summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--common.c16
1 files changed, 11 insertions, 5 deletions
diff --git a/common.c b/common.c
index fbc9ae2..62f0a2e 100644
--- a/common.c
+++ b/common.c
@@ -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 == ' ') {