/*
* 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>
#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#endif
#ifdef HAVE_LIBREADLINE
#include <readline/readline.h>
#ifdef HAVE_LIBHISTORY
#endif
#endif
#include <libxml/xmlmemory.h>
#if defined(LIBXML_CATALOG_ENABLED) && defined(LIBXML_OUTPUT_ENABLED)
static int shell = 0;
static int sgml = 0;
static int noout = 0;
static int create = 0;
static int add = 0;
static int del = 0;
static int convert = 0;
static int no_super_update = 0;
static int verbose = 0;
#ifndef XML_SGML_DEFAULT_CATALOG
#endif
/************************************************************************
* *
* Shell Interface *
* *
************************************************************************/
/**
* xmlShellReadline:
* @prompt: the prompt value
*
* Read a string
*
* Returns a pointer to it or NULL on EOF the caller is expected to
* free the returned string.
*/
static char *
#ifdef HAVE_LIBREADLINE
char *line_read;
/* Get a line from the user. */
/* If the line has any text in it, save it on the history. */
return (line_read);
#else
char line_read[501];
char *ret;
int len;
return(NULL);
line_read[500] = 0;
}
return(ret);
#endif
}
static void usershell(void) {
int nbargs;
int i, ret;
while (1) {
return;
/*
* Parse the command itself
*/
nbargs = 0;
i = 0;
if (*cur == 0)
break;
}
command[i] = 0;
if (i == 0) {
continue;
}
nbargs++;
/*
* Parse the argument string
*/
i = 0;
if (*cur == 0)
break;
}
arg[i] = 0;
if (i != 0)
nbargs++;
/*
* Parse the arguments
*/
i = 0;
nbargs = 0;
while (*cur != 0) {
if (*cur == '\'') {
cur++;
if (*cur == '\'') {
*cur = 0;
nbargs++;
i++;
cur++;
}
} else if (*cur == '"') {
cur++;
if (*cur == '"') {
*cur = 0;
nbargs++;
i++;
cur++;
}
} else {
cur++;
*cur = 0;
nbargs++;
i++;
cur++;
}
}
/*
* start interpreting the command
*/
break;
break;
break;
if (nbargs != 1) {
printf("public requires 1 arguments\n");
} else {
} else {
}
}
if (nbargs != 1) {
printf("system requires 1 arguments\n");
} else {
} else {
}
}
if (sgml) {
printf("add requires 2 or 3 arguments\n");
} else {
else
if (ret != 0)
printf("add command failed\n");
}
} else {
printf("add requires 2 or 3 arguments\n");
} else {
else
if (ret != 0)
printf("add command failed\n");
}
}
if (nbargs != 1) {
printf("del requires 1\n");
} else {
if (ret <= 0)
printf("del command failed\n");
}
if (nbargs != 2) {
printf("resolve requires 2 arguments\n");
} else {
printf("Resolver failed to find an answer\n");
} else {
}
}
if (nbargs != 0) {
printf("dump has no arguments\n");
} else {
}
if (nbargs != 0) {
printf("debug has no arguments\n");
} else {
verbose++;
}
if (nbargs != 0) {
printf("quiet has no arguments\n");
} else {
if (verbose > 0)
verbose--;
}
} else {
}
printf("Commands available:\n");
printf("\tpublic PublicID: make a PUBLIC identifier lookup\n");
printf("\tsystem SystemID: make a SYSTEM identifier lookup\n");
printf("\tresolve PublicID SystemID: do a full resolver lookup\n");
printf("\tadd 'type' 'orig' 'replace' : add an entry\n");
printf("\tdel 'values' : remove values\n");
printf("\tdump: print the current catalog state\n");
printf("\tdebug: increase the verbosity level\n");
printf("\tquiet: decrease the verbosity level\n");
printf("\texit: quit the shell\n");
}
}
}
/************************************************************************
* *
* Main *
* *
************************************************************************/
/* split into 2 printf's to avoid overly long string (gcc warning) */
printf("\
Usage : %s [options] catalogfile entities...\n\
\tParse the catalog file and query it for the entities\n\
\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\
\t--add 'entry' : add an SGML entry\n", name);
printf("\
\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\
\t-v --verbose : provide debug informations\n");
}
int i;
int ret;
int exit_value = 0;
if (argc <= 1) {
return(1);
}
for (i = 1; i < argc ; i++) {
break;
if (argv[i][0] != '-')
break;
verbose++;
noout = 1;
shell++;
noout = 1;
sgml++;
create++;
convert++;
if (sgml)
i += 2;
else
i += 3;
add++;
i += 1;
del++;
} else {
return(1);
}
}
for (i = 1; i < argc; i++) {
if (sgml)
i += 2;
else
i += 3;
continue;
i += 1;
/* No catalog entry specified */
return(1);
}
continue;
} else if (argv[i][0] == '-')
continue;
}
break;
}
if (convert)
ret = xmlCatalogConvert();
for (i = 1; i < argc ; i++) {
break;
if (argv[i][0] != '-')
continue;
continue;
if (sgml) {
/*
* Maintenance of SGML catalogs.
*/
if (!no_super_update) {
}
} else {
else
ret = -1;
if (ret < 0) {
argv[i + 1]);
exit_value = 1;
}
(xmlCatalogIsEmpty(catal))) {
if (ret < 0) {
"Failed to remove entry from %s\n",
exit_value = 1;
}
}
}
}
if (noout) {
if (xmlCatalogIsEmpty(catal)) {
} else {
argv[i + 1]);
exit_value = 2;
noout = 0;
} else {
}
}
if (xmlCatalogIsEmpty(super)) {
} else {
"could not open %s for saving\n",
exit_value = 2;
noout = 0;
} else {
}
}
}
} else {
}
i += 2;
} else {
else
if (ret != 0) {
printf("add command failed\n");
exit_value = 3;
}
i += 3;
if (ret < 0) {
argv[i + 1]);
exit_value = 1;
}
i += 1;
}
}
}
} else if (shell) {
usershell();
} else {
for (i++; i < argc; i++) {
exit_value = 4;
} else {
}
} else {
exit_value = 4;
} else {
}
} else {
}
}
}
}
exit_value = 2;
noout = 0;
} else {
}
} else {
}
}
/*
* Cleanup and check for memory leaks
*/
return(exit_value);
}
#else
return(1);
}
#endif