amxmodx/amxmodx/textparse.h

139 lines
3.1 KiB
C
Raw Normal View History

2014-08-03 20:43:32 +02:00
/**
* vim: set ts=4 sw=4 tw=99 noet:
*
* AMX Mod X, based on AMX Mod by Aleksander Naszko ("OLO").
* Copyright (C) The AMX Mod X Development Team.
*
* This software is licensed under the GNU General Public License, version 3 or higher.
* Additional exceptions apply. For full license details, see LICENSE.txt or visit:
* https://alliedmods.net/amxmodx-license
*/
2014-07-21 21:12:35 +02:00
#ifndef _INCLUDE_TEXTPARSE_H_
#define _INCLUDE_TEXTPARSE_H_
#include "amxmodx.h"
#include "CTextParsers.h"
#include "natives_handles.h"
2014-07-21 21:12:35 +02:00
class ParseInfo :
public ITextListener_SMC,
public ITextListener_INI
2014-07-21 21:12:35 +02:00
{
public:
ParseInfo()
{
parse_start = -1;
2014-08-03 20:43:32 +02:00
parse_end = -1;
2014-07-21 21:12:35 +02:00
new_section = -1;
2014-08-03 20:43:32 +02:00
key_value = -1;
2014-07-21 21:12:35 +02:00
end_section = -1;
2014-08-03 20:43:32 +02:00
raw_line = -1;
handle = -1;
data = 0;
2014-07-21 21:12:35 +02:00
}
2014-07-21 21:12:35 +02:00
public:
2014-08-03 20:43:32 +02:00
/**
* SMC CONFIG.
*/
2014-07-21 21:12:35 +02:00
void ReadSMC_ParseStart()
{
if (parse_start != -1)
executeForwards(parse_start, handle, data);
}
2014-07-21 21:12:35 +02:00
void ReadSMC_ParseEnd(bool halted, bool failed)
{
if (parse_end != -1)
executeForwards(parse_end, handle, halted ? 1 : 0, failed ? 1 : 0, data);
}
2014-07-21 21:12:35 +02:00
SMCResult ReadSMC_NewSection(const SMCStates *states, const char *name)
{
if (new_section != -1)
return (SMCResult)executeForwards(new_section, handle, name, data);
return SMCResult_Continue;
}
2014-07-21 21:12:35 +02:00
SMCResult ReadSMC_KeyValue(const SMCStates *states, const char *key, const char *value)
{
if (key_value != -1)
return (SMCResult)executeForwards(key_value, handle, key, value, data);
return SMCResult_Continue;
}
2014-07-21 21:12:35 +02:00
SMCResult ReadSMC_LeavingSection(const SMCStates *states)
{
if (end_section != -1)
return (SMCResult)executeForwards(end_section, handle, data);
2014-07-21 21:12:35 +02:00
return SMCResult_Continue;
}
SMCResult ReadSMC_RawLine(const SMCStates *states, const char *line)
{
if (raw_line != -1)
return (SMCResult)executeForwards(raw_line, handle, line, states->line, data);
return SMCResult_Continue;
}
2014-08-03 20:43:32 +02:00
/**
* INI CONFIG.
*/
void ReadINI_ParseStart()
{
if (parse_start != -1)
executeForwards(parse_start, handle, data);
2014-08-03 20:43:32 +02:00
}
void ReadINI_ParseEnd(bool halted)
{
if (parse_end != -1)
executeForwards(parse_end, handle, halted ? 1 : 0, data);
2014-08-03 20:43:32 +02:00
}
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, data) > 0 ? true : false;
2014-08-03 20:43:32 +02:00
return true;
}
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, data) > 0 ? true : false;
2014-08-03 20:43:32 +02:00
return true;
}
bool ReadINI_RawLine(const char *line, unsigned int *curtok)
{
if (raw_line != -1)
return executeForwards(raw_line, handle, line, *curtok, data) > 0 ? true : false;
2014-07-21 21:12:35 +02:00
2014-08-03 20:43:32 +02:00
return true;
2014-07-21 21:12:35 +02:00
}
public:
int parse_start;
int parse_end;
int new_section;
int key_value;
int end_section;
int raw_line;
int handle;
cell data;
2014-07-21 21:12:35 +02:00
};
extern NativeHandle<ParseInfo> TextParsersHandles;
2014-07-21 21:12:35 +02:00
#endif // _INCLUDE_TEXTPARSE_H_