diff options
Diffstat (limited to 'cmd/main.c')
-rw-r--r-- | cmd/main.c | 32 |
1 files changed, 24 insertions, 8 deletions
@@ -19,6 +19,7 @@ #define _GNU_SOURCE #include <getopt.h> +#include <errno.h> #include <libguile.h> #include <stdbool.h> #include <stdio.h> @@ -37,10 +38,10 @@ int main(int argc, char **argv) { 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"; + " -2 --player-two <file> specify a file to use for player two strategy\n"; - char *player_one_strategy_path = NULL; - char *player_two_strategy_path = NULL; + FILE *player_one_strategy = NULL; + FILE *player_two_strategy = NULL; int c; while (1) { @@ -49,22 +50,37 @@ int main(int argc, char **argv) { if (c == -1) { break; } + errno = 0; switch (c) { case 'h': printf("%s", usage); exit(EXIT_SUCCESS); case '1': - free(player_one_strategy_path); - player_one_strategy_path = strdup(optarg); + /*char *player_one_strategy_path = strdup(optarg);*/ + if (player_one_strategy != NULL) { + fclose(player_one_strategy); + } + player_one_strategy = fopen(optarg, "r"); + if (errno != 0) { + perror("Could not open player 1 strategy"); + } + /*free(player_one_strategy_path);*/ break; case '2': - free(player_two_strategy_path); - player_two_strategy_path = strdup(optarg); + if (player_two_strategy != NULL) { + fclose(player_two_strategy); + } + player_two_strategy = fopen(optarg, "r"); + if (errno != 0) { + perror("Could not open player 2 strategy"); + } + /*char *player_two_strategy_path = strdup(optarg);*/ + /*free(player_two_strategy_path);*/ break; } } - enum player_color winner = game_loop(); + enum player_color winner = game_loop(player_one_strategy, player_two_strategy); switch (winner) { case WHITE: |