diff options
Diffstat (limited to 'util/update_keys.lua')
-rw-r--r-- | util/update_keys.lua | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/util/update_keys.lua b/util/update_keys.lua new file mode 100644 index 0000000..5edab2c --- /dev/null +++ b/util/update_keys.lua | |||
@@ -0,0 +1,48 @@ | |||
1 | local file = ...; | ||
2 | local keymodes = {}; | ||
3 | local failed = false; | ||
4 | |||
5 | local function process_line(line) | ||
6 | if string.match(line, '^%s*$') ~= nil then | ||
7 | return line; | ||
8 | end; | ||
9 | local comment = string.match(line, '^%s*[#!](.*)$'); | ||
10 | if comment ~= nil then | ||
11 | return '--' .. comment; | ||
12 | end; | ||
13 | |||
14 | local mode, key, cmd = string.match(line, '^%s*(%a%w*):%s*([^:]-)%s*:(.*)$'); | ||
15 | if key == nil then | ||
16 | key, cmd = string.match(line, '^%s*([^:]*):(.*)$'); | ||
17 | end; | ||
18 | |||
19 | if mode == nil or mode == 'default' then | ||
20 | mode = 'default_keymode'; | ||
21 | else | ||
22 | keymodes[mode] = true; | ||
23 | end; | ||
24 | |||
25 | if key ~= nil then | ||
26 | return string.format('%s[%q] = %q', mode, key, cmd); | ||
27 | else | ||
28 | failed = true; | ||
29 | return '-- FBCV16 ' .. line; | ||
30 | end; | ||
31 | end; | ||
32 | |||
33 | file = string.gsub(file, '[^\n]*', process_line); | ||
34 | |||
35 | local decls = ''; | ||
36 | for k, v in pairs(keymodes) do | ||
37 | decls = decls .. k .. ' = newKeyMode();\n'; | ||
38 | end; | ||
39 | |||
40 | if failed == true then | ||
41 | decls = [[ | ||
42 | --fluxbox-update_configs could not convert some of the lines into the new format. | ||
43 | --These lines are marked with FBCV16 and you will have to convert them yourself. | ||
44 | |||
45 | ]] .. decls; | ||
46 | end; | ||
47 | |||
48 | return decls .. '\n' .. file; | ||