#include <string.h>
#define MAXLINE 500
-#define LIST "/home/huck/.local/state/odot/todo.txt"
-#define DONE "/home/huck/.local/state/odot/done.txt"
-#define TMP "/home/huck/.local/state/odot/odot.txt"
int getopt(int, char **);
char *getnote(int, char **);
+void envar(void);
void addnote(char *);
void show();
-char *hash(char *);
+char *list;
+char *done;
+char *tmp;
int main(int argc, char *argv[]){
+ extern char *list;
+ extern char *done;
+ extern char *tmp;
+
+ char *homedir = getenv("HOME");
+ list = strcat(homedir,"/.local/share/odot/todo.txt");
+ done = strcat(homedir,"/.local/share/odot/done.txt");
+ tmp = strcat(homedir,"/.local/share/odot/tmp.txt");
if (argc == 1){
show();
}
void addnote(char *note){
+ extern char *list;
+ extern char *done;
+ extern char *tmp;
+
int i = 0;
char *buf = malloc(MAXLINE * sizeof(char));
- FILE *fp = fopen(LIST,"r");
- FILE *fdone = fopen(DONE,"a");
- FILE *tmp = fopen(TMP,"w");
+ FILE *fp = fopen(list,"r");
+ FILE *fdone = fopen(done,"a");
+ FILE *tfp = fopen(tmp,"w");
if(!fp || !tmp || !fdone)
exit(1);
while(fgets(buf, MAXLINE, fp)){
if (strcmp(note,buf) > 0){
- fputs(buf,tmp);
+ fputs(buf,tfp);
} else if (strcmp(note,buf) == 0){
fputs(note,fdone);
printf("Removed from list: %s", note);
i++;
} else if (strcmp(note,buf) < 0){
if (i == 0){
- fputs(note,tmp);
+ fputs(note,tfp);
printf("Added to list: %s", note);
i++;
}
- fputs(buf,tmp);
+ fputs(buf,tfp);
}
}
if (i == 0){
- fputs(note,tmp);
+ fputs(note,tfp);
printf("Added to list: %s", note);
}
- fclose(tmp);
+ fclose(tfp);
fclose(fp);
fclose(fdone);
free(buf);
- remove(LIST);
- rename(TMP,LIST);
+ remove(list);
+ rename(tmp,list);
return;
}
void show(void){
- FILE *fp = fopen(LIST,"r");
+ extern char *list;
+
+ FILE *fp = fopen(list,"r");
char *buf = malloc(MAXLINE * sizeof(char));
printf("\033[36;1mTODO\033[0m:\n");
return;
}
-char *hash(char *note){
-
-}