1
0
Fork 0

(svn r223) -Fix: Const correctness and miscellaneous fixes. Thank you Tron for your diligent fixing of warnings (and some possibly bugs) (Tron)

-CodeLayout: Remove trailing spaces and Windows linebreaks
release/0.4.5
darkvater 2004-09-12 21:49:38 +00:00
parent 1b498bca57
commit e295e46e3e
40 changed files with 717 additions and 721 deletions

View File

@ -88,7 +88,7 @@ static void AirportFTAClass_Constructor(AirportFTAClass *Airport,
Airport->nofhelipadgroups = nofhelipadgroups; Airport->nofhelipadgroups = nofhelipadgroups;
Airport->acc_planes = acc_planes; Airport->acc_planes = acc_planes;
Airport->entry_point = entry_point; Airport->entry_point = entry_point;
Airport->airport_depots = (uint16*)depots; Airport->airport_depots = (const uint16*)depots;
// build the state machine // build the state machine

View File

@ -32,7 +32,7 @@ typedef struct AirportFTAClass {
byte nofhelipadgroups; // helipads belong to so many groups (MAX is the nofhelipads) byte nofhelipadgroups; // helipads belong to so many groups (MAX is the nofhelipads)
byte entry_point; // when an airplane arrives at this airport, enter it at position entry_point byte entry_point; // when an airplane arrives at this airport, enter it at position entry_point
byte acc_planes; // accept airplanes or helicopters or both byte acc_planes; // accept airplanes or helicopters or both
uint16 *airport_depots; // gives the position of the depots on the airports const uint16 *airport_depots; // gives the position of the depots on the airports
struct AirportFTA *layout; // state machine for airport struct AirportFTA *layout; // state machine for airport
} AirportFTAClass; } AirportFTAClass;

View File

@ -207,9 +207,9 @@ void IConsoleInit()
} }
IConsoleStdLibRegister(); IConsoleStdLibRegister();
#if defined(WITH_REV) #if defined(WITH_REV)
IConsolePrintF(13,"OpenTTD Game Console Revision 3 - %s",_openttd_revision); IConsolePrintF(13,"OpenTTD Game Console Revision 4 - %s",_openttd_revision);
#else #else
IConsolePrint(13,"OpenTTD Game Console Revision 3"); IConsolePrint(13,"OpenTTD Game Console Revision 4");
#endif #endif
IConsolePrint(12,"---------------------------------"); IConsolePrint(12,"---------------------------------");
IConsolePrint(12,"use \"help\" for more info"); IConsolePrint(12,"use \"help\" for more info");
@ -269,16 +269,16 @@ void IConsoleOpen()
if (_iconsole_mode==ICONSOLE_CLOSED) IConsoleSwitch(); if (_iconsole_mode==ICONSOLE_CLOSED) IConsoleSwitch();
} }
void IConsoleCmdBufferAdd(byte * cmd) void IConsoleCmdBufferAdd(const byte * cmd)
{ {
int i; int i;
if (_iconsole_cmdbufferpos != 19) return; if (_iconsole_cmdbufferpos != 19) return;
if (_iconsole_cmdbuffer[18]!=NULL) free(_iconsole_cmdbuffer[18]); if (_iconsole_cmdbuffer[18]!=NULL) free(_iconsole_cmdbuffer[18]);
for (i=18; i>0; i--) _iconsole_cmdbuffer[i]=_iconsole_cmdbuffer[i-1]; for (i=18; i>0; i--) _iconsole_cmdbuffer[i]=_iconsole_cmdbuffer[i-1];
i=strlen((char *)cmd); i=strlen(cmd);
_iconsole_cmdbuffer[0]=malloc(i+1); _iconsole_cmdbuffer[0]=malloc(i+1);
memset(((void *)_iconsole_cmdbuffer[0]),0,i+1); memset(((void *)_iconsole_cmdbuffer[0]),0,i+1);
memcpy(((void *)_iconsole_cmdbuffer[0]),(void *)cmd,i); memcpy(((void *)_iconsole_cmdbuffer[0]),cmd,i);
_iconsole_cmdbuffer[0][i]=0; _iconsole_cmdbuffer[0][i]=0;
_iconsole_cmdbufferpos = 19; _iconsole_cmdbufferpos = 19;
} }
@ -303,7 +303,7 @@ void IConsoleCmdBufferNavigate(signed char direction)
_iconsole_cmdpos =strlen(_iconsole_cmdbuffer[i]); _iconsole_cmdpos =strlen(_iconsole_cmdbuffer[i]);
} }
void IConsolePrint(byte color_code, byte* string) void IConsolePrint(byte color_code, const byte* string)
{ {
byte * _ex; byte * _ex;
byte * _new; byte * _new;
@ -314,7 +314,7 @@ void IConsolePrint(byte color_code, byte* string)
if (!_iconsole_inited) return; if (!_iconsole_inited) return;
_newc=color_code; _newc=color_code;
i=strlen((char *)string); i=strlen(string);
_new=malloc(i+1); _new=malloc(i+1);
memset(_new,0,i+1); memset(_new,0,i+1);
memcpy(_new,string,i); memcpy(_new,string,i);
@ -354,19 +354,19 @@ void IConsoleDebug(byte* string)
if (_stdlib_developer>1) IConsolePrintF(_iconsole_color_debug, "DEBUG: %s", string); if (_stdlib_developer>1) IConsolePrintF(_iconsole_color_debug, "DEBUG: %s", string);
} }
void IConsoleError(byte* string) void IConsoleError(const byte* string)
{ {
if (_stdlib_developer>0) IConsolePrintF(_iconsole_color_error, "ERROR: %s", string); if (_stdlib_developer>0) IConsolePrintF(_iconsole_color_error, "ERROR: %s", string);
} }
void IConsoleCmdRegister(byte * name, void * addr) void IConsoleCmdRegister(const byte * name, void * addr)
{ {
byte * _new; byte * _new;
_iconsole_cmd * item; _iconsole_cmd * item;
_iconsole_cmd * item_new; _iconsole_cmd * item_new;
int i; int i;
i=strlen((char *)name); i=strlen(name);
_new=malloc(i+1); _new=malloc(i+1);
memset(_new,0,i+1); memset(_new,0,i+1);
memcpy(_new,name,i); memcpy(_new,name,i);
@ -390,7 +390,7 @@ void IConsoleCmdRegister(byte * name, void * addr)
} }
} }
void* IConsoleCmdGet(byte * name) void* IConsoleCmdGet(const byte * name)
{ {
_iconsole_cmd * item; _iconsole_cmd * item;
@ -402,14 +402,14 @@ void* IConsoleCmdGet(byte * name)
return NULL; return NULL;
} }
void IConsoleVarRegister(byte * name, void * addr, byte type) void IConsoleVarRegister(const byte * name, void * addr, byte type)
{ {
byte * _new; byte * _new;
_iconsole_var * item; _iconsole_var * item;
_iconsole_var * item_new; _iconsole_var * item_new;
int i; int i;
i=strlen((char *)name)+1; i=strlen(name)+1;
_new=malloc(i+1); _new=malloc(i+1);
memset(_new,0,i+1); memset(_new,0,i+1);
_new[0]='*'; _new[0]='*';
@ -436,7 +436,7 @@ void IConsoleVarRegister(byte * name, void * addr, byte type)
} }
} }
void IConsoleVarMemRegister(byte * name, byte type) void IConsoleVarMemRegister(byte * name, byte type) /* XXX TRON */
{ {
_iconsole_var * item; _iconsole_var * item;
item = IConsoleVarAlloc(type); item = IConsoleVarAlloc(type);
@ -444,7 +444,7 @@ void IConsoleVarMemRegister(byte * name, byte type)
} }
void IConsoleVarInsert(_iconsole_var * var, byte * name) void IConsoleVarInsert(_iconsole_var * var, const byte * name)
{ {
byte * _new; byte * _new;
_iconsole_var * item; _iconsole_var * item;
@ -456,7 +456,7 @@ void IConsoleVarInsert(_iconsole_var * var, byte * name)
// dont allow to build variable rings // dont allow to build variable rings
if (item_new->_next != NULL) return; if (item_new->_next != NULL) return;
i=strlen((char *)name)+1; i=strlen(name)+1;
_new=malloc(i+1); _new=malloc(i+1);
memset(_new,0,i+1); memset(_new,0,i+1);
_new[0]='*'; _new[0]='*';
@ -474,7 +474,7 @@ void IConsoleVarInsert(_iconsole_var * var, byte * name)
} }
_iconsole_var * IConsoleVarGet(byte * name) _iconsole_var * IConsoleVarGet(const byte * name)
{ {
_iconsole_var * item; _iconsole_var * item;
@ -551,13 +551,12 @@ _iconsole_var * IConsoleVarAlloc(byte type)
void IConsoleVarFree(_iconsole_var * var) void IConsoleVarFree(_iconsole_var * var)
{ {
if (var ->_malloc) { if (var->_malloc)
free(var ->addr); free(var->addr);
}
free(var); free(var);
} }
void IConsoleVarSetString(_iconsole_var * var, byte * string) void IConsoleVarSetString(_iconsole_var * var, const byte * string)
{ {
int l; int l;
@ -567,52 +566,40 @@ void IConsoleVarSetString(_iconsole_var * var, byte * string)
free(var->addr); free(var->addr);
} }
l=strlen((char *) string); l=strlen(string);
var->addr=malloc(l+1); var->addr=malloc(l+1);
var->_malloc=true; var->_malloc=true;
memset(var->addr,0,l); memset(var->addr,0,l);
memcpy((void *) var->addr,(void *) string, l); memcpy(var->addr, string, l);
((byte *)var->addr)[l]=0; ((byte *)var->addr)[l]=0;
} }
void IConsoleVarSetValue(_iconsole_var * var, int value) { void IConsoleVarSetValue(_iconsole_var * var, int value) {
switch (var->type) { switch (var->type) {
case ICONSOLE_VAR_BOOLEAN: case ICONSOLE_VAR_BOOLEAN:
{ *(bool *)var->addr = (value != 0);
(*(bool *)var->addr)=(value!=0);
}
break; break;
case ICONSOLE_VAR_BYTE: case ICONSOLE_VAR_BYTE:
{ *(byte *)var->addr = value;
(*(byte *)var->addr)=value;
}
break; break;
case ICONSOLE_VAR_UINT16: case ICONSOLE_VAR_UINT16:
{ *(unsigned short *)var->addr = value;
(*(unsigned short *)var->addr)=value;
}
break; break;
case ICONSOLE_VAR_UINT32: case ICONSOLE_VAR_UINT32:
{ *(unsigned int *)var->addr = value;
(*(unsigned int *)var->addr)=value;
}
break; break;
case ICONSOLE_VAR_INT16: case ICONSOLE_VAR_INT16:
{ *(signed short *)var->addr = value;
(*(signed short *)var->addr)=value;
}
break; break;
case ICONSOLE_VAR_INT32: case ICONSOLE_VAR_INT32:
{ *(signed int *)var->addr = value;
(*(signed int *)var->addr)=value;
}
break; break;
default: default:
break; break;
} }
} }
void IConsoleVarDump(_iconsole_var * var, byte * dump_desc) void IConsoleVarDump(_iconsole_var * var, const byte * dump_desc)
{ {
byte var_b; // TYPE BYTE byte var_b; // TYPE BYTE
unsigned short var_ui16; // TYPE UINT16 unsigned short var_ui16; // TYPE UINT16
@ -686,7 +673,7 @@ void IConsoleVarDump(_iconsole_var * var, byte * dump_desc)
// * hooking code * // // * hooking code * //
// * ************************* * // // * ************************* * //
void IConsoleVarHook(byte * name, byte type, void * proc) void IConsoleVarHook(const byte * name, byte type, void * proc)
{ {
_iconsole_var * hook_var; _iconsole_var * hook_var;
hook_var = IConsoleVarGet(name); hook_var = IConsoleVarGet(name);
@ -706,7 +693,7 @@ void IConsoleVarHook(byte * name, byte type, void * proc)
bool IConsoleVarHookHandle(_iconsole_var * hook_var, byte type) bool IConsoleVarHookHandle(_iconsole_var * hook_var, byte type)
{ {
bool (*proc)(_iconsole_var * hook_var); bool (*proc)(_iconsole_var * hook_var) = NULL;
switch (type) { switch (type) {
case ICONSOLE_HOOK_BEFORE_CHANGE: case ICONSOLE_HOOK_BEFORE_CHANGE:
proc = hook_var->hook_before_change; proc = hook_var->hook_before_change;
@ -717,12 +704,13 @@ bool IConsoleVarHookHandle(_iconsole_var * hook_var, byte type)
case ICONSOLE_HOOK_ACCESS: case ICONSOLE_HOOK_ACCESS:
proc = hook_var->hook_access; proc = hook_var->hook_access;
break; break;
default: return true;
} }
if (proc == NULL) return true;
return proc(hook_var); return proc(hook_var);
} }
void IConsoleCmdHook(byte * name, byte type, void * proc) void IConsoleCmdHook(const byte * name, byte type, void * proc)
{ {
_iconsole_cmd * hook_cmd; _iconsole_cmd * hook_cmd;
hook_cmd = IConsoleCmdGet(name); hook_cmd = IConsoleCmdGet(name);
@ -753,6 +741,9 @@ bool IConsoleCmdHookHandle(_iconsole_cmd * hook_cmd, byte type)
case ICONSOLE_HOOK_ACCESS: case ICONSOLE_HOOK_ACCESS:
proc = hook_cmd->hook_access; proc = hook_cmd->hook_access;
break; break;
default:
proc = NULL;
break;
} }
if (proc == NULL) return true; if (proc == NULL) return true;
return proc(hook_cmd); return proc(hook_cmd);
@ -1115,7 +1106,8 @@ void IConsoleCmdExec(byte * cmdstr)
case 4: case 4:
{ {
// execute command with result or assign a variable // execute command with result or assign a variable
if (execution_mode==3) if (IConsoleCmdHookHandle(cmd,ICONSOLE_HOOK_ACCESS)) { if (execution_mode==3) {
if (IConsoleCmdHookHandle(cmd,ICONSOLE_HOOK_ACCESS)) {
int i; int i;
int diff; int diff;
void * temp; void * temp;
@ -1135,7 +1127,7 @@ void IConsoleCmdExec(byte * cmdstr)
IConsoleCmdHookHandle(cmd,ICONSOLE_HOOK_BEFORE_EXEC); IConsoleCmdHookHandle(cmd,ICONSOLE_HOOK_BEFORE_EXEC);
result = function(c,tokens,tokentypes); result = function(c,tokens,tokentypes);
IConsoleCmdHookHandle(cmd,ICONSOLE_HOOK_AFTER_EXEC); IConsoleCmdHookHandle(cmd,ICONSOLE_HOOK_AFTER_EXEC);
} else { } else
execution_mode=255; execution_mode=255;
} }

View File

@ -47,7 +47,7 @@ typedef struct {
typedef struct { typedef struct {
// --------------- // // --------------- //
void * addr; void * addr;
byte * name; const byte * name;
byte type; byte type;
// -------------- // // -------------- //
void * hook_access; void * hook_access;
@ -85,31 +85,31 @@ void IConsoleClose();
void IConsoleOpen(); void IConsoleOpen();
// ** console cmd buffer ** // // ** console cmd buffer ** //
void IConsoleCmdBufferAdd(byte * cmd); void IConsoleCmdBufferAdd(const byte *cmd);
void IConsoleCmdBufferNavigate(signed char direction); void IConsoleCmdBufferNavigate(signed char direction);
// ** console output ** // // ** console output ** //
void IConsolePrint(byte color_code, byte* string); void IConsolePrint(byte color_code, const byte* string);
void CDECL IConsolePrintF(byte color_code, const char *s, ...); void CDECL IConsolePrintF(byte color_code, const char *s, ...);
void IConsoleDebug(byte* string); void IConsoleDebug(byte* string);
void IConsoleError(byte* string); void IConsoleError(const byte* string);
// *** Commands *** // // *** Commands *** //
void IConsoleCmdRegister(byte * name, void * addr); void IConsoleCmdRegister(const byte * name, void * addr);
void* IConsoleCmdGetAddr(byte * name); void* IConsoleCmdGetAddr(byte * name);
// *** Variables *** // // *** Variables *** //
void IConsoleVarRegister(byte * name, void * addr, byte type); void IConsoleVarRegister(const byte * name, void * addr, byte type);
void IConsoleVarMemRegister(byte * name, byte type); void IConsoleVarMemRegister(byte * name, byte type);
void IConsoleVarInsert(_iconsole_var * var, byte * name); void IConsoleVarInsert(_iconsole_var * var, const byte * name);
_iconsole_var * IConsoleVarGet(byte * name); _iconsole_var * IConsoleVarGet(const byte * name);
_iconsole_var * IConsoleVarAlloc(byte type); _iconsole_var * IConsoleVarAlloc(byte type);
void IConsoleVarFree(_iconsole_var * var); void IConsoleVarFree(_iconsole_var * var);
void IConsoleVarSetString(_iconsole_var * var, byte * string); void IConsoleVarSetString(_iconsole_var * var, const byte * string);
void IConsoleVarSetValue(_iconsole_var * var, int value); void IConsoleVarSetValue(_iconsole_var * var, int value);
void IConsoleVarDump(_iconsole_var * var, byte * dump_desc); void IConsoleVarDump(_iconsole_var * var, const byte * dump_desc);
// *** Parser *** // // *** Parser *** //
@ -119,8 +119,8 @@ void IConsoleCmdExec(byte * cmdstr);
void IConsoleStdLibRegister(); void IConsoleStdLibRegister();
// ** hook code ** // // ** hook code ** //
void IConsoleVarHook(byte * name, byte type, void * proc); void IConsoleVarHook(const byte * name, byte type, void * proc);
void IConsoleCmdHook(byte * name, byte type, void * proc); void IConsoleCmdHook(const byte * name, byte type, void * proc);
bool IConsoleVarHookHandle(_iconsole_var * hook_var, byte type); bool IConsoleVarHookHandle(_iconsole_var * hook_var, byte type);
bool IConsoleCmdHookHandle(_iconsole_cmd * hook_cmd, byte type); bool IConsoleCmdHookHandle(_iconsole_cmd * hook_cmd, byte type);

View File

@ -39,6 +39,7 @@ DEF_CONSOLE_CMD_HOOK(ConCmdHookNoNetwork)
return true; return true;
} }
#if 0 /* Not used atm */
DEF_CONSOLE_VAR_HOOK(ConVarHookNoNetwork) DEF_CONSOLE_VAR_HOOK(ConVarHookNoNetwork)
{ {
if (_networking) { if (_networking) {
@ -47,6 +48,7 @@ DEF_CONSOLE_VAR_HOOK(ConVarHookNoNetwork)
} }
return true; return true;
} }
#endif
DEF_CONSOLE_VAR_HOOK(ConVarHookNoNetClient) DEF_CONSOLE_VAR_HOOK(ConVarHookNoNetClient)
{ {
@ -275,7 +277,7 @@ DEF_CONSOLE_CMD(ConListVariables)
while (item != NULL) { while (item != NULL) {
if (argv[1]!=NULL) { if (argv[1]!=NULL) {
if (memcmp((void *) item->name, (void *) argv[1],l)==0) if (memcmp(item->name, argv[1],l)==0)
IConsolePrintF(_iconsole_color_default,"%s",item->name); IConsolePrintF(_iconsole_color_default,"%s",item->name);
} else { } else {
@ -300,7 +302,7 @@ DEF_CONSOLE_CMD(ConListDumpVariables)
while (item != NULL) { while (item != NULL) {
if (argv[1]!=NULL) { if (argv[1]!=NULL) {
if (memcmp((void *) item->name, (void *) argv[1],l)==0) if (memcmp(item->name, argv[1],l)==0)
IConsoleVarDump(item,NULL); IConsoleVarDump(item,NULL);
} else { } else {
@ -346,6 +348,8 @@ void IConsoleStdLibRegister()
#ifdef _DEBUG #ifdef _DEBUG
IConsoleDebugLibRegister(); IConsoleDebugLibRegister();
#else
(void)ConResetTile; // Silence warning, this is only used in _DEBUG
#endif #endif
// functions [please add them alphabeticaly] // functions [please add them alphabeticaly]

View File

View File

@ -1016,8 +1016,8 @@ static StringID GetPerformanceTitleFromValue(uint v)
} }
static int CDECL _perf_hist_comp(const void *elem1, const void *elem2 ) { static int CDECL _perf_hist_comp(const void *elem1, const void *elem2 ) {
Player *p1 = *(Player**)elem1; const Player *p1 = *(const Player* const *)elem1;
Player *p2 = *(Player**)elem2; const Player *p2 = *(const Player* const *)elem2;
int32 v = p2->old_economy[1].performance_history - p1->old_economy[1].performance_history; int32 v = p2->old_economy[1].performance_history - p1->old_economy[1].performance_history;
return (v!=0) | (v >> (sizeof(int32)*8-1)); return (v!=0) | (v >> (sizeof(int32)*8-1));
} }

2
hal.h
View File

@ -135,7 +135,7 @@ char *FiosBrowseTo(const FiosItem *item);
// Get descriptive texts. // Get descriptive texts.
// Returns a path as well as a // Returns a path as well as a
// string describing the path. // string describing the path.
StringID FiosGetDescText(char **path); StringID FiosGetDescText(const char **path);
// Delete a name // Delete a name
void FiosDelete(const char *name); void FiosDelete(const char *name);
// Make a filename from a name // Make a filename from a name

View File

@ -392,8 +392,8 @@ static int CDECL GeneralIndustrySorter(const void *a, const void *b)
{ {
char buf1[96]; char buf1[96];
byte val; byte val;
Industry *i = DEREF_INDUSTRY(*(byte*)a); Industry *i = DEREF_INDUSTRY(*(const byte*)a);
Industry *j = DEREF_INDUSTRY(*(byte*)b); Industry *j = DEREF_INDUSTRY(*(const byte*)b);
int r = 0; int r = 0;
switch (_industry_sort_order >> 1) { switch (_industry_sort_order >> 1) {
@ -437,7 +437,7 @@ static int CDECL GeneralIndustrySorter(const void *a, const void *b)
SET_DPARAM32(0, i->town->townnameparts); SET_DPARAM32(0, i->town->townnameparts);
GetString(buf1, i->town->townnametype); GetString(buf1, i->town->townnametype);
if ( (val=*(byte*)b) != _last_industry_idx) { if ( (val=*(const byte*)b) != _last_industry_idx) {
_last_industry_idx = val; _last_industry_idx = val;
SET_DPARAM32(0, j->town->townnameparts); SET_DPARAM32(0, j->town->townnameparts);
GetString(_bufcache, j->town->townnametype); GetString(_bufcache, j->town->townnametype);

View File

@ -203,18 +203,18 @@ static INLINE void swap_tile(TileIndex *a, TileIndex *b) { TileIndex t = *a; *a
#if defined(TTD_LITTLE_ENDIAN) #if defined(TTD_LITTLE_ENDIAN)
# define READ_LE_UINT16(b) (*(uint16*)(b)) # define READ_LE_UINT16(b) (*(const uint16*)(b))
# define ADD_WORD(x) (x)&0xFF, ((x) >> 8)&0xFF # define ADD_WORD(x) (x)&0xFF, ((x) >> 8)&0xFF
# define ADD_DWORD(x) (x)&0xFF, ((x) >> 8)&0xFF, ((x) >> 16)&0xFF, ((x) >> 24)&0xFF # define ADD_DWORD(x) (x)&0xFF, ((x) >> 8)&0xFF, ((x) >> 16)&0xFF, ((x) >> 24)&0xFF
#elif defined(TTD_BIG_ENDIAN) #elif defined(TTD_BIG_ENDIAN)
static INLINE uint16 READ_LE_UINT16(const void *b) { static INLINE uint16 READ_LE_UINT16(const void *b) {
return ((byte*)b)[0] + (((byte*)b)[1] << 8); return ((const byte*)b)[0] + (((const byte*)b)[1] << 8);
} }
# define ADD_WORD(x) ((x) >> 8)&0xFF, (x)&0xFF # define ADD_WORD(x) ((x) >> 8)&0xFF, (x)&0xFF
# define ADD_DWORD(x) ((x) >> 24)&0xFF, ((x) >> 16)&0xFF, ((x) >> 8)&0xFF, (x)&0xFF # define ADD_DWORD(x) ((x) >> 24)&0xFF, ((x) >> 16)&0xFF, ((x) >> 8)&0xFF, (x)&0xFF
#endif #endif
static INLINE void WRITE_LE_UINT16(const void *b, uint16 x) { static INLINE void WRITE_LE_UINT16(void *b, uint16 x) {
((byte*)b)[0] = (byte)x; ((byte*)b)[0] = (byte)x;
((byte*)b)[1] = (byte)(x >> 8); ((byte*)b)[1] = (byte)(x >> 8);
} }

View File

@ -963,7 +963,7 @@ static void BuildFileList()
static void DrawFiosTexts() static void DrawFiosTexts()
{ {
char *path; const char *path;
StringID str; StringID str;
str = FiosGetDescText(&path); str = FiosGetDescText(&path);

View File

@ -1520,7 +1520,7 @@ static void DrawTile_Track(TileInfo *ti)
s = _track_depot_layout_table[m5 & 0x3F]; s = _track_depot_layout_table[m5 & 0x3F];
image = *(uint16*)s; image = *(const uint16*)s;
if (image & 0x8000) image = (image & 0x7FFF) + tracktype_offs; if (image & 0x8000) image = (image & 0x7FFF) + tracktype_offs;
// adjust ground tile for desert // adjust ground tile for desert
@ -1566,11 +1566,11 @@ void DrawTrainDepotSprite(int x, int y, int image, int railtype)
x+=33; x+=33;
y+=17; y+=17;
img = *(uint16*)t; img = *(const uint16*)t;
if (img & 0x8000) img = (img & 0x7FFF) + railtype; if (img & 0x8000) img = (img & 0x7FFF) + railtype;
DrawSprite(img, x, y); DrawSprite(img, x, y);
for(dtss = (DrawTrackSeqStruct *)(t + sizeof(uint16)); dtss->image != 0; dtss++) { for(dtss = (const DrawTrackSeqStruct *)(t + sizeof(uint16)); dtss->image != 0; dtss++) {
Point pt = RemapCoords(dtss->subcoord_x, dtss->subcoord_y, 0); Point pt = RemapCoords(dtss->subcoord_x, dtss->subcoord_y, 0);
image = dtss->image; image = dtss->image;
if (image & 0x8000) image |= ormod; if (image & 0x8000) image |= ormod;

View File

@ -810,9 +810,9 @@ static void DrawTile_Road(TileInfo *ti)
s = _road_display_datas[ti->map5 & 0xF]; s = _road_display_datas[ti->map5 & 0xF];
DrawGroundSprite(*(uint32*)s); DrawGroundSprite(*(const uint32*)s);
s += sizeof(uint32); s += sizeof(uint32);
drss = (DrawRoadSeqStruct*)s; drss = (const DrawRoadSeqStruct*)s;
while ((image=drss->image) != 0) { while ((image=drss->image) != 0) {
if (image & 0x8000) if (image & 0x8000)
@ -840,10 +840,10 @@ void DrawRoadDepotSprite(int x, int y, int image)
x+=33; x+=33;
y+=17; y+=17;
DrawSprite(*(uint32*)t, x, y); DrawSprite(*(const uint32*)t, x, y);
t += sizeof(uint32); t += sizeof(uint32);
for(dtss = (DrawRoadSeqStruct *)t; dtss->image != 0; dtss++) { for(dtss = (const DrawRoadSeqStruct *)t; dtss->image != 0; dtss++) {
Point pt = RemapCoords(dtss->subcoord_x, dtss->subcoord_y, 0); Point pt = RemapCoords(dtss->subcoord_x, dtss->subcoord_y, 0);
image = dtss->image; image = dtss->image;

View File

@ -422,7 +422,7 @@ static size_t SlCalcObjLength(void *object, const void *desc)
{ {
size_t length = 0; size_t length = 0;
uint cmd,conv; uint cmd,conv;
byte *d = (byte*)desc; const byte *d = (const byte*)desc;
// Need to determine the length and write a length tag. // Need to determine the length and write a length tag.
while (true) { while (true) {
@ -464,7 +464,7 @@ static size_t SlCalcObjLength(void *object, const void *desc)
void SlObject(void *object, const void *desc) void SlObject(void *object, const void *desc)
{ {
byte *d = (byte*)desc; const byte *d = (const byte*)desc;
void *ptr; void *ptr;
uint cmd,conv; uint cmd,conv;

4
sdl.c
View File

@ -212,9 +212,9 @@ static void DrawSurfaceToScreen()
static int CDECL compare_res(const void *pa, const void *pb) static int CDECL compare_res(const void *pa, const void *pb)
{ {
int x = ((uint16*)pa)[0] - ((uint16*)pb)[0]; int x = ((const uint16*)pa)[0] - ((const uint16*)pb)[0];
if (x) return x; if (x) return x;
return ((uint16*)pa)[1] - ((uint16*)pb)[1]; return ((const uint16*)pa)[1] - ((const uint16*)pb)[1];
} }
static const uint16 default_resolutions[][2] = { static const uint16 default_resolutions[][2] = {

View File

@ -325,9 +325,9 @@ static void ini_free(IniFile *ini)
struct SettingDesc { struct SettingDesc {
const char *name; const char *name;
int flags; int flags;
void *def; const void *def;
void *ptr; void *ptr;
void *b; const void *b;
}; };
@ -493,7 +493,7 @@ static void make_manyofmany(char *buf, const char *many, uint32 x)
*buf = 0; *buf = 0;
} }
static void *string_to_val(const SettingDesc *desc, const char *str) static const void *string_to_val(const SettingDesc *desc, const char *str)
{ {
unsigned long val; unsigned long val;
char *end; char *end;
@ -532,11 +532,11 @@ static void *string_to_val(const SettingDesc *desc, const char *str)
return NULL; return NULL;
} }
static void load_setting_desc(IniFile *ini, const SettingDesc *desc, void *grpname, void *base) static void load_setting_desc(IniFile *ini, const SettingDesc *desc, const void *grpname, void *base)
{ {
IniGroup *group_def = ini_getgroup(ini, grpname, -1), *group; IniGroup *group_def = ini_getgroup(ini, grpname, -1), *group;
IniItem *item; IniItem *item;
void *p; const void *p;
void *ptr; void *ptr;
for (;desc->name;desc++) { for (;desc->name;desc++) {
@ -603,11 +603,12 @@ static void load_setting_desc(IniFile *ini, const SettingDesc *desc, void *grpna
} }
} }
static void save_setting_desc(IniFile *ini, const SettingDesc *desc, void *grpname, void *base) static void save_setting_desc(IniFile *ini, const SettingDesc *desc, const void *grpname, void *base)
{ {
IniGroup *group_def = NULL, *group; IniGroup *group_def = NULL, *group;
IniItem *item; IniItem *item;
void *p, *ptr; const void *p;
void *ptr;
int i = 0; int i = 0;
char buf[512]; // setting buffer char buf[512]; // setting buffer
const char *s; const char *s;
@ -883,7 +884,7 @@ static const SettingDesc patch_settings[] = {
{NULL, 0, NULL, NULL, NULL} {NULL, 0, NULL, NULL, NULL}
}; };
typedef void SettingDescProc(IniFile *ini, const SettingDesc *desc, void *grpname, void *base); typedef void SettingDescProc(IniFile *ini, const SettingDesc *desc, const void *grpname, void *base);
static void HandleSettingDescs(IniFile *ini, SettingDescProc *proc) static void HandleSettingDescs(IniFile *ini, SettingDescProc *proc)
{ {

View File

@ -1743,13 +1743,13 @@ static void DrawTile_Station(TileInfo *ti)
t = _station_display_datas[ti->map5]; t = _station_display_datas[ti->map5];
image = *(uint32*)t; image = *(const uint32*)t;
t += sizeof(uint32); t += sizeof(uint32);
if (image & 0x8000) if (image & 0x8000)
image |= image_or_modificator; image |= image_or_modificator;
DrawGroundSprite(image + base_img); DrawGroundSprite(image + base_img);
for(dtss = (DrawTileSeqStruct *)t; (byte)dtss->delta_x != 0x80; dtss++) { for(dtss = (const DrawTileSeqStruct *)t; (byte)dtss->delta_x != 0x80; dtss++) {
if ((byte)dtss->delta_z != 0x80) { if ((byte)dtss->delta_z != 0x80) {
image = dtss->image + base_img; image = dtss->image + base_img;
if (_display_opt & DO_TRANS_BUILDINGS) { if (_display_opt & DO_TRANS_BUILDINGS) {
@ -1760,7 +1760,7 @@ static void DrawTile_Station(TileInfo *ti)
AddSortableSpriteToDraw(image, ti->x + dtss->delta_x, ti->y + dtss->delta_y, dtss->width, dtss->height, dtss->unk, ti->z + dtss->delta_z); AddSortableSpriteToDraw(image, ti->x + dtss->delta_x, ti->y + dtss->delta_y, dtss->width, dtss->height, dtss->unk, ti->z + dtss->delta_z);
} else { } else {
image = *(uint32*)&dtss->height + base_img; /* endian ok */ image = *(const uint32*)&dtss->height + base_img; /* endian ok */
if (_display_opt & DO_TRANS_BUILDINGS) { if (_display_opt & DO_TRANS_BUILDINGS) {
if (image&0x8000) image |= image_or_modificator; if (image&0x8000) image |= image_or_modificator;
@ -1785,13 +1785,13 @@ void StationPickerDrawSprite(int x, int y, int railtype, int image)
t = _station_display_datas[image]; t = _station_display_datas[image];
img = *(uint32*)t; img = *(const uint32*)t;
t += sizeof(uint32); t += sizeof(uint32);
if (img & 0x8000) if (img & 0x8000)
img |= ormod; img |= ormod;
DrawSprite(img, x, y); DrawSprite(img, x, y);
for(dtss = (DrawTileSeqStruct *)t; (byte)dtss->delta_x != 0x80; dtss++) { for(dtss = (const DrawTileSeqStruct *)t; (byte)dtss->delta_x != 0x80; dtss++) {
Point pt = RemapCoords(dtss->delta_x, dtss->delta_y, dtss->delta_z); Point pt = RemapCoords(dtss->delta_x, dtss->delta_y, dtss->delta_z);
DrawSprite((dtss->image | ormod) + railtype, x + pt.x, y + pt.y); DrawSprite((dtss->image | ormod) + railtype, x + pt.x, y + pt.y);
} }

View File

@ -54,9 +54,8 @@ static int CDECL StationNameSorter(const void *a, const void *b)
{ {
char buf1[64]; char buf1[64];
Station *st; Station *st;
SortStruct *cmp1, *cmp2; const SortStruct *cmp1 = (const SortStruct*)a;
cmp1 = (SortStruct*)a; const SortStruct *cmp2 = (const SortStruct*)b;
cmp2 = (SortStruct*)b;
st = DEREF_STATION(cmp1->index); st = DEREF_STATION(cmp1->index);
SET_DPARAM16(0, st->town->townnametype); SET_DPARAM16(0, st->town->townnametype);

View File

@ -712,7 +712,7 @@ void write_langfile(const char *filename, int show_todo)
if (show_todo == 2) { if (show_todo == 2) {
fprintf(stderr, "Warning:%s: String '%s' is untranslated\n", filename, s + 1); fprintf(stderr, "Warning:%s: String '%s' is untranslated\n", filename, s + 1);
} else { } else {
char *s = "<TODO> "; const char *s = "<TODO> ";
while(*s) put_byte(*s++); while(*s) put_byte(*s++);
} }
} }

View File

@ -354,15 +354,15 @@ static byte _last_town_idx;
static int CDECL TownNameSorter(const void *a, const void *b) static int CDECL TownNameSorter(const void *a, const void *b)
{ {
char buf1[64]; char buf1[64];
Town *t; const Town *t;
byte val; byte val;
int r; int r;
t = DEREF_TOWN(*(byte*)a); t = DEREF_TOWN(*(const byte*)a);
SET_DPARAM32(0, t->townnameparts); SET_DPARAM32(0, t->townnameparts);
GetString(buf1, t->townnametype); GetString(buf1, t->townnametype);
if ( (val=*(byte*)b) != _last_town_idx) { if ( (val=*(const byte*)b) != _last_town_idx) {
_last_town_idx = val; _last_town_idx = val;
t = DEREF_TOWN(val); t = DEREF_TOWN(val);
SET_DPARAM32(0, t->townnameparts); SET_DPARAM32(0, t->townnameparts);
@ -376,8 +376,8 @@ static int CDECL TownNameSorter(const void *a, const void *b)
static int CDECL TownPopSorter(const void *a, const void *b) static int CDECL TownPopSorter(const void *a, const void *b)
{ {
Town *ta = DEREF_TOWN(*(byte*)a); const Town *ta = DEREF_TOWN(*(const byte*)a);
Town *tb = DEREF_TOWN(*(byte*)b); const Town *tb = DEREF_TOWN(*(const byte*)b);
int r = ta->population - tb->population; int r = ta->population - tb->population;
if (_town_sort_order & 1) r = -r; if (_town_sort_order & 1) r = -r;
return r; return r;

4
ttd.c
View File

@ -279,10 +279,10 @@ void LoadDriver(int driver, const char *name)
error("No such %s driver: %s\n", dc->name, buffer); error("No such %s driver: %s\n", dc->name, buffer);
} }
var = dc->var; var = dc->var;
if (*var != NULL) ((HalCommonDriver*)*var)->stop(); if (*var != NULL) ((const HalCommonDriver*)*var)->stop();
*var = NULL; *var = NULL;
drv = dd->drv; drv = dd->drv;
if ((err=((HalCommonDriver*)drv)->start(parms)) != NULL) if ((err=((const HalCommonDriver*)drv)->start(parms)) != NULL)
error("Unable to load driver %s(%s). The error was: %s\n", dd->name, dd->longname, err); error("Unable to load driver %s(%s). The error was: %s\n", dd->name, dd->longname, err);
*var = drv; *var = drv;
} }

4
unix.c
View File

@ -279,7 +279,7 @@ char *FiosBrowseTo(const FiosItem *item)
// Get descriptive texts. // Get descriptive texts.
// Returns a path as well as a // Returns a path as well as a
// string describing the path. // string describing the path.
StringID FiosGetDescText(char **path) StringID FiosGetDescText(const char **path)
{ {
*path = _fios_path[0] ? _fios_path : "/"; *path = _fios_path[0] ? _fios_path : "/";
@ -360,7 +360,7 @@ bool FileExists(const char *filename)
static int LanguageCompareFunc(const void *a, const void *b) static int LanguageCompareFunc(const void *a, const void *b)
{ {
return strcmp(*(char**)a, *(char**)b); return strcmp(*(const char* const *)a, *(const char* const *)b);
} }
int GetLanguageList(char **languages, int max) int GetLanguageList(char **languages, int max)

View File

@ -84,11 +84,11 @@ static void DrawTile_Unmovable(TileInfo *ti)
ormod = PLAYER_SPRITE_COLOR(_map_owner[ti->tile]); ormod = PLAYER_SPRITE_COLOR(_map_owner[ti->tile]);
t = _unmovable_display_datas[ti->map5 & 0x7F]; t = _unmovable_display_datas[ti->map5 & 0x7F];
DrawGroundSprite(*(uint16*)t | ormod); DrawGroundSprite(*(const uint16*)t | ormod);
t += sizeof(uint16); t += sizeof(uint16);
for(dtss = (DrawTileSeqStruct *)t; (byte)dtss->delta_x != 0x80; dtss++) { for(dtss = (const DrawTileSeqStruct *)t; (byte)dtss->delta_x != 0x80; dtss++) {
image = dtss->image; image = dtss->image;
if (_display_opt & DO_TRANS_BUILDINGS) { if (_display_opt & DO_TRANS_BUILDINGS) {
image |= ormod; image |= ormod;

View File

@ -383,10 +383,10 @@ static void DrawWaterStuff(TileInfo *ti, const byte *t, uint32 palette, uint bas
const WaterDrawTileStruct *wdts; const WaterDrawTileStruct *wdts;
uint32 image; uint32 image;
DrawGroundSprite(*(uint16*)t); DrawGroundSprite(*(const uint16*)t);
t += sizeof(uint16); t += sizeof(uint16);
for(wdts = (WaterDrawTileStruct *)t; (byte)wdts->delta_x != 0x80; wdts++) { for(wdts = (const WaterDrawTileStruct *)t; (byte)wdts->delta_x != 0x80; wdts++) {
image = wdts->image + base; image = wdts->image + base;
if (_display_opt & DO_TRANS_BUILDINGS) { if (_display_opt & DO_TRANS_BUILDINGS) {
image |= palette; image |= palette;
@ -429,10 +429,10 @@ void DrawShipDepotSprite(int x, int y, int image)
const WaterDrawTileStruct *wdts; const WaterDrawTileStruct *wdts;
t = _shipdepot_display_seq[image]; t = _shipdepot_display_seq[image];
DrawSprite(*(uint16*)t, x, y); DrawSprite(*(const uint16*)t, x, y);
t += sizeof(uint16); t += sizeof(uint16);
for(wdts = (WaterDrawTileStruct *)t; (byte)wdts->delta_x != 0x80; wdts++) { for(wdts = (const WaterDrawTileStruct *)t; (byte)wdts->delta_x != 0x80; wdts++) {
Point pt = RemapCoords(wdts->delta_x, wdts->delta_y, wdts->delta_z); Point pt = RemapCoords(wdts->delta_x, wdts->delta_y, wdts->delta_z);
DrawSprite(wdts->image + PLAYER_SPRITE_COLOR(_local_player), x + pt.x, y + pt.y); DrawSprite(wdts->image + PLAYER_SPRITE_COLOR(_local_player), x + pt.x, y + pt.y);
} }

View File

@ -1741,7 +1741,7 @@ char *FiosBrowseTo(const FiosItem *item)
// Get descriptive texts. // Get descriptive texts.
// Returns a path as well as a // Returns a path as well as a
// string describing the path. // string describing the path.
StringID FiosGetDescText(char **path) StringID FiosGetDescText(const char **path)
{ {
char root[4]; char root[4];
DWORD spc, bps, nfc, tnc; DWORD spc, bps, nfc, tnc;
@ -1812,7 +1812,7 @@ bool FileExists(const char *filename)
static int CDECL LanguageCompareFunc(const void *a, const void *b) static int CDECL LanguageCompareFunc(const void *a, const void *b)
{ {
return strcmp(*(char**)a, *(char**)b); return strcmp(*(const char* const *)a, *(const char* const *)b);
} }
int GetLanguageList(char **languages, int max) int GetLanguageList(char **languages, int max)