Skip to content

Commit 942389f

Browse files
committed
logg
1 parent 4f5e9e3 commit 942389f

File tree

1 file changed

+24
-36
lines changed

1 file changed

+24
-36
lines changed

src/lexer.l

Lines changed: 24 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ void inflate_inbuf(void *yyscanner, const bxstr_t *configfile);
6161
#include <unitypes.h>
6262

6363
#include "boxes.h"
64+
#include "logging.h"
6465
#include "shape.h"
6566
#include "tools.h"
6667
#include "parsing.h"
@@ -181,9 +182,7 @@ PFILENAME [^\r\n]+
181182
else if (*p == yyextra->sdel) {
182183
*p = '\0';
183184
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);
187186

188187
uint32_t *utf8 = u32_strconv_from_arg(str, CONFIG_FILE_ENCODING);
189188
yylval->s = bxs_from_unicode(utf8);
@@ -293,9 +292,7 @@ PFILENAME [^\r\n]+
293292

294293

295294
<BOX>Tags {
296-
#ifdef LEXER_DEBUG
297-
fprintf (stderr, " YTAGS: %s\n", yytext);
298-
#endif
295+
log_debug(__FILE__, LEXER, " YTAGS: %s\n", yytext);
299296
return YTAGS;
300297
}
301298

@@ -368,9 +365,7 @@ PFILENAME [^\r\n]+
368365
/*
369366
* general key words
370367
*/
371-
#ifdef LEXER_DEBUG
372-
fprintf (stderr, "KEYWORD: %s\n", yytext);
373-
#endif
368+
log_debug(__FILE__, LEXER, "KEYWORD: %s\n", yytext);
374369
yylval->ascii = strdup(yytext);
375370
if (yylval->ascii == NULL) {
376371
perror (PROJECT);
@@ -398,9 +393,7 @@ PFILENAME [^\r\n]+
398393
perror (PROJECT);
399394
exit (EXIT_FAILURE);
400395
}
401-
#ifdef LEXER_DEBUG
402-
fprintf (stderr, "ASCIIID: %s\n", yylval->ascii);
403-
#endif
396+
log_debug(__FILE__, LEXER, "ASCIIID: %s\n", yylval->ascii);
404397
return ASCII_ID;
405398
}
406399

@@ -414,44 +407,38 @@ PFILENAME [^\r\n]+
414407
perror (PROJECT);
415408
exit (EXIT_FAILURE);
416409
}
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+
}
420415
BFREE(utf8);
421416
return BXWORD;
422417
}
423418

424419

425420
<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);
429422
yylval->num = atoi (yytext);
430423
return YNUMBER;
431424
}
432425

433426

434427
<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]);
438429
return yytext[0];
439430
}
440431

441432

442433
<INITIAL,BOX,SHAPES,ELASTIC>#.*$ {
443434
/* 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);
447436
}
448437

449438

450439
<INITIAL,BOX,SHAPES,ELASTIC>. {
451440
/* 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]);
455442
return YUNREC;
456443
}
457444

@@ -490,12 +477,15 @@ static void report_state_char(char *symbol, char c, char *expected_state_str)
490477

491478
static void report_state(char *symbol, char *text, char *expected_state_str)
492479
{
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);
499489
}
500490
}
501491

@@ -516,9 +506,7 @@ static int change_string_delimiters(pass_to_flex *extra, char *delim_expr)
516506
return 1;
517507
}
518508

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]);
522510
extra->sesc = delim_expr[0];
523511
extra->sdel = delim_expr[1];
524512

0 commit comments

Comments
 (0)