voltage: outsource printing code
authorPhil Sutter <phil@nwl.cc>
Thu, 12 Nov 2009 23:24:54 +0000 (00:24 +0100)
committerPhil Sutter <phil@nwl.cc>
Thu, 19 Nov 2009 23:02:42 +0000 (00:02 +0100)
src/common.h
src/conky.c
src/linux.c

index a0f006a..4dadab2 100644 (file)
@@ -29,7 +29,8 @@ void update_threads(void);
 void update_running_processes(void);
 void update_stuff(void);
 char get_freq(char *, size_t, const char *, int, unsigned int);
-char get_voltage(char *, size_t, const char *, int, unsigned int);     /* ptarjan */
+void print_voltage_mv(struct text_object *, char *, int);
+void print_voltage_v(struct text_object *, char *, int);
 void update_load_average(void);
 void update_top(void);
 void free_all_processes(void);
index 9b6b14c..bd54960 100644 (file)
@@ -818,18 +818,10 @@ void generate_text_internal(char *p, int p_max_size,
                        }
 #if defined(__linux__)
                        OBJ(voltage_mv) {
-                               static int ok = 1;
-                               if (ok) {
-                                       ok = get_voltage(p, p_max_size, "%.0f", 1,
-                                                       obj->data.i);
-                               }
+                               print_voltage_mv(obj, p, p_max_size);
                        }
                        OBJ(voltage_v) {
-                               static int ok = 1;
-                               if (ok) {
-                                       ok = get_voltage(p, p_max_size, "%'.3f", 1000,
-                                                       obj->data.i);
-                               }
+                               print_voltage_v(obj, p, p_max_size);
                        }
 
 #ifdef HAVE_IWLIB
index f70117f..b4fc672 100644 (file)
@@ -1201,7 +1201,7 @@ char get_freq(char *p_client_buffer, size_t client_buffer_size,
  * Peter Tarjan (ptarjan@citromail.hu) */
 
 /* return cpu voltage in mV (use divisor=1) or V (use divisor=1000) */
-char get_voltage(char *p_client_buffer, size_t client_buffer_size,
+static char get_voltage(char *p_client_buffer, size_t client_buffer_size,
                const char *p_format, int divisor, unsigned int cpu)
 {
        FILE *f;
@@ -1270,6 +1270,22 @@ char get_voltage(char *p_client_buffer, size_t client_buffer_size,
        return 1;
 }
 
+void print_voltage_mv(struct text_object *obj, char *p, int p_max_size)
+{
+       static int ok = 1;
+       if (ok) {
+               ok = get_voltage(p, p_max_size, "%.0f", 1, obj->data.i);
+       }
+}
+
+void print_voltage_v(struct text_object *obj, char *p, int p_max_size)
+{
+       static int ok = 1;
+       if (ok) {
+               ok = get_voltage(p, p_max_size, "%'.3f", 1000, obj->data.i);
+       }
+}
+
 #define ACPI_FAN_DIR "/proc/acpi/fan/"
 
 void get_acpi_fan(char *p_client_buffer, size_t client_buffer_size)