hash/crc-mktab.c, hash/unihash-mkstatic.c: Add `const' option.
[mLib] / hash / unihash-mkstatic.c
index dd69f45..0505fcf 100644 (file)
@@ -62,7 +62,7 @@ static void version(FILE *fp)
 
 static void usage(FILE *fp)
 {
-  pquis(fp, "Usage: $ [-c] [-o FILE] [-g GUARD] [-i HEADER] [-s SYM]\n\
+  pquis(fp, "Usage: $ [-Cc] [-o FILE] [-g GUARD] [-i HEADER] [-s SYM]\n\
        [-k KEY]\n");
 }
 
@@ -79,6 +79,7 @@ Emits a precomputed unihash_info structure for a given key.\n\
 -u, --usage            Show a terse usage message.\n\
 \n\
 -c, --c-source         Emit a C source file rather than a header.\n\
+-C, --const            Declare table to be `const' (only useful with `-c').\n\
 -k, --key=KEY          Use KEY as the universal hashing key.\n\
 -g, --guard=GUARD      Use GUARD as a multiple-inclusion guard constant.\n\
 -i, --include=HEADER   Include HEADER at top of C source file.\n\
@@ -101,6 +102,7 @@ int main(int argc, char *argv[])
 
 #define f_bogus 1u
 #define f_ctab 2u
+#define f_const 4u
 
   ego(argv[0]);
 
@@ -112,6 +114,7 @@ int main(int argc, char *argv[])
 
       { "output",      OPTF_ARGREQ,    0,      'o' },
       { "c-source",    0,              0,      'c' },
+      { "const",       0,              0,      'C' },
       { "key",         OPTF_ARGREQ,    0,      'k' },
       { "symbol",      OPTF_ARGREQ,    0,      's' },
       { "include",     OPTF_ARGREQ,    0,      'i' },
@@ -119,7 +122,7 @@ int main(int argc, char *argv[])
 
       { 0,             0,              0,      0 }
     };
-    int i = mdwopt(argc, argv, "hvu o:ck:s:i:g:", opts, 0, 0, 0);
+    int i = mdwopt(argc, argv, "hvu o:cCk:s:i:g:", opts, 0, 0, 0);
 
     if (i < 0)
       break;
@@ -140,6 +143,9 @@ int main(int argc, char *argv[])
       case 'c':
        flags |= f_ctab;
        break;
+      case 'C':
+       flags |= f_const;
+       break;
       case 's':
        sym = optarg;
        break;
@@ -207,7 +213,8 @@ int main(int argc, char *argv[])
       fprintf(fp, "#include \"%s\"\n\n", inc);
     else
       fputs("#include <mLib/unihash.h>\n\n", fp);
-    fprintf(fp, "unihash_info %s = { {\n", sym);
+    fprintf(fp, "%sunihash_info %s = { {\n",
+           (flags&f_const) ? "const " : "", sym);
   } else {
     int n;
     if (guard)