blob: 37969f01127f63d975c869f7e45a1c5ba6fa22e7 [file] [log] [blame]
Daniel Veillard344cee72001-08-20 00:08:40 +00001/*
2 * xmlcatalog.c : a small utility program to handle XML catalogs
3 *
4 * See Copyright for the status of this software.
5 *
6 * daniel@veillard.com
7 */
8
9#include "libxml.h"
10
11#include <string.h>
12#include <stdio.h>
13#include <stdarg.h>
14
Daniel Veillardc0631a62001-09-20 13:56:06 +000015#ifdef HAVE_STDLIB_H
16#include <stdlib.h>
17#endif
18
Bjorn Reese45029602001-08-21 09:23:53 +000019#ifdef HAVE_LIBREADLINE
20#include <readline/readline.h>
21#ifdef HAVE_LIBHISTORY
22#include <readline/history.h>
23#endif
24#endif
25
Daniel Veillard344cee72001-08-20 00:08:40 +000026#include <libxml/xmlmemory.h>
27#include <libxml/uri.h>
28#include <libxml/catalog.h>
29#include <libxml/parser.h>
Daniel Veillard3c01b1d2001-10-17 15:58:35 +000030#include <libxml/globals.h>
Daniel Veillard344cee72001-08-20 00:08:40 +000031
32static int shell = 0;
Daniel Veillard82d75332001-10-08 15:01:59 +000033static int sgml = 0;
Daniel Veillard344cee72001-08-20 00:08:40 +000034static int noout = 0;
Daniel Veillarde7ead2d2001-08-22 23:44:09 +000035static int create = 0;
Daniel Veillardcda96922001-08-21 10:56:31 +000036static int add = 0;
37static int del = 0;
Daniel Veillard6c5f9d12001-08-25 13:33:14 +000038static int convert = 0;
Daniel Veillard344cee72001-08-20 00:08:40 +000039static int verbose = 0;
Daniel Veillardcda96922001-08-21 10:56:31 +000040static char *filename;
Daniel Veillard344cee72001-08-20 00:08:40 +000041
42#ifdef LIBXML_CATALOG_ENABLED
Daniel Veillardcd21dc72001-11-04 20:03:38 +000043
44#define XML_SGML_DEFAULT_CATALOG "/etc/sgml/catalog"
45
Daniel Veillard344cee72001-08-20 00:08:40 +000046/************************************************************************
47 * *
48 * Shell Interface *
49 * *
50 ************************************************************************/
51/**
52 * xmlShellReadline:
53 * @prompt: the prompt value
54 *
55 * Read a string
56 *
57 * Returns a pointer to it or NULL on EOF the caller is expected to
58 * free the returned string.
59 */
60static char *
61xmlShellReadline(const char *prompt) {
62#ifdef HAVE_LIBREADLINE
63 char *line_read;
64
65 /* Get a line from the user. */
66 line_read = readline (prompt);
67
68 /* If the line has any text in it, save it on the history. */
69 if (line_read && *line_read)
70 add_history (line_read);
71
72 return (line_read);
73#else
74 char line_read[501];
Daniel Veillard572577e2002-01-18 16:23:55 +000075 char *ret;
76 int len;
Daniel Veillard344cee72001-08-20 00:08:40 +000077
78 if (prompt != NULL)
79 fprintf(stdout, "%s", prompt);
80 if (!fgets(line_read, 500, stdin))
81 return(NULL);
82 line_read[500] = 0;
Daniel Veillard572577e2002-01-18 16:23:55 +000083 len = strlen(line_read);
84 ret = (char *) malloc(len + 1);
85 if (ret != NULL) {
86 memcpy (ret, line_read, len + 1);
87 }
88 return(ret);
Daniel Veillard344cee72001-08-20 00:08:40 +000089#endif
90}
91
Daniel Veillard344cee72001-08-20 00:08:40 +000092static void usershell(void) {
93 char *cmdline = NULL, *cur;
94 int nbargs;
95 char command[100];
96 char arg[400];
Daniel Veillardcda96922001-08-21 10:56:31 +000097 char *argv[20];
98 int i, ret;
Daniel Veillardcda96922001-08-21 10:56:31 +000099 xmlChar *ans;
Daniel Veillard344cee72001-08-20 00:08:40 +0000100
101 while (1) {
102 cmdline = xmlShellReadline("> ");
103 if (cmdline == NULL)
104 return;
105
106 /*
107 * Parse the command itself
108 */
109 cur = cmdline;
110 nbargs = 0;
111 while ((*cur == ' ') || (*cur == '\t')) cur++;
112 i = 0;
113 while ((*cur != ' ') && (*cur != '\t') &&
114 (*cur != '\n') && (*cur != '\r')) {
115 if (*cur == 0)
116 break;
117 command[i++] = *cur++;
118 }
119 command[i] = 0;
120 if (i == 0) continue;
121 nbargs++;
122
123 /*
Daniel Veillardcda96922001-08-21 10:56:31 +0000124 * Parse the argument string
Daniel Veillard344cee72001-08-20 00:08:40 +0000125 */
Daniel Veillardcda96922001-08-21 10:56:31 +0000126 memset(arg, 0, sizeof(arg));
Daniel Veillard344cee72001-08-20 00:08:40 +0000127 while ((*cur == ' ') || (*cur == '\t')) cur++;
128 i = 0;
129 while ((*cur != '\n') && (*cur != '\r') && (*cur != 0)) {
130 if (*cur == 0)
131 break;
132 arg[i++] = *cur++;
133 }
134 arg[i] = 0;
135 if (i != 0)
136 nbargs++;
137
138 /*
Daniel Veillardcda96922001-08-21 10:56:31 +0000139 * Parse the arguments
140 */
141 i = 0;
142 nbargs = 0;
143 cur = arg;
144 memset(argv, 0, sizeof(argv));
145 while (*cur != 0) {
146 while ((*cur == ' ') || (*cur == '\t')) cur++;
147 if (*cur == '\'') {
148 cur++;
149 argv[i] = cur;
150 while ((*cur != 0) && (*cur != '\'')) cur++;
151 if (*cur == '\'') {
152 *cur = 0;
153 nbargs++;
154 i++;
155 cur++;
156 }
157 } else if (*cur == '"') {
158 cur++;
159 argv[i] = cur;
160 while ((*cur != 0) && (*cur != '"')) cur++;
161 if (*cur == '"') {
162 *cur = 0;
163 nbargs++;
164 i++;
165 cur++;
166 }
167 } else {
168 argv[i] = cur;
169 while ((*cur != 0) && (*cur != ' ') && (*cur != '\t'))
170 cur++;
171 *cur = 0;
172 nbargs++;
173 i++;
174 cur++;
175 }
176 }
177
178 /*
Daniel Veillard344cee72001-08-20 00:08:40 +0000179 * start interpreting the command
180 */
181 if (!strcmp(command, "exit"))
182 break;
183 if (!strcmp(command, "quit"))
184 break;
185 if (!strcmp(command, "bye"))
186 break;
187 if (!strcmp(command, "public")) {
Daniel Veillardcda96922001-08-21 10:56:31 +0000188 if (nbargs != 1) {
189 printf("public requires 1 arguments\n");
Daniel Veillard344cee72001-08-20 00:08:40 +0000190 } else {
Daniel Veillarde2940dd2001-08-22 00:06:49 +0000191 ans = xmlCatalogResolvePublic((const xmlChar *) argv[0]);
192 if (ans == NULL) {
Daniel Veillardcda96922001-08-21 10:56:31 +0000193 printf("No entry for PUBLIC %s\n", argv[0]);
194 } else {
Daniel Veillarde2940dd2001-08-22 00:06:49 +0000195 printf("%s\n", ans);
196 xmlFree(ans);
Daniel Veillardcda96922001-08-21 10:56:31 +0000197 }
Daniel Veillard344cee72001-08-20 00:08:40 +0000198 }
199 } else if (!strcmp(command, "system")) {
Daniel Veillardcda96922001-08-21 10:56:31 +0000200 if (nbargs != 1) {
201 printf("system requires 1 arguments\n");
Daniel Veillard344cee72001-08-20 00:08:40 +0000202 } else {
Daniel Veillarde2940dd2001-08-22 00:06:49 +0000203 ans = xmlCatalogResolveSystem((const xmlChar *) argv[0]);
204 if (ans == NULL) {
Daniel Veillardcda96922001-08-21 10:56:31 +0000205 printf("No entry for SYSTEM %s\n", argv[0]);
206 } else {
Daniel Veillarde2940dd2001-08-22 00:06:49 +0000207 printf("%s\n", ans);
208 xmlFree(ans);
Daniel Veillardcda96922001-08-21 10:56:31 +0000209 }
210 }
211 } else if (!strcmp(command, "add")) {
Daniel Veillard82d75332001-10-08 15:01:59 +0000212 if (sgml) {
213 if (nbargs != 1) {
214 printf("add requires 1 argument\n");
215 } else {
216 ret = xmlCatalogAdd(BAD_CAST "sgmlcatalog", NULL,
217 BAD_CAST argv[0]);
218 }
Daniel Veillardcda96922001-08-21 10:56:31 +0000219 } else {
Daniel Veillard82d75332001-10-08 15:01:59 +0000220 if ((nbargs != 3) && (nbargs != 2)) {
221 printf("add requires 2 or 3 arguments\n");
222 } else {
223 if (argv[2] == NULL)
224 ret = xmlCatalogAdd(BAD_CAST argv[0], NULL,
225 BAD_CAST argv[1]);
226 else
227 ret = xmlCatalogAdd(BAD_CAST argv[0], BAD_CAST argv[1],
228 BAD_CAST argv[2]);
229 if (ret != 0)
230 printf("add command failed\n");
231 }
Daniel Veillardcda96922001-08-21 10:56:31 +0000232 }
233 } else if (!strcmp(command, "del")) {
234 if (nbargs != 1) {
235 printf("del requires 1\n");
236 } else {
237 ret = xmlCatalogRemove(BAD_CAST argv[0]);
238 if (ret <= 0)
239 printf("del command failed\n");
240
241 }
242 } else if (!strcmp(command, "resolve")) {
243 if (nbargs != 2) {
244 printf("resolve requires 2 arguments\n");
245 } else {
246 ans = xmlCatalogResolve(BAD_CAST argv[0],
247 BAD_CAST argv[1]);
248 if (ans == NULL) {
249 printf("Resolver failed to find an answer\n");
250 } else {
251 printf("%s\n", ans);
252 xmlFree(ans);
253 }
Daniel Veillard344cee72001-08-20 00:08:40 +0000254 }
255 } else if (!strcmp(command, "dump")) {
Daniel Veillardcda96922001-08-21 10:56:31 +0000256 if (nbargs != 0) {
257 printf("dump has no arguments\n");
258 } else {
259 xmlCatalogDump(stdout);
260 }
Daniel Veillarde2940dd2001-08-22 00:06:49 +0000261 } else if (!strcmp(command, "debug")) {
262 if (nbargs != 0) {
263 printf("debug has no arguments\n");
264 } else {
265 verbose++;
266 xmlCatalogSetDebug(verbose);
267 }
268 } else if (!strcmp(command, "quiet")) {
269 if (nbargs != 0) {
270 printf("quiet has no arguments\n");
271 } else {
272 if (verbose > 0)
273 verbose--;
274 xmlCatalogSetDebug(verbose);
275 }
Daniel Veillard344cee72001-08-20 00:08:40 +0000276 } else {
277 if (strcmp(command, "help")) {
278 printf("Unrecognized command %s\n", command);
279 }
280 printf("Commands available:\n");
281 printf("\tpublic PublicID: make a PUBLIC identifier lookup\n");
282 printf("\tsystem SystemID: make a SYSTEM identifier lookup\n");
Daniel Veillardcda96922001-08-21 10:56:31 +0000283 printf("\tresolve PublicID SystemID: do a full resolver lookup\n");
284 printf("\tadd 'type' 'orig' 'replace' : add an entry\n");
285 printf("\tdel 'values' : remove values\n");
Daniel Veillard344cee72001-08-20 00:08:40 +0000286 printf("\tdump: print the current catalog state\n");
Daniel Veillarde2940dd2001-08-22 00:06:49 +0000287 printf("\tdebug: increase the verbosity level\n");
288 printf("\tquiet: decrease the verbosity level\n");
Daniel Veillard344cee72001-08-20 00:08:40 +0000289 printf("\texit: quit the shell\n");
290 }
291 free(cmdline); /* not xmlFree here ! */
292 }
293}
294
295/************************************************************************
296 * *
297 * Main *
298 * *
299 ************************************************************************/
300static void usage(const char *name) {
Daniel Veillarde2940dd2001-08-22 00:06:49 +0000301 printf("Usage : %s [options] catalogfile entities...\n", name);
302 printf("\tParse the catalog file and query it for the entities\n");
Daniel Veillardcd21dc72001-11-04 20:03:38 +0000303 printf("\t--sgml : handle SGML Super catalogs for --add and --del\n");
Daniel Veillard344cee72001-08-20 00:08:40 +0000304 printf("\t--shell : run a shell allowing interactive queries\n");
Daniel Veillarde7ead2d2001-08-22 23:44:09 +0000305 printf("\t--create : create a new catalog\n");
Daniel Veillardcda96922001-08-21 10:56:31 +0000306 printf("\t--add 'type' 'orig' 'replace' : add an entry\n");
307 printf("\t--del 'values' : remove values\n");
308 printf("\t--noout: avoid dumping the result on stdout\n");
309 printf("\t used with add or del, it saves the catalog changes\n");
Daniel Veillardcd21dc72001-11-04 20:03:38 +0000310 printf("\t and with --sgml it also updates the super catalog\n");
Daniel Veillard344cee72001-08-20 00:08:40 +0000311 printf("\t-v --verbose : provide debug informations\n");
312}
313int main(int argc, char **argv) {
314 int i;
Daniel Veillard6c5f9d12001-08-25 13:33:14 +0000315 int ret;
Daniel Veillard0f5f1622002-01-20 12:42:06 +0000316 int exit_value = 0;
Daniel Veillard6c5f9d12001-08-25 13:33:14 +0000317
Daniel Veillard344cee72001-08-20 00:08:40 +0000318
319 if (argc <= 1) {
320 usage(argv[0]);
321 return(1);
322 }
323
324 LIBXML_TEST_VERSION
325 for (i = 1; i < argc ; i++) {
326 if (!strcmp(argv[i], "-"))
327 break;
328
329 if (argv[i][0] != '-')
Daniel Veillarde2940dd2001-08-22 00:06:49 +0000330 break;
Daniel Veillard344cee72001-08-20 00:08:40 +0000331 if ((!strcmp(argv[i], "-verbose")) ||
332 (!strcmp(argv[i], "-v")) ||
333 (!strcmp(argv[i], "--verbose"))) {
334 verbose++;
335 xmlCatalogSetDebug(verbose);
Daniel Veillardcda96922001-08-21 10:56:31 +0000336 } else if ((!strcmp(argv[i], "-noout")) ||
337 (!strcmp(argv[i], "--noout"))) {
338 noout = 1;
Daniel Veillard344cee72001-08-20 00:08:40 +0000339 } else if ((!strcmp(argv[i], "-shell")) ||
340 (!strcmp(argv[i], "--shell"))) {
341 shell++;
342 noout = 1;
Daniel Veillard82d75332001-10-08 15:01:59 +0000343 } else if ((!strcmp(argv[i], "-sgml")) ||
344 (!strcmp(argv[i], "--sgml"))) {
345 sgml++;
Daniel Veillarde7ead2d2001-08-22 23:44:09 +0000346 } else if ((!strcmp(argv[i], "-create")) ||
347 (!strcmp(argv[i], "--create"))) {
348 create++;
Daniel Veillard6c5f9d12001-08-25 13:33:14 +0000349 } else if ((!strcmp(argv[i], "-convert")) ||
350 (!strcmp(argv[i], "--convert"))) {
351 convert++;
Daniel Veillardcda96922001-08-21 10:56:31 +0000352 } else if ((!strcmp(argv[i], "-add")) ||
353 (!strcmp(argv[i], "--add"))) {
Daniel Veillard82d75332001-10-08 15:01:59 +0000354 if (sgml)
Daniel Veillardcd21dc72001-11-04 20:03:38 +0000355 i += 2;
Daniel Veillard82d75332001-10-08 15:01:59 +0000356 else
357 i += 3;
Daniel Veillardcda96922001-08-21 10:56:31 +0000358 add++;
359 } else if ((!strcmp(argv[i], "-del")) ||
360 (!strcmp(argv[i], "--del"))) {
361 i += 1;
362 del++;
Daniel Veillard344cee72001-08-20 00:08:40 +0000363 } else {
364 fprintf(stderr, "Unknown option %s\n", argv[i]);
365 usage(argv[0]);
366 return(1);
367 }
368 }
369
370 for (i = 1; i < argc; i++) {
Daniel Veillardcda96922001-08-21 10:56:31 +0000371 if ((!strcmp(argv[i], "-add")) ||
372 (!strcmp(argv[i], "--add"))) {
Daniel Veillard82d75332001-10-08 15:01:59 +0000373 if (sgml)
Daniel Veillardcd21dc72001-11-04 20:03:38 +0000374 i += 2;
Daniel Veillard82d75332001-10-08 15:01:59 +0000375 else
376 i += 3;
Daniel Veillard344cee72001-08-20 00:08:40 +0000377 continue;
Daniel Veillardcda96922001-08-21 10:56:31 +0000378 } else if ((!strcmp(argv[i], "-del")) ||
379 (!strcmp(argv[i], "--del"))) {
380 i += 1;
381 continue;
382 } else if (argv[i][0] == '-')
383 continue;
384 filename = argv[i];
Daniel Veillardcd21dc72001-11-04 20:03:38 +0000385 if (!sgml) {
Daniel Veillard82d75332001-10-08 15:01:59 +0000386 ret = xmlLoadCatalog(argv[i]);
Daniel Veillardcd21dc72001-11-04 20:03:38 +0000387 if ((ret < 0) && (create)) {
388 xmlCatalogAdd(BAD_CAST "catalog", BAD_CAST argv[i], NULL);
389 }
Daniel Veillarde7ead2d2001-08-22 23:44:09 +0000390 }
Daniel Veillardcda96922001-08-21 10:56:31 +0000391 break;
392 }
393
Daniel Veillard6c5f9d12001-08-25 13:33:14 +0000394 if (convert)
395 ret = xmlCatalogConvert();
Daniel Veillardcda96922001-08-21 10:56:31 +0000396
Daniel Veillard6c5f9d12001-08-25 13:33:14 +0000397 if ((add) || (del)) {
Daniel Veillardcda96922001-08-21 10:56:31 +0000398 for (i = 1; i < argc ; i++) {
399 if (!strcmp(argv[i], "-"))
400 break;
401
402 if (argv[i][0] != '-')
403 continue;
Daniel Veillardcd21dc72001-11-04 20:03:38 +0000404 if (strcmp(argv[i], "-add") && strcmp(argv[i], "--add") &&
405 strcmp(argv[i], "-del") && strcmp(argv[i], "--del"))
406 continue;
407
408 if (sgml) {
409 /*
Daniel Veillardcbaf3992001-12-31 16:16:02 +0000410 * Maintenance of SGML catalogs.
Daniel Veillardcd21dc72001-11-04 20:03:38 +0000411 */
412 xmlCatalogPtr catal = NULL;
413 xmlCatalogPtr super = NULL;
414
415 catal = xmlLoadSGMLSuperCatalog(argv[i + 1]);
416
417 if ((!strcmp(argv[i], "-add")) ||
418 (!strcmp(argv[i], "--add"))) {
419 if (catal == NULL)
420 catal = xmlNewCatalog(1);
421 super = xmlLoadSGMLSuperCatalog(XML_SGML_DEFAULT_CATALOG);
422 if (super == NULL)
423 super = xmlNewCatalog(1);
424
425 xmlACatalogAdd(catal, BAD_CAST "CATALOG",
426 BAD_CAST argv[i + 2], NULL);
427 xmlACatalogAdd(super, BAD_CAST "CATALOG",
428 BAD_CAST argv[i + 1], NULL);
Daniel Veillard82d75332001-10-08 15:01:59 +0000429 } else {
Daniel Veillardcd21dc72001-11-04 20:03:38 +0000430 if (catal != NULL)
431 ret = xmlACatalogRemove(catal, BAD_CAST argv[i + 2]);
Daniel Veillard82d75332001-10-08 15:01:59 +0000432 else
Daniel Veillardcd21dc72001-11-04 20:03:38 +0000433 ret = -1;
Daniel Veillard0f5f1622002-01-20 12:42:06 +0000434 if (ret < 0) {
435 fprintf(stderr, "Failed to remove entry from %s\n",
Daniel Veillardcd21dc72001-11-04 20:03:38 +0000436 argv[i + 1]);
Daniel Veillard0f5f1622002-01-20 12:42:06 +0000437 exit_value = 1;
438 }
Daniel Veillardcd21dc72001-11-04 20:03:38 +0000439 if ((noout) && (catal != NULL) &&
440 (xmlCatalogIsEmpty(catal))) {
441 super = xmlLoadSGMLSuperCatalog(
442 XML_SGML_DEFAULT_CATALOG);
443 if (super != NULL) {
444 ret = xmlACatalogRemove(super,
445 BAD_CAST argv[i + 1]);
Daniel Veillard0f5f1622002-01-20 12:42:06 +0000446 if (ret < 0) {
Daniel Veillardcd21dc72001-11-04 20:03:38 +0000447 fprintf(stderr,
Daniel Veillard0f5f1622002-01-20 12:42:06 +0000448 "Failed to remove entry from %s\n",
Daniel Veillardcd21dc72001-11-04 20:03:38 +0000449 XML_SGML_DEFAULT_CATALOG);
Daniel Veillard0f5f1622002-01-20 12:42:06 +0000450 exit_value = 1;
451 }
Daniel Veillardcd21dc72001-11-04 20:03:38 +0000452 }
453 }
Daniel Veillard82d75332001-10-08 15:01:59 +0000454 }
Daniel Veillardcd21dc72001-11-04 20:03:38 +0000455 if (noout) {
456 FILE *out;
457
458 if (xmlCatalogIsEmpty(catal)) {
Daniel Veillard6eb17722001-11-04 22:19:27 +0000459 remove(argv[i + 1]);
Daniel Veillardcd21dc72001-11-04 20:03:38 +0000460 } else {
461 out = fopen(argv[i + 1], "w");
462 if (out == NULL) {
463 fprintf(stderr, "could not open %s for saving\n",
464 argv[i + 1]);
Daniel Veillard0f5f1622002-01-20 12:42:06 +0000465 exit_value = 2;
Daniel Veillardcd21dc72001-11-04 20:03:38 +0000466 noout = 0;
467 } else {
468 xmlACatalogDump(catal, out);
469 fclose(out);
470 }
471 }
472 if (super != NULL) {
473 if (xmlCatalogIsEmpty(super)) {
Daniel Veillard6eb17722001-11-04 22:19:27 +0000474 remove(XML_SGML_DEFAULT_CATALOG);
Daniel Veillardcd21dc72001-11-04 20:03:38 +0000475 } else {
476 out = fopen(XML_SGML_DEFAULT_CATALOG, "w");
477 if (out == NULL) {
478 fprintf(stderr,
479 "could not open %s for saving\n",
480 XML_SGML_DEFAULT_CATALOG);
Daniel Veillard0f5f1622002-01-20 12:42:06 +0000481 exit_value = 2;
Daniel Veillardcd21dc72001-11-04 20:03:38 +0000482 noout = 0;
483 } else {
484
485 xmlACatalogDump(super, out);
486 fclose(out);
487 }
488 }
489 }
490 } else {
491 xmlACatalogDump(catal, stdout);
492 }
493 i += 2;
494 } else {
495 if ((!strcmp(argv[i], "-add")) ||
496 (!strcmp(argv[i], "--add"))) {
497 if ((argv[i + 3] == NULL) || (argv[i + 3][0] == 0))
498 ret = xmlCatalogAdd(BAD_CAST argv[i + 1], NULL,
499 BAD_CAST argv[i + 2]);
500 else
501 ret = xmlCatalogAdd(BAD_CAST argv[i + 1],
502 BAD_CAST argv[i + 2],
503 BAD_CAST argv[i + 3]);
Daniel Veillard0f5f1622002-01-20 12:42:06 +0000504 if (ret != 0) {
Daniel Veillardcd21dc72001-11-04 20:03:38 +0000505 printf("add command failed\n");
Daniel Veillard0f5f1622002-01-20 12:42:06 +0000506 exit_value = 3;
507 }
Daniel Veillardcd21dc72001-11-04 20:03:38 +0000508 i += 3;
509 } else if ((!strcmp(argv[i], "-del")) ||
510 (!strcmp(argv[i], "--del"))) {
511 ret = xmlCatalogRemove(BAD_CAST argv[i + 1]);
Daniel Veillard0f5f1622002-01-20 12:42:06 +0000512 if (ret < 0) {
513 fprintf(stderr, "Failed to remove entry %s\n",
514 argv[i + 1]);
515 exit_value = 1;
516 }
Daniel Veillardcd21dc72001-11-04 20:03:38 +0000517 i += 1;
518 }
Daniel Veillardcda96922001-08-21 10:56:31 +0000519 }
520 }
521
Daniel Veillarde2940dd2001-08-22 00:06:49 +0000522 } else if (shell) {
Daniel Veillard344cee72001-08-20 00:08:40 +0000523 usershell();
Daniel Veillarde2940dd2001-08-22 00:06:49 +0000524 } else {
525 for (i++; i < argc; i++) {
526 xmlURIPtr uri;
527 xmlChar *ans;
528
529 uri = xmlParseURI(argv[i]);
530 if (uri == NULL) {
531 ans = xmlCatalogResolvePublic((const xmlChar *) argv[i]);
532 if (ans == NULL) {
533 printf("No entry for PUBLIC %s\n", argv[i]);
Daniel Veillard0f5f1622002-01-20 12:42:06 +0000534 exit_value = 4;
Daniel Veillarde2940dd2001-08-22 00:06:49 +0000535 } else {
536 printf("%s\n", ans);
537 xmlFree(ans);
538 }
539 } else {
540 xmlFreeURI(uri);
541 ans = xmlCatalogResolveSystem((const xmlChar *) argv[i]);
542 if (ans == NULL) {
543 printf("No entry for SYSTEM %s\n", argv[i]);
Daniel Veillard0f5f1622002-01-20 12:42:06 +0000544 exit_value = 4;
Daniel Veillarde2940dd2001-08-22 00:06:49 +0000545 } else {
546 printf("%s\n", ans);
547 xmlFree(ans);
548 }
549 }
550 }
Daniel Veillard344cee72001-08-20 00:08:40 +0000551 }
Daniel Veillardcd21dc72001-11-04 20:03:38 +0000552 if ((!sgml) && ((add) || (del) || (create) || (convert))) {
Daniel Veillarde7ead2d2001-08-22 23:44:09 +0000553 if (noout) {
554 FILE *out;
555
556 out = fopen(filename, "w");
557 if (out == NULL) {
558 fprintf(stderr, "could not open %s for saving\n", filename);
Daniel Veillard0f5f1622002-01-20 12:42:06 +0000559 exit_value = 2;
Daniel Veillarde7ead2d2001-08-22 23:44:09 +0000560 noout = 0;
561 } else {
562 xmlCatalogDump(out);
563 }
564 } else {
565 xmlCatalogDump(stdout);
566 }
567 }
Daniel Veillard344cee72001-08-20 00:08:40 +0000568
569 /*
570 * Cleanup and check for memory leaks
571 */
Daniel Veillard344cee72001-08-20 00:08:40 +0000572 xmlCleanupParser();
573 xmlMemoryDump();
Daniel Veillard0f5f1622002-01-20 12:42:06 +0000574 return(exit_value);
Daniel Veillard344cee72001-08-20 00:08:40 +0000575}
576#else
577int main(int argc, char **argv) {
578 fprintf(stderr, "libxml was not compiled with catalog support\n");
579 return(1);
580}
581#endif