summaryrefslogtreecommitdiffstats
path: root/games/primes
diff options
context:
space:
mode:
authorphk <phk@FreeBSD.org>1998-08-09 10:36:25 +0000
committerphk <phk@FreeBSD.org>1998-08-09 10:36:25 +0000
commit07b6ec539fe3c75fc30da67afd40bd6c194b1d1d (patch)
tree6d0289fef1ea1ec21aeda291b5287fa236efcdb5 /games/primes
parent5895e6980afbdca08ff9a9f67d889a499e2eb9b9 (diff)
downloadFreeBSD-src-07b6ec539fe3c75fc30da67afd40bd6c194b1d1d.zip
FreeBSD-src-07b6ec539fe3c75fc30da67afd40bd6c194b1d1d.tar.gz
Revert the last commit, it made the Bruce filter flip:
PR7402 was even less suitable for committing almost verbatim than at first appearance. Rev.1.9 of primes.c has at least the following defects. - no update for man page. - no update for usage string. - blowing away of a previous commit to change EOF to -1 in getopt() test. - blowing away of a previous commit to fix printf format errors. - new printf format errors. - one gratuitous ANSIism. - two style bugs. - ... and a partition in a pear tree. PR: 7402
Diffstat (limited to 'games/primes')
-rw-r--r--games/primes/primes.c31
1 files changed, 13 insertions, 18 deletions
diff --git a/games/primes/primes.c b/games/primes/primes.c
index 359c109..e928885 100644
--- a/games/primes/primes.c
+++ b/games/primes/primes.c
@@ -101,8 +101,8 @@ extern ubig *pr_limit; /* largest prime in the prime array */
extern char pattern[];
extern int pattern_size; /* length of pattern array */
-void primes __P((ubig, ubig, int));
-ubig read_num_buf __P((int));
+void primes __P((ubig, ubig));
+ubig read_num_buf __P((void));
void usage __P((void));
int
@@ -114,13 +114,9 @@ main(argc, argv)
ubig stop; /* don't generate at or above this value */
int ch;
char *p;
- int hexa = 0;
- while ((ch = getopt(argc, argv, "h")) != EOF)
+ while ((ch = getopt(argc, argv, "")) != -1)
switch (ch) {
- case 'h':
- hexa = 1;
- break;
case '?':
default:
usage();
@@ -144,14 +140,14 @@ main(argc, argv)
errx(1, "negative numbers aren't permitted.");
errno = 0;
- start = strtoul(argv[0], &p, 0);
+ start = strtoul(argv[0], &p, 10);
if (errno)
err(1, "%s", argv[0]);
if (*p != '\0')
errx(1, "%s: illegal numeric format.", argv[0]);
errno = 0;
- stop = strtoul(argv[1], &p, 0);
+ stop = strtoul(argv[1], &p, 10);
if (errno)
err(1, "%s", argv[1]);
if (*p != '\0')
@@ -163,14 +159,14 @@ main(argc, argv)
errx(1, "negative numbers aren't permitted.");
errno = 0;
- start = strtoul(argv[0], &p, 0);
+ start = strtoul(argv[0], &p, 10);
if (errno)
err(1, "%s", argv[0]);
if (*p != '\0')
errx(1, "%s: illegal numeric format.", argv[0]);
break;
case 0:
- start = read_num_buf(hexa);
+ start = read_num_buf();
break;
default:
usage();
@@ -178,7 +174,7 @@ main(argc, argv)
if (start > stop)
errx(1, "start value must be less than stop value.");
- primes(start, stop, hexa);
+ primes(start, stop);
exit(0);
}
@@ -187,7 +183,7 @@ main(argc, argv)
* This routine returns a number n, where 0 <= n && n <= BIG.
*/
ubig
-read_num_buf(int hexa)
+read_num_buf()
{
ubig val;
char *p, buf[100]; /* > max number of digits. */
@@ -204,7 +200,7 @@ read_num_buf(int hexa)
if (*p == '-')
errx(1, "negative numbers aren't permitted.");
errno = 0;
- val = strtoul(buf, &p, 0);
+ val = strtoul(buf, &p, 10);
if (errno)
err(1, "%s", buf);
if (*p != '\n')
@@ -217,10 +213,9 @@ read_num_buf(int hexa)
* primes - sieve and print primes from start up to and but not including stop
*/
void
-primes(start, stop, hexa)
+primes(start, stop)
ubig start; /* where to start generating */
ubig stop; /* don't generate at or above this value */
- int hexa;
{
register char *q; /* sieve spot */
register ubig factor; /* index and factor */
@@ -261,7 +256,7 @@ primes(start, stop, hexa)
for (p = &prime[0], factor = prime[0];
factor < stop && p <= pr_limit; factor = *(++p)) {
if (factor >= start) {
- printf(hexa ? "0x%x\n" : "%u\n", factor);
+ printf("%lu\n", factor);
}
}
/* return early if we are done */
@@ -324,7 +319,7 @@ primes(start, stop, hexa)
*/
for (q = table; q < tab_lim; ++q, start+=2) {
if (*q) {
- printf(hexa ? "0x%x\n" : "%u\n", start);
+ printf("%lu\n", start);
}
}
}
OpenPOWER on IntegriCloud