From bdca78e1a76cd97a20d45d5f6990b52533154aee Mon Sep 17 00:00:00 2001 From: Shenghou Ma Date: Sun, 26 Feb 2012 01:36:26 +0800 Subject: [PATCH] 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 --- src/cmd/yacc/Makefile | 3 +++ src/cmd/yacc/units.y | 12 ++++++++---- 2 files changed, 11 insertions(+), 4 deletions(-) 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) -- 2.50.0