added dbus support
[monky] / src / core.c
index ac1a7f3..2ca922d 100644 (file)
@@ -80,6 +80,7 @@
 #include <string.h>
 #include <ctype.h>
 
+
 /* strip a leading /dev/ if any, following symlinks first
  *
  * BEWARE: this function returns a pointer to static content
@@ -160,12 +161,12 @@ struct text_object *construct_text_object(const char *s, const char *arg, long
                if(arg) {
 #ifdef __linux__
                        if(strpbrk(arg, "/.") != NULL) {
-                               /* 
+                               /*
                                 * a bit of paranoia. screen out funky paths
                                 * i hope no device will have a '.' in its name
                                 */
                                NORM_ERR("acpiacadapter: arg must not contain '/' or '.'");
-                       } else 
+                       } else
                                obj->data.opaque = strdup(arg);
 #else
                        NORM_ERR("acpiacadapter: arg is only used on linux");
@@ -245,7 +246,7 @@ struct text_object *construct_text_object(const char *s, const char *arg, long
                if (arg) {
                        sscanf(arg, "%63s", bat);
                } else {
-                       strcpy(bat, "BAT0");
+                       strcpy(bat, "bq27200-0");
                }
                obj->data.s = strndup(bat, text_buffer_size);
        END OBJ(battery_short, 0)
@@ -254,7 +255,7 @@ struct text_object *construct_text_object(const char *s, const char *arg, long
                if (arg) {
                        sscanf(arg, "%63s", bat);
                } else {
-                       strcpy(bat, "BAT0");
+                       strcpy(bat, "bq27200-0");
                }
                obj->data.s = strndup(bat, text_buffer_size);
        END OBJ(battery_time, 0)
@@ -263,7 +264,7 @@ struct text_object *construct_text_object(const char *s, const char *arg, long
                if (arg) {
                        sscanf(arg, "%63s", bat);
                } else {
-                       strcpy(bat, "BAT0");
+                       strcpy(bat, "bq27200-0");
                }
                obj->data.s = strndup(bat, text_buffer_size);
        END OBJ(battery_percent, 0)
@@ -272,18 +273,37 @@ struct text_object *construct_text_object(const char *s, const char *arg, long
                if (arg) {
                        sscanf(arg, "%63s", bat);
                } else {
-                       strcpy(bat, "BAT0");
+                       strcpy(bat, "bq27200-0");
                }
                obj->data.s = strndup(bat, text_buffer_size);
        END OBJ(battery_bar, 0)
                char bat[64];
+
+               arg = scan_bar(obj, arg);
+               if (arg && strlen(arg)>0) {
+                       sscanf(arg, "%63s", bat);
+               } else {
+                       strcpy(bat, "bq27200-0");
+               }
+               obj->data.s = strndup(bat, text_buffer_size);
+       END OBJ(battery_volts, 0)
+               char bat[64];
                if (arg) {
                        sscanf(arg, "%63s", bat);
                } else {
-                       strcpy(bat, "BAT0");
+                       strcpy(bat, "bq27200-0");
                }
-               scan_bar(obj, bat);
                obj->data.s = strndup(bat, text_buffer_size);
+       END OBJ(battery_temp, 0)
+               char bat[64];
+               if (arg) {
+                       sscanf(arg, "%63s", bat);
+               } else {
+                       strcpy(bat, "bq27200-0");
+               }
+               obj->data.s = strndup(bat, text_buffer_size);
+       END OBJ(cell_radio_dbm, 0)
+       END OBJ(cell_radio_percent, 0)
 #endif /* !__OpenBSD__ */
 
 #if defined(__linux__)
@@ -540,6 +560,11 @@ struct text_object *construct_text_object(const char *s, const char *arg, long
                parse_platform_sensor(obj, arg);
        END OBJ_ARG(hwmon, 0, "hwmon needs argumanets")
                parse_hwmon_sensor(obj, arg);
+       END OBJ(addrs, &update_net_stats)
+               parse_net_stat_arg(obj, arg, free_at_crash);
+#endif /* __linux__ */
+       END OBJ(addr, &update_net_stats)
+               parse_net_stat_arg(obj, arg, free_at_crash);
        END
        /* we have four different types of top (top, top_mem, top_time and top_io). To
         * avoid having almost-same code four times, we have this special
@@ -550,12 +575,8 @@ struct text_object *construct_text_object(const char *s, const char *arg, long
                if (!parse_top_args(s, arg, obj)) {
                        return NULL;
                }
-       } else OBJ(addr, &update_net_stats)
-               parse_net_stat_arg(obj, arg, free_at_crash);
-       END OBJ(addrs, &update_net_stats)
-               parse_net_stat_arg(obj, arg, free_at_crash);
-#endif /* __linux__ */
-       END OBJ_ARG(tail, 0, "tail needs arguments")
+       } else
+               OBJ_ARG(tail, 0, "tail needs arguments")
                init_tailhead("tail", arg, obj, free_at_crash);
        END OBJ_ARG(head, 0, "head needs arguments")
                init_tailhead("head", arg, obj, free_at_crash);
@@ -575,7 +596,7 @@ struct text_object *construct_text_object(const char *s, const char *arg, long
                obj->data.s = strndup(arg, text_buffer_size);
        END OBJ_IF_ARG(if_mounted, 0, "if_mounted needs an argument")
                obj->data.s = strndup(arg, text_buffer_size);
-#ifdef __linux__
+#if defined(__linux__) || defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
        END OBJ_IF_ARG(if_running, &update_top, "if_running needs an argument")
                top_running = 1;
                obj->data.s = strndup(arg, text_buffer_size);
@@ -655,6 +676,7 @@ struct text_object *construct_text_object(const char *s, const char *arg, long
                obj->sub = malloc(sizeof(struct text_object));
                extract_variable_text_internal(obj->sub, arg);
        END OBJ(nodename, 0)
+       END OBJ(nodename_short, 0)
        END OBJ_ARG(cmdline_to_pid, 0, "cmdline_to_pid needs a command line as argument")
                scan_cmdline_to_pid_arg(obj, arg, free_at_crash);
        END OBJ_ARG(pid_chroot, 0, "pid_chroot needs a pid as argument")
@@ -784,9 +806,9 @@ struct text_object *construct_text_object(const char *s, const char *arg, long
                obj->sub = malloc(sizeof(struct text_object));
                extract_variable_text_internal(obj->sub, arg);
        END OBJ(processes, &update_total_processes)
-#ifdef __linux__
        END OBJ(running_processes, &update_top)
                top_running = 1;
+#ifdef __linux__
        END OBJ(threads, &update_threads)
        END OBJ(running_threads, &update_stat)
 #else
@@ -964,8 +986,10 @@ struct text_object *construct_text_object(const char *s, const char *arg, long
        END OBJ(xmms2_size, &update_xmms2)
        END OBJ(xmms2_status, &update_xmms2)
        END OBJ(xmms2_percent, &update_xmms2)
+#ifdef X11
        END OBJ(xmms2_bar, &update_xmms2)
                scan_bar(obj, arg);
+#endif
        END OBJ(xmms2_smart, &update_xmms2)
        END OBJ(xmms2_playlist, &update_xmms2)
        END OBJ(xmms2_timesplayed, &update_xmms2)
@@ -991,9 +1015,11 @@ struct text_object *construct_text_object(const char *s, const char *arg, long
        END OBJ(audacious_playlist_length, &update_audacious)
        END OBJ(audacious_playlist_position, &update_audacious)
        END OBJ(audacious_main_volume, &update_audacious)
+#ifdef X11
        END OBJ(audacious_bar, &update_audacious)
                scan_bar(obj, arg);
 #endif
+#endif
 #ifdef BMPX
        END OBJ(bmpx_title, &update_bmpx)
                memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
@@ -1645,6 +1671,12 @@ void free_text_objects(struct text_object *root, int internal)
                        case OBJ_battery_time:
                                free(data.s);
                                break;
+                       case OBJ_battery_volts:
+                               free(data.s);
+                               break;
+                       case OBJ_battery_temp:
+                               free(data.s);
+                               break;
 #endif /* !__OpenBSD__ */
                        case OBJ_execpi:
                        case OBJ_execi: