Skip to content

Commit

Permalink
Update LoadWadconfig and LoadWadcfgfile
Browse files Browse the repository at this point in the history
  • Loading branch information
seedee committed Jul 10, 2024
1 parent 1f2fc60 commit d05d661
Showing 1 changed file with 57 additions and 39 deletions.
96 changes: 57 additions & 39 deletions src/sdhlt/sdHLCSG/wadcfg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,83 +3,101 @@
#include "csg.h"
void LoadWadconfig (const char *filename, const char *configname)
{
Log ("Loading wad configuration '%s' from '%s' :\n", configname, filename);
int found = 0;
int count = 0;
int size;
char *buffer;
size = LoadFile (filename, &buffer);
ParseFromMemory (buffer, size);
while (GetToken (true))
char filenameOnly[_MAX_PATH];
size_t filenameLength = strlen(filename);
strncpy(filenameOnly, filename, filenameLength);
filenameOnly[filenameLength] = '\0'; //Null terminate
auto pos = std::string(filenameOnly).find_last_of("/\\");

if (pos != std::string::npos) // Copy everything after the last slash to the beginning of filenameOnly
{
std::string temp(filenameOnly + pos + 1);
strncpy(filenameOnly, temp.c_str(), _MAX_PATH);
filenameOnly[temp.size()] = '\0';
}
Log("Loading wadconfig %s from '%s'\n", configname, filenameOnly);
Log("--------------------------------------\n");
int wadconfigsFound = 0;
int wadPathsFound = 0;
int filesize;
char *file;
filesize = LoadFile(filename, &file); //Load file and store it's size
ParseFromMemory (file, filesize); //Parse contents from memory

while (GetToken (true)) //Loop through file
{
bool skip = true;
if (!strcasecmp (g_token, configname))
bool skip = true; //Skip until the -wadconfig configname is found

if (!strcasecmp (g_token, configname)) //If we find configname line
{
skip = false;
found++;
wadconfigsFound++;
}
if (!GetToken (true) || strcasecmp (g_token, "{"))
if (!GetToken (true) || strcasecmp(g_token, "{")) //If next line is not an opening bracket
{
Error ("parsing '%s': missing '{'.", filename);
Error ("Parsing %s (missing '{' opening bracket in '%s' config)\n", filenameOnly, configname);
}
while (1)
while (1) //Loop through content of braces
{
if (!GetToken (true))
{
Error ("parsing '%s': unexpected end of file.", filename);
Error("Parsing '%s': unexpected EOF in '%s'\n", filenameOnly, configname);
}
if (!strcasecmp (g_token, "}"))
if (!strcasecmp (g_token, "}")) //If we find closing bracket
{
break;
}
if (skip)
{
continue;
}
Log (" ");
bool include = false;
if (!strcasecmp (g_token, "include"))
{
Log ("include ");
Log("[include] ");
include = true;

if (!GetToken (true))
{
Error ("parsing '%s': unexpected end of file.", filename);
Error ("Parsing '%s': unexpected EOF in '%s'\n", filenameOnly, configname);
}
}
Log ("\"%s\"\n", g_token);
Log ("%s\n", g_token);
if (g_iNumWadPaths >= MAX_WADPATHS)
{
Error ("parsing '%s': too many wad files.", filename);
Error ("Parsing '%s': too many wad files (%i/%i) in '%s'\n", filenameOnly, configname, g_iNumWadPaths, MAX_WADPATHS);
}
count++;
wadPathsFound++;
PushWadPath (g_token, !include);
}
}
if (found == 0)
Log("- %d wadpaths found in %s\n", wadPathsFound, configname);
Log("--------------------------------------\n\n");

if (wadconfigsFound < 1)
{
Error ("Couldn't find wad configuration '%s' in file '%s'.\n", configname, filename);
Error ("Couldn't find wad config %s in '%s'\n", configname, filenameOnly);
}
if (found >= 2)
if (wadconfigsFound > 1)
{
Error ("Found more than one wad configuration for '%s' in file '%s'.\n", configname, filename);
Error("Found more than one wad config %s in '%s'\n", configname, filenameOnly);
}
free (buffer); // should not be freed because it is still being used as script buffer
//Log ("Using custom wadfile configuration: '%s' (with %i wad%s)\n", configname, count, count > 1 ? "s" : "");
free (file); // should not be freed because it is still being used as script buffer
//Log ("Using custom wadfile configuration: '%s' (with %i wad%s)\n", configname, wadPathsFound, wadPathsFound > 1 ? "s" : "");
}
void LoadWadcfgfile (const char *filename)
{
Log ("Loading wad configuration file '%s' :\n", filename);
int count = 0;
int size;
char *buffer;
size = LoadFile (filename, &buffer);
ParseFromMemory (buffer, size);
while (GetToken (true))
Log ("Loading %s\n", filename);
Log ("------------\n");
int wadPathsCount = 0;
int wadFileSize;
char *wadFile;
wadFileSize = LoadFile (filename, &wadFile);
ParseFromMemory (wadFile, wadFileSize);
while (GetToken (true)) //Loop through file
{
Log (" ");
bool include = false;
if (!strcasecmp (g_token, "include"))
if (!strcasecmp (g_token, "include")) //If line starts with include (or contains?)
{
Log ("include ");
include = true;
Expand All @@ -93,9 +111,9 @@ void LoadWadcfgfile (const char *filename)
{
Error ("parsing '%s': too many wad files.", filename);
}
count++;
wadPathsCount++;
PushWadPath (g_token, !include);
}
free (buffer); // should not be freed because it is still being used as script buffer
free (wadFile); // should not be freed because it is still being used as script buffer
//Log ("Using custom wadfile configuration: '%s' (with %i wad%s)\n", filename, count, count > 1 ? "s" : "");
}

0 comments on commit d05d661

Please sign in to comment.