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.
32 #if !defined(WIN32) && !defined(_WIN32) && !defined(__WIN32) && !defined(__WIN32__)
40 #include "base/rand_util.h"
50 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
51 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't',
52 'u', 'v', 'w', 'x', 'w', 'z'
57 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J',
58 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T',
59 'U', 'V', 'W', 'X', 'W', 'Z'
67 ** decapitalize() - This routine replaces all capital letters
68 ** to small letters in the word:
77 decapitalize (char *word
)
79 int i
= 0; /* counter */
80 int j
= 0; /* counter */
81 int str_len
= (int) strlen(word
);
82 for(j
= 0; j
< str_len
; j
++)
84 if(word
[j
] == clet
[i
])
90 ** capitalize() - This routine designed to modify sullable like this:
102 capitalize (char *syllable
)
106 if (base::RandInt(0, 1) == 1)
108 (void)memcpy((void *)&tmp
, (void *)syllable
, sizeof(tmp
));
109 for(i
=0; i
< 26; i
++)
111 if (is_restricted_symbol(clet
[i
]) != TRUE
)
112 (void)memcpy ((void *)syllable
, (void *)&clet
[i
], 1);
117 ** numerize() - This routine designed to modify single-letter
118 ** syllable like this:
119 ** a ----> 1 or 2 or 3 etc.
120 ** u ----> 1 or 2 or 3 etc.
123 ** char * - single-letter syllable
130 numerize (char *syllable
)
132 char *tmp
= (char *)calloc(1, 4);
133 if ( strlen (syllable
) == 1 )
135 (void) gen_rand_symbol(tmp
, S_NB
);
136 (void)memcpy ((void *)syllable
, (void *)tmp
, 1);
141 ** specialize() - This routine designed to modify single-letter syllable
143 ** a ----> # or $ or % etc.
144 ** u ----> # or $ or % etc.
147 ** char * - single-letter syllable.
154 specialize (char *syllable
)
156 char *tmp
= (char *)calloc(1, 4);
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 const 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
= (int) 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
+ (int) 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
);