X-Git-Url: https://git.distorted.org.uk/u/mdw/catacomb/blobdiff_plain/62f34e465125f07961ae8cc8bff167f9cdb6f80a..578a86d91941a0f722b87973d88e84ec2cf9a608:/genprimes.c diff --git a/genprimes.c b/genprimes.c index 2961621..93e041b 100644 --- a/genprimes.c +++ b/genprimes.c @@ -1,6 +1,6 @@ /* -*-c-*- * - * $Id: genprimes.c,v 1.4 2001/03/04 13:08:10 mdw Exp $ + * $Id: genprimes.c,v 1.7 2004/04/08 01:36:15 mdw Exp $ * * Generate prime number table * @@ -27,23 +27,6 @@ * MA 02111-1307, USA. */ -/*----- Revision history --------------------------------------------------* - * - * $Log: genprimes.c,v $ - * Revision 1.4 2001/03/04 13:08:10 mdw - * Use @DA_LAST@ to determine @MAXPRIME@, now that it exists. - * - * Revision 1.3 2000/08/15 21:41:58 mdw - * Create a new type for the small primes table elements. - * - * Revision 1.2 1999/12/22 15:48:39 mdw - * Rename output file. Make output constants unsigned. - * - * Revision 1.1 1999/11/19 13:19:37 mdw - * Generate small primes table. - * - */ - /*----- Header files ------------------------------------------------------*/ #include @@ -71,13 +54,14 @@ int main(int argc, char *argv[]) char *header = "primetab.h"; char *source = "primetab.c"; char *name = "primetab"; + char *sym = 0; intv p = DA_INIT; int i; ego(argv[0]); for (;;) { - int i = getopt(argc, argv, "h:c:i:n:m:t:"); + int i = getopt(argc, argv, "h:c:i:n:m:t:s:"); if (i < 0) break; switch (i) { @@ -101,6 +85,9 @@ int main(int argc, char *argv[]) case 't': type = optarg; break; + case 's': + sym = optarg; + break; default: pquis(stderr, "Usage: $ [-n nprimes] [-m maxprime] [-t type]\n"); exit(EXIT_FAILURE); @@ -131,15 +118,18 @@ int main(int argc, char *argv[]) char *q; if (!fp) die(EXIT_FAILURE, "couldn't write `%s': %s", header, strerror(errno)); - for (q = header; *q; q++) { - int ch = (unsigned char)*q; - if (isalnum(ch)) - ch = toupper(ch); - else - ch = '_'; - DPUTC(&d, ch); + if (!sym) { + for (q = header; *q; q++) { + int ch = (unsigned char)*q; + if (isalnum(ch)) + ch = toupper(ch); + else + ch = '_'; + DPUTC(&d, ch); + } + DPUTZ(&d); + sym = d.buf; } - DPUTZ(&d); fprintf(fp, "\ /* -*-c-*-\n\ *\n\ @@ -153,11 +143,11 @@ int main(int argc, char *argv[]) #define MAXPRIME %uu\n\ \n\ typedef %s smallprime;\n\ -extern smallprime %s[];\n\ +extern const smallprime %s[];\n\ \n\ #endif\n\ ", - d.buf, d.buf, + sym, sym, (unsigned long)DA_LEN(&p), DA_LAST(&p), type, name); @@ -181,7 +171,7 @@ extern smallprime %s[];\n\ \n\ #include \"%s\"\n\ \n\ -%s %s[] = {", +const %s %s[] = {", header, type, name); for (i = 0; i < DA_LEN(&p); i++) { if (i % 8 == 0)