Skip to content

tweak(ini): Improve consistency in use of INI::getNextTokenOrNull#2597

Draft
Caball009 wants to merge 4 commits intoTheSuperHackers:mainfrom
Caball009:ini_change_next_token
Draft

tweak(ini): Improve consistency in use of INI::getNextTokenOrNull#2597
Caball009 wants to merge 4 commits intoTheSuperHackers:mainfrom
Caball009:ini_change_next_token

Conversation

@Caball009
Copy link
Copy Markdown

This PR contains two changes that may change behavior:

  1. for (const char* token = ini->getNextToken(); token; token = ini->getNextTokenOrNull()) ->
    for (const char* token = ini->getNextTokenOrNull(); token; token = ini->getNextTokenOrNull())
  2. static void parseDebrisObjectNames( INI* ini, void *instance, void *store, const void* /*userData*/ )
    {
    GenericObjectCreationNugget* debrisNugget = (GenericObjectCreationNugget*)instance;
    for (const char* debrisName = ini->getNextToken(); debrisName; debrisName = ini->getNextTokenOrNull())
    {
    if (TheGlobalData->m_preloadAssets)
    debrisModelNamesGlobalHack.push_back(debrisName);
    debrisNugget->m_names.push_back(AsciiString(debrisName));
    debrisName = ini->getNextTokenOrNull();
    }
    }

    Line 1447 is unnecessary / undesirable.
Note on the first change

WRT the first change, it's not possible to have all loops match this format:
for (const char* token = ini->getNextToken(); token; token = ini->getNextTokenOrNull()) because some lines in the standard ini files are incomplete and so the token may be empty. I came across two types of incomplete lines:

https://github.com/TheSuperHackers/GeneralsGamePatch/blob/5845293dd12ab10c5f16c6f3116ce526f62dc369/Patch104pZH/GameFilesOriginalZH/Data/INI/SoundEffects.ini#L333

https://github.com/TheSuperHackers/GeneralsGamePatch/blob/5845293dd12ab10c5f16c6f3116ce526f62dc369/Patch104pZH/GameFilesOriginalZH/Data/INI/Object/ChemicalGeneral.ini#L10693

const char *c = ini->getNextTokenOrNull(SEPS);
while ( c )

for (const char *token = ini->getNextTokenOrNull(); token != nullptr; token = ini->getNextTokenOrNull())

@Caball009 Caball009 added the Minor Severity: Minor < Major < Critical < Blocker label Apr 13, 2026
@Mauller
Copy link
Copy Markdown

Mauller commented Apr 13, 2026

I mentioned this in the other PR, but i think we should just go down to having a single function getNextToken but it can return null.

External code should then check for null on the first token and gracefully handle it instead of throwing like the original variant did.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Minor Severity: Minor < Major < Critical < Blocker

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants