blob: 349ca0282a401c42f2858cebcc5dc1e837cfa7c3 [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
Daniel Veillard52402ce2000-08-22 23:36:12 +000030 if (argv[arg] == NULL) {
31 printf("Usage: %s [-base URI] URI ...\n", argv[0]);
32 exit(0);
33 }
Daniel Veillarde77a9182000-04-05 19:12:29 +000034 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 }
Daniel Veillarde77a9182000-04-05 19:12:29 +000061
Daniel Veillard98a79162000-09-04 11:15:39 +000062 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");
Daniel Veillarde77a9182000-04-05 19:12:29 +000078 }
Daniel Veillarde77a9182000-04-05 19:12:29 +000079 }
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);
Daniel Veillard52402ce2000-08-22 23:36:12 +000092 if (composite != NULL) {
Daniel Veillarde77a9182000-04-05 19:12:29 +000093 printf("%s\n", composite);
94 xmlFree(composite);
95 }
96 }
97 arg++;
98 }
99 }
100 xmlFreeURI(uri);
101 xmlMemoryDump();
102 exit(0);
103}