gw_info: move code to where it belongs
[monky] / src / core.c
index 23c4701..6decbd3 100644 (file)
@@ -1,4 +1,5 @@
 /* -*- mode: c; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: t -*-
+ * vim: ts=4 sw=4 noet ai cindent syntax=c
  *
  * Conky, a system monitor, based on torsmo
  *
@@ -25,8 +26,6 @@
  * You should have received a copy of the GNU General Public License
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  *
- * vim: ts=4 sw=4 noet ai cindent syntax=c
- *
  */
 
 /* local headers */
@@ -40,6 +39,9 @@
 #include "fonts.h"
 #endif
 #include "fs.h"
+#ifdef HAVE_ICONV
+#include "iconv_tools.h"
+#endif
 #include "logging.h"
 #include "mixer.h"
 #include "mail.h"
 #include "temphelper.h"
 #include "template.h"
 #include "tailhead.h"
+#include "timeinfo.h"
 #include "top.h"
 
+#ifdef NCURSES
+#include <ncurses.h>
+#endif
+
 /* check for OS and include appropriate headers */
 #if defined(__linux__)
 #include "linux.h"
@@ -65,107 +72,6 @@ void update_entropy(void);
 #include <string.h>
 #include <ctype.h>
 
-#ifdef HAVE_ICONV
-#include <iconv.h>
-
-#ifdef NCURSES
-#include <ncurses.h>
-#endif
-
-#define ICONV_CODEPAGE_LENGTH 20
-
-int register_iconv(iconv_t *new_iconv);
-
-long iconv_selected;
-long iconv_count = 0;
-char iconv_converting;
-static iconv_t **iconv_cd = 0;
-
-char is_iconv_converting(void)
-{
-       return iconv_converting;
-}
-
-void set_iconv_converting(char i)
-{
-       iconv_converting = i;
-}
-
-long get_iconv_selected(void)
-{
-       return iconv_selected;
-}
-
-void set_iconv_selected(long i)
-{
-       iconv_selected = i;
-}
-
-int register_iconv(iconv_t *new_iconv)
-{
-       iconv_cd = realloc(iconv_cd, sizeof(iconv_t *) * (iconv_count + 1));
-       if (!iconv_cd) {
-               CRIT_ERR(NULL, NULL, "Out of memory");
-       }
-       iconv_cd[iconv_count] = malloc(sizeof(iconv_t));
-       if (!iconv_cd[iconv_count]) {
-               CRIT_ERR(NULL, NULL, "Out of memory");
-       }
-       memcpy(iconv_cd[iconv_count], new_iconv, sizeof(iconv_t));
-       iconv_count++;
-       return iconv_count;
-}
-
-void free_iconv(void)
-{
-       if (iconv_cd) {
-               long i;
-
-               for (i = 0; i < iconv_count; i++) {
-                       if (iconv_cd[i]) {
-                               iconv_close(*iconv_cd[i]);
-                               free(iconv_cd[i]);
-                       }
-               }
-               free(iconv_cd);
-       }
-       iconv_cd = 0;
-}
-
-void iconv_convert(size_t a, char *buff_in, char *p, size_t p_max_size)
-{
-       if (a > 0 && is_iconv_converting() && get_iconv_selected() > 0
-                       && (iconv_cd[iconv_selected - 1] != (iconv_t) (-1))) {
-               int bytes;
-               size_t dummy1, dummy2;
-#ifdef __FreeBSD__
-               const char *ptr = buff_in;
-#else
-               char *ptr = buff_in;
-#endif
-               char *outptr = p;
-
-               dummy1 = dummy2 = a;
-
-               strncpy(buff_in, p, p_max_size);
-
-               iconv(*iconv_cd[iconv_selected - 1], NULL, NULL, NULL, NULL);
-               while (dummy1 > 0) {
-                       bytes = iconv(*iconv_cd[iconv_selected - 1], &ptr, &dummy1,
-                                       &outptr, &dummy2);
-                       if (bytes == -1) {
-                               NORM_ERR("Iconv codeset conversion failed");
-                               break;
-                       }
-               }
-
-               /* It is nessecary when we are converting from multibyte to
-                * singlebyte codepage */
-               a = outptr - p;
-       }
-}
-#endif /* HAVE_ICONV */
-
 /* strip a leading /dev/ if any, following symlinks first
  *
  * BEWARE: this function returns a pointer to static content
@@ -220,23 +126,19 @@ struct text_object *construct_text_object(const char *s, const char *arg, long
 
        obj->line = line;
 
-#define CALLBACK(x) (-(long)x)
-
-#define OBJ(a, n) if (strcmp(s, #a) == 0) { \
-       obj->type = OBJ_##a; \
-       if (n > 0) { need_mask |= (1ULL << n); } \
-       else if (n < 0) { add_update_callback((void (*)(void))CALLBACK(n)); } {
-#define OBJ_IF(a, n) if (strcmp(s, #a) == 0) { \
-       obj->type = OBJ_##a; obj_be_ifblock_if(ifblock_opaque, obj); \
-       if (n > 0) { need_mask |= (1ULL << n); } \
-       else if (n < 0) { add_update_callback((void (*)(void))CALLBACK(n)); } {
+/* helper defines for internal use only */
+#define __OBJ_HEAD(a, n) if (!strcmp(s, #a)) { \
+       obj->type = OBJ_##a; add_update_callback(n);
+#define __OBJ_IF obj_be_ifblock_if(ifblock_opaque, obj)
+#define __OBJ_ARG(...) if (!arg) { CRIT_ERR(obj, free_at_crash, __VA_ARGS__); }
+
+/* defines to be used below */
+#define OBJ(a, n) __OBJ_HEAD(a, n) {
+#define OBJ_ARG(a, n, ...) __OBJ_HEAD(a, n) __OBJ_ARG(__VA_ARGS__) {
+#define OBJ_IF(a, n) __OBJ_HEAD(a, n) __OBJ_IF; {
+#define OBJ_IF_ARG(a, n, ...) __OBJ_HEAD(a, n) __OBJ_ARG(__VA_ARGS__) __OBJ_IF; {
 #define END } } else
 
-#define SIZE_DEFAULTS(arg) { \
-       obj->a = default_##arg##_width; \
-       obj->b = default_##arg##_height; \
-}
-
 #ifdef X11
        if (s[0] == '#') {
                obj->type = OBJ_color;
@@ -272,20 +174,16 @@ struct text_object *construct_text_object(const char *s, const char *arg, long
                        obj->data.cpu_index = atoi(&arg[0]);
                }
                obj->a = 1;
-       END OBJ(read_tcp, 0)
-               if (arg) {
-                       obj->data.read_tcp.host = malloc(text_buffer_size);
-                       sscanf(arg, "%s", obj->data.read_tcp.host);
-                       sscanf(arg+strlen(obj->data.read_tcp.host), "%u", &(obj->data.read_tcp.port));
-                       if(obj->data.read_tcp.port == 0) {
-                               obj->data.read_tcp.port = atoi(obj->data.read_tcp.host);
-                               strcpy(obj->data.read_tcp.host,"localhost");
-                       }
-                       obj->data.read_tcp.port = htons(obj->data.read_tcp.port);
-                       if(obj->data.read_tcp.port < 1 || obj->data.read_tcp.port > 65535) {
-                               CRIT_ERR(obj, free_at_crash, "read_tcp: Needs \"(host) port\" as argument(s)");
-                       }
-               }else{
+       END OBJ_ARG(read_tcp, 0, "read_tcp: Needs \"(host) port\" as argument(s)")
+               obj->data.read_tcp.host = malloc(text_buffer_size);
+               sscanf(arg, "%s", obj->data.read_tcp.host);
+               sscanf(arg+strlen(obj->data.read_tcp.host), "%u", &(obj->data.read_tcp.port));
+               if(obj->data.read_tcp.port == 0) {
+                       obj->data.read_tcp.port = atoi(obj->data.read_tcp.host);
+                       strcpy(obj->data.read_tcp.host,"localhost");
+               }
+               obj->data.read_tcp.port = htons(obj->data.read_tcp.port);
+               if(obj->data.read_tcp.port < 1 || obj->data.read_tcp.port > 65535) {
                        CRIT_ERR(obj, free_at_crash, "read_tcp: Needs \"(host) port\" as argument(s)");
                }
 #if defined(__linux__)
@@ -313,7 +211,7 @@ struct text_object *construct_text_object(const char *s, const char *arg, long
                obj->a = 1;
 
 #ifdef HAVE_IWLIB
-       END OBJ(wireless_essid, CALLBACK(&update_net_stats))
+       END OBJ(wireless_essid, &update_net_stats)
                if (arg) {
                        obj->data.net = get_net_stat(arg, obj, free_at_crash);
                } else {
@@ -322,7 +220,7 @@ struct text_object *construct_text_object(const char *s, const char *arg, long
                        obj->data.net = get_net_stat(buf, obj, free_at_crash);
                        free(buf);
                }
-       END OBJ(wireless_mode, CALLBACK(&update_net_stats))
+       END OBJ(wireless_mode, &update_net_stats)
                if (arg) {
                        obj->data.net = get_net_stat(arg, obj, free_at_crash);
                } else {
@@ -331,7 +229,7 @@ struct text_object *construct_text_object(const char *s, const char *arg, long
                        obj->data.net = get_net_stat(buf, obj, free_at_crash);
                        free(buf);
                }
-       END OBJ(wireless_bitrate, CALLBACK(&update_net_stats))
+       END OBJ(wireless_bitrate, &update_net_stats)
                if (arg) {
                        obj->data.net = get_net_stat(arg, obj, free_at_crash);
                } else {
@@ -340,7 +238,7 @@ struct text_object *construct_text_object(const char *s, const char *arg, long
                        obj->data.net = get_net_stat(buf, obj, free_at_crash);
                        free(buf);
                }
-       END OBJ(wireless_ap, CALLBACK(&update_net_stats))
+       END OBJ(wireless_ap, &update_net_stats)
                if (arg) {
                        obj->data.net = get_net_stat(arg, obj, free_at_crash);
                } else {
@@ -349,7 +247,7 @@ struct text_object *construct_text_object(const char *s, const char *arg, long
                        obj->data.net = get_net_stat(buf, obj, free_at_crash);
                        free(buf);
                }
-       END OBJ(wireless_link_qual, CALLBACK(&update_net_stats))
+       END OBJ(wireless_link_qual, &update_net_stats)
                if (arg) {
                        obj->data.net = get_net_stat(arg, obj, free_at_crash);
                } else {
@@ -358,7 +256,7 @@ struct text_object *construct_text_object(const char *s, const char *arg, long
                        obj->data.net = get_net_stat(buf, obj, free_at_crash);
                        free(buf);
                }
-       END OBJ(wireless_link_qual_max, CALLBACK(&update_net_stats))
+       END OBJ(wireless_link_qual_max, &update_net_stats)
                if (arg) {
                        obj->data.net = get_net_stat(arg, obj, free_at_crash);
                } else {
@@ -367,7 +265,7 @@ struct text_object *construct_text_object(const char *s, const char *arg, long
                        obj->data.net = get_net_stat(buf, obj, free_at_crash);
                        free(buf);
                }
-       END OBJ(wireless_link_qual_perc, CALLBACK(&update_net_stats))
+       END OBJ(wireless_link_qual_perc, &update_net_stats)
                if (arg) {
                        obj->data.net = get_net_stat(arg, obj, free_at_crash);
                } else {
@@ -376,7 +274,7 @@ struct text_object *construct_text_object(const char *s, const char *arg, long
                        obj->data.net = get_net_stat(buf, obj, free_at_crash);
                        free(buf);
                }
-       END OBJ(wireless_link_bar, CALLBACK(&update_net_stats))
+       END OBJ(wireless_link_bar, &update_net_stats)
                SIZE_DEFAULTS(bar);
                if (arg) {
                        arg = scan_bar(arg, &obj->a, &obj->b);
@@ -443,108 +341,80 @@ struct text_object *construct_text_object(const char *s, const char *arg, long
 #endif /* !__OpenBSD__ */
 
 #if defined(__linux__)
-       END OBJ(disk_protect, 0)
-               if (arg)
-                       obj->data.s = strndup(dev_name(arg), text_buffer_size);
-               else
-                       CRIT_ERR(obj, free_at_crash, "disk_protect needs an argument");
-       END OBJ(i8k_version, CALLBACK(&update_i8k))
-       END OBJ(i8k_bios, CALLBACK(&update_i8k))
-       END OBJ(i8k_serial, CALLBACK(&update_i8k))
-       END OBJ(i8k_cpu_temp, CALLBACK(&update_i8k))
-       END OBJ(i8k_left_fan_status, CALLBACK(&update_i8k))
-       END OBJ(i8k_right_fan_status, CALLBACK(&update_i8k))
-       END OBJ(i8k_left_fan_rpm, CALLBACK(&update_i8k))
-       END OBJ(i8k_right_fan_rpm, CALLBACK(&update_i8k))
-       END OBJ(i8k_ac_status, CALLBACK(&update_i8k))
-       END OBJ(i8k_buttons_status, CALLBACK(&update_i8k))
+       END OBJ_ARG(disk_protect, 0, "disk_protect needs an argument")
+               obj->data.s = strndup(dev_name(arg), text_buffer_size);
+       END OBJ(i8k_version, &update_i8k)
+       END OBJ(i8k_bios, &update_i8k)
+       END OBJ(i8k_serial, &update_i8k)
+       END OBJ(i8k_cpu_temp, &update_i8k)
+       END OBJ(i8k_left_fan_status, &update_i8k)
+       END OBJ(i8k_right_fan_status, &update_i8k)
+       END OBJ(i8k_left_fan_rpm, &update_i8k)
+       END OBJ(i8k_right_fan_rpm, &update_i8k)
+       END OBJ(i8k_ac_status, &update_i8k)
+       END OBJ(i8k_buttons_status, &update_i8k)
 #if defined(IBM)
        END OBJ(ibm_fan, 0)
-       END OBJ(ibm_temps, 0)
-               if (!arg) {
-                       CRIT_ERR(obj, free_at_crash, "ibm_temps: needs an argument");
-               }
+       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).");
-               }
-               obj->data.sensor = atoi(&arg[0]);
+               } else
+                       obj->data.sensor = atoi(&arg[0]);
        END OBJ(ibm_volume, 0)
        END OBJ(ibm_brightness, 0)
 #endif
        /* information from sony_laptop kernel module
         * /sys/devices/platform/sony-laptop */
        END OBJ(sony_fanspeed, 0)
-       END OBJ_IF(if_gw, CALLBACK(&update_gateway_info))
-       END OBJ(ioscheduler, 0)
-               if (!arg) {
-                       CRIT_ERR(obj, free_at_crash, "get_ioscheduler needs an argument (e.g. hda)");
-                       obj->data.s = 0;
-               } else
-                       obj->data.s = strndup(dev_name(arg), text_buffer_size);
+       END OBJ_IF(if_gw, &update_gateway_info)
+       END OBJ_ARG(ioscheduler, 0, "get_ioscheduler needs an argument (e.g. hda)")
+               obj->data.s = strndup(dev_name(arg), text_buffer_size);
        END OBJ(laptop_mode, 0)
-       END OBJ(pb_battery, 0)
-               if (arg && strcmp(arg, "status") == EQUAL) {
+       END OBJ_ARG(pb_battery, 0, "pb_battery: needs one argument: status, percent or time")
+               if (strcmp(arg, "status") == EQUAL) {
                        obj->data.i = PB_BATT_STATUS;
-               } else if (arg && strcmp(arg, "percent") == EQUAL) {
+               } else if (strcmp(arg, "percent") == EQUAL) {
                        obj->data.i = PB_BATT_PERCENT;
-               } else if (arg && strcmp(arg, "time") == EQUAL) {
+               } else if (strcmp(arg, "time") == EQUAL) {
                        obj->data.i = PB_BATT_TIME;
                } else {
-                       NORM_ERR("pb_battery: needs one argument: status, percent or time");
-                       free(obj);
-                       return NULL;
+                       NORM_ERR("pb_battery: illegal argument '%s', defaulting to status", arg);
+                       obj->data.i = PB_BATT_STATUS;
                }
-
 #endif /* __linux__ */
 #if (defined(__FreeBSD__) || defined(__linux__))
-       END OBJ_IF(if_up, 0)
-               if (!arg) {
-                       NORM_ERR("if_up needs an argument");
-                       obj->data.ifblock.s = 0;
-               } else {
-                       obj->data.ifblock.s = strndup(arg, text_buffer_size);
-               }
+       END OBJ_IF_ARG(if_up, 0, "if_up needs an argument")
+               obj->data.ifblock.s = strndup(arg, text_buffer_size);
 #endif
 #if defined(__OpenBSD__)
-       END OBJ(obsd_sensors_temp, 0)
-               if (!arg) {
-                       CRIT_ERR(obj, free_at_crash, "obsd_sensors_temp: needs an argument");
-               }
+       END OBJ_ARG(obsd_sensors_temp, 0, "obsd_sensors_temp: needs an argument")
                if (!isdigit(arg[0]) || atoi(&arg[0]) < 0
                                || atoi(&arg[0]) > OBSD_MAX_SENSORS - 1) {
                        obj->data.sensor = 0;
                        NORM_ERR("Invalid temperature sensor number!");
-               }
-               obj->data.sensor = atoi(&arg[0]);
-       END OBJ(obsd_sensors_fan, 0)
-               if (!arg) {
-                       CRIT_ERR(obj, free_at_crash, "obsd_sensors_fan: needs 2 arguments (device and sensor "
-                               "number)");
-               }
+               } else
+                       obj->data.sensor = atoi(&arg[0]);
+       END OBJ_ARG(obsd_sensors_fan, 0, "obsd_sensors_fan: needs 2 arguments (device and sensor number)")
                if (!isdigit(arg[0]) || atoi(&arg[0]) < 0
                                || atoi(&arg[0]) > OBSD_MAX_SENSORS - 1) {
                        obj->data.sensor = 0;
                        NORM_ERR("Invalid fan sensor number!");
-               }
-               obj->data.sensor = atoi(&arg[0]);
-       END OBJ(obsd_sensors_volt, 0)
-               if (!arg) {
-                       CRIT_ERR(obj, free_at_crash, "obsd_sensors_volt: needs 2 arguments (device and sensor "
-                               "number)");
-               }
+               } else
+                       obj->data.sensor = atoi(&arg[0]);
+       END OBJ_ARG(obsd_sensors_volt, 0, "obsd_sensors_volt: needs 2 arguments (device and sensor number)")
                if (!isdigit(arg[0]) || atoi(&arg[0]) < 0
                                || atoi(&arg[0]) > OBSD_MAX_SENSORS - 1) {
                        obj->data.sensor = 0;
                        NORM_ERR("Invalid voltage sensor number!");
-               }
-               obj->data.sensor = atoi(&arg[0]);
+               } else
+                       obj->data.sensor = atoi(&arg[0]);
        END OBJ(obsd_vendor, 0)
        END OBJ(obsd_product, 0)
 #endif /* __OpenBSD__ */
-       END OBJ(buffers, CALLBACK(&update_meminfo))
-       END OBJ(cached, CALLBACK(&update_meminfo))
+       END OBJ(buffers, &update_meminfo)
+       END OBJ(cached, &update_meminfo)
 #define SCAN_CPU(__arg, __var) { \
        int __offset = 0; \
        if (__arg && sscanf(__arg, " cpu%u %n", &__var, &__offset) > 0) \
@@ -552,23 +422,23 @@ struct text_object *construct_text_object(const char *s, const char *arg, long
        else \
                __var = 0; \
 }
-       END OBJ(cpu, CALLBACK(&update_cpu_usage))
+       END OBJ(cpu, &update_cpu_usage)
                SCAN_CPU(arg, obj->data.cpu_index);
                DBGP2("Adding $cpu for CPU %d", obj->data.cpu_index);
 #ifdef X11
-       END OBJ(cpugauge, CALLBACK(&update_cpu_usage))
+       END OBJ(cpugauge, &update_cpu_usage)
                SIZE_DEFAULTS(gauge);
                SCAN_CPU(arg, obj->data.cpu_index);
                scan_gauge(arg, &obj->a, &obj->b);
                DBGP2("Adding $cpugauge for CPU %d", obj->data.cpu_index);
 #endif /* X11 */
-       END OBJ(cpubar, CALLBACK(&update_cpu_usage))
+       END OBJ(cpubar, &update_cpu_usage)
                SIZE_DEFAULTS(bar);
                SCAN_CPU(arg, obj->data.cpu_index);
                scan_bar(arg, &obj->a, &obj->b);
                DBGP2("Adding $cpubar for CPU %d", obj->data.cpu_index);
 #ifdef X11
-       END OBJ(cpugraph, CALLBACK(&update_cpu_usage))
+       END OBJ(cpugraph, &update_cpu_usage)
                char *buf = 0;
                SIZE_DEFAULTS(graph);
                SCAN_CPU(arg, obj->data.cpu_index);
@@ -576,7 +446,7 @@ struct text_object *construct_text_object(const char *s, const char *arg, long
                        &obj->e, &obj->char_a, &obj->char_b);
                DBGP2("Adding $cpugraph for CPU %d", obj->data.cpu_index);
                if (buf) free(buf);
-       END OBJ(loadgraph, CALLBACK(&update_load_average))
+       END OBJ(loadgraph, &update_load_average)
                char *buf = 0;
                SIZE_DEFAULTS(graph);
                buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
@@ -590,14 +460,14 @@ struct text_object *construct_text_object(const char *s, const char *arg, long
                        free(buf);
                }
 #endif /* X11 */
-       END OBJ(diskio, CALLBACK(&update_diskio))
+       END OBJ(diskio, &update_diskio)
                obj->data.diskio = prepare_diskio_stat(dev_name(arg));
-       END OBJ(diskio_read, CALLBACK(&update_diskio))
+       END OBJ(diskio_read, &update_diskio)
                obj->data.diskio = prepare_diskio_stat(dev_name(arg));
-       END OBJ(diskio_write, CALLBACK(&update_diskio))
+       END OBJ(diskio_write, &update_diskio)
                obj->data.diskio = prepare_diskio_stat(dev_name(arg));
 #ifdef X11
-       END OBJ(diskiograph, CALLBACK(&update_diskio))
+       END OBJ(diskiograph, &update_diskio)
                char *buf = 0;
                SIZE_DEFAULTS(graph);
                buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
@@ -605,7 +475,7 @@ struct text_object *construct_text_object(const char *s, const char *arg, long
 
                obj->data.diskio = prepare_diskio_stat(dev_name(buf));
                if (buf) free(buf);
-       END OBJ(diskiograph_read, CALLBACK(&update_diskio))
+       END OBJ(diskiograph_read, &update_diskio)
                char *buf = 0;
                SIZE_DEFAULTS(graph);
                buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
@@ -613,7 +483,7 @@ struct text_object *construct_text_object(const char *s, const char *arg, long
 
                obj->data.diskio = prepare_diskio_stat(dev_name(buf));
                if (buf) free(buf);
-       END OBJ(diskiograph_write, CALLBACK(&update_diskio))
+       END OBJ(diskiograph_write, &update_diskio)
                char *buf = 0;
                SIZE_DEFAULTS(graph);
                buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
@@ -690,7 +560,7 @@ struct text_object *construct_text_object(const char *s, const char *arg, long
        END OBJ(conky_version, 0)
        END OBJ(conky_build_date, 0)
        END OBJ(conky_build_arch, 0)
-       END OBJ(downspeed, CALLBACK(&update_net_stats))
+       END OBJ(downspeed, &update_net_stats)
                if (arg) {
                        obj->data.net = get_net_stat(arg, obj, free_at_crash);
                } else {
@@ -699,7 +569,7 @@ struct text_object *construct_text_object(const char *s, const char *arg, long
                        obj->data.net = get_net_stat(buf, obj, free_at_crash);
                        free(buf);
                }
-       END OBJ(downspeedf, CALLBACK(&update_net_stats))
+       END OBJ(downspeedf, &update_net_stats)
                if (arg) {
                        obj->data.net = get_net_stat(arg, obj, free_at_crash);
                } else {
@@ -709,7 +579,7 @@ struct text_object *construct_text_object(const char *s, const char *arg, long
                        free(buf);
                }
 #ifdef X11
-       END OBJ(downspeedgraph, CALLBACK(&update_net_stats))
+       END OBJ(downspeedgraph, &update_net_stats)
                char *buf = 0;
                SIZE_DEFAULTS(graph);
                buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
@@ -726,8 +596,10 @@ struct text_object *construct_text_object(const char *s, const char *arg, long
                obj_be_ifblock_endif(ifblock_opaque, obj);
        END OBJ(eval, 0)
                obj->data.s = strndup(arg ? arg : "", text_buffer_size);
+#if defined(IMLIB2) && defined(X11)
        END OBJ(image, 0)
                obj->data.s = strndup(arg ? arg : "", text_buffer_size);
+#endif /* IMLIB2 */
        END OBJ(exec, 0)
                obj->data.s = strndup(arg ? arg : "", text_buffer_size);
        END OBJ(execp, 0)
@@ -840,84 +712,50 @@ struct text_object *construct_text_object(const char *s, const char *arg, long
                } else {
                        obj->data.s = strndup("", text_buffer_size);
                }
-       END OBJ(fs_bar, CALLBACK(&update_fs_stats))
-               SIZE_DEFAULTS(bar);
-               arg = scan_bar(arg, &obj->data.fsbar.w, &obj->data.fsbar.h);
-               if (arg) {
-                       while (isspace(*arg)) {
-                               arg++;
-                       }
-                       if (*arg == '\0') {
-                               arg = "/";
-                       }
-               } else {
-                       arg = "/";
-               }
-               obj->data.fsbar.fs = prepare_fs_stat(arg);
-       END OBJ(fs_bar_free, CALLBACK(&update_fs_stats))
-               SIZE_DEFAULTS(bar);
-               arg = scan_bar(arg, &obj->data.fsbar.w, &obj->data.fsbar.h);
-               if (arg) {
-                       while (isspace(*arg)) {
-                               arg++;
-                       }
-                       if (*arg == '\0') {
-                               arg = "/";
-                       }
-               } else {
-                       arg = "/";
-               }
-
-               obj->data.fsbar.fs = prepare_fs_stat(arg);
-       END OBJ(fs_free, CALLBACK(&update_fs_stats))
+       END OBJ(fs_bar, &update_fs_stats)
+               init_fs_bar(obj, arg);
+       END OBJ(fs_bar_free, &update_fs_stats)
+               init_fs_bar(obj, arg);
+       END OBJ(fs_free, &update_fs_stats)
                if (!arg) {
                        arg = "/";
                }
                obj->data.fs = prepare_fs_stat(arg);
-       END OBJ(fs_used_perc, CALLBACK(&update_fs_stats))
+       END OBJ(fs_used_perc, &update_fs_stats)
                if (!arg) {
                        arg = "/";
                }
                obj->data.fs = prepare_fs_stat(arg);
-       END OBJ(fs_free_perc, CALLBACK(&update_fs_stats))
+       END OBJ(fs_free_perc, &update_fs_stats)
                if (!arg) {
                        arg = "/";
                }
                obj->data.fs = prepare_fs_stat(arg);
-       END OBJ(fs_size, CALLBACK(&update_fs_stats))
+       END OBJ(fs_size, &update_fs_stats)
                if (!arg) {
                        arg = "/";
                }
                obj->data.fs = prepare_fs_stat(arg);
-       END OBJ(fs_type, CALLBACK(&update_fs_stats))
+       END OBJ(fs_type, &update_fs_stats)
                if (!arg) {
                        arg = "/";
                }
                obj->data.fs = prepare_fs_stat(arg);
-       END OBJ(fs_used, CALLBACK(&update_fs_stats))
+       END OBJ(fs_used, &update_fs_stats)
                if (!arg) {
                        arg = "/";
                }
                obj->data.fs = prepare_fs_stat(arg);
        END OBJ(hr, 0)
                obj->data.i = arg ? atoi(arg) : 1;
-       END OBJ(nameserver, CALLBACK(&update_dns_data))
+       END OBJ(nameserver, &update_dns_data)
                obj->data.i = arg ? atoi(arg) : 0;
        END OBJ(offset, 0)
                obj->data.i = arg ? atoi(arg) : 1;
        END OBJ(voffset, 0)
                obj->data.i = arg ? atoi(arg) : 1;
-       END OBJ(goto, 0)
-
-               if (!arg) {
-                       NORM_ERR("goto needs arguments");
-                       obj->type = OBJ_text;
-                       obj->data.s = strndup("${goto}", text_buffer_size);
-                       return NULL;
-               }
-
+       END OBJ_ARG(goto, 0, "goto needs arguments")
                obj->data.i = atoi(arg);
-
        END OBJ(tab, 0)
                int a = 10, b = 0;
 
@@ -933,99 +771,13 @@ struct text_object *construct_text_object(const char *s, const char *arg, long
                obj->data.pair.b = b;
 
 #ifdef __linux__
-       END OBJ(i2c, 0)
-               char buf1[64], buf2[64];
-               float factor, offset;
-               int n, found = 0;
-
-               if (!arg) {
-                       NORM_ERR("i2c needs arguments");
-                       obj->type = OBJ_text;
-                       // obj->data.s = strndup("${i2c}", text_buffer_size);
-                       return NULL;
-               }
-
-#define HWMON_RESET() {\
-               buf1[0] = 0; \
-               factor = 1.0; \
-               offset = 0.0; }
-
-               if (sscanf(arg, "%63s %d %f %f", buf2, &n, &factor, &offset) == 4) found = 1; else HWMON_RESET();
-               if (!found && sscanf(arg, "%63s %63s %d %f %f", buf1, buf2, &n, &factor, &offset) == 5) found = 1; else if (!found) HWMON_RESET();
-               if (!found && sscanf(arg, "%63s %63s %d", buf1, buf2, &n) == 3) found = 1; else if (!found) HWMON_RESET();
-               if (!found && sscanf(arg, "%63s %d", buf2, &n) == 2) found = 1; else if (!found) HWMON_RESET();
-
-               if (!found) {
-                       NORM_ERR("i2c failed to parse arguments");
-                       obj->type = OBJ_text;
-                       return NULL;
-               }
-               DBGP("parsed i2c args: '%s' '%s' %d %f %f\n", buf1, buf2, n, factor, offset);
-               obj->data.sysfs.fd = open_i2c_sensor((*buf1) ? buf1 : 0, buf2, n,
-                               &obj->data.sysfs.arg, obj->data.sysfs.devtype);
-               strncpy(obj->data.sysfs.type, buf2, 63);
-               obj->data.sysfs.factor = factor;
-               obj->data.sysfs.offset = offset;
-
-       END OBJ(platform, 0)
-               char buf1[64], buf2[64];
-               float factor, offset;
-               int n, found = 0;
-
-               if (!arg) {
-                       NORM_ERR("platform needs arguments");
-                       obj->type = OBJ_text;
-                       return NULL;
-               }
-
-               if (sscanf(arg, "%63s %d %f %f", buf2, &n, &factor, &offset) == 4) found = 1; else HWMON_RESET();
-               if (!found && sscanf(arg, "%63s %63s %d %f %f", buf1, buf2, &n, &factor, &offset) == 5) found = 1; else if (!found) HWMON_RESET();
-               if (!found && sscanf(arg, "%63s %63s %d", buf1, buf2, &n) == 3) found = 1; else if (!found) HWMON_RESET();
-               if (!found && sscanf(arg, "%63s %d", buf2, &n) == 2) found = 1; else if (!found) HWMON_RESET();
-
-               if (!found) {
-                       NORM_ERR("platform failed to parse arguments");
-                       obj->type = OBJ_text;
-                       return NULL;
-               }
-               DBGP("parsed platform args: '%s' '%s' %d %f %f", buf1, buf2, n, factor, offset);
-               obj->data.sysfs.fd = open_platform_sensor((*buf1) ? buf1 : 0, buf2, n,
-                               &obj->data.sysfs.arg, obj->data.sysfs.devtype);
-               strncpy(obj->data.sysfs.type, buf2, 63);
-               obj->data.sysfs.factor = factor;
-               obj->data.sysfs.offset = offset;
-
-       END OBJ(hwmon, 0)
-               char buf1[64], buf2[64];
-               float factor, offset;
-               int n, found = 0;
-
-               if (!arg) {
-                       NORM_ERR("hwmon needs argumanets");
-                       obj->type = OBJ_text;
-                       return NULL;
-               }
-
-               if (sscanf(arg, "%63s %d %f %f", buf2, &n, &factor, &offset) == 4) found = 1; else HWMON_RESET();
-               if (!found && sscanf(arg, "%63s %63s %d %f %f", buf1, buf2, &n, &factor, &offset) == 5) found = 1; else if (!found) HWMON_RESET();
-               if (!found && sscanf(arg, "%63s %63s %d", buf1, buf2, &n) == 3) found = 1; else if (!found) HWMON_RESET();
-               if (!found && sscanf(arg, "%63s %d", buf2, &n) == 2) found = 1; else if (!found) HWMON_RESET();
-
-#undef HWMON_RESET
-
-               if (!found) {
-                       NORM_ERR("hwmon failed to parse arguments");
-                       obj->type = OBJ_text;
-                       return NULL;
-               }
-               DBGP("parsed hwmon args: '%s' '%s' %d %f %f\n", buf1, buf2, n, factor, offset);
-               obj->data.sysfs.fd = open_hwmon_sensor((*buf1) ? buf1 : 0, buf2, n,
-                               &obj->data.sysfs.arg, obj->data.sysfs.devtype);
-               strncpy(obj->data.sysfs.type, buf2, 63);
-               obj->data.sysfs.factor = factor;
-               obj->data.sysfs.offset = offset;
-
-#endif /* !__OpenBSD__ */
+       END OBJ_ARG(i2c, 0, "i2c needs arguments")
+               parse_i2c_sensor(obj, arg);
+       END OBJ_ARG(platform, 0, "platform needs arguments")
+               parse_platform_sensor(obj, arg);
+       END OBJ_ARG(hwmon, 0, "hwmon needs argumanets")
+               parse_hwmon_sensor(obj, arg);
+#endif /* __linux__ */
 
        END
        /* we have four different types of top (top, top_mem, top_time and top_io). To
@@ -1033,10 +785,11 @@ struct text_object *construct_text_object(const char *s, const char *arg, long
         * handler. */
        if (strncmp(s, "top", 3) == EQUAL) {
                add_update_callback(&update_meminfo);
+               add_update_callback(&update_top);
                if (!parse_top_args(s, arg, obj)) {
                        return NULL;
                }
-       } else OBJ(addr, CALLBACK(&update_net_stats))
+       } else OBJ(addr, &update_net_stats)
                if (arg) {
                        obj->data.net = get_net_stat(arg, obj, free_at_crash);
                } else {
@@ -1046,7 +799,7 @@ struct text_object *construct_text_object(const char *s, const char *arg, long
                        free(buf);
                }
 #if defined(__linux__)
-       END OBJ(addrs, CALLBACK(&update_net_stats))
+       END OBJ(addrs, &update_net_stats)
                if (arg) {
                        obj->data.net = get_net_stat(arg, obj, free_at_crash);
                } else {
@@ -1056,23 +809,15 @@ struct text_object *construct_text_object(const char *s, const char *arg, long
                        free(buf);
                }
 #endif /* __linux__ */
-       END OBJ(tail, 0)
+       END OBJ_ARG(tail, 0, "tail needs arguments")
                init_tailhead("tail", arg, obj, free_at_crash);
-       END OBJ(head, 0)
+       END OBJ_ARG(head, 0, "head needs arguments")
                init_tailhead("head", arg, obj, free_at_crash);
-       END OBJ(lines, 0)
-               if (arg) {
-                       obj->data.s = strndup(arg, text_buffer_size);
-               }else{
-                       CRIT_ERR(obj, free_at_crash, "lines needs a argument");
-               }
-       END OBJ(words, 0)
-               if (arg) {
-                       obj->data.s = strndup(arg, text_buffer_size);
-               }else{
-                       CRIT_ERR(obj, free_at_crash, "words needs a argument");
-               }
-       END OBJ(loadavg, CALLBACK(&update_load_average))
+       END OBJ_ARG(lines, 0, "lines needs an argument")
+               obj->data.s = strndup(arg, text_buffer_size);
+       END OBJ_ARG(words, 0, "words needs a argument")
+               obj->data.s = strndup(arg, text_buffer_size);
+       END OBJ(loadavg, &update_load_average)
                int a = 1, b = 2, c = 3, r = 3;
 
                if (arg) {
@@ -1090,68 +835,39 @@ struct text_object *construct_text_object(const char *s, const char *arg, long
                obj->data.loadavg[0] = (r >= 1) ? (unsigned char) a : 0;
                obj->data.loadavg[1] = (r >= 2) ? (unsigned char) b : 0;
                obj->data.loadavg[2] = (r >= 3) ? (unsigned char) c : 0;
-       END OBJ_IF(if_empty, 0)
-               if (!arg) {
-                       NORM_ERR("if_empty needs an argument");
-                       obj->data.ifblock.s = 0;
-               } else {
-                       obj->data.ifblock.s = strndup(arg, text_buffer_size);
-                       obj->sub = malloc(sizeof(struct text_object));
-                       extract_variable_text_internal(obj->sub,
-                                                      obj->data.ifblock.s);
-               }
-       END OBJ_IF(if_match, 0)
-               if (!arg) {
-                       NORM_ERR("if_match needs arguments");
-                       obj->data.ifblock.s = 0;
-               } else {
-                       obj->data.ifblock.s = strndup(arg, text_buffer_size);
-                       obj->sub = malloc(sizeof(struct text_object));
-                       extract_variable_text_internal(obj->sub,
-                                                      obj->data.ifblock.s);
-               }
-       END OBJ_IF(if_existing, 0)
-               if (!arg) {
-                       NORM_ERR("if_existing needs an argument or two");
-                       obj->data.ifblock.s = NULL;
+       END OBJ_IF_ARG(if_empty, 0, "if_empty needs an argument")
+               obj->data.ifblock.s = strndup(arg, text_buffer_size);
+               obj->sub = malloc(sizeof(struct text_object));
+               extract_variable_text_internal(obj->sub, obj->data.ifblock.s);
+       END OBJ_IF_ARG(if_match, 0, "if_match needs arguments")
+               obj->data.ifblock.s = strndup(arg, text_buffer_size);
+               obj->sub = malloc(sizeof(struct text_object));
+               extract_variable_text_internal(obj->sub, obj->data.ifblock.s);
+       END OBJ_IF_ARG(if_existing, 0, "if_existing needs an argument or two")
+               char buf1[256], buf2[256];
+               int r = sscanf(arg, "%255s %255[^\n]", buf1, buf2);
+
+               if (r == 1) {
+                       obj->data.ifblock.s = strndup(buf1, text_buffer_size);
                        obj->data.ifblock.str = NULL;
                } else {
-                       char buf1[256], buf2[256];
-                       int r = sscanf(arg, "%255s %255[^\n]", buf1, buf2);
-
-                       if (r == 1) {
-                               obj->data.ifblock.s = strndup(buf1, text_buffer_size);
-                               obj->data.ifblock.str = NULL;
-                       } else {
-                               obj->data.ifblock.s = strndup(buf1, text_buffer_size);
-                               obj->data.ifblock.str = strndup(buf2, text_buffer_size);
-                       }
+                       obj->data.ifblock.s = strndup(buf1, text_buffer_size);
+                       obj->data.ifblock.str = strndup(buf2, text_buffer_size);
                }
                DBGP("if_existing: '%s' '%s'", obj->data.ifblock.s, obj->data.ifblock.str);
-       END OBJ_IF(if_mounted, 0)
-               if (!arg) {
-                       NORM_ERR("if_mounted needs an argument");
-                       obj->data.ifblock.s = 0;
-               } else {
-                       obj->data.ifblock.s = strndup(arg, text_buffer_size);
-               }
+       END OBJ_IF_ARG(if_mounted, 0, "if_mounted needs an argument")
+               obj->data.ifblock.s = strndup(arg, text_buffer_size);
 #ifdef __linux__
-       END OBJ_IF(if_running, CALLBACK(&update_top))
-               if (arg) {
-                       top_running = 1;
-                       obj->data.ifblock.s = strndup(arg, text_buffer_size);
+       END OBJ_IF_ARG(if_running, &update_top, "if_running needs an argument")
+               top_running = 1;
+               obj->data.ifblock.s = strndup(arg, text_buffer_size);
 #else
-       END OBJ_IF(if_running, 0)
-               if (arg) {
-                       char buf[256];
+       END OBJ_IF_ARG(if_running, 0, "if_running needs an argument")
+               char buf[256];
 
-                       snprintf(buf, 256, "pidof %s >/dev/null", arg);
-                       obj->data.ifblock.s = strndup(buf, text_buffer_size);
+               snprintf(buf, 256, "pidof %s >/dev/null", arg);
+               obj->data.ifblock.s = strndup(buf, text_buffer_size);
 #endif
-               } else {
-                       NORM_ERR("if_running needs an argument");
-                       obj->data.ifblock.s = 0;
-               }
        END OBJ(kernel, 0)
        END OBJ(machine, 0)
        END OBJ(mails, 0)
@@ -1369,21 +1085,21 @@ struct text_object *construct_text_object(const char *s, const char *arg, long
                /* if '1' (in mboxscan.c) then there was SIGUSR1, hmm */
                obj->data.mboxscan.output[0] = 1;
                strncpy(obj->data.mboxscan.args, arg, text_buffer_size);
-       END OBJ(mem, CALLBACK(&update_meminfo))
-       END OBJ(memeasyfree, CALLBACK(&update_meminfo))
-       END OBJ(memfree, CALLBACK(&update_meminfo))
-       END OBJ(memmax, CALLBACK(&update_meminfo))
-       END OBJ(memperc, CALLBACK(&update_meminfo))
+       END OBJ(mem, &update_meminfo)
+       END OBJ(memeasyfree, &update_meminfo)
+       END OBJ(memfree, &update_meminfo)
+       END OBJ(memmax, &update_meminfo)
+       END OBJ(memperc, &update_meminfo)
 #ifdef X11
-       END OBJ(memgauge, CALLBACK(&update_meminfo))
+       END OBJ(memgauge, &update_meminfo)
                SIZE_DEFAULTS(gauge);
                scan_gauge(arg, &obj->data.pair.a, &obj->data.pair.b);
 #endif /* X11*/
-       END OBJ(membar, CALLBACK(&update_meminfo))
+       END OBJ(membar, &update_meminfo)
                SIZE_DEFAULTS(bar);
                scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
 #ifdef X11
-       END OBJ(memgraph, CALLBACK(&update_meminfo))
+       END OBJ(memgraph, &update_meminfo)
                char *buf = 0;
                SIZE_DEFAULTS(graph);
                buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
@@ -1414,15 +1130,15 @@ struct text_object *construct_text_object(const char *s, const char *arg, long
        END OBJ_IF(if_mixer_mute, 0)
                obj->data.ifblock.i = mixer_init(arg);
 #ifdef X11
-       END OBJ(monitor, CALLBACK(&update_x11info))
-       END OBJ(monitor_number, CALLBACK(&update_x11info))
-       END OBJ(desktop, CALLBACK(&update_x11info))
-       END OBJ(desktop_number, CALLBACK(&update_x11info))
-       END OBJ(desktop_name, CALLBACK(&update_x11info))
+       END OBJ(monitor, &update_x11info)
+       END OBJ(monitor_number, &update_x11info)
+       END OBJ(desktop, &update_x11info)
+       END OBJ(desktop_number, &update_x11info)
+       END OBJ(desktop_name, &update_x11info)
 #endif
        END OBJ(nodename, 0)
-       END OBJ(processes, CALLBACK(&update_total_processes))
-       END OBJ(running_processes, CALLBACK(&update_running_processes))
+       END OBJ(processes, &update_total_processes)
+       END OBJ(running_processes, &update_running_processes)
        END OBJ(shadecolor, 0)
 #ifdef X11
                obj->data.l = arg ? get_x11_color(arg) : default_bg_color;
@@ -1446,66 +1162,27 @@ struct text_object *construct_text_object(const char *s, const char *arg, long
                obj->data.pair.a = a;
                obj->data.pair.b = b;
 #endif /* X11 */
-       END OBJ(swap, CALLBACK(&update_meminfo))
-       END OBJ(swapfree, CALLBACK(&update_meminfo))
-       END OBJ(swapmax, CALLBACK(&update_meminfo))
-       END OBJ(swapperc, CALLBACK(&update_meminfo))
-       END OBJ(swapbar, CALLBACK(&update_meminfo))
+       END OBJ(swap, &update_meminfo)
+       END OBJ(swapfree, &update_meminfo)
+       END OBJ(swapmax, &update_meminfo)
+       END OBJ(swapperc, &update_meminfo)
+       END OBJ(swapbar, &update_meminfo)
                SIZE_DEFAULTS(bar);
                scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
        END OBJ(sysname, 0)
        END OBJ(time, 0)
-               obj->data.s = strndup(arg ? arg : "%F %T", text_buffer_size);
+               scan_time(obj, arg);
        END OBJ(utime, 0)
-               obj->data.s = strndup(arg ? arg : "%F %T", text_buffer_size);
+               scan_time(obj, arg);
        END OBJ(tztime, 0)
-               char buf1[256], buf2[256], *fmt, *tz;
-
-               fmt = tz = NULL;
-               if (arg) {
-                       int nArgs = sscanf(arg, "%255s %255[^\n]", buf1, buf2);
-
-                       switch (nArgs) {
-                               case 2:
-                                       tz = buf1;
-                               case 1:
-                                       fmt = buf2;
-                       }
-               }
-
-               obj->data.tztime.fmt = strndup(fmt ? fmt : "%F %T", text_buffer_size);
-               obj->data.tztime.tz = tz ? strndup(tz, text_buffer_size) : NULL;
+               scan_tztime(obj, arg);
 #ifdef HAVE_ICONV
-       END OBJ(iconv_start, 0)
-               if (is_iconv_converting()) {
-                       CRIT_ERR(obj, free_at_crash, "You must stop your last iconv conversion before "
-                               "starting another");
-               }
-               if (arg) {
-                       char iconv_from[ICONV_CODEPAGE_LENGTH];
-                       char iconv_to[ICONV_CODEPAGE_LENGTH];
-
-                       if (sscanf(arg, "%s %s", iconv_from, iconv_to) != 2) {
-                               CRIT_ERR(obj, free_at_crash, "Invalid arguments for iconv_start");
-                       } else {
-                               iconv_t new_iconv;
-
-                               new_iconv = iconv_open(iconv_to, iconv_from);
-                               if (new_iconv == (iconv_t) (-1)) {
-                                       NORM_ERR("Can't convert from %s to %s.", iconv_from, iconv_to);
-                               } else {
-                                       obj->a = register_iconv(&new_iconv);
-                                       set_iconv_converting(1);
-                               }
-                       }
-               } else {
-                       CRIT_ERR(obj, free_at_crash, "Iconv requires arguments");
-               }
+       END OBJ_ARG(iconv_start, 0, "Iconv requires arguments")
+               init_iconv_start(obj, free_at_crash, arg);
        END OBJ(iconv_stop, 0)
-               set_iconv_converting(0);
-
+               init_iconv_stop();
 #endif
-       END OBJ(totaldown, CALLBACK(&update_net_stats))
+       END OBJ(totaldown, &update_net_stats)
                if (arg) {
                        obj->data.net = get_net_stat(arg, obj, free_at_crash);
                } else {
@@ -1514,7 +1191,7 @@ struct text_object *construct_text_object(const char *s, const char *arg, long
                        obj->data.net = get_net_stat(buf, obj, free_at_crash);
                        free(buf);
                }
-       END OBJ(totalup, CALLBACK(&update_net_stats))
+       END OBJ(totalup, &update_net_stats)
                obj->data.net = get_net_stat(arg, obj, free_at_crash);
                if (arg) {
                        obj->data.net = get_net_stat(arg, obj, free_at_crash);
@@ -1533,7 +1210,7 @@ struct text_object *construct_text_object(const char *s, const char *arg, long
                obj->data.i = arg ? atoi(arg) : 0;
        END OBJ(alignc, 0)
                obj->data.i = arg ? atoi(arg) : 0;
-       END OBJ(upspeed, CALLBACK(&update_net_stats))
+       END OBJ(upspeed, &update_net_stats)
                if (arg) {
                        obj->data.net = get_net_stat(arg, obj, free_at_crash);
                } else {
@@ -1542,7 +1219,7 @@ struct text_object *construct_text_object(const char *s, const char *arg, long
                        obj->data.net = get_net_stat(buf, obj, free_at_crash);
                        free(buf);
                }
-       END OBJ(upspeedf, CALLBACK(&update_net_stats))
+       END OBJ(upspeedf, &update_net_stats)
                if (arg) {
                        obj->data.net = get_net_stat(arg, obj, free_at_crash);
                } else {
@@ -1553,7 +1230,7 @@ struct text_object *construct_text_object(const char *s, const char *arg, long
                }
 
 #ifdef X11
-       END OBJ(upspeedgraph, CALLBACK(&update_net_stats))
+       END OBJ(upspeedgraph, &update_net_stats)
                char *buf = 0;
                SIZE_DEFAULTS(graph);
                buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
@@ -1564,15 +1241,15 @@ struct text_object *construct_text_object(const char *s, const char *arg, long
                obj->data.net = get_net_stat(buf, obj, free_at_crash);
                free(buf);
 #endif
-       END OBJ(uptime_short, CALLBACK(&update_uptime))
-       END OBJ(uptime, CALLBACK(&update_uptime))
-       END OBJ(user_names, CALLBACK(&update_users))
-       END OBJ(user_times, CALLBACK(&update_users))
-       END OBJ(user_terms, CALLBACK(&update_users))
-       END OBJ(user_number, CALLBACK(&update_users))
+       END OBJ(uptime_short, &update_uptime)
+       END OBJ(uptime, &update_uptime)
+       END OBJ(user_names, &update_users)
+       END OBJ(user_times, &update_users)
+       END OBJ(user_terms, &update_users)
+       END OBJ(user_number, &update_users)
 #if defined(__linux__)
-       END OBJ(gw_iface, CALLBACK(&update_gateway_info))
-       END OBJ(gw_ip, CALLBACK(&update_gateway_info))
+       END OBJ(gw_iface, &update_gateway_info)
+       END OBJ(gw_ip, &update_gateway_info)
 #endif /* !__linux__ */
 #ifndef __OpenBSD__
        END OBJ(adt746xcpu, 0)
@@ -1617,46 +1294,27 @@ struct text_object *construct_text_object(const char *s, const char *arg, long
                        obj->char_b = 1;
                }
 #ifdef IBM
-       END OBJ(smapi, 0)
-               if (arg)
-                       obj->data.s = strndup(arg, text_buffer_size);
-               else
-                       NORM_ERR("smapi needs an argument");
-       END OBJ_IF(if_smapi_bat_installed, 0)
-               if (!arg) {
-                       NORM_ERR("if_smapi_bat_installed needs an argument");
-                       obj->data.ifblock.s = 0;
-               } else
-                       obj->data.ifblock.s = strndup(arg, text_buffer_size);
-       END OBJ(smapi_bat_perc, 0)
-               if (arg)
-                       obj->data.s = strndup(arg, text_buffer_size);
-               else
-                       NORM_ERR("smapi_bat_perc needs an argument");
-       END OBJ(smapi_bat_temp, 0)
-               if (arg)
-                       obj->data.s = strndup(arg, text_buffer_size);
-               else
-                       NORM_ERR("smapi_bat_temp needs an argument");
-       END OBJ(smapi_bat_power, 0)
-               if (arg)
-                       obj->data.s = strndup(arg, text_buffer_size);
-               else
-                       NORM_ERR("smapi_bat_power needs an argument");
+       END OBJ_ARG(smapi, 0, "smapi needs an argument")
+               obj->data.s = strndup(arg, text_buffer_size);
+       END OBJ_IF_ARG(if_smapi_bat_installed, 0, "if_smapi_bat_installed needs an argument")
+               obj->data.ifblock.s = strndup(arg, text_buffer_size);
+       END OBJ_ARG(smapi_bat_perc, 0, "smapi_bat_perc needs an argument")
+               obj->data.s = strndup(arg, text_buffer_size);
+       END OBJ_ARG(smapi_bat_temp, 0, "smapi_bat_temp needs an argument")
+               obj->data.s = strndup(arg, text_buffer_size);
+       END OBJ_ARG(smapi_bat_power, 0, "smapi_bat_power needs an argument")
+               obj->data.s = strndup(arg, text_buffer_size);
 #ifdef X11
-       END OBJ(smapi_bat_bar, 0)
+       END OBJ_ARG(smapi_bat_bar, 0, "smapi_bat_bar needs an argument")
+               int cnt;
                SIZE_DEFAULTS(bar);
-               if(arg) {
-                       int cnt;
-                       if(sscanf(arg, "%i %n", &obj->data.i, &cnt) <= 0) {
-                               NORM_ERR("first argument to smapi_bat_bar must be an integer value");
-                               obj->data.i = -1;
-                       } else {
-                               obj->b = 4;
-                               arg = scan_bar(arg + cnt, &obj->a, &obj->b);
-                       }
-               } else
-                       NORM_ERR("smapi_bat_bar needs an argument");
+               if(sscanf(arg, "%i %n", &obj->data.i, &cnt) <= 0) {
+                       NORM_ERR("first argument to smapi_bat_bar must be an integer value");
+                       obj->data.i = -1;
+               } else {
+                       obj->b = 4;
+                       arg = scan_bar(arg + cnt, &obj->a, &obj->b);
+               }
 #endif /* X11 */
 #endif /* IBM */
 #ifdef MPD
@@ -1669,381 +1327,211 @@ struct text_object *construct_text_object(const char *s, const char *arg, long
                        else \
                                NORM_ERR(#name ": invalid length argument"); \
                }
-       END OBJ(mpd_artist, CALLBACK(&update_mpd))
+       END OBJ(mpd_artist, &update_mpd)
                mpd_set_maxlen(mpd_artist);
                init_mpd();
-       END OBJ(mpd_title, CALLBACK(&update_mpd))
+       END OBJ(mpd_title, &update_mpd)
                mpd_set_maxlen(mpd_title);
                init_mpd();
-       END OBJ(mpd_random, CALLBACK(&update_mpd)) init_mpd();
-       END OBJ(mpd_repeat, CALLBACK(&update_mpd)) init_mpd();
-       END OBJ(mpd_elapsed, CALLBACK(&update_mpd)) init_mpd();
-       END OBJ(mpd_length, CALLBACK(&update_mpd)) init_mpd();
-       END OBJ(mpd_track, CALLBACK(&update_mpd))
+       END OBJ(mpd_random, &update_mpd) init_mpd();
+       END OBJ(mpd_repeat, &update_mpd) init_mpd();
+       END OBJ(mpd_elapsed, &update_mpd) init_mpd();
+       END OBJ(mpd_length, &update_mpd) init_mpd();
+       END OBJ(mpd_track, &update_mpd)
                mpd_set_maxlen(mpd_track);
                init_mpd();
-       END OBJ(mpd_name, CALLBACK(&update_mpd))
+       END OBJ(mpd_name, &update_mpd)
                mpd_set_maxlen(mpd_name);
                init_mpd();
-       END OBJ(mpd_file, CALLBACK(&update_mpd))
+       END OBJ(mpd_file, &update_mpd)
                mpd_set_maxlen(mpd_file);
                init_mpd();
-       END OBJ(mpd_percent, CALLBACK(&update_mpd)) init_mpd();
-       END OBJ(mpd_album, CALLBACK(&update_mpd))
+       END OBJ(mpd_percent, &update_mpd) init_mpd();
+       END OBJ(mpd_album, &update_mpd)
                mpd_set_maxlen(mpd_album);
                init_mpd();
-       END OBJ(mpd_vol, CALLBACK(&update_mpd)) init_mpd();
-       END OBJ(mpd_bitrate, CALLBACK(&update_mpd)) init_mpd();
-       END OBJ(mpd_status, CALLBACK(&update_mpd)) init_mpd();
-       END OBJ(mpd_bar, CALLBACK(&update_mpd))
+       END OBJ(mpd_vol, &update_mpd) init_mpd();
+       END OBJ(mpd_bitrate, &update_mpd) init_mpd();
+       END OBJ(mpd_status, &update_mpd) init_mpd();
+       END OBJ(mpd_bar, &update_mpd)
                SIZE_DEFAULTS(bar);
                scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
                init_mpd();
-       END OBJ(mpd_smart, CALLBACK(&update_mpd))
+       END OBJ(mpd_smart, &update_mpd)
                mpd_set_maxlen(mpd_smart);
                init_mpd();
-       END OBJ_IF(if_mpd_playing, CALLBACK(&update_mpd))
+       END OBJ_IF(if_mpd_playing, &update_mpd)
                init_mpd();
 #undef mpd_set_maxlen
 #endif /* MPD */
 #ifdef MOC
-       END OBJ(moc_state, CALLBACK(&update_moc))
-       END OBJ(moc_file, CALLBACK(&update_moc))
-       END OBJ(moc_title, CALLBACK(&update_moc))
-       END OBJ(moc_artist, CALLBACK(&update_moc))
-       END OBJ(moc_song, CALLBACK(&update_moc))
-       END OBJ(moc_album, CALLBACK(&update_moc))
-       END OBJ(moc_totaltime, CALLBACK(&update_moc))
-       END OBJ(moc_timeleft, CALLBACK(&update_moc))
-       END OBJ(moc_curtime, CALLBACK(&update_moc))
-       END OBJ(moc_bitrate, CALLBACK(&update_moc))
-       END OBJ(moc_rate, CALLBACK(&update_moc))
+       END OBJ(moc_state, &update_moc)
+       END OBJ(moc_file, &update_moc)
+       END OBJ(moc_title, &update_moc)
+       END OBJ(moc_artist, &update_moc)
+       END OBJ(moc_song, &update_moc)
+       END OBJ(moc_album, &update_moc)
+       END OBJ(moc_totaltime, &update_moc)
+       END OBJ(moc_timeleft, &update_moc)
+       END OBJ(moc_curtime, &update_moc)
+       END OBJ(moc_bitrate, &update_moc)
+       END OBJ(moc_rate, &update_moc)
 #endif /* MOC */
 #ifdef XMMS2
-       END OBJ(xmms2_artist, CALLBACK(&update_xmms2))
-       END OBJ(xmms2_album, CALLBACK(&update_xmms2))
-       END OBJ(xmms2_title, CALLBACK(&update_xmms2))
-       END OBJ(xmms2_genre, CALLBACK(&update_xmms2))
-       END OBJ(xmms2_comment, CALLBACK(&update_xmms2))
-       END OBJ(xmms2_url, CALLBACK(&update_xmms2))
-       END OBJ(xmms2_tracknr, CALLBACK(&update_xmms2))
-       END OBJ(xmms2_bitrate, CALLBACK(&update_xmms2))
-       END OBJ(xmms2_date, CALLBACK(&update_xmms2))
-       END OBJ(xmms2_id, CALLBACK(&update_xmms2))
-       END OBJ(xmms2_duration, CALLBACK(&update_xmms2))
-       END OBJ(xmms2_elapsed, CALLBACK(&update_xmms2))
-       END OBJ(xmms2_size, CALLBACK(&update_xmms2))
-       END OBJ(xmms2_status, CALLBACK(&update_xmms2))
-       END OBJ(xmms2_percent, CALLBACK(&update_xmms2))
+       END OBJ(xmms2_artist, &update_xmms2)
+       END OBJ(xmms2_album, &update_xmms2)
+       END OBJ(xmms2_title, &update_xmms2)
+       END OBJ(xmms2_genre, &update_xmms2)
+       END OBJ(xmms2_comment, &update_xmms2)
+       END OBJ(xmms2_url, &update_xmms2)
+       END OBJ(xmms2_tracknr, &update_xmms2)
+       END OBJ(xmms2_bitrate, &update_xmms2)
+       END OBJ(xmms2_date, &update_xmms2)
+       END OBJ(xmms2_id, &update_xmms2)
+       END OBJ(xmms2_duration, &update_xmms2)
+       END OBJ(xmms2_elapsed, &update_xmms2)
+       END OBJ(xmms2_size, &update_xmms2)
+       END OBJ(xmms2_status, &update_xmms2)
+       END OBJ(xmms2_percent, &update_xmms2)
 #ifdef X11
-       END OBJ(xmms2_bar, CALLBACK(&update_xmms2))
+       END OBJ(xmms2_bar, &update_xmms2)
                SIZE_DEFAULTS(bar);
                scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
 #endif /* X11 */
-       END OBJ(xmms2_smart, CALLBACK(&update_xmms2))
-       END OBJ(xmms2_playlist, CALLBACK(&update_xmms2))
-       END OBJ(xmms2_timesplayed, CALLBACK(&update_xmms2))
-       END OBJ_IF(if_xmms2_connected, CALLBACK(&update_xmms2))
+       END OBJ(xmms2_smart, &update_xmms2)
+       END OBJ(xmms2_playlist, &update_xmms2)
+       END OBJ(xmms2_timesplayed, &update_xmms2)
+       END OBJ_IF(if_xmms2_connected, &update_xmms2)
 #endif
 #ifdef AUDACIOUS
-       END OBJ(audacious_status, CALLBACK(&update_audacious))
-       END OBJ(audacious_title, CALLBACK(&update_audacious))
-               if (arg) {
-                       sscanf(arg, "%d", &info.audacious.max_title_len);
-                       if (info.audacious.max_title_len > 0) {
-                               info.audacious.max_title_len++;
-                       } else {
-                               CRIT_ERR(obj, free_at_crash, "audacious_title: invalid length argument");
-                       }
-               }
-       END OBJ(audacious_length, CALLBACK(&update_audacious))
-       END OBJ(audacious_length_seconds, CALLBACK(&update_audacious))
-       END OBJ(audacious_position, CALLBACK(&update_audacious))
-       END OBJ(audacious_position_seconds, CALLBACK(&update_audacious))
-       END OBJ(audacious_bitrate, CALLBACK(&update_audacious))
-       END OBJ(audacious_frequency, CALLBACK(&update_audacious))
-       END OBJ(audacious_channels, CALLBACK(&update_audacious))
-       END OBJ(audacious_filename, CALLBACK(&update_audacious))
-       END OBJ(audacious_playlist_length, CALLBACK(&update_audacious))
-       END OBJ(audacious_playlist_position, CALLBACK(&update_audacious))
-       END OBJ(audacious_main_volume, CALLBACK(&update_audacious))
+       END OBJ(audacious_status, &update_audacious)
+       END OBJ_ARG(audacious_title, &update_audacious, "audacious_title needs an argument")
+               sscanf(arg, "%d", &info.audacious.max_title_len);
+               if (info.audacious.max_title_len > 0) {
+                       info.audacious.max_title_len++;
+               } else {
+                       CRIT_ERR(obj, free_at_crash, "audacious_title: invalid length argument");
+               }
+       END OBJ(audacious_length, &update_audacious)
+       END OBJ(audacious_length_seconds, &update_audacious)
+       END OBJ(audacious_position, &update_audacious)
+       END OBJ(audacious_position_seconds, &update_audacious)
+       END OBJ(audacious_bitrate, &update_audacious)
+       END OBJ(audacious_frequency, &update_audacious)
+       END OBJ(audacious_channels, &update_audacious)
+       END OBJ(audacious_filename, &update_audacious)
+       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, CALLBACK(&update_audacious))
+       END OBJ(audacious_bar, &update_audacious)
                SIZE_DEFAULTS(bar);
                scan_bar(arg, &obj->a, &obj->b);
 #endif /* X11 */
 #endif
 #ifdef BMPX
-       END OBJ(bmpx_title, CALLBACK(&update_bmpx))
+       END OBJ(bmpx_title, &update_bmpx)
                memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
-       END OBJ(bmpx_artist, CALLBACK(&update_bmpx))
+       END OBJ(bmpx_artist, &update_bmpx)
                memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
-       END OBJ(bmpx_album, CALLBACK(&update_bmpx))
+       END OBJ(bmpx_album, &update_bmpx)
                memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
-       END OBJ(bmpx_track, CALLBACK(&update_bmpx))
+       END OBJ(bmpx_track, &update_bmpx)
                memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
-       END OBJ(bmpx_uri, CALLBACK(&update_bmpx))
+       END OBJ(bmpx_uri, &update_bmpx)
                memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
-       END OBJ(bmpx_bitrate, CALLBACK(&update_bmpx))
+       END OBJ(bmpx_bitrate, &update_bmpx)
                memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
 #endif
 #ifdef EVE
-       END OBJ(eve, 0)
-               if(arg) {
-                       int argc;
-                       char *userid = (char *) malloc(20 * sizeof(char));
-                       char *apikey = (char *) malloc(64 * sizeof(char));
-                       char *charid = (char *) malloc(20 * sizeof(char));
-
-                       argc = sscanf(arg, "%20s %64s %20s", userid, apikey, charid);
-                       obj->data.eve.charid = charid;
-                       obj->data.eve.userid = userid;
-                       obj->data.eve.apikey = apikey;
-
-                       init_eve();
-               } else {
-                       CRIT_ERR(obj, free_at_crash, "eve needs arguments: <userid> <apikey> <characterid>");
-               }
+       END OBJ_ARG(eve, 0, "eve needs arguments: <userid> <apikey> <characterid>")
+               scan_eve(obj, arg);
 #endif
 #ifdef HAVE_CURL
-       END OBJ(curl, 0)
-               if (arg) {
-                       int argc;
-                       float interval = 0;
-                       char *uri = (char *) malloc(128 * sizeof(char));
-
-                       argc = sscanf(arg, "%127s %f", uri, &interval);
-                       if (argc == 2) {
-                               obj->data.curl.uri = uri;
-                               obj->data.curl.interval = interval > 0 ? interval * 60 : 15*60;
-                       } else {
-                               NORM_ERR("wrong number of arguments for $curl");
-                       }
-               } else {
-                       CRIT_ERR(obj, free_at_crash, "curl needs arguments: <uri> <interval in minutes>");
-               }
+       END OBJ_ARG(curl, 0, "curl needs arguments: <uri> <interval in minutes>")
+               curl_parse_arg(obj, arg);
 #endif
 #ifdef RSS
-       END OBJ(rss, 0)
-               if (arg) {
-                       float interval = 0;
-                       int argc, act_par = 0;
-                       unsigned int nrspaces = 0;
-                       char *uri = (char *) malloc(128 * sizeof(char));
-                       char *action = (char *) malloc(64 * sizeof(char));
-
-                       argc = sscanf(arg, "%127s %f %63s %d %u", uri, &interval, action,
-                                       &act_par, &nrspaces);
-                       if (argc >= 3) {
-                               obj->data.rss.uri = uri;
-                               obj->data.rss.interval = interval > 0 ? interval * 60 : 15*60;
-                               obj->data.rss.action = action;
-                               obj->data.rss.act_par = act_par;
-                               obj->data.rss.nrspaces = nrspaces;
-                       } else {
-                               NORM_ERR("wrong number of arguments for $rss");
-                       }
-               } else {
-                       CRIT_ERR(obj, free_at_crash, "rss needs arguments: <uri> <interval in minutes> <action> "
-                                       "[act_par] [spaces in front]");
-               }
+       END OBJ_ARG(rss, 0, "rss needs arguments: <uri> <interval in minutes> <action> [act_par] [spaces in front]")
+               rss_scan_arg(obj, arg);
 #endif
 #ifdef WEATHER
-       END OBJ(weather, 0)
-               if (arg) {
-                       int argc;
-                       float interval = 0;
-                       char *locID = (char *) malloc(9 * sizeof(char));
-                       char *uri = (char *) malloc(128 * sizeof(char));
-                       char *data_type = (char *) malloc(32 * sizeof(char));
-
-                       argc = sscanf(arg, "%119s %8s %31s %f", uri, locID, data_type, &interval);
-
-                       if (argc >= 3) {
-                               if (process_weather_uri(uri, locID, 0)) {
-                                       free(data_type);
-                                       free(uri);
-                                       free(locID);
-                                       CRIT_ERR(obj, free_at_crash, \
-                                                       "could not recognize the weather uri");
-                               }
-
-                               obj->data.weather.uri = uri;
-                               obj->data.weather.data_type = data_type;
-
-                               /* Limit the data retrieval interval to half hour min */
-                               if (interval < 30) {
-                                       interval = 30;
-                               }
-
-                               /* Convert to seconds */
-                               obj->data.weather.interval = interval * 60;
-                               free(locID);
-
-                               DBGP("weather: fetching %s from %s every %d seconds", \
-                                               data_type, uri, obj->data.weather.interval);
-                       } else {
-                               free(data_type);
-                               free(uri);
-                               free(locID);
-                               CRIT_ERR(obj, free_at_crash, "wrong number of arguments for $weather");
-                       }
-               } else {
-                       CRIT_ERR(obj, free_at_crash, "weather needs arguments: <uri> <locID> <data_type> [interval in minutes]");
-               }
+       END OBJ_ARG(weather, 0, "weather needs arguments: <uri> <locID> <data_type> [interval in minutes]")
+               scan_weather_arg(obj, arg, free_at_crash);
 #endif
 #ifdef XOAP
-       END OBJ(weather_forecast, 0)
-               if (arg) {
-                       int argc;
-                       unsigned int day;
-                       float interval = 0;
-                       char *locID = (char *) malloc(9 * sizeof(char));
-                       char *uri = (char *) malloc(128 * sizeof(char));
-                       char *data_type = (char *) malloc(32 * sizeof(char));
-
-                       argc = sscanf(arg, "%119s %8s %1u %31s %f", uri, locID, &day, data_type, &interval);
-
-                       if (argc >= 4) {
-                               if (process_weather_uri(uri, locID, 1)) {
-                                       free(data_type);
-                                       free(uri);
-                                       free(locID);
-                                       CRIT_ERR(obj, free_at_crash, \
-                                                       "could not recognize the weather forecast uri");
-                               }
-
-                               obj->data.weather_forecast.uri = uri;
-                               obj->data.weather_forecast.data_type = data_type;
-
-                               /* Limit the day between 0 (today) and FORECAST_DAYS */
-                               if (day >= FORECAST_DAYS) {
-                                       day = FORECAST_DAYS-1;
-                               }
-                               obj->data.weather_forecast.day = day;
-
-                               /* Limit the data retrieval interval to 3 hours and an half */
-                               if (interval < 210) {
-                                       interval = 210;
-                               }
-
-                               /* Convert to seconds */
-                               obj->data.weather_forecast.interval = interval * 60;
-                               free(locID);
-
-                               DBGP("weather_forecast: fetching %s for day %d from %s every %d seconds", \
-                                        data_type, day, uri, obj->data.weather_forecast.interval);
-                       } else {
-                               free(data_type);
-                               free(uri);
-                               free(locID);
-                               CRIT_ERR(obj, free_at_crash, "wrong number of arguments for $weather_forecast");
-                       }
-               } else {
-                       CRIT_ERR(obj, free_at_crash, "weather_forecast needs arguments: <uri> <locID> <day> <data_type> [interval in minutes]");
-               }
+       END OBJ_ARG(weather_forecast, 0, "weather_forecast needs arguments: <uri> <locID> <day> <data_type> [interval in minutes]")
+               scan_weather_forecast_arg(obj, arg, free_at_crash);
 #endif
 #ifdef HAVE_LUA
-       END OBJ(lua, 0)
-               if (arg) {
-                       obj->data.s = strndup(arg, text_buffer_size);
-               } else {
-                       CRIT_ERR(obj, free_at_crash, "lua needs arguments: <function name> [function parameters]");
-               }
-       END OBJ(lua_parse, 0)
-               if (arg) {
-                       obj->data.s = strndup(arg, text_buffer_size);
-               } else {
-                       CRIT_ERR(obj, free_at_crash, "lua_parse needs arguments: <function name> [function parameters]");
-               }
-       END OBJ(lua_bar, 0)
+       END OBJ_ARG(lua, 0, "lua needs arguments: <function name> [function parameters]")
+               obj->data.s = strndup(arg, text_buffer_size);
+       END OBJ_ARG(lua_parse, 0, "lua_parse needs arguments: <function name> [function parameters]")
+               obj->data.s = strndup(arg, text_buffer_size);
+       END OBJ_ARG(lua_bar, 0, "lua_bar needs arguments: <height>,<width> <function name> [function parameters]")
                SIZE_DEFAULTS(bar);
-               if (arg) {
-                       arg = scan_bar(arg, &obj->a, &obj->b);
-                       if(arg) {
-                               obj->data.s = strndup(arg, text_buffer_size);
-                       } else {
-                               CRIT_ERR(obj, free_at_crash, "lua_bar needs arguments: <height>,<width> <function name> [function parameters]");
-                       }
+               arg = scan_bar(arg, &obj->a, &obj->b);
+               if(arg) {
+                       obj->data.s = strndup(arg, text_buffer_size);
                } else {
                        CRIT_ERR(obj, free_at_crash, "lua_bar needs arguments: <height>,<width> <function name> [function parameters]");
                }
 #ifdef X11
-       END OBJ(lua_graph, 0)
+       END OBJ_ARG(lua_graph, 0, "lua_graph needs arguments: <function name> [height],[width] [gradient colour 1] [gradient colour 2] [scale] [-t] [-l]")
+               char *buf = 0;
                SIZE_DEFAULTS(graph);
-               if (arg) {
-                       char *buf = 0;
-                       buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
-                                       &obj->e, &obj->char_a, &obj->char_b);
-                       if (buf) {
-                               obj->data.s = buf;
-                       } else {
-                               CRIT_ERR(obj, free_at_crash, "lua_graph needs arguments: <function name> [height],[width] [gradient colour 1] [gradient colour 2] [scale] [-t] [-l]");
-                       }
+               buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
+                               &obj->e, &obj->char_a, &obj->char_b);
+               if (buf) {
+                       obj->data.s = buf;
                } else {
                        CRIT_ERR(obj, free_at_crash, "lua_graph needs arguments: <function name> [height],[width] [gradient colour 1] [gradient colour 2] [scale] [-t] [-l]");
-       }
-       END OBJ(lua_gauge, 0)
+               }
+       END OBJ_ARG(lua_gauge, 0, "lua_gauge needs arguments: <height>,<width> <function name> [function parameters]")
                SIZE_DEFAULTS(gauge);
+               arg = scan_gauge(arg, &obj->a, &obj->b);
                if (arg) {
-                       arg = scan_gauge(arg, &obj->a, &obj->b);
-                       if (arg) {
-                               obj->data.s = strndup(arg, text_buffer_size);
-                       } else {
-                               CRIT_ERR(obj, free_at_crash, "lua_gauge needs arguments: <height>,<width> <function name> [function parameters]");
-                       }
+                       obj->data.s = strndup(arg, text_buffer_size);
                } else {
                        CRIT_ERR(obj, free_at_crash, "lua_gauge needs arguments: <height>,<width> <function name> [function parameters]");
                }
 #endif /* X11 */
 #endif /* HAVE_LUA */
 #ifdef HDDTEMP
-       END OBJ(hddtemp, CALLBACK(&update_hddtemp))
+       END OBJ(hddtemp, &update_hddtemp)
                if (arg)
                        obj->data.s = strndup(arg, text_buffer_size);
 #endif /* HDDTEMP */
 #ifdef TCP_PORT_MONITOR
-       END OBJ(tcp_portmon, CALLBACK(&tcp_portmon_update))
+       END OBJ_ARG(tcp_portmon, &tcp_portmon_update, "tcp_portmon: needs arguments")
                tcp_portmon_init(arg, &obj->data.tcp_port_monitor);
 #endif /* TCP_PORT_MONITOR */
-       END OBJ(entropy_avail, CALLBACK(&update_entropy))
-       END OBJ(entropy_perc, CALLBACK(&update_entropy))
-       END OBJ(entropy_poolsize, CALLBACK(&update_entropy))
-       END OBJ(entropy_bar, CALLBACK(&update_entropy))
+       END OBJ(entropy_avail, &update_entropy)
+       END OBJ(entropy_perc, &update_entropy)
+       END OBJ(entropy_poolsize, &update_entropy)
+       END OBJ(entropy_bar, &update_entropy)
                SIZE_DEFAULTS(bar);
                scan_bar(arg, &obj->a, &obj->b);
-       END OBJ(include, 0)
-               if(arg) {
-                       struct conftree *leaf = conftree_add(currentconffile, arg);
-                       if(leaf) {
-                               if (load_config_file(arg) == TRUE) {
-                                       obj->sub = malloc(sizeof(struct text_object));
-                                       currentconffile = leaf;
-                                       extract_variable_text_internal(obj->sub, get_global_text());
-                                       currentconffile = leaf->back;
-                               } else {
-                                       NORM_ERR("Can't load configfile '%s'.", arg);
-                               }
+       END OBJ_ARG(include, 0, "include needs a argument")
+               struct conftree *leaf = conftree_add(currentconffile, arg);
+               if(leaf) {
+                       if (load_config_file(arg) == TRUE) {
+                               obj->sub = malloc(sizeof(struct text_object));
+                               currentconffile = leaf;
+                               extract_variable_text_internal(obj->sub, get_global_text());
+                               currentconffile = leaf->back;
                        } else {
-                               NORM_ERR("You are trying to load '%s' recursively, I'm only going to load it once to prevent an infinite loop.", arg);
+                               NORM_ERR("Can't load configfile '%s'.", arg);
                        }
                } else {
-                       CRIT_ERR(obj, free_at_crash, "include needs a argument");
-               }
-       END OBJ(blink, 0)
-               if(arg) {
-                       obj->sub = malloc(sizeof(struct text_object));
-                       extract_variable_text_internal(obj->sub, arg);
-               }else{
-                       CRIT_ERR(obj, free_at_crash, "blink needs a argument");
-               }
-       END OBJ(to_bytes, 0)
-               if(arg) {
-                       obj->sub = malloc(sizeof(struct text_object));
-                       extract_variable_text_internal(obj->sub, arg);
-               }else{
-                       CRIT_ERR(obj, free_at_crash, "to_bytes needs a argument");
+                       NORM_ERR("You are trying to load '%s' recursively, I'm only going to load it once to prevent an infinite loop.", arg);
                }
+       END OBJ_ARG(blink, 0, "blink needs a argument")
+               obj->sub = malloc(sizeof(struct text_object));
+               extract_variable_text_internal(obj->sub, arg);
+       END OBJ_ARG(to_bytes, 0, "to_bytes needs a argument")
+               obj->sub = malloc(sizeof(struct text_object));
+               extract_variable_text_internal(obj->sub, arg);
        END OBJ(scroll, 0)
                int n1 = 0, n2 = 0;
 
@@ -2069,104 +1557,93 @@ struct text_object *construct_text_object(const char *s, const char *arg, long
                } else {
                        CRIT_ERR(obj, free_at_crash, "scroll needs arguments: <length> [<step>] <text>");
                }
-       END OBJ(combine, 0)
-               if(arg) {
-                       unsigned int i,j;
-                       unsigned int indenting = 0;     //vars can be used as args for other vars
-                       int startvar[2];
-                       int endvar[2];
-                       startvar[0] = endvar[0] = startvar[1] = endvar[1] = -1;
-                       j=0;
-                       for (i=0; arg[i] != 0 && j < 2; i++) {
-                               if(startvar[j] == -1) {
-                                       if(arg[i] == '$') {
-                                               startvar[j] = i;
-                                       }
-                               }else if(endvar[j] == -1) {
-                                       if(arg[i] == '{') {
-                                               indenting++;
-                                       }else if(arg[i] == '}') {
-                                               indenting--;
-                                       }
-                                       if (indenting == 0 && arg[i+1] < 48) {  //<48 has 0, $, and the most used chars not used in varnames but not { or }
-                                               endvar[j]=i+1;
-                                               j++;
-                                       }
+       END OBJ_ARG(combine, 0, "combine needs arguments: <text1> <text2>")
+               unsigned int i,j;
+               unsigned int indenting = 0;     //vars can be used as args for other vars
+               int startvar[2];
+               int endvar[2];
+               startvar[0] = endvar[0] = startvar[1] = endvar[1] = -1;
+               j=0;
+               for (i=0; arg[i] != 0 && j < 2; i++) {
+                       if(startvar[j] == -1) {
+                               if(arg[i] == '$') {
+                                       startvar[j] = i;
+                               }
+                       }else if(endvar[j] == -1) {
+                               if(arg[i] == '{') {
+                                       indenting++;
+                               }else if(arg[i] == '}') {
+                                       indenting--;
+                               }
+                               if (indenting == 0 && arg[i+1] < 48) {  //<48 has 0, $, and the most used chars not used in varnames but not { or }
+                                       endvar[j]=i+1;
+                                       j++;
                                }
                        }
-                       if(startvar[0] >= 0 && endvar[0] >= 0 && startvar[1] >= 0 && endvar[1] >= 0) {
-                               obj->data.combine.left = malloc(endvar[0]-startvar[0] + 1);
-                               obj->data.combine.seperation = malloc(startvar[1] - endvar[0] + 1);
-                               obj->data.combine.right= malloc(endvar[1]-startvar[1] + 1);
+               }
+               if(startvar[0] >= 0 && endvar[0] >= 0 && startvar[1] >= 0 && endvar[1] >= 0) {
+                       obj->data.combine.left = malloc(endvar[0]-startvar[0] + 1);
+                       obj->data.combine.seperation = malloc(startvar[1] - endvar[0] + 1);
+                       obj->data.combine.right= malloc(endvar[1]-startvar[1] + 1);
 
-                               strncpy(obj->data.combine.left, arg + startvar[0], endvar[0] - startvar[0]);
-                               obj->data.combine.left[endvar[0] - startvar[0]] = 0;
+                       strncpy(obj->data.combine.left, arg + startvar[0], endvar[0] - startvar[0]);
+                       obj->data.combine.left[endvar[0] - startvar[0]] = 0;
 
-                               strncpy(obj->data.combine.seperation, arg + endvar[0], startvar[1] - endvar[0]);
-                               obj->data.combine.seperation[startvar[1] - endvar[0]] = 0;
+                       strncpy(obj->data.combine.seperation, arg + endvar[0], startvar[1] - endvar[0]);
+                       obj->data.combine.seperation[startvar[1] - endvar[0]] = 0;
 
-                               strncpy(obj->data.combine.right, arg + startvar[1], endvar[1] - startvar[1]);
-                               obj->data.combine.right[endvar[1] - startvar[1]] = 0;
+                       strncpy(obj->data.combine.right, arg + startvar[1], endvar[1] - startvar[1]);
+                       obj->data.combine.right[endvar[1] - startvar[1]] = 0;
 
-                               obj->sub = malloc(sizeof(struct text_object));
-                               extract_variable_text_internal(obj->sub, obj->data.combine.left);
-                               obj->sub->sub = malloc(sizeof(struct text_object));
-                               extract_variable_text_internal(obj->sub->sub, obj->data.combine.right);
-                       } else {
-                               CRIT_ERR(obj, free_at_crash, "combine needs arguments: <text1> <text2>");
-                       }
+                       obj->sub = malloc(sizeof(struct text_object));
+                       extract_variable_text_internal(obj->sub, obj->data.combine.left);
+                       obj->sub->sub = malloc(sizeof(struct text_object));
+                       extract_variable_text_internal(obj->sub->sub, obj->data.combine.right);
                } else {
                        CRIT_ERR(obj, free_at_crash, "combine needs arguments: <text1> <text2>");
                }
 #ifdef NVIDIA
-       END OBJ(nvidia, 0)
-               if (!arg) {
-                       CRIT_ERR(obj, free_at_crash, "nvidia needs an argument\n");
-               } else if (set_nvidia_type(&obj->data.nvidia, arg)) {
+       END OBJ_ARG(nvidia, 0, "nvidia needs an argument")
+               if (set_nvidia_type(&obj->data.nvidia, arg)) {
                        CRIT_ERR(obj, free_at_crash, "nvidia: invalid argument"
                                 " specified: '%s'\n", arg);
                }
 #endif /* NVIDIA */
 #ifdef APCUPSD
-               init_apcupsd();
-               END OBJ(apcupsd, CALLBACK(&update_apcupsd))
-                       if (arg) {
-                               char host[64];
-                               int port;
-                               if (sscanf(arg, "%63s %d", host, &port) != 2) {
-                                       CRIT_ERR(obj, free_at_crash, "apcupsd needs arguments: <host> <port>");
-                               } else {
-                                       info.apcupsd.port = htons(port);
-                                       strncpy(info.apcupsd.host, host, sizeof(info.apcupsd.host));
-                               }
-                       } else {
-                               CRIT_ERR(obj, free_at_crash, "apcupsd needs arguments: <host> <port>");
-                       }
-                       END OBJ(apcupsd_name, CALLBACK(&update_apcupsd))
-                       END OBJ(apcupsd_model, CALLBACK(&update_apcupsd))
-                       END OBJ(apcupsd_upsmode, CALLBACK(&update_apcupsd))
-                       END OBJ(apcupsd_cable, CALLBACK(&update_apcupsd))
-                       END OBJ(apcupsd_status, CALLBACK(&update_apcupsd))
-                       END OBJ(apcupsd_linev, CALLBACK(&update_apcupsd))
-                       END OBJ(apcupsd_load, CALLBACK(&update_apcupsd))
-                       END OBJ(apcupsd_loadbar, CALLBACK(&update_apcupsd))
-                               SIZE_DEFAULTS(bar);
-                               scan_bar(arg, &obj->a, &obj->b);
+       END OBJ_ARG(apcupsd, &update_apcupsd, "apcupsd needs arguments: <host> <port>")
+               char host[64];
+               int port;
+               if (sscanf(arg, "%63s %d", host, &port) != 2) {
+                       CRIT_ERR(obj, free_at_crash, "apcupsd needs arguments: <host> <port>");
+               } else {
+                       info.apcupsd.port = htons(port);
+                       strncpy(info.apcupsd.host, host, sizeof(info.apcupsd.host));
+               }
+       END OBJ(apcupsd_name, &update_apcupsd)
+       END OBJ(apcupsd_model, &update_apcupsd)
+       END OBJ(apcupsd_upsmode, &update_apcupsd)
+       END OBJ(apcupsd_cable, &update_apcupsd)
+       END OBJ(apcupsd_status, &update_apcupsd)
+       END OBJ(apcupsd_linev, &update_apcupsd)
+       END OBJ(apcupsd_load, &update_apcupsd)
+       END OBJ(apcupsd_loadbar, &update_apcupsd)
+               SIZE_DEFAULTS(bar);
+               scan_bar(arg, &obj->a, &obj->b);
 #ifdef X11
-                       END OBJ(apcupsd_loadgraph, CALLBACK(&update_apcupsd))
-                               char* buf = 0;
-                               SIZE_DEFAULTS(graph);
-                               buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
-                                               &obj->e, &obj->char_a, &obj->char_b);
-                               if (buf) free(buf);
-                       END OBJ(apcupsd_loadgauge, CALLBACK(&update_apcupsd))
-                               SIZE_DEFAULTS(gauge);
-                               scan_gauge(arg, &obj->a, &obj->b);
+       END OBJ(apcupsd_loadgraph, &update_apcupsd)
+               char* buf = 0;
+               SIZE_DEFAULTS(graph);
+               buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
+                               &obj->e, &obj->char_a, &obj->char_b);
+               if (buf) free(buf);
+       END OBJ(apcupsd_loadgauge, &update_apcupsd)
+               SIZE_DEFAULTS(gauge);
+               scan_gauge(arg, &obj->a, &obj->b);
 #endif /* X11 */
-                       END OBJ(apcupsd_charge, CALLBACK(&update_apcupsd))
-                       END OBJ(apcupsd_timeleft, CALLBACK(&update_apcupsd))
-                       END OBJ(apcupsd_temp, CALLBACK(&update_apcupsd))
-                       END OBJ(apcupsd_lastxfer, CALLBACK(&update_apcupsd))
+       END OBJ(apcupsd_charge, &update_apcupsd)
+       END OBJ(apcupsd_timeleft, &update_apcupsd)
+       END OBJ(apcupsd_temp, &update_apcupsd)
+       END OBJ(apcupsd_lastxfer, &update_apcupsd)
 #endif /* APCUPSD */
        END {
                char buf[256];
@@ -2177,6 +1654,14 @@ struct text_object *construct_text_object(const char *s, const char *arg, long
                obj->data.s = strndup(buf, text_buffer_size);
        }
 #undef OBJ
+#undef OBJ_IF
+#undef OBJ_ARG
+#undef OBJ_IF_ARG
+#undef __OBJ_HEAD
+#undef __OBJ_IF
+#undef __OBJ_ARG
+#undef END
+#undef SIZE_DEFAULTS
 
        return obj;
 }
@@ -2404,11 +1889,10 @@ void free_text_objects(struct text_object *root, int internal)
                                break;
                        case OBJ_time:
                        case OBJ_utime:
-                               free(data.s);
+                               free_time(obj);
                                break;
                        case OBJ_tztime:
-                               free(data.tztime.tz);
-                               free(data.tztime.fmt);
+                               free_tztime(obj);
                                break;
                        case OBJ_mboxscan:
                                free(data.mboxscan.args);
@@ -2493,14 +1977,7 @@ void free_text_objects(struct text_object *root, int internal)
                                free(data.ifblock.str);
                        case OBJ_gw_iface:
                        case OBJ_gw_ip:
-                               if (info.gw_info.iface) {
-                                       free(info.gw_info.iface);
-                                       info.gw_info.iface = 0;
-                               }
-                               if (info.gw_info.ip) {
-                                       free(info.gw_info.ip);
-                                       info.gw_info.ip = 0;
-                               }
+                               free_gateway_info();
                                break;
                        case OBJ_ioscheduler:
                                if(data.s)
@@ -2801,11 +2278,11 @@ void free_text_objects(struct text_object *root, int internal)
                        case OBJ_desktop:
                        case OBJ_desktop_number:
                        case OBJ_desktop_name:
-                               if(info.x11.desktop.name) {
+                               if(info.x11.desktop.name && !internal) {
                                  free(info.x11.desktop.name);
                                  info.x11.desktop.name = NULL;
                                }
-                               if(info.x11.desktop.all_names) {
+                               if(info.x11.desktop.all_names && !internal) {
                                  free(info.x11.desktop.all_names);
                                  info.x11.desktop.all_names = NULL;
                                }