blob: dcbda1f5562dbdc4095e9cfb72a7527ce8a5c724 [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>
17
18int main(int argc, char **argv) {
19 int i, ret, arg = 1;
20 xmlURIPtr uri;
21 const char *base = NULL;
22 xmlChar *composite;
23
Daniel Veillard56a4cb82001-03-24 17:00:36 +000024 if ((argc > 1) && (argv[arg] != NULL) &&
Daniel Veillardb6e7fdb2001-02-02 17:07:32 +000025 ((!strcmp(argv[arg], "-base")) || (!strcmp(argv[arg], "--base")))) {
Daniel Veillarde77a9182000-04-05 19:12:29 +000026 arg++;
27 base = argv[arg];
28 if (base != NULL)
29 arg++;
30 }
31 uri = xmlCreateURI();
32 if (argv[arg] == NULL) {
33 char str[1024];
34
35 while (1) {
36 /*
37 * read one line in string buffer.
38 */
39 if (fgets (&str[0], sizeof (str) - 1, stdin) == NULL)
40 break;
41
42 /*
43 * remove the ending spaces
44 */
45 i = strlen(str);
46 while ((i > 0) &&
47 ((str[i - 1] == '\n') || (str[i - 1] == '\r') ||
48 (str[i - 1] == ' ') || (str[i - 1] == '\t'))) {
49 i--;
50 str[i] = 0;
51 }
Daniel Veillarde77a9182000-04-05 19:12:29 +000052
Daniel Veillard98a79162000-09-04 11:15:39 +000053 if (base == NULL) {
54 ret = xmlParseURIReference(uri, str);
55 if (ret != 0)
56 printf("%s : error %d\n", str, ret);
57 else {
Daniel Veillardb6e7fdb2001-02-02 17:07:32 +000058 xmlNormalizeURIPath(uri->path);
Daniel Veillard98a79162000-09-04 11:15:39 +000059 xmlPrintURI(stdout, uri);
60 printf("\n");
61 }
62 } else {
63 composite = xmlBuildURI((xmlChar *)str, (xmlChar *) base);
64 if (composite != NULL) {
65 printf("%s\n", composite);
66 xmlFree(composite);
67 }
68 else
69 printf("::ERROR::\n");
Daniel Veillarde77a9182000-04-05 19:12:29 +000070 }
Daniel Veillarde77a9182000-04-05 19:12:29 +000071 }
72 } else {
73 while (argv[arg] != NULL) {
74 if (base == NULL) {
75 ret = xmlParseURIReference(uri, argv[arg]);
76 if (ret != 0)
77 printf("%s : error %d\n", argv[arg], ret);
78 else {
79 xmlPrintURI(stdout, uri);
80 printf("\n");
81 }
82 } else {
83 composite = xmlBuildURI((xmlChar *)argv[arg], (xmlChar *) base);
Daniel Veillard52402ce2000-08-22 23:36:12 +000084 if (composite != NULL) {
Daniel Veillarde77a9182000-04-05 19:12:29 +000085 printf("%s\n", composite);
86 xmlFree(composite);
87 }
88 }
89 arg++;
90 }
91 }
92 xmlFreeURI(uri);
93 xmlMemoryDump();
Daniel Veillardb6e7fdb2001-02-02 17:07:32 +000094 return(0);
Daniel Veillarde77a9182000-04-05 19:12:29 +000095}