add if_match object comparing strings, floats and ints
[monky] / src / conky.c
index 2a9e4b6..852bf97 100644 (file)
@@ -59,6 +59,7 @@
 #include <getopt.h>
 
 /* local headers */
+#include "algebra.h"
 #include "build.h"
 #include "diskio.h"
 #include "fs.h"
@@ -1267,6 +1268,7 @@ static void free_text_objects(struct text_object *root)
                                }
                                break;
                        case OBJ_if_empty:
+                       case OBJ_if_match:
                        case OBJ_if_existing:
                        case OBJ_if_mounted:
                        case OBJ_if_running:
@@ -2517,6 +2519,14 @@ static struct text_object *construct_text_object(const char *s,
                        obj->data.ifblock.s = strndup(arg, text_buffer_size);
                }
                obj_be_ifblock_if(obj);
+       END OBJ(if_match, 0)
+               if (!arg) {
+                       ERR("if_match needs arguments");
+                       obj->data.ifblock.s = 0;
+               } else {
+                       obj->data.ifblock.s = strndup(arg, text_buffer_size);
+               }
+               obj_be_ifblock_if(obj);
        END OBJ(if_existing, 0)
                if (!arg) {
                        ERR("if_existing needs an argument or two");
@@ -4572,6 +4582,28 @@ static void generate_text_internal(char *p, int p_max_size,
                                free_text_objects(&subroot);
                                free(tmp_info);
                        }
+                       OBJ(if_match) {
+                               char expression[max_user_text];
+                               int val;
+                               struct text_object subroot;
+                               struct information *tmp_info;
+
+                               tmp_info = malloc(sizeof(struct information));
+                               memcpy(tmp_info, cur, sizeof(struct information));
+                               parse_conky_vars(&subroot, obj->data.ifblock.s,
+                                               expression, tmp_info);
+                               DBGP("parsed arg into '%s'", expression);
+
+                               val = compare(expression);
+                               if (val == -2) {
+                                       ERR("compare failed for expression '%s'",
+                                                       expression);
+                               } else if (!val) {
+                                       DO_JUMP;
+                               }
+                               free_text_objects(&subroot);
+                               free(tmp_info);
+                       }
                        OBJ(if_existing) {
                                if (obj->data.ifblock.str
                                    && !check_contains(obj->data.ifblock.s,