Blame debugXML.c

Packit Service a31ea6
/*
Packit Service a31ea6
 * debugXML.c : This is a set of routines used for debugging the tree
Packit Service a31ea6
 *              produced by the XML parser.
Packit Service a31ea6
 *
Packit Service a31ea6
 * See Copyright for the status of this software.
Packit Service a31ea6
 *
Packit Service a31ea6
 * Daniel Veillard <daniel@veillard.com>
Packit Service a31ea6
 */
Packit Service a31ea6
Packit Service a31ea6
#define IN_LIBXML
Packit Service a31ea6
#include "libxml.h"
Packit Service a31ea6
#ifdef LIBXML_DEBUG_ENABLED
Packit Service a31ea6
Packit Service a31ea6
#include <string.h>
Packit Service a31ea6
#ifdef HAVE_STDLIB_H
Packit Service a31ea6
#include <stdlib.h>
Packit Service a31ea6
#endif
Packit Service a31ea6
#ifdef HAVE_STRING_H
Packit Service a31ea6
#include <string.h>
Packit Service a31ea6
#endif
Packit Service a31ea6
#include <libxml/xmlmemory.h>
Packit Service a31ea6
#include <libxml/tree.h>
Packit Service a31ea6
#include <libxml/parser.h>
Packit Service a31ea6
#include <libxml/parserInternals.h>
Packit Service a31ea6
#include <libxml/valid.h>
Packit Service a31ea6
#include <libxml/debugXML.h>
Packit Service a31ea6
#include <libxml/HTMLtree.h>
Packit Service a31ea6
#include <libxml/HTMLparser.h>
Packit Service a31ea6
#include <libxml/xmlerror.h>
Packit Service a31ea6
#include <libxml/globals.h>
Packit Service a31ea6
#include <libxml/xpathInternals.h>
Packit Service a31ea6
#include <libxml/uri.h>
Packit Service a31ea6
#ifdef LIBXML_SCHEMAS_ENABLED
Packit Service a31ea6
#include <libxml/relaxng.h>
Packit Service a31ea6
#endif
Packit Service a31ea6
Packit Service a31ea6
#define DUMP_TEXT_TYPE 1
Packit Service a31ea6
Packit Service a31ea6
typedef struct _xmlDebugCtxt xmlDebugCtxt;
Packit Service a31ea6
typedef xmlDebugCtxt *xmlDebugCtxtPtr;
Packit Service a31ea6
struct _xmlDebugCtxt {
Packit Service a31ea6
    FILE *output;               /* the output file */
Packit Service a31ea6
    char shift[101];            /* used for indenting */
Packit Service a31ea6
    int depth;                  /* current depth */
Packit Service a31ea6
    xmlDocPtr doc;              /* current document */
Packit Service a31ea6
    xmlNodePtr node;		/* current node */
Packit Service a31ea6
    xmlDictPtr dict;		/* the doc dictionary */
Packit Service a31ea6
    int check;                  /* do just checkings */
Packit Service a31ea6
    int errors;                 /* number of errors found */
Packit Service a31ea6
    int nodict;			/* if the document has no dictionary */
Packit Service a31ea6
    int options;		/* options */
Packit Service a31ea6
};
Packit Service a31ea6
Packit Service a31ea6
static void xmlCtxtDumpNodeList(xmlDebugCtxtPtr ctxt, xmlNodePtr node);
Packit Service a31ea6
Packit Service a31ea6
static void
Packit Service a31ea6
xmlCtxtDumpInitCtxt(xmlDebugCtxtPtr ctxt)
Packit Service a31ea6
{
Packit Service a31ea6
    int i;
Packit Service a31ea6
Packit Service a31ea6
    ctxt->depth = 0;
Packit Service a31ea6
    ctxt->check = 0;
Packit Service a31ea6
    ctxt->errors = 0;
Packit Service a31ea6
    ctxt->output = stdout;
Packit Service a31ea6
    ctxt->doc = NULL;
Packit Service a31ea6
    ctxt->node = NULL;
Packit Service a31ea6
    ctxt->dict = NULL;
Packit Service a31ea6
    ctxt->nodict = 0;
Packit Service a31ea6
    ctxt->options = 0;
Packit Service a31ea6
    for (i = 0; i < 100; i++)
Packit Service a31ea6
        ctxt->shift[i] = ' ';
Packit Service a31ea6
    ctxt->shift[100] = 0;
Packit Service a31ea6
}
Packit Service a31ea6
Packit Service a31ea6
static void
Packit Service a31ea6
xmlCtxtDumpCleanCtxt(xmlDebugCtxtPtr ctxt ATTRIBUTE_UNUSED)
Packit Service a31ea6
{
Packit Service a31ea6
 /* remove the ATTRIBUTE_UNUSED when this is added */
Packit Service a31ea6
}
Packit Service a31ea6
Packit Service a31ea6
/**
Packit Service a31ea6
 * xmlNsCheckScope:
Packit Service a31ea6
 * @node: the node
Packit Service a31ea6
 * @ns: the namespace node
Packit Service a31ea6
 *
Packit Service a31ea6
 * Check that a given namespace is in scope on a node.
Packit Service a31ea6
 *
Packit Service a31ea6
 * Returns 1 if in scope, -1 in case of argument error,
Packit Service a31ea6
 *         -2 if the namespace is not in scope, and -3 if not on
Packit Service a31ea6
 *         an ancestor node.
Packit Service a31ea6
 */
Packit Service a31ea6
static int
Packit Service a31ea6
xmlNsCheckScope(xmlNodePtr node, xmlNsPtr ns)
Packit Service a31ea6
{
Packit Service a31ea6
    xmlNsPtr cur;
Packit Service a31ea6
Packit Service a31ea6
    if ((node == NULL) || (ns == NULL))
Packit Service a31ea6
        return(-1);
Packit Service a31ea6
Packit Service a31ea6
    if ((node->type != XML_ELEMENT_NODE) &&
Packit Service a31ea6
	(node->type != XML_ATTRIBUTE_NODE) &&
Packit Service a31ea6
	(node->type != XML_DOCUMENT_NODE) &&
Packit Service a31ea6
	(node->type != XML_TEXT_NODE) &&
Packit Service a31ea6
	(node->type != XML_HTML_DOCUMENT_NODE) &&
Packit Service a31ea6
	(node->type != XML_XINCLUDE_START))
Packit Service a31ea6
	return(-2);
Packit Service a31ea6
Packit Service a31ea6
    while ((node != NULL) &&
Packit Service a31ea6
           ((node->type == XML_ELEMENT_NODE) ||
Packit Service a31ea6
            (node->type == XML_ATTRIBUTE_NODE) ||
Packit Service a31ea6
            (node->type == XML_TEXT_NODE) ||
Packit Service a31ea6
	    (node->type == XML_XINCLUDE_START))) {
Packit Service a31ea6
	if ((node->type == XML_ELEMENT_NODE) ||
Packit Service a31ea6
	    (node->type == XML_XINCLUDE_START)) {
Packit Service a31ea6
	    cur = node->nsDef;
Packit Service a31ea6
	    while (cur != NULL) {
Packit Service a31ea6
	        if (cur == ns)
Packit Service a31ea6
		    return(1);
Packit Service a31ea6
		if (xmlStrEqual(cur->prefix, ns->prefix))
Packit Service a31ea6
		    return(-2);
Packit Service a31ea6
		cur = cur->next;
Packit Service a31ea6
	    }
Packit Service a31ea6
	}
Packit Service a31ea6
	node = node->parent;
Packit Service a31ea6
    }
Packit Service a31ea6
    /* the xml namespace may be declared on the document node */
Packit Service a31ea6
    if ((node != NULL) &&
Packit Service a31ea6
        ((node->type == XML_DOCUMENT_NODE) ||
Packit Service a31ea6
	 (node->type == XML_HTML_DOCUMENT_NODE))) {
Packit Service a31ea6
	 xmlNsPtr oldNs = ((xmlDocPtr) node)->oldNs;
Packit Service a31ea6
	 if (oldNs == ns)
Packit Service a31ea6
	     return(1);
Packit Service a31ea6
    }
Packit Service a31ea6
    return(-3);
Packit Service a31ea6
}
Packit Service a31ea6
Packit Service a31ea6
static void
Packit Service a31ea6
xmlCtxtDumpSpaces(xmlDebugCtxtPtr ctxt)
Packit Service a31ea6
{
Packit Service a31ea6
    if (ctxt->check)
Packit Service a31ea6
        return;
Packit Service a31ea6
    if ((ctxt->output != NULL) && (ctxt->depth > 0)) {
Packit Service a31ea6
        if (ctxt->depth < 50)
Packit Service a31ea6
            fprintf(ctxt->output, "%s", &ctxt->shift[100 - 2 * ctxt->depth]);
Packit Service a31ea6
        else
Packit Service a31ea6
            fprintf(ctxt->output, "%s", ctxt->shift);
Packit Service a31ea6
    }
Packit Service a31ea6
}
Packit Service a31ea6
Packit Service a31ea6
/**
Packit Service a31ea6
 * xmlDebugErr:
Packit Service a31ea6
 * @ctxt:  a debug context
Packit Service a31ea6
 * @error:  the error code
Packit Service a31ea6
 *
Packit Service a31ea6
 * Handle a debug error.
Packit Service a31ea6
 */
Packit Service a31ea6
static void
Packit Service a31ea6
xmlDebugErr(xmlDebugCtxtPtr ctxt, int error, const char *msg)
Packit Service a31ea6
{
Packit Service a31ea6
    ctxt->errors++;
Packit Service a31ea6
    __xmlRaiseError(NULL, NULL, NULL,
Packit Service a31ea6
		    NULL, ctxt->node, XML_FROM_CHECK,
Packit Service a31ea6
		    error, XML_ERR_ERROR, NULL, 0,
Packit Service a31ea6
		    NULL, NULL, NULL, 0, 0,
Packit Service a31ea6
		    "%s", msg);
Packit Service a31ea6
}
Packit Service a31ea6
static void LIBXML_ATTR_FORMAT(3,0)
Packit Service a31ea6
xmlDebugErr2(xmlDebugCtxtPtr ctxt, int error, const char *msg, int extra)
Packit Service a31ea6
{
Packit Service a31ea6
    ctxt->errors++;
Packit Service a31ea6
    __xmlRaiseError(NULL, NULL, NULL,
Packit Service a31ea6
		    NULL, ctxt->node, XML_FROM_CHECK,
Packit Service a31ea6
		    error, XML_ERR_ERROR, NULL, 0,
Packit Service a31ea6
		    NULL, NULL, NULL, 0, 0,
Packit Service a31ea6
		    msg, extra);
Packit Service a31ea6
}
Packit Service a31ea6
static void LIBXML_ATTR_FORMAT(3,0)
Packit Service a31ea6
xmlDebugErr3(xmlDebugCtxtPtr ctxt, int error, const char *msg, const char *extra)
Packit Service a31ea6
{
Packit Service a31ea6
    ctxt->errors++;
Packit Service a31ea6
    __xmlRaiseError(NULL, NULL, NULL,
Packit Service a31ea6
		    NULL, ctxt->node, XML_FROM_CHECK,
Packit Service a31ea6
		    error, XML_ERR_ERROR, NULL, 0,
Packit Service a31ea6
		    NULL, NULL, NULL, 0, 0,
Packit Service a31ea6
		    msg, extra);
Packit Service a31ea6
}
Packit Service a31ea6
Packit Service a31ea6
/**
Packit Service a31ea6
 * xmlCtxtNsCheckScope:
Packit Service a31ea6
 * @ctxt: the debugging context
Packit Service a31ea6
 * @node: the node
Packit Service a31ea6
 * @ns: the namespace node
Packit Service a31ea6
 *
Packit Service a31ea6
 * Report if a given namespace is is not in scope.
Packit Service a31ea6
 */
Packit Service a31ea6
static void
Packit Service a31ea6
xmlCtxtNsCheckScope(xmlDebugCtxtPtr ctxt, xmlNodePtr node, xmlNsPtr ns)
Packit Service a31ea6
{
Packit Service a31ea6
    int ret;
Packit Service a31ea6
Packit Service a31ea6
    ret = xmlNsCheckScope(node, ns);
Packit Service a31ea6
    if (ret == -2) {
Packit Service a31ea6
        if (ns->prefix == NULL)
Packit Service a31ea6
	    xmlDebugErr(ctxt, XML_CHECK_NS_SCOPE,
Packit Service a31ea6
			"Reference to default namespace not in scope\n");
Packit Service a31ea6
	else
Packit Service a31ea6
	    xmlDebugErr3(ctxt, XML_CHECK_NS_SCOPE,
Packit Service a31ea6
			 "Reference to namespace '%s' not in scope\n",
Packit Service a31ea6
			 (char *) ns->prefix);
Packit Service a31ea6
    }
Packit Service a31ea6
    if (ret == -3) {
Packit Service a31ea6
        if (ns->prefix == NULL)
Packit Service a31ea6
	    xmlDebugErr(ctxt, XML_CHECK_NS_ANCESTOR,
Packit Service a31ea6
			"Reference to default namespace not on ancestor\n");
Packit Service a31ea6
	else
Packit Service a31ea6
	    xmlDebugErr3(ctxt, XML_CHECK_NS_ANCESTOR,
Packit Service a31ea6
			 "Reference to namespace '%s' not on ancestor\n",
Packit Service a31ea6
			 (char *) ns->prefix);
Packit Service a31ea6
    }
Packit Service a31ea6
}
Packit Service a31ea6
Packit Service a31ea6
/**
Packit Service a31ea6
 * xmlCtxtCheckString:
Packit Service a31ea6
 * @ctxt: the debug context
Packit Service a31ea6
 * @str: the string
Packit Service a31ea6
 *
Packit Service a31ea6
 * Do debugging on the string, currently it just checks the UTF-8 content
Packit Service a31ea6
 */
Packit Service a31ea6
static void
Packit Service a31ea6
xmlCtxtCheckString(xmlDebugCtxtPtr ctxt, const xmlChar * str)
Packit Service a31ea6
{
Packit Service a31ea6
    if (str == NULL) return;
Packit Service a31ea6
    if (ctxt->check) {
Packit Service a31ea6
        if (!xmlCheckUTF8(str)) {
Packit Service a31ea6
	    xmlDebugErr3(ctxt, XML_CHECK_NOT_UTF8,
Packit Service a31ea6
			 "String is not UTF-8 %s", (const char *) str);
Packit Service a31ea6
	}
Packit Service a31ea6
    }
Packit Service a31ea6
}
Packit Service a31ea6
Packit Service a31ea6
/**
Packit Service a31ea6
 * xmlCtxtCheckName:
Packit Service a31ea6
 * @ctxt: the debug context
Packit Service a31ea6
 * @name: the name
Packit Service a31ea6
 *
Packit Service a31ea6
 * Do debugging on the name, for example the dictionary status and
Packit Service a31ea6
 * conformance to the Name production.
Packit Service a31ea6
 */
Packit Service a31ea6
static void
Packit Service a31ea6
xmlCtxtCheckName(xmlDebugCtxtPtr ctxt, const xmlChar * name)
Packit Service a31ea6
{
Packit Service a31ea6
    if (ctxt->check) {
Packit Service a31ea6
	if (name == NULL) {
Packit Service a31ea6
	    xmlDebugErr(ctxt, XML_CHECK_NO_NAME, "Name is NULL");
Packit Service a31ea6
	    return;
Packit Service a31ea6
	}
Packit Service a31ea6
#if defined(LIBXML_TREE_ENABLED) || defined(LIBXML_SCHEMAS_ENABLED)
Packit Service a31ea6
        if (xmlValidateName(name, 0)) {
Packit Service a31ea6
	    xmlDebugErr3(ctxt, XML_CHECK_NOT_NCNAME,
Packit Service a31ea6
			 "Name is not an NCName '%s'", (const char *) name);
Packit Service a31ea6
	}
Packit Service a31ea6
#endif
Packit Service a31ea6
	if ((ctxt->dict != NULL) &&
Packit Service a31ea6
	    (!xmlDictOwns(ctxt->dict, name)) &&
Packit Service a31ea6
            ((ctxt->doc == NULL) ||
Packit Service a31ea6
             ((ctxt->doc->parseFlags & (XML_PARSE_SAX1 | XML_PARSE_NODICT)) == 0))) {
Packit Service a31ea6
	    xmlDebugErr3(ctxt, XML_CHECK_OUTSIDE_DICT,
Packit Service a31ea6
			 "Name is not from the document dictionary '%s'",
Packit Service a31ea6
			 (const char *) name);
Packit Service a31ea6
	}
Packit Service a31ea6
    }
Packit Service a31ea6
}
Packit Service a31ea6
Packit Service a31ea6
static void
Packit Service a31ea6
xmlCtxtGenericNodeCheck(xmlDebugCtxtPtr ctxt, xmlNodePtr node) {
Packit Service a31ea6
    xmlDocPtr doc;
Packit Service a31ea6
    xmlDictPtr dict;
Packit Service a31ea6
Packit Service a31ea6
    doc = node->doc;
Packit Service a31ea6
Packit Service a31ea6
    if (node->parent == NULL)
Packit Service a31ea6
        xmlDebugErr(ctxt, XML_CHECK_NO_PARENT,
Packit Service a31ea6
	            "Node has no parent\n");
Packit Service a31ea6
    if (node->doc == NULL) {
Packit Service a31ea6
        xmlDebugErr(ctxt, XML_CHECK_NO_DOC,
Packit Service a31ea6
	            "Node has no doc\n");
Packit Service a31ea6
        dict = NULL;
Packit Service a31ea6
    } else {
Packit Service a31ea6
	dict = doc->dict;
Packit Service a31ea6
	if ((dict == NULL) && (ctxt->nodict == 0)) {
Packit Service a31ea6
#if 0
Packit Service a31ea6
            /* desactivated right now as it raises too many errors */
Packit Service a31ea6
	    if (doc->type == XML_DOCUMENT_NODE)
Packit Service a31ea6
		xmlDebugErr(ctxt, XML_CHECK_NO_DICT,
Packit Service a31ea6
			    "Document has no dictionary\n");
Packit Service a31ea6
#endif
Packit Service a31ea6
	    ctxt->nodict = 1;
Packit Service a31ea6
	}
Packit Service a31ea6
	if (ctxt->doc == NULL)
Packit Service a31ea6
	    ctxt->doc = doc;
Packit Service a31ea6
Packit Service a31ea6
	if (ctxt->dict == NULL) {
Packit Service a31ea6
	    ctxt->dict = dict;
Packit Service a31ea6
	}
Packit Service a31ea6
    }
Packit Service a31ea6
    if ((node->parent != NULL) && (node->doc != node->parent->doc) &&
Packit Service a31ea6
        (!xmlStrEqual(node->name, BAD_CAST "pseudoroot")))
Packit Service a31ea6
        xmlDebugErr(ctxt, XML_CHECK_WRONG_DOC,
Packit Service a31ea6
	            "Node doc differs from parent's one\n");
Packit Service a31ea6
    if (node->prev == NULL) {
Packit Service a31ea6
        if (node->type == XML_ATTRIBUTE_NODE) {
Packit Service a31ea6
	    if ((node->parent != NULL) &&
Packit Service a31ea6
	        (node != (xmlNodePtr) node->parent->properties))
Packit Service a31ea6
		xmlDebugErr(ctxt, XML_CHECK_NO_PREV,
Packit Service a31ea6
                    "Attr has no prev and not first of attr list\n");
Packit Service a31ea6
Packit Service a31ea6
        } else if ((node->parent != NULL) && (node->parent->children != node))
Packit Service a31ea6
	    xmlDebugErr(ctxt, XML_CHECK_NO_PREV,
Packit Service a31ea6
                    "Node has no prev and not first of parent list\n");
Packit Service a31ea6
    } else {
Packit Service a31ea6
        if (node->prev->next != node)
Packit Service a31ea6
	    xmlDebugErr(ctxt, XML_CHECK_WRONG_PREV,
Packit Service a31ea6
                        "Node prev->next : back link wrong\n");
Packit Service a31ea6
    }
Packit Service a31ea6
    if (node->next == NULL) {
Packit Service a31ea6
	if ((node->parent != NULL) && (node->type != XML_ATTRIBUTE_NODE) &&
Packit Service a31ea6
	    (node->parent->last != node) &&
Packit Service a31ea6
	    (node->parent->type == XML_ELEMENT_NODE))
Packit Service a31ea6
	    xmlDebugErr(ctxt, XML_CHECK_NO_NEXT,
Packit Service a31ea6
                    "Node has no next and not last of parent list\n");
Packit Service a31ea6
    } else {
Packit Service a31ea6
        if (node->next->prev != node)
Packit Service a31ea6
	    xmlDebugErr(ctxt, XML_CHECK_WRONG_NEXT,
Packit Service a31ea6
                    "Node next->prev : forward link wrong\n");
Packit Service a31ea6
        if (node->next->parent != node->parent)
Packit Service a31ea6
	    xmlDebugErr(ctxt, XML_CHECK_WRONG_PARENT,
Packit Service a31ea6
                    "Node next->prev : forward link wrong\n");
Packit Service a31ea6
    }
Packit Service a31ea6
    if (node->type == XML_ELEMENT_NODE) {
Packit Service a31ea6
        xmlNsPtr ns;
Packit Service a31ea6
Packit Service a31ea6
	ns = node->nsDef;
Packit Service a31ea6
	while (ns != NULL) {
Packit Service a31ea6
	    xmlCtxtNsCheckScope(ctxt, node, ns);
Packit Service a31ea6
	    ns = ns->next;
Packit Service a31ea6
	}
Packit Service a31ea6
	if (node->ns != NULL)
Packit Service a31ea6
	    xmlCtxtNsCheckScope(ctxt, node, node->ns);
Packit Service a31ea6
    } else if (node->type == XML_ATTRIBUTE_NODE) {
Packit Service a31ea6
	if (node->ns != NULL)
Packit Service a31ea6
	    xmlCtxtNsCheckScope(ctxt, node, node->ns);
Packit Service a31ea6
    }
Packit Service a31ea6
Packit Service a31ea6
    if ((node->type != XML_ELEMENT_NODE) &&
Packit Service a31ea6
	(node->type != XML_ATTRIBUTE_NODE) &&
Packit Service a31ea6
	(node->type != XML_ELEMENT_DECL) &&
Packit Service a31ea6
	(node->type != XML_ATTRIBUTE_DECL) &&
Packit Service a31ea6
	(node->type != XML_DTD_NODE) &&
Packit Service a31ea6
	(node->type != XML_HTML_DOCUMENT_NODE) &&
Packit Service a31ea6
	(node->type != XML_DOCUMENT_NODE)) {
Packit Service a31ea6
	if (node->content != NULL)
Packit Service a31ea6
	    xmlCtxtCheckString(ctxt, (const xmlChar *) node->content);
Packit Service a31ea6
    }
Packit Service a31ea6
    switch (node->type) {
Packit Service a31ea6
        case XML_ELEMENT_NODE:
Packit Service a31ea6
        case XML_ATTRIBUTE_NODE:
Packit Service a31ea6
	    xmlCtxtCheckName(ctxt, node->name);
Packit Service a31ea6
	    break;
Packit Service a31ea6
        case XML_TEXT_NODE:
Packit Service a31ea6
	    if ((node->name == xmlStringText) ||
Packit Service a31ea6
	        (node->name == xmlStringTextNoenc))
Packit Service a31ea6
		break;
Packit Service a31ea6
	    /* some case of entity substitution can lead to this */
Packit Service a31ea6
	    if ((ctxt->dict != NULL) &&
Packit Service a31ea6
	        (node->name == xmlDictLookup(ctxt->dict, BAD_CAST "nbktext",
Packit Service a31ea6
		                             7)))
Packit Service a31ea6
		break;
Packit Service a31ea6
Packit Service a31ea6
	    xmlDebugErr3(ctxt, XML_CHECK_WRONG_NAME,
Packit Service a31ea6
			 "Text node has wrong name '%s'",
Packit Service a31ea6
			 (const char *) node->name);
Packit Service a31ea6
	    break;
Packit Service a31ea6
        case XML_COMMENT_NODE:
Packit Service a31ea6
	    if (node->name == xmlStringComment)
Packit Service a31ea6
		break;
Packit Service a31ea6
	    xmlDebugErr3(ctxt, XML_CHECK_WRONG_NAME,
Packit Service a31ea6
			 "Comment node has wrong name '%s'",
Packit Service a31ea6
			 (const char *) node->name);
Packit Service a31ea6
	    break;
Packit Service a31ea6
        case XML_PI_NODE:
Packit Service a31ea6
	    xmlCtxtCheckName(ctxt, node->name);
Packit Service a31ea6
	    break;
Packit Service a31ea6
        case XML_CDATA_SECTION_NODE:
Packit Service a31ea6
	    if (node->name == NULL)
Packit Service a31ea6
		break;
Packit Service a31ea6
	    xmlDebugErr3(ctxt, XML_CHECK_NAME_NOT_NULL,
Packit Service a31ea6
			 "CData section has non NULL name '%s'",
Packit Service a31ea6
			 (const char *) node->name);
Packit Service a31ea6
	    break;
Packit Service a31ea6
        case XML_ENTITY_REF_NODE:
Packit Service a31ea6
        case XML_ENTITY_NODE:
Packit Service a31ea6
        case XML_DOCUMENT_TYPE_NODE:
Packit Service a31ea6
        case XML_DOCUMENT_FRAG_NODE:
Packit Service a31ea6
        case XML_NOTATION_NODE:
Packit Service a31ea6
        case XML_DTD_NODE:
Packit Service a31ea6
        case XML_ELEMENT_DECL:
Packit Service a31ea6
        case XML_ATTRIBUTE_DECL:
Packit Service a31ea6
        case XML_ENTITY_DECL:
Packit Service a31ea6
        case XML_NAMESPACE_DECL:
Packit Service a31ea6
        case XML_XINCLUDE_START:
Packit Service a31ea6
        case XML_XINCLUDE_END:
Packit Service a31ea6
#ifdef LIBXML_DOCB_ENABLED
Packit Service a31ea6
        case XML_DOCB_DOCUMENT_NODE:
Packit Service a31ea6
#endif
Packit Service a31ea6
        case XML_DOCUMENT_NODE:
Packit Service a31ea6
        case XML_HTML_DOCUMENT_NODE:
Packit Service a31ea6
	    break;
Packit Service a31ea6
    }
Packit Service a31ea6
}
Packit Service a31ea6
Packit Service a31ea6
static void
Packit Service a31ea6
xmlCtxtDumpString(xmlDebugCtxtPtr ctxt, const xmlChar * str)
Packit Service a31ea6
{
Packit Service a31ea6
    int i;
Packit Service a31ea6
Packit Service a31ea6
    if (ctxt->check) {
Packit Service a31ea6
        return;
Packit Service a31ea6
    }
Packit Service a31ea6
    /* TODO: check UTF8 content of the string */
Packit Service a31ea6
    if (str == NULL) {
Packit Service a31ea6
        fprintf(ctxt->output, "(NULL)");
Packit Service a31ea6
        return;
Packit Service a31ea6
    }
Packit Service a31ea6
    for (i = 0; i < 40; i++)
Packit Service a31ea6
        if (str[i] == 0)
Packit Service a31ea6
            return;
Packit Service a31ea6
        else if (IS_BLANK_CH(str[i]))
Packit Service a31ea6
            fputc(' ', ctxt->output);
Packit Service a31ea6
        else if (str[i] >= 0x80)
Packit Service a31ea6
            fprintf(ctxt->output, "#%X", str[i]);
Packit Service a31ea6
        else
Packit Service a31ea6
            fputc(str[i], ctxt->output);
Packit Service a31ea6
    fprintf(ctxt->output, "...");
Packit Service a31ea6
}
Packit Service a31ea6
Packit Service a31ea6
static void
Packit Service a31ea6
xmlCtxtDumpDtdNode(xmlDebugCtxtPtr ctxt, xmlDtdPtr dtd)
Packit Service a31ea6
{
Packit Service a31ea6
    xmlCtxtDumpSpaces(ctxt);
Packit Service a31ea6
Packit Service a31ea6
    if (dtd == NULL) {
Packit Service a31ea6
        if (!ctxt->check)
Packit Service a31ea6
            fprintf(ctxt->output, "DTD node is NULL\n");
Packit Service a31ea6
        return;
Packit Service a31ea6
    }
Packit Service a31ea6
Packit Service a31ea6
    if (dtd->type != XML_DTD_NODE) {
Packit Service a31ea6
	xmlDebugErr(ctxt, XML_CHECK_NOT_DTD,
Packit Service a31ea6
	            "Node is not a DTD");
Packit Service a31ea6
        return;
Packit Service a31ea6
    }
Packit Service a31ea6
    if (!ctxt->check) {
Packit Service a31ea6
        if (dtd->name != NULL)
Packit Service a31ea6
            fprintf(ctxt->output, "DTD(%s)", (char *) dtd->name);
Packit Service a31ea6
        else
Packit Service a31ea6
            fprintf(ctxt->output, "DTD");
Packit Service a31ea6
        if (dtd->ExternalID != NULL)
Packit Service a31ea6
            fprintf(ctxt->output, ", PUBLIC %s", (char *) dtd->ExternalID);
Packit Service a31ea6
        if (dtd->SystemID != NULL)
Packit Service a31ea6
            fprintf(ctxt->output, ", SYSTEM %s", (char *) dtd->SystemID);
Packit Service a31ea6
        fprintf(ctxt->output, "\n");
Packit Service a31ea6
    }
Packit Service a31ea6
    /*
Packit Service a31ea6
     * Do a bit of checking
Packit Service a31ea6
     */
Packit Service a31ea6
    xmlCtxtGenericNodeCheck(ctxt, (xmlNodePtr) dtd);
Packit Service a31ea6
}
Packit Service a31ea6
Packit Service a31ea6
static void
Packit Service a31ea6
xmlCtxtDumpAttrDecl(xmlDebugCtxtPtr ctxt, xmlAttributePtr attr)
Packit Service a31ea6
{
Packit Service a31ea6
    xmlCtxtDumpSpaces(ctxt);
Packit Service a31ea6
Packit Service a31ea6
    if (attr == NULL) {
Packit Service a31ea6
        if (!ctxt->check)
Packit Service a31ea6
            fprintf(ctxt->output, "Attribute declaration is NULL\n");
Packit Service a31ea6
        return;
Packit Service a31ea6
    }
Packit Service a31ea6
    if (attr->type != XML_ATTRIBUTE_DECL) {
Packit Service a31ea6
	xmlDebugErr(ctxt, XML_CHECK_NOT_ATTR_DECL,
Packit Service a31ea6
	            "Node is not an attribute declaration");
Packit Service a31ea6
        return;
Packit Service a31ea6
    }
Packit Service a31ea6
    if (attr->name != NULL) {
Packit Service a31ea6
        if (!ctxt->check)
Packit Service a31ea6
            fprintf(ctxt->output, "ATTRDECL(%s)", (char *) attr->name);
Packit Service a31ea6
    } else
Packit Service a31ea6
	xmlDebugErr(ctxt, XML_CHECK_NO_NAME,
Packit Service a31ea6
	            "Node attribute declaration has no name");
Packit Service a31ea6
    if (attr->elem != NULL) {
Packit Service a31ea6
        if (!ctxt->check)
Packit Service a31ea6
            fprintf(ctxt->output, " for %s", (char *) attr->elem);
Packit Service a31ea6
    } else
Packit Service a31ea6
	xmlDebugErr(ctxt, XML_CHECK_NO_ELEM,
Packit Service a31ea6
	            "Node attribute declaration has no element name");
Packit Service a31ea6
    if (!ctxt->check) {
Packit Service a31ea6
        switch (attr->atype) {
Packit Service a31ea6
            case XML_ATTRIBUTE_CDATA:
Packit Service a31ea6
                fprintf(ctxt->output, " CDATA");
Packit Service a31ea6
                break;
Packit Service a31ea6
            case XML_ATTRIBUTE_ID:
Packit Service a31ea6
                fprintf(ctxt->output, " ID");
Packit Service a31ea6
                break;
Packit Service a31ea6
            case XML_ATTRIBUTE_IDREF:
Packit Service a31ea6
                fprintf(ctxt->output, " IDREF");
Packit Service a31ea6
                break;
Packit Service a31ea6
            case XML_ATTRIBUTE_IDREFS:
Packit Service a31ea6
                fprintf(ctxt->output, " IDREFS");
Packit Service a31ea6
                break;
Packit Service a31ea6
            case XML_ATTRIBUTE_ENTITY:
Packit Service a31ea6
                fprintf(ctxt->output, " ENTITY");
Packit Service a31ea6
                break;
Packit Service a31ea6
            case XML_ATTRIBUTE_ENTITIES:
Packit Service a31ea6
                fprintf(ctxt->output, " ENTITIES");
Packit Service a31ea6
                break;
Packit Service a31ea6
            case XML_ATTRIBUTE_NMTOKEN:
Packit Service a31ea6
                fprintf(ctxt->output, " NMTOKEN");
Packit Service a31ea6
                break;
Packit Service a31ea6
            case XML_ATTRIBUTE_NMTOKENS:
Packit Service a31ea6
                fprintf(ctxt->output, " NMTOKENS");
Packit Service a31ea6
                break;
Packit Service a31ea6
            case XML_ATTRIBUTE_ENUMERATION:
Packit Service a31ea6
                fprintf(ctxt->output, " ENUMERATION");
Packit Service a31ea6
                break;
Packit Service a31ea6
            case XML_ATTRIBUTE_NOTATION:
Packit Service a31ea6
                fprintf(ctxt->output, " NOTATION ");
Packit Service a31ea6
                break;
Packit Service a31ea6
        }
Packit Service a31ea6
        if (attr->tree != NULL) {
Packit Service a31ea6
            int indx;
Packit Service a31ea6
            xmlEnumerationPtr cur = attr->tree;
Packit Service a31ea6
Packit Service a31ea6
            for (indx = 0; indx < 5; indx++) {
Packit Service a31ea6
                if (indx != 0)
Packit Service a31ea6
                    fprintf(ctxt->output, "|%s", (char *) cur->name);
Packit Service a31ea6
                else
Packit Service a31ea6
                    fprintf(ctxt->output, " (%s", (char *) cur->name);
Packit Service a31ea6
                cur = cur->next;
Packit Service a31ea6
                if (cur == NULL)
Packit Service a31ea6
                    break;
Packit Service a31ea6
            }
Packit Service a31ea6
            if (cur == NULL)
Packit Service a31ea6
                fprintf(ctxt->output, ")");
Packit Service a31ea6
            else
Packit Service a31ea6
                fprintf(ctxt->output, "...)");
Packit Service a31ea6
        }
Packit Service a31ea6
        switch (attr->def) {
Packit Service a31ea6
            case XML_ATTRIBUTE_NONE:
Packit Service a31ea6
                break;
Packit Service a31ea6
            case XML_ATTRIBUTE_REQUIRED:
Packit Service a31ea6
                fprintf(ctxt->output, " REQUIRED");
Packit Service a31ea6
                break;
Packit Service a31ea6
            case XML_ATTRIBUTE_IMPLIED:
Packit Service a31ea6
                fprintf(ctxt->output, " IMPLIED");
Packit Service a31ea6
                break;
Packit Service a31ea6
            case XML_ATTRIBUTE_FIXED:
Packit Service a31ea6
                fprintf(ctxt->output, " FIXED");
Packit Service a31ea6
                break;
Packit Service a31ea6
        }
Packit Service a31ea6
        if (attr->defaultValue != NULL) {
Packit Service a31ea6
            fprintf(ctxt->output, "\"");
Packit Service a31ea6
            xmlCtxtDumpString(ctxt, attr->defaultValue);
Packit Service a31ea6
            fprintf(ctxt->output, "\"");
Packit Service a31ea6
        }
Packit Service a31ea6
        fprintf(ctxt->output, "\n");
Packit Service a31ea6
    }
Packit Service a31ea6
Packit Service a31ea6
    /*
Packit Service a31ea6
     * Do a bit of checking
Packit Service a31ea6
     */
Packit Service a31ea6
    xmlCtxtGenericNodeCheck(ctxt, (xmlNodePtr) attr);
Packit Service a31ea6
}
Packit Service a31ea6
Packit Service a31ea6
static void
Packit Service a31ea6
xmlCtxtDumpElemDecl(xmlDebugCtxtPtr ctxt, xmlElementPtr elem)
Packit Service a31ea6
{
Packit Service a31ea6
    xmlCtxtDumpSpaces(ctxt);
Packit Service a31ea6
Packit Service a31ea6
    if (elem == NULL) {
Packit Service a31ea6
        if (!ctxt->check)
Packit Service a31ea6
            fprintf(ctxt->output, "Element declaration is NULL\n");
Packit Service a31ea6
        return;
Packit Service a31ea6
    }
Packit Service a31ea6
    if (elem->type != XML_ELEMENT_DECL) {
Packit Service a31ea6
	xmlDebugErr(ctxt, XML_CHECK_NOT_ELEM_DECL,
Packit Service a31ea6
	            "Node is not an element declaration");
Packit Service a31ea6
        return;
Packit Service a31ea6
    }
Packit Service a31ea6
    if (elem->name != NULL) {
Packit Service a31ea6
        if (!ctxt->check) {
Packit Service a31ea6
            fprintf(ctxt->output, "ELEMDECL(");
Packit Service a31ea6
            xmlCtxtDumpString(ctxt, elem->name);
Packit Service a31ea6
            fprintf(ctxt->output, ")");
Packit Service a31ea6
        }
Packit Service a31ea6
    } else
Packit Service a31ea6
	xmlDebugErr(ctxt, XML_CHECK_NO_NAME,
Packit Service a31ea6
	            "Element declaration has no name");
Packit Service a31ea6
    if (!ctxt->check) {
Packit Service a31ea6
        switch (elem->etype) {
Packit Service a31ea6
            case XML_ELEMENT_TYPE_UNDEFINED:
Packit Service a31ea6
                fprintf(ctxt->output, ", UNDEFINED");
Packit Service a31ea6
                break;
Packit Service a31ea6
            case XML_ELEMENT_TYPE_EMPTY:
Packit Service a31ea6
                fprintf(ctxt->output, ", EMPTY");
Packit Service a31ea6
                break;
Packit Service a31ea6
            case XML_ELEMENT_TYPE_ANY:
Packit Service a31ea6
                fprintf(ctxt->output, ", ANY");
Packit Service a31ea6
                break;
Packit Service a31ea6
            case XML_ELEMENT_TYPE_MIXED:
Packit Service a31ea6
                fprintf(ctxt->output, ", MIXED ");
Packit Service a31ea6
                break;
Packit Service a31ea6
            case XML_ELEMENT_TYPE_ELEMENT:
Packit Service a31ea6
                fprintf(ctxt->output, ", MIXED ");
Packit Service a31ea6
                break;
Packit Service a31ea6
        }
Packit Service a31ea6
        if ((elem->type != XML_ELEMENT_NODE) && (elem->content != NULL)) {
Packit Service a31ea6
            char buf[5001];
Packit Service a31ea6
Packit Service a31ea6
            buf[0] = 0;
Packit Service a31ea6
            xmlSnprintfElementContent(buf, 5000, elem->content, 1);
Packit Service a31ea6
            buf[5000] = 0;
Packit Service a31ea6
            fprintf(ctxt->output, "%s", buf);
Packit Service a31ea6
        }
Packit Service a31ea6
        fprintf(ctxt->output, "\n");
Packit Service a31ea6
    }
Packit Service a31ea6
Packit Service a31ea6
    /*
Packit Service a31ea6
     * Do a bit of checking
Packit Service a31ea6
     */
Packit Service a31ea6
    xmlCtxtGenericNodeCheck(ctxt, (xmlNodePtr) elem);
Packit Service a31ea6
}
Packit Service a31ea6
Packit Service a31ea6
static void
Packit Service a31ea6
xmlCtxtDumpEntityDecl(xmlDebugCtxtPtr ctxt, xmlEntityPtr ent)
Packit Service a31ea6
{
Packit Service a31ea6
    xmlCtxtDumpSpaces(ctxt);
Packit Service a31ea6
Packit Service a31ea6
    if (ent == NULL) {
Packit Service a31ea6
        if (!ctxt->check)
Packit Service a31ea6
            fprintf(ctxt->output, "Entity declaration is NULL\n");
Packit Service a31ea6
        return;
Packit Service a31ea6
    }
Packit Service a31ea6
    if (ent->type != XML_ENTITY_DECL) {
Packit Service a31ea6
	xmlDebugErr(ctxt, XML_CHECK_NOT_ENTITY_DECL,
Packit Service a31ea6
	            "Node is not an entity declaration");
Packit Service a31ea6
        return;
Packit Service a31ea6
    }
Packit Service a31ea6
    if (ent->name != NULL) {
Packit Service a31ea6
        if (!ctxt->check) {
Packit Service a31ea6
            fprintf(ctxt->output, "ENTITYDECL(");
Packit Service a31ea6
            xmlCtxtDumpString(ctxt, ent->name);
Packit Service a31ea6
            fprintf(ctxt->output, ")");
Packit Service a31ea6
        }
Packit Service a31ea6
    } else
Packit Service a31ea6
	xmlDebugErr(ctxt, XML_CHECK_NO_NAME,
Packit Service a31ea6
	            "Entity declaration has no name");
Packit Service a31ea6
    if (!ctxt->check) {
Packit Service a31ea6
        switch (ent->etype) {
Packit Service a31ea6
            case XML_INTERNAL_GENERAL_ENTITY:
Packit Service a31ea6
                fprintf(ctxt->output, ", internal\n");
Packit Service a31ea6
                break;
Packit Service a31ea6
            case XML_EXTERNAL_GENERAL_PARSED_ENTITY:
Packit Service a31ea6
                fprintf(ctxt->output, ", external parsed\n");
Packit Service a31ea6
                break;
Packit Service a31ea6
            case XML_EXTERNAL_GENERAL_UNPARSED_ENTITY:
Packit Service a31ea6
                fprintf(ctxt->output, ", unparsed\n");
Packit Service a31ea6
                break;
Packit Service a31ea6
            case XML_INTERNAL_PARAMETER_ENTITY:
Packit Service a31ea6
                fprintf(ctxt->output, ", parameter\n");
Packit Service a31ea6
                break;
Packit Service a31ea6
            case XML_EXTERNAL_PARAMETER_ENTITY:
Packit Service a31ea6
                fprintf(ctxt->output, ", external parameter\n");
Packit Service a31ea6
                break;
Packit Service a31ea6
            case XML_INTERNAL_PREDEFINED_ENTITY:
Packit Service a31ea6
                fprintf(ctxt->output, ", predefined\n");
Packit Service a31ea6
                break;
Packit Service a31ea6
        }
Packit Service a31ea6
        if (ent->ExternalID) {
Packit Service a31ea6
            xmlCtxtDumpSpaces(ctxt);
Packit Service a31ea6
            fprintf(ctxt->output, " ExternalID=%s\n",
Packit Service a31ea6
                    (char *) ent->ExternalID);
Packit Service a31ea6
        }
Packit Service a31ea6
        if (ent->SystemID) {
Packit Service a31ea6
            xmlCtxtDumpSpaces(ctxt);
Packit Service a31ea6
            fprintf(ctxt->output, " SystemID=%s\n",
Packit Service a31ea6
                    (char *) ent->SystemID);
Packit Service a31ea6
        }
Packit Service a31ea6
        if (ent->URI != NULL) {
Packit Service a31ea6
            xmlCtxtDumpSpaces(ctxt);
Packit Service a31ea6
            fprintf(ctxt->output, " URI=%s\n", (char *) ent->URI);
Packit Service a31ea6
        }
Packit Service a31ea6
        if (ent->content) {
Packit Service a31ea6
            xmlCtxtDumpSpaces(ctxt);
Packit Service a31ea6
            fprintf(ctxt->output, " content=");
Packit Service a31ea6
            xmlCtxtDumpString(ctxt, ent->content);
Packit Service a31ea6
            fprintf(ctxt->output, "\n");
Packit Service a31ea6
        }
Packit Service a31ea6
    }
Packit Service a31ea6
Packit Service a31ea6
    /*
Packit Service a31ea6
     * Do a bit of checking
Packit Service a31ea6
     */
Packit Service a31ea6
    xmlCtxtGenericNodeCheck(ctxt, (xmlNodePtr) ent);
Packit Service a31ea6
}
Packit Service a31ea6
Packit Service a31ea6
static void
Packit Service a31ea6
xmlCtxtDumpNamespace(xmlDebugCtxtPtr ctxt, xmlNsPtr ns)
Packit Service a31ea6
{
Packit Service a31ea6
    xmlCtxtDumpSpaces(ctxt);
Packit Service a31ea6
Packit Service a31ea6
    if (ns == NULL) {
Packit Service a31ea6
        if (!ctxt->check)
Packit Service a31ea6
            fprintf(ctxt->output, "namespace node is NULL\n");
Packit Service a31ea6
        return;
Packit Service a31ea6
    }
Packit Service a31ea6
    if (ns->type != XML_NAMESPACE_DECL) {
Packit Service a31ea6
	xmlDebugErr(ctxt, XML_CHECK_NOT_NS_DECL,
Packit Service a31ea6
	            "Node is not a namespace declaration");
Packit Service a31ea6
        return;
Packit Service a31ea6
    }
Packit Service a31ea6
    if (ns->href == NULL) {
Packit Service a31ea6
        if (ns->prefix != NULL)
Packit Service a31ea6
	    xmlDebugErr3(ctxt, XML_CHECK_NO_HREF,
Packit Service a31ea6
                    "Incomplete namespace %s href=NULL\n",
Packit Service a31ea6
                    (char *) ns->prefix);
Packit Service a31ea6
        else
Packit Service a31ea6
	    xmlDebugErr(ctxt, XML_CHECK_NO_HREF,
Packit Service a31ea6
                    "Incomplete default namespace href=NULL\n");
Packit Service a31ea6
    } else {
Packit Service a31ea6
        if (!ctxt->check) {
Packit Service a31ea6
            if (ns->prefix != NULL)
Packit Service a31ea6
                fprintf(ctxt->output, "namespace %s href=",
Packit Service a31ea6
                        (char *) ns->prefix);
Packit Service a31ea6
            else
Packit Service a31ea6
                fprintf(ctxt->output, "default namespace href=");
Packit Service a31ea6
Packit Service a31ea6
            xmlCtxtDumpString(ctxt, ns->href);
Packit Service a31ea6
            fprintf(ctxt->output, "\n");
Packit Service a31ea6
        }
Packit Service a31ea6
    }
Packit Service a31ea6
}
Packit Service a31ea6
Packit Service a31ea6
static void
Packit Service a31ea6
xmlCtxtDumpNamespaceList(xmlDebugCtxtPtr ctxt, xmlNsPtr ns)
Packit Service a31ea6
{
Packit Service a31ea6
    while (ns != NULL) {
Packit Service a31ea6
        xmlCtxtDumpNamespace(ctxt, ns);
Packit Service a31ea6
        ns = ns->next;
Packit Service a31ea6
    }
Packit Service a31ea6
}
Packit Service a31ea6
Packit Service a31ea6
static void
Packit Service a31ea6
xmlCtxtDumpEntity(xmlDebugCtxtPtr ctxt, xmlEntityPtr ent)
Packit Service a31ea6
{
Packit Service a31ea6
    xmlCtxtDumpSpaces(ctxt);
Packit Service a31ea6
Packit Service a31ea6
    if (ent == NULL) {
Packit Service a31ea6
        if (!ctxt->check)
Packit Service a31ea6
            fprintf(ctxt->output, "Entity is NULL\n");
Packit Service a31ea6
        return;
Packit Service a31ea6
    }
Packit Service a31ea6
    if (!ctxt->check) {
Packit Service a31ea6
        switch (ent->etype) {
Packit Service a31ea6
            case XML_INTERNAL_GENERAL_ENTITY:
Packit Service a31ea6
                fprintf(ctxt->output, "INTERNAL_GENERAL_ENTITY ");
Packit Service a31ea6
                break;
Packit Service a31ea6
            case XML_EXTERNAL_GENERAL_PARSED_ENTITY:
Packit Service a31ea6
                fprintf(ctxt->output, "EXTERNAL_GENERAL_PARSED_ENTITY ");
Packit Service a31ea6
                break;
Packit Service a31ea6
            case XML_EXTERNAL_GENERAL_UNPARSED_ENTITY:
Packit Service a31ea6
                fprintf(ctxt->output, "EXTERNAL_GENERAL_UNPARSED_ENTITY ");
Packit Service a31ea6
                break;
Packit Service a31ea6
            case XML_INTERNAL_PARAMETER_ENTITY:
Packit Service a31ea6
                fprintf(ctxt->output, "INTERNAL_PARAMETER_ENTITY ");
Packit Service a31ea6
                break;
Packit Service a31ea6
            case XML_EXTERNAL_PARAMETER_ENTITY:
Packit Service a31ea6
                fprintf(ctxt->output, "EXTERNAL_PARAMETER_ENTITY ");
Packit Service a31ea6
                break;
Packit Service a31ea6
            default:
Packit Service a31ea6
                fprintf(ctxt->output, "ENTITY_%d ! ", (int) ent->etype);
Packit Service a31ea6
        }
Packit Service a31ea6
        fprintf(ctxt->output, "%s\n", ent->name);
Packit Service a31ea6
        if (ent->ExternalID) {
Packit Service a31ea6
            xmlCtxtDumpSpaces(ctxt);
Packit Service a31ea6
            fprintf(ctxt->output, "ExternalID=%s\n",
Packit Service a31ea6
                    (char *) ent->ExternalID);
Packit Service a31ea6
        }
Packit Service a31ea6
        if (ent->SystemID) {
Packit Service a31ea6
            xmlCtxtDumpSpaces(ctxt);
Packit Service a31ea6
            fprintf(ctxt->output, "SystemID=%s\n", (char *) ent->SystemID);
Packit Service a31ea6
        }
Packit Service a31ea6
        if (ent->URI) {
Packit Service a31ea6
            xmlCtxtDumpSpaces(ctxt);
Packit Service a31ea6
            fprintf(ctxt->output, "URI=%s\n", (char *) ent->URI);
Packit Service a31ea6
        }
Packit Service a31ea6
        if (ent->content) {
Packit Service a31ea6
            xmlCtxtDumpSpaces(ctxt);
Packit Service a31ea6
            fprintf(ctxt->output, "content=");
Packit Service a31ea6
            xmlCtxtDumpString(ctxt, ent->content);
Packit Service a31ea6
            fprintf(ctxt->output, "\n");
Packit Service a31ea6
        }
Packit Service a31ea6
    }
Packit Service a31ea6
}
Packit Service a31ea6
Packit Service a31ea6
/**
Packit Service a31ea6
 * xmlCtxtDumpAttr:
Packit Service a31ea6
 * @output:  the FILE * for the output
Packit Service a31ea6
 * @attr:  the attribute
Packit Service a31ea6
 * @depth:  the indentation level.
Packit Service a31ea6
 *
Packit Service a31ea6
 * Dumps debug information for the attribute
Packit Service a31ea6
 */
Packit Service a31ea6
static void
Packit Service a31ea6
xmlCtxtDumpAttr(xmlDebugCtxtPtr ctxt, xmlAttrPtr attr)
Packit Service a31ea6
{
Packit Service a31ea6
    xmlCtxtDumpSpaces(ctxt);
Packit Service a31ea6
Packit Service a31ea6
    if (attr == NULL) {
Packit Service a31ea6
        if (!ctxt->check)
Packit Service a31ea6
            fprintf(ctxt->output, "Attr is NULL");
Packit Service a31ea6
        return;
Packit Service a31ea6
    }
Packit Service a31ea6
    if (!ctxt->check) {
Packit Service a31ea6
        fprintf(ctxt->output, "ATTRIBUTE ");
Packit Service a31ea6
	xmlCtxtDumpString(ctxt, attr->name);
Packit Service a31ea6
        fprintf(ctxt->output, "\n");
Packit Service a31ea6
        if (attr->children != NULL) {
Packit Service a31ea6
            ctxt->depth++;
Packit Service a31ea6
            xmlCtxtDumpNodeList(ctxt, attr->children);
Packit Service a31ea6
            ctxt->depth--;
Packit Service a31ea6
        }
Packit Service a31ea6
    }
Packit Service a31ea6
    if (attr->name == NULL)
Packit Service a31ea6
	xmlDebugErr(ctxt, XML_CHECK_NO_NAME,
Packit Service a31ea6
	            "Attribute has no name");
Packit Service a31ea6
Packit Service a31ea6
    /*
Packit Service a31ea6
     * Do a bit of checking
Packit Service a31ea6
     */
Packit Service a31ea6
    xmlCtxtGenericNodeCheck(ctxt, (xmlNodePtr) attr);
Packit Service a31ea6
}
Packit Service a31ea6
Packit Service a31ea6
/**
Packit Service a31ea6
 * xmlCtxtDumpAttrList:
Packit Service a31ea6
 * @output:  the FILE * for the output
Packit Service a31ea6
 * @attr:  the attribute list
Packit Service a31ea6
 * @depth:  the indentation level.
Packit Service a31ea6
 *
Packit Service a31ea6
 * Dumps debug information for the attribute list
Packit Service a31ea6
 */
Packit Service a31ea6
static void
Packit Service a31ea6
xmlCtxtDumpAttrList(xmlDebugCtxtPtr ctxt, xmlAttrPtr attr)
Packit Service a31ea6
{
Packit Service a31ea6
    while (attr != NULL) {
Packit Service a31ea6
        xmlCtxtDumpAttr(ctxt, attr);
Packit Service a31ea6
        attr = attr->next;
Packit Service a31ea6
    }
Packit Service a31ea6
}
Packit Service a31ea6
Packit Service a31ea6
/**
Packit Service a31ea6
 * xmlCtxtDumpOneNode:
Packit Service a31ea6
 * @output:  the FILE * for the output
Packit Service a31ea6
 * @node:  the node
Packit Service a31ea6
 * @depth:  the indentation level.
Packit Service a31ea6
 *
Packit Service a31ea6
 * Dumps debug information for the element node, it is not recursive
Packit Service a31ea6
 */
Packit Service a31ea6
static void
Packit Service a31ea6
xmlCtxtDumpOneNode(xmlDebugCtxtPtr ctxt, xmlNodePtr node)
Packit Service a31ea6
{
Packit Service a31ea6
    if (node == NULL) {
Packit Service a31ea6
        if (!ctxt->check) {
Packit Service a31ea6
            xmlCtxtDumpSpaces(ctxt);
Packit Service a31ea6
            fprintf(ctxt->output, "node is NULL\n");
Packit Service a31ea6
        }
Packit Service a31ea6
        return;
Packit Service a31ea6
    }
Packit Service a31ea6
    ctxt->node = node;
Packit Service a31ea6
Packit Service a31ea6
    switch (node->type) {
Packit Service a31ea6
        case XML_ELEMENT_NODE:
Packit Service a31ea6
            if (!ctxt->check) {
Packit Service a31ea6
                xmlCtxtDumpSpaces(ctxt);
Packit Service a31ea6
                fprintf(ctxt->output, "ELEMENT ");
Packit Service a31ea6
                if ((node->ns != NULL) && (node->ns->prefix != NULL)) {
Packit Service a31ea6
                    xmlCtxtDumpString(ctxt, node->ns->prefix);
Packit Service a31ea6
                    fprintf(ctxt->output, ":");
Packit Service a31ea6
                }
Packit Service a31ea6
                xmlCtxtDumpString(ctxt, node->name);
Packit Service a31ea6
                fprintf(ctxt->output, "\n");
Packit Service a31ea6
            }
Packit Service a31ea6
            break;
Packit Service a31ea6
        case XML_ATTRIBUTE_NODE:
Packit Service a31ea6
            if (!ctxt->check)
Packit Service a31ea6
                xmlCtxtDumpSpaces(ctxt);
Packit Service a31ea6
            fprintf(ctxt->output, "Error, ATTRIBUTE found here\n");
Packit Service a31ea6
            xmlCtxtGenericNodeCheck(ctxt, node);
Packit Service a31ea6
            return;
Packit Service a31ea6
        case XML_TEXT_NODE:
Packit Service a31ea6
            if (!ctxt->check) {
Packit Service a31ea6
                xmlCtxtDumpSpaces(ctxt);
Packit Service a31ea6
                if (node->name == (const xmlChar *) xmlStringTextNoenc)
Packit Service a31ea6
                    fprintf(ctxt->output, "TEXT no enc");
Packit Service a31ea6
                else
Packit Service a31ea6
                    fprintf(ctxt->output, "TEXT");
Packit Service a31ea6
		if (ctxt->options & DUMP_TEXT_TYPE) {
Packit Service a31ea6
		    if (node->content == (xmlChar *) &(node->properties))
Packit Service a31ea6
			fprintf(ctxt->output, " compact\n");
Packit Service a31ea6
		    else if (xmlDictOwns(ctxt->dict, node->content) == 1)
Packit Service a31ea6
			fprintf(ctxt->output, " interned\n");
Packit Service a31ea6
		    else
Packit Service a31ea6
			fprintf(ctxt->output, "\n");
Packit Service a31ea6
		} else
Packit Service a31ea6
		    fprintf(ctxt->output, "\n");
Packit Service a31ea6
            }
Packit Service a31ea6
            break;
Packit Service a31ea6
        case XML_CDATA_SECTION_NODE:
Packit Service a31ea6
            if (!ctxt->check) {
Packit Service a31ea6
                xmlCtxtDumpSpaces(ctxt);
Packit Service a31ea6
                fprintf(ctxt->output, "CDATA_SECTION\n");
Packit Service a31ea6
            }
Packit Service a31ea6
            break;
Packit Service a31ea6
        case XML_ENTITY_REF_NODE:
Packit Service a31ea6
            if (!ctxt->check) {
Packit Service a31ea6
                xmlCtxtDumpSpaces(ctxt);
Packit Service a31ea6
                fprintf(ctxt->output, "ENTITY_REF(%s)\n",
Packit Service a31ea6
                        (char *) node->name);
Packit Service a31ea6
            }
Packit Service a31ea6
            break;
Packit Service a31ea6
        case XML_ENTITY_NODE:
Packit Service a31ea6
            if (!ctxt->check) {
Packit Service a31ea6
                xmlCtxtDumpSpaces(ctxt);
Packit Service a31ea6
                fprintf(ctxt->output, "ENTITY\n");
Packit Service a31ea6
            }
Packit Service a31ea6
            break;
Packit Service a31ea6
        case XML_PI_NODE:
Packit Service a31ea6
            if (!ctxt->check) {
Packit Service a31ea6
                xmlCtxtDumpSpaces(ctxt);
Packit Service a31ea6
                fprintf(ctxt->output, "PI %s\n", (char *) node->name);
Packit Service a31ea6
            }
Packit Service a31ea6
            break;
Packit Service a31ea6
        case XML_COMMENT_NODE:
Packit Service a31ea6
            if (!ctxt->check) {
Packit Service a31ea6
                xmlCtxtDumpSpaces(ctxt);
Packit Service a31ea6
                fprintf(ctxt->output, "COMMENT\n");
Packit Service a31ea6
            }
Packit Service a31ea6
            break;
Packit Service a31ea6
        case XML_DOCUMENT_NODE:
Packit Service a31ea6
        case XML_HTML_DOCUMENT_NODE:
Packit Service a31ea6
            if (!ctxt->check) {
Packit Service a31ea6
                xmlCtxtDumpSpaces(ctxt);
Packit Service a31ea6
            }
Packit Service a31ea6
            fprintf(ctxt->output, "Error, DOCUMENT found here\n");
Packit Service a31ea6
            xmlCtxtGenericNodeCheck(ctxt, node);
Packit Service a31ea6
            return;
Packit Service a31ea6
        case XML_DOCUMENT_TYPE_NODE:
Packit Service a31ea6
            if (!ctxt->check) {
Packit Service a31ea6
                xmlCtxtDumpSpaces(ctxt);
Packit Service a31ea6
                fprintf(ctxt->output, "DOCUMENT_TYPE\n");
Packit Service a31ea6
            }
Packit Service a31ea6
            break;
Packit Service a31ea6
        case XML_DOCUMENT_FRAG_NODE:
Packit Service a31ea6
            if (!ctxt->check) {
Packit Service a31ea6
                xmlCtxtDumpSpaces(ctxt);
Packit Service a31ea6
                fprintf(ctxt->output, "DOCUMENT_FRAG\n");
Packit Service a31ea6
            }
Packit Service a31ea6
            break;
Packit Service a31ea6
        case XML_NOTATION_NODE:
Packit Service a31ea6
            if (!ctxt->check) {
Packit Service a31ea6
                xmlCtxtDumpSpaces(ctxt);
Packit Service a31ea6
                fprintf(ctxt->output, "NOTATION\n");
Packit Service a31ea6
            }
Packit Service a31ea6
            break;
Packit Service a31ea6
        case XML_DTD_NODE:
Packit Service a31ea6
            xmlCtxtDumpDtdNode(ctxt, (xmlDtdPtr) node);
Packit Service a31ea6
            return;
Packit Service a31ea6
        case XML_ELEMENT_DECL:
Packit Service a31ea6
            xmlCtxtDumpElemDecl(ctxt, (xmlElementPtr) node);
Packit Service a31ea6
            return;
Packit Service a31ea6
        case XML_ATTRIBUTE_DECL:
Packit Service a31ea6
            xmlCtxtDumpAttrDecl(ctxt, (xmlAttributePtr) node);
Packit Service a31ea6
            return;
Packit Service a31ea6
        case XML_ENTITY_DECL:
Packit Service a31ea6
            xmlCtxtDumpEntityDecl(ctxt, (xmlEntityPtr) node);
Packit Service a31ea6
            return;
Packit Service a31ea6
        case XML_NAMESPACE_DECL:
Packit Service a31ea6
            xmlCtxtDumpNamespace(ctxt, (xmlNsPtr) node);
Packit Service a31ea6
            return;
Packit Service a31ea6
        case XML_XINCLUDE_START:
Packit Service a31ea6
            if (!ctxt->check) {
Packit Service a31ea6
                xmlCtxtDumpSpaces(ctxt);
Packit Service a31ea6
                fprintf(ctxt->output, "INCLUDE START\n");
Packit Service a31ea6
            }
Packit Service a31ea6
            return;
Packit Service a31ea6
        case XML_XINCLUDE_END:
Packit Service a31ea6
            if (!ctxt->check) {
Packit Service a31ea6
                xmlCtxtDumpSpaces(ctxt);
Packit Service a31ea6
                fprintf(ctxt->output, "INCLUDE END\n");
Packit Service a31ea6
            }
Packit Service a31ea6
            return;
Packit Service a31ea6
        default:
Packit Service a31ea6
            if (!ctxt->check)
Packit Service a31ea6
                xmlCtxtDumpSpaces(ctxt);
Packit Service a31ea6
	    xmlDebugErr2(ctxt, XML_CHECK_UNKNOWN_NODE,
Packit Service a31ea6
	                "Unknown node type %d\n", node->type);
Packit Service a31ea6
            return;
Packit Service a31ea6
    }
Packit Service a31ea6
    if (node->doc == NULL) {
Packit Service a31ea6
        if (!ctxt->check) {
Packit Service a31ea6
            xmlCtxtDumpSpaces(ctxt);
Packit Service a31ea6
        }
Packit Service a31ea6
        fprintf(ctxt->output, "PBM: doc == NULL !!!\n");
Packit Service a31ea6
    }
Packit Service a31ea6
    ctxt->depth++;
Packit Service a31ea6
    if ((node->type == XML_ELEMENT_NODE) && (node->nsDef != NULL))
Packit Service a31ea6
        xmlCtxtDumpNamespaceList(ctxt, node->nsDef);
Packit Service a31ea6
    if ((node->type == XML_ELEMENT_NODE) && (node->properties != NULL))
Packit Service a31ea6
        xmlCtxtDumpAttrList(ctxt, node->properties);
Packit Service a31ea6
    if (node->type != XML_ENTITY_REF_NODE) {
Packit Service a31ea6
        if ((node->type != XML_ELEMENT_NODE) && (node->content != NULL)) {
Packit Service a31ea6
            if (!ctxt->check) {
Packit Service a31ea6
                xmlCtxtDumpSpaces(ctxt);
Packit Service a31ea6
                fprintf(ctxt->output, "content=");
Packit Service a31ea6
                xmlCtxtDumpString(ctxt, node->content);
Packit Service a31ea6
                fprintf(ctxt->output, "\n");
Packit Service a31ea6
            }
Packit Service a31ea6
        }
Packit Service a31ea6
    } else {
Packit Service a31ea6
        xmlEntityPtr ent;
Packit Service a31ea6
Packit Service a31ea6
        ent = xmlGetDocEntity(node->doc, node->name);
Packit Service a31ea6
        if (ent != NULL)
Packit Service a31ea6
            xmlCtxtDumpEntity(ctxt, ent);
Packit Service a31ea6
    }
Packit Service a31ea6
    ctxt->depth--;
Packit Service a31ea6
Packit Service a31ea6
    /*
Packit Service a31ea6
     * Do a bit of checking
Packit Service a31ea6
     */
Packit Service a31ea6
    xmlCtxtGenericNodeCheck(ctxt, node);
Packit Service a31ea6
}
Packit Service a31ea6
Packit Service a31ea6
/**
Packit Service a31ea6
 * xmlCtxtDumpNode:
Packit Service a31ea6
 * @output:  the FILE * for the output
Packit Service a31ea6
 * @node:  the node
Packit Service a31ea6
 * @depth:  the indentation level.
Packit Service a31ea6
 *
Packit Service a31ea6
 * Dumps debug information for the element node, it is recursive
Packit Service a31ea6
 */
Packit Service a31ea6
static void
Packit Service a31ea6
xmlCtxtDumpNode(xmlDebugCtxtPtr ctxt, xmlNodePtr node)
Packit Service a31ea6
{
Packit Service a31ea6
    if (node == NULL) {
Packit Service a31ea6
        if (!ctxt->check) {
Packit Service a31ea6
            xmlCtxtDumpSpaces(ctxt);
Packit Service a31ea6
            fprintf(ctxt->output, "node is NULL\n");
Packit Service a31ea6
        }
Packit Service a31ea6
        return;
Packit Service a31ea6
    }
Packit Service a31ea6
    xmlCtxtDumpOneNode(ctxt, node);
Packit Service a31ea6
    if ((node->type != XML_NAMESPACE_DECL) &&
Packit Service a31ea6
        (node->children != NULL) && (node->type != XML_ENTITY_REF_NODE)) {
Packit Service a31ea6
        ctxt->depth++;
Packit Service a31ea6
        xmlCtxtDumpNodeList(ctxt, node->children);
Packit Service a31ea6
        ctxt->depth--;
Packit Service a31ea6
    }
Packit Service a31ea6
}
Packit Service a31ea6
Packit Service a31ea6
/**
Packit Service a31ea6
 * xmlCtxtDumpNodeList:
Packit Service a31ea6
 * @output:  the FILE * for the output
Packit Service a31ea6
 * @node:  the node list
Packit Service a31ea6
 * @depth:  the indentation level.
Packit Service a31ea6
 *
Packit Service a31ea6
 * Dumps debug information for the list of element node, it is recursive
Packit Service a31ea6
 */
Packit Service a31ea6
static void
Packit Service a31ea6
xmlCtxtDumpNodeList(xmlDebugCtxtPtr ctxt, xmlNodePtr node)
Packit Service a31ea6
{
Packit Service a31ea6
    while (node != NULL) {
Packit Service a31ea6
        xmlCtxtDumpNode(ctxt, node);
Packit Service a31ea6
        node = node->next;
Packit Service a31ea6
    }
Packit Service a31ea6
}
Packit Service a31ea6
Packit Service a31ea6
static void
Packit Service a31ea6
xmlCtxtDumpDocHead(xmlDebugCtxtPtr ctxt, xmlDocPtr doc)
Packit Service a31ea6
{
Packit Service a31ea6
    if (doc == NULL) {
Packit Service a31ea6
        if (!ctxt->check)
Packit Service a31ea6
            fprintf(ctxt->output, "DOCUMENT == NULL !\n");
Packit Service a31ea6
        return;
Packit Service a31ea6
    }
Packit Service a31ea6
    ctxt->node = (xmlNodePtr) doc;
Packit Service a31ea6
Packit Service a31ea6
    switch (doc->type) {
Packit Service a31ea6
        case XML_ELEMENT_NODE:
Packit Service a31ea6
	    xmlDebugErr(ctxt, XML_CHECK_FOUND_ELEMENT,
Packit Service a31ea6
	                "Misplaced ELEMENT node\n");
Packit Service a31ea6
            break;
Packit Service a31ea6
        case XML_ATTRIBUTE_NODE:
Packit Service a31ea6
	    xmlDebugErr(ctxt, XML_CHECK_FOUND_ATTRIBUTE,
Packit Service a31ea6
	                "Misplaced ATTRIBUTE node\n");
Packit Service a31ea6
            break;
Packit Service a31ea6
        case XML_TEXT_NODE:
Packit Service a31ea6
	    xmlDebugErr(ctxt, XML_CHECK_FOUND_TEXT,
Packit Service a31ea6
	                "Misplaced TEXT node\n");
Packit Service a31ea6
            break;
Packit Service a31ea6
        case XML_CDATA_SECTION_NODE:
Packit Service a31ea6
	    xmlDebugErr(ctxt, XML_CHECK_FOUND_CDATA,
Packit Service a31ea6
	                "Misplaced CDATA node\n");
Packit Service a31ea6
            break;
Packit Service a31ea6
        case XML_ENTITY_REF_NODE:
Packit Service a31ea6
	    xmlDebugErr(ctxt, XML_CHECK_FOUND_ENTITYREF,
Packit Service a31ea6
	                "Misplaced ENTITYREF node\n");
Packit Service a31ea6
            break;
Packit Service a31ea6
        case XML_ENTITY_NODE:
Packit Service a31ea6
	    xmlDebugErr(ctxt, XML_CHECK_FOUND_ENTITY,
Packit Service a31ea6
	                "Misplaced ENTITY node\n");
Packit Service a31ea6
            break;
Packit Service a31ea6
        case XML_PI_NODE:
Packit Service a31ea6
	    xmlDebugErr(ctxt, XML_CHECK_FOUND_PI,
Packit Service a31ea6
	                "Misplaced PI node\n");
Packit Service a31ea6
            break;
Packit Service a31ea6
        case XML_COMMENT_NODE:
Packit Service a31ea6
	    xmlDebugErr(ctxt, XML_CHECK_FOUND_COMMENT,
Packit Service a31ea6
	                "Misplaced COMMENT node\n");
Packit Service a31ea6
            break;
Packit Service a31ea6
        case XML_DOCUMENT_NODE:
Packit Service a31ea6
	    if (!ctxt->check)
Packit Service a31ea6
		fprintf(ctxt->output, "DOCUMENT\n");
Packit Service a31ea6
            break;
Packit Service a31ea6
        case XML_HTML_DOCUMENT_NODE:
Packit Service a31ea6
	    if (!ctxt->check)
Packit Service a31ea6
		fprintf(ctxt->output, "HTML DOCUMENT\n");
Packit Service a31ea6
            break;
Packit Service a31ea6
        case XML_DOCUMENT_TYPE_NODE:
Packit Service a31ea6
	    xmlDebugErr(ctxt, XML_CHECK_FOUND_DOCTYPE,
Packit Service a31ea6
	                "Misplaced DOCTYPE node\n");
Packit Service a31ea6
            break;
Packit Service a31ea6
        case XML_DOCUMENT_FRAG_NODE:
Packit Service a31ea6
	    xmlDebugErr(ctxt, XML_CHECK_FOUND_FRAGMENT,
Packit Service a31ea6
	                "Misplaced FRAGMENT node\n");
Packit Service a31ea6
            break;
Packit Service a31ea6
        case XML_NOTATION_NODE:
Packit Service a31ea6
	    xmlDebugErr(ctxt, XML_CHECK_FOUND_NOTATION,
Packit Service a31ea6
	                "Misplaced NOTATION node\n");
Packit Service a31ea6
            break;
Packit Service a31ea6
        default:
Packit Service a31ea6
	    xmlDebugErr2(ctxt, XML_CHECK_UNKNOWN_NODE,
Packit Service a31ea6
	                "Unknown node type %d\n", doc->type);
Packit Service a31ea6
    }
Packit Service a31ea6
}
Packit Service a31ea6
Packit Service a31ea6
/**
Packit Service a31ea6
 * xmlCtxtDumpDocumentHead:
Packit Service a31ea6
 * @output:  the FILE * for the output
Packit Service a31ea6
 * @doc:  the document
Packit Service a31ea6
 *
Packit Service a31ea6
 * Dumps debug information cncerning the document, not recursive
Packit Service a31ea6
 */
Packit Service a31ea6
static void
Packit Service a31ea6
xmlCtxtDumpDocumentHead(xmlDebugCtxtPtr ctxt, xmlDocPtr doc)
Packit Service a31ea6
{
Packit Service a31ea6
    if (doc == NULL) return;
Packit Service a31ea6
    xmlCtxtDumpDocHead(ctxt, doc);
Packit Service a31ea6
    if (!ctxt->check) {
Packit Service a31ea6
        if (doc->name != NULL) {
Packit Service a31ea6
            fprintf(ctxt->output, "name=");
Packit Service a31ea6
            xmlCtxtDumpString(ctxt, BAD_CAST doc->name);
Packit Service a31ea6
            fprintf(ctxt->output, "\n");
Packit Service a31ea6
        }
Packit Service a31ea6
        if (doc->version != NULL) {
Packit Service a31ea6
            fprintf(ctxt->output, "version=");
Packit Service a31ea6
            xmlCtxtDumpString(ctxt, doc->version);
Packit Service a31ea6
            fprintf(ctxt->output, "\n");
Packit Service a31ea6
        }
Packit Service a31ea6
        if (doc->encoding != NULL) {
Packit Service a31ea6
            fprintf(ctxt->output, "encoding=");
Packit Service a31ea6
            xmlCtxtDumpString(ctxt, doc->encoding);
Packit Service a31ea6
            fprintf(ctxt->output, "\n");
Packit Service a31ea6
        }
Packit Service a31ea6
        if (doc->URL != NULL) {
Packit Service a31ea6
            fprintf(ctxt->output, "URL=");
Packit Service a31ea6
            xmlCtxtDumpString(ctxt, doc->URL);
Packit Service a31ea6
            fprintf(ctxt->output, "\n");
Packit Service a31ea6
        }
Packit Service a31ea6
        if (doc->standalone)
Packit Service a31ea6
            fprintf(ctxt->output, "standalone=true\n");
Packit Service a31ea6
    }
Packit Service a31ea6
    if (doc->oldNs != NULL)
Packit Service a31ea6
        xmlCtxtDumpNamespaceList(ctxt, doc->oldNs);
Packit Service a31ea6
}
Packit Service a31ea6
Packit Service a31ea6
/**
Packit Service a31ea6
 * xmlCtxtDumpDocument:
Packit Service a31ea6
 * @output:  the FILE * for the output
Packit Service a31ea6
 * @doc:  the document
Packit Service a31ea6
 *
Packit Service a31ea6
 * Dumps debug information for the document, it's recursive
Packit Service a31ea6
 */
Packit Service a31ea6
static void
Packit Service a31ea6
xmlCtxtDumpDocument(xmlDebugCtxtPtr ctxt, xmlDocPtr doc)
Packit Service a31ea6
{
Packit Service a31ea6
    if (doc == NULL) {
Packit Service a31ea6
        if (!ctxt->check)
Packit Service a31ea6
            fprintf(ctxt->output, "DOCUMENT == NULL !\n");
Packit Service a31ea6
        return;
Packit Service a31ea6
    }
Packit Service a31ea6
    xmlCtxtDumpDocumentHead(ctxt, doc);
Packit Service a31ea6
    if (((doc->type == XML_DOCUMENT_NODE) ||
Packit Service a31ea6
         (doc->type == XML_HTML_DOCUMENT_NODE))
Packit Service a31ea6
        && (doc->children != NULL)) {
Packit Service a31ea6
        ctxt->depth++;
Packit Service a31ea6
        xmlCtxtDumpNodeList(ctxt, doc->children);
Packit Service a31ea6
        ctxt->depth--;
Packit Service a31ea6
    }
Packit Service a31ea6
}
Packit Service a31ea6
Packit Service a31ea6
static void
Packit Service a31ea6
xmlCtxtDumpEntityCallback(xmlEntityPtr cur, xmlDebugCtxtPtr ctxt)
Packit Service a31ea6
{
Packit Service a31ea6
    if (cur == NULL) {
Packit Service a31ea6
        if (!ctxt->check)
Packit Service a31ea6
            fprintf(ctxt->output, "Entity is NULL");
Packit Service a31ea6
        return;
Packit Service a31ea6
    }
Packit Service a31ea6
    if (!ctxt->check) {
Packit Service a31ea6
        fprintf(ctxt->output, "%s : ", (char *) cur->name);
Packit Service a31ea6
        switch (cur->etype) {
Packit Service a31ea6
            case XML_INTERNAL_GENERAL_ENTITY:
Packit Service a31ea6
                fprintf(ctxt->output, "INTERNAL GENERAL, ");
Packit Service a31ea6
                break;
Packit Service a31ea6
            case XML_EXTERNAL_GENERAL_PARSED_ENTITY:
Packit Service a31ea6
                fprintf(ctxt->output, "EXTERNAL PARSED, ");
Packit Service a31ea6
                break;
Packit Service a31ea6
            case XML_EXTERNAL_GENERAL_UNPARSED_ENTITY:
Packit Service a31ea6
                fprintf(ctxt->output, "EXTERNAL UNPARSED, ");
Packit Service a31ea6
                break;
Packit Service a31ea6
            case XML_INTERNAL_PARAMETER_ENTITY:
Packit Service a31ea6
                fprintf(ctxt->output, "INTERNAL PARAMETER, ");
Packit Service a31ea6
                break;
Packit Service a31ea6
            case XML_EXTERNAL_PARAMETER_ENTITY:
Packit Service a31ea6
                fprintf(ctxt->output, "EXTERNAL PARAMETER, ");
Packit Service a31ea6
                break;
Packit Service a31ea6
            default:
Packit Service a31ea6
		xmlDebugErr2(ctxt, XML_CHECK_ENTITY_TYPE,
Packit Service a31ea6
			     "Unknown entity type %d\n", cur->etype);
Packit Service a31ea6
        }
Packit Service a31ea6
        if (cur->ExternalID != NULL)
Packit Service a31ea6
            fprintf(ctxt->output, "ID \"%s\"", (char *) cur->ExternalID);
Packit Service a31ea6
        if (cur->SystemID != NULL)
Packit Service a31ea6
            fprintf(ctxt->output, "SYSTEM \"%s\"", (char *) cur->SystemID);
Packit Service a31ea6
        if (cur->orig != NULL)
Packit Service a31ea6
            fprintf(ctxt->output, "\n orig \"%s\"", (char *) cur->orig);
Packit Service a31ea6
        if ((cur->type != XML_ELEMENT_NODE) && (cur->content != NULL))
Packit Service a31ea6
            fprintf(ctxt->output, "\n content \"%s\"",
Packit Service a31ea6
                    (char *) cur->content);
Packit Service a31ea6
        fprintf(ctxt->output, "\n");
Packit Service a31ea6
    }
Packit Service a31ea6
}
Packit Service a31ea6
Packit Service a31ea6
/**
Packit Service a31ea6
 * xmlCtxtDumpEntities:
Packit Service a31ea6
 * @output:  the FILE * for the output
Packit Service a31ea6
 * @doc:  the document
Packit Service a31ea6
 *
Packit Service a31ea6
 * Dumps debug information for all the entities in use by the document
Packit Service a31ea6
 */
Packit Service a31ea6
static void
Packit Service a31ea6
xmlCtxtDumpEntities(xmlDebugCtxtPtr ctxt, xmlDocPtr doc)
Packit Service a31ea6
{
Packit Service a31ea6
    if (doc == NULL) return;
Packit Service a31ea6
    xmlCtxtDumpDocHead(ctxt, doc);
Packit Service a31ea6
    if ((doc->intSubset != NULL) && (doc->intSubset->entities != NULL)) {
Packit Service a31ea6
        xmlEntitiesTablePtr table = (xmlEntitiesTablePtr)
Packit Service a31ea6
            doc->intSubset->entities;
Packit Service a31ea6
Packit Service a31ea6
        if (!ctxt->check)
Packit Service a31ea6
            fprintf(ctxt->output, "Entities in internal subset\n");
Packit Service a31ea6
        xmlHashScan(table, (xmlHashScanner) xmlCtxtDumpEntityCallback,
Packit Service a31ea6
                    ctxt);
Packit Service a31ea6
    } else
Packit Service a31ea6
        fprintf(ctxt->output, "No entities in internal subset\n");
Packit Service a31ea6
    if ((doc->extSubset != NULL) && (doc->extSubset->entities != NULL)) {
Packit Service a31ea6
        xmlEntitiesTablePtr table = (xmlEntitiesTablePtr)
Packit Service a31ea6
            doc->extSubset->entities;
Packit Service a31ea6
Packit Service a31ea6
        if (!ctxt->check)
Packit Service a31ea6
            fprintf(ctxt->output, "Entities in external subset\n");
Packit Service a31ea6
        xmlHashScan(table, (xmlHashScanner) xmlCtxtDumpEntityCallback,
Packit Service a31ea6
                    ctxt);
Packit Service a31ea6
    } else if (!ctxt->check)
Packit Service a31ea6
        fprintf(ctxt->output, "No entities in external subset\n");
Packit Service a31ea6
}
Packit Service a31ea6
Packit Service a31ea6
/**
Packit Service a31ea6
 * xmlCtxtDumpDTD:
Packit Service a31ea6
 * @output:  the FILE * for the output
Packit Service a31ea6
 * @dtd:  the DTD
Packit Service a31ea6
 *
Packit Service a31ea6
 * Dumps debug information for the DTD
Packit Service a31ea6
 */
Packit Service a31ea6
static void
Packit Service a31ea6
xmlCtxtDumpDTD(xmlDebugCtxtPtr ctxt, xmlDtdPtr dtd)
Packit Service a31ea6
{
Packit Service a31ea6
    if (dtd == NULL) {
Packit Service a31ea6
        if (!ctxt->check)
Packit Service a31ea6
            fprintf(ctxt->output, "DTD is NULL\n");
Packit Service a31ea6
        return;
Packit Service a31ea6
    }
Packit Service a31ea6
    xmlCtxtDumpDtdNode(ctxt, dtd);
Packit Service a31ea6
    if (dtd->children == NULL)
Packit Service a31ea6
        fprintf(ctxt->output, "    DTD is empty\n");
Packit Service a31ea6
    else {
Packit Service a31ea6
        ctxt->depth++;
Packit Service a31ea6
        xmlCtxtDumpNodeList(ctxt, dtd->children);
Packit Service a31ea6
        ctxt->depth--;
Packit Service a31ea6
    }
Packit Service a31ea6
}
Packit Service a31ea6
Packit Service a31ea6
/************************************************************************
Packit Service a31ea6
 *									*
Packit Service a31ea6
 *			Public entry points for dump			*
Packit Service a31ea6
 *									*
Packit Service a31ea6
 ************************************************************************/
Packit Service a31ea6
Packit Service a31ea6
/**
Packit Service a31ea6
 * xmlDebugDumpString:
Packit Service a31ea6
 * @output:  the FILE * for the output
Packit Service a31ea6
 * @str:  the string
Packit Service a31ea6
 *
Packit Service a31ea6
 * Dumps informations about the string, shorten it if necessary
Packit Service a31ea6
 */
Packit Service a31ea6
void
Packit Service a31ea6
xmlDebugDumpString(FILE * output, const xmlChar * str)
Packit Service a31ea6
{
Packit Service a31ea6
    int i;
Packit Service a31ea6
Packit Service a31ea6
    if (output == NULL)
Packit Service a31ea6
	output = stdout;
Packit Service a31ea6
    if (str == NULL) {
Packit Service a31ea6
        fprintf(output, "(NULL)");
Packit Service a31ea6
        return;
Packit Service a31ea6
    }
Packit Service a31ea6
    for (i = 0; i < 40; i++)
Packit Service a31ea6
        if (str[i] == 0)
Packit Service a31ea6
            return;
Packit Service a31ea6
        else if (IS_BLANK_CH(str[i]))
Packit Service a31ea6
            fputc(' ', output);
Packit Service a31ea6
        else if (str[i] >= 0x80)
Packit Service a31ea6
            fprintf(output, "#%X", str[i]);
Packit Service a31ea6
        else
Packit Service a31ea6
            fputc(str[i], output);
Packit Service a31ea6
    fprintf(output, "...");
Packit Service a31ea6
}
Packit Service a31ea6
Packit Service a31ea6
/**
Packit Service a31ea6
 * xmlDebugDumpAttr:
Packit Service a31ea6
 * @output:  the FILE * for the output
Packit Service a31ea6
 * @attr:  the attribute
Packit Service a31ea6
 * @depth:  the indentation level.
Packit Service a31ea6
 *
Packit Service a31ea6
 * Dumps debug information for the attribute
Packit Service a31ea6
 */
Packit Service a31ea6
void
Packit Service a31ea6
xmlDebugDumpAttr(FILE *output, xmlAttrPtr attr, int depth) {
Packit Service a31ea6
    xmlDebugCtxt ctxt;
Packit Service a31ea6
Packit Service a31ea6
    if (output == NULL) return;
Packit Service a31ea6
    xmlCtxtDumpInitCtxt(&ctxt);
Packit Service a31ea6
    ctxt.output = output;
Packit Service a31ea6
    ctxt.depth = depth;
Packit Service a31ea6
    xmlCtxtDumpAttr(&ctxt, attr);
Packit Service a31ea6
    xmlCtxtDumpCleanCtxt(&ctxt);
Packit Service a31ea6
}
Packit Service a31ea6
Packit Service a31ea6
Packit Service a31ea6
/**
Packit Service a31ea6
 * xmlDebugDumpEntities:
Packit Service a31ea6
 * @output:  the FILE * for the output
Packit Service a31ea6
 * @doc:  the document
Packit Service a31ea6
 *
Packit Service a31ea6
 * Dumps debug information for all the entities in use by the document
Packit Service a31ea6
 */
Packit Service a31ea6
void
Packit Service a31ea6
xmlDebugDumpEntities(FILE * output, xmlDocPtr doc)
Packit Service a31ea6
{
Packit Service a31ea6
    xmlDebugCtxt ctxt;
Packit Service a31ea6
Packit Service a31ea6
    if (output == NULL) return;
Packit Service a31ea6
    xmlCtxtDumpInitCtxt(&ctxt);
Packit Service a31ea6
    ctxt.output = output;
Packit Service a31ea6
    xmlCtxtDumpEntities(&ctxt, doc);
Packit Service a31ea6
    xmlCtxtDumpCleanCtxt(&ctxt);
Packit Service a31ea6
}
Packit Service a31ea6
Packit Service a31ea6
/**
Packit Service a31ea6
 * xmlDebugDumpAttrList:
Packit Service a31ea6
 * @output:  the FILE * for the output
Packit Service a31ea6
 * @attr:  the attribute list
Packit Service a31ea6
 * @depth:  the indentation level.
Packit Service a31ea6
 *
Packit Service a31ea6
 * Dumps debug information for the attribute list
Packit Service a31ea6
 */
Packit Service a31ea6
void
Packit Service a31ea6
xmlDebugDumpAttrList(FILE * output, xmlAttrPtr attr, int depth)
Packit Service a31ea6
{
Packit Service a31ea6
    xmlDebugCtxt ctxt;
Packit Service a31ea6
Packit Service a31ea6
    if (output == NULL) return;
Packit Service a31ea6
    xmlCtxtDumpInitCtxt(&ctxt);
Packit Service a31ea6
    ctxt.output = output;
Packit Service a31ea6
    ctxt.depth = depth;
Packit Service a31ea6
    xmlCtxtDumpAttrList(&ctxt, attr);
Packit Service a31ea6
    xmlCtxtDumpCleanCtxt(&ctxt);
Packit Service a31ea6
}
Packit Service a31ea6
Packit Service a31ea6
/**
Packit Service a31ea6
 * xmlDebugDumpOneNode:
Packit Service a31ea6
 * @output:  the FILE * for the output
Packit Service a31ea6
 * @node:  the node
Packit Service a31ea6
 * @depth:  the indentation level.
Packit Service a31ea6
 *
Packit Service a31ea6
 * Dumps debug information for the element node, it is not recursive
Packit Service a31ea6
 */
Packit Service a31ea6
void
Packit Service a31ea6
xmlDebugDumpOneNode(FILE * output, xmlNodePtr node, int depth)
Packit Service a31ea6
{
Packit Service a31ea6
    xmlDebugCtxt ctxt;
Packit Service a31ea6
Packit Service a31ea6
    if (output == NULL) return;
Packit Service a31ea6
    xmlCtxtDumpInitCtxt(&ctxt);
Packit Service a31ea6
    ctxt.output = output;
Packit Service a31ea6
    ctxt.depth = depth;
Packit Service a31ea6
    xmlCtxtDumpOneNode(&ctxt, node);
Packit Service a31ea6
    xmlCtxtDumpCleanCtxt(&ctxt);
Packit Service a31ea6
}
Packit Service a31ea6
Packit Service a31ea6
/**
Packit Service a31ea6
 * xmlDebugDumpNode:
Packit Service a31ea6
 * @output:  the FILE * for the output
Packit Service a31ea6
 * @node:  the node
Packit Service a31ea6
 * @depth:  the indentation level.
Packit Service a31ea6
 *
Packit Service a31ea6
 * Dumps debug information for the element node, it is recursive
Packit Service a31ea6
 */
Packit Service a31ea6
void
Packit Service a31ea6
xmlDebugDumpNode(FILE * output, xmlNodePtr node, int depth)
Packit Service a31ea6
{
Packit Service a31ea6
    xmlDebugCtxt ctxt;
Packit Service a31ea6
Packit Service a31ea6
    if (output == NULL)
Packit Service a31ea6
	output = stdout;
Packit Service a31ea6
    xmlCtxtDumpInitCtxt(&ctxt);
Packit Service a31ea6
    ctxt.output = output;
Packit Service a31ea6
    ctxt.depth = depth;
Packit Service a31ea6
    xmlCtxtDumpNode(&ctxt, node);
Packit Service a31ea6
    xmlCtxtDumpCleanCtxt(&ctxt);
Packit Service a31ea6
}
Packit Service a31ea6
Packit Service a31ea6
/**
Packit Service a31ea6
 * xmlDebugDumpNodeList:
Packit Service a31ea6
 * @output:  the FILE * for the output
Packit Service a31ea6
 * @node:  the node list
Packit Service a31ea6
 * @depth:  the indentation level.
Packit Service a31ea6
 *
Packit Service a31ea6
 * Dumps debug information for the list of element node, it is recursive
Packit Service a31ea6
 */
Packit Service a31ea6
void
Packit Service a31ea6
xmlDebugDumpNodeList(FILE * output, xmlNodePtr node, int depth)
Packit Service a31ea6
{
Packit Service a31ea6
    xmlDebugCtxt ctxt;
Packit Service a31ea6
Packit Service a31ea6
    if (output == NULL)
Packit Service a31ea6
	output = stdout;
Packit Service a31ea6
    xmlCtxtDumpInitCtxt(&ctxt);
Packit Service a31ea6
    ctxt.output = output;
Packit Service a31ea6
    ctxt.depth = depth;
Packit Service a31ea6
    xmlCtxtDumpNodeList(&ctxt, node);
Packit Service a31ea6
    xmlCtxtDumpCleanCtxt(&ctxt);
Packit Service a31ea6
}
Packit Service a31ea6
Packit Service a31ea6
/**
Packit Service a31ea6
 * xmlDebugDumpDocumentHead:
Packit Service a31ea6
 * @output:  the FILE * for the output
Packit Service a31ea6
 * @doc:  the document
Packit Service a31ea6
 *
Packit Service a31ea6
 * Dumps debug information cncerning the document, not recursive
Packit Service a31ea6
 */
Packit Service a31ea6
void
Packit Service a31ea6
xmlDebugDumpDocumentHead(FILE * output, xmlDocPtr doc)
Packit Service a31ea6
{
Packit Service a31ea6
    xmlDebugCtxt ctxt;
Packit Service a31ea6
Packit Service a31ea6
    if (output == NULL)
Packit Service a31ea6
	output = stdout;
Packit Service a31ea6
    xmlCtxtDumpInitCtxt(&ctxt);
Packit Service a31ea6
    ctxt.options |= DUMP_TEXT_TYPE;
Packit Service a31ea6
    ctxt.output = output;
Packit Service a31ea6
    xmlCtxtDumpDocumentHead(&ctxt, doc);
Packit Service a31ea6
    xmlCtxtDumpCleanCtxt(&ctxt);
Packit Service a31ea6
}
Packit Service a31ea6
Packit Service a31ea6
/**
Packit Service a31ea6
 * xmlDebugDumpDocument:
Packit Service a31ea6
 * @output:  the FILE * for the output
Packit Service a31ea6
 * @doc:  the document
Packit Service a31ea6
 *
Packit Service a31ea6
 * Dumps debug information for the document, it's recursive
Packit Service a31ea6
 */
Packit Service a31ea6
void
Packit Service a31ea6
xmlDebugDumpDocument(FILE * output, xmlDocPtr doc)
Packit Service a31ea6
{
Packit Service a31ea6
    xmlDebugCtxt ctxt;
Packit Service a31ea6
Packit Service a31ea6
    if (output == NULL)
Packit Service a31ea6
	output = stdout;
Packit Service a31ea6
    xmlCtxtDumpInitCtxt(&ctxt);
Packit Service a31ea6
    ctxt.options |= DUMP_TEXT_TYPE;
Packit Service a31ea6
    ctxt.output = output;
Packit Service a31ea6
    xmlCtxtDumpDocument(&ctxt, doc);
Packit Service a31ea6
    xmlCtxtDumpCleanCtxt(&ctxt);
Packit Service a31ea6
}
Packit Service a31ea6
Packit Service a31ea6
/**
Packit Service a31ea6
 * xmlDebugDumpDTD:
Packit Service a31ea6
 * @output:  the FILE * for the output
Packit Service a31ea6
 * @dtd:  the DTD
Packit Service a31ea6
 *
Packit Service a31ea6
 * Dumps debug information for the DTD
Packit Service a31ea6
 */
Packit Service a31ea6
void
Packit Service a31ea6
xmlDebugDumpDTD(FILE * output, xmlDtdPtr dtd)
Packit Service a31ea6
{
Packit Service a31ea6
    xmlDebugCtxt ctxt;
Packit Service a31ea6
Packit Service a31ea6
    if (output == NULL)
Packit Service a31ea6
	output = stdout;
Packit Service a31ea6
    xmlCtxtDumpInitCtxt(&ctxt);
Packit Service a31ea6
    ctxt.options |= DUMP_TEXT_TYPE;
Packit Service a31ea6
    ctxt.output = output;
Packit Service a31ea6
    xmlCtxtDumpDTD(&ctxt, dtd);
Packit Service a31ea6
    xmlCtxtDumpCleanCtxt(&ctxt);
Packit Service a31ea6
}
Packit Service a31ea6
Packit Service a31ea6
/************************************************************************
Packit Service a31ea6
 *									*
Packit Service a31ea6
 *			Public entry points for checkings		*
Packit Service a31ea6
 *									*
Packit Service a31ea6
 ************************************************************************/
Packit Service a31ea6
Packit Service a31ea6
/**
Packit Service a31ea6
 * xmlDebugCheckDocument:
Packit Service a31ea6
 * @output:  the FILE * for the output
Packit Service a31ea6
 * @doc:  the document
Packit Service a31ea6
 *
Packit Service a31ea6
 * Check the document for potential content problems, and output
Packit Service a31ea6
 * the errors to @output
Packit Service a31ea6
 *
Packit Service a31ea6
 * Returns the number of errors found
Packit Service a31ea6
 */
Packit Service a31ea6
int
Packit Service a31ea6
xmlDebugCheckDocument(FILE * output, xmlDocPtr doc)
Packit Service a31ea6
{
Packit Service a31ea6
    xmlDebugCtxt ctxt;
Packit Service a31ea6
Packit Service a31ea6
    if (output == NULL)
Packit Service a31ea6
	output = stdout;
Packit Service a31ea6
    xmlCtxtDumpInitCtxt(&ctxt);
Packit Service a31ea6
    ctxt.output = output;
Packit Service a31ea6
    ctxt.check = 1;
Packit Service a31ea6
    xmlCtxtDumpDocument(&ctxt, doc);
Packit Service a31ea6
    xmlCtxtDumpCleanCtxt(&ctxt);
Packit Service a31ea6
    return(ctxt.errors);
Packit Service a31ea6
}
Packit Service a31ea6
Packit Service a31ea6
/************************************************************************
Packit Service a31ea6
 *									*
Packit Service a31ea6
 *			Helpers for Shell				*
Packit Service a31ea6
 *									*
Packit Service a31ea6
 ************************************************************************/
Packit Service a31ea6
Packit Service a31ea6
/**
Packit Service a31ea6
 * xmlLsCountNode:
Packit Service a31ea6
 * @node:  the node to count
Packit Service a31ea6
 *
Packit Service a31ea6
 * Count the children of @node.
Packit Service a31ea6
 *
Packit Service a31ea6
 * Returns the number of children of @node.
Packit Service a31ea6
 */
Packit Service a31ea6
int
Packit Service a31ea6
xmlLsCountNode(xmlNodePtr node) {
Packit Service a31ea6
    int ret = 0;
Packit Service a31ea6
    xmlNodePtr list = NULL;
Packit Service a31ea6
Packit Service a31ea6
    if (node == NULL)
Packit Service a31ea6
	return(0);
Packit Service a31ea6
Packit Service a31ea6
    switch (node->type) {
Packit Service a31ea6
	case XML_ELEMENT_NODE:
Packit Service a31ea6
	    list = node->children;
Packit Service a31ea6
	    break;
Packit Service a31ea6
	case XML_DOCUMENT_NODE:
Packit Service a31ea6
	case XML_HTML_DOCUMENT_NODE:
Packit Service a31ea6
#ifdef LIBXML_DOCB_ENABLED
Packit Service a31ea6
	case XML_DOCB_DOCUMENT_NODE:
Packit Service a31ea6
#endif
Packit Service a31ea6
	    list = ((xmlDocPtr) node)->children;
Packit Service a31ea6
	    break;
Packit Service a31ea6
	case XML_ATTRIBUTE_NODE:
Packit Service a31ea6
	    list = ((xmlAttrPtr) node)->children;
Packit Service a31ea6
	    break;
Packit Service a31ea6
	case XML_TEXT_NODE:
Packit Service a31ea6
	case XML_CDATA_SECTION_NODE:
Packit Service a31ea6
	case XML_PI_NODE:
Packit Service a31ea6
	case XML_COMMENT_NODE:
Packit Service a31ea6
	    if (node->content != NULL) {
Packit Service a31ea6
		ret = xmlStrlen(node->content);
Packit Service a31ea6
            }
Packit Service a31ea6
	    break;
Packit Service a31ea6
	case XML_ENTITY_REF_NODE:
Packit Service a31ea6
	case XML_DOCUMENT_TYPE_NODE:
Packit Service a31ea6
	case XML_ENTITY_NODE:
Packit Service a31ea6
	case XML_DOCUMENT_FRAG_NODE:
Packit Service a31ea6
	case XML_NOTATION_NODE:
Packit Service a31ea6
	case XML_DTD_NODE:
Packit Service a31ea6
        case XML_ELEMENT_DECL:
Packit Service a31ea6
        case XML_ATTRIBUTE_DECL:
Packit Service a31ea6
        case XML_ENTITY_DECL:
Packit Service a31ea6
	case XML_NAMESPACE_DECL:
Packit Service a31ea6
	case XML_XINCLUDE_START:
Packit Service a31ea6
	case XML_XINCLUDE_END:
Packit Service a31ea6
	    ret = 1;
Packit Service a31ea6
	    break;
Packit Service a31ea6
    }
Packit Service a31ea6
    for (;list != NULL;ret++)
Packit Service a31ea6
        list = list->next;
Packit Service a31ea6
    return(ret);
Packit Service a31ea6
}
Packit Service a31ea6
Packit Service a31ea6
/**
Packit Service a31ea6
 * xmlLsOneNode:
Packit Service a31ea6
 * @output:  the FILE * for the output
Packit Service a31ea6
 * @node:  the node to dump
Packit Service a31ea6
 *
Packit Service a31ea6
 * Dump to @output the type and name of @node.
Packit Service a31ea6
 */
Packit Service a31ea6
void
Packit Service a31ea6
xmlLsOneNode(FILE *output, xmlNodePtr node) {
Packit Service a31ea6
    if (output == NULL) return;
Packit Service a31ea6
    if (node == NULL) {
Packit Service a31ea6
	fprintf(output, "NULL\n");
Packit Service a31ea6
	return;
Packit Service a31ea6
    }
Packit Service a31ea6
    switch (node->type) {
Packit Service a31ea6
	case XML_ELEMENT_NODE:
Packit Service a31ea6
	    fprintf(output, "-");
Packit Service a31ea6
	    break;
Packit Service a31ea6
	case XML_ATTRIBUTE_NODE:
Packit Service a31ea6
	    fprintf(output, "a");
Packit Service a31ea6
	    break;
Packit Service a31ea6
	case XML_TEXT_NODE:
Packit Service a31ea6
	    fprintf(output, "t");
Packit Service a31ea6
	    break;
Packit Service a31ea6
	case XML_CDATA_SECTION_NODE:
Packit Service a31ea6
	    fprintf(output, "C");
Packit Service a31ea6
	    break;
Packit Service a31ea6
	case XML_ENTITY_REF_NODE:
Packit Service a31ea6
	    fprintf(output, "e");
Packit Service a31ea6
	    break;
Packit Service a31ea6
	case XML_ENTITY_NODE:
Packit Service a31ea6
	    fprintf(output, "E");
Packit Service a31ea6
	    break;
Packit Service a31ea6
	case XML_PI_NODE:
Packit Service a31ea6
	    fprintf(output, "p");
Packit Service a31ea6
	    break;
Packit Service a31ea6
	case XML_COMMENT_NODE:
Packit Service a31ea6
	    fprintf(output, "c");
Packit Service a31ea6
	    break;
Packit Service a31ea6
	case XML_DOCUMENT_NODE:
Packit Service a31ea6
	    fprintf(output, "d");
Packit Service a31ea6
	    break;
Packit Service a31ea6
	case XML_HTML_DOCUMENT_NODE:
Packit Service a31ea6
	    fprintf(output, "h");
Packit Service a31ea6
	    break;
Packit Service a31ea6
	case XML_DOCUMENT_TYPE_NODE:
Packit Service a31ea6
	    fprintf(output, "T");
Packit Service a31ea6
	    break;
Packit Service a31ea6
	case XML_DOCUMENT_FRAG_NODE:
Packit Service a31ea6
	    fprintf(output, "F");
Packit Service a31ea6
	    break;
Packit Service a31ea6
	case XML_NOTATION_NODE:
Packit Service a31ea6
	    fprintf(output, "N");
Packit Service a31ea6
	    break;
Packit Service a31ea6
	case XML_NAMESPACE_DECL:
Packit Service a31ea6
	    fprintf(output, "n");
Packit Service a31ea6
	    break;
Packit Service a31ea6
	default:
Packit Service a31ea6
	    fprintf(output, "?");
Packit Service a31ea6
    }
Packit Service a31ea6
    if (node->type != XML_NAMESPACE_DECL) {
Packit Service a31ea6
	if (node->properties != NULL)
Packit Service a31ea6
	    fprintf(output, "a");
Packit Service a31ea6
	else
Packit Service a31ea6
	    fprintf(output, "-");
Packit Service a31ea6
	if (node->nsDef != NULL)
Packit Service a31ea6
	    fprintf(output, "n");
Packit Service a31ea6
	else
Packit Service a31ea6
	    fprintf(output, "-");
Packit Service a31ea6
    }
Packit Service a31ea6
Packit Service a31ea6
    fprintf(output, " %8d ", xmlLsCountNode(node));
Packit Service a31ea6
Packit Service a31ea6
    switch (node->type) {
Packit Service a31ea6
	case XML_ELEMENT_NODE:
Packit Service a31ea6
	    if (node->name != NULL) {
Packit Service a31ea6
                if ((node->ns != NULL) && (node->ns->prefix != NULL))
Packit Service a31ea6
                    fprintf(output, "%s:", node->ns->prefix);
Packit Service a31ea6
		fprintf(output, "%s", (const char *) node->name);
Packit Service a31ea6
            }
Packit Service a31ea6
	    break;
Packit Service a31ea6
	case XML_ATTRIBUTE_NODE:
Packit Service a31ea6
	    if (node->name != NULL)
Packit Service a31ea6
		fprintf(output, "%s", (const char *) node->name);
Packit Service a31ea6
	    break;
Packit Service a31ea6
	case XML_TEXT_NODE:
Packit Service a31ea6
	    if (node->content != NULL) {
Packit Service a31ea6
		xmlDebugDumpString(output, node->content);
Packit Service a31ea6
            }
Packit Service a31ea6
	    break;
Packit Service a31ea6
	case XML_CDATA_SECTION_NODE:
Packit Service a31ea6
	    break;
Packit Service a31ea6
	case XML_ENTITY_REF_NODE:
Packit Service a31ea6
	    if (node->name != NULL)
Packit Service a31ea6
		fprintf(output, "%s", (const char *) node->name);
Packit Service a31ea6
	    break;
Packit Service a31ea6
	case XML_ENTITY_NODE:
Packit Service a31ea6
	    if (node->name != NULL)
Packit Service a31ea6
		fprintf(output, "%s", (const char *) node->name);
Packit Service a31ea6
	    break;
Packit Service a31ea6
	case XML_PI_NODE:
Packit Service a31ea6
	    if (node->name != NULL)
Packit Service a31ea6
		fprintf(output, "%s", (const char *) node->name);
Packit Service a31ea6
	    break;
Packit Service a31ea6
	case XML_COMMENT_NODE:
Packit Service a31ea6
	    break;
Packit Service a31ea6
	case XML_DOCUMENT_NODE:
Packit Service a31ea6
	    break;
Packit Service a31ea6
	case XML_HTML_DOCUMENT_NODE:
Packit Service a31ea6
	    break;
Packit Service a31ea6
	case XML_DOCUMENT_TYPE_NODE:
Packit Service a31ea6
	    break;
Packit Service a31ea6
	case XML_DOCUMENT_FRAG_NODE:
Packit Service a31ea6
	    break;
Packit Service a31ea6
	case XML_NOTATION_NODE:
Packit Service a31ea6
	    break;
Packit Service a31ea6
	case XML_NAMESPACE_DECL: {
Packit Service a31ea6
	    xmlNsPtr ns = (xmlNsPtr) node;
Packit Service a31ea6
Packit Service a31ea6
	    if (ns->prefix == NULL)
Packit Service a31ea6
		fprintf(output, "default -> %s", (char *)ns->href);
Packit Service a31ea6
	    else
Packit Service a31ea6
		fprintf(output, "%s -> %s", (char *)ns->prefix,
Packit Service a31ea6
			(char *)ns->href);
Packit Service a31ea6
	    break;
Packit Service a31ea6
	}
Packit Service a31ea6
	default:
Packit Service a31ea6
	    if (node->name != NULL)
Packit Service a31ea6
		fprintf(output, "%s", (const char *) node->name);
Packit Service a31ea6
    }
Packit Service a31ea6
    fprintf(output, "\n");
Packit Service a31ea6
}
Packit Service a31ea6
Packit Service a31ea6
/**
Packit Service a31ea6
 * xmlBoolToText:
Packit Service a31ea6
 * @boolval: a bool to turn into text
Packit Service a31ea6
 *
Packit Service a31ea6
 * Convenient way to turn bool into text
Packit Service a31ea6
 *
Packit Service a31ea6
 * Returns a pointer to either "True" or "False"
Packit Service a31ea6
 */
Packit Service a31ea6
const char *
Packit Service a31ea6
xmlBoolToText(int boolval)
Packit Service a31ea6
{
Packit Service a31ea6
    if (boolval)
Packit Service a31ea6
        return("True");
Packit Service a31ea6
    else
Packit Service a31ea6
        return("False");
Packit Service a31ea6
}
Packit Service a31ea6
Packit Service a31ea6
#ifdef LIBXML_XPATH_ENABLED
Packit Service a31ea6
/****************************************************************
Packit Service a31ea6
 *								*
Packit Service a31ea6
 *		The XML shell related functions			*
Packit Service a31ea6
 *								*
Packit Service a31ea6
 ****************************************************************/
Packit Service a31ea6
Packit Service a31ea6
Packit Service a31ea6
Packit Service a31ea6
/*
Packit Service a31ea6
 * TODO: Improvement/cleanups for the XML shell
Packit Service a31ea6
 *     - allow to shell out an editor on a subpart
Packit Service a31ea6
 *     - cleanup function registrations (with help) and calling
Packit Service a31ea6
 *     - provide registration routines
Packit Service a31ea6
 */
Packit Service a31ea6
Packit Service a31ea6
/**
Packit Service a31ea6
 * xmlShellPrintXPathError:
Packit Service a31ea6
 * @errorType: valid xpath error id
Packit Service a31ea6
 * @arg: the argument that cause xpath to fail
Packit Service a31ea6
 *
Packit Service a31ea6
 * Print the xpath error to libxml default error channel
Packit Service a31ea6
 */
Packit Service a31ea6
void
Packit Service a31ea6
xmlShellPrintXPathError(int errorType, const char *arg)
Packit Service a31ea6
{
Packit Service a31ea6
    const char *default_arg = "Result";
Packit Service a31ea6
Packit Service a31ea6
    if (!arg)
Packit Service a31ea6
        arg = default_arg;
Packit Service a31ea6
Packit Service a31ea6
    switch (errorType) {
Packit Service a31ea6
        case XPATH_UNDEFINED:
Packit Service a31ea6
            xmlGenericError(xmlGenericErrorContext,
Packit Service a31ea6
                            "%s: no such node\n", arg);
Packit Service a31ea6
            break;
Packit Service a31ea6
Packit Service a31ea6
        case XPATH_BOOLEAN:
Packit Service a31ea6
            xmlGenericError(xmlGenericErrorContext,
Packit Service a31ea6
                            "%s is a Boolean\n", arg);
Packit Service a31ea6
            break;
Packit Service a31ea6
        case XPATH_NUMBER:
Packit Service a31ea6
            xmlGenericError(xmlGenericErrorContext,
Packit Service a31ea6
                            "%s is a number\n", arg);
Packit Service a31ea6
            break;
Packit Service a31ea6
        case XPATH_STRING:
Packit Service a31ea6
            xmlGenericError(xmlGenericErrorContext,
Packit Service a31ea6
                            "%s is a string\n", arg);
Packit Service a31ea6
            break;
Packit Service a31ea6
        case XPATH_POINT:
Packit Service a31ea6
            xmlGenericError(xmlGenericErrorContext,
Packit Service a31ea6
                            "%s is a point\n", arg);
Packit Service a31ea6
            break;
Packit Service a31ea6
        case XPATH_RANGE:
Packit Service a31ea6
            xmlGenericError(xmlGenericErrorContext,
Packit Service a31ea6
                            "%s is a range\n", arg);
Packit Service a31ea6
            break;
Packit Service a31ea6
        case XPATH_LOCATIONSET:
Packit Service a31ea6
            xmlGenericError(xmlGenericErrorContext,
Packit Service a31ea6
                            "%s is a range\n", arg);
Packit Service a31ea6
            break;
Packit Service a31ea6
        case XPATH_USERS:
Packit Service a31ea6
            xmlGenericError(xmlGenericErrorContext,
Packit Service a31ea6
                            "%s is user-defined\n", arg);
Packit Service a31ea6
            break;
Packit Service a31ea6
        case XPATH_XSLT_TREE:
Packit Service a31ea6
            xmlGenericError(xmlGenericErrorContext,
Packit Service a31ea6
                            "%s is an XSLT value tree\n", arg);
Packit Service a31ea6
            break;
Packit Service a31ea6
    }
Packit Service a31ea6
#if 0
Packit Service a31ea6
    xmlGenericError(xmlGenericErrorContext,
Packit Service a31ea6
                    "Try casting the result string function (xpath builtin)\n",
Packit Service a31ea6
                    arg);
Packit Service a31ea6
#endif
Packit Service a31ea6
}
Packit Service a31ea6
Packit Service a31ea6
Packit Service a31ea6
#ifdef LIBXML_OUTPUT_ENABLED
Packit Service a31ea6
/**
Packit Service a31ea6
 * xmlShellPrintNodeCtxt:
Packit Service a31ea6
 * @ctxt : a non-null shell context
Packit Service a31ea6
 * @node : a non-null node to print to the output FILE
Packit Service a31ea6
 *
Packit Service a31ea6
 * Print node to the output FILE
Packit Service a31ea6
 */
Packit Service a31ea6
static void
Packit Service a31ea6
xmlShellPrintNodeCtxt(xmlShellCtxtPtr ctxt,xmlNodePtr node)
Packit Service a31ea6
{
Packit Service a31ea6
    FILE *fp;
Packit Service a31ea6
Packit Service a31ea6
    if (!node)
Packit Service a31ea6
        return;
Packit Service a31ea6
    if (ctxt == NULL)
Packit Service a31ea6
	fp = stdout;
Packit Service a31ea6
    else
Packit Service a31ea6
	fp = ctxt->output;
Packit Service a31ea6
Packit Service a31ea6
    if (node->type == XML_DOCUMENT_NODE)
Packit Service a31ea6
        xmlDocDump(fp, (xmlDocPtr) node);
Packit Service a31ea6
    else if (node->type == XML_ATTRIBUTE_NODE)
Packit Service a31ea6
        xmlDebugDumpAttrList(fp, (xmlAttrPtr) node, 0);
Packit Service a31ea6
    else
Packit Service a31ea6
        xmlElemDump(fp, node->doc, node);
Packit Service a31ea6
Packit Service a31ea6
    fprintf(fp, "\n");
Packit Service a31ea6
}
Packit Service a31ea6
Packit Service a31ea6
/**
Packit Service a31ea6
 * xmlShellPrintNode:
Packit Service a31ea6
 * @node : a non-null node to print to the output FILE
Packit Service a31ea6
 *
Packit Service a31ea6
 * Print node to the output FILE
Packit Service a31ea6
 */
Packit Service a31ea6
void
Packit Service a31ea6
xmlShellPrintNode(xmlNodePtr node)
Packit Service a31ea6
{
Packit Service a31ea6
    xmlShellPrintNodeCtxt(NULL, node);
Packit Service a31ea6
}
Packit Service a31ea6
#endif /* LIBXML_OUTPUT_ENABLED */
Packit Service a31ea6
Packit Service a31ea6
/**
Packit Service a31ea6
 * xmlShellPrintXPathResultCtxt:
Packit Service a31ea6
 * @ctxt: a valid shell context
Packit Service a31ea6
 * @list: a valid result generated by an xpath evaluation
Packit Service a31ea6
 *
Packit Service a31ea6
 * Prints result to the output FILE
Packit Service a31ea6
 */
Packit Service a31ea6
static void
Packit Service a31ea6
xmlShellPrintXPathResultCtxt(xmlShellCtxtPtr ctxt,xmlXPathObjectPtr list)
Packit Service a31ea6
{
Packit Service a31ea6
    if (!ctxt)
Packit Service a31ea6
       return;
Packit Service a31ea6
Packit Service a31ea6
    if (list != NULL) {
Packit Service a31ea6
        switch (list->type) {
Packit Service a31ea6
            case XPATH_NODESET:{
Packit Service a31ea6
#ifdef LIBXML_OUTPUT_ENABLED
Packit Service a31ea6
                    int indx;
Packit Service a31ea6
Packit Service a31ea6
                    if (list->nodesetval) {
Packit Service a31ea6
                        for (indx = 0; indx < list->nodesetval->nodeNr;
Packit Service a31ea6
                             indx++) {
Packit Service a31ea6
                            xmlShellPrintNodeCtxt(ctxt,
Packit Service a31ea6
				    list->nodesetval->nodeTab[indx]);
Packit Service a31ea6
                        }
Packit Service a31ea6
                    } else {
Packit Service a31ea6
                        xmlGenericError(xmlGenericErrorContext,
Packit Service a31ea6
                                        "Empty node set\n");
Packit Service a31ea6
                    }
Packit Service a31ea6
                    break;
Packit Service a31ea6
#else
Packit Service a31ea6
		    xmlGenericError(xmlGenericErrorContext,
Packit Service a31ea6
				    "Node set\n");
Packit Service a31ea6
#endif /* LIBXML_OUTPUT_ENABLED */
Packit Service a31ea6
                }
Packit Service a31ea6
            case XPATH_BOOLEAN:
Packit Service a31ea6
                xmlGenericError(xmlGenericErrorContext,
Packit Service a31ea6
                                "Is a Boolean:%s\n",
Packit Service a31ea6
                                xmlBoolToText(list->boolval));
Packit Service a31ea6
                break;
Packit Service a31ea6
            case XPATH_NUMBER:
Packit Service a31ea6
                xmlGenericError(xmlGenericErrorContext,
Packit Service a31ea6
                                "Is a number:%0g\n", list->floatval);
Packit Service a31ea6
                break;
Packit Service a31ea6
            case XPATH_STRING:
Packit Service a31ea6
                xmlGenericError(xmlGenericErrorContext,
Packit Service a31ea6
                                "Is a string:%s\n", list->stringval);
Packit Service a31ea6
                break;
Packit Service a31ea6
Packit Service a31ea6
            default:
Packit Service a31ea6
                xmlShellPrintXPathError(list->type, NULL);
Packit Service a31ea6
        }
Packit Service a31ea6
    }
Packit Service a31ea6
}
Packit Service a31ea6
Packit Service a31ea6
/**
Packit Service a31ea6
 * xmlShellPrintXPathResult:
Packit Service a31ea6
 * @list: a valid result generated by an xpath evaluation
Packit Service a31ea6
 *
Packit Service a31ea6
 * Prints result to the output FILE
Packit Service a31ea6
 */
Packit Service a31ea6
void
Packit Service a31ea6
xmlShellPrintXPathResult(xmlXPathObjectPtr list)
Packit Service a31ea6
{
Packit Service a31ea6
    xmlShellPrintXPathResultCtxt(NULL, list);
Packit Service a31ea6
}
Packit Service a31ea6
Packit Service a31ea6
/**
Packit Service a31ea6
 * xmlShellList:
Packit Service a31ea6
 * @ctxt:  the shell context
Packit Service a31ea6
 * @arg:  unused
Packit Service a31ea6
 * @node:  a node
Packit Service a31ea6
 * @node2:  unused
Packit Service a31ea6
 *
Packit Service a31ea6
 * Implements the XML shell function "ls"
Packit Service a31ea6
 * Does an Unix like listing of the given node (like a directory)
Packit Service a31ea6
 *
Packit Service a31ea6
 * Returns 0
Packit Service a31ea6
 */
Packit Service a31ea6
int
Packit Service a31ea6
xmlShellList(xmlShellCtxtPtr ctxt,
Packit Service a31ea6
             char *arg ATTRIBUTE_UNUSED, xmlNodePtr node,
Packit Service a31ea6
             xmlNodePtr node2 ATTRIBUTE_UNUSED)
Packit Service a31ea6
{
Packit Service a31ea6
    xmlNodePtr cur;
Packit Service a31ea6
    if (!ctxt)
Packit Service a31ea6
        return (0);
Packit Service a31ea6
    if (node == NULL) {
Packit Service a31ea6
	fprintf(ctxt->output, "NULL\n");
Packit Service a31ea6
	return (0);
Packit Service a31ea6
    }
Packit Service a31ea6
    if ((node->type == XML_DOCUMENT_NODE) ||
Packit Service a31ea6
        (node->type == XML_HTML_DOCUMENT_NODE)) {
Packit Service a31ea6
        cur = ((xmlDocPtr) node)->children;
Packit Service a31ea6
    } else if (node->type == XML_NAMESPACE_DECL) {
Packit Service a31ea6
        xmlLsOneNode(ctxt->output, node);
Packit Service a31ea6
        return (0);
Packit Service a31ea6
    } else if (node->children != NULL) {
Packit Service a31ea6
        cur = node->children;
Packit Service a31ea6
    } else {
Packit Service a31ea6
        xmlLsOneNode(ctxt->output, node);
Packit Service a31ea6
        return (0);
Packit Service a31ea6
    }
Packit Service a31ea6
    while (cur != NULL) {
Packit Service a31ea6
        xmlLsOneNode(ctxt->output, cur);
Packit Service a31ea6
        cur = cur->next;
Packit Service a31ea6
    }
Packit Service a31ea6
    return (0);
Packit Service a31ea6
}
Packit Service a31ea6
Packit Service a31ea6
/**
Packit Service a31ea6
 * xmlShellBase:
Packit Service a31ea6
 * @ctxt:  the shell context
Packit Service a31ea6
 * @arg:  unused
Packit Service a31ea6
 * @node:  a node
Packit Service a31ea6
 * @node2:  unused
Packit Service a31ea6
 *
Packit Service a31ea6
 * Implements the XML shell function "base"
Packit Service a31ea6
 * dumps the current XML base of the node
Packit Service a31ea6
 *
Packit Service a31ea6
 * Returns 0
Packit Service a31ea6
 */
Packit Service a31ea6
int
Packit Service a31ea6
xmlShellBase(xmlShellCtxtPtr ctxt,
Packit Service a31ea6
             char *arg ATTRIBUTE_UNUSED, xmlNodePtr node,
Packit Service a31ea6
             xmlNodePtr node2 ATTRIBUTE_UNUSED)
Packit Service a31ea6
{
Packit Service a31ea6
    xmlChar *base;
Packit Service a31ea6
    if (!ctxt)
Packit Service a31ea6
        return 0;
Packit Service a31ea6
    if (node == NULL) {
Packit Service a31ea6
	fprintf(ctxt->output, "NULL\n");
Packit Service a31ea6
	return (0);
Packit Service a31ea6
    }
Packit Service a31ea6
Packit Service a31ea6
    base = xmlNodeGetBase(node->doc, node);
Packit Service a31ea6
Packit Service a31ea6
    if (base == NULL) {
Packit Service a31ea6
        fprintf(ctxt->output, " No base found !!!\n");
Packit Service a31ea6
    } else {
Packit Service a31ea6
        fprintf(ctxt->output, "%s\n", base);
Packit Service a31ea6
        xmlFree(base);
Packit Service a31ea6
    }
Packit Service a31ea6
    return (0);
Packit Service a31ea6
}
Packit Service a31ea6
Packit Service a31ea6
#ifdef LIBXML_TREE_ENABLED
Packit Service a31ea6
/**
Packit Service a31ea6
 * xmlShellSetBase:
Packit Service a31ea6
 * @ctxt:  the shell context
Packit Service a31ea6
 * @arg:  the new base
Packit Service a31ea6
 * @node:  a node
Packit Service a31ea6
 * @node2:  unused
Packit Service a31ea6
 *
Packit Service a31ea6
 * Implements the XML shell function "setbase"
Packit Service a31ea6
 * change the current XML base of the node
Packit Service a31ea6
 *
Packit Service a31ea6
 * Returns 0
Packit Service a31ea6
 */
Packit Service a31ea6
static int
Packit Service a31ea6
xmlShellSetBase(xmlShellCtxtPtr ctxt ATTRIBUTE_UNUSED,
Packit Service a31ea6
             char *arg ATTRIBUTE_UNUSED, xmlNodePtr node,
Packit Service a31ea6
             xmlNodePtr node2 ATTRIBUTE_UNUSED)
Packit Service a31ea6
{
Packit Service a31ea6
    xmlNodeSetBase(node, (xmlChar*) arg);
Packit Service a31ea6
    return (0);
Packit Service a31ea6
}
Packit Service a31ea6
#endif
Packit Service a31ea6
Packit Service a31ea6
#ifdef LIBXML_XPATH_ENABLED
Packit Service a31ea6
/**
Packit Service a31ea6
 * xmlShellRegisterNamespace:
Packit Service a31ea6
 * @ctxt:  the shell context
Packit Service a31ea6
 * @arg:  a string in prefix=nsuri format
Packit Service a31ea6
 * @node:  unused
Packit Service a31ea6
 * @node2:  unused
Packit Service a31ea6
 *
Packit Service a31ea6
 * Implements the XML shell function "setns"
Packit Service a31ea6
 * register/unregister a prefix=namespace pair
Packit Service a31ea6
 * on the XPath context
Packit Service a31ea6
 *
Packit Service a31ea6
 * Returns 0 on success and a negative value otherwise.
Packit Service a31ea6
 */
Packit Service a31ea6
static int
Packit Service a31ea6
xmlShellRegisterNamespace(xmlShellCtxtPtr ctxt, char *arg,
Packit Service a31ea6
      xmlNodePtr node ATTRIBUTE_UNUSED, xmlNodePtr node2 ATTRIBUTE_UNUSED)
Packit Service a31ea6
{
Packit Service a31ea6
    xmlChar* nsListDup;
Packit Service a31ea6
    xmlChar* prefix;
Packit Service a31ea6
    xmlChar* href;
Packit Service a31ea6
    xmlChar* next;
Packit Service a31ea6
Packit Service a31ea6
    nsListDup = xmlStrdup((xmlChar *) arg);
Packit Service a31ea6
    next = nsListDup;
Packit Service a31ea6
    while(next != NULL) {
Packit Service a31ea6
	/* skip spaces */
Packit Service a31ea6
	/*while((*next) == ' ') next++;*/
Packit Service a31ea6
	if((*next) == '\0') break;
Packit Service a31ea6
Packit Service a31ea6
	/* find prefix */
Packit Service a31ea6
	prefix = next;
Packit Service a31ea6
	next = (xmlChar*)xmlStrchr(next, '=');
Packit Service a31ea6
	if(next == NULL) {
Packit Service a31ea6
	    fprintf(ctxt->output, "setns: prefix=[nsuri] required\n");
Packit Service a31ea6
	    xmlFree(nsListDup);
Packit Service a31ea6
	    return(-1);
Packit Service a31ea6
	}
Packit Service a31ea6
	*(next++) = '\0';
Packit Service a31ea6
Packit Service a31ea6
	/* find href */
Packit Service a31ea6
	href = next;
Packit Service a31ea6
	next = (xmlChar*)xmlStrchr(next, ' ');
Packit Service a31ea6
	if(next != NULL) {
Packit Service a31ea6
	    *(next++) = '\0';
Packit Service a31ea6
	}
Packit Service a31ea6
Packit Service a31ea6
	/* do register namespace */
Packit Service a31ea6
	if(xmlXPathRegisterNs(ctxt->pctxt, prefix, href) != 0) {
Packit Service a31ea6
	    fprintf(ctxt->output,"Error: unable to register NS with prefix=\"%s\" and href=\"%s\"\n", prefix, href);
Packit Service a31ea6
	    xmlFree(nsListDup);
Packit Service a31ea6
	    return(-1);
Packit Service a31ea6
	}
Packit Service a31ea6
    }
Packit Service a31ea6
Packit Service a31ea6
    xmlFree(nsListDup);
Packit Service a31ea6
    return(0);
Packit Service a31ea6
}
Packit Service a31ea6
/**
Packit Service a31ea6
 * xmlShellRegisterRootNamespaces:
Packit Service a31ea6
 * @ctxt:  the shell context
Packit Service a31ea6
 * @arg:  unused
Packit Service a31ea6
 * @node:  the root element
Packit Service a31ea6
 * @node2:  unused
Packit Service a31ea6
 *
Packit Service a31ea6
 * Implements the XML shell function "setrootns"
Packit Service a31ea6
 * which registers all namespaces declarations found on the root element.
Packit Service a31ea6
 *
Packit Service a31ea6
 * Returns 0 on success and a negative value otherwise.
Packit Service a31ea6
 */
Packit Service a31ea6
static int
Packit Service a31ea6
xmlShellRegisterRootNamespaces(xmlShellCtxtPtr ctxt, char *arg ATTRIBUTE_UNUSED,
Packit Service a31ea6
      xmlNodePtr root, xmlNodePtr node2 ATTRIBUTE_UNUSED)
Packit Service a31ea6
{
Packit Service a31ea6
    xmlNsPtr ns;
Packit Service a31ea6
Packit Service a31ea6
    if ((root == NULL) || (root->type != XML_ELEMENT_NODE) ||
Packit Service a31ea6
        (root->nsDef == NULL) || (ctxt == NULL) || (ctxt->pctxt == NULL))
Packit Service a31ea6
	return(-1);
Packit Service a31ea6
    ns = root->nsDef;
Packit Service a31ea6
    while (ns != NULL) {
Packit Service a31ea6
        if (ns->prefix == NULL)
Packit Service a31ea6
	    xmlXPathRegisterNs(ctxt->pctxt, BAD_CAST "defaultns", ns->href);
Packit Service a31ea6
	else
Packit Service a31ea6
	    xmlXPathRegisterNs(ctxt->pctxt, ns->prefix, ns->href);
Packit Service a31ea6
        ns = ns->next;
Packit Service a31ea6
    }
Packit Service a31ea6
    return(0);
Packit Service a31ea6
}
Packit Service a31ea6
#endif
Packit Service a31ea6
Packit Service a31ea6
/**
Packit Service a31ea6
 * xmlShellGrep:
Packit Service a31ea6
 * @ctxt:  the shell context
Packit Service a31ea6
 * @arg:  the string or regular expression to find
Packit Service a31ea6
 * @node:  a node
Packit Service a31ea6
 * @node2:  unused
Packit Service a31ea6
 *
Packit Service a31ea6
 * Implements the XML shell function "grep"
Packit Service a31ea6
 * dumps informations about the node (namespace, attributes, content).
Packit Service a31ea6
 *
Packit Service a31ea6
 * Returns 0
Packit Service a31ea6
 */
Packit Service a31ea6
static int
Packit Service a31ea6
xmlShellGrep(xmlShellCtxtPtr ctxt ATTRIBUTE_UNUSED,
Packit Service a31ea6
            char *arg, xmlNodePtr node, xmlNodePtr node2 ATTRIBUTE_UNUSED)
Packit Service a31ea6
{
Packit Service a31ea6
    if (!ctxt)
Packit Service a31ea6
        return (0);
Packit Service a31ea6
    if (node == NULL)
Packit Service a31ea6
	return (0);
Packit Service a31ea6
    if (arg == NULL)
Packit Service a31ea6
	return (0);
Packit Service a31ea6
#ifdef LIBXML_REGEXP_ENABLED
Packit Service a31ea6
    if ((xmlStrchr((xmlChar *) arg, '?')) ||
Packit Service a31ea6
	(xmlStrchr((xmlChar *) arg, '*')) ||
Packit Service a31ea6
	(xmlStrchr((xmlChar *) arg, '.')) ||
Packit Service a31ea6
	(xmlStrchr((xmlChar *) arg, '['))) {
Packit Service a31ea6
    }
Packit Service a31ea6
#endif
Packit Service a31ea6
    while (node != NULL) {
Packit Service a31ea6
        if (node->type == XML_COMMENT_NODE) {
Packit Service a31ea6
	    if (xmlStrstr(node->content, (xmlChar *) arg)) {
Packit Service a31ea6
Packit Service a31ea6
		fprintf(ctxt->output, "%s : ", xmlGetNodePath(node));
Packit Service a31ea6
                xmlShellList(ctxt, NULL, node, NULL);
Packit Service a31ea6
	    }
Packit Service a31ea6
        } else if (node->type == XML_TEXT_NODE) {
Packit Service a31ea6
	    if (xmlStrstr(node->content, (xmlChar *) arg)) {
Packit Service a31ea6
Packit Service a31ea6
		fprintf(ctxt->output, "%s : ", xmlGetNodePath(node->parent));
Packit Service a31ea6
                xmlShellList(ctxt, NULL, node->parent, NULL);
Packit Service a31ea6
	    }
Packit Service a31ea6
        }
Packit Service a31ea6
Packit Service a31ea6
        /*
Packit Service a31ea6
         * Browse the full subtree, deep first
Packit Service a31ea6
         */
Packit Service a31ea6
Packit Service a31ea6
        if ((node->type == XML_DOCUMENT_NODE) ||
Packit Service a31ea6
            (node->type == XML_HTML_DOCUMENT_NODE)) {
Packit Service a31ea6
            node = ((xmlDocPtr) node)->children;
Packit Service a31ea6
        } else if ((node->children != NULL)
Packit Service a31ea6
                   && (node->type != XML_ENTITY_REF_NODE)) {
Packit Service a31ea6
            /* deep first */
Packit Service a31ea6
            node = node->children;
Packit Service a31ea6
        } else if (node->next != NULL) {
Packit Service a31ea6
            /* then siblings */
Packit Service a31ea6
            node = node->next;
Packit Service a31ea6
        } else {
Packit Service a31ea6
            /* go up to parents->next if needed */
Packit Service a31ea6
            while (node != NULL) {
Packit Service a31ea6
                if (node->parent != NULL) {
Packit Service a31ea6
                    node = node->parent;
Packit Service a31ea6
                }
Packit Service a31ea6
                if (node->next != NULL) {
Packit Service a31ea6
                    node = node->next;
Packit Service a31ea6
                    break;
Packit Service a31ea6
                }
Packit Service a31ea6
                if (node->parent == NULL) {
Packit Service a31ea6
                    node = NULL;
Packit Service a31ea6
                    break;
Packit Service a31ea6
                }
Packit Service a31ea6
            }
Packit Service a31ea6
	}
Packit Service a31ea6
    }
Packit Service a31ea6
    return (0);
Packit Service a31ea6
}
Packit Service a31ea6
Packit Service a31ea6
/**
Packit Service a31ea6
 * xmlShellDir:
Packit Service a31ea6
 * @ctxt:  the shell context
Packit Service a31ea6
 * @arg:  unused
Packit Service a31ea6
 * @node:  a node
Packit Service a31ea6
 * @node2:  unused
Packit Service a31ea6
 *
Packit Service a31ea6
 * Implements the XML shell function "dir"
Packit Service a31ea6
 * dumps informations about the node (namespace, attributes, content).
Packit Service a31ea6
 *
Packit Service a31ea6
 * Returns 0
Packit Service a31ea6
 */
Packit Service a31ea6
int
Packit Service a31ea6
xmlShellDir(xmlShellCtxtPtr ctxt ATTRIBUTE_UNUSED,
Packit Service a31ea6
            char *arg ATTRIBUTE_UNUSED, xmlNodePtr node,
Packit Service a31ea6
            xmlNodePtr node2 ATTRIBUTE_UNUSED)
Packit Service a31ea6
{
Packit Service a31ea6
    if (!ctxt)
Packit Service a31ea6
        return (0);
Packit Service a31ea6
    if (node == NULL) {
Packit Service a31ea6
	fprintf(ctxt->output, "NULL\n");
Packit Service a31ea6
	return (0);
Packit Service a31ea6
    }
Packit Service a31ea6
    if ((node->type == XML_DOCUMENT_NODE) ||
Packit Service a31ea6
        (node->type == XML_HTML_DOCUMENT_NODE)) {
Packit Service a31ea6
        xmlDebugDumpDocumentHead(ctxt->output, (xmlDocPtr) node);
Packit Service a31ea6
    } else if (node->type == XML_ATTRIBUTE_NODE) {
Packit Service a31ea6
        xmlDebugDumpAttr(ctxt->output, (xmlAttrPtr) node, 0);
Packit Service a31ea6
    } else {
Packit Service a31ea6
        xmlDebugDumpOneNode(ctxt->output, node, 0);
Packit Service a31ea6
    }
Packit Service a31ea6
    return (0);
Packit Service a31ea6
}
Packit Service a31ea6
Packit Service a31ea6
/**
Packit Service a31ea6
 * xmlShellSetContent:
Packit Service a31ea6
 * @ctxt:  the shell context
Packit Service a31ea6
 * @value:  the content as a string
Packit Service a31ea6
 * @node:  a node
Packit Service a31ea6
 * @node2:  unused
Packit Service a31ea6
 *
Packit Service a31ea6
 * Implements the XML shell function "dir"
Packit Service a31ea6
 * dumps informations about the node (namespace, attributes, content).
Packit Service a31ea6
 *
Packit Service a31ea6
 * Returns 0
Packit Service a31ea6
 */
Packit Service a31ea6
static int
Packit Service a31ea6
xmlShellSetContent(xmlShellCtxtPtr ctxt ATTRIBUTE_UNUSED,
Packit Service a31ea6
            char *value, xmlNodePtr node,
Packit Service a31ea6
            xmlNodePtr node2 ATTRIBUTE_UNUSED)
Packit Service a31ea6
{
Packit Service a31ea6
    xmlNodePtr results;
Packit Service a31ea6
    xmlParserErrors ret;
Packit Service a31ea6
Packit Service a31ea6
    if (!ctxt)
Packit Service a31ea6
        return (0);
Packit Service a31ea6
    if (node == NULL) {
Packit Service a31ea6
	fprintf(ctxt->output, "NULL\n");
Packit Service a31ea6
	return (0);
Packit Service a31ea6
    }
Packit Service a31ea6
    if (value == NULL) {
Packit Service a31ea6
        fprintf(ctxt->output, "NULL\n");
Packit Service a31ea6
	return (0);
Packit Service a31ea6
    }
Packit Service a31ea6
Packit Service a31ea6
    ret = xmlParseInNodeContext(node, value, strlen(value), 0, &results);
Packit Service a31ea6
    if (ret == XML_ERR_OK) {
Packit Service a31ea6
	if (node->children != NULL) {
Packit Service a31ea6
	    xmlFreeNodeList(node->children);
Packit Service a31ea6
	    node->children = NULL;
Packit Service a31ea6
	    node->last = NULL;
Packit Service a31ea6
	}
Packit Service a31ea6
	xmlAddChildList(node, results);
Packit Service a31ea6
    } else {
Packit Service a31ea6
        fprintf(ctxt->output, "failed to parse content\n");
Packit Service a31ea6
    }
Packit Service a31ea6
    return (0);
Packit Service a31ea6
}
Packit Service a31ea6
Packit Service a31ea6
#ifdef LIBXML_SCHEMAS_ENABLED
Packit Service a31ea6
/**
Packit Service a31ea6
 * xmlShellRNGValidate:
Packit Service a31ea6
 * @ctxt:  the shell context
Packit Service a31ea6
 * @schemas:  the path to the Relax-NG schemas
Packit Service a31ea6
 * @node:  a node
Packit Service a31ea6
 * @node2:  unused
Packit Service a31ea6
 *
Packit Service a31ea6
 * Implements the XML shell function "relaxng"
Packit Service a31ea6
 * validating the instance against a Relax-NG schemas
Packit Service a31ea6
 *
Packit Service a31ea6
 * Returns 0
Packit Service a31ea6
 */
Packit Service a31ea6
static int
Packit Service a31ea6
xmlShellRNGValidate(xmlShellCtxtPtr sctxt, char *schemas,
Packit Service a31ea6
            xmlNodePtr node ATTRIBUTE_UNUSED,
Packit Service a31ea6
	    xmlNodePtr node2 ATTRIBUTE_UNUSED)
Packit Service a31ea6
{
Packit Service a31ea6
    xmlRelaxNGPtr relaxngschemas;
Packit Service a31ea6
    xmlRelaxNGParserCtxtPtr ctxt;
Packit Service a31ea6
    xmlRelaxNGValidCtxtPtr vctxt;
Packit Service a31ea6
    int ret;
Packit Service a31ea6
Packit Service a31ea6
    ctxt = xmlRelaxNGNewParserCtxt(schemas);
Packit Service a31ea6
    xmlRelaxNGSetParserErrors(ctxt,
Packit Service a31ea6
	    (xmlRelaxNGValidityErrorFunc) fprintf,
Packit Service a31ea6
	    (xmlRelaxNGValidityWarningFunc) fprintf,
Packit Service a31ea6
	    stderr);
Packit Service a31ea6
    relaxngschemas = xmlRelaxNGParse(ctxt);
Packit Service a31ea6
    xmlRelaxNGFreeParserCtxt(ctxt);
Packit Service a31ea6
    if (relaxngschemas == NULL) {
Packit Service a31ea6
	xmlGenericError(xmlGenericErrorContext,
Packit Service a31ea6
		"Relax-NG schema %s failed to compile\n", schemas);
Packit Service a31ea6
	return(-1);
Packit Service a31ea6
    }
Packit Service a31ea6
    vctxt = xmlRelaxNGNewValidCtxt(relaxngschemas);
Packit Service a31ea6
    xmlRelaxNGSetValidErrors(vctxt,
Packit Service a31ea6
	    (xmlRelaxNGValidityErrorFunc) fprintf,
Packit Service a31ea6
	    (xmlRelaxNGValidityWarningFunc) fprintf,
Packit Service a31ea6
	    stderr);
Packit Service a31ea6
    ret = xmlRelaxNGValidateDoc(vctxt, sctxt->doc);
Packit Service a31ea6
    if (ret == 0) {
Packit Service a31ea6
	fprintf(stderr, "%s validates\n", sctxt->filename);
Packit Service a31ea6
    } else if (ret > 0) {
Packit Service a31ea6
	fprintf(stderr, "%s fails to validate\n", sctxt->filename);
Packit Service a31ea6
    } else {
Packit Service a31ea6
	fprintf(stderr, "%s validation generated an internal error\n",
Packit Service a31ea6
	       sctxt->filename);
Packit Service a31ea6
    }
Packit Service a31ea6
    xmlRelaxNGFreeValidCtxt(vctxt);
Packit Service a31ea6
    if (relaxngschemas != NULL)
Packit Service a31ea6
	xmlRelaxNGFree(relaxngschemas);
Packit Service a31ea6
    return(0);
Packit Service a31ea6
}
Packit Service a31ea6
#endif
Packit Service a31ea6
Packit Service a31ea6
#ifdef LIBXML_OUTPUT_ENABLED
Packit Service a31ea6
/**
Packit Service a31ea6
 * xmlShellCat:
Packit Service a31ea6
 * @ctxt:  the shell context
Packit Service a31ea6
 * @arg:  unused
Packit Service a31ea6
 * @node:  a node
Packit Service a31ea6
 * @node2:  unused
Packit Service a31ea6
 *
Packit Service a31ea6
 * Implements the XML shell function "cat"
Packit Service a31ea6
 * dumps the serialization node content (XML or HTML).
Packit Service a31ea6
 *
Packit Service a31ea6
 * Returns 0
Packit Service a31ea6
 */
Packit Service a31ea6
int
Packit Service a31ea6
xmlShellCat(xmlShellCtxtPtr ctxt, char *arg ATTRIBUTE_UNUSED,
Packit Service a31ea6
            xmlNodePtr node, xmlNodePtr node2 ATTRIBUTE_UNUSED)
Packit Service a31ea6
{
Packit Service a31ea6
    if (!ctxt)
Packit Service a31ea6
        return (0);
Packit Service a31ea6
    if (node == NULL) {
Packit Service a31ea6
	fprintf(ctxt->output, "NULL\n");
Packit Service a31ea6
	return (0);
Packit Service a31ea6
    }
Packit Service a31ea6
    if (ctxt->doc->type == XML_HTML_DOCUMENT_NODE) {
Packit Service a31ea6
#ifdef LIBXML_HTML_ENABLED
Packit Service a31ea6
        if (node->type == XML_HTML_DOCUMENT_NODE)
Packit Service a31ea6
            htmlDocDump(ctxt->output, (htmlDocPtr) node);
Packit Service a31ea6
        else
Packit Service a31ea6
            htmlNodeDumpFile(ctxt->output, ctxt->doc, node);
Packit Service a31ea6
#else
Packit Service a31ea6
        if (node->type == XML_DOCUMENT_NODE)
Packit Service a31ea6
            xmlDocDump(ctxt->output, (xmlDocPtr) node);
Packit Service a31ea6
        else
Packit Service a31ea6
            xmlElemDump(ctxt->output, ctxt->doc, node);
Packit Service a31ea6
#endif /* LIBXML_HTML_ENABLED */
Packit Service a31ea6
    } else {
Packit Service a31ea6
        if (node->type == XML_DOCUMENT_NODE)
Packit Service a31ea6
            xmlDocDump(ctxt->output, (xmlDocPtr) node);
Packit Service a31ea6
        else
Packit Service a31ea6
            xmlElemDump(ctxt->output, ctxt->doc, node);
Packit Service a31ea6
    }
Packit Service a31ea6
    fprintf(ctxt->output, "\n");
Packit Service a31ea6
    return (0);
Packit Service a31ea6
}
Packit Service a31ea6
#endif /* LIBXML_OUTPUT_ENABLED */
Packit Service a31ea6
Packit Service a31ea6
/**
Packit Service a31ea6
 * xmlShellLoad:
Packit Service a31ea6
 * @ctxt:  the shell context
Packit Service a31ea6
 * @filename:  the file name
Packit Service a31ea6
 * @node:  unused
Packit Service a31ea6
 * @node2:  unused
Packit Service a31ea6
 *
Packit Service a31ea6
 * Implements the XML shell function "load"
Packit Service a31ea6
 * loads a new document specified by the filename
Packit Service a31ea6
 *
Packit Service a31ea6
 * Returns 0 or -1 if loading failed
Packit Service a31ea6
 */
Packit Service a31ea6
int
Packit Service a31ea6
xmlShellLoad(xmlShellCtxtPtr ctxt, char *filename,
Packit Service a31ea6
             xmlNodePtr node ATTRIBUTE_UNUSED,
Packit Service a31ea6
             xmlNodePtr node2 ATTRIBUTE_UNUSED)
Packit Service a31ea6
{
Packit Service a31ea6
    xmlDocPtr doc;
Packit Service a31ea6
    int html = 0;
Packit Service a31ea6
Packit Service a31ea6
    if ((ctxt == NULL) || (filename == NULL)) return(-1);
Packit Service a31ea6
    if (ctxt->doc != NULL)
Packit Service a31ea6
        html = (ctxt->doc->type == XML_HTML_DOCUMENT_NODE);
Packit Service a31ea6
Packit Service a31ea6
    if (html) {
Packit Service a31ea6
#ifdef LIBXML_HTML_ENABLED
Packit Service a31ea6
        doc = htmlParseFile(filename, NULL);
Packit Service a31ea6
#else
Packit Service a31ea6
        fprintf(ctxt->output, "HTML support not compiled in\n");
Packit Service a31ea6
        doc = NULL;
Packit Service a31ea6
#endif /* LIBXML_HTML_ENABLED */
Packit Service a31ea6
    } else {
Packit Service a31ea6
        doc = xmlReadFile(filename,NULL,0);
Packit Service a31ea6
    }
Packit Service a31ea6
    if (doc != NULL) {
Packit Service a31ea6
        if (ctxt->loaded == 1) {
Packit Service a31ea6
            xmlFreeDoc(ctxt->doc);
Packit Service a31ea6
        }
Packit Service a31ea6
        ctxt->loaded = 1;
Packit Service a31ea6
#ifdef LIBXML_XPATH_ENABLED
Packit Service a31ea6
        xmlXPathFreeContext(ctxt->pctxt);
Packit Service a31ea6
#endif /* LIBXML_XPATH_ENABLED */
Packit Service a31ea6
        xmlFree(ctxt->filename);
Packit Service a31ea6
        ctxt->doc = doc;
Packit Service a31ea6
        ctxt->node = (xmlNodePtr) doc;
Packit Service a31ea6
#ifdef LIBXML_XPATH_ENABLED
Packit Service a31ea6
        ctxt->pctxt = xmlXPathNewContext(doc);
Packit Service a31ea6
#endif /* LIBXML_XPATH_ENABLED */
Packit Service a31ea6
        ctxt->filename = (char *) xmlCanonicPath((xmlChar *) filename);
Packit Service a31ea6
    } else
Packit Service a31ea6
        return (-1);
Packit Service a31ea6
    return (0);
Packit Service a31ea6
}
Packit Service a31ea6
Packit Service a31ea6
#ifdef LIBXML_OUTPUT_ENABLED
Packit Service a31ea6
/**
Packit Service a31ea6
 * xmlShellWrite:
Packit Service a31ea6
 * @ctxt:  the shell context
Packit Service a31ea6
 * @filename:  the file name
Packit Service a31ea6
 * @node:  a node in the tree
Packit Service a31ea6
 * @node2:  unused
Packit Service a31ea6
 *
Packit Service a31ea6
 * Implements the XML shell function "write"
Packit Service a31ea6
 * Write the current node to the filename, it saves the serialization
Packit Service a31ea6
 * of the subtree under the @node specified
Packit Service a31ea6
 *
Packit Service a31ea6
 * Returns 0 or -1 in case of error
Packit Service a31ea6
 */
Packit Service a31ea6
int
Packit Service a31ea6
xmlShellWrite(xmlShellCtxtPtr ctxt, char *filename, xmlNodePtr node,
Packit Service a31ea6
              xmlNodePtr node2 ATTRIBUTE_UNUSED)
Packit Service a31ea6
{
Packit Service a31ea6
    if (node == NULL)
Packit Service a31ea6
        return (-1);
Packit Service a31ea6
    if ((filename == NULL) || (filename[0] == 0)) {
Packit Service a31ea6
        return (-1);
Packit Service a31ea6
    }
Packit Service a31ea6
#ifdef W_OK
Packit Service a31ea6
    if (access((char *) filename, W_OK)) {
Packit Service a31ea6
        xmlGenericError(xmlGenericErrorContext,
Packit Service a31ea6
                        "Cannot write to %s\n", filename);
Packit Service a31ea6
        return (-1);
Packit Service a31ea6
    }
Packit Service a31ea6
#endif
Packit Service a31ea6
    switch (node->type) {
Packit Service a31ea6
        case XML_DOCUMENT_NODE:
Packit Service a31ea6
            if (xmlSaveFile((char *) filename, ctxt->doc) < -1) {
Packit Service a31ea6
                xmlGenericError(xmlGenericErrorContext,
Packit Service a31ea6
                                "Failed to write to %s\n", filename);
Packit Service a31ea6
                return (-1);
Packit Service a31ea6
            }
Packit Service a31ea6
            break;
Packit Service a31ea6
        case XML_HTML_DOCUMENT_NODE:
Packit Service a31ea6
#ifdef LIBXML_HTML_ENABLED
Packit Service a31ea6
            if (htmlSaveFile((char *) filename, ctxt->doc) < 0) {
Packit Service a31ea6
                xmlGenericError(xmlGenericErrorContext,
Packit Service a31ea6
                                "Failed to write to %s\n", filename);
Packit Service a31ea6
                return (-1);
Packit Service a31ea6
            }
Packit Service a31ea6
#else
Packit Service a31ea6
            if (xmlSaveFile((char *) filename, ctxt->doc) < -1) {
Packit Service a31ea6
                xmlGenericError(xmlGenericErrorContext,
Packit Service a31ea6
                                "Failed to write to %s\n", filename);
Packit Service a31ea6
                return (-1);
Packit Service a31ea6
            }
Packit Service a31ea6
#endif /* LIBXML_HTML_ENABLED */
Packit Service a31ea6
            break;
Packit Service a31ea6
        default:{
Packit Service a31ea6
                FILE *f;
Packit Service a31ea6
Packit Service a31ea6
                f = fopen((char *) filename, "w");
Packit Service a31ea6
                if (f == NULL) {
Packit Service a31ea6
                    xmlGenericError(xmlGenericErrorContext,
Packit Service a31ea6
                                    "Failed to write to %s\n", filename);
Packit Service a31ea6
                    return (-1);
Packit Service a31ea6
                }
Packit Service a31ea6
                xmlElemDump(f, ctxt->doc, node);
Packit Service a31ea6
                fclose(f);
Packit Service a31ea6
            }
Packit Service a31ea6
    }
Packit Service a31ea6
    return (0);
Packit Service a31ea6
}
Packit Service a31ea6
Packit Service a31ea6
/**
Packit Service a31ea6
 * xmlShellSave:
Packit Service a31ea6
 * @ctxt:  the shell context
Packit Service a31ea6
 * @filename:  the file name (optional)
Packit Service a31ea6
 * @node:  unused
Packit Service a31ea6
 * @node2:  unused
Packit Service a31ea6
 *
Packit Service a31ea6
 * Implements the XML shell function "save"
Packit Service a31ea6
 * Write the current document to the filename, or it's original name
Packit Service a31ea6
 *
Packit Service a31ea6
 * Returns 0 or -1 in case of error
Packit Service a31ea6
 */
Packit Service a31ea6
int
Packit Service a31ea6
xmlShellSave(xmlShellCtxtPtr ctxt, char *filename,
Packit Service a31ea6
             xmlNodePtr node ATTRIBUTE_UNUSED,
Packit Service a31ea6
             xmlNodePtr node2 ATTRIBUTE_UNUSED)
Packit Service a31ea6
{
Packit Service a31ea6
    if ((ctxt == NULL) || (ctxt->doc == NULL))
Packit Service a31ea6
        return (-1);
Packit Service a31ea6
    if ((filename == NULL) || (filename[0] == 0))
Packit Service a31ea6
        filename = ctxt->filename;
Packit Service a31ea6
    if (filename == NULL)
Packit Service a31ea6
        return (-1);
Packit Service a31ea6
#ifdef W_OK
Packit Service a31ea6
    if (access((char *) filename, W_OK)) {
Packit Service a31ea6
        xmlGenericError(xmlGenericErrorContext,
Packit Service a31ea6
                        "Cannot save to %s\n", filename);
Packit Service a31ea6
        return (-1);
Packit Service a31ea6
    }
Packit Service a31ea6
#endif
Packit Service a31ea6
    switch (ctxt->doc->type) {
Packit Service a31ea6
        case XML_DOCUMENT_NODE:
Packit Service a31ea6
            if (xmlSaveFile((char *) filename, ctxt->doc) < 0) {
Packit Service a31ea6
                xmlGenericError(xmlGenericErrorContext,
Packit Service a31ea6
                                "Failed to save to %s\n", filename);
Packit Service a31ea6
            }
Packit Service a31ea6
            break;
Packit Service a31ea6
        case XML_HTML_DOCUMENT_NODE:
Packit Service a31ea6
#ifdef LIBXML_HTML_ENABLED
Packit Service a31ea6
            if (htmlSaveFile((char *) filename, ctxt->doc) < 0) {
Packit Service a31ea6
                xmlGenericError(xmlGenericErrorContext,
Packit Service a31ea6
                                "Failed to save to %s\n", filename);
Packit Service a31ea6
            }
Packit Service a31ea6
#else
Packit Service a31ea6
            if (xmlSaveFile((char *) filename, ctxt->doc) < 0) {
Packit Service a31ea6
                xmlGenericError(xmlGenericErrorContext,
Packit Service a31ea6
                                "Failed to save to %s\n", filename);
Packit Service a31ea6
            }
Packit Service a31ea6
#endif /* LIBXML_HTML_ENABLED */
Packit Service a31ea6
            break;
Packit Service a31ea6
        default:
Packit Service a31ea6
            xmlGenericError(xmlGenericErrorContext,
Packit Service a31ea6
	    "To save to subparts of a document use the 'write' command\n");
Packit Service a31ea6
            return (-1);
Packit Service a31ea6
Packit Service a31ea6
    }
Packit Service a31ea6
    return (0);
Packit Service a31ea6
}
Packit Service a31ea6
#endif /* LIBXML_OUTPUT_ENABLED */
Packit Service a31ea6
Packit Service a31ea6
#ifdef LIBXML_VALID_ENABLED
Packit Service a31ea6
/**
Packit Service a31ea6
 * xmlShellValidate:
Packit Service a31ea6
 * @ctxt:  the shell context
Packit Service a31ea6
 * @dtd:  the DTD URI (optional)
Packit Service a31ea6
 * @node:  unused
Packit Service a31ea6
 * @node2:  unused
Packit Service a31ea6
 *
Packit Service a31ea6
 * Implements the XML shell function "validate"
Packit Service a31ea6
 * Validate the document, if a DTD path is provided, then the validation
Packit Service a31ea6
 * is done against the given DTD.
Packit Service a31ea6
 *
Packit Service a31ea6
 * Returns 0 or -1 in case of error
Packit Service a31ea6
 */
Packit Service a31ea6
int
Packit Service a31ea6
xmlShellValidate(xmlShellCtxtPtr ctxt, char *dtd,
Packit Service a31ea6
                 xmlNodePtr node ATTRIBUTE_UNUSED,
Packit Service a31ea6
                 xmlNodePtr node2 ATTRIBUTE_UNUSED)
Packit Service a31ea6
{
Packit Service a31ea6
    xmlValidCtxt vctxt;
Packit Service a31ea6
    int res = -1;
Packit Service a31ea6
Packit Service a31ea6
    if ((ctxt == NULL) || (ctxt->doc == NULL)) return(-1);
Packit Service a31ea6
    vctxt.userData = stderr;
Packit Service a31ea6
    vctxt.error = (xmlValidityErrorFunc) fprintf;
Packit Service a31ea6
    vctxt.warning = (xmlValidityWarningFunc) fprintf;
Packit Service a31ea6
Packit Service a31ea6
    if ((dtd == NULL) || (dtd[0] == 0)) {
Packit Service a31ea6
        res = xmlValidateDocument(&vctxt, ctxt->doc);
Packit Service a31ea6
    } else {
Packit Service a31ea6
        xmlDtdPtr subset;
Packit Service a31ea6
Packit Service a31ea6
        subset = xmlParseDTD(NULL, (xmlChar *) dtd);
Packit Service a31ea6
        if (subset != NULL) {
Packit Service a31ea6
            res = xmlValidateDtd(&vctxt, ctxt->doc, subset);
Packit Service a31ea6
Packit Service a31ea6
            xmlFreeDtd(subset);
Packit Service a31ea6
        }
Packit Service a31ea6
    }
Packit Service a31ea6
    return (res);
Packit Service a31ea6
}
Packit Service a31ea6
#endif /* LIBXML_VALID_ENABLED */
Packit Service a31ea6
Packit Service a31ea6
/**
Packit Service a31ea6
 * xmlShellDu:
Packit Service a31ea6
 * @ctxt:  the shell context
Packit Service a31ea6
 * @arg:  unused
Packit Service a31ea6
 * @tree:  a node defining a subtree
Packit Service a31ea6
 * @node2:  unused
Packit Service a31ea6
 *
Packit Service a31ea6
 * Implements the XML shell function "du"
Packit Service a31ea6
 * show the structure of the subtree under node @tree
Packit Service a31ea6
 * If @tree is null, the command works on the current node.
Packit Service a31ea6
 *
Packit Service a31ea6
 * Returns 0 or -1 in case of error
Packit Service a31ea6
 */
Packit Service a31ea6
int
Packit Service a31ea6
xmlShellDu(xmlShellCtxtPtr ctxt,
Packit Service a31ea6
           char *arg ATTRIBUTE_UNUSED, xmlNodePtr tree,
Packit Service a31ea6
           xmlNodePtr node2 ATTRIBUTE_UNUSED)
Packit Service a31ea6
{
Packit Service a31ea6
    xmlNodePtr node;
Packit Service a31ea6
    int indent = 0, i;
Packit Service a31ea6
Packit Service a31ea6
    if (!ctxt)
Packit Service a31ea6
	return (-1);
Packit Service a31ea6
Packit Service a31ea6
    if (tree == NULL)
Packit Service a31ea6
        return (-1);
Packit Service a31ea6
    node = tree;
Packit Service a31ea6
    while (node != NULL) {
Packit Service a31ea6
        if ((node->type == XML_DOCUMENT_NODE) ||
Packit Service a31ea6
            (node->type == XML_HTML_DOCUMENT_NODE)) {
Packit Service a31ea6
            fprintf(ctxt->output, "/\n");
Packit Service a31ea6
        } else if (node->type == XML_ELEMENT_NODE) {
Packit Service a31ea6
            for (i = 0; i < indent; i++)
Packit Service a31ea6
                fprintf(ctxt->output, "  ");
Packit Service a31ea6
            if ((node->ns) && (node->ns->prefix))
Packit Service a31ea6
                fprintf(ctxt->output, "%s:", node->ns->prefix);
Packit Service a31ea6
            fprintf(ctxt->output, "%s\n", node->name);
Packit Service a31ea6
        } else {
Packit Service a31ea6
        }
Packit Service a31ea6
Packit Service a31ea6
        /*
Packit Service a31ea6
         * Browse the full subtree, deep first
Packit Service a31ea6
         */
Packit Service a31ea6
Packit Service a31ea6
        if ((node->type == XML_DOCUMENT_NODE) ||
Packit Service a31ea6
            (node->type == XML_HTML_DOCUMENT_NODE)) {
Packit Service a31ea6
            node = ((xmlDocPtr) node)->children;
Packit Service a31ea6
        } else if ((node->children != NULL)
Packit Service a31ea6
                   && (node->type != XML_ENTITY_REF_NODE)) {
Packit Service a31ea6
            /* deep first */
Packit Service a31ea6
            node = node->children;
Packit Service a31ea6
            indent++;
Packit Service a31ea6
        } else if ((node != tree) && (node->next != NULL)) {
Packit Service a31ea6
            /* then siblings */
Packit Service a31ea6
            node = node->next;
Packit Service a31ea6
        } else if (node != tree) {
Packit Service a31ea6
            /* go up to parents->next if needed */
Packit Service a31ea6
            while (node != tree) {
Packit Service a31ea6
                if (node->parent != NULL) {
Packit Service a31ea6
                    node = node->parent;
Packit Service a31ea6
                    indent--;
Packit Service a31ea6
                }
Packit Service a31ea6
                if ((node != tree) && (node->next != NULL)) {
Packit Service a31ea6
                    node = node->next;
Packit Service a31ea6
                    break;
Packit Service a31ea6
                }
Packit Service a31ea6
                if (node->parent == NULL) {
Packit Service a31ea6
                    node = NULL;
Packit Service a31ea6
                    break;
Packit Service a31ea6
                }
Packit Service a31ea6
                if (node == tree) {
Packit Service a31ea6
                    node = NULL;
Packit Service a31ea6
                    break;
Packit Service a31ea6
                }
Packit Service a31ea6
            }
Packit Service a31ea6
            /* exit condition */
Packit Service a31ea6
            if (node == tree)
Packit Service a31ea6
                node = NULL;
Packit Service a31ea6
        } else
Packit Service a31ea6
            node = NULL;
Packit Service a31ea6
    }
Packit Service a31ea6
    return (0);
Packit Service a31ea6
}
Packit Service a31ea6
Packit Service a31ea6
/**
Packit Service a31ea6
 * xmlShellPwd:
Packit Service a31ea6
 * @ctxt:  the shell context
Packit Service a31ea6
 * @buffer:  the output buffer
Packit Service a31ea6
 * @node:  a node
Packit Service a31ea6
 * @node2:  unused
Packit Service a31ea6
 *
Packit Service a31ea6
 * Implements the XML shell function "pwd"
Packit Service a31ea6
 * Show the full path from the root to the node, if needed building
Packit Service a31ea6
 * thumblers when similar elements exists at a given ancestor level.
Packit Service a31ea6
 * The output is compatible with XPath commands.
Packit Service a31ea6
 *
Packit Service a31ea6
 * Returns 0 or -1 in case of error
Packit Service a31ea6
 */
Packit Service a31ea6
int
Packit Service a31ea6
xmlShellPwd(xmlShellCtxtPtr ctxt ATTRIBUTE_UNUSED, char *buffer,
Packit Service a31ea6
            xmlNodePtr node, xmlNodePtr node2 ATTRIBUTE_UNUSED)
Packit Service a31ea6
{
Packit Service a31ea6
    xmlChar *path;
Packit Service a31ea6
Packit Service a31ea6
    if ((node == NULL) || (buffer == NULL))
Packit Service a31ea6
        return (-1);
Packit Service a31ea6
Packit Service a31ea6
    path = xmlGetNodePath(node);
Packit Service a31ea6
    if (path == NULL)
Packit Service a31ea6
	return (-1);
Packit Service a31ea6
Packit Service a31ea6
    /*
Packit Service a31ea6
     * This test prevents buffer overflow, because this routine
Packit Service a31ea6
     * is only called by xmlShell, in which the second argument is
Packit Service a31ea6
     * 500 chars long.
Packit Service a31ea6
     * It is a dirty hack before a cleaner solution is found.
Packit Service a31ea6
     * Documentation should mention that the second argument must
Packit Service a31ea6
     * be at least 500 chars long, and could be stripped if too long.
Packit Service a31ea6
     */
Packit Service a31ea6
    snprintf(buffer, 499, "%s", path);
Packit Service a31ea6
    buffer[499] = '0';
Packit Service a31ea6
    xmlFree(path);
Packit Service a31ea6
Packit Service a31ea6
    return (0);
Packit Service a31ea6
}
Packit Service a31ea6
Packit Service a31ea6
/**
Packit Service a31ea6
 * xmlShell:
Packit Service a31ea6
 * @doc:  the initial document
Packit Service a31ea6
 * @filename:  the output buffer
Packit Service a31ea6
 * @input:  the line reading function
Packit Service a31ea6
 * @output:  the output FILE*, defaults to stdout if NULL
Packit Service a31ea6
 *
Packit Service a31ea6
 * Implements the XML shell
Packit Service a31ea6
 * This allow to load, validate, view, modify and save a document
Packit Service a31ea6
 * using a environment similar to a UNIX commandline.
Packit Service a31ea6
 */
Packit Service a31ea6
void
Packit Service a31ea6
xmlShell(xmlDocPtr doc, char *filename, xmlShellReadlineFunc input,
Packit Service a31ea6
         FILE * output)
Packit Service a31ea6
{
Packit Service a31ea6
    char prompt[500] = "/ > ";
Packit Service a31ea6
    char *cmdline = NULL, *cur;
Packit Service a31ea6
    char command[100];
Packit Service a31ea6
    char arg[400];
Packit Service a31ea6
    int i;
Packit Service a31ea6
    xmlShellCtxtPtr ctxt;
Packit Service a31ea6
    xmlXPathObjectPtr list;
Packit Service a31ea6
Packit Service a31ea6
    if (doc == NULL)
Packit Service a31ea6
        return;
Packit Service a31ea6
    if (filename == NULL)
Packit Service a31ea6
        return;
Packit Service a31ea6
    if (input == NULL)
Packit Service a31ea6
        return;
Packit Service a31ea6
    if (output == NULL)
Packit Service a31ea6
        output = stdout;
Packit Service a31ea6
    ctxt = (xmlShellCtxtPtr) xmlMalloc(sizeof(xmlShellCtxt));
Packit Service a31ea6
    if (ctxt == NULL)
Packit Service a31ea6
        return;
Packit Service a31ea6
    ctxt->loaded = 0;
Packit Service a31ea6
    ctxt->doc = doc;
Packit Service a31ea6
    ctxt->input = input;
Packit Service a31ea6
    ctxt->output = output;
Packit Service a31ea6
    ctxt->filename = (char *) xmlStrdup((xmlChar *) filename);
Packit Service a31ea6
    ctxt->node = (xmlNodePtr) ctxt->doc;
Packit Service a31ea6
Packit Service a31ea6
#ifdef LIBXML_XPATH_ENABLED
Packit Service a31ea6
    ctxt->pctxt = xmlXPathNewContext(ctxt->doc);
Packit Service a31ea6
    if (ctxt->pctxt == NULL) {
Packit Service a31ea6
        xmlFree(ctxt);
Packit Service a31ea6
        return;
Packit Service a31ea6
    }
Packit Service a31ea6
#endif /* LIBXML_XPATH_ENABLED */
Packit Service a31ea6
    while (1) {
Packit Service a31ea6
        if (ctxt->node == (xmlNodePtr) ctxt->doc)
Packit Service a31ea6
            snprintf(prompt, sizeof(prompt), "%s > ", "/");
Packit Service a31ea6
        else if ((ctxt->node != NULL) && (ctxt->node->name) &&
Packit Service a31ea6
                 (ctxt->node->ns) && (ctxt->node->ns->prefix))
Packit Service a31ea6
            snprintf(prompt, sizeof(prompt), "%s:%s > ",
Packit Service a31ea6
                     (ctxt->node->ns->prefix), ctxt->node->name);
Packit Service a31ea6
        else if ((ctxt->node != NULL) && (ctxt->node->name))
Packit Service a31ea6
            snprintf(prompt, sizeof(prompt), "%s > ", ctxt->node->name);
Packit Service a31ea6
        else
Packit Service a31ea6
            snprintf(prompt, sizeof(prompt), "? > ");
Packit Service a31ea6
        prompt[sizeof(prompt) - 1] = 0;
Packit Service a31ea6
Packit Service a31ea6
        /*
Packit Service a31ea6
         * Get a new command line
Packit Service a31ea6
         */
Packit Service a31ea6
        cmdline = ctxt->input(prompt);
Packit Service a31ea6
        if (cmdline == NULL)
Packit Service a31ea6
            break;
Packit Service a31ea6
Packit Service a31ea6
        /*
Packit Service a31ea6
         * Parse the command itself
Packit Service a31ea6
         */
Packit Service a31ea6
        cur = cmdline;
Packit Service a31ea6
        while ((*cur == ' ') || (*cur == '\t'))
Packit Service a31ea6
            cur++;
Packit Service a31ea6
        i = 0;
Packit Service a31ea6
        while ((*cur != ' ') && (*cur != '\t') &&
Packit Service a31ea6
               (*cur != '\n') && (*cur != '\r')) {
Packit Service a31ea6
            if (*cur == 0)
Packit Service a31ea6
                break;
Packit Service a31ea6
            command[i++] = *cur++;
Packit Service a31ea6
        }
Packit Service a31ea6
        command[i] = 0;
Packit Service a31ea6
        if (i == 0)
Packit Service a31ea6
            continue;
Packit Service a31ea6
Packit Service a31ea6
        /*
Packit Service a31ea6
         * Parse the argument
Packit Service a31ea6
         */
Packit Service a31ea6
        while ((*cur == ' ') || (*cur == '\t'))
Packit Service a31ea6
            cur++;
Packit Service a31ea6
        i = 0;
Packit Service a31ea6
        while ((*cur != '\n') && (*cur != '\r') && (*cur != 0)) {
Packit Service a31ea6
            if (*cur == 0)
Packit Service a31ea6
                break;
Packit Service a31ea6
            arg[i++] = *cur++;
Packit Service a31ea6
        }
Packit Service a31ea6
        arg[i] = 0;
Packit Service a31ea6
Packit Service a31ea6
        /*
Packit Service a31ea6
         * start interpreting the command
Packit Service a31ea6
         */
Packit Service a31ea6
        if (!strcmp(command, "exit"))
Packit Service a31ea6
            break;
Packit Service a31ea6
        if (!strcmp(command, "quit"))
Packit Service a31ea6
            break;
Packit Service a31ea6
        if (!strcmp(command, "bye"))
Packit Service a31ea6
            break;
Packit Service a31ea6
		if (!strcmp(command, "help")) {
Packit Service a31ea6
		  fprintf(ctxt->output, "\tbase         display XML base of the node\n");
Packit Service a31ea6
		  fprintf(ctxt->output, "\tsetbase URI  change the XML base of the node\n");
Packit Service a31ea6
		  fprintf(ctxt->output, "\tbye          leave shell\n");
Packit Service a31ea6
		  fprintf(ctxt->output, "\tcat [node]   display node or current node\n");
Packit Service a31ea6
		  fprintf(ctxt->output, "\tcd [path]    change directory to path or to root\n");
Packit Service a31ea6
		  fprintf(ctxt->output, "\tdir [path]   dumps informations about the node (namespace, attributes, content)\n");
Packit Service a31ea6
		  fprintf(ctxt->output, "\tdu [path]    show the structure of the subtree under path or the current node\n");
Packit Service a31ea6
		  fprintf(ctxt->output, "\texit         leave shell\n");
Packit Service a31ea6
		  fprintf(ctxt->output, "\thelp         display this help\n");
Packit Service a31ea6
		  fprintf(ctxt->output, "\tfree         display memory usage\n");
Packit Service a31ea6
		  fprintf(ctxt->output, "\tload [name]  load a new document with name\n");
Packit Service a31ea6
		  fprintf(ctxt->output, "\tls [path]    list contents of path or the current directory\n");
Packit Service a31ea6
		  fprintf(ctxt->output, "\tset xml_fragment replace the current node content with the fragment parsed in context\n");
Packit Service a31ea6
#ifdef LIBXML_XPATH_ENABLED
Packit Service a31ea6
		  fprintf(ctxt->output, "\txpath expr   evaluate the XPath expression in that context and print the result\n");
Packit Service a31ea6
		  fprintf(ctxt->output, "\tsetns nsreg  register a namespace to a prefix in the XPath evaluation context\n");
Packit Service a31ea6
		  fprintf(ctxt->output, "\t             format for nsreg is: prefix=[nsuri] (i.e. prefix= unsets a prefix)\n");
Packit Service a31ea6
		  fprintf(ctxt->output, "\tsetrootns    register all namespace found on the root element\n");
Packit Service a31ea6
		  fprintf(ctxt->output, "\t             the default namespace if any uses 'defaultns' prefix\n");
Packit Service a31ea6
#endif /* LIBXML_XPATH_ENABLED */
Packit Service a31ea6
		  fprintf(ctxt->output, "\tpwd          display current working directory\n");
Packit Service a31ea6
		  fprintf(ctxt->output, "\twhereis      display absolute path of [path] or current working directory\n");
Packit Service a31ea6
		  fprintf(ctxt->output, "\tquit         leave shell\n");
Packit Service a31ea6
#ifdef LIBXML_OUTPUT_ENABLED
Packit Service a31ea6
		  fprintf(ctxt->output, "\tsave [name]  save this document to name or the original name\n");
Packit Service a31ea6
		  fprintf(ctxt->output, "\twrite [name] write the current node to the filename\n");
Packit Service a31ea6
#endif /* LIBXML_OUTPUT_ENABLED */
Packit Service a31ea6
#ifdef LIBXML_VALID_ENABLED
Packit Service a31ea6
		  fprintf(ctxt->output, "\tvalidate     check the document for errors\n");
Packit Service a31ea6
#endif /* LIBXML_VALID_ENABLED */
Packit Service a31ea6
#ifdef LIBXML_SCHEMAS_ENABLED
Packit Service a31ea6
		  fprintf(ctxt->output, "\trelaxng rng  validate the document against the Relax-NG schemas\n");
Packit Service a31ea6
#endif
Packit Service a31ea6
		  fprintf(ctxt->output, "\tgrep string  search for a string in the subtree\n");
Packit Service a31ea6
#ifdef LIBXML_VALID_ENABLED
Packit Service a31ea6
        } else if (!strcmp(command, "validate")) {
Packit Service a31ea6
            xmlShellValidate(ctxt, arg, NULL, NULL);
Packit Service a31ea6
#endif /* LIBXML_VALID_ENABLED */
Packit Service a31ea6
        } else if (!strcmp(command, "load")) {
Packit Service a31ea6
            xmlShellLoad(ctxt, arg, NULL, NULL);
Packit Service a31ea6
#ifdef LIBXML_SCHEMAS_ENABLED
Packit Service a31ea6
        } else if (!strcmp(command, "relaxng")) {
Packit Service a31ea6
            xmlShellRNGValidate(ctxt, arg, NULL, NULL);
Packit Service a31ea6
#endif
Packit Service a31ea6
#ifdef LIBXML_OUTPUT_ENABLED
Packit Service a31ea6
        } else if (!strcmp(command, "save")) {
Packit Service a31ea6
            xmlShellSave(ctxt, arg, NULL, NULL);
Packit Service a31ea6
        } else if (!strcmp(command, "write")) {
Packit Service a31ea6
	    if (arg[0] == 0)
Packit Service a31ea6
		xmlGenericError(xmlGenericErrorContext,
Packit Service a31ea6
                        "Write command requires a filename argument\n");
Packit Service a31ea6
	    else
Packit Service a31ea6
		xmlShellWrite(ctxt, arg, ctxt->node, NULL);
Packit Service a31ea6
#endif /* LIBXML_OUTPUT_ENABLED */
Packit Service a31ea6
        } else if (!strcmp(command, "grep")) {
Packit Service a31ea6
            xmlShellGrep(ctxt, arg, ctxt->node, NULL);
Packit Service a31ea6
        } else if (!strcmp(command, "free")) {
Packit Service a31ea6
            if (arg[0] == 0) {
Packit Service a31ea6
                xmlMemShow(ctxt->output, 0);
Packit Service a31ea6
            } else {
Packit Service a31ea6
                int len = 0;
Packit Service a31ea6
Packit Service a31ea6
                sscanf(arg, "%d", &len;;
Packit Service a31ea6
                xmlMemShow(ctxt->output, len);
Packit Service a31ea6
            }
Packit Service a31ea6
        } else if (!strcmp(command, "pwd")) {
Packit Service a31ea6
            char dir[500];
Packit Service a31ea6
Packit Service a31ea6
            if (!xmlShellPwd(ctxt, dir, ctxt->node, NULL))
Packit Service a31ea6
                fprintf(ctxt->output, "%s\n", dir);
Packit Service a31ea6
        } else if (!strcmp(command, "du")) {
Packit Service a31ea6
            if (arg[0] == 0) {
Packit Service a31ea6
                xmlShellDu(ctxt, NULL, ctxt->node, NULL);
Packit Service a31ea6
            } else {
Packit Service a31ea6
                ctxt->pctxt->node = ctxt->node;
Packit Service a31ea6
#ifdef LIBXML_XPATH_ENABLED
Packit Service a31ea6
                ctxt->pctxt->node = ctxt->node;
Packit Service a31ea6
                list = xmlXPathEval((xmlChar *) arg, ctxt->pctxt);
Packit Service a31ea6
#else
Packit Service a31ea6
                list = NULL;
Packit Service a31ea6
#endif /* LIBXML_XPATH_ENABLED */
Packit Service a31ea6
                if (list != NULL) {
Packit Service a31ea6
                    switch (list->type) {
Packit Service a31ea6
                        case XPATH_UNDEFINED:
Packit Service a31ea6
                            xmlGenericError(xmlGenericErrorContext,
Packit Service a31ea6
                                            "%s: no such node\n", arg);
Packit Service a31ea6
                            break;
Packit Service a31ea6
                        case XPATH_NODESET:{
Packit Service a31ea6
                            int indx;
Packit Service a31ea6
Packit Service a31ea6
                            if (list->nodesetval == NULL)
Packit Service a31ea6
                                break;
Packit Service a31ea6
Packit Service a31ea6
                            for (indx = 0;
Packit Service a31ea6
                                 indx < list->nodesetval->nodeNr;
Packit Service a31ea6
                                 indx++)
Packit Service a31ea6
                                xmlShellDu(ctxt, NULL,
Packit Service a31ea6
                                           list->nodesetval->
Packit Service a31ea6
                                           nodeTab[indx], NULL);
Packit Service a31ea6
                            break;
Packit Service a31ea6
                        }
Packit Service a31ea6
                        case XPATH_BOOLEAN:
Packit Service a31ea6
                            xmlGenericError(xmlGenericErrorContext,
Packit Service a31ea6
                                            "%s is a Boolean\n", arg);
Packit Service a31ea6
                            break;
Packit Service a31ea6
                        case XPATH_NUMBER:
Packit Service a31ea6
                            xmlGenericError(xmlGenericErrorContext,
Packit Service a31ea6
                                            "%s is a number\n", arg);
Packit Service a31ea6
                            break;
Packit Service a31ea6
                        case XPATH_STRING:
Packit Service a31ea6
                            xmlGenericError(xmlGenericErrorContext,
Packit Service a31ea6
                                            "%s is a string\n", arg);
Packit Service a31ea6
                            break;
Packit Service a31ea6
                        case XPATH_POINT:
Packit Service a31ea6
                            xmlGenericError(xmlGenericErrorContext,
Packit Service a31ea6
                                            "%s is a point\n", arg);
Packit Service a31ea6
                            break;
Packit Service a31ea6
                        case XPATH_RANGE:
Packit Service a31ea6
                            xmlGenericError(xmlGenericErrorContext,
Packit Service a31ea6
                                            "%s is a range\n", arg);
Packit Service a31ea6
                            break;
Packit Service a31ea6
                        case XPATH_LOCATIONSET:
Packit Service a31ea6
                            xmlGenericError(xmlGenericErrorContext,
Packit Service a31ea6
                                            "%s is a range\n", arg);
Packit Service a31ea6
                            break;
Packit Service a31ea6
                        case XPATH_USERS:
Packit Service a31ea6
                            xmlGenericError(xmlGenericErrorContext,
Packit Service a31ea6
                                            "%s is user-defined\n", arg);
Packit Service a31ea6
                            break;
Packit Service a31ea6
                        case XPATH_XSLT_TREE:
Packit Service a31ea6
                            xmlGenericError(xmlGenericErrorContext,
Packit Service a31ea6
                                            "%s is an XSLT value tree\n",
Packit Service a31ea6
                                            arg);
Packit Service a31ea6
                            break;
Packit Service a31ea6
                    }
Packit Service a31ea6
#ifdef LIBXML_XPATH_ENABLED
Packit Service a31ea6
                    xmlXPathFreeObject(list);
Packit Service a31ea6
#endif
Packit Service a31ea6
                } else {
Packit Service a31ea6
                    xmlGenericError(xmlGenericErrorContext,
Packit Service a31ea6
                                    "%s: no such node\n", arg);
Packit Service a31ea6
                }
Packit Service a31ea6
                ctxt->pctxt->node = NULL;
Packit Service a31ea6
            }
Packit Service a31ea6
        } else if (!strcmp(command, "base")) {
Packit Service a31ea6
            xmlShellBase(ctxt, NULL, ctxt->node, NULL);
Packit Service a31ea6
        } else if (!strcmp(command, "set")) {
Packit Service a31ea6
	    xmlShellSetContent(ctxt, arg, ctxt->node, NULL);
Packit Service a31ea6
#ifdef LIBXML_XPATH_ENABLED
Packit Service a31ea6
        } else if (!strcmp(command, "setns")) {
Packit Service a31ea6
            if (arg[0] == 0) {
Packit Service a31ea6
		xmlGenericError(xmlGenericErrorContext,
Packit Service a31ea6
				"setns: prefix=[nsuri] required\n");
Packit Service a31ea6
            } else {
Packit Service a31ea6
                xmlShellRegisterNamespace(ctxt, arg, NULL, NULL);
Packit Service a31ea6
            }
Packit Service a31ea6
        } else if (!strcmp(command, "setrootns")) {
Packit Service a31ea6
	    xmlNodePtr root;
Packit Service a31ea6
Packit Service a31ea6
	    root = xmlDocGetRootElement(ctxt->doc);
Packit Service a31ea6
	    xmlShellRegisterRootNamespaces(ctxt, NULL, root, NULL);
Packit Service a31ea6
        } else if (!strcmp(command, "xpath")) {
Packit Service a31ea6
            if (arg[0] == 0) {
Packit Service a31ea6
		xmlGenericError(xmlGenericErrorContext,
Packit Service a31ea6
				"xpath: expression required\n");
Packit Service a31ea6
	    } else {
Packit Service a31ea6
                ctxt->pctxt->node = ctxt->node;
Packit Service a31ea6
                list = xmlXPathEval((xmlChar *) arg, ctxt->pctxt);
Packit Service a31ea6
		xmlXPathDebugDumpObject(ctxt->output, list, 0);
Packit Service a31ea6
		xmlXPathFreeObject(list);
Packit Service a31ea6
	    }
Packit Service a31ea6
#endif /* LIBXML_XPATH_ENABLED */
Packit Service a31ea6
#ifdef LIBXML_TREE_ENABLED
Packit Service a31ea6
        } else if (!strcmp(command, "setbase")) {
Packit Service a31ea6
            xmlShellSetBase(ctxt, arg, ctxt->node, NULL);
Packit Service a31ea6
#endif
Packit Service a31ea6
        } else if ((!strcmp(command, "ls")) || (!strcmp(command, "dir"))) {
Packit Service a31ea6
            int dir = (!strcmp(command, "dir"));
Packit Service a31ea6
Packit Service a31ea6
            if (arg[0] == 0) {
Packit Service a31ea6
                if (dir)
Packit Service a31ea6
                    xmlShellDir(ctxt, NULL, ctxt->node, NULL);
Packit Service a31ea6
                else
Packit Service a31ea6
                    xmlShellList(ctxt, NULL, ctxt->node, NULL);
Packit Service a31ea6
            } else {
Packit Service a31ea6
                ctxt->pctxt->node = ctxt->node;
Packit Service a31ea6
#ifdef LIBXML_XPATH_ENABLED
Packit Service a31ea6
                ctxt->pctxt->node = ctxt->node;
Packit Service a31ea6
                list = xmlXPathEval((xmlChar *) arg, ctxt->pctxt);
Packit Service a31ea6
#else
Packit Service a31ea6
                list = NULL;
Packit Service a31ea6
#endif /* LIBXML_XPATH_ENABLED */
Packit Service a31ea6
                if (list != NULL) {
Packit Service a31ea6
                    switch (list->type) {
Packit Service a31ea6
                        case XPATH_UNDEFINED:
Packit Service a31ea6
                            xmlGenericError(xmlGenericErrorContext,
Packit Service a31ea6
                                            "%s: no such node\n", arg);
Packit Service a31ea6
                            break;
Packit Service a31ea6
                        case XPATH_NODESET:{
Packit Service a31ea6
                                int indx;
Packit Service a31ea6
Packit Service a31ea6
				if (list->nodesetval == NULL)
Packit Service a31ea6
				    break;
Packit Service a31ea6
Packit Service a31ea6
                                for (indx = 0;
Packit Service a31ea6
                                     indx < list->nodesetval->nodeNr;
Packit Service a31ea6
                                     indx++) {
Packit Service a31ea6
                                    if (dir)
Packit Service a31ea6
                                        xmlShellDir(ctxt, NULL,
Packit Service a31ea6
                                                    list->nodesetval->
Packit Service a31ea6
                                                    nodeTab[indx], NULL);
Packit Service a31ea6
                                    else
Packit Service a31ea6
                                        xmlShellList(ctxt, NULL,
Packit Service a31ea6
                                                     list->nodesetval->
Packit Service a31ea6
                                                     nodeTab[indx], NULL);
Packit Service a31ea6
                                }
Packit Service a31ea6
                                break;
Packit Service a31ea6
                            }
Packit Service a31ea6
                        case XPATH_BOOLEAN:
Packit Service a31ea6
                            xmlGenericError(xmlGenericErrorContext,
Packit Service a31ea6
                                            "%s is a Boolean\n", arg);
Packit Service a31ea6
                            break;
Packit Service a31ea6
                        case XPATH_NUMBER:
Packit Service a31ea6
                            xmlGenericError(xmlGenericErrorContext,
Packit Service a31ea6
                                            "%s is a number\n", arg);
Packit Service a31ea6
                            break;
Packit Service a31ea6
                        case XPATH_STRING:
Packit Service a31ea6
                            xmlGenericError(xmlGenericErrorContext,
Packit Service a31ea6
                                            "%s is a string\n", arg);
Packit Service a31ea6
                            break;
Packit Service a31ea6
                        case XPATH_POINT:
Packit Service a31ea6
                            xmlGenericError(xmlGenericErrorContext,
Packit Service a31ea6
                                            "%s is a point\n", arg);
Packit Service a31ea6
                            break;
Packit Service a31ea6
                        case XPATH_RANGE:
Packit Service a31ea6
                            xmlGenericError(xmlGenericErrorContext,
Packit Service a31ea6
                                            "%s is a range\n", arg);
Packit Service a31ea6
                            break;
Packit Service a31ea6
                        case XPATH_LOCATIONSET:
Packit Service a31ea6
                            xmlGenericError(xmlGenericErrorContext,
Packit Service a31ea6
                                            "%s is a range\n", arg);
Packit Service a31ea6
                            break;
Packit Service a31ea6
                        case XPATH_USERS:
Packit Service a31ea6
                            xmlGenericError(xmlGenericErrorContext,
Packit Service a31ea6
                                            "%s is user-defined\n", arg);
Packit Service a31ea6
                            break;
Packit Service a31ea6
                        case XPATH_XSLT_TREE:
Packit Service a31ea6
                            xmlGenericError(xmlGenericErrorContext,
Packit Service a31ea6
                                            "%s is an XSLT value tree\n",
Packit Service a31ea6
                                            arg);
Packit Service a31ea6
                            break;
Packit Service a31ea6
                    }
Packit Service a31ea6
#ifdef LIBXML_XPATH_ENABLED
Packit Service a31ea6
                    xmlXPathFreeObject(list);
Packit Service a31ea6
#endif
Packit Service a31ea6
                } else {
Packit Service a31ea6
                    xmlGenericError(xmlGenericErrorContext,
Packit Service a31ea6
                                    "%s: no such node\n", arg);
Packit Service a31ea6
                }
Packit Service a31ea6
                ctxt->pctxt->node = NULL;
Packit Service a31ea6
            }
Packit Service a31ea6
        } else if (!strcmp(command, "whereis")) {
Packit Service a31ea6
            char dir[500];
Packit Service a31ea6
Packit Service a31ea6
            if (arg[0] == 0) {
Packit Service a31ea6
                if (!xmlShellPwd(ctxt, dir, ctxt->node, NULL))
Packit Service a31ea6
                    fprintf(ctxt->output, "%s\n", dir);
Packit Service a31ea6
            } else {
Packit Service a31ea6
                ctxt->pctxt->node = ctxt->node;
Packit Service a31ea6
#ifdef LIBXML_XPATH_ENABLED
Packit Service a31ea6
                list = xmlXPathEval((xmlChar *) arg, ctxt->pctxt);
Packit Service a31ea6
#else
Packit Service a31ea6
                list = NULL;
Packit Service a31ea6
#endif /* LIBXML_XPATH_ENABLED */
Packit Service a31ea6
                if (list != NULL) {
Packit Service a31ea6
                    switch (list->type) {
Packit Service a31ea6
                        case XPATH_UNDEFINED:
Packit Service a31ea6
                            xmlGenericError(xmlGenericErrorContext,
Packit Service a31ea6
                                            "%s: no such node\n", arg);
Packit Service a31ea6
                            break;
Packit Service a31ea6
                        case XPATH_NODESET:{
Packit Service a31ea6
                                int indx;
Packit Service a31ea6
Packit Service a31ea6
				if (list->nodesetval == NULL)
Packit Service a31ea6
				    break;
Packit Service a31ea6
Packit Service a31ea6
                                for (indx = 0;
Packit Service a31ea6
                                     indx < list->nodesetval->nodeNr;
Packit Service a31ea6
                                     indx++) {
Packit Service a31ea6
                                    if (!xmlShellPwd(ctxt, dir, list->nodesetval->
Packit Service a31ea6
                                                     nodeTab[indx], NULL))
Packit Service a31ea6
                                        fprintf(ctxt->output, "%s\n", dir);
Packit Service a31ea6
                                }
Packit Service a31ea6
                                break;
Packit Service a31ea6
                            }
Packit Service a31ea6
                        case XPATH_BOOLEAN:
Packit Service a31ea6
                            xmlGenericError(xmlGenericErrorContext,
Packit Service a31ea6
                                            "%s is a Boolean\n", arg);
Packit Service a31ea6
                            break;
Packit Service a31ea6
                        case XPATH_NUMBER:
Packit Service a31ea6
                            xmlGenericError(xmlGenericErrorContext,
Packit Service a31ea6
                                            "%s is a number\n", arg);
Packit Service a31ea6
                            break;
Packit Service a31ea6
                        case XPATH_STRING:
Packit Service a31ea6
                            xmlGenericError(xmlGenericErrorContext,
Packit Service a31ea6
                                            "%s is a string\n", arg);
Packit Service a31ea6
                            break;
Packit Service a31ea6
                        case XPATH_POINT:
Packit Service a31ea6
                            xmlGenericError(xmlGenericErrorContext,
Packit Service a31ea6
                                            "%s is a point\n", arg);
Packit Service a31ea6
                            break;
Packit Service a31ea6
                        case XPATH_RANGE:
Packit Service a31ea6
                            xmlGenericError(xmlGenericErrorContext,
Packit Service a31ea6
                                            "%s is a range\n", arg);
Packit Service a31ea6
                            break;
Packit Service a31ea6
                        case XPATH_LOCATIONSET:
Packit Service a31ea6
                            xmlGenericError(xmlGenericErrorContext,
Packit Service a31ea6
                                            "%s is a range\n", arg);
Packit Service a31ea6
                            break;
Packit Service a31ea6
                        case XPATH_USERS:
Packit Service a31ea6
                            xmlGenericError(xmlGenericErrorContext,
Packit Service a31ea6
                                            "%s is user-defined\n", arg);
Packit Service a31ea6
                            break;
Packit Service a31ea6
                        case XPATH_XSLT_TREE:
Packit Service a31ea6
                            xmlGenericError(xmlGenericErrorContext,
Packit Service a31ea6
                                            "%s is an XSLT value tree\n",
Packit Service a31ea6
                                            arg);
Packit Service a31ea6
                            break;
Packit Service a31ea6
                    }
Packit Service a31ea6
#ifdef LIBXML_XPATH_ENABLED
Packit Service a31ea6
                    xmlXPathFreeObject(list);
Packit Service a31ea6
#endif
Packit Service a31ea6
                } else {
Packit Service a31ea6
                    xmlGenericError(xmlGenericErrorContext,
Packit Service a31ea6
                                    "%s: no such node\n", arg);
Packit Service a31ea6
                }
Packit Service a31ea6
                ctxt->pctxt->node = NULL;
Packit Service a31ea6
            }
Packit Service a31ea6
        } else if (!strcmp(command, "cd")) {
Packit Service a31ea6
            if (arg[0] == 0) {
Packit Service a31ea6
                ctxt->node = (xmlNodePtr) ctxt->doc;
Packit Service a31ea6
            } else {
Packit Service a31ea6
#ifdef LIBXML_XPATH_ENABLED
Packit Service a31ea6
                int l;
Packit Service a31ea6
Packit Service a31ea6
                ctxt->pctxt->node = ctxt->node;
Packit Service a31ea6
		l = strlen(arg);
Packit Service a31ea6
		if ((l >= 2) && (arg[l - 1] == '/'))
Packit Service a31ea6
		    arg[l - 1] = 0;
Packit Service a31ea6
                list = xmlXPathEval((xmlChar *) arg, ctxt->pctxt);
Packit Service a31ea6
#else
Packit Service a31ea6
                list = NULL;
Packit Service a31ea6
#endif /* LIBXML_XPATH_ENABLED */
Packit Service a31ea6
                if (list != NULL) {
Packit Service a31ea6
                    switch (list->type) {
Packit Service a31ea6
                        case XPATH_UNDEFINED:
Packit Service a31ea6
                            xmlGenericError(xmlGenericErrorContext,
Packit Service a31ea6
                                            "%s: no such node\n", arg);
Packit Service a31ea6
                            break;
Packit Service a31ea6
                        case XPATH_NODESET:
Packit Service a31ea6
                            if (list->nodesetval != NULL) {
Packit Service a31ea6
				if (list->nodesetval->nodeNr == 1) {
Packit Service a31ea6
				    ctxt->node = list->nodesetval->nodeTab[0];
Packit Service a31ea6
				    if ((ctxt->node != NULL) &&
Packit Service a31ea6
				        (ctxt->node->type ==
Packit Service a31ea6
					 XML_NAMESPACE_DECL)) {
Packit Service a31ea6
					xmlGenericError(xmlGenericErrorContext,
Packit Service a31ea6
						    "cannot cd to namespace\n");
Packit Service a31ea6
					ctxt->node = NULL;
Packit Service a31ea6
				    }
Packit Service a31ea6
				} else
Packit Service a31ea6
				    xmlGenericError(xmlGenericErrorContext,
Packit Service a31ea6
						    "%s is a %d Node Set\n",
Packit Service a31ea6
						    arg,
Packit Service a31ea6
						    list->nodesetval->nodeNr);
Packit Service a31ea6
                            } else
Packit Service a31ea6
                                xmlGenericError(xmlGenericErrorContext,
Packit Service a31ea6
                                                "%s is an empty Node Set\n",
Packit Service a31ea6
                                                arg);
Packit Service a31ea6
                            break;
Packit Service a31ea6
                        case XPATH_BOOLEAN:
Packit Service a31ea6
                            xmlGenericError(xmlGenericErrorContext,
Packit Service a31ea6
                                            "%s is a Boolean\n", arg);
Packit Service a31ea6
                            break;
Packit Service a31ea6
                        case XPATH_NUMBER:
Packit Service a31ea6
                            xmlGenericError(xmlGenericErrorContext,
Packit Service a31ea6
                                            "%s is a number\n", arg);
Packit Service a31ea6
                            break;
Packit Service a31ea6
                        case XPATH_STRING:
Packit Service a31ea6
                            xmlGenericError(xmlGenericErrorContext,
Packit Service a31ea6
                                            "%s is a string\n", arg);
Packit Service a31ea6
                            break;
Packit Service a31ea6
                        case XPATH_POINT:
Packit Service a31ea6
                            xmlGenericError(xmlGenericErrorContext,
Packit Service a31ea6
                                            "%s is a point\n", arg);
Packit Service a31ea6
                            break;
Packit Service a31ea6
                        case XPATH_RANGE:
Packit Service a31ea6
                            xmlGenericError(xmlGenericErrorContext,
Packit Service a31ea6
                                            "%s is a range\n", arg);
Packit Service a31ea6
                            break;
Packit Service a31ea6
                        case XPATH_LOCATIONSET:
Packit Service a31ea6
                            xmlGenericError(xmlGenericErrorContext,
Packit Service a31ea6
                                            "%s is a range\n", arg);
Packit Service a31ea6
                            break;
Packit Service a31ea6
                        case XPATH_USERS:
Packit Service a31ea6
                            xmlGenericError(xmlGenericErrorContext,
Packit Service a31ea6
                                            "%s is user-defined\n", arg);
Packit Service a31ea6
                            break;
Packit Service a31ea6
                        case XPATH_XSLT_TREE:
Packit Service a31ea6
                            xmlGenericError(xmlGenericErrorContext,
Packit Service a31ea6
                                            "%s is an XSLT value tree\n",
Packit Service a31ea6
                                            arg);
Packit Service a31ea6
                            break;
Packit Service a31ea6
                    }
Packit Service a31ea6
#ifdef LIBXML_XPATH_ENABLED
Packit Service a31ea6
                    xmlXPathFreeObject(list);
Packit Service a31ea6
#endif
Packit Service a31ea6
                } else {
Packit Service a31ea6
                    xmlGenericError(xmlGenericErrorContext,
Packit Service a31ea6
                                    "%s: no such node\n", arg);
Packit Service a31ea6
                }
Packit Service a31ea6
                ctxt->pctxt->node = NULL;
Packit Service a31ea6
            }
Packit Service a31ea6
#ifdef LIBXML_OUTPUT_ENABLED
Packit Service a31ea6
        } else if (!strcmp(command, "cat")) {
Packit Service a31ea6
            if (arg[0] == 0) {
Packit Service a31ea6
                xmlShellCat(ctxt, NULL, ctxt->node, NULL);
Packit Service a31ea6
            } else {
Packit Service a31ea6
                ctxt->pctxt->node = ctxt->node;
Packit Service a31ea6
#ifdef LIBXML_XPATH_ENABLED
Packit Service a31ea6
                ctxt->pctxt->node = ctxt->node;
Packit Service a31ea6
                list = xmlXPathEval((xmlChar *) arg, ctxt->pctxt);
Packit Service a31ea6
#else
Packit Service a31ea6
                list = NULL;
Packit Service a31ea6
#endif /* LIBXML_XPATH_ENABLED */
Packit Service a31ea6
                if (list != NULL) {
Packit Service a31ea6
                    switch (list->type) {
Packit Service a31ea6
                        case XPATH_UNDEFINED:
Packit Service a31ea6
                            xmlGenericError(xmlGenericErrorContext,
Packit Service a31ea6
                                            "%s: no such node\n", arg);
Packit Service a31ea6
                            break;
Packit Service a31ea6
                        case XPATH_NODESET:{
Packit Service a31ea6
                                int indx;
Packit Service a31ea6
Packit Service a31ea6
				if (list->nodesetval == NULL)
Packit Service a31ea6
				    break;
Packit Service a31ea6
Packit Service a31ea6
                                for (indx = 0;
Packit Service a31ea6
                                     indx < list->nodesetval->nodeNr;
Packit Service a31ea6
                                     indx++) {
Packit Service a31ea6
                                    if (i > 0)
Packit Service a31ea6
                                        fprintf(ctxt->output, " -------\n");
Packit Service a31ea6
                                    xmlShellCat(ctxt, NULL,
Packit Service a31ea6
                                                list->nodesetval->
Packit Service a31ea6
                                                nodeTab[indx], NULL);
Packit Service a31ea6
                                }
Packit Service a31ea6
                                break;
Packit Service a31ea6
                            }
Packit Service a31ea6
                        case XPATH_BOOLEAN:
Packit Service a31ea6
                            xmlGenericError(xmlGenericErrorContext,
Packit Service a31ea6
                                            "%s is a Boolean\n", arg);
Packit Service a31ea6
                            break;
Packit Service a31ea6
                        case XPATH_NUMBER:
Packit Service a31ea6
                            xmlGenericError(xmlGenericErrorContext,
Packit Service a31ea6
                                            "%s is a number\n", arg);
Packit Service a31ea6
                            break;
Packit Service a31ea6
                        case XPATH_STRING:
Packit Service a31ea6
                            xmlGenericError(xmlGenericErrorContext,
Packit Service a31ea6
                                            "%s is a string\n", arg);
Packit Service a31ea6
                            break;
Packit Service a31ea6
                        case XPATH_POINT:
Packit Service a31ea6
                            xmlGenericError(xmlGenericErrorContext,
Packit Service a31ea6
                                            "%s is a point\n", arg);
Packit Service a31ea6
                            break;
Packit Service a31ea6
                        case XPATH_RANGE:
Packit Service a31ea6
                            xmlGenericError(xmlGenericErrorContext,
Packit Service a31ea6
                                            "%s is a range\n", arg);
Packit Service a31ea6
                            break;
Packit Service a31ea6
                        case XPATH_LOCATIONSET:
Packit Service a31ea6
                            xmlGenericError(xmlGenericErrorContext,
Packit Service a31ea6
                                            "%s is a range\n", arg);
Packit Service a31ea6
                            break;
Packit Service a31ea6
                        case XPATH_USERS:
Packit Service a31ea6
                            xmlGenericError(xmlGenericErrorContext,
Packit Service a31ea6
                                            "%s is user-defined\n", arg);
Packit Service a31ea6
                            break;
Packit Service a31ea6
                        case XPATH_XSLT_TREE:
Packit Service a31ea6
                            xmlGenericError(xmlGenericErrorContext,
Packit Service a31ea6
                                            "%s is an XSLT value tree\n",
Packit Service a31ea6
                                            arg);
Packit Service a31ea6
                            break;
Packit Service a31ea6
                    }
Packit Service a31ea6
#ifdef LIBXML_XPATH_ENABLED
Packit Service a31ea6
                    xmlXPathFreeObject(list);
Packit Service a31ea6
#endif
Packit Service a31ea6
                } else {
Packit Service a31ea6
                    xmlGenericError(xmlGenericErrorContext,
Packit Service a31ea6
                                    "%s: no such node\n", arg);
Packit Service a31ea6
                }
Packit Service a31ea6
                ctxt->pctxt->node = NULL;
Packit Service a31ea6
            }
Packit Service a31ea6
#endif /* LIBXML_OUTPUT_ENABLED */
Packit Service a31ea6
        } else {
Packit Service a31ea6
            xmlGenericError(xmlGenericErrorContext,
Packit Service a31ea6
                            "Unknown command %s\n", command);
Packit Service a31ea6
        }
Packit Service a31ea6
        free(cmdline);          /* not xmlFree here ! */
Packit Service a31ea6
	cmdline = NULL;
Packit Service a31ea6
    }
Packit Service a31ea6
#ifdef LIBXML_XPATH_ENABLED
Packit Service a31ea6
    xmlXPathFreeContext(ctxt->pctxt);
Packit Service a31ea6
#endif /* LIBXML_XPATH_ENABLED */
Packit Service a31ea6
    if (ctxt->loaded) {
Packit Service a31ea6
        xmlFreeDoc(ctxt->doc);
Packit Service a31ea6
    }
Packit Service a31ea6
    if (ctxt->filename != NULL)
Packit Service a31ea6
        xmlFree(ctxt->filename);
Packit Service a31ea6
    xmlFree(ctxt);
Packit Service a31ea6
    if (cmdline != NULL)
Packit Service a31ea6
        free(cmdline);          /* not xmlFree here ! */
Packit Service a31ea6
}
Packit Service a31ea6
Packit Service a31ea6
#endif /* LIBXML_XPATH_ENABLED */
Packit Service a31ea6
#define bottom_debugXML
Packit Service a31ea6
#include "elfgcchack.h"
Packit Service a31ea6
#endif /* LIBXML_DEBUG_ENABLED */