Compare commits
6 Commits
bf1f5e0c70
...
7a9d7e9ff0
Author | SHA1 | Date | |
---|---|---|---|
7a9d7e9ff0 | |||
53a5c910b5 | |||
43323dbf9b | |||
2dfbc19d2c | |||
9c46269868 | |||
58893119c7 |
@ -26,7 +26,10 @@ install: dodo
|
|||||||
uninstall:
|
uninstall:
|
||||||
rm -rf $(HOME_DIR)$(CONFIG_DIR)
|
rm -rf $(HOME_DIR)$(CONFIG_DIR)
|
||||||
|
|
||||||
clean:
|
clean_all:
|
||||||
rm -f dodo $(OBJ)
|
rm -f dodo $(OBJ)
|
||||||
|
|
||||||
.PHONY: all clean install uninstall
|
clean:
|
||||||
|
rm -f dodo dodo.o x_string.o
|
||||||
|
|
||||||
|
.PHONY: all clean_all clean install uninstall
|
||||||
|
121
src/dodo.c
121
src/dodo.c
@ -5,6 +5,7 @@
|
|||||||
#include "x_curses.h"
|
#include "x_curses.h"
|
||||||
|
|
||||||
#define SQLQUERY_MAX 100
|
#define SQLQUERY_MAX 100
|
||||||
|
#define ARG_MAX 100
|
||||||
#define TODAY_COL_START -1
|
#define TODAY_COL_START -1
|
||||||
#define BACKLOG_COL_START 33
|
#define BACKLOG_COL_START 33
|
||||||
#define BLOCKED_COL_START 66
|
#define BLOCKED_COL_START 66
|
||||||
@ -12,6 +13,7 @@
|
|||||||
|
|
||||||
int checksqlerr(int rc, char *errmsg){
|
int checksqlerr(int rc, char *errmsg){
|
||||||
if( rc!=SQLITE_OK ){
|
if( rc!=SQLITE_OK ){
|
||||||
|
fprintf(stderr, "rc = %d\n", rc);
|
||||||
fprintf(stderr, "SQL error: %s\n", errmsg);
|
fprintf(stderr, "SQL error: %s\n", errmsg);
|
||||||
sqlite3_free(errmsg);
|
sqlite3_free(errmsg);
|
||||||
return -1;
|
return -1;
|
||||||
@ -70,17 +72,25 @@ void display_heading(){
|
|||||||
printf("\n");
|
printf("\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Generate the sql statement by giving the columns, table, and current task list wanted
|
int gen_sql_insert_stmt(sqlite3 *db, sqlite3_stmt** out_stmt, char* table, char* colnames, char* values){
|
||||||
// TODO make the stmt an arg pass and return an int
|
char sql_query[SQLQUERY_MAX];
|
||||||
// TODO ME THINKS THIS IS THE NEXT THING TO DO BECAUSE BREAKING EVERYTHING
|
int rc = 0;
|
||||||
int gen_sql_stmt(sqlite3 *db, sqlite3_stmt** out_stmt, char* colnames, char* table, char* status){
|
|
||||||
|
snprintf(sql_query, SQLQUERY_MAX, "INSERT INTO %s %s VALUES %s", table, colnames, values);
|
||||||
|
rc = sqlite3_prepare_v2(db, sql_query, -1, out_stmt, NULL);
|
||||||
|
if (checksqlerr(rc, "prepare broken in gen_sql_insert_stmt")){
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Generate the sql statement by giving the columns, table, and current task list wanted
|
||||||
|
int gen_sql_select_stmt(sqlite3 *db, sqlite3_stmt** out_stmt, char* colnames, char* table, char* status){
|
||||||
char sql_query[SQLQUERY_MAX];
|
char sql_query[SQLQUERY_MAX];
|
||||||
int rc = 0;
|
int rc = 0;
|
||||||
//sqlite3_stmt *out_stmt;
|
|
||||||
|
|
||||||
snprintf(sql_query, SQLQUERY_MAX, "SELECT %s FROM %s WHERE status='%s'", colnames, table, status);
|
snprintf(sql_query, SQLQUERY_MAX, "SELECT %s FROM %s WHERE status='%s'", colnames, table, status);
|
||||||
rc = sqlite3_prepare_v2(db, sql_query, -1, out_stmt, NULL);
|
rc = sqlite3_prepare_v2(db, sql_query, -1, out_stmt, NULL);
|
||||||
if (checksqlerr(rc, "prepare broken in gen_sql_stmt")){
|
if (checksqlerr(rc, "prepare broken in gen_sql_select_stmt")){
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -88,13 +98,12 @@ int gen_sql_stmt(sqlite3 *db, sqlite3_stmt** out_stmt, char* colnames, char* tab
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Get number of tasks from tasks table give status
|
// Get number of tasks from tasks table give status
|
||||||
// TODO: Gotta make the error checking not broken
|
|
||||||
int get_num_rows(sqlite3 *db, char* table, char* status){
|
int get_num_rows(sqlite3 *db, char* table, char* status){
|
||||||
sqlite3_stmt *out_stmt;
|
sqlite3_stmt *out_stmt;
|
||||||
int rc = 0;
|
int rc = 0;
|
||||||
char *col_name = "COUNT(*)";
|
char *col_name = "COUNT(*)";
|
||||||
|
|
||||||
if ( gen_sql_stmt(db, &out_stmt, col_name, table, status) == 1 ){
|
if ( gen_sql_select_stmt(db, &out_stmt, col_name, table, status) == 1 ){
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -105,7 +114,7 @@ int get_num_rows(sqlite3 *db, char* table, char* status){
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Print columns
|
// Print with FIXED_WIDTH
|
||||||
int print_fixed_width(const unsigned char* str){
|
int print_fixed_width(const unsigned char* str){
|
||||||
if (str){
|
if (str){
|
||||||
printf("%-*.*s", FIXED_WIDTH, FIXED_WIDTH, str);
|
printf("%-*.*s", FIXED_WIDTH, FIXED_WIDTH, str);
|
||||||
@ -114,11 +123,12 @@ int print_fixed_width(const unsigned char* str){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int display_task_list(int start_col, sqlite3 *db, char* colnames, char* table, char* status){
|
int display_task_list(int start_col, sqlite3 *db, char* colnames, char* table, char* status){
|
||||||
static int max_rows = 0;
|
static int max_rows = -1;
|
||||||
int rc = 0;
|
int rc = 0;
|
||||||
int i = 0;
|
int i = 0;
|
||||||
int num_rows = 0;
|
int num_rows = -1;
|
||||||
int num_cols = 0;
|
int num_cols = 0;
|
||||||
char* errmsg;
|
char* errmsg;
|
||||||
const unsigned char* col_val;
|
const unsigned char* col_val;
|
||||||
@ -135,7 +145,7 @@ int display_task_list(int start_col, sqlite3 *db, char* colnames, char* table, c
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Generate the sql statement by giving the columns, table, and current task list wanted
|
// Generate the sql statement by giving the columns, table, and current task list wanted
|
||||||
if ( gen_sql_stmt(db, &out_stmt, colnames, table, status) ){
|
if ( gen_sql_select_stmt(db, &out_stmt, colnames, table, status) ){
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
// while there is still rows available
|
// while there is still rows available
|
||||||
@ -160,7 +170,9 @@ int display_task_list(int start_col, sqlite3 *db, char* colnames, char* table, c
|
|||||||
|
|
||||||
// Once the task list is completely printed
|
// Once the task list is completely printed
|
||||||
// reset to the top of the task lists
|
// reset to the top of the task lists
|
||||||
X_goup(num_rows);
|
if (num_rows > 0){
|
||||||
|
X_goup(num_rows);
|
||||||
|
}
|
||||||
|
|
||||||
// if it is the last task list move down one past the longest list
|
// if it is the last task list move down one past the longest list
|
||||||
if ( status == "blocked"){
|
if ( status == "blocked"){
|
||||||
@ -169,14 +181,71 @@ int display_task_list(int start_col, sqlite3 *db, char* colnames, char* table, c
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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!
|
||||||
|
int arg_parser(int argc, char** argv, char** title, char** due_date){
|
||||||
|
if ( argc > 1 ){
|
||||||
|
*title = argv[2];
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( argc > 2 ){
|
||||||
|
*due_date = argv[3];
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int add_task(sqlite3 *db, int argc, char** argv){
|
||||||
|
int rc = 0;
|
||||||
|
char* table = "tasks";
|
||||||
|
char* title;
|
||||||
|
char* due_date;
|
||||||
|
char* colnames = "(title, due_date)";
|
||||||
|
char values[100];
|
||||||
|
sqlite3_stmt* out_stmt;
|
||||||
|
|
||||||
|
arg_parser(argc, argv, &title, &due_date);
|
||||||
|
|
||||||
|
snprintf(values, 100, "('%s', '%s')", title, due_date);
|
||||||
|
|
||||||
|
if ( gen_sql_insert_stmt(db, &out_stmt, table, colnames, values) ){
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
if ( ( rc = sqlite3_step(out_stmt) ) == SQLITE_DONE){
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
checksqlerr(rc, "broken in add_task");
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
// Format Col names like this (col1, col2, col3)
|
||||||
|
//char* colnames = "(title, due_date)";
|
||||||
|
|
||||||
|
// Format values like this
|
||||||
|
// For first row For second row For third row
|
||||||
|
// (col1val, col2val, col3val), (col1val, col2val, col3val), (col1val, col2val, col3val)
|
||||||
|
// char* values[ARG_MAX];
|
||||||
|
// sqlite3_stmt* out_stmt;
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// if ( gen_sql_insert_stmt(db, &out_stmt, table, colnames, values) ){
|
||||||
|
// return -1;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// if ( ( rc = sqlite3_step(out_stmt) ) == SQLITE_DONE){
|
||||||
|
// return 0;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// checksqlerr(rc, "broken in add_task");
|
||||||
|
// return 1;
|
||||||
|
}
|
||||||
|
|
||||||
// Print kanban table
|
// Print kanban table
|
||||||
// All lists with task name and due date
|
// All lists with task name and due date
|
||||||
|
|
||||||
// TODO just gotta use snprintf because can't bind column or table names
|
|
||||||
int view(sqlite3 *db){
|
int view(sqlite3 *db){
|
||||||
char* table = "tasks";
|
char* table = "tasks";
|
||||||
char* status = "today";
|
char* status = "today";
|
||||||
char* colnames = "title,creation_date";
|
char* colnames = "title,due_date";
|
||||||
|
|
||||||
// Print Heading
|
// Print Heading
|
||||||
display_heading();
|
display_heading();
|
||||||
@ -208,13 +277,21 @@ int main( int argc, char **argv ){
|
|||||||
char* filename = x_strconcat(home_dir, DB_PATH);
|
char* filename = x_strconcat(home_dir, DB_PATH);
|
||||||
|
|
||||||
rc = opendb(&db, filename);
|
rc = opendb(&db, filename);
|
||||||
rc = view(db);
|
if ( argv[1] ){
|
||||||
|
if (argv[1][0] == 'b'){
|
||||||
|
rc = view(db);
|
||||||
|
}
|
||||||
|
else if ( argv[1][0] == 'a'){
|
||||||
|
rc = add_task(db,argc,argv);
|
||||||
|
}
|
||||||
|
else if ( argv[1][0] == 'v'){
|
||||||
|
rc = view_all(db);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
rc = view(db);
|
||||||
|
}
|
||||||
|
|
||||||
puts("");
|
|
||||||
puts("");
|
|
||||||
puts("");
|
|
||||||
puts("");
|
|
||||||
rc = view_all(db);
|
|
||||||
sqlite3_close(db);
|
sqlite3_close(db);
|
||||||
|
|
||||||
|
|
||||||
|
@ -3,8 +3,12 @@ CREATE TABLE tasks(
|
|||||||
title TEXT NOT NULL,
|
title TEXT NOT NULL,
|
||||||
active_id INTEGER UNIQUE,
|
active_id INTEGER UNIQUE,
|
||||||
status TEXT NOT NULL DEFAULT 'backlog',
|
status TEXT NOT NULL DEFAULT 'backlog',
|
||||||
due_date DATE,
|
creation_date DATE DEFAULT (date('now')),
|
||||||
creation_date DATE DEFAULT (date('now'))
|
due_date TEXT,
|
||||||
|
CHECK (
|
||||||
|
due_date IS NULL OR
|
||||||
|
due_date GLOB '????-??-??'
|
||||||
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE TABLE entries(
|
CREATE TABLE entries(
|
||||||
|
Loading…
Reference in New Issue
Block a user