-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
59 lines (50 loc) · 1.28 KB
/
main.go
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package main
import (
"flag"
"fmt"
"io/ioutil"
"log"
"os"
"github.com/mitchr/dallas/compiler"
)
var (
disAsm = flag.Bool("d", false, "disassemble .8xp files")
progName = flag.String("p", "PROG", "set the program name (only for compilation)")
archive = flag.Bool("a", false, "set the archive bit; if false, ram is used to store the program")
lock = flag.Bool("e", false, "set the edit-lock bit")
help = flag.Bool("h", false, "display this help message")
ti83 = flag.Bool("ti83", false, "compile for the TI-83 (compiles for TI-84 by default)")
)
func main() {
flag.Usage = func() {
fmt.Fprintf(os.Stderr, "dallas is a TI-BASIC Compiler and Decompiler\n\nUsage:\n\tdallas [flags] filename\n\nFlags:\n")
flag.PrintDefaults()
os.Exit(0)
}
flag.Parse()
inName := flag.Arg(0)
if inName == "" || *help {
flag.Usage()
}
inFile, err := ioutil.ReadFile(inName)
if err != nil {
log.Fatal(err)
}
var output []byte
if *disAsm == true {
var b []byte
output, b = compiler.Decompile(inFile)
*progName = string(b) + ".tib"
} else {
output = compiler.Compile(inFile, *progName, *archive, *ti83)
*progName += ".8xp"
}
outFile, err := os.Create(*progName)
if err != nil {
log.Fatal(err)
}
_, err = outFile.Write(output)
if err != nil {
log.Fatal(err)
}
}