diff options
| -rw-r--r-- | main.c | 41 | ||||
| -rw-r--r-- | readme.md | 3 |
2 files changed, 23 insertions, 21 deletions
@@ -177,7 +177,7 @@ char *format_time(char* string, intmax_t time, int length) { return string; } -int64_t add_time(int64_t x, int64_t y) { +int64_t add_int64(int64_t x, int64_t y) { if (y > 0 && x > INT64_MAX - y) return INT64_MAX; @@ -188,7 +188,7 @@ int64_t add_time(int64_t x, int64_t y) { return x + y; } -int64_t sub_time(int64_t x, int64_t y) { +int64_t sub_int64(int64_t x, int64_t y) { if (y < 0 && x > INT64_MAX + y) return INT64_MAX; @@ -280,7 +280,7 @@ bool add_task(database_st *db, task_st *task) { // Add task timer values to total timers. for (int idx = 0; idx < NUM_WEEK_DAYS; idx++) { // db->total_times[idx] += task->times[idx]; TODO - db->total_times[idx] = add_time(db->total_times[idx], task->times[idx]); + db->total_times[idx] = add_int64(db->total_times[idx], task->times[idx]); } return true; @@ -296,7 +296,7 @@ bool delete_task(database_st *db, task_st *task) { // Remove task timer values from total timers. for (int idx = 0; idx < NUM_WEEK_DAYS; idx++) { // db->total_times[idx] -= task->times[idx]; TODO - db->total_times[idx] = sub_time(db->total_times[idx], task->times[idx]); + db->total_times[idx] = sub_int64(db->total_times[idx], task->times[idx]); } // Move tasks after the index position to their new positions. @@ -505,7 +505,7 @@ bool import_from_csv(database_st *db, const char *path) { // Add task timer values to total timers. for (int idx = 0; idx < NUM_WEEK_DAYS; idx++) { // db->total_times[idx] += task->times[idx]; TODO - db->total_times[idx] = add_time(db->total_times[idx], task->times[idx]); + db->total_times[idx] = add_int64(db->total_times[idx], task->times[idx]); } } @@ -587,7 +587,6 @@ void update_timers(database_st *db) { } void update_total_timers(database_st *db) { - int64_t *d0 = &db->total_times[0]; int64_t *d1 = &db->total_times[1]; int64_t *d2 = &db->total_times[2]; @@ -599,13 +598,13 @@ void update_total_timers(database_st *db) { for (size_t idx = 0; idx < db->count; idx++) { int64_t *times = db->tasks[idx].times; - *d0 = add_time(*d0, times[0]); - *d1 = add_time(*d1, times[1]); - *d2 = add_time(*d2, times[2]); - *d3 = add_time(*d3, times[3]); - *d4 = add_time(*d4, times[4]); - *d5 = add_time(*d5, times[5]); - *d6 = add_time(*d6, times[6]); + *d0 = add_int64(*d0, times[0]); + *d1 = add_int64(*d1, times[1]); + *d2 = add_int64(*d2, times[2]); + *d3 = add_int64(*d3, times[3]); + *d4 = add_int64(*d4, times[4]); + *d5 = add_int64(*d5, times[5]); + *d6 = add_int64(*d6, times[6]); } } @@ -850,7 +849,7 @@ void draw_tui(database_st *db, layout_st *layout) { column_width = layout->columns[L_DAYS_IDX + day_idx].width; int64_t task_stime = task->times[day_idx]; - total_time = add_time(total_time, task_stime); + total_time = add_int64(total_time, task_stime); format_time(string_buffer, task_stime, column_width); mvaddstr(y, x, string_buffer); x += column_width; @@ -885,7 +884,7 @@ void draw_tui(database_st *db, layout_st *layout) { x++; column_width = layout->columns[L_DAYS_IDX + idx].width; - total_time = add_time(total_time, daily_total); + total_time = add_int64(total_time, daily_total); format_time(string_buffer, daily_total, column_width); // Apply theme. @@ -1203,8 +1202,10 @@ int main(int argc, char *argv[]) { } case KEY_PPAGE: { - db->selected_task -= NUM_TABLE_ROWS; - if (db->selected_task < 0) { + if (db->selected_task > NUM_TABLE_ROWS) { + db->selected_task -= NUM_TABLE_ROWS; + } + else if (db->count > 0) { db->selected_task = 0; } break; @@ -1225,8 +1226,10 @@ int main(int argc, char *argv[]) { } case KEY_NPAGE: { - db->selected_task += NUM_TABLE_ROWS; - if (db->selected_task >= db->count) { + if (db->selected_task < db->count - NUM_TABLE_ROWS) { + db->selected_task += NUM_TABLE_ROWS; + } + else if (db->count > 0) { db->selected_task = db->count - 1; } break; @@ -41,11 +41,10 @@ Task Time Tracker - [x] By default, store files on `~/.config/task_time_tracker/` or `~/.local/share/task_time_tracker` and allow to store elsewhere if passed by argument `--config`. - [x] Allow usage of `ttt: ./ttt --dpath ./` to change the app folder: To changes app data path change the environment variable HOME (USERPROFILE for windows users). - [x] Clone (replicate) task; If task is active, mark newly created task as inactive; +- [x] Check if next/previous is safe against overflows/underflows using https://gcc.gnu.org/onlinedocs/gcc/Integer-Overflow-Builtins.html - [ ] Confirm delete_task operation. - For actions that require confirmation, show confirmation message on selected line (horizontally centered) saying "Press enter to delete/archive. Any other to cancel." and await on `getch` for a `\n`. On archiving action this should only occur if the task is active. Use red/black for confirmation message surrounded by diamonds. Implement this using a function `bool get_confirmation(const char *message)`. -- [ ] Check if next/previous is safe against overflows/underflows using https://gcc.gnu.org/onlinedocs/gcc/Integer-Overflow-Builtins.html - [ ] Check totals update speedup using https://gcc.gnu.org/onlinedocs/gcc/Integer-Overflow-Builtins.html -- [ ] Detect if using gcc https://stackoverflow.com/questions/28166565/detect-gcc-as-opposed-to-msvc-clang-with-macro - [ ] Change task order (using task_t tmp_task + memcpy); - [ ] Allow to jump to specific task by index number using key `g` and `G`; - [ ] Add/remove time using keys: `F3`; |
