plugins/include/textparse.inc
author Scott Ehlert <ds@alliedmods.net>
Fri Jun 22 15:37:12 2007 +0000 (2007-06-22)
changeset 1001 8de56a71f200
parent 619 6934bf39171e
child 1330 ab94316bb52b
permissions -rw-r--r--
Implemented amb423 - Added IsClientObserver() native
dvander@374
     1
/**
ds@475
     2
 * vim: set ts=4 :
dvander@374
     3
 * ===============================================================
dvander@374
     4
 * SourceMod (C)2004-2007 AlliedModders LLC.  All rights reserved.
dvander@374
     5
 * ===============================================================
dvander@374
     6
 *
dvander@374
     7
 *  This file is part of the SourceMod/SourcePawn SDK.  This file may only be used 
dvander@374
     8
 * or modified under the Terms and Conditions of its License Agreement, which is found 
dvander@374
     9
 * in LICENSE.txt.  The Terms and Conditions for making SourceMod extensions/plugins 
dvander@374
    10
 * may change at any time.  To view the latest information, see:
dvander@374
    11
 *   http://www.sourcemod.net/license.php
dvander@374
    12
 *
dvander@374
    13
 * Version: $Id$
dvander@374
    14
 */
dvander@374
    15
 
dvander@345
    16
#if defined _textparse_included
dvander@345
    17
 #endinput
dvander@345
    18
#endif
dvander@345
    19
#define _textparse_included
dvander@345
    20
dvander@345
    21
dvander@345
    22
/********************************
dvander@345
    23
 * Everything below describes the SMC Parse, or "SourceMod Configuration" format.
dvander@345
    24
 * This parser is entirely event based.  You must hook events to receive data.
dvander@345
    25
 * The file format itself is nearly identical to Valve's KeyValues format.
dvander@345
    26
 ********************************/
dvander@345
    27
dvander@619
    28
/**
dvander@619
    29
 * Parse result directive.
dvander@619
    30
 */
dvander@345
    31
enum SMCResult
dvander@345
    32
{
ds@475
    33
	SMCParse_Continue,			/**< Continue parsing */
ds@475
    34
	SMCParse_Halt,				/**< Stop parsing here */
ds@475
    35
	SMCParse_HaltFail			/**< Stop parsing and return failure */
dvander@345
    36
};
dvander@345
    37
dvander@619
    38
/**
dvander@619
    39
 * Parse error codes.
dvander@619
    40
 */
dvander@345
    41
enum SMCError
dvander@345
    42
{
ds@475
    43
	SMCError_Okay = 0,			/**< No error */
ds@475
    44
	SMCError_StreamOpen,		/**< Stream failed to open */
ds@475
    45
	SMCError_StreamError,		/**< The stream died... somehow */
ds@475
    46
	SMCError_Custom,			/**< A custom handler threw an error */
ds@475
    47
	SMCError_InvalidSection1,	/**< A section was declared without quotes, and had extra tokens */
ds@475
    48
	SMCError_InvalidSection2,	/**< A section was declared without any header */
ds@475
    49
	SMCError_InvalidSection3,	/**< A section ending was declared with too many unknown tokens */
ds@475
    50
	SMCError_InvalidSection4,	/**< A section ending has no matching beginning */
ds@475
    51
	SMCError_InvalidSection5,	/**< A section beginning has no matching ending */
ds@475
    52
	SMCError_InvalidTokens,		/**< There were too many unidentifiable strings on one line */
ds@475
    53
	SMCError_TokenOverflow,		/**< The token buffer overflowed */
ds@475
    54
	SMCError_InvalidProperty1,	/**< A property was declared outside of any section */
dvander@345
    55
};
dvander@345
    56
dvander@345
    57
/**
dvander@345
    58
 * Creates a new SMC file format parser.  This is used to set parse hooks.
dvander@345
    59
 *
dvander@345
    60
 * @return			A new Handle to an SMC Parse structure.
dvander@345
    61
 */
dvander@364
    62
native Handle:SMC_CreateParser();
dvander@345
    63
dvander@345
    64
/**
dvander@345
    65
 * Parses an SMC file.
dvander@345
    66
 *
ds@475
    67
 * @param smc			A Handle to an SMC Parse structure.
ds@475
    68
 * @param file			A string containing the file path.
ds@475
    69
 * @param line			An optional by reference cell to store the last line number read.
ds@475
    70
 * @param col			An optional by reference cell to store the last column number read.
ds@475
    71
 * @return				An SMCParseError result.
ds@475
    72
 * @error				Invalid or corrupt Handle. 
dvander@345
    73
 */
dvander@345
    74
native SMCError:SMC_ParseFile(Handle:smc, const String:file[], &line=0, &col=0);
dvander@345
    75
dvander@345
    76
/**
dvander@345
    77
 * Gets an error string for an SMCError code.
dvander@345
    78
 * @note SMCError_Okay returns false.
dvander@345
    79
 * @note SMCError_Custom (which is thrown on SMCParse_HaltFail) returns false.
dvander@345
    80
 *
ds@475
    81
 * @param error			The SMCParseError code.
ds@475
    82
 * @param buffer		A string buffer for the error (contents undefined on failure).
ds@475
    83
 * @param buf_max		The maximum size of the buffer.
ds@475
    84
 * @return				True on success, false otherwise.
dvander@345
    85
 */
dvander@345
    86
native bool:SMC_GetErrorString(SMCError:error, String:buffer[], buf_max);
dvander@345
    87
dvander@345
    88
/**
dvander@345
    89
 * Called when parsing is started.
dvander@345
    90
 *
dvander@345
    91
 * @param smc			The SMC Parse Handle.
dvander@345
    92
 * @noreturn
dvander@345
    93
 */
dvander@345
    94
functag SMC_ParseStart public(Handle:smc);
dvander@345
    95
dvander@345
    96
/**
dvander@345
    97
 * Sets the SMC_ParseStart function of a parse Handle.
dvander@345
    98
 *
ds@475
    99
 * @param smc			Handle to an SMC Parse.
ds@475
   100
 * @param func			SMC_ParseStart function.
dvander@345
   101
 * @noreturn
ds@475
   102
 * @error				Invalid or corrupt Handle. 
dvander@345
   103
 */
dvander@345
   104
native SMC_SetParseStart(Handle:smc, SMC_ParseStart:func);
dvander@345
   105
dvander@345
   106
/**
dvander@345
   107
 * Called when parsing is halted.
dvander@345
   108
 *
dvander@345
   109
 * @param smc			The SMC Parse Handle.
ds@475
   110
 * @param halted		True if abnormally halted, false otherwise.
ds@475
   111
 * @param failed		True if parsing failed, false otherwise.
dvander@345
   112
 * @noreturn
dvander@345
   113
 */
dvander@345
   114
functag SMC_ParseEnd public(Handle:smc, bool:halted, bool:failed);
dvander@345
   115
dvander@345
   116
/**
dvander@345
   117
 * Sets the SMC_ParseEnd of a parse handle.
dvander@345
   118
 *
ds@475
   119
 * @param smc			Handle to an SMC Parse.
ds@475
   120
 * @param func			SMC_ParseEnd function.
dvander@345
   121
 * @noreturn
ds@475
   122
 * @error				Invalid or corrupt Handle. 
dvander@345
   123
 */
dvander@345
   124
native SMC_SetParseEnd(Handle:smc, SMC_ParseEnd:func);
dvander@345
   125
dvander@345
   126
/**
dvander@345
   127
 * Called when the parser is entering a new section or sub-section.
dvander@345
   128
 * @note Enclosing quotes are always stripped.
dvander@345
   129
 *
dvander@345
   130
 * @param smc			The SMC Parse Handle.
dvander@345
   131
 * @param name			String containing section name.
dvander@345
   132
 * @param opt_quotes	True if the section name was quote-enclosed in the file.
dvander@345
   133
 * @return				An SMCResult action to take.
dvander@345
   134
 */
dvander@345
   135
functag SMC_NewSection SMCResult:public(Handle:smc, const String:name[], bool:opt_quotes);
dvander@345
   136
dvander@345
   137
/**
dvander@345
   138
 * Called when the parser finds a new key/value pair.
dvander@345
   139
 * @note Enclosing quotes are always stripped.
dvander@345
   140
 *
dvander@345
   141
 * @param smc			The SMC Parse Handle.
dvander@345
   142
 * @param key			String containing key name.
dvander@345
   143
 * @param value			String containing value name.
dvander@345
   144
 * @param key_quotes	Whether or not the key was enclosed in quotes.
dvander@345
   145
 * @param value_quotes	Whether or not the value was enclosed in quotes.
dvander@345
   146
 * @return				An SMCResult action to take.
dvander@345
   147
 */
dvander@345
   148
functag SMC_KeyValue SMCResult:public(Handle:smc, const String:key[], const String:value[], bool:key_quotes, bool:value_quotes);
dvander@345
   149
dvander@345
   150
/**
dvander@345
   151
 * Called when the parser finds the end of the current section.
dvander@345
   152
 *
dvander@345
   153
 * @param smc			The SMC Parse Handle.
dvander@345
   154
 * @return				An SMCResult action to take.
dvander@345
   155
 */
dvander@345
   156
functag SMC_EndSection SMCResult:public(Handle:smc);
dvander@345
   157
dvander@345
   158
/**
dvander@345
   159
 * Sets the three main reader functions.
dvander@345
   160
 *
dvander@345
   161
 * @param smc			An SMC parse Handle.
dvander@345
   162
 * @param ns			An SMC_NewSection function pointer.
dvander@345
   163
 * @param kv			An SMC_KeyValue function pointer.
dvander@345
   164
 * @param es			An SMC_EndSection function pointer.
dvander@345
   165
 * @noreturn
dvander@345
   166
 */
dvander@345
   167
native SMC_SetReaders(Handle:smc, SMC_NewSection:ns, SMC_KeyValue:kv, SMC_EndSection:es);
dvander@345
   168
dvander@345
   169
/**
dvander@345
   170
 * Called whenever a raw line is read.
dvander@345
   171
 *
dvander@345
   172
 * @param smc			The SMC Parse Handle.
dvander@345
   173
 * @param line			A string containing the raw line from the file.
dvander@345
   174
 * @param lineno		The line number it occurs on.
dvander@345
   175
 * @return				An SMCResult action to take.
dvander@345
   176
 */
dvander@345
   177
functag SMC_RawLine SMCResult:public(Handle:smc, const String:line[], lineno);
dvander@345
   178
dvander@345
   179
/**
dvander@345
   180
 * Sets a raw line reader on an SMC parser Handle.
dvander@345
   181
 *
ds@475
   182
 * @param smc			Handle to an SMC Parse.
ds@475
   183
 * @param func			SMC_RawLine function.
dvander@345
   184
 * @noreturn
dvander@345
   185
 */
faluco@427
   186
native SMC_SetRawLine(Handle:smc, SMC_RawLine:func);