-/* $NetBSD: primes.c,v 1.4 1995/03/23 08:35:55 cgd Exp $ */
+/* $NetBSD: primes.c,v 1.7 1997/10/12 01:04:55 lukem Exp $ */
/*
* Copyright (c) 1989, 1993
* SUCH DAMAGE.
*/
+#include <sys/cdefs.h>
#ifndef lint
-static char copyright[] =
-"@(#) Copyright (c) 1989, 1993\n\
- The Regents of the University of California. All rights reserved.\n";
+__COPYRIGHT("@(#) Copyright (c) 1989, 1993\n\
+ The Regents of the University of California. All rights reserved.\n");
#endif /* not lint */
#ifndef lint
#if 0
-static char sccsid[] = "@(#)primes.c 8.4 (Berkeley) 3/21/94";
+static char sccsid[] = "@(#)primes.c 8.5 (Berkeley) 5/10/95";
#else
-static char rcsid[] = "$NetBSD: primes.c,v 1.4 1995/03/23 08:35:55 cgd Exp $";
+__RCSID("$NetBSD: primes.c,v 1.7 1997/10/12 01:04:55 lukem Exp $");
#endif
#endif /* not lint */
#include <memory.h>
#include <stdio.h>
#include <stdlib.h>
+#include <unistd.h>
#include "primes.h"
extern char pattern[];
extern int pattern_size; /* length of pattern array */
+int main __P((int, char *[]));
void primes __P((ubig, ubig));
ubig read_num_buf __P((void));
void usage __P((void));
int ch;
char *p;
- while ((ch = getopt(argc, argv, "")) != EOF)
+ while ((ch = getopt(argc, argv, "")) != -1)
switch (ch) {
case '?':
default:
ubig start; /* where to start generating */
ubig stop; /* don't generate at or above this value */
{
- register char *q; /* sieve spot */
- register ubig factor; /* index and factor */
- register char *tab_lim; /* the limit to sieve on the table */
- register ubig *p; /* prime table pointer */
- register ubig fact_lim; /* highest prime for current block */
+ char *q; /* sieve spot */
+ ubig factor; /* index and factor */
+ char *tab_lim; /* the limit to sieve on the table */
+ ubig *p; /* prime table pointer */
+ ubig fact_lim; /* highest prime for current block */
/*
* A number of systems can not convert double values into unsigned
for (p = &prime[0], factor = prime[0];
factor < stop && p <= pr_limit; factor = *(++p)) {
if (factor >= start) {
- printf("%u\n", factor);
+ printf("%lu\n", (unsigned long) factor);
}
}
/* return early if we are done */
do {
/* determine the factor's initial sieve point */
q = (char *)(start%factor); /* temp storage for mod */
- if ((int)q & 0x1) {
- q = &table[(factor-(int)q)/2];
+ if ((long)q & 0x1) {
+ q = &table[(factor-(long)q)/2];
} else {
- q = &table[q ? factor-((int)q/2) : 0];
+ q = &table[q ? factor-((long)q/2) : 0];
}
/* sive for our current factor */
for ( ; q < tab_lim; q += factor) {
*/
for (q = table; q < tab_lim; ++q, start+=2) {
if (*q) {
- printf("%u\n", start);
+ printf("%lu\n", (unsigned long) start);
}
}
}