plugins/include/textparse.inc
changeset 345 df0b05b4f50d
child 364 99f3e60a7f68
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/plugins/include/textparse.inc	Thu Jan 25 04:37:23 2007 +0000
     1.3 @@ -0,0 +1,165 @@
     1.4 +#if defined _textparse_included
     1.5 + #endinput
     1.6 +#endif
     1.7 +#define _textparse_included
     1.8 +
     1.9 +
    1.10 +/********************************
    1.11 + * Everything below describes the SMC Parse, or "SourceMod Configuration" format.
    1.12 + * This parser is entirely event based.  You must hook events to receive data.
    1.13 + * The file format itself is nearly identical to Valve's KeyValues format.
    1.14 + ********************************/
    1.15 +
    1.16 +enum SMCResult
    1.17 +{
    1.18 +	SMCParse_Continue,		//continue parsing
    1.19 +	SMCParse_Halt,			//stop parsing here
    1.20 +	SMCParse_HaltFail		//stop parsing and return failure
    1.21 +};
    1.22 +
    1.23 +enum SMCError
    1.24 +{
    1.25 +	SMCError_Okay = 0,			//no error
    1.26 +	SMCError_StreamOpen,		//stream failed to open
    1.27 +	SMCError_StreamError,		//the stream died... somehow
    1.28 +	SMCError_Custom,			//a custom handler threw an error
    1.29 +	SMCError_InvalidSection1,	//a section was declared without quotes, and had extra tokens
    1.30 +	SMCError_InvalidSection2,	//a section was declared without any header
    1.31 +	SMCError_InvalidSection3,	//a section ending was declared with too many unknown tokens
    1.32 +	SMCError_InvalidSection4,	//a section ending has no matching beginning
    1.33 +	SMCError_InvalidSection5,	//a section beginning has no matching ending
    1.34 +	SMCError_InvalidTokens,		//there were too many unidentifiable strings on one line
    1.35 +	SMCError_TokenOverflow,		//the token buffer overflowed
    1.36 +	SMCError_InvalidProperty1,	//a property was declared outside of any section
    1.37 +};
    1.38 +
    1.39 +/**
    1.40 + * Creates a new SMC file format parser.  This is used to set parse hooks.
    1.41 + *
    1.42 + * @return			A new Handle to an SMC Parse structure.
    1.43 + */
    1.44 +native Handle:SMC_CreateParse();
    1.45 +
    1.46 +/**
    1.47 + * Parses an SMC file.
    1.48 + *
    1.49 + * @param smc		A Handle to an SMC Parse structure.
    1.50 + * @param file		A string containing the file path.
    1.51 + * @param line		An optional by reference cell to store the last line number read.
    1.52 + * @param col		An optional by reference cell to store the last column number read.
    1.53 + * @return			An SMCParseError result.
    1.54 + * @error			Invalid or corrupt Handle. 
    1.55 + */
    1.56 +native SMCError:SMC_ParseFile(Handle:smc, const String:file[], &line=0, &col=0);
    1.57 +
    1.58 +/**
    1.59 + * Gets an error string for an SMCError code.
    1.60 + * @note SMCError_Okay returns false.
    1.61 + * @note SMCError_Custom (which is thrown on SMCParse_HaltFail) returns false.
    1.62 + *
    1.63 + * @param error		The SMCParseError code.
    1.64 + * @param buffer	A string buffer for the error (contents undefined on failure).
    1.65 + * @param buf_max	The maximum size of the buffer.
    1.66 + * @return			True on success, false otherwise.
    1.67 + */
    1.68 +native bool:SMC_GetErrorString(SMCError:error, String:buffer[], buf_max);
    1.69 +
    1.70 +/**
    1.71 + * Called when parsing is started.
    1.72 + *
    1.73 + * @param smc			The SMC Parse Handle.
    1.74 + * @noreturn
    1.75 + */
    1.76 +functag SMC_ParseStart public(Handle:smc);
    1.77 +
    1.78 +/**
    1.79 + * Sets the SMC_ParseStart function of a parse Handle.
    1.80 + *
    1.81 + * @param smc		Handle to an SMC Parse.
    1.82 + * @param func		SMC_ParseStart function.
    1.83 + * @noreturn
    1.84 + * @error			Invalid or corrupt Handle. 
    1.85 + */
    1.86 +native SMC_SetParseStart(Handle:smc, SMC_ParseStart:func);
    1.87 +
    1.88 +/**
    1.89 + * Called when parsing is halted.
    1.90 + *
    1.91 + * @param smc			The SMC Parse Handle.
    1.92 + * @param halted			True if abnormally halted, false otherwise.
    1.93 + * @param failed			True if parsing failed, false otherwise.
    1.94 + * @noreturn
    1.95 + */
    1.96 +functag SMC_ParseEnd public(Handle:smc, bool:halted, bool:failed);
    1.97 +
    1.98 +/**
    1.99 + * Sets the SMC_ParseEnd of a parse handle.
   1.100 + *
   1.101 + * @param smc		Handle to an SMC Parse.
   1.102 + * @param func		SMC_ParseEnd function.
   1.103 + * @noreturn
   1.104 + * @error			Invalid or corrupt Handle. 
   1.105 + */
   1.106 +native SMC_SetParseEnd(Handle:smc, SMC_ParseEnd:func);
   1.107 +
   1.108 +/**
   1.109 + * Called when the parser is entering a new section or sub-section.
   1.110 + * @note Enclosing quotes are always stripped.
   1.111 + *
   1.112 + * @param smc			The SMC Parse Handle.
   1.113 + * @param name			String containing section name.
   1.114 + * @param opt_quotes	True if the section name was quote-enclosed in the file.
   1.115 + * @return				An SMCResult action to take.
   1.116 + */
   1.117 +functag SMC_NewSection SMCResult:public(Handle:smc, const String:name[], bool:opt_quotes);
   1.118 +
   1.119 +/**
   1.120 + * Called when the parser finds a new key/value pair.
   1.121 + * @note Enclosing quotes are always stripped.
   1.122 + *
   1.123 + * @param smc			The SMC Parse Handle.
   1.124 + * @param key			String containing key name.
   1.125 + * @param value			String containing value name.
   1.126 + * @param key_quotes	Whether or not the key was enclosed in quotes.
   1.127 + * @param value_quotes	Whether or not the value was enclosed in quotes.
   1.128 + * @return				An SMCResult action to take.
   1.129 + */
   1.130 +functag SMC_KeyValue SMCResult:public(Handle:smc, const String:key[], const String:value[], bool:key_quotes, bool:value_quotes);
   1.131 +
   1.132 +/**
   1.133 + * Called when the parser finds the end of the current section.
   1.134 + *
   1.135 + * @param smc			The SMC Parse Handle.
   1.136 + * @return				An SMCResult action to take.
   1.137 + */
   1.138 +functag SMC_EndSection SMCResult:public(Handle:smc);
   1.139 +
   1.140 +/**
   1.141 + * Sets the three main reader functions.
   1.142 + *
   1.143 + * @param smc			An SMC parse Handle.
   1.144 + * @param ns			An SMC_NewSection function pointer.
   1.145 + * @param kv			An SMC_KeyValue function pointer.
   1.146 + * @param es			An SMC_EndSection function pointer.
   1.147 + * @noreturn
   1.148 + */
   1.149 +native SMC_SetReaders(Handle:smc, SMC_NewSection:ns, SMC_KeyValue:kv, SMC_EndSection:es);
   1.150 +
   1.151 +/**
   1.152 + * Called whenever a raw line is read.
   1.153 + *
   1.154 + * @param smc			The SMC Parse Handle.
   1.155 + * @param line			A string containing the raw line from the file.
   1.156 + * @param lineno		The line number it occurs on.
   1.157 + * @return				An SMCResult action to take.
   1.158 + */
   1.159 +functag SMC_RawLine SMCResult:public(Handle:smc, const String:line[], lineno);
   1.160 +
   1.161 +/**
   1.162 + * Sets a raw line reader on an SMC parser Handle.
   1.163 + *
   1.164 + * @param smc		Handle to an SMC Parse.
   1.165 + * @param func		SMC_RawLine function.
   1.166 + * @noreturn
   1.167 + */
   1.168 +native SMC_SetRawLine(Handle:smc, SMC_Rawline:func);