Modified display_task_list to display active id
This commit is contained in:
parent
175b621d7a
commit
98378e80e0
13
Makefile
13
Makefile
@ -40,7 +40,7 @@ DFLAGS = -DDB_PATH=\"$(DB_FILE)\"
|
|||||||
|
|
||||||
all: dodo
|
all: dodo
|
||||||
|
|
||||||
$(OBJ): $(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_HEADERS)
|
||||||
@ -49,12 +49,13 @@ $(X_STRING_OBJ): $(X_STRING_HEADERS)
|
|||||||
$(SQLITE_OBJ): $(SQLITE_HEADERS)
|
$(SQLITE_OBJ): $(SQLITE_HEADERS)
|
||||||
$(CC) -c -o $(OBJ_DIR)/$(@F) $(CFLAGS) $(SQLITE_SRC)
|
$(CC) -c -o $(OBJ_DIR)/$(@F) $(CFLAGS) $(SQLITE_SRC)
|
||||||
|
|
||||||
dodo: $(OBJ)
|
dodo: test $(OBJ) $(X_STRING_OBJ) $(SQLITE_OBJ)
|
||||||
$(CC) -o $@ $(CFLAGS) $(ALL_OBJS)
|
$(CC) -o $@ $(CFLAGS) $(OBJ) $(X_STRING_OBJ) $(SQLITE_OBJ)
|
||||||
|
|
||||||
test: $(OBJ) $(TEST_SRC)
|
|
||||||
$(CC) -o $@ $(TEST_SRC) $(INC_DIRS) $(DFLAGS) $(CFLAGS) obj/dodo.o $(X_STRING_OBJ) $(SQLITE_OBJ)
|
|
||||||
./test
|
./test
|
||||||
|
rm ./test
|
||||||
|
|
||||||
|
test: $(OBJ) $(TEST_SRC) $(X_STRING_OBJ) $(SQLITE_OBJ)
|
||||||
|
$(CC) -o $@ $(TEST_SRC) $(INC_DIRS) $(DFLAGS) $(CFLAGS) obj/dodo.o $(X_STRING_OBJ) $(SQLITE_OBJ)
|
||||||
|
|
||||||
|
|
||||||
install:
|
install:
|
||||||
|
91
src/dodo.c
91
src/dodo.c
@ -116,18 +116,64 @@ int opendb(sqlite3 **db, char* filename){
|
|||||||
return(rc);
|
return(rc);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Print Heading TODO: obvi make this better
|
void display_task_list_heading(char* heading){
|
||||||
void display_heading(){
|
int width = (FIXED_ID_WIDTH + FIXED_TITLE_WIDTH + FIXED_DATE_WIDTH + x_strlen(heading) );
|
||||||
|
int width_div_2 = width / 2;
|
||||||
|
printf("%s%*s", X_BOLD, width_div_2, heading);
|
||||||
|
printf("%*s", width_div_2 - x_strlen(heading), "");
|
||||||
|
printf(" ");
|
||||||
|
}
|
||||||
|
|
||||||
|
void display_column_heading(const char* str){
|
||||||
|
int width = 0;
|
||||||
|
|
||||||
|
if ( x_strcmp(str, "id") == 0 ){
|
||||||
|
width = FIXED_ID_WIDTH;
|
||||||
|
}
|
||||||
|
else if ( x_strcmp(str, "title") == 0 ){
|
||||||
|
width = FIXED_TITLE_WIDTH;
|
||||||
|
}
|
||||||
|
else if ( x_strcmp(str, "due_date") == 0 ){
|
||||||
|
width = FIXED_DATE_WIDTH;
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
width = FIXED_MAX_WIDTH;
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("%s%s%-*.*s%s", X_BOLD, X_UNDL, width, width, str, X_RST);
|
||||||
|
}
|
||||||
|
|
||||||
|
void display_column_headings_for_all_task_lists(){
|
||||||
|
int i = 0;
|
||||||
|
char* str;
|
||||||
|
for ( i = 0; i < NUM_TASK_LISTS; i++){
|
||||||
|
str = "id";
|
||||||
|
display_column_heading(str);
|
||||||
|
str = "title";
|
||||||
|
display_column_heading(str);
|
||||||
|
str = "due_date";
|
||||||
|
display_column_heading(str);
|
||||||
|
printf(" ");
|
||||||
|
}
|
||||||
printf("\n");
|
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);
|
// Print Heading
|
||||||
|
void display_heading(){
|
||||||
|
char* colnames = "active_id,title,due_date";
|
||||||
|
char * str;
|
||||||
|
int width = 0;
|
||||||
|
|
||||||
|
printf("\n");
|
||||||
|
str = "Today";
|
||||||
|
display_task_list_heading(str);
|
||||||
|
str = "Backlog";
|
||||||
|
display_task_list_heading(str);
|
||||||
|
str = "Blocked";
|
||||||
|
display_task_list_heading(str);
|
||||||
printf("\n");
|
printf("\n");
|
||||||
|
|
||||||
printf("%s%stitle due date %s", X_BOLD, X_UNDL, X_RST);
|
display_column_headings_for_all_task_lists();
|
||||||
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
|
// pass in the args and return the title and due date
|
||||||
@ -162,11 +208,11 @@ int get_num_rows(sqlite3 *db, char* table, char* status){
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Print with FIXED_WIDTH
|
// Print with FIXED_WIDTH
|
||||||
int print_fixed_width(const unsigned char* str){
|
int print_fixed_width(const unsigned char* str, int width){
|
||||||
if (str){
|
if (str){
|
||||||
printf("%-*.*s", FIXED_WIDTH, FIXED_WIDTH, str);
|
printf("%-*.*s", width, width, str);
|
||||||
}else{
|
}else{
|
||||||
printf("%-*.*s", FIXED_WIDTH, FIXED_WIDTH, "");
|
printf("%-*.*s", width, width, "");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -177,12 +223,12 @@ int display_task_list(int start_col, sqlite3 *db, char* colnames, char* table, c
|
|||||||
int i = 0;
|
int i = 0;
|
||||||
int num_rows = -1;
|
int num_rows = -1;
|
||||||
int num_cols = 0;
|
int num_cols = 0;
|
||||||
|
int fixed_width = 0;
|
||||||
char* errmsg;
|
char* errmsg;
|
||||||
const unsigned char* col_val;
|
const unsigned char* col_val;
|
||||||
|
const unsigned char* col_name;
|
||||||
sqlite3_stmt* out_stmt;
|
sqlite3_stmt* out_stmt;
|
||||||
|
|
||||||
// Start col for the current task list
|
|
||||||
X_goright(start_col);
|
|
||||||
|
|
||||||
// Get the number of rows in current task list
|
// Get the number of rows in current task list
|
||||||
num_rows = get_num_rows(db, table, status);
|
num_rows = get_num_rows(db, table, status);
|
||||||
@ -197,13 +243,26 @@ int display_task_list(int start_col, sqlite3 *db, char* colnames, char* table, c
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TODO: prob should be a func begin
|
// TODO: prob should be a func begin
|
||||||
|
// Start col for the current task list
|
||||||
|
X_goright(start_col);
|
||||||
|
|
||||||
// while there is still rows available
|
// while there is still rows available
|
||||||
while ( rc = sqlite3_step(out_stmt) == SQLITE_ROW ){
|
while ( rc = sqlite3_step(out_stmt) == SQLITE_ROW ){
|
||||||
// for each column print the column
|
// for each column print the column
|
||||||
num_cols = sqlite3_column_count(out_stmt);
|
num_cols = sqlite3_column_count(out_stmt);
|
||||||
for (i = 0; i < num_cols; i++){
|
for (i = 0; i < num_cols; i++){
|
||||||
col_val = sqlite3_column_text(out_stmt, i);
|
col_val = sqlite3_column_text(out_stmt, i);
|
||||||
print_fixed_width(col_val);
|
col_name = sqlite3_column_name(out_stmt, i);
|
||||||
|
if ( x_strcmp(col_name, "title") == 0 ){
|
||||||
|
fixed_width = FIXED_TITLE_WIDTH;
|
||||||
|
}
|
||||||
|
else if ( x_strcmp(col_name, "active_id") == 0 ){
|
||||||
|
fixed_width = FIXED_ID_WIDTH;
|
||||||
|
}
|
||||||
|
else if ( x_strcmp(col_name, "due_date") == 0 ){
|
||||||
|
fixed_width = FIXED_DATE_WIDTH;
|
||||||
|
}
|
||||||
|
print_fixed_width(col_val, fixed_width);
|
||||||
}
|
}
|
||||||
// move down one and over to the start of the current task column
|
// move down one and over to the start of the current task column
|
||||||
printf("\n");
|
printf("\n");
|
||||||
@ -236,7 +295,7 @@ int display_task_list(int start_col, sqlite3 *db, char* colnames, char* table, c
|
|||||||
int view_tasks(sqlite3 *db){
|
int view_tasks(sqlite3 *db){
|
||||||
char* table = "tasks";
|
char* table = "tasks";
|
||||||
char* status = "today";
|
char* status = "today";
|
||||||
char* colnames = "title,due_date";
|
char* colnames = "active_id,title,due_date";
|
||||||
|
|
||||||
// Print Heading
|
// Print Heading
|
||||||
display_heading();
|
display_heading();
|
||||||
|
13
src/dodo.h
13
src/dodo.h
@ -3,10 +3,15 @@
|
|||||||
|
|
||||||
#define SQLQUERY_MAX 100
|
#define SQLQUERY_MAX 100
|
||||||
#define ARG_MAX 100
|
#define ARG_MAX 100
|
||||||
|
#define NUM_TASK_LISTS 3
|
||||||
|
#define FIXED_TITLE_WIDTH 19
|
||||||
|
#define FIXED_DATE_WIDTH 14
|
||||||
|
#define FIXED_ID_WIDTH 4
|
||||||
|
#define FIXED_COLUMN_WIDTH (FIXED_ID_WIDTH + FIXED_TITLE_WIDTH +FIXED_DATE_WIDTH)
|
||||||
|
#define FIXED_MAX_WIDTH (FIXED_COLUMN_WIDTH)
|
||||||
#define TODAY_COL_START -1
|
#define TODAY_COL_START -1
|
||||||
#define BACKLOG_COL_START 33
|
#define BACKLOG_COL_START (FIXED_COLUMN_WIDTH + 1)
|
||||||
#define BLOCKED_COL_START 66
|
#define BLOCKED_COL_START (2 * (FIXED_COLUMN_WIDTH + 1))
|
||||||
#define FIXED_WIDTH 19
|
|
||||||
|
|
||||||
typedef struct{
|
typedef struct{
|
||||||
int year;
|
int year;
|
||||||
@ -39,7 +44,7 @@ int opendb(sqlite3 **db, char* filename);
|
|||||||
void display_heading();
|
void display_heading();
|
||||||
int parse_args(int argc, char** argv, char** title, char** due_date);
|
int parse_args(int argc, char** argv, char** title, char** due_date);
|
||||||
int get_num_rows(sqlite3 *db, char* table, char* status);
|
int get_num_rows(sqlite3 *db, char* table, char* status);
|
||||||
int print_fixed_width(const unsigned char* str);
|
int print_fixed_width(const unsigned char* str, int width);
|
||||||
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);
|
||||||
|
|
||||||
// main functions
|
// main functions
|
||||||
|
Loading…
Reference in New Issue
Block a user