summaryrefslogtreecommitdiffstats
path: root/games/caesar/caesar.c
diff options
context:
space:
mode:
Diffstat (limited to 'games/caesar/caesar.c')
-rw-r--r--games/caesar/caesar.c34
1 files changed, 20 insertions, 14 deletions
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;
OpenPOWER on IntegriCloud