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