diff options
author | David Phillips <david@sighup.nz> | 2018-08-01 02:10:08 +1200 |
---|---|---|
committer | David Phillips <david@sighup.nz> | 2018-08-01 02:10:08 +1200 |
commit | 74808af82e455a944e689ba53945ebd8485d4f4f (patch) | |
tree | 6152ab9905cf93fe17346b952d18fba823d9a633 | |
parent | 957d77141f56714e9f4551c8d49e6658ff778ce7 (diff) | |
download | hence-74808af82e455a944e689ba53945ebd8485d4f4f.tar.xz |
Add missing common.c
-rw-r--r-- | common.c | 31 |
1 files changed, 31 insertions, 0 deletions
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 <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); +} |