From f02ffff98932f22b0a253b225b88df2042948231 Mon Sep 17 00:00:00 2001 From: Mike Dvorkin Date: Thu, 22 Jul 2010 23:33:03 -0700 Subject: [PATCH] Streamlined .h files, added command line parsing routines --- Makefile | 19 ++++--- src/activity.c | 2 - src/activity.h | 1 - src/args.c | 102 +++++++++++++++++++++++++++++++++++++ src/db.c | 3 -- src/db.h | 8 --- src/models.h | 58 +++++++++++++++++++++ src/pit.c | 17 ++++--- src/pit.h | 79 +++++++++-------------------- src/project.c | 3 -- src/project.h | 6 --- src/table.c | 1 - src/table.c.out | Bin 14272 -> 0 bytes src/task.c | 130 ++++++++++++++++++++++++++++++++++-------------- src/task.h | 6 --- src/user.c | 2 - src/user.h | 1 - 17 files changed, 299 insertions(+), 139 deletions(-) delete mode 100644 src/activity.h create mode 100644 src/args.c delete mode 100644 src/db.h create mode 100644 src/models.h delete mode 100644 src/project.h delete mode 100755 src/table.c.out delete mode 100644 src/task.h delete mode 100644 src/user.h diff --git a/Makefile b/Makefile index c61aef6..6f297c0 100644 --- a/Makefile +++ b/Makefile @@ -15,6 +15,7 @@ CC = gcc -g -Os -Wall SRC = \ $(SRCDIR)/activity.c \ + $(SRCDIR)/args.c \ $(SRCDIR)/db.c \ $(SRCDIR)/pit.c \ $(SRCDIR)/project.c \ @@ -24,6 +25,7 @@ SRC = \ OBJ = \ $(OBJDIR)/activity.o \ + $(OBJDIR)/args.o \ $(OBJDIR)/db.o \ $(OBJDIR)/pit.o \ $(OBJDIR)/project.o \ @@ -42,25 +44,28 @@ $(OBJDIR): $(APP): $(OBJ) $(CC) -o $(BINDIR)/$(APP) $(OBJ) -$(OBJDIR)/activity.o: $(SRCDIR)/activity.c $(SRCDIR)/activity.h +$(OBJDIR)/activity.o: $(SRCDIR)/activity.c $(SRCDIR)/pit.h $(SRCDIR)/models.h $(SRCDIR)/table.h $(CC) -o $(OBJDIR)/activity.o -c $(SRCDIR)/activity.c -$(OBJDIR)/db.o: $(SRCDIR)/db.c $(SRCDIR)/db.h +$(OBJDIR)/args.o: $(SRCDIR)/args.c $(SRCDIR)/pit.h $(SRCDIR)/models.h $(SRCDIR)/table.h + $(CC) -o $(OBJDIR)/args.o -c $(SRCDIR)/args.c + +$(OBJDIR)/db.o: $(SRCDIR)/db.c $(SRCDIR)/pit.h $(SRCDIR)/models.h $(SRCDIR)/table.h $(CC) -o $(OBJDIR)/db.o -c $(SRCDIR)/db.c -$(OBJDIR)/pit.o: $(SRCDIR)/pit.c $(SRCDIR)/pit.h +$(OBJDIR)/pit.o: $(SRCDIR)/pit.c $(SRCDIR)/pit.h $(SRCDIR)/models.h $(SRCDIR)/table.h $(CC) -o $(OBJDIR)/pit.o -c $(SRCDIR)/pit.c -$(OBJDIR)/project.o: $(SRCDIR)/project.c $(SRCDIR)/project.h +$(OBJDIR)/project.o: $(SRCDIR)/project.c $(SRCDIR)/pit.h $(SRCDIR)/models.h $(SRCDIR)/table.h $(CC) -o $(OBJDIR)/project.o -c $(SRCDIR)/project.c -$(OBJDIR)/table.o: $(SRCDIR)/table.c $(SRCDIR)/table.h +$(OBJDIR)/table.o: $(SRCDIR)/table.c $(SRCDIR)/pit.h $(SRCDIR)/models.h $(SRCDIR)/table.h $(CC) -o $(OBJDIR)/table.o -c $(SRCDIR)/table.c -$(OBJDIR)/task.o: $(SRCDIR)/task.c $(SRCDIR)/task.h +$(OBJDIR)/task.o: $(SRCDIR)/task.c $(SRCDIR)/pit.h $(SRCDIR)/models.h $(SRCDIR)/table.h $(CC) -o $(OBJDIR)/task.o -c $(SRCDIR)/task.c -$(OBJDIR)/user.o: $(SRCDIR)/user.c $(SRCDIR)/user.h +$(OBJDIR)/user.o: $(SRCDIR)/user.c $(SRCDIR)/pit.h $(SRCDIR)/models.h $(SRCDIR)/table.h $(CC) -o $(OBJDIR)/user.o -c $(SRCDIR)/user.c clean: diff --git a/src/activity.c b/src/activity.c index 880c00c..cf542d2 100644 --- a/src/activity.c +++ b/src/activity.c @@ -1,9 +1,7 @@ #include #include #include -#include #include "pit.h" -#include "activity.h" ulong subject_id; /* Reference to the specific Project, Task, or Note. */ char subject[16]; /* Project, Task, or Note. */ diff --git a/src/activity.h b/src/activity.h deleted file mode 100644 index 92b0f59..0000000 --- a/src/activity.h +++ /dev/null @@ -1 +0,0 @@ -PActivity pit_add_activity(ulong id, char *subject, char *message, ulong user_id); diff --git a/src/args.c b/src/args.c new file mode 100644 index 0000000..61b3987 --- /dev/null +++ b/src/args.c @@ -0,0 +1,102 @@ +#include +#include +#include +#include "pit.h" + +int pit_arg_is_option(char **arg) +{ + return *arg && (**arg == '-' || **arg == '/') && strlen(*arg) == 2; +} + +int pit_arg_option(char **arg) +{ + if (pit_arg_is_option(arg)) { + return *(*arg + 1); + } else { + die("invalid option"); + return 0; + } +} + +char *pit_arg_string(char **arg, char *required) +{ + if (required && (!*arg || pit_arg_is_option(arg))) { + die("missing %s", required); + } + + return *arg; +} + +ulong pit_arg_number(char **arg, char *required) +{ + ulong number = 0L; + + if (required && (!*arg || pit_arg_is_option(arg))) { + die("missing %s", required); + } else if (*arg) { + number = atol(*arg); + if (number == 0 && **arg != '0' && required) { + die("invalid %s value: %s", required, *arg); + } + } + + return number; +} + +// char *strptime(const char *restrict buf, const char *restrict format, struct tm *restrict tm); +// time_t mktime ( struct tm * timeptr ); +time_t pit_arg_time(char **arg, char *required) +{ + time_t seconds = (time_t)-1; + struct tm tm; + + + if (required && (!*arg || pit_arg_is_option(arg))) { + die("missing %s", required); + } else { + memset(&tm, 0, sizeof(tm)); + if (strptime(*arg, "%m/%d/%Y", &tm)) { + seconds = mktime(&tm); + } + + if (strchr(*arg, ',')) { /* Date present. */ + if (strchr(*arg, ':')) { /* Date and HH:MM. */ + if (!strstr(*arg, "am") || !strstr(*arg, "pm")) { /* Date and HH:MM am/pm. */ + /* Oct 10, 1992 7:30pm */ + } else { + /* Oct 10, 1992 19:30 */ + } + } else { + if (strlen(*arg) > 12) { /* Date and HH. */ + if (!strstr(*arg, "am") || !strstr(*arg, "pm")) { /* Date and HH am/pm. */ + /* Oct 10, 1992 7pm */ + } else { + /* Oct 10, 1992 19 */ /* HH */ + } + } else { /* Date with no time. */ + /* Oct 10, 1992 19 */ + } + } + } else { /* No date, time only. */ + if (strchr(*arg, ':')) { /* HH:MM. */ + if (!strstr(*arg, "am") || !strstr(*arg, "pm")) { /* HH:MM am/pm. */ + /* 7:30pm */ + } else { + /* 19:30 */ + } + } else { + if (!strstr(*arg, "am") || !strstr(*arg, "pm")) { /* HH am/pm. */ + /* 7pm */ + } else { + /* 19 */ /* HH */ + } + } + } + + if (seconds == (time_t)-1) { + die("invalid %s: %s", required, *arg); + } + } + + return seconds; +} \ No newline at end of file diff --git a/src/db.c b/src/db.c index 7a85e86..a0b3975 100644 --- a/src/db.c +++ b/src/db.c @@ -5,9 +5,6 @@ #include #include #include "pit.h" -#include "db.h" -#include "activity.h" -#include "user.h" #define PITFILE "~/.pit" diff --git a/src/db.h b/src/db.h deleted file mode 100644 index 1c36352..0000000 --- a/src/db.h +++ /dev/null @@ -1,8 +0,0 @@ -#if !defined(__DB_H__) -#define __DB_H__ - -int pit_init(char *argv[]); -void pit_db_load(); -void pit_db_save(); -void pit_db_initialize(); -#endif diff --git a/src/models.h b/src/models.h new file mode 100644 index 0000000..7056501 --- /dev/null +++ b/src/models.h @@ -0,0 +1,58 @@ +#if !defined(__MODELS_H__) +#define __MODELS_H__ + +typedef struct _Project { + ulong id; + char name[128]; /* Project name. */ + char status[16]; /* Project status. */ + ulong number_of_open_tasks; /* Number of open tasks. */ + ulong number_of_closed_tasks; /* Number of closed tasks. */ + ulong closed_by; /* Who closed the project? */ + ulong created_by; /* Who created the project? */ + ulong updated_by; /* Who last updated the project? */ + time_t closed_at; /* When the project was closed? */ + time_t created_at; /* When the project was created? */ + time_t updated_at; /* When the project was last updated? */ +} Project, *PProject; + +typedef struct _Task { + ulong id; + ulong project_id; /* Which project the task belongs to? */ + char name[128]; /* Task name. */ + char status[16]; /* Task status. */ + char priority[16]; /* Task priority. */ + time_t deadline; /* Task deadline. */ + ulong number_of_notes; /* Number of notes. */ + ulong closed_by; /* Who closed the task? */ + ulong created_by; /* Who created the task? */ + ulong updated_by; /* Who last updated the task? */ + time_t closed_at; /* When the task was closed? */ + time_t created_at; /* When the task was created? */ + time_t updated_at; /* When the task was last updated? */ +} Task, *PTask; + +typedef struct _Note { + ulong id; + ulong task_id; /* Task the note belongs to. */ + char message[255]; /* The body of the note. */ + ulong created_by; /* Who created the note? */ + ulong updated_by; /* Who last updated the note? */ + time_t created_at; /* When the note was created? */ + time_t updated_at; /* When the note was last updated? */ +} Note, *PNote; + +typedef struct _Activity { + ulong subject_id; /* Reference to the specific Project, Task, or Note. */ + char subject[16]; /* Project, Task, or Note. */ + char message[255]; /* Log message. */ + ulong created_by; /* Who added log message? */ + time_t created_at; /* When log message was added? */ +} Activity, *PActivity; + +typedef struct _User { + ulong id; + char username[32]; /* Username. */ + char email[32]; /* User's email. */ +} User, *PUser; + +#endif diff --git a/src/pit.c b/src/pit.c index 16efcad..956938e 100644 --- a/src/pit.c +++ b/src/pit.c @@ -1,11 +1,8 @@ #include +#include #include #include -#include #include "pit.h" -#include "db.h" -#include "project.h" -#include "task.h" PTable projects; PTable tasks; @@ -21,12 +18,18 @@ static int usage() { /* ** Suicide. */ -void die(char *msg) +void die(char *message, ...) { - fprintf(stderr, "pit: %s\n", msg); + char str[4096]; + va_list params; + + va_start(params, message); + vsnprintf(str, sizeof(str), message, params); + fprintf(stderr, "pit: %s\n", str); + va_end(params); + exit(0); } - /* ** Forceful death. */ diff --git a/src/pit.h b/src/pit.h index d1c6bcc..66ff43b 100644 --- a/src/pit.h +++ b/src/pit.h @@ -5,69 +5,38 @@ typedef unsigned int uint; typedef unsigned long ulong; typedef unsigned char uchar; +#include +#include "models.h" #include "table.h" -typedef struct _Project { - ulong id; - char name[128]; /* Project name. */ - char status[16]; /* Project status. */ - ulong number_of_open_tasks; /* Number of open tasks. */ - ulong number_of_closed_tasks; /* Number of closed tasks. */ - ulong closed_by; /* Who closed the project? */ - ulong created_by; /* Who created the project? */ - ulong updated_by; /* Who last updated the project? */ - time_t closed_at; /* When the project was closed? */ - time_t created_at; /* When the project was created? */ - time_t updated_at; /* When the project was last updated? */ -} Project, *PProject; - -typedef struct _Task { - ulong id; - ulong project_id; /* Which project the task belongs to? */ - int priority; /* Task priority. */ - char name[128]; /* Task name. */ - char status[16]; /* Task status. */ - time_t deadline; /* Task deadline. */ - ulong number_of_notes; /* Number of notes. */ - ulong closed_by; /* Who closed the task? */ - ulong created_by; /* Who created the task? */ - ulong updated_by; /* Who last updated the task? */ - time_t closed_at; /* When the task was closed? */ - time_t created_at; /* When the task was created? */ - time_t updated_at; /* When the task was last updated? */ -} Task, *PTask; - -typedef struct _Note { - ulong id; - ulong task_id; /* Task the note belongs to. */ - char message[255]; /* The body of the note. */ - ulong created_by; /* Who created the note? */ - ulong updated_by; /* Who last updated the note? */ - time_t created_at; /* When the note was created? */ - time_t updated_at; /* When the note was last updated? */ -} Note, *PNote; - -typedef struct _Activity { - ulong subject_id; /* Reference to the specific Project, Task, or Note. */ - char subject[16]; /* Project, Task, or Note. */ - char message[255]; /* Log message. */ - ulong created_by; /* Who added log message? */ - time_t created_at; /* When log message was added? */ -} Activity, *PActivity; - -typedef struct _User { - ulong id; - char username[32]; /* Username. */ - char email[32]; /* User's email. */ -} User, *PUser; - +/* Externals. */ extern PTable projects; extern PTable tasks; extern PTable notes; extern PTable activities; extern PTable users; -void die(char *msg); +/* Command line parsing. */ +int pit_arg_is_option(char **arg); +int pit_arg_option(char **arg); +char *pit_arg_string(char **arg, char *required); +ulong pit_arg_number(char **arg, char *required); +time_t pit_arg_time(char **arg, char *required); + +/* Database. */ +int pit_init(char *argv[]); +void pit_db_load(); +void pit_db_save(); +void pit_db_initialize(); + +/* Models. */ +int pit_project(char *argv[]); +int pit_task(char *argv[]); +char *pit_current_user(); +PActivity pit_add_activity(ulong id, char *subject, char *message, ulong user_id); + +/* Utilities. */ +void die(char *msg, ...); void perish(char *prefix); #endif diff --git a/src/project.c b/src/project.c index 731cfad..afb51cf 100644 --- a/src/project.c +++ b/src/project.c @@ -1,10 +1,7 @@ #include #include #include -#include #include "pit.h" -#include "db.h" -#include "project.h" static int already_exist(char *name) { diff --git a/src/project.h b/src/project.h deleted file mode 100644 index 0857fb0..0000000 --- a/src/project.h +++ /dev/null @@ -1,6 +0,0 @@ -#if !defined(__PROJECT_H__) -#define __PROJECT_H__ - -int pit_project(char *argv[]); - -#endif diff --git a/src/table.c b/src/table.c index e3f880a..e55eee4 100644 --- a/src/table.c +++ b/src/table.c @@ -1,7 +1,6 @@ #include #include #include -#include #include "pit.h" #define TABLE_INCREMENT 10 diff --git a/src/table.c.out b/src/table.c.out deleted file mode 100755 index b174e0d414bbfc8b133f50ce8923d3cc434b41db..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 14272 zcmeHOeQ;FO6~Au@8e=4j1Dc}3ibMk1;B*>0^u%1(ZSYx!HXotDDWv?%S|9 z#-UxYd9z02v{UJqLu*GF>sYiMKNt-OAPH*iN|k0DM>E!To|D)~)!IlY+uynOzWoYd z+JE}b-r?SR&bjBFbM86!o=fiT{^8hXC(dL{nZek07h~*fRCWeqJE%wb7OIA->n)An zQ8%f#t|e+=Q3}zMVkD;)3UqzFx^aCW3!m>Pq%n!ZHZ~I#Ch?-{rjalug05KJ`YJ32 zbQfO;V}#SXvZah|&%yw7J+`f*wKJs0%y{dSQ{~+@PsrOOCpowyqg=|%*++u(b|Vxq zqFjFAdiO|qPe}oU7nCXX`D11@7~Ue8ir2gG0%2c|948#H%$9<+gR1NC@YY~Bpa;Wk zog6Q;Z&b>QNC||OWu;98blqsz+oHY>LyQ&M*K(n-Z?`mx@O=9arn~c{(mv@y0CjzJ z!>I7m3q8A-RsNx*kSMMQ9^t^px_dg%n2nE#FrZPi&oR(e;q;bn>b_ z!oGx@L3qAAvhQ3uMxCxlqMcjdH@(XjjZIzeE{~8`E9VeS=ipRD*8@J&mm4ki->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hFH~y_dbG#C%-_`$!3OV)>sa%oQ|) zzEJQ!gFUCj3>f$(e!bC$2Q(Mr#0Hh9VX*f>8eIe(uhpQjYtg)PIhv!?>{yEC18NRk zf#!ueMTaNYKQL!!JqRc8*z58$%hkmmam`@Eji9Be8KGvhksL%Tn1zR#>)hg9rdr}Y ziC-@9XC>Yw@wX*TUni&ecuVH*MXeI2cV&?AkS)gPeVOoH)cJVda(+MYQyM=D@1Gtq z{!8Fh_@;{UPV|h#o%f;_Bt9zn>GP8r^2Y=u{|Jo(c;S2@Z$#qNSQw3eOgQ8_?@nWK z`~f-scZt(GIPuf7Ey=?hImgeF_}vn}RN^zw6XVxPoZi;~vSx|nZJpzHN&JxH4@>;0 z)c1hI@08<@NZk2;_z!{Szx6*^gg;+|AK*Aw4Qm)XS~UJ)5srOXAb-3F|Dp&#R)o`r z%D1n)2zM9Z)kXOHBK)!<{0ffe)`RCp{&~bj=;`g*gL*OQLexu87opamUW$4dDt%_M z7)ReW8@k37G`LY<~V4f$dw5|zIbS$PU0rR9V}=9~o- z{7%Y1LO^~GhC{)yL7CCX&jrM6Cil>9mptOPOEIQL_)k-Gp5OdT^j##6e!9XlnXXSw zbUM$Dyya;{ck-gn^QE3kq)wvCBgrI~M`@#^mXA|<%fo}=Y&tBU^30e=;n_0}=eacx z=Sfy1e5^44eiLY(=W^F2ztb?DqlgRCx!}ar=3Hv>I+GU}by$hKyqs&xxv<1lmA#|H K #include #include -#include #include "pit.h" -#include "db.h" -#include "task.h" -static void list_tasks() +/* +** CREATING TASKS: +** pit task -c name [-s status] [-d deadline] [-p priority] +** +** UPDATING TASKS: +** pit task -u [number] [-n name] [-s status] [-d deadline] [-p priority] +** +** DELETING TASKS: +** pit task -d [number] +** +** SHOWING TASK: +** pit task [-s number] +** +** LISTING TASKS: +** pit task -s [all|open|closed] [-s status] [-d deadline] [-p priority] +*/ +static void list_tasks(char *mode, char *status, char *deadline, ulong priority) { pit_db_load(); @@ -22,7 +35,7 @@ static void list_tasks() } } -static void create_task(char *name, char *status) +static void create_task(char *name, char *status, char *priority, time_t deadline) { pit_db_load(); @@ -38,13 +51,17 @@ static void create_task(char *name, char *status) if (!status) { status = "open"; } - printf("creating task [%s], status [%s]\n", name, status); + if (!priority) { + priority = "normal"; + } + + printf("creating task: %s, status: %s, priority: %s, deadline: %s", name, status, priority, ctime(&deadline)); strncpy(t.name, name, sizeof(t.name) - 1); strncpy(t.status, status, sizeof(t.status) - 1); + strncpy(t.priority, priority, sizeof(t.priority) - 1); t.project_id = pp->id; - t.priority = 1; - t.deadline = time(NULL); + t.deadline = deadline; t.number_of_notes = 0; t.closed_by = 0; t.created_by = t.updated_by = 1; // TODO @@ -58,49 +75,88 @@ static void create_task(char *name, char *status) } } -static int show_task(ulong number) +static void show_task(ulong number) { - return 1; + printf("show_task(%lu)\n", number); } -static int delete_task(ulong number) +static void delete_task(ulong number) { - return 1; + printf("delete_task(%lu)\n", number); +} + +static void update_task(ulong number, char *name, char *status, char *priority, time_t deadline) +{ + printf("update task: #%lu, name: %s, status: %s, priority: %s, deadline: %s", number, name, status, priority, ctime(&deadline)); } int pit_task(char *argv[]) { char **arg = &argv[1]; - unsigned long number; + char *name = NULL, *status = NULL, *priority = NULL; + time_t deadline = (time_t)0; + ulong number = 0; if (!*arg) { - list_tasks(); - } else if (!strcmp(*arg, "-c")) { - if (!*++arg) { - die("missing task name"); - } else { - create_task(*arg, *(arg + 1)); - } - } else if (!strcmp(*arg, "-d")) { - if (!*++arg) { - die("missing task number"); - } else { - number = atoi(*arg); - if (!number) { - die("invalid task number"); - } else { - delete_task(number); - } - } - /* } else if (!strcmp(*arg, "-e")) { TODO: Edit */ + list_tasks(NULL, NULL, NULL, 0); /* ...with default paramaters. */ } else { - number = atoi(*arg); - if (!number) { - die("invalid task parameters"); - } else { + switch(pit_arg_option(arg)) { + case 'c': /* pit task -c name [-s status] [-p priority] [-d deadline] */ + name = pit_arg_string(++arg, "task name"); + while(*++arg) { + switch(pit_arg_option(arg)) { + case 's': + status = pit_arg_string(++arg, "task status"); + break; + case 'p': + priority = pit_arg_string(++arg, "task priority"); + break; + case 'd': + deadline = pit_arg_time(++arg, "task deadline"); + break; + default: + die("invalid task option: %s", *arg); + } + } + create_task(name, status, priority, deadline); + break; + case 'u': /* pit task -u [number] [-n name] [-s status] [-d deadline] [-p priority] */ + number = pit_arg_number(++arg, NULL); + if (!number) --arg; + while(*++arg) { + switch(pit_arg_option(arg)) { + case 'n': + name = pit_arg_string(++arg, "task name"); + break; + case 's': + status = pit_arg_string(++arg, "task status"); + break; + case 'p': + priority = pit_arg_string(++arg, "task priority"); + break; + case 'd': + deadline = pit_arg_time(++arg, "task deadline"); + break; + default: + die("invalid task option: %s", *arg); + } + } + if (!name && !status && !priority && !deadline) { + die("nothing to update"); + } else { + update_task(number, name, status, priority, deadline); + } + break; + case 'd': /* pit task -d [number] */ + number = pit_arg_number(++arg, NULL); + delete_task(number); + break; + case 's': /* pit task -s [all|open|closed] [-s status] [-d deadline] [-p priority] */ + break; + default: /* pit task [number] */ + number = pit_arg_number(++arg, NULL); show_task(number); } } - return 1; } diff --git a/src/task.h b/src/task.h deleted file mode 100644 index aff477c..0000000 --- a/src/task.h +++ /dev/null @@ -1,6 +0,0 @@ -#if !defined(__TASK_H__) -#define __TASK_H__ - -int pit_task(char *argv[]); - -#endif diff --git a/src/user.c b/src/user.c index 786667e..5dc6e84 100644 --- a/src/user.c +++ b/src/user.c @@ -1,10 +1,8 @@ #include #include #include -#include #include #include "pit.h" -#include "user.h" char *pit_current_user() { return getlogin(); diff --git a/src/user.h b/src/user.h deleted file mode 100644 index 37a7f20..0000000 --- a/src/user.h +++ /dev/null @@ -1 +0,0 @@ -char *pit_current_user(); \ No newline at end of file