blob: eb93d96e350a78010d26fef043ad29b10746b4c3 [file] [log] [blame]
Daniel Veillard260a68f1998-08-13 03:39:55 +00001/*
Daniel Veillard97b58771998-10-20 06:14:16 +00002 * error.c: module displaying/handling XML parser errors
3 *
Daniel Veillard39a1f9a1999-01-17 19:11:59 +00004 * See Copyright for the status of this software.
5 *
Daniel Veillard97b58771998-10-20 06:14:16 +00006 * Daniel Veillard <Daniel.Veillard@w3.org>
Daniel Veillard260a68f1998-08-13 03:39:55 +00007 */
8
9#include <stdio.h>
10#include <stdarg.h>
11#include "parser.h"
12
Daniel Veillard97b58771998-10-20 06:14:16 +000013/**
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 Veillard260a68f1998-08-13 03:39:55 +000021 */
Daniel Veillard97b58771998-10-20 06:14:16 +000022void
23xmlParserError(xmlParserCtxtPtr ctxt, const char *msg, ...)
24{
Daniel Veillard260a68f1998-08-13 03:39:55 +000025 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 Veillard97b58771998-10-20 06:14:16 +000067/**
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 Veillard260a68f1998-08-13 03:39:55 +000075 */
Daniel Veillard97b58771998-10-20 06:14:16 +000076void
77xmlParserWarning(xmlParserCtxtPtr ctxt, const char *msg, ...)
78{
Daniel Veillard260a68f1998-08-13 03:39:55 +000079 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 Veillard97b58771998-10-20 06:14:16 +0000114