- /* The caret of a multiline location ends with the first line. */
- int end = loc.start.line != loc.end.line ? len : loc.end.column;
-
- if (len)
- {
- int i = loc.start.column;
- /* Quote the file, indent by a single column. */
- fputc (' ', out);
- fwrite (buf, 1, len, out);
-
- /* Print the caret, with the same indent as above. */
- fputc (' ', out);
- fprintf (out, "%*s", loc.start.column - 1, "");
- do {
- fputc ('^', out);
- } while (++i < end);
+ /* Quote the file, indent by a single column. */
+ putc (' ', out);
+ do
+ putc (c, out);
+ while ((c = getc (caret_info.source)) != EOF && c != '\n');
+ putc ('\n', out);
+
+ {
+ /* The caret of a multiline location ends with the first line. */
+ size_t len = loc.start.line != loc.end.line
+ ? ftell (caret_info.source) - caret_info.offset
+ : loc.end.column;
+ int i;
+
+ /* Print the carets (at least one), with the same indent as above.*/
+ fprintf (out, " %*s", loc.start.column - 1, "");
+ for (i = loc.start.column; i == loc.start.column || i < len; ++i)
+ putc ('^', out);