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 #pragma ident "%Z%%M% %I% %E% SMI"
377c478bd9Sstevel@tonic-gate
387c478bd9Sstevel@tonic-gate #include <stdio.h>
397c478bd9Sstevel@tonic-gate #include <strings.h>
407c478bd9Sstevel@tonic-gate #include <ctype.h>
417c478bd9Sstevel@tonic-gate
427c478bd9Sstevel@tonic-gate int
main()437c478bd9Sstevel@tonic-gate main()
447c478bd9Sstevel@tonic-gate {
45*d29b2c44Sab196087 char buffer[32767], * cb, * sb;
467c478bd9Sstevel@tonic-gate int ic, ignore = 0, word = 0;
477c478bd9Sstevel@tonic-gate
487c478bd9Sstevel@tonic-gate sb = cb = &buffer[0];
497c478bd9Sstevel@tonic-gate *sb = '\0';
507c478bd9Sstevel@tonic-gate
517c478bd9Sstevel@tonic-gate while ((ic = getc(stdin)) != EOF) {
527c478bd9Sstevel@tonic-gate char c = (char)ic;
537c478bd9Sstevel@tonic-gate
547c478bd9Sstevel@tonic-gate /*
557c478bd9Sstevel@tonic-gate * Ignore all possible formatting statements.
567c478bd9Sstevel@tonic-gate */
577c478bd9Sstevel@tonic-gate if (c == '%')
587c478bd9Sstevel@tonic-gate ignore = 1;
597c478bd9Sstevel@tonic-gate
607c478bd9Sstevel@tonic-gate /*
617c478bd9Sstevel@tonic-gate * Isolate the word that will be converted.
627c478bd9Sstevel@tonic-gate */
637c478bd9Sstevel@tonic-gate if (isspace(ic) || (ispunct(ic) && ((ignore == 0) ||
647c478bd9Sstevel@tonic-gate ((c != '%') && (c != '.') && (c != '#') && (c != '-'))))) {
657c478bd9Sstevel@tonic-gate char s = buffer[0];
667c478bd9Sstevel@tonic-gate
677c478bd9Sstevel@tonic-gate /*
687c478bd9Sstevel@tonic-gate * If we haven't collected any words yet simply
697c478bd9Sstevel@tonic-gate * printf the last character.
707c478bd9Sstevel@tonic-gate */
717c478bd9Sstevel@tonic-gate if (word == 0) {
727c478bd9Sstevel@tonic-gate (void) putc(ic, stdout);
737c478bd9Sstevel@tonic-gate continue;
747c478bd9Sstevel@tonic-gate }
757c478bd9Sstevel@tonic-gate
767c478bd9Sstevel@tonic-gate /*
777c478bd9Sstevel@tonic-gate * Leave format strings alone - contain "%".
787c478bd9Sstevel@tonic-gate * Leave single characters alone, typically
797c478bd9Sstevel@tonic-gate * these result from "\n", "\t" etc.
807c478bd9Sstevel@tonic-gate */
817c478bd9Sstevel@tonic-gate if ((ignore == 0) && ((cb - buffer) > 1)) {
827c478bd9Sstevel@tonic-gate if ((s == 'a') || (s == 'A') ||
837c478bd9Sstevel@tonic-gate (s == 'e') || (s == 'E') ||
847c478bd9Sstevel@tonic-gate (s == 'i') || (s == 'I') ||
857c478bd9Sstevel@tonic-gate (s == 'o') || (s == 'O') ||
867c478bd9Sstevel@tonic-gate (s == 'u') || (s == 'U')) {
877c478bd9Sstevel@tonic-gate /*
887c478bd9Sstevel@tonic-gate * Append "way" to the word.
897c478bd9Sstevel@tonic-gate */
907c478bd9Sstevel@tonic-gate (void) strcpy(cb, "way");
917c478bd9Sstevel@tonic-gate } else {
927c478bd9Sstevel@tonic-gate /*
937c478bd9Sstevel@tonic-gate * Move first letter to the end
947c478bd9Sstevel@tonic-gate * of the word and add "ay".
957c478bd9Sstevel@tonic-gate */
967c478bd9Sstevel@tonic-gate sb++;
977c478bd9Sstevel@tonic-gate *cb = s;
987c478bd9Sstevel@tonic-gate (void) strcpy(++cb, "ay");
997c478bd9Sstevel@tonic-gate }
1007c478bd9Sstevel@tonic-gate } else
1017c478bd9Sstevel@tonic-gate *cb = '\0';
1027c478bd9Sstevel@tonic-gate
1037c478bd9Sstevel@tonic-gate /*
1047c478bd9Sstevel@tonic-gate * Output the collected buffer, the last character
1057c478bd9Sstevel@tonic-gate * read and reinitialize pointers for next round.
1067c478bd9Sstevel@tonic-gate */
1077c478bd9Sstevel@tonic-gate (void) printf("%s", sb);
1087c478bd9Sstevel@tonic-gate (void) putc(ic, stdout);
1097c478bd9Sstevel@tonic-gate
1107c478bd9Sstevel@tonic-gate sb = cb = &buffer[0];
1117c478bd9Sstevel@tonic-gate word = ignore = 0;
1127c478bd9Sstevel@tonic-gate
1137c478bd9Sstevel@tonic-gate continue;
1147c478bd9Sstevel@tonic-gate }
1157c478bd9Sstevel@tonic-gate
1167c478bd9Sstevel@tonic-gate /*
1177c478bd9Sstevel@tonic-gate * Store this character into the word buffer.
1187c478bd9Sstevel@tonic-gate */
1197c478bd9Sstevel@tonic-gate *cb++ = c;
1207c478bd9Sstevel@tonic-gate *cb = '\0';
1217c478bd9Sstevel@tonic-gate word = 1;
1227c478bd9Sstevel@tonic-gate }
1237c478bd9Sstevel@tonic-gate
1247c478bd9Sstevel@tonic-gate return (0);
1257c478bd9Sstevel@tonic-gate }
126