blob: a67bdbd960f954af318c571ed1f4918c0b38699a [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 *
4 * Daniel Veillard <Daniel.Veillard@w3.org>
Daniel Veillard260a68f1998-08-13 03:39:55 +00005 */
6
7#include <stdio.h>
8#include <stdarg.h>
9#include "parser.h"
10
Daniel Veillard97b58771998-10-20 06:14:16 +000011/**
12 * xmlParserError:
13 * @ctxt: an XML parser context
14 * @msg: the message to display/transmit
15 * @...: extra parameters for the message display
16 *
17 * Display and format an error messages, gives file, line, position and
18 * extra parameters.
Daniel Veillard260a68f1998-08-13 03:39:55 +000019 */
Daniel Veillard97b58771998-10-20 06:14:16 +000020void
21xmlParserError(xmlParserCtxtPtr ctxt, const char *msg, ...)
22{
Daniel Veillard260a68f1998-08-13 03:39:55 +000023 const CHAR *cur, *base;
24 va_list args;
25 int n;
26
27 va_start(args, msg);
28 if (ctxt->input->filename)
29 fprintf(stderr, "%s:%d: ", ctxt->input->filename,
30 ctxt->input->line);
31 else
32 fprintf(stderr, "line %d: ", ctxt->input->line);
33
34 fprintf(stderr, "error: ");
35 vfprintf(stderr, msg, args);
36 va_end(ap);
37 cur = ctxt->input->cur;
38 base = ctxt->input->base;
39 while ((*cur == '\n') || (*cur == '\r')) {
40 cur--;
41 base--;
42 }
43 n = 0;
44 while ((n++ < 60) && (cur >= base) && (*cur != '\n') && (*cur != '\r'))
45 cur--;
46 if ((*cur == '\n') || (*cur == '\r')) cur++;
47 base = cur;
48 n = 0;
49 while ((*cur != 0) && (*cur != '\n') && (*cur != '\r') && (n < 79)) {
50 fprintf(stderr, "%c", (unsigned char) *cur++);
51 n++;
52 }
53 fprintf(stderr, "\n");
54 cur = ctxt->input->cur;
55 while ((*cur == '\n') || (*cur == '\r'))
56 cur--;
57 n = 0;
58 while ((cur != base) && (n++ < 60)) {
59 fprintf(stderr, " ");
60 base++;
61 }
62 fprintf(stderr,"^\n");
63}
64
Daniel Veillard97b58771998-10-20 06:14:16 +000065/**
66 * xmlParserWarning:
67 * @ctxt: an XML parser context
68 * @msg: the message to display/transmit
69 * @...: extra parameters for the message display
70 *
71 * Display and format a warning messages, gives file, line, position and
72 * extra parameters.
Daniel Veillard260a68f1998-08-13 03:39:55 +000073 */
Daniel Veillard97b58771998-10-20 06:14:16 +000074void
75xmlParserWarning(xmlParserCtxtPtr ctxt, const char *msg, ...)
76{
Daniel Veillard260a68f1998-08-13 03:39:55 +000077 const CHAR *cur, *base;
78 va_list args;
79 int n;
80
81 va_start(args, msg);
82 if (ctxt->input->filename)
83 fprintf(stderr, "%s:%d: ", ctxt->input->filename,
84 ctxt->input->line);
85 else
86 fprintf(stderr, "line %d: ", ctxt->input->line);
87
88 fprintf(stderr, "warning: ");
89 vfprintf(stderr, msg, args);
90 va_end(ap);
91 cur = ctxt->input->cur;
92 base = ctxt->input->base;
93 n = 0;
94 while ((n++ < 60) && (cur >= base) && (*cur != '\n') && (*cur != '\r'))
95 cur--;
96 if ((*cur != '\n') || (*cur != '\r')) cur++;
97 base = cur;
98 n = 0;
99 while ((*cur != 0) && (*cur != '\n') && (*cur != '\r') && (n < 79)) {
100 fprintf(stderr, "%c", (unsigned char) *cur++);
101 n++;
102 }
103 fprintf(stderr, "\n");
104 cur = ctxt->input->cur;
105 n = 0;
106 while ((cur != base) && (n++ < 60)) {
107 fprintf(stderr, " ");
108 base++;
109 }
110 fprintf(stderr,"^\n");
111}
Daniel Veillard97b58771998-10-20 06:14:16 +0000112