Commit c62b3265 authored by Russ Cox's avatar Russ Cox

apply gofmt to the LGTM-marked files from 34501

that have not changed since I applied gofmt.

R=gri
DELTA=456  (77 added, 3 deleted, 376 changed)
OCL=35378
CL=35383
parent 9d9a421e
......@@ -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);
}
......@@ -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;
}
......@@ -7,11 +7,14 @@ 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);
......
......@@ -6,13 +6,16 @@ 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);
}
......@@ -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;
}
}
......@@ -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;
}
}
}();
......
......@@ -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,32 +32,62 @@ 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));
}
......@@ -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,28 +37,34 @@ 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");
}
......
......@@ -9,7 +9,9 @@ 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";
......
......@@ -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");
}
......@@ -139,11 +139,11 @@ func walk(x interface{}, p *Prog, context string) {
}
p.Crefs = new;
}
p.Crefs = p.Crefs[0:i+1];
p.Crefs = p.Crefs[0 : i+1];
p.Crefs[i] = &Cref{
Name: sel.Sel.Value,
Expr: n,
Context: context
Context: context,
};
break;
}
......@@ -321,4 +321,3 @@ func walk(x interface{}, p *Prog, context string) {
}
}
}
......@@ -20,13 +20,13 @@ func usage() {
fmt.Fprint(os.Stderr, "usage: cgo [compiler options] file.go\n");
}
var ptrSizeMap = map[string]int64 {
var ptrSizeMap = map[string]int64{
"386": 4,
"amd64": 8,
"arm": 4
"arm": 4,
}
var expandName = map[string]string {
var expandName = map[string]string{
"schar": "signed char",
"uchar": "unsigned char",
"ushort": "unsigned short",
......@@ -42,7 +42,7 @@ func main() {
usage();
os.Exit(2);
}
gccOptions := args[1:len(args)-1];
gccOptions := args[1 : len(args)-1];
input := args[len(args)-1];
arch := os.Getenv("GOARCH");
......
......@@ -13,7 +13,7 @@ import (
)
func creat(name string) *os.File {
f, err := os.Open(name, os.O_WRONLY|os.O_CREAT|os.O_TRUNC, 0666);
f, err := os.Open(name, os.O_WRONLY | os.O_CREAT | os.O_TRUNC, 0666);
if err != nil {
fatal("%s", err);
}
......@@ -27,7 +27,7 @@ func (p *Prog) writeOutput(srcfile string) {
base := srcfile;
if strings.HasSuffix(base, ".go") {
base = base[0:len(base)-3];
base = base[0 : len(base)-3];
}
fgo1 := creat(base + ".cgo1.go");
fgo2 := creat(base + ".cgo2.go");
......@@ -71,7 +71,7 @@ func (p *Prog) writeOutput(srcfile string) {
for name, def := range p.Funcdef {
// Go func declaration.
d := &ast.FuncDecl{
Name: &ast.Ident{Value: "_C_" + name},
Name: &ast.Ident{Value: "_C_"+name},
Type: def.Go,
};
printer.Fprint(fgo2, d, 0, 8);
......@@ -91,8 +91,8 @@ func (p *Prog) writeOutput(srcfile string) {
off := int64(0);
npad := 0;
for i, t := range def.Params {
if off%t.Align != 0 {
pad := t.Align - off%t.Align;
if off % t.Align != 0 {
pad := t.Align - off % t.Align;
structType += fmt.Sprintf("\t\tchar __pad%d[%d];\n", npad, pad);
off += pad;
npad++;
......@@ -100,15 +100,15 @@ func (p *Prog) writeOutput(srcfile string) {
structType += fmt.Sprintf("\t\t%s p%d;\n", t.C, i);
off += t.Size;
}
if off%p.PtrSize != 0 {
pad := p.PtrSize - off%p.PtrSize;
if off % p.PtrSize != 0 {
pad := p.PtrSize - off % p.PtrSize;
structType += fmt.Sprintf("\t\tchar __pad%d[%d];\n", npad, pad);
off += pad;
npad++;
}
if t := def.Result; t != nil {
if off%t.Align != 0 {
pad := t.Align - off%t.Align;
if off % t.Align != 0 {
pad := t.Align - off % t.Align;
structType += fmt.Sprintf("\t\tchar __pad%d[%d];\n", npad, pad);
off += pad;
npad++;
......@@ -116,8 +116,8 @@ func (p *Prog) writeOutput(srcfile string) {
structType += fmt.Sprintf("\t\t%s r;\n", t.C);
off += t.Size;
}
if off%p.PtrSize != 0 {
pad := p.PtrSize - off%p.PtrSize;
if off % p.PtrSize != 0 {
pad := p.PtrSize - off % p.PtrSize;
structType += fmt.Sprintf("\t\tchar __pad%d[%d];\n", npad, pad);
off += pad;
npad++;
......@@ -218,4 +218,3 @@ void
FLUSH(&p);
}
`
......@@ -93,4 +93,3 @@ func error(pos token.Position, msg string, args ...) {
fmt.Fprintf(os.Stderr, msg, args);
fmt.Fprintf(os.Stderr, "\n");
}
......@@ -17,7 +17,7 @@ import (
)
var start = flag.String("start", "Start", "name of start production");
var start = flag.String("start", "Start", "name of start production")
func usage() {
......@@ -47,24 +47,24 @@ func extractEBNF(src []byte) []byte {
// write as many newlines as found in the excluded text
// to maintain correct line numbers in error messages
for _, ch := range src[0 : i] {
for _, ch := range src[0:i] {
if ch == '\n' {
buf.WriteByte('\n');
}
}
// j = end of EBNF text (or end of source)
j := bytes.Index(src[i : len(src)], close); // close marker
j := bytes.Index(src[i:len(src)], close); // close marker
if j < 0 {
j = len(src)-i;
}
j += i;
// copy EBNF text
buf.Write(src[i : j]);
buf.Write(src[i:j]);
// advance
src = src[j : len(src)];
src = src[j:len(src)];
}
return buf.Bytes();
......
......@@ -6,83 +6,83 @@ package PACKAGE
// emitted by compiler, not referred to by go programs
func mal(int32) *any;
func throwindex();
func throwreturn();
func throwinit();
func panicl();
func mal(int32) *any
func throwindex()
func throwreturn()
func throwinit()
func panicl()
func printbool(bool);
func printfloat(float64);
func printint(int64);
func printuint(uint64);
func printstring(string);
func printpointer(any);
func printiface(any);
func printeface(any);
func printslice(any);
func printnl();
func printsp();
func printbool(bool)
func printfloat(float64)
func printint(int64)
func printuint(uint64)
func printstring(string)
func printpointer(any)
func printiface(any)
func printeface(any)
func printslice(any)
func printnl()
func printsp()
func catstring(string, string) string;
func cmpstring(string, string) int;
func slicestring(string, int, int) string;
func indexstring(string, int) byte;
func intstring(int64) string;
func slicebytetostring([]byte) string;
func sliceinttostring([]int) string;
func stringiter(string, int) int;
func stringiter2(string, int) (retk int, retv int);
func catstring(string, string) string
func cmpstring(string, string) int
func slicestring(string, int, int) string
func indexstring(string, int) byte
func intstring(int64) string
func slicebytetostring([]byte) string
func sliceinttostring([]int) string
func stringiter(string, int) int
func stringiter2(string, int) (retk int, retv int)
func ifaceI2E(iface any) (ret any);
func ifaceE2I(typ *byte, iface any) (ret any);
func ifaceT2E(typ *byte, elem any) (ret any);
func ifaceE2T(typ *byte, elem any) (ret any);
func ifaceE2I2(typ *byte, iface any) (ret any, ok bool);
func ifaceE2T2(typ *byte, elem any) (ret any, ok bool);
func ifaceT2I(typ1 *byte, typ2 *byte, elem any) (ret any);
func ifaceI2T(typ *byte, iface any) (ret any);
func ifaceI2T2(typ *byte, iface any) (ret any, ok bool);
func ifaceI2I(typ *byte, iface any) (ret any);
func ifaceI2Ix(typ *byte, iface any) (ret any);
func ifaceI2I2(typ *byte, iface any) (ret any, ok bool);
func ifaceeq(i1 any, i2 any) (ret bool);
func efaceeq(i1 any, i2 any) (ret bool);
func ifacethash(i1 any) (ret uint32);
func efacethash(i1 any) (ret uint32);
func ifaceI2E(iface any) (ret any)
func ifaceE2I(typ *byte, iface any) (ret any)
func ifaceT2E(typ *byte, elem any) (ret any)
func ifaceE2T(typ *byte, elem any) (ret any)
func ifaceE2I2(typ *byte, iface any) (ret any, ok bool)
func ifaceE2T2(typ *byte, elem any) (ret any, ok bool)
func ifaceT2I(typ1 *byte, typ2 *byte, elem any) (ret any)
func ifaceI2T(typ *byte, iface any) (ret any)
func ifaceI2T2(typ *byte, iface any) (ret any, ok bool)
func ifaceI2I(typ *byte, iface any) (ret any)
func ifaceI2Ix(typ *byte, iface any) (ret any)
func ifaceI2I2(typ *byte, iface any) (ret any, ok bool)
func ifaceeq(i1 any, i2 any) (ret bool)
func efaceeq(i1 any, i2 any) (ret bool)
func ifacethash(i1 any) (ret uint32)
func efacethash(i1 any) (ret uint32)
// *byte is really *runtime.Type
func makemap(key, val *byte, hint int) (hmap map[any]any);
func mapaccess1(hmap map[any]any, key any) (val any);
func mapaccess2(hmap map[any]any, key any) (val any, pres bool);
func mapassign1(hmap map[any]any, key any, val any);
func mapassign2(hmap map[any]any, key any, val any, pres bool);
func mapiterinit(hmap map[any]any, hiter *any);
func mapiternext(hiter *any);
func mapiter1(hiter *any) (key any);
func mapiter2(hiter *any) (key any, val any);
func makemap(key, val *byte, hint int) (hmap map[any]any)
func mapaccess1(hmap map[any]any, key any) (val any)
func mapaccess2(hmap map[any]any, key any) (val any, pres bool)
func mapassign1(hmap map[any]any, key any, val any)
func mapassign2(hmap map[any]any, key any, val any, pres bool)
func mapiterinit(hmap map[any]any, hiter *any)
func mapiternext(hiter *any)
func mapiter1(hiter *any) (key any)
func mapiter2(hiter *any) (key any, val any)
// *byte is really *runtime.Type
func makechan(elem *byte, hint int) (hchan chan any);
func chanrecv1(hchan <-chan any) (elem any);
func chanrecv2(hchan <-chan any) (elem any, pres bool);
func chansend1(hchan chan<- any, elem any);
func chansend2(hchan chan<- any, elem any) (pres bool);
func closechan(hchan any);
func closedchan(hchan any) bool;
func makechan(elem *byte, hint int) (hchan chan any)
func chanrecv1(hchan <-chan any) (elem any)
func chanrecv2(hchan <-chan any) (elem any, pres bool)
func chansend1(hchan chan<- any, elem any)
func chansend2(hchan chan<- any, elem any) (pres bool)
func closechan(hchan any)
func closedchan(hchan any) bool
func newselect(size int) (sel *byte);
func selectsend(sel *byte, hchan chan<- any, elem any) (selected bool);
func selectrecv(sel *byte, hchan <-chan any, elem *any) (selected bool);
func selectdefault(sel *byte) (selected bool);
func selectgo(sel *byte);
func newselect(size int) (sel *byte)
func selectsend(sel *byte, hchan chan<- any, elem any) (selected bool)
func selectrecv(sel *byte, hchan <-chan any, elem *any) (selected bool)
func selectdefault(sel *byte) (selected bool)
func selectgo(sel *byte)
func makeslice(nel int, cap int, width int) (ary []any);
func sliceslice(old []any, lb int, hb int, width int) (ary []any);
func slicearray(old *any, nel int, lb int, hb int, width int) (ary []any);
func arraytoslice(old *any, nel int) (ary []any);
func makeslice(nel int, cap int, width int) (ary []any)
func sliceslice(old []any, lb int, hb int, width int) (ary []any)
func slicearray(old *any, nel int, lb int, hb int, width int) (ary []any)
func arraytoslice(old *any, nel int) (ary []any)
func closure(); // has args, but compiler fills in
func closure() // has args, but compiler fills in
// only used on 32-bit
func int64div(int64, int64) int64
......
......@@ -4,10 +4,10 @@
package PACKAGE
type Pointer *any;
func Offsetof(any) int;
func Sizeof(any) int;
func Alignof(any) int;
func Typeof(i interface { }) (typ interface{});
func Reflect(i interface { }) (typ interface{}, addr Pointer);
func Unreflect(typ interface{}, addr Pointer) (ret interface { });
type Pointer *any
func Offsetof(any) int
func Sizeof(any) int
func Alignof(any) int
func Typeof(i interface{}) (typ interface{})
func Reflect(i interface{}) (typ interface{}, addr Pointer)
func Unreflect(typ interface{}, addr Pointer) (ret interface{})
......@@ -17,7 +17,7 @@ import (
)
const pkgDir = "src/pkg"; // relative to $GOROOT
const pkgDir = "src/pkg" // relative to $GOROOT
var (
......
......@@ -47,7 +47,7 @@ type Header struct {
Ctime int64;
}
var zeroBlock = make([]byte, blockSize);
var zeroBlock = make([]byte, blockSize)
// POSIX specifies a sum of the unsigned byte values, but the Sun tar uses signed byte values.
// We compute and return both.
......@@ -55,20 +55,20 @@ func checksum(header []byte) (unsigned int64, signed int64) {
for i := 0; i < len(header); i++ {
if i == 148 {
// The chksum field (header[148:156]) is special: it should be treated as space bytes.
unsigned += ' ' * 8;
signed += ' ' * 8;
unsigned += ' '*8;
signed += ' '*8;
i += 7;
continue
continue;
}
unsigned += int64(header[i]);
signed += int64(int8(header[i]));
}
return
return;
}
type slicer []byte
func (sp *slicer) next(n int) (b []byte) {
s := *sp;
b, *sp = s[0:n], s[n:len(s)];
return
return;
}
......@@ -45,7 +45,7 @@ type Reader struct {
// NewReader creates a new Reader reading from r.
func NewReader(r io.Reader) *Reader {
return &Reader{ r: r }
return &Reader{r: r};
}
// Next advances to the next entry in the tar archive.
......@@ -57,7 +57,7 @@ func (tr *Reader) Next() (*Header, os.Error) {
if tr.err == nil {
hdr = tr.readHeader();
}
return hdr, tr.err
return hdr, tr.err;
}
// Parse bytes as a NUL-terminated C-style string.
......@@ -67,7 +67,7 @@ func cString(b []byte) string {
for n < len(b) && b[n] != 0 {
n++;
}
return string(b[0:n])
return string(b[0:n]);
}
func (tr *Reader) octal(b []byte) int64 {
......@@ -77,18 +77,18 @@ func (tr *Reader) octal(b []byte) int64 {
}
// Removing trailing NULs and spaces.
for len(b) > 0 && (b[len(b)-1] == ' ' || b[len(b)-1] == '\x00') {
b = b[0:len(b)-1];
b = b[0 : len(b)-1];
}
x, err := strconv.Btoui64(cString(b), 8);
if err != nil {
tr.err = err;
}
return int64(x)
return int64(x);
}
type ignoreWriter struct {}
type ignoreWriter struct{}
func (ignoreWriter) Write(b []byte) (n int, err os.Error) {
return len(b), nil
return len(b), nil;
}
// Skip any unread bytes in the existing file entry, as well as any alignment padding.
......@@ -105,34 +105,34 @@ func (tr *Reader) skipUnread() {
func (tr *Reader) verifyChecksum(header []byte) bool {
if tr.err != nil {
return false
return false;
}
given := tr.octal(header[148:156]);
unsigned, signed := checksum(header);
return given == unsigned || given == signed
return given == unsigned || given == signed;
}
func (tr *Reader) readHeader() *Header {
header := make([]byte, blockSize);
if _, tr.err = io.ReadFull(tr.r, header); tr.err != nil {
return nil
return nil;
}
// Two blocks of zero bytes marks the end of the archive.
if bytes.Equal(header, zeroBlock[0:blockSize]) {
if _, tr.err = io.ReadFull(tr.r, header); tr.err != nil {
return nil
return nil;
}
if !bytes.Equal(header, zeroBlock[0:blockSize]) {
tr.err = HeaderError;
}
return nil
return nil;
}
if !tr.verifyChecksum(header) {
tr.err = HeaderError;
return nil
return nil;
}
// Unpack
......@@ -191,15 +191,15 @@ func (tr *Reader) readHeader() *Header {
if tr.err != nil {
tr.err = HeaderError;
return nil
return nil;
}
// Maximum value of hdr.Size is 64 GB (12 octal digits),
// so there's no risk of int64 overflowing.
tr.nb = int64(hdr.Size);
tr.pad = -tr.nb & (blockSize - 1); // blockSize is a power of two
tr.pad = -tr.nb & (blockSize-1); // blockSize is a power of two
return hdr
return hdr;
}
// Read reads from the current entry in the tar archive.
......@@ -207,10 +207,10 @@ func (tr *Reader) readHeader() *Header {
// until Next is called to advance to the next entry.
func (tr *Reader) Read(b []uint8) (n int, err os.Error) {
if int64(len(b)) > tr.nb {
b = b[0:tr.nb];
b = b[0 : tr.nb];
}
n, err = tr.r.Read(b);
tr.nb -= int64(n);
tr.err = err;
return
return;
}
......@@ -17,7 +17,7 @@ type testpair struct {
decoded, encoded string;
}
var pairs = []testpair {
var pairs = []testpair{
// RFC 3548 examples
testpair{"\x14\xfb\x9c\x03\xd9\x7e", "FPucA9l+"},
testpair{"\x14\xfb\x9c\x03\xd9", "FPucA9k="},
......@@ -43,9 +43,9 @@ var pairs = []testpair {
testpair{"sure.", "c3VyZS4="},
}
var bigtest = testpair {
var bigtest = testpair{
"Twas brillig, and the slithy toves",
"VHdhcyBicmlsbGlnLCBhbmQgdGhlIHNsaXRoeSB0b3Zlcw=="
"VHdhcyBicmlsbGlnLCBhbmQgdGhlIHNsaXRoeSB0b3Zlcw==",
}
func testEqual(t *testing.T, msg string, args ...) bool {
......@@ -104,7 +104,7 @@ func TestDecode(t *testing.T) {
testEqual(t, "Decode(%q) = error %v, want %v", p.encoded, err, os.Error(nil));
testEqual(t, "Decode(%q) = length %v, want %v", p.encoded, count, len(p.decoded));
if len(p.encoded) > 0 {
testEqual(t, "Decode(%q) = end %v, want %v", p.encoded, end, (p.encoded[len(p.encoded)-1] == '='));
testEqual(t, "Decode(%q) = end %v, want %v", p.encoded, end, (p.encoded[len(p.encoded) - 1] == '='));
}
testEqual(t, "Decode(%q) = %q, want %q", p.encoded, string(dbuf[0:count]), p.decoded);
}
......@@ -133,7 +133,7 @@ func TestDecoderBuffering(t *testing.T) {
buf := make([]byte, len(bigtest.decoded) + 12);
var total int;
for total = 0; total < len(bigtest.decoded); {
n, err := decoder.Read(buf[total:total+bs]);
n, err := decoder.Read(buf[total : total+bs]);
testEqual(t, "Read from %q at pos %d = %d, %v, want _, %v", bigtest.encoded, total, n, err, os.Error(nil));
total += n;
}
......@@ -145,8 +145,8 @@ func TestDecodeCorrupt(t *testing.T) {
type corrupt struct {
e string;
p int;
};
examples := []corrupt {
}
examples := []corrupt{
corrupt{"!!!!", 0},
corrupt{"x===", 1},
corrupt{"AA=A", 2},
......@@ -168,7 +168,7 @@ func TestDecodeCorrupt(t *testing.T) {
}
func TestBig(t *testing.T) {
n := 3*1000+1;
n := 3*1000 + 1;
raw := make([]byte, n);
const alpha = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
for i := 0; i < n; i++ {
......
......@@ -61,7 +61,7 @@ func mulWW_g(x, y Word) (z1, z0 Word) {
// and return the product as 2 Words.
if x < y {
x, y = y, x
x, y = y, x;
}
if x < _B2 {
......@@ -85,7 +85,7 @@ func mulWW_g(x, y Word) (z1, z0 Word) {
// compute result digits but avoid overflow
// z = z[1]*_B + z[0] = x*y
z0 = t1<<_W2 + t0;
z1 = (t1 + t0>>_W2) >> _W2;
z1 = (t1 + t0>>_W2)>>_W2;
return;
}
......@@ -104,7 +104,7 @@ func mulWW_g(x, y Word) (z1, z0 Word) {
// compute result digits but avoid overflow
// z = z[1]*_B + z[0] = x*y
z0 = t1<<_W2 + t0;
z1 = t2 + (t1 + t0>>_W2) >> _W2;
z1 = t2 + (t1 + t0>>_W2)>>_W2;
return;
}
......@@ -133,7 +133,7 @@ func mulAddWWW_g(x, y, c Word) (z1, z0 Word) {
// compute result digits but avoid overflow
// z = z[1]*_B + z[0] = x*y
z0 = t1<<_W2 + t0;
z1 = t2 + (t1 + t0>>_W2) >> _W2;
z1 = t2 + (t1 + t0>>_W2)>>_W2;
return;
}
......@@ -180,7 +180,7 @@ func leadingZeros(x Word) (n uint) {
if x == 0 {
return uint(_W);
}
for x & (1<<(_W-1)) == 0 {
for x&(1<<(_W-1)) == 0 {
n++;
x <<= 1;
}
......@@ -200,7 +200,7 @@ func divWW_g(x1, x0, y Word) (q, r Word) {
if y > x1 {
if z != 0 {
y <<= z;
x1 = (x1 << z) | (x0 >> (uint(_W) - z));
x1 = (x1<<z)|(x0>>(uint(_W)-z));
x0 <<= z;
}
q0, x0 = divStep(x1, x0, y);
......@@ -210,10 +210,10 @@ func divWW_g(x1, x0, y Word) (q, r Word) {
x1 -= y;
q1 = 1;
} else {
z1 := uint(_W) - z;
z1 := uint(_W)-z;
y <<= z;
x2 := x1 >> z1;
x1 = (x1 << z) | (x0 >> z1);
x2 := x1>>z1;
x1 = (x1<<z)|(x0>>z1);
x0 <<= z;
q1, x1 = divStep(x2, x1, y);
}
......@@ -221,7 +221,7 @@ func divWW_g(x1, x0, y Word) (q, r Word) {
q0, x0 = divStep(x1, x0, y);
}
r = x0 >> z;
r = x0>>z;
if q1 != 0 {
panic("div out of range");
......@@ -258,7 +258,7 @@ var (
addMulVVW func(z, x *Word, y Word, n int) (c Word) = addMulVVW_g;
// divWVW sets z and returns r such that z-r = (xn<<(n*_W) + x) / y.
divWVW func(z* Word, xn Word, x *Word, y Word, n int) (r Word) = divWVW_g;
divWVW func(z *Word, xn Word, x *Word, y Word, n int) (r Word) = divWVW_g;
)
......@@ -289,7 +289,7 @@ func addVV_g(z, x, y *Word, n int) (c Word) {
for i := 0; i < n; i++ {
c, *z.at(i) = addWW_g(*x.at(i), *y.at(i), c);
}
return
return;
}
......@@ -298,7 +298,7 @@ func subVV_g(z, x, y *Word, n int) (c Word) {
for i := 0; i < n; i++ {
c, *z.at(i) = subWW_g(*x.at(i), *y.at(i), c);
}
return
return;
}
......@@ -308,7 +308,7 @@ func addVW_g(z, x *Word, y Word, n int) (c Word) {
for i := 0; i < n; i++ {
c, *z.at(i) = addWW_g(*x.at(i), c, 0);
}
return
return;
}
......@@ -318,7 +318,7 @@ func subVW_g(z, x *Word, y Word, n int) (c Word) {
for i := 0; i < n; i++ {
c, *z.at(i) = subWW_g(*x.at(i), c, 0);
}
return
return;
}
......@@ -328,7 +328,7 @@ func mulAddVWW_g(z, x *Word, y, r Word, n int) (c Word) {
for i := 0; i < n; i++ {
c, *z.at(i) = mulAddWWW_g(*x.at(i), y, c);
}
return
return;
}
......@@ -343,8 +343,8 @@ func addMulVVW_g(z, x *Word, y Word, n int) (c Word) {
}
func divWVW_s(z* Word, xn Word, x *Word, y Word, n int) (r Word)
func divWVW_g(z* Word, xn Word, x *Word, y Word, n int) (r Word) {
func divWVW_s(z *Word, xn Word, x *Word, y Word, n int) (r Word)
func divWVW_g(z *Word, xn Word, x *Word, y Word, n int) (r Word) {
r = xn;
for i := n-1; i >= 0; i-- {
*z.at(i), r = divWW_g(r, *x.at(i), y);
......
......@@ -8,7 +8,9 @@ import "testing"
type funWW func(x, y, c Word) (z1, z0 Word)
type argWW struct { x, y, c, z1, z0 Word }
type argWW struct {
x, y, c, z1, z0 Word;
}
var sumWW = []argWW{
argWW{0, 0, 0, 0, 0},
......@@ -59,7 +61,10 @@ func addr(x []Word) *Word {
type funVV func(z, x, y *Word, n int) (c Word)
type argVV struct { z, x, y []Word; c Word }
type argVV struct {
z, x, y []Word;
c Word;
}
var sumVV = []argVV{
argVV{},
......@@ -112,7 +117,11 @@ func TestFunVV(t *testing.T) {
type funVW func(z, x *Word, y Word, n int) (c Word)
type argVW struct { z, x []Word; y Word; c Word }
type argVW struct {
z, x []Word;
y Word;
c Word;
}
var sumVW = []argVW{
argVW{},
......@@ -133,9 +142,9 @@ var prodVW = []argVW{
argVW{[]Word{0, 0, 0, 22793}, []Word{0, 0, 0, 991}, 23, 0},
argVW{[]Word{0, 0, 0, 0}, []Word{7893475, 7395495, 798547395, 68943}, 0, 0},
argVW{[]Word{0, 0, 0, 0}, []Word{0, 0, 0, 0}, 894375984, 0},
argVW{[]Word{_M<<1 & _M}, []Word{_M}, 1<<1, _M>>(_W-1)},
argVW{[]Word{_M<<7 & _M}, []Word{_M}, 1<<7, _M>>(_W-7)},
argVW{[]Word{_M<<7 & _M, _M, _M, _M}, []Word{_M, _M, _M, _M}, 1<<7, _M>>(_W-7)},
argVW{[]Word{_M<<1&_M}, []Word{_M}, 1<<1, _M>>(_W-1)},
argVW{[]Word{_M<<7&_M}, []Word{_M}, 1<<7, _M>>(_W-7)},
argVW{[]Word{_M<<7&_M, _M, _M, _M}, []Word{_M, _M, _M, _M}, 1<<7, _M>>(_W-7)},
}
......@@ -169,7 +178,11 @@ func TestFunVW(t *testing.T) {
type funVWW func(z, x *Word, y, r Word, n int) (c Word)
type argVWW struct { z, x []Word; y, r Word; c Word }
type argVWW struct {
z, x []Word;
y, r Word;
c Word;
}
var prodVWW = []argVWW{
argVWW{},
......@@ -217,8 +230,14 @@ func testFunVWW(t *testing.T, msg string, f funVWW, a argVWW) {
// TODO(gri) mulAddVWW and divWVW are symmetric operations but
// their signature is not symmetric. Try to unify.
type funWVW func(z* Word, xn Word, x *Word, y Word, n int) (r Word)
type argWVW struct { z []Word; xn Word; x []Word; y Word; r Word }
type funWVW func(z *Word, xn Word, x *Word, y Word, n int) (r Word)
type argWVW struct {
z []Word;
xn Word;
x []Word;
y Word;
r Word;
}
func testFunWVW(t *testing.T, msg string, f funWVW, a argWVW) {
n := len(a.z);
......
......@@ -55,7 +55,7 @@ func (z *Int) Add(x, y *Int) *Int {
if len(z.abs) == 0 {
z.neg = false; // 0 has no sign
}
return z
return z;
}
......@@ -80,7 +80,7 @@ func (z *Int) Sub(x, y *Int) *Int {
if len(z.abs) == 0 {
z.neg = false; // 0 has no sign
}
return z
return z;
}
......@@ -92,7 +92,7 @@ func (z *Int) Mul(x, y *Int) *Int {
// (-x) * (-y) == x * y
z.abs = mulNN(z.abs, x.abs, y.abs);
z.neg = len(z.abs) > 0 && x.neg != y.neg; // 0 has no sign
return z
return z;
}
......
......@@ -39,14 +39,14 @@ func normN(z []Word) []Word {
for i > 0 && z[i-1] == 0 {
i--;
}
z = z[0 : i];
z = z[0:i];
return z;
}
func makeN(z []Word, m int, clear bool) []Word {
if len(z) > m {
z = z[0 : m]; // reuse z - has at least one extra word for a carry, if any
z = z[0:m]; // reuse z - has at least one extra word for a carry, if any
if clear {
for i := range z {
z[i] = 0;
......@@ -84,7 +84,7 @@ func newN(z []Word, x uint64) []Word {
// split x into n words
z = makeN(z, n, false);
for i := 0; i < n; i++ {
z[i] = Word(x & _M);
z[i] = Word(x&_M);
x >>= _W;
}
......@@ -166,8 +166,10 @@ func cmpNN(x, y []Word) (r int) {
n := len(y);
if m != n || m == 0 {
switch {
case m < n: r = -1;
case m > n: r = 1;
case m < n:
r = -1;
case m > n:
r = 1;
}
return;
}
......@@ -178,8 +180,10 @@ func cmpNN(x, y []Word) (r int) {
}
switch {
case x[i] < y[i]: r = -1;
case x[i] > y[i]: r = 1;
case x[i] < y[i]:
r = -1;
case x[i] > y[i]:
r = 1;
}
return;
}
......@@ -228,7 +232,7 @@ func mulNN(z, x, y []Word) []Word {
}
z = normN(z);
return z
return z;
}
......@@ -280,10 +284,14 @@ func log2N(x []Word) int {
func hexValue(ch byte) int {
var d byte;
switch {
case '0' <= ch && ch <= '9': d = ch - '0';
case 'a' <= ch && ch <= 'f': d = ch - 'a' + 10;
case 'A' <= ch && ch <= 'F': d = ch - 'A' + 10;
default: return -1;
case '0' <= ch && ch <= '9':
d = ch-'0';
case 'a' <= ch && ch <= 'f':
d = ch-'a'+10;
case 'A' <= ch && ch <= 'F':
d = ch-'A'+10;
default:
return -1;
}
return int(d);
}
......@@ -344,7 +352,7 @@ func stringN(x []Word, base int) string {
}
// allocate buffer for conversion
i := (log2N(x) + 1) / log2(Word(base)) + 1; // +1: round up
i := (log2N(x)+1)/log2(Word(base)) + 1; // +1: round up
s := make([]byte, i);
// don't destroy x
......@@ -356,7 +364,7 @@ func stringN(x []Word, base int) string {
var r Word;
q, r = divNW(q, q, 10);
s[i] = "0123456789abcdef"[r];
};
}
return string(s[i : len(s)]);
return string(s[i:len(s)]);
}
......@@ -7,12 +7,14 @@ package big
import "testing"
func TestCmpNN(t *testing.T) {
// TODO(gri) write this test - all other tests depends on it
// TODO(gri) write this test - all other tests depends on it
}
type funNN func(z, x, y []Word) []Word
type argNN struct { z, x, y []Word }
type argNN struct {
z, x, y []Word;
}
var sumNN = []argNN{
argNN{},
......@@ -23,7 +25,7 @@ var sumNN = []argNN{
argNN{[]Word{0, 0, 0, 1}, []Word{0, 0, _M}, []Word{0, 0, 1}},
}
var prodNN = []argNN {
var prodNN = []argNN{
argNN{},
argNN{nil, nil, nil},
argNN{nil, []Word{991}, nil},
......@@ -78,7 +80,11 @@ func TestFunNN(t *testing.T) {
}
type strN struct { x []Word; b int; s string }
type strN struct {
x []Word;
b int;
s string;
}
var tabN = []strN{
strN{nil, 10, "0"},
strN{[]Word{1}, 10, "1"},
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment