alliedmodders / amxmodx

AMX Mod X - Half-Life 1 Scripting and Administration
http://www.amxmodx.org/
489 stars 197 forks source link

OnNewSection skipping section instead breaking parsing. #798

Open afwn90cj93201nixr2e1re opened 4 years ago

afwn90cj93201nixr2e1re commented 4 years ago

Description

When OnNewSection return false parser should skip only section(not handler), till new one.

Problematic Code (or Steps to Reproduce)


new bool:anyMapFound = false;
new bool:transferZmToSpawnAfterStart = false;
new bool:transferHumansToSpawnAfterStart = false;
new const CONFIG_FILE[] = "addons/amxmodx/configs/escape_mode.ini";

startFileParsing(){
    new INIParser:Parser = INI_CreateParser();
    INI_SetReaders(Parser, "OnKeyValue", "OnNewSection");
    INI_SetParseEnd(Parser, "OnParseEnd");
    INI_SetRawLine(Parser, "OnRawLine");
    INI_ParseFile(Parser, CONFIG_FILE);
    log_to_file("123.txt","parsing end %d", anyMapFound);
    INI_DestroyParser(Parser);
}
public OnParseEnd(INIParser:handle, bool:halted, any:data){
    log_to_file("123.txt","OnParseEnd parsing end %d %d", halted,anyMapFound);
}
public bool:OnRawLine(INIParser:handle, const line[], lineno, curtok, any:data){
    log_to_file("123.txt","OnRawLine line %s|||%d|||%d", line,lineno,curtok);
    return true;
}
public bool:OnNewSection(INIParser:handle, const section[], bool:invalid_tokens, bool:close_bracket, bool:extra_tokens, curtok, any:data){
    #pragma unused handle, invalid_tokens, close_bracket, extra_tokens, curtok, data
    //skip invalid sections, which are not current map name
    if (!equali(section, g_Mapname)){
        return false;
    }
    return true;
}

public bool:OnKeyValue(INIParser:handle, const key[], const value[], bool:invalid_tokens, bool:equal_token, bool:quotes, curtok, any:data){
    return true;
}
[zm_dust_world]
val=1
[zm_dust_world2]
val=1
[zm_dust_world3]
val=1
afwn90cj93201nixr2e1re commented 4 years ago

Then if we need something we can just call INI_ParserDestroy() which gonna destroy parser after reading needed section.

@Arkshine any ideas?

voed commented 4 years ago
  if (!equali(section, g_Mapname)){
    return true;
  }

and your problem fixed 🤔

afwn90cj93201nixr2e1re commented 4 years ago

Я же говорю, тогда в ключи будут приходить значения.

voed commented 4 years ago

Ok. i got it. I think it should be great to add "section" paremeter to OnKeyValue handler. Then you can just parse everything here.

public bool:OnKeyValue(INIParser:handle, const section[], const key[], const value[], bool:invalid_tokens, bool:equal_token, bool:quotes, curtok, any:data)
afwn90cj93201nixr2e1re commented 4 years ago

I can already do it, just by simple skipping.

OnNewSection(...)if(equali...)neededSection = true;
OnNewKeyValue(...)if(!neededSection)return true; else{...}return true;

But that's not nice for perf.

voed commented 4 years ago

Or instead of true/false we can add 3 return values: 0 - break parsing(like false now) 1 - continue parsing(like true) 2 - skip section and continue

afwn90cj93201nixr2e1re commented 4 years ago

Yep, like PLUGIN_* stuff.