diff --git a/src/help.c b/src/help.c index 8a2eeaf..7bc349d 100644 --- a/src/help.c +++ b/src/help.c @@ -72,7 +72,7 @@ static void help_task() "Viewing a task:\n", " pit task [[-q] number]\n", "Searching tasks:\n", - " pit task -q [number | [-n name] [-s status] [-p priority] [-d date] [-t time]]\n", + " pit task -q [number | [-n name] [-s status] [-p priority] [-d date-from] [-D date-to] [-t time-min] [-T time-max]]\n", "Supported date formats:\n", " none, 4/26, 4/26/2012, 4/26/12, '4/26 3pm', '4/26 19:30', '4/26/2012 3:15am', '4/26/12 17:00'", " 'Apr 26', 'Apr 26, 2012', 'Apr 26 3pm', 'Apr 26 19:30', 'Apr 26, 12 3:15am', 'Apr 26, 2012 17:00'\n", diff --git a/src/object.h b/src/object.h index 02f99cc..d03c3e7 100644 --- a/src/object.h +++ b/src/object.h @@ -36,8 +36,9 @@ typedef struct _Task { typedef struct _Note { int id; - int task_id; /* Task the note belongs to. */ - char username[32]; /* User the note belongs to. */ + int project_id; /* Project the note belongs to (0 if belongs to task). */ + int task_id; /* Task the note belongs to (0 if belongs to project). */ + char username[32]; /* User who created the note. */ char message[255]; /* The body of the note. */ time_t created_at; /* When the note was created? */ time_t updated_at; /* When the note was last updated? */ @@ -59,7 +60,9 @@ typedef union _Options { char *status; char *priority; time_t date; + time_t date_max; time_t time; + time_t time_max; } task; struct { int id; diff --git a/src/pit.h b/src/pit.h index 17346d2..99df69d 100644 --- a/src/pit.h +++ b/src/pit.h @@ -75,6 +75,7 @@ void perish(char *prefix); char *str2str(char *str); char *mem2str(char *mem, int len); bool is_zero(char *mem, int len); +char *stristr(char *haystack, char *needle); void printa(char *msg[]); char *current_user(); char *home_dir(char *username, int len); diff --git a/src/task.c b/src/task.c index e92caa3..2e1bf80 100644 --- a/src/task.c +++ b/src/task.c @@ -163,15 +163,25 @@ static void task_parse_options(char **arg, POptions po) case 'd': po->task.date = pit_arg_date(++arg, "task date"); break; + case 'D': + po->task.date_max = pit_arg_date(++arg, "task end date"); + break; case 't': po->task.time = pit_arg_time(++arg, "task time"); break; + case 'T': + po->task.time_max = pit_arg_time(++arg, "task max time"); + break; default: die("invalid task option: %s", *arg); } } } +/* +** Display a list of tasks based on any combination of name, status, priority, +** date, time. If the project is set the search results get scoped by the project. +*/ void pit_task_list(POptions po, PProject pp) { if (!tasks) pit_db_load(); @@ -181,7 +191,14 @@ void pit_task_list(POptions po, PProject pp) if (!pp) pp = (PProject)pit_table_current(projects); for_each_task(pt) { - if (pp && pt->project_id != pp->id) + if ((pp && pt->project_id != pp->id) || + (po->task.name && !stristr(pt->name, po->task.name)) || + (po->task.status && !stristr(pt->status, po->task.status)) || + (po->task.priority && !stristr(pt->priority, po->task.priority)) || + (po->task.date && pt->date < po->task.date) || + (po->task.date_max && pt->date > po->task.date_max) || + (po->task.time && pt->time < po->task.time) || + (po->task.time_max && pt->time > po->task.time_max)) continue; pit_pager_print(ppager, (char *)pt); } @@ -252,7 +269,7 @@ void pit_task_delete(int id, PProject pp) ** pit task [[-q] number] ** ** LISTING TASKS: -** pit task -q [number | [-n name] [-s status] [-p priority] [-d date] [-t time]] +** pit task -q [number | [-n name] [-s status] [-p priority] [-d date] [-D date] [-t time] [-T time]] */ void pit_task(char *argv[]) { diff --git a/src/util.c b/src/util.c index 3d760e0..82dbe61 100644 --- a/src/util.c +++ b/src/util.c @@ -1,6 +1,7 @@ #include #include #include +#include #include #include #include @@ -27,6 +28,22 @@ bool is_zero(char *mem, int len) { return TRUE; } +char *stristr(char *haystack, char *needle) +{ + char *start, *pn, *ps; + + for (start = haystack; *start; start++) { + for (; (*start && (toupper(*start) != toupper(*needle))); start++) ; + if (!*start) return NULL; + + ps = start; pn = needle; + while (toupper(*ps++) == toupper(*pn++)) { + if (!*pn) return start; + } + } + return NULL; +} + void printa(char *msg[]) { while(*msg) puts(*msg++); }