Don't require -f flag for specifying file (adding -f won't hurt though), allow specifying sd-add card file as argv[1]

This commit is contained in:
Anthony Wang 2024-01-30 22:39:58 -05:00
parent a5bfafa8a7
commit 00d60c4620
Signed by: a
SSH key fingerprint: SHA256:B5ADfMCqd2M7d/jtXDoihAV/yfXOAbWWri9+GdCN4hQ
2 changed files with 8 additions and 19 deletions

View file

@ -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

22
sd.c
View file

@ -2,31 +2,21 @@
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <getopt.h>
#include <sqlite3.h>
#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 */