Google

Main Page   Class Hierarchy   Compound List   File List   Compound Members  

parser.h

00001 /*
00002     Copyright (C) 1998,2000 by Jorrit Tyberghein and Steve Israelson
00003 
00004     This library is free software; you can redistribute it and/or
00005     modify it under the terms of the GNU Library General Public
00006     License as published by the Free Software Foundation; either
00007     version 2 of the License, or (at your option) any later version.
00008 
00009     This library is distributed in the hope that it will be useful,
00010     but WITHOUT ANY WARRANTY; without even the implied warranty of
00011     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012     Library General Public License for more details.
00013 
00014     You should have received a copy of the GNU Library General Public
00015     License along with this library; if not, write to the Free
00016     Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00017 */
00018 
00019 #ifndef __CS_PARSER_H__
00020 #define __CS_PARSER_H__
00021 
00022 #include "csutil/csvector.h"
00023 #include "csutil/util.h"
00024 
00029 struct csTokenDesc
00030 {
00032   long  id;
00034   char *token;
00035   csTokenDesc (){id=0; token=NULL;}
00036   ~csTokenDesc ()
00037   {delete [] token;}
00038 };
00039 
00040 class csTokenVector : public csVector
00041 {
00042   public:
00043     virtual ~csTokenVector () {DeleteAll ();}
00044     virtual bool FreeItem (csSome Item){ delete (csTokenDesc*)Item; return true;}
00045     csTokenDesc* Get (int idx) const {return (csTokenDesc*)csVector::Get (idx);}
00046     virtual int Compare (csSome Item1, csSome Item2, int Mode=0) const
00047     { (void)Mode;
00048       csTokenDesc *td1 = (csTokenDesc*)Item1;
00049       csTokenDesc *td2 = (csTokenDesc*)Item2;
00050       int l1 = (td1->token ? strlen(td1->token) : 0);
00051       int l2 = (td2->token ? strlen(td2->token) : 0);
00052       return l1 > l2 ? -1 : l1 < l2 ? 1 : 0;
00053     }
00054     virtual int CompareKey (csSome Item1, csConstSome Key, int Mode=0) const
00055     { (void)Mode;
00056       csTokenDesc *td1 = (csTokenDesc*)Item1;
00057       csTokenDesc *td2 = (csTokenDesc*)Key;
00058       int l1 = (td1->token ? strlen(td1->token) : 0);
00059       int l2 = (td2->token ? strlen(td2->token) : 0);
00060       return l1 > l2 ? -1 : l1 < l2 ? 1 : 0;
00061     }
00062     csTokenVector *Push (int id, const char *name)
00063     {
00064       csTokenDesc *td = new csTokenDesc;
00065       td->id = id;
00066       td->token = (name ? csStrNew (name) : 0);
00067       InsertSorted (td);
00068       return this;
00069     }
00070 };
00071 
00113 #define CS_TOKEN_DEF_START              \
00114   enum                                  \
00115   {                                     \
00116     CS_TOKEN_EMPTY = 0,
00117 #define CS_TOKEN_DEF(name)              \
00118     CS_TOKEN_ ## name,
00119 #define CS_TOKEN_DEF_END                \
00120     CS_TOKEN_TOTAL_COUNT                \
00121   };
00122 #define CS_TOKEN_TABLE_START(name)      \
00123   csTokenVector name ## _hlp, *name;        \
00124   name = &name ## _hlp;                 \
00125   name->
00126 #define CS_TOKEN_TABLE(name)            \
00127     Push (CS_TOKEN_ ## name, #name )->
00128 #define CS_TOKEN_TABLE_END              \
00129     Push (0, NULL);
00130 
00131 #define CS_PARSERR_EOF                  -2
00132 #define CS_PARSERR_TOKENNOTFOUND        -1
00133 
00137 int csGetParserLine ();
00138 
00144 void csResetParserLine ();
00145 
00149 char* csGetLastOffender ();
00150 
00165 long csGetObject(char **buf, csTokenVector *tokens, char **name, char **data);
00182 long csGetCommand(char **buf, csTokenVector *tokens, char **params);
00190 char *csGetSubText(char **buf, char open, char close);
00195 void csSkipCharacters(char **buf, const char *toSkip);
00200 char *csGetAssignmentText(char **buf);
00201 
00202 #endif // __CS_PARSER_H__

Generated for Crystal Space by doxygen 1.2.5 written by Dimitri van Heesch, ©1997-2000