mirror of
https://github.com/Llewellynvdm/conky.git
synced 2024-12-28 13:00:45 +00:00
convert OBJ_text to callbacks
This is tricky: there is no such thing as $text. In fact, everything below TEXT in the conkyrc which is NOT a text object will become one of type OBJ_text. To make life easy, introduce a function obj_be_plain_text() converting a given object to the given plain text.
This commit is contained in:
parent
e569803324
commit
c9f1c318aa
@ -794,10 +794,6 @@ void generate_text_internal(char *p, int p_max_size,
|
||||
switch (obj->type) {
|
||||
default:
|
||||
NORM_ERR("not implemented obj type %d", obj->type);
|
||||
OBJ(text) {
|
||||
snprintf(p, p_max_size, "%s", obj->data.s);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
#undef DO_JUMP
|
||||
|
18
src/core.c
18
src/core.c
@ -124,8 +124,7 @@ static struct text_object *create_plain_text(const char *s)
|
||||
|
||||
obj = new_text_object_internal();
|
||||
|
||||
obj->type = OBJ_text;
|
||||
obj->data.s = strndup(s, text_buffer_size);
|
||||
obj_be_plain_text(obj, s);
|
||||
return obj;
|
||||
}
|
||||
|
||||
@ -526,14 +525,11 @@ struct text_object *construct_text_object(const char *s, const char *arg, long
|
||||
obj->callbacks.free = &gen_free_opaque;
|
||||
#endif /* X11 */
|
||||
END OBJ(conky_version, 0)
|
||||
obj->type = OBJ_text;
|
||||
obj->data.s = strdup(VERSION);
|
||||
obj_be_plain_text(obj, VERSION);
|
||||
END OBJ(conky_build_date, 0)
|
||||
obj->type = OBJ_text;
|
||||
obj->data.s = strdup(BUILD_DATE);
|
||||
obj_be_plain_text(obj, BUILD_DATE);
|
||||
END OBJ(conky_build_arch, 0)
|
||||
obj->type = OBJ_text;
|
||||
obj->data.s = strdup(BUILD_ARCH);
|
||||
obj_be_plain_text(obj, BUILD_ARCH);
|
||||
END OBJ(downspeed, &update_net_stats)
|
||||
parse_net_stat_arg(obj, arg, free_at_crash);
|
||||
obj->callbacks.print = &print_downspeed;
|
||||
@ -1547,9 +1543,8 @@ struct text_object *construct_text_object(const char *s, const char *arg, long
|
||||
char buf[text_buffer_size];
|
||||
|
||||
NORM_ERR("unknown variable %s", s);
|
||||
obj->type = OBJ_text;
|
||||
snprintf(buf, text_buffer_size, "${%s}", s);
|
||||
obj->data.s = strndup(buf, text_buffer_size);
|
||||
obj_be_plain_text(obj, buf);
|
||||
}
|
||||
#undef OBJ
|
||||
#undef OBJ_IF
|
||||
@ -1836,9 +1831,6 @@ void free_text_objects(struct text_object *root, int internal)
|
||||
free_text_objects(obj->sub, 1);
|
||||
free(obj->sub);
|
||||
break;
|
||||
case OBJ_text:
|
||||
free(data.s);
|
||||
break;
|
||||
#ifdef __linux__
|
||||
case OBJ_if_gw:
|
||||
case OBJ_gw_iface:
|
||||
|
@ -230,9 +230,8 @@ void scan_pre_exec_arg(struct text_object *obj, const char *arg)
|
||||
{
|
||||
char buf[2048];
|
||||
|
||||
obj->type = OBJ_text;
|
||||
read_exec(arg, buf, sizeof(buf));
|
||||
obj->data.s = strndup(buf, text_buffer_size);
|
||||
obj_be_plain_text(obj, buf);
|
||||
}
|
||||
|
||||
void scan_execi_arg(struct text_object *obj, const char *arg)
|
||||
|
@ -1054,8 +1054,7 @@ static void parse_sysfs_sensor(struct text_object *obj, const char *arg, const c
|
||||
if (!found && sscanf(arg, "%63s %d", buf2, &n) == 2) found = 1; else if (!found) HWMON_RESET();
|
||||
|
||||
if (!found) {
|
||||
NORM_ERR("i2c failed to parse arguments");
|
||||
obj->type = OBJ_text;
|
||||
obj_be_plain_text(obj, "fail");
|
||||
return;
|
||||
}
|
||||
DBGP("parsed %s args: '%s' '%s' %d %f %f\n", type, buf1, buf2, n, factor, offset);
|
||||
|
@ -50,6 +50,13 @@ void gen_print_nothing(struct text_object *obj, char *p, int p_max_size)
|
||||
(void)p_max_size;
|
||||
}
|
||||
|
||||
void gen_print_obj_data_s(struct text_object *obj, char *p, int p_max_size)
|
||||
{
|
||||
if (!obj->data.s)
|
||||
return;
|
||||
snprintf(p, p_max_size, "%s", obj->data.s);
|
||||
}
|
||||
|
||||
/* text_object_list
|
||||
*
|
||||
* this list is special. it looks like this:
|
||||
@ -184,3 +191,13 @@ int ifblock_stack_empty(void **opaque)
|
||||
{
|
||||
return *opaque == NULL;
|
||||
}
|
||||
|
||||
void obj_be_plain_text(struct text_object *obj, const char *text)
|
||||
{
|
||||
obj->type = OBJ_text;
|
||||
obj->data.s = strdup(text);
|
||||
|
||||
memset(&obj->callbacks, 0, sizeof(obj->callbacks));
|
||||
obj->callbacks.print = &gen_print_obj_data_s;
|
||||
obj->callbacks.free = &gen_free_opaque;
|
||||
}
|
||||
|
@ -501,6 +501,10 @@ int gen_false_iftest(struct text_object *);
|
||||
* used for the endif object */
|
||||
void gen_print_nothing(struct text_object *, char *, int);
|
||||
|
||||
/* generic obj->data.s printer
|
||||
* used by the $text object */
|
||||
void gen_print_obj_data_s(struct text_object *, char *, int);
|
||||
|
||||
struct text_object {
|
||||
struct text_object *next, *prev; /* doubly linked list of text objects */
|
||||
struct text_object *sub; /* for objects parsing text into objects */
|
||||
@ -532,4 +536,7 @@ int obj_be_ifblock_else(void **opaque, struct text_object *);
|
||||
int obj_be_ifblock_endif(void **opaque, struct text_object *);
|
||||
int ifblock_stack_empty(void **opaque);
|
||||
|
||||
/* make the given object be a plain text object printing given string */
|
||||
void obj_be_plain_text(struct text_object *, const char *);
|
||||
|
||||
#endif /* _TEXT_OBJECT_H */
|
||||
|
Loading…
Reference in New Issue
Block a user