Merge pull request #272 from Arkshine/feature/textparser-data-param
Add a data argument in INI/SMC_ParseFile() to pass through to callbacks (bug 6228)
This commit is contained in:
@ -63,7 +63,7 @@ static cell AMX_NATIVE_CALL SMC_SetParseStart(AMX *amx, cell *params)
|
||||
|
||||
if ((funcName = get_amxstring(amx, params[2], 0, length)) && length)
|
||||
{
|
||||
p->parse_start = registerSPForwardByName(amx, funcName, FP_CELL, FP_DONE);
|
||||
p->parse_start = registerSPForwardByName(amx, funcName, FP_CELL, FP_CELL, FP_DONE);
|
||||
}
|
||||
|
||||
if (p->parse_start == -1)
|
||||
@ -91,7 +91,7 @@ static cell AMX_NATIVE_CALL SMC_SetParseEnd(AMX *amx, cell *params)
|
||||
|
||||
if ((funcName = get_amxstring(amx, params[2], 0, length)) && length)
|
||||
{
|
||||
p->parse_end = registerSPForwardByName(amx, funcName, FP_CELL, FP_CELL, FP_CELL, FP_DONE);
|
||||
p->parse_end = registerSPForwardByName(amx, funcName, FP_CELL, FP_CELL, FP_CELL, FP_CELL, FP_DONE);
|
||||
}
|
||||
|
||||
if (p->parse_end == -1)
|
||||
@ -119,17 +119,17 @@ static cell AMX_NATIVE_CALL SMC_SetReaders(AMX *amx, cell *params)
|
||||
|
||||
if ((funcName = get_amxstring(amx, params[2], 0, kvLength)) && kvLength)
|
||||
{
|
||||
p->key_value = registerSPForwardByName(amx, funcName, FP_CELL, FP_STRING, FP_STRING, FP_DONE);
|
||||
p->key_value = registerSPForwardByName(amx, funcName, FP_CELL, FP_STRING, FP_STRING, FP_CELL, FP_DONE);
|
||||
}
|
||||
|
||||
if (kvLength && (funcName = get_amxstring(amx, params[3], 1, nsLength)) && nsLength)
|
||||
{
|
||||
p->new_section = registerSPForwardByName(amx, funcName, FP_CELL, FP_STRING, FP_DONE);
|
||||
p->new_section = registerSPForwardByName(amx, funcName, FP_CELL, FP_STRING, FP_CELL, FP_DONE);
|
||||
}
|
||||
|
||||
if (kvLength && (funcName = get_amxstring(amx, params[4], 2, esLength)) && esLength)
|
||||
{
|
||||
p->end_section = registerSPForwardByName(amx, funcName, FP_CELL, FP_DONE);
|
||||
p->end_section = registerSPForwardByName(amx, funcName, FP_CELL, FP_CELL, FP_DONE);
|
||||
}
|
||||
|
||||
if (p->key_value == -1 || (nsLength && p->new_section == -1) || (esLength && p->end_section == -1))
|
||||
@ -157,7 +157,7 @@ static cell AMX_NATIVE_CALL SMC_SetRawLine(AMX *amx, cell *params)
|
||||
|
||||
if ((funcName = get_amxstring(amx, params[2], 0, length)) && length)
|
||||
{
|
||||
p->raw_line = registerSPForwardByName(amx, funcName, FP_CELL, FP_STRING, FP_CELL, FP_DONE);
|
||||
p->raw_line = registerSPForwardByName(amx, funcName, FP_CELL, FP_STRING, FP_CELL, FP_CELL, FP_DONE);
|
||||
}
|
||||
|
||||
if (p->raw_line == -1)
|
||||
@ -169,7 +169,7 @@ static cell AMX_NATIVE_CALL SMC_SetRawLine(AMX *amx, cell *params)
|
||||
return 1;
|
||||
}
|
||||
|
||||
// native SMCError:SMC_ParseFile(SMCParser:handle, const file[], &line = 0, &col = 0);
|
||||
// native SMCError:SMC_ParseFile(SMCParser:handle, const file[], &line = 0, &col = 0, any:data = 0);
|
||||
static cell AMX_NATIVE_CALL SMC_ParseFile(AMX *amx, cell *params)
|
||||
{
|
||||
ParseInfo *p = TextParsersHandles.lookup(params[1]);
|
||||
@ -180,6 +180,11 @@ static cell AMX_NATIVE_CALL SMC_ParseFile(AMX *amx, cell *params)
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (*params / sizeof(cell) >= 5)
|
||||
{
|
||||
p->data = params[5];
|
||||
}
|
||||
|
||||
int length;
|
||||
const char *file = build_pathname("%s", get_amxstring(amx, params[2], 0, length));
|
||||
|
||||
@ -222,7 +227,7 @@ static cell AMX_NATIVE_CALL INI_CreateParser(AMX *amx, cell *params)
|
||||
return createParser();
|
||||
}
|
||||
|
||||
// native bool:INI_ParseFile(INIParser:handle, const file[], &line = 0, &col = 0);
|
||||
// native bool:INI_ParseFile(INIParser:handle, const file[], &line = 0, &col = 0, any:data = 0);
|
||||
static cell AMX_NATIVE_CALL INI_ParseFile(AMX *amx, cell *params)
|
||||
{
|
||||
ParseInfo *p = TextParsersHandles.lookup(params[1]);
|
||||
@ -236,6 +241,11 @@ static cell AMX_NATIVE_CALL INI_ParseFile(AMX *amx, cell *params)
|
||||
int length;
|
||||
const char *file = build_pathname("%s", get_amxstring(amx, params[2], 0, length));
|
||||
|
||||
if (*params / sizeof(cell) >= 5)
|
||||
{
|
||||
p->data = params[5];
|
||||
}
|
||||
|
||||
unsigned int line, col;
|
||||
bool result = textparsers->ParseFile_INI(file, p, &line, &col);
|
||||
|
||||
@ -261,7 +271,7 @@ static cell AMX_NATIVE_CALL INI_SetParseStart(AMX *amx, cell *params)
|
||||
|
||||
if ((funcName = get_amxstring(amx, params[2], 0, length)) && length)
|
||||
{
|
||||
p->parse_start = registerSPForwardByName(amx, funcName, FP_CELL, FP_DONE);
|
||||
p->parse_start = registerSPForwardByName(amx, funcName, FP_CELL, FP_CELL, FP_DONE);
|
||||
}
|
||||
|
||||
if (p->parse_start == -1)
|
||||
@ -289,7 +299,7 @@ static cell AMX_NATIVE_CALL INI_SetParseEnd(AMX *amx, cell *params)
|
||||
|
||||
if ((funcName = get_amxstring(amx, params[2], 0, length)))
|
||||
{
|
||||
p->parse_end = registerSPForwardByName(amx, funcName, FP_CELL, FP_CELL, FP_CELL, FP_DONE);
|
||||
p->parse_end = registerSPForwardByName(amx, funcName, FP_CELL, FP_CELL, FP_CELL, FP_CELL, FP_DONE);
|
||||
}
|
||||
|
||||
if (p->parse_end == -1)
|
||||
@ -317,12 +327,12 @@ static cell AMX_NATIVE_CALL INI_SetReaders(AMX *amx, cell *params)
|
||||
|
||||
if ((funcName = get_amxstring(amx, params[2], 0, kvLength)) && kvLength)
|
||||
{
|
||||
p->key_value = registerSPForwardByName(amx, funcName, FP_CELL, FP_STRING, FP_STRING, FP_CELL, FP_CELL, FP_CELL, FP_CELL, FP_DONE);
|
||||
p->key_value = registerSPForwardByName(amx, funcName, FP_CELL, FP_STRING, FP_STRING, FP_CELL, FP_CELL, FP_CELL, FP_CELL, FP_CELL, FP_DONE);
|
||||
}
|
||||
|
||||
if (kvLength && (funcName = get_amxstring(amx, params[3], 1, nsLength)) && nsLength)
|
||||
{
|
||||
p->new_section = registerSPForwardByName(amx, funcName, FP_CELL, FP_STRING, FP_CELL, FP_CELL, FP_CELL, FP_CELL, FP_DONE);
|
||||
p->new_section = registerSPForwardByName(amx, funcName, FP_CELL, FP_STRING, FP_CELL, FP_CELL, FP_CELL, FP_CELL, FP_CELL, FP_DONE);
|
||||
}
|
||||
|
||||
if (p->key_value == -1 || (nsLength && p->new_section == -1))
|
||||
@ -350,7 +360,7 @@ static cell AMX_NATIVE_CALL INI_SetRawLine(AMX *amx, cell *params)
|
||||
|
||||
if ((funcName = get_amxstring(amx, params[2], 0, length)) && length)
|
||||
{
|
||||
p->raw_line = registerSPForwardByName(amx, funcName, FP_CELL, FP_STRING, FP_CELL, FP_CELL, FP_DONE);
|
||||
p->raw_line = registerSPForwardByName(amx, funcName, FP_CELL, FP_STRING, FP_CELL, FP_CELL, FP_CELL, FP_DONE);
|
||||
}
|
||||
|
||||
if (p->raw_line == -1)
|
||||
|
@ -30,6 +30,7 @@ public:
|
||||
end_section = -1;
|
||||
raw_line = -1;
|
||||
handle = -1;
|
||||
data = 0;
|
||||
}
|
||||
|
||||
public:
|
||||
@ -41,19 +42,19 @@ public:
|
||||
void ReadSMC_ParseStart()
|
||||
{
|
||||
if (parse_start != -1)
|
||||
executeForwards(parse_start, handle);
|
||||
executeForwards(parse_start, handle, data);
|
||||
}
|
||||
|
||||
void ReadSMC_ParseEnd(bool halted, bool failed)
|
||||
{
|
||||
if (parse_end != -1)
|
||||
executeForwards(parse_end, handle, halted ? 1 : 0, failed ? 1 : 0);
|
||||
executeForwards(parse_end, handle, halted ? 1 : 0, failed ? 1 : 0, data);
|
||||
}
|
||||
|
||||
SMCResult ReadSMC_NewSection(const SMCStates *states, const char *name)
|
||||
{
|
||||
if (new_section != -1)
|
||||
return (SMCResult)executeForwards(new_section, handle, name);
|
||||
return (SMCResult)executeForwards(new_section, handle, name, data);
|
||||
|
||||
return SMCResult_Continue;
|
||||
}
|
||||
@ -61,7 +62,7 @@ public:
|
||||
SMCResult ReadSMC_KeyValue(const SMCStates *states, const char *key, const char *value)
|
||||
{
|
||||
if (key_value != -1)
|
||||
return (SMCResult)executeForwards(key_value, handle, key, value);
|
||||
return (SMCResult)executeForwards(key_value, handle, key, value, data);
|
||||
|
||||
return SMCResult_Continue;
|
||||
}
|
||||
@ -69,7 +70,7 @@ public:
|
||||
SMCResult ReadSMC_LeavingSection(const SMCStates *states)
|
||||
{
|
||||
if (end_section != -1)
|
||||
return (SMCResult)executeForwards(end_section, handle);
|
||||
return (SMCResult)executeForwards(end_section, handle, data);
|
||||
|
||||
return SMCResult_Continue;
|
||||
}
|
||||
@ -77,7 +78,7 @@ public:
|
||||
SMCResult ReadSMC_RawLine(const SMCStates *states, const char *line)
|
||||
{
|
||||
if (raw_line != -1)
|
||||
return (SMCResult)executeForwards(raw_line, handle, line, states->line);
|
||||
return (SMCResult)executeForwards(raw_line, handle, line, states->line, data);
|
||||
|
||||
return SMCResult_Continue;
|
||||
}
|
||||
@ -90,19 +91,19 @@ public:
|
||||
void ReadINI_ParseStart()
|
||||
{
|
||||
if (parse_start != -1)
|
||||
executeForwards(parse_start, handle);
|
||||
executeForwards(parse_start, handle, data);
|
||||
}
|
||||
|
||||
void ReadINI_ParseEnd(bool halted)
|
||||
{
|
||||
if (parse_end != -1)
|
||||
executeForwards(parse_end, handle, halted ? 1 : 0);
|
||||
executeForwards(parse_end, handle, halted ? 1 : 0, data);
|
||||
}
|
||||
|
||||
bool ReadINI_NewSection(const char *section, bool invalid_tokens, bool close_bracket, bool extra_tokens, unsigned int *curtok)
|
||||
{
|
||||
if (new_section != -1)
|
||||
return executeForwards(new_section, handle, section, invalid_tokens, close_bracket, extra_tokens, *curtok) > 0 ? true : false;
|
||||
return executeForwards(new_section, handle, section, invalid_tokens, close_bracket, extra_tokens, *curtok, data) > 0 ? true : false;
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -110,7 +111,7 @@ public:
|
||||
bool ReadINI_KeyValue(const char *key, const char *value, bool invalid_tokens, bool equal_token, bool quotes, unsigned int *curtok)
|
||||
{
|
||||
if (key_value != -1)
|
||||
return executeForwards(key_value, handle, key, value, invalid_tokens, equal_token, quotes, *curtok) > 0 ? true : false;
|
||||
return executeForwards(key_value, handle, key, value, invalid_tokens, equal_token, quotes, *curtok, data) > 0 ? true : false;
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -118,7 +119,7 @@ public:
|
||||
bool ReadINI_RawLine(const char *line, unsigned int *curtok)
|
||||
{
|
||||
if (raw_line != -1)
|
||||
return executeForwards(raw_line, handle, line, *curtok) > 0 ? true : false;
|
||||
return executeForwards(raw_line, handle, line, *curtok, data) > 0 ? true : false;
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -130,6 +131,7 @@ public:
|
||||
int end_section;
|
||||
int raw_line;
|
||||
int handle;
|
||||
cell data;
|
||||
};
|
||||
|
||||
extern NativeHandle<ParseInfo> TextParsersHandles;
|
||||
|
Reference in New Issue
Block a user