1 /*
2 *
3 * Conky, a system monitor, based on torsmo
4 *
5 * Any original torsmo code is licensed under the BSD license
6 *
7 * All code written since the fork of torsmo is licensed under the GPL
8 *
9 * Please see COPYING for details
10 *
11 * Copyright (c) 2004, Hannu Saransaari and Lauri Hakkarainen
12 * Copyright (c) 2005-2021 Brenden Matthews, Philip Kovacs, et. al.
13 * (see AUTHORS)
14 * All rights reserved.
15 *
16 * This program is free software: you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License as published by
18 * the Free Software Foundation, either version 3 of the License, or
19 * (at your option) any later version.
20 *
21 * This program is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
25 * You should have received a copy of the GNU General Public License
26 * along with this program. If not, see <http://www.gnu.org/licenses/>.
27 *
28 */
29
30 /* local headers */
31 #include "core.h"
32 #include "algebra.h"
33 #include "bsdapm.h"
34 #include "build.h"
35 #include "colours.h"
36 #include "combine.h"
37 #include "diskio.h"
38 #include "entropy.h"
39 #include "exec.h"
40 #include "i8k.h"
41 #include "misc.h"
42 #include "text_object.h"
43 #ifdef BUILD_IMLIB2
44 #include "imlib2.h"
45 #endif /* BUILD_IMLIB2 */
46 #include "proc.h"
47 #ifdef BUILD_MYSQL
48 #include "mysql.h"
49 #endif /* BUILD_MYSQL */
50 #ifdef BUILD_ICAL
51 #include "ical.h"
52 #endif /* BUILD_ICAL */
53 #ifdef BUILD_IRC
54 #include "irc.h"
55 #endif /* BUILD_IRC */
56 #ifdef BUILD_X11
57 #include "fonts.h"
58 #endif /* BUILD_X11 */
59 #include "fs.h"
60 #ifdef BUILD_IBM
61 #include "ibm.h"
62 #include "smapi.h"
63 #endif /* BUILD_IBM */
64 #ifdef BUILD_ICONV
65 #include "iconv_tools.h"
66 #endif /* BUILD_ICONV */
67 #include "llua.h"
68 #include "logging.h"
69 #include "mail.h"
70 #include "mboxscan.h"
71 #include "mixer.h"
72 #include "nc.h"
73 #include "net_stat.h"
74 #ifdef BUILD_NVIDIA
75 #include "nvidia.h"
76 #endif /* BUILD_NVIDIA */
77 #include <inttypes.h>
78 #include "cpu.h"
79 #include "read_tcpip.h"
80 #include "scroll.h"
81 #include "specials.h"
82 #include "tailhead.h"
83 #include "temphelper.h"
84 #include "template.h"
85 #include "timeinfo.h"
86 #include "top.h"
87 #include "user.h"
88 #include "users.h"
89 #ifdef BUILD_CURL
90 #include "ccurl_thread.h"
91 #endif /* BUILD_CURL */
92 #ifdef BUILD_WEATHER_METAR
93 #include "weather.h"
94 #endif /* BUILD_WEATHER_METAR */
95 #ifdef BUILD_RSS
96 #include "rss.h"
97 #endif /* BUILD_RSS */
98 #ifdef BUILD_AUDACIOUS
99 #include "audacious.h"
100 #endif /* BUILD_AUDACIOUS */
101 #ifdef BUILD_CMUS
102 #include "cmus.h"
103 #endif /* BUILD_CMUS */
104 #ifdef BUILD_JOURNAL
105 #include "journal.h"
106 #endif /* BUILD_JOURNAL */
107 #ifdef BUILD_PULSEAUDIO
108 #include "pulseaudio.h"
109 #endif /* BUILD_PULSEAUDIO */
110 #ifdef BUILD_INTEL_BACKLIGHT
111 #include "intel_backlight.h"
112 #endif /* BUILD_INTEL_BACKLIGHT */
113
114 /* check for OS and include appropriate headers */
115 #if defined(__linux__)
116 #include "linux.h"
117 #elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
118 #include "freebsd.h"
119 #elif defined(__DragonFly__)
120 #include "dragonfly.h"
121 #elif defined(__OpenBSD__)
122 #include "openbsd.h"
123 #elif defined(__APPLE__) && defined(__MACH__)
124 #include "darwin.h"
125 #endif
126
127 #define STRNDUP_ARG strndup(arg ? arg : "", text_buffer_size.get(*state))
128
129 #include <cctype>
130 #include <cstring>
131
132 /* strip a leading /dev/ if any, following symlinks first
133 *
134 * BEWARE: this function returns a pointer to static content
135 * which gets overwritten in consecutive calls. I.e.:
136 * this function is NOT reentrant.
137 */
dev_name(const char * path)138 const char *dev_name(const char *path) {
139 static char buf[PATH_MAX];
140
141 if (path == nullptr) { return nullptr; }
142
143 #define DEV_NAME(x) \
144 ((x) != nullptr && strlen(x) > 5 && strncmp(x, "/dev/", 5) == 0 ? (x) + 5 \
145 : (x))
146 if (realpath(path, buf) == nullptr) { return DEV_NAME(path); }
147 return DEV_NAME(buf);
148 #undef DEV_NAME
149 }
150
new_text_object_internal()151 static struct text_object *new_text_object_internal() {
152 auto *obj = static_cast<text_object *>(malloc(sizeof(struct text_object)));
153 memset(obj, 0, sizeof(struct text_object));
154 return obj;
155 }
156
create_plain_text(const char * s)157 static struct text_object *create_plain_text(const char *s) {
158 struct text_object *obj;
159
160 if (s == nullptr || *s == '\0') { return nullptr; }
161
162 obj = new_text_object_internal();
163
164 obj_be_plain_text(obj, s);
165 return obj;
166 }
167
168 #ifdef BUILD_CURL
stock_parse_arg(struct text_object * obj,const char * arg)169 void stock_parse_arg(struct text_object *obj, const char *arg) {
170 char stock[8];
171 char data[16];
172
173 obj->data.s = nullptr;
174 if (sscanf(arg, "%7s %15s", stock, data) != 2) {
175 NORM_ERR("wrong number of arguments for $stock");
176 return;
177 }
178 if (!strcasecmp("ask", data)) {
179 strncpy(data, "a", 3);
180 } else if (!strcasecmp("adv", data)) {
181 strncpy(data, "a2", 3);
182 } else if (!strcasecmp("asksize", data)) {
183 strncpy(data, "a5", 3);
184 } else if (!strcasecmp("bid", data)) {
185 strncpy(data, "b", 3);
186 } else if (!strcasecmp("askrt", data)) {
187 strncpy(data, "b2", 3);
188 } else if (!strcasecmp("bidrt", data)) {
189 strncpy(data, "b3", 3);
190 } else if (!strcasecmp("bookvalue", data)) {
191 strncpy(data, "b4", 3);
192 } else if (!strcasecmp("bidsize", data)) {
193 strncpy(data, "b6", 3);
194 } else if (!strcasecmp("change", data)) {
195 strncpy(data, "c1", 3);
196 } else if (!strcasecmp("commission", data)) {
197 strncpy(data, "c3", 3);
198 } else if (!strcasecmp("changert", data)) {
199 strncpy(data, "c6", 3);
200 } else if (!strcasecmp("ahcrt", data)) {
201 strncpy(data, "c8", 3);
202 } else if (!strcasecmp("ds", data)) {
203 strncpy(data, "d", 3);
204 } else if (!strcasecmp("ltd", data)) {
205 strncpy(data, "d1", 3);
206 } else if (!strcasecmp("tradedate", data)) {
207 strncpy(data, "d2", 3);
208 } else if (!strcasecmp("es", data)) {
209 strncpy(data, "e", 3);
210 } else if (!strcasecmp("ei", data)) {
211 strncpy(data, "e1", 3);
212 } else if (!strcasecmp("epsecy", data)) {
213 strncpy(data, "e7", 3);
214 } else if (!strcasecmp("epseny", data)) {
215 strncpy(data, "e8", 3);
216 } else if (!strcasecmp("epsenq", data)) {
217 strncpy(data, "e9", 3);
218 } else if (!strcasecmp("floatshares", data)) {
219 strncpy(data, "f6", 3);
220 } else if (!strcasecmp("dayslow", data)) {
221 strncpy(data, "g", 3);
222 } else if (!strcasecmp("dayshigh", data)) {
223 strncpy(data, "h", 3);
224 } else if (!strcasecmp("52weeklow", data)) {
225 strncpy(data, "j", 3);
226 } else if (!strcasecmp("52weekhigh", data)) {
227 strncpy(data, "k", 3);
228 } else if (!strcasecmp("hgp", data)) {
229 strncpy(data, "g1", 3);
230 } else if (!strcasecmp("ag", data)) {
231 strncpy(data, "g3", 3);
232 } else if (!strcasecmp("hg", data)) {
233 strncpy(data, "g4", 3);
234 } else if (!strcasecmp("hgprt", data)) {
235 strncpy(data, "g5", 3);
236 } else if (!strcasecmp("hgrt", data)) {
237 strncpy(data, "g6", 3);
238 } else if (!strcasecmp("moreinfo", data)) {
239 strncpy(data, "i", 3);
240 } else if (!strcasecmp("obrt", data)) {
241 strncpy(data, "i5", 3);
242 } else if (!strcasecmp("mc", data)) {
243 strncpy(data, "j1", 3);
244 } else if (!strcasecmp("mcrt", data)) {
245 strncpy(data, "j3", 3);
246 } else if (!strcasecmp("ebitda", data)) {
247 strncpy(data, "j4", 3);
248 } else if (!strcasecmp("c52wlow", data)) {
249 strncpy(data, "j5", 3);
250 } else if (!strcasecmp("pc52wlow", data)) {
251 strncpy(data, "j6", 3);
252 } else if (!strcasecmp("cprt", data)) {
253 strncpy(data, "k2", 3);
254 } else if (!strcasecmp("lts", data)) {
255 strncpy(data, "k3", 3);
256 } else if (!strcasecmp("c52whigh", data)) {
257 strncpy(data, "k4", 3);
258 } else if (!strcasecmp("pc52whigh", data)) {
259 strncpy(data, "k5", 3);
260 } else if (!strcasecmp("ltp", data)) {
261 strncpy(data, "l1", 3);
262 } else if (!strcasecmp("hl", data)) {
263 strncpy(data, "l2", 3);
264 } else if (!strcasecmp("ll", data)) {
265 strncpy(data, "l3", 3);
266 } else if (!strcasecmp("dr", data)) {
267 strncpy(data, "m", 3);
268 } else if (!strcasecmp("drrt", data)) {
269 strncpy(data, "m2", 3);
270 } else if (!strcasecmp("50ma", data)) {
271 strncpy(data, "m3", 3);
272 } else if (!strcasecmp("200ma", data)) {
273 strncpy(data, "m4", 3);
274 } else if (!strcasecmp("c200ma", data)) {
275 strncpy(data, "m5", 3);
276 } else if (!strcasecmp("pc200ma", data)) {
277 strncpy(data, "m6", 3);
278 } else if (!strcasecmp("c50ma", data)) {
279 strncpy(data, "m7", 3);
280 } else if (!strcasecmp("pc50ma", data)) {
281 strncpy(data, "m8", 3);
282 } else if (!strcasecmp("name", data)) {
283 strncpy(data, "n", 3);
284 } else if (!strcasecmp("notes", data)) {
285 strncpy(data, "n4", 3);
286 } else if (!strcasecmp("open", data)) {
287 strncpy(data, "o", 3);
288 } else if (!strcasecmp("pc", data)) {
289 strncpy(data, "p", 3);
290 } else if (!strcasecmp("pricepaid", data)) {
291 strncpy(data, "p1", 3);
292 } else if (!strcasecmp("cip", data)) {
293 strncpy(data, "p2", 3);
294 } else if (!strcasecmp("ps", data)) {
295 strncpy(data, "p5", 3);
296 } else if (!strcasecmp("pb", data)) {
297 strncpy(data, "p6", 3);
298 } else if (!strcasecmp("edv", data)) {
299 strncpy(data, "q", 3);
300 } else if (!strcasecmp("per", data)) {
301 strncpy(data, "r", 3);
302 } else if (!strcasecmp("dpd", data)) {
303 strncpy(data, "r1", 3);
304 } else if (!strcasecmp("perrt", data)) {
305 strncpy(data, "r2", 3);
306 } else if (!strcasecmp("pegr", data)) {
307 strncpy(data, "r5", 3);
308 } else if (!strcasecmp("pepsecy", data)) {
309 strncpy(data, "r6", 3);
310 } else if (!strcasecmp("pepseny", data)) {
311 strncpy(data, "r7", 3);
312 } else if (!strcasecmp("symbol", data)) {
313 strncpy(data, "s", 3);
314 } else if (!strcasecmp("sharesowned", data)) {
315 strncpy(data, "s1", 3);
316 } else if (!strcasecmp("shortratio", data)) {
317 strncpy(data, "s7", 3);
318 } else if (!strcasecmp("ltt", data)) {
319 strncpy(data, "t1", 3);
320 } else if (!strcasecmp("tradelinks", data)) {
321 strncpy(data, "t6", 3);
322 } else if (!strcasecmp("tt", data)) {
323 strncpy(data, "t7", 3);
324 } else if (!strcasecmp("1ytp", data)) {
325 strncpy(data, "t8", 3);
326 } else if (!strcasecmp("volume", data)) {
327 strncpy(data, "v", 3);
328 } else if (!strcasecmp("hv", data)) {
329 strncpy(data, "v1", 3);
330 } else if (!strcasecmp("hvrt", data)) {
331 strncpy(data, "v7", 3);
332 } else if (!strcasecmp("52weekrange", data)) {
333 strncpy(data, "w", 3);
334 } else if (!strcasecmp("dvc", data)) {
335 strncpy(data, "w1", 3);
336 } else if (!strcasecmp("dvcrt", data)) {
337 strncpy(data, "w4", 3);
338 } else if (!strcasecmp("se", data)) {
339 strncpy(data, "x", 3);
340 } else if (!strcasecmp("dy", data)) {
341 strncpy(data, "y", 3);
342 } else {
343 NORM_ERR(
344 "\"%s\" is not supported by $stock. Supported: 1ytp, 200ma, 50ma, "
345 "52weeklow, 52weekhigh, 52weekrange, adv, ag, ahcrt, ask, askrt, "
346 "asksize, bid, bidrt, bidsize, bookvalue, c200ma, c50ma, c52whigh, "
347 "c52wlow, change, changert, cip, commission, cprt, dayshigh, dayslow, "
348 "dpd, dr, drrt, ds, dvc, dvcrt, dy, ebitda, edv, ei, epsecy, epsenq, "
349 "epseny, es, floatshares, hg, hgp, hgprt, hl, hv, hvrt, ll, ltd, ltp, "
350 "lts, ltt, mc, mcrt, moreinfo, name, notes, obrt, open, pb, pc, "
351 "pc200ma, pc50ma, pc52whigh, pc52wlow, pegr, pepsecy, pepseny, per, "
352 "perrt, pricepaid, ps, se, sharesowned, shortratio, symbol, tradedate, "
353 "tradelinks, tt, volume",
354 data);
355 return;
356 }
357 #define MAX_FINYAH_URL_LENGTH 64
358 obj->data.s = static_cast<char *>(malloc(MAX_FINYAH_URL_LENGTH));
359 snprintf(obj->data.s, MAX_FINYAH_URL_LENGTH,
360 "http://download.finance.yahoo.com/d/quotes.csv?s=%s&f=%s", stock,
361 data);
362 }
363 #endif /* BUILD_CURL */
364
create_cb_handle(int (* fn)())365 legacy_cb_handle *create_cb_handle(int (*fn)()) {
366 if (fn != nullptr) {
367 return new legacy_cb_handle(conky::register_cb<legacy_cb>(1, fn));
368 }
369 { return nullptr; }
370 }
371
372 /* construct_text_object() creates a new text_object */
construct_text_object(char * s,const char * arg,long line,void ** ifblock_opaque,void * free_at_crash)373 struct text_object *construct_text_object(char *s, const char *arg, long line,
374 void **ifblock_opaque,
375 void *free_at_crash) {
376 // struct text_object *obj = new_text_object();
377 struct text_object *obj = new_text_object_internal();
378
379 obj->line = line;
380
381 /* helper defines for internal use only */
382 #define __OBJ_HEAD(a, n) \
383 if (!strcmp(s, #a)) { \
384 obj->cb_handle = create_cb_handle(n);
385 #define __OBJ_IF obj_be_ifblock_if(ifblock_opaque, obj)
386 #define __OBJ_ARG(...) \
387 if (!arg) { \
388 free(s); \
389 CRIT_ERR(obj, free_at_crash, __VA_ARGS__); \
390 }
391
392 /* defines to be used below */
393 #define OBJ(a, n) __OBJ_HEAD(a, n) {
394 #define OBJ_ARG(a, n, ...) __OBJ_HEAD(a, n) __OBJ_ARG(__VA_ARGS__) {
395 #define OBJ_IF(a, n) \
396 __OBJ_HEAD(a, n) __OBJ_IF; \
397 {
398 #define OBJ_IF_ARG(a, n, ...) \
399 __OBJ_HEAD(a, n) __OBJ_ARG(__VA_ARGS__) __OBJ_IF; \
400 {
401 #define END \
402 } \
403 } \
404 else
405
406 #ifdef BUILD_X11
407 if (s[0] == '#') {
408 obj->data.l = get_x11_color(s);
409 obj->callbacks.print = &new_fg;
410 } else
411 #endif /* BUILD_X11 */
412 #ifndef __OpenBSD__
413 OBJ(acpitemp, nullptr)
414 obj->data.i = open_acpi_temperature(arg);
415 obj->callbacks.print = &print_acpitemp;
416 obj->callbacks.free = &free_acpitemp;
417 END OBJ(acpiacadapter, nullptr) if (arg != nullptr) {
418 #ifdef __linux__
419 if (strpbrk(arg, "/.") != nullptr) {
420 /*
421 * a bit of paranoia. screen out funky paths
422 * i hope no device will have a '.' in its name
423 */
424 NORM_ERR("acpiacadapter: arg must not contain '/' or '.'");
425 } else
426 obj->data.opaque = strdup(arg);
427 #else
428 NORM_ERR("acpiacadapter: arg is only used on linux");
429 #endif
430 }
431 obj->callbacks.print = &print_acpiacadapter;
432 obj->callbacks.free = &gen_free_opaque;
433 #endif /* !__OpenBSD__ */
434 END OBJ(freq, nullptr) get_cpu_count();
435 if ((arg == nullptr) || (isdigit(static_cast<unsigned char>(arg[0])) == 0) ||
436 strlen(arg) >= 3 || atoi(&arg[0]) == 0 ||
437 static_cast<unsigned int>(atoi(&arg[0])) > info.cpu_count) {
438 obj->data.i = 1;
439 /* NORM_ERR("freq: Invalid CPU number or you don't have that many CPUs! "
440 "Displaying the clock for CPU 1."); */
441 } else {
442 obj->data.i = atoi(&arg[0]);
443 }
444 obj->callbacks.print = &print_freq;
445 END OBJ(freq_g, nullptr) get_cpu_count();
446 if ((arg == nullptr) || (isdigit(static_cast<unsigned char>(arg[0])) == 0) ||
447 strlen(arg) >= 3 || atoi(&arg[0]) == 0 ||
448 static_cast<unsigned int>(atoi(&arg[0])) > info.cpu_count) {
449 obj->data.i = 1;
450 /* NORM_ERR("freq_g: Invalid CPU number or you don't have that many "
451 "CPUs! Displaying the clock for CPU 1."); */
452 } else {
453 obj->data.i = atoi(&arg[0]);
454 }
455 obj->callbacks.print = &print_freq_g;
456 END OBJ_ARG(read_tcp, nullptr,
457 "read_tcp: Needs \"(host) port\" as argument(s)")
458 parse_read_tcpip_arg(obj, arg, free_at_crash);
459 obj->callbacks.print = &print_read_tcp;
460 obj->callbacks.free = &free_read_tcpip;
461 END OBJ_ARG(read_udp, nullptr,
462 "read_udp: Needs \"(host) port\" as argument(s)")
463 parse_read_tcpip_arg(obj, arg, free_at_crash);
464 obj->callbacks.print = &print_read_udp;
465 obj->callbacks.free = &free_read_tcpip;
466 END OBJ_ARG(tcp_ping, nullptr,
467 "tcp_ping: Needs \"host (port)\" as argument(s)")
468 parse_tcp_ping_arg(obj, arg, free_at_crash);
469 obj->callbacks.print = &print_tcp_ping;
470 obj->callbacks.free = &free_tcp_ping;
471 #if defined(__linux__)
472 END OBJ(voltage_mv, 0) get_cpu_count();
473 if (!arg || !isdigit((unsigned char)arg[0]) || strlen(arg) >= 3 ||
474 atoi(&arg[0]) == 0 || (unsigned int)atoi(&arg[0]) > info.cpu_count) {
475 obj->data.i = 1;
476 /* NORM_ERR("voltage_mv: Invalid CPU number or you don't have that many "
477 "CPUs! Displaying voltage for CPU 1."); */
478 } else {
479 obj->data.i = atoi(&arg[0]);
480 }
481 obj->callbacks.print = &print_voltage_mv;
482 END OBJ(voltage_v, 0) get_cpu_count();
483 if (!arg || !isdigit((unsigned char)arg[0]) || strlen(arg) >= 3 ||
484 atoi(&arg[0]) == 0 || (unsigned int)atoi(&arg[0]) > info.cpu_count) {
485 obj->data.i = 1;
486 /* NORM_ERR("voltage_v: Invalid CPU number or you don't have that many "
487 "CPUs! Displaying voltage for CPU 1."); */
488 } else {
489 obj->data.i = atoi(&arg[0]);
490 }
491 obj->callbacks.print = &print_voltage_v;
492
493 #endif /* __linux__ */
494
495 #ifdef BUILD_WLAN
496 END OBJ(wireless_essid, &update_net_stats) obj->data.opaque =
497 get_net_stat(arg, obj, free_at_crash);
498 parse_net_stat_arg(obj, arg, free_at_crash);
499 obj->callbacks.print = &print_wireless_essid;
500 END OBJ(wireless_channel, &update_net_stats)
501 parse_net_stat_arg(obj, arg, free_at_crash);
502 obj->callbacks.print = &print_wireless_channel;
503 END OBJ(wireless_freq, &update_net_stats)
504 parse_net_stat_arg(obj, arg, free_at_crash);
505 obj->callbacks.print = &print_wireless_frequency;
506 END OBJ(wireless_mode, &update_net_stats)
507 parse_net_stat_arg(obj, arg, free_at_crash);
508 obj->callbacks.print = &print_wireless_mode;
509 END OBJ(wireless_bitrate, &update_net_stats)
510 parse_net_stat_arg(obj, arg, free_at_crash);
511 obj->callbacks.print = &print_wireless_bitrate;
512 END OBJ(wireless_ap, &update_net_stats)
513 parse_net_stat_arg(obj, arg, free_at_crash);
514 obj->callbacks.print = &print_wireless_ap;
515 END OBJ(wireless_link_qual, &update_net_stats)
516 parse_net_stat_arg(obj, arg, free_at_crash);
517 obj->callbacks.print = &print_wireless_link_qual;
518 END OBJ(wireless_link_qual_max, &update_net_stats)
519 parse_net_stat_arg(obj, arg, free_at_crash);
520 obj->callbacks.print = &print_wireless_link_qual_max;
521 END OBJ(wireless_link_qual_perc, &update_net_stats)
522 parse_net_stat_arg(obj, arg, free_at_crash);
523 obj->callbacks.print = &print_wireless_link_qual_perc;
524 END OBJ(wireless_link_bar, &update_net_stats)
525 parse_net_stat_bar_arg(obj, arg, free_at_crash);
526 obj->callbacks.barval = &wireless_link_barval;
527 #endif /* BUILD_WLAN */
528
529 #ifndef __OpenBSD__
530 END OBJ(acpifan, nullptr) obj->callbacks.print = &print_acpifan;
531 END OBJ(battery, nullptr) char bat[64];
532
533 if (arg != nullptr) {
534 sscanf(arg, "%63s", bat);
535 } else {
536 strncpy(bat, "BAT0", 5);
537 }
538 obj->data.s = strndup(bat, text_buffer_size.get(*state));
539 obj->callbacks.print = &print_battery;
540 obj->callbacks.free = &gen_free_opaque;
541 END OBJ(battery_short, nullptr) char bat[64];
542
543 if (arg != nullptr) {
544 sscanf(arg, "%63s", bat);
545 } else {
546 strncpy(bat, "BAT0", 5);
547 }
548 obj->data.s = strndup(bat, text_buffer_size.get(*state));
549 obj->callbacks.print = &print_battery_short;
550 obj->callbacks.free = &gen_free_opaque;
551
552 END OBJ(battery_status, 0) obj->data.s =
553 strndup(arg ? arg : "BAT0", text_buffer_size.get(*state));
554 obj->callbacks.print = &print_battery_status;
555 obj->callbacks.free = &gen_free_opaque;
556 END OBJ(battery_time, nullptr) char bat[64];
557
558 if (arg != nullptr) {
559 sscanf(arg, "%63s", bat);
560 } else {
561 strncpy(bat, "BAT0", 5);
562 }
563 obj->data.s = strndup(bat, text_buffer_size.get(*state));
564 obj->callbacks.print = &print_battery_time;
565 obj->callbacks.free = &gen_free_opaque;
566 END OBJ(battery_percent, nullptr) char bat[64];
567
568 if (arg != nullptr) {
569 sscanf(arg, "%63s", bat);
570 } else {
571 strncpy(bat, "BAT0", 5);
572 }
573 obj->data.s = strndup(bat, text_buffer_size.get(*state));
574 obj->callbacks.percentage = &battery_percentage;
575 obj->callbacks.free = &gen_free_opaque;
576 END OBJ(battery_bar, nullptr) char bat[64];
577
578 arg = scan_bar(obj, arg, 100);
579 if ((arg != nullptr) && strlen(arg) > 0) {
580 sscanf(arg, "%63s", bat);
581 } else {
582 strncpy(bat, "BAT0", 5);
583 }
584 obj->data.s = strndup(bat, text_buffer_size.get(*state));
585 obj->callbacks.barval = &get_battery_perct_bar;
586 obj->callbacks.free = &gen_free_opaque;
587 #endif /* !__OpenBSD__ */
588
589 #if defined(__linux__)
590 END OBJ_ARG(disk_protect, 0, "disk_protect needs an argument") obj->data.s =
591 strndup(dev_name(arg), text_buffer_size.get(*state));
592 obj->callbacks.print = &print_disk_protect_queue;
593 obj->callbacks.free = &gen_free_opaque;
594 END OBJ(i8k_version, &update_i8k) obj->callbacks.print = &print_i8k_version;
595 END OBJ(i8k_bios, &update_i8k) obj->callbacks.print = &print_i8k_bios;
596 END OBJ(i8k_serial, &update_i8k) obj->callbacks.print = &print_i8k_serial;
597 END OBJ(i8k_cpu_temp, &update_i8k) obj->callbacks.print = &print_i8k_cpu_temp;
598 END OBJ(i8k_left_fan_status, &update_i8k) obj->callbacks.print =
599 &print_i8k_left_fan_status;
600 END OBJ(i8k_right_fan_status, &update_i8k) obj->callbacks.print =
601 &print_i8k_right_fan_status;
602 END OBJ(i8k_left_fan_rpm, &update_i8k) obj->callbacks.print =
603 &print_i8k_left_fan_rpm;
604 END OBJ(i8k_right_fan_rpm, &update_i8k) obj->callbacks.print =
605 &print_i8k_right_fan_rpm;
606 END OBJ(i8k_ac_status, &update_i8k) obj->callbacks.print =
607 &print_i8k_ac_status;
608 END OBJ(i8k_buttons_status, &update_i8k) obj->callbacks.print =
609 &print_i8k_buttons_status;
610 #if defined(BUILD_IBM)
611 END OBJ(ibm_fan, 0) obj->callbacks.print = &get_ibm_acpi_fan;
612 END OBJ_ARG(ibm_temps, &get_ibm_acpi_temps, "ibm_temps: needs an argument")
613 parse_ibm_temps_arg(obj, arg);
614 obj->callbacks.print = &print_ibm_temps;
615 END OBJ(ibm_volume, 0) obj->callbacks.print = &get_ibm_acpi_volume;
616 END OBJ(ibm_brightness, 0) obj->callbacks.print = &get_ibm_acpi_brightness;
617 END OBJ(ibm_thinklight, 0) obj->callbacks.print = &get_ibm_acpi_thinklight;
618 #endif
619 /* information from sony_laptop kernel module
620 * /sys/devices/platform/sony-laptop */
621 END OBJ(sony_fanspeed, 0) obj->callbacks.print = &get_sony_fanspeed;
622 END OBJ_ARG(ioscheduler, 0, "get_ioscheduler needs an argument (e.g. hda)")
623 obj->data.s = strndup(dev_name(arg), text_buffer_size.get(*state));
624 obj->callbacks.print = &print_ioscheduler;
625 obj->callbacks.free = &gen_free_opaque;
626 END OBJ(laptop_mode, 0) obj->callbacks.print = &print_laptop_mode;
627 END OBJ_ARG(
628 pb_battery, 0,
629 "pb_battery: needs one argument: status, percent or time") if (strcmp(arg,
630 "st"
631 "at"
632 "u"
633 "s") ==
634 EQUAL) {
635 obj->data.i = PB_BATT_STATUS;
636 }
637 else if (strcmp(arg, "percent") == EQUAL) {
638 obj->data.i = PB_BATT_PERCENT;
639 }
640 else if (strcmp(arg, "time") == EQUAL) {
641 obj->data.i = PB_BATT_TIME;
642 }
643 else {
644 NORM_ERR("pb_battery: illegal argument '%s', defaulting to status", arg);
645 obj->data.i = PB_BATT_STATUS;
646 }
647 obj->callbacks.print = get_powerbook_batt_info;
648 #endif /* __linux__ */
649 #if (defined(__FreeBSD__) || defined(__linux__) || defined(__DragonFly__) || \
650 (defined(__APPLE__) && defined(__MACH__)))
651 END OBJ_IF_ARG(if_up, nullptr, "if_up needs an argument")
652 parse_if_up_arg(obj, arg);
653 obj->callbacks.iftest = &interface_up;
654 obj->callbacks.free = &free_if_up;
655 #endif
656 #if defined(__OpenBSD__)
657 END OBJ_ARG(obsd_sensors_temp, 0, "obsd_sensors_temp: needs an argument")
658 parse_obsd_sensor(obj, arg);
659 obj->callbacks.print = &print_obsd_sensors_temp;
660 END OBJ_ARG(obsd_sensors_fan, 0,
661 "obsd_sensors_fan: needs 2 arguments (device and sensor number)")
662 parse_obsd_sensor(obj, arg);
663 obj->callbacks.print = &print_obsd_sensors_fan;
664 END OBJ_ARG(obsd_sensors_volt, 0,
665 "obsd_sensors_volt: needs 2 arguments (device and sensor number)")
666 parse_obsd_sensor(obj, arg);
667 obj->callbacks.print = &print_obsd_sensors_volt;
668 END OBJ(obsd_vendor, 0) obj->callbacks.print = &get_obsd_vendor;
669 END OBJ(obsd_product, 0) obj->callbacks.print = &get_obsd_product;
670 #endif /* __OpenBSD__ */
671 END OBJ(buffers, &update_meminfo) obj->data.s = STRNDUP_ARG;
672 obj->callbacks.print = &print_buffers;
673 obj->callbacks.free = &gen_free_opaque;
674 END OBJ(cached, &update_meminfo) obj->data.s = STRNDUP_ARG;
675 obj->callbacks.print = &print_cached;
676 obj->callbacks.free = &gen_free_opaque;
677 #define SCAN_CPU(__arg, __var) \
678 { \
679 int __offset = 0; \
680 if ((__arg) && sscanf(__arg, " cpu%d %n", &(__var), &__offset) > 0) \
681 (__arg) += __offset; \
682 else \
683 (__var) = 0; \
684 }
685 END OBJ(cpu, &update_cpu_usage) get_cpu_count();
686 SCAN_CPU(arg, obj->data.i);
687 obj->callbacks.percentage = &cpu_percentage;
688 obj->callbacks.free = &free_cpu;
689 DBGP2("Adding $cpu for CPU %d", obj->data.i);
690 #ifdef BUILD_X11
691 END OBJ(cpugauge, &update_cpu_usage) get_cpu_count();
692 SCAN_CPU(arg, obj->data.i);
693 scan_gauge(obj, arg, 1);
694 obj->callbacks.gaugeval = &cpu_barval;
695 obj->callbacks.free = &free_cpu;
696 DBGP2("Adding $cpugauge for CPU %d", obj->data.i);
697 #endif
698 END OBJ(cpubar, &update_cpu_usage) get_cpu_count();
699 SCAN_CPU(arg, obj->data.i);
700 scan_bar(obj, arg, 1);
701 obj->callbacks.barval = &cpu_barval;
702 obj->callbacks.free = &free_cpu;
703 DBGP2("Adding $cpubar for CPU %d", obj->data.i);
704 #ifdef BUILD_X11
705 END OBJ(cpugraph, &update_cpu_usage) get_cpu_count();
706 char *buf = nullptr;
707 SCAN_CPU(arg, obj->data.i);
708 buf = scan_graph(obj, arg, 1);
709 DBGP2("Adding $cpugraph for CPU %d", obj->data.i);
710 free_and_zero(buf);
711 obj->callbacks.graphval = &cpu_barval;
712 obj->callbacks.free = &free_cpu;
713 END OBJ(loadgraph, &update_load_average) scan_loadgraph_arg(obj, arg);
714 obj->callbacks.graphval = &loadgraphval;
715 #endif /* BUILD_X11 */
716 END OBJ(diskio, &update_diskio) parse_diskio_arg(obj, arg);
717 obj->callbacks.print = &print_diskio;
718 END OBJ(diskio_read, &update_diskio) parse_diskio_arg(obj, arg);
719 obj->callbacks.print = &print_diskio_read;
720 END OBJ(diskio_write, &update_diskio) parse_diskio_arg(obj, arg);
721 obj->callbacks.print = &print_diskio_write;
722 #ifdef BUILD_X11
723 END OBJ(diskiograph, &update_diskio) parse_diskiograph_arg(obj, arg);
724 obj->callbacks.graphval = &diskiographval;
725 END OBJ(diskiograph_read, &update_diskio) parse_diskiograph_arg(obj, arg);
726 obj->callbacks.graphval = &diskiographval_read;
727 END OBJ(diskiograph_write, &update_diskio) parse_diskiograph_arg(obj, arg);
728 obj->callbacks.graphval = &diskiographval_write;
729 #endif /* BUILD_X11 */
730 END OBJ(color, nullptr)
731 #ifdef BUILD_X11
732 if (out_to_x.get(*state)) {
733 obj->data.l =
734 arg != nullptr ? get_x11_color(arg) : default_color.get(*state);
735 set_current_text_color(obj->data.l);
736 }
737 #endif /* BUILD_X11 */
738 #ifdef BUILD_NCURSES
739 if (out_to_ncurses.get(*state)) {
740 obj->data.l = COLOR_WHITE;
741 if (arg != nullptr) {
742 if (strcasecmp(arg, "red") == 0) {
743 obj->data.l = COLOR_RED;
744 } else if (strcasecmp(arg, "green") == 0) {
745 obj->data.l = COLOR_GREEN;
746 } else if (strcasecmp(arg, "yellow") == 0) {
747 obj->data.l = COLOR_YELLOW;
748 } else if (strcasecmp(arg, "blue") == 0) {
749 obj->data.l = COLOR_BLUE;
750 } else if (strcasecmp(arg, "magenta") == 0) {
751 obj->data.l = COLOR_MAGENTA;
752 } else if (strcasecmp(arg, "cyan") == 0) {
753 obj->data.l = COLOR_CYAN;
754 } else if (strcasecmp(arg, "black") == 0) {
755 obj->data.l = COLOR_BLACK;
756 }
757 }
758 set_current_text_color(obj->data.l);
759 init_pair(obj->data.l, obj->data.l, COLOR_BLACK);
760 }
761 #endif /* BUILD_NCURSES */
762 obj->callbacks.print = &new_fg;
763 #ifdef BUILD_X11
764 END OBJ(color0, nullptr) obj->data.l = color[0].get(*state);
765 set_current_text_color(obj->data.l);
766 obj->callbacks.print = &new_fg;
767 END OBJ(color1, nullptr) obj->data.l = color[1].get(*state);
768 set_current_text_color(obj->data.l);
769 obj->callbacks.print = &new_fg;
770 END OBJ(color2, nullptr) obj->data.l = color[2].get(*state);
771 set_current_text_color(obj->data.l);
772 obj->callbacks.print = &new_fg;
773 END OBJ(color3, nullptr) obj->data.l = color[3].get(*state);
774 set_current_text_color(obj->data.l);
775 obj->callbacks.print = &new_fg;
776 END OBJ(color4, nullptr) obj->data.l = color[4].get(*state);
777 set_current_text_color(obj->data.l);
778 obj->callbacks.print = &new_fg;
779 END OBJ(color5, nullptr) obj->data.l = color[5].get(*state);
780 set_current_text_color(obj->data.l);
781 obj->callbacks.print = &new_fg;
782 END OBJ(color6, nullptr) obj->data.l = color[6].get(*state);
783 set_current_text_color(obj->data.l);
784 obj->callbacks.print = &new_fg;
785 END OBJ(color7, nullptr) obj->data.l = color[7].get(*state);
786 set_current_text_color(obj->data.l);
787 obj->callbacks.print = &new_fg;
788 END OBJ(color8, nullptr) obj->data.l = color[8].get(*state);
789 set_current_text_color(obj->data.l);
790 obj->callbacks.print = &new_fg;
791 END OBJ(color9, nullptr) obj->data.l = color[9].get(*state);
792 set_current_text_color(obj->data.l);
793 obj->callbacks.print = &new_fg;
794 END OBJ(font, nullptr) scan_font(obj, arg);
795 obj->callbacks.print = &new_font;
796 obj->callbacks.free = &gen_free_opaque;
797 END OBJ(font0, nullptr) scan_font(obj, font_template[0].get(*state).c_str());
798 obj->callbacks.print = &new_font;
799 obj->callbacks.free = &gen_free_opaque;
800 END OBJ(font1, nullptr) scan_font(obj, font_template[1].get(*state).c_str());
801 obj->callbacks.print = &new_font;
802 obj->callbacks.free = &gen_free_opaque;
803 END OBJ(font2, nullptr) scan_font(obj, font_template[2].get(*state).c_str());
804 obj->callbacks.print = &new_font;
805 obj->callbacks.free = &gen_free_opaque;
806 END OBJ(font3, nullptr) scan_font(obj, font_template[3].get(*state).c_str());
807 obj->callbacks.print = &new_font;
808 obj->callbacks.free = &gen_free_opaque;
809 END OBJ(font4, nullptr) scan_font(obj, font_template[4].get(*state).c_str());
810 obj->callbacks.print = &new_font;
811 obj->callbacks.free = &gen_free_opaque;
812 END OBJ(font5, nullptr) scan_font(obj, font_template[5].get(*state).c_str());
813 obj->callbacks.print = &new_font;
814 obj->callbacks.free = &gen_free_opaque;
815 END OBJ(font6, nullptr) scan_font(obj, font_template[6].get(*state).c_str());
816 obj->callbacks.print = &new_font;
817 obj->callbacks.free = &gen_free_opaque;
818 END OBJ(font7, nullptr) scan_font(obj, font_template[7].get(*state).c_str());
819 obj->callbacks.print = &new_font;
820 obj->callbacks.free = &gen_free_opaque;
821 END OBJ(font8, nullptr) scan_font(obj, font_template[8].get(*state).c_str());
822 obj->callbacks.print = &new_font;
823 obj->callbacks.free = &gen_free_opaque;
824 END OBJ(font9, nullptr) scan_font(obj, font_template[9].get(*state).c_str());
825 obj->callbacks.print = &new_font;
826 obj->callbacks.free = &gen_free_opaque;
827 #endif /* BUILD_X11 */
828 END OBJ(conky_version, nullptr) obj_be_plain_text(obj, VERSION);
829 END OBJ(conky_build_date, nullptr) obj_be_plain_text(obj, BUILD_DATE);
830 END OBJ(conky_build_arch, nullptr) obj_be_plain_text(obj, BUILD_ARCH);
831 END OBJ(downspeed, &update_net_stats)
832 parse_net_stat_arg(obj, arg, free_at_crash);
833 obj->callbacks.print = &print_downspeed;
834 END OBJ(downspeedf, &update_net_stats)
835 parse_net_stat_arg(obj, arg, free_at_crash);
836 obj->callbacks.print = &print_downspeedf;
837 #ifdef BUILD_X11
838 END OBJ(downspeedgraph, &update_net_stats)
839 parse_net_stat_graph_arg(obj, arg, free_at_crash);
840 obj->callbacks.graphval = &downspeedgraphval;
841 #endif /* BUILD_X11 */
842 END OBJ(else, nullptr) obj_be_ifblock_else(ifblock_opaque, obj);
843 obj->callbacks.iftest = &gen_false_iftest;
844 END OBJ(endif, nullptr) obj_be_ifblock_endif(ifblock_opaque, obj);
845 obj->callbacks.print = &gen_print_nothing;
846 END OBJ(eval, nullptr) obj->data.s = STRNDUP_ARG;
847 obj->callbacks.print = &print_evaluate;
848 obj->callbacks.free = &gen_free_opaque;
849 #if defined(BUILD_IMLIB2) && defined(BUILD_X11)
850 END OBJ(image, nullptr) obj->data.s = STRNDUP_ARG;
851 obj->callbacks.print = &print_image_callback;
852 obj->callbacks.free = &gen_free_opaque;
853 #endif /* BUILD_IMLIB2 */
854 #ifdef BUILD_MYSQL
855 END OBJ_ARG(mysql, 0, "mysql needs a query") obj->data.s = strdup(arg);
856 obj->callbacks.print = &print_mysql;
857 #endif /* BUILD_MYSQL */
858 END OBJ_ARG(no_update, nullptr, "no_update needs arguments")
859 scan_no_update(obj, arg);
860 obj->callbacks.print = &print_no_update;
861 obj->callbacks.free = &free_no_update;
862 END OBJ(cat, 0) obj->data.s = STRNDUP_ARG;
863 obj->callbacks.print = &print_cat;
864 obj->callbacks.free = &gen_free_opaque;
865
866 #ifdef BUILD_X11
867 END OBJ(key_num_lock, 0) obj->callbacks.print = &print_key_num_lock;
868 END OBJ(key_caps_lock, 0) obj->callbacks.print = &print_key_caps_lock;
869 END OBJ(key_scroll_lock, 0) obj->callbacks.print = &print_key_scroll_lock;
870 END OBJ(keyboard_layout, 0) obj->callbacks.print = &print_keyboard_layout;
871 END OBJ(mouse_speed, 0) obj->callbacks.print = &print_mouse_speed;
872 #endif /* BUILD_X11 */
873
874 #ifdef __FreeBSD__
875 END OBJ(sysctlbyname, 0) obj->data.s = STRNDUP_ARG;
876 obj->callbacks.print = &print_sysctlbyname;
877 obj->callbacks.free = &gen_free_opaque;
878 #endif /* __FreeBSD__ */
879
880 END OBJ(password, 0) obj->data.s =
881 strndup(arg ? arg : "20", text_buffer_size.get(*state));
882 obj->callbacks.print = &print_password;
883 obj->callbacks.free = &gen_free_opaque;
884
885 #ifdef __x86_64__
886 END OBJ(freq2, 0) obj->callbacks.print = &print_freq2;
887 #endif /* __x86_64__ */
888 END OBJ(startcase, 0) obj->data.s = STRNDUP_ARG;
889 obj->callbacks.print = &print_startcase;
890 obj->callbacks.free = &gen_free_opaque;
891 // Deprecated, for compatibility purposes only
892 END OBJ(start_case, 0) obj->data.s = STRNDUP_ARG;
893 obj->callbacks.print = &print_startcase;
894 obj->callbacks.free = &gen_free_opaque;
895 END OBJ(lowercase, 0) obj->data.s = STRNDUP_ARG;
896 obj->callbacks.print = &print_lowercase;
897 obj->callbacks.free = &gen_free_opaque;
898 END OBJ(uppercase, 0) obj->data.s = STRNDUP_ARG;
899 obj->callbacks.print = &print_uppercase;
900 obj->callbacks.free = &gen_free_opaque;
901 END OBJ(rstrip, 0) obj->data.s = STRNDUP_ARG;
902 obj->callbacks.print = &strip_trailing_whitespace;
903 obj->callbacks.free = &gen_free_opaque;
904 END OBJ(catp, 0) obj->data.s = STRNDUP_ARG;
905 obj->callbacks.print = &print_catp;
906 obj->callbacks.free = &gen_free_opaque;
907 END OBJ_ARG(exec, nullptr, "exec needs arguments: <command>")
908 scan_exec_arg(obj, arg, EF_EXEC);
909 obj->parse = false;
910 obj->thread = false;
911 register_exec(obj);
912 obj->callbacks.print = &print_exec;
913 obj->callbacks.free = &free_exec;
914 END OBJ_ARG(execi, nullptr, "execi needs arguments: <interval> <command>")
915 scan_exec_arg(obj, arg, EF_EXECI);
916 obj->parse = false;
917 obj->thread = false;
918 register_execi(obj);
919 obj->callbacks.print = &print_exec;
920 obj->callbacks.free = &free_execi;
921 END OBJ_ARG(execp, nullptr, "execp needs arguments: <command>")
922 scan_exec_arg(obj, arg, EF_EXEC);
923 obj->parse = true;
924 obj->thread = false;
925 register_exec(obj);
926 obj->callbacks.print = &print_exec;
927 obj->callbacks.free = &free_exec;
928 END OBJ_ARG(execpi, nullptr, "execpi needs arguments: <interval> <command>")
929 scan_exec_arg(obj, arg, EF_EXECI);
930 obj->parse = true;
931 obj->thread = false;
932 register_execi(obj);
933 obj->callbacks.print = &print_exec;
934 obj->callbacks.free = &free_execi;
935 END OBJ_ARG(execbar, nullptr,
936 "execbar needs arguments: [height],[width] <command>")
937 scan_exec_arg(obj, arg, EF_EXEC | EF_BAR);
938 register_exec(obj);
939 obj->callbacks.barval = &execbarval;
940 obj->callbacks.free = &free_exec;
941 END OBJ_ARG(execibar, nullptr,
942 "execibar needs arguments: <interval> [height],[width] <command>")
943 scan_exec_arg(obj, arg, EF_EXECI | EF_BAR);
944 register_execi(obj);
945 obj->callbacks.barval = &execbarval;
946 obj->callbacks.free = &free_execi;
947 #ifdef BUILD_X11
948 END OBJ_ARG(execgauge, nullptr,
949 "execgauge needs arguments: [height],[width] <command>")
950 scan_exec_arg(obj, arg, EF_EXEC | EF_GAUGE);
951 register_exec(obj);
952 obj->callbacks.gaugeval = &execbarval;
953 obj->callbacks.free = &free_exec;
954 END OBJ_ARG(
955 execigauge, nullptr,
956 "execigauge needs arguments: <interval> [height],[width] <command>")
957 scan_exec_arg(obj, arg, EF_EXECI | EF_GAUGE);
958 register_execi(obj);
959 obj->callbacks.gaugeval = &execbarval;
960 obj->callbacks.free = &free_execi;
961 END OBJ_ARG(execgraph, nullptr,
962 "execgraph needs arguments: <command> [height],[width] [color1] "
963 "[color2] [scale] [-t|-l]")
964 scan_exec_arg(obj, arg, EF_EXEC | EF_GRAPH);
965 register_exec(obj);
966 obj->callbacks.graphval = &execbarval;
967 obj->callbacks.free = &free_exec;
968 END OBJ_ARG(execigraph, nullptr,
969 "execigraph needs arguments: <interval> <command> "
970 "[height],[width] [color1] [color2] [scale] [-t|-l]")
971 scan_exec_arg(obj, arg, EF_EXECI | EF_GRAPH);
972 register_execi(obj);
973 obj->callbacks.graphval = &execbarval;
974 obj->callbacks.free = &free_execi;
975 #endif /* BUILD_X11 */
976 END OBJ_ARG(texeci, nullptr, "texeci needs arguments: <interval> <command>")
977 scan_exec_arg(obj, arg, EF_EXECI);
978 obj->parse = false;
979 obj->thread = true;
980 register_execi(obj);
981 obj->callbacks.print = &print_exec;
982 obj->callbacks.free = &free_execi;
983 END OBJ_ARG(texecpi, nullptr, "texecpi needs arguments: <interval> <command>")
984 scan_exec_arg(obj, arg, EF_EXECI);
985 obj->parse = true;
986 obj->thread = true;
987 register_execi(obj);
988 obj->callbacks.print = &print_exec;
989 obj->callbacks.free = &free_execi;
990 END OBJ(fs_bar, &update_fs_stats) init_fs_bar(obj, arg);
991 obj->callbacks.barval = &fs_barval;
992 END OBJ(fs_bar_free, &update_fs_stats) init_fs_bar(obj, arg);
993 obj->callbacks.barval = &fs_free_barval;
994 END OBJ(fs_free, &update_fs_stats) init_fs(obj, arg);
995 obj->callbacks.print = &print_fs_free;
996 END OBJ(fs_used_perc, &update_fs_stats) init_fs(obj, arg);
997 obj->callbacks.percentage = &fs_used_percentage;
998 END OBJ(fs_free_perc, &update_fs_stats) init_fs(obj, arg);
999 obj->callbacks.percentage = &fs_free_percentage;
1000 END OBJ(fs_size, &update_fs_stats) init_fs(obj, arg);
1001 obj->callbacks.print = &print_fs_size;
1002 END OBJ(fs_type, &update_fs_stats) init_fs(obj, arg);
1003 obj->callbacks.print = &print_fs_type;
1004 END OBJ(fs_used, &update_fs_stats) init_fs(obj, arg);
1005 obj->callbacks.print = &print_fs_used;
1006 #ifdef BUILD_X11
1007 END OBJ(hr, nullptr) obj->data.l = arg != nullptr ? atoi(arg) : 1;
1008 obj->callbacks.print = &new_hr;
1009 #endif /* BUILD_X11 */
1010 END OBJ(nameserver, &update_dns_data) parse_nameserver_arg(obj, arg);
1011 obj->callbacks.print = &print_nameserver;
1012 obj->callbacks.free = &free_dns_data;
1013 END OBJ(offset, nullptr) obj->data.l = arg != nullptr ? atoi(arg) : 1;
1014 obj->callbacks.print = &new_offset;
1015 END OBJ(voffset, nullptr) obj->data.l = arg != nullptr ? atoi(arg) : 1;
1016 obj->callbacks.print = &new_voffset;
1017 END OBJ(save_coordinates, nullptr) obj->data.l =
1018 arg != nullptr ? atoi(arg) : 0;
1019 obj->callbacks.print = &new_save_coordinates;
1020 END OBJ_ARG(goto, nullptr, "goto needs arguments") obj->data.l = atoi(arg);
1021 obj->callbacks.print = &new_goto;
1022 #ifdef BUILD_X11
1023 END OBJ(tab, nullptr) scan_tab(obj, arg);
1024 obj->callbacks.print = &new_tab;
1025 #endif /* BUILD_X11 */
1026 #ifdef __linux__
1027 END OBJ_ARG(i2c, 0, "i2c needs arguments") parse_i2c_sensor(obj, arg);
1028 obj->callbacks.print = &print_sysfs_sensor;
1029 obj->callbacks.free = &free_sysfs_sensor;
1030 END OBJ_ARG(platform, 0, "platform needs arguments")
1031 parse_platform_sensor(obj, arg);
1032 obj->callbacks.print = &print_sysfs_sensor;
1033 obj->callbacks.free = &free_sysfs_sensor;
1034 END OBJ_ARG(hwmon, 0, "hwmon needs argumanets") parse_hwmon_sensor(obj, arg);
1035 obj->callbacks.print = &print_sysfs_sensor;
1036 obj->callbacks.free = &free_sysfs_sensor;
1037 #endif /* __linux__ */
1038 END
1039 /* we have four different types of top (top, top_mem, top_time and
1040 * top_io). To avoid having almost-same code four times, we have this
1041 * special handler. */
1042 /* XXX: maybe fiddle them apart later, as print_top() does
1043 * nothing else than just that, using an ugly switch(). */
1044 if (strncmp(s, "top", 3) == EQUAL) {
1045 if (parse_top_args(s, arg, obj) != 0) {
1046 #ifdef __linux__
1047 determine_longstat_file();
1048 #endif
1049 obj->cb_handle = create_cb_handle(update_top);
1050 } else {
1051 free(obj);
1052 return nullptr;
1053 }
1054 }
1055 else OBJ(addr, &update_net_stats) parse_net_stat_arg(obj, arg, free_at_crash);
1056 obj->callbacks.print = &print_addr;
1057 END
1058 #ifdef __linux__
1059 OBJ(addrs, &update_net_stats) parse_net_stat_arg(obj, arg, free_at_crash);
1060 obj->callbacks.print = &print_addrs;
1061 #ifdef BUILD_IPV6
1062 END OBJ(v6addrs, &update_net_stats)
1063 parse_net_stat_arg(obj, arg, free_at_crash);
1064 obj->callbacks.print = &print_v6addrs;
1065 #endif /* BUILD_IPV6 */
1066 END
1067 #endif /* __linux__ */
1068 OBJ_ARG(tail, nullptr, "tail needs arguments")
1069 init_tailhead("tail", arg, obj, free_at_crash);
1070 obj->callbacks.print = &print_tail;
1071 obj->callbacks.free = &free_tailhead;
1072 END OBJ_ARG(head, nullptr, "head needs arguments")
1073 init_tailhead("head", arg, obj, free_at_crash);
1074 obj->callbacks.print = &print_head;
1075 obj->callbacks.free = &free_tailhead;
1076 END OBJ_ARG(lines, nullptr, "lines needs an argument") obj->data.s =
1077 STRNDUP_ARG;
1078 obj->callbacks.print = &print_lines;
1079 obj->callbacks.free = &gen_free_opaque;
1080 END OBJ_ARG(words, nullptr, "words needs a argument") obj->data.s =
1081 STRNDUP_ARG;
1082 obj->callbacks.print = &print_words;
1083 obj->callbacks.free = &gen_free_opaque;
1084 END OBJ(loadavg, &update_load_average) scan_loadavg_arg(obj, arg);
1085 obj->callbacks.print = &print_loadavg;
1086 END OBJ_IF_ARG(if_empty, nullptr, "if_empty needs an argument") obj->sub =
1087 static_cast<text_object *>(malloc(sizeof(struct text_object)));
1088 extract_variable_text_internal(obj->sub, arg);
1089 obj->callbacks.iftest = &if_empty_iftest;
1090 END OBJ_IF_ARG(if_match, nullptr, "if_match needs arguments") obj->sub =
1091 static_cast<text_object *>(malloc(sizeof(struct text_object)));
1092 extract_variable_text_internal(obj->sub, arg);
1093 obj->callbacks.iftest = &check_if_match;
1094 END OBJ_IF_ARG(if_existing, nullptr, "if_existing needs an argument or two")
1095 obj->data.s = STRNDUP_ARG;
1096 obj->callbacks.iftest = &if_existing_iftest;
1097 obj->callbacks.free = &gen_free_opaque;
1098 #if defined(__linux__) || defined(__FreeBSD__)
1099 END OBJ_IF_ARG(if_mounted, 0, "if_mounted needs an argument") obj->data.s =
1100 STRNDUP_ARG;
1101 obj->callbacks.iftest = &check_mount;
1102 obj->callbacks.free = &gen_free_opaque;
1103 END OBJ_IF_ARG(if_running, &update_top, "if_running needs an argument")
1104 top_running = 1;
1105 obj->data.s = STRNDUP_ARG;
1106 obj->callbacks.iftest = &if_running_iftest;
1107 obj->callbacks.free = &gen_free_opaque;
1108 #elif defined(__APPLE__) && defined(__MACH__)
1109 END OBJ_IF_ARG(if_mounted, nullptr, "if_mounted needs an argument")
1110 obj->data.s = STRNDUP_ARG;
1111 obj->callbacks.iftest = &check_mount;
1112 obj->callbacks.free = &gen_free_opaque;
1113
1114 /* System Integrity Protection */
1115 END OBJ(sip_status, &get_sip_status) obj->data.s = STRNDUP_ARG;
1116 obj->callbacks.print = &print_sip_status;
1117 obj->callbacks.free = &gen_free_opaque;
1118 #else
1119 END OBJ_IF_ARG(if_running, 0, "if_running needs an argument")
1120
1121 char buf[DEFAULT_TEXT_BUFFER_SIZE];
1122
1123 snprintf(buf, DEFAULT_TEXT_BUFFER_SIZE, "pidof %s >/dev/null", arg);
1124 obj->data.s = STRNDUP_ARG;
1125 /* XXX: maybe use a different callback here */
1126 obj->callbacks.iftest = &if_running_iftest;
1127 #endif
1128 END OBJ(kernel, nullptr) obj->callbacks.print = &print_kernel;
1129 END OBJ(machine, nullptr) obj->callbacks.print = &print_machine;
1130 #if defined(__DragonFly__)
1131 END OBJ(version, 0) obj->callbacks.print = &print_version;
1132 #endif
1133 END OBJ(mails, nullptr) parse_local_mail_args(obj, arg);
1134 obj->callbacks.print = &print_mails;
1135 obj->callbacks.free = &free_local_mails;
1136 END OBJ(new_mails, nullptr) parse_local_mail_args(obj, arg);
1137 obj->callbacks.print = &print_new_mails;
1138 obj->callbacks.free = &free_local_mails;
1139 END OBJ(seen_mails, nullptr) parse_local_mail_args(obj, arg);
1140 obj->callbacks.print = &print_seen_mails;
1141 obj->callbacks.free = &free_local_mails;
1142 END OBJ(unseen_mails, nullptr) parse_local_mail_args(obj, arg);
1143 obj->callbacks.print = &print_unseen_mails;
1144 obj->callbacks.free = &free_local_mails;
1145 END OBJ(flagged_mails, nullptr) parse_local_mail_args(obj, arg);
1146 obj->callbacks.print = &print_flagged_mails;
1147 obj->callbacks.free = &free_local_mails;
1148 END OBJ(unflagged_mails, nullptr) parse_local_mail_args(obj, arg);
1149 obj->callbacks.print = &print_unflagged_mails;
1150 obj->callbacks.free = &free_local_mails;
1151 END OBJ(forwarded_mails, nullptr) parse_local_mail_args(obj, arg);
1152 obj->callbacks.print = &print_forwarded_mails;
1153 obj->callbacks.free = &free_local_mails;
1154 END OBJ(unforwarded_mails, nullptr) parse_local_mail_args(obj, arg);
1155 obj->callbacks.print = &print_unforwarded_mails;
1156 obj->callbacks.free = &free_local_mails;
1157 END OBJ(replied_mails, nullptr) parse_local_mail_args(obj, arg);
1158 obj->callbacks.print = &print_replied_mails;
1159 obj->callbacks.free = &free_local_mails;
1160 END OBJ(unreplied_mails, nullptr) parse_local_mail_args(obj, arg);
1161 obj->callbacks.print = &print_unreplied_mails;
1162 obj->callbacks.free = &free_local_mails;
1163 END OBJ(draft_mails, nullptr) parse_local_mail_args(obj, arg);
1164 obj->callbacks.print = &print_draft_mails;
1165 obj->callbacks.free = &free_local_mails;
1166 END OBJ(trashed_mails, nullptr) parse_local_mail_args(obj, arg);
1167 obj->callbacks.print = &print_trashed_mails;
1168 obj->callbacks.free = &free_local_mails;
1169 END OBJ(mboxscan, nullptr) parse_mboxscan_arg(obj, arg);
1170 obj->callbacks.print = &print_mboxscan;
1171 obj->callbacks.free = &free_mboxscan;
1172 END OBJ(mem, &update_meminfo) obj->data.s = STRNDUP_ARG;
1173 obj->callbacks.print = &print_mem;
1174 obj->callbacks.free = &gen_free_opaque;
1175 END OBJ(legacymem, &update_meminfo) obj->data.s = STRNDUP_ARG;
1176 obj->callbacks.print = &print_legacymem;
1177 obj->callbacks.free = &gen_free_opaque;
1178 END OBJ(memwithbuffers, &update_meminfo) obj->data.s = STRNDUP_ARG;
1179 obj->callbacks.print = &print_memwithbuffers;
1180 obj->callbacks.free = &gen_free_opaque;
1181 END OBJ(memeasyfree, &update_meminfo) obj->data.s = STRNDUP_ARG;
1182 obj->callbacks.print = &print_memeasyfree;
1183 obj->callbacks.free = &gen_free_opaque;
1184 END OBJ(memfree, &update_meminfo) obj->data.s = STRNDUP_ARG;
1185 obj->callbacks.print = &print_memfree;
1186 obj->callbacks.free = &gen_free_opaque;
1187 END OBJ(memmax, &update_meminfo) obj->data.s = STRNDUP_ARG;
1188 obj->callbacks.print = &print_memmax;
1189 obj->callbacks.free = &gen_free_opaque;
1190 END OBJ(memperc, &update_meminfo) obj->callbacks.percentage = &mem_percentage;
1191 #ifdef __linux__
1192 END OBJ(memdirty, &update_meminfo) obj->data.s = STRNDUP_ARG;
1193 obj->callbacks.print = &print_memdirty;
1194 obj->callbacks.free = &gen_free_opaque;
1195 #endif /* __linux__ */
1196 #ifdef BUILD_X11
1197 END OBJ(memgauge, &update_meminfo) scan_gauge(obj, arg, 1);
1198 obj->callbacks.gaugeval = &mem_barval;
1199 #endif /* BUILD_X11 */
1200 END OBJ(membar, &update_meminfo) scan_bar(obj, arg, 1);
1201 obj->callbacks.barval = &mem_barval;
1202 END OBJ(memwithbuffersbar, &update_meminfo) scan_bar(obj, arg, 1);
1203 obj->callbacks.barval = &mem_with_buffers_barval;
1204 #ifdef BUILD_X11
1205 END OBJ(memgraph, &update_meminfo) char *buf = nullptr;
1206 buf = scan_graph(obj, arg, 1);
1207 free_and_zero(buf);
1208 obj->callbacks.graphval = &mem_barval;
1209 END OBJ(memwithbuffersgraph, &update_meminfo) char *buf = nullptr;
1210 buf = scan_graph(obj, arg, 1);
1211 free_and_zero(buf);
1212 obj->callbacks.graphval = &mem_with_buffers_barval;
1213 #endif /* BUILD_X11*/
1214 #ifdef HAVE_SOME_SOUNDCARD_H
1215 END OBJ(mixer, 0) parse_mixer_arg(obj, arg);
1216 obj->callbacks.percentage = &mixer_percentage;
1217 END OBJ(mixerl, 0) parse_mixer_arg(obj, arg);
1218 obj->callbacks.percentage = &mixerl_percentage;
1219 END OBJ(mixerr, 0) parse_mixer_arg(obj, arg);
1220 obj->callbacks.percentage = &mixerr_percentage;
1221 END OBJ(mixerbar, 0) scan_mixer_bar(obj, arg);
1222 obj->callbacks.barval = &mixer_barval;
1223 END OBJ(mixerlbar, 0) scan_mixer_bar(obj, arg);
1224 obj->callbacks.barval = &mixerl_barval;
1225 END OBJ(mixerrbar, 0) scan_mixer_bar(obj, arg);
1226 obj->callbacks.barval = &mixerr_barval;
1227 END OBJ_IF(if_mixer_mute, 0) parse_mixer_arg(obj, arg);
1228 obj->callbacks.iftest = &check_mixer_muted;
1229 #endif /* HAVE_SOME_SOUNDCARD_H */
1230 #ifdef BUILD_X11
1231 END OBJ(monitor, nullptr) obj->callbacks.print = &print_monitor;
1232 END OBJ(monitor_number, nullptr) obj->callbacks.print = &print_monitor_number;
1233 END OBJ(desktop, nullptr) obj->callbacks.print = &print_desktop;
1234 END OBJ(desktop_number, nullptr) obj->callbacks.print = &print_desktop_number;
1235 END OBJ(desktop_name, nullptr) obj->callbacks.print = &print_desktop_name;
1236 #endif /* BUILD_X11 */
1237 END OBJ_ARG(format_time, nullptr, "format_time needs a pid as argument")
1238 obj->sub = static_cast<text_object *>(malloc(sizeof(struct text_object)));
1239 extract_variable_text_internal(obj->sub, arg);
1240 obj->callbacks.print = &print_format_time;
1241 END OBJ(nodename, nullptr) obj->callbacks.print = &print_nodename;
1242 END OBJ(nodename_short, nullptr) obj->callbacks.print = &print_nodename_short;
1243 END OBJ_ARG(cmdline_to_pid, nullptr,
1244 "cmdline_to_pid needs a command line as argument")
1245 scan_cmdline_to_pid_arg(obj, arg, free_at_crash);
1246 obj->callbacks.print = &print_cmdline_to_pid;
1247 obj->callbacks.free = &gen_free_opaque;
1248 END OBJ_ARG(pid_chroot, nullptr, "pid_chroot needs a pid as argument")
1249 extract_object_args_to_sub(obj, arg);
1250 obj->callbacks.print = &print_pid_chroot;
1251 END OBJ_ARG(pid_cmdline, nullptr, "pid_cmdline needs a pid as argument")
1252 extract_object_args_to_sub(obj, arg);
1253 obj->callbacks.print = &print_pid_cmdline;
1254 END OBJ_ARG(pid_cwd, nullptr, "pid_cwd needs a pid as argument")
1255 extract_object_args_to_sub(obj, arg);
1256 obj->callbacks.print = &print_pid_cwd;
1257 END OBJ_ARG(pid_environ, nullptr, "pid_environ needs arguments")
1258 extract_object_args_to_sub(obj, arg);
1259 obj->callbacks.print = &print_pid_environ;
1260 END OBJ_ARG(pid_environ_list, nullptr,
1261 "pid_environ_list needs a pid as argument")
1262 extract_object_args_to_sub(obj, arg);
1263 obj->callbacks.print = &print_pid_environ_list;
1264 END OBJ_ARG(pid_exe, nullptr, "pid_exe needs a pid as argument")
1265 extract_object_args_to_sub(obj, arg);
1266 obj->callbacks.print = &print_pid_exe;
1267 END OBJ_ARG(pid_nice, nullptr, "pid_nice needs a pid as argument")
1268 extract_object_args_to_sub(obj, arg);
1269 obj->callbacks.print = &print_pid_nice;
1270 END OBJ_ARG(pid_openfiles, nullptr, "pid_openfiles needs a pid as argument")
1271 extract_object_args_to_sub(obj, arg);
1272 obj->callbacks.print = &print_pid_openfiles;
1273 END OBJ_ARG(pid_parent, nullptr, "pid_parent needs a pid as argument")
1274 extract_object_args_to_sub(obj, arg);
1275 obj->callbacks.print = &print_pid_parent;
1276 END OBJ_ARG(pid_priority, nullptr, "pid_priority needs a pid as argument")
1277 extract_object_args_to_sub(obj, arg);
1278 obj->callbacks.print = &print_pid_priority;
1279 END OBJ_ARG(pid_state, nullptr, "pid_state needs a pid as argument")
1280 extract_object_args_to_sub(obj, arg);
1281 obj->callbacks.print = &print_pid_state;
1282 END OBJ_ARG(pid_state_short, nullptr,
1283 "pid_state_short needs a pid as argument")
1284 extract_object_args_to_sub(obj, arg);
1285 obj->callbacks.print = &print_pid_state_short;
1286 END OBJ_ARG(pid_stderr, nullptr, "pid_stderr needs a pid as argument")
1287 extract_object_args_to_sub(obj, arg);
1288 obj->callbacks.print = &print_pid_stderr;
1289 END OBJ_ARG(pid_stdin, nullptr, "pid_stdin needs a pid as argument")
1290 extract_object_args_to_sub(obj, arg);
1291 obj->callbacks.print = &print_pid_stdin;
1292 END OBJ_ARG(pid_stdout, nullptr, "pid_stdout needs a pid as argument")
1293 extract_object_args_to_sub(obj, arg);
1294 obj->callbacks.print = &print_pid_stdout;
1295 END OBJ_ARG(pid_threads, nullptr, "pid_threads needs a pid as argument")
1296 extract_object_args_to_sub(obj, arg);
1297 obj->callbacks.print = &print_pid_threads;
1298 END OBJ_ARG(pid_thread_list, nullptr,
1299 "pid_thread_list needs a pid as argument")
1300 extract_object_args_to_sub(obj, arg);
1301 obj->callbacks.print = &print_pid_thread_list;
1302 END OBJ_ARG(pid_time_kernelmode, nullptr,
1303 "pid_time_kernelmode needs a pid as argument")
1304 extract_object_args_to_sub(obj, arg);
1305 obj->callbacks.print = &print_pid_time_kernelmode;
1306 END OBJ_ARG(pid_time_usermode, nullptr,
1307 "pid_time_usermode needs a pid as argument")
1308 extract_object_args_to_sub(obj, arg);
1309 obj->callbacks.print = &print_pid_time_usermode;
1310 END OBJ_ARG(pid_time, nullptr, "pid_time needs a pid as argument")
1311 extract_object_args_to_sub(obj, arg);
1312 obj->callbacks.print = &print_pid_time;
1313 END OBJ_ARG(pid_uid, nullptr, "pid_uid needs a pid as argument")
1314 extract_object_args_to_sub(obj, arg);
1315 obj->callbacks.print = &print_pid_uid;
1316 END OBJ_ARG(pid_euid, nullptr, "pid_euid needs a pid as argument")
1317 extract_object_args_to_sub(obj, arg);
1318 obj->callbacks.print = &print_pid_euid;
1319 END OBJ_ARG(pid_suid, nullptr, "pid_suid needs a pid as argument")
1320 extract_object_args_to_sub(obj, arg);
1321 obj->callbacks.print = &print_pid_suid;
1322 END OBJ_ARG(pid_fsuid, nullptr, "pid_fsuid needs a pid as argument")
1323 extract_object_args_to_sub(obj, arg);
1324 obj->callbacks.print = &print_pid_fsuid;
1325 END OBJ_ARG(pid_gid, nullptr, "pid_gid needs a pid as argument")
1326 extract_object_args_to_sub(obj, arg);
1327 obj->callbacks.print = &print_pid_gid;
1328 END OBJ_ARG(pid_egid, nullptr, "pid_egid needs a pid as argument")
1329 extract_object_args_to_sub(obj, arg);
1330 obj->callbacks.print = &print_pid_egid;
1331 END OBJ_ARG(pid_sgid, nullptr, "pid_sgid needs a pid as argument")
1332 extract_object_args_to_sub(obj, arg);
1333 obj->callbacks.print = &print_pid_sgid;
1334 END OBJ_ARG(pid_fsgid, nullptr, "pid_fsgid needs a pid as argument")
1335 extract_object_args_to_sub(obj, arg);
1336 obj->callbacks.print = &print_pid_fsgid;
1337 END OBJ_ARG(gid_name, nullptr, "gid_name needs a gid as argument")
1338 extract_object_args_to_sub(obj, arg);
1339 obj->callbacks.print = &print_gid_name;
1340 END OBJ_ARG(uid_name, nullptr, "uid_name needs a uid as argument")
1341 extract_object_args_to_sub(obj, arg);
1342 obj->callbacks.print = &print_uid_name;
1343 END OBJ_ARG(pid_read, nullptr, "pid_read needs a pid as argument")
1344 extract_object_args_to_sub(obj, arg);
1345 obj->callbacks.print = &print_pid_read;
1346 END OBJ_ARG(pid_vmpeak, nullptr, "pid_vmpeak needs a pid as argument")
1347 extract_object_args_to_sub(obj, arg);
1348 obj->callbacks.print = &print_pid_vmpeak;
1349 END OBJ_ARG(pid_vmsize, nullptr, "pid_vmsize needs a pid as argument")
1350 extract_object_args_to_sub(obj, arg);
1351 obj->callbacks.print = &print_pid_vmsize;
1352 END OBJ_ARG(pid_vmlck, nullptr, "pid_vmlck needs a pid as argument")
1353 extract_object_args_to_sub(obj, arg);
1354 obj->callbacks.print = &print_pid_vmlck;
1355 END OBJ_ARG(pid_vmhwm, nullptr, "pid_vmhwm needs a pid as argument")
1356 extract_object_args_to_sub(obj, arg);
1357 obj->callbacks.print = &print_pid_vmhwm;
1358 END OBJ_ARG(pid_vmrss, nullptr, "pid_vmrss needs a pid as argument")
1359 extract_object_args_to_sub(obj, arg);
1360 obj->callbacks.print = &print_pid_vmrss;
1361 END OBJ_ARG(pid_vmdata, nullptr, "pid_vmdata needs a pid as argument")
1362 extract_object_args_to_sub(obj, arg);
1363 obj->callbacks.print = &print_pid_vmdata;
1364 END OBJ_ARG(pid_vmstk, nullptr, "pid_vmstk needs a pid as argument")
1365 extract_object_args_to_sub(obj, arg);
1366 obj->callbacks.print = &print_pid_vmstk;
1367 END OBJ_ARG(pid_vmexe, nullptr, "pid_vmexe needs a pid as argument")
1368 extract_object_args_to_sub(obj, arg);
1369 obj->callbacks.print = &print_pid_vmexe;
1370 END OBJ_ARG(pid_vmlib, nullptr, "pid_vmlib needs a pid as argument")
1371 extract_object_args_to_sub(obj, arg);
1372 obj->callbacks.print = &print_pid_vmlib;
1373 END OBJ_ARG(pid_vmpte, nullptr, "pid_vmpte needs a pid as argument")
1374 extract_object_args_to_sub(obj, arg);
1375 obj->callbacks.print = &print_pid_vmpte;
1376 END OBJ_ARG(pid_write, nullptr, "pid_write needs a pid as argument")
1377 extract_object_args_to_sub(obj, arg);
1378 obj->callbacks.print = &print_pid_write;
1379 #ifdef __DragonFly__
1380 END OBJ(processes, &update_top)
1381 #else
1382 END OBJ(processes, &update_total_processes)
1383 #endif
1384 obj->callbacks.print = &print_processes;
1385 #ifdef __linux__
1386 END OBJ(distribution, 0) obj->callbacks.print = &print_distribution;
1387 END OBJ(running_processes, &update_top) top_running = 1;
1388 obj->callbacks.print = &print_running_processes;
1389 END OBJ(threads, &update_threads) obj->callbacks.print = &print_threads;
1390 END OBJ(running_threads, &update_stat) obj->callbacks.print =
1391 &print_running_threads;
1392 #else
1393 #if defined(__DragonFly__)
1394 END OBJ(running_processes, &update_top) obj->callbacks.print =
1395 &print_running_processes;
1396 #elif (defined(__APPLE__) && defined(__MACH__))
1397 END OBJ(running_processes, &update_running_processes) obj->callbacks.print =
1398 &print_running_processes;
1399 END OBJ(threads, &update_threads) obj->callbacks.print = &print_threads;
1400 END OBJ(running_threads, &update_running_threads) obj->callbacks.print =
1401 &print_running_threads;
1402 #else
1403 END OBJ(running_processes, &update_running_processes) obj->callbacks.print =
1404 &print_running_processes;
1405 #endif
1406 #endif /* __linux__ */
1407 END OBJ(shadecolor, nullptr)
1408 #ifdef BUILD_X11
1409 obj->data.l =
1410 arg != nullptr ? get_x11_color(arg) : default_shade_color.get(*state);
1411 obj->callbacks.print = &new_bg;
1412 #endif /* BUILD_X11 */
1413 END OBJ(outlinecolor, nullptr)
1414 #ifdef BUILD_X11
1415 obj->data.l =
1416 arg != nullptr ? get_x11_color(arg) : default_outline_color.get(*state);
1417 obj->callbacks.print = &new_outline;
1418 #endif /* BUILD_X11 */
1419 END OBJ(stippled_hr, nullptr)
1420 #ifdef BUILD_X11
1421 scan_stippled_hr(obj, arg);
1422 obj->callbacks.print = &new_stippled_hr;
1423 #endif /* BUILD_X11 */
1424 END OBJ(swap, &update_meminfo) obj->data.s = STRNDUP_ARG;
1425 obj->callbacks.print = &print_swap;
1426 obj->callbacks.free = &gen_free_opaque;
1427 END OBJ(swapfree, &update_meminfo) obj->data.s = STRNDUP_ARG;
1428 obj->callbacks.print = &print_swapfree;
1429 obj->callbacks.free = &gen_free_opaque;
1430 END OBJ(swapmax, &update_meminfo) obj->data.s = STRNDUP_ARG;
1431 obj->callbacks.print = &print_swapmax;
1432 obj->callbacks.free = &gen_free_opaque;
1433 END OBJ(swapperc, &update_meminfo) obj->callbacks.percentage =
1434 &swap_percentage;
1435 END OBJ(swapbar, &update_meminfo) scan_bar(obj, arg, 1);
1436 obj->callbacks.barval = &swap_barval;
1437 /* XXX: swapgraph, swapgauge? */
1438 END OBJ(sysname, nullptr) obj->callbacks.print = &print_sysname;
1439 END OBJ(time, nullptr) scan_time(obj, arg);
1440 obj->callbacks.print = &print_time;
1441 obj->callbacks.free = &free_time;
1442 END OBJ(utime, nullptr) scan_time(obj, arg);
1443 obj->callbacks.print = &print_utime;
1444 obj->callbacks.free = &free_time;
1445 END OBJ(tztime, nullptr) scan_tztime(obj, arg);
1446 obj->callbacks.print = &print_tztime;
1447 obj->callbacks.free = &free_tztime;
1448 #ifdef BUILD_ICAL
1449 END OBJ_ARG(ical, 0, "ical requires arguments")
1450 parse_ical_args(obj, arg, free_at_crash, s);
1451 obj->callbacks.print = &print_ical;
1452 obj->callbacks.free = &free_ical;
1453 #endif
1454 #ifdef BUILD_IRC
1455 END OBJ_ARG(irc, 0, "irc requires arguments") parse_irc_args(obj, arg);
1456 obj->callbacks.print = &print_irc;
1457 obj->callbacks.free = &free_irc;
1458 #endif
1459 #ifdef BUILD_ICONV
1460 END OBJ_ARG(iconv_start, 0, "Iconv requires arguments")
1461 init_iconv_start(obj, free_at_crash, arg);
1462 obj->callbacks.print = &print_iconv_start;
1463 obj->callbacks.free = &free_iconv;
1464 END OBJ(iconv_stop, 0) init_iconv_stop();
1465 obj->callbacks.print = &print_iconv_stop;
1466 #endif
1467 END OBJ(totaldown, &update_net_stats)
1468 parse_net_stat_arg(obj, arg, free_at_crash);
1469 obj->callbacks.print = &print_totaldown;
1470 END OBJ(totalup, &update_net_stats)
1471 parse_net_stat_arg(obj, arg, free_at_crash);
1472 obj->callbacks.print = &print_totalup;
1473 END OBJ(updates, nullptr) obj->callbacks.print = &print_updates;
1474 END OBJ_IF(if_updatenr, nullptr) obj->data.i = arg != nullptr ? atoi(arg) : 0;
1475 if (obj->data.i == 0) {
1476 CRIT_ERR(obj, free_at_crash,
1477 "if_updatenr needs a number above 0 as argument");
1478 }
1479 set_updatereset(obj->data.i > get_updatereset() ? obj->data.i
1480 : get_updatereset());
1481 obj->callbacks.iftest = &updatenr_iftest;
1482 END OBJ(alignr, nullptr) obj->data.l = arg != nullptr ? atoi(arg) : 1;
1483 obj->callbacks.print = &new_alignr;
1484 END OBJ(alignc, nullptr) obj->data.l = arg != nullptr ? atoi(arg) : 0;
1485 obj->callbacks.print = &new_alignc;
1486 END OBJ(upspeed, &update_net_stats)
1487 parse_net_stat_arg(obj, arg, free_at_crash);
1488 obj->callbacks.print = &print_upspeed;
1489 END OBJ(upspeedf, &update_net_stats)
1490 parse_net_stat_arg(obj, arg, free_at_crash);
1491 obj->callbacks.print = &print_upspeedf;
1492 #ifdef BUILD_X11
1493 END OBJ(upspeedgraph, &update_net_stats)
1494 parse_net_stat_graph_arg(obj, arg, free_at_crash);
1495 obj->callbacks.graphval = &upspeedgraphval;
1496 #endif
1497 END OBJ(uptime_short, &update_uptime) obj->callbacks.print =
1498 &print_uptime_short;
1499 END OBJ(uptime, &update_uptime) obj->callbacks.print = &print_uptime;
1500 #if defined(__linux__)
1501 END OBJ(user_names, &update_users) obj->callbacks.print = &print_user_names;
1502 obj->callbacks.free = &free_user_names;
1503 END OBJ(user_times, &update_users) obj->callbacks.print = &print_user_times;
1504 obj->callbacks.free = &free_user_times;
1505 END OBJ_ARG(user_time, 0, "user time needs a console name as argument")
1506 obj->data.s = STRNDUP_ARG;
1507 obj->callbacks.print = &print_user_time;
1508 obj->callbacks.free = &free_user_time;
1509 END OBJ(user_terms, &update_users) obj->callbacks.print = &print_user_terms;
1510 obj->callbacks.free = &free_user_terms;
1511 END OBJ(user_number, &update_users) obj->callbacks.print = &print_user_number;
1512 END OBJ(gw_iface, &update_gateway_info) obj->callbacks.print =
1513 &print_gateway_iface;
1514 obj->callbacks.free = &free_gateway_info;
1515 END OBJ_IF(if_gw, &update_gateway_info) obj->callbacks.iftest =
1516 &gateway_exists;
1517 obj->callbacks.free = &free_gateway_info;
1518 END OBJ(gw_ip, &update_gateway_info) obj->callbacks.print = &print_gateway_ip;
1519 obj->callbacks.free = &free_gateway_info;
1520 END OBJ(iface, &update_gateway_info2) obj->data.s = STRNDUP_ARG;
1521 obj->callbacks.print = &print_gateway_iface2;
1522 obj->callbacks.free = &gen_free_opaque;
1523 #endif /* __linux__ */
1524 #if (defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || \
1525 defined(__DragonFly__) || defined(__OpenBSD__)) && \
1526 (defined(i386) || defined(__i386__))
1527 END OBJ(apm_adapter, 0) obj->callbacks.print = &print_apm_adapter;
1528 END OBJ(apm_battery_life, 0) obj->callbacks.print = &print_apm_battery_life;
1529 END OBJ(apm_battery_time, 0) obj->callbacks.print = &print_apm_battery_time;
1530 #endif /* __FreeBSD__ */
1531 END OBJ(imap_unseen, nullptr) parse_imap_mail_args(obj, arg);
1532 obj->callbacks.print = &print_imap_unseen;
1533 obj->callbacks.free = &free_mail_obj;
1534 END OBJ(imap_messages, nullptr) parse_imap_mail_args(obj, arg);
1535 obj->callbacks.print = &print_imap_messages;
1536 obj->callbacks.free = &free_mail_obj;
1537 END OBJ(pop3_unseen, nullptr) parse_pop3_mail_args(obj, arg);
1538 obj->callbacks.print = &print_pop3_unseen;
1539 obj->callbacks.free = &free_mail_obj;
1540 END OBJ(pop3_used, nullptr) parse_pop3_mail_args(obj, arg);
1541 obj->callbacks.print = &print_pop3_used;
1542 obj->callbacks.free = &free_mail_obj;
1543 #ifdef BUILD_IBM
1544 END OBJ_ARG(smapi, 0, "smapi needs an argument") obj->data.s = STRNDUP_ARG;
1545 obj->callbacks.print = &print_smapi;
1546 obj->callbacks.free = &gen_free_opaque;
1547 END OBJ_IF_ARG(if_smapi_bat_installed, 0,
1548 "if_smapi_bat_installed needs an argument") obj->data.s =
1549 STRNDUP_ARG;
1550 obj->callbacks.iftest = &smapi_bat_installed;
1551 obj->callbacks.free = &gen_free_opaque;
1552 END OBJ_ARG(smapi_bat_perc, 0, "smapi_bat_perc needs an argument")
1553 obj->data.s = STRNDUP_ARG;
1554 obj->callbacks.percentage = &smapi_bat_percentage;
1555 obj->callbacks.free = &gen_free_opaque;
1556 END OBJ_ARG(smapi_bat_temp, 0, "smapi_bat_temp needs an argument")
1557 obj->data.s = STRNDUP_ARG;
1558 obj->callbacks.print = &print_smapi_bat_temp;
1559 obj->callbacks.free = &gen_free_opaque;
1560 END OBJ_ARG(smapi_bat_power, 0, "smapi_bat_power needs an argument")
1561 obj->data.s = STRNDUP_ARG;
1562 obj->callbacks.print = &print_smapi_bat_power;
1563 obj->callbacks.free = &gen_free_opaque;
1564 END OBJ_ARG(smapi_bat_bar, 0, "smapi_bat_bar needs an argument") int cnt;
1565 if (sscanf(arg, "%i %n", &obj->data.i, &cnt) <= 0) {
1566 NORM_ERR("first argument to smapi_bat_bar must be an integer value");
1567 obj->data.i = -1;
1568 } else
1569 arg = scan_bar(obj, arg + cnt, 100);
1570 obj->callbacks.barval = &smapi_bat_barval;
1571 #endif /* BUILD_IBM */
1572 #ifdef BUILD_MPD
1573 #define mpd_set_maxlen(name) \
1574 if (arg) { \
1575 int i; \
1576 sscanf(arg, "%d", &i); \
1577 if (i > 0) \
1578 obj->data.i = i + 1; \
1579 else \
1580 NORM_ERR(#name ": invalid length argument"); \
1581 }
1582 END OBJ(mpd_artist, nullptr) mpd_set_maxlen(mpd_artist);
1583 obj->callbacks.print = &print_mpd_artist;
1584 END OBJ(mpd_albumartist, nullptr) mpd_set_maxlen(mpd_albumartist);
1585 obj->callbacks.print = &print_mpd_albumartist;
1586 END OBJ(mpd_title, nullptr) mpd_set_maxlen(mpd_title);
1587 obj->callbacks.print = &print_mpd_title;
1588 END OBJ(mpd_date, nullptr) mpd_set_maxlen(mpd_date);
1589 obj->callbacks.print = &print_mpd_date;
1590 END OBJ(mpd_comment, nullptr) mpd_set_maxlen(mpd_comment);
1591 obj->callbacks.print = &print_mpd_comment;
1592 END OBJ(mpd_random, nullptr) obj->callbacks.print = &print_mpd_random;
1593 END OBJ(mpd_repeat, nullptr) obj->callbacks.print = &print_mpd_repeat;
1594 END OBJ(mpd_elapsed, nullptr) obj->callbacks.print = &print_mpd_elapsed;
1595 END OBJ(mpd_length, nullptr) obj->callbacks.print = &print_mpd_length;
1596 END OBJ(mpd_track, nullptr) mpd_set_maxlen(mpd_track);
1597 obj->callbacks.print = &print_mpd_track;
1598 END OBJ(mpd_name, nullptr) mpd_set_maxlen(mpd_name);
1599 obj->callbacks.print = &print_mpd_name;
1600 END OBJ(mpd_file, nullptr) mpd_set_maxlen(mpd_file);
1601 obj->callbacks.print = &print_mpd_file;
1602 END OBJ(mpd_percent, nullptr) obj->callbacks.percentage = &mpd_percentage;
1603 END OBJ(mpd_album, nullptr) mpd_set_maxlen(mpd_album);
1604 obj->callbacks.print = &print_mpd_album;
1605 END OBJ(mpd_vol, nullptr) obj->callbacks.print = &print_mpd_vol;
1606 END OBJ(mpd_bitrate, nullptr) obj->callbacks.print = &print_mpd_bitrate;
1607 END OBJ(mpd_status, nullptr) obj->callbacks.print = &print_mpd_status;
1608 END OBJ(mpd_bar, nullptr) scan_bar(obj, arg, 1);
1609 obj->callbacks.barval = &mpd_barval;
1610 END OBJ(mpd_smart, nullptr) mpd_set_maxlen(mpd_smart);
1611 obj->callbacks.print = &print_mpd_smart;
1612 END OBJ_IF(if_mpd_playing, nullptr) obj->callbacks.iftest =
1613 &check_mpd_playing;
1614 #undef mpd_set_maxlen
1615 #endif /* BUILD_MPD */
1616 #ifdef BUILD_MOC
1617 END OBJ(moc_state, nullptr) obj->callbacks.print = &print_moc_state;
1618 END OBJ(moc_file, nullptr) obj->callbacks.print = &print_moc_file;
1619 END OBJ(moc_title, nullptr) obj->callbacks.print = &print_moc_title;
1620 END OBJ(moc_artist, nullptr) obj->callbacks.print = &print_moc_artist;
1621 END OBJ(moc_song, nullptr) obj->callbacks.print = &print_moc_song;
1622 END OBJ(moc_album, nullptr) obj->callbacks.print = &print_moc_album;
1623 END OBJ(moc_totaltime, nullptr) obj->callbacks.print = &print_moc_totaltime;
1624 END OBJ(moc_timeleft, nullptr) obj->callbacks.print = &print_moc_timeleft;
1625 END OBJ(moc_curtime, nullptr) obj->callbacks.print = &print_moc_curtime;
1626 END OBJ(moc_bitrate, nullptr) obj->callbacks.print = &print_moc_bitrate;
1627 END OBJ(moc_rate, nullptr) obj->callbacks.print = &print_moc_rate;
1628 #endif /* BUILD_MOC */
1629 #ifdef BUILD_CMUS
1630 END OBJ(cmus_state, 0) obj->callbacks.print = &print_cmus_state;
1631 END OBJ(cmus_file, 0) obj->callbacks.print = &print_cmus_file;
1632 END OBJ(cmus_title, 0) obj->callbacks.print = &print_cmus_title;
1633 END OBJ(cmus_artist, 0) obj->callbacks.print = &print_cmus_artist;
1634 END OBJ(cmus_album, 0) obj->callbacks.print = &print_cmus_album;
1635 END OBJ(cmus_totaltime, 0) obj->callbacks.print = &print_cmus_totaltime;
1636 END OBJ(cmus_timeleft, 0) obj->callbacks.print = &print_cmus_timeleft;
1637 END OBJ(cmus_curtime, 0) obj->callbacks.print = &print_cmus_curtime;
1638 END OBJ(cmus_random, 0) obj->callbacks.print = &print_cmus_random;
1639 END OBJ(cmus_state, 0) obj->callbacks.print = &print_cmus_state;
1640 END OBJ(cmus_file, 0) obj->callbacks.print = &print_cmus_file;
1641 END OBJ(cmus_title, 0) obj->callbacks.print = &print_cmus_title;
1642 END OBJ(cmus_artist, 0) obj->callbacks.print = &print_cmus_artist;
1643 END OBJ(cmus_album, 0) obj->callbacks.print = &print_cmus_album;
1644 END OBJ(cmus_totaltime, 0) obj->callbacks.print = &print_cmus_totaltime;
1645 END OBJ(cmus_timeleft, 0) obj->callbacks.print = &print_cmus_timeleft;
1646 END OBJ(cmus_curtime, 0) obj->callbacks.print = &print_cmus_curtime;
1647 END OBJ(cmus_random, 0) obj->callbacks.print = &print_cmus_random;
1648 END OBJ(cmus_repeat, 0) obj->callbacks.print = &print_cmus_repeat;
1649 END OBJ(cmus_aaa, 0) obj->callbacks.print = &print_cmus_aaa;
1650 END OBJ(cmus_track, 0) obj->callbacks.print = &print_cmus_track;
1651 END OBJ(cmus_genre, 0) obj->callbacks.print = &print_cmus_genre;
1652 END OBJ(cmus_date, 0) obj->callbacks.print = &print_cmus_date;
1653 END OBJ(cmus_progress, 0) scan_bar(obj, arg, 1);
1654 obj->callbacks.barval = &cmus_progress;
1655 END OBJ(cmus_percent, 0) obj->callbacks.percentage = &cmus_percent;
1656 #endif /* BUILD_CMUS */
1657 #ifdef BUILD_XMMS2
1658 END OBJ(xmms2_artist, &update_xmms2) obj->callbacks.print =
1659 &print_xmms2_artist;
1660 obj->callbacks.free = &free_xmms2;
1661 END OBJ(xmms2_album, &update_xmms2) obj->callbacks.print = &print_xmms2_album;
1662 obj->callbacks.free = &free_xmms2;
1663 END OBJ(xmms2_title, &update_xmms2) obj->callbacks.print = &print_xmms2_title;
1664 obj->callbacks.free = &free_xmms2;
1665 END OBJ(xmms2_genre, &update_xmms2) obj->callbacks.print = &print_xmms2_genre;
1666 obj->callbacks.free = &free_xmms2;
1667 END OBJ(xmms2_comment, &update_xmms2) obj->callbacks.print =
1668 &print_xmms2_comment;
1669 obj->callbacks.free = &free_xmms2;
1670 END OBJ(xmms2_url, &update_xmms2) obj->callbacks.print = &print_xmms2_url;
1671 obj->callbacks.free = &free_xmms2;
1672 END OBJ(xmms2_tracknr, &update_xmms2) obj->callbacks.print =
1673 &print_xmms2_tracknr;
1674 obj->callbacks.free = &free_xmms2;
1675 END OBJ(xmms2_bitrate, &update_xmms2) obj->callbacks.print =
1676 &print_xmms2_bitrate;
1677 obj->callbacks.free = &free_xmms2;
1678 END OBJ(xmms2_date, &update_xmms2) obj->callbacks.print = &print_xmms2_date;
1679 obj->callbacks.free = &free_xmms2;
1680 END OBJ(xmms2_id, &update_xmms2) obj->callbacks.print = &print_xmms2_id;
1681 obj->callbacks.free = &free_xmms2;
1682 END OBJ(xmms2_duration, &update_xmms2) obj->callbacks.print =
1683 &print_xmms2_duration;
1684 obj->callbacks.free = &free_xmms2;
1685 END OBJ(xmms2_elapsed, &update_xmms2) obj->callbacks.print =
1686 &print_xmms2_elapsed;
1687 obj->callbacks.free = &free_xmms2;
1688 END OBJ(xmms2_size, &update_xmms2) obj->callbacks.print = &print_xmms2_size;
1689 obj->callbacks.free = &free_xmms2;
1690 END OBJ(xmms2_status, &update_xmms2) obj->callbacks.print =
1691 &print_xmms2_status;
1692 obj->callbacks.free = &free_xmms2;
1693 END OBJ(xmms2_percent, &update_xmms2) obj->callbacks.print =
1694 &print_xmms2_percent;
1695 obj->callbacks.free = &free_xmms2;
1696 END OBJ(xmms2_bar, &update_xmms2) scan_bar(obj, arg, 1);
1697 obj->callbacks.barval = &xmms2_barval;
1698 obj->callbacks.free = &free_xmms2;
1699 END OBJ(xmms2_smart, &update_xmms2) obj->callbacks.print = &print_xmms2_smart;
1700 obj->callbacks.free = &free_xmms2;
1701 END OBJ(xmms2_playlist, &update_xmms2) obj->callbacks.print =
1702 &print_xmms2_playlist;
1703 obj->callbacks.free = &free_xmms2;
1704 END OBJ(xmms2_timesplayed, &update_xmms2) obj->callbacks.print =
1705 &print_xmms2_timesplayed;
1706 obj->callbacks.free = &free_xmms2;
1707 END OBJ_IF(if_xmms2_connected, &update_xmms2) obj->callbacks.iftest =
1708 &if_xmms2_connected;
1709 obj->callbacks.free = &free_xmms2;
1710 #endif /* BUILD_XMMS2 */
1711 #ifdef BUILD_AUDACIOUS
1712 END OBJ(audacious_status, 0) obj->callbacks.print = &print_audacious_status;
1713 END OBJ_ARG(audacious_title, 0, "audacious_title needs an argument")
1714 sscanf(arg, "%d", &obj->data.i);
1715 if (obj->data.i > 0) {
1716 ++obj->data.i;
1717 } else {
1718 CRIT_ERR(obj, free_at_crash, "audacious_title: invalid length argument");
1719 }
1720 obj->callbacks.print = &print_audacious_title;
1721 END OBJ(audacious_length, 0) obj->callbacks.print = &print_audacious_length;
1722 END OBJ(audacious_length_seconds, 0) obj->callbacks.print =
1723 &print_audacious_length_seconds;
1724 END OBJ(audacious_position, 0) obj->callbacks.print =
1725 &print_audacious_position;
1726 END OBJ(audacious_position_seconds, 0) obj->callbacks.print =
1727 &print_audacious_position_seconds;
1728 END OBJ(audacious_bitrate, 0) obj->callbacks.print = &print_audacious_bitrate;
1729 END OBJ(audacious_frequency, 0) obj->callbacks.print =
1730 &print_audacious_frequency;
1731 END OBJ(audacious_channels, 0) obj->callbacks.print =
1732 &print_audacious_channels;
1733 END OBJ(audacious_filename, 0) obj->callbacks.print =
1734 &print_audacious_filename;
1735 END OBJ(audacious_playlist_length, 0) obj->callbacks.print =
1736 &print_audacious_playlist_length;
1737 END OBJ(audacious_playlist_position, 0) obj->callbacks.print =
1738 &print_audacious_playlist_position;
1739 END OBJ(audacious_main_volume, 0) obj->callbacks.print =
1740 &print_audacious_main_volume;
1741 END OBJ(audacious_bar, 0) scan_bar(obj, arg, 1);
1742 obj->callbacks.barval = &audacious_barval;
1743 #endif /* BUILD_AUDACIOUS */
1744 #ifdef BUILD_CURL
1745 END OBJ_ARG(curl, 0, "curl needs arguments: <uri> <interval in minutes>")
1746 curl_parse_arg(obj, arg);
1747 obj->callbacks.print = &curl_print;
1748 obj->callbacks.free = &curl_obj_free;
1749 END OBJ(github_notifications, 0) obj->callbacks.print = &print_github;
1750 #endif /* BUILD_CURL */
1751 #ifdef BUILD_RSS
1752 END OBJ_ARG(rss, 0,
1753 "rss needs arguments: <uri> <interval in minutes> <action> "
1754 "[act_par] [spaces in front]") rss_scan_arg(obj, arg);
1755 obj->callbacks.print = &rss_print_info;
1756 obj->callbacks.free = &rss_free_obj_info;
1757 #endif /* BUILD_RSS */
1758 #ifdef BUILD_WEATHER_METAR
1759 END OBJ_ARG(weather, 0, "weather still needs to written...")
1760 obj->callbacks.print = &print_weather;
1761 #endif /* BUILD_WEATHER_METAR */
1762 END OBJ_ARG(lua, nullptr,
1763 "lua needs arguments: <function name> [function parameters]")
1764 obj->data.s = STRNDUP_ARG;
1765 obj->callbacks.print = &print_lua;
1766 obj->callbacks.free = &gen_free_opaque;
1767 END OBJ_ARG(
1768 lua_parse, nullptr,
1769 "lua_parse needs arguments: <function name> [function parameters]")
1770 obj->data.s = STRNDUP_ARG;
1771 obj->callbacks.print = &print_lua_parse;
1772 obj->callbacks.free = &gen_free_opaque;
1773 END OBJ_ARG(lua_bar, nullptr,
1774 "lua_bar needs arguments: <height>,<width> <function name> "
1775 "[function parameters]") arg = scan_bar(obj, arg, 100);
1776 if (arg != nullptr) {
1777 obj->data.s = STRNDUP_ARG;
1778 } else {
1779 CRIT_ERR(obj, free_at_crash,
1780 "lua_bar needs arguments: <height>,<width> <function name> "
1781 "[function parameters]");
1782 }
1783 obj->callbacks.barval = &lua_barval;
1784 obj->callbacks.free = &gen_free_opaque;
1785 #ifdef BUILD_X11
1786 END OBJ_ARG(
1787 lua_graph, nullptr,
1788 "lua_graph needs arguments: <function name> [height],[width] [gradient "
1789 "colour 1] [gradient colour 2] [scale] [-t] [-l]") char *buf = nullptr;
1790 buf = scan_graph(obj, arg, 100);
1791 if (buf != nullptr) {
1792 obj->data.s = buf;
1793 } else {
1794 CRIT_ERR(obj, free_at_crash,
1795 "lua_graph needs arguments: <function name> [height],[width] "
1796 "[gradient colour 1] [gradient colour 2] [scale] [-t] [-l]");
1797 }
1798 obj->callbacks.graphval = &lua_barval;
1799 obj->callbacks.free = &gen_free_opaque;
1800 END OBJ_ARG(lua_gauge, nullptr,
1801 "lua_gauge needs arguments: <height>,<width> <function name> "
1802 "[function parameters]") arg = scan_gauge(obj, arg, 100);
1803 if (arg != nullptr) {
1804 obj->data.s = STRNDUP_ARG;
1805 } else {
1806 CRIT_ERR(obj, free_at_crash,
1807 "lua_gauge needs arguments: <height>,<width> <function name> "
1808 "[function parameters]");
1809 }
1810 obj->callbacks.gaugeval = &lua_barval;
1811 obj->callbacks.free = &gen_free_opaque;
1812 #endif /* BUILD_X11 */
1813 #ifdef BUILD_HDDTEMP
1814 END OBJ(hddtemp, &update_hddtemp) if (arg) obj->data.s = STRNDUP_ARG;
1815 obj->callbacks.print = &print_hddtemp;
1816 obj->callbacks.free = &free_hddtemp;
1817 #endif /* BUILD_HDDTEMP */
1818 #ifdef BUILD_PORT_MONITORS
1819 END OBJ_ARG(tcp_portmon, &tcp_portmon_update, "tcp_portmon: needs arguments")
1820 tcp_portmon_init(obj, arg);
1821 obj->callbacks.print = &tcp_portmon_action;
1822 obj->callbacks.free = &tcp_portmon_free;
1823 #endif /* BUILD_PORT_MONITORS */
1824 END OBJ(entropy_avail, &update_entropy) obj->callbacks.print =
1825 &print_entropy_avail;
1826 END OBJ(entropy_perc, &update_entropy) obj->callbacks.percentage =
1827 &entropy_percentage;
1828 END OBJ(entropy_poolsize, &update_entropy) obj->callbacks.print =
1829 &print_entropy_poolsize;
1830 END OBJ(entropy_bar, &update_entropy) scan_bar(obj, arg, 1);
1831 obj->callbacks.barval = &entropy_barval;
1832 END OBJ_ARG(blink, nullptr, "blink needs a argument") obj->sub =
1833 static_cast<text_object *>(malloc(sizeof(struct text_object)));
1834 extract_variable_text_internal(obj->sub, arg);
1835 obj->callbacks.print = &print_blink;
1836 END OBJ_ARG(to_bytes, nullptr, "to_bytes needs a argument") obj->sub =
1837 static_cast<text_object *>(malloc(sizeof(struct text_object)));
1838 extract_variable_text_internal(obj->sub, arg);
1839 obj->callbacks.print = &print_to_bytes;
1840 #ifdef BUILD_CURL
1841 END OBJ_ARG(stock, 0, "stock needs arguments") stock_parse_arg(obj, arg);
1842 obj->callbacks.print = &print_stock;
1843 obj->callbacks.free = &free_stock;
1844 #endif /* BUILD_CURL */
1845 END OBJ(scroll, nullptr)
1846 #ifdef BUILD_X11
1847 /* allocate a follower to reset any color changes */
1848 #endif /* BUILD_X11 */
1849 parse_scroll_arg(obj, arg, free_at_crash, s);
1850 obj->callbacks.print = &print_scroll;
1851 obj->callbacks.free = &free_scroll;
1852 END OBJ(combine, nullptr) try {
1853 parse_combine_arg(obj, arg);
1854 } catch (combine_needs_2_args_error &e) {
1855 free(obj);
1856 throw obj_create_error(e.what());
1857 }
1858 obj->callbacks.print = &print_combine;
1859 obj->callbacks.free = &free_combine;
1860 #ifdef BUILD_NVIDIA
1861 END OBJ_ARG(
1862 nvidia, 0,
1863 "nvidia needs an argument") if (set_nvidia_query(obj, arg, NONSPECIAL)) {
1864 CRIT_ERR(obj, free_at_crash,
1865 "nvidia: invalid argument"
1866 " specified: '%s'",
1867 arg);
1868 }
1869 obj->callbacks.print = &print_nvidia_value;
1870 obj->callbacks.free = &free_nvidia;
1871 END OBJ_ARG(
1872 nvidiabar, 0,
1873 "nvidiabar needs an argument") if (set_nvidia_query(obj, arg, BAR)) {
1874 CRIT_ERR(obj, free_at_crash,
1875 "nvidiabar: invalid argument"
1876 " specified: '%s'",
1877 arg);
1878 }
1879 obj->callbacks.barval = &get_nvidia_barval;
1880 obj->callbacks.free = &free_nvidia;
1881 END OBJ_ARG(
1882 nvidiagraph, 0,
1883 "nvidiagraph needs an argument") if (set_nvidia_query(obj, arg, GRAPH)) {
1884 CRIT_ERR(obj, free_at_crash,
1885 "nvidiagraph: invalid argument"
1886 " specified: '%s'",
1887 arg);
1888 }
1889 obj->callbacks.graphval = &get_nvidia_barval;
1890 obj->callbacks.free = &free_nvidia;
1891 END OBJ_ARG(
1892 nvidiagauge, 0,
1893 "nvidiagauge needs an argument") if (set_nvidia_query(obj, arg, GAUGE)) {
1894 CRIT_ERR(obj, free_at_crash,
1895 "nvidiagauge: invalid argument"
1896 " specified: '%s'",
1897 arg);
1898 }
1899 obj->callbacks.gaugeval = &get_nvidia_barval;
1900 obj->callbacks.free = &free_nvidia;
1901 #endif /* BUILD_NVIDIA */
1902 #ifdef BUILD_APCUPSD
1903 END OBJ_ARG(
1904 apcupsd, &update_apcupsd,
1905 "apcupsd needs arguments: <host> <port>") if (apcupsd_scan_arg(arg) !=
1906 0) {
1907 CRIT_ERR(obj, free_at_crash, "apcupsd needs arguments: <host> <port>");
1908 }
1909 obj->callbacks.print = &gen_print_nothing;
1910 END OBJ(apcupsd_name, &update_apcupsd) obj->callbacks.print =
1911 &print_apcupsd_name;
1912 END OBJ(apcupsd_model, &update_apcupsd) obj->callbacks.print =
1913 &print_apcupsd_model;
1914 END OBJ(apcupsd_upsmode, &update_apcupsd) obj->callbacks.print =
1915 &print_apcupsd_upsmode;
1916 END OBJ(apcupsd_cable, &update_apcupsd) obj->callbacks.print =
1917 &print_apcupsd_cable;
1918 END OBJ(apcupsd_status, &update_apcupsd) obj->callbacks.print =
1919 &print_apcupsd_status;
1920 END OBJ(apcupsd_linev, &update_apcupsd) obj->callbacks.print =
1921 &print_apcupsd_linev;
1922 END OBJ(apcupsd_load, &update_apcupsd) obj->callbacks.print =
1923 &print_apcupsd_load;
1924 END OBJ(apcupsd_loadbar, &update_apcupsd) scan_bar(obj, arg, 100);
1925 obj->callbacks.barval = &apcupsd_loadbarval;
1926 #ifdef BUILD_X11
1927 END OBJ(apcupsd_loadgraph, &update_apcupsd) char *buf = nullptr;
1928 buf = scan_graph(obj, arg, 100);
1929 free_and_zero(buf);
1930 obj->callbacks.graphval = &apcupsd_loadbarval;
1931 END OBJ(apcupsd_loadgauge, &update_apcupsd) scan_gauge(obj, arg, 100);
1932 obj->callbacks.gaugeval = &apcupsd_loadbarval;
1933 #endif /* BUILD_X11 */
1934 END OBJ(apcupsd_charge, &update_apcupsd) obj->callbacks.print =
1935 &print_apcupsd_charge;
1936 END OBJ(apcupsd_timeleft, &update_apcupsd) obj->callbacks.print =
1937 &print_apcupsd_timeleft;
1938 END OBJ(apcupsd_temp, &update_apcupsd) obj->callbacks.print =
1939 &print_apcupsd_temp;
1940 END OBJ(apcupsd_lastxfer, &update_apcupsd) obj->callbacks.print =
1941 &print_apcupsd_lastxfer;
1942 #endif /* BUILD_APCUPSD */
1943 #ifdef BUILD_JOURNAL
1944 END OBJ_ARG(journal, 0, "journal needs arguments")
1945 init_journal("journal", arg, obj, free_at_crash);
1946 obj->callbacks.print = &print_journal;
1947 obj->callbacks.free = &free_journal;
1948 #endif /* BUILD_JOURNAL */
1949 #ifdef BUILD_PULSEAUDIO
1950 END OBJ_IF(if_pa_sink_muted, 0) obj->callbacks.iftest = &puau_muted;
1951 obj->callbacks.free = &free_pulseaudio;
1952 init_pulseaudio(obj);
1953 END OBJ(pa_sink_description, 0) obj->callbacks.print =
1954 &print_puau_sink_description;
1955 obj->callbacks.free = &free_pulseaudio;
1956 init_pulseaudio(obj);
1957 END OBJ(pa_sink_active_port_name, 0) obj->callbacks.print =
1958 &print_puau_sink_active_port_name;
1959 obj->callbacks.free = &free_pulseaudio;
1960 init_pulseaudio(obj);
1961 END OBJ(pa_sink_active_port_description, 0) obj->callbacks.print =
1962 &print_puau_sink_active_port_description;
1963 obj->callbacks.free = &free_pulseaudio;
1964 init_pulseaudio(obj);
1965 END OBJ(pa_sink_volume, 0) obj->callbacks.percentage = &puau_vol;
1966 obj->callbacks.free = &free_pulseaudio;
1967 init_pulseaudio(obj);
1968 END OBJ(pa_sink_volumebar, 0) scan_bar(obj, arg, 1);
1969 init_pulseaudio(obj);
1970 obj->callbacks.barval = &puau_volumebarval;
1971 obj->callbacks.free = &free_pulseaudio;
1972 END OBJ(pa_card_active_profile, 0) obj->callbacks.print =
1973 &print_puau_card_active_profile;
1974 obj->callbacks.free = &free_pulseaudio;
1975 init_pulseaudio(obj);
1976 END OBJ(pa_card_name, 0) obj->callbacks.print = &print_puau_card_name;
1977 obj->callbacks.free = &free_pulseaudio;
1978 init_pulseaudio(obj);
1979 #endif /* BUILD_PULSEAUDIO */
1980 #ifdef BUILD_INTEL_BACKLIGHT
1981 END OBJ(intel_backlight, 0) obj->callbacks.print = &print_intel_backlight;
1982 obj->callbacks.free = &free_intel_backlight;
1983 init_intel_backlight(obj);
1984 #endif /* BUILD_INTEL_BACKLIGHT */
1985 END {
1986 auto *buf = static_cast<char *>(malloc(text_buffer_size.get(*state)));
1987
1988 NORM_ERR("unknown variable '$%s'", s);
1989 snprintf(buf, text_buffer_size.get(*state), "${%s}", s);
1990 obj_be_plain_text(obj, buf);
1991 free(buf);
1992 }
1993 #undef OBJ
1994 #undef OBJ_IF
1995 #undef OBJ_ARG
1996 #undef OBJ_IF_ARG
1997 #undef __OBJ_HEAD
1998 #undef __OBJ_IF
1999 #undef __OBJ_ARG
2000 #undef END
2001
2002 return obj;
2003 }
2004
2005 /*
2006 * - assumes that *string is '#'
2007 * - removes the part from '#' to the end of line ('\n' or '\0')
2008 * - it removes the '\n'
2009 * - copies the last char into 'char *last' argument, which should be a pointer
2010 * to a char rather than a string.
2011 */
2012 static size_t remove_comment(char *string, char *last) {
2013 char *end = string;
2014 while (*end != '\0' && *end != '\n') { ++end; }
2015 if (last != nullptr) { *last = *end; }
2016 if (*end == '\n') { end++; }
2017 strfold(string, end - string);
2018 return end - string;
2019 }
2020
2021 size_t remove_comments(char *string) {
2022 char *curplace;
2023 size_t folded = 0;
2024 for (curplace = string; *curplace != 0; curplace++) {
2025 if (*curplace == '\\' && *(curplace + 1) == '#') {
2026 // strcpy can't be used for overlapping strings
2027 strfold(curplace, 1);
2028 folded += 1;
2029 } else if (*curplace == '#') {
2030 folded += remove_comment(curplace, nullptr);
2031 }
2032 }
2033 return folded;
2034 }
2035
2036 int extract_variable_text_internal(struct text_object *retval,
2037 const char *const_p) {
2038 struct text_object *obj;
2039 char *p, *s, *orig_p;
2040 long line;
2041 void *ifblock_opaque = nullptr;
2042 char *tmp_p;
2043 char *arg = nullptr;
2044 size_t len = 0;
2045
2046 p = strndup(const_p, max_user_text.get(*state) - 1);
2047 while (text_contains_templates(p) != 0) {
2048 char *tmp;
2049 tmp = find_and_replace_templates(p);
2050 free(p);
2051 p = tmp;
2052 }
2053 s = orig_p = p;
2054
2055 if (static_cast<int>(strcmp(p, const_p) != 0) != 0) {
2056 DBGP2("replaced all templates in text: input is\n'%s'\noutput is\n'%s'",
2057 const_p, p);
2058 } else {
2059 DBGP2("no templates to replace");
2060 }
2061
2062 memset(retval, 0, sizeof(struct text_object));
2063
2064 line = global_text_lines;
2065
2066 while (*p != 0) {
2067 if (*p == '\n') { line++; }
2068 if (*p == '$') {
2069 *p = '\0';
2070 obj = create_plain_text(s);
2071 if (obj != nullptr) { append_object(retval, obj); }
2072 *p = '$';
2073 p++;
2074 s = p;
2075
2076 if (*p != '$') {
2077 auto *buf = static_cast<char *>(malloc(text_buffer_size.get(*state)));
2078 const char *var;
2079
2080 /* variable is either $foo or ${foo} */
2081 if (*p == '{') {
2082 unsigned int brl = 1, brr = 0;
2083
2084 p++;
2085 s = p;
2086 while ((*p != 0) && brl != brr) {
2087 if (*p == '{') { brl++; }
2088 if (*p == '}') { brr++; }
2089 p++;
2090 }
2091 p--;
2092 } else {
2093 s = p;
2094 if (*p == '#') { p++; }
2095 while ((*p != 0) && ((isalnum(static_cast<unsigned char>(*p)) != 0) ||
2096 *p == '_')) {
2097 p++;
2098 }
2099 }
2100
2101 /* copy variable to buffer */
2102 len = (p - s > static_cast<int>(text_buffer_size.get(*state)) - 1)
2103 ? static_cast<int>(text_buffer_size.get(*state)) - 1
2104 : (p - s);
2105 strncpy(buf, s, len);
2106 buf[len] = '\0';
2107
2108 if (*p == '}') { p++; }
2109 s = p;
2110
2111 /* search for variable in environment */
2112
2113 var = getenv(buf);
2114 if (var != nullptr) {
2115 obj = create_plain_text(var);
2116 if (obj != nullptr) { append_object(retval, obj); }
2117 free(buf);
2118 continue;
2119 }
2120
2121 /* if variable wasn't found in environment, use some special */
2122
2123 arg = nullptr;
2124
2125 /* split arg */
2126 if (strchr(buf, ' ') != nullptr) {
2127 arg = strchr(buf, ' ');
2128 *arg = '\0';
2129 arg++;
2130 while (isspace(static_cast<unsigned char>(*arg)) != 0) { arg++; }
2131 if (*arg == 0) { arg = nullptr; }
2132 }
2133
2134 /* lowercase variable name */
2135 tmp_p = buf;
2136 while (*tmp_p != 0) {
2137 *tmp_p = tolower(static_cast<unsigned char>(*tmp_p));
2138 tmp_p++;
2139 }
2140
2141 try {
2142 obj = construct_text_object(buf, arg, line, &ifblock_opaque, orig_p);
2143 } catch (obj_create_error &e) {
2144 free(buf);
2145 free(orig_p);
2146 throw;
2147 }
2148 if (obj != nullptr) { append_object(retval, obj); }
2149 free(buf);
2150 continue;
2151 }
2152 obj = create_plain_text("$");
2153 s = p + 1;
2154 if (obj != nullptr) { append_object(retval, obj); }
2155
2156 } else if (*p == '\\' && *(p + 1) == '#') {
2157 strfold(p, 1);
2158 } else if (*p == '#') {
2159 char c;
2160 if ((remove_comment(p, &c) != 0u) && p >= orig_p && c == '\n') {
2161 /* if remove_comment removed a newline, we need to 'back up' with p */
2162 p--;
2163 }
2164 }
2165 p++;
2166 }
2167 obj = create_plain_text(s);
2168 if (obj != nullptr) { append_object(retval, obj); }
2169
2170 if (ifblock_stack_empty(&ifblock_opaque) == 0) {
2171 NORM_ERR("one or more $endif's are missing");
2172 }
2173
2174 free(orig_p);
2175 return 0;
2176 }
2177
2178 void extract_object_args_to_sub(struct text_object *obj, const char *args) {
2179 obj->sub =
2180 static_cast<struct text_object *>(malloc(sizeof(struct text_object)));
2181 memset(obj->sub, 0, sizeof(struct text_object));
2182 extract_variable_text_internal(obj->sub, args);
2183 }
2184
2185 /* Frees the list of text objects root points to. */
2186 void free_text_objects(struct text_object *root) {
2187 struct text_object *obj;
2188
2189 if ((root != nullptr) && (root->prev != nullptr)) {
2190 for (obj = root->prev; obj != nullptr; obj = root->prev) {
2191 root->prev = obj->prev;
2192 if (obj->callbacks.free != nullptr) { (*obj->callbacks.free)(obj); }
2193 free_text_objects(obj->sub);
2194 free_and_zero(obj->sub);
2195 free_and_zero(obj->special_data);
2196 delete obj->cb_handle;
2197
2198 free(obj);
2199 }
2200 }
2201 }
2202