Mercurial > ~dholland > hg > tradcpp > index.cgi
comparison 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 |
comparison
equal
deleted
inserted
replaced
184:d359d9b86327 | 185:16b4451e34b8 |
---|---|
25 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | 25 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
26 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | 26 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
27 * POSSIBILITY OF SUCH DAMAGE. | 27 * POSSIBILITY OF SUCH DAMAGE. |
28 */ | 28 */ |
29 | 29 |
30 #include <stdio.h> | |
30 #include <string.h> | 31 #include <string.h> |
31 #include <unistd.h> | 32 #include <unistd.h> |
32 #include <fcntl.h> | 33 #include <fcntl.h> |
33 #include <errno.h> | 34 #include <errno.h> |
34 | 35 |
170 linebufmax *= 2; | 171 linebufmax *= 2; |
171 } | 172 } |
172 linebuf = dorealloc(linebuf, oldmax, linebufmax); | 173 linebuf = dorealloc(linebuf, oldmax, linebufmax); |
173 } | 174 } |
174 if (linebufpos == 0) { | 175 if (linebufpos == 0) { |
176 if (!place_samefile(&linebufplace, p)) { | |
177 if (mode.output_cheaplinenumbers) { | |
178 char str[256]; | |
179 | |
180 snprintf(str, sizeof(str), "# %u \"%s\"\n", | |
181 p->line, place_getname(p)); | |
182 dowrite(str, strlen(str)); | |
183 } | |
184 } | |
175 linebufplace = *p; | 185 linebufplace = *p; |
176 } | 186 } |
177 memcpy(linebuf + linebufpos, buf, len); | 187 memcpy(linebuf + linebufpos, buf, len); |
178 linebufpos += len; | 188 linebufpos += len; |
179 | 189 |