diff options
-rw-r--r-- | common.c | 16 |
1 files changed, 11 insertions, 5 deletions
@@ -4,14 +4,20 @@ void 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]; + const char margin[] = " "; + + char buf[1024] = { '\0' }; + char *s = buf; char *line_start = buf; rewind(fd); - for (; line; line--) { - fgets(buf, sizeof(buf), fd); + while (line && !feof(fd) && fgets(buf, sizeof(buf), fd)) { + s = buf; + while (*s) { + if (*(s++) == '\n') { + line--; + } + } } while (*line_start == '\t' || *line_start == ' ') { |