From cb7c8031ced6e9a393e8bdc3f409687741ef9feb Mon Sep 17 00:00:00 2001 From: Pixel Date: Sun, 20 Dec 2009 03:02:33 -0800 Subject: Factorizing some bits of code. --- dalos-luahandle.lua | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 dalos-luahandle.lua (limited to 'dalos-luahandle.lua') diff --git a/dalos-luahandle.lua b/dalos-luahandle.lua new file mode 100644 index 0000000..3254490 --- /dev/null +++ b/dalos-luahandle.lua @@ -0,0 +1,51 @@ +dalosp.luahandle = { + create = function (tab) + local obj = { + offset = 0, + canread = function (self) return true end, + canwrite = function (self) return false end, + canseek = function (self) return true end, + canwatch = function (self) return false end, + tell = function (self) return self.offset end, + getsize = function (self) return self.size end, + getmodif = function (self) return 0 end, + flush = function (self) return true end, + seek = function (self, offset, wheel) + if wheel == SEEK_SET then + self.offset = offset + elseif wheel == SEEK_CUR then + self.offset = self.offset + offset + elseif wheel == SEEK_END then + self.offset = self.size + offset + else + error "Unknown wheel" + end + if self.offset < 0 then self.offset = 0 end + if self.offset >= self.size then self.offset = self.size end + if self.do_seek then self:do_seek() end + return self.offset + end, + read = function (self, userdata, count) + count = math.min(count, self.size - self.offset) + + if count == 0 then + if self.got_eof then self.lh:close() end + self.got_eof = true + return 0 + end + + self.got_eof = false + + local r, t = self:do_read(count, userdata) + self.offset = self.offset + r + return r, t + end, + } + for k, v in pairs(tab) do obj[k] = v end + local newh = HandleLua(obj) + obj.lh = newh + self:set_houtput(newh) + end, +} + +dalos.luahandle = dalosp.luahandle.create -- cgit v1.2.3 From e294e63159e9596dd23bdb33e6ac3c574c32289f Mon Sep 17 00:00:00 2001 From: Pixel Date: Mon, 21 Dec 2009 21:22:38 +0100 Subject: Various fixes. --- dalos-binaryops.lua | 2 +- dalos-hexview.lua | 17 +++++++++++------ dalos-limiter.lua | 2 +- dalos-luahandle.lua | 2 +- dalos.lua | 8 ++++++-- iupe-hexview.lua | 30 ++++++++++++++++++++++++++++++ 6 files changed, 50 insertions(+), 11 deletions(-) (limited to 'dalos-luahandle.lua') diff --git a/dalos-binaryops.lua b/dalos-binaryops.lua index 022020c..1ced26f 100644 --- a/dalos-binaryops.lua +++ b/dalos-binaryops.lua @@ -45,7 +45,7 @@ Maximize: %b[No,Yes]{Check if you want to maximize the output} offset = 0, size = self.extra.maximize and math.max(h1:getsize(), h2:getsize()) or math.min(h1:getsize(), h2:getsize()), getname = function () return self.name end, - do_read = function (self, dummy, count) + do_read = function (self, count) self.h1:seek(self.offset) self.h2:seek(self.offset) diff --git a/dalos-hexview.lua b/dalos-hexview.lua index a302d39..ee9412e 100644 --- a/dalos-hexview.lua +++ b/dalos-hexview.lua @@ -52,12 +52,16 @@ dalosp.hexview = { output_change = function (self, ind) self.watchees[ind] = self.outputs[ind] and true or false + self:set_houtput(nil, ind) + self.oldcursors[ind] = -1 + self:dalos_hv_cb(self.extra.hv) end, update_houtput = function (self, ind, cursor) local h = self:get_linked_input(1) - local maxsixe = h and h:getsize() or -1 - if h and self.watchees[ind] then + local maxsize = h and h:getsize() or -1 + cursor = cursor + 0 + if cursor >= 0 and h and self.watchees[ind] then if cursor < maxsize then self:set_houtput(nil, ind) end @@ -72,7 +76,7 @@ dalosp.hexview = { do_seek = function (self) self.h:seek(self.offset + self.origin) end, - do_read = function (self, userdata, count) + do_read = function (self, count, userdata) return self.h:read(count, userdata) end, } @@ -84,20 +88,20 @@ dalosp.hexview = { local m for i = 1, 10 do m = hv.markers[i] - if self.oldcursors[i] ~= m then + if m and self.oldcursors[i] ~= m then self:update_houtput(i, m) self.oldcursors[i] = m end end m = hv.kcursor - if self.oldcursors[11] ~= m then + if m and self.oldcursors[11] ~= m then self:update_houtput(11, m) self.oldcursors[11] = m end m = hv.mcursor - if self.oldcursors[12] ~= m then + if m and self.oldcursors[12] ~= m then self:update_houtput(12, m) self.oldcursors[12] = m end @@ -146,6 +150,7 @@ dalosp.hexview = { end hv:registercb(dalosp.hexview.dalos_hv_cb, obj) + obj.dalos_hv_cb = dalosp.hexview.dalos_hv_cb return obj end, diff --git a/dalos-limiter.lua b/dalos-limiter.lua index ee9b106..99bd07f 100644 --- a/dalos-limiter.lua +++ b/dalos-limiter.lua @@ -21,7 +21,7 @@ Limit: %i{The actual size this limiter is going to produce} h = h, size = math.max(h:getsize(), self.limit), getname = function () return self.name end, - do_read = function (self, userdata, count) + do_read = function (self, count, userdata) return self.h:read(count, userdata) end, do_seek = function (self) diff --git a/dalos-luahandle.lua b/dalos-luahandle.lua index 3254490..332a90e 100644 --- a/dalos-luahandle.lua +++ b/dalos-luahandle.lua @@ -44,7 +44,7 @@ dalosp.luahandle = { for k, v in pairs(tab) do obj[k] = v end local newh = HandleLua(obj) obj.lh = newh - self:set_houtput(newh) + return newh end, } diff --git a/dalos.lua b/dalos.lua index 7f554d1..06058de 100644 --- a/dalos.lua +++ b/dalos.lua @@ -16,6 +16,8 @@ dalosp.WEST = 3 dalosp.EAST = 4 dalosp.cross = { } +dalos.version = { MAJOR = 0, MINOR = 1, suffix = "alpha" } + function dalos:register_obj(name, constructor) if self.objectstypes_by_name[name] then error("An object type of that name already exists: " .. name) @@ -502,7 +504,9 @@ dalosp.menu = { if dlg.status ~= -1 then local s, v = pcall(Output, dlg.value) if s then - v:write "local " + v:write "---- Dalos save\nlocal " + dumpvars(v, dalos.version, "version") + v:write "if dalos.version.MAJOR < version.MAJOR or dalos.version.MAJOR == version.MAJOR and dalos.version.MINOR < version.MINOR then error 'Dalos version too old for this save.' end\n\nlocal " dumpvars(v, save, "save") v:write "return save" end @@ -519,7 +523,7 @@ dalosp.menu = { ButtonDefault = "1", Buttons = "OK", Title = "About", - Value = 'DALOS (c) 2009-2010 Nicolas "Pixel" Noble.\nThis is free software with ABSOLUTELY NO WARRANTY.\nPlease look at the COPYRIGHT file for details.', + Value = 'DALOS ' .. dalos.version.MAJOR .. '.' .. dalos.version.MINOR .. dalos.version.suffix .. ' (c) 2009-2010 Nicolas "Pixel" Noble.\nThis is free software with ABSOLUTELY NO WARRANTY.\nPlease look at the COPYRIGHT file for details.', } dlg:popup() return iup.DEFAULT diff --git a/iupe-hexview.lua b/iupe-hexview.lua index 0567cd0..4b135f0 100644 --- a/iupe-hexview.lua +++ b/iupe-hexview.lua @@ -340,6 +340,36 @@ iupep.hexview = { elseif c == iup.K_m0 then kaction = true self.markers[10] = kcursor + elseif c == iup.K_c1 then + kaction = true + self.markers[1] = nil + elseif c == iup.K_c2 then + kaction = true + self.markers[2] = nil + elseif c == iup.K_c3 then + kaction = true + self.markers[3] = nil + elseif c == iup.K_c4 then + kaction = true + self.markers[4] = nil + elseif c == iup.K_c5 then + kaction = true + self.markers[5] = nil + elseif c == iup.K_c6 then + kaction = true + self.markers[6] = nil + elseif c == iup.K_c7 then + kaction = true + self.markers[7] = nil + elseif c == iup.K_c8 then + kaction = true + self.markers[8] = nil + elseif c == iup.K_c9 then + kaction = true + self.markers[9] = nil + elseif c == iup.K_c0 then + kaction = true + self.markers[10] = nil elseif c == iup.K_SP then kaction = true end -- cgit v1.2.3 From f6ac50837aabd69c6ea5892a858359f51f40ee03 Mon Sep 17 00:00:00 2001 From: Pixel Date: Wed, 23 Dec 2009 00:11:30 +0100 Subject: Mbmbmlmlm \r is evil. --- dalos-binaryops.lua | 228 ++++++++++++++++++------------------ dalos-buffer.lua | 60 +++++----- dalos-hexview.lua | 320 +++++++++++++++++++++++++-------------------------- dalos-input.lua | 88 +++++++------- dalos-limiter.lua | 118 +++++++++---------- dalos-luafilter.lua | 276 ++++++++++++++++++++++---------------------- dalos-luahandle.lua | 102 ++++++++-------- dalos-tee.lua | 100 ++++++++-------- dalos-textbuffer.lua | 70 +++++------ 9 files changed, 681 insertions(+), 681 deletions(-) (limited to 'dalos-luahandle.lua') diff --git a/dalos-binaryops.lua b/dalos-binaryops.lua index 1ced26f..59e8361 100644 --- a/dalos-binaryops.lua +++ b/dalos-binaryops.lua @@ -1,114 +1,114 @@ -dalosp.binaryops = { - operations = { - XOR = 0, - AND = 1, - OR = 2, - ADD = 3, - SUB = 4, - }, - - opnames = { - [0] = "XOR", - [1] = "AND", - [2] = "OR", - [3] = "ADD", - [4] = "SUB", - }, - - configure = function (self) - local accept, operation, maximize = iup.GetParam(self.name .. " configuration", nil, [[ -Operation: %l|xor|and|or|add|sub|{Binary operation that's going to occur} -Maximize: %b[No,Yes]{Check if you want to maximize the output} -]], self.op or 0, self.maximize and 1 or 0) - if accept then - self.extra.op = operation - self.extra.maximize = maximize == 1 - self:input_change() - end - end, - - get_settings = function (self) - return { op = self.extra.op, maximize = self.extra.maximize } - end, - - input_change = function (self, ind) - local h1 = self:get_linked_input(1) - local h2 = self:get_linked_input(2) - local op = self.extra.op or dalosp.binaryops.operations.XOR - if h1 and h2 then - self.color = cd.GREEN - local obj = { - h1 = h1, - h2 = h2, - op = op, - maximize = self.extra.maximize, - offset = 0, - size = self.extra.maximize and math.max(h1:getsize(), h2:getsize()) or math.min(h1:getsize(), h2:getsize()), - getname = function () return self.name end, - do_read = function (self, count) - self.h1:seek(self.offset) - self.h2:seek(self.offset) - - local t1, r1 = self.h1:read(count) - local t2, r2 = self.h2:read(count) - local r = self.extra.maximize and math.max(r1, r2) or math.min(r1, r2) - self.offset = self.offset + r - if r == 0 then self.got_eof = true return 0 end - local t = {} - local op - if self.op == dalosp.binaryops.operations.XOR then - op = bit.bxor - elseif self.op == dalosp.binaryops.operations.AND then - op = bit.band - elseif self.op == dalosp.binaryops.operations.OR then - op = bit.bor - elseif self.op == dalosp.binaryops.operations.ADD then - op = function(a, b) return a + b end - elseif self.op == dalosp.binaryops.operations.SUB then - op = function(a, b) return a - b end - end - for i = 0, r - 1 do - t[i] = bit.band(op(t1[i % r1], t2[i % r2]), 255) - end - return r, t - end, - } - self:set_houtput(dalos.luahandle(obj)) - self.dcanvas:draw() - else - self.color = cd.YELLOW - self:set_houtput(nil) - self.dcanvas:draw() - end - end, - - draw = function (self, cv, x, y, w, h) - dalosp.object.default_draw(self, cv, x, y, w, h) - local cx, cy = x + w / 2, cv:InvertYAxis(y + h / 2) - local op = self.extra.op or dalosp.binaryops.operations.XOR - cv:TextAlignment(cd.CENTER) - cv:Foreground(cd.BLACK) - cv:Text(cx, cy, dalosp.binaryops.opnames[op]) - end, - - create = function (d, tab, settings) - tab.ninputs = 2 - tab.noutputs = 1 - tab.otype = dalos.objtype.LUA_FILTER - tab.configure = dalosp.binaryops.configure - tab.input_change = dalosp.binaryops.input_change - tab.default_name = "Binary Ops" - tab.draw = dalosp.binaryops.draw - tab.get_settings = dalosp.binaryops.get_settings - tab.ntype = "Binary Ops" - local extra = { } - if settings then extra.op = settings.op extra.maximize = settings.maximize end - - local obj = dalos.object(d, tab, extra) - - return obj - end, -} - -dalos.binaryops = dalosp.binaryops.create -dalos:register_obj("Binary Ops", dalos.binaryops) +dalosp.binaryops = { + operations = { + XOR = 0, + AND = 1, + OR = 2, + ADD = 3, + SUB = 4, + }, + + opnames = { + [0] = "XOR", + [1] = "AND", + [2] = "OR", + [3] = "ADD", + [4] = "SUB", + }, + + configure = function (self) + local accept, operation, maximize = iup.GetParam(self.name .. " configuration", nil, [[ +Operation: %l|xor|and|or|add|sub|{Binary operation that's going to occur} +Maximize: %b[No,Yes]{Check if you want to maximize the output} +]], self.op or 0, self.maximize and 1 or 0) + if accept then + self.extra.op = operation + self.extra.maximize = maximize == 1 + self:input_change() + end + end, + + get_settings = function (self) + return { op = self.extra.op, maximize = self.extra.maximize } + end, + + input_change = function (self, ind) + local h1 = self:get_linked_input(1) + local h2 = self:get_linked_input(2) + local op = self.extra.op or dalosp.binaryops.operations.XOR + if h1 and h2 then + self.color = cd.GREEN + local obj = { + h1 = h1, + h2 = h2, + op = op, + maximize = self.extra.maximize, + offset = 0, + size = self.extra.maximize and math.max(h1:getsize(), h2:getsize()) or math.min(h1:getsize(), h2:getsize()), + getname = function () return self.name end, + do_read = function (self, count) + self.h1:seek(self.offset) + self.h2:seek(self.offset) + + local t1, r1 = self.h1:read(count) + local t2, r2 = self.h2:read(count) + local r = self.extra.maximize and math.max(r1, r2) or math.min(r1, r2) + self.offset = self.offset + r + if r == 0 then self.got_eof = true return 0 end + local t = {} + local op + if self.op == dalosp.binaryops.operations.XOR then + op = bit.bxor + elseif self.op == dalosp.binaryops.operations.AND then + op = bit.band + elseif self.op == dalosp.binaryops.operations.OR then + op = bit.bor + elseif self.op == dalosp.binaryops.operations.ADD then + op = function(a, b) return a + b end + elseif self.op == dalosp.binaryops.operations.SUB then + op = function(a, b) return a - b end + end + for i = 0, r - 1 do + t[i] = bit.band(op(t1[i % r1], t2[i % r2]), 255) + end + return r, t + end, + } + self:set_houtput(dalos.luahandle(obj)) + self.dcanvas:draw() + else + self.color = cd.YELLOW + self:set_houtput(nil) + self.dcanvas:draw() + end + end, + + draw = function (self, cv, x, y, w, h) + dalosp.object.default_draw(self, cv, x, y, w, h) + local cx, cy = x + w / 2, cv:InvertYAxis(y + h / 2) + local op = self.extra.op or dalosp.binaryops.operations.XOR + cv:TextAlignment(cd.CENTER) + cv:Foreground(cd.BLACK) + cv:Text(cx, cy, dalosp.binaryops.opnames[op]) + end, + + create = function (d, tab, settings) + tab.ninputs = 2 + tab.noutputs = 1 + tab.otype = dalos.objtype.LUA_FILTER + tab.configure = dalosp.binaryops.configure + tab.input_change = dalosp.binaryops.input_change + tab.default_name = "Binary Ops" + tab.draw = dalosp.binaryops.draw + tab.get_settings = dalosp.binaryops.get_settings + tab.ntype = "Binary Ops" + local extra = { } + if settings then extra.op = settings.op extra.maximize = settings.maximize end + + local obj = dalos.object(d, tab, extra) + + return obj + end, +} + +dalos.binaryops = dalosp.binaryops.create +dalos:register_obj("Binary Ops", dalos.binaryops) diff --git a/dalos-buffer.lua b/dalos-buffer.lua index ecab2ed..8abcadc 100644 --- a/dalos-buffer.lua +++ b/dalos-buffer.lua @@ -1,30 +1,30 @@ -dalosp.buffer = { - input_change = function (self, ind) - local h = self:get_linked_input(1) - if h then - self.color = cd.GREEN - local b = Buffer(true) - b:copyfrom(self:get_linked_input(1)) - self:set_houtput(b) - else - self:set_houtput(nil) - self.color = cd.YELLOW - end - self.dcanvas:draw() - end, - - create = function (d, tab, settings) - tab.ninputs = 1 - tab.noutputs = 1 - tab.otype = dalos.objtype.LUA_FILTER - tab.default_name = "Buffer" - tab.input_change = dalosp.buffer.input_change - tab.ntype = "Buffer" - local obj = dalos.object(d, tab, extra) - - return obj - end, -} - -dalos.buffer = dalosp.buffer.create -dalos:register_obj("Buffer", dalos.buffer) +dalosp.buffer = { + input_change = function (self, ind) + local h = self:get_linked_input(1) + if h then + self.color = cd.GREEN + local b = Buffer(true) + b:copyfrom(self:get_linked_input(1)) + self:set_houtput(b) + else + self:set_houtput(nil) + self.color = cd.YELLOW + end + self.dcanvas:draw() + end, + + create = function (d, tab, settings) + tab.ninputs = 1 + tab.noutputs = 1 + tab.otype = dalos.objtype.LUA_FILTER + tab.default_name = "Buffer" + tab.input_change = dalosp.buffer.input_change + tab.ntype = "Buffer" + local obj = dalos.object(d, tab, extra) + + return obj + end, +} + +dalos.buffer = dalosp.buffer.create +dalos:register_obj("Buffer", dalos.buffer) diff --git a/dalos-hexview.lua b/dalos-hexview.lua index a4915f4..cfd8652 100644 --- a/dalos-hexview.lua +++ b/dalos-hexview.lua @@ -1,160 +1,160 @@ -load "iupe-hexview.lua" -load "iupe-hexview-toolbox.lua" - -dalosp.hexview = { - activate = function (self) - self.extra.hvdlg:show() - end, - - input_change = function (self, ind) - local extra = self.extra - local hv = extra.hv - local h = self:get_linked_input(ind) - if not h then - self.color = cd.YELLOW - hv:updatehandle(nil) - self.dcanvas:draw() - return - end - if not h:canread() or not h:canseek() then - self.color = cd.RED - hv:updatehandle(nil) - self.dcanvas:draw() - return - end - self.color = cd.GREEN - for i = 1, 12 do - self:set_houtput(nil, i) - self.oldcursors[i] = -1 - end - hv:updatehandle(h) - self.dcanvas:draw() - end, - - configure = function (self) - end, - - get_settings = function (self) - local hv = extra.hv - local r = { - mcursor = hv.mcursor + 0, - kcursor = hv.kcursor + 0, - markers = {}, - filecursor = hv.filecursor + 0, - nbbytes = hv.nbbytes + 0, - nblines = hv.nblines + 0, - } - for i = 1, 10 do - r.markers[i] = hv.markers[i] + 0 - end - return r - end, - - output_change = function (self, ind) - self.watchees[ind] = self.outputs[ind] and true or false - self:set_houtput(nil, ind) - self.oldcursors[ind] = -1 - self:dalos_hv_cb(self.extra.hv) - end, - - update_houtput = function (self, ind, cursor) - local h = self:get_linked_input(1) - local maxsize = h and h:getsize() or -1 - cursor = cursor + 0 - if cursor >= 0 and h and self.watchees[ind] then - if cursor < maxsize then - self:set_houtput(nil, ind) - end - local obj = { - h = h, - hvo = self, - ind = ind, - origin = cursor, - size = maxsize - cursor, - getname = function (self) return self.hvo.name .. ":" .. self.ind end, - getmodif = function (self) return self.hvo:getmodif() end, - do_seek = function (self) - self.h:seek(self.offset + self.origin) - end, - do_read = function (self, count, userdata) - return self.h:read(count, userdata) - end, - } - self:set_houtput(dalos.luahandle(obj), ind) - end - end, - - dalos_hv_cb = function (self, hv, reset) - local m - for i = 1, 10 do - m = hv.markers[i] - if m and self.oldcursors[i] ~= m then - self:update_houtput(i, m) - self.oldcursors[i] = m - end - end - - m = hv.kcursor - if m and self.oldcursors[11] ~= m then - self:update_houtput(11, m) - self.oldcursors[11] = m - end - - m = hv.mcursor - if m and self.oldcursors[12] ~= m then - self:update_houtput(12, m) - self.oldcursors[12] = m - end - end, - - create = function (d, tab, settings) - tab.otype = dalos.objtype.LUA_FILTER - tab.activate = dalosp.hexview.activate - tab.input_change = dalosp.hexview.input_change - tab.output_change = dalosp.hexview.output_change - tab.configure = dalosp.hexview.configure - tab.get_settings = dalosp.hexview.get_settings - tab.ninputs = 1 - tab.noutputs = 12 - tab.default_name = "Hexview" - tab.ntype = "Hexview" - - local extra = { } - - local obj = dalos.object(d, tab, extra) - - local hv = iupe.hexview { } - local hvtb = iupe.hexview_toolbox { hexview = hv } - local hvdlg = iup.dialog { iup.hbox { iup.frame { hv }, iup.sbox { direction = "WEST", hvtb } }, title = obj.name, size = "500x" } - - extra.hv = hv - extra.hvtb = hvtb - extra.hvdlg = hvdlg - - obj.oldcursors = { } - obj.watchees = { } - obj.update_houtput = dalosp.hexview.update_houtput - for i = 1, 12 do obj.oldcursors[i] = -1 end - - if settings then - if settings.markers then - for i = 1, 10 do - if settings.markers[i] then hv.markers[i] = settings.markers[i] end - end - end - if settings.mcursor then hv.mcursor = settings.mcursor end - if settings.kcursor then hv.kcursor = settings.kcursor end - if settings.filecursor then hv.filecursor = settings.filecursor end - if settings.nbbytes then hv.nbbytes = settings.nbbytes end - if settings.nblines then hv.nblines = settings.nblines end - end - - hv:registercb(dalosp.hexview.dalos_hv_cb, obj) - obj.dalos_hv_cb = dalosp.hexview.dalos_hv_cb - - return obj - end, -} - -dalos.hexview = dalosp.hexview.create -dalos:register_obj("Hexview", dalos.hexview) +load "iupe-hexview.lua" +load "iupe-hexview-toolbox.lua" + +dalosp.hexview = { + activate = function (self) + self.extra.hvdlg:show() + end, + + input_change = function (self, ind) + local extra = self.extra + local hv = extra.hv + local h = self:get_linked_input(ind) + if not h then + self.color = cd.YELLOW + hv:updatehandle(nil) + self.dcanvas:draw() + return + end + if not h:canread() or not h:canseek() then + self.color = cd.RED + hv:updatehandle(nil) + self.dcanvas:draw() + return + end + self.color = cd.GREEN + for i = 1, 12 do + self:set_houtput(nil, i) + self.oldcursors[i] = -1 + end + hv:updatehandle(h) + self.dcanvas:draw() + end, + + configure = function (self) + end, + + get_settings = function (self) + local hv = extra.hv + local r = { + mcursor = hv.mcursor + 0, + kcursor = hv.kcursor + 0, + markers = {}, + filecursor = hv.filecursor + 0, + nbbytes = hv.nbbytes + 0, + nblines = hv.nblines + 0, + } + for i = 1, 10 do + r.markers[i] = hv.markers[i] + 0 + end + return r + end, + + output_change = function (self, ind) + self.watchees[ind] = self.outputs[ind] and true or false + self:set_houtput(nil, ind) + self.oldcursors[ind] = -1 + self:dalos_hv_cb(self.extra.hv) + end, + + update_houtput = function (self, ind, cursor) + local h = self:get_linked_input(1) + local maxsize = h and h:getsize() or -1 + cursor = cursor + 0 + if cursor >= 0 and h and self.watchees[ind] then + if cursor < maxsize then + self:set_houtput(nil, ind) + end + local obj = { + h = h, + hvo = self, + ind = ind, + origin = cursor, + size = maxsize - cursor, + getname = function (self) return self.hvo.name .. ":" .. self.ind end, + getmodif = function (self) return self.hvo:getmodif() end, + do_seek = function (self) + self.h:seek(self.offset + self.origin) + end, + do_read = function (self, count, userdata) + return self.h:read(count, userdata) + end, + } + self:set_houtput(dalos.luahandle(obj), ind) + end + end, + + dalos_hv_cb = function (self, hv, reset) + local m + for i = 1, 10 do + m = hv.markers[i] + if m and self.oldcursors[i] ~= m then + self:update_houtput(i, m) + self.oldcursors[i] = m + end + end + + m = hv.kcursor + if m and self.oldcursors[11] ~= m then + self:update_houtput(11, m) + self.oldcursors[11] = m + end + + m = hv.mcursor + if m and self.oldcursors[12] ~= m then + self:update_houtput(12, m) + self.oldcursors[12] = m + end + end, + + create = function (d, tab, settings) + tab.otype = dalos.objtype.LUA_FILTER + tab.activate = dalosp.hexview.activate + tab.input_change = dalosp.hexview.input_change + tab.output_change = dalosp.hexview.output_change + tab.configure = dalosp.hexview.configure + tab.get_settings = dalosp.hexview.get_settings + tab.ninputs = 1 + tab.noutputs = 12 + tab.default_name = "Hexview" + tab.ntype = "Hexview" + + local extra = { } + + local obj = dalos.object(d, tab, extra) + + local hv = iupe.hexview { } + local hvtb = iupe.hexview_toolbox { hexview = hv } + local hvdlg = iup.dialog { iup.hbox { iup.frame { hv }, iup.sbox { direction = "WEST", hvtb } }, title = obj.name, size = "500x" } + + extra.hv = hv + extra.hvtb = hvtb + extra.hvdlg = hvdlg + + obj.oldcursors = { } + obj.watchees = { } + obj.update_houtput = dalosp.hexview.update_houtput + for i = 1, 12 do obj.oldcursors[i] = -1 end + + if settings then + if settings.markers then + for i = 1, 10 do + if settings.markers[i] then hv.markers[i] = settings.markers[i] end + end + end + if settings.mcursor then hv.mcursor = settings.mcursor end + if settings.kcursor then hv.kcursor = settings.kcursor end + if settings.filecursor then hv.filecursor = settings.filecursor end + if settings.nbbytes then hv.nbbytes = settings.nbbytes end + if settings.nblines then hv.nblines = settings.nblines end + end + + hv:registercb(dalosp.hexview.dalos_hv_cb, obj) + obj.dalos_hv_cb = dalosp.hexview.dalos_hv_cb + + return obj + end, +} + +dalos.hexview = dalosp.hexview.create +dalos:register_obj("Hexview", dalos.hexview) diff --git a/dalos-input.lua b/dalos-input.lua index be2cf75..625dcab 100644 --- a/dalos-input.lua +++ b/dalos-input.lua @@ -1,44 +1,44 @@ -dalosp.input = { - get_settings = function (self) - return { filename = self.extra.filename } - end, - - configure = function (self) - local dlg = iup.filedlg { - dialogtype = "Open", - file = self.extra.filename, - } - iup.Popup(dlg) - if dlg.status ~= -1 then - local s, v = pcall(Input, dlg.value) - if s then - self:set_houtput(v) - return - end - end - self:set_houtput(nil) - end, - - create = function (d, tab, settings) - tab.ninputs = 0 - tab.noutputs = 1 - tab.otype = dalos.objtype.HANDLE - tab.configure = dalosp.input.configure - tab.default_name = "Input" - tab.ntype = "Input" - tab.get_settings = dalosp.input.get_settings - local extra = { } - if settings then extra.filename = settings.filename end - local obj = dalos.object(d, tab, extra) - - if extra.filename then - local s, v = pcall(Input, extra.filename) - if s then obj:set_houtput(v) end - end - - return obj - end, -} - -dalos.input = dalosp.input.create -dalos:register_obj("Input", dalos.input) +dalosp.input = { + get_settings = function (self) + return { filename = self.extra.filename } + end, + + configure = function (self) + local dlg = iup.filedlg { + dialogtype = "Open", + file = self.extra.filename, + } + iup.Popup(dlg) + if dlg.status ~= -1 then + local s, v = pcall(Input, dlg.value) + if s then + self:set_houtput(v) + return + end + end + self:set_houtput(nil) + end, + + create = function (d, tab, settings) + tab.ninputs = 0 + tab.noutputs = 1 + tab.otype = dalos.objtype.HANDLE + tab.configure = dalosp.input.configure + tab.default_name = "Input" + tab.ntype = "Input" + tab.get_settings = dalosp.input.get_settings + local extra = { } + if settings then extra.filename = settings.filename end + local obj = dalos.object(d, tab, extra) + + if extra.filename then + local s, v = pcall(Input, extra.filename) + if s then obj:set_houtput(v) end + end + + return obj + end, +} + +dalos.input = dalosp.input.create +dalos:register_obj("Input", dalos.input) diff --git a/dalos-limiter.lua b/dalos-limiter.lua index 99bd07f..b8387e3 100644 --- a/dalos-limiter.lua +++ b/dalos-limiter.lua @@ -1,59 +1,59 @@ -dalosp.limiter = { - configure = function (self) - local accept, limit = iup.GetParam(self.name .. " configuration", nil, [[ -Limit: %i{The actual size this limiter is going to produce} -]], self.op or 0, self.maximize and 1 or 0) - if accept then - self.extra.limit = limit - self:input_change() - end - end, - - get_settings = function (self) - return { limit = self.extra.limit } - end, - - input_change = function (self, ind) - local h = self:get_linked_input(1) - if h then - self.color = cd.GREEN - local obj = { - h = h, - size = math.max(h:getsize(), self.limit), - getname = function () return self.name end, - do_read = function (self, count, userdata) - return self.h:read(count, userdata) - end, - do_seek = function (self) - self.h:seek(self.offset, SEEK_SET) - end, - } - self:set_houtput(dalos.luahandle(obj)) - self.dcanvas:draw() - else - self.color = cd.YELLOW - self:set_houtput(nil) - self.dcanvas:draw() - end - end, - - create = function (d, tab, settings) - tab.ninputs = 1 - tab.noutputs = 1 - tab.otype = dalos.objtype.LUA_FILTER - tab.configure = dalosp.limiter.configure - tab.input_change = dalosp.limiter.input_change - tab.default_name = "Limiter" - tab.ntype = "Limiter" - tab.get_settings = dalosp.limiter.get_settings - local extra = { } - if settings then extra.limit = settings.limit end - - local obj = dalos.object(d, tab, extra) - - return obj - end, -} - -dalos.limiter = dalosp.limiter.create -dalos:register_obj("Limiter", dalos.limiter) +dalosp.limiter = { + configure = function (self) + local accept, limit = iup.GetParam(self.name .. " configuration", nil, [[ +Limit: %i{The actual size this limiter is going to produce} +]], self.op or 0, self.maximize and 1 or 0) + if accept then + self.extra.limit = limit + self:input_change() + end + end, + + get_settings = function (self) + return { limit = self.extra.limit } + end, + + input_change = function (self, ind) + local h = self:get_linked_input(1) + if h then + self.color = cd.GREEN + local obj = { + h = h, + size = math.max(h:getsize(), self.limit), + getname = function () return self.name end, + do_read = function (self, count, userdata) + return self.h:read(count, userdata) + end, + do_seek = function (self) + self.h:seek(self.offset, SEEK_SET) + end, + } + self:set_houtput(dalos.luahandle(obj)) + self.dcanvas:draw() + else + self.color = cd.YELLOW + self:set_houtput(nil) + self.dcanvas:draw() + end + end, + + create = function (d, tab, settings) + tab.ninputs = 1 + tab.noutputs = 1 + tab.otype = dalos.objtype.LUA_FILTER + tab.configure = dalosp.limiter.configure + tab.input_change = dalosp.limiter.input_change + tab.default_name = "Limiter" + tab.ntype = "Limiter" + tab.get_settings = dalosp.limiter.get_settings + local extra = { } + if settings then extra.limit = settings.limit end + + local obj = dalos.object(d, tab, extra) + + return obj + end, +} + +dalos.limiter = dalosp.limiter.create +dalos:register_obj("Limiter", dalos.limiter) diff --git a/dalos-luafilter.lua b/dalos-luafilter.lua index b267142..20f4f99 100644 --- a/dalos-luafilter.lua +++ b/dalos-luafilter.lua @@ -1,138 +1,138 @@ -dalosp.luafilter = { - default_code = [[ --- available globals: - --- ninputs, noutputs: numbers - --- get_input(ind): handle --- del_output(ind): nil --- new_output(ind): nil --- set_color(c) : nil - -function activate() -end - -function read(ind, count, userdata, offset) -end - -function seek(ind, offset) -end - -function input_change(ind) -end -]], - - get_settings = function (self) - return { ninputs = self.ninputs, noutputs = self.noutputs, code = self.extra.code } - end, - - run_in_localenv = function (self, f, ...) - local localenv = self.extra.localenv - local metatable = getmetatable(_G) - if not metatable then metatable = {} end - local oldni, oldi = metatable.__newindex, metatable.__index - metatable.__newindex = function (table, key, value) --- print("Setting _G[" .. key .. "] = " .. tostring(value)) - localenv[key] = value - end - metatable.__index = function (table, key) --- print("Getting _G[" .. key .. "]") - local l = localenv[key] - if l then return localenv[key] end - return rawget(_G, key) - end - setmetatable(_G, metatable) - - if type(f) ~= "function" then f = localenv[f] end - local rets = { true } - if f then rets = { pcall(f, ...) } end - - metatable.__newindex, metatable.__index = oldni, oldi - setmetatable(_G, metatable) - - if not rets[1] then error(rets[2]) end - table.remove(rets, 1) - return unpack(rets) - end, - - load_code = function (self, code) - self.extra.localenv = { - ninputs = self.ninputs + 0, - noutputs = self.noutputs + 0, - get_input = function(ind) return self:get_linked_input(ind) end, - del_output = function(ind) self:set_houtput(nil, ind) end, - new_output = function(ind, size, name) - self:set_houtput(dalos.luahandle{ - size = size, - getname = function () - return name - end, - do_read = function (lh, count, userdata) - return self:run_in_localenv("read", ind, count, userdata, lh.offset) - end, - do_seek = function (lh) - return self:run_in_localenv("seek", ind, lh.offset) - end, - }, ind) - end, - set_color = function(c) self.color = c self:draw() end, - } - if code and code ~= "" then - local f = loadstring(code) - if f then self:run_in_localenv(f) end - end - end, - - input_change = function (self, ind) - self:run_in_localenv("input_change", ind) - end, - - configure = function (self) - local okay = false - local text = iup.text { multiline = "Yes", font = "Courier", expand = "Yes", value = self.extra.code } - local bok = iup.button { title = "Ok", action = function () okay = true return iup.CLOSE end } - local bcancel = iup.button { title = "Cancel", action = function () okay = false return iup.CLOSE end } - local dlg = iup.dialog { iup.vbox { text, iup.hbox { bok, iup.fill{}, bcancel, normalizesize = "Horizontal" } }, title = "Code for " .. self.name, size = "600x300" } - local r = dlg:popup() --- if r ~= iup.NOERROR then return end - local newcode = text.value - if newcode and okay then - self.extra.code = newcode - self:load_code(newcode) - end - end, - - activate = function (self) - self:run_in_localenv "activate" - end, - - create = function (d, tab, settings) - tab.ninputs = settings and settings.ninputs - tab.noutputs = settings and settings.noutputs - tab.otype = dalos.objtype.LUA_FILTER - tab.configure = dalosp.luafilter.configure - tab.activate = dalosp.luafilter.activate - tab.input_change = dalosp.luafilter.input_change - tab.default_name = "Lua Filter" - tab.get_settings = dalosp.luafilter.get_settings - tab.ntype = "Lua Filter" - local extra = { localenv = {} } - extra.code = settings and settings.code - if not extra.code or extra.code == "" then extra.code = dalosp.luafilter.default_code end - local s = true - while not s and not tab.ninputs or not tab.noutputs do - s, tab.ninputs, tab.noutputs = iup.GetParam("Lua Filter", nil, "Inputs number: %i\nOutputs number: %i\n", 1, 1) - end - - local obj = dalos.object(d, tab, extra) - - obj.load_code = dalosp.luafilter.load_code - obj.run_in_localenv = dalosp.luafilter.run_in_localenv - obj:load_code(extra.code) - - return obj - end, -} - -dalos.luafilter = dalosp.luafilter.create -dalos:register_obj("Lua Filter", dalos.luafilter) +dalosp.luafilter = { + default_code = [[ +-- available globals: + +-- ninputs, noutputs: numbers + +-- get_input(ind): handle +-- del_output(ind): nil +-- new_output(ind): nil +-- set_color(c) : nil + +function activate() +end + +function read(ind, count, userdata, offset) +end + +function seek(ind, offset) +end + +function input_change(ind) +end +]], + + get_settings = function (self) + return { ninputs = self.ninputs, noutputs = self.noutputs, code = self.extra.code } + end, + + run_in_localenv = function (self, f, ...) + local localenv = self.extra.localenv + local metatable = getmetatable(_G) + if not metatable then metatable = {} end + local oldni, oldi = metatable.__newindex, metatable.__index + metatable.__newindex = function (table, key, value) +-- print("Setting _G[" .. key .. "] = " .. tostring(value)) + localenv[key] = value + end + metatable.__index = function (table, key) +-- print("Getting _G[" .. key .. "]") + local l = localenv[key] + if l then return localenv[key] end + return rawget(_G, key) + end + setmetatable(_G, metatable) + + if type(f) ~= "function" then f = localenv[f] end + local rets = { true } + if f then rets = { pcall(f, ...) } end + + metatable.__newindex, metatable.__index = oldni, oldi + setmetatable(_G, metatable) + + if not rets[1] then error(rets[2]) end + table.remove(rets, 1) + return unpack(rets) + end, + + load_code = function (self, code) + self.extra.localenv = { + ninputs = self.ninputs + 0, + noutputs = self.noutputs + 0, + get_input = function(ind) return self:get_linked_input(ind) end, + del_output = function(ind) self:set_houtput(nil, ind) end, + new_output = function(ind, size, name) + self:set_houtput(dalos.luahandle{ + size = size, + getname = function () + return name + end, + do_read = function (lh, count, userdata) + return self:run_in_localenv("read", ind, count, userdata, lh.offset) + end, + do_seek = function (lh) + return self:run_in_localenv("seek", ind, lh.offset) + end, + }, ind) + end, + set_color = function(c) self.color = c self:draw() end, + } + if code and code ~= "" then + local f = loadstring(code) + if f then self:run_in_localenv(f) end + end + end, + + input_change = function (self, ind) + self:run_in_localenv("input_change", ind) + end, + + configure = function (self) + local okay = false + local text = iup.text { multiline = "Yes", font = "Courier", expand = "Yes", value = self.extra.code } + local bok = iup.button { title = "Ok", action = function () okay = true return iup.CLOSE end } + local bcancel = iup.button { title = "Cancel", action = function () okay = false return iup.CLOSE end } + local dlg = iup.dialog { iup.vbox { text, iup.hbox { bok, iup.fill{}, bcancel, normalizesize = "Horizontal" } }, title = "Code for " .. self.name, size = "600x300" } + local r = dlg:popup() +-- if r ~= iup.NOERROR then return end + local newcode = text.value + if newcode and okay then + self.extra.code = newcode + self:load_code(newcode) + end + end, + + activate = function (self) + self:run_in_localenv "activate" + end, + + create = function (d, tab, settings) + tab.ninputs = settings and settings.ninputs + tab.noutputs = settings and settings.noutputs + tab.otype = dalos.objtype.LUA_FILTER + tab.configure = dalosp.luafilter.configure + tab.activate = dalosp.luafilter.activate + tab.input_change = dalosp.luafilter.input_change + tab.default_name = "Lua Filter" + tab.get_settings = dalosp.luafilter.get_settings + tab.ntype = "Lua Filter" + local extra = { localenv = {} } + extra.code = settings and settings.code + if not extra.code or extra.code == "" then extra.code = dalosp.luafilter.default_code end + local s = true + while not s and not tab.ninputs or not tab.noutputs do + s, tab.ninputs, tab.noutputs = iup.GetParam("Lua Filter", nil, "Inputs number: %i\nOutputs number: %i\n", 1, 1) + end + + local obj = dalos.object(d, tab, extra) + + obj.load_code = dalosp.luafilter.load_code + obj.run_in_localenv = dalosp.luafilter.run_in_localenv + obj:load_code(extra.code) + + return obj + end, +} + +dalos.luafilter = dalosp.luafilter.create +dalos:register_obj("Lua Filter", dalos.luafilter) diff --git a/dalos-luahandle.lua b/dalos-luahandle.lua index 332a90e..952f856 100644 --- a/dalos-luahandle.lua +++ b/dalos-luahandle.lua @@ -1,51 +1,51 @@ -dalosp.luahandle = { - create = function (tab) - local obj = { - offset = 0, - canread = function (self) return true end, - canwrite = function (self) return false end, - canseek = function (self) return true end, - canwatch = function (self) return false end, - tell = function (self) return self.offset end, - getsize = function (self) return self.size end, - getmodif = function (self) return 0 end, - flush = function (self) return true end, - seek = function (self, offset, wheel) - if wheel == SEEK_SET then - self.offset = offset - elseif wheel == SEEK_CUR then - self.offset = self.offset + offset - elseif wheel == SEEK_END then - self.offset = self.size + offset - else - error "Unknown wheel" - end - if self.offset < 0 then self.offset = 0 end - if self.offset >= self.size then self.offset = self.size end - if self.do_seek then self:do_seek() end - return self.offset - end, - read = function (self, userdata, count) - count = math.min(count, self.size - self.offset) - - if count == 0 then - if self.got_eof then self.lh:close() end - self.got_eof = true - return 0 - end - - self.got_eof = false - - local r, t = self:do_read(count, userdata) - self.offset = self.offset + r - return r, t - end, - } - for k, v in pairs(tab) do obj[k] = v end - local newh = HandleLua(obj) - obj.lh = newh - return newh - end, -} - -dalos.luahandle = dalosp.luahandle.create +dalosp.luahandle = { + create = function (tab) + local obj = { + offset = 0, + canread = function (self) return true end, + canwrite = function (self) return false end, + canseek = function (self) return true end, + canwatch = function (self) return false end, + tell = function (self) return self.offset end, + getsize = function (self) return self.size end, + getmodif = function (self) return 0 end, + flush = function (self) return true end, + seek = function (self, offset, wheel) + if wheel == SEEK_SET then + self.offset = offset + elseif wheel == SEEK_CUR then + self.offset = self.offset + offset + elseif wheel == SEEK_END then + self.offset = self.size + offset + else + error "Unknown wheel" + end + if self.offset < 0 then self.offset = 0 end + if self.offset >= self.size then self.offset = self.size end + if self.do_seek then self:do_seek() end + return self.offset + end, + read = function (self, userdata, count) + count = math.min(count, self.size - self.offset) + + if count == 0 then + if self.got_eof then self.lh:close() end + self.got_eof = true + return 0 + end + + self.got_eof = false + + local r, t = self:do_read(count, userdata) + self.offset = self.offset + r + return r, t + end, + } + for k, v in pairs(tab) do obj[k] = v end + local newh = HandleLua(obj) + obj.lh = newh + return newh + end, +} + +dalos.luahandle = dalosp.luahandle.create diff --git a/dalos-tee.lua b/dalos-tee.lua index 5c9b26a..1d75fb2 100644 --- a/dalos-tee.lua +++ b/dalos-tee.lua @@ -1,50 +1,50 @@ -dalosp.tee = { - NTEE = 16, - - set_out = function (self, h, ind) - local name = h:getname() - local obj = { - h = h, - size = h:getsize(), - getname = function () return name end, - do_read = function (self, count, userdata) - self.h:seek(self.offset, SEEK_SET) - return self.h:read(count, userdata) - end, - } - self:set_houtput(dalos.luahandle(obj), ind) - end, - - input_change = function (self, ind) - local h = self:get_linked_input(1) - if h then - self.color = cd.GREEN - for ind = 1, 16 do self:set_out(h, ind) end - self.dcanvas:draw() - else - self.color = cd.YELLOW - for i = 1, dalosp.tee.NTEE do - self:set_houtput(nil, i) - end - self.dcanvas:draw() - end - end, - - create = function (d, tab, settings) - tab.ninputs = 1 - tab.noutputs = dalosp.tee.NTEE - tab.otype = dalos.objtype.LUA_FILTER - tab.input_change = dalosp.tee.input_change - tab.default_name = "Tee" - tab.ntype = "Tee" - - local obj = dalos.object(d, tab) - - obj.set_out = dalosp.tee.set_out - - return obj - end, -} - -dalos.tee = dalosp.tee.create -dalos:register_obj("Tee", dalos.tee) +dalosp.tee = { + NTEE = 16, + + set_out = function (self, h, ind) + local name = h:getname() + local obj = { + h = h, + size = h:getsize(), + getname = function () return name end, + do_read = function (self, count, userdata) + self.h:seek(self.offset, SEEK_SET) + return self.h:read(count, userdata) + end, + } + self:set_houtput(dalos.luahandle(obj), ind) + end, + + input_change = function (self, ind) + local h = self:get_linked_input(1) + if h then + self.color = cd.GREEN + for ind = 1, 16 do self:set_out(h, ind) end + self.dcanvas:draw() + else + self.color = cd.YELLOW + for i = 1, dalosp.tee.NTEE do + self:set_houtput(nil, i) + end + self.dcanvas:draw() + end + end, + + create = function (d, tab, settings) + tab.ninputs = 1 + tab.noutputs = dalosp.tee.NTEE + tab.otype = dalos.objtype.LUA_FILTER + tab.input_change = dalosp.tee.input_change + tab.default_name = "Tee" + tab.ntype = "Tee" + + local obj = dalos.object(d, tab) + + obj.set_out = dalosp.tee.set_out + + return obj + end, +} + +dalos.tee = dalosp.tee.create +dalos:register_obj("Tee", dalos.tee) diff --git a/dalos-textbuffer.lua b/dalos-textbuffer.lua index cd91689..a5a4f40 100644 --- a/dalos-textbuffer.lua +++ b/dalos-textbuffer.lua @@ -1,35 +1,35 @@ -dalosp.textbuffer = { - get_settings = function (self) - return { text = self.extra.text } - end, - - activate = function (self) - local text = self.extra.text or "" - text = iup.GetText(self.name, text) - if text then - self.extra.text = text - local b = Buffer(true) - b:write(text) - self:set_houtput(b) - end - end, - - create = function (d, tab, settings) - tab.ninputs = 0 - tab.noutputs = 1 - tab.otype = dalos.objtype.HANDLE - tab.activate = dalosp.textbuffer.activate - tab.default_name = "Text Buffer" - tab.ntype = "Text Buffer" - tab.get_settings = dalosp.textbuffer.get_settings - local extra = { } - if settings then extra.text = settings.text end - - local obj = dalos.object(d, tab, extra) - - return obj - end, -} - -dalos.textbuffer = dalosp.textbuffer.create -dalos:register_obj("Text Buffer", dalos.textbuffer) +dalosp.textbuffer = { + get_settings = function (self) + return { text = self.extra.text } + end, + + activate = function (self) + local text = self.extra.text or "" + text = iup.GetText(self.name, text) + if text then + self.extra.text = text + local b = Buffer(true) + b:write(text) + self:set_houtput(b) + end + end, + + create = function (d, tab, settings) + tab.ninputs = 0 + tab.noutputs = 1 + tab.otype = dalos.objtype.HANDLE + tab.activate = dalosp.textbuffer.activate + tab.default_name = "Text Buffer" + tab.ntype = "Text Buffer" + tab.get_settings = dalosp.textbuffer.get_settings + local extra = { } + if settings then extra.text = settings.text end + + local obj = dalos.object(d, tab, extra) + + return obj + end, +} + +dalos.textbuffer = dalosp.textbuffer.create +dalos:register_obj("Text Buffer", dalos.textbuffer) -- cgit v1.2.3 From dc22c96581d74e353b722edd903ee1c5eeb67414 Mon Sep 17 00:00:00 2001 From: Pixel Date: Thu, 24 Dec 2009 19:24:55 +0100 Subject: Adding more hexview configuration items, and adding the ability of the hexviewer to display read limits, somehow. --- dalos-hexview.lua | 49 +++++++++++++++++++++++++++++++++++++++++++------ dalos-luahandle.lua | 1 + iupe-hexview.lua | 23 ++++++++++++++++++----- 3 files changed, 62 insertions(+), 11 deletions(-) (limited to 'dalos-luahandle.lua') diff --git a/dalos-hexview.lua b/dalos-hexview.lua index 79f2a08..0ee8a8c 100644 --- a/dalos-hexview.lua +++ b/dalos-hexview.lua @@ -32,17 +32,38 @@ dalosp.hexview = { end, configure = function (self) + local s, newname, gsx, gsy, dgsx, dgsy, dl, ml = + iup.GetParam(self.name .. " properties", nil, [[ +Name: %s +Gridsize X: %i +Gridsize Y: %i +Default gridsize X: %i +Default gridsize Y: %i +Lines: %i +Marker lengths: %b +]], + self.name, self.extra.hv.gridsize.x, self.extra.hv.gridsize.y, iupep.hexview.gridsize.x, iupep.hexview.gridsize.y, + self.extra.hv.displaylines, self.extra.hv.showmarkerslengths and 1 or 0) + if not s then return end + self.name = newname + self.extra.hv.gridsize.x = gsx + self.extra.hv.gridsize.y = gsy + iupep.hexview.gridsize.x = dgsx + iupep.hexview.gridsize.y = dgsy + self.extra.hv.displaylines = dl + self.extra.hv.showmarkerslengths = ml == 1 end, get_settings = function (self) - local hv = extra.hv + local hv = self.extra.hv local r = { mcursor = hv.mcursor + 0, kcursor = hv.kcursor + 0, markers = {}, filecursor = hv.filecursor + 0, - nbbytes = hv.nbbytes + 0, - nblines = hv.nblines + 0, + displaylines = hv.displaylines + 0, + gridsize = hv.gridsize, + showmarkerslengths = hv.showmarkerslengths, } for i = 1, 10 do r.markers[i] = hv.markers[i] + 0 @@ -51,6 +72,7 @@ dalosp.hexview = { end, output_change = function (self, ind) + self.extra.hv.markerslengths[ind] = 0 self.watchees[ind] = self.outputs[ind] and true or false self:set_houtput(nil, ind) self.oldcursors[ind] = -1 @@ -58,13 +80,16 @@ dalosp.hexview = { end, update_houtput = function (self, ind, cursor) + local hv = self.extra.hv local h = self:get_linked_input(1) local maxsize = h and h:getsize() or -1 cursor = cursor + 0 if cursor >= 0 and h and self.watchees[ind] then - if cursor < maxsize then + if cursor >= maxsize then self:set_houtput(nil, ind) + return end + h:seek(cursor) local obj = { h = h, hvo = self, @@ -75,10 +100,21 @@ dalosp.hexview = { getmodif = function (self) return self.hvo:getmodif() end, do_seek = function (self) self.h:seek(self.offset + self.origin) + self:post_read() end, do_read = function (self, count, userdata) return self.h:read(count, userdata) end, + post_read = function (self, count) + local ol = hv.markerslengths[ind] + local nl = self.offset + if nl > ol then + hv.markerslengths[ind] = nl + if hv.showmarkerslengths then + hv:draw() + end + end + end, } self:set_houtput(dalos.luahandle(obj), ind) end @@ -145,8 +181,9 @@ dalosp.hexview = { if settings.mcursor then hv.mcursor = settings.mcursor end if settings.kcursor then hv.kcursor = settings.kcursor end if settings.filecursor then hv.filecursor = settings.filecursor end - if settings.nbbytes then hv.nbbytes = settings.nbbytes end - if settings.nblines then hv.nblines = settings.nblines end + if settings.displaylines then hv.displaylines = settings.displaylines end + if settings.gridsize then hv.gridsize.x, hv.gridsize.y = settings.gridsize.x, settings.gridsize.y end + if settings.showmarkerslengths then hv.showmarkerslengths = settings.showmarkerslengths end end hv:registercb(dalosp.hexview.dalos_hv_cb, obj) diff --git a/dalos-luahandle.lua b/dalos-luahandle.lua index 952f856..d3615fc 100644 --- a/dalos-luahandle.lua +++ b/dalos-luahandle.lua @@ -38,6 +38,7 @@ dalosp.luahandle = { local r, t = self:do_read(count, userdata) self.offset = self.offset + r + if self.post_read then self:post_read(r) end return r, t end, } diff --git a/iupe-hexview.lua b/iupe-hexview.lua index 1d5f9e3..fb02b68 100644 --- a/iupe-hexview.lua +++ b/iupe-hexview.lua @@ -34,6 +34,8 @@ markercolors = { } iupep.hexview = { + gridsize = { x = 8, y = 14 }, + printgrid = function (self, msg, y, x) local cvdb = self.cvdb if not x then x = self.textcursor.x end @@ -116,15 +118,24 @@ iupep.hexview = { self:colorgrid(cursorcolors.GREEN, 2, kline, kcolumn * 3 + 10) self:colorgrid(cursorcolors.GREEN, 1, kline, kcolumn + 12 + columns * 3) - local marker + local marker, len, mlen for i = 0, 10 do marker = self.markers[i] or -1 marker = marker - filecursor - if marker >= 0 and marker < nbbytes then + mlen = self.markerslengths[i] + if marker >= 0 and self.showmarkerslengths and mlen and mlen > 0 then + len = math.min(mlen, nbbytes - marker) + elseif marker >= 0 and marker < nbbytes then + len = 1 + else + len = 0 + end + for j = 1, len do mline = math.floor(marker / columns) mcolumn = marker % columns self:colorgrid(markercolors[i], 2, mline, mcolumn * 3 + 10) self:colorgrid(markercolors[i], 1, mline, mcolumn + 12 + columns * 3) + marker = marker + 1 end end @@ -522,7 +533,7 @@ iupep.hexview = { end, updategridsize = function (self, gridsize) - self.gridsize = gridsize or { x = 8, y = 14 } + self.gridsize = gridsize or iupep.hexview.gridsize self:resize_cb(self.width, self.height) end, @@ -575,9 +586,11 @@ iupep.hexview = { r.filesize = handle and handle:getsize() or 0 r.mcursor = -1 r.markers = {} - r.displaylines = -1 + r.markerslengths = {} + r.showmarkerslengths = false + r.displaylines = 0 for i = 0, 10 do r.markers[i] = -1 end - r.gridsize = gridsize or { x = 8, y = 14 } + r.gridsize = gridsize or iupep.hexview.gridsize r.textcursor = { x = 0, y = 0 } return r end, -- cgit v1.2.3