Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(754)

Side by Side Diff: third_party/fips181/fips181.cc

Issue 2571113002: Remove unnecessary typedefs in third_party/fips181. (Closed)
Patch Set: Solve for MSVC warning C4805. Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « third_party/fips181/fips181.h ('k') | third_party/fips181/owntypes.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 ** This module uses code from the NIST implementation of FIPS-181, 2 ** This module uses code from the NIST implementation of FIPS-181,
3 ** but the algorythm is CHANGED and I think that I CAN 3 ** but the algorythm is CHANGED and I think that I CAN
4 ** copyright it. See copiright notes below. 4 ** copyright it. See copiright notes below.
5 */ 5 */
6 6
7 /* 7 /*
8 ** Copyright (c) 1999, 2000, 2001, 2002, 2003 8 ** Copyright (c) 1999, 2000, 2001, 2002, 2003
9 ** Adel I. Mirzazhanov. All rights reserved 9 ** Adel I. Mirzazhanov. All rights reserved
10 ** 10 **
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 #include <time.h> 43 #include <time.h>
44 #include <sys/types.h> 44 #include <sys/types.h>
45 #include "base/rand_util.h" 45 #include "base/rand_util.h"
46 #include "fips181.h" 46 #include "fips181.h"
47 #include "randpass.h" 47 #include "randpass.h"
48 #include "convert.h" 48 #include "convert.h"
49 49
50 struct unit 50 struct unit
51 { 51 {
52 char unit_code[5]; 52 char unit_code[5];
53 USHORT flags; 53 unsigned short flags;
54 }; 54 };
55 55
56 static struct unit rules[] = 56 static struct unit rules[] =
57 { {"a", VOWEL}, 57 { {"a", VOWEL},
58 {"b", NO_SPECIAL_RULE}, 58 {"b", NO_SPECIAL_RULE},
59 {"c", NO_SPECIAL_RULE}, 59 {"c", NO_SPECIAL_RULE},
60 {"d", NO_SPECIAL_RULE}, 60 {"d", NO_SPECIAL_RULE},
61 {"e", NO_FINAL_SPLIT | VOWEL}, 61 {"e", NO_FINAL_SPLIT | VOWEL},
62 {"f", NO_SPECIAL_RULE}, 62 {"f", NO_SPECIAL_RULE},
63 {"g", NO_SPECIAL_RULE}, 63 {"g", NO_SPECIAL_RULE},
(...skipping 1184 matching lines...) Expand 10 before | Expand all | Expand 10 after
1248 /* ckwh */ ILLEGAL_PAIR, 1248 /* ckwh */ ILLEGAL_PAIR,
1249 /* ckqu */ NOT_BEGIN | BREAK | NOT_END, 1249 /* ckqu */ NOT_BEGIN | BREAK | NOT_END,
1250 /* ckck */ ILLEGAL_PAIR} 1250 /* ckck */ ILLEGAL_PAIR}
1251 }; 1251 };
1252 1252
1253 /* 1253 /*
1254 ** gen_pron_pass will generate a Random word and place it in the 1254 ** gen_pron_pass will generate a Random word and place it in the
1255 ** buffer word. Also, the hyphenated word will be placed into 1255 ** buffer word. Also, the hyphenated word will be placed into
1256 ** the buffer hyphenated_word. Both word and hyphenated_word must 1256 ** the buffer hyphenated_word. Both word and hyphenated_word must
1257 ** be pre-allocated. The words generated will have sizes between 1257 ** be pre-allocated. The words generated will have sizes between
1258 ** minlen and maxlen. If restrict is TRUE, words will not be generated that 1258 ** minlen and maxlen. If restrict is true, words will not be generated that
1259 ** appear as login names or as entries in the on-line dictionary. 1259 ** appear as login names or as entries in the on-line dictionary.
1260 ** This algorithm was initially worded out by Morrie Gasser in 1975. 1260 ** This algorithm was initially worded out by Morrie Gasser in 1975.
1261 ** Any changes here are minimal so that as many word combinations 1261 ** Any changes here are minimal so that as many word combinations
1262 ** can be produced as possible (and thus keep the words Random). 1262 ** can be produced as possible (and thus keep the words Random).
1263 ** The seed is used on first use of the routine. 1263 ** The seed is used on first use of the routine.
1264 ** The length of the unhyphenated word is returned, or -1 if there 1264 ** The length of the unhyphenated word is returned, or -1 if there
1265 ** were an error (length settings are wrong or dictionary checking 1265 ** were an error (length settings are wrong or dictionary checking
1266 ** could not be done. 1266 ** could not be done.
1267 */ 1267 */
1268 int 1268 int
1269 gen_pron_pass (char *word, char *hyphenated_word, USHORT minlen, 1269 gen_pron_pass (char *word, char *hyphenated_word, unsigned short minlen,
1270 USHORT maxlen, unsigned int pass_mode) 1270 unsigned short maxlen, unsigned int pass_mode)
1271 { 1271 {
1272 1272
1273 int pwlen; 1273 int pwlen;
1274 1274
1275 /* 1275 /*
1276 * Check for minlen>maxlen. This is an error. 1276 * Check for minlen>maxlen. This is an error.
1277 * and a length of 0. 1277 * and a length of 0.
1278 */ 1278 */
1279 if (minlen > maxlen || minlen > APG_MAX_PASSWORD_LENGTH || 1279 if (minlen > maxlen || minlen > APG_MAX_PASSWORD_LENGTH ||
1280 maxlen > APG_MAX_PASSWORD_LENGTH) 1280 maxlen > APG_MAX_PASSWORD_LENGTH)
(...skipping 21 matching lines...) Expand all
1302 /* 1302 /*
1303 * This is the routine that returns a Random word -- as 1303 * This is the routine that returns a Random word -- as
1304 * yet unchecked against the passwd file or the dictionary. 1304 * yet unchecked against the passwd file or the dictionary.
1305 * It collects Random syllables until a predetermined 1305 * It collects Random syllables until a predetermined
1306 * word length is found. If a retry threshold is reached, 1306 * word length is found. If a retry threshold is reached,
1307 * another word is tried. Given that the Random number 1307 * another word is tried. Given that the Random number
1308 * generator is uniformly distributed, eventually a word 1308 * generator is uniformly distributed, eventually a word
1309 * will be found if the retry limit is adequately large enough. 1309 * will be found if the retry limit is adequately large enough.
1310 */ 1310 */
1311 int 1311 int
1312 gen_word (char *word, char *hyphenated_word, USHORT pwlen, unsigned int pass_mod e) 1312 gen_word (char *word, char *hyphenated_word, unsigned short pwlen, unsigned int pass_mode)
1313 { 1313 {
1314 USHORT word_length; 1314 unsigned short word_length;
1315 USHORT syllable_length; 1315 unsigned short syllable_length;
1316 char *new_syllable; 1316 char *new_syllable;
1317 char *syllable_for_hyph; 1317 char *syllable_for_hyph;
1318 USHORT *syllable_units; 1318 unsigned short *syllable_units;
1319 USHORT word_size; 1319 unsigned short word_size;
1320 USHORT word_place; 1320 unsigned short word_place;
1321 USHORT *word_units; 1321 unsigned short *word_units;
1322 USHORT syllable_size; 1322 unsigned short syllable_size;
1323 UINT tries; 1323 unsigned int tries;
1324 int ch_flag = FALSE; 1324 bool ch_flag = false;
1325 int dsd = 0; 1325 int dsd = 0;
1326 1326
1327 /* 1327 /*
1328 * Keep count of retries. 1328 * Keep count of retries.
1329 */ 1329 */
1330 tries = 0; 1330 tries = 0;
1331 1331
1332 /* 1332 /*
1333 * The length of the word in characters. 1333 * The length of the word in characters.
1334 */ 1334 */
1335 word_length = 0; 1335 word_length = 0;
1336 1336
1337 /* 1337 /*
1338 * The length of the word in character units (each of which is one or 1338 * The length of the word in character units (each of which is one or
1339 * two characters long. 1339 * two characters long.
1340 */ 1340 */
1341 word_size = 0; 1341 word_size = 0;
1342 1342
1343 /* 1343 /*
1344 * Initialize the array storing the word units. Since we know the 1344 * Initialize the array storing the word units. Since we know the
1345 * length of the word, we only need one of that length. This method is 1345 * length of the word, we only need one of that length. This method is
1346 * preferable to a static array, since it allows us flexibility in 1346 * preferable to a static array, since it allows us flexibility in
1347 * choosing arbitrarily long word lengths. Since a word can contain one 1347 * choosing arbitrarily long word lengths. Since a word can contain one
1348 * syllable, we should make syllable_units, the array holding the 1348 * syllable, we should make syllable_units, the array holding the
1349 * analogous units for an individual syllable, the same length. No 1349 * analogous units for an individual syllable, the same length. No
1350 * explicit rule limits the length of syllables, but digram rules and 1350 * explicit rule limits the length of syllables, but digram rules and
1351 * heuristics do so indirectly. 1351 * heuristics do so indirectly.
1352 */ 1352 */
1353 if ( (word_units = (USHORT *) calloc (sizeof (USHORT), pwlen+1))==NULL | | 1353 if ( (word_units = (unsigned short *) calloc (sizeof (unsigned short), p wlen+1))==NULL ||
1354 (syllable_units = (USHORT *) calloc (sizeof (USHORT), pwlen+1))==NULL | | 1354 (syllable_units = (unsigned short *) calloc (sizeof (unsigned short), p wlen+1))==NULL ||
1355 (new_syllable = (char *) calloc (sizeof (USHORT), pwlen+1)) ==NULL | | 1355 (new_syllable = (char *) calloc (sizeof (unsigned short), pwlen+1)) ==NULL ||
1356 (syllable_for_hyph = (char *) calloc (sizeof(char), 20))==NULL) 1356 (syllable_for_hyph = (char *) calloc (sizeof(char), 20))==NULL)
1357 return(-1); 1357 return(-1);
1358 1358
1359 /* 1359 /*
1360 * Find syllables until the entire word is constructed. 1360 * Find syllables until the entire word is constructed.
1361 */ 1361 */
1362 while (word_length < pwlen) 1362 while (word_length < pwlen)
1363 { 1363 {
1364 /* 1364 /*
1365 * Get the syllable and find its length. 1365 * Get the syllable and find its length.
1366 */ 1366 */
1367 (void) gen_syllable (new_syllable, pwlen - word_length, syllable_units, &sy llable_size); 1367 (void) gen_syllable (new_syllable, pwlen - word_length, syllable_units, &sy llable_size);
1368 syllable_length = (USHORT) strlen (new_syllable); 1368 syllable_length = (unsigned short) strlen (new_syllable);
1369 1369
1370 /* 1370 /*
1371 * Append the syllable units to the word units. 1371 * Append the syllable units to the word units.
1372 */ 1372 */
1373 for (word_place = 0; word_place <= syllable_size; word_place++) 1373 for (word_place = 0; word_place <= syllable_size; word_place++)
1374 word_units[word_size + word_place] = syllable_units[word_place]; 1374 word_units[word_size + word_place] = syllable_units[word_place];
1375 word_size += syllable_size + 1; 1375 word_size += syllable_size + 1;
1376 1376
1377 /* 1377 /*
1378 * If the word has been improperly formed, throw out 1378 * If the word has been improperly formed, throw out
(...skipping 13 matching lines...) Expand all
1392 if (word_length == 0) 1392 if (word_length == 0)
1393 { 1393 {
1394 /* 1394 /*
1395 ** Modify syllable for numeric or capital symbols required 1395 ** Modify syllable for numeric or capital symbols required
1396 ** Should be done after word quality check. 1396 ** Should be done after word quality check.
1397 */ 1397 */
1398 dsd = base::RandInt(0, 1); 1398 dsd = base::RandInt(0, 1);
1399 if ( ((pass_mode & S_NB) > 0) && (syllable_length == 1) && dsd == 0) 1399 if ( ((pass_mode & S_NB) > 0) && (syllable_length == 1) && dsd == 0)
1400 { 1400 {
1401 numerize(new_syllable); 1401 numerize(new_syllable);
1402 » ch_flag = TRUE; 1402 » ch_flag = true;
1403 } 1403 }
1404 if ( ((pass_mode & S_SS) > 0) && (syllable_length == 1) && (dsd == 1)) 1404 if ( ((pass_mode & S_SS) > 0) && (syllable_length == 1) && (dsd == 1))
1405 { 1405 {
1406 specialize(new_syllable); 1406 specialize(new_syllable);
1407 » ch_flag = TRUE; 1407 » ch_flag = true;
1408 } 1408 }
1409 if ( ( (pass_mode & S_CL) > 0) && (ch_flag != TRUE)) 1409 if ( ( (pass_mode & S_CL) > 0) && (ch_flag != true))
1410 capitalize(new_syllable); 1410 capitalize(new_syllable);
1411 ch_flag = FALSE; 1411 ch_flag = false;
1412 /**/ 1412 /**/
1413 (void) strcpy (word, new_syllable); 1413 (void) strcpy (word, new_syllable);
1414 if (syllable_length == 1) 1414 if (syllable_length == 1)
1415 { 1415 {
1416 symb2name(new_syllable, syllable_for_hyph); 1416 symb2name(new_syllable, syllable_for_hyph);
1417 (void) strcpy (hyphenated_word, syllable_for_hyph); 1417 (void) strcpy (hyphenated_word, syllable_for_hyph);
1418 } 1418 }
1419 else 1419 else
1420 { 1420 {
1421 (void) strcpy (hyphenated_word, new_syllable); 1421 (void) strcpy (hyphenated_word, new_syllable);
1422 } 1422 }
1423 » (void)memset ( (void *)new_syllable, 0, (size_t)(pwlen * sizeof(USHORT )+1)); 1423 » (void)memset ( (void *)new_syllable, 0, (size_t)(pwlen * sizeof(unsign ed short)+1));
1424 (void)memset ( (void *)syllable_for_hyph, 0, 20); 1424 (void)memset ( (void *)syllable_for_hyph, 0, 20);
1425 } 1425 }
1426 else 1426 else
1427 { 1427 {
1428 /* 1428 /*
1429 ** Modify syllable for numeric or capital symbols required 1429 ** Modify syllable for numeric or capital symbols required
1430 ** Should be done after word quality check. 1430 ** Should be done after word quality check.
1431 */ 1431 */
1432 dsd = base::RandInt(0, 1); 1432 dsd = base::RandInt(0, 1);
1433 if ( ((pass_mode & S_NB) > 0) && (syllable_length == 1) && (dsd == 0)) 1433 if ( ((pass_mode & S_NB) > 0) && (syllable_length == 1) && (dsd == 0))
1434 { 1434 {
1435 numerize(new_syllable); 1435 numerize(new_syllable);
1436 » ch_flag = TRUE; 1436 » ch_flag = true;
1437 } 1437 }
1438 if ( ( (pass_mode & S_SS) > 0) && (syllable_length == 1) && (dsd == 1) ) 1438 if ( ( (pass_mode & S_SS) > 0) && (syllable_length == 1) && (dsd == 1) )
1439 { 1439 {
1440 specialize(new_syllable); 1440 specialize(new_syllable);
1441 » ch_flag = TRUE; 1441 » ch_flag = true;
1442 } 1442 }
1443 if ( ( (pass_mode & S_CL) > 0) && (ch_flag != TRUE)) 1443 if ( ( (pass_mode & S_CL) > 0) && (ch_flag != true))
1444 capitalize(new_syllable); 1444 capitalize(new_syllable);
1445 ch_flag = FALSE; 1445 ch_flag = false;
1446 /**/ 1446 /**/
1447 (void) strcat (word, new_syllable); 1447 (void) strcat (word, new_syllable);
1448 (void) strcat (hyphenated_word, "-"); 1448 (void) strcat (hyphenated_word, "-");
1449 if (syllable_length == 1) 1449 if (syllable_length == 1)
1450 { 1450 {
1451 symb2name(new_syllable, syllable_for_hyph); 1451 symb2name(new_syllable, syllable_for_hyph);
1452 (void) strcat (hyphenated_word, syllable_for_hyph); 1452 (void) strcat (hyphenated_word, syllable_for_hyph);
1453 } 1453 }
1454 else 1454 else
1455 { 1455 {
1456 (void) strcat (hyphenated_word, new_syllable); 1456 (void) strcat (hyphenated_word, new_syllable);
1457 } 1457 }
1458 » (void)memset ( (void *)new_syllable, 0, (size_t)(pwlen * sizeof(USHORT )+1)); 1458 » (void)memset ( (void *)new_syllable, 0, (size_t)(pwlen * sizeof(unsign ed short)+1));
1459 (void)memset ( (void *)syllable_for_hyph, 0, 20); 1459 (void)memset ( (void *)syllable_for_hyph, 0, 20);
1460 } 1460 }
1461 word_length += syllable_length; 1461 word_length += syllable_length;
1462 } 1462 }
1463 1463
1464 /* 1464 /*
1465 * Keep track of the times we have tried to get 1465 * Keep track of the times we have tried to get
1466 * syllables. If we have exceeded the threshold, 1466 * syllables. If we have exceeded the threshold,
1467 * reinitialize the pwlen and word_size variables, clear 1467 * reinitialize the pwlen and word_size variables, clear
1468 * out the word arrays, and start from scratch. 1468 * out the word arrays, and start from scratch.
(...skipping 27 matching lines...) Expand all
1496 /* 1496 /*
1497 * Check that the word does not contain illegal combinations 1497 * Check that the word does not contain illegal combinations
1498 * that may span syllables. Specifically, these are: 1498 * that may span syllables. Specifically, these are:
1499 * 1. An illegal pair of units between syllables. 1499 * 1. An illegal pair of units between syllables.
1500 * 2. Three consecutive vowel units. 1500 * 2. Three consecutive vowel units.
1501 * 3. Three consecutive consonant units. 1501 * 3. Three consecutive consonant units.
1502 * The checks are made against units (1 or 2 letters), not against 1502 * The checks are made against units (1 or 2 letters), not against
1503 * the individual letters, so three consecutive units can have 1503 * the individual letters, so three consecutive units can have
1504 * the length of 6 at most. 1504 * the length of 6 at most.
1505 */ 1505 */
1506 boolean 1506 bool
1507 improper_word (USHORT *units, USHORT word_size) 1507 improper_word (unsigned short *units, unsigned short word_size)
1508 { 1508 {
1509 USHORT unit_count; 1509 unsigned short unit_count;
1510 boolean failure; 1510 bool failure;
1511 1511
1512 failure = FALSE; 1512 failure = false;
1513 1513
1514 for (unit_count = 0; !failure && (unit_count < word_size); 1514 for (unit_count = 0; !failure && (unit_count < word_size);
1515 unit_count++) 1515 unit_count++)
1516 { 1516 {
1517 /* 1517 /*
1518 * Check for ILLEGAL_PAIR. This should have been caught 1518 * Check for ILLEGAL_PAIR. This should have been caught
1519 * for units within a syllable, but in some cases it 1519 * for units within a syllable, but in some cases it
1520 * would have gone unnoticed for units between syllables 1520 * would have gone unnoticed for units between syllables
1521 * (e.g., when saved_unit's in gen_syllable() were not 1521 * (e.g., when saved_unit's in gen_syllable() were not
1522 * used). 1522 * used).
1523 */ 1523 */
1524 if ((unit_count != 0) && 1524 if ((unit_count != 0) &&
1525 (digram[units[unit_count - 1]][units[unit_count]] & 1525 (digram[units[unit_count - 1]][units[unit_count]] &
1526 ILLEGAL_PAIR)) 1526 ILLEGAL_PAIR))
1527 failure = TRUE; 1527 failure = true;
1528 1528
1529 /* 1529 /*
1530 * Check for consecutive vowels or consonants. Because 1530 * Check for consecutive vowels or consonants. Because
1531 * the initial y of a syllable is treated as a consonant 1531 * the initial y of a syllable is treated as a consonant
1532 * rather than as a vowel, we exclude y from the first 1532 * rather than as a vowel, we exclude y from the first
1533 * vowel in the vowel test. The only problem comes when 1533 * vowel in the vowel test. The only problem comes when
1534 * y ends a syllable and two other vowels start the next, 1534 * y ends a syllable and two other vowels start the next,
1535 * like fly-oint. Since such words are still 1535 * like fly-oint. Since such words are still
1536 * pronounceable, we accept this. 1536 * pronounceable, we accept this.
1537 */ 1537 */
1538 if (!failure && (unit_count >= 2)) 1538 if (!failure && (unit_count >= 2))
1539 { 1539 {
1540 /* 1540 /*
1541 * Vowel check. 1541 * Vowel check.
1542 */ 1542 */
1543 if ((((rules[units[unit_count - 2]].flags & VOWEL) && 1543 if ((((rules[units[unit_count - 2]].flags & VOWEL) &&
1544 !(rules[units[unit_count - 2]].flags & 1544 !(rules[units[unit_count - 2]].flags &
1545 ALTERNATE_VOWEL)) && 1545 ALTERNATE_VOWEL)) &&
1546 (rules[units[unit_count - 1]].flags & VOWEL) && 1546 (rules[units[unit_count - 1]].flags & VOWEL) &&
1547 (rules[units[unit_count]].flags & VOWEL)) || 1547 (rules[units[unit_count]].flags & VOWEL)) ||
1548 /* 1548 /*
1549 * Consonant check. 1549 * Consonant check.
1550 */ 1550 */
1551 (!(rules[units[unit_count - 2]].flags & VOWEL) && 1551 (!(rules[units[unit_count - 2]].flags & VOWEL) &&
1552 !(rules[units[unit_count - 1]].flags & VOWEL) && 1552 !(rules[units[unit_count - 1]].flags & VOWEL) &&
1553 !(rules[units[unit_count]].flags & VOWEL))) 1553 !(rules[units[unit_count]].flags & VOWEL)))
1554 failure = TRUE; 1554 failure = true;
1555 } 1555 }
1556 } 1556 }
1557 1557
1558 return (failure); 1558 return (failure);
1559 } 1559 }
1560 1560
1561 1561
1562 /* 1562 /*
1563 * Treating y as a vowel is sometimes a problem. Some words 1563 * Treating y as a vowel is sometimes a problem. Some words
1564 * get formed that look irregular. One special group is when 1564 * get formed that look irregular. One special group is when
1565 * y starts a word and is the only vowel in the first syllable. 1565 * y starts a word and is the only vowel in the first syllable.
1566 * The word ycl is one example. We discard words like these. 1566 * The word ycl is one example. We discard words like these.
1567 */ 1567 */
1568 boolean 1568 bool
1569 have_initial_y (USHORT *units, USHORT unit_size) 1569 have_initial_y (unsigned short *units, unsigned short unit_size)
1570 { 1570 {
1571 USHORT unit_count; 1571 unsigned short unit_count;
1572 USHORT vowel_count; 1572 unsigned short vowel_count;
1573 USHORT normal_vowel_count; 1573 unsigned short normal_vowel_count;
1574 1574
1575 vowel_count = 0; 1575 vowel_count = 0;
1576 normal_vowel_count = 0; 1576 normal_vowel_count = 0;
1577 1577
1578 for (unit_count = 0; unit_count <= unit_size; unit_count++) 1578 for (unit_count = 0; unit_count <= unit_size; unit_count++)
1579 /* 1579 /*
1580 * Count vowels. 1580 * Count vowels.
1581 */ 1581 */
1582 if (rules[units[unit_count]].flags & VOWEL) 1582 if (rules[units[unit_count]].flags & VOWEL)
1583 { 1583 {
(...skipping 12 matching lines...) Expand all
1596 } 1596 }
1597 1597
1598 1598
1599 /* 1599 /*
1600 * Besides the problem with the letter y, there is one with 1600 * Besides the problem with the letter y, there is one with
1601 * a silent e at the end of words, like face or nice. We 1601 * a silent e at the end of words, like face or nice. We
1602 * allow this silent e, but we do not allow it as the only 1602 * allow this silent e, but we do not allow it as the only
1603 * vowel at the end of the word or syllables like ble will 1603 * vowel at the end of the word or syllables like ble will
1604 * be generated. 1604 * be generated.
1605 */ 1605 */
1606 boolean 1606 bool
1607 have_final_split (USHORT *units, USHORT unit_size) 1607 have_final_split (unsigned short *units, unsigned short unit_size)
1608 { 1608 {
1609 USHORT unit_count; 1609 unsigned short unit_count;
1610 USHORT vowel_count; 1610 unsigned short vowel_count;
1611 1611
1612 vowel_count = 0; 1612 vowel_count = 0;
1613 1613
1614 /* 1614 /*
1615 * Count all the vowels in the word. 1615 * Count all the vowels in the word.
1616 */ 1616 */
1617 for (unit_count = 0; unit_count <= unit_size; unit_count++) 1617 for (unit_count = 0; unit_count <= unit_size; unit_count++)
1618 if (rules[units[unit_count]].flags & VOWEL) 1618 if (rules[units[unit_count]].flags & VOWEL)
1619 vowel_count++; 1619 vowel_count++;
1620 1620
1621 /* 1621 /*
1622 * Return TRUE iff the only vowel was e, found at the end if the 1622 * Return true iff the only vowel was e, found at the end if the
1623 * word. 1623 * word.
1624 */ 1624 */
1625 return ((vowel_count == 1) && 1625 return ((vowel_count == 1) &&
1626 (rules[units[unit_size]].flags & NO_FINAL_SPLIT)); 1626 (rules[units[unit_size]].flags & NO_FINAL_SPLIT));
1627 } 1627 }
1628 1628
1629 1629
1630 /* 1630 /*
1631 * Generate next unit to password, making sure that it follows 1631 * Generate next unit to password, making sure that it follows
1632 * these rules: 1632 * these rules:
(...skipping 23 matching lines...) Expand all
1656 * or in "end" pair. 1656 * or in "end" pair.
1657 * e. "not_begin" pair generated but new syllable must 1657 * e. "not_begin" pair generated but new syllable must
1658 * begin (because previous syllable ended as defined in 1658 * begin (because previous syllable ended as defined in
1659 * 2 above). 1659 * 2 above).
1660 * f. vowel is generated and 2a is satisfied, but no syllable 1660 * f. vowel is generated and 2a is satisfied, but no syllable
1661 * break is possible in previous 3 pairs. 1661 * break is possible in previous 3 pairs.
1662 * g. Second and third units of syllable must begin, and 1662 * g. Second and third units of syllable must begin, and
1663 * first unit is "alternate_vowel". 1663 * first unit is "alternate_vowel".
1664 */ 1664 */
1665 char * 1665 char *
1666 gen_syllable (char *syllable, USHORT pwlen, USHORT *units_in_syllable, 1666 gen_syllable (char *syllable, unsigned short pwlen, unsigned short *units_in_syl lable,
1667 USHORT *syllable_length) 1667 unsigned short *syllable_length)
1668 { 1668 {
1669 USHORT unit = 0; 1669 unsigned short unit = 0;
1670 SHORT current_unit = 0; 1670 short current_unit = 0;
1671 USHORT vowel_count = 0; 1671 unsigned short vowel_count = 0;
1672 boolean rule_broken; 1672 bool rule_broken;
1673 boolean want_vowel; 1673 bool want_vowel;
1674 boolean want_another_unit; 1674 bool want_another_unit;
1675 UINT tries = 0; 1675 unsigned int tries = 0;
1676 USHORT last_unit = 0; 1676 unsigned short last_unit = 0;
1677 SHORT length_left = 0; 1677 short length_left = 0;
1678 USHORT hold_saved_unit = 0; 1678 unsigned short hold_saved_unit = 0;
1679 static USHORT saved_unit; 1679 static unsigned short saved_unit;
1680 static USHORT saved_pair[2]; 1680 static unsigned short saved_pair[2];
1681 1681
1682 /* 1682 /*
1683 * This is needed if the saved_unit is tries and the syllable then 1683 * This is needed if the saved_unit is tries and the syllable then
1684 * discarded because of the retry limit. Since the saved_unit is OK and 1684 * discarded because of the retry limit. Since the saved_unit is OK and
1685 * fits in nicely with the preceding syllable, we will always use it. 1685 * fits in nicely with the preceding syllable, we will always use it.
1686 */ 1686 */
1687 hold_saved_unit = saved_unit; 1687 hold_saved_unit = saved_unit;
1688 1688
1689 /* 1689 /*
1690 * Loop until valid syllable is found. 1690 * Loop until valid syllable is found.
1691 */ 1691 */
1692 do 1692 do
1693 { 1693 {
1694 /* 1694 /*
1695 * Try for a new syllable. Initialize all pertinent 1695 * Try for a new syllable. Initialize all pertinent
1696 * syllable variables. 1696 * syllable variables.
1697 */ 1697 */
1698 tries = 0; 1698 tries = 0;
1699 saved_unit = hold_saved_unit; 1699 saved_unit = hold_saved_unit;
1700 (void) strcpy (syllable, ""); 1700 (void) strcpy (syllable, "");
1701 vowel_count = 0; 1701 vowel_count = 0;
1702 current_unit = 0; 1702 current_unit = 0;
1703 length_left = (short int) pwlen; 1703 length_left = (short int) pwlen;
1704 want_another_unit = TRUE; 1704 want_another_unit = true;
1705 1705
1706 /* 1706 /*
1707 * This loop finds all the units for the syllable. 1707 * This loop finds all the units for the syllable.
1708 */ 1708 */
1709 do 1709 do
1710 { 1710 {
1711 want_vowel = FALSE; 1711 want_vowel = false;
1712 1712
1713 /* 1713 /*
1714 * This loop continues until a valid unit is found for the 1714 * This loop continues until a valid unit is found for the
1715 * current position within the syllable. 1715 * current position within the syllable.
1716 */ 1716 */
1717 do 1717 do
1718 { 1718 {
1719 /* 1719 /*
1720 * If there are saved_unit's from the previous 1720 * If there are saved_unit's from the previous
1721 * syllable, use them up first. 1721 * syllable, use them up first.
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
1762 if (want_vowel) 1762 if (want_vowel)
1763 unit = random_unit (VOWEL); 1763 unit = random_unit (VOWEL);
1764 else 1764 else
1765 unit = random_unit (NO_SPECIAL_RULE); 1765 unit = random_unit (NO_SPECIAL_RULE);
1766 length_left -= (short int) strlen (rules[unit].unit_code); 1766 length_left -= (short int) strlen (rules[unit].unit_code);
1767 1767
1768 /* 1768 /*
1769 * Prevent having a word longer than expected. 1769 * Prevent having a word longer than expected.
1770 */ 1770 */
1771 if (length_left < 0) 1771 if (length_left < 0)
1772 rule_broken = TRUE; 1772 rule_broken = true;
1773 else 1773 else
1774 rule_broken = FALSE; 1774 rule_broken = false;
1775 1775
1776 /* 1776 /*
1777 * First unit of syllable. This is special because the 1777 * First unit of syllable. This is special because the
1778 * digram tests require 2 units and we don't have that yet. 1778 * digram tests require 2 units and we don't have that yet.
1779 * Nevertheless, we can perform some checks. 1779 * Nevertheless, we can perform some checks.
1780 */ 1780 */
1781 if (current_unit == 0) 1781 if (current_unit == 0)
1782 { 1782 {
1783 /* 1783 /*
1784 * If the shouldn't begin a syllable, don't 1784 * If the shouldn't begin a syllable, don't
1785 * use it. 1785 * use it.
1786 */ 1786 */
1787 if (rules[unit].flags & NOT_BEGIN_SYLLABLE) 1787 if (rules[unit].flags & NOT_BEGIN_SYLLABLE)
1788 rule_broken = TRUE; 1788 rule_broken = true;
1789 else 1789 else
1790 /* 1790 /*
1791 * If this is the last unit of a word, 1791 * If this is the last unit of a word,
1792 * we have a one unit syllable. Since each 1792 * we have a one unit syllable. Since each
1793 * syllable must have a vowel, we make sure 1793 * syllable must have a vowel, we make sure
1794 * the unit is a vowel. Otherwise, we 1794 * the unit is a vowel. Otherwise, we
1795 * discard it. 1795 * discard it.
1796 */ 1796 */
1797 if (length_left == 0) 1797 if (length_left == 0)
1798 { 1798 {
1799 if (rules[unit].flags & VOWEL) 1799 if (rules[unit].flags & VOWEL)
1800 want_another_unit = FALSE; 1800 want_another_unit = false;
1801 else 1801 else
1802 rule_broken = TRUE; 1802 rule_broken = true;
1803 } 1803 }
1804 } 1804 }
1805 else 1805 else
1806 { 1806 {
1807 /* 1807 /*
1808 * There are some digram tests that are 1808 * There are some digram tests that are
1809 * universally true. We test them out. 1809 * universally true. We test them out.
1810 */ 1810 */
1811 1811
1812 /* 1812 /*
1813 * Reject ILLEGAL_PAIRS of units. 1813 * Reject ILLEGAL_PAIRS of units.
1814 */ 1814 */
1815 if ((ALLOWED (ILLEGAL_PAIR)) || 1815 if ((ALLOWED (ILLEGAL_PAIR)) ||
1816 1816
1817 /* 1817 /*
1818 * Reject units that will be split between syllables 1818 * Reject units that will be split between syllables
1819 * when the syllable has no vowels in it. 1819 * when the syllable has no vowels in it.
1820 */ 1820 */
1821 (ALLOWED (BREAK) && (vowel_count == 0)) || 1821 (ALLOWED (BREAK) && (vowel_count == 0)) ||
1822 1822
1823 /* 1823 /*
1824 * Reject a unit that will end a syllable when no 1824 * Reject a unit that will end a syllable when no
1825 * previous unit was a vowel and neither is this one. 1825 * previous unit was a vowel and neither is this one.
1826 */ 1826 */
1827 (ALLOWED (END) && (vowel_count == 0) && 1827 (ALLOWED (END) && (vowel_count == 0) &&
1828 !(rules[unit].flags & VOWEL))) 1828 !(rules[unit].flags & VOWEL)))
1829 rule_broken = TRUE; 1829 rule_broken = true;
1830 1830
1831 if (current_unit == 1) 1831 if (current_unit == 1)
1832 { 1832 {
1833 /* 1833 /*
1834 * Reject the unit if we are at te starting digram of 1834 * Reject the unit if we are at te starting digram of
1835 * a syllable and it does not fit. 1835 * a syllable and it does not fit.
1836 */ 1836 */
1837 if (ALLOWED (NOT_BEGIN)) 1837 if (ALLOWED (NOT_BEGIN))
1838 rule_broken = TRUE; 1838 rule_broken = true;
1839 } 1839 }
1840 else 1840 else
1841 { 1841 {
1842 /* 1842 /*
1843 * We are not at the start of a syllable. 1843 * We are not at the start of a syllable.
1844 * Save the previous unit for later tests. 1844 * Save the previous unit for later tests.
1845 */ 1845 */
1846 last_unit = units_in_syllable[current_unit - 1]; 1846 last_unit = units_in_syllable[current_unit - 1];
1847 1847
1848 /* 1848 /*
(...skipping 29 matching lines...) Expand all
1878 1878
1879 /* 1879 /*
1880 * Reject the unit if the digram it forms 1880 * Reject the unit if the digram it forms
1881 * expects a vowel preceding it and there is 1881 * expects a vowel preceding it and there is
1882 * none. 1882 * none.
1883 */ 1883 */
1884 (ALLOWED (PREFIX) && 1884 (ALLOWED (PREFIX) &&
1885 !(rules[units_in_syllable 1885 !(rules[units_in_syllable
1886 [current_unit - 2]].flags & 1886 [current_unit - 2]].flags &
1887 VOWEL))) 1887 VOWEL)))
1888 rule_broken = TRUE; 1888 rule_broken = true;
1889 1889
1890 /* 1890 /*
1891 * The following checks occur when the current unit 1891 * The following checks occur when the current unit
1892 * is a vowel and we are not looking at a word ending 1892 * is a vowel and we are not looking at a word ending
1893 * with an e. 1893 * with an e.
1894 */ 1894 */
1895 if (!rule_broken && 1895 if (!rule_broken &&
1896 (rules[unit].flags & VOWEL) && 1896 (rules[unit].flags & VOWEL) &&
1897 ((length_left > 0) || 1897 ((length_left > 0) ||
1898 !(rules[last_unit].flags & 1898 !(rules[last_unit].flags &
1899 NO_FINAL_SPLIT))) 1899 NO_FINAL_SPLIT)))
1900 { 1900 {
1901 /* 1901 /*
1902 * Don't allow 3 consecutive vowels in a 1902 * Don't allow 3 consecutive vowels in a
1903 * syllable. Although some words formed like this 1903 * syllable. Although some words formed like this
1904 * are OK, like beau, most are not. 1904 * are OK, like beau, most are not.
1905 */ 1905 */
1906 if ((vowel_count > 1) && 1906 if ((vowel_count > 1) &&
1907 (rules[last_unit].flags & VOWEL)) 1907 (rules[last_unit].flags & VOWEL))
1908 rule_broken = TRUE; 1908 rule_broken = true;
1909 else 1909 else
1910 /* 1910 /*
1911 * Check for the case of 1911 * Check for the case of
1912 * vowels-consonants-vowel, which is only 1912 * vowels-consonants-vowel, which is only
1913 * legal if the last vowel is an e and we are 1913 * legal if the last vowel is an e and we are
1914 * the end of the word (wich is not 1914 * the end of the word (wich is not
1915 * happening here due to a previous check. 1915 * happening here due to a previous check.
1916 */ 1916 */
1917 if ((vowel_count != 0) && 1917 if ((vowel_count != 0) &&
1918 !(rules[last_unit].flags & VOWEL)) 1918 !(rules[last_unit].flags & VOWEL))
1919 { 1919 {
1920 /* 1920 /*
1921 * Try to save the vowel for the next 1921 * Try to save the vowel for the next
1922 * syllable, but if the syllable left here 1922 * syllable, but if the syllable left here
1923 * is not proper (i.e., the resulting last 1923 * is not proper (i.e., the resulting last
1924 * digram cannot legally end it), just 1924 * digram cannot legally end it), just
1925 * discard it and try for another. 1925 * discard it and try for another.
1926 */ 1926 */
1927 if (digram[units_in_syllable 1927 if (digram[units_in_syllable
1928 [current_unit - 2]] 1928 [current_unit - 2]]
1929 [last_unit] & 1929 [last_unit] &
1930 NOT_END) 1930 NOT_END)
1931 rule_broken = TRUE; 1931 rule_broken = true;
1932 else 1932 else
1933 { 1933 {
1934 saved_unit = 1; 1934 saved_unit = 1;
1935 saved_pair[0] = unit; 1935 saved_pair[0] = unit;
1936 want_another_unit = FALSE; 1936 want_another_unit = false;
1937 } 1937 }
1938 } 1938 }
1939 } 1939 }
1940 } 1940 }
1941 1941
1942 /* 1942 /*
1943 * The unit picked and the digram formed are legal. 1943 * The unit picked and the digram formed are legal.
1944 * We now determine if we can end the syllable. It may, 1944 * We now determine if we can end the syllable. It may,
1945 * in some cases, mean the last unit(s) may be deferred to 1945 * in some cases, mean the last unit(s) may be deferred to
1946 * the next syllable. We also check here to see if the 1946 * the next syllable. We also check here to see if the
1947 * digram formed expects a vowel to follow. 1947 * digram formed expects a vowel to follow.
1948 */ 1948 */
1949 if (!rule_broken && want_another_unit) 1949 if (!rule_broken && want_another_unit)
1950 { 1950 {
1951 /* 1951 /*
1952 * This word ends in a silent e. 1952 * This word ends in a silent e.
1953 */ 1953 */
1954 /******/ if (((vowel_count != 0) && 1954 /******/ if (((vowel_count != 0) &&
1955 (rules[unit].flags & NO_FINAL_SPLIT) && 1955 (rules[unit].flags & NO_FINAL_SPLIT) &&
1956 (length_left == 0) && 1956 (length_left == 0) &&
1957 !(rules[last_unit].flags & VOWEL)) || 1957 !(rules[last_unit].flags & VOWEL)) ||
1958 1958
1959 /* 1959 /*
1960 * This syllable ends either because the digram 1960 * This syllable ends either because the digram
1961 * is an END pair or we would otherwise exceed 1961 * is an END pair or we would otherwise exceed
1962 * the length of the word. 1962 * the length of the word.
1963 */ 1963 */
1964 (ALLOWED (END) || (length_left == 0))) 1964 (ALLOWED (END) || (length_left == 0)))
1965 { 1965 {
1966 want_another_unit = FALSE; 1966 want_another_unit = false;
1967 } 1967 }
1968 else 1968 else
1969 /* 1969 /*
1970 * Since we have a vowel in the syllable 1970 * Since we have a vowel in the syllable
1971 * already, if the digram calls for the end of the 1971 * already, if the digram calls for the end of the
1972 * syllable, we can legally split it off. We also 1972 * syllable, we can legally split it off. We also
1973 * make sure that we are not at the end of the 1973 * make sure that we are not at the end of the
1974 * dangerous because that syllable may not have 1974 * dangerous because that syllable may not have
1975 * vowels, or it may not be a legal syllable end, 1975 * vowels, or it may not be a legal syllable end,
1976 * and the retrying mechanism will loop infinitely 1976 * and the retrying mechanism will loop infinitely
1977 * with the same digram. 1977 * with the same digram.
1978 */ 1978 */
1979 if ((vowel_count != 0) && (length_left > 0)) 1979 if ((vowel_count != 0) && (length_left > 0))
1980 { 1980 {
1981 /* 1981 /*
1982 * If we must begin a syllable, we do so if 1982 * If we must begin a syllable, we do so if
1983 * the only vowel in THIS syllable is not part 1983 * the only vowel in THIS syllable is not part
1984 * of the digram we are pushing to the next 1984 * of the digram we are pushing to the next
1985 * syllable. 1985 * syllable.
1986 */ 1986 */
1987 if (ALLOWED (BEGIN) && 1987 if (ALLOWED (BEGIN) &&
1988 (current_unit > 1) && 1988 (current_unit > 1) &&
1989 !((vowel_count == 1) && 1989 !((vowel_count == 1) &&
1990 (rules[last_unit].flags & VOWEL))) 1990 (rules[last_unit].flags & VOWEL)))
1991 { 1991 {
1992 saved_unit = 2; 1992 saved_unit = 2;
1993 saved_pair[0] = unit; 1993 saved_pair[0] = unit;
1994 saved_pair[1] = last_unit; 1994 saved_pair[1] = last_unit;
1995 want_another_unit = FALSE; 1995 want_another_unit = false;
1996 } 1996 }
1997 else 1997 else
1998 if (ALLOWED (BREAK)) 1998 if (ALLOWED (BREAK))
1999 { 1999 {
2000 saved_unit = 1; 2000 saved_unit = 1;
2001 saved_pair[0] = unit; 2001 saved_pair[0] = unit;
2002 want_another_unit = FALSE; 2002 want_another_unit = false;
2003 } 2003 }
2004 } 2004 }
2005 else 2005 else
2006 if (ALLOWED (SUFFIX)) 2006 if (ALLOWED (SUFFIX))
2007 { 2007 {
2008 want_vowel = TRUE; 2008 want_vowel = true;
2009 } 2009 }
2010 } 2010 }
2011 } 2011 }
2012 /********/ 2012 /********/
2013 tries++; 2013 tries++;
2014 2014
2015 /* 2015 /*
2016 * If this unit was illegal, redetermine the amount of 2016 * If this unit was illegal, redetermine the amount of
2017 * letters left to go in the word. 2017 * letters left to go in the word.
2018 */ 2018 */
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
2059 length_left += (short int) strlen (rules[last_unit].unit_code); 2059 length_left += (short int) strlen (rules[last_unit].unit_code);
2060 current_unit -= 2; 2060 current_unit -= 2;
2061 break; 2061 break;
2062 } 2062 }
2063 } 2063 }
2064 else 2064 else
2065 /* 2065 /*
2066 * Whoops! Too many tries. We set rule_broken so we can 2066 * Whoops! Too many tries. We set rule_broken so we can
2067 * loop in the outer loop and try another syllable. 2067 * loop in the outer loop and try another syllable.
2068 */ 2068 */
2069 rule_broken = TRUE; 2069 rule_broken = true;
2070 2070
2071 /* 2071 /*
2072 * ...and the syllable length grows. 2072 * ...and the syllable length grows.
2073 */ 2073 */
2074 *syllable_length = current_unit; 2074 *syllable_length = current_unit;
2075 2075
2076 current_unit++; 2076 current_unit++;
2077 } 2077 }
2078 while ((tries <= MAX_RETRIES) && want_another_unit); 2078 while ((tries <= MAX_RETRIES) && want_another_unit);
2079 } 2079 }
2080 while (rule_broken || 2080 while (rule_broken ||
2081 illegal_placement (units_in_syllable, *syllable_length)); 2081 illegal_placement (units_in_syllable, *syllable_length));
2082 2082
2083 return (syllable); 2083 return (syllable);
2084 } 2084 }
2085 2085
2086 2086
2087 /* 2087 /*
2088 * This routine goes through an individual syllable and checks 2088 * This routine goes through an individual syllable and checks
2089 * for illegal combinations of letters that go beyond looking 2089 * for illegal combinations of letters that go beyond looking
2090 * at digrams. We look at things like 3 consecutive vowels or 2090 * at digrams. We look at things like 3 consecutive vowels or
2091 * consonants, or syllables with consonants between vowels (unless 2091 * consonants, or syllables with consonants between vowels (unless
2092 * one of them is the final silent e). 2092 * one of them is the final silent e).
2093 */ 2093 */
2094 boolean 2094 bool
2095 illegal_placement (USHORT *units, USHORT pwlen) 2095 illegal_placement (unsigned short *units, unsigned short pwlen)
2096 { 2096 {
2097 USHORT vowel_count; 2097 unsigned short vowel_count;
2098 USHORT unit_count; 2098 unsigned short unit_count;
2099 boolean failure; 2099 bool failure;
2100 2100
2101 vowel_count = 0; 2101 vowel_count = 0;
2102 failure = FALSE; 2102 failure = false;
2103 2103
2104 for (unit_count = 0; !failure && (unit_count <= pwlen); 2104 for (unit_count = 0; !failure && (unit_count <= pwlen);
2105 unit_count++) 2105 unit_count++)
2106 { 2106 {
2107 if (unit_count >= 1) 2107 if (unit_count >= 1)
2108 { 2108 {
2109 /* 2109 /*
2110 * Don't allow vowels to be split with consonants in 2110 * Don't allow vowels to be split with consonants in
2111 * a single syllable. If we find such a combination 2111 * a single syllable. If we find such a combination
2112 * (except for the silent e) we have to discard the 2112 * (except for the silent e) we have to discard the
(...skipping 23 matching lines...) Expand all
2136 */ 2136 */
2137 (((rules[units[unit_count - 2]].flags & 2137 (((rules[units[unit_count - 2]].flags &
2138 VOWEL) && 2138 VOWEL) &&
2139 !((rules[units[0]].flags & 2139 !((rules[units[0]].flags &
2140 ALTERNATE_VOWEL) && 2140 ALTERNATE_VOWEL) &&
2141 (unit_count == 2))) && 2141 (unit_count == 2))) &&
2142 (rules[units[unit_count - 1]].flags & 2142 (rules[units[unit_count - 1]].flags &
2143 VOWEL) && 2143 VOWEL) &&
2144 (rules[units[unit_count]].flags & 2144 (rules[units[unit_count]].flags &
2145 VOWEL))))) 2145 VOWEL)))))
2146 failure = TRUE; 2146 failure = true;
2147 } 2147 }
2148 2148
2149 /* 2149 /*
2150 * Count the vowels in the syllable. As mentioned somewhere 2150 * Count the vowels in the syllable. As mentioned somewhere
2151 * above, exclude the initial y of a syllable. Instead, 2151 * above, exclude the initial y of a syllable. Instead,
2152 * treat it as a consonant. 2152 * treat it as a consonant.
2153 */ 2153 */
2154 if ((rules[units[unit_count]].flags & VOWEL) && 2154 if ((rules[units[unit_count]].flags & VOWEL) &&
2155 !((rules[units[0]].flags & ALTERNATE_VOWEL) && 2155 !((rules[units[0]].flags & ALTERNATE_VOWEL) &&
2156 (unit_count == 0) && (pwlen != 0))) 2156 (unit_count == 0) && (pwlen != 0)))
(...skipping 21 matching lines...) Expand all
2178 * index 1 appears 10 times in the array, the probability of 2178 * index 1 appears 10 times in the array, the probability of
2179 * selecting an `a' is 10/211. 2179 * selecting an `a' is 10/211.
2180 * 2180 *
2181 * Changes may be made to the digram table without affect to this 2181 * Changes may be made to the digram table without affect to this
2182 * procedure providing the letter-to-number correspondence of 2182 * procedure providing the letter-to-number correspondence of
2183 * the units does not change. Likewise, the distribution of the 2183 * the units does not change. Likewise, the distribution of the
2184 * 34 units may be altered (and the array size may be changed) 2184 * 34 units may be altered (and the array size may be changed)
2185 * in this procedure without affecting the digram table or any other 2185 * in this procedure without affecting the digram table or any other
2186 * programs using the Random_word subroutine. 2186 * programs using the Random_word subroutine.
2187 */ 2187 */
2188 static USHORT numbers[] = 2188 static unsigned short numbers[] =
2189 { 2189 {
2190 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2190 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2191 1, 1, 1, 1, 1, 1, 1, 1, 2191 1, 1, 1, 1, 1, 1, 1, 1,
2192 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2192 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2193 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2193 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
2194 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 2194 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
2195 5, 5, 5, 5, 5, 5, 5, 5, 2195 5, 5, 5, 5, 5, 5, 5, 5,
2196 6, 6, 6, 6, 6, 6, 6, 6, 2196 6, 6, 6, 6, 6, 6, 6, 6,
2197 7, 7, 7, 7, 7, 7, 2197 7, 7, 7, 7, 7, 7,
2198 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 2198 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
(...skipping 28 matching lines...) Expand all
2227 /* 2227 /*
2228 * This structure has a typical English frequency of vowels. 2228 * This structure has a typical English frequency of vowels.
2229 * The value of an entry is the vowel position (a=0, e=4, i=8, 2229 * The value of an entry is the vowel position (a=0, e=4, i=8,
2230 * o=14, u=19, y=23) in the rules array. The number of times 2230 * o=14, u=19, y=23) in the rules array. The number of times
2231 * the value appears is the frequency. Thus, the letter "a" 2231 * the value appears is the frequency. Thus, the letter "a"
2232 * is assumed to appear 2/12 = 1/6 of the time. This array 2232 * is assumed to appear 2/12 = 1/6 of the time. This array
2233 * may be altered if better data is obtained. The routines that 2233 * may be altered if better data is obtained. The routines that
2234 * use vowel_numbers will adjust to the size difference 2234 * use vowel_numbers will adjust to the size difference
2235 automatically. 2235 automatically.
2236 */ 2236 */
2237 static USHORT vowel_numbers[] = 2237 static unsigned short vowel_numbers[] =
2238 { 2238 {
2239 0, 0, 4, 4, 4, 8, 8, 14, 14, 19, 19, 23 2239 0, 0, 4, 4, 4, 8, 8, 14, 14, 19, 19, 23
2240 }; 2240 };
2241 2241
2242 2242
2243 /* 2243 /*
2244 * Select a unit (a letter or a consonant group). If a vowel is 2244 * Select a unit (a letter or a consonant group). If a vowel is
2245 * expected, use the vowel_numbers array rather than looping through 2245 * expected, use the vowel_numbers array rather than looping through
2246 * the numbers array until a vowel is found. 2246 * the numbers array until a vowel is found.
2247 */ 2247 */
2248 USHORT 2248 unsigned short
2249 random_unit (USHORT type) 2249 random_unit (unsigned short type)
2250 { 2250 {
2251 USHORT number; 2251 unsigned short number;
2252 2252
2253 /* 2253 /*
2254 * Sometimes, we are asked to explicitly get a vowel (i.e., if 2254 * Sometimes, we are asked to explicitly get a vowel (i.e., if
2255 * a digram pair expects one following it). This is a shortcut 2255 * a digram pair expects one following it). This is a shortcut
2256 * to do that and avoid looping with rejected consonants. 2256 * to do that and avoid looping with rejected consonants.
2257 */ 2257 */
2258 if (type & VOWEL) 2258 if (type & VOWEL)
2259 number = vowel_numbers[ 2259 number = vowel_numbers[
2260 base::RandInt(0, (sizeof (vowel_numbers) / sizeof (USHORT))-1)]; 2260 base::RandInt(0, (sizeof (vowel_numbers) / sizeof (unsigned short))-1) ];
2261 else 2261 else
2262 /* 2262 /*
2263 * Get any letter according to the English distribution. 2263 * Get any letter according to the English distribution.
2264 */ 2264 */
2265 number = numbers[ 2265 number = numbers[
2266 base::RandInt(0, (sizeof (numbers) / sizeof (USHORT))-1)]; 2266 base::RandInt(0, (sizeof (numbers) / sizeof (unsigned short))-1)];
2267 return (number); 2267 return (number);
2268 } 2268 }
OLDNEW
« no previous file with comments | « third_party/fips181/fips181.h ('k') | third_party/fips181/owntypes.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698