Merge branch 'tizen_base' of ssh://review.tizen.org:29418/platform/upstream/libxml2...
[platform/upstream/libxml2.git] / xmlcatalog.c
index 489509f..c02b97f 100644 (file)
@@ -47,16 +47,16 @@ static char *filename = NULL;
 #endif
 
 /************************************************************************
- *                                                                     *
- *                     Shell Interface                                 *
- *                                                                     *
+ *                                                                     *
+ *                     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.
  */
@@ -80,6 +80,7 @@ xmlShellReadline(const char *prompt) {
 
     if (prompt != NULL)
        fprintf(stdout, "%s", prompt);
+    fflush(stdout);
     if (!fgets(line_read, 500, stdin))
         return(NULL);
     line_read[500] = 0;
@@ -157,7 +158,7 @@ static void usershell(void) {
                    i++;
                    cur++;
                }
-           } else if (*cur == '"') { 
+           } else if (*cur == '"') {
                cur++;
                argv[i] = cur;
                while ((*cur != 0) && (*cur != '"')) cur++;
@@ -181,12 +182,13 @@ static void usershell(void) {
        /*
         * start interpreting the command
         */
-        if (!strcmp(command, "exit"))
-           break;
-        if (!strcmp(command, "quit"))
-           break;
-        if (!strcmp(command, "bye"))
+       if (!strcmp(command, "exit") ||
+           !strcmp(command, "quit") ||
+           !strcmp(command, "bye")) {
+           free(cmdline);
            break;
+       }
+
        if (!strcmp(command, "public")) {
            if (nbargs != 1) {
                printf("public requires 1 arguments\n");
@@ -296,21 +298,22 @@ static void usershell(void) {
            printf("\tdebug: increase the verbosity level\n");
            printf("\tquiet: decrease the verbosity level\n");
            printf("\texit:  quit the shell\n");
-       } 
+       }
        free(cmdline); /* not xmlFree here ! */
     }
 }
 
 /************************************************************************
- *                                                                     *
- *                     Main                                            *
- *                                                                     *
+ *                                                                     *
+ *                     Main                                            *
+ *                                                                     *
  ************************************************************************/
 static void usage(const char *name) {
     /* 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\
+\tParse the catalog file (void specification possibly expressed as \"\"\n\
+\tappoints the default system one) 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\
@@ -406,11 +409,18 @@ int main(int argc, char **argv) {
            continue;
        } else if (argv[i][0] == '-')
            continue;
-       filename = argv[i];
+
+       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];
            ret = xmlLoadCatalog(argv[i]);
            if ((ret < 0) && (create)) {
                xmlCatalogAdd(BAD_CAST "catalog", BAD_CAST argv[i], NULL);
            }
+       }
        break;
     }
 
@@ -507,7 +517,7 @@ int main(int argc, char **argv) {
                                exit_value = 2;
                                noout = 0;
                            } else {
-                               
+
                                xmlACatalogDump(super, out);
                                fclose(out);
                            }
@@ -544,14 +554,14 @@ int main(int argc, char **argv) {
                }
            }
        }
-       
+
     } else if (shell) {
        usershell();
     } else {
        for (i++; i < argc; i++) {
            xmlURIPtr uri;
            xmlChar *ans;
-           
+
            uri = xmlParseURI(argv[i]);
            if (uri == NULL) {
                ans = xmlCatalogResolvePublic((const xmlChar *) argv[i]);