From c64321df477bf95603f679ad93af80d560bfa6b7 Mon Sep 17 00:00:00 2001 From: Jakob Borg Date: Sat, 12 Jul 2014 19:43:47 +0200 Subject: [PATCH] Portable new line converter --- build.sh | 3 +-- cmd/todos/main.go | 31 +++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 cmd/todos/main.go diff --git a/build.sh b/build.sh index 18357c31..7c127ba0 100755 --- a/build.sh +++ b/build.sh @@ -75,8 +75,7 @@ zipDist() { rm -rf "$name" mkdir -p "$name" for f in "${distFiles[@]}" ; do - sed 's/$/ -/' < "$f" > "$name/$f.txt" + GOARCH="" GOOS="" go run cmd/todos/main.go < "$f" > "$name/$f.txt" done cp syncthing.exe "$name" sign "$name/syncthing.exe" diff --git a/cmd/todos/main.go b/cmd/todos/main.go new file mode 100644 index 00000000..60a0a7b9 --- /dev/null +++ b/cmd/todos/main.go @@ -0,0 +1,31 @@ +package main + +import ( + "bytes" + "fmt" + "io" + "os" +) + +func main() { + buf := make([]byte, 4096) + var err error + for err == nil { + n, err := io.ReadFull(os.Stdin, buf) + if n > 0 { + buf = buf[:n] + repl := bytes.Replace(buf, []byte("\n"), []byte("\r\n"), -1) + _, err = os.Stdout.Write(repl) + if err != nil { + fmt.Println(err) + os.Exit(1) + } + } + if err == io.EOF { + return + } + buf = buf[:cap(buf)] + } + fmt.Println(err) + os.Exit(1) +}