2 * testURI.c : a small tester program for XML input.
4 * See Copyright for the status of this software.
15 #include <libxml/xmlmemory.h>
16 #include <libxml/uri.h>
17 #include <libxml/globals.h>
19 static const char *base = NULL;
20 static int escape = 0;
23 static void handleURI(const char *str) {
26 xmlChar *res = NULL, *parsed = NULL;
31 ret = xmlParseURIReference(uri, str);
33 printf("%s : error %d\n", str, ret);
36 if (uri->scheme) printf("scheme: %s\n", uri->scheme);
37 if (uri->opaque) printf("opaque: %s\n", uri->opaque);
38 if (uri->authority) printf("authority: %s\n", uri->authority);
39 if (uri->server) printf("server: %s\n", uri->server);
40 if (uri->user) printf("user: %s\n", uri->user);
41 if (uri->port != 0) printf("port: %d\n", uri->port);
42 if (uri->path) printf("path: %s\n", uri->path);
43 if (uri->query) printf("query: %s\n", uri->query);
44 if (uri->fragment) printf("fragment: %s\n", uri->fragment);
45 if (uri->query_raw) printf("query_raw: %s\n", uri->query_raw);
46 if (uri->cleanup != 0) printf("cleanup\n");
48 xmlNormalizeURIPath(uri->path);
50 parsed = xmlSaveUri(uri);
51 res = xmlURIEscape(parsed);
52 printf("%s\n", (char *) res);
55 xmlPrintURI(stdout, uri);
60 res = xmlBuildURI((xmlChar *)str, (xmlChar *) base);
62 printf("%s\n", (char *) res);
65 printf("::ERROR::\n");
74 int main(int argc, char **argv) {
77 if ((argc > arg) && (argv[arg] != NULL) &&
78 ((!strcmp(argv[arg], "-base")) || (!strcmp(argv[arg], "--base")))) {
84 if ((argc > arg) && (argv[arg] != NULL) &&
85 ((!strcmp(argv[arg], "-escape")) || (!strcmp(argv[arg], "--escape")))) {
89 if ((argc > arg) && (argv[arg] != NULL) &&
90 ((!strcmp(argv[arg], "-debug")) || (!strcmp(argv[arg], "--debug")))) {
94 if (argv[arg] == NULL) {
99 * read one line in string buffer.
101 if (fgets (&str[0], sizeof (str) - 1, stdin) == NULL)
105 * remove the ending spaces
109 ((str[i - 1] == '\n') || (str[i - 1] == '\r') ||
110 (str[i - 1] == ' ') || (str[i - 1] == '\t'))) {
117 while (argv[arg] != NULL) {
118 handleURI(argv[arg]);