mirror of
https://github.com/libretro/libretro-prboom.git
synced 2024-11-23 07:59:39 +00:00
Reduce strlens
This commit is contained in:
parent
b22a6b19fd
commit
dd6192e94e
@ -1662,7 +1662,8 @@ const char *I_DoomExeDir(void)
|
||||
*/
|
||||
dbool HasTrailingSlash(const char* dn)
|
||||
{
|
||||
return ( dn && ((dn[strlen(dn)-1] == '/') || (dn[strlen(dn)-1] == '\\')));
|
||||
size_t dn_len = strlen(dn);
|
||||
return ( dn && ((dn[dn_len - 1] == '/') || (dn[dn_len - 1] == '\\')));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -2661,8 +2661,9 @@ static void deh_procText(DEHFILE *fpin, FILE* fpout, char *line)
|
||||
|
||||
if (!found) // Nothing we want to handle here--see if strings can deal with it.
|
||||
{
|
||||
if (fpout) fprintf(fpout,"Checking text area through strings for '%.12s%s' from=%d to=%d\n",inbuffer, (strlen(inbuffer) > 12) ? "..." : "",fromlen,tolen);
|
||||
if ((size_t)fromlen <= strlen(inbuffer))
|
||||
size_t inbuffer_len = strlen(inbuffer);
|
||||
if (fpout) fprintf(fpout,"Checking text area through strings for '%.12s%s' from=%d to=%d\n",inbuffer, (inbuffer_len > 12) ? "..." : "",fromlen,tolen);
|
||||
if ((size_t)fromlen <= inbuffer_len)
|
||||
{
|
||||
line2 = strdup(&inbuffer[fromlen]);
|
||||
inbuffer[fromlen] = '\0';
|
||||
|
21
src/d_main.c
21
src/d_main.c
@ -515,23 +515,26 @@ void D_StartTitle (void)
|
||||
// - modified to allocate & use new wadfiles array
|
||||
void D_AddFile (const char *file, wad_source_t source)
|
||||
{
|
||||
char *gwa_filename=NULL;
|
||||
size_t gwa_filename_len;
|
||||
size_t file_len = strlen(file);
|
||||
char *gwa_filename = NULL;
|
||||
|
||||
wadfiles = realloc(wadfiles, sizeof(*wadfiles)*(numwadfiles+1));
|
||||
wadfiles[numwadfiles].name =
|
||||
AddDefaultExtension(strcpy(malloc(strlen(file)+5), file), ".wad");
|
||||
AddDefaultExtension(strcpy(malloc(file_len + 5), file), ".wad");
|
||||
wadfiles[numwadfiles].src = source; // Ty 08/29/98
|
||||
numwadfiles++;
|
||||
// proff: automatically try to add the gwa files
|
||||
// proff - moved from w_wad.c
|
||||
gwa_filename=AddDefaultExtension(strcpy(malloc(strlen(file)+5), file), ".wad");
|
||||
if (strlen(gwa_filename)>4)
|
||||
if (!strcasecmp(gwa_filename+(strlen(gwa_filename)-4),".wad"))
|
||||
gwa_filename = AddDefaultExtension(strcpy(malloc(file_len + 5), file), ".wad");
|
||||
gwa_filename_len = strlen(gwa_filename);
|
||||
|
||||
if (gwa_filename_len > 4)
|
||||
if (!strcasecmp(gwa_filename+(gwa_filename_len - 4),".wad"))
|
||||
{
|
||||
char *ext;
|
||||
ext = &gwa_filename[strlen(gwa_filename)-4];
|
||||
ext[1] = 'g'; ext[2] = 'w'; ext[3] = 'a';
|
||||
wadfiles = realloc(wadfiles, sizeof(*wadfiles)*(numwadfiles+1));
|
||||
char *ext = &gwa_filename[gwa_filename_len - 4];
|
||||
ext[1] = 'g'; ext[2] = 'w'; ext[3] = 'a';
|
||||
wadfiles = realloc(wadfiles, sizeof(*wadfiles)*(numwadfiles+1));
|
||||
wadfiles[numwadfiles].name = gwa_filename;
|
||||
wadfiles[numwadfiles].src = source; // Ty 08/29/98
|
||||
numwadfiles++;
|
||||
|
@ -1844,7 +1844,7 @@ static void M_DrawSetting(const setup_menu_t* s)
|
||||
key == &key_fire || key == &key_strafe || key == &key_use)
|
||||
{
|
||||
if (s->m_mouse && *s->m_mouse != -1)
|
||||
sprintf(menu_buffer+strlen(menu_buffer), "/MB%d",
|
||||
sprintf(menu_buffer + strlen(menu_buffer), "/MB%d",
|
||||
*s->m_mouse+1);
|
||||
}
|
||||
M_DrawMenuString(x,y,color);
|
||||
@ -5278,7 +5278,8 @@ void M_DrawSelCell (menu_t* menu,int item)
|
||||
int M_StringWidth(const char* string)
|
||||
{
|
||||
int i, c, w = 0;
|
||||
for (i = 0;(size_t)i < strlen(string);i++)
|
||||
size_t string_len = strlen(string);
|
||||
for (i = 0;(size_t)i < string_len; i++)
|
||||
w += (c = toupper(string[i]) - HU_FONTSTART) < 0 || c >= HU_FONTSIZE ?
|
||||
4 : hu_font[c].width;
|
||||
return w;
|
||||
|
19
src/w_wad.c
19
src/w_wad.c
@ -67,16 +67,14 @@ int numlumps; // killough
|
||||
|
||||
void ExtractFileBase (const char *path, char *dest)
|
||||
{
|
||||
const char *src = path + strlen(path) - 1;
|
||||
int length;
|
||||
const char *src = path + strlen(path) - 1;
|
||||
|
||||
// back up until a \ or the start
|
||||
while (src != path && src[-1] != ':' // killough 3/22/98: allow c:filename
|
||||
&& *(src-1) != '\\'
|
||||
&& *(src-1) != '/')
|
||||
{
|
||||
src--;
|
||||
}
|
||||
|
||||
// copy up to eight characters
|
||||
memset(dest,0,8);
|
||||
@ -129,6 +127,7 @@ char *AddDefaultExtension(char *path, const char *ext)
|
||||
static void W_AddFile(wadfile_info_t *wadfile)
|
||||
// killough 1/31/98: static, const
|
||||
{
|
||||
size_t wadfile_name_len;
|
||||
wadinfo_t header;
|
||||
lumpinfo_t* lump_p;
|
||||
unsigned i;
|
||||
@ -143,11 +142,13 @@ static void W_AddFile(wadfile_info_t *wadfile)
|
||||
RETRO_VFS_FILE_ACCESS_READ,
|
||||
RETRO_VFS_FILE_ACCESS_HINT_NONE);
|
||||
|
||||
wadfile_name_len = strlen(wadfile->name);
|
||||
|
||||
if (!wadfile->handle)
|
||||
{
|
||||
if ( strlen(wadfile->name)<=4 || // add error check -- killough
|
||||
(strcasecmp(wadfile->name+strlen(wadfile->name)-4 , ".lmp" ) &&
|
||||
strcasecmp(wadfile->name+strlen(wadfile->name)-4 , ".gwa" ) )
|
||||
if ( wadfile_name_len <= 4 || // add error check -- killough
|
||||
(strcasecmp(wadfile->name + wadfile_name_len - 4, ".lmp" ) &&
|
||||
strcasecmp(wadfile->name + wadfile_name_len - 4, ".gwa" ) )
|
||||
)
|
||||
I_Error("W_AddFile: couldn't open %s",wadfile->name);
|
||||
return;
|
||||
@ -165,10 +166,10 @@ static void W_AddFile(wadfile_info_t *wadfile)
|
||||
lprintf (LO_INFO," adding %s\n",wadfile->name);
|
||||
startlump = numlumps;
|
||||
|
||||
if ( strlen(wadfile->name)<=4 ||
|
||||
if ( wadfile_name_len <=4 ||
|
||||
(
|
||||
strcasecmp(wadfile->name+strlen(wadfile->name)-4,".wad") &&
|
||||
strcasecmp(wadfile->name+strlen(wadfile->name)-4,".gwa")
|
||||
strcasecmp(wadfile->name + wadfile_name_len - 4,".wad") &&
|
||||
strcasecmp(wadfile->name + wadfile_name_len - 4,".gwa")
|
||||
)
|
||||
)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user