Index: src/0dev.org/commands/plaindiff/main.go ================================================================== --- src/0dev.org/commands/plaindiff/main.go +++ src/0dev.org/commands/plaindiff/main.go @@ -1,11 +1,10 @@ package main import ( diff "0dev.org/diff" "bufio" - "flag" "fmt" "hash" "hash/fnv" "io" "os" @@ -12,41 +11,40 @@ ) const usage = "Usage: plaindiff " func main() { - flag.Parse() - - var args []string = flag.Args() - if len(args) != 2 { + var args []string = os.Args + if len(args) != 3 { os.Stderr.WriteString(usage) os.Exit(1) } var hd hashDiff hd.hash = fnv.New64a() - hd.first = read(args[0], hd.hash) - hd.second = read(args[1], hd.hash) + hd.first = read(args[1], hd.hash) + hd.second = read(args[2], hd.hash) var result diff.Delta = diff.Diff(&hd) gen := source(result) + out := bufio.NewWriter(os.Stdout) for have, added, mark := gen(); have; have, added, mark = gen() { var from []line = hd.line(!added) - fmt.Println() + fmt.Fprintln(out) for i := mark.From; i < mark.Length; i++ { - fmt.Print(i) + fmt.Fprint(out, i) if added { - fmt.Print(" > ") + fmt.Fprint(out, " > ") } else { - fmt.Print(" < ") + fmt.Fprint(out, " < ") } - fmt.Println(from[i].text) + fmt.Fprintln(out, from[i].text) } } - + out.Flush() } // Returns a closure over the provided diff.Delta // that returns diff.Mark entries while prioritizing removals when possible func source(d diff.Delta) func() (bool, bool, diff.Mark) {