-- dictionary module -- creates tables with dictionary entries from shared\shared_dict*.h files -- performs usb transfer when making dictionary call and returns device data -- create the module's table local dict = {} -- file constants local USB_IN = 0x80 --device to host local USB_OUT = 0x00 --host to device -- read all the C shared_dict*.h files and create tables with all values -- This isn't 'Nam there are rules! -- dictionary #define that start with underscore are skipped this skips over header and special cases -- currently only finds lowercase #define statements (seems C does too!) -- multiline comments /* comment */ are not permitted, will throw error! -- #define statements must have a numeric value such as: #define FOO 4 -- #define without number will error like this: "#define FOO BAR" or "#define FOO BAR - 100" is bad too! -- fills passed in table with keys and values to be used for making usb dictionary calls -- accepts decimal or hex when 0x00 format -- trailing underscores are trimmed, this allows firmware macro defines to match dictionary defines -- sets "opcode_rlen" when RL= (ie RL = 5) in the comments following the opcode local function create_dict_tables( table, file ) assert(io.input(file, "r")) local count = 0 local define = 0 local define_end = 0 local slash = 0 local line local comment for line in io.lines() do count = count + 1 comment = nil --needs cleared for each pass --search for multiline comment opening, starting at index 1, plain search = true if string.find( line, "/*", 1, true) then print("\n\n!!!ERROR!!!\nmultiline comment found line number", count) print("while parsing file:", file, "\nonly inline comments are permitted!!!\n") error("multiline comments not allowed in dictionary files!") end define, define_end = string.find( line, "#define") if define then slash = string.find(line, "//") --check for comment following define, if present cut out comment if slash and (slash>define) then --store comment contents for later parsing comment = string.sub(line, slash, -1) line = string.sub(line, 1, slash-1 ) end --check for comment prior to define, skip if present if not (slash and (slash