xmms2 and audacious bars exist only under X
[monky] / src / core.c
index d221786..5a146f9 100644 (file)
@@ -10,7 +10,7 @@
  * Please see COPYING for details
  *
  * Copyright (c) 2004, Hannu Saransaari and Lauri Hakkarainen
- * Copyright (c) 2005-2009 Brenden Matthews, Philip Kovacs, et. al.
+ * Copyright (c) 2005-2010 Brenden Matthews, Philip Kovacs, et. al.
  *     (see AUTHORS)
  * All rights reserved.
  *
@@ -153,14 +153,26 @@ struct text_object *construct_text_object(const char *s, const char *arg, long
                obj->data.l = get_x11_color(s);
        } else
 #endif /* X11 */
-#ifdef __OpenBSD__
-       OBJ(freq, 0)
-#else
+#ifndef __OpenBSD__
        OBJ(acpitemp, 0)
                obj->data.i = open_acpi_temperature(arg);
        END OBJ(acpiacadapter, 0)
-       END OBJ(freq, 0)
+               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 
+                               obj->data.opaque = strdup(arg);
+#else
+                       NORM_ERR("acpiacadapter: arg is only used on linux");
+#endif
+               }
 #endif /* !__OpenBSD__ */
+       END OBJ(freq, 0)
                get_cpu_count();
                if (!arg || !isdigit(arg[0]) || strlen(arg) >= 2 || atoi(&arg[0]) == 0
                                || atoi(&arg[0]) > info.cpu_count) {
@@ -265,8 +277,9 @@ struct text_object *construct_text_object(const char *s, const char *arg, long
                obj->data.s = strndup(bat, text_buffer_size);
        END OBJ(battery_bar, 0)
                char bat[64];
-               if (arg) {
-                       arg = scan_bar(obj, arg);
+
+               arg = scan_bar(obj, arg);
+               if (arg && strlen(arg)>0) {
                        sscanf(arg, "%63s", bat);
                } else {
                        strcpy(bat, "BAT0");
@@ -358,18 +371,18 @@ struct text_object *construct_text_object(const char *s, const char *arg, long
                scan_loadgraph_arg(obj, arg);
 #endif /* X11 */
        END OBJ(diskio, &update_diskio)
-               parse_diskio_arg(obj, arg);
+               parse_diskio_arg(obj, dev_name(arg));
        END OBJ(diskio_read, &update_diskio)
-               parse_diskio_arg(obj, arg);
+               parse_diskio_arg(obj, dev_name(arg));
        END OBJ(diskio_write, &update_diskio)
-               parse_diskio_arg(obj, arg);
+               parse_diskio_arg(obj, dev_name(arg));
 #ifdef X11
        END OBJ(diskiograph, &update_diskio)
-               parse_diskiograph_arg(obj, arg);
+               parse_diskiograph_arg(obj, dev_name(arg));
        END OBJ(diskiograph_read, &update_diskio)
-               parse_diskiograph_arg(obj, arg);
+               parse_diskiograph_arg(obj, dev_name(arg));
        END OBJ(diskiograph_write, &update_diskio)
-               parse_diskiograph_arg(obj, arg);
+               parse_diskiograph_arg(obj, dev_name(arg));
 #endif /* X11 */
        END OBJ(color, 0)
 #ifdef X11
@@ -528,6 +541,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(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
        /* 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
@@ -538,12 +556,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);
@@ -643,6 +657,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")
@@ -772,9 +787,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
@@ -952,8 +967,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)
@@ -979,9 +996,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));
@@ -1198,9 +1217,9 @@ int extract_variable_text_internal(struct text_object *retval, const char *const
        s = orig_p = p;
 
        if (strcmp(p, const_p)) {
-               DBGP("replaced all templates in text: input is\n'%s'\noutput is\n'%s'", const_p, p);
+               DBGP2("replaced all templates in text: input is\n'%s'\noutput is\n'%s'", const_p, p);
        } else {
-               DBGP("no templates to replace");
+               DBGP2("no templates to replace");
        }
 
        memset(retval, 0, sizeof(struct text_object));
@@ -1252,7 +1271,7 @@ int extract_variable_text_internal(struct text_object *retval, const char *const
                                }
 
                                /* copy variable to buffer */
-                               len = (p - s > text_buffer_size-1) ? text_buffer_size-1 : (p - s);
+                               len = ((unsigned int) (p - s) > text_buffer_size - 1) ? text_buffer_size - 1 : (unsigned int) (p - s);
                                strncpy(buf, s, len);
                                buf[len] = '\0';
 
@@ -1313,7 +1332,7 @@ int extract_variable_text_internal(struct text_object *retval, const char *const
                        strfold(p, 1);
                } else if (*p == '#') {
                        char c;
-                       if (remove_comment(p, &c) && p > orig_p && c == '\n') {
+                       if (remove_comment(p, &c) && p >= orig_p && c == '\n') {
                                /* if remove_comment removed a newline, we need to 'back up' with p */
                                p--;
                        }
@@ -1353,6 +1372,9 @@ void free_text_objects(struct text_object *root, int internal)
                        case OBJ_acpitemp:
                                close(data.i);
                                break;
+                       case OBJ_acpiacadapter:
+                               free(data.opaque);
+                               break;
 #endif /* !__OpenBSD__ */
 #ifdef __linux__
                        case OBJ_i2c: