# HG changeset patch # User David A. Holland # Date 1434095976 14400 # Node ID 16b4451e34b8aad10e9eaaf294dacaaeea0c4043 # Parent d359d9b86327c059c2a98c7f690f6ddfcec0f385 Add the ability to output line numbers, sort of. It is enabled with the intentionally undocumented -p option (similar to -P but reversed sense) and it might be vaguely useful but only prints the line number when the file changes and may not get the line numbers right. diff -r d359d9b86327 -r 16b4451e34b8 TODO --- a/TODO Fri Jun 12 03:35:01 2015 -0400 +++ b/TODO Fri Jun 12 03:59:36 2015 -0400 @@ -33,3 +33,5 @@ twice, once when the macro is defined and again when it's expanded. Note that gcc's cpp -traditional is getting t37 wrong, and it gets t36 wrong with -C. + - remove the intentionally undocumented -p option and generate + proper linenumber output. diff -r d359d9b86327 -r 16b4451e34b8 main.c --- a/main.c Fri Jun 12 03:35:01 2015 -0400 +++ b/main.c Fri Jun 12 03:59:36 2015 -0400 @@ -55,6 +55,7 @@ .do_output = true, .output_linenumbers = true, + .output_cheaplinenumbers = false, .output_retain_comments = false, .output_file = NULL, @@ -781,6 +782,7 @@ { "MG", &mode.depend_assume_generated, true }, { "MP", &mode.depend_issue_fakerules, true }, { "P", &mode.output_linenumbers, false }, + { "p", &mode.output_cheaplinenumbers, true }, { "Wcomment", &warns.nestcomment, true }, { "Wendif-labels", &warns.endiflabels, true }, { "Werror", &mode.werror, true }, diff -r d359d9b86327 -r 16b4451e34b8 mode.h --- a/mode.h Fri Jun 12 03:35:01 2015 -0400 +++ b/mode.h Fri Jun 12 03:59:36 2015 -0400 @@ -37,6 +37,7 @@ bool do_stddef; bool do_output; bool output_linenumbers; + bool output_cheaplinenumbers; bool output_retain_comments; const char *output_file; bool do_depend; diff -r d359d9b86327 -r 16b4451e34b8 output.c --- a/output.c Fri Jun 12 03:35:01 2015 -0400 +++ b/output.c Fri Jun 12 03:59:36 2015 -0400 @@ -27,6 +27,7 @@ * POSSIBILITY OF SUCH DAMAGE. */ +#include #include #include #include @@ -172,6 +173,15 @@ linebuf = dorealloc(linebuf, oldmax, linebufmax); } if (linebufpos == 0) { + if (!place_samefile(&linebufplace, p)) { + if (mode.output_cheaplinenumbers) { + char str[256]; + + snprintf(str, sizeof(str), "# %u \"%s\"\n", + p->line, place_getname(p)); + dowrite(str, strlen(str)); + } + } linebufplace = *p; } memcpy(linebuf + linebufpos, buf, len); diff -r d359d9b86327 -r 16b4451e34b8 place.c --- a/place.c Fri Jun 12 03:35:01 2015 -0400 +++ b/place.c Fri Jun 12 03:59:36 2015 -0400 @@ -102,22 +102,6 @@ } static -bool -place_eq(const struct place *a, const struct place *b) -{ - if (a->type != b->type) { - return false; - } - if (a->file != b->file) { - return false; - } - if (a->line != b->line || a->column != b->column) { - return false; - } - return true; -} - -static struct placefile * placefile_find(const struct place *incfrom, const char *name) { @@ -219,6 +203,30 @@ return NULL; } +bool +place_samefile(const struct place *a, const struct place *b) +{ + if (a->type != b->type) { + return false; + } + if (a->file != b->file) { + return false; + } + return true; +} + +bool +place_eq(const struct place *a, const struct place *b) +{ + if (!place_samefile(a, b)) { + return false; + } + if (a->line != b->line || a->column != b->column) { + return false; + } + return true; +} + static void place_printfrom(const struct place *p) diff -r d359d9b86327 -r 16b4451e34b8 place.h --- a/place.h Fri Jun 12 03:35:01 2015 -0400 +++ b/place.h Fri Jun 12 03:59:36 2015 -0400 @@ -55,6 +55,8 @@ const char *place_getname(const struct place *); const char *place_getparsedir(const struct place *incplace); +bool place_eq(const struct place *, const struct place *); +bool place_samefile(const struct place *, const struct place *); void place_changefile(struct place *p, const char *name);