]> git.huck.website - odot.git/commitdiff
Thu Nov 17 12:00:10 AM CST 2022 automatic backup
authorHuck Boles <huboles@protonmail.com>
Thu, 17 Nov 2022 06:00:10 +0000 (00:00 -0600)
committerHuck Boles <huboles@protonmail.com>
Thu, 17 Nov 2022 06:00:10 +0000 (00:00 -0600)
19 files changed:
.ccls-cache/@@home@huck@.repos@odot/@usr@include@bits@types.h.blob
.ccls-cache/@@home@huck@.repos@odot/@usr@include@bits@wordsize.h.blob
.ccls-cache/@@home@huck@.repos@odot/@usr@include@features-time64.h.blob
.ccls-cache/@@home@huck@.repos@odot/@usr@include@gnu@stubs.h.blob
.ccls-cache/@@home@huck@.repos@odot/@usr@include@stdc-predef.h.blob
.ccls-cache/@@home@huck@.repos@odot/@usr@include@stdio.h.blob
.ccls-cache/@home@huck@.repos@odot/file.c
.ccls-cache/@home@huck@.repos@odot/file.c.blob
.ccls-cache/@home@huck@.repos@odot/input.c
.ccls-cache/@home@huck@.repos@odot/input.c.blob
.ccls-cache/@home@huck@.repos@odot/main.c
.ccls-cache/@home@huck@.repos@odot/main.c.blob
.ccls-cache/@home@huck@.repos@odot/odot.h
.ccls-cache/@home@huck@.repos@odot/odot.h.blob
file.c
input.c
main.c
odot
odot.h

index 2a97e0c6792c103efdf1f87b945606b64d653ae7..80141a71c38a5ac527e7ba2689579a018c30bf41 100644 (file)
Binary files a/.ccls-cache/@@home@huck@.repos@odot/@usr@include@bits@types.h.blob and b/.ccls-cache/@@home@huck@.repos@odot/@usr@include@bits@types.h.blob differ
index bcbe4f3367d2fda0145507cf6a1fd70a8a8bbc5c..fc978a6ffba553e6d8cd73dccb85aec159536310 100644 (file)
Binary files a/.ccls-cache/@@home@huck@.repos@odot/@usr@include@bits@wordsize.h.blob and b/.ccls-cache/@@home@huck@.repos@odot/@usr@include@bits@wordsize.h.blob differ
index a2c8cf881cc6f6466ed35de0cf5b2dfdc2c6414f..5a61925eef691a41d868392af862afe47faf49e0 100644 (file)
Binary files a/.ccls-cache/@@home@huck@.repos@odot/@usr@include@features-time64.h.blob and b/.ccls-cache/@@home@huck@.repos@odot/@usr@include@features-time64.h.blob differ
index 4d6b49e87d49560491e687f7cbaa7f8e8f93f3db..1cd7b8dc2d8a11f0e1bafa2e7c13a44e358c5694 100644 (file)
Binary files a/.ccls-cache/@@home@huck@.repos@odot/@usr@include@gnu@stubs.h.blob and b/.ccls-cache/@@home@huck@.repos@odot/@usr@include@gnu@stubs.h.blob differ
index b299ad6e50dc1d73c1c58b74cc2802a9f93ef4e6..bddb0b58385fc8eba96598c0c09953af190a984a 100644 (file)
Binary files a/.ccls-cache/@@home@huck@.repos@odot/@usr@include@stdc-predef.h.blob and b/.ccls-cache/@@home@huck@.repos@odot/@usr@include@stdc-predef.h.blob differ
index d8ef87d5de8516970f34ab151b000c0a51f9af2f..88a88c1a441eccff981a03b978237cd27d8cde8e 100644 (file)
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
index 2d5b277aa4c81b4aaeff9e408788b5e8206a3033..4fbcfb9b7850a1f884e9c2561761b6b69a890952 100644 (file)
@@ -1,63 +1,71 @@
 #include "odot.h"
 
 void add(struct task t, FILE *fp){
-                    printf("\nalloc\n");
-    char *c = malloc(strlen(t.task)*sizeof(char));
-                    printf("\nfopen\n");
-    FILE *buf = fopen("odot.tmp", "w");
+                    printf("\talloc\n");
+    char *line = malloc(MAXLINE*sizeof(char));
+                    printf("\tfopen\n");
+    FILE *buf = fopen("/home/huck/.local/state/odot/odot.txt", "w+");
     int i = 0;
     
-                    printf("\nloopstart\n");
-                    int j = 0;
-    while (fgets(c,strlen(t.task),fp) != NULL){
-                    printf("\n%i-nloop\n", j++);
-        switch (listcheck(t,fp)){
-            case 3:
-                dialogue("Already on todo list", t.task, CYAN);
-                printf("Remove from list?");
-                if (check() == 0){
+                    printf("\tNULLcheck\n");
+    if (fgets(line,MAXLINE,fp) == NULL){
+        puttask(t,buf);
+    } else {
+                        printf("\tloopstart\n");
+                        int j = 0;
+        while (fgets(line,MAXLINE,fp) != NULL){
+                        printf("\t%i-nloop\n", ++j);
+            switch (listcheck(t,line)){
+                case 3:
+                    dialogue("Already on todo list", t.task, CYAN);
+                    printf("Remove from list?");
+                    if (check() == 0){
+                        break;
+                    } else {
+                        puttask(gettask(line), buf);
+                        break;
+                    }
+                case 1:
+                    dialogue("Already on list in a different group", gettask(line).group, YELLOW);
+                    if (check() == 0){
+                        puttask(t,buf);
+                        i++;
+                    }
+                    puttask(gettask(line), buf);
                     break;
-                } else {
-                    puttask(gettask(fp), buf);
+                default:
+                    /* first time t.task is lexigraphically greater than a previous task */
+                    if (i == 0 && strcmp(line,t.task) > 0){
+                        puttask(t,buf);
+                        ++i;
+                    }
+                    puttask(gettask(line), buf);
                     break;
-                }
-            case 1:
-                dialogue("Already on list in a different group", gettask(fp).group, YELLOW);
-                if (check() == 0){
-                    puttask(t,buf);
-                    i++;
-                }
-                puttask(gettask(fp), buf);
-                break;
-            default:
-                /* first time t.task is lexigraphically greater than a previous task */
-                if (i == 0 && strcmp(c,t.task) > 0){
-                    puttask(t,buf);
-                    ++i;
-                }
-                puttask(gettask(fp), buf);
-                break;
+            }
         }
     }
 
-    free(c);
     fclose(fp);
     fclose(buf);
-    remove("/home/huck/.local/state/odot/todo");
-    rename("odot.tmp", "/home/huck/.local/state/odot/todo");
+    remove("/home/huck/.local/state/odot/todo.txt");
+    rename("/home/huck/.local/state/odot/odot.txt", "/home/huck/.local/state/odot/todo.txt");
+    free(line); 
+    fp = fopen("/home/huck/.local/state/odot/todo.txt", "w+");
+    if (!fp)
+        error(1);
     return; 
 }
 
 
 void rem(struct task t, FILE *fp){
     char *s = malloc(MAXLINE * sizeof(char));
-    FILE *buf = fopen("odot.tmp", "w");
+    FILE *buf = fopen("/home/huck/.local/state/odot/odot.txt", "w+");
     int i = 0;
 
     while (fgets(s, MAXLINE, fp) != NULL){
         s[strlen(s) - 1] = 0;
         if (strcmp(t.task, s) != 0){
-            fputs(strcat(s,"\n"),buf);
+            fputs(strcat(s,"\t"),buf);
         } else {
             i++;
         }
@@ -66,8 +74,10 @@ void rem(struct task t, FILE *fp){
     fclose(fp);
     fclose(buf);
 
-    remove ("/home/huck/.local/state/odot/todo");
-    rename("odot.tmp", "/home/huck/.local/state/odot/todo");
+    remove ("/home/huck/.local/state/odot/todo.txt");
+    rename("/home/huck/.local/state/odot/odot.txt", "/home/huck/.local/state/odot/todo.txt");
+
+    fp = fopen("/home/huck/.local/state/odot/todo.txt", "w+");
 
     if (i == 0){
         dialogue("Task not found", t.task, YELLOW);
@@ -76,18 +86,24 @@ void rem(struct task t, FILE *fp){
             add(t,fp);
         }
     }
-
     free(s);
+
 }
 
 void show(char *group, FILE *fp){
-    char *c = malloc(sizeof(char));
+    char *task = malloc(MAXLINE * sizeof(char));
+    struct task tmp;
+
+                printf("\twhileloop\n");
+                int j = 0;
 
-    while (fgets(c, 1, fp) != NULL ){
-        if (strcmp(group, "all") == 0 || strcmp(gettask(fp).group, group) == 0){
-            formattask(gettask(fp));
+    while ((fgets(task, MAXLINE, fp)) != NULL ){
+                printf("\t%i-nloop\n", ++j);
+            tmp = gettask(task);
+        if (strcmp(group, "all") == 0 || strcmp(tmp.group, group) == 0){
+            formattask(tmp);
         }
     }
-    free(c);
+    free(task);
 }
 
index 6379548e81af1a96113d3e1c900b96ed4a7a847c..3d1f47fff9c181a3fe5cacd6a080fcba6cf684e1 100644 (file)
Binary files a/.ccls-cache/@home@huck@.repos@odot/file.c.blob and b/.ccls-cache/@home@huck@.repos@odot/file.c.blob differ
index 0cb2c50fdce8fe65bee1228eddc35bfa4ecd470a..4d39442b6fe2e0a2ae11776d4bb679ceb228e89d 100644 (file)
@@ -1,26 +1,28 @@
 #include "odot.h"
 
 struct task getnote(int n, char *arg[], char *group){
-    char *s = malloc(MAXLINE * sizeof(char));
+    char *note = malloc(MAXLINE * sizeof(char));
     struct task tmp;
     
-    if (n == 1)
-            printf("\nreturn from note\n");
+    if (n == 1){
+            printf("\t\treturn from note\n");
         return tmp;
+    }
 
 
-    while(n-- > 0){ 
-            printf("\n%i-nloop\n",n);
-        if (*arg[0] != '-'){
-            strcat(s, *arg);
-            strcat(s, (n > 1) ? " " : "");
+    while(--n > 0){ 
+            printf("\t%i-nloop\n",n);
+        if ((*++arg)[0] != '-'){
+            strcat(note, *arg);
+            strcat(note, " ");
         } else if (strcmp(*arg,"-g") == 0){
-            strcpy(group, *arg);
+            strcpy(group, (*++arg));
+            n--;
         }
     }
-    strcpy(tmp.task, s);
-    strcpy(tmp.group, group);
-    free(s);
+                printf("\t%s %s getnote\n",note,group);
+    tmp = maketask(note,group);
+    free(note);
     return tmp;
 }
 
@@ -32,19 +34,19 @@ struct task getnote(int n, char *arg[], char *group){
 short getopt(int n, char *arg[]){
     short options;
     
-                printf("\nreturn1\n");
+                printf("\treturn1\n");
     /* show list if no arguments given */
     if (n == 1)
         return 1;
     
-                printf("\ncheckopt\n");
+                printf("\tcheckopt\n");
     while (--n > 0 && (*++arg)[0] == '-'){
         /* if theres a d delete, otherwise add */
         options += strchr(*arg, 's') ? 1 : 0;
         options += strchr(*arg, 'n') ? 2 : 0;
         options += strchr(*arg, 'd') ? 4 : 0;
     }
-                printf("%i", options);
+                printf("\t%i-optcode\n", options);
     if ((options - 5) > 0)
         error(2);
     return options;
@@ -52,25 +54,31 @@ short getopt(int n, char *arg[]){
 
 
 struct task maketask(char *task, char *group){
+            printf("\tmaketask\n");
     struct task tmp;
+    
+    tmp.task = malloc(strlen(task) * sizeof(char));
+    tmp.group = malloc(strlen(group) * sizeof(char));
+
+    strcpy(tmp.task,task);
+    strcpy(tmp.group,(strcmp(tmp.group,"") == 0) ? "all" : group);
 
-    tmp.task = task;
-    tmp.date = 0;
-    /* add to all group if group isn't specified */
-    tmp.group = (strcmp(group,"") == 0) ? "all" : group;
+            printf("\t%s-task %s-group\n",tmp.task,tmp.group);
 
     return tmp;
 }
 
 
-struct task gettask(FILE *fp){
+struct task gettask(char *c){
+            printf("\tgettask\n");
     struct task tmp;
      
-    fscanf(fp,"%s\t%s\t%i\n",tmp.task,tmp.group,&tmp.date);
+    sscanf(c,"%s\t%s",tmp.task,tmp.group);
 
     return tmp;
 }
 
 void puttask(struct task t, FILE *fp){
-    fprintf(fp,"%s\t%s\t%i\n",t.task,t.group,t.date);
+            printf("\t%s %s puttask\n", t.task, t.group);
+    fprintf(fp,"%s\t%s\n",t.task,t.group);
 }
index 19f6e3c21f194716c55d991d8723341c97f3f018..a84d4ccf764a90d6d7d623fa6987359de9133c29 100644 (file)
Binary files a/.ccls-cache/@home@huck@.repos@odot/input.c.blob and b/.ccls-cache/@home@huck@.repos@odot/input.c.blob differ
index 9b86cd1c8add3ed3142b12fb6bbaa49ca25a34dc..e498acf1b90a5d214b616d41b88aba4ffdedc692 100644 (file)
@@ -1,46 +1,46 @@
 #include "odot.h"
 
 int main(int argc, char *argv[]){
-                printf("\nstart\n");
+                printf("\tstart\n");
     struct task note;
     short opt;
     FILE *fp;
     char *group = malloc(MAXLINE*sizeof(char));
 
-                printf("\nfopen\n");
-    fp = fopen("/home/huck/.local/state/odot/todo", "w+");
+                printf("\tfopen\n");
+    fp = fopen("/home/huck/.local/state/odot/todo.txt", "w+");
     if (!fp){
         error(1);
     }
 
-                printf("\ngetopt\n");
+                printf("\tgetopt\n");
     opt = getopt(argc, argv);
 
-                printf("\ngetnote\n");
+                printf("\tgetnote\n");
     note = getnote(argc, argv, group);
 
     if (opt >= 4){
-                printf("\nrem\n");
+                printf("\trem\n");
         rem(note, fp);
-    } else {
-                printf("\nadd\n");
+    } else if (opt >= 2){
+                printf("\tadd\n");
         add(note, fp);
     }
 
     if (opt % 2 != 0){
-                printf("\nshow\n");
+                printf("\tshow\n");
         show(group, fp); 
     }
-
-    free(group);
+                printf("\texiting\n");
     fclose(fp);
+    free(group);
     return 0;
 }
 
 void error(int err){
     switch (err) {
         case 1:
-            fprintf(stderr,"ERROR: COULD NOT ACCESS FILE: %s\n", "/home/huck/.local/state/odot/todo");
+            fprintf(stderr,"ERROR: COULD NOT ACCESS FILE: %s\n", "/home/huck/.local/state/odot/todo.txt");
             break;
         case 2:
             fprintf(stderr,"ERROR: CANT ADD AND REMOVE SAME TASK\n");
@@ -55,7 +55,7 @@ void dialogue(char *m1, char *m2, int c){
 }
 
 void formattask(struct task t){
-    printf("* %s\t%s\t%i", t.task, t.group, t.date);
+    printf("* %s\t%s\n", t.task, t.group);
 }
 
     /* Returns:
@@ -64,17 +64,13 @@ void formattask(struct task t){
         2 - Group matches
         3 - Both match
     */
-int listcheck(struct task t, FILE *fp){
+int listcheck(struct task t, char *c){
     int i;
-    i += (strcmp(t.task,gettask(fp).task) == 0) ? 1 : 0;
-    i += (strcmp(t.group,gettask(fp).group) == 0) ? 2 : 0;
+    i += (strcmp(t.task,gettask(c).task) == 0) ? 1 : 0;
+    i += (strcmp(t.group,gettask(c).group) == 0) ? 2 : 0;
     return i;
 }
 
-char *gettime(void){
-    return NULL;
-}
-
 /* returns 0 for yes and 1 for no */
 int check(void){
     printf("Continue? [y/n] (y):");
index e10b157d58ad8b30026c94752ab9f0ab52e18939..ecc8316389674dc4b3eb6eb404078fbfff8e5d16 100644 (file)
Binary files a/.ccls-cache/@home@huck@.repos@odot/main.c.blob and b/.ccls-cache/@home@huck@.repos@odot/main.c.blob differ
index 78c35483c1f0e31e17590d60e9f3be440b89271b..1cd5ff272fd5d2524e0fd6be8717a24550e7d197 100644 (file)
@@ -10,7 +10,6 @@
 
 struct task {
     char *task;
-    int date;
     char *group;
 };
 
@@ -21,7 +20,7 @@ void add(struct task, FILE *);
 void rem(struct task, FILE *);
 void show(char *group, FILE *);
 
-int listcheck(struct task, FILE *);
+int listcheck(struct task, char *);
 int geturgency(int);
 char *gettime(void);
 
@@ -32,6 +31,6 @@ int check(void);
 
 struct task maketask(char *, char *);
 void puttask(struct task n, FILE*);
-struct task gettask(FILE *);
+struct task gettask(char *);
 
 enum color {BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE};
index ee6868639ad80439d6bc0711f4fa7c5697a9d206..bbbd5b8036bf2bfa2dbc0a8f52fe01e66ab5c715 100644 (file)
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/file.c b/file.c
index 2d5b277aa4c81b4aaeff9e408788b5e8206a3033..4fbcfb9b7850a1f884e9c2561761b6b69a890952 100644 (file)
--- a/file.c
+++ b/file.c
@@ -1,63 +1,71 @@
 #include "odot.h"
 
 void add(struct task t, FILE *fp){
-                    printf("\nalloc\n");
-    char *c = malloc(strlen(t.task)*sizeof(char));
-                    printf("\nfopen\n");
-    FILE *buf = fopen("odot.tmp", "w");
+                    printf("\talloc\n");
+    char *line = malloc(MAXLINE*sizeof(char));
+                    printf("\tfopen\n");
+    FILE *buf = fopen("/home/huck/.local/state/odot/odot.txt", "w+");
     int i = 0;
     
-                    printf("\nloopstart\n");
-                    int j = 0;
-    while (fgets(c,strlen(t.task),fp) != NULL){
-                    printf("\n%i-nloop\n", j++);
-        switch (listcheck(t,fp)){
-            case 3:
-                dialogue("Already on todo list", t.task, CYAN);
-                printf("Remove from list?");
-                if (check() == 0){
+                    printf("\tNULLcheck\n");
+    if (fgets(line,MAXLINE,fp) == NULL){
+        puttask(t,buf);
+    } else {
+                        printf("\tloopstart\n");
+                        int j = 0;
+        while (fgets(line,MAXLINE,fp) != NULL){
+                        printf("\t%i-nloop\n", ++j);
+            switch (listcheck(t,line)){
+                case 3:
+                    dialogue("Already on todo list", t.task, CYAN);
+                    printf("Remove from list?");
+                    if (check() == 0){
+                        break;
+                    } else {
+                        puttask(gettask(line), buf);
+                        break;
+                    }
+                case 1:
+                    dialogue("Already on list in a different group", gettask(line).group, YELLOW);
+                    if (check() == 0){
+                        puttask(t,buf);
+                        i++;
+                    }
+                    puttask(gettask(line), buf);
                     break;
-                } else {
-                    puttask(gettask(fp), buf);
+                default:
+                    /* first time t.task is lexigraphically greater than a previous task */
+                    if (i == 0 && strcmp(line,t.task) > 0){
+                        puttask(t,buf);
+                        ++i;
+                    }
+                    puttask(gettask(line), buf);
                     break;
-                }
-            case 1:
-                dialogue("Already on list in a different group", gettask(fp).group, YELLOW);
-                if (check() == 0){
-                    puttask(t,buf);
-                    i++;
-                }
-                puttask(gettask(fp), buf);
-                break;
-            default:
-                /* first time t.task is lexigraphically greater than a previous task */
-                if (i == 0 && strcmp(c,t.task) > 0){
-                    puttask(t,buf);
-                    ++i;
-                }
-                puttask(gettask(fp), buf);
-                break;
+            }
         }
     }
 
-    free(c);
     fclose(fp);
     fclose(buf);
-    remove("/home/huck/.local/state/odot/todo");
-    rename("odot.tmp", "/home/huck/.local/state/odot/todo");
+    remove("/home/huck/.local/state/odot/todo.txt");
+    rename("/home/huck/.local/state/odot/odot.txt", "/home/huck/.local/state/odot/todo.txt");
+    free(line); 
+    fp = fopen("/home/huck/.local/state/odot/todo.txt", "w+");
+    if (!fp)
+        error(1);
     return; 
 }
 
 
 void rem(struct task t, FILE *fp){
     char *s = malloc(MAXLINE * sizeof(char));
-    FILE *buf = fopen("odot.tmp", "w");
+    FILE *buf = fopen("/home/huck/.local/state/odot/odot.txt", "w+");
     int i = 0;
 
     while (fgets(s, MAXLINE, fp) != NULL){
         s[strlen(s) - 1] = 0;
         if (strcmp(t.task, s) != 0){
-            fputs(strcat(s,"\n"),buf);
+            fputs(strcat(s,"\t"),buf);
         } else {
             i++;
         }
@@ -66,8 +74,10 @@ void rem(struct task t, FILE *fp){
     fclose(fp);
     fclose(buf);
 
-    remove ("/home/huck/.local/state/odot/todo");
-    rename("odot.tmp", "/home/huck/.local/state/odot/todo");
+    remove ("/home/huck/.local/state/odot/todo.txt");
+    rename("/home/huck/.local/state/odot/odot.txt", "/home/huck/.local/state/odot/todo.txt");
+
+    fp = fopen("/home/huck/.local/state/odot/todo.txt", "w+");
 
     if (i == 0){
         dialogue("Task not found", t.task, YELLOW);
@@ -76,18 +86,24 @@ void rem(struct task t, FILE *fp){
             add(t,fp);
         }
     }
-
     free(s);
+
 }
 
 void show(char *group, FILE *fp){
-    char *c = malloc(sizeof(char));
+    char *task = malloc(MAXLINE * sizeof(char));
+    struct task tmp;
+
+                printf("\twhileloop\n");
+                int j = 0;
 
-    while (fgets(c, 1, fp) != NULL ){
-        if (strcmp(group, "all") == 0 || strcmp(gettask(fp).group, group) == 0){
-            formattask(gettask(fp));
+    while ((fgets(task, MAXLINE, fp)) != NULL ){
+                printf("\t%i-nloop\n", ++j);
+            tmp = gettask(task);
+        if (strcmp(group, "all") == 0 || strcmp(tmp.group, group) == 0){
+            formattask(tmp);
         }
     }
-    free(c);
+    free(task);
 }
 
diff --git a/input.c b/input.c
index 0cb2c50fdce8fe65bee1228eddc35bfa4ecd470a..4d39442b6fe2e0a2ae11776d4bb679ceb228e89d 100644 (file)
--- a/input.c
+++ b/input.c
@@ -1,26 +1,28 @@
 #include "odot.h"
 
 struct task getnote(int n, char *arg[], char *group){
-    char *s = malloc(MAXLINE * sizeof(char));
+    char *note = malloc(MAXLINE * sizeof(char));
     struct task tmp;
     
-    if (n == 1)
-            printf("\nreturn from note\n");
+    if (n == 1){
+            printf("\t\treturn from note\n");
         return tmp;
+    }
 
 
-    while(n-- > 0){ 
-            printf("\n%i-nloop\n",n);
-        if (*arg[0] != '-'){
-            strcat(s, *arg);
-            strcat(s, (n > 1) ? " " : "");
+    while(--n > 0){ 
+            printf("\t%i-nloop\n",n);
+        if ((*++arg)[0] != '-'){
+            strcat(note, *arg);
+            strcat(note, " ");
         } else if (strcmp(*arg,"-g") == 0){
-            strcpy(group, *arg);
+            strcpy(group, (*++arg));
+            n--;
         }
     }
-    strcpy(tmp.task, s);
-    strcpy(tmp.group, group);
-    free(s);
+                printf("\t%s %s getnote\n",note,group);
+    tmp = maketask(note,group);
+    free(note);
     return tmp;
 }
 
@@ -32,19 +34,19 @@ struct task getnote(int n, char *arg[], char *group){
 short getopt(int n, char *arg[]){
     short options;
     
-                printf("\nreturn1\n");
+                printf("\treturn1\n");
     /* show list if no arguments given */
     if (n == 1)
         return 1;
     
-                printf("\ncheckopt\n");
+                printf("\tcheckopt\n");
     while (--n > 0 && (*++arg)[0] == '-'){
         /* if theres a d delete, otherwise add */
         options += strchr(*arg, 's') ? 1 : 0;
         options += strchr(*arg, 'n') ? 2 : 0;
         options += strchr(*arg, 'd') ? 4 : 0;
     }
-                printf("%i", options);
+                printf("\t%i-optcode\n", options);
     if ((options - 5) > 0)
         error(2);
     return options;
@@ -52,25 +54,31 @@ short getopt(int n, char *arg[]){
 
 
 struct task maketask(char *task, char *group){
+            printf("\tmaketask\n");
     struct task tmp;
+    
+    tmp.task = malloc(strlen(task) * sizeof(char));
+    tmp.group = malloc(strlen(group) * sizeof(char));
+
+    strcpy(tmp.task,task);
+    strcpy(tmp.group,(strcmp(tmp.group,"") == 0) ? "all" : group);
 
-    tmp.task = task;
-    tmp.date = 0;
-    /* add to all group if group isn't specified */
-    tmp.group = (strcmp(group,"") == 0) ? "all" : group;
+            printf("\t%s-task %s-group\n",tmp.task,tmp.group);
 
     return tmp;
 }
 
 
-struct task gettask(FILE *fp){
+struct task gettask(char *c){
+            printf("\tgettask\n");
     struct task tmp;
      
-    fscanf(fp,"%s\t%s\t%i\n",tmp.task,tmp.group,&tmp.date);
+    sscanf(c,"%s\t%s",tmp.task,tmp.group);
 
     return tmp;
 }
 
 void puttask(struct task t, FILE *fp){
-    fprintf(fp,"%s\t%s\t%i\n",t.task,t.group,t.date);
+            printf("\t%s %s puttask\n", t.task, t.group);
+    fprintf(fp,"%s\t%s\n",t.task,t.group);
 }
diff --git a/main.c b/main.c
index 9b86cd1c8add3ed3142b12fb6bbaa49ca25a34dc..e498acf1b90a5d214b616d41b88aba4ffdedc692 100644 (file)
--- a/main.c
+++ b/main.c
@@ -1,46 +1,46 @@
 #include "odot.h"
 
 int main(int argc, char *argv[]){
-                printf("\nstart\n");
+                printf("\tstart\n");
     struct task note;
     short opt;
     FILE *fp;
     char *group = malloc(MAXLINE*sizeof(char));
 
-                printf("\nfopen\n");
-    fp = fopen("/home/huck/.local/state/odot/todo", "w+");
+                printf("\tfopen\n");
+    fp = fopen("/home/huck/.local/state/odot/todo.txt", "w+");
     if (!fp){
         error(1);
     }
 
-                printf("\ngetopt\n");
+                printf("\tgetopt\n");
     opt = getopt(argc, argv);
 
-                printf("\ngetnote\n");
+                printf("\tgetnote\n");
     note = getnote(argc, argv, group);
 
     if (opt >= 4){
-                printf("\nrem\n");
+                printf("\trem\n");
         rem(note, fp);
-    } else {
-                printf("\nadd\n");
+    } else if (opt >= 2){
+                printf("\tadd\n");
         add(note, fp);
     }
 
     if (opt % 2 != 0){
-                printf("\nshow\n");
+                printf("\tshow\n");
         show(group, fp); 
     }
-
-    free(group);
+                printf("\texiting\n");
     fclose(fp);
+    free(group);
     return 0;
 }
 
 void error(int err){
     switch (err) {
         case 1:
-            fprintf(stderr,"ERROR: COULD NOT ACCESS FILE: %s\n", "/home/huck/.local/state/odot/todo");
+            fprintf(stderr,"ERROR: COULD NOT ACCESS FILE: %s\n", "/home/huck/.local/state/odot/todo.txt");
             break;
         case 2:
             fprintf(stderr,"ERROR: CANT ADD AND REMOVE SAME TASK\n");
@@ -55,7 +55,7 @@ void dialogue(char *m1, char *m2, int c){
 }
 
 void formattask(struct task t){
-    printf("* %s\t%s\t%i", t.task, t.group, t.date);
+    printf("* %s\t%s\n", t.task, t.group);
 }
 
     /* Returns:
@@ -64,17 +64,13 @@ void formattask(struct task t){
         2 - Group matches
         3 - Both match
     */
-int listcheck(struct task t, FILE *fp){
+int listcheck(struct task t, char *c){
     int i;
-    i += (strcmp(t.task,gettask(fp).task) == 0) ? 1 : 0;
-    i += (strcmp(t.group,gettask(fp).group) == 0) ? 2 : 0;
+    i += (strcmp(t.task,gettask(c).task) == 0) ? 1 : 0;
+    i += (strcmp(t.group,gettask(c).group) == 0) ? 2 : 0;
     return i;
 }
 
-char *gettime(void){
-    return NULL;
-}
-
 /* returns 0 for yes and 1 for no */
 int check(void){
     printf("Continue? [y/n] (y):");
diff --git a/odot b/odot
index 1c93fb8b2c1bea2ab336ac8e48fc500c0c1690f6..f13d2281af9e0bc113ccc70ba193c8e28596de48 100755 (executable)
Binary files a/odot and b/odot differ
diff --git a/odot.h b/odot.h
index 78c35483c1f0e31e17590d60e9f3be440b89271b..1cd5ff272fd5d2524e0fd6be8717a24550e7d197 100644 (file)
--- a/odot.h
+++ b/odot.h
@@ -10,7 +10,6 @@
 
 struct task {
     char *task;
-    int date;
     char *group;
 };
 
@@ -21,7 +20,7 @@ void add(struct task, FILE *);
 void rem(struct task, FILE *);
 void show(char *group, FILE *);
 
-int listcheck(struct task, FILE *);
+int listcheck(struct task, char *);
 int geturgency(int);
 char *gettime(void);
 
@@ -32,6 +31,6 @@ int check(void);
 
 struct task maketask(char *, char *);
 void puttask(struct task n, FILE*);
-struct task gettask(FILE *);
+struct task gettask(char *);
 
 enum color {BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE};