Portable new line converter

This commit is contained in:
Jakob Borg 2014-07-12 19:43:47 +02:00
parent 3f791b57ce
commit c64321df47
2 changed files with 32 additions and 2 deletions

View File

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

31
cmd/todos/main.go Normal file
View File

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