update
This commit is contained in:
parent
95b0a90499
commit
1cc56f9b60
@ -24,10 +24,8 @@ main :: proc() {
|
|||||||
print_usage()
|
print_usage()
|
||||||
}
|
}
|
||||||
filename := os.args[1]
|
filename := os.args[1]
|
||||||
success := load_ppm(&file, filename)
|
if ok, err := load_ppm(&file, filename); !ok {
|
||||||
|
fmt.eprintfln("ERROR: Failed to load file '%s': %s ", filename, os.error_string(err))
|
||||||
if !success {
|
|
||||||
fmt.eprintfln("Could not load file %s", filename)
|
|
||||||
os.exit(1)
|
os.exit(1)
|
||||||
}
|
}
|
||||||
ppm_parse(&file)
|
ppm_parse(&file)
|
||||||
|
|||||||
BIN
ppm-viewer
BIN
ppm-viewer
Binary file not shown.
26
ppm.odin
26
ppm.odin
@ -1,9 +1,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import "core:c"
|
|
||||||
import "core:fmt"
|
import "core:fmt"
|
||||||
import "core:os"
|
import "core:os"
|
||||||
import "core:os/os2"
|
|
||||||
import "core:strconv"
|
import "core:strconv"
|
||||||
import "core:strings"
|
import "core:strings"
|
||||||
|
|
||||||
@ -19,8 +17,8 @@ Ppm_Pixel :: struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Ppm_file :: struct {
|
Ppm_file :: struct {
|
||||||
file: os2.File, //TODO: use this instead perhaps?
|
file: os.File, //TODO: use this instead perhaps?
|
||||||
data: []byte,
|
data: []u8,
|
||||||
magic_num: PPM_MAGIC_NUMBER,
|
magic_num: PPM_MAGIC_NUMBER,
|
||||||
width: int,
|
width: int,
|
||||||
height: int,
|
height: int,
|
||||||
@ -28,19 +26,21 @@ Ppm_file :: struct {
|
|||||||
pixels: []Ppm_Pixel,
|
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") {
|
if !strings.has_suffix(filename, ".ppm") {
|
||||||
fmt.eprintfln("ERROR: File %s does not have a valid ppm extention (.ppm)", filename)
|
return false, .Invalid_File
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
succ: bool
|
//if file is valid, opemn but check error too!
|
||||||
ppm_file.data, succ = os.read_entire_file_from_filename(filename, context.temp_allocator)
|
err: os.Error
|
||||||
if !succ {
|
ppm_file.data, err = os.read_entire_file_from_path(filename, context.temp_allocator)
|
||||||
fmt.eprintfln("ERROR: Failed to load file: %s ", filename)
|
if err != nil {
|
||||||
return false
|
return false, err
|
||||||
}
|
}
|
||||||
return true
|
return true, err
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO: handle errors and err return type (success: bool?, err: ErrorType?)
|
//TODO: handle errors and err return type (success: bool?, err: ErrorType?)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user