summaryrefslogtreecommitdiff
path: root/error.c
blob: a67bdbd960f954af318c571ed1f4918c0b38699a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/*
 * error.c: module displaying/handling XML parser errors
 *
 * Daniel Veillard <Daniel.Veillard@w3.org>
 */

#include <stdio.h>
#include <stdarg.h>
#include "parser.h"

/**
 * xmlParserError:
 * @ctxt:  an XML parser context
 * @msg:  the message to display/transmit
 * @...:  extra parameters for the message display
 * 
 * Display and format an error messages, gives file, line, position and
 * extra parameters.
 */
void
xmlParserError(xmlParserCtxtPtr ctxt, const char *msg, ...)
{
    const CHAR *cur, *base;
    va_list args;
    int n;

    va_start(args, msg);
    if (ctxt->input->filename)
        fprintf(stderr, "%s:%d: ", ctxt->input->filename,
	        ctxt->input->line);
    else
        fprintf(stderr, "line %d: ", ctxt->input->line);
        
    fprintf(stderr, "error: ");
    vfprintf(stderr, msg, args);
    va_end(ap);
    cur = ctxt->input->cur;
    base = ctxt->input->base;
    while ((*cur == '\n') || (*cur == '\r')) {
	cur--;
	base--;
    }
    n = 0;
    while ((n++ < 60) && (cur >= base) && (*cur != '\n') && (*cur != '\r'))
        cur--;
    if ((*cur == '\n') || (*cur == '\r')) cur++;
    base = cur;
    n = 0;
    while ((*cur != 0) && (*cur != '\n') && (*cur != '\r') && (n < 79)) {
        fprintf(stderr, "%c", (unsigned char) *cur++);
	n++;
    }
    fprintf(stderr, "\n");
    cur = ctxt->input->cur;
    while ((*cur == '\n') || (*cur == '\r'))
	cur--;
    n = 0;
    while ((cur != base) && (n++ < 60)) {
        fprintf(stderr, " ");
        base++;
    }
    fprintf(stderr,"^\n");
}

/**
 * xmlParserWarning:
 * @ctxt:  an XML parser context
 * @msg:  the message to display/transmit
 * @...:  extra parameters for the message display
 * 
 * Display and format a warning messages, gives file, line, position and
 * extra parameters.
 */
void
xmlParserWarning(xmlParserCtxtPtr ctxt, const char *msg, ...)
{
    const CHAR *cur, *base;
    va_list args;
    int n;

    va_start(args, msg);
    if (ctxt->input->filename)
        fprintf(stderr, "%s:%d: ", ctxt->input->filename,
	        ctxt->input->line);
    else
        fprintf(stderr, "line %d: ", ctxt->input->line);
        
    fprintf(stderr, "warning: ");
    vfprintf(stderr, msg, args);
    va_end(ap);
    cur = ctxt->input->cur;
    base = ctxt->input->base;
    n = 0;
    while ((n++ < 60) && (cur >= base) && (*cur != '\n') && (*cur != '\r'))
        cur--;
    if ((*cur != '\n') || (*cur != '\r')) cur++;
    base = cur;
    n = 0;
    while ((*cur != 0) && (*cur != '\n') && (*cur != '\r') && (n < 79)) {
        fprintf(stderr, "%c", (unsigned char) *cur++);
	n++;
    }
    fprintf(stderr, "\n");
    cur = ctxt->input->cur;
    n = 0;
    while ((cur != base) && (n++ < 60)) {
        fprintf(stderr, " ");
        base++;
    }
    fprintf(stderr,"^\n");
}