diff options
author | Adam Spragg <adam@spra.gg> | 2022-12-30 12:07:20 +0000 |
---|---|---|
committer | Adam Spragg <adam@spra.gg> | 2022-12-30 12:07:20 +0000 |
commit | 670ef721b13e907a1da915080b146b9e7dc1c3b8 (patch) | |
tree | 2dfc6040393e72af781ed2b7b94cc6a970f6c2ad /19.c | |
parent | d9ce5d31b273328be1d5d47f3e8608fcb2de18b1 (diff) |
Puzzle 19: Allow user to specify build strategy
Diffstat (limited to '19.c')
-rw-r--r-- | 19.c | 17 |
1 files changed, 15 insertions, 2 deletions
@@ -2,6 +2,7 @@ #include <regex.h> #include <stdio.h> #include <stdlib.h> +#include <string.h> #include <unistd.h> @@ -181,13 +182,18 @@ int main(int argc, char ** argv) { int rounds = 24; + char const * build = "basic"; int i; regex_t reblueprint; char buf[BUFSIZ]; - while ((i = getopt(argc, argv, "r:")) != -1) + while ((i = getopt(argc, argv, "b:r:")) != -1) { switch (i) { + case 'b': + build = optarg; + break; + case 'r': rounds = atoi(optarg); break; @@ -229,7 +235,14 @@ main(int argc, char ** argv) inventory_init(&i); - inventory_build_basic(&i, &b, rounds); + if (strcmp(build, "basic") == 0) { + inventory_build_basic(&i, &b, rounds); + } + else { + fprintf(stderr, "Unknown build strategy: %s\n", build); + regfree(&reblueprint); + return -1; + } printf("Blueprint %d geodes = %ld\n", b.id, i.geod.amount); } |