drop useless ifblock.str
authorPhil Sutter <phil@nwl.cc>
Thu, 29 Oct 2009 02:41:23 +0000 (03:41 +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.h

index f5c9fcb..79edc0b 100644 (file)
@@ -1414,13 +1414,16 @@ void generate_text_internal(char *p, int p_max_size,
                                free(tmp_info);
                        }
                        OBJ(if_existing) {
-                               if (obj->data.ifblock.str
-                                   && !check_contains(obj->data.ifblock.s,
-                                                      obj->data.ifblock.str)) {
-                                       DO_JUMP;
-                               } else if (obj->data.ifblock.s
-                                          && access(obj->data.ifblock.s, F_OK)) {
+                               char *spc;
+
+                               spc = strchr(obj->data.ifblock.s, ' ');
+                               if (!spc && access(obj->data.ifblock.s, F_OK)) {
                                        DO_JUMP;
+                               } else if (spc) {
+                                       *spc = '\0';
+                                       if (check_contains(obj->data.ifblock.s, spc + 1))
+                                               DO_JUMP;
+                                       *spc = ' ';
                                }
                        }
                        OBJ(if_mounted) {
index aa45081..351f832 100644 (file)
@@ -557,17 +557,7 @@ 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")
-               char buf1[256], buf2[256];
-               int r = sscanf(arg, "%255s %255[^\n]", buf1, buf2);
-
-               if (r == 1) {
-                       obj->data.ifblock.s = strndup(buf1, text_buffer_size);
-                       obj->data.ifblock.str = NULL;
-               } else {
-                       obj->data.ifblock.s = strndup(buf1, text_buffer_size);
-                       obj->data.ifblock.str = strndup(buf2, text_buffer_size);
-               }
-               DBGP("if_existing: '%s' '%s'", obj->data.ifblock.s, obj->data.ifblock.str);
+               obj->data.ifblock.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);
 #ifdef __linux__
@@ -1284,7 +1274,6 @@ void free_text_objects(struct text_object *root, int internal)
                        case OBJ_if_mounted:
                        case OBJ_if_running:
                                free(data.ifblock.s);
-                               free(data.ifblock.str);
                                break;
                        case OBJ_head:
                        case OBJ_tail:
@@ -1314,7 +1303,6 @@ void free_text_objects(struct text_object *root, int internal)
                                break;
                        case OBJ_if_gw:
                                free(data.ifblock.s);
-                               free(data.ifblock.str);
                        case OBJ_gw_iface:
                        case OBJ_gw_ip:
                                free_gateway_info();
@@ -1519,7 +1507,6 @@ void free_text_objects(struct text_object *root, int internal)
                                break;
                        case OBJ_if_smapi_bat_installed:
                                free(data.ifblock.s);
-                               free(data.ifblock.str);
                                break;
 #endif /* IBM */
 #ifdef NVIDIA
index 4b51d70..983b7ee 100644 (file)
@@ -441,7 +441,6 @@ struct text_object {
                        struct text_object *next;
                        char *s;
                        int i;
-                       char *str;
                } ifblock;
        } data;