Some more code cleanup.

pull/4/head
jim teeuwen 2012-06-07 23:34:34 +02:00
parent 665944b444
commit ed2cd8b81c
2 changed files with 18 additions and 16 deletions

View File

@ -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
}

30
main.go
View File

@ -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