summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPixel <pixel@nobis-crew.org>2009-12-27 02:22:14 +0100
committerPixel <pixel@nobis-crew.org>2009-12-27 02:22:14 +0100
commit551cae6794486d30bee8333c54b1586edb2913ed (patch)
treea1b6c93e385126bfb2f94f09c03a84836468e983
parentef0404604e36a45ea950439c2396eb0ea3b5bdf9 (diff)
Structures are now displaying, at least partially.
-rw-r--r--dalos-struct.lua160
1 files changed, 144 insertions, 16 deletions
diff --git a/dalos-struct.lua b/dalos-struct.lua
index 0835b7d..d3e0080 100644
--- a/dalos-struct.lua
+++ b/dalos-struct.lua
@@ -50,7 +50,7 @@ dalosp.struct = {
},
get_settings = function (self)
- return { self.extra.entries }
+ return { entries = self.extra.entries }
end,
configure = function (self)
@@ -58,10 +58,11 @@ dalosp.struct = {
end,
activate = function (self)
- self.actv_dlg:show()
+ self.act_dlg:show()
end,
- input_change = function (self)
+ input_change = function (self, ind)
+ if ind == 1 then self:update_values() end
end,
offset = function (self, lin)
@@ -69,6 +70,72 @@ dalosp.struct = {
return cache[lin]
end,
+ read_value = function (self, h, t, flags, size)
+ local v
+
+ if t == "int8" then
+ v = h:readU8()
+ return v > 127 and v - 256 or v
+ elseif t == "uint8" then
+ return h:readU8()
+ elseif t == "int16" then
+ elseif t == "uint16" then
+ return h:readU16()
+ elseif t == "int32" then
+ elseif t == "uint32" then
+ return h:readU32()
+ elseif t == "int64" then
+ elseif t == "uint64" then
+ elseif t == "float" then
+ return h:readFloat()
+ elseif t == "double" then
+ return h:readDouble()
+ elseif t == "asciiz" then
+ v = ""
+ local b
+ repeat
+ b = h:readU8()
+ if b ~= 0 then v = v .. string.char(b) end
+ until b == 0
+ return v
+ elseif t == "nascii" then
+ v = ""
+ for i = 1, size do
+ v = v .. string.char(h:readU8())
+ end
+ return v
+ end
+
+ return 0
+ end,
+
+ update_values = function (self)
+ local h = self:get_linked_input(1)
+ self.extra.values = {}
+ self.extra.values_by_name = {}
+ if h and h:getsize() >= self.extra.size then
+ h:seek(0)
+ local v, s, t
+ for e, f in ipairs(self.extra.entries) do
+ s = f.size
+ if not tonumber(s) then
+ s = self.extra.values_by_name[s]
+ end
+ t = dalosp.struct.types[f.type]
+ if t == "asciiz" or t == "nascii" or s == 1 then
+ v = self:read_value(h, t, f.flags, s)
+ else
+ v = {}
+ for i = 1, f.size do
+ v[i] = self:read_value(h, t, f.flags, s)
+ end
+ end
+ self.extra.values[e] = v
+ self.extra.values_by_name[f.name] = v
+ end
+ end
+ end,
+
cacheoffset = function (self)
local entries = self.extra.entries
self.extra.cache = {}
@@ -93,6 +160,10 @@ dalosp.struct = {
if self.cfg_dlg then
self.cfg_dlg.mx.redraw = "C10"
self.cfg_dlg.lsize.title = offset
+ self:update_values()
+ self.act_dlg.mx.numlin = #entries
+ self.act_dlg.mx.numlin_visible = #entries
+ self.act_dlg.mx.redraw = "All"
end
end,
@@ -140,7 +211,8 @@ dalosp.struct = {
table.insert(entries, lin - 1, old_lin)
self:cacheoffset()
local mx = self.cfg_dlg.mx
- mx.redraw = "All"
+ mx.redraw = "L" .. (lin - 1)
+ mx.redraw = "L" .. lin
end,
line_down = function (self, lin)
@@ -151,7 +223,8 @@ dalosp.struct = {
table.insert(entries, lin + 1, old_lin)
self:cacheoffset()
local mx = self.cfg_dlg.mx
- mx.redraw = "All"
+ mx.redraw = "L" .. lin
+ mx.redraw = "L" .. (lin + 1)
end,
gen_template = function (self)
@@ -163,6 +236,24 @@ dalosp.struct = {
self:cacheoffset()
end,
+ get_field_value = function (self, lin)
+ local v = self.extra.values[lin]
+ if type(v) == "table" then
+ local r = nil
+ for k, sv in ipairs(v) do
+ if not r then
+ r = sv
+ else
+ r = r .. ", " .. sv
+ end
+ end
+
+ return "[" .. (r or " ") .."]"
+ else
+ return v or ""
+ end
+ end,
+
cfg_draw_cb = function (self, lin, col, x1, x2, y1, y2, cv)
if col == 1 then
dalosp.struct.images.plus:cdCanvasPutImageRect(cv, x1 + 3, y2 + 5, 12, 12, 0, 12, 0, 12)
@@ -193,6 +284,8 @@ dalosp.struct = {
self.struct:line_up(lin)
elseif col == 4 then
self.struct:line_down(lin)
+ elseif col == 11 then
+ -- edit flags
end
end,
@@ -210,6 +303,8 @@ dalosp.struct = {
return "Value Check"
elseif col == 10 then
return "Offset"
+ elseif col == 11 then
+ return "Flags"
end
return ""
end
@@ -223,7 +318,11 @@ dalosp.struct = {
elseif col == 7 then
return entries[lin].size
elseif col == 10 then
- return self.struct:offset(lin)
+ local off = self.struct:offset(lin)
+ if off == -1 then return "" end
+ return off
+ elseif col == 11 then
+ -- flags
end
return ""
@@ -240,13 +339,14 @@ dalosp.struct = {
elseif col == 7 then
local nnewval = tonumber(newval)
if nnewval then newval = nnewval end
- entries[lin].size = nnewval
+ entries[lin].size = newval
self.struct:cacheoffset()
elseif col == 8 then
-- enum
elseif col == 9 then
-- value check
end
+ self.struct.act_dlg.mx.redraw = "All"
end,
cfg_dropcheck_cb = function (self, lin, col)
@@ -257,13 +357,14 @@ dalosp.struct = {
if mode == 1 then
return (col >= 5 and col <= 7) and iup.DEFAULT or iup.IGNORE
else
+ local newval = self.value
if update == 0 then return iup.DEFAULT end
if col == 5 then
- -- lookup duplicates in names
+ if not self.struct:isunique(newval) then return iup.IGNORE end
elseif col == 6 then
-- do a check on the dropdown ? I don't think so
elseif col == 7 then
- -- do a check on the size; can be the name of another field
+ if not tonumber(newval) and self.struct:isunique(newval) then return iup.IGNORE end
elseif col == 8 then
-- enum
elseif col == 9 then
@@ -285,9 +386,26 @@ dalosp.struct = {
return iup.DEFAULT
end,
+ act_value_cb = function (self, lin, col)
+ if lin == 0 then if col == 1 then return "Field" elseif col == 2 return "Value" end end
+ if col == 0 then return nil end
+
+ local entry = self.struct.extra.entries[lin]
+
+ if col == 1 then
+ return entry.name
+ else
+ return self.struct:get_field_value(lin)
+ end
+ end,
+
+ act_click_cb = function (self, lin, col, status)
+
+ end,
+
create = function (d, tab, settings)
- tab.ninputs = 1
- tab.noutputs = 1
+ tab.ninputs = 2
+ tab.noutputs = 2
tab.otype = dalos.objtype.LUA_VIEWER
tab.configure = dalosp.struct.configure
tab.activate = dalosp.struct.activate
@@ -315,12 +433,15 @@ dalosp.struct = {
obj.getunique = dalosp.struct.getunique
obj.gen_template = dalosp.struct.gen_template
obj.apply_template = dalosp.struct.apply_template
+ obj.get_field_value = dalosp.struct.get_field_value
+ obj.update_values = dalosp.struct.update_values
+ obj.read_value = dalosp.struct.read_value
obj:cacheoffset()
local cmx = iup.matrix {
- numcol = 10,
- numcol_visible = 10,
+ numcol = 11,
+ numcol_visible = 11,
usetitlesize = "Yes",
rasterwidth1 = 12,
rasterwidth2 = 12,
@@ -332,8 +453,10 @@ dalosp.struct = {
rasterwidth8 = 80,
rasterwidth9 = 120,
rasterwidth10 = 40,
+ rasterwidth11 = 60,
resizematrix = "Yes",
readonly = "No",
+ struct = obj,
draw_cb = dalosp.struct.cfg_draw_cb,
value_cb = dalosp.struct.cfg_value_cb,
value_edit_cb = dalosp.struct.cfg_value_edit_cb,
@@ -341,7 +464,6 @@ dalosp.struct = {
drop_cb = dalosp.struct.cfg_drop_cb,
edition_cb = dalosp.struct.cfg_edition_cb,
click_cb = dalosp.struct.cfg_click_cb,
- struct = obj,
}
local amx = iup.matrix {
numcol = 2,
@@ -349,7 +471,11 @@ dalosp.struct = {
usetitlesize = "Yes",
rasterwidth1 = 120,
rasterwidth2 = 120,
+ readonly = "Yes",
+ resizematrix = "Yes",
struct = obj,
+ value_cb = dalosp.struct.act_value_cb,
+ click_cb = dalosp.struct.act_click_cb,
}
local lsize = iup.label { title = "0", expand = "Horizontal", }
@@ -382,13 +508,15 @@ dalosp.struct = {
},
},
- size = "450x220",
+ size = "500x220",
mx = cmx,
lsize = lsize
}
- obj.actv_dlg = iup.dialog {
+ obj.act_dlg = iup.dialog {
amx,
+ size = "250x120",
+ mx = amx,
}
return obj