blob: 2233dc7fd2a8dddd0cac5f12524e7167454291be [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 *
Daniel Veillardc5d64342001-06-24 12:13:24 +00006 * daniel@veillard.com
Daniel Veillarde77a9182000-04-05 19:12:29 +00007 */
8
Bjorn Reese70a9da52001-04-21 16:57:29 +00009#include "libxml.h"
Daniel Veillarde77a9182000-04-05 19:12:29 +000010
Daniel Veillarde77a9182000-04-05 19:12:29 +000011#include <string.h>
12#include <stdio.h>
13#include <stdarg.h>
14
Daniel Veillardbe803962000-06-28 23:40:59 +000015#include <libxml/xmlmemory.h>
Daniel Veillarde77a9182000-04-05 19:12:29 +000016#include <libxml/uri.h>
Daniel Veillard3c01b1d2001-10-17 15:58:35 +000017#include <libxml/globals.h>
Daniel Veillarde77a9182000-04-05 19:12:29 +000018
19int main(int argc, char **argv) {
20 int i, ret, arg = 1;
21 xmlURIPtr uri;
22 const char *base = NULL;
23 xmlChar *composite;
24
Daniel Veillard56a4cb82001-03-24 17:00:36 +000025 if ((argc > 1) && (argv[arg] != NULL) &&
Daniel Veillardb6e7fdb2001-02-02 17:07:32 +000026 ((!strcmp(argv[arg], "-base")) || (!strcmp(argv[arg], "--base")))) {
Daniel Veillarde77a9182000-04-05 19:12:29 +000027 arg++;
28 base = argv[arg];
29 if (base != NULL)
30 arg++;
31 }
32 uri = xmlCreateURI();
33 if (argv[arg] == NULL) {
34 char str[1024];
35
36 while (1) {
37 /*
38 * read one line in string buffer.
39 */
40 if (fgets (&str[0], sizeof (str) - 1, stdin) == NULL)
41 break;
42
43 /*
44 * remove the ending spaces
45 */
46 i = strlen(str);
47 while ((i > 0) &&
48 ((str[i - 1] == '\n') || (str[i - 1] == '\r') ||
49 (str[i - 1] == ' ') || (str[i - 1] == '\t'))) {
50 i--;
51 str[i] = 0;
52 }
Daniel Veillarde77a9182000-04-05 19:12:29 +000053
Daniel Veillard98a79162000-09-04 11:15:39 +000054 if (base == NULL) {
55 ret = xmlParseURIReference(uri, str);
56 if (ret != 0)
57 printf("%s : error %d\n", str, ret);
58 else {
Daniel Veillardb6e7fdb2001-02-02 17:07:32 +000059 xmlNormalizeURIPath(uri->path);
Daniel Veillard98a79162000-09-04 11:15:39 +000060 xmlPrintURI(stdout, uri);
61 printf("\n");
62 }
63 } else {
64 composite = xmlBuildURI((xmlChar *)str, (xmlChar *) base);
65 if (composite != NULL) {
66 printf("%s\n", composite);
67 xmlFree(composite);
68 }
69 else
70 printf("::ERROR::\n");
Daniel Veillarde77a9182000-04-05 19:12:29 +000071 }
Daniel Veillarde77a9182000-04-05 19:12:29 +000072 }
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();
Daniel Veillardb6e7fdb2001-02-02 17:07:32 +000095 return(0);
Daniel Veillarde77a9182000-04-05 19:12:29 +000096}