Compare commits
3 Commits
4cc935cd01
...
65464112a6
Author | SHA1 | Date | |
---|---|---|---|
65464112a6 | |||
b0eb5be2c0 | |||
443c9f04cd |
40
Makefile
40
Makefile
@ -1,24 +1,30 @@
|
|||||||
.POSIX:
|
.POSIX:
|
||||||
|
|
||||||
|
# DIRECTORIES
|
||||||
SRC_DIR = src
|
SRC_DIR = src
|
||||||
OBJ_DIR = obj
|
OBJ_DIR = obj
|
||||||
|
X_STRING_DIR = $(SRC_DIR)/xlibc/x_string
|
||||||
|
SQLITE_DIR = $(SRC_DIR)/sqlite3
|
||||||
|
|
||||||
|
# Sources
|
||||||
|
SRC = $(wildcard $(SRC_DIR)/*.c)
|
||||||
|
X_STRING_SRC = $(wildcard $(X_STRING_DIR)/src/*.c)
|
||||||
|
SQLITE_SRC = $(wildcard $(SQLITE_DIR)/src/*.c)
|
||||||
|
|
||||||
|
# Headers
|
||||||
|
HEADERS = $(wildcard $(SRC_DIR)/*.h)
|
||||||
|
X_STRING_HEADERS = $(wildcard $(X_STRING_DIR)/src/*.h)
|
||||||
|
SQLITE_HEADERS = $(wildcard $(SQLITE_DIR)/src/*.h)
|
||||||
|
|
||||||
|
# Objects
|
||||||
|
OBJ = $(patsubst $(SRC_DIR)/%.c, $(OBJ_DIR)/%.o, $(SRC))
|
||||||
|
X_STRING_OBJ = $(patsubst $(X_STRING_DIR)/src/%.c, $(OBJ_DIR)/%.o, $(X_STRING_SRC))
|
||||||
|
SQLITE_OBJ = $(patsubst $(SQLITE_DIR)/src/%.c, $(OBJ_DIR)/%.o, $(SQLITE_SRC))
|
||||||
ALL_OBJS = $(wildcard $(OBJ_DIR)/*.o)
|
ALL_OBJS = $(wildcard $(OBJ_DIR)/*.o)
|
||||||
|
|
||||||
SRC = $(wildcard $(SRC_DIR)/*.c)
|
|
||||||
OBJ = $(addprefix $(OBJ_DIR)/, $(notdir $(SRC:.c=.o)))
|
|
||||||
|
|
||||||
|
|
||||||
X_STRING_DIR = $(SRC_DIR)/xlibc/x_string
|
|
||||||
X_STRING_SRC = $(wildcard $(X_STRING_DIR)/src/*.c)
|
|
||||||
X_STRING_OBJ = $(addprefix $(OBJ_DIR)/, $(notdir $(X_STRING_SRC:.c=.o)))
|
|
||||||
|
|
||||||
SQLITE_DIR = $(SRC_DIR)/sqlite3
|
|
||||||
SQLITE_SRC = $(wildcard $(SQLITE_DIR)/src/*.c)
|
|
||||||
SQLITE_OBJ = $(addprefix $(OBJ_DIR)/, $(notdir $(SQLITE_SRC:.c=.o)))
|
|
||||||
SQLITE_DB_SCHEMA = $(SRC_DIR)/dodo.schema
|
SQLITE_DB_SCHEMA = $(SRC_DIR)/dodo.schema
|
||||||
|
INC_DIRS=-I./$(X_STRING_DIR)/src/ -I./$(SQLITE_DIR)/src/
|
||||||
INC_DIRS=$(X_STRING_DIR)/src
|
|
||||||
|
|
||||||
HOME_DIR = $$HOME
|
HOME_DIR = $$HOME
|
||||||
CONFIG_DIR = /.config/dodo
|
CONFIG_DIR = /.config/dodo
|
||||||
@ -28,16 +34,16 @@ DFLAGS = -DDB_PATH=\"$(DB_FILE)\"
|
|||||||
|
|
||||||
all: dodo
|
all: dodo
|
||||||
|
|
||||||
$(OBJ): $(X_STRING_OBJ)
|
$(OBJ): $(X_STRING_OBJ) $(SQLITE_OBJ) $(HEADERS)
|
||||||
$(CC) -c -o $(OBJ_DIR)/$(@F) -I./$(INC_DIRS)/ $(DFLAGS) $(SRC)
|
$(CC) -c -o $(OBJ_DIR)/$(@F) $(INC_DIRS) $(DFLAGS) $(SRC_DIR)/$(@F:.o=.c)
|
||||||
|
|
||||||
$(X_STRING_OBJ):
|
$(X_STRING_OBJ): $(X_STRING_HEADERS)
|
||||||
$(CC) -c -o $(OBJ_DIR)/$(@F) $(X_STRING_SRC)
|
$(CC) -c -o $(OBJ_DIR)/$(@F) $(X_STRING_SRC)
|
||||||
|
|
||||||
$(SQLITE_OBJ):
|
$(SQLITE_OBJ): $(SQLITE_HEADERS)
|
||||||
$(CC) -c -o $(OBJ_DIR)/$(@F) $(SQLITE_SRC)
|
$(CC) -c -o $(OBJ_DIR)/$(@F) $(SQLITE_SRC)
|
||||||
|
|
||||||
dodo: $(OBJ) $(X_STRING_OBJ) $(SQLITE_OBJ)
|
dodo: $(OBJ)
|
||||||
$(CC) -o $@ $(ALL_OBJS)
|
$(CC) -o $@ $(ALL_OBJS)
|
||||||
|
|
||||||
install:
|
install:
|
||||||
|
337
src/dodo.c
337
src/dodo.c
@ -3,53 +3,8 @@
|
|||||||
#include "sqlite3.h"
|
#include "sqlite3.h"
|
||||||
#include "x_string.h"
|
#include "x_string.h"
|
||||||
#include "x_curses.h"
|
#include "x_curses.h"
|
||||||
|
#include "dodo.h"
|
||||||
|
|
||||||
#define SQLQUERY_MAX 100
|
|
||||||
#define ARG_MAX 100
|
|
||||||
#define TODAY_COL_START -1
|
|
||||||
#define BACKLOG_COL_START 33
|
|
||||||
#define BLOCKED_COL_START 66
|
|
||||||
#define FIXED_WIDTH 19
|
|
||||||
|
|
||||||
typedef struct{
|
|
||||||
int year;
|
|
||||||
int month;
|
|
||||||
int day;
|
|
||||||
}date;
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
int task_id;
|
|
||||||
char* title;
|
|
||||||
int active_id;
|
|
||||||
char* status;
|
|
||||||
date creation_date;
|
|
||||||
date due_date;
|
|
||||||
}task_entry;
|
|
||||||
|
|
||||||
int checksqlerr(int rc, char *errmsg){
|
|
||||||
if( rc!=SQLITE_OK ){
|
|
||||||
fprintf(stderr, "rc = %d\n", rc);
|
|
||||||
fprintf(stderr, "SQL error: %s\n", errmsg);
|
|
||||||
sqlite3_free(errmsg);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int opendb(sqlite3 **db, char* filename){
|
|
||||||
int rc = 0;
|
|
||||||
|
|
||||||
rc = sqlite3_open(filename, db);
|
|
||||||
|
|
||||||
if ( rc != 0 ){
|
|
||||||
fprintf(stderr, "Can't open database: %s\n", sqlite3_errmsg(*db));
|
|
||||||
sqlite3_close(*db);
|
|
||||||
return(rc);
|
|
||||||
}
|
|
||||||
|
|
||||||
return(rc);
|
|
||||||
}
|
|
||||||
|
|
||||||
// FOR DEBUG
|
// FOR DEBUG
|
||||||
int callback(void *NotUsed, int argc, char **argv, char **azColName){
|
int callback(void *NotUsed, int argc, char **argv, char **azColName){
|
||||||
@ -73,20 +28,8 @@ int view_all(sqlite3 *db){
|
|||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Print Heading TODO: obvi make this better
|
|
||||||
void display_heading(){
|
|
||||||
printf("\n");
|
|
||||||
printf("%s Today %s", X_BOLD, X_RST);
|
|
||||||
printf(" %s Backlog %s", X_BOLD, X_RST);
|
|
||||||
printf(" %s Blocked %s", X_BOLD, X_RST);
|
|
||||||
printf("\n");
|
|
||||||
|
|
||||||
printf("%s%stitle due date %s", X_BOLD, X_UNDL, X_RST);
|
|
||||||
printf(" %s%stitle due date %s", X_BOLD, X_UNDL, X_RST);
|
|
||||||
printf(" %s%stitle due date %s", X_BOLD, X_UNDL, X_RST);
|
|
||||||
printf("\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
// sql generators TODO: might be able to boil this down to 1 func
|
||||||
int gen_sql_update_stmt(sqlite3 *db, sqlite3_stmt** out_stmt, char* table, char* status, char* title){
|
int gen_sql_update_stmt(sqlite3 *db, sqlite3_stmt** out_stmt, char* table, char* status, char* title){
|
||||||
char sql_query[SQLQUERY_MAX];
|
char sql_query[SQLQUERY_MAX];
|
||||||
int rc = 0;
|
int rc = 0;
|
||||||
@ -149,6 +92,58 @@ int gen_sql_select_stmt(sqlite3 *db, sqlite3_stmt** out_stmt, char* colnames, ch
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int checksqlerr(int rc, char *errmsg){
|
||||||
|
if( rc!=SQLITE_OK ){
|
||||||
|
fprintf(stderr, "rc = %d\n", rc);
|
||||||
|
fprintf(stderr, "SQL error: %s\n", errmsg);
|
||||||
|
sqlite3_free(errmsg);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int opendb(sqlite3 **db, char* filename){
|
||||||
|
int rc = 0;
|
||||||
|
|
||||||
|
rc = sqlite3_open(filename, db);
|
||||||
|
|
||||||
|
if ( rc != 0 ){
|
||||||
|
fprintf(stderr, "Can't open database: %s\n", sqlite3_errmsg(*db));
|
||||||
|
sqlite3_close(*db);
|
||||||
|
return(rc);
|
||||||
|
}
|
||||||
|
|
||||||
|
return(rc);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Print Heading TODO: obvi make this better
|
||||||
|
void display_heading(){
|
||||||
|
printf("\n");
|
||||||
|
printf("%s Today %s", X_BOLD, X_RST);
|
||||||
|
printf(" %s Backlog %s", X_BOLD, X_RST);
|
||||||
|
printf(" %s Blocked %s", X_BOLD, X_RST);
|
||||||
|
printf("\n");
|
||||||
|
|
||||||
|
printf("%s%stitle due date %s", X_BOLD, X_UNDL, X_RST);
|
||||||
|
printf(" %s%stitle due date %s", X_BOLD, X_UNDL, X_RST);
|
||||||
|
printf(" %s%stitle due date %s", X_BOLD, X_UNDL, X_RST);
|
||||||
|
printf("\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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 parse_args(int argc, char** argv, char** title, char** due_date){
|
||||||
|
if ( argc > 2 ){
|
||||||
|
*title = argv[2];
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( argc > 3 ){
|
||||||
|
*due_date = argv[3];
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
// 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){
|
||||||
sqlite3_stmt *out_stmt;
|
sqlite3_stmt *out_stmt;
|
||||||
@ -236,110 +231,6 @@ 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 parse_args(int argc, char** argv, char** title, char** due_date){
|
|
||||||
if ( argc > 2 ){
|
|
||||||
*title = argv[2];
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( argc > 3 ){
|
|
||||||
*due_date = argv[3];
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
int complete_task(sqlite3 *db, int argc, char** argv){
|
|
||||||
int rc = 0;
|
|
||||||
char* table = "tasks";
|
|
||||||
char* title;
|
|
||||||
sqlite3_stmt* out_stmt;
|
|
||||||
|
|
||||||
parse_args(argc, argv, &title, NULL);
|
|
||||||
if ( gen_sql_update_stmt(db, &out_stmt, table, NULL, title) ){
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( ( rc = sqlite3_step(out_stmt) ) == SQLITE_DONE){
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
checksqlerr(rc, "broken in complete_task");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
int update_task_status(sqlite3 *db, int argc, char** argv){
|
|
||||||
int rc = 0;
|
|
||||||
char* table = "tasks";
|
|
||||||
char* title;
|
|
||||||
sqlite3_stmt* out_stmt;
|
|
||||||
parse_args(argc, argv, &title, NULL);
|
|
||||||
|
|
||||||
if ( gen_sql_update_stmt(db, &out_stmt, table, argv[1], title) ){
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( ( rc = sqlite3_step(out_stmt) ) == SQLITE_DONE){
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
checksqlerr(rc, "broken in update_task_status");
|
|
||||||
return 1;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
int del_task(sqlite3 *db, int argc, char** argv){
|
|
||||||
int rc = 0;
|
|
||||||
char* table = "tasks";
|
|
||||||
char* title;
|
|
||||||
sqlite3_stmt* out_stmt;
|
|
||||||
|
|
||||||
parse_args(argc, argv, &title, NULL);
|
|
||||||
if ( gen_sql_delete_stmt(db, &out_stmt, table, title) ){
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( ( rc = sqlite3_step(out_stmt) ) == SQLITE_DONE){
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
checksqlerr(rc, "broken in del_task");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// TODO: the way this ensures that we are only passing in
|
|
||||||
// valid inputs is stupid and ugly FIX
|
|
||||||
int add_new_task(sqlite3 *db, int argc, char** argv){
|
|
||||||
int rc = 0;
|
|
||||||
char* table = "tasks";
|
|
||||||
char* title = NULL;
|
|
||||||
char* due_date = NULL;
|
|
||||||
char* colnames = "(title, due_date)";
|
|
||||||
char values[100];
|
|
||||||
sqlite3_stmt* out_stmt;
|
|
||||||
|
|
||||||
parse_args(argc, argv, &title, &due_date);
|
|
||||||
|
|
||||||
if ( due_date != NULL ){
|
|
||||||
snprintf(values, 100, "('%s', '%s')", title, due_date);
|
|
||||||
}else{
|
|
||||||
colnames = "(title)";
|
|
||||||
snprintf(values, 100, "('%s')", title);
|
|
||||||
}
|
|
||||||
|
|
||||||
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_new_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
|
||||||
int view_tasks(sqlite3 *db){
|
int view_tasks(sqlite3 *db){
|
||||||
@ -370,45 +261,93 @@ int view_tasks(sqlite3 *db){
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main( int argc, char **argv ){
|
// TODO: the way this ensures that we are only passing in
|
||||||
sqlite3 *db;
|
// valid inputs is stupid and ugly FIX
|
||||||
|
int add_new_task(sqlite3 *db, int argc, char** argv){
|
||||||
int rc = 0;
|
int rc = 0;
|
||||||
char* home_dir = getenv("HOME");
|
char* table = "tasks";
|
||||||
char* filename = x_strconcat(home_dir, DB_PATH);
|
char* title = NULL;
|
||||||
|
char* due_date = NULL;
|
||||||
|
char* colnames = "(title, due_date)";
|
||||||
|
char values[100];
|
||||||
|
sqlite3_stmt* out_stmt;
|
||||||
|
|
||||||
rc = opendb(&db, filename);
|
parse_args(argc, argv, &title, &due_date);
|
||||||
if ( argv[1] ){
|
|
||||||
if (x_strcmp(argv[1], "view") == 0){
|
if ( due_date != NULL ){
|
||||||
rc = view_tasks(db);
|
snprintf(values, 100, "('%s', '%s')", title, due_date);
|
||||||
}
|
}else{
|
||||||
else if (x_strcmp(argv[1], "new") == 0){
|
colnames = "(title)";
|
||||||
rc = add_new_task(db,argc,argv);
|
snprintf(values, 100, "('%s')", title);
|
||||||
}
|
|
||||||
else if (x_strcmp(argv[1], "del") == 0){
|
|
||||||
rc = del_task(db,argc,argv);
|
|
||||||
}
|
|
||||||
else if (x_strcmp(argv[1], "today") == 0){
|
|
||||||
rc = update_task_status(db,argc,argv);
|
|
||||||
}
|
|
||||||
else if (x_strcmp(argv[1], "blocked") == 0){
|
|
||||||
rc = update_task_status(db,argc,argv);
|
|
||||||
}
|
|
||||||
else if (x_strcmp(argv[1], "backlog") == 0){
|
|
||||||
rc = update_task_status(db,argc,argv);
|
|
||||||
}
|
|
||||||
else if (x_strcmp(argv[1], "done") == 0){
|
|
||||||
rc = complete_task(db,argc,argv);
|
|
||||||
}
|
|
||||||
else if (x_strcmp(argv[1], "view_all") == 0){
|
|
||||||
rc = view_all(db);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
rc = view_tasks(db);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sqlite3_close(db);
|
if ( gen_sql_insert_stmt(db, &out_stmt, table, colnames, values) ){
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
if ( ( rc = sqlite3_step(out_stmt) ) == SQLITE_DONE){
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
checksqlerr(rc, "broken in add_new_task");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int update_task_status(sqlite3 *db, int argc, char** argv){
|
||||||
|
int rc = 0;
|
||||||
|
char* table = "tasks";
|
||||||
|
char* title;
|
||||||
|
sqlite3_stmt* out_stmt;
|
||||||
|
parse_args(argc, argv, &title, NULL);
|
||||||
|
|
||||||
|
if ( gen_sql_update_stmt(db, &out_stmt, table, argv[1], title) ){
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( ( rc = sqlite3_step(out_stmt) ) == SQLITE_DONE){
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
checksqlerr(rc, "broken in update_task_status");
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int complete_task(sqlite3 *db, int argc, char** argv){
|
||||||
|
int rc = 0;
|
||||||
|
char* table = "tasks";
|
||||||
|
char* title;
|
||||||
|
sqlite3_stmt* out_stmt;
|
||||||
|
|
||||||
|
parse_args(argc, argv, &title, NULL);
|
||||||
|
if ( gen_sql_update_stmt(db, &out_stmt, table, NULL, title) ){
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( ( rc = sqlite3_step(out_stmt) ) == SQLITE_DONE){
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
checksqlerr(rc, "broken in complete_task");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int del_task(sqlite3 *db, int argc, char** argv){
|
||||||
|
int rc = 0;
|
||||||
|
char* table = "tasks";
|
||||||
|
char* title;
|
||||||
|
sqlite3_stmt* out_stmt;
|
||||||
|
|
||||||
|
parse_args(argc, argv, &title, NULL);
|
||||||
|
if ( gen_sql_delete_stmt(db, &out_stmt, table, title) ){
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( ( rc = sqlite3_step(out_stmt) ) == SQLITE_DONE){
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
checksqlerr(rc, "broken in del_task");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
55
src/dodo.h
Normal file
55
src/dodo.h
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
#ifndef DODO_H
|
||||||
|
#define DODO_H
|
||||||
|
|
||||||
|
#define SQLQUERY_MAX 100
|
||||||
|
#define ARG_MAX 100
|
||||||
|
#define TODAY_COL_START -1
|
||||||
|
#define BACKLOG_COL_START 33
|
||||||
|
#define BLOCKED_COL_START 66
|
||||||
|
#define FIXED_WIDTH 19
|
||||||
|
|
||||||
|
typedef struct{
|
||||||
|
int year;
|
||||||
|
int month;
|
||||||
|
int day;
|
||||||
|
}date;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
int task_id;
|
||||||
|
char* title;
|
||||||
|
int active_id;
|
||||||
|
char* status;
|
||||||
|
date creation_date;
|
||||||
|
date due_date;
|
||||||
|
}task_entry;
|
||||||
|
|
||||||
|
// FOR DEBUG
|
||||||
|
int callback(void *NotUsed, int argc, char **argv, char **azColName);
|
||||||
|
int view_all(sqlite3 *db);
|
||||||
|
|
||||||
|
// sql generators TODO: might be able to boil this down to 1 func
|
||||||
|
int gen_sql_update_stmt(sqlite3 *db, sqlite3_stmt** out_stmt, char* table, char* status, char* title);
|
||||||
|
int gen_sql_delete_stmt(sqlite3 *db, sqlite3_stmt** out_stmt, char* table, char* title);
|
||||||
|
int gen_sql_insert_stmt(sqlite3 *db, sqlite3_stmt** out_stmt, char* table, char* colnames, char* values);
|
||||||
|
int gen_sql_select_stmt(sqlite3 *db, sqlite3_stmt** out_stmt, char* colnames, char* table, char* status);
|
||||||
|
|
||||||
|
// helpers
|
||||||
|
int checksqlerr(int rc, char *errmsg);
|
||||||
|
int opendb(sqlite3 **db, char* filename);
|
||||||
|
void display_heading();
|
||||||
|
int parse_args(int argc, char** argv, char** title, char** due_date);
|
||||||
|
int get_num_rows(sqlite3 *db, char* table, char* status);
|
||||||
|
int print_fixed_width(const unsigned char* str);
|
||||||
|
int display_task_list(int start_col, sqlite3 *db, char* colnames, char* table, char* status);
|
||||||
|
|
||||||
|
// main functions
|
||||||
|
int view_tasks(sqlite3 *db);
|
||||||
|
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 modify_task(sqlite3 *db, int argc, char** argv);
|
||||||
|
|
||||||
|
|
||||||
|
int del_task(sqlite3 *db, int argc, char** argv);
|
||||||
|
|
||||||
|
#endif
|
50
src/main.c
Normal file
50
src/main.c
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include "sqlite3.h"
|
||||||
|
#include "x_string.h"
|
||||||
|
#include "x_curses.h"
|
||||||
|
#include "dodo.h"
|
||||||
|
|
||||||
|
int main( int argc, char **argv ){
|
||||||
|
sqlite3 *db;
|
||||||
|
int rc = 0;
|
||||||
|
char* home_dir = getenv("HOME");
|
||||||
|
char* filename = x_strconcat(home_dir, DB_PATH);
|
||||||
|
|
||||||
|
rc = opendb(&db, filename);
|
||||||
|
if ( argv[1] ){
|
||||||
|
if (x_strcmp(argv[1], "view") == 0){
|
||||||
|
rc = view_tasks(db);
|
||||||
|
}
|
||||||
|
else if (x_strcmp(argv[1], "new") == 0){
|
||||||
|
rc = add_new_task(db,argc,argv);
|
||||||
|
}
|
||||||
|
else if (x_strcmp(argv[1], "del") == 0){
|
||||||
|
rc = del_task(db,argc,argv);
|
||||||
|
}
|
||||||
|
else if (x_strcmp(argv[1], "today") == 0){
|
||||||
|
rc = update_task_status(db,argc,argv);
|
||||||
|
}
|
||||||
|
else if (x_strcmp(argv[1], "blocked") == 0){
|
||||||
|
rc = update_task_status(db,argc,argv);
|
||||||
|
}
|
||||||
|
else if (x_strcmp(argv[1], "backlog") == 0){
|
||||||
|
rc = update_task_status(db,argc,argv);
|
||||||
|
}
|
||||||
|
else if (x_strcmp(argv[1], "done") == 0){
|
||||||
|
rc = complete_task(db,argc,argv);
|
||||||
|
}
|
||||||
|
else if (x_strcmp(argv[1], "view_all") == 0){
|
||||||
|
rc = view_all(db);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
rc = view_tasks(db);
|
||||||
|
}
|
||||||
|
|
||||||
|
sqlite3_close(db);
|
||||||
|
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
57
tests/test_temp.c
Normal file
57
tests/test_temp.c
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
// printf Formating
|
||||||
|
#define X_RED "\x1B[31m"
|
||||||
|
#define X_GREEN "\x1B[32m"
|
||||||
|
#define X_RST "\x1B[0m"
|
||||||
|
|
||||||
|
// INSERT HEADERS FOR FUNCS
|
||||||
|
|
||||||
|
// SET THE NUMBER OF TESTS
|
||||||
|
#define NUM_TESTS 1
|
||||||
|
|
||||||
|
|
||||||
|
// DEFINE TESTS
|
||||||
|
|
||||||
|
|
||||||
|
// DUMMY TEST
|
||||||
|
int fail(){
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// END OF TEST DEFINITIONS
|
||||||
|
|
||||||
|
void run_tests(int (**tests)()){
|
||||||
|
int i = 0;
|
||||||
|
int errors = 0;
|
||||||
|
|
||||||
|
for ( i = 0; i < NUM_TESTS; i++ ){
|
||||||
|
printf("Test #%d... ", i);
|
||||||
|
if ( tests[i]() == 0){
|
||||||
|
printf("%spassed%s\n", X_GREEN, X_RST);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
printf("%sfailed%s\n", X_RED, X_RST);
|
||||||
|
errors++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("Tests completed with %s%d passed%s", X_GREEN, NUM_TESTS - errors, X_RST);
|
||||||
|
printf(" and %s%d failed%s\n", X_RED, errors, X_RST);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(){
|
||||||
|
int (*tests[NUM_TESTS])();
|
||||||
|
|
||||||
|
// PASS TESTS INTO ARRAY
|
||||||
|
tests[0] = fail;
|
||||||
|
|
||||||
|
|
||||||
|
// END OF PASSING TESTS
|
||||||
|
|
||||||
|
// RUN TESTS
|
||||||
|
run_tests(tests);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user