blob: 6712119cb130aab9ae096a612cf559c428e9d00a [file] [log] [blame]
Daniel Veillarde77a9182000-04-05 19:12:29 +00001/*
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
20#include <libxml/uri.h>
21
22int main(int argc, char **argv) {
23 int i, ret, arg = 1;
24 xmlURIPtr uri;
25 const char *base = NULL;
26 xmlChar *composite;
27
28 if ((!strcmp(argv[arg], "-base")) || (!strcmp(argv[arg], "--base"))) {
29 arg++;
30 base = argv[arg];
31 if (base != NULL)
32 arg++;
33 }
34 uri = xmlCreateURI();
35 if (argv[arg] == NULL) {
36 char str[1024];
37
38 while (1) {
39 /*
40 * read one line in string buffer.
41 */
42 if (fgets (&str[0], sizeof (str) - 1, stdin) == NULL)
43 break;
44
45 /*
46 * remove the ending spaces
47 */
48 i = strlen(str);
49 while ((i > 0) &&
50 ((str[i - 1] == '\n') || (str[i - 1] == '\r') ||
51 (str[i - 1] == ' ') || (str[i - 1] == '\t'))) {
52 i--;
53 str[i] = 0;
54 }
55 if (i <= 0)
56 continue;
57
58 ret = xmlParseURIReference(uri, str);
59 if (ret != 0)
60 printf("%s : error %d\n", str, ret);
61 else {
62 xmlPrintURI(stdout, uri);
63 printf("\n");
64 }
65
66 }
67 } else {
68 while (argv[arg] != NULL) {
69 if (base == NULL) {
70 ret = xmlParseURIReference(uri, argv[arg]);
71 if (ret != 0)
72 printf("%s : error %d\n", argv[arg], ret);
73 else {
74 xmlPrintURI(stdout, uri);
75 printf("\n");
76 }
77 } else {
78 composite = xmlBuildURI((xmlChar *)argv[arg], (xmlChar *) base);
79 if (base == NULL) {
80 } else {
81 printf("%s\n", composite);
82 xmlFree(composite);
83 }
84 }
85 arg++;
86 }
87 }
88 xmlFreeURI(uri);
89 xmlMemoryDump();
90 exit(0);
91}