45 lines
804 B
Go
45 lines
804 B
Go
|
package main
|
||
|
|
||
|
import (
|
||
|
"flag"
|
||
|
"fmt"
|
||
|
"os"
|
||
|
)
|
||
|
|
||
|
func fileExists(p string) (bool, error) {
|
||
|
_, err := os.Stat(p)
|
||
|
if err == nil { return true, nil }
|
||
|
if os.IsNotExist(err) { return false, nil }
|
||
|
return false, err
|
||
|
}
|
||
|
|
||
|
func setIn() {
|
||
|
args := flag.Args()
|
||
|
if len(args) == 0 {
|
||
|
fmt.Fprintf(os.Stderr, "no input file\n")
|
||
|
os.Exit(1)
|
||
|
} else if len(args) > 1 {
|
||
|
fmt.Fprintf(os.Stderr, "too many input files (%d), needed 1\n", len(args))
|
||
|
os.Exit(2)
|
||
|
}
|
||
|
in = args[0]
|
||
|
exists, err := fileExists(in)
|
||
|
if err != nil {
|
||
|
fmt.Fprintf(os.Stderr, "could not open file\n\t%s", err.Error())
|
||
|
os.Exit(3)
|
||
|
} else if !exists {
|
||
|
fmt.Fprintf(os.Stderr, "%q does not exist\n", in)
|
||
|
os.Exit(4)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func setOut(o string) {
|
||
|
if o == "" {
|
||
|
out = "out.rom"
|
||
|
} else {
|
||
|
out = o
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|