dmake: do not set MAKEFLAGS=k
[unleashed/tickless.git] / usr / src / cmd / sgs / tools / common / piglatin.c
blobdb656eb5877373ac09fcd4353b14b2448d63eb31
1 /*
2 * CDDL HEADER START
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]
19 * CDDL HEADER END
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"
38 #include <stdio.h>
39 #include <strings.h>
40 #include <ctype.h>
42 int
43 main()
45 char buffer[32767], * cb, * sb;
46 int ic, ignore = 0, word = 0;
48 sb = cb = &buffer[0];
49 *sb = '\0';
51 while ((ic = getc(stdin)) != EOF) {
52 char c = (char)ic;
55 * Ignore all possible formatting statements.
57 if (c == '%')
58 ignore = 1;
61 * Isolate the word that will be converted.
63 if (isspace(ic) || (ispunct(ic) && ((ignore == 0) ||
64 ((c != '%') && (c != '.') && (c != '#') && (c != '-'))))) {
65 char s = buffer[0];
68 * If we haven't collected any words yet simply
69 * printf the last character.
71 if (word == 0) {
72 (void) putc(ic, stdout);
73 continue;
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");
91 } else {
93 * Move first letter to the end
94 * of the word and add "ay".
96 sb++;
97 *cb = s;
98 (void) strcpy(++cb, "ay");
100 } else
101 *cb = '\0';
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];
111 word = ignore = 0;
113 continue;
117 * Store this character into the word buffer.
119 *cb++ = c;
120 *cb = '\0';
121 word = 1;
124 return (0);