From ed2cd8b81c5543e7b774809e0e980e1bef7f862d Mon Sep 17 00:00:00 2001 From: jim teeuwen Date: Thu, 7 Jun 2012 23:34:34 +0200 Subject: [PATCH] Some more code cleanup. --- gowriter.go | 4 +++- main.go | 30 +++++++++++++++--------------- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/gowriter.go b/gowriter.go index 551dd1f..908c242 100644 --- a/gowriter.go +++ b/gowriter.go @@ -9,6 +9,8 @@ import ( "io" ) +var newline = []byte{'\n'} + type GoWriter struct { io.Writer c int @@ -21,7 +23,7 @@ func (w *GoWriter) Write(p []byte) (n int, err error) { for n = range p { if w.c%12 == 0 { - w.Writer.Write([]byte{'\n'}) + w.Writer.Write(newline) w.c = 0 } diff --git a/main.go b/main.go index 6254bf2..68d3b2c 100644 --- a/main.go +++ b/main.go @@ -74,22 +74,22 @@ func main() { if pipe { // Can't infer from input file name in this mode. fmt.Fprintln(os.Stderr, "[e] No function name specified.") - os.Exit(1) - } else { - _, file := path.Split(*in) - file = strings.ToLower(file) - file = strings.Replace(file, " ", "_", -1) - file = strings.Replace(file, ".", "_", -1) - file = strings.Replace(file, "-", "_", -1) - - if unicode.IsDigit(rune(file[0])) { - // Identifier can't start with a digit. - file = "_" + file - } - - fmt.Fprintf(os.Stderr, "[w] No function name specified. Using '%s'.\n", file) - *funcname = file + return } + + _, file := path.Split(*in) + file = strings.ToLower(file) + file = strings.Replace(file, " ", "_", -1) + file = strings.Replace(file, ".", "_", -1) + file = strings.Replace(file, "-", "_", -1) + + if unicode.IsDigit(rune(file[0])) { + // Identifier can't start with a digit. + file = "_" + file + } + + fmt.Fprintf(os.Stderr, "[w] No function name specified. Using '%s'.\n", file) + *funcname = file } // Read the input file, transform it into a gzip compressed data stream and