aboutsummaryrefslogtreecommitdiff
path: root/ttt.jai
diff options
context:
space:
mode:
authordam <dam@gudinoff>2023-03-28 03:41:00 +0100
committerdam <dam@gudinoff>2023-03-28 03:41:00 +0100
commitbf8fb0e2a8bd35bfec3f3348d58367b9b6b54a54 (patch)
tree3acd83fe6eaa0f89a76eef0829f5feec8c7507d1 /ttt.jai
parent5108f6062c1045b85ba0e624eab0833326604b86 (diff)
downloadtask-time-tracker-bf8fb0e2a8bd35bfec3f3348d58367b9b6b54a54.tar.zst
task-time-tracker-bf8fb0e2a8bd35bfec3f3348d58367b9b6b54a54.zip
Playing with different hacks to store/load tasks.
Diffstat (limited to 'ttt.jai')
-rw-r--r--ttt.jai35
1 files changed, 8 insertions, 27 deletions
diff --git a/ttt.jai b/ttt.jai
index 42c68d7..9e6af5f 100644
--- a/ttt.jai
+++ b/ttt.jai
@@ -711,36 +711,17 @@ load_database :: (db: *Database, path: string) -> success: bool {
}
// Read database structure.
- read_success = file_read(file, db, size_of(Database));
- db.tasks.data = null; // Discard invalid pointer read into 'data'.
+ read_success = file_read(file, db, size_of(Database) - size_of([..] Task)); // HACK
//if read_success == false print_error("Failed to read database info from '%'.", path); TODO
- //file_open :: (name: string, for_writing := false, keep_existing_content := false, log_errors := true) -> File, bool
- //file_read :: (f: File, vdata: *void, bytes_to_read: s64) -> (success: bool, total_read: s64)
-
-
// Reserve database capacity for tasks. HACK
- value := db.tasks.count;
- d: [..] Task;
- db.tasks = d;
-// array_reserve(*db.tasks, value);
-// db.tasks.count = value;
-
-// size_t capacity_bytes = db->capacity * SIZEOF_TASK_ST;
-// db->tasks = malloc(capacity_bytes);
-// if (db->tasks == NULL && capacity_bytes > 0) {
-// print_error("Failed to allocate memory while loading database: %s.", strerror(errno));
-// return false;
-// }
-//
- // Read database tasks. HACK
- for 0..value-1 {
- task: Task;
- file_read(file, *task, size_of(Task));
- array_add(*db.tasks, task);
- }
-// file_read(file, db.tasks.data, size_of(Task)*db.tasks.count);
-
+ tasks_count: s64;
+ file_read(file, *tasks_count, size_of(s64));
+ t: [2048]u8; file_read(file, *t, size_of([..] Task) - size_of(s64)); // HACK
+ array_reserve(*db.tasks, tasks_count);
+ file_read(file, db.tasks.data, size_of(Task)*tasks_count);
+ db.tasks.count = tasks_count;
+
// Make sure we are reading all the file.
buffer: [1] u8;
success, bytes := file_read(file, *buffer, 1);