4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
22 * Copyright 2007 Sun Microsystems, Inc.
23 * All rights reserved.
24 * Use is subject to license terms.
26 * Very crude pig latin converter.
27 * Piglatin is an encoded form of English that is often used by children
28 * as a game. A piglatin word is formed from an English word by:
30 * . If the word begins with a consonant, move the consonant to the end of
31 * the word and append the letters "ay". Example: "door" becomes "oorday".
33 * . If the word begins with a vowel, merely append "way" to the word.
34 * Example: "ate" becomes "ateway
36 #pragma ident "%Z%%M% %I% %E% SMI"
45 char buffer
[32767], * cb
, * sb
;
46 int ic
, ignore
= 0, word
= 0;
51 while ((ic
= getc(stdin
)) != EOF
) {
55 * Ignore all possible formatting statements.
61 * Isolate the word that will be converted.
63 if (isspace(ic
) || (ispunct(ic
) && ((ignore
== 0) ||
64 ((c
!= '%') && (c
!= '.') && (c
!= '#') && (c
!= '-'))))) {
68 * If we haven't collected any words yet simply
69 * printf the last character.
72 (void) putc(ic
, stdout
);
77 * Leave format strings alone - contain "%".
78 * Leave single characters alone, typically
79 * these result from "\n", "\t" etc.
81 if ((ignore
== 0) && ((cb
- buffer
) > 1)) {
82 if ((s
== 'a') || (s
== 'A') ||
83 (s
== 'e') || (s
== 'E') ||
84 (s
== 'i') || (s
== 'I') ||
85 (s
== 'o') || (s
== 'O') ||
86 (s
== 'u') || (s
== 'U')) {
88 * Append "way" to the word.
90 (void) strcpy(cb
, "way");
93 * Move first letter to the end
94 * of the word and add "ay".
98 (void) strcpy(++cb
, "ay");
104 * Output the collected buffer, the last character
105 * read and reinitialize pointers for next round.
107 (void) printf("%s", sb
);
108 (void) putc(ic
, stdout
);
110 sb
= cb
= &buffer
[0];
117 * Store this character into the word buffer.