#include "odot.h"
-void error(int err){
- switch (err) {
- case '1':
- fprintf(stderr,"ERROR: COULD NOT ACCESS FILE: %s\n", TODOLIST);
- case '2':
- fprintf(stderr,"ERROR: COULD NOT GET CURRENT TIME\n");
- case '3':
- fprintf(stderr,"ERROR: ARGUMENT OUT OF RANGE\n");
- }
- exit(err);
-}
-
-void dialogue(char *m1, char *m2, int c){
- printf("\033[1;3%im%s\033[0m: %s\n", c, m1, m2);
- return;
-}
-
-void formattask(struct task t){
- printf("* %s\t%s\t%i", t.task, t.group, t.date);
-}
#include "odot.h"
-
-extern FILE *fp;
-
-enum color {BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE};
-
void add(struct task t, FILE *fp){
+ printf("\nalloc\n");
char *c = malloc(strlen(t.task)*sizeof(char));
- FILE *fc = fopen("/tmp/odot", "w");
+ printf("\nfopen\n");
+ FILE *buf = fopen("odot.tmp", "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);
- break;
+ printf("Remove from list?");
+ if (check() == 0){
+ break;
+ } else {
+ puttask(gettask(fp), buf);
+ break;
+ }
case 1:
dialogue("Already on list in a different group", gettask(fp).group, YELLOW);
- /* confirm(); */
+ 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,fc);
+ puttask(t,buf);
++i;
}
+ puttask(gettask(fp), buf);
+ break;
}
- puttask(gettask(fp), fc);
}
free(c);
fclose(fp);
- fclose(fc);
- remove(TODOLIST);
- rename("/tmp/odot", TODOLIST);
+ fclose(buf);
+ remove("/home/huck/.local/state/odot/todo");
+ rename("odot.tmp", "/home/huck/.local/state/odot/todo");
return;
}
-void rem(FILE *fp){
+void rem(struct task t, FILE *fp){
char *s = malloc(MAXLINE * sizeof(char));
- FILE *fc = fopen("/tmp/odot", "w");
+ FILE *buf = fopen("odot.tmp", "w");
+ int i = 0;
while (fgets(s, MAXLINE, fp) != NULL){
s[strlen(s) - 1] = 0;
- if (strcmp(note, s) != 0){
- fputs(strcat(s,"\n"),fc);
+ if (strcmp(t.task, s) != 0){
+ fputs(strcat(s,"\n"),buf);
+ } else {
+ i++;
}
}
fclose(fp);
- fclose(fc);
+ fclose(buf);
+
+ remove ("/home/huck/.local/state/odot/todo");
+ rename("odot.tmp", "/home/huck/.local/state/odot/todo");
- remove (TODOLIST);
- rename("/tmp/odot", TODOLIST);
+ if (i == 0){
+ dialogue("Task not found", t.task, YELLOW);
+ printf("Add to list?");
+ if(check() == 0){
+ add(t,fp);
+ }
+ }
free(s);
}
-void show(FILE *fp){
+void show(char *group, FILE *fp){
char *c = malloc(sizeof(char));
- while (fgets(c, 1, fp) != NULL )
- formattask(gettask(fp));
+ while (fgets(c, 1, fp) != NULL ){
+ if (strcmp(group, "all") == 0 || strcmp(gettask(fp).group, group) == 0){
+ formattask(gettask(fp));
+ }
+ }
free(c);
}
#include "odot.h"
-enum color {BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE};
-
- /* 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;
-}
-
-
-char *gettime(void){
- return NULL;
-}
-
-int linecount(FILE *fp){
- int i = 0;
- char c;
- while ((c = fgetc(fp)) != EOF){
- if (c == '\n')
- i++;
- }
- fseek(fp,0,SEEK_SET);
- return i;
-}
#include "odot.h"
-extern char *note, *group;
-extern int urgency;
-
-char *getnote(int n, char *arg[]){
+struct task getnote(int n, char *arg[], char *group){
char *s = malloc(MAXLINE * sizeof(char));
+ struct task tmp;
+
+ if (n == 1)
+ printf("\nreturn from note\n");
+ return tmp;
+
-/* adds word to note if it doesn't start with - */
- while(--n > 0 && (*++arg)[0] != '-'){
+ while(n-- > 0){
+ printf("\n%i-nloop\n",n);
+ if (*arg[0] != '-'){
strcat(s, *arg);
strcat(s, (n > 1) ? " " : "");
+ } else if (strcmp(*arg,"-g") == 0){
+ strcpy(group, *arg);
+ }
}
- return s;
+ strcpy(tmp.task, s);
+ strcpy(tmp.group, group);
+ free(s);
+ return tmp;
}
/* uses a 3 bit number to represent options
4 - remove from list
*/
short getopt(int n, char *arg[]){
- char *c;
short options;
-
+
+ printf("\nreturn1\n");
/* show list if no arguments given */
if (n == 1)
return 1;
+ printf("\ncheckopt\n");
while (--n > 0 && (*++arg)[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(*arg,'g') != NULL){
- strcpy(group,*++arg);
- }
+ options += strchr(*arg, 'n') ? 2 : 0;
+ options += strchr(*arg, 'd') ? 4 : 0;
}
-
+ printf("%i", options);
+ if ((options - 5) > 0)
+ error(2);
return options;
}
#include "odot.h"
-extern char *note, *o;
-extern int urgency;
-
int main(int argc, char *argv[]){
+ printf("\nstart\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+");
+ if (!fp){
+ error(1);
+ }
+
+ printf("\ngetopt\n");
+ opt = getopt(argc, argv);
+
+ printf("\ngetnote\n");
+ note = getnote(argc, argv, group);
+
+ if (opt >= 4){
+ printf("\nrem\n");
+ rem(note, fp);
+ } else {
+ printf("\nadd\n");
+ add(note, fp);
+ }
+ if (opt % 2 != 0){
+ printf("\nshow\n");
+ show(group, fp);
+ }
+
+ free(group);
+ fclose(fp);
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");
+ break;
+ case 2:
+ fprintf(stderr,"ERROR: CANT ADD AND REMOVE SAME TASK\n");
+ break;
+ }
+ exit(err);
+}
+
+void dialogue(char *m1, char *m2, int c){
+ printf("\033[1;3%im%s\033[0m: %s\n", c, m1, m2);
+ return;
+}
+
+void formattask(struct task t){
+ printf("* %s\t%s\t%i", t.task, t.group, t.date);
+}
+
+ /* 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;
+}
+
+char *gettime(void){
+ return NULL;
+}
+
+/* returns 0 for yes and 1 for no */
+int check(void){
+ printf("Continue? [y/n] (y):");
+ if (((char) getchar()) == 'n')
+ return 1;
+ return 0;
+}
#include <string.h>
#include <ctype.h>
#include <time.h>
+#define TODOLIST "/home/huck/.local/state/odot/todo"
#define MAXLINE 1000
#define TIME "%H:%M %m-%d-%y"
-#define TODOLIST "/home/huck/.local/state/odot/todo"
struct task {
char *task;
char *group;
};
-char *getnote(int, char *[]);
+struct task getnote(int, char *[], char *);
short getopt(int, char *[]);
void add(struct task, FILE *);
-void rem(FILE *);
-void show(FILE *);
+void rem(struct task, FILE *);
+void show(char *group, FILE *);
int listcheck(struct task, FILE *);
int geturgency(int);
void dialogue(char *, char *, int);
void formattask(struct task t);
void error(int);
-
-int linecount(FILE *);
+int check(void);
struct task maketask(char *, char *);
void puttask(struct task n, FILE*);
struct task gettask(FILE *);
-char *note, *o;
-FILE *fp;
-
+enum color {BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE};
--- /dev/null
+#include <stdio.h>
+
+int main(int argc, char *argv[]){
+ FILE *fp = fopen("/home/huck/.local/state/odot/todo", "w+");
+
+ fclose(fp);
+ return 0;
+}
+
SHELL = /bin/zsh
-PROG = todo
+PROG = odot
PREFIX ?= /usr/local/bin
-TODOLIST = $(HOME)/.local/share/odot/todo
+ODOT = /home/huck/.local/share/odot
+TODOLIST = $(ODOT)/todo
-install : main.c input.c file.c dialogue.c func.c
+install : main.c input.c file.c
+ [[ ! -d $(TODOLIST) ]] && mkdir -p $(ODOT)
gcc *.c -o '$(PREFIX)/$(PROG)'
- [[ ! -d $(TODOLIST) ]] && mkdir -p $(TODOLIST)
-header : todo.h
+header : odot.h
gcc *.h
clean :
#include "odot.h"
-void error(int err){
- switch (err) {
- case '1':
- fprintf(stderr,"ERROR: COULD NOT ACCESS FILE: %s\n", TODOLIST);
- case '2':
- fprintf(stderr,"ERROR: COULD NOT GET CURRENT TIME\n");
- case '3':
- fprintf(stderr,"ERROR: ARGUMENT OUT OF RANGE\n");
- }
- exit(err);
-}
-
-void dialogue(char *m1, char *m2, int c){
- printf("\033[1;3%im%s\033[0m: %s\n", c, m1, m2);
- return;
-}
-
-void formattask(struct task t){
- printf("* %s\t%s\t%i", t.task, t.group, t.date);
-}
#include "odot.h"
-
-extern FILE *fp;
-
-enum color {BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE};
-
void add(struct task t, FILE *fp){
+ printf("\nalloc\n");
char *c = malloc(strlen(t.task)*sizeof(char));
- FILE *fc = fopen("/tmp/odot", "w");
+ printf("\nfopen\n");
+ FILE *buf = fopen("odot.tmp", "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);
- break;
+ printf("Remove from list?");
+ if (check() == 0){
+ break;
+ } else {
+ puttask(gettask(fp), buf);
+ break;
+ }
case 1:
dialogue("Already on list in a different group", gettask(fp).group, YELLOW);
- /* confirm(); */
+ 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,fc);
+ puttask(t,buf);
++i;
}
+ puttask(gettask(fp), buf);
+ break;
}
- puttask(gettask(fp), fc);
}
free(c);
fclose(fp);
- fclose(fc);
- remove(TODOLIST);
- rename("/tmp/odot", TODOLIST);
+ fclose(buf);
+ remove("/home/huck/.local/state/odot/todo");
+ rename("odot.tmp", "/home/huck/.local/state/odot/todo");
return;
}
-void rem(FILE *fp){
+void rem(struct task t, FILE *fp){
char *s = malloc(MAXLINE * sizeof(char));
- FILE *fc = fopen("/tmp/odot", "w");
+ FILE *buf = fopen("odot.tmp", "w");
+ int i = 0;
while (fgets(s, MAXLINE, fp) != NULL){
s[strlen(s) - 1] = 0;
- if (strcmp(note, s) != 0){
- fputs(strcat(s,"\n"),fc);
+ if (strcmp(t.task, s) != 0){
+ fputs(strcat(s,"\n"),buf);
+ } else {
+ i++;
}
}
fclose(fp);
- fclose(fc);
+ fclose(buf);
+
+ remove ("/home/huck/.local/state/odot/todo");
+ rename("odot.tmp", "/home/huck/.local/state/odot/todo");
- remove (TODOLIST);
- rename("/tmp/odot", TODOLIST);
+ if (i == 0){
+ dialogue("Task not found", t.task, YELLOW);
+ printf("Add to list?");
+ if(check() == 0){
+ add(t,fp);
+ }
+ }
free(s);
}
-void show(FILE *fp){
+void show(char *group, FILE *fp){
char *c = malloc(sizeof(char));
- while (fgets(c, 1, fp) != NULL )
- formattask(gettask(fp));
+ while (fgets(c, 1, fp) != NULL ){
+ if (strcmp(group, "all") == 0 || strcmp(gettask(fp).group, group) == 0){
+ formattask(gettask(fp));
+ }
+ }
free(c);
}
+++ /dev/null
-#include "odot.h"
-
-enum color {BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE};
-
- /* 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;
-}
-
-
-char *gettime(void){
- return NULL;
-}
-
-int linecount(FILE *fp){
- int i = 0;
- char c;
- while ((c = fgetc(fp)) != EOF){
- if (c == '\n')
- i++;
- }
- fseek(fp,0,SEEK_SET);
- return i;
-}
#include "odot.h"
-extern char *note, *group;
-extern int urgency;
-
-char *getnote(int n, char *arg[]){
+struct task getnote(int n, char *arg[], char *group){
char *s = malloc(MAXLINE * sizeof(char));
+ struct task tmp;
+
+ if (n == 1)
+ printf("\nreturn from note\n");
+ return tmp;
+
-/* adds word to note if it doesn't start with - */
- while(--n > 0 && (*++arg)[0] != '-'){
+ while(n-- > 0){
+ printf("\n%i-nloop\n",n);
+ if (*arg[0] != '-'){
strcat(s, *arg);
strcat(s, (n > 1) ? " " : "");
+ } else if (strcmp(*arg,"-g") == 0){
+ strcpy(group, *arg);
+ }
}
- return s;
+ strcpy(tmp.task, s);
+ strcpy(tmp.group, group);
+ free(s);
+ return tmp;
}
/* uses a 3 bit number to represent options
4 - remove from list
*/
short getopt(int n, char *arg[]){
- char *c;
short options;
-
+
+ printf("\nreturn1\n");
/* show list if no arguments given */
if (n == 1)
return 1;
+ printf("\ncheckopt\n");
while (--n > 0 && (*++arg)[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(*arg,'g') != NULL){
- strcpy(group,*++arg);
- }
+ options += strchr(*arg, 'n') ? 2 : 0;
+ options += strchr(*arg, 'd') ? 4 : 0;
}
-
+ printf("%i", options);
+ if ((options - 5) > 0)
+ error(2);
return options;
}
#include "odot.h"
-extern char *note, *o;
-extern int urgency;
-
int main(int argc, char *argv[]){
+ printf("\nstart\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+");
+ if (!fp){
+ error(1);
+ }
+
+ printf("\ngetopt\n");
+ opt = getopt(argc, argv);
+
+ printf("\ngetnote\n");
+ note = getnote(argc, argv, group);
+
+ if (opt >= 4){
+ printf("\nrem\n");
+ rem(note, fp);
+ } else {
+ printf("\nadd\n");
+ add(note, fp);
+ }
+ if (opt % 2 != 0){
+ printf("\nshow\n");
+ show(group, fp);
+ }
+
+ free(group);
+ fclose(fp);
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");
+ break;
+ case 2:
+ fprintf(stderr,"ERROR: CANT ADD AND REMOVE SAME TASK\n");
+ break;
+ }
+ exit(err);
+}
+
+void dialogue(char *m1, char *m2, int c){
+ printf("\033[1;3%im%s\033[0m: %s\n", c, m1, m2);
+ return;
+}
+
+void formattask(struct task t){
+ printf("* %s\t%s\t%i", t.task, t.group, t.date);
+}
+
+ /* 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;
+}
+
+char *gettime(void){
+ return NULL;
+}
+
+/* returns 0 for yes and 1 for no */
+int check(void){
+ printf("Continue? [y/n] (y):");
+ if (((char) getchar()) == 'n')
+ return 1;
+ return 0;
+}
#include <string.h>
#include <ctype.h>
#include <time.h>
+#define TODOLIST "/home/huck/.local/state/odot/todo"
#define MAXLINE 1000
#define TIME "%H:%M %m-%d-%y"
-#define TODOLIST "/home/huck/.local/state/odot/todo"
struct task {
char *task;
char *group;
};
-char *getnote(int, char *[]);
+struct task getnote(int, char *[], char *);
short getopt(int, char *[]);
void add(struct task, FILE *);
-void rem(FILE *);
-void show(FILE *);
+void rem(struct task, FILE *);
+void show(char *group, FILE *);
int listcheck(struct task, FILE *);
int geturgency(int);
void dialogue(char *, char *, int);
void formattask(struct task t);
void error(int);
-
-int linecount(FILE *);
+int check(void);
struct task maketask(char *, char *);
void puttask(struct task n, FILE*);
struct task gettask(FILE *);
-char *note, *o;
-FILE *fp;
-
+enum color {BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE};
+++ /dev/null
-#include "odot.h"
-
-extern FILE *fp;
-
-