SHELL = /bin/bash
PREFIX = /usr
DESTDIR = $(PREFIX)/bin
+MANDIR = $(PREFIX)/share/man
PROG = odot
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)
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) {
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){
/* 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");
closedir(test);
} else {
int err = mkdir(dir, 0777);
- if (err) error(2);
+ if (err) error(DIRERR);
}
sprintf(db,"%s/odot.db",dir);
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;
parseopt(argc,argv);
hash = genhash();
+ /* checks if task already exists in db */
dbcheck(db);
switch (action){
/* always gets shown unless quiet is set */
break;
case '?':
- error(4);
+ error(CMDERR);
}
/* show db after action */
strcpy(newgroup,optarg);
break;
case '?':
- error(4);
+ error(FLAGERR);
break;
}
}
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;
}
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);
}
#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"
#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);