blob: 50b508e2e7caddd854cf8129e7d56ec4fbf9d33b [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 }
61 if (i <= 0)
62 continue;
63
64 ret = xmlParseURIReference(uri, str);
65 if (ret != 0)
66 printf("%s : error %d\n", str, ret);
67 else {
68 xmlPrintURI(stdout, uri);
69 printf("\n");
70 }
71
72 }
73 } else {
74 while (argv[arg] != NULL) {
75 if (base == NULL) {
76 ret = xmlParseURIReference(uri, argv[arg]);
77 if (ret != 0)
78 printf("%s : error %d\n", argv[arg], ret);
79 else {
80 xmlPrintURI(stdout, uri);
81 printf("\n");
82 }
83 } else {
84 composite = xmlBuildURI((xmlChar *)argv[arg], (xmlChar *) base);
Daniel Veillard52402ce2000-08-22 23:36:12 +000085 if (composite != NULL) {
Daniel Veillarde77a9182000-04-05 19:12:29 +000086 printf("%s\n", composite);
87 xmlFree(composite);
88 }
89 }
90 arg++;
91 }
92 }
93 xmlFreeURI(uri);
94 xmlMemoryDump();
95 exit(0);
96}