blob: 62f0a2ea9e3646381b4afeec0eefe858dddf723c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
#include <stdio.h>
#include <stddef.h>
#include <string.h>
void
indicate_file_area(FILE* fd, size_t line, size_t column, size_t span) {
const char margin[] = " ";
char buf[1024] = { '\0' };
char *s = buf;
char *line_start = buf;
rewind(fd);
while (line && !feof(fd) && fgets(buf, sizeof(buf), fd)) {
s = buf;
while (*s) {
if (*(s++) == '\n') {
line--;
}
}
}
while (*line_start == '\t' || *line_start == ' ') {
line_start++;
}
fputs(margin, stderr);
fputs(line_start, stderr);
/* corner case (still needed?) - buf was just return */
if (strlen(buf) == 1 && buf[0] == '\n') {
fputc('\n', stderr);
}
fputs(margin, stderr);
for (column--; column; column--) {
fputc(' ', stderr);
}
for (; span; span--) {
fputc('^', stderr);
}
fputc('\n', stderr);
}
|