From 37bb84e2977265331503236ed78d39ca04352226 Mon Sep 17 00:00:00 2001 From: Nor Khasyatillah Date: Mon, 6 Jun 2022 18:10:53 +0700 Subject: Add new option `--seed` --- lolcat.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/lolcat.c b/lolcat.c index 8257b34..bed0c6b 100755 --- a/lolcat.c +++ b/lolcat.c @@ -41,6 +41,7 @@ static char helpstr[] = "\n" " --no-force-locale, -l: Use encoding from system locale instead of\n" " assuming UTF-8\n" " --random, -r: Random colors\n" + " --seed , -s : Random colors based on given seed, implies --random\n" " --color_offset , -o : Start with a different color\n" " --24bit, -b: Output in 24-bit \"true\" RGB mode (slower and\n" " not supported by all terminals)\n" @@ -104,6 +105,7 @@ int main(int argc, char** argv) int colors = isatty(STDOUT_FILENO); int force_locale = 1; int random = 0; + unsigned int seed = time(NULL); int start_color = 0; int rgb = 0; int ansi16 = 0; @@ -137,6 +139,15 @@ int main(int argc, char** argv) force_locale = 0; } else if (!strcmp(argv[i], "-r") || !strcmp(argv[i], "--random")) { random = 1; + } else if (!strcmp(argv[i], "-S") || !strcmp(argv[i], "--seed")) { + random = 1; + if ((++i) < argc) { + seed = strtoul(argv[i], &endptr, 10); + if (*endptr) + usage(); + } else { + usage(); + } } else if (!strcmp(argv[i], "-o") || !strcmp(argv[i], "--color_offset")) { if ((++i) < argc) { start_color = strtod(argv[i], &endptr); @@ -165,9 +176,10 @@ int main(int argc, char** argv) int rand_offset = 0; if (random) { - srand(time(NULL)); + srand(seed); rand_offset = rand(); } + char** inputs = argv + i; char** inputs_end = argv + argc; if (inputs == inputs_end) { -- cgit