10Sstevel@tonic-gate /*
20Sstevel@tonic-gate * CDDL HEADER START
30Sstevel@tonic-gate *
40Sstevel@tonic-gate * The contents of this file are subject to the terms of the
5*5088Sab196087 * Common Development and Distribution License (the "License").
6*5088Sab196087 * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate *
80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate * See the License for the specific language governing permissions
110Sstevel@tonic-gate * and limitations under the License.
120Sstevel@tonic-gate *
130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate *
190Sstevel@tonic-gate * CDDL HEADER END
200Sstevel@tonic-gate */
210Sstevel@tonic-gate /*
22*5088Sab196087 * Copyright 2007 Sun Microsystems, Inc.
230Sstevel@tonic-gate * All rights reserved.
240Sstevel@tonic-gate * Use is subject to license terms.
250Sstevel@tonic-gate *
260Sstevel@tonic-gate * Very crude pig latin converter.
270Sstevel@tonic-gate * Piglatin is an encoded form of English that is often used by children
280Sstevel@tonic-gate * as a game. A piglatin word is formed from an English word by:
290Sstevel@tonic-gate *
300Sstevel@tonic-gate * . If the word begins with a consonant, move the consonant to the end of
310Sstevel@tonic-gate * the word and append the letters "ay". Example: "door" becomes "oorday".
320Sstevel@tonic-gate *
330Sstevel@tonic-gate * . If the word begins with a vowel, merely append "way" to the word.
340Sstevel@tonic-gate * Example: "ate" becomes "ateway
350Sstevel@tonic-gate */
360Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI"
370Sstevel@tonic-gate
380Sstevel@tonic-gate #include <stdio.h>
390Sstevel@tonic-gate #include <strings.h>
400Sstevel@tonic-gate #include <ctype.h>
410Sstevel@tonic-gate
420Sstevel@tonic-gate int
main()430Sstevel@tonic-gate main()
440Sstevel@tonic-gate {
45*5088Sab196087 char buffer[32767], * cb, * sb;
460Sstevel@tonic-gate int ic, ignore = 0, word = 0;
470Sstevel@tonic-gate
480Sstevel@tonic-gate sb = cb = &buffer[0];
490Sstevel@tonic-gate *sb = '\0';
500Sstevel@tonic-gate
510Sstevel@tonic-gate while ((ic = getc(stdin)) != EOF) {
520Sstevel@tonic-gate char c = (char)ic;
530Sstevel@tonic-gate
540Sstevel@tonic-gate /*
550Sstevel@tonic-gate * Ignore all possible formatting statements.
560Sstevel@tonic-gate */
570Sstevel@tonic-gate if (c == '%')
580Sstevel@tonic-gate ignore = 1;
590Sstevel@tonic-gate
600Sstevel@tonic-gate /*
610Sstevel@tonic-gate * Isolate the word that will be converted.
620Sstevel@tonic-gate */
630Sstevel@tonic-gate if (isspace(ic) || (ispunct(ic) && ((ignore == 0) ||
640Sstevel@tonic-gate ((c != '%') && (c != '.') && (c != '#') && (c != '-'))))) {
650Sstevel@tonic-gate char s = buffer[0];
660Sstevel@tonic-gate
670Sstevel@tonic-gate /*
680Sstevel@tonic-gate * If we haven't collected any words yet simply
690Sstevel@tonic-gate * printf the last character.
700Sstevel@tonic-gate */
710Sstevel@tonic-gate if (word == 0) {
720Sstevel@tonic-gate (void) putc(ic, stdout);
730Sstevel@tonic-gate continue;
740Sstevel@tonic-gate }
750Sstevel@tonic-gate
760Sstevel@tonic-gate /*
770Sstevel@tonic-gate * Leave format strings alone - contain "%".
780Sstevel@tonic-gate * Leave single characters alone, typically
790Sstevel@tonic-gate * these result from "\n", "\t" etc.
800Sstevel@tonic-gate */
810Sstevel@tonic-gate if ((ignore == 0) && ((cb - buffer) > 1)) {
820Sstevel@tonic-gate if ((s == 'a') || (s == 'A') ||
830Sstevel@tonic-gate (s == 'e') || (s == 'E') ||
840Sstevel@tonic-gate (s == 'i') || (s == 'I') ||
850Sstevel@tonic-gate (s == 'o') || (s == 'O') ||
860Sstevel@tonic-gate (s == 'u') || (s == 'U')) {
870Sstevel@tonic-gate /*
880Sstevel@tonic-gate * Append "way" to the word.
890Sstevel@tonic-gate */
900Sstevel@tonic-gate (void) strcpy(cb, "way");
910Sstevel@tonic-gate } else {
920Sstevel@tonic-gate /*
930Sstevel@tonic-gate * Move first letter to the end
940Sstevel@tonic-gate * of the word and add "ay".
950Sstevel@tonic-gate */
960Sstevel@tonic-gate sb++;
970Sstevel@tonic-gate *cb = s;
980Sstevel@tonic-gate (void) strcpy(++cb, "ay");
990Sstevel@tonic-gate }
1000Sstevel@tonic-gate } else
1010Sstevel@tonic-gate *cb = '\0';
1020Sstevel@tonic-gate
1030Sstevel@tonic-gate /*
1040Sstevel@tonic-gate * Output the collected buffer, the last character
1050Sstevel@tonic-gate * read and reinitialize pointers for next round.
1060Sstevel@tonic-gate */
1070Sstevel@tonic-gate (void) printf("%s", sb);
1080Sstevel@tonic-gate (void) putc(ic, stdout);
1090Sstevel@tonic-gate
1100Sstevel@tonic-gate sb = cb = &buffer[0];
1110Sstevel@tonic-gate word = ignore = 0;
1120Sstevel@tonic-gate
1130Sstevel@tonic-gate continue;
1140Sstevel@tonic-gate }
1150Sstevel@tonic-gate
1160Sstevel@tonic-gate /*
1170Sstevel@tonic-gate * Store this character into the word buffer.
1180Sstevel@tonic-gate */
1190Sstevel@tonic-gate *cb++ = c;
1200Sstevel@tonic-gate *cb = '\0';
1210Sstevel@tonic-gate word = 1;
1220Sstevel@tonic-gate }
1230Sstevel@tonic-gate
1240Sstevel@tonic-gate return (0);
1250Sstevel@tonic-gate }
126