Daniel Veillard | e77a918 | 2000-04-05 19:12:29 +0000 | [diff] [blame] | 1 | /* |
| 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 | |
Bjorn Reese | 70a9da5 | 2001-04-21 16:57:29 +0000 | [diff] [blame] | 9 | #include "libxml.h" |
Daniel Veillard | e77a918 | 2000-04-05 19:12:29 +0000 | [diff] [blame] | 10 | |
Daniel Veillard | e77a918 | 2000-04-05 19:12:29 +0000 | [diff] [blame] | 11 | #include <string.h> |
| 12 | #include <stdio.h> |
| 13 | #include <stdarg.h> |
| 14 | |
Daniel Veillard | be80396 | 2000-06-28 23:40:59 +0000 | [diff] [blame] | 15 | #include <libxml/xmlmemory.h> |
Daniel Veillard | e77a918 | 2000-04-05 19:12:29 +0000 | [diff] [blame] | 16 | #include <libxml/uri.h> |
| 17 | |
| 18 | int main(int argc, char **argv) { |
| 19 | int i, ret, arg = 1; |
| 20 | xmlURIPtr uri; |
| 21 | const char *base = NULL; |
| 22 | xmlChar *composite; |
| 23 | |
Daniel Veillard | 56a4cb8 | 2001-03-24 17:00:36 +0000 | [diff] [blame] | 24 | if ((argc > 1) && (argv[arg] != NULL) && |
Daniel Veillard | b6e7fdb | 2001-02-02 17:07:32 +0000 | [diff] [blame] | 25 | ((!strcmp(argv[arg], "-base")) || (!strcmp(argv[arg], "--base")))) { |
Daniel Veillard | e77a918 | 2000-04-05 19:12:29 +0000 | [diff] [blame] | 26 | 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 Veillard | e77a918 | 2000-04-05 19:12:29 +0000 | [diff] [blame] | 52 | |
Daniel Veillard | 98a7916 | 2000-09-04 11:15:39 +0000 | [diff] [blame] | 53 | if (base == NULL) { |
| 54 | ret = xmlParseURIReference(uri, str); |
| 55 | if (ret != 0) |
| 56 | printf("%s : error %d\n", str, ret); |
| 57 | else { |
Daniel Veillard | b6e7fdb | 2001-02-02 17:07:32 +0000 | [diff] [blame] | 58 | xmlNormalizeURIPath(uri->path); |
Daniel Veillard | 98a7916 | 2000-09-04 11:15:39 +0000 | [diff] [blame] | 59 | 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 Veillard | e77a918 | 2000-04-05 19:12:29 +0000 | [diff] [blame] | 70 | } |
Daniel Veillard | e77a918 | 2000-04-05 19:12:29 +0000 | [diff] [blame] | 71 | } |
| 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 Veillard | 52402ce | 2000-08-22 23:36:12 +0000 | [diff] [blame] | 84 | if (composite != NULL) { |
Daniel Veillard | e77a918 | 2000-04-05 19:12:29 +0000 | [diff] [blame] | 85 | printf("%s\n", composite); |
| 86 | xmlFree(composite); |
| 87 | } |
| 88 | } |
| 89 | arg++; |
| 90 | } |
| 91 | } |
| 92 | xmlFreeURI(uri); |
| 93 | xmlMemoryDump(); |
Daniel Veillard | b6e7fdb | 2001-02-02 17:07:32 +0000 | [diff] [blame] | 94 | return(0); |
Daniel Veillard | e77a918 | 2000-04-05 19:12:29 +0000 | [diff] [blame] | 95 | } |