Re: [xml] How is xmlcatalog --sgml --del suppose to work?



On Mon, Jul 05, 2004 at 04:09:50AM -0400, Daniel Veillard wrote:
On Sun, Jul 04, 2004 at 09:16:10PM -0500, Albert Chin wrote:
At present:
  $ xmlcatalog --noout --sgml --add /tmp/b /tmp/a
will add
  CATALOG "/tmp/a"
to /tmp/b and add
  CATALOG "/tmp/b"
to the super catalog.

I really dislike this. It gives no control over which catalog file gets
modified (and I don't like the super catalog being modified
automatically). I'd like the operation of xmlcatalog with respect to
SGML catalogs to be like so:
  $ xmlcatalog --noout --sgml --add [new catalog entry] [catalog file]

So, the above would add
  CATALOG "/tmp/b"
to catalog file /tmp/a, without updating the super catalog. To update
the super catalog, rerun xmlcatalog with [catalog file] pointing to
the super catalog file.

At present, the behavior of XML and SGML catalog operations are
inconsistent. This would make them consistent, though introduce
backward incompatibility into the new xmlcatalog.

  Hum, this kind of behaviour surprises me but is certainly on-purpose.
That mean changing it will break things, as the SGML support was added
to repace an old SGML tool. I don't think changing the behaviour is
a good idea. Adding a flag to avoid modifying the super catalog sounds
far far more safe, please bugzilla this.

Ok, how about the attached patch? Note, the usage string is wrong.
SGML --add and -del entries take the catalog first. The usage string
has always been wrong.

http://bugzilla.gnome.org/show_bug.cgi?id=145461

-- 
albert chin (china thewrittenword com)

-- snip snip
--- xmlcatalog.c.orig   Sun Jul  4 21:38:31 2004
+++ xmlcatalog.c        Mon Jul  5 11:02:42 2004
@@ -37,6 +37,7 @@
 static int add = 0;
 static int del = 0;
 static int convert = 0;
+static int no_super_update = 0;
 static int verbose = 0;
 static char *filename = NULL;
 
@@ -306,17 +307,20 @@
  *                                                                     *
  ************************************************************************/
 static void usage(const char *name) {
-    printf("Usage : %s [options] catalogfile entities...\n", name);
-    printf("\tParse the catalog file and query it for the entities\n");
-    printf("\t--sgml : handle SGML Super catalogs for --add and --del\n");
-    printf("\t--shell : run a shell allowing interactive queries\n");
-    printf("\t--create : create a new catalog\n");
-    printf("\t--add 'type' 'orig' 'replace' : add an entry\n");
-    printf("\t--del 'values' : remove values\n");
-    printf("\t--noout: avoid dumping the result on stdout\n");
-    printf("\t         used with add or del, it saves the catalog changes\n");
-    printf("\t         and with --sgml it also updates the super catalog\n");
-    printf("\t-v --verbose : provide debug informations\n");
+    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\
+\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", name);
 }
 int main(int argc, char **argv) {
     int i;
@@ -357,6 +361,9 @@
        } else if ((!strcmp(argv[i], "-convert")) ||
            (!strcmp(argv[i], "--convert"))) {
            convert++;
+       } else if ((!strcmp(argv[i], "-no-super-update")) ||
+           (!strcmp(argv[i], "--no-super-update"))) {
+           no_super_update++;
        } else if ((!strcmp(argv[i], "-add")) ||
            (!strcmp(argv[i], "--add"))) {
            if (sgml)
@@ -424,14 +446,17 @@
                    (!strcmp(argv[i], "--add"))) {
                    if (catal == NULL)
                        catal = xmlNewCatalog(1);
-                   super = xmlLoadSGMLSuperCatalog(XML_SGML_DEFAULT_CATALOG);
-                   if (super == NULL)
-                       super = xmlNewCatalog(1);
-
                    xmlACatalogAdd(catal, BAD_CAST "CATALOG",
                                         BAD_CAST argv[i + 2], NULL);
-                   xmlACatalogAdd(super, BAD_CAST "CATALOG",
-                                        BAD_CAST argv[i + 1], NULL);
+
+                   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);
+                   }
                } else {
                    if (catal != NULL)
                        ret = xmlACatalogRemove(catal, BAD_CAST argv[i + 2]);
@@ -442,7 +467,7 @@
                                argv[i + 1]);
                        exit_value = 1;
                    }
-                   if ((noout) && (catal != NULL) &&
+                   if ((!no_super_update) && (noout) && (catal != NULL) &&
                        (xmlCatalogIsEmpty(catal))) {
                        super = xmlLoadSGMLSuperCatalog(
                                   XML_SGML_DEFAULT_CATALOG);
@@ -475,7 +500,7 @@
                            fclose(out);
                        }
                    }
-                   if (super != NULL) {
+                   if (!no_super_update && super != NULL) {
                        if (xmlCatalogIsEmpty(super)) {
                            remove(XML_SGML_DEFAULT_CATALOG);
                        } else {



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]