[33d539] | 1 | %{ |
---|
| 2 | /**************************************** |
---|
| 3 | * Computer Algebra System SINGULAR * |
---|
| 4 | ****************************************/ |
---|
| 5 | #include <stdio.h> |
---|
| 6 | #include <string.h> |
---|
| 7 | #include <stdlib.h> |
---|
| 8 | #include <ctype.h> |
---|
[b1dfaf] | 9 | #include <kernel/mod2.h> |
---|
[33d539] | 10 | #ifdef STANDALONE_PARSER |
---|
[599326] | 11 | #include <Singular/utils.h> |
---|
[0ee865] | 12 | |
---|
| 13 | int initializeGMP(){ return 1; } // NEEDED FOR MAIN APP. LINKING!!! |
---|
| 14 | int mmInit(void) {return 1; } // ? due to SINGULAR!!!...??? |
---|
| 15 | |
---|
[d40d574] | 16 | #define HAVE_LIBPARSER |
---|
| 17 | #define YYLPDEBUG 1 |
---|
[5e80f6] | 18 | #define myfread fread |
---|
[33d539] | 19 | #else |
---|
[599326] | 20 | #include <Singular/subexpr.h> |
---|
| 21 | #include <Singular/grammar.h> |
---|
| 22 | #include <Singular/ipshell.h> |
---|
| 23 | #include <Singular/ipid.h> |
---|
| 24 | #include <Singular/tok.h> |
---|
[0fb34ba] | 25 | #include <misc/options.h> |
---|
[599326] | 26 | #include <kernel/febase.h> |
---|
[b1dfaf] | 27 | #include <omalloc/omalloc.h> |
---|
[33d539] | 28 | #endif |
---|
[599326] | 29 | #include <Singular/libparse.h> |
---|
[33d539] | 30 | |
---|
| 31 | #ifdef HAVE_LIBPARSER |
---|
[d40d574] | 32 | #define YY_SKIP_YYWRAP |
---|
[33d539] | 33 | |
---|
[7035b2] | 34 | typedef enum { LP_NONE, LP_INFO, LP_CATEGORY, LP_URL, LP_VERSION} lib_cmds; |
---|
[5480da] | 35 | |
---|
[33d539] | 36 | int libread(FILE* f, char* buf, int max_size); |
---|
| 37 | int current_pos(int i); |
---|
[5480da] | 38 | void print_version(lp_modes mode, char *p); |
---|
| 39 | void copy_string(lp_modes mode); |
---|
[a3bc95e] | 40 | extern void piCleanUp(procinfov pi); |
---|
[5480da] | 41 | void make_version(char *p, int what); |
---|
[33d539] | 42 | |
---|
| 43 | int brace1 = 0; /* { } */ |
---|
| 44 | int brace2 = 0; /* ( ) */ |
---|
| 45 | int brace3 = 0; /* [ ] */ |
---|
| 46 | int quote = 0; /* " */ |
---|
| 47 | int offset = 0; |
---|
[c2da0a] | 48 | BOOLEAN p_static = FALSE; |
---|
[33d539] | 49 | int old_state = 0; |
---|
[5480da] | 50 | lib_cmds last_cmd = LP_NONE; |
---|
[33d539] | 51 | |
---|
| 52 | char libnamebuf[128]; |
---|
[6d32d7] | 53 | char *text_buffer=NULL; |
---|
[5480da] | 54 | long string_start; |
---|
[33d539] | 55 | |
---|
| 56 | char *yylp_buffer_start; |
---|
[b1dfaf] | 57 | #ifndef NEW_FLEX |
---|
[33d539] | 58 | int yylplineno = 1; |
---|
[b1dfaf] | 59 | #endif /* NEW_FLEX */ |
---|
[d2b2a7] | 60 | int lpverbose = 0, check = 0; |
---|
[f36635] | 61 | int texinfo_out = 0; |
---|
[d2b2a7] | 62 | int found_info=0, |
---|
[14b6448] | 63 | found_cat=0, |
---|
[d2b2a7] | 64 | found_version=0, |
---|
| 65 | found_oldhelp = 0, |
---|
| 66 | found_proc_in_proc = 0; |
---|
[33d539] | 67 | |
---|
[85e68dd] | 68 | const char *yylp_errlist[]= { |
---|
[33d539] | 69 | "", |
---|
| 70 | "missing close bracket ')' for proc definition in line %d.", /* 1 */ |
---|
| 71 | "missing close bracket ')' for procbody in line %d.", /* 2 */ |
---|
| 72 | "missing close bracket ']' for procbody in line %d.", /* 3 */ |
---|
| 73 | "too many ')' closed brackets in line %d.", /* 4 */ |
---|
| 74 | "too many ']' closed brackets in line %d.", /* 5 */ |
---|
| 75 | "missing close bracket ')' for example in line %d.", /* 6 */ |
---|
| 76 | "missing close bracket ']' for example in line %d.", /* 7 */ |
---|
[60a3add] | 77 | "cannot assign character '%c' in line %d to any group.", /* 8 */ |
---|
[33d539] | 78 | "there must be a quote missing somewhere before line %d.", /* 9 */ |
---|
| 79 | "missing close bracket '}' at end of library in line %d.", /* 10 */ |
---|
| 80 | "missing close bracket ')' at end of library in line %d.", /* 11 */ |
---|
[5480da] | 81 | "missing close bracket ']' at end of library in line %d.", /* 12 */ |
---|
[33d539] | 82 | NULL |
---|
| 83 | }; |
---|
| 84 | int yylp_errno = 0; |
---|
| 85 | |
---|
[d40d574] | 86 | #ifdef STANDALONE_PARSER |
---|
[33d539] | 87 | procinfov pi; |
---|
[5ecf042] | 88 | int category_out = 0; |
---|
[a70441f] | 89 | void printpi(procinfov pi); |
---|
| 90 | void pi_clear(procinfov pi); |
---|
[33d539] | 91 | extern "C" { |
---|
| 92 | int yylpwrap(); |
---|
| 93 | } |
---|
[d2b2a7] | 94 | void main_init(int argc, char *argv[]); |
---|
| 95 | void main_result(char *libname); |
---|
[d40d574] | 96 | #else /* STANDALONE_PARSER */ |
---|
[56459d] | 97 | idhdl h0; |
---|
[a3bc95e] | 98 | idhdl h_top; |
---|
[d40d574] | 99 | #define pi IDPROC(h0) |
---|
[d636ad] | 100 | extern "C" |
---|
| 101 | { |
---|
| 102 | int yylpwrap(); |
---|
| 103 | } |
---|
[33d539] | 104 | extern libstackv library_stack; |
---|
[d40d574] | 105 | #endif /* STANDALONE_PARSER */ |
---|
[33d539] | 106 | |
---|
[f92cf8] | 107 | static unsigned long help_chksum; |
---|
[d40d574] | 108 | |
---|
| 109 | #define SET_DEF_END(mode, pi, p) \ |
---|
| 110 | if ( mode == LOAD_LIB) pi->data.s.def_end = p; |
---|
| 111 | #define SET_HELP_START(mode, pi, p) \ |
---|
| 112 | if ( mode == LOAD_LIB) {pi->data.s.help_start = p; help_chksum = 0;} |
---|
| 113 | #define SET_HELP_END(mode, pi, p) \ |
---|
| 114 | if ( mode == LOAD_LIB) {pi->data.s.help_end = p; \ |
---|
| 115 | pi->data.s.help_chksum = help_chksum;} |
---|
| 116 | |
---|
| 117 | #define SET_BODY_START(mode, pi, l, p) \ |
---|
| 118 | if ( mode == LOAD_LIB) \ |
---|
| 119 | { \ |
---|
| 120 | pi->data.s.body_lineno = l; \ |
---|
| 121 | pi->data.s.body_start = p; \ |
---|
[c4bbf1f] | 122 | } |
---|
[d40d574] | 123 | #define SET_BODY_END(mode, pi, p) \ |
---|
| 124 | if ( mode == LOAD_LIB) \ |
---|
| 125 | { \ |
---|
[c4bbf1f] | 126 | pi->data.s.body_end = p-1; \ |
---|
| 127 | pi->data.s.proc_end = p-1; \ |
---|
| 128 | } |
---|
| 129 | |
---|
[d40d574] | 130 | #define SET_EXAMPLE_START(mode, pi, l, p) \ |
---|
| 131 | if ( mode == LOAD_LIB) \ |
---|
| 132 | { \ |
---|
| 133 | pi->data.s.example_lineno = l; \ |
---|
| 134 | pi->data.s.example_start = p; \ |
---|
| 135 | } |
---|
| 136 | #define SET_PROC_END(mode, pi, p) \ |
---|
| 137 | if ( mode == LOAD_LIB) \ |
---|
| 138 | { \ |
---|
| 139 | pi->data.s.proc_end = p-1; \ |
---|
| 140 | if(pi->data.s.body_end==0) \ |
---|
| 141 | pi->data.s.body_end = p-1; \ |
---|
[c4bbf1f] | 142 | } |
---|
| 143 | |
---|
[f92cf8] | 144 | #define ROTATE_RIGHT(c) if ((c) & 01) (c) = ((c) >>1) + 0x8000; else (c) >>= 1; |
---|
| 145 | #define IncrCheckSum(c) \ |
---|
[d40d574] | 146 | do \ |
---|
| 147 | { \ |
---|
[f92cf8] | 148 | ROTATE_RIGHT(help_chksum); \ |
---|
| 149 | help_chksum += c; \ |
---|
| 150 | help_chksum &= 0xffff; \ |
---|
[d40d574] | 151 | } \ |
---|
[f92cf8] | 152 | while(0) |
---|
| 153 | |
---|
[d40d574] | 154 | #undef YY_DECL |
---|
[e2202ee] | 155 | #define YY_DECL int yylex(const char *newlib, const char *libfile, \ |
---|
[a3bc95e] | 156 | lib_style_types *lib_style, \ |
---|
| 157 | idhdl pl, BOOLEAN autoexport, lp_modes mode) |
---|
[d40d574] | 158 | #undef YY_INPUT |
---|
| 159 | #define YY_INPUT(buf,result,max_size) \ |
---|
[33d539] | 160 | if ( ((result = libread( (yyin), (char *) buf, max_size )) < 0 ) \ |
---|
[df595d] | 161 | && ferror( yyin ) ) \ |
---|
| 162 | YY_FATAL_ERROR( "read in flex scanner failed" ); |
---|
[33d539] | 163 | |
---|
[d40d574] | 164 | #define YY_USER_INIT { \ |
---|
[33d539] | 165 | BEGIN(header); \ |
---|
| 166 | yylplineno = 1; \ |
---|
| 167 | yylp_errno = 0; \ |
---|
[5480da] | 168 | *lib_style = OLD_LIBSTYLE; \ |
---|
[33d539] | 169 | strcpy(libnamebuf,"(**unknown version**)"); \ |
---|
| 170 | } |
---|
| 171 | |
---|
[d40d574] | 172 | #if 0 |
---|
[df595d] | 173 | <pbody>proc[ \t]+{name} { |
---|
[33d539] | 174 | printf("MISSING: PROC-cmd found. ERROR!\n"); } |
---|
[df595d] | 175 | <pbody>example[ \t]*\n { |
---|
[33d539] | 176 | yylplineno++; |
---|
| 177 | printf("MISSING: EXAMPLE-cmd found. ERROR!\n"); } |
---|
[60a3add] | 178 | info=+"\"" { |
---|
[d40d574] | 179 | #endif |
---|
| 180 | |
---|
[33d539] | 181 | %} |
---|
| 182 | |
---|
| 183 | digit [0-9] |
---|
| 184 | letter [@a-zA-Z\'] |
---|
| 185 | name ({letter}({letter}*{digit}*_*)*|_) |
---|
[d2b2a7] | 186 | varname ({letter}({letter}*{digit}*_*\(\))*|_|#) |
---|
[33d539] | 187 | letters ({letter}|{digit}|[_./#%^*:,]) |
---|
| 188 | string ({letters}*) |
---|
| 189 | comment [\/][\/] |
---|
[795d89] | 190 | dolar [$] |
---|
[d2b2a7] | 191 | nls [\n\r] |
---|
| 192 | symbols [~!@#$%^&*()_+-=\\\|\[\];:,<.>/\?\' \t\~\`] |
---|
| 193 | asymbols ({symbols}|[{}]) |
---|
| 194 | bsymbols ({symbols}|{escbrack}|[}]) |
---|
| 195 | aletters ({letter}|{digit}|{asymbols}|{dolar}|{escquote}|{nls}) |
---|
| 196 | bletters ({letter}|{digit}|{bsymbols}|{dolar}|{quote}|{nls}) |
---|
| 197 | cletters ({letter}|{digit}|{asymbols}|{dolar}|{quote}) |
---|
[5480da] | 198 | strings ({aletters}*) |
---|
[d2b2a7] | 199 | escstrings ({bletters}*) |
---|
| 200 | fstring ({cletters}*) |
---|
| 201 | param ({name}+{tos}+{varname}) |
---|
| 202 | parameters ({param}(,{param})*) |
---|
| 203 | paramlist ("("{parameters}")") |
---|
[5480da] | 204 | quote [\"] |
---|
| 205 | escquote (\\\") |
---|
[d2b2a7] | 206 | escbrack (\\\{) |
---|
[2703e9] | 207 | tnl ([ \t\n\r]*) |
---|
[d2b2a7] | 208 | eos ({quote}+{tnl}+"{") |
---|
| 209 | tos ([ \t]*) |
---|
| 210 | eq ([ \t]*+=[ \t]*) |
---|
[2703e9] | 211 | eqnl ([ \t\n\r]*+=[ \t\n\r]*) |
---|
[33d539] | 212 | |
---|
| 213 | /* %start START */ |
---|
| 214 | |
---|
| 215 | %x header |
---|
| 216 | %x help |
---|
| 217 | %x libcmd |
---|
[14b6448] | 218 | %x libcmd2 |
---|
[33d539] | 219 | %x pdef |
---|
| 220 | %x phead |
---|
[d2b2a7] | 221 | %x poldhelp |
---|
| 222 | %x phelp |
---|
[33d539] | 223 | %x pbody |
---|
| 224 | %x pstr |
---|
| 225 | %x pexample |
---|
| 226 | %x pestr |
---|
| 227 | %x string |
---|
| 228 | %x comment |
---|
[60a3add] | 229 | %x info |
---|
[14b6448] | 230 | %x category |
---|
[7035b2] | 231 | %x url |
---|
[60a3add] | 232 | %x version |
---|
[33d539] | 233 | |
---|
| 234 | %% |
---|
| 235 | (\/\/[^\n]*)|(^#![^\n]*)|([ \t]) { } |
---|
[5480da] | 236 | \/\/* { old_state = YYSTATE; BEGIN(comment); } |
---|
| 237 | |
---|
[befd6b5] | 238 | (info+{eqnl}+{quote}+{strings}+{quote}) { |
---|
[60a3add] | 239 | yyless(4); old_state = YYSTATE; BEGIN(info); |
---|
| 240 | } |
---|
[14b6448] | 241 | (category+{eqnl}+{quote}+{strings}+{quote}) { |
---|
| 242 | yyless(8); old_state = YYSTATE; BEGIN(category); |
---|
| 243 | } |
---|
[7035b2] | 244 | (url+{eqnl}+{quote}+{strings}+{quote}) { |
---|
| 245 | if ( mode != GET_INFO ) |
---|
| 246 | { |
---|
| 247 | #ifdef STANDALONE_PARSER |
---|
| 248 | if (texinfo_out) |
---|
| 249 | { |
---|
| 250 | char *c = yytext; |
---|
| 251 | printf("$url = \""); |
---|
| 252 | while ((*c != '\0') && (*c != '"')) c++; |
---|
| 253 | c++; |
---|
| 254 | while ((*c != '\0') && (*c != '"')) |
---|
| 255 | { |
---|
| 256 | if (*c != '\r') putchar(*c); |
---|
| 257 | c++; |
---|
| 258 | } |
---|
| 259 | printf("\";\n"); |
---|
| 260 | } |
---|
| 261 | #endif |
---|
| 262 | } |
---|
| 263 | } |
---|
| 264 | |
---|
[60a3add] | 265 | (version+{eqnl}+{quote}+{strings}+{quote}) { |
---|
[d2b2a7] | 266 | found_version++; |
---|
[befd6b5] | 267 | if ( mode != GET_INFO ) |
---|
| 268 | { |
---|
[5480da] | 269 | make_version(yytext,1); |
---|
[d40d574] | 270 | #ifdef STANDALONE_PARSER |
---|
| 271 | if (texinfo_out) |
---|
[460c1e1] | 272 | { |
---|
| 273 | char *c = libnamebuf; |
---|
| 274 | printf("$version = \""); |
---|
| 275 | while (*c != '\0') |
---|
| 276 | { |
---|
[dcc635] | 277 | if (*c == '$' || *c == '@') putchar('\\'); |
---|
| 278 | if (*c != '\r') putchar(*c); |
---|
[d40d574] | 279 | if (*c == '\\') |
---|
[dcc635] | 280 | { |
---|
| 281 | c++; |
---|
| 282 | if (*c != '"') putchar('\\'); |
---|
| 283 | } |
---|
| 284 | else |
---|
| 285 | c++; |
---|
[460c1e1] | 286 | } |
---|
| 287 | printf("\";\n"); |
---|
| 288 | } |
---|
[5ecf042] | 289 | else if (!category_out) |
---|
[f36635] | 290 | printf("Version:%s;\n", libnamebuf); |
---|
[d40d574] | 291 | #else |
---|
[c232af] | 292 | if (text_buffer!=NULL) omFree((ADDRESS)text_buffer); |
---|
| 293 | text_buffer = omStrDup(libnamebuf); |
---|
[50cbdc] | 294 | omMarkAsStaticAddr(text_buffer); |
---|
[d40d574] | 295 | #endif |
---|
[5480da] | 296 | } |
---|
| 297 | } |
---|
| 298 | |
---|
[c2da0a] | 299 | static { p_static=TRUE; } |
---|
[33d539] | 300 | |
---|
| 301 | (proc[ \t]+{name})|([ \t]proc[ \t]+{name}) { |
---|
[5480da] | 302 | char proc[256]; |
---|
| 303 | BEGIN(pdef); |
---|
[d2b2a7] | 304 | found_proc_in_proc = 0; |
---|
[799ce1] | 305 | proc[0]='\0'; |
---|
| 306 | sscanf( yytext, "%*[^p]proc %s", proc); |
---|
| 307 | if(strlen(proc)<1) sscanf( yytext, "proc %s", proc); |
---|
[d40d574] | 308 | #if YYLPDEBUG > 1 |
---|
[5480da] | 309 | printf("Newlib:%s\n", newlib); |
---|
[d40d574] | 310 | #endif |
---|
| 311 | #ifdef STANDALONE_PARSER |
---|
| 312 | if ( pi != NULL ) |
---|
| 313 | { |
---|
| 314 | printpi(pi); |
---|
| 315 | pi_clear(pi); |
---|
| 316 | } |
---|
| 317 | pi = (procinfo *)malloc(sizeof(procinfo)); |
---|
| 318 | iiInitSingularProcinfo(pi, newlib, proc, yylplineno, |
---|
| 319 | current_pos(0), p_static); |
---|
[af68ef] | 320 | #else /*STANDALONE_PARSER*/ |
---|
[befd6b5] | 321 | if( mode == LOAD_LIB) |
---|
| 322 | { |
---|
[3b1a83c] | 323 | h0 = enterid( proc, 0 /*myynest*/, PROC_CMD, |
---|
[a53ae5] | 324 | &(IDPACKAGE(pl)->idroot), TRUE, !p_static); |
---|
[d3f95ab] | 325 | if (h0==NULL) return(1); |
---|
[22ed4c] | 326 | if((!p_static) && autoexport) |
---|
[a3bc95e] | 327 | { |
---|
[c0d3e8e] | 328 | package save=currPack; |
---|
| 329 | currPack=basePack; |
---|
[3b1a83c] | 330 | h_top = enterid( proc, 0 /*myynest*/, PROC_CMD, |
---|
[a3bc95e] | 331 | &(basePack->idroot), FALSE ); |
---|
[c0d3e8e] | 332 | currPack=save; |
---|
[d3f95ab] | 333 | if (h_top==NULL) return(1); |
---|
[a3bc95e] | 334 | } |
---|
[50cbdc] | 335 | /* omCheckAddr(IDID(h0)); */ |
---|
[befd6b5] | 336 | if (h0!=NULL) |
---|
| 337 | { |
---|
[56459d] | 338 | iiInitSingularProcinfo(IDPROC(h0), newlib, proc, |
---|
[df595d] | 339 | yylplineno, current_pos(0),p_static); |
---|
[22ed4c] | 340 | if ((!p_static) && (h_top != NULL) && autoexport) |
---|
[a3bc95e] | 341 | { |
---|
| 342 | if(IDPROC(h_top)!=NULL) piCleanUp((procinfo *)IDPROC(h_top)); |
---|
| 343 | IDPROC(h_top)=IDPROC(h0); |
---|
| 344 | IDPROC(h_top)->ref++; |
---|
| 345 | } |
---|
[3b1a83c] | 346 | IDPROC(h0)->pack=IDPACKAGE(pl); |
---|
[5480da] | 347 | if (BVERBOSE(V_LOAD_PROC)) |
---|
[97f92a] | 348 | Warn( " proc '%s' registered", proc ); |
---|
[5480da] | 349 | } |
---|
[af68ef] | 350 | #endif /*STANDALONE_PARSER*/ |
---|
[5480da] | 351 | SET_DEF_END(mode, pi, current_pos(yyleng+1)); |
---|
[d40d574] | 352 | #if YYLPDEBUG |
---|
[befd6b5] | 353 | if(lpverbose) |
---|
| 354 | { |
---|
[029516e] | 355 | printf("// PROCEDURE '%s' status: %s, ", proc, |
---|
| 356 | p_static ? "local" : "global"); |
---|
[befd6b5] | 357 | printf("starting at line %d,%d: definition end: %d (%d).\n", |
---|
[cc486c] | 358 | yylplineno, current_pos(0), (int)pi->data.s.def_end, brace1); |
---|
[029516e] | 359 | } |
---|
[d40d574] | 360 | #endif |
---|
[c2da0a] | 361 | p_static=FALSE; |
---|
[d40d574] | 362 | #ifndef STANDALONE_PARSER |
---|
[5480da] | 363 | } |
---|
[af68ef] | 364 | #endif /*STANDALONE_PARSER*/ |
---|
[5480da] | 365 | } |
---|
| 366 | example { |
---|
| 367 | BEGIN(pexample); |
---|
| 368 | SET_EXAMPLE_START(mode, pi, yylplineno, current_pos(0)); |
---|
[d40d574] | 369 | #if YYLPDEBUG |
---|
[799ce1] | 370 | if(lpverbose) |
---|
[befd6b5] | 371 | { |
---|
[799ce1] | 372 | printf("// EXAMPLE at line %d,%d (%d)\n", yylplineno, |
---|
[df595d] | 373 | current_pos(0), brace1); |
---|
[befd6b5] | 374 | } |
---|
[d40d574] | 375 | #endif |
---|
[5480da] | 376 | } |
---|
[33d539] | 377 | |
---|
[5480da] | 378 | LIB[ \t]+"\"" { quote++; |
---|
| 379 | BEGIN(libcmd); |
---|
| 380 | } |
---|
[33d539] | 381 | |
---|
[14b6448] | 382 | LIB[ \t]*"(\"" { quote++; brace2++; |
---|
| 383 | BEGIN(libcmd2); |
---|
| 384 | } |
---|
| 385 | |
---|
[5480da] | 386 | <header>({comment}+{tos}+{dolar}+Id:+{string}+[^\n]*)|({comment}+{tos}+{dolar}+Header:+{string}+[^\n]*) { |
---|
[df595d] | 387 | make_version(yytext, 0); |
---|
[d40d574] | 388 | #if YYLPDEBUG > 1 |
---|
[d336d53] | 389 | printf("+(id)HEAD:%s\n", yytext); |
---|
[d40d574] | 390 | #endif |
---|
[5480da] | 391 | } |
---|
[df595d] | 392 | <header>(^{comment}+[^\n]*) { |
---|
[d40d574] | 393 | #if YYLPDEBUG |
---|
[d336d53] | 394 | printf("+(cmt)HEAD:%s\n", yytext); |
---|
[d40d574] | 395 | #endif |
---|
[5480da] | 396 | } |
---|
[df595d] | 397 | <header>(^#![^\n]*) { |
---|
[d40d574] | 398 | #if YYLPDEBUG > 1 |
---|
[5480da] | 399 | printf("-HEAD:%s\n", yytext); |
---|
[d40d574] | 400 | #endif |
---|
[5480da] | 401 | } |
---|
| 402 | <header>^proc\ { yyless(0); |
---|
| 403 | BEGIN(INITIAL); |
---|
| 404 | yymore(); |
---|
| 405 | } |
---|
[7035b2] | 406 | <header>(info+{eqnl}+{quote})|(version+{eqnl}+{quote})|(category+{eqnl}+{quote})|(url+{eqnl}+{quote}) { |
---|
[36741d] | 407 | yyless(0); |
---|
[5480da] | 408 | *lib_style = NEW_LIBSTYLE; |
---|
| 409 | BEGIN(INITIAL); |
---|
| 410 | yymore(); |
---|
| 411 | } |
---|
| 412 | |
---|
[33d539] | 413 | <header>^LIB[ \t]+"\"" { quote++; |
---|
[5480da] | 414 | BEGIN(libcmd); |
---|
| 415 | } |
---|
[14b6448] | 416 | <header>^LIB[ \t]+"(\"" { quote++; brace2++; |
---|
| 417 | BEGIN(libcmd2); |
---|
| 418 | } |
---|
[5480da] | 419 | <header>\n { yylplineno++; } |
---|
[df595d] | 420 | <header>. { |
---|
[d40d574] | 421 | #if YYLPDEBUG > 1 |
---|
[5480da] | 422 | printf(" HEAD:%s\n", yytext); |
---|
[d40d574] | 423 | #endif |
---|
[d2b2a7] | 424 | yyless(0); |
---|
[5480da] | 425 | BEGIN(help); |
---|
| 426 | } |
---|
[df595d] | 427 | <help>(^{comment}+[^\n]*) { |
---|
[d40d574] | 428 | #if YYLPDEBUG > 1 |
---|
[5480da] | 429 | printf(" HELP:%s\n", yytext); |
---|
[d40d574] | 430 | #endif |
---|
[5480da] | 431 | BEGIN(INITIAL); } |
---|
[df595d] | 432 | <help>(^#![^\n]*) { |
---|
[d40d574] | 433 | #if YYLPDEBUG > 1 |
---|
[5480da] | 434 | printf(" HELP:%s\n", yytext); |
---|
[d40d574] | 435 | #endif |
---|
[5480da] | 436 | BEGIN(INITIAL); |
---|
| 437 | } |
---|
[7035b2] | 438 | <help>(info+{eqnl}+{quote})|(version+{eqnl}+{quote})|(category+{eqnl}+{quote})|(url+{eqnl}+{quote}) { |
---|
[36741d] | 439 | yyless(0); |
---|
[d336d53] | 440 | *lib_style = NEW_LIBSTYLE; |
---|
| 441 | BEGIN(INITIAL); |
---|
| 442 | yymore(); |
---|
| 443 | } |
---|
[5480da] | 444 | <help>^proc\ { |
---|
| 445 | yyless(0); |
---|
| 446 | //printf("2) proc found.\n"); |
---|
| 447 | BEGIN(INITIAL); |
---|
| 448 | yymore(); |
---|
| 449 | } |
---|
[33d539] | 450 | <help>^LIB[ \t]+"\"" { quote++; |
---|
[5480da] | 451 | BEGIN(libcmd); |
---|
| 452 | } |
---|
[14b6448] | 453 | <help>^LIB[ \t]+"(\"" { quote++; brace2++; |
---|
| 454 | BEGIN(libcmd2); |
---|
| 455 | } |
---|
[33d539] | 456 | |
---|
[d336d53] | 457 | <help>\n { yylplineno++; } |
---|
[befd6b5] | 458 | <help>({tos}|{comment}+{fstring}) { |
---|
[d40d574] | 459 | #if YYLPDEBUG |
---|
[d2b2a7] | 460 | if(lpverbose>2) printf("--->%s<---\n", yytext); |
---|
[d40d574] | 461 | #endif |
---|
[d2b2a7] | 462 | } |
---|
[df595d] | 463 | <help>. { |
---|
[d2b2a7] | 464 | found_oldhelp=1; |
---|
[d40d574] | 465 | #if YYLPDEBUG > 1 |
---|
[5480da] | 466 | printf("-HELP:%s\n", yytext); |
---|
[d40d574] | 467 | #endif |
---|
[5480da] | 468 | } |
---|
[33d539] | 469 | |
---|
| 470 | |
---|
| 471 | <libcmd>{string}"\"" { quote--; |
---|
[5480da] | 472 | yytext[yyleng-1] = '\0'; |
---|
[d40d574] | 473 | #ifndef STANDALONE_PARSER |
---|
| 474 | if ( mode == LOAD_LIB ) |
---|
| 475 | { |
---|
| 476 | library_stack->push(newlib, yytext); |
---|
| 477 | } |
---|
| 478 | #endif /* STANDALONE_PARSER */ |
---|
| 479 | #if YYLPDEBUG |
---|
[d2b2a7] | 480 | if(lpverbose>1) printf("LIB:'%s'\n", yytext); |
---|
[d40d574] | 481 | #endif |
---|
[5480da] | 482 | BEGIN(INITIAL); |
---|
| 483 | } |
---|
[14b6448] | 484 | <libcmd2>{string}"\")" { quote--; brace2--; |
---|
| 485 | yytext[yyleng-1] = '\0'; |
---|
| 486 | #ifndef STANDALONE_PARSER |
---|
| 487 | if ( mode == LOAD_LIB ) |
---|
| 488 | { |
---|
| 489 | library_stack->push(newlib, yytext); |
---|
| 490 | } |
---|
| 491 | #endif /* STANDALONE_PARSER */ |
---|
| 492 | #if YYLPDEBUG |
---|
| 493 | if(lpverbose>1) printf("LIB:'%s'\n", yytext); |
---|
| 494 | #endif |
---|
| 495 | BEGIN(INITIAL); |
---|
| 496 | } |
---|
[33d539] | 497 | |
---|
[5480da] | 498 | <pdef>[ \t] { } |
---|
[df595d] | 499 | <pdef>\( { |
---|
[5480da] | 500 | brace2++; |
---|
[d40d574] | 501 | #if YYLPDEBUG > 1 |
---|
[5480da] | 502 | printf("%s", yytext); |
---|
[d40d574] | 503 | #endif |
---|
[5480da] | 504 | } |
---|
[df595d] | 505 | <pdef>\) { |
---|
[5480da] | 506 | brace2--; |
---|
[d40d574] | 507 | #if YYLPDEBUG > 1 |
---|
[5480da] | 508 | printf(">%s<\n", yytext); |
---|
| 509 | printf("{=%d, (=%d, [=%d\n", brace1, brace2, brace3); |
---|
[d40d574] | 510 | #endif |
---|
[befd6b5] | 511 | if(brace2<=0) |
---|
| 512 | { |
---|
[d40d574] | 513 | #if YYLPDEBUG > 1 |
---|
[5480da] | 514 | printf("BEGIN(phead){=%d, (=%d, [=%d\n", brace1, brace2, brace3); |
---|
[d40d574] | 515 | #endif |
---|
[5480da] | 516 | SET_DEF_END(mode, pi, current_pos(yyleng)); |
---|
| 517 | BEGIN(phead); |
---|
| 518 | } |
---|
| 519 | } |
---|
[df595d] | 520 | <pdef>"{" { |
---|
[befd6b5] | 521 | if(brace2>0) |
---|
| 522 | { |
---|
[d40d574] | 523 | #if YYLPDEBUG > 1 |
---|
[5480da] | 524 | printf("{=%d, (=%d, [=%d\n", brace1, brace2, brace3); |
---|
[d40d574] | 525 | #endif |
---|
[5480da] | 526 | yylp_errno = YYLP_DEF_BR2; |
---|
| 527 | return(1); |
---|
[befd6b5] | 528 | } |
---|
| 529 | else |
---|
| 530 | { |
---|
[5480da] | 531 | brace1++; BEGIN(pbody); |
---|
[799ce1] | 532 | if(lpverbose) |
---|
| 533 | printf("// BODY at line %d,%d (%d)\n", yylplineno, |
---|
| 534 | current_pos(0), brace1); |
---|
[5480da] | 535 | SET_BODY_START(mode, pi, yylplineno, current_pos(0)); |
---|
| 536 | } |
---|
| 537 | } |
---|
[d336d53] | 538 | <pdef>\n { yylplineno++; |
---|
[befd6b5] | 539 | if(brace2<=0) |
---|
| 540 | { |
---|
[d2b2a7] | 541 | #if YYLPDEBUG > 1 |
---|
[d336d53] | 542 | printf("BEGIN(phead-2){=%d, (=%d, [=%d\n", brace1, brace2, brace3); |
---|
[33d539] | 543 | #endif |
---|
[d336d53] | 544 | BEGIN(phead); |
---|
| 545 | } |
---|
| 546 | } |
---|
[7fd611] | 547 | <pdef>({comment}[^\n]*) { } |
---|
| 548 | <pdef>\/\/* { old_state = YYSTATE; BEGIN(comment); } |
---|
[df595d] | 549 | <pdef>. { |
---|
[befd6b5] | 550 | if(brace2<=0) |
---|
| 551 | { |
---|
[5480da] | 552 | BEGIN(phead); |
---|
[d2b2a7] | 553 | yyless(0); |
---|
[5480da] | 554 | } |
---|
| 555 | } |
---|
[33d539] | 556 | |
---|
[d2b2a7] | 557 | <phead>({tnl}+{quote}+{strings}+{escquote}+{tnl}+"{") { |
---|
[d40d574] | 558 | #if YYLPDEBUG |
---|
[d2b2a7] | 559 | if(lpverbose>2)printf("0-Len=%d;\n", yyleng); |
---|
[d40d574] | 560 | #endif |
---|
[befd6b5] | 561 | if(check) |
---|
| 562 | { |
---|
[d2b2a7] | 563 | printf("Procedure %s (line %d) has OLD-STYLE-HELP!\n", |
---|
| 564 | pi->procname, pi->data.s.proc_lineno); |
---|
| 565 | } |
---|
| 566 | SET_HELP_START(mode, pi, current_pos(0)); |
---|
[befd6b5] | 567 | BEGIN(poldhelp); |
---|
[d2b2a7] | 568 | yyless(0); |
---|
| 569 | } |
---|
| 570 | <phead>({tnl}+{quote}+{strings}+{eos}) { |
---|
[d40d574] | 571 | #if YYLPDEBUG |
---|
[d2b2a7] | 572 | if(lpverbose>2)printf("1-Len=%d;\n", yyleng); |
---|
[d40d574] | 573 | #endif |
---|
[d2b2a7] | 574 | BEGIN(phelp); |
---|
| 575 | yyless(0); |
---|
| 576 | } |
---|
| 577 | <phead>{escstrings}+"{" { |
---|
[befd6b5] | 578 | if(check && yyleng>2) |
---|
| 579 | { |
---|
[d2b2a7] | 580 | printf("Procedure %s (line %d) has OLD-STYLE-HELP!\n", |
---|
| 581 | pi->procname, pi->data.s.proc_lineno); |
---|
| 582 | } |
---|
[d40d574] | 583 | #if YYLPDEBUG |
---|
[befd6b5] | 584 | if(lpverbose>2 && yyleng>2) |
---|
[d2b2a7] | 585 | printf("2-Len=%d, %s;\n", yyleng, pi->procname); |
---|
[d40d574] | 586 | #endif |
---|
[d2b2a7] | 587 | SET_HELP_START(mode, pi, current_pos(0)); |
---|
| 588 | BEGIN(poldhelp); |
---|
| 589 | yyless(0); |
---|
| 590 | } |
---|
| 591 | <phead>. { printf("[%s]", yytext); } |
---|
| 592 | |
---|
| 593 | <poldhelp>{escbrack} { } |
---|
| 594 | <poldhelp>"{" { |
---|
[6be769] | 595 | SET_HELP_END(mode, pi, current_pos(0)); |
---|
[d2b2a7] | 596 | brace1++; BEGIN(pbody); |
---|
[befd6b5] | 597 | if(lpverbose) |
---|
| 598 | { |
---|
| 599 | printf("// HELP from %d to %d\n", |
---|
[cc486c] | 600 | (int)pi->data.s.help_start, (int)pi->data.s.help_end); |
---|
[799ce1] | 601 | printf("// BODY at line %d,%d (%d)\n", yylplineno, |
---|
| 602 | current_pos(0), brace1); |
---|
[6be769] | 603 | } |
---|
[d2b2a7] | 604 | #if YYLPDEBUG > 1 |
---|
| 605 | printf("BEGIN(pbody){=%d, (=%d, [=%d\n", brace1, brace2, brace3); |
---|
| 606 | #endif |
---|
| 607 | SET_BODY_START(mode, pi, yylplineno, current_pos(0)); |
---|
| 608 | #if YYLPDEBUG > 1 |
---|
| 609 | printf("BODY at %d/%d", yylplineno, current_pos(0)); |
---|
| 610 | #endif |
---|
| 611 | } |
---|
| 612 | <poldhelp>\n { yylplineno++; } |
---|
| 613 | <poldhelp>. { } |
---|
| 614 | |
---|
| 615 | <phelp>{quote} { |
---|
| 616 | old_state = YYSTATE; |
---|
| 617 | BEGIN(string); |
---|
| 618 | SET_HELP_START(mode, pi, current_pos(1)); |
---|
| 619 | } |
---|
| 620 | <phelp>{tos} {} |
---|
| 621 | <phelp>"{" { |
---|
| 622 | brace1++; BEGIN(pbody); |
---|
[befd6b5] | 623 | if(lpverbose) |
---|
| 624 | { |
---|
| 625 | printf("// HELP from %d to %d\n", |
---|
[cc486c] | 626 | (int)pi->data.s.help_start, (int)pi->data.s.help_end); |
---|
[799ce1] | 627 | printf("// BODY at line %d,%d (%d)\n", yylplineno, |
---|
| 628 | current_pos(0), brace1); |
---|
[6be769] | 629 | } |
---|
[d40d574] | 630 | #if YYLPDEBUG > 1 |
---|
[d2b2a7] | 631 | printf("BEGIN(pbody){=%d, (=%d, [=%d\n", brace1, brace2, brace3); |
---|
[d40d574] | 632 | #endif |
---|
[d2b2a7] | 633 | SET_BODY_START(mode, pi, yylplineno, current_pos(0)); |
---|
[d40d574] | 634 | #if YYLPDEBUG > 1 |
---|
[d2b2a7] | 635 | printf("BODY at %d/%d", yylplineno, current_pos(0)); |
---|
[d40d574] | 636 | #endif |
---|
[d2b2a7] | 637 | } |
---|
[f92cf8] | 638 | <phelp>\n { yylplineno++;} |
---|
[33d539] | 639 | |
---|
[d336d53] | 640 | <pbody>({comment}[^\n]*) { } |
---|
[d2b2a7] | 641 | <pbody>{quote} { quote++; old_state = YYSTATE; |
---|
| 642 | BEGIN(string); /* printf("%s", yytext); */ |
---|
| 643 | } |
---|
| 644 | |
---|
[befd6b5] | 645 | <pbody>proc+{tos}+{name}+{tnl}+{paramlist}+{tnl}+"{" { |
---|
[d2b2a7] | 646 | if(check) printf("*** found 2 proc whithin procedure '%s'.\n", |
---|
| 647 | pi->procname); |
---|
| 648 | yyless(yyleng-1); |
---|
| 649 | } |
---|
[befd6b5] | 650 | <pbody>proc+{tos}+{name}+{tnl}+"{" { |
---|
[d2b2a7] | 651 | if(check) printf("*** found 1 proc whithin procedure '%s'.\n", |
---|
| 652 | pi->procname); |
---|
| 653 | yyless(yyleng-1); |
---|
| 654 | } |
---|
| 655 | <pbody>"{" { |
---|
| 656 | brace1++; |
---|
[d40d574] | 657 | #if YYLPDEBUG > 1 |
---|
[d2b2a7] | 658 | printf("line: %d, (%d)%s\n", yylplineno, brace1, yytext); |
---|
[d40d574] | 659 | #endif |
---|
[d2b2a7] | 660 | } |
---|
[df595d] | 661 | <pbody>"}" { |
---|
[d40d574] | 662 | #if YYLPDEBUG > 1 |
---|
| 663 | printf("line: %d, (%d)%s\n", |
---|
| 664 | yylplineno, brace1, yytext); |
---|
| 665 | #endif |
---|
[33d539] | 666 | brace1--; |
---|
[befd6b5] | 667 | if(brace2>0) |
---|
| 668 | { |
---|
[33d539] | 669 | yylp_errno = YYLP_BODY_BR2; |
---|
| 670 | return(1); |
---|
| 671 | } |
---|
[befd6b5] | 672 | if(brace3>0) |
---|
| 673 | { |
---|
[33d539] | 674 | yylp_errno = YYLP_BODY_BR3; |
---|
| 675 | return(1); |
---|
| 676 | } |
---|
[befd6b5] | 677 | if(brace1<=0) |
---|
| 678 | { |
---|
[5480da] | 679 | SET_BODY_END(mode, pi, current_pos(yyleng)); |
---|
| 680 | SET_PROC_END(mode, pi, current_pos(yyleng)); |
---|
[d40d574] | 681 | #if YYLPDEBUG > 1 |
---|
| 682 | printf("-%d\n", current_pos(0)); |
---|
| 683 | #endif |
---|
[33d539] | 684 | BEGIN(INITIAL); |
---|
| 685 | } |
---|
| 686 | } |
---|
[df595d] | 687 | <pbody>"(" { |
---|
[33d539] | 688 | brace2++; /* printf("%s", yytext); */ |
---|
| 689 | } |
---|
[df595d] | 690 | <pbody>")" { |
---|
[33d539] | 691 | brace2--; /* printf("%s", yytext); */ |
---|
[df595d] | 692 | if(brace2<0) { |
---|
[33d539] | 693 | yylp_errno = YYLP_BODY_TMBR2; |
---|
| 694 | return(1); |
---|
| 695 | } |
---|
| 696 | } |
---|
[df595d] | 697 | <pbody>"[" { |
---|
[33d539] | 698 | brace3++; /* printf("%s", yytext); */ |
---|
| 699 | } |
---|
[df595d] | 700 | <pbody>"]" { |
---|
[33d539] | 701 | brace3--; /* printf("%s", yytext); */ |
---|
| 702 | if(brace3<0) { |
---|
| 703 | yylp_errno = YYLP_BODY_TMBR3; |
---|
| 704 | return(1); |
---|
| 705 | } |
---|
| 706 | } |
---|
| 707 | <pbody>\n { yylplineno++; } |
---|
| 708 | <pbody>. { } |
---|
| 709 | |
---|
[60a3add] | 710 | <info>{quote} { |
---|
| 711 | quote++; BEGIN(string); |
---|
| 712 | found_info++; |
---|
| 713 | string_start = current_pos(yyleng); |
---|
| 714 | *lib_style = NEW_LIBSTYLE; |
---|
| 715 | last_cmd = LP_INFO; |
---|
| 716 | } |
---|
| 717 | <info>\n { yylplineno++; } |
---|
| 718 | <info>. { } |
---|
| 719 | |
---|
[14b6448] | 720 | <category>{quote} { |
---|
| 721 | quote++; BEGIN(string); |
---|
| 722 | found_cat++; |
---|
| 723 | string_start = current_pos(yyleng); |
---|
| 724 | *lib_style = NEW_LIBSTYLE; |
---|
| 725 | last_cmd = LP_CATEGORY; |
---|
| 726 | } |
---|
| 727 | <category>\n { yylplineno++; } |
---|
| 728 | <category>. { } |
---|
| 729 | |
---|
[7035b2] | 730 | |
---|
[33d539] | 731 | <string>"\"" { quote--; |
---|
[ad0463] | 732 | copy_string(mode); |
---|
[5480da] | 733 | last_cmd = LP_NONE; |
---|
[6be769] | 734 | if(old_state==phelp) |
---|
[d40d574] | 735 | { |
---|
[6be769] | 736 | SET_HELP_END(mode, pi, current_pos(0)); |
---|
[f92cf8] | 737 | } |
---|
[33d539] | 738 | BEGIN(old_state); /* printf("%s", yytext); */ |
---|
| 739 | } |
---|
[f92cf8] | 740 | <string>(\\\\)|(\\\") { if (old_state == phelp) IncrCheckSum(*yytext);} |
---|
| 741 | <string>\n { yylplineno++; if (old_state == phelp) IncrCheckSum('\n');} |
---|
| 742 | <string>. { if (old_state == phelp) IncrCheckSum(*yytext);} |
---|
[33d539] | 743 | |
---|
[d336d53] | 744 | <pexample>(\/\/[^\n]*) { } |
---|
[33d539] | 745 | <pexample>"\"" { quote++; old_state = YYSTATE; |
---|
| 746 | BEGIN(string); /* printf("%s", yytext); */ |
---|
| 747 | } |
---|
[df595d] | 748 | <pexample>"{" { |
---|
[33d539] | 749 | brace1++; /* printf("(%d)%s", brace1, yytext); */ |
---|
| 750 | } |
---|
[df595d] | 751 | <pexample>"}" { |
---|
[33d539] | 752 | brace1--; /* printf("(%d)%s", brace1, yytext); */ |
---|
| 753 | if(brace1<=0) { |
---|
| 754 | if(brace2>0) { yylp_errno=YYLP_EX_BR2; return(1); } |
---|
| 755 | if(brace3>0) { yylp_errno=YYLP_EX_BR3; return(1); } |
---|
| 756 | BEGIN(INITIAL); |
---|
[5480da] | 757 | SET_PROC_END(mode, pi, current_pos(yyleng)); |
---|
[33d539] | 758 | } |
---|
| 759 | } |
---|
[df595d] | 760 | <pexample>"(" { |
---|
[33d539] | 761 | brace2++; /* printf("%s", yytext); */ |
---|
| 762 | } |
---|
[df595d] | 763 | <pexample>")" { |
---|
[33d539] | 764 | brace2--; /* printf("%s", yytext); */ |
---|
| 765 | } |
---|
[df595d] | 766 | <pexample>"[" { |
---|
[33d539] | 767 | brace3++; /* printf("%s", yytext); */ |
---|
| 768 | } |
---|
[df595d] | 769 | <pexample>"]" { |
---|
[33d539] | 770 | brace3--; /* printf("%s", yytext); */ |
---|
| 771 | } |
---|
| 772 | <pexample>\n { yylplineno++; } |
---|
| 773 | <pexample>. { } |
---|
| 774 | |
---|
| 775 | <pestr>"\"" { quote--; |
---|
| 776 | BEGIN(pexample); /* printf("%s", yytext); */ |
---|
| 777 | } |
---|
| 778 | <pestr>\\\\ { } |
---|
| 779 | <pestr>\\\" { } |
---|
| 780 | <pestr>\n { yylplineno++; } |
---|
| 781 | <pestr>. { } |
---|
| 782 | |
---|
| 783 | <comment>\*\/ { BEGIN(old_state); } |
---|
| 784 | <comment>\n { yylplineno++; } |
---|
| 785 | <comment>. { } |
---|
| 786 | |
---|
| 787 | \n { yylplineno++; } |
---|
[a76420] | 788 | \r { } |
---|
[c2da0a] | 789 | ; { p_static = FALSE; |
---|
[d40d574] | 790 | #if YYLPDEBUG > 1 |
---|
[33d539] | 791 | printf("%s", yytext); |
---|
[d40d574] | 792 | #endif |
---|
[33d539] | 793 | } |
---|
[df595d] | 794 | . { p_static = FALSE; |
---|
[33d539] | 795 | yylp_errno = YYLP_BAD_CHAR; |
---|
[d40d574] | 796 | #ifdef STANDALONE_PARSER |
---|
[df595d] | 797 | printf("[%d]", *yytext); |
---|
[d40d574] | 798 | #else |
---|
[c232af] | 799 | if (text_buffer!=NULL) omFree((ADDRESS)text_buffer); |
---|
| 800 | text_buffer = omStrDup(yytext); |
---|
[ec7aac] | 801 | omMarkAsStaticAddr(text_buffer); |
---|
[d40d574] | 802 | #endif |
---|
| 803 | #if YYLPDEBUG > 1 |
---|
| 804 | printf("[%s]", yytext); |
---|
| 805 | #endif |
---|
[33d539] | 806 | return(1); |
---|
| 807 | } |
---|
| 808 | |
---|
| 809 | %% |
---|
| 810 | |
---|
| 811 | int current_pos(int i) |
---|
| 812 | { |
---|
| 813 | return(i+offset+(int)(yytext-yylp_buffer_start)); |
---|
| 814 | } |
---|
| 815 | |
---|
| 816 | int libread(FILE* f, char* buf, int max_size) |
---|
| 817 | { int rc; |
---|
| 818 | |
---|
| 819 | offset = ftell(f); |
---|
[d5f35ac] | 820 | rc = myfread( buf, 1, max_size, f ); |
---|
[d40d574] | 821 | #if YYLPDEBUG >2 |
---|
| 822 | printf("fread: %d of %d\n", rc, max_size); |
---|
| 823 | #endif |
---|
[33d539] | 824 | yylp_buffer_start = buf; |
---|
| 825 | return rc; |
---|
| 826 | } |
---|
| 827 | |
---|
| 828 | extern "C" { |
---|
[befd6b5] | 829 | int yylpwrap() |
---|
| 830 | { |
---|
[33d539] | 831 | //printf("======================= YYWRAP ====================\n"); |
---|
| 832 | if(brace1>0) { yylp_errno=YYLP_MISS_BR1; } |
---|
| 833 | if(brace2>0) { yylp_errno=YYLP_MISS_BR2; } |
---|
| 834 | if(brace3>0) { yylp_errno=YYLP_MISS_BR3; } |
---|
| 835 | if(quote>0) { yylp_errno=YYLP_MISSQUOT; } |
---|
| 836 | /* printf("{=%d, (=%d, [=%d\n", brace1, brace2, brace3);/**/ |
---|
| 837 | if(feof(yyin)) return 1; else return 0; |
---|
| 838 | } |
---|
| 839 | } |
---|
| 840 | |
---|
| 841 | void reinit_yylp() |
---|
| 842 | { |
---|
| 843 | brace1 = 0; |
---|
| 844 | brace2 = 0; |
---|
| 845 | brace3 = 0; |
---|
| 846 | quote = 0; |
---|
| 847 | yy_init=1; |
---|
[b1dfaf] | 848 | yy_delete_buffer(YY_CURRENT_BUFFER); |
---|
[33d539] | 849 | } |
---|
| 850 | |
---|
[5480da] | 851 | void make_version(char *p,int what) |
---|
| 852 | { |
---|
| 853 | char ver[10]; |
---|
| 854 | char date[16]; |
---|
| 855 | ver[0]='?'; ver[1]='.'; ver[2]='?'; ver[3]='\0'; |
---|
| 856 | date[0]='?'; date[1]='\0'; |
---|
| 857 | if(what) sscanf(p,"%*[^=]= %*s %*s %10s %16s",ver,date); |
---|
| 858 | else sscanf(p,"// %*s %*s %10s %16s",ver,date); |
---|
| 859 | strcpy(libnamebuf,"("); |
---|
| 860 | strcat(libnamebuf,ver); |
---|
| 861 | strcat(libnamebuf,","); |
---|
| 862 | strcat(libnamebuf,date); |
---|
| 863 | strcat(libnamebuf,")"); |
---|
[befd6b5] | 864 | if(what && strcmp(libnamebuf, "(?.?,?)")==0) |
---|
| 865 | { |
---|
[d2b2a7] | 866 | sscanf(p,"%*[^\"]\"%[^\"]\"",libnamebuf); |
---|
| 867 | } |
---|
| 868 | //printf("ID=(%d)%s; \n", what, p); |
---|
[5480da] | 869 | } |
---|
| 870 | |
---|
| 871 | void copy_string(lp_modes mode) |
---|
| 872 | { |
---|
[f36635] | 873 | #ifdef STANDALONE_PARSER |
---|
[7035b2] | 874 | if ((texinfo_out |
---|
| 875 | && (last_cmd == LP_INFO || last_cmd == LP_CATEGORY || last_cmd == LP_URL)) |
---|
| 876 | || (category_out && last_cmd == LP_CATEGORY) |
---|
| 877 | ) |
---|
[f36635] | 878 | { |
---|
| 879 | long current_location = ftell(yylpin), i = string_start, quote = 0; |
---|
| 880 | char c; |
---|
[5ecf042] | 881 | if (texinfo_out) |
---|
[14b6448] | 882 | { |
---|
[5ecf042] | 883 | if (last_cmd == LP_INFO) |
---|
| 884 | { |
---|
| 885 | printf("$info = <<EOT;\n"); |
---|
| 886 | } |
---|
[7035b2] | 887 | else if (last_cmd == LP_URL) |
---|
| 888 | { |
---|
| 889 | printf("$url = <<EOT;\n"); |
---|
| 890 | } |
---|
[5ecf042] | 891 | else |
---|
| 892 | { |
---|
| 893 | printf("$category = <<EOT;\n"); |
---|
| 894 | } |
---|
[14b6448] | 895 | } |
---|
[f36635] | 896 | fseek (yylpin, i, SEEK_SET); |
---|
[d40d574] | 897 | while (i< current_location) |
---|
| 898 | { |
---|
[f36635] | 899 | c = fgetc(yylpin); |
---|
[d40d574] | 900 | if (c == '\\') |
---|
[f36635] | 901 | { |
---|
| 902 | quote = (! quote); |
---|
| 903 | } |
---|
| 904 | else if (c == '"') |
---|
| 905 | { |
---|
| 906 | if (! quote) break; |
---|
| 907 | } |
---|
| 908 | else |
---|
| 909 | quote = 0; |
---|
| 910 | if (c == '@' || c == '$') putchar('\\'); |
---|
| 911 | if (c != '\r') putchar(c); |
---|
| 912 | i++; |
---|
| 913 | } |
---|
[5ecf042] | 914 | if (category_out) exit(0); |
---|
[f36635] | 915 | fseek (yylpin, current_location, SEEK_SET); |
---|
| 916 | printf("\nEOT\n"); |
---|
| 917 | } |
---|
| 918 | #else |
---|
[df595d] | 919 | if((last_cmd == LP_INFO)&&(mode == GET_INFO)) |
---|
| 920 | { |
---|
[7fd611] | 921 | int i, offset=0; |
---|
[5480da] | 922 | long current_location = ftell(yylpin); |
---|
| 923 | int len = (int)(current_pos(0) - string_start); |
---|
| 924 | fseek(yylpin, string_start, SEEK_SET); |
---|
[c232af] | 925 | if (text_buffer!=NULL) omFree((ADDRESS)text_buffer); |
---|
| 926 | text_buffer = (char *)omAlloc(len+2); |
---|
[ec7aac] | 927 | omMarkAsStaticAddr(text_buffer); |
---|
[d5f35ac] | 928 | myfread(text_buffer, len, 1, yylpin); |
---|
[5480da] | 929 | fseek(yylpin, current_location, SEEK_SET); |
---|
[8597cf] | 930 | text_buffer[len]='\0'; |
---|
[7fd611] | 931 | offset=0; |
---|
[befd6b5] | 932 | for(i=0;i<=len; i++) |
---|
| 933 | { |
---|
[7fd611] | 934 | if(text_buffer[i]=='\\' && |
---|
[46d09b] | 935 | (text_buffer[i+1]=='\"' || text_buffer[i+1]=='{' || |
---|
[befd6b5] | 936 | text_buffer[i+1]=='}' || text_buffer[i+1]=='\\')) |
---|
| 937 | { |
---|
[7fd611] | 938 | i++; |
---|
| 939 | offset++; |
---|
| 940 | } |
---|
| 941 | if(offset>0) text_buffer[i-offset] = text_buffer[i]; |
---|
| 942 | } |
---|
[5480da] | 943 | } |
---|
[f36635] | 944 | #endif /* STANDALONE_PARSER */ |
---|
[5480da] | 945 | } |
---|
| 946 | |
---|
[33d539] | 947 | void print_init() |
---|
| 948 | { |
---|
| 949 | printf("Init=%d\n", yy_init); |
---|
| 950 | } |
---|
| 951 | |
---|
[5480da] | 952 | void print_version(lp_modes mode, char *p) |
---|
[33d539] | 953 | { |
---|
[d40d574] | 954 | #ifdef STANDALONE_PARSER |
---|
[5480da] | 955 | //printf("loading %s%s", p, libnamebuf); |
---|
[d40d574] | 956 | #else |
---|
[befd6b5] | 957 | if ( mode == LOAD_LIB ) |
---|
| 958 | { |
---|
[d336d53] | 959 | if (BVERBOSE(V_LOAD_LIB) && p!=NULL ) Print(" %s...", p); |
---|
| 960 | //Warn( "loading %s%s", p, libnamebuf); |
---|
[5480da] | 961 | } |
---|
[d40d574] | 962 | #endif |
---|
[33d539] | 963 | } |
---|
| 964 | |
---|
[d40d574] | 965 | #ifdef STANDALONE_PARSER |
---|
[8836a9] | 966 | int main( int argc, char *argv[] ) |
---|
[33d539] | 967 | { |
---|
[5480da] | 968 | lib_style_types lib_style; |
---|
[d2b2a7] | 969 | main_init(argc, argv); |
---|
[d3e630] | 970 | if(yyin == NULL) |
---|
| 971 | { |
---|
[f36635] | 972 | fprintf(stderr, "No library found to parse.\n"); |
---|
[8836a9] | 973 | return 1; |
---|
[6be769] | 974 | } |
---|
[5ecf042] | 975 | if (! (texinfo_out || category_out)) |
---|
[f36635] | 976 | { |
---|
| 977 | if(lpverbose)printf("Verbose level=%d\n", lpverbose); |
---|
| 978 | if(check)printf("Reporting most possible annomalies.\n"); |
---|
| 979 | if(lpverbose||check)printf("\n"); |
---|
[befd6b5] | 980 | |
---|
[f36635] | 981 | printf( " %-15s %20s %s,%s %s,%s %s,%s\n", "Library", |
---|
| 982 | "function", "line", "start-eod", "line", "body-eob", |
---|
| 983 | "line", "example-eoe"); |
---|
| 984 | } |
---|
[f51b9c] | 985 | yylplex(argv[0], argv[0], &lib_style,NULL); |
---|
[d3e630] | 986 | if(yylp_errno) |
---|
| 987 | { |
---|
[c0971e] | 988 | printf("ERROR occured: [%d] ", yylp_errno); |
---|
[33d539] | 989 | printf(yylp_errlist[yylp_errno], yylplineno); |
---|
| 990 | printf("\n"); |
---|
[df595d] | 991 | } |
---|
[33d539] | 992 | else if(pi!=NULL) printpi(pi); |
---|
[f36635] | 993 | if (texinfo_out) |
---|
| 994 | printf("1;"); |
---|
[8836a9] | 995 | return 0; |
---|
[33d539] | 996 | } |
---|
| 997 | |
---|
[d40d574] | 998 | #endif /* STANDALONE_PARSER */ |
---|
[33d539] | 999 | #endif /* HAVE_LIBPARSE */ |
---|