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