仿对比软件的对比功能
发布时间:2020-12-14 22:55:44 所属栏目:大数据 来源:网络整理
导读:今天PHP站长网 52php.cn把收集自互联网的代码分享给大家,仅供参考。 require "iuplua"require "iupluacontrols"--iup.Message("abc","def")--[[fileDlg = iup.filedlg{dialogtype = "save",title = "file save",filter =
以下代码由PHP站长网 52php.cn收集自互联网 现在PHP站长网小编把它分享给大家,仅供参考 require "iuplua" require "iupluacontrols" --iup.Message("abc","def") --[[ fileDlg = iup.filedlg{dialogtype = "save",title = "file save",filter = "*.bmp",filerinfo = "Bitmap files",directory = "C:Windows"} fileDlg:popup(iup.anywhere,iup.anywhere) --]] --fl = io.open("E:ProgramLuaScrawlcander.lua") --for line in fl:lines() do print(line) end local isOnlyShowDiff = false local tabTxtFileLeft,tabTxtFileRight = {},{} function openFile(filePath) local tab = {} --clear local flh = io.open(filePath) for line in flh:lines() do tab[#tab + 1] = {} tab[#tab].str = line end --for _,v in ipairs(tab) do print(v) end return tab end btnAll = iup.button{title = "Show All",id = 1} btnOnly = iup.button{title = "Only Show Difference",id = 2} --print(iup.button1) --[[ print(type(iup)) for k,v in pairs(iup) do if type(v) == "number" then print(k,v) end end --]] function changeShow(ih,but,pressed,x,y,stat) --print(ih.id) --print(but,pressed) if(but == iup.BUTTON1 and pressed == 0) then --print(ih.id) --isOnlyShowDiff = not isOnlyShowDiff if tonumber(ih.id) == 1 then isOnlyShowDiff = false else isOnlyShowDiff = true end print(isOnlyShowDiff) end end btnAll.button_cb,btnOnly.button_cb = changeShow,changeShow hbox1 = iup.hbox{btnAll,btnOnly; margin = "3x3",gap = "2"} slnLeft = iup.text{size = "300x",value = ""} btnLeft = iup.button{title = "Browse"} hbox2 = iup.hbox{slnLeft,btnLeft; margin = "3x3",gap = "2"} mlnLeft = iup.multiline{size = "450x400",value = "",readonly = "yes",formatting = "yes"} --[[ tags = iup.user{bulk = "Yes",cleanout = "Yes"} iup.Append(tags,iup.user{selection = "1,1:1,10",fgcolor = "255 0 0"}) iup.Append(tags,iup.user{selection = "2,1:2,fgcolor = "0 255 0"}) iup.Append(tags,iup.user{selection = "3,1:3,bgcolor = "100 255 255"}) --mlnLeft.addformattag = tags function mlnLeft.caret_cb(ih,lin,col,pos) str = lin..",1:"..lin..",100" tags2 = iup.user{bulk = "yes",cleanout = "Yes"} iup.Append(tags2,iup.user{selection = str,bgcolor = "255 0 255"}) mlnLeft.addformattag = tags2 print(lin,pos,str) end --]] vbox1 = iup.vbox{hbox2,mlnLeft} slnRight = iup.text{size = "300x",value = ""} btnRight = iup.button{title = "Browse"} hbox3 = iup.hbox{slnRight,btnRight; margin = "3x3",gap = "2"} flDlg = iup.filedlg{dialogtype = "OPEN",title = "Open File",filter = "*.*",directory = "D:"} --[[ xxa = "abc" print("abc" == "abc") print(xxa == "abc") xxb = "abc" print(xxa == xxb) --]] --like max-len common sub-squeue problem function markLabel(p,i,j,tab1,tab2) if i == 0 or j == 0 then for k = 1,i do tab1[k].label = 0 end for k = 1,j do tab2[k].label = 0 end return end local a local b if j == 1 then a = 0 else a = p[i][j - 1] end if i == 1 then b = 0 else b = p[i - 1][j] end if p[i][j] == a then tab2[j].label = 0 return markLabel(p,j - 1,tab2) elseif p[i][j] == b then tab1[i].label = 0 return markLabel(p,i - 1,tab2) else tab1[i].label,tab2[j].label = 1,1 return markLabel(p,tab2) end end function computeDiff(tab1,tab2) local p = {} local n,m = #tab1,#tab2 for i = 1,n do p[i] = {} end for i = 1,n do for j = 1,m do local a local b if j == 1 then a = 0 else a = p[i][j - 1] end if i == 1 then b = 0 else b = p[i - 1][j] end if tab1[i].str == tab2[j].str then p[i][j] = math.max(a,b) + 1 else p[i][j] = math.max(a,b) end end end markLabel(p,n,m,tab2) --[[ for i = 1,n do print(i,tab1[i].label,tab2[i].label) end --]] end mlnRight = iup.multiline{size = "450x400",formatting = "yes"} vbox2 = iup.vbox{hbox3,mlnRight} hbox4 = iup.hbox{vbox1,vbox2} vbox3 = iup.vbox{hbox1,hbox4} function showResult() local tagsLeft = iup.user{bulk = "Yes",cleanout = "Yes"} local tagsRight = iup.user{bulk = "Yes",cleanout = "Yes"} local strLeft = "" local strRight = "" for i = 1,#tabTxtFileLeft do if isOnlyShowDiff then strLeft = strLeft .. "n" else strLeft = strLeft .. tabTxtFileLeft[i].str .. "n" end if tabTxtFileLeft[i].label == 0 then iup.Append(tagsLeft,iup.user{selection = i .. ",1:" .. i .. ",500",fgcolor = "200 0 0"}) else iup.Append(tagsLeft,fgcolor = "0 200 0"}) end end for i = 1,#tabTxtFileRight do if isOnlyShowDiff then strRight = strRight .. "n" else strRight = strRight .. tabTxtFileRight[i].str .. "n" end if tabTxtFileRight[i].label == 0 then iup.Append(tagsRight,fgcolor = "0 0 200"}) else iup.Append(tagsRight,fgcolor = "0 200 0"}) end end print(strLeft,strRight) mlnLeft.value,mlnRight.value = strLeft,strRight mlnLeft.addformattag = tagsLeft mlnRight.addformattag = tagsRight end function selectFile(ih,stat) if but == iup.BUTTON1 and pressed == 0 then flDlg:popup(iup.ANYWHERE,iup.ANYWHERE) --print(flDlg.value) if ih == btnLeft and flDlg.value ~= nil then slnLeft.value = flDlg.value tabTxtFileLeft = openFile(flDlg.value) --print(#tabTxtFileLeft) --for _,v in ipairs(tabTxtFileLeft) do print(v.str) end --print(flDlg.value) elseif ih == btnRight and flDlg.value ~= nil then slnRight.value = flDlg.value tabTxtFileRight = openFile(flDlg.value) end if slnLeft.value ~= nil and slnLeft.value ~= "" and slnRight.value ~= nil and slnRight.value ~= "" then --print(slnLeft.value,slnRight.value) --print("asdgasg",slnRight.value) computeDiff(tabTxtFileLeft,tabTxtFileRight) showResult() iup.Flush() end end end btnLeft.button_cb,btnRight.button_cb = selectFile,selectFile dlg = iup.dialog{vbox3; title = "Contrast Soft"} dlg:show() iup.MainLoop() 以上内容由PHP站长网【52php.cn】收集整理供大家参考研究 如果以上内容对您有帮助,欢迎收藏、点赞、推荐、分享。 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |