From 62a1565137992a8b50c5728a34db3129b6c6464e Mon Sep 17 00:00:00 2001 From: xavi Date: Tue, 17 Sep 2024 20:54:34 -0700 Subject: [PATCH] Modified the rest of the main functions to use struct TODO: update is broke --- Makefile | 4 ++-- src/dodo.c | 60 +++++++++++++++++++++++++++++++++++------------------- src/dodo.h | 5 ++--- src/xlibc | 2 +- 4 files changed, 44 insertions(+), 27 deletions(-) diff --git a/Makefile b/Makefile index a420fa5..5f1da19 100644 --- a/Makefile +++ b/Makefile @@ -43,10 +43,10 @@ all: dodo $(OBJ): $(SRC) $(X_STRING_OBJ) $(SQLITE_OBJ) $(HEADERS) $(CC) -c -o $(OBJ_DIR)/$(@F) $(INC_DIRS) $(CFLAGS) $(DFLAGS) $(SRC_DIR)/$(@F:.o=.c) -$(X_STRING_OBJ): $(X_STRING_HEADERS) +$(X_STRING_OBJ): $(X_STRING_SRC) $(X_STRING_HEADERS) $(CC) -c -o $(OBJ_DIR)/$(@F) $(CFLAGS) $(X_STRING_SRC) -$(SQLITE_OBJ): $(SQLITE_HEADERS) +$(SQLITE_OBJ): $(SQLITE_SRC) $(SQLITE_HEADERS) $(CC) -c -o $(OBJ_DIR)/$(@F) $(CFLAGS) $(SQLITE_SRC) dodo: test $(OBJ) $(X_STRING_OBJ) $(SQLITE_OBJ) diff --git a/src/dodo.c b/src/dodo.c index 40eee5a..da191bc 100644 --- a/src/dodo.c +++ b/src/dodo.c @@ -199,32 +199,49 @@ void display_heading(){ // pass in the args and return the title and due date // due date passed as NULL if for delete // TODO input validation for strings implement in strings! +// TODO maybe a Abstract Sytnax Tree for parsing int parse_args(int argc, char** argv, filtered_tasks* task){ + if ( argc > 2 ){ x_strcpy(task->title, argv[2], ARG_MAX); } if ( argc > 3 ){ - x_strcpy(task->due_date, argv[3], ARG_MAX); + if ( x_strcmp(argv[1], "update") ){ + x_strcpy(task->due_date, argv[3], ARG_MAX); + return 0; + } + else{ + x_strcpy(task->new_title, argv[3], ARG_MAX); + } } -} - -int parse_args_v2(int argc, char** argv, char** title, char** new_title, char** new_due_date, char** new_project_tag){ - if ( argc > 2 ){ - *title = argv[2]; - } - if ( argc > 3 ){ - *new_title = argv[3]; - } if ( argc > 4 ){ - *new_due_date = argv[4]; + x_strcpy(task->due_date, argv[4], ARG_MAX); } + if ( argc > 5 ){ - *new_project_tag = argv[5]; + x_strcpy(task->project_tag, argv[5], ARG_MAX); } + + return 0; } +//int parse_args_v2(int argc, char** argv, char** title, char** new_title, char** new_due_date, char** new_project_tag){ +// if ( argc > 2 ){ +// *title = argv[2]; +// } +// if ( argc > 3 ){ +// *new_title = argv[3]; +// } +// if ( argc > 4 ){ +// *new_due_date = argv[4]; +// } +// if ( argc > 5 ){ +// *new_project_tag = argv[5]; +// } +//} + // Get number of tasks from tasks table give status int get_num_rows(sqlite3 *db, char* table, char* status){ filtered_tasks* task = malloc(sizeof(filtered_tasks)); @@ -340,7 +357,6 @@ int view_tasks(sqlite3 *db){ // TODO check that malloc is ok x_strcpy(tasks->table, "tasks", ARG_MAX); x_strcpy(tasks->selected_columns, "active_id, title, due_date", ARG_MAX); - // Print Heading display_heading(); @@ -375,7 +391,7 @@ int view_tasks(sqlite3 *db){ int add_new_task(sqlite3 *db, int argc, char** argv){ int rc = 0; - char values[100]; + char values[ARG_MAX]; sqlite3_stmt* out_stmt; filtered_tasks* task = malloc(sizeof(filtered_tasks)); @@ -463,23 +479,25 @@ int complete_task(sqlite3 *db, int argc, char** argv){ // TODO this can definatly be made into one func with all the other updates int update_task(sqlite3 *db, int argc, char** argv){ int rc = 0; - char* table = "tasks"; - char* title; - char* new_title; - char* new_due_date; - char* new_project_tag; sqlite3_stmt* out_stmt; + filtered_tasks* task = malloc(sizeof(filtered_tasks)); - parse_args_v2(argc, argv, &title, &new_title, &new_due_date, &new_project_tag); - if ( gen_sql_update_stmt_v2(db, &out_stmt, table, new_title, new_due_date, new_project_tag, title) ){ + x_strcpy(task->table, "task", ARG_MAX); + + parse_args(argc, argv, task); + if ( gen_sql_update_stmt_v2(db, &out_stmt, task->table, task->new_title, task->due_date, task->project_tag, task->title) ){ + free(task); return -1; } if ( ( rc = sqlite3_step(out_stmt) ) == SQLITE_DONE){ + free(task); return 0; } checksqlerr(rc, "broken in complete_task"); + + free(task); return -1; } diff --git a/src/dodo.h b/src/dodo.h index 132dab9..bbbf5dc 100644 --- a/src/dodo.h +++ b/src/dodo.h @@ -13,6 +13,7 @@ #define TODAY_COL_START -1 #define BACKLOG_COL_START (FIXED_COLUMN_WIDTH + 1) #define BLOCKED_COL_START (2 * (FIXED_COLUMN_WIDTH + 1)) +#define DUEPARSE_SIZE 4 typedef struct{ int year; @@ -23,9 +24,9 @@ typedef struct{ // Filters for sql selection typedef struct { char table[ARG_MAX]; - int task_id; char selected_columns[ARG_MAX]; char title[ARG_MAX]; + char new_title[ARG_MAX]; int active_id; char status[ARG_MAX]; char project_tag[ARG_MAX]; @@ -59,8 +60,6 @@ int add_new_task(sqlite3 *db, int argc, char** argv); int update_task_status(sqlite3 *db, int argc, char** argv); int complete_task(sqlite3 *db, int argc, char** argv); int update_task(sqlite3 *db, int argc, char** argv); - - int del_task(sqlite3 *db, int argc, char** argv); #endif diff --git a/src/xlibc b/src/xlibc index 787bf40..4fb48e6 160000 --- a/src/xlibc +++ b/src/xlibc @@ -1 +1 @@ -Subproject commit 787bf40377a6f490729a02ba1c680c0b85e4f318 +Subproject commit 4fb48e69126058c09a93a102970d182db3be31b9