ibm: put specific code to where it belongs
authorPhil Sutter <phil@nwl.cc>
Tue, 13 Oct 2009 21:01:31 +0000 (23:01 +0200)
committerPhil Sutter <phil@nwl.cc>
Tue, 3 Nov 2009 00:50:28 +0000 (01:50 +0100)
src/conky.c
src/core.c
src/ibm.c
src/ibm.h

index 711e481..60c6228 100644 (file)
@@ -1343,9 +1343,7 @@ static void generate_text_internal(char *p, int p_max_size,
                                get_ibm_acpi_fan(p, p_max_size);
                        }
                        OBJ(ibm_temps) {
-                               get_ibm_acpi_temps();
-                               temp_print(p, p_max_size,
-                                          ibm_acpi.temps[obj->data.sensor], TEMP_CELSIUS);
+                               print_ibm_temps(obj, p, p_max_size);
                        }
                        OBJ(ibm_volume) {
                                get_ibm_acpi_volume(p, p_max_size);
index 6decbd3..42d4a8a 100644 (file)
@@ -355,13 +355,8 @@ struct text_object *construct_text_object(const char *s, const char *arg, long
        END OBJ(i8k_buttons_status, &update_i8k)
 #if defined(IBM)
        END OBJ(ibm_fan, 0)
-       END OBJ(ibm_temps, 0, "ibm_temps: needs an argument")
-               if (!isdigit(arg[0]) || strlen(arg) >= 2 || atoi(&arg[0]) >= 8) {
-                       obj->data.sensor = 0;
-                       NORM_ERR("Invalid temperature sensor! Sensor number must be 0 to 7. "
-                               "Using 0 (CPU temp sensor).");
-               } else
-                       obj->data.sensor = atoi(&arg[0]);
+       END OBJ(ibm_temps, &get_ibm_acpi_temps, "ibm_temps: needs an argument")
+               parse_ibm_temps_arg(obj, arg);
        END OBJ(ibm_volume, 0)
        END OBJ(ibm_brightness, 0)
 #endif
index 168c88e..d0a03e8 100644 (file)
--- a/src/ibm.c
+++ b/src/ibm.c
@@ -38,6 +38,8 @@
 #include <string.h>
 #include <stdlib.h>
 
+static int ibm_acpi_temps[8];
+
 /* Here come the IBM ACPI-specific things. For reference, see
  * http://ibm-acpi.sourceforge.net/README
  * If IBM ACPI is installed, /proc/acpi/ibm contains the following files:
@@ -151,9 +153,9 @@ void get_ibm_acpi_temps(void)
                                break;
                        }
                        if (sscanf(line, "temperatures: %d %d %d %d %d %d %d %d",
-                                       &ibm_acpi.temps[0], &ibm_acpi.temps[1], &ibm_acpi.temps[2],
-                                       &ibm_acpi.temps[3], &ibm_acpi.temps[4], &ibm_acpi.temps[5],
-                                       &ibm_acpi.temps[6], &ibm_acpi.temps[7])) {
+                                       &ibm_acpi_temps[0], &ibm_acpi_temps[1], &ibm_acpi_temps[2],
+                                       &ibm_acpi_temps[3], &ibm_acpi_temps[4], &ibm_acpi_temps[5],
+                                       &ibm_acpi_temps[6], &ibm_acpi_temps[7])) {
                                break;
                        }
                }
@@ -264,3 +266,17 @@ void get_ibm_acpi_brightness(char *p_client_buffer, size_t client_buffer_size)
        snprintf(p_client_buffer, client_buffer_size, "%d", brightness);
 }
 
+void parse_ibm_temps_arg(struct text_object *obj, const char *arg)
+{
+       if (!isdigit(arg[0]) || strlen(arg) > 1 || atoi(&arg[0]) >= 8) {
+               obj->data.sensor = 0;
+               NORM_ERR("Invalid temperature sensor! Sensor number must be 0 to 7. "
+                               "Using 0 (CPU temp sensor).");
+       } else
+               obj->data.sensor = atoi(arg);
+}
+
+void print_ibm_temps(struct text_object *obj, char *p, int p_max_size)
+{
+       temp_print(p, p_max_size, ibm_acpi_temps[obj->data.sensor], TEMP_CELSIUS);
+}
index f232acd..de01364 100644 (file)
--- a/src/ibm.h
+++ b/src/ibm.h
@@ -5,15 +5,11 @@
 
 #include <sys/types.h>
 
-struct ibm_acpi_struct {
-       int temps[8];
-};
-
-struct ibm_acpi_struct ibm_acpi;
-
 void get_ibm_acpi_fan(char *buf, size_t client_buffer_size);
 void get_ibm_acpi_temps(void);
 void get_ibm_acpi_volume(char *buf, size_t client_buffer_size);
 void get_ibm_acpi_brightness(char *buf, size_t client_buffer_size);
 
+void parse_ibm_temps_arg(struct text_object *, const char *);
+void print_ibm_temps(struct text_object *, char *, int);
 #endif /* _IBM_H */