📄 xmllint.c
字号:
/* * xmllint.c : a small tester program for XML input. * * See Copyright for the status of this software. * * Daniel.Veillard@w3.org */#include "global.h"#ifdef WIN32#include "win32config.h"#else#include "config.h"#endif#include <stdio.h>#include <string.h>#include <stdio.h>#include <stdarg.h>#ifdef HAVE_SYS_TYPES_H#include <sys/types.h>#endif#ifdef HAVE_SYS_STAT_H#include <sys/stat.h>#endif#ifdef HAVE_FCNTL_H#include <fcntl.h>#endif#ifdef HAVE_UNISTD_H#include <unistd.h>#endif#ifdef HAVE_STDLIB_H#include <stdlib.h>#endif#ifdef HAVE_LIBREADLINE#include <readline/readline.h>#ifdef HAVE_LIBHISTORY#include <readline/history.h>#endif#endif#include <libxml/xmlmemory.h>#include <libxml/parser.h>#include <libxml/parserInternals.h>#include <libxml/HTMLparser.h>#include <libxml/HTMLtree.h>#include <libxml/tree.h>#include <libxml/xpath.h>#include <libxml/debugXML.h>#ifdef LIBXML_DEBUG_ENABLEDstatic int debug = 0;static int shell = 0;static int debugent = 0;#endifstatic int copy = 0;static int recovery = 0;static int noent = 0;static int noout = 0;static int nowrap = 0;static int valid = 0;static int postvalid = 0;static int repeat = 0;static int insert = 0;static int compress = 0;static int html = 0;static int htmlout = 0;static int push = 0;static int noblanks = 0;static int testIO = 0;extern int xmlDoValidityCheckingDefaultValue;extern int xmlGetWarningsDefaultValue;/************************************************************************ * * * HTML ouput * * * ************************************************************************/char buffer[50000];voidxmlHTMLEncodeSend(void) { char *result; result = (char *) xmlEncodeEntitiesReentrant(NULL, BAD_CAST buffer); if (result) { fprintf(stderr, "%s", result); xmlFree(result); } buffer[0] = 0;}/** * xmlHTMLPrintFileInfo: * @input: an xmlParserInputPtr input * * Displays the associated file and line informations for the current input */voidxmlHTMLPrintFileInfo(xmlParserInputPtr input) { fprintf(stderr, "<p>"); if (input != NULL) { if (input->filename) { sprintf(&buffer[strlen(buffer)], "%s:%d: ", input->filename, input->line); } else { sprintf(&buffer[strlen(buffer)], "Entity: line %d: ", input->line); } } xmlHTMLEncodeSend();}/** * xmlHTMLPrintFileContext: * @input: an xmlParserInputPtr input * * Displays current context within the input content for error tracking */voidxmlHTMLPrintFileContext(xmlParserInputPtr input) { const xmlChar *cur, *base; int n; if (input == NULL) return; fprintf(stderr, "<pre>\n"); cur = input->cur; base = input->base; while ((cur > base) && ((*cur == '\n') || (*cur == '\r'))) { cur--; } n = 0; while ((n++ < 80) && (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)) { sprintf(&buffer[strlen(buffer)], "%c", (unsigned char) *cur++); n++; } sprintf(&buffer[strlen(buffer)], "\n"); cur = input->cur; while ((*cur == '\n') || (*cur == '\r')) cur--; n = 0; while ((cur != base) && (n++ < 80)) { sprintf(&buffer[strlen(buffer)], " "); base++; } sprintf(&buffer[strlen(buffer)],"^\n"); xmlHTMLEncodeSend(); fprintf(stderr, "</pre>");}/** * xmlHTMLError: * @ctx: 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. */voidxmlHTMLError(void *ctx, const char *msg, ...){ xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; xmlParserInputPtr input; xmlParserInputPtr cur = NULL; va_list args; buffer[0] = 0; input = ctxt->input; if ((input != NULL) && (input->filename == NULL) && (ctxt->inputNr > 1)) { cur = input; input = ctxt->inputTab[ctxt->inputNr - 2]; } xmlHTMLPrintFileInfo(input); fprintf(stderr, "<b>error</b>: "); va_start(args, msg); vsprintf(&buffer[strlen(buffer)], msg, args); va_end(args); xmlHTMLEncodeSend(); fprintf(stderr, "</p>\n"); xmlHTMLPrintFileContext(input); xmlHTMLEncodeSend();}/** * xmlHTMLWarning: * @ctx: 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. */voidxmlHTMLWarning(void *ctx, const char *msg, ...){ xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; xmlParserInputPtr input; xmlParserInputPtr cur = NULL; va_list args; buffer[0] = 0; input = ctxt->input; if ((input != NULL) && (input->filename == NULL) && (ctxt->inputNr > 1)) { cur = input; input = ctxt->inputTab[ctxt->inputNr - 2]; } xmlHTMLPrintFileInfo(input); fprintf(stderr, "<b>warning</b>: "); va_start(args, msg); vsprintf(&buffer[strlen(buffer)], msg, args); va_end(args); xmlHTMLEncodeSend(); fprintf(stderr, "</p>\n"); xmlHTMLPrintFileContext(input); xmlHTMLEncodeSend();}/** * xmlHTMLValidityError: * @ctx: an XML parser context * @msg: the message to display/transmit * @...: extra parameters for the message display * * Display and format an validity error messages, gives file, * line, position and extra parameters. */voidxmlHTMLValidityError(void *ctx, const char *msg, ...){ xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; xmlParserInputPtr input; va_list args; buffer[0] = 0; input = ctxt->input; if ((input->filename == NULL) && (ctxt->inputNr > 1)) input = ctxt->inputTab[ctxt->inputNr - 2]; xmlHTMLPrintFileInfo(input); fprintf(stderr, "<b>validity error</b>: "); va_start(args, msg); vsprintf(&buffer[strlen(buffer)], msg, args); va_end(args); xmlHTMLEncodeSend(); fprintf(stderr, "</p>\n"); xmlHTMLPrintFileContext(input); xmlHTMLEncodeSend();}/** * xmlHTMLValidityWarning: * @ctx: an XML parser context * @msg: the message to display/transmit * @...: extra parameters for the message display * * Display and format a validity warning messages, gives file, line, * position and extra parameters. */voidxmlHTMLValidityWarning(void *ctx, const char *msg, ...){ xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; xmlParserInputPtr input; va_list args; buffer[0] = 0; input = ctxt->input; if ((input->filename == NULL) && (ctxt->inputNr > 1)) input = ctxt->inputTab[ctxt->inputNr - 2]; xmlHTMLPrintFileInfo(input); fprintf(stderr, "<b>validity warning</b>: "); va_start(args, msg); vsprintf(&buffer[strlen(buffer)], msg, args); va_end(args); xmlHTMLEncodeSend(); fprintf(stderr, "</p>\n"); xmlHTMLPrintFileContext(input); xmlHTMLEncodeSend();}/************************************************************************ * * * Shell Interface * * * ************************************************************************//** * xmlShellReadline: * @prompt: the prompt value * * Read a string * * Returns a pointer to it or NULL on EOF the caller is expected to * free the returned string. */char *xmlShellReadline(char *prompt) {#ifdef HAVE_LIBREADLINE char *line_read; /* Get a line from the user. */ line_read = readline (prompt); /* If the line has any text in it, save it on the history. */ if (line_read && *line_read) add_history (line_read); return (line_read);#else char line_read[501];
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -