Refactoring patch by DevHC

This commit is contained in:
Thilo Schulz 2011-03-05 19:20:37 +00:00
parent 21668c0616
commit fef4d12d68
31 changed files with 60 additions and 98 deletions

View file

@ -3459,7 +3459,7 @@ void FS_PureServerSetReferencedPaks( const char *pakSums, const char *pakNames )
fs_serverReferencedPaks[i] = atoi( Cmd_Argv( i ) );
}
for (i = 0 ; i < sizeof(fs_serverReferencedPakNames) / sizeof(*fs_serverReferencedPakNames); i++)
for (i = 0 ; i < ARRAY_LEN(fs_serverReferencedPakNames); i++)
{
if(fs_serverReferencedPakNames[i])
Z_Free(fs_serverReferencedPakNames[i]);

View file

@ -895,7 +895,7 @@ void MSG_WriteDeltaEntity( msg_t *msg, struct entityState_s *from, struct entity
float fullFloat;
int *fromF, *toF;
numFields = sizeof(entityStateFields)/sizeof(entityStateFields[0]);
numFields = ARRAY_LEN( entityStateFields );
// all fields should be 32 bits to avoid any compiler packing issues
// the "number" field is not part of the field list
@ -1040,7 +1040,7 @@ void MSG_ReadDeltaEntity( msg_t *msg, entityState_t *from, entityState_t *to,
return;
}
numFields = sizeof(entityStateFields)/sizeof(entityStateFields[0]);
numFields = ARRAY_LEN( entityStateFields );
lc = MSG_ReadByte(msg);
if ( lc > numFields || lc < 0 ) {
@ -1210,7 +1210,7 @@ void MSG_WriteDeltaPlayerstate( msg_t *msg, struct playerState_s *from, struct p
c = msg->cursize;
numFields = sizeof( playerStateFields ) / sizeof( playerStateFields[0] );
numFields = ARRAY_LEN( playerStateFields );
lc = 0;
for ( i = 0, field = playerStateFields ; i < numFields ; i++, field++ ) {
@ -1377,7 +1377,7 @@ void MSG_ReadDeltaPlayerstate (msg_t *msg, playerState_t *from, playerState_t *t
print = 0;
}
numFields = sizeof( playerStateFields ) / sizeof( playerStateFields[0] );
numFields = ARRAY_LEN( playerStateFields );
lc = MSG_ReadByte(msg);
if ( lc > numFields || lc < 0 ) {

View file

@ -194,7 +194,7 @@ typedef int clipHandle_t;
#define MAX_QINT 0x7fffffff
#define MIN_QINT (-MAX_QINT-1)
#define ARRAY_LEN(x) (sizeof(x) / sizeof(*x))
#define ARRAY_LEN(x) (sizeof(x) / sizeof(*(x)))
// angle indexes

View file

@ -346,7 +346,7 @@ intptr_t QDECL VM_DllSyscall( intptr_t arg, ... ) {
args[0] = arg;
va_start(ap, arg);
for (i = 1; i < sizeof (args) / sizeof (args[i]); i++)
for (i = 1; i < ARRAY_LEN (args); i++)
args[i] = va_arg(ap, intptr_t);
va_end(ap);
@ -756,7 +756,7 @@ intptr_t QDECL VM_Call( vm_t *vm, int callnum, ... ) {
int args[10];
va_list ap;
va_start(ap, callnum);
for (i = 0; i < sizeof (args) / sizeof (args[i]); i++) {
for (i = 0; i < ARRAY_LEN(args); i++) {
args[i] = va_arg(ap, int);
}
va_end(ap);
@ -781,7 +781,7 @@ intptr_t QDECL VM_Call( vm_t *vm, int callnum, ... ) {
a.callnum = callnum;
va_start(ap, callnum);
for (i = 0; i < sizeof (a.args) / sizeof (a.args[0]); i++) {
for (i = 0; i < ARRAY_LEN(a.args); i++) {
a.args[i] = va_arg(ap, int);
}
va_end(ap);

View file

@ -690,7 +690,7 @@ static const long int gpr_list[] = {
r7, r8, r9, r10,
};
static const long int gpr_vstart = 8; /* position of first volatile register */
static const long int gpr_total = sizeof( gpr_list ) / sizeof( gpr_list[0] );
static const long int gpr_total = ARRAY_LEN( gpr_list );
static const long int fpr_list[] = {
/* static registers, normally none is used */
@ -704,7 +704,7 @@ static const long int fpr_list[] = {
f12, f13,
};
static const long int fpr_vstart = 8;
static const long int fpr_total = sizeof( fpr_list ) / sizeof( fpr_list[0] );
static const long int fpr_total = ARRAY_LEN( fpr_list );
/*
* prepare some dummy structures and emit init code

View file

@ -389,8 +389,7 @@ static const struct powerpc_operand powerpc_operands[] =
};
static const unsigned int num_powerpc_operands =
(sizeof (powerpc_operands) / sizeof (powerpc_operands[0]));
static const unsigned int num_powerpc_operands = ARRAY_LEN (powerpc_operands);
/* The functions used to insert and extract complicated operands. */
@ -1004,6 +1003,3 @@ static const struct powerpc_opcode powerpc_opcodes[] = {
{ "fsub", A(63,20,0), AFRC_MASK, PPCCOM, { FRT, FRA, FRB } },
{ "fneg", XRC(63,40,0), XRA_MASK, COM, { FRT, FRB } },
};
static const int powerpc_num_opcodes =
sizeof (powerpc_opcodes) / sizeof (powerpc_opcodes[0]);

View file

@ -259,7 +259,7 @@ static const struct sparc_opcode sparc_opcodes[] = {
{ "fbg", BFCC(0,6), { ARG_DISP22 }, },
{ "fble", BFCC(0,13), { ARG_DISP22 }, },
};
#define SPARC_NUM_OPCODES (sizeof(sparc_opcodes) / sizeof(sparc_opcodes[0]))
#define SPARC_NUM_OPCODES (ARRAY_LEN(sparc_opcodes))
#define RS1(X) (((X) & 0x1f) << 14)
#define RS2(X) (((X) & 0x1f) << 0)
@ -320,7 +320,7 @@ static unsigned int sparc_assemble(enum sparc_iname iname, const int argc, const
#define IN(inst, args...) \
({ const int argv[] = { args }; \
const int argc = sizeof(argv) / sizeof(argv[0]); \
const int argc = ARRAY_LEN(argv); \
sparc_assemble(inst, argc, argv); \
})

View file

@ -243,7 +243,7 @@ static void hash_add_label(const char* label, unsigned address)
unsigned i = hashkey(label, -1U);
int labellen;
i %= sizeof(labelhash)/sizeof(labelhash[0]);
i %= ARRAY_LEN(labelhash);
h = Z_Malloc(sizeof(struct hashentry));
labellen = strlen(label) + 1;
@ -259,7 +259,7 @@ static unsigned lookup_label(const char* label)
{
struct hashentry* h;
unsigned i = hashkey(label, -1U);
i %= sizeof(labelhash)/sizeof(labelhash[0]);
i %= ARRAY_LEN(labelhash);
for(h = labelhash[i]; h; h = h->next )
{
if(!strcmp(h->label, label))
@ -275,7 +275,7 @@ static void labelhash_free(void)
struct hashentry* h;
unsigned i;
unsigned z = 0, min = -1U, max = 0, t = 0;
for ( i = 0; i < sizeof(labelhash)/sizeof(labelhash[0]); ++i)
for ( i = 0; i < ARRAY_LEN(labelhash); ++i)
{
unsigned n = 0;
h = labelhash[i];
@ -293,7 +293,7 @@ static void labelhash_free(void)
min = MIN(min, n);
max = MAX(max, n);
}
printf("total %u, hsize %"PRIu64", zero %u, min %u, max %u\n", t, sizeof(labelhash)/sizeof(labelhash[0]), z, min, max);
printf("total %u, hsize %"PRIu64", zero %u, min %u, max %u\n", t, ARRAY_LEN(labelhash), z, min, max);
memset(labelhash, 0, sizeof(labelhash));
}
@ -1015,7 +1015,7 @@ static op_t* getop(const char* n)
#else
unsigned m, t, b;
int r;
t = sizeof(ops)/sizeof(ops[0])-1;
t = ARRAY_LEN(ops)-1;
b = 0;
while(b <= t)
@ -1306,7 +1306,7 @@ void assembler_init(int pass)
if(!ops_sorted)
{
ops_sorted = 1;
qsort(ops, sizeof(ops)/sizeof(ops[0])-1, sizeof(ops[0]), opsort);
qsort(ops, ARRAY_LEN(ops)-1, sizeof(ops[0]), opsort);
}
}