155918Sbostic /*- 2*60827Sbostic * Copyright (c) 1992, 1993 3*60827Sbostic * The Regents of the University of California. All rights reserved. 455918Sbostic * 555918Sbostic * %sccs.include.redist.c% 655918Sbostic */ 755918Sbostic 855918Sbostic #ifndef lint 9*60827Sbostic static char copyright[] = 10*60827Sbostic "@(#) Copyright (c) 1992, 1993\n\ 11*60827Sbostic The Regents of the University of California. All rights reserved.\n"; 1255918Sbostic #endif /* not lint */ 1355918Sbostic 1455918Sbostic #ifndef lint 15*60827Sbostic static char sccsid[] = "@(#)pig.c 8.1 (Berkeley) 05/31/93"; 1655918Sbostic #endif /* not lint */ 1755918Sbostic 1855918Sbostic #include <sys/types.h> 1955918Sbostic 2055918Sbostic #include <ctype.h> 2155918Sbostic #include <stdio.h> 2255918Sbostic #include <stdlib.h> 2355918Sbostic #include <string.h> 2455918Sbostic 2555918Sbostic void pigout __P((char *, int)); 2655918Sbostic void usage __P((void)); 2755918Sbostic 2855918Sbostic int 2955918Sbostic main(argc, argv) 3055918Sbostic int argc; 3155918Sbostic char *argv[]; 3255918Sbostic { 3355918Sbostic register int len; 3455918Sbostic int ch; 3555918Sbostic char buf[1024]; 3655918Sbostic 3755918Sbostic while ((ch = getopt(argc, argv, "")) != EOF) 3855918Sbostic switch(ch) { 3955918Sbostic case '?': 4055918Sbostic default: 4155918Sbostic usage(); 4255918Sbostic } 4355918Sbostic argc -= optind; 4455918Sbostic argv += optind; 4555918Sbostic 4655918Sbostic for (len = 0; (ch = getchar()) != EOF;) { 4755918Sbostic if (isalpha(ch)) { 4855918Sbostic if (len >= sizeof(buf)) { 4955918Sbostic (void)fprintf(stderr, "pig: ate too much!\n"); 5055918Sbostic exit(1); 5155918Sbostic } 5255918Sbostic buf[len++] = ch; 5355918Sbostic continue; 5455918Sbostic } 5555918Sbostic if (len != 0) { 5655918Sbostic pigout(buf, len); 5755918Sbostic len = 0; 5855918Sbostic } 5955918Sbostic (void)putchar(ch); 6055918Sbostic } 6155918Sbostic exit(0); 6255918Sbostic } 6355918Sbostic 6455918Sbostic void 6555918Sbostic pigout(buf, len) 6655918Sbostic char *buf; 6755918Sbostic int len; 6855918Sbostic { 6955918Sbostic register int ch, start; 7055918Sbostic int olen; 7155918Sbostic 7255918Sbostic /* 7355918Sbostic * If the word starts with a vowel, append "way". Don't treat 'y' 7455918Sbostic * as a vowel if it appears first. 7555918Sbostic */ 7655918Sbostic if (index("aeiouAEIOU", buf[0]) != NULL) { 7755918Sbostic (void)printf("%.*sway", len, buf); 7855918Sbostic return; 7955918Sbostic } 8055918Sbostic 8155918Sbostic /* 8255918Sbostic * Copy leading consonants to the end of the word. The unit "qu" 8355918Sbostic * isn't treated as a vowel. 8455918Sbostic */ 8555918Sbostic for (start = 0, olen = len; 8655918Sbostic !index("aeiouyAEIOUY", buf[start]) && start < olen;) { 8755918Sbostic ch = buf[len++] = buf[start++]; 8855918Sbostic if ((ch == 'q' || ch == 'Q') && start < olen && 8955918Sbostic (buf[start] == 'u' || buf[start] == 'U')) 9055918Sbostic buf[len++] = buf[start++]; 9155918Sbostic } 9255918Sbostic (void)printf("%.*say", olen, buf + start); 9355918Sbostic } 9455918Sbostic 9555918Sbostic void 9655918Sbostic usage() 9755918Sbostic { 9855918Sbostic (void)fprintf(stderr, "usage: pig\n"); 9955918Sbostic exit(1); 10055918Sbostic } 101