Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > DoxygentestURI.c
Go to the documentation of this file.
00001 /* 00002 * testURI.c : a small tester program for XML input. 00003 * 00004 * See Copyright for the status of this software. 00005 * 00006 * daniel@veillard.com 00007 */ 00008 00009 #include "libxml.h" 00010 00011 #include <string.h> 00012 #include <stdio.h> 00013 #include <stdarg.h> 00014 00015 #include <libxml/xmlmemory.h> 00016 #include <libxml/uri.h> 00017 #include <libxml/globals.h> 00018 00019 static const char *base = NULL; 00020 static int escape = 0; 00021 static int debug = 0; 00022 00023 static void handleURI(const char *str) { 00024 int ret; 00025 xmlURIPtr uri; 00026 xmlChar *res = NULL, *parsed = NULL; 00027 00028 uri = xmlCreateURI(); 00029 00030 if (base == NULL) { 00031 ret = xmlParseURIReference(uri, str); 00032 if (ret != 0) 00033 printf("%s : error %d\n", str, ret); 00034 else { 00035 if (debug) { 00036 if (uri->scheme) printf("scheme: %s\n", uri->scheme); 00037 if (uri->opaque) printf("opaque: %s\n", uri->opaque); 00038 if (uri->authority) printf("authority: %s\n", uri->authority); 00039 if (uri->server) printf("server: %s\n", uri->server); 00040 if (uri->user) printf("user: %s\n", uri->user); 00041 if (uri->port != 0) printf("port: %d\n", uri->port); 00042 if (uri->path) printf("path: %s\n", uri->path); 00043 if (uri->query) printf("query: %s\n", uri->query); 00044 if (uri->fragment) printf("fragment: %s\n", uri->fragment); 00045 if (uri->query_raw) printf("query_raw: %s\n", uri->query_raw); 00046 if (uri->cleanup != 0) printf("cleanup\n"); 00047 } 00048 xmlNormalizeURIPath(uri->path); 00049 if (escape != 0) { 00050 parsed = xmlSaveUri(uri); 00051 res = xmlURIEscape(parsed); 00052 printf("%s\n", (char *) res); 00053 00054 } else { 00055 xmlPrintURI(stdout, uri); 00056 printf("\n"); 00057 } 00058 } 00059 } else { 00060 res = xmlBuildURI((xmlChar *)str, (xmlChar *) base); 00061 if (res != NULL) { 00062 printf("%s\n", (char *) res); 00063 } 00064 else 00065 printf("::ERROR::\n"); 00066 } 00067 if (res != NULL) 00068 xmlFree(res); 00069 if (parsed != NULL) 00070 xmlFree(parsed); 00071 xmlFreeURI(uri); 00072 } 00073 00074 int main(int argc, char **argv) { 00075 int i, arg = 1; 00076 00077 if ((argc > arg) && (argv[arg] != NULL) && 00078 ((!strcmp(argv[arg], "-base")) || (!strcmp(argv[arg], "--base")))) { 00079 arg++; 00080 base = argv[arg]; 00081 if (base != NULL) 00082 arg++; 00083 } 00084 if ((argc > arg) && (argv[arg] != NULL) && 00085 ((!strcmp(argv[arg], "-escape")) || (!strcmp(argv[arg], "--escape")))) { 00086 arg++; 00087 escape++; 00088 } 00089 if ((argc > arg) && (argv[arg] != NULL) && 00090 ((!strcmp(argv[arg], "-debug")) || (!strcmp(argv[arg], "--debug")))) { 00091 arg++; 00092 debug++; 00093 } 00094 if (argv[arg] == NULL) { 00095 char str[1024]; 00096 00097 while (1) { 00098 /* 00099 * read one line in string buffer. 00100 */ 00101 if (fgets (&str[0], sizeof (str) - 1, stdin) == NULL) 00102 break; 00103 00104 /* 00105 * remove the ending spaces 00106 */ 00107 i = strlen(str); 00108 while ((i > 0) && 00109 ((str[i - 1] == '\n') || (str[i - 1] == '\r') || 00110 (str[i - 1] == ' ') || (str[i - 1] == '\t'))) { 00111 i--; 00112 str[i] = 0; 00113 } 00114 handleURI(str); 00115 } 00116 } else { 00117 while (argv[arg] != NULL) { 00118 handleURI(argv[arg]); 00119 arg++; 00120 } 00121 } 00122 xmlMemoryDump(); 00123 return(0); 00124 } Generated on Sat May 26 2012 04:33:33 for ReactOS by
1.7.6.1
|