From 7bd7bcfcdf98d6a3864580e925b33d24ea75ae77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20B=C5=82aszczyk?= Date: Fri, 3 Jan 2014 18:46:33 +0100 Subject: [PATCH 1/2] Fix for ignored trailing path separator in prefix. --- main.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/main.go b/main.go index 8682966..bce5d01 100644 --- a/main.go +++ b/main.go @@ -11,6 +11,7 @@ import ( "os" "path" "path/filepath" + "strings" "unicode" ) @@ -90,7 +91,14 @@ func parseArgs() { pipe = flag.NArg() == 0 if !pipe { + sepsuffix := false + if strings.HasSuffix(*prefix, string(filepath.Separator)) { + sepsuffix = true + } *prefix, _ = filepath.Abs(filepath.Clean(*prefix)) + if sepsuffix { + *prefix += string(filepath.Separator) + } in, _ = filepath.Abs(filepath.Clean(flag.Args()[0])) *out = safeFilename(*out, in) } From 28919a6a56460bb97d69f31d869e412e65ea3e48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20B=C5=82aszczyk?= Date: Fri, 3 Jan 2014 19:08:52 +0100 Subject: [PATCH 2/2] Output files are not formatted in accordance with go fmt. --- lib/bytewriter.go | 9 ++++++++- lib/toc.go | 4 ++-- lib/translate.go | 6 ++++-- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/lib/bytewriter.go b/lib/bytewriter.go index c9b602c..05d6d67 100644 --- a/lib/bytewriter.go +++ b/lib/bytewriter.go @@ -9,7 +9,11 @@ import ( "io" ) -var newline = []byte{'\n'} +var ( + newline = []byte{'\n'} + dataindent = []byte{'\t', '\t'} + space = []byte{' '} +) type ByteWriter struct { io.Writer @@ -24,7 +28,10 @@ func (w *ByteWriter) Write(p []byte) (n int, err error) { for n = range p { if w.c%12 == 0 { w.Writer.Write(newline) + w.Writer.Write(dataindent) w.c = 0 + } else { + w.Writer.Write(space) } fmt.Fprintf(w.Writer, "0x%02x,", p[n]) diff --git a/lib/toc.go b/lib/toc.go index a534d93..4eb7350 100644 --- a/lib/toc.go +++ b/lib/toc.go @@ -21,7 +21,8 @@ func CreateTOC(dir, pkgname string) error { // After startup of the program, all generated data files will // put themselves in this map. The key is the full filename, as // supplied to go-bindata. -var go_bindata = make(map[string]func() []byte)`, pkgname) +var go_bindata = make(map[string]func() []byte) +`, pkgname) return ioutil.WriteFile(file, []byte(code), 0600) } @@ -31,7 +32,6 @@ var go_bindata = make(map[string]func() []byte)`, pkgname) func WriteTOCInit(output io.Writer, filename, prefix, funcname string) { filename = strings.Replace(filename, prefix, "", 1) fmt.Fprintf(output, ` - func init() { go_bindata[%q] = %s } diff --git a/lib/translate.go b/lib/translate.go index 4e8cb2f..224e00f 100644 --- a/lib/translate.go +++ b/lib/translate.go @@ -62,7 +62,8 @@ func %s() []byte { gz.Close() return b.Bytes() -}`) +} +`) } // input -> gzip -> gowriter -> output. @@ -77,7 +78,8 @@ func %s() []byte { fmt.Fprint(output, ` } -}`) +} +`) } // input -> gzip -> gowriter -> output.