| OLD | NEW |
| 1 /* | 1 /* |
| 2 ** Copyright (c) 1999, 2000, 2001, 2002, 2003 | 2 ** Copyright (c) 1999, 2000, 2001, 2002, 2003 |
| 3 ** Adel I. Mirzazhanov. All rights reserved | 3 ** Adel I. Mirzazhanov. All rights reserved |
| 4 ** | 4 ** |
| 5 ** Redistribution and use in source and binary forms, with or without | 5 ** Redistribution and use in source and binary forms, with or without |
| 6 ** modification, are permitted provided that the following conditions | 6 ** modification, are permitted provided that the following conditions |
| 7 ** are met: | 7 ** are met: |
| 8 ** | 8 ** |
| 9 ** 1.Redistributions of source code must retain the above copyright notice, | 9 ** 1.Redistributions of source code must retain the above copyright notice, |
| 10 ** this list of conditions and the following disclaimer. | 10 ** this list of conditions and the following disclaimer. |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 ** NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | 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. | 27 ** SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 28 */ | 28 */ |
| 29 | 29 |
| 30 #include <stdlib.h> | 30 #include <stdlib.h> |
| 31 #include <string.h> | 31 #include <string.h> |
| 32 #if !defined(WIN32) && !defined(_WIN32) && !defined(__WIN32) && !defined(__WIN32
__) | 32 #if !defined(WIN32) && !defined(_WIN32) && !defined(__WIN32) && !defined(__WIN32
__) |
| 33 #include <strings.h> | 33 #include <strings.h> |
| 34 #endif | 34 #endif |
| 35 #ifndef APGBFM | 35 #ifndef APGBFM |
| 36 # include "errs.h" | 36 #include "fips181.h" |
| 37 # include "randpass.h" | 37 #include "randpass.h" |
| 38 #endif | 38 #endif |
| 39 | 39 |
| 40 #include "base/rand_util.h" |
| 40 #include "convert.h" | 41 #include "convert.h" |
| 41 | 42 |
| 42 /* | 43 /* |
| 43 ** GLOBALS | 44 ** GLOBALS |
| 44 */ | 45 */ |
| 45 | 46 |
| 46 /* small letters */ | 47 /* small letters */ |
| 47 char let[26] = | 48 char let[26] = |
| 48 { | 49 { |
| 49 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', | 50 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', |
| (...skipping 20 matching lines...) Expand all Loading... |
| 70 ** OUTPUT: | 71 ** OUTPUT: |
| 71 ** none. | 72 ** none. |
| 72 ** NOTES: | 73 ** NOTES: |
| 73 ** none. | 74 ** none. |
| 74 */ | 75 */ |
| 75 void | 76 void |
| 76 decapitalize (char *word) | 77 decapitalize (char *word) |
| 77 { | 78 { |
| 78 int i = 0; /* counter */ | 79 int i = 0; /* counter */ |
| 79 int j = 0; /* counter */ | 80 int j = 0; /* counter */ |
| 80 int str_len = strlen(word); | 81 int str_len = (int) strlen(word); |
| 81 for(j = 0; j < str_len; j++) | 82 for(j = 0; j < str_len; j++) |
| 82 for(i=0; i < 26; i++) | 83 for(i=0; i < 26; i++) |
| 83 if(word[j] == clet[i]) | 84 if(word[j] == clet[i]) |
| 84 word[j] = let[i]; | 85 word[j] = let[i]; |
| 85 } | 86 } |
| 86 | 87 |
| 87 #ifndef APGBFM | 88 #ifndef APGBFM |
| 88 /* | 89 /* |
| 89 ** capitalize() - This routine designed to modify sullable like this: | 90 ** capitalize() - This routine designed to modify sullable like this: |
| 90 ** adel ----> Adel | 91 ** adel ----> Adel |
| 91 ** dot ----> Dot | 92 ** dot ----> Dot |
| 92 ** etc. | 93 ** etc. |
| 93 ** INPUT: | 94 ** INPUT: |
| 94 ** char * - syllable. | 95 ** char * - syllable. |
| 95 ** OUTPUT: | 96 ** OUTPUT: |
| 96 ** none. | 97 ** none. |
| 97 ** NOTES: | 98 ** NOTES: |
| 98 ** none. | 99 ** none. |
| 99 */ | 100 */ |
| 100 void | 101 void |
| 101 capitalize (char *syllable) | 102 capitalize (char *syllable) |
| 102 { | 103 { |
| 103 char tmp = 0x00; | 104 char tmp = 0x00; |
| 104 int i = 0; | 105 int i = 0; |
| 105 if ( randint(2) == TRUE) | 106 if (base::RandInt(0, 1) == 1) |
| 106 { | 107 { |
| 107 (void)memcpy((void *)&tmp, (void *)syllable, sizeof(tmp)); | 108 (void)memcpy((void *)&tmp, (void *)syllable, sizeof(tmp)); |
| 108 for(i=0; i < 26; i++) | 109 for(i=0; i < 26; i++) |
| 109 if ( let[i] == tmp ) | 110 if ( let[i] == tmp ) |
| 110 if (is_restricted_symbol(clet[i]) != TRUE) | 111 if (is_restricted_symbol(clet[i]) != TRUE) |
| 111 (void)memcpy ((void *)syllable, (void *)&clet[i], 1); | 112 (void)memcpy ((void *)syllable, (void *)&clet[i], 1); |
| 112 } | 113 } |
| 113 } | 114 } |
| 114 | 115 |
| 115 /* | 116 /* |
| 116 ** numerize() - This routine designed to modify single-letter | 117 ** numerize() - This routine designed to modify single-letter |
| 117 ** syllable like this: | 118 ** syllable like this: |
| 118 ** a ----> 1 or 2 or 3 etc. | 119 ** a ----> 1 or 2 or 3 etc. |
| 119 ** u ----> 1 or 2 or 3 etc. | 120 ** u ----> 1 or 2 or 3 etc. |
| 120 ** etc. | 121 ** etc. |
| 121 ** INPUT: | 122 ** INPUT: |
| 122 ** char * - single-letter syllable | 123 ** char * - single-letter syllable |
| 123 ** OUTPUT: | 124 ** OUTPUT: |
| 124 ** none. | 125 ** none. |
| 125 ** NOTES: | 126 ** NOTES: |
| 126 ** none. | 127 ** none. |
| 127 */ | 128 */ |
| 128 void | 129 void |
| 129 numerize (char *syllable) | 130 numerize (char *syllable) |
| 130 { | 131 { |
| 131 char *tmp; | 132 char *tmp = (char *)calloc(1, 4); |
| 132 if ( (tmp = (char *)calloc(1, 4)) == NULL) | |
| 133 err_sys_fatal("calloc"); | |
| 134 if ( strlen (syllable) == 1 ) | 133 if ( strlen (syllable) == 1 ) |
| 135 { | 134 { |
| 136 (void) gen_rand_symbol(tmp, S_NB); | 135 (void) gen_rand_symbol(tmp, S_NB); |
| 137 (void)memcpy ((void *)syllable, (void *)tmp, 1); | 136 (void)memcpy ((void *)syllable, (void *)tmp, 1); |
| 138 } | 137 } |
| 139 free ((void *)tmp); | 138 free ((void *)tmp); |
| 140 } | 139 } |
| 141 /* | 140 /* |
| 142 ** specialize() - This routine designed to modify single-letter syllable | 141 ** specialize() - This routine designed to modify single-letter syllable |
| 143 ** like this: | 142 ** like this: |
| 144 ** a ----> # or $ or % etc. | 143 ** a ----> # or $ or % etc. |
| 145 ** u ----> # or $ or % etc. | 144 ** u ----> # or $ or % etc. |
| 146 ** etc. | 145 ** etc. |
| 147 ** INPUT: | 146 ** INPUT: |
| 148 ** char * - single-letter syllable. | 147 ** char * - single-letter syllable. |
| 149 ** OUTPUT: | 148 ** OUTPUT: |
| 150 ** none. | 149 ** none. |
| 151 ** NOTES: | 150 ** NOTES: |
| 152 ** none. | 151 ** none. |
| 153 */ | 152 */ |
| 154 void | 153 void |
| 155 specialize (char *syllable) | 154 specialize (char *syllable) |
| 156 { | 155 { |
| 157 char *tmp; | 156 char *tmp = (char *)calloc(1, 4); |
| 158 if ( (tmp = (char *)calloc(1, 4)) == NULL) | |
| 159 err_sys_fatal("calloc"); | |
| 160 if ( strlen (syllable) == 1 ) | 157 if ( strlen (syllable) == 1 ) |
| 161 { | 158 { |
| 162 (void) gen_rand_symbol(tmp, S_SS); | 159 (void) gen_rand_symbol(tmp, S_SS); |
| 163 (void)memcpy ((void *)syllable, (void *)tmp, 1); | 160 (void)memcpy ((void *)syllable, (void *)tmp, 1); |
| 164 } | 161 } |
| 165 free ((void *)tmp); | 162 free ((void *)tmp); |
| 166 } | 163 } |
| 167 | 164 |
| 168 /* | 165 /* |
| 169 ** symb2name - convert symbol to it's name | 166 ** symb2name - convert symbol to it's name |
| 170 ** INPUT: | 167 ** INPUT: |
| 171 ** char * - one symbol syllable | 168 ** char * - one symbol syllable |
| 172 ** OUTPUT: | 169 ** OUTPUT: |
| 173 ** none. | 170 ** none. |
| 174 ** NOTES: | 171 ** NOTES: |
| 175 ** none. | 172 ** none. |
| 176 */ | 173 */ |
| 177 void | 174 void |
| 178 symb2name(char * syllable, char * h_syllable) | 175 symb2name(char * syllable, char * h_syllable) |
| 179 { | 176 { |
| 180 struct ssymb_names | 177 struct ssymb_names |
| 181 { | 178 { |
| 182 char symbol; | 179 char symbol; |
| 183 char *name; | 180 const char * name; |
| 184 }; | 181 }; |
| 185 static struct ssymb_names ssn[42] = | 182 static const struct ssymb_names ssn[42] = |
| 186 { | 183 { |
| 187 {'1',"ONE"}, | 184 {'1',"ONE"}, |
| 188 {'2',"TWO"}, | 185 {'2',"TWO"}, |
| 189 {'3',"THREE"}, | 186 {'3',"THREE"}, |
| 190 {'4',"FOUR"}, | 187 {'4',"FOUR"}, |
| 191 {'5',"FIVE"}, | 188 {'5',"FIVE"}, |
| 192 {'6',"SIX"}, | 189 {'6',"SIX"}, |
| 193 {'7',"SEVEN"}, | 190 {'7',"SEVEN"}, |
| 194 {'8',"EIGHT"}, | 191 {'8',"EIGHT"}, |
| 195 {'9',"NINE"}, | 192 {'9',"NINE"}, |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 255 ** NULL - something is wrong | 252 ** NULL - something is wrong |
| 256 ** NOTES: | 253 ** NOTES: |
| 257 ** You should free() memory pointed by spelled_word after each use of spell_wo
rd | 254 ** You should free() memory pointed by spelled_word after each use of spell_wo
rd |
| 258 */ | 255 */ |
| 259 char * | 256 char * |
| 260 spell_word(char * word, char * spelled_word) | 257 spell_word(char * word, char * spelled_word) |
| 261 { | 258 { |
| 262 struct char_spell | 259 struct char_spell |
| 263 { | 260 { |
| 264 char symbol; | 261 char symbol; |
| 265 char *name; | 262 const char *name; |
| 266 }; | 263 }; |
| 267 static struct char_spell cs[94] = | 264 static struct char_spell cs[94] = |
| 268 { | 265 { |
| 269 {'1',"ONE" }, | 266 {'1',"ONE" }, |
| 270 {'2',"TWO" }, | 267 {'2',"TWO" }, |
| 271 {'3',"THREE" }, | 268 {'3',"THREE" }, |
| 272 {'4',"FOUR" }, | 269 {'4',"FOUR" }, |
| 273 {'5',"FIVE" }, | 270 {'5',"FIVE" }, |
| 274 {'6',"SIX" }, | 271 {'6',"SIX" }, |
| 275 {'7',"SEVEN" }, | 272 {'7',"SEVEN" }, |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 357 {95, "UNDERSCORE" }, | 354 {95, "UNDERSCORE" }, |
| 358 {96, "GRAVE" }, | 355 {96, "GRAVE" }, |
| 359 {123, "LEFT_BRACE" }, | 356 {123, "LEFT_BRACE" }, |
| 360 {124, "VERTICAL_BAR" }, | 357 {124, "VERTICAL_BAR" }, |
| 361 {125, "RIGHT_BRACE" }, | 358 {125, "RIGHT_BRACE" }, |
| 362 {126, "TILDE" } | 359 {126, "TILDE" } |
| 363 }; | 360 }; |
| 364 int s_length = 0; | 361 int s_length = 0; |
| 365 int i = 0; | 362 int i = 0; |
| 366 int j = 0; | 363 int j = 0; |
| 367 int word_len = strlen(word); | 364 int word_len = (int) strlen(word); |
| 368 char * tmp_ptr; | 365 char * tmp_ptr; |
| 369 char hyphen = '-'; | 366 char hyphen = '-'; |
| 370 char zero = 0x00; | 367 char zero = 0x00; |
| 371 | 368 |
| 372 /* Count the length of the spelled word */ | 369 /* Count the length of the spelled word */ |
| 373 for (i=0; i <= word_len; i++) | 370 for (i=0; i <= word_len; i++) |
| 374 for (j=0; j < 94; j++) | 371 for (j=0; j < 94; j++) |
| 375 if (word[i] == cs[j].symbol) | 372 if (word[i] == cs[j].symbol) |
| 376 { | 373 { |
| 377 s_length = s_length + strlen(cs[j].name) + 1; | 374 s_length = s_length + (int) strlen(cs[j].name) + 1; |
| 378 continue; | 375 continue; |
| 379 } | 376 } |
| 380 | 377 |
| 381 /* Allocate memory for spelled word */ | 378 /* Allocate memory for spelled word */ |
| 382 if ( (spelled_word = (char *)calloc(1, (size_t)s_length)) == NULL) | 379 if ( (spelled_word = (char *)calloc(1, (size_t)s_length)) == NULL) |
| 383 return(NULL); | 380 return(NULL); |
| 384 | 381 |
| 385 /* Construct spelled word */ | 382 /* Construct spelled word */ |
| 386 tmp_ptr = spelled_word; | 383 tmp_ptr = spelled_word; |
| 387 | 384 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 398 } | 395 } |
| 399 | 396 |
| 400 /* Remove hyphen at the end of the word */ | 397 /* Remove hyphen at the end of the word */ |
| 401 tmp_ptr = tmp_ptr - 1; | 398 tmp_ptr = tmp_ptr - 1; |
| 402 (void) memcpy((void *)(tmp_ptr), (void *)&zero, 1); | 399 (void) memcpy((void *)(tmp_ptr), (void *)&zero, 1); |
| 403 | 400 |
| 404 return (spelled_word); | 401 return (spelled_word); |
| 405 } | 402 } |
| 406 | 403 |
| 407 #endif /* APGBFM */ | 404 #endif /* APGBFM */ |
| OLD | NEW |