text_object: completely remove the need for data.ifblock
authorPhil Sutter <phil@nwl.cc>
Thu, 29 Oct 2009 02:52:59 +0000 (03:52 +0100)
committerPhil Sutter <phil@nwl.cc>
Tue, 3 Nov 2009 22:23:23 +0000 (23:23 +0100)
src/conky.c
src/core.c
src/text_object.c
src/text_object.h

index 79edc0b..9345315 100644 (file)
@@ -793,7 +793,7 @@ void generate_text_internal(char *p, int p_max_size,
  */
 #define DO_JUMP { \
        DBGP2("jumping"); \
-       obj = obj->data.ifblock.next; \
+       obj = obj->sub; \
 }
 
 #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.
                                 * This is to prevent us from stale jumped flags.
                                 */
-                               obj = obj->data.ifblock.next;
+                               obj = obj->sub;
                                continue;
                        }
                        OBJ(endif) {
@@ -1416,27 +1416,27 @@ void generate_text_internal(char *p, int p_max_size,
                        OBJ(if_existing) {
                                char *spc;
 
-                               spc = strchr(obj->data.ifblock.s, ' ');
-                               if (!spc && access(obj->data.ifblock.s, F_OK)) {
+                               spc = strchr(obj->data.s, ' ');
+                               if (!spc && access(obj->data.s, F_OK)) {
                                        DO_JUMP;
                                } else if (spc) {
                                        *spc = '\0';
-                                       if (check_contains(obj->data.ifblock.s, spc + 1))
+                                       if (check_contains(obj->data.s, spc + 1))
                                                DO_JUMP;
                                        *spc = ' ';
                                }
                        }
                        OBJ(if_mounted) {
-                               if ((obj->data.ifblock.s)
-                                               && (!check_mount(obj->data.ifblock.s))) {
+                               if ((obj->data.s)
+                                               && (!check_mount(obj->data.s))) {
                                        DO_JUMP;
                                }
                        }
                        OBJ(if_running) {
 #ifdef __linux__
-                               if (!get_process_by_name(obj->data.ifblock.s)) {
+                               if (!get_process_by_name(obj->data.s)) {
 #else
-                               if ((obj->data.ifblock.s) && system(obj->data.ifblock.s)) {
+                               if ((obj->data.s) && system(obj->data.s)) {
 #endif
                                        DO_JUMP;
                                }
@@ -1662,7 +1662,7 @@ void generate_text_internal(char *p, int p_max_size,
                                snprintf(p, p_max_size, "%d", total_updates);
                        }
                        OBJ(if_updatenr) {
-                               if(total_updates % updatereset != obj->data.ifblock.i - 1) {
+                               if(total_updates % updatereset != obj->data.i - 1) {
                                        DO_JUMP;
                                }
                        }
@@ -2120,7 +2120,7 @@ void generate_text_internal(char *p, int p_max_size,
                        }
                        OBJ(if_smapi_bat_installed) {
                                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)) {
                                                DO_JUMP;
                                        }
index 351f832..92b7370 100644 (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));
                extract_variable_text_internal(obj->sub, arg);
        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")
-               obj->data.ifblock.s = strndup(arg, text_buffer_size);
+               obj->data.s = strndup(arg, text_buffer_size);
 #ifdef __linux__
        END OBJ_IF_ARG(if_running, &update_top, "if_running needs an argument")
                top_running = 1;
-               obj->data.ifblock.s = strndup(arg, text_buffer_size);
+               obj->data.s = strndup(arg, text_buffer_size);
 #else
        END OBJ_IF_ARG(if_running, 0, "if_running needs an argument")
                char buf[256];
 
                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
        END OBJ(kernel, 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);
        END OBJ(updates, 0)
        END OBJ_IF(if_updatenr, 0)
-               obj->data.ifblock.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");
-               set_updatereset(obj->data.ifblock.i > get_updatereset() ? obj->data.ifblock.i : get_updatereset());
+               obj->data.i = arg ? atoi(arg) : 0;
+               if(obj->data.i == 0) CRIT_ERR(obj, free_at_crash, "if_updatenr needs a number above 0 as argument");
+               set_updatereset(obj->data.i > get_updatereset() ? obj->data.i : get_updatereset());
        END OBJ(alignr, 0)
                obj->data.i = arg ? atoi(arg) : 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")
                obj->data.s = strndup(arg, text_buffer_size);
        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")
                obj->data.s = strndup(arg, text_buffer_size);
        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_mounted:
                        case OBJ_if_running:
-                               free(data.ifblock.s);
+                               free(data.s);
                                break;
                        case OBJ_head:
                        case OBJ_tail:
@@ -1302,7 +1302,7 @@ void free_text_objects(struct text_object *root, int internal)
                                free(data.s);
                                break;
                        case OBJ_if_gw:
-                               free(data.ifblock.s);
+                               free(data.s);
                        case OBJ_gw_iface:
                        case OBJ_gw_ip:
                                free_gateway_info();
@@ -1506,7 +1506,7 @@ void free_text_objects(struct text_object *root, int internal)
                                free(data.s);
                                break;
                        case OBJ_if_smapi_bat_installed:
-                               free(data.ifblock.s);
+                               free(data.s);
                                break;
 #endif /* IBM */
 #ifdef NVIDIA
index cbde6b4..c28bc42 100644 (file)
@@ -107,7 +107,7 @@ static int push_ifblock(struct ifblock_stack_obj **ifblock_stack_top,
                case IFBLOCK_ENDIF:
                        if (!(*ifblock_stack_top))
                                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 ((*ifblock_stack_top)->type == IFBLOCK_ELSE) {
                                stackobj = *ifblock_stack_top;
@@ -122,7 +122,7 @@ static int push_ifblock(struct ifblock_stack_obj **ifblock_stack_top,
                case IFBLOCK_ELSE:
                        if (!(*ifblock_stack_top))
                                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 */
                case IFBLOCK_IF:
                        stackobj = malloc(sizeof(struct ifblock_stack_obj));
index 983b7ee..12edede 100644 (file)
@@ -435,13 +435,6 @@ struct text_object {
                char *s;                /* some string */
                int i;                  /* some 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;
 
        void *special_data;