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;
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:
#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:
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:
#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
#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)
* 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)
}
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");
}
} else {
CRIT_ERR("lua needs arguments: <function name> [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 name> [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: <function name> <string to pass>");
+ }
#ifdef X11
END OBJ(lua_bar, 0)
if (arg) {
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;
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) {
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
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) {
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;
struct text_object subroot;
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;
* 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;
}
#endif /* X11 */
- free_text_objects(&global_root_object);
+ free_text_objects(&global_root_object, 0);
if (tmpstring1) {
free(tmpstring1);
tmpstring1 = 0;