2001-08-20 04:08:40 +04:00
/*
* xmlcatalog . c : a small utility program to handle XML catalogs
*
* See Copyright for the status of this software .
*
* daniel @ veillard . com
*/
# include "libxml.h"
# include <string.h>
# include <stdio.h>
# include <stdarg.h>
2001-09-20 17:56:06 +04:00
# include <stdlib.h>
2001-08-21 13:23:53 +04:00
# ifdef HAVE_LIBREADLINE
# include <readline/readline.h>
# ifdef HAVE_LIBHISTORY
# include <readline/history.h>
# endif
# endif
2001-08-20 04:08:40 +04:00
# include <libxml/xmlmemory.h>
# include <libxml/uri.h>
# include <libxml/catalog.h>
# include <libxml/parser.h>
2001-10-17 19:58:35 +04:00
# include <libxml/globals.h>
2001-08-20 04:08:40 +04:00
2003-09-29 17:20:24 +04:00
# if defined(LIBXML_CATALOG_ENABLED) && defined(LIBXML_OUTPUT_ENABLED)
2001-08-20 04:08:40 +04:00
static int shell = 0 ;
2001-10-08 19:01:59 +04:00
static int sgml = 0 ;
2001-08-20 04:08:40 +04:00
static int noout = 0 ;
2001-08-23 03:44:09 +04:00
static int create = 0 ;
2001-08-21 14:56:31 +04:00
static int add = 0 ;
static int del = 0 ;
2001-08-25 17:33:14 +04:00
static int convert = 0 ;
2004-08-15 01:46:31 +04:00
static int no_super_update = 0 ;
2001-08-20 04:08:40 +04:00
static int verbose = 0 ;
2003-12-12 17:56:03 +03:00
static char * filename = NULL ;
2001-08-20 04:08:40 +04:00
2001-11-04 23:03:38 +03:00
2003-01-26 22:49:04 +03:00
# ifndef XML_SGML_DEFAULT_CATALOG
2022-03-30 01:32:35 +03:00
# define XML_SGML_DEFAULT_CATALOG SYSCONFDIR " / sgml / catalog"
2003-01-26 22:49:04 +03:00
# endif
2001-11-04 23:03:38 +03:00
2001-08-20 04:08:40 +04:00
/************************************************************************
2012-09-11 09:26:36 +04:00
* *
* Shell Interface *
* *
2001-08-20 04:08:40 +04:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/**
* xmlShellReadline :
* @ prompt : the prompt value
*
* Read a string
2012-09-11 09:26:36 +04:00
*
2001-08-20 04:08:40 +04:00
* Returns a pointer to it or NULL on EOF the caller is expected to
* free the returned string .
*/
static char *
xmlShellReadline ( const char * prompt ) {
# ifdef HAVE_LIBREADLINE
char * line_read ;
/* Get a line from the user. */
line_read = readline ( prompt ) ;
/* If the line has any text in it, save it on the history. */
if ( line_read & & * line_read )
add_history ( line_read ) ;
return ( line_read ) ;
# else
char line_read [ 501 ] ;
2002-01-18 19:23:55 +03:00
char * ret ;
int len ;
2001-08-20 04:08:40 +04:00
if ( prompt ! = NULL )
fprintf ( stdout , " %s " , prompt ) ;
2015-04-20 16:00:58 +03:00
fflush ( stdout ) ;
2001-08-20 04:08:40 +04:00
if ( ! fgets ( line_read , 500 , stdin ) )
return ( NULL ) ;
line_read [ 500 ] = 0 ;
2002-01-18 19:23:55 +03:00
len = strlen ( line_read ) ;
ret = ( char * ) malloc ( len + 1 ) ;
if ( ret ! = NULL ) {
memcpy ( ret , line_read , len + 1 ) ;
}
return ( ret ) ;
2001-08-20 04:08:40 +04:00
# endif
}
static void usershell ( void ) {
char * cmdline = NULL , * cur ;
int nbargs ;
char command [ 100 ] ;
char arg [ 400 ] ;
2001-08-21 14:56:31 +04:00
char * argv [ 20 ] ;
int i , ret ;
xmlChar * ans ;
2001-08-20 04:08:40 +04:00
while ( 1 ) {
cmdline = xmlShellReadline ( " > " ) ;
if ( cmdline = = NULL )
return ;
/*
* Parse the command itself
*/
cur = cmdline ;
nbargs = 0 ;
while ( ( * cur = = ' ' ) | | ( * cur = = ' \t ' ) ) cur + + ;
i = 0 ;
while ( ( * cur ! = ' ' ) & & ( * cur ! = ' \t ' ) & &
( * cur ! = ' \n ' ) & & ( * cur ! = ' \r ' ) ) {
if ( * cur = = 0 )
break ;
command [ i + + ] = * cur + + ;
}
command [ i ] = 0 ;
2006-03-10 03:36:23 +03:00
if ( i = = 0 ) {
free ( cmdline ) ;
continue ;
}
2001-08-20 04:08:40 +04:00
/*
2001-08-21 14:56:31 +04:00
* Parse the argument string
2001-08-20 04:08:40 +04:00
*/
2001-08-21 14:56:31 +04:00
memset ( arg , 0 , sizeof ( arg ) ) ;
2001-08-20 04:08:40 +04:00
while ( ( * cur = = ' ' ) | | ( * cur = = ' \t ' ) ) cur + + ;
i = 0 ;
while ( ( * cur ! = ' \n ' ) & & ( * cur ! = ' \r ' ) & & ( * cur ! = 0 ) ) {
if ( * cur = = 0 )
break ;
arg [ i + + ] = * cur + + ;
}
arg [ i ] = 0 ;
2001-08-21 14:56:31 +04:00
/*
* Parse the arguments
*/
i = 0 ;
nbargs = 0 ;
cur = arg ;
memset ( argv , 0 , sizeof ( argv ) ) ;
while ( * cur ! = 0 ) {
while ( ( * cur = = ' ' ) | | ( * cur = = ' \t ' ) ) cur + + ;
if ( * cur = = ' \' ' ) {
cur + + ;
argv [ i ] = cur ;
while ( ( * cur ! = 0 ) & & ( * cur ! = ' \' ' ) ) cur + + ;
if ( * cur = = ' \' ' ) {
* cur = 0 ;
nbargs + + ;
i + + ;
cur + + ;
}
2012-09-11 09:26:36 +04:00
} else if ( * cur = = ' " ' ) {
2001-08-21 14:56:31 +04:00
cur + + ;
argv [ i ] = cur ;
while ( ( * cur ! = 0 ) & & ( * cur ! = ' " ' ) ) cur + + ;
if ( * cur = = ' " ' ) {
* cur = 0 ;
nbargs + + ;
i + + ;
cur + + ;
}
} else {
argv [ i ] = cur ;
while ( ( * cur ! = 0 ) & & ( * cur ! = ' ' ) & & ( * cur ! = ' \t ' ) )
cur + + ;
* cur = 0 ;
nbargs + + ;
i + + ;
cur + + ;
}
}
2001-08-20 04:08:40 +04:00
/*
* start interpreting the command
*/
2014-06-21 00:05:33 +04:00
if ( ! strcmp ( command , " exit " ) | |
! strcmp ( command , " quit " ) | |
! strcmp ( command , " bye " ) ) {
free ( cmdline ) ;
2001-08-20 04:08:40 +04:00
break ;
2014-06-21 00:05:33 +04:00
}
2001-08-20 04:08:40 +04:00
if ( ! strcmp ( command , " public " ) ) {
2001-08-21 14:56:31 +04:00
if ( nbargs ! = 1 ) {
printf ( " public requires 1 arguments \n " ) ;
2001-08-20 04:08:40 +04:00
} else {
2001-08-22 04:06:49 +04:00
ans = xmlCatalogResolvePublic ( ( const xmlChar * ) argv [ 0 ] ) ;
if ( ans = = NULL ) {
2001-08-21 14:56:31 +04:00
printf ( " No entry for PUBLIC %s \n " , argv [ 0 ] ) ;
} else {
2003-08-05 19:52:22 +04:00
printf ( " %s \n " , ( char * ) ans ) ;
2001-08-22 04:06:49 +04:00
xmlFree ( ans ) ;
2001-08-21 14:56:31 +04:00
}
2001-08-20 04:08:40 +04:00
}
} else if ( ! strcmp ( command , " system " ) ) {
2001-08-21 14:56:31 +04:00
if ( nbargs ! = 1 ) {
printf ( " system requires 1 arguments \n " ) ;
} else {
2001-08-22 04:06:49 +04:00
ans = xmlCatalogResolveSystem ( ( const xmlChar * ) argv [ 0 ] ) ;
if ( ans = = NULL ) {
2001-08-21 14:56:31 +04:00
printf ( " No entry for SYSTEM %s \n " , argv [ 0 ] ) ;
} else {
2003-08-05 19:52:22 +04:00
printf ( " %s \n " , ( char * ) ans ) ;
2001-08-22 04:06:49 +04:00
xmlFree ( ans ) ;
2001-08-21 14:56:31 +04:00
}
}
} else if ( ! strcmp ( command , " add " ) ) {
2021-07-14 19:12:11 +03:00
if ( ( nbargs ! = 3 ) & & ( nbargs ! = 2 ) ) {
printf ( " add requires 2 or 3 arguments \n " ) ;
2001-08-21 14:56:31 +04:00
} else {
2021-07-14 19:12:11 +03:00
if ( argv [ 2 ] = = NULL )
ret = xmlCatalogAdd ( BAD_CAST argv [ 0 ] , NULL ,
BAD_CAST argv [ 1 ] ) ;
else
ret = xmlCatalogAdd ( BAD_CAST argv [ 0 ] , BAD_CAST argv [ 1 ] ,
BAD_CAST argv [ 2 ] ) ;
if ( ret ! = 0 )
printf ( " add command failed \n " ) ;
2001-08-21 14:56:31 +04:00
}
} else if ( ! strcmp ( command , " del " ) ) {
if ( nbargs ! = 1 ) {
printf ( " del requires 1 \n " ) ;
} else {
ret = xmlCatalogRemove ( BAD_CAST argv [ 0 ] ) ;
if ( ret < = 0 )
printf ( " del command failed \n " ) ;
}
} else if ( ! strcmp ( command , " resolve " ) ) {
if ( nbargs ! = 2 ) {
printf ( " resolve requires 2 arguments \n " ) ;
2001-08-20 04:08:40 +04:00
} else {
2001-08-21 14:56:31 +04:00
ans = xmlCatalogResolve ( BAD_CAST argv [ 0 ] ,
BAD_CAST argv [ 1 ] ) ;
if ( ans = = NULL ) {
printf ( " Resolver failed to find an answer \n " ) ;
} else {
2003-08-05 19:52:22 +04:00
printf ( " %s \n " , ( char * ) ans ) ;
2001-08-21 14:56:31 +04:00
xmlFree ( ans ) ;
}
2001-08-20 04:08:40 +04:00
}
} else if ( ! strcmp ( command , " dump " ) ) {
2001-08-21 14:56:31 +04:00
if ( nbargs ! = 0 ) {
printf ( " dump has no arguments \n " ) ;
} else {
xmlCatalogDump ( stdout ) ;
}
2001-08-22 04:06:49 +04:00
} else if ( ! strcmp ( command , " debug " ) ) {
if ( nbargs ! = 0 ) {
printf ( " debug has no arguments \n " ) ;
} else {
verbose + + ;
xmlCatalogSetDebug ( verbose ) ;
}
} else if ( ! strcmp ( command , " quiet " ) ) {
if ( nbargs ! = 0 ) {
printf ( " quiet has no arguments \n " ) ;
} else {
if ( verbose > 0 )
verbose - - ;
xmlCatalogSetDebug ( verbose ) ;
}
2001-08-20 04:08:40 +04:00
} else {
if ( strcmp ( command , " help " ) ) {
printf ( " Unrecognized command %s \n " , command ) ;
}
printf ( " Commands available: \n " ) ;
printf ( " \t public PublicID: make a PUBLIC identifier lookup \n " ) ;
printf ( " \t system SystemID: make a SYSTEM identifier lookup \n " ) ;
2001-08-21 14:56:31 +04:00
printf ( " \t resolve PublicID SystemID: do a full resolver lookup \n " ) ;
printf ( " \t add 'type' 'orig' 'replace' : add an entry \n " ) ;
printf ( " \t del 'values' : remove values \n " ) ;
2001-08-20 04:08:40 +04:00
printf ( " \t dump: print the current catalog state \n " ) ;
2001-08-22 04:06:49 +04:00
printf ( " \t debug: increase the verbosity level \n " ) ;
printf ( " \t quiet: decrease the verbosity level \n " ) ;
2001-08-20 04:08:40 +04:00
printf ( " \t exit: quit the shell \n " ) ;
2012-09-11 09:26:36 +04:00
}
2001-08-20 04:08:40 +04:00
free ( cmdline ) ; /* not xmlFree here ! */
}
}
/************************************************************************
2012-09-11 09:26:36 +04:00
* *
* Main *
* *
2001-08-20 04:08:40 +04:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
static void usage ( const char * name ) {
2004-10-06 20:38:01 +04:00
/* split into 2 printf's to avoid overly long string (gcc warning) */
2004-08-15 01:46:31 +04:00
printf ( " \
Usage : % s [ options ] catalogfile entities . . . \ n \
2017-10-19 14:27:29 +03:00
\ tParse the catalog file ( void specification possibly expressed as \ " \" \n \
\ tappoints the default system one ) and query it for the entities \ n \
2004-08-15 01:46:31 +04:00
\ t - - sgml : handle SGML Super catalogs for - - add and - - del \ n \
\ t - - shell : run a shell allowing interactive queries \ n \
\ t - - create : create a new catalog \ n \
\ t - - add ' type ' ' orig ' ' replace ' : add an XML entry \ n \
2004-10-06 20:38:01 +04:00
\ t - - add ' entry ' : add an SGML entry \ n " , name);
printf ( " \
2004-08-15 01:46:31 +04:00
\ t - - del ' values ' : remove values \ n \
\ t - - noout : avoid dumping the result on stdout \ n \
\ t used with - - add or - - del , it saves the catalog changes \ n \
\ t and with - - sgml it automatically updates the super catalog \ n \
\ t - - no - super - update : do not update the SGML super catalog \ n \
2020-03-08 19:19:42 +03:00
\ t - v - - verbose : provide debug information \ n " );
2001-08-20 04:08:40 +04:00
}
int main ( int argc , char * * argv ) {
int i ;
2001-08-25 17:33:14 +04:00
int ret ;
2002-01-20 15:42:06 +03:00
int exit_value = 0 ;
2001-08-25 17:33:14 +04:00
2001-08-20 04:08:40 +04:00
if ( argc < = 1 ) {
usage ( argv [ 0 ] ) ;
return ( 1 ) ;
}
LIBXML_TEST_VERSION
for ( i = 1 ; i < argc ; i + + ) {
if ( ! strcmp ( argv [ i ] , " - " ) )
break ;
if ( argv [ i ] [ 0 ] ! = ' - ' )
2001-08-22 04:06:49 +04:00
break ;
2001-08-20 04:08:40 +04:00
if ( ( ! strcmp ( argv [ i ] , " -verbose " ) ) | |
( ! strcmp ( argv [ i ] , " -v " ) ) | |
( ! strcmp ( argv [ i ] , " --verbose " ) ) ) {
verbose + + ;
xmlCatalogSetDebug ( verbose ) ;
2001-08-21 14:56:31 +04:00
} else if ( ( ! strcmp ( argv [ i ] , " -noout " ) ) | |
( ! strcmp ( argv [ i ] , " --noout " ) ) ) {
noout = 1 ;
2001-08-20 04:08:40 +04:00
} else if ( ( ! strcmp ( argv [ i ] , " -shell " ) ) | |
( ! strcmp ( argv [ i ] , " --shell " ) ) ) {
shell + + ;
noout = 1 ;
2001-10-08 19:01:59 +04:00
} else if ( ( ! strcmp ( argv [ i ] , " -sgml " ) ) | |
( ! strcmp ( argv [ i ] , " --sgml " ) ) ) {
sgml + + ;
2001-08-23 03:44:09 +04:00
} else if ( ( ! strcmp ( argv [ i ] , " -create " ) ) | |
( ! strcmp ( argv [ i ] , " --create " ) ) ) {
create + + ;
2001-08-25 17:33:14 +04:00
} else if ( ( ! strcmp ( argv [ i ] , " -convert " ) ) | |
( ! strcmp ( argv [ i ] , " --convert " ) ) ) {
convert + + ;
2004-08-15 01:46:31 +04:00
} else if ( ( ! strcmp ( argv [ i ] , " -no-super-update " ) ) | |
( ! strcmp ( argv [ i ] , " --no-super-update " ) ) ) {
no_super_update + + ;
2001-08-21 14:56:31 +04:00
} else if ( ( ! strcmp ( argv [ i ] , " -add " ) ) | |
( ! strcmp ( argv [ i ] , " --add " ) ) ) {
2001-10-08 19:01:59 +04:00
if ( sgml )
2001-11-04 23:03:38 +03:00
i + = 2 ;
2001-10-08 19:01:59 +04:00
else
i + = 3 ;
2001-08-21 14:56:31 +04:00
add + + ;
} else if ( ( ! strcmp ( argv [ i ] , " -del " ) ) | |
( ! strcmp ( argv [ i ] , " --del " ) ) ) {
i + = 1 ;
del + + ;
2001-08-20 04:08:40 +04:00
} else {
fprintf ( stderr , " Unknown option %s \n " , argv [ i ] ) ;
usage ( argv [ 0 ] ) ;
return ( 1 ) ;
}
}
for ( i = 1 ; i < argc ; i + + ) {
2001-08-21 14:56:31 +04:00
if ( ( ! strcmp ( argv [ i ] , " -add " ) ) | |
( ! strcmp ( argv [ i ] , " --add " ) ) ) {
2001-10-08 19:01:59 +04:00
if ( sgml )
2001-11-04 23:03:38 +03:00
i + = 2 ;
2001-10-08 19:01:59 +04:00
else
i + = 3 ;
2001-08-21 14:56:31 +04:00
continue ;
} else if ( ( ! strcmp ( argv [ i ] , " -del " ) ) | |
( ! strcmp ( argv [ i ] , " --del " ) ) ) {
i + = 1 ;
2004-08-15 01:46:31 +04:00
/* No catalog entry specified */
if ( i = = argc | | ( sgml & & i + 1 = = argc ) ) {
fprintf ( stderr , " No catalog entry specified to remove from \n " ) ;
usage ( argv [ 0 ] ) ;
return ( 1 ) ;
}
2001-08-20 04:08:40 +04:00
continue ;
2001-08-21 14:56:31 +04:00
} else if ( argv [ i ] [ 0 ] = = ' - ' )
continue ;
2017-10-19 14:27:29 +03:00
if ( filename = = NULL & & argv [ i ] [ 0 ] = = ' \0 ' ) {
/* Interpret empty-string catalog specification as
a shortcut for a default system catalog . */
xmlInitializeCatalog ( ) ;
} else {
filename = argv [ i ] ;
2001-10-08 19:01:59 +04:00
ret = xmlLoadCatalog ( argv [ i ] ) ;
2001-11-04 23:03:38 +03:00
if ( ( ret < 0 ) & & ( create ) ) {
xmlCatalogAdd ( BAD_CAST " catalog " , BAD_CAST argv [ i ] , NULL ) ;
}
2017-10-19 14:27:29 +03:00
}
2001-08-21 14:56:31 +04:00
break ;
}
2001-08-25 17:33:14 +04:00
if ( convert )
ret = xmlCatalogConvert ( ) ;
2001-08-21 14:56:31 +04:00
2001-08-25 17:33:14 +04:00
if ( ( add ) | | ( del ) ) {
2001-08-21 14:56:31 +04:00
for ( i = 1 ; i < argc ; i + + ) {
if ( ! strcmp ( argv [ i ] , " - " ) )
break ;
if ( argv [ i ] [ 0 ] ! = ' - ' )
continue ;
2001-11-04 23:03:38 +03:00
if ( strcmp ( argv [ i ] , " -add " ) & & strcmp ( argv [ i ] , " --add " ) & &
strcmp ( argv [ i ] , " -del " ) & & strcmp ( argv [ i ] , " --del " ) )
continue ;
if ( sgml ) {
/*
2001-12-31 19:16:02 +03:00
* Maintenance of SGML catalogs .
2001-11-04 23:03:38 +03:00
*/
xmlCatalogPtr catal = NULL ;
xmlCatalogPtr super = NULL ;
catal = xmlLoadSGMLSuperCatalog ( argv [ i + 1 ] ) ;
if ( ( ! strcmp ( argv [ i ] , " -add " ) ) | |
( ! strcmp ( argv [ i ] , " --add " ) ) ) {
if ( catal = = NULL )
catal = xmlNewCatalog ( 1 ) ;
xmlACatalogAdd ( catal , BAD_CAST " CATALOG " ,
BAD_CAST argv [ i + 2 ] , NULL ) ;
2004-08-15 01:46:31 +04:00
if ( ! no_super_update ) {
super = xmlLoadSGMLSuperCatalog ( XML_SGML_DEFAULT_CATALOG ) ;
if ( super = = NULL )
super = xmlNewCatalog ( 1 ) ;
xmlACatalogAdd ( super , BAD_CAST " CATALOG " ,
BAD_CAST argv [ i + 1 ] , NULL ) ;
}
2001-10-08 19:01:59 +04:00
} else {
2001-11-04 23:03:38 +03:00
if ( catal ! = NULL )
ret = xmlACatalogRemove ( catal , BAD_CAST argv [ i + 2 ] ) ;
2001-10-08 19:01:59 +04:00
else
2001-11-04 23:03:38 +03:00
ret = - 1 ;
2002-01-20 15:42:06 +03:00
if ( ret < 0 ) {
fprintf ( stderr , " Failed to remove entry from %s \n " ,
2001-11-04 23:03:38 +03:00
argv [ i + 1 ] ) ;
2002-01-20 15:42:06 +03:00
exit_value = 1 ;
}
2004-08-15 01:46:31 +04:00
if ( ( ! no_super_update ) & & ( noout ) & & ( catal ! = NULL ) & &
2001-11-04 23:03:38 +03:00
( xmlCatalogIsEmpty ( catal ) ) ) {
super = xmlLoadSGMLSuperCatalog (
XML_SGML_DEFAULT_CATALOG ) ;
if ( super ! = NULL ) {
ret = xmlACatalogRemove ( super ,
BAD_CAST argv [ i + 1 ] ) ;
2002-01-20 15:42:06 +03:00
if ( ret < 0 ) {
2001-11-04 23:03:38 +03:00
fprintf ( stderr ,
2002-01-20 15:42:06 +03:00
" Failed to remove entry from %s \n " ,
2001-11-04 23:03:38 +03:00
XML_SGML_DEFAULT_CATALOG ) ;
2002-01-20 15:42:06 +03:00
exit_value = 1 ;
}
2001-11-04 23:03:38 +03:00
}
}
}
if ( noout ) {
FILE * out ;
if ( xmlCatalogIsEmpty ( catal ) ) {
2001-11-05 01:19:27 +03:00
remove ( argv [ i + 1 ] ) ;
2001-11-04 23:03:38 +03:00
} else {
out = fopen ( argv [ i + 1 ] , " w " ) ;
if ( out = = NULL ) {
fprintf ( stderr , " could not open %s for saving \n " ,
argv [ i + 1 ] ) ;
2002-01-20 15:42:06 +03:00
exit_value = 2 ;
2001-11-04 23:03:38 +03:00
noout = 0 ;
} else {
xmlACatalogDump ( catal , out ) ;
fclose ( out ) ;
}
}
2004-08-15 01:46:31 +04:00
if ( ! no_super_update & & super ! = NULL ) {
2001-11-04 23:03:38 +03:00
if ( xmlCatalogIsEmpty ( super ) ) {
2001-11-05 01:19:27 +03:00
remove ( XML_SGML_DEFAULT_CATALOG ) ;
2001-11-04 23:03:38 +03:00
} else {
out = fopen ( XML_SGML_DEFAULT_CATALOG , " w " ) ;
if ( out = = NULL ) {
fprintf ( stderr ,
" could not open %s for saving \n " ,
XML_SGML_DEFAULT_CATALOG ) ;
2002-01-20 15:42:06 +03:00
exit_value = 2 ;
2001-11-04 23:03:38 +03:00
noout = 0 ;
} else {
2012-09-11 09:26:36 +04:00
2001-11-04 23:03:38 +03:00
xmlACatalogDump ( super , out ) ;
fclose ( out ) ;
}
}
}
} else {
xmlACatalogDump ( catal , stdout ) ;
}
i + = 2 ;
} else {
if ( ( ! strcmp ( argv [ i ] , " -add " ) ) | |
( ! strcmp ( argv [ i ] , " --add " ) ) ) {
if ( ( argv [ i + 3 ] = = NULL ) | | ( argv [ i + 3 ] [ 0 ] = = 0 ) )
ret = xmlCatalogAdd ( BAD_CAST argv [ i + 1 ] , NULL ,
BAD_CAST argv [ i + 2 ] ) ;
else
ret = xmlCatalogAdd ( BAD_CAST argv [ i + 1 ] ,
BAD_CAST argv [ i + 2 ] ,
BAD_CAST argv [ i + 3 ] ) ;
2002-01-20 15:42:06 +03:00
if ( ret ! = 0 ) {
2001-11-04 23:03:38 +03:00
printf ( " add command failed \n " ) ;
2002-01-20 15:42:06 +03:00
exit_value = 3 ;
}
2001-11-04 23:03:38 +03:00
i + = 3 ;
} else if ( ( ! strcmp ( argv [ i ] , " -del " ) ) | |
( ! strcmp ( argv [ i ] , " --del " ) ) ) {
ret = xmlCatalogRemove ( BAD_CAST argv [ i + 1 ] ) ;
2002-01-20 15:42:06 +03:00
if ( ret < 0 ) {
fprintf ( stderr , " Failed to remove entry %s \n " ,
argv [ i + 1 ] ) ;
exit_value = 1 ;
}
2001-11-04 23:03:38 +03:00
i + = 1 ;
2001-10-08 19:01:59 +04:00
}
2001-08-21 14:56:31 +04:00
}
}
2012-09-11 09:26:36 +04:00
2001-08-22 04:06:49 +04:00
} else if ( shell ) {
2001-08-20 04:08:40 +04:00
usershell ( ) ;
2001-08-22 04:06:49 +04:00
} else {
for ( i + + ; i < argc ; i + + ) {
xmlURIPtr uri ;
xmlChar * ans ;
2012-09-11 09:26:36 +04:00
2001-08-22 04:06:49 +04:00
uri = xmlParseURI ( argv [ i ] ) ;
if ( uri = = NULL ) {
ans = xmlCatalogResolvePublic ( ( const xmlChar * ) argv [ i ] ) ;
if ( ans = = NULL ) {
printf ( " No entry for PUBLIC %s \n " , argv [ i ] ) ;
2002-01-20 15:42:06 +03:00
exit_value = 4 ;
2001-08-22 04:06:49 +04:00
} else {
2003-08-05 19:52:22 +04:00
printf ( " %s \n " , ( char * ) ans ) ;
2001-08-22 04:06:49 +04:00
xmlFree ( ans ) ;
}
} else {
xmlFreeURI ( uri ) ;
ans = xmlCatalogResolveSystem ( ( const xmlChar * ) argv [ i ] ) ;
if ( ans = = NULL ) {
printf ( " No entry for SYSTEM %s \n " , argv [ i ] ) ;
2004-03-04 17:02:13 +03:00
ans = xmlCatalogResolveURI ( ( const xmlChar * ) argv [ i ] ) ;
if ( ans = = NULL ) {
printf ( " No entry for URI %s \n " , argv [ i ] ) ;
exit_value = 4 ;
} else {
printf ( " %s \n " , ( char * ) ans ) ;
xmlFree ( ans ) ;
}
2001-08-22 04:06:49 +04:00
} else {
2003-08-05 19:52:22 +04:00
printf ( " %s \n " , ( char * ) ans ) ;
2001-08-22 04:06:49 +04:00
xmlFree ( ans ) ;
}
}
}
2001-08-20 04:08:40 +04:00
}
2001-11-04 23:03:38 +03:00
if ( ( ! sgml ) & & ( ( add ) | | ( del ) | | ( create ) | | ( convert ) ) ) {
2003-12-12 17:56:03 +03:00
if ( noout & & filename & & * filename ) {
2001-08-23 03:44:09 +04:00
FILE * out ;
out = fopen ( filename , " w " ) ;
if ( out = = NULL ) {
fprintf ( stderr , " could not open %s for saving \n " , filename ) ;
2002-01-20 15:42:06 +03:00
exit_value = 2 ;
2001-08-23 03:44:09 +04:00
noout = 0 ;
} else {
xmlCatalogDump ( out ) ;
}
} else {
xmlCatalogDump ( stdout ) ;
}
}
2001-08-20 04:08:40 +04:00
/*
* Cleanup and check for memory leaks
*/
xmlCleanupParser ( ) ;
xmlMemoryDump ( ) ;
2002-01-20 15:42:06 +03:00
return ( exit_value ) ;
2001-08-20 04:08:40 +04:00
}
# else
2003-09-29 17:20:24 +04:00
int main ( int argc ATTRIBUTE_UNUSED , char * * argv ATTRIBUTE_UNUSED ) {
fprintf ( stderr , " libxml was not compiled with catalog and output support \n " ) ;
2001-08-20 04:08:40 +04:00
return ( 1 ) ;
}
# endif