From: Shenghou Ma Date: Sat, 25 Feb 2012 17:36:26 +0000 (+0800) Subject: cmd/yacc/units.y: update comment, give better error messages when $GOROOT not set X-Git-Tag: weekly.2012-03-04~151 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=bdca78e1a76cd97a20d45d5f6990b52533154aee;p=gostls13.git 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 --- diff --git a/src/cmd/yacc/Makefile b/src/cmd/yacc/Makefile index 4d84891e31..56e954289a 100644 --- a/src/cmd/yacc/Makefile +++ b/src/cmd/yacc/Makefile @@ -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 diff --git a/src/cmd/yacc/units.y b/src/cmd/yacc/units.y index f10cb7c7dc..7258e3e597 100644 --- a/src/cmd/yacc/units.y +++ b/src/cmd/yacc/units.y @@ -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)