plugins/include/textparse.inc
author Scott Ehlert <ds@alliedmods.net>
Sun Sep 14 02:58:58 2008 -0500 (2008-09-14)
changeset 2287 017a725c9d17
parent 1952 b7aa2b626807
child 2289 44045ead61cd
permissions -rw-r--r--
Eliminated head for dead branch: sourcemod-1.1.0
ds@1952
     1
/**
ds@1952
     2
 * vim: set ts=4 :
ds@1952
     3
 * =============================================================================
ds@1952
     4
 * SourceMod (C)2004-2008 AlliedModders LLC.  All rights reserved.
ds@1952
     5
 * =============================================================================
ds@1952
     6
 *
ds@1952
     7
 * This file is part of the SourceMod/SourcePawn SDK.
ds@1952
     8
 *
ds@1952
     9
 * This program is free software; you can redistribute it and/or modify it under
ds@1952
    10
 * the terms of the GNU General Public License, version 3.0, as published by the
ds@1952
    11
 * Free Software Foundation.
ds@1952
    12
 * 
ds@1952
    13
 * This program is distributed in the hope that it will be useful, but WITHOUT
ds@1952
    14
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
ds@1952
    15
 * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
ds@1952
    16
 * details.
ds@1952
    17
 *
ds@1952
    18
 * You should have received a copy of the GNU General Public License along with
ds@1952
    19
 * this program.  If not, see <http://www.gnu.org/licenses/>.
ds@1952
    20
 *
ds@1952
    21
 * As a special exception, AlliedModders LLC gives you permission to link the
ds@1952
    22
 * code of this program (as well as its derivative works) to "Half-Life 2," the
ds@1952
    23
 * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
ds@1952
    24
 * by the Valve Corporation.  You must obey the GNU General Public License in
ds@1952
    25
 * all respects for all other code used.  Additionally, AlliedModders LLC grants
ds@1952
    26
 * this exception to all derivative works.  AlliedModders LLC defines further
ds@1952
    27
 * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
ds@1952
    28
 * or <http://www.sourcemod.net/license.php>.
ds@1952
    29
 *
ds@1952
    30
 * Version: $Id$
ds@1952
    31
 */
ds@1952
    32
 
ds@1952
    33
#if defined _textparse_included
ds@1952
    34
 #endinput
ds@1952
    35
#endif
ds@1952
    36
#define _textparse_included
ds@1952
    37
ds@1952
    38
ds@1952
    39
/********************************
ds@1952
    40
 * Everything below describes the SMC Parse, or "SourceMod Configuration" format.
ds@1952
    41
 * This parser is entirely event based.  You must hook events to receive data.
ds@1952
    42
 * The file format itself is nearly identical to Valve's KeyValues format.
ds@1952
    43
 ********************************/
ds@1952
    44
ds@1952
    45
/**
ds@1952
    46
 * Parse result directive.
ds@1952
    47
 */
ds@1952
    48
enum SMCResult
ds@1952
    49
{
ds@1952
    50
	SMCParse_Continue,			/**< Continue parsing */
ds@1952
    51
	SMCParse_Halt,				/**< Stop parsing here */
ds@1952
    52
	SMCParse_HaltFail			/**< Stop parsing and return failure */
ds@1952
    53
};
ds@1952
    54
ds@1952
    55
/**
ds@1952
    56
 * Parse error codes.
ds@1952
    57
 */
ds@1952
    58
enum SMCError
ds@1952
    59
{
ds@1952
    60
	SMCError_Okay = 0,			/**< No error */
ds@1952
    61
	SMCError_StreamOpen,		/**< Stream failed to open */
ds@1952
    62
	SMCError_StreamError,		/**< The stream died... somehow */
ds@1952
    63
	SMCError_Custom,			/**< A custom handler threw an error */
ds@1952
    64
	SMCError_InvalidSection1,	/**< A section was declared without quotes, and had extra tokens */
ds@1952
    65
	SMCError_InvalidSection2,	/**< A section was declared without any header */
ds@1952
    66
	SMCError_InvalidSection3,	/**< A section ending was declared with too many unknown tokens */
ds@1952
    67
	SMCError_InvalidSection4,	/**< A section ending has no matching beginning */
ds@1952
    68
	SMCError_InvalidSection5,	/**< A section beginning has no matching ending */
ds@1952
    69
	SMCError_InvalidTokens,		/**< There were too many unidentifiable strings on one line */
ds@1952
    70
	SMCError_TokenOverflow,		/**< The token buffer overflowed */
ds@1952
    71
	SMCError_InvalidProperty1,	/**< A property was declared outside of any section */
ds@1952
    72
};
ds@1952
    73
ds@1952
    74
/**
ds@1952
    75
 * Creates a new SMC file format parser.  This is used to set parse hooks.
ds@1952
    76
 *
ds@1952
    77
 * @return			A new Handle to an SMC Parse structure.
ds@1952
    78
 */
ds@1952
    79
native Handle:SMC_CreateParser();
ds@1952
    80
ds@1952
    81
/**
ds@1952
    82
 * Parses an SMC file.
ds@1952
    83
 *
ds@1952
    84
 * @param smc			A Handle to an SMC Parse structure.
ds@1952
    85
 * @param file			A string containing the file path.
ds@1952
    86
 * @param line			An optional by reference cell to store the last line number read.
ds@1952
    87
 * @param col			An optional by reference cell to store the last column number read.
ds@1952
    88
 * @return				An SMCParseError result.
ds@1952
    89
 * @error				Invalid or corrupt Handle. 
ds@1952
    90
 */
ds@1952
    91
native SMCError:SMC_ParseFile(Handle:smc, const String:file[], &line=0, &col=0);
ds@1952
    92
ds@1952
    93
/**
ds@1952
    94
 * Gets an error string for an SMCError code.
ds@1952
    95
 * @note SMCError_Okay returns false.
ds@1952
    96
 * @note SMCError_Custom (which is thrown on SMCParse_HaltFail) returns false.
ds@1952
    97
 *
ds@1952
    98
 * @param error			The SMCParseError code.
ds@1952
    99
 * @param buffer		A string buffer for the error (contents undefined on failure).
ds@1952
   100
 * @param buf_max		The maximum size of the buffer.
ds@1952
   101
 * @return				True on success, false otherwise.
ds@1952
   102
 */
ds@1952
   103
native bool:SMC_GetErrorString(SMCError:error, String:buffer[], buf_max);
ds@1952
   104
ds@1952
   105
/**
ds@1952
   106
 * Called when parsing is started.
ds@1952
   107
 *
ds@1952
   108
 * @param smc			The SMC Parse Handle.
ds@1952
   109
 * @noreturn
ds@1952
   110
 */
ds@1952
   111
functag SMC_ParseStart public(Handle:smc);
ds@1952
   112
ds@1952
   113
/**
ds@1952
   114
 * Sets the SMC_ParseStart function of a parse Handle.
ds@1952
   115
 *
ds@1952
   116
 * @param smc			Handle to an SMC Parse.
ds@1952
   117
 * @param func			SMC_ParseStart function.
ds@1952
   118
 * @noreturn
ds@1952
   119
 * @error				Invalid or corrupt Handle. 
ds@1952
   120
 */
ds@1952
   121
native SMC_SetParseStart(Handle:smc, SMC_ParseStart:func);
ds@1952
   122
ds@1952
   123
/**
ds@1952
   124
 * Called when parsing is halted.
ds@1952
   125
 *
ds@1952
   126
 * @param smc			The SMC Parse Handle.
ds@1952
   127
 * @param halted		True if abnormally halted, false otherwise.
ds@1952
   128
 * @param failed		True if parsing failed, false otherwise.
ds@1952
   129
 * @noreturn
ds@1952
   130
 */
ds@1952
   131
functag SMC_ParseEnd public(Handle:smc, bool:halted, bool:failed);
ds@1952
   132
ds@1952
   133
/**
ds@1952
   134
 * Sets the SMC_ParseEnd of a parse handle.
ds@1952
   135
 *
ds@1952
   136
 * @param smc			Handle to an SMC Parse.
ds@1952
   137
 * @param func			SMC_ParseEnd function.
ds@1952
   138
 * @noreturn
ds@1952
   139
 * @error				Invalid or corrupt Handle. 
ds@1952
   140
 */
ds@1952
   141
native SMC_SetParseEnd(Handle:smc, SMC_ParseEnd:func);
ds@1952
   142
ds@1952
   143
/**
ds@1952
   144
 * Called when the parser is entering a new section or sub-section.
ds@1952
   145
 * @note Enclosing quotes are always stripped.
ds@1952
   146
 *
ds@1952
   147
 * @param smc			The SMC Parse Handle.
ds@1952
   148
 * @param name			String containing section name.
ds@1952
   149
 * @param opt_quotes	True if the section name was quote-enclosed in the file.
ds@1952
   150
 * @return				An SMCResult action to take.
ds@1952
   151
 */
ds@1952
   152
functag SMC_NewSection SMCResult:public(Handle:smc, const String:name[], bool:opt_quotes);
ds@1952
   153
ds@1952
   154
/**
ds@1952
   155
 * Called when the parser finds a new key/value pair.
ds@1952
   156
 * @note Enclosing quotes are always stripped.
ds@1952
   157
 *
ds@1952
   158
 * @param smc			The SMC Parse Handle.
ds@1952
   159
 * @param key			String containing key name.
ds@1952
   160
 * @param value			String containing value name.
ds@1952
   161
 * @param key_quotes	Whether or not the key was enclosed in quotes.
ds@1952
   162
 * @param value_quotes	Whether or not the value was enclosed in quotes.
ds@1952
   163
 * @return				An SMCResult action to take.
ds@1952
   164
 */
ds@1952
   165
functag SMC_KeyValue SMCResult:public(Handle:smc, const String:key[], const String:value[], bool:key_quotes, bool:value_quotes);
ds@1952
   166
ds@1952
   167
/**
ds@1952
   168
 * Called when the parser finds the end of the current section.
ds@1952
   169
 *
ds@1952
   170
 * @param smc			The SMC Parse Handle.
ds@1952
   171
 * @return				An SMCResult action to take.
ds@1952
   172
 */
ds@1952
   173
functag SMC_EndSection SMCResult:public(Handle:smc);
ds@1952
   174
ds@1952
   175
/**
ds@1952
   176
 * Sets the three main reader functions.
ds@1952
   177
 *
ds@1952
   178
 * @param smc			An SMC parse Handle.
ds@1952
   179
 * @param ns			An SMC_NewSection function pointer.
ds@1952
   180
 * @param kv			An SMC_KeyValue function pointer.
ds@1952
   181
 * @param es			An SMC_EndSection function pointer.
ds@1952
   182
 * @noreturn
ds@1952
   183
 */
ds@1952
   184
native SMC_SetReaders(Handle:smc, SMC_NewSection:ns, SMC_KeyValue:kv, SMC_EndSection:es);
ds@1952
   185
ds@1952
   186
/**
ds@1952
   187
 * Called whenever a raw line is read.
ds@1952
   188
 *
ds@1952
   189
 * @param smc			The SMC Parse Handle.
ds@1952
   190
 * @param line			A string containing the raw line from the file.
ds@1952
   191
 * @param lineno		The line number it occurs on.
ds@1952
   192
 * @return				An SMCResult action to take.
ds@1952
   193
 */
ds@1952
   194
functag SMC_RawLine SMCResult:public(Handle:smc, const String:line[], lineno);
ds@1952
   195
ds@1952
   196
/**
ds@1952
   197
 * Sets a raw line reader on an SMC parser Handle.
ds@1952
   198
 *
ds@1952
   199
 * @param smc			Handle to an SMC Parse.
ds@1952
   200
 * @param func			SMC_RawLine function.
ds@1952
   201
 * @noreturn
ds@1952
   202
 */
ds@1952
   203
native SMC_SetRawLine(Handle:smc, SMC_RawLine:func);