Get rid of standard string functions

This commit is contained in:
Lephenixnoir 2021-09-19 19:16:50 +02:00
parent e586f9fba5
commit c8d897e819
Signed by: Lephenixnoir
GPG Key ID: 1BBA026E13FC0495
11 changed files with 42 additions and 157 deletions

View File

@ -138,8 +138,8 @@ void CGDAppendNum0_999(const char *pszText,int iNum,int iMinDigits,char *pszBuf)
void CGDAppendHex32(const char *pszText,int iNum,int iDigits,char *pszBuf)
{
CGDstrcpy(pszBuf, pszText);
pszBuf += CGDstrlen(pszText);
strcpy(pszBuf, pszText);
pszBuf += strlen(pszText);
for(int i = 0; i < iDigits; i++)
{
int c = (iNum >> (i * 4)) & 0xf;
@ -149,121 +149,16 @@ void CGDAppendHex32(const char *pszText,int iNum,int iDigits,char *pszBuf)
pszBuf[iDigits] = 0;
}
int CGDstrlen(const char *pszText)
int strnicmp(const char *s1,const char *s2,int count)
{
int i = 0;
while(pszText[i])
{
i++;
for(int i = 0; i < count; i++) {
int c1 = (s1[i] >= 'a' && s1[i] <= 'z') ? s1[i] & ~0x20 : s1[i];
int c2 = (s2[i] >= 'a' && s2[i] <= 'z') ? s2[i] & ~0x20 : s2[i];
if(c1 != c2 || !c1 || !c2)
return c1 - c2;
}
return i;
}
void CGDstrcpy(char *pszBuf,const char *pszText)
{
int i = 0;
while(pszText[i])
{
pszBuf[i] = pszText[i];
i++;
}
pszBuf[i] = 0;
}
void CGDstrncpy(char *pszBuf,const char *pszText,int iLen)
{
int i = 0;
while(pszText[i])
{
if(iLen == i)
{
return;
}
pszBuf[i] = pszText[i];
i++;
}
pszBuf[i] = 0;
}
int CGDstrcmp (const char*s1,const char*s2)
{
while(s1[0])
{
unsigned char c1 = (unsigned char)s1[0];
unsigned char c2 = (unsigned char)s2[0];
if(c1 !=c2)
{
return 1;//who cares 1/-1, important is match/nonmatch
}
s1++;
s2++;
}
return (unsigned char)s2[0]>0;
}
int CGDstrncmp (const char*s1,const char*s2,int iLen)
{
if(!iLen)
{
return 0;
}
while(s1[0])
{
unsigned char c1 = (unsigned char)s1[0];
unsigned char c2 = (unsigned char)s2[0];
if(c1 !=c2)
{
return 1;//who cares 1/-1, important is match/nonmatch
}
s1++;
s2++;
iLen--;
if(!iLen)
{
return 0;
}
}
return (unsigned char)s2[0]>0;
}
static unsigned char Upper(unsigned char c)
{
if((c>='a')&&(c<='z'))
{
c -='a'-'A';
}
return c;
}
int CGDstrnicmp (const char*s1,const char*s2,int iLen)
{
if(!iLen)
{
return 0;
}
while(s1[0])
{
unsigned char c1 = Upper((unsigned char)s1[0]);
unsigned char c2 = Upper((unsigned char)s2[0]);
if(c1 !=c2)
{
return 1;//who cares 1/-1, important is match/nonmatch
}
s1++;
s2++;
iLen--;
if(!iLen)
{
return 0;
}
}
return (unsigned char)s2[0]>0;
return 0;
}
///////////////////////////////////////////////////////////////////////////////
@ -726,13 +621,13 @@ int main(void)
autostart = autostart_;
/* Override version detection for single-episode Ultimate Doom WADs */
if (!CGDstrcmp(wads[choice].name, "doomu1.wad"))
if (!strcmp(wads[choice].name, "doomu1.wad"))
CGD_SingleEpisodeUltimate = 1;
if (!CGDstrcmp(wads[choice].name, "doomu2.wad"))
if (!strcmp(wads[choice].name, "doomu2.wad"))
CGD_SingleEpisodeUltimate = 2;
if (!CGDstrcmp(wads[choice].name, "doomu3.wad"))
if (!strcmp(wads[choice].name, "doomu3.wad"))
CGD_SingleEpisodeUltimate = 3;
if (!CGDstrcmp(wads[choice].name, "doomu4.wad"))
if (!strcmp(wads[choice].name, "doomu4.wad"))
CGD_SingleEpisodeUltimate = 4;
unsigned tmp=((unsigned)getSecondaryVramAddress()+3)&(~3);

View File

@ -229,7 +229,7 @@ void F_Ticker (void)
if ( gamemode == commercial)
return;
if (!finalestage && finalecount>CGDstrlen (finaletext)*TEXTSPEED + TEXTWAIT)
if (!finalestage && finalecount>strlen (finaletext)*TEXTSPEED + TEXTWAIT)
{
finalecount = 0;
finalestage = 1;

View File

@ -507,7 +507,7 @@ void G_Ticker (void)
case BTS_SAVEGAME:
if (!savedescription[0])
CGDstrcpy(savedescription, "NET GAME");
strcpy(savedescription, "NET GAME");
savegameslot = (players[0].cmd.buttons & BTS_SAVEMASK)>>BTS_SAVESHIFT;
gameaction = ga_savegame;
@ -1008,7 +1008,7 @@ void G_DoLoadGame (void)
void G_SaveGame( int slot, char* description )
{
savegameslot = slot;
CGDstrcpy (savedescription, description);
strcpy (savedescription, description);
sendsave = true;
}
@ -1075,7 +1075,7 @@ boolean G_DoSaveGame (void)
dfw->data = savebuffer;
}
CGDstrcpy(dfw->filename, name);
strcpy(dfw->filename, name);
dfw->size = length;
gameaction = ga_nothing;

View File

@ -492,7 +492,7 @@ boolean HU_Responder(event_t *ev)
// leave chat mode and notify that it was sent
chat_on = false;
CGDstrcpy(lastmessage, chat_macros[c]);
strcpy(lastmessage, chat_macros[c]);
hu_stuff_plr->message = lastmessage;
eatkey = true;
}
@ -514,7 +514,7 @@ boolean HU_Responder(event_t *ev)
chat_on = false;
if (w_chat.l.len)
{
CGDstrcpy(lastmessage, w_chat.l.l);
strcpy(lastmessage, w_chat.l.l);
hu_stuff_plr->message = lastmessage;
}
}

View File

@ -484,7 +484,7 @@ void M_ReadSaveStrings(void)
fd = Bfile_OpenFile_OS(fc_path, READ, 0);
if(fd < 0) {
CGDstrcpy(savegamestrings[i], EMPTYSTRING);
strcpy(savegamestrings[i], EMPTYSTRING);
LoadMenu[i].status = 0;
}
else {
@ -533,7 +533,7 @@ void M_DrawSaveLoadBorder(int x,int y,int height,int count)
for (i = 0; i < 24; i++)
V_DrawPatchDirect (x+8*i,y+7,0,center);
V_DrawPatchDirect (x,y+7,0,right);
V_DrawPatchDirect (x+8*24,y+7,0,right);
y += height;
}
@ -610,7 +610,7 @@ void M_SaveSelect(int choice)
saveStringEnter = 1;
saveSlot = choice;
CGDstrcpy(saveOldString,savegamestrings[choice]);
strcpy(saveOldString,savegamestrings[choice]);
if (!strcmp(savegamestrings[choice],EMPTYSTRING))
savegamestrings[choice][0] = 0;
saveCharIndex = strlen(savegamestrings[choice]);
@ -994,7 +994,7 @@ int M_StringWidth(char* string)
int w = 0;
int c;
for (i = 0;i < CGDstrlen(string);i++)
for (i = 0;i < strlen(string);i++)
{
c = toupper_int(string[i]) - HU_FONTSTART;
if (c < 0 || c >= HU_FONTSIZE)
@ -1018,7 +1018,7 @@ int M_StringHeight(char* string)
int height = SHORT(hu_font[0]->height);
h = height;
for (i = 0;i < CGDstrlen(string);i++)
for (i = 0;i < strlen(string);i++)
if (string[i] == '\n')
h += height;
@ -1109,7 +1109,7 @@ boolean M_Responder (event_t* ev)
case KEY_ESCAPE:
saveStringEnter = 0;
CGDstrcpy(&savegamestrings[saveSlot][0],saveOldString);
strcpy(&savegamestrings[saveSlot][0],saveOldString);
break;
case KEY_ENTER:
@ -1308,18 +1308,18 @@ void M_Drawer (void)
y = (short)(100 - M_StringHeight(messageString)/2);
while(*(messageString+start))
{
for (i = 0;i < CGDstrlen(messageString+start);i++)
for (i = 0;i < strlen(messageString+start);i++)
if (*(messageString+start+i) == '\n')
{
memset(string,0,40);
CGDstrncpy(string,messageString+start,i);
strncpy(string,messageString+start,i);
start += i+1;
break;
}
if (i == CGDstrlen(messageString+start))
if (i == strlen(messageString+start))
{
CGDstrcpy(string,messageString+start);
strcpy(string,messageString+start);
start += i;
}

View File

@ -18,24 +18,14 @@ void * CGDRealloc (void *p, int iSize);
void D_DoomMain();
void CGDAppendNum09(const char *pszText,int iNum,char *pszBuf);
int CGDstrlen(const char *pszText);
void CGDstrcpy(char *pszBuf,const char *pszText);
int CGDstrcmp (const char*s1,const char*s2);
int CGDstrncmp (const char*s1,const char*s2,int iLen);
int CGDstrnicmp (const char*s1,const char*s2,int iLen);
void CGDstrncpy(char *pszBuf,const char *pszText,int iLen);
void CGDAppendNum0_999(const char *pszText,int iNum,int iMinDigits,char *pszBuf);
void CGDAppendHex32(const char *pszText,int iNum, int iDigits,char *pszBuf);
int abs(int x);
int strnicmp (const char*s1,const char*s2,int iLen);
void I_Error (const char *error, ...);
//force compiler error on use following:
#define strcpy 12
#define strnicmp 22
//return ptr to flash
int FindInFlash(const void **buf, int size, int readpos);
//direct read from flash

View File

@ -291,7 +291,7 @@ void P_LoadSectors (int lump)
ss->floorheight = SHORT(ms->floorheight)<<FRACBITS;
ss->ceilingheight = SHORT(ms->ceilingheight)<<FRACBITS;
//printf("S%if%i|c%i\n",i,ss->floorheight>>16,ss->ceilingheight>>16);
CGDstrncpy(tmp,ms->floorpic,8);tmp[8]=0;
strncpy(tmp,ms->floorpic,8);tmp[8]=0;
//printf ("tmp= %s \n",tmp);
/*printf ("ms->floorpic= %s \n",ms->floorpic);
printf ("tmp= %s \n",&tmp);
@ -299,7 +299,7 @@ void P_LoadSectors (int lump)
ss->floorpic = R_FlatNumForName(ms->floorpic);
ss->ceilingpic = R_FlatNumForName(ms->ceilingpic);*/
ss->floorpic = (short)R_FlatNumForName(tmp);
CGDstrncpy(tmp,ms->ceilingpic,8);tmp[8]=0;
strncpy(tmp,ms->ceilingpic,8);tmp[8]=0;
//printf ("tmp= %s \n",tmp);
ss->ceilingpic = (short)R_FlatNumForName(tmp);
//printf("gotf: %i, gotc: %i \n",ss->floorpic,ss->ceilingpic);

View File

@ -446,7 +446,7 @@ void R_InitTextures (void)
for (i=0 ; i<nummappatches ; i++)
{
//CGDstrncpy (name,name_p+i*8, 8);
//strncpy (name,name_p+i*8, 8);
//printf ("%i \n",i);
//printf ("%s \n",name);
//printf ("%i \n",sizeof(name));
@ -719,7 +719,7 @@ int R_CheckTextureNumForName (const char *name)
for(i=0 ; i<numtextures ; i++)
{
if(!CGDstrnicmp(textures[i]->name,name,8))
if(!strnicmp(textures[i]->name,name,8))
{
return i;
}

View File

@ -256,7 +256,7 @@
// Height, in lines.
#define ST_OUTHEIGHT 1
#define ST_MAPWIDTH (CGDstrlen(mapnames[(gameepisode-1)*9+(gamemap-1)]))
#define ST_MAPWIDTH (strlen(mapnames[(gameepisode-1)*9+(gamemap-1)]))
#define ST_MAPTITLEX (SCREENWIDTH - ST_MAPWIDTH * ST_CHATFONTWIDTH)

View File

@ -97,10 +97,10 @@ static int W_AddFile ()
startlump = numlumps;
Flash_ReadFile(&header, sizeof(header),0);
if (CGDstrncmp(header.identification,"IWAD",4))
if (strncmp(header.identification,"IWAD",4))
{
// Homebrew levels?
if (CGDstrncmp(header.identification,"PWAD",4))
if (strncmp(header.identification,"PWAD",4))
return 0; // CX port
//I_Error ("Wad file %s doesn't have IWAD or PWAD id\n", filename);
}
@ -135,7 +135,7 @@ static int W_AddFile ()
lump_p->position = LONG(fileinfo->filepos);
lump_p->size = LONG(fileinfo->size);
memset(lump_p->name,0,8);//hack
CGDstrncpy (lump_p->name, fileinfo->name, 8);
strncpy (lump_p->name, fileinfo->name, 8);
}
//Nspire has no alloca() function for temporary memory, so we have to use malloc() and free() to compensate
@ -219,7 +219,7 @@ int W_CheckNumForName (const char* name)
while(lump_p-- != lumpinfo)
{
if(CGDstrnicmp(name,lump_p->name,8)==0 )
if(strnicmp(name,lump_p->name,8)==0 )
{
return lump_p - lumpinfo;
}

View File

@ -972,7 +972,7 @@ static void WI_loadData(void)
wi_stuff_anim_t* a;
if (gamemode == commercial)
CGDstrcpy(name, "INTERPIC");
strcpy(name, "INTERPIC");
else
{
//sprintf(name, "WIMAP%d", wbs->epsd);
@ -982,7 +982,7 @@ static void WI_loadData(void)
if ( gamemode == retail )
{
if (wbs->epsd == 3)
CGDstrcpy(name,"INTERPIC");
strcpy(name,"INTERPIC");
}
// background