Skip to content

Commit b19fea1

Browse files
committed
Added CRC32 code to DIFF.LUA
1 parent f78ce09 commit b19fea1

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

xtra/DIFF.LUA

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/usr/bin/env lua
22

3-
CL=tonumber(os.getenv("DIFF_CONTEXT"))or 3
3+
local CL,PF,CT,M=tonumber(os.getenv("DIFF_CONTEXT"))or 3,"I2I4I8",{},0xFFFFFFFF
4+
local function crc32(s)local c=M for i=1,#s do local byte=s:byte(i)c=(c >> 8)~CT[(c~byte)&0xFF]end return(~c)&M end
45
local function diff_u(fn1,fn2)
56
local function open(fn)local f,e=io.open(fn)if not f then print(e)os.exit(1)end return f end
67
local f1,f2,p,a,d,p1,p2,x,y,B,h,l1,l2=open(fn1),open(fn2),{},{},{},0,0,0,0,{a=0,d=0,l={}}
@@ -34,4 +35,5 @@ if#arg<2 or#arg%2~=0 then print(arg[-1].." "..arg[0]..[[ old new...
3435
Compare differences between files, print them as unified context.
3536
To compare multiple files,write them sequentially.
3637
Example: ']]..arg[0]..[[ old1 new1 old2 new2 old3 new3' etc...]])os.exit(1)end
38+
for i=0,255 do local c=i for _=1,8 do c=(c&1~=0)and((c>>1)~0xEDB88320)or(c>>1)end CT[i]=c end
3739
for i=1,#arg,2 do diff_u(arg[i],arg[i+1])end

0 commit comments

Comments
 (0)