From 321be0c5bf7b74a3f5a21434ab2ad656b899bc11 Mon Sep 17 00:00:00 2001 From: Daniel Veillard Date: Tue, 8 Oct 2002 21:26:42 +0000 Subject: applied patch from Mark Vakoc except the API change, preserved it. updated * debugXML.c: applied patch from Mark Vakoc except the API change, preserved it. * doc/*: updated the docs to point to the search engine for information lookup or before bug/help reports. Daniel --- debugXML.c | 172 +++++++++++++++++++++++++++++++++++++------------------------ 1 file changed, 105 insertions(+), 67 deletions(-) (limited to 'debugXML.c') diff --git a/debugXML.c b/debugXML.c index 22bbb56f..fabcd128 100644 --- a/debugXML.c +++ b/debugXML.c @@ -1346,38 +1346,53 @@ xmlShellPrintXPathError(int errorType, const char *arg) /** - * xmlShellPrintNode: - * @node : a non-null node to print to stdout + * xmlShellPrintNodeCtxt: + * @ctxt : a non-null shell context + * @node : a non-null node to print to the output FILE * - * Print node to stdout + * Print node to the output FILE */ -void -xmlShellPrintNode(xmlNodePtr node) +static void +xmlShellPrintNodeCtxt(xmlShellCtxtPtr ctxt,xmlNodePtr node) { - if (!node) + if (!ctxt || !node) return; if (node->type == XML_DOCUMENT_NODE) - xmlDocDump(stdout, (xmlDocPtr) node); + xmlDocDump(ctxt->output, (xmlDocPtr) node); else if (node->type == XML_ATTRIBUTE_NODE) - xmlDebugDumpAttrList(stdout, (xmlAttrPtr) node, 0); + xmlDebugDumpAttrList(ctxt->output, (xmlAttrPtr) node, 0); else - xmlElemDump(stdout, node->doc, node); + xmlElemDump(ctxt->output, node->doc, node); - fprintf(stdout, "\n"); + fprintf(ctxt->output, "\n"); } +/** + * xmlShellPrintNode: + * @node : a non-null node to print to the output FILE + * + * Print node to the output FILE + */ +void +xmlShellPrintNode(xmlNodePtr node) +{ + xmlShellPrintNodeCtxt(NULL, node); +} /** - * xmlShellPrintXPathResult: + * xmlShellPrintXPathResultCtxt: + * @ctxt: a valid shell context * @list: a valid result generated by an xpath evaluation * - * Prints result to stdout + * Prints result to the output FILE */ -void -xmlShellPrintXPathResult(xmlXPathObjectPtr list) +static void +xmlShellPrintXPathResultCtxt(xmlShellCtxtPtr ctxt,xmlXPathObjectPtr list) { int i = 0; + if (!ctxt) + return; if (list != NULL) { switch (list->type) { @@ -1389,8 +1404,8 @@ xmlShellPrintXPathResult(xmlXPathObjectPtr list) indx++) { if (i > 0) fprintf(stderr, " -------\n"); - xmlShellPrintNode(list->nodesetval-> - nodeTab[indx]); + xmlShellPrintNodeCtxt(ctxt, + list->nodesetval->nodeTab[indx]); } } else { xmlGenericError(xmlGenericErrorContext, @@ -1418,6 +1433,18 @@ xmlShellPrintXPathResult(xmlXPathObjectPtr list) } } +/** + * xmlShellPrintXPathResult: + * @list: a valid result generated by an xpath evaluation + * + * Prints result to the output FILE + */ +void +xmlShellPrintXPathResult(xmlXPathObjectPtr list) +{ + xmlShellPrintXPathResultCtxt(NULL, list); +} + /** * xmlShellList: * @ctxt: the shell context @@ -1431,29 +1458,31 @@ xmlShellPrintXPathResult(xmlXPathObjectPtr list) * Returns 0 */ int -xmlShellList(xmlShellCtxtPtr ctxt ATTRIBUTE_UNUSED, +xmlShellList(xmlShellCtxtPtr ctxt, char *arg ATTRIBUTE_UNUSED, xmlNodePtr node, xmlNodePtr node2 ATTRIBUTE_UNUSED) { xmlNodePtr cur; + if (!ctxt) + return (0); if (node == NULL) { - fprintf(stdout, "NULL\n"); + fprintf(ctxt->output, "NULL\n"); return (0); } if ((node->type == XML_DOCUMENT_NODE) || (node->type == XML_HTML_DOCUMENT_NODE)) { cur = ((xmlDocPtr) node)->children; } else if (node->type == XML_NAMESPACE_DECL) { - xmlLsOneNode(stdout, node); + xmlLsOneNode(ctxt->output, node); return (0); } else if (node->children != NULL) { cur = node->children; } else { - xmlLsOneNode(stdout, node); + xmlLsOneNode(ctxt->output, node); return (0); } while (cur != NULL) { - xmlLsOneNode(stdout, cur); + xmlLsOneNode(ctxt->output, cur); cur = cur->next; } return (0); @@ -1472,22 +1501,24 @@ xmlShellList(xmlShellCtxtPtr ctxt ATTRIBUTE_UNUSED, * Returns 0 */ int -xmlShellBase(xmlShellCtxtPtr ctxt ATTRIBUTE_UNUSED, +xmlShellBase(xmlShellCtxtPtr ctxt, char *arg ATTRIBUTE_UNUSED, xmlNodePtr node, xmlNodePtr node2 ATTRIBUTE_UNUSED) { xmlChar *base; + if (!ctxt) + return 0; if (node == NULL) { - fprintf(stdout, "NULL\n"); + fprintf(ctxt->output, "NULL\n"); return (0); } base = xmlNodeGetBase(node->doc, node); if (base == NULL) { - fprintf(stdout, " No base found !!!\n"); + fprintf(ctxt->output, " No base found !!!\n"); } else { - fprintf(stdout, "%s\n", base); + fprintf(ctxt->output, "%s\n", base); xmlFree(base); } return (0); @@ -1531,17 +1562,19 @@ xmlShellDir(xmlShellCtxtPtr ctxt ATTRIBUTE_UNUSED, char *arg ATTRIBUTE_UNUSED, xmlNodePtr node, xmlNodePtr node2 ATTRIBUTE_UNUSED) { + if (!ctxt) + return (0); if (node == NULL) { - fprintf(stdout, "NULL\n"); + fprintf(ctxt->output, "NULL\n"); return (0); } if ((node->type == XML_DOCUMENT_NODE) || (node->type == XML_HTML_DOCUMENT_NODE)) { - xmlDebugDumpDocumentHead(stdout, (xmlDocPtr) node); + xmlDebugDumpDocumentHead(ctxt->output, (xmlDocPtr) node); } else if (node->type == XML_ATTRIBUTE_NODE) { - xmlDebugDumpAttr(stdout, (xmlAttrPtr) node, 0); + xmlDebugDumpAttr(ctxt->output, (xmlAttrPtr) node, 0); } else { - xmlDebugDumpOneNode(stdout, node, 0); + xmlDebugDumpOneNode(ctxt->output, node, 0); } return (0); } @@ -1562,29 +1595,31 @@ int xmlShellCat(xmlShellCtxtPtr ctxt, char *arg ATTRIBUTE_UNUSED, xmlNodePtr node, xmlNodePtr node2 ATTRIBUTE_UNUSED) { + if (!ctxt) + return (0); if (node == NULL) { - fprintf(stdout, "NULL\n"); + fprintf(ctxt->output, "NULL\n"); return (0); } if (ctxt->doc->type == XML_HTML_DOCUMENT_NODE) { #ifdef LIBXML_HTML_ENABLED if (node->type == XML_HTML_DOCUMENT_NODE) - htmlDocDump(stdout, (htmlDocPtr) node); + htmlDocDump(ctxt->output, (htmlDocPtr) node); else - htmlNodeDumpFile(stdout, ctxt->doc, node); + htmlNodeDumpFile(ctxt->output, ctxt->doc, node); #else if (node->type == XML_DOCUMENT_NODE) - xmlDocDump(stdout, (xmlDocPtr) node); + xmlDocDump(ctxt->output, (xmlDocPtr) node); else - xmlElemDump(stdout, ctxt->doc, node); + xmlElemDump(ctxt->output, ctxt->doc, node); #endif /* LIBXML_HTML_ENABLED */ } else { if (node->type == XML_DOCUMENT_NODE) - xmlDocDump(stdout, (xmlDocPtr) node); + xmlDocDump(ctxt->output, (xmlDocPtr) node); else - xmlElemDump(stdout, ctxt->doc, node); + xmlElemDump(ctxt->output, ctxt->doc, node); } - fprintf(stdout, "\n"); + fprintf(ctxt->output, "\n"); return (0); } @@ -1615,7 +1650,7 @@ xmlShellLoad(xmlShellCtxtPtr ctxt, char *filename, #ifdef LIBXML_HTML_ENABLED doc = htmlParseFile(filename, NULL); #else - fprintf(stdout, "HTML support not compiled in\n"); + fprintf(ctxt->output, "HTML support not compiled in\n"); doc = NULL; #endif /* LIBXML_HTML_ENABLED */ } else { @@ -1822,24 +1857,27 @@ xmlShellValidate(xmlShellCtxtPtr ctxt, char *dtd, * Returns 0 or -1 in case of error */ int -xmlShellDu(xmlShellCtxtPtr ctxt ATTRIBUTE_UNUSED, +xmlShellDu(xmlShellCtxtPtr ctxt, char *arg ATTRIBUTE_UNUSED, xmlNodePtr tree, xmlNodePtr node2 ATTRIBUTE_UNUSED) { xmlNodePtr node; int indent = 0, i; + if (!ctxt) + return (-1); + if (tree == NULL) return (-1); node = tree; while (node != NULL) { if ((node->type == XML_DOCUMENT_NODE) || (node->type == XML_HTML_DOCUMENT_NODE)) { - fprintf(stdout, "/\n"); + fprintf(ctxt->output, "/\n"); } else if (node->type == XML_ELEMENT_NODE) { for (i = 0; i < indent; i++) - fprintf(stdout, " "); - fprintf(stdout, "%s\n", node->name); + fprintf(ctxt->output, " "); + fprintf(ctxt->output, "%s\n", node->name); } else { } @@ -1934,7 +1972,7 @@ xmlShellPwd(xmlShellCtxtPtr ctxt ATTRIBUTE_UNUSED, char *buffer, * @doc: the initial document * @filename: the output buffer * @input: the line reading function - * @output: the output FILE* + * @output: the output FILE*, defaults to stdout if NULL * * Implements the XML shell * This allow to load, validate, view, modify and save a document @@ -1960,7 +1998,7 @@ xmlShell(xmlDocPtr doc, char *filename, xmlShellReadlineFunc input, if (input == NULL) return; if (output == NULL) - return; + output = stdout; ctxt = (xmlShellCtxtPtr) xmlMalloc(sizeof(xmlShellCtxt)); if (ctxt == NULL) return; @@ -2038,26 +2076,26 @@ xmlShell(xmlDocPtr doc, char *filename, xmlShellReadlineFunc input, if (!strcmp(command, "bye")) break; if (!strcmp(command, "help")) { - fprintf(stdout, "\tbase display XML base of the node\n"); - fprintf(stdout, "\tsetbase URI change the XML base of the node\n"); - fprintf(stdout, "\tbye leave shell\n"); - fprintf(stdout, "\tcat [node] display node or current node\n"); - fprintf(stdout, "\tcd [path] change directory to path or to root\n"); - fprintf(stdout, "\tdir [path] dumps informations about the node (namespace, attributes, content)\n"); - fprintf(stdout, "\tdu [path] show the structure of the subtree under path or the current node\n"); - fprintf(stdout, "\texit leave shell\n"); - fprintf(stdout, "\thelp display this help\n"); - fprintf(stdout, "\tfree display memory usage\n"); - fprintf(stdout, "\tload [name] load a new document with name\n"); - fprintf(stdout, "\tls [path] list contents of path or the current directory\n"); + fprintf(ctxt->output, "\tbase display XML base of the node\n"); + fprintf(ctxt->output, "\tsetbase URI change the XML base of the node\n"); + fprintf(ctxt->output, "\tbye leave shell\n"); + fprintf(ctxt->output, "\tcat [node] display node or current node\n"); + fprintf(ctxt->output, "\tcd [path] change directory to path or to root\n"); + fprintf(ctxt->output, "\tdir [path] dumps informations about the node (namespace, attributes, content)\n"); + fprintf(ctxt->output, "\tdu [path] show the structure of the subtree under path or the current node\n"); + fprintf(ctxt->output, "\texit leave shell\n"); + fprintf(ctxt->output, "\thelp display this help\n"); + fprintf(ctxt->output, "\tfree display memory usage\n"); + fprintf(ctxt->output, "\tload [name] load a new document with name\n"); + fprintf(ctxt->output, "\tls [path] list contents of path or the current directory\n"); #ifdef LIBXML_XPATH_ENABLED - fprintf(stdout, "\txpath expr evaluate the XPath expression in that context and print the result\n"); + fprintf(ctxt->output, "\txpath expr evaluate the XPath expression in that context and print the result\n"); #endif /* LIBXML_XPATH_ENABLED */ - fprintf(stdout, "\tpwd display current working directory\n"); - fprintf(stdout, "\tquit leave shell\n"); - fprintf(stdout, "\tsave [name] save this document to name or the original name\n"); - fprintf(stdout, "\tvalidate check the document for errors\n"); - fprintf(stdout, "\twrite [name] write the current node to the filename\n"); + fprintf(ctxt->output, "\tpwd display current working directory\n"); + fprintf(ctxt->output, "\tquit leave shell\n"); + fprintf(ctxt->output, "\tsave [name] save this document to name or the original name\n"); + fprintf(ctxt->output, "\tvalidate check the document for errors\n"); + fprintf(ctxt->output, "\twrite [name] write the current node to the filename\n"); } else if (!strcmp(command, "validate")) { xmlShellValidate(ctxt, arg, NULL, NULL); } else if (!strcmp(command, "load")) { @@ -2068,18 +2106,18 @@ xmlShell(xmlDocPtr doc, char *filename, xmlShellReadlineFunc input, xmlShellWrite(ctxt, arg, NULL, NULL); } else if (!strcmp(command, "free")) { if (arg[0] == 0) { - xmlMemShow(stdout, 0); + xmlMemShow(ctxt->output, 0); } else { int len = 0; sscanf(arg, "%d", &len); - xmlMemShow(stdout, len); + xmlMemShow(ctxt->output, len); } } else if (!strcmp(command, "pwd")) { char dir[500]; if (!xmlShellPwd(ctxt, dir, ctxt->node, NULL)) - fprintf(stdout, "%s\n", dir); + fprintf(ctxt->output, "%s\n", dir); } else if (!strcmp(command, "du")) { xmlShellDu(ctxt, NULL, ctxt->node, NULL); } else if (!strcmp(command, "base")) { @@ -2092,7 +2130,7 @@ xmlShell(xmlDocPtr doc, char *filename, xmlShellReadlineFunc input, } else { ctxt->pctxt->node = ctxt->node; list = xmlXPathEval((xmlChar *) arg, ctxt->pctxt); - xmlXPathDebugDumpObject(stdout, list, 0); + xmlXPathDebugDumpObject(ctxt->output, list, 0); xmlXPathFreeObject(list); } #endif /* LIBXML_XPATH_ENABLED */ @@ -2283,7 +2321,7 @@ xmlShell(xmlDocPtr doc, char *filename, xmlShellReadlineFunc input, indx < list->nodesetval->nodeNr; indx++) { if (i > 0) - fprintf(stdout, " -------\n"); + fprintf(ctxt->output, " -------\n"); xmlShellCat(ctxt, NULL, list->nodesetval-> nodeTab[indx], NULL); -- cgit v1.2.1