]> git.huck.website - odot.git/commitdiff
Makefile
authorHuck Boles <huboles@protonmail.com>
Sat, 26 Nov 2022 20:14:52 +0000 (14:14 -0600)
committerHuck Boles <huboles@protonmail.com>
Sat, 26 Nov 2022 20:14:52 +0000 (14:14 -0600)
Makefile [new file with mode: 0644]
main.c
odot [deleted file]

diff --git a/Makefile b/Makefile
new file mode 100644 (file)
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 a9058a7f53dbc3b3eaa3542568ffd6968e34a801..6c36855ee7c45b0a11650bba72a9839500e1352c 100644 (file)
--- a/main.c
+++ b/main.c
@@ -3,19 +3,27 @@
 #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();
@@ -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 (executable)
index 2ef5f6a..0000000
Binary files a/odot and /dev/null differ