summaryrefslogtreecommitdiff
path: root/debugXML.c
diff options
context:
space:
mode:
authorAron Xu <aron@debian.org>2012-05-25 04:03:35 +0000
committerAron Xu <aron@debian.org>2012-05-25 04:03:35 +0000
commitd7372d053bbd1d58216fbb04d1771ffa4cc3e624 (patch)
tree62b661911406394bbeaca8951d660bb6d8aac0de /debugXML.c
parent2d1849b271fa8697b88d07ba7d78dc83591e1363 (diff)
downloadlibxml2-d7372d053bbd1d58216fbb04d1771ffa4cc3e624.tar.gz
Imported Upstream version 2.8.0+dfsg1upstream/2.8.0+dfsg1
Diffstat (limited to 'debugXML.c')
-rw-r--r--debugXML.c163
1 files changed, 161 insertions, 2 deletions
diff --git a/debugXML.c b/debugXML.c
index c26217a..3e9ec7a 100644
--- a/debugXML.c
+++ b/debugXML.c
@@ -1724,8 +1724,11 @@ xmlLsOneNode(FILE *output, xmlNodePtr node) {
switch (node->type) {
case XML_ELEMENT_NODE:
- if (node->name != NULL)
+ if (node->name != NULL) {
+ if ((node->ns != NULL) && (node->ns->prefix != NULL))
+ fprintf(output, "%s:", node->ns->prefix);
fprintf(output, "%s", (const char *) node->name);
+ }
break;
case XML_ATTRIBUTE_NODE:
if (node->name != NULL)
@@ -2696,6 +2699,8 @@ xmlShellDu(xmlShellCtxtPtr ctxt,
} else if (node->type == XML_ELEMENT_NODE) {
for (i = 0; i < indent; i++)
fprintf(ctxt->output, " ");
+ if ((node->ns) && (node->ns->prefix))
+ fprintf(ctxt->output, "%s:", node->ns->prefix);
fprintf(ctxt->output, "%s\n", node->name);
} else {
}
@@ -2837,6 +2842,10 @@ xmlShell(xmlDocPtr doc, char *filename, xmlShellReadlineFunc input,
while (1) {
if (ctxt->node == (xmlNodePtr) ctxt->doc)
snprintf(prompt, sizeof(prompt), "%s > ", "/");
+ else if ((ctxt->node != NULL) && (ctxt->node->name) &&
+ (ctxt->node->ns) && (ctxt->node->ns->prefix))
+ snprintf(prompt, sizeof(prompt), "%s:%s > ",
+ (ctxt->node->ns->prefix), ctxt->node->name);
else if ((ctxt->node != NULL) && (ctxt->node->name))
snprintf(prompt, sizeof(prompt), "%s > ", ctxt->node->name);
else
@@ -2911,6 +2920,7 @@ xmlShell(xmlDocPtr doc, char *filename, xmlShellReadlineFunc input,
fprintf(ctxt->output, "\t the default namespace if any uses 'defaultns' prefix\n");
#endif /* LIBXML_XPATH_ENABLED */
fprintf(ctxt->output, "\tpwd display current working directory\n");
+ fprintf(ctxt->output, "\twhereis display absolute path of [path] or current working directory\n");
fprintf(ctxt->output, "\tquit leave shell\n");
#ifdef LIBXML_OUTPUT_ENABLED
fprintf(ctxt->output, "\tsave [name] save this document to name or the original name\n");
@@ -2960,7 +2970,79 @@ xmlShell(xmlDocPtr doc, char *filename, xmlShellReadlineFunc input,
if (!xmlShellPwd(ctxt, dir, ctxt->node, NULL))
fprintf(ctxt->output, "%s\n", dir);
} else if (!strcmp(command, "du")) {
- xmlShellDu(ctxt, NULL, ctxt->node, NULL);
+ if (arg[0] == 0) {
+ xmlShellDu(ctxt, NULL, ctxt->node, NULL);
+ } else {
+ ctxt->pctxt->node = ctxt->node;
+#ifdef LIBXML_XPATH_ENABLED
+ ctxt->pctxt->node = ctxt->node;
+ list = xmlXPathEval((xmlChar *) arg, ctxt->pctxt);
+#else
+ list = NULL;
+#endif /* LIBXML_XPATH_ENABLED */
+ if (list != NULL) {
+ switch (list->type) {
+ case XPATH_UNDEFINED:
+ xmlGenericError(xmlGenericErrorContext,
+ "%s: no such node\n", arg);
+ break;
+ case XPATH_NODESET:{
+ int indx;
+
+ if (list->nodesetval == NULL)
+ break;
+
+ for (indx = 0;
+ indx < list->nodesetval->nodeNr;
+ indx++)
+ xmlShellDu(ctxt, NULL,
+ list->nodesetval->
+ nodeTab[indx], NULL);
+ break;
+ }
+ case XPATH_BOOLEAN:
+ xmlGenericError(xmlGenericErrorContext,
+ "%s is a Boolean\n", arg);
+ break;
+ case XPATH_NUMBER:
+ xmlGenericError(xmlGenericErrorContext,
+ "%s is a number\n", arg);
+ break;
+ case XPATH_STRING:
+ xmlGenericError(xmlGenericErrorContext,
+ "%s is a string\n", arg);
+ break;
+ case XPATH_POINT:
+ xmlGenericError(xmlGenericErrorContext,
+ "%s is a point\n", arg);
+ break;
+ case XPATH_RANGE:
+ xmlGenericError(xmlGenericErrorContext,
+ "%s is a range\n", arg);
+ break;
+ case XPATH_LOCATIONSET:
+ xmlGenericError(xmlGenericErrorContext,
+ "%s is a range\n", arg);
+ break;
+ case XPATH_USERS:
+ xmlGenericError(xmlGenericErrorContext,
+ "%s is user-defined\n", arg);
+ break;
+ case XPATH_XSLT_TREE:
+ xmlGenericError(xmlGenericErrorContext,
+ "%s is an XSLT value tree\n",
+ arg);
+ break;
+ }
+#ifdef LIBXML_XPATH_ENABLED
+ xmlXPathFreeObject(list);
+#endif
+ } else {
+ xmlGenericError(xmlGenericErrorContext,
+ "%s: no such node\n", arg);
+ }
+ ctxt->pctxt->node = NULL;
+ }
} else if (!strcmp(command, "base")) {
xmlShellBase(ctxt, NULL, ctxt->node, NULL);
} else if (!strcmp(command, "set")) {
@@ -3078,6 +3160,83 @@ xmlShell(xmlDocPtr doc, char *filename, xmlShellReadlineFunc input,
}
ctxt->pctxt->node = NULL;
}
+ } else if (!strcmp(command, "whereis")) {
+ char dir[500];
+
+ if (arg[0] == 0) {
+ if (!xmlShellPwd(ctxt, dir, ctxt->node, NULL))
+ fprintf(ctxt->output, "%s\n", dir);
+ } else {
+ ctxt->pctxt->node = ctxt->node;
+#ifdef LIBXML_XPATH_ENABLED
+ list = xmlXPathEval((xmlChar *) arg, ctxt->pctxt);
+#else
+ list = NULL;
+#endif /* LIBXML_XPATH_ENABLED */
+ if (list != NULL) {
+ switch (list->type) {
+ case XPATH_UNDEFINED:
+ xmlGenericError(xmlGenericErrorContext,
+ "%s: no such node\n", arg);
+ break;
+ case XPATH_NODESET:{
+ int indx;
+
+ if (list->nodesetval == NULL)
+ break;
+
+ for (indx = 0;
+ indx < list->nodesetval->nodeNr;
+ indx++) {
+ if (!xmlShellPwd(ctxt, dir, list->nodesetval->
+ nodeTab[indx], NULL))
+ fprintf(ctxt->output, "%s\n", dir);
+ }
+ break;
+ }
+ case XPATH_BOOLEAN:
+ xmlGenericError(xmlGenericErrorContext,
+ "%s is a Boolean\n", arg);
+ break;
+ case XPATH_NUMBER:
+ xmlGenericError(xmlGenericErrorContext,
+ "%s is a number\n", arg);
+ break;
+ case XPATH_STRING:
+ xmlGenericError(xmlGenericErrorContext,
+ "%s is a string\n", arg);
+ break;
+ case XPATH_POINT:
+ xmlGenericError(xmlGenericErrorContext,
+ "%s is a point\n", arg);
+ break;
+ case XPATH_RANGE:
+ xmlGenericError(xmlGenericErrorContext,
+ "%s is a range\n", arg);
+ break;
+ case XPATH_LOCATIONSET:
+ xmlGenericError(xmlGenericErrorContext,
+ "%s is a range\n", arg);
+ break;
+ case XPATH_USERS:
+ xmlGenericError(xmlGenericErrorContext,
+ "%s is user-defined\n", arg);
+ break;
+ case XPATH_XSLT_TREE:
+ xmlGenericError(xmlGenericErrorContext,
+ "%s is an XSLT value tree\n",
+ arg);
+ break;
+ }
+#ifdef LIBXML_XPATH_ENABLED
+ xmlXPathFreeObject(list);
+#endif
+ } else {
+ xmlGenericError(xmlGenericErrorContext,
+ "%s: no such node\n", arg);
+ }
+ ctxt->pctxt->node = NULL;
+ }
} else if (!strcmp(command, "cd")) {
if (arg[0] == 0) {
ctxt->node = (xmlNodePtr) ctxt->doc;