forked from nitlang/nitutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdiff.nit
More file actions
72 lines (61 loc) · 1.34 KB
/
diff.nit
File metadata and controls
72 lines (61 loc) · 1.34 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
var tmpl_path = args[0]
var input_path = args[1]
var tmpl = tmpl_path.to_path.read_lines
var input = input_path.to_path.read_lines
#print "tmpl:{tmpl.length}"
#print "input:{input.length}"
var ili = 0
for tli in [0..tmpl.length[ do
# Get template line
var tl = tmpl[tli].trim
if tl == "# CHANGE BELOW" then break
if tl == "# CODE HERE" then break
if tl.is_empty then continue
# Get input line
var il
loop
if ili >= input.length then
stderr.write "top: no more input line {ili} for the template line {tli}\n"
exit 1
end
il = input[ili].trim
if il.is_empty then
ili += 1
continue
end
break
end
if tl != il then
stderr.write "top: different template line {tli} vs input {ili}. `{tl}` vs. `{il}`\n"
exit 1
end
ili += 1
end
ili = 0
for tli in [0..tmpl.length[ do
# Get template line
var tl = tmpl[tmpl.length-1-tli].trim
if tl == "# CHANGE ABOVE" then break
if tl == "# CODE HERE" then break
if tl.is_empty then continue
# Get input line
var il
loop
if ili >= input.length then
stderr.write "bot: no more input line {ili} for the template line {tli}\n"
exit 1
end
il = input[input.length-1-ili].trim
if il.is_empty then
ili += 1
continue
end
break
end
if tl != il then
stderr.write "bop: different template line {tli} vs input {ili}. `{tl}` vs. `{il}`\n"
exit 1
end
ili += 1
end
exit 0