-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.go
65 lines (56 loc) · 943 Bytes
/
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
60
61
62
63
64
65
package main
//go:generate goyacc -l gram.y
import (
"bufio"
"flag"
"fmt"
"io"
"log"
"os"
"strings"
"github.com/lufia/qsh/build"
)
var (
flagDebug = flag.Bool("d", false, "debug")
)
func usage() {
fmt.Fprintf(os.Stderr, "usage: qsh [-d] [file [arg ...]]\n")
os.Exit(2)
}
func init() {
a := os.Environ()
for _, s := range a {
kv := strings.SplitN(s, "=", 2)
if len(kv) != 2 {
continue
}
build.ImportVar(kv[0])
}
}
func main() {
log.SetFlags(0)
log.SetPrefix("qsh: ")
flag.Usage = usage
flag.Parse()
if flag.NArg() == 0 {
Run(os.Stdin, "<stdin>", nil)
} else {
args := flag.Args()
f, err := os.Open(args[0])
if err != nil {
log.Fatal(err)
}
Run(f, args[0], args[1:])
f.Close()
}
}
func Run(f io.Reader, name string, args []string) {
var l Lexer
fin := bufio.NewReader(f)
l.Init(fin, name)
for yyParse(&l) == 0 {
}
if l.err != nil && l.err != io.EOF {
l.Error(l.err.Error())
}
}