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
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.

1 participant