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