aboutsummaryrefslogtreecommitdiff
path: root/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'main.c')
-rw-r--r--main.c41
1 files changed, 22 insertions, 19 deletions
diff --git a/main.c b/main.c
index 2c60813..b6cbda1 100644
--- a/main.c
+++ b/main.c
@@ -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;