aboutsummaryrefslogtreecommitdiff
path: root/util/update_keys.lua
blob: 5edab2cae42ee658c6e037e85245f5ac9605a93d (plain)
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
local file = ...;
local keymodes = {};
local failed = false;

local function process_line(line)
    if string.match(line, '^%s*$') ~= nil then
        return line;
    end;
    local comment = string.match(line, '^%s*[#!](.*)$');
    if comment ~= nil then
        return '--' .. comment;
    end;

    local mode, key, cmd = string.match(line, '^%s*(%a%w*):%s*([^:]-)%s*:(.*)$');
    if key == nil then
        key, cmd = string.match(line, '^%s*([^:]*):(.*)$');
    end;

    if mode == nil or mode == 'default' then
        mode = 'default_keymode';
    else
        keymodes[mode] = true;
    end;

    if key ~= nil then
        return string.format('%s[%q] = %q', mode, key, cmd);
    else
        failed = true;
        return '-- FBCV16 ' .. line;
    end;
end;

file = string.gsub(file, '[^\n]*', process_line);

local decls = '';
for k, v in pairs(keymodes) do
    decls = decls .. k .. ' = newKeyMode();\n';
end;

if failed == true then
    decls = [[
--fluxbox-update_configs could not convert some of the lines into the new format.
--These lines are marked with FBCV16 and you will have to convert them yourself.

]] .. decls;
end;

return decls .. '\n' .. file;