diff options
author | David Phillips <david@sighup.nz> | 2018-08-01 20:21:37 +1200 |
---|---|---|
committer | David Phillips <david@sighup.nz> | 2018-08-01 20:29:38 +1200 |
commit | 328e34077a2017d4017f907ac69c7ed5d6c160d4 (patch) | |
tree | 1795fd0d10293320dae0854b5b1d34a59e8fdbec /common.c | |
parent | 70c76b708308c72956e83163b2819be69f725a7e (diff) | |
download | hence-328e34077a2017d4017f907ac69c7ed5d6c160d4.tar.xz |
Trim leading whitespace from contextual error, detect EOF
Side-note that the token location tuple maintains the correct column
number to include the whitespace in the source file. Side-side note:
tabs are counted as one column but many editors will count them as
whatever the tabstop/tabwidth is.
Diffstat (limited to 'common.c')
-rw-r--r-- | common.c | 8 |
1 files changed, 7 insertions, 1 deletions
@@ -7,13 +7,19 @@ indicate_file_area(FILE* fd, size_t line, size_t column, size_t span) { char margin[] = " "; /* FIXME use proper line counting, not this hack */ char buf[1024]; + char *line_start = &buf; + rewind(fd); for (; line; line--) { fgets(buf, sizeof(buf), fd); } + while (*line_start == '\t' || *line_start == ' ') { + line_start++; + } + fputs(margin, stderr); - fputs(buf, stderr); + fputs(line_start, stderr); /* corner case (still needed?) - buf was just return */ if (strlen(buf) == 1 && buf[0] == '\n') { |