Check-in [074a26f76b]
Overview
Comment:Buffer stdout, use os.Args instead of flag
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 074a26f76b320d84c08f2a48a50c8558bdd2e9a6
User & Date: spaskalev on 2014-12-14 20:41:38
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
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
53
54
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"
	"flag"
	"fmt"
	"hash"
	"hash/fnv"
	"io"
	"os"
)

const usage = "Usage: plaindiff <file1> <file2>"

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) {
	var addedAt, removedAt int = 0, 0
	return func() (bool, bool, diff.Mark) {