Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(311)

Side by Side Diff: third_party/libxml/src/debugXML.c

Issue 1193533007: Upgrade to libxml 2.9.2 and libxslt 1.1.28 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: no iconv Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « third_party/libxml/src/configure.in ('k') | third_party/libxml/src/depcomp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * debugXML.c : This is a set of routines used for debugging the tree 2 * debugXML.c : This is a set of routines used for debugging the tree
3 * produced by the XML parser. 3 * produced by the XML parser.
4 * 4 *
5 * See Copyright for the status of this software. 5 * See Copyright for the status of this software.
6 * 6 *
7 * Daniel Veillard <daniel@veillard.com> 7 * Daniel Veillard <daniel@veillard.com>
8 */ 8 */
9 9
10 #define IN_LIBXML 10 #define IN_LIBXML
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 /* remove the ATTRIBUTE_UNUSED when this is added */ 78 /* remove the ATTRIBUTE_UNUSED when this is added */
79 } 79 }
80 80
81 /** 81 /**
82 * xmlNsCheckScope: 82 * xmlNsCheckScope:
83 * @node: the node 83 * @node: the node
84 * @ns: the namespace node 84 * @ns: the namespace node
85 * 85 *
86 * Check that a given namespace is in scope on a node. 86 * Check that a given namespace is in scope on a node.
87 * 87 *
88 * Returns 1 if in scope, -1 in case of argument error, 88 * Returns 1 if in scope, -1 in case of argument error,
89 * -2 if the namespace is not in scope, and -3 if not on 89 * -2 if the namespace is not in scope, and -3 if not on
90 * an ancestor node. 90 * an ancestor node.
91 */ 91 */
92 static int 92 static int
93 xmlNsCheckScope(xmlNodePtr node, xmlNsPtr ns) 93 xmlNsCheckScope(xmlNodePtr node, xmlNsPtr ns)
94 { 94 {
95 xmlNsPtr cur; 95 xmlNsPtr cur;
96 96
97 if ((node == NULL) || (ns == NULL)) 97 if ((node == NULL) || (ns == NULL))
98 return(-1); 98 return(-1);
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
247 * conformance to the Name production. 247 * conformance to the Name production.
248 */ 248 */
249 static void 249 static void
250 xmlCtxtCheckName(xmlDebugCtxtPtr ctxt, const xmlChar * name) 250 xmlCtxtCheckName(xmlDebugCtxtPtr ctxt, const xmlChar * name)
251 { 251 {
252 if (ctxt->check) { 252 if (ctxt->check) {
253 if (name == NULL) { 253 if (name == NULL) {
254 xmlDebugErr(ctxt, XML_CHECK_NO_NAME, "Name is NULL"); 254 xmlDebugErr(ctxt, XML_CHECK_NO_NAME, "Name is NULL");
255 return; 255 return;
256 } 256 }
257 #if defined(LIBXML_TREE_ENABLED) || defined(LIBXML_SCHEMAS_ENABLED)
257 if (xmlValidateName(name, 0)) { 258 if (xmlValidateName(name, 0)) {
258 xmlDebugErr3(ctxt, XML_CHECK_NOT_NCNAME, 259 xmlDebugErr3(ctxt, XML_CHECK_NOT_NCNAME,
259 "Name is not an NCName '%s'", (const char *) name); 260 "Name is not an NCName '%s'", (const char *) name);
260 } 261 }
262 #endif
261 if ((ctxt->dict != NULL) && 263 if ((ctxt->dict != NULL) &&
262 (!xmlDictOwns(ctxt->dict, name)) && 264 (!xmlDictOwns(ctxt->dict, name)) &&
263 ((ctxt->doc == NULL) || 265 ((ctxt->doc == NULL) ||
264 ((ctxt->doc->parseFlags & (XML_PARSE_SAX1 | XML_PARSE_NODICT)) == 0 ))) { 266 ((ctxt->doc->parseFlags & (XML_PARSE_SAX1 | XML_PARSE_NODICT)) == 0 ))) {
265 xmlDebugErr3(ctxt, XML_CHECK_OUTSIDE_DICT, 267 xmlDebugErr3(ctxt, XML_CHECK_OUTSIDE_DICT,
266 "Name is not from the document dictionnary '%s'", 268 "Name is not from the document dictionnary '%s'",
267 (const char *) name); 269 (const char *) name);
268 } 270 }
269 } 271 }
270 } 272 }
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
304 if ((node->parent != NULL) && (node->doc != node->parent->doc) && 306 if ((node->parent != NULL) && (node->doc != node->parent->doc) &&
305 (!xmlStrEqual(node->name, BAD_CAST "pseudoroot"))) 307 (!xmlStrEqual(node->name, BAD_CAST "pseudoroot")))
306 xmlDebugErr(ctxt, XML_CHECK_WRONG_DOC, 308 xmlDebugErr(ctxt, XML_CHECK_WRONG_DOC,
307 "Node doc differs from parent's one\n"); 309 "Node doc differs from parent's one\n");
308 if (node->prev == NULL) { 310 if (node->prev == NULL) {
309 if (node->type == XML_ATTRIBUTE_NODE) { 311 if (node->type == XML_ATTRIBUTE_NODE) {
310 if ((node->parent != NULL) && 312 if ((node->parent != NULL) &&
311 (node != (xmlNodePtr) node->parent->properties)) 313 (node != (xmlNodePtr) node->parent->properties))
312 xmlDebugErr(ctxt, XML_CHECK_NO_PREV, 314 xmlDebugErr(ctxt, XML_CHECK_NO_PREV,
313 "Attr has no prev and not first of attr list\n"); 315 "Attr has no prev and not first of attr list\n");
314 » 316
315 } else if ((node->parent != NULL) && (node->parent->children != node)) 317 } else if ((node->parent != NULL) && (node->parent->children != node))
316 xmlDebugErr(ctxt, XML_CHECK_NO_PREV, 318 xmlDebugErr(ctxt, XML_CHECK_NO_PREV,
317 "Node has no prev and not first of parent list\n"); 319 "Node has no prev and not first of parent list\n");
318 } else { 320 } else {
319 if (node->prev->next != node) 321 if (node->prev->next != node)
320 xmlDebugErr(ctxt, XML_CHECK_WRONG_PREV, 322 xmlDebugErr(ctxt, XML_CHECK_WRONG_PREV,
321 "Node prev->next : back link wrong\n"); 323 "Node prev->next : back link wrong\n");
322 } 324 }
323 if (node->next == NULL) { 325 if (node->next == NULL) {
324 if ((node->parent != NULL) && (node->type != XML_ATTRIBUTE_NODE) && 326 if ((node->parent != NULL) && (node->type != XML_ATTRIBUTE_NODE) &&
(...skipping 735 matching lines...) Expand 10 before | Expand all | Expand 10 after
1060 xmlCtxtDumpNode(xmlDebugCtxtPtr ctxt, xmlNodePtr node) 1062 xmlCtxtDumpNode(xmlDebugCtxtPtr ctxt, xmlNodePtr node)
1061 { 1063 {
1062 if (node == NULL) { 1064 if (node == NULL) {
1063 if (!ctxt->check) { 1065 if (!ctxt->check) {
1064 xmlCtxtDumpSpaces(ctxt); 1066 xmlCtxtDumpSpaces(ctxt);
1065 fprintf(ctxt->output, "node is NULL\n"); 1067 fprintf(ctxt->output, "node is NULL\n");
1066 } 1068 }
1067 return; 1069 return;
1068 } 1070 }
1069 xmlCtxtDumpOneNode(ctxt, node); 1071 xmlCtxtDumpOneNode(ctxt, node);
1070 if ((node->type != XML_NAMESPACE_DECL) && 1072 if ((node->type != XML_NAMESPACE_DECL) &&
1071 (node->children != NULL) && (node->type != XML_ENTITY_REF_NODE)) { 1073 (node->children != NULL) && (node->type != XML_ENTITY_REF_NODE)) {
1072 ctxt->depth++; 1074 ctxt->depth++;
1073 xmlCtxtDumpNodeList(ctxt, node->children); 1075 xmlCtxtDumpNodeList(ctxt, node->children);
1074 ctxt->depth--; 1076 ctxt->depth--;
1075 } 1077 }
1076 } 1078 }
1077 1079
1078 /** 1080 /**
1079 * xmlCtxtDumpNodeList: 1081 * xmlCtxtDumpNodeList:
1080 * @output: the FILE * for the output 1082 * @output: the FILE * for the output
(...skipping 514 matching lines...) Expand 10 before | Expand all | Expand 10 after
1595 * @node: the node to count 1597 * @node: the node to count
1596 * 1598 *
1597 * Count the children of @node. 1599 * Count the children of @node.
1598 * 1600 *
1599 * Returns the number of children of @node. 1601 * Returns the number of children of @node.
1600 */ 1602 */
1601 int 1603 int
1602 xmlLsCountNode(xmlNodePtr node) { 1604 xmlLsCountNode(xmlNodePtr node) {
1603 int ret = 0; 1605 int ret = 0;
1604 xmlNodePtr list = NULL; 1606 xmlNodePtr list = NULL;
1605 1607
1606 if (node == NULL) 1608 if (node == NULL)
1607 return(0); 1609 return(0);
1608 1610
1609 switch (node->type) { 1611 switch (node->type) {
1610 case XML_ELEMENT_NODE: 1612 case XML_ELEMENT_NODE:
1611 list = node->children; 1613 list = node->children;
1612 break; 1614 break;
1613 case XML_DOCUMENT_NODE: 1615 case XML_DOCUMENT_NODE:
1614 case XML_HTML_DOCUMENT_NODE: 1616 case XML_HTML_DOCUMENT_NODE:
1615 #ifdef LIBXML_DOCB_ENABLED 1617 #ifdef LIBXML_DOCB_ENABLED
(...skipping 20 matching lines...) Expand all
1636 case XML_DTD_NODE: 1638 case XML_DTD_NODE:
1637 case XML_ELEMENT_DECL: 1639 case XML_ELEMENT_DECL:
1638 case XML_ATTRIBUTE_DECL: 1640 case XML_ATTRIBUTE_DECL:
1639 case XML_ENTITY_DECL: 1641 case XML_ENTITY_DECL:
1640 case XML_NAMESPACE_DECL: 1642 case XML_NAMESPACE_DECL:
1641 case XML_XINCLUDE_START: 1643 case XML_XINCLUDE_START:
1642 case XML_XINCLUDE_END: 1644 case XML_XINCLUDE_END:
1643 ret = 1; 1645 ret = 1;
1644 break; 1646 break;
1645 } 1647 }
1646 for (;list != NULL;ret++) 1648 for (;list != NULL;ret++)
1647 list = list->next; 1649 list = list->next;
1648 return(ret); 1650 return(ret);
1649 } 1651 }
1650 1652
1651 /** 1653 /**
1652 * xmlLsOneNode: 1654 * xmlLsOneNode:
1653 * @output: the FILE * for the output 1655 * @output: the FILE * for the output
1654 * @node: the node to dump 1656 * @node: the node to dump
1655 * 1657 *
1656 * Dump to @output the type and name of @node. 1658 * Dump to @output the type and name of @node.
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
1704 break; 1706 break;
1705 case XML_NAMESPACE_DECL: 1707 case XML_NAMESPACE_DECL:
1706 fprintf(output, "n"); 1708 fprintf(output, "n");
1707 break; 1709 break;
1708 default: 1710 default:
1709 fprintf(output, "?"); 1711 fprintf(output, "?");
1710 } 1712 }
1711 if (node->type != XML_NAMESPACE_DECL) { 1713 if (node->type != XML_NAMESPACE_DECL) {
1712 if (node->properties != NULL) 1714 if (node->properties != NULL)
1713 fprintf(output, "a"); 1715 fprintf(output, "a");
1714 » else» 1716 » else
1715 fprintf(output, "-"); 1717 fprintf(output, "-");
1716 » if (node->nsDef != NULL) 1718 » if (node->nsDef != NULL)
1717 fprintf(output, "n"); 1719 fprintf(output, "n");
1718 » else» 1720 » else
1719 fprintf(output, "-"); 1721 fprintf(output, "-");
1720 } 1722 }
1721 1723
1722 fprintf(output, " %8d ", xmlLsCountNode(node)); 1724 fprintf(output, " %8d ", xmlLsCountNode(node));
1723 1725
1724 switch (node->type) { 1726 switch (node->type) {
1725 case XML_ELEMENT_NODE: 1727 case XML_ELEMENT_NODE:
1726 » if (node->name != NULL) 1728 » if (node->name != NULL) {
1729 if ((node->ns != NULL) && (node->ns->prefix != NULL))
1730 fprintf(output, "%s:", node->ns->prefix);
1727 fprintf(output, "%s", (const char *) node->name); 1731 fprintf(output, "%s", (const char *) node->name);
1732 }
1728 break; 1733 break;
1729 case XML_ATTRIBUTE_NODE: 1734 case XML_ATTRIBUTE_NODE:
1730 if (node->name != NULL) 1735 if (node->name != NULL)
1731 fprintf(output, "%s", (const char *) node->name); 1736 fprintf(output, "%s", (const char *) node->name);
1732 break; 1737 break;
1733 case XML_TEXT_NODE: 1738 case XML_TEXT_NODE:
1734 if (node->content != NULL) { 1739 if (node->content != NULL) {
1735 xmlDebugDumpString(output, node->content); 1740 xmlDebugDumpString(output, node->content);
1736 } 1741 }
1737 break; 1742 break;
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
1775 if (node->name != NULL) 1780 if (node->name != NULL)
1776 fprintf(output, "%s", (const char *) node->name); 1781 fprintf(output, "%s", (const char *) node->name);
1777 } 1782 }
1778 fprintf(output, "\n"); 1783 fprintf(output, "\n");
1779 } 1784 }
1780 1785
1781 /** 1786 /**
1782 * xmlBoolToText: 1787 * xmlBoolToText:
1783 * @boolval: a bool to turn into text 1788 * @boolval: a bool to turn into text
1784 * 1789 *
1785 * Convenient way to turn bool into text 1790 * Convenient way to turn bool into text
1786 * 1791 *
1787 * Returns a pointer to either "True" or "False" 1792 * Returns a pointer to either "True" or "False"
1788 */ 1793 */
1789 const char * 1794 const char *
1790 xmlBoolToText(int boolval) 1795 xmlBoolToText(int boolval)
1791 { 1796 {
1792 if (boolval) 1797 if (boolval)
1793 return("True"); 1798 return("True");
1794 else 1799 else
1795 return("False"); 1800 return("False");
1796 } 1801 }
1797 1802
1798 #ifdef LIBXML_XPATH_ENABLED 1803 #ifdef LIBXML_XPATH_ENABLED
1799 /**************************************************************** 1804 /****************************************************************
1800 * * 1805 * *
1801 *» » The XML shell related functions»» » * 1806 *» » The XML shell related functions»» » *
1802 * * 1807 * *
1803 ****************************************************************/ 1808 ****************************************************************/
1804 1809
1805 1810
1806 1811
1807 /* 1812 /*
1808 * TODO: Improvement/cleanups for the XML shell 1813 * TODO: Improvement/cleanups for the XML shell
1809 * - allow to shell out an editor on a subpart 1814 * - allow to shell out an editor on a subpart
1810 * - cleanup function registrations (with help) and calling 1815 * - cleanup function registrations (with help) and calling
1811 * - provide registration routines 1816 * - provide registration routines
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after
2042 xmlShellBase(xmlShellCtxtPtr ctxt, 2047 xmlShellBase(xmlShellCtxtPtr ctxt,
2043 char *arg ATTRIBUTE_UNUSED, xmlNodePtr node, 2048 char *arg ATTRIBUTE_UNUSED, xmlNodePtr node,
2044 xmlNodePtr node2 ATTRIBUTE_UNUSED) 2049 xmlNodePtr node2 ATTRIBUTE_UNUSED)
2045 { 2050 {
2046 xmlChar *base; 2051 xmlChar *base;
2047 if (!ctxt) 2052 if (!ctxt)
2048 return 0; 2053 return 0;
2049 if (node == NULL) { 2054 if (node == NULL) {
2050 fprintf(ctxt->output, "NULL\n"); 2055 fprintf(ctxt->output, "NULL\n");
2051 return (0); 2056 return (0);
2052 } 2057 }
2053 2058
2054 base = xmlNodeGetBase(node->doc, node); 2059 base = xmlNodeGetBase(node->doc, node);
2055 2060
2056 if (base == NULL) { 2061 if (base == NULL) {
2057 fprintf(ctxt->output, " No base found !!!\n"); 2062 fprintf(ctxt->output, " No base found !!!\n");
2058 } else { 2063 } else {
2059 fprintf(ctxt->output, "%s\n", base); 2064 fprintf(ctxt->output, "%s\n", base);
2060 xmlFree(base); 2065 xmlFree(base);
2061 } 2066 }
2062 return (0); 2067 return (0);
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
2269 int 2274 int
2270 xmlShellDir(xmlShellCtxtPtr ctxt ATTRIBUTE_UNUSED, 2275 xmlShellDir(xmlShellCtxtPtr ctxt ATTRIBUTE_UNUSED,
2271 char *arg ATTRIBUTE_UNUSED, xmlNodePtr node, 2276 char *arg ATTRIBUTE_UNUSED, xmlNodePtr node,
2272 xmlNodePtr node2 ATTRIBUTE_UNUSED) 2277 xmlNodePtr node2 ATTRIBUTE_UNUSED)
2273 { 2278 {
2274 if (!ctxt) 2279 if (!ctxt)
2275 return (0); 2280 return (0);
2276 if (node == NULL) { 2281 if (node == NULL) {
2277 fprintf(ctxt->output, "NULL\n"); 2282 fprintf(ctxt->output, "NULL\n");
2278 return (0); 2283 return (0);
2279 } 2284 }
2280 if ((node->type == XML_DOCUMENT_NODE) || 2285 if ((node->type == XML_DOCUMENT_NODE) ||
2281 (node->type == XML_HTML_DOCUMENT_NODE)) { 2286 (node->type == XML_HTML_DOCUMENT_NODE)) {
2282 xmlDebugDumpDocumentHead(ctxt->output, (xmlDocPtr) node); 2287 xmlDebugDumpDocumentHead(ctxt->output, (xmlDocPtr) node);
2283 } else if (node->type == XML_ATTRIBUTE_NODE) { 2288 } else if (node->type == XML_ATTRIBUTE_NODE) {
2284 xmlDebugDumpAttr(ctxt->output, (xmlAttrPtr) node, 0); 2289 xmlDebugDumpAttr(ctxt->output, (xmlAttrPtr) node, 0);
2285 } else { 2290 } else {
2286 xmlDebugDumpOneNode(ctxt->output, node, 0); 2291 xmlDebugDumpOneNode(ctxt->output, node, 0);
2287 } 2292 }
2288 return (0); 2293 return (0);
2289 } 2294 }
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
2404 */ 2409 */
2405 int 2410 int
2406 xmlShellCat(xmlShellCtxtPtr ctxt, char *arg ATTRIBUTE_UNUSED, 2411 xmlShellCat(xmlShellCtxtPtr ctxt, char *arg ATTRIBUTE_UNUSED,
2407 xmlNodePtr node, xmlNodePtr node2 ATTRIBUTE_UNUSED) 2412 xmlNodePtr node, xmlNodePtr node2 ATTRIBUTE_UNUSED)
2408 { 2413 {
2409 if (!ctxt) 2414 if (!ctxt)
2410 return (0); 2415 return (0);
2411 if (node == NULL) { 2416 if (node == NULL) {
2412 fprintf(ctxt->output, "NULL\n"); 2417 fprintf(ctxt->output, "NULL\n");
2413 return (0); 2418 return (0);
2414 } 2419 }
2415 if (ctxt->doc->type == XML_HTML_DOCUMENT_NODE) { 2420 if (ctxt->doc->type == XML_HTML_DOCUMENT_NODE) {
2416 #ifdef LIBXML_HTML_ENABLED 2421 #ifdef LIBXML_HTML_ENABLED
2417 if (node->type == XML_HTML_DOCUMENT_NODE) 2422 if (node->type == XML_HTML_DOCUMENT_NODE)
2418 htmlDocDump(ctxt->output, (htmlDocPtr) node); 2423 htmlDocDump(ctxt->output, (htmlDocPtr) node);
2419 else 2424 else
2420 htmlNodeDumpFile(ctxt->output, ctxt->doc, node); 2425 htmlNodeDumpFile(ctxt->output, ctxt->doc, node);
2421 #else 2426 #else
2422 if (node->type == XML_DOCUMENT_NODE) 2427 if (node->type == XML_DOCUMENT_NODE)
2423 xmlDocDump(ctxt->output, (xmlDocPtr) node); 2428 xmlDocDump(ctxt->output, (xmlDocPtr) node);
2424 else 2429 else
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after
2688 if (tree == NULL) 2693 if (tree == NULL)
2689 return (-1); 2694 return (-1);
2690 node = tree; 2695 node = tree;
2691 while (node != NULL) { 2696 while (node != NULL) {
2692 if ((node->type == XML_DOCUMENT_NODE) || 2697 if ((node->type == XML_DOCUMENT_NODE) ||
2693 (node->type == XML_HTML_DOCUMENT_NODE)) { 2698 (node->type == XML_HTML_DOCUMENT_NODE)) {
2694 fprintf(ctxt->output, "/\n"); 2699 fprintf(ctxt->output, "/\n");
2695 } else if (node->type == XML_ELEMENT_NODE) { 2700 } else if (node->type == XML_ELEMENT_NODE) {
2696 for (i = 0; i < indent; i++) 2701 for (i = 0; i < indent; i++)
2697 fprintf(ctxt->output, " "); 2702 fprintf(ctxt->output, " ");
2703 if ((node->ns) && (node->ns->prefix))
2704 fprintf(ctxt->output, "%s:", node->ns->prefix);
2698 fprintf(ctxt->output, "%s\n", node->name); 2705 fprintf(ctxt->output, "%s\n", node->name);
2699 } else { 2706 } else {
2700 } 2707 }
2701 2708
2702 /* 2709 /*
2703 * Browse the full subtree, deep first 2710 * Browse the full subtree, deep first
2704 */ 2711 */
2705 2712
2706 if ((node->type == XML_DOCUMENT_NODE) || 2713 if ((node->type == XML_DOCUMENT_NODE) ||
2707 (node->type == XML_HTML_DOCUMENT_NODE)) { 2714 (node->type == XML_HTML_DOCUMENT_NODE)) {
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
2740 } else 2747 } else
2741 node = NULL; 2748 node = NULL;
2742 } 2749 }
2743 return (0); 2750 return (0);
2744 } 2751 }
2745 2752
2746 /** 2753 /**
2747 * xmlShellPwd: 2754 * xmlShellPwd:
2748 * @ctxt: the shell context 2755 * @ctxt: the shell context
2749 * @buffer: the output buffer 2756 * @buffer: the output buffer
2750 * @node: a node 2757 * @node: a node
2751 * @node2: unused 2758 * @node2: unused
2752 * 2759 *
2753 * Implements the XML shell function "pwd" 2760 * Implements the XML shell function "pwd"
2754 * Show the full path from the root to the node, if needed building 2761 * Show the full path from the root to the node, if needed building
2755 * thumblers when similar elements exists at a given ancestor level. 2762 * thumblers when similar elements exists at a given ancestor level.
2756 * The output is compatible with XPath commands. 2763 * The output is compatible with XPath commands.
2757 * 2764 *
2758 * Returns 0 or -1 in case of error 2765 * Returns 0 or -1 in case of error
2759 */ 2766 */
2760 int 2767 int
(...skipping 24 matching lines...) Expand all
2785 return (0); 2792 return (0);
2786 } 2793 }
2787 2794
2788 /** 2795 /**
2789 * xmlShell: 2796 * xmlShell:
2790 * @doc: the initial document 2797 * @doc: the initial document
2791 * @filename: the output buffer 2798 * @filename: the output buffer
2792 * @input: the line reading function 2799 * @input: the line reading function
2793 * @output: the output FILE*, defaults to stdout if NULL 2800 * @output: the output FILE*, defaults to stdout if NULL
2794 * 2801 *
2795 * Implements the XML shell 2802 * Implements the XML shell
2796 * This allow to load, validate, view, modify and save a document 2803 * This allow to load, validate, view, modify and save a document
2797 * using a environment similar to a UNIX commandline. 2804 * using a environment similar to a UNIX commandline.
2798 */ 2805 */
2799 void 2806 void
2800 xmlShell(xmlDocPtr doc, char *filename, xmlShellReadlineFunc input, 2807 xmlShell(xmlDocPtr doc, char *filename, xmlShellReadlineFunc input,
2801 FILE * output) 2808 FILE * output)
2802 { 2809 {
2803 char prompt[500] = "/ > "; 2810 char prompt[500] = "/ > ";
2804 char *cmdline = NULL, *cur; 2811 char *cmdline = NULL, *cur;
2805 char command[100]; 2812 char command[100];
(...skipping 23 matching lines...) Expand all
2829 #ifdef LIBXML_XPATH_ENABLED 2836 #ifdef LIBXML_XPATH_ENABLED
2830 ctxt->pctxt = xmlXPathNewContext(ctxt->doc); 2837 ctxt->pctxt = xmlXPathNewContext(ctxt->doc);
2831 if (ctxt->pctxt == NULL) { 2838 if (ctxt->pctxt == NULL) {
2832 xmlFree(ctxt); 2839 xmlFree(ctxt);
2833 return; 2840 return;
2834 } 2841 }
2835 #endif /* LIBXML_XPATH_ENABLED */ 2842 #endif /* LIBXML_XPATH_ENABLED */
2836 while (1) { 2843 while (1) {
2837 if (ctxt->node == (xmlNodePtr) ctxt->doc) 2844 if (ctxt->node == (xmlNodePtr) ctxt->doc)
2838 snprintf(prompt, sizeof(prompt), "%s > ", "/"); 2845 snprintf(prompt, sizeof(prompt), "%s > ", "/");
2846 else if ((ctxt->node != NULL) && (ctxt->node->name) &&
2847 (ctxt->node->ns) && (ctxt->node->ns->prefix))
2848 snprintf(prompt, sizeof(prompt), "%s:%s > ",
2849 (ctxt->node->ns->prefix), ctxt->node->name);
2839 else if ((ctxt->node != NULL) && (ctxt->node->name)) 2850 else if ((ctxt->node != NULL) && (ctxt->node->name))
2840 snprintf(prompt, sizeof(prompt), "%s > ", ctxt->node->name); 2851 snprintf(prompt, sizeof(prompt), "%s > ", ctxt->node->name);
2841 else 2852 else
2842 snprintf(prompt, sizeof(prompt), "? > "); 2853 snprintf(prompt, sizeof(prompt), "? > ");
2843 prompt[sizeof(prompt) - 1] = 0; 2854 prompt[sizeof(prompt) - 1] = 0;
2844 2855
2845 /* 2856 /*
2846 * Get a new command line 2857 * Get a new command line
2847 */ 2858 */
2848 cmdline = ctxt->input(prompt); 2859 cmdline = ctxt->input(prompt);
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
2903 fprintf(ctxt->output, "\tls [path] list contents of path or the current directory\n"); 2914 fprintf(ctxt->output, "\tls [path] list contents of path or the current directory\n");
2904 fprintf(ctxt->output, "\tset xml_fragment replace the current node content with the fragment parsed in context\n"); 2915 fprintf(ctxt->output, "\tset xml_fragment replace the current node content with the fragment parsed in context\n");
2905 #ifdef LIBXML_XPATH_ENABLED 2916 #ifdef LIBXML_XPATH_ENABLED
2906 fprintf(ctxt->output, "\txpath expr evaluate the XPath expre ssion in that context and print the result\n"); 2917 fprintf(ctxt->output, "\txpath expr evaluate the XPath expre ssion in that context and print the result\n");
2907 fprintf(ctxt->output, "\tsetns nsreg register a namespace to a prefix in the XPath evaluation context\n"); 2918 fprintf(ctxt->output, "\tsetns nsreg register a namespace to a prefix in the XPath evaluation context\n");
2908 fprintf(ctxt->output, "\t format for nsreg is: pre fix=[nsuri] (i.e. prefix= unsets a prefix)\n"); 2919 fprintf(ctxt->output, "\t format for nsreg is: pre fix=[nsuri] (i.e. prefix= unsets a prefix)\n");
2909 fprintf(ctxt->output, "\tsetrootns register all namespace f ound on the root element\n"); 2920 fprintf(ctxt->output, "\tsetrootns register all namespace f ound on the root element\n");
2910 fprintf(ctxt->output, "\t the default namespace if any uses 'defaultns' prefix\n"); 2921 fprintf(ctxt->output, "\t the default namespace if any uses 'defaultns' prefix\n");
2911 #endif /* LIBXML_XPATH_ENABLED */ 2922 #endif /* LIBXML_XPATH_ENABLED */
2912 fprintf(ctxt->output, "\tpwd display current working directory\n"); 2923 fprintf(ctxt->output, "\tpwd display current working directory\n");
2924 fprintf(ctxt->output, "\twhereis display absolute path of [path] or current working directory\n");
2913 fprintf(ctxt->output, "\tquit leave shell\n"); 2925 fprintf(ctxt->output, "\tquit leave shell\n");
2914 #ifdef LIBXML_OUTPUT_ENABLED 2926 #ifdef LIBXML_OUTPUT_ENABLED
2915 fprintf(ctxt->output, "\tsave [name] save this document to na me or the original name\n"); 2927 fprintf(ctxt->output, "\tsave [name] save this document to na me or the original name\n");
2916 fprintf(ctxt->output, "\twrite [name] write the current node t o the filename\n"); 2928 fprintf(ctxt->output, "\twrite [name] write the current node t o the filename\n");
2917 #endif /* LIBXML_OUTPUT_ENABLED */ 2929 #endif /* LIBXML_OUTPUT_ENABLED */
2918 #ifdef LIBXML_VALID_ENABLED 2930 #ifdef LIBXML_VALID_ENABLED
2919 fprintf(ctxt->output, "\tvalidate check the document for e rrors\n"); 2931 fprintf(ctxt->output, "\tvalidate check the document for e rrors\n");
2920 #endif /* LIBXML_VALID_ENABLED */ 2932 #endif /* LIBXML_VALID_ENABLED */
2921 #ifdef LIBXML_SCHEMAS_ENABLED 2933 #ifdef LIBXML_SCHEMAS_ENABLED
2922 fprintf(ctxt->output, "\trelaxng rng validate the document ag aisnt the Relax-NG schemas\n"); 2934 fprintf(ctxt->output, "\trelaxng rng validate the document ag aisnt the Relax-NG schemas\n");
2923 #endif 2935 #endif
2924 fprintf(ctxt->output, "\tgrep string search for a string in t he subtree\n"); 2936 fprintf(ctxt->output, "\tgrep string search for a string in t he subtree\n");
2925 #ifdef LIBXML_VALID_ENABLED 2937 #ifdef LIBXML_VALID_ENABLED
2926 } else if (!strcmp(command, "validate")) { 2938 } else if (!strcmp(command, "validate")) {
2927 xmlShellValidate(ctxt, arg, NULL, NULL); 2939 xmlShellValidate(ctxt, arg, NULL, NULL);
2928 #endif /* LIBXML_VALID_ENABLED */ 2940 #endif /* LIBXML_VALID_ENABLED */
2929 } else if (!strcmp(command, "load")) { 2941 } else if (!strcmp(command, "load")) {
2930 xmlShellLoad(ctxt, arg, NULL, NULL); 2942 xmlShellLoad(ctxt, arg, NULL, NULL);
2931 #ifdef LIBXML_SCHEMAS_ENABLED 2943 #ifdef LIBXML_SCHEMAS_ENABLED
2932 } else if (!strcmp(command, "relaxng")) { 2944 } else if (!strcmp(command, "relaxng")) {
2933 xmlShellRNGValidate(ctxt, arg, NULL, NULL); 2945 xmlShellRNGValidate(ctxt, arg, NULL, NULL);
2934 #endif 2946 #endif
2935 #ifdef LIBXML_OUTPUT_ENABLED 2947 #ifdef LIBXML_OUTPUT_ENABLED
2936 } else if (!strcmp(command, "save")) { 2948 } else if (!strcmp(command, "save")) {
2937 xmlShellSave(ctxt, arg, NULL, NULL); 2949 xmlShellSave(ctxt, arg, NULL, NULL);
2938 } else if (!strcmp(command, "write")) { 2950 } else if (!strcmp(command, "write")) {
2939 » if ((arg == NULL) || (arg[0] == 0)) 2951 » if (arg[0] == 0)
2940 xmlGenericError(xmlGenericErrorContext, 2952 xmlGenericError(xmlGenericErrorContext,
2941 "Write command requires a filename argument\n"); 2953 "Write command requires a filename argument\n");
2942 else 2954 else
2943 » » xmlShellWrite(ctxt, arg, NULL, NULL); 2955 » » xmlShellWrite(ctxt, arg, ctxt->node, NULL);
2944 #endif /* LIBXML_OUTPUT_ENABLED */ 2956 #endif /* LIBXML_OUTPUT_ENABLED */
2945 } else if (!strcmp(command, "grep")) { 2957 } else if (!strcmp(command, "grep")) {
2946 xmlShellGrep(ctxt, arg, ctxt->node, NULL); 2958 xmlShellGrep(ctxt, arg, ctxt->node, NULL);
2947 } else if (!strcmp(command, "free")) { 2959 } else if (!strcmp(command, "free")) {
2948 if (arg[0] == 0) { 2960 if (arg[0] == 0) {
2949 xmlMemShow(ctxt->output, 0); 2961 xmlMemShow(ctxt->output, 0);
2950 } else { 2962 } else {
2951 int len = 0; 2963 int len = 0;
2952 2964
2953 sscanf(arg, "%d", &len); 2965 sscanf(arg, "%d", &len);
2954 xmlMemShow(ctxt->output, len); 2966 xmlMemShow(ctxt->output, len);
2955 } 2967 }
2956 } else if (!strcmp(command, "pwd")) { 2968 } else if (!strcmp(command, "pwd")) {
2957 char dir[500]; 2969 char dir[500];
2958 2970
2959 if (!xmlShellPwd(ctxt, dir, ctxt->node, NULL)) 2971 if (!xmlShellPwd(ctxt, dir, ctxt->node, NULL))
2960 fprintf(ctxt->output, "%s\n", dir); 2972 fprintf(ctxt->output, "%s\n", dir);
2961 } else if (!strcmp(command, "du")) { 2973 } else if (!strcmp(command, "du")) {
2962 xmlShellDu(ctxt, NULL, ctxt->node, NULL); 2974 if (arg[0] == 0) {
2975 xmlShellDu(ctxt, NULL, ctxt->node, NULL);
2976 } else {
2977 ctxt->pctxt->node = ctxt->node;
2978 #ifdef LIBXML_XPATH_ENABLED
2979 ctxt->pctxt->node = ctxt->node;
2980 list = xmlXPathEval((xmlChar *) arg, ctxt->pctxt);
2981 #else
2982 list = NULL;
2983 #endif /* LIBXML_XPATH_ENABLED */
2984 if (list != NULL) {
2985 switch (list->type) {
2986 case XPATH_UNDEFINED:
2987 xmlGenericError(xmlGenericErrorContext,
2988 "%s: no such node\n", arg);
2989 break;
2990 case XPATH_NODESET:{
2991 int indx;
2992
2993 if (list->nodesetval == NULL)
2994 break;
2995
2996 for (indx = 0;
2997 indx < list->nodesetval->nodeNr;
2998 indx++)
2999 xmlShellDu(ctxt, NULL,
3000 list->nodesetval->
3001 nodeTab[indx], NULL);
3002 break;
3003 }
3004 case XPATH_BOOLEAN:
3005 xmlGenericError(xmlGenericErrorContext,
3006 "%s is a Boolean\n", arg);
3007 break;
3008 case XPATH_NUMBER:
3009 xmlGenericError(xmlGenericErrorContext,
3010 "%s is a number\n", arg);
3011 break;
3012 case XPATH_STRING:
3013 xmlGenericError(xmlGenericErrorContext,
3014 "%s is a string\n", arg);
3015 break;
3016 case XPATH_POINT:
3017 xmlGenericError(xmlGenericErrorContext,
3018 "%s is a point\n", arg);
3019 break;
3020 case XPATH_RANGE:
3021 xmlGenericError(xmlGenericErrorContext,
3022 "%s is a range\n", arg);
3023 break;
3024 case XPATH_LOCATIONSET:
3025 xmlGenericError(xmlGenericErrorContext,
3026 "%s is a range\n", arg);
3027 break;
3028 case XPATH_USERS:
3029 xmlGenericError(xmlGenericErrorContext,
3030 "%s is user-defined\n", arg);
3031 break;
3032 case XPATH_XSLT_TREE:
3033 xmlGenericError(xmlGenericErrorContext,
3034 "%s is an XSLT value tree\n",
3035 arg);
3036 break;
3037 }
3038 #ifdef LIBXML_XPATH_ENABLED
3039 xmlXPathFreeObject(list);
3040 #endif
3041 } else {
3042 xmlGenericError(xmlGenericErrorContext,
3043 "%s: no such node\n", arg);
3044 }
3045 ctxt->pctxt->node = NULL;
3046 }
2963 } else if (!strcmp(command, "base")) { 3047 } else if (!strcmp(command, "base")) {
2964 xmlShellBase(ctxt, NULL, ctxt->node, NULL); 3048 xmlShellBase(ctxt, NULL, ctxt->node, NULL);
2965 } else if (!strcmp(command, "set")) { 3049 } else if (!strcmp(command, "set")) {
2966 xmlShellSetContent(ctxt, arg, ctxt->node, NULL); 3050 xmlShellSetContent(ctxt, arg, ctxt->node, NULL);
2967 #ifdef LIBXML_XPATH_ENABLED 3051 #ifdef LIBXML_XPATH_ENABLED
2968 } else if (!strcmp(command, "setns")) { 3052 } else if (!strcmp(command, "setns")) {
2969 if (arg[0] == 0) { 3053 if (arg[0] == 0) {
2970 xmlGenericError(xmlGenericErrorContext, 3054 xmlGenericError(xmlGenericErrorContext,
2971 "setns: prefix=[nsuri] required\n"); 3055 "setns: prefix=[nsuri] required\n");
2972 } else { 3056 } else {
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
3070 } 3154 }
3071 #ifdef LIBXML_XPATH_ENABLED 3155 #ifdef LIBXML_XPATH_ENABLED
3072 xmlXPathFreeObject(list); 3156 xmlXPathFreeObject(list);
3073 #endif 3157 #endif
3074 } else { 3158 } else {
3075 xmlGenericError(xmlGenericErrorContext, 3159 xmlGenericError(xmlGenericErrorContext,
3076 "%s: no such node\n", arg); 3160 "%s: no such node\n", arg);
3077 } 3161 }
3078 ctxt->pctxt->node = NULL; 3162 ctxt->pctxt->node = NULL;
3079 } 3163 }
3164 } else if (!strcmp(command, "whereis")) {
3165 char dir[500];
3166
3167 if (arg[0] == 0) {
3168 if (!xmlShellPwd(ctxt, dir, ctxt->node, NULL))
3169 fprintf(ctxt->output, "%s\n", dir);
3170 } else {
3171 ctxt->pctxt->node = ctxt->node;
3172 #ifdef LIBXML_XPATH_ENABLED
3173 list = xmlXPathEval((xmlChar *) arg, ctxt->pctxt);
3174 #else
3175 list = NULL;
3176 #endif /* LIBXML_XPATH_ENABLED */
3177 if (list != NULL) {
3178 switch (list->type) {
3179 case XPATH_UNDEFINED:
3180 xmlGenericError(xmlGenericErrorContext,
3181 "%s: no such node\n", arg);
3182 break;
3183 case XPATH_NODESET:{
3184 int indx;
3185
3186 if (list->nodesetval == NULL)
3187 break;
3188
3189 for (indx = 0;
3190 indx < list->nodesetval->nodeNr;
3191 indx++) {
3192 if (!xmlShellPwd(ctxt, dir, list->nodesetval ->
3193 nodeTab[indx], NULL))
3194 fprintf(ctxt->output, "%s\n", dir);
3195 }
3196 break;
3197 }
3198 case XPATH_BOOLEAN:
3199 xmlGenericError(xmlGenericErrorContext,
3200 "%s is a Boolean\n", arg);
3201 break;
3202 case XPATH_NUMBER:
3203 xmlGenericError(xmlGenericErrorContext,
3204 "%s is a number\n", arg);
3205 break;
3206 case XPATH_STRING:
3207 xmlGenericError(xmlGenericErrorContext,
3208 "%s is a string\n", arg);
3209 break;
3210 case XPATH_POINT:
3211 xmlGenericError(xmlGenericErrorContext,
3212 "%s is a point\n", arg);
3213 break;
3214 case XPATH_RANGE:
3215 xmlGenericError(xmlGenericErrorContext,
3216 "%s is a range\n", arg);
3217 break;
3218 case XPATH_LOCATIONSET:
3219 xmlGenericError(xmlGenericErrorContext,
3220 "%s is a range\n", arg);
3221 break;
3222 case XPATH_USERS:
3223 xmlGenericError(xmlGenericErrorContext,
3224 "%s is user-defined\n", arg);
3225 break;
3226 case XPATH_XSLT_TREE:
3227 xmlGenericError(xmlGenericErrorContext,
3228 "%s is an XSLT value tree\n",
3229 arg);
3230 break;
3231 }
3232 #ifdef LIBXML_XPATH_ENABLED
3233 xmlXPathFreeObject(list);
3234 #endif
3235 } else {
3236 xmlGenericError(xmlGenericErrorContext,
3237 "%s: no such node\n", arg);
3238 }
3239 ctxt->pctxt->node = NULL;
3240 }
3080 } else if (!strcmp(command, "cd")) { 3241 } else if (!strcmp(command, "cd")) {
3081 if (arg[0] == 0) { 3242 if (arg[0] == 0) {
3082 ctxt->node = (xmlNodePtr) ctxt->doc; 3243 ctxt->node = (xmlNodePtr) ctxt->doc;
3083 } else { 3244 } else {
3084 #ifdef LIBXML_XPATH_ENABLED 3245 #ifdef LIBXML_XPATH_ENABLED
3246 int l;
3247
3085 ctxt->pctxt->node = ctxt->node; 3248 ctxt->pctxt->node = ctxt->node;
3249 l = strlen(arg);
3250 if ((l >= 2) && (arg[l - 1] == '/'))
3251 arg[l - 1] = 0;
3086 list = xmlXPathEval((xmlChar *) arg, ctxt->pctxt); 3252 list = xmlXPathEval((xmlChar *) arg, ctxt->pctxt);
3087 #else 3253 #else
3088 list = NULL; 3254 list = NULL;
3089 #endif /* LIBXML_XPATH_ENABLED */ 3255 #endif /* LIBXML_XPATH_ENABLED */
3090 if (list != NULL) { 3256 if (list != NULL) {
3091 switch (list->type) { 3257 switch (list->type) {
3092 case XPATH_UNDEFINED: 3258 case XPATH_UNDEFINED:
3093 xmlGenericError(xmlGenericErrorContext, 3259 xmlGenericError(xmlGenericErrorContext,
3094 "%s: no such node\n", arg); 3260 "%s: no such node\n", arg);
3095 break; 3261 break;
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
3253 xmlFree(ctxt->filename); 3419 xmlFree(ctxt->filename);
3254 xmlFree(ctxt); 3420 xmlFree(ctxt);
3255 if (cmdline != NULL) 3421 if (cmdline != NULL)
3256 free(cmdline); /* not xmlFree here ! */ 3422 free(cmdline); /* not xmlFree here ! */
3257 } 3423 }
3258 3424
3259 #endif /* LIBXML_XPATH_ENABLED */ 3425 #endif /* LIBXML_XPATH_ENABLED */
3260 #define bottom_debugXML 3426 #define bottom_debugXML
3261 #include "elfgcchack.h" 3427 #include "elfgcchack.h"
3262 #endif /* LIBXML_DEBUG_ENABLED */ 3428 #endif /* LIBXML_DEBUG_ENABLED */
OLDNEW
« no previous file with comments | « third_party/libxml/src/configure.in ('k') | third_party/libxml/src/depcomp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698