Modified filtered_task struct to change char array to char* finished
This commit is contained in:
parent
24e7dc3ae7
commit
20fdead266
30
src/dodo.c
30
src/dodo.c
@ -32,7 +32,7 @@ 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 != NULL && task->due_date[0] != '\0'){
|
||||
if (task->new_title != NULL && task->due_date != NULL){
|
||||
//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);
|
||||
}
|
||||
@ -57,7 +57,7 @@ int gen_sql_update_stmt(sqlite3 *db, sqlite3_stmt** out_stmt, filtered_tasks* ta
|
||||
char sql_query[SQLQUERY_MAX];
|
||||
int rc = 0;
|
||||
|
||||
if (task->status[0] != '\0'){
|
||||
if (task->status != NULL){
|
||||
snprintf(sql_query, SQLQUERY_MAX, "UPDATE %s SET status='%s' WHERE title='%s' OR active_id='%d'", task->table, task->status, task->title, task->active_id);
|
||||
}
|
||||
else{
|
||||
@ -209,7 +209,7 @@ int parse_args(int argc, char** argv, filtered_tasks* task){
|
||||
|
||||
if ( argc > 3 ){
|
||||
if ( x_strcmp(argv[1], "update") ){
|
||||
x_strcpy(task->due_date, argv[3], ARG_MAX);
|
||||
task->due_date = argv[3];
|
||||
return 0;
|
||||
}
|
||||
else{
|
||||
@ -218,11 +218,11 @@ int parse_args(int argc, char** argv, filtered_tasks* task){
|
||||
}
|
||||
|
||||
if ( argc > 4 ){
|
||||
x_strcpy(task->due_date, argv[4], ARG_MAX);
|
||||
task->due_date = argv[3];
|
||||
}
|
||||
|
||||
if ( argc > 5 ){
|
||||
x_strcpy(task->project_tag, argv[5], ARG_MAX);
|
||||
task->project_tag = argv[5];
|
||||
}
|
||||
|
||||
return 0;
|
||||
@ -232,7 +232,7 @@ int parse_args(int argc, char** argv, filtered_tasks* task){
|
||||
int get_num_rows(sqlite3 *db, char* table, char* status){
|
||||
filtered_tasks* task = malloc(sizeof(filtered_tasks));
|
||||
task->table = table;
|
||||
x_strcpy(task->status, status, ARG_MAX);
|
||||
task->status = status;
|
||||
task->selected_columns = "COUNT(*)";
|
||||
sqlite3_stmt *out_stmt;
|
||||
int rc = 0;
|
||||
@ -348,21 +348,21 @@ int view_tasks(sqlite3 *db){
|
||||
display_heading();
|
||||
|
||||
// Print "today" tasks
|
||||
x_strcpy(tasks->status, "today", ARG_MAX);
|
||||
tasks->status = "today";
|
||||
if ( display_task_list(TODAY_COL_START, db, tasks) ){
|
||||
free(tasks);
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Print "backlog" tasks
|
||||
x_strcpy(tasks->status, "backlog", ARG_MAX);
|
||||
tasks->status = "backlog";
|
||||
if ( display_task_list(BACKLOG_COL_START, db, tasks) ){
|
||||
free(tasks);
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Print "blocked" tasks
|
||||
x_strcpy(tasks->status, "blocked", ARG_MAX);
|
||||
tasks->status = "blocked";
|
||||
if ( display_task_list(BLOCKED_COL_START, db, tasks) ){
|
||||
free(tasks);
|
||||
return -1;
|
||||
@ -384,12 +384,12 @@ int add_new_task(sqlite3 *db, int argc, char** argv){
|
||||
task->table = "tasks";
|
||||
|
||||
task->title = NULL;
|
||||
task->due_date[0] = '\0';
|
||||
task->due_date = NULL;
|
||||
|
||||
parse_args(argc, argv, task);
|
||||
|
||||
if ( task->title != NULL ){
|
||||
if ( task->due_date[0] != '\0' ){
|
||||
if ( task->due_date != NULL ){
|
||||
task->selected_columns = "(title, due_date)";
|
||||
snprintf(values, ARG_MAX, "('%s', '%s')", task->title, task->due_date);
|
||||
}else{
|
||||
@ -415,13 +415,13 @@ int update_task_status(sqlite3 *db, int argc, char** argv){
|
||||
sqlite3_stmt* out_stmt;
|
||||
filtered_tasks* task = malloc(sizeof(filtered_tasks));
|
||||
|
||||
task->status[0] = '\0';
|
||||
task->status = NULL;
|
||||
task->table = "tasks";
|
||||
|
||||
// TODO: this is not just title but also active ID so fix this
|
||||
parse_args(argc, argv, task);
|
||||
|
||||
x_strcpy(task->status, argv[1], ARG_MAX);
|
||||
task->status = argv[1];
|
||||
if ( gen_sql_update_stmt(db, &out_stmt, task) ){
|
||||
free(task);
|
||||
return -1;
|
||||
@ -445,7 +445,7 @@ int complete_task(sqlite3 *db, int argc, char** argv){
|
||||
sqlite3_stmt* out_stmt;
|
||||
filtered_tasks* task = malloc(sizeof(filtered_tasks));
|
||||
|
||||
task->status[0] = '\0';
|
||||
task->status = NULL;
|
||||
task->table = "tasks";
|
||||
|
||||
parse_args(argc, argv, task);
|
||||
@ -473,7 +473,7 @@ int update_task(sqlite3 *db, int argc, char** argv){
|
||||
filtered_tasks* task = malloc(sizeof(filtered_tasks));
|
||||
|
||||
task->new_title = NULL;
|
||||
task->due_date[0] = '\0';
|
||||
task->due_date = NULL;
|
||||
task->table = "tasks";
|
||||
|
||||
parse_args(argc, argv, task);
|
||||
|
@ -12,7 +12,7 @@
|
||||
#define FIXED_MAX_WIDTH (FIXED_COLUMN_WIDTH)
|
||||
#define TODAY_COL_START -1
|
||||
#define BACKLOG_COL_START (FIXED_COLUMN_WIDTH + 1)
|
||||
#define BLOCKED_COL_START (FIXED_COLUMN_WIDTH + 1)
|
||||
#define BLOCKED_COL_START ( (2 * FIXED_COLUMN_WIDTH) + 1)
|
||||
#define DUEPARSE_SIZE 4
|
||||
|
||||
typedef struct{
|
||||
@ -28,10 +28,9 @@ typedef struct {
|
||||
char *title;
|
||||
char *new_title;
|
||||
int active_id;
|
||||
char status[ARG_MAX];
|
||||
char project_tag[ARG_MAX];
|
||||
char creation_date[ARG_MAX];
|
||||
char due_date[ARG_MAX];
|
||||
char *status;
|
||||
char *project_tag;
|
||||
char *due_date;
|
||||
}filtered_tasks;
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user