MCPcopy Create free account
hub / github.com/Kitware/VTK / xmlShell

Function xmlShell

ThirdParty/libxml2/vtklibxml2/debugXML.c:2794–3412  ·  view source on GitHub ↗

* xmlShell: * @doc: the initial document * @filename: the output buffer * @input: the line reading function * @output: the output FILE*, defaults to stdout if NULL * * Implements the XML shell * This allow to load, validate, view, modify and save a document * using a environment similar to a UNIX commandline. */

Source from the content-addressed store, hash-verified

2792 * using a environment similar to a UNIX commandline.
2793 */
2794void
2795xmlShell(xmlDocPtr doc, const char *filename, xmlShellReadlineFunc input,
2796 FILE * output)
2797{
2798 char prompt[500] = "/ > ";
2799 char *cmdline = NULL, *cur;
2800 char command[100];
2801 char arg[400];
2802 int i;
2803 xmlShellCtxtPtr ctxt;
2804 xmlXPathObjectPtr list;
2805
2806 if (doc == NULL)
2807 return;
2808 if (filename == NULL)
2809 return;
2810 if (input == NULL)
2811 return;
2812 if (output == NULL)
2813 output = stdout;
2814 ctxt = (xmlShellCtxtPtr) xmlMalloc(sizeof(xmlShellCtxt));
2815 if (ctxt == NULL)
2816 return;
2817 ctxt->loaded = 0;
2818 ctxt->doc = doc;
2819 ctxt->input = input;
2820 ctxt->output = output;
2821 ctxt->filename = (char *) xmlStrdup((xmlChar *) filename);
2822 ctxt->node = (xmlNodePtr) ctxt->doc;
2823
2824#ifdef LIBXML_XPATH_ENABLED
2825 ctxt->pctxt = xmlXPathNewContext(ctxt->doc);
2826 if (ctxt->pctxt == NULL) {
2827 xmlFree(ctxt);
2828 return;
2829 }
2830#endif /* LIBXML_XPATH_ENABLED */
2831 while (1) {
2832 if (ctxt->node == (xmlNodePtr) ctxt->doc)
2833 snprintf(prompt, sizeof(prompt), "%s > ", "/");
2834 else if ((ctxt->node != NULL) && (ctxt->node->name) &&
2835 (ctxt->node->ns) && (ctxt->node->ns->prefix))
2836 snprintf(prompt, sizeof(prompt), "%s:%s > ",
2837 (ctxt->node->ns->prefix), ctxt->node->name);
2838 else if ((ctxt->node != NULL) && (ctxt->node->name))
2839 snprintf(prompt, sizeof(prompt), "%s > ", ctxt->node->name);
2840 else
2841 snprintf(prompt, sizeof(prompt), "? > ");
2842 prompt[sizeof(prompt) - 1] = 0;
2843
2844 /*
2845 * Get a new command line
2846 */
2847 cmdline = ctxt->input(prompt);
2848 if (cmdline == NULL)
2849 break;
2850
2851 /*

Callers 1

parseAndPrintFileFunction · 0.85

Calls 15

xmlStrdupFunction · 0.85
xmlXPathNewContextFunction · 0.85
fprintfFunction · 0.85
xmlShellValidateFunction · 0.85
xmlShellLoadFunction · 0.85
xmlShellRNGValidateFunction · 0.85
xmlShellSaveFunction · 0.85
xmlShellWriteFunction · 0.85
xmlShellGrepFunction · 0.85
xmlShellPwdFunction · 0.85
xmlShellDuFunction · 0.85
xmlXPathEvalFunction · 0.85

Tested by

no test coverage detected