diff options
| -rw-r--r-- | task_tracker.c | 172 |
1 files changed, 162 insertions, 10 deletions
diff --git a/task_tracker.c b/task_tracker.c index 9984618..9bb8f4b 100644 --- a/task_tracker.c +++ b/task_tracker.c @@ -1,7 +1,157 @@ -// Compile with: gcc task_tracker.c -O2 -m64 -lncurses -o task_tracker.x64 +// Compile with: gcc task_tracker.c -Wall -O2 -m64 -lncurses -o task_tracker.x64 -#include <string.h> + +#include <inttypes.h> #include <ncurses.h> +#include <stdlib.h> +#include <string.h> +#include <time.h> + + +int selected_task = -1; + +struct task_event { + char* name; + time_t start; + time_t end; +}; + +struct task_info { + char* name; + uint64_t total_seconds; +}; + + +char** tasks_names = NULL; +uint32_t tasks_names_size = 0; +uint32_t tasks_names_capacity = 0; + +void add_task(char* name) +{ + if (tasks_names_size >= tasks_names_capacity) + { + tasks_names_capacity = tasks_names_capacity == 0 ? 16 : tasks_names_capacity << 1; + tasks_names = realloc(tasks_names, sizeof(char*) * tasks_names_capacity); + /* + uint32_t new_capacity = tasks_names_capacity == 0 ? 16 : tasks_names_capacity << 1; + char** new_memory = malloc(sizeof(char*) * new_capacity); + + if (tasks_names != NULL) + { + memcpy(new_memory, tasks_names, sizeof(char*) * tasks_names_capacity); + free(tasks_names); + } + + tasks_names_capacity = new_capacity; + tasks_names = (char *[])new_memory; + */ + } + tasks_names[tasks_names_size] = name; + tasks_names_size++; + + // TODO Missing the task_info array. +} + +void add_task_event(char* name, uint64_t start, uint64_t end) +{ + // TODO Missing the task_event array. +} + +void fake_data() +{ + const char* csv_head = "task_name,start,end"; + const char* csv_line[] = { + "PI-0000,1659479138,1659482738", + "PI-0001,1659479127,1659482727", + "XPTO-01 : testing long name,1659479138,1659482738", + "Olá vamos cantar uma canção.,1659479127,1659482727", + "[ TST-00 á],1659479138,1659482738", + "[ XPTO- 01,1659479127,1659482727", + "[ TST-00 á],1659479138,1659482738", + "[ XPTO- 01,1659479127,1659482727", + "[ TST-00 á],1659479138,1659482738", + "[ XPTO- 01,1659479127,1659482727", + "[ TST-00 á],1659479138,1659482738", + "[ XPTO- 01,1659479127,1659482727", + "[ TST-00 á],1659479138,1659482738", + "[ XPTO- 01,1659479127,1659482727", + "[ TST-00 á],1659479138,1659482738", + "[ XPTO- 01,1659479127,1659482727", + "[ TST-00 á],1659479138,1659482738", + "[ XPTO- 01,1659479127,1659482727", + "[ TST-00 á],1659479138,1659482738", + "[ XPTO- 01,1659479127,1659482727", + }; +// const char* csv_line = "1659479138,1659482738"; +// const char* csv_line = "zZ[ ã ]Yy,123"; + +// char name[] = { 'a', 'b', 'c', '\0' }; + char* name; + uint64_t start; + uint64_t end; + printf("--- --- àè.ªãº.éá --- ---\n"); + + uint32_t lines_count = sizeof(csv_line)/sizeof(char*); + for (uint32_t idx = 0; idx < lines_count; idx++) + { + sscanf(csv_line[idx], "%m[^,\n],%" SCNu64 ",%" SCNu64, &name, &start, &end); + add_task(name); + printf("bazinga: %s : %d : %d\n", name, start, end); + } + + printf("### ### --------- ### ###\n"); + + + +// tasks_names = + + + // Free tasks names. + for (uint32_t idx = tasks_names_size; idx > 0; idx--) + { + printf("> %s\n", tasks_names[idx-1]); + free(tasks_names[idx-1]); + } + free(tasks_names); + + return; + /* + char *token, *copy, *to_free; + copy = to_free = strdup(csv_line); + + + while ( token = strsep(&str, ",") ) + { + my_fn(token); + } + free(to_free); + */ + + +// tasks_names = malloc( ... + + time_t x = time(NULL); +// x = (time_t)((1U << 32) - 1); + printf("%s\n", ctime(&x)); + x = x<<1; + printf("%s\n", ctime(&x)); + x += 1; + printf("%s\n", ctime(&x)); + x = x<<1; + printf("%s\n", ctime(&x)); + x = x<<1; + printf("%s\n", ctime(&x)); + x = x<<1; + printf("%s\n", ctime(&x)); + x = x<<1; + printf("%s\n", ctime(&x)); +} + + +void draw_table() +{ + struct task_info asd; +} void draw_header() @@ -33,11 +183,6 @@ void draw_header() addch(ACS_URCORNER); } -void draw_table() -{ - -} - void draw_footer() { const char *app_name = "Task Tracker"; @@ -67,7 +212,12 @@ WINDOW *create_newwin(int height, int width, int starty, int startx); void destroy_win(WINDOW *local_win); int main(int argc, char *argv[]) -{ WINDOW *my_win; +{ + fake_data(); + return 0; + + + WINDOW *my_win; int startx, starty, width, height; int ch; @@ -85,8 +235,10 @@ int main(int argc, char *argv[]) refresh(); my_win = create_newwin(height, width, starty, startx); - int rows; - int colums; + int rows; + int colums; + + fake_data(); ch = KEY_RESIZE; do { |
