summaryrefslogtreecommitdiff
path: root/src/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c74
1 files changed, 74 insertions, 0 deletions
diff --git a/src/main.c b/src/main.c
new file mode 100644
index 0000000..9dfe71d
--- /dev/null
+++ b/src/main.c
@@ -0,0 +1,74 @@
+#include <stdint.h>
+
+#include "dbhandling.h"
+#include "enum.h"
+
+const uint8_t PATH_MAX = 64;
+const char *filepath = ".local/share/sqlite";
+const char *filename = "library.db";
+
+void print_help(void)
+{
+ printf("\n");
+ printf("usage: myal MODE TARGET NAME [EPISODE|CHAPTER] \n");
+ printf("possible modes are: get|set|add \n");
+ printf("possible targets are: anime|manga|book \n");
+ printf("EXAMPLES: myal get anime %% | Prints all anime \n");
+ printf(" myal set manga Murcielago 10 | Set chapter of " \
+ "Murcielago to 10\n");
+ printf("mode get is fuzzy; set and add have to match exactly \n");
+ printf("See more examples in the readme. \n");
+ printf("\n");
+}
+
+int main(int argc, char **argv)
+{
+ if (argc < 3) {
+ fprintf(stderr, "missing argument...\n");
+ print_help();
+ exit(69);
+ }
+
+ args_e mode;
+ mode = str2enum(argv[1]);
+ args_e target;
+ target = str2enum(argv[2]);
+ entry_t *entry = malloc(sizeof(entry_t));
+ entry->name = malloc(MAX_NAME_LEN);
+ entry->author = malloc(MAX_AUTHOR_LEN);
+ entry->value = malloc(MAX_VALUE_LEN);
+ entry->status = malloc(MAX_STATUS_LEN);
+
+ char fullpath[PATH_MAX];
+ snprintf(fullpath, PATH_MAX, "%s/%s/%s", getenv("HOME"), filepath, filename);
+
+ sqlite3 *db;
+ int rc;
+
+ rc = sqlite3_open(fullpath, &db);
+
+ if (rc) {
+ exit_with_error(db, "Can't open database: ");
+ }
+
+ switch (mode) {
+ case GET:
+ select_from_table(db, target, entry);
+ break;
+ case SET:
+ update_entry(db, target, entry);
+ break;
+ case ADD:
+ add_entry(db, target, entry);
+ break;
+ default:
+ fprintf(stderr, "unknown option...\n");
+ print_help();
+ sqlite3_close(db);
+ exit(69);
+ }
+
+ sqlite3_close(db);
+ free(entry);
+ return 0;
+}