aboutsummaryrefslogtreecommitdiff
path: root/cd.c
diff options
context:
space:
mode:
authorAnthony Wang2022-04-19 08:23:47 -0500
committerAnthony Wang2022-04-19 08:23:47 -0500
commit74b018bf1c5b89a77447d25b7bbdb1ba7cbc5dd4 (patch)
tree16ee602d816f3e3af6926daa731170fab80357ee /cd.c
parent530da23dfca6c39ed08f2fcd3a106c345c89baeb (diff)
Implement C arg parsing with getopt_long
Diffstat (limited to 'cd.c')
-rw-r--r--cd.c37
1 files changed, 36 insertions, 1 deletions
diff --git a/cd.c b/cd.c
index 617cdaf..14a9105 100644
--- a/cd.c
+++ b/cd.c
@@ -1,7 +1,42 @@
#include <stdio.h>
+#include <stdlib.h>
+#include <stdbool.h>
+#include <string.h>
+#include <unistd.h>
+#include <getopt.h>
#include <sqlite3.h>
#include "segmenttree.h"
int main(int argc, char* argv[]) {
- printf("Hello!");
+ char *file = "cards";
+ bool verbose = false;
+
+ static struct option long_options[] = {
+ {"file", required_argument, 0, 'f'},
+ {"verbose", no_argument, 0, 'v'}
+ };
+ while (1) {
+ int option_index = 0;
+ int c = getopt_long(argc, argv, "f:v", long_options, &option_index);
+ if (c == -1) break;
+ switch (c) {
+ case 'f': file = strdup(optarg); break;
+ case 'v': verbose = true; break;
+ default: abort();
+ }
+ }
+
+ printf("%s", file);
+
+ sqlite3 *db;
+ int rc = sqlite3_open(file, &db);
+ if (rc) {
+ fprintf(stderr, "Can't open database: %s\n", sqlite3_errmsg(db));
+ abort();
+ }
+ fprintf(stderr, "Opened database successfully\n");
+
+ //int N = sqlite3_exec(db, "SELECT COUNT(*) FROM cards", callback)
+
+ sqlite3_close(db);
}