#include #include #include 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); }