top: convert to generic object payload
[monky] / src / core.c
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
3  *
4  * Conky, a system monitor, based on torsmo
5  *
6  * Any original torsmo code is licensed under the BSD license
7  *
8  * All code written since the fork of torsmo is licensed under the GPL
9  *
10  * Please see COPYING for details
11  *
12  * Copyright (c) 2004, Hannu Saransaari and Lauri Hakkarainen
13  * Copyright (c) 2005-2009 Brenden Matthews, Philip Kovacs, et. al.
14  *      (see AUTHORS)
15  * All rights reserved.
16  *
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.
21  *
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/>.
28  *
29  */
30
31 /* local headers */
32 #include "core.h"
33 #include "text_object.h"
34 #include "algebra.h"
35 #include "build.h"
36 #include "colours.h"
37 #include "combine.h"
38 #include "diskio.h"
39 #include "exec.h"
40 #ifdef X11
41 #include "fonts.h"
42 #endif
43 #include "fs.h"
44 #ifdef HAVE_ICONV
45 #include "iconv_tools.h"
46 #endif
47 #include "logging.h"
48 #include "mixer.h"
49 #include "mail.h"
50 #include "mboxscan.h"
51 #include "net_stat.h"
52 #ifdef NVIDIA
53 #include "nvidia.h"
54 #endif
55 #include "read_tcp.h"
56 #include "scroll.h"
57 #include "specials.h"
58 #include "temphelper.h"
59 #include "template.h"
60 #include "tailhead.h"
61 #include "timeinfo.h"
62 #include "top.h"
63
64 #ifdef NCURSES
65 #include <ncurses.h>
66 #endif
67
68 /* check for OS and include appropriate headers */
69 #if defined(__linux__)
70 #include "linux.h"
71 #elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
72 #include "freebsd.h"
73 #elif defined(__OpenBSD__)
74 #include "openbsd.h"
75 #endif
76
77 /* OS specific prototypes to be implemented by linux.c & Co. */
78 void update_entropy(void);
79
80 #include <string.h>
81 #include <ctype.h>
82
83 /* strip a leading /dev/ if any, following symlinks first
84  *
85  * BEWARE: this function returns a pointer to static content
86  *         which gets overwritten in consecutive calls. I.e.:
87  *         this function is NOT reentrant.
88  */
89 const char *dev_name(const char *path)
90 {
91         static char buf[255];   /* should be enough for pathnames */
92         ssize_t buflen;
93
94         if (!path)
95                 return NULL;
96
97 #define DEV_NAME(x) \
98   x != NULL && strlen(x) > 5 && strncmp(x, "/dev/", 5) == 0 ? x + 5 : x
99         if ((buflen = readlink(path, buf, 254)) == -1)
100                 return DEV_NAME(path);
101         buf[buflen] = '\0';
102         return DEV_NAME(buf);
103 #undef DEV_NAME
104 }
105
106 static struct text_object *new_text_object_internal(void)
107 {
108         struct text_object *obj = malloc(sizeof(struct text_object));
109         memset(obj, 0, sizeof(struct text_object));
110         return obj;
111 }
112
113 static struct text_object *create_plain_text(const char *s)
114 {
115         struct text_object *obj;
116
117         if (s == NULL || *s == '\0') {
118                 return NULL;
119         }
120
121         obj = new_text_object_internal();
122
123         obj->type = OBJ_text;
124         obj->data.s = strndup(s, text_buffer_size);
125         return obj;
126 }
127
128 /* construct_text_object() creates a new text_object */
129 struct text_object *construct_text_object(const char *s, const char *arg, long
130                 line, void **ifblock_opaque, void *free_at_crash)
131 {
132         // struct text_object *obj = new_text_object();
133         struct text_object *obj = new_text_object_internal();
134
135         obj->line = line;
136
137 /* helper defines for internal use only */
138 #define __OBJ_HEAD(a, n) if (!strcmp(s, #a)) { \
139         obj->type = OBJ_##a; add_update_callback(n);
140 #define __OBJ_IF obj_be_ifblock_if(ifblock_opaque, obj)
141 #define __OBJ_ARG(...) if (!arg) { CRIT_ERR(obj, free_at_crash, __VA_ARGS__); }
142
143 /* defines to be used below */
144 #define OBJ(a, n) __OBJ_HEAD(a, n) {
145 #define OBJ_ARG(a, n, ...) __OBJ_HEAD(a, n) __OBJ_ARG(__VA_ARGS__) {
146 #define OBJ_IF(a, n) __OBJ_HEAD(a, n) __OBJ_IF; {
147 #define OBJ_IF_ARG(a, n, ...) __OBJ_HEAD(a, n) __OBJ_ARG(__VA_ARGS__) __OBJ_IF; {
148 #define END } } else
149
150 #ifdef X11
151         if (s[0] == '#') {
152                 obj->type = OBJ_color;
153                 obj->data.l = get_x11_color(s);
154         } else
155 #endif /* X11 */
156 #ifdef __OpenBSD__
157         OBJ(freq, 0)
158 #else
159         OBJ(acpitemp, 0)
160                 obj->data.i = open_acpi_temperature(arg);
161         END OBJ(acpiacadapter, 0)
162         END OBJ(freq, 0)
163 #endif /* !__OpenBSD__ */
164                 get_cpu_count();
165                 if (!arg || !isdigit(arg[0]) || strlen(arg) >= 2 || atoi(&arg[0]) == 0
166                                 || (unsigned int) atoi(&arg[0]) > info.cpu_count) {
167                         obj->data.cpu_index = 1;
168                         /* NORM_ERR("freq: Invalid CPU number or you don't have that many CPUs! "
169                                 "Displaying the clock for CPU 1."); */
170                 } else {
171                         obj->data.cpu_index = atoi(&arg[0]);
172                 }
173                 obj->a = 1;
174         END OBJ(freq_g, 0)
175                 get_cpu_count();
176                 if (!arg || !isdigit(arg[0]) || strlen(arg) >= 2 || atoi(&arg[0]) == 0
177                                 || (unsigned int) atoi(&arg[0]) > info.cpu_count) {
178                         obj->data.cpu_index = 1;
179                         /* NORM_ERR("freq_g: Invalid CPU number or you don't have that many "
180                                 "CPUs! Displaying the clock for CPU 1."); */
181                 } else {
182                         obj->data.cpu_index = atoi(&arg[0]);
183                 }
184                 obj->a = 1;
185         END OBJ_ARG(read_tcp, 0, "read_tcp: Needs \"(host) port\" as argument(s)")
186                 parse_read_tcp_arg(obj, arg, free_at_crash);
187 #if defined(__linux__)
188         END OBJ(voltage_mv, 0)
189                 get_cpu_count();
190                 if (!arg || !isdigit(arg[0]) || strlen(arg) >= 2 || atoi(&arg[0]) == 0
191                                 || (unsigned int) atoi(&arg[0]) > info.cpu_count) {
192                         obj->data.cpu_index = 1;
193                         /* NORM_ERR("voltage_mv: Invalid CPU number or you don't have that many "
194                                 "CPUs! Displaying voltage for CPU 1."); */
195                 } else {
196                         obj->data.cpu_index = atoi(&arg[0]);
197                 }
198                 obj->a = 1;
199         END OBJ(voltage_v, 0)
200                 get_cpu_count();
201                 if (!arg || !isdigit(arg[0]) || strlen(arg) >= 2 || atoi(&arg[0]) == 0
202                                 || (unsigned int) atoi(&arg[0]) > info.cpu_count) {
203                         obj->data.cpu_index = 1;
204                         /* NORM_ERR("voltage_v: Invalid CPU number or you don't have that many "
205                                 "CPUs! Displaying voltage for CPU 1."); */
206                 } else {
207                         obj->data.cpu_index = atoi(&arg[0]);
208                 }
209                 obj->a = 1;
210
211 #ifdef HAVE_IWLIB
212         END OBJ(wireless_essid, &update_net_stats)
213                 parse_net_stat_arg(obj, arg, free_at_crash);
214         END OBJ(wireless_mode, &update_net_stats)
215                 parse_net_stat_arg(obj, arg, free_at_crash);
216         END OBJ(wireless_bitrate, &update_net_stats)
217                 parse_net_stat_arg(obj, arg, free_at_crash);
218         END OBJ(wireless_ap, &update_net_stats)
219                 parse_net_stat_arg(obj, arg, free_at_crash);
220         END OBJ(wireless_link_qual, &update_net_stats)
221                 parse_net_stat_arg(obj, arg, free_at_crash);
222         END OBJ(wireless_link_qual_max, &update_net_stats)
223                 parse_net_stat_arg(obj, arg, free_at_crash);
224         END OBJ(wireless_link_qual_perc, &update_net_stats)
225                 parse_net_stat_arg(obj, arg, free_at_crash);
226         END OBJ(wireless_link_bar, &update_net_stats)
227                 parse_net_stat_bar_arg(obj, arg, free_at_crash);
228 #endif /* HAVE_IWLIB */
229
230 #endif /* __linux__ */
231
232 #ifndef __OpenBSD__
233         END OBJ(acpifan, 0)
234         END OBJ(battery, 0)
235                 char bat[64];
236
237                 if (arg) {
238                         sscanf(arg, "%63s", bat);
239                 } else {
240                         strcpy(bat, "BAT0");
241                 }
242                 obj->data.s = strndup(bat, text_buffer_size);
243         END OBJ(battery_short, 0)
244                 char bat[64];
245
246                 if (arg) {
247                         sscanf(arg, "%63s", bat);
248                 } else {
249                         strcpy(bat, "BAT0");
250                 }
251                 obj->data.s = strndup(bat, text_buffer_size);
252         END OBJ(battery_time, 0)
253                 char bat[64];
254
255                 if (arg) {
256                         sscanf(arg, "%63s", bat);
257                 } else {
258                         strcpy(bat, "BAT0");
259                 }
260                 obj->data.s = strndup(bat, text_buffer_size);
261         END OBJ(battery_percent, 0)
262                 char bat[64];
263
264                 if (arg) {
265                         sscanf(arg, "%63s", bat);
266                 } else {
267                         strcpy(bat, "BAT0");
268                 }
269                 obj->data.s = strndup(bat, text_buffer_size);
270         END OBJ(battery_bar, 0)
271                 char bat[64];
272                 SIZE_DEFAULTS(bar);
273                 obj->b = 6;
274                 if (arg) {
275                         arg = scan_bar(arg, &obj->a, &obj->b);
276                         sscanf(arg, "%63s", bat);
277                 } else {
278                         strcpy(bat, "BAT0");
279                 }
280                 obj->data.s = strndup(bat, text_buffer_size);
281 #endif /* !__OpenBSD__ */
282
283 #if defined(__linux__)
284         END OBJ_ARG(disk_protect, 0, "disk_protect needs an argument")
285                 obj->data.s = strndup(dev_name(arg), text_buffer_size);
286         END OBJ(i8k_version, &update_i8k)
287         END OBJ(i8k_bios, &update_i8k)
288         END OBJ(i8k_serial, &update_i8k)
289         END OBJ(i8k_cpu_temp, &update_i8k)
290         END OBJ(i8k_left_fan_status, &update_i8k)
291         END OBJ(i8k_right_fan_status, &update_i8k)
292         END OBJ(i8k_left_fan_rpm, &update_i8k)
293         END OBJ(i8k_right_fan_rpm, &update_i8k)
294         END OBJ(i8k_ac_status, &update_i8k)
295         END OBJ(i8k_buttons_status, &update_i8k)
296 #if defined(IBM)
297         END OBJ(ibm_fan, 0)
298         END OBJ(ibm_temps, &get_ibm_acpi_temps, "ibm_temps: needs an argument")
299                 parse_ibm_temps_arg(obj, arg);
300         END OBJ(ibm_volume, 0)
301         END OBJ(ibm_brightness, 0)
302 #endif
303         /* information from sony_laptop kernel module
304          * /sys/devices/platform/sony-laptop */
305         END OBJ(sony_fanspeed, 0)
306         END OBJ_IF(if_gw, &update_gateway_info)
307         END OBJ_ARG(ioscheduler, 0, "get_ioscheduler needs an argument (e.g. hda)")
308                 obj->data.s = strndup(dev_name(arg), text_buffer_size);
309         END OBJ(laptop_mode, 0)
310         END OBJ_ARG(pb_battery, 0, "pb_battery: needs one argument: status, percent or time")
311                 if (strcmp(arg, "status") == EQUAL) {
312                         obj->data.i = PB_BATT_STATUS;
313                 } else if (strcmp(arg, "percent") == EQUAL) {
314                         obj->data.i = PB_BATT_PERCENT;
315                 } else if (strcmp(arg, "time") == EQUAL) {
316                         obj->data.i = PB_BATT_TIME;
317                 } else {
318                         NORM_ERR("pb_battery: illegal argument '%s', defaulting to status", arg);
319                         obj->data.i = PB_BATT_STATUS;
320                 }
321 #endif /* __linux__ */
322 #if (defined(__FreeBSD__) || defined(__linux__))
323         END OBJ_IF_ARG(if_up, 0, "if_up needs an argument")
324                 obj->data.ifblock.s = strndup(arg, text_buffer_size);
325 #endif
326 #if defined(__OpenBSD__)
327         END OBJ_ARG(obsd_sensors_temp, 0, "obsd_sensors_temp: needs an argument")
328                 if (!isdigit(arg[0]) || atoi(&arg[0]) < 0
329                                 || atoi(&arg[0]) > OBSD_MAX_SENSORS - 1) {
330                         obj->data.sensor = 0;
331                         NORM_ERR("Invalid temperature sensor number!");
332                 } else
333                         obj->data.sensor = atoi(&arg[0]);
334         END OBJ_ARG(obsd_sensors_fan, 0, "obsd_sensors_fan: needs 2 arguments (device and sensor number)")
335                 if (!isdigit(arg[0]) || atoi(&arg[0]) < 0
336                                 || atoi(&arg[0]) > OBSD_MAX_SENSORS - 1) {
337                         obj->data.sensor = 0;
338                         NORM_ERR("Invalid fan sensor number!");
339                 } else
340                         obj->data.sensor = atoi(&arg[0]);
341         END OBJ_ARG(obsd_sensors_volt, 0, "obsd_sensors_volt: needs 2 arguments (device and sensor number)")
342                 if (!isdigit(arg[0]) || atoi(&arg[0]) < 0
343                                 || atoi(&arg[0]) > OBSD_MAX_SENSORS - 1) {
344                         obj->data.sensor = 0;
345                         NORM_ERR("Invalid voltage sensor number!");
346                 } else
347                         obj->data.sensor = atoi(&arg[0]);
348         END OBJ(obsd_vendor, 0)
349         END OBJ(obsd_product, 0)
350 #endif /* __OpenBSD__ */
351         END OBJ(buffers, &update_meminfo)
352         END OBJ(cached, &update_meminfo)
353 #define SCAN_CPU(__arg, __var) { \
354         int __offset = 0; \
355         if (__arg && sscanf(__arg, " cpu%u %n", &__var, &__offset) > 0) \
356                 __arg += __offset; \
357         else \
358                 __var = 0; \
359 }
360         END OBJ(cpu, &update_cpu_usage)
361                 SCAN_CPU(arg, obj->data.cpu_index);
362                 DBGP2("Adding $cpu for CPU %d", obj->data.cpu_index);
363 #ifdef X11
364         END OBJ(cpugauge, &update_cpu_usage)
365                 SIZE_DEFAULTS(gauge);
366                 SCAN_CPU(arg, obj->data.cpu_index);
367                 scan_gauge(arg, &obj->a, &obj->b);
368                 DBGP2("Adding $cpugauge for CPU %d", obj->data.cpu_index);
369 #endif /* X11 */
370         END OBJ(cpubar, &update_cpu_usage)
371                 SIZE_DEFAULTS(bar);
372                 SCAN_CPU(arg, obj->data.cpu_index);
373                 scan_bar(arg, &obj->a, &obj->b);
374                 DBGP2("Adding $cpubar for CPU %d", obj->data.cpu_index);
375 #ifdef X11
376         END OBJ(cpugraph, &update_cpu_usage)
377                 char *buf = 0;
378                 SIZE_DEFAULTS(graph);
379                 SCAN_CPU(arg, obj->data.cpu_index);
380                 buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
381                         &obj->e, &obj->char_a, &obj->char_b);
382                 DBGP2("Adding $cpugraph for CPU %d", obj->data.cpu_index);
383                 if (buf) free(buf);
384         END OBJ(loadgraph, &update_load_average)
385                 char *buf = 0;
386                 SIZE_DEFAULTS(graph);
387                 buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
388                                 &obj->e, &obj->char_a, &obj->char_b);
389                 if (buf) {
390                         int a = 1, r = 3;
391                         if (arg) {
392                                 r = sscanf(arg, "%d", &a);
393                         }
394                         obj->data.loadavg[0] = (r >= 1) ? (unsigned char) a : 0;
395                         free(buf);
396                 }
397 #endif /* X11 */
398         END OBJ(diskio, &update_diskio)
399                 obj->data.diskio = prepare_diskio_stat(dev_name(arg));
400         END OBJ(diskio_read, &update_diskio)
401                 obj->data.diskio = prepare_diskio_stat(dev_name(arg));
402         END OBJ(diskio_write, &update_diskio)
403                 obj->data.diskio = prepare_diskio_stat(dev_name(arg));
404 #ifdef X11
405         END OBJ(diskiograph, &update_diskio)
406                 char *buf = 0;
407                 SIZE_DEFAULTS(graph);
408                 buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
409                                 &obj->e, &obj->char_a, &obj->char_b);
410
411                 obj->data.diskio = prepare_diskio_stat(dev_name(buf));
412                 if (buf) free(buf);
413         END OBJ(diskiograph_read, &update_diskio)
414                 char *buf = 0;
415                 SIZE_DEFAULTS(graph);
416                 buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
417                                 &obj->e, &obj->char_a, &obj->char_b);
418
419                 obj->data.diskio = prepare_diskio_stat(dev_name(buf));
420                 if (buf) free(buf);
421         END OBJ(diskiograph_write, &update_diskio)
422                 char *buf = 0;
423                 SIZE_DEFAULTS(graph);
424                 buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
425                                 &obj->e, &obj->char_a, &obj->char_b);
426
427                 obj->data.diskio = prepare_diskio_stat(dev_name(buf));
428                 if (buf) free(buf);
429 #endif /* X11 */
430         END OBJ(color, 0)
431 #ifdef X11
432                 if (output_methods & TO_X) {
433                         obj->data.l = arg ? get_x11_color(arg) : default_fg_color;
434                         set_current_text_color(obj->data.l);
435                 }
436 #endif /* X11 */
437 #ifdef NCURSES
438                 if (output_methods & TO_NCURSES) {
439                         obj->data.l = COLOR_WHITE;
440                         if(arg) {
441                                 if(strcasecmp(arg, "red") == 0) {
442                                         obj->data.l = COLOR_RED;
443                                 }else if(strcasecmp(arg, "green") == 0) {
444                                         obj->data.l = COLOR_GREEN;
445                                 }else if(strcasecmp(arg, "yellow") == 0) {
446                                         obj->data.l = COLOR_YELLOW;
447                                 }else if(strcasecmp(arg, "blue") == 0) {
448                                         obj->data.l = COLOR_BLUE;
449                                 }else if(strcasecmp(arg, "magenta") == 0) {
450                                         obj->data.l = COLOR_MAGENTA;
451                                 }else if(strcasecmp(arg, "cyan") == 0) {
452                                         obj->data.l = COLOR_CYAN;
453                                 }else if(strcasecmp(arg, "black") == 0) {
454                                         obj->data.l = COLOR_BLACK;
455                                 }
456                         }
457                         set_current_text_color(obj->data.l);
458                         init_pair(obj->data.l, obj->data.l, COLOR_BLACK);
459                 }
460 #endif /* NCURSES */
461         END OBJ(color0, 0)
462                 obj->data.l = color0;
463                 set_current_text_color(obj->data.l);
464         END OBJ(color1, 0)
465                 obj->data.l = color1;
466                 set_current_text_color(obj->data.l);
467         END OBJ(color2, 0)
468                 obj->data.l = color2;
469                 set_current_text_color(obj->data.l);
470         END OBJ(color3, 0)
471                 obj->data.l = color3;
472                 set_current_text_color(obj->data.l);
473         END OBJ(color4, 0)
474                 obj->data.l = color4;
475                 set_current_text_color(obj->data.l);
476         END OBJ(color5, 0)
477                 obj->data.l = color5;
478                 set_current_text_color(obj->data.l);
479         END OBJ(color6, 0)
480                 obj->data.l = color6;
481                 set_current_text_color(obj->data.l);
482         END OBJ(color7, 0)
483                 obj->data.l = color7;
484                 set_current_text_color(obj->data.l);
485         END OBJ(color8, 0)
486                 obj->data.l = color8;
487                 set_current_text_color(obj->data.l);
488         END OBJ(color9, 0)
489                 obj->data.l = color9;
490                 set_current_text_color(obj->data.l);
491 #ifdef X11
492         END OBJ(font, 0)
493                 obj->data.s = scan_font(arg);
494 #endif /* X11 */
495         END OBJ(conky_version, 0)
496         END OBJ(conky_build_date, 0)
497         END OBJ(conky_build_arch, 0)
498         END OBJ(downspeed, &update_net_stats)
499                 parse_net_stat_arg(obj, arg, free_at_crash);
500         END OBJ(downspeedf, &update_net_stats)
501                 parse_net_stat_arg(obj, arg, free_at_crash);
502 #ifdef X11
503         END OBJ(downspeedgraph, &update_net_stats)
504                 parse_net_stat_graph_arg(obj, arg, free_at_crash);
505 #endif /* X11 */
506         END OBJ(else, 0)
507                 obj_be_ifblock_else(ifblock_opaque, obj);
508         END OBJ(endif, 0)
509                 obj_be_ifblock_endif(ifblock_opaque, obj);
510         END OBJ(eval, 0)
511                 obj->data.s = strndup(arg ? arg : "", text_buffer_size);
512 #if defined(IMLIB2) && defined(X11)
513         END OBJ(image, 0)
514                 obj->data.s = strndup(arg ? arg : "", text_buffer_size);
515 #endif /* IMLIB2 */
516         END OBJ(exec, 0)
517                 scan_exec_arg(obj, arg);
518         END OBJ(execp, 0)
519                 scan_exec_arg(obj, arg);
520         END OBJ(execbar, 0)
521                 SIZE_DEFAULTS(bar);
522                 scan_exec_arg(obj, arg);
523 #ifdef X11
524         END OBJ(execgauge, 0)
525                 SIZE_DEFAULTS(gauge);
526                 scan_exec_arg(obj, arg);
527         END OBJ(execgraph, 0)
528                 SIZE_DEFAULTS(graph);
529                 scan_exec_arg(obj, arg);
530 #endif /* X11 */
531         END OBJ_ARG(execibar, 0, "execibar needs arguments")
532                 SIZE_DEFAULTS(bar);
533                 scan_execi_arg(obj, arg);
534 #ifdef X11
535         END OBJ_ARG(execigraph, 0, "execigraph needs arguments")
536                 SIZE_DEFAULTS(graph);
537                 scan_execi_arg(obj, arg);
538         END OBJ_ARG(execigauge, 0, "execigauge needs arguments")
539                 SIZE_DEFAULTS(gauge);
540                 scan_execi_arg(obj, arg);
541 #endif /* X11 */
542         END OBJ_ARG(execi, 0, "execi needs arguments")
543                 scan_execi_arg(obj, arg);
544         END OBJ_ARG(execpi, 0, "execpi needs arguments")
545                 scan_execi_arg(obj, arg);
546         END OBJ_ARG(texeci, 0, "texeci needs arguments")
547                 scan_execi_arg(obj, arg);
548         END OBJ(pre_exec, 0)
549                 scan_pre_exec_arg(obj, arg);
550         END OBJ(fs_bar, &update_fs_stats)
551                 init_fs_bar(obj, arg);
552         END OBJ(fs_bar_free, &update_fs_stats)
553                 init_fs_bar(obj, arg);
554         END OBJ(fs_free, &update_fs_stats)
555                 init_fs(obj, arg);
556         END OBJ(fs_used_perc, &update_fs_stats)
557                 init_fs(obj, arg);
558         END OBJ(fs_free_perc, &update_fs_stats)
559                 init_fs(obj, arg);
560         END OBJ(fs_size, &update_fs_stats)
561                 init_fs(obj, arg);
562         END OBJ(fs_type, &update_fs_stats)
563                 init_fs(obj, arg);
564         END OBJ(fs_used, &update_fs_stats)
565                 init_fs(obj, arg);
566         END OBJ(hr, 0)
567                 obj->data.i = arg ? atoi(arg) : 1;
568         END OBJ(nameserver, &update_dns_data)
569                 parse_nameserver_arg(obj, arg);
570         END OBJ(offset, 0)
571                 obj->data.i = arg ? atoi(arg) : 1;
572         END OBJ(voffset, 0)
573                 obj->data.i = arg ? atoi(arg) : 1;
574         END OBJ_ARG(goto, 0, "goto needs arguments")
575                 obj->data.i = atoi(arg);
576         END OBJ(tab, 0)
577                 int a = 10, b = 0;
578
579                 if (arg) {
580                         if (sscanf(arg, "%d %d", &a, &b) != 2) {
581                                 sscanf(arg, "%d", &b);
582                         }
583                 }
584                 if (a <= 0) {
585                         a = 1;
586                 }
587                 obj->data.pair.a = a;
588                 obj->data.pair.b = b;
589
590 #ifdef __linux__
591         END OBJ_ARG(i2c, 0, "i2c needs arguments")
592                 parse_i2c_sensor(obj, arg);
593         END OBJ_ARG(platform, 0, "platform needs arguments")
594                 parse_platform_sensor(obj, arg);
595         END OBJ_ARG(hwmon, 0, "hwmon needs argumanets")
596                 parse_hwmon_sensor(obj, arg);
597 #endif /* __linux__ */
598
599         END
600         /* we have four different types of top (top, top_mem, top_time and top_io). To
601          * avoid having almost-same code four times, we have this special
602          * handler. */
603         if (strncmp(s, "top", 3) == EQUAL) {
604                 add_update_callback(&update_meminfo);
605                 add_update_callback(&update_top);
606                 if (!parse_top_args(s, arg, obj)) {
607                         return NULL;
608                 }
609         } else OBJ(addr, &update_net_stats)
610                 parse_net_stat_arg(obj, arg, free_at_crash);
611 #if defined(__linux__)
612         END OBJ(addrs, &update_net_stats)
613                 parse_net_stat_arg(obj, arg, free_at_crash);
614 #endif /* __linux__ */
615         END OBJ_ARG(tail, 0, "tail needs arguments")
616                 init_tailhead("tail", arg, obj, free_at_crash);
617         END OBJ_ARG(head, 0, "head needs arguments")
618                 init_tailhead("head", arg, obj, free_at_crash);
619         END OBJ_ARG(lines, 0, "lines needs an argument")
620                 obj->data.s = strndup(arg, text_buffer_size);
621         END OBJ_ARG(words, 0, "words needs a argument")
622                 obj->data.s = strndup(arg, text_buffer_size);
623         END OBJ(loadavg, &update_load_average)
624                 int a = 1, b = 2, c = 3, r = 3;
625
626                 if (arg) {
627                         r = sscanf(arg, "%d %d %d", &a, &b, &c);
628                         if (r >= 3 && (c < 1 || c > 3)) {
629                                 r--;
630                         }
631                         if (r >= 2 && (b < 1 || b > 3)) {
632                                 r--, b = c;
633                         }
634                         if (r >= 1 && (a < 1 || a > 3)) {
635                                 r--, a = b, b = c;
636                         }
637                 }
638                 obj->data.loadavg[0] = (r >= 1) ? (unsigned char) a : 0;
639                 obj->data.loadavg[1] = (r >= 2) ? (unsigned char) b : 0;
640                 obj->data.loadavg[2] = (r >= 3) ? (unsigned char) c : 0;
641         END OBJ_IF_ARG(if_empty, 0, "if_empty needs an argument")
642                 obj->data.ifblock.s = strndup(arg, text_buffer_size);
643                 obj->sub = malloc(sizeof(struct text_object));
644                 extract_variable_text_internal(obj->sub, obj->data.ifblock.s);
645         END OBJ_IF_ARG(if_match, 0, "if_match needs arguments")
646                 obj->data.ifblock.s = strndup(arg, text_buffer_size);
647                 obj->sub = malloc(sizeof(struct text_object));
648                 extract_variable_text_internal(obj->sub, obj->data.ifblock.s);
649         END OBJ_IF_ARG(if_existing, 0, "if_existing needs an argument or two")
650                 char buf1[256], buf2[256];
651                 int r = sscanf(arg, "%255s %255[^\n]", buf1, buf2);
652
653                 if (r == 1) {
654                         obj->data.ifblock.s = strndup(buf1, text_buffer_size);
655                         obj->data.ifblock.str = NULL;
656                 } else {
657                         obj->data.ifblock.s = strndup(buf1, text_buffer_size);
658                         obj->data.ifblock.str = strndup(buf2, text_buffer_size);
659                 }
660                 DBGP("if_existing: '%s' '%s'", obj->data.ifblock.s, obj->data.ifblock.str);
661         END OBJ_IF_ARG(if_mounted, 0, "if_mounted needs an argument")
662                 obj->data.ifblock.s = strndup(arg, text_buffer_size);
663 #ifdef __linux__
664         END OBJ_IF_ARG(if_running, &update_top, "if_running needs an argument")
665                 top_running = 1;
666                 obj->data.ifblock.s = strndup(arg, text_buffer_size);
667 #else
668         END OBJ_IF_ARG(if_running, 0, "if_running needs an argument")
669                 char buf[256];
670
671                 snprintf(buf, 256, "pidof %s >/dev/null", arg);
672                 obj->data.ifblock.s = strndup(buf, text_buffer_size);
673 #endif
674         END OBJ(kernel, 0)
675         END OBJ(machine, 0)
676         END OBJ(mails, 0)
677                 parse_local_mail_args(obj, arg);
678         END OBJ(new_mails, 0)
679                 parse_local_mail_args(obj, arg);
680         END OBJ(seen_mails, 0)
681                 parse_local_mail_args(obj, arg);
682         END OBJ(unseen_mails, 0)
683                 parse_local_mail_args(obj, arg);
684         END OBJ(flagged_mails, 0)
685                 parse_local_mail_args(obj, arg);
686         END OBJ(unflagged_mails, 0)
687                 parse_local_mail_args(obj, arg);
688         END OBJ(forwarded_mails, 0)
689                 parse_local_mail_args(obj, arg);
690         END OBJ(unforwarded_mails, 0)
691                 parse_local_mail_args(obj, arg);
692         END OBJ(replied_mails, 0)
693                 parse_local_mail_args(obj, arg);
694         END OBJ(unreplied_mails, 0)
695                 parse_local_mail_args(obj, arg);
696         END OBJ(draft_mails, 0)
697                 parse_local_mail_args(obj, arg);
698         END OBJ(trashed_mails, 0)
699                 parse_local_mail_args(obj, arg);
700         END OBJ(mboxscan, 0)
701                 parse_mboxscan_arg(obj, arg);
702         END OBJ(mem, &update_meminfo)
703         END OBJ(memeasyfree, &update_meminfo)
704         END OBJ(memfree, &update_meminfo)
705         END OBJ(memmax, &update_meminfo)
706         END OBJ(memperc, &update_meminfo)
707 #ifdef X11
708         END OBJ(memgauge, &update_meminfo)
709                 SIZE_DEFAULTS(gauge);
710                 scan_gauge(arg, &obj->data.pair.a, &obj->data.pair.b);
711 #endif /* X11*/
712         END OBJ(membar, &update_meminfo)
713                 SIZE_DEFAULTS(bar);
714                 scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
715 #ifdef X11
716         END OBJ(memgraph, &update_meminfo)
717                 char *buf = 0;
718                 SIZE_DEFAULTS(graph);
719                 buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
720                                 &obj->e, &obj->char_a, &obj->char_b);
721
722                 if (buf) free(buf);
723 #endif /* X11*/
724         END OBJ(mixer, 0)
725                 parse_mixer_arg(obj, arg);
726         END OBJ(mixerl, 0)
727                 parse_mixer_arg(obj, arg);
728         END OBJ(mixerr, 0)
729                 parse_mixer_arg(obj, arg);
730 #ifdef X11
731         END OBJ(mixerbar, 0)
732                 scan_mixer_bar(obj, arg);
733         END OBJ(mixerlbar, 0)
734                 scan_mixer_bar(obj, arg);
735         END OBJ(mixerrbar, 0)
736                 scan_mixer_bar(obj, arg);
737 #endif
738         END OBJ_IF(if_mixer_mute, 0)
739                 parse_mixer_arg(obj, arg);
740 #ifdef X11
741         END OBJ(monitor, &update_x11info)
742         END OBJ(monitor_number, &update_x11info)
743         END OBJ(desktop, &update_x11info)
744         END OBJ(desktop_number, &update_x11info)
745         END OBJ(desktop_name, &update_x11info)
746 #endif
747         END OBJ(nodename, 0)
748         END OBJ(processes, &update_total_processes)
749         END OBJ(running_processes, &update_running_processes)
750         END OBJ(shadecolor, 0)
751 #ifdef X11
752                 obj->data.l = arg ? get_x11_color(arg) : default_bg_color;
753 #endif /* X11 */
754         END OBJ(outlinecolor, 0)
755 #ifdef X11
756                 obj->data.l = arg ? get_x11_color(arg) : default_out_color;
757 #endif /* X11 */
758         END OBJ(stippled_hr, 0)
759 #ifdef X11
760                 int a = get_stippled_borders(), b = 1;
761
762                 if (arg) {
763                         if (sscanf(arg, "%d %d", &a, &b) != 2) {
764                                 sscanf(arg, "%d", &b);
765                         }
766                 }
767                 if (a <= 0) {
768                         a = 1;
769                 }
770                 obj->data.pair.a = a;
771                 obj->data.pair.b = b;
772 #endif /* X11 */
773         END OBJ(swap, &update_meminfo)
774         END OBJ(swapfree, &update_meminfo)
775         END OBJ(swapmax, &update_meminfo)
776         END OBJ(swapperc, &update_meminfo)
777         END OBJ(swapbar, &update_meminfo)
778                 SIZE_DEFAULTS(bar);
779                 scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
780         END OBJ(sysname, 0)
781         END OBJ(time, 0)
782                 scan_time(obj, arg);
783         END OBJ(utime, 0)
784                 scan_time(obj, arg);
785         END OBJ(tztime, 0)
786                 scan_tztime(obj, arg);
787 #ifdef HAVE_ICONV
788         END OBJ_ARG(iconv_start, 0, "Iconv requires arguments")
789                 init_iconv_start(obj, free_at_crash, arg);
790         END OBJ(iconv_stop, 0)
791                 init_iconv_stop();
792 #endif
793         END OBJ(totaldown, &update_net_stats)
794                 parse_net_stat_arg(obj, arg, free_at_crash);
795         END OBJ(totalup, &update_net_stats)
796                 parse_net_stat_arg(obj, arg, free_at_crash);
797         END OBJ(updates, 0)
798         END OBJ_IF(if_updatenr, 0)
799                 obj->data.ifblock.i = arg ? atoi(arg) : 0;
800                 if(obj->data.ifblock.i == 0) CRIT_ERR(obj, free_at_crash, "if_updatenr needs a number above 0 as argument");
801                 set_updatereset(obj->data.ifblock.i > get_updatereset() ? obj->data.ifblock.i : get_updatereset());
802         END OBJ(alignr, 0)
803                 obj->data.i = arg ? atoi(arg) : 0;
804         END OBJ(alignc, 0)
805                 obj->data.i = arg ? atoi(arg) : 0;
806         END OBJ(upspeed, &update_net_stats)
807                 parse_net_stat_arg(obj, arg, free_at_crash);
808         END OBJ(upspeedf, &update_net_stats)
809                 parse_net_stat_arg(obj, arg, free_at_crash);
810 #ifdef X11
811         END OBJ(upspeedgraph, &update_net_stats)
812                 parse_net_stat_graph_arg(obj, arg, free_at_crash);
813 #endif
814         END OBJ(uptime_short, &update_uptime)
815         END OBJ(uptime, &update_uptime)
816         END OBJ(user_names, &update_users)
817         END OBJ(user_times, &update_users)
818         END OBJ(user_terms, &update_users)
819         END OBJ(user_number, &update_users)
820 #if defined(__linux__)
821         END OBJ(gw_iface, &update_gateway_info)
822         END OBJ(gw_ip, &update_gateway_info)
823 #endif /* !__linux__ */
824 #ifndef __OpenBSD__
825         END OBJ(adt746xcpu, 0)
826         END OBJ(adt746xfan, 0)
827 #endif /* !__OpenBSD__ */
828 #if (defined(__FreeBSD__) || defined(__FreeBSD_kernel__) \
829                 || defined(__OpenBSD__)) && (defined(i386) || defined(__i386__))
830         END OBJ(apm_adapter, 0)
831         END OBJ(apm_battery_life, 0)
832         END OBJ(apm_battery_time, 0)
833 #endif /* __FreeBSD__ */
834         END OBJ(imap_unseen, 0)
835                 parse_imap_mail_args(obj, arg);
836         END OBJ(imap_messages, 0)
837                 parse_imap_mail_args(obj, arg);
838         END OBJ(pop3_unseen, 0)
839                 parse_pop3_mail_args(obj, arg);
840         END OBJ(pop3_used, 0)
841                 parse_pop3_mail_args(obj, arg);
842 #ifdef IBM
843         END OBJ_ARG(smapi, 0, "smapi needs an argument")
844                 obj->data.s = strndup(arg, text_buffer_size);
845         END OBJ_IF_ARG(if_smapi_bat_installed, 0, "if_smapi_bat_installed needs an argument")
846                 obj->data.ifblock.s = strndup(arg, text_buffer_size);
847         END OBJ_ARG(smapi_bat_perc, 0, "smapi_bat_perc needs an argument")
848                 obj->data.s = strndup(arg, text_buffer_size);
849         END OBJ_ARG(smapi_bat_temp, 0, "smapi_bat_temp needs an argument")
850                 obj->data.s = strndup(arg, text_buffer_size);
851         END OBJ_ARG(smapi_bat_power, 0, "smapi_bat_power needs an argument")
852                 obj->data.s = strndup(arg, text_buffer_size);
853 #ifdef X11
854         END OBJ_ARG(smapi_bat_bar, 0, "smapi_bat_bar needs an argument")
855                 int cnt;
856                 SIZE_DEFAULTS(bar);
857                 if(sscanf(arg, "%i %n", &obj->data.i, &cnt) <= 0) {
858                         NORM_ERR("first argument to smapi_bat_bar must be an integer value");
859                         obj->data.i = -1;
860                 } else {
861                         obj->b = 4;
862                         arg = scan_bar(arg + cnt, &obj->a, &obj->b);
863                 }
864 #endif /* X11 */
865 #endif /* IBM */
866 #ifdef MPD
867 #define mpd_set_maxlen(name) \
868                 if (arg) { \
869                         int i; \
870                         sscanf(arg, "%d", &i); \
871                         if (i > 0) \
872                                 obj->data.i = i + 1; \
873                         else \
874                                 NORM_ERR(#name ": invalid length argument"); \
875                 }
876         END OBJ(mpd_artist, &update_mpd)
877                 mpd_set_maxlen(mpd_artist);
878                 init_mpd();
879         END OBJ(mpd_title, &update_mpd)
880                 mpd_set_maxlen(mpd_title);
881                 init_mpd();
882         END OBJ(mpd_random, &update_mpd) init_mpd();
883         END OBJ(mpd_repeat, &update_mpd) init_mpd();
884         END OBJ(mpd_elapsed, &update_mpd) init_mpd();
885         END OBJ(mpd_length, &update_mpd) init_mpd();
886         END OBJ(mpd_track, &update_mpd)
887                 mpd_set_maxlen(mpd_track);
888                 init_mpd();
889         END OBJ(mpd_name, &update_mpd)
890                 mpd_set_maxlen(mpd_name);
891                 init_mpd();
892         END OBJ(mpd_file, &update_mpd)
893                 mpd_set_maxlen(mpd_file);
894                 init_mpd();
895         END OBJ(mpd_percent, &update_mpd) init_mpd();
896         END OBJ(mpd_album, &update_mpd)
897                 mpd_set_maxlen(mpd_album);
898                 init_mpd();
899         END OBJ(mpd_vol, &update_mpd) init_mpd();
900         END OBJ(mpd_bitrate, &update_mpd) init_mpd();
901         END OBJ(mpd_status, &update_mpd) init_mpd();
902         END OBJ(mpd_bar, &update_mpd)
903                 SIZE_DEFAULTS(bar);
904                 scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
905                 init_mpd();
906         END OBJ(mpd_smart, &update_mpd)
907                 mpd_set_maxlen(mpd_smart);
908                 init_mpd();
909         END OBJ_IF(if_mpd_playing, &update_mpd)
910                 init_mpd();
911 #undef mpd_set_maxlen
912 #endif /* MPD */
913 #ifdef MOC
914         END OBJ(moc_state, &update_moc)
915         END OBJ(moc_file, &update_moc)
916         END OBJ(moc_title, &update_moc)
917         END OBJ(moc_artist, &update_moc)
918         END OBJ(moc_song, &update_moc)
919         END OBJ(moc_album, &update_moc)
920         END OBJ(moc_totaltime, &update_moc)
921         END OBJ(moc_timeleft, &update_moc)
922         END OBJ(moc_curtime, &update_moc)
923         END OBJ(moc_bitrate, &update_moc)
924         END OBJ(moc_rate, &update_moc)
925 #endif /* MOC */
926 #ifdef XMMS2
927         END OBJ(xmms2_artist, &update_xmms2)
928         END OBJ(xmms2_album, &update_xmms2)
929         END OBJ(xmms2_title, &update_xmms2)
930         END OBJ(xmms2_genre, &update_xmms2)
931         END OBJ(xmms2_comment, &update_xmms2)
932         END OBJ(xmms2_url, &update_xmms2)
933         END OBJ(xmms2_tracknr, &update_xmms2)
934         END OBJ(xmms2_bitrate, &update_xmms2)
935         END OBJ(xmms2_date, &update_xmms2)
936         END OBJ(xmms2_id, &update_xmms2)
937         END OBJ(xmms2_duration, &update_xmms2)
938         END OBJ(xmms2_elapsed, &update_xmms2)
939         END OBJ(xmms2_size, &update_xmms2)
940         END OBJ(xmms2_status, &update_xmms2)
941         END OBJ(xmms2_percent, &update_xmms2)
942 #ifdef X11
943         END OBJ(xmms2_bar, &update_xmms2)
944                 SIZE_DEFAULTS(bar);
945                 scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
946 #endif /* X11 */
947         END OBJ(xmms2_smart, &update_xmms2)
948         END OBJ(xmms2_playlist, &update_xmms2)
949         END OBJ(xmms2_timesplayed, &update_xmms2)
950         END OBJ_IF(if_xmms2_connected, &update_xmms2)
951 #endif
952 #ifdef AUDACIOUS
953         END OBJ(audacious_status, &update_audacious)
954         END OBJ_ARG(audacious_title, &update_audacious, "audacious_title needs an argument")
955                 sscanf(arg, "%d", &info.audacious.max_title_len);
956                 if (info.audacious.max_title_len > 0) {
957                         info.audacious.max_title_len++;
958                 } else {
959                         CRIT_ERR(obj, free_at_crash, "audacious_title: invalid length argument");
960                 }
961         END OBJ(audacious_length, &update_audacious)
962         END OBJ(audacious_length_seconds, &update_audacious)
963         END OBJ(audacious_position, &update_audacious)
964         END OBJ(audacious_position_seconds, &update_audacious)
965         END OBJ(audacious_bitrate, &update_audacious)
966         END OBJ(audacious_frequency, &update_audacious)
967         END OBJ(audacious_channels, &update_audacious)
968         END OBJ(audacious_filename, &update_audacious)
969         END OBJ(audacious_playlist_length, &update_audacious)
970         END OBJ(audacious_playlist_position, &update_audacious)
971         END OBJ(audacious_main_volume, &update_audacious)
972 #ifdef X11
973         END OBJ(audacious_bar, &update_audacious)
974                 SIZE_DEFAULTS(bar);
975                 scan_bar(arg, &obj->a, &obj->b);
976 #endif /* X11 */
977 #endif
978 #ifdef BMPX
979         END OBJ(bmpx_title, &update_bmpx)
980                 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
981         END OBJ(bmpx_artist, &update_bmpx)
982                 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
983         END OBJ(bmpx_album, &update_bmpx)
984                 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
985         END OBJ(bmpx_track, &update_bmpx)
986                 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
987         END OBJ(bmpx_uri, &update_bmpx)
988                 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
989         END OBJ(bmpx_bitrate, &update_bmpx)
990                 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
991 #endif
992 #ifdef EVE
993         END OBJ_ARG(eve, 0, "eve needs arguments: <userid> <apikey> <characterid>")
994                 scan_eve(obj, arg);
995 #endif
996 #ifdef HAVE_CURL
997         END OBJ_ARG(curl, 0, "curl needs arguments: <uri> <interval in minutes>")
998                 curl_parse_arg(obj, arg);
999 #endif
1000 #ifdef RSS
1001         END OBJ_ARG(rss, 0, "rss needs arguments: <uri> <interval in minutes> <action> [act_par] [spaces in front]")
1002                 rss_scan_arg(obj, arg);
1003 #endif
1004 #ifdef WEATHER
1005         END OBJ_ARG(weather, 0, "weather needs arguments: <uri> <locID> <data_type> [interval in minutes]")
1006                 scan_weather_arg(obj, arg, free_at_crash);
1007 #endif
1008 #ifdef XOAP
1009         END OBJ_ARG(weather_forecast, 0, "weather_forecast needs arguments: <uri> <locID> <day> <data_type> [interval in minutes]")
1010                 scan_weather_forecast_arg(obj, arg, free_at_crash);
1011 #endif
1012 #ifdef HAVE_LUA
1013         END OBJ_ARG(lua, 0, "lua needs arguments: <function name> [function parameters]")
1014                 obj->data.s = strndup(arg, text_buffer_size);
1015         END OBJ_ARG(lua_parse, 0, "lua_parse needs arguments: <function name> [function parameters]")
1016                 obj->data.s = strndup(arg, text_buffer_size);
1017         END OBJ_ARG(lua_bar, 0, "lua_bar needs arguments: <height>,<width> <function name> [function parameters]")
1018                 SIZE_DEFAULTS(bar);
1019                 arg = scan_bar(arg, &obj->a, &obj->b);
1020                 if(arg) {
1021                         obj->data.s = strndup(arg, text_buffer_size);
1022                 } else {
1023                         CRIT_ERR(obj, free_at_crash, "lua_bar needs arguments: <height>,<width> <function name> [function parameters]");
1024                 }
1025 #ifdef X11
1026         END OBJ_ARG(lua_graph, 0, "lua_graph needs arguments: <function name> [height],[width] [gradient colour 1] [gradient colour 2] [scale] [-t] [-l]")
1027                 char *buf = 0;
1028                 SIZE_DEFAULTS(graph);
1029                 buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
1030                                 &obj->e, &obj->char_a, &obj->char_b);
1031                 if (buf) {
1032                         obj->data.s = buf;
1033                 } else {
1034                         CRIT_ERR(obj, free_at_crash, "lua_graph needs arguments: <function name> [height],[width] [gradient colour 1] [gradient colour 2] [scale] [-t] [-l]");
1035                 }
1036         END OBJ_ARG(lua_gauge, 0, "lua_gauge needs arguments: <height>,<width> <function name> [function parameters]")
1037                 SIZE_DEFAULTS(gauge);
1038                 arg = scan_gauge(arg, &obj->a, &obj->b);
1039                 if (arg) {
1040                         obj->data.s = strndup(arg, text_buffer_size);
1041                 } else {
1042                         CRIT_ERR(obj, free_at_crash, "lua_gauge needs arguments: <height>,<width> <function name> [function parameters]");
1043                 }
1044 #endif /* X11 */
1045 #endif /* HAVE_LUA */
1046 #ifdef HDDTEMP
1047         END OBJ(hddtemp, &update_hddtemp)
1048                 if (arg)
1049                         obj->data.s = strndup(arg, text_buffer_size);
1050 #endif /* HDDTEMP */
1051 #ifdef TCP_PORT_MONITOR
1052         END OBJ_ARG(tcp_portmon, &tcp_portmon_update, "tcp_portmon: needs arguments")
1053                 tcp_portmon_init(obj, arg);
1054 #endif /* TCP_PORT_MONITOR */
1055         END OBJ(entropy_avail, &update_entropy)
1056         END OBJ(entropy_perc, &update_entropy)
1057         END OBJ(entropy_poolsize, &update_entropy)
1058         END OBJ(entropy_bar, &update_entropy)
1059                 SIZE_DEFAULTS(bar);
1060                 scan_bar(arg, &obj->a, &obj->b);
1061         END OBJ_ARG(include, 0, "include needs a argument")
1062                 struct conftree *leaf = conftree_add(currentconffile, arg);
1063                 if(leaf) {
1064                         if (load_config_file(arg) == TRUE) {
1065                                 obj->sub = malloc(sizeof(struct text_object));
1066                                 currentconffile = leaf;
1067                                 extract_variable_text_internal(obj->sub, get_global_text());
1068                                 currentconffile = leaf->back;
1069                         } else {
1070                                 NORM_ERR("Can't load configfile '%s'.", arg);
1071                         }
1072                 } else {
1073                         NORM_ERR("You are trying to load '%s' recursively, I'm only going to load it once to prevent an infinite loop.", arg);
1074                 }
1075         END OBJ_ARG(blink, 0, "blink needs a argument")
1076                 obj->sub = malloc(sizeof(struct text_object));
1077                 extract_variable_text_internal(obj->sub, arg);
1078         END OBJ_ARG(to_bytes, 0, "to_bytes needs a argument")
1079                 obj->sub = malloc(sizeof(struct text_object));
1080                 extract_variable_text_internal(obj->sub, arg);
1081         END OBJ(scroll, 0)
1082                 parse_scroll_arg(obj, arg, free_at_crash);
1083         END OBJ_ARG(combine, 0, "combine needs arguments: <text1> <text2>")
1084                 parse_combine_arg(obj, arg, free_at_crash);
1085 #ifdef NVIDIA
1086         END OBJ_ARG(nvidia, 0, "nvidia needs an argument")
1087                 if (set_nvidia_type(obj, arg)) {
1088                         CRIT_ERR(obj, free_at_crash, "nvidia: invalid argument"
1089                                  " specified: '%s'\n", arg);
1090                 }
1091 #endif /* NVIDIA */
1092 #ifdef APCUPSD
1093         END OBJ_ARG(apcupsd, &update_apcupsd, "apcupsd needs arguments: <host> <port>")
1094                 char host[64];
1095                 int port;
1096                 if (sscanf(arg, "%63s %d", host, &port) != 2) {
1097                         CRIT_ERR(obj, free_at_crash, "apcupsd needs arguments: <host> <port>");
1098                 } else {
1099                         info.apcupsd.port = htons(port);
1100                         strncpy(info.apcupsd.host, host, sizeof(info.apcupsd.host));
1101                 }
1102         END OBJ(apcupsd_name, &update_apcupsd)
1103         END OBJ(apcupsd_model, &update_apcupsd)
1104         END OBJ(apcupsd_upsmode, &update_apcupsd)
1105         END OBJ(apcupsd_cable, &update_apcupsd)
1106         END OBJ(apcupsd_status, &update_apcupsd)
1107         END OBJ(apcupsd_linev, &update_apcupsd)
1108         END OBJ(apcupsd_load, &update_apcupsd)
1109         END OBJ(apcupsd_loadbar, &update_apcupsd)
1110                 SIZE_DEFAULTS(bar);
1111                 scan_bar(arg, &obj->a, &obj->b);
1112 #ifdef X11
1113         END OBJ(apcupsd_loadgraph, &update_apcupsd)
1114                 char* buf = 0;
1115                 SIZE_DEFAULTS(graph);
1116                 buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
1117                                 &obj->e, &obj->char_a, &obj->char_b);
1118                 if (buf) free(buf);
1119         END OBJ(apcupsd_loadgauge, &update_apcupsd)
1120                 SIZE_DEFAULTS(gauge);
1121                 scan_gauge(arg, &obj->a, &obj->b);
1122 #endif /* X11 */
1123         END OBJ(apcupsd_charge, &update_apcupsd)
1124         END OBJ(apcupsd_timeleft, &update_apcupsd)
1125         END OBJ(apcupsd_temp, &update_apcupsd)
1126         END OBJ(apcupsd_lastxfer, &update_apcupsd)
1127 #endif /* APCUPSD */
1128         END {
1129                 char buf[256];
1130
1131                 NORM_ERR("unknown variable %s", s);
1132                 obj->type = OBJ_text;
1133                 snprintf(buf, 256, "${%s}", s);
1134                 obj->data.s = strndup(buf, text_buffer_size);
1135         }
1136 #undef OBJ
1137 #undef OBJ_IF
1138 #undef OBJ_ARG
1139 #undef OBJ_IF_ARG
1140 #undef __OBJ_HEAD
1141 #undef __OBJ_IF
1142 #undef __OBJ_ARG
1143 #undef END
1144 #undef SIZE_DEFAULTS
1145
1146         return obj;
1147 }
1148
1149 /*
1150  * - assumes that *string is '#'
1151  * - removes the part from '#' to the end of line ('\n' or '\0')
1152  * - it removes the '\n'
1153  * - copies the last char into 'char *last' argument, which should be a pointer
1154  *   to a char rather than a string.
1155  */
1156 static size_t remove_comment(char *string, char *last)
1157 {
1158         char *end = string;
1159         while (*end != '\0' && *end != '\n') {
1160                 ++end;
1161         }
1162         if (last) *last = *end;
1163         if (*end == '\n') end++;
1164         strfold(string, end - string);
1165         return end - string;
1166 }
1167
1168 size_t remove_comments(char *string)
1169 {
1170         char *curplace;
1171         size_t folded = 0;
1172         for (curplace = string; *curplace != 0; curplace++) {
1173                 if (*curplace == '\\' && *(curplace + 1) == '#') {
1174                         // strcpy can't be used for overlapping strings
1175                         strfold(curplace, 1);
1176                         folded += 1;
1177                 } else if (*curplace == '#') {
1178                         folded += remove_comment(curplace, 0);
1179                 }
1180         }
1181         return folded;
1182 }
1183
1184 int extract_variable_text_internal(struct text_object *retval, const char *const_p)
1185 {
1186         struct text_object *obj;
1187         char *p, *s, *orig_p;
1188         long line;
1189         void *ifblock_opaque = NULL;
1190         char *tmp_p;
1191         char *arg = 0;
1192         size_t len = 0;
1193
1194         p = strndup(const_p, max_user_text - 1);
1195         while (text_contains_templates(p)) {
1196                 char *tmp;
1197                 tmp = find_and_replace_templates(p);
1198                 free(p);
1199                 p = tmp;
1200         }
1201         s = orig_p = p;
1202
1203         if (strcmp(p, const_p)) {
1204                 DBGP("replaced all templates in text: input is\n'%s'\noutput is\n'%s'", const_p, p);
1205         } else {
1206                 DBGP("no templates to replace");
1207         }
1208
1209         memset(retval, 0, sizeof(struct text_object));
1210
1211         line = global_text_lines;
1212
1213         while (*p) {
1214                 if (*p == '\n') {
1215                         line++;
1216                 }
1217                 if (*p == '$') {
1218                         *p = '\0';
1219                         obj = create_plain_text(s);
1220                         if (obj != NULL) {
1221                                 append_object(retval, obj);
1222                         }
1223                         *p = '$';
1224                         p++;
1225                         s = p;
1226
1227                         if (*p != '$') {
1228                                 char buf[256];
1229                                 const char *var;
1230
1231                                 /* variable is either $foo or ${foo} */
1232                                 if (*p == '{') {
1233                                         unsigned int brl = 1, brr = 0;
1234
1235                                         p++;
1236                                         s = p;
1237                                         while (*p && brl != brr) {
1238                                                 if (*p == '{') {
1239                                                         brl++;
1240                                                 }
1241                                                 if (*p == '}') {
1242                                                         brr++;
1243                                                 }
1244                                                 p++;
1245                                         }
1246                                         p--;
1247                                 } else {
1248                                         s = p;
1249                                         if (*p == '#') {
1250                                                 p++;
1251                                         }
1252                                         while (*p && (isalnum((int) *p) || *p == '_')) {
1253                                                 p++;
1254                                         }
1255                                 }
1256
1257                                 /* copy variable to buffer */
1258                                 len = (p - s > 255) ? 255 : (p - s);
1259                                 strncpy(buf, s, len);
1260                                 buf[len] = '\0';
1261
1262                                 if (*p == '}') {
1263                                         p++;
1264                                 }
1265                                 s = p;
1266
1267                                 /* search for variable in environment */
1268
1269                                 var = getenv(buf);
1270                                 if (var) {
1271                                         obj = create_plain_text(var);
1272                                         if (obj) {
1273                                                 append_object(retval, obj);
1274                                         }
1275                                         continue;
1276                                 }
1277
1278                                 /* if variable wasn't found in environment, use some special */
1279
1280                                 arg = 0;
1281
1282                                 /* split arg */
1283                                 if (strchr(buf, ' ')) {
1284                                         arg = strchr(buf, ' ');
1285                                         *arg = '\0';
1286                                         arg++;
1287                                         while (isspace((int) *arg)) {
1288                                                 arg++;
1289                                         }
1290                                         if (!*arg) {
1291                                                 arg = 0;
1292                                         }
1293                                 }
1294
1295                                 /* lowercase variable name */
1296                                 tmp_p = buf;
1297                                 while (*tmp_p) {
1298                                         *tmp_p = tolower(*tmp_p);
1299                                         tmp_p++;
1300                                 }
1301
1302                                 obj = construct_text_object(buf, arg,
1303                                                 line, &ifblock_opaque, orig_p);
1304                                 if (obj != NULL) {
1305                                         append_object(retval, obj);
1306                                 }
1307                                 continue;
1308                         } else {
1309                                 obj = create_plain_text("$");
1310                                 s = p + 1;
1311                                 if (obj != NULL) {
1312                                         append_object(retval, obj);
1313                                 }
1314                         }
1315                 } else if (*p == '\\' && *(p+1) == '#') {
1316                         strfold(p, 1);
1317                 } else if (*p == '#') {
1318                         char c;
1319                         if (remove_comment(p, &c) && p > orig_p && c == '\n') {
1320                                 /* if remove_comment removed a newline, we need to 'back up' with p */
1321                                 p--;
1322                         }
1323                 }
1324                 p++;
1325         }
1326         obj = create_plain_text(s);
1327         if (obj != NULL) {
1328                 append_object(retval, obj);
1329         }
1330
1331         if (!ifblock_stack_empty(&ifblock_opaque)) {
1332                 NORM_ERR("one or more $endif's are missing");
1333         }
1334
1335         free(orig_p);
1336         return 0;
1337 }
1338
1339 /*
1340  * Frees the list of text objects root points to.  When internal = 1, it won't
1341  * free global objects.
1342  */
1343 void free_text_objects(struct text_object *root, int internal)
1344 {
1345         struct text_object *obj;
1346
1347         if (!root->prev) {
1348                 return;
1349         }
1350
1351 #define data obj->data
1352         for (obj = root->prev; obj; obj = root->prev) {
1353                 root->prev = obj->prev;
1354                 switch (obj->type) {
1355 #ifndef __OpenBSD__
1356                         case OBJ_acpitemp:
1357                                 close(data.i);
1358                                 break;
1359 #endif /* !__OpenBSD__ */
1360 #ifdef __linux__
1361                         case OBJ_i2c:
1362                         case OBJ_platform:
1363                         case OBJ_hwmon:
1364                                 free_sysfs_sensor(obj);
1365                                 break;
1366 #endif /* __linux__ */
1367                         case OBJ_read_tcp:
1368                                 free_read_tcp(obj);
1369                                 break;
1370                         case OBJ_time:
1371                         case OBJ_utime:
1372                                 free_time(obj);
1373                                 break;
1374                         case OBJ_tztime:
1375                                 free_tztime(obj);
1376                                 break;
1377                         case OBJ_mboxscan:
1378                                 free_mboxscan(obj);
1379                                 break;
1380                         case OBJ_mails:
1381                         case OBJ_new_mails:
1382                         case OBJ_seen_mails:
1383                         case OBJ_unseen_mails:
1384                         case OBJ_flagged_mails:
1385                         case OBJ_unflagged_mails:
1386                         case OBJ_forwarded_mails:
1387                         case OBJ_unforwarded_mails:
1388                         case OBJ_replied_mails:
1389                         case OBJ_unreplied_mails:
1390                         case OBJ_draft_mails:
1391                         case OBJ_trashed_mails:
1392                                 free(data.local_mail.mbox);
1393                                 break;
1394                         case OBJ_imap_unseen:
1395                         case OBJ_imap_messages:
1396                         case OBJ_pop3_unseen:
1397                         case OBJ_pop3_used:
1398                                 free_mail_obj(obj);
1399                                 break;
1400                         case OBJ_if_empty:
1401                         case OBJ_if_match:
1402                                 free_text_objects(obj->sub, 1);
1403                                 free(obj->sub);
1404                                 /* fall through */
1405                         case OBJ_if_existing:
1406                         case OBJ_if_mounted:
1407                         case OBJ_if_running:
1408                                 free(data.ifblock.s);
1409                                 free(data.ifblock.str);
1410                                 break;
1411                         case OBJ_head:
1412                         case OBJ_tail:
1413                                 free_tailhead(obj);
1414                                 break;
1415                         case OBJ_text:
1416                         case OBJ_font:
1417                         case OBJ_image:
1418                         case OBJ_eval:
1419                         case OBJ_exec:
1420                         case OBJ_execbar:
1421 #ifdef X11
1422                         case OBJ_execgauge:
1423                         case OBJ_execgraph:
1424 #endif
1425                         case OBJ_execp:
1426                                 free_exec(obj);
1427                                 break;
1428 #ifdef HAVE_ICONV
1429                         case OBJ_iconv_start:
1430                                 free_iconv();
1431                                 break;
1432 #endif
1433 #ifdef __linux__
1434                         case OBJ_disk_protect:
1435                                 free(data.s);
1436                                 break;
1437                         case OBJ_if_gw:
1438                                 free(data.ifblock.s);
1439                                 free(data.ifblock.str);
1440                         case OBJ_gw_iface:
1441                         case OBJ_gw_ip:
1442                                 free_gateway_info();
1443                                 break;
1444                         case OBJ_ioscheduler:
1445                                 if(data.s)
1446                                         free(data.s);
1447                                 break;
1448 #endif
1449 #if (defined(__FreeBSD__) || defined(__linux__))
1450                         case OBJ_if_up:
1451                                 free(data.ifblock.s);
1452                                 free(data.ifblock.str);
1453                                 break;
1454 #endif
1455 #ifdef XMMS2
1456                         case OBJ_xmms2_artist:
1457                                 if (info.xmms2.artist) {
1458                                         free(info.xmms2.artist);
1459                                         info.xmms2.artist = 0;
1460                                 }
1461                                 break;
1462                         case OBJ_xmms2_album:
1463                                 if (info.xmms2.album) {
1464                                         free(info.xmms2.album);
1465                                         info.xmms2.album = 0;
1466                                 }
1467                                 break;
1468                         case OBJ_xmms2_title:
1469                                 if (info.xmms2.title) {
1470                                         free(info.xmms2.title);
1471                                         info.xmms2.title = 0;
1472                                 }
1473                                 break;
1474                         case OBJ_xmms2_genre:
1475                                 if (info.xmms2.genre) {
1476                                         free(info.xmms2.genre);
1477                                         info.xmms2.genre = 0;
1478                                 }
1479                                 break;
1480                         case OBJ_xmms2_comment:
1481                                 if (info.xmms2.comment) {
1482                                         free(info.xmms2.comment);
1483                                         info.xmms2.comment = 0;
1484                                 }
1485                                 break;
1486                         case OBJ_xmms2_url:
1487                                 if (info.xmms2.url) {
1488                                         free(info.xmms2.url);
1489                                         info.xmms2.url = 0;
1490                                 }
1491                                 break;
1492                         case OBJ_xmms2_date:
1493                                 if (info.xmms2.date) {
1494                                         free(info.xmms2.date);
1495                                         info.xmms2.date = 0;
1496                                 }
1497                                 break;
1498                         case OBJ_xmms2_status:
1499                                 if (info.xmms2.status) {
1500                                         free(info.xmms2.status);
1501                                         info.xmms2.status = 0;
1502                                 }
1503                                 break;
1504                         case OBJ_xmms2_playlist:
1505                                 if (info.xmms2.playlist) {
1506                                         free(info.xmms2.playlist);
1507                                         info.xmms2.playlist = 0;
1508                                 }
1509                                 break;
1510                         case OBJ_xmms2_smart:
1511                                 if (info.xmms2.artist) {
1512                                         free(info.xmms2.artist);
1513                                         info.xmms2.artist = 0;
1514                                 }
1515                                 if (info.xmms2.title) {
1516                                         free(info.xmms2.title);
1517                                         info.xmms2.title = 0;
1518                                 }
1519                                 if (info.xmms2.url) {
1520                                         free(info.xmms2.url);
1521                                         info.xmms2.url = 0;
1522                                 }
1523                                 break;
1524 #endif
1525 #ifdef BMPX
1526                         case OBJ_bmpx_title:
1527                         case OBJ_bmpx_artist:
1528                         case OBJ_bmpx_album:
1529                         case OBJ_bmpx_track:
1530                         case OBJ_bmpx_uri:
1531                         case OBJ_bmpx_bitrate:
1532                                 break;
1533 #endif
1534 #ifdef EVE
1535                         case OBJ_eve:
1536                                 free_eve(obj);
1537                                 break;
1538 #endif
1539 #ifdef HAVE_CURL
1540                         case OBJ_curl:
1541                                 curl_obj_free(obj);
1542                                 break;
1543 #endif
1544 #ifdef RSS
1545                         case OBJ_rss:
1546                                 rss_free_obj_info(obj);
1547                                 break;
1548 #endif
1549 #ifdef WEATHER
1550                         case OBJ_weather:
1551                                 free_weather(obj);
1552                                 break;
1553 #endif
1554 #ifdef XOAP
1555                         case OBJ_weather_forecast:
1556                                 free_weather(obj);
1557                                 break;
1558 #endif
1559 #ifdef HAVE_LUA
1560                         case OBJ_lua:
1561                         case OBJ_lua_parse:
1562                         case OBJ_lua_bar:
1563 #ifdef X11
1564                         case OBJ_lua_graph:
1565                         case OBJ_lua_gauge:
1566 #endif /* X11 */
1567                                 free(data.s);
1568                                 break;
1569 #endif /* HAVE_LUA */
1570                         case OBJ_pre_exec:
1571                                 break;
1572 #ifndef __OpenBSD__
1573                         case OBJ_battery:
1574                                 free(data.s);
1575                                 break;
1576                         case OBJ_battery_short:
1577                                 free(data.s);
1578                                 break;
1579                         case OBJ_battery_time:
1580                                 free(data.s);
1581                                 break;
1582 #endif /* !__OpenBSD__ */
1583                         case OBJ_execpi:
1584                         case OBJ_execi:
1585                         case OBJ_execibar:
1586                         case OBJ_texeci:
1587 #ifdef X11
1588                         case OBJ_execigraph:
1589                         case OBJ_execigauge:
1590 #endif /* X11 */
1591                                 free_execi(obj);
1592                                 break;
1593                         case OBJ_nameserver:
1594                                 free_dns_data();
1595                                 break;
1596                         case OBJ_top:
1597                         case OBJ_top_mem:
1598                         case OBJ_top_time:
1599 #ifdef IOSTATS
1600                         case OBJ_top_io:
1601 #endif
1602                                 free_top(obj, internal);
1603                                 break;
1604 #ifdef HDDTEMP
1605                         case OBJ_hddtemp:
1606                                 if (data.s) {
1607                                         free(data.s);
1608                                         data.s = NULL;
1609                                 }
1610                                 free_hddtemp();
1611                                 break;
1612 #endif /* HDDTEMP */
1613                         case OBJ_entropy_avail:
1614                         case OBJ_entropy_perc:
1615                         case OBJ_entropy_poolsize:
1616                         case OBJ_entropy_bar:
1617                                 break;
1618                         case OBJ_user_names:
1619                                 if (info.users.names) {
1620                                         free(info.users.names);
1621                                         info.users.names = 0;
1622                                 }
1623                                 break;
1624                         case OBJ_user_terms:
1625                                 if (info.users.terms) {
1626                                         free(info.users.terms);
1627                                         info.users.terms = 0;
1628                                 }
1629                                 break;
1630                         case OBJ_user_times:
1631                                 if (info.users.times) {
1632                                         free(info.users.times);
1633                                         info.users.times = 0;
1634                                 }
1635                                 break;
1636 #ifdef IBM
1637                         case OBJ_smapi:
1638                         case OBJ_smapi_bat_perc:
1639                         case OBJ_smapi_bat_temp:
1640                         case OBJ_smapi_bat_power:
1641                                 free(data.s);
1642                                 break;
1643                         case OBJ_if_smapi_bat_installed:
1644                                 free(data.ifblock.s);
1645                                 free(data.ifblock.str);
1646                                 break;
1647 #endif /* IBM */
1648 #ifdef NVIDIA
1649                         case OBJ_nvidia:
1650                                 free_nvidia(obj);
1651                                 break;
1652 #endif /* NVIDIA */
1653 #ifdef MPD
1654                         case OBJ_mpd_title:
1655                         case OBJ_mpd_artist:
1656                         case OBJ_mpd_album:
1657                         case OBJ_mpd_random:
1658                         case OBJ_mpd_repeat:
1659                         case OBJ_mpd_vol:
1660                         case OBJ_mpd_bitrate:
1661                         case OBJ_mpd_status:
1662                         case OBJ_mpd_bar:
1663                         case OBJ_mpd_elapsed:
1664                         case OBJ_mpd_length:
1665                         case OBJ_mpd_track:
1666                         case OBJ_mpd_name:
1667                         case OBJ_mpd_file:
1668                         case OBJ_mpd_percent:
1669                         case OBJ_mpd_smart:
1670                         case OBJ_if_mpd_playing:
1671                                 free_mpd();
1672                                 break;
1673 #endif /* MPD */
1674 #ifdef MOC
1675                         case OBJ_moc_state:
1676                         case OBJ_moc_file:
1677                         case OBJ_moc_title:
1678                         case OBJ_moc_artist:
1679                         case OBJ_moc_song:
1680                         case OBJ_moc_album:
1681                         case OBJ_moc_totaltime:
1682                         case OBJ_moc_timeleft:
1683                         case OBJ_moc_curtime:
1684                         case OBJ_moc_bitrate:
1685                         case OBJ_moc_rate:
1686                                 free_moc();
1687                                 break;
1688 #endif /* MOC */
1689                         case OBJ_include:
1690                         case OBJ_blink:
1691                         case OBJ_to_bytes:
1692                                 if(obj->sub) {
1693                                         free_text_objects(obj->sub, 1);
1694                                         free(obj->sub);
1695                                 }
1696                                 break;
1697                         case OBJ_scroll:
1698                                 free_scroll(obj);
1699                                 break;
1700                         case OBJ_combine:
1701                                 free_combine(obj);
1702                                 break;
1703 #ifdef APCUPSD
1704                         case OBJ_apcupsd:
1705                         case OBJ_apcupsd_name:
1706                         case OBJ_apcupsd_model:
1707                         case OBJ_apcupsd_upsmode:
1708                         case OBJ_apcupsd_cable:
1709                         case OBJ_apcupsd_status:
1710                         case OBJ_apcupsd_linev:
1711                         case OBJ_apcupsd_load:
1712                         case OBJ_apcupsd_loadbar:
1713 #ifdef X11
1714                         case OBJ_apcupsd_loadgraph:
1715                         case OBJ_apcupsd_loadgauge:
1716 #endif /* X11 */
1717                         case OBJ_apcupsd_charge:
1718                         case OBJ_apcupsd_timeleft:
1719                         case OBJ_apcupsd_temp:
1720                         case OBJ_apcupsd_lastxfer:
1721                                 break;
1722 #endif /* APCUPSD */
1723 #ifdef TCP_PORT_MONITOR
1724                         case OBJ_tcp_portmon:
1725                                 tcp_portmon_free(obj);
1726                                 break;
1727 #endif /* TCP_PORT_MONITOR */
1728 #ifdef X11
1729                         case OBJ_desktop:
1730                         case OBJ_desktop_number:
1731                         case OBJ_desktop_name:
1732                                 if(info.x11.desktop.name && !internal) {
1733                                   free(info.x11.desktop.name);
1734                                   info.x11.desktop.name = NULL;
1735                                 }
1736                                 if(info.x11.desktop.all_names && !internal) {
1737                                   free(info.x11.desktop.all_names);
1738                                   info.x11.desktop.all_names = NULL;
1739                                 }
1740                                 break;
1741 #endif /* X11 */
1742                 }
1743                 free(obj);
1744         }
1745 #undef data
1746 }
1747