diff options
author | William M. Brack <wbrack@src.gnome.org> | 2003-05-13 02:06:18 +0000 |
---|---|---|
committer | William M. Brack <wbrack@src.gnome.org> | 2003-05-13 02:06:18 +0000 |
commit | 3dd57f79813f4a253644396172320293e53e932c (patch) | |
tree | ec30becb9100ff1cbb07d936599c0d20aa8d4e61 /error.c | |
parent | d72c7e339c9c1be80cf194f23152545aff8f2a05 (diff) | |
download | libxml2-3dd57f79813f4a253644396172320293e53e932c.tar.gz |
Fixed bug 109942
Diffstat (limited to 'error.c')
-rw-r--r-- | error.c | 37 |
1 files changed, 17 insertions, 20 deletions
@@ -149,8 +149,8 @@ xmlParserPrintFileInfo(xmlParserInputPtr input) { void xmlParserPrintFileContext(xmlParserInputPtr input) { const xmlChar *cur, *base; - int n; - xmlChar content[81]; + int n, col; + xmlChar content[81]; /* space for 80 chars + line terminator */ xmlChar *ctnt; if (input == NULL) return; @@ -161,37 +161,34 @@ xmlParserPrintFileContext(xmlParserInputPtr input) { cur--; } n = 0; - /* search backwards for beginning-of-line maximum 80 characters */ - while ((n++ < 80) && (cur > base) && (*cur != '\n') && (*cur != '\r')) + /* search backwards for beginning-of-line (to max buff size) */ + while ((n++ < sizeof(content)-1) && (cur > base) && (*cur != '\n') && (*cur != '\r')) cur--; if ((*cur == '\n') || (*cur == '\r')) cur++; - /* search forward for end-of-line maximum 80 characters */ + /* calculate the error position in terms of the current position */ + col = input->cur - cur; + /* search forward for end-of-line (to max buff size) */ n = 0; ctnt = content; - while ((*cur != 0) && (*cur != '\n') && (*cur != '\r') && (n < 79)) { + /* copy selected text to our buffer */ + while ((*cur != 0) && (*cur != '\n') && (*cur != '\r') && (n < sizeof(content)-1)) { *ctnt++ = *cur++; n++; } *ctnt = 0; + /* print out the selected text */ xmlGenericError(xmlGenericErrorContext,"%s\n", content); /* create blank line with problem pointer */ - cur = input->cur; - while ((cur > base) && ((*cur == '\n') || (*cur == '\r'))) { - cur--; - } n = 0; ctnt = content; - while ((n++ < 79) && (cur > base) && (*cur != '\n') && (*cur != '\r')) { - *ctnt++ = ' '; - cur--; - } - if (ctnt > content) { - *(--ctnt) = '^'; - *(++ctnt) = 0; - } else { - *ctnt = '^'; - *(++ctnt) = 0; + /* (leave buffer space for pointer + line terminator) */ + while ((n<col) && (n++ < sizeof(content)-2) && (*ctnt != 0)) { + if (*ctnt!='\t') + *ctnt = ' '; + *ctnt++; } + *ctnt++ = '^'; + *ctnt = 0; xmlGenericError(xmlGenericErrorContext,"%s\n", content); } |