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