1*0Sstevel@tonic-gate /*
2*0Sstevel@tonic-gate  * CDDL HEADER START
3*0Sstevel@tonic-gate  *
4*0Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*0Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*0Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*0Sstevel@tonic-gate  * with the License.
8*0Sstevel@tonic-gate  *
9*0Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*0Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*0Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*0Sstevel@tonic-gate  * and limitations under the License.
13*0Sstevel@tonic-gate  *
14*0Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*0Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*0Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*0Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*0Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*0Sstevel@tonic-gate  *
20*0Sstevel@tonic-gate  * CDDL HEADER END
21*0Sstevel@tonic-gate  */
22*0Sstevel@tonic-gate /*
23*0Sstevel@tonic-gate  *	Copyright 2000, 2002 Sun Microsystems, Inc.
24*0Sstevel@tonic-gate  *	All rights reserved.
25*0Sstevel@tonic-gate  *	Use is subject to license terms.
26*0Sstevel@tonic-gate  *
27*0Sstevel@tonic-gate  * Very crude pig latin converter.
28*0Sstevel@tonic-gate  * Piglatin is an encoded form of English that is often used by  children
29*0Sstevel@tonic-gate  * as a game. A piglatin word is formed from an English word by:
30*0Sstevel@tonic-gate  *
31*0Sstevel@tonic-gate  *  .	If the word begins with a consonant, move the consonant to the end of
32*0Sstevel@tonic-gate  *	the word and append the letters "ay". Example: "door" becomes "oorday".
33*0Sstevel@tonic-gate  *
34*0Sstevel@tonic-gate  *  .	If the word begins with a vowel, merely append "way" to the word.
35*0Sstevel@tonic-gate  *	Example: "ate" becomes "ateway
36*0Sstevel@tonic-gate  */
37*0Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
38*0Sstevel@tonic-gate 
39*0Sstevel@tonic-gate #include <stdio.h>
40*0Sstevel@tonic-gate #include <strings.h>
41*0Sstevel@tonic-gate #include <ctype.h>
42*0Sstevel@tonic-gate 
43*0Sstevel@tonic-gate int
44*0Sstevel@tonic-gate main()
45*0Sstevel@tonic-gate {
46*0Sstevel@tonic-gate 	char	buffer[200], * cb, * sb;
47*0Sstevel@tonic-gate 	int	ic, ignore = 0, word = 0;
48*0Sstevel@tonic-gate 
49*0Sstevel@tonic-gate 	sb = cb = &buffer[0];
50*0Sstevel@tonic-gate 	*sb = '\0';
51*0Sstevel@tonic-gate 
52*0Sstevel@tonic-gate 	while ((ic = getc(stdin)) != EOF) {
53*0Sstevel@tonic-gate 		char c = (char)ic;
54*0Sstevel@tonic-gate 
55*0Sstevel@tonic-gate 		/*
56*0Sstevel@tonic-gate 		 * Ignore all possible formatting statements.
57*0Sstevel@tonic-gate 		 */
58*0Sstevel@tonic-gate 		if (c == '%')
59*0Sstevel@tonic-gate 			ignore = 1;
60*0Sstevel@tonic-gate 
61*0Sstevel@tonic-gate 		/*
62*0Sstevel@tonic-gate 		 * Isolate the word that will be converted.
63*0Sstevel@tonic-gate 		 */
64*0Sstevel@tonic-gate 		if (isspace(ic) || (ispunct(ic) && ((ignore == 0) ||
65*0Sstevel@tonic-gate 		    ((c != '%') && (c != '.') && (c != '#') && (c != '-'))))) {
66*0Sstevel@tonic-gate 			char s = buffer[0];
67*0Sstevel@tonic-gate 
68*0Sstevel@tonic-gate 			/*
69*0Sstevel@tonic-gate 			 * If we haven't collected any words yet simply
70*0Sstevel@tonic-gate 			 * printf the last character.
71*0Sstevel@tonic-gate 			 */
72*0Sstevel@tonic-gate 			if (word == 0) {
73*0Sstevel@tonic-gate 				(void) putc(ic, stdout);
74*0Sstevel@tonic-gate 				continue;
75*0Sstevel@tonic-gate 			}
76*0Sstevel@tonic-gate 
77*0Sstevel@tonic-gate 			/*
78*0Sstevel@tonic-gate 			 * Leave format strings alone - contain "%".
79*0Sstevel@tonic-gate 			 * Leave single characters alone, typically
80*0Sstevel@tonic-gate 			 * these result from "\n", "\t" etc.
81*0Sstevel@tonic-gate 			 */
82*0Sstevel@tonic-gate 			if ((ignore == 0) && ((cb - buffer) > 1)) {
83*0Sstevel@tonic-gate 				if ((s == 'a') || (s == 'A') ||
84*0Sstevel@tonic-gate 				    (s == 'e') || (s == 'E') ||
85*0Sstevel@tonic-gate 				    (s == 'i') || (s == 'I') ||
86*0Sstevel@tonic-gate 				    (s == 'o') || (s == 'O') ||
87*0Sstevel@tonic-gate 				    (s == 'u') || (s == 'U')) {
88*0Sstevel@tonic-gate 					/*
89*0Sstevel@tonic-gate 					 * Append "way" to the word.
90*0Sstevel@tonic-gate 					 */
91*0Sstevel@tonic-gate 					(void) strcpy(cb, "way");
92*0Sstevel@tonic-gate 				} else {
93*0Sstevel@tonic-gate 					/*
94*0Sstevel@tonic-gate 					 * Move first letter to the end
95*0Sstevel@tonic-gate 					 * of the word and add "ay".
96*0Sstevel@tonic-gate 					 */
97*0Sstevel@tonic-gate 					sb++;
98*0Sstevel@tonic-gate 					*cb = s;
99*0Sstevel@tonic-gate 					(void) strcpy(++cb, "ay");
100*0Sstevel@tonic-gate 				}
101*0Sstevel@tonic-gate 			} else
102*0Sstevel@tonic-gate 				*cb = '\0';
103*0Sstevel@tonic-gate 
104*0Sstevel@tonic-gate 			/*
105*0Sstevel@tonic-gate 			 * Output the collected buffer, the last character
106*0Sstevel@tonic-gate 			 * read and reinitialize pointers for next round.
107*0Sstevel@tonic-gate 			 */
108*0Sstevel@tonic-gate 			(void) printf("%s", sb);
109*0Sstevel@tonic-gate 			(void) putc(ic, stdout);
110*0Sstevel@tonic-gate 
111*0Sstevel@tonic-gate 			sb = cb = &buffer[0];
112*0Sstevel@tonic-gate 			word = ignore = 0;
113*0Sstevel@tonic-gate 
114*0Sstevel@tonic-gate 			continue;
115*0Sstevel@tonic-gate 		}
116*0Sstevel@tonic-gate 
117*0Sstevel@tonic-gate 		/*
118*0Sstevel@tonic-gate 		 * Store this character into the word buffer.
119*0Sstevel@tonic-gate 		 */
120*0Sstevel@tonic-gate 		*cb++ = c;
121*0Sstevel@tonic-gate 		*cb = '\0';
122*0Sstevel@tonic-gate 		word = 1;
123*0Sstevel@tonic-gate 	}
124*0Sstevel@tonic-gate 
125*0Sstevel@tonic-gate 	return (0);
126*0Sstevel@tonic-gate }
127