Demonstration of groff .psbb request handling code, for EPS and PDF input files
Revision | 9a532c1800ae4204adf3b0f379ba00b71d4fbf14 (tree) |
---|---|
Zeit | 2021-10-20 07:48:11 |
Autor | ![]() |
Commiter | Keith Marshall |
Extend debugging diagnostics to report popped lexer state.
* psbblex.l (DEBUG_POP_STATE): New macro; define, and use it
as a debug-enabled diagnostic wrapper, in place of...
(yy_pop_state): ...this.
@@ -49,8 +49,15 @@ | ||
49 | 49 | yy_push_state( NAME ); \ |
50 | 50 | } while(0) |
51 | 51 | |
52 | +# define DEBUG_POP_STATE() \ | |
53 | + do { debug_msg("%d: revert to state ", YYSTATE); \ | |
54 | + yy_pop_state(); debug_msg("%d\n", YYSTATE); \ | |
55 | + } while(0) | |
56 | + | |
52 | 57 | # define DEBUG_RETURN(TOKEN, NAME) \ |
53 | - do { debug_msg("%d: return token %s (%d)\n", YYSTATE, NAME, TOKEN); \ | |
58 | + do { debug_msg("%d: return token %s (%d)\n", \ | |
59 | + YYSTATE, NAME, TOKEN \ | |
60 | + ); \ | |
54 | 61 | return TOKEN; \ |
55 | 62 | } while(0) |
56 | 63 |
@@ -73,6 +80,7 @@ static void debug_msg (const char *fmt, ...) | ||
73 | 80 | # define DEBUG_ECHO |
74 | 81 | # define DEBUG_MSG(ARGLIST) |
75 | 82 | # define DEBUG_PUSH_STATE(NAME) yy_push_state( NAME ) |
83 | +# define DEBUG_POP_STATE() yy_pop_state() | |
76 | 84 | # define DEBUG_RETURN(TOKEN, NAME) return TOKEN |
77 | 85 | # define DEBUG_RETURN_VALUE return VALUE |
78 | 86 | #endif |
@@ -86,7 +94,10 @@ enum { PSBB_PHASE_INIT = 0, PSBB_IN_HEADER, PSBB_IN_TRAILER }; | ||
86 | 94 | static int psbb_phase, psbb_crescendo_seek( void ), psbb_parse_status; |
87 | 95 | |
88 | 96 | #define DEBUG_PDFINVOKE(STATE, TOKEN, NAME) \ |
89 | - do { yy_push_state( STATE ); DEBUG_RETURN(TOKEN, NAME); \ | |
97 | + do { DEBUG_MSG(("%d: processing entry with key '%s'\n", \ | |
98 | + YYSTATE, yytext \ | |
99 | + )); \ | |
100 | + yy_push_state( STATE ); DEBUG_RETURN(TOKEN, NAME); \ | |
90 | 101 | } while(0) |
91 | 102 | |
92 | 103 | #define PDFINVOKE(STATE, TOKEN) DEBUG_PDFINVOKE(STATE, TOKEN, #TOKEN) |
@@ -179,7 +190,7 @@ static int pdf_trailer( void ) | ||
179 | 190 | * not sufficient here, since we need to be prepared to handle any of |
180 | 191 | * the CR only, LF only, or CRLF line ending conventions). |
181 | 192 | */ |
182 | -<SKIP>{READLN} { yy_pop_state(); } | |
193 | +<SKIP>{READLN} { DEBUG_POP_STATE(); } | |
183 | 194 | |
184 | 195 | |
185 | 196 | /* State: PSHDR |
@@ -345,10 +356,12 @@ static int pdf_trailer( void ) | ||
345 | 356 | "/Pages"/{PDFSEP} { DEBUG_PUSH_STATE( PDFREFER ); } |
346 | 357 | "/Kids"/{PDFSEP} { DEBUG_PUSH_STATE( PDFALLKIDS ); } |
347 | 358 | "/MediaBox"/{PDFSEP} { DEBUG_PUSH_STATE( PDFMEDIABOX ); } |
348 | -"/"{PDFNAME}/{PDFSEP} { DEBUG_MSG(("%d: skipping entry with key '%s'\n", YYSTATE, yytext)); | |
359 | +"/"{PDFNAME}/{PDFSEP} { DEBUG_MSG(("%d: skipping entry with key '%s'\n", | |
360 | + YYSTATE, yytext | |
361 | + )); | |
349 | 362 | DEBUG_PUSH_STATE( PDFIGNORE ); |
350 | 363 | } |
351 | -">>" { yy_pop_state(); } | |
364 | +">>" { DEBUG_POP_STATE(); } | |
352 | 365 | .|\n |
353 | 366 | } |
354 | 367 |
@@ -365,8 +378,8 @@ static int pdf_trailer( void ) | ||
365 | 378 | * object type which we do not expect to encounter. |
366 | 379 | */ |
367 | 380 | <PDFOBJTYPE>{ |
368 | -"/Catalog"/{PDFSEP} { yy_pop_state(); RETURN(PDFOBJREF); } | |
369 | -"/Page"s?/{PDFSEP} { yy_pop_state(); } | |
381 | +"/Catalog"/{PDFSEP} { DEBUG_POP_STATE(); RETURN(PDFOBJREF); } | |
382 | +"/Page"s?/{PDFSEP} { DEBUG_POP_STATE(); } | |
370 | 383 | "/"{PDFNAME}/{PDFSEP} { DEBUG_MSG(("%d: ignoring unknown object type '%s'\n" |
371 | 384 | "%d: fall back to state 'PDFIGNORE'\n", |
372 | 385 | YYSTATE, yytext, YYSTATE |
@@ -388,7 +401,7 @@ static int pdf_trailer( void ) | ||
388 | 401 | */ |
389 | 402 | <PDFALLKIDS>"["{SEP}* { BEGIN PDFKIDS; PDFINVOKE( PDFREFER, PDFOBJREF ); } |
390 | 403 | <PDFKIDS,PDFALLKIDS>{ |
391 | -"]" { yy_pop_state(); } | |
404 | +"]" { DEBUG_POP_STATE(); } | |
392 | 405 | {INTVAL}/{SEP} |
393 | 406 | "R"/{PDFSEP} |
394 | 407 | {SEP}+ |
@@ -403,9 +416,9 @@ static int pdf_trailer( void ) | ||
403 | 416 | * start condition whence this state was attained. |
404 | 417 | */ |
405 | 418 | <PDFREFER>{ |
406 | -"R"/{PDFSEP} { yy_pop_state(); RETURN('R'); } | |
419 | +"R"/{PDFSEP} { DEBUG_POP_STATE(); RETURN('R'); } | |
407 | 420 | {INTVAL}/{PDFSEP} { yylval = atol( yytext ); RETURN_VALUE; } |
408 | -./({EOL}|"/") { yy_pop_state(); } | |
421 | +./({EOL}|"/") { DEBUG_POP_STATE(); } | |
409 | 422 | [ \t\r\n]+ |
410 | 423 | } |
411 | 424 |
@@ -431,7 +444,7 @@ static int pdf_trailer( void ) | ||
431 | 444 | <PDFMEDIABOXEVAL>{ |
432 | 445 | {FLOATVAL}/{PDFSEP} { yylval = lround( atof( yytext )); RETURN_VALUE; } |
433 | 446 | {INTVAL}/{PDFSEP} { yylval = atol( yytext ); RETURN_VALUE; } |
434 | -"]" { yy_pop_state(); } | |
447 | +"]" { DEBUG_POP_STATE(); } | |
435 | 448 | {SEP}+ |
436 | 449 | } |
437 | 450 |
@@ -442,7 +455,9 @@ static int pdf_trailer( void ) | ||
442 | 455 | * revert to the state whence this condition was invoked. |
443 | 456 | */ |
444 | 457 | <PDFEVAL>{ |
445 | -{INTVAL}/{PDFSEP} { yylval = atol( yytext ); yy_pop_state(); RETURN_VALUE; } | |
458 | +{INTVAL}/{PDFSEP} { yylval = atol( yytext ); DEBUG_POP_STATE(); | |
459 | + RETURN_VALUE; | |
460 | + } | |
446 | 461 | [ \t\r\n]+ |
447 | 462 | } |
448 | 463 |
@@ -454,8 +469,8 @@ static int pdf_trailer( void ) | ||
454 | 469 | <PDFIGNORE>{ |
455 | 470 | [^</>\r\n]+ { DEBUG_ECHO; } |
456 | 471 | "<<" { DEBUG_PUSH_STATE( PDFDICT ); } |
457 | -[</>] { yyless(0); yy_pop_state(); } | |
458 | -{EOL} { yy_pop_state(); } | |
472 | +[</>] { yyless(0); DEBUG_POP_STATE(); } | |
473 | +{EOL} { DEBUG_POP_STATE(); } | |
459 | 474 | } |
460 | 475 | |
461 | 476 | /* State: PDFXREF |
@@ -533,13 +548,18 @@ static int pdf_trailer( void ) | ||
533 | 548 | * specified object; |
534 | 549 | */ |
535 | 550 | <PDFGOXREF>{READLN} { long offset, gen; char disp; |
536 | - sscanf( yytext, "%10ld %5ld %c", &offset, &gen, &disp ); | |
537 | - DEBUG_MSG(("%d: %.18s --> %d; %d %c\n", YYSTATE, yytext, offset, gen, disp)); | |
551 | + sscanf( yytext, "%10ld %5ld %c", | |
552 | + &offset, &gen, &disp | |
553 | + ); | |
554 | + DEBUG_MSG(("%d: %.18s --> %d; %d %c\n", | |
555 | + YYSTATE, yytext, offset, gen, disp | |
556 | + )); | |
538 | 557 | if( disp == 'n' && gen == ref[1] ) |
539 | 558 | { pdfseek( offset ); BEGIN PDFGETOBJECT; |
540 | 559 | } |
541 | 560 | else |
542 | - { yyerror( "index entry '%.18s' unexpected in file '%s'", | |
561 | + { yyerror( | |
562 | + "index entry '%.18s' unexpected in file '%s'", | |
543 | 563 | yytext, psbb_input_file |
544 | 564 | ); |
545 | 565 | return PSBB_PARSE_FAILURE; |