2000-04-05 19:12:29 +00:00
/*
* testURI . c : a small tester program for XML input .
*
* See Copyright for the status of this software .
*
2001-06-24 12:13:24 +00:00
* daniel @ veillard . com
2000-04-05 19:12:29 +00:00
*/
2001-04-21 16:57:29 +00:00
# include "libxml.h"
2000-04-05 19:12:29 +00:00
# include <string.h>
# include <stdio.h>
# include <stdarg.h>
2000-06-28 23:40:59 +00:00
# include <libxml/xmlmemory.h>
2000-04-05 19:12:29 +00:00
# include <libxml/uri.h>
2001-10-17 15:58:35 +00:00
# include <libxml/globals.h>
2000-04-05 19:12:29 +00:00
2001-12-07 11:33:54 +00:00
static const char * base = NULL ;
static int escape = 0 ;
static void handleURI ( const char * str ) {
int ret ;
2000-04-05 19:12:29 +00:00
xmlURIPtr uri ;
2001-12-07 11:33:54 +00:00
xmlChar * res = NULL , * parsed = NULL ;
uri = xmlCreateURI ( ) ;
2000-04-05 19:12:29 +00:00
2001-12-07 11:33:54 +00:00
if ( base = = NULL ) {
ret = xmlParseURIReference ( uri , str ) ;
if ( ret ! = 0 )
printf ( " %s : error %d \n " , str , ret ) ;
else {
xmlNormalizeURIPath ( uri - > path ) ;
if ( escape ! = 0 ) {
parsed = xmlSaveUri ( uri ) ;
res = xmlURIEscape ( parsed ) ;
2003-08-05 15:52:22 +00:00
printf ( " %s \n " , ( char * ) res ) ;
2001-12-07 11:33:54 +00:00
} else {
xmlPrintURI ( stdout , uri ) ;
printf ( " \n " ) ;
}
}
} else {
res = xmlBuildURI ( ( xmlChar * ) str , ( xmlChar * ) base ) ;
if ( res ! = NULL ) {
2003-08-05 15:52:22 +00:00
printf ( " %s \n " , ( char * ) res ) ;
2001-12-07 11:33:54 +00:00
}
else
printf ( " ::ERROR:: \n " ) ;
}
if ( res ! = NULL )
xmlFree ( res ) ;
if ( parsed ! = NULL )
xmlFree ( parsed ) ;
xmlFreeURI ( uri ) ;
}
int main ( int argc , char * * argv ) {
int i , arg = 1 ;
if ( ( argc > arg ) & & ( argv [ arg ] ! = NULL ) & &
2001-02-02 17:07:32 +00:00
( ( ! strcmp ( argv [ arg ] , " -base " ) ) | | ( ! strcmp ( argv [ arg ] , " --base " ) ) ) ) {
2000-04-05 19:12:29 +00:00
arg + + ;
base = argv [ arg ] ;
if ( base ! = NULL )
arg + + ;
}
2001-12-07 11:33:54 +00:00
if ( ( argc > arg ) & & ( argv [ arg ] ! = NULL ) & &
( ( ! strcmp ( argv [ arg ] , " -escape " ) ) | | ( ! strcmp ( argv [ arg ] , " --escape " ) ) ) ) {
arg + + ;
escape + + ;
}
2000-04-05 19:12:29 +00:00
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 ;
}
2001-12-07 11:33:54 +00:00
handleURI ( str ) ;
2000-04-05 19:12:29 +00:00
}
} else {
while ( argv [ arg ] ! = NULL ) {
2001-12-07 11:33:54 +00:00
handleURI ( argv [ arg ] ) ;
2000-04-05 19:12:29 +00:00
arg + + ;
}
}
xmlMemoryDump ( ) ;
2001-02-02 17:07:32 +00:00
return ( 0 ) ;
2000-04-05 19:12:29 +00:00
}