Modified parse_args and other functs to task struct TODO: broke things
This commit is contained in:
parent
7f15e44f29
commit
52eff82c03
80
src/dodo.c
80
src/dodo.c
@ -182,9 +182,7 @@ void display_column_headings_for_all_task_lists(){
|
|||||||
|
|
||||||
// Print Heading
|
// Print Heading
|
||||||
void display_heading(){
|
void display_heading(){
|
||||||
char* colnames = "active_id,title,due_date";
|
|
||||||
char * str;
|
char * str;
|
||||||
int width = 0;
|
|
||||||
|
|
||||||
printf("\n");
|
printf("\n");
|
||||||
str = "Today";
|
str = "Today";
|
||||||
@ -201,13 +199,13 @@ void display_heading(){
|
|||||||
// pass in the args and return the title and due date
|
// pass in the args and return the title and due date
|
||||||
// due date passed as NULL if for delete
|
// due date passed as NULL if for delete
|
||||||
// TODO input validation for strings implement in strings!
|
// TODO input validation for strings implement in strings!
|
||||||
int parse_args(int argc, char** argv, char** title, char** due_date){
|
int parse_args(int argc, char** argv, filtered_tasks* task){
|
||||||
if ( argc > 2 ){
|
if ( argc > 2 ){
|
||||||
*title = argv[2];
|
x_strcpy(task->title, argv[2], ARG_MAX);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( argc > 3 ){
|
if ( argc > 3 ){
|
||||||
*due_date = argv[3];
|
x_strcpy(task->due_date, argv[3], ARG_MAX);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -339,6 +337,7 @@ int view_tasks(sqlite3 *db){
|
|||||||
|
|
||||||
// Set the table and cols to be printed
|
// Set the table and cols to be printed
|
||||||
filtered_tasks* tasks = malloc(sizeof(filtered_tasks));
|
filtered_tasks* tasks = malloc(sizeof(filtered_tasks));
|
||||||
|
// TODO check that malloc is ok
|
||||||
x_strcpy(tasks->table, "tasks", ARG_MAX);
|
x_strcpy(tasks->table, "tasks", ARG_MAX);
|
||||||
x_strcpy(tasks->selected_columns, "active_id, title, due_date", ARG_MAX);
|
x_strcpy(tasks->selected_columns, "active_id, title, due_date", ARG_MAX);
|
||||||
|
|
||||||
@ -349,47 +348,54 @@ int view_tasks(sqlite3 *db){
|
|||||||
// Print "today" tasks
|
// Print "today" tasks
|
||||||
x_strcpy(tasks->status, "today", ARG_MAX);
|
x_strcpy(tasks->status, "today", ARG_MAX);
|
||||||
if ( display_task_list(TODAY_COL_START, db, tasks) ){
|
if ( display_task_list(TODAY_COL_START, db, tasks) ){
|
||||||
|
free(tasks);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Print "backlog" tasks
|
// Print "backlog" tasks
|
||||||
x_strcpy(tasks->status, "backlog", ARG_MAX);
|
x_strcpy(tasks->status, "backlog", ARG_MAX);
|
||||||
if ( display_task_list(BACKLOG_COL_START, db, tasks) ){
|
if ( display_task_list(BACKLOG_COL_START, db, tasks) ){
|
||||||
|
free(tasks);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Print "blocked" tasks
|
// Print "blocked" tasks
|
||||||
x_strcpy(tasks->status, "blocked", ARG_MAX);
|
x_strcpy(tasks->status, "blocked", ARG_MAX);
|
||||||
if ( display_task_list(BLOCKED_COL_START, db, tasks) ){
|
if ( display_task_list(BLOCKED_COL_START, db, tasks) ){
|
||||||
|
free(tasks);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
free(tasks);
|
free(tasks);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: the way this ensures that we are only passing in
|
// TODO: the way this ensures that we are only passing in
|
||||||
// valid inputs is stupid and ugly FIX
|
// valid inputs is stupid and ugly FIX
|
||||||
int add_new_task(sqlite3 *db, int argc, char** argv){
|
int add_new_task(sqlite3 *db, int argc, char** argv){
|
||||||
|
|
||||||
int rc = 0;
|
int rc = 0;
|
||||||
char* table = "tasks";
|
|
||||||
char* title = NULL;
|
|
||||||
char* due_date = NULL;
|
|
||||||
char* colnames = "(title, due_date)";
|
|
||||||
char values[100];
|
char values[100];
|
||||||
sqlite3_stmt* out_stmt;
|
sqlite3_stmt* out_stmt;
|
||||||
|
|
||||||
parse_args(argc, argv, &title, &due_date);
|
filtered_tasks* task = malloc(sizeof(filtered_tasks));
|
||||||
|
x_strcpy(task->table, "tasks", ARG_MAX);
|
||||||
|
task->title[0] = '\0';
|
||||||
|
task->due_date[0] = '\0';
|
||||||
|
|
||||||
if ( due_date != NULL ){
|
parse_args(argc, argv, task);
|
||||||
snprintf(values, 100, "('%s', '%s')", title, due_date);
|
|
||||||
|
if ( task->title[0] != '\0' ){
|
||||||
|
if ( task->due_date[0] != '\0' ){
|
||||||
|
x_strcpy(task->selected_columns, "(title, due_date)", ARG_MAX);
|
||||||
|
snprintf(values, 100, "('%s', '%s')", task->title, task->due_date);
|
||||||
}else{
|
}else{
|
||||||
colnames = "(title)";
|
x_strcpy(task->selected_columns, "(title)", ARG_MAX);
|
||||||
snprintf(values, 100, "('%s')", title);
|
snprintf(values, 100, "('%s')", task->title);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( gen_sql_insert_stmt(db, &out_stmt, table, colnames, values) ){
|
if ( gen_sql_insert_stmt(db, &out_stmt, task->table, task->selected_columns, values) ){
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if ( ( rc = sqlite3_step(out_stmt) ) == SQLITE_DONE){
|
if ( ( rc = sqlite3_step(out_stmt) ) == SQLITE_DONE){
|
||||||
@ -403,20 +409,27 @@ int add_new_task(sqlite3 *db, int argc, char** argv){
|
|||||||
|
|
||||||
int update_task_status(sqlite3 *db, int argc, char** argv){
|
int update_task_status(sqlite3 *db, int argc, char** argv){
|
||||||
int rc = 0;
|
int rc = 0;
|
||||||
char* table = "tasks";
|
|
||||||
char* title_or_active_id;
|
|
||||||
sqlite3_stmt* out_stmt;
|
sqlite3_stmt* out_stmt;
|
||||||
parse_args(argc, argv, &title_or_active_id, NULL);
|
filtered_tasks* task = malloc(sizeof(filtered_tasks));
|
||||||
|
|
||||||
if ( gen_sql_update_stmt(db, &out_stmt, table, argv[1], title_or_active_id) ){
|
x_strcpy(task->table, "tasks", ARG_MAX);
|
||||||
|
|
||||||
|
// TODO: this is not just title but also active ID so fix this
|
||||||
|
parse_args(argc, argv, task);
|
||||||
|
|
||||||
|
if ( gen_sql_update_stmt(db, &out_stmt, task->table, argv[1], task->title) ){
|
||||||
|
free(task);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( ( rc = sqlite3_step(out_stmt) ) == SQLITE_DONE){
|
if ( ( rc = sqlite3_step(out_stmt) ) == SQLITE_DONE){
|
||||||
|
free(task);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
checksqlerr(rc, "broken in update_task_status");
|
checksqlerr(rc, "broken in update_task_status");
|
||||||
|
|
||||||
|
free(task);
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -424,20 +437,26 @@ int update_task_status(sqlite3 *db, int argc, char** argv){
|
|||||||
|
|
||||||
int complete_task(sqlite3 *db, int argc, char** argv){
|
int complete_task(sqlite3 *db, int argc, char** argv){
|
||||||
int rc = 0;
|
int rc = 0;
|
||||||
char* table = "tasks";
|
|
||||||
char* title;
|
|
||||||
sqlite3_stmt* out_stmt;
|
sqlite3_stmt* out_stmt;
|
||||||
|
filtered_tasks* task = malloc(sizeof(filtered_tasks));
|
||||||
|
|
||||||
parse_args(argc, argv, &title, NULL);
|
x_strcpy(task->table, "tasks", ARG_MAX);
|
||||||
if ( gen_sql_update_stmt(db, &out_stmt, table, NULL, title) ){
|
|
||||||
|
parse_args(argc, argv, task);
|
||||||
|
if ( gen_sql_update_stmt(db, &out_stmt, task->table, NULL, task->title) ){
|
||||||
|
free(task);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if ( ( rc = sqlite3_step(out_stmt) ) == SQLITE_DONE){
|
if ( ( rc = sqlite3_step(out_stmt) ) == SQLITE_DONE){
|
||||||
|
free(task);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
checksqlerr(rc, "broken in complete_task");
|
checksqlerr(rc, "broken in complete_task");
|
||||||
|
|
||||||
|
free(task);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -467,19 +486,24 @@ int update_task(sqlite3 *db, int argc, char** argv){
|
|||||||
|
|
||||||
int del_task(sqlite3 *db, int argc, char** argv){
|
int del_task(sqlite3 *db, int argc, char** argv){
|
||||||
int rc = 0;
|
int rc = 0;
|
||||||
char* table = "tasks";
|
|
||||||
char* title;
|
|
||||||
sqlite3_stmt* out_stmt;
|
sqlite3_stmt* out_stmt;
|
||||||
|
filtered_tasks* task = malloc(sizeof(filtered_tasks));
|
||||||
|
|
||||||
parse_args(argc, argv, &title, NULL);
|
x_strcpy(task->table, "tasks", ARG_MAX);
|
||||||
if ( gen_sql_delete_stmt(db, &out_stmt, table, title) ){
|
|
||||||
|
parse_args(argc, argv, task);
|
||||||
|
if ( gen_sql_delete_stmt(db, &out_stmt, task->table, task->title) ){
|
||||||
|
free(task);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( ( rc = sqlite3_step(out_stmt) ) == SQLITE_DONE){
|
if ( ( rc = sqlite3_step(out_stmt) ) == SQLITE_DONE){
|
||||||
|
free(task);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
checksqlerr(rc, "broken in del_task");
|
checksqlerr(rc, "broken in del_task");
|
||||||
|
|
||||||
|
free(task);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -29,8 +29,8 @@ typedef struct {
|
|||||||
int active_id;
|
int active_id;
|
||||||
char status[ARG_MAX];
|
char status[ARG_MAX];
|
||||||
char project_tag[ARG_MAX];
|
char project_tag[ARG_MAX];
|
||||||
date creation_date;
|
char creation_date[ARG_MAX];
|
||||||
date due_date;
|
char due_date[ARG_MAX];
|
||||||
}filtered_tasks;
|
}filtered_tasks;
|
||||||
|
|
||||||
|
|
||||||
@ -48,7 +48,7 @@ int gen_sql_select_stmt(sqlite3 *db, sqlite3_stmt** out_stmt, filtered_tasks* ta
|
|||||||
int checksqlerr(int rc, char *errmsg);
|
int checksqlerr(int rc, char *errmsg);
|
||||||
int opendb(sqlite3 **db, char* filename);
|
int opendb(sqlite3 **db, char* filename);
|
||||||
void display_heading();
|
void display_heading();
|
||||||
int parse_args(int argc, char** argv, char** title, char** due_date);
|
int parse_args(int argc, char** argv, filtered_tasks* task);
|
||||||
int get_num_rows(sqlite3 *db, char* table, char* status);
|
int get_num_rows(sqlite3 *db, char* table, char* status);
|
||||||
int print_fixed_width(const unsigned char* str, int width);
|
int print_fixed_width(const unsigned char* str, int width);
|
||||||
int display_task_list(int start_col, sqlite3 *db, filtered_tasks*);
|
int display_task_list(int start_col, sqlite3 *db, filtered_tasks*);
|
||||||
|
Loading…
Reference in New Issue
Block a user