summaryrefslogtreecommitdiff
path: root/testURI.c
diff options
context:
space:
mode:
authorDaniel Veillard <veillard@src.gnome.org>2001-12-07 11:33:54 +0000
committerDaniel Veillard <veillard@src.gnome.org>2001-12-07 11:33:54 +0000
commit220346d16b87abda52fc6771a6e50b700a1813f8 (patch)
tree984330663cf3ce278eba473ea32377fba2f5157f /testURI.c
parent2a9068212f118cd0b1e40283a5bb0cdb514f3fc4 (diff)
downloadlibxml2-220346d16b87abda52fc6771a6e50b700a1813f8.tar.gz
closed bug #66159 added --escape option some cleanup for xml2-config
* uri.c: closed bug #66159 * testURI.c: added --escape option * configure.in: some cleanup for xml2-config --cflags Daniel
Diffstat (limited to 'testURI.c')
-rw-r--r--testURI.c91
1 files changed, 50 insertions, 41 deletions
diff --git a/testURI.c b/testURI.c
index 2233dc7f..60abae02 100644
--- a/testURI.c
+++ b/testURI.c
@@ -16,20 +16,62 @@
#include <libxml/uri.h>
#include <libxml/globals.h>
-int main(int argc, char **argv) {
- int i, ret, arg = 1;
+static const char *base = NULL;
+static int escape = 0;
+
+static void handleURI(const char *str) {
+ int ret;
xmlURIPtr uri;
- const char *base = NULL;
- xmlChar *composite;
+ xmlChar *res = NULL, *parsed = NULL;
+
+ uri = xmlCreateURI();
- if ((argc > 1) && (argv[arg] != NULL) &&
+ if (base == NULL) {
+ ret = xmlParseURIReference(uri, str);
+ if (ret != 0)
+ printf("%s : error %d\n", str, ret);
+ else {
+ xmlNormalizeURIPath(uri->path);
+ if (escape != 0) {
+ parsed = xmlSaveUri(uri);
+ res = xmlURIEscape(parsed);
+ printf("%s\n", res);
+
+ } else {
+ xmlPrintURI(stdout, uri);
+ printf("\n");
+ }
+ }
+ } else {
+ res = xmlBuildURI((xmlChar *)str, (xmlChar *) base);
+ if (res != NULL) {
+ printf("%s\n", res);
+ }
+ else
+ printf("::ERROR::\n");
+ }
+ if (res != NULL)
+ xmlFree(res);
+ if (parsed != NULL)
+ xmlFree(parsed);
+ xmlFreeURI(uri);
+}
+
+int main(int argc, char **argv) {
+ int i, arg = 1;
+
+ if ((argc > arg) && (argv[arg] != NULL) &&
((!strcmp(argv[arg], "-base")) || (!strcmp(argv[arg], "--base")))) {
arg++;
base = argv[arg];
if (base != NULL)
arg++;
}
- uri = xmlCreateURI();
+ if ((argc > arg) && (argv[arg] != NULL) &&
+ ((!strcmp(argv[arg], "-escape")) || (!strcmp(argv[arg], "--escape")))) {
+ arg++;
+ escape++;
+ }
if (argv[arg] == NULL) {
char str[1024];
@@ -50,47 +92,14 @@ int main(int argc, char **argv) {
i--;
str[i] = 0;
}
-
- if (base == NULL) {
- ret = xmlParseURIReference(uri, str);
- if (ret != 0)
- printf("%s : error %d\n", str, ret);
- else {
- xmlNormalizeURIPath(uri->path);
- xmlPrintURI(stdout, uri);
- printf("\n");
- }
- } else {
- composite = xmlBuildURI((xmlChar *)str, (xmlChar *) base);
- if (composite != NULL) {
- printf("%s\n", composite);
- xmlFree(composite);
- }
- else
- printf("::ERROR::\n");
- }
+ handleURI(str);
}
} else {
while (argv[arg] != NULL) {
- if (base == NULL) {
- ret = xmlParseURIReference(uri, argv[arg]);
- if (ret != 0)
- printf("%s : error %d\n", argv[arg], ret);
- else {
- xmlPrintURI(stdout, uri);
- printf("\n");
- }
- } else {
- composite = xmlBuildURI((xmlChar *)argv[arg], (xmlChar *) base);
- if (composite != NULL) {
- printf("%s\n", composite);
- xmlFree(composite);
- }
- }
+ handleURI(argv[arg]);
arg++;
}
}
- xmlFreeURI(uri);
xmlMemoryDump();
return(0);
}