summaryrefslogtreecommitdiff
path: root/common.c
blob: 96c9b72761f578cde48935befb7f0d68de1aeef2 (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
#include <stdio.h>
#include <stddef.h>
#include <string.h>

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];
	rewind(fd);
	for (; line; line--) {
		fgets(buf, sizeof(buf), fd);
	}

	fputs(margin, stderr);
	fputs(buf, 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);
}