update README for 43.05
[rofl0r-df-mayday.git] / utils / diffchar.ooc
blob0e60b5be556d00102a1cc48a40685fa1280b7af9
1 import text/Opts
2 import structs/ArrayList
3 import text/StringTokenizer
4 import BufferFile
5 import nconv
7 charok := "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890[]{}():\0"
8 charOk?: func(c:Char) -> Bool { charok contains?(c) }
9 debugbuf: func(b:Buffer) {
10 ob := Buffer new()
11 for (i in 0 .. b size) ob append("\\x" + numberToString(b[i] as UInt64, 16, 2, true))
12 "ptr: %p, size: %d, buf: %s" format(b, b size, ob data) println()
16 main: func( args: ArrayList<String>) {
17 opts := Opts new(args)
18 oldchars := Buffer new()
19 newchars := Buffer new()
20 if(!opts set?("new")) {
21 assert(oldchars fromFile("oldchars"))
22 assert(newchars fromFile("newchars"))
24 debugbuf(newchars)
25 if (opts args size < 2 ) exit(1)
26 x := Buffer new()
27 x fromFile(opts args get(0))
28 org := x toString() split('\n')
29 y := Buffer new()
30 y fromFile(opts args get(1))
31 dfg := y toString() split('\n')
32 for (lineno in 0..org size) {
33 orgline := org get(lineno)
34 dfgline := dfg get(lineno)
35 found := false
36 for (i in 0..orgline size) {
37 if (orgline[i] != dfgline[i]) {
38 if (!charOk?(orgline[i])) {
39 if (!oldchars contains?(orgline[i])) {
40 oldchars append(orgline[i])
41 newchars append(dfgline[i])
43 // s := numberToString(orgline[i] as UInt64,16,2) + '=' + numberToString(dfgline[i] as UInt64,16,2)
44 // s println()
45 found = true
46 break
47 } else break
50 // if (found) orgline println()
51 // if (found) dfgline println()
54 ("oldchars: " + oldchars toString()) println()
55 ("newchars: " + newchars toString()) println()
56 if (newchars contains?('\0')) "something went wrong" println()
57 debugbuf(oldchars)
58 debugbuf(newchars)
59 assert(oldchars toFile("oldchars"))
60 assert(newchars toFile("newchars"))