OLD | NEW |
1 /* | 1 /* |
2 * xmlcatalog.c : a small utility program to handle XML catalogs | 2 * xmlcatalog.c : a small utility program to handle XML catalogs |
3 * | 3 * |
4 * See Copyright for the status of this software. | 4 * See Copyright for the status of this software. |
5 * | 5 * |
6 * daniel@veillard.com | 6 * daniel@veillard.com |
7 */ | 7 */ |
8 | 8 |
9 #include "libxml.h" | 9 #include "libxml.h" |
10 | 10 |
(...skipping 29 matching lines...) Expand all Loading... |
40 static int no_super_update = 0; | 40 static int no_super_update = 0; |
41 static int verbose = 0; | 41 static int verbose = 0; |
42 static char *filename = NULL; | 42 static char *filename = NULL; |
43 | 43 |
44 | 44 |
45 #ifndef XML_SGML_DEFAULT_CATALOG | 45 #ifndef XML_SGML_DEFAULT_CATALOG |
46 #define XML_SGML_DEFAULT_CATALOG "/etc/sgml/catalog" | 46 #define XML_SGML_DEFAULT_CATALOG "/etc/sgml/catalog" |
47 #endif | 47 #endif |
48 | 48 |
49 /************************************************************************ | 49 /************************************************************************ |
50 * » » » » » » » » » * | 50 *» » » » » » » » » * |
51 * » » » Shell Interface»» » » » * | 51 *» » » Shell Interface»» » » » * |
52 * » » » » » » » » » * | 52 *» » » » » » » » » * |
53 ************************************************************************/ | 53 ************************************************************************/ |
54 /** | 54 /** |
55 * xmlShellReadline: | 55 * xmlShellReadline: |
56 * @prompt: the prompt value | 56 * @prompt: the prompt value |
57 * | 57 * |
58 * Read a string | 58 * Read a string |
59 * | 59 * |
60 * Returns a pointer to it or NULL on EOF the caller is expected to | 60 * Returns a pointer to it or NULL on EOF the caller is expected to |
61 * free the returned string. | 61 * free the returned string. |
62 */ | 62 */ |
63 static char * | 63 static char * |
64 xmlShellReadline(const char *prompt) { | 64 xmlShellReadline(const char *prompt) { |
65 #ifdef HAVE_LIBREADLINE | 65 #ifdef HAVE_LIBREADLINE |
66 char *line_read; | 66 char *line_read; |
67 | 67 |
68 /* Get a line from the user. */ | 68 /* Get a line from the user. */ |
69 line_read = readline (prompt); | 69 line_read = readline (prompt); |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 if (*cur == '\'') { | 150 if (*cur == '\'') { |
151 cur++; | 151 cur++; |
152 argv[i] = cur; | 152 argv[i] = cur; |
153 while ((*cur != 0) && (*cur != '\'')) cur++; | 153 while ((*cur != 0) && (*cur != '\'')) cur++; |
154 if (*cur == '\'') { | 154 if (*cur == '\'') { |
155 *cur = 0; | 155 *cur = 0; |
156 nbargs++; | 156 nbargs++; |
157 i++; | 157 i++; |
158 cur++; | 158 cur++; |
159 } | 159 } |
160 » } else if (*cur == '"') { | 160 » } else if (*cur == '"') { |
161 cur++; | 161 cur++; |
162 argv[i] = cur; | 162 argv[i] = cur; |
163 while ((*cur != 0) && (*cur != '"')) cur++; | 163 while ((*cur != 0) && (*cur != '"')) cur++; |
164 if (*cur == '"') { | 164 if (*cur == '"') { |
165 *cur = 0; | 165 *cur = 0; |
166 nbargs++; | 166 nbargs++; |
167 i++; | 167 i++; |
168 cur++; | 168 cur++; |
169 } | 169 } |
170 } else { | 170 } else { |
171 argv[i] = cur; | 171 argv[i] = cur; |
172 while ((*cur != 0) && (*cur != ' ') && (*cur != '\t')) | 172 while ((*cur != 0) && (*cur != ' ') && (*cur != '\t')) |
173 cur++; | 173 cur++; |
174 *cur = 0; | 174 *cur = 0; |
175 nbargs++; | 175 nbargs++; |
176 i++; | 176 i++; |
177 cur++; | 177 cur++; |
178 } | 178 } |
179 } | 179 } |
180 | 180 |
181 /* | 181 /* |
182 * start interpreting the command | 182 * start interpreting the command |
183 */ | 183 */ |
184 if (!strcmp(command, "exit")) | 184 » if (!strcmp(command, "exit") || |
| 185 » !strcmp(command, "quit") || |
| 186 » !strcmp(command, "bye")) { |
| 187 » free(cmdline); |
185 break; | 188 break; |
186 if (!strcmp(command, "quit")) | 189 » } |
187 » break; | 190 |
188 if (!strcmp(command, "bye")) | |
189 » break; | |
190 if (!strcmp(command, "public")) { | 191 if (!strcmp(command, "public")) { |
191 if (nbargs != 1) { | 192 if (nbargs != 1) { |
192 printf("public requires 1 arguments\n"); | 193 printf("public requires 1 arguments\n"); |
193 } else { | 194 } else { |
194 ans = xmlCatalogResolvePublic((const xmlChar *) argv[0]); | 195 ans = xmlCatalogResolvePublic((const xmlChar *) argv[0]); |
195 if (ans == NULL) { | 196 if (ans == NULL) { |
196 printf("No entry for PUBLIC %s\n", argv[0]); | 197 printf("No entry for PUBLIC %s\n", argv[0]); |
197 } else { | 198 } else { |
198 printf("%s\n", (char *) ans); | 199 printf("%s\n", (char *) ans); |
199 xmlFree(ans); | 200 xmlFree(ans); |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
289 printf("Commands available:\n"); | 290 printf("Commands available:\n"); |
290 printf("\tpublic PublicID: make a PUBLIC identifier lookup\n"); | 291 printf("\tpublic PublicID: make a PUBLIC identifier lookup\n"); |
291 printf("\tsystem SystemID: make a SYSTEM identifier lookup\n"); | 292 printf("\tsystem SystemID: make a SYSTEM identifier lookup\n"); |
292 printf("\tresolve PublicID SystemID: do a full resolver lookup\n"); | 293 printf("\tresolve PublicID SystemID: do a full resolver lookup\n"); |
293 printf("\tadd 'type' 'orig' 'replace' : add an entry\n"); | 294 printf("\tadd 'type' 'orig' 'replace' : add an entry\n"); |
294 printf("\tdel 'values' : remove values\n"); | 295 printf("\tdel 'values' : remove values\n"); |
295 printf("\tdump: print the current catalog state\n"); | 296 printf("\tdump: print the current catalog state\n"); |
296 printf("\tdebug: increase the verbosity level\n"); | 297 printf("\tdebug: increase the verbosity level\n"); |
297 printf("\tquiet: decrease the verbosity level\n"); | 298 printf("\tquiet: decrease the verbosity level\n"); |
298 printf("\texit: quit the shell\n"); | 299 printf("\texit: quit the shell\n"); |
299 » } | 300 » } |
300 free(cmdline); /* not xmlFree here ! */ | 301 free(cmdline); /* not xmlFree here ! */ |
301 } | 302 } |
302 } | 303 } |
303 | 304 |
304 /************************************************************************ | 305 /************************************************************************ |
305 * » » » » » » » » » * | 306 *» » » » » » » » » * |
306 * » » » Main» » » » » » * | 307 *» » » Main» » » » » » * |
307 * » » » » » » » » » * | 308 *» » » » » » » » » * |
308 ************************************************************************/ | 309 ************************************************************************/ |
309 static void usage(const char *name) { | 310 static void usage(const char *name) { |
310 /* split into 2 printf's to avoid overly long string (gcc warning) */ | 311 /* split into 2 printf's to avoid overly long string (gcc warning) */ |
311 printf("\ | 312 printf("\ |
312 Usage : %s [options] catalogfile entities...\n\ | 313 Usage : %s [options] catalogfile entities...\n\ |
313 \tParse the catalog file and query it for the entities\n\ | 314 \tParse the catalog file and query it for the entities\n\ |
314 \t--sgml : handle SGML Super catalogs for --add and --del\n\ | 315 \t--sgml : handle SGML Super catalogs for --add and --del\n\ |
315 \t--shell : run a shell allowing interactive queries\n\ | 316 \t--shell : run a shell allowing interactive queries\n\ |
316 \t--create : create a new catalog\n\ | 317 \t--create : create a new catalog\n\ |
317 \t--add 'type' 'orig' 'replace' : add an XML entry\n\ | 318 \t--add 'type' 'orig' 'replace' : add an XML entry\n\ |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
500 remove(XML_SGML_DEFAULT_CATALOG); | 501 remove(XML_SGML_DEFAULT_CATALOG); |
501 } else { | 502 } else { |
502 out = fopen(XML_SGML_DEFAULT_CATALOG, "w"); | 503 out = fopen(XML_SGML_DEFAULT_CATALOG, "w"); |
503 if (out == NULL) { | 504 if (out == NULL) { |
504 fprintf(stderr, | 505 fprintf(stderr, |
505 "could not open %s for saving\n", | 506 "could not open %s for saving\n", |
506 XML_SGML_DEFAULT_CATALOG); | 507 XML_SGML_DEFAULT_CATALOG); |
507 exit_value = 2; | 508 exit_value = 2; |
508 noout = 0; | 509 noout = 0; |
509 } else { | 510 } else { |
510 » » » » | 511 |
511 xmlACatalogDump(super, out); | 512 xmlACatalogDump(super, out); |
512 fclose(out); | 513 fclose(out); |
513 } | 514 } |
514 } | 515 } |
515 } | 516 } |
516 } else { | 517 } else { |
517 xmlACatalogDump(catal, stdout); | 518 xmlACatalogDump(catal, stdout); |
518 } | 519 } |
519 i += 2; | 520 i += 2; |
520 } else { | 521 } else { |
(...skipping 16 matching lines...) Expand all Loading... |
537 ret = xmlCatalogRemove(BAD_CAST argv[i + 1]); | 538 ret = xmlCatalogRemove(BAD_CAST argv[i + 1]); |
538 if (ret < 0) { | 539 if (ret < 0) { |
539 fprintf(stderr, "Failed to remove entry %s\n", | 540 fprintf(stderr, "Failed to remove entry %s\n", |
540 argv[i + 1]); | 541 argv[i + 1]); |
541 exit_value = 1; | 542 exit_value = 1; |
542 } | 543 } |
543 i += 1; | 544 i += 1; |
544 } | 545 } |
545 } | 546 } |
546 } | 547 } |
547 » | 548 |
548 } else if (shell) { | 549 } else if (shell) { |
549 usershell(); | 550 usershell(); |
550 } else { | 551 } else { |
551 for (i++; i < argc; i++) { | 552 for (i++; i < argc; i++) { |
552 xmlURIPtr uri; | 553 xmlURIPtr uri; |
553 xmlChar *ans; | 554 xmlChar *ans; |
554 » | 555 |
555 uri = xmlParseURI(argv[i]); | 556 uri = xmlParseURI(argv[i]); |
556 if (uri == NULL) { | 557 if (uri == NULL) { |
557 ans = xmlCatalogResolvePublic((const xmlChar *) argv[i]); | 558 ans = xmlCatalogResolvePublic((const xmlChar *) argv[i]); |
558 if (ans == NULL) { | 559 if (ans == NULL) { |
559 printf("No entry for PUBLIC %s\n", argv[i]); | 560 printf("No entry for PUBLIC %s\n", argv[i]); |
560 exit_value = 4; | 561 exit_value = 4; |
561 } else { | 562 } else { |
562 printf("%s\n", (char *) ans); | 563 printf("%s\n", (char *) ans); |
563 xmlFree(ans); | 564 xmlFree(ans); |
564 } | 565 } |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
605 xmlCleanupParser(); | 606 xmlCleanupParser(); |
606 xmlMemoryDump(); | 607 xmlMemoryDump(); |
607 return(exit_value); | 608 return(exit_value); |
608 } | 609 } |
609 #else | 610 #else |
610 int main(int argc ATTRIBUTE_UNUSED, char **argv ATTRIBUTE_UNUSED) { | 611 int main(int argc ATTRIBUTE_UNUSED, char **argv ATTRIBUTE_UNUSED) { |
611 fprintf(stderr, "libxml was not compiled with catalog and output support\n")
; | 612 fprintf(stderr, "libxml was not compiled with catalog and output support\n")
; |
612 return(1); | 613 return(1); |
613 } | 614 } |
614 #endif | 615 #endif |
OLD | NEW |