From 8e6248cecd2d1600eac9855de30922459f7b98a2 Mon Sep 17 00:00:00 2001 From: Huck Boles Date: Tue, 15 Nov 2022 00:00:13 -0600 Subject: [PATCH] Tue Nov 15 12:00:13 AM CST 2022 automatic backup --- .../@usr@include@stdio.h.blob | Bin 37510 -> 37510 bytes .ccls-cache/@home@huck@.repos@odot/dialogue.c | 1 - .../@home@huck@.repos@odot/dialogue.c.blob | Bin 3650 -> 3650 bytes .ccls-cache/@home@huck@.repos@odot/file.c | 84 +++++++----------- .../@home@huck@.repos@odot/file.c.blob | Bin 6788 -> 6599 bytes .ccls-cache/@home@huck@.repos@odot/func.c | 30 +++---- .../@home@huck@.repos@odot/func.c.blob | Bin 3573 -> 4375 bytes .ccls-cache/@home@huck@.repos@odot/input.c | 19 ++-- .../@home@huck@.repos@odot/input.c.blob | Bin 5048 -> 5279 bytes .../@home@huck@.repos@odot/main.c.blob | Bin 2613 -> 2781 bytes .ccls-cache/@home@huck@.repos@odot/odot.h | 12 +-- .../@home@huck@.repos@odot/odot.h.blob | Bin 4702 -> 4765 bytes Makefile | 9 +- file.c | 84 +++++++----------- func.c | 30 +++---- input.c | 19 ++-- odot.h | 12 +-- 17 files changed, 120 insertions(+), 180 deletions(-) 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 2c54f42b3a61d53d5ae68adf428c9be5dfec5df5..a1526a4e7ca5be6ed9e7bd081df2f8faea2de00d 100644 GIT binary patch delta 38 rcmZo$%G9=$X@WURT4qk_L~BJby)hx4mDz;p*k@1GNox delta 38 rcmZo$%G9=$X@WURZenKML~BJby)hx4mHC(Ly~%=1Qk(CvuId2*5Ec%2 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 53b636cb918acb1d784df752368fe5df7852096a..7dffb28a7d0da606bf51954586c01a1e656e9e67 100644 GIT binary patch delta 37 tcmX>kb4Z3;i{alJ$9u;Z7#SHR*K>$&R9Mc+e2w+lkb4Z3;i{alb`+LV27#SHR*K>$&R9Mc+EN6djav_V<<|nLi902?=47~sV 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 70d8cc5e67758201d1f5eedb5583369db9364354..e7c1ccb1550e08b2eeaa2f88d1e76dae42ec0122 100644 GIT binary patch delta 2710 zcma)8eQaCR6@T~nJ^R|dj@`GHXD1H!i|g6XA90P77&mqu7t*g#RaK#-6crkhlmyZ^ zBu>j$aS2poVk@P0+8FCrZB!d$8WP&pRY-se73B{QUqYSG1W1KSYZ(HS4W=r+yXPf# z`dX0iAMf0E?#H?3cYeR~{7Co7PFF&>=nbBEO+dmE+kMZsKPuaP;yptjlKg);Axn~! zj-)fR*|ns$YVEp}dLk~kTz2GeIlLlr2oX^b1ev{gIC?|-_4`({&wl*rZ7nxHR$+xt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pM(;2l8W3cA1(SKQSA6iO8sQ>|2ktaa9c!QNuf z3(G-&FbJ%r0kb-UCm?a?>VP-^yaW7zv>Kryeh7H8{w%yQDvV-;N*_)%XSQUH(+a~2 z%n=N8*h;<<&1rKb!34P)eeu@@wG&lpQHTnSln8^u4wkrgyC*3LjfQpsZ>ct6#y&Bz znpUO2$TFH`iCSVeO)RkpmYDw3KWg9lVb?p{O~^%s5EfJ*deFU#C82GhEXduVM?gLn znq`T8>BRMuAMU$xe6*(*M(S9xQ_j6&+phLYP5m;GoCG=`>W(jJEhcY6THcQ$# zxWSTM!2?Zpr(K35#{vnhPl{}3J*<}ymSMeA=oX-Qy)|Bi5})XUT_H6Tqa@N9NmEiM z)j>hD@~u=P$z*a1C0$Y%AjAAHAlYOVkdc-V2$;4cc_}Azemoep_Gc+rNz5LzpAa(x zvNPPNU6(d);AXjku?h5=AElX%_1=^a6OhdWpIEJTF6mD~9y^>JP-q?g4!G}Z>`YLS zYD|Ib6?#Rg)mQrjZVT6M@Pc0D)y8D6jceeN2He1Dhvh&uw~c$icm{23BkpPUJgZT6 zpvdjwrj0ewYo?X{rdH>})I@&%AXJ_8j>p>rqaJ2Sy|Lx?*szHzy;l?>%K>M}H1UUB67;s5hA=KEJOKzVfy&KljFa@6LX*z6>`UjncL>i9{nH z6VU|7q?&9=lc9#8Eii!8Y>W1&TN&gIa8Da)9w?|$*S4Ov4+8j=kcw;;R YKP=wXILvXmTZJ(n?g7$a?=T?$10s19>Hq)$ 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 c72c6d09c852467d318fea300a09b7ada43ca215..4100071c98b31a5fcf860c386945402367f7e50a 100644 GIT binary patch delta 1857 zcmZWqYfKzf6rQ z&f`1ZIp^-3>@yzh<^Cmc(3( zBRs5z<549NRh8~UINVoQzq2{0csn~2YCPOE;8Xfz(H^CPo= zNtk1Qgr2-xaNAb%t9gC<(xu7Yan@NHvp*6IhhjrfH5s>v69gNtNrL1;yu@ur;F+c$ zet7o>6T*8l`ayE?-MJS&o7FFNeHy<~nKO!ncX3=vf4dT-@DfCo9c$!|n zb5NSU*1vo!)Y}zTyggx6jSPefi#S58yp7l(osF~8bR0)C!^I4{mIH7M-N(WIDy5iM zrEp=9m|h!jKw0ZuIAk`??T?X`nQR6Jb9N zSa>N%%D3?Pk#F5I@7G*SU)%bZUgoS;!Hn&I3nWjL&0{Yv1;2Bj{JL*j<&`H#J8-@+ zhFPi9v{w;W5X3G@rBVzL9GMOq;vIs+H6=o?QMR1z%HeaRT$%9tj>ve{M26*KGbfe2 zJJ-Dx*6_RbcgC&5)(h*tId?b%@a=lRjc4`K+Qe03xac_e{q*FB%nG0fA_ZhC;YlNT z8h|gIUHS0Zp})u5f_3mM9RvU@fpn+<`BssI$tj6$mOgUVr+qp6#lqgko$WzTV0Hof z?bLo49cA{z0y=6qjGh-C)c7nZD;Kbt#2eGuJqR0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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 3ed7c31c342ebfd06228b2e51eb0dab4038a631f..3ae02cf4b95f0e223a8d1351de4984bcf3098b00 100644 GIT binary patch delta 1252 zcmZvbO>7%Q6vy}Nt}Vx1J5Ew9ZfeJa?fPrC>ul;|m&Nr?)0U(mbhPDXD zI1Xxsz@=(XkqQzT!2!yLDi9x+wrZs!ap0?>s^EZ-0D+1KmtK0P03ig(EHif3N-Fm7 zW;FZez5n~YHy@_o%=YBCfA;^5}f_xJNh@x=w!KH(j{m`9uJToa}i(uzVI- z?a`7(*hukUaNBu~<9O$dnHRo(erb2wxifSg*R3Dl0_Hg4-`CXRy4Ff!aK1mj^UTAo zp7N86hbpMH+-S@%J(gK&)R)T*#P+DFqI>pC??$;S=l2J}_S<0|Y;H#Rv_Eu8a1^r`2b4Za+0$0j2il5n`>P9I*qxH9g%!=Hm=)j$!LT1WZ3_r`;tUS3%fbK=a|(%o0z z-hALl<3PQN$_MA`C`S{NYexwRZ1F%MoJf+Z{+%0Rsn`gs7o|{pjfdk&^3#S<$dCc) zL{nt{olB$9Z<@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main.c.blob b/.ccls-cache/@home@huck@.repos@odot/main.c.blob index 1cfe75fa10e9910c8e8e9bef4e484c5a11d7449d..eaa9588029e6420eb3fb1e2003579e452cfbe936 100644 GIT binary patch delta 312 zcmdlga#wW2N>=7;tj{JlvPf(`!g`Rop7DS2r^~kHUcYiP^GXzQ6EpKPK#atq^kf}{ zMs)uBdZ##9m8K9 zpkZ*GFc*TH1X3x*ssvUk#HzFnta9=aPHPW{nfXBDK#pbL1*&AyVA5h_WMW{_V)(yC cV&&8;`Zb;qWqJ7}sSt~yDy5i|z$%p(0NgK6umAu6 delta 143 zcmcaBx>aPuN>=7yw)ZACvPf(`!g`Qdo`G>20~%obUtQuc=e^|XV+_obqqwZYQY%VQ zi}DnbGZKpwwDK9Gq?kZDco`TOnKYQRfFuKx7Q_EF5-X=((Xa7DQJt4xk_yzo0oNeK Kqy*NW!~g&Wh9Wlr 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 4e83d72cf37f476c6d70f71ea687b33d2a03d435..54cbfa50ccc19c4afc0f3e61052966ed92d4e893 100644 GIT binary patch delta 434 zcmcboGFO#Ni{W37z_X2Pi?}Dh=eD0bgU5)YUtf(&YUW?5$s4$(Ty+%OJbhdhv@{vG zxcC@=fboB@%%i&!Na;ruN$xT@0!Fb>47krgF^^pG6UE^aSm}QMn-W4agc$c^Pm4!lr}d9 z8gt0HlHrn(V`P+Jkg=I; z#A`YEHm|$5tg82=NKRfhuyIAHxiII|08LPsEYIgLIh(h@^nYx&_w1`LIWzN06ml~2 zQj_yb^GcvfH5pJGE6*VhbgVpsyw>C=e5uMD!aBkxEQ}&TB2p}jq9UR)ER5o2;&v>I z@-p%&ER0GPN)D6#_-h4W?t};BtjHs!sL8;^#m4{yjQ^h>Ke2-&f7NUT z9w1MNOG$!}QHeom@)B-mztYKK(>=WGo|WZirYIz)q-YeE6qP2ID3l}?XX_|r=9Peq zVFMY%0M;$cB`m%uLiZk-dH6}OkNZ82%wO#XOxXV93RSjsmLQZCJNpePNayGKXnhYEqLI^v>ImD$H z8O0gIO(tjXT24;jE10~H*L|`ypX+2rUIUZ&A8MxjY{`uRyHAEoMvjqDhC#*#XweC_ z#djF{wrD~u%1ceoFU>2_aP#zWo&1JRf>CWUD}O30v%HMF%H&@DT0xjW@bH=}EfCHD b6P;`#q`$dHpqY^a7Mzp+3hGZz7P0~WDsq25 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; -- 2.45.2