#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++;
}
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);
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);
}
#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;
}
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;
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);
}
#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");
}
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:
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):");
struct task {
char *task;
- int date;
char *group;
};
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);
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};
#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++;
}
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);
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);
}
#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;
}
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;
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);
}
#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");
}
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:
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):");
struct task {
char *task;
- int date;
char *group;
};
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);
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};