1
0
mirror of https://github.com/Llewellynvdm/conky.git synced 2025-01-26 00:28:25 +00:00

text_object: completely remove the need for data.ifblock

This commit is contained in:
Phil Sutter 2009-10-29 03:52:59 +01:00
parent 9a770295d1
commit f61d8d108f
4 changed files with 24 additions and 31 deletions

View File

@ -793,7 +793,7 @@ void generate_text_internal(char *p, int p_max_size,
*/ */
#define DO_JUMP { \ #define DO_JUMP { \
DBGP2("jumping"); \ DBGP2("jumping"); \
obj = obj->data.ifblock.next; \ obj = obj->sub; \
} }
#define OBJ(a) break; case OBJ_##a: #define OBJ(a) break; case OBJ_##a:
@ -1162,7 +1162,7 @@ void generate_text_internal(char *p, int p_max_size,
* Do Ninja jump here: without leaving traces. * Do Ninja jump here: without leaving traces.
* This is to prevent us from stale jumped flags. * This is to prevent us from stale jumped flags.
*/ */
obj = obj->data.ifblock.next; obj = obj->sub;
continue; continue;
} }
OBJ(endif) { OBJ(endif) {
@ -1416,27 +1416,27 @@ void generate_text_internal(char *p, int p_max_size,
OBJ(if_existing) { OBJ(if_existing) {
char *spc; char *spc;
spc = strchr(obj->data.ifblock.s, ' '); spc = strchr(obj->data.s, ' ');
if (!spc && access(obj->data.ifblock.s, F_OK)) { if (!spc && access(obj->data.s, F_OK)) {
DO_JUMP; DO_JUMP;
} else if (spc) { } else if (spc) {
*spc = '\0'; *spc = '\0';
if (check_contains(obj->data.ifblock.s, spc + 1)) if (check_contains(obj->data.s, spc + 1))
DO_JUMP; DO_JUMP;
*spc = ' '; *spc = ' ';
} }
} }
OBJ(if_mounted) { OBJ(if_mounted) {
if ((obj->data.ifblock.s) if ((obj->data.s)
&& (!check_mount(obj->data.ifblock.s))) { && (!check_mount(obj->data.s))) {
DO_JUMP; DO_JUMP;
} }
} }
OBJ(if_running) { OBJ(if_running) {
#ifdef __linux__ #ifdef __linux__
if (!get_process_by_name(obj->data.ifblock.s)) { if (!get_process_by_name(obj->data.s)) {
#else #else
if ((obj->data.ifblock.s) && system(obj->data.ifblock.s)) { if ((obj->data.s) && system(obj->data.s)) {
#endif #endif
DO_JUMP; DO_JUMP;
} }
@ -1662,7 +1662,7 @@ void generate_text_internal(char *p, int p_max_size,
snprintf(p, p_max_size, "%d", total_updates); snprintf(p, p_max_size, "%d", total_updates);
} }
OBJ(if_updatenr) { OBJ(if_updatenr) {
if(total_updates % updatereset != obj->data.ifblock.i - 1) { if(total_updates % updatereset != obj->data.i - 1) {
DO_JUMP; DO_JUMP;
} }
} }
@ -2120,7 +2120,7 @@ void generate_text_internal(char *p, int p_max_size,
} }
OBJ(if_smapi_bat_installed) { OBJ(if_smapi_bat_installed) {
int idx; int idx;
if(obj->data.ifblock.s && sscanf(obj->data.ifblock.s, "%i", &idx) == 1) { if(obj->data.s && sscanf(obj->data.s, "%i", &idx) == 1) {
if(!smapi_bat_installed(idx)) { if(!smapi_bat_installed(idx)) {
DO_JUMP; DO_JUMP;
} }

View File

@ -557,19 +557,19 @@ struct text_object *construct_text_object(const char *s, const char *arg, long
obj->sub = malloc(sizeof(struct text_object)); obj->sub = malloc(sizeof(struct text_object));
extract_variable_text_internal(obj->sub, arg); extract_variable_text_internal(obj->sub, arg);
END OBJ_IF_ARG(if_existing, 0, "if_existing needs an argument or two") END OBJ_IF_ARG(if_existing, 0, "if_existing needs an argument or two")
obj->data.ifblock.s = strndup(arg, text_buffer_size); obj->data.s = strndup(arg, text_buffer_size);
END OBJ_IF_ARG(if_mounted, 0, "if_mounted needs an argument") END OBJ_IF_ARG(if_mounted, 0, "if_mounted needs an argument")
obj->data.ifblock.s = strndup(arg, text_buffer_size); obj->data.s = strndup(arg, text_buffer_size);
#ifdef __linux__ #ifdef __linux__
END OBJ_IF_ARG(if_running, &update_top, "if_running needs an argument") END OBJ_IF_ARG(if_running, &update_top, "if_running needs an argument")
top_running = 1; top_running = 1;
obj->data.ifblock.s = strndup(arg, text_buffer_size); obj->data.s = strndup(arg, text_buffer_size);
#else #else
END OBJ_IF_ARG(if_running, 0, "if_running needs an argument") END OBJ_IF_ARG(if_running, 0, "if_running needs an argument")
char buf[256]; char buf[256];
snprintf(buf, 256, "pidof %s >/dev/null", arg); snprintf(buf, 256, "pidof %s >/dev/null", arg);
obj->data.ifblock.s = strndup(buf, text_buffer_size); obj->data.s = strndup(buf, text_buffer_size);
#endif #endif
END OBJ(kernel, 0) END OBJ(kernel, 0)
END OBJ(machine, 0) END OBJ(machine, 0)
@ -680,9 +680,9 @@ struct text_object *construct_text_object(const char *s, const char *arg, long
parse_net_stat_arg(obj, arg, free_at_crash); parse_net_stat_arg(obj, arg, free_at_crash);
END OBJ(updates, 0) END OBJ(updates, 0)
END OBJ_IF(if_updatenr, 0) END OBJ_IF(if_updatenr, 0)
obj->data.ifblock.i = arg ? atoi(arg) : 0; obj->data.i = arg ? atoi(arg) : 0;
if(obj->data.ifblock.i == 0) CRIT_ERR(obj, free_at_crash, "if_updatenr needs a number above 0 as argument"); if(obj->data.i == 0) CRIT_ERR(obj, free_at_crash, "if_updatenr needs a number above 0 as argument");
set_updatereset(obj->data.ifblock.i > get_updatereset() ? obj->data.ifblock.i : get_updatereset()); set_updatereset(obj->data.i > get_updatereset() ? obj->data.i : get_updatereset());
END OBJ(alignr, 0) END OBJ(alignr, 0)
obj->data.i = arg ? atoi(arg) : 0; obj->data.i = arg ? atoi(arg) : 0;
END OBJ(alignc, 0) END OBJ(alignc, 0)
@ -727,7 +727,7 @@ struct text_object *construct_text_object(const char *s, const char *arg, long
END OBJ_ARG(smapi, 0, "smapi needs an argument") END OBJ_ARG(smapi, 0, "smapi needs an argument")
obj->data.s = strndup(arg, text_buffer_size); obj->data.s = strndup(arg, text_buffer_size);
END OBJ_IF_ARG(if_smapi_bat_installed, 0, "if_smapi_bat_installed needs an argument") END OBJ_IF_ARG(if_smapi_bat_installed, 0, "if_smapi_bat_installed needs an argument")
obj->data.ifblock.s = strndup(arg, text_buffer_size); obj->data.s = strndup(arg, text_buffer_size);
END OBJ_ARG(smapi_bat_perc, 0, "smapi_bat_perc needs an argument") END OBJ_ARG(smapi_bat_perc, 0, "smapi_bat_perc needs an argument")
obj->data.s = strndup(arg, text_buffer_size); obj->data.s = strndup(arg, text_buffer_size);
END OBJ_ARG(smapi_bat_temp, 0, "smapi_bat_temp needs an argument") END OBJ_ARG(smapi_bat_temp, 0, "smapi_bat_temp needs an argument")
@ -1273,7 +1273,7 @@ void free_text_objects(struct text_object *root, int internal)
case OBJ_if_existing: case OBJ_if_existing:
case OBJ_if_mounted: case OBJ_if_mounted:
case OBJ_if_running: case OBJ_if_running:
free(data.ifblock.s); free(data.s);
break; break;
case OBJ_head: case OBJ_head:
case OBJ_tail: case OBJ_tail:
@ -1302,7 +1302,7 @@ void free_text_objects(struct text_object *root, int internal)
free(data.s); free(data.s);
break; break;
case OBJ_if_gw: case OBJ_if_gw:
free(data.ifblock.s); free(data.s);
case OBJ_gw_iface: case OBJ_gw_iface:
case OBJ_gw_ip: case OBJ_gw_ip:
free_gateway_info(); free_gateway_info();
@ -1506,7 +1506,7 @@ void free_text_objects(struct text_object *root, int internal)
free(data.s); free(data.s);
break; break;
case OBJ_if_smapi_bat_installed: case OBJ_if_smapi_bat_installed:
free(data.ifblock.s); free(data.s);
break; break;
#endif /* IBM */ #endif /* IBM */
#ifdef NVIDIA #ifdef NVIDIA

View File

@ -107,7 +107,7 @@ static int push_ifblock(struct ifblock_stack_obj **ifblock_stack_top,
case IFBLOCK_ENDIF: case IFBLOCK_ENDIF:
if (!(*ifblock_stack_top)) if (!(*ifblock_stack_top))
CRIT_ERR(NULL, NULL, "got an endif without matching if"); CRIT_ERR(NULL, NULL, "got an endif without matching if");
(*ifblock_stack_top)->obj->data.ifblock.next = obj; (*ifblock_stack_top)->obj->sub = obj;
/* if there's some else in between, remove and free it */ /* if there's some else in between, remove and free it */
if ((*ifblock_stack_top)->type == IFBLOCK_ELSE) { if ((*ifblock_stack_top)->type == IFBLOCK_ELSE) {
stackobj = *ifblock_stack_top; stackobj = *ifblock_stack_top;
@ -122,7 +122,7 @@ static int push_ifblock(struct ifblock_stack_obj **ifblock_stack_top,
case IFBLOCK_ELSE: case IFBLOCK_ELSE:
if (!(*ifblock_stack_top)) if (!(*ifblock_stack_top))
CRIT_ERR(NULL, NULL, "got an else without matching if"); CRIT_ERR(NULL, NULL, "got an else without matching if");
(*ifblock_stack_top)->obj->data.ifblock.next = obj; (*ifblock_stack_top)->obj->sub = obj;
/* fall through */ /* fall through */
case IFBLOCK_IF: case IFBLOCK_IF:
stackobj = malloc(sizeof(struct ifblock_stack_obj)); stackobj = malloc(sizeof(struct ifblock_stack_obj));

View File

@ -435,13 +435,6 @@ struct text_object {
char *s; /* some string */ char *s; /* some string */
int i; /* some integer */ int i; /* some integer */
long l; /* some long integer */ long l; /* some long integer */
struct {
void *opaque; /* temporary workaround to not blow stuff */
struct text_object *next;
char *s;
int i;
} ifblock;
} data; } data;
void *special_data; void *special_data;