summaryrefslogtreecommitdiff
path: root/error.c
diff options
context:
space:
mode:
authorDaniel Veillard <veillard@src.gnome.org>1998-08-13 03:39:55 +0000
committerDaniel Veillard <veillard@src.gnome.org>1998-08-13 03:39:55 +0000
commit260a68fd34302f352aa8f4c2f2901cefa3e1d2f7 (patch)
tree4b8121b97a44fdb0e5c7713150af11074a69a1e2 /error.c
parenta65771c1cad93b33a936be986be043420adc9648 (diff)
downloadlibxml2-260a68fd34302f352aa8f4c2f2901cefa3e1d2f7.tar.gz
Release 0.2, 80% rewrite, nothing left intact ... Daniel
Diffstat (limited to 'error.c')
-rw-r--r--error.c93
1 files changed, 93 insertions, 0 deletions
diff --git a/error.c b/error.c
new file mode 100644
index 00000000..4c4bac5b
--- /dev/null
+++ b/error.c
@@ -0,0 +1,93 @@
+/*
+ * error.c: module displaying errors
+ */
+
+#include <stdio.h>
+#include <stdarg.h>
+#include "parser.h"
+
+/*
+ * Display and format error messages.
+ */
+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");
+}
+
+/*
+ * Display and format error messages.
+ */
+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");
+}