blob: 5ec8157c1b5841a0483398ef09fbd587ddae536a [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 Veillardb6e7fdb2001-02-02 17:07:32 +000030 if ((argv[arg] != NULL) &&
31 ((!strcmp(argv[arg], "-base")) || (!strcmp(argv[arg], "--base")))) {
Daniel Veillarde77a9182000-04-05 19:12:29 +000032 arg++;
33 base = argv[arg];
34 if (base != NULL)
35 arg++;
36 }
37 uri = xmlCreateURI();
38 if (argv[arg] == NULL) {
39 char str[1024];
40
41 while (1) {
42 /*
43 * read one line in string buffer.
44 */
45 if (fgets (&str[0], sizeof (str) - 1, stdin) == NULL)
46 break;
47
48 /*
49 * remove the ending spaces
50 */
51 i = strlen(str);
52 while ((i > 0) &&
53 ((str[i - 1] == '\n') || (str[i - 1] == '\r') ||
54 (str[i - 1] == ' ') || (str[i - 1] == '\t'))) {
55 i--;
56 str[i] = 0;
57 }
Daniel Veillarde77a9182000-04-05 19:12:29 +000058
Daniel Veillard98a79162000-09-04 11:15:39 +000059 if (base == NULL) {
60 ret = xmlParseURIReference(uri, str);
61 if (ret != 0)
62 printf("%s : error %d\n", str, ret);
63 else {
Daniel Veillardb6e7fdb2001-02-02 17:07:32 +000064 xmlNormalizeURIPath(uri->path);
Daniel Veillard98a79162000-09-04 11:15:39 +000065 xmlPrintURI(stdout, uri);
66 printf("\n");
67 }
68 } else {
69 composite = xmlBuildURI((xmlChar *)str, (xmlChar *) base);
70 if (composite != NULL) {
71 printf("%s\n", composite);
72 xmlFree(composite);
73 }
74 else
75 printf("::ERROR::\n");
Daniel Veillarde77a9182000-04-05 19:12:29 +000076 }
Daniel Veillarde77a9182000-04-05 19:12:29 +000077 }
78 } else {
79 while (argv[arg] != NULL) {
80 if (base == NULL) {
81 ret = xmlParseURIReference(uri, argv[arg]);
82 if (ret != 0)
83 printf("%s : error %d\n", argv[arg], ret);
84 else {
85 xmlPrintURI(stdout, uri);
86 printf("\n");
87 }
88 } else {
89 composite = xmlBuildURI((xmlChar *)argv[arg], (xmlChar *) base);
Daniel Veillard52402ce2000-08-22 23:36:12 +000090 if (composite != NULL) {
Daniel Veillarde77a9182000-04-05 19:12:29 +000091 printf("%s\n", composite);
92 xmlFree(composite);
93 }
94 }
95 arg++;
96 }
97 }
98 xmlFreeURI(uri);
99 xmlMemoryDump();
Daniel Veillardb6e7fdb2001-02-02 17:07:32 +0000100 return(0);
Daniel Veillarde77a9182000-04-05 19:12:29 +0000101}