2000-04-06 03:12:29 +08:00
|
|
|
/*
|
|
|
|
* testURI.c : a small tester program for XML input.
|
|
|
|
*
|
|
|
|
* See Copyright for the status of this software.
|
|
|
|
*
|
2001-06-24 20:13:24 +08:00
|
|
|
* daniel@veillard.com
|
2000-04-06 03:12:29 +08:00
|
|
|
*/
|
|
|
|
|
2001-04-22 00:57:29 +08:00
|
|
|
#include "libxml.h"
|
2000-04-06 03:12:29 +08:00
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
|
2000-06-29 07:40:59 +08:00
|
|
|
#include <libxml/xmlmemory.h>
|
2000-04-06 03:12:29 +08:00
|
|
|
#include <libxml/uri.h>
|
|
|
|
|
|
|
|
int main(int argc, char **argv) {
|
|
|
|
int i, ret, arg = 1;
|
|
|
|
xmlURIPtr uri;
|
|
|
|
const char *base = NULL;
|
|
|
|
xmlChar *composite;
|
|
|
|
|
2001-03-25 01:00:36 +08:00
|
|
|
if ((argc > 1) && (argv[arg] != NULL) &&
|
2001-02-03 01:07:32 +08:00
|
|
|
((!strcmp(argv[arg], "-base")) || (!strcmp(argv[arg], "--base")))) {
|
2000-04-06 03:12:29 +08:00
|
|
|
arg++;
|
|
|
|
base = argv[arg];
|
|
|
|
if (base != NULL)
|
|
|
|
arg++;
|
|
|
|
}
|
|
|
|
uri = xmlCreateURI();
|
|
|
|
if (argv[arg] == NULL) {
|
|
|
|
char str[1024];
|
|
|
|
|
|
|
|
while (1) {
|
|
|
|
/*
|
|
|
|
* read one line in string buffer.
|
|
|
|
*/
|
|
|
|
if (fgets (&str[0], sizeof (str) - 1, stdin) == NULL)
|
|
|
|
break;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* remove the ending spaces
|
|
|
|
*/
|
|
|
|
i = strlen(str);
|
|
|
|
while ((i > 0) &&
|
|
|
|
((str[i - 1] == '\n') || (str[i - 1] == '\r') ||
|
|
|
|
(str[i - 1] == ' ') || (str[i - 1] == '\t'))) {
|
|
|
|
i--;
|
|
|
|
str[i] = 0;
|
|
|
|
}
|
|
|
|
|
2000-09-04 19:15:39 +08:00
|
|
|
if (base == NULL) {
|
|
|
|
ret = xmlParseURIReference(uri, str);
|
|
|
|
if (ret != 0)
|
|
|
|
printf("%s : error %d\n", str, ret);
|
|
|
|
else {
|
2001-02-03 01:07:32 +08:00
|
|
|
xmlNormalizeURIPath(uri->path);
|
2000-09-04 19:15:39 +08:00
|
|
|
xmlPrintURI(stdout, uri);
|
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
composite = xmlBuildURI((xmlChar *)str, (xmlChar *) base);
|
|
|
|
if (composite != NULL) {
|
|
|
|
printf("%s\n", composite);
|
|
|
|
xmlFree(composite);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
printf("::ERROR::\n");
|
2000-04-06 03:12:29 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
while (argv[arg] != NULL) {
|
|
|
|
if (base == NULL) {
|
|
|
|
ret = xmlParseURIReference(uri, argv[arg]);
|
|
|
|
if (ret != 0)
|
|
|
|
printf("%s : error %d\n", argv[arg], ret);
|
|
|
|
else {
|
|
|
|
xmlPrintURI(stdout, uri);
|
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
composite = xmlBuildURI((xmlChar *)argv[arg], (xmlChar *) base);
|
2000-08-23 07:36:12 +08:00
|
|
|
if (composite != NULL) {
|
2000-04-06 03:12:29 +08:00
|
|
|
printf("%s\n", composite);
|
|
|
|
xmlFree(composite);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
arg++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
xmlFreeURI(uri);
|
|
|
|
xmlMemoryDump();
|
2001-02-03 01:07:32 +08:00
|
|
|
return(0);
|
2000-04-06 03:12:29 +08:00
|
|
|
}
|