mirror of
https://github.com/Llewellynvdm/conky.git
synced 2024-06-02 07:20:47 +00:00
Support for old config syntax (Optional)
This commit is contained in:
parent
8bdaeaa09a
commit
5d28bed7db
|
@ -89,6 +89,8 @@ endif(OS_LINUX)
|
|||
|
||||
option(BUILD_BUILTIN_CONFIG "Enable builtin default configuration" true)
|
||||
|
||||
option(BUILD_OLD_CONFIG "Enable support for the old syntax of configurations" true)
|
||||
|
||||
option(BUILD_MATH "Enable math support" true)
|
||||
|
||||
option(BUILD_NCURSES "Enable ncurses support" true)
|
||||
|
|
|
@ -80,6 +80,8 @@
|
|||
|
||||
#cmakedefine BUILD_BUILTIN_CONFIG 1
|
||||
|
||||
#cmakedefine BUILD_OLD_CONFIG 1
|
||||
|
||||
#cmakedefine BUILD_NCURSES 1
|
||||
#cmakedefine LEAKFREE_NCURSES 1
|
||||
|
||||
|
|
106
convert.lua
106
convert.lua
|
@ -1,105 +1,3 @@
|
|||
#! /usr/bin/lua
|
||||
|
||||
local function quote(s)
|
||||
if not s:find("[\n']") then
|
||||
return "'" .. s .. "'";
|
||||
end;
|
||||
local q = '';
|
||||
while s:find(']' .. q .. ']', 1, true) do
|
||||
q = q .. '=';
|
||||
end;
|
||||
return string.format('[%s[%s]%s]', q, s, q);
|
||||
end;
|
||||
|
||||
local bool_setting = {
|
||||
background = true, disable_auto_reload = true, double_buffer = true, draw_borders = true,
|
||||
draw_graph_borders = true, draw_outline = true, draw_shades = true, extra_newline = true,
|
||||
format_human_readable = true, no_buffers = true, out_to_console = true,
|
||||
out_to_ncurses = true, out_to_stderr = true, out_to_x = true, override_utf8_locale = true,
|
||||
own_window = true, own_window_argb_visual = true, own_window_transparent = true,
|
||||
short_units = true, show_graph_range = true, show_graph_scale = true,
|
||||
times_in_seconds = true, top_cpu_separate = true, uppercase = true, use_xft = true
|
||||
};
|
||||
|
||||
local num_setting = {
|
||||
border_inner_margin = true, border_outer_margin = true, border_width = true,
|
||||
cpu_avg_samples = true, diskio_avg_samples = true, gap_x = true, gap_y = true,
|
||||
imlib_cache_flush_interval = true, imlib_cache_size = true,
|
||||
max_port_monitor_connections = true, max_text_width = true, max_user_text = true,
|
||||
maximum_width = true, mpd_port = true, music_player_interval = true, net_avg_samples = true,
|
||||
own_window_argb_value = true, pad_percents = true, stippled_borders = true,
|
||||
text_buffer_size = true, top_name_width = true, total_run_times = true,
|
||||
update_interval = true, update_interval_on_battery = true, xftalpha = true
|
||||
};
|
||||
|
||||
local split_setting = {
|
||||
default_bar_size = true, default_gauge_size = true, default_graph_size = true,
|
||||
minimum_size = true
|
||||
};
|
||||
|
||||
local colour_setting = {
|
||||
color0 = true, color1 = true, color2 = true, color3 = true, color4 = true, color5 = true,
|
||||
color6 = true, color7 = true, color8 = true, color9 = true, default_color = true,
|
||||
default_outline_color = true, default_shade_color = true, own_window_colour = true
|
||||
};
|
||||
|
||||
local function alignment_map(value)
|
||||
local map = { m = 'middle', t = 'top', b = 'bottom', r = 'right', l = 'left' };
|
||||
if map[value] == nil then
|
||||
return value;
|
||||
else
|
||||
return map[value];
|
||||
end;
|
||||
end;
|
||||
|
||||
local function handle(setting, value)
|
||||
setting = setting:lower();
|
||||
if setting == '' then
|
||||
return '';
|
||||
end;
|
||||
if split_setting[setting] then
|
||||
local x, y = value:match('^(%S+)%s*(%S*)$');
|
||||
local ret = setting:gsub('_size', '_width = ') .. x .. ',';
|
||||
if y ~= '' then
|
||||
ret = ret .. ' ' .. setting:gsub('_size', '_height = ') .. y .. ',';
|
||||
end;
|
||||
return '\t' .. ret;
|
||||
end;
|
||||
if bool_setting[setting] then
|
||||
value = value:lower();
|
||||
if value == 'yes' or value == 'true' or value == '1' or value == '' then
|
||||
value = 'true';
|
||||
else
|
||||
value = 'false';
|
||||
end;
|
||||
elseif not num_setting[setting] then
|
||||
if setting == 'alignment' and value:len() == 2 then
|
||||
value = alignment_map(value:sub(1,1)) .. '_' .. alignment_map(value:sub(2,2));
|
||||
elseif colour_setting[setting] and value:match('^[0-9a-fA-F]+$') then
|
||||
value = '#' .. value;
|
||||
elseif setting == 'xftfont' then
|
||||
setting = 'font';
|
||||
end;
|
||||
value = quote(value);
|
||||
end;
|
||||
return '\t' .. setting .. ' = ' .. value .. ',';
|
||||
end;
|
||||
|
||||
local function convert(s)
|
||||
local setting, comment = s:match('^([^#]*)#?(.*)\n$');
|
||||
if comment ~= '' then
|
||||
comment = '--' .. comment;
|
||||
end;
|
||||
comment = comment .. '\n';
|
||||
return handle(setting:match('^%s*(%S*)%s*(.-)%s*$')) .. comment;
|
||||
end;
|
||||
|
||||
local input = io.input();
|
||||
local output = io.output();
|
||||
|
||||
local config = input:read('*a');
|
||||
|
||||
local settings, text = config:match('^(.-)TEXT\n(.*)$');
|
||||
|
||||
output:write('conky.config = {\n', settings:gsub('.-\n', convert), '};\n\n');
|
||||
output:write('conky.text = \n', quote(text), ';\n');
|
||||
assert(loadfile("convertluafuncs"))()
|
||||
print(convertconfigfile())
|
||||
|
|
102
convertluafuncs
Normal file
102
convertluafuncs
Normal file
|
@ -0,0 +1,102 @@
|
|||
local function quote(s)
|
||||
if not s:find("[\n']") then
|
||||
return "'" .. s .. "'";
|
||||
end;
|
||||
local q = '';
|
||||
while s:find(']' .. q .. ']', 1, true) do
|
||||
q = q .. '=';
|
||||
end;
|
||||
return string.format('[%s[%s]%s]', q, s, q);
|
||||
end;
|
||||
|
||||
local bool_setting = {
|
||||
background = true, disable_auto_reload = true, double_buffer = true, draw_borders = true,
|
||||
draw_graph_borders = true, draw_outline = true, draw_shades = true, extra_newline = true,
|
||||
format_human_readable = true, no_buffers = true, out_to_console = true,
|
||||
out_to_ncurses = true, out_to_stderr = true, out_to_x = true, override_utf8_locale = true,
|
||||
own_window = true, own_window_argb_visual = true, own_window_transparent = true,
|
||||
short_units = true, show_graph_range = true, show_graph_scale = true,
|
||||
times_in_seconds = true, top_cpu_separate = true, uppercase = true, use_xft = true
|
||||
};
|
||||
|
||||
local num_setting = {
|
||||
border_inner_margin = true, border_outer_margin = true, border_width = true,
|
||||
cpu_avg_samples = true, diskio_avg_samples = true, gap_x = true, gap_y = true,
|
||||
imlib_cache_flush_interval = true, imlib_cache_size = true,
|
||||
max_port_monitor_connections = true, max_text_width = true, max_user_text = true,
|
||||
maximum_width = true, mpd_port = true, music_player_interval = true, net_avg_samples = true,
|
||||
own_window_argb_value = true, pad_percents = true, stippled_borders = true,
|
||||
text_buffer_size = true, top_name_width = true, total_run_times = true,
|
||||
update_interval = true, update_interval_on_battery = true, xftalpha = true
|
||||
};
|
||||
|
||||
local split_setting = {
|
||||
default_bar_size = true, default_gauge_size = true, default_graph_size = true,
|
||||
minimum_size = true
|
||||
};
|
||||
|
||||
local colour_setting = {
|
||||
color0 = true, color1 = true, color2 = true, color3 = true, color4 = true, color5 = true,
|
||||
color6 = true, color7 = true, color8 = true, color9 = true, default_color = true,
|
||||
default_outline_color = true, default_shade_color = true, own_window_colour = true
|
||||
};
|
||||
|
||||
local function alignment_map(value)
|
||||
local map = { m = 'middle', t = 'top', b = 'bottom', r = 'right', l = 'left' };
|
||||
if map[value] == nil then
|
||||
return value;
|
||||
else
|
||||
return map[value];
|
||||
end;
|
||||
end;
|
||||
|
||||
local function handle(setting, value)
|
||||
setting = setting:lower();
|
||||
if setting == '' then
|
||||
return '';
|
||||
end;
|
||||
if split_setting[setting] then
|
||||
local x, y = value:match('^(%S+)%s*(%S*)$');
|
||||
local ret = setting:gsub('_size', '_width = ') .. x .. ',';
|
||||
if y ~= '' then
|
||||
ret = ret .. ' ' .. setting:gsub('_size', '_height = ') .. y .. ',';
|
||||
end;
|
||||
return '\t' .. ret;
|
||||
end;
|
||||
if bool_setting[setting] then
|
||||
value = value:lower();
|
||||
if value == 'yes' or value == 'true' or value == '1' or value == '' then
|
||||
value = 'true';
|
||||
else
|
||||
value = 'false';
|
||||
end;
|
||||
elseif not num_setting[setting] then
|
||||
if setting == 'alignment' and value:len() == 2 then
|
||||
value = alignment_map(value:sub(1,1)) .. '_' .. alignment_map(value:sub(2,2));
|
||||
elseif colour_setting[setting] and value:match('^[0-9a-fA-F]+$') then
|
||||
value = '#' .. value;
|
||||
elseif setting == 'xftfont' then
|
||||
setting = 'font';
|
||||
end;
|
||||
value = quote(value);
|
||||
end;
|
||||
return '\t' .. setting .. ' = ' .. value .. ',';
|
||||
end;
|
||||
|
||||
local function convert(s)
|
||||
local setting, comment = s:match('^([^#]*)#?(.*)\n$');
|
||||
if comment ~= '' then
|
||||
comment = '--' .. comment;
|
||||
end;
|
||||
comment = comment .. '\n';
|
||||
return handle(setting:match('^%s*(%S*)%s*(.-)%s*$')) .. comment;
|
||||
end;
|
||||
|
||||
local function convertconfig(oldconfig)
|
||||
local settings, text = oldconfig:match('^(.-)TEXT\n(.*)$');
|
||||
return 'conky.config = {\n' .. settings:gsub('.-\n', convert) .. '};\n\n' .. 'conky.text = \n' .. quote(text) .. ';\n'
|
||||
end;
|
||||
|
||||
function convertconfigfile(filename)
|
||||
return convertconfig(io.input(filename):read('*a'))
|
||||
end
|
|
@ -35,3 +35,12 @@ if(BUILD_BUILTIN_CONFIG)
|
|||
set_source_files_properties(defconfig.h PROPERTIES GENERATED TRUE)
|
||||
endif(BUILD_BUILTIN_CONFIG)
|
||||
|
||||
if(BUILD_OLD_CONFIG)
|
||||
add_custom_command(OUTPUT convertconf.h COMMAND
|
||||
${CMAKE_SOURCE_DIR}/text2c.sh ${CMAKE_SOURCE_DIR}/convertluafuncs
|
||||
convertconf.h convertconf DEPENDS ${CMAKE_SOURCE_DIR}/convertluafuncs
|
||||
)
|
||||
add_custom_target(convertconf ALL DEPENDS convertconf.h)
|
||||
set_source_files_properties(convertconf.h PROPERTIES GENERATED TRUE)
|
||||
endif(BUILD_OLD_CONFIG)
|
||||
|
||||
|
|
|
@ -21,10 +21,10 @@
|
|||
#
|
||||
|
||||
include_directories(${conky_includes})
|
||||
if(BUILD_BUILTIN_CONFIG)
|
||||
if(BUILD_BUILTIN_CONFIG OR BUILD_OLD_CONFIG)
|
||||
# include config output dir
|
||||
include_directories(${CMAKE_BINARY_DIR}/data)
|
||||
endif(BUILD_BUILTIN_CONFIG)
|
||||
endif(BUILD_BUILTIN_CONFIG OR BUILD_OLD_CONFIG)
|
||||
|
||||
# ensure build.h and config.h aren't in the way
|
||||
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/config.h)
|
||||
|
|
33
src/conky.cc
33
src/conky.cc
|
@ -128,6 +128,10 @@
|
|||
namespace { const char builtin_config_magic[] = "==builtin=="; }
|
||||
#endif
|
||||
|
||||
#ifdef BUILD_OLD_CONFIG
|
||||
#include "convertconf.h"
|
||||
#endif
|
||||
|
||||
#ifndef S_ISSOCK
|
||||
#define S_ISSOCK(x) ((x & S_IFMT) == S_IFSOCK)
|
||||
#endif
|
||||
|
@ -308,6 +312,9 @@ static void print_version(void)
|
|||
#ifdef BUILD_BUILTIN_CONFIG
|
||||
<< _(" * builtin default configuration\n")
|
||||
#endif /* BUILD_BUILTIN_CONFIG */
|
||||
#ifdef BUILD_OLD_CONFIG
|
||||
<< _(" * old configuration syntax\n")
|
||||
#endif /* BUILD_OLD_CONFIG */
|
||||
#ifdef BUILD_IMLIB2
|
||||
<< " * Imlib2\n"
|
||||
#endif /* BUILD_IMLIB2 */
|
||||
|
@ -2642,7 +2649,31 @@ void load_config_file()
|
|||
#endif
|
||||
l.loadfile(current_config.c_str());
|
||||
}
|
||||
catch(lua::syntax_error &e) { throw conky::critical_error(_("syntax error in configfile")); }
|
||||
catch(lua::syntax_error &e) {
|
||||
#define THROW_CONF_SYNTAX_ERR throw conky::critical_error(_("syntax error in configfile"))
|
||||
#ifdef BUILD_OLD_CONFIG
|
||||
l.loadstring(convertconf);
|
||||
l.call(0, 0);
|
||||
#ifdef BUILD_BUILTIN_CONFIG
|
||||
if(current_config == builtin_config_magic) {
|
||||
l.getglobal("convertconfig");
|
||||
l.pushstring(defconfig);
|
||||
} else {
|
||||
#endif /* BUILD_BUILTIN_CONFIG */
|
||||
l.getglobal("convertconfigfile");
|
||||
l.pushstring(current_config.c_str());
|
||||
#ifdef BUILD_BUILTIN_CONFIG
|
||||
}
|
||||
#endif /* BUILD_BUILTIN_CONFIG */
|
||||
l.call(1, 1);
|
||||
try {
|
||||
l.loadstring(l.tostring(-1).c_str());
|
||||
}
|
||||
catch(lua::syntax_error &e) { THROW_CONF_SYNTAX_ERR; }
|
||||
#else
|
||||
THROW_CONF_SYNTAX_ERR;
|
||||
#endif /* BUILD_OLD_CONFIG */
|
||||
}
|
||||
catch(lua::file_error &e) { throw conky::critical_error(_("no configfile given")); }
|
||||
l.call(0, 0);
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user