]> Cypherpunks repositories - gostls13.git/commitdiff
Automated g4 rollback of changelist 35383.
authorRob Pike <r@golang.org>
Tue, 13 Oct 2009 19:37:04 +0000 (12:37 -0700)
committerRob Pike <r@golang.org>
Tue, 13 Oct 2009 19:37:04 +0000 (12:37 -0700)
*** Reason for rollback ***

roll back the changes to the tutorial programs (only) since they
break the automated processing used to create the tutorial.

*** Original change description ***

apply gofmt to the LGTM-marked files from 34501
that have not changed since I applied gofmt.

R=rsc
DELTA=139  (0 added, 44 deleted, 95 changed)
OCL=35670
CL=35670

14 files changed:
doc/progs/cat.go
doc/progs/cat_rot13.go
doc/progs/echo.go
doc/progs/file.go
doc/progs/helloworld.go
doc/progs/helloworld3.go
doc/progs/print.go
doc/progs/print_string.go
doc/progs/sieve.go
doc/progs/sieve1.go
doc/progs/sort.go
doc/progs/sortmain.go
doc/progs/strings.go
doc/progs/sum.go

index 824b9245985e1212ee69fa1effcbf6c44d4e5eab..f9f00b6e325ed64861764aef015ec6bf3fde4b8f 100644 (file)
@@ -19,7 +19,7 @@ func cat(f *file.File) {
                case nr < 0:
                        fmt.Fprintf(os.Stderr, "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);
        }
index 6cad78f5a7bd0c0c619cb36f20bfb91e2e3873f8..ea608b83d7f57081ea0e7402af20c4c018f5f8f1 100644 (file)
@@ -15,12 +15,12 @@ var rot13_flag = 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;
+       return b
 }
 
 type reader interface {
@@ -29,23 +29,23 @@ type reader interface {
 }
 
 type rotate13 struct {
-       source reader;
+       source  reader;
 }
 
 func newRotate13(source reader) *rotate13 {
-       return &rotate13{source};
+       return &rotate13{source}
 }
 
 func (r13 *rotate13) Read(b []byte) (ret int, err os.Error) {
        r, e := r13.source.Read(b);
        for i := 0; i < r; i++ {
-               b[i] = rot13(b[i]);
+               b[i] = rot13(b[i])
        }
-       return r, e;
+       return r, e
 }
 
 func (r13 *rotate13) String() string {
-       return r13.source.String();
+       return r13.source.String()
 }
 // end of rotate13 implementation
 
@@ -54,14 +54,14 @@ func cat(r reader) {
        var buf [NBUF]byte;
 
        if *rot13_flag {
-               r = newRotate13(r);
+               r = newRotate13(r)
        }
        for {
                switch nr, er := r.Read(&buf); {
                case nr < 0:
                        fmt.Fprintf(os.Stderr, "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);
        }
index e5cd016005457a20fd10ad871a25adce2e62b731..3ddb4f83e20ed6ad6bd5a5033ae716f2cd5697c1 100644 (file)
@@ -12,21 +12,21 @@ import (
 var n_flag = flag.Bool("n", false, "don't print final newline")
 
 const (
-       kSpace          = " ";
-       kNewline        = "\n";
+       kSpace = " ";
+       kNewline = "\n";
 )
 
 func main() {
-       flag.Parse();   // Scans the arg list and sets up flags
+       flag.Parse();   // Scans the arg list and sets up flags
        var s string = "";
        for i := 0; i < flag.NArg(); i++ {
                if i > 0 {
-                       s += kSpace;
+                       s += kSpace
                }
-               s += flag.Arg(i);
+               s += flag.Arg(i)
        }
        if !*n_flag {
-               s += kNewline;
+               s += kNewline
        }
        os.Stdout.WriteString(s);
 }
index 74b9ee4403b3f6597230cc985b82bf744ba802fc..bda3890de2e546de4576dc535a3a501f179c7e0f 100644 (file)
@@ -10,21 +10,21 @@ 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 {
        if fd < 0 {
-               return nil;
+               return nil
        }
-       return &File{fd, name};
+       return &File{fd, name}
 }
 
 var (
-       Stdin   = newFile(0, "/dev/stdin");
-       Stdout  = newFile(1, "/dev/stdout");
-       Stderr  = newFile(2, "/dev/stderr");
+       Stdin  = newFile(0, "/dev/stdin");
+       Stdout = newFile(1, "/dev/stdout");
+       Stderr = newFile(2, "/dev/stderr");
 )
 
 func Open(name string, mode int, perm int) (file *File, err os.Error) {
@@ -32,43 +32,43 @@ func Open(name string, mode int, perm int) (file *File, err os.Error) {
        if e != 0 {
                err = os.Errno(e);
        }
-       return newFile(r, name), err;
+       return newFile(r, name), err
 }
 
 func (file *File) Close() os.Error {
        if file == nil {
-               return os.EINVAL;
+               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);
        }
-       return nil;
+       return nil
 }
 
 func (file *File) Read(b []byte) (ret int, err os.Error) {
        if file == nil {
-               return -1, os.EINVAL;
+               return -1, os.EINVAL
        }
        r, e := syscall.Read(file.fd, b);
        if e != 0 {
                err = os.Errno(e);
        }
-       return int(r), err;
+       return int(r), err
 }
 
 func (file *File) Write(b []byte) (ret int, err os.Error) {
        if file == nil {
-               return -1, os.EINVAL;
+               return -1, os.EINVAL
        }
        r, e := syscall.Write(file.fd, b);
        if e != 0 {
                err = os.Errno(e);
        }
-       return int(r), err;
+       return int(r), err
 }
 
 func (file *File) String() string {
-       return file.name;
+       return file.name
 }
index 9192c41ba43f9c936d60baa20646ecf59586dfe9..c4c3855edfc8286a68981d7d07119b3ce1f11f1a 100644 (file)
@@ -4,7 +4,7 @@
 
 package main
 
-import fmt "fmt"       // Package implementing formatted I/O.
+import fmt "fmt"  // Package implementing formatted I/O.
 
 func main() {
        fmt.Printf("Hello, world; or Καλημέρα κόσμε; or こんにちは 世界\n");
index 1aa0eab09c79b97b2e7524899210d162324903cc..ea567fe1bdc42aa06c11815ea053a29aea3e83ed 100644 (file)
@@ -13,9 +13,9 @@ import (
 func main() {
        hello := []byte{'h', 'e', 'l', 'l', 'o', ',', ' ', 'w', 'o', 'r', 'l', 'd', '\n'};
        file.Stdout.Write(hello);
-       file, err := file.Open("/does/not/exist", 0, 0);
+       file, err := file.Open("/does/not/exist",  0,  0);
        if file == nil {
-               fmt.Printf("can't open file; err=%s\n", err.String());
+               fmt.Printf("can't open file; err=%s\n",  err.String());
                os.Exit(1);
        }
 }
index 0c08bff18d16edf8245a1b8c1335281a885c821b..cc146fed8c895ee075892be7cf013f269e4ad3a1 100644 (file)
@@ -7,14 +7,11 @@ package main
 import "fmt"
 
 func main() {
-       var u64 uint64 = 1<<64 - 1;
+       var u64 uint64 = 1<<64-1;
        fmt.Printf("%d %d\n", u64, int64(u64));
 
        // harder stuff
-       type T struct {
-               a       int;
-               b       string;
-       }
+       type T struct { a int; b string };
        t := T{77, "Sunset Strip"};
        a := []int{1, 2, 3, 4};
        fmt.Printf("%v %v %v\n", u64, t, a);
index 7526f79fbd1a6aeffc76df435cdfa4fce72c330b..13a8d824189d7e05b0bf14f4284c3d726bd87320 100644 (file)
@@ -6,16 +6,13 @@ package main
 
 import "fmt"
 
-type testType struct {
-       a       int;
-       b       string;
-}
+type testType struct { a int; b string }
 
 func (t *testType) String() string {
-       return fmt.Sprint(t.a) + " " + t.b;
+       return fmt.Sprint(t.a) + " " + t.b
 }
 
 func main() {
        t := &testType{77, "Sunset Strip"};
-       fmt.Println(t);
+       fmt.Println(t)
 }
index 601c2c410a70e2996fc6dc4754754526dfac5e63..cd011d29311b66297d821acc244f510852ff5774 100644 (file)
@@ -9,7 +9,7 @@ import "fmt"
 // Send the sequence 2, 3, 4, ... to channel 'ch'.
 func generate(ch chan int) {
        for i := 2; ; i++ {
-               ch <- i;        // Send 'i' to channel 'ch'.
+               ch <- i  // Send 'i' to channel 'ch'.
        }
 }
 
@@ -17,22 +17,22 @@ func generate(ch chan int) {
 // removing those divisible by 'prime'.
 func filter(in, out chan int, prime int) {
        for {
-               i := <-in;      // Receive value of new variable 'i' from 'in'.
-               if i%prime != 0 {
-                       out <- i;       // Send 'i' to channel 'out'.
+               i := <-in;  // Receive value of new variable 'i' from 'in'.
+               if i % prime != 0 {
+                       out <- i  // Send 'i' to channel 'out'.
                }
        }
 }
 
 // The prime sieve: Daisy-chain filter processes together.
 func main() {
-       ch := make(chan int);   // Create a new channel.
-       go generate(ch);        // Start generate() as a goroutine.
+       ch := make(chan int);  // Create a new channel.
+       go generate(ch);  // Start generate() as a goroutine.
        for {
                prime := <-ch;
                fmt.Println(prime);
                ch1 := make(chan int);
                go filter(ch, ch1, prime);
-               ch = ch1;
+               ch = ch1
        }
 }
index 7dd5ecc2cf24b2f17120e0f0e6a6868f73de5b52..0ae3893ab7a542a2cde2ed9767c8cb5f56ad7774 100644 (file)
@@ -6,12 +6,12 @@ package main
 
 import "fmt"
 
-// Send the sequence 2, 3, 4, ... to returned channel
+// Send the sequence 2, 3, 4, ... to returned channel 
 func generate() chan int {
        ch := make(chan int);
-       go func() {
+       go func(){
                for i := 2; ; i++ {
-                       ch <- i;
+                       ch <- i
                }
        }();
        return ch;
@@ -22,8 +22,8 @@ func filter(in chan int, prime int) chan int {
        out := make(chan int);
        go func() {
                for {
-                       if i := <-in; i%prime != 0 {
-                               out <- i;
+                       if i := <-in; i % prime != 0 {
+                               out <- i
                        }
                }
        }();
index 0d9eab607706dc3aeefd0ff116532dbd8ccce270..687217a316e172ba5efc6512397503b0312fa6a4 100644 (file)
@@ -20,8 +20,8 @@ func Sort(data SortInterface) {
 
 func IsSorted(data SortInterface) bool {
        n := data.Len();
-       for i := n-1; i > 0; i-- {
-               if data.Less(i, i-1) {
+       for i := n - 1; i > 0; i-- {
+               if data.Less(i, i - 1) {
                        return false;
                }
        }
@@ -32,62 +32,32 @@ func IsSorted(data SortInterface) bool {
 
 type IntArray []int
 
-func (p IntArray) Len() int {
-       return len(p);
-}
-func (p IntArray) Less(i, j int) bool {
-       return p[i] < p[j];
-}
-func (p IntArray) Swap(i, j int) {
-       p[i], p[j] = p[j], p[i];
-}
+func (p IntArray) Len() int            { return len(p); }
+func (p IntArray) Less(i, j int) bool  { return p[i] < p[j]; }
+func (p IntArray) Swap(i, j int)       { p[i], p[j] = p[j], p[i]; }
 
 
 type FloatArray []float
 
-func (p FloatArray) Len() int {
-       return len(p);
-}
-func (p FloatArray) Less(i, j int) bool {
-       return p[i] < p[j];
-}
-func (p FloatArray) Swap(i, j int) {
-       p[i], p[j] = p[j], p[i];
-}
+func (p FloatArray) Len() int            { return len(p); }
+func (p FloatArray) Less(i, j int) bool  { return p[i] < p[j]; }
+func (p FloatArray) Swap(i, j int)       { p[i], p[j] = p[j], p[i]; }
 
 
 type StringArray []string
 
-func (p StringArray) Len() int {
-       return len(p);
-}
-func (p StringArray) Less(i, j int) bool {
-       return p[i] < p[j];
-}
-func (p StringArray) Swap(i, j int) {
-       p[i], p[j] = p[j], p[i];
-}
+func (p StringArray) Len() int            { return len(p); }
+func (p StringArray) Less(i, j int) bool  { return p[i] < p[j]; }
+func (p StringArray) Swap(i, j int)       { p[i], p[j] = p[j], p[i]; }
 
 
 // Convenience wrappers for common cases
 
-func SortInts(a []int) {
-       Sort(IntArray(a));
-}
-func SortFloats(a []float) {
-       Sort(FloatArray(a));
-}
-func SortStrings(a []string) {
-       Sort(StringArray(a));
-}
+func SortInts(a []int)        { Sort(IntArray(a)); }
+func SortFloats(a []float)    { Sort(FloatArray(a)); }
+func SortStrings(a []string)  { Sort(StringArray(a)); }
 
 
-func IntsAreSorted(a []int) bool {
-       return IsSorted(IntArray(a));
-}
-func FloatsAreSorted(a []float) bool {
-       return IsSorted(FloatArray(a));
-}
-func StringsAreSorted(a []string) bool {
-       return IsSorted(StringArray(a));
-}
+func IntsAreSorted(a []int) bool       { return IsSorted(IntArray(a)); }
+func FloatsAreSorted(a []float) bool   { return IsSorted(FloatArray(a)); }
+func StringsAreSorted(a []string) bool { return IsSorted(StringArray(a)); }
index 9f1a58ce5b8f10932c58207a4301d4bdf68b043c..63d68ff05c31a44d6fb7bd7552e0d9afd46a3302 100644 (file)
@@ -14,7 +14,7 @@ func ints() {
        a := sort.IntArray(data);
        sort.Sort(a);
        if !sort.IsSorted(a) {
-               panic();
+               panic()
        }
 }
 
@@ -23,48 +23,42 @@ func strings() {
        a := sort.StringArray(data);
        sort.Sort(a);
        if !sort.IsSorted(a) {
-               panic();
+               panic()
        }
 }
 
 type day struct {
-       num             int;
-       short_name      string;
-       long_name       string;
+       num        int;
+       short_name string;
+       long_name  string;
 }
 
 type dayArray struct {
        data []*day;
 }
 
-func (p *dayArray) Len() int {
-       return len(p.data);
-}
-func (p *dayArray) Less(i, j int) bool {
-       return p.data[i].num < p.data[j].num;
-}
-func (p *dayArray) Swap(i, j int) {
-       p.data[i], p.data[j] = p.data[j], p.data[i];
-}
+func (p *dayArray) Len() int            { return len(p.data); }
+func (p *dayArray) Less(i, j int) bool  { return p.data[i].num < p.data[j].num; }
+func (p *dayArray) Swap(i, j int)       { p.data[i], p.data[j] = p.data[j], p.data[i]; }
 
 func days() {
-       Sunday := day{0, "SUN", "Sunday"};
-       Monday := day{1, "MON", "Monday"};
-       Tuesday := day{2, "TUE", "Tuesday"};
-       Wednesday := day{3, "WED", "Wednesday"};
-       Thursday := day{4, "THU", "Thursday"};
-       Friday := day{5, "FRI", "Friday"};
-       Saturday := day{6, "SAT", "Saturday"};
+       Sunday :=    day{ 0, "SUN", "Sunday" };
+       Monday :=    day{ 1, "MON", "Monday" };
+       Tuesday :=   day{ 2, "TUE", "Tuesday" };
+       Wednesday := day{ 3, "WED", "Wednesday" };
+       Thursday :=  day{ 4, "THU", "Thursday" };
+       Friday :=    day{ 5, "FRI", "Friday" };
+       Saturday :=  day{ 6, "SAT", "Saturday" };
        data := []*day{&Tuesday, &Thursday, &Wednesday, &Sunday, &Monday, &Friday, &Saturday};
        a := dayArray{data};
        sort.Sort(&a);
        if !sort.IsSorted(&a) {
-               panic();
+               panic()
        }
        for _, d := range data {
-               fmt.Printf("%s ", d.long_name);
+               fmt.Printf("%s ", d.long_name)
        }
-       fmt.Printf("\n");
+       fmt.Printf("\n")
 }
 
 
index 3a3d61f47049d2d3fb523896414c57a2cd66f8dd..2c4937e38f24aa5a08abe47e1c002c328926a051 100644 (file)
@@ -9,9 +9,7 @@ import "os"
 
 func main() {
        s := "hello";
-       if s[1] != 'e' {
-               os.Exit(1);
-       }
+       if s[1] != 'e' { os.Exit(1) }
        s = "good bye";
        var p *string = &s;
        *p = "ciao";
index 1194230f8fc2409ad8a7bc842047fbdb126373b5..f087ca3e5c4b3f8f726d2b7c311ab7fb0ff862ce 100644 (file)
@@ -6,16 +6,16 @@ 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];
+               s += a[i]
        }
-       return s;
+       return s
 }
 
 
 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");
 }