summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md15
-rw-r--r--main.c26
2 files changed, 33 insertions, 8 deletions
diff --git a/README.md b/README.md
index f6c9351..3a29dbe 100644
--- a/README.md
+++ b/README.md
@@ -25,12 +25,15 @@ just a number but rather in the form "Volume 6 Chapter 4", shortened to "V6CH4".
When I'm done with an anime or manga, I set the episode or chapter to 0 and set
the status to "done".
-You need to set the filepath to your db-file in the main.c, but everything else
-should work out of the box.
-The Makefile uses clang, because that's what I prefer, but you can change it
-to gcc in the second line. Or you could simply do
-```
-gcc -o myal main.c -lsqlite3
+The database file is expected to be in "~/.local/share/sqlite/library.db".
+To compile, do
+```bash
+make
+```
+ 
+To install it in /usr/local/bin/, do
+```bash
+make install
```
## Usage
diff --git a/main.c b/main.c
index 9ac3f32..526270c 100644
--- a/main.c
+++ b/main.c
@@ -3,8 +3,12 @@
#include <string.h>
#include <unistd.h>
#include <sqlite3.h>
+#include <stdint.h>
+
+const uint8_t PATH_MAX = 64;
+const char *filepath = ".local/share/sqlite";
+const char *filename = "library.db";
-const char *filename = "./library.db";
static int callback(void *NotUsed, int argc, char **argv, char **azColName)
{
@@ -16,6 +20,18 @@ static int callback(void *NotUsed, int argc, char **argv, char **azColName)
return 0;
}
+void print_help(void)
+{
+ printf("usage: myal MODE TARGET NAME [EPISODE|CHAPTER] \n");
+ printf("possible modes are: get|set|add \n");
+ printf("possible targets are: anime|manga \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("\n");
+}
+
void exit_with_error(sqlite3 *db, const char *msg)
{
fprintf(stderr, "%s: %s\n", msg, sqlite3_errmsg(db));
@@ -60,6 +76,7 @@ void select_from_table(sqlite3 *db, char *tblName, char *qp)
id = sqlite3_column_int(stmt, 0);
name = sqlite3_column_text(stmt, 1);
value = sqlite3_column_text(stmt, 2);
+ value = sqlite3_column_text(stmt, 2);
status = sqlite3_column_text(stmt, 3);
printf("%03d: %s, %s %s, %s\n", id, name, type, value, status);
}
@@ -145,6 +162,7 @@ int main(int argc, char **argv)
{
if (argc < 4) {
fprintf(stderr, "missing argument...\n");
+ print_help();
exit(69);
}
char *mode, *target, *name, *value, *status;
@@ -152,10 +170,13 @@ int main(int argc, char **argv)
target = argv[2];
name = argv[3];
+ char fullpath[PATH_MAX];
+ snprintf(fullpath, PATH_MAX, "%s/%s/%s", getenv("HOME"), filepath, filename);
+
sqlite3 *db;
int rc;
- rc = sqlite3_open(filename, &db);
+ rc = sqlite3_open(fullpath, &db);
if (rc) {
exit_with_error(db, "Can't open database: ");
@@ -188,6 +209,7 @@ int main(int argc, char **argv)
add_entry(db, target, name, value, status);
} else {
fprintf(stderr, "unknown option...\n");
+ print_help();
sqlite3_close(db);
exit(69);
}