/* -*-c-*-
*
- * $Id: genprimes.c,v 1.3 2000/08/15 21:41:58 mdw Exp $
+ * $Id: genprimes.c,v 1.7 2004/04/08 01:36:15 mdw Exp $
*
* Generate prime number table
*
* (c) 1999 Straylight/Edgeware
*/
-/*----- Licensing notice --------------------------------------------------*
+/*----- Licensing notice --------------------------------------------------*
*
* This file is part of Catacomb.
*
* it under the terms of the GNU Library General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
- *
+ *
* Catacomb is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Library General Public License for more details.
- *
+ *
* You should have received a copy of the GNU Library General Public
* License along with Catacomb; if not, write to the Free
* Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
* MA 02111-1307, USA.
*/
-/*----- Revision history --------------------------------------------------*
- *
- * $Log: genprimes.c,v $
- * 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 <ctype.h>
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) {
case 't':
type = optarg;
break;
+ case 's':
+ sym = optarg;
+ break;
default:
pquis(stderr, "Usage: $ [-n nprimes] [-m maxprime] [-t type]\n");
exit(EXIT_FAILURE);
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\
#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(&p)[DA_LEN(&p) - 1],
+ DA_LAST(&p),
type, name);
dstr_destroy(&d);
if (fclose(fp) == EOF) {
\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)