feat: odin setup
This commit is contained in:
29
utils/utils.odin
Normal file
29
utils/utils.odin
Normal file
@@ -0,0 +1,29 @@
|
||||
package utils
|
||||
|
||||
import "core:bufio"
|
||||
import "core:fmt"
|
||||
import "core:os"
|
||||
import "core:strings"
|
||||
|
||||
read_input_lines :: proc(allocator := context.allocator) -> []string {
|
||||
lines := make([dynamic]string, allocator)
|
||||
|
||||
scanner: bufio.Scanner
|
||||
bufio.scanner_init(&scanner, os.to_stream(os.stdin))
|
||||
defer bufio.scanner_destroy(&scanner)
|
||||
|
||||
for bufio.scanner_scan(&scanner) {
|
||||
line := strings.clone(bufio.scanner_text(&scanner), allocator)
|
||||
append(&lines, line)
|
||||
}
|
||||
|
||||
if err := bufio.scanner_error(&scanner); err != nil {
|
||||
fmt.eprintfln("ERROR: Scanning input: %v", err)
|
||||
}
|
||||
|
||||
for len(lines) > 0 && len(lines[len(lines) - 1]) == 0 {
|
||||
pop(&lines)
|
||||
}
|
||||
|
||||
return lines[:]
|
||||
}
|
||||
Reference in New Issue
Block a user