summaryrefslogtreecommitdiffstats
path: root/games
diff options
context:
space:
mode:
authorache <ache@FreeBSD.org>1996-05-27 08:50:53 +0000
committerache <ache@FreeBSD.org>1996-05-27 08:50:53 +0000
commitfa8ff06c20810fa112034f685069b927241ae387 (patch)
treecec0c7ba3d3594e153acef2ce430ac1532c80269 /games
parentc2a4a97427813cec0191f5359e757baabead09c9 (diff)
downloadFreeBSD-src-fa8ff06c20810fa112034f685069b927241ae387.zip
FreeBSD-src-fa8ff06c20810fa112034f685069b927241ae387.tar.gz
Use valid ctype range now.
Includes cleanup Misc. cleanup Use absolute path in rot13 wrapper.
Diffstat (limited to 'games')
-rw-r--r--games/caesar/Makefile2
-rw-r--r--games/caesar/caesar.62
-rw-r--r--games/caesar/caesar.c34
-rw-r--r--games/caesar/rot13.sh2
4 files changed, 24 insertions, 16 deletions
diff --git a/games/caesar/Makefile b/games/caesar/Makefile
index 2c1ff10..b9e4bca 100644
--- a/games/caesar/Makefile
+++ b/games/caesar/Makefile
@@ -6,6 +6,8 @@ DPADD= ${LIBM}
LDADD= -lm
MLINKS= caesar.6 rot13.6
+CFLAGS+= -Wall
+
beforeinstall:
${INSTALL} -c -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \
${.CURDIR}/rot13.sh ${DESTDIR}/usr/games/rot13
diff --git a/games/caesar/caesar.6 b/games/caesar/caesar.6
index cf7c445..8c600c0 100644
--- a/games/caesar/caesar.6
+++ b/games/caesar/caesar.6
@@ -49,7 +49,7 @@ statistics.
reads from the standard input and writes to the standard output.
.Pp
The optional numerical argument
-Ar rotation
+.Ar rotation
may be used to specify a specific rotation value.
.Pp
The frequency (from most common to least) of English letters is as follows:
diff --git a/games/caesar/caesar.c b/games/caesar/caesar.c
index b002786..749da50 100644
--- a/games/caesar/caesar.c
+++ b/games/caesar/caesar.c
@@ -40,24 +40,28 @@
*/
#ifndef lint
-static char copyright[] =
+static const char copyright[] =
"@(#) Copyright (c) 1989, 1993\n\
The Regents of the University of California. All rights reserved.\n";
#endif /* not lint */
#ifndef lint
-static char sccsid[] = "@(#)caesar.c 8.1 (Berkeley) 5/31/93";
+static const char sccsid[] = "@(#)caesar.c 8.1 (Berkeley) 5/31/93";
#endif /* not lint */
+#include <errno.h>
#include <math.h>
#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
#include <ctype.h>
#include <unistd.h>
#define LINELENGTH 2048
#define ROTATE(ch, perm) \
+ isascii(ch) ? ( \
isupper(ch) ? ('A' + (ch - 'A' + perm) % 26) : \
- islower(ch) ? ('a' + (ch - 'a' + perm) % 26) : ch
+ islower(ch) ? ('a' + (ch - 'a' + perm) % 26) : ch) : ch
/*
* letter frequencies (taken from some unix(tm) documentation)
@@ -69,15 +73,15 @@ double stdf[26] = {
2.62, 0.81, 1.88, 0.23, 2.07, 0.06,
};
-main(argc, argv)
+void printit();
+
+void main(argc, argv)
int argc;
char **argv;
{
- extern int errno;
- register int ch, dot, i, nread, winnerdot;
+ register int ch, dot, i, nread, winnerdot = 0;
register char *inbuf;
int obs[26], try, winner;
- char *malloc(), *strerror();
if (argc > 1)
printit(argv[1]);
@@ -99,11 +103,13 @@ main(argc, argv)
exit(1);
}
for (i = nread; i--;) {
- ch = inbuf[i];
- if (islower(ch))
- ++obs[ch - 'a'];
- else if (isupper(ch))
- ++obs[ch - 'A'];
+ ch = (unsigned char) inbuf[i];
+ if (isascii(ch)) {
+ if (islower(ch))
+ ++obs[ch - 'a'];
+ else if (isupper(ch))
+ ++obs[ch - 'A'];
+ }
}
/*
@@ -126,7 +132,7 @@ main(argc, argv)
for (;;) {
for (i = 0; i < nread; ++i) {
- ch = inbuf[i];
+ ch = (unsigned char) inbuf[i];
putchar(ROTATE(ch, winner));
}
if (nread < LINELENGTH)
@@ -139,7 +145,7 @@ main(argc, argv)
exit(0);
}
-printit(arg)
+void printit(arg)
char *arg;
{
register int ch, rot;
diff --git a/games/caesar/rot13.sh b/games/caesar/rot13.sh
index 93fb935..b71300f 100644
--- a/games/caesar/rot13.sh
+++ b/games/caesar/rot13.sh
@@ -34,4 +34,4 @@
# @(#)rot13.sh 8.1 (Berkeley) 5/31/93
#
-caesar 13 $*
+/usr/games/caesar 13 $*
OpenPOWER on IntegriCloud