[Date Prev][Date Next] [Thread Prev][Thread Next]
[Thread Index]
[Date Index]
[Author Index]
Re: [xml] patch for adding "shell" scripting
- From: Nic <nferrier tapsellferrier co uk>
- To: veillard redhat com
- Cc: xml gnome org
- Subject: Re: [xml] patch for adding "shell" scripting
- Date: 05 Sep 2003 21:29:24 +0100
Daniel Veillard <veillard redhat com> writes:
> I like the idea, but please rewitre the patch for portability.
Harumph.
> No, it's a portability nightmare...
I'm not very interested in portability /8->
But I've done most of what you ask. See the next bit for some
questions:
> It would be good to make sure all string allocated or copied
> are cleaned up with xmlFree() on exit too.
The script string created by the shellx argument processing is
allocated via malloc. Should I allocate that using xml memory
handlers? I'm a bit confused about what to use... free() is used in
the shell argument processor for example, not xmlFree().
> So good idea, but the code need some cleanup :-)
If I could spell a raspberry being blown I would.
Here's the patch:
diff -u /home/nferrier/projects/libxmlxsl/gnome-xml/xmllint.c /home/nferrier/projects/libxml2-2.5.7/xmllint.c
--- /home/nferrier/projects/libxmlxsl/gnome-xml/xmllint.c Thu Aug 28 13:32:04 2003
+++ /home/nferrier/projects/libxml2-2.5.7/xmllint.c Fri Sep 5 14:42:20 2003
@@ -525,6 +522,44 @@
* *
************************************************************************/
#ifdef LIBXML_DEBUG_ENABLED
+
+static char* (*xmlShellScriptSourcer)(char*);
+
+// Read the xmlShell commands from a script string
+static char *cmdLineScript = NULL;
+
+// libxml2 version of strsep
+// This returns a new copy of the token.
+// You must free the token yourself.
+static xmlChar*
+xmlStrsep(xmlChar** str, xmlChar sep)
+{
+ const xmlChar* nextPtr = xmlStrchr(*str, sep);
+ xmlChar* token = xmlStrndup(*str, nextPtr - *str);
+ *str = nextPtr + 1;
+ return (char*) token;
+}
+
+
+/**
+ * xmlShellScriptReader
+ * @prompt: not used.
+ *
+ * Read the next command token from the script passed on the cmd line.
+ *
+ * Returns a pointer to it or NULL on EOF; the caller is expected to
+ * free the returned string.
+ */
+static char*
+xmlShellScriptReader (char* prompt)
+{
+ xmlChar* scriptLine = xmlStrsep (&cmdLineScript, ';');
+ if (scriptLine != NULL)
+ if (xmlStrlen(scriptLine) < 1)
+ return NULL;
+ return (scriptLine);
+}
+
/**
* xmlShellReadline:
* @prompt: the prompt value
@@ -965,7 +975,7 @@
* shell interaction
*/
if (shell)
- xmlShell(doc, filename, xmlShellReadline, stdout);
+ xmlShell(doc, filename, xmlShellScriptSourcer, stdout);
#endif
/*
@@ -1297,6 +1255,7 @@
#ifdef LIBXML_DEBUG_ENABLED
printf("\t--debug : dump a debug tree of the in-memory document\n");
printf("\t--shell : run a navigating shell\n");
+ printf("\t--shellx script : run a navigating shell\n");
printf("\t--debugent : debug the entities defined in the document\n");
#else
printf("\t--debug : dump the nodes content when using --stream\n");
@@ -1392,11 +1348,26 @@
debug++;
else
#ifdef LIBXML_DEBUG_ENABLED
- if ((!strcmp(argv[i], "-shell")) ||
- (!strcmp(argv[i], "--shell"))) {
- shell++;
+ if ((!strcmp(argv[i], "-shell")) ||
+ (!strcmp(argv[i], "--shell"))) {
+ shell++;
+ noout = 1;
+ xmlShellScriptSourcer = xmlShellReadline;
+ }
+ else if ((!strncmp(argv[i], "-shellx", 7)) ||
+ (!strncmp(argv[i], "--shellx", 8))) {
+ shell++;
noout = 1;
- } else
+ if (++i < argc) {
+ cmdLineScript = (char*) malloc(strlen(argv[i]) + 2);
+ strncpy(cmdLineScript, argv[i], strlen(argv[i]));
+ // Put the terminator char at the end.
+ cmdLineScript[strlen(argv[i])] = ';';
+ cmdLineScript[strlen(argv[i]) + 1] = 0;
+ xmlShellScriptSourcer = xmlShellScriptReader;
+ }
+ }
+ else
#endif
if ((!strcmp(argv[i], "-copy")) || (!strcmp(argv[i], "--copy")))
copy++;
@@ -1673,19 +1610,22 @@
(!strcmp(argv[i], "--encode"))) {
i++;
continue;
- } else if ((!strcmp(argv[i], "-o")) ||
+ }
+ else if ((!strcmp(argv[i], "-o")) ||
(!strcmp(argv[i], "-output")) ||
(!strcmp(argv[i], "--output"))) {
i++;
continue;
}
- if ((!strcmp(argv[i], "-dtdvalid")) ||
- (!strcmp(argv[i], "--dtdvalid"))) {
+
+ if ((!strcmp(argv[i], "-shellx")) ||
+ (!strcmp(argv[i], "--shellx"))) {
i++;
continue;
}
- if ((!strcmp(argv[i], "-dtdvalidfpi")) ||
- (!strcmp(argv[i], "--dtdvalidfpi"))) {
+
+ if ((!strcmp(argv[i], "-dtdvalid")) ||
+ (!strcmp(argv[i], "--dtdvalid"))) {
i++;
continue;
}
[Date Prev][Date Next] [Thread Prev][Thread Next]
[Thread Index]
[Date Index]
[Author Index]