1
0
mirror of https://github.com/golang/go synced 2024-11-25 01:17:56 -07:00

Automated g4 rollback of changelist 35383.

*** 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
This commit is contained in:
Rob Pike 2009-10-13 12:37:04 -07:00
parent 3139b2031c
commit 7839521335
14 changed files with 95 additions and 139 deletions

View 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 {
@ -33,19 +33,19 @@ type rotate13 struct {
}
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,7 +54,7 @@ func cat(r reader) {
var buf [NBUF]byte;
if *rot13_flag {
r = newRotate13(r);
r = newRotate13(r)
}
for {
switch nr, er := r.Read(&buf); {

View File

@ -21,12 +21,12 @@ func main() {
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);
}

View File

@ -16,9 +16,9 @@ type File struct {
func newFile(fd int, name string) *File {
if fd < 0 {
return nil;
return nil
}
return &File{fd, name};
return &File{fd, name}
}
var (
@ -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
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
}

View 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);

View 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)
}

View 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'.
}
}
@ -18,8 +18,8 @@ func generate(ch chan int) {
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'.
if i % prime != 0 {
out <- i // Send 'i' to channel 'out'.
}
}
}
@ -33,6 +33,6 @@ func main() {
fmt.Println(prime);
ch1 := make(chan int);
go filter(ch, ch1, prime);
ch = ch1;
ch = ch1
}
}

View File

@ -9,9 +9,9 @@ import "fmt"
// 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
}
}
}();

View 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)); }

View File

@ -14,7 +14,7 @@ func ints() {
a := sort.IntArray(data);
sort.Sort(a);
if !sort.IsSorted(a) {
panic();
panic()
}
}
@ -23,7 +23,7 @@ func strings() {
a := sort.StringArray(data);
sort.Sort(a);
if !sort.IsSorted(a) {
panic();
panic()
}
}
@ -37,34 +37,28 @@ 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")
}

View 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";

View File

@ -9,13 +9,13 @@ import "fmt"
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");
}