X-Git-Url: https://plomlompom.com/repos/%7B%7B%20web_path%20%7D%7D/decks/%7B%7Bdeck_id%7D%7D/cards/%7B%7Bcard_id%7D%7D/static/git-logo.png?a=blobdiff_plain;f=src%2Fmisc.c;h=8d38d59c383297ef3be00af1f3f67ce562d5e01c;hb=0f12557b88c73f8629ffafc38dc59ab5bd15e687;hp=683346f84efd974538a501f904b18f1d909e5ae7;hpb=e4f2a14c7385d99d49cf831cd3fd92234caf71b5;p=plomrogue diff --git a/src/misc.c b/src/misc.c index 683346f..8d38d59 100644 --- a/src/misc.c +++ b/src/misc.c @@ -10,6 +10,26 @@ #include "main.h" #include "yx_uint16.h" +extern void textfile_sizes (FILE * file, uint16_t * linemax_p, uint16_t * n_lines_p) { +// Learn largest line length (linemax_p) and (n_lines_p if not set to NULL) number of lines. + uint16_t n_lines = 0; + int c = 0; + uint16_t linemax = 0; + uint16_t c_count = 0; + while (EOF != c) { + c_count++; + c = getc(file); + if ('\n' == c) { + if (c_count > linemax) + linemax = c_count + 1; + c_count = 0; + if (n_lines_p) + n_lines++; } } + fseek(file, 0, SEEK_SET); + * linemax_p = linemax; + if (n_lines_p) + * n_lines_p = n_lines; } + extern uint16_t rrand(char use_seed, uint32_t new_seed) { // Pseudo-random number generator (LGC algorithm). Use instead of rand() to ensure portable predictability. static uint32_t seed;