Merge branch 'long-names' into 'next'

Enable entry searching functions to retrieve entry names longer than 8 characters

See merge request STJr/SRB2!885
This commit is contained in:
LJ Sonic 2020-04-23 04:40:33 -04:00
commit 5e440e79cc
4 changed files with 65 additions and 45 deletions

View File

@ -441,9 +441,9 @@ void LUA_LoadLump(UINT16 wad, UINT16 lump)
else // If it's not a .lua file, copy the lump name in too. else // If it's not a .lua file, copy the lump name in too.
{ {
lumpinfo_t *lump_p = &wadfiles[wad]->lumpinfo[lump]; lumpinfo_t *lump_p = &wadfiles[wad]->lumpinfo[lump];
len += 1 + strlen(lump_p->name2); // length of file name, '|', and lump name len += 1 + strlen(lump_p->fullname); // length of file name, '|', and lump name
name = malloc(len+1); name = malloc(len+1);
sprintf(name, "%s|%s", wadfiles[wad]->filename, lump_p->name2); sprintf(name, "%s|%s", wadfiles[wad]->filename, lump_p->fullname);
name[len] = '\0'; name[len] = '\0';
} }

View File

@ -3777,12 +3777,12 @@ static lumpinfo_t* FindFolder(const char *folName, UINT16 *start, UINT16 *end, l
{ {
UINT16 numlumps = *pnumlumps; UINT16 numlumps = *pnumlumps;
size_t i = *pi; size_t i = *pi;
if (!stricmp(lumpinfo->name2, folName)) if (!stricmp(lumpinfo->fullname, folName))
{ {
lumpinfo++; lumpinfo++;
*start = ++i; *start = ++i;
for (; i < numlumps; i++, lumpinfo++) for (; i < numlumps; i++, lumpinfo++)
if (strnicmp(lumpinfo->name2, folName, strlen(folName))) if (strnicmp(lumpinfo->fullname, folName, strlen(folName)))
break; break;
lumpinfo--; lumpinfo--;
*end = i-- - *start; *end = i-- - *start;

View File

@ -92,7 +92,7 @@ typedef struct
typedef struct lumpnum_cache_s typedef struct lumpnum_cache_s
{ {
char lumpname[8]; char lumpname[32];
lumpnum_t lumpnum; lumpnum_t lumpnum;
} lumpnum_cache_t; } lumpnum_cache_t;
@ -114,13 +114,18 @@ void W_Shutdown(void)
{ {
while (numwadfiles--) while (numwadfiles--)
{ {
fclose(wadfiles[numwadfiles]->handle); wadfile_t *wad = wadfiles[numwadfiles];
Z_Free(wadfiles[numwadfiles]->filename);
while (wadfiles[numwadfiles]->numlumps--)
Z_Free(wadfiles[numwadfiles]->lumpinfo[wadfiles[numwadfiles]->numlumps].name2);
Z_Free(wadfiles[numwadfiles]->lumpinfo); fclose(wad->handle);
Z_Free(wadfiles[numwadfiles]); Z_Free(wad->filename);
while (wad->numlumps--)
{
Z_Free(wad->lumpinfo[wad->numlumps].longname);
Z_Free(wad->lumpinfo[wad->numlumps].fullname);
}
Z_Free(wad->lumpinfo);
Z_Free(wad);
} }
} }
@ -206,9 +211,9 @@ static inline void W_LoadDehackedLumpsPK3(UINT16 wadnum, boolean mainfile)
for(; posStart < posEnd; posStart++) for(; posStart < posEnd; posStart++)
{ {
lumpinfo_t *lump_p = &wadfiles[wadnum]->lumpinfo[posStart]; lumpinfo_t *lump_p = &wadfiles[wadnum]->lumpinfo[posStart];
size_t length = strlen(wadfiles[wadnum]->filename) + 1 + strlen(lump_p->name2); // length of file name, '|', and lump name size_t length = strlen(wadfiles[wadnum]->filename) + 1 + strlen(lump_p->fullname); // length of file name, '|', and lump name
char *name = malloc(length + 1); char *name = malloc(length + 1);
sprintf(name, "%s|%s", wadfiles[wadnum]->filename, lump_p->name2); sprintf(name, "%s|%s", wadfiles[wadnum]->filename, lump_p->fullname);
name[length] = '\0'; name[length] = '\0';
CONS_Printf(M_GetText("Loading SOC from %s\n"), name); CONS_Printf(M_GetText("Loading SOC from %s\n"), name);
DEH_LoadDehackedLumpPwad(wadnum, posStart, mainfile); DEH_LoadDehackedLumpPwad(wadnum, posStart, mainfile);
@ -235,9 +240,9 @@ static inline void W_LoadDehackedLumps(UINT16 wadnum, boolean mainfile)
for (lump = 0; lump < wadfiles[wadnum]->numlumps; lump++, lump_p++) for (lump = 0; lump < wadfiles[wadnum]->numlumps; lump++, lump_p++)
if (memcmp(lump_p->name,"SOC_",4)==0) // Check for generic SOC lump if (memcmp(lump_p->name,"SOC_",4)==0) // Check for generic SOC lump
{ // shameless copy+paste of code from LUA_LoadLump { // shameless copy+paste of code from LUA_LoadLump
size_t length = strlen(wadfiles[wadnum]->filename) + 1 + strlen(lump_p->name2); // length of file name, '|', and lump name size_t length = strlen(wadfiles[wadnum]->filename) + 1 + strlen(lump_p->fullname); // length of file name, '|', and lump name
char *name = malloc(length + 1); char *name = malloc(length + 1);
sprintf(name, "%s|%s", wadfiles[wadnum]->filename, lump_p->name2); sprintf(name, "%s|%s", wadfiles[wadnum]->filename, lump_p->fullname);
name[length] = '\0'; name[length] = '\0';
CONS_Printf(M_GetText("Loading SOC from %s\n"), name); CONS_Printf(M_GetText("Loading SOC from %s\n"), name);
@ -339,10 +344,17 @@ static lumpinfo_t* ResGetLumpsStandalone (FILE* handle, UINT16* numlumps, const
lumpinfo->size = ftell(handle); lumpinfo->size = ftell(handle);
fseek(handle, 0, SEEK_SET); fseek(handle, 0, SEEK_SET);
strcpy(lumpinfo->name, lumpname); strcpy(lumpinfo->name, lumpname);
// Allocate the lump's long name.
lumpinfo->longname = Z_Malloc(9 * sizeof(char), PU_STATIC, NULL);
strcpy(lumpinfo->longname, lumpname);
lumpinfo->longname[8] = '\0';
// Allocate the lump's full name. // Allocate the lump's full name.
lumpinfo->name2 = Z_Malloc(9 * sizeof(char), PU_STATIC, NULL); lumpinfo->fullname = Z_Malloc(9 * sizeof(char), PU_STATIC, NULL);
strcpy(lumpinfo->name2, lumpname); strcpy(lumpinfo->fullname, lumpname);
lumpinfo->name2[8] = '\0'; lumpinfo->fullname[8] = '\0';
*numlumps = 1; *numlumps = 1;
return lumpinfo; return lumpinfo;
} }
@ -429,10 +441,16 @@ static lumpinfo_t* ResGetLumpsWad (FILE* handle, UINT16* nlmp, const char* filen
lump_p->compression = CM_NOCOMPRESSION; lump_p->compression = CM_NOCOMPRESSION;
memset(lump_p->name, 0x00, 9); memset(lump_p->name, 0x00, 9);
strncpy(lump_p->name, fileinfo->name, 8); strncpy(lump_p->name, fileinfo->name, 8);
// Allocate the lump's long name.
lump_p->longname = Z_Malloc(9 * sizeof(char), PU_STATIC, NULL);
strncpy(lump_p->longname, fileinfo->name, 8);
lump_p->longname[8] = '\0';
// Allocate the lump's full name. // Allocate the lump's full name.
lump_p->name2 = Z_Malloc(9 * sizeof(char), PU_STATIC, NULL); lump_p->fullname = Z_Malloc(9 * sizeof(char), PU_STATIC, NULL);
strncpy(lump_p->name2, fileinfo->name, 8); strncpy(lump_p->fullname, fileinfo->name, 8);
lump_p->name2[8] = '\0'; lump_p->fullname[8] = '\0';
} }
free(fileinfov); free(fileinfov);
*nlmp = numlumps; *nlmp = numlumps;
@ -598,8 +616,11 @@ static lumpinfo_t* ResGetLumpsZip (FILE* handle, UINT16* nlmp)
memset(lump_p->name, '\0', 9); // Making sure they're initialized to 0. Is it necessary? memset(lump_p->name, '\0', 9); // Making sure they're initialized to 0. Is it necessary?
strncpy(lump_p->name, trimname, min(8, dotpos - trimname)); strncpy(lump_p->name, trimname, min(8, dotpos - trimname));
lump_p->name2 = Z_Calloc(zentry.namelen + 1, PU_STATIC, NULL); lump_p->longname = Z_Calloc(dotpos - trimname + 1, PU_STATIC, NULL);
strncpy(lump_p->name2, fullname, zentry.namelen); strlcpy(lump_p->longname, trimname, dotpos - trimname + 1);
lump_p->fullname = Z_Calloc(zentry.namelen + 1, PU_STATIC, NULL);
strncpy(lump_p->fullname, fullname, zentry.namelen);
free(fullname); free(fullname);
@ -637,7 +658,7 @@ static lumpinfo_t* ResGetLumpsZip (FILE* handle, UINT16* nlmp)
// skip and ignore comments/extra fields // skip and ignore comments/extra fields
if ((fseek(handle, lump_p->position, SEEK_SET) != 0) || (fread(&zlentry, 1, sizeof(zlentry_t), handle) < sizeof(zlentry_t))) if ((fseek(handle, lump_p->position, SEEK_SET) != 0) || (fread(&zlentry, 1, sizeof(zlentry_t), handle) < sizeof(zlentry_t)))
{ {
CONS_Alert(CONS_ERROR, "Local headers for lump %s are corrupt\n", lump_p->name2); CONS_Alert(CONS_ERROR, "Local headers for lump %s are corrupt\n", lump_p->fullname);
Z_Free(lumpinfo); Z_Free(lumpinfo);
return NULL; return NULL;
} }
@ -901,16 +922,14 @@ const char *W_CheckNameForNum(lumpnum_t lumpnum)
UINT16 W_CheckNumForNamePwad(const char *name, UINT16 wad, UINT16 startlump) UINT16 W_CheckNumForNamePwad(const char *name, UINT16 wad, UINT16 startlump)
{ {
UINT16 i; UINT16 i;
static char uname[9]; static char uname[256 + 1];
memset(uname, 0x00, sizeof uname);
strncpy(uname, name, 8);
uname[8] = 0;
strupr(uname);
if (!TestValidLump(wad,0)) if (!TestValidLump(wad,0))
return INT16_MAX; return INT16_MAX;
strlcpy(uname, name, sizeof uname);
strupr(uname);
// //
// scan forward // scan forward
// start at 'startlump', useful parameter when there are multiple // start at 'startlump', useful parameter when there are multiple
@ -920,7 +939,7 @@ UINT16 W_CheckNumForNamePwad(const char *name, UINT16 wad, UINT16 startlump)
{ {
lumpinfo_t *lump_p = wadfiles[wad]->lumpinfo + startlump; lumpinfo_t *lump_p = wadfiles[wad]->lumpinfo + startlump;
for (i = startlump; i < wadfiles[wad]->numlumps; i++, lump_p++) for (i = startlump; i < wadfiles[wad]->numlumps; i++, lump_p++)
if (memcmp(lump_p->name,uname,8) == 0) if (!strcmp(lump_p->longname, uname))
return i; return i;
} }
@ -947,10 +966,10 @@ UINT16 W_CheckNumForFolderStartPK3(const char *name, UINT16 wad, UINT16 startlum
name_length = strlen(name); name_length = strlen(name);
for (i = startlump; i < wadfiles[wad]->numlumps; i++, lump_p++) for (i = startlump; i < wadfiles[wad]->numlumps; i++, lump_p++)
{ {
if (strnicmp(name, lump_p->name2, name_length) == 0) if (strnicmp(name, lump_p->fullname, name_length) == 0)
{ {
/* SLADE is special and puts a single directory entry. Skip that. */ /* SLADE is special and puts a single directory entry. Skip that. */
if (strlen(lump_p->name2) == name_length) if (strlen(lump_p->fullname) == name_length)
i++; i++;
break; break;
} }
@ -967,7 +986,7 @@ UINT16 W_CheckNumForFolderEndPK3(const char *name, UINT16 wad, UINT16 startlump)
lumpinfo_t *lump_p = wadfiles[wad]->lumpinfo + startlump; lumpinfo_t *lump_p = wadfiles[wad]->lumpinfo + startlump;
for (i = startlump; i < wadfiles[wad]->numlumps; i++, lump_p++) for (i = startlump; i < wadfiles[wad]->numlumps; i++, lump_p++)
{ {
if (strnicmp(name, lump_p->name2, strlen(name))) if (strnicmp(name, lump_p->fullname, strlen(name)))
break; break;
} }
return i; return i;
@ -981,7 +1000,7 @@ UINT16 W_CheckNumForFullNamePK3(const char *name, UINT16 wad, UINT16 startlump)
lumpinfo_t *lump_p = wadfiles[wad]->lumpinfo + startlump; lumpinfo_t *lump_p = wadfiles[wad]->lumpinfo + startlump;
for (i = startlump; i < wadfiles[wad]->numlumps; i++, lump_p++) for (i = startlump; i < wadfiles[wad]->numlumps; i++, lump_p++)
{ {
if (!strnicmp(name, lump_p->name2, strlen(name))) if (!strnicmp(name, lump_p->fullname, strlen(name)))
{ {
return i; return i;
} }
@ -1006,7 +1025,7 @@ lumpnum_t W_CheckNumForName(const char *name)
// most recent entries first // most recent entries first
for (i = lumpnumcacheindex + LUMPNUMCACHESIZE; i > lumpnumcacheindex; i--) for (i = lumpnumcacheindex + LUMPNUMCACHESIZE; i > lumpnumcacheindex; i--)
{ {
if (strncmp(lumpnumcache[i & (LUMPNUMCACHESIZE - 1)].lumpname, name, 8) == 0) if (strcmp(lumpnumcache[i & (LUMPNUMCACHESIZE - 1)].lumpname, name) == 0)
{ {
lumpnumcacheindex = i & (LUMPNUMCACHESIZE - 1); lumpnumcacheindex = i & (LUMPNUMCACHESIZE - 1);
return lumpnumcache[lumpnumcacheindex].lumpnum; return lumpnumcache[lumpnumcacheindex].lumpnum;
@ -1026,7 +1045,7 @@ lumpnum_t W_CheckNumForName(const char *name)
{ {
// Update the cache. // Update the cache.
lumpnumcacheindex = (lumpnumcacheindex + 1) & (LUMPNUMCACHESIZE - 1); lumpnumcacheindex = (lumpnumcacheindex + 1) & (LUMPNUMCACHESIZE - 1);
strncpy(lumpnumcache[lumpnumcacheindex].lumpname, name, 8); strlcpy(lumpnumcache[lumpnumcacheindex].lumpname, name, 32);
lumpnumcache[lumpnumcacheindex].lumpnum = (i<<16)+check; lumpnumcache[lumpnumcacheindex].lumpnum = (i<<16)+check;
return lumpnumcache[lumpnumcacheindex].lumpnum; return lumpnumcache[lumpnumcacheindex].lumpnum;
@ -1151,7 +1170,7 @@ boolean W_IsLumpWad(lumpnum_t lumpnum)
{ {
if (wadfiles[WADFILENUM(lumpnum)]->type == RET_PK3) if (wadfiles[WADFILENUM(lumpnum)]->type == RET_PK3)
{ {
const char *lumpfullName = (wadfiles[WADFILENUM(lumpnum)]->lumpinfo + LUMPNUM(lumpnum))->name2; const char *lumpfullName = (wadfiles[WADFILENUM(lumpnum)]->lumpinfo + LUMPNUM(lumpnum))->fullname;
if (strlen(lumpfullName) < 4) if (strlen(lumpfullName) < 4)
return false; // can't possibly be a WAD can it? return false; // can't possibly be a WAD can it?
@ -1169,7 +1188,7 @@ boolean W_IsLumpFolder(UINT16 wad, UINT16 lump)
{ {
if (wadfiles[wad]->type == RET_PK3) if (wadfiles[wad]->type == RET_PK3)
{ {
const char *name = wadfiles[wad]->lumpinfo[lump].name2; const char *name = wadfiles[wad]->lumpinfo[lump].fullname;
return (name[strlen(name)-1] == '/'); // folders end in '/' return (name[strlen(name)-1] == '/'); // folders end in '/'
} }
@ -1247,7 +1266,7 @@ size_t W_ReadLumpHeaderPwad(UINT16 wad, UINT16 lump, void *dest, size_t size, si
{ {
size_t bytesread = fread(dest, 1, size, handle); size_t bytesread = fread(dest, 1, size, handle);
if (R_IsLumpPNG((UINT8 *)dest, bytesread)) if (R_IsLumpPNG((UINT8 *)dest, bytesread))
W_ThrowPNGError(l->name2, wadfiles[wad]->filename); W_ThrowPNGError(l->fullname, wadfiles[wad]->filename);
return bytesread; return bytesread;
} }
#else #else
@ -1289,7 +1308,7 @@ size_t W_ReadLumpHeaderPwad(UINT16 wad, UINT16 lump, void *dest, size_t size, si
Z_Free(decData); Z_Free(decData);
#ifdef NO_PNG_LUMPS #ifdef NO_PNG_LUMPS
if (R_IsLumpPNG((UINT8 *)dest, size)) if (R_IsLumpPNG((UINT8 *)dest, size))
W_ThrowPNGError(l->name2, wadfiles[wad]->filename); W_ThrowPNGError(l->fullname, wadfiles[wad]->filename);
#endif #endif
return size; return size;
#else #else
@ -1352,7 +1371,7 @@ size_t W_ReadLumpHeaderPwad(UINT16 wad, UINT16 lump, void *dest, size_t size, si
#ifdef NO_PNG_LUMPS #ifdef NO_PNG_LUMPS
if (R_IsLumpPNG((UINT8 *)dest, size)) if (R_IsLumpPNG((UINT8 *)dest, size))
W_ThrowPNGError(l->name2, wadfiles[wad]->filename); W_ThrowPNGError(l->fullname, wadfiles[wad]->filename);
#endif #endif
return size; return size;
} }

View File

@ -66,9 +66,10 @@ typedef struct
{ {
unsigned long position; // filelump_t filepos unsigned long position; // filelump_t filepos
unsigned long disksize; // filelump_t size unsigned long disksize; // filelump_t size
char name[9]; // filelump_t name[] char name[9]; // filelump_t name[] e.g. "LongEntr"
char *name2; // Used by PK3s. Dynamically allocated name. char *longname; // e.g. "LongEntryName"
size_t size; // real (uncompressed) size char *fullname; // e.g. "Folder/Subfolder/LongEntryName.extension"
size_t size; // real (uncompressed) size
compmethod compression; // lump compression method compmethod compression; // lump compression method
} lumpinfo_t; } lumpinfo_t;