From 00d60c46204a072f5ed96d7498692f0b48cc8bc4 Mon Sep 17 00:00:00 2001 From: Anthony Wang Date: Tue, 30 Jan 2024 22:39:58 -0500 Subject: Don't require -f flag for specifying file (adding -f won't hurt though), allow specifying sd-add card file as argv[1] --- sd-add.fish | 5 ++--- sd.c | 22 ++++++---------------- 2 files changed, 8 insertions(+), 19 deletions(-) diff --git a/sd-add.fish b/sd-add.fish index 69bb353..dd4eb62 100644 --- a/sd-add.fish +++ b/sd-add.fish @@ -1,5 +1,4 @@ function sd-add - set cardfile cards - set idx (math 1+(sqlite3 "$cardfile" "SELECT MAX(idx) FROM cards")) - sqlite3 "$cardfile" "INSERT INTO cards VALUES ($idx, 256, '$argv[1]', '$argv[2]')" + set idx (math 1+(sqlite3 "$argv[1]" "SELECT MAX(idx) FROM cards")) + sqlite3 "$argv[1]" "INSERT INTO cards VALUES ($idx, 256, '$argv[2]', '$argv[3]')" end diff --git a/sd.c b/sd.c index 0e39156..b7bab8b 100644 --- a/sd.c +++ b/sd.c @@ -2,31 +2,21 @@ #include #include #include +#include #include -#include #include #include "segmenttree.h" -int main(int argc, char* argv[]) { +int main(int argc, char *argv[]) { char *file = "cards"; bool verbose = false; bool noninteractive = false; /* Proccess args */ - static struct option long_options[] = { - {"file", required_argument, NULL, 'f'}, - {"verbose", no_argument, NULL, 'v'}, - {"noninteractive", no_argument, NULL, 'n'} - }; - while (true) { - int c = getopt_long(argc, argv, "f:vn", long_options, NULL); - if (c == -1) break; - switch (c) { - case 'f': file = optarg; break; - case 'v': verbose = true; break; - case 'n': noninteractive = true; break; - default: abort(); - } + for (int i = 1; i < argc; i++) { + if (strcmp(argv[i], "-v") == 0) verbose = true; + else if (strcmp(argv[i], "-n") == 0) noninteractive = true; + else file = argv[i]; } /* Seed the RNG */ -- cgit v1.2.3-70-g09d2