summaryrefslogtreecommitdiff
path: root/games/pig/pig.c
diff options
context:
space:
mode:
authorPaul Janzen <pjanzen@cvs.openbsd.org>1998-08-19 07:42:28 +0000
committerPaul Janzen <pjanzen@cvs.openbsd.org>1998-08-19 07:42:28 +0000
commited884b9fa4509c09f0f7ab71efe57a4e83a2e055 (patch)
treeef9d859a0754785b42ea5cacb27aff54b5000315 /games/pig/pig.c
parentf4fc9566a4d35c0cc2bf8c7f1136287d8eec8c44 (diff)
tags, formatting, ANSI-fication, prototypes, de-typos, and the occasional
initialization, removal of unused variable, or other minor fix. Most changes are from or inspired by NetBSD.
Diffstat (limited to 'games/pig/pig.c')
-rw-r--r--games/pig/pig.c33
1 files changed, 22 insertions, 11 deletions
diff --git a/games/pig/pig.c b/games/pig/pig.c
index 89230a673af..e7584b90a97 100644
--- a/games/pig/pig.c
+++ b/games/pig/pig.c
@@ -1,3 +1,4 @@
+/* $OpenBSD: pig.c,v 1.6 1998/08/19 07:40:49 pjanzen Exp $ */
/* $NetBSD: pig.c,v 1.2 1995/03/23 08:41:40 cgd Exp $ */
/*-
@@ -41,18 +42,20 @@ static char copyright[] =
#ifndef lint
#if 0
-static char sccsid[] = "@(#)pig.c 8.1 (Berkeley) 5/31/93";
+static char sccsid[] = "@(#)pig.c 8.2 (Berkeley) 5/4/95";
#else
-static char rcsid[] = "$NetBSD: pig.c,v 1.2 1995/03/23 08:41:40 cgd Exp $";
+static char rcsid[] = "$OpenBSD: pig.c,v 1.6 1998/08/19 07:40:49 pjanzen Exp $";
#endif
#endif /* not lint */
#include <sys/types.h>
#include <ctype.h>
+#include <err.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <unistd.h>
void pigout __P((char *, int));
void usage __P((void));
@@ -62,7 +65,7 @@ main(argc, argv)
int argc;
char *argv[];
{
- register int len;
+ int len;
int ch;
char buf[1024];
@@ -81,10 +84,8 @@ main(argc, argv)
for (len = 0; (ch = getchar()) != EOF;) {
if (isalpha(ch)) {
- if (len >= sizeof(buf)) {
- (void)fprintf(stderr, "pig: ate too much!\n");
- exit(1);
- }
+ if (len >= sizeof(buf))
+ errx(1, "ate too much!");
buf[len++] = ch;
continue;
}
@@ -102,15 +103,21 @@ pigout(buf, len)
char *buf;
int len;
{
- register int ch, start;
- int olen;
+ int ch, start, i;
+ int olen, allupper, firstupper;
+
+ /* See if the word is all upper case */
+ allupper = firstupper = isupper(buf[0]);
+ for (i = 1; i < len && allupper; i++)
+ allupper = allupper && isupper(buf[i]);
/*
* If the word starts with a vowel, append "way". Don't treat 'y'
* as a vowel if it appears first.
*/
if (strchr("aeiouAEIOU", buf[0]) != NULL) {
- (void)printf("%.*sway", len, buf);
+ (void)printf("%.*s%s", len, buf,
+ allupper ? "WAY" : "way");
return;
}
@@ -118,6 +125,8 @@ pigout(buf, len)
* Copy leading consonants to the end of the word. The unit "qu"
* isn't treated as a vowel.
*/
+ if (!allupper)
+ buf[0] = tolower(buf[0]);
for (start = 0, olen = len;
!strchr("aeiouyAEIOUY", buf[start]) && start < olen;) {
ch = buf[len++] = buf[start++];
@@ -125,7 +134,9 @@ pigout(buf, len)
(buf[start] == 'u' || buf[start] == 'U'))
buf[len++] = buf[start++];
}
- (void)printf("%.*say", olen, buf + start);
+ if (firstupper)
+ buf[start] = toupper(buf[start]);
+ (void)printf("%.*s%s", olen, buf + start, allupper ? "AY" : "ay");
}
void