summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMariusz PluciƄski <mplucinski@mplucinski.com>2014-06-21 02:07:23 +0200
committerWill Estes <westes575@gmail.com>2014-06-26 16:39:39 -0400
commit3e0d96af4c72ed2ab3f6650713ff24689ac936c7 (patch)
tree7fa0f9d046f19a7ab94a79024c4c7a0bbf63dee6 /src
parentc979ed27bb4389ead5e812c0336e1d0b70a3a5a8 (diff)
Change output formats from octal to hexadecimal
Diffstat (limited to 'src')
-rw-r--r--src/flexdef.h3
-rw-r--r--src/main.c5
-rw-r--r--src/misc.c7
-rw-r--r--src/options.c2
-rw-r--r--src/options.h1
-rw-r--r--src/yylex.c11
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;
}