diff --git a/src/dodo.c b/src/dodo.c index db4b5a2..0edf8f7 100644 --- a/src/dodo.c +++ b/src/dodo.c @@ -32,11 +32,11 @@ int gen_sql_update_stmt_v2(sqlite3 *db, sqlite3_stmt** out_stmt, filtered_tasks* char sql_query[SQLQUERY_MAX]; int rc = 0; - if (task->new_title[0] != '\0' && task->due_date[0] != '\0'){ + if (task->new_title != NULL && task->due_date[0] != '\0'){ //snprintf(sql_query, SQLQUERY_MAX, "UPDATE %s SET title='%s', due_date='%s', project_tag='%s' WHERE title='%s' OR active_id='%s'", table, status, title_or_active_id, title_or_active_id); snprintf(sql_query, SQLQUERY_MAX, "UPDATE %s SET title='%s', due_date='%s' WHERE title='%s' OR active_id='%d'", task->table, task->new_title, task->due_date, task->title, task->active_id); } - else if (task->new_title[0] != '\0'){ + else if (task->new_title != NULL){ snprintf(sql_query, SQLQUERY_MAX, "UPDATE %s SET title='%s' WHERE title='%s' OR active_id='%d'", task->table, task->new_title, task->title, task->active_id); } else{ @@ -203,7 +203,7 @@ void display_heading(){ int parse_args(int argc, char** argv, filtered_tasks* task){ if ( argc > 2 ){ - x_strcpy(task->title, argv[2], ARG_MAX); + task->title = argv[2]; task->active_id = atoi(argv[2]); } @@ -213,7 +213,7 @@ int parse_args(int argc, char** argv, filtered_tasks* task){ return 0; } else{ - x_strcpy(task->new_title, argv[3], ARG_MAX); + task->new_title = argv[3]; } } @@ -231,9 +231,9 @@ int parse_args(int argc, char** argv, filtered_tasks* task){ // 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)); - x_strcpy(task->table, table, ARG_MAX); + task->table = table; x_strcpy(task->status, status, ARG_MAX); - x_strcpy(task->selected_columns, "COUNT(*)", ARG_MAX); + task->selected_columns = "COUNT(*)"; sqlite3_stmt *out_stmt; int rc = 0; @@ -341,8 +341,8 @@ int view_tasks(sqlite3 *db){ // Set the table and cols to be printed filtered_tasks* tasks = malloc(sizeof(filtered_tasks)); // 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); + tasks->table = "tasks"; + tasks->selected_columns = "active_id, title, due_date"; // Print Heading display_heading(); @@ -381,18 +381,19 @@ int add_new_task(sqlite3 *db, int argc, char** argv){ sqlite3_stmt* out_stmt; filtered_tasks* task = malloc(sizeof(filtered_tasks)); - x_strcpy(task->table, "tasks", ARG_MAX); - task->title[0] = '\0'; + task->table = "tasks"; + + task->title = NULL; task->due_date[0] = '\0'; parse_args(argc, argv, task); - if ( task->title[0] != '\0' ){ + if ( task->title != NULL ){ if ( task->due_date[0] != '\0' ){ - x_strcpy(task->selected_columns, "(title, due_date)", ARG_MAX); + task->selected_columns = "(title, due_date)"; snprintf(values, ARG_MAX, "('%s', '%s')", task->title, task->due_date); }else{ - x_strcpy(task->selected_columns, "(title)", ARG_MAX); + task->selected_columns = "(title)"; snprintf(values, ARG_MAX, "('%s')", task->title); } } @@ -415,7 +416,7 @@ int update_task_status(sqlite3 *db, int argc, char** argv){ filtered_tasks* task = malloc(sizeof(filtered_tasks)); task->status[0] = '\0'; - x_strcpy(task->table, "tasks", ARG_MAX); + task->table = "tasks"; // TODO: this is not just title but also active ID so fix this parse_args(argc, argv, task); @@ -445,7 +446,7 @@ int complete_task(sqlite3 *db, int argc, char** argv){ filtered_tasks* task = malloc(sizeof(filtered_tasks)); task->status[0] = '\0'; - x_strcpy(task->table, "tasks", ARG_MAX); + task->table = "tasks"; parse_args(argc, argv, task); if ( gen_sql_update_stmt(db, &out_stmt, task) ){ @@ -471,9 +472,9 @@ int update_task(sqlite3 *db, int argc, char** argv){ sqlite3_stmt* out_stmt; filtered_tasks* task = malloc(sizeof(filtered_tasks)); - task->new_title[0] = '\0'; + task->new_title = NULL; task->due_date[0] = '\0'; - x_strcpy(task->table, "tasks", ARG_MAX); + task->table = "tasks"; parse_args(argc, argv, task); if ( gen_sql_update_stmt_v2(db, &out_stmt, task) ){ @@ -499,7 +500,7 @@ int del_task(sqlite3 *db, int argc, char** argv){ filtered_tasks* task = malloc(sizeof(filtered_tasks)); task->active_id = 0; - x_strcpy(task->table, "tasks", ARG_MAX); + task->table = "tasks"; parse_args(argc, argv, task); if ( gen_sql_delete_stmt(db, &out_stmt, task) ){ diff --git a/src/dodo.h b/src/dodo.h index b563e60..5ff3c78 100644 --- a/src/dodo.h +++ b/src/dodo.h @@ -4,7 +4,7 @@ #define SQLQUERY_MAX 400 #define ARG_MAX 100 #define NUM_TASK_LISTS 3 -#define FIXED_TITLE_WIDTH 21 +#define FIXED_TITLE_WIDTH 20 #define FIXED_DATE_WIDTH 12 #define FIXED_ID_WIDTH 4 #define FIXED_COLUMN_WIDTH (FIXED_ID_WIDTH + FIXED_TITLE_WIDTH +FIXED_DATE_WIDTH) @@ -23,10 +23,10 @@ typedef struct{ // Filters for sql selection typedef struct { - char table[ARG_MAX]; - char selected_columns[ARG_MAX]; - char title[ARG_MAX]; - char new_title[ARG_MAX]; + char *table; + char *selected_columns; + char *title; + char *new_title; int active_id; char status[ARG_MAX]; char project_tag[ARG_MAX];