add entropy_perc
authorPhil Sutter <n0-1@freewrt.org>
Thu, 4 Jun 2009 20:51:25 +0000 (22:51 +0200)
committerPhil Sutter <n0-1@freewrt.org>
Thu, 4 Jun 2009 20:51:25 +0000 (22:51 +0200)
There is no rounding done, so e.g. 3.6% get 3%. But double casting and
calling round_to_int() is just too ugly.

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

index de4a21f..d728948 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,6 @@
+2009-06-04
+       * Add entropy_perc printing the available entropy as percentage
+
 2009-05-31
        * Fix hostname resolution for mpd_host
 
index 7860bfa..842d562 100644 (file)
 
        <varlistentry>
                <term>
+                       <command><option>entropy_perc</option></command>
+               </term>
+               <listitem>
+                       Percentage of entropy available in comparison to the poolsize
+                       <para></para></listitem>
+       </varlistentry>
+
+       <varlistentry>
+               <term>
                        <command><option>entropy_poolsize</option></command>
                </term>
                <listitem>
index 0271361..ee20248 100644 (file)
@@ -945,6 +945,7 @@ static void free_text_objects(struct text_object *root, int internal)
                                break;
 #endif /* HDDTEMP */
                        case OBJ_entropy_avail:
+                       case OBJ_entropy_perc:
                        case OBJ_entropy_poolsize:
                        case OBJ_entropy_bar:
                                break;
@@ -2761,6 +2762,7 @@ static struct text_object *construct_text_object(const char *s,
                tcp_portmon_init(arg, &obj->data.tcp_port_monitor);
 #endif /* TCP_PORT_MONITOR */
        END OBJ(entropy_avail, INFO_ENTROPY)
+       END OBJ(entropy_perc, INFO_ENTROPY)
        END OBJ(entropy_poolsize, INFO_ENTROPY)
        END OBJ(entropy_bar, INFO_ENTROPY)
                SIZE_DEFAULTS(bar);
@@ -5395,6 +5397,11 @@ static void generate_text_internal(char *p, int p_max_size,
                        OBJ(entropy_avail) {
                                snprintf(p, p_max_size, "%d", cur->entropy.entropy_avail);
                        }
+                       OBJ(entropy_perc) {
+                               percent_print(p, p_max_size,
+                                             cur->entropy.entropy_avail *
+                                             100 / cur->entropy.poolsize);
+                       }
                        OBJ(entropy_poolsize) {
                                snprintf(p, p_max_size, "%d", cur->entropy.poolsize);
                        }
index f2a2a2f..c2037b7 100644 (file)
@@ -396,6 +396,7 @@ enum text_object_type {
        OBJ_scroll,
        OBJ_combine,
        OBJ_entropy_avail,
+       OBJ_entropy_perc,
        OBJ_entropy_poolsize,
        OBJ_entropy_bar,
 #ifdef APCUPSD