1 -- The getopt-functionality is loaded from pm3/getopt.lua
2 -- Have a look there for further details
3 getopt = require('getopt')
6 example = "script run 14araw -x 6000F57b"
7 author = "Martin Holst Swende"
8 usage = "script run htmldump [-f <file>]"
10 This script takes a dumpfile and produces a html based dump, which is a
11 bit more easily analyzed.
15 -i <file> Specifies the dump-file (input). If omitted, 'dumpdata.bin' is used
16 -o <filename> Speciies the output file. If omitted, <curtime>.html is used.
20 -------------------------------
22 -------------------------------
25 -- A debug printout-function
32 -- This is only meant to be used when errors occur
42 print("Example usage")
46 local function readdump(infile)
47 t = infile:read("*all")
48 --print(string.len(t))
50 local len,hex = bin.unpack(("H%d"):format(len),t)
54 local function convert_to_js(hexdata)
55 if string.len(hexdata) % 32 ~= 0 then
56 return oops(("Bad data, length should be a multiple of 32 (was %d)"):format(string.len(hexdata)))
59 for i = 1, string.len(hexdata),32 do
60 js = js .."'" ..string.sub(hexdata,i,i+31).."',\n"
66 local function main(args)
68 local input = "dumpdata.bin"
69 local output = os.date("%Y-%m-%d_%H%M%S.html");
70 for o, a in getopt.getopt(args, 'i:o:h') do
71 if o == "h" then return help() end
72 if o == "i" then input = a end
73 if o == "o" then output = a end
75 -- Validate the parameters
77 local infile = io.open(input, "r")
79 return oops("Could not read file ", input)
81 --lokal skel = require("skel")
82 local dumpdata = readdump(infile)
85 local js_code = convert_to_js(dumpdata)
87 local skel = require("htmlskel")
88 html = skel.getHTML(js_code);
90 local outfile = io.open(output, "w")
91 if outfile == nil then
92 return oops("Could not write to file ", output)
96 print(("Wrote a HTML dump to the file %s"):format(output))
101 In the future, we may implement so that scripts are invoked directly
102 into a 'main' function, instead of being executed blindly. For future
103 compatibility, I have done so, but I invoke my main from here.