Commit bdca78e1 authored by Shenghou Ma's avatar Shenghou Ma

cmd/yacc/units.y: update comment, give better error messages when $GOROOT not set

R=r, golang-dev
CC=golang-dev
https://golang.org/cl/5698062
parent 4af3dda4
......@@ -5,3 +5,6 @@
units: yacc.go units.y
go run yacc.go -p units_ units.y
go build -o units y.go
clean:
rm -f y.go y.output units
......@@ -15,9 +15,8 @@
// example of a Go yacc program
// usage is
// go tool yacc -p "units_" units.y (produces y.go)
// 6g y.go
// 6l y.6
// ./6.out $GOROOT/src/cmd/yacc/units
// go build -o units y.go
// ./units $GOROOT/src/cmd/yacc/units.txt
// you have: c
// you want: furlongs/fortnight
// * 1.8026178e+12
......@@ -288,9 +287,14 @@ func main() {
flag.Parse()
file = os.Getenv("GOROOT") + "/src/cmd/yacc/units.txt"
if dir := os.Getenv("GOROOT"); dir != "" {
file = dir + "/src/cmd/yacc/units.txt"
}
if flag.NArg() > 0 {
file = flag.Arg(0)
} else if file == "" {
fmt.Fprintf(os.Stderr, "can not find data file units.txt; provide it as argument or set $GOROOT\n")
os.Exit(1)
}
f, err := os.Open(file)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment