]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Generate squid.conf.default with just the configuration data & comments
authorHenrik Nordstrom <henrik@henriknordstrom.net>
Wed, 30 Sep 2009 01:15:18 +0000 (03:15 +0200)
committerHenrik Nordstrom <henrik@henriknordstrom.net>
Wed, 30 Sep 2009 01:15:18 +0000 (03:15 +0200)
forward-port from squid-2

src/Makefile.am
src/cf_gen.cc

index b235c0ed224fce2c66ffb5147f6e148b19883082..ce1799199f4b3541f762ff48f1b6dd21d9d2ada2 100644 (file)
@@ -771,12 +771,9 @@ test_cache_digest: test_cache_digest.o CacheDigest.o debug.o globals.o store_key
 cache_cf.o: cf_parser.h
 
 # squid.conf.default is built by cf_gen when making cf_parser.h
-squid.conf.documented: cf_parser.h
+squid.conf.default squid.conf.documented: cf_parser.h
        true
 
-squid.conf.default: squid.conf.documented
-       $(EGREP) -v "^[#\ ]" squid.conf.documented | $(EGREP) . >squid.conf.default
-
 cf_parser.h: cf.data cf_gen$(EXEEXT)
        ./cf_gen cf.data $(srcdir)/cf.data.depend
 
index 8ad00de525e13c359904d69dcd21a8536d16bbd0..9eeb4be29c1176a98038191b09c4c0cf7072b4e7 100644 (file)
@@ -61,6 +61,7 @@
 #define MAX_LINE       1024    /* longest configuration line */
 #define _PATH_PARSER           "cf_parser.h"
 #define _PATH_SQUID_CONF       "squid.conf.documented"
+#define _PATH_SQUID_CONF_SHORT "squid.conf.default"
 #define _PATH_CF_DEPEND                "cf.data.depend"
 
 enum State {
@@ -119,7 +120,7 @@ static void gen_parse_entry(Entry *entry, FILE *fp);
 static void gen_parse_alias(char *, EntryAlias *, Entry *, FILE *);
 static void gen_dump(Entry *, FILE *);
 static void gen_free(Entry *, FILE *);
-static void gen_conf(Entry *, FILE *);
+static void gen_conf(Entry *, FILE *, bool verbose_output);
 static void gen_default_if_none(Entry *, FILE *);
 
 
@@ -159,14 +160,22 @@ checkDepend(const char *directive, const char *name, const Type *types, const En
     exit(1);
 }
 
+static void
+usage(const char *program_name)
+{
+    fprintf(stderr, "Usage: %s cf.data cf.data.depend\n", program_name);
+    exit(1);
+}
+
 int
 main(int argc, char *argv[])
 {
     FILE *fp;
-    char *input_filename = argv[1];
+    char *input_filename;
     const char *output_filename = _PATH_PARSER;
     const char *conf_filename = _PATH_SQUID_CONF;
-    const char *type_depend = argv[2];
+    const char *conf_filename_short = _PATH_SQUID_CONF_SHORT;
+    const char *type_depend;
     int linenum = 0;
     Entry *entries = NULL;
     Entry *curr = NULL;
@@ -183,6 +192,11 @@ main(int argc, char *argv[])
 #endif
     char buff[MAX_LINE];
 
+    if (argc != 3)
+       usage(argv[0]);
+
+    input_filename = argv[1];
+    type_depend = argv[2];
 
     /*-------------------------------------------------------------------*
      * Parse type dependencies
@@ -486,10 +500,20 @@ main(int argc, char *argv[])
 
 #endif
 
-    gen_conf(entries, fp);
+    gen_conf(entries, fp, 1);
 
     fclose(fp);
 
+    if ((fp = fopen(conf_filename_short, "w")) == NULL) {
+        perror(conf_filename_short);
+        exit(1);
+    }
+#ifdef _SQUID_WIN32_
+    setmode(fileno(fp), O_TEXT);
+#endif
+    gen_conf(entries, fp, 0);
+    fclose(fp);
+
     return (rc);
 }
 
@@ -772,7 +796,7 @@ available_if(char *name)
 }
 
 static void
-gen_conf(Entry * head, FILE * fp)
+gen_conf(Entry * head, FILE * fp, bool verbose_output)
 {
     Entry *entry;
     char buf[8192];
@@ -780,28 +804,32 @@ gen_conf(Entry * head, FILE * fp)
 
     for (entry = head; entry != NULL; entry = entry->next) {
         Line *line;
-        int blank = 1;
         int enabled = 1;
 
         if (!strcmp(entry->name, "comment"))
             (void) 0;
-        else
-            fprintf(fp, "#  TAG: %s", entry->name);
+       else if (verbose_output) {
+           fprintf(fp, "#  TAG: %s", entry->name);
 
-        if (entry->comment)
-            fprintf(fp, "\t%s", entry->comment);
+           if (entry->comment)
+               fprintf(fp, "\t%s", entry->comment);
 
-        fprintf(fp, "\n");
+           fprintf(fp, "\n");
+       }
 
-        if (!defined(entry->ifdef)) {
-            fprintf(fp, "# Note: This option is only available if Squid is rebuilt with the\n");
-            fprintf(fp, "#       %s\n#\n", available_if(entry->ifdef));
-            enabled = 0;
+       if (!defined(entry->ifdef)) {
+           if (verbose_output) {
+               fprintf(fp, "# Note: This option is only available if Squid is rebuilt with the\n");
+               fprintf(fp, "#       %s\n#\n", available_if(entry->ifdef));
+           }
+           enabled = 0;
         }
 
-        for (line = entry->doc; line != NULL; line = line->next) {
-            fprintf(fp, "#%s\n", line->data);
-        }
+       if (verbose_output) {
+           for (line = entry->doc; line != NULL; line = line->next) {
+               fprintf(fp, "#%s\n", line->data);
+           }
+       }
 
         if (entry->default_value && strcmp(entry->default_value, "none") != 0) {
             snprintf(buf, sizeof(buf), "%s %s", entry->name, entry->default_value);
@@ -815,19 +843,12 @@ gen_conf(Entry * head, FILE * fp)
             }
         }
 
-        if (entry->nocomment)
-            blank = 0;
-
         if (!def && entry->doc && !entry->nocomment &&
                 strcmp(entry->name, "comment") != 0)
             lineAdd(&def, "none");
 
-        if (def && (entry->doc || entry->nocomment)) {
-            if (blank)
-                fprintf(fp, "#\n");
-
-            fprintf(fp, "#Default:\n");
-
+        if (verbose_output && def && (entry->doc || entry->nocomment)) {
+           fprintf(fp, "#Default:\n");
             while (def != NULL) {
                 line = def;
                 def = line->next;
@@ -835,21 +856,21 @@ gen_conf(Entry * head, FILE * fp)
                 xfree(line->data);
                 xfree(line);
             }
-
-            blank = 1;
         }
 
-        if (entry->nocomment && blank)
+        if (verbose_output && entry->nocomment)
             fprintf(fp, "#\n");
 
-        for (line = entry->nocomment; line != NULL; line = line->next) {
-            if (!enabled && line->data[0] != '#')
-                fprintf(fp, "#%s\n", line->data);
-            else
-                fprintf(fp, "%s\n", line->data);
-        }
+       if (enabled || verbose_output) {
+           for (line = entry->nocomment; line != NULL; line = line->next) {
+               if (!enabled && line->data[0] != '#')
+                   fprintf(fp, "#%s\n", line->data);
+               else
+                   fprintf(fp, "%s\n", line->data);
+           }
+       }
 
-        if (entry->doc != NULL) {
+        if (verbose_output && entry->doc != NULL) {
             fprintf(fp, "\n");
         }
     }