Return to testURI.c CVS log | Up to [Public] / XML |
1.1 daniel 1: /*
2: * testURI.c : a small tester program for XML input.
3: *
4: * See Copyright for the status of this software.
5: *
6: * Daniel.Veillard@w3.org
7: */
8:
9: #ifdef WIN32
10: #include "win32config.h"
11: #else
12: #include "config.h"
13: #endif
14:
15: #include <stdio.h>
16: #include <string.h>
17: #include <stdio.h>
18: #include <stdarg.h>
19:
1.2 daniel 20: #include <libxml/xmlversion.h>
1.3 daniel 21: #include <libxml/xmlmemory.h>
1.1 daniel 22: #include <libxml/uri.h>
23:
24: int main(int argc, char **argv) {
25: int i, ret, arg = 1;
26: xmlURIPtr uri;
27: const char *base = NULL;
28: xmlChar *composite;
29:
1.4 veillard 30: if (argv[arg] == NULL) {
1.7 ! veillard 31: printf("Usage: %s [-base URI] URI ...\n", argv[0]);
1.4 veillard 32: exit(0);
33: }
1.1 daniel 34: if ((!strcmp(argv[arg], "-base")) || (!strcmp(argv[arg], "--base"))) {
35: arg++;
36: base = argv[arg];
37: if (base != NULL)
38: arg++;
39: }
40: uri = xmlCreateURI();
41: if (argv[arg] == NULL) {
42: char str[1024];
43:
44: while (1) {
45: /*
46: * read one line in string buffer.
47: */
48: if (fgets (&str[0], sizeof (str) - 1, stdin) == NULL)
49: break;
50:
51: /*
52: * remove the ending spaces
53: */
54: i = strlen(str);
55: while ((i > 0) &&
56: ((str[i - 1] == '\n') || (str[i - 1] == '\r') ||
57: (str[i - 1] == ' ') || (str[i - 1] == '\t'))) {
58: i--;
59: str[i] = 0;
60: }
61:
1.5 veillard 62: if (base == NULL) {
63: ret = xmlParseURIReference(uri, str);
64: if (ret != 0)
65: printf("%s : error %d\n", str, ret);
66: else {
67: xmlPrintURI(stdout, uri);
68: printf("\n");
69: }
70: } else {
71: composite = xmlBuildURI((xmlChar *)str, (xmlChar *) base);
72: if (composite != NULL) {
73: printf("%s\n", composite);
74: xmlFree(composite);
75: }
76: else
77: printf("::ERROR::\n");
1.1 daniel 78: }
79: }
80: } else {
81: while (argv[arg] != NULL) {
82: if (base == NULL) {
83: ret = xmlParseURIReference(uri, argv[arg]);
84: if (ret != 0)
85: printf("%s : error %d\n", argv[arg], ret);
86: else {
87: xmlPrintURI(stdout, uri);
88: printf("\n");
89: }
90: } else {
91: composite = xmlBuildURI((xmlChar *)argv[arg], (xmlChar *) base);
1.4 veillard 92: if (composite != NULL) {
1.1 daniel 93: printf("%s\n", composite);
94: xmlFree(composite);
95: }
96: }
97: arg++;
98: }
99: }
100: xmlFreeURI(uri);
101: xmlMemoryDump();
102: exit(0);
103: }