Commit 094f1d59 authored by Russ Cox's avatar Russ Cox

more lgtm files from gofmt

R=gri
OCL=35485
CL=35488
parent 82315483
This diff is collapsed.
......@@ -21,13 +21,13 @@ import (
type ebnfParser struct {
out io.Writer; // parser output
src []byte; // parser source
scanner scanner.Scanner;
prev int; // offset of previous token
pos token.Position; // token position
tok token.Token; // one token look-ahead
lit []byte; // token literal
out io.Writer; // parser output
src []byte; // parser source
scanner scanner.Scanner;
prev int; // offset of previous token
pos token.Position; // token position
tok token.Token; // one token look-ahead
lit []byte; // token literal
}
......@@ -48,7 +48,7 @@ func (p *ebnfParser) next() {
}
func (p *ebnfParser) Error (pos token.Position, msg string) {
func (p *ebnfParser) Error(pos token.Position, msg string) {
fmt.Fprintf(p.out, "<font color=red>error: %s</font>", msg);
}
......@@ -60,7 +60,7 @@ func (p *ebnfParser) errorExpected(pos token.Position, msg string) {
// make the error message more specific
msg += ", found '" + p.tok.String() + "'";
if p.tok.IsLiteral() {
msg += " " + string(p.lit);
msg += " "+string(p.lit);
}
}
p.Error(pos, msg);
......@@ -72,7 +72,7 @@ func (p *ebnfParser) expect(tok token.Token) token.Position {
if p.tok != tok {
p.errorExpected(pos, "'" + tok.String() + "'");
}
p.next(); // make progress in any case
p.next(); // make progress in any case
return pos;
}
......@@ -85,7 +85,7 @@ func (p *ebnfParser) parseIdentifier(def bool) {
} else {
fmt.Fprintf(p.out, `<a href="#%s" style="text-decoration: none;">%s</a>`, name, name);
}
p.prev += len(name); // skip identifier when calling flush
p.prev += len(name); // skip identifier when calling flush
}
......@@ -125,8 +125,7 @@ func (p *ebnfParser) parseTerm() bool {
func (p *ebnfParser) parseSequence() {
for p.parseTerm() {
}
for p.parseTerm() {}
}
......@@ -154,7 +153,7 @@ func (p *ebnfParser) parse(out io.Writer, src []byte) {
p.out = out;
p.src = src;
p.scanner.Init("", src, p, 0);
p.next(); // initializes pos, tok, lit
p.next(); // initializes pos, tok, lit
// process source
for p.tok != token.EOF {
......@@ -166,8 +165,8 @@ func (p *ebnfParser) parse(out io.Writer, src []byte) {
// Markers around EBNF sections
var (
open = strings.Bytes(`<pre class="ebnf">`);
close = strings.Bytes(`</pre>`);
open = strings.Bytes(`<pre class="ebnf">`);
close = strings.Bytes(`</pre>`);
)
......@@ -183,19 +182,19 @@ func linkify(out io.Writer, src []byte) {
i += len(open);
// j: end of EBNF text (or end of source)
j := bytes.Index(src[i : n], close); // close marker
j := bytes.Index(src[i:n], close); // close marker
if j < 0 {
j = n-i;
}
j += i;
// write text before EBNF
out.Write(src[0 : i]);
out.Write(src[0:i]);
// parse and write EBNF
var p ebnfParser;
p.parse(out, src[i : j]);
p.parse(out, src[i:j]);
// advance
src = src[j : n];
src = src[j:n];
}
}
......@@ -121,11 +121,11 @@ func (tr *Reader) readHeader() *Header {
}
// 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 {
return nil;
}
if !bytes.Equal(header, zeroBlock[0:blockSize]) {
if !bytes.Equal(header, zeroBlock[0 : blockSize]) {
tr.err = HeaderError;
}
return nil;
......@@ -198,7 +198,7 @@ func (tr *Reader) readHeader() *Header {
// Maximum value of hdr.Size is 64 GB (12 octal digits),
// so there's no risk of int64 overflowing.
tr.nb = int64(hdr.Size);
tr.pad = -tr.nb & (blockSize-1); // blockSize is a power of two
tr.pad = -tr.nb & (blockSize - 1); // blockSize is a power of two
return hdr;
}
......
......@@ -120,7 +120,7 @@ func (tw *Writer) WriteHeader(hdr *Header) os.Error {
}
tw.nb = int64(hdr.Size);
tw.pad = -tw.nb & (blockSize-1); // blockSize is a power of two
tw.pad = -tw.nb & (blockSize - 1); // blockSize is a power of two
header := make([]byte, blockSize);
s := slicer(header);
......
......@@ -143,7 +143,7 @@ func (e *encoder) Write(p []byte) (n int, err os.Error) {
// Large interior chunks.
for len(p) > 3 {
nn := len(e.out) / 4 * 3;
nn := len(e.out)/4*3;
if nn > len(p) {
nn = len(p);
}
......@@ -286,7 +286,7 @@ func (d *decoder) Read(p []byte) (n int, err os.Error) {
// Use leftover decoded output from last read.
if len(d.out) > 0 {
n = bytes.Copy(p, d.out);
d.out = d.out[n : len(d.out)];
d.out = d.out[n:len(d.out)];
return n, nil;
}
......@@ -311,7 +311,7 @@ func (d *decoder) Read(p []byte) (n int, err os.Error) {
nw, d.end, d.err = d.enc.decode(d.buf[0:nr], &d.outbuf);
d.out = d.outbuf[0:nw];
n = bytes.Copy(p, d.out);
d.out = d.out[n : len(d.out)];
d.out = d.out[n:len(d.out)];
} else {
n, d.end, d.err = d.enc.decode(d.buf[0:nr], p);
}
......
......@@ -104,7 +104,7 @@ func TestDecode(t *testing.T) {
testEqual(t, "Decode(%q) = error %v, want %v", p.encoded, err, os.Error(nil));
testEqual(t, "Decode(%q) = length %v, want %v", p.encoded, count, len(p.decoded));
if len(p.encoded) > 0 {
testEqual(t, "Decode(%q) = end %v, want %v", p.encoded, end, (p.encoded[len(p.encoded) - 1] == '='));
testEqual(t, "Decode(%q) = end %v, want %v", p.encoded, end, (p.encoded[len(p.encoded)-1] == '='));
}
testEqual(t, "Decode(%q) = %q, want %q", p.encoded, string(dbuf[0:count]), p.decoded);
}
......@@ -130,7 +130,7 @@ func TestDecoder(t *testing.T) {
func TestDecoderBuffering(t *testing.T) {
for bs := 1; bs <= 12; bs++ {
decoder := NewDecoder(StdEncoding, bytes.NewBufferString(bigtest.encoded));
buf := make([]byte, len(bigtest.decoded) + 12);
buf := make([]byte, len(bigtest.decoded)+12);
var total int;
for total = 0; total < len(bigtest.decoded); {
n, err := decoder.Read(buf[total : total+bs]);
......
......@@ -18,7 +18,7 @@ func Mul128(x, y uint64) (z1, z0 uint64) {
// and return the product as 2 words.
const (
W = uint(unsafe.Sizeof(x)) * 8;
W = uint(unsafe.Sizeof(x))*8;
W2 = W/2;
B2 = 1<<W2;
M2 = B2-1;
......@@ -80,7 +80,7 @@ func MulAdd128(x, y, c uint64) (z1, z0 uint64) {
// and return the product as 2 words.
const (
W = uint(unsafe.Sizeof(x)) * 8;
W = uint(unsafe.Sizeof(x))*8;
W2 = W/2;
B2 = 1<<W2;
M2 = B2-1;
......
......@@ -899,9 +899,9 @@ func hexvalue(ch byte) uint {
case '0' <= ch && ch <= '9':
d = uint(ch-'0');
case 'a' <= ch && ch <= 'f':
d = uint(ch-'a') + 10;
d = uint(ch-'a')+10;
case 'A' <= ch && ch <= 'F':
d = uint(ch-'A') + 10;
d = uint(ch-'A')+10;
}
return d;
}
......
......@@ -99,7 +99,7 @@ func nrDivEst(x0, y0 Natural) Natural {
// Determine a scale factor f = 2^e such that
// 0.5 <= y/f == y*(2^-e) < 1.0
// and scale y accordingly.
e := int(y.m.Log2()) + 1;
e := int(y.m.Log2())+1;
y.e -= e;
// t1
......@@ -133,7 +133,7 @@ func nrDivEst(x0, y0 Natural) Natural {
// reduce mantissa size
// TODO: Find smaller bound as it will reduce
// computation time massively.
d := int(r.m.Log2() + 1) - maxLen;
d := int(r.m.Log2() + 1)-maxLen;
if d > 0 {
r = fpNat{r.m.Shr(uint(d)), r.e + d};
}
......
This diff is collapsed.
......@@ -38,19 +38,19 @@ type Buffer struct {
// Bytes returns the contents of the unread portion of the buffer;
// len(b.Bytes()) == b.Len().
func (b *Buffer) Bytes() []byte {
return b.buf[b.off : len(b.buf)]
return b.buf[b.off : len(b.buf)];
}
// String returns the contents of the unread portion of the buffer
// as a string.
func (b *Buffer) String() string {
return string(b.buf[b.off : len(b.buf)])
return string(b.buf[b.off : len(b.buf)]);
}
// Len returns the number of bytes of the unread portion of the buffer;
// b.Len() == len(b.Bytes()).
func (b *Buffer) Len() int {
return len(b.buf) - b.off
return len(b.buf) - b.off;
}
// Truncate discards all but the first n unread bytes from the buffer.
......@@ -75,21 +75,21 @@ func (b *Buffer) Write(p []byte) (n int, err os.Error) {
m := b.Len();
n = len(p);
if len(b.buf) + n > cap(b.buf) {
if len(b.buf)+n > cap(b.buf) {
// not enough space at end
buf := b.buf;
if m + n > cap(b.buf) {
if m+n > cap(b.buf) {
// not enough space anywhere
buf = make([]byte, 2*cap(b.buf) + n)
buf = make([]byte, 2*cap(b.buf) + n);
}
copyBytes(buf, 0, b.buf[b.off:b.off+m]);
copyBytes(buf, 0, b.buf[b.off : b.off + m]);
b.buf = buf;
b.off = 0
b.off = 0;
}
b.buf = b.buf[0 : b.off + m + n];
copyBytes(b.buf, b.off + m, p);
return n, nil
return n, nil;
}
// WriteString appends the contents of s to the buffer. The return
......@@ -98,21 +98,21 @@ func (b *Buffer) WriteString(s string) (n int, err os.Error) {
m := b.Len();
n = len(s);
if len(b.buf) + n > cap(b.buf) {
if len(b.buf)+n > cap(b.buf) {
// not enough space at end
buf := b.buf;
if m + n > cap(b.buf) {
if m+n > cap(b.buf) {
// not enough space anywhere
buf = make([]byte, 2*cap(b.buf) + n)
buf = make([]byte, 2*cap(b.buf) + n);
}
copyBytes(buf, 0, b.buf[b.off:b.off+m]);
copyBytes(buf, 0, b.buf[b.off : b.off + m]);
b.buf = buf;
b.off = 0
b.off = 0;
}
b.buf = b.buf[0 : b.off + m + n];
copyString(b.buf, b.off+m, s);
return n, nil
copyString(b.buf, b.off + m, s);
return n, nil;
}
// WriteByte appends the byte c to the buffer.
......@@ -134,19 +134,19 @@ func (b *Buffer) WriteByte(c byte) os.Error {
// otherwise it is nil.
func (b *Buffer) Read(p []byte) (n int, err os.Error) {
if b.off >= len(b.buf) {
return 0, os.EOF
return 0, os.EOF;
}
m := b.Len();
n = len(p);
if n > m {
// more bytes requested than available
n = m
n = m;
}
copyBytes(p, 0, b.buf[b.off:b.off+n]);
copyBytes(p, 0, b.buf[b.off : b.off + n]);
b.off += n;
return n, err
return n, err;
}
// ReadByte reads and returns the next byte from the buffer.
......
......@@ -19,7 +19,7 @@ var bytes []byte // test data; same as data but as a slice.
func init() {
bytes = make([]byte, N);
for i := 0; i < N; i++ {
bytes[i] = 'a' + byte(i%26);
bytes[i] = 'a'+byte(i%26);
}
data = string(bytes);
}
......
......@@ -5,10 +5,10 @@
package bytes_test
import (
. "bytes";
"strings";
"testing";
"unicode";
. "bytes";
"strings";
"testing";
"unicode";
)
func eq(a, b []string) bool {
......@@ -26,9 +26,9 @@ func eq(a, b []string) bool {
func arrayOfString(a [][]byte) []string {
result := make([]string, len(a));
for j := 0; j < len(a); j++ {
result[j] = string(a[j])
result[j] = string(a[j]);
}
return result
return result;
}
// For ease of reading, the test cases use strings that are converted to byte
......@@ -40,21 +40,22 @@ var commas = "1,2,3,4"
var dots = "1....2....3....4"
type CompareTest struct {
a string;
b string;
cmp int;
a string;
b string;
cmp int;
}
var comparetests = []CompareTest {
CompareTest{ "", "", 0 },
CompareTest{ "a", "", 1 },
CompareTest{ "", "a", -1 },
CompareTest{ "abc", "abc", 0 },
CompareTest{ "ab", "abc", -1 },
CompareTest{ "abc", "ab", 1 },
CompareTest{ "x", "ab", 1 },
CompareTest{ "ab", "x", -1 },
CompareTest{ "x", "a", 1 },
CompareTest{ "b", "x", -1 },
var comparetests = []CompareTest{
CompareTest{"", "", 0},
CompareTest{"a", "", 1},
CompareTest{"", "a", -1},
CompareTest{"abc", "abc", 0},
CompareTest{"ab", "abc", -1},
CompareTest{"abc", "ab", 1},
CompareTest{"x", "ab", 1},
CompareTest{"ab", "x", -1},
CompareTest{"x", "a", 1},
CompareTest{"b", "x", -1},
}
func TestCompare(t *testing.T) {
......@@ -67,7 +68,7 @@ func TestCompare(t *testing.T) {
if cmp != tt.cmp {
t.Errorf(`Compare(%q, %q) = %v`, tt.a, tt.b, cmp);
}
if eql != (tt.cmp==0) {
if eql != (tt.cmp == 0) {
t.Errorf(`Equal(%q, %q) = %v`, tt.a, tt.b, eql);
}
}
......@@ -75,17 +76,19 @@ func TestCompare(t *testing.T) {
type ExplodeTest struct {
s string;
n int;
a []string;
s string;
n int;
a []string;
}
var explodetests = []ExplodeTest {
ExplodeTest{ abcd, 0, []string{"a", "b", "c", "d"} },
ExplodeTest{ faces, 0, []string{"☺", "☻", "☹"} },
ExplodeTest{ abcd, 2, []string{"a", "bcd"} },
var explodetests = []ExplodeTest{
ExplodeTest{abcd, 0, []string{"a", "b", "c", "d"}},
ExplodeTest{faces, 0, []string{"☺", "☻", "☹"}},
ExplodeTest{abcd, 2, []string{"a", "bcd"}},
}
func TestExplode(t *testing.T) {
for _, tt := range(explodetests) {
for _, tt := range (explodetests) {
a := Split(strings.Bytes(tt.s), nil, tt.n);
result := arrayOfString(a);
if !eq(result, tt.a) {
......@@ -101,25 +104,26 @@ func TestExplode(t *testing.T) {
type SplitTest struct {
s string;
sep string;
n int;
a []string;
s string;
sep string;
n int;
a []string;
}
var splittests = []SplitTest {
SplitTest{ abcd, "a", 0, []string{"", "bcd"} },
SplitTest{ abcd, "z", 0, []string{"abcd"} },
SplitTest{ abcd, "", 0, []string{"a", "b", "c", "d"} },
SplitTest{ commas, ",", 0, []string{"1", "2", "3", "4"} },
SplitTest{ dots, "...", 0, []string{"1", ".2", ".3", ".4"} },
SplitTest{ faces, "☹", 0, []string{"☺☻", ""} },
SplitTest{ faces, "~", 0, []string{faces} },
SplitTest{ faces, "", 0, []string{"☺", "☻", "☹"} },
SplitTest{ "1 2 3 4", " ", 3, []string{"1", "2", "3 4"} },
SplitTest{ "1 2 3", " ", 3, []string{"1", "2", "3"} },
SplitTest{ "1 2", " ", 3, []string{"1", "2"} },
SplitTest{ "123", "", 2, []string{"1", "23"} },
SplitTest{ "123", "", 17, []string{"1", "2", "3"} },
var splittests = []SplitTest{
SplitTest{abcd, "a", 0, []string{"", "bcd"}},
SplitTest{abcd, "z", 0, []string{"abcd"}},
SplitTest{abcd, "", 0, []string{"a", "b", "c", "d"}},
SplitTest{commas, ",", 0, []string{"1", "2", "3", "4"}},
SplitTest{dots, "...", 0, []string{"1", ".2", ".3", ".4"}},
SplitTest{faces, "☹", 0, []string{"☺☻", ""}},
SplitTest{faces, "~", 0, []string{faces}},
SplitTest{faces, "", 0, []string{"☺", "☻", "☹"}},
SplitTest{"1 2 3 4", " ", 3, []string{"1", "2", "3 4"}},
SplitTest{"1 2 3", " ", 3, []string{"1", "2", "3"}},
SplitTest{"1 2", " ", 3, []string{"1", "2"}},
SplitTest{"123", "", 2, []string{"1", "23"}},
SplitTest{"123", "", 17, []string{"1", "2", "3"}},
}
func TestSplit(t *testing.T) {
......@@ -143,14 +147,15 @@ type CopyTest struct {
n int;
res string;
}
var copytests = []CopyTest {
CopyTest{ "", "", 0, "" },
CopyTest{ "a", "", 0, "a" },
CopyTest{ "a", "a", 1, "a" },
CopyTest{ "a", "b", 1, "b" },
CopyTest{ "xyz", "abc", 3, "abc" },
CopyTest{ "wxyz", "abc", 3, "abcz" },
CopyTest{ "xyz", "abcd", 3, "abc" },
var copytests = []CopyTest{
CopyTest{"", "", 0, ""},
CopyTest{"a", "", 0, "a"},
CopyTest{"a", "a", 1, "a"},
CopyTest{"a", "b", 1, "b"},
CopyTest{"xyz", "abc", 3, "abc"},
CopyTest{"wxyz", "abc", 3, "abcz"},
CopyTest{"xyz", "abcd", 3, "abc"},
}
func TestCopy(t *testing.T) {
......@@ -172,7 +177,7 @@ type StringTest struct {
in, out string;
}
var upperTests = []StringTest {
var upperTests = []StringTest{
StringTest{"", ""},
StringTest{"abc", "ABC"},
StringTest{"AbC123", "ABC123"},
......@@ -180,7 +185,7 @@ var upperTests = []StringTest {
StringTest{"\u0250\u0250\u0250\u0250\u0250", "\u2C6F\u2C6F\u2C6F\u2C6F\u2C6F"}, // grows one byte per char
}
var lowerTests = []StringTest {
var lowerTests = []StringTest{
StringTest{"", ""},
StringTest{"abc", "abc"},
StringTest{"AbC123", "abc123"},
......@@ -190,10 +195,10 @@ var lowerTests = []StringTest {
const space = "\t\v\r\f\n\u0085\u00a0\u2000\u3000"
var trimSpaceTests = []StringTest {
var trimSpaceTests = []StringTest{
StringTest{"", ""},
StringTest{"abc", "abc"},
StringTest{space + "abc" + space, "abc"},
StringTest{space+"abc"+space, "abc"},
StringTest{" ", ""},
StringTest{" \t\r\n \t\t\r\r\n\n ", ""},
StringTest{" \t\r\n x\t\t\r\r\n\n ", "x"},
......@@ -227,23 +232,27 @@ func runStringTests(t *testing.T, f func([]byte) []byte, funcName string, testCa
func tenRunes(rune int) string {
r := make([]int, 10);
for i := range r {
r[i] = rune
r[i] = rune;
}
return string(r)
return string(r);
}
func TestMap(t *testing.T) {
// Run a couple of awful growth/shrinkage tests
a := tenRunes('a');
// 1. Grow. This triggers two reallocations in Map.
maxRune := func(rune int) int { return unicode.MaxRune };
maxRune := func(rune int) int {
return unicode.MaxRune;
};
m := Map(maxRune, Bytes(a));
expect := tenRunes(unicode.MaxRune);
if string(m) != expect {
t.Errorf("growing: expected %q got %q", expect, m);
}
// 2. Shrink
minRune := func(rune int) int { return 'a' };
minRune := func(rune int) int {
return 'a';
};
m = Map(minRune, Bytes(tenRunes(unicode.MaxRune)));
expect = a;
if string(m) != expect {
......@@ -264,24 +273,25 @@ func TestTrimSpace(t *testing.T) {
}
type AddTest struct {
s, t string;
s, t string;
cap int;
}
var addtests = []AddTest {
AddTest{ "", "", 0 },
AddTest{ "a", "", 1 },
AddTest{ "a", "b", 1 },
AddTest{ "abc", "def", 100 },
var addtests = []AddTest{
AddTest{"", "", 0},
AddTest{"a", "", 1},
AddTest{"a", "b", 1},
AddTest{"abc", "def", 100},
}
func TestAdd(t *testing.T) {
for _, test := range addtests {
b := make([]byte, len(test.s), test.cap);
for i := 0; i < len(test.s); i++ {
b[i] = test.s[i]
b[i] = test.s[i];
}
b = Add(b, strings.Bytes(test.t));
if string(b) != test.s+test.t {
if string(b) != test.s + test.t {
t.Errorf("Add(%q,%q) = %q", test.s, test.t, string(b));
}
}
......@@ -291,7 +301,7 @@ func TestAddByte(t *testing.T) {
const N = 2e5;
b := make([]byte, 0);
for i := 0; i < N; i++ {
b = AddByte(b, byte(i))
b = AddByte(b, byte(i));
}
if len(b) != N {
t.Errorf("AddByte: too small; expected %d got %d", N, len(b));
......
This diff is collapsed.
This diff is collapsed.
......@@ -56,8 +56,8 @@ var initDecoderTests = []*InitDecoderTest{
[]int{3, 5, 2, 4, 3, 5, 5, 4, 4, 3, 4, 5},
huffmanDecoder{
2, 5,
[maxCodeLen+1]int{2: 0, 4, 13, 31},
[maxCodeLen+1]int{2: 0, 1, 6, 20},
[maxCodeLen + 1]int{2: 0, 4, 13, 31},
[maxCodeLen + 1]int{2: 0, 1, 6, 20},
// Paper used different code assignment:
// 2, 9, 4, 0, 10, 8, 3, 7, 1, 5, 11, 6
// Reordered here so that codes of same length
......@@ -72,8 +72,8 @@ var initDecoderTests = []*InitDecoderTest{
[]int{2, 1, 3, 3},
huffmanDecoder{
1, 3,
[maxCodeLen+1]int{1: 0, 2, 7},
[maxCodeLen+1]int{1: 0, 1, 4},
[maxCodeLen + 1]int{1: 0, 2, 7},
[maxCodeLen + 1]int{1: 0, 1, 4},
[]int{1, 0, 2, 3},
},
true,
......@@ -84,8 +84,8 @@ var initDecoderTests = []*InitDecoderTest{
[]int{3, 3, 3, 3, 3, 2, 4, 4},
huffmanDecoder{
2, 4,
[maxCodeLen+1]int{2: 0, 6, 15},
[maxCodeLen+1]int{2: 0, 1, 8},
[maxCodeLen + 1]int{2: 0, 6, 15},
[maxCodeLen + 1]int{2: 0, 1, 8},
[]int{5, 0, 1, 2, 3, 4, 6, 7},
},
true,
......
......@@ -13,48 +13,47 @@ import (
const (
// The largest offset code.
offsetCodeCount = 30;
offsetCodeCount = 30;
// The largest offset code in the extensions.
extendedOffsetCodeCount = 42;
extendedOffsetCodeCount = 42;
// The special code used to mark the end of a block.
endBlockMarker = 256;
endBlockMarker = 256;
// The first length code.
lengthCodesStart = 257;
lengthCodesStart = 257;
// The number of codegen codes.
codegenCodeCount = 19;
badCode = 255;
codegenCodeCount = 19;
badCode = 255;
)
// The number of extra bits needed by length code X - LENGTH_CODES_START.
var lengthExtraBits = []int8 {
/* 257 */ 0, 0, 0,
/* 260 */ 0, 0, 0, 0, 0, 1, 1, 1, 1, 2,
/* 270 */ 2, 2, 2, 3, 3, 3, 3, 4, 4, 4,
/* 280 */ 4, 5, 5, 5, 5, 0,
var lengthExtraBits = []int8{
/* 257 */0, 0, 0,
/* 260 */0, 0, 0, 0, 0, 1, 1, 1, 1, 2,
/* 270 */2, 2, 2, 3, 3, 3, 3, 4, 4, 4,
/* 280 */4, 5, 5, 5, 5, 0,
}
// The length indicated by length code X - LENGTH_CODES_START.
var lengthBase = []uint32 {
0, 1, 2, 3, 4, 5, 6, 7, 8, 10,
12, 14, 16, 20, 24, 28, 32, 40, 48, 56,
64, 80, 96, 112, 128, 160, 192, 224, 255
var lengthBase = []uint32{
0, 1, 2, 3, 4, 5, 6, 7, 8, 10,
12, 14, 16, 20, 24, 28, 32, 40, 48, 56,
64, 80, 96, 112, 128, 160, 192, 224, 255,
}
// offset code word extra bits.
var offsetExtraBits = []int8 {
0, 0, 0, 0, 1, 1, 2, 2, 3, 3,
4, 4, 5, 5, 6, 6, 7, 7, 8, 8,
9, 9, 10, 10, 11, 11, 12, 12, 13, 13,
var offsetExtraBits = []int8{
0, 0, 0, 0, 1, 1, 2, 2, 3, 3,
4, 4, 5, 5, 6, 6, 7, 7, 8, 8,
9, 9, 10, 10, 11, 11, 12, 12, 13, 13,
/* extended window */
14, 14, 15, 15, 16, 16, 17, 17, 18, 18, 19, 19, 20, 20,
}
var offsetBase = []uint32 {
var offsetBase = []uint32{
/* normal deflate */
0x000000, 0x000001, 0x000002, 0x000003, 0x000004,
0x000006, 0x000008, 0x00000c, 0x000010, 0x000018,
......@@ -66,37 +65,35 @@ var offsetBase = []uint32 {
/* extended window */
0x008000, 0x00c000, 0x010000, 0x018000, 0x020000,
0x030000, 0x040000, 0x060000, 0x080000, 0x0c0000,
0x100000, 0x180000, 0x200000, 0x300000
0x100000, 0x180000, 0x200000, 0x300000,
}
// The odd order in which the codegen code sizes are written.
var codegenOrder = []uint32 {
16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15
}
var codegenOrder = []uint32{16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15}
type huffmanBitWriter struct {
w io.Writer;
w io.Writer;
// Data waiting to be written is bytes[0:nbytes]
// and then the low nbits of bits.
bits uint32;
nbits uint32;
bytes [64]byte;
nbytes int;
literalFreq []int32;
offsetFreq []int32;
codegen []uint8;
codegenFreq []int32;
literalEncoding *huffmanEncoder;
offsetEncoding *huffmanEncoder;
codegenEncoding *huffmanEncoder;
err os.Error;
bits uint32;
nbits uint32;
bytes [64]byte;
nbytes int;
literalFreq []int32;
offsetFreq []int32;
codegen []uint8;
codegenFreq []int32;
literalEncoding *huffmanEncoder;
offsetEncoding *huffmanEncoder;
codegenEncoding *huffmanEncoder;
err os.Error;
}
type WrongValueError struct {
name string;
from int32;
to int32;
value int32;
name string;
from int32;
to int32;
value int32;
}
func newHuffmanBitWriter(w io.Writer) *huffmanBitWriter {
......@@ -175,7 +172,7 @@ func (w *huffmanBitWriter) writeBytes(bytes []byte) {
n++;
}
if w.nbits != 0 {
w.err = InternalError("writeBytes with unfinished bits");
w.err = InternalError("writeBytes with unfinished bits");
return;
}
if n != 0 {
......@@ -205,7 +202,7 @@ func (w *huffmanBitWriter) generateCodegen(numLiterals int, numOffsets int) {
// a copy of the frequencies, and as the place where we put the result.
// This is fine because the output is always shorter than the input used
// so far.
codegen := w.codegen; // cache
codegen := w.codegen; // cache
// Copy the concatenated code sizes to codegen. Put a marker at the end.
copyUint8s(codegen[0 : numLiterals], w.literalEncoding.codeBits);
copyUint8s(codegen[numLiterals : numLiterals + numOffsets], w.offsetEncoding.codeBits);
......@@ -232,7 +229,7 @@ func (w *huffmanBitWriter) generateCodegen(numLiterals int, numOffsets int) {
n := min(count, 6);
codegen[outIndex] = 16;
outIndex++;
codegen[outIndex] = uint8(n - 3);
codegen[outIndex] = uint8(n-3);
outIndex++;
w.codegenFreq[16]++;
count -= n;
......@@ -242,7 +239,7 @@ func (w *huffmanBitWriter) generateCodegen(numLiterals int, numOffsets int) {
n := min(count, 138);
codegen[outIndex] = 18;
outIndex++;
codegen[outIndex] = uint8(n - 11);
codegen[outIndex] = uint8(n-11);
outIndex++;
w.codegenFreq[18]++;
count -= n;
......@@ -251,7 +248,7 @@ func (w *huffmanBitWriter) generateCodegen(numLiterals int, numOffsets int) {
// count >= 3 && count <= 10
codegen[outIndex] = 17;
outIndex++;
codegen[outIndex] = uint8(count - 3);
codegen[outIndex] = uint8(count-3);
outIndex++;
w.codegenFreq[17]++;
count = 0;
......@@ -295,8 +292,8 @@ func (w *huffmanBitWriter) writeDynamicHeader(numLiterals int, numOffsets int, n
w.writeBits(int32(numLiterals - 257), 5);
if numOffsets > offsetCodeCount {
// Extended version of deflater
w.writeBits(int32(offsetCodeCount + ((numOffsets - (1 + offsetCodeCount)) >> 3)), 5);
w.writeBits(int32((numOffsets - (1 + offsetCodeCount)) & 0x7), 3);
w.writeBits(int32(offsetCodeCount + ((numOffsets - (1 + offsetCodeCount))>>3)), 5);
w.writeBits(int32((numOffsets - (1 + offsetCodeCount))&0x7), 3);
} else {
w.writeBits(int32(numOffsets - 1), 5);
}
......@@ -368,10 +365,10 @@ func (w *huffmanBitWriter) writeBlock(tokens []token, eof bool, input []byte) {
fillInt32s(w.offsetFreq, 0);
n := len(tokens);
tokens = tokens[0:n+1];
tokens = tokens[0 : n+1];
tokens[n] = endBlockMarker;
totalLength := -1; // Subtract 1 for endBlock.
totalLength := -1; // Subtract 1 for endBlock.
for _, t := range tokens {
switch t.typ() {
case literalType:
......@@ -381,7 +378,7 @@ func (w *huffmanBitWriter) writeBlock(tokens []token, eof bool, input []byte) {
case matchType:
length := t.length();
offset := t.offset();
totalLength += int(length + 3);
totalLength += int(length+3);
w.literalFreq[lengthCodesStart + lengthCode(length)]++;
w.offsetFreq[offsetCode(offset)]++;
break;
......@@ -407,18 +404,18 @@ func (w *huffmanBitWriter) writeBlock(tokens []token, eof bool, input []byte) {
var extraBits int64;
var storedSize int64;
if storedBytes <= maxStoreBlockSize && input != nil {
storedSize = int64((storedBytes + 5) * 8);
storedSize = int64((storedBytes + 5)*8);
// We only bother calculating the costs of the extra bits required by
// the length of offset fields (which will be the same for both fixed
// and dynamic encoding), if we need to compare those two encodings
// against stored encoding.
for lengthCode := lengthCodesStart + 8; lengthCode < numLiterals; lengthCode++ {
// First eight length codes have extra size = 0.
extraBits += int64(w.literalFreq[lengthCode]) * int64(lengthExtraBits[lengthCode - lengthCodesStart]);
extraBits += int64(w.literalFreq[lengthCode])*int64(lengthExtraBits[lengthCode - lengthCodesStart]);
}
for offsetCode := 4; offsetCode < numOffsets; offsetCode++ {
// First four offset codes have extra size = 0.
extraBits += int64(w.offsetFreq[offsetCode]) * int64(offsetExtraBits[offsetCode]);
extraBits += int64(w.offsetFreq[offsetCode])*int64(offsetExtraBits[offsetCode]);
}
} else {
storedSize = math.MaxInt32;
......@@ -445,7 +442,7 @@ func (w *huffmanBitWriter) writeBlock(tokens []token, eof bool, input []byte) {
if numOffsets > offsetCodeCount {
extensionSummand = 3;
}
dynamicHeader := int64(3 + 5 + 5 + 4 + (3 * numCodegens)) +
dynamicHeader := int64(3+5+5+4+(3 * numCodegens)) +
// Following line is an extension.
int64(extensionSummand) +
w.codegenEncoding.bitLength(w.codegenFreq) +
......@@ -459,7 +456,7 @@ func (w *huffmanBitWriter) writeBlock(tokens []token, eof bool, input []byte) {
if storedSize < fixedSize && storedSize < dynamicSize {
w.writeStoredHeader(storedBytes, eof);
w.writeBytes(input[0:storedBytes]);
w.writeBytes(input[0 : storedBytes]);
return;
}
var literalEncoding *huffmanEncoder;
......@@ -507,4 +504,3 @@ func (w *huffmanBitWriter) writeBlock(tokens []token, eof bool, input []byte) {
}
}
}
......@@ -66,10 +66,10 @@ type huffmanDecoder struct {
// limit[i] = largest code word of length i
// Given code v of length n,
// need more bits if v > limit[n].
limit [maxCodeLen+1]int;
limit [maxCodeLen + 1]int;
// base[i] = smallest code word of length i - seq number
base [maxCodeLen+1]int;
base [maxCodeLen + 1]int;
// codes[seq number] = output code.
// Given code v of length n, value is
......@@ -83,7 +83,7 @@ func (h *huffmanDecoder) init(bits []int) bool {
// Count number of codes of each length,
// compute min and max length.
var count [maxCodeLen+1]int;
var count [maxCodeLen + 1]int;
var min, max int;
for _, n := range bits {
if n == 0 {
......@@ -142,8 +142,8 @@ func (h *huffmanDecoder) init(bits []int) bool {
// See RFC 1951, section 3.2.6.
var fixedHuffmanDecoder = huffmanDecoder{
7, 9,
[maxCodeLen+1]int{7: 23, 199, 511},
[maxCodeLen+1]int{7: 0, 24, 224},
[maxCodeLen + 1]int{7: 23, 199, 511},
[maxCodeLen + 1]int{7: 0, 24, 224},
[]int{
// length 7: 256-279
256, 257, 258, 259, 260, 261, 262,
......@@ -271,11 +271,11 @@ func (f *inflater) readHuffman() os.Error {
return err;
}
}
nlit := int(f.b & 0x1F) + 257;
nlit := int(f.b & 0x1F)+257;
f.b >>= 5;
ndist := int(f.b & 0x1F) + 1;
ndist := int(f.b & 0x1F)+1;
f.b >>= 5;
nclen := int(f.b & 0xF) + 4;
nclen := int(f.b & 0xF)+4;
f.b >>= 4;
f.nb -= 5+5+4;
......@@ -437,7 +437,7 @@ func (f *inflater) decodeBlock(hl, hd *huffmanDecoder) os.Error {
case dist >= 30:
return CorruptInputError(f.roffset);
default:
nb := uint(dist-2) >> 1;
nb := uint(dist-2)>>1;
// have 1 bit in bottom of dist, need nb more.
extra := (dist&1)<<nb;
for f.nb < nb {
......@@ -495,8 +495,8 @@ func (f *inflater) dataBlock() os.Error {
if err != nil {
return &ReadError{f.roffset, err};
}
n := int(f.buf[0]) | int(f.buf[1]) << 8;
nn := int(f.buf[2]) | int(f.buf[3]) << 8;
n := int(f.buf[0]) | int(f.buf[1])<<8;
nn := int(f.buf[2]) | int(f.buf[3])<<8;
if uint16(nn) != uint16(^n) {
return CorruptInputError(f.roffset);
}
......
......@@ -44,5 +44,5 @@ func reverseUint16(v uint16) uint16 {
}
func reverseBits(number uint16, bitLength byte) uint16 {
return reverseUint16(number << uint8(16-bitLength));
return reverseUint16(number<<uint8(16 - bitLength));
}
......@@ -9,7 +9,7 @@ const (
// 8 bits: xlength = length - MIN_MATCH_LENGTH
// 22 bits xoffset = offset - MIN_OFFSET_SIZE, or literal
lengthShift = 22;
offsetMask = 1<<lengthShift - 1;
offsetMask = 1 << lengthShift - 1;
typeMask = 3<<30;
literalType = 0<<30;
matchType = 1<<30;
......@@ -69,12 +69,12 @@ type token uint32
// Convert a literal into a literal token.
func literalToken(literal uint32) token {
return token(literalType+literal);
return token(literalType + literal);
}
// Convert a < xlength, xoffset > pair into a match token.
func matchToken(xlength uint32, xoffset uint32) token {
return token(matchType + xlength<<lengthShift + xoffset);
return token(matchType + xlength << lengthShift + xoffset);
}
// Returns the type of a token
......@@ -84,16 +84,16 @@ func (t token) typ() uint32 {
// Returns the literal of a literal token
func (t token) literal() uint32 {
return uint32(t-literalType);
return uint32(t - literalType);
}
// Returns the extra offset of a match token
func (t token) offset() uint32 {
return uint32(t)&offsetMask;
return uint32(t) & offsetMask;
}
func (t token) length() uint32 {
return uint32((t-matchType)>>lengthShift);
return uint32((t - matchType) >> lengthShift);
}
func lengthCode(len uint32) uint32 {
......@@ -107,9 +107,9 @@ func offsetCode(off uint32) uint32 {
case off < n:
return offsetCodes[off];
case off>>7 < n:
return offsetCodes[off>>7]+14;
return offsetCodes[off>>7] + 14;
default:
return offsetCodes[off>>14]+28;
return offsetCodes[off>>14] + 28;
}
panic("unreachable");
}
......@@ -110,7 +110,7 @@ func (z *Inflater) read2() (uint32, os.Error) {
if err != nil {
return 0, err;
}
return uint32(z.buf[0]) | uint32(z.buf[1]) << 8, nil;
return uint32(z.buf[0]) | uint32(z.buf[1])<<8, nil;
}
func (z *Inflater) readHeader(save bool) os.Error {
......
......@@ -12,31 +12,31 @@ import (
)
type gzipTest struct {
name string;
desc string;
raw string;
gzip []byte;
err os.Error;
name string;
desc string;
raw string;
gzip []byte;
err os.Error;
}
var gzipTests = []gzipTest {
gzipTest { // has 1 empty fixed-huffman block
var gzipTests = []gzipTest{
gzipTest{ // has 1 empty fixed-huffman block
"empty.txt",
"empty.txt",
"",
[]byte {
[]byte{
0x1f, 0x8b, 0x08, 0x08, 0xf7, 0x5e, 0x14, 0x4a,
0x00, 0x03, 0x65, 0x6d, 0x70, 0x74, 0x79, 0x2e,
0x74, 0x78, 0x74, 0x00, 0x03, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
},
nil
nil,
},
gzipTest { // has 1 non-empty fixed huffman block
gzipTest{ // has 1 non-empty fixed huffman block
"hello.txt",
"hello.txt",
"hello world\n",
[]byte {
[]byte{
0x1f, 0x8b, 0x08, 0x08, 0xc8, 0x58, 0x13, 0x4a,
0x00, 0x03, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x2e,
0x74, 0x78, 0x74, 0x00, 0xcb, 0x48, 0xcd, 0xc9,
......@@ -44,14 +44,14 @@ var gzipTests = []gzipTest {
0x02, 0x00, 0x2d, 0x3b, 0x08, 0xaf, 0x0c, 0x00,
0x00, 0x00,
},
nil
nil,
},
gzipTest { // concatenation
gzipTest{ // concatenation
"hello.txt",
"hello.txt x2",
"hello world\n"
"hello world\n",
[]byte {
[]byte{
0x1f, 0x8b, 0x08, 0x08, 0xc8, 0x58, 0x13, 0x4a,
0x00, 0x03, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x2e,
0x74, 0x78, 0x74, 0x00, 0xcb, 0x48, 0xcd, 0xc9,
......@@ -65,13 +65,13 @@ var gzipTests = []gzipTest {
0x02, 0x00, 0x2d, 0x3b, 0x08, 0xaf, 0x0c, 0x00,
0x00, 0x00,
},
nil
nil,
},
gzipTest { // has a fixed huffman block with some length-distance pairs
gzipTest{ // has a fixed huffman block with some length-distance pairs
"shesells.txt",
"shesells.txt",
"she sells seashells by the seashore\n",
[]byte {
[]byte{
0x1f, 0x8b, 0x08, 0x08, 0x72, 0x66, 0x8b, 0x4a,
0x00, 0x03, 0x73, 0x68, 0x65, 0x73, 0x65, 0x6c,
0x6c, 0x73, 0x2e, 0x74, 0x78, 0x74, 0x00, 0x2b,
......@@ -81,9 +81,9 @@ var gzipTests = []gzipTest {
0x94, 0xca, 0x05, 0x00, 0x76, 0xb0, 0x3b, 0xeb,
0x24, 0x00, 0x00, 0x00,
},
nil
nil,
},
gzipTest { // has dynamic huffman blocks
gzipTest{ // has dynamic huffman blocks
"gettysburg",
"gettysburg",
" Four score and seven years ago our fathers brought forth on\n"
......@@ -115,7 +115,7 @@ var gzipTests = []gzipTest {
"people, for the people, shall not perish from this earth.\n"
"\n"
"Abraham Lincoln, November 19, 1863, Gettysburg, Pennsylvania\n",
[]byte {
[]byte{
0x1f, 0x8b, 0x08, 0x08, 0xd1, 0x12, 0x2b, 0x4a,
0x00, 0x03, 0x67, 0x65, 0x74, 0x74, 0x79, 0x73,
0x62, 0x75, 0x72, 0x67, 0x00, 0x65, 0x54, 0xcd,
......@@ -219,13 +219,13 @@ var gzipTests = []gzipTest {
0x4a, 0x65, 0x8f, 0x08, 0x42, 0x60, 0xf7, 0x0f,
0xb9, 0x16, 0x0b, 0x0c, 0x1a, 0x06, 0x00, 0x00,
},
nil
nil,
},
gzipTest { // has 1 non-empty fixed huffman block then garbage
gzipTest{ // has 1 non-empty fixed huffman block then garbage
"hello.txt",
"hello.txt + garbage",
"hello world\n",
[]byte {
[]byte{
0x1f, 0x8b, 0x08, 0x08, 0xc8, 0x58, 0x13, 0x4a,
0x00, 0x03, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x2e,
0x74, 0x78, 0x74, 0x00, 0xcb, 0x48, 0xcd, 0xc9,
......@@ -235,11 +235,11 @@ var gzipTests = []gzipTest {
},
HeaderError,
},
gzipTest { // has 1 non-empty fixed huffman block not enough header
gzipTest{ // has 1 non-empty fixed huffman block not enough header
"hello.txt",
"hello.txt + garbage",
"hello world\n",
[]byte {
[]byte{
0x1f, 0x8b, 0x08, 0x08, 0xc8, 0x58, 0x13, 0x4a,
0x00, 0x03, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x2e,
0x74, 0x78, 0x74, 0x00, 0xcb, 0x48, 0xcd, 0xc9,
......@@ -249,11 +249,11 @@ var gzipTests = []gzipTest {
},
io.ErrUnexpectedEOF,
},
gzipTest { // has 1 non-empty fixed huffman block but corrupt checksum
gzipTest{ // has 1 non-empty fixed huffman block but corrupt checksum
"hello.txt",
"hello.txt + corrupt checksum",
"hello world\n",
[]byte {
[]byte{
0x1f, 0x8b, 0x08, 0x08, 0xc8, 0x58, 0x13, 0x4a,
0x00, 0x03, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x2e,
0x74, 0x78, 0x74, 0x00, 0xcb, 0x48, 0xcd, 0xc9,
......@@ -263,11 +263,11 @@ var gzipTests = []gzipTest {
},
ChecksumError,
},
gzipTest { // has 1 non-empty fixed huffman block but corrupt size
gzipTest{ // has 1 non-empty fixed huffman block but corrupt size
"hello.txt",
"hello.txt + corrupt size",
"hello world\n",
[]byte {
[]byte{
0x1f, 0x8b, 0x08, 0x08, 0xc8, 0x58, 0x13, 0x4a,
0x00, 0x03, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x2e,
0x74, 0x78, 0x74, 0x00, 0xcb, 0x48, 0xcd, 0xc9,
......@@ -303,4 +303,3 @@ func TestInflater(t *testing.T) {
}
}
}
......@@ -43,7 +43,7 @@ func NewInflater(r io.Reader) (io.ReadCloser, os.Error) {
if err != nil {
return nil, err;
}
h := uint(z.scratch[0]) << 8 | uint(z.scratch[1]);
h := uint(z.scratch[0])<<8 | uint(z.scratch[1]);
if (z.scratch[0] & 0x0f != zlibDeflate) || (h%31 != 0) {
return nil, HeaderError;
}
......@@ -77,7 +77,7 @@ func (z *reader) Read(p []byte) (n int, err os.Error) {
return 0, err;
}
// ZLIB (RFC 1950) is big-endian, unlike GZIP (RFC 1952).
checksum := uint32(z.scratch[0]) << 24 | uint32(z.scratch[1]) << 16 | uint32(z.scratch[2]) << 8 | uint32(z.scratch[3]);
checksum := uint32(z.scratch[0])<<24 | uint32(z.scratch[1])<<16 | uint32(z.scratch[2])<<8 | uint32(z.scratch[3]);
if checksum != z.digest.Sum32() {
z.err = ChecksumError;
return 0, z.err;
......
......@@ -73,7 +73,7 @@ func (p *Vector) Init(initial_len int) *Vector {
}
}
p.a = a[0:initial_len];
p.a = a[0 : initial_len];
return p;
}
......@@ -108,7 +108,7 @@ func (p *Vector) Set(i int, x Element) {
// Last returns the element in the vector of highest index.
func (p *Vector) Last() Element {
return p.a[len(p.a) - 1];
return p.a[len(p.a)-1];
}
......@@ -146,7 +146,7 @@ func (p *Vector) Delete(i int) {
// x such that the 0th element of x appears at index i after insertion.
func (p *Vector) InsertVector(i int, x *Vector) {
p.a = expand(p.a, i, len(x.a));
copy(p.a[i : i + len(x.a)], x.a);
copy(p.a[i : i+len(x.a)], x.a);
}
......@@ -193,7 +193,7 @@ func (p *Vector) Push(x Element) {
// Pop deletes the last element of the vector.
func (p *Vector) Pop() Element {
i := len(p.a) - 1;
i := len(p.a)-1;
x := p.a[i];
p.a[i] = nil; // support GC, nil out entry
p.a = p.a[0:i];
......
......@@ -278,7 +278,7 @@ var encryptTests = []CryptTest{
// Test encryptBlock against FIPS 197 examples.
func TestEncryptBlock(t *testing.T) {
for i, tt := range encryptTests {
n := len(tt.key) + 28;
n := len(tt.key)+28;
enc := make([]uint32, n);
dec := make([]uint32, n);
expandKey(tt.key, enc, dec);
......@@ -296,7 +296,7 @@ func TestEncryptBlock(t *testing.T) {
// Test decryptBlock against FIPS 197 examples.
func TestDecryptBlock(t *testing.T) {
for i, tt := range encryptTests {
n := len(tt.key) + 28;
n := len(tt.key)+28;
enc := make([]uint32, n);
dec := make([]uint32, n);
expandKey(tt.key, enc, dec);
......
......@@ -56,19 +56,19 @@ func encryptBlock(xk []uint32, src, dst []byte) {
nr := len(xk)/4 - 2; // - 2: one above, one more below
k := 4;
for r := 0; r < nr; r++ {
t0 = xk[k+0] ^ te[0][s0>>24] ^ te[1][s1>>16 & 0xff] ^ te[2][s2>>8 & 0xff] ^ te[3][s3 & 0xff];
t1 = xk[k+1] ^ te[0][s1>>24] ^ te[1][s2>>16 & 0xff] ^ te[2][s3>>8 & 0xff] ^ te[3][s0 & 0xff];
t2 = xk[k+2] ^ te[0][s2>>24] ^ te[1][s3>>16 & 0xff] ^ te[2][s0>>8 & 0xff] ^ te[3][s1 & 0xff];
t3 = xk[k+3] ^ te[0][s3>>24] ^ te[1][s0>>16 & 0xff] ^ te[2][s1>>8 & 0xff] ^ te[3][s2 & 0xff];
t0 = xk[k+0]^te[0][s0>>24]^te[1][s1>>16&0xff]^te[2][s2>>8&0xff]^te[3][s3&0xff];
t1 = xk[k+1]^te[0][s1>>24]^te[1][s2>>16&0xff]^te[2][s3>>8&0xff]^te[3][s0&0xff];
t2 = xk[k+2]^te[0][s2>>24]^te[1][s3>>16&0xff]^te[2][s0>>8&0xff]^te[3][s1&0xff];
t3 = xk[k+3]^te[0][s3>>24]^te[1][s0>>16&0xff]^te[2][s1>>8&0xff]^te[3][s2&0xff];
k += 4;
s0, s1, s2, s3 = t0, t1, t2, t3;
}
// Last round uses s-box directly and XORs to produce output.
s0 = uint32(sbox0[t0>>24])<<24 | uint32(sbox0[t1>>16 & 0xff])<<16 | uint32(sbox0[t2>>8 & 0xff])<<8 | uint32(sbox0[t3 & 0xff]);
s1 = uint32(sbox0[t1>>24])<<24 | uint32(sbox0[t2>>16 & 0xff])<<16 | uint32(sbox0[t3>>8 & 0xff])<<8 | uint32(sbox0[t0 & 0xff]);
s2 = uint32(sbox0[t2>>24])<<24 | uint32(sbox0[t3>>16 & 0xff])<<16 | uint32(sbox0[t0>>8 & 0xff])<<8 | uint32(sbox0[t1 & 0xff]);
s3 = uint32(sbox0[t3>>24])<<24 | uint32(sbox0[t0>>16 & 0xff])<<16 | uint32(sbox0[t1>>8 & 0xff])<<8 | uint32(sbox0[t2 & 0xff]);
s0 = uint32(sbox0[t0>>24])<<24 | uint32(sbox0[t1>>16&0xff])<<16 | uint32(sbox0[t2>>8&0xff])<<8 | uint32(sbox0[t3&0xff]);
s1 = uint32(sbox0[t1>>24])<<24 | uint32(sbox0[t2>>16&0xff])<<16 | uint32(sbox0[t3>>8&0xff])<<8 | uint32(sbox0[t0&0xff]);
s2 = uint32(sbox0[t2>>24])<<24 | uint32(sbox0[t3>>16&0xff])<<16 | uint32(sbox0[t0>>8&0xff])<<8 | uint32(sbox0[t1&0xff]);
s3 = uint32(sbox0[t3>>24])<<24 | uint32(sbox0[t0>>16&0xff])<<16 | uint32(sbox0[t1>>8&0xff])<<8 | uint32(sbox0[t2&0xff]);
s0 ^= xk[k+0];
s1 ^= xk[k+1];
......@@ -101,19 +101,19 @@ func decryptBlock(xk []uint32, src, dst []byte) {
nr := len(xk)/4 - 2; // - 2: one above, one more below
k := 4;
for r := 0; r < nr; r++ {
t0 = xk[k+0] ^ td[0][s0>>24] ^ td[1][s3>>16 & 0xff] ^ td[2][s2>>8 & 0xff] ^ td[3][s1 & 0xff];
t1 = xk[k+1] ^ td[0][s1>>24] ^ td[1][s0>>16 & 0xff] ^ td[2][s3>>8 & 0xff] ^ td[3][s2 & 0xff];
t2 = xk[k+2] ^ td[0][s2>>24] ^ td[1][s1>>16 & 0xff] ^ td[2][s0>>8 & 0xff] ^ td[3][s3 & 0xff];
t3 = xk[k+3] ^ td[0][s3>>24] ^ td[1][s2>>16 & 0xff] ^ td[2][s1>>8 & 0xff] ^ td[3][s0 & 0xff];
t0 = xk[k+0]^td[0][s0>>24]^td[1][s3>>16&0xff]^td[2][s2>>8&0xff]^td[3][s1&0xff];
t1 = xk[k+1]^td[0][s1>>24]^td[1][s0>>16&0xff]^td[2][s3>>8&0xff]^td[3][s2&0xff];
t2 = xk[k+2]^td[0][s2>>24]^td[1][s1>>16&0xff]^td[2][s0>>8&0xff]^td[3][s3&0xff];
t3 = xk[k+3]^td[0][s3>>24]^td[1][s2>>16&0xff]^td[2][s1>>8&0xff]^td[3][s0&0xff];
k += 4;
s0, s1, s2, s3 = t0, t1, t2, t3;
}
// Last round uses s-box directly and XORs to produce output.
s0 = uint32(sbox1[t0>>24])<<24 | uint32(sbox1[t3>>16 & 0xff])<<16 | uint32(sbox1[t2>>8 & 0xff])<<8 | uint32(sbox1[t1 & 0xff]);
s1 = uint32(sbox1[t1>>24])<<24 | uint32(sbox1[t0>>16 & 0xff])<<16 | uint32(sbox1[t3>>8 & 0xff])<<8 | uint32(sbox1[t2 & 0xff]);
s2 = uint32(sbox1[t2>>24])<<24 | uint32(sbox1[t1>>16 & 0xff])<<16 | uint32(sbox1[t0>>8 & 0xff])<<8 | uint32(sbox1[t3 & 0xff]);
s3 = uint32(sbox1[t3>>24])<<24 | uint32(sbox1[t2>>16 & 0xff])<<16 | uint32(sbox1[t1>>8 & 0xff])<<8 | uint32(sbox1[t0 & 0xff]);
s0 = uint32(sbox1[t0>>24])<<24 | uint32(sbox1[t3>>16&0xff])<<16 | uint32(sbox1[t2>>8&0xff])<<8 | uint32(sbox1[t1&0xff]);
s1 = uint32(sbox1[t1>>24])<<24 | uint32(sbox1[t0>>16&0xff])<<16 | uint32(sbox1[t3>>8&0xff])<<8 | uint32(sbox1[t2&0xff]);
s2 = uint32(sbox1[t2>>24])<<24 | uint32(sbox1[t1>>16&0xff])<<16 | uint32(sbox1[t0>>8&0xff])<<8 | uint32(sbox1[t3&0xff]);
s3 = uint32(sbox1[t3>>24])<<24 | uint32(sbox1[t2>>16&0xff])<<16 | uint32(sbox1[t1>>8&0xff])<<8 | uint32(sbox1[t0&0xff]);
s0 ^= xk[k+0];
s1 ^= xk[k+1];
......@@ -128,11 +128,10 @@ func decryptBlock(xk []uint32, src, dst []byte) {
// Apply sbox0 to each byte in w.
func subw(w uint32) uint32 {
return
uint32(sbox0[w>>24])<<24 |
uint32(sbox0[w>>16 & 0xff])<<16 |
uint32(sbox0[w>>8 & 0xff])<<8 |
uint32(sbox0[w & 0xff]);
return uint32(sbox0[w>>24])<<24 |
uint32(sbox0[w>>16&0xff])<<16 |
uint32(sbox0[w>>8&0xff])<<8 |
uint32(sbox0[w&0xff]);
}
// Rotate
......@@ -145,18 +144,18 @@ func rotw(w uint32) uint32 {
func expandKey(key []byte, enc, dec []uint32) {
// Encryption key setup.
var i int;
nk := len(key) / 4;
nk := len(key)/4;
for i = 0; i < nk; i++ {
enc[i] = uint32(key[4*i])<<24 | uint32(key[4*i+1])<<16 | uint32(key[4*i+2])<<8 | uint32(key[4*i+3]);
enc[i] = uint32(key[4*i])<<24 | uint32(key[4*i + 1])<<16 | uint32(key[4*i + 2])<<8 | uint32(key[4*i + 3]);
}
for ; i < len(enc); i++ {
t := enc[i-1];
if i % nk == 0 {
t = subw(rotw(t)) ^ (uint32(powx[i/nk - 1]) << 24);
} else if nk > 6 && i % nk == 4 {
if i%nk == 0 {
t = subw(rotw(t))^(uint32(powx[i/nk - 1])<<24);
} else if nk > 6 && i%nk == 4 {
t = subw(t);
}
enc[i] = enc[i-nk] ^ t;
enc[i] = enc[i-nk]^t;
}
// Derive decryption key from encryption key.
......@@ -167,14 +166,13 @@ func expandKey(key []byte, enc, dec []uint32) {
}
n := len(enc);
for i := 0; i < n; i += 4 {
ei := n - i - 4;
ei := n-i-4;
for j := 0; j < 4; j++ {
x := enc[ei+j];
if i > 0 && i+4 < n {
x = td[0][sbox0[x>>24]] ^ td[1][sbox0[x>>16 & 0xff]] ^ td[2][sbox0[x>>8 & 0xff]] ^ td[3][sbox0[x & 0xff]];
x = td[0][sbox0[x>>24]]^td[1][sbox0[x>>16&0xff]]^td[2][sbox0[x>>8&0xff]]^td[3][sbox0[x&0xff]];
}
dec[i+j] = x;
}
}
}
......@@ -35,7 +35,7 @@ func (x *ctrStream) Next() []byte {
x.c.Encrypt(x.ctr, x.out);
// Increment counter
for i := len(x.ctr) - 1; i >= 0; i-- {
for i := len(x.ctr)-1; i >= 0; i-- {
x.ctr[i]++;
if x.ctr[i] != 0 {
break;
......
......@@ -79,7 +79,7 @@ func TestCTR_AES(t *testing.T) {
for j := 0; j <= 5; j += 5 {
var crypt bytes.Buffer;
in := tt.in[0 : len(tt.in) - j];
in := tt.in[0 : len(tt.in)-j];
w := NewCTRWriter(c, tt.iv, &crypt);
var r io.Reader = bytes.NewBuffer(in);
n, err := io.Copy(r, w);
......@@ -92,7 +92,7 @@ func TestCTR_AES(t *testing.T) {
for j := 0; j <= 7; j += 7 {
var plain bytes.Buffer;
out := tt.out[0 : len(tt.out) - j];
out := tt.out[0 : len(tt.out)-j];
r := NewCTRReader(c, tt.iv, bytes.NewBuffer(out));
w := &plain;
n, err := io.Copy(r, w);
......
......@@ -66,7 +66,7 @@ func (x *ecbDecrypter) readPlain(p []byte) int {
p[i] = x.plain[i];
}
if n < len(x.plain) {
x.plain = x.plain[n : len(x.plain)];
x.plain = x.plain[n:len(x.plain)];
} else {
x.plain = nil;
}
......@@ -172,7 +172,7 @@ func (x *ecbEncrypter) flushCrypt() os.Error {
}
n, err := x.w.Write(x.crypt);
if n < len(x.crypt) {
x.crypt = x.crypt[n : len(x.crypt)];
x.crypt = x.crypt[n:len(x.crypt)];
if err == nil {
err = io.ErrShortWrite;
}
......@@ -196,7 +196,7 @@ func (x *ecbEncrypter) slidePlain() {
for i := 0; i < len(x.plain); i++ {
x.buf[i] = x.plain[i];
}
x.plain = x.buf[0 : len(x.plain)];
x.plain = x.buf[0:len(x.plain)];
}
}
......@@ -205,7 +205,7 @@ func (x *ecbEncrypter) slidePlain() {
func (x *ecbEncrypter) fillPlain(p []byte) int {
off := len(x.plain);
n := len(p);
if max := cap(x.plain) - off; n > max {
if max := cap(x.plain)-off; n > max {
n = max;
}
x.plain = x.plain[0 : off+n];
......
......@@ -77,7 +77,7 @@ func TestOFB_AES(t *testing.T) {
for j := 0; j <= 5; j += 5 {
var crypt bytes.Buffer;
in := tt.in[0 : len(tt.in) - j];
in := tt.in[0 : len(tt.in)-j];
w := NewOFBWriter(c, tt.iv, &crypt);
var r io.Reader = bytes.NewBuffer(in);
n, err := io.Copy(r, w);
......@@ -90,7 +90,7 @@ func TestOFB_AES(t *testing.T) {
for j := 0; j <= 7; j += 7 {
var plain bytes.Buffer;
out := tt.out[0 : len(tt.out) - j];
out := tt.out[0 : len(tt.out)-j];
r := NewOFBReader(c, tt.iv, bytes.NewBuffer(out));
w := &plain;
n, err := io.Copy(r, w);
......
......@@ -55,7 +55,7 @@ func (p *parser) errorExpected(pos token.Position, msg string) {
// make the error message more specific
msg += ", found '" + p.tok.String() + "'";
if p.tok.IsLiteral() {
msg += " " + string(p.lit);
msg += " "+string(p.lit);
}
}
p.Error(pos, msg);
......@@ -347,7 +347,7 @@ func remap(p *parser, name string) string {
packageName, suffix := name[0:i], name[i:len(name)];
// lookup package
if importPath, found := p.packs[packageName]; found {
name = importPath+suffix;
name = importPath + suffix;
} else {
var invalidPos token.Position;
p.Error(invalidPos, "package not declared: " + packageName);
......
......@@ -141,8 +141,8 @@ func sizeof(t reflect.Type) int {
}
type decoder struct {
order ByteOrder;
buf []byte;
order ByteOrder;
buf []byte;
}
func (d *decoder) uint8() uint8 {
......
......@@ -33,7 +33,7 @@ func (b *buf) uint8() uint8 {
return 0;
}
val := b.data[0];
b.data = b.data[1 : len(b.data)];
b.data = b.data[1:len(b.data)];
b.off++;
return val;
}
......@@ -44,7 +44,7 @@ func (b *buf) bytes(n int) []byte {
return nil;
}
data := b.data[0:n];
b.data = b.data[n : len(b.data)];
b.data = b.data[n:len(b.data)];
b.off += Offset(n);
return data;
}
......@@ -95,7 +95,7 @@ func (b *buf) uint64() uint64 {
func (b *buf) varint() (c uint64, bits uint) {
for i := 0; i < len(b.data); i++ {
byte := b.data[i];
c |= uint64(byte&0x7F) << bits;
c |= uint64(byte&0x7F)<<bits;
bits += 7;
if byte&0x80 == 0 {
b.off += Offset(i+1);
......
......@@ -190,15 +190,15 @@ func (b *buf) entry(atab abbrevTable, ubase Offset) *Entry {
case formRefAddr:
val = Offset(b.addr());
case formRef1:
val = Offset(b.uint8()) + ubase;
val = Offset(b.uint8())+ubase;
case formRef2:
val = Offset(b.uint16()) + ubase;
val = Offset(b.uint16())+ubase;
case formRef4:
val = Offset(b.uint32()) + ubase;
val = Offset(b.uint32())+ubase;
case formRef8:
val = Offset(b.uint64()) + ubase;
val = Offset(b.uint64())+ubase;
case formRefUdata:
val = Offset(b.uint()) + ubase;
val = Offset(b.uint())+ubase;
// string
case formString:
......
......@@ -20,7 +20,7 @@ var nameTests = []nameTest{
nameTest{EM_860, "EM_860"},
nameTest{SHN_LOPROC, "SHN_LOPROC"},
nameTest{SHT_PROGBITS, "SHT_PROGBITS"},
nameTest{SHF_MERGE+SHF_TLS, "SHF_MERGE+SHF_TLS"},
nameTest{SHF_MERGE + SHF_TLS, "SHF_MERGE+SHF_TLS"},
nameTest{PT_LOAD, "PT_LOAD"},
nameTest{PF_W+PF_R+0x50, "PF_W+PF_R+0x50"},
nameTest{DT_SYMBOLIC, "DT_SYMBOLIC"},
......
......@@ -298,7 +298,7 @@ func NewFile(r io.ReaderAt) (*File, os.Error) {
var ok bool;
s.Name, ok = getString(shstrtab, int(names[i]));
if !ok {
return nil, &FormatError{shoff + int64(i*shentsize), "bad section name index", names[i]};
return nil, &FormatError{shoff+int64(i * shentsize), "bad section name index", names[i]};
}
}
......
......@@ -32,14 +32,14 @@ var fileTests = []fileTest{
SectionHeader{".text", SHT_PROGBITS, SHF_ALLOC + SHF_EXECINSTR, 0x80483cc, 0x3cc, 0x180, 0x0, 0x0, 0x4, 0x0},
SectionHeader{".fini", SHT_PROGBITS, SHF_ALLOC + SHF_EXECINSTR, 0x804854c, 0x54c, 0xc, 0x0, 0x0, 0x4, 0x0},
SectionHeader{".rodata", SHT_PROGBITS, SHF_ALLOC, 0x8048558, 0x558, 0xa3, 0x0, 0x0, 0x1, 0x0},
SectionHeader{".data", SHT_PROGBITS, SHF_WRITE+SHF_ALLOC, 0x80495fc, 0x5fc, 0xc, 0x0, 0x0, 0x4, 0x0},
SectionHeader{".data", SHT_PROGBITS, SHF_WRITE + SHF_ALLOC, 0x80495fc, 0x5fc, 0xc, 0x0, 0x0, 0x4, 0x0},
SectionHeader{".eh_frame", SHT_PROGBITS, SHF_ALLOC, 0x8049608, 0x608, 0x4, 0x0, 0x0, 0x4, 0x0},
SectionHeader{".dynamic", SHT_DYNAMIC, SHF_WRITE+SHF_ALLOC, 0x804960c, 0x60c, 0x98, 0x4, 0x0, 0x4, 0x8},
SectionHeader{".ctors", SHT_PROGBITS, SHF_WRITE+SHF_ALLOC, 0x80496a4, 0x6a4, 0x8, 0x0, 0x0, 0x4, 0x0},
SectionHeader{".dtors", SHT_PROGBITS, SHF_WRITE+SHF_ALLOC, 0x80496ac, 0x6ac, 0x8, 0x0, 0x0, 0x4, 0x0},
SectionHeader{".jcr", SHT_PROGBITS, SHF_WRITE+SHF_ALLOC, 0x80496b4, 0x6b4, 0x4, 0x0, 0x0, 0x4, 0x0},
SectionHeader{".got", SHT_PROGBITS, SHF_WRITE+SHF_ALLOC, 0x80496b8, 0x6b8, 0x1c, 0x0, 0x0, 0x4, 0x4},
SectionHeader{".bss", SHT_NOBITS, SHF_WRITE+SHF_ALLOC, 0x80496d4, 0x6d4, 0x20, 0x0, 0x0, 0x4, 0x0},
SectionHeader{".dynamic", SHT_DYNAMIC, SHF_WRITE + SHF_ALLOC, 0x804960c, 0x60c, 0x98, 0x4, 0x0, 0x4, 0x8},
SectionHeader{".ctors", SHT_PROGBITS, SHF_WRITE + SHF_ALLOC, 0x80496a4, 0x6a4, 0x8, 0x0, 0x0, 0x4, 0x0},
SectionHeader{".dtors", SHT_PROGBITS, SHF_WRITE + SHF_ALLOC, 0x80496ac, 0x6ac, 0x8, 0x0, 0x0, 0x4, 0x0},
SectionHeader{".jcr", SHT_PROGBITS, SHF_WRITE + SHF_ALLOC, 0x80496b4, 0x6b4, 0x4, 0x0, 0x0, 0x4, 0x0},
SectionHeader{".got", SHT_PROGBITS, SHF_WRITE + SHF_ALLOC, 0x80496b8, 0x6b8, 0x1c, 0x0, 0x0, 0x4, 0x4},
SectionHeader{".bss", SHT_NOBITS, SHF_WRITE + SHF_ALLOC, 0x80496d4, 0x6d4, 0x20, 0x0, 0x0, 0x4, 0x0},
SectionHeader{".comment", SHT_PROGBITS, 0x0, 0x0, 0x6d4, 0x12d, 0x0, 0x0, 0x1, 0x0},
SectionHeader{".debug_aranges", SHT_PROGBITS, 0x0, 0x0, 0x801, 0x20, 0x0, 0x0, 0x1, 0x0},
SectionHeader{".debug_pubnames", SHT_PROGBITS, 0x0, 0x0, 0x821, 0x1b, 0x0, 0x0, 0x1, 0x0},
......@@ -75,21 +75,21 @@ var fileTests = []fileTest{
SectionHeader{".rodata", SHT_PROGBITS, SHF_ALLOC, 0x4005a4, 0x5a4, 0x11, 0x0, 0x0, 0x4, 0x0},
SectionHeader{".eh_frame_hdr", SHT_PROGBITS, SHF_ALLOC, 0x4005b8, 0x5b8, 0x24, 0x0, 0x0, 0x4, 0x0},
SectionHeader{".eh_frame", SHT_PROGBITS, SHF_ALLOC, 0x4005e0, 0x5e0, 0xa4, 0x0, 0x0, 0x8, 0x0},
SectionHeader{".ctors", SHT_PROGBITS, SHF_WRITE+SHF_ALLOC, 0x600688, 0x688, 0x10, 0x0, 0x0, 0x8, 0x0},
SectionHeader{".dtors", SHT_PROGBITS, SHF_WRITE+SHF_ALLOC, 0x600698, 0x698, 0x10, 0x0, 0x0, 0x8, 0x0},
SectionHeader{".jcr", SHT_PROGBITS, SHF_WRITE+SHF_ALLOC, 0x6006a8, 0x6a8, 0x8, 0x0, 0x0, 0x8, 0x0},
SectionHeader{".dynamic", SHT_DYNAMIC, SHF_WRITE+SHF_ALLOC, 0x6006b0, 0x6b0, 0x1a0, 0x6, 0x0, 0x8, 0x10},
SectionHeader{".got", SHT_PROGBITS, SHF_WRITE+SHF_ALLOC, 0x600850, 0x850, 0x8, 0x0, 0x0, 0x8, 0x8},
SectionHeader{".got.plt", SHT_PROGBITS, SHF_WRITE+SHF_ALLOC, 0x600858, 0x858, 0x28, 0x0, 0x0, 0x8, 0x8},
SectionHeader{".data", SHT_PROGBITS, SHF_WRITE+SHF_ALLOC, 0x600880, 0x880, 0x18, 0x0, 0x0, 0x8, 0x0},
SectionHeader{".bss", SHT_NOBITS, SHF_WRITE+SHF_ALLOC, 0x600898, 0x898, 0x8, 0x0, 0x0, 0x4, 0x0},
SectionHeader{".ctors", SHT_PROGBITS, SHF_WRITE + SHF_ALLOC, 0x600688, 0x688, 0x10, 0x0, 0x0, 0x8, 0x0},
SectionHeader{".dtors", SHT_PROGBITS, SHF_WRITE + SHF_ALLOC, 0x600698, 0x698, 0x10, 0x0, 0x0, 0x8, 0x0},
SectionHeader{".jcr", SHT_PROGBITS, SHF_WRITE + SHF_ALLOC, 0x6006a8, 0x6a8, 0x8, 0x0, 0x0, 0x8, 0x0},
SectionHeader{".dynamic", SHT_DYNAMIC, SHF_WRITE + SHF_ALLOC, 0x6006b0, 0x6b0, 0x1a0, 0x6, 0x0, 0x8, 0x10},
SectionHeader{".got", SHT_PROGBITS, SHF_WRITE + SHF_ALLOC, 0x600850, 0x850, 0x8, 0x0, 0x0, 0x8, 0x8},
SectionHeader{".got.plt", SHT_PROGBITS, SHF_WRITE + SHF_ALLOC, 0x600858, 0x858, 0x28, 0x0, 0x0, 0x8, 0x8},
SectionHeader{".data", SHT_PROGBITS, SHF_WRITE + SHF_ALLOC, 0x600880, 0x880, 0x18, 0x0, 0x0, 0x8, 0x0},
SectionHeader{".bss", SHT_NOBITS, SHF_WRITE + SHF_ALLOC, 0x600898, 0x898, 0x8, 0x0, 0x0, 0x4, 0x0},
SectionHeader{".comment", SHT_PROGBITS, 0x0, 0x0, 0x898, 0x126, 0x0, 0x0, 0x1, 0x0},
SectionHeader{".debug_aranges", SHT_PROGBITS, 0x0, 0x0, 0x9c0, 0x90, 0x0, 0x0, 0x10, 0x0},
SectionHeader{".debug_pubnames", SHT_PROGBITS, 0x0, 0x0, 0xa50, 0x25, 0x0, 0x0, 0x1, 0x0},
SectionHeader{".debug_info", SHT_PROGBITS, 0x0, 0x0, 0xa75, 0x1a7, 0x0, 0x0, 0x1, 0x0},
SectionHeader{".debug_abbrev", SHT_PROGBITS, 0x0, 0x0, 0xc1c, 0x6f, 0x0, 0x0, 0x1, 0x0},
SectionHeader{".debug_line", SHT_PROGBITS, 0x0, 0x0, 0xc8b, 0x13f, 0x0, 0x0, 0x1, 0x0},
SectionHeader{".debug_str", SHT_PROGBITS, SHF_MERGE+SHF_STRINGS, 0x0, 0xdca, 0xb1, 0x0, 0x0, 0x1, 0x1},
SectionHeader{".debug_str", SHT_PROGBITS, SHF_MERGE + SHF_STRINGS, 0x0, 0xdca, 0xb1, 0x0, 0x0, 0x1, 0x1},
SectionHeader{".debug_ranges", SHT_PROGBITS, 0x0, 0x0, 0xe80, 0x90, 0x0, 0x0, 0x10, 0x0},
SectionHeader{".shstrtab", SHT_STRTAB, 0x0, 0x0, 0xf10, 0x149, 0x0, 0x0, 0x1, 0x0},
SectionHeader{".symtab", SHT_SYMTAB, 0x0, 0x0, 0x19a0, 0x6f0, 0x24, 0x39, 0x8, 0x18},
......
......@@ -46,7 +46,7 @@ func (t *LineTable) parse(targetPC uint64, targetLine int) (b []byte, pc uint64,
case code <= 128:
line -= int(code-64);
default:
pc += quantum * uint64(code-128);
pc += quantum*uint64(code-128);
continue;
}
pc += quantum;
......
......@@ -515,7 +515,7 @@ func (ev *debugEvent) doTrap() (threadState, os.Error) {
return stopped, err;
}
b, ok := t.proc.breakpoints[uintptr(regs.PC()) - uintptr(len(bpinst386))];
b, ok := t.proc.breakpoints[uintptr(regs.PC())-uintptr(len(bpinst386))];
if !ok {
// We must have hit a breakpoint that was actually in
// the program. Leave the IP where it is so we don't
......@@ -1218,7 +1218,7 @@ func (p *process) attachAllThreads() os.Error {
if err != nil {
// There could have been a race, or
// this process could be a zobmie.
statFile, err2 := io.ReadFile(taskPath + "/" + tidStr + "/stat");
statFile, err2 := io.ReadFile(taskPath+"/"+tidStr+"/stat");
if err2 != nil {
switch err2 := err2.(type) {
case *os.PathError:
......
......@@ -15,10 +15,10 @@ import (
type parser struct {
scanner.ErrorVector;
scanner scanner.Scanner;
pos token.Position; // token position
tok token.Token; // one token look-ahead
lit []byte; // token literal
scanner scanner.Scanner;
pos token.Position; // token position
tok token.Token; // one token look-ahead
lit []byte; // token literal
}
......@@ -39,7 +39,7 @@ func (p *parser) errorExpected(pos token.Position, msg string) {
// make the error message more specific
msg += ", found '" + p.tok.String() + "'";
if p.tok.IsLiteral() {
msg += " " + string(p.lit);
msg += " "+string(p.lit);
}
}
p.Error(pos, msg);
......@@ -51,7 +51,7 @@ func (p *parser) expect(tok token.Token) token.Position {
if p.tok != tok {
p.errorExpected(pos, "'" + tok.String() + "'");
}
p.next(); // make progress in any case
p.next(); // make progress in any case
return pos;
}
......@@ -185,7 +185,7 @@ func (p *parser) parse(filename string, src []byte) Grammar {
// initialize parser
p.ErrorVector.Init();
p.scanner.Init(filename, src, p, 0);
p.next(); // initializes pos, tok, lit
p.next(); // initializes pos, tok, lit
grammar := make(Grammar);
for p.tok != token.EOF {
......
......@@ -396,7 +396,7 @@ func (f *allFlags) parseOne(index int) (ok bool, next int) {
return false, index+1;
}
}
name := s[num_minuses:len(s)];
name := s[num_minuses : len(s)];
if len(name) == 0 || name[0] == '-' || name[0] == '=' {
fmt.Fprintln(os.Stderr, "bad flag syntax:", s);
Usage();
......@@ -439,7 +439,7 @@ func (f *allFlags) parseOne(index int) (ok bool, next int) {
}
} else {
// It must have a value, which might be the next argument.
if !has_value && index < len(os.Args) - 1 {
if !has_value && index < len(os.Args)-1 {
// value is the next arg
has_value = true;
index++;
......
......@@ -164,7 +164,7 @@ func (p *pp) ensure(n int) {
if len(p.buf) < n {
newn := allocSize + len(p.buf);
if newn < n {
newn = n+allocSize;
newn = n + allocSize;
}
b := make([]byte, newn);
for i := 0; i < p.n; i++ {
......
......@@ -203,7 +203,7 @@ func MergePackageFiles(pkg *Package) *File {
ndecls := 0;
for _, f := range pkg.Files {
if f.Doc != nil {
ncomments += len(f.Doc.List) + 1; // +1 for separator
ncomments += len(f.Doc.List)+1; // +1 for separator
}
ndecls += len(f.Decls);
}
......@@ -215,7 +215,7 @@ func MergePackageFiles(pkg *Package) *File {
// than drop them on the floor.
var doc *CommentGroup;
if ncomments > 0 {
list := make([]*Comment, ncomments-1); // -1: no separator before first group
list := make([]*Comment, ncomments - 1); // -1: no separator before first group
i := 0;
for _, f := range pkg.Files {
if f.Doc != nil {
......
This diff is collapsed.
......@@ -23,7 +23,7 @@ type encoderState struct {
b *bytes.Buffer;
err os.Error; // error encountered during encoding;
fieldnum int; // the last field number written.
buf [1+uint64Size]byte; // buffer used by the encoder; here to avoid allocation.
buf [1 + uint64Size]byte; // buffer used by the encoder; here to avoid allocation.
}
// Unsigned integers have a two-state encoding. If the number is less
......@@ -49,7 +49,7 @@ func encodeUint(state *encoderState, x uint64) {
m--;
}
state.buf[m] = uint8(-(n-1));
n, state.err = state.b.Write(state.buf[m : uint64Size+1]);
n, state.err = state.b.Write(state.buf[m : uint64Size + 1]);
}
// encodeInt writes an encoded signed integer to state.w.
......@@ -58,7 +58,7 @@ func encodeUint(state *encoderState, x uint64) {
func encodeInt(state *encoderState, i int64) {
var x uint64;
if i < 0 {
x = uint64(^i << 1) | 1;
x = uint64(^i << 1)|1;
} else {
x = uint64(i<<1);
}
......
......@@ -49,7 +49,7 @@ func (r *Response) AddHeader(key, value string) {
oldValues, oldValuesPresent := r.Header[key];
if oldValuesPresent {
r.Header[key] = oldValues+","+value;
r.Header[key] = oldValues + "," + value;
} else {
r.Header[key] = value;
}
......
This diff is collapsed.
......@@ -146,7 +146,7 @@ func (c *Conn) WriteHeader(code int) {
if !ok {
text = "status code " + codestring;
}
io.WriteString(c.buf, proto+" "+codestring+" "+text+"\r\n");
io.WriteString(c.buf, proto + " " + codestring + " " + text + "\r\n");
for k, v := range c.header {
io.WriteString(c.buf, k+": "+v+"\r\n");
}
......
......@@ -203,7 +203,7 @@ func (d *decoder) idatReader(idat io.Reader) os.Error {
case ctPaletted:
bpp = 1;
paletted = d.image.(*image.Paletted);
maxPalette = uint8(len(paletted.Palette) - 1);
maxPalette = uint8(len(paletted.Palette)-1);
case ctTrueColorAlpha:
bpp = 4;
nrgba = d.image.(*image.NRGBA);
......
......@@ -54,7 +54,7 @@ func (p *pipe) Read(data []byte) (n int, err os.Error) {
data[i] = p.wpend[i];
}
p.wtot += n;
p.wpend = p.wpend[n : len(p.wpend)];
p.wpend = p.wpend[n:len(p.wpend)];
// If write block is done, finish the write.
if len(p.wpend) == 0 {
......
......@@ -75,7 +75,7 @@ func itoa(i int, wid int) string {
for ; u > 0 || wid > 0; u /= 10 {
bp--;
wid--;
b[bp] = byte(u%10) + '0';
b[bp] = byte(u%10)+'0';
}
return string(b[bp:len(b)]);
......@@ -91,12 +91,12 @@ func (l *Logger) formatHeader(ns int64, calldepth int) string {
if l.flag & (Ltime | Lmicroseconds) != 0 {
h += itoa(t.Hour, 2) + ":" + itoa(t.Minute, 2) + ":" + itoa(t.Second, 2);
if l.flag & Lmicroseconds != 0 {
h += "." + itoa(int(ns%1e9) / 1e3, 6);
h += "." + itoa(int(ns%1e9)/1e3, 6);
}
h += " ";
}
}
if l.flag & (Lshortfile|Llongfile) != 0 {
if l.flag & (Lshortfile | Llongfile) != 0 {
_, file, line, ok := runtime.Caller(calldepth);
if ok {
if l.flag & Lshortfile != 0 {
......@@ -131,7 +131,7 @@ func (l *Logger) Output(calldepth int, s string) {
if len(s) > 0 && s[len(s)-1] == '\n' {
newline = "";
}
s = l.formatHeader(now, calldepth+1) + s + newline;
s = l.formatHeader(now, calldepth + 1) + s + newline;
io.WriteString(l.out0, s);
if l.out1 != nil {
io.WriteString(l.out1, s);
......
......@@ -36,9 +36,9 @@ var tests = []tester{
tester{Lok|Ltime, "", Rtime+" "},
tester{Lok | Ltime | Lmicroseconds, "", Rtime + Rmicroseconds + " "},
tester{Lok | Lmicroseconds, "", Rtime + Rmicroseconds + " "}, // microsec implies time
tester{Lok|Llongfile, "", Rlongfile+" "},
tester{Lok|Lshortfile, "", Rshortfile+" "},
tester{Lok|Llongfile|Lshortfile, "", Rshortfile+" "}, // shortfile overrides longfile
tester{Lok | Llongfile, "", Rlongfile + " "},
tester{Lok | Lshortfile, "", Rshortfile + " "},
tester{Lok | Llongfile | Lshortfile, "", Rshortfile + " "}, // shortfile overrides longfile
// everything at once:
tester{Lok | Ldate | Ltime | Lmicroseconds | Llongfile, "XXX", "XXX" + Rdate + " " + Rtime + Rmicroseconds + " " + Rlongfile + " "},
tester{Lok | Ldate | Ltime | Lmicroseconds | Lshortfile, "XXX", "XXX" + Rdate + " " + Rtime + Rmicroseconds + " " + Rshortfile + " "},
......
......@@ -18,13 +18,13 @@ var pow10tab [70]float64
// Pow10 returns 10**x, the base-10 exponential of x.
func Pow10(e int) float64 {
if e < 0 {
return 1 / Pow10(-e);
return 1/Pow10(-e);
}
if e < len(pow10tab) {
return pow10tab[e];
}
m := e/2;
return Pow10(m) * Pow10(e-m);
return Pow10(m)*Pow10(e-m);
}
func init() {
......
......@@ -42,7 +42,7 @@ func Sinh(x float64) float64 {
temp = Exp(x)/2;
case x > 0.5:
temp = (Exp(x) - Exp(-x))/2;
temp = (Exp(x)-Exp(-x))/2;
default:
sq := x*x;
......@@ -64,5 +64,5 @@ func Cosh(x float64) float64 {
if x > 21 {
return Exp(x)/2;
}
return (Exp(x) + Exp(-x))/2;
return (Exp(x)+Exp(-x))/2;
}
......@@ -43,18 +43,18 @@ func Sqrt(x float64) float64 {
temp := 0.5*(1+y);
for exp > 60 {
temp = temp * float64(1<<30);
temp = temp*float64(1<<30);
exp = exp-60;
}
for exp < -60 {
temp = temp / float64(1<<30);
temp = temp/float64(1<<30);
exp = exp+60;
}
if exp >= 0 {
exp = 1 << uint(exp/2);
exp = 1<<uint(exp/2);
temp = temp*float64(exp);
} else {
exp = 1 << uint(-exp / 2);
exp = 1<<uint(-exp / 2);
temp = temp/float64(exp);
}
......
......@@ -111,7 +111,7 @@ func itod(i int) string {
bp := len(b);
for ; u > 0; u /= 10 {
bp--;
b[bp] = byte(u%10) + '0';
b[bp] = byte(u%10)+'0';
}
if i < 0 {
......
......@@ -25,7 +25,7 @@ func TestMkdirAll(t *testing.T) {
}
// Make file.
fpath := path + "/file";
fpath := path+"/file";
_, err = Open(fpath, O_WRONLY|O_CREAT, 0666);
if err != nil {
t.Fatalf("create %q: %s", fpath, err);
......@@ -64,7 +64,7 @@ func TestMkdirAll(t *testing.T) {
func TestRemoveAll(t *testing.T) {
// Work directory.
path := "_obj/_TestRemoveAll_";
fpath := path + "/file";
fpath := path+"/file";
dpath := path+"/dir";
// Make directory with 1 file and remove.
......@@ -92,7 +92,7 @@ func TestRemoveAll(t *testing.T) {
t.Fatalf("create %q: %s", fpath, err);
}
fd.Close();
fd, err = Open(dpath + "/file", O_WRONLY|O_CREAT, 0666);
fd, err = Open(dpath+"/file", O_WRONLY|O_CREAT, 0666);
if err != nil {
t.Fatalf("create %q: %s", fpath, err);
}
......@@ -109,7 +109,7 @@ func TestRemoveAll(t *testing.T) {
t.Fatalf("MkdirAll %q: %s", dpath, err);
}
for _, s := range []string{fpath, dpath + "/file1", path+"/zzz"} {
for _, s := range []string{fpath, dpath+"/file1", path+"/zzz"} {
fd, err = Open(s, O_WRONLY|O_CREAT, 0666);
if err != nil {
t.Fatalf("create %q: %s", s, err);
......
......@@ -27,9 +27,9 @@ func dirFromStat(name string, dir *Dir, lstat, stat *syscall.Stat_t) *Dir {
dir.Size = uint64(stat.Size);
dir.Blksize = uint64(stat.Blksize);
dir.Blocks = uint64(stat.Blocks);
dir.Atime_ns = uint64(stat.Atime) * 1e9;
dir.Mtime_ns = uint64(stat.Mtime) * 1e9;
dir.Ctime_ns = uint64(stat.Ctime) * 1e9;
dir.Atime_ns = uint64(stat.Atime)*1e9;
dir.Mtime_ns = uint64(stat.Mtime)*1e9;
dir.Ctime_ns = uint64(stat.Ctime)*1e9;
for i := len(name)-1; i >= 0; i-- {
if name[i] == '/' {
name = name[i+1 : len(name)];
......
......@@ -16,5 +16,5 @@ func Time() (sec int64, nsec int64, err Error) {
if errno := syscall.Gettimeofday(&tv); errno != 0 {
return 0, 0, NewSyscallError("gettimeofday", errno);
}
return int64(tv.Sec), int64(tv.Usec) * 1000, err;
return int64(tv.Sec), int64(tv.Usec)*1000, err;
}
......@@ -27,7 +27,7 @@ import "strings"
// http://plan9.bell-labs.com/sys/doc/lexnames.html
func Clean(path string) string {
if path == "" {
return "."
return ".";
}
rooted := path[0] == '/';
......@@ -105,10 +105,10 @@ func Clean(path string) string {
func Split(path string) (dir, file string) {
for i := len(path)-1; i >= 0; i-- {
if path[i] == '/' {
return path[0:i+1], path[i+1:len(path)];
return path[0 : i+1], path[i+1 : len(path)];
}
}
return "", path
return "", path;
}
// Join joins dir and file into a single path, adding a separating
......@@ -117,7 +117,7 @@ func Join(dir, file string) string {
if dir == "" {
return file;
}
return Clean(dir + "/" + file);
return Clean(dir+"/"+file);
}
// Ext returns the file name extension used by path.
......@@ -130,6 +130,5 @@ func Ext(path string) string {
return path[i:len(path)];
}
}
return ""
return "";
}
......@@ -5,14 +5,14 @@
package path
import (
"testing"
"testing";
)
type CleanTest struct {
path, clean string
path, clean string;
}
var cleantests = []CleanTest {
var cleantests = []CleanTest{
// Already clean
CleanTest{"", "."},
CleanTest{"abc", "abc"},
......@@ -71,10 +71,10 @@ func TestClean(t *testing.T) {
}
type SplitTest struct {
path, dir, file string
path, dir, file string;
}
var splittests = []SplitTest {
var splittests = []SplitTest{
SplitTest{"a/b", "a/", "b"},
SplitTest{"a/b/", "a/b/", ""},
SplitTest{"a/", "a/", ""},
......@@ -91,10 +91,10 @@ func TestSplit(t *testing.T) {
}
type JoinTest struct {
dir, file, path string
dir, file, path string;
}
var jointests = []JoinTest {
var jointests = []JoinTest{
JoinTest{"a", "b", "a/b"},
JoinTest{"a", "", "a"},
JoinTest{"", "b", "b"},
......@@ -113,10 +113,10 @@ func TestJoin(t *testing.T) {
}
type ExtTest struct {
path, ext string
path, ext string;
}
var exttests = []ExtTest {
var exttests = []ExtTest{
ExtTest{"path.go", ".go"},
ExtTest{"path.pb.go", ".go"},
ExtTest{"a.dir/b", ""},
......@@ -131,4 +131,3 @@ func TestExt(t *testing.T) {
}
}
}
......@@ -470,7 +470,7 @@ func TestAllMatches(t *testing.T) {
switch c.matchfunc {
case "matchit":
result = make([]string, len(c.input) + 1);
result = make([]string, len(c.input)+1);
i := 0;
b := strings.Bytes(c.input);
for match := range re.AllMatchesIter(b, c.n) {
......@@ -479,7 +479,7 @@ func TestAllMatches(t *testing.T) {
}
result = result[0:i];
case "stringmatchit":
result = make([]string, len(c.input) + 1);
result = make([]string, len(c.input)+1);
i := 0;
for match := range re.AllMatchesStringIter(c.input, c.n) {
result[i] = match;
......@@ -487,7 +487,7 @@ func TestAllMatches(t *testing.T) {
}
result = result[0:i];
case "match":
result = make([]string, len(c.input) + 1);
result = make([]string, len(c.input)+1);
b := strings.Bytes(c.input);
i := 0;
for _, match := range re.AllMatches(b, c.n) {
......
......@@ -265,11 +265,11 @@ func decimalAtof64(neg bool, d *decimal, trunc bool) (f float64, ok bool) {
f *= float64pow10[k-22];
k = 22;
}
return f*float64pow10[k], true;
return f * float64pow10[k], true;
case d.dp < d.nd && d.nd - d.dp <= 22: // int / 10^k
f := decimalAtof64Int(neg, d);
return f/float64pow10[d.nd - d.dp], true;
return f / float64pow10[d.nd - d.dp], true;
}
return;
}
......@@ -296,11 +296,11 @@ func decimalAtof32(neg bool, d *decimal, trunc bool) (f float32, ok bool) {
f *= float32pow10[k-10];
k = 10;
}
return f*float32pow10[k], true;
return f * float32pow10[k], true;
case d.dp < d.nd && d.nd - d.dp <= 10: // int / 10^k
f := decimalAtof32Int(neg, d);
return f/float32pow10[d.nd - d.dp], true;
return f / float32pow10[d.nd - d.dp], true;
}
return;
}
......
......@@ -21,7 +21,7 @@ var shifttests = []shiftTest{
shiftTest{1, 100, "1267650600228229401496703205376"},
shiftTest{1, -100,
"0.00000000000000000000000000000078886090522101180541"
"17285652827862296732064351090230047702789306640625",
"17285652827862296732064351090230047702789306640625",
},
shiftTest{12345678, 8, "3160493568"},
shiftTest{12345678, -8, "48225.3046875"},
......
......@@ -16,13 +16,13 @@ import (
func pow2(i int) float64 {
switch {
case i < 0:
return 1 / pow2(-i);
return 1/pow2(-i);
case i == 0:
return 1;
case i == 1:
return 2;
}
return pow2(i/2) * pow2(i - i/2);
return pow2(i/2)*pow2(i - i/2);
}
// Wrapper around strconv.Atof64. Handles dddddp+ddd (binary exponent)
......
......@@ -14,12 +14,13 @@ import "math"
// TODO: move elsewhere?
type floatInfo struct {
mantbits uint;
expbits uint;
bias int;
mantbits uint;
expbits uint;
bias int;
}
var float32info = floatInfo{ 23, 8, -127 }
var float64info = floatInfo{ 52, 11, -1023 }
var float32info = floatInfo{23, 8, -127}
var float64info = floatInfo{52, 11, -1023}
func floatsize() int {
// Figure out whether float is float32 or float64.
......@@ -72,12 +73,12 @@ func Ftoa(f float, fmt byte, prec int) string {
}
func genericFtoa(bits uint64, fmt byte, prec int, flt *floatInfo) string {
neg := bits>>flt.expbits>>flt.mantbits != 0;
exp := int(bits>>flt.mantbits) & (1<<flt.expbits - 1);
mant := bits & (uint64(1)<<flt.mantbits - 1);
neg := bits >> flt.expbits >> flt.mantbits != 0;
exp := int(bits >> flt.mantbits)&(1 << flt.expbits - 1);
mant := bits&(uint64(1) << flt.mantbits - 1);
switch exp {
case 1<<flt.expbits - 1:
case 1 << flt.expbits - 1:
// Inf, NaN
if mant != 0 {
return "NaN";
......@@ -93,7 +94,7 @@ func genericFtoa(bits uint64, fmt byte, prec int, flt *floatInfo) string {
default:
// add implicit top bit
mant |= uint64(1)<<flt.mantbits;
mant |= uint64(1) << flt.mantbits;
}
exp += flt.bias;
......@@ -106,7 +107,7 @@ func genericFtoa(bits uint64, fmt byte, prec int, flt *floatInfo) string {
// The shift is exp - flt.mantbits because mant is a 1-bit integer
// followed by a flt.mantbits fraction, and we are treating it as
// a 1+flt.mantbits-bit integer.
d := newDecimal(mant).Shift(exp - int(flt.mantbits));
d := newDecimal(mant).Shift(exp-int(flt.mantbits));
// Round appropriately.
// Negative precision means "only as much as needed to be exact."
......@@ -127,7 +128,7 @@ func genericFtoa(bits uint64, fmt byte, prec int, flt *floatInfo) string {
case 'e', 'E':
d.Round(prec+1);
case 'f':
d.Round(d.dp+prec);
d.Round(d.dp + prec);
case 'g', 'G':
if prec == 0 {
prec = 1;
......@@ -151,16 +152,16 @@ func genericFtoa(bits uint64, fmt byte, prec int, flt *floatInfo) string {
// if precision was the shortest possible, use precision 6 for this decision.
eprec := prec;
if shortest {
eprec = 6
eprec = 6;
}
exp := d.dp - 1;
if exp < -4 || exp >= eprec {
return fmtE(neg, d, prec - 1, fmt + 'e' - 'g');
return fmtE(neg, d, prec-1, fmt+'e'-'g');
}
return fmtF(neg, d, max(prec - d.dp, 0));
}
return "%" + string(fmt);
return "%"+string(fmt);
}
// Round d (= mant * 2^exp) to the shortest number of digits
......@@ -185,7 +186,7 @@ func roundShortest(d *decimal, mant uint64, exp int, flt *floatInfo) {
// d = mant << (exp - mantbits)
// Next highest floating point number is mant+1 << exp-mantbits.
// Our upper bound is halfway inbetween, mant*2+1 << exp-mantbits-1.
upper := newDecimal(mant*2+1).Shift(exp-int(flt.mantbits)-1);
upper := newDecimal(mant*2 + 1).Shift(exp-int(flt.mantbits)-1);
// d = mant << (exp - mantbits)
// Next lowest floating point number is mant-1 << exp-mantbits,
......@@ -196,14 +197,14 @@ func roundShortest(d *decimal, mant uint64, exp int, flt *floatInfo) {
minexp := flt.bias + 1; // minimum possible exponent
var mantlo uint64;
var explo int;
if mant > 1<<flt.mantbits || exp == minexp {
mantlo = mant - 1;
if mant > 1 << flt.mantbits || exp == minexp {
mantlo = mant-1;
explo = exp;
} else {
mantlo = mant*2-1;
mantlo = mant*2 - 1;
explo = exp-1;
}
lower := newDecimal(mantlo*2+1).Shift(explo-int(flt.mantbits)-1);
lower := newDecimal(mantlo*2 + 1).Shift(explo-int(flt.mantbits)-1);
// The upper and lower bounds are possible outputs only if
// the original mantissa is even, so that IEEE round-to-even
......@@ -252,8 +253,8 @@ func roundShortest(d *decimal, mant uint64, exp int, flt *floatInfo) {
// %e: -d.ddddde±dd
func fmtE(neg bool, d *decimal, prec int, fmt byte) string {
buf := make([]byte, 3+max(prec, 0)+30); // "-0." + prec digits + exp
w := 0; // write index
buf := make([]byte, 3 + max(prec, 0) + 30); // "-0." + prec digits + exp
w := 0; // write index
// sign
if neg {
......@@ -322,7 +323,7 @@ func fmtE(neg bool, d *decimal, prec int, fmt byte) string {
// %f: -ddddddd.ddddd
func fmtF(neg bool, d *decimal, prec int) string {
buf := make([]byte, 1+max(d.dp, 1)+1+max(prec, 0));
buf := make([]byte, 1 + max(d.dp, 1) + 1 + max(prec, 0));
w := 0;
// sign
......@@ -352,10 +353,10 @@ func fmtF(neg bool, d *decimal, prec int) string {
buf[w] = '.';
w++;
for i := 0; i < prec; i++ {
if d.dp+i < 0 || d.dp+i >= d.nd {
if d.dp + i < 0 || d.dp + i >= d.nd {
buf[w] = '0';
} else {
buf[w] = d.d[d.dp+i];
buf[w] = d.d[d.dp + i];
}
w++;
}
......@@ -379,7 +380,7 @@ func fmtB(neg bool, mant uint64, exp int, flt *floatInfo) string {
n++;
w--;
buf[w] = byte(exp%10 + '0');
exp /= 10
exp /= 10;
}
w--;
buf[w] = esign;
......@@ -405,4 +406,3 @@ func max(a, b int) int {
}
return b;
}
......@@ -13,32 +13,32 @@ import (
)
type Test struct {
in, out, err string
in, out, err string;
}
type T struct {
item string;
value string;
item string;
value string;
}
type S struct {
header string;
integer int;
raw string;
innerT T;
innerPointerT *T;
data []T;
pdata []*T;
empty []*T;
emptystring string;
null []*T;
vec *vector.Vector;
true bool;
false bool;
header string;
integer int;
raw string;
innerT T;
innerPointerT *T;
data []T;
pdata []*T;
empty []*T;
emptystring string;
null []*T;
vec *vector.Vector;
true bool;
false bool;
}
var t1 = T{ "ItemNumber1", "ValueNumber1" }
var t2 = T{ "ItemNumber2", "ValueNumber2" }
var t1 = T{"ItemNumber1", "ValueNumber1"}
var t2 = T{"ItemNumber2", "ValueNumber2"}
func uppercase(v interface{}) string {
s := v.(string);
......@@ -46,7 +46,7 @@ func uppercase(v interface{}) string {
for i := 0; i < len(s); i++ {
c := s[i];
if 'a' <= c && c <= 'z' {
c = c + 'A' - 'a'
c = c+'A'-'a';
}
t += string(c);
}
......@@ -55,36 +55,36 @@ func uppercase(v interface{}) string {
func plus1(v interface{}) string {
i := v.(int);
return fmt.Sprint(i + 1);
return fmt.Sprint(i+1);
}
func writer(f func(interface{}) string) (func(io.Writer, interface{}, string)) {
return func(w io.Writer, v interface{}, format string) {
io.WriteString(w, f(v));
}
};
}
var formatters = FormatterMap {
"uppercase" : writer(uppercase),
"+1" : writer(plus1),
var formatters = FormatterMap{
"uppercase": writer(uppercase),
"+1": writer(plus1),
}
var tests = []*Test {
var tests = []*Test{
// Simple
&Test{ "", "", "" },
&Test{ "abc\ndef\n", "abc\ndef\n", "" },
&Test{ " {.meta-left} \n", "{", "" },
&Test{ " {.meta-right} \n", "}", "" },
&Test{ " {.space} \n", " ", "" },
&Test{ " {.tab} \n", "\t", "" },
&Test{ " {#comment} \n", "", "" },
&Test{"", "", ""},
&Test{"abc\ndef\n", "abc\ndef\n", ""},
&Test{" {.meta-left} \n", "{", ""},
&Test{" {.meta-right} \n", "}", ""},
&Test{" {.space} \n", " ", ""},
&Test{" {.tab} \n", "\t", ""},
&Test{" {#comment} \n", "", ""},
// Variables at top level
&Test{
in: "{header}={integer}\n",
out: "Header=77\n"
out: "Header=77\n",
},
// Section
......@@ -93,21 +93,21 @@ var tests = []*Test {
"some text for the section\n"
"{.end}\n",
out: "some text for the section\n"
out: "some text for the section\n",
},
&Test{
in: "{.section data }\n"
"{header}={integer}\n"
"{.end}\n",
out: "Header=77\n"
out: "Header=77\n",
},
&Test{
in: "{.section pdata }\n"
"{header}={integer}\n"
"{.end}\n",
out: "Header=77\n"
out: "Header=77\n",
},
&Test{
in: "{.section pdata }\n"
......@@ -116,7 +116,7 @@ var tests = []*Test {
"data not present\n"
"{.end}\n",
out: "data present\n"
out: "data present\n",
},
&Test{
in: "{.section empty }\n"
......@@ -125,7 +125,7 @@ var tests = []*Test {
"data not present\n"
"{.end}\n",
out: "data not present\n"
out: "data not present\n",
},
&Test{
in: "{.section null }\n"
......@@ -134,7 +134,7 @@ var tests = []*Test {
"data not present\n"
"{.end}\n",
out: "data not present\n"
out: "data not present\n",
},
&Test{
in: "{.section pdata }\n"
......@@ -145,12 +145,12 @@ var tests = []*Test {
"{.end}\n",
out: "Header=77\n"
"Header=77\n"
"Header=77\n",
},
&Test{
in: "{.section data}{.end} {header}\n",
out: " Header\n"
out: " Header\n",
},
// Repeated
......@@ -162,7 +162,7 @@ var tests = []*Test {
"{.end}\n",
out: "ItemNumber1=ValueNumber1\n"
"ItemNumber2=ValueNumber2\n"
"ItemNumber2=ValueNumber2\n",
},
&Test{
in: "{.section pdata }\n"
......@@ -174,7 +174,7 @@ var tests = []*Test {
"{.end}\n",
out: "ItemNumber1=ValueNumber1\n"
"ItemNumber2=ValueNumber2\n"
"ItemNumber2=ValueNumber2\n",
},
&Test{
in: "{.section @ }\n"
......@@ -185,7 +185,7 @@ var tests = []*Test {
"{.end}\n"
"{.end}\n",
out: "this should appear: empty field\n"
out: "this should appear: empty field\n",
},
&Test{
in: "{.repeated section pdata }\n"
......@@ -196,7 +196,7 @@ var tests = []*Test {
out: "ItemNumber1\n"
"is\nover\nmultiple\nlines\n"
"ItemNumber2\n"
"ItemNumber2\n",
},
&Test{
in: "{.section pdata }\n"
......@@ -210,7 +210,7 @@ var tests = []*Test {
out: "ItemNumber1=ValueNumber1\n"
"DIVIDER\n"
"ItemNumber2=ValueNumber2\n"
"ItemNumber2=ValueNumber2\n",
},
&Test{
in: "{.repeated section vec }\n"
......@@ -218,7 +218,7 @@ var tests = []*Test {
"{.end}\n",
out: "elt1\n"
"elt2\n"
"elt2\n",
},
&Test{
in: "{.repeated section integer}{.end}",
......@@ -232,14 +232,14 @@ var tests = []*Test {
"{innerT.item}={innerT.value}\n"
"{.end}",
out: "ItemNumber1=ValueNumber1\n"
out: "ItemNumber1=ValueNumber1\n",
},
&Test{
in: "{.section @ }\n"
"{innerT.item}={.section innerT}{.section value}{@}{.end}{.end}\n"
"{.end}",
out: "ItemNumber1=ValueNumber1\n"
out: "ItemNumber1=ValueNumber1\n",
},
......@@ -251,7 +251,7 @@ var tests = []*Test {
"{.end}\n",
out: "HEADER=78\n"
"Header=77\n"
"Header=77\n",
},
&Test{
......@@ -259,21 +259,21 @@ var tests = []*Test {
"{raw|html}\n",
out: "&<>!@ #$%^\n"
"&amp;&lt;&gt;!@ #$%^\n"
"&amp;&lt;&gt;!@ #$%^\n",
},
&Test{
in: "{.section emptystring}emptystring{.end}\n"
"{.section header}header{.end}\n",
out: "\nheader\n"
out: "\nheader\n",
},
&Test {
&Test{
in: "{.section true}1{.or}2{.end}\n"
"{.section false}3{.or}4{.end}\n",
out: "1\n4\n"
out: "1\n4\n",
},
}
......@@ -284,9 +284,9 @@ func TestAll(t *testing.T) {
s.integer = 77;
s.raw = "&<>!@ #$%^";
s.innerT = t1;
s.data = []T{ t1, t2 };
s.pdata = []*T{ &t1, &t2 };
s.empty = []*T{ };
s.data = []T{t1, t2};
s.pdata = []*T{&t1, &t2};
s.empty = []*T{};
s.null = nil;
s.vec = vector.New(0);
s.vec.Push("elt1");
......@@ -321,28 +321,28 @@ func TestAll(t *testing.T) {
func TestStringDriverType(t *testing.T) {
tmpl, err := Parse("template: {@}", nil);
if err != nil {
t.Error("unexpected parse error:", err)
t.Error("unexpected parse error:", err);
}
var b bytes.Buffer;
err = tmpl.Execute("hello", &b);
if err != nil {
t.Error("unexpected execute error:", err)
t.Error("unexpected execute error:", err);
}
s := b.String();
if s != "template: hello" {
t.Errorf("failed passing string as data: expected %q got %q", "template: hello", s)
t.Errorf("failed passing string as data: expected %q got %q", "template: hello", s);
}
}
func TestTwice(t *testing.T) {
tmpl, err := Parse("template: {@}", nil);
if err != nil {
t.Error("unexpected parse error:", err)
t.Error("unexpected parse error:", err);
}
var b bytes.Buffer;
err = tmpl.Execute("hello", &b);
if err != nil {
t.Error("unexpected parse error:", err)
t.Error("unexpected parse error:", err);
}
s := b.String();
text := "template: hello";
......@@ -351,7 +351,7 @@ func TestTwice(t *testing.T) {
}
err = tmpl.Execute("hello", &b);
if err != nil {
t.Error("unexpected parse error:", err)
t.Error("unexpected parse error:", err);
}
s = b.String();
text += text;
......@@ -377,9 +377,9 @@ func TestCustomDelims(t *testing.T) {
err := tmpl.Parse(text);
if err != nil {
if i == 0 || j == 0 { // expected
continue
continue;
}
t.Error("unexpected parse error:", err)
t.Error("unexpected parse error:", err);
} else if i == 0 || j == 0 {
t.Errorf("expected parse error for empty delimiter: %d %d %q %q", i, j, ldelim, rdelim);
continue;
......@@ -388,7 +388,7 @@ func TestCustomDelims(t *testing.T) {
err = tmpl.Execute("hello", &b);
s := b.String();
if s != "template: hello" + ldelim + rdelim {
t.Errorf("failed delim check(%q %q) %q got %q", ldelim, rdelim, text, s)
t.Errorf("failed delim check(%q %q) %q got %q", ldelim, rdelim, text, s);
}
}
}
......@@ -408,7 +408,7 @@ func TestVarIndirection(t *testing.T) {
}
err = tmpl.Execute(s, &buf);
if err != nil {
t.Fatal("unexpected execute error:", err)
t.Fatal("unexpected execute error:", err);
}
expect := fmt.Sprintf("%v", &t1); // output should be hex address of t1
if buf.String() != expect {
......
......@@ -70,7 +70,7 @@ func (r *dataErrReader) Read(p []byte) (n int, err os.Error) {
break;
}
n = bytes.Copy(p, r.unread);
r.unread = r.unread[n : len(r.unread)];
r.unread = r.unread[n:len(r.unread)];
}
return;
}
This diff is collapsed.
This diff is collapsed.
......@@ -67,13 +67,13 @@ func (t *T) FailNow() {
// Log formats its arguments using default formatting, analogous to Print(),
// and records the text in the error log.
func (t *T) Log(args ...) {
t.errors += "\t" + tabify(fmt.Sprintln(args));
t.errors += "\t"+tabify(fmt.Sprintln(args));
}
// Log formats its arguments according to the format, analogous to Printf(),
// and records the text in the error log.
func (t *T) Logf(format string, args ...) {
t.errors += "\t" + tabify(fmt.Sprintf(format, args));
t.errors += "\t"+tabify(fmt.Sprintf(format, args));
}
// Error is equivalent to Log() followed by Fail().
......
......@@ -211,8 +211,8 @@ func (t *Time) Seconds() int64 {
sec := day * secondsPerDay;
// Add in time elapsed today.
sec += int64(t.Hour) * 3600;
sec += int64(t.Minute) * 60;
sec += int64(t.Hour)*3600;
sec += int64(t.Minute)*60;
sec += int64(t.Second);
// Convert from seconds since 2001 to seconds since 1970.
......
......@@ -5,9 +5,9 @@
package time_test
import (
"os";
"testing";
. "time";
"os";
"testing";
. "time";
)
func init() {
......@@ -18,35 +18,35 @@ func init() {
}
type TimeTest struct {
seconds int64;
golden Time;
seconds int64;
golden Time;
}
var utctests = []TimeTest {
var utctests = []TimeTest{
TimeTest{0, Time{1970, 1, 1, 0, 0, 0, Thursday, 0, "UTC"}},
TimeTest{1221681866, Time{2008, 9, 17, 20, 4, 26, Wednesday, 0, "UTC"}},
TimeTest{-1221681866, Time{1931, 4, 16, 3, 55, 34, Thursday, 0, "UTC"}},
TimeTest{1e18, Time{31688740476, 10, 23, 1, 46, 40, Friday, 0, "UTC"}},
TimeTest{-1e18, Time{-31688736537, 3, 10, 22, 13, 20, Tuesday, 0, "UTC"}},
TimeTest{0x7fffffffffffffff, Time{292277026596, 12, 4, 15, 30, 7, Sunday, 0, "UTC"}},
TimeTest{-0x8000000000000000, Time{-292277022657, 1, 27, 8, 29, 52, Sunday, 0, "UTC"}}
TimeTest{-0x8000000000000000, Time{-292277022657, 1, 27, 8, 29, 52, Sunday, 0, "UTC"}},
}
var localtests = []TimeTest {
TimeTest{0, Time{1969, 12, 31, 16, 0, 0, Wednesday, -8*60*60, "PST"}},
TimeTest{1221681866, Time{2008, 9, 17, 13, 4, 26, Wednesday, -7*60*60, "PDT"}}
var localtests = []TimeTest{
TimeTest{0, Time{1969, 12, 31, 16, 0, 0, Wednesday, -8 * 60 * 60, "PST"}},
TimeTest{1221681866, Time{2008, 9, 17, 13, 4, 26, Wednesday, -7 * 60 * 60, "PDT"}},
}
func same(t, u *Time) bool {
return t.Year == u.Year
&& t.Month == u.Month
&& t.Day == u.Day
&& t.Hour == u.Hour
&& t.Minute == u.Minute
&& t.Second == u.Second
&& t.Weekday == u.Weekday
&& t.ZoneOffset == u.ZoneOffset
&& t.Zone == u.Zone
return t.Year == u.Year &&
t.Month == u.Month &&
t.Day == u.Day &&
t.Hour == u.Hour &&
t.Minute == u.Minute &&
t.Second == u.Second &&
t.Weekday == u.Weekday &&
t.ZoneOffset == u.ZoneOffset &&
t.Zone == u.Zone;
}
func TestSecondsToUTC(t *testing.T) {
......@@ -82,4 +82,3 @@ func TestSecondsToLocalTime(t *testing.T) {
}
}
}
......@@ -34,7 +34,7 @@ func (d *data) read(n int) []byte {
return nil;
}
p := d.p[0:n];
d.p = d.p[n : len(d.p)];
d.p = d.p[n:len(d.p)];
return p;
}
......
This diff is collapsed.
This diff is collapsed.
......@@ -120,7 +120,7 @@ func TestDecodeRune(t *testing.T) {
if rune != RuneError || size != wantsize {
t.Errorf("DecodeRune(%q) = 0x%04x, %d want 0x%04x, %d", b[0 : len(b)-1], rune, size, RuneError, wantsize);
}
s = m.str[0 : len(m.str) - 1];
s = m.str[0 : len(m.str)-1];
rune, size = DecodeRuneInString(s);
if rune != RuneError || size != wantsize {
t.Errorf("DecodeRuneInString(%q) = 0x%04x, %d want 0x%04x, %d", s, rune, size, RuneError, wantsize);
......
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