SHELL = /bin/bash
PREFIX = /usr
DESTDIR = $(PREFIX)/bin
-MANDIR = $(PREFIX)/share/man
+MANDIR = $(PREFIX)/share/man/man1
PROG = odot
OBJECTS = $(PROG).o database.o actions.o function.o sqlite3.o
LDFLAGS = -L .
LDLIBS = -lpthread
-CFLAGS = -O2
-WARNINGS = -Werror -Wall -Wextra -Wpedantic -Wconversion -Wformat=2 -Wformat-signedness -Wstrict-prototypes -Wshadow -Wno-unused
+CFLAGS = -O2 -v
+WARNINGS = -Werror -Wall -Wextra -Wpedantic -Wno-unused
CPPFLAGS = -I .
ALL_CFLAGS = $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) $(LDLIBS) $(WARNINGS)
sql: sqlite3.c
- $(CC) sqlite3.c $(CFLAGS) -c
+ $(CC) sqlite3.c $(ALL_CFLAGS) -c
header: $(HEADER)
- $(CC) $(HEADER) $(CFLAGS) -c
+ $(CC) $(HEADER) $(ALL_CFLAGS) -c
compile: $(CFILE)
- $(CC) $(CFILE) $(CFLAGS) -c
+ $(CC) $(CFILE) $(ALL_CFLAGS) -c
link: $(OBJECTS)
- $(CC) $(OBJECTS) $(CFLAGS) -o $(PROG)
+ $(CC) $(OBJECTS) $(ALL_CFLAGS) -o $(PROG)
build: $(CFILE) $(HEADER) sqlite3.c
- $(CC) $(CFILE) sqlite3.c $(CFLAGS) -o $(PROG)
+ $(CC) $(CFILE) sqlite3.c $(ALL_CFLAGS) -o $(PROG)
install: $(CFILE) $(HEADER) sqlite3.c
- $(CC) $(CFILE) sqlite3.c $(CFLAGS) -o $(PROG)
+ $(CC) $(CFILE) sqlite3.c $(ALL_CFLAGS) -o $(PROG)
install -CDTm 755 $(PROG) $(DESTDIR)/$(PROG)
- install -CDTm 644 $(PROG).1 $(MANDIR)/$(PROG).1
+ install -CDTm 644 $(PROG).1.gz $(MANDIR)/$(PROG).1
debug: $(CFILE)
$(CC) $(CFILE) sqlite3.o $(CFLAGS) -ggdb3 -Og -o $(PROG)
clean:
- rm *.gch *.o
[[ -f $(PROG) ]] && rm $(PROG)
[[ -f $(DESTDIR)/$(PROG) ]] && sudo rm $(DESTDIR)/$(PROG)
-odot
+odot v0.2.1
Task manager written in C
$ mkdir odot && cd odot
# Download source files
- $ curl "https://download.huck.website/odot-0.2.0.tar.gz" > odot-0.2.0.tar.gz
+ $ curl "https://download.huck.website/odot-[VERSION].tar.gz" > odot-[VERSION].tar.gz
# Optional: Download and check pgp signature
- $ curl "https://download.huck.website/odot-0.2.0.tar.gz.sig" > odot-0.2.0.tar.gz.sig
+ $ curl "https://download.huck.website/odot-[VERSION].tar.gz.sig" > odot-[VERSION].tar.gz.sig
$ curl "https://download.huck.website/pub.asc" > huck.asc
$ gpg --import huck.asc
- $ gpg --verify odot-0.2.0.tar.gz.sig odot-0.2.0.tar.gz
+ $ gpg --verify odot-[VERSION].tar.gz.sig odot-[VERSION].tar.gz
# Unpack source files
- $ tar -xzvf odot-0.2.0.tar.gz
+ $ tar -xzvf odot-[VERSION].tar.gz
# Build odot
Global install:
new Adds a new task to the list
done Marks a task on the list as complete
show Shows current tasks in database
+ update Change group for a task
remove Remove task from database
Available options:
- -g (group) Specify group for task
+ -g [group] Specify group for task
-a Show all groups
-d Also show completed tasks
+ -q Don't show tasks
+ -V Display version
Examples:
*group,
*newgroup;
-extern u_long hash;
+extern int hash;
extern int exists,
showall,
char *cmd = malloc(MAXLINE*sizeof(char));
if (exists == 0){
- sprintf(cmd,"%s (%lu, '%s', '%s', 0);",INSERT,hash,task,group);
+ sprintf(cmd,"%s (%i, '%s', '%s', 0);",INSERT,hash,task,group);
sqlcmd(db,cmd,'q');
} else {
printf("Task already exists\nMark as done? [y/(n)] ");
char *cmd = malloc(MAXLINE*sizeof(char));
if (exists == 1) {
- sprintf(cmd,"%s %lu;",DONE,hash);
+ sprintf(cmd,"%s %i;",DONE,hash);
sqlcmd(db,cmd,'q');
- sprintf(cmd,"%s %lu;", GETTASK,hash);
+ sprintf(cmd,"%s %i;", GETTASK,hash);
sqlcmd(db,cmd,'t');
printf("\n");
- sprintf(cmd,"SELECT Done, Task FROM Tasks WHERE Hash = %lu;",hash);
+ sprintf(cmd,"SELECT Done, Task FROM Tasks WHERE Hash = %i;",hash);
sqlcmd(db,cmd,'p');
} else {
printf("Task does not exist\nAdd task [y/n] ");
char *cmd = malloc(MAXLINE*sizeof(char));
if (exists == 1) {
- sprintf(cmd,"%s '%s' WHERE Hash = %lu;",CHANGEGROUP,newgroup,hash);
+ sprintf(cmd,"%s '%s' WHERE Hash = %i;",CHANGEGROUP,newgroup,hash);
sqlcmd(db,cmd,'q');
strcpy(group,newgroup);
} else {
char *cmd = malloc(MAXLINE*sizeof(char));
if (exists == 1){
- sprintf(cmd,"%s %lu;",DELETE,hash);
+ sprintf(cmd,"%s %i;",DELETE,hash);
sqlcmd(db,cmd,'c');
}
free(cmd);
*newgroup,
*task;
-extern u_long hash;
+extern int hash;
extern int exists;
void sqlcmd(sqlite3 *db, char *cmd, char action){
int checkcallback(void *unused,int argc, char **argv, char **name){
if (exists == 1) return 0;
- if (hash == strtoul(argv[2],NULL,10)) {
+ if (hash == (int) strtoul(argv[2],NULL,10)) {
exists = 1;
} else if (strcmp(task,argv[0]) == 0) {
checksame(task,argv[1]);
*task,
*action;
-extern u_long hash;
+extern int hash;
extern int exists;
-u_long genhash(void){
- char *tmp = calloc((strlen(task)+strlen(group)+1), sizeof(char));
- strcat(tmp,task);
- strcat(tmp,group);
- int h = 11235813;
-
- for (int i = 0; i < strlen(tmp);i++)
- h = ~((h << 5) ^ tmp[i]);
-
- return h;
+/* dgb hash */
+int genhash(char *str) {
+ u_int h=5381;
+
+ for (int i = 0; i < (int) strlen(str); i++) {
+ h = ((h << 5) + h) + *str++;
+ }
+
+ return h % TABLE_SIZE;
}
char *filepath(void){
if (getchar() == 'y'){
exists = 1;
strcpy(group,oldgroup);
- hash = genhash();
+ char *hashstring = malloc((strlen(task)+strlen(group)+1)*sizeof(char));
+ strcpy(hashstring, task);
+ strcat(hashstring,group);
+ hash = genhash(hashstring);
+ free(hashstring);
}
return;
quiet = 0,
exists = 0;
-u_long hash;
+int hash;
char *group,
*newgroup,
newgroup = calloc(MAXLINE,sizeof(char));
parseopt(argc,argv);
- hash = genhash();
+ char *hashstring = malloc((strlen(task)+strlen(group)+1)*sizeof(char));
+ strcpy(hashstring, task);
+ strcat(hashstring,group);
+ hash = genhash(hashstring);
+ free(hashstring);
/* checks if task already exists in db */
dbcheck(db);
#define VERSION "0.2.1"
#define MAXLINE 10000
+#define TABLE_SIZE 65535
/* 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 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);"
#define INSERT "INSERT INTO Tasks VALUES"
#define DELETE "DELETE FROM Tasks WHERE Hash ="
/* function.c */
char *filepath(void);
-u_long genhash(void);
+int genhash(char *);
void checksame(char *, char *);
/* functions for interfacing with sqlite database: database.c */