aboutsummaryrefslogtreecommitdiff
path: root/ttt.jai
diff options
context:
space:
mode:
Diffstat (limited to 'ttt.jai')
-rw-r--r--ttt.jai118
1 files changed, 51 insertions, 67 deletions
diff --git a/ttt.jai b/ttt.jai
index 7612f1b..392b692 100644
--- a/ttt.jai
+++ b/ttt.jai
@@ -20,6 +20,7 @@
#import "Basic";
#import "System";
#import "Math";
+#import "POSIX";
#import "File";
#import "String";
#import "curses";
@@ -700,17 +701,38 @@ bool export_to_csv(const database_st *db, const char *path) {
// Returns success.
import_from_csv :: (db: *Database, path: string) -> bool {
+ // TODO WIP
+
assert(db != null, "Parameter 'db' is null.");
assert(xx path, "Parameter 'path' is empty.");
+ error_code: s64;
+
+ // Check file size
+ file_info: stat_t;
+ error_code = sys_stat(path, *file_info); // TODO Check for error.
+ size := file_info.st_size;
+
+ success: bool;
+ map: Map_File_Info;
+ 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;
+ }
+ 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);
+ csv := data;
- // Read file.
- file_data, success := read_entire_file(path); // TODO Read entire file... may fail it file is too big.
if success == false {
print_error("Failed to read file '%' while loading database: ERROR_FROM_LOG", path); // TODO Get error from logger ?!
return false;
}
- defer free(file_data.data);
- csv := file_data;
// TODO Helper function.
consume_next_line :: (sp: *string) -> string, bool {
@@ -753,9 +775,24 @@ import_from_csv :: (db: *Database, path: string) -> bool {
array.data += amount;
}
+ next_line :: inline (csv: *string) -> line: string, success: bool {
+ for 0..csv.count {
+ if csv.data[it] == #char "\n" {
+ line: string = <<csv;
+ line.count = it;
+ csv.data += it + 1;
+ csv.count -= it + 1;
+ return line, true;
+ }
+ }
+ return "", false;
+ }
+
// Parse CSV lines.
+ line := csv;
while (true) {
line, success := consume_next_line(*csv);
+// line, success := next_line(*csv);
if success == false break;
task: Task;
@@ -767,8 +804,14 @@ import_from_csv :: (db: *Database, path: string) -> bool {
}
add_task(db, *task);
+// if context.temporary_storage.total_bytes_occupied > (100<<20) {
+// print("temp: %\n", context.temporary_storage.total_bytes_occupied >> 20);
+// reset_temporary_storage();
+// }
}
-
+ print("temp: %\n", context.temporary_storage.total_bytes_occupied >> 20);
+ reset_temporary_storage();
+
return false;
}
/*
@@ -1252,76 +1295,17 @@ main :: () {
}
-
- { // Try out the mapping file in linux.
- //a, b := file_open(db_file_path);
- //c, d := file_open(ar_file_path);
- mfi, success := map_entire_file_start(ar_file_path);
- print("Success is %\n", success);
- //print("MFI is %\n", mfi);
- print("MFI.data.count is %\n", mfi.data.count);
- //print("MFI.data.data[1] is %\n", mfi.data.data[123]);
- print("%\n", ifx success then "success" else "fail");
- print("--------------------------------------\n");
- //print(">>>%\n", mfi.map_info.file.handle.unknown_pre[111]);
- //print("###%\n", mfi.map_info.file.handle._file);
- print("###%\n", mfi.map_info.file_descriptor);
- //file_h := c.handle;
- //for file_h.cena
- //if it == 4 {
- //data := file_h.cena.data;
- //print("HERE[%] = %\n", it_index-4, data[it-4]);
- //print("HERE[%] = %\n", it_index-3, data[it-3]);
- //print("HERE[%] = %\n", it_index-2, data[it-2]);
- //print("HERE[%] = %\n", it_index-1, data[it-1]);
- //print("HERE[%] = %\n", it_index, it);
- //print("HERE[%] = %\n", it_index+1, data[it+1]);
- //print("HERE[%] = %\n", it_index+2, data[it+2]);
- //print("HERE[%] = %\n", it_index+3, data[it+3]);
- //print("HERE[%] = %\n", it_index+4, data[it+4]);
- //}
-
- //print("%\n", <<mfi.map_info.file.handle);
- print("> IN LOOP <\n");
- peek :string;
- peek.data = mfi.map_info.data.data;
- peek.count = 1;
- seek := 0;
- while true {
- //sleep_milliseconds(10);
- print("peeking '%'\n", peek);
- peek.data += 100000;
- seek += 100000;
- if seek >= (186880600/2)
- break;
- }
- print("-- peek complete\n");
- print("MFI.data.count is %\n", mfi.data.count);
- sleep_milliseconds(10000);
- print("-- unloading...");
- map_entire_file_end(*mfi);
- print("done\n");
- sleep_milliseconds(10000);
- //print("-- reading entire file");
- //read_entire_file(ar_file_path);
- //print("done\n");
- //sleep_milliseconds(10000);
- return;
- }
-
-
-
db : Database;
{
-
import_from_csv(*db, ar_file_path);
-
- for db.tasks print_task(it);
+
+// for db.tasks print_task(it);
print_task :: (task: Task) {
for task.times print("% |", it);
print(" %\n", cast(string)task.name);
}
+ return;
// Stores data from database into binary file.