1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142
|
#!/usr/bin/env lua
--[[
Script to create the "glspi_sci.h" file.
Requires:
"Scintilla.h" and "Scintilla.iface" in the current directory.
"lua" and "cpp" somewhere in your $PATH
--]]
local cmdvals={}
cpp=io.popen("cpp -dM Scintilla.h")
for line in cpp:lines()
do
if line:match("^#define%s+SCI_") then
table.insert(cmdvals,{
name=line:gsub("^#define%s+([^ ]+).*", "%1"),
value=line:gsub("^#define%s+SCI_[^%s]*%s*","")
})
end
end
function get_cmd_name(id)
for i,rec in ipairs(cmdvals)
do
if ( rec.value == id ) then
return rec.name:sub(5,-1)
end
end
return nil
end
function translate_typename(tn)
if (tn=="position") or (tn=="colour") or (tn=="keymod") then
return "int"
else
return tn
end
end
local alltypes={}
function add_type(tn)
for i,v in ipairs(alltypes)
do
if (v==tn) then return end
end
table.insert(alltypes,tn)
end
local entries={}
io.input("Scintilla.iface")
for line in io.lines()
do
if line:match("^fun%s")
or line:match("^get%s")
or line:match("^set%s")
then
rvtype=line:gsub("...%s+([^%s]+).*", "%1")
rvtype=translate_typename(rvtype)
arglist=line:gsub("^.*%(", "(")
wparam=arglist:gsub("%(%s*([^,]-),.*","%1")
if (wparam~="") then
wparam=wparam:gsub("%s.*$","")
wparam=translate_typename(wparam)
else
wparam="void"
end
lparam=arglist:gsub("^[^,]*,%s*([^)]-)%).*","%1")
if (lparam~="") then
lparam=lparam:gsub("%s.*","")
lparam=translate_typename(lparam)
else
lparam="void"
end
cmdid=line:gsub("^.*=([0-9]+)%(.*", "%1")
cmdname=get_cmd_name(cmdid)
if cmdname then
add_type(rvtype)
add_type(wparam)
add_type(lparam)
table.insert(entries,
"\t{\""..cmdname.."\", SLT_"..rvtype:upper()..", SCI_"..cmdname..", SLT_"..wparam:upper()..", SLT_"..lparam:upper().."},")
end
end
end
print(
[[
/*
******************* !!! IMPORTANT !!! ***************************
*
* This is a machine generated file, do not edit by hand!
* If you need to modify this file, see "geanylua/util/mkiface.lua"
*
*******************************************************************
*
*/
]]
)
print("typedef enum {")
for i,v in ipairs(alltypes)
do
print("\tSLT_"..v:upper()..", ")
end
print("\tSLT_LAST\n} GlspiType;\n\n")
print("typedef struct _SciCmdHashEntry {")
print("\tconst gchar *name;")
print("\tGlspiType result;")
print("\tgint msgid;")
print("\tGlspiType wparam;")
print("\tGlspiType lparam;")
print("} SciCmdHashEntry;")
print("\n")
print("static SciCmdHashEntry sci_cmd_hash_entries[] = {")
for i,v in ipairs(entries)
do
print(v)
end
print("\t{NULL, SLT_LAST, 0, SLT_LAST, SLT_LAST}")
print("};")
|