From 4dbd3e2c85e761b7fa5a0a03d073bf8612d36cce Mon Sep 17 00:00:00 2001 From: Curtis McEnroe Date: Thu, 23 May 2019 19:39:19 -0400 Subject: Open path given to -t read-only --- play.c | 18 ++++++++++++++++-- 1 file 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 #include #include +#include #ifdef __FreeBSD__ #include @@ -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(); -- cgit 1.4.1