aboutsummaryrefslogtreecommitdiff
path: root/cmd/headless_interpreter/main.go
blob: 3d2329a41eca9b3ab897a8987360919f1bc19b0c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package main

import (
	"flag"
	"fmt"
	"os"

	"git.adyxax.org/adyxax/gofunge98/pkg/field"
	"git.adyxax.org/adyxax/gofunge98/pkg/interpreter"
	"git.adyxax.org/adyxax/gofunge98/pkg/pointer"
)

func main() {
	filename := flag.String("f", "", "b98 file to interpret")
	help := flag.Bool("h", false, "display this help message")
	flag.Parse()

	if *help {
		flag.Usage()
		os.Exit(0)
	}

	if *filename == "" {
		fmt.Println("Error : no b98 file to interpret")
		flag.Usage()
		os.Exit(1)
	}
	file, err := os.Open(*filename)
	if err != nil {
		fmt.Printf("Failed to open file %s : %+v", *filename, err)
		os.Exit(2)
	}
	defer file.Close()

	f, err := field.Load(file)
	if err != nil {
		fmt.Printf("Failed to load file %s : %+v", *filename, err)
		os.Exit(3)
	}
	p := pointer.NewPointer()
	p.Argv = []string{*filename}
	v := interpreter.NewInterpreter(f, p).Run()
	os.Exit(v)
}