Modified the rest of the main functions to use struct TODO: update is broke
This commit is contained in:
parent
52eff82c03
commit
62a1565137
4
Makefile
4
Makefile
@ -43,10 +43,10 @@ all: dodo
|
|||||||
$(OBJ): $(SRC) $(X_STRING_OBJ) $(SQLITE_OBJ) $(HEADERS)
|
$(OBJ): $(SRC) $(X_STRING_OBJ) $(SQLITE_OBJ) $(HEADERS)
|
||||||
$(CC) -c -o $(OBJ_DIR)/$(@F) $(INC_DIRS) $(CFLAGS) $(DFLAGS) $(SRC_DIR)/$(@F:.o=.c)
|
$(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)
|
$(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)
|
$(CC) -c -o $(OBJ_DIR)/$(@F) $(CFLAGS) $(SQLITE_SRC)
|
||||||
|
|
||||||
dodo: test $(OBJ) $(X_STRING_OBJ) $(SQLITE_OBJ)
|
dodo: test $(OBJ) $(X_STRING_OBJ) $(SQLITE_OBJ)
|
||||||
|
60
src/dodo.c
60
src/dodo.c
@ -199,32 +199,49 @@ 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!
|
||||||
|
// TODO maybe a Abstract Sytnax Tree for parsing
|
||||||
int parse_args(int argc, char** argv, filtered_tasks* task){
|
int parse_args(int argc, char** argv, filtered_tasks* task){
|
||||||
|
|
||||||
if ( argc > 2 ){
|
if ( argc > 2 ){
|
||||||
x_strcpy(task->title, argv[2], ARG_MAX);
|
x_strcpy(task->title, argv[2], ARG_MAX);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( argc > 3 ){
|
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 ){
|
if ( argc > 4 ){
|
||||||
*new_due_date = argv[4];
|
x_strcpy(task->due_date, argv[4], ARG_MAX);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( argc > 5 ){
|
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
|
// Get number of tasks from tasks table give status
|
||||||
int get_num_rows(sqlite3 *db, char* table, char* status){
|
int get_num_rows(sqlite3 *db, char* table, char* status){
|
||||||
filtered_tasks* task = malloc(sizeof(filtered_tasks));
|
filtered_tasks* task = malloc(sizeof(filtered_tasks));
|
||||||
@ -340,7 +357,6 @@ int view_tasks(sqlite3 *db){
|
|||||||
// TODO check that malloc is ok
|
// 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);
|
||||||
|
|
||||||
|
|
||||||
// Print Heading
|
// Print Heading
|
||||||
display_heading();
|
display_heading();
|
||||||
@ -375,7 +391,7 @@ int view_tasks(sqlite3 *db){
|
|||||||
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 values[100];
|
char values[ARG_MAX];
|
||||||
sqlite3_stmt* out_stmt;
|
sqlite3_stmt* out_stmt;
|
||||||
|
|
||||||
filtered_tasks* task = malloc(sizeof(filtered_tasks));
|
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
|
// TODO this can definatly be made into one func with all the other updates
|
||||||
int update_task(sqlite3 *db, int argc, char** argv){
|
int update_task(sqlite3 *db, int argc, char** argv){
|
||||||
int rc = 0;
|
int rc = 0;
|
||||||
char* table = "tasks";
|
|
||||||
char* title;
|
|
||||||
char* new_title;
|
|
||||||
char* new_due_date;
|
|
||||||
char* new_project_tag;
|
|
||||||
sqlite3_stmt* out_stmt;
|
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);
|
x_strcpy(task->table, "task", ARG_MAX);
|
||||||
if ( gen_sql_update_stmt_v2(db, &out_stmt, table, new_title, new_due_date, new_project_tag, title) ){
|
|
||||||
|
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;
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,6 +13,7 @@
|
|||||||
#define TODAY_COL_START -1
|
#define TODAY_COL_START -1
|
||||||
#define BACKLOG_COL_START (FIXED_COLUMN_WIDTH + 1)
|
#define BACKLOG_COL_START (FIXED_COLUMN_WIDTH + 1)
|
||||||
#define BLOCKED_COL_START (2 * (FIXED_COLUMN_WIDTH + 1))
|
#define BLOCKED_COL_START (2 * (FIXED_COLUMN_WIDTH + 1))
|
||||||
|
#define DUEPARSE_SIZE 4
|
||||||
|
|
||||||
typedef struct{
|
typedef struct{
|
||||||
int year;
|
int year;
|
||||||
@ -23,9 +24,9 @@ typedef struct{
|
|||||||
// Filters for sql selection
|
// Filters for sql selection
|
||||||
typedef struct {
|
typedef struct {
|
||||||
char table[ARG_MAX];
|
char table[ARG_MAX];
|
||||||
int task_id;
|
|
||||||
char selected_columns[ARG_MAX];
|
char selected_columns[ARG_MAX];
|
||||||
char title[ARG_MAX];
|
char title[ARG_MAX];
|
||||||
|
char new_title[ARG_MAX];
|
||||||
int active_id;
|
int active_id;
|
||||||
char status[ARG_MAX];
|
char status[ARG_MAX];
|
||||||
char project_tag[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 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 update_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);
|
int del_task(sqlite3 *db, int argc, char** argv);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -1 +1 @@
|
|||||||
Subproject commit 787bf40377a6f490729a02ba1c680c0b85e4f318
|
Subproject commit 4fb48e69126058c09a93a102970d182db3be31b9
|
Loading…
Reference in New Issue
Block a user