2 ** Copyright (c) 1999, 2000, 2001, 2002, 2003
3 ** Adel I. Mirzazhanov. All rights reserved
5 ** Redistribution and use in source and binary forms, with or without
6 ** modification, are permitted provided that the following conditions
9 ** 1.Redistributions of source code must retain the above copyright notice,
10 ** this list of conditions and the following disclaimer.
11 ** 2.Redistributions in binary form must reproduce the above copyright
12 ** notice, this list of conditions and the following disclaimer in the
13 ** documentation and/or other materials provided with the distribution.
14 ** 3.The name of the author may not be used to endorse or promote products
15 ** derived from this software without specific prior written permission.
17 ** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
18 ** OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 ** WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 ** ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
21 ** DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 ** DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
23 ** GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 ** INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
25 ** WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
26 ** NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27 ** SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
46 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
47 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't',
48 'u', 'v', 'w', 'x', 'w', 'z'
53 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J',
54 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T',
55 'U', 'V', 'W', 'X', 'W', 'Z'
63 ** decapitalize() - This routine replaces all capital letters
64 ** to small letters in the word:
73 decapitalize (char *word)
75 int i = 0; /* counter */
76 int j = 0; /* counter */
77 int str_len = strlen(word);
78 for(j = 0; j < str_len; j++)
80 if(word[j] == clet[i])
86 ** capitalize() - This routine designed to modify sullable like this:
98 capitalize (char *syllable)
102 if ( randint(2) == TRUE)
104 (void)memcpy((void *)&tmp, (void *)syllable, sizeof(tmp));
105 for(i=0; i < 26; i++)
107 if (is_restricted_symbol(clet[i]) != TRUE)
108 (void)memcpy ((void *)syllable, (void *)&clet[i], 1);
113 ** numerize() - This routine designed to modify single-letter
114 ** syllable like this:
115 ** a ----> 1 or 2 or 3 etc.
116 ** u ----> 1 or 2 or 3 etc.
119 ** char * - single-letter syllable
126 numerize (char *syllable)
129 if ( (tmp = (char *)calloc(1, 4)) == NULL)
131 if ( strlen (syllable) == 1 )
133 (void) gen_rand_symbol(tmp, S_NB);
134 (void)memcpy ((void *)syllable, (void *)tmp, 1);
139 ** specialize() - This routine designed to modify single-letter syllable
141 ** a ----> # or $ or % etc.
142 ** u ----> # or $ or % etc.
145 ** char * - single-letter syllable.
152 specialize (char *syllable)
155 if ( (tmp = (char *)calloc(1, 4)) == NULL)
157 if ( strlen (syllable) == 1 )
159 (void) gen_rand_symbol(tmp, S_SS);
160 (void)memcpy ((void *)syllable, (void *)tmp, 1);
166 ** symb2name - convert symbol to it's name
168 ** char * - one symbol syllable
175 symb2name(char * syllable, char * h_syllable)
182 static struct ssymb_names ssn[42] =
194 {33, "EXCLAMATION_POINT"},
195 {34, "QUOTATION_MARK"},
198 {37, "PERCENT_SIGN"},
201 {40, "LEFT_PARENTHESIS"},
202 {41, "RIGHT_PARENTHESIS"},
213 {62, "GREATER_THAN"},
214 {63, "QUESTION_MARK"},
216 {91, "LEFT_BRACKET"},
218 {93, "RIGHT_BRACKET"},
223 {124, "VERTICAL_BAR"},
224 {125, "RIGHT_BRACE"},
230 if (strlen(syllable) == 1)
232 for (i = 0; i < 42; i++)
234 if(*syllable == ssn[i].symbol)
236 (void)memcpy((void*)h_syllable, (void*)ssn[i].name, strlen(ssn[i].name));
241 (void)memcpy((void*)h_syllable, (void*)syllable, strlen(syllable));
246 ** spell_word - spell the word
248 ** char * - pointer to the word
249 ** char * - pointer to the spelled word
251 ** char * - pointer to the spelled word
252 ** NULL - something is wrong
254 ** You should free() memory pointed by spelled_word after each use of spell_word
257 spell_word(char * word, char * spelled_word)
264 static struct char_spell cs[94] =
328 {33, "EXCLAMATION_POINT"},
329 {34, "QUOTATION_MARK" },
331 {36, "DOLLAR_SIGN" },
332 {37, "PERCENT_SIGN" },
335 {40, "LEFT_PARENTHESIS" },
336 {41, "RIGHT_PARENTHESIS"},
347 {62, "GREATER_THAN" },
348 {63, "QUESTION_MARK" },
350 {91, "LEFT_BRACKET" },
352 {93, "RIGHT_BRACKET" },
356 {123, "LEFT_BRACE" },
357 {124, "VERTICAL_BAR" },
358 {125, "RIGHT_BRACE" },
364 int word_len = strlen(word);
369 /* Count the length of the spelled word */
370 for (i=0; i <= word_len; i++)
371 for (j=0; j < 94; j++)
372 if (word[i] == cs[j].symbol)
374 s_length = s_length + strlen(cs[j].name) + 1;
378 /* Allocate memory for spelled word */
379 if ( (spelled_word = (char *)calloc(1, (size_t)s_length)) == NULL)
382 /* Construct spelled word */
383 tmp_ptr = spelled_word;
385 for (i=0; i < word_len; i++)
386 for (j=0; j < 94; j++)
387 if (word[i] == cs[j].symbol)
389 (void) memcpy((void *)tmp_ptr, (void *)cs[j].name, strlen(cs[j].name));
390 tmp_ptr = tmp_ptr + strlen(cs[j].name);
391 /* Place the hyphen after each symbol */
392 (void) memcpy((void *)(tmp_ptr), (void *)&hyphen, 1);
393 tmp_ptr = tmp_ptr + 1;
397 /* Remove hyphen at the end of the word */
398 tmp_ptr = tmp_ptr - 1;
399 (void) memcpy((void *)(tmp_ptr), (void *)&zero, 1);
401 return (spelled_word);