X-Git-Url: https://plomlompom.com/repos/berlin_corona.txt?a=blobdiff_plain;f=src%2Fmisc.c;h=cff42644ca1abe26ff8f9d4997a03d542aa46168;hb=2e690e2500e66535018bb6e01222442c074cb298;hp=683346f84efd974538a501f904b18f1d909e5ae7;hpb=00a66e3c7cbcad13b5c29162e6c1c33235be9f07;p=plomrogue diff --git a/src/misc.c b/src/misc.c index 683346f..cff4264 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; @@ -73,7 +93,7 @@ extern void save_game(struct World * world) { write_uint16_bigendian(world->player->pos.x + 1, file); fputc(world->player->hitpoints, file); write_map_objects (world->monster, file, write_map_objects_monsterdata); - write_map_objects (world->item, file, readwrite_map_objects_dummy); + write_map_objects (world->item, file, NULL); fclose(file); } extern void toggle_window (struct WinMeta * win_meta, struct Win * win) {