Commit 40621d5c authored by Robert Griesemer's avatar Robert Griesemer

remove semis after statements in one-statement statement lists

R=rsc, r
http://go/go-review/1025029
parent 18ccbc69
...@@ -22,7 +22,7 @@ func fibber(c chan *big.Int, out chan string, n int64) { ...@@ -22,7 +22,7 @@ func fibber(c chan *big.Int, out chan string, n int64) {
i := big.NewInt(n); i := big.NewInt(n);
if n == 0 { if n == 0 {
c <- i; c <- i
} }
for { for {
j := <-c; j := <-c;
...@@ -38,6 +38,6 @@ func main() { ...@@ -38,6 +38,6 @@ func main() {
go fibber(c, out, 0); go fibber(c, out, 0);
go fibber(c, out, 1); go fibber(c, out, 1);
for i := 0; i < 200; i++ { for i := 0; i < 200; i++ {
println(<-out); println(<-out)
} }
} }
...@@ -130,7 +130,7 @@ func NewInt(x int64) *Int { return new(Int).SetInt64(x) } ...@@ -130,7 +130,7 @@ func NewInt(x int64) *Int { return new(Int).SetInt64(x) }
// making zero values useful and gmp's decision not to. // making zero values useful and gmp's decision not to.
func (z *Int) doinit() { func (z *Int) doinit() {
if z.init { if z.init {
return; return
} }
z.init = true; z.init = true;
C.mpz_init(&z.i[0]); C.mpz_init(&z.i[0]);
...@@ -162,9 +162,9 @@ func (z *Int) Set(x *Int) *Int { ...@@ -162,9 +162,9 @@ func (z *Int) Set(x *Int) *Int {
func (z *Int) SetBytes(b []byte) *Int { func (z *Int) SetBytes(b []byte) *Int {
z.doinit(); z.doinit();
if len(b) == 0 { if len(b) == 0 {
z.SetInt64(0); z.SetInt64(0)
} else { } else {
C.mpz_import(&z.i[0], C.size_t(len(b)), 1, 1, 1, 0, unsafe.Pointer(&b[0])); C.mpz_import(&z.i[0], C.size_t(len(b)), 1, 1, 1, 0, unsafe.Pointer(&b[0]))
} }
return z; return z;
} }
...@@ -183,12 +183,12 @@ func (z *Int) SetInt64(x int64) *Int { ...@@ -183,12 +183,12 @@ func (z *Int) SetInt64(x int64) *Int {
func (z *Int) SetString(s string, base int) os.Error { func (z *Int) SetString(s string, base int) os.Error {
z.doinit(); z.doinit();
if base < 2 || base > 36 { if base < 2 || base > 36 {
return os.EINVAL; return os.EINVAL
} }
p := C.CString(s); p := C.CString(s);
defer C.free(unsafe.Pointer(p)); defer C.free(unsafe.Pointer(p));
if C.mpz_set_str(&z.i[0], p, C.int(base)) < 0 { if C.mpz_set_str(&z.i[0], p, C.int(base)) < 0 {
return os.EINVAL; return os.EINVAL
} }
return z; return z;
} }
...@@ -196,7 +196,7 @@ func (z *Int) SetString(s string, base int) os.Error { ...@@ -196,7 +196,7 @@ func (z *Int) SetString(s string, base int) os.Error {
// String returns the decimal representation of z. // String returns the decimal representation of z.
func (z *Int) String() string { func (z *Int) String() string {
if z == nil { if z == nil {
return "nil"; return "nil"
} }
z.doinit(); z.doinit();
p := C.mpz_get_str(nil, 10, &z.i[0]); p := C.mpz_get_str(nil, 10, &z.i[0]);
...@@ -207,7 +207,7 @@ func (z *Int) String() string { ...@@ -207,7 +207,7 @@ func (z *Int) String() string {
func (z *Int) destroy() { func (z *Int) destroy() {
if z.init { if z.init {
C.mpz_clear(&z.i[0]); C.mpz_clear(&z.i[0])
} }
z.init = false; z.init = false;
} }
...@@ -287,16 +287,16 @@ func (z *Int) Exp(x, y, m *Int) *Int { ...@@ -287,16 +287,16 @@ func (z *Int) Exp(x, y, m *Int) *Int {
y.doinit(); y.doinit();
z.doinit(); z.doinit();
if m == nil { if m == nil {
C.mpz_pow_ui(&z.i[0], &x.i[0], C.mpz_get_ui(&y.i[0])); C.mpz_pow_ui(&z.i[0], &x.i[0], C.mpz_get_ui(&y.i[0]))
} else { } else {
C.mpz_powm(&z.i[0], &x.i[0], &y.i[0], &m.i[0]); C.mpz_powm(&z.i[0], &x.i[0], &y.i[0], &m.i[0])
} }
return z; return z;
} }
func (z *Int) Int64() int64 { func (z *Int) Int64() int64 {
if !z.init { if !z.init {
return 0; return 0
} }
return int64(C.mpz_get_si(&z.i[0])); return int64(C.mpz_get_si(&z.i[0]));
} }
...@@ -334,9 +334,9 @@ func CmpInt(x, y *Int) int { ...@@ -334,9 +334,9 @@ func CmpInt(x, y *Int) int {
y.doinit(); y.doinit();
switch cmp := C.mpz_cmp(&x.i[0], &y.i[0]); { switch cmp := C.mpz_cmp(&x.i[0], &y.i[0]); {
case cmp < 0: case cmp < 0:
return -1; return -1
case cmp == 0: case cmp == 0:
return 0; return 0
} }
return +1; return +1;
} }
......
...@@ -54,13 +54,13 @@ var ( ...@@ -54,13 +54,13 @@ var (
func extractDigit() int64 { func extractDigit() int64 {
if big.CmpInt(numer, accum) > 0 { if big.CmpInt(numer, accum) > 0 {
return -1; return -1
} }
tmp1.Lsh(numer, 1).Add(tmp1, numer).Add(tmp1, accum); tmp1.Lsh(numer, 1).Add(tmp1, numer).Add(tmp1, accum);
big.DivModInt(tmp1, tmp2, tmp1, denom); big.DivModInt(tmp1, tmp2, tmp1, denom);
tmp2.Add(tmp2, numer); tmp2.Add(tmp2, numer);
if big.CmpInt(tmp2, denom) >= 0 { if big.CmpInt(tmp2, denom) >= 0 {
return -1; return -1
} }
return tmp1.Int64(); return tmp1.Int64();
} }
...@@ -95,7 +95,7 @@ func main() { ...@@ -95,7 +95,7 @@ func main() {
if i++; i%50 == 0 { if i++; i%50 == 0 {
fmt.Printf("\n"); fmt.Printf("\n");
if i >= 1000 { if i >= 1000 {
break; break
} }
} }
} }
......
...@@ -22,7 +22,7 @@ func fibber(c, out chan int64, i int64) { ...@@ -22,7 +22,7 @@ func fibber(c, out chan int64, i int64) {
runtime.LockOSThread(); runtime.LockOSThread();
if i == 0 { if i == 0 {
c <- i; c <- i
} }
for { for {
j := <-c; j := <-c;
......
...@@ -8,5 +8,5 @@ import "stdio" ...@@ -8,5 +8,5 @@ import "stdio"
func main() { func main() {
// stdio.Stdout.WriteString("hello, world\n"); // stdio.Stdout.WriteString("hello, world\n");
stdio.Puts("hello, world"); stdio.Puts("hello, world")
} }
...@@ -65,7 +65,7 @@ func openProg(name string) *Prog { ...@@ -65,7 +65,7 @@ func openProg(name string) *Prog {
// Instead, turn it into a new Error that will return // Instead, turn it into a new Error that will return
// details for all the errors. // details for all the errors.
for _, e := range list { for _, e := range list {
fmt.Fprintln(os.Stderr, e); fmt.Fprintln(os.Stderr, e)
} }
os.Exit(2); os.Exit(2);
} }
...@@ -94,16 +94,16 @@ func openProg(name string) *Prog { ...@@ -94,16 +94,16 @@ func openProg(name string) *Prog {
} }
sawC = true; sawC = true;
if s.Name != nil { if s.Name != nil {
error(s.Path[0].Pos(), `cannot rename import "C"`); error(s.Path[0].Pos(), `cannot rename import "C"`)
} }
if s.Doc != nil { if s.Doc != nil {
p.Preamble += doc.CommentText(s.Doc) + "\n"; p.Preamble += doc.CommentText(s.Doc) + "\n"
} else if len(d.Specs) == 1 && d.Doc != nil { } else if len(d.Specs) == 1 && d.Doc != nil {
p.Preamble += doc.CommentText(d.Doc) + "\n"; p.Preamble += doc.CommentText(d.Doc) + "\n"
} }
} }
if ws == 0 { if ws == 0 {
continue; continue
} }
d.Specs = d.Specs[0:ws]; d.Specs = d.Specs[0:ws];
p.AST.Decls[w] = d; p.AST.Decls[w] = d;
...@@ -112,7 +112,7 @@ func openProg(name string) *Prog { ...@@ -112,7 +112,7 @@ func openProg(name string) *Prog {
p.AST.Decls = p.AST.Decls[0:w]; p.AST.Decls = p.AST.Decls[0:w];
if !sawC { if !sawC {
error(noPos, `cannot find import "C"`); error(noPos, `cannot find import "C"`)
} }
// Accumulate pointers to uses of C.x. // Accumulate pointers to uses of C.x.
...@@ -135,7 +135,7 @@ func walk(x interface{}, p *Prog, context string) { ...@@ -135,7 +135,7 @@ func walk(x interface{}, p *Prog, context string) {
if i >= cap(p.Crefs) { if i >= cap(p.Crefs) {
new := make([]*Cref, 2*i); new := make([]*Cref, 2*i);
for j, v := range p.Crefs { for j, v := range p.Crefs {
new[j] = v; new[j] = v
} }
p.Crefs = new; p.Crefs = new;
} }
...@@ -159,7 +159,7 @@ func walk(x interface{}, p *Prog, context string) { ...@@ -159,7 +159,7 @@ func walk(x interface{}, p *Prog, context string) {
// These are ordered and grouped to match ../../pkg/go/ast/ast.go // These are ordered and grouped to match ../../pkg/go/ast/ast.go
case *ast.Field: case *ast.Field:
walk(&n.Type, p, "type"); walk(&n.Type, p, "type")
case *ast.BadExpr: case *ast.BadExpr:
case *ast.Ident: case *ast.Ident:
case *ast.Ellipsis: case *ast.Ellipsis:
...@@ -172,14 +172,14 @@ func walk(x interface{}, p *Prog, context string) { ...@@ -172,14 +172,14 @@ func walk(x interface{}, p *Prog, context string) {
walk(&n.Type, p, "type"); walk(&n.Type, p, "type");
walk(n.Elts, p, "expr"); walk(n.Elts, p, "expr");
case *ast.ParenExpr: case *ast.ParenExpr:
walk(&n.X, p, context); walk(&n.X, p, context)
case *ast.SelectorExpr: case *ast.SelectorExpr:
walk(&n.X, p, "selector"); walk(&n.X, p, "selector")
case *ast.IndexExpr: case *ast.IndexExpr:
walk(&n.X, p, "expr"); walk(&n.X, p, "expr");
walk(&n.Index, p, "expr"); walk(&n.Index, p, "expr");
if n.End != nil { if n.End != nil {
walk(&n.End, p, "expr"); walk(&n.End, p, "expr")
} }
case *ast.TypeAssertExpr: case *ast.TypeAssertExpr:
walk(&n.X, p, "expr"); walk(&n.X, p, "expr");
...@@ -188,9 +188,9 @@ func walk(x interface{}, p *Prog, context string) { ...@@ -188,9 +188,9 @@ func walk(x interface{}, p *Prog, context string) {
walk(&n.Fun, p, "call"); walk(&n.Fun, p, "call");
walk(n.Args, p, "expr"); walk(n.Args, p, "expr");
case *ast.StarExpr: case *ast.StarExpr:
walk(&n.X, p, context); walk(&n.X, p, context)
case *ast.UnaryExpr: case *ast.UnaryExpr:
walk(&n.X, p, "expr"); walk(&n.X, p, "expr")
case *ast.BinaryExpr: case *ast.BinaryExpr:
walk(&n.X, p, "expr"); walk(&n.X, p, "expr");
walk(&n.Y, p, "expr"); walk(&n.Y, p, "expr");
...@@ -202,40 +202,40 @@ func walk(x interface{}, p *Prog, context string) { ...@@ -202,40 +202,40 @@ func walk(x interface{}, p *Prog, context string) {
walk(&n.Len, p, "expr"); walk(&n.Len, p, "expr");
walk(&n.Elt, p, "type"); walk(&n.Elt, p, "type");
case *ast.StructType: case *ast.StructType:
walk(n.Fields, p, "field"); walk(n.Fields, p, "field")
case *ast.FuncType: case *ast.FuncType:
walk(n.Params, p, "field"); walk(n.Params, p, "field");
walk(n.Results, p, "field"); walk(n.Results, p, "field");
case *ast.InterfaceType: case *ast.InterfaceType:
walk(n.Methods, p, "field"); walk(n.Methods, p, "field")
case *ast.MapType: case *ast.MapType:
walk(&n.Key, p, "type"); walk(&n.Key, p, "type");
walk(&n.Value, p, "type"); walk(&n.Value, p, "type");
case *ast.ChanType: case *ast.ChanType:
walk(&n.Value, p, "type"); walk(&n.Value, p, "type")
case *ast.BadStmt: case *ast.BadStmt:
case *ast.DeclStmt: case *ast.DeclStmt:
walk(n.Decl, p, "decl"); walk(n.Decl, p, "decl")
case *ast.EmptyStmt: case *ast.EmptyStmt:
case *ast.LabeledStmt: case *ast.LabeledStmt:
walk(n.Stmt, p, "stmt"); walk(n.Stmt, p, "stmt")
case *ast.ExprStmt: case *ast.ExprStmt:
walk(&n.X, p, "expr"); walk(&n.X, p, "expr")
case *ast.IncDecStmt: case *ast.IncDecStmt:
walk(&n.X, p, "expr"); walk(&n.X, p, "expr")
case *ast.AssignStmt: case *ast.AssignStmt:
walk(n.Lhs, p, "expr"); walk(n.Lhs, p, "expr");
walk(n.Rhs, p, "expr"); walk(n.Rhs, p, "expr");
case *ast.GoStmt: case *ast.GoStmt:
walk(n.Call, p, "expr"); walk(n.Call, p, "expr")
case *ast.DeferStmt: case *ast.DeferStmt:
walk(n.Call, p, "expr"); walk(n.Call, p, "expr")
case *ast.ReturnStmt: case *ast.ReturnStmt:
walk(n.Results, p, "expr"); walk(n.Results, p, "expr")
case *ast.BranchStmt: case *ast.BranchStmt:
case *ast.BlockStmt: case *ast.BlockStmt:
walk(n.List, p, "stmt"); walk(n.List, p, "stmt")
case *ast.IfStmt: case *ast.IfStmt:
walk(n.Init, p, "stmt"); walk(n.Init, p, "stmt");
walk(&n.Cond, p, "expr"); walk(&n.Cond, p, "expr");
...@@ -260,7 +260,7 @@ func walk(x interface{}, p *Prog, context string) { ...@@ -260,7 +260,7 @@ func walk(x interface{}, p *Prog, context string) {
walk(n.Rhs, p, "expr"); walk(n.Rhs, p, "expr");
walk(n.Body, p, "stmt"); walk(n.Body, p, "stmt");
case *ast.SelectStmt: case *ast.SelectStmt:
walk(n.Body, p, "stmt"); walk(n.Body, p, "stmt")
case *ast.ForStmt: case *ast.ForStmt:
walk(n.Init, p, "stmt"); walk(n.Init, p, "stmt");
walk(&n.Cond, p, "expr"); walk(&n.Cond, p, "expr");
...@@ -277,47 +277,47 @@ func walk(x interface{}, p *Prog, context string) { ...@@ -277,47 +277,47 @@ func walk(x interface{}, p *Prog, context string) {
walk(&n.Type, p, "type"); walk(&n.Type, p, "type");
walk(n.Values, p, "expr"); walk(n.Values, p, "expr");
case *ast.TypeSpec: case *ast.TypeSpec:
walk(&n.Type, p, "type"); walk(&n.Type, p, "type")
case *ast.BadDecl: case *ast.BadDecl:
case *ast.GenDecl: case *ast.GenDecl:
walk(n.Specs, p, "spec"); walk(n.Specs, p, "spec")
case *ast.FuncDecl: case *ast.FuncDecl:
if n.Recv != nil { if n.Recv != nil {
walk(n.Recv, p, "field"); walk(n.Recv, p, "field")
} }
walk(n.Type, p, "type"); walk(n.Type, p, "type");
if n.Body != nil { if n.Body != nil {
walk(n.Body, p, "stmt"); walk(n.Body, p, "stmt")
} }
case *ast.File: case *ast.File:
walk(n.Decls, p, "decl"); walk(n.Decls, p, "decl")
case *ast.Package: case *ast.Package:
for _, f := range n.Files { for _, f := range n.Files {
walk(f, p, "file"); walk(f, p, "file")
} }
case []ast.Decl: case []ast.Decl:
for _, d := range n { for _, d := range n {
walk(d, p, context); walk(d, p, context)
} }
case []ast.Expr: case []ast.Expr:
for i := range n { for i := range n {
walk(&n[i], p, context); walk(&n[i], p, context)
} }
case []*ast.Field: case []*ast.Field:
for _, f := range n { for _, f := range n {
walk(f, p, context); walk(f, p, context)
} }
case []ast.Stmt: case []ast.Stmt:
for _, s := range n { for _, s := range n {
walk(s, p, context); walk(s, p, context)
} }
case []ast.Spec: case []ast.Spec:
for _, s := range n { for _, s := range n {
walk(s, p, context); walk(s, p, context)
} }
} }
} }
This diff is collapsed.
...@@ -45,18 +45,18 @@ func main() { ...@@ -45,18 +45,18 @@ func main() {
arch := os.Getenv("GOARCH"); arch := os.Getenv("GOARCH");
if arch == "" { if arch == "" {
fatal("$GOARCH is not set"); fatal("$GOARCH is not set")
} }
ptrSize, ok := ptrSizeMap[arch]; ptrSize, ok := ptrSizeMap[arch];
if !ok { if !ok {
fatal("unknown architecture %s", arch); fatal("unknown architecture %s", arch)
} }
p := openProg(input); p := openProg(input);
for _, cref := range p.Crefs { for _, cref := range p.Crefs {
// Convert C.ulong to C.unsigned long, etc. // Convert C.ulong to C.unsigned long, etc.
if expand, ok := expandName[cref.Name]; ok { if expand, ok := expandName[cref.Name]; ok {
cref.Name = expand; cref.Name = expand
} }
} }
...@@ -79,7 +79,7 @@ func main() { ...@@ -79,7 +79,7 @@ func main() {
*cref.Expr = cref.Type.Go; *cref.Expr = cref.Type.Go;
case "expr": case "expr":
if cref.TypeName { if cref.TypeName {
error((*cref.Expr).Pos(), "type C.%s used as expression", cref.Name); error((*cref.Expr).Pos(), "type C.%s used as expression", cref.Name)
} }
// Reference to C variable. // Reference to C variable.
// We declare a pointer and arrange to have it filled in. // We declare a pointer and arrange to have it filled in.
...@@ -87,13 +87,13 @@ func main() { ...@@ -87,13 +87,13 @@ func main() {
p.Vardef[cref.Name] = cref.Type; p.Vardef[cref.Name] = cref.Type;
case "type": case "type":
if !cref.TypeName { if !cref.TypeName {
error((*cref.Expr).Pos(), "expression C.%s used as type", cref.Name); error((*cref.Expr).Pos(), "expression C.%s used as type", cref.Name)
} }
*cref.Expr = cref.Type.Go; *cref.Expr = cref.Type.Go;
} }
} }
if nerrors > 0 { if nerrors > 0 {
os.Exit(2); os.Exit(2)
} }
p.PackagePath = p.Package; p.PackagePath = p.Package;
......
...@@ -15,7 +15,7 @@ import ( ...@@ -15,7 +15,7 @@ import (
func creat(name string) *os.File { 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 { if err != nil {
fatal("%s", err); fatal("%s", err)
} }
return f; return f;
} }
...@@ -27,7 +27,7 @@ func (p *Prog) writeOutput(srcfile string) { ...@@ -27,7 +27,7 @@ func (p *Prog) writeOutput(srcfile string) {
base := srcfile; base := srcfile;
if strings.HasSuffix(base, ".go") { if strings.HasSuffix(base, ".go") {
base = base[0 : len(base)-3]; base = base[0 : len(base)-3]
} }
fgo1 := creat(base + ".cgo1.go"); fgo1 := creat(base + ".cgo1.go");
fgo2 := creat(base + ".cgo2.go"); fgo2 := creat(base + ".cgo2.go");
...@@ -80,7 +80,7 @@ func (p *Prog) writeOutput(srcfile string) { ...@@ -80,7 +80,7 @@ func (p *Prog) writeOutput(srcfile string) {
if name == "CString" || name == "GoString" { if name == "CString" || name == "GoString" {
// The builtins are already defined in the C prolog. // The builtins are already defined in the C prolog.
continue; continue
} }
// Construct a gcc struct matching the 6c argument frame. // Construct a gcc struct matching the 6c argument frame.
...@@ -150,12 +150,12 @@ func (p *Prog) writeOutput(srcfile string) { ...@@ -150,12 +150,12 @@ func (p *Prog) writeOutput(srcfile string) {
fmt.Fprintf(fgcc, "\t%s *a = v;\n", structType); fmt.Fprintf(fgcc, "\t%s *a = v;\n", structType);
fmt.Fprintf(fgcc, "\t"); fmt.Fprintf(fgcc, "\t");
if def.Result != nil { if def.Result != nil {
fmt.Fprintf(fgcc, "a->r = "); fmt.Fprintf(fgcc, "a->r = ")
} }
fmt.Fprintf(fgcc, "%s(", name); fmt.Fprintf(fgcc, "%s(", name);
for i := range def.Params { for i := range def.Params {
if i > 0 { if i > 0 {
fmt.Fprintf(fgcc, ", "); fmt.Fprintf(fgcc, ", ")
} }
fmt.Fprintf(fgcc, "a->p%d", i); fmt.Fprintf(fgcc, "a->p%d", i);
} }
......
...@@ -18,7 +18,7 @@ type ByteReaderAt []byte ...@@ -18,7 +18,7 @@ type ByteReaderAt []byte
func (r ByteReaderAt) ReadAt(p []byte, off int64) (n int, err os.Error) { func (r ByteReaderAt) ReadAt(p []byte, off int64) (n int, err os.Error) {
if off >= int64(len(r)) || off < 0 { if off >= int64(len(r)) || off < 0 {
return 0, os.EOF; return 0, os.EOF
} }
return bytes.Copy(p, r[off:len(r)]), nil; return bytes.Copy(p, r[off:len(r)]), nil;
} }
...@@ -29,23 +29,23 @@ func (r ByteReaderAt) ReadAt(p []byte, off int64) (n int, err os.Error) { ...@@ -29,23 +29,23 @@ func (r ByteReaderAt) ReadAt(p []byte, off int64) (n int, err os.Error) {
func run(stdin []byte, argv []string) (stdout, stderr []byte, ok bool) { func run(stdin []byte, argv []string) (stdout, stderr []byte, ok bool) {
cmd, err := exec.LookPath(argv[0]); cmd, err := exec.LookPath(argv[0]);
if err != nil { if err != nil {
fatal("exec %s: %s", argv[0], err); fatal("exec %s: %s", argv[0], err)
} }
r0, w0, err := os.Pipe(); r0, w0, err := os.Pipe();
if err != nil { if err != nil {
fatal("%s", err); fatal("%s", err)
} }
r1, w1, err := os.Pipe(); r1, w1, err := os.Pipe();
if err != nil { if err != nil {
fatal("%s", err); fatal("%s", err)
} }
r2, w2, err := os.Pipe(); r2, w2, err := os.Pipe();
if err != nil { if err != nil {
fatal("%s", err); fatal("%s", err)
} }
pid, err := os.ForkExec(cmd, argv, os.Environ(), "", []*os.File{r0, w1, w2}); pid, err := os.ForkExec(cmd, argv, os.Environ(), "", []*os.File{r0, w1, w2});
if err != nil { if err != nil {
fatal("%s", err); fatal("%s", err)
} }
r0.Close(); r0.Close();
w1.Close(); w1.Close();
...@@ -70,7 +70,7 @@ func run(stdin []byte, argv []string) (stdout, stderr []byte, ok bool) { ...@@ -70,7 +70,7 @@ func run(stdin []byte, argv []string) (stdout, stderr []byte, ok bool) {
w, err := os.Wait(pid, 0); w, err := os.Wait(pid, 0);
if err != nil { if err != nil {
fatal("%s", err); fatal("%s", err)
} }
ok = w.Exited() && w.ExitStatus() == 0; ok = w.Exited() && w.ExitStatus() == 0;
return; return;
...@@ -88,7 +88,7 @@ var noPos token.Position ...@@ -88,7 +88,7 @@ var noPos token.Position
func error(pos token.Position, msg string, args ...) { func error(pos token.Position, msg string, args ...) {
nerrors++; nerrors++;
if pos.IsValid() { if pos.IsValid() {
fmt.Fprintf(os.Stderr, "%s: ", pos); fmt.Fprintf(os.Stderr, "%s: ", pos)
} }
fmt.Fprintf(os.Stderr, msg, args); fmt.Fprintf(os.Stderr, msg, args);
fmt.Fprintf(os.Stderr, "\n"); fmt.Fprintf(os.Stderr, "\n");
......
...@@ -41,7 +41,7 @@ func extractEBNF(src []byte) []byte { ...@@ -41,7 +41,7 @@ func extractEBNF(src []byte) []byte {
// i = beginning of EBNF text // i = beginning of EBNF text
i := bytes.Index(src, open); i := bytes.Index(src, open);
if i < 0 { if i < 0 {
break; // no EBNF found - we are done break // no EBNF found - we are done
} }
i += len(open); i += len(open);
...@@ -49,14 +49,14 @@ func extractEBNF(src []byte) []byte { ...@@ -49,14 +49,14 @@ func extractEBNF(src []byte) []byte {
// to maintain correct line numbers in error messages // to maintain correct line numbers in error messages
for _, ch := range src[0:i] { for _, ch := range src[0:i] {
if ch == '\n' { if ch == '\n' {
buf.WriteByte('\n'); buf.WriteByte('\n')
} }
} }
// j = end of EBNF text (or end of source) // 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 { if j < 0 {
j = len(src)-i; j = len(src)-i
} }
j += i; j += i;
...@@ -77,28 +77,28 @@ func main() { ...@@ -77,28 +77,28 @@ func main() {
var filename string; var filename string;
switch flag.NArg() { switch flag.NArg() {
case 0: case 0:
filename = "/dev/stdin"; filename = "/dev/stdin"
case 1: case 1:
filename = flag.Arg(0); filename = flag.Arg(0)
default: default:
usage(); usage()
} }
src, err := io.ReadFile(filename); src, err := io.ReadFile(filename);
if err != nil { if err != nil {
scanner.PrintError(os.Stderr, err); scanner.PrintError(os.Stderr, err)
} }
if path.Ext(filename) == ".html" { if path.Ext(filename) == ".html" {
src = extractEBNF(src); src = extractEBNF(src)
} }
grammar, err := ebnf.Parse(filename, src); grammar, err := ebnf.Parse(filename, src);
if err != nil { if err != nil {
scanner.PrintError(os.Stderr, err); scanner.PrintError(os.Stderr, err)
} }
if err = ebnf.Verify(grammar, *start); err != nil { if err = ebnf.Verify(grammar, *start); err != nil {
scanner.PrintError(os.Stderr, err); scanner.PrintError(os.Stderr, err)
} }
} }
This diff is collapsed.
...@@ -77,7 +77,7 @@ func (h *RunList) reduce(less func(x, y interface{}) bool, newRun func(h *RunLis ...@@ -77,7 +77,7 @@ func (h *RunList) reduce(less func(x, y interface{}) bool, newRun func(h *RunLis
} }
// add final run, if any // add final run, if any
if i < h.Len() { if i < h.Len() {
hh.Push(newRun(h, i, h.Len())); hh.Push(newRun(h, i, h.Len()))
} }
return &hh; return &hh;
...@@ -119,7 +119,7 @@ func init() { ...@@ -119,7 +119,7 @@ func init() {
// sanity check: if nKinds is too large, the SpotInfo // sanity check: if nKinds is too large, the SpotInfo
// accessor functions may need to be updated // accessor functions may need to be updated
if nKinds > 8 { if nKinds > 8 {
panic(); panic()
} }
} }
...@@ -132,13 +132,13 @@ func makeSpotInfo(kind SpotKind, lori int, isIndex bool) SpotInfo { ...@@ -132,13 +132,13 @@ func makeSpotInfo(kind SpotKind, lori int, isIndex bool) SpotInfo {
// lori value doesn't fit - since snippet indices are // lori value doesn't fit - since snippet indices are
// most certainly always smaller then 1<<28, this can // most certainly always smaller then 1<<28, this can
// only happen for line numbers; give it no line number (= 0) // only happen for line numbers; give it no line number (= 0)
x = 0; x = 0
} }
// encode kind: bits [1..4) // encode kind: bits [1..4)
x |= SpotInfo(kind)<<1; x |= SpotInfo(kind)<<1;
// encode isIndex: bit 0 // encode isIndex: bit 0
if isIndex { if isIndex {
x |= 1; x |= 1
} }
return x; return x;
} }
...@@ -220,7 +220,7 @@ type Pak struct { ...@@ -220,7 +220,7 @@ type Pak struct {
// Paks are sorted by name (primary key) and by import path (secondary key). // Paks are sorted by name (primary key) and by import path (secondary key).
func (p *Pak) less(q *Pak) bool { func (p *Pak) less(q *Pak) bool {
return p.Name < q.Name || p.Name == q.Name && p.Path < q.Path; return p.Name < q.Name || p.Name == q.Name && p.Path < q.Path
} }
...@@ -266,7 +266,7 @@ func newFileRun(h0 *RunList, i, j int) interface{} { ...@@ -266,7 +266,7 @@ func newFileRun(h0 *RunList, i, j int) interface{} {
// create the FileRun // create the FileRun
groups := make([]*KindRun, h2.Len()); groups := make([]*KindRun, h2.Len());
for i := 0; i < h2.Len(); i++ { for i := 0; i < h2.Len(); i++ {
groups[i] = h2.At(i).(*KindRun); groups[i] = h2.At(i).(*KindRun)
} }
return &FileRun{file, groups}; return &FileRun{file, groups};
} }
...@@ -289,7 +289,7 @@ func (p *PakRun) Swap(i, j int) { p.Files[i], p.Files[j] = p.Files[j], p.Files[ ...@@ -289,7 +289,7 @@ func (p *PakRun) Swap(i, j int) { p.Files[i], p.Files[j] = p.Files[j], p.Files[
// FileRuns are sorted by package for the reduction into PakRuns. // FileRuns are sorted by package for the reduction into PakRuns.
func lessFileRun(x, y interface{}) bool { func lessFileRun(x, y interface{}) bool {
return x.(*FileRun).File.Pak.less(&y.(*FileRun).File.Pak); return x.(*FileRun).File.Pak.less(&y.(*FileRun).File.Pak)
} }
...@@ -329,7 +329,7 @@ func reduce(h0 *RunList) HitList { ...@@ -329,7 +329,7 @@ func reduce(h0 *RunList) HitList {
// create a HitList // create a HitList
h := make(HitList, h2.Len()); h := make(HitList, h2.Len());
for i := 0; i < h2.Len(); i++ { for i := 0; i < h2.Len(); i++ {
h[i] = h2.At(i).(*PakRun); h[i] = h2.At(i).(*PakRun)
} }
return h; return h;
} }
...@@ -340,7 +340,7 @@ func (h HitList) filter(pakname string) HitList { ...@@ -340,7 +340,7 @@ func (h HitList) filter(pakname string) HitList {
n := 0; n := 0;
for _, p := range h { for _, p := range h {
if p.Pak.Name == pakname { if p.Pak.Name == pakname {
n++; n++
} }
} }
// create filtered HitList // create filtered HitList
...@@ -393,7 +393,7 @@ func newAltWords(h *RunList, i, j int) interface{} { ...@@ -393,7 +393,7 @@ func newAltWords(h *RunList, i, j int) interface{} {
func (a *AltWords) filter(s string) *AltWords { func (a *AltWords) filter(s string) *AltWords {
if len(a.Alts) == 1 && a.Alts[0] == s { if len(a.Alts) == 1 && a.Alts[0] == s {
// there are no different alternatives // there are no different alternatives
return nil; return nil
} }
// make a new AltWords with the current spelling removed // make a new AltWords with the current spelling removed
...@@ -445,7 +445,7 @@ func (x *Indexer) addSnippet(s *Snippet) int { ...@@ -445,7 +445,7 @@ func (x *Indexer) addSnippet(s *Snippet) int {
func (x *Indexer) visitComment(c *ast.CommentGroup) { func (x *Indexer) visitComment(c *ast.CommentGroup) {
if c != nil { if c != nil {
ast.Walk(x, c); ast.Walk(x, c)
} }
} }
...@@ -480,7 +480,7 @@ func (x *Indexer) visitSpec(spec ast.Spec, isVarDecl bool) { ...@@ -480,7 +480,7 @@ func (x *Indexer) visitSpec(spec ast.Spec, isVarDecl bool) {
x.visitComment(n.Doc); x.visitComment(n.Doc);
x.visitIdent(ImportDecl, n.Name); x.visitIdent(ImportDecl, n.Name);
for _, s := range n.Path { for _, s := range n.Path {
ast.Walk(x, s); ast.Walk(x, s)
} }
x.visitComment(n.Comment); x.visitComment(n.Comment);
...@@ -488,14 +488,14 @@ func (x *Indexer) visitSpec(spec ast.Spec, isVarDecl bool) { ...@@ -488,14 +488,14 @@ func (x *Indexer) visitSpec(spec ast.Spec, isVarDecl bool) {
x.visitComment(n.Doc); x.visitComment(n.Doc);
kind := ConstDecl; kind := ConstDecl;
if isVarDecl { if isVarDecl {
kind = VarDecl; kind = VarDecl
} }
for _, n := range n.Names { for _, n := range n.Names {
x.visitIdent(kind, n); x.visitIdent(kind, n)
} }
ast.Walk(x, n.Type); ast.Walk(x, n.Type);
for _, v := range n.Values { for _, v := range n.Values {
ast.Walk(x, v); ast.Walk(x, v)
} }
x.visitComment(n.Comment); x.visitComment(n.Comment);
...@@ -512,17 +512,17 @@ func (x *Indexer) Visit(node interface{}) bool { ...@@ -512,17 +512,17 @@ func (x *Indexer) Visit(node interface{}) bool {
// TODO(gri): methods in interface types are categorized as VarDecl // TODO(gri): methods in interface types are categorized as VarDecl
switch n := node.(type) { switch n := node.(type) {
case *ast.Ident: case *ast.Ident:
x.visitIdent(Use, n); x.visitIdent(Use, n)
case *ast.Field: case *ast.Field:
x.decl = nil; // no snippets for fields x.decl = nil; // no snippets for fields
x.visitComment(n.Doc); x.visitComment(n.Doc);
for _, m := range n.Names { for _, m := range n.Names {
x.visitIdent(VarDecl, m); x.visitIdent(VarDecl, m)
} }
ast.Walk(x, n.Type); ast.Walk(x, n.Type);
for _, s := range n.Tag { for _, s := range n.Tag {
ast.Walk(x, s); ast.Walk(x, s)
} }
x.visitComment(n.Comment); x.visitComment(n.Comment);
...@@ -532,18 +532,18 @@ func (x *Indexer) Visit(node interface{}) bool { ...@@ -532,18 +532,18 @@ func (x *Indexer) Visit(node interface{}) bool {
x.decl = nil; // no snippets for local declarations x.decl = nil; // no snippets for local declarations
x.visitComment(decl.Doc); x.visitComment(decl.Doc);
for _, s := range decl.Specs { for _, s := range decl.Specs {
x.visitSpec(s, decl.Tok == token.VAR); x.visitSpec(s, decl.Tok == token.VAR)
} }
} else { } else {
// handle error case gracefully // handle error case gracefully
ast.Walk(x, n.Decl); ast.Walk(x, n.Decl)
} }
case *ast.GenDecl: case *ast.GenDecl:
x.decl = n; x.decl = n;
x.visitComment(n.Doc); x.visitComment(n.Doc);
for _, s := range n.Specs { for _, s := range n.Specs {
x.visitSpec(s, n.Tok == token.VAR); x.visitSpec(s, n.Tok == token.VAR)
} }
case *ast.FuncDecl: case *ast.FuncDecl:
...@@ -557,7 +557,7 @@ func (x *Indexer) Visit(node interface{}) bool { ...@@ -557,7 +557,7 @@ func (x *Indexer) Visit(node interface{}) bool {
x.visitIdent(kind, n.Name); x.visitIdent(kind, n.Name);
ast.Walk(x, n.Type); ast.Walk(x, n.Type);
if n.Body != nil { if n.Body != nil {
ast.Walk(x, n.Type); ast.Walk(x, n.Type)
} }
case *ast.File: case *ast.File:
...@@ -565,14 +565,14 @@ func (x *Indexer) Visit(node interface{}) bool { ...@@ -565,14 +565,14 @@ func (x *Indexer) Visit(node interface{}) bool {
x.decl = nil; x.decl = nil;
x.visitIdent(PackageClause, n.Name); x.visitIdent(PackageClause, n.Name);
for _, d := range n.Decls { for _, d := range n.Decls {
ast.Walk(x, d); ast.Walk(x, d)
} }
// don't visit package level comments for now // don't visit package level comments for now
// to avoid duplicate visiting from individual // to avoid duplicate visiting from individual
// nodes // nodes
default: default:
return true; return true
} }
return false; return false;
...@@ -580,26 +580,26 @@ func (x *Indexer) Visit(node interface{}) bool { ...@@ -580,26 +580,26 @@ func (x *Indexer) Visit(node interface{}) bool {
func (x *Indexer) VisitDir(path string, d *os.Dir) bool { func (x *Indexer) VisitDir(path string, d *os.Dir) bool {
return true; return true
} }
func (x *Indexer) VisitFile(path string, d *os.Dir) { func (x *Indexer) VisitFile(path string, d *os.Dir) {
if !isGoFile(d) { if !isGoFile(d) {
return; return
} }
if excludeTestFiles && (!isPkgFile(d) || strings.HasPrefix(path, "test/")) { if excludeTestFiles && (!isPkgFile(d) || strings.HasPrefix(path, "test/")) {
return; return
} }
if excludeMainPackages && pkgName(path) == "main" { if excludeMainPackages && pkgName(path) == "main" {
return; return
} }
file, err := parser.ParseFile(path, nil, parser.ParseComments); file, err := parser.ParseFile(path, nil, parser.ParseComments);
if err != nil { if err != nil {
return; // ignore files with (parse) errors return // ignore files with (parse) errors
} }
dir, _ := pathutil.Split(path); dir, _ := pathutil.Split(path);
...@@ -668,7 +668,7 @@ func NewIndex(root string) *Index { ...@@ -668,7 +668,7 @@ func NewIndex(root string) *Index {
// convert snippet vector into a list // convert snippet vector into a list
snippets := make([]*Snippet, x.snippets.Len()); snippets := make([]*Snippet, x.snippets.Len());
for i := 0; i < x.snippets.Len(); i++ { for i := 0; i < x.snippets.Len(); i++ {
snippets[i] = x.snippets.At(i).(*Snippet); snippets[i] = x.snippets.At(i).(*Snippet)
} }
return &Index{words, alts, snippets, x.nspots}; return &Index{words, alts, snippets, x.nspots};
...@@ -678,7 +678,7 @@ func NewIndex(root string) *Index { ...@@ -678,7 +678,7 @@ func NewIndex(root string) *Index {
// Size returns the number of different words and // Size returns the number of different words and
// spots indexed as a measure for the index size. // spots indexed as a measure for the index size.
func (x *Index) Size() (nwords int, nspots int) { func (x *Index) Size() (nwords int, nspots int) {
return len(x.words), x.nspots; return len(x.words), x.nspots
} }
...@@ -689,7 +689,7 @@ func (x *Index) LookupWord(w string) (match *LookupResult, alt *AltWords) { ...@@ -689,7 +689,7 @@ func (x *Index) LookupWord(w string) (match *LookupResult, alt *AltWords) {
// (if there is no match, the alternatives do // (if there is no match, the alternatives do
// not contain the current spelling) // not contain the current spelling)
if match != nil && alt != nil { if match != nil && alt != nil {
alt = alt.filter(w); alt = alt.filter(w)
} }
return; return;
} }
...@@ -722,7 +722,7 @@ func (x *Index) Lookup(query string) (match *LookupResult, alt *AltWords, illega ...@@ -722,7 +722,7 @@ func (x *Index) Lookup(query string) (match *LookupResult, alt *AltWords, illega
switch len(ss) { switch len(ss) {
case 1: case 1:
match, alt = x.LookupWord(ss[0]); match, alt = x.LookupWord(ss[0])
case 2: case 2:
pakname := ss[0]; pakname := ss[0];
...@@ -735,7 +735,7 @@ func (x *Index) Lookup(query string) (match *LookupResult, alt *AltWords, illega ...@@ -735,7 +735,7 @@ func (x *Index) Lookup(query string) (match *LookupResult, alt *AltWords, illega
} }
default: default:
illegal = true; illegal = true
} }
return; return;
...@@ -745,7 +745,7 @@ func (x *Index) Lookup(query string) (match *LookupResult, alt *AltWords, illega ...@@ -745,7 +745,7 @@ func (x *Index) Lookup(query string) (match *LookupResult, alt *AltWords, illega
func (x *Index) Snippet(i int) *Snippet { func (x *Index) Snippet(i int) *Snippet {
// handle illegal snippet indices gracefully // handle illegal snippet indices gracefully
if 0 <= i && i < len(x.snippets) { if 0 <= i && i < len(x.snippets) {
return x.snippets[i]; return x.snippets[i]
} }
return nil; return nil;
} }
...@@ -60,7 +60,7 @@ func exec(c *http.Conn, args []string) (status int) { ...@@ -60,7 +60,7 @@ func exec(c *http.Conn, args []string) (status int) {
bin := args[0]; bin := args[0];
fds := []*os.File{nil, w, w}; fds := []*os.File{nil, w, w};
if *verbose { if *verbose {
log.Stderrf("executing %v", args); log.Stderrf("executing %v", args)
} }
pid, err := os.ForkExec(bin, args, os.Environ(), goroot, fds); pid, err := os.ForkExec(bin, args, os.Environ(), goroot, fds);
defer r.Close(); defer r.Close();
...@@ -86,7 +86,7 @@ func exec(c *http.Conn, args []string) (status int) { ...@@ -86,7 +86,7 @@ func exec(c *http.Conn, args []string) (status int) {
} }
if *verbose { if *verbose {
os.Stderr.Write(buf.Bytes()); os.Stderr.Write(buf.Bytes())
} }
if c != nil { if c != nil {
c.SetHeader("content-type", "text/plain; charset=utf-8"); c.SetHeader("content-type", "text/plain; charset=utf-8");
...@@ -114,10 +114,10 @@ func dosync(c *http.Conn, r *http.Request) { ...@@ -114,10 +114,10 @@ func dosync(c *http.Conn, r *http.Request) {
case 1: case 1:
// sync failed because no files changed; // sync failed because no files changed;
// don't change the package tree // don't change the package tree
syncDelay.set(*syncMin); // revert to regular sync schedule syncDelay.set(*syncMin) // revert to regular sync schedule
default: default:
// sync failed because of an error - back off exponentially, but try at least once a day // sync failed because of an error - back off exponentially, but try at least once a day
syncDelay.backoff(24*60); syncDelay.backoff(24*60)
} }
} }
...@@ -135,7 +135,7 @@ func loggingHandler(h http.Handler) http.Handler { ...@@ -135,7 +135,7 @@ func loggingHandler(h http.Handler) http.Handler {
return http.HandlerFunc(func(c *http.Conn, req *http.Request) { return http.HandlerFunc(func(c *http.Conn, req *http.Request) {
log.Stderrf("%s\t%s", c.RemoteAddr, req.URL); log.Stderrf("%s\t%s", c.RemoteAddr, req.URL);
h.ServeHTTP(c, req); h.ServeHTTP(c, req);
}); })
} }
...@@ -145,15 +145,15 @@ func main() { ...@@ -145,15 +145,15 @@ func main() {
// Check usage: either server and no args, or command line and args // Check usage: either server and no args, or command line and args
if (*httpaddr != "") != (flag.NArg() == 0) { if (*httpaddr != "") != (flag.NArg() == 0) {
usage(); usage()
} }
if *tabwidth < 0 { if *tabwidth < 0 {
log.Exitf("negative tabwidth %d", *tabwidth); log.Exitf("negative tabwidth %d", *tabwidth)
} }
if err := os.Chdir(goroot); err != nil { if err := os.Chdir(goroot); err != nil {
log.Exitf("chdir %s: %v", goroot, err); log.Exitf("chdir %s: %v", goroot, err)
} }
readTemplates(); readTemplates();
...@@ -174,7 +174,7 @@ func main() { ...@@ -174,7 +174,7 @@ func main() {
registerPublicHandlers(http.DefaultServeMux); registerPublicHandlers(http.DefaultServeMux);
if *syncCmd != "" { if *syncCmd != "" {
http.Handle("/debug/sync", http.HandlerFunc(dosync)); http.Handle("/debug/sync", http.HandlerFunc(dosync))
} }
// Initialize directory tree with corresponding timestamp. // Initialize directory tree with corresponding timestamp.
...@@ -192,7 +192,7 @@ func main() { ...@@ -192,7 +192,7 @@ func main() {
dosync(nil, nil); dosync(nil, nil);
delay, _ := syncDelay.get(); delay, _ := syncDelay.get();
if *verbose { if *verbose {
log.Stderrf("next sync in %dmin", delay.(int)); log.Stderrf("next sync in %dmin", delay.(int))
} }
time.Sleep(int64(delay.(int))*60e9); time.Sleep(int64(delay.(int))*60e9);
} }
...@@ -210,7 +210,7 @@ func main() { ...@@ -210,7 +210,7 @@ func main() {
// Start http server. // Start http server.
if err := http.ListenAndServe(*httpaddr, handler); err != nil { if err := http.ListenAndServe(*httpaddr, handler); err != nil {
log.Exitf("ListenAndServe %s: %v", *httpaddr, err); log.Exitf("ListenAndServe %s: %v", *httpaddr, err)
} }
return; return;
} }
...@@ -225,7 +225,7 @@ func main() { ...@@ -225,7 +225,7 @@ func main() {
if info.PDoc == nil && info.Dirs == nil { if info.PDoc == nil && info.Dirs == nil {
// try again, this time assume it's a command // try again, this time assume it's a command
info = cmdHandler.getPageInfo(flag.Arg(0)); info = cmdHandler.getPageInfo(flag.Arg(0))
} }
if info.PDoc != nil && flag.NArg() > 1 { if info.PDoc != nil && flag.NArg() > 1 {
...@@ -234,6 +234,6 @@ func main() { ...@@ -234,6 +234,6 @@ func main() {
} }
if err := packageText.Execute(info, os.Stdout); err != nil { if err := packageText.Execute(info, os.Stdout); err != nil {
log.Stderrf("packageText.Execute: %s", err); log.Stderrf("packageText.Execute: %s", err)
} }
} }
...@@ -31,14 +31,14 @@ type snippetStyler struct { ...@@ -31,14 +31,14 @@ type snippetStyler struct {
func (s *snippetStyler) LineTag(line int) (text []uint8, tag printer.HTMLTag) { func (s *snippetStyler) LineTag(line int) (text []uint8, tag printer.HTMLTag) {
return; // no LineTag for snippets return // no LineTag for snippets
} }
func (s *snippetStyler) Ident(id *ast.Ident) (text []byte, tag printer.HTMLTag) { func (s *snippetStyler) Ident(id *ast.Ident) (text []byte, tag printer.HTMLTag) {
text = strings.Bytes(id.Value); text = strings.Bytes(id.Value);
if s.highlight == id { if s.highlight == id {
tag = printer.HTMLTag{"<span class=highlight>", "</span>"}; tag = printer.HTMLTag{"<span class=highlight>", "</span>"}
} }
return; return;
} }
...@@ -56,17 +56,17 @@ func findSpec(list []ast.Spec, id *ast.Ident) ast.Spec { ...@@ -56,17 +56,17 @@ func findSpec(list []ast.Spec, id *ast.Ident) ast.Spec {
switch s := spec.(type) { switch s := spec.(type) {
case *ast.ImportSpec: case *ast.ImportSpec:
if s.Name == id { if s.Name == id {
return s; return s
} }
case *ast.ValueSpec: case *ast.ValueSpec:
for _, n := range s.Names { for _, n := range s.Names {
if n == id { if n == id {
return s; return s
} }
} }
case *ast.TypeSpec: case *ast.TypeSpec:
if s.Name == id { if s.Name == id {
return s; return s
} }
} }
} }
...@@ -77,7 +77,7 @@ func findSpec(list []ast.Spec, id *ast.Ident) ast.Spec { ...@@ -77,7 +77,7 @@ func findSpec(list []ast.Spec, id *ast.Ident) ast.Spec {
func genSnippet(d *ast.GenDecl, id *ast.Ident) *Snippet { func genSnippet(d *ast.GenDecl, id *ast.Ident) *Snippet {
s := findSpec(d.Specs, id); s := findSpec(d.Specs, id);
if s == nil { if s == nil {
return nil; // declaration doesn't contain id - exit gracefully return nil // declaration doesn't contain id - exit gracefully
} }
// only use the spec containing the id for the snippet // only use the spec containing the id for the snippet
...@@ -89,7 +89,7 @@ func genSnippet(d *ast.GenDecl, id *ast.Ident) *Snippet { ...@@ -89,7 +89,7 @@ func genSnippet(d *ast.GenDecl, id *ast.Ident) *Snippet {
func funcSnippet(d *ast.FuncDecl, id *ast.Ident) *Snippet { func funcSnippet(d *ast.FuncDecl, id *ast.Ident) *Snippet {
if d.Name != id { if d.Name != id {
return nil; // declaration doesn't contain id - exit gracefully return nil // declaration doesn't contain id - exit gracefully
} }
// only use the function signature for the snippet // only use the function signature for the snippet
...@@ -106,9 +106,9 @@ func funcSnippet(d *ast.FuncDecl, id *ast.Ident) *Snippet { ...@@ -106,9 +106,9 @@ func funcSnippet(d *ast.FuncDecl, id *ast.Ident) *Snippet {
func NewSnippet(decl ast.Decl, id *ast.Ident) (s *Snippet) { func NewSnippet(decl ast.Decl, id *ast.Ident) (s *Snippet) {
switch d := decl.(type) { switch d := decl.(type) {
case *ast.GenDecl: case *ast.GenDecl:
s = genSnippet(d, id); s = genSnippet(d, id)
case *ast.FuncDecl: case *ast.FuncDecl:
s = funcSnippet(d, id); s = funcSnippet(d, id)
} }
// handle failure gracefully // handle failure gracefully
...@@ -116,7 +116,7 @@ func NewSnippet(decl ast.Decl, id *ast.Ident) (s *Snippet) { ...@@ -116,7 +116,7 @@ func NewSnippet(decl ast.Decl, id *ast.Ident) (s *Snippet) {
s = &Snippet{ s = &Snippet{
id.Pos().Line, id.Pos().Line,
fmt.Sprintf(`could not generate a snippet for <span class="highlight">%s</span>`, id.Value), fmt.Sprintf(`could not generate a snippet for <span class="highlight">%s</span>`, id.Value),
}; }
} }
return; return;
} }
...@@ -43,13 +43,13 @@ func (p *ebnfParser) next() { ...@@ -43,13 +43,13 @@ func (p *ebnfParser) next() {
if p.tok.IsKeyword() { if p.tok.IsKeyword() {
// TODO Should keyword mapping always happen outside scanner? // TODO Should keyword mapping always happen outside scanner?
// Or should there be a flag to scanner to enable keyword mapping? // Or should there be a flag to scanner to enable keyword mapping?
p.tok = token.IDENT; p.tok = token.IDENT
} }
} }
func (p *ebnfParser) Error(pos token.Position, msg string) { func (p *ebnfParser) Error(pos token.Position, msg string) {
fmt.Fprintf(p.out, `<span class="alert">error: %s</span>`, msg); fmt.Fprintf(p.out, `<span class="alert">error: %s</span>`, msg)
} }
...@@ -60,7 +60,7 @@ func (p *ebnfParser) errorExpected(pos token.Position, msg string) { ...@@ -60,7 +60,7 @@ func (p *ebnfParser) errorExpected(pos token.Position, msg string) {
// make the error message more specific // make the error message more specific
msg += ", found '" + p.tok.String() + "'"; msg += ", found '" + p.tok.String() + "'";
if p.tok.IsLiteral() { if p.tok.IsLiteral() {
msg += " "+string(p.lit); msg += " "+string(p.lit)
} }
} }
p.Error(pos, msg); p.Error(pos, msg);
...@@ -70,7 +70,7 @@ func (p *ebnfParser) errorExpected(pos token.Position, msg string) { ...@@ -70,7 +70,7 @@ func (p *ebnfParser) errorExpected(pos token.Position, msg string) {
func (p *ebnfParser) expect(tok token.Token) token.Position { func (p *ebnfParser) expect(tok token.Token) token.Position {
pos := p.pos; pos := p.pos;
if p.tok != tok { if p.tok != tok {
p.errorExpected(pos, "'" + tok.String() + "'"); p.errorExpected(pos, "'" + tok.String() + "'")
} }
p.next(); // make progress in any case p.next(); // make progress in any case
return pos; return pos;
...@@ -81,9 +81,9 @@ func (p *ebnfParser) parseIdentifier(def bool) { ...@@ -81,9 +81,9 @@ func (p *ebnfParser) parseIdentifier(def bool) {
name := string(p.lit); name := string(p.lit);
p.expect(token.IDENT); p.expect(token.IDENT);
if def { if def {
fmt.Fprintf(p.out, `<a id="%s">%s</a>`, name, name); fmt.Fprintf(p.out, `<a id="%s">%s</a>`, name, name)
} else { } else {
fmt.Fprintf(p.out, `<a href="#%s" class="noline">%s</a>`, name, name); fmt.Fprintf(p.out, `<a href="#%s" class="noline">%s</a>`, name, name)
} }
p.prev += len(name); // skip identifier when calling flush p.prev += len(name); // skip identifier when calling flush
} }
...@@ -92,7 +92,7 @@ func (p *ebnfParser) parseIdentifier(def bool) { ...@@ -92,7 +92,7 @@ func (p *ebnfParser) parseIdentifier(def bool) {
func (p *ebnfParser) parseTerm() bool { func (p *ebnfParser) parseTerm() bool {
switch p.tok { switch p.tok {
case token.IDENT: case token.IDENT:
p.parseIdentifier(false); p.parseIdentifier(false)
case token.STRING: case token.STRING:
p.next(); p.next();
...@@ -117,7 +117,7 @@ func (p *ebnfParser) parseTerm() bool { ...@@ -117,7 +117,7 @@ func (p *ebnfParser) parseTerm() bool {
p.expect(token.RBRACE); p.expect(token.RBRACE);
default: default:
return false; return false
} }
return true; return true;
...@@ -134,7 +134,7 @@ func (p *ebnfParser) parseExpression() { ...@@ -134,7 +134,7 @@ func (p *ebnfParser) parseExpression() {
for { for {
p.parseSequence(); p.parseSequence();
if p.tok != token.OR { if p.tok != token.OR {
break; break
} }
p.next(); p.next();
} }
...@@ -158,7 +158,7 @@ func (p *ebnfParser) parse(out io.Writer, src []byte) { ...@@ -158,7 +158,7 @@ func (p *ebnfParser) parse(out io.Writer, src []byte) {
// process source // process source
for p.tok != token.EOF { for p.tok != token.EOF {
p.parseProduction(); p.parseProduction()
} }
p.flush(); p.flush();
} }
...@@ -178,14 +178,14 @@ func linkify(out io.Writer, src []byte) { ...@@ -178,14 +178,14 @@ func linkify(out io.Writer, src []byte) {
// i: beginning of EBNF text (or end of source) // i: beginning of EBNF text (or end of source)
i := bytes.Index(src, openTag); i := bytes.Index(src, openTag);
if i < 0 { if i < 0 {
i = n-len(openTag); i = n-len(openTag)
} }
i += len(openTag); i += len(openTag);
// j: end of EBNF text (or end of source) // j: end of EBNF text (or end of source)
j := bytes.Index(src[i:n], closeTag); // close marker j := bytes.Index(src[i:n], closeTag); // close marker
if j < 0 { if j < 0 {
j = n-i; j = n-i
} }
j += i; j += i;
......
...@@ -52,10 +52,10 @@ func usage() { ...@@ -52,10 +52,10 @@ func usage() {
func parserMode() uint { func parserMode() uint {
mode := uint(0); mode := uint(0);
if *comments { if *comments {
mode |= parser.ParseComments; mode |= parser.ParseComments
} }
if *trace { if *trace {
mode |= parser.Trace; mode |= parser.Trace
} }
return mode; return mode;
} }
...@@ -64,10 +64,10 @@ func parserMode() uint { ...@@ -64,10 +64,10 @@ func parserMode() uint {
func printerMode() uint { func printerMode() uint {
mode := uint(0); mode := uint(0);
if !*align { if !*align {
mode |= printer.RawFormat; mode |= printer.RawFormat
} }
if *usespaces { if *usespaces {
mode |= printer.UseSpaces; mode |= printer.UseSpaces
} }
return mode; return mode;
} }
...@@ -75,42 +75,42 @@ func printerMode() uint { ...@@ -75,42 +75,42 @@ func printerMode() uint {
func isGoFile(d *os.Dir) bool { func isGoFile(d *os.Dir) bool {
// ignore non-Go files // ignore non-Go files
return d.IsRegular() && !strings.HasPrefix(d.Name, ".") && strings.HasSuffix(d.Name, ".go"); return d.IsRegular() && !strings.HasPrefix(d.Name, ".") && strings.HasSuffix(d.Name, ".go")
} }
func processFile(filename string) os.Error { func processFile(filename string) os.Error {
src, err := io.ReadFile(filename); src, err := io.ReadFile(filename);
if err != nil { if err != nil {
return err; return err
} }
file, err := parser.ParseFile(filename, src, parserMode()); file, err := parser.ParseFile(filename, src, parserMode());
if err != nil { if err != nil {
return err; return err
} }
var res bytes.Buffer; var res bytes.Buffer;
_, err = (&printer.Config{printerMode(), *tabwidth, nil}).Fprint(&res, file); _, err = (&printer.Config{printerMode(), *tabwidth, nil}).Fprint(&res, file);
if err != nil { if err != nil {
return err; return err
} }
if bytes.Compare(src, res.Bytes()) != 0 { if bytes.Compare(src, res.Bytes()) != 0 {
// formatting has changed // formatting has changed
if *list { if *list {
fmt.Fprintln(os.Stdout, filename); fmt.Fprintln(os.Stdout, filename)
} }
if *write { if *write {
err = io.WriteFile(filename, res.Bytes(), 0); err = io.WriteFile(filename, res.Bytes(), 0);
if err != nil { if err != nil {
return err; return err
} }
} }
} }
if !*list && !*write { if !*list && !*write {
_, err = os.Stdout.Write(res.Bytes()); _, err = os.Stdout.Write(res.Bytes())
} }
return err; return err;
...@@ -120,7 +120,7 @@ func processFile(filename string) os.Error { ...@@ -120,7 +120,7 @@ func processFile(filename string) os.Error {
type fileVisitor chan os.Error type fileVisitor chan os.Error
func (v fileVisitor) VisitDir(path string, d *os.Dir) bool { func (v fileVisitor) VisitDir(path string, d *os.Dir) bool {
return true; return true
} }
...@@ -128,7 +128,7 @@ func (v fileVisitor) VisitFile(path string, d *os.Dir) { ...@@ -128,7 +128,7 @@ func (v fileVisitor) VisitFile(path string, d *os.Dir) {
if isGoFile(d) { if isGoFile(d) {
v <- nil; // synchronize error handler v <- nil; // synchronize error handler
if err := processFile(path); err != nil { if err := processFile(path); err != nil {
v <- err; v <- err
} }
} }
} }
...@@ -140,7 +140,7 @@ func walkDir(path string) { ...@@ -140,7 +140,7 @@ func walkDir(path string) {
go func() { go func() {
for err := range v { for err := range v {
if err != nil { if err != nil {
report(err); report(err)
} }
} }
}(); }();
...@@ -160,7 +160,7 @@ func main() { ...@@ -160,7 +160,7 @@ func main() {
if flag.NArg() == 0 { if flag.NArg() == 0 {
if err := processFile("/dev/stdin"); err != nil { if err := processFile("/dev/stdin"); err != nil {
report(err); report(err)
} }
} }
...@@ -168,13 +168,13 @@ func main() { ...@@ -168,13 +168,13 @@ func main() {
path := flag.Arg(i); path := flag.Arg(i);
switch dir, err := os.Stat(path); { switch dir, err := os.Stat(path); {
case err != nil: case err != nil:
report(err); report(err)
case dir.IsRegular(): case dir.IsRegular():
if err := processFile(path); err != nil { if err := processFile(path); err != nil {
report(err); report(err)
} }
case dir.IsDirectory(): case dir.IsDirectory():
walkDir(path); walkDir(path)
} }
} }
......
This diff is collapsed.
...@@ -35,11 +35,11 @@ func main() { ...@@ -35,11 +35,11 @@ func main() {
var err os.Error; var err os.Error;
switch len(args) { switch len(args) {
case 0: case 0:
data, err = io.ReadAll(os.Stdin); data, err = io.ReadAll(os.Stdin)
case 1: case 1:
data, err = io.ReadFile(args[0]); data, err = io.ReadFile(args[0])
default: default:
usage(); usage()
} }
chk(err); chk(err);
...@@ -63,25 +63,25 @@ func main() { ...@@ -63,25 +63,25 @@ func main() {
chk(err); chk(err);
dirty := make(map[string]int); dirty := make(map[string]int);
for _, f := range dirtylist { for _, f := range dirtylist {
dirty[f] = 1; dirty[f] = 1
} }
conflict := make(map[string]int); conflict := make(map[string]int);
for _, f := range pset.File { for _, f := range pset.File {
if f.Verb == patch.Delete || f.Verb == patch.Rename { if f.Verb == patch.Delete || f.Verb == patch.Rename {
if _, ok := dirty[f.Src]; ok { if _, ok := dirty[f.Src]; ok {
conflict[f.Src] = 1; conflict[f.Src] = 1
} }
} }
if f.Verb != patch.Delete { if f.Verb != patch.Delete {
if _, ok := dirty[f.Dst]; ok { if _, ok := dirty[f.Dst]; ok {
conflict[f.Dst] = 1; conflict[f.Dst] = 1
} }
} }
} }
if len(conflict) > 0 { if len(conflict) > 0 {
fmt.Fprintf(os.Stderr, "cannot apply patch to locally modified files:\n"); fmt.Fprintf(os.Stderr, "cannot apply patch to locally modified files:\n");
for name := range conflict { for name := range conflict {
fmt.Fprintf(os.Stderr, "\t%s\n", name); fmt.Fprintf(os.Stderr, "\t%s\n", name)
} }
os.Exit(2); os.Exit(2);
} }
...@@ -136,7 +136,7 @@ func main() { ...@@ -136,7 +136,7 @@ func main() {
for i := range op { for i := range op {
o := &op[i]; o := &op[i];
if o.Verb == patch.Delete { if o.Verb == patch.Delete {
continue; continue
} }
if o.Verb == patch.Add { if o.Verb == patch.Add {
makeParent(o.Dst); makeParent(o.Dst);
...@@ -145,9 +145,9 @@ func main() { ...@@ -145,9 +145,9 @@ func main() {
if o.Data != nil { if o.Data != nil {
chk(io.WriteFile(o.Dst, o.Data, 0644)); chk(io.WriteFile(o.Dst, o.Data, 0644));
if o.Verb == patch.Add { if o.Verb == patch.Add {
undoRm(o.Dst); undoRm(o.Dst)
} else { } else {
undoRevert(o.Dst); undoRevert(o.Dst)
} }
changed[o.Dst] = 1; changed[o.Dst] = 1;
} }
...@@ -178,7 +178,7 @@ func main() { ...@@ -178,7 +178,7 @@ func main() {
} }
sort.SortStrings(list); sort.SortStrings(list);
for _, f := range list { for _, f := range list {
fmt.Printf("%s\n", f); fmt.Printf("%s\n", f)
} }
} }
...@@ -195,25 +195,25 @@ func mkdirAll(path string, perm int) os.Error { ...@@ -195,25 +195,25 @@ func mkdirAll(path string, perm int) os.Error {
dir, err := os.Lstat(path); dir, err := os.Lstat(path);
if err == nil { if err == nil {
if dir.IsDirectory() { if dir.IsDirectory() {
return nil; return nil
} }
return &os.PathError{"mkdir", path, os.ENOTDIR}; return &os.PathError{"mkdir", path, os.ENOTDIR};
} }
i := len(path); i := len(path);
for i > 0 && path[i-1] == '/' { // Skip trailing slashes. for i > 0 && path[i-1] == '/' { // Skip trailing slashes.
i--; i--
} }
j := i; j := i;
for j > 0 && path[j-1] != '/' { // Scan backward over element. for j > 0 && path[j-1] != '/' { // Scan backward over element.
j--; j--
} }
if j > 0 { if j > 0 {
err = mkdirAll(path[0 : j-1], perm); err = mkdirAll(path[0 : j-1], perm);
if err != nil { if err != nil {
return err; return err
} }
} }
...@@ -223,7 +223,7 @@ func mkdirAll(path string, perm int) os.Error { ...@@ -223,7 +223,7 @@ func mkdirAll(path string, perm int) os.Error {
// double-checking that directory doesn't exist. // double-checking that directory doesn't exist.
dir, err1 := os.Lstat(path); dir, err1 := os.Lstat(path);
if err1 == nil && dir.IsDirectory() { if err1 == nil && dir.IsDirectory() {
return nil; return nil
} }
return err; return err;
} }
...@@ -253,7 +253,7 @@ func undoRm(name string) { undoLog.Push(undo(func() os.Error { return os.Remove( ...@@ -253,7 +253,7 @@ func undoRm(name string) { undoLog.Push(undo(func() os.Error { return os.Remove(
func runUndo() { func runUndo() {
for i := undoLog.Len() - 1; i >= 0; i-- { for i := undoLog.Len() - 1; i >= 0; i-- {
if err := undoLog.At(i).(undo)(); err != nil { if err := undoLog.At(i).(undo)(); err != nil {
fmt.Fprintf(os.Stderr, "%s\n", err); fmt.Fprintf(os.Stderr, "%s\n", err)
} }
} }
} }
...@@ -263,7 +263,7 @@ func runUndo() { ...@@ -263,7 +263,7 @@ func runUndo() {
func hgRoot() (string, os.Error) { func hgRoot() (string, os.Error) {
out, err := run([]string{"hg", "root"}, nil); out, err := run([]string{"hg", "root"}, nil);
if err != nil { if err != nil {
return "", err; return "", err
} }
return strings.TrimSpace(out), nil; return strings.TrimSpace(out), nil;
} }
...@@ -280,7 +280,7 @@ func hgIncoming() bool { ...@@ -280,7 +280,7 @@ func hgIncoming() bool {
func hgModified() ([]string, os.Error) { func hgModified() ([]string, os.Error) {
out, err := run([]string{"hg", "status", "-n"}, nil); out, err := run([]string{"hg", "status", "-n"}, nil);
if err != nil { if err != nil {
return nil, err; return nil, err
} }
return strings.Split(strings.TrimSpace(out), "\n", 0), nil; return strings.Split(strings.TrimSpace(out), "\n", 0), nil;
} }
...@@ -320,7 +320,7 @@ func hgRename(dst, src string) os.Error { ...@@ -320,7 +320,7 @@ func hgRename(dst, src string) os.Error {
func copy(a []string) []string { func copy(a []string) []string {
b := make([]string, len(a)); b := make([]string, len(a));
for i, s := range a { for i, s := range a {
b[i] = s; b[i] = s
} }
return b; return b;
} }
...@@ -338,7 +338,7 @@ func run(argv []string, input []byte) (out string, err os.Error) { ...@@ -338,7 +338,7 @@ func run(argv []string, input []byte) (out string, err os.Error) {
if !ok { if !ok {
prog, err = exec.LookPath(argv[0]); prog, err = exec.LookPath(argv[0]);
if err != nil { if err != nil {
goto Error; goto Error
} }
lookPathCache[argv[0]] = prog; lookPathCache[argv[0]] = prog;
} }
...@@ -347,12 +347,12 @@ func run(argv []string, input []byte) (out string, err os.Error) { ...@@ -347,12 +347,12 @@ func run(argv []string, input []byte) (out string, err os.Error) {
if len(input) == 0 { if len(input) == 0 {
cmd, err = exec.Run(prog, argv, os.Environ(), exec.DevNull, exec.Pipe, exec.MergeWithStdout); cmd, err = exec.Run(prog, argv, os.Environ(), exec.DevNull, exec.Pipe, exec.MergeWithStdout);
if err != nil { if err != nil {
goto Error; goto Error
} }
} else { } else {
cmd, err = exec.Run(prog, argv, os.Environ(), exec.Pipe, exec.Pipe, exec.MergeWithStdout); cmd, err = exec.Run(prog, argv, os.Environ(), exec.Pipe, exec.Pipe, exec.MergeWithStdout);
if err != nil { if err != nil {
goto Error; goto Error
} }
go func() { go func() {
cmd.Stdin.Write(input); cmd.Stdin.Write(input);
...@@ -369,7 +369,7 @@ func run(argv []string, input []byte) (out string, err os.Error) { ...@@ -369,7 +369,7 @@ func run(argv []string, input []byte) (out string, err os.Error) {
} }
w, err := cmd.Wait(0); w, err := cmd.Wait(0);
if err != nil { if err != nil {
goto Error; goto Error
} }
if !w.Exited() || w.ExitStatus() != 0 { if !w.Exited() || w.ExitStatus() != 0 {
err = w; err = w;
......
...@@ -50,10 +50,10 @@ func NewReader(r io.Reader) *Reader { return &Reader{r: r} } ...@@ -50,10 +50,10 @@ func NewReader(r io.Reader) *Reader { return &Reader{r: r} }
func (tr *Reader) Next() (*Header, os.Error) { func (tr *Reader) Next() (*Header, os.Error) {
var hdr *Header; var hdr *Header;
if tr.err == nil { if tr.err == nil {
tr.skipUnread(); tr.skipUnread()
} }
if tr.err == nil { if tr.err == nil {
hdr = tr.readHeader(); hdr = tr.readHeader()
} }
return hdr, tr.err; return hdr, tr.err;
} }
...@@ -63,7 +63,7 @@ func (tr *Reader) Next() (*Header, os.Error) { ...@@ -63,7 +63,7 @@ func (tr *Reader) Next() (*Header, os.Error) {
func cString(b []byte) string { func cString(b []byte) string {
n := 0; n := 0;
for n < len(b) && b[n] != 0 { for n < len(b) && b[n] != 0 {
n++; n++
} }
return string(b[0:n]); return string(b[0:n]);
} }
...@@ -71,15 +71,15 @@ func cString(b []byte) string { ...@@ -71,15 +71,15 @@ func cString(b []byte) string {
func (tr *Reader) octal(b []byte) int64 { func (tr *Reader) octal(b []byte) int64 {
// Removing leading spaces. // Removing leading spaces.
for len(b) > 0 && b[0] == ' ' { for len(b) > 0 && b[0] == ' ' {
b = b[1:len(b)]; b = b[1:len(b)]
} }
// Removing trailing NULs and spaces. // Removing trailing NULs and spaces.
for len(b) > 0 && (b[len(b)-1] == ' ' || b[len(b)-1] == '\x00') { 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); x, err := strconv.Btoui64(cString(b), 8);
if err != nil { if err != nil {
tr.err = err; tr.err = err
} }
return int64(x); return int64(x);
} }
...@@ -87,7 +87,7 @@ func (tr *Reader) octal(b []byte) int64 { ...@@ -87,7 +87,7 @@ func (tr *Reader) octal(b []byte) int64 {
type ignoreWriter struct{} type ignoreWriter struct{}
func (ignoreWriter) Write(b []byte) (n int, err os.Error) { 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. // Skip any unread bytes in the existing file entry, as well as any alignment padding.
...@@ -95,16 +95,16 @@ func (tr *Reader) skipUnread() { ...@@ -95,16 +95,16 @@ func (tr *Reader) skipUnread() {
nr := tr.nb + tr.pad; // number of bytes to skip nr := tr.nb + tr.pad; // number of bytes to skip
if sr, ok := tr.r.(io.Seeker); ok { if sr, ok := tr.r.(io.Seeker); ok {
_, tr.err = sr.Seek(nr, 1); _, tr.err = sr.Seek(nr, 1)
} else { } else {
_, tr.err = io.Copyn(ignoreWriter{}, tr.r, nr); _, tr.err = io.Copyn(ignoreWriter{}, tr.r, nr)
} }
tr.nb, tr.pad = 0, 0; tr.nb, tr.pad = 0, 0;
} }
func (tr *Reader) verifyChecksum(header []byte) bool { func (tr *Reader) verifyChecksum(header []byte) bool {
if tr.err != nil { if tr.err != nil {
return false; return false
} }
given := tr.octal(header[148:156]); given := tr.octal(header[148:156]);
...@@ -115,16 +115,16 @@ func (tr *Reader) verifyChecksum(header []byte) bool { ...@@ -115,16 +115,16 @@ func (tr *Reader) verifyChecksum(header []byte) bool {
func (tr *Reader) readHeader() *Header { func (tr *Reader) readHeader() *Header {
header := make([]byte, blockSize); header := make([]byte, blockSize);
if _, tr.err = io.ReadFull(tr.r, header); tr.err != nil { 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. // Two blocks of zero bytes marks the end of the archive.
if bytes.Equal(header, zeroBlock[0 : blockSize]) { if bytes.Equal(header, zeroBlock[0 : blockSize]) {
if _, tr.err = io.ReadFull(tr.r, header); tr.err != nil { if _, tr.err = io.ReadFull(tr.r, header); tr.err != nil {
return nil; return nil
} }
if !bytes.Equal(header, zeroBlock[0 : blockSize]) { if !bytes.Equal(header, zeroBlock[0 : blockSize]) {
tr.err = HeaderError; tr.err = HeaderError
} }
return nil; return nil;
} }
...@@ -156,12 +156,12 @@ func (tr *Reader) readHeader() *Header { ...@@ -156,12 +156,12 @@ func (tr *Reader) readHeader() *Header {
switch magic { switch magic {
case "ustar\x0000": // POSIX tar (1003.1-1988) case "ustar\x0000": // POSIX tar (1003.1-1988)
if string(header[508:512]) == "tar\x00" { if string(header[508:512]) == "tar\x00" {
format = "star"; format = "star"
} else { } else {
format = "posix"; format = "posix"
} }
case "ustar \x00": // old GNU tar case "ustar \x00": // old GNU tar
format = "gnu"; format = "gnu"
} }
switch format { switch format {
...@@ -177,14 +177,14 @@ func (tr *Reader) readHeader() *Header { ...@@ -177,14 +177,14 @@ func (tr *Reader) readHeader() *Header {
var prefix string; var prefix string;
switch format { switch format {
case "posix", "gnu": case "posix", "gnu":
prefix = cString(s.next(155)); prefix = cString(s.next(155))
case "star": case "star":
prefix = cString(s.next(131)); prefix = cString(s.next(131));
hdr.Atime = tr.octal(s.next(12)); hdr.Atime = tr.octal(s.next(12));
hdr.Ctime = tr.octal(s.next(12)); hdr.Ctime = tr.octal(s.next(12));
} }
if len(prefix) > 0 { if len(prefix) > 0 {
hdr.Name = prefix + "/" + hdr.Name; hdr.Name = prefix + "/" + hdr.Name
} }
} }
...@@ -206,7 +206,7 @@ func (tr *Reader) readHeader() *Header { ...@@ -206,7 +206,7 @@ func (tr *Reader) readHeader() *Header {
// until Next is called to advance to the next entry. // until Next is called to advance to the next entry.
func (tr *Reader) Read(b []uint8) (n int, err os.Error) { func (tr *Reader) Read(b []uint8) (n int, err os.Error) {
if int64(len(b)) > tr.nb { if int64(len(b)) > tr.nb {
b = b[0 : tr.nb]; b = b[0 : tr.nb]
} }
n, err = tr.r.Read(b); n, err = tr.r.Read(b);
tr.nb -= int64(n); tr.nb -= int64(n);
......
...@@ -120,12 +120,12 @@ testLoop: ...@@ -120,12 +120,12 @@ testLoop:
} }
if !reflect.DeepEqual(hdr, header) { if !reflect.DeepEqual(hdr, header) {
t.Errorf("test %d, entry %d: Incorrect header:\nhave %+v\nwant %+v", t.Errorf("test %d, entry %d: Incorrect header:\nhave %+v\nwant %+v",
i, j, *hdr, *header); i, j, *hdr, *header)
} }
} }
hdr, err := tr.Next(); hdr, err := tr.Next();
if hdr != nil || err != nil { if hdr != nil || err != nil {
t.Errorf("test %d: Unexpected entry or error: hdr=%v err=%v", i, err); t.Errorf("test %d: Unexpected entry or error: hdr=%v err=%v", i, err)
} }
f.Close(); f.Close();
} }
...@@ -134,7 +134,7 @@ testLoop: ...@@ -134,7 +134,7 @@ testLoop:
func TestPartialRead(t *testing.T) { func TestPartialRead(t *testing.T) {
f, err := os.Open("testdata/gnu.tar", os.O_RDONLY, 0444); f, err := os.Open("testdata/gnu.tar", os.O_RDONLY, 0444);
if err != nil { if err != nil {
t.Fatalf("Unexpected error: %v", err); t.Fatalf("Unexpected error: %v", err)
} }
defer f.Close(); defer f.Close();
...@@ -143,26 +143,26 @@ func TestPartialRead(t *testing.T) { ...@@ -143,26 +143,26 @@ func TestPartialRead(t *testing.T) {
// Read the first four bytes; Next() should skip the last byte. // Read the first four bytes; Next() should skip the last byte.
hdr, err := tr.Next(); hdr, err := tr.Next();
if err != nil || hdr == nil { if err != nil || hdr == nil {
t.Fatalf("Didn't get first file: %v", err); t.Fatalf("Didn't get first file: %v", err)
} }
buf := make([]byte, 4); buf := make([]byte, 4);
if _, err := io.ReadFull(tr, buf); err != nil { if _, err := io.ReadFull(tr, buf); err != nil {
t.Fatalf("Unexpected error: %v", err); t.Fatalf("Unexpected error: %v", err)
} }
if expected := strings.Bytes("Kilt"); !bytes.Equal(buf, expected) { if expected := strings.Bytes("Kilt"); !bytes.Equal(buf, expected) {
t.Errorf("Contents = %v, want %v", buf, expected); t.Errorf("Contents = %v, want %v", buf, expected)
} }
// Second file // Second file
hdr, err = tr.Next(); hdr, err = tr.Next();
if err != nil || hdr == nil { if err != nil || hdr == nil {
t.Fatalf("Didn't get second file: %v", err); t.Fatalf("Didn't get second file: %v", err)
} }
buf = make([]byte, 6); buf = make([]byte, 6);
if _, err := io.ReadFull(tr, buf); err != nil { if _, err := io.ReadFull(tr, buf); err != nil {
t.Fatalf("Unexpected error: %v", err); t.Fatalf("Unexpected error: %v", err)
} }
if expected := strings.Bytes("Google"); !bytes.Equal(buf, expected) { if expected := strings.Bytes("Google"); !bytes.Equal(buf, expected) {
t.Errorf("Contents = %v, want %v", buf, expected); t.Errorf("Contents = %v, want %v", buf, expected)
} }
} }
...@@ -53,7 +53,7 @@ func (tw *Writer) Flush() os.Error { ...@@ -53,7 +53,7 @@ func (tw *Writer) Flush() os.Error {
for n > 0 && tw.err == nil { for n > 0 && tw.err == nil {
nr := n; nr := n;
if nr > blockSize { if nr > blockSize {
nr = blockSize; nr = blockSize
} }
var nw int; var nw int;
nw, tw.err = tw.w.Write(zeroBlock[0:nr]); nw, tw.err = tw.w.Write(zeroBlock[0:nr]);
...@@ -68,15 +68,15 @@ func (tw *Writer) Flush() os.Error { ...@@ -68,15 +68,15 @@ func (tw *Writer) Flush() os.Error {
func (tw *Writer) cString(b []byte, s string) { func (tw *Writer) cString(b []byte, s string) {
if len(s) > len(b) { if len(s) > len(b) {
if tw.err == nil { if tw.err == nil {
tw.err = ErrFieldTooLong; tw.err = ErrFieldTooLong
} }
return; return;
} }
for i, ch := range strings.Bytes(s) { for i, ch := range strings.Bytes(s) {
b[i] = ch; b[i] = ch
} }
if len(s) < len(b) { if len(s) < len(b) {
b[len(s)] = 0; b[len(s)] = 0
} }
} }
...@@ -85,7 +85,7 @@ func (tw *Writer) octal(b []byte, x int64) { ...@@ -85,7 +85,7 @@ func (tw *Writer) octal(b []byte, x int64) {
s := strconv.Itob64(x, 8); s := strconv.Itob64(x, 8);
// leading zeros, but leave room for a NUL. // leading zeros, but leave room for a NUL.
for len(s)+1 < len(b) { for len(s)+1 < len(b) {
s = "0"+s; s = "0"+s
} }
tw.cString(b, s); tw.cString(b, s);
} }
...@@ -111,10 +111,10 @@ func (tw *Writer) numeric(b []byte, x int64) { ...@@ -111,10 +111,10 @@ func (tw *Writer) numeric(b []byte, x int64) {
// WriteHeader calls Flush if it is not the first header. // WriteHeader calls Flush if it is not the first header.
func (tw *Writer) WriteHeader(hdr *Header) os.Error { func (tw *Writer) WriteHeader(hdr *Header) os.Error {
if tw.err == nil { if tw.err == nil {
tw.Flush(); tw.Flush()
} }
if tw.err != nil { if tw.err != nil {
return tw.err; return tw.err
} }
tw.nb = int64(hdr.Size); tw.nb = int64(hdr.Size);
...@@ -142,7 +142,7 @@ func (tw *Writer) WriteHeader(hdr *Header) os.Error { ...@@ -142,7 +142,7 @@ func (tw *Writer) WriteHeader(hdr *Header) os.Error {
// Use the GNU magic instead of POSIX magic if we used any GNU extensions. // Use the GNU magic instead of POSIX magic if we used any GNU extensions.
if tw.usedBinary { if tw.usedBinary {
bytes.Copy(header[257:265], strings.Bytes("ustar \x00")); bytes.Copy(header[257:265], strings.Bytes("ustar \x00"))
} }
// The chksum field is terminated by a NUL and a space. // The chksum field is terminated by a NUL and a space.
...@@ -153,7 +153,7 @@ func (tw *Writer) WriteHeader(hdr *Header) os.Error { ...@@ -153,7 +153,7 @@ func (tw *Writer) WriteHeader(hdr *Header) os.Error {
if tw.err != nil { if tw.err != nil {
// problem with header; probably integer too big for a field. // problem with header; probably integer too big for a field.
return tw.err; return tw.err
} }
_, tw.err = tw.w.Write(header); _, tw.err = tw.w.Write(header);
...@@ -173,7 +173,7 @@ func (tw *Writer) Write(b []uint8) (n int, err os.Error) { ...@@ -173,7 +173,7 @@ func (tw *Writer) Write(b []uint8) (n int, err os.Error) {
n, err = tw.w.Write(b); n, err = tw.w.Write(b);
tw.nb -= int64(n); tw.nb -= int64(n);
if err == nil && overwrite { if err == nil && overwrite {
err = ErrWriteTooLong; err = ErrWriteTooLong
} }
tw.err = err; tw.err = err;
return; return;
...@@ -181,7 +181,7 @@ func (tw *Writer) Write(b []uint8) (n int, err os.Error) { ...@@ -181,7 +181,7 @@ func (tw *Writer) Write(b []uint8) (n int, err os.Error) {
func (tw *Writer) Close() os.Error { func (tw *Writer) Close() os.Error {
if tw.err != nil || tw.closed { if tw.err != nil || tw.closed {
return tw.err; return tw.err
} }
tw.Flush(); tw.Flush();
tw.closed = true; tw.closed = true;
...@@ -190,7 +190,7 @@ func (tw *Writer) Close() os.Error { ...@@ -190,7 +190,7 @@ func (tw *Writer) Close() os.Error {
for i := 0; i < 2; i++ { for i := 0; i < 2; i++ {
_, tw.err = tw.w.Write(zeroBlock); _, tw.err = tw.w.Write(zeroBlock);
if tw.err != nil { if tw.err != nil {
break; break
} }
} }
return tw.err; return tw.err;
......
...@@ -87,9 +87,9 @@ func bytestr(offset int, b []byte) string { ...@@ -87,9 +87,9 @@ func bytestr(offset int, b []byte) string {
for _, ch := range b { for _, ch := range b {
switch { switch {
case '0' <= ch && ch <= '9', 'A' <= ch && ch <= 'Z', 'a' <= ch && ch <= 'z': case '0' <= ch && ch <= '9', 'A' <= ch && ch <= 'Z', 'a' <= ch && ch <= 'z':
s += fmt.Sprintf(" %c", ch); s += fmt.Sprintf(" %c", ch)
default: default:
s += fmt.Sprintf(" %02x", ch); s += fmt.Sprintf(" %02x", ch)
} }
} }
return s; return s;
...@@ -102,15 +102,15 @@ func bytediff(a []byte, b []byte) string { ...@@ -102,15 +102,15 @@ func bytediff(a []byte, b []byte) string {
for offset := 0; len(a)+len(b) > 0; offset += rowLen { for offset := 0; len(a)+len(b) > 0; offset += rowLen {
na, nb := rowLen, rowLen; na, nb := rowLen, rowLen;
if na > len(a) { if na > len(a) {
na = len(a); na = len(a)
} }
if nb > len(b) { if nb > len(b) {
nb = len(b); nb = len(b)
} }
sa := bytestr(offset, a[0:na]); sa := bytestr(offset, a[0:na]);
sb := bytestr(offset, b[0:nb]); sb := bytestr(offset, b[0:nb]);
if sa != sb { if sa != sb {
s += fmt.Sprintf("-%v\n+%v\n", sa, sb); s += fmt.Sprintf("-%v\n+%v\n", sa, sb)
} }
a = a[na:len(a)]; a = a[na:len(a)];
b = b[nb:len(b)]; b = b[nb:len(b)];
...@@ -147,7 +147,7 @@ testLoop: ...@@ -147,7 +147,7 @@ testLoop:
actual := buf.Bytes(); actual := buf.Bytes();
if !bytes.Equal(expected, actual) { if !bytes.Equal(expected, actual) {
t.Errorf("test %d: Incorrect result: (-=expected, +=actual)\n%v", t.Errorf("test %d: Incorrect result: (-=expected, +=actual)\n%v",
i, bytediff(expected, actual)); i, bytediff(expected, actual))
} }
} }
} }
This diff is collapsed.
...@@ -35,10 +35,10 @@ func TestParseInt64(t *testing.T) { ...@@ -35,10 +35,10 @@ func TestParseInt64(t *testing.T) {
for i, test := range int64TestData { for i, test := range int64TestData {
ret, err := parseInt64(test.in); ret, err := parseInt64(test.in);
if (err == nil) != test.ok { if (err == nil) != test.ok {
t.Errorf("#%d: Incorrect error result (did fail? %v, expected: %v)", i, err == nil, test.ok); t.Errorf("#%d: Incorrect error result (did fail? %v, expected: %v)", i, err == nil, test.ok)
} }
if test.ok && ret != test.out { if test.ok && ret != test.out {
t.Errorf("#%d: Bad result: %v (expected %v)", i, ret, test.out); t.Errorf("#%d: Bad result: %v (expected %v)", i, ret, test.out)
} }
} }
} }
...@@ -63,11 +63,11 @@ func TestBitString(t *testing.T) { ...@@ -63,11 +63,11 @@ func TestBitString(t *testing.T) {
for i, test := range bitStringTestData { for i, test := range bitStringTestData {
ret, err := parseBitString(test.in); ret, err := parseBitString(test.in);
if (err == nil) != test.ok { if (err == nil) != test.ok {
t.Errorf("#%d: Incorrect error result (did fail? %v, expected: %v)", i, err == nil, test.ok); t.Errorf("#%d: Incorrect error result (did fail? %v, expected: %v)", i, err == nil, test.ok)
} }
if err == nil { if err == nil {
if test.bitLength != ret.BitLength || bytes.Compare(ret.Bytes, test.out) != 0 { if test.bitLength != ret.BitLength || bytes.Compare(ret.Bytes, test.out) != 0 {
t.Errorf("#%d: Bad result: %v (expected %v %v)", i, ret, test.out, test.bitLength); t.Errorf("#%d: Bad result: %v (expected %v %v)", i, ret, test.out, test.bitLength)
} }
} }
} }
...@@ -76,16 +76,16 @@ func TestBitString(t *testing.T) { ...@@ -76,16 +76,16 @@ func TestBitString(t *testing.T) {
func TestBitStringAt(t *testing.T) { func TestBitStringAt(t *testing.T) {
bs := BitString{[]byte{0x82, 0x40}, 16}; bs := BitString{[]byte{0x82, 0x40}, 16};
if bs.At(0) != 1 { if bs.At(0) != 1 {
t.Error("#1: Failed"); t.Error("#1: Failed")
} }
if bs.At(1) != 0 { if bs.At(1) != 0 {
t.Error("#2: Failed"); t.Error("#2: Failed")
} }
if bs.At(6) != 1 { if bs.At(6) != 1 {
t.Error("#3: Failed"); t.Error("#3: Failed")
} }
if bs.At(9) != 1 { if bs.At(9) != 1 {
t.Error("#4: Failed"); t.Error("#4: Failed")
} }
} }
...@@ -107,11 +107,11 @@ func TestObjectIdentifier(t *testing.T) { ...@@ -107,11 +107,11 @@ func TestObjectIdentifier(t *testing.T) {
for i, test := range objectIdentifierTestData { for i, test := range objectIdentifierTestData {
ret, err := parseObjectIdentifier(test.in); ret, err := parseObjectIdentifier(test.in);
if (err == nil) != test.ok { if (err == nil) != test.ok {
t.Errorf("#%d: Incorrect error result (did fail? %v, expected: %v)", i, err == nil, test.ok); t.Errorf("#%d: Incorrect error result (did fail? %v, expected: %v)", i, err == nil, test.ok)
} }
if err == nil { if err == nil {
if !reflect.DeepEqual(test.out, ret) { if !reflect.DeepEqual(test.out, ret) {
t.Errorf("#%d: Bad result: %v (expected %v)", i, ret, test.out); t.Errorf("#%d: Bad result: %v (expected %v)", i, ret, test.out)
} }
} }
} }
...@@ -142,11 +142,11 @@ func TestTime(t *testing.T) { ...@@ -142,11 +142,11 @@ func TestTime(t *testing.T) {
for i, test := range timeTestData { for i, test := range timeTestData {
ret, err := parseUTCTime(strings.Bytes(test.in)); ret, err := parseUTCTime(strings.Bytes(test.in));
if (err == nil) != test.ok { if (err == nil) != test.ok {
t.Errorf("#%d: Incorrect error result (did fail? %v, expected: %v)", i, err == nil, test.ok); t.Errorf("#%d: Incorrect error result (did fail? %v, expected: %v)", i, err == nil, test.ok)
} }
if err == nil { if err == nil {
if !reflect.DeepEqual(test.out, ret) { if !reflect.DeepEqual(test.out, ret) {
t.Errorf("#%d: Bad result: %v (expected %v)", i, ret, test.out); t.Errorf("#%d: Bad result: %v (expected %v)", i, ret, test.out)
} }
} }
} }
...@@ -177,10 +177,10 @@ func TestParseTagAndLength(t *testing.T) { ...@@ -177,10 +177,10 @@ func TestParseTagAndLength(t *testing.T) {
for i, test := range tagAndLengthData { for i, test := range tagAndLengthData {
tagAndLength, _, err := parseTagAndLength(test.in, 0); tagAndLength, _, err := parseTagAndLength(test.in, 0);
if (err == nil) != test.ok { if (err == nil) != test.ok {
t.Errorf("#%d: Incorrect error result (did pass? %v, expected: %v)", i, err == nil, test.ok); t.Errorf("#%d: Incorrect error result (did pass? %v, expected: %v)", i, err == nil, test.ok)
} }
if err == nil && !reflect.DeepEqual(test.out, tagAndLength) { if err == nil && !reflect.DeepEqual(test.out, tagAndLength) {
t.Errorf("#%d: Bad result: %v (expected %v)", i, tagAndLength, test.out); t.Errorf("#%d: Bad result: %v (expected %v)", i, tagAndLength, test.out)
} }
} }
} }
...@@ -213,7 +213,7 @@ func TestParseFieldParameters(t *testing.T) { ...@@ -213,7 +213,7 @@ func TestParseFieldParameters(t *testing.T) {
for i, test := range parseFieldParametersTestData { for i, test := range parseFieldParametersTestData {
f := parseFieldParameters(test.in); f := parseFieldParameters(test.in);
if !reflect.DeepEqual(f, test.out) { if !reflect.DeepEqual(f, test.out) {
t.Errorf("#%d: Bad result: %v (expected %v)", i, f, test.out); t.Errorf("#%d: Bad result: %v (expected %v)", i, f, test.out)
} }
} }
} }
...@@ -260,10 +260,10 @@ func TestUnmarshal(t *testing.T) { ...@@ -260,10 +260,10 @@ func TestUnmarshal(t *testing.T) {
val := pv.Interface(); val := pv.Interface();
err := Unmarshal(val, test.in); err := Unmarshal(val, test.in);
if err != nil { if err != nil {
t.Errorf("Unmarshal failed at index %d %v", i, err); t.Errorf("Unmarshal failed at index %d %v", i, err)
} }
if !reflect.DeepEqual(val, test.out) { if !reflect.DeepEqual(val, test.out) {
t.Errorf("#%d:\nhave %#v\nwant %#v", i, val, test.out); t.Errorf("#%d:\nhave %#v\nwant %#v", i, val, test.out)
} }
} }
} }
...@@ -310,10 +310,10 @@ func TestCertificate(t *testing.T) { ...@@ -310,10 +310,10 @@ func TestCertificate(t *testing.T) {
// This is a minimal, self-signed certificate that should parse correctly. // This is a minimal, self-signed certificate that should parse correctly.
var cert Certificate; var cert Certificate;
if err := Unmarshal(&cert, derEncodedSelfSignedCertBytes); err != nil { if err := Unmarshal(&cert, derEncodedSelfSignedCertBytes); err != nil {
t.Errorf("Unmarshal failed: %v", err); t.Errorf("Unmarshal failed: %v", err)
} }
if !reflect.DeepEqual(cert, derEncodedSelfSignedCert) { if !reflect.DeepEqual(cert, derEncodedSelfSignedCert) {
t.Errorf("Bad result:\ngot: %+v\nwant: %+v\n", cert, derEncodedSelfSignedCert); t.Errorf("Bad result:\ngot: %+v\nwant: %+v\n", cert, derEncodedSelfSignedCert)
} }
} }
...@@ -323,7 +323,7 @@ func TestCertificateWithNUL(t *testing.T) { ...@@ -323,7 +323,7 @@ func TestCertificateWithNUL(t *testing.T) {
var cert Certificate; var cert Certificate;
if err := Unmarshal(&cert, derEncodedPaypalNULCertBytes); err == nil { if err := Unmarshal(&cert, derEncodedPaypalNULCertBytes); err == nil {
t.Error("Unmarshal succeeded, should not have"); t.Error("Unmarshal succeeded, should not have")
} }
} }
......
...@@ -33,7 +33,7 @@ func addWW_g(x, y, c Word) (z1, z0 Word) { ...@@ -33,7 +33,7 @@ func addWW_g(x, y, c Word) (z1, z0 Word) {
yc := y+c; yc := y+c;
z0 = x+yc; z0 = x+yc;
if z0 < x || yc < y { if z0 < x || yc < y {
z1 = 1; z1 = 1
} }
return; return;
} }
...@@ -44,7 +44,7 @@ func subWW_g(x, y, c Word) (z1, z0 Word) { ...@@ -44,7 +44,7 @@ func subWW_g(x, y, c Word) (z1, z0 Word) {
yc := y+c; yc := y+c;
z0 = x-yc; z0 = x-yc;
if z0 > x || yc < y { if z0 > x || yc < y {
z1 = 1; z1 = 1
} }
return; return;
} }
...@@ -57,7 +57,7 @@ func mulWW_g(x, y Word) (z1, z0 Word) { ...@@ -57,7 +57,7 @@ func mulWW_g(x, y Word) (z1, z0 Word) {
// and return the product as 2 Words. // and return the product as 2 Words.
if x < y { if x < y {
x, y = y, x; x, y = y, x
} }
if x < _B2 { if x < _B2 {
...@@ -100,7 +100,7 @@ func mulWW_g(x, y Word) (z1, z0 Word) { ...@@ -100,7 +100,7 @@ func mulWW_g(x, y Word) (z1, z0 Word) {
t1a := t1; t1a := t1;
t1 += x0*y1; t1 += x0*y1;
if t1 < t1a { if t1 < t1a {
c++; c++
} }
t2 := x1*y1 + c*_B2; t2 := x1*y1 + c*_B2;
...@@ -114,7 +114,7 @@ func mulWW_g(x, y Word) (z1, z0 Word) { ...@@ -114,7 +114,7 @@ func mulWW_g(x, y Word) (z1, z0 Word) {
var c3 Word; var c3 Word;
z1 = t1 + t0>>_W2; z1 = t1 + t0>>_W2;
if z1 < t1 { if z1 < t1 {
c3++; c3++
} }
z1 >>= _W2; z1 >>= _W2;
z1 += c3*_B2; z1 += c3*_B2;
...@@ -149,7 +149,7 @@ func mulAddWWW_g(x, y, c Word) (z1, z0 Word) { ...@@ -149,7 +149,7 @@ func mulAddWWW_g(x, y, c Word) (z1, z0 Word) {
t1a := t1; t1a := t1;
t1 += x0*y1; t1 += x0*y1;
if t1 < t1a { // If the number got smaller then we overflowed. if t1 < t1a { // If the number got smaller then we overflowed.
c2++; c2++
} }
t2 := x1*y1 + c2*_B2; t2 := x1*y1 + c2*_B2;
...@@ -164,7 +164,7 @@ func mulAddWWW_g(x, y, c Word) (z1, z0 Word) { ...@@ -164,7 +164,7 @@ func mulAddWWW_g(x, y, c Word) (z1, z0 Word) {
var c3 Word; var c3 Word;
z1 = t1 + t0>>_W2; z1 = t1 + t0>>_W2;
if z1 < t1 { if z1 < t1 {
c3++; c3++
} }
z1 >>= _W2; z1 >>= _W2;
z1 += t2 + c3*_B2; z1 += t2 + c3*_B2;
...@@ -213,7 +213,7 @@ func divStep(x1, x0, y Word) (q, r Word) { ...@@ -213,7 +213,7 @@ func divStep(x1, x0, y Word) (q, r Word) {
// Number of leading zeros in x. // Number of leading zeros in x.
func leadingZeros(x Word) (n uint) { func leadingZeros(x Word) (n uint) {
if x == 0 { if x == 0 {
return uint(_W); return uint(_W)
} }
for x&(1<<(_W-1)) == 0 { for x&(1<<(_W-1)) == 0 {
n++; n++;
...@@ -259,7 +259,7 @@ func divWW_g(x1, x0, y Word) (q, r Word) { ...@@ -259,7 +259,7 @@ func divWW_g(x1, x0, y Word) (q, r Word) {
r = x0>>z; r = x0>>z;
if q1 != 0 { if q1 != 0 {
panic("div out of range"); panic("div out of range")
} }
return q0, r; return q0, r;
...@@ -315,14 +315,14 @@ func init() { ...@@ -315,14 +315,14 @@ func init() {
func (p *Word) at(i int) *Word { func (p *Word) at(i int) *Word {
return (*Word)(unsafe.Pointer(uintptr(unsafe.Pointer(p)) + uintptr(i)*_S)); return (*Word)(unsafe.Pointer(uintptr(unsafe.Pointer(p)) + uintptr(i)*_S))
} }
func addVV_s(z, x, y *Word, n int) (c Word) func addVV_s(z, x, y *Word, n int) (c Word)
func addVV_g(z, x, y *Word, n int) (c Word) { func addVV_g(z, x, y *Word, n int) (c Word) {
for i := 0; i < n; i++ { for i := 0; i < n; i++ {
c, *z.at(i) = addWW_g(*x.at(i), *y.at(i), c); c, *z.at(i) = addWW_g(*x.at(i), *y.at(i), c)
} }
return; return;
} }
...@@ -331,7 +331,7 @@ func addVV_g(z, x, y *Word, n int) (c Word) { ...@@ -331,7 +331,7 @@ func addVV_g(z, x, y *Word, n int) (c Word) {
func subVV_s(z, x, y *Word, n int) (c Word) func subVV_s(z, x, y *Word, n int) (c Word)
func subVV_g(z, x, y *Word, n int) (c Word) { func subVV_g(z, x, y *Word, n int) (c Word) {
for i := 0; i < n; i++ { for i := 0; i < n; i++ {
c, *z.at(i) = subWW_g(*x.at(i), *y.at(i), c); c, *z.at(i) = subWW_g(*x.at(i), *y.at(i), c)
} }
return; return;
} }
...@@ -341,7 +341,7 @@ func addVW_s(z, x *Word, y Word, n int) (c Word) ...@@ -341,7 +341,7 @@ func addVW_s(z, x *Word, y Word, n int) (c Word)
func addVW_g(z, x *Word, y Word, n int) (c Word) { func addVW_g(z, x *Word, y Word, n int) (c Word) {
c = y; c = y;
for i := 0; i < n; i++ { for i := 0; i < n; i++ {
c, *z.at(i) = addWW_g(*x.at(i), c, 0); c, *z.at(i) = addWW_g(*x.at(i), c, 0)
} }
return; return;
} }
...@@ -351,7 +351,7 @@ func subVW_s(z, x *Word, y Word, n int) (c Word) ...@@ -351,7 +351,7 @@ func subVW_s(z, x *Word, y Word, n int) (c Word)
func subVW_g(z, x *Word, y Word, n int) (c Word) { func subVW_g(z, x *Word, y Word, n int) (c Word) {
c = y; c = y;
for i := 0; i < n; i++ { for i := 0; i < n; i++ {
c, *z.at(i) = subWW_g(*x.at(i), c, 0); c, *z.at(i) = subWW_g(*x.at(i), c, 0)
} }
return; return;
} }
...@@ -361,7 +361,7 @@ func mulAddVWW_s(z, x *Word, y, r Word, n int) (c Word) ...@@ -361,7 +361,7 @@ func mulAddVWW_s(z, x *Word, y, r Word, n int) (c Word)
func mulAddVWW_g(z, x *Word, y, r Word, n int) (c Word) { func mulAddVWW_g(z, x *Word, y, r Word, n int) (c Word) {
c = r; c = r;
for i := 0; i < n; i++ { for i := 0; i < n; i++ {
c, *z.at(i) = mulAddWWW_g(*x.at(i), y, c); c, *z.at(i) = mulAddWWW_g(*x.at(i), y, c)
} }
return; return;
} }
...@@ -382,7 +382,7 @@ func divWVW_s(z *Word, xn Word, x *Word, y Word, n int) (r Word) ...@@ -382,7 +382,7 @@ 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_g(z *Word, xn Word, x *Word, y Word, n int) (r Word) {
r = xn; r = xn;
for i := n-1; i >= 0; i-- { for i := n-1; i >= 0; i-- {
*z.at(i), r = divWW_g(r, *x.at(i), y); *z.at(i), r = divWW_g(r, *x.at(i), y)
} }
return; return;
} }
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
...@@ -25,7 +25,7 @@ func Mul128(x, y uint64) (z1, z0 uint64) { ...@@ -25,7 +25,7 @@ func Mul128(x, y uint64) (z1, z0 uint64) {
) )
if x < y { if x < y {
x, y = y, x; x, y = y, x
} }
if x < B2 { if x < B2 {
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
...@@ -121,7 +121,7 @@ func TestInitDecoder(t *testing.T) { ...@@ -121,7 +121,7 @@ func TestInitDecoder(t *testing.T) {
continue; continue;
} }
if !reflect.DeepEqual(&h, &tt.out) { if !reflect.DeepEqual(&h, &tt.out) {
t.Errorf("test %d:\nhave %v\nwant %v", i, h, tt.out); t.Errorf("test %d:\nhave %v\nwant %v", i, h, tt.out)
} }
} }
} }
...@@ -131,9 +131,9 @@ func TestUncompressedSource(t *testing.T) { ...@@ -131,9 +131,9 @@ func TestUncompressedSource(t *testing.T) {
output := make([]byte, 1); output := make([]byte, 1);
n, error := decoder.Read(output); n, error := decoder.Read(output);
if n != 1 || error != nil { if n != 1 || error != nil {
t.Fatalf("decoder.Read() = %d, %v, want 1, nil", n, error); t.Fatalf("decoder.Read() = %d, %v, want 1, nil", n, error)
} }
if output[0] != 0x11 { if output[0] != 0x11 {
t.Errorf("output[0] = %x, want 0x11", output[0]); t.Errorf("output[0] = %x, want 0x11", output[0])
} }
} }
This diff is collapsed.
This diff is collapsed.
...@@ -40,9 +40,9 @@ var reverseByte = [256]byte{ ...@@ -40,9 +40,9 @@ var reverseByte = [256]byte{
} }
func reverseUint16(v uint16) uint16 { func reverseUint16(v uint16) uint16 {
return uint16(reverseByte[v>>8]) | uint16(reverseByte[v&0xFF])<<8; return uint16(reverseByte[v>>8]) | uint16(reverseByte[v&0xFF])<<8
} }
func reverseBits(number uint16, bitLength byte) uint16 { func reverseBits(number uint16, bitLength byte) uint16 {
return reverseUint16(number<<uint8(16 - bitLength)); return reverseUint16(number<<uint8(16 - bitLength))
} }
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
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