mirror of
https://github.com/neovim/neovim.git
synced 2025-10-26 12:27:24 +00:00
Use lua generator in place of ex_cmds_defs header trick
Closes #788 Fixes #379 Ref #549
This commit is contained in:
87
scripts/genex_cmds.lua
Normal file
87
scripts/genex_cmds.lua
Normal file
@@ -0,0 +1,87 @@
|
||||
local nvimsrcdir = arg[1]
|
||||
local includedir = arg[2]
|
||||
local autodir = arg[3]
|
||||
|
||||
if nvimsrcdir == '--help' then
|
||||
print ([[
|
||||
Usage:
|
||||
lua genex_cmds.lua src/nvim build/include build/src/nvim/auto
|
||||
|
||||
Will generate files build/include/ex_cmds_enum.generated.h with cmdidx_T
|
||||
enum and build/src/nvim/auto/ex_cmds_defs.generated.h with main Ex commands
|
||||
definitions.
|
||||
]])
|
||||
os.exit(0)
|
||||
end
|
||||
|
||||
package.path = nvimsrcdir .. '/?.lua;' .. package.path
|
||||
|
||||
local enumfname = includedir .. '/ex_cmds_enum.generated.h'
|
||||
local defsfname = autodir .. '/ex_cmds_defs.generated.h'
|
||||
|
||||
local enumfile = io.open(enumfname, 'w')
|
||||
local defsfile = io.open(defsfname, 'w')
|
||||
|
||||
local defs = require('ex_cmds')
|
||||
local lastchar = nil
|
||||
|
||||
local i
|
||||
local cmd
|
||||
local first = true
|
||||
local prevfirstchar = nil
|
||||
|
||||
local byte_a = string.byte('a')
|
||||
local byte_z = string.byte('z')
|
||||
|
||||
local cmdidxs = string.format([[
|
||||
static cmdidx_T cmdidxs[%u] = {
|
||||
]], byte_z - byte_a + 2)
|
||||
|
||||
enumfile:write([[
|
||||
typedef enum CMD_index {
|
||||
]])
|
||||
defsfile:write([[
|
||||
static CommandDefinition cmdnames[] = {
|
||||
]])
|
||||
for i, cmd in ipairs(defs) do
|
||||
local enumname = cmd.enum or ('CMD_' .. cmd.command)
|
||||
firstchar = string.byte(cmd.command)
|
||||
if firstchar ~= prevfirstchar then
|
||||
if (not prevfirstchar
|
||||
or (byte_a <= firstchar and firstchar <= byte_z)
|
||||
or (byte_a <= prevfirstchar and prevfirstchar <= byte_z)) then
|
||||
if not first then
|
||||
cmdidxs = cmdidxs .. ',\n'
|
||||
end
|
||||
cmdidxs = cmdidxs .. ' ' .. enumname
|
||||
end
|
||||
prevfirstchar = firstchar
|
||||
end
|
||||
if first then
|
||||
first = false
|
||||
else
|
||||
defsfile:write(',\n')
|
||||
end
|
||||
enumfile:write(' ' .. enumname .. ',\n')
|
||||
defsfile:write(string.format([[
|
||||
[%s] = {
|
||||
.cmd_name = (char_u *) "%s",
|
||||
.cmd_func = &%s,
|
||||
.cmd_argt = %uL
|
||||
}]], enumname, cmd.command, cmd.func, cmd.flags))
|
||||
end
|
||||
defsfile:write([[
|
||||
|
||||
};
|
||||
]])
|
||||
enumfile:write([[
|
||||
CMD_SIZE,
|
||||
CMD_USER = -1,
|
||||
CMD_USER_BUF = -2
|
||||
} cmdidx_T;
|
||||
]])
|
||||
cmdidxs = cmdidxs .. [[
|
||||
|
||||
};
|
||||
]]
|
||||
defsfile:write(cmdidxs)
|
||||
Reference in New Issue
Block a user