diff options
Diffstat (limited to 'cph.c')
-rw-r--r-- | cph.c | 57 |
1 files changed, 55 insertions, 2 deletions
@@ -21,13 +21,66 @@ #include <stdio.h> #include <stdlib.h> #include <time.h> +#include <getopt.h> static const char *answer_yes = "y"; static const char *answer_no = "n"; -int main(void) +static unsigned int seed_g; + +static struct option options_g[] = { + { + .name = "yes", + .has_arg = required_argument, + .flag = NULL, + .val = 'y', + }, { + .name = "no", + .has_arg = required_argument, + .flag = NULL, + .val = 'n', + }, { + .name = 0, + .has_arg = 0, + .flag = NULL, + .val = 0, + } +}; + +static int parse_arguments(int *argcp, char *argv[]) +{ + int opt; + int ret = 0; + + while ((opt = getopt_long(*argcp, argv, "y:n:s:", options_g, NULL)) >= 0) + { + switch (opt) { + case 'y': + answer_yes = optarg; + break; + case 'n': + answer_no = optarg; + break; + case '?': + ret = -1; + break; + default: + break; + } + } + + return ret; +} + +int main(int argc, char *argv[]) { - srand(time(NULL)); + seed_g = time(NULL); + if (parse_arguments(&argc, argv) < 0) { + fprintf(stderr, "usage: %s [OPTIONS]\n", argv[0]); + return -1; + } + + srand(seed_g); for (;;) { switch (rand() % 2) { |