#include "odot.h"
-void error(char type){
- switch (type) {
- case 'f':
+void error(int err){
+ switch (err) {
+ case '1':
fprintf(stderr,"ERROR: COULD NOT ACCESS FILE: %s\n", TODOLIST);
- exit(1);
- case 't':
+ case '2':
fprintf(stderr,"ERROR: COULD NOT GET CURRENT TIME\n");
- exit(2);
- case 'r':
+ case '3':
fprintf(stderr,"ERROR: ARGUMENT OUT OF RANGE\n");
- exit(3);
}
+ 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);
+}
+
+gT
l = 0;
while (!(h == m && m == l)){
- i = strcmp(t.task,gettask().task);
+ i = strcmp(t.task,gettask(fp).task);
if (i < 0) {
h = m;
fp = fopen(TODOLIST,"r");
while (fgets(c, MAXLINE, fp) != NULL )
- printf("\t\t\033[1;35m*\033[0m %s", c);
+ formattask(gettask(fp));
free(c);
}
error('f');
while (fgets(s, strlen(t.task), fp) != NULL){
+ /* strip newline for comparison, return 1 if string matches */
s[strlen(s) - 1] = 0;
if (strcmp(t.task, s) == 0){
free(s);
return NULL;
}
-int linecount(void){
+int linecount(FILE *fp){
int i = 0;
char c;
while ((c = fgetc(fp)) != EOF){
#include "odot.h"
-extern char *note, *o;
+extern char *note, *group;
extern int urgency;
char *getnote(int n, char *arg[]){
char *s = malloc(MAXLINE * sizeof(char));
- while(--n > 0){
- if ((*++arg)[0] != '-'){
+/* adds word to note if it doesn't start with - */
+ while(--n > 0 && (*++arg)[0] != '-'){
strcat(s, *arg);
strcat(s, (n > 1) ? " " : "");
- }
}
return s;
}
-void getopt(int n, char *arg[]){
+/* uses a 3 bit number to represent options
+ 1 - show list
+ 2 - add to list
+ 4 - remove from list
+*/
+short getopt(int n, char *arg[]){
char *c;
+ short options;
- if (n == 1){
- o = "s";
- return;
- }
+ /* show list if no arguments given */
+ if (n == 1)
+ return 1;
while (--n > 0 && (*++arg)[0] == '-'){
c = malloc(strlen(*arg) * sizeof(char));
c = *arg;
- strcat(o,(strchr(c, 'd')) ? "d" : "n");
- if (strchr(c,'s') != NULL){
- strcat(o,"s");
+ options += strchr(c, 'd') ? 4 : 2;
+ options += strchr(c, 's') ? 1 : 0;
+
+ /* if theres a g then add the next argument as a group */
+ if (strchr(c,'g') != NULL){
+ group = *++arg;
}
free(c);
}
+
+ return options;
}
+
struct task maketask(char *task, char *group){
struct task tmp;
tmp.task = task;
tmp.date = 0;
- tmp.group = group;
+ /* add to all group if group isn't specified */
+ tmp.group = (strcmp(group,"") == 0) ? "all" : group;
return tmp;
}
-struct task gettask(void){
+struct task gettask(FILE *fp){
struct task tmp;
-
- fscanf(fp,"%s\t%i\t%s\n",tmp.task,&tmp.date,tmp.group);
+
+ fscanf(fp,"%s\t%s\t%i\n",tmp.task,tmp.group,&tmp.date);
return tmp;
}
};
char *getnote(int, char *[]);
-void getopt(int, char *[]);
+short getopt(int, char *[]);
void add(struct task, int);
void rem(void);
int geturgency(int);
char *gettime(void);
-void error(char);
-
-int linecount(void);
void dialogue(char *, char *, int);
+void formattask(struct task t);
+void error(int);
+
+int linecount(FILE);
struct task maketask(char *, char *);
void puttask(struct task n);
-struct task gettask(void);
+struct task gettask(FILE *);
char *note, *o;
-int urgency;
FILE *fp;
#include "odot.h"
-void error(char type){
- switch (type) {
- case 'f':
+void error(int err){
+ switch (err) {
+ case '1':
fprintf(stderr,"ERROR: COULD NOT ACCESS FILE: %s\n", TODOLIST);
- exit(1);
- case 't':
+ case '2':
fprintf(stderr,"ERROR: COULD NOT GET CURRENT TIME\n");
- exit(2);
- case 'r':
+ case '3':
fprintf(stderr,"ERROR: ARGUMENT OUT OF RANGE\n");
- exit(3);
}
+ 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);
+}
+
l = 0;
while (!(h == m && m == l)){
- i = strcmp(t.task,gettask().task);
+ i = strcmp(t.task,gettask(fp).task);
if (i < 0) {
h = m;
fp = fopen(TODOLIST,"r");
while (fgets(c, MAXLINE, fp) != NULL )
- printf("\t\t\033[1;35m*\033[0m %s", c);
+ formattask(gettask(fp));
free(c);
}
error('f');
while (fgets(s, strlen(t.task), fp) != NULL){
+ /* strip newline for comparison, return 1 if string matches */
s[strlen(s) - 1] = 0;
if (strcmp(t.task, s) == 0){
free(s);
return NULL;
}
-int linecount(void){
+int linecount(FILE *fp){
int i = 0;
char c;
while ((c = fgetc(fp)) != EOF){
#include "odot.h"
-extern char *note, *o;
+extern char *note, *group;
extern int urgency;
char *getnote(int n, char *arg[]){
char *s = malloc(MAXLINE * sizeof(char));
- while(--n > 0){
- if ((*++arg)[0] != '-'){
+/* adds word to note if it doesn't start with - */
+ while(--n > 0 && (*++arg)[0] != '-'){
strcat(s, *arg);
strcat(s, (n > 1) ? " " : "");
- }
}
return s;
}
-void getopt(int n, char *arg[]){
+/* uses a 3 bit number to represent options
+ 1 - show list
+ 2 - add to list
+ 4 - remove from list
+*/
+short getopt(int n, char *arg[]){
char *c;
+ short options;
- if (n == 1){
- o = "s";
- return;
- }
+ /* show list if no arguments given */
+ if (n == 1)
+ return 1;
while (--n > 0 && (*++arg)[0] == '-'){
c = malloc(strlen(*arg) * sizeof(char));
c = *arg;
- strcat(o,(strchr(c, 'd')) ? "d" : "n");
- if (strchr(c,'s') != NULL){
- strcat(o,"s");
+ options += strchr(c, 'd') ? 4 : 2;
+ options += strchr(c, 's') ? 1 : 0;
+
+ /* if theres a g then add the next argument as a group */
+ if (strchr(c,'g') != NULL){
+ group = *++arg;
}
free(c);
}
+
+ return options;
}
+
struct task maketask(char *task, char *group){
struct task tmp;
tmp.task = task;
tmp.date = 0;
- tmp.group = group;
+ /* add to all group if group isn't specified */
+ tmp.group = (strcmp(group,"") == 0) ? "all" : group;
return tmp;
}
-struct task gettask(void){
+struct task gettask(FILE *fp){
struct task tmp;
-
- fscanf(fp,"%s\t%i\t%s\n",tmp.task,&tmp.date,tmp.group);
+
+ fscanf(fp,"%s\t%s\t%i\n",tmp.task,tmp.group,&tmp.date);
return tmp;
}
};
char *getnote(int, char *[]);
-void getopt(int, char *[]);
+short getopt(int, char *[]);
void add(struct task, int);
void rem(void);
int geturgency(int);
char *gettime(void);
-void error(char);
-
-int linecount(void);
void dialogue(char *, char *, int);
+void formattask(struct task t);
+void error(int);
+
+int linecount(FILE);
struct task maketask(char *, char *);
void puttask(struct task n);
-struct task gettask(void);
+struct task gettask(FILE *);
char *note, *o;
-int urgency;
FILE *fp;