aboutsummaryrefslogtreecommitdiff
path: root/pkg/pointer/intput-output.go
diff options
context:
space:
mode:
authorJulien Dessaux2021-12-04 00:07:41 +0100
committerJulien Dessaux2021-12-04 00:07:41 +0100
commit2dbd22114b4906c6ae60de15f4c30a5ea38441c6 (patch)
treeb8035d711eee7e69b33a0bc59f8cf034a1c53f74 /pkg/pointer/intput-output.go
parentRenamed headless_interpreter to gofunge98 (diff)
downloadgofunge98-2dbd22114b4906c6ae60de15f4c30a5ea38441c6.tar.gz
gofunge98-2dbd22114b4906c6ae60de15f4c30a5ea38441c6.tar.bz2
gofunge98-2dbd22114b4906c6ae60de15f4c30a5ea38441c6.zip
Fixed standard input error handling
Diffstat (limited to 'pkg/pointer/intput-output.go')
-rw-r--r--pkg/pointer/intput-output.go23
1 files changed, 14 insertions, 9 deletions
diff --git a/pkg/pointer/intput-output.go b/pkg/pointer/intput-output.go
index ac58d44..6a2423a 100644
--- a/pkg/pointer/intput-output.go
+++ b/pkg/pointer/intput-output.go
@@ -2,37 +2,42 @@ package pointer
import (
"fmt"
- "log"
"os"
)
var defaultInputLastChar *int = nil
-func DefaultCharacterInput() int {
+func DefaultCharacterInput() (int, error) {
if defaultInputLastChar != nil {
c := *defaultInputLastChar
defaultInputLastChar = nil
- return c
+ return c, nil
}
b := make([]byte, 1)
i, err := os.Stdin.Read(b)
if err != nil {
- log.Fatalf("Error in DefaultCharacterInput { b: %c, i: %d, err: %+v }", b[0], i, err)
+ return 0, fmt.Errorf("Error in DefaultCharacterInput { b: %c, i: %d, err: %w }", b[0], i, err)
}
- return int(b[0])
+ return int(b[0]), nil
}
-func DefaultDecimalInput() int {
+func DefaultDecimalInput() (int, error) {
var v int
for {
- c := DefaultCharacterInput()
+ c, err := DefaultCharacterInput()
+ if err != nil {
+ return 0, err
+ }
if c >= '0' && c <= '9' {
v = c - '0'
break
}
}
for {
- c := DefaultCharacterInput()
+ c, err := DefaultCharacterInput()
+ if err != nil {
+ break
+ }
if c >= '0' && c <= '9' {
v = v*10 + c - '0'
} else {
@@ -40,7 +45,7 @@ func DefaultDecimalInput() int {
break
}
}
- return v
+ return v, nil
}
func DefaultCharacterOutput(c int) {