Add cyclic group abstraction, with test code. Separate off exponentation
[u/mdw/catacomb] / genprimes.c
index 2961621..56e388e 100644 (file)
@@ -1,6 +1,6 @@
 /* -*-c-*-
  *
- * $Id: genprimes.c,v 1.4 2001/03/04 13:08:10 mdw Exp $
+ * $Id: genprimes.c,v 1.5 2004/04/01 12:50:09 mdw Exp $
  *
  * Generate prime number table
  *
 /*----- 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.
  *
@@ -71,13 +78,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 +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);
@@ -131,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\
@@ -157,7 +171,7 @@ extern smallprime %s[];\n\
 \n\
 #endif\n\
 ",
-           d.buf, d.buf,
+           sym, sym,
            (unsigned long)DA_LEN(&p),
            DA_LAST(&p),
            type, name);