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 | |
Daniel Veillard | 3c558c3 | 1999-12-22 11:30:41 +0000 | [diff] [blame^] | 9 | #ifdef WIN32 |
| 10 | #include "win32config.h" |
| 11 | #else |
| 12 | #include "config.h" |
| 13 | #endif |
| 14 | |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 15 | #include <stdio.h> |
| 16 | #include <stdarg.h> |
| 17 | #include "parser.h" |
| 18 | |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 19 | /** |
| 20 | * xmlParserPrintFileInfo: |
| 21 | * @input: an xmlParserInputPtr input |
| 22 | * |
| 23 | * Displays the associated file and line informations for the current input |
| 24 | */ |
| 25 | |
| 26 | void |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 27 | xmlParserPrintFileInfo(xmlParserInputPtr input) { |
| 28 | if (input != NULL) { |
| 29 | if (input->filename) |
| 30 | fprintf(stderr, "%s:%d: ", input->filename, |
| 31 | input->line); |
| 32 | else |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 33 | fprintf(stderr, "Entity: line %d: ", input->line); |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 34 | } |
| 35 | } |
| 36 | |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 37 | /** |
| 38 | * xmlParserPrintFileContext: |
| 39 | * @input: an xmlParserInputPtr input |
| 40 | * |
| 41 | * Displays current context within the input content for error tracking |
| 42 | */ |
| 43 | |
| 44 | void |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 45 | xmlParserPrintFileContext(xmlParserInputPtr input) { |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 46 | const xmlChar *cur, *base; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 47 | int n; |
| 48 | |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 49 | cur = input->cur; |
| 50 | base = input->base; |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 51 | while ((cur > base) && ((*cur == '\n') || (*cur == '\r'))) { |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 52 | cur--; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 53 | } |
| 54 | n = 0; |
Daniel Veillard | bc50b59 | 1999-03-01 12:28:53 +0000 | [diff] [blame] | 55 | while ((n++ < 80) && (cur > base) && (*cur != '\n') && (*cur != '\r')) |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 56 | cur--; |
| 57 | if ((*cur == '\n') || (*cur == '\r')) cur++; |
| 58 | base = cur; |
| 59 | n = 0; |
| 60 | while ((*cur != 0) && (*cur != '\n') && (*cur != '\r') && (n < 79)) { |
| 61 | fprintf(stderr, "%c", (unsigned char) *cur++); |
| 62 | n++; |
| 63 | } |
| 64 | fprintf(stderr, "\n"); |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 65 | cur = input->cur; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 66 | while ((*cur == '\n') || (*cur == '\r')) |
| 67 | cur--; |
| 68 | n = 0; |
Daniel Veillard | bc50b59 | 1999-03-01 12:28:53 +0000 | [diff] [blame] | 69 | while ((cur != base) && (n++ < 80)) { |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 70 | fprintf(stderr, " "); |
| 71 | base++; |
| 72 | } |
| 73 | fprintf(stderr,"^\n"); |
| 74 | } |
| 75 | |
Daniel Veillard | 97b5877 | 1998-10-20 06:14:16 +0000 | [diff] [blame] | 76 | /** |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 77 | * xmlParserError: |
| 78 | * @ctx: an XML parser context |
| 79 | * @msg: the message to display/transmit |
| 80 | * @...: extra parameters for the message display |
| 81 | * |
| 82 | * Display and format an error messages, gives file, line, position and |
| 83 | * extra parameters. |
| 84 | */ |
| 85 | void |
| 86 | xmlParserError(void *ctx, const char *msg, ...) |
| 87 | { |
| 88 | xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; |
| 89 | xmlParserInputPtr input; |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 90 | xmlParserInputPtr cur = NULL; |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 91 | va_list args; |
| 92 | |
| 93 | input = ctxt->input; |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 94 | if ((input->filename == NULL) && (ctxt->inputNr > 1)) { |
| 95 | cur = input; |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 96 | input = ctxt->inputTab[ctxt->inputNr - 2]; |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 97 | } |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 98 | |
| 99 | xmlParserPrintFileInfo(input); |
| 100 | |
| 101 | fprintf(stderr, "error: "); |
| 102 | va_start(args, msg); |
| 103 | vfprintf(stderr, msg, args); |
| 104 | va_end(args); |
| 105 | |
| 106 | xmlParserPrintFileContext(input); |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 107 | if (cur != NULL) { |
| 108 | xmlParserPrintFileInfo(cur); |
| 109 | fprintf(stderr, "\n"); |
| 110 | xmlParserPrintFileContext(cur); |
| 111 | } |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 112 | } |
| 113 | |
| 114 | /** |
Daniel Veillard | 97b5877 | 1998-10-20 06:14:16 +0000 | [diff] [blame] | 115 | * xmlParserWarning: |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 116 | * @ctx: an XML parser context |
Daniel Veillard | 97b5877 | 1998-10-20 06:14:16 +0000 | [diff] [blame] | 117 | * @msg: the message to display/transmit |
| 118 | * @...: extra parameters for the message display |
| 119 | * |
| 120 | * Display and format a warning messages, gives file, line, position and |
| 121 | * extra parameters. |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 122 | */ |
Daniel Veillard | 97b5877 | 1998-10-20 06:14:16 +0000 | [diff] [blame] | 123 | void |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 124 | xmlParserWarning(void *ctx, const char *msg, ...) |
Daniel Veillard | 97b5877 | 1998-10-20 06:14:16 +0000 | [diff] [blame] | 125 | { |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 126 | xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 127 | xmlParserInputPtr input; |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 128 | xmlParserInputPtr cur = NULL; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 129 | va_list args; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 130 | |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 131 | input = ctxt->input; |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 132 | if ((input->filename == NULL) && (ctxt->inputNr > 1)) { |
| 133 | cur = input; |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 134 | input = ctxt->inputTab[ctxt->inputNr - 2]; |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 135 | } |
| 136 | |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 137 | |
| 138 | xmlParserPrintFileInfo(input); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 139 | |
| 140 | fprintf(stderr, "warning: "); |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 141 | va_start(args, msg); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 142 | vfprintf(stderr, msg, args); |
Daniel Veillard | 64068b3 | 1999-03-24 20:42:16 +0000 | [diff] [blame] | 143 | va_end(args); |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 144 | |
| 145 | xmlParserPrintFileContext(input); |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 146 | if (cur != NULL) { |
| 147 | xmlParserPrintFileInfo(cur); |
| 148 | fprintf(stderr, "\n"); |
| 149 | xmlParserPrintFileContext(cur); |
| 150 | } |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 151 | } |
| 152 | |
| 153 | /** |
| 154 | * xmlParserValidityError: |
| 155 | * @ctx: an XML parser context |
| 156 | * @msg: the message to display/transmit |
| 157 | * @...: extra parameters for the message display |
| 158 | * |
| 159 | * Display and format an validity error messages, gives file, |
| 160 | * line, position and extra parameters. |
| 161 | */ |
| 162 | void |
| 163 | xmlParserValidityError(void *ctx, const char *msg, ...) |
| 164 | { |
| 165 | xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; |
| 166 | xmlParserInputPtr input; |
| 167 | va_list args; |
| 168 | |
| 169 | input = ctxt->input; |
| 170 | if ((input->filename == NULL) && (ctxt->inputNr > 1)) |
| 171 | input = ctxt->inputTab[ctxt->inputNr - 2]; |
| 172 | |
| 173 | xmlParserPrintFileInfo(input); |
| 174 | |
| 175 | fprintf(stderr, "validity error: "); |
| 176 | va_start(args, msg); |
| 177 | vfprintf(stderr, msg, args); |
| 178 | va_end(args); |
| 179 | |
| 180 | xmlParserPrintFileContext(input); |
| 181 | } |
| 182 | |
| 183 | /** |
| 184 | * xmlParserValidityWarning: |
| 185 | * @ctx: an XML parser context |
| 186 | * @msg: the message to display/transmit |
| 187 | * @...: extra parameters for the message display |
| 188 | * |
| 189 | * Display and format a validity warning messages, gives file, line, |
| 190 | * position and extra parameters. |
| 191 | */ |
| 192 | void |
| 193 | xmlParserValidityWarning(void *ctx, const char *msg, ...) |
| 194 | { |
| 195 | xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; |
| 196 | xmlParserInputPtr input; |
| 197 | va_list args; |
| 198 | |
| 199 | input = ctxt->input; |
| 200 | if ((input->filename == NULL) && (ctxt->inputNr > 1)) |
| 201 | input = ctxt->inputTab[ctxt->inputNr - 2]; |
| 202 | |
| 203 | xmlParserPrintFileInfo(input); |
| 204 | |
| 205 | fprintf(stderr, "validity warning: "); |
| 206 | va_start(args, msg); |
| 207 | vfprintf(stderr, msg, args); |
| 208 | va_end(args); |
| 209 | |
| 210 | xmlParserPrintFileContext(input); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 211 | } |
Daniel Veillard | 97b5877 | 1998-10-20 06:14:16 +0000 | [diff] [blame] | 212 | |