Commit b50dd609 authored by ChaiShushan's avatar ChaiShushan Committed by Rob Pike

compress/flate: use go generate to create fixedhuff.go

LGTM=r
R=golang-codereviews, r
CC=golang-codereviews
https://golang.org/cl/137750043
parent 5db510f1
......@@ -4,7 +4,7 @@
package flate
// autogenerated by gen.go, DO NOT EDIT
// autogenerated by go run gen.go -output fixedhuff.go, DO NOT EDIT
var fixedHuffmanDecoder = huffmanDecoder{
7,
......
......@@ -7,14 +7,21 @@
// This program generates fixedhuff.go
// Invoke as
//
// go run gen.go |gofmt >fixedhuff.go
// go run gen.go -output fixedhuff.go
package main
import (
"bytes"
"flag"
"fmt"
"go/format"
"io/ioutil"
"log"
)
var filename = flag.String("output", "fixedhuff.go", "output file name")
const maxCodeLen = 16
// Note: the definition of the huffmanDecoder struct is copied from
......@@ -113,6 +120,8 @@ func (h *huffmanDecoder) init(bits []int) bool {
}
func main() {
flag.Parse()
var h huffmanDecoder
var bits [288]int
initReverseByte()
......@@ -129,27 +138,43 @@ func main() {
bits[i] = 8
}
h.init(bits[:])
fmt.Println("package flate")
fmt.Println()
fmt.Println("// autogenerated by gen.go, DO NOT EDIT")
fmt.Println()
fmt.Println("var fixedHuffmanDecoder = huffmanDecoder{")
fmt.Printf("\t%d,\n", h.min)
fmt.Println("\t[huffmanNumChunks]uint32{")
var buf bytes.Buffer
fmt.Fprintf(&buf, `// Copyright 2013 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.`+"\n\n")
fmt.Fprintln(&buf, "package flate")
fmt.Fprintln(&buf)
fmt.Fprintln(&buf, "// autogenerated by go run gen.go -output fixedhuff.go, DO NOT EDIT")
fmt.Fprintln(&buf)
fmt.Fprintln(&buf, "var fixedHuffmanDecoder = huffmanDecoder{")
fmt.Fprintf(&buf, "\t%d,\n", h.min)
fmt.Fprintln(&buf, "\t[huffmanNumChunks]uint32{")
for i := 0; i < huffmanNumChunks; i++ {
if i&7 == 0 {
fmt.Printf("\t\t")
fmt.Fprintf(&buf, "\t\t")
} else {
fmt.Printf(" ")
fmt.Fprintf(&buf, " ")
}
fmt.Printf("0x%04x,", h.chunks[i])
fmt.Fprintf(&buf, "0x%04x,", h.chunks[i])
if i&7 == 7 {
fmt.Println()
fmt.Fprintln(&buf)
}
}
fmt.Fprintln(&buf, "\t},")
fmt.Fprintln(&buf, "\tnil, 0,")
fmt.Fprintln(&buf, "}")
data, err := format.Source(buf.Bytes())
if err != nil {
log.Fatal(err)
}
err = ioutil.WriteFile(*filename, data, 0644)
if err != nil {
log.Fatal(err)
}
fmt.Println("\t},")
fmt.Println("\tnil, 0,")
fmt.Println("}")
}
var reverseByte [256]byte
......
......@@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:generate go run gen.go -output fixedhuff.go
// Package flate implements the DEFLATE compressed data format, described in
// RFC 1951. The gzip and zlib packages implement access to DEFLATE-based file
// formats.
......
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