@@ -61,6 +61,7 @@ void inflate_inbuf(void *yyscanner, const bxstr_t *configfile);
61
61
#include < unitypes.h>
62
62
63
63
#include " boxes.h"
64
+ #include " logging.h"
64
65
#include " shape.h"
65
66
#include " tools.h"
66
67
#include " parsing.h"
@@ -181,9 +182,7 @@ PFILENAME [^\r\n]+
181
182
else if (*p == yyextra->sdel ) {
182
183
*p = ' \0 ' ;
183
184
yyless ((p - str) + 2 + qcnt); /* string plus quotes */
184
- #ifdef LEXER_DEBUG
185
- fprintf (stderr, " STRING: \" %s\"\n " , str);
186
- #endif
185
+ log_debug (__FILE__, LEXER, " STRING: \" %s\"\n " , str);
187
186
188
187
uint32_t *utf8 = u32_strconv_from_arg (str, CONFIG_FILE_ENCODING);
189
188
yylval->s = bxs_from_unicode (utf8);
@@ -293,9 +292,7 @@ PFILENAME [^\r\n]+
293
292
294
293
295
294
<BOX >Tags {
296
- #ifdef LEXER_DEBUG
297
- fprintf (stderr, " YTAGS: %s\n " , yytext);
298
- #endif
295
+ log_debug (__FILE__, LEXER, " YTAGS: %s\n " , yytext);
299
296
return YTAGS;
300
297
}
301
298
@@ -368,9 +365,7 @@ PFILENAME [^\r\n]+
368
365
/*
369
366
* general key words
370
367
*/
371
- #ifdef LEXER_DEBUG
372
- fprintf (stderr, " KEYWORD: %s\n " , yytext);
373
- #endif
368
+ log_debug (__FILE__, LEXER, " KEYWORD: %s\n " , yytext);
374
369
yylval->ascii = strdup (yytext);
375
370
if (yylval->ascii == NULL ) {
376
371
perror (PROJECT);
@@ -398,9 +393,7 @@ PFILENAME [^\r\n]+
398
393
perror (PROJECT);
399
394
exit (EXIT_FAILURE);
400
395
}
401
- #ifdef LEXER_DEBUG
402
- fprintf (stderr, " ASCIIID: %s\n " , yylval->ascii );
403
- #endif
396
+ log_debug (__FILE__, LEXER, " ASCIIID: %s\n " , yylval->ascii );
404
397
return ASCII_ID;
405
398
}
406
399
@@ -414,44 +407,38 @@ PFILENAME [^\r\n]+
414
407
perror (PROJECT);
415
408
exit (EXIT_FAILURE);
416
409
}
417
- #ifdef LEXER_DEBUG
418
- fprintf (stderr, " BXWORD: %s\n " , u32_strconv_to_output (utf8));
419
- #endif
410
+ if (is_debug_logging (LEXER)) {
411
+ char *out_utf8 = u32_strconv_to_output (utf8);
412
+ log_debug (__FILE__, LEXER, " BXWORD: %s\n " , out_utf8);
413
+ BFREE (out_utf8);
414
+ }
420
415
BFREE (utf8);
421
416
return BXWORD;
422
417
}
423
418
424
419
425
420
<BOX >[\+ - ]? [0 -9 ]+ {
426
- #ifdef LEXER_DEBUG
427
- fprintf (stderr, " YNUMBER: %s\n " , yytext);
428
- #endif
421
+ log_debug (__FILE__, LEXER, " YNUMBER: %s\n " , yytext);
429
422
yylval->num = atoi (yytext);
430
423
return YNUMBER;
431
424
}
432
425
433
426
434
427
<BOX ,SHAPES ,ELASTIC >[,(){} ] {
435
- #ifdef LEXER_DEBUG
436
- fprintf (stderr, " SYMBOL: \' %c\'\n " , yytext[0 ]);
437
- #endif
428
+ log_debug (__FILE__, LEXER, " SYMBOL: \' %c\'\n " , yytext[0 ]);
438
429
return yytext[0 ];
439
430
}
440
431
441
432
442
433
<INITIAL ,BOX ,SHAPES ,ELASTIC >#. * $ {
443
434
/* ignore comments */
444
- #ifdef LEXER_DEBUG
445
- fprintf (stderr, " COMMENT: %s\n " , yytext+1 );
446
- #endif
435
+ log_debug (__FILE__, LEXER, " COMMENT: %s\n " , yytext + 1 );
447
436
}
448
437
449
438
450
439
<INITIAL ,BOX ,SHAPES ,ELASTIC >. {
451
440
/* a character that made no sense where it was encountered. Let the parser handle it. */
452
- #ifdef LEXER_DEBUG
453
- fprintf (stderr, " YUNREC: \' %c\'\n " , yytext[0 ]);
454
- #endif
441
+ log_debug (__FILE__, LEXER, " YUNREC: \' %c\'\n " , yytext[0 ]);
455
442
return YUNREC;
456
443
}
457
444
@@ -490,12 +477,15 @@ static void report_state_char(char *symbol, char c, char *expected_state_str)
490
477
491
478
static void report_state (char *symbol, char *text, char *expected_state_str)
492
479
{
493
- int lexerDebug = 0 ;
494
- #ifdef LEXER_DEBUG
495
- lexerDebug = 1 ;
496
- #endif
497
- if (lexerDebug) {
498
- fprintf (stderr, " %7s: %s -- STATE %s\n " , symbol, text, expected_state_str);
480
+ if (is_debug_logging (LEXER)) {
481
+ size_t text_len = 0 ;
482
+ if (text != NULL ) {
483
+ text_len = strlen (text);
484
+ if (text_len > 0 && (text[text_len - 1 ] == ' \r ' || text[text_len - 1 ] == ' \t ' )) {
485
+ text[text_len - 1 ] = ' \0 ' ;
486
+ }
487
+ }
488
+ log_debug (__FILE__, LEXER, " %7s: %s (%d) -- STATE %s\n " , symbol, text, text_len, expected_state_str);
499
489
}
500
490
}
501
491
@@ -516,9 +506,7 @@ static int change_string_delimiters(pass_to_flex *extra, char *delim_expr)
516
506
return 1 ;
517
507
}
518
508
519
- #ifdef LEXER_DEBUG
520
- fprintf (stderr, " YDELIMS: change_string_delimiters('%c', '%c')\n " , delim_expr[0 ], delim_expr[1 ]);
521
- #endif
509
+ log_debug (__FILE__, LEXER, " YDELIMS: change_string_delimiters('%c', '%c')\n " , delim_expr[0 ], delim_expr[1 ]);
522
510
extra->sesc = delim_expr[0 ];
523
511
extra->sdel = delim_expr[1 ];
524
512
0 commit comments