Connect top.c to the build only on Linux.
[monky] / src / conky.c
index 1b21e7b..0e3b3ae 100644 (file)
@@ -746,6 +746,7 @@ enum text_object_type {
        OBJ_alignr,
        OBJ_alignc,
        OBJ_i2c,
+#if defined(__linux__)
        OBJ_i8k_version,
        OBJ_i8k_bios,
        OBJ_i8k_serial,
@@ -757,6 +758,7 @@ enum text_object_type {
        OBJ_i8k_right_fan_rpm,
        OBJ_i8k_ac_status,      
        OBJ_i8k_buttons_status,
+#endif /* __linux__ */
        OBJ_if_existing,
        OBJ_if_mounted,
        OBJ_if_running,
@@ -851,7 +853,7 @@ struct text_object {
                struct fs_stat *fs;
                unsigned char loadavg[3];
                //unsigned int diskio;
-               int cpu_index;
+               unsigned int cpu_index;
                struct {
                        struct fs_stat *fs;
                        int w, h;
@@ -1024,6 +1026,7 @@ if (s[0] == '#') {
        else
                strcpy(bat, "BAT0");
        obj->data.s = strdup(bat);
+#if defined(__linux__)
        END OBJ(i8k_version, INFO_I8K)
        END OBJ(i8k_bios, INFO_I8K)
        END OBJ(i8k_serial, INFO_I8K)
@@ -1035,20 +1038,41 @@ if (s[0] == '#') {
        END OBJ(i8k_right_fan_rpm, INFO_I8K)
        END OBJ(i8k_ac_status, INFO_I8K)
        END OBJ(i8k_buttons_status, INFO_I8K)
+#endif /* __linux__ */
        END OBJ(buffers, INFO_BUFFERS)
        END OBJ(cached, INFO_BUFFERS)
        END OBJ(cpu, INFO_CPU)
-                       if (arg) {
-               if (sscanf(arg, "%i", &obj->data.cpu_index) < 1) {
-                       ERR("$cpu takes an int as an arg");
-                       } else {
-                               obj->data.cpu_index = 1;
-                       }
+               if (arg) {
+               if (strncmp(arg, "cpu", 3) == 0 && isdigit(arg[3])) {
+                       obj->data.cpu_index = atoi(&arg[3]);
+                       arg += 4;
+               } else {obj->data.cpu_index = 0; }
+               } else {
+                               obj->data.cpu_index = 0;
                        }
        END OBJ(cpubar, INFO_CPU)
-        (void) scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
+               if (arg) {
+               if (strncmp(arg, "cpu", 3) == 0 && isdigit(arg[3])) {
+                       obj->data.cpu_index = atoi(&arg[3]);
+                       arg += 4;
+               }
+               else {obj->data.cpu_index = 0;}
+               (void) scan_bar(arg, &obj->a, &obj->b);
+               } else {
+                               (void) scan_bar(arg, &obj->a, &obj->b);
+                               obj->data.cpu_index = 0;
+                       }
        END OBJ(cpugraph, INFO_CPU)
-                       (void) scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d, &obj->e);
+                       if (arg) {
+               if (strncmp(arg, "cpu", 3) == 0 && isdigit(arg[3])) {
+                       obj->data.cpu_index = atoi(&arg[3]);
+                       arg += 4;
+               }
+                               (void) scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d, &obj->e);
+} else {
+       (void) scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d, &obj->e);
+       obj->data.cpu_index = 0;
+                       }
        END OBJ(diskio, INFO_DISKIO)
        END OBJ(diskiograph, INFO_DISKIO) (void) scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d, &obj->e);
        END OBJ(color, 0) 
@@ -1777,6 +1801,10 @@ static void generate_text()
                                human_readable(cur->cached * 1024, p, 255);
                        }
                        OBJ(cpu) {
+                               if (obj->data.cpu_index > info.cpu_count) {
+                                       printf("obj->data.cpu_index %i info.cpu_count %i", obj->data.cpu_index, info.cpu_count);
+                                       CRIT_ERR("attempting to use more CPUs then you have!");
+                               }
                                if (!use_spacer)
                                        snprintf(p, n, "%*d", pad_percents,
                                                (int) (cur->cpu_usage[obj->data.cpu_index] *
@@ -1788,19 +1816,20 @@ static void generate_text()
                                                        100.0));
                        }
                        OBJ(cpubar) {
-                               new_bar(p, obj->data.pair.a,
-                                       obj->data.pair.b,
-                                       (int) (cur->cpu_usage[0] * 255.0));
+                               new_bar(p, obj->a,
+                                       obj->b,
+                                       (int) (cur->cpu_usage[obj->data.cpu_index] * 255.0));
                        }
                        OBJ(cpugraph) {
                                new_graph(p, obj->a,
                                          obj->b, obj->c, obj->d,
-                                         (unsigned int) (cur->cpu_usage[0] *
+                                         (unsigned int) (cur->cpu_usage[obj->data.cpu_index] *
                                                          100), 100, 1);
                        }
                        OBJ(color) {
                                new_fg(p, obj->data.l);
                        }
+#if defined(__linux__)
                        OBJ(i8k_version) {
                                snprintf(p, n, "%s", i8k.version);
                        }
@@ -1862,7 +1891,7 @@ static void generate_text()
                                snprintf(p, n, "%s", i8k.buttons_status); 
 
                        }
-
+#endif /* __linux__ */
 
 #ifdef X11
                        OBJ(font) {