1
0
mirror of https://github.com/Llewellynvdm/conky.git synced 2024-11-15 17:47:09 +00:00

make templateN a lua setting

This commit is contained in:
Pavel Labath 2010-06-21 00:37:58 +02:00
parent 76a1b17e5c
commit c33d617179
3 changed files with 14 additions and 57 deletions

View File

@ -2536,8 +2536,6 @@ void clean_up_without_threads(void *memtofree1, void* memtofree2)
#endif /* BUILD_X11 */
free_templates();
if (info.first_process) {
free_all_processes();
info.first_process = NULL;
@ -2673,8 +2671,6 @@ static void set_default_configurations(void)
stippled_borders = 0;
#endif /* BUILD_X11 */
free_templates();
free(current_mail_spool);
{
char buf[256];
@ -2851,21 +2847,6 @@ char load_config_file(const char *f)
// start the whole if-then-else-if cascade
if (false) {}
#define TEMPLATE_CONF(n) \
CONF("template"#n) { \
if (set_template(n, value)) \
CONF_ERR; \
}
TEMPLATE_CONF(0)
TEMPLATE_CONF(1)
TEMPLATE_CONF(2)
TEMPLATE_CONF(3)
TEMPLATE_CONF(4)
TEMPLATE_CONF(5)
TEMPLATE_CONF(6)
TEMPLATE_CONF(7)
TEMPLATE_CONF(8)
TEMPLATE_CONF(9)
CONF("imap") {
if (value) {
parse_global_imap_mail_args(value);
@ -3714,7 +3695,6 @@ int main(int argc, char **argv)
argv_copy = argv;
g_signal_pending = 0;
max_user_text = MAX_USER_TEXT_DEFAULT;
free_templates();
clear_net_stats();
#ifdef BUILD_PORT_MONITORS

View File

@ -32,42 +32,22 @@
#include <ctype.h>
#include <stdlib.h>
#include <string>
/* The templates defined by the user.
*
* This is a 1 to 1 mapping from templateN config option to template[N] field. */
static char *_template[MAX_TEMPLATES]; //this is named _template because template is a reserved word in c++
/* free all templates
*
* On first invocation, just memset all pointers to zero, so this function can
* be used when initialising data upon startup. */
void free_templates(void)
{
int i;
static int initialised = 0;
if (!initialised) {
memset(_template, 0, MAX_TEMPLATES * sizeof(char *));
initialised = 1;
return;
}
for (i = 0; i < MAX_TEMPLATES; i++) {
free_and_zero(_template[i]);
}
namespace {
conky::simple_config_setting<std::string> _template[10] = {
{ "template0", std::string(), true },
{ "template1", std::string(), true },
{ "template2", std::string(), true },
{ "template3", std::string(), true },
{ "template4", std::string(), true },
{ "template5", std::string(), true },
{ "template6", std::string(), true },
{ "template7", std::string(), true },
{ "template8", std::string(), true },
{ "template9", std::string(), true }
};
}
/* set the value of template at index n
*
* Returns non-zero on illegal arguments passed, zero otherwise. */
int set_template(int n, const char *val)
{
if (n < 0 || n >= MAX_TEMPLATES || !val)
return 1;
free_and_zero(_template[n]);
_template[n] = strdup(val);
return 0;
}
/* backslash_escape - do the actual substitution task for template objects
*
@ -171,7 +151,7 @@ static char *handle_template(const char *tmpl, const char *args)
}
}
eval_text = backslash_escape(_template[template_idx], argsp, argcnt);
eval_text = backslash_escape(_template[template_idx].get(*state).c_str(), argsp, argcnt);
DBGP("substituted %s, output is '%s'", tmpl, eval_text);
free(args_dup);
for (i = 0; i < argcnt; i++)

View File

@ -31,9 +31,6 @@
#ifndef _TEMPLATE_H
#define _TEMPLATE_H
void free_templates(void);
int set_template(int, const char *);
char *find_and_replace_templates(const char *);
int text_contains_templates(const char *);