From ba2b9c8a1bb1876b6eb4c9783fde798b19de4418 Mon Sep 17 00:00:00 2001 From: stefan Date: Wed, 24 May 2023 08:32:08 -0400 Subject: init --- as/main.go | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 as/main.go (limited to 'as/main.go') diff --git a/as/main.go b/as/main.go new file mode 100644 index 0000000..95aff46 --- /dev/null +++ b/as/main.go @@ -0,0 +1,59 @@ +package main + +import ( + "os" + "fmt" +) + +func usage(arg0 string) { + fmt.Fprintf(os.Stderr, "usage: %s [-o file] file.easm\n", os.Args[0]) + os.Exit(1) +} + +func main() { + if (len(os.Args) <= 2) { + usage(os.Args[0]) + } + + + var aout int = 0 + var ain int = 0 + + for i := 0; i < len(os.Args); i++ { + fmt.Println(os.Args[i]) + switch os.Args[i] { + case "-o": + i = i + 1 + aout = i + default: + ain = i + } + } + + if (ain == 0) { + usage(os.Args[0]) + } + + var outf string = "out.bin" + if (aout != 0) { + outf = os.Args[aout] + } + + b, errin := os.ReadFile(os.Args[ain]) + out, errout := os.Create(outf) + + if errin != nil { + fmt.Fprintf(os.Stderr, "failed to read file: %s\n", os.Args[ain]) + os.Exit(1) + } + + if errout != nil { + fmt.Fprintf(os.Stderr, "failed to create file for output: %s\n", outf) + os.Exit(1) + } + + s := string(b) + c := Assemble(s) + + out.Write(c) +} -- cgit v1.2.3