diff options
author | David Larsson <david.larsson@selfhosted.xyz> | 2021-05-15 20:52:50 +0200 |
---|---|---|
committer | Marius Bakke <marius@gnu.org> | 2021-05-18 22:23:49 +0200 |
commit | b58efbc6611550ad9234163e198ff71ace5306ea (patch) | |
tree | a3d94d94d4c139d9a5d9b70320608e9700260fb7 /gnu/packages | |
parent | 6f20fa3b8b558e5e8452eb48a4e992c4b0958c35 (diff) | |
download | guix-b58efbc6611550ad9234163e198ff71ace5306ea.tar.gz |
gnu: Add libxml2-xpath0.
* gnu/packages/patches/libxml2-xpath0-Add-option-xpath0.patch: New file... * gnu/local.mk (dist_patch_DATA): Register it. * gnu/packages/xml.scm (libxml2-xpath0): New variable. Signed-off-by: Marius Bakke <marius@gnu.org>
Diffstat (limited to 'gnu/packages')
-rw-r--r-- | gnu/packages/patches/libxml2-xpath0-Add-option-xpath0.patch | 129 | ||||
-rw-r--r-- | gnu/packages/xml.scm | 14 |
2 files changed, 143 insertions, 0 deletions
diff --git a/gnu/packages/patches/libxml2-xpath0-Add-option-xpath0.patch b/gnu/packages/patches/libxml2-xpath0-Add-option-xpath0.patch new file mode 100644 index 0000000000..e83642eb37 --- /dev/null +++ b/gnu/packages/patches/libxml2-xpath0-Add-option-xpath0.patch @@ -0,0 +1,129 @@ +This patch adds an "--xpath0" option to xmllint so that NUL characters +can be used as separators. + +See <https://gitlab.gnome.org/GNOME/libxml2/-/issues/227>. + +diff --git a/doc/xmllint.xml b/doc/xmllint.xml +--- a/doc/xmllint.xml ++++ b/doc/xmllint.xml +@@ -70,6 +70,7 @@ + <arg choice="plain"><option>--debug</option></arg> + <arg choice="plain"><option>--shell</option></arg> + <arg choice="plain"><option>--xpath "<replaceable class="option">XPath_expression</replaceable>"</option></arg> ++ <arg choice="plain"><option>--xpath0 "<replaceable class="option">XPath_expression</replaceable>"</option></arg> + <arg choice="plain"><option>--debugent</option></arg> + <arg choice="plain"><option>--copy</option></arg> + <arg choice="plain"><option>--recover</option></arg> +@@ -537,6 +538,21 @@ + node set is serialized in full in the output. In case + of an empty node set the "XPath set is empty" result + will be shown and an error exit code will be returned. ++ Results are separated by the newline character. ++ </para> ++ </listitem> ++ </varlistentry> ++ ++ <varlistentry> ++ <term><option>--xpath0 "<replaceable class="option">XPath_expression</replaceable>"</option></term> ++ <listitem> ++ <para> ++ Run an XPath expression given as argument and print the ++ result. In case of a nodeset result, each node in the ++ node set is serialized in full in the output. In case ++ of an empty node set the "XPath set is empty" result ++ will be shown and an error exit code will be returned. ++ Results are separated by the null character. + </para> + </listitem> + </varlistentry> +diff --git a/xmllint.c b/xmllint.c +--- a/xmllint.c ++++ b/xmllint.c +@@ -194,6 +194,7 @@ static int sax1 = 0; + #endif /* LIBXML_SAX1_ENABLED */ + #ifdef LIBXML_XPATH_ENABLED + static const char *xpathquery = NULL; ++static const char *xpathsep = "\n"; + #endif + static int options = XML_PARSE_COMPACT | XML_PARSE_BIG_LINES; + static int sax = 0; +@@ -2095,7 +2096,7 @@ static void doXPathDump(xmlXPathObjectPtr cur) { + for (i = 0;i < cur->nodesetval->nodeNr;i++) { + node = cur->nodesetval->nodeTab[i]; + xmlNodeDumpOutput(buf, NULL, node, 0, 0, NULL); +- xmlOutputBufferWrite(buf, 1, "\n"); ++ xmlOutputBufferWrite(buf, 1, xpathsep); + } + xmlOutputBufferClose(buf); + #else +@@ -2104,27 +2105,27 @@ static void doXPathDump(xmlXPathObjectPtr cur) { + break; + } + case XPATH_BOOLEAN: +- if (cur->boolval) printf("true\n"); +- else printf("false\n"); ++ if (cur->boolval) printf("true%s", xpathsep); ++ else printf("false%s", xpathsep); + break; + case XPATH_NUMBER: + switch (xmlXPathIsInf(cur->floatval)) { + case 1: +- printf("Infinity\n"); ++ printf("Infinity%s", xpathsep); + break; + case -1: +- printf("-Infinity\n"); ++ printf("-Infinity%s", xpathsep); + break; + default: + if (xmlXPathIsNaN(cur->floatval)) { +- printf("NaN\n"); ++ printf("NaN%s", xpathsep); + } else { +- printf("%0g\n", cur->floatval); ++ printf("%0g%s", cur->floatval, xpathsep); + } + } + break; + case XPATH_STRING: +- printf("%s\n", (const char *) cur->stringval); ++ printf("%s%s", (const char *) cur->stringval, xpathsep); + break; + case XPATH_UNDEFINED: + fprintf(stderr, "XPath Object is uninitialized\n"); +@@ -3098,7 +3099,8 @@ static void usage(FILE *f, const char *name) { + fprintf(f, "\t--sax: do not build a tree but work just at the SAX level\n"); + fprintf(f, "\t--oldxml10: use XML-1.0 parsing rules before the 5th edition\n"); + #ifdef LIBXML_XPATH_ENABLED +- fprintf(f, "\t--xpath expr: evaluate the XPath expression, imply --noout\n"); ++ fprintf(f, "\t--xpath expr: evaluate the XPath expression, results are separated by \\n, imply --noout\n"); ++ fprintf(f, "\t--xpath0 expr: evaluate the XPath expression, results are separated by \\0, imply --noout\n"); + #endif + + fprintf(f, "\nLibxml project home page: http://xmlsoft.org/\n"); +@@ -3480,6 +3482,13 @@ main(int argc, char **argv) { + i++; + noout++; + xpathquery = argv[i]; ++ xpathsep = "\n"; ++ } else if ((!strcmp(argv[i], "-xpath0")) || ++ (!strcmp(argv[i], "--xpath0"))) { ++ i++; ++ noout++; ++ xpathquery = argv[i]; ++ xpathsep = "\0"; + #endif + } else if ((!strcmp(argv[i], "-oldxml10")) || + (!strcmp(argv[i], "--oldxml10"))) { +@@ -3712,6 +3721,11 @@ main(int argc, char **argv) { + i++; + continue; + } ++ if ((!strcmp(argv[i], "-xpath0")) || ++ (!strcmp(argv[i], "--xpath0"))) { ++ i++; ++ continue; ++ } + #endif + if ((timing) && (repeat)) + startTimer(); diff --git a/gnu/packages/xml.scm b/gnu/packages/xml.scm index fd3ea8c0ae..ad2e3ec6c9 100644 --- a/gnu/packages/xml.scm +++ b/gnu/packages/xml.scm @@ -31,6 +31,7 @@ ;;; Copyright © 2021 Julien Lepiller <julien@lepiller.eu> ;;; Copyright © 2021 Felix Gruber <felgru@posteo.net> ;;; Copyright © 2021 Guillaume Le Vaillant <glv@posteo.net> +;;; Copyright © 2021 David Larsson <david.larsson@selfhosted.xyz> ;;; ;;; This file is part of GNU Guix. ;;; @@ -218,6 +219,19 @@ hierarchical form with variable field lengths.") project (but it is usable outside of the Gnome platform).") (license license:x11))) +(define-public libxml2-xpath0 + (package/inherit libxml2 + (name "libxml2-xpath0") + (source (origin + (inherit (package-source libxml2)) + (patches (append (search-patches + "libxml2-xpath0-Add-option-xpath0.patch") + (origin-patches (package-source libxml2)))))) + (description + "Libxml2-xpath0 is like libxml2 but with a patch applied that +provides an @code{--xpath0} option to @command{xmllint} that enables it +to output XPath results with a null delimiter."))) + (define-public libxlsxwriter (package (name "libxlsxwriter") |