aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordam <dam@gudinoff>2024-07-24 12:27:45 +0100
committerdam <dam@gudinoff>2024-07-24 12:27:45 +0100
commit10045da39d6eb6aa767b360fbea43d5361383c15 (patch)
tree3d446fea64825893f832b4e01a742d23f3da8c62
parentb8eeb1f44b083ecc25bdaa351540beeab112af07 (diff)
downloadtask-time-tracker-10045da39d6eb6aa767b360fbea43d5361383c15.tar.zst
task-time-tracker-10045da39d6eb6aa767b360fbea43d5361383c15.zip
Improved robustness of CSV line parsing.v3.1
-rw-r--r--ttt.jai24
1 files changed, 11 insertions, 13 deletions
diff --git a/ttt.jai b/ttt.jai
index 2bbc90d..cc6ec0d 100644
--- a/ttt.jai
+++ b/ttt.jai
@@ -14,7 +14,7 @@ DEBUG :: false;
#import "UTF8";
TUI :: #import "TUI"(COLOR_MODE_BITS=4);
-VERSION :: "3.0"; // Use only 3 chars (to fit layouts).
+VERSION :: "3.1"; // Use only 3 chars (to fit layouts).
YEAR :: "2024";
NUM_WEEK_DAYS :: 7;
@@ -175,14 +175,6 @@ hide_processing :: () {
TUI.tui_write_string(TUI.Commands.TextMode);
}
-// Advance to next item in array.
-advance :: inline (array: *[] $T, amount: int = 1) {
- assert(amount >= 0);
- assert(array.count >= amount);
- array.count -= amount;
- array.data += amount;
-}
-
// Advances to next line and returns it.
// Taken from Text_File_Handler module.
// Returns the next line and success.
@@ -645,8 +637,6 @@ load_app_state :: (db: *Database, st_path: string, db_path: string) -> success:
case "first_day_of_week";
first_day_of_week = abs(string_to_int(value)) % NUM_WEEK_DAYS;
}
-
- advance(*csv_line);
}
// Adjust selected task.
@@ -721,12 +711,20 @@ import_from_csv :: (db: *Database, path: string) -> bool #must {
task: Task;
csv_line := split(line, CSV_SEPARATOR,, temporary_allocator);
-
+
+ if csv_line.count != 8 {
+ log_error("Discarded invalid CSV entry '%' from file '%'.", line, path);
+ continue;
+ }
+
// Truncate and import task name.
task_name := truncate(csv_line[0], task.name.count);
memcpy(task.name.data, task_name.data, task_name.count);
+
+ // Advance to next item in csv_line array.
+ csv_line.count -= 1;
+ csv_line.data += 1;
- advance(*csv_line);
for csv_line
task.times[it_index] = string_to_int(it);