add eval object, evaluating it's args
authorPhil Sutter <phil@nwl.cc>
Mon, 23 Mar 2009 23:27:51 +0000 (00:27 +0100)
committerPhil Sutter <phil@nwl.cc>
Tue, 24 Mar 2009 00:25:13 +0000 (01:25 +0100)
This object makes use of the possibility to escape dollar signs in TEXT.
Take the following example in the conkyrc:
| $${downspeed ${gw_iface}}
will be evaluated to (assuming the gw_iface is eth0):
| ${downspeed eth0}
and finally interpreted to print the gateway interface's downspeed rate.

ChangeLog
doc/variables.xml
src/conky.c
src/text_object.h

index 04b673d..8d26d02 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,6 @@
+2009-03-24
+       * Added eval text object to realise double parsing
+
 2009-03-16
        * Fix bug with wacky netstat values on startup
 
index bdf0388..e932d6c 100644 (file)
 
        <varlistentry>
                <term>
+                       <command><option>eval</option></command>
+                       <option>string</option>
+               </term>
+               <listitem>
+                       Evalutates given string according to the rules of TEXT interpretation, i.e. parsing any contained text object specifications into their output, any occuring '$$' into a single '$' and so on. The output is then being parsed again.
+                       <para></para></listitem>
+       </varlistentry>
+
+       <varlistentry>
+               <term>
                        <command><option>exec</option></command>
                        <option>command</option>
                </term>
index 83cd965..fc4fee2 100644 (file)
@@ -703,6 +703,7 @@ static void free_text_objects(struct text_object *root)
                        case OBJ_text:
                        case OBJ_font:
                        case OBJ_image:
+                       case OBJ_eval:
                        case OBJ_exec:
                        case OBJ_execgauge:
                        case OBJ_execbar:
@@ -1412,6 +1413,8 @@ static struct text_object *construct_text_object(const char *s,
                obj_be_ifblock_else(ifblock_opaque, obj);
        END OBJ(endif, 0)
                obj_be_ifblock_endif(ifblock_opaque, obj);
+       END OBJ(eval, 0)
+               obj->data.s = strndup(arg ? arg : "", text_buffer_size);
        END OBJ(image, 0)
                obj->data.s = strndup(arg ? arg : "", text_buffer_size);
 #ifdef HAVE_POPEN
@@ -3517,6 +3520,20 @@ static void generate_text_internal(char *p, int p_max_size,
                        }
 #endif /* IMLIB2 */
 
+                       OBJ(eval) {
+                               struct information *tmp_info;
+                               struct text_object subroot, subroot2;
+
+                               tmp_info = malloc(sizeof(struct information));
+                               memcpy(tmp_info, cur, sizeof(struct information));
+                               parse_conky_vars(&subroot, obj->data.s, p, tmp_info);
+                               DBGP("evaluated '%s' to '%s'", obj->data.s, p);
+                               parse_conky_vars(&subroot2, p, p, tmp_info);
+
+                               free_text_objects(&subroot);
+                               free_text_objects(&subroot2);
+                               free(tmp_info);
+                       }
                        OBJ(exec) {
                                read_exec(obj->data.s, p, text_buffer_size);
                                remove_deleted_chars(p);
index ad18bf0..c0e2a8a 100644 (file)
@@ -91,6 +91,7 @@ enum text_object_type {
        OBJ_downspeedgraph,
        OBJ_else,
        OBJ_endif,
+       OBJ_eval,
        OBJ_image,
        OBJ_exec,
        OBJ_execi,