]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/yacc/units.y: update comment, give better error messages when $GOROOT not set
authorShenghou Ma <minux.ma@gmail.com>
Sat, 25 Feb 2012 17:36:26 +0000 (01:36 +0800)
committerShenghou Ma <minux.ma@gmail.com>
Sat, 25 Feb 2012 17:36:26 +0000 (01:36 +0800)
R=r, golang-dev
CC=golang-dev
https://golang.org/cl/5698062

src/cmd/yacc/Makefile
src/cmd/yacc/units.y

index 4d84891e31b05c0e37e7611f096e2f1a78352a6b..56e954289a0b5b946bbaf5a5f5e1fb2acfb86ceb 100644 (file)
@@ -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
index f10cb7c7dcb3e1e45257de8ca28d02a999daa221..7258e3e5975a414e326f6fc3150f8374d070a587 100644 (file)
@@ -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)