diff options
author | Nor Khasyatillah <mazznoer@ymail.com> | 2022-06-06 18:10:53 +0700 |
---|---|---|
committer | jaseg <git@jaseg.de> | 2022-11-19 12:49:46 +0100 |
commit | 37bb84e2977265331503236ed78d39ca04352226 (patch) | |
tree | 3727264221297310dbf2acf432f89da6d6c5f6ab | |
parent | 2a23642da7d6b98dd7c4c3b92c5e3fef3c70fb9d (diff) | |
download | lolcat-37bb84e2977265331503236ed78d39ca04352226.tar.gz lolcat-37bb84e2977265331503236ed78d39ca04352226.tar.bz2 lolcat-37bb84e2977265331503236ed78d39ca04352226.zip |
Add new option `--seed`
-rwxr-xr-x | lolcat.c | 14 |
1 files changed, 13 insertions, 1 deletions
@@ -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 <d>, -s <d>: Random colors based on given seed, implies --random\n" " --color_offset <d>, -o <d>: 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) { |