Mercurial > ~dholland > hg > tradcpp > index.cgi
diff output.c @ 185:16b4451e34b8
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.
author | David A. Holland |
---|---|
date | Fri, 12 Jun 2015 03:59:36 -0400 |
parents | ed45f2d8d3bc |
children |
line wrap: on
line diff
--- 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 <stdio.h> #include <string.h> #include <unistd.h> #include <fcntl.h> @@ -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);