mirror of
https://codeberg.org/scip/diceware.git
synced 2025-12-17 02:40:57 +01:00
format
This commit is contained in:
105
dictfile.c
105
dictfile.c
@@ -27,39 +27,35 @@ int *incr_dicedigit(int *digits) {
|
||||
be a multiple of 10000, the 2nd a multiple of 1000 and so on.
|
||||
*/
|
||||
|
||||
if(digits[4] == 6) {
|
||||
if (digits[4] == 6) {
|
||||
digits[4] = 1;
|
||||
if(digits[3] == 60) {
|
||||
if (digits[3] == 60) {
|
||||
digits[3] = 10;
|
||||
if(digits[2] == 600) {
|
||||
digits[2] = 100;
|
||||
if(digits[1] == 6000) {
|
||||
digits[1] = 1000;
|
||||
digits[0] += 10000; /* may overflow to 71111, must be catched by caller */
|
||||
}
|
||||
else
|
||||
digits[1] += 1000;
|
||||
}
|
||||
else
|
||||
digits[2] += 100;
|
||||
}
|
||||
else
|
||||
if (digits[2] == 600) {
|
||||
digits[2] = 100;
|
||||
if (digits[1] == 6000) {
|
||||
digits[1] = 1000;
|
||||
digits[0] +=
|
||||
10000; /* may overflow to 71111, must be catched by caller */
|
||||
} else
|
||||
digits[1] += 1000;
|
||||
} else
|
||||
digits[2] += 100;
|
||||
} else
|
||||
digits[3] += 10;
|
||||
}
|
||||
else
|
||||
} else
|
||||
digits[4]++;
|
||||
|
||||
return digits;
|
||||
}
|
||||
|
||||
|
||||
int get_dicenum(int *digits) {
|
||||
/*
|
||||
get the actual number of an array of dice digits
|
||||
*/
|
||||
int i = 0;
|
||||
int pos = 0;
|
||||
for(i=0; i<5; i++)
|
||||
for (i = 0; i < 5; i++)
|
||||
pos += digits[i];
|
||||
|
||||
return pos;
|
||||
@@ -82,7 +78,7 @@ char **fetch_dict(char *dictfile) {
|
||||
FILE *DICT;
|
||||
int *digits;
|
||||
|
||||
if((DICT = fopen(dictfile, "rb")) == NULL) {
|
||||
if ((DICT = fopen(dictfile, "rb")) == NULL) {
|
||||
perror("Could not open dictfile");
|
||||
exit(1);
|
||||
}
|
||||
@@ -90,65 +86,64 @@ char **fetch_dict(char *dictfile) {
|
||||
words = malloc(66666 * sizeof(char *));
|
||||
digits = malloc(5 * sizeof(int));
|
||||
jump = rand_lim(32);
|
||||
|
||||
digits[0] = 10000;
|
||||
digits[1] = 1000;
|
||||
digits[2] = 100;
|
||||
digits[3] = 10;
|
||||
digits[4] = 1;
|
||||
|
||||
pos = 11111;
|
||||
digits[0] = 10000;
|
||||
digits[1] = 1000;
|
||||
digits[2] = 100;
|
||||
digits[3] = 10;
|
||||
digits[4] = 1;
|
||||
|
||||
pos = 11111;
|
||||
next = 0;
|
||||
|
||||
for(i=0; i<6666; i++)
|
||||
for (i = 0; i < 6666; i++)
|
||||
words[i] = NULL;
|
||||
|
||||
|
||||
LOOP:
|
||||
LOOP:
|
||||
while ((linelen = getline(&line, &len, DICT)) != -1) {
|
||||
if(! dontjump) {
|
||||
if(jump > 0) {
|
||||
jump--;
|
||||
continue;
|
||||
}
|
||||
else {
|
||||
jump = rand_lim(32);
|
||||
if (!dontjump) {
|
||||
if (jump > 0) {
|
||||
jump--;
|
||||
continue;
|
||||
} else {
|
||||
jump = rand_lim(32);
|
||||
}
|
||||
}
|
||||
if(linelen >= WMIN+1 && linelen <= WMAX+1) {
|
||||
line[linelen-1] = '\0'; /* remove newline */
|
||||
if (linelen >= WMIN + 1 && linelen <= WMAX + 1) {
|
||||
line[linelen - 1] = '\0'; /* remove newline */
|
||||
|
||||
for(i=0; i<linelen-1; i++) {
|
||||
if(isalnum((int)line[i]) == 0) {
|
||||
next = 1;
|
||||
break;
|
||||
}
|
||||
for (i = 0; i < linelen - 1; i++) {
|
||||
if (isalnum((int)line[i]) == 0) {
|
||||
next = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(next) {
|
||||
next = 0;
|
||||
continue;
|
||||
if (next) {
|
||||
next = 0;
|
||||
continue;
|
||||
}
|
||||
|
||||
words[pos] = malloc(linelen);
|
||||
strncpy( words[pos], line, linelen);
|
||||
if(verbose > 1)
|
||||
debug("add to wordlist at index %d: %s", pos, line);
|
||||
strncpy(words[pos], line, linelen);
|
||||
if (verbose > 1)
|
||||
debug("add to wordlist at index %d: %s", pos, line);
|
||||
|
||||
digits = incr_dicedigit(digits);
|
||||
pos = get_dicenum(digits);
|
||||
|
||||
/* this is what pos gets next after 66666, which is max reachable with 5 dices */
|
||||
if(pos == 71111)
|
||||
break;
|
||||
/* this is what pos gets next after 66666, which is max reachable with 5
|
||||
* dices */
|
||||
if (pos == 71111)
|
||||
break;
|
||||
} /* endif word 4<=>10 */
|
||||
} /* while read */
|
||||
|
||||
if(pos < 66666) {
|
||||
if (pos < 66666) {
|
||||
fseek(DICT, 0L, SEEK_SET);
|
||||
goto LOOP;
|
||||
}
|
||||
|
||||
|
||||
fclose(DICT);
|
||||
free(line);
|
||||
free(digits);
|
||||
|
||||
Reference in New Issue
Block a user