00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #ifndef REGEXPRMAN_HPP
00034 #define REGEXPRMAN_HPP
00035
00036 #include "FSM.hpp"
00037 #include "CompressMan.hpp"
00038
00039 class VPathExprMan;
00040 struct FSMManStateItem;
00041 class SmallBlockUncompressor;
00042
00043
00044 class VPathExpr
00045
00046 {
00047 friend VPathExprMan;
00048
00049 VPathExpr *next;
00050
00051 #ifdef XMILL
00052
00053
00054 #ifdef USE_FORWARD_DATAGUIDE
00055 FSM *forwardfsm;
00056 #endif
00057 FSM *reversefsm;
00058 #endif
00059
00060
00061 char *regexprstr,*regexprendptr,
00062 *regexprusercompressptr;
00063
00064 unsigned long idx:20;
00065
00066
00067
00068 unsigned long leftwhitespacescompress:2;
00069 unsigned long rightwhitespacescompress:2;
00070
00071
00072
00073
00074 #ifdef XMILL
00075 UserCompressor *usercompressor;
00076 #endif
00077 #ifdef XDEMILL
00078 UserUncompressor *useruncompressor;
00079 #endif
00080
00081 void HandlePathExprOption(char * &str,char *endptr);
00082
00083
00084 void ParseUserCompressorString(char * &str,char *endptr);
00085
00086
00087 void PathParseError(char *errmsg,char *errptr);
00088
00089
00090 void CreateXPathEdge(char *from,char *to,FSM *fsm,FSMState *fromstate,FSMState *tostate,char ignore_pounds);
00091
00092
00093
00094
00095 void ParseXPathItem(char * &startptr,char *endptr,FSM *fsm,FSMState *fromstate,FSMState *tostate,char ignore_pounds);
00096 FSM *ParseXPath(char * &str,char *endptr,char ignore_pounds);
00097
00098 void InitWhitespaceHandling();
00099
00100
00101
00102
00103
00104 public:
00105
00106 void *operator new(size_t size, MemStreamer *mem) { return mem->GetByteBlock(size); }
00107 void operator delete(void *ptr) {}
00108 #ifdef SPECIAL_DELETE
00109 void operator delete(void *ptr,MemStreamer *mem) {}
00110 #endif
00111
00112 VPathExpr()
00113 {
00114 #ifdef XMILL
00115
00116 #ifdef USE_FORWARD_DATAGUIDE
00117 forwardfsm=NULL;
00118 #endif
00119 reversefsm=NULL;
00120 next=NULL;
00121 #endif
00122 }
00123
00124 void CreateFromString(char * &str,char *endptr);
00125
00126
00127
00128
00129
00130 void PrintRegExpr();
00131
00132 unsigned long GetIdx() { return idx; }
00133 VPathExpr *GetNext() { return next; }
00134
00135 #ifdef XMILL
00136 FSMState *GetReverseFSMStartState() { return reversefsm->GetStartState();}
00137 #ifdef USE_FORWARD_DATAGUIDE
00138 FSMState *GetForwardFSMStartState() { return forwardfsm->GetStartState();}
00139 #endif
00140
00141 void Store(MemStreamer *output);
00142
00143 #endif
00144
00145 #ifdef XDEMILL
00146 void Load(SmallBlockUncompressor *uncompressor);
00147
00148
00149 #endif
00150
00151 #ifdef XMILL
00152 unsigned long GetUserContNum() { return usercompressor->GetUserContNum(); }
00153 unsigned long GetUserDataSize() { return usercompressor->GetUserDataSize(); }
00154 #endif
00155 #ifdef XDEMILL
00156 unsigned long GetUserContNum() { return useruncompressor->GetUserContNum(); }
00157 unsigned long GetUserDataSize() { return useruncompressor->GetUserDataSize(); }
00158 #endif
00159
00160 #ifdef XMILL
00161 void InitCompress(CompressContainer *cont,char *dataptr)
00162 {
00163 usercompressor->InitCompress(cont,dataptr);
00164 }
00165
00166 void FinishCompress(CompressContainer *cont,char *dataptr)
00167 {
00168 usercompressor->FinishCompress(cont,dataptr);
00169 }
00170
00171 char CompressTextItem(char *str,int len,PathDictNode *pathdictnode,int wsleftlen,int wsrightlen);
00172
00173
00174
00175
00176
00177 UserCompressor *GetUserCompressor()
00178 {
00179 return usercompressor;
00180 }
00181
00182 #endif
00183
00184 #ifdef XDEMILL
00185 UserUncompressor *GetUserUncompressor()
00186 {
00187 return useruncompressor;
00188 }
00189 #endif
00190 };
00191
00192
00193
00194
00195
00196
00197 struct PathTreeNode;
00198
00199 class VPathExprMan
00200
00201 {
00202 unsigned pathexprnum;
00203 VPathExpr *pathexprs;
00204 VPathExpr *lastpathexpr;
00205
00206 public:
00207
00208 VPathExprMan()
00209 {
00210 pathexprnum=0;
00211 pathexprs=lastpathexpr=NULL;
00212 }
00213
00214 VPathExpr *GetPathExpr(unsigned long idx)
00215
00216 {
00217 VPathExpr *curpathexpr=pathexprs;
00218 while(idx--)
00219 curpathexpr=curpathexpr->next;
00220 return curpathexpr;
00221 }
00222 #ifdef XMILL
00223 void AddNewVPathExpr(char * &str,char *endptr);
00224
00225
00226 void Store(MemStreamer *memstream);
00227
00228 #endif
00229
00230 #ifdef XDEMILL
00231 void Load(SmallBlockUncompressor *uncompressor);
00232
00233 #endif
00234
00235 VPathExpr *GetVPathExprs() { return pathexprs; }
00236
00237 void InitWhitespaceHandling();
00238
00239
00240
00241
00242
00243 };
00244
00245 #ifdef XMILL
00246
00247 class PathDictNode;
00248
00249 extern MemStreamer *pathtreemem;
00250
00251 struct FSMManStateItem
00252
00253
00254 {
00255 FSMManStateItem *next;
00256
00257 FSMState *curstate;
00258 VPathExpr *pathexpr;
00259 PathDictNode *pathdictnode;
00260
00261 #ifndef USE_FORWARD_DATAGUIDE
00262 unsigned long overpoundedge:1;
00263 unsigned long poundcount:7;
00264 #endif
00265
00266 public:
00267
00268 void *operator new(size_t size) { return pathtreemem->GetByteBlock(size); }
00269 void operator delete(void *ptr) {}
00270
00271 PathDictNode *GetPathDictNode()
00272 {
00273 return pathdictnode;
00274 }
00275 };
00276
00277 #endif
00278
00279 #endif