X-Git-Url: http://vcs.maemo.org/git/?a=blobdiff_plain;f=src%2Fcore.c;h=766b04587cc4265488af5b7fdaf140d636394102;hb=refs%2Fheads%2Fmaster;hp=36d1e34cdc4a13ca47ee04cedad77e60b980f9f7;hpb=8b76d8fb60cc85932c444a4325c9bd6b2bcb51fa;p=monky diff --git a/src/core.c b/src/core.c index 36d1e34..766b045 100644 --- a/src/core.c +++ b/src/core.c @@ -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. * @@ -36,7 +36,10 @@ #include "colours.h" #include "combine.h" #include "diskio.h" +#include "entropy.h" #include "exec.h" +#include "i8k.h" +#include "proc.h" #ifdef X11 #include "fonts.h" #endif @@ -49,6 +52,9 @@ #include "mail.h" #include "mboxscan.h" #include "net_stat.h" +#ifdef NVIDIA +#include "nvidia.h" +#endif #include "read_tcp.h" #include "scroll.h" #include "specials.h" @@ -71,12 +77,10 @@ #include "openbsd.h" #endif -/* OS specific prototypes to be implemented by linux.c & Co. */ -void update_entropy(void); - #include #include + /* strip a leading /dev/ if any, following symlinks first * * BEWARE: this function returns a pointer to static content @@ -150,60 +154,68 @@ 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 - || (unsigned int) atoi(&arg[0]) > info.cpu_count) { - obj->data.cpu_index = 1; + || atoi(&arg[0]) > info.cpu_count) { + obj->data.i = 1; /* NORM_ERR("freq: Invalid CPU number or you don't have that many CPUs! " "Displaying the clock for CPU 1."); */ } else { - obj->data.cpu_index = atoi(&arg[0]); + obj->data.i = atoi(&arg[0]); } - obj->a = 1; END OBJ(freq_g, 0) get_cpu_count(); if (!arg || !isdigit(arg[0]) || strlen(arg) >= 2 || atoi(&arg[0]) == 0 - || (unsigned int) atoi(&arg[0]) > info.cpu_count) { - obj->data.cpu_index = 1; + || atoi(&arg[0]) > info.cpu_count) { + obj->data.i = 1; /* NORM_ERR("freq_g: Invalid CPU number or you don't have that many " "CPUs! Displaying the clock for CPU 1."); */ } else { - obj->data.cpu_index = atoi(&arg[0]); + obj->data.i = atoi(&arg[0]); } - obj->a = 1; END OBJ_ARG(read_tcp, 0, "read_tcp: Needs \"(host) port\" as argument(s)") parse_read_tcp_arg(obj, arg, free_at_crash); #if defined(__linux__) END OBJ(voltage_mv, 0) get_cpu_count(); if (!arg || !isdigit(arg[0]) || strlen(arg) >= 2 || atoi(&arg[0]) == 0 - || (unsigned int) atoi(&arg[0]) > info.cpu_count) { - obj->data.cpu_index = 1; + || atoi(&arg[0]) > info.cpu_count) { + obj->data.i = 1; /* NORM_ERR("voltage_mv: Invalid CPU number or you don't have that many " "CPUs! Displaying voltage for CPU 1."); */ } else { - obj->data.cpu_index = atoi(&arg[0]); + obj->data.i = atoi(&arg[0]); } - obj->a = 1; END OBJ(voltage_v, 0) get_cpu_count(); if (!arg || !isdigit(arg[0]) || strlen(arg) >= 2 || atoi(&arg[0]) == 0 - || (unsigned int) atoi(&arg[0]) > info.cpu_count) { - obj->data.cpu_index = 1; + || atoi(&arg[0]) > info.cpu_count) { + obj->data.i = 1; /* NORM_ERR("voltage_v: Invalid CPU number or you don't have that many " "CPUs! Displaying voltage for CPU 1."); */ } else { - obj->data.cpu_index = atoi(&arg[0]); + obj->data.i = atoi(&arg[0]); } - obj->a = 1; #ifdef HAVE_IWLIB END OBJ(wireless_essid, &update_net_stats) @@ -234,7 +246,7 @@ struct text_object *construct_text_object(const char *s, const char *arg, long if (arg) { sscanf(arg, "%63s", bat); } else { - strcpy(bat, "BAT0"); + strcpy(bat, "bq27200-0"); } obj->data.s = strndup(bat, text_buffer_size); END OBJ(battery_short, 0) @@ -243,7 +255,7 @@ struct text_object *construct_text_object(const char *s, const char *arg, long if (arg) { sscanf(arg, "%63s", bat); } else { - strcpy(bat, "BAT0"); + strcpy(bat, "bq27200-0"); } obj->data.s = strndup(bat, text_buffer_size); END OBJ(battery_time, 0) @@ -252,7 +264,7 @@ struct text_object *construct_text_object(const char *s, const char *arg, long if (arg) { sscanf(arg, "%63s", bat); } else { - strcpy(bat, "BAT0"); + strcpy(bat, "bq27200-0"); } obj->data.s = strndup(bat, text_buffer_size); END OBJ(battery_percent, 0) @@ -261,20 +273,45 @@ struct text_object *construct_text_object(const char *s, const char *arg, long if (arg) { sscanf(arg, "%63s", bat); } else { - strcpy(bat, "BAT0"); + strcpy(bat, "bq27200-0"); } obj->data.s = strndup(bat, text_buffer_size); END OBJ(battery_bar, 0) char bat[64]; - SIZE_DEFAULTS(bar); - obj->b = 6; + + arg = scan_bar(obj, arg); + if (arg && strlen(arg)>0) { + sscanf(arg, "%63s", bat); + } else { + strcpy(bat, "bq27200-0"); + } + obj->data.s = strndup(bat, text_buffer_size); + END OBJ(battery_volts, 0) + char bat[64]; if (arg) { - arg = scan_bar(arg, &obj->a, &obj->b); sscanf(arg, "%63s", bat); } else { - strcpy(bat, "BAT0"); + strcpy(bat, "bq27200-0"); } obj->data.s = strndup(bat, text_buffer_size); + END OBJ(battery_temp, 0) + char bat[64]; + if (arg) { + sscanf(arg, "%63s", bat); + } else { + strcpy(bat, "bq27200-0"); + } + obj->data.s = strndup(bat, text_buffer_size); + END OBJ(battery_rate, 0) + char bat[64]; + if (arg) { + sscanf(arg, "%63s", bat); + } else { + strcpy(bat, "bq27200-0"); + } + obj->data.s = strndup(bat, text_buffer_size); + END OBJ(cell_radio_dbm, 0) + END OBJ(cell_radio_percent, 0) #endif /* !__OpenBSD__ */ #if defined(__linux__) @@ -292,7 +329,7 @@ struct text_object *construct_text_object(const char *s, const char *arg, long END OBJ(i8k_buttons_status, &update_i8k) #if defined(IBM) END OBJ(ibm_fan, 0) - END OBJ(ibm_temps, &get_ibm_acpi_temps, "ibm_temps: needs an argument") + END OBJ_ARG(ibm_temps, &get_ibm_acpi_temps, "ibm_temps: needs an argument") parse_ibm_temps_arg(obj, arg); END OBJ(ibm_volume, 0) END OBJ(ibm_brightness, 0) @@ -318,30 +355,15 @@ struct text_object *construct_text_object(const char *s, const char *arg, long #endif /* __linux__ */ #if (defined(__FreeBSD__) || defined(__linux__)) END OBJ_IF_ARG(if_up, 0, "if_up needs an argument") - obj->data.ifblock.s = strndup(arg, text_buffer_size); + parse_if_up_arg(obj, arg); #endif #if defined(__OpenBSD__) 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!"); - } else - obj->data.sensor = atoi(&arg[0]); + parse_obsd_sensor(obj, arg); 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!"); - } else - obj->data.sensor = atoi(&arg[0]); + parse_obsd_sensor(obj, arg); 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!"); - } else - obj->data.sensor = atoi(&arg[0]); + parse_obsd_sensor(obj, arg); END OBJ(obsd_vendor, 0) END OBJ(obsd_product, 0) #endif /* __OpenBSD__ */ @@ -349,80 +371,45 @@ struct text_object *construct_text_object(const char *s, const char *arg, long END OBJ(cached, &update_meminfo) #define SCAN_CPU(__arg, __var) { \ int __offset = 0; \ - if (__arg && sscanf(__arg, " cpu%u %n", &__var, &__offset) > 0) \ + if (__arg && sscanf(__arg, " cpu%d %n", &__var, &__offset) > 0) \ __arg += __offset; \ else \ __var = 0; \ } 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 + SCAN_CPU(arg, obj->data.i); + DBGP2("Adding $cpu for CPU %d", obj->data.i); 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 */ + SCAN_CPU(arg, obj->data.i); + scan_gauge(obj, arg); + DBGP2("Adding $cpugauge for CPU %d", obj->data.i); 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); + SCAN_CPU(arg, obj->data.i); + scan_bar(obj, arg); + DBGP2("Adding $cpubar for CPU %d", obj->data.i); #ifdef X11 END OBJ(cpugraph, &update_cpu_usage) char *buf = 0; - SIZE_DEFAULTS(graph); - SCAN_CPU(arg, obj->data.cpu_index); - buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d, - &obj->e, &obj->char_a, &obj->char_b); - DBGP2("Adding $cpugraph for CPU %d", obj->data.cpu_index); + SCAN_CPU(arg, obj->data.i); + buf = scan_graph(obj, arg, 100); + DBGP2("Adding $cpugraph for CPU %d", obj->data.i); if (buf) free(buf); END OBJ(loadgraph, &update_load_average) - 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) { - int a = 1, r = 3; - if (arg) { - r = sscanf(arg, "%d", &a); - } - obj->data.loadavg[0] = (r >= 1) ? (unsigned char) a : 0; - free(buf); - } + scan_loadgraph_arg(obj, arg); #endif /* X11 */ END OBJ(diskio, &update_diskio) - obj->data.diskio = prepare_diskio_stat(dev_name(arg)); + parse_diskio_arg(obj, dev_name(arg)); END OBJ(diskio_read, &update_diskio) - obj->data.diskio = prepare_diskio_stat(dev_name(arg)); + parse_diskio_arg(obj, dev_name(arg)); END OBJ(diskio_write, &update_diskio) - obj->data.diskio = prepare_diskio_stat(dev_name(arg)); + parse_diskio_arg(obj, dev_name(arg)); #ifdef X11 END OBJ(diskiograph, &update_diskio) - 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); - - obj->data.diskio = prepare_diskio_stat(dev_name(buf)); - if (buf) free(buf); + parse_diskiograph_arg(obj, dev_name(arg)); END OBJ(diskiograph_read, &update_diskio) - 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); - - obj->data.diskio = prepare_diskio_stat(dev_name(buf)); - if (buf) free(buf); + parse_diskiograph_arg(obj, dev_name(arg)); END OBJ(diskiograph_write, &update_diskio) - 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); - - obj->data.diskio = prepare_diskio_stat(dev_name(buf)); - if (buf) free(buf); + parse_diskiograph_arg(obj, dev_name(arg)); #endif /* X11 */ END OBJ(color, 0) #ifdef X11 @@ -490,8 +477,14 @@ struct text_object *construct_text_object(const char *s, const char *arg, long obj->data.s = scan_font(arg); #endif /* X11 */ END OBJ(conky_version, 0) + obj->type = OBJ_text; + obj->data.s = strdup(VERSION); END OBJ(conky_build_date, 0) + obj->type = OBJ_text; + obj->data.s = strdup(BUILD_DATE); END OBJ(conky_build_arch, 0) + obj->type = OBJ_text; + obj->data.s = strdup(BUILD_ARCH); END OBJ(downspeed, &update_net_stats) parse_net_stat_arg(obj, arg, free_at_crash); END OBJ(downspeedf, &update_net_stats) @@ -515,27 +508,21 @@ struct text_object *construct_text_object(const char *s, const char *arg, long END OBJ(execp, 0) scan_exec_arg(obj, arg); END OBJ(execbar, 0) - SIZE_DEFAULTS(bar); scan_exec_arg(obj, arg); -#ifdef X11 END OBJ(execgauge, 0) - SIZE_DEFAULTS(gauge); scan_exec_arg(obj, arg); +#ifdef X11 END OBJ(execgraph, 0) - SIZE_DEFAULTS(graph); - scan_exec_arg(obj, arg); + scan_execgraph_arg(obj, arg); #endif /* X11 */ END OBJ_ARG(execibar, 0, "execibar needs arguments") - SIZE_DEFAULTS(bar); scan_execi_arg(obj, arg); #ifdef X11 END OBJ_ARG(execigraph, 0, "execigraph needs arguments") - SIZE_DEFAULTS(graph); - scan_execi_arg(obj, arg); + scan_execgraph_arg(obj, arg); +#endif /* X11 */ END OBJ_ARG(execigauge, 0, "execigauge needs arguments") - SIZE_DEFAULTS(gauge); scan_execi_arg(obj, arg); -#endif /* X11 */ END OBJ_ARG(execi, 0, "execi needs arguments") scan_execi_arg(obj, arg); END OBJ_ARG(execpi, 0, "execpi needs arguments") @@ -549,35 +536,17 @@ struct text_object *construct_text_object(const char *s, const char *arg, long 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); + init_fs(obj, arg); END OBJ(fs_used_perc, &update_fs_stats) - if (!arg) { - arg = "/"; - } - obj->data.fs = prepare_fs_stat(arg); + init_fs(obj, arg); END OBJ(fs_free_perc, &update_fs_stats) - if (!arg) { - arg = "/"; - } - obj->data.fs = prepare_fs_stat(arg); + init_fs(obj, arg); END OBJ(fs_size, &update_fs_stats) - if (!arg) { - arg = "/"; - } - obj->data.fs = prepare_fs_stat(arg); + init_fs(obj, arg); END OBJ(fs_type, &update_fs_stats) - if (!arg) { - arg = "/"; - } - obj->data.fs = prepare_fs_stat(arg); + init_fs(obj, arg); END OBJ(fs_used, &update_fs_stats) - if (!arg) { - arg = "/"; - } - obj->data.fs = prepare_fs_stat(arg); + init_fs(obj, arg); END OBJ(hr, 0) obj->data.i = arg ? atoi(arg) : 1; END OBJ(nameserver, &update_dns_data) @@ -588,20 +557,10 @@ struct text_object *construct_text_object(const char *s, const char *arg, long obj->data.i = arg ? atoi(arg) : 1; END OBJ_ARG(goto, 0, "goto needs arguments") obj->data.i = atoi(arg); +#ifdef X11 END OBJ(tab, 0) - int a = 10, b = 0; - - if (arg) { - if (sscanf(arg, "%d %d", &a, &b) != 2) { - sscanf(arg, "%d", &b); - } - } - if (a <= 0) { - a = 1; - } - obj->data.pair.a = a; - obj->data.pair.b = b; - + scan_tab(obj, arg); +#endif /* X11 */ #ifdef __linux__ END OBJ_ARG(i2c, 0, "i2c needs arguments") parse_i2c_sensor(obj, arg); @@ -609,8 +568,11 @@ struct text_object *construct_text_object(const char *s, const char *arg, long parse_platform_sensor(obj, arg); END OBJ_ARG(hwmon, 0, "hwmon needs argumanets") parse_hwmon_sensor(obj, arg); + END OBJ(addrs, &update_net_stats) + parse_net_stat_arg(obj, arg, free_at_crash); #endif /* __linux__ */ - + END OBJ(addr, &update_net_stats) + parse_net_stat_arg(obj, arg, free_at_crash); END /* we have four different types of top (top, top_mem, top_time and top_io). To * avoid having almost-same code four times, we have this special @@ -621,13 +583,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); -#if defined(__linux__) - 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); @@ -636,317 +593,86 @@ struct text_object *construct_text_object(const char *s, const char *arg, long 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) { - r = sscanf(arg, "%d %d %d", &a, &b, &c); - if (r >= 3 && (c < 1 || c > 3)) { - r--; - } - if (r >= 2 && (b < 1 || b > 3)) { - r--, b = c; - } - if (r >= 1 && (a < 1 || a > 3)) { - r--, a = b, b = c; - } - } - 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; + scan_loadavg_arg(obj, arg); 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); + extract_variable_text_internal(obj->sub, arg); 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); + extract_variable_text_internal(obj->sub, arg); 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 { - 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); + obj->data.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__ + obj->data.s = strndup(arg, text_buffer_size); +#if defined(__linux__) || defined(__FreeBSD__) || defined(__FreeBSD_kernel__) END OBJ_IF_ARG(if_running, &update_top, "if_running needs an argument") top_running = 1; - obj->data.ifblock.s = strndup(arg, text_buffer_size); + obj->data.s = strndup(arg, text_buffer_size); #else END OBJ_IF_ARG(if_running, 0, "if_running needs an argument") - char buf[256]; + char buf[text_buffer_size]; - snprintf(buf, 256, "pidof %s >/dev/null", arg); - obj->data.ifblock.s = strndup(buf, text_buffer_size); + snprintf(buf, text_buffer_size, "pidof %s >/dev/null", arg); + obj->data.s = strndup(buf, text_buffer_size); #endif END OBJ(kernel, 0) END OBJ(machine, 0) END OBJ(mails, 0) - float n1; - char mbox[256], dst[256]; - - if (!arg) { - n1 = 9.5; - /* Kapil: Changed from MAIL_FILE to - current_mail_spool since the latter - is a copy of the former if undefined - but the latter should take precedence - if defined */ - strncpy(mbox, current_mail_spool, sizeof(mbox)); - } else { - if (sscanf(arg, "%s %f", mbox, &n1) != 2) { - n1 = 9.5; - strncpy(mbox, arg, sizeof(mbox)); - } - } - - variable_substitute(mbox, dst, sizeof(dst)); - obj->data.local_mail.mbox = strndup(dst, text_buffer_size); - obj->data.local_mail.interval = n1; + parse_local_mail_args(obj, arg); END OBJ(new_mails, 0) - float n1; - char mbox[256], dst[256]; - - if (!arg) { - n1 = 9.5; - strncpy(mbox, current_mail_spool, sizeof(mbox)); - } else { - if (sscanf(arg, "%s %f", mbox, &n1) != 2) { - n1 = 9.5; - strncpy(mbox, arg, sizeof(mbox)); - } - } - - variable_substitute(mbox, dst, sizeof(dst)); - obj->data.local_mail.mbox = strndup(dst, text_buffer_size); - obj->data.local_mail.interval = n1; + parse_local_mail_args(obj, arg); END OBJ(seen_mails, 0) - float n1; - char mbox[256], dst[256]; - - if (!arg) { - n1 = 9.5; - strncpy(mbox, current_mail_spool, sizeof(mbox)); - } else { - if (sscanf(arg, "%s %f", mbox, &n1) != 2) { - n1 = 9.5; - strncpy(mbox, arg, sizeof(mbox)); - } - } - - variable_substitute(mbox, dst, sizeof(dst)); - obj->data.local_mail.mbox = strndup(dst, text_buffer_size); - obj->data.local_mail.interval = n1; + parse_local_mail_args(obj, arg); END OBJ(unseen_mails, 0) - float n1; - char mbox[256], dst[256]; - - if (!arg) { - n1 = 9.5; - strncpy(mbox, current_mail_spool, sizeof(mbox)); - } else { - if (sscanf(arg, "%s %f", mbox, &n1) != 2) { - n1 = 9.5; - strncpy(mbox, arg, sizeof(mbox)); - } - } - - variable_substitute(mbox, dst, sizeof(dst)); - obj->data.local_mail.mbox = strndup(dst, text_buffer_size); - obj->data.local_mail.interval = n1; + parse_local_mail_args(obj, arg); END OBJ(flagged_mails, 0) - float n1; - char mbox[256], dst[256]; - - if (!arg) { - n1 = 9.5; - strncpy(mbox, current_mail_spool, sizeof(mbox)); - } else { - if (sscanf(arg, "%s %f", mbox, &n1) != 2) { - n1 = 9.5; - strncpy(mbox, arg, sizeof(mbox)); - } - } - - variable_substitute(mbox, dst, sizeof(dst)); - obj->data.local_mail.mbox = strndup(dst, text_buffer_size); - obj->data.local_mail.interval = n1; + parse_local_mail_args(obj, arg); END OBJ(unflagged_mails, 0) - float n1; - char mbox[256], dst[256]; - - if (!arg) { - n1 = 9.5; - strncpy(mbox, current_mail_spool, sizeof(mbox)); - } else { - if (sscanf(arg, "%s %f", mbox, &n1) != 2) { - n1 = 9.5; - strncpy(mbox, arg, sizeof(mbox)); - } - } - - variable_substitute(mbox, dst, sizeof(dst)); - obj->data.local_mail.mbox = strndup(dst, text_buffer_size); - obj->data.local_mail.interval = n1; + parse_local_mail_args(obj, arg); END OBJ(forwarded_mails, 0) - float n1; - char mbox[256], dst[256]; - - if (!arg) { - n1 = 9.5; - strncpy(mbox, current_mail_spool, sizeof(mbox)); - } else { - if (sscanf(arg, "%s %f", mbox, &n1) != 2) { - n1 = 9.5; - strncpy(mbox, arg, sizeof(mbox)); - } - } - - variable_substitute(mbox, dst, sizeof(dst)); - obj->data.local_mail.mbox = strndup(dst, text_buffer_size); - obj->data.local_mail.interval = n1; + parse_local_mail_args(obj, arg); END OBJ(unforwarded_mails, 0) - float n1; - char mbox[256], dst[256]; - - if (!arg) { - n1 = 9.5; - strncpy(mbox, current_mail_spool, sizeof(mbox)); - } else { - if (sscanf(arg, "%s %f", mbox, &n1) != 2) { - n1 = 9.5; - strncpy(mbox, arg, sizeof(mbox)); - } - } - - variable_substitute(mbox, dst, sizeof(dst)); - obj->data.local_mail.mbox = strndup(dst, text_buffer_size); - obj->data.local_mail.interval = n1; + parse_local_mail_args(obj, arg); END OBJ(replied_mails, 0) - float n1; - char mbox[256], dst[256]; - - if (!arg) { - n1 = 9.5; - strncpy(mbox, current_mail_spool, sizeof(mbox)); - } else { - if (sscanf(arg, "%s %f", mbox, &n1) != 2) { - n1 = 9.5; - strncpy(mbox, arg, sizeof(mbox)); - } - } - - variable_substitute(mbox, dst, sizeof(dst)); - obj->data.local_mail.mbox = strndup(dst, text_buffer_size); - obj->data.local_mail.interval = n1; + parse_local_mail_args(obj, arg); END OBJ(unreplied_mails, 0) - float n1; - char mbox[256], dst[256]; - - if (!arg) { - n1 = 9.5; - strncpy(mbox, current_mail_spool, sizeof(mbox)); - } else { - if (sscanf(arg, "%s %f", mbox, &n1) != 2) { - n1 = 9.5; - strncpy(mbox, arg, sizeof(mbox)); - } - } - - variable_substitute(mbox, dst, sizeof(dst)); - obj->data.local_mail.mbox = strndup(dst, text_buffer_size); - obj->data.local_mail.interval = n1; + parse_local_mail_args(obj, arg); END OBJ(draft_mails, 0) - float n1; - char mbox[256], dst[256]; - - if (!arg) { - n1 = 9.5; - strncpy(mbox, current_mail_spool, sizeof(mbox)); - } else { - if (sscanf(arg, "%s %f", mbox, &n1) != 2) { - n1 = 9.5; - strncpy(mbox, arg, sizeof(mbox)); - } - } - - variable_substitute(mbox, dst, sizeof(dst)); - obj->data.local_mail.mbox = strndup(dst, text_buffer_size); - obj->data.local_mail.interval = n1; + parse_local_mail_args(obj, arg); END OBJ(trashed_mails, 0) - float n1; - char mbox[256], dst[256]; - - if (!arg) { - n1 = 9.5; - strncpy(mbox, current_mail_spool, sizeof(mbox)); - } else { - if (sscanf(arg, "%s %f", mbox, &n1) != 2) { - n1 = 9.5; - strncpy(mbox, arg, sizeof(mbox)); - } - } - - variable_substitute(mbox, dst, sizeof(dst)); - obj->data.local_mail.mbox = strndup(dst, text_buffer_size); - obj->data.local_mail.interval = n1; + parse_local_mail_args(obj, arg); END OBJ(mboxscan, 0) - obj->data.mboxscan.args = (char *) malloc(text_buffer_size); - obj->data.mboxscan.output = (char *) malloc(text_buffer_size); - /* 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); + parse_mboxscan_arg(obj, arg); 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, &update_meminfo) - SIZE_DEFAULTS(gauge); - scan_gauge(arg, &obj->data.pair.a, &obj->data.pair.b); -#endif /* X11*/ + scan_gauge(obj, arg); END OBJ(membar, &update_meminfo) - SIZE_DEFAULTS(bar); - scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b); + scan_bar(obj, arg); #ifdef X11 END OBJ(memgraph, &update_meminfo) 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); + buf = scan_graph(obj, arg, 100); if (buf) free(buf); #endif /* X11*/ END OBJ(mixer, 0) - obj->data.l = mixer_init(arg); + parse_mixer_arg(obj, arg); END OBJ(mixerl, 0) - obj->data.l = mixer_init(arg); + parse_mixer_arg(obj, arg); END OBJ(mixerr, 0) - obj->data.l = mixer_init(arg); -#ifdef X11 + parse_mixer_arg(obj, arg); END OBJ(mixerbar, 0) - SIZE_DEFAULTS(bar); - scan_mixer_bar(arg, &obj->data.mixerbar.l, &obj->data.mixerbar.w, - &obj->data.mixerbar.h); + scan_mixer_bar(obj, arg); END OBJ(mixerlbar, 0) - SIZE_DEFAULTS(bar); - scan_mixer_bar(arg, &obj->data.mixerbar.l, &obj->data.mixerbar.w, - &obj->data.mixerbar.h); + scan_mixer_bar(obj, arg); END OBJ(mixerrbar, 0) - SIZE_DEFAULTS(bar); - scan_mixer_bar(arg, &obj->data.mixerbar.l, &obj->data.mixerbar.w, - &obj->data.mixerbar.h); -#endif + scan_mixer_bar(obj, arg); END OBJ_IF(if_mixer_mute, 0) - obj->data.ifblock.i = mixer_init(arg); + parse_mixer_arg(obj, arg); #ifdef X11 END OBJ(monitor, &update_x11info) END OBJ(monitor_number, &update_x11info) @@ -954,9 +680,148 @@ struct text_object *construct_text_object(const char *s, const char *arg, long END OBJ(desktop_number, &update_x11info) END OBJ(desktop_name, &update_x11info) #endif + END OBJ_ARG(format_time, 0, "format_time needs a pid as argument") + 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") + obj->sub = malloc(sizeof(struct text_object)); + extract_variable_text_internal(obj->sub, arg); + END OBJ_ARG(pid_cmdline, 0, "pid_cmdline needs a pid as argument") + obj->sub = malloc(sizeof(struct text_object)); + extract_variable_text_internal(obj->sub, arg); + END OBJ_ARG(pid_cwd, 0, "pid_cwd needs a pid as argument") + obj->sub = malloc(sizeof(struct text_object)); + extract_variable_text_internal(obj->sub, arg); + END OBJ_ARG(pid_environ, 0, "pid_environ needs arguments") + obj->sub = malloc(sizeof(struct text_object)); + extract_variable_text_internal(obj->sub, arg); + END OBJ_ARG(pid_environ_list, 0, "pid_environ_list needs a pid as argument") + obj->sub = malloc(sizeof(struct text_object)); + extract_variable_text_internal(obj->sub, arg); + END OBJ_ARG(pid_exe, 0, "pid_exe needs a pid as argument") + obj->sub = malloc(sizeof(struct text_object)); + extract_variable_text_internal(obj->sub, arg); + END OBJ_ARG(pid_nice, 0, "pid_nice needs a pid as argument") + obj->sub = malloc(sizeof(struct text_object)); + extract_variable_text_internal(obj->sub, arg); + END OBJ_ARG(pid_openfiles, 0, "pid_openfiles needs a pid as argument") + obj->sub = malloc(sizeof(struct text_object)); + extract_variable_text_internal(obj->sub, arg); + END OBJ_ARG(pid_parent, 0, "pid_parent needs a pid as argument") + obj->sub = malloc(sizeof(struct text_object)); + extract_variable_text_internal(obj->sub, arg); + END OBJ_ARG(pid_priority, 0, "pid_priority needs a pid as argument") + obj->sub = malloc(sizeof(struct text_object)); + extract_variable_text_internal(obj->sub, arg); + END OBJ_ARG(pid_state, 0, "pid_state needs a pid as argument") + obj->sub = malloc(sizeof(struct text_object)); + extract_variable_text_internal(obj->sub, arg); + END OBJ_ARG(pid_state_short, 0, "pid_state_short needs a pid as argument") + obj->sub = malloc(sizeof(struct text_object)); + extract_variable_text_internal(obj->sub, arg); + END OBJ_ARG(pid_stderr, 0, "pid_stderr needs a pid as argument") + obj->sub = malloc(sizeof(struct text_object)); + extract_variable_text_internal(obj->sub, arg); + END OBJ_ARG(pid_stdin, 0, "pid_stdin needs a pid as argument") + obj->sub = malloc(sizeof(struct text_object)); + extract_variable_text_internal(obj->sub, arg); + END OBJ_ARG(pid_stdout, 0, "pid_stdout needs a pid as argument") + obj->sub = malloc(sizeof(struct text_object)); + extract_variable_text_internal(obj->sub, arg); + END OBJ_ARG(pid_threads, 0, "pid_threads needs a pid as argument") + obj->sub = malloc(sizeof(struct text_object)); + extract_variable_text_internal(obj->sub, arg); + END OBJ_ARG(pid_thread_list, 0, "pid_thread_list needs a pid as argument") + obj->sub = malloc(sizeof(struct text_object)); + extract_variable_text_internal(obj->sub, arg); + END OBJ_ARG(pid_time_kernelmode, 0, "pid_time_kernelmode needs a pid as argument") + obj->sub = malloc(sizeof(struct text_object)); + extract_variable_text_internal(obj->sub, arg); + END OBJ_ARG(pid_time_usermode, 0, "pid_time_usermode needs a pid as argument") + obj->sub = malloc(sizeof(struct text_object)); + extract_variable_text_internal(obj->sub, arg); + END OBJ_ARG(pid_time, 0, "pid_time needs a pid as argument") + obj->sub = malloc(sizeof(struct text_object)); + extract_variable_text_internal(obj->sub, arg); + END OBJ_ARG(pid_uid, 0, "pid_uid needs a pid as argument") + obj->sub = malloc(sizeof(struct text_object)); + extract_variable_text_internal(obj->sub, arg); + END OBJ_ARG(pid_euid, 0, "pid_euid needs a pid as argument") + obj->sub = malloc(sizeof(struct text_object)); + extract_variable_text_internal(obj->sub, arg); + END OBJ_ARG(pid_suid, 0, "pid_suid needs a pid as argument") + obj->sub = malloc(sizeof(struct text_object)); + extract_variable_text_internal(obj->sub, arg); + END OBJ_ARG(pid_fsuid, 0, "pid_fsuid needs a pid as argument") + obj->sub = malloc(sizeof(struct text_object)); + extract_variable_text_internal(obj->sub, arg); + END OBJ_ARG(pid_gid, 0, "pid_gid needs a pid as argument") + obj->sub = malloc(sizeof(struct text_object)); + extract_variable_text_internal(obj->sub, arg); + END OBJ_ARG(pid_egid, 0, "pid_egid needs a pid as argument") + obj->sub = malloc(sizeof(struct text_object)); + extract_variable_text_internal(obj->sub, arg); + END OBJ_ARG(pid_sgid, 0, "pid_sgid needs a pid as argument") + obj->sub = malloc(sizeof(struct text_object)); + extract_variable_text_internal(obj->sub, arg); + END OBJ_ARG(pid_fsgid, 0, "pid_fsgid needs a pid as argument") + obj->sub = malloc(sizeof(struct text_object)); + extract_variable_text_internal(obj->sub, arg); + END OBJ_ARG(gid_name, 0, "gid_name needs a gid as argument") + obj->sub = malloc(sizeof(struct text_object)); + extract_variable_text_internal(obj->sub, arg); + END OBJ_ARG(uid_name, 0, "uid_name needs a uid as argument") + obj->sub = malloc(sizeof(struct text_object)); + extract_variable_text_internal(obj->sub, arg); + END OBJ_ARG(pid_read, 0, "pid_read needs a pid as argument") + obj->sub = malloc(sizeof(struct text_object)); + extract_variable_text_internal(obj->sub, arg); + END OBJ_ARG(pid_vmpeak, 0, "pid_vmpeak needs a pid as argument") + obj->sub = malloc(sizeof(struct text_object)); + extract_variable_text_internal(obj->sub, arg); + END OBJ_ARG(pid_vmsize, 0, "pid_vmsize needs a pid as argument") + obj->sub = malloc(sizeof(struct text_object)); + extract_variable_text_internal(obj->sub, arg); + END OBJ_ARG(pid_vmlck, 0, "pid_vmlck needs a pid as argument") + obj->sub = malloc(sizeof(struct text_object)); + extract_variable_text_internal(obj->sub, arg); + END OBJ_ARG(pid_vmhwm, 0, "pid_vmhwm needs a pid as argument") + obj->sub = malloc(sizeof(struct text_object)); + extract_variable_text_internal(obj->sub, arg); + END OBJ_ARG(pid_vmrss, 0, "pid_vmrss needs a pid as argument") + obj->sub = malloc(sizeof(struct text_object)); + extract_variable_text_internal(obj->sub, arg); + END OBJ_ARG(pid_vmdata, 0, "pid_vmdata needs a pid as argument") + obj->sub = malloc(sizeof(struct text_object)); + extract_variable_text_internal(obj->sub, arg); + END OBJ_ARG(pid_vmstk, 0, "pid_vmstk needs a pid as argument") + obj->sub = malloc(sizeof(struct text_object)); + extract_variable_text_internal(obj->sub, arg); + END OBJ_ARG(pid_vmexe, 0, "pid_vmexe needs a pid as argument") + obj->sub = malloc(sizeof(struct text_object)); + extract_variable_text_internal(obj->sub, arg); + END OBJ_ARG(pid_vmlib, 0, "pid_vmlib needs a pid as argument") + obj->sub = malloc(sizeof(struct text_object)); + extract_variable_text_internal(obj->sub, arg); + END OBJ_ARG(pid_vmpte, 0, "pid_vmpte needs a pid as argument") + obj->sub = malloc(sizeof(struct text_object)); + extract_variable_text_internal(obj->sub, arg); + END OBJ_ARG(pid_write, 0, "pid_write needs a pid as argument") + obj->sub = malloc(sizeof(struct text_object)); + extract_variable_text_internal(obj->sub, arg); END OBJ(processes, &update_total_processes) + END OBJ(running_processes, &update_top) + top_running = 1; +#ifdef __linux__ + END OBJ(threads, &update_threads) + END OBJ(running_threads, &update_stat) +#else END OBJ(running_processes, &update_running_processes) +#endif /* __linux__ */ END OBJ(shadecolor, 0) #ifdef X11 obj->data.l = arg ? get_x11_color(arg) : default_bg_color; @@ -967,26 +832,14 @@ struct text_object *construct_text_object(const char *s, const char *arg, long #endif /* X11 */ END OBJ(stippled_hr, 0) #ifdef X11 - int a = get_stippled_borders(), b = 1; - - if (arg) { - if (sscanf(arg, "%d %d", &a, &b) != 2) { - sscanf(arg, "%d", &b); - } - } - if (a <= 0) { - a = 1; - } - obj->data.pair.a = a; - obj->data.pair.b = b; + scan_stippled_hr(obj, arg); #endif /* X11 */ 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); + scan_bar(obj, arg); END OBJ(sysname, 0) END OBJ(time, 0) scan_time(obj, arg); @@ -1006,9 +859,9 @@ struct text_object *construct_text_object(const char *s, const char *arg, long parse_net_stat_arg(obj, arg, free_at_crash); END OBJ(updates, 0) END OBJ_IF(if_updatenr, 0) - obj->data.ifblock.i = arg ? atoi(arg) : 0; - if(obj->data.ifblock.i == 0) CRIT_ERR(obj, free_at_crash, "if_updatenr needs a number above 0 as argument"); - set_updatereset(obj->data.ifblock.i > get_updatereset() ? obj->data.ifblock.i : get_updatereset()); + obj->data.i = arg ? atoi(arg) : 0; + if(obj->data.i == 0) CRIT_ERR(obj, free_at_crash, "if_updatenr needs a number above 0 as argument"); + set_updatereset(obj->data.i > get_updatereset() ? obj->data.i : get_updatereset()); END OBJ(alignr, 0) obj->data.i = arg ? atoi(arg) : 0; END OBJ(alignc, 0) @@ -1023,18 +876,16 @@ struct text_object *construct_text_object(const char *s, const char *arg, long #endif END OBJ(uptime_short, &update_uptime) END OBJ(uptime, &update_uptime) +#if defined(__linux__) END OBJ(user_names, &update_users) END OBJ(user_times, &update_users) + END OBJ_ARG(user_time, 0, "user time needs a console name as argument") + obj->data.s = strndup(arg, text_buffer_size); END OBJ(user_terms, &update_users) END OBJ(user_number, &update_users) -#if defined(__linux__) END OBJ(gw_iface, &update_gateway_info) END OBJ(gw_ip, &update_gateway_info) #endif /* !__linux__ */ -#ifndef __OpenBSD__ - END OBJ(adt746xcpu, 0) - END OBJ(adt746xfan, 0) -#endif /* !__OpenBSD__ */ #if (defined(__FreeBSD__) || defined(__FreeBSD_kernel__) \ || defined(__OpenBSD__)) && (defined(i386) || defined(__i386__)) END OBJ(apm_adapter, 0) @@ -1042,60 +893,31 @@ struct text_object *construct_text_object(const char *s, const char *arg, long END OBJ(apm_battery_time, 0) #endif /* __FreeBSD__ */ END OBJ(imap_unseen, 0) - if (arg) { - // proccss - obj->data.mail = parse_mail_args(IMAP_TYPE, arg); - obj->char_b = 0; - } else { - obj->char_b = 1; - } + parse_imap_mail_args(obj, arg); END OBJ(imap_messages, 0) - if (arg) { - // proccss - obj->data.mail = parse_mail_args(IMAP_TYPE, arg); - obj->char_b = 0; - } else { - obj->char_b = 1; - } + parse_imap_mail_args(obj, arg); END OBJ(pop3_unseen, 0) - if (arg) { - // proccss - obj->data.mail = parse_mail_args(POP3_TYPE, arg); - obj->char_b = 0; - } else { - obj->char_b = 1; - } + parse_pop3_mail_args(obj, arg); END OBJ(pop3_used, 0) - if (arg) { - // proccss - obj->data.mail = parse_mail_args(POP3_TYPE, arg); - obj->char_b = 0; - } else { - obj->char_b = 1; - } + parse_pop3_mail_args(obj, arg); #ifdef IBM 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); + obj->data.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_ARG(smapi_bat_bar, 0, "smapi_bat_bar needs an argument") int cnt; - SIZE_DEFAULTS(bar); 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 */ + } else + arg = scan_bar(obj, arg + cnt); #endif /* IBM */ #ifdef MPD #define mpd_set_maxlen(name) \ @@ -1134,8 +956,7 @@ struct text_object *construct_text_object(const char *s, const char *arg, long 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); + scan_bar(obj, arg); init_mpd(); END OBJ(mpd_smart, &update_mpd) mpd_set_maxlen(mpd_smart); @@ -1175,9 +996,8 @@ struct text_object *construct_text_object(const char *s, const char *arg, long END OBJ(xmms2_percent, &update_xmms2) #ifdef X11 END OBJ(xmms2_bar, &update_xmms2) - SIZE_DEFAULTS(bar); - scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b); -#endif /* X11 */ + scan_bar(obj, arg); +#endif END OBJ(xmms2_smart, &update_xmms2) END OBJ(xmms2_playlist, &update_xmms2) END OBJ(xmms2_timesplayed, &update_xmms2) @@ -1205,9 +1025,8 @@ struct text_object *construct_text_object(const char *s, const char *arg, long END OBJ(audacious_main_volume, &update_audacious) #ifdef X11 END OBJ(audacious_bar, &update_audacious) - SIZE_DEFAULTS(bar); - scan_bar(arg, &obj->a, &obj->b); -#endif /* X11 */ + scan_bar(obj, arg); +#endif #endif #ifdef BMPX END OBJ(bmpx_title, &update_bmpx) @@ -1249,8 +1068,7 @@ struct text_object *construct_text_object(const char *s, const char *arg, long END OBJ_ARG(lua_parse, 0, "lua_parse needs arguments: [function parameters]") obj->data.s = strndup(arg, text_buffer_size); END OBJ_ARG(lua_bar, 0, "lua_bar needs arguments: , [function parameters]") - SIZE_DEFAULTS(bar); - arg = scan_bar(arg, &obj->a, &obj->b); + arg = scan_bar(obj, arg); if(arg) { obj->data.s = strndup(arg, text_buffer_size); } else { @@ -1259,23 +1077,20 @@ struct text_object *construct_text_object(const char *s, const char *arg, long #ifdef X11 END OBJ_ARG(lua_graph, 0, "lua_graph needs arguments: [height],[width] [gradient colour 1] [gradient colour 2] [scale] [-t] [-l]") 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); + buf = scan_graph(obj, arg, 0); if (buf) { obj->data.s = buf; } else { CRIT_ERR(obj, free_at_crash, "lua_graph needs arguments: [height],[width] [gradient colour 1] [gradient colour 2] [scale] [-t] [-l]"); } +#endif /* X11 */ END OBJ_ARG(lua_gauge, 0, "lua_gauge needs arguments: , [function parameters]") - SIZE_DEFAULTS(gauge); - arg = scan_gauge(arg, &obj->a, &obj->b); + arg = scan_gauge(obj, arg); if (arg) { obj->data.s = strndup(arg, text_buffer_size); } else { CRIT_ERR(obj, free_at_crash, "lua_gauge needs arguments: , [function parameters]"); } -#endif /* X11 */ #endif /* HAVE_LUA */ #ifdef HDDTEMP END OBJ(hddtemp, &update_hddtemp) @@ -1284,14 +1099,13 @@ struct text_object *construct_text_object(const char *s, const char *arg, long #endif /* HDDTEMP */ #ifdef TCP_PORT_MONITOR END OBJ_ARG(tcp_portmon, &tcp_portmon_update, "tcp_portmon: needs arguments") - tcp_portmon_init(arg, &obj->data.tcp_port_monitor); + tcp_portmon_init(obj, arg); #endif /* TCP_PORT_MONITOR */ 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); + scan_bar(obj, arg); END OBJ_ARG(include, 0, "include needs a argument") struct conftree *leaf = conftree_add(currentconffile, arg); if(leaf) { @@ -1318,7 +1132,7 @@ struct text_object *construct_text_object(const char *s, const char *arg, long parse_combine_arg(obj, arg, free_at_crash); #ifdef NVIDIA END OBJ_ARG(nvidia, 0, "nvidia needs an argument") - if (set_nvidia_type(&obj->data.nvidia, arg)) { + if (set_nvidia_type(obj, arg)) { CRIT_ERR(obj, free_at_crash, "nvidia: invalid argument" " specified: '%s'\n", arg); } @@ -1341,30 +1155,26 @@ struct text_object *construct_text_object(const char *s, const char *arg, long 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); + scan_bar(obj, arg); #ifdef X11 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); + buf = scan_graph(obj, arg, 0); 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_loadgauge, &update_apcupsd) + scan_gauge(obj, arg); 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]; + char buf[text_buffer_size]; NORM_ERR("unknown variable %s", s); obj->type = OBJ_text; - snprintf(buf, 256, "${%s}", s); + snprintf(buf, text_buffer_size, "${%s}", s); obj->data.s = strndup(buf, text_buffer_size); } #undef OBJ @@ -1375,7 +1185,6 @@ struct text_object *construct_text_object(const char *s, const char *arg, long #undef __OBJ_IF #undef __OBJ_ARG #undef END -#undef SIZE_DEFAULTS return obj; } @@ -1435,9 +1244,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)); @@ -1459,7 +1268,7 @@ int extract_variable_text_internal(struct text_object *retval, const char *const s = p; if (*p != '$') { - char buf[256]; + char buf[text_buffer_size]; const char *var; /* variable is either $foo or ${foo} */ @@ -1489,7 +1298,7 @@ int extract_variable_text_internal(struct text_object *retval, const char *const } /* copy variable to buffer */ - len = (p - s > 255) ? 255 : (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'; @@ -1550,7 +1359,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--; } @@ -1590,14 +1399,73 @@ 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: case OBJ_platform: case OBJ_hwmon: - close(data.sysfs.fd); + free_sysfs_sensor(obj); break; #endif /* __linux__ */ + case OBJ_cmdline_to_pid: + free(data.s); + break; + case OBJ_format_time: + case OBJ_pid_environ: + case OBJ_pid_chroot: + case OBJ_pid_cmdline: + case OBJ_pid_cwd: + case OBJ_pid_environ_list: + case OBJ_pid_exe: + case OBJ_pid_nice: + case OBJ_pid_openfiles: + case OBJ_pid_parent: + case OBJ_pid_priority: + case OBJ_pid_state: + case OBJ_pid_state_short: + case OBJ_pid_stderr: + case OBJ_pid_stdin: + case OBJ_pid_stdout: + case OBJ_pid_threads: + case OBJ_pid_thread_list: + case OBJ_pid_time_kernelmode: + case OBJ_pid_time_usermode: + case OBJ_pid_time: + case OBJ_pid_uid: + case OBJ_pid_euid: + case OBJ_pid_suid: + case OBJ_pid_fsuid: + case OBJ_pid_gid: + case OBJ_pid_egid: + case OBJ_pid_sgid: + case OBJ_pid_fsgid: + case OBJ_pid_read: + case OBJ_pid_vmpeak: + case OBJ_pid_vmsize: + case OBJ_pid_vmlck: + case OBJ_pid_vmhwm: + case OBJ_pid_vmrss: + case OBJ_pid_vmdata: + case OBJ_pid_vmstk: + case OBJ_pid_vmexe: + case OBJ_pid_vmlib: + case OBJ_pid_vmpte: + case OBJ_pid_write: + case OBJ_gid_name: + if(obj->sub) { + free_text_objects(obj->sub, 1); + free(obj->sub); + } + break; + case OBJ_uid_name: + if(obj->sub) { + free_text_objects(obj->sub, 1); + free(obj->sub); + } + break; case OBJ_read_tcp: free_read_tcp(obj); break; @@ -1609,8 +1477,7 @@ void free_text_objects(struct text_object *root, int internal) free_tztime(obj); break; case OBJ_mboxscan: - free(data.mboxscan.args); - free(data.mboxscan.output); + free_mboxscan(obj); break; case OBJ_mails: case OBJ_new_mails: @@ -1624,54 +1491,38 @@ void free_text_objects(struct text_object *root, int internal) case OBJ_unreplied_mails: case OBJ_draft_mails: case OBJ_trashed_mails: - free(data.local_mail.mbox); + free_local_mails(obj); break; case OBJ_imap_unseen: - if (!obj->char_b) { - free(data.mail); - } - break; case OBJ_imap_messages: - if (!obj->char_b) { - free(data.mail); - } - break; case OBJ_pop3_unseen: - if (!obj->char_b) { - free(data.mail); - } - break; case OBJ_pop3_used: - if (!obj->char_b) { - free(data.mail); - } + free_mail_obj(obj); break; case OBJ_if_empty: case OBJ_if_match: free_text_objects(obj->sub, 1); free(obj->sub); - /* fall through */ + break; case OBJ_if_existing: case OBJ_if_mounted: case OBJ_if_running: - free(data.ifblock.s); - free(data.ifblock.str); + free(data.s); break; case OBJ_head: case OBJ_tail: - free(data.headtail.logfile); - if(data.headtail.buffer) { - free(data.headtail.buffer); - } + free_tailhead(obj); break; case OBJ_text: case OBJ_font: case OBJ_image: case OBJ_eval: + free(data.s); + break; case OBJ_exec: case OBJ_execbar: -#ifdef X11 case OBJ_execgauge: +#ifdef X11 case OBJ_execgraph: #endif case OBJ_execp: @@ -1687,8 +1538,6 @@ void free_text_objects(struct text_object *root, int internal) free(data.s); break; case OBJ_if_gw: - free(data.ifblock.s); - free(data.ifblock.str); case OBJ_gw_iface: case OBJ_gw_ip: free_gateway_info(); @@ -1700,8 +1549,7 @@ void free_text_objects(struct text_object *root, int internal) #endif #if (defined(__FreeBSD__) || defined(__linux__)) case OBJ_if_up: - free(data.ifblock.s); - free(data.ifblock.str); + free_if_up(obj); break; #endif #ifdef XMMS2 @@ -1785,29 +1633,27 @@ void free_text_objects(struct text_object *root, int internal) #endif #ifdef EVE case OBJ_eve: + free_eve(obj); break; #endif #ifdef HAVE_CURL case OBJ_curl: - free(data.curl.uri); + curl_obj_free(obj); break; #endif #ifdef RSS case OBJ_rss: - free(data.rss.uri); - free(data.rss.action); + rss_free_obj_info(obj); break; #endif #ifdef WEATHER case OBJ_weather: - free(data.weather.uri); - free(data.weather.data_type); + free_weather(obj); break; #endif #ifdef XOAP case OBJ_weather_forecast: - free(data.weather_forecast.uri); - free(data.weather_forecast.data_type); + free_weather(obj); break; #endif #ifdef HAVE_LUA @@ -1816,8 +1662,8 @@ void free_text_objects(struct text_object *root, int internal) case OBJ_lua_bar: #ifdef X11 case OBJ_lua_graph: - case OBJ_lua_gauge: #endif /* X11 */ + case OBJ_lua_gauge: free(data.s); break; #endif /* HAVE_LUA */ @@ -1833,6 +1679,12 @@ void free_text_objects(struct text_object *root, int internal) case OBJ_battery_time: free(data.s); break; + case OBJ_battery_volts: + free(data.s); + break; + case OBJ_battery_temp: + free(data.s); + break; #endif /* !__OpenBSD__ */ case OBJ_execpi: case OBJ_execi: @@ -1840,25 +1692,23 @@ void free_text_objects(struct text_object *root, int internal) case OBJ_texeci: #ifdef X11 case OBJ_execigraph: - case OBJ_execigauge: #endif /* X11 */ + case OBJ_execigauge: free_execi(obj); break; case OBJ_nameserver: free_dns_data(); break; +#ifdef __linux__ case OBJ_top: case OBJ_top_mem: case OBJ_top_time: #ifdef IOSTATS case OBJ_top_io: #endif - if (info.first_process && !internal) { - free_all_processes(); - info.first_process = NULL; - } - if (data.top.s) free(data.top.s); + free_top(obj, internal); break; +#endif /* __linux__ */ #ifdef HDDTEMP case OBJ_hddtemp: if (data.s) { @@ -1891,6 +1741,15 @@ void free_text_objects(struct text_object *root, int internal) info.users.times = 0; } break; + case OBJ_user_time: + if (info.users.ctime) { + free(info.users.ctime); + info.users.ctime = 0; + } + if (data.s) { + free(data.s); + } + break; #ifdef IBM case OBJ_smapi: case OBJ_smapi_bat_perc: @@ -1899,12 +1758,12 @@ void free_text_objects(struct text_object *root, int internal) free(data.s); break; case OBJ_if_smapi_bat_installed: - free(data.ifblock.s); - free(data.ifblock.str); + free(data.s); break; #endif /* IBM */ #ifdef NVIDIA case OBJ_nvidia: + free_nvidia(obj); break; #endif /* NVIDIA */ #ifdef MPD @@ -1969,14 +1828,19 @@ void free_text_objects(struct text_object *root, int internal) case OBJ_apcupsd_loadbar: #ifdef X11 case OBJ_apcupsd_loadgraph: - case OBJ_apcupsd_loadgauge: #endif /* X11 */ + case OBJ_apcupsd_loadgauge: case OBJ_apcupsd_charge: case OBJ_apcupsd_timeleft: case OBJ_apcupsd_temp: case OBJ_apcupsd_lastxfer: break; #endif /* APCUPSD */ +#ifdef TCP_PORT_MONITOR + case OBJ_tcp_portmon: + tcp_portmon_free(obj); + break; +#endif /* TCP_PORT_MONITOR */ #ifdef X11 case OBJ_desktop: case OBJ_desktop_number: @@ -1992,6 +1856,8 @@ void free_text_objects(struct text_object *root, int internal) break; #endif /* X11 */ } + if(obj->special_data) + free(obj->special_data); free(obj); } #undef data