Some infrastructure work, and of course some debug:
[platform/upstream/libxslt.git] / libxslt / xsltutils.c
1 /*
2  * xsltutils.c: Utilities for the XSL Transformation 1.0 engine
3  *
4  * Reference:
5  *   http://www.w3.org/TR/1999/REC-xslt-19991116
6  *
7  * See Copyright for the status of this software.
8  *
9  * Daniel.Veillard@imag.fr
10  */
11
12 #include "xsltconfig.h"
13
14 #include <stdio.h>
15 #include <stdarg.h>
16
17 #include <libxml/xmlmemory.h>
18 #include <libxml/tree.h>
19 #include <libxml/xmlerror.h>
20 #include "xsltutils.h"
21
22
23 /************************************************************************
24  *                                                                      *
25  *              Handling of out of context errors                       *
26  *                                                                      *
27  ************************************************************************/
28
29 /**
30  * xsltGenericErrorDefaultFunc:
31  * @ctx:  an error context
32  * @msg:  the message to display/transmit
33  * @...:  extra parameters for the message display
34  * 
35  * Default handler for out of context error messages.
36  */
37 void
38 xsltGenericErrorDefaultFunc(void *ctx, const char *msg, ...) {
39     va_list args;
40
41     if (xsltGenericErrorContext == NULL)
42         xsltGenericErrorContext = (void *) stderr;
43
44     va_start(args, msg);
45     vfprintf((FILE *)xsltGenericErrorContext, msg, args);
46     va_end(args);
47 }
48
49 xmlGenericErrorFunc xsltGenericError = xsltGenericErrorDefaultFunc;
50 void *xsltGenericErrorContext = NULL;
51
52
53 /**
54  * xsltSetGenericErrorFunc:
55  * @ctx:  the new error handling context
56  * @handler:  the new handler function
57  *
58  * Function to reset the handler and the error context for out of
59  * context error messages.
60  * This simply means that @handler will be called for subsequent
61  * error messages while not parsing nor validating. And @ctx will
62  * be passed as first argument to @handler
63  * One can simply force messages to be emitted to another FILE * than
64  * stderr by setting @ctx to this file handle and @handler to NULL.
65  */
66 void
67 xsltSetGenericErrorFunc(void *ctx, xmlGenericErrorFunc handler) {
68     xsltGenericErrorContext = ctx;
69     if (handler != NULL)
70         xsltGenericError = handler;
71     else
72         xsltGenericError = xsltGenericErrorDefaultFunc;
73 }
74
75 /**
76  * xsltGenericDebugDefaultFunc:
77  * @ctx:  an error context
78  * @msg:  the message to display/transmit
79  * @...:  extra parameters for the message display
80  * 
81  * Default handler for out of context error messages.
82  */
83 void
84 xsltGenericDebugDefaultFunc(void *ctx, const char *msg, ...) {
85     va_list args;
86
87     if (xsltGenericDebugContext == NULL)
88         return;
89
90     va_start(args, msg);
91     vfprintf((FILE *)xsltGenericDebugContext, msg, args);
92     va_end(args);
93 }
94
95 xmlGenericErrorFunc xsltGenericDebug = xsltGenericDebugDefaultFunc;
96 void *xsltGenericDebugContext = NULL;
97
98
99 /**
100  * xsltSetGenericDebugFunc:
101  * @ctx:  the new error handling context
102  * @handler:  the new handler function
103  *
104  * Function to reset the handler and the error context for out of
105  * context error messages.
106  * This simply means that @handler will be called for subsequent
107  * error messages while not parsing nor validating. And @ctx will
108  * be passed as first argument to @handler
109  * One can simply force messages to be emitted to another FILE * than
110  * stderr by setting @ctx to this file handle and @handler to NULL.
111  */
112 void
113 xsltSetGenericDebugFunc(void *ctx, xmlGenericErrorFunc handler) {
114     xsltGenericDebugContext = ctx;
115     if (handler != NULL)
116         xsltGenericDebug = handler;
117     else
118         xsltGenericDebug = xsltGenericDebugDefaultFunc;
119 }
120