diff options
Diffstat (limited to 'cmd/main.c')
-rw-r--r-- | cmd/main.c | 39 |
1 files changed, 37 insertions, 2 deletions
@@ -18,16 +18,51 @@ #define _GNU_SOURCE +#include <getopt.h> #include <libguile.h> #include <stdbool.h> #include <stdio.h> #include <stdlib.h> +#include <string.h> #include "othello.h" int main(int argc, char **argv) { - (void)argc; - (void)argv; + static const struct option long_options[] = { + {"help", no_argument, NULL, 'h'}, + {"player-one", required_argument, NULL, '1'}, + {"player-two", required_argument, NULL, '2'}, + {0, 0, 0, 0}}; + + const char *usage = + " -h --help show help output\n" + " -1 --player-one <file> specify a file to use for player one strategy\n" + " -2 --player-two <file> specify a file to use for player one strategy\n"; + + char *player_one_strategy_path = NULL; + char *player_two_strategy_path = NULL; + + int c; + while (1) { + int option_index = 0; + c = getopt_long(argc, argv, "h1:2:", long_options, &option_index); + if (c == -1) { + break; + } + switch (c) { + case 'h': + printf("%s", usage); + exit(EXIT_SUCCESS); + case '1': + free(player_one_strategy_path); + player_one_strategy_path = strdup(optarg); + break; + case '2': + free(player_two_strategy_path); + player_two_strategy_path = strdup(optarg); + break; + } + } enum player_color winner = game_loop(); |