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)
69 local input = "dumpdata.bin"
70 local output = os.date("%Y-%m-%d_%H%M%S.html");
71 for o, a in getopt.getopt(args, 'i:o:h') do
72 if o == "h" then return help() end
73 if o == "i" then input = a end
74 if o == "o" then output = a end
76 -- Validate the parameters
78 local infile = io.open(input, "r")
80 return ("Could not read file ", input)
82 --lokal skel = require("skel")
83 local dumpdata = readdump(infile)
86 local js_code = convert_to_js(dumpdata)
88 local skel = require("htmlskel")
89 html = skel.getHTML(js_code);
91 local outfile = io.open(output, "w")
92 if outfile == nil then
93 return oops("Could not write to file ", output)
97 print(("Wrote a HTML dump to the file %s"):format(output))
102 In the future, we may implement so that scripts are invoked directly
103 into a 'main' function, instead of being executed blindly. For future
104 compatibility, I have done so, but I invoke my main from here.