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