From: Huck Boles Date: Sat, 26 Nov 2022 20:14:52 +0000 (-0600) Subject: Makefile X-Git-Url: https://git.huck.website/?a=commitdiff_plain;h=138060f7bf5f48b607ede0302b7eaa420e1058ac;p=odot.git Makefile --- diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..1708218 --- /dev/null +++ b/Makefile @@ -0,0 +1,14 @@ +SHELL = /bin/bash +PROG = odot +PREFIX ?= /usr +BINDIR ?= $(PREFIX)/bin +SHAREDIR ?= $(HOME)/.local/share + + +install : main.c + sudo gcc main.c -o '$(BINDIR)/$(PROG)' + [[ ! -d '$(SHAREDIR)/$(PROG))' ]] && mkdir -p '$(SHAREDIR)/$(PROG)' + +clean : + rm -rf '$(SHAREDIR)/$(PROG)' + diff --git a/main.c b/main.c index a9058a7..6c36855 100644 --- a/main.c +++ b/main.c @@ -3,19 +3,27 @@ #include #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(); @@ -35,47 +43,53 @@ char *getnote(int n, char *arg[]){ } 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"); @@ -88,6 +102,3 @@ void show(void){ return; } -char *hash(char *note){ - -} diff --git a/odot b/odot deleted file mode 100755 index 2ef5f6a..0000000 Binary files a/odot and /dev/null differ