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
|
open configure/Configure
static. =
DIFF_AVAILABLE = $(CheckProg diff)
if $(not $(DIFF_AVAILABLE))
Shell. +=
diff(argv) =
while $(and $(gt $(length $(argv)), 2), $(mem $(nth 0, $(argv)), -u -c))
argv = $(nth-tl 1, $(argv))
if $(not $(eq $(length $(argv)), 2))
eprintln($"Shell.diff: USAGE:")
eprintln($" diff file1 file2")
exit 2
src = $(nth 0, $(argv))
dst = $(nth 1, $(argv))
if $(not $(test -r $(src)))
eprintln($"$(src) is not readable")
exit 2
if $(not $(test -r $(dst)))
eprintln($"$(dst) is not readable")
exit 2
eof = false
code = 0
ch_src = $(fopen $(src), r)
ch_dst = $(fopen $(dst), r)
l_dst =
l_src =
line = 0
eof_src = false
eof_dst = false
while $(not $(eof))
line = $(add $(line), 1)
eof_src = false
try
l_src = $(ch_src.readln)
export
default
eof_src = true
export
eof_dst = false
try
l_dst = $(ch_dst.readln)
export
default
eof_dst = true
export
if $(not $(and $(equal $(eof_src), $(eof_dst)), $(equal $(l_src), $(l_dst))))
eprintln($"Mismatch on line $(line):")
eprintln($"- $(src):")
eprintln($" $(if $(eof_src), END OF FILE, $(l_src))")
eprintln($"- $(dst):")
eprintln($" $(if $(eof_dst), END OF FILE, $(l_dst))")
exit 1
eof = $(or $(eof_src), $(eof_dst))
close($(ch_src))
close($(ch_dst))
return true
export
|