This commit is contained in:
Simon Kellet 2026-06-02 22:10:47 +01:00
parent 95b0a90499
commit 1cc56f9b60
4 changed files with 1909603 additions and 17 deletions

View File

@ -24,10 +24,8 @@ main :: proc() {
print_usage()
}
filename := os.args[1]
success := load_ppm(&file, filename)
if !success {
fmt.eprintfln("Could not load file %s", filename)
if ok, err := load_ppm(&file, filename); !ok {
fmt.eprintfln("ERROR: Failed to load file '%s': %s ", filename, os.error_string(err))
os.exit(1)
}
ppm_parse(&file)

Binary file not shown.

View File

@ -1,9 +1,7 @@
package main
import "core:c"
import "core:fmt"
import "core:os"
import "core:os/os2"
import "core:strconv"
import "core:strings"
@ -19,8 +17,8 @@ Ppm_Pixel :: struct {
}
Ppm_file :: struct {
file: os2.File, //TODO: use this instead perhaps?
data: []byte,
file: os.File, //TODO: use this instead perhaps?
data: []u8,
magic_num: PPM_MAGIC_NUMBER,
width: int,
height: int,
@ -28,19 +26,21 @@ Ppm_file :: struct {
pixels: []Ppm_Pixel,
}
load_ppm :: proc(ppm_file: ^Ppm_file, filename: string) -> (success: bool) {
load_ppm :: proc(ppm_file: ^Ppm_file, filename: string) -> (bool, os.Error) {
if ppm_file == nil || len(filename) == 0 {
return false, .Not_Exist
}
if !strings.has_suffix(filename, ".ppm") {
fmt.eprintfln("ERROR: File %s does not have a valid ppm extention (.ppm)", filename)
return false
return false, .Invalid_File
}
succ: bool
ppm_file.data, succ = os.read_entire_file_from_filename(filename, context.temp_allocator)
if !succ {
fmt.eprintfln("ERROR: Failed to load file: %s ", filename)
return false
//if file is valid, opemn but check error too!
err: os.Error
ppm_file.data, err = os.read_entire_file_from_path(filename, context.temp_allocator)
if err != nil {
return false, err
}
return true
return true, err
}
//TODO: handle errors and err return type (success: bool?, err: ErrorType?)

1909588
test2.ppm Normal file

File diff suppressed because it is too large Load Diff