diff options
| author | dam <dam@gudinoff> | 2023-07-29 18:47:48 +0100 |
|---|---|---|
| committer | dam <dam@gudinoff> | 2023-07-29 18:47:48 +0100 |
| commit | 1473ed9db288f36c736726da62dd96133023a568 (patch) | |
| tree | e7a6fdd6638524f15615b7f34aabdecd763290dc | |
| parent | f9bbb8fa35f64fe722086c785974e96427c5ab28 (diff) | |
| download | task-time-tracker-1473ed9db288f36c736726da62dd96133023a568.tar.zst task-time-tracker-1473ed9db288f36c736726da62dd96133023a568.zip | |
Fixed bug when trying to duplicate entries.
| -rw-r--r-- | ttt.jai | 45 |
1 files changed, 26 insertions, 19 deletions
@@ -29,6 +29,12 @@ #load "Integer_Saturating_Arithmetic.jai"; +// TODO List: +// [ ] Decide once and for all if we're calling them entries or tasks. +// [ ] Test shrinking mechanism... this may be done by using the coalescing function. +// [ ] Every time we add or remove entries to the database, it may be reallocated, +// thus making the selected_task and active_task pointers invalid. Check this is not messing up the app. + VERSION :: "2.0"; // Use only 3 chars (to fit layouts). YEAR :: "2023"; FIRST_DAY_OF_WEEK :: 1; // (0-6, Sunday = 0). @@ -307,9 +313,12 @@ is_valid_index :: inline(db: Database, index: s64) -> bool { return index >= 0 & // Adds a task to the database and returns it. // If necessary, expands database capacity. -add_task :: (db: *Database, task: Task = .{}) -> task: *Task, index: s64 { +add_task :: (db: *Database, task: *Task = null) -> task: *Task, index: s64 { assert(db != null, ASSERT_NOT_NULL, "db"); - array_add(*db.tasks, task); + + new_task: Task = .{}; + if task != null new_task = <<task; + array_add(*db.tasks, new_task); for * db.total_times { <<it = add(<<it, task.times[it_index]); @@ -350,13 +359,20 @@ delete_task :: (using db: *Database, index: s64) -> bool { // TODO Maybe use `us } // Try to shrink database capacity if using more than 2MB. + // TODO WIP WIP WIP if (tasks.allocated >> 2) > tasks.count && tasks.allocated * SIZE_OF_TASK > 2_000_000 { new_capacity := tasks.allocated >> 1; + msg := tprint("shrinking from % to %\n", tasks.allocated, new_capacity); + print_error(msg); new_tasks_data := realloc(tasks.data, new_capacity * SIZE_OF_TASK, tasks.allocated * SIZE_OF_TASK, tasks.allocator); if new_tasks_data != null { + msg = tprint("OH NOEWS"); + print_error(msg); tasks.data = new_tasks_data; tasks.allocated = new_capacity; } + msg = tprint("ALL OK"); + print_error(msg); } return true; @@ -1477,21 +1493,10 @@ main :: () { for 0..input.count-1 { ch := to_lower(input[it]); if ch == { - case #char "m"; - multiplier = xx SECONDS_IN_MINUTE; - break; - - case #char "h"; - multiplier = xx SECONDS_IN_HOUR; - break; - - case #char "d"; - multiplier = xx SECONDS_IN_DAY; - break; - - case #char "y"; - multiplier = xx SECONDS_IN_YEAR; - break; + case #char "m"; multiplier = xx SECONDS_IN_MINUTE; + case #char "h"; multiplier = xx SECONDS_IN_HOUR; + case #char "d"; multiplier = xx SECONDS_IN_DAY; + case #char "y"; multiplier = xx SECONDS_IN_YEAR; } } @@ -1534,8 +1539,10 @@ main :: () { continue; } - add_task(db, selected_task); - + if (add_task(db, selected_task) == null) { + print_error("Failed to duplicate entry."); + continue; + } trigger_autosave(); case KEY_F5; |
