aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ttt.jai144
-rw-r--r--unused.jai25
2 files changed, 58 insertions, 111 deletions
diff --git a/ttt.jai b/ttt.jai
index ec35973..7b49eff 100644
--- a/ttt.jai
+++ b/ttt.jai
@@ -328,6 +328,7 @@ get_selected_task :: inline (db: Database) -> *Task {
add_task :: (db: *Database, task: Task) -> success: bool {
assert(db != null, "Parameter 'db' is null.");
+ // TODO Remove old implementation... or use the dynamics arrays?
// idx := db.tasks.count;
// maybe_grow(*db.tasks); // TODO Check for errors?
// db.tasks.count += 1;
@@ -346,7 +347,6 @@ add_task :: (db: *Database, task: Task) -> success: bool {
ifx current_capacity > (S64_MAX >> 1) then S64_MAX else
current_capacity << 1;
- print("expanding from % to %\n", current_capacity, new_capacity);
new_tasks := realloc(db.tasks.data, new_capacity * size_of(Task), current_capacity * size_of(Task));
if (new_tasks == null) {
print_error("Failed to expand database.");
@@ -758,13 +758,9 @@ import_from_csv :: (db: *Database, path: string) -> bool {
data: string;
is_using_map := false;
if size >= 1<<30 {
- print("big file with % MB\n", size>>20); // TODO
- map, success = map_entire_file_start(path);
- data = map.data;
- is_using_map = true;
+ assert(false, "Parsing big files not implemented yet.");
}
else {
- print("small file with % B\n", size); // TODO
data, success = read_entire_file(path);
}
defer if is_using_map then map_entire_file_end(*map); else free(data.data);
@@ -857,7 +853,6 @@ import_from_csv :: (db: *Database, path: string) -> bool {
// reset_temporary_storage();
// }
}
- print("temp: %\n", context.temporary_storage.total_bytes_occupied >> 20);
reset_temporary_storage();
return true;
@@ -1245,13 +1240,7 @@ free_memory :: () {
free(ar_file_path);
//reset_temporary_storage();
}
-
/*
-void exit_gracefully(int signal) {
- flushinp();
- ungetch('q');
-}
-
void read_input_to_string_buffer_with_space(int row, int column, int style, int length, int space) {
assert(length < string_buffer_size);
assert(space < string_buffer_size);
@@ -1482,12 +1471,6 @@ main :: () {
initialize_tui();
- // TODO Remove this?!
- //signal(SIGTERM, exit_gracefully);
- //signal(SIGINT, exit_gracefully);
- //signal(SIGQUIT, exit_gracefully);
- //signal(SIGHUP, exit_gracefully);
-
layout := *layouts[Layouts.COMPACT];
db := *database;
@@ -1766,32 +1749,30 @@ main :: () {
*/
case #char "\n"; #through;
case #char " ";
- if (db != *database || selected_task == null) break;
+ if (db != *database || selected_task == null)
+ break; // BUG The break does not work inside an if_case. Review this and all other usages.
set_active_task(db, ifx (active_task == selected_task) then null else selected_task);
active_task = get_active_task(db);
trigger_autosave();
-
- /*
- case '\t': {
- if (db == &database) {
- if (import_from_csv(&archive, ar_file_path) == false) {
- reset_database(&archive);
+
+ case #char "\t";
+ if (db == *database) {
+ if (import_from_csv(*archive, ar_file_path) == false) {
+ reset_database(*archive);
print_error("Failed to load archive.");
break;
}
- db = &archive;
+ db = *archive;
}
else {
- if (export_to_csv(&archive, ar_file_path) == false) {
+ if (export_to_csv(*archive, ar_file_path) == false) {
print_error("Failed to store archive.");
break;
}
- reset_database(&archive);
- db = &database;
+ reset_database(*archive);
+ db = *database;
}
- break;
- }
-
+/*
case 'a':
case 'A': {
if (db != &database || selected_task == NULL || selected_task == active_task) {
@@ -1857,86 +1838,27 @@ main :: () {
}
// Save any unsaved changes.
-// show_processing();
+ show_processing();
error_saving := false;
-// if (db == &archive) {
-// if (export_to_csv(&archive, ar_file_path) == false) {
-// print_error("Failed to save archive.");
-// error_saving |= true;
-// }
-// }
-// if (countdown_to_autosave > 0 || is_autosave_enabled == false) {
-// if (store_database(&database, db_file_path) == false) {
-// print_error("Failed to save database.");
-// error_saving |= true;
-// }
-// }
-// if (error_saving) {
-// print_error("Press any key to close.");
-// draw_error_window();
-// timeout(INPUT_AWAIT_INF);
-// getch();
-// }
+ if (db == *archive) {
+ if (export_to_csv(archive, ar_file_path) == false) {
+ print_error("Failed to save archive.");
+ error_saving |= true;
+ }
+ }
+ if (countdown_to_autosave > 0 || is_autosave_enabled == false) {
+ if (store_database(database, db_file_path) == false) {
+ print_error("Failed to save database.");
+ error_saving |= true;
+ }
+ }
+ if (error_saving) {
+ print_error("Press any key to close.");
+ draw_error_window();
+ timeout(INPUT_AWAIT_INF);
+ getch();
+ }
endwin();
exit(xx ifx error_saving then 1 else 0);
}
-
-/*
-main :: () {
-
- print("TNL %\n", TASK_NAME_LENGTH);
- print("TNB %\n", TASK_NAME_BYTES);
-
- home, success := get_home_directory();
- print("home '%' | success '%'\n", home, success);
-
- print("Task Time Tracker version %\n", VERSION);
- print("Copyright 2022 Daniel Martins\n");
- print("License GPL-3.0-or-later\n");
-
-// TODO More binding examples here https://github.com/vrcamillo/jai-tracy
-// short : s16
-// int : s32
-// long : s64 (int)
-// single : float32 (float)
-// double : float64
-
- stdscr := initscr();
- curs_set(0);
- noecho();
- box(stdscr, 0, 0);
- while true {
- key := getch();
- if key == #char "q" break;
- mvaddstr(1, 1, "> wow alçapão <");
- }
- endwin();
-
-}
-*/
-
-// TODO DEBUG
-print_owner_allocator :: (tag: string, memory: *void) {
- owner := "unkown";
-
- if true == xx context.allocator.proc(.IS_THIS_YOURS, 0, 0, memory, null) then owner = "default";
- else if true == xx temp.proc(.IS_THIS_YOURS, 0, 0, memory, null) then owner = "temp";
-
- print("'%' belongs to '%'\n", tag, owner);
-}
-
-// TODO DEBUG
-print_database :: (db: Database) {
- for db.tasks {
- print("% | % : % : % : % : % : % : %\n", cast(string)it.name,
- it.times[0],
- it.times[1],
- it.times[2],
- it.times[3],
- it.times[4],
- it.times[5],
- it.times[6]
- );
- }
-}
diff --git a/unused.jai b/unused.jai
index 264fa88..a218aef 100644
--- a/unused.jai
+++ b/unused.jai
@@ -1,5 +1,30 @@
print(">%<", S64_MIN + delta, to_standard_error = true);
+
+// TODO DEBUG
+print_owner_allocator :: (tag: string, memory: *void) {
+ owner := "unkown";
+
+ if true == xx context.allocator.proc(.IS_THIS_YOURS, 0, 0, memory, null) then owner = "default";
+ else if true == xx temp.proc(.IS_THIS_YOURS, 0, 0, memory, null) then owner = "temp";
+
+ print("'%' belongs to '%'\n", tag, owner);
+}
+// TODO DEBUG
+print_database :: (db: Database) {
+ for db.tasks {
+ print("% | % : % : % : % : % : % : %\n", cast(string)it.name,
+ it.times[0],
+ it.times[1],
+ it.times[2],
+ it.times[3],
+ it.times[4],
+ it.times[5],
+ it.times[6]
+ );
+ }
+}
+
// --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- //