Overview
| Comment: | Buffer stdout, use os.Args instead of flag |
|---|---|
| Downloads: | Tarball | ZIP archive |
| Timelines: | family | ancestors | descendants | both | trunk |
| Files: | files | file ages | folders |
| SHA1: |
074a26f76b320d84c08f2a48a50c8558 |
| User & Date: | spaskalev on 2014-12-14 20:41:38.263 |
| Other Links: | manifest | tags |
Context
|
2014-12-15
| ||
| 21:22 | Added diff.D struct; Added an RFC1978 Predictor compressor implementation and a test check-in: 67794bdf14 user: spaskalev tags: trunk | |
|
2014-12-14
| ||
| 20:41 | Buffer stdout, use os.Args instead of flag check-in: 074a26f76b user: spaskalev tags: trunk | |
| 12:11 | Skip diagonals shorter than the current match check-in: e01b36769d user: spaskalev tags: trunk | |
Changes
Modified src/0dev.org/commands/plaindiff/main.go
from [f32b00c34a]
to [f98671241a].
1 2 3 4 5 | package main import ( diff "0dev.org/diff" "bufio" | < < < | | | | > | | | | | | | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
package main
import (
diff "0dev.org/diff"
"bufio"
"fmt"
"hash"
"hash/fnv"
"io"
"os"
)
const usage = "Usage: plaindiff <file1> <file2>"
func main() {
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[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.Fprintln(out)
for i := mark.From; i < mark.Length; i++ {
fmt.Fprint(out, i)
if added {
fmt.Fprint(out, " > ")
} else {
fmt.Fprint(out, " < ")
}
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) {
var addedAt, removedAt int = 0, 0
return func() (bool, bool, diff.Mark) {
|
| ︙ | ︙ |