@@ -7,22 +7,19 @@ local function diff_u(fn1,fn2)
77 local function FP ()
88 local function SW (s ) return string.match (s ," %s" )and ' "' .. s .. ' "' or s end
99 if not h then print (" --- " .. SW (fn1 ).. " \n +++ " .. SW (fn2 ))h = true end
10- if # p > 0 then for _ ,v in ipairs (p )do table.insert (B .l ," " .. v )end B .o ,B .n = x -# p ,y -# p end
11- p = {}end
10+ if # p > 0 then for _ ,v in ipairs (p )do table.insert (B .l ," " .. v )end B .o ,B .n = x -# p ,y -# p end p = {}end
1211 local function FH ()
1312 local pol = {}
14- local function optimize ()local i ,j = 1 repeat j = 1 repeat if d [i ]== a [j ]then table.insert (pol ,table.remove (d ,i ))table.remove (a ,j )break end j = j + 1 until j ># a i = i + 1 until i ># d end
15- if # d > 0 and# a > 0 then optimize ()end
13+ local function opt ()local i ,j = 1 repeat j = 1 repeat if d [i ]== a [j ]then table.insert (pol ,table.remove (d ,i ))table.remove (a ,j )break end j = j + 1 until j ># a i = i + 1 until i ># d end
14+ if # d > 0 and# a > 0 then opt ()end
1615 for _ ,v in ipairs (d )do table.insert (B .l ," -" .. v )end
1716 for _ ,v in ipairs (a )do table.insert (B .l ," +" .. v )end
1817 for _ ,v in ipairs (pol )do table.insert (B .l ," " .. v )end
19- B .a ,B .d = B .a +# a ,B .d +# d
20- d ,a = {},{}end
18+ B .a ,B .d = B .a +# a ,B .d +# d d ,a = {},{}end
2119 local function FB ()
2220 if # B .l > 0 then B .d ,B .a =# B .l - B .a ,# B .l - B .d
2321 local he = " @@ -" .. (B .o or B .d > 0 and " 1" or " 0" ).. (B .d == 1 and " " or " ," .. B .d ).. " +" .. (B .n or B .a > 0 and " 1" or " 0" ).. (B .a == 1 and " " or " ," .. B .a ).. " @@"
24- table.insert (B .l ,1 ,he )for _ ,v in ipairs (B .l )do print (v )end end
25- B .l ,B .a ,B .d ,B .o ,B .n = {},0 ,0 ,nil ,nil end
22+ table.insert (B .l ,1 ,he )for _ ,v in ipairs (B .l )do print (v )end end B .l ,B .a ,B .d ,B .o ,B .n = {},0 ,0 ,nil ,nil end
2623 local function di ()
2724 FH ()if # p > CL then table.remove (p ,1 )end
2825 if p1 > 0 or p2 > 0 then
@@ -38,7 +35,7 @@ local function diff_u(fn1,fn2)
3835 repeat if l1 == l2 then di ()elseif not l2 then ri ()elseif not l1 then dn ()else ri ()dn ()end until not l1 and not l2 f1 :close ()f2 :close ()if # a > 0 or# d > 0 then FP ()FH ()end if # B .l > 0 then FB ()end end
3936if # arg < 2 or# arg % 2 ~= 0 then print (arg [- 1 ].. " " .. arg [0 ].. [[ old new...
4037
41- Compare differences between old and new files and print them as unified context.
42- To compare multiple sets of files at a time ,write as sequential parameters .
38+ Compare differences between files, print them as unified context.
39+ To compare multiple files,write them sequentially .
4340Example: ']] .. arg [0 ].. [[ old1 new1 old2 new2 old3 new3' etc...]] )os.exit (1 )end
4441for i = 1 ,# arg ,2 do diff_u (arg [i ],arg [i + 1 ])end
0 commit comments