From 74808af82e455a944e689ba53945ebd8485d4f4f Mon Sep 17 00:00:00 2001 From: David Phillips Date: Wed, 1 Aug 2018 02:10:08 +1200 Subject: Add missing common.c --- common.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 common.c diff --git a/common.c b/common.c new file mode 100644 index 0000000..96c9b72 --- /dev/null +++ b/common.c @@ -0,0 +1,31 @@ +#include +#include +#include + +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); +} -- cgit v1.1