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