From 45451301f8b33626f6799061d2815c1d5080d3aa Mon Sep 17 00:00:00 2001 From: Pavel Labath Date: Tue, 16 Aug 2011 20:09:06 +0200 Subject: fluxbox-update_configs: automatically update keys file --- util/Makefile.am | 13 +++++++----- util/fluxbox-update_configs.cc | 19 ++++++++++++++++- util/update_keys.lua | 48 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 74 insertions(+), 6 deletions(-) create mode 100644 util/update_keys.lua diff --git a/util/Makefile.am b/util/Makefile.am index f5495e9..c2bbe74 100644 --- a/util/Makefile.am +++ b/util/Makefile.am @@ -6,7 +6,7 @@ bin_PROGRAMS= fbsetroot fluxbox-update_configs fluxbox-remote fbsetroot_SOURCES= fbsetroot.cc fbsetroot.hh fbsetroot_LDADD=../src/FbRootWindow.o ../src/FbAtoms.o \ ../src/FbTk/libFbTk.a -fluxbox_update_configs_SOURCES= fluxbox-update_configs.cc +fluxbox_update_configs_SOURCES= fluxbox-update_configs.cc update_keys-lua.cc fluxbox_update_configs_LDADD= ../src/defaults.o ../src/Resources.o \ ../src/FbTk/libFbTk.a ../libs/lua/src/liblua.a fluxbox_remote_SOURCES= fluxbox-remote.cc @@ -49,11 +49,14 @@ fluxbox-generate_menu: fluxbox-generate_menu.in > fluxbox-generate_menu -chmod 755 fluxbox-generate_menu -../src/FbRootWindow.o: - cd ../src && ${MAKE} FbRootWindow.o -../src/FbAtoms.o: - cd ../src && ${MAKE} FbAtoms.o ../src/defaults.o: cd ../src && ${MAKE} defaults.o ../src/Resources.o: cd ../src && ${MAKE} Resources.o + +%.luac: %.lua Makefile + $(top_builddir)/libs/lua/src/luac -o $@ $< + + +%-lua.cc: %.luac $(top_srcdir)/luatoc.sh Makefile + $(top_srcdir)/luatoc.sh $< $@ $(<:.luac=) diff --git a/util/fluxbox-update_configs.cc b/util/fluxbox-update_configs.cc index 233bdbb..883d864 100644 --- a/util/fluxbox-update_configs.cc +++ b/util/fluxbox-update_configs.cc @@ -724,6 +724,22 @@ update_move_slitlist_to_init_file(std::auto_ptr& rm, rc_slitlist->push_back(line); } +void update_keys_for_lua(std::auto_ptr& rm, FbTk::Lua &l) { + extern const char update_keys[]; + extern const unsigned int update_keys_size; + + l.checkstack(2); + lua::stack_sentry s(l); + + FbTk::StringResource &rc_keyfile = rm->getResource("keyFile"); + + l.loadstring(update_keys, update_keys_size); + l.pushstring(read_file(FbTk::StringUtil::expandFilename(*rc_keyfile))); + l.call(1, 1); + *rc_keyfile = string(*rc_keyfile) + ".lua"; + write_file(FbTk::StringUtil::expandFilename(*rc_keyfile), l.tostring(-1)); +} + /*------------------------------------------------------------------*\ \*------------------------------------------------------------------*/ @@ -747,7 +763,8 @@ const Update UPDATES[] = { { 12, update_keys_for_activetab }, { 13, update_limit_nextwindow_to_current_workspace }, { 14, update_lua_resource_manager }, - { 15, update_move_slitlist_to_init_file } + { 15, update_move_slitlist_to_init_file }, + { 16, update_keys_for_lua } }; /*------------------------------------------------------------------*\ 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 @@ +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; -- cgit v0.11.2