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

index d4fcd1d6a80fd0bb786449f1ad3370739d1edba4..f636508dd2d0f1bbf574c86813c40ea87b094422 100644 (file)
@@ -8,13 +8,14 @@ enum color {BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE};
 
 
 void add(struct task t, int size){
-    int l,m,h,i;
-
-    h = linecount();
+    int l,m,h,i,len;
+    FILE *fcopy;
+    char *s;
+    h = len = linecount();
     m = h / 2;
     l = 0;
 
-    while (h != m  && m != l){
+    while (!(h == m && m == l)){
         i = strcmp(t.task,gettask().task);
 
         if (i < 0) {
@@ -27,9 +28,26 @@ void add(struct task t, int size){
         }
 
         m = (h + l)/2;
+        fseek(fp, m, SEEK_SET);
+    }
+
+    fseek(fp, 0, SEEK_SET);
+    fcopy = fopen("/tmp/fcopy", "w");
+
+    for (i = 0; i < len;){
+        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);
 
-    puttask(t);
     return;
 }
 
index 1421e3e8dd6d3e112aa9569e7a6f264e784e2ebd..03b9d1378e33e42762150c5a941926ac984f83c4 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 f5db53d9ed8e55d7d7e1581a8d9f8f164fc45cc9..577b28767dba54099b7e366525038da90f645a40 100644 (file)
@@ -34,6 +34,6 @@ int linecount(void){
         if (c == '\n')
             i++;
     }
-    rewind(fp);
+    fseek(fp,0,SEEK_SET);
     return i;
 }
index c849efdb44ddba85bb396d3d95d5b1ded238151e..975bcaf2de7b69c77ce700d20d1a13ad4707f001 100644 (file)
Binary files a/.ccls-cache/@home@huck@.repos@odot/func.c.blob and b/.ccls-cache/@home@huck@.repos@odot/func.c.blob differ
index cf3c428150d08eb30ade4b71594c3b66456562a1..403c254e07c6ddfca32a13504fdf5f562a41efbb 100644 (file)
@@ -1,6 +1,5 @@
 #include "odot.h"
 
-extern int urgency;
 extern FILE *fp;
 
 
@@ -14,9 +13,6 @@ struct task maketask(char *task, char *group){
     return tmp;
 }
 
-void puttask(struct task n){
-    fprintf(fp, "%s\t%i\t%s\n",n.task,n.date,n.group);
-}
 
 struct task gettask(void){
     struct task tmp;
index c4d3cc0a0fc6912dcd7284adcd5a20028ed5d876..d5b11573ffe39e1037f256518e2114b212208c35 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 d4fcd1d6a80fd0bb786449f1ad3370739d1edba4..f636508dd2d0f1bbf574c86813c40ea87b094422 100644 (file)
--- a/file.c
+++ b/file.c
@@ -8,13 +8,14 @@ enum color {BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE};
 
 
 void add(struct task t, int size){
-    int l,m,h,i;
-
-    h = linecount();
+    int l,m,h,i,len;
+    FILE *fcopy;
+    char *s;
+    h = len = linecount();
     m = h / 2;
     l = 0;
 
-    while (h != m  && m != l){
+    while (!(h == m && m == l)){
         i = strcmp(t.task,gettask().task);
 
         if (i < 0) {
@@ -27,9 +28,26 @@ void add(struct task t, int size){
         }
 
         m = (h + l)/2;
+        fseek(fp, m, SEEK_SET);
+    }
+
+    fseek(fp, 0, SEEK_SET);
+    fcopy = fopen("/tmp/fcopy", "w");
+
+    for (i = 0; i < len;){
+        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);
 
-    puttask(t);
     return;
 }
 
diff --git a/func.c b/func.c
index f5db53d9ed8e55d7d7e1581a8d9f8f164fc45cc9..577b28767dba54099b7e366525038da90f645a40 100644 (file)
--- a/func.c
+++ b/func.c
@@ -34,6 +34,6 @@ int linecount(void){
         if (c == '\n')
             i++;
     }
-    rewind(fp);
+    fseek(fp,0,SEEK_SET);
     return i;
 }
index cf3c428150d08eb30ade4b71594c3b66456562a1..403c254e07c6ddfca32a13504fdf5f562a41efbb 100644 (file)
@@ -1,6 +1,5 @@
 #include "odot.h"
 
-extern int urgency;
 extern FILE *fp;
 
 
@@ -14,9 +13,6 @@ struct task maketask(char *task, char *group){
     return tmp;
 }
 
-void puttask(struct task n){
-    fprintf(fp, "%s\t%i\t%s\n",n.task,n.date,n.group);
-}
 
 struct task gettask(void){
     struct task tmp;