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 | |
| 9 | #ifdef WIN32 |
| 10 | #include "win32config.h" |
| 11 | #else |
| 12 | #include "config.h" |
| 13 | #endif |
| 14 | |
| 15 | #include <stdio.h> |
| 16 | #include <string.h> |
| 17 | #include <stdio.h> |
| 18 | #include <stdarg.h> |
| 19 | |
Daniel Veillard | be80396 | 2000-06-28 23:40:59 +0000 | [diff] [blame] | 20 | #include <libxml/xmlversion.h> |
| 21 | #include <libxml/xmlmemory.h> |
Daniel Veillard | e77a918 | 2000-04-05 19:12:29 +0000 | [diff] [blame] | 22 | #include <libxml/uri.h> |
| 23 | |
| 24 | int main(int argc, char **argv) { |
| 25 | int i, ret, arg = 1; |
| 26 | xmlURIPtr uri; |
| 27 | const char *base = NULL; |
| 28 | xmlChar *composite; |
| 29 | |
Daniel Veillard | b6e7fdb | 2001-02-02 17:07:32 +0000 | [diff] [blame] | 30 | if ((argv[arg] != NULL) && |
| 31 | ((!strcmp(argv[arg], "-base")) || (!strcmp(argv[arg], "--base")))) { |
Daniel Veillard | e77a918 | 2000-04-05 19:12:29 +0000 | [diff] [blame] | 32 | arg++; |
| 33 | base = argv[arg]; |
| 34 | if (base != NULL) |
| 35 | arg++; |
| 36 | } |
| 37 | uri = xmlCreateURI(); |
| 38 | if (argv[arg] == NULL) { |
| 39 | char str[1024]; |
| 40 | |
| 41 | while (1) { |
| 42 | /* |
| 43 | * read one line in string buffer. |
| 44 | */ |
| 45 | if (fgets (&str[0], sizeof (str) - 1, stdin) == NULL) |
| 46 | break; |
| 47 | |
| 48 | /* |
| 49 | * remove the ending spaces |
| 50 | */ |
| 51 | i = strlen(str); |
| 52 | while ((i > 0) && |
| 53 | ((str[i - 1] == '\n') || (str[i - 1] == '\r') || |
| 54 | (str[i - 1] == ' ') || (str[i - 1] == '\t'))) { |
| 55 | i--; |
| 56 | str[i] = 0; |
| 57 | } |
Daniel Veillard | e77a918 | 2000-04-05 19:12:29 +0000 | [diff] [blame] | 58 | |
Daniel Veillard | 98a7916 | 2000-09-04 11:15:39 +0000 | [diff] [blame] | 59 | if (base == NULL) { |
| 60 | ret = xmlParseURIReference(uri, str); |
| 61 | if (ret != 0) |
| 62 | printf("%s : error %d\n", str, ret); |
| 63 | else { |
Daniel Veillard | b6e7fdb | 2001-02-02 17:07:32 +0000 | [diff] [blame] | 64 | xmlNormalizeURIPath(uri->path); |
Daniel Veillard | 98a7916 | 2000-09-04 11:15:39 +0000 | [diff] [blame] | 65 | xmlPrintURI(stdout, uri); |
| 66 | printf("\n"); |
| 67 | } |
| 68 | } else { |
| 69 | composite = xmlBuildURI((xmlChar *)str, (xmlChar *) base); |
| 70 | if (composite != NULL) { |
| 71 | printf("%s\n", composite); |
| 72 | xmlFree(composite); |
| 73 | } |
| 74 | else |
| 75 | printf("::ERROR::\n"); |
Daniel Veillard | e77a918 | 2000-04-05 19:12:29 +0000 | [diff] [blame] | 76 | } |
Daniel Veillard | e77a918 | 2000-04-05 19:12:29 +0000 | [diff] [blame] | 77 | } |
| 78 | } else { |
| 79 | while (argv[arg] != NULL) { |
| 80 | if (base == NULL) { |
| 81 | ret = xmlParseURIReference(uri, argv[arg]); |
| 82 | if (ret != 0) |
| 83 | printf("%s : error %d\n", argv[arg], ret); |
| 84 | else { |
| 85 | xmlPrintURI(stdout, uri); |
| 86 | printf("\n"); |
| 87 | } |
| 88 | } else { |
| 89 | composite = xmlBuildURI((xmlChar *)argv[arg], (xmlChar *) base); |
Daniel Veillard | 52402ce | 2000-08-22 23:36:12 +0000 | [diff] [blame] | 90 | if (composite != NULL) { |
Daniel Veillard | e77a918 | 2000-04-05 19:12:29 +0000 | [diff] [blame] | 91 | printf("%s\n", composite); |
| 92 | xmlFree(composite); |
| 93 | } |
| 94 | } |
| 95 | arg++; |
| 96 | } |
| 97 | } |
| 98 | xmlFreeURI(uri); |
| 99 | xmlMemoryDump(); |
Daniel Veillard | b6e7fdb | 2001-02-02 17:07:32 +0000 | [diff] [blame] | 100 | return(0); |
Daniel Veillard | e77a918 | 2000-04-05 19:12:29 +0000 | [diff] [blame] | 101 | } |