summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--dalos-hexview.lua153
-rw-r--r--dalos.lua153
2 files changed, 154 insertions, 152 deletions
diff --git a/dalos-hexview.lua b/dalos-hexview.lua
new file mode 100644
index 0000000..7e46ed6
--- /dev/null
+++ b/dalos-hexview.lua
@@ -0,0 +1,153 @@
+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,
+
+ output_change = function (self, ind)
+ self.watchees[ind] = self.outputs[ind] and true or false
+ end,
+
+ update_houtput = function (self, ind, cursor)
+ local h = self:get_linked_input(1)
+ if h and self.watchees[ind] then
+ local obj = {
+ h = h,
+ hvo = self,
+ ind = ind,
+ origin = cursor,
+ offset = 0,
+ size = h:getsize() - cursor,
+ canread = function (self) return true end,
+ canwrite = function (self) return false end,
+ canseek = function (self) return true end,
+ canwatch = function (self) return self.h:canwatch() end,
+ getname = function (self) return self.hvo.name .. ":" .. self.ind end,
+ tell = function (self) return self.offset end,
+ getsize = function (self) return self.size end,
+ getmodif = function (self) return self.hvo:getmodif() end,
+ flush = function (self) return self.hvo:flush() 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
+ self.h:seek(self.offset + self.origin)
+ 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 = self.h:read(count, userdata)
+ self.offset = self.offset + r
+ if r == 0 then self.got_eof = true end
+ return r
+ end,
+ }
+ local newh = HandleLua(obj)
+ obj.lh = newh
+ self:set_houtput(newh, ind)
+ end
+ end,
+
+ dalos_hv_cb = function (self, hv, reset)
+ local m
+ for i = 1, 10 do
+ m = hv.markers[i]
+ if 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
+ self:update_houtput(11, m)
+ self.oldcursors[11] = m
+ end
+
+ m = hv.mcursor
+ if self.oldcursors[12] ~= m then
+ self:update_houtput(12, m)
+ self.oldcursors[12] = m
+ end
+ end,
+
+ create = function (d, tab)
+ 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.ninputs = 1
+ tab.noutputs = 12
+ tab.default_name = "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 }
+
+ 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
+
+ hv:registercb(dalosp.hexview.dalos_hv_cb, obj)
+
+ return obj
+ end,
+}
+
+dalos.hexview = dalosp.hexview.create
+dalos:register_obj("Hexview", dalos.hexview)
diff --git a/dalos.lua b/dalos.lua
index ff55f20..fe94973 100644
--- a/dalos.lua
+++ b/dalos.lua
@@ -3,8 +3,6 @@ loadmodule "luahandle"
loadmodule "lualibs"
load "iupe-dbuffer.lua"
-load "iupe-hexview.lua"
-load "iupe-hexview-toolbox.lua"
load "iupe-tview.lua"
if not dalosp then dalosp = {} end
@@ -664,156 +662,7 @@ dalos.objtype = {
----------------
-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,
-
- output_change = function (self, ind)
- self.watchees[ind] = self.outputs[ind] and true or false
- end,
-
- update_houtput = function (self, ind, cursor)
- local h = self:get_linked_input(1)
- if h and self.watchees[ind] then
- local obj = {
- h = h,
- hvo = self,
- ind = ind,
- origin = cursor,
- offset = 0,
- size = h:getsize() - cursor,
- canread = function (self) return true end,
- canwrite = function (self) return false end,
- canseek = function (self) return true end,
- canwatch = function (self) return self.h:canwatch() end,
- getname = function (self) return self.hvo.name .. ":" .. self.ind end,
- tell = function (self) return self.offset end,
- getsize = function (self) return self.size end,
- getmodif = function (self) return self.hvo:getmodif() end,
- flush = function (self) return self.hvo:flush() 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
- self.h:seek(self.offset + self.origin)
- 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 = self.h:read(count, userdata)
- self.offset = self.offset + r
- if r == 0 then self.got_eof = true end
- return r
- end,
- }
- local newh = HandleLua(obj)
- obj.lh = newh
- self:set_houtput(newh, ind)
- end
- end,
-
- dalos_hv_cb = function (self, hv, reset)
- local m
- for i = 1, 10 do
- m = hv.markers[i]
- if 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
- self:update_houtput(11, m)
- self.oldcursors[11] = m
- end
-
- m = hv.mcursor
- if self.oldcursors[12] ~= m then
- self:update_houtput(12, m)
- self.oldcursors[12] = m
- end
- end,
-
- create = function (d, tab)
- 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.ninputs = 1
- tab.noutputs = 12
- tab.default_name = "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 }
-
- 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
-
- hv:registercb(dalosp.hexview.dalos_hv_cb, obj)
-
- return obj
- end,
-}
-
-dalos.hexview = dalosp.hexview.create
-dalos:register_obj("Hexview", dalos.hexview)
+load "dalos-hexview.lua"
----------------