From 6a68c2399bb251ec4d1c28a103272fc0cb7b0dbe Mon Sep 17 00:00:00 2001 From: cancel Date: Fri, 13 Sep 2019 10:02:09 +0900 Subject: [PATCH] Change --seed to use atoi, change init_seed to int This avoids using `long` in orca-c, which had previous been avoided. Using `long` comes with some baggage. It would be best to avoid it where possible, especially since there are no other uses of it orca-c. If explicit sizes are needed, use the types from stdint.h. The only reason `int` is used for argument handling in orca-c's TUI is that `atoi` requires it. `atol` doesn't provide any advantage over `atoi`, except to allow the `--seed` option to be larger on some platforms and some configurations. But I think it's better to have consistent argument handling, and have `--seed` always have a range of `0..INT_MAX`, which is going to be signed 32-bit max on almost every platform, unlike `long`. This change also allows init_seed to be set to 0, where it previously was not allowed. The default still remains 1. --- tui_main.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tui_main.c b/tui_main.c index cfd3d31..ef1470e 100644 --- a/tui_main.c +++ b/tui_main.c @@ -1880,7 +1880,7 @@ int main(int argc, char** argv) { char const* osc_port = NULL; bool strict_timing = false; int init_bpm = 120; - long init_seed = 1; + int init_seed = 1; int init_grid_dim_y = 25; int init_grid_dim_x = 57; Midi_mode midi_mode; @@ -1930,11 +1930,11 @@ int main(int argc, char** argv) { } } break; case Argopt_seed: { - init_seed = atol(optarg); - if (init_seed < 1) { + init_seed = atoi(optarg); + if (init_seed < 0 || (init_seed == 0 && strcmp(optarg, "0"))) { fprintf(stderr, "Bad seed argument %s.\n" - "Must be positive integer.\n", + "Must be 0 or positive integer.\n", optarg); exit(1); }