1 /* -*- mode: c; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: t -*-
3 * Conky, a system monitor, based on torsmo
5 * Any original torsmo code is licensed under the BSD license
7 * All code written since the fork of torsmo is licensed under the GPL
9 * Please see COPYING for details
11 * Copyright (c) 2004, Hannu Saransaari and Lauri Hakkarainen
12 * Copyright (c) 2005-2009 Brenden Matthews, Philip Kovacs, et. al.
14 * All rights reserved.
16 * This program is free software: you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License as published by
18 * the Free Software Foundation, either version 3 of the License, or
19 * (at your option) any later version.
21 * This program is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
25 * You should have received a copy of the GNU General Public License
26 * along with this program. If not, see <http://www.gnu.org/licenses/>.
28 * vim: ts=4 sw=4 noet ai cindent syntax=c
34 #include "text_object.h"
48 #include "temphelper.h"
53 /* check for OS and include appropriate headers */
54 #if defined(__linux__)
56 #elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
58 #elif defined(__OpenBSD__)
62 /* OS specific prototypes to be implemented by linux.c & Co. */
63 void update_entropy(void);
75 #define ICONV_CODEPAGE_LENGTH 20
77 int register_iconv(iconv_t *new_iconv);
81 char iconv_converting;
82 static iconv_t **iconv_cd = 0;
84 char is_iconv_converting(void)
86 return iconv_converting;
89 void set_iconv_converting(char i)
94 long get_iconv_selected(void)
96 return iconv_selected;
99 void set_iconv_selected(long i)
104 int register_iconv(iconv_t *new_iconv)
106 iconv_cd = realloc(iconv_cd, sizeof(iconv_t *) * (iconv_count + 1));
108 CRIT_ERR(NULL, NULL, "Out of memory");
110 iconv_cd[iconv_count] = malloc(sizeof(iconv_t));
111 if (!iconv_cd[iconv_count]) {
112 CRIT_ERR(NULL, NULL, "Out of memory");
114 memcpy(iconv_cd[iconv_count], new_iconv, sizeof(iconv_t));
119 void free_iconv(void)
124 for (i = 0; i < iconv_count; i++) {
126 iconv_close(*iconv_cd[i]);
135 void iconv_convert(size_t a, char *buff_in, char *p, size_t p_max_size)
137 if (a > 0 && is_iconv_converting() && get_iconv_selected() > 0
138 && (iconv_cd[iconv_selected - 1] != (iconv_t) (-1))) {
140 size_t dummy1, dummy2;
142 const char *ptr = buff_in;
150 strncpy(buff_in, p, p_max_size);
152 iconv(*iconv_cd[iconv_selected - 1], NULL, NULL, NULL, NULL);
154 bytes = iconv(*iconv_cd[iconv_selected - 1], &ptr, &dummy1,
157 NORM_ERR("Iconv codeset conversion failed");
162 /* It is nessecary when we are converting from multibyte to
163 * singlebyte codepage */
167 #endif /* HAVE_ICONV */
169 /* strip a leading /dev/ if any, following symlinks first
171 * BEWARE: this function returns a pointer to static content
172 * which gets overwritten in consecutive calls. I.e.:
173 * this function is NOT reentrant.
175 static const char *dev_name(const char *path)
177 static char buf[255]; /* should be enough for pathnames */
183 #define DEV_NAME(x) \
184 x != NULL && strlen(x) > 5 && strncmp(x, "/dev/", 5) == 0 ? x + 5 : x
185 if ((buflen = readlink(path, buf, 254)) == -1)
186 return DEV_NAME(path);
188 return DEV_NAME(buf);
192 static struct text_object *new_text_object_internal(void)
194 struct text_object *obj = malloc(sizeof(struct text_object));
195 memset(obj, 0, sizeof(struct text_object));
199 static struct text_object *create_plain_text(const char *s)
201 struct text_object *obj;
203 if (s == NULL || *s == '\0') {
207 obj = new_text_object_internal();
209 obj->type = OBJ_text;
210 obj->data.s = strndup(s, text_buffer_size);
214 /* construct_text_object() creates a new text_object */
215 struct text_object *construct_text_object(const char *s, const char *arg, long
216 line, void **ifblock_opaque, void *free_at_crash)
218 // struct text_object *obj = new_text_object();
219 struct text_object *obj = new_text_object_internal();
223 #define CALLBACK(x) (-(long)x)
225 #define OBJ(a, n) if (strcmp(s, #a) == 0) { \
226 obj->type = OBJ_##a; \
227 if (n > 0) { need_mask |= (1ULL << n); } \
228 else if (n < 0) { add_update_callback((void (*)(void))CALLBACK(n)); } {
229 #define OBJ_IF(a, n) if (strcmp(s, #a) == 0) { \
230 obj->type = OBJ_##a; obj_be_ifblock_if(ifblock_opaque, obj); \
231 if (n > 0) { need_mask |= (1ULL << n); } \
232 else if (n < 0) { add_update_callback((void (*)(void))CALLBACK(n)); } {
235 #define SIZE_DEFAULTS(arg) { \
236 obj->a = default_##arg##_width; \
237 obj->b = default_##arg##_height; \
242 obj->type = OBJ_color;
243 obj->data.l = get_x11_color(s);
250 obj->data.i = open_acpi_temperature(arg);
251 END OBJ(acpiacadapter, 0)
253 #endif /* !__OpenBSD__ */
255 if (!arg || !isdigit(arg[0]) || strlen(arg) >= 2 || atoi(&arg[0]) == 0
256 || (unsigned int) atoi(&arg[0]) > info.cpu_count) {
257 obj->data.cpu_index = 1;
258 /* NORM_ERR("freq: Invalid CPU number or you don't have that many CPUs! "
259 "Displaying the clock for CPU 1."); */
261 obj->data.cpu_index = atoi(&arg[0]);
266 if (!arg || !isdigit(arg[0]) || strlen(arg) >= 2 || atoi(&arg[0]) == 0
267 || (unsigned int) atoi(&arg[0]) > info.cpu_count) {
268 obj->data.cpu_index = 1;
269 /* NORM_ERR("freq_g: Invalid CPU number or you don't have that many "
270 "CPUs! Displaying the clock for CPU 1."); */
272 obj->data.cpu_index = atoi(&arg[0]);
277 obj->data.read_tcp.host = malloc(text_buffer_size);
278 sscanf(arg, "%s", obj->data.read_tcp.host);
279 sscanf(arg+strlen(obj->data.read_tcp.host), "%u", &(obj->data.read_tcp.port));
280 if(obj->data.read_tcp.port == 0) {
281 obj->data.read_tcp.port = atoi(obj->data.read_tcp.host);
282 strcpy(obj->data.read_tcp.host,"localhost");
284 obj->data.read_tcp.port = htons(obj->data.read_tcp.port);
285 if(obj->data.read_tcp.port < 1 || obj->data.read_tcp.port > 65535) {
286 CRIT_ERR(obj, free_at_crash, "read_tcp: Needs \"(host) port\" as argument(s)");
289 CRIT_ERR(obj, free_at_crash, "read_tcp: Needs \"(host) port\" as argument(s)");
291 #if defined(__linux__)
292 END OBJ(voltage_mv, 0)
294 if (!arg || !isdigit(arg[0]) || strlen(arg) >= 2 || atoi(&arg[0]) == 0
295 || (unsigned int) atoi(&arg[0]) > info.cpu_count) {
296 obj->data.cpu_index = 1;
297 /* NORM_ERR("voltage_mv: Invalid CPU number or you don't have that many "
298 "CPUs! Displaying voltage for CPU 1."); */
300 obj->data.cpu_index = atoi(&arg[0]);
303 END OBJ(voltage_v, 0)
305 if (!arg || !isdigit(arg[0]) || strlen(arg) >= 2 || atoi(&arg[0]) == 0
306 || (unsigned int) atoi(&arg[0]) > info.cpu_count) {
307 obj->data.cpu_index = 1;
308 /* NORM_ERR("voltage_v: Invalid CPU number or you don't have that many "
309 "CPUs! Displaying voltage for CPU 1."); */
311 obj->data.cpu_index = atoi(&arg[0]);
316 END OBJ(wireless_essid, CALLBACK(&update_net_stats))
318 obj->data.net = get_net_stat(arg, obj, free_at_crash);
320 // default to DEFAULTNETDEV
321 char *buf = strndup(DEFAULTNETDEV, text_buffer_size);
322 obj->data.net = get_net_stat(buf, obj, free_at_crash);
325 END OBJ(wireless_mode, CALLBACK(&update_net_stats))
327 obj->data.net = get_net_stat(arg, obj, free_at_crash);
329 // default to DEFAULTNETDEV
330 char *buf = strndup(DEFAULTNETDEV, text_buffer_size);
331 obj->data.net = get_net_stat(buf, obj, free_at_crash);
334 END OBJ(wireless_bitrate, CALLBACK(&update_net_stats))
336 obj->data.net = get_net_stat(arg, obj, free_at_crash);
338 // default to DEFAULTNETDEV
339 char *buf = strndup(DEFAULTNETDEV, text_buffer_size);
340 obj->data.net = get_net_stat(buf, obj, free_at_crash);
343 END OBJ(wireless_ap, CALLBACK(&update_net_stats))
345 obj->data.net = get_net_stat(arg, obj, free_at_crash);
347 // default to DEFAULTNETDEV
348 char *buf = strndup(DEFAULTNETDEV, text_buffer_size);
349 obj->data.net = get_net_stat(buf, obj, free_at_crash);
352 END OBJ(wireless_link_qual, CALLBACK(&update_net_stats))
354 obj->data.net = get_net_stat(arg, obj, free_at_crash);
356 // default to DEFAULTNETDEV
357 char *buf = strndup(DEFAULTNETDEV, text_buffer_size);
358 obj->data.net = get_net_stat(buf, obj, free_at_crash);
361 END OBJ(wireless_link_qual_max, CALLBACK(&update_net_stats))
363 obj->data.net = get_net_stat(arg, obj, free_at_crash);
365 // default to DEFAULTNETDEV
366 char *buf = strndup(DEFAULTNETDEV, text_buffer_size);
367 obj->data.net = get_net_stat(buf, obj, free_at_crash);
370 END OBJ(wireless_link_qual_perc, CALLBACK(&update_net_stats))
372 obj->data.net = get_net_stat(arg, obj, free_at_crash);
374 // default to DEFAULTNETDEV
375 char *buf = strndup(DEFAULTNETDEV, text_buffer_size);
376 obj->data.net = get_net_stat(buf, obj, free_at_crash);
379 END OBJ(wireless_link_bar, CALLBACK(&update_net_stats))
382 arg = scan_bar(arg, &obj->a, &obj->b);
383 obj->data.net = get_net_stat(arg, obj, free_at_crash);
385 // default to DEFAULTNETDEV
386 char *buf = strndup(DEFAULTNETDEV, text_buffer_size);
387 obj->data.net = get_net_stat(buf, obj, free_at_crash);
390 #endif /* HAVE_IWLIB */
392 #endif /* __linux__ */
400 sscanf(arg, "%63s", bat);
404 obj->data.s = strndup(bat, text_buffer_size);
405 END OBJ(battery_short, 0)
409 sscanf(arg, "%63s", bat);
413 obj->data.s = strndup(bat, text_buffer_size);
414 END OBJ(battery_time, 0)
418 sscanf(arg, "%63s", bat);
422 obj->data.s = strndup(bat, text_buffer_size);
423 END OBJ(battery_percent, 0)
427 sscanf(arg, "%63s", bat);
431 obj->data.s = strndup(bat, text_buffer_size);
432 END OBJ(battery_bar, 0)
437 arg = scan_bar(arg, &obj->a, &obj->b);
438 sscanf(arg, "%63s", bat);
442 obj->data.s = strndup(bat, text_buffer_size);
443 #endif /* !__OpenBSD__ */
445 #if defined(__linux__)
446 END OBJ(disk_protect, 0)
448 obj->data.s = strndup(dev_name(arg), text_buffer_size);
450 CRIT_ERR(obj, free_at_crash, "disk_protect needs an argument");
451 END OBJ(i8k_version, CALLBACK(&update_i8k))
452 END OBJ(i8k_bios, CALLBACK(&update_i8k))
453 END OBJ(i8k_serial, CALLBACK(&update_i8k))
454 END OBJ(i8k_cpu_temp, CALLBACK(&update_i8k))
455 END OBJ(i8k_left_fan_status, CALLBACK(&update_i8k))
456 END OBJ(i8k_right_fan_status, CALLBACK(&update_i8k))
457 END OBJ(i8k_left_fan_rpm, CALLBACK(&update_i8k))
458 END OBJ(i8k_right_fan_rpm, CALLBACK(&update_i8k))
459 END OBJ(i8k_ac_status, CALLBACK(&update_i8k))
460 END OBJ(i8k_buttons_status, CALLBACK(&update_i8k))
463 END OBJ(ibm_temps, 0)
465 CRIT_ERR(obj, free_at_crash, "ibm_temps: needs an argument");
467 if (!isdigit(arg[0]) || strlen(arg) >= 2 || atoi(&arg[0]) >= 8) {
468 obj->data.sensor = 0;
469 NORM_ERR("Invalid temperature sensor! Sensor number must be 0 to 7. "
470 "Using 0 (CPU temp sensor).");
472 obj->data.sensor = atoi(&arg[0]);
473 END OBJ(ibm_volume, 0)
474 END OBJ(ibm_brightness, 0)
476 /* information from sony_laptop kernel module
477 * /sys/devices/platform/sony-laptop */
478 END OBJ(sony_fanspeed, 0)
479 END OBJ_IF(if_gw, CALLBACK(&update_gateway_info))
480 END OBJ(ioscheduler, 0)
482 CRIT_ERR(obj, free_at_crash, "get_ioscheduler needs an argument (e.g. hda)");
485 obj->data.s = strndup(dev_name(arg), text_buffer_size);
486 END OBJ(laptop_mode, 0)
487 END OBJ(pb_battery, 0)
488 if (arg && strcmp(arg, "status") == EQUAL) {
489 obj->data.i = PB_BATT_STATUS;
490 } else if (arg && strcmp(arg, "percent") == EQUAL) {
491 obj->data.i = PB_BATT_PERCENT;
492 } else if (arg && strcmp(arg, "time") == EQUAL) {
493 obj->data.i = PB_BATT_TIME;
495 NORM_ERR("pb_battery: needs one argument: status, percent or time");
500 #endif /* __linux__ */
501 #if (defined(__FreeBSD__) || defined(__linux__))
504 NORM_ERR("if_up needs an argument");
505 obj->data.ifblock.s = 0;
507 obj->data.ifblock.s = strndup(arg, text_buffer_size);
510 #if defined(__OpenBSD__)
511 END OBJ(obsd_sensors_temp, 0)
513 CRIT_ERR(obj, free_at_crash, "obsd_sensors_temp: needs an argument");
515 if (!isdigit(arg[0]) || atoi(&arg[0]) < 0
516 || atoi(&arg[0]) > OBSD_MAX_SENSORS - 1) {
517 obj->data.sensor = 0;
518 NORM_ERR("Invalid temperature sensor number!");
520 obj->data.sensor = atoi(&arg[0]);
521 END OBJ(obsd_sensors_fan, 0)
523 CRIT_ERR(obj, free_at_crash, "obsd_sensors_fan: needs 2 arguments (device and sensor "
526 if (!isdigit(arg[0]) || atoi(&arg[0]) < 0
527 || atoi(&arg[0]) > OBSD_MAX_SENSORS - 1) {
528 obj->data.sensor = 0;
529 NORM_ERR("Invalid fan sensor number!");
531 obj->data.sensor = atoi(&arg[0]);
532 END OBJ(obsd_sensors_volt, 0)
534 CRIT_ERR(obj, free_at_crash, "obsd_sensors_volt: needs 2 arguments (device and sensor "
537 if (!isdigit(arg[0]) || atoi(&arg[0]) < 0
538 || atoi(&arg[0]) > OBSD_MAX_SENSORS - 1) {
539 obj->data.sensor = 0;
540 NORM_ERR("Invalid voltage sensor number!");
542 obj->data.sensor = atoi(&arg[0]);
543 END OBJ(obsd_vendor, 0)
544 END OBJ(obsd_product, 0)
545 #endif /* __OpenBSD__ */
546 END OBJ(buffers, CALLBACK(&update_meminfo))
547 END OBJ(cached, CALLBACK(&update_meminfo))
548 #define SCAN_CPU(__arg, __var) { \
550 if (__arg && sscanf(__arg, " cpu%u %n", &__var, &__offset) > 0) \
555 END OBJ(cpu, CALLBACK(&update_cpu_usage))
556 SCAN_CPU(arg, obj->data.cpu_index);
557 DBGP2("Adding $cpu for CPU %d", obj->data.cpu_index);
559 END OBJ(cpugauge, CALLBACK(&update_cpu_usage))
560 SIZE_DEFAULTS(gauge);
561 SCAN_CPU(arg, obj->data.cpu_index);
562 scan_gauge(arg, &obj->a, &obj->b);
563 DBGP2("Adding $cpugauge for CPU %d", obj->data.cpu_index);
565 END OBJ(cpubar, CALLBACK(&update_cpu_usage))
567 SCAN_CPU(arg, obj->data.cpu_index);
568 scan_bar(arg, &obj->a, &obj->b);
569 DBGP2("Adding $cpubar for CPU %d", obj->data.cpu_index);
571 END OBJ(cpugraph, CALLBACK(&update_cpu_usage))
573 SIZE_DEFAULTS(graph);
574 SCAN_CPU(arg, obj->data.cpu_index);
575 buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
576 &obj->e, &obj->char_a, &obj->char_b);
577 DBGP2("Adding $cpugraph for CPU %d", obj->data.cpu_index);
579 END OBJ(loadgraph, CALLBACK(&update_load_average))
581 SIZE_DEFAULTS(graph);
582 buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
583 &obj->e, &obj->char_a, &obj->char_b);
587 r = sscanf(arg, "%d", &a);
589 obj->data.loadavg[0] = (r >= 1) ? (unsigned char) a : 0;
593 END OBJ(diskio, CALLBACK(&update_diskio))
594 obj->data.diskio = prepare_diskio_stat(dev_name(arg));
595 END OBJ(diskio_read, CALLBACK(&update_diskio))
596 obj->data.diskio = prepare_diskio_stat(dev_name(arg));
597 END OBJ(diskio_write, CALLBACK(&update_diskio))
598 obj->data.diskio = prepare_diskio_stat(dev_name(arg));
600 END OBJ(diskiograph, CALLBACK(&update_diskio))
602 SIZE_DEFAULTS(graph);
603 buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
604 &obj->e, &obj->char_a, &obj->char_b);
606 obj->data.diskio = prepare_diskio_stat(dev_name(buf));
608 END OBJ(diskiograph_read, CALLBACK(&update_diskio))
610 SIZE_DEFAULTS(graph);
611 buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
612 &obj->e, &obj->char_a, &obj->char_b);
614 obj->data.diskio = prepare_diskio_stat(dev_name(buf));
616 END OBJ(diskiograph_write, CALLBACK(&update_diskio))
618 SIZE_DEFAULTS(graph);
619 buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
620 &obj->e, &obj->char_a, &obj->char_b);
622 obj->data.diskio = prepare_diskio_stat(dev_name(buf));
627 if (output_methods & TO_X) {
628 obj->data.l = arg ? get_x11_color(arg) : default_fg_color;
629 set_current_text_color(obj->data.l);
633 if (output_methods & TO_NCURSES) {
634 obj->data.l = COLOR_WHITE;
636 if(strcasecmp(arg, "red") == 0) {
637 obj->data.l = COLOR_RED;
638 }else if(strcasecmp(arg, "green") == 0) {
639 obj->data.l = COLOR_GREEN;
640 }else if(strcasecmp(arg, "yellow") == 0) {
641 obj->data.l = COLOR_YELLOW;
642 }else if(strcasecmp(arg, "blue") == 0) {
643 obj->data.l = COLOR_BLUE;
644 }else if(strcasecmp(arg, "magenta") == 0) {
645 obj->data.l = COLOR_MAGENTA;
646 }else if(strcasecmp(arg, "cyan") == 0) {
647 obj->data.l = COLOR_CYAN;
648 }else if(strcasecmp(arg, "black") == 0) {
649 obj->data.l = COLOR_BLACK;
652 set_current_text_color(obj->data.l);
653 init_pair(obj->data.l, obj->data.l, COLOR_BLACK);
657 obj->data.l = color0;
658 set_current_text_color(obj->data.l);
660 obj->data.l = color1;
661 set_current_text_color(obj->data.l);
663 obj->data.l = color2;
664 set_current_text_color(obj->data.l);
666 obj->data.l = color3;
667 set_current_text_color(obj->data.l);
669 obj->data.l = color4;
670 set_current_text_color(obj->data.l);
672 obj->data.l = color5;
673 set_current_text_color(obj->data.l);
675 obj->data.l = color6;
676 set_current_text_color(obj->data.l);
678 obj->data.l = color7;
679 set_current_text_color(obj->data.l);
681 obj->data.l = color8;
682 set_current_text_color(obj->data.l);
684 obj->data.l = color9;
685 set_current_text_color(obj->data.l);
688 obj->data.s = scan_font(arg);
690 END OBJ(conky_version, 0)
691 END OBJ(conky_build_date, 0)
692 END OBJ(conky_build_arch, 0)
693 END OBJ(downspeed, CALLBACK(&update_net_stats))
695 obj->data.net = get_net_stat(arg, obj, free_at_crash);
697 // default to DEFAULTNETDEV
698 char *buf = strndup(DEFAULTNETDEV, text_buffer_size);
699 obj->data.net = get_net_stat(buf, obj, free_at_crash);
702 END OBJ(downspeedf, CALLBACK(&update_net_stats))
704 obj->data.net = get_net_stat(arg, obj, free_at_crash);
706 // default to DEFAULTNETDEV
707 char *buf = strndup(DEFAULTNETDEV, text_buffer_size);
708 obj->data.net = get_net_stat(buf, obj, free_at_crash);
712 END OBJ(downspeedgraph, CALLBACK(&update_net_stats))
714 SIZE_DEFAULTS(graph);
715 buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
716 &obj->e, &obj->char_a, &obj->char_b);
718 // default to DEFAULTNETDEV
719 buf = strndup(buf ? buf : DEFAULTNETDEV, text_buffer_size);
720 obj->data.net = get_net_stat(buf, obj, free_at_crash);
724 obj_be_ifblock_else(ifblock_opaque, obj);
726 obj_be_ifblock_endif(ifblock_opaque, obj);
728 obj->data.s = strndup(arg ? arg : "", text_buffer_size);
730 obj->data.s = strndup(arg ? arg : "", text_buffer_size);
732 obj->data.s = strndup(arg ? arg : "", text_buffer_size);
734 obj->data.s = strndup(arg ? arg : "", text_buffer_size);
737 obj->data.s = strndup(arg ? arg : "", text_buffer_size);
739 END OBJ(execgauge, 0)
740 SIZE_DEFAULTS(gauge);
741 obj->data.s = strndup(arg ? arg : "", text_buffer_size);
742 END OBJ(execgraph, 0)
743 SIZE_DEFAULTS(graph);
744 obj->data.s = strndup(arg ? arg : "", text_buffer_size);
750 if (!arg || sscanf(arg, "%f %n", &obj->data.execi.interval, &n) <= 0) {
753 NORM_ERR("${execibar <interval> command}");
754 obj->type = OBJ_text;
755 snprintf(buf, 256, "${%s}", s);
756 obj->data.s = strndup(buf, text_buffer_size);
758 obj->data.execi.cmd = strndup(arg + n, text_buffer_size);
761 END OBJ(execigraph, 0)
763 SIZE_DEFAULTS(graph);
765 if (!arg || sscanf(arg, "%f %n", &obj->data.execi.interval, &n) <= 0) {
768 NORM_ERR("${execigraph <interval> command}");
769 obj->type = OBJ_text;
770 snprintf(buf, 256, "${%s}", s);
771 obj->data.s = strndup(buf, text_buffer_size);
773 obj->data.execi.cmd = strndup(arg + n, text_buffer_size);
775 END OBJ(execigauge, 0)
777 SIZE_DEFAULTS(gauge);
779 if (!arg || sscanf(arg, "%f %n", &obj->data.execi.interval, &n) <= 0) {
782 NORM_ERR("${execigauge <interval> command}");
783 obj->type = OBJ_text;
784 snprintf(buf, 256, "${%s}", s);
785 obj->data.s = strndup(buf, text_buffer_size);
787 obj->data.execi.cmd = strndup(arg + n, text_buffer_size);
793 if (!arg || sscanf(arg, "%f %n", &obj->data.execi.interval, &n) <= 0) {
796 NORM_ERR("${execi <interval> command}");
797 obj->type = OBJ_text;
798 snprintf(buf, 256, "${%s}", s);
799 obj->data.s = strndup(buf, text_buffer_size);
801 obj->data.execi.cmd = strndup(arg + n, text_buffer_size);
802 obj->data.execi.buffer = malloc(text_buffer_size);
807 if (!arg || sscanf(arg, "%f %n", &obj->data.execi.interval, &n) <= 0) {
810 NORM_ERR("${execi <interval> command}");
811 obj->type = OBJ_text;
812 snprintf(buf, 256, "${%s}", s);
813 obj->data.s = strndup(buf, text_buffer_size);
815 obj->data.execi.cmd = strndup(arg + n, text_buffer_size);
816 obj->data.execi.buffer = malloc(text_buffer_size);
821 if (!arg || sscanf(arg, "%f %n", &obj->data.texeci.interval, &n) <= 0) {
824 NORM_ERR("${texeci <interval> command}");
825 obj->type = OBJ_text;
826 snprintf(buf, 256, "${%s}", s);
827 obj->data.s = strndup(buf, text_buffer_size);
829 obj->data.texeci.cmd = strndup(arg + n, text_buffer_size);
830 obj->data.texeci.buffer = malloc(text_buffer_size);
832 obj->data.texeci.p_timed_thread = NULL;
834 obj->type = OBJ_text;
838 do_read_exec(arg, buf, sizeof(buf));
839 obj->data.s = strndup(buf, text_buffer_size);
841 obj->data.s = strndup("", text_buffer_size);
843 END OBJ(fs_bar, CALLBACK(&update_fs_stats))
845 arg = scan_bar(arg, &obj->data.fsbar.w, &obj->data.fsbar.h);
847 while (isspace(*arg)) {
856 obj->data.fsbar.fs = prepare_fs_stat(arg);
857 END OBJ(fs_bar_free, CALLBACK(&update_fs_stats))
859 arg = scan_bar(arg, &obj->data.fsbar.w, &obj->data.fsbar.h);
861 while (isspace(*arg)) {
871 obj->data.fsbar.fs = prepare_fs_stat(arg);
872 END OBJ(fs_free, CALLBACK(&update_fs_stats))
876 obj->data.fs = prepare_fs_stat(arg);
877 END OBJ(fs_used_perc, CALLBACK(&update_fs_stats))
881 obj->data.fs = prepare_fs_stat(arg);
882 END OBJ(fs_free_perc, CALLBACK(&update_fs_stats))
886 obj->data.fs = prepare_fs_stat(arg);
887 END OBJ(fs_size, CALLBACK(&update_fs_stats))
891 obj->data.fs = prepare_fs_stat(arg);
892 END OBJ(fs_type, CALLBACK(&update_fs_stats))
896 obj->data.fs = prepare_fs_stat(arg);
897 END OBJ(fs_used, CALLBACK(&update_fs_stats))
901 obj->data.fs = prepare_fs_stat(arg);
903 obj->data.i = arg ? atoi(arg) : 1;
904 END OBJ(nameserver, CALLBACK(&update_dns_data))
905 obj->data.i = arg ? atoi(arg) : 0;
907 obj->data.i = arg ? atoi(arg) : 1;
909 obj->data.i = arg ? atoi(arg) : 1;
913 NORM_ERR("goto needs arguments");
914 obj->type = OBJ_text;
915 obj->data.s = strndup("${goto}", text_buffer_size);
919 obj->data.i = atoi(arg);
925 if (sscanf(arg, "%d %d", &a, &b) != 2) {
926 sscanf(arg, "%d", &b);
932 obj->data.pair.a = a;
933 obj->data.pair.b = b;
937 char buf1[64], buf2[64];
938 float factor, offset;
942 NORM_ERR("i2c needs arguments");
943 obj->type = OBJ_text;
944 // obj->data.s = strndup("${i2c}", text_buffer_size);
948 #define HWMON_RESET() {\
953 if (sscanf(arg, "%63s %d %f %f", buf2, &n, &factor, &offset) == 4) found = 1; else HWMON_RESET();
954 if (!found && sscanf(arg, "%63s %63s %d %f %f", buf1, buf2, &n, &factor, &offset) == 5) found = 1; else if (!found) HWMON_RESET();
955 if (!found && sscanf(arg, "%63s %63s %d", buf1, buf2, &n) == 3) found = 1; else if (!found) HWMON_RESET();
956 if (!found && sscanf(arg, "%63s %d", buf2, &n) == 2) found = 1; else if (!found) HWMON_RESET();
959 NORM_ERR("i2c failed to parse arguments");
960 obj->type = OBJ_text;
963 DBGP("parsed i2c args: '%s' '%s' %d %f %f\n", buf1, buf2, n, factor, offset);
964 obj->data.sysfs.fd = open_i2c_sensor((*buf1) ? buf1 : 0, buf2, n,
965 &obj->data.sysfs.arg, obj->data.sysfs.devtype);
966 strncpy(obj->data.sysfs.type, buf2, 63);
967 obj->data.sysfs.factor = factor;
968 obj->data.sysfs.offset = offset;
971 char buf1[64], buf2[64];
972 float factor, offset;
976 NORM_ERR("platform needs arguments");
977 obj->type = OBJ_text;
981 if (sscanf(arg, "%63s %d %f %f", buf2, &n, &factor, &offset) == 4) found = 1; else HWMON_RESET();
982 if (!found && sscanf(arg, "%63s %63s %d %f %f", buf1, buf2, &n, &factor, &offset) == 5) found = 1; else if (!found) HWMON_RESET();
983 if (!found && sscanf(arg, "%63s %63s %d", buf1, buf2, &n) == 3) found = 1; else if (!found) HWMON_RESET();
984 if (!found && sscanf(arg, "%63s %d", buf2, &n) == 2) found = 1; else if (!found) HWMON_RESET();
987 NORM_ERR("platform failed to parse arguments");
988 obj->type = OBJ_text;
991 DBGP("parsed platform args: '%s' '%s' %d %f %f", buf1, buf2, n, factor, offset);
992 obj->data.sysfs.fd = open_platform_sensor((*buf1) ? buf1 : 0, buf2, n,
993 &obj->data.sysfs.arg, obj->data.sysfs.devtype);
994 strncpy(obj->data.sysfs.type, buf2, 63);
995 obj->data.sysfs.factor = factor;
996 obj->data.sysfs.offset = offset;
999 char buf1[64], buf2[64];
1000 float factor, offset;
1004 NORM_ERR("hwmon needs argumanets");
1005 obj->type = OBJ_text;
1009 if (sscanf(arg, "%63s %d %f %f", buf2, &n, &factor, &offset) == 4) found = 1; else HWMON_RESET();
1010 if (!found && sscanf(arg, "%63s %63s %d %f %f", buf1, buf2, &n, &factor, &offset) == 5) found = 1; else if (!found) HWMON_RESET();
1011 if (!found && sscanf(arg, "%63s %63s %d", buf1, buf2, &n) == 3) found = 1; else if (!found) HWMON_RESET();
1012 if (!found && sscanf(arg, "%63s %d", buf2, &n) == 2) found = 1; else if (!found) HWMON_RESET();
1017 NORM_ERR("hwmon failed to parse arguments");
1018 obj->type = OBJ_text;
1021 DBGP("parsed hwmon args: '%s' '%s' %d %f %f\n", buf1, buf2, n, factor, offset);
1022 obj->data.sysfs.fd = open_hwmon_sensor((*buf1) ? buf1 : 0, buf2, n,
1023 &obj->data.sysfs.arg, obj->data.sysfs.devtype);
1024 strncpy(obj->data.sysfs.type, buf2, 63);
1025 obj->data.sysfs.factor = factor;
1026 obj->data.sysfs.offset = offset;
1028 #endif /* !__OpenBSD__ */
1031 /* we have four different types of top (top, top_mem, top_time and top_io). To
1032 * avoid having almost-same code four times, we have this special
1034 if (strncmp(s, "top", 3) == EQUAL) {
1035 add_update_callback(&update_meminfo);
1036 if (!parse_top_args(s, arg, obj)) {
1039 } else OBJ(addr, CALLBACK(&update_net_stats))
1041 obj->data.net = get_net_stat(arg, obj, free_at_crash);
1043 // default to DEFAULTNETDEV
1044 char *buf = strndup(DEFAULTNETDEV, text_buffer_size);
1045 obj->data.net = get_net_stat(buf, obj, free_at_crash);
1048 #if defined(__linux__)
1049 END OBJ(addrs, CALLBACK(&update_net_stats))
1051 obj->data.net = get_net_stat(arg, obj, free_at_crash);
1053 // default to DEFAULTNETDEV
1054 char *buf = strndup(DEFAULTNETDEV, text_buffer_size);
1055 obj->data.net = get_net_stat(buf, obj, free_at_crash);
1058 #endif /* __linux__ */
1060 init_tailhead("tail", arg, obj, free_at_crash);
1062 init_tailhead("head", arg, obj, free_at_crash);
1065 obj->data.s = strndup(arg, text_buffer_size);
1067 CRIT_ERR(obj, free_at_crash, "lines needs a argument");
1071 obj->data.s = strndup(arg, text_buffer_size);
1073 CRIT_ERR(obj, free_at_crash, "words needs a argument");
1075 END OBJ(loadavg, CALLBACK(&update_load_average))
1076 int a = 1, b = 2, c = 3, r = 3;
1079 r = sscanf(arg, "%d %d %d", &a, &b, &c);
1080 if (r >= 3 && (c < 1 || c > 3)) {
1083 if (r >= 2 && (b < 1 || b > 3)) {
1086 if (r >= 1 && (a < 1 || a > 3)) {
1090 obj->data.loadavg[0] = (r >= 1) ? (unsigned char) a : 0;
1091 obj->data.loadavg[1] = (r >= 2) ? (unsigned char) b : 0;
1092 obj->data.loadavg[2] = (r >= 3) ? (unsigned char) c : 0;
1093 END OBJ_IF(if_empty, 0)
1095 NORM_ERR("if_empty needs an argument");
1096 obj->data.ifblock.s = 0;
1098 obj->data.ifblock.s = strndup(arg, text_buffer_size);
1099 obj->sub = malloc(sizeof(struct text_object));
1100 extract_variable_text_internal(obj->sub,
1101 obj->data.ifblock.s);
1103 END OBJ_IF(if_match, 0)
1105 NORM_ERR("if_match needs arguments");
1106 obj->data.ifblock.s = 0;
1108 obj->data.ifblock.s = strndup(arg, text_buffer_size);
1109 obj->sub = malloc(sizeof(struct text_object));
1110 extract_variable_text_internal(obj->sub,
1111 obj->data.ifblock.s);
1113 END OBJ_IF(if_existing, 0)
1115 NORM_ERR("if_existing needs an argument or two");
1116 obj->data.ifblock.s = NULL;
1117 obj->data.ifblock.str = NULL;
1119 char buf1[256], buf2[256];
1120 int r = sscanf(arg, "%255s %255[^\n]", buf1, buf2);
1123 obj->data.ifblock.s = strndup(buf1, text_buffer_size);
1124 obj->data.ifblock.str = NULL;
1126 obj->data.ifblock.s = strndup(buf1, text_buffer_size);
1127 obj->data.ifblock.str = strndup(buf2, text_buffer_size);
1130 DBGP("if_existing: '%s' '%s'", obj->data.ifblock.s, obj->data.ifblock.str);
1131 END OBJ_IF(if_mounted, 0)
1133 NORM_ERR("if_mounted needs an argument");
1134 obj->data.ifblock.s = 0;
1136 obj->data.ifblock.s = strndup(arg, text_buffer_size);
1139 END OBJ_IF(if_running, CALLBACK(&update_top))
1142 obj->data.ifblock.s = strndup(arg, text_buffer_size);
1144 END OBJ_IF(if_running, 0)
1148 snprintf(buf, 256, "pidof %s >/dev/null", arg);
1149 obj->data.ifblock.s = strndup(buf, text_buffer_size);
1152 NORM_ERR("if_running needs an argument");
1153 obj->data.ifblock.s = 0;
1159 char mbox[256], dst[256];
1163 /* Kapil: Changed from MAIL_FILE to
1164 current_mail_spool since the latter
1165 is a copy of the former if undefined
1166 but the latter should take precedence
1168 strncpy(mbox, current_mail_spool, sizeof(mbox));
1170 if (sscanf(arg, "%s %f", mbox, &n1) != 2) {
1172 strncpy(mbox, arg, sizeof(mbox));
1176 variable_substitute(mbox, dst, sizeof(dst));
1177 obj->data.local_mail.mbox = strndup(dst, text_buffer_size);
1178 obj->data.local_mail.interval = n1;
1179 END OBJ(new_mails, 0)
1181 char mbox[256], dst[256];
1185 strncpy(mbox, current_mail_spool, sizeof(mbox));
1187 if (sscanf(arg, "%s %f", mbox, &n1) != 2) {
1189 strncpy(mbox, arg, sizeof(mbox));
1193 variable_substitute(mbox, dst, sizeof(dst));
1194 obj->data.local_mail.mbox = strndup(dst, text_buffer_size);
1195 obj->data.local_mail.interval = n1;
1196 END OBJ(seen_mails, 0)
1198 char mbox[256], dst[256];
1202 strncpy(mbox, current_mail_spool, sizeof(mbox));
1204 if (sscanf(arg, "%s %f", mbox, &n1) != 2) {
1206 strncpy(mbox, arg, sizeof(mbox));
1210 variable_substitute(mbox, dst, sizeof(dst));
1211 obj->data.local_mail.mbox = strndup(dst, text_buffer_size);
1212 obj->data.local_mail.interval = n1;
1213 END OBJ(unseen_mails, 0)
1215 char mbox[256], dst[256];
1219 strncpy(mbox, current_mail_spool, sizeof(mbox));
1221 if (sscanf(arg, "%s %f", mbox, &n1) != 2) {
1223 strncpy(mbox, arg, sizeof(mbox));
1227 variable_substitute(mbox, dst, sizeof(dst));
1228 obj->data.local_mail.mbox = strndup(dst, text_buffer_size);
1229 obj->data.local_mail.interval = n1;
1230 END OBJ(flagged_mails, 0)
1232 char mbox[256], dst[256];
1236 strncpy(mbox, current_mail_spool, sizeof(mbox));
1238 if (sscanf(arg, "%s %f", mbox, &n1) != 2) {
1240 strncpy(mbox, arg, sizeof(mbox));
1244 variable_substitute(mbox, dst, sizeof(dst));
1245 obj->data.local_mail.mbox = strndup(dst, text_buffer_size);
1246 obj->data.local_mail.interval = n1;
1247 END OBJ(unflagged_mails, 0)
1249 char mbox[256], dst[256];
1253 strncpy(mbox, current_mail_spool, sizeof(mbox));
1255 if (sscanf(arg, "%s %f", mbox, &n1) != 2) {
1257 strncpy(mbox, arg, sizeof(mbox));
1261 variable_substitute(mbox, dst, sizeof(dst));
1262 obj->data.local_mail.mbox = strndup(dst, text_buffer_size);
1263 obj->data.local_mail.interval = n1;
1264 END OBJ(forwarded_mails, 0)
1266 char mbox[256], dst[256];
1270 strncpy(mbox, current_mail_spool, sizeof(mbox));
1272 if (sscanf(arg, "%s %f", mbox, &n1) != 2) {
1274 strncpy(mbox, arg, sizeof(mbox));
1278 variable_substitute(mbox, dst, sizeof(dst));
1279 obj->data.local_mail.mbox = strndup(dst, text_buffer_size);
1280 obj->data.local_mail.interval = n1;
1281 END OBJ(unforwarded_mails, 0)
1283 char mbox[256], dst[256];
1287 strncpy(mbox, current_mail_spool, sizeof(mbox));
1289 if (sscanf(arg, "%s %f", mbox, &n1) != 2) {
1291 strncpy(mbox, arg, sizeof(mbox));
1295 variable_substitute(mbox, dst, sizeof(dst));
1296 obj->data.local_mail.mbox = strndup(dst, text_buffer_size);
1297 obj->data.local_mail.interval = n1;
1298 END OBJ(replied_mails, 0)
1300 char mbox[256], dst[256];
1304 strncpy(mbox, current_mail_spool, sizeof(mbox));
1306 if (sscanf(arg, "%s %f", mbox, &n1) != 2) {
1308 strncpy(mbox, arg, sizeof(mbox));
1312 variable_substitute(mbox, dst, sizeof(dst));
1313 obj->data.local_mail.mbox = strndup(dst, text_buffer_size);
1314 obj->data.local_mail.interval = n1;
1315 END OBJ(unreplied_mails, 0)
1317 char mbox[256], dst[256];
1321 strncpy(mbox, current_mail_spool, sizeof(mbox));
1323 if (sscanf(arg, "%s %f", mbox, &n1) != 2) {
1325 strncpy(mbox, arg, sizeof(mbox));
1329 variable_substitute(mbox, dst, sizeof(dst));
1330 obj->data.local_mail.mbox = strndup(dst, text_buffer_size);
1331 obj->data.local_mail.interval = n1;
1332 END OBJ(draft_mails, 0)
1334 char mbox[256], dst[256];
1338 strncpy(mbox, current_mail_spool, sizeof(mbox));
1340 if (sscanf(arg, "%s %f", mbox, &n1) != 2) {
1342 strncpy(mbox, arg, sizeof(mbox));
1346 variable_substitute(mbox, dst, sizeof(dst));
1347 obj->data.local_mail.mbox = strndup(dst, text_buffer_size);
1348 obj->data.local_mail.interval = n1;
1349 END OBJ(trashed_mails, 0)
1351 char mbox[256], dst[256];
1355 strncpy(mbox, current_mail_spool, sizeof(mbox));
1357 if (sscanf(arg, "%s %f", mbox, &n1) != 2) {
1359 strncpy(mbox, arg, sizeof(mbox));
1363 variable_substitute(mbox, dst, sizeof(dst));
1364 obj->data.local_mail.mbox = strndup(dst, text_buffer_size);
1365 obj->data.local_mail.interval = n1;
1366 END OBJ(mboxscan, 0)
1367 obj->data.mboxscan.args = (char *) malloc(text_buffer_size);
1368 obj->data.mboxscan.output = (char *) malloc(text_buffer_size);
1369 /* if '1' (in mboxscan.c) then there was SIGUSR1, hmm */
1370 obj->data.mboxscan.output[0] = 1;
1371 strncpy(obj->data.mboxscan.args, arg, text_buffer_size);
1372 END OBJ(mem, CALLBACK(&update_meminfo))
1373 END OBJ(memeasyfree, CALLBACK(&update_meminfo))
1374 END OBJ(memfree, CALLBACK(&update_meminfo))
1375 END OBJ(memmax, CALLBACK(&update_meminfo))
1376 END OBJ(memperc, CALLBACK(&update_meminfo))
1378 END OBJ(memgauge, CALLBACK(&update_meminfo))
1379 SIZE_DEFAULTS(gauge);
1380 scan_gauge(arg, &obj->data.pair.a, &obj->data.pair.b);
1382 END OBJ(membar, CALLBACK(&update_meminfo))
1384 scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
1386 END OBJ(memgraph, CALLBACK(&update_meminfo))
1388 SIZE_DEFAULTS(graph);
1389 buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
1390 &obj->e, &obj->char_a, &obj->char_b);
1395 obj->data.l = mixer_init(arg);
1397 obj->data.l = mixer_init(arg);
1399 obj->data.l = mixer_init(arg);
1401 END OBJ(mixerbar, 0)
1403 scan_mixer_bar(arg, &obj->data.mixerbar.l, &obj->data.mixerbar.w,
1404 &obj->data.mixerbar.h);
1405 END OBJ(mixerlbar, 0)
1407 scan_mixer_bar(arg, &obj->data.mixerbar.l, &obj->data.mixerbar.w,
1408 &obj->data.mixerbar.h);
1409 END OBJ(mixerrbar, 0)
1411 scan_mixer_bar(arg, &obj->data.mixerbar.l, &obj->data.mixerbar.w,
1412 &obj->data.mixerbar.h);
1414 END OBJ_IF(if_mixer_mute, 0)
1415 obj->data.ifblock.i = mixer_init(arg);
1417 END OBJ(monitor, CALLBACK(&update_x11info))
1418 END OBJ(monitor_number, CALLBACK(&update_x11info))
1419 END OBJ(desktop, CALLBACK(&update_x11info))
1420 END OBJ(desktop_number, CALLBACK(&update_x11info))
1421 END OBJ(desktop_name, CALLBACK(&update_x11info))
1423 END OBJ(nodename, 0)
1424 END OBJ(processes, CALLBACK(&update_total_processes))
1425 END OBJ(running_processes, CALLBACK(&update_running_processes))
1426 END OBJ(shadecolor, 0)
1428 obj->data.l = arg ? get_x11_color(arg) : default_bg_color;
1430 END OBJ(outlinecolor, 0)
1432 obj->data.l = arg ? get_x11_color(arg) : default_out_color;
1434 END OBJ(stippled_hr, 0)
1436 int a = get_stippled_borders(), b = 1;
1439 if (sscanf(arg, "%d %d", &a, &b) != 2) {
1440 sscanf(arg, "%d", &b);
1446 obj->data.pair.a = a;
1447 obj->data.pair.b = b;
1449 END OBJ(swap, CALLBACK(&update_meminfo))
1450 END OBJ(swapfree, CALLBACK(&update_meminfo))
1451 END OBJ(swapmax, CALLBACK(&update_meminfo))
1452 END OBJ(swapperc, CALLBACK(&update_meminfo))
1453 END OBJ(swapbar, CALLBACK(&update_meminfo))
1455 scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
1458 obj->data.s = strndup(arg ? arg : "%F %T", text_buffer_size);
1460 obj->data.s = strndup(arg ? arg : "%F %T", text_buffer_size);
1462 char buf1[256], buf2[256], *fmt, *tz;
1466 int nArgs = sscanf(arg, "%255s %255[^\n]", buf1, buf2);
1476 obj->data.tztime.fmt = strndup(fmt ? fmt : "%F %T", text_buffer_size);
1477 obj->data.tztime.tz = tz ? strndup(tz, text_buffer_size) : NULL;
1479 END OBJ(iconv_start, 0)
1480 if (is_iconv_converting()) {
1481 CRIT_ERR(obj, free_at_crash, "You must stop your last iconv conversion before "
1482 "starting another");
1485 char iconv_from[ICONV_CODEPAGE_LENGTH];
1486 char iconv_to[ICONV_CODEPAGE_LENGTH];
1488 if (sscanf(arg, "%s %s", iconv_from, iconv_to) != 2) {
1489 CRIT_ERR(obj, free_at_crash, "Invalid arguments for iconv_start");
1493 new_iconv = iconv_open(iconv_to, iconv_from);
1494 if (new_iconv == (iconv_t) (-1)) {
1495 NORM_ERR("Can't convert from %s to %s.", iconv_from, iconv_to);
1497 obj->a = register_iconv(&new_iconv);
1498 set_iconv_converting(1);
1502 CRIT_ERR(obj, free_at_crash, "Iconv requires arguments");
1504 END OBJ(iconv_stop, 0)
1505 set_iconv_converting(0);
1508 END OBJ(totaldown, CALLBACK(&update_net_stats))
1510 obj->data.net = get_net_stat(arg, obj, free_at_crash);
1512 // default to DEFAULTNETDEV
1513 char *buf = strndup(DEFAULTNETDEV, text_buffer_size);
1514 obj->data.net = get_net_stat(buf, obj, free_at_crash);
1517 END OBJ(totalup, CALLBACK(&update_net_stats))
1518 obj->data.net = get_net_stat(arg, obj, free_at_crash);
1520 obj->data.net = get_net_stat(arg, obj, free_at_crash);
1522 // default to DEFAULTNETDEV
1523 char *buf = strndup(DEFAULTNETDEV, text_buffer_size);
1524 obj->data.net = get_net_stat(buf, obj, free_at_crash);
1528 END OBJ_IF(if_updatenr, 0)
1529 obj->data.ifblock.i = arg ? atoi(arg) : 0;
1530 if(obj->data.ifblock.i == 0) CRIT_ERR(obj, free_at_crash, "if_updatenr needs a number above 0 as argument");
1531 set_updatereset(obj->data.ifblock.i > get_updatereset() ? obj->data.ifblock.i : get_updatereset());
1533 obj->data.i = arg ? atoi(arg) : 0;
1535 obj->data.i = arg ? atoi(arg) : 0;
1536 END OBJ(upspeed, CALLBACK(&update_net_stats))
1538 obj->data.net = get_net_stat(arg, obj, free_at_crash);
1540 // default to DEFAULTNETDEV
1541 char *buf = strndup(DEFAULTNETDEV, text_buffer_size);
1542 obj->data.net = get_net_stat(buf, obj, free_at_crash);
1545 END OBJ(upspeedf, CALLBACK(&update_net_stats))
1547 obj->data.net = get_net_stat(arg, obj, free_at_crash);
1549 // default to DEFAULTNETDEV
1550 char *buf = strndup(DEFAULTNETDEV, text_buffer_size);
1551 obj->data.net = get_net_stat(buf, obj, free_at_crash);
1556 END OBJ(upspeedgraph, CALLBACK(&update_net_stats))
1558 SIZE_DEFAULTS(graph);
1559 buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
1560 &obj->e, &obj->char_a, &obj->char_b);
1562 // default to DEFAULTNETDEV
1563 buf = strndup(buf ? buf : DEFAULTNETDEV, text_buffer_size);
1564 obj->data.net = get_net_stat(buf, obj, free_at_crash);
1567 END OBJ(uptime_short, CALLBACK(&update_uptime))
1568 END OBJ(uptime, CALLBACK(&update_uptime))
1569 END OBJ(user_names, CALLBACK(&update_users))
1570 END OBJ(user_times, CALLBACK(&update_users))
1571 END OBJ(user_terms, CALLBACK(&update_users))
1572 END OBJ(user_number, CALLBACK(&update_users))
1573 #if defined(__linux__)
1574 END OBJ(gw_iface, CALLBACK(&update_gateway_info))
1575 END OBJ(gw_ip, CALLBACK(&update_gateway_info))
1576 #endif /* !__linux__ */
1578 END OBJ(adt746xcpu, 0)
1579 END OBJ(adt746xfan, 0)
1580 #endif /* !__OpenBSD__ */
1581 #if (defined(__FreeBSD__) || defined(__FreeBSD_kernel__) \
1582 || defined(__OpenBSD__)) && (defined(i386) || defined(__i386__))
1583 END OBJ(apm_adapter, 0)
1584 END OBJ(apm_battery_life, 0)
1585 END OBJ(apm_battery_time, 0)
1586 #endif /* __FreeBSD__ */
1587 END OBJ(imap_unseen, 0)
1590 obj->data.mail = parse_mail_args(IMAP_TYPE, arg);
1595 END OBJ(imap_messages, 0)
1598 obj->data.mail = parse_mail_args(IMAP_TYPE, arg);
1603 END OBJ(pop3_unseen, 0)
1606 obj->data.mail = parse_mail_args(POP3_TYPE, arg);
1611 END OBJ(pop3_used, 0)
1614 obj->data.mail = parse_mail_args(POP3_TYPE, arg);
1622 obj->data.s = strndup(arg, text_buffer_size);
1624 NORM_ERR("smapi needs an argument");
1625 END OBJ_IF(if_smapi_bat_installed, 0)
1627 NORM_ERR("if_smapi_bat_installed needs an argument");
1628 obj->data.ifblock.s = 0;
1630 obj->data.ifblock.s = strndup(arg, text_buffer_size);
1631 END OBJ(smapi_bat_perc, 0)
1633 obj->data.s = strndup(arg, text_buffer_size);
1635 NORM_ERR("smapi_bat_perc needs an argument");
1636 END OBJ(smapi_bat_temp, 0)
1638 obj->data.s = strndup(arg, text_buffer_size);
1640 NORM_ERR("smapi_bat_temp needs an argument");
1641 END OBJ(smapi_bat_power, 0)
1643 obj->data.s = strndup(arg, text_buffer_size);
1645 NORM_ERR("smapi_bat_power needs an argument");
1647 END OBJ(smapi_bat_bar, 0)
1651 if(sscanf(arg, "%i %n", &obj->data.i, &cnt) <= 0) {
1652 NORM_ERR("first argument to smapi_bat_bar must be an integer value");
1656 arg = scan_bar(arg + cnt, &obj->a, &obj->b);
1659 NORM_ERR("smapi_bat_bar needs an argument");
1663 #define mpd_set_maxlen(name) \
1666 sscanf(arg, "%d", &i); \
1668 obj->data.i = i + 1; \
1670 NORM_ERR(#name ": invalid length argument"); \
1672 END OBJ(mpd_artist, CALLBACK(&update_mpd))
1673 mpd_set_maxlen(mpd_artist);
1675 END OBJ(mpd_title, CALLBACK(&update_mpd))
1676 mpd_set_maxlen(mpd_title);
1678 END OBJ(mpd_random, CALLBACK(&update_mpd)) init_mpd();
1679 END OBJ(mpd_repeat, CALLBACK(&update_mpd)) init_mpd();
1680 END OBJ(mpd_elapsed, CALLBACK(&update_mpd)) init_mpd();
1681 END OBJ(mpd_length, CALLBACK(&update_mpd)) init_mpd();
1682 END OBJ(mpd_track, CALLBACK(&update_mpd))
1683 mpd_set_maxlen(mpd_track);
1685 END OBJ(mpd_name, CALLBACK(&update_mpd))
1686 mpd_set_maxlen(mpd_name);
1688 END OBJ(mpd_file, CALLBACK(&update_mpd))
1689 mpd_set_maxlen(mpd_file);
1691 END OBJ(mpd_percent, CALLBACK(&update_mpd)) init_mpd();
1692 END OBJ(mpd_album, CALLBACK(&update_mpd))
1693 mpd_set_maxlen(mpd_album);
1695 END OBJ(mpd_vol, CALLBACK(&update_mpd)) init_mpd();
1696 END OBJ(mpd_bitrate, CALLBACK(&update_mpd)) init_mpd();
1697 END OBJ(mpd_status, CALLBACK(&update_mpd)) init_mpd();
1698 END OBJ(mpd_bar, CALLBACK(&update_mpd))
1700 scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
1702 END OBJ(mpd_smart, CALLBACK(&update_mpd))
1703 mpd_set_maxlen(mpd_smart);
1705 END OBJ_IF(if_mpd_playing, CALLBACK(&update_mpd))
1707 #undef mpd_set_maxlen
1710 END OBJ(moc_state, CALLBACK(&update_moc))
1711 END OBJ(moc_file, CALLBACK(&update_moc))
1712 END OBJ(moc_title, CALLBACK(&update_moc))
1713 END OBJ(moc_artist, CALLBACK(&update_moc))
1714 END OBJ(moc_song, CALLBACK(&update_moc))
1715 END OBJ(moc_album, CALLBACK(&update_moc))
1716 END OBJ(moc_totaltime, CALLBACK(&update_moc))
1717 END OBJ(moc_timeleft, CALLBACK(&update_moc))
1718 END OBJ(moc_curtime, CALLBACK(&update_moc))
1719 END OBJ(moc_bitrate, CALLBACK(&update_moc))
1720 END OBJ(moc_rate, CALLBACK(&update_moc))
1723 END OBJ(xmms2_artist, CALLBACK(&update_xmms2))
1724 END OBJ(xmms2_album, CALLBACK(&update_xmms2))
1725 END OBJ(xmms2_title, CALLBACK(&update_xmms2))
1726 END OBJ(xmms2_genre, CALLBACK(&update_xmms2))
1727 END OBJ(xmms2_comment, CALLBACK(&update_xmms2))
1728 END OBJ(xmms2_url, CALLBACK(&update_xmms2))
1729 END OBJ(xmms2_tracknr, CALLBACK(&update_xmms2))
1730 END OBJ(xmms2_bitrate, CALLBACK(&update_xmms2))
1731 END OBJ(xmms2_date, CALLBACK(&update_xmms2))
1732 END OBJ(xmms2_id, CALLBACK(&update_xmms2))
1733 END OBJ(xmms2_duration, CALLBACK(&update_xmms2))
1734 END OBJ(xmms2_elapsed, CALLBACK(&update_xmms2))
1735 END OBJ(xmms2_size, CALLBACK(&update_xmms2))
1736 END OBJ(xmms2_status, CALLBACK(&update_xmms2))
1737 END OBJ(xmms2_percent, CALLBACK(&update_xmms2))
1739 END OBJ(xmms2_bar, CALLBACK(&update_xmms2))
1741 scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
1743 END OBJ(xmms2_smart, CALLBACK(&update_xmms2))
1744 END OBJ(xmms2_playlist, CALLBACK(&update_xmms2))
1745 END OBJ(xmms2_timesplayed, CALLBACK(&update_xmms2))
1746 END OBJ_IF(if_xmms2_connected, CALLBACK(&update_xmms2))
1749 END OBJ(audacious_status, CALLBACK(&update_audacious))
1750 END OBJ(audacious_title, CALLBACK(&update_audacious))
1752 sscanf(arg, "%d", &info.audacious.max_title_len);
1753 if (info.audacious.max_title_len > 0) {
1754 info.audacious.max_title_len++;
1756 CRIT_ERR(obj, free_at_crash, "audacious_title: invalid length argument");
1759 END OBJ(audacious_length, CALLBACK(&update_audacious))
1760 END OBJ(audacious_length_seconds, CALLBACK(&update_audacious))
1761 END OBJ(audacious_position, CALLBACK(&update_audacious))
1762 END OBJ(audacious_position_seconds, CALLBACK(&update_audacious))
1763 END OBJ(audacious_bitrate, CALLBACK(&update_audacious))
1764 END OBJ(audacious_frequency, CALLBACK(&update_audacious))
1765 END OBJ(audacious_channels, CALLBACK(&update_audacious))
1766 END OBJ(audacious_filename, CALLBACK(&update_audacious))
1767 END OBJ(audacious_playlist_length, CALLBACK(&update_audacious))
1768 END OBJ(audacious_playlist_position, CALLBACK(&update_audacious))
1769 END OBJ(audacious_main_volume, CALLBACK(&update_audacious))
1771 END OBJ(audacious_bar, CALLBACK(&update_audacious))
1773 scan_bar(arg, &obj->a, &obj->b);
1777 END OBJ(bmpx_title, CALLBACK(&update_bmpx))
1778 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
1779 END OBJ(bmpx_artist, CALLBACK(&update_bmpx))
1780 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
1781 END OBJ(bmpx_album, CALLBACK(&update_bmpx))
1782 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
1783 END OBJ(bmpx_track, CALLBACK(&update_bmpx))
1784 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
1785 END OBJ(bmpx_uri, CALLBACK(&update_bmpx))
1786 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
1787 END OBJ(bmpx_bitrate, CALLBACK(&update_bmpx))
1788 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
1794 char *userid = (char *) malloc(20 * sizeof(char));
1795 char *apikey = (char *) malloc(64 * sizeof(char));
1796 char *charid = (char *) malloc(20 * sizeof(char));
1798 argc = sscanf(arg, "%20s %64s %20s", userid, apikey, charid);
1799 obj->data.eve.charid = charid;
1800 obj->data.eve.userid = userid;
1801 obj->data.eve.apikey = apikey;
1805 CRIT_ERR(obj, free_at_crash, "eve needs arguments: <userid> <apikey> <characterid>");
1813 char *uri = (char *) malloc(128 * sizeof(char));
1815 argc = sscanf(arg, "%127s %f", uri, &interval);
1817 obj->data.curl.uri = uri;
1818 obj->data.curl.interval = interval > 0 ? interval * 60 : 15*60;
1820 NORM_ERR("wrong number of arguments for $curl");
1823 CRIT_ERR(obj, free_at_crash, "curl needs arguments: <uri> <interval in minutes>");
1830 int argc, act_par = 0;
1831 unsigned int nrspaces = 0;
1832 char *uri = (char *) malloc(128 * sizeof(char));
1833 char *action = (char *) malloc(64 * sizeof(char));
1835 argc = sscanf(arg, "%127s %f %63s %d %u", uri, &interval, action,
1836 &act_par, &nrspaces);
1838 obj->data.rss.uri = uri;
1839 obj->data.rss.interval = interval > 0 ? interval * 60 : 15*60;
1840 obj->data.rss.action = action;
1841 obj->data.rss.act_par = act_par;
1842 obj->data.rss.nrspaces = nrspaces;
1844 NORM_ERR("wrong number of arguments for $rss");
1847 CRIT_ERR(obj, free_at_crash, "rss needs arguments: <uri> <interval in minutes> <action> "
1848 "[act_par] [spaces in front]");
1856 char *locID = (char *) malloc(9 * sizeof(char));
1857 char *uri = (char *) malloc(128 * sizeof(char));
1858 char *data_type = (char *) malloc(32 * sizeof(char));
1860 argc = sscanf(arg, "%119s %8s %31s %f", uri, locID, data_type, &interval);
1863 if (process_weather_uri(uri, locID, 0)) {
1867 CRIT_ERR(obj, free_at_crash, \
1868 "could not recognize the weather uri");
1871 obj->data.weather.uri = uri;
1872 obj->data.weather.data_type = data_type;
1874 /* Limit the data retrieval interval to half hour min */
1875 if (interval < 30) {
1879 /* Convert to seconds */
1880 obj->data.weather.interval = interval * 60;
1883 DBGP("weather: fetching %s from %s every %d seconds", \
1884 data_type, uri, obj->data.weather.interval);
1889 CRIT_ERR(obj, free_at_crash, "wrong number of arguments for $weather");
1892 CRIT_ERR(obj, free_at_crash, "weather needs arguments: <uri> <locID> <data_type> [interval in minutes]");
1896 END OBJ(weather_forecast, 0)
1901 char *locID = (char *) malloc(9 * sizeof(char));
1902 char *uri = (char *) malloc(128 * sizeof(char));
1903 char *data_type = (char *) malloc(32 * sizeof(char));
1905 argc = sscanf(arg, "%119s %8s %1u %31s %f", uri, locID, &day, data_type, &interval);
1908 if (process_weather_uri(uri, locID, 1)) {
1912 CRIT_ERR(obj, free_at_crash, \
1913 "could not recognize the weather forecast uri");
1916 obj->data.weather_forecast.uri = uri;
1917 obj->data.weather_forecast.data_type = data_type;
1919 /* Limit the day between 0 (today) and FORECAST_DAYS */
1920 if (day >= FORECAST_DAYS) {
1921 day = FORECAST_DAYS-1;
1923 obj->data.weather_forecast.day = day;
1925 /* Limit the data retrieval interval to 3 hours and an half */
1926 if (interval < 210) {
1930 /* Convert to seconds */
1931 obj->data.weather_forecast.interval = interval * 60;
1934 DBGP("weather_forecast: fetching %s for day %d from %s every %d seconds", \
1935 data_type, day, uri, obj->data.weather_forecast.interval);
1940 CRIT_ERR(obj, free_at_crash, "wrong number of arguments for $weather_forecast");
1943 CRIT_ERR(obj, free_at_crash, "weather_forecast needs arguments: <uri> <locID> <day> <data_type> [interval in minutes]");
1949 obj->data.s = strndup(arg, text_buffer_size);
1951 CRIT_ERR(obj, free_at_crash, "lua needs arguments: <function name> [function parameters]");
1953 END OBJ(lua_parse, 0)
1955 obj->data.s = strndup(arg, text_buffer_size);
1957 CRIT_ERR(obj, free_at_crash, "lua_parse needs arguments: <function name> [function parameters]");
1962 arg = scan_bar(arg, &obj->a, &obj->b);
1964 obj->data.s = strndup(arg, text_buffer_size);
1966 CRIT_ERR(obj, free_at_crash, "lua_bar needs arguments: <height>,<width> <function name> [function parameters]");
1969 CRIT_ERR(obj, free_at_crash, "lua_bar needs arguments: <height>,<width> <function name> [function parameters]");
1972 END OBJ(lua_graph, 0)
1973 SIZE_DEFAULTS(graph);
1976 buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
1977 &obj->e, &obj->char_a, &obj->char_b);
1981 CRIT_ERR(obj, free_at_crash, "lua_graph needs arguments: <function name> [height],[width] [gradient colour 1] [gradient colour 2] [scale] [-t] [-l]");
1984 CRIT_ERR(obj, free_at_crash, "lua_graph needs arguments: <function name> [height],[width] [gradient colour 1] [gradient colour 2] [scale] [-t] [-l]");
1986 END OBJ(lua_gauge, 0)
1987 SIZE_DEFAULTS(gauge);
1989 arg = scan_gauge(arg, &obj->a, &obj->b);
1991 obj->data.s = strndup(arg, text_buffer_size);
1993 CRIT_ERR(obj, free_at_crash, "lua_gauge needs arguments: <height>,<width> <function name> [function parameters]");
1996 CRIT_ERR(obj, free_at_crash, "lua_gauge needs arguments: <height>,<width> <function name> [function parameters]");
1999 #endif /* HAVE_LUA */
2001 END OBJ(hddtemp, CALLBACK(&update_hddtemp))
2003 obj->data.s = strndup(arg, text_buffer_size);
2004 #endif /* HDDTEMP */
2005 #ifdef TCP_PORT_MONITOR
2006 END OBJ(tcp_portmon, CALLBACK(&tcp_portmon_update))
2007 tcp_portmon_init(arg, &obj->data.tcp_port_monitor);
2008 #endif /* TCP_PORT_MONITOR */
2009 END OBJ(entropy_avail, CALLBACK(&update_entropy))
2010 END OBJ(entropy_perc, CALLBACK(&update_entropy))
2011 END OBJ(entropy_poolsize, CALLBACK(&update_entropy))
2012 END OBJ(entropy_bar, CALLBACK(&update_entropy))
2014 scan_bar(arg, &obj->a, &obj->b);
2017 struct conftree *leaf = conftree_add(currentconffile, arg);
2019 if (load_config_file(arg) == TRUE) {
2020 obj->sub = malloc(sizeof(struct text_object));
2021 currentconffile = leaf;
2022 extract_variable_text_internal(obj->sub, get_global_text());
2023 currentconffile = leaf->back;
2025 NORM_ERR("Can't load configfile '%s'.", arg);
2028 NORM_ERR("You are trying to load '%s' recursively, I'm only going to load it once to prevent an infinite loop.", arg);
2031 CRIT_ERR(obj, free_at_crash, "include needs a argument");
2035 obj->sub = malloc(sizeof(struct text_object));
2036 extract_variable_text_internal(obj->sub, arg);
2038 CRIT_ERR(obj, free_at_crash, "blink needs a argument");
2040 END OBJ(to_bytes, 0)
2042 obj->sub = malloc(sizeof(struct text_object));
2043 extract_variable_text_internal(obj->sub, arg);
2045 CRIT_ERR(obj, free_at_crash, "to_bytes needs a argument");
2050 obj->data.scroll.resetcolor = get_current_text_color();
2051 obj->data.scroll.step = 1;
2052 if (arg && sscanf(arg, "%u %n", &obj->data.scroll.show, &n1) > 0) {
2053 sscanf(arg + n1, "%u %n", &obj->data.scroll.step, &n2);
2054 if (*(arg + n1 + n2)) {
2057 obj->data.scroll.step = 1;
2059 obj->data.scroll.text = malloc(strlen(arg + n1) + obj->data.scroll.show + 1);
2060 for(n2 = 0; (unsigned int) n2 < obj->data.scroll.show; n2++) {
2061 obj->data.scroll.text[n2] = ' ';
2063 obj->data.scroll.text[n2] = 0;
2064 strcat(obj->data.scroll.text, arg + n1);
2065 obj->data.scroll.start = 0;
2066 obj->sub = malloc(sizeof(struct text_object));
2067 extract_variable_text_internal(obj->sub,
2068 obj->data.scroll.text);
2070 CRIT_ERR(obj, free_at_crash, "scroll needs arguments: <length> [<step>] <text>");
2075 unsigned int indenting = 0; //vars can be used as args for other vars
2078 startvar[0] = endvar[0] = startvar[1] = endvar[1] = -1;
2080 for (i=0; arg[i] != 0 && j < 2; i++) {
2081 if(startvar[j] == -1) {
2085 }else if(endvar[j] == -1) {
2088 }else if(arg[i] == '}') {
2091 if (indenting == 0 && arg[i+1] < 48) { //<48 has 0, $, and the most used chars not used in varnames but not { or }
2097 if(startvar[0] >= 0 && endvar[0] >= 0 && startvar[1] >= 0 && endvar[1] >= 0) {
2098 obj->data.combine.left = malloc(endvar[0]-startvar[0] + 1);
2099 obj->data.combine.seperation = malloc(startvar[1] - endvar[0] + 1);
2100 obj->data.combine.right= malloc(endvar[1]-startvar[1] + 1);
2102 strncpy(obj->data.combine.left, arg + startvar[0], endvar[0] - startvar[0]);
2103 obj->data.combine.left[endvar[0] - startvar[0]] = 0;
2105 strncpy(obj->data.combine.seperation, arg + endvar[0], startvar[1] - endvar[0]);
2106 obj->data.combine.seperation[startvar[1] - endvar[0]] = 0;
2108 strncpy(obj->data.combine.right, arg + startvar[1], endvar[1] - startvar[1]);
2109 obj->data.combine.right[endvar[1] - startvar[1]] = 0;
2111 obj->sub = malloc(sizeof(struct text_object));
2112 extract_variable_text_internal(obj->sub, obj->data.combine.left);
2113 obj->sub->sub = malloc(sizeof(struct text_object));
2114 extract_variable_text_internal(obj->sub->sub, obj->data.combine.right);
2116 CRIT_ERR(obj, free_at_crash, "combine needs arguments: <text1> <text2>");
2119 CRIT_ERR(obj, free_at_crash, "combine needs arguments: <text1> <text2>");
2124 CRIT_ERR(obj, free_at_crash, "nvidia needs an argument\n");
2125 } else if (set_nvidia_type(&obj->data.nvidia, arg)) {
2126 CRIT_ERR(obj, free_at_crash, "nvidia: invalid argument"
2127 " specified: '%s'\n", arg);
2132 END OBJ(apcupsd, CALLBACK(&update_apcupsd))
2136 if (sscanf(arg, "%63s %d", host, &port) != 2) {
2137 CRIT_ERR(obj, free_at_crash, "apcupsd needs arguments: <host> <port>");
2139 info.apcupsd.port = htons(port);
2140 strncpy(info.apcupsd.host, host, sizeof(info.apcupsd.host));
2143 CRIT_ERR(obj, free_at_crash, "apcupsd needs arguments: <host> <port>");
2145 END OBJ(apcupsd_name, CALLBACK(&update_apcupsd))
2146 END OBJ(apcupsd_model, CALLBACK(&update_apcupsd))
2147 END OBJ(apcupsd_upsmode, CALLBACK(&update_apcupsd))
2148 END OBJ(apcupsd_cable, CALLBACK(&update_apcupsd))
2149 END OBJ(apcupsd_status, CALLBACK(&update_apcupsd))
2150 END OBJ(apcupsd_linev, CALLBACK(&update_apcupsd))
2151 END OBJ(apcupsd_load, CALLBACK(&update_apcupsd))
2152 END OBJ(apcupsd_loadbar, CALLBACK(&update_apcupsd))
2154 scan_bar(arg, &obj->a, &obj->b);
2156 END OBJ(apcupsd_loadgraph, CALLBACK(&update_apcupsd))
2158 SIZE_DEFAULTS(graph);
2159 buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
2160 &obj->e, &obj->char_a, &obj->char_b);
2162 END OBJ(apcupsd_loadgauge, CALLBACK(&update_apcupsd))
2163 SIZE_DEFAULTS(gauge);
2164 scan_gauge(arg, &obj->a, &obj->b);
2166 END OBJ(apcupsd_charge, CALLBACK(&update_apcupsd))
2167 END OBJ(apcupsd_timeleft, CALLBACK(&update_apcupsd))
2168 END OBJ(apcupsd_temp, CALLBACK(&update_apcupsd))
2169 END OBJ(apcupsd_lastxfer, CALLBACK(&update_apcupsd))
2170 #endif /* APCUPSD */
2174 NORM_ERR("unknown variable %s", s);
2175 obj->type = OBJ_text;
2176 snprintf(buf, 256, "${%s}", s);
2177 obj->data.s = strndup(buf, text_buffer_size);
2185 * - assumes that *string is '#'
2186 * - removes the part from '#' to the end of line ('\n' or '\0')
2187 * - it removes the '\n'
2188 * - copies the last char into 'char *last' argument, which should be a pointer
2189 * to a char rather than a string.
2191 static size_t remove_comment(char *string, char *last)
2194 while (*end != '\0' && *end != '\n') {
2197 if (last) *last = *end;
2198 if (*end == '\n') end++;
2199 strfold(string, end - string);
2200 return end - string;
2203 size_t remove_comments(char *string)
2207 for (curplace = string; *curplace != 0; curplace++) {
2208 if (*curplace == '\\' && *(curplace + 1) == '#') {
2209 // strcpy can't be used for overlapping strings
2210 strfold(curplace, 1);
2212 } else if (*curplace == '#') {
2213 folded += remove_comment(curplace, 0);
2219 int extract_variable_text_internal(struct text_object *retval, const char *const_p)
2221 struct text_object *obj;
2222 char *p, *s, *orig_p;
2224 void *ifblock_opaque = NULL;
2229 p = strndup(const_p, max_user_text - 1);
2230 while (text_contains_templates(p)) {
2232 tmp = find_and_replace_templates(p);
2238 if (strcmp(p, const_p)) {
2239 DBGP("replaced all templates in text: input is\n'%s'\noutput is\n'%s'", const_p, p);
2241 DBGP("no templates to replace");
2244 memset(retval, 0, sizeof(struct text_object));
2246 line = global_text_lines;
2254 obj = create_plain_text(s);
2256 append_object(retval, obj);
2266 /* variable is either $foo or ${foo} */
2268 unsigned int brl = 1, brr = 0;
2272 while (*p && brl != brr) {
2287 while (*p && (isalnum((int) *p) || *p == '_')) {
2292 /* copy variable to buffer */
2293 len = (p - s > 255) ? 255 : (p - s);
2294 strncpy(buf, s, len);
2302 /* search for variable in environment */
2306 obj = create_plain_text(var);
2308 append_object(retval, obj);
2313 /* if variable wasn't found in environment, use some special */
2318 if (strchr(buf, ' ')) {
2319 arg = strchr(buf, ' ');
2322 while (isspace((int) *arg)) {
2330 /* lowercase variable name */
2333 *tmp_p = tolower(*tmp_p);
2337 obj = construct_text_object(buf, arg,
2338 line, &ifblock_opaque, orig_p);
2340 append_object(retval, obj);
2344 obj = create_plain_text("$");
2347 append_object(retval, obj);
2350 } else if (*p == '\\' && *(p+1) == '#') {
2352 } else if (*p == '#') {
2354 if (remove_comment(p, &c) && p > orig_p && c == '\n') {
2355 /* if remove_comment removed a newline, we need to 'back up' with p */
2361 obj = create_plain_text(s);
2363 append_object(retval, obj);
2366 if (!ifblock_stack_empty(&ifblock_opaque)) {
2367 NORM_ERR("one or more $endif's are missing");
2375 * Frees the list of text objects root points to. When internal = 1, it won't
2376 * free global objects.
2378 void free_text_objects(struct text_object *root, int internal)
2380 struct text_object *obj;
2386 #define data obj->data
2387 for (obj = root->prev; obj; obj = root->prev) {
2388 root->prev = obj->prev;
2389 switch (obj->type) {
2394 #endif /* !__OpenBSD__ */
2399 close(data.sysfs.fd);
2401 #endif /* __linux__ */
2403 free(data.read_tcp.host);
2410 free(data.tztime.tz);
2411 free(data.tztime.fmt);
2414 free(data.mboxscan.args);
2415 free(data.mboxscan.output);
2419 case OBJ_seen_mails:
2420 case OBJ_unseen_mails:
2421 case OBJ_flagged_mails:
2422 case OBJ_unflagged_mails:
2423 case OBJ_forwarded_mails:
2424 case OBJ_unforwarded_mails:
2425 case OBJ_replied_mails:
2426 case OBJ_unreplied_mails:
2427 case OBJ_draft_mails:
2428 case OBJ_trashed_mails:
2429 free(data.local_mail.mbox);
2431 case OBJ_imap_unseen:
2436 case OBJ_imap_messages:
2441 case OBJ_pop3_unseen:
2453 free_text_objects(obj->sub, 1);
2456 case OBJ_if_existing:
2457 case OBJ_if_mounted:
2458 case OBJ_if_running:
2459 free(data.ifblock.s);
2460 free(data.ifblock.str);
2464 free(data.headtail.logfile);
2465 if(data.headtail.buffer) {
2466 free(data.headtail.buffer);
2483 case OBJ_iconv_start:
2488 case OBJ_disk_protect:
2492 free(data.ifblock.s);
2493 free(data.ifblock.str);
2496 if (info.gw_info.iface) {
2497 free(info.gw_info.iface);
2498 info.gw_info.iface = 0;
2500 if (info.gw_info.ip) {
2501 free(info.gw_info.ip);
2502 info.gw_info.ip = 0;
2505 case OBJ_ioscheduler:
2510 #if (defined(__FreeBSD__) || defined(__linux__))
2512 free(data.ifblock.s);
2513 free(data.ifblock.str);
2517 case OBJ_xmms2_artist:
2518 if (info.xmms2.artist) {
2519 free(info.xmms2.artist);
2520 info.xmms2.artist = 0;
2523 case OBJ_xmms2_album:
2524 if (info.xmms2.album) {
2525 free(info.xmms2.album);
2526 info.xmms2.album = 0;
2529 case OBJ_xmms2_title:
2530 if (info.xmms2.title) {
2531 free(info.xmms2.title);
2532 info.xmms2.title = 0;
2535 case OBJ_xmms2_genre:
2536 if (info.xmms2.genre) {
2537 free(info.xmms2.genre);
2538 info.xmms2.genre = 0;
2541 case OBJ_xmms2_comment:
2542 if (info.xmms2.comment) {
2543 free(info.xmms2.comment);
2544 info.xmms2.comment = 0;
2548 if (info.xmms2.url) {
2549 free(info.xmms2.url);
2553 case OBJ_xmms2_date:
2554 if (info.xmms2.date) {
2555 free(info.xmms2.date);
2556 info.xmms2.date = 0;
2559 case OBJ_xmms2_status:
2560 if (info.xmms2.status) {
2561 free(info.xmms2.status);
2562 info.xmms2.status = 0;
2565 case OBJ_xmms2_playlist:
2566 if (info.xmms2.playlist) {
2567 free(info.xmms2.playlist);
2568 info.xmms2.playlist = 0;
2571 case OBJ_xmms2_smart:
2572 if (info.xmms2.artist) {
2573 free(info.xmms2.artist);
2574 info.xmms2.artist = 0;
2576 if (info.xmms2.title) {
2577 free(info.xmms2.title);
2578 info.xmms2.title = 0;
2580 if (info.xmms2.url) {
2581 free(info.xmms2.url);
2587 case OBJ_bmpx_title:
2588 case OBJ_bmpx_artist:
2589 case OBJ_bmpx_album:
2590 case OBJ_bmpx_track:
2592 case OBJ_bmpx_bitrate:
2601 free(data.curl.uri);
2607 free(data.rss.action);
2612 free(data.weather.uri);
2613 free(data.weather.data_type);
2617 case OBJ_weather_forecast:
2618 free(data.weather_forecast.uri);
2619 free(data.weather_forecast.data_type);
2632 #endif /* HAVE_LUA */
2639 case OBJ_battery_short:
2642 case OBJ_battery_time:
2645 #endif /* !__OpenBSD__ */
2650 case OBJ_execigraph:
2651 case OBJ_execigauge:
2653 free(data.execi.cmd);
2654 free(data.execi.buffer);
2657 if (data.texeci.p_timed_thread) timed_thread_destroy(data.texeci.p_timed_thread, &data.texeci.p_timed_thread);
2658 free(data.texeci.cmd);
2659 free(data.texeci.buffer);
2661 case OBJ_nameserver:
2670 if (info.first_process && !internal) {
2671 free_all_processes();
2672 info.first_process = NULL;
2674 if (data.top.s) free(data.top.s);
2684 #endif /* HDDTEMP */
2685 case OBJ_entropy_avail:
2686 case OBJ_entropy_perc:
2687 case OBJ_entropy_poolsize:
2688 case OBJ_entropy_bar:
2690 case OBJ_user_names:
2691 if (info.users.names) {
2692 free(info.users.names);
2693 info.users.names = 0;
2696 case OBJ_user_terms:
2697 if (info.users.terms) {
2698 free(info.users.terms);
2699 info.users.terms = 0;
2702 case OBJ_user_times:
2703 if (info.users.times) {
2704 free(info.users.times);
2705 info.users.times = 0;
2710 case OBJ_smapi_bat_perc:
2711 case OBJ_smapi_bat_temp:
2712 case OBJ_smapi_bat_power:
2715 case OBJ_if_smapi_bat_installed:
2716 free(data.ifblock.s);
2717 free(data.ifblock.str);
2726 case OBJ_mpd_artist:
2728 case OBJ_mpd_random:
2729 case OBJ_mpd_repeat:
2731 case OBJ_mpd_bitrate:
2732 case OBJ_mpd_status:
2734 case OBJ_mpd_elapsed:
2735 case OBJ_mpd_length:
2739 case OBJ_mpd_percent:
2741 case OBJ_if_mpd_playing:
2749 case OBJ_moc_artist:
2752 case OBJ_moc_totaltime:
2753 case OBJ_moc_timeleft:
2754 case OBJ_moc_curtime:
2755 case OBJ_moc_bitrate:
2764 free_text_objects(obj->sub, 1);
2769 free(data.scroll.text);
2770 free_text_objects(obj->sub, 1);
2774 free(data.combine.left);
2775 free(data.combine.seperation);
2776 free(data.combine.right);
2777 free_text_objects(obj->sub, 1);
2782 case OBJ_apcupsd_name:
2783 case OBJ_apcupsd_model:
2784 case OBJ_apcupsd_upsmode:
2785 case OBJ_apcupsd_cable:
2786 case OBJ_apcupsd_status:
2787 case OBJ_apcupsd_linev:
2788 case OBJ_apcupsd_load:
2789 case OBJ_apcupsd_loadbar:
2791 case OBJ_apcupsd_loadgraph:
2792 case OBJ_apcupsd_loadgauge:
2794 case OBJ_apcupsd_charge:
2795 case OBJ_apcupsd_timeleft:
2796 case OBJ_apcupsd_temp:
2797 case OBJ_apcupsd_lastxfer:
2799 #endif /* APCUPSD */
2802 case OBJ_desktop_number:
2803 case OBJ_desktop_name:
2804 if(info.x11.desktop.name) {
2805 free(info.x11.desktop.name);
2806 info.x11.desktop.name = NULL;
2808 if(info.x11.desktop.all_names) {
2809 free(info.x11.desktop.all_names);
2810 info.x11.desktop.all_names = NULL;