From: Huck Boles Date: Tue, 15 Nov 2022 06:00:13 +0000 (-0600) Subject: Tue Nov 15 12:00:13 AM CST 2022 automatic backup X-Git-Url: https://git.huck.website/?a=commitdiff_plain;h=8e6248cecd2d1600eac9855de30922459f7b98a2;p=odot.git Tue Nov 15 12:00:13 AM CST 2022 automatic backup --- diff --git a/.ccls-cache/@@home@huck@.repos@odot/@usr@include@stdio.h.blob b/.ccls-cache/@@home@huck@.repos@odot/@usr@include@stdio.h.blob index 2c54f42..a1526a4 100644 Binary files a/.ccls-cache/@@home@huck@.repos@odot/@usr@include@stdio.h.blob and b/.ccls-cache/@@home@huck@.repos@odot/@usr@include@stdio.h.blob differ diff --git a/.ccls-cache/@home@huck@.repos@odot/dialogue.c b/.ccls-cache/@home@huck@.repos@odot/dialogue.c index 9183301..bf125b9 100644 --- a/.ccls-cache/@home@huck@.repos@odot/dialogue.c +++ b/.ccls-cache/@home@huck@.repos@odot/dialogue.c @@ -21,4 +21,3 @@ void formattask(struct task t){ printf("* %s\t%s\t%i", t.task, t.group, t.date); } -gT diff --git a/.ccls-cache/@home@huck@.repos@odot/dialogue.c.blob b/.ccls-cache/@home@huck@.repos@odot/dialogue.c.blob index 53b636c..7dffb28 100644 Binary files a/.ccls-cache/@home@huck@.repos@odot/dialogue.c.blob and b/.ccls-cache/@home@huck@.repos@odot/dialogue.c.blob differ diff --git a/.ccls-cache/@home@huck@.repos@odot/file.c b/.ccls-cache/@home@huck@.repos@odot/file.c index b385503..0d9dc1f 100644 --- a/.ccls-cache/@home@huck@.repos@odot/file.c +++ b/.ccls-cache/@home@huck@.repos@odot/file.c @@ -1,84 +1,66 @@ #include "odot.h" -extern char *note; extern FILE *fp; enum color {BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE}; - -void add(struct task t, int size){ - int l,m,h,i; - FILE *fcopy = fopen("/tmp/fcopy", "w"); - char *s = malloc(MAXLINE * sizeof(char)); - h = size; - m = h / 2; - l = 0; - - while (!(h == m && m == l)){ - i = strcmp(t.task,gettask(fp).task); - - if (i < 0) { - h = m; - } else if (i > 0) { - l = m; - } else { - dialogue("Task already on list",t.task, BLUE); - return; +void add(struct task t, FILE *fp){ + char *c = malloc(strlen(t.task)*sizeof(char)); + FILE *fc = fopen("/tmp/odot", "w"); + int i = 0; + + while (fgets(c,strlen(t.task),fp) != NULL){ + switch (listcheck(t,fp)){ + case 3: + dialogue("Already on todo list", t.task, CYAN); + break; + case 1: + dialogue("Already on list in a different group", gettask(fp).group, YELLOW); + /* confirm(); */ + break; + default: + if (i == 0 && strcmp(c,t.task) > 0){ + puttask(t,fc); + ++i; + } } - - m = (h + l)/2; - fseek(fp, m, SEEK_SET); + puttask(gettask(fp), fc); } - fseek(fp, 0, SEEK_SET); - - for (i = 0; i <= (size + 1); i++){ - if (i == m){ - fprintf(fp, "%s\t%i\t%s\n",t.task,t.date,t.group); - } else { - fgets(s, MAXLINE, fp); - fputs(s, fcopy); - } - } + free(c); fclose(fp); - fclose(fcopy); + fclose(fc); remove(TODOLIST); - rename("/tmp/fcopy", TODOLIST); - free(s); - return; + rename("/tmp/odot", TODOLIST); + return; } -void rem(void){ - char *s = malloc(MAXLINE * sizeof(char)); - FILE *tmp = fopen("temp", "w"); - - fp = fopen(TODOLIST, "r"); +void rem(FILE *fp){ + char *s = malloc(MAXLINE * sizeof(char)); + FILE *fc = fopen("/tmp/odot", "w"); while (fgets(s, MAXLINE, fp) != NULL){ s[strlen(s) - 1] = 0; if (strcmp(note, s) != 0){ - fputs(strcat(s,"\n"),tmp); + fputs(strcat(s,"\n"),fc); } } fclose(fp); - fclose(tmp); + fclose(fc); remove (TODOLIST); - rename("temp", TODOLIST); + rename("/tmp/odot", TODOLIST); free(s); } -void show(void){ - char *c; - - c = (char *) malloc(MAXLINE * sizeof(int)); +void show(FILE *fp){ + char *c = malloc(sizeof(char)); - fp = fopen(TODOLIST,"r"); - while (fgets(c, MAXLINE, fp) != NULL ) + while (fgets(c, 1, fp) != NULL ) formattask(gettask(fp)); free(c); } diff --git a/.ccls-cache/@home@huck@.repos@odot/file.c.blob b/.ccls-cache/@home@huck@.repos@odot/file.c.blob index 70d8cc5..e7c1ccb 100644 Binary files a/.ccls-cache/@home@huck@.repos@odot/file.c.blob and b/.ccls-cache/@home@huck@.repos@odot/file.c.blob differ diff --git a/.ccls-cache/@home@huck@.repos@odot/func.c b/.ccls-cache/@home@huck@.repos@odot/func.c index 30d512c..1991b9e 100644 --- a/.ccls-cache/@home@huck@.repos@odot/func.c +++ b/.ccls-cache/@home@huck@.repos@odot/func.c @@ -1,26 +1,18 @@ #include "odot.h" enum color {BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE}; -extern FILE *fp; - -int listcheck(struct task t){ - char *s = malloc(strlen(t.task) * sizeof(char)); - - fp = fopen(TODOLIST, "r"); - if (fp == NULL) - error('f'); - - while (fgets(s, strlen(t.task), fp) != NULL){ - /* strip newline for comparison, return 1 if string matches */ - s[strlen(s) - 1] = 0; - if (strcmp(t.task, s) == 0){ - free(s); - return 1; - } - } - free(s); - return 0; + /* Returns: + 0 - Nothing matches + 1 - Task matches + 2 - Group matches + 3 - Both match + */ +int listcheck(struct task t, FILE *fp){ + int i; + i += (strcmp(t.task,gettask(fp).task) == 0) ? 1 : 0; + i += (strcmp(t.group,gettask(fp).group) == 0) ? 2 : 0; + return i; } diff --git a/.ccls-cache/@home@huck@.repos@odot/func.c.blob b/.ccls-cache/@home@huck@.repos@odot/func.c.blob index c72c6d0..4100071 100644 Binary files a/.ccls-cache/@home@huck@.repos@odot/func.c.blob and b/.ccls-cache/@home@huck@.repos@odot/func.c.blob differ diff --git a/.ccls-cache/@home@huck@.repos@odot/input.c b/.ccls-cache/@home@huck@.repos@odot/input.c index 0fc6eb7..0cc316a 100644 --- a/.ccls-cache/@home@huck@.repos@odot/input.c +++ b/.ccls-cache/@home@huck@.repos@odot/input.c @@ -28,18 +28,13 @@ short getopt(int n, char *arg[]){ return 1; while (--n > 0 && (*++arg)[0] == '-'){ - c = malloc(strlen(*arg) * sizeof(char)); - c = *arg; - - options += strchr(c, 'd') ? 4 : 2; - options += strchr(c, 's') ? 1 : 0; - + /* if theres a d delete, otherwise add */ + options += strchr(*arg, 'd') ? 4 : 2; + options += strchr(*arg, 's') ? 1 : 0; /* if theres a g then add the next argument as a group */ - if (strchr(c,'g') != NULL){ - group = *++arg; + if (strchr(*arg,'g') != NULL){ + strcpy(group,*++arg); } - - free(c); } return options; @@ -65,3 +60,7 @@ struct task gettask(FILE *fp){ return tmp; } + +void puttask(struct task t, FILE *fp){ + fprintf(fp,"%s\t%s\t%i\n",t.task,t.group,t.date); +} diff --git a/.ccls-cache/@home@huck@.repos@odot/input.c.blob b/.ccls-cache/@home@huck@.repos@odot/input.c.blob index 3ed7c31..3ae02cf 100644 Binary files a/.ccls-cache/@home@huck@.repos@odot/input.c.blob and b/.ccls-cache/@home@huck@.repos@odot/input.c.blob differ diff --git a/.ccls-cache/@home@huck@.repos@odot/main.c.blob b/.ccls-cache/@home@huck@.repos@odot/main.c.blob index 1cfe75f..eaa9588 100644 Binary files a/.ccls-cache/@home@huck@.repos@odot/main.c.blob and b/.ccls-cache/@home@huck@.repos@odot/main.c.blob differ diff --git a/.ccls-cache/@home@huck@.repos@odot/odot.h b/.ccls-cache/@home@huck@.repos@odot/odot.h index 61544ad..b881802 100644 --- a/.ccls-cache/@home@huck@.repos@odot/odot.h +++ b/.ccls-cache/@home@huck@.repos@odot/odot.h @@ -17,11 +17,11 @@ struct task { char *getnote(int, char *[]); short getopt(int, char *[]); -void add(struct task, int); -void rem(void); -void show(void); +void add(struct task, FILE *); +void rem(FILE *); +void show(FILE *); -int listcheck(struct task); +int listcheck(struct task, FILE *); int geturgency(int); char *gettime(void); @@ -29,10 +29,10 @@ void dialogue(char *, char *, int); void formattask(struct task t); void error(int); -int linecount(FILE); +int linecount(FILE *); struct task maketask(char *, char *); -void puttask(struct task n); +void puttask(struct task n, FILE*); struct task gettask(FILE *); char *note, *o; diff --git a/.ccls-cache/@home@huck@.repos@odot/odot.h.blob b/.ccls-cache/@home@huck@.repos@odot/odot.h.blob index 4e83d72..54cbfa5 100644 Binary files a/.ccls-cache/@home@huck@.repos@odot/odot.h.blob and b/.ccls-cache/@home@huck@.repos@odot/odot.h.blob differ diff --git a/Makefile b/Makefile index 7e48f1c..722a5a5 100644 --- a/Makefile +++ b/Makefile @@ -3,8 +3,9 @@ PROG = todo PREFIX ?= /usr/local/bin TODOLIST = $(HOME)/.local/share/odot/todo -install : main.c input.c file.c +install : main.c input.c file.c dialogue.c func.c gcc *.c -o '$(PREFIX)/$(PROG)' + [[ ! -d $(TODOLIST) ]] && mkdir -p $(TODOLIST) header : todo.h gcc *.h @@ -13,9 +14,3 @@ clean : rm *.gch rm "$(PREFIX)/$(PROG)" -test : - todo - todo -n something - todo -d stuff to do now - todo -ns stuff to do - todo -ds stuff to do diff --git a/file.c b/file.c index b385503..0d9dc1f 100644 --- a/file.c +++ b/file.c @@ -1,84 +1,66 @@ #include "odot.h" -extern char *note; extern FILE *fp; enum color {BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE}; - -void add(struct task t, int size){ - int l,m,h,i; - FILE *fcopy = fopen("/tmp/fcopy", "w"); - char *s = malloc(MAXLINE * sizeof(char)); - h = size; - m = h / 2; - l = 0; - - while (!(h == m && m == l)){ - i = strcmp(t.task,gettask(fp).task); - - if (i < 0) { - h = m; - } else if (i > 0) { - l = m; - } else { - dialogue("Task already on list",t.task, BLUE); - return; +void add(struct task t, FILE *fp){ + char *c = malloc(strlen(t.task)*sizeof(char)); + FILE *fc = fopen("/tmp/odot", "w"); + int i = 0; + + while (fgets(c,strlen(t.task),fp) != NULL){ + switch (listcheck(t,fp)){ + case 3: + dialogue("Already on todo list", t.task, CYAN); + break; + case 1: + dialogue("Already on list in a different group", gettask(fp).group, YELLOW); + /* confirm(); */ + break; + default: + if (i == 0 && strcmp(c,t.task) > 0){ + puttask(t,fc); + ++i; + } } - - m = (h + l)/2; - fseek(fp, m, SEEK_SET); + puttask(gettask(fp), fc); } - fseek(fp, 0, SEEK_SET); - - for (i = 0; i <= (size + 1); i++){ - if (i == m){ - fprintf(fp, "%s\t%i\t%s\n",t.task,t.date,t.group); - } else { - fgets(s, MAXLINE, fp); - fputs(s, fcopy); - } - } + free(c); fclose(fp); - fclose(fcopy); + fclose(fc); remove(TODOLIST); - rename("/tmp/fcopy", TODOLIST); - free(s); - return; + rename("/tmp/odot", TODOLIST); + return; } -void rem(void){ - char *s = malloc(MAXLINE * sizeof(char)); - FILE *tmp = fopen("temp", "w"); - - fp = fopen(TODOLIST, "r"); +void rem(FILE *fp){ + char *s = malloc(MAXLINE * sizeof(char)); + FILE *fc = fopen("/tmp/odot", "w"); while (fgets(s, MAXLINE, fp) != NULL){ s[strlen(s) - 1] = 0; if (strcmp(note, s) != 0){ - fputs(strcat(s,"\n"),tmp); + fputs(strcat(s,"\n"),fc); } } fclose(fp); - fclose(tmp); + fclose(fc); remove (TODOLIST); - rename("temp", TODOLIST); + rename("/tmp/odot", TODOLIST); free(s); } -void show(void){ - char *c; - - c = (char *) malloc(MAXLINE * sizeof(int)); +void show(FILE *fp){ + char *c = malloc(sizeof(char)); - fp = fopen(TODOLIST,"r"); - while (fgets(c, MAXLINE, fp) != NULL ) + while (fgets(c, 1, fp) != NULL ) formattask(gettask(fp)); free(c); } diff --git a/func.c b/func.c index 30d512c..1991b9e 100644 --- a/func.c +++ b/func.c @@ -1,26 +1,18 @@ #include "odot.h" enum color {BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE}; -extern FILE *fp; - -int listcheck(struct task t){ - char *s = malloc(strlen(t.task) * sizeof(char)); - - fp = fopen(TODOLIST, "r"); - if (fp == NULL) - error('f'); - - while (fgets(s, strlen(t.task), fp) != NULL){ - /* strip newline for comparison, return 1 if string matches */ - s[strlen(s) - 1] = 0; - if (strcmp(t.task, s) == 0){ - free(s); - return 1; - } - } - free(s); - return 0; + /* Returns: + 0 - Nothing matches + 1 - Task matches + 2 - Group matches + 3 - Both match + */ +int listcheck(struct task t, FILE *fp){ + int i; + i += (strcmp(t.task,gettask(fp).task) == 0) ? 1 : 0; + i += (strcmp(t.group,gettask(fp).group) == 0) ? 2 : 0; + return i; } diff --git a/input.c b/input.c index 0fc6eb7..0cc316a 100644 --- a/input.c +++ b/input.c @@ -28,18 +28,13 @@ short getopt(int n, char *arg[]){ return 1; while (--n > 0 && (*++arg)[0] == '-'){ - c = malloc(strlen(*arg) * sizeof(char)); - c = *arg; - - options += strchr(c, 'd') ? 4 : 2; - options += strchr(c, 's') ? 1 : 0; - + /* if theres a d delete, otherwise add */ + options += strchr(*arg, 'd') ? 4 : 2; + options += strchr(*arg, 's') ? 1 : 0; /* if theres a g then add the next argument as a group */ - if (strchr(c,'g') != NULL){ - group = *++arg; + if (strchr(*arg,'g') != NULL){ + strcpy(group,*++arg); } - - free(c); } return options; @@ -65,3 +60,7 @@ struct task gettask(FILE *fp){ return tmp; } + +void puttask(struct task t, FILE *fp){ + fprintf(fp,"%s\t%s\t%i\n",t.task,t.group,t.date); +} diff --git a/odot.h b/odot.h index 61544ad..b881802 100644 --- a/odot.h +++ b/odot.h @@ -17,11 +17,11 @@ struct task { char *getnote(int, char *[]); short getopt(int, char *[]); -void add(struct task, int); -void rem(void); -void show(void); +void add(struct task, FILE *); +void rem(FILE *); +void show(FILE *); -int listcheck(struct task); +int listcheck(struct task, FILE *); int geturgency(int); char *gettime(void); @@ -29,10 +29,10 @@ void dialogue(char *, char *, int); void formattask(struct task t); void error(int); -int linecount(FILE); +int linecount(FILE *); struct task maketask(char *, char *); -void puttask(struct task n); +void puttask(struct task n, FILE*); struct task gettask(FILE *); char *note, *o;