1 /* -*- mode: c; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: t -*-
2 * vim: ts=4 sw=4 noet ai cindent syntax=c
4 * Conky, a system monitor, based on torsmo
6 * Any original torsmo code is licensed under the BSD license
8 * All code written since the fork of torsmo is licensed under the GPL
10 * Please see COPYING for details
12 * Copyright (c) 2004, Hannu Saransaari and Lauri Hakkarainen
13 * Copyright (c) 2005-2009 Brenden Matthews, Philip Kovacs, et. al.
15 * All rights reserved.
17 * This program is free software: you can redistribute it and/or modify
18 * it under the terms of the GNU General Public License as published by
19 * the Free Software Foundation, either version 3 of the License, or
20 * (at your option) any later version.
22 * This program is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
26 * You should have received a copy of the GNU General Public License
27 * along with this program. If not, see <http://www.gnu.org/licenses/>.
33 #include "text_object.h"
43 #include "iconv_tools.h"
50 #include "temphelper.h"
60 /* check for OS and include appropriate headers */
61 #if defined(__linux__)
63 #elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
65 #elif defined(__OpenBSD__)
69 /* OS specific prototypes to be implemented by linux.c & Co. */
70 void update_entropy(void);
75 /* strip a leading /dev/ if any, following symlinks first
77 * BEWARE: this function returns a pointer to static content
78 * which gets overwritten in consecutive calls. I.e.:
79 * this function is NOT reentrant.
81 static const char *dev_name(const char *path)
83 static char buf[255]; /* should be enough for pathnames */
90 x != NULL && strlen(x) > 5 && strncmp(x, "/dev/", 5) == 0 ? x + 5 : x
91 if ((buflen = readlink(path, buf, 254)) == -1)
92 return DEV_NAME(path);
98 static struct text_object *new_text_object_internal(void)
100 struct text_object *obj = malloc(sizeof(struct text_object));
101 memset(obj, 0, sizeof(struct text_object));
105 static struct text_object *create_plain_text(const char *s)
107 struct text_object *obj;
109 if (s == NULL || *s == '\0') {
113 obj = new_text_object_internal();
115 obj->type = OBJ_text;
116 obj->data.s = strndup(s, text_buffer_size);
120 /* construct_text_object() creates a new text_object */
121 struct text_object *construct_text_object(const char *s, const char *arg, long
122 line, void **ifblock_opaque, void *free_at_crash)
124 // struct text_object *obj = new_text_object();
125 struct text_object *obj = new_text_object_internal();
129 /* helper defines for internal use only */
130 #define __OBJ_HEAD(a, n) if (!strcmp(s, #a)) { \
131 obj->type = OBJ_##a; add_update_callback(n);
132 #define __OBJ_IF obj_be_ifblock_if(ifblock_opaque, obj)
133 #define __OBJ_ARG(...) if (!arg) { CRIT_ERR(obj, free_at_crash, __VA_ARGS__); }
135 /* defines to be used below */
136 #define OBJ(a, n) __OBJ_HEAD(a, n) {
137 #define OBJ_ARG(a, n, ...) __OBJ_HEAD(a, n) __OBJ_ARG(__VA_ARGS__) {
138 #define OBJ_IF(a, n) __OBJ_HEAD(a, n) __OBJ_IF; {
139 #define OBJ_IF_ARG(a, n, ...) __OBJ_HEAD(a, n) __OBJ_ARG(__VA_ARGS__) __OBJ_IF; {
144 obj->type = OBJ_color;
145 obj->data.l = get_x11_color(s);
152 obj->data.i = open_acpi_temperature(arg);
153 END OBJ(acpiacadapter, 0)
155 #endif /* !__OpenBSD__ */
157 if (!arg || !isdigit(arg[0]) || strlen(arg) >= 2 || atoi(&arg[0]) == 0
158 || (unsigned int) atoi(&arg[0]) > info.cpu_count) {
159 obj->data.cpu_index = 1;
160 /* NORM_ERR("freq: Invalid CPU number or you don't have that many CPUs! "
161 "Displaying the clock for CPU 1."); */
163 obj->data.cpu_index = atoi(&arg[0]);
168 if (!arg || !isdigit(arg[0]) || strlen(arg) >= 2 || atoi(&arg[0]) == 0
169 || (unsigned int) atoi(&arg[0]) > info.cpu_count) {
170 obj->data.cpu_index = 1;
171 /* NORM_ERR("freq_g: Invalid CPU number or you don't have that many "
172 "CPUs! Displaying the clock for CPU 1."); */
174 obj->data.cpu_index = atoi(&arg[0]);
177 END OBJ_ARG(read_tcp, 0, "read_tcp: Needs \"(host) port\" as argument(s)")
178 obj->data.read_tcp.host = malloc(text_buffer_size);
179 sscanf(arg, "%s", obj->data.read_tcp.host);
180 sscanf(arg+strlen(obj->data.read_tcp.host), "%u", &(obj->data.read_tcp.port));
181 if(obj->data.read_tcp.port == 0) {
182 obj->data.read_tcp.port = atoi(obj->data.read_tcp.host);
183 strcpy(obj->data.read_tcp.host,"localhost");
185 obj->data.read_tcp.port = htons(obj->data.read_tcp.port);
186 if(obj->data.read_tcp.port < 1 || obj->data.read_tcp.port > 65535) {
187 CRIT_ERR(obj, free_at_crash, "read_tcp: Needs \"(host) port\" as argument(s)");
189 #if defined(__linux__)
190 END OBJ(voltage_mv, 0)
192 if (!arg || !isdigit(arg[0]) || strlen(arg) >= 2 || atoi(&arg[0]) == 0
193 || (unsigned int) atoi(&arg[0]) > info.cpu_count) {
194 obj->data.cpu_index = 1;
195 /* NORM_ERR("voltage_mv: Invalid CPU number or you don't have that many "
196 "CPUs! Displaying voltage for CPU 1."); */
198 obj->data.cpu_index = atoi(&arg[0]);
201 END OBJ(voltage_v, 0)
203 if (!arg || !isdigit(arg[0]) || strlen(arg) >= 2 || atoi(&arg[0]) == 0
204 || (unsigned int) atoi(&arg[0]) > info.cpu_count) {
205 obj->data.cpu_index = 1;
206 /* NORM_ERR("voltage_v: Invalid CPU number or you don't have that many "
207 "CPUs! Displaying voltage for CPU 1."); */
209 obj->data.cpu_index = atoi(&arg[0]);
214 END OBJ(wireless_essid, &update_net_stats)
216 obj->data.net = get_net_stat(arg, obj, free_at_crash);
218 // default to DEFAULTNETDEV
219 char *buf = strndup(DEFAULTNETDEV, text_buffer_size);
220 obj->data.net = get_net_stat(buf, obj, free_at_crash);
223 END OBJ(wireless_mode, &update_net_stats)
225 obj->data.net = get_net_stat(arg, obj, free_at_crash);
227 // default to DEFAULTNETDEV
228 char *buf = strndup(DEFAULTNETDEV, text_buffer_size);
229 obj->data.net = get_net_stat(buf, obj, free_at_crash);
232 END OBJ(wireless_bitrate, &update_net_stats)
234 obj->data.net = get_net_stat(arg, obj, free_at_crash);
236 // default to DEFAULTNETDEV
237 char *buf = strndup(DEFAULTNETDEV, text_buffer_size);
238 obj->data.net = get_net_stat(buf, obj, free_at_crash);
241 END OBJ(wireless_ap, &update_net_stats)
243 obj->data.net = get_net_stat(arg, obj, free_at_crash);
245 // default to DEFAULTNETDEV
246 char *buf = strndup(DEFAULTNETDEV, text_buffer_size);
247 obj->data.net = get_net_stat(buf, obj, free_at_crash);
250 END OBJ(wireless_link_qual, &update_net_stats)
252 obj->data.net = get_net_stat(arg, obj, free_at_crash);
254 // default to DEFAULTNETDEV
255 char *buf = strndup(DEFAULTNETDEV, text_buffer_size);
256 obj->data.net = get_net_stat(buf, obj, free_at_crash);
259 END OBJ(wireless_link_qual_max, &update_net_stats)
261 obj->data.net = get_net_stat(arg, obj, free_at_crash);
263 // default to DEFAULTNETDEV
264 char *buf = strndup(DEFAULTNETDEV, text_buffer_size);
265 obj->data.net = get_net_stat(buf, obj, free_at_crash);
268 END OBJ(wireless_link_qual_perc, &update_net_stats)
270 obj->data.net = get_net_stat(arg, obj, free_at_crash);
272 // default to DEFAULTNETDEV
273 char *buf = strndup(DEFAULTNETDEV, text_buffer_size);
274 obj->data.net = get_net_stat(buf, obj, free_at_crash);
277 END OBJ(wireless_link_bar, &update_net_stats)
280 arg = scan_bar(arg, &obj->a, &obj->b);
281 obj->data.net = get_net_stat(arg, obj, free_at_crash);
283 // default to DEFAULTNETDEV
284 char *buf = strndup(DEFAULTNETDEV, text_buffer_size);
285 obj->data.net = get_net_stat(buf, obj, free_at_crash);
288 #endif /* HAVE_IWLIB */
290 #endif /* __linux__ */
298 sscanf(arg, "%63s", bat);
302 obj->data.s = strndup(bat, text_buffer_size);
303 END OBJ(battery_short, 0)
307 sscanf(arg, "%63s", bat);
311 obj->data.s = strndup(bat, text_buffer_size);
312 END OBJ(battery_time, 0)
316 sscanf(arg, "%63s", bat);
320 obj->data.s = strndup(bat, text_buffer_size);
321 END OBJ(battery_percent, 0)
325 sscanf(arg, "%63s", bat);
329 obj->data.s = strndup(bat, text_buffer_size);
330 END OBJ(battery_bar, 0)
335 arg = scan_bar(arg, &obj->a, &obj->b);
336 sscanf(arg, "%63s", bat);
340 obj->data.s = strndup(bat, text_buffer_size);
341 #endif /* !__OpenBSD__ */
343 #if defined(__linux__)
344 END OBJ_ARG(disk_protect, 0, "disk_protect needs an argument")
345 obj->data.s = strndup(dev_name(arg), text_buffer_size);
346 END OBJ(i8k_version, &update_i8k)
347 END OBJ(i8k_bios, &update_i8k)
348 END OBJ(i8k_serial, &update_i8k)
349 END OBJ(i8k_cpu_temp, &update_i8k)
350 END OBJ(i8k_left_fan_status, &update_i8k)
351 END OBJ(i8k_right_fan_status, &update_i8k)
352 END OBJ(i8k_left_fan_rpm, &update_i8k)
353 END OBJ(i8k_right_fan_rpm, &update_i8k)
354 END OBJ(i8k_ac_status, &update_i8k)
355 END OBJ(i8k_buttons_status, &update_i8k)
358 END OBJ(ibm_temps, 0, "ibm_temps: needs an argument")
359 if (!isdigit(arg[0]) || strlen(arg) >= 2 || atoi(&arg[0]) >= 8) {
360 obj->data.sensor = 0;
361 NORM_ERR("Invalid temperature sensor! Sensor number must be 0 to 7. "
362 "Using 0 (CPU temp sensor).");
364 obj->data.sensor = atoi(&arg[0]);
365 END OBJ(ibm_volume, 0)
366 END OBJ(ibm_brightness, 0)
368 /* information from sony_laptop kernel module
369 * /sys/devices/platform/sony-laptop */
370 END OBJ(sony_fanspeed, 0)
371 END OBJ_IF(if_gw, &update_gateway_info)
372 END OBJ_ARG(ioscheduler, 0, "get_ioscheduler needs an argument (e.g. hda)")
373 obj->data.s = strndup(dev_name(arg), text_buffer_size);
374 END OBJ(laptop_mode, 0)
375 END OBJ_ARG(pb_battery, 0, "pb_battery: needs one argument: status, percent or time")
376 if (strcmp(arg, "status") == EQUAL) {
377 obj->data.i = PB_BATT_STATUS;
378 } else if (strcmp(arg, "percent") == EQUAL) {
379 obj->data.i = PB_BATT_PERCENT;
380 } else if (strcmp(arg, "time") == EQUAL) {
381 obj->data.i = PB_BATT_TIME;
383 NORM_ERR("pb_battery: illegal argument '%s', defaulting to status", arg);
384 obj->data.i = PB_BATT_STATUS;
386 #endif /* __linux__ */
387 #if (defined(__FreeBSD__) || defined(__linux__))
388 END OBJ_IF_ARG(if_up, 0, "if_up needs an argument")
389 obj->data.ifblock.s = strndup(arg, text_buffer_size);
391 #if defined(__OpenBSD__)
392 END OBJ_ARG(obsd_sensors_temp, 0, "obsd_sensors_temp: needs an argument")
393 if (!isdigit(arg[0]) || atoi(&arg[0]) < 0
394 || atoi(&arg[0]) > OBSD_MAX_SENSORS - 1) {
395 obj->data.sensor = 0;
396 NORM_ERR("Invalid temperature sensor number!");
398 obj->data.sensor = atoi(&arg[0]);
399 END OBJ_ARG(obsd_sensors_fan, 0, "obsd_sensors_fan: needs 2 arguments (device and sensor number)")
400 if (!isdigit(arg[0]) || atoi(&arg[0]) < 0
401 || atoi(&arg[0]) > OBSD_MAX_SENSORS - 1) {
402 obj->data.sensor = 0;
403 NORM_ERR("Invalid fan sensor number!");
405 obj->data.sensor = atoi(&arg[0]);
406 END OBJ_ARG(obsd_sensors_volt, 0, "obsd_sensors_volt: needs 2 arguments (device and sensor number)")
407 if (!isdigit(arg[0]) || atoi(&arg[0]) < 0
408 || atoi(&arg[0]) > OBSD_MAX_SENSORS - 1) {
409 obj->data.sensor = 0;
410 NORM_ERR("Invalid voltage sensor number!");
412 obj->data.sensor = atoi(&arg[0]);
413 END OBJ(obsd_vendor, 0)
414 END OBJ(obsd_product, 0)
415 #endif /* __OpenBSD__ */
416 END OBJ(buffers, &update_meminfo)
417 END OBJ(cached, &update_meminfo)
418 #define SCAN_CPU(__arg, __var) { \
420 if (__arg && sscanf(__arg, " cpu%u %n", &__var, &__offset) > 0) \
425 END OBJ(cpu, &update_cpu_usage)
426 SCAN_CPU(arg, obj->data.cpu_index);
427 DBGP2("Adding $cpu for CPU %d", obj->data.cpu_index);
429 END OBJ(cpugauge, &update_cpu_usage)
430 SIZE_DEFAULTS(gauge);
431 SCAN_CPU(arg, obj->data.cpu_index);
432 scan_gauge(arg, &obj->a, &obj->b);
433 DBGP2("Adding $cpugauge for CPU %d", obj->data.cpu_index);
435 END OBJ(cpubar, &update_cpu_usage)
437 SCAN_CPU(arg, obj->data.cpu_index);
438 scan_bar(arg, &obj->a, &obj->b);
439 DBGP2("Adding $cpubar for CPU %d", obj->data.cpu_index);
441 END OBJ(cpugraph, &update_cpu_usage)
443 SIZE_DEFAULTS(graph);
444 SCAN_CPU(arg, obj->data.cpu_index);
445 buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
446 &obj->e, &obj->char_a, &obj->char_b);
447 DBGP2("Adding $cpugraph for CPU %d", obj->data.cpu_index);
449 END OBJ(loadgraph, &update_load_average)
451 SIZE_DEFAULTS(graph);
452 buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
453 &obj->e, &obj->char_a, &obj->char_b);
457 r = sscanf(arg, "%d", &a);
459 obj->data.loadavg[0] = (r >= 1) ? (unsigned char) a : 0;
463 END OBJ(diskio, &update_diskio)
464 obj->data.diskio = prepare_diskio_stat(dev_name(arg));
465 END OBJ(diskio_read, &update_diskio)
466 obj->data.diskio = prepare_diskio_stat(dev_name(arg));
467 END OBJ(diskio_write, &update_diskio)
468 obj->data.diskio = prepare_diskio_stat(dev_name(arg));
470 END OBJ(diskiograph, &update_diskio)
472 SIZE_DEFAULTS(graph);
473 buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
474 &obj->e, &obj->char_a, &obj->char_b);
476 obj->data.diskio = prepare_diskio_stat(dev_name(buf));
478 END OBJ(diskiograph_read, &update_diskio)
480 SIZE_DEFAULTS(graph);
481 buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
482 &obj->e, &obj->char_a, &obj->char_b);
484 obj->data.diskio = prepare_diskio_stat(dev_name(buf));
486 END OBJ(diskiograph_write, &update_diskio)
488 SIZE_DEFAULTS(graph);
489 buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
490 &obj->e, &obj->char_a, &obj->char_b);
492 obj->data.diskio = prepare_diskio_stat(dev_name(buf));
497 if (output_methods & TO_X) {
498 obj->data.l = arg ? get_x11_color(arg) : default_fg_color;
499 set_current_text_color(obj->data.l);
503 if (output_methods & TO_NCURSES) {
504 obj->data.l = COLOR_WHITE;
506 if(strcasecmp(arg, "red") == 0) {
507 obj->data.l = COLOR_RED;
508 }else if(strcasecmp(arg, "green") == 0) {
509 obj->data.l = COLOR_GREEN;
510 }else if(strcasecmp(arg, "yellow") == 0) {
511 obj->data.l = COLOR_YELLOW;
512 }else if(strcasecmp(arg, "blue") == 0) {
513 obj->data.l = COLOR_BLUE;
514 }else if(strcasecmp(arg, "magenta") == 0) {
515 obj->data.l = COLOR_MAGENTA;
516 }else if(strcasecmp(arg, "cyan") == 0) {
517 obj->data.l = COLOR_CYAN;
518 }else if(strcasecmp(arg, "black") == 0) {
519 obj->data.l = COLOR_BLACK;
522 set_current_text_color(obj->data.l);
523 init_pair(obj->data.l, obj->data.l, COLOR_BLACK);
527 obj->data.l = color0;
528 set_current_text_color(obj->data.l);
530 obj->data.l = color1;
531 set_current_text_color(obj->data.l);
533 obj->data.l = color2;
534 set_current_text_color(obj->data.l);
536 obj->data.l = color3;
537 set_current_text_color(obj->data.l);
539 obj->data.l = color4;
540 set_current_text_color(obj->data.l);
542 obj->data.l = color5;
543 set_current_text_color(obj->data.l);
545 obj->data.l = color6;
546 set_current_text_color(obj->data.l);
548 obj->data.l = color7;
549 set_current_text_color(obj->data.l);
551 obj->data.l = color8;
552 set_current_text_color(obj->data.l);
554 obj->data.l = color9;
555 set_current_text_color(obj->data.l);
558 obj->data.s = scan_font(arg);
560 END OBJ(conky_version, 0)
561 END OBJ(conky_build_date, 0)
562 END OBJ(conky_build_arch, 0)
563 END OBJ(downspeed, &update_net_stats)
565 obj->data.net = get_net_stat(arg, obj, free_at_crash);
567 // default to DEFAULTNETDEV
568 char *buf = strndup(DEFAULTNETDEV, text_buffer_size);
569 obj->data.net = get_net_stat(buf, obj, free_at_crash);
572 END OBJ(downspeedf, &update_net_stats)
574 obj->data.net = get_net_stat(arg, obj, free_at_crash);
576 // default to DEFAULTNETDEV
577 char *buf = strndup(DEFAULTNETDEV, text_buffer_size);
578 obj->data.net = get_net_stat(buf, obj, free_at_crash);
582 END OBJ(downspeedgraph, &update_net_stats)
584 SIZE_DEFAULTS(graph);
585 buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
586 &obj->e, &obj->char_a, &obj->char_b);
588 // default to DEFAULTNETDEV
589 buf = strndup(buf ? buf : DEFAULTNETDEV, text_buffer_size);
590 obj->data.net = get_net_stat(buf, obj, free_at_crash);
594 obj_be_ifblock_else(ifblock_opaque, obj);
596 obj_be_ifblock_endif(ifblock_opaque, obj);
598 obj->data.s = strndup(arg ? arg : "", text_buffer_size);
599 #if defined(IMLIB2) && defined(X11)
601 obj->data.s = strndup(arg ? arg : "", text_buffer_size);
604 obj->data.s = strndup(arg ? arg : "", text_buffer_size);
606 obj->data.s = strndup(arg ? arg : "", text_buffer_size);
609 obj->data.s = strndup(arg ? arg : "", text_buffer_size);
611 END OBJ(execgauge, 0)
612 SIZE_DEFAULTS(gauge);
613 obj->data.s = strndup(arg ? arg : "", text_buffer_size);
614 END OBJ(execgraph, 0)
615 SIZE_DEFAULTS(graph);
616 obj->data.s = strndup(arg ? arg : "", text_buffer_size);
622 if (!arg || sscanf(arg, "%f %n", &obj->data.execi.interval, &n) <= 0) {
625 NORM_ERR("${execibar <interval> command}");
626 obj->type = OBJ_text;
627 snprintf(buf, 256, "${%s}", s);
628 obj->data.s = strndup(buf, text_buffer_size);
630 obj->data.execi.cmd = strndup(arg + n, text_buffer_size);
633 END OBJ(execigraph, 0)
635 SIZE_DEFAULTS(graph);
637 if (!arg || sscanf(arg, "%f %n", &obj->data.execi.interval, &n) <= 0) {
640 NORM_ERR("${execigraph <interval> command}");
641 obj->type = OBJ_text;
642 snprintf(buf, 256, "${%s}", s);
643 obj->data.s = strndup(buf, text_buffer_size);
645 obj->data.execi.cmd = strndup(arg + n, text_buffer_size);
647 END OBJ(execigauge, 0)
649 SIZE_DEFAULTS(gauge);
651 if (!arg || sscanf(arg, "%f %n", &obj->data.execi.interval, &n) <= 0) {
654 NORM_ERR("${execigauge <interval> command}");
655 obj->type = OBJ_text;
656 snprintf(buf, 256, "${%s}", s);
657 obj->data.s = strndup(buf, text_buffer_size);
659 obj->data.execi.cmd = strndup(arg + n, text_buffer_size);
665 if (!arg || sscanf(arg, "%f %n", &obj->data.execi.interval, &n) <= 0) {
668 NORM_ERR("${execi <interval> command}");
669 obj->type = OBJ_text;
670 snprintf(buf, 256, "${%s}", s);
671 obj->data.s = strndup(buf, text_buffer_size);
673 obj->data.execi.cmd = strndup(arg + n, text_buffer_size);
674 obj->data.execi.buffer = malloc(text_buffer_size);
679 if (!arg || sscanf(arg, "%f %n", &obj->data.execi.interval, &n) <= 0) {
682 NORM_ERR("${execi <interval> command}");
683 obj->type = OBJ_text;
684 snprintf(buf, 256, "${%s}", s);
685 obj->data.s = strndup(buf, text_buffer_size);
687 obj->data.execi.cmd = strndup(arg + n, text_buffer_size);
688 obj->data.execi.buffer = malloc(text_buffer_size);
693 if (!arg || sscanf(arg, "%f %n", &obj->data.texeci.interval, &n) <= 0) {
696 NORM_ERR("${texeci <interval> command}");
697 obj->type = OBJ_text;
698 snprintf(buf, 256, "${%s}", s);
699 obj->data.s = strndup(buf, text_buffer_size);
701 obj->data.texeci.cmd = strndup(arg + n, text_buffer_size);
702 obj->data.texeci.buffer = malloc(text_buffer_size);
704 obj->data.texeci.p_timed_thread = NULL;
706 obj->type = OBJ_text;
710 do_read_exec(arg, buf, sizeof(buf));
711 obj->data.s = strndup(buf, text_buffer_size);
713 obj->data.s = strndup("", text_buffer_size);
715 END OBJ(fs_bar, &update_fs_stats)
716 init_fs_bar(obj, arg);
717 END OBJ(fs_bar_free, &update_fs_stats)
718 init_fs_bar(obj, arg);
719 END OBJ(fs_free, &update_fs_stats)
723 obj->data.fs = prepare_fs_stat(arg);
724 END OBJ(fs_used_perc, &update_fs_stats)
728 obj->data.fs = prepare_fs_stat(arg);
729 END OBJ(fs_free_perc, &update_fs_stats)
733 obj->data.fs = prepare_fs_stat(arg);
734 END OBJ(fs_size, &update_fs_stats)
738 obj->data.fs = prepare_fs_stat(arg);
739 END OBJ(fs_type, &update_fs_stats)
743 obj->data.fs = prepare_fs_stat(arg);
744 END OBJ(fs_used, &update_fs_stats)
748 obj->data.fs = prepare_fs_stat(arg);
750 obj->data.i = arg ? atoi(arg) : 1;
751 END OBJ(nameserver, &update_dns_data)
752 obj->data.i = arg ? atoi(arg) : 0;
754 obj->data.i = arg ? atoi(arg) : 1;
756 obj->data.i = arg ? atoi(arg) : 1;
757 END OBJ_ARG(goto, 0, "goto needs arguments")
758 obj->data.i = atoi(arg);
763 if (sscanf(arg, "%d %d", &a, &b) != 2) {
764 sscanf(arg, "%d", &b);
770 obj->data.pair.a = a;
771 obj->data.pair.b = b;
774 END OBJ_ARG(i2c, 0, "i2c needs arguments")
775 parse_i2c_sensor(obj, arg);
776 END OBJ_ARG(platform, 0, "platform needs arguments")
777 parse_platform_sensor(obj, arg);
778 END OBJ_ARG(hwmon, 0, "hwmon needs argumanets")
779 parse_hwmon_sensor(obj, arg);
780 #endif /* __linux__ */
783 /* we have four different types of top (top, top_mem, top_time and top_io). To
784 * avoid having almost-same code four times, we have this special
786 if (strncmp(s, "top", 3) == EQUAL) {
787 add_update_callback(&update_meminfo);
788 add_update_callback(&update_top);
789 if (!parse_top_args(s, arg, obj)) {
792 } else OBJ(addr, &update_net_stats)
794 obj->data.net = get_net_stat(arg, obj, free_at_crash);
796 // default to DEFAULTNETDEV
797 char *buf = strndup(DEFAULTNETDEV, text_buffer_size);
798 obj->data.net = get_net_stat(buf, obj, free_at_crash);
801 #if defined(__linux__)
802 END OBJ(addrs, &update_net_stats)
804 obj->data.net = get_net_stat(arg, obj, free_at_crash);
806 // default to DEFAULTNETDEV
807 char *buf = strndup(DEFAULTNETDEV, text_buffer_size);
808 obj->data.net = get_net_stat(buf, obj, free_at_crash);
811 #endif /* __linux__ */
812 END OBJ_ARG(tail, 0, "tail needs arguments")
813 init_tailhead("tail", arg, obj, free_at_crash);
814 END OBJ_ARG(head, 0, "head needs arguments")
815 init_tailhead("head", arg, obj, free_at_crash);
816 END OBJ_ARG(lines, 0, "lines needs an argument")
817 obj->data.s = strndup(arg, text_buffer_size);
818 END OBJ_ARG(words, 0, "words needs a argument")
819 obj->data.s = strndup(arg, text_buffer_size);
820 END OBJ(loadavg, &update_load_average)
821 int a = 1, b = 2, c = 3, r = 3;
824 r = sscanf(arg, "%d %d %d", &a, &b, &c);
825 if (r >= 3 && (c < 1 || c > 3)) {
828 if (r >= 2 && (b < 1 || b > 3)) {
831 if (r >= 1 && (a < 1 || a > 3)) {
835 obj->data.loadavg[0] = (r >= 1) ? (unsigned char) a : 0;
836 obj->data.loadavg[1] = (r >= 2) ? (unsigned char) b : 0;
837 obj->data.loadavg[2] = (r >= 3) ? (unsigned char) c : 0;
838 END OBJ_IF_ARG(if_empty, 0, "if_empty needs an argument")
839 obj->data.ifblock.s = strndup(arg, text_buffer_size);
840 obj->sub = malloc(sizeof(struct text_object));
841 extract_variable_text_internal(obj->sub, obj->data.ifblock.s);
842 END OBJ_IF_ARG(if_match, 0, "if_match needs arguments")
843 obj->data.ifblock.s = strndup(arg, text_buffer_size);
844 obj->sub = malloc(sizeof(struct text_object));
845 extract_variable_text_internal(obj->sub, obj->data.ifblock.s);
846 END OBJ_IF_ARG(if_existing, 0, "if_existing needs an argument or two")
847 char buf1[256], buf2[256];
848 int r = sscanf(arg, "%255s %255[^\n]", buf1, buf2);
851 obj->data.ifblock.s = strndup(buf1, text_buffer_size);
852 obj->data.ifblock.str = NULL;
854 obj->data.ifblock.s = strndup(buf1, text_buffer_size);
855 obj->data.ifblock.str = strndup(buf2, text_buffer_size);
857 DBGP("if_existing: '%s' '%s'", obj->data.ifblock.s, obj->data.ifblock.str);
858 END OBJ_IF_ARG(if_mounted, 0, "if_mounted needs an argument")
859 obj->data.ifblock.s = strndup(arg, text_buffer_size);
861 END OBJ_IF_ARG(if_running, &update_top, "if_running needs an argument")
863 obj->data.ifblock.s = strndup(arg, text_buffer_size);
865 END OBJ_IF_ARG(if_running, 0, "if_running needs an argument")
868 snprintf(buf, 256, "pidof %s >/dev/null", arg);
869 obj->data.ifblock.s = strndup(buf, text_buffer_size);
875 char mbox[256], dst[256];
879 /* Kapil: Changed from MAIL_FILE to
880 current_mail_spool since the latter
881 is a copy of the former if undefined
882 but the latter should take precedence
884 strncpy(mbox, current_mail_spool, sizeof(mbox));
886 if (sscanf(arg, "%s %f", mbox, &n1) != 2) {
888 strncpy(mbox, arg, sizeof(mbox));
892 variable_substitute(mbox, dst, sizeof(dst));
893 obj->data.local_mail.mbox = strndup(dst, text_buffer_size);
894 obj->data.local_mail.interval = n1;
895 END OBJ(new_mails, 0)
897 char mbox[256], dst[256];
901 strncpy(mbox, current_mail_spool, sizeof(mbox));
903 if (sscanf(arg, "%s %f", mbox, &n1) != 2) {
905 strncpy(mbox, arg, sizeof(mbox));
909 variable_substitute(mbox, dst, sizeof(dst));
910 obj->data.local_mail.mbox = strndup(dst, text_buffer_size);
911 obj->data.local_mail.interval = n1;
912 END OBJ(seen_mails, 0)
914 char mbox[256], dst[256];
918 strncpy(mbox, current_mail_spool, sizeof(mbox));
920 if (sscanf(arg, "%s %f", mbox, &n1) != 2) {
922 strncpy(mbox, arg, sizeof(mbox));
926 variable_substitute(mbox, dst, sizeof(dst));
927 obj->data.local_mail.mbox = strndup(dst, text_buffer_size);
928 obj->data.local_mail.interval = n1;
929 END OBJ(unseen_mails, 0)
931 char mbox[256], dst[256];
935 strncpy(mbox, current_mail_spool, sizeof(mbox));
937 if (sscanf(arg, "%s %f", mbox, &n1) != 2) {
939 strncpy(mbox, arg, sizeof(mbox));
943 variable_substitute(mbox, dst, sizeof(dst));
944 obj->data.local_mail.mbox = strndup(dst, text_buffer_size);
945 obj->data.local_mail.interval = n1;
946 END OBJ(flagged_mails, 0)
948 char mbox[256], dst[256];
952 strncpy(mbox, current_mail_spool, sizeof(mbox));
954 if (sscanf(arg, "%s %f", mbox, &n1) != 2) {
956 strncpy(mbox, arg, sizeof(mbox));
960 variable_substitute(mbox, dst, sizeof(dst));
961 obj->data.local_mail.mbox = strndup(dst, text_buffer_size);
962 obj->data.local_mail.interval = n1;
963 END OBJ(unflagged_mails, 0)
965 char mbox[256], dst[256];
969 strncpy(mbox, current_mail_spool, sizeof(mbox));
971 if (sscanf(arg, "%s %f", mbox, &n1) != 2) {
973 strncpy(mbox, arg, sizeof(mbox));
977 variable_substitute(mbox, dst, sizeof(dst));
978 obj->data.local_mail.mbox = strndup(dst, text_buffer_size);
979 obj->data.local_mail.interval = n1;
980 END OBJ(forwarded_mails, 0)
982 char mbox[256], dst[256];
986 strncpy(mbox, current_mail_spool, sizeof(mbox));
988 if (sscanf(arg, "%s %f", mbox, &n1) != 2) {
990 strncpy(mbox, arg, sizeof(mbox));
994 variable_substitute(mbox, dst, sizeof(dst));
995 obj->data.local_mail.mbox = strndup(dst, text_buffer_size);
996 obj->data.local_mail.interval = n1;
997 END OBJ(unforwarded_mails, 0)
999 char mbox[256], dst[256];
1003 strncpy(mbox, current_mail_spool, sizeof(mbox));
1005 if (sscanf(arg, "%s %f", mbox, &n1) != 2) {
1007 strncpy(mbox, arg, sizeof(mbox));
1011 variable_substitute(mbox, dst, sizeof(dst));
1012 obj->data.local_mail.mbox = strndup(dst, text_buffer_size);
1013 obj->data.local_mail.interval = n1;
1014 END OBJ(replied_mails, 0)
1016 char mbox[256], dst[256];
1020 strncpy(mbox, current_mail_spool, sizeof(mbox));
1022 if (sscanf(arg, "%s %f", mbox, &n1) != 2) {
1024 strncpy(mbox, arg, sizeof(mbox));
1028 variable_substitute(mbox, dst, sizeof(dst));
1029 obj->data.local_mail.mbox = strndup(dst, text_buffer_size);
1030 obj->data.local_mail.interval = n1;
1031 END OBJ(unreplied_mails, 0)
1033 char mbox[256], dst[256];
1037 strncpy(mbox, current_mail_spool, sizeof(mbox));
1039 if (sscanf(arg, "%s %f", mbox, &n1) != 2) {
1041 strncpy(mbox, arg, sizeof(mbox));
1045 variable_substitute(mbox, dst, sizeof(dst));
1046 obj->data.local_mail.mbox = strndup(dst, text_buffer_size);
1047 obj->data.local_mail.interval = n1;
1048 END OBJ(draft_mails, 0)
1050 char mbox[256], dst[256];
1054 strncpy(mbox, current_mail_spool, sizeof(mbox));
1056 if (sscanf(arg, "%s %f", mbox, &n1) != 2) {
1058 strncpy(mbox, arg, sizeof(mbox));
1062 variable_substitute(mbox, dst, sizeof(dst));
1063 obj->data.local_mail.mbox = strndup(dst, text_buffer_size);
1064 obj->data.local_mail.interval = n1;
1065 END OBJ(trashed_mails, 0)
1067 char mbox[256], dst[256];
1071 strncpy(mbox, current_mail_spool, sizeof(mbox));
1073 if (sscanf(arg, "%s %f", mbox, &n1) != 2) {
1075 strncpy(mbox, arg, sizeof(mbox));
1079 variable_substitute(mbox, dst, sizeof(dst));
1080 obj->data.local_mail.mbox = strndup(dst, text_buffer_size);
1081 obj->data.local_mail.interval = n1;
1082 END OBJ(mboxscan, 0)
1083 obj->data.mboxscan.args = (char *) malloc(text_buffer_size);
1084 obj->data.mboxscan.output = (char *) malloc(text_buffer_size);
1085 /* if '1' (in mboxscan.c) then there was SIGUSR1, hmm */
1086 obj->data.mboxscan.output[0] = 1;
1087 strncpy(obj->data.mboxscan.args, arg, text_buffer_size);
1088 END OBJ(mem, &update_meminfo)
1089 END OBJ(memeasyfree, &update_meminfo)
1090 END OBJ(memfree, &update_meminfo)
1091 END OBJ(memmax, &update_meminfo)
1092 END OBJ(memperc, &update_meminfo)
1094 END OBJ(memgauge, &update_meminfo)
1095 SIZE_DEFAULTS(gauge);
1096 scan_gauge(arg, &obj->data.pair.a, &obj->data.pair.b);
1098 END OBJ(membar, &update_meminfo)
1100 scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
1102 END OBJ(memgraph, &update_meminfo)
1104 SIZE_DEFAULTS(graph);
1105 buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
1106 &obj->e, &obj->char_a, &obj->char_b);
1111 obj->data.l = mixer_init(arg);
1113 obj->data.l = mixer_init(arg);
1115 obj->data.l = mixer_init(arg);
1117 END OBJ(mixerbar, 0)
1119 scan_mixer_bar(arg, &obj->data.mixerbar.l, &obj->data.mixerbar.w,
1120 &obj->data.mixerbar.h);
1121 END OBJ(mixerlbar, 0)
1123 scan_mixer_bar(arg, &obj->data.mixerbar.l, &obj->data.mixerbar.w,
1124 &obj->data.mixerbar.h);
1125 END OBJ(mixerrbar, 0)
1127 scan_mixer_bar(arg, &obj->data.mixerbar.l, &obj->data.mixerbar.w,
1128 &obj->data.mixerbar.h);
1130 END OBJ_IF(if_mixer_mute, 0)
1131 obj->data.ifblock.i = mixer_init(arg);
1133 END OBJ(monitor, &update_x11info)
1134 END OBJ(monitor_number, &update_x11info)
1135 END OBJ(desktop, &update_x11info)
1136 END OBJ(desktop_number, &update_x11info)
1137 END OBJ(desktop_name, &update_x11info)
1139 END OBJ(nodename, 0)
1140 END OBJ(processes, &update_total_processes)
1141 END OBJ(running_processes, &update_running_processes)
1142 END OBJ(shadecolor, 0)
1144 obj->data.l = arg ? get_x11_color(arg) : default_bg_color;
1146 END OBJ(outlinecolor, 0)
1148 obj->data.l = arg ? get_x11_color(arg) : default_out_color;
1150 END OBJ(stippled_hr, 0)
1152 int a = get_stippled_borders(), b = 1;
1155 if (sscanf(arg, "%d %d", &a, &b) != 2) {
1156 sscanf(arg, "%d", &b);
1162 obj->data.pair.a = a;
1163 obj->data.pair.b = b;
1165 END OBJ(swap, &update_meminfo)
1166 END OBJ(swapfree, &update_meminfo)
1167 END OBJ(swapmax, &update_meminfo)
1168 END OBJ(swapperc, &update_meminfo)
1169 END OBJ(swapbar, &update_meminfo)
1171 scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
1174 scan_time(obj, arg);
1176 scan_time(obj, arg);
1178 scan_tztime(obj, arg);
1180 END OBJ_ARG(iconv_start, 0, "Iconv requires arguments")
1181 init_iconv_start(obj, free_at_crash, arg);
1182 END OBJ(iconv_stop, 0)
1185 END OBJ(totaldown, &update_net_stats)
1187 obj->data.net = get_net_stat(arg, obj, free_at_crash);
1189 // default to DEFAULTNETDEV
1190 char *buf = strndup(DEFAULTNETDEV, text_buffer_size);
1191 obj->data.net = get_net_stat(buf, obj, free_at_crash);
1194 END OBJ(totalup, &update_net_stats)
1195 obj->data.net = get_net_stat(arg, obj, free_at_crash);
1197 obj->data.net = get_net_stat(arg, obj, free_at_crash);
1199 // default to DEFAULTNETDEV
1200 char *buf = strndup(DEFAULTNETDEV, text_buffer_size);
1201 obj->data.net = get_net_stat(buf, obj, free_at_crash);
1205 END OBJ_IF(if_updatenr, 0)
1206 obj->data.ifblock.i = arg ? atoi(arg) : 0;
1207 if(obj->data.ifblock.i == 0) CRIT_ERR(obj, free_at_crash, "if_updatenr needs a number above 0 as argument");
1208 set_updatereset(obj->data.ifblock.i > get_updatereset() ? obj->data.ifblock.i : get_updatereset());
1210 obj->data.i = arg ? atoi(arg) : 0;
1212 obj->data.i = arg ? atoi(arg) : 0;
1213 END OBJ(upspeed, &update_net_stats)
1215 obj->data.net = get_net_stat(arg, obj, free_at_crash);
1217 // default to DEFAULTNETDEV
1218 char *buf = strndup(DEFAULTNETDEV, text_buffer_size);
1219 obj->data.net = get_net_stat(buf, obj, free_at_crash);
1222 END OBJ(upspeedf, &update_net_stats)
1224 obj->data.net = get_net_stat(arg, obj, free_at_crash);
1226 // default to DEFAULTNETDEV
1227 char *buf = strndup(DEFAULTNETDEV, text_buffer_size);
1228 obj->data.net = get_net_stat(buf, obj, free_at_crash);
1233 END OBJ(upspeedgraph, &update_net_stats)
1235 SIZE_DEFAULTS(graph);
1236 buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
1237 &obj->e, &obj->char_a, &obj->char_b);
1239 // default to DEFAULTNETDEV
1240 buf = strndup(buf ? buf : DEFAULTNETDEV, text_buffer_size);
1241 obj->data.net = get_net_stat(buf, obj, free_at_crash);
1244 END OBJ(uptime_short, &update_uptime)
1245 END OBJ(uptime, &update_uptime)
1246 END OBJ(user_names, &update_users)
1247 END OBJ(user_times, &update_users)
1248 END OBJ(user_terms, &update_users)
1249 END OBJ(user_number, &update_users)
1250 #if defined(__linux__)
1251 END OBJ(gw_iface, &update_gateway_info)
1252 END OBJ(gw_ip, &update_gateway_info)
1253 #endif /* !__linux__ */
1255 END OBJ(adt746xcpu, 0)
1256 END OBJ(adt746xfan, 0)
1257 #endif /* !__OpenBSD__ */
1258 #if (defined(__FreeBSD__) || defined(__FreeBSD_kernel__) \
1259 || defined(__OpenBSD__)) && (defined(i386) || defined(__i386__))
1260 END OBJ(apm_adapter, 0)
1261 END OBJ(apm_battery_life, 0)
1262 END OBJ(apm_battery_time, 0)
1263 #endif /* __FreeBSD__ */
1264 END OBJ(imap_unseen, 0)
1267 obj->data.mail = parse_mail_args(IMAP_TYPE, arg);
1272 END OBJ(imap_messages, 0)
1275 obj->data.mail = parse_mail_args(IMAP_TYPE, arg);
1280 END OBJ(pop3_unseen, 0)
1283 obj->data.mail = parse_mail_args(POP3_TYPE, arg);
1288 END OBJ(pop3_used, 0)
1291 obj->data.mail = parse_mail_args(POP3_TYPE, arg);
1297 END OBJ_ARG(smapi, 0, "smapi needs an argument")
1298 obj->data.s = strndup(arg, text_buffer_size);
1299 END OBJ_IF_ARG(if_smapi_bat_installed, 0, "if_smapi_bat_installed needs an argument")
1300 obj->data.ifblock.s = strndup(arg, text_buffer_size);
1301 END OBJ_ARG(smapi_bat_perc, 0, "smapi_bat_perc needs an argument")
1302 obj->data.s = strndup(arg, text_buffer_size);
1303 END OBJ_ARG(smapi_bat_temp, 0, "smapi_bat_temp needs an argument")
1304 obj->data.s = strndup(arg, text_buffer_size);
1305 END OBJ_ARG(smapi_bat_power, 0, "smapi_bat_power needs an argument")
1306 obj->data.s = strndup(arg, text_buffer_size);
1308 END OBJ_ARG(smapi_bat_bar, 0, "smapi_bat_bar needs an argument")
1311 if(sscanf(arg, "%i %n", &obj->data.i, &cnt) <= 0) {
1312 NORM_ERR("first argument to smapi_bat_bar must be an integer value");
1316 arg = scan_bar(arg + cnt, &obj->a, &obj->b);
1321 #define mpd_set_maxlen(name) \
1324 sscanf(arg, "%d", &i); \
1326 obj->data.i = i + 1; \
1328 NORM_ERR(#name ": invalid length argument"); \
1330 END OBJ(mpd_artist, &update_mpd)
1331 mpd_set_maxlen(mpd_artist);
1333 END OBJ(mpd_title, &update_mpd)
1334 mpd_set_maxlen(mpd_title);
1336 END OBJ(mpd_random, &update_mpd) init_mpd();
1337 END OBJ(mpd_repeat, &update_mpd) init_mpd();
1338 END OBJ(mpd_elapsed, &update_mpd) init_mpd();
1339 END OBJ(mpd_length, &update_mpd) init_mpd();
1340 END OBJ(mpd_track, &update_mpd)
1341 mpd_set_maxlen(mpd_track);
1343 END OBJ(mpd_name, &update_mpd)
1344 mpd_set_maxlen(mpd_name);
1346 END OBJ(mpd_file, &update_mpd)
1347 mpd_set_maxlen(mpd_file);
1349 END OBJ(mpd_percent, &update_mpd) init_mpd();
1350 END OBJ(mpd_album, &update_mpd)
1351 mpd_set_maxlen(mpd_album);
1353 END OBJ(mpd_vol, &update_mpd) init_mpd();
1354 END OBJ(mpd_bitrate, &update_mpd) init_mpd();
1355 END OBJ(mpd_status, &update_mpd) init_mpd();
1356 END OBJ(mpd_bar, &update_mpd)
1358 scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
1360 END OBJ(mpd_smart, &update_mpd)
1361 mpd_set_maxlen(mpd_smart);
1363 END OBJ_IF(if_mpd_playing, &update_mpd)
1365 #undef mpd_set_maxlen
1368 END OBJ(moc_state, &update_moc)
1369 END OBJ(moc_file, &update_moc)
1370 END OBJ(moc_title, &update_moc)
1371 END OBJ(moc_artist, &update_moc)
1372 END OBJ(moc_song, &update_moc)
1373 END OBJ(moc_album, &update_moc)
1374 END OBJ(moc_totaltime, &update_moc)
1375 END OBJ(moc_timeleft, &update_moc)
1376 END OBJ(moc_curtime, &update_moc)
1377 END OBJ(moc_bitrate, &update_moc)
1378 END OBJ(moc_rate, &update_moc)
1381 END OBJ(xmms2_artist, &update_xmms2)
1382 END OBJ(xmms2_album, &update_xmms2)
1383 END OBJ(xmms2_title, &update_xmms2)
1384 END OBJ(xmms2_genre, &update_xmms2)
1385 END OBJ(xmms2_comment, &update_xmms2)
1386 END OBJ(xmms2_url, &update_xmms2)
1387 END OBJ(xmms2_tracknr, &update_xmms2)
1388 END OBJ(xmms2_bitrate, &update_xmms2)
1389 END OBJ(xmms2_date, &update_xmms2)
1390 END OBJ(xmms2_id, &update_xmms2)
1391 END OBJ(xmms2_duration, &update_xmms2)
1392 END OBJ(xmms2_elapsed, &update_xmms2)
1393 END OBJ(xmms2_size, &update_xmms2)
1394 END OBJ(xmms2_status, &update_xmms2)
1395 END OBJ(xmms2_percent, &update_xmms2)
1397 END OBJ(xmms2_bar, &update_xmms2)
1399 scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
1401 END OBJ(xmms2_smart, &update_xmms2)
1402 END OBJ(xmms2_playlist, &update_xmms2)
1403 END OBJ(xmms2_timesplayed, &update_xmms2)
1404 END OBJ_IF(if_xmms2_connected, &update_xmms2)
1407 END OBJ(audacious_status, &update_audacious)
1408 END OBJ_ARG(audacious_title, &update_audacious, "audacious_title needs an argument")
1409 sscanf(arg, "%d", &info.audacious.max_title_len);
1410 if (info.audacious.max_title_len > 0) {
1411 info.audacious.max_title_len++;
1413 CRIT_ERR(obj, free_at_crash, "audacious_title: invalid length argument");
1415 END OBJ(audacious_length, &update_audacious)
1416 END OBJ(audacious_length_seconds, &update_audacious)
1417 END OBJ(audacious_position, &update_audacious)
1418 END OBJ(audacious_position_seconds, &update_audacious)
1419 END OBJ(audacious_bitrate, &update_audacious)
1420 END OBJ(audacious_frequency, &update_audacious)
1421 END OBJ(audacious_channels, &update_audacious)
1422 END OBJ(audacious_filename, &update_audacious)
1423 END OBJ(audacious_playlist_length, &update_audacious)
1424 END OBJ(audacious_playlist_position, &update_audacious)
1425 END OBJ(audacious_main_volume, &update_audacious)
1427 END OBJ(audacious_bar, &update_audacious)
1429 scan_bar(arg, &obj->a, &obj->b);
1433 END OBJ(bmpx_title, &update_bmpx)
1434 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
1435 END OBJ(bmpx_artist, &update_bmpx)
1436 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
1437 END OBJ(bmpx_album, &update_bmpx)
1438 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
1439 END OBJ(bmpx_track, &update_bmpx)
1440 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
1441 END OBJ(bmpx_uri, &update_bmpx)
1442 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
1443 END OBJ(bmpx_bitrate, &update_bmpx)
1444 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
1447 END OBJ_ARG(eve, 0, "eve needs arguments: <userid> <apikey> <characterid>")
1451 END OBJ_ARG(curl, 0, "curl needs arguments: <uri> <interval in minutes>")
1454 char *uri = (char *) malloc(128 * sizeof(char));
1456 argc = sscanf(arg, "%127s %f", uri, &interval);
1458 obj->data.curl.uri = uri;
1459 obj->data.curl.interval = interval > 0 ? interval * 60 : 15*60;
1461 NORM_ERR("wrong number of arguments for $curl");
1465 END OBJ_ARG(rss, 0, "rss needs arguments: <uri> <interval in minutes> <action> [act_par] [spaces in front]")
1467 int argc, act_par = 0;
1468 unsigned int nrspaces = 0;
1469 char *uri = (char *) malloc(128 * sizeof(char));
1470 char *action = (char *) malloc(64 * sizeof(char));
1472 argc = sscanf(arg, "%127s %f %63s %d %u", uri, &interval, action,
1473 &act_par, &nrspaces);
1475 obj->data.rss.uri = uri;
1476 obj->data.rss.interval = interval > 0 ? interval * 60 : 15*60;
1477 obj->data.rss.action = action;
1478 obj->data.rss.act_par = act_par;
1479 obj->data.rss.nrspaces = nrspaces;
1481 NORM_ERR("wrong number of arguments for $rss");
1485 END OBJ_ARG(weather, 0, "weather needs arguments: <uri> <locID> <data_type> [interval in minutes]")
1488 char *locID = (char *) malloc(9 * sizeof(char));
1489 char *uri = (char *) malloc(128 * sizeof(char));
1490 char *data_type = (char *) malloc(32 * sizeof(char));
1492 argc = sscanf(arg, "%119s %8s %31s %f", uri, locID, data_type, &interval);
1495 if (process_weather_uri(uri, locID, 0)) {
1499 CRIT_ERR(obj, free_at_crash, \
1500 "could not recognize the weather uri");
1503 obj->data.weather.uri = uri;
1504 obj->data.weather.data_type = data_type;
1506 /* Limit the data retrieval interval to half hour min */
1507 if (interval < 30) {
1511 /* Convert to seconds */
1512 obj->data.weather.interval = interval * 60;
1515 DBGP("weather: fetching %s from %s every %d seconds", \
1516 data_type, uri, obj->data.weather.interval);
1521 CRIT_ERR(obj, free_at_crash, "wrong number of arguments for $weather");
1525 END OBJ_ARG(weather_forecast, 0, "weather_forecast needs arguments: <uri> <locID> <day> <data_type> [interval in minutes]")
1529 char *locID = (char *) malloc(9 * sizeof(char));
1530 char *uri = (char *) malloc(128 * sizeof(char));
1531 char *data_type = (char *) malloc(32 * sizeof(char));
1533 argc = sscanf(arg, "%119s %8s %1u %31s %f", uri, locID, &day, data_type, &interval);
1536 if (process_weather_uri(uri, locID, 1)) {
1540 CRIT_ERR(obj, free_at_crash, \
1541 "could not recognize the weather forecast uri");
1544 obj->data.weather_forecast.uri = uri;
1545 obj->data.weather_forecast.data_type = data_type;
1547 /* Limit the day between 0 (today) and FORECAST_DAYS */
1548 if (day >= FORECAST_DAYS) {
1549 day = FORECAST_DAYS-1;
1551 obj->data.weather_forecast.day = day;
1553 /* Limit the data retrieval interval to 3 hours and an half */
1554 if (interval < 210) {
1558 /* Convert to seconds */
1559 obj->data.weather_forecast.interval = interval * 60;
1562 DBGP("weather_forecast: fetching %s for day %d from %s every %d seconds", \
1563 data_type, day, uri, obj->data.weather_forecast.interval);
1568 CRIT_ERR(obj, free_at_crash, "wrong number of arguments for $weather_forecast");
1572 END OBJ_ARG(lua, 0, "lua needs arguments: <function name> [function parameters]")
1573 obj->data.s = strndup(arg, text_buffer_size);
1574 END OBJ_ARG(lua_parse, 0, "lua_parse needs arguments: <function name> [function parameters]")
1575 obj->data.s = strndup(arg, text_buffer_size);
1576 END OBJ_ARG(lua_bar, 0, "lua_bar needs arguments: <height>,<width> <function name> [function parameters]")
1578 arg = scan_bar(arg, &obj->a, &obj->b);
1580 obj->data.s = strndup(arg, text_buffer_size);
1582 CRIT_ERR(obj, free_at_crash, "lua_bar needs arguments: <height>,<width> <function name> [function parameters]");
1585 END OBJ_ARG(lua_graph, 0, "lua_graph needs arguments: <function name> [height],[width] [gradient colour 1] [gradient colour 2] [scale] [-t] [-l]")
1587 SIZE_DEFAULTS(graph);
1588 buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
1589 &obj->e, &obj->char_a, &obj->char_b);
1593 CRIT_ERR(obj, free_at_crash, "lua_graph needs arguments: <function name> [height],[width] [gradient colour 1] [gradient colour 2] [scale] [-t] [-l]");
1595 END OBJ_ARG(lua_gauge, 0, "lua_gauge needs arguments: <height>,<width> <function name> [function parameters]")
1596 SIZE_DEFAULTS(gauge);
1597 arg = scan_gauge(arg, &obj->a, &obj->b);
1599 obj->data.s = strndup(arg, text_buffer_size);
1601 CRIT_ERR(obj, free_at_crash, "lua_gauge needs arguments: <height>,<width> <function name> [function parameters]");
1604 #endif /* HAVE_LUA */
1606 END OBJ(hddtemp, &update_hddtemp)
1608 obj->data.s = strndup(arg, text_buffer_size);
1609 #endif /* HDDTEMP */
1610 #ifdef TCP_PORT_MONITOR
1611 END OBJ_ARG(tcp_portmon, &tcp_portmon_update, "tcp_portmon: needs arguments")
1612 tcp_portmon_init(arg, &obj->data.tcp_port_monitor);
1613 #endif /* TCP_PORT_MONITOR */
1614 END OBJ(entropy_avail, &update_entropy)
1615 END OBJ(entropy_perc, &update_entropy)
1616 END OBJ(entropy_poolsize, &update_entropy)
1617 END OBJ(entropy_bar, &update_entropy)
1619 scan_bar(arg, &obj->a, &obj->b);
1620 END OBJ_ARG(include, 0, "include needs a argument")
1621 struct conftree *leaf = conftree_add(currentconffile, arg);
1623 if (load_config_file(arg) == TRUE) {
1624 obj->sub = malloc(sizeof(struct text_object));
1625 currentconffile = leaf;
1626 extract_variable_text_internal(obj->sub, get_global_text());
1627 currentconffile = leaf->back;
1629 NORM_ERR("Can't load configfile '%s'.", arg);
1632 NORM_ERR("You are trying to load '%s' recursively, I'm only going to load it once to prevent an infinite loop.", arg);
1634 END OBJ_ARG(blink, 0, "blink needs a argument")
1635 obj->sub = malloc(sizeof(struct text_object));
1636 extract_variable_text_internal(obj->sub, arg);
1637 END OBJ_ARG(to_bytes, 0, "to_bytes needs a argument")
1638 obj->sub = malloc(sizeof(struct text_object));
1639 extract_variable_text_internal(obj->sub, arg);
1643 obj->data.scroll.resetcolor = get_current_text_color();
1644 obj->data.scroll.step = 1;
1645 if (arg && sscanf(arg, "%u %n", &obj->data.scroll.show, &n1) > 0) {
1646 sscanf(arg + n1, "%u %n", &obj->data.scroll.step, &n2);
1647 if (*(arg + n1 + n2)) {
1650 obj->data.scroll.step = 1;
1652 obj->data.scroll.text = malloc(strlen(arg + n1) + obj->data.scroll.show + 1);
1653 for(n2 = 0; (unsigned int) n2 < obj->data.scroll.show; n2++) {
1654 obj->data.scroll.text[n2] = ' ';
1656 obj->data.scroll.text[n2] = 0;
1657 strcat(obj->data.scroll.text, arg + n1);
1658 obj->data.scroll.start = 0;
1659 obj->sub = malloc(sizeof(struct text_object));
1660 extract_variable_text_internal(obj->sub,
1661 obj->data.scroll.text);
1663 CRIT_ERR(obj, free_at_crash, "scroll needs arguments: <length> [<step>] <text>");
1665 END OBJ_ARG(combine, 0, "combine needs arguments: <text1> <text2>")
1667 unsigned int indenting = 0; //vars can be used as args for other vars
1670 startvar[0] = endvar[0] = startvar[1] = endvar[1] = -1;
1672 for (i=0; arg[i] != 0 && j < 2; i++) {
1673 if(startvar[j] == -1) {
1677 }else if(endvar[j] == -1) {
1680 }else if(arg[i] == '}') {
1683 if (indenting == 0 && arg[i+1] < 48) { //<48 has 0, $, and the most used chars not used in varnames but not { or }
1689 if(startvar[0] >= 0 && endvar[0] >= 0 && startvar[1] >= 0 && endvar[1] >= 0) {
1690 obj->data.combine.left = malloc(endvar[0]-startvar[0] + 1);
1691 obj->data.combine.seperation = malloc(startvar[1] - endvar[0] + 1);
1692 obj->data.combine.right= malloc(endvar[1]-startvar[1] + 1);
1694 strncpy(obj->data.combine.left, arg + startvar[0], endvar[0] - startvar[0]);
1695 obj->data.combine.left[endvar[0] - startvar[0]] = 0;
1697 strncpy(obj->data.combine.seperation, arg + endvar[0], startvar[1] - endvar[0]);
1698 obj->data.combine.seperation[startvar[1] - endvar[0]] = 0;
1700 strncpy(obj->data.combine.right, arg + startvar[1], endvar[1] - startvar[1]);
1701 obj->data.combine.right[endvar[1] - startvar[1]] = 0;
1703 obj->sub = malloc(sizeof(struct text_object));
1704 extract_variable_text_internal(obj->sub, obj->data.combine.left);
1705 obj->sub->sub = malloc(sizeof(struct text_object));
1706 extract_variable_text_internal(obj->sub->sub, obj->data.combine.right);
1708 CRIT_ERR(obj, free_at_crash, "combine needs arguments: <text1> <text2>");
1711 END OBJ_ARG(nvidia, 0, "nvidia needs an argument")
1712 if (set_nvidia_type(&obj->data.nvidia, arg)) {
1713 CRIT_ERR(obj, free_at_crash, "nvidia: invalid argument"
1714 " specified: '%s'\n", arg);
1718 END OBJ_ARG(apcupsd, &update_apcupsd, "apcupsd needs arguments: <host> <port>")
1721 if (sscanf(arg, "%63s %d", host, &port) != 2) {
1722 CRIT_ERR(obj, free_at_crash, "apcupsd needs arguments: <host> <port>");
1724 info.apcupsd.port = htons(port);
1725 strncpy(info.apcupsd.host, host, sizeof(info.apcupsd.host));
1727 END OBJ(apcupsd_name, &update_apcupsd)
1728 END OBJ(apcupsd_model, &update_apcupsd)
1729 END OBJ(apcupsd_upsmode, &update_apcupsd)
1730 END OBJ(apcupsd_cable, &update_apcupsd)
1731 END OBJ(apcupsd_status, &update_apcupsd)
1732 END OBJ(apcupsd_linev, &update_apcupsd)
1733 END OBJ(apcupsd_load, &update_apcupsd)
1734 END OBJ(apcupsd_loadbar, &update_apcupsd)
1736 scan_bar(arg, &obj->a, &obj->b);
1738 END OBJ(apcupsd_loadgraph, &update_apcupsd)
1740 SIZE_DEFAULTS(graph);
1741 buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
1742 &obj->e, &obj->char_a, &obj->char_b);
1744 END OBJ(apcupsd_loadgauge, &update_apcupsd)
1745 SIZE_DEFAULTS(gauge);
1746 scan_gauge(arg, &obj->a, &obj->b);
1748 END OBJ(apcupsd_charge, &update_apcupsd)
1749 END OBJ(apcupsd_timeleft, &update_apcupsd)
1750 END OBJ(apcupsd_temp, &update_apcupsd)
1751 END OBJ(apcupsd_lastxfer, &update_apcupsd)
1752 #endif /* APCUPSD */
1756 NORM_ERR("unknown variable %s", s);
1757 obj->type = OBJ_text;
1758 snprintf(buf, 256, "${%s}", s);
1759 obj->data.s = strndup(buf, text_buffer_size);
1769 #undef SIZE_DEFAULTS
1775 * - assumes that *string is '#'
1776 * - removes the part from '#' to the end of line ('\n' or '\0')
1777 * - it removes the '\n'
1778 * - copies the last char into 'char *last' argument, which should be a pointer
1779 * to a char rather than a string.
1781 static size_t remove_comment(char *string, char *last)
1784 while (*end != '\0' && *end != '\n') {
1787 if (last) *last = *end;
1788 if (*end == '\n') end++;
1789 strfold(string, end - string);
1790 return end - string;
1793 size_t remove_comments(char *string)
1797 for (curplace = string; *curplace != 0; curplace++) {
1798 if (*curplace == '\\' && *(curplace + 1) == '#') {
1799 // strcpy can't be used for overlapping strings
1800 strfold(curplace, 1);
1802 } else if (*curplace == '#') {
1803 folded += remove_comment(curplace, 0);
1809 int extract_variable_text_internal(struct text_object *retval, const char *const_p)
1811 struct text_object *obj;
1812 char *p, *s, *orig_p;
1814 void *ifblock_opaque = NULL;
1819 p = strndup(const_p, max_user_text - 1);
1820 while (text_contains_templates(p)) {
1822 tmp = find_and_replace_templates(p);
1828 if (strcmp(p, const_p)) {
1829 DBGP("replaced all templates in text: input is\n'%s'\noutput is\n'%s'", const_p, p);
1831 DBGP("no templates to replace");
1834 memset(retval, 0, sizeof(struct text_object));
1836 line = global_text_lines;
1844 obj = create_plain_text(s);
1846 append_object(retval, obj);
1856 /* variable is either $foo or ${foo} */
1858 unsigned int brl = 1, brr = 0;
1862 while (*p && brl != brr) {
1877 while (*p && (isalnum((int) *p) || *p == '_')) {
1882 /* copy variable to buffer */
1883 len = (p - s > 255) ? 255 : (p - s);
1884 strncpy(buf, s, len);
1892 /* search for variable in environment */
1896 obj = create_plain_text(var);
1898 append_object(retval, obj);
1903 /* if variable wasn't found in environment, use some special */
1908 if (strchr(buf, ' ')) {
1909 arg = strchr(buf, ' ');
1912 while (isspace((int) *arg)) {
1920 /* lowercase variable name */
1923 *tmp_p = tolower(*tmp_p);
1927 obj = construct_text_object(buf, arg,
1928 line, &ifblock_opaque, orig_p);
1930 append_object(retval, obj);
1934 obj = create_plain_text("$");
1937 append_object(retval, obj);
1940 } else if (*p == '\\' && *(p+1) == '#') {
1942 } else if (*p == '#') {
1944 if (remove_comment(p, &c) && p > orig_p && c == '\n') {
1945 /* if remove_comment removed a newline, we need to 'back up' with p */
1951 obj = create_plain_text(s);
1953 append_object(retval, obj);
1956 if (!ifblock_stack_empty(&ifblock_opaque)) {
1957 NORM_ERR("one or more $endif's are missing");
1965 * Frees the list of text objects root points to. When internal = 1, it won't
1966 * free global objects.
1968 void free_text_objects(struct text_object *root, int internal)
1970 struct text_object *obj;
1976 #define data obj->data
1977 for (obj = root->prev; obj; obj = root->prev) {
1978 root->prev = obj->prev;
1979 switch (obj->type) {
1984 #endif /* !__OpenBSD__ */
1989 close(data.sysfs.fd);
1991 #endif /* __linux__ */
1993 free(data.read_tcp.host);
2003 free(data.mboxscan.args);
2004 free(data.mboxscan.output);
2008 case OBJ_seen_mails:
2009 case OBJ_unseen_mails:
2010 case OBJ_flagged_mails:
2011 case OBJ_unflagged_mails:
2012 case OBJ_forwarded_mails:
2013 case OBJ_unforwarded_mails:
2014 case OBJ_replied_mails:
2015 case OBJ_unreplied_mails:
2016 case OBJ_draft_mails:
2017 case OBJ_trashed_mails:
2018 free(data.local_mail.mbox);
2020 case OBJ_imap_unseen:
2025 case OBJ_imap_messages:
2030 case OBJ_pop3_unseen:
2042 free_text_objects(obj->sub, 1);
2045 case OBJ_if_existing:
2046 case OBJ_if_mounted:
2047 case OBJ_if_running:
2048 free(data.ifblock.s);
2049 free(data.ifblock.str);
2053 free(data.headtail.logfile);
2054 if(data.headtail.buffer) {
2055 free(data.headtail.buffer);
2072 case OBJ_iconv_start:
2077 case OBJ_disk_protect:
2081 free(data.ifblock.s);
2082 free(data.ifblock.str);
2085 if (info.gw_info.iface) {
2086 free(info.gw_info.iface);
2087 info.gw_info.iface = 0;
2089 if (info.gw_info.ip) {
2090 free(info.gw_info.ip);
2091 info.gw_info.ip = 0;
2094 case OBJ_ioscheduler:
2099 #if (defined(__FreeBSD__) || defined(__linux__))
2101 free(data.ifblock.s);
2102 free(data.ifblock.str);
2106 case OBJ_xmms2_artist:
2107 if (info.xmms2.artist) {
2108 free(info.xmms2.artist);
2109 info.xmms2.artist = 0;
2112 case OBJ_xmms2_album:
2113 if (info.xmms2.album) {
2114 free(info.xmms2.album);
2115 info.xmms2.album = 0;
2118 case OBJ_xmms2_title:
2119 if (info.xmms2.title) {
2120 free(info.xmms2.title);
2121 info.xmms2.title = 0;
2124 case OBJ_xmms2_genre:
2125 if (info.xmms2.genre) {
2126 free(info.xmms2.genre);
2127 info.xmms2.genre = 0;
2130 case OBJ_xmms2_comment:
2131 if (info.xmms2.comment) {
2132 free(info.xmms2.comment);
2133 info.xmms2.comment = 0;
2137 if (info.xmms2.url) {
2138 free(info.xmms2.url);
2142 case OBJ_xmms2_date:
2143 if (info.xmms2.date) {
2144 free(info.xmms2.date);
2145 info.xmms2.date = 0;
2148 case OBJ_xmms2_status:
2149 if (info.xmms2.status) {
2150 free(info.xmms2.status);
2151 info.xmms2.status = 0;
2154 case OBJ_xmms2_playlist:
2155 if (info.xmms2.playlist) {
2156 free(info.xmms2.playlist);
2157 info.xmms2.playlist = 0;
2160 case OBJ_xmms2_smart:
2161 if (info.xmms2.artist) {
2162 free(info.xmms2.artist);
2163 info.xmms2.artist = 0;
2165 if (info.xmms2.title) {
2166 free(info.xmms2.title);
2167 info.xmms2.title = 0;
2169 if (info.xmms2.url) {
2170 free(info.xmms2.url);
2176 case OBJ_bmpx_title:
2177 case OBJ_bmpx_artist:
2178 case OBJ_bmpx_album:
2179 case OBJ_bmpx_track:
2181 case OBJ_bmpx_bitrate:
2190 free(data.curl.uri);
2196 free(data.rss.action);
2201 free(data.weather.uri);
2202 free(data.weather.data_type);
2206 case OBJ_weather_forecast:
2207 free(data.weather_forecast.uri);
2208 free(data.weather_forecast.data_type);
2221 #endif /* HAVE_LUA */
2228 case OBJ_battery_short:
2231 case OBJ_battery_time:
2234 #endif /* !__OpenBSD__ */
2239 case OBJ_execigraph:
2240 case OBJ_execigauge:
2242 free(data.execi.cmd);
2243 free(data.execi.buffer);
2246 if (data.texeci.p_timed_thread) timed_thread_destroy(data.texeci.p_timed_thread, &data.texeci.p_timed_thread);
2247 free(data.texeci.cmd);
2248 free(data.texeci.buffer);
2250 case OBJ_nameserver:
2259 if (info.first_process && !internal) {
2260 free_all_processes();
2261 info.first_process = NULL;
2263 if (data.top.s) free(data.top.s);
2273 #endif /* HDDTEMP */
2274 case OBJ_entropy_avail:
2275 case OBJ_entropy_perc:
2276 case OBJ_entropy_poolsize:
2277 case OBJ_entropy_bar:
2279 case OBJ_user_names:
2280 if (info.users.names) {
2281 free(info.users.names);
2282 info.users.names = 0;
2285 case OBJ_user_terms:
2286 if (info.users.terms) {
2287 free(info.users.terms);
2288 info.users.terms = 0;
2291 case OBJ_user_times:
2292 if (info.users.times) {
2293 free(info.users.times);
2294 info.users.times = 0;
2299 case OBJ_smapi_bat_perc:
2300 case OBJ_smapi_bat_temp:
2301 case OBJ_smapi_bat_power:
2304 case OBJ_if_smapi_bat_installed:
2305 free(data.ifblock.s);
2306 free(data.ifblock.str);
2315 case OBJ_mpd_artist:
2317 case OBJ_mpd_random:
2318 case OBJ_mpd_repeat:
2320 case OBJ_mpd_bitrate:
2321 case OBJ_mpd_status:
2323 case OBJ_mpd_elapsed:
2324 case OBJ_mpd_length:
2328 case OBJ_mpd_percent:
2330 case OBJ_if_mpd_playing:
2338 case OBJ_moc_artist:
2341 case OBJ_moc_totaltime:
2342 case OBJ_moc_timeleft:
2343 case OBJ_moc_curtime:
2344 case OBJ_moc_bitrate:
2353 free_text_objects(obj->sub, 1);
2358 free(data.scroll.text);
2359 free_text_objects(obj->sub, 1);
2363 free(data.combine.left);
2364 free(data.combine.seperation);
2365 free(data.combine.right);
2366 free_text_objects(obj->sub, 1);
2371 case OBJ_apcupsd_name:
2372 case OBJ_apcupsd_model:
2373 case OBJ_apcupsd_upsmode:
2374 case OBJ_apcupsd_cable:
2375 case OBJ_apcupsd_status:
2376 case OBJ_apcupsd_linev:
2377 case OBJ_apcupsd_load:
2378 case OBJ_apcupsd_loadbar:
2380 case OBJ_apcupsd_loadgraph:
2381 case OBJ_apcupsd_loadgauge:
2383 case OBJ_apcupsd_charge:
2384 case OBJ_apcupsd_timeleft:
2385 case OBJ_apcupsd_temp:
2386 case OBJ_apcupsd_lastxfer:
2388 #endif /* APCUPSD */
2391 case OBJ_desktop_number:
2392 case OBJ_desktop_name:
2393 if(info.x11.desktop.name && !internal) {
2394 free(info.x11.desktop.name);
2395 info.x11.desktop.name = NULL;
2397 if(info.x11.desktop.all_names && !internal) {
2398 free(info.x11.desktop.all_names);
2399 info.x11.desktop.all_names = NULL;