From: Huck Boles Date: Thu, 3 Nov 2022 01:00:02 +0000 (-0500) Subject: automatic backup X-Git-Url: https://git.huck.website/?a=commitdiff_plain;h=aa3f1fcdab5929e541f993b9a42799b7a862ef2b;p=odot.git automatic backup --- diff --git a/.ccls-cache/@home@huck@.repos@odot/file.c b/.ccls-cache/@home@huck@.repos@odot/file.c index d4fcd1d..f636508 100644 --- a/.ccls-cache/@home@huck@.repos@odot/file.c +++ b/.ccls-cache/@home@huck@.repos@odot/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/.ccls-cache/@home@huck@.repos@odot/file.c.blob b/.ccls-cache/@home@huck@.repos@odot/file.c.blob index 1421e3e..03b9d13 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 f5db53d..577b287 100644 --- a/.ccls-cache/@home@huck@.repos@odot/func.c +++ b/.ccls-cache/@home@huck@.repos@odot/func.c @@ -34,6 +34,6 @@ int linecount(void){ if (c == '\n') i++; } - rewind(fp); + fseek(fp,0,SEEK_SET); 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 c849efd..975bcaf 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/structure.c b/.ccls-cache/@home@huck@.repos@odot/structure.c index cf3c428..403c254 100644 --- a/.ccls-cache/@home@huck@.repos@odot/structure.c +++ b/.ccls-cache/@home@huck@.repos@odot/structure.c @@ -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; diff --git a/.ccls-cache/@home@huck@.repos@odot/structure.c.blob b/.ccls-cache/@home@huck@.repos@odot/structure.c.blob index c4d3cc0..d5b1157 100644 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 d4fcd1d..f636508 100644 --- 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 f5db53d..577b287 100644 --- 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; } diff --git a/structure.c b/structure.c index cf3c428..403c254 100644 --- a/structure.c +++ b/structure.c @@ -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;