From a64e9f89506106710022e0128180f76d21d5a6f7 Mon Sep 17 00:00:00 2001 From: Toni Spets Date: Fri, 15 May 2009 21:08:51 +0300 Subject: [PATCH 01/12] Lua scripting support, initial commit --- configure.ac.in | 19 ++++++ doc/config_settings.xml | 7 +++ doc/variables.xml | 20 ++++++ src/Makefile.am | 6 ++ src/conky.c | 65 ++++++++++++++++++++ src/conky.h | 4 ++ src/llua.c | 132 ++++++++++++++++++++++++++++++++++++++++ src/llua.h | 14 +++++ src/text_object.h | 4 ++ 9 files changed, 271 insertions(+) create mode 100644 src/llua.c create mode 100644 src/llua.h diff --git a/configure.ac.in b/configure.ac.in index 2deabd9f..2398c103 100644 --- a/configure.ac.in +++ b/configure.ac.in @@ -324,6 +324,24 @@ if test x$want_rss = xyes; then AC_DEFINE(RSS, 1, [Define if you want rss support]) fi +dnl +dnl Lua +dnl + +AC_ARG_ENABLE([lua], + AC_HELP_STRING([--enable-lua], [enable if you want Lua scripting support @<:@default=no@:>@]), + [want_lua="$enableval"], [want_lua=no]) +# +AM_CONDITIONAL(BUILD_LUA, test x$want_lua = xyes) +if test x$want_lua = xyes; then + PKG_CHECK_MODULES(LUA, lua >= 5.1, [ ],[ + PKG_CHECK_MODULES(LUA51, lua5.1 >= 5.1, [ ]) + ]) + CFLAGS="$CFLAGS $LUA_CFLAGS $LUA51_CFLAGS" + LIBS="$LIBS $LUA_LIBS $LUA51_LIBS" + AC_DEFINE(HAVE_LUA, 1, [Define if you want Lua scripting support]) +fi + dnl dnl Wireless extensions dnl @@ -781,6 +799,7 @@ $PACKAGE $VERSION configured successfully: hddtemp: $want_hddtemp portmon: $want_portmon RSS: $want_rss + Lua: $want_lua wireless: $want_wlan IBM: $want_ibm nvidia: $want_nvidia diff --git a/doc/config_settings.xml b/doc/config_settings.xml index 7a2f80de..6818d83f 100644 --- a/doc/config_settings.xml +++ b/doc/config_settings.xml @@ -513,6 +513,13 @@ + + + + Loads the Lua scripts separated by spaces. + + + diff --git a/doc/variables.xml b/doc/variables.xml index c2162935..6b49936b 100644 --- a/doc/variables.xml +++ b/doc/variables.xml @@ -2341,6 +2341,26 @@ + + + + + + + Executes a Lua function with given parameters and prints the result value. + + + + + + + + + + Executes a Lua function with given parameters and prints a bar. Expects result value to be an integer between 0 and 100. + + + diff --git a/src/Makefile.am b/src/Makefile.am index 61f202df..689ea800 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -107,6 +107,10 @@ if BUILD_RSS rss = rss.c prss.c prss.h endif +if BUILD_LUA +lua = llua.c llua.h +endif + if BUILD_NVIDIA nvidia = nvidia.c nvidia.h endif @@ -141,6 +145,7 @@ conky_SOURCES = \ $(port_monitors) \ $(eve) \ $(rss) \ + $(lua) \ $(solaris) \ timed_thread.c \ timed_thread.h \ @@ -189,6 +194,7 @@ EXTRA_DIST = \ libtcp-portmon.c \ libtcp-portmon.h \ rss.h \ + llua.h \ mail.h \ mixer.h \ moc.h \ diff --git a/src/conky.c b/src/conky.c index e8cc412d..b81b7d88 100644 --- a/src/conky.c +++ b/src/conky.c @@ -196,6 +196,9 @@ static void print_version(void) #ifdef RSS " * RSS\n" #endif /* RSS */ +#ifdef HAVE_LUA + " * Lua\n" +#endif /* HAVE_LUA */ #ifdef HAVE_IWLIB " * wireless\n" #endif /* HAVE_IWLIB */ @@ -848,6 +851,14 @@ static void free_text_objects(struct text_object *root) free(data.rss.uri); free(data.rss.action); break; +#endif +#ifdef HAVE_LUA + case OBJ_lua: + llua_close(); + break; + case OBJ_lua_bar: + llua_close(); + break; #endif case OBJ_pre_exec: break; @@ -2568,6 +2579,28 @@ static struct text_object *construct_text_object(const char *s, "[act_par] [spaces in front]"); } #endif +#ifdef HAVE_LUA + END OBJ(lua, 0) + if(arg) { + obj->data.s = strndup(arg, text_buffer_size); + } else { + CRIT_ERR("lua needs arguments: [function parameters]"); + } + +#ifdef X11 + END OBJ(lua_bar, 0) + if(arg) { + arg = scan_bar(arg, &obj->a, &obj->b); + if(arg) { + obj->data.s = strndup(arg, text_buffer_size); + } else { + CRIT_ERR("lua_bar needs arguments: , [function parameters]"); + } + } else { + CRIT_ERR("lua_bar needs arguments: , [function parameters]"); + } +#endif +#endif #ifdef HDDTEMP END OBJ(hddtemp, 0) if (scan_hddtemp(arg, &obj->data.hddtemp.dev, @@ -4147,6 +4180,24 @@ static void generate_text_internal(char *p, int p_max_size, } } #endif +#ifdef HAVE_LUA + OBJ(lua) { + char *str = llua_getstring(obj->data.s); + if(str) { + snprintf(p, p_max_size, "%s", str); + free(str); + } + } + +#ifdef X11 + OBJ(lua_bar) { + int per; + if(llua_getpercent(strdup(obj->data.s), &per)) { + new_bar(p, obj->a, obj->b, (per/100.0 * 255)); + } + } +#endif +#endif #ifdef HDDTEMP OBJ(hddtemp) { char *endptr, unit; @@ -7653,6 +7704,20 @@ static void load_config_file(const char *f) CONF_ERR; } } +#ifdef HAVE_LUA + CONF("lua_load") { + llua_init(); + if(value) { + char *ptr = strtok(value, " "); + while(ptr) { + llua_load(ptr); + ptr = strtok(NULL, " "); + } + } else { + CONF_ERR; + } + } +#endif CONF("color0"){} CONF("color1"){} diff --git a/src/conky.h b/src/conky.h index b12952ec..a8206444 100644 --- a/src/conky.h +++ b/src/conky.h @@ -90,6 +90,10 @@ char *strndup(const char *s, size_t n); #include "rss.h" #endif +#ifdef HAVE_LUA +#include "llua.h" +#endif + #ifdef TCP_PORT_MONITOR #include "tcp-portmon.h" #endif diff --git a/src/llua.c b/src/llua.c new file mode 100644 index 00000000..1d9070c2 --- /dev/null +++ b/src/llua.c @@ -0,0 +1,132 @@ +/* Conky, a system monitor, based on torsmo + * + * Any original torsmo code is licensed under the BSD license + * + * All code written since the fork of torsmo is licensed under the GPL + * + * Please see COPYING for details + * + * Copyright (c) 2007 Toni Spets + * Copyright (c) 2005-2009 Brenden Matthews, Philip Kovacs, et. al. + * (see AUTHORS) + * All rights reserved. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +#include "conky.h" + +lua_State *lua_L = NULL; + +void llua_init() +{ + if(lua_L) return; + lua_L = lua_open(); + luaL_openlibs(lua_L); +} + +void llua_load(const char *script) +{ + int error; + error = luaL_loadfile(lua_L, script); + if(error) { + fprintf(stderr, "llua_load: %s\n", lua_tostring(lua_L, -1)); + lua_pop(lua_L, 1); + } else { + lua_pcall(lua_L, 0, 0, 0); + } +} + +char *llua_getstring(const char *args) +{ + char *ret = NULL; + char *tmp = strdup(args); + char func[64]; + int parcount = 0; + + if(!lua_L) return NULL; + + char *ptr = strtok(tmp, " "); + if(!ptr) return NULL; /* function name missing */ + snprintf(func, 64, "conky_%s", ptr); + + lua_getglobal(lua_L, func); + + ptr = strtok(NULL, " "); + while(ptr) { + lua_pushstring(lua_L, ptr); + ptr = strtok(NULL, " "); + parcount++; + } + + if(lua_pcall(lua_L, parcount, 1, 0) != 0) { + fprintf(stderr, "llua: function %s execution failed: %s\n", func, lua_tostring(lua_L, -1)); + lua_pop(lua_L, -1); + } else { + if(!lua_isstring(lua_L, -1)) { + fprintf(stderr, "llua: function %s didn't return a string, result discarded\n", func); + } else { + ret = strdup((char *)lua_tostring(lua_L, -1)); + lua_pop(lua_L, 1); + } + } + + free(tmp); + + return ret; +} + +int llua_getpercent(const char *args, int *per) +{ + char func[64]; + char *tmp = strdup(args); + int parcount = 0; + + if(!lua_L) return 0; + + char *ptr = strtok(tmp, " "); + if(!ptr) return 0; /* function name missing */ + snprintf(func, 64, "conky_%s", ptr); + + lua_getglobal(lua_L, func); + + ptr = strtok(NULL, " "); + while(ptr) { + lua_pushstring(lua_L, ptr); + ptr = strtok(NULL, " "); + parcount++; + } + free(tmp); + + if(lua_pcall(lua_L, parcount, 1, 0) != 0) { + fprintf(stderr, "llua: function %s execution failed: %s\n", func, lua_tostring(lua_L, -1)); + lua_pop(lua_L, -1); + } else { + if(!lua_isnumber(lua_L, -1)) { + fprintf(stderr, "llua: function %s didn't return a number (percent), result discarded\n", func); + } else { + *per = lua_tonumber(lua_L, -1); + lua_pop(lua_L, 1); + return 1; + } + } + return 0; +} + +void llua_close() +{ + if(!lua_L) return; + lua_close(lua_L); + lua_L = NULL; +} diff --git a/src/llua.h b/src/llua.h new file mode 100644 index 00000000..596f2b4d --- /dev/null +++ b/src/llua.h @@ -0,0 +1,14 @@ +#ifndef LUA_H_ +#define LUA_H_ + +#include +#include +#include + +void llua_init(); +void llua_load(const char *script); +char *llua_getstring(const char *args); +int llua_getpercent(const char *args, int *per); +void llua_close(); + +#endif /* LUA_H_*/ diff --git a/src/text_object.h b/src/text_object.h index fe915a28..a4f13bcb 100644 --- a/src/text_object.h +++ b/src/text_object.h @@ -380,6 +380,10 @@ enum text_object_type { #ifdef RSS OBJ_rss, #endif +#ifdef HAVE_LUA + OBJ_lua, + OBJ_lua_bar, +#endif #ifdef TCP_PORT_MONITOR OBJ_tcp_portmon, #endif From 90c9ac27238e8e531a822cdff352d6fd50b98b40 Mon Sep 17 00:00:00 2001 From: Toni Spets Date: Fri, 15 May 2009 21:48:11 +0300 Subject: [PATCH 02/12] Fix old copyright year Change all fprintf's to ERR() --- src/llua.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/llua.c b/src/llua.c index 1d9070c2..cbc6864f 100644 --- a/src/llua.c +++ b/src/llua.c @@ -6,7 +6,7 @@ * * Please see COPYING for details * - * Copyright (c) 2007 Toni Spets + * Copyright (c) 2009 Toni Spets * Copyright (c) 2005-2009 Brenden Matthews, Philip Kovacs, et. al. * (see AUTHORS) * All rights reserved. @@ -26,6 +26,7 @@ */ #include "conky.h" +#include "logging.h" lua_State *lua_L = NULL; @@ -41,7 +42,7 @@ void llua_load(const char *script) int error; error = luaL_loadfile(lua_L, script); if(error) { - fprintf(stderr, "llua_load: %s\n", lua_tostring(lua_L, -1)); + ERR("llua_load: %s\n", lua_tostring(lua_L, -1)); lua_pop(lua_L, 1); } else { lua_pcall(lua_L, 0, 0, 0); @@ -71,11 +72,11 @@ char *llua_getstring(const char *args) } if(lua_pcall(lua_L, parcount, 1, 0) != 0) { - fprintf(stderr, "llua: function %s execution failed: %s\n", func, lua_tostring(lua_L, -1)); + ERR("llua_getstring: function %s execution failed: %s\n", func, lua_tostring(lua_L, -1)); lua_pop(lua_L, -1); } else { if(!lua_isstring(lua_L, -1)) { - fprintf(stderr, "llua: function %s didn't return a string, result discarded\n", func); + ERR("llua_getstring: function %s didn't return a string, result discarded\n", func); } else { ret = strdup((char *)lua_tostring(lua_L, -1)); lua_pop(lua_L, 1); @@ -110,11 +111,11 @@ int llua_getpercent(const char *args, int *per) free(tmp); if(lua_pcall(lua_L, parcount, 1, 0) != 0) { - fprintf(stderr, "llua: function %s execution failed: %s\n", func, lua_tostring(lua_L, -1)); + ERR("llua_getpercent: function %s execution failed: %s\n", func, lua_tostring(lua_L, -1)); lua_pop(lua_L, -1); } else { if(!lua_isnumber(lua_L, -1)) { - fprintf(stderr, "llua: function %s didn't return a number (percent), result discarded\n", func); + ERR("llua_getpercent: function %s didn't return a number (percent), result discarded\n", func); } else { *per = lua_tonumber(lua_L, -1); lua_pop(lua_L, 1); From b5934e5f696fa9fdf251cb714bcbf4f76ed9ce93 Mon Sep 17 00:00:00 2001 From: Toni Spets Date: Fri, 15 May 2009 23:01:08 +0300 Subject: [PATCH 03/12] Remove new lines from ERR messages --- src/llua.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/llua.c b/src/llua.c index cbc6864f..f45bf1f4 100644 --- a/src/llua.c +++ b/src/llua.c @@ -42,7 +42,7 @@ void llua_load(const char *script) int error; error = luaL_loadfile(lua_L, script); if(error) { - ERR("llua_load: %s\n", lua_tostring(lua_L, -1)); + ERR("llua_load: %s", lua_tostring(lua_L, -1)); lua_pop(lua_L, 1); } else { lua_pcall(lua_L, 0, 0, 0); @@ -72,11 +72,11 @@ char *llua_getstring(const char *args) } if(lua_pcall(lua_L, parcount, 1, 0) != 0) { - ERR("llua_getstring: function %s execution failed: %s\n", func, lua_tostring(lua_L, -1)); + ERR("llua_getstring: function %s execution failed: %s", func, lua_tostring(lua_L, -1)); lua_pop(lua_L, -1); } else { if(!lua_isstring(lua_L, -1)) { - ERR("llua_getstring: function %s didn't return a string, result discarded\n", func); + ERR("llua_getstring: function %s didn't return a string, result discarded", func); } else { ret = strdup((char *)lua_tostring(lua_L, -1)); lua_pop(lua_L, 1); @@ -111,11 +111,11 @@ int llua_getpercent(const char *args, int *per) free(tmp); if(lua_pcall(lua_L, parcount, 1, 0) != 0) { - ERR("llua_getpercent: function %s execution failed: %s\n", func, lua_tostring(lua_L, -1)); + ERR("llua_getpercent: function %s execution failed: %s", func, lua_tostring(lua_L, -1)); lua_pop(lua_L, -1); } else { if(!lua_isnumber(lua_L, -1)) { - ERR("llua_getpercent: function %s didn't return a number (percent), result discarded\n", func); + ERR("llua_getpercent: function %s didn't return a number (percent), result discarded", func); } else { *per = lua_tonumber(lua_L, -1); lua_pop(lua_L, 1); From 66ba6e36c9aa19bd5af4ca1932a0ae7a2aa809e2 Mon Sep 17 00:00:00 2001 From: Toni Spets Date: Fri, 15 May 2009 23:35:18 +0300 Subject: [PATCH 04/12] * Fix leaks * Fix HUP behaviour - scripts are now reloaded on HUP * Remove unneccessary calls to llua_close() --- src/conky.c | 13 ++++++++++--- src/llua.c | 1 + 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/conky.c b/src/conky.c index b81b7d88..6cbda097 100644 --- a/src/conky.c +++ b/src/conky.c @@ -854,10 +854,10 @@ static void free_text_objects(struct text_object *root) #endif #ifdef HAVE_LUA case OBJ_lua: - llua_close(); + free(data.s); break; case OBJ_lua_bar: - llua_close(); + free(data.s); break; #endif case OBJ_pre_exec: @@ -4192,7 +4192,7 @@ static void generate_text_internal(char *p, int p_max_size, #ifdef X11 OBJ(lua_bar) { int per; - if(llua_getpercent(strdup(obj->data.s), &per)) { + if(llua_getpercent(obj->data.s, &per)) { new_bar(p, obj->a, obj->b, (per/100.0 * 255)); } } @@ -6646,6 +6646,10 @@ static void reload_config(void) tcp_portmon_clear(); #endif +#ifdef HAVE_LUA + llua_close(); +#endif + if (current_config) { clear_fs_stats(); load_config_file(current_config); @@ -6747,6 +6751,9 @@ static void clean_up(void) #ifdef RSS free_rss_info(); #endif +#ifdef HAVE_LUA + llua_close(); +#endif if (specials) { unsigned int i; diff --git a/src/llua.c b/src/llua.c index f45bf1f4..ee930faf 100644 --- a/src/llua.c +++ b/src/llua.c @@ -40,6 +40,7 @@ void llua_init() void llua_load(const char *script) { int error; + if(!lua_L) return; error = luaL_loadfile(lua_L, script); if(error) { ERR("llua_load: %s", lua_tostring(lua_L, -1)); From 95f6748baae1fe072e9541a8f9d237882fdd92cf Mon Sep 17 00:00:00 2001 From: Toni Spets Date: Sat, 16 May 2009 20:32:47 +0300 Subject: [PATCH 05/12] Updated AUTHORS to match Lua stuff, also updated my email --- AUTHORS | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/AUTHORS b/AUTHORS index cc37a49d..2e6725be 100644 --- a/AUTHORS +++ b/AUTHORS @@ -309,10 +309,11 @@ Thomas Cort Toni exec*/tail/head output evalution -Toni Spets hifi +Toni Spets hifi OpenBSD support Linux wifi code - RSS code (created with Mikko Sysikaski) + RSS code (created together with Mikko Sysikaski) + Lua scripting Tris Scroll step patch From da5704fd7456d4deacf7b629ab2f75a649388f0e Mon Sep 17 00:00:00 2001 From: Toni Spets Date: Sat, 16 May 2009 20:37:53 +0300 Subject: [PATCH 06/12] Specifically ask for an integer from Lua for percentage --- src/llua.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/llua.c b/src/llua.c index ee930faf..159105b9 100644 --- a/src/llua.c +++ b/src/llua.c @@ -118,7 +118,7 @@ int llua_getpercent(const char *args, int *per) if(!lua_isnumber(lua_L, -1)) { ERR("llua_getpercent: function %s didn't return a number (percent), result discarded", func); } else { - *per = lua_tonumber(lua_L, -1); + *per = lua_tointeger(lua_L, -1); lua_pop(lua_L, 1); return 1; } From 453908953fbceb3b9d0af038f8b9fdcac867e4cf Mon Sep 17 00:00:00 2001 From: Toni Spets Date: Sat, 16 May 2009 20:57:43 +0300 Subject: [PATCH 07/12] Moved the Lua function calling to it's own function --- src/llua.c | 77 +++++++++++++++++++++++++++++------------------------- 1 file changed, 42 insertions(+), 35 deletions(-) diff --git a/src/llua.c b/src/llua.c index 159105b9..44bb1c97 100644 --- a/src/llua.c +++ b/src/llua.c @@ -50,32 +50,59 @@ void llua_load(const char *script) } } -char *llua_getstring(const char *args) +/* + llua_do_call does a flexible call to any Lua function + string: [par1] [par2...] + retc: the number of return values expected +*/ +char *llua_do_call(const char *string, int retc) { - char *ret = NULL; - char *tmp = strdup(args); - char func[64]; - int parcount = 0; - - if(!lua_L) return NULL; + static char func[64]; + int argc = 0; + char *tmp = strdup(string); char *ptr = strtok(tmp, " "); - if(!ptr) return NULL; /* function name missing */ + + /* proceed only if the function name is present */ + if(!ptr) { + free(tmp); + return NULL; + } + + /* call only conky_ prefixed functions */ snprintf(func, 64, "conky_%s", ptr); + /* push the function name to stack */ lua_getglobal(lua_L, func); + /* parse all function parameters from args and push them to the stack */ ptr = strtok(NULL, " "); while(ptr) { lua_pushstring(lua_L, ptr); ptr = strtok(NULL, " "); - parcount++; + argc++; } - if(lua_pcall(lua_L, parcount, 1, 0) != 0) { - ERR("llua_getstring: function %s execution failed: %s", func, lua_tostring(lua_L, -1)); + free(tmp); + + if(lua_pcall(lua_L, argc, retc, 0) != 0) { + ERR("llua_do_call: function %s execution failed: %s", func, lua_tostring(lua_L, -1)); lua_pop(lua_L, -1); - } else { + return NULL; + } + + return func; +} + +char *llua_getstring(const char *args) +{ + char *func; + char *ret = NULL; + + if(!lua_L) return NULL; + + func = llua_do_call(args, 1); + if(func) { if(!lua_isstring(lua_L, -1)) { ERR("llua_getstring: function %s didn't return a string, result discarded", func); } else { @@ -84,37 +111,17 @@ char *llua_getstring(const char *args) } } - free(tmp); - return ret; } int llua_getpercent(const char *args, int *per) { - char func[64]; - char *tmp = strdup(args); - int parcount = 0; + char *func; if(!lua_L) return 0; - char *ptr = strtok(tmp, " "); - if(!ptr) return 0; /* function name missing */ - snprintf(func, 64, "conky_%s", ptr); - - lua_getglobal(lua_L, func); - - ptr = strtok(NULL, " "); - while(ptr) { - lua_pushstring(lua_L, ptr); - ptr = strtok(NULL, " "); - parcount++; - } - free(tmp); - - if(lua_pcall(lua_L, parcount, 1, 0) != 0) { - ERR("llua_getpercent: function %s execution failed: %s", func, lua_tostring(lua_L, -1)); - lua_pop(lua_L, -1); - } else { + func = llua_do_call(args, 1); + if(func) { if(!lua_isnumber(lua_L, -1)) { ERR("llua_getpercent: function %s didn't return a number (percent), result discarded", func); } else { From 0e21a804ee1ea1b692ad9844f6df82265ec9bae8 Mon Sep 17 00:00:00 2001 From: Brenden Matthews Date: Sat, 16 May 2009 14:55:05 -0600 Subject: [PATCH 08/12] Couple minor lua changes. --- doc/docs.xml | 2 +- doc/variables.xml | 24 +++++++++++-- extras/nano/conky.nanorc | 4 +-- extras/vim/syntax/conkyrc.vim | 4 +-- src/conky.c | 68 +++++++++++++++++++++++++++-------- src/llua.c | 10 +++--- src/llua.h | 2 +- src/specials.c | 7 ++-- src/text_object.h | 6 +++- 9 files changed, 94 insertions(+), 33 deletions(-) diff --git a/doc/docs.xml b/doc/docs.xml index 6ba30882..b9c249fd 100644 --- a/doc/docs.xml +++ b/doc/docs.xml @@ -16,7 +16,7 @@ Brenden Matthews - 2009-05-01 + 2009-05-16 diff --git a/doc/variables.xml b/doc/variables.xml index 6b49936b..1cd145f7 100644 --- a/doc/variables.xml +++ b/doc/variables.xml @@ -2347,7 +2347,7 @@ - Executes a Lua function with given parameters and prints the result value. + Executes a Lua function with given parameters and prints the result value. See also 'lua_load' on how to load scripts. @@ -2357,7 +2357,27 @@ - Executes a Lua function with given parameters and prints a bar. Expects result value to be an integer between 0 and 100. + Executes a Lua function with given parameters and draws a bar. Expects result value to be an integer between 0 and 100. See also 'lua_load' on how to load scripts. + + + + + + + + + + Executes a Lua function with given parameters and draws a graph. Expects result value to be an integer between 0 and 100. See also 'lua_load' on how to load scripts. + + + + + + + + + + Executes a Lua function with given parameters and draws a gauge. Expects result value to be an integer between 0 and 100. See also 'lua_load' on how to load scripts. diff --git a/extras/nano/conky.nanorc b/extras/nano/conky.nanorc index de91922c..509cbafb 100644 --- a/extras/nano/conky.nanorc +++ b/extras/nano/conky.nanorc @@ -5,13 +5,13 @@ syntax "conky" "(\.*conkyrc.*$|conky.conf)" ## Configuration items -color green "\<(alias|alignment|append_file|background|border_margin|border_width|color0|color1|color2|color3|color4|color5|color6|color7|color8|color9|colorN|cpu_avg_samples|default_bar_size|default_color|default_gauge_size|default_graph_size|default_outline_color|default_shade_color|diskio_avg_samples|display|double_buffer|draw_borders|draw_graph_borders|draw_outline|draw_shades|font|gap_x|gap_y|if_up_strictness|imap|mail_spool|max_port_monitor_connections|max_specials|max_user_text|maximum_width|minimum_size|mpd_host|mpd_password|mpd_port|music_player_interval|net_avg_samples|no_buffers|out_to_console|out_to_stderr|out_to_x|override_utf8_locale|overwrite_file|own_window|own_window_class|own_window_colour|own_window_hints|own_window_title|own_window_transparent|own_window_type|pad_percents|pop3|sensor_device|short_units|show_graph_range|show_graph_scale|stippled_borders|temperature_unit|template|template0|template1|template2|template3|template4|template5|template6|template7|template8|template9|text|text_buffer_size|top_cpu_separate|top_name_width|total_run_times|update_interval|uppercase|use_spacer|use_xft|xftalpha|xftfont)\>" +color green "\<(alias|alignment|append_file|background|border_margin|border_width|color0|color1|color2|color3|color4|color5|color6|color7|color8|color9|colorN|cpu_avg_samples|default_bar_size|default_color|default_gauge_size|default_graph_size|default_outline_color|default_shade_color|diskio_avg_samples|display|double_buffer|draw_borders|draw_graph_borders|draw_outline|draw_shades|font|gap_x|gap_y|if_up_strictness|imap|lua_load|mail_spool|max_port_monitor_connections|max_specials|max_user_text|maximum_width|minimum_size|mpd_host|mpd_password|mpd_port|music_player_interval|net_avg_samples|no_buffers|out_to_console|out_to_stderr|out_to_x|override_utf8_locale|overwrite_file|own_window|own_window_class|own_window_colour|own_window_hints|own_window_title|own_window_transparent|own_window_type|pad_percents|pop3|sensor_device|short_units|show_graph_range|show_graph_scale|stippled_borders|temperature_unit|template|template0|template1|template2|template3|template4|template5|template6|template7|template8|template9|text|text_buffer_size|top_cpu_separate|top_name_width|total_run_times|update_interval|uppercase|use_spacer|use_xft|xftalpha|xftfont)\>" ## Configuration item constants color yellow "\<(above|below|bottom_left|bottom_right|bottom_middle|desktop|dock|no|none|normal|override|skip_pager|skip_taskbar|sticky|top_left|top_right|top_middle|middle_left|middle_right|undecorated|yes)\>" ## Variables -color brightblue "\<(acpiacadapter|acpifan|acpitemp|addr|addrs|adt746xcpu|adt746xfan|alignc|alignr|apcupsd|apcupsd_cable|apcupsd_charge|apcupsd_lastxfer|apcupsd_linev|apcupsd_load|apcupsd_loadbar|apcupsd_loadgauge|apcupsd_loadgraph|apcupsd_model|apcupsd_name|apcupsd_status|apcupsd_temp|apcupsd_timeleft|apcupsd_upsmode|apm_adapter|apm_battery_life|apm_battery_time|audacious_bar|audacious_bitrate|audacious_channels|audacious_filename|audacious_frequency|audacious_length|audacious_length_seconds|audacious_main_volume|audacious_playlist_length|audacious_playlist_position|audacious_position|audacious_position_seconds|audacious_status|audacious_title|battery|battery_bar|battery_percent|battery_short|battery_time|bmpx_album|bmpx_artist|bmpx_bitrate|bmpx_title|bmpx_track|bmpx_uri|buffers|cached|color|color0|color1|color2|color3|color4|color5|color6|color7|color8|color9|combine|conky_build_arch|conky_build_date|conky_version|cpu|cpubar|cpugauge|cpugraph|disk_protect|diskio|diskio_read|diskio_write|diskiograph|diskiograph_read|diskiograph_write|downspeed|downspeedf|downspeedgraph|draft_mails|else|endif|entropy_avail|entropy_bar|entropy_poolsize|eval|eve|exec|execbar|execgauge|execgraph|execi|execibar|execigauge|execigraph|execp|execpi|flagged_mails|font|forwarded_mails|freq|freq_g|fs_bar|fs_bar_free|fs_free|fs_free_perc|fs_size|fs_type|fs_used|fs_used_perc|goto|gw_iface|gw_ip|hddtemp|head|hr|hwmon|i2c|i8k_ac_status|i8k_bios|i8k_buttons_status|i8k_cpu_temp|i8k_left_fan_rpm|i8k_left_fan_status|i8k_right_fan_rpm|i8k_right_fan_status|i8k_serial|i8k_version|ibm_brightness|ibm_fan|ibm_temps|ibm_volume|iconv_start|iconv_stop|if_empty|if_existing|if_gw|if_match|if_mixer_mute|if_mounted|if_mpd_playing|if_running|if_smapi_bat_installed|if_up|if_updatenr|if_xmms2_connected|image|imap_messages|imap_unseen|ioscheduler|kernel|laptop_mode|lines|loadavg|loadgraph|machine|mails|mboxscan|mem|membar|memeasyfree|memfree|memgauge|memgraph|memmax|memperc|mixer|mixerbar|mixerl|mixerlbar|mixerr|mixerrbar|moc_album|moc_artist|moc_bitrate|moc_curtime|moc_file|moc_rate|moc_song|moc_state|moc_timeleft|moc_title|moc_totaltime|monitor|monitor_number|mpd_album|mpd_artist|mpd_bar|mpd_bitrate|mpd_elapsed|mpd_file|mpd_length|mpd_name|mpd_percent|mpd_random|mpd_repeat|mpd_smart|mpd_status|mpd_title|mpd_track|mpd_vol|nameserver|new_mails|nodename|nvidia|obsd_product|obsd_sensors_fan|obsd_sensors_temp|obsd_sensors_volt|obsd_vendor|offset|outlinecolor|pb_battery|platform|pop3_unseen|pop3_used|pre_exec|processes|replied_mails|rss|running_processes|scroll|seen_mails|shadecolor|smapi|smapi_bat_bar|smapi_bat_perc|smapi_bat_power|smapi_bat_temp|sony_fanspeed|stippled_hr|swap|swapbar|swapmax|swapperc|sysname|tab|tail|tcp_portmon|template0|template1|template2|template3|template4|template5|template6|template7|template8|template9|texeci|time|top|top_mem|top_time|totaldown|totalup|trashed_mails|tztime|unflagged_mails|unforwarded_mails|unreplied_mails|unseen_mails|updates|upspeed|upspeedf|upspeedgraph|uptime|uptime_short|user_names|user_number|user_terms|user_times|utime|voffset|voltage_mv|voltage_v|wireless_ap|wireless_bitrate|wireless_essid|wireless_link_bar|wireless_link_qual|wireless_link_qual_max|wireless_link_qual_perc|wireless_mode|words|xmms2_album|xmms2_artist|xmms2_bar|xmms2_bitrate|xmms2_comment|xmms2_date|xmms2_duration|xmms2_elapsed|xmms2_genre|xmms2_id|xmms2_percent|xmms2_playlist|xmms2_size|xmms2_smart|xmms2_status|xmms2_timesplayed|xmms2_title|xmms2_tracknr|xmms2_url)\>" +color brightblue "\<(acpiacadapter|acpifan|acpitemp|addr|addrs|adt746xcpu|adt746xfan|alignc|alignr|apcupsd|apcupsd_cable|apcupsd_charge|apcupsd_lastxfer|apcupsd_linev|apcupsd_load|apcupsd_loadbar|apcupsd_loadgauge|apcupsd_loadgraph|apcupsd_model|apcupsd_name|apcupsd_status|apcupsd_temp|apcupsd_timeleft|apcupsd_upsmode|apm_adapter|apm_battery_life|apm_battery_time|audacious_bar|audacious_bitrate|audacious_channels|audacious_filename|audacious_frequency|audacious_length|audacious_length_seconds|audacious_main_volume|audacious_playlist_length|audacious_playlist_position|audacious_position|audacious_position_seconds|audacious_status|audacious_title|battery|battery_bar|battery_percent|battery_short|battery_time|bmpx_album|bmpx_artist|bmpx_bitrate|bmpx_title|bmpx_track|bmpx_uri|buffers|cached|color|color0|color1|color2|color3|color4|color5|color6|color7|color8|color9|combine|conky_build_arch|conky_build_date|conky_version|cpu|cpubar|cpugauge|cpugraph|disk_protect|diskio|diskio_read|diskio_write|diskiograph|diskiograph_read|diskiograph_write|downspeed|downspeedf|downspeedgraph|draft_mails|else|endif|entropy_avail|entropy_bar|entropy_poolsize|eval|eve|exec|execbar|execgauge|execgraph|execi|execibar|execigauge|execigraph|execp|execpi|flagged_mails|font|forwarded_mails|freq|freq_g|fs_bar|fs_bar_free|fs_free|fs_free_perc|fs_size|fs_type|fs_used|fs_used_perc|goto|gw_iface|gw_ip|hddtemp|head|hr|hwmon|i2c|i8k_ac_status|i8k_bios|i8k_buttons_status|i8k_cpu_temp|i8k_left_fan_rpm|i8k_left_fan_status|i8k_right_fan_rpm|i8k_right_fan_status|i8k_serial|i8k_version|ibm_brightness|ibm_fan|ibm_temps|ibm_volume|iconv_start|iconv_stop|if_empty|if_existing|if_gw|if_match|if_mixer_mute|if_mounted|if_mpd_playing|if_running|if_smapi_bat_installed|if_up|if_updatenr|if_xmms2_connected|image|imap_messages|imap_unseen|ioscheduler|kernel|laptop_mode|lines|loadavg|loadgraph|lua|lua_bar|lua_gauge|lua_graph|machine|mails|mboxscan|mem|membar|memeasyfree|memfree|memgauge|memgraph|memmax|memperc|mixer|mixerbar|mixerl|mixerlbar|mixerr|mixerrbar|moc_album|moc_artist|moc_bitrate|moc_curtime|moc_file|moc_rate|moc_song|moc_state|moc_timeleft|moc_title|moc_totaltime|monitor|monitor_number|mpd_album|mpd_artist|mpd_bar|mpd_bitrate|mpd_elapsed|mpd_file|mpd_length|mpd_name|mpd_percent|mpd_random|mpd_repeat|mpd_smart|mpd_status|mpd_title|mpd_track|mpd_vol|nameserver|new_mails|nodename|nvidia|obsd_product|obsd_sensors_fan|obsd_sensors_temp|obsd_sensors_volt|obsd_vendor|offset|outlinecolor|pb_battery|platform|pop3_unseen|pop3_used|pre_exec|processes|replied_mails|rss|running_processes|scroll|seen_mails|shadecolor|smapi|smapi_bat_bar|smapi_bat_perc|smapi_bat_power|smapi_bat_temp|sony_fanspeed|stippled_hr|swap|swapbar|swapmax|swapperc|sysname|tab|tail|tcp_portmon|template0|template1|template2|template3|template4|template5|template6|template7|template8|template9|texeci|time|top|top_mem|top_time|totaldown|totalup|trashed_mails|tztime|unflagged_mails|unforwarded_mails|unreplied_mails|unseen_mails|updates|upspeed|upspeedf|upspeedgraph|uptime|uptime_short|user_names|user_number|user_terms|user_times|utime|voffset|voltage_mv|voltage_v|wireless_ap|wireless_bitrate|wireless_essid|wireless_link_bar|wireless_link_qual|wireless_link_qual_max|wireless_link_qual_perc|wireless_mode|words|xmms2_album|xmms2_artist|xmms2_bar|xmms2_bitrate|xmms2_comment|xmms2_date|xmms2_duration|xmms2_elapsed|xmms2_genre|xmms2_id|xmms2_percent|xmms2_playlist|xmms2_size|xmms2_smart|xmms2_status|xmms2_timesplayed|xmms2_title|xmms2_tracknr|xmms2_url)\>" color brightblue "\$\{?[0-9A-Z_!@#$*?-]+\}?" color cyan "(\{|\}|\(|\)|\;|\]|\[|`|\\|\$|<|>|!|=|&|\|)" diff --git a/extras/vim/syntax/conkyrc.vim b/extras/vim/syntax/conkyrc.vim index b8886c42..73db7753 100644 --- a/extras/vim/syntax/conkyrc.vim +++ b/extras/vim/syntax/conkyrc.vim @@ -12,7 +12,7 @@ endif syn region ConkyrcComment start=/^\s*#/ end=/$/ -syn keyword ConkyrcSetting alias alignment append_file background border_margin border_width color0 color1 color2 color3 color4 color5 color6 color7 color8 color9 colorN cpu_avg_samples default_bar_size default_color default_gauge_size default_graph_size default_outline_color default_shade_color diskio_avg_samples display double_buffer draw_borders draw_graph_borders draw_outline draw_shades font gap_x gap_y if_up_strictness imap mail_spool max_port_monitor_connections max_specials max_user_text maximum_width minimum_size mpd_host mpd_password mpd_port music_player_interval net_avg_samples no_buffers out_to_console out_to_stderr out_to_x override_utf8_locale overwrite_file own_window own_window_class own_window_colour own_window_hints own_window_title own_window_transparent own_window_type pad_percents pop3 sensor_device short_units show_graph_range show_graph_scale stippled_borders temperature_unit template template0 template1 template2 template3 template4 template5 template6 template7 template8 template9 text text_buffer_size top_cpu_separate top_name_width total_run_times update_interval uppercase use_spacer use_xft xftalpha xftfont +syn keyword ConkyrcSetting alias alignment append_file background border_margin border_width color0 color1 color2 color3 color4 color5 color6 color7 color8 color9 colorN cpu_avg_samples default_bar_size default_color default_gauge_size default_graph_size default_outline_color default_shade_color diskio_avg_samples display double_buffer draw_borders draw_graph_borders draw_outline draw_shades font gap_x gap_y if_up_strictness imap lua_load mail_spool max_port_monitor_connections max_specials max_user_text maximum_width minimum_size mpd_host mpd_password mpd_port music_player_interval net_avg_samples no_buffers out_to_console out_to_stderr out_to_x override_utf8_locale overwrite_file own_window own_window_class own_window_colour own_window_hints own_window_title own_window_transparent own_window_type pad_percents pop3 sensor_device short_units show_graph_range show_graph_scale stippled_borders temperature_unit template template0 template1 template2 template3 template4 template5 template6 template7 template8 template9 text text_buffer_size top_cpu_separate top_name_width total_run_times update_interval uppercase use_spacer use_xft xftalpha xftfont syn keyword ConkyrcConstant \ above @@ -49,7 +49,7 @@ syn region ConkyrcVar start=/\$\w\@=/ end=/\W\@=\|$/ contained contains=ConkyrcV syn match ConkyrcVarStuff /{\@<=/ms=s contained nextgroup=ConkyrcVarName -syn keyword ConkyrcVarName contained nextgroup=ConkyrcNumber,ConkyrcColour skipwhite acpiacadapter acpifan acpitemp addr addrs adt746xcpu adt746xfan alignc alignr apcupsd apcupsd_cable apcupsd_charge apcupsd_lastxfer apcupsd_linev apcupsd_load apcupsd_loadbar apcupsd_loadgauge apcupsd_loadgraph apcupsd_model apcupsd_name apcupsd_status apcupsd_temp apcupsd_timeleft apcupsd_upsmode apm_adapter apm_battery_life apm_battery_time audacious_bar audacious_bitrate audacious_channels audacious_filename audacious_frequency audacious_length audacious_length_seconds audacious_main_volume audacious_playlist_length audacious_playlist_position audacious_position audacious_position_seconds audacious_status audacious_title battery battery_bar battery_percent battery_short battery_time bmpx_album bmpx_artist bmpx_bitrate bmpx_title bmpx_track bmpx_uri buffers cached color color0 color1 color2 color3 color4 color5 color6 color7 color8 color9 combine conky_build_arch conky_build_date conky_version cpu cpubar cpugauge cpugraph disk_protect diskio diskio_read diskio_write diskiograph diskiograph_read diskiograph_write downspeed downspeedf downspeedgraph draft_mails else endif entropy_avail entropy_bar entropy_poolsize eval eve exec execbar execgauge execgraph execi execibar execigauge execigraph execp execpi flagged_mails font forwarded_mails freq freq_g fs_bar fs_bar_free fs_free fs_free_perc fs_size fs_type fs_used fs_used_perc goto gw_iface gw_ip hddtemp head hr hwmon i2c i8k_ac_status i8k_bios i8k_buttons_status i8k_cpu_temp i8k_left_fan_rpm i8k_left_fan_status i8k_right_fan_rpm i8k_right_fan_status i8k_serial i8k_version ibm_brightness ibm_fan ibm_temps ibm_volume iconv_start iconv_stop if_empty if_existing if_gw if_match if_mixer_mute if_mounted if_mpd_playing if_running if_smapi_bat_installed if_up if_updatenr if_xmms2_connected image imap_messages imap_unseen ioscheduler kernel laptop_mode lines loadavg loadgraph machine mails mboxscan mem membar memeasyfree memfree memgauge memgraph memmax memperc mixer mixerbar mixerl mixerlbar mixerr mixerrbar moc_album moc_artist moc_bitrate moc_curtime moc_file moc_rate moc_song moc_state moc_timeleft moc_title moc_totaltime monitor monitor_number mpd_album mpd_artist mpd_bar mpd_bitrate mpd_elapsed mpd_file mpd_length mpd_name mpd_percent mpd_random mpd_repeat mpd_smart mpd_status mpd_title mpd_track mpd_vol nameserver new_mails nodename nvidia obsd_product obsd_sensors_fan obsd_sensors_temp obsd_sensors_volt obsd_vendor offset outlinecolor pb_battery platform pop3_unseen pop3_used pre_exec processes replied_mails rss running_processes scroll seen_mails shadecolor smapi smapi_bat_bar smapi_bat_perc smapi_bat_power smapi_bat_temp sony_fanspeed stippled_hr swap swapbar swapmax swapperc sysname tab tail tcp_portmon template0 template1 template2 template3 template4 template5 template6 template7 template8 template9 texeci time top top_mem top_time totaldown totalup trashed_mails tztime unflagged_mails unforwarded_mails unreplied_mails unseen_mails updates upspeed upspeedf upspeedgraph uptime uptime_short user_names user_number user_terms user_times utime voffset voltage_mv voltage_v wireless_ap wireless_bitrate wireless_essid wireless_link_bar wireless_link_qual wireless_link_qual_max wireless_link_qual_perc wireless_mode words xmms2_album xmms2_artist xmms2_bar xmms2_bitrate xmms2_comment xmms2_date xmms2_duration xmms2_elapsed xmms2_genre xmms2_id xmms2_percent xmms2_playlist xmms2_size xmms2_smart xmms2_status xmms2_timesplayed xmms2_title xmms2_tracknr xmms2_url +syn keyword ConkyrcVarName contained nextgroup=ConkyrcNumber,ConkyrcColour skipwhite acpiacadapter acpifan acpitemp addr addrs adt746xcpu adt746xfan alignc alignr apcupsd apcupsd_cable apcupsd_charge apcupsd_lastxfer apcupsd_linev apcupsd_load apcupsd_loadbar apcupsd_loadgauge apcupsd_loadgraph apcupsd_model apcupsd_name apcupsd_status apcupsd_temp apcupsd_timeleft apcupsd_upsmode apm_adapter apm_battery_life apm_battery_time audacious_bar audacious_bitrate audacious_channels audacious_filename audacious_frequency audacious_length audacious_length_seconds audacious_main_volume audacious_playlist_length audacious_playlist_position audacious_position audacious_position_seconds audacious_status audacious_title battery battery_bar battery_percent battery_short battery_time bmpx_album bmpx_artist bmpx_bitrate bmpx_title bmpx_track bmpx_uri buffers cached color color0 color1 color2 color3 color4 color5 color6 color7 color8 color9 combine conky_build_arch conky_build_date conky_version cpu cpubar cpugauge cpugraph disk_protect diskio diskio_read diskio_write diskiograph diskiograph_read diskiograph_write downspeed downspeedf downspeedgraph draft_mails else endif entropy_avail entropy_bar entropy_poolsize eval eve exec execbar execgauge execgraph execi execibar execigauge execigraph execp execpi flagged_mails font forwarded_mails freq freq_g fs_bar fs_bar_free fs_free fs_free_perc fs_size fs_type fs_used fs_used_perc goto gw_iface gw_ip hddtemp head hr hwmon i2c i8k_ac_status i8k_bios i8k_buttons_status i8k_cpu_temp i8k_left_fan_rpm i8k_left_fan_status i8k_right_fan_rpm i8k_right_fan_status i8k_serial i8k_version ibm_brightness ibm_fan ibm_temps ibm_volume iconv_start iconv_stop if_empty if_existing if_gw if_match if_mixer_mute if_mounted if_mpd_playing if_running if_smapi_bat_installed if_up if_updatenr if_xmms2_connected image imap_messages imap_unseen ioscheduler kernel laptop_mode lines loadavg loadgraph lua lua_bar lua_gauge lua_graph machine mails mboxscan mem membar memeasyfree memfree memgauge memgraph memmax memperc mixer mixerbar mixerl mixerlbar mixerr mixerrbar moc_album moc_artist moc_bitrate moc_curtime moc_file moc_rate moc_song moc_state moc_timeleft moc_title moc_totaltime monitor monitor_number mpd_album mpd_artist mpd_bar mpd_bitrate mpd_elapsed mpd_file mpd_length mpd_name mpd_percent mpd_random mpd_repeat mpd_smart mpd_status mpd_title mpd_track mpd_vol nameserver new_mails nodename nvidia obsd_product obsd_sensors_fan obsd_sensors_temp obsd_sensors_volt obsd_vendor offset outlinecolor pb_battery platform pop3_unseen pop3_used pre_exec processes replied_mails rss running_processes scroll seen_mails shadecolor smapi smapi_bat_bar smapi_bat_perc smapi_bat_power smapi_bat_temp sony_fanspeed stippled_hr swap swapbar swapmax swapperc sysname tab tail tcp_portmon template0 template1 template2 template3 template4 template5 template6 template7 template8 template9 texeci time top top_mem top_time totaldown totalup trashed_mails tztime unflagged_mails unforwarded_mails unreplied_mails unseen_mails updates upspeed upspeedf upspeedgraph uptime uptime_short user_names user_number user_terms user_times utime voffset voltage_mv voltage_v wireless_ap wireless_bitrate wireless_essid wireless_link_bar wireless_link_qual wireless_link_qual_max wireless_link_qual_perc wireless_mode words xmms2_album xmms2_artist xmms2_bar xmms2_bitrate xmms2_comment xmms2_date xmms2_duration xmms2_elapsed xmms2_genre xmms2_id xmms2_percent xmms2_playlist xmms2_size xmms2_smart xmms2_status xmms2_timesplayed xmms2_title xmms2_tracknr xmms2_url hi def link ConkyrcComment Comment hi def link ConkyrcSetting Keyword diff --git a/src/conky.c b/src/conky.c index 6cbda097..dd2a5ed3 100644 --- a/src/conky.c +++ b/src/conky.c @@ -854,12 +854,14 @@ static void free_text_objects(struct text_object *root) #endif #ifdef HAVE_LUA case OBJ_lua: - free(data.s); - break; +#ifdef X11 case OBJ_lua_bar: + case OBJ_lua_graph: + case OBJ_lua_gauge: +#endif /* X11 */ free(data.s); break; -#endif +#endif /* HAVE_LUA */ case OBJ_pre_exec: break; #ifndef __OpenBSD__ @@ -2581,7 +2583,7 @@ static struct text_object *construct_text_object(const char *s, #endif #ifdef HAVE_LUA END OBJ(lua, 0) - if(arg) { + if (arg) { obj->data.s = strndup(arg, text_buffer_size); } else { CRIT_ERR("lua needs arguments: [function parameters]"); @@ -2589,7 +2591,7 @@ static struct text_object *construct_text_object(const char *s, #ifdef X11 END OBJ(lua_bar, 0) - if(arg) { + if (arg) { arg = scan_bar(arg, &obj->a, &obj->b); if(arg) { obj->data.s = strndup(arg, text_buffer_size); @@ -2599,8 +2601,31 @@ static struct text_object *construct_text_object(const char *s, } else { CRIT_ERR("lua_bar needs arguments: , [function parameters]"); } -#endif -#endif + END OBJ(lua_graph, 0) + if (arg) { + arg = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d, + &obj->e, &obj->showaslog); + if (arg) { + obj->data.s = strndup(arg, text_buffer_size); + } else { + CRIT_ERR("lua_graph needs arguments: <\"normal\"|\"log\"> , [function parameters]"); + } + } else { + CRIT_ERR("lua_graph needs arguments: <\"normal\"|\"log\"> , [function parameters]"); + } + END OBJ(lua_gauge, 0) + if (arg) { + arg = scan_gauge(arg, &obj->a, &obj->b); + if (arg) { + obj->data.s = strndup(arg, text_buffer_size); + } else { + CRIT_ERR("lua_gauge needs arguments: , [function parameters]"); + } + } else { + CRIT_ERR("lua_gauge needs arguments: , [function parameters]"); + } +#endif /* X11 */ +#endif /* HAVE_LUA */ #ifdef HDDTEMP END OBJ(hddtemp, 0) if (scan_hddtemp(arg, &obj->data.hddtemp.dev, @@ -4183,7 +4208,7 @@ static void generate_text_internal(char *p, int p_max_size, #ifdef HAVE_LUA OBJ(lua) { char *str = llua_getstring(obj->data.s); - if(str) { + if (str) { snprintf(p, p_max_size, "%s", str); free(str); } @@ -4192,12 +4217,25 @@ static void generate_text_internal(char *p, int p_max_size, #ifdef X11 OBJ(lua_bar) { int per; - if(llua_getpercent(obj->data.s, &per)) { + if (llua_getinteger(obj->data.s, &per)) { new_bar(p, obj->a, obj->b, (per/100.0 * 255)); } } -#endif -#endif + OBJ(lua_graph) { + int per; + if (llua_getinteger(obj->data.s, &per)) { + new_graph(p, obj->a, obj->b, obj->c, obj->d, + (per/100.0 * 255), 100, 1, obj->showaslog); + } + } + OBJ(lua_gauge) { + int per; + if (llua_getinteger(obj->data.s, &per)) { + new_gauge(p, obj->a, obj->b, (per/100.0 * 255)); + } + } +#endif /* X11 */ +#endif /* HAVE_LUA */ #ifdef HDDTEMP OBJ(hddtemp) { char *endptr, unit; @@ -5858,7 +5896,7 @@ static void draw_line(char *s) XDrawLine(display, window.drawable, window.gc, cur_x + (w/2.), by+(h), (int)(px), (int)(py)); -#endif +#endif /* MATH */ if (h > cur_y_add && h > font_h) { @@ -6648,7 +6686,7 @@ static void reload_config(void) #ifdef HAVE_LUA llua_close(); -#endif +#endif /* HAVE_LUA */ if (current_config) { clear_fs_stats(); @@ -6753,7 +6791,7 @@ static void clean_up(void) #endif #ifdef HAVE_LUA llua_close(); -#endif +#endif /* HAVE_LUA */ if (specials) { unsigned int i; @@ -7724,7 +7762,7 @@ static void load_config_file(const char *f) CONF_ERR; } } -#endif +#endif /* HAVE_LUA */ CONF("color0"){} CONF("color1"){} diff --git a/src/llua.c b/src/llua.c index 44bb1c97..45e87146 100644 --- a/src/llua.c +++ b/src/llua.c @@ -41,12 +41,10 @@ void llua_load(const char *script) { int error; if(!lua_L) return; - error = luaL_loadfile(lua_L, script); - if(error) { + error = luaL_dofile(lua_L, script); + if (error) { ERR("llua_load: %s", lua_tostring(lua_L, -1)); lua_pop(lua_L, 1); - } else { - lua_pcall(lua_L, 0, 0, 0); } } @@ -114,7 +112,7 @@ char *llua_getstring(const char *args) return ret; } -int llua_getpercent(const char *args, int *per) +int llua_getinteger(const char *args, int *per) { char *func; @@ -123,7 +121,7 @@ int llua_getpercent(const char *args, int *per) func = llua_do_call(args, 1); if(func) { if(!lua_isnumber(lua_L, -1)) { - ERR("llua_getpercent: function %s didn't return a number (percent), result discarded", func); + ERR("llua_getinteger: function %s didn't return an integer, result discarded", func); } else { *per = lua_tointeger(lua_L, -1); lua_pop(lua_L, 1); diff --git a/src/llua.h b/src/llua.h index 596f2b4d..6a26bac3 100644 --- a/src/llua.h +++ b/src/llua.h @@ -8,7 +8,7 @@ void llua_init(); void llua_load(const char *script); char *llua_getstring(const char *args); -int llua_getpercent(const char *args, int *per); +int llua_getinteger(const char *args, int *per); void llua_close(); #endif /* LUA_H_*/ diff --git a/src/specials.c b/src/specials.c index f951fed4..dc789680 100644 --- a/src/specials.c +++ b/src/specials.c @@ -45,7 +45,7 @@ unsigned int special_count; #ifdef X11 int default_bar_width = 0, default_bar_height = 6; int default_graph_width = 0, default_graph_height = 25; -int default_gauge_width = 50, default_gauge_height = 25; +int default_gauge_width = 40, default_gauge_height = 25; /* * Scanning arguments to various special text objects @@ -62,8 +62,9 @@ const char *scan_gauge(const char *args, int *w, int *h) int n = 0; if (sscanf(args, "%d,%d %n", h, w, &n) <= 1) { - sscanf(args, "%d %n", h, &n); - *w = *h; /*square gauge*/ + if (sscanf(args, "%d %n", h, &n) == 2) { + *w = *h; /*square gauge*/ + } } args += n; } diff --git a/src/text_object.h b/src/text_object.h index a4f13bcb..b185ba41 100644 --- a/src/text_object.h +++ b/src/text_object.h @@ -382,8 +382,12 @@ enum text_object_type { #endif #ifdef HAVE_LUA OBJ_lua, +#ifdef X11 OBJ_lua_bar, -#endif + OBJ_lua_graph, + OBJ_lua_gauge, +#endif /* X11 */ +#endif /* HAVE_LUA */ #ifdef TCP_PORT_MONITOR OBJ_tcp_portmon, #endif From 69718f5b75b033473164f2066001edf0e66e2782 Mon Sep 17 00:00:00 2001 From: Brenden Matthews Date: Sat, 16 May 2009 15:06:29 -0600 Subject: [PATCH 09/12] Oh my, parse lua output. --- src/conky.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/conky.c b/src/conky.c index bd13616b..368731e0 100644 --- a/src/conky.c +++ b/src/conky.c @@ -4209,7 +4209,15 @@ static void generate_text_internal(char *p, int p_max_size, OBJ(lua) { char *str = llua_getstring(obj->data.s); if (str) { - snprintf(p, p_max_size, "%s", str); + struct information *tmp_info; + struct text_object subroot; + + tmp_info = malloc(sizeof(struct information)); + memcpy(tmp_info, cur, sizeof(struct information)); + parse_conky_vars(&subroot, str, p, tmp_info); + + free_text_objects(&subroot); + free(tmp_info); free(str); } } From b661dbf5a7f8f7a51e7de41b5841bd339541dab4 Mon Sep 17 00:00:00 2001 From: Brenden Matthews Date: Sat, 16 May 2009 17:04:26 -0600 Subject: [PATCH 10/12] More lua stuff. --- doc/variables.xml | 22 ++++- src/conky.c | 206 ++++++++++++++++++++++++++++++---------------- src/llua.c | 49 ++++++++++- src/llua.h | 32 ++++++- src/text_object.h | 4 + 5 files changed, 238 insertions(+), 75 deletions(-) diff --git a/doc/variables.xml b/doc/variables.xml index 1cd145f7..35e9bf2b 100644 --- a/doc/variables.xml +++ b/doc/variables.xml @@ -2347,7 +2347,27 @@ - Executes a Lua function with given parameters and prints the result value. See also 'lua_load' on how to load scripts. + Executes a Lua function with given parameters, then prints the returned string. See also 'lua_load' on how to load scripts. + + + + + + + + + + Executes a Lua function with given parameters as per $lua, then parses and prints the result value as per the syntax for Conky's TEXT section. See also 'lua_load' on how to load scripts. + + + + + + + + + + Executes a Lua function per $lua, except takes a 2nd argument which is first evaluated as per Conky's TEXT section and passed to the function first. The return value is then parsed and prints the result value as per the syntax for Conky's TEXT section. See also 'lua_load' on how to load scripts. diff --git a/src/conky.c b/src/conky.c index 368731e0..cd234c76 100644 --- a/src/conky.c +++ b/src/conky.c @@ -631,8 +631,11 @@ static struct text_object *new_text_object_internal(void) return obj; } -/* free the list of text objects root points to */ -static void free_text_objects(struct text_object *root) +/* + * Frees the list of text objects root points to. When internal = 1, it won't + * free global objects. + */ +static void free_text_objects(struct text_object *root, int internal) { struct text_object *obj; @@ -704,7 +707,7 @@ static void free_text_objects(struct text_object *root) break; case OBJ_if_empty: case OBJ_if_match: - free_text_objects(obj->sub); + free_text_objects(obj->sub, 1); free(obj->sub); /* fall through */ case OBJ_if_existing: @@ -854,6 +857,8 @@ static void free_text_objects(struct text_object *root) #endif #ifdef HAVE_LUA case OBJ_lua: + case OBJ_lua_parse: + case OBJ_lua_read_parse: #ifdef X11 case OBJ_lua_bar: case OBJ_lua_graph: @@ -895,10 +900,11 @@ static void free_text_objects(struct text_object *root) case OBJ_top: case OBJ_top_mem: case OBJ_top_time: - if (info.first_process) { + if (info.first_process && !internal) { free_all_processes(); info.first_process = NULL; } + if (data.top.s) free(data.top.s); break; #ifdef HDDTEMP case OBJ_hddtemp: @@ -988,14 +994,14 @@ static void free_text_objects(struct text_object *root) #endif case OBJ_scroll: free(data.scroll.text); - free_text_objects(obj->sub); + free_text_objects(obj->sub, 1); free(obj->sub); break; case OBJ_combine: free(data.combine.left); free(data.combine.seperation); free(data.combine.right); - free_text_objects(obj->sub); + free_text_objects(obj->sub, 1); free(obj->sub); break; #ifdef APCUPSD @@ -1063,6 +1069,74 @@ static const char *dev_name(const char *path) #undef DEV_NAME } +static int parse_top_args(const char *s, const char *arg, struct text_object *obj) +{ + char buf[64]; + int n; + + if (obj->data.top.was_parsed) { + return 1; + } + obj->data.top.was_parsed = 1; + + if (arg && !obj->data.top.s) { + obj->data.top.s = strndup(arg, text_buffer_size); + } + + need_mask |= (1 << INFO_TOP); + + if (s[3] == 0) { + obj->type = OBJ_top; + top_cpu = 1; + } else if (strcmp(&s[3], "_mem") == EQUAL) { + obj->type = OBJ_top_mem; + top_mem = 1; + } else if (strcmp(&s[3], "_time") == EQUAL) { + obj->type = OBJ_top_time; + top_time = 1; + } else { + ERR("Must be top, top_mem or top_time"); + return 0; + } + + if (!arg) { + ERR("top needs arguments"); + return 0; + } + + if (sscanf(arg, "%63s %i", buf, &n) == 2) { + if (strcmp(buf, "name") == EQUAL) { + obj->data.top.type = TOP_NAME; + } else if (strcmp(buf, "cpu") == EQUAL) { + obj->data.top.type = TOP_CPU; + } else if (strcmp(buf, "pid") == EQUAL) { + obj->data.top.type = TOP_PID; + } else if (strcmp(buf, "mem") == EQUAL) { + obj->data.top.type = TOP_MEM; + } else if (strcmp(buf, "time") == EQUAL) { + obj->data.top.type = TOP_TIME; + } else if (strcmp(buf, "mem_res") == EQUAL) { + obj->data.top.type = TOP_MEM_RES; + } else if (strcmp(buf, "mem_vsize") == EQUAL) { + obj->data.top.type = TOP_MEM_VSIZE; + } else { + ERR("invalid type arg for top"); + ERR("must be one of: name, cpu, pid, mem, time, mem_res, mem_vsize"); + return 0; + } + if (n < 1 || n > 10) { + ERR("invalid num arg for top. Must be between 1 and 10."); + return 0; + } else { + obj->data.top.num = n - 1; + } + } else { + ERR("invalid argument count for top"); + return 0; + } + return 1; +} + /* construct_text_object() creates a new text_object */ static struct text_object *construct_text_object(const char *s, const char *arg, long line, char allow_threaded, void **ifblock_opaque) @@ -1775,58 +1849,7 @@ static struct text_object *construct_text_object(const char *s, * avoid having almost-same code three times, we have this special * handler. */ if (strncmp(s, "top", 3) == EQUAL) { - char buf[64]; - int n; - - need_mask |= (1 << INFO_TOP); - - if (s[3] == 0) { - obj->type = OBJ_top; - top_cpu = 1; - } else if (strcmp(&s[3], "_mem") == EQUAL) { - obj->type = OBJ_top_mem; - top_mem = 1; - } else if (strcmp(&s[3], "_time") == EQUAL) { - obj->type = OBJ_top_time; - top_time = 1; - } else { - ERR("Must be top, top_mem or top_time"); - return NULL; - } - - if (!arg) { - ERR("top needs arguments"); - return NULL; - } - - if (sscanf(arg, "%63s %i", buf, &n) == 2) { - if (strcmp(buf, "name") == EQUAL) { - obj->data.top.type = TOP_NAME; - } else if (strcmp(buf, "cpu") == EQUAL) { - obj->data.top.type = TOP_CPU; - } else if (strcmp(buf, "pid") == EQUAL) { - obj->data.top.type = TOP_PID; - } else if (strcmp(buf, "mem") == EQUAL) { - obj->data.top.type = TOP_MEM; - } else if (strcmp(buf, "time") == EQUAL) { - obj->data.top.type = TOP_TIME; - } else if (strcmp(buf, "mem_res") == EQUAL) { - obj->data.top.type = TOP_MEM_RES; - } else if (strcmp(buf, "mem_vsize") == EQUAL) { - obj->data.top.type = TOP_MEM_VSIZE; - } else { - ERR("invalid type arg for top"); - ERR("must be one of: name, cpu, pid, mem, time, mem_res, mem_vsize"); - return NULL; - } - if (n < 1 || n > 10) { - ERR("invalid num arg for top. Must be between 1 and 10."); - return NULL; - } else { - obj->data.top.num = n - 1; - } - } else { - ERR("invalid argument count for top"); + if (!parse_top_args(s, arg, obj)) { return NULL; } } else OBJ(addr, INFO_NET) @@ -1855,13 +1878,13 @@ static struct text_object *construct_text_object(const char *s, } END OBJ(lines, 0) if (arg) { - obj->data.s = strdup(arg); + obj->data.s = strndup(arg, text_buffer_size); }else{ CRIT_ERR("lines needs a argument"); } END OBJ(words, 0) if (arg) { - obj->data.s = strdup(arg); + obj->data.s = strndup(arg, text_buffer_size); }else{ CRIT_ERR("words needs a argument"); } @@ -2588,7 +2611,18 @@ static struct text_object *construct_text_object(const char *s, } else { CRIT_ERR("lua needs arguments: [function parameters]"); } - + END OBJ(lua_parse, 0) + if (arg) { + obj->data.s = strndup(arg, text_buffer_size); + } else { + CRIT_ERR("lua_parse needs arguments: [function parameters]"); + } + END OBJ(lua_read_parse, 0) + if (arg) { + obj->data.s = strndup(arg, text_buffer_size); + } else { + CRIT_ERR("lua_read_parse needs arguments: "); + } #ifdef X11 END OBJ(lua_bar, 0) if (arg) { @@ -3138,7 +3172,7 @@ static int extract_variable_text_internal(struct text_object *retval, const char static void extract_variable_text(const char *p) { - free_text_objects(&global_root_object); + free_text_objects(&global_root_object, 0); if (tmpstring1) { free(tmpstring1); tmpstring1 = 0; @@ -3814,8 +3848,8 @@ static void generate_text_internal(char *p, int p_max_size, DBGP("evaluated '%s' to '%s'", obj->data.s, p); parse_conky_vars(&subroot2, p, p, tmp_info); - free_text_objects(&subroot); - free_text_objects(&subroot2); + free_text_objects(&subroot, 1); + free_text_objects(&subroot2, 1); free(tmp_info); } OBJ(exec) { @@ -3832,7 +3866,7 @@ static void generate_text_internal(char *p, int p_max_size, memcpy(tmp_info, cur, sizeof(struct information)); parse_conky_vars(&subroot, p, p, tmp_info); - free_text_objects(&subroot); + free_text_objects(&subroot, 1); free(tmp_info); } #ifdef X11 @@ -3958,7 +3992,7 @@ static void generate_text_internal(char *p, int p_max_size, parse_conky_vars(&subroot, obj->data.execi.buffer, p, tmp_info); obj->data.execi.last_update = current_update_time; } - free_text_objects(&subroot); + free_text_objects(&subroot, 1); free(tmp_info); } OBJ(texeci) { @@ -4207,6 +4241,13 @@ static void generate_text_internal(char *p, int p_max_size, #endif #ifdef HAVE_LUA OBJ(lua) { + char *str = llua_getstring(obj->data.s); + if (str) { + snprintf(p, p_max_size, "%s", str); + free(str); + } + } + OBJ(lua_parse) { char *str = llua_getstring(obj->data.s); if (str) { struct information *tmp_info; @@ -4216,12 +4257,37 @@ static void generate_text_internal(char *p, int p_max_size, memcpy(tmp_info, cur, sizeof(struct information)); parse_conky_vars(&subroot, str, p, tmp_info); - free_text_objects(&subroot); + free_text_objects(&subroot, 1); free(tmp_info); free(str); } } + OBJ(lua_read_parse) { + struct information *tmp_info; + struct text_object subroot, subroot2; + char func[64]; + char *text, *str; + sscanf(obj->data.s, "%64s", func); + text = obj->data.s + strlen(func); + tmp_info = malloc(sizeof(struct information)); + memcpy(tmp_info, cur, sizeof(struct information)); + parse_conky_vars(&subroot, text, p, tmp_info); + DBGP("evaluated '%s' to '%s'", text, p); + + str = llua_getstring_read(func, p); + if (str) { + free_text_objects(&subroot, 1); +// memcpy(tmp_info, cur, sizeof(struct information)); + parse_conky_vars(&subroot2, str, p, tmp_info); + DBGP("evaluated '%s' to '%s'", str, p); + + free(str); + free_text_objects(&subroot2, 1); + } + free_text_objects(&subroot, 1); + free(tmp_info); + } #ifdef X11 OBJ(lua_bar) { int per; @@ -4965,12 +5031,14 @@ static void generate_text_internal(char *p, int p_max_size, * times, we have this special handler. */ break; case OBJ_top: + parse_top_args("top", obj->data.top.s, obj); if (!needed) needed = cur->cpu; case OBJ_top_mem: + parse_top_args("top_mem", obj->data.top.s, obj); if (!needed) needed = cur->memu; case OBJ_top_time: + parse_top_args("top_time", obj->data.top.s, obj); if (!needed) needed = cur->time; - { char *timeval; @@ -6770,7 +6838,7 @@ static void clean_up(void) } #endif /* X11 */ - free_text_objects(&global_root_object); + free_text_objects(&global_root_object, 0); if (tmpstring1) { free(tmpstring1); tmpstring1 = 0; diff --git a/src/llua.c b/src/llua.c index 45e87146..61e3dacb 100644 --- a/src/llua.c +++ b/src/llua.c @@ -30,7 +30,7 @@ lua_State *lua_L = NULL; -void llua_init() +void llua_init(void) { if(lua_L) return; lua_L = lua_open(); @@ -92,6 +92,29 @@ char *llua_do_call(const char *string, int retc) return func; } +/* + * same as llua_do_call() except passes everything after func as one arg. + */ +char *llua_do_read_call(const char *function, const char *arg, int retc) +{ + static char func[64]; + snprintf(func, 64, "conky_%s", function); + + /* push the function name to stack */ + lua_getglobal(lua_L, func); + + /* push function parameter to the stack */ + lua_pushstring(lua_L, arg); + + if (lua_pcall(lua_L, 1, retc, 0) != 0) { + ERR("llua_do_call: function %s execution failed: %s", func, lua_tostring(lua_L, -1)); + lua_pop(lua_L, -1); + return NULL; + } + + return func; +} + char *llua_getstring(const char *args) { char *func; @@ -104,7 +127,27 @@ char *llua_getstring(const char *args) if(!lua_isstring(lua_L, -1)) { ERR("llua_getstring: function %s didn't return a string, result discarded", func); } else { - ret = strdup((char *)lua_tostring(lua_L, -1)); + ret = strdup(lua_tostring(lua_L, -1)); + lua_pop(lua_L, 1); + } + } + + return ret; +} + +char *llua_getstring_read(const char *function, const char *arg) +{ + char *func; + char *ret = NULL; + + if(!lua_L) return NULL; + + func = llua_do_read_call(function, arg, 1); + if (func) { + if(!lua_isstring(lua_L, -1)) { + ERR("llua_getstring_read: function %s didn't return a string, result discarded", func); + } else { + ret = strdup(lua_tostring(lua_L, -1)); lua_pop(lua_L, 1); } } @@ -131,7 +174,7 @@ int llua_getinteger(const char *args, int *per) return 0; } -void llua_close() +void llua_close(void) { if(!lua_L) return; lua_close(lua_L); diff --git a/src/llua.h b/src/llua.h index 6a26bac3..763eb4fe 100644 --- a/src/llua.h +++ b/src/llua.h @@ -1,3 +1,30 @@ +/* Conky, a system monitor, based on torsmo + * + * Any original torsmo code is licensed under the BSD license + * + * All code written since the fork of torsmo is licensed under the GPL + * + * Please see COPYING for details + * + * Copyright (c) 2009 Toni Spets + * Copyright (c) 2005-2009 Brenden Matthews, Philip Kovacs, et. al. + * (see AUTHORS) + * All rights reserved. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + #ifndef LUA_H_ #define LUA_H_ @@ -5,10 +32,11 @@ #include #include -void llua_init(); +void llua_init(void); void llua_load(const char *script); char *llua_getstring(const char *args); +char *llua_getstring_read(const char *function, const char *arg); int llua_getinteger(const char *args, int *per); -void llua_close(); +void llua_close(void); #endif /* LUA_H_*/ diff --git a/src/text_object.h b/src/text_object.h index b185ba41..f6c07b06 100644 --- a/src/text_object.h +++ b/src/text_object.h @@ -382,6 +382,8 @@ enum text_object_type { #endif #ifdef HAVE_LUA OBJ_lua, + OBJ_lua_parse, + OBJ_lua_read_parse, #ifdef X11 OBJ_lua_bar, OBJ_lua_graph, @@ -481,6 +483,8 @@ struct text_object { struct { int num; int type; + int was_parsed; + char *s; } top; struct { From e18e051b666ed4458adbb8368ca3fd06257dcb33 Mon Sep 17 00:00:00 2001 From: Brenden Matthews Date: Sat, 16 May 2009 17:19:15 -0600 Subject: [PATCH 11/12] Fix docs. --- doc/variables.xml | 2 +- extras/nano/conky.nanorc | 2 +- extras/vim/syntax/conkyrc.vim | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/doc/variables.xml b/doc/variables.xml index 35e9bf2b..0cf3250e 100644 --- a/doc/variables.xml +++ b/doc/variables.xml @@ -2363,7 +2363,7 @@ - + diff --git a/extras/nano/conky.nanorc b/extras/nano/conky.nanorc index 509cbafb..fc052a59 100644 --- a/extras/nano/conky.nanorc +++ b/extras/nano/conky.nanorc @@ -11,7 +11,7 @@ color green "\<(alias|alignment|append_file|background|border_margin|border_widt color yellow "\<(above|below|bottom_left|bottom_right|bottom_middle|desktop|dock|no|none|normal|override|skip_pager|skip_taskbar|sticky|top_left|top_right|top_middle|middle_left|middle_right|undecorated|yes)\>" ## Variables -color brightblue "\<(acpiacadapter|acpifan|acpitemp|addr|addrs|adt746xcpu|adt746xfan|alignc|alignr|apcupsd|apcupsd_cable|apcupsd_charge|apcupsd_lastxfer|apcupsd_linev|apcupsd_load|apcupsd_loadbar|apcupsd_loadgauge|apcupsd_loadgraph|apcupsd_model|apcupsd_name|apcupsd_status|apcupsd_temp|apcupsd_timeleft|apcupsd_upsmode|apm_adapter|apm_battery_life|apm_battery_time|audacious_bar|audacious_bitrate|audacious_channels|audacious_filename|audacious_frequency|audacious_length|audacious_length_seconds|audacious_main_volume|audacious_playlist_length|audacious_playlist_position|audacious_position|audacious_position_seconds|audacious_status|audacious_title|battery|battery_bar|battery_percent|battery_short|battery_time|bmpx_album|bmpx_artist|bmpx_bitrate|bmpx_title|bmpx_track|bmpx_uri|buffers|cached|color|color0|color1|color2|color3|color4|color5|color6|color7|color8|color9|combine|conky_build_arch|conky_build_date|conky_version|cpu|cpubar|cpugauge|cpugraph|disk_protect|diskio|diskio_read|diskio_write|diskiograph|diskiograph_read|diskiograph_write|downspeed|downspeedf|downspeedgraph|draft_mails|else|endif|entropy_avail|entropy_bar|entropy_poolsize|eval|eve|exec|execbar|execgauge|execgraph|execi|execibar|execigauge|execigraph|execp|execpi|flagged_mails|font|forwarded_mails|freq|freq_g|fs_bar|fs_bar_free|fs_free|fs_free_perc|fs_size|fs_type|fs_used|fs_used_perc|goto|gw_iface|gw_ip|hddtemp|head|hr|hwmon|i2c|i8k_ac_status|i8k_bios|i8k_buttons_status|i8k_cpu_temp|i8k_left_fan_rpm|i8k_left_fan_status|i8k_right_fan_rpm|i8k_right_fan_status|i8k_serial|i8k_version|ibm_brightness|ibm_fan|ibm_temps|ibm_volume|iconv_start|iconv_stop|if_empty|if_existing|if_gw|if_match|if_mixer_mute|if_mounted|if_mpd_playing|if_running|if_smapi_bat_installed|if_up|if_updatenr|if_xmms2_connected|image|imap_messages|imap_unseen|ioscheduler|kernel|laptop_mode|lines|loadavg|loadgraph|lua|lua_bar|lua_gauge|lua_graph|machine|mails|mboxscan|mem|membar|memeasyfree|memfree|memgauge|memgraph|memmax|memperc|mixer|mixerbar|mixerl|mixerlbar|mixerr|mixerrbar|moc_album|moc_artist|moc_bitrate|moc_curtime|moc_file|moc_rate|moc_song|moc_state|moc_timeleft|moc_title|moc_totaltime|monitor|monitor_number|mpd_album|mpd_artist|mpd_bar|mpd_bitrate|mpd_elapsed|mpd_file|mpd_length|mpd_name|mpd_percent|mpd_random|mpd_repeat|mpd_smart|mpd_status|mpd_title|mpd_track|mpd_vol|nameserver|new_mails|nodename|nvidia|obsd_product|obsd_sensors_fan|obsd_sensors_temp|obsd_sensors_volt|obsd_vendor|offset|outlinecolor|pb_battery|platform|pop3_unseen|pop3_used|pre_exec|processes|replied_mails|rss|running_processes|scroll|seen_mails|shadecolor|smapi|smapi_bat_bar|smapi_bat_perc|smapi_bat_power|smapi_bat_temp|sony_fanspeed|stippled_hr|swap|swapbar|swapmax|swapperc|sysname|tab|tail|tcp_portmon|template0|template1|template2|template3|template4|template5|template6|template7|template8|template9|texeci|time|top|top_mem|top_time|totaldown|totalup|trashed_mails|tztime|unflagged_mails|unforwarded_mails|unreplied_mails|unseen_mails|updates|upspeed|upspeedf|upspeedgraph|uptime|uptime_short|user_names|user_number|user_terms|user_times|utime|voffset|voltage_mv|voltage_v|wireless_ap|wireless_bitrate|wireless_essid|wireless_link_bar|wireless_link_qual|wireless_link_qual_max|wireless_link_qual_perc|wireless_mode|words|xmms2_album|xmms2_artist|xmms2_bar|xmms2_bitrate|xmms2_comment|xmms2_date|xmms2_duration|xmms2_elapsed|xmms2_genre|xmms2_id|xmms2_percent|xmms2_playlist|xmms2_size|xmms2_smart|xmms2_status|xmms2_timesplayed|xmms2_title|xmms2_tracknr|xmms2_url)\>" +color brightblue "\<(acpiacadapter|acpifan|acpitemp|addr|addrs|adt746xcpu|adt746xfan|alignc|alignr|apcupsd|apcupsd_cable|apcupsd_charge|apcupsd_lastxfer|apcupsd_linev|apcupsd_load|apcupsd_loadbar|apcupsd_loadgauge|apcupsd_loadgraph|apcupsd_model|apcupsd_name|apcupsd_status|apcupsd_temp|apcupsd_timeleft|apcupsd_upsmode|apm_adapter|apm_battery_life|apm_battery_time|audacious_bar|audacious_bitrate|audacious_channels|audacious_filename|audacious_frequency|audacious_length|audacious_length_seconds|audacious_main_volume|audacious_playlist_length|audacious_playlist_position|audacious_position|audacious_position_seconds|audacious_status|audacious_title|battery|battery_bar|battery_percent|battery_short|battery_time|bmpx_album|bmpx_artist|bmpx_bitrate|bmpx_title|bmpx_track|bmpx_uri|buffers|cached|color|color0|color1|color2|color3|color4|color5|color6|color7|color8|color9|combine|conky_build_arch|conky_build_date|conky_version|cpu|cpubar|cpugauge|cpugraph|disk_protect|diskio|diskio_read|diskio_write|diskiograph|diskiograph_read|diskiograph_write|downspeed|downspeedf|downspeedgraph|draft_mails|else|endif|entropy_avail|entropy_bar|entropy_poolsize|eval|eve|exec|execbar|execgauge|execgraph|execi|execibar|execigauge|execigraph|execp|execpi|flagged_mails|font|forwarded_mails|freq|freq_g|fs_bar|fs_bar_free|fs_free|fs_free_perc|fs_size|fs_type|fs_used|fs_used_perc|goto|gw_iface|gw_ip|hddtemp|head|hr|hwmon|i2c|i8k_ac_status|i8k_bios|i8k_buttons_status|i8k_cpu_temp|i8k_left_fan_rpm|i8k_left_fan_status|i8k_right_fan_rpm|i8k_right_fan_status|i8k_serial|i8k_version|ibm_brightness|ibm_fan|ibm_temps|ibm_volume|iconv_start|iconv_stop|if_empty|if_existing|if_gw|if_match|if_mixer_mute|if_mounted|if_mpd_playing|if_running|if_smapi_bat_installed|if_up|if_updatenr|if_xmms2_connected|image|imap_messages|imap_unseen|ioscheduler|kernel|laptop_mode|lines|loadavg|loadgraph|lua|lua_bar|lua_gauge|lua_graph|lua_parse|lua_read_parse|machine|mails|mboxscan|mem|membar|memeasyfree|memfree|memgauge|memgraph|memmax|memperc|mixer|mixerbar|mixerl|mixerlbar|mixerr|mixerrbar|moc_album|moc_artist|moc_bitrate|moc_curtime|moc_file|moc_rate|moc_song|moc_state|moc_timeleft|moc_title|moc_totaltime|monitor|monitor_number|mpd_album|mpd_artist|mpd_bar|mpd_bitrate|mpd_elapsed|mpd_file|mpd_length|mpd_name|mpd_percent|mpd_random|mpd_repeat|mpd_smart|mpd_status|mpd_title|mpd_track|mpd_vol|nameserver|new_mails|nodename|nvidia|obsd_product|obsd_sensors_fan|obsd_sensors_temp|obsd_sensors_volt|obsd_vendor|offset|outlinecolor|pb_battery|platform|pop3_unseen|pop3_used|pre_exec|processes|replied_mails|rss|running_processes|scroll|seen_mails|shadecolor|smapi|smapi_bat_bar|smapi_bat_perc|smapi_bat_power|smapi_bat_temp|sony_fanspeed|stippled_hr|swap|swapbar|swapmax|swapperc|sysname|tab|tail|tcp_portmon|template0|template1|template2|template3|template4|template5|template6|template7|template8|template9|texeci|time|top|top_mem|top_time|totaldown|totalup|trashed_mails|tztime|unflagged_mails|unforwarded_mails|unreplied_mails|unseen_mails|updates|upspeed|upspeedf|upspeedgraph|uptime|uptime_short|user_names|user_number|user_terms|user_times|utime|voffset|voltage_mv|voltage_v|wireless_ap|wireless_bitrate|wireless_essid|wireless_link_bar|wireless_link_qual|wireless_link_qual_max|wireless_link_qual_perc|wireless_mode|words|xmms2_album|xmms2_artist|xmms2_bar|xmms2_bitrate|xmms2_comment|xmms2_date|xmms2_duration|xmms2_elapsed|xmms2_genre|xmms2_id|xmms2_percent|xmms2_playlist|xmms2_size|xmms2_smart|xmms2_status|xmms2_timesplayed|xmms2_title|xmms2_tracknr|xmms2_url)\>" color brightblue "\$\{?[0-9A-Z_!@#$*?-]+\}?" color cyan "(\{|\}|\(|\)|\;|\]|\[|`|\\|\$|<|>|!|=|&|\|)" diff --git a/extras/vim/syntax/conkyrc.vim b/extras/vim/syntax/conkyrc.vim index 73db7753..bdba054b 100644 --- a/extras/vim/syntax/conkyrc.vim +++ b/extras/vim/syntax/conkyrc.vim @@ -49,7 +49,7 @@ syn region ConkyrcVar start=/\$\w\@=/ end=/\W\@=\|$/ contained contains=ConkyrcV syn match ConkyrcVarStuff /{\@<=/ms=s contained nextgroup=ConkyrcVarName -syn keyword ConkyrcVarName contained nextgroup=ConkyrcNumber,ConkyrcColour skipwhite acpiacadapter acpifan acpitemp addr addrs adt746xcpu adt746xfan alignc alignr apcupsd apcupsd_cable apcupsd_charge apcupsd_lastxfer apcupsd_linev apcupsd_load apcupsd_loadbar apcupsd_loadgauge apcupsd_loadgraph apcupsd_model apcupsd_name apcupsd_status apcupsd_temp apcupsd_timeleft apcupsd_upsmode apm_adapter apm_battery_life apm_battery_time audacious_bar audacious_bitrate audacious_channels audacious_filename audacious_frequency audacious_length audacious_length_seconds audacious_main_volume audacious_playlist_length audacious_playlist_position audacious_position audacious_position_seconds audacious_status audacious_title battery battery_bar battery_percent battery_short battery_time bmpx_album bmpx_artist bmpx_bitrate bmpx_title bmpx_track bmpx_uri buffers cached color color0 color1 color2 color3 color4 color5 color6 color7 color8 color9 combine conky_build_arch conky_build_date conky_version cpu cpubar cpugauge cpugraph disk_protect diskio diskio_read diskio_write diskiograph diskiograph_read diskiograph_write downspeed downspeedf downspeedgraph draft_mails else endif entropy_avail entropy_bar entropy_poolsize eval eve exec execbar execgauge execgraph execi execibar execigauge execigraph execp execpi flagged_mails font forwarded_mails freq freq_g fs_bar fs_bar_free fs_free fs_free_perc fs_size fs_type fs_used fs_used_perc goto gw_iface gw_ip hddtemp head hr hwmon i2c i8k_ac_status i8k_bios i8k_buttons_status i8k_cpu_temp i8k_left_fan_rpm i8k_left_fan_status i8k_right_fan_rpm i8k_right_fan_status i8k_serial i8k_version ibm_brightness ibm_fan ibm_temps ibm_volume iconv_start iconv_stop if_empty if_existing if_gw if_match if_mixer_mute if_mounted if_mpd_playing if_running if_smapi_bat_installed if_up if_updatenr if_xmms2_connected image imap_messages imap_unseen ioscheduler kernel laptop_mode lines loadavg loadgraph lua lua_bar lua_gauge lua_graph machine mails mboxscan mem membar memeasyfree memfree memgauge memgraph memmax memperc mixer mixerbar mixerl mixerlbar mixerr mixerrbar moc_album moc_artist moc_bitrate moc_curtime moc_file moc_rate moc_song moc_state moc_timeleft moc_title moc_totaltime monitor monitor_number mpd_album mpd_artist mpd_bar mpd_bitrate mpd_elapsed mpd_file mpd_length mpd_name mpd_percent mpd_random mpd_repeat mpd_smart mpd_status mpd_title mpd_track mpd_vol nameserver new_mails nodename nvidia obsd_product obsd_sensors_fan obsd_sensors_temp obsd_sensors_volt obsd_vendor offset outlinecolor pb_battery platform pop3_unseen pop3_used pre_exec processes replied_mails rss running_processes scroll seen_mails shadecolor smapi smapi_bat_bar smapi_bat_perc smapi_bat_power smapi_bat_temp sony_fanspeed stippled_hr swap swapbar swapmax swapperc sysname tab tail tcp_portmon template0 template1 template2 template3 template4 template5 template6 template7 template8 template9 texeci time top top_mem top_time totaldown totalup trashed_mails tztime unflagged_mails unforwarded_mails unreplied_mails unseen_mails updates upspeed upspeedf upspeedgraph uptime uptime_short user_names user_number user_terms user_times utime voffset voltage_mv voltage_v wireless_ap wireless_bitrate wireless_essid wireless_link_bar wireless_link_qual wireless_link_qual_max wireless_link_qual_perc wireless_mode words xmms2_album xmms2_artist xmms2_bar xmms2_bitrate xmms2_comment xmms2_date xmms2_duration xmms2_elapsed xmms2_genre xmms2_id xmms2_percent xmms2_playlist xmms2_size xmms2_smart xmms2_status xmms2_timesplayed xmms2_title xmms2_tracknr xmms2_url +syn keyword ConkyrcVarName contained nextgroup=ConkyrcNumber,ConkyrcColour skipwhite acpiacadapter acpifan acpitemp addr addrs adt746xcpu adt746xfan alignc alignr apcupsd apcupsd_cable apcupsd_charge apcupsd_lastxfer apcupsd_linev apcupsd_load apcupsd_loadbar apcupsd_loadgauge apcupsd_loadgraph apcupsd_model apcupsd_name apcupsd_status apcupsd_temp apcupsd_timeleft apcupsd_upsmode apm_adapter apm_battery_life apm_battery_time audacious_bar audacious_bitrate audacious_channels audacious_filename audacious_frequency audacious_length audacious_length_seconds audacious_main_volume audacious_playlist_length audacious_playlist_position audacious_position audacious_position_seconds audacious_status audacious_title battery battery_bar battery_percent battery_short battery_time bmpx_album bmpx_artist bmpx_bitrate bmpx_title bmpx_track bmpx_uri buffers cached color color0 color1 color2 color3 color4 color5 color6 color7 color8 color9 combine conky_build_arch conky_build_date conky_version cpu cpubar cpugauge cpugraph disk_protect diskio diskio_read diskio_write diskiograph diskiograph_read diskiograph_write downspeed downspeedf downspeedgraph draft_mails else endif entropy_avail entropy_bar entropy_poolsize eval eve exec execbar execgauge execgraph execi execibar execigauge execigraph execp execpi flagged_mails font forwarded_mails freq freq_g fs_bar fs_bar_free fs_free fs_free_perc fs_size fs_type fs_used fs_used_perc goto gw_iface gw_ip hddtemp head hr hwmon i2c i8k_ac_status i8k_bios i8k_buttons_status i8k_cpu_temp i8k_left_fan_rpm i8k_left_fan_status i8k_right_fan_rpm i8k_right_fan_status i8k_serial i8k_version ibm_brightness ibm_fan ibm_temps ibm_volume iconv_start iconv_stop if_empty if_existing if_gw if_match if_mixer_mute if_mounted if_mpd_playing if_running if_smapi_bat_installed if_up if_updatenr if_xmms2_connected image imap_messages imap_unseen ioscheduler kernel laptop_mode lines loadavg loadgraph lua lua_bar lua_gauge lua_graph lua_parse lua_read_parse machine mails mboxscan mem membar memeasyfree memfree memgauge memgraph memmax memperc mixer mixerbar mixerl mixerlbar mixerr mixerrbar moc_album moc_artist moc_bitrate moc_curtime moc_file moc_rate moc_song moc_state moc_timeleft moc_title moc_totaltime monitor monitor_number mpd_album mpd_artist mpd_bar mpd_bitrate mpd_elapsed mpd_file mpd_length mpd_name mpd_percent mpd_random mpd_repeat mpd_smart mpd_status mpd_title mpd_track mpd_vol nameserver new_mails nodename nvidia obsd_product obsd_sensors_fan obsd_sensors_temp obsd_sensors_volt obsd_vendor offset outlinecolor pb_battery platform pop3_unseen pop3_used pre_exec processes replied_mails rss running_processes scroll seen_mails shadecolor smapi smapi_bat_bar smapi_bat_perc smapi_bat_power smapi_bat_temp sony_fanspeed stippled_hr swap swapbar swapmax swapperc sysname tab tail tcp_portmon template0 template1 template2 template3 template4 template5 template6 template7 template8 template9 texeci time top top_mem top_time totaldown totalup trashed_mails tztime unflagged_mails unforwarded_mails unreplied_mails unseen_mails updates upspeed upspeedf upspeedgraph uptime uptime_short user_names user_number user_terms user_times utime voffset voltage_mv voltage_v wireless_ap wireless_bitrate wireless_essid wireless_link_bar wireless_link_qual wireless_link_qual_max wireless_link_qual_perc wireless_mode words xmms2_album xmms2_artist xmms2_bar xmms2_bitrate xmms2_comment xmms2_date xmms2_duration xmms2_elapsed xmms2_genre xmms2_id xmms2_percent xmms2_playlist xmms2_size xmms2_smart xmms2_status xmms2_timesplayed xmms2_title xmms2_tracknr xmms2_url hi def link ConkyrcComment Comment hi def link ConkyrcSetting Keyword From e7bf480d48daed958539101531215c9effa23f66 Mon Sep 17 00:00:00 2001 From: Brenden Matthews Date: Sun, 17 May 2009 21:59:05 -0600 Subject: [PATCH 12/12] Fix null pointer boog in $top stuff. --- src/conky.c | 17 ++++++++--------- src/linux.c | 3 --- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/src/conky.c b/src/conky.c index 33a7e56c..5a2ae336 100644 --- a/src/conky.c +++ b/src/conky.c @@ -4291,7 +4291,7 @@ static void generate_text_internal(char *p, int p_max_size, char func[64]; char *text, *str; sscanf(obj->data.s, "%64s", func); - text = obj->data.s + strlen(func); + text = obj->data.s + strlen(func) + 1; tmp_info = malloc(sizeof(struct information)); memcpy(tmp_info, cur, sizeof(struct information)); @@ -4300,8 +4300,6 @@ static void generate_text_internal(char *p, int p_max_size, str = llua_getstring_read(func, p); if (str) { - free_text_objects(&subroot, 1); -// memcpy(tmp_info, cur, sizeof(struct information)); parse_conky_vars(&subroot2, str, p, tmp_info); DBGP("evaluated '%s' to '%s'", str, p); @@ -5062,29 +5060,30 @@ static void generate_text_internal(char *p, int p_max_size, case OBJ_top_time: parse_top_args("top_time", obj->data.top.s, obj); if (!needed) needed = cur->time; - { + + if (needed[obj->data.top.num]) { char *timeval; switch (obj->data.top.type) { case TOP_NAME: snprintf(p, top_name_width + 1, "%-*s", top_name_width, - needed[obj->data.top.num]->name); + needed[obj->data.top.num]->name); break; case TOP_CPU: snprintf(p, 7, "%6.2f", - needed[obj->data.top.num]->amount); + needed[obj->data.top.num]->amount); break; case TOP_PID: snprintf(p, 6, "%5i", - needed[obj->data.top.num]->pid); + needed[obj->data.top.num]->pid); break; case TOP_MEM: snprintf(p, 7, "%6.2f", - needed[obj->data.top.num]->totalmem); + needed[obj->data.top.num]->totalmem); break; case TOP_TIME: timeval = format_time( - needed[obj->data.top.num]->total_cpu_time, 9); + needed[obj->data.top.num]->total_cpu_time, 9); snprintf(p, 10, "%9s", timeval); free(timeval); break; diff --git a/src/linux.c b/src/linux.c index 3f824641..eb90895d 100644 --- a/src/linux.c +++ b/src/linux.c @@ -65,8 +65,6 @@ #define SHORTSTAT_TEMPL "%*s %llu %llu %llu" #define LONGSTAT_TEMPL "%*s %llu %llu %llu " -static int show_nice_processes; - /* This flag tells the linux routines to use the /proc system where possible, * even if other api's are available, e.g. sysinfo() or getloadavg(). * the reason for this is to allow for /proc-based distributed monitoring. @@ -2081,7 +2079,6 @@ void get_powerbook_batt_info(char *buffer, size_t n, int i) void update_top(void) { - show_nice_processes = 1; process_find_top(info.cpu, info.memu, info.time); info.first_process = get_first_process(); }