Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1 | /* |
Daniel Veillard | 97b5877 | 1998-10-20 06:14:16 +0000 | [diff] [blame] | 2 | * error.c: module displaying/handling XML parser errors |
| 3 | * |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 4 | * See Copyright for the status of this software. |
| 5 | * |
Daniel Veillard | 97b5877 | 1998-10-20 06:14:16 +0000 | [diff] [blame] | 6 | * Daniel Veillard <Daniel.Veillard@w3.org> |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | #include <stdio.h> |
| 10 | #include <stdarg.h> |
| 11 | #include "parser.h" |
| 12 | |
Daniel Veillard | 97b5877 | 1998-10-20 06:14:16 +0000 | [diff] [blame] | 13 | /** |
| 14 | * xmlParserError: |
| 15 | * @ctxt: an XML parser context |
| 16 | * @msg: the message to display/transmit |
| 17 | * @...: extra parameters for the message display |
| 18 | * |
| 19 | * Display and format an error messages, gives file, line, position and |
| 20 | * extra parameters. |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 21 | */ |
Daniel Veillard | 97b5877 | 1998-10-20 06:14:16 +0000 | [diff] [blame] | 22 | void |
| 23 | xmlParserError(xmlParserCtxtPtr ctxt, const char *msg, ...) |
| 24 | { |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 25 | const CHAR *cur, *base; |
| 26 | va_list args; |
| 27 | int n; |
| 28 | |
| 29 | va_start(args, msg); |
| 30 | if (ctxt->input->filename) |
| 31 | fprintf(stderr, "%s:%d: ", ctxt->input->filename, |
| 32 | ctxt->input->line); |
| 33 | else |
| 34 | fprintf(stderr, "line %d: ", ctxt->input->line); |
| 35 | |
| 36 | fprintf(stderr, "error: "); |
| 37 | vfprintf(stderr, msg, args); |
| 38 | va_end(ap); |
| 39 | cur = ctxt->input->cur; |
| 40 | base = ctxt->input->base; |
| 41 | while ((*cur == '\n') || (*cur == '\r')) { |
| 42 | cur--; |
| 43 | base--; |
| 44 | } |
| 45 | n = 0; |
| 46 | while ((n++ < 60) && (cur >= base) && (*cur != '\n') && (*cur != '\r')) |
| 47 | cur--; |
| 48 | if ((*cur == '\n') || (*cur == '\r')) cur++; |
| 49 | base = cur; |
| 50 | n = 0; |
| 51 | while ((*cur != 0) && (*cur != '\n') && (*cur != '\r') && (n < 79)) { |
| 52 | fprintf(stderr, "%c", (unsigned char) *cur++); |
| 53 | n++; |
| 54 | } |
| 55 | fprintf(stderr, "\n"); |
| 56 | cur = ctxt->input->cur; |
| 57 | while ((*cur == '\n') || (*cur == '\r')) |
| 58 | cur--; |
| 59 | n = 0; |
| 60 | while ((cur != base) && (n++ < 60)) { |
| 61 | fprintf(stderr, " "); |
| 62 | base++; |
| 63 | } |
| 64 | fprintf(stderr,"^\n"); |
| 65 | } |
| 66 | |
Daniel Veillard | 97b5877 | 1998-10-20 06:14:16 +0000 | [diff] [blame] | 67 | /** |
| 68 | * xmlParserWarning: |
| 69 | * @ctxt: an XML parser context |
| 70 | * @msg: the message to display/transmit |
| 71 | * @...: extra parameters for the message display |
| 72 | * |
| 73 | * Display and format a warning messages, gives file, line, position and |
| 74 | * extra parameters. |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 75 | */ |
Daniel Veillard | 97b5877 | 1998-10-20 06:14:16 +0000 | [diff] [blame] | 76 | void |
| 77 | xmlParserWarning(xmlParserCtxtPtr ctxt, const char *msg, ...) |
| 78 | { |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 79 | const CHAR *cur, *base; |
| 80 | va_list args; |
| 81 | int n; |
| 82 | |
| 83 | va_start(args, msg); |
| 84 | if (ctxt->input->filename) |
| 85 | fprintf(stderr, "%s:%d: ", ctxt->input->filename, |
| 86 | ctxt->input->line); |
| 87 | else |
| 88 | fprintf(stderr, "line %d: ", ctxt->input->line); |
| 89 | |
| 90 | fprintf(stderr, "warning: "); |
| 91 | vfprintf(stderr, msg, args); |
| 92 | va_end(ap); |
| 93 | cur = ctxt->input->cur; |
| 94 | base = ctxt->input->base; |
| 95 | n = 0; |
| 96 | while ((n++ < 60) && (cur >= base) && (*cur != '\n') && (*cur != '\r')) |
| 97 | cur--; |
| 98 | if ((*cur != '\n') || (*cur != '\r')) cur++; |
| 99 | base = cur; |
| 100 | n = 0; |
| 101 | while ((*cur != 0) && (*cur != '\n') && (*cur != '\r') && (n < 79)) { |
| 102 | fprintf(stderr, "%c", (unsigned char) *cur++); |
| 103 | n++; |
| 104 | } |
| 105 | fprintf(stderr, "\n"); |
| 106 | cur = ctxt->input->cur; |
| 107 | n = 0; |
| 108 | while ((cur != base) && (n++ < 60)) { |
| 109 | fprintf(stderr, " "); |
| 110 | base++; |
| 111 | } |
| 112 | fprintf(stderr,"^\n"); |
| 113 | } |
Daniel Veillard | 97b5877 | 1998-10-20 06:14:16 +0000 | [diff] [blame] | 114 | |