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