From 3e0d96af4c72ed2ab3f6650713ff24689ac936c7 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Mariusz=20Pluci=C5=84ski?= Date: Sat, 21 Jun 2014 02:07:23 +0200 Subject: [PATCH] Change output formats from octal to hexadecimal --- src/flexdef.h | 3 ++- src/main.c | 5 ++++- src/misc.c | 7 +++++-- src/options.c | 2 ++ src/options.h | 1 + src/yylex.c | 11 ++++++----- 6 files changed, 20 insertions(+), 9 deletions(-) diff --git a/src/flexdef.h b/src/flexdef.h index 046dd9a..132812b 100644 --- a/src/flexdef.h +++ b/src/flexdef.h @@ -395,6 +395,7 @@ char *alloca (); * yymore_really_used - whether to treat yymore() as really used, regardless * of what we think based on references to it in the user's actions. * reject_really_used - same for REJECT + * trace_hex - use hexadecimal numbers in trace/debug outputs instead of octals */ extern int printstats, syntaxerror, eofseen, ddebug, trace, nowarn, @@ -409,7 +410,7 @@ extern int csize; extern int yymore_used, reject, real_reject, continued_action, in_rule; extern int yymore_really_used, reject_really_used; - +extern int trace_hex; /* Variables used in the flex input routines: * datapos - characters on current output line diff --git a/src/main.c b/src/main.c index 069b7b2..1eb5aa6 100644 --- a/src/main.c +++ b/src/main.c @@ -57,6 +57,7 @@ int C_plus_plus, long_align, use_read, yytext_is_array, do_yywrap, int reentrant, bison_bridge_lval, bison_bridge_lloc; int yymore_used, reject, real_reject, continued_action, in_rule; int yymore_really_used, reject_really_used; +int trace_hex = 0; int datapos, dataline, linenum; FILE *skelfile = NULL; int skel_ind = 0; @@ -1421,7 +1422,8 @@ void flexinit (argc, argv) //buf_strdefine (&userdef_buf, "YY_NO_SET_LLOC", "1"); buf_m4_define( &m4defs_buf, "M4_YY_NO_SET_LLOC",0); break; - + case OPT_HEX: + trace_hex = 1; } /* switch */ } /* while scanopt() */ @@ -1818,6 +1820,7 @@ void usage () " -T, --trace %s should run in trace mode\n" " -w, --nowarn do not generate warnings\n" " -v, --verbose write summary of scanner statistics to stdout\n" + " --hex use hexadecimal numbers instead of octal in debug outputs\n" "\n" "Files:\n" " -o, --outfile=FILE specify output filename\n" " -S, --skel=FILE specify skeleton file\n" diff --git a/src/misc.c b/src/misc.c index e3fdd50..cd88928 100644 --- a/src/misc.c +++ b/src/misc.c @@ -748,7 +748,7 @@ void out_m4_define (const char* def, const char* val) char *readable_form (c) register int c; { - static char rform[10]; + static char rform[20]; if ((c >= 0 && c < 32) || c >= 127) { switch (c) { @@ -771,7 +771,10 @@ char *readable_form (c) #endif default: - snprintf (rform, sizeof(rform), "\\%.3o", (unsigned int) c); + if(trace_hex) + snprintf (rform, sizeof(rform), "\\x%.2x", (unsigned int) c); + else + snprintf (rform, sizeof(rform), "\\%.3o", (unsigned int) c); return rform; } } diff --git a/src/options.c b/src/options.c index c673173..39d020e 100644 --- a/src/options.c +++ b/src/options.c @@ -117,6 +117,8 @@ optspec_t flexopts[] = { , {"--help", OPT_HELP, 0} , /* Produce this help message. */ + {"--hex", OPT_HEX, 0} + , /* Use hexadecimals in debug/trace outputs */ {"-I", OPT_INTERACTIVE, 0} , {"--interactive", OPT_INTERACTIVE, 0} diff --git a/src/options.h b/src/options.h index 1f3925b..ac3391c 100644 --- a/src/options.h +++ b/src/options.h @@ -60,6 +60,7 @@ enum flexopt_flag_t { OPT_FULL, OPT_HEADER_FILE, OPT_HELP, + OPT_HEX, OPT_INTERACTIVE, OPT_LEX_COMPAT, OPT_POSIX_COMPAT, diff --git a/src/yylex.c b/src/yylex.c index f06e5e6..73d371f 100644 --- a/src/yylex.c +++ b/src/yylex.c @@ -150,11 +150,12 @@ int yylex () break; default: - if (!isascii (yylval) || !isprint (yylval)) - fprintf (stderr, - "\\%.3o", - (unsigned int) yylval); - else + if (!isascii (yylval) || !isprint (yylval)) { + if(trace_hex) + fprintf (stderr, "\\x%02x", (unsigned int) yylval); + else + fprintf (stderr, "\\%.3o", (unsigned int) yylval); + } else (void) putc (yylval, stderr); break; } -- 2.40.0