summaryrefslogtreecommitdiff
path: root/doc/progs
diff options
context:
space:
mode:
Diffstat (limited to 'doc/progs')
-rw-r--r--doc/progs/cat.go6
-rw-r--r--doc/progs/cat_rot13.go12
-rw-r--r--doc/progs/file.go8
-rw-r--r--doc/progs/helloworld3.go4
-rwxr-xr-xdoc/progs/run12
-rw-r--r--doc/progs/sortmain.go2
-rw-r--r--doc/progs/sum.go4
7 files changed, 23 insertions, 25 deletions
diff --git a/doc/progs/cat.go b/doc/progs/cat.go
index f8d1a54fb..697e5f786 100644
--- a/doc/progs/cat.go
+++ b/doc/progs/cat.go
@@ -15,11 +15,11 @@ func cat(f *file.File) {
const NBUF = 512
var buf [NBUF]byte
for {
- switch nr, er := f.Read(&buf); true {
+ switch nr, er := f.Read(buf[:]); true {
case nr < 0:
fmt.Fprintf(os.Stderr, "cat: error reading from %s: %s\n", f.String(), er.String())
os.Exit(1)
- case nr == 0: // EOF
+ case nr == 0: // EOF
return
case nr > 0:
if nw, ew := file.Stdout.Write(buf[0:nr]); nw != nr {
@@ -30,7 +30,7 @@ func cat(f *file.File) {
}
func main() {
- flag.Parse() // Scans the arg list and sets up flags
+ flag.Parse() // Scans the arg list and sets up flags
if flag.NArg() == 0 {
cat(file.Stdin)
}
diff --git a/doc/progs/cat_rot13.go b/doc/progs/cat_rot13.go
index 42c6195fb..03fc02259 100644
--- a/doc/progs/cat_rot13.go
+++ b/doc/progs/cat_rot13.go
@@ -15,10 +15,10 @@ var rot13Flag = flag.Bool("rot13", false, "rot13 the input")
func rot13(b byte) byte {
if 'a' <= b && b <= 'z' {
- b = 'a' + ((b - 'a') + 13) % 26
+ b = 'a' + ((b-'a')+13)%26
}
if 'A' <= b && b <= 'Z' {
- b = 'A' + ((b - 'A') + 13) % 26
+ b = 'A' + ((b-'A')+13)%26
}
return b
}
@@ -29,7 +29,7 @@ type reader interface {
}
type rotate13 struct {
- source reader
+ source reader
}
func newRotate13(source reader) *rotate13 {
@@ -57,11 +57,11 @@ func cat(r reader) {
r = newRotate13(r)
}
for {
- switch nr, er := r.Read(&buf); {
+ switch nr, er := r.Read(buf[:]); {
case nr < 0:
fmt.Fprintf(os.Stderr, "cat: error reading from %s: %s\n", r.String(), er.String())
os.Exit(1)
- case nr == 0: // EOF
+ case nr == 0: // EOF
return
case nr > 0:
nw, ew := file.Stdout.Write(buf[0:nr])
@@ -73,7 +73,7 @@ func cat(r reader) {
}
func main() {
- flag.Parse() // Scans the arg list and sets up flags
+ flag.Parse() // Scans the arg list and sets up flags
if flag.NArg() == 0 {
cat(file.Stdin)
}
diff --git a/doc/progs/file.go b/doc/progs/file.go
index b2f2c0476..d3fb5ae9e 100644
--- a/doc/progs/file.go
+++ b/doc/progs/file.go
@@ -10,8 +10,8 @@ import (
)
type File struct {
- fd int // file descriptor number
- name string // file name at Open time
+ fd int // file descriptor number
+ name string // file name at Open time
}
func newFile(fd int, name string) *File {
@@ -27,7 +27,7 @@ var (
Stderr = newFile(2, "/dev/stderr")
)
-func Open(name string, mode int, perm int) (file *File, err os.Error) {
+func Open(name string, mode int, perm uint32) (file *File, err os.Error) {
r, e := syscall.Open(name, mode, perm)
if e != 0 {
err = os.Errno(e)
@@ -40,7 +40,7 @@ func (file *File) Close() os.Error {
return os.EINVAL
}
e := syscall.Close(file.fd)
- file.fd = -1 // so it can't be closed again
+ file.fd = -1 // so it can't be closed again
if e != 0 {
return os.Errno(e)
}
diff --git a/doc/progs/helloworld3.go b/doc/progs/helloworld3.go
index e065f02e6..adbcea324 100644
--- a/doc/progs/helloworld3.go
+++ b/doc/progs/helloworld3.go
@@ -13,8 +13,8 @@ import (
func main() {
hello := []byte("hello, world\n")
file.Stdout.Write(hello)
- file, err := file.Open("/does/not/exist", 0, 0)
- if file == nil {
+ f, err := file.Open("/does/not/exist", 0, 0)
+ if f == nil {
fmt.Printf("can't open file; err=%s\n", err.String())
os.Exit(1)
}
diff --git a/doc/progs/run b/doc/progs/run
index 07bc141df..29f1f8152 100755
--- a/doc/progs/run
+++ b/doc/progs/run
@@ -5,9 +5,7 @@
set -e
-GOBIN="${GOBIN:-$HOME/bin}"
-
-. "$GOROOT"/src/Make.$GOARCH
+eval $(gomake --no-print-directory -f ../../src/Make.inc go-env)
if [ -z "$O" ]; then
echo 'missing $O - maybe no Make.$GOARCH?' 1>&2
@@ -34,11 +32,11 @@ for i in \
; do
BASE=$(basename $i .go)
- "$GOBIN"/$GC $i
+ $GC $i
done
function testit {
- "$GOBIN"/$LD $1.$O
+ $LD $1.$O
x=$(echo $(./$O.out $2 2>&1)) # extra echo canonicalizes
if [ "$x" != "$3" ]
then
@@ -47,7 +45,7 @@ function testit {
}
function testitpipe {
- "$GOBIN"/$LD $1.$O
+ $LD $1.$O
x=$(echo $(./$O.out | $2 2>&1)) # extra echo canonicalizes
if [ "$x" != "$3" ]
then
@@ -76,7 +74,7 @@ testitpipe sieve "sed 10q" "2 3 5 7 11 13 17 19 23 29"
testitpipe sieve "sed 10q" "2 3 5 7 11 13 17 19 23 29"
# server hangs; don't run it, just compile it
-"$GOBIN"/$GC server.go
+$GC server.go
testit server1 "" ""
rm -f $O.out *.$O
diff --git a/doc/progs/sortmain.go b/doc/progs/sortmain.go
index 6bd504a5b..a77ae7381 100644
--- a/doc/progs/sortmain.go
+++ b/doc/progs/sortmain.go
@@ -6,7 +6,7 @@ package main
import (
"fmt"
- "sort"
+ "./sort"
)
func ints() {
diff --git a/doc/progs/sum.go b/doc/progs/sum.go
index 74fd5bca3..9caa799fd 100644
--- a/doc/progs/sum.go
+++ b/doc/progs/sum.go
@@ -6,7 +6,7 @@ package main
import "fmt"
-func sum(a []int) int { // returns an int
+func sum(a []int) int { // returns an int
s := 0
for i := 0; i < len(a); i++ {
s += a[i]
@@ -16,6 +16,6 @@ func sum(a []int) int { // returns an int
func main() {
- s := sum(&[3]int{1,2,3}) // a slice of the array is passed to sum
+ s := sum([3]int{1, 2, 3}[:]) // a slice of the array is passed to sum
fmt.Print(s, "\n")
}