X-Git-Url: https://git.distorted.org.uk/u/mdw/catacomb/blobdiff_plain/8ecfe0dc4e8d52324a9f839f02e3ca2fad417c51..34e4f738bcba58e6d8c4cabbb0b3232a65b42a9d:/genprimes.c diff --git a/genprimes.c b/genprimes.c index 4474110..56e388e 100644 --- a/genprimes.c +++ b/genprimes.c @@ -1,6 +1,6 @@ /* -*-c-*- * - * $Id: genprimes.c,v 1.1 1999/11/19 13:19:37 mdw Exp $ + * $Id: genprimes.c,v 1.5 2004/04/01 12:50:09 mdw Exp $ * * Generate prime number table * @@ -30,6 +30,22 @@ /*----- Revision history --------------------------------------------------* * * $Log: genprimes.c,v $ + * Revision 1.5 2004/04/01 12:50:09 mdw + * Add cyclic group abstraction, with test code. Separate off exponentation + * functions for better static linking. Fix a buttload of bugs on the way. + * Generally ensure that negative exponents do inversion correctly. Add + * table of standard prime-field subgroups. (Binary field subgroups are + * currently unimplemented but easy to add if anyone ever finds a good one.) + * + * 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. * @@ -59,16 +75,17 @@ int main(int argc, char *argv[]) { int p_max = 0, p_n = 0; char *type = "unsigned int"; - char *header = "ptab.h"; - char *source = "ptab.c"; - char *name = "ptab"; + 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) { @@ -92,6 +109,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); @@ -101,7 +121,7 @@ int main(int argc, char *argv[]) if (!p_max && !p_n) die(EXIT_FAILURE, "bad arguments to `-n' or `-m'"); - if (p_max >= 2) + if (p_n || p_max >= 2) DA_PUSH(&p, 2); for (i = 3; (!p_max && !p_n) || (p_n && DA_LEN(&p) < p_n) || @@ -122,15 +142,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\ @@ -140,16 +163,17 @@ int main(int argc, char *argv[]) #ifndef %s\n\ #define %s\n\ \n\ -#define NPRIME %lu\n\ -#define MAXPRIME %i\n\ +#define NPRIME %luu\n\ +#define MAXPRIME %uu\n\ \n\ -extern %s %s[];\n\ +typedef %s smallprime;\n\ +extern smallprime %s[];\n\ \n\ #endif\n\ ", - d.buf, d.buf, + sym, sym, (unsigned long)DA_LEN(&p), - DA(&p)[DA_LEN(&p) - 1], + DA_LAST(&p), type, name); dstr_destroy(&d); if (fclose(fp) == EOF) {