From: Mark Wooding Date: Wed, 4 Sep 2019 17:39:52 +0000 (+0100) Subject: hash/crc-mktab.c, hash/unihash-mkstatic.c: Add `const' option. X-Git-Tag: 2.4.0~4 X-Git-Url: https://git.distorted.org.uk/~mdw/mLib/commitdiff_plain/3e7267bfb1faa4895769c785d859a88e86a79ff5 hash/crc-mktab.c, hash/unihash-mkstatic.c: Add `const' option. Add `-C' option to produce `const' tables. I'd probably like this to be the default, at least for `crc-mktab', but currently it isn't for (a) compatibility and (b) consistency between the two. --- diff --git a/hash/crc-mktab.1 b/hash/crc-mktab.1 index 3f26960..bfbeb8a 100644 --- a/hash/crc-mktab.1 +++ b/hash/crc-mktab.1 @@ -12,7 +12,7 @@ crc-mktab \- construct CRC tables for efficient computation .SH SYNOPSIS .B crc-mktab -.RB [ \-cr ] +.RB [ \-Ccr ] .RB [ \-s .IR symbol ] .RB [ \-t @@ -57,6 +57,11 @@ successfully. .B "\-u, \-\-usage" Print a one-line usage summary to standard output and exit successfully. .TP +.B "\-C, \-\-const" +When producing C source (the +.B \-c +option), rather than a header, define the table to be +.BR const . .B "\-c, \-\-c-source" Produce a C source file which exports a symbol naming the array, instead of a C header file. diff --git a/hash/crc-mktab.c b/hash/crc-mktab.c index a64b43c..4453cf3 100644 --- a/hash/crc-mktab.c +++ b/hash/crc-mktab.c @@ -57,6 +57,7 @@ static FILE *fp; #define f_bogus 1u #define f_ctab 2u #define f_reverse 4u +#define f_const 8u #define BSCOL 72 @@ -79,7 +80,7 @@ static void version(FILE *fp) static void usage(FILE *fp) { - pquis(fp, "Usage: $ [-cr] [-o FILE] [-g GUARD] [-s SYM] [-i HEADER]\n\ + pquis(fp, "Usage: $ [-Ccr] [-o FILE] [-g GUARD] [-s SYM] [-i HEADER]\n\ [-t TYPE] [-b BITS] [-B BITS] [-p POLY]\n"); } @@ -97,6 +98,7 @@ of options are provided:\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\ -b, --bits=BITS Emit a table for a BITS bits-wide CRC.\n\ -B, --bit-chunk=BITS Emit a table to process BITS bits at a time.\n\ -p, --polynomial=POLY Use the POLY as the dividing polynomial.\n\ @@ -143,6 +145,7 @@ int main(int argc, char *argv[]) { "output", OPTF_ARGREQ, 0, 'o' }, { "c-source", 0, 0, 'c' }, + { "const", 0, 0, 'C' }, { "symbol", OPTF_ARGREQ, 0, 's' }, { "type", OPTF_ARGREQ, 0, 't' }, { "include", OPTF_ARGREQ, 0, 'i' }, @@ -155,7 +158,7 @@ int main(int argc, char *argv[]) { 0, 0, 0, 0 } }; - int i = mdwopt(argc, argv, "hvu o:cs:t:i:g: b:B:p:r", opts, 0, 0, 0); + int i = mdwopt(argc, argv, "hvu o:cCs:t:i:g: b:B:p:r", opts, 0, 0, 0); if (i < 0) break; @@ -176,6 +179,9 @@ int main(int argc, char *argv[]) case 'c': flags |= f_ctab; break; + case 'C': + flags |= f_const; + break; case 's': sym = optarg; break; @@ -287,7 +293,8 @@ int main(int argc, char *argv[]) if (flags & f_ctab) { if (inc) fprintf(fp, "#include \"%s\"\n\n", inc); - fprintf(fp, "%s %s[] = {\n", type, sym); + fprintf(fp, "%s%s %s[] = {\n", + (flags&f_const) ? "const " : "", type, sym); } else { int n; if (guard) diff --git a/hash/unihash-mkstatic.1 b/hash/unihash-mkstatic.1 index f33ec6b..09da499 100644 --- a/hash/unihash-mkstatic.1 +++ b/hash/unihash-mkstatic.1 @@ -12,7 +12,7 @@ unihash-mkstatic \- construct tables for universal hashing .SH SYNOPSIS .B unihash-mkstatic -.RB [ \-c ] +.RB [ \-Cc ] .RB [ \-s .IR symbol ] .RB [ \-i @@ -46,6 +46,12 @@ successfully. .B "\-u, \-\-usage" Print a one-line usage summary to standard output and exit successfully. .TP +.B "\-C, \-\-const" +When producing C source (the +.B \-c +option), rather than a header, define the table to be +.BR const . +.TP .B "\-c, \-\-c-source" Produce a C source file which exports a symbol naming the array, instead of a C header file. diff --git a/hash/unihash-mkstatic.c b/hash/unihash-mkstatic.c index dd69f45..0505fcf 100644 --- a/hash/unihash-mkstatic.c +++ b/hash/unihash-mkstatic.c @@ -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 \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)