]> git.huck.website - odot.git/commitdiff
version 0.2.1
authorHuck Boles <huck@huck.website>
Tue, 3 Jan 2023 23:04:42 +0000 (17:04 -0600)
committerHuck Boles <huck@huck.website>
Tue, 3 Jan 2023 23:04:42 +0000 (17:04 -0600)
Makefile
README
actions.c
database.c
function.c
odot.c
odot.h

index f50d060d29d5482491bdf5c8ae9cd5ab11dfd784..07cc47476aebc53fdd109703e51f326a0073387b 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,7 +1,7 @@
 SHELL = /bin/bash
 PREFIX = /usr
 DESTDIR = $(PREFIX)/bin
-MANDIR = $(PREFIX)/share/man
+MANDIR = $(PREFIX)/share/man/man1
 
 PROG = odot
 
@@ -11,36 +11,35 @@ HEADER = $(PROG).h sqlite3.h
 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)
 
diff --git a/README b/README
index 6534ff784519cbd93bf4139e1b05f5c1998fb177..df8098ac08590d3790b76afc0f86e4d8486593c1 100644 (file)
--- a/README
+++ b/README
@@ -1,4 +1,4 @@
-odot
+odot v0.2.1
 
 Task manager written in C
 
@@ -12,16 +12,16 @@ Installation:
         $ 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:
@@ -40,12 +40,15 @@ Usage:
         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:
 
index 2ee8431c80e5660c27b18319cf9fbc5ba1a0089e..2fc62548da99dd6c9849f9d1f06d0b834e0a6796 100644 (file)
--- a/actions.c
+++ b/actions.c
@@ -4,7 +4,7 @@ extern char *task,
             *group,
             *newgroup;
 
-extern u_long hash;
+extern int hash;
 
 extern int  exists,
             showall,
@@ -14,7 +14,7 @@ void newtask(sqlite3 *db){
     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)] ");
@@ -28,14 +28,14 @@ void done(sqlite3 *db){
     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] ");
@@ -52,7 +52,7 @@ void update(sqlite3 *db){
     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 {
@@ -67,7 +67,7 @@ void removetask(sqlite3 *db){
     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);
index a2f737f480e1cc4c9d7c92a9d179d6f2f1f23d58..31d4d96d813947c76e79d6686f4237fa15ef728a 100644 (file)
@@ -4,7 +4,7 @@ extern char *group,
             *newgroup,
             *task;
 
-extern u_long hash;
+extern int hash;
 extern int exists;
 
 void sqlcmd(sqlite3 *db, char *cmd, char action){
@@ -61,7 +61,7 @@ int taskcallback(void *unused,int argc, char **argv, char **name){
 
 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]);
index e2635bdad53a94855ac4732f018ce7a62b6b66a4..0421ebbb4c7a1bab4a9bd15713fcb6d16e742622 100644 (file)
@@ -5,20 +5,19 @@ extern char *group,
             *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){
@@ -54,7 +53,11 @@ void checksame(char *task,char *oldgroup){
     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;
diff --git a/odot.c b/odot.c
index 406121b28b49d3647997c8666fd3c36e6d905346..f95fedb1cad6c17ee8c5980acca035fdd8c51522 100644 (file)
--- a/odot.c
+++ b/odot.c
@@ -6,7 +6,7 @@ int showdone = 0,
     quiet    = 0,
     exists   = 0;
 
-u_long hash;
+int hash;
 
 char    *group,
         *newgroup,
@@ -36,7 +36,11 @@ int main(int argc, char *argv[]){
     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);
diff --git a/odot.h b/odot.h
index 397b0d0f8eb9cb551976c71764268881f47a0ba3..99d46ab5557fb16c78d5c3b0915f67e1f2dbbf71 100644 (file)
--- a/odot.h
+++ b/odot.h
 
 #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 ="
@@ -43,7 +44,7 @@ void show(sqlite3 *);
 
 /* function.c */
 char *filepath(void);
-u_long genhash(void);
+int genhash(char *);
 void checksame(char *, char *);
 
 /* functions for interfacing with sqlite database: database.c */