diskio: 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                 parse_diskio_arg(obj, arg);
400         END OBJ(diskio_read, &update_diskio)
401                 parse_diskio_arg(obj, arg);
402         END OBJ(diskio_write, &update_diskio)
403                 parse_diskio_arg(obj, arg);
404 #ifdef X11
405         END OBJ(diskiograph, &update_diskio)
406                 parse_diskiograph_arg(obj, arg);
407         END OBJ(diskiograph_read, &update_diskio)
408                 parse_diskiograph_arg(obj, arg);
409         END OBJ(diskiograph_write, &update_diskio)
410                 parse_diskiograph_arg(obj, arg);
411 #endif /* X11 */
412         END OBJ(color, 0)
413 #ifdef X11
414                 if (output_methods & TO_X) {
415                         obj->data.l = arg ? get_x11_color(arg) : default_fg_color;
416                         set_current_text_color(obj->data.l);
417                 }
418 #endif /* X11 */
419 #ifdef NCURSES
420                 if (output_methods & TO_NCURSES) {
421                         obj->data.l = COLOR_WHITE;
422                         if(arg) {
423                                 if(strcasecmp(arg, "red") == 0) {
424                                         obj->data.l = COLOR_RED;
425                                 }else if(strcasecmp(arg, "green") == 0) {
426                                         obj->data.l = COLOR_GREEN;
427                                 }else if(strcasecmp(arg, "yellow") == 0) {
428                                         obj->data.l = COLOR_YELLOW;
429                                 }else if(strcasecmp(arg, "blue") == 0) {
430                                         obj->data.l = COLOR_BLUE;
431                                 }else if(strcasecmp(arg, "magenta") == 0) {
432                                         obj->data.l = COLOR_MAGENTA;
433                                 }else if(strcasecmp(arg, "cyan") == 0) {
434                                         obj->data.l = COLOR_CYAN;
435                                 }else if(strcasecmp(arg, "black") == 0) {
436                                         obj->data.l = COLOR_BLACK;
437                                 }
438                         }
439                         set_current_text_color(obj->data.l);
440                         init_pair(obj->data.l, obj->data.l, COLOR_BLACK);
441                 }
442 #endif /* NCURSES */
443         END OBJ(color0, 0)
444                 obj->data.l = color0;
445                 set_current_text_color(obj->data.l);
446         END OBJ(color1, 0)
447                 obj->data.l = color1;
448                 set_current_text_color(obj->data.l);
449         END OBJ(color2, 0)
450                 obj->data.l = color2;
451                 set_current_text_color(obj->data.l);
452         END OBJ(color3, 0)
453                 obj->data.l = color3;
454                 set_current_text_color(obj->data.l);
455         END OBJ(color4, 0)
456                 obj->data.l = color4;
457                 set_current_text_color(obj->data.l);
458         END OBJ(color5, 0)
459                 obj->data.l = color5;
460                 set_current_text_color(obj->data.l);
461         END OBJ(color6, 0)
462                 obj->data.l = color6;
463                 set_current_text_color(obj->data.l);
464         END OBJ(color7, 0)
465                 obj->data.l = color7;
466                 set_current_text_color(obj->data.l);
467         END OBJ(color8, 0)
468                 obj->data.l = color8;
469                 set_current_text_color(obj->data.l);
470         END OBJ(color9, 0)
471                 obj->data.l = color9;
472                 set_current_text_color(obj->data.l);
473 #ifdef X11
474         END OBJ(font, 0)
475                 obj->data.s = scan_font(arg);
476 #endif /* X11 */
477         END OBJ(conky_version, 0)
478         END OBJ(conky_build_date, 0)
479         END OBJ(conky_build_arch, 0)
480         END OBJ(downspeed, &update_net_stats)
481                 parse_net_stat_arg(obj, arg, free_at_crash);
482         END OBJ(downspeedf, &update_net_stats)
483                 parse_net_stat_arg(obj, arg, free_at_crash);
484 #ifdef X11
485         END OBJ(downspeedgraph, &update_net_stats)
486                 parse_net_stat_graph_arg(obj, arg, free_at_crash);
487 #endif /* X11 */
488         END OBJ(else, 0)
489                 obj_be_ifblock_else(ifblock_opaque, obj);
490         END OBJ(endif, 0)
491                 obj_be_ifblock_endif(ifblock_opaque, obj);
492         END OBJ(eval, 0)
493                 obj->data.s = strndup(arg ? arg : "", text_buffer_size);
494 #if defined(IMLIB2) && defined(X11)
495         END OBJ(image, 0)
496                 obj->data.s = strndup(arg ? arg : "", text_buffer_size);
497 #endif /* IMLIB2 */
498         END OBJ(exec, 0)
499                 scan_exec_arg(obj, arg);
500         END OBJ(execp, 0)
501                 scan_exec_arg(obj, arg);
502         END OBJ(execbar, 0)
503                 SIZE_DEFAULTS(bar);
504                 scan_exec_arg(obj, arg);
505 #ifdef X11
506         END OBJ(execgauge, 0)
507                 SIZE_DEFAULTS(gauge);
508                 scan_exec_arg(obj, arg);
509         END OBJ(execgraph, 0)
510                 SIZE_DEFAULTS(graph);
511                 scan_exec_arg(obj, arg);
512 #endif /* X11 */
513         END OBJ_ARG(execibar, 0, "execibar needs arguments")
514                 SIZE_DEFAULTS(bar);
515                 scan_execi_arg(obj, arg);
516 #ifdef X11
517         END OBJ_ARG(execigraph, 0, "execigraph needs arguments")
518                 SIZE_DEFAULTS(graph);
519                 scan_execi_arg(obj, arg);
520         END OBJ_ARG(execigauge, 0, "execigauge needs arguments")
521                 SIZE_DEFAULTS(gauge);
522                 scan_execi_arg(obj, arg);
523 #endif /* X11 */
524         END OBJ_ARG(execi, 0, "execi needs arguments")
525                 scan_execi_arg(obj, arg);
526         END OBJ_ARG(execpi, 0, "execpi needs arguments")
527                 scan_execi_arg(obj, arg);
528         END OBJ_ARG(texeci, 0, "texeci needs arguments")
529                 scan_execi_arg(obj, arg);
530         END OBJ(pre_exec, 0)
531                 scan_pre_exec_arg(obj, arg);
532         END OBJ(fs_bar, &update_fs_stats)
533                 init_fs_bar(obj, arg);
534         END OBJ(fs_bar_free, &update_fs_stats)
535                 init_fs_bar(obj, arg);
536         END OBJ(fs_free, &update_fs_stats)
537                 init_fs(obj, arg);
538         END OBJ(fs_used_perc, &update_fs_stats)
539                 init_fs(obj, arg);
540         END OBJ(fs_free_perc, &update_fs_stats)
541                 init_fs(obj, arg);
542         END OBJ(fs_size, &update_fs_stats)
543                 init_fs(obj, arg);
544         END OBJ(fs_type, &update_fs_stats)
545                 init_fs(obj, arg);
546         END OBJ(fs_used, &update_fs_stats)
547                 init_fs(obj, arg);
548         END OBJ(hr, 0)
549                 obj->data.i = arg ? atoi(arg) : 1;
550         END OBJ(nameserver, &update_dns_data)
551                 parse_nameserver_arg(obj, arg);
552         END OBJ(offset, 0)
553                 obj->data.i = arg ? atoi(arg) : 1;
554         END OBJ(voffset, 0)
555                 obj->data.i = arg ? atoi(arg) : 1;
556         END OBJ_ARG(goto, 0, "goto needs arguments")
557                 obj->data.i = atoi(arg);
558         END OBJ(tab, 0)
559                 int a = 10, b = 0;
560
561                 if (arg) {
562                         if (sscanf(arg, "%d %d", &a, &b) != 2) {
563                                 sscanf(arg, "%d", &b);
564                         }
565                 }
566                 if (a <= 0) {
567                         a = 1;
568                 }
569                 obj->data.pair.a = a;
570                 obj->data.pair.b = b;
571
572 #ifdef __linux__
573         END OBJ_ARG(i2c, 0, "i2c needs arguments")
574                 parse_i2c_sensor(obj, arg);
575         END OBJ_ARG(platform, 0, "platform needs arguments")
576                 parse_platform_sensor(obj, arg);
577         END OBJ_ARG(hwmon, 0, "hwmon needs argumanets")
578                 parse_hwmon_sensor(obj, arg);
579 #endif /* __linux__ */
580
581         END
582         /* we have four different types of top (top, top_mem, top_time and top_io). To
583          * avoid having almost-same code four times, we have this special
584          * handler. */
585         if (strncmp(s, "top", 3) == EQUAL) {
586                 add_update_callback(&update_meminfo);
587                 add_update_callback(&update_top);
588                 if (!parse_top_args(s, arg, obj)) {
589                         return NULL;
590                 }
591         } else OBJ(addr, &update_net_stats)
592                 parse_net_stat_arg(obj, arg, free_at_crash);
593 #if defined(__linux__)
594         END OBJ(addrs, &update_net_stats)
595                 parse_net_stat_arg(obj, arg, free_at_crash);
596 #endif /* __linux__ */
597         END OBJ_ARG(tail, 0, "tail needs arguments")
598                 init_tailhead("tail", arg, obj, free_at_crash);
599         END OBJ_ARG(head, 0, "head needs arguments")
600                 init_tailhead("head", arg, obj, free_at_crash);
601         END OBJ_ARG(lines, 0, "lines needs an argument")
602                 obj->data.s = strndup(arg, text_buffer_size);
603         END OBJ_ARG(words, 0, "words needs a argument")
604                 obj->data.s = strndup(arg, text_buffer_size);
605         END OBJ(loadavg, &update_load_average)
606                 int a = 1, b = 2, c = 3, r = 3;
607
608                 if (arg) {
609                         r = sscanf(arg, "%d %d %d", &a, &b, &c);
610                         if (r >= 3 && (c < 1 || c > 3)) {
611                                 r--;
612                         }
613                         if (r >= 2 && (b < 1 || b > 3)) {
614                                 r--, b = c;
615                         }
616                         if (r >= 1 && (a < 1 || a > 3)) {
617                                 r--, a = b, b = c;
618                         }
619                 }
620                 obj->data.loadavg[0] = (r >= 1) ? (unsigned char) a : 0;
621                 obj->data.loadavg[1] = (r >= 2) ? (unsigned char) b : 0;
622                 obj->data.loadavg[2] = (r >= 3) ? (unsigned char) c : 0;
623         END OBJ_IF_ARG(if_empty, 0, "if_empty needs an argument")
624                 obj->data.ifblock.s = strndup(arg, text_buffer_size);
625                 obj->sub = malloc(sizeof(struct text_object));
626                 extract_variable_text_internal(obj->sub, obj->data.ifblock.s);
627         END OBJ_IF_ARG(if_match, 0, "if_match needs arguments")
628                 obj->data.ifblock.s = strndup(arg, text_buffer_size);
629                 obj->sub = malloc(sizeof(struct text_object));
630                 extract_variable_text_internal(obj->sub, obj->data.ifblock.s);
631         END OBJ_IF_ARG(if_existing, 0, "if_existing needs an argument or two")
632                 char buf1[256], buf2[256];
633                 int r = sscanf(arg, "%255s %255[^\n]", buf1, buf2);
634
635                 if (r == 1) {
636                         obj->data.ifblock.s = strndup(buf1, text_buffer_size);
637                         obj->data.ifblock.str = NULL;
638                 } else {
639                         obj->data.ifblock.s = strndup(buf1, text_buffer_size);
640                         obj->data.ifblock.str = strndup(buf2, text_buffer_size);
641                 }
642                 DBGP("if_existing: '%s' '%s'", obj->data.ifblock.s, obj->data.ifblock.str);
643         END OBJ_IF_ARG(if_mounted, 0, "if_mounted needs an argument")
644                 obj->data.ifblock.s = strndup(arg, text_buffer_size);
645 #ifdef __linux__
646         END OBJ_IF_ARG(if_running, &update_top, "if_running needs an argument")
647                 top_running = 1;
648                 obj->data.ifblock.s = strndup(arg, text_buffer_size);
649 #else
650         END OBJ_IF_ARG(if_running, 0, "if_running needs an argument")
651                 char buf[256];
652
653                 snprintf(buf, 256, "pidof %s >/dev/null", arg);
654                 obj->data.ifblock.s = strndup(buf, text_buffer_size);
655 #endif
656         END OBJ(kernel, 0)
657         END OBJ(machine, 0)
658         END OBJ(mails, 0)
659                 parse_local_mail_args(obj, arg);
660         END OBJ(new_mails, 0)
661                 parse_local_mail_args(obj, arg);
662         END OBJ(seen_mails, 0)
663                 parse_local_mail_args(obj, arg);
664         END OBJ(unseen_mails, 0)
665                 parse_local_mail_args(obj, arg);
666         END OBJ(flagged_mails, 0)
667                 parse_local_mail_args(obj, arg);
668         END OBJ(unflagged_mails, 0)
669                 parse_local_mail_args(obj, arg);
670         END OBJ(forwarded_mails, 0)
671                 parse_local_mail_args(obj, arg);
672         END OBJ(unforwarded_mails, 0)
673                 parse_local_mail_args(obj, arg);
674         END OBJ(replied_mails, 0)
675                 parse_local_mail_args(obj, arg);
676         END OBJ(unreplied_mails, 0)
677                 parse_local_mail_args(obj, arg);
678         END OBJ(draft_mails, 0)
679                 parse_local_mail_args(obj, arg);
680         END OBJ(trashed_mails, 0)
681                 parse_local_mail_args(obj, arg);
682         END OBJ(mboxscan, 0)
683                 parse_mboxscan_arg(obj, arg);
684         END OBJ(mem, &update_meminfo)
685         END OBJ(memeasyfree, &update_meminfo)
686         END OBJ(memfree, &update_meminfo)
687         END OBJ(memmax, &update_meminfo)
688         END OBJ(memperc, &update_meminfo)
689 #ifdef X11
690         END OBJ(memgauge, &update_meminfo)
691                 SIZE_DEFAULTS(gauge);
692                 scan_gauge(arg, &obj->data.pair.a, &obj->data.pair.b);
693 #endif /* X11*/
694         END OBJ(membar, &update_meminfo)
695                 SIZE_DEFAULTS(bar);
696                 scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
697 #ifdef X11
698         END OBJ(memgraph, &update_meminfo)
699                 char *buf = 0;
700                 SIZE_DEFAULTS(graph);
701                 buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
702                                 &obj->e, &obj->char_a, &obj->char_b);
703
704                 if (buf) free(buf);
705 #endif /* X11*/
706         END OBJ(mixer, 0)
707                 parse_mixer_arg(obj, arg);
708         END OBJ(mixerl, 0)
709                 parse_mixer_arg(obj, arg);
710         END OBJ(mixerr, 0)
711                 parse_mixer_arg(obj, arg);
712 #ifdef X11
713         END OBJ(mixerbar, 0)
714                 scan_mixer_bar(obj, arg);
715         END OBJ(mixerlbar, 0)
716                 scan_mixer_bar(obj, arg);
717         END OBJ(mixerrbar, 0)
718                 scan_mixer_bar(obj, arg);
719 #endif
720         END OBJ_IF(if_mixer_mute, 0)
721                 parse_mixer_arg(obj, arg);
722 #ifdef X11
723         END OBJ(monitor, &update_x11info)
724         END OBJ(monitor_number, &update_x11info)
725         END OBJ(desktop, &update_x11info)
726         END OBJ(desktop_number, &update_x11info)
727         END OBJ(desktop_name, &update_x11info)
728 #endif
729         END OBJ(nodename, 0)
730         END OBJ(processes, &update_total_processes)
731         END OBJ(running_processes, &update_running_processes)
732         END OBJ(shadecolor, 0)
733 #ifdef X11
734                 obj->data.l = arg ? get_x11_color(arg) : default_bg_color;
735 #endif /* X11 */
736         END OBJ(outlinecolor, 0)
737 #ifdef X11
738                 obj->data.l = arg ? get_x11_color(arg) : default_out_color;
739 #endif /* X11 */
740         END OBJ(stippled_hr, 0)
741 #ifdef X11
742                 int a = get_stippled_borders(), b = 1;
743
744                 if (arg) {
745                         if (sscanf(arg, "%d %d", &a, &b) != 2) {
746                                 sscanf(arg, "%d", &b);
747                         }
748                 }
749                 if (a <= 0) {
750                         a = 1;
751                 }
752                 obj->data.pair.a = a;
753                 obj->data.pair.b = b;
754 #endif /* X11 */
755         END OBJ(swap, &update_meminfo)
756         END OBJ(swapfree, &update_meminfo)
757         END OBJ(swapmax, &update_meminfo)
758         END OBJ(swapperc, &update_meminfo)
759         END OBJ(swapbar, &update_meminfo)
760                 SIZE_DEFAULTS(bar);
761                 scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
762         END OBJ(sysname, 0)
763         END OBJ(time, 0)
764                 scan_time(obj, arg);
765         END OBJ(utime, 0)
766                 scan_time(obj, arg);
767         END OBJ(tztime, 0)
768                 scan_tztime(obj, arg);
769 #ifdef HAVE_ICONV
770         END OBJ_ARG(iconv_start, 0, "Iconv requires arguments")
771                 init_iconv_start(obj, free_at_crash, arg);
772         END OBJ(iconv_stop, 0)
773                 init_iconv_stop();
774 #endif
775         END OBJ(totaldown, &update_net_stats)
776                 parse_net_stat_arg(obj, arg, free_at_crash);
777         END OBJ(totalup, &update_net_stats)
778                 parse_net_stat_arg(obj, arg, free_at_crash);
779         END OBJ(updates, 0)
780         END OBJ_IF(if_updatenr, 0)
781                 obj->data.ifblock.i = arg ? atoi(arg) : 0;
782                 if(obj->data.ifblock.i == 0) CRIT_ERR(obj, free_at_crash, "if_updatenr needs a number above 0 as argument");
783                 set_updatereset(obj->data.ifblock.i > get_updatereset() ? obj->data.ifblock.i : get_updatereset());
784         END OBJ(alignr, 0)
785                 obj->data.i = arg ? atoi(arg) : 0;
786         END OBJ(alignc, 0)
787                 obj->data.i = arg ? atoi(arg) : 0;
788         END OBJ(upspeed, &update_net_stats)
789                 parse_net_stat_arg(obj, arg, free_at_crash);
790         END OBJ(upspeedf, &update_net_stats)
791                 parse_net_stat_arg(obj, arg, free_at_crash);
792 #ifdef X11
793         END OBJ(upspeedgraph, &update_net_stats)
794                 parse_net_stat_graph_arg(obj, arg, free_at_crash);
795 #endif
796         END OBJ(uptime_short, &update_uptime)
797         END OBJ(uptime, &update_uptime)
798         END OBJ(user_names, &update_users)
799         END OBJ(user_times, &update_users)
800         END OBJ(user_terms, &update_users)
801         END OBJ(user_number, &update_users)
802 #if defined(__linux__)
803         END OBJ(gw_iface, &update_gateway_info)
804         END OBJ(gw_ip, &update_gateway_info)
805 #endif /* !__linux__ */
806 #ifndef __OpenBSD__
807         END OBJ(adt746xcpu, 0)
808         END OBJ(adt746xfan, 0)
809 #endif /* !__OpenBSD__ */
810 #if (defined(__FreeBSD__) || defined(__FreeBSD_kernel__) \
811                 || defined(__OpenBSD__)) && (defined(i386) || defined(__i386__))
812         END OBJ(apm_adapter, 0)
813         END OBJ(apm_battery_life, 0)
814         END OBJ(apm_battery_time, 0)
815 #endif /* __FreeBSD__ */
816         END OBJ(imap_unseen, 0)
817                 parse_imap_mail_args(obj, arg);
818         END OBJ(imap_messages, 0)
819                 parse_imap_mail_args(obj, arg);
820         END OBJ(pop3_unseen, 0)
821                 parse_pop3_mail_args(obj, arg);
822         END OBJ(pop3_used, 0)
823                 parse_pop3_mail_args(obj, arg);
824 #ifdef IBM
825         END OBJ_ARG(smapi, 0, "smapi needs an argument")
826                 obj->data.s = strndup(arg, text_buffer_size);
827         END OBJ_IF_ARG(if_smapi_bat_installed, 0, "if_smapi_bat_installed needs an argument")
828                 obj->data.ifblock.s = strndup(arg, text_buffer_size);
829         END OBJ_ARG(smapi_bat_perc, 0, "smapi_bat_perc needs an argument")
830                 obj->data.s = strndup(arg, text_buffer_size);
831         END OBJ_ARG(smapi_bat_temp, 0, "smapi_bat_temp needs an argument")
832                 obj->data.s = strndup(arg, text_buffer_size);
833         END OBJ_ARG(smapi_bat_power, 0, "smapi_bat_power needs an argument")
834                 obj->data.s = strndup(arg, text_buffer_size);
835 #ifdef X11
836         END OBJ_ARG(smapi_bat_bar, 0, "smapi_bat_bar needs an argument")
837                 int cnt;
838                 SIZE_DEFAULTS(bar);
839                 if(sscanf(arg, "%i %n", &obj->data.i, &cnt) <= 0) {
840                         NORM_ERR("first argument to smapi_bat_bar must be an integer value");
841                         obj->data.i = -1;
842                 } else {
843                         obj->b = 4;
844                         arg = scan_bar(arg + cnt, &obj->a, &obj->b);
845                 }
846 #endif /* X11 */
847 #endif /* IBM */
848 #ifdef MPD
849 #define mpd_set_maxlen(name) \
850                 if (arg) { \
851                         int i; \
852                         sscanf(arg, "%d", &i); \
853                         if (i > 0) \
854                                 obj->data.i = i + 1; \
855                         else \
856                                 NORM_ERR(#name ": invalid length argument"); \
857                 }
858         END OBJ(mpd_artist, &update_mpd)
859                 mpd_set_maxlen(mpd_artist);
860                 init_mpd();
861         END OBJ(mpd_title, &update_mpd)
862                 mpd_set_maxlen(mpd_title);
863                 init_mpd();
864         END OBJ(mpd_random, &update_mpd) init_mpd();
865         END OBJ(mpd_repeat, &update_mpd) init_mpd();
866         END OBJ(mpd_elapsed, &update_mpd) init_mpd();
867         END OBJ(mpd_length, &update_mpd) init_mpd();
868         END OBJ(mpd_track, &update_mpd)
869                 mpd_set_maxlen(mpd_track);
870                 init_mpd();
871         END OBJ(mpd_name, &update_mpd)
872                 mpd_set_maxlen(mpd_name);
873                 init_mpd();
874         END OBJ(mpd_file, &update_mpd)
875                 mpd_set_maxlen(mpd_file);
876                 init_mpd();
877         END OBJ(mpd_percent, &update_mpd) init_mpd();
878         END OBJ(mpd_album, &update_mpd)
879                 mpd_set_maxlen(mpd_album);
880                 init_mpd();
881         END OBJ(mpd_vol, &update_mpd) init_mpd();
882         END OBJ(mpd_bitrate, &update_mpd) init_mpd();
883         END OBJ(mpd_status, &update_mpd) init_mpd();
884         END OBJ(mpd_bar, &update_mpd)
885                 SIZE_DEFAULTS(bar);
886                 scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
887                 init_mpd();
888         END OBJ(mpd_smart, &update_mpd)
889                 mpd_set_maxlen(mpd_smart);
890                 init_mpd();
891         END OBJ_IF(if_mpd_playing, &update_mpd)
892                 init_mpd();
893 #undef mpd_set_maxlen
894 #endif /* MPD */
895 #ifdef MOC
896         END OBJ(moc_state, &update_moc)
897         END OBJ(moc_file, &update_moc)
898         END OBJ(moc_title, &update_moc)
899         END OBJ(moc_artist, &update_moc)
900         END OBJ(moc_song, &update_moc)
901         END OBJ(moc_album, &update_moc)
902         END OBJ(moc_totaltime, &update_moc)
903         END OBJ(moc_timeleft, &update_moc)
904         END OBJ(moc_curtime, &update_moc)
905         END OBJ(moc_bitrate, &update_moc)
906         END OBJ(moc_rate, &update_moc)
907 #endif /* MOC */
908 #ifdef XMMS2
909         END OBJ(xmms2_artist, &update_xmms2)
910         END OBJ(xmms2_album, &update_xmms2)
911         END OBJ(xmms2_title, &update_xmms2)
912         END OBJ(xmms2_genre, &update_xmms2)
913         END OBJ(xmms2_comment, &update_xmms2)
914         END OBJ(xmms2_url, &update_xmms2)
915         END OBJ(xmms2_tracknr, &update_xmms2)
916         END OBJ(xmms2_bitrate, &update_xmms2)
917         END OBJ(xmms2_date, &update_xmms2)
918         END OBJ(xmms2_id, &update_xmms2)
919         END OBJ(xmms2_duration, &update_xmms2)
920         END OBJ(xmms2_elapsed, &update_xmms2)
921         END OBJ(xmms2_size, &update_xmms2)
922         END OBJ(xmms2_status, &update_xmms2)
923         END OBJ(xmms2_percent, &update_xmms2)
924 #ifdef X11
925         END OBJ(xmms2_bar, &update_xmms2)
926                 SIZE_DEFAULTS(bar);
927                 scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
928 #endif /* X11 */
929         END OBJ(xmms2_smart, &update_xmms2)
930         END OBJ(xmms2_playlist, &update_xmms2)
931         END OBJ(xmms2_timesplayed, &update_xmms2)
932         END OBJ_IF(if_xmms2_connected, &update_xmms2)
933 #endif
934 #ifdef AUDACIOUS
935         END OBJ(audacious_status, &update_audacious)
936         END OBJ_ARG(audacious_title, &update_audacious, "audacious_title needs an argument")
937                 sscanf(arg, "%d", &info.audacious.max_title_len);
938                 if (info.audacious.max_title_len > 0) {
939                         info.audacious.max_title_len++;
940                 } else {
941                         CRIT_ERR(obj, free_at_crash, "audacious_title: invalid length argument");
942                 }
943         END OBJ(audacious_length, &update_audacious)
944         END OBJ(audacious_length_seconds, &update_audacious)
945         END OBJ(audacious_position, &update_audacious)
946         END OBJ(audacious_position_seconds, &update_audacious)
947         END OBJ(audacious_bitrate, &update_audacious)
948         END OBJ(audacious_frequency, &update_audacious)
949         END OBJ(audacious_channels, &update_audacious)
950         END OBJ(audacious_filename, &update_audacious)
951         END OBJ(audacious_playlist_length, &update_audacious)
952         END OBJ(audacious_playlist_position, &update_audacious)
953         END OBJ(audacious_main_volume, &update_audacious)
954 #ifdef X11
955         END OBJ(audacious_bar, &update_audacious)
956                 SIZE_DEFAULTS(bar);
957                 scan_bar(arg, &obj->a, &obj->b);
958 #endif /* X11 */
959 #endif
960 #ifdef BMPX
961         END OBJ(bmpx_title, &update_bmpx)
962                 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
963         END OBJ(bmpx_artist, &update_bmpx)
964                 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
965         END OBJ(bmpx_album, &update_bmpx)
966                 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
967         END OBJ(bmpx_track, &update_bmpx)
968                 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
969         END OBJ(bmpx_uri, &update_bmpx)
970                 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
971         END OBJ(bmpx_bitrate, &update_bmpx)
972                 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
973 #endif
974 #ifdef EVE
975         END OBJ_ARG(eve, 0, "eve needs arguments: <userid> <apikey> <characterid>")
976                 scan_eve(obj, arg);
977 #endif
978 #ifdef HAVE_CURL
979         END OBJ_ARG(curl, 0, "curl needs arguments: <uri> <interval in minutes>")
980                 curl_parse_arg(obj, arg);
981 #endif
982 #ifdef RSS
983         END OBJ_ARG(rss, 0, "rss needs arguments: <uri> <interval in minutes> <action> [act_par] [spaces in front]")
984                 rss_scan_arg(obj, arg);
985 #endif
986 #ifdef WEATHER
987         END OBJ_ARG(weather, 0, "weather needs arguments: <uri> <locID> <data_type> [interval in minutes]")
988                 scan_weather_arg(obj, arg, free_at_crash);
989 #endif
990 #ifdef XOAP
991         END OBJ_ARG(weather_forecast, 0, "weather_forecast needs arguments: <uri> <locID> <day> <data_type> [interval in minutes]")
992                 scan_weather_forecast_arg(obj, arg, free_at_crash);
993 #endif
994 #ifdef HAVE_LUA
995         END OBJ_ARG(lua, 0, "lua needs arguments: <function name> [function parameters]")
996                 obj->data.s = strndup(arg, text_buffer_size);
997         END OBJ_ARG(lua_parse, 0, "lua_parse needs arguments: <function name> [function parameters]")
998                 obj->data.s = strndup(arg, text_buffer_size);
999         END OBJ_ARG(lua_bar, 0, "lua_bar needs arguments: <height>,<width> <function name> [function parameters]")
1000                 SIZE_DEFAULTS(bar);
1001                 arg = scan_bar(arg, &obj->a, &obj->b);
1002                 if(arg) {
1003                         obj->data.s = strndup(arg, text_buffer_size);
1004                 } else {
1005                         CRIT_ERR(obj, free_at_crash, "lua_bar needs arguments: <height>,<width> <function name> [function parameters]");
1006                 }
1007 #ifdef X11
1008         END OBJ_ARG(lua_graph, 0, "lua_graph needs arguments: <function name> [height],[width] [gradient colour 1] [gradient colour 2] [scale] [-t] [-l]")
1009                 char *buf = 0;
1010                 SIZE_DEFAULTS(graph);
1011                 buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
1012                                 &obj->e, &obj->char_a, &obj->char_b);
1013                 if (buf) {
1014                         obj->data.s = buf;
1015                 } else {
1016                         CRIT_ERR(obj, free_at_crash, "lua_graph needs arguments: <function name> [height],[width] [gradient colour 1] [gradient colour 2] [scale] [-t] [-l]");
1017                 }
1018         END OBJ_ARG(lua_gauge, 0, "lua_gauge needs arguments: <height>,<width> <function name> [function parameters]")
1019                 SIZE_DEFAULTS(gauge);
1020                 arg = scan_gauge(arg, &obj->a, &obj->b);
1021                 if (arg) {
1022                         obj->data.s = strndup(arg, text_buffer_size);
1023                 } else {
1024                         CRIT_ERR(obj, free_at_crash, "lua_gauge needs arguments: <height>,<width> <function name> [function parameters]");
1025                 }
1026 #endif /* X11 */
1027 #endif /* HAVE_LUA */
1028 #ifdef HDDTEMP
1029         END OBJ(hddtemp, &update_hddtemp)
1030                 if (arg)
1031                         obj->data.s = strndup(arg, text_buffer_size);
1032 #endif /* HDDTEMP */
1033 #ifdef TCP_PORT_MONITOR
1034         END OBJ_ARG(tcp_portmon, &tcp_portmon_update, "tcp_portmon: needs arguments")
1035                 tcp_portmon_init(obj, arg);
1036 #endif /* TCP_PORT_MONITOR */
1037         END OBJ(entropy_avail, &update_entropy)
1038         END OBJ(entropy_perc, &update_entropy)
1039         END OBJ(entropy_poolsize, &update_entropy)
1040         END OBJ(entropy_bar, &update_entropy)
1041                 SIZE_DEFAULTS(bar);
1042                 scan_bar(arg, &obj->a, &obj->b);
1043         END OBJ_ARG(include, 0, "include needs a argument")
1044                 struct conftree *leaf = conftree_add(currentconffile, arg);
1045                 if(leaf) {
1046                         if (load_config_file(arg) == TRUE) {
1047                                 obj->sub = malloc(sizeof(struct text_object));
1048                                 currentconffile = leaf;
1049                                 extract_variable_text_internal(obj->sub, get_global_text());
1050                                 currentconffile = leaf->back;
1051                         } else {
1052                                 NORM_ERR("Can't load configfile '%s'.", arg);
1053                         }
1054                 } else {
1055                         NORM_ERR("You are trying to load '%s' recursively, I'm only going to load it once to prevent an infinite loop.", arg);
1056                 }
1057         END OBJ_ARG(blink, 0, "blink needs a argument")
1058                 obj->sub = malloc(sizeof(struct text_object));
1059                 extract_variable_text_internal(obj->sub, arg);
1060         END OBJ_ARG(to_bytes, 0, "to_bytes needs a argument")
1061                 obj->sub = malloc(sizeof(struct text_object));
1062                 extract_variable_text_internal(obj->sub, arg);
1063         END OBJ(scroll, 0)
1064                 parse_scroll_arg(obj, arg, free_at_crash);
1065         END OBJ_ARG(combine, 0, "combine needs arguments: <text1> <text2>")
1066                 parse_combine_arg(obj, arg, free_at_crash);
1067 #ifdef NVIDIA
1068         END OBJ_ARG(nvidia, 0, "nvidia needs an argument")
1069                 if (set_nvidia_type(obj, arg)) {
1070                         CRIT_ERR(obj, free_at_crash, "nvidia: invalid argument"
1071                                  " specified: '%s'\n", arg);
1072                 }
1073 #endif /* NVIDIA */
1074 #ifdef APCUPSD
1075         END OBJ_ARG(apcupsd, &update_apcupsd, "apcupsd needs arguments: <host> <port>")
1076                 char host[64];
1077                 int port;
1078                 if (sscanf(arg, "%63s %d", host, &port) != 2) {
1079                         CRIT_ERR(obj, free_at_crash, "apcupsd needs arguments: <host> <port>");
1080                 } else {
1081                         info.apcupsd.port = htons(port);
1082                         strncpy(info.apcupsd.host, host, sizeof(info.apcupsd.host));
1083                 }
1084         END OBJ(apcupsd_name, &update_apcupsd)
1085         END OBJ(apcupsd_model, &update_apcupsd)
1086         END OBJ(apcupsd_upsmode, &update_apcupsd)
1087         END OBJ(apcupsd_cable, &update_apcupsd)
1088         END OBJ(apcupsd_status, &update_apcupsd)
1089         END OBJ(apcupsd_linev, &update_apcupsd)
1090         END OBJ(apcupsd_load, &update_apcupsd)
1091         END OBJ(apcupsd_loadbar, &update_apcupsd)
1092                 SIZE_DEFAULTS(bar);
1093                 scan_bar(arg, &obj->a, &obj->b);
1094 #ifdef X11
1095         END OBJ(apcupsd_loadgraph, &update_apcupsd)
1096                 char* buf = 0;
1097                 SIZE_DEFAULTS(graph);
1098                 buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
1099                                 &obj->e, &obj->char_a, &obj->char_b);
1100                 if (buf) free(buf);
1101         END OBJ(apcupsd_loadgauge, &update_apcupsd)
1102                 SIZE_DEFAULTS(gauge);
1103                 scan_gauge(arg, &obj->a, &obj->b);
1104 #endif /* X11 */
1105         END OBJ(apcupsd_charge, &update_apcupsd)
1106         END OBJ(apcupsd_timeleft, &update_apcupsd)
1107         END OBJ(apcupsd_temp, &update_apcupsd)
1108         END OBJ(apcupsd_lastxfer, &update_apcupsd)
1109 #endif /* APCUPSD */
1110         END {
1111                 char buf[256];
1112
1113                 NORM_ERR("unknown variable %s", s);
1114                 obj->type = OBJ_text;
1115                 snprintf(buf, 256, "${%s}", s);
1116                 obj->data.s = strndup(buf, text_buffer_size);
1117         }
1118 #undef OBJ
1119 #undef OBJ_IF
1120 #undef OBJ_ARG
1121 #undef OBJ_IF_ARG
1122 #undef __OBJ_HEAD
1123 #undef __OBJ_IF
1124 #undef __OBJ_ARG
1125 #undef END
1126 #undef SIZE_DEFAULTS
1127
1128         return obj;
1129 }
1130
1131 /*
1132  * - assumes that *string is '#'
1133  * - removes the part from '#' to the end of line ('\n' or '\0')
1134  * - it removes the '\n'
1135  * - copies the last char into 'char *last' argument, which should be a pointer
1136  *   to a char rather than a string.
1137  */
1138 static size_t remove_comment(char *string, char *last)
1139 {
1140         char *end = string;
1141         while (*end != '\0' && *end != '\n') {
1142                 ++end;
1143         }
1144         if (last) *last = *end;
1145         if (*end == '\n') end++;
1146         strfold(string, end - string);
1147         return end - string;
1148 }
1149
1150 size_t remove_comments(char *string)
1151 {
1152         char *curplace;
1153         size_t folded = 0;
1154         for (curplace = string; *curplace != 0; curplace++) {
1155                 if (*curplace == '\\' && *(curplace + 1) == '#') {
1156                         // strcpy can't be used for overlapping strings
1157                         strfold(curplace, 1);
1158                         folded += 1;
1159                 } else if (*curplace == '#') {
1160                         folded += remove_comment(curplace, 0);
1161                 }
1162         }
1163         return folded;
1164 }
1165
1166 int extract_variable_text_internal(struct text_object *retval, const char *const_p)
1167 {
1168         struct text_object *obj;
1169         char *p, *s, *orig_p;
1170         long line;
1171         void *ifblock_opaque = NULL;
1172         char *tmp_p;
1173         char *arg = 0;
1174         size_t len = 0;
1175
1176         p = strndup(const_p, max_user_text - 1);
1177         while (text_contains_templates(p)) {
1178                 char *tmp;
1179                 tmp = find_and_replace_templates(p);
1180                 free(p);
1181                 p = tmp;
1182         }
1183         s = orig_p = p;
1184
1185         if (strcmp(p, const_p)) {
1186                 DBGP("replaced all templates in text: input is\n'%s'\noutput is\n'%s'", const_p, p);
1187         } else {
1188                 DBGP("no templates to replace");
1189         }
1190
1191         memset(retval, 0, sizeof(struct text_object));
1192
1193         line = global_text_lines;
1194
1195         while (*p) {
1196                 if (*p == '\n') {
1197                         line++;
1198                 }
1199                 if (*p == '$') {
1200                         *p = '\0';
1201                         obj = create_plain_text(s);
1202                         if (obj != NULL) {
1203                                 append_object(retval, obj);
1204                         }
1205                         *p = '$';
1206                         p++;
1207                         s = p;
1208
1209                         if (*p != '$') {
1210                                 char buf[256];
1211                                 const char *var;
1212
1213                                 /* variable is either $foo or ${foo} */
1214                                 if (*p == '{') {
1215                                         unsigned int brl = 1, brr = 0;
1216
1217                                         p++;
1218                                         s = p;
1219                                         while (*p && brl != brr) {
1220                                                 if (*p == '{') {
1221                                                         brl++;
1222                                                 }
1223                                                 if (*p == '}') {
1224                                                         brr++;
1225                                                 }
1226                                                 p++;
1227                                         }
1228                                         p--;
1229                                 } else {
1230                                         s = p;
1231                                         if (*p == '#') {
1232                                                 p++;
1233                                         }
1234                                         while (*p && (isalnum((int) *p) || *p == '_')) {
1235                                                 p++;
1236                                         }
1237                                 }
1238
1239                                 /* copy variable to buffer */
1240                                 len = (p - s > 255) ? 255 : (p - s);
1241                                 strncpy(buf, s, len);
1242                                 buf[len] = '\0';
1243
1244                                 if (*p == '}') {
1245                                         p++;
1246                                 }
1247                                 s = p;
1248
1249                                 /* search for variable in environment */
1250
1251                                 var = getenv(buf);
1252                                 if (var) {
1253                                         obj = create_plain_text(var);
1254                                         if (obj) {
1255                                                 append_object(retval, obj);
1256                                         }
1257                                         continue;
1258                                 }
1259
1260                                 /* if variable wasn't found in environment, use some special */
1261
1262                                 arg = 0;
1263
1264                                 /* split arg */
1265                                 if (strchr(buf, ' ')) {
1266                                         arg = strchr(buf, ' ');
1267                                         *arg = '\0';
1268                                         arg++;
1269                                         while (isspace((int) *arg)) {
1270                                                 arg++;
1271                                         }
1272                                         if (!*arg) {
1273                                                 arg = 0;
1274                                         }
1275                                 }
1276
1277                                 /* lowercase variable name */
1278                                 tmp_p = buf;
1279                                 while (*tmp_p) {
1280                                         *tmp_p = tolower(*tmp_p);
1281                                         tmp_p++;
1282                                 }
1283
1284                                 obj = construct_text_object(buf, arg,
1285                                                 line, &ifblock_opaque, orig_p);
1286                                 if (obj != NULL) {
1287                                         append_object(retval, obj);
1288                                 }
1289                                 continue;
1290                         } else {
1291                                 obj = create_plain_text("$");
1292                                 s = p + 1;
1293                                 if (obj != NULL) {
1294                                         append_object(retval, obj);
1295                                 }
1296                         }
1297                 } else if (*p == '\\' && *(p+1) == '#') {
1298                         strfold(p, 1);
1299                 } else if (*p == '#') {
1300                         char c;
1301                         if (remove_comment(p, &c) && p > orig_p && c == '\n') {
1302                                 /* if remove_comment removed a newline, we need to 'back up' with p */
1303                                 p--;
1304                         }
1305                 }
1306                 p++;
1307         }
1308         obj = create_plain_text(s);
1309         if (obj != NULL) {
1310                 append_object(retval, obj);
1311         }
1312
1313         if (!ifblock_stack_empty(&ifblock_opaque)) {
1314                 NORM_ERR("one or more $endif's are missing");
1315         }
1316
1317         free(orig_p);
1318         return 0;
1319 }
1320
1321 /*
1322  * Frees the list of text objects root points to.  When internal = 1, it won't
1323  * free global objects.
1324  */
1325 void free_text_objects(struct text_object *root, int internal)
1326 {
1327         struct text_object *obj;
1328
1329         if (!root->prev) {
1330                 return;
1331         }
1332
1333 #define data obj->data
1334         for (obj = root->prev; obj; obj = root->prev) {
1335                 root->prev = obj->prev;
1336                 switch (obj->type) {
1337 #ifndef __OpenBSD__
1338                         case OBJ_acpitemp:
1339                                 close(data.i);
1340                                 break;
1341 #endif /* !__OpenBSD__ */
1342 #ifdef __linux__
1343                         case OBJ_i2c:
1344                         case OBJ_platform:
1345                         case OBJ_hwmon:
1346                                 free_sysfs_sensor(obj);
1347                                 break;
1348 #endif /* __linux__ */
1349                         case OBJ_read_tcp:
1350                                 free_read_tcp(obj);
1351                                 break;
1352                         case OBJ_time:
1353                         case OBJ_utime:
1354                                 free_time(obj);
1355                                 break;
1356                         case OBJ_tztime:
1357                                 free_tztime(obj);
1358                                 break;
1359                         case OBJ_mboxscan:
1360                                 free_mboxscan(obj);
1361                                 break;
1362                         case OBJ_mails:
1363                         case OBJ_new_mails:
1364                         case OBJ_seen_mails:
1365                         case OBJ_unseen_mails:
1366                         case OBJ_flagged_mails:
1367                         case OBJ_unflagged_mails:
1368                         case OBJ_forwarded_mails:
1369                         case OBJ_unforwarded_mails:
1370                         case OBJ_replied_mails:
1371                         case OBJ_unreplied_mails:
1372                         case OBJ_draft_mails:
1373                         case OBJ_trashed_mails:
1374                                 free(data.local_mail.mbox);
1375                                 break;
1376                         case OBJ_imap_unseen:
1377                         case OBJ_imap_messages:
1378                         case OBJ_pop3_unseen:
1379                         case OBJ_pop3_used:
1380                                 free_mail_obj(obj);
1381                                 break;
1382                         case OBJ_if_empty:
1383                         case OBJ_if_match:
1384                                 free_text_objects(obj->sub, 1);
1385                                 free(obj->sub);
1386                                 /* fall through */
1387                         case OBJ_if_existing:
1388                         case OBJ_if_mounted:
1389                         case OBJ_if_running:
1390                                 free(data.ifblock.s);
1391                                 free(data.ifblock.str);
1392                                 break;
1393                         case OBJ_head:
1394                         case OBJ_tail:
1395                                 free_tailhead(obj);
1396                                 break;
1397                         case OBJ_text:
1398                         case OBJ_font:
1399                         case OBJ_image:
1400                         case OBJ_eval:
1401                         case OBJ_exec:
1402                         case OBJ_execbar:
1403 #ifdef X11
1404                         case OBJ_execgauge:
1405                         case OBJ_execgraph:
1406 #endif
1407                         case OBJ_execp:
1408                                 free_exec(obj);
1409                                 break;
1410 #ifdef HAVE_ICONV
1411                         case OBJ_iconv_start:
1412                                 free_iconv();
1413                                 break;
1414 #endif
1415 #ifdef __linux__
1416                         case OBJ_disk_protect:
1417                                 free(data.s);
1418                                 break;
1419                         case OBJ_if_gw:
1420                                 free(data.ifblock.s);
1421                                 free(data.ifblock.str);
1422                         case OBJ_gw_iface:
1423                         case OBJ_gw_ip:
1424                                 free_gateway_info();
1425                                 break;
1426                         case OBJ_ioscheduler:
1427                                 if(data.s)
1428                                         free(data.s);
1429                                 break;
1430 #endif
1431 #if (defined(__FreeBSD__) || defined(__linux__))
1432                         case OBJ_if_up:
1433                                 free(data.ifblock.s);
1434                                 free(data.ifblock.str);
1435                                 break;
1436 #endif
1437 #ifdef XMMS2
1438                         case OBJ_xmms2_artist:
1439                                 if (info.xmms2.artist) {
1440                                         free(info.xmms2.artist);
1441                                         info.xmms2.artist = 0;
1442                                 }
1443                                 break;
1444                         case OBJ_xmms2_album:
1445                                 if (info.xmms2.album) {
1446                                         free(info.xmms2.album);
1447                                         info.xmms2.album = 0;
1448                                 }
1449                                 break;
1450                         case OBJ_xmms2_title:
1451                                 if (info.xmms2.title) {
1452                                         free(info.xmms2.title);
1453                                         info.xmms2.title = 0;
1454                                 }
1455                                 break;
1456                         case OBJ_xmms2_genre:
1457                                 if (info.xmms2.genre) {
1458                                         free(info.xmms2.genre);
1459                                         info.xmms2.genre = 0;
1460                                 }
1461                                 break;
1462                         case OBJ_xmms2_comment:
1463                                 if (info.xmms2.comment) {
1464                                         free(info.xmms2.comment);
1465                                         info.xmms2.comment = 0;
1466                                 }
1467                                 break;
1468                         case OBJ_xmms2_url:
1469                                 if (info.xmms2.url) {
1470                                         free(info.xmms2.url);
1471                                         info.xmms2.url = 0;
1472                                 }
1473                                 break;
1474                         case OBJ_xmms2_date:
1475                                 if (info.xmms2.date) {
1476                                         free(info.xmms2.date);
1477                                         info.xmms2.date = 0;
1478                                 }
1479                                 break;
1480                         case OBJ_xmms2_status:
1481                                 if (info.xmms2.status) {
1482                                         free(info.xmms2.status);
1483                                         info.xmms2.status = 0;
1484                                 }
1485                                 break;
1486                         case OBJ_xmms2_playlist:
1487                                 if (info.xmms2.playlist) {
1488                                         free(info.xmms2.playlist);
1489                                         info.xmms2.playlist = 0;
1490                                 }
1491                                 break;
1492                         case OBJ_xmms2_smart:
1493                                 if (info.xmms2.artist) {
1494                                         free(info.xmms2.artist);
1495                                         info.xmms2.artist = 0;
1496                                 }
1497                                 if (info.xmms2.title) {
1498                                         free(info.xmms2.title);
1499                                         info.xmms2.title = 0;
1500                                 }
1501                                 if (info.xmms2.url) {
1502                                         free(info.xmms2.url);
1503                                         info.xmms2.url = 0;
1504                                 }
1505                                 break;
1506 #endif
1507 #ifdef BMPX
1508                         case OBJ_bmpx_title:
1509                         case OBJ_bmpx_artist:
1510                         case OBJ_bmpx_album:
1511                         case OBJ_bmpx_track:
1512                         case OBJ_bmpx_uri:
1513                         case OBJ_bmpx_bitrate:
1514                                 break;
1515 #endif
1516 #ifdef EVE
1517                         case OBJ_eve:
1518                                 free_eve(obj);
1519                                 break;
1520 #endif
1521 #ifdef HAVE_CURL
1522                         case OBJ_curl:
1523                                 curl_obj_free(obj);
1524                                 break;
1525 #endif
1526 #ifdef RSS
1527                         case OBJ_rss:
1528                                 rss_free_obj_info(obj);
1529                                 break;
1530 #endif
1531 #ifdef WEATHER
1532                         case OBJ_weather:
1533                                 free_weather(obj);
1534                                 break;
1535 #endif
1536 #ifdef XOAP
1537                         case OBJ_weather_forecast:
1538                                 free_weather(obj);
1539                                 break;
1540 #endif
1541 #ifdef HAVE_LUA
1542                         case OBJ_lua:
1543                         case OBJ_lua_parse:
1544                         case OBJ_lua_bar:
1545 #ifdef X11
1546                         case OBJ_lua_graph:
1547                         case OBJ_lua_gauge:
1548 #endif /* X11 */
1549                                 free(data.s);
1550                                 break;
1551 #endif /* HAVE_LUA */
1552                         case OBJ_pre_exec:
1553                                 break;
1554 #ifndef __OpenBSD__
1555                         case OBJ_battery:
1556                                 free(data.s);
1557                                 break;
1558                         case OBJ_battery_short:
1559                                 free(data.s);
1560                                 break;
1561                         case OBJ_battery_time:
1562                                 free(data.s);
1563                                 break;
1564 #endif /* !__OpenBSD__ */
1565                         case OBJ_execpi:
1566                         case OBJ_execi:
1567                         case OBJ_execibar:
1568                         case OBJ_texeci:
1569 #ifdef X11
1570                         case OBJ_execigraph:
1571                         case OBJ_execigauge:
1572 #endif /* X11 */
1573                                 free_execi(obj);
1574                                 break;
1575                         case OBJ_nameserver:
1576                                 free_dns_data();
1577                                 break;
1578                         case OBJ_top:
1579                         case OBJ_top_mem:
1580                         case OBJ_top_time:
1581 #ifdef IOSTATS
1582                         case OBJ_top_io:
1583 #endif
1584                                 free_top(obj, internal);
1585                                 break;
1586 #ifdef HDDTEMP
1587                         case OBJ_hddtemp:
1588                                 if (data.s) {
1589                                         free(data.s);
1590                                         data.s = NULL;
1591                                 }
1592                                 free_hddtemp();
1593                                 break;
1594 #endif /* HDDTEMP */
1595                         case OBJ_entropy_avail:
1596                         case OBJ_entropy_perc:
1597                         case OBJ_entropy_poolsize:
1598                         case OBJ_entropy_bar:
1599                                 break;
1600                         case OBJ_user_names:
1601                                 if (info.users.names) {
1602                                         free(info.users.names);
1603                                         info.users.names = 0;
1604                                 }
1605                                 break;
1606                         case OBJ_user_terms:
1607                                 if (info.users.terms) {
1608                                         free(info.users.terms);
1609                                         info.users.terms = 0;
1610                                 }
1611                                 break;
1612                         case OBJ_user_times:
1613                                 if (info.users.times) {
1614                                         free(info.users.times);
1615                                         info.users.times = 0;
1616                                 }
1617                                 break;
1618 #ifdef IBM
1619                         case OBJ_smapi:
1620                         case OBJ_smapi_bat_perc:
1621                         case OBJ_smapi_bat_temp:
1622                         case OBJ_smapi_bat_power:
1623                                 free(data.s);
1624                                 break;
1625                         case OBJ_if_smapi_bat_installed:
1626                                 free(data.ifblock.s);
1627                                 free(data.ifblock.str);
1628                                 break;
1629 #endif /* IBM */
1630 #ifdef NVIDIA
1631                         case OBJ_nvidia:
1632                                 free_nvidia(obj);
1633                                 break;
1634 #endif /* NVIDIA */
1635 #ifdef MPD
1636                         case OBJ_mpd_title:
1637                         case OBJ_mpd_artist:
1638                         case OBJ_mpd_album:
1639                         case OBJ_mpd_random:
1640                         case OBJ_mpd_repeat:
1641                         case OBJ_mpd_vol:
1642                         case OBJ_mpd_bitrate:
1643                         case OBJ_mpd_status:
1644                         case OBJ_mpd_bar:
1645                         case OBJ_mpd_elapsed:
1646                         case OBJ_mpd_length:
1647                         case OBJ_mpd_track:
1648                         case OBJ_mpd_name:
1649                         case OBJ_mpd_file:
1650                         case OBJ_mpd_percent:
1651                         case OBJ_mpd_smart:
1652                         case OBJ_if_mpd_playing:
1653                                 free_mpd();
1654                                 break;
1655 #endif /* MPD */
1656 #ifdef MOC
1657                         case OBJ_moc_state:
1658                         case OBJ_moc_file:
1659                         case OBJ_moc_title:
1660                         case OBJ_moc_artist:
1661                         case OBJ_moc_song:
1662                         case OBJ_moc_album:
1663                         case OBJ_moc_totaltime:
1664                         case OBJ_moc_timeleft:
1665                         case OBJ_moc_curtime:
1666                         case OBJ_moc_bitrate:
1667                         case OBJ_moc_rate:
1668                                 free_moc();
1669                                 break;
1670 #endif /* MOC */
1671                         case OBJ_include:
1672                         case OBJ_blink:
1673                         case OBJ_to_bytes:
1674                                 if(obj->sub) {
1675                                         free_text_objects(obj->sub, 1);
1676                                         free(obj->sub);
1677                                 }
1678                                 break;
1679                         case OBJ_scroll:
1680                                 free_scroll(obj);
1681                                 break;
1682                         case OBJ_combine:
1683                                 free_combine(obj);
1684                                 break;
1685 #ifdef APCUPSD
1686                         case OBJ_apcupsd:
1687                         case OBJ_apcupsd_name:
1688                         case OBJ_apcupsd_model:
1689                         case OBJ_apcupsd_upsmode:
1690                         case OBJ_apcupsd_cable:
1691                         case OBJ_apcupsd_status:
1692                         case OBJ_apcupsd_linev:
1693                         case OBJ_apcupsd_load:
1694                         case OBJ_apcupsd_loadbar:
1695 #ifdef X11
1696                         case OBJ_apcupsd_loadgraph:
1697                         case OBJ_apcupsd_loadgauge:
1698 #endif /* X11 */
1699                         case OBJ_apcupsd_charge:
1700                         case OBJ_apcupsd_timeleft:
1701                         case OBJ_apcupsd_temp:
1702                         case OBJ_apcupsd_lastxfer:
1703                                 break;
1704 #endif /* APCUPSD */
1705 #ifdef TCP_PORT_MONITOR
1706                         case OBJ_tcp_portmon:
1707                                 tcp_portmon_free(obj);
1708                                 break;
1709 #endif /* TCP_PORT_MONITOR */
1710 #ifdef X11
1711                         case OBJ_desktop:
1712                         case OBJ_desktop_number:
1713                         case OBJ_desktop_name:
1714                                 if(info.x11.desktop.name && !internal) {
1715                                   free(info.x11.desktop.name);
1716                                   info.x11.desktop.name = NULL;
1717                                 }
1718                                 if(info.x11.desktop.all_names && !internal) {
1719                                   free(info.x11.desktop.all_names);
1720                                   info.x11.desktop.all_names = NULL;
1721                                 }
1722                                 break;
1723 #endif /* X11 */
1724                 }
1725                 free(obj);
1726         }
1727 #undef data
1728 }
1729