diff --git a/celseed.c b/celseed.c index b7a2a7a..5d8498a 100644 --- a/celseed.c +++ b/celseed.c @@ -643,6 +643,8 @@ static void usage(const char *prog) { " --large Enable large biomes\n" " --quiet Print only seed values to stdout\n" " --verbose Print seed index alongside value\n" +" --output FILE, -o Write matched seeds to FILE (one per line)\n" +" --append Append to output file instead of overwriting\n" " --log-level LEVEL trace|debug|info|warn|error|off (default: info)\n" " --log-file FILE Write logs to FILE in addition to stderr\n" " --no-progress Disable progress bar\n" @@ -689,6 +691,8 @@ int main(int argc, char **argv) { bool verbose = false; int log_level = LOG_INFO; const char *log_file = NULL; + const char *out_file = NULL; + bool out_append = false; int prog_force = 0; /* 0=auto, 1=on, -1=off */ for (int i=1; i=argc) { fprintf(stderr,"--output requires a filename\n"); return 1; } + out_file=argv[++i]; + } + else if (!strcmp(argv[i],"--append")) { out_append=true; } else if (!strcmp(argv[i],"--no-progress")) { prog_force=-1; } else if (!strcmp(argv[i],"--progress")) { prog_force=1; } else if (!strcmp(argv[i],"--list-versions")) { list_versions(); return 0; } @@ -740,6 +749,13 @@ int main(int argc, char **argv) { log_add_callback(log_file_cb, log_fp, LOG_TRACE); } + FILE *out_fp = NULL; + if (out_file) { + out_fp = fopen(out_file, out_append ? "a" : "w"); + if (!out_fp) { perror(out_file); return 1; } + log_debug("output file: %s (%s)", out_file, out_append ? "append" : "overwrite"); + } + /* Set up progress bar */ g_bar.is_tty = (prog_force == 1) || (prog_force == 0 && stderr_is_tty); g_bar.enabled = (prog_force >= 0) && (prog_force == 1 || stderr_is_tty); @@ -817,6 +833,10 @@ int main(int argc, char **argv) { printf("%"PRId64"\n", (int64_t)seed); fflush(stdout); } + if (out_fp) { + fprintf(out_fp, "%"PRId64"\n", (int64_t)seed); + fflush(out_fp); + } log_info("found seed=%-20"PRId64" [%"PRIu64"/%"PRIu64"]", (int64_t)seed, found, count); g_bar.found = found; @@ -837,6 +857,10 @@ int main(int argc, char **argv) { log_info("done tested=%"PRIu64" found=%"PRIu64" elapsed=%.2fs", tested, found, elapsed); bar_finish(tested, found, elapsed); + if (out_fp) { + fclose(out_fp); + log_info("seeds written to %s", out_file); + } if (log_fp) fclose(log_fp); return 0; }