]> git.huck.website - odot.git/commitdiff
automatic backup
authorHuck Boles <huboles@protonmail.com>
Thu, 3 Nov 2022 02:00:02 +0000 (21:00 -0500)
committerHuck Boles <huboles@protonmail.com>
Thu, 3 Nov 2022 02:00:02 +0000 (21:00 -0500)
.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/structure.c
.ccls-cache/@home@huck@.repos@odot/structure.c.blob
file.c
input.c
structure.c

index f636508dd2d0f1bbf574c86813c40ea87b094422..14a07c9e3c67f9b68bca0a3b39e92abedf64ecaf 100644 (file)
@@ -8,10 +8,10 @@ enum color {BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE};
 
 
 void add(struct task t, int size){
-    int l,m,h,i,len;
-    FILE *fcopy;
-    char *s;
-    h = len = linecount();
+    int l,m,h,i;
+    FILE *fcopy = fopen("/tmp/fcopy", "w");
+    char *s = malloc(MAXLINE * sizeof(char));
+    h = size;
     m = h / 2;
     l = 0;
 
@@ -32,22 +32,20 @@ void add(struct task t, int size){
     }
 
     fseek(fp, 0, SEEK_SET);
-    fcopy = fopen("/tmp/fcopy", "w");
 
-    for (i = 0; i < len;){
+    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);
-            i++;
         }
     }
     fclose(fp);
     fclose(fcopy);
     remove(TODOLIST);
     rename("/tmp/fcopy", TODOLIST);
-
+    free(s);
     return;
 }
 
@@ -82,7 +80,6 @@ void show(void){
     fp = fopen(TODOLIST,"r");
     while (fgets(c, MAXLINE, fp) != NULL )
         printf("\t\t\033[1;35m*\033[0m %s", c);
-    fclose(fp);
     free(c);
 }
 
index 03b9d1378e33e42762150c5a941926ac984f83c4..ba4f73213cda76b5840328ece1f49d0e0e554c0b 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 a8846d3badae5fb5061646943da7fd33409180df..7a7690ec3d01e8a44b2ce59cdce51c9fda7aff9b 100644 (file)
@@ -36,3 +36,21 @@ void getopt(int n, char *arg[]){
     }
 }
 
+struct task maketask(char *task, char *group){
+    struct task tmp;
+
+    tmp.task = task;
+    tmp.date = 0;
+    tmp.group = group;
+
+    return tmp;
+}
+
+
+struct task gettask(void){
+    struct task tmp;
+    
+    fscanf(fp,"%s\t%i\t%s\n",tmp.task,&tmp.date,tmp.group);
+
+    return tmp;
+}
index 0338a569a4846675ed62909ea2b64ad189c8409b..bd2c79821f1f19961328772050d104a513c0054b 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 403c254e07c6ddfca32a13504fdf5f562a41efbb..65828eb7b02e9eb14a1dbf2ba6c7c4f313c162a7 100644 (file)
@@ -3,21 +3,3 @@
 extern FILE *fp;
 
 
-struct task maketask(char *task, char *group){
-    struct task tmp;
-
-    tmp.task = task;
-    tmp.date = 0;
-    tmp.group = group;
-
-    return tmp;
-}
-
-
-struct task gettask(void){
-    struct task tmp;
-    
-    fscanf(fp,"%s\t%i\t%s\n",tmp.task,&tmp.date,tmp.group);
-
-    return tmp;
-}
index d5b11573ffe39e1037f256518e2114b212208c35..af2db949188e017ce0430a2c035310f3f359b87c 100644 (file)
Binary files a/.ccls-cache/@home@huck@.repos@odot/structure.c.blob and b/.ccls-cache/@home@huck@.repos@odot/structure.c.blob differ
diff --git a/file.c b/file.c
index f636508dd2d0f1bbf574c86813c40ea87b094422..14a07c9e3c67f9b68bca0a3b39e92abedf64ecaf 100644 (file)
--- a/file.c
+++ b/file.c
@@ -8,10 +8,10 @@ enum color {BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE};
 
 
 void add(struct task t, int size){
-    int l,m,h,i,len;
-    FILE *fcopy;
-    char *s;
-    h = len = linecount();
+    int l,m,h,i;
+    FILE *fcopy = fopen("/tmp/fcopy", "w");
+    char *s = malloc(MAXLINE * sizeof(char));
+    h = size;
     m = h / 2;
     l = 0;
 
@@ -32,22 +32,20 @@ void add(struct task t, int size){
     }
 
     fseek(fp, 0, SEEK_SET);
-    fcopy = fopen("/tmp/fcopy", "w");
 
-    for (i = 0; i < len;){
+    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);
-            i++;
         }
     }
     fclose(fp);
     fclose(fcopy);
     remove(TODOLIST);
     rename("/tmp/fcopy", TODOLIST);
-
+    free(s);
     return;
 }
 
@@ -82,7 +80,6 @@ void show(void){
     fp = fopen(TODOLIST,"r");
     while (fgets(c, MAXLINE, fp) != NULL )
         printf("\t\t\033[1;35m*\033[0m %s", c);
-    fclose(fp);
     free(c);
 }
 
diff --git a/input.c b/input.c
index a8846d3badae5fb5061646943da7fd33409180df..7a7690ec3d01e8a44b2ce59cdce51c9fda7aff9b 100644 (file)
--- a/input.c
+++ b/input.c
@@ -36,3 +36,21 @@ void getopt(int n, char *arg[]){
     }
 }
 
+struct task maketask(char *task, char *group){
+    struct task tmp;
+
+    tmp.task = task;
+    tmp.date = 0;
+    tmp.group = group;
+
+    return tmp;
+}
+
+
+struct task gettask(void){
+    struct task tmp;
+    
+    fscanf(fp,"%s\t%i\t%s\n",tmp.task,&tmp.date,tmp.group);
+
+    return tmp;
+}
index 403c254e07c6ddfca32a13504fdf5f562a41efbb..65828eb7b02e9eb14a1dbf2ba6c7c4f313c162a7 100644 (file)
@@ -3,21 +3,3 @@
 extern FILE *fp;
 
 
-struct task maketask(char *task, char *group){
-    struct task tmp;
-
-    tmp.task = task;
-    tmp.date = 0;
-    tmp.group = group;
-
-    return tmp;
-}
-
-
-struct task gettask(void){
-    struct task tmp;
-    
-    fscanf(fp,"%s\t%i\t%s\n",tmp.task,&tmp.date,tmp.group);
-
-    return tmp;
-}