ibm: put specific code to where it belongs
[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 "diskio.h"
38 #ifdef X11
39 #include "fonts.h"
40 #endif
41 #include "fs.h"
42 #ifdef HAVE_ICONV
43 #include "iconv_tools.h"
44 #endif
45 #include "logging.h"
46 #include "mixer.h"
47 #include "mail.h"
48 #include "mboxscan.h"
49 #include "specials.h"
50 #include "temphelper.h"
51 #include "template.h"
52 #include "tailhead.h"
53 #include "timeinfo.h"
54 #include "top.h"
55
56 #ifdef NCURSES
57 #include <ncurses.h>
58 #endif
59
60 /* check for OS and include appropriate headers */
61 #if defined(__linux__)
62 #include "linux.h"
63 #elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
64 #include "freebsd.h"
65 #elif defined(__OpenBSD__)
66 #include "openbsd.h"
67 #endif
68
69 /* OS specific prototypes to be implemented by linux.c & Co. */
70 void update_entropy(void);
71
72 #include <string.h>
73 #include <ctype.h>
74
75 /* strip a leading /dev/ if any, following symlinks first
76  *
77  * BEWARE: this function returns a pointer to static content
78  *         which gets overwritten in consecutive calls. I.e.:
79  *         this function is NOT reentrant.
80  */
81 static const char *dev_name(const char *path)
82 {
83         static char buf[255];   /* should be enough for pathnames */
84         ssize_t buflen;
85
86         if (!path)
87                 return NULL;
88
89 #define DEV_NAME(x) \
90   x != NULL && strlen(x) > 5 && strncmp(x, "/dev/", 5) == 0 ? x + 5 : x
91         if ((buflen = readlink(path, buf, 254)) == -1)
92                 return DEV_NAME(path);
93         buf[buflen] = '\0';
94         return DEV_NAME(buf);
95 #undef DEV_NAME
96 }
97
98 static struct text_object *new_text_object_internal(void)
99 {
100         struct text_object *obj = malloc(sizeof(struct text_object));
101         memset(obj, 0, sizeof(struct text_object));
102         return obj;
103 }
104
105 static struct text_object *create_plain_text(const char *s)
106 {
107         struct text_object *obj;
108
109         if (s == NULL || *s == '\0') {
110                 return NULL;
111         }
112
113         obj = new_text_object_internal();
114
115         obj->type = OBJ_text;
116         obj->data.s = strndup(s, text_buffer_size);
117         return obj;
118 }
119
120 /* construct_text_object() creates a new text_object */
121 struct text_object *construct_text_object(const char *s, const char *arg, long
122                 line, void **ifblock_opaque, void *free_at_crash)
123 {
124         // struct text_object *obj = new_text_object();
125         struct text_object *obj = new_text_object_internal();
126
127         obj->line = line;
128
129 /* helper defines for internal use only */
130 #define __OBJ_HEAD(a, n) if (!strcmp(s, #a)) { \
131         obj->type = OBJ_##a; add_update_callback(n);
132 #define __OBJ_IF obj_be_ifblock_if(ifblock_opaque, obj)
133 #define __OBJ_ARG(...) if (!arg) { CRIT_ERR(obj, free_at_crash, __VA_ARGS__); }
134
135 /* defines to be used below */
136 #define OBJ(a, n) __OBJ_HEAD(a, n) {
137 #define OBJ_ARG(a, n, ...) __OBJ_HEAD(a, n) __OBJ_ARG(__VA_ARGS__) {
138 #define OBJ_IF(a, n) __OBJ_HEAD(a, n) __OBJ_IF; {
139 #define OBJ_IF_ARG(a, n, ...) __OBJ_HEAD(a, n) __OBJ_ARG(__VA_ARGS__) __OBJ_IF; {
140 #define END } } else
141
142 #ifdef X11
143         if (s[0] == '#') {
144                 obj->type = OBJ_color;
145                 obj->data.l = get_x11_color(s);
146         } else
147 #endif /* X11 */
148 #ifdef __OpenBSD__
149         OBJ(freq, 0)
150 #else
151         OBJ(acpitemp, 0)
152                 obj->data.i = open_acpi_temperature(arg);
153         END OBJ(acpiacadapter, 0)
154         END OBJ(freq, 0)
155 #endif /* !__OpenBSD__ */
156                 get_cpu_count();
157                 if (!arg || !isdigit(arg[0]) || strlen(arg) >= 2 || atoi(&arg[0]) == 0
158                                 || (unsigned int) atoi(&arg[0]) > info.cpu_count) {
159                         obj->data.cpu_index = 1;
160                         /* NORM_ERR("freq: Invalid CPU number or you don't have that many CPUs! "
161                                 "Displaying the clock for CPU 1."); */
162                 } else {
163                         obj->data.cpu_index = atoi(&arg[0]);
164                 }
165                 obj->a = 1;
166         END OBJ(freq_g, 0)
167                 get_cpu_count();
168                 if (!arg || !isdigit(arg[0]) || strlen(arg) >= 2 || atoi(&arg[0]) == 0
169                                 || (unsigned int) atoi(&arg[0]) > info.cpu_count) {
170                         obj->data.cpu_index = 1;
171                         /* NORM_ERR("freq_g: Invalid CPU number or you don't have that many "
172                                 "CPUs! Displaying the clock for CPU 1."); */
173                 } else {
174                         obj->data.cpu_index = atoi(&arg[0]);
175                 }
176                 obj->a = 1;
177         END OBJ_ARG(read_tcp, 0, "read_tcp: Needs \"(host) port\" as argument(s)")
178                 obj->data.read_tcp.host = malloc(text_buffer_size);
179                 sscanf(arg, "%s", obj->data.read_tcp.host);
180                 sscanf(arg+strlen(obj->data.read_tcp.host), "%u", &(obj->data.read_tcp.port));
181                 if(obj->data.read_tcp.port == 0) {
182                         obj->data.read_tcp.port = atoi(obj->data.read_tcp.host);
183                         strcpy(obj->data.read_tcp.host,"localhost");
184                 }
185                 obj->data.read_tcp.port = htons(obj->data.read_tcp.port);
186                 if(obj->data.read_tcp.port < 1 || obj->data.read_tcp.port > 65535) {
187                         CRIT_ERR(obj, free_at_crash, "read_tcp: Needs \"(host) port\" as argument(s)");
188                 }
189 #if defined(__linux__)
190         END OBJ(voltage_mv, 0)
191                 get_cpu_count();
192                 if (!arg || !isdigit(arg[0]) || strlen(arg) >= 2 || atoi(&arg[0]) == 0
193                                 || (unsigned int) atoi(&arg[0]) > info.cpu_count) {
194                         obj->data.cpu_index = 1;
195                         /* NORM_ERR("voltage_mv: Invalid CPU number or you don't have that many "
196                                 "CPUs! Displaying voltage for CPU 1."); */
197                 } else {
198                         obj->data.cpu_index = atoi(&arg[0]);
199                 }
200                 obj->a = 1;
201         END OBJ(voltage_v, 0)
202                 get_cpu_count();
203                 if (!arg || !isdigit(arg[0]) || strlen(arg) >= 2 || atoi(&arg[0]) == 0
204                                 || (unsigned int) atoi(&arg[0]) > info.cpu_count) {
205                         obj->data.cpu_index = 1;
206                         /* NORM_ERR("voltage_v: Invalid CPU number or you don't have that many "
207                                 "CPUs! Displaying voltage for CPU 1."); */
208                 } else {
209                         obj->data.cpu_index = atoi(&arg[0]);
210                 }
211                 obj->a = 1;
212
213 #ifdef HAVE_IWLIB
214         END OBJ(wireless_essid, &update_net_stats)
215                 if (arg) {
216                         obj->data.net = get_net_stat(arg, obj, free_at_crash);
217                 } else {
218                         // default to DEFAULTNETDEV
219                         char *buf = strndup(DEFAULTNETDEV, text_buffer_size);
220                         obj->data.net = get_net_stat(buf, obj, free_at_crash);
221                         free(buf);
222                 }
223         END OBJ(wireless_mode, &update_net_stats)
224                 if (arg) {
225                         obj->data.net = get_net_stat(arg, obj, free_at_crash);
226                 } else {
227                         // default to DEFAULTNETDEV
228                         char *buf = strndup(DEFAULTNETDEV, text_buffer_size);
229                         obj->data.net = get_net_stat(buf, obj, free_at_crash);
230                         free(buf);
231                 }
232         END OBJ(wireless_bitrate, &update_net_stats)
233                 if (arg) {
234                         obj->data.net = get_net_stat(arg, obj, free_at_crash);
235                 } else {
236                         // default to DEFAULTNETDEV
237                         char *buf = strndup(DEFAULTNETDEV, text_buffer_size);
238                         obj->data.net = get_net_stat(buf, obj, free_at_crash);
239                         free(buf);
240                 }
241         END OBJ(wireless_ap, &update_net_stats)
242                 if (arg) {
243                         obj->data.net = get_net_stat(arg, obj, free_at_crash);
244                 } else {
245                         // default to DEFAULTNETDEV
246                         char *buf = strndup(DEFAULTNETDEV, text_buffer_size);
247                         obj->data.net = get_net_stat(buf, obj, free_at_crash);
248                         free(buf);
249                 }
250         END OBJ(wireless_link_qual, &update_net_stats)
251                 if (arg) {
252                         obj->data.net = get_net_stat(arg, obj, free_at_crash);
253                 } else {
254                         // default to DEFAULTNETDEV
255                         char *buf = strndup(DEFAULTNETDEV, text_buffer_size);
256                         obj->data.net = get_net_stat(buf, obj, free_at_crash);
257                         free(buf);
258                 }
259         END OBJ(wireless_link_qual_max, &update_net_stats)
260                 if (arg) {
261                         obj->data.net = get_net_stat(arg, obj, free_at_crash);
262                 } else {
263                         // default to DEFAULTNETDEV
264                         char *buf = strndup(DEFAULTNETDEV, text_buffer_size);
265                         obj->data.net = get_net_stat(buf, obj, free_at_crash);
266                         free(buf);
267                 }
268         END OBJ(wireless_link_qual_perc, &update_net_stats)
269                 if (arg) {
270                         obj->data.net = get_net_stat(arg, obj, free_at_crash);
271                 } else {
272                         // default to DEFAULTNETDEV
273                         char *buf = strndup(DEFAULTNETDEV, text_buffer_size);
274                         obj->data.net = get_net_stat(buf, obj, free_at_crash);
275                         free(buf);
276                 }
277         END OBJ(wireless_link_bar, &update_net_stats)
278                 SIZE_DEFAULTS(bar);
279                 if (arg) {
280                         arg = scan_bar(arg, &obj->a, &obj->b);
281                         obj->data.net = get_net_stat(arg, obj, free_at_crash);
282                 } else {
283                         // default to DEFAULTNETDEV
284                         char *buf = strndup(DEFAULTNETDEV, text_buffer_size);
285                         obj->data.net = get_net_stat(buf, obj, free_at_crash);
286                         free(buf);
287                 }
288 #endif /* HAVE_IWLIB */
289
290 #endif /* __linux__ */
291
292 #ifndef __OpenBSD__
293         END OBJ(acpifan, 0)
294         END OBJ(battery, 0)
295                 char bat[64];
296
297                 if (arg) {
298                         sscanf(arg, "%63s", bat);
299                 } else {
300                         strcpy(bat, "BAT0");
301                 }
302                 obj->data.s = strndup(bat, text_buffer_size);
303         END OBJ(battery_short, 0)
304                 char bat[64];
305
306                 if (arg) {
307                         sscanf(arg, "%63s", bat);
308                 } else {
309                         strcpy(bat, "BAT0");
310                 }
311                 obj->data.s = strndup(bat, text_buffer_size);
312         END OBJ(battery_time, 0)
313                 char bat[64];
314
315                 if (arg) {
316                         sscanf(arg, "%63s", bat);
317                 } else {
318                         strcpy(bat, "BAT0");
319                 }
320                 obj->data.s = strndup(bat, text_buffer_size);
321         END OBJ(battery_percent, 0)
322                 char bat[64];
323
324                 if (arg) {
325                         sscanf(arg, "%63s", bat);
326                 } else {
327                         strcpy(bat, "BAT0");
328                 }
329                 obj->data.s = strndup(bat, text_buffer_size);
330         END OBJ(battery_bar, 0)
331                 char bat[64];
332                 SIZE_DEFAULTS(bar);
333                 obj->b = 6;
334                 if (arg) {
335                         arg = scan_bar(arg, &obj->a, &obj->b);
336                         sscanf(arg, "%63s", bat);
337                 } else {
338                         strcpy(bat, "BAT0");
339                 }
340                 obj->data.s = strndup(bat, text_buffer_size);
341 #endif /* !__OpenBSD__ */
342
343 #if defined(__linux__)
344         END OBJ_ARG(disk_protect, 0, "disk_protect needs an argument")
345                 obj->data.s = strndup(dev_name(arg), text_buffer_size);
346         END OBJ(i8k_version, &update_i8k)
347         END OBJ(i8k_bios, &update_i8k)
348         END OBJ(i8k_serial, &update_i8k)
349         END OBJ(i8k_cpu_temp, &update_i8k)
350         END OBJ(i8k_left_fan_status, &update_i8k)
351         END OBJ(i8k_right_fan_status, &update_i8k)
352         END OBJ(i8k_left_fan_rpm, &update_i8k)
353         END OBJ(i8k_right_fan_rpm, &update_i8k)
354         END OBJ(i8k_ac_status, &update_i8k)
355         END OBJ(i8k_buttons_status, &update_i8k)
356 #if defined(IBM)
357         END OBJ(ibm_fan, 0)
358         END OBJ(ibm_temps, &get_ibm_acpi_temps, "ibm_temps: needs an argument")
359                 parse_ibm_temps_arg(obj, arg);
360         END OBJ(ibm_volume, 0)
361         END OBJ(ibm_brightness, 0)
362 #endif
363         /* information from sony_laptop kernel module
364          * /sys/devices/platform/sony-laptop */
365         END OBJ(sony_fanspeed, 0)
366         END OBJ_IF(if_gw, &update_gateway_info)
367         END OBJ_ARG(ioscheduler, 0, "get_ioscheduler needs an argument (e.g. hda)")
368                 obj->data.s = strndup(dev_name(arg), text_buffer_size);
369         END OBJ(laptop_mode, 0)
370         END OBJ_ARG(pb_battery, 0, "pb_battery: needs one argument: status, percent or time")
371                 if (strcmp(arg, "status") == EQUAL) {
372                         obj->data.i = PB_BATT_STATUS;
373                 } else if (strcmp(arg, "percent") == EQUAL) {
374                         obj->data.i = PB_BATT_PERCENT;
375                 } else if (strcmp(arg, "time") == EQUAL) {
376                         obj->data.i = PB_BATT_TIME;
377                 } else {
378                         NORM_ERR("pb_battery: illegal argument '%s', defaulting to status", arg);
379                         obj->data.i = PB_BATT_STATUS;
380                 }
381 #endif /* __linux__ */
382 #if (defined(__FreeBSD__) || defined(__linux__))
383         END OBJ_IF_ARG(if_up, 0, "if_up needs an argument")
384                 obj->data.ifblock.s = strndup(arg, text_buffer_size);
385 #endif
386 #if defined(__OpenBSD__)
387         END OBJ_ARG(obsd_sensors_temp, 0, "obsd_sensors_temp: needs an argument")
388                 if (!isdigit(arg[0]) || atoi(&arg[0]) < 0
389                                 || atoi(&arg[0]) > OBSD_MAX_SENSORS - 1) {
390                         obj->data.sensor = 0;
391                         NORM_ERR("Invalid temperature sensor number!");
392                 } else
393                         obj->data.sensor = atoi(&arg[0]);
394         END OBJ_ARG(obsd_sensors_fan, 0, "obsd_sensors_fan: needs 2 arguments (device and sensor number)")
395                 if (!isdigit(arg[0]) || atoi(&arg[0]) < 0
396                                 || atoi(&arg[0]) > OBSD_MAX_SENSORS - 1) {
397                         obj->data.sensor = 0;
398                         NORM_ERR("Invalid fan sensor number!");
399                 } else
400                         obj->data.sensor = atoi(&arg[0]);
401         END OBJ_ARG(obsd_sensors_volt, 0, "obsd_sensors_volt: needs 2 arguments (device and sensor number)")
402                 if (!isdigit(arg[0]) || atoi(&arg[0]) < 0
403                                 || atoi(&arg[0]) > OBSD_MAX_SENSORS - 1) {
404                         obj->data.sensor = 0;
405                         NORM_ERR("Invalid voltage sensor number!");
406                 } else
407                         obj->data.sensor = atoi(&arg[0]);
408         END OBJ(obsd_vendor, 0)
409         END OBJ(obsd_product, 0)
410 #endif /* __OpenBSD__ */
411         END OBJ(buffers, &update_meminfo)
412         END OBJ(cached, &update_meminfo)
413 #define SCAN_CPU(__arg, __var) { \
414         int __offset = 0; \
415         if (__arg && sscanf(__arg, " cpu%u %n", &__var, &__offset) > 0) \
416                 __arg += __offset; \
417         else \
418                 __var = 0; \
419 }
420         END OBJ(cpu, &update_cpu_usage)
421                 SCAN_CPU(arg, obj->data.cpu_index);
422                 DBGP2("Adding $cpu for CPU %d", obj->data.cpu_index);
423 #ifdef X11
424         END OBJ(cpugauge, &update_cpu_usage)
425                 SIZE_DEFAULTS(gauge);
426                 SCAN_CPU(arg, obj->data.cpu_index);
427                 scan_gauge(arg, &obj->a, &obj->b);
428                 DBGP2("Adding $cpugauge for CPU %d", obj->data.cpu_index);
429 #endif /* X11 */
430         END OBJ(cpubar, &update_cpu_usage)
431                 SIZE_DEFAULTS(bar);
432                 SCAN_CPU(arg, obj->data.cpu_index);
433                 scan_bar(arg, &obj->a, &obj->b);
434                 DBGP2("Adding $cpubar for CPU %d", obj->data.cpu_index);
435 #ifdef X11
436         END OBJ(cpugraph, &update_cpu_usage)
437                 char *buf = 0;
438                 SIZE_DEFAULTS(graph);
439                 SCAN_CPU(arg, obj->data.cpu_index);
440                 buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
441                         &obj->e, &obj->char_a, &obj->char_b);
442                 DBGP2("Adding $cpugraph for CPU %d", obj->data.cpu_index);
443                 if (buf) free(buf);
444         END OBJ(loadgraph, &update_load_average)
445                 char *buf = 0;
446                 SIZE_DEFAULTS(graph);
447                 buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
448                                 &obj->e, &obj->char_a, &obj->char_b);
449                 if (buf) {
450                         int a = 1, r = 3;
451                         if (arg) {
452                                 r = sscanf(arg, "%d", &a);
453                         }
454                         obj->data.loadavg[0] = (r >= 1) ? (unsigned char) a : 0;
455                         free(buf);
456                 }
457 #endif /* X11 */
458         END OBJ(diskio, &update_diskio)
459                 obj->data.diskio = prepare_diskio_stat(dev_name(arg));
460         END OBJ(diskio_read, &update_diskio)
461                 obj->data.diskio = prepare_diskio_stat(dev_name(arg));
462         END OBJ(diskio_write, &update_diskio)
463                 obj->data.diskio = prepare_diskio_stat(dev_name(arg));
464 #ifdef X11
465         END OBJ(diskiograph, &update_diskio)
466                 char *buf = 0;
467                 SIZE_DEFAULTS(graph);
468                 buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
469                                 &obj->e, &obj->char_a, &obj->char_b);
470
471                 obj->data.diskio = prepare_diskio_stat(dev_name(buf));
472                 if (buf) free(buf);
473         END OBJ(diskiograph_read, &update_diskio)
474                 char *buf = 0;
475                 SIZE_DEFAULTS(graph);
476                 buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
477                                 &obj->e, &obj->char_a, &obj->char_b);
478
479                 obj->data.diskio = prepare_diskio_stat(dev_name(buf));
480                 if (buf) free(buf);
481         END OBJ(diskiograph_write, &update_diskio)
482                 char *buf = 0;
483                 SIZE_DEFAULTS(graph);
484                 buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
485                                 &obj->e, &obj->char_a, &obj->char_b);
486
487                 obj->data.diskio = prepare_diskio_stat(dev_name(buf));
488                 if (buf) free(buf);
489 #endif /* X11 */
490         END OBJ(color, 0)
491 #ifdef X11
492                 if (output_methods & TO_X) {
493                         obj->data.l = arg ? get_x11_color(arg) : default_fg_color;
494                         set_current_text_color(obj->data.l);
495                 }
496 #endif /* X11 */
497 #ifdef NCURSES
498                 if (output_methods & TO_NCURSES) {
499                         obj->data.l = COLOR_WHITE;
500                         if(arg) {
501                                 if(strcasecmp(arg, "red") == 0) {
502                                         obj->data.l = COLOR_RED;
503                                 }else if(strcasecmp(arg, "green") == 0) {
504                                         obj->data.l = COLOR_GREEN;
505                                 }else if(strcasecmp(arg, "yellow") == 0) {
506                                         obj->data.l = COLOR_YELLOW;
507                                 }else if(strcasecmp(arg, "blue") == 0) {
508                                         obj->data.l = COLOR_BLUE;
509                                 }else if(strcasecmp(arg, "magenta") == 0) {
510                                         obj->data.l = COLOR_MAGENTA;
511                                 }else if(strcasecmp(arg, "cyan") == 0) {
512                                         obj->data.l = COLOR_CYAN;
513                                 }else if(strcasecmp(arg, "black") == 0) {
514                                         obj->data.l = COLOR_BLACK;
515                                 }
516                         }
517                         set_current_text_color(obj->data.l);
518                         init_pair(obj->data.l, obj->data.l, COLOR_BLACK);
519                 }
520 #endif /* NCURSES */
521         END OBJ(color0, 0)
522                 obj->data.l = color0;
523                 set_current_text_color(obj->data.l);
524         END OBJ(color1, 0)
525                 obj->data.l = color1;
526                 set_current_text_color(obj->data.l);
527         END OBJ(color2, 0)
528                 obj->data.l = color2;
529                 set_current_text_color(obj->data.l);
530         END OBJ(color3, 0)
531                 obj->data.l = color3;
532                 set_current_text_color(obj->data.l);
533         END OBJ(color4, 0)
534                 obj->data.l = color4;
535                 set_current_text_color(obj->data.l);
536         END OBJ(color5, 0)
537                 obj->data.l = color5;
538                 set_current_text_color(obj->data.l);
539         END OBJ(color6, 0)
540                 obj->data.l = color6;
541                 set_current_text_color(obj->data.l);
542         END OBJ(color7, 0)
543                 obj->data.l = color7;
544                 set_current_text_color(obj->data.l);
545         END OBJ(color8, 0)
546                 obj->data.l = color8;
547                 set_current_text_color(obj->data.l);
548         END OBJ(color9, 0)
549                 obj->data.l = color9;
550                 set_current_text_color(obj->data.l);
551 #ifdef X11
552         END OBJ(font, 0)
553                 obj->data.s = scan_font(arg);
554 #endif /* X11 */
555         END OBJ(conky_version, 0)
556         END OBJ(conky_build_date, 0)
557         END OBJ(conky_build_arch, 0)
558         END OBJ(downspeed, &update_net_stats)
559                 if (arg) {
560                         obj->data.net = get_net_stat(arg, obj, free_at_crash);
561                 } else {
562                         // default to DEFAULTNETDEV
563                         char *buf = strndup(DEFAULTNETDEV, text_buffer_size);
564                         obj->data.net = get_net_stat(buf, obj, free_at_crash);
565                         free(buf);
566                 }
567         END OBJ(downspeedf, &update_net_stats)
568                 if (arg) {
569                         obj->data.net = get_net_stat(arg, obj, free_at_crash);
570                 } else {
571                         // default to DEFAULTNETDEV
572                         char *buf = strndup(DEFAULTNETDEV, text_buffer_size);
573                         obj->data.net = get_net_stat(buf, obj, free_at_crash);
574                         free(buf);
575                 }
576 #ifdef X11
577         END OBJ(downspeedgraph, &update_net_stats)
578                 char *buf = 0;
579                 SIZE_DEFAULTS(graph);
580                 buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
581                                 &obj->e, &obj->char_a, &obj->char_b);
582
583                 // default to DEFAULTNETDEV
584                 buf = strndup(buf ? buf : DEFAULTNETDEV, text_buffer_size);
585                 obj->data.net = get_net_stat(buf, obj, free_at_crash);
586                 free(buf);
587 #endif /* X11 */
588         END OBJ(else, 0)
589                 obj_be_ifblock_else(ifblock_opaque, obj);
590         END OBJ(endif, 0)
591                 obj_be_ifblock_endif(ifblock_opaque, obj);
592         END OBJ(eval, 0)
593                 obj->data.s = strndup(arg ? arg : "", text_buffer_size);
594 #if defined(IMLIB2) && defined(X11)
595         END OBJ(image, 0)
596                 obj->data.s = strndup(arg ? arg : "", text_buffer_size);
597 #endif /* IMLIB2 */
598         END OBJ(exec, 0)
599                 obj->data.s = strndup(arg ? arg : "", text_buffer_size);
600         END OBJ(execp, 0)
601                 obj->data.s = strndup(arg ? arg : "", text_buffer_size);
602         END OBJ(execbar, 0)
603                 SIZE_DEFAULTS(bar);
604                 obj->data.s = strndup(arg ? arg : "", text_buffer_size);
605 #ifdef X11
606         END OBJ(execgauge, 0)
607                 SIZE_DEFAULTS(gauge);
608                 obj->data.s = strndup(arg ? arg : "", text_buffer_size);
609         END OBJ(execgraph, 0)
610                 SIZE_DEFAULTS(graph);
611                 obj->data.s = strndup(arg ? arg : "", text_buffer_size);
612 #endif /* X11 */
613         END OBJ(execibar, 0)
614                 int n;
615                 SIZE_DEFAULTS(bar);
616
617                 if (!arg || sscanf(arg, "%f %n", &obj->data.execi.interval, &n) <= 0) {
618                         char buf[256];
619
620                         NORM_ERR("${execibar <interval> command}");
621                         obj->type = OBJ_text;
622                         snprintf(buf, 256, "${%s}", s);
623                         obj->data.s = strndup(buf, text_buffer_size);
624                 } else {
625                         obj->data.execi.cmd = strndup(arg + n, text_buffer_size);
626                 }
627 #ifdef X11
628         END OBJ(execigraph, 0)
629                 int n;
630                 SIZE_DEFAULTS(graph);
631
632                 if (!arg || sscanf(arg, "%f %n", &obj->data.execi.interval, &n) <= 0) {
633                         char buf[256];
634
635                         NORM_ERR("${execigraph <interval> command}");
636                         obj->type = OBJ_text;
637                         snprintf(buf, 256, "${%s}", s);
638                         obj->data.s = strndup(buf, text_buffer_size);
639                 } else {
640                         obj->data.execi.cmd = strndup(arg + n, text_buffer_size);
641                 }
642         END OBJ(execigauge, 0)
643                 int n;
644                 SIZE_DEFAULTS(gauge);
645
646                 if (!arg || sscanf(arg, "%f %n", &obj->data.execi.interval, &n) <= 0) {
647                         char buf[256];
648
649                         NORM_ERR("${execigauge <interval> command}");
650                         obj->type = OBJ_text;
651                         snprintf(buf, 256, "${%s}", s);
652                         obj->data.s = strndup(buf, text_buffer_size);
653                 } else {
654                         obj->data.execi.cmd = strndup(arg + n, text_buffer_size);
655                 }
656 #endif /* X11 */
657         END OBJ(execi, 0)
658                 int n;
659
660                 if (!arg || sscanf(arg, "%f %n", &obj->data.execi.interval, &n) <= 0) {
661                         char buf[256];
662
663                         NORM_ERR("${execi <interval> command}");
664                         obj->type = OBJ_text;
665                         snprintf(buf, 256, "${%s}", s);
666                         obj->data.s = strndup(buf, text_buffer_size);
667                 } else {
668                         obj->data.execi.cmd = strndup(arg + n, text_buffer_size);
669                         obj->data.execi.buffer = malloc(text_buffer_size);
670                 }
671         END OBJ(execpi, 0)
672                 int n;
673
674                 if (!arg || sscanf(arg, "%f %n", &obj->data.execi.interval, &n) <= 0) {
675                         char buf[256];
676
677                         NORM_ERR("${execi <interval> command}");
678                         obj->type = OBJ_text;
679                         snprintf(buf, 256, "${%s}", s);
680                         obj->data.s = strndup(buf, text_buffer_size);
681                 } else {
682                         obj->data.execi.cmd = strndup(arg + n, text_buffer_size);
683                         obj->data.execi.buffer = malloc(text_buffer_size);
684                 }
685         END OBJ(texeci, 0)
686                         int n;
687
688                         if (!arg || sscanf(arg, "%f %n", &obj->data.texeci.interval, &n) <= 0) {
689                                 char buf[256];
690
691                                 NORM_ERR("${texeci <interval> command}");
692                                 obj->type = OBJ_text;
693                                 snprintf(buf, 256, "${%s}", s);
694                                 obj->data.s = strndup(buf, text_buffer_size);
695                         } else {
696                                 obj->data.texeci.cmd = strndup(arg + n, text_buffer_size);
697                                 obj->data.texeci.buffer = malloc(text_buffer_size);
698                         }
699                         obj->data.texeci.p_timed_thread = NULL;
700         END OBJ(pre_exec, 0)
701                 obj->type = OBJ_text;
702                 if (arg) {
703                         char buf[2048];
704
705                         do_read_exec(arg, buf, sizeof(buf));
706                         obj->data.s = strndup(buf, text_buffer_size);
707                 } else {
708                         obj->data.s = strndup("", text_buffer_size);
709                 }
710         END OBJ(fs_bar, &update_fs_stats)
711                 init_fs_bar(obj, arg);
712         END OBJ(fs_bar_free, &update_fs_stats)
713                 init_fs_bar(obj, arg);
714         END OBJ(fs_free, &update_fs_stats)
715                 if (!arg) {
716                         arg = "/";
717                 }
718                 obj->data.fs = prepare_fs_stat(arg);
719         END OBJ(fs_used_perc, &update_fs_stats)
720                 if (!arg) {
721                         arg = "/";
722                 }
723                 obj->data.fs = prepare_fs_stat(arg);
724         END OBJ(fs_free_perc, &update_fs_stats)
725                 if (!arg) {
726                         arg = "/";
727                 }
728                 obj->data.fs = prepare_fs_stat(arg);
729         END OBJ(fs_size, &update_fs_stats)
730                 if (!arg) {
731                         arg = "/";
732                 }
733                 obj->data.fs = prepare_fs_stat(arg);
734         END OBJ(fs_type, &update_fs_stats)
735                 if (!arg) {
736                         arg = "/";
737                 }
738                 obj->data.fs = prepare_fs_stat(arg);
739         END OBJ(fs_used, &update_fs_stats)
740                 if (!arg) {
741                         arg = "/";
742                 }
743                 obj->data.fs = prepare_fs_stat(arg);
744         END OBJ(hr, 0)
745                 obj->data.i = arg ? atoi(arg) : 1;
746         END OBJ(nameserver, &update_dns_data)
747                 obj->data.i = arg ? atoi(arg) : 0;
748         END OBJ(offset, 0)
749                 obj->data.i = arg ? atoi(arg) : 1;
750         END OBJ(voffset, 0)
751                 obj->data.i = arg ? atoi(arg) : 1;
752         END OBJ_ARG(goto, 0, "goto needs arguments")
753                 obj->data.i = atoi(arg);
754         END OBJ(tab, 0)
755                 int a = 10, b = 0;
756
757                 if (arg) {
758                         if (sscanf(arg, "%d %d", &a, &b) != 2) {
759                                 sscanf(arg, "%d", &b);
760                         }
761                 }
762                 if (a <= 0) {
763                         a = 1;
764                 }
765                 obj->data.pair.a = a;
766                 obj->data.pair.b = b;
767
768 #ifdef __linux__
769         END OBJ_ARG(i2c, 0, "i2c needs arguments")
770                 parse_i2c_sensor(obj, arg);
771         END OBJ_ARG(platform, 0, "platform needs arguments")
772                 parse_platform_sensor(obj, arg);
773         END OBJ_ARG(hwmon, 0, "hwmon needs argumanets")
774                 parse_hwmon_sensor(obj, arg);
775 #endif /* __linux__ */
776
777         END
778         /* we have four different types of top (top, top_mem, top_time and top_io). To
779          * avoid having almost-same code four times, we have this special
780          * handler. */
781         if (strncmp(s, "top", 3) == EQUAL) {
782                 add_update_callback(&update_meminfo);
783                 add_update_callback(&update_top);
784                 if (!parse_top_args(s, arg, obj)) {
785                         return NULL;
786                 }
787         } else OBJ(addr, &update_net_stats)
788                 if (arg) {
789                         obj->data.net = get_net_stat(arg, obj, free_at_crash);
790                 } else {
791                         // default to DEFAULTNETDEV
792                         char *buf = strndup(DEFAULTNETDEV, text_buffer_size);
793                         obj->data.net = get_net_stat(buf, obj, free_at_crash);
794                         free(buf);
795                 }
796 #if defined(__linux__)
797         END OBJ(addrs, &update_net_stats)
798                 if (arg) {
799                         obj->data.net = get_net_stat(arg, obj, free_at_crash);
800                 } else {
801                         // default to DEFAULTNETDEV
802                         char *buf = strndup(DEFAULTNETDEV, text_buffer_size);
803                         obj->data.net = get_net_stat(buf, obj, free_at_crash);
804                         free(buf);
805                 }
806 #endif /* __linux__ */
807         END OBJ_ARG(tail, 0, "tail needs arguments")
808                 init_tailhead("tail", arg, obj, free_at_crash);
809         END OBJ_ARG(head, 0, "head needs arguments")
810                 init_tailhead("head", arg, obj, free_at_crash);
811         END OBJ_ARG(lines, 0, "lines needs an argument")
812                 obj->data.s = strndup(arg, text_buffer_size);
813         END OBJ_ARG(words, 0, "words needs a argument")
814                 obj->data.s = strndup(arg, text_buffer_size);
815         END OBJ(loadavg, &update_load_average)
816                 int a = 1, b = 2, c = 3, r = 3;
817
818                 if (arg) {
819                         r = sscanf(arg, "%d %d %d", &a, &b, &c);
820                         if (r >= 3 && (c < 1 || c > 3)) {
821                                 r--;
822                         }
823                         if (r >= 2 && (b < 1 || b > 3)) {
824                                 r--, b = c;
825                         }
826                         if (r >= 1 && (a < 1 || a > 3)) {
827                                 r--, a = b, b = c;
828                         }
829                 }
830                 obj->data.loadavg[0] = (r >= 1) ? (unsigned char) a : 0;
831                 obj->data.loadavg[1] = (r >= 2) ? (unsigned char) b : 0;
832                 obj->data.loadavg[2] = (r >= 3) ? (unsigned char) c : 0;
833         END OBJ_IF_ARG(if_empty, 0, "if_empty needs an argument")
834                 obj->data.ifblock.s = strndup(arg, text_buffer_size);
835                 obj->sub = malloc(sizeof(struct text_object));
836                 extract_variable_text_internal(obj->sub, obj->data.ifblock.s);
837         END OBJ_IF_ARG(if_match, 0, "if_match needs arguments")
838                 obj->data.ifblock.s = strndup(arg, text_buffer_size);
839                 obj->sub = malloc(sizeof(struct text_object));
840                 extract_variable_text_internal(obj->sub, obj->data.ifblock.s);
841         END OBJ_IF_ARG(if_existing, 0, "if_existing needs an argument or two")
842                 char buf1[256], buf2[256];
843                 int r = sscanf(arg, "%255s %255[^\n]", buf1, buf2);
844
845                 if (r == 1) {
846                         obj->data.ifblock.s = strndup(buf1, text_buffer_size);
847                         obj->data.ifblock.str = NULL;
848                 } else {
849                         obj->data.ifblock.s = strndup(buf1, text_buffer_size);
850                         obj->data.ifblock.str = strndup(buf2, text_buffer_size);
851                 }
852                 DBGP("if_existing: '%s' '%s'", obj->data.ifblock.s, obj->data.ifblock.str);
853         END OBJ_IF_ARG(if_mounted, 0, "if_mounted needs an argument")
854                 obj->data.ifblock.s = strndup(arg, text_buffer_size);
855 #ifdef __linux__
856         END OBJ_IF_ARG(if_running, &update_top, "if_running needs an argument")
857                 top_running = 1;
858                 obj->data.ifblock.s = strndup(arg, text_buffer_size);
859 #else
860         END OBJ_IF_ARG(if_running, 0, "if_running needs an argument")
861                 char buf[256];
862
863                 snprintf(buf, 256, "pidof %s >/dev/null", arg);
864                 obj->data.ifblock.s = strndup(buf, text_buffer_size);
865 #endif
866         END OBJ(kernel, 0)
867         END OBJ(machine, 0)
868         END OBJ(mails, 0)
869                 float n1;
870                 char mbox[256], dst[256];
871
872                 if (!arg) {
873                         n1 = 9.5;
874                         /* Kapil: Changed from MAIL_FILE to
875                            current_mail_spool since the latter
876                            is a copy of the former if undefined
877                            but the latter should take precedence
878                            if defined */
879                         strncpy(mbox, current_mail_spool, sizeof(mbox));
880                 } else {
881                         if (sscanf(arg, "%s %f", mbox, &n1) != 2) {
882                                 n1 = 9.5;
883                                 strncpy(mbox, arg, sizeof(mbox));
884                         }
885                 }
886
887                 variable_substitute(mbox, dst, sizeof(dst));
888                 obj->data.local_mail.mbox = strndup(dst, text_buffer_size);
889                 obj->data.local_mail.interval = n1;
890         END OBJ(new_mails, 0)
891                 float n1;
892                 char mbox[256], dst[256];
893
894                 if (!arg) {
895                         n1 = 9.5;
896                         strncpy(mbox, current_mail_spool, sizeof(mbox));
897                 } else {
898                         if (sscanf(arg, "%s %f", mbox, &n1) != 2) {
899                                 n1 = 9.5;
900                                 strncpy(mbox, arg, sizeof(mbox));
901                         }
902                 }
903
904                 variable_substitute(mbox, dst, sizeof(dst));
905                 obj->data.local_mail.mbox = strndup(dst, text_buffer_size);
906                 obj->data.local_mail.interval = n1;
907         END OBJ(seen_mails, 0)
908                 float n1;
909                 char mbox[256], dst[256];
910
911                 if (!arg) {
912                         n1 = 9.5;
913                         strncpy(mbox, current_mail_spool, sizeof(mbox));
914                 } else {
915                         if (sscanf(arg, "%s %f", mbox, &n1) != 2) {
916                                 n1 = 9.5;
917                                 strncpy(mbox, arg, sizeof(mbox));
918                         }
919                 }
920
921                 variable_substitute(mbox, dst, sizeof(dst));
922                 obj->data.local_mail.mbox = strndup(dst, text_buffer_size);
923                 obj->data.local_mail.interval = n1;
924         END OBJ(unseen_mails, 0)
925                 float n1;
926                 char mbox[256], dst[256];
927
928                 if (!arg) {
929                         n1 = 9.5;
930                         strncpy(mbox, current_mail_spool, sizeof(mbox));
931                 } else {
932                         if (sscanf(arg, "%s %f", mbox, &n1) != 2) {
933                                 n1 = 9.5;
934                                 strncpy(mbox, arg, sizeof(mbox));
935                         }
936                 }
937
938                 variable_substitute(mbox, dst, sizeof(dst));
939                 obj->data.local_mail.mbox = strndup(dst, text_buffer_size);
940                 obj->data.local_mail.interval = n1;
941         END OBJ(flagged_mails, 0)
942                 float n1;
943                 char mbox[256], dst[256];
944
945                 if (!arg) {
946                         n1 = 9.5;
947                         strncpy(mbox, current_mail_spool, sizeof(mbox));
948                 } else {
949                         if (sscanf(arg, "%s %f", mbox, &n1) != 2) {
950                                 n1 = 9.5;
951                                 strncpy(mbox, arg, sizeof(mbox));
952                         }
953                 }
954
955                 variable_substitute(mbox, dst, sizeof(dst));
956                 obj->data.local_mail.mbox = strndup(dst, text_buffer_size);
957                 obj->data.local_mail.interval = n1;
958         END OBJ(unflagged_mails, 0)
959                 float n1;
960                 char mbox[256], dst[256];
961
962                 if (!arg) {
963                         n1 = 9.5;
964                         strncpy(mbox, current_mail_spool, sizeof(mbox));
965                 } else {
966                         if (sscanf(arg, "%s %f", mbox, &n1) != 2) {
967                                 n1 = 9.5;
968                                 strncpy(mbox, arg, sizeof(mbox));
969                         }
970                 }
971
972                 variable_substitute(mbox, dst, sizeof(dst));
973                 obj->data.local_mail.mbox = strndup(dst, text_buffer_size);
974                 obj->data.local_mail.interval = n1;
975         END OBJ(forwarded_mails, 0)
976                 float n1;
977                 char mbox[256], dst[256];
978
979                 if (!arg) {
980                         n1 = 9.5;
981                         strncpy(mbox, current_mail_spool, sizeof(mbox));
982                 } else {
983                         if (sscanf(arg, "%s %f", mbox, &n1) != 2) {
984                                 n1 = 9.5;
985                                 strncpy(mbox, arg, sizeof(mbox));
986                         }
987                 }
988
989                 variable_substitute(mbox, dst, sizeof(dst));
990                 obj->data.local_mail.mbox = strndup(dst, text_buffer_size);
991                 obj->data.local_mail.interval = n1;
992         END OBJ(unforwarded_mails, 0)
993                 float n1;
994                 char mbox[256], dst[256];
995
996                 if (!arg) {
997                         n1 = 9.5;
998                         strncpy(mbox, current_mail_spool, sizeof(mbox));
999                 } else {
1000                         if (sscanf(arg, "%s %f", mbox, &n1) != 2) {
1001                                 n1 = 9.5;
1002                                 strncpy(mbox, arg, sizeof(mbox));
1003                         }
1004                 }
1005
1006                 variable_substitute(mbox, dst, sizeof(dst));
1007                 obj->data.local_mail.mbox = strndup(dst, text_buffer_size);
1008                 obj->data.local_mail.interval = n1;
1009         END OBJ(replied_mails, 0)
1010                 float n1;
1011                 char mbox[256], dst[256];
1012
1013                 if (!arg) {
1014                         n1 = 9.5;
1015                         strncpy(mbox, current_mail_spool, sizeof(mbox));
1016                 } else {
1017                         if (sscanf(arg, "%s %f", mbox, &n1) != 2) {
1018                                 n1 = 9.5;
1019                                 strncpy(mbox, arg, sizeof(mbox));
1020                         }
1021                 }
1022
1023                 variable_substitute(mbox, dst, sizeof(dst));
1024                 obj->data.local_mail.mbox = strndup(dst, text_buffer_size);
1025                 obj->data.local_mail.interval = n1;
1026         END OBJ(unreplied_mails, 0)
1027                 float n1;
1028                 char mbox[256], dst[256];
1029
1030                 if (!arg) {
1031                         n1 = 9.5;
1032                         strncpy(mbox, current_mail_spool, sizeof(mbox));
1033                 } else {
1034                         if (sscanf(arg, "%s %f", mbox, &n1) != 2) {
1035                                 n1 = 9.5;
1036                                 strncpy(mbox, arg, sizeof(mbox));
1037                         }
1038                 }
1039
1040                 variable_substitute(mbox, dst, sizeof(dst));
1041                 obj->data.local_mail.mbox = strndup(dst, text_buffer_size);
1042                 obj->data.local_mail.interval = n1;
1043         END OBJ(draft_mails, 0)
1044                 float n1;
1045                 char mbox[256], dst[256];
1046
1047                 if (!arg) {
1048                         n1 = 9.5;
1049                         strncpy(mbox, current_mail_spool, sizeof(mbox));
1050                 } else {
1051                         if (sscanf(arg, "%s %f", mbox, &n1) != 2) {
1052                                 n1 = 9.5;
1053                                 strncpy(mbox, arg, sizeof(mbox));
1054                         }
1055                 }
1056
1057                 variable_substitute(mbox, dst, sizeof(dst));
1058                 obj->data.local_mail.mbox = strndup(dst, text_buffer_size);
1059                 obj->data.local_mail.interval = n1;
1060         END OBJ(trashed_mails, 0)
1061                 float n1;
1062                 char mbox[256], dst[256];
1063
1064                 if (!arg) {
1065                         n1 = 9.5;
1066                         strncpy(mbox, current_mail_spool, sizeof(mbox));
1067                 } else {
1068                         if (sscanf(arg, "%s %f", mbox, &n1) != 2) {
1069                                 n1 = 9.5;
1070                                 strncpy(mbox, arg, sizeof(mbox));
1071                         }
1072                 }
1073
1074                 variable_substitute(mbox, dst, sizeof(dst));
1075                 obj->data.local_mail.mbox = strndup(dst, text_buffer_size);
1076                 obj->data.local_mail.interval = n1;
1077         END OBJ(mboxscan, 0)
1078                 obj->data.mboxscan.args = (char *) malloc(text_buffer_size);
1079                 obj->data.mboxscan.output = (char *) malloc(text_buffer_size);
1080                 /* if '1' (in mboxscan.c) then there was SIGUSR1, hmm */
1081                 obj->data.mboxscan.output[0] = 1;
1082                 strncpy(obj->data.mboxscan.args, arg, text_buffer_size);
1083         END OBJ(mem, &update_meminfo)
1084         END OBJ(memeasyfree, &update_meminfo)
1085         END OBJ(memfree, &update_meminfo)
1086         END OBJ(memmax, &update_meminfo)
1087         END OBJ(memperc, &update_meminfo)
1088 #ifdef X11
1089         END OBJ(memgauge, &update_meminfo)
1090                 SIZE_DEFAULTS(gauge);
1091                 scan_gauge(arg, &obj->data.pair.a, &obj->data.pair.b);
1092 #endif /* X11*/
1093         END OBJ(membar, &update_meminfo)
1094                 SIZE_DEFAULTS(bar);
1095                 scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
1096 #ifdef X11
1097         END OBJ(memgraph, &update_meminfo)
1098                 char *buf = 0;
1099                 SIZE_DEFAULTS(graph);
1100                 buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
1101                                 &obj->e, &obj->char_a, &obj->char_b);
1102
1103                 if (buf) free(buf);
1104 #endif /* X11*/
1105         END OBJ(mixer, 0)
1106                 obj->data.l = mixer_init(arg);
1107         END OBJ(mixerl, 0)
1108                 obj->data.l = mixer_init(arg);
1109         END OBJ(mixerr, 0)
1110                 obj->data.l = mixer_init(arg);
1111 #ifdef X11
1112         END OBJ(mixerbar, 0)
1113                 SIZE_DEFAULTS(bar);
1114                 scan_mixer_bar(arg, &obj->data.mixerbar.l, &obj->data.mixerbar.w,
1115                         &obj->data.mixerbar.h);
1116         END OBJ(mixerlbar, 0)
1117                 SIZE_DEFAULTS(bar);
1118                 scan_mixer_bar(arg, &obj->data.mixerbar.l, &obj->data.mixerbar.w,
1119                         &obj->data.mixerbar.h);
1120         END OBJ(mixerrbar, 0)
1121                 SIZE_DEFAULTS(bar);
1122                 scan_mixer_bar(arg, &obj->data.mixerbar.l, &obj->data.mixerbar.w,
1123                         &obj->data.mixerbar.h);
1124 #endif
1125         END OBJ_IF(if_mixer_mute, 0)
1126                 obj->data.ifblock.i = mixer_init(arg);
1127 #ifdef X11
1128         END OBJ(monitor, &update_x11info)
1129         END OBJ(monitor_number, &update_x11info)
1130         END OBJ(desktop, &update_x11info)
1131         END OBJ(desktop_number, &update_x11info)
1132         END OBJ(desktop_name, &update_x11info)
1133 #endif
1134         END OBJ(nodename, 0)
1135         END OBJ(processes, &update_total_processes)
1136         END OBJ(running_processes, &update_running_processes)
1137         END OBJ(shadecolor, 0)
1138 #ifdef X11
1139                 obj->data.l = arg ? get_x11_color(arg) : default_bg_color;
1140 #endif /* X11 */
1141         END OBJ(outlinecolor, 0)
1142 #ifdef X11
1143                 obj->data.l = arg ? get_x11_color(arg) : default_out_color;
1144 #endif /* X11 */
1145         END OBJ(stippled_hr, 0)
1146 #ifdef X11
1147                 int a = get_stippled_borders(), b = 1;
1148
1149                 if (arg) {
1150                         if (sscanf(arg, "%d %d", &a, &b) != 2) {
1151                                 sscanf(arg, "%d", &b);
1152                         }
1153                 }
1154                 if (a <= 0) {
1155                         a = 1;
1156                 }
1157                 obj->data.pair.a = a;
1158                 obj->data.pair.b = b;
1159 #endif /* X11 */
1160         END OBJ(swap, &update_meminfo)
1161         END OBJ(swapfree, &update_meminfo)
1162         END OBJ(swapmax, &update_meminfo)
1163         END OBJ(swapperc, &update_meminfo)
1164         END OBJ(swapbar, &update_meminfo)
1165                 SIZE_DEFAULTS(bar);
1166                 scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
1167         END OBJ(sysname, 0)
1168         END OBJ(time, 0)
1169                 scan_time(obj, arg);
1170         END OBJ(utime, 0)
1171                 scan_time(obj, arg);
1172         END OBJ(tztime, 0)
1173                 scan_tztime(obj, arg);
1174 #ifdef HAVE_ICONV
1175         END OBJ_ARG(iconv_start, 0, "Iconv requires arguments")
1176                 init_iconv_start(obj, free_at_crash, arg);
1177         END OBJ(iconv_stop, 0)
1178                 init_iconv_stop();
1179 #endif
1180         END OBJ(totaldown, &update_net_stats)
1181                 if (arg) {
1182                         obj->data.net = get_net_stat(arg, obj, free_at_crash);
1183                 } else {
1184                         // default to DEFAULTNETDEV
1185                         char *buf = strndup(DEFAULTNETDEV, text_buffer_size);
1186                         obj->data.net = get_net_stat(buf, obj, free_at_crash);
1187                         free(buf);
1188                 }
1189         END OBJ(totalup, &update_net_stats)
1190                 obj->data.net = get_net_stat(arg, obj, free_at_crash);
1191                 if (arg) {
1192                         obj->data.net = get_net_stat(arg, obj, free_at_crash);
1193                 } else {
1194                         // default to DEFAULTNETDEV
1195                         char *buf = strndup(DEFAULTNETDEV, text_buffer_size);
1196                         obj->data.net = get_net_stat(buf, obj, free_at_crash);
1197                         free(buf);
1198                 }
1199         END OBJ(updates, 0)
1200         END OBJ_IF(if_updatenr, 0)
1201                 obj->data.ifblock.i = arg ? atoi(arg) : 0;
1202                 if(obj->data.ifblock.i == 0) CRIT_ERR(obj, free_at_crash, "if_updatenr needs a number above 0 as argument");
1203                 set_updatereset(obj->data.ifblock.i > get_updatereset() ? obj->data.ifblock.i : get_updatereset());
1204         END OBJ(alignr, 0)
1205                 obj->data.i = arg ? atoi(arg) : 0;
1206         END OBJ(alignc, 0)
1207                 obj->data.i = arg ? atoi(arg) : 0;
1208         END OBJ(upspeed, &update_net_stats)
1209                 if (arg) {
1210                         obj->data.net = get_net_stat(arg, obj, free_at_crash);
1211                 } else {
1212                         // default to DEFAULTNETDEV
1213                         char *buf = strndup(DEFAULTNETDEV, text_buffer_size);
1214                         obj->data.net = get_net_stat(buf, obj, free_at_crash);
1215                         free(buf);
1216                 }
1217         END OBJ(upspeedf, &update_net_stats)
1218                 if (arg) {
1219                         obj->data.net = get_net_stat(arg, obj, free_at_crash);
1220                 } else {
1221                         // default to DEFAULTNETDEV
1222                         char *buf = strndup(DEFAULTNETDEV, text_buffer_size);
1223                         obj->data.net = get_net_stat(buf, obj, free_at_crash);
1224                         free(buf);
1225                 }
1226
1227 #ifdef X11
1228         END OBJ(upspeedgraph, &update_net_stats)
1229                 char *buf = 0;
1230                 SIZE_DEFAULTS(graph);
1231                 buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
1232                                 &obj->e, &obj->char_a, &obj->char_b);
1233
1234                 // default to DEFAULTNETDEV
1235                 buf = strndup(buf ? buf : DEFAULTNETDEV, text_buffer_size);
1236                 obj->data.net = get_net_stat(buf, obj, free_at_crash);
1237                 free(buf);
1238 #endif
1239         END OBJ(uptime_short, &update_uptime)
1240         END OBJ(uptime, &update_uptime)
1241         END OBJ(user_names, &update_users)
1242         END OBJ(user_times, &update_users)
1243         END OBJ(user_terms, &update_users)
1244         END OBJ(user_number, &update_users)
1245 #if defined(__linux__)
1246         END OBJ(gw_iface, &update_gateway_info)
1247         END OBJ(gw_ip, &update_gateway_info)
1248 #endif /* !__linux__ */
1249 #ifndef __OpenBSD__
1250         END OBJ(adt746xcpu, 0)
1251         END OBJ(adt746xfan, 0)
1252 #endif /* !__OpenBSD__ */
1253 #if (defined(__FreeBSD__) || defined(__FreeBSD_kernel__) \
1254                 || defined(__OpenBSD__)) && (defined(i386) || defined(__i386__))
1255         END OBJ(apm_adapter, 0)
1256         END OBJ(apm_battery_life, 0)
1257         END OBJ(apm_battery_time, 0)
1258 #endif /* __FreeBSD__ */
1259         END OBJ(imap_unseen, 0)
1260                 if (arg) {
1261                         // proccss
1262                         obj->data.mail = parse_mail_args(IMAP_TYPE, arg);
1263                         obj->char_b = 0;
1264                 } else {
1265                         obj->char_b = 1;
1266                 }
1267         END OBJ(imap_messages, 0)
1268                 if (arg) {
1269                         // proccss
1270                         obj->data.mail = parse_mail_args(IMAP_TYPE, arg);
1271                         obj->char_b = 0;
1272                 } else {
1273                         obj->char_b = 1;
1274                 }
1275         END OBJ(pop3_unseen, 0)
1276                 if (arg) {
1277                         // proccss
1278                         obj->data.mail = parse_mail_args(POP3_TYPE, arg);
1279                         obj->char_b = 0;
1280                 } else {
1281                         obj->char_b = 1;
1282                 }
1283         END OBJ(pop3_used, 0)
1284                 if (arg) {
1285                         // proccss
1286                         obj->data.mail = parse_mail_args(POP3_TYPE, arg);
1287                         obj->char_b = 0;
1288                 } else {
1289                         obj->char_b = 1;
1290                 }
1291 #ifdef IBM
1292         END OBJ_ARG(smapi, 0, "smapi needs an argument")
1293                 obj->data.s = strndup(arg, text_buffer_size);
1294         END OBJ_IF_ARG(if_smapi_bat_installed, 0, "if_smapi_bat_installed needs an argument")
1295                 obj->data.ifblock.s = strndup(arg, text_buffer_size);
1296         END OBJ_ARG(smapi_bat_perc, 0, "smapi_bat_perc needs an argument")
1297                 obj->data.s = strndup(arg, text_buffer_size);
1298         END OBJ_ARG(smapi_bat_temp, 0, "smapi_bat_temp needs an argument")
1299                 obj->data.s = strndup(arg, text_buffer_size);
1300         END OBJ_ARG(smapi_bat_power, 0, "smapi_bat_power needs an argument")
1301                 obj->data.s = strndup(arg, text_buffer_size);
1302 #ifdef X11
1303         END OBJ_ARG(smapi_bat_bar, 0, "smapi_bat_bar needs an argument")
1304                 int cnt;
1305                 SIZE_DEFAULTS(bar);
1306                 if(sscanf(arg, "%i %n", &obj->data.i, &cnt) <= 0) {
1307                         NORM_ERR("first argument to smapi_bat_bar must be an integer value");
1308                         obj->data.i = -1;
1309                 } else {
1310                         obj->b = 4;
1311                         arg = scan_bar(arg + cnt, &obj->a, &obj->b);
1312                 }
1313 #endif /* X11 */
1314 #endif /* IBM */
1315 #ifdef MPD
1316 #define mpd_set_maxlen(name) \
1317                 if (arg) { \
1318                         int i; \
1319                         sscanf(arg, "%d", &i); \
1320                         if (i > 0) \
1321                                 obj->data.i = i + 1; \
1322                         else \
1323                                 NORM_ERR(#name ": invalid length argument"); \
1324                 }
1325         END OBJ(mpd_artist, &update_mpd)
1326                 mpd_set_maxlen(mpd_artist);
1327                 init_mpd();
1328         END OBJ(mpd_title, &update_mpd)
1329                 mpd_set_maxlen(mpd_title);
1330                 init_mpd();
1331         END OBJ(mpd_random, &update_mpd) init_mpd();
1332         END OBJ(mpd_repeat, &update_mpd) init_mpd();
1333         END OBJ(mpd_elapsed, &update_mpd) init_mpd();
1334         END OBJ(mpd_length, &update_mpd) init_mpd();
1335         END OBJ(mpd_track, &update_mpd)
1336                 mpd_set_maxlen(mpd_track);
1337                 init_mpd();
1338         END OBJ(mpd_name, &update_mpd)
1339                 mpd_set_maxlen(mpd_name);
1340                 init_mpd();
1341         END OBJ(mpd_file, &update_mpd)
1342                 mpd_set_maxlen(mpd_file);
1343                 init_mpd();
1344         END OBJ(mpd_percent, &update_mpd) init_mpd();
1345         END OBJ(mpd_album, &update_mpd)
1346                 mpd_set_maxlen(mpd_album);
1347                 init_mpd();
1348         END OBJ(mpd_vol, &update_mpd) init_mpd();
1349         END OBJ(mpd_bitrate, &update_mpd) init_mpd();
1350         END OBJ(mpd_status, &update_mpd) init_mpd();
1351         END OBJ(mpd_bar, &update_mpd)
1352                 SIZE_DEFAULTS(bar);
1353                 scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
1354                 init_mpd();
1355         END OBJ(mpd_smart, &update_mpd)
1356                 mpd_set_maxlen(mpd_smart);
1357                 init_mpd();
1358         END OBJ_IF(if_mpd_playing, &update_mpd)
1359                 init_mpd();
1360 #undef mpd_set_maxlen
1361 #endif /* MPD */
1362 #ifdef MOC
1363         END OBJ(moc_state, &update_moc)
1364         END OBJ(moc_file, &update_moc)
1365         END OBJ(moc_title, &update_moc)
1366         END OBJ(moc_artist, &update_moc)
1367         END OBJ(moc_song, &update_moc)
1368         END OBJ(moc_album, &update_moc)
1369         END OBJ(moc_totaltime, &update_moc)
1370         END OBJ(moc_timeleft, &update_moc)
1371         END OBJ(moc_curtime, &update_moc)
1372         END OBJ(moc_bitrate, &update_moc)
1373         END OBJ(moc_rate, &update_moc)
1374 #endif /* MOC */
1375 #ifdef XMMS2
1376         END OBJ(xmms2_artist, &update_xmms2)
1377         END OBJ(xmms2_album, &update_xmms2)
1378         END OBJ(xmms2_title, &update_xmms2)
1379         END OBJ(xmms2_genre, &update_xmms2)
1380         END OBJ(xmms2_comment, &update_xmms2)
1381         END OBJ(xmms2_url, &update_xmms2)
1382         END OBJ(xmms2_tracknr, &update_xmms2)
1383         END OBJ(xmms2_bitrate, &update_xmms2)
1384         END OBJ(xmms2_date, &update_xmms2)
1385         END OBJ(xmms2_id, &update_xmms2)
1386         END OBJ(xmms2_duration, &update_xmms2)
1387         END OBJ(xmms2_elapsed, &update_xmms2)
1388         END OBJ(xmms2_size, &update_xmms2)
1389         END OBJ(xmms2_status, &update_xmms2)
1390         END OBJ(xmms2_percent, &update_xmms2)
1391 #ifdef X11
1392         END OBJ(xmms2_bar, &update_xmms2)
1393                 SIZE_DEFAULTS(bar);
1394                 scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
1395 #endif /* X11 */
1396         END OBJ(xmms2_smart, &update_xmms2)
1397         END OBJ(xmms2_playlist, &update_xmms2)
1398         END OBJ(xmms2_timesplayed, &update_xmms2)
1399         END OBJ_IF(if_xmms2_connected, &update_xmms2)
1400 #endif
1401 #ifdef AUDACIOUS
1402         END OBJ(audacious_status, &update_audacious)
1403         END OBJ_ARG(audacious_title, &update_audacious, "audacious_title needs an argument")
1404                 sscanf(arg, "%d", &info.audacious.max_title_len);
1405                 if (info.audacious.max_title_len > 0) {
1406                         info.audacious.max_title_len++;
1407                 } else {
1408                         CRIT_ERR(obj, free_at_crash, "audacious_title: invalid length argument");
1409                 }
1410         END OBJ(audacious_length, &update_audacious)
1411         END OBJ(audacious_length_seconds, &update_audacious)
1412         END OBJ(audacious_position, &update_audacious)
1413         END OBJ(audacious_position_seconds, &update_audacious)
1414         END OBJ(audacious_bitrate, &update_audacious)
1415         END OBJ(audacious_frequency, &update_audacious)
1416         END OBJ(audacious_channels, &update_audacious)
1417         END OBJ(audacious_filename, &update_audacious)
1418         END OBJ(audacious_playlist_length, &update_audacious)
1419         END OBJ(audacious_playlist_position, &update_audacious)
1420         END OBJ(audacious_main_volume, &update_audacious)
1421 #ifdef X11
1422         END OBJ(audacious_bar, &update_audacious)
1423                 SIZE_DEFAULTS(bar);
1424                 scan_bar(arg, &obj->a, &obj->b);
1425 #endif /* X11 */
1426 #endif
1427 #ifdef BMPX
1428         END OBJ(bmpx_title, &update_bmpx)
1429                 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
1430         END OBJ(bmpx_artist, &update_bmpx)
1431                 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
1432         END OBJ(bmpx_album, &update_bmpx)
1433                 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
1434         END OBJ(bmpx_track, &update_bmpx)
1435                 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
1436         END OBJ(bmpx_uri, &update_bmpx)
1437                 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
1438         END OBJ(bmpx_bitrate, &update_bmpx)
1439                 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
1440 #endif
1441 #ifdef EVE
1442         END OBJ_ARG(eve, 0, "eve needs arguments: <userid> <apikey> <characterid>")
1443                 scan_eve(obj, arg);
1444 #endif
1445 #ifdef HAVE_CURL
1446         END OBJ_ARG(curl, 0, "curl needs arguments: <uri> <interval in minutes>")
1447                 curl_parse_arg(obj, arg);
1448 #endif
1449 #ifdef RSS
1450         END OBJ_ARG(rss, 0, "rss needs arguments: <uri> <interval in minutes> <action> [act_par] [spaces in front]")
1451                 rss_scan_arg(obj, arg);
1452 #endif
1453 #ifdef WEATHER
1454         END OBJ_ARG(weather, 0, "weather needs arguments: <uri> <locID> <data_type> [interval in minutes]")
1455                 scan_weather_arg(obj, arg, free_at_crash);
1456 #endif
1457 #ifdef XOAP
1458         END OBJ_ARG(weather_forecast, 0, "weather_forecast needs arguments: <uri> <locID> <day> <data_type> [interval in minutes]")
1459                 scan_weather_forecast_arg(obj, arg, free_at_crash);
1460 #endif
1461 #ifdef HAVE_LUA
1462         END OBJ_ARG(lua, 0, "lua needs arguments: <function name> [function parameters]")
1463                 obj->data.s = strndup(arg, text_buffer_size);
1464         END OBJ_ARG(lua_parse, 0, "lua_parse needs arguments: <function name> [function parameters]")
1465                 obj->data.s = strndup(arg, text_buffer_size);
1466         END OBJ_ARG(lua_bar, 0, "lua_bar needs arguments: <height>,<width> <function name> [function parameters]")
1467                 SIZE_DEFAULTS(bar);
1468                 arg = scan_bar(arg, &obj->a, &obj->b);
1469                 if(arg) {
1470                         obj->data.s = strndup(arg, text_buffer_size);
1471                 } else {
1472                         CRIT_ERR(obj, free_at_crash, "lua_bar needs arguments: <height>,<width> <function name> [function parameters]");
1473                 }
1474 #ifdef X11
1475         END OBJ_ARG(lua_graph, 0, "lua_graph needs arguments: <function name> [height],[width] [gradient colour 1] [gradient colour 2] [scale] [-t] [-l]")
1476                 char *buf = 0;
1477                 SIZE_DEFAULTS(graph);
1478                 buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
1479                                 &obj->e, &obj->char_a, &obj->char_b);
1480                 if (buf) {
1481                         obj->data.s = buf;
1482                 } else {
1483                         CRIT_ERR(obj, free_at_crash, "lua_graph needs arguments: <function name> [height],[width] [gradient colour 1] [gradient colour 2] [scale] [-t] [-l]");
1484                 }
1485         END OBJ_ARG(lua_gauge, 0, "lua_gauge needs arguments: <height>,<width> <function name> [function parameters]")
1486                 SIZE_DEFAULTS(gauge);
1487                 arg = scan_gauge(arg, &obj->a, &obj->b);
1488                 if (arg) {
1489                         obj->data.s = strndup(arg, text_buffer_size);
1490                 } else {
1491                         CRIT_ERR(obj, free_at_crash, "lua_gauge needs arguments: <height>,<width> <function name> [function parameters]");
1492                 }
1493 #endif /* X11 */
1494 #endif /* HAVE_LUA */
1495 #ifdef HDDTEMP
1496         END OBJ(hddtemp, &update_hddtemp)
1497                 if (arg)
1498                         obj->data.s = strndup(arg, text_buffer_size);
1499 #endif /* HDDTEMP */
1500 #ifdef TCP_PORT_MONITOR
1501         END OBJ_ARG(tcp_portmon, &tcp_portmon_update, "tcp_portmon: needs arguments")
1502                 tcp_portmon_init(arg, &obj->data.tcp_port_monitor);
1503 #endif /* TCP_PORT_MONITOR */
1504         END OBJ(entropy_avail, &update_entropy)
1505         END OBJ(entropy_perc, &update_entropy)
1506         END OBJ(entropy_poolsize, &update_entropy)
1507         END OBJ(entropy_bar, &update_entropy)
1508                 SIZE_DEFAULTS(bar);
1509                 scan_bar(arg, &obj->a, &obj->b);
1510         END OBJ_ARG(include, 0, "include needs a argument")
1511                 struct conftree *leaf = conftree_add(currentconffile, arg);
1512                 if(leaf) {
1513                         if (load_config_file(arg) == TRUE) {
1514                                 obj->sub = malloc(sizeof(struct text_object));
1515                                 currentconffile = leaf;
1516                                 extract_variable_text_internal(obj->sub, get_global_text());
1517                                 currentconffile = leaf->back;
1518                         } else {
1519                                 NORM_ERR("Can't load configfile '%s'.", arg);
1520                         }
1521                 } else {
1522                         NORM_ERR("You are trying to load '%s' recursively, I'm only going to load it once to prevent an infinite loop.", arg);
1523                 }
1524         END OBJ_ARG(blink, 0, "blink needs a argument")
1525                 obj->sub = malloc(sizeof(struct text_object));
1526                 extract_variable_text_internal(obj->sub, arg);
1527         END OBJ_ARG(to_bytes, 0, "to_bytes needs a argument")
1528                 obj->sub = malloc(sizeof(struct text_object));
1529                 extract_variable_text_internal(obj->sub, arg);
1530         END OBJ(scroll, 0)
1531                 int n1 = 0, n2 = 0;
1532
1533                 obj->data.scroll.resetcolor = get_current_text_color();
1534                 obj->data.scroll.step = 1;
1535                 if (arg && sscanf(arg, "%u %n", &obj->data.scroll.show, &n1) > 0) {
1536                         sscanf(arg + n1, "%u %n", &obj->data.scroll.step, &n2);
1537                         if (*(arg + n1 + n2)) {
1538                                 n1 += n2;
1539                         } else {
1540                                 obj->data.scroll.step = 1;
1541                         }
1542                         obj->data.scroll.text = malloc(strlen(arg + n1) + obj->data.scroll.show + 1);
1543                         for(n2 = 0; (unsigned int) n2 < obj->data.scroll.show; n2++) {
1544                                 obj->data.scroll.text[n2] = ' ';
1545                         }
1546                         obj->data.scroll.text[n2] = 0;
1547                         strcat(obj->data.scroll.text, arg + n1);
1548                         obj->data.scroll.start = 0;
1549                         obj->sub = malloc(sizeof(struct text_object));
1550                         extract_variable_text_internal(obj->sub,
1551                                         obj->data.scroll.text);
1552                 } else {
1553                         CRIT_ERR(obj, free_at_crash, "scroll needs arguments: <length> [<step>] <text>");
1554                 }
1555         END OBJ_ARG(combine, 0, "combine needs arguments: <text1> <text2>")
1556                 unsigned int i,j;
1557                 unsigned int indenting = 0;     //vars can be used as args for other vars
1558                 int startvar[2];
1559                 int endvar[2];
1560                 startvar[0] = endvar[0] = startvar[1] = endvar[1] = -1;
1561                 j=0;
1562                 for (i=0; arg[i] != 0 && j < 2; i++) {
1563                         if(startvar[j] == -1) {
1564                                 if(arg[i] == '$') {
1565                                         startvar[j] = i;
1566                                 }
1567                         }else if(endvar[j] == -1) {
1568                                 if(arg[i] == '{') {
1569                                         indenting++;
1570                                 }else if(arg[i] == '}') {
1571                                         indenting--;
1572                                 }
1573                                 if (indenting == 0 && arg[i+1] < 48) {  //<48 has 0, $, and the most used chars not used in varnames but not { or }
1574                                         endvar[j]=i+1;
1575                                         j++;
1576                                 }
1577                         }
1578                 }
1579                 if(startvar[0] >= 0 && endvar[0] >= 0 && startvar[1] >= 0 && endvar[1] >= 0) {
1580                         obj->data.combine.left = malloc(endvar[0]-startvar[0] + 1);
1581                         obj->data.combine.seperation = malloc(startvar[1] - endvar[0] + 1);
1582                         obj->data.combine.right= malloc(endvar[1]-startvar[1] + 1);
1583
1584                         strncpy(obj->data.combine.left, arg + startvar[0], endvar[0] - startvar[0]);
1585                         obj->data.combine.left[endvar[0] - startvar[0]] = 0;
1586
1587                         strncpy(obj->data.combine.seperation, arg + endvar[0], startvar[1] - endvar[0]);
1588                         obj->data.combine.seperation[startvar[1] - endvar[0]] = 0;
1589
1590                         strncpy(obj->data.combine.right, arg + startvar[1], endvar[1] - startvar[1]);
1591                         obj->data.combine.right[endvar[1] - startvar[1]] = 0;
1592
1593                         obj->sub = malloc(sizeof(struct text_object));
1594                         extract_variable_text_internal(obj->sub, obj->data.combine.left);
1595                         obj->sub->sub = malloc(sizeof(struct text_object));
1596                         extract_variable_text_internal(obj->sub->sub, obj->data.combine.right);
1597                 } else {
1598                         CRIT_ERR(obj, free_at_crash, "combine needs arguments: <text1> <text2>");
1599                 }
1600 #ifdef NVIDIA
1601         END OBJ_ARG(nvidia, 0, "nvidia needs an argument")
1602                 if (set_nvidia_type(&obj->data.nvidia, arg)) {
1603                         CRIT_ERR(obj, free_at_crash, "nvidia: invalid argument"
1604                                  " specified: '%s'\n", arg);
1605                 }
1606 #endif /* NVIDIA */
1607 #ifdef APCUPSD
1608         END OBJ_ARG(apcupsd, &update_apcupsd, "apcupsd needs arguments: <host> <port>")
1609                 char host[64];
1610                 int port;
1611                 if (sscanf(arg, "%63s %d", host, &port) != 2) {
1612                         CRIT_ERR(obj, free_at_crash, "apcupsd needs arguments: <host> <port>");
1613                 } else {
1614                         info.apcupsd.port = htons(port);
1615                         strncpy(info.apcupsd.host, host, sizeof(info.apcupsd.host));
1616                 }
1617         END OBJ(apcupsd_name, &update_apcupsd)
1618         END OBJ(apcupsd_model, &update_apcupsd)
1619         END OBJ(apcupsd_upsmode, &update_apcupsd)
1620         END OBJ(apcupsd_cable, &update_apcupsd)
1621         END OBJ(apcupsd_status, &update_apcupsd)
1622         END OBJ(apcupsd_linev, &update_apcupsd)
1623         END OBJ(apcupsd_load, &update_apcupsd)
1624         END OBJ(apcupsd_loadbar, &update_apcupsd)
1625                 SIZE_DEFAULTS(bar);
1626                 scan_bar(arg, &obj->a, &obj->b);
1627 #ifdef X11
1628         END OBJ(apcupsd_loadgraph, &update_apcupsd)
1629                 char* buf = 0;
1630                 SIZE_DEFAULTS(graph);
1631                 buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
1632                                 &obj->e, &obj->char_a, &obj->char_b);
1633                 if (buf) free(buf);
1634         END OBJ(apcupsd_loadgauge, &update_apcupsd)
1635                 SIZE_DEFAULTS(gauge);
1636                 scan_gauge(arg, &obj->a, &obj->b);
1637 #endif /* X11 */
1638         END OBJ(apcupsd_charge, &update_apcupsd)
1639         END OBJ(apcupsd_timeleft, &update_apcupsd)
1640         END OBJ(apcupsd_temp, &update_apcupsd)
1641         END OBJ(apcupsd_lastxfer, &update_apcupsd)
1642 #endif /* APCUPSD */
1643         END {
1644                 char buf[256];
1645
1646                 NORM_ERR("unknown variable %s", s);
1647                 obj->type = OBJ_text;
1648                 snprintf(buf, 256, "${%s}", s);
1649                 obj->data.s = strndup(buf, text_buffer_size);
1650         }
1651 #undef OBJ
1652 #undef OBJ_IF
1653 #undef OBJ_ARG
1654 #undef OBJ_IF_ARG
1655 #undef __OBJ_HEAD
1656 #undef __OBJ_IF
1657 #undef __OBJ_ARG
1658 #undef END
1659 #undef SIZE_DEFAULTS
1660
1661         return obj;
1662 }
1663
1664 /*
1665  * - assumes that *string is '#'
1666  * - removes the part from '#' to the end of line ('\n' or '\0')
1667  * - it removes the '\n'
1668  * - copies the last char into 'char *last' argument, which should be a pointer
1669  *   to a char rather than a string.
1670  */
1671 static size_t remove_comment(char *string, char *last)
1672 {
1673         char *end = string;
1674         while (*end != '\0' && *end != '\n') {
1675                 ++end;
1676         }
1677         if (last) *last = *end;
1678         if (*end == '\n') end++;
1679         strfold(string, end - string);
1680         return end - string;
1681 }
1682
1683 size_t remove_comments(char *string)
1684 {
1685         char *curplace;
1686         size_t folded = 0;
1687         for (curplace = string; *curplace != 0; curplace++) {
1688                 if (*curplace == '\\' && *(curplace + 1) == '#') {
1689                         // strcpy can't be used for overlapping strings
1690                         strfold(curplace, 1);
1691                         folded += 1;
1692                 } else if (*curplace == '#') {
1693                         folded += remove_comment(curplace, 0);
1694                 }
1695         }
1696         return folded;
1697 }
1698
1699 int extract_variable_text_internal(struct text_object *retval, const char *const_p)
1700 {
1701         struct text_object *obj;
1702         char *p, *s, *orig_p;
1703         long line;
1704         void *ifblock_opaque = NULL;
1705         char *tmp_p;
1706         char *arg = 0;
1707         size_t len = 0;
1708
1709         p = strndup(const_p, max_user_text - 1);
1710         while (text_contains_templates(p)) {
1711                 char *tmp;
1712                 tmp = find_and_replace_templates(p);
1713                 free(p);
1714                 p = tmp;
1715         }
1716         s = orig_p = p;
1717
1718         if (strcmp(p, const_p)) {
1719                 DBGP("replaced all templates in text: input is\n'%s'\noutput is\n'%s'", const_p, p);
1720         } else {
1721                 DBGP("no templates to replace");
1722         }
1723
1724         memset(retval, 0, sizeof(struct text_object));
1725
1726         line = global_text_lines;
1727
1728         while (*p) {
1729                 if (*p == '\n') {
1730                         line++;
1731                 }
1732                 if (*p == '$') {
1733                         *p = '\0';
1734                         obj = create_plain_text(s);
1735                         if (obj != NULL) {
1736                                 append_object(retval, obj);
1737                         }
1738                         *p = '$';
1739                         p++;
1740                         s = p;
1741
1742                         if (*p != '$') {
1743                                 char buf[256];
1744                                 const char *var;
1745
1746                                 /* variable is either $foo or ${foo} */
1747                                 if (*p == '{') {
1748                                         unsigned int brl = 1, brr = 0;
1749
1750                                         p++;
1751                                         s = p;
1752                                         while (*p && brl != brr) {
1753                                                 if (*p == '{') {
1754                                                         brl++;
1755                                                 }
1756                                                 if (*p == '}') {
1757                                                         brr++;
1758                                                 }
1759                                                 p++;
1760                                         }
1761                                         p--;
1762                                 } else {
1763                                         s = p;
1764                                         if (*p == '#') {
1765                                                 p++;
1766                                         }
1767                                         while (*p && (isalnum((int) *p) || *p == '_')) {
1768                                                 p++;
1769                                         }
1770                                 }
1771
1772                                 /* copy variable to buffer */
1773                                 len = (p - s > 255) ? 255 : (p - s);
1774                                 strncpy(buf, s, len);
1775                                 buf[len] = '\0';
1776
1777                                 if (*p == '}') {
1778                                         p++;
1779                                 }
1780                                 s = p;
1781
1782                                 /* search for variable in environment */
1783
1784                                 var = getenv(buf);
1785                                 if (var) {
1786                                         obj = create_plain_text(var);
1787                                         if (obj) {
1788                                                 append_object(retval, obj);
1789                                         }
1790                                         continue;
1791                                 }
1792
1793                                 /* if variable wasn't found in environment, use some special */
1794
1795                                 arg = 0;
1796
1797                                 /* split arg */
1798                                 if (strchr(buf, ' ')) {
1799                                         arg = strchr(buf, ' ');
1800                                         *arg = '\0';
1801                                         arg++;
1802                                         while (isspace((int) *arg)) {
1803                                                 arg++;
1804                                         }
1805                                         if (!*arg) {
1806                                                 arg = 0;
1807                                         }
1808                                 }
1809
1810                                 /* lowercase variable name */
1811                                 tmp_p = buf;
1812                                 while (*tmp_p) {
1813                                         *tmp_p = tolower(*tmp_p);
1814                                         tmp_p++;
1815                                 }
1816
1817                                 obj = construct_text_object(buf, arg,
1818                                                 line, &ifblock_opaque, orig_p);
1819                                 if (obj != NULL) {
1820                                         append_object(retval, obj);
1821                                 }
1822                                 continue;
1823                         } else {
1824                                 obj = create_plain_text("$");
1825                                 s = p + 1;
1826                                 if (obj != NULL) {
1827                                         append_object(retval, obj);
1828                                 }
1829                         }
1830                 } else if (*p == '\\' && *(p+1) == '#') {
1831                         strfold(p, 1);
1832                 } else if (*p == '#') {
1833                         char c;
1834                         if (remove_comment(p, &c) && p > orig_p && c == '\n') {
1835                                 /* if remove_comment removed a newline, we need to 'back up' with p */
1836                                 p--;
1837                         }
1838                 }
1839                 p++;
1840         }
1841         obj = create_plain_text(s);
1842         if (obj != NULL) {
1843                 append_object(retval, obj);
1844         }
1845
1846         if (!ifblock_stack_empty(&ifblock_opaque)) {
1847                 NORM_ERR("one or more $endif's are missing");
1848         }
1849
1850         free(orig_p);
1851         return 0;
1852 }
1853
1854 /*
1855  * Frees the list of text objects root points to.  When internal = 1, it won't
1856  * free global objects.
1857  */
1858 void free_text_objects(struct text_object *root, int internal)
1859 {
1860         struct text_object *obj;
1861
1862         if (!root->prev) {
1863                 return;
1864         }
1865
1866 #define data obj->data
1867         for (obj = root->prev; obj; obj = root->prev) {
1868                 root->prev = obj->prev;
1869                 switch (obj->type) {
1870 #ifndef __OpenBSD__
1871                         case OBJ_acpitemp:
1872                                 close(data.i);
1873                                 break;
1874 #endif /* !__OpenBSD__ */
1875 #ifdef __linux__
1876                         case OBJ_i2c:
1877                         case OBJ_platform:
1878                         case OBJ_hwmon:
1879                                 close(data.sysfs.fd);
1880                                 break;
1881 #endif /* __linux__ */
1882                         case OBJ_read_tcp:
1883                                 free(data.read_tcp.host);
1884                                 break;
1885                         case OBJ_time:
1886                         case OBJ_utime:
1887                                 free_time(obj);
1888                                 break;
1889                         case OBJ_tztime:
1890                                 free_tztime(obj);
1891                                 break;
1892                         case OBJ_mboxscan:
1893                                 free(data.mboxscan.args);
1894                                 free(data.mboxscan.output);
1895                                 break;
1896                         case OBJ_mails:
1897                         case OBJ_new_mails:
1898                         case OBJ_seen_mails:
1899                         case OBJ_unseen_mails:
1900                         case OBJ_flagged_mails:
1901                         case OBJ_unflagged_mails:
1902                         case OBJ_forwarded_mails:
1903                         case OBJ_unforwarded_mails:
1904                         case OBJ_replied_mails:
1905                         case OBJ_unreplied_mails:
1906                         case OBJ_draft_mails:
1907                         case OBJ_trashed_mails:
1908                                 free(data.local_mail.mbox);
1909                                 break;
1910                         case OBJ_imap_unseen:
1911                                 if (!obj->char_b) {
1912                                         free(data.mail);
1913                                 }
1914                                 break;
1915                         case OBJ_imap_messages:
1916                                 if (!obj->char_b) {
1917                                         free(data.mail);
1918                                 }
1919                                 break;
1920                         case OBJ_pop3_unseen:
1921                                 if (!obj->char_b) {
1922                                         free(data.mail);
1923                                 }
1924                                 break;
1925                         case OBJ_pop3_used:
1926                                 if (!obj->char_b) {
1927                                         free(data.mail);
1928                                 }
1929                                 break;
1930                         case OBJ_if_empty:
1931                         case OBJ_if_match:
1932                                 free_text_objects(obj->sub, 1);
1933                                 free(obj->sub);
1934                                 /* fall through */
1935                         case OBJ_if_existing:
1936                         case OBJ_if_mounted:
1937                         case OBJ_if_running:
1938                                 free(data.ifblock.s);
1939                                 free(data.ifblock.str);
1940                                 break;
1941                         case OBJ_head:
1942                         case OBJ_tail:
1943                                 free(data.headtail.logfile);
1944                                 if(data.headtail.buffer) {
1945                                         free(data.headtail.buffer);
1946                                 }
1947                                 break;
1948                         case OBJ_text:
1949                         case OBJ_font:
1950                         case OBJ_image:
1951                         case OBJ_eval:
1952                         case OBJ_exec:
1953                         case OBJ_execbar:
1954 #ifdef X11
1955                         case OBJ_execgauge:
1956                         case OBJ_execgraph:
1957 #endif
1958                         case OBJ_execp:
1959                                 free(data.s);
1960                                 break;
1961 #ifdef HAVE_ICONV
1962                         case OBJ_iconv_start:
1963                                 free_iconv();
1964                                 break;
1965 #endif
1966 #ifdef __linux__
1967                         case OBJ_disk_protect:
1968                                 free(data.s);
1969                                 break;
1970                         case OBJ_if_gw:
1971                                 free(data.ifblock.s);
1972                                 free(data.ifblock.str);
1973                         case OBJ_gw_iface:
1974                         case OBJ_gw_ip:
1975                                 free_gateway_info();
1976                                 break;
1977                         case OBJ_ioscheduler:
1978                                 if(data.s)
1979                                         free(data.s);
1980                                 break;
1981 #endif
1982 #if (defined(__FreeBSD__) || defined(__linux__))
1983                         case OBJ_if_up:
1984                                 free(data.ifblock.s);
1985                                 free(data.ifblock.str);
1986                                 break;
1987 #endif
1988 #ifdef XMMS2
1989                         case OBJ_xmms2_artist:
1990                                 if (info.xmms2.artist) {
1991                                         free(info.xmms2.artist);
1992                                         info.xmms2.artist = 0;
1993                                 }
1994                                 break;
1995                         case OBJ_xmms2_album:
1996                                 if (info.xmms2.album) {
1997                                         free(info.xmms2.album);
1998                                         info.xmms2.album = 0;
1999                                 }
2000                                 break;
2001                         case OBJ_xmms2_title:
2002                                 if (info.xmms2.title) {
2003                                         free(info.xmms2.title);
2004                                         info.xmms2.title = 0;
2005                                 }
2006                                 break;
2007                         case OBJ_xmms2_genre:
2008                                 if (info.xmms2.genre) {
2009                                         free(info.xmms2.genre);
2010                                         info.xmms2.genre = 0;
2011                                 }
2012                                 break;
2013                         case OBJ_xmms2_comment:
2014                                 if (info.xmms2.comment) {
2015                                         free(info.xmms2.comment);
2016                                         info.xmms2.comment = 0;
2017                                 }
2018                                 break;
2019                         case OBJ_xmms2_url:
2020                                 if (info.xmms2.url) {
2021                                         free(info.xmms2.url);
2022                                         info.xmms2.url = 0;
2023                                 }
2024                                 break;
2025                         case OBJ_xmms2_date:
2026                                 if (info.xmms2.date) {
2027                                         free(info.xmms2.date);
2028                                         info.xmms2.date = 0;
2029                                 }
2030                                 break;
2031                         case OBJ_xmms2_status:
2032                                 if (info.xmms2.status) {
2033                                         free(info.xmms2.status);
2034                                         info.xmms2.status = 0;
2035                                 }
2036                                 break;
2037                         case OBJ_xmms2_playlist:
2038                                 if (info.xmms2.playlist) {
2039                                         free(info.xmms2.playlist);
2040                                         info.xmms2.playlist = 0;
2041                                 }
2042                                 break;
2043                         case OBJ_xmms2_smart:
2044                                 if (info.xmms2.artist) {
2045                                         free(info.xmms2.artist);
2046                                         info.xmms2.artist = 0;
2047                                 }
2048                                 if (info.xmms2.title) {
2049                                         free(info.xmms2.title);
2050                                         info.xmms2.title = 0;
2051                                 }
2052                                 if (info.xmms2.url) {
2053                                         free(info.xmms2.url);
2054                                         info.xmms2.url = 0;
2055                                 }
2056                                 break;
2057 #endif
2058 #ifdef BMPX
2059                         case OBJ_bmpx_title:
2060                         case OBJ_bmpx_artist:
2061                         case OBJ_bmpx_album:
2062                         case OBJ_bmpx_track:
2063                         case OBJ_bmpx_uri:
2064                         case OBJ_bmpx_bitrate:
2065                                 break;
2066 #endif
2067 #ifdef EVE
2068                         case OBJ_eve:
2069                                 break;
2070 #endif
2071 #ifdef HAVE_CURL
2072                         case OBJ_curl:
2073                                 free(data.curl.uri);
2074                                 break;
2075 #endif
2076 #ifdef RSS
2077                         case OBJ_rss:
2078                                 free(data.rss.uri);
2079                                 free(data.rss.action);
2080                                 break;
2081 #endif
2082 #ifdef WEATHER
2083                         case OBJ_weather:
2084                                 free(data.weather.uri);
2085                                 free(data.weather.data_type);
2086                                 break;
2087 #endif
2088 #ifdef XOAP
2089                         case OBJ_weather_forecast:
2090                                 free(data.weather_forecast.uri);
2091                                 free(data.weather_forecast.data_type);
2092                                 break;
2093 #endif
2094 #ifdef HAVE_LUA
2095                         case OBJ_lua:
2096                         case OBJ_lua_parse:
2097                         case OBJ_lua_bar:
2098 #ifdef X11
2099                         case OBJ_lua_graph:
2100                         case OBJ_lua_gauge:
2101 #endif /* X11 */
2102                                 free(data.s);
2103                                 break;
2104 #endif /* HAVE_LUA */
2105                         case OBJ_pre_exec:
2106                                 break;
2107 #ifndef __OpenBSD__
2108                         case OBJ_battery:
2109                                 free(data.s);
2110                                 break;
2111                         case OBJ_battery_short:
2112                                 free(data.s);
2113                                 break;
2114                         case OBJ_battery_time:
2115                                 free(data.s);
2116                                 break;
2117 #endif /* !__OpenBSD__ */
2118                         case OBJ_execpi:
2119                         case OBJ_execi:
2120                         case OBJ_execibar:
2121 #ifdef X11
2122                         case OBJ_execigraph:
2123                         case OBJ_execigauge:
2124 #endif /* X11 */
2125                                 free(data.execi.cmd);
2126                                 free(data.execi.buffer);
2127                                 break;
2128                         case OBJ_texeci:
2129                                 if (data.texeci.p_timed_thread) timed_thread_destroy(data.texeci.p_timed_thread, &data.texeci.p_timed_thread);
2130                                 free(data.texeci.cmd);
2131                                 free(data.texeci.buffer);
2132                                 break;
2133                         case OBJ_nameserver:
2134                                 free_dns_data();
2135                                 break;
2136                         case OBJ_top:
2137                         case OBJ_top_mem:
2138                         case OBJ_top_time:
2139 #ifdef IOSTATS
2140                         case OBJ_top_io:
2141 #endif
2142                                 if (info.first_process && !internal) {
2143                                         free_all_processes();
2144                                         info.first_process = NULL;
2145                                 }
2146                                 if (data.top.s) free(data.top.s);
2147                                 break;
2148 #ifdef HDDTEMP
2149                         case OBJ_hddtemp:
2150                                 if (data.s) {
2151                                         free(data.s);
2152                                         data.s = NULL;
2153                                 }
2154                                 free_hddtemp();
2155                                 break;
2156 #endif /* HDDTEMP */
2157                         case OBJ_entropy_avail:
2158                         case OBJ_entropy_perc:
2159                         case OBJ_entropy_poolsize:
2160                         case OBJ_entropy_bar:
2161                                 break;
2162                         case OBJ_user_names:
2163                                 if (info.users.names) {
2164                                         free(info.users.names);
2165                                         info.users.names = 0;
2166                                 }
2167                                 break;
2168                         case OBJ_user_terms:
2169                                 if (info.users.terms) {
2170                                         free(info.users.terms);
2171                                         info.users.terms = 0;
2172                                 }
2173                                 break;
2174                         case OBJ_user_times:
2175                                 if (info.users.times) {
2176                                         free(info.users.times);
2177                                         info.users.times = 0;
2178                                 }
2179                                 break;
2180 #ifdef IBM
2181                         case OBJ_smapi:
2182                         case OBJ_smapi_bat_perc:
2183                         case OBJ_smapi_bat_temp:
2184                         case OBJ_smapi_bat_power:
2185                                 free(data.s);
2186                                 break;
2187                         case OBJ_if_smapi_bat_installed:
2188                                 free(data.ifblock.s);
2189                                 free(data.ifblock.str);
2190                                 break;
2191 #endif /* IBM */
2192 #ifdef NVIDIA
2193                         case OBJ_nvidia:
2194                                 break;
2195 #endif /* NVIDIA */
2196 #ifdef MPD
2197                         case OBJ_mpd_title:
2198                         case OBJ_mpd_artist:
2199                         case OBJ_mpd_album:
2200                         case OBJ_mpd_random:
2201                         case OBJ_mpd_repeat:
2202                         case OBJ_mpd_vol:
2203                         case OBJ_mpd_bitrate:
2204                         case OBJ_mpd_status:
2205                         case OBJ_mpd_bar:
2206                         case OBJ_mpd_elapsed:
2207                         case OBJ_mpd_length:
2208                         case OBJ_mpd_track:
2209                         case OBJ_mpd_name:
2210                         case OBJ_mpd_file:
2211                         case OBJ_mpd_percent:
2212                         case OBJ_mpd_smart:
2213                         case OBJ_if_mpd_playing:
2214                                 free_mpd();
2215                                 break;
2216 #endif /* MPD */
2217 #ifdef MOC
2218                         case OBJ_moc_state:
2219                         case OBJ_moc_file:
2220                         case OBJ_moc_title:
2221                         case OBJ_moc_artist:
2222                         case OBJ_moc_song:
2223                         case OBJ_moc_album:
2224                         case OBJ_moc_totaltime:
2225                         case OBJ_moc_timeleft:
2226                         case OBJ_moc_curtime:
2227                         case OBJ_moc_bitrate:
2228                         case OBJ_moc_rate:
2229                                 free_moc();
2230                                 break;
2231 #endif /* MOC */
2232                         case OBJ_include:
2233                         case OBJ_blink:
2234                         case OBJ_to_bytes:
2235                                 if(obj->sub) {
2236                                         free_text_objects(obj->sub, 1);
2237                                         free(obj->sub);
2238                                 }
2239                                 break;
2240                         case OBJ_scroll:
2241                                 free(data.scroll.text);
2242                                 free_text_objects(obj->sub, 1);
2243                                 free(obj->sub);
2244                                 break;
2245                         case OBJ_combine:
2246                                 free(data.combine.left);
2247                                 free(data.combine.seperation);
2248                                 free(data.combine.right);
2249                                 free_text_objects(obj->sub, 1);
2250                                 free(obj->sub);
2251                                 break;
2252 #ifdef APCUPSD
2253                         case OBJ_apcupsd:
2254                         case OBJ_apcupsd_name:
2255                         case OBJ_apcupsd_model:
2256                         case OBJ_apcupsd_upsmode:
2257                         case OBJ_apcupsd_cable:
2258                         case OBJ_apcupsd_status:
2259                         case OBJ_apcupsd_linev:
2260                         case OBJ_apcupsd_load:
2261                         case OBJ_apcupsd_loadbar:
2262 #ifdef X11
2263                         case OBJ_apcupsd_loadgraph:
2264                         case OBJ_apcupsd_loadgauge:
2265 #endif /* X11 */
2266                         case OBJ_apcupsd_charge:
2267                         case OBJ_apcupsd_timeleft:
2268                         case OBJ_apcupsd_temp:
2269                         case OBJ_apcupsd_lastxfer:
2270                                 break;
2271 #endif /* APCUPSD */
2272 #ifdef X11
2273                         case OBJ_desktop:
2274                         case OBJ_desktop_number:
2275                         case OBJ_desktop_name:
2276                                 if(info.x11.desktop.name && !internal) {
2277                                   free(info.x11.desktop.name);
2278                                   info.x11.desktop.name = NULL;
2279                                 }
2280                                 if(info.x11.desktop.all_names && !internal) {
2281                                   free(info.x11.desktop.all_names);
2282                                   info.x11.desktop.all_names = NULL;
2283                                 }
2284                                 break;
2285 #endif /* X11 */
2286                 }
2287                 free(obj);
2288         }
2289 #undef data
2290 }
2291