]> granicus.if.org Git - flex/commitdiff
Change output formats from octal to hexadecimal
authorMariusz Pluciński <mplucinski@mplucinski.com>
Sat, 21 Jun 2014 00:07:23 +0000 (02:07 +0200)
committerWill Estes <westes575@gmail.com>
Thu, 26 Jun 2014 20:39:39 +0000 (16:39 -0400)
src/flexdef.h
src/main.c
src/misc.c
src/options.c
src/options.h
src/yylex.c

index 046dd9aa794d05d8ff3b8b31d9b67c91a10a9cb2..132812bd736a12731267633a471d7de95b954655 100644 (file)
@@ -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
index 069b7b228c6fe7b1e6216ebad61247e7cd8b92c1..1eb5aa618c12c0024c2986f69a98c1cd0a831923 100644 (file)
@@ -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"
index e3fdd50cdd9b599c0f4585163bda10dadc23cecd..cd889282c82c3d3d722a0dc9483e7d33f838b6c9 100644 (file)
@@ -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;
                }
        }
index c6731738a19beddd7e2f8a6fcbcab12ce9bd4718..39d020ece83bc760f0ce9d7ba1a6f74a2c0f0d81 100644 (file)
@@ -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}
index 1f3925b9e94d7e11400890c713a06dbd788f6841..ac3391c086b5b9b7a3bdb5b480b6afa90d86aed0 100644 (file)
@@ -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,
index f06e5e6a2659ce032c4c33189ffeca3dc6f5eb7c..73d371f0a381a150d80da95f3c43d61bc73f51bf 100644 (file)
@@ -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;
                        }