mirror of
https://github.com/DrBeef/Raze.git
synced 2024-11-15 17:01:51 +00:00
Define Batoi/Batol to strtol(...) in compat.h and use these when necessary.
That is, everyplace a user input is to be converted. The only remaining instance of atoi() is now atoi(s_buildDate). git-svn-id: https://svn.eduke32.com/eduke32@2374 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
parent
80bd1bb4e4
commit
8b7a4dab9b
12 changed files with 45 additions and 45 deletions
|
@ -499,8 +499,8 @@ static inline uint16_t system_15bit_rand(void) { return ((uint16_t)rand())&0x7ff
|
|||
# define Bstrlen strlen
|
||||
# define Bstrchr strchr
|
||||
# define Bstrrchr strrchr
|
||||
# define Batoi atoi
|
||||
# define Batol atol
|
||||
# define Batoi(str) ((int32_t)strtol(str, NULL, 10))
|
||||
# define Batol(str) (strtol(str, NULL, 10))
|
||||
# define Bstrtol strtol
|
||||
# define Bstrtoul strtoul
|
||||
# define Bstrtod strtod
|
||||
|
|
|
@ -237,20 +237,20 @@ char *Bstrrchr(const char *s, int32_t c)
|
|||
|
||||
int32_t Batoi(const char *nptr)
|
||||
{
|
||||
return atoi(nptr);
|
||||
return strtol(nptr, NULL, 10);
|
||||
}
|
||||
|
||||
int32_t Batol(const char *nptr)
|
||||
{
|
||||
return atol(nptr);
|
||||
return strtol(nptr, NULL, 10);
|
||||
}
|
||||
|
||||
int32_t int32_t Bstrtol(const char *nptr, char **endptr, int32_t base)
|
||||
int32_t Bstrtol(const char *nptr, char **endptr, int32_t base)
|
||||
{
|
||||
return strtol(nptr,endptr,base);
|
||||
}
|
||||
|
||||
uint32_t int32_t Bstrtoul(const char *nptr, char **endptr, int32_t base)
|
||||
uint32_t Bstrtoul(const char *nptr, char **endptr, int32_t base)
|
||||
{
|
||||
return strtoul(nptr,endptr,base);
|
||||
}
|
||||
|
|
|
@ -15405,7 +15405,7 @@ int32_t printext16(int32_t xpos, int32_t ypos, int16_t col, int16_t backcol, con
|
|||
smallbuf[1] = '\0';
|
||||
}
|
||||
if (!(fontsize & 4))
|
||||
col = editorcolors[atol(smallbuf)];
|
||||
col = editorcolors[Batol(smallbuf)];
|
||||
|
||||
if (name[i+1] == ',' && isdigit(name[i+2]))
|
||||
{
|
||||
|
@ -15432,7 +15432,7 @@ int32_t printext16(int32_t xpos, int32_t ypos, int16_t col, int16_t backcol, con
|
|||
}
|
||||
|
||||
if (!(fontsize & 4))
|
||||
backcol = editorcolors[atol(smallbuf)];
|
||||
backcol = editorcolors[Batol(smallbuf)];
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
@ -15511,7 +15511,7 @@ void printext256(int32_t xpos, int32_t ypos, int16_t col, int16_t backcol, const
|
|||
}
|
||||
smallbuf[bi++]=0;
|
||||
if (col)
|
||||
col = atol(smallbuf);
|
||||
col = Batol(smallbuf);
|
||||
|
||||
p = getpal(col);
|
||||
|
||||
|
@ -15564,7 +15564,7 @@ void printext256(int32_t xpos, int32_t ypos, int16_t col, int16_t backcol, const
|
|||
i++;
|
||||
}
|
||||
smallbuf[bi++]=0;
|
||||
if (col)col = atol(smallbuf);
|
||||
if (col)col = Batol(smallbuf);
|
||||
continue;
|
||||
}
|
||||
letptr = &fontptr[name[i]<<3];
|
||||
|
|
|
@ -1579,14 +1579,14 @@ void OSD_Printf(const char *fmt, ...)
|
|||
{
|
||||
smallbuf[0] = *(chp);
|
||||
smallbuf[1] = '\0';
|
||||
p = atol(smallbuf);
|
||||
p = Batol(smallbuf);
|
||||
continue;
|
||||
}
|
||||
|
||||
smallbuf[0] = *(chp++);
|
||||
smallbuf[1] = *(chp);
|
||||
smallbuf[2] = '\0';
|
||||
p = atol(smallbuf);
|
||||
p = Batol(smallbuf);
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -2064,7 +2064,7 @@ int32_t osdcmd_cvar_set(const osdfuncparm_t *parm)
|
|||
return OSDCMD_OK;
|
||||
}
|
||||
|
||||
val = atoi(parm->parms[0]);
|
||||
val = Batoi(parm->parms[0]);
|
||||
if (cvars[i].type & CVAR_BOOL) val = val != 0;
|
||||
|
||||
if (val < cvars[i].min || val > cvars[i].max)
|
||||
|
|
|
@ -6203,7 +6203,7 @@ int32_t polymost_printext256(int32_t xpos, int32_t ypos, int16_t col, int16_t ba
|
|||
c++;
|
||||
}
|
||||
smallbuf[bi++]=0;
|
||||
if (col)col = atol(smallbuf); /* FIXME: atol is unsafe */
|
||||
if (col)col = Batol(smallbuf);
|
||||
if ((unsigned)col >= 256)
|
||||
col = 0;
|
||||
|
||||
|
|
|
@ -729,7 +729,7 @@ int32_t CONFIG_ReadSetup(void)
|
|||
i = 0;
|
||||
while (ptr != NULL && i < 3)
|
||||
{
|
||||
palptr[i++] = atoi(ptr);
|
||||
palptr[i++] = Batoi(ptr);
|
||||
ptr = strtok(NULL,",");
|
||||
}
|
||||
if (i == 3)
|
||||
|
|
|
@ -401,14 +401,14 @@ int32_t G_PrintGameText(int32_t f, int32_t tile, int32_t x, int32_t y, const
|
|||
{
|
||||
smallbuf[0] = *(t);
|
||||
smallbuf[1] = '\0';
|
||||
p = atoi(smallbuf);
|
||||
p = Batoi(smallbuf);
|
||||
continue;
|
||||
}
|
||||
|
||||
smallbuf[0] = *(t++);
|
||||
smallbuf[1] = *(t);
|
||||
smallbuf[2] = '\0';
|
||||
p = atoi(smallbuf);
|
||||
p = Batoi(smallbuf);
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -503,13 +503,13 @@ int32_t minitext_(int32_t x,int32_t y,const char *t,int32_t s,int32_t p,int32_t
|
|||
{
|
||||
smallbuf[0] = *(t);
|
||||
smallbuf[1] = '\0';
|
||||
p = atoi(smallbuf);
|
||||
p = Batoi(smallbuf);
|
||||
continue;
|
||||
}
|
||||
smallbuf[0] = *(t++);
|
||||
smallbuf[1] = *(t);
|
||||
smallbuf[2] = '\0';
|
||||
p = atoi(smallbuf);
|
||||
p = Batoi(smallbuf);
|
||||
continue;
|
||||
}
|
||||
ch = Btoupper(*t);
|
||||
|
@ -8668,7 +8668,7 @@ static void G_CheckCommandLine(int32_t argc, const char **argv)
|
|||
{
|
||||
if (argc > i+1)
|
||||
{
|
||||
g_netPort = atoi(argv[i+1]);
|
||||
g_netPort = Batoi(argv[i+1]);
|
||||
i++;
|
||||
}
|
||||
i++;
|
||||
|
@ -8778,7 +8778,7 @@ static void G_CheckCommandLine(int32_t argc, const char **argv)
|
|||
{
|
||||
if (argc > i+1)
|
||||
{
|
||||
uint32_t j = atol((char *)argv[i+1]);
|
||||
uint32_t j = Batol((char *)argv[i+1]);
|
||||
if (j>=10000000 && j<=99999999)
|
||||
{
|
||||
g_scriptDateVersion = j;
|
||||
|
@ -8809,7 +8809,7 @@ static void G_CheckCommandLine(int32_t argc, const char **argv)
|
|||
{
|
||||
if (argc > i+1)
|
||||
{
|
||||
uint32_t j = atol((char *)argv[i+1]);
|
||||
uint32_t j = Batol((char *)argv[i+1]);
|
||||
MAXCACHE1DSIZE = j<<10;
|
||||
initprintf("Cache size: %dkB\n",j);
|
||||
i++;
|
||||
|
@ -8890,7 +8890,7 @@ static void G_CheckCommandLine(int32_t argc, const char **argv)
|
|||
case 'l':
|
||||
ud.warp_on = 1;
|
||||
c++;
|
||||
ud.m_level_number = ud.level_number = (atoi(c)-1)%MAXLEVELS;
|
||||
ud.m_level_number = ud.level_number = (Batoi(c)-1)%MAXLEVELS;
|
||||
break;
|
||||
case 'm':
|
||||
if (*(c+1) != 'a' && *(c+1) != 'A')
|
||||
|
@ -8921,7 +8921,7 @@ static void G_CheckCommandLine(int32_t argc, const char **argv)
|
|||
case 'q':
|
||||
initprintf("Fake multiplayer mode.\n");
|
||||
if (*(++c) == 0) ud.multimode = 1;
|
||||
else ud.multimode = atoi(c)%17;
|
||||
else ud.multimode = Batoi(c)%17;
|
||||
ud.m_coop = ud.coop = 0;
|
||||
ud.m_marker = ud.marker = 1;
|
||||
ud.m_respawn_monsters = ud.respawn_monsters = 1;
|
||||
|
@ -8934,7 +8934,7 @@ static void G_CheckCommandLine(int32_t argc, const char **argv)
|
|||
break;
|
||||
case 's':
|
||||
c++;
|
||||
ud.m_player_skill = ud.player_skill = (atoi(c)%5);
|
||||
ud.m_player_skill = ud.player_skill = (Batoi(c)%5);
|
||||
if (ud.m_player_skill == 4)
|
||||
ud.m_respawn_monsters = ud.respawn_monsters = 1;
|
||||
break;
|
||||
|
@ -8992,7 +8992,7 @@ static void G_CheckCommandLine(int32_t argc, const char **argv)
|
|||
case 'v':
|
||||
c++;
|
||||
ud.warp_on = 1;
|
||||
ud.m_volume_number = ud.volume_number = atoi(c)-1;
|
||||
ud.m_volume_number = ud.volume_number = Batoi(c)-1;
|
||||
break;
|
||||
case 'w':
|
||||
ud.coords = 1;
|
||||
|
@ -9020,7 +9020,7 @@ static void G_CheckCommandLine(int32_t argc, const char **argv)
|
|||
break;
|
||||
case 'z':
|
||||
c++;
|
||||
g_scriptDebug = atoi(c);
|
||||
g_scriptDebug = Batoi(c);
|
||||
if (!g_scriptDebug)
|
||||
g_scriptDebug = 1;
|
||||
break;
|
||||
|
@ -9869,7 +9869,7 @@ int32_t app_main(int32_t argc,const char **argv)
|
|||
|
||||
#ifdef _WIN32
|
||||
|
||||
// initprintf("build %d\n",(uint8_t)atoi(BUILDDATE));
|
||||
// initprintf("build %d\n",(uint8_t)Batoi(BUILDDATE));
|
||||
|
||||
if (ud.config.CheckForUpdates == 1)
|
||||
{
|
||||
|
@ -9878,10 +9878,10 @@ int32_t app_main(int32_t argc,const char **argv)
|
|||
initprintf("Checking for updates...\n");
|
||||
if (G_GetVersionFromWebsite(tempbuf))
|
||||
{
|
||||
initprintf("Current version is %d",atoi(tempbuf));
|
||||
initprintf("Current version is %d",Batoi(tempbuf));
|
||||
ud.config.LastUpdateCheck = time(NULL);
|
||||
|
||||
if (atoi(tempbuf) > atoi(s_buildDate))
|
||||
if (Batoi(tempbuf) > atoi(s_buildDate))
|
||||
{
|
||||
if (wm_ynbox("EDuke32","A new version of EDuke32 is available. "
|
||||
"Browse to http://eduke32.sourceforge.net now?"))
|
||||
|
|
|
@ -1471,13 +1471,13 @@ static void C_GetNextVarType(int32_t type)
|
|||
if (!type && !g_labelsOnly && (isdigit(*textptr) || ((*textptr == '-') && (isdigit(*(textptr+1))))))
|
||||
{
|
||||
if (!(g_numCompilerErrors || g_numCompilerWarnings) && g_scriptDebug)
|
||||
initprintf("%s:%d: debug: accepted constant %ld in place of gamevar.\n",g_szScriptFileName,g_lineNumber,atol(textptr));
|
||||
initprintf("%s:%d: debug: accepted constant %ld in place of gamevar.\n",g_szScriptFileName,g_lineNumber,Batol(textptr));
|
||||
bitptr[(g_scriptPtr-script)>>3] &= ~(BITPTR_POINTER<<((g_scriptPtr-script)&7));
|
||||
*g_scriptPtr++=MAXGAMEVARS;
|
||||
if (tolower(textptr[1])=='x')
|
||||
sscanf(textptr+2,"%" PRIxPTR "",g_scriptPtr);
|
||||
else
|
||||
*g_scriptPtr=atoi(textptr);
|
||||
*g_scriptPtr=Batoi(textptr);
|
||||
bitptr[(g_scriptPtr-script)>>3] &= ~(BITPTR_POINTER<<((g_scriptPtr-script)&7));
|
||||
g_scriptPtr++;
|
||||
#if 1
|
||||
|
@ -1492,7 +1492,7 @@ static void C_GetNextVarType(int32_t type)
|
|||
if (!type)
|
||||
{
|
||||
if (!(g_numCompilerErrors || g_numCompilerWarnings) && g_scriptDebug)
|
||||
initprintf("%s:%d: debug: flagging gamevar as negative.\n",g_szScriptFileName,g_lineNumber); //,atol(textptr));
|
||||
initprintf("%s:%d: debug: flagging gamevar as negative.\n",g_szScriptFileName,g_lineNumber); //,Batol(textptr));
|
||||
f = (MAXGAMEVARS<<1);
|
||||
}
|
||||
else
|
||||
|
@ -1802,13 +1802,13 @@ static int32_t C_GetNextValue(int32_t type)
|
|||
while (i > 0);
|
||||
|
||||
if (!(g_numCompilerErrors || g_numCompilerWarnings) && g_scriptDebug > 1)
|
||||
initprintf("%s:%d: debug: accepted constant %ld.\n",g_szScriptFileName,g_lineNumber,atol(textptr));
|
||||
initprintf("%s:%d: debug: accepted constant %ld.\n",g_szScriptFileName,g_lineNumber,Batol(textptr));
|
||||
bitptr[(g_scriptPtr-script)>>3] &= ~(BITPTR_POINTER<<((g_scriptPtr-script)&7));
|
||||
|
||||
if (tolower(textptr[1])=='x')
|
||||
sscanf(textptr+2,"%" PRIxPTR "",g_scriptPtr);
|
||||
else
|
||||
*g_scriptPtr = atol(textptr);
|
||||
*g_scriptPtr = Batol(textptr);
|
||||
|
||||
g_scriptPtr++;
|
||||
|
||||
|
|
|
@ -997,7 +997,7 @@ static void C_GetNextVarType(int32_t type)
|
|||
// literal numeric constant where gamevar expected
|
||||
|
||||
// if (!(g_numCompilerErrors || g_numCompilerWarnings) && g_scriptDebug)
|
||||
// initprintf("%s:%d: debug: accepted constant %d in place of gamevar.\n",g_szScriptFileName,g_lineNumber,atol(textptr));
|
||||
// initprintf("%s:%d: debug: accepted constant %d in place of gamevar.\n",g_szScriptFileName,g_lineNumber,Batol(textptr));
|
||||
|
||||
parse_integer_literal(&num);
|
||||
//thenum=num;
|
||||
|
@ -1087,7 +1087,7 @@ static void C_GetNextVarType(int32_t type)
|
|||
if (type==0)
|
||||
{
|
||||
// if (!(g_numCompilerErrors || g_numCompilerWarnings) && g_scriptDebug)
|
||||
// initprintf("%s:%d: debug: flagging gamevar as negative.\n",g_szScriptFileName,g_lineNumber,atol(textptr));
|
||||
// initprintf("%s:%d: debug: flagging gamevar as negative.\n",g_szScriptFileName,g_lineNumber,Batol(textptr));
|
||||
flags = M32_FLAG_NEGATE;
|
||||
}
|
||||
else
|
||||
|
@ -1507,7 +1507,7 @@ static int32_t C_GetNextValue(int32_t type)
|
|||
while (i > 0);
|
||||
|
||||
// if (!(g_numCompilerErrors || g_numCompilerWarnings) && g_scriptDebug > 1)
|
||||
// initprintf("%s:%d: debug: accepted constant %d.\n",g_szScriptFileName,g_lineNumber,atol(textptr));
|
||||
// initprintf("%s:%d: debug: accepted constant %d.\n",g_szScriptFileName,g_lineNumber,Batol(textptr));
|
||||
|
||||
parse_integer_literal(g_scriptPtr);
|
||||
|
||||
|
|
|
@ -81,7 +81,7 @@ void Net_Connect(const char *srvaddr)
|
|||
|
||||
addrstr = strtok((char *)srvaddr, ":");
|
||||
enet_address_set_host(&address, addrstr);
|
||||
address.port = atoi((addrstr = strtok(NULL, ":")) == NULL ? "23513" : addrstr);
|
||||
address.port = Batoi((addrstr = strtok(NULL, ":")) == NULL ? "23513" : addrstr);
|
||||
|
||||
g_netClientPeer = enet_host_connect(g_netClient, &address, CHAN_MAX, 0);
|
||||
|
||||
|
|
|
@ -631,9 +631,9 @@ static int32_t osdcmd_crosshaircolor(const osdfuncparm_t *parm)
|
|||
OSD_Printf("crosshaircolor: r:%d g:%d b:%d\n",CrosshairColors.r,CrosshairColors.g,CrosshairColors.b);
|
||||
return OSDCMD_SHOWHELP;
|
||||
}
|
||||
r = atol(parm->parms[0]);
|
||||
g = atol(parm->parms[1]);
|
||||
b = atol(parm->parms[2]);
|
||||
r = Batol(parm->parms[0]);
|
||||
g = Batol(parm->parms[1]);
|
||||
b = Batol(parm->parms[2]);
|
||||
G_SetCrosshairColor(r,g,b);
|
||||
OSD_Printf("%s\n", parm->raw);
|
||||
return OSDCMD_OK;
|
||||
|
@ -647,7 +647,7 @@ static int32_t osdcmd_setbrightness(const osdfuncparm_t *parm)
|
|||
// OSD_Printf("\"setbri\" \"%d\"\n",ud.brightness>>2);
|
||||
return OSDCMD_SHOWHELP;
|
||||
}
|
||||
ud.brightness = atoi(parm->parms[0])<<2;
|
||||
ud.brightness = Batoi(parm->parms[0])<<2;
|
||||
setbrightness(ud.brightness>>2,&g_player[screenpeek].ps->palette[0],0);
|
||||
OSD_Printf("setbrightness %d\n",ud.brightness>>2);
|
||||
return OSDCMD_OK;
|
||||
|
@ -1127,7 +1127,7 @@ static int32_t osdcmd_inittimer(const osdfuncparm_t *parm)
|
|||
return OSDCMD_SHOWHELP;
|
||||
}
|
||||
|
||||
j = atol(parm->parms[0]);
|
||||
j = Batol(parm->parms[0]);
|
||||
if (g_timerTicsPerSecond == j)
|
||||
return OSDCMD_OK;
|
||||
uninittimer();
|
||||
|
|
|
@ -100,7 +100,7 @@ int32_t G_GetVersionFromWebsite(char *buffer)
|
|||
Bmemcpy(&otherbuf,&tempbuf,sizeof(otherbuf));
|
||||
|
||||
strtok(otherbuf," ");
|
||||
if (atol(strtok(NULL," ")) == 200)
|
||||
if (Batol(strtok(NULL," ")) == 200)
|
||||
{
|
||||
for (i=0; (unsigned)i<strlen(tempbuf); i++) // HACK: all of this needs to die a fiery death; we just skip to the content
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue