diff options
author | June McEnroe <june@causal.agency> | 2019-05-23 19:39:19 -0400 |
---|---|---|
committer | June McEnroe <june@causal.agency> | 2019-05-23 19:39:19 -0400 |
commit | 4dbd3e2c85e761b7fa5a0a03d073bf8612d36cce (patch) | |
tree | 76673b28e82684599df6224d0e795e8cd9b31e92 | |
parent | Add -t option to print scores as text (diff) | |
download | play-4dbd3e2c85e761b7fa5a0a03d073bf8612d36cce.tar.gz play-4dbd3e2c85e761b7fa5a0a03d073bf8612d36cce.zip |
Open path given to -t read-only
-rw-r--r-- | play.c | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/play.c b/play.c index 2d8c462..5940d34 100644 --- a/play.c +++ b/play.c @@ -24,6 +24,7 @@ #include <sys/file.h> #include <sysexits.h> #include <time.h> +#include <unistd.h> #ifdef __FreeBSD__ #include <sys/capsicum.h> @@ -160,9 +161,20 @@ static void draw(size_t new) { } int main(int argc, char *argv[]) { - FILE *file = scoresOpen("2048.scores"); + const char *path = NULL; + + int opt; + while (0 < (opt = getopt(argc, argv, "t:"))) { + switch (opt) { + break; case 't': path = optarg; + break; default: return EX_USAGE; + } + } + + if (path) { + FILE *file = fopen(path, "r"); + if (!file) err(EX_NOINPUT, "%s", path); - if (argc > 1 && !strcmp(argv[1], "-t")) { scoresRead(file); printf( "%*s\n", @@ -175,10 +187,12 @@ int main(int argc, char *argv[]) { if (!scores[i].score) break; printf("%s\n", formatScore(i)); } + return EX_OK; } curse(); + FILE *file = scoresOpen("2048.scores"); #ifdef __FreeBSD__ int error = cap_enter(); |