summaryrefslogtreecommitdiff
path: root/debugXML.c
diff options
context:
space:
mode:
authorRyan <s.covich@gmail.com>2012-05-07 19:53:19 +0800
committerDaniel Veillard <veillard@redhat.com>2012-05-07 19:53:19 +0800
commit0cd29a3a256ef122920263cf0ef793eafb5f3faa (patch)
treeba2af8ff305ac3ed5034f38eb0fe456db3c7c013 /debugXML.c
parent996449273fd4a8fc656d42088779e236d456e47a (diff)
downloadlibxml2-0cd29a3a256ef122920263cf0ef793eafb5f3faa.tar.gz
Add "whereis" command to xmllint shell
When playing with xpath in the xmllint shell, it's really handy to be able to ask where the returned nodes live in the tree, in the same way "pwd" asks where the current node lives. The feature is actually quite easy to implement by combining the functionality of the existing dir/ls and pwd commands (see proposed patch). Example usage: / > whereis //last_name /clinical_study/overall_official/last_name /clinical_study/location/contact/last_name /clinical_study/location/investigator/last_name
Diffstat (limited to 'debugXML.c')
-rw-r--r--debugXML.c78
1 files changed, 78 insertions, 0 deletions
diff --git a/debugXML.c b/debugXML.c
index 30ca6c2a..3e9ec7af 100644
--- a/debugXML.c
+++ b/debugXML.c
@@ -2920,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");
@@ -3159,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;