~ubuntu-branches/debian/squeeze/geany-plugins/squeeze

« back to all changes in this revision

Viewing changes to geanylua/util/mkiface.lua

  • Committer: Bazaar Package Importer
  • Author(s): Chow Loong Jin
  • Date: 2009-07-10 22:56:41 UTC
  • Revision ID: james.westby@ubuntu.com-20090710225641-xc1126t7pq0jmpos
Tags: upstream-0.17.1
ImportĀ upstreamĀ versionĀ 0.17.1

Show diffs side-by-side

added added

removed removed

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