From 4ab8b87c93e1d6c12fb58e9de7b214babd500226 Mon Sep 17 00:00:00 2001 From: Huck Boles Date: Tue, 3 Jan 2023 00:00:07 -0600 Subject: [PATCH] Tue Jan 3 12:00:07 AM CST 2023 automatic backup --- Makefile | 2 ++ actions.c | 2 +- database.c | 2 +- function.c | 4 ++-- odot.c | 30 +++++++++++++++++++----------- odot.h | 6 +++++- 6 files changed, 30 insertions(+), 16 deletions(-) diff --git a/Makefile b/Makefile index 3254a15..f50d060 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,7 @@ SHELL = /bin/bash PREFIX = /usr DESTDIR = $(PREFIX)/bin +MANDIR = $(PREFIX)/share/man PROG = odot @@ -33,6 +34,7 @@ build: $(CFILE) $(HEADER) sqlite3.c install: $(CFILE) $(HEADER) sqlite3.c $(CC) $(CFILE) sqlite3.c $(CFLAGS) -o $(PROG) install -CDTm 755 $(PROG) $(DESTDIR)/$(PROG) + install -CDTm 644 $(PROG).1 $(MANDIR)/$(PROG).1 debug: $(CFILE) $(CC) $(CFILE) sqlite3.o $(CFLAGS) -ggdb3 -Og -o $(PROG) diff --git a/actions.c b/actions.c index fa6d249..2ee8431 100644 --- a/actions.c +++ b/actions.c @@ -48,7 +48,7 @@ void done(sqlite3 *db){ void update(sqlite3 *db){ /* terminates if newgroup isn't set*/ - if (strcmp(newgroup,"") == 0) error(5); + if (strcmp(newgroup,"") == 0) error(GRPERR); char *cmd = malloc(MAXLINE*sizeof(char)); if (exists == 1) { diff --git a/database.c b/database.c index 0d44fd6..a2f737f 100644 --- a/database.c +++ b/database.c @@ -30,7 +30,7 @@ void sqlcmd(sqlite3 *db, char *cmd, char action){ void sqlerror(sqlite3 *db) { fprintf(stderr, "%s\n", sqlite3_errmsg(db)); sqlite3_close(db); - error(1); + error(SQLERR); } int printcallback(void *unused,int argc, char **argv, char **name){ diff --git a/function.c b/function.c index dabfd32..e2635bd 100644 --- a/function.c +++ b/function.c @@ -28,7 +28,7 @@ char *filepath(void){ /* set dir to $HOME/.local/share if XDG isn't set */ if (!dir) { dir = getenv("HOME"); - if (!dir) error(3); + if (!dir) error(ENVERR); strcat(dir,"/.local/share"); } strcat(dir,"/odot"); @@ -40,7 +40,7 @@ char *filepath(void){ closedir(test); } else { int err = mkdir(dir, 0777); - if (err) error(2); + if (err) error(DIRERR); } sprintf(db,"%s/odot.db",dir); diff --git a/odot.c b/odot.c index 53fe21e..406121b 100644 --- a/odot.c +++ b/odot.c @@ -14,7 +14,7 @@ char *group, action; int main(int argc, char *argv[]){ - /* show help if no arguments unless its just showing tasks */ + /* show help if just subcommand called, unless its just showing tasks */ if (argc == 2 && strcmp(argv[1],"show") != 0) help(); int err = 0; @@ -38,6 +38,7 @@ int main(int argc, char *argv[]){ parseopt(argc,argv); hash = genhash(); + /* checks if task already exists in db */ dbcheck(db); switch (action){ @@ -57,7 +58,7 @@ int main(int argc, char *argv[]){ /* always gets shown unless quiet is set */ break; case '?': - error(4); + error(CMDERR); } /* show db after action */ @@ -96,7 +97,7 @@ void parseopt(int n, char **args){ strcpy(newgroup,optarg); break; case '?': - error(4); + error(FLAGERR); break; } } @@ -113,20 +114,24 @@ void parseopt(int n, char **args){ void error(int err){ switch (err) { - case 1: + case SQLERR: fprintf(stderr,"^^ SQL error ^^\n"); break; - case 2: + case DIRERR: fprintf(stderr,"Could not create odot directory\n\t$XDG_DATA_HOME/odot\n"); break; - case 3: + case ENVERR: fprintf(stderr,"Could not determine $HOME\n"); break; - case 4: - fprintf(stderr,"Unknown Command\n"); + case FLAGERR: + fprintf(stderr,"Unknown Flag\n"); help(); break; - case 5: + case CMDERR: + fprintf(stderr,"Unknown Subcommand\n"); + help(); + break; + case GRPERR: fprintf(stderr,"Specify new group with -G\n"); break; } @@ -135,18 +140,21 @@ void error(int err){ void help(){ printf("Usage: odot [subcommand] (task)\n"); - printf("\tSubcommands:\n"); + printf("Subcommands:\n"); printf("\tnew\tadd new task to database\n"); printf("\tdone\tmark task as done in database\n"); printf("\tupdate\tupdate task group, requires -G\n"); printf("\tshow\tshow tasks in database\n"); printf("\tremove\tremove task from database\t\n"); - printf("\tOptions:\n"); + printf("Option flags:\n"); printf("\t-a\tshow all groups\n"); printf("\t-d\talso show completed tasks\n"); printf("\t-g\tset group for task\n"); printf("\t-G\tnew group for update"); + printf("\t-q\tdon't show tasks\n"); + printf("\t-V\tversion information\n"); printf("\t-h\tshow this help\n"); + exit(0); } diff --git a/odot.h b/odot.h index e76bb07..397b0d0 100644 --- a/odot.h +++ b/odot.h @@ -12,6 +12,7 @@ #define VERSION "0.2.1" #define MAXLINE 10000 +/* sql commands */ #define BUILDTABLE "CREATE TABLE IF NOT EXISTS Tasks (Hash int NOT NULL PRIMARY KEY, Task varchar(10000) NOT NULL, Type varchar(32), Done int NOT NULL DEFAULT 0, Timestamp DATETIME DEFAULT CURRENT_TIMESTAMP, Duedate DATETIME);" #define INSERT "INSERT INTO Tasks VALUES" @@ -24,10 +25,13 @@ #define PRINTGROUP "SELECT Done, Task FROM Tasks WHERE Done = 0 AND Type =" #define PRINTGROUPALL "SELECT Done, Task FROM Tasks WHERE Type =" +/* error handling */ +enum {SQLERR = 1, DIRERR = 1 << 1, ENVERR = 1 << 2, FLAGERR = 1 << 3, CMDERR = 1 << 4, GRPERR = 1 << 5}; + +/* main.c */ void error(int); void help(void); void parseopt(int, char **); -void operate(sqlite3 *); /* action.c */ void dbcheck(sqlite3 *db); -- 2.45.2