From 1012edf3b15f707824a78977ec8a831da2ea845e Mon Sep 17 00:00:00 2001 From: San Jacobs Date: Fri, 23 Jan 2026 19:48:13 +0100 Subject: Fixed memory corruption and prettier printing --- build.bat | 8 +++++++- main.odin | 43 +++++++++++++++++++++++++++---------------- 2 files changed, 34 insertions(+), 17 deletions(-) diff --git a/build.bat b/build.bat index 859a75c..944c2ed 100644 --- a/build.bat +++ b/build.bat @@ -1 +1,7 @@ -odin build . -out:statics.exe && statics.exe "test-data.ics" -i 2025-08 -v -s Test \ No newline at end of file +odin build . -debug -out:statics.exe + +if %ERRORLEVEL% == 0 ( + statics.exe "test-data.ics" -i 2025-08 -v -s Test + mkdir release + odin build . -o:speed -out:release/statics.exe +) diff --git a/main.odin b/main.odin index f269a70..ca0ccc6 100644 --- a/main.odin +++ b/main.odin @@ -50,7 +50,7 @@ main :: proc() { windows.SetConsoleOutputCP(windows.CODEPAGE.UTF8) } exe_dir, _ = os2.get_executable_directory(context.allocator) - data_dir = fmt.tprint(exe_dir, "statics_data", sep = SEPARATOR) + data_dir = fmt.tprint(exe_dir, "statics_data", sep = SEPARATOR) alias_dir = fmt.tprint(data_dir, "aliases", sep = SEPARATOR) ics_cache_dir = fmt.tprint(data_dir, "ics_cache", sep = SEPARATOR) @@ -77,7 +77,7 @@ main :: proc() { } } - lower := strings.to_lower(arg, context.temp_allocator) + lower := strings.to_lower(arg, context.allocator) // I feel like there's a platform that doesn't supply the executable // as the first argument, so I'm doing this at runtime just in case @@ -154,18 +154,21 @@ main :: proc() { parsing = .ALIAS } case .FROM: - parse_to_filter(&arg, &from_filter) + text := strings.clone(arg) + parse_to_filter(text, &from_filter) filters |= {.FROM} fmt.println("FROM filter set up from", momentToString(from_filter.time)) parsing = .NONE case .TO: - parse_to_filter(&arg, &to_filter) + text := strings.clone(arg) + parse_to_filter(text, &to_filter) filters |= {.TO} fmt.println("TO filter set up to", momentToString(to_filter.time)) filter_maxx(&to_filter) parsing = .NONE case .IN: - parse_to_filter(&arg, &in_filter) + text := strings.clone(arg) + parse_to_filter(text, &in_filter) in_filter_out = in_filter filter_maxx(&in_filter_out) filters |= {.IN} @@ -207,28 +210,33 @@ main :: proc() { if ok { minutes : int = 0 for each_block in timeblocks { - if verbose do fmt.println("Block:", timeblockToString(each_block)) pass := true + pass_from : bool = true + pass_to : bool = true + pass_in : bool = true + pass_substring : bool = true if .FROM in filters { - pass_from := greatEq(each_block.start, from_filter.time) - if verbose do if !pass_from do fmt.println(" └ FILTERED! By From filter.") + pass_from = greatEq(each_block.start, from_filter.time) pass &= pass_from } if .TO in filters { - pass_to := lessEq(each_block.start, to_filter.time) - if verbose do if !pass_to do fmt.println(" └ FILTERED! By To filter.") + pass_to = lessEq(each_block.start, to_filter.time) pass &= pass_to } if .IN in filters { - pass_in := lessEq(in_filter.time, each_block.start) && lessEq(each_block.start, in_filter_out.time) - if verbose do if !pass_in do fmt.println(" └ FILTERED! By In filter.") + pass_in = lessEq(in_filter.time, each_block.start) && lessEq(each_block.start, in_filter_out.time) pass &= pass_in } if .SUBSTRING in filters { - pass_substring := strings.contains(each_block.title, substring) - if verbose do if !pass_substring do fmt.println(" └ FILTERED! By Substring filter.") + pass_substring = strings.contains(each_block.title, substring) pass &= pass_substring } + icon := pass ? "✅" : "🚫" + if verbose do fmt.println(icon, timeblockToString(each_block)) + if verbose && !pass_from do fmt.println(" FILTERED! By From filter.") + if verbose && !pass_to do fmt.println(" FILTERED! By To filter.") + if verbose && !pass_in do fmt.println(" FILTERED! By In filter.") + if verbose && !pass_substring do fmt.println(" FILTERED! By Substring filter.") if !pass do continue @@ -256,14 +264,17 @@ main :: proc() { fmt.printf(" Hour count: %f\nHours & Minutes: %d:%02d\n\n", display_hour_count, display_hours, display_minutes) } + + fmt.println("About to exit!") os.exit(0) } -parse_to_filter :: proc(input : ^string, filter : ^Filter) { +parse_to_filter :: proc(input : string, filter : ^Filter) { + input := input i : int = 0 ok : bool - for substring in strings.split_iterator(input, "-") { + for substring in strings.split_iterator(&input, "-") { switch i { case 0: filter.time.year, ok = strconv.parse_int(substring) -- cgit v1.2.1