17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*d29b2c44Sab196087  * Common Development and Distribution License (the "License").
6*d29b2c44Sab196087  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
22*d29b2c44Sab196087  *	Copyright 2007 Sun Microsystems, Inc.
237c478bd9Sstevel@tonic-gate  *	All rights reserved.
247c478bd9Sstevel@tonic-gate  *	Use is subject to license terms.
257c478bd9Sstevel@tonic-gate  *
267c478bd9Sstevel@tonic-gate  * Very crude pig latin converter.
277c478bd9Sstevel@tonic-gate  * Piglatin is an encoded form of English that is often used by  children
287c478bd9Sstevel@tonic-gate  * as a game. A piglatin word is formed from an English word by:
297c478bd9Sstevel@tonic-gate  *
307c478bd9Sstevel@tonic-gate  *  .	If the word begins with a consonant, move the consonant to the end of
317c478bd9Sstevel@tonic-gate  *	the word and append the letters "ay". Example: "door" becomes "oorday".
327c478bd9Sstevel@tonic-gate  *
337c478bd9Sstevel@tonic-gate  *  .	If the word begins with a vowel, merely append "way" to the word.
347c478bd9Sstevel@tonic-gate  *	Example: "ate" becomes "ateway
357c478bd9Sstevel@tonic-gate  */
367c478bd9Sstevel@tonic-gate 
377c478bd9Sstevel@tonic-gate #include <stdio.h>
387c478bd9Sstevel@tonic-gate #include <strings.h>
397c478bd9Sstevel@tonic-gate #include <ctype.h>
407c478bd9Sstevel@tonic-gate 
417c478bd9Sstevel@tonic-gate int
main()427c478bd9Sstevel@tonic-gate main()
437c478bd9Sstevel@tonic-gate {
44*d29b2c44Sab196087 	char	buffer[32767], * cb, * sb;
457c478bd9Sstevel@tonic-gate 	int	ic, ignore = 0, word = 0;
467c478bd9Sstevel@tonic-gate 
477c478bd9Sstevel@tonic-gate 	sb = cb = &buffer[0];
487c478bd9Sstevel@tonic-gate 	*sb = '\0';
497c478bd9Sstevel@tonic-gate 
507c478bd9Sstevel@tonic-gate 	while ((ic = getc(stdin)) != EOF) {
517c478bd9Sstevel@tonic-gate 		char c = (char)ic;
527c478bd9Sstevel@tonic-gate 
537c478bd9Sstevel@tonic-gate 		/*
547c478bd9Sstevel@tonic-gate 		 * Ignore all possible formatting statements.
557c478bd9Sstevel@tonic-gate 		 */
567c478bd9Sstevel@tonic-gate 		if (c == '%')
577c478bd9Sstevel@tonic-gate 			ignore = 1;
587c478bd9Sstevel@tonic-gate 
597c478bd9Sstevel@tonic-gate 		/*
607c478bd9Sstevel@tonic-gate 		 * Isolate the word that will be converted.
617c478bd9Sstevel@tonic-gate 		 */
627c478bd9Sstevel@tonic-gate 		if (isspace(ic) || (ispunct(ic) && ((ignore == 0) ||
637c478bd9Sstevel@tonic-gate 		    ((c != '%') && (c != '.') && (c != '#') && (c != '-'))))) {
647c478bd9Sstevel@tonic-gate 			char s = buffer[0];
657c478bd9Sstevel@tonic-gate 
667c478bd9Sstevel@tonic-gate 			/*
677c478bd9Sstevel@tonic-gate 			 * If we haven't collected any words yet simply
687c478bd9Sstevel@tonic-gate 			 * printf the last character.
697c478bd9Sstevel@tonic-gate 			 */
707c478bd9Sstevel@tonic-gate 			if (word == 0) {
717c478bd9Sstevel@tonic-gate 				(void) putc(ic, stdout);
727c478bd9Sstevel@tonic-gate 				continue;
737c478bd9Sstevel@tonic-gate 			}
747c478bd9Sstevel@tonic-gate 
757c478bd9Sstevel@tonic-gate 			/*
767c478bd9Sstevel@tonic-gate 			 * Leave format strings alone - contain "%".
777c478bd9Sstevel@tonic-gate 			 * Leave single characters alone, typically
787c478bd9Sstevel@tonic-gate 			 * these result from "\n", "\t" etc.
797c478bd9Sstevel@tonic-gate 			 */
807c478bd9Sstevel@tonic-gate 			if ((ignore == 0) && ((cb - buffer) > 1)) {
817c478bd9Sstevel@tonic-gate 				if ((s == 'a') || (s == 'A') ||
827c478bd9Sstevel@tonic-gate 				    (s == 'e') || (s == 'E') ||
837c478bd9Sstevel@tonic-gate 				    (s == 'i') || (s == 'I') ||
847c478bd9Sstevel@tonic-gate 				    (s == 'o') || (s == 'O') ||
857c478bd9Sstevel@tonic-gate 				    (s == 'u') || (s == 'U')) {
867c478bd9Sstevel@tonic-gate 					/*
877c478bd9Sstevel@tonic-gate 					 * Append "way" to the word.
887c478bd9Sstevel@tonic-gate 					 */
897c478bd9Sstevel@tonic-gate 					(void) strcpy(cb, "way");
907c478bd9Sstevel@tonic-gate 				} else {
917c478bd9Sstevel@tonic-gate 					/*
927c478bd9Sstevel@tonic-gate 					 * Move first letter to the end
937c478bd9Sstevel@tonic-gate 					 * of the word and add "ay".
947c478bd9Sstevel@tonic-gate 					 */
957c478bd9Sstevel@tonic-gate 					sb++;
967c478bd9Sstevel@tonic-gate 					*cb = s;
977c478bd9Sstevel@tonic-gate 					(void) strcpy(++cb, "ay");
987c478bd9Sstevel@tonic-gate 				}
997c478bd9Sstevel@tonic-gate 			} else
1007c478bd9Sstevel@tonic-gate 				*cb = '\0';
1017c478bd9Sstevel@tonic-gate 
1027c478bd9Sstevel@tonic-gate 			/*
1037c478bd9Sstevel@tonic-gate 			 * Output the collected buffer, the last character
1047c478bd9Sstevel@tonic-gate 			 * read and reinitialize pointers for next round.
1057c478bd9Sstevel@tonic-gate 			 */
1067c478bd9Sstevel@tonic-gate 			(void) printf("%s", sb);
1077c478bd9Sstevel@tonic-gate 			(void) putc(ic, stdout);
1087c478bd9Sstevel@tonic-gate 
1097c478bd9Sstevel@tonic-gate 			sb = cb = &buffer[0];
1107c478bd9Sstevel@tonic-gate 			word = ignore = 0;
1117c478bd9Sstevel@tonic-gate 
1127c478bd9Sstevel@tonic-gate 			continue;
1137c478bd9Sstevel@tonic-gate 		}
1147c478bd9Sstevel@tonic-gate 
1157c478bd9Sstevel@tonic-gate 		/*
1167c478bd9Sstevel@tonic-gate 		 * Store this character into the word buffer.
1177c478bd9Sstevel@tonic-gate 		 */
1187c478bd9Sstevel@tonic-gate 		*cb++ = c;
1197c478bd9Sstevel@tonic-gate 		*cb = '\0';
1207c478bd9Sstevel@tonic-gate 		word = 1;
1217c478bd9Sstevel@tonic-gate 	}
1227c478bd9Sstevel@tonic-gate 
1237c478bd9Sstevel@tonic-gate 	return (0);
1247c478bd9Sstevel@tonic-gate }
125