1 /* -*- mode: c; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: t -*-
3 * Conky, a system monitor, based on torsmo
5 * Any original torsmo code is licensed under the BSD license
7 * All code written since the fork of torsmo is licensed under the GPL
9 * Please see COPYING for details
11 * Copyright (c) 2004, Hannu Saransaari and Lauri Hakkarainen
12 * Copyright (c) 2005-2009 Brenden Matthews, Philip Kovacs, et. al.
14 * All rights reserved.
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.
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/>.
28 * vim: ts=4 sw=4 noet ai cindent syntax=c
33 #include "text_object.h"
48 #include <sys/param.h>
49 #ifdef HAVE_SYS_INOTIFY_H
50 #include <sys/inotify.h>
51 #endif /* HAVE_SYS_INOTIFY_H */
54 #include <X11/Xutil.h>
56 #include <X11/extensions/Xdamage.h>
62 #include <sys/types.h>
64 #include <netinet/in.h>
86 #include "temphelper.h"
90 /* check for OS and include appropriate headers */
91 #if defined(__linux__)
93 #elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
95 #elif defined(__OpenBSD__)
99 #if defined(__FreeBSD_kernel__)
103 /* FIXME: apm_getinfo is unused here. maybe it's meant for common.c */
104 #if (defined(__FreeBSD__) || defined(__FreeBSD_kernel__) \
105 || defined(__OpenBSD__)) && (defined(i386) || defined(__i386__))
106 int apm_getinfo(int fd, apm_info_t aip);
107 char *get_apm_adapter(void);
108 char *get_apm_battery_life(void);
109 char *get_apm_battery_time(void);
117 #include "defconfig.h"
118 #include "conf_cookie.h"
122 #define S_ISSOCK(x) ((x & S_IFMT) == S_IFSOCK)
125 #define MAIL_FILE "$MAIL"
126 #define MAX_IF_BLOCK_DEPTH 5
128 //#define SIGNAL_BLOCKING
129 #undef SIGNAL_BLOCKING
131 /* debugging level, used by logging.h */
132 int global_debug_level = 0;
134 /* two strings for internal use */
135 static char *tmpstring1, *tmpstring2;
137 /* variables holding various config settings */
139 int format_human_readable;
146 int top_cpu, top_mem, top_time;
150 static unsigned int top_name_width = 15;
152 static int extra_newline;
153 enum x_initialiser_state x_initialised = NO;
154 static volatile int g_signal_pending;
155 /* Update interval */
156 double update_interval;
157 double update_interval_old;
158 double update_interval_bat;
159 void *global_cpu = NULL;
165 /* prototypes for internally used functions */
166 static void signal_handler(int);
167 static void print_version(void) __attribute__((noreturn));
168 static void reload_config(void);
169 static void generate_text_internal(char *, int, struct text_object,
170 struct information *);
171 static int extract_variable_text_internal(struct text_object *,
174 static void print_version(void)
176 printf(PACKAGE_NAME" "VERSION" compiled "BUILD_DATE" for "BUILD_ARCH"\n");
178 printf("\nCompiled in features:\n\n"
179 "System config file: "SYSTEM_CONFIG_FILE"\n"
180 "Package library path: "PACKAGE_LIBDIR"\n\n"
184 " * Xdamage extension\n"
185 # endif /* HAVE_XDAMAGE */
187 " * XDBE (double buffer extension)\n"
188 # endif /* HAVE_XDBE */
193 "\n Music detection:\n"
196 #endif /* AUDACIOUS */
212 #endif /* HAVE_OPENMP */
219 #ifdef TCP_PORT_MONITOR
221 #endif /* TCP_PORT_MONITOR */
224 #endif /* HAVE_CURL */
229 " * Weather (METAR)\n"
231 " * Weather (XOAP)\n"
236 #endif /* HAVE_IWLIB */
238 " * support for IBM/Lenovo notebooks\n"
248 #endif /* CONFIG_OUTPUT */
253 " * ALSA mixer support\n"
254 #endif /* MIXER_IS_ALSA */
264 #ifdef HAVE_LUA_CAIRO
266 #endif /* HAVE_LUA_CAIRO */
267 #ifdef HAVE_LUA_IMLIB2
270 #endif /* HAVE_LUA */
276 static const char *suffixes[] = { "B", "KiB", "MiB", "GiB", "TiB", "PiB", "" };
281 static void X11_create_window(void);
282 static void X11_initialisation(void);
284 struct _x11_stuff_s {
288 XserverRegion region2, part;
289 int event_base, error_base;
295 static int text_start_x, text_start_y; /* text start position in window */
296 static int text_width, text_height;
311 /* display to connect to */
312 static char *disp = NULL;
316 /* struct that has all info to be shared between
317 * instances of the same text object */
318 struct information info;
320 /* path to config file */
321 char *current_config;
323 /* set to 1 if you want all text to be in uppercase */
324 static unsigned int stuff_in_uppercase;
326 /* Run how many times? */
327 static unsigned long total_run_times;
330 static int fork_to_background;
332 static int cpu_avg_samples, net_avg_samples, diskio_avg_samples;
334 /* filenames for output */
335 char *overwrite_file = NULL; FILE *overwrite_fpointer = NULL;
336 char *append_file = NULL; FILE *append_fpointer = NULL;
340 static int show_graph_scale;
341 static int show_graph_range;
343 /* Position on the screen */
344 static int text_alignment;
345 static int gap_x, gap_y;
348 static int draw_borders;
349 static int draw_graph_borders;
350 static int stippled_borders;
352 static int draw_shades, draw_outline;
354 static long default_fg_color, default_bg_color, default_out_color;
356 /* create own window or draw stuff to root? */
357 static int set_transparent = 0;
360 static int own_window = 0;
361 static int background_colour = 0;
363 /* fixed size/pos is set if wm/user changes them */
364 static int fixed_size = 0, fixed_pos = 0;
367 static int minimum_width, minimum_height;
368 static int maximum_width;
373 static int sensor_device;
376 static long color0, color1, color2, color3, color4, color5, color6, color7,
379 #define MAX_TEMPLATES 10
380 static char *template[MAX_TEMPLATES];
382 /* maximum size of config TEXT buffer, i.e. below TEXT line. */
383 unsigned int max_user_text;
385 /* maximum size of individual text buffers, ie $exec buffer size */
386 unsigned int text_buffer_size = DEFAULT_TEXT_BUFFER_SIZE;
389 #define CODEPAGE_LENGTH 20
391 long iconv_count = 0;
392 char iconv_converting;
393 static iconv_t **iconv_cd = 0;
395 int register_iconv(iconv_t *new_iconv)
397 iconv_cd = realloc(iconv_cd, sizeof(iconv_t *) * (iconv_count + 1));
399 CRIT_ERR(NULL, NULL, "Out of memory");
401 iconv_cd[iconv_count] = malloc(sizeof(iconv_t));
402 if (!iconv_cd[iconv_count]) {
403 CRIT_ERR(NULL, NULL, "Out of memory");
405 memcpy(iconv_cd[iconv_count], new_iconv, sizeof(iconv_t));
410 void free_iconv(void)
415 for (i = 0; i < iconv_count; i++) {
417 iconv_close(*iconv_cd[i]);
431 /* no buffers in used memory? */
434 /* pad percentages to decimals? */
435 static int pad_percents = 0;
437 static char *global_text = 0;
438 long global_text_lines;
440 static int total_updates;
441 static int updatereset;
443 int check_contains(char *f, char *s)
446 FILE *where = open_file(f, 0);
451 while (fgets(buf1, 256, where)) {
452 if (strstr(buf1, s)) {
459 NORM_ERR("Could not open the file");
464 #define SECRIT_MULTILINE_CHAR '\x02'
468 static inline int calc_text_width(const char *s, int l)
470 if ((output_methods & TO_X) == 0) {
478 XftTextExtentsUtf8(display, fonts[selected_font].xftfont,
479 (const FcChar8 *) s, l, &gi);
481 XftTextExtents8(display, fonts[selected_font].xftfont,
482 (const FcChar8 *) s, l, &gi);
488 return XTextWidth(fonts[selected_font].font, s, l);
493 /* formatted text to render on screen, generated in generate_text(),
494 * drawn in draw_stuff() */
496 static char *text_buffer;
498 /* quite boring functions */
500 static inline void for_each_line(char *b, int f(char *, int))
503 int special_index = 0; /* specials index */
505 for (ps = b, pe = b; *pe; pe++) {
508 special_index = f(ps, special_index);
515 f(ps, special_index);
519 static void convert_escapes(char *buf)
521 char *p = buf, *s = buf;
528 } else if (*s == '\\') {
539 /* Prints anything normally printed with snprintf according to the current value
540 * of use_spacer. Actually slightly more flexible than snprintf, as you can
541 * safely specify the destination buffer as one of your inputs. */
542 int spaced_print(char *buf, int size, const char *format, int width, ...)
551 tempbuf = malloc(size * sizeof(char));
553 // Passes the varargs along to vsnprintf
554 va_start(argp, width);
555 vsnprintf(tempbuf, size, format, argp);
558 switch (use_spacer) {
560 len = snprintf(buf, size, "%s", tempbuf);
563 len = snprintf(buf, size, "%*s", width, tempbuf);
566 len = snprintf(buf, size, "%-*s", width, tempbuf);
573 /* print percentage values
575 * - i.e., unsigned values between 0 and 100
576 * - respect the value of pad_percents */
577 static int percent_print(char *buf, int size, unsigned value)
579 return spaced_print(buf, size, "%u", pad_percents, value);
582 /* converts from bytes to human readable format (K, M, G, T)
584 * The algorithm always divides by 1024, as unit-conversion of byte
585 * counts suggests. But for output length determination we need to
586 * compare with 1000 here, as we print in decimal form. */
587 static void human_readable(long long num, char *buf, int size)
589 const char **suffix = suffixes;
595 /* Possibly just output as usual, for example for stdout usage */
596 if (!format_human_readable) {
597 spaced_print(buf, size, "%d", 6, round_to_int(num));
608 if (llabs(num) < 1000LL) {
609 spaced_print(buf, size, format, width, 0, (float)num, *suffix);
613 while (llabs(num / 1024) >= 1000LL && **(suffix + 2)) {
621 /* fnum should now be < 1000, so looks like 'AAA.BBBBB'
623 * The goal is to always have a significance of 3, by
624 * adjusting the decimal part of the number. Sample output:
628 * so the point of alignment resides between number and unit. The
629 * upside of this is that there is minimal padding necessary, though
630 * there should be a way to make alignment take place at the decimal
631 * dot (then with fixed width decimal part).
633 * Note the repdigits below: when given a precision value, printf()
634 * rounds the float to it, not just cuts off the remaining digits. So
635 * e.g. 99.95 with a precision of 1 gets 100.0, which again should be
636 * printed with a precision of 0. Yay. */
638 precision = 0; /* print 100-999 without decimal part */
640 precision = 1; /* print 10-99 with one decimal place */
642 precision = 2; /* print 0-9 with two decimal places */
644 spaced_print(buf, size, format, width, precision, fnum, *suffix);
647 /* global object list root element */
648 static struct text_object global_root_object;
650 //our own implementation of popen, the difference : the value of 'childpid' will be filled with
651 //the pid of the running 'command'. This is useful if want to kill it when it hangs while reading
652 //or writing to it. We have to kill it because pclose will wait until the process dies by itself
653 FILE* pid_popen(const char *command, const char *mode, pid_t *child) {
655 int parentend, childend;
657 //by running pipe after the strcmp's we make sure that we don't have to create a pipe
658 //and close the ends if mode is something illegal
659 if(strcmp(mode, "r") == 0) {
660 if(pipe(ends) != 0) {
665 } else if(strcmp(mode, "w") == 0) {
666 if(pipe(ends) != 0) {
679 } else if(*child > 0) {
681 waitpid(*child, NULL, 0);
683 //don't read from both stdin and pipe or write to both stdout and pipe
684 if(childend == ends[0]) {
689 dup(childend); //by dupping childend, the returned fd will have close-on-exec turned off
690 execl("/bin/sh", "sh", "-c", command, (char *) NULL);
691 _exit(EXIT_FAILURE); //child should die here, (normally execl will take care of this but it can fail)
693 return fdopen(parentend, mode);
696 static inline void read_exec(const char *data, char *buf, const int size)
700 alarm(update_interval);
701 fp = pid_popen(data, "r", &childpid);
705 length = fread(buf, 1, size, fp);
708 if (length > 0 && buf[length - 1] == '\n') {
709 buf[length - 1] = '\0';
717 void *threaded_exec(void *) __attribute__((noreturn));
719 void *threaded_exec(void *arg)
722 struct text_object *obj = (struct text_object *)arg;
725 buff = malloc(text_buffer_size);
726 read_exec(obj->data.texeci.cmd, buff,
735 timed_thread_lock(obj->data.texeci.p_timed_thread);
736 strncpy(obj->data.texeci.buffer, buff, text_buffer_size);
737 timed_thread_unlock(obj->data.texeci.p_timed_thread);
739 if (timed_thread_test(obj->data.texeci.p_timed_thread, 0)) {
740 timed_thread_exit(obj->data.texeci.p_timed_thread);
746 static struct text_object *new_text_object_internal(void)
748 struct text_object *obj = malloc(sizeof(struct text_object));
749 memset(obj, 0, sizeof(struct text_object));
754 * Frees the list of text objects root points to. When internal = 1, it won't
755 * free global objects.
757 static void free_text_objects(struct text_object *root, int internal)
759 struct text_object *obj;
765 #define data obj->data
766 for (obj = root->prev; obj; obj = root->prev) {
767 root->prev = obj->prev;
773 #endif /* !__OpenBSD__ */
778 close(data.sysfs.fd);
780 #endif /* __linux__ */
782 free(data.read_tcp.host);
789 free(data.tztime.tz);
790 free(data.tztime.fmt);
793 free(data.mboxscan.args);
794 free(data.mboxscan.output);
799 case OBJ_unseen_mails:
800 case OBJ_flagged_mails:
801 case OBJ_unflagged_mails:
802 case OBJ_forwarded_mails:
803 case OBJ_unforwarded_mails:
804 case OBJ_replied_mails:
805 case OBJ_unreplied_mails:
806 case OBJ_draft_mails:
807 case OBJ_trashed_mails:
808 free(data.local_mail.mbox);
810 case OBJ_imap_unseen:
815 case OBJ_imap_messages:
820 case OBJ_pop3_unseen:
832 free_text_objects(obj->sub, 1);
835 case OBJ_if_existing:
838 free(data.ifblock.s);
839 free(data.ifblock.str);
843 free(data.headtail.logfile);
844 if(data.headtail.buffer) {
845 free(data.headtail.buffer);
862 case OBJ_iconv_start:
867 case OBJ_disk_protect:
871 free(data.ifblock.s);
872 free(data.ifblock.str);
875 if (info.gw_info.iface) {
876 free(info.gw_info.iface);
877 info.gw_info.iface = 0;
879 if (info.gw_info.ip) {
880 free(info.gw_info.ip);
884 case OBJ_ioscheduler:
889 #if (defined(__FreeBSD__) || defined(__linux__))
891 free(data.ifblock.s);
892 free(data.ifblock.str);
896 case OBJ_xmms2_artist:
897 if (info.xmms2.artist) {
898 free(info.xmms2.artist);
899 info.xmms2.artist = 0;
902 case OBJ_xmms2_album:
903 if (info.xmms2.album) {
904 free(info.xmms2.album);
905 info.xmms2.album = 0;
908 case OBJ_xmms2_title:
909 if (info.xmms2.title) {
910 free(info.xmms2.title);
911 info.xmms2.title = 0;
914 case OBJ_xmms2_genre:
915 if (info.xmms2.genre) {
916 free(info.xmms2.genre);
917 info.xmms2.genre = 0;
920 case OBJ_xmms2_comment:
921 if (info.xmms2.comment) {
922 free(info.xmms2.comment);
923 info.xmms2.comment = 0;
927 if (info.xmms2.url) {
928 free(info.xmms2.url);
933 if (info.xmms2.date) {
934 free(info.xmms2.date);
938 case OBJ_xmms2_status:
939 if (info.xmms2.status) {
940 free(info.xmms2.status);
941 info.xmms2.status = 0;
944 case OBJ_xmms2_playlist:
945 if (info.xmms2.playlist) {
946 free(info.xmms2.playlist);
947 info.xmms2.playlist = 0;
950 case OBJ_xmms2_smart:
951 if (info.xmms2.artist) {
952 free(info.xmms2.artist);
953 info.xmms2.artist = 0;
955 if (info.xmms2.title) {
956 free(info.xmms2.title);
957 info.xmms2.title = 0;
959 if (info.xmms2.url) {
960 free(info.xmms2.url);
967 case OBJ_bmpx_artist:
971 case OBJ_bmpx_bitrate:
986 free(data.rss.action);
991 free(data.weather.uri);
992 free(data.weather.data_type);
1005 #endif /* HAVE_LUA */
1012 case OBJ_battery_short:
1015 case OBJ_battery_time:
1018 #endif /* !__OpenBSD__ */
1023 case OBJ_execigraph:
1024 case OBJ_execigauge:
1026 free(data.execi.cmd);
1027 free(data.execi.buffer);
1030 if (data.texeci.p_timed_thread) timed_thread_destroy(data.texeci.p_timed_thread, &data.texeci.p_timed_thread);
1031 free(data.texeci.cmd);
1032 free(data.texeci.buffer);
1034 case OBJ_nameserver:
1043 if (info.first_process && !internal) {
1044 free_all_processes();
1045 info.first_process = NULL;
1047 if (data.top.s) free(data.top.s);
1051 free(data.hddtemp.dev);
1052 free(data.hddtemp.addr);
1053 if (data.hddtemp.temp)
1054 free(data.hddtemp.temp);
1056 #endif /* HDDTEMP */
1057 case OBJ_entropy_avail:
1058 case OBJ_entropy_perc:
1059 case OBJ_entropy_poolsize:
1060 case OBJ_entropy_bar:
1062 case OBJ_user_names:
1063 if (info.users.names) {
1064 free(info.users.names);
1065 info.users.names = 0;
1068 case OBJ_user_terms:
1069 if (info.users.terms) {
1070 free(info.users.terms);
1071 info.users.terms = 0;
1074 case OBJ_user_times:
1075 if (info.users.times) {
1076 free(info.users.times);
1077 info.users.times = 0;
1082 case OBJ_smapi_bat_perc:
1083 case OBJ_smapi_bat_temp:
1084 case OBJ_smapi_bat_power:
1087 case OBJ_if_smapi_bat_installed:
1088 free(data.ifblock.s);
1089 free(data.ifblock.str);
1098 case OBJ_mpd_artist:
1100 case OBJ_mpd_random:
1101 case OBJ_mpd_repeat:
1103 case OBJ_mpd_bitrate:
1104 case OBJ_mpd_status:
1106 case OBJ_mpd_elapsed:
1107 case OBJ_mpd_length:
1111 case OBJ_mpd_percent:
1113 case OBJ_if_mpd_playing:
1121 case OBJ_moc_artist:
1124 case OBJ_moc_totaltime:
1125 case OBJ_moc_timeleft:
1126 case OBJ_moc_curtime:
1127 case OBJ_moc_bitrate:
1136 free_text_objects(obj->sub, 1);
1141 free(data.scroll.text);
1142 free_text_objects(obj->sub, 1);
1146 free(data.combine.left);
1147 free(data.combine.seperation);
1148 free(data.combine.right);
1149 free_text_objects(obj->sub, 1);
1154 case OBJ_apcupsd_name:
1155 case OBJ_apcupsd_model:
1156 case OBJ_apcupsd_upsmode:
1157 case OBJ_apcupsd_cable:
1158 case OBJ_apcupsd_status:
1159 case OBJ_apcupsd_linev:
1160 case OBJ_apcupsd_load:
1161 case OBJ_apcupsd_loadbar:
1163 case OBJ_apcupsd_loadgraph:
1164 case OBJ_apcupsd_loadgauge:
1166 case OBJ_apcupsd_charge:
1167 case OBJ_apcupsd_timeleft:
1168 case OBJ_apcupsd_temp:
1169 case OBJ_apcupsd_lastxfer:
1171 #endif /* APCUPSD */
1174 case OBJ_desktop_number:
1175 case OBJ_desktop_name:
1176 if(info.x11.desktop.name) {
1177 free(info.x11.desktop.name);
1178 info.x11.desktop.name = NULL;
1180 if(info.x11.desktop.all_names) {
1181 free(info.x11.desktop.all_names);
1182 info.x11.desktop.all_names = NULL;
1193 void scan_mixer_bar(const char *arg, int *a, int *w, int *h)
1198 if (arg && sscanf(arg, "%63s %n", buf1, &n) >= 1) {
1199 *a = mixer_init(buf1);
1200 scan_bar(arg + n, w, h);
1202 *a = mixer_init(NULL);
1203 scan_bar(arg, w, h);
1208 /* strip a leading /dev/ if any, following symlinks first
1210 * BEWARE: this function returns a pointer to static content
1211 * which gets overwritten in consecutive calls. I.e.:
1212 * this function is NOT reentrant.
1214 static const char *dev_name(const char *path)
1216 static char buf[255]; /* should be enough for pathnames */
1222 #define DEV_NAME(x) \
1223 x != NULL && strlen(x) > 5 && strncmp(x, "/dev/", 5) == 0 ? x + 5 : x
1224 if ((buflen = readlink(path, buf, 254)) == -1)
1225 return DEV_NAME(path);
1227 return DEV_NAME(buf);
1231 static int parse_top_args(const char *s, const char *arg, struct text_object *obj)
1236 if (obj->data.top.was_parsed) {
1239 obj->data.top.was_parsed = 1;
1241 if (arg && !obj->data.top.s) {
1242 obj->data.top.s = strndup(arg, text_buffer_size);
1245 need_mask |= (1 << INFO_TOP);
1248 obj->type = OBJ_top;
1250 } else if (strcmp(&s[3], "_mem") == EQUAL) {
1251 obj->type = OBJ_top_mem;
1253 } else if (strcmp(&s[3], "_time") == EQUAL) {
1254 obj->type = OBJ_top_time;
1257 } else if (strcmp(&s[3], "_io") == EQUAL) {
1258 obj->type = OBJ_top_io;
1263 NORM_ERR("Must be top, top_mem, top_time or top_io");
1265 NORM_ERR("Must be top, top_mem or top_time");
1271 NORM_ERR("top needs arguments");
1275 if (sscanf(arg, "%63s %i", buf, &n) == 2) {
1276 if (strcmp(buf, "name") == EQUAL) {
1277 obj->data.top.type = TOP_NAME;
1278 } else if (strcmp(buf, "cpu") == EQUAL) {
1279 obj->data.top.type = TOP_CPU;
1280 } else if (strcmp(buf, "pid") == EQUAL) {
1281 obj->data.top.type = TOP_PID;
1282 } else if (strcmp(buf, "mem") == EQUAL) {
1283 obj->data.top.type = TOP_MEM;
1284 } else if (strcmp(buf, "time") == EQUAL) {
1285 obj->data.top.type = TOP_TIME;
1286 } else if (strcmp(buf, "mem_res") == EQUAL) {
1287 obj->data.top.type = TOP_MEM_RES;
1288 } else if (strcmp(buf, "mem_vsize") == EQUAL) {
1289 obj->data.top.type = TOP_MEM_VSIZE;
1291 } else if (strcmp(buf, "io_read") == EQUAL) {
1292 obj->data.top.type = TOP_READ_BYTES;
1293 } else if (strcmp(buf, "io_write") == EQUAL) {
1294 obj->data.top.type = TOP_WRITE_BYTES;
1295 } else if (strcmp(buf, "io_perc") == EQUAL) {
1296 obj->data.top.type = TOP_IO_PERC;
1299 NORM_ERR("invalid type arg for top");
1301 NORM_ERR("must be one of: name, cpu, pid, mem, time, mem_res, mem_vsize, "
1302 "io_read, io_write, io_perc");
1304 NORM_ERR("must be one of: name, cpu, pid, mem, time, mem_res, mem_vsize");
1308 if (n < 1 || n > 10) {
1309 NORM_ERR("invalid num arg for top. Must be between 1 and 10.");
1312 obj->data.top.num = n - 1;
1315 NORM_ERR("invalid argument count for top");
1321 long current_text_color;
1325 struct conftree* horz_next;
1326 struct conftree* vert_next;
1327 struct conftree* back;
1330 //adds newstring to to the tree unless you can already see it when travelling back.
1331 //if it's possible to attach it then it returns a pointer to the leaf, else it returns NULL
1332 struct conftree* conftree_add(struct conftree* previous, const char* newstring) {
1333 struct conftree* node;
1334 struct conftree* node2;
1336 for(node = previous; node != NULL; node = node->back) {
1337 if(strcmp(node->string, newstring) == 0) {
1341 node = malloc(sizeof(struct conftree));
1342 if (previous != NULL) {
1343 if(previous->vert_next == NULL) {
1344 previous->vert_next = node;
1346 for(node2 = previous->vert_next; node2->horz_next != NULL; node2 = node2->horz_next ) { }
1347 node2->horz_next = node;
1350 node->string = strdup(newstring);
1351 node->horz_next = NULL;
1352 node->vert_next = NULL;
1353 node->back = previous;
1357 void conftree_empty(struct conftree* tree) {
1359 conftree_empty(tree->horz_next);
1360 conftree_empty(tree->vert_next);
1366 struct conftree *currentconffile;
1368 char load_config_file(const char *);
1370 /* construct_text_object() creates a new text_object */
1371 static struct text_object *construct_text_object(const char *s,
1372 const char *arg, long line, void **ifblock_opaque, void *free_at_crash)
1374 // struct text_object *obj = new_text_object();
1375 struct text_object *obj = new_text_object_internal();
1379 #define OBJ(a, n) if (strcmp(s, #a) == 0) { \
1380 obj->type = OBJ_##a; need_mask |= (1ULL << n); {
1381 #define OBJ_IF(a, n) if (strcmp(s, #a) == 0) { \
1382 obj->type = OBJ_##a; need_mask |= (1ULL << n); \
1383 obj_be_ifblock_if(ifblock_opaque, obj); {
1384 #define END } } else
1386 #define SIZE_DEFAULTS(arg) { \
1387 obj->a = default_##arg##_width; \
1388 obj->b = default_##arg##_height; \
1393 obj->type = OBJ_color;
1394 obj->data.l = get_x11_color(s);
1398 OBJ(freq, INFO_FREQ)
1401 obj->data.i = open_acpi_temperature(arg);
1402 END OBJ(acpiacadapter, 0)
1403 END OBJ(freq, INFO_FREQ)
1404 #endif /* !__OpenBSD__ */
1406 if (!arg || !isdigit(arg[0]) || strlen(arg) >= 2 || atoi(&arg[0]) == 0
1407 || (unsigned int) atoi(&arg[0]) > info.cpu_count) {
1408 obj->data.cpu_index = 1;
1409 /* NORM_ERR("freq: Invalid CPU number or you don't have that many CPUs! "
1410 "Displaying the clock for CPU 1."); */
1412 obj->data.cpu_index = atoi(&arg[0]);
1415 END OBJ(freq_g, INFO_FREQ)
1417 if (!arg || !isdigit(arg[0]) || strlen(arg) >= 2 || atoi(&arg[0]) == 0
1418 || (unsigned int) atoi(&arg[0]) > info.cpu_count) {
1419 obj->data.cpu_index = 1;
1420 /* NORM_ERR("freq_g: Invalid CPU number or you don't have that many "
1421 "CPUs! Displaying the clock for CPU 1."); */
1423 obj->data.cpu_index = atoi(&arg[0]);
1426 END OBJ(read_tcp, 0)
1428 obj->data.read_tcp.host = malloc(text_buffer_size);
1429 sscanf(arg, "%s", obj->data.read_tcp.host);
1430 sscanf(arg+strlen(obj->data.read_tcp.host), "%u", &(obj->data.read_tcp.port));
1431 if(obj->data.read_tcp.port == 0) {
1432 obj->data.read_tcp.port = atoi(obj->data.read_tcp.host);
1433 strcpy(obj->data.read_tcp.host,"localhost");
1435 obj->data.read_tcp.port = htons(obj->data.read_tcp.port);
1436 if(obj->data.read_tcp.port < 1 || obj->data.read_tcp.port > 65535) {
1437 CRIT_ERR(obj, free_at_crash, "read_tcp: Needs \"(host) port\" as argument(s)");
1440 CRIT_ERR(obj, free_at_crash, "read_tcp: Needs \"(host) port\" as argument(s)");
1442 #if defined(__linux__)
1443 END OBJ(voltage_mv, 0)
1445 if (!arg || !isdigit(arg[0]) || strlen(arg) >= 2 || atoi(&arg[0]) == 0
1446 || (unsigned int) atoi(&arg[0]) > info.cpu_count) {
1447 obj->data.cpu_index = 1;
1448 /* NORM_ERR("voltage_mv: Invalid CPU number or you don't have that many "
1449 "CPUs! Displaying voltage for CPU 1."); */
1451 obj->data.cpu_index = atoi(&arg[0]);
1454 END OBJ(voltage_v, 0)
1456 if (!arg || !isdigit(arg[0]) || strlen(arg) >= 2 || atoi(&arg[0]) == 0
1457 || (unsigned int) atoi(&arg[0]) > info.cpu_count) {
1458 obj->data.cpu_index = 1;
1459 /* NORM_ERR("voltage_v: Invalid CPU number or you don't have that many "
1460 "CPUs! Displaying voltage for CPU 1."); */
1462 obj->data.cpu_index = atoi(&arg[0]);
1467 END OBJ(wireless_essid, INFO_NET)
1469 obj->data.net = get_net_stat(arg, obj, free_at_crash);
1471 // default to DEFAULTNETDEV
1472 char *buf = strndup(DEFAULTNETDEV, text_buffer_size);
1473 obj->data.net = get_net_stat(buf, obj, free_at_crash);
1476 END OBJ(wireless_mode, INFO_NET)
1478 obj->data.net = get_net_stat(arg, obj, free_at_crash);
1480 // default to DEFAULTNETDEV
1481 char *buf = strndup(DEFAULTNETDEV, text_buffer_size);
1482 obj->data.net = get_net_stat(buf, obj, free_at_crash);
1485 END OBJ(wireless_bitrate, INFO_NET)
1487 obj->data.net = get_net_stat(arg, obj, free_at_crash);
1489 // default to DEFAULTNETDEV
1490 char *buf = strndup(DEFAULTNETDEV, text_buffer_size);
1491 obj->data.net = get_net_stat(buf, obj, free_at_crash);
1494 END OBJ(wireless_ap, INFO_NET)
1496 obj->data.net = get_net_stat(arg, obj, free_at_crash);
1498 // default to DEFAULTNETDEV
1499 char *buf = strndup(DEFAULTNETDEV, text_buffer_size);
1500 obj->data.net = get_net_stat(buf, obj, free_at_crash);
1503 END OBJ(wireless_link_qual, INFO_NET)
1505 obj->data.net = get_net_stat(arg, obj, free_at_crash);
1507 // default to DEFAULTNETDEV
1508 char *buf = strndup(DEFAULTNETDEV, text_buffer_size);
1509 obj->data.net = get_net_stat(buf, obj, free_at_crash);
1512 END OBJ(wireless_link_qual_max, INFO_NET)
1514 obj->data.net = get_net_stat(arg, obj, free_at_crash);
1516 // default to DEFAULTNETDEV
1517 char *buf = strndup(DEFAULTNETDEV, text_buffer_size);
1518 obj->data.net = get_net_stat(buf, obj, free_at_crash);
1521 END OBJ(wireless_link_qual_perc, INFO_NET)
1523 obj->data.net = get_net_stat(arg, obj, free_at_crash);
1525 // default to DEFAULTNETDEV
1526 char *buf = strndup(DEFAULTNETDEV, text_buffer_size);
1527 obj->data.net = get_net_stat(buf, obj, free_at_crash);
1530 END OBJ(wireless_link_bar, INFO_NET)
1533 arg = scan_bar(arg, &obj->a, &obj->b);
1534 obj->data.net = get_net_stat(arg, obj, free_at_crash);
1536 // default to DEFAULTNETDEV
1537 char *buf = strndup(DEFAULTNETDEV, text_buffer_size);
1538 obj->data.net = get_net_stat(buf, obj, free_at_crash);
1541 #endif /* HAVE_IWLIB */
1543 #endif /* __linux__ */
1551 sscanf(arg, "%63s", bat);
1553 strcpy(bat, "BAT0");
1555 obj->data.s = strndup(bat, text_buffer_size);
1556 END OBJ(battery_short, 0)
1560 sscanf(arg, "%63s", bat);
1562 strcpy(bat, "BAT0");
1564 obj->data.s = strndup(bat, text_buffer_size);
1565 END OBJ(battery_time, 0)
1569 sscanf(arg, "%63s", bat);
1571 strcpy(bat, "BAT0");
1573 obj->data.s = strndup(bat, text_buffer_size);
1574 END OBJ(battery_percent, 0)
1578 sscanf(arg, "%63s", bat);
1580 strcpy(bat, "BAT0");
1582 obj->data.s = strndup(bat, text_buffer_size);
1583 END OBJ(battery_bar, 0)
1588 arg = scan_bar(arg, &obj->a, &obj->b);
1589 sscanf(arg, "%63s", bat);
1591 strcpy(bat, "BAT0");
1593 obj->data.s = strndup(bat, text_buffer_size);
1594 #endif /* !__OpenBSD__ */
1596 #if defined(__linux__)
1597 END OBJ(disk_protect, 0)
1599 obj->data.s = strndup(dev_name(arg), text_buffer_size);
1601 CRIT_ERR(obj, free_at_crash, "disk_protect needs an argument");
1602 END OBJ(i8k_version, INFO_I8K)
1603 END OBJ(i8k_bios, INFO_I8K)
1604 END OBJ(i8k_serial, INFO_I8K)
1605 END OBJ(i8k_cpu_temp, INFO_I8K)
1606 END OBJ(i8k_left_fan_status, INFO_I8K)
1607 END OBJ(i8k_right_fan_status, INFO_I8K)
1608 END OBJ(i8k_left_fan_rpm, INFO_I8K)
1609 END OBJ(i8k_right_fan_rpm, INFO_I8K)
1610 END OBJ(i8k_ac_status, INFO_I8K)
1611 END OBJ(i8k_buttons_status, INFO_I8K)
1614 END OBJ(ibm_temps, 0)
1616 CRIT_ERR(obj, free_at_crash, "ibm_temps: needs an argument");
1618 if (!isdigit(arg[0]) || strlen(arg) >= 2 || atoi(&arg[0]) >= 8) {
1619 obj->data.sensor = 0;
1620 NORM_ERR("Invalid temperature sensor! Sensor number must be 0 to 7. "
1621 "Using 0 (CPU temp sensor).");
1623 obj->data.sensor = atoi(&arg[0]);
1624 END OBJ(ibm_volume, 0)
1625 END OBJ(ibm_brightness, 0)
1627 /* information from sony_laptop kernel module
1628 * /sys/devices/platform/sony-laptop */
1629 END OBJ(sony_fanspeed, 0)
1630 END OBJ_IF(if_gw, INFO_GW)
1631 END OBJ(ioscheduler, 0)
1633 CRIT_ERR(obj, free_at_crash, "get_ioscheduler needs an argument (e.g. hda)");
1636 obj->data.s = strndup(dev_name(arg), text_buffer_size);
1637 END OBJ(laptop_mode, 0)
1638 END OBJ(pb_battery, 0)
1639 if (arg && strcmp(arg, "status") == EQUAL) {
1640 obj->data.i = PB_BATT_STATUS;
1641 } else if (arg && strcmp(arg, "percent") == EQUAL) {
1642 obj->data.i = PB_BATT_PERCENT;
1643 } else if (arg && strcmp(arg, "time") == EQUAL) {
1644 obj->data.i = PB_BATT_TIME;
1646 NORM_ERR("pb_battery: needs one argument: status, percent or time");
1651 #endif /* __linux__ */
1652 #if (defined(__FreeBSD__) || defined(__linux__))
1653 END OBJ_IF(if_up, 0)
1655 NORM_ERR("if_up needs an argument");
1656 obj->data.ifblock.s = 0;
1658 obj->data.ifblock.s = strndup(arg, text_buffer_size);
1661 #if defined(__OpenBSD__)
1662 END OBJ(obsd_sensors_temp, 0)
1664 CRIT_ERR(obj, free_at_crash, "obsd_sensors_temp: needs an argument");
1666 if (!isdigit(arg[0]) || atoi(&arg[0]) < 0
1667 || atoi(&arg[0]) > OBSD_MAX_SENSORS - 1) {
1668 obj->data.sensor = 0;
1669 NORM_ERR("Invalid temperature sensor number!");
1671 obj->data.sensor = atoi(&arg[0]);
1672 END OBJ(obsd_sensors_fan, 0)
1674 CRIT_ERR(obj, free_at_crash, "obsd_sensors_fan: needs 2 arguments (device and sensor "
1677 if (!isdigit(arg[0]) || atoi(&arg[0]) < 0
1678 || atoi(&arg[0]) > OBSD_MAX_SENSORS - 1) {
1679 obj->data.sensor = 0;
1680 NORM_ERR("Invalid fan sensor number!");
1682 obj->data.sensor = atoi(&arg[0]);
1683 END OBJ(obsd_sensors_volt, 0)
1685 CRIT_ERR(obj, free_at_crash, "obsd_sensors_volt: needs 2 arguments (device and sensor "
1688 if (!isdigit(arg[0]) || atoi(&arg[0]) < 0
1689 || atoi(&arg[0]) > OBSD_MAX_SENSORS - 1) {
1690 obj->data.sensor = 0;
1691 NORM_ERR("Invalid voltage sensor number!");
1693 obj->data.sensor = atoi(&arg[0]);
1694 END OBJ(obsd_vendor, 0)
1695 END OBJ(obsd_product, 0)
1696 #endif /* __OpenBSD__ */
1697 END OBJ(buffers, INFO_BUFFERS)
1698 END OBJ(cached, INFO_BUFFERS)
1699 #define SCAN_CPU(__arg, __var) { \
1701 if (__arg && sscanf(__arg, " cpu%u %n", &__var, &__offset) > 0) \
1702 __arg += __offset; \
1706 END OBJ(cpu, INFO_CPU)
1707 SCAN_CPU(arg, obj->data.cpu_index);
1708 DBGP2("Adding $cpu for CPU %d", obj->data.cpu_index);
1710 END OBJ(cpugauge, INFO_CPU)
1711 SIZE_DEFAULTS(gauge);
1712 SCAN_CPU(arg, obj->data.cpu_index);
1713 scan_gauge(arg, &obj->a, &obj->b);
1714 DBGP2("Adding $cpugauge for CPU %d", obj->data.cpu_index);
1716 END OBJ(cpubar, INFO_CPU)
1718 SCAN_CPU(arg, obj->data.cpu_index);
1719 scan_bar(arg, &obj->a, &obj->b);
1720 DBGP2("Adding $cpubar for CPU %d", obj->data.cpu_index);
1722 END OBJ(cpugraph, INFO_CPU)
1724 SIZE_DEFAULTS(graph);
1725 SCAN_CPU(arg, obj->data.cpu_index);
1726 buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
1727 &obj->e, &obj->char_a, &obj->char_b);
1728 DBGP2("Adding $cpugraph for CPU %d", obj->data.cpu_index);
1730 END OBJ(loadgraph, INFO_LOADAVG)
1732 SIZE_DEFAULTS(graph);
1733 buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
1734 &obj->e, &obj->char_a, &obj->char_b);
1738 r = sscanf(arg, "%d", &a);
1740 obj->data.loadavg[0] = (r >= 1) ? (unsigned char) a : 0;
1744 END OBJ(diskio, INFO_DISKIO)
1745 obj->data.diskio = prepare_diskio_stat(dev_name(arg));
1746 END OBJ(diskio_read, INFO_DISKIO)
1747 obj->data.diskio = prepare_diskio_stat(dev_name(arg));
1748 END OBJ(diskio_write, INFO_DISKIO)
1749 obj->data.diskio = prepare_diskio_stat(dev_name(arg));
1751 END OBJ(diskiograph, INFO_DISKIO)
1753 SIZE_DEFAULTS(graph);
1754 buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
1755 &obj->e, &obj->char_a, &obj->char_b);
1757 obj->data.diskio = prepare_diskio_stat(dev_name(buf));
1759 END OBJ(diskiograph_read, INFO_DISKIO)
1761 SIZE_DEFAULTS(graph);
1762 buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
1763 &obj->e, &obj->char_a, &obj->char_b);
1765 obj->data.diskio = prepare_diskio_stat(dev_name(buf));
1767 END OBJ(diskiograph_write, INFO_DISKIO)
1769 SIZE_DEFAULTS(graph);
1770 buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
1771 &obj->e, &obj->char_a, &obj->char_b);
1773 obj->data.diskio = prepare_diskio_stat(dev_name(buf));
1778 if (output_methods & TO_X) {
1779 obj->data.l = arg ? get_x11_color(arg) : default_fg_color;
1780 current_text_color = obj->data.l;
1784 obj->data.l = color0;
1785 current_text_color = obj->data.l;
1787 obj->data.l = color1;
1788 current_text_color = obj->data.l;
1790 obj->data.l = color2;
1791 current_text_color = obj->data.l;
1793 obj->data.l = color3;
1794 current_text_color = obj->data.l;
1796 obj->data.l = color4;
1797 current_text_color = obj->data.l;
1799 obj->data.l = color5;
1800 current_text_color = obj->data.l;
1802 obj->data.l = color6;
1803 current_text_color = obj->data.l;
1805 obj->data.l = color7;
1806 current_text_color = obj->data.l;
1808 obj->data.l = color8;
1809 current_text_color = obj->data.l;
1811 obj->data.l = color9;
1812 current_text_color = obj->data.l;
1815 obj->data.s = scan_font(arg);
1817 END OBJ(conky_version, 0)
1818 END OBJ(conky_build_date, 0)
1819 END OBJ(conky_build_arch, 0)
1820 END OBJ(downspeed, INFO_NET)
1822 obj->data.net = get_net_stat(arg, obj, free_at_crash);
1824 // default to DEFAULTNETDEV
1825 char *buf = strndup(DEFAULTNETDEV, text_buffer_size);
1826 obj->data.net = get_net_stat(buf, obj, free_at_crash);
1829 END OBJ(downspeedf, INFO_NET)
1831 obj->data.net = get_net_stat(arg, obj, free_at_crash);
1833 // default to DEFAULTNETDEV
1834 char *buf = strndup(DEFAULTNETDEV, text_buffer_size);
1835 obj->data.net = get_net_stat(buf, obj, free_at_crash);
1839 END OBJ(downspeedgraph, INFO_NET)
1841 SIZE_DEFAULTS(graph);
1842 buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
1843 &obj->e, &obj->char_a, &obj->char_b);
1845 // default to DEFAULTNETDEV
1846 buf = strndup(buf ? buf : DEFAULTNETDEV, text_buffer_size);
1847 obj->data.net = get_net_stat(buf, obj, free_at_crash);
1851 obj_be_ifblock_else(ifblock_opaque, obj);
1853 obj_be_ifblock_endif(ifblock_opaque, obj);
1855 obj->data.s = strndup(arg ? arg : "", text_buffer_size);
1857 obj->data.s = strndup(arg ? arg : "", text_buffer_size);
1859 obj->data.s = strndup(arg ? arg : "", text_buffer_size);
1861 obj->data.s = strndup(arg ? arg : "", text_buffer_size);
1864 obj->data.s = strndup(arg ? arg : "", text_buffer_size);
1866 END OBJ(execgauge, 0)
1867 SIZE_DEFAULTS(gauge);
1868 obj->data.s = strndup(arg ? arg : "", text_buffer_size);
1869 END OBJ(execgraph, 0)
1870 SIZE_DEFAULTS(graph);
1871 obj->data.s = strndup(arg ? arg : "", text_buffer_size);
1873 END OBJ(execibar, 0)
1877 if (!arg || sscanf(arg, "%f %n", &obj->data.execi.interval, &n) <= 0) {
1880 NORM_ERR("${execibar <interval> command}");
1881 obj->type = OBJ_text;
1882 snprintf(buf, 256, "${%s}", s);
1883 obj->data.s = strndup(buf, text_buffer_size);
1885 obj->data.execi.cmd = strndup(arg + n, text_buffer_size);
1888 END OBJ(execigraph, 0)
1890 SIZE_DEFAULTS(graph);
1892 if (!arg || sscanf(arg, "%f %n", &obj->data.execi.interval, &n) <= 0) {
1895 NORM_ERR("${execigraph <interval> command}");
1896 obj->type = OBJ_text;
1897 snprintf(buf, 256, "${%s}", s);
1898 obj->data.s = strndup(buf, text_buffer_size);
1900 obj->data.execi.cmd = strndup(arg + n, text_buffer_size);
1902 END OBJ(execigauge, 0)
1904 SIZE_DEFAULTS(gauge);
1906 if (!arg || sscanf(arg, "%f %n", &obj->data.execi.interval, &n) <= 0) {
1909 NORM_ERR("${execigauge <interval> command}");
1910 obj->type = OBJ_text;
1911 snprintf(buf, 256, "${%s}", s);
1912 obj->data.s = strndup(buf, text_buffer_size);
1914 obj->data.execi.cmd = strndup(arg + n, text_buffer_size);
1920 if (!arg || sscanf(arg, "%f %n", &obj->data.execi.interval, &n) <= 0) {
1923 NORM_ERR("${execi <interval> command}");
1924 obj->type = OBJ_text;
1925 snprintf(buf, 256, "${%s}", s);
1926 obj->data.s = strndup(buf, text_buffer_size);
1928 obj->data.execi.cmd = strndup(arg + n, text_buffer_size);
1929 obj->data.execi.buffer = malloc(text_buffer_size);
1934 if (!arg || sscanf(arg, "%f %n", &obj->data.execi.interval, &n) <= 0) {
1937 NORM_ERR("${execi <interval> command}");
1938 obj->type = OBJ_text;
1939 snprintf(buf, 256, "${%s}", s);
1940 obj->data.s = strndup(buf, text_buffer_size);
1942 obj->data.execi.cmd = strndup(arg + n, text_buffer_size);
1943 obj->data.execi.buffer = malloc(text_buffer_size);
1948 if (!arg || sscanf(arg, "%f %n", &obj->data.texeci.interval, &n) <= 0) {
1951 NORM_ERR("${texeci <interval> command}");
1952 obj->type = OBJ_text;
1953 snprintf(buf, 256, "${%s}", s);
1954 obj->data.s = strndup(buf, text_buffer_size);
1956 obj->data.texeci.cmd = strndup(arg + n, text_buffer_size);
1957 obj->data.texeci.buffer = malloc(text_buffer_size);
1959 obj->data.texeci.p_timed_thread = NULL;
1960 END OBJ(pre_exec, 0)
1961 obj->type = OBJ_text;
1965 read_exec(arg, buf, sizeof(buf));
1966 obj->data.s = strndup(buf, text_buffer_size);
1968 obj->data.s = strndup("", text_buffer_size);
1970 END OBJ(fs_bar, INFO_FS)
1972 arg = scan_bar(arg, &obj->data.fsbar.w, &obj->data.fsbar.h);
1974 while (isspace(*arg)) {
1983 obj->data.fsbar.fs = prepare_fs_stat(arg);
1984 END OBJ(fs_bar_free, INFO_FS)
1986 arg = scan_bar(arg, &obj->data.fsbar.w, &obj->data.fsbar.h);
1988 while (isspace(*arg)) {
1998 obj->data.fsbar.fs = prepare_fs_stat(arg);
1999 END OBJ(fs_free, INFO_FS)
2003 obj->data.fs = prepare_fs_stat(arg);
2004 END OBJ(fs_used_perc, INFO_FS)
2008 obj->data.fs = prepare_fs_stat(arg);
2009 END OBJ(fs_free_perc, INFO_FS)
2013 obj->data.fs = prepare_fs_stat(arg);
2014 END OBJ(fs_size, INFO_FS)
2018 obj->data.fs = prepare_fs_stat(arg);
2019 END OBJ(fs_type, INFO_FS)
2023 obj->data.fs = prepare_fs_stat(arg);
2024 END OBJ(fs_used, INFO_FS)
2028 obj->data.fs = prepare_fs_stat(arg);
2030 obj->data.i = arg ? atoi(arg) : 1;
2031 END OBJ(nameserver, INFO_DNS)
2032 obj->data.i = arg ? atoi(arg) : 0;
2034 obj->data.i = arg ? atoi(arg) : 1;
2036 obj->data.i = arg ? atoi(arg) : 1;
2040 NORM_ERR("goto needs arguments");
2041 obj->type = OBJ_text;
2042 obj->data.s = strndup("${goto}", text_buffer_size);
2046 obj->data.i = atoi(arg);
2052 if (sscanf(arg, "%d %d", &a, &b) != 2) {
2053 sscanf(arg, "%d", &b);
2059 obj->data.pair.a = a;
2060 obj->data.pair.b = b;
2063 END OBJ(i2c, INFO_SYSFS)
2064 char buf1[64], buf2[64];
2065 float factor, offset;
2069 NORM_ERR("i2c needs arguments");
2070 obj->type = OBJ_text;
2071 // obj->data.s = strndup("${i2c}", text_buffer_size);
2075 #define HWMON_RESET() {\
2080 if (sscanf(arg, "%63s %d %f %f", buf2, &n, &factor, &offset) == 4) found = 1; else HWMON_RESET();
2081 if (!found && sscanf(arg, "%63s %63s %d %f %f", buf1, buf2, &n, &factor, &offset) == 5) found = 1; else if (!found) HWMON_RESET();
2082 if (!found && sscanf(arg, "%63s %63s %d", buf1, buf2, &n) == 3) found = 1; else if (!found) HWMON_RESET();
2083 if (!found && sscanf(arg, "%63s %d", buf2, &n) == 2) found = 1; else if (!found) HWMON_RESET();
2086 NORM_ERR("i2c failed to parse arguments");
2087 obj->type = OBJ_text;
2090 DBGP("parsed i2c args: '%s' '%s' %d %f %f\n", buf1, buf2, n, factor, offset);
2091 obj->data.sysfs.fd = open_i2c_sensor((*buf1) ? buf1 : 0, buf2, n,
2092 &obj->data.sysfs.arg, obj->data.sysfs.devtype);
2093 strncpy(obj->data.sysfs.type, buf2, 63);
2094 obj->data.sysfs.factor = factor;
2095 obj->data.sysfs.offset = offset;
2097 END OBJ(platform, INFO_SYSFS)
2098 char buf1[64], buf2[64];
2099 float factor, offset;
2103 NORM_ERR("platform needs arguments");
2104 obj->type = OBJ_text;
2108 if (sscanf(arg, "%63s %d %f %f", buf2, &n, &factor, &offset) == 4) found = 1; else HWMON_RESET();
2109 if (!found && sscanf(arg, "%63s %63s %d %f %f", buf1, buf2, &n, &factor, &offset) == 5) found = 1; else if (!found) HWMON_RESET();
2110 if (!found && sscanf(arg, "%63s %63s %d", buf1, buf2, &n) == 3) found = 1; else if (!found) HWMON_RESET();
2111 if (!found && sscanf(arg, "%63s %d", buf2, &n) == 2) found = 1; else if (!found) HWMON_RESET();
2114 NORM_ERR("platform failed to parse arguments");
2115 obj->type = OBJ_text;
2118 DBGP("parsed platform args: '%s' '%s' %d %f %f\n", buf1, buf2, n, factor, offset);
2119 obj->data.sysfs.fd = open_platform_sensor((*buf1) ? buf1 : 0, buf2, n,
2120 &obj->data.sysfs.arg, obj->data.sysfs.devtype);
2121 strncpy(obj->data.sysfs.type, buf2, 63);
2122 obj->data.sysfs.factor = factor;
2123 obj->data.sysfs.offset = offset;
2125 END OBJ(hwmon, INFO_SYSFS)
2126 char buf1[64], buf2[64];
2127 float factor, offset;
2131 NORM_ERR("hwmon needs argumanets");
2132 obj->type = OBJ_text;
2136 if (sscanf(arg, "%63s %d %f %f", buf2, &n, &factor, &offset) == 4) found = 1; else HWMON_RESET();
2137 if (!found && sscanf(arg, "%63s %63s %d %f %f", buf1, buf2, &n, &factor, &offset) == 5) found = 1; else if (!found) HWMON_RESET();
2138 if (!found && sscanf(arg, "%63s %63s %d", buf1, buf2, &n) == 3) found = 1; else if (!found) HWMON_RESET();
2139 if (!found && sscanf(arg, "%63s %d", buf2, &n) == 2) found = 1; else if (!found) HWMON_RESET();
2144 NORM_ERR("hwmon failed to parse arguments");
2145 obj->type = OBJ_text;
2148 DBGP("parsed hwmon args: '%s' '%s' %d %f %f\n", buf1, buf2, n, factor, offset);
2149 obj->data.sysfs.fd = open_hwmon_sensor((*buf1) ? buf1 : 0, buf2, n,
2150 &obj->data.sysfs.arg, obj->data.sysfs.devtype);
2151 strncpy(obj->data.sysfs.type, buf2, 63);
2152 obj->data.sysfs.factor = factor;
2153 obj->data.sysfs.offset = offset;
2155 #endif /* !__OpenBSD__ */
2158 /* we have four different types of top (top, top_mem, top_time and top_io). To
2159 * avoid having almost-same code four times, we have this special
2161 if (strncmp(s, "top", 3) == EQUAL) {
2162 if (!parse_top_args(s, arg, obj)) {
2165 } else OBJ(addr, INFO_NET)
2167 obj->data.net = get_net_stat(arg, obj, free_at_crash);
2169 // default to DEFAULTNETDEV
2170 char *buf = strndup(DEFAULTNETDEV, text_buffer_size);
2171 obj->data.net = get_net_stat(buf, obj, free_at_crash);
2174 #if defined(__linux__)
2175 END OBJ(addrs, INFO_NET)
2177 obj->data.net = get_net_stat(arg, obj, free_at_crash);
2179 // default to DEFAULTNETDEV
2180 char *buf = strndup(DEFAULTNETDEV, text_buffer_size);
2181 obj->data.net = get_net_stat(buf, obj, free_at_crash);
2184 #endif /* __linux__ */
2186 init_tailhead("tail", arg, obj, free_at_crash);
2188 init_tailhead("head", arg, obj, free_at_crash);
2191 obj->data.s = strndup(arg, text_buffer_size);
2193 CRIT_ERR(obj, free_at_crash, "lines needs a argument");
2197 obj->data.s = strndup(arg, text_buffer_size);
2199 CRIT_ERR(obj, free_at_crash, "words needs a argument");
2201 END OBJ(loadavg, INFO_LOADAVG)
2202 int a = 1, b = 2, c = 3, r = 3;
2205 r = sscanf(arg, "%d %d %d", &a, &b, &c);
2206 if (r >= 3 && (c < 1 || c > 3)) {
2209 if (r >= 2 && (b < 1 || b > 3)) {
2212 if (r >= 1 && (a < 1 || a > 3)) {
2216 obj->data.loadavg[0] = (r >= 1) ? (unsigned char) a : 0;
2217 obj->data.loadavg[1] = (r >= 2) ? (unsigned char) b : 0;
2218 obj->data.loadavg[2] = (r >= 3) ? (unsigned char) c : 0;
2219 END OBJ_IF(if_empty, 0)
2221 NORM_ERR("if_empty needs an argument");
2222 obj->data.ifblock.s = 0;
2224 obj->data.ifblock.s = strndup(arg, text_buffer_size);
2225 obj->sub = malloc(sizeof(struct text_object));
2226 extract_variable_text_internal(obj->sub,
2227 obj->data.ifblock.s);
2229 END OBJ_IF(if_match, 0)
2231 NORM_ERR("if_match needs arguments");
2232 obj->data.ifblock.s = 0;
2234 obj->data.ifblock.s = strndup(arg, text_buffer_size);
2235 obj->sub = malloc(sizeof(struct text_object));
2236 extract_variable_text_internal(obj->sub,
2237 obj->data.ifblock.s);
2239 END OBJ_IF(if_existing, 0)
2241 NORM_ERR("if_existing needs an argument or two");
2242 obj->data.ifblock.s = NULL;
2243 obj->data.ifblock.str = NULL;
2245 char buf1[256], buf2[256];
2246 int r = sscanf(arg, "%255s %255[^\n]", buf1, buf2);
2249 obj->data.ifblock.s = strndup(buf1, text_buffer_size);
2250 obj->data.ifblock.str = NULL;
2252 obj->data.ifblock.s = strndup(buf1, text_buffer_size);
2253 obj->data.ifblock.str = strndup(buf2, text_buffer_size);
2256 DBGP("if_existing: '%s' '%s'", obj->data.ifblock.s, obj->data.ifblock.str);
2257 END OBJ_IF(if_mounted, 0)
2259 NORM_ERR("if_mounted needs an argument");
2260 obj->data.ifblock.s = 0;
2262 obj->data.ifblock.s = strndup(arg, text_buffer_size);
2265 END OBJ_IF(if_running, INFO_TOP)
2267 obj->data.ifblock.s = strndup(arg, text_buffer_size);
2269 END OBJ_IF(if_running, 0)
2273 snprintf(buf, 256, "pidof %s >/dev/null", arg);
2274 obj->data.ifblock.s = strndup(buf, text_buffer_size);
2277 NORM_ERR("if_running needs an argument");
2278 obj->data.ifblock.s = 0;
2284 char mbox[256], dst[256];
2288 /* Kapil: Changed from MAIL_FILE to
2289 current_mail_spool since the latter
2290 is a copy of the former if undefined
2291 but the latter should take precedence
2293 strncpy(mbox, current_mail_spool, sizeof(mbox));
2295 if (sscanf(arg, "%s %f", mbox, &n1) != 2) {
2297 strncpy(mbox, arg, sizeof(mbox));
2301 variable_substitute(mbox, dst, sizeof(dst));
2302 obj->data.local_mail.mbox = strndup(dst, text_buffer_size);
2303 obj->data.local_mail.interval = n1;
2304 END OBJ(new_mails, 0)
2306 char mbox[256], dst[256];
2310 strncpy(mbox, current_mail_spool, sizeof(mbox));
2312 if (sscanf(arg, "%s %f", mbox, &n1) != 2) {
2314 strncpy(mbox, arg, sizeof(mbox));
2318 variable_substitute(mbox, dst, sizeof(dst));
2319 obj->data.local_mail.mbox = strndup(dst, text_buffer_size);
2320 obj->data.local_mail.interval = n1;
2321 END OBJ(seen_mails, 0)
2323 char mbox[256], dst[256];
2327 strncpy(mbox, current_mail_spool, sizeof(mbox));
2329 if (sscanf(arg, "%s %f", mbox, &n1) != 2) {
2331 strncpy(mbox, arg, sizeof(mbox));
2335 variable_substitute(mbox, dst, sizeof(dst));
2336 obj->data.local_mail.mbox = strndup(dst, text_buffer_size);
2337 obj->data.local_mail.interval = n1;
2338 END OBJ(unseen_mails, 0)
2340 char mbox[256], dst[256];
2344 strncpy(mbox, current_mail_spool, sizeof(mbox));
2346 if (sscanf(arg, "%s %f", mbox, &n1) != 2) {
2348 strncpy(mbox, arg, sizeof(mbox));
2352 variable_substitute(mbox, dst, sizeof(dst));
2353 obj->data.local_mail.mbox = strndup(dst, text_buffer_size);
2354 obj->data.local_mail.interval = n1;
2355 END OBJ(flagged_mails, 0)
2357 char mbox[256], dst[256];
2361 strncpy(mbox, current_mail_spool, sizeof(mbox));
2363 if (sscanf(arg, "%s %f", mbox, &n1) != 2) {
2365 strncpy(mbox, arg, sizeof(mbox));
2369 variable_substitute(mbox, dst, sizeof(dst));
2370 obj->data.local_mail.mbox = strndup(dst, text_buffer_size);
2371 obj->data.local_mail.interval = n1;
2372 END OBJ(unflagged_mails, 0)
2374 char mbox[256], dst[256];
2378 strncpy(mbox, current_mail_spool, sizeof(mbox));
2380 if (sscanf(arg, "%s %f", mbox, &n1) != 2) {
2382 strncpy(mbox, arg, sizeof(mbox));
2386 variable_substitute(mbox, dst, sizeof(dst));
2387 obj->data.local_mail.mbox = strndup(dst, text_buffer_size);
2388 obj->data.local_mail.interval = n1;
2389 END OBJ(forwarded_mails, 0)
2391 char mbox[256], dst[256];
2395 strncpy(mbox, current_mail_spool, sizeof(mbox));
2397 if (sscanf(arg, "%s %f", mbox, &n1) != 2) {
2399 strncpy(mbox, arg, sizeof(mbox));
2403 variable_substitute(mbox, dst, sizeof(dst));
2404 obj->data.local_mail.mbox = strndup(dst, text_buffer_size);
2405 obj->data.local_mail.interval = n1;
2406 END OBJ(unforwarded_mails, 0)
2408 char mbox[256], dst[256];
2412 strncpy(mbox, current_mail_spool, sizeof(mbox));
2414 if (sscanf(arg, "%s %f", mbox, &n1) != 2) {
2416 strncpy(mbox, arg, sizeof(mbox));
2420 variable_substitute(mbox, dst, sizeof(dst));
2421 obj->data.local_mail.mbox = strndup(dst, text_buffer_size);
2422 obj->data.local_mail.interval = n1;
2423 END OBJ(replied_mails, 0)
2425 char mbox[256], dst[256];
2429 strncpy(mbox, current_mail_spool, sizeof(mbox));
2431 if (sscanf(arg, "%s %f", mbox, &n1) != 2) {
2433 strncpy(mbox, arg, sizeof(mbox));
2437 variable_substitute(mbox, dst, sizeof(dst));
2438 obj->data.local_mail.mbox = strndup(dst, text_buffer_size);
2439 obj->data.local_mail.interval = n1;
2440 END OBJ(unreplied_mails, 0)
2442 char mbox[256], dst[256];
2446 strncpy(mbox, current_mail_spool, sizeof(mbox));
2448 if (sscanf(arg, "%s %f", mbox, &n1) != 2) {
2450 strncpy(mbox, arg, sizeof(mbox));
2454 variable_substitute(mbox, dst, sizeof(dst));
2455 obj->data.local_mail.mbox = strndup(dst, text_buffer_size);
2456 obj->data.local_mail.interval = n1;
2457 END OBJ(draft_mails, 0)
2459 char mbox[256], dst[256];
2463 strncpy(mbox, current_mail_spool, sizeof(mbox));
2465 if (sscanf(arg, "%s %f", mbox, &n1) != 2) {
2467 strncpy(mbox, arg, sizeof(mbox));
2471 variable_substitute(mbox, dst, sizeof(dst));
2472 obj->data.local_mail.mbox = strndup(dst, text_buffer_size);
2473 obj->data.local_mail.interval = n1;
2474 END OBJ(trashed_mails, 0)
2476 char mbox[256], dst[256];
2480 strncpy(mbox, current_mail_spool, sizeof(mbox));
2482 if (sscanf(arg, "%s %f", mbox, &n1) != 2) {
2484 strncpy(mbox, arg, sizeof(mbox));
2488 variable_substitute(mbox, dst, sizeof(dst));
2489 obj->data.local_mail.mbox = strndup(dst, text_buffer_size);
2490 obj->data.local_mail.interval = n1;
2491 END OBJ(mboxscan, 0)
2492 obj->data.mboxscan.args = (char *) malloc(text_buffer_size);
2493 obj->data.mboxscan.output = (char *) malloc(text_buffer_size);
2494 /* if '1' (in mboxscan.c) then there was SIGUSR1, hmm */
2495 obj->data.mboxscan.output[0] = 1;
2496 strncpy(obj->data.mboxscan.args, arg, text_buffer_size);
2497 END OBJ(mem, INFO_MEM)
2498 END OBJ(memeasyfree, INFO_MEM)
2499 END OBJ(memfree, INFO_MEM)
2500 END OBJ(memmax, INFO_MEM)
2501 END OBJ(memperc, INFO_MEM)
2503 END OBJ(memgauge, INFO_MEM)
2504 SIZE_DEFAULTS(gauge);
2505 scan_gauge(arg, &obj->data.pair.a, &obj->data.pair.b);
2507 END OBJ(membar, INFO_MEM)
2509 scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
2511 END OBJ(memgraph, INFO_MEM)
2513 SIZE_DEFAULTS(graph);
2514 buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
2515 &obj->e, &obj->char_a, &obj->char_b);
2519 END OBJ(mixer, INFO_MIXER)
2520 obj->data.l = mixer_init(arg);
2521 END OBJ(mixerl, INFO_MIXER)
2522 obj->data.l = mixer_init(arg);
2523 END OBJ(mixerr, INFO_MIXER)
2524 obj->data.l = mixer_init(arg);
2526 END OBJ(mixerbar, INFO_MIXER)
2528 scan_mixer_bar(arg, &obj->data.mixerbar.l, &obj->data.mixerbar.w,
2529 &obj->data.mixerbar.h);
2530 END OBJ(mixerlbar, INFO_MIXER)
2532 scan_mixer_bar(arg, &obj->data.mixerbar.l, &obj->data.mixerbar.w,
2533 &obj->data.mixerbar.h);
2534 END OBJ(mixerrbar, INFO_MIXER)
2536 scan_mixer_bar(arg, &obj->data.mixerbar.l, &obj->data.mixerbar.w,
2537 &obj->data.mixerbar.h);
2539 END OBJ_IF(if_mixer_mute, INFO_MIXER)
2540 obj->data.ifblock.i = mixer_init(arg);
2542 END OBJ(monitor, INFO_X11)
2543 END OBJ(monitor_number, INFO_X11)
2544 END OBJ(desktop, INFO_X11)
2545 END OBJ(desktop_number, INFO_X11)
2546 END OBJ(desktop_name, INFO_X11)
2548 END OBJ(nodename, 0)
2549 END OBJ(processes, INFO_PROCS)
2550 END OBJ(running_processes, INFO_RUN_PROCS)
2551 END OBJ(shadecolor, 0)
2553 obj->data.l = arg ? get_x11_color(arg) : default_bg_color;
2555 END OBJ(outlinecolor, 0)
2557 obj->data.l = arg ? get_x11_color(arg) : default_out_color;
2559 END OBJ(stippled_hr, 0)
2561 int a = stippled_borders, b = 1;
2564 if (sscanf(arg, "%d %d", &a, &b) != 2) {
2565 sscanf(arg, "%d", &b);
2571 obj->data.pair.a = a;
2572 obj->data.pair.b = b;
2574 END OBJ(swap, INFO_MEM)
2575 END OBJ(swapfree, INFO_MEM)
2576 END OBJ(swapmax, INFO_MEM)
2577 END OBJ(swapperc, INFO_MEM)
2578 END OBJ(swapbar, INFO_MEM)
2580 scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
2583 obj->data.s = strndup(arg ? arg : "%F %T", text_buffer_size);
2585 obj->data.s = strndup(arg ? arg : "%F %T", text_buffer_size);
2587 char buf1[256], buf2[256], *fmt, *tz;
2591 int nArgs = sscanf(arg, "%255s %255[^\n]", buf1, buf2);
2601 obj->data.tztime.fmt = strndup(fmt ? fmt : "%F %T", text_buffer_size);
2602 obj->data.tztime.tz = tz ? strndup(tz, text_buffer_size) : NULL;
2604 END OBJ(iconv_start, 0)
2605 if (iconv_converting) {
2606 CRIT_ERR(obj, free_at_crash, "You must stop your last iconv conversion before "
2607 "starting another");
2610 char iconv_from[CODEPAGE_LENGTH];
2611 char iconv_to[CODEPAGE_LENGTH];
2613 if (sscanf(arg, "%s %s", iconv_from, iconv_to) != 2) {
2614 CRIT_ERR(obj, free_at_crash, "Invalid arguments for iconv_start");
2618 new_iconv = iconv_open(iconv_to, iconv_from);
2619 if (new_iconv == (iconv_t) (-1)) {
2620 NORM_ERR("Can't convert from %s to %s.", iconv_from, iconv_to);
2622 obj->a = register_iconv(&new_iconv);
2623 iconv_converting = 1;
2627 CRIT_ERR(obj, free_at_crash, "Iconv requires arguments");
2629 END OBJ(iconv_stop, 0)
2630 iconv_converting = 0;
2633 END OBJ(totaldown, INFO_NET)
2635 obj->data.net = get_net_stat(arg, obj, free_at_crash);
2637 // default to DEFAULTNETDEV
2638 char *buf = strndup(DEFAULTNETDEV, text_buffer_size);
2639 obj->data.net = get_net_stat(buf, obj, free_at_crash);
2642 END OBJ(totalup, INFO_NET)
2643 obj->data.net = get_net_stat(arg, obj, free_at_crash);
2645 obj->data.net = get_net_stat(arg, obj, free_at_crash);
2647 // default to DEFAULTNETDEV
2648 char *buf = strndup(DEFAULTNETDEV, text_buffer_size);
2649 obj->data.net = get_net_stat(buf, obj, free_at_crash);
2653 END OBJ_IF(if_updatenr, 0)
2654 obj->data.ifblock.i = arg ? atoi(arg) : 0;
2655 if(obj->data.ifblock.i == 0) CRIT_ERR(obj, free_at_crash, "if_updatenr needs a number above 0 as argument");
2656 updatereset = obj->data.ifblock.i > updatereset ? obj->data.ifblock.i : updatereset;
2658 obj->data.i = arg ? atoi(arg) : 0;
2660 obj->data.i = arg ? atoi(arg) : 0;
2661 END OBJ(upspeed, INFO_NET)
2663 obj->data.net = get_net_stat(arg, obj, free_at_crash);
2665 // default to DEFAULTNETDEV
2666 char *buf = strndup(DEFAULTNETDEV, text_buffer_size);
2667 obj->data.net = get_net_stat(buf, obj, free_at_crash);
2670 END OBJ(upspeedf, INFO_NET)
2672 obj->data.net = get_net_stat(arg, obj, free_at_crash);
2674 // default to DEFAULTNETDEV
2675 char *buf = strndup(DEFAULTNETDEV, text_buffer_size);
2676 obj->data.net = get_net_stat(buf, obj, free_at_crash);
2681 END OBJ(upspeedgraph, INFO_NET)
2683 SIZE_DEFAULTS(graph);
2684 buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
2685 &obj->e, &obj->char_a, &obj->char_b);
2687 // default to DEFAULTNETDEV
2688 buf = strndup(buf ? buf : DEFAULTNETDEV, text_buffer_size);
2689 obj->data.net = get_net_stat(buf, obj, free_at_crash);
2692 END OBJ(uptime_short, INFO_UPTIME)
2693 END OBJ(uptime, INFO_UPTIME)
2694 END OBJ(user_names, INFO_USERS)
2695 END OBJ(user_times, INFO_USERS)
2696 END OBJ(user_terms, INFO_USERS)
2697 END OBJ(user_number, INFO_USERS)
2698 #if defined(__linux__)
2699 END OBJ(gw_iface, INFO_GW)
2700 END OBJ(gw_ip, INFO_GW)
2701 #endif /* !__linux__ */
2703 END OBJ(adt746xcpu, 0)
2704 END OBJ(adt746xfan, 0)
2705 #endif /* !__OpenBSD__ */
2706 #if (defined(__FreeBSD__) || defined(__FreeBSD_kernel__) \
2707 || defined(__OpenBSD__)) && (defined(i386) || defined(__i386__))
2708 END OBJ(apm_adapter, 0)
2709 END OBJ(apm_battery_life, 0)
2710 END OBJ(apm_battery_time, 0)
2711 #endif /* __FreeBSD__ */
2712 END OBJ(imap_unseen, 0)
2715 obj->data.mail = parse_mail_args(IMAP_TYPE, arg);
2720 END OBJ(imap_messages, 0)
2723 obj->data.mail = parse_mail_args(IMAP_TYPE, arg);
2728 END OBJ(pop3_unseen, 0)
2731 obj->data.mail = parse_mail_args(POP3_TYPE, arg);
2736 END OBJ(pop3_used, 0)
2739 obj->data.mail = parse_mail_args(POP3_TYPE, arg);
2747 obj->data.s = strndup(arg, text_buffer_size);
2749 NORM_ERR("smapi needs an argument");
2750 END OBJ_IF(if_smapi_bat_installed, 0)
2752 NORM_ERR("if_smapi_bat_installed needs an argument");
2753 obj->data.ifblock.s = 0;
2755 obj->data.ifblock.s = strndup(arg, text_buffer_size);
2756 END OBJ(smapi_bat_perc, 0)
2758 obj->data.s = strndup(arg, text_buffer_size);
2760 NORM_ERR("smapi_bat_perc needs an argument");
2761 END OBJ(smapi_bat_temp, 0)
2763 obj->data.s = strndup(arg, text_buffer_size);
2765 NORM_ERR("smapi_bat_temp needs an argument");
2766 END OBJ(smapi_bat_power, 0)
2768 obj->data.s = strndup(arg, text_buffer_size);
2770 NORM_ERR("smapi_bat_power needs an argument");
2772 END OBJ(smapi_bat_bar, 0)
2776 if(sscanf(arg, "%i %n", &obj->data.i, &cnt) <= 0) {
2777 NORM_ERR("first argument to smapi_bat_bar must be an integer value");
2781 arg = scan_bar(arg + cnt, &obj->a, &obj->b);
2784 NORM_ERR("smapi_bat_bar needs an argument");
2788 #define mpd_set_maxlen(name) \
2791 sscanf(arg, "%d", &i); \
2793 obj->data.i = i + 1; \
2795 NORM_ERR(#name ": invalid length argument"); \
2797 END OBJ(mpd_artist, INFO_MPD)
2798 mpd_set_maxlen(mpd_artist);
2800 END OBJ(mpd_title, INFO_MPD)
2801 mpd_set_maxlen(mpd_title);
2803 END OBJ(mpd_random, INFO_MPD) init_mpd();
2804 END OBJ(mpd_repeat, INFO_MPD) init_mpd();
2805 END OBJ(mpd_elapsed, INFO_MPD) init_mpd();
2806 END OBJ(mpd_length, INFO_MPD) init_mpd();
2807 END OBJ(mpd_track, INFO_MPD)
2808 mpd_set_maxlen(mpd_track);
2810 END OBJ(mpd_name, INFO_MPD)
2811 mpd_set_maxlen(mpd_name);
2813 END OBJ(mpd_file, INFO_MPD)
2814 mpd_set_maxlen(mpd_file);
2816 END OBJ(mpd_percent, INFO_MPD) init_mpd();
2817 END OBJ(mpd_album, INFO_MPD)
2818 mpd_set_maxlen(mpd_album);
2820 END OBJ(mpd_vol, INFO_MPD) init_mpd();
2821 END OBJ(mpd_bitrate, INFO_MPD) init_mpd();
2822 END OBJ(mpd_status, INFO_MPD) init_mpd();
2823 END OBJ(mpd_bar, INFO_MPD)
2825 scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
2827 END OBJ(mpd_smart, INFO_MPD)
2828 mpd_set_maxlen(mpd_smart);
2830 END OBJ_IF(if_mpd_playing, INFO_MPD)
2832 #undef mpd_set_maxlen
2835 END OBJ(moc_state, INFO_MOC)
2836 END OBJ(moc_file, INFO_MOC)
2837 END OBJ(moc_title, INFO_MOC)
2838 END OBJ(moc_artist, INFO_MOC)
2839 END OBJ(moc_song, INFO_MOC)
2840 END OBJ(moc_album, INFO_MOC)
2841 END OBJ(moc_totaltime, INFO_MOC)
2842 END OBJ(moc_timeleft, INFO_MOC)
2843 END OBJ(moc_curtime, INFO_MOC)
2844 END OBJ(moc_bitrate, INFO_MOC)
2845 END OBJ(moc_rate, INFO_MOC)
2848 END OBJ(xmms2_artist, INFO_XMMS2)
2849 END OBJ(xmms2_album, INFO_XMMS2)
2850 END OBJ(xmms2_title, INFO_XMMS2)
2851 END OBJ(xmms2_genre, INFO_XMMS2)
2852 END OBJ(xmms2_comment, INFO_XMMS2)
2853 END OBJ(xmms2_url, INFO_XMMS2)
2854 END OBJ(xmms2_tracknr, INFO_XMMS2)
2855 END OBJ(xmms2_bitrate, INFO_XMMS2)
2856 END OBJ(xmms2_date, INFO_XMMS2)
2857 END OBJ(xmms2_id, INFO_XMMS2)
2858 END OBJ(xmms2_duration, INFO_XMMS2)
2859 END OBJ(xmms2_elapsed, INFO_XMMS2)
2860 END OBJ(xmms2_size, INFO_XMMS2)
2861 END OBJ(xmms2_status, INFO_XMMS2)
2862 END OBJ(xmms2_percent, INFO_XMMS2)
2864 END OBJ(xmms2_bar, INFO_XMMS2)
2866 scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
2868 END OBJ(xmms2_smart, INFO_XMMS2)
2869 END OBJ(xmms2_playlist, INFO_XMMS2)
2870 END OBJ(xmms2_timesplayed, INFO_XMMS2)
2871 END OBJ_IF(if_xmms2_connected, INFO_XMMS2)
2874 END OBJ(audacious_status, INFO_AUDACIOUS)
2875 END OBJ(audacious_title, INFO_AUDACIOUS)
2877 sscanf(arg, "%d", &info.audacious.max_title_len);
2878 if (info.audacious.max_title_len > 0) {
2879 info.audacious.max_title_len++;
2881 CRIT_ERR(obj, free_at_crash, "audacious_title: invalid length argument");
2884 END OBJ(audacious_length, INFO_AUDACIOUS)
2885 END OBJ(audacious_length_seconds, INFO_AUDACIOUS)
2886 END OBJ(audacious_position, INFO_AUDACIOUS)
2887 END OBJ(audacious_position_seconds, INFO_AUDACIOUS)
2888 END OBJ(audacious_bitrate, INFO_AUDACIOUS)
2889 END OBJ(audacious_frequency, INFO_AUDACIOUS)
2890 END OBJ(audacious_channels, INFO_AUDACIOUS)
2891 END OBJ(audacious_filename, INFO_AUDACIOUS)
2892 END OBJ(audacious_playlist_length, INFO_AUDACIOUS)
2893 END OBJ(audacious_playlist_position, INFO_AUDACIOUS)
2894 END OBJ(audacious_main_volume, INFO_AUDACIOUS)
2896 END OBJ(audacious_bar, INFO_AUDACIOUS)
2898 scan_bar(arg, &obj->a, &obj->b);
2902 END OBJ(bmpx_title, INFO_BMPX)
2903 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
2904 END OBJ(bmpx_artist, INFO_BMPX)
2905 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
2906 END OBJ(bmpx_album, INFO_BMPX)
2907 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
2908 END OBJ(bmpx_track, INFO_BMPX)
2909 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
2910 END OBJ(bmpx_uri, INFO_BMPX)
2911 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
2912 END OBJ(bmpx_bitrate, INFO_BMPX)
2913 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
2919 char *userid = (char *) malloc(20 * sizeof(char));
2920 char *apikey = (char *) malloc(64 * sizeof(char));
2921 char *charid = (char *) malloc(20 * sizeof(char));
2923 argc = sscanf(arg, "%20s %64s %20s", userid, apikey, charid);
2924 obj->data.eve.charid = charid;
2925 obj->data.eve.userid = userid;
2926 obj->data.eve.apikey = apikey;
2930 CRIT_ERR(obj, free_at_crash, "eve needs arguments: <userid> <apikey> <characterid>");
2938 char *uri = (char *) malloc(128 * sizeof(char));
2940 argc = sscanf(arg, "%127s %f", uri, &interval);
2942 obj->data.curl.uri = uri;
2943 obj->data.curl.interval = interval > 0 ? interval * 60 : 15*60;
2945 NORM_ERR("wrong number of arguments for $curl");
2948 CRIT_ERR(obj, free_at_crash, "curl needs arguments: <uri> <interval in minutes>");
2956 unsigned int nrspaces = 0;
2957 char *uri = (char *) malloc(128 * sizeof(char));
2958 char *action = (char *) malloc(64 * sizeof(char));
2960 argc = sscanf(arg, "%127s %f %63s %d %u", uri, &interval, action,
2961 &act_par, &nrspaces);
2963 obj->data.rss.uri = uri;
2964 obj->data.rss.interval = interval > 0 ? interval * 60 : 15*60;
2965 obj->data.rss.action = action;
2966 obj->data.rss.act_par = act_par;
2967 obj->data.rss.nrspaces = nrspaces;
2969 NORM_ERR("wrong number of arguments for $rss");
2972 CRIT_ERR(obj, free_at_crash, "rss needs arguments: <uri> <interval in minutes> <action> "
2973 "[act_par] [spaces in front]");
2981 char *locID = (char *) malloc(9 * sizeof(char));
2982 char *uri = (char *) malloc(128 * sizeof(char));
2983 char *data_type = (char *) malloc(32 * sizeof(char));
2985 argc = sscanf(arg, "%119s %8s %31s %f", uri, locID, data_type, &interval);
2988 if (process_weather_uri(uri, locID)) {
2992 CRIT_ERR(obj, free_at_crash, \
2993 "could not recognize the weather uri");
2996 obj->data.weather.uri = uri;
2997 obj->data.weather.data_type = data_type;
2999 /* Limit the data retrieval interval to half hour min */
3000 if (interval < 30) {
3004 /* Convert to seconds */
3005 obj->data.weather.interval = interval * 60;
3008 DBGP("weather: fetching %s from %s every %d seconds", \
3009 data_type, uri, obj->data.weather.interval);
3014 CRIT_ERR(obj, free_at_crash, "wrong number of arguments for $weather");
3017 CRIT_ERR(obj, free_at_crash, "weather needs arguments: <uri> <locID> <data_type> [interval in minutes]");
3023 obj->data.s = strndup(arg, text_buffer_size);
3025 CRIT_ERR(obj, free_at_crash, "lua needs arguments: <function name> [function parameters]");
3027 END OBJ(lua_parse, 0)
3029 obj->data.s = strndup(arg, text_buffer_size);
3031 CRIT_ERR(obj, free_at_crash, "lua_parse needs arguments: <function name> [function parameters]");
3036 arg = scan_bar(arg, &obj->a, &obj->b);
3038 obj->data.s = strndup(arg, text_buffer_size);
3040 CRIT_ERR(obj, free_at_crash, "lua_bar needs arguments: <height>,<width> <function name> [function parameters]");
3043 CRIT_ERR(obj, free_at_crash, "lua_bar needs arguments: <height>,<width> <function name> [function parameters]");
3046 END OBJ(lua_graph, 0)
3047 SIZE_DEFAULTS(graph);
3050 buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
3051 &obj->e, &obj->char_a, &obj->char_b);
3055 CRIT_ERR(obj, free_at_crash, "lua_graph needs arguments: <function name> [height],[width] [gradient colour 1] [gradient colour 2] [scale] [-t] [-l]");
3058 CRIT_ERR(obj, free_at_crash, "lua_graph needs arguments: <function name> [height],[width] [gradient colour 1] [gradient colour 2] [scale] [-t] [-l]");
3060 END OBJ(lua_gauge, 0)
3061 SIZE_DEFAULTS(gauge);
3063 arg = scan_gauge(arg, &obj->a, &obj->b);
3065 obj->data.s = strndup(arg, text_buffer_size);
3067 CRIT_ERR(obj, free_at_crash, "lua_gauge needs arguments: <height>,<width> <function name> [function parameters]");
3070 CRIT_ERR(obj, free_at_crash, "lua_gauge needs arguments: <height>,<width> <function name> [function parameters]");
3073 #endif /* HAVE_LUA */
3076 if (scan_hddtemp(arg, &obj->data.hddtemp.dev,
3077 &obj->data.hddtemp.addr, &obj->data.hddtemp.port)) {
3078 NORM_ERR("hddtemp needs arguments");
3079 obj->type = OBJ_text;
3080 obj->data.s = strndup("${hddtemp}", text_buffer_size);
3081 obj->data.hddtemp.update_time = 0;
3083 obj->data.hddtemp.temp = NULL;
3084 #endif /* HDDTEMP */
3085 #ifdef TCP_PORT_MONITOR
3086 END OBJ(tcp_portmon, INFO_TCP_PORT_MONITOR)
3087 tcp_portmon_init(arg, &obj->data.tcp_port_monitor);
3088 #endif /* TCP_PORT_MONITOR */
3089 END OBJ(entropy_avail, INFO_ENTROPY)
3090 END OBJ(entropy_perc, INFO_ENTROPY)
3091 END OBJ(entropy_poolsize, INFO_ENTROPY)
3092 END OBJ(entropy_bar, INFO_ENTROPY)
3094 scan_bar(arg, &obj->a, &obj->b);
3097 struct conftree *leaf = conftree_add(currentconffile, arg);
3099 if( load_config_file(arg) == TRUE) {
3100 obj->sub = malloc(sizeof(struct text_object));
3101 currentconffile = leaf;
3102 extract_variable_text_internal(obj->sub, global_text);
3103 currentconffile = leaf->back;
3105 NORM_ERR("Can't load configfile '%s'.", arg);
3108 NORM_ERR("You are trying to load '%s' recursively, I'm only going to load it once to prevent an infinite loop.", arg);
3111 CRIT_ERR(obj, free_at_crash, "include needs a argument");
3115 obj->sub = malloc(sizeof(struct text_object));
3116 extract_variable_text_internal(obj->sub, arg);
3118 CRIT_ERR(obj, free_at_crash, "blink needs a argument");
3120 END OBJ(to_bytes, 0)
3122 obj->sub = malloc(sizeof(struct text_object));
3123 extract_variable_text_internal(obj->sub, arg);
3125 CRIT_ERR(obj, free_at_crash, "to_bytes needs a argument");
3130 obj->data.scroll.resetcolor = current_text_color;
3131 obj->data.scroll.step = 1;
3132 if (arg && sscanf(arg, "%u %n", &obj->data.scroll.show, &n1) > 0) {
3133 sscanf(arg + n1, "%u %n", &obj->data.scroll.step, &n2);
3134 if (*(arg + n1 + n2)) {
3137 obj->data.scroll.step = 1;
3139 obj->data.scroll.text = malloc(strlen(arg + n1) + obj->data.scroll.show + 1);
3140 for(n2 = 0; (unsigned int) n2 < obj->data.scroll.show; n2++) {
3141 obj->data.scroll.text[n2] = ' ';
3143 obj->data.scroll.text[n2] = 0;
3144 strcat(obj->data.scroll.text, arg + n1);
3145 obj->data.scroll.start = 0;
3146 obj->sub = malloc(sizeof(struct text_object));
3147 extract_variable_text_internal(obj->sub,
3148 obj->data.scroll.text);
3150 CRIT_ERR(obj, free_at_crash, "scroll needs arguments: <length> [<step>] <text>");
3155 unsigned int indenting = 0; //vars can be used as args for other vars
3158 startvar[0] = endvar[0] = startvar[1] = endvar[1] = -1;
3160 for (i=0; arg[i] != 0 && j < 2; i++) {
3161 if(startvar[j] == -1) {
3165 }else if(endvar[j] == -1) {
3168 }else if(arg[i] == '}') {
3171 if (indenting == 0 && arg[i+1] < 48) { //<48 has 0, $, and the most used chars not used in varnames but not { or }
3177 if(startvar[0] >= 0 && endvar[0] >= 0 && startvar[1] >= 0 && endvar[1] >= 0) {
3178 obj->data.combine.left = malloc(endvar[0]-startvar[0] + 1);
3179 obj->data.combine.seperation = malloc(startvar[1] - endvar[0] + 1);
3180 obj->data.combine.right= malloc(endvar[1]-startvar[1] + 1);
3182 strncpy(obj->data.combine.left, arg + startvar[0], endvar[0] - startvar[0]);
3183 obj->data.combine.left[endvar[0] - startvar[0]] = 0;
3185 strncpy(obj->data.combine.seperation, arg + endvar[0], startvar[1] - endvar[0]);
3186 obj->data.combine.seperation[startvar[1] - endvar[0]] = 0;
3188 strncpy(obj->data.combine.right, arg + startvar[1], endvar[1] - startvar[1]);
3189 obj->data.combine.right[endvar[1] - startvar[1]] = 0;
3191 obj->sub = malloc(sizeof(struct text_object));
3192 extract_variable_text_internal(obj->sub, obj->data.combine.left);
3193 obj->sub->sub = malloc(sizeof(struct text_object));
3194 extract_variable_text_internal(obj->sub->sub, obj->data.combine.right);
3196 CRIT_ERR(obj, free_at_crash, "combine needs arguments: <text1> <text2>");
3199 CRIT_ERR(obj, free_at_crash, "combine needs arguments: <text1> <text2>");
3204 CRIT_ERR(obj, free_at_crash, "nvidia needs an argument\n");
3205 } else if (set_nvidia_type(&obj->data.nvidia, arg)) {
3206 CRIT_ERR(obj, free_at_crash, "nvidia: invalid argument"
3207 " specified: '%s'\n", arg);
3212 END OBJ(apcupsd, INFO_APCUPSD)
3216 if (sscanf(arg, "%63s %d", host, &port) != 2) {
3217 CRIT_ERR(obj, free_at_crash, "apcupsd needs arguments: <host> <port>");
3219 info.apcupsd.port = htons(port);
3220 strncpy(info.apcupsd.host, host, sizeof(info.apcupsd.host));
3223 CRIT_ERR(obj, free_at_crash, "apcupsd needs arguments: <host> <port>");
3225 END OBJ(apcupsd_name, INFO_APCUPSD)
3226 END OBJ(apcupsd_model, INFO_APCUPSD)
3227 END OBJ(apcupsd_upsmode, INFO_APCUPSD)
3228 END OBJ(apcupsd_cable, INFO_APCUPSD)
3229 END OBJ(apcupsd_status, INFO_APCUPSD)
3230 END OBJ(apcupsd_linev, INFO_APCUPSD)
3231 END OBJ(apcupsd_load, INFO_APCUPSD)
3232 END OBJ(apcupsd_loadbar, INFO_APCUPSD)
3234 scan_bar(arg, &obj->a, &obj->b);
3236 END OBJ(apcupsd_loadgraph, INFO_APCUPSD)
3238 SIZE_DEFAULTS(graph);
3239 buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
3240 &obj->e, &obj->char_a, &obj->char_b);
3242 END OBJ(apcupsd_loadgauge, INFO_APCUPSD)
3243 SIZE_DEFAULTS(gauge);
3244 scan_gauge(arg, &obj->a, &obj->b);
3246 END OBJ(apcupsd_charge, INFO_APCUPSD)
3247 END OBJ(apcupsd_timeleft, INFO_APCUPSD)
3248 END OBJ(apcupsd_temp, INFO_APCUPSD)
3249 END OBJ(apcupsd_lastxfer, INFO_APCUPSD)
3250 #endif /* APCUPSD */
3254 NORM_ERR("unknown variable %s", s);
3255 obj->type = OBJ_text;
3256 snprintf(buf, 256, "${%s}", s);
3257 obj->data.s = strndup(buf, text_buffer_size);
3264 static struct text_object *create_plain_text(const char *s)
3266 struct text_object *obj;
3268 if (s == NULL || *s == '\0') {
3272 obj = new_text_object_internal();
3274 obj->type = OBJ_text;
3275 obj->data.s = strndup(s, text_buffer_size);
3279 /* backslash_escape - do the actual substitution task for template objects
3281 * The field templates is used for substituting the \N occurences. Set it to
3282 * NULL to leave them as they are.
3284 static char *backslash_escape(const char *src, char **templates, unsigned int template_count)
3288 unsigned int dup_idx = 0, dup_len;
3290 dup_len = strlen(src) + 1;
3291 src_dup = malloc(dup_len * sizeof(char));
3299 if (*(p + 1) == '\\') {
3300 src_dup[dup_idx++] = '\\';
3302 } else if (*(p + 1) == ' ') {
3303 src_dup[dup_idx++] = ' ';
3305 } else if (*(p + 1) == 'n') {
3306 src_dup[dup_idx++] = '\n';
3308 } else if (templates) {
3309 unsigned int tmpl_num;
3311 if ((sscanf(p + 1, "%u%n", &tmpl_num, &digits) <= 0) ||
3312 (tmpl_num > template_count))
3314 dup_len += strlen(templates[tmpl_num - 1]);
3315 src_dup = realloc(src_dup, dup_len * sizeof(char));
3316 sprintf(src_dup + dup_idx, "%s", templates[tmpl_num - 1]);
3317 dup_idx += strlen(templates[tmpl_num - 1]);
3322 src_dup[dup_idx++] = *p;
3327 src_dup[dup_idx] = '\0';
3328 src_dup = realloc(src_dup, (strlen(src_dup) + 1) * sizeof(char));
3332 /* handle_template_object - core logic of the template object
3334 * use config variables like this:
3335 * template1 = "$\1\2"
3336 * template2 = "\1: ${fs_bar 4,100 \2} ${fs_used \2} / ${fs_size \2}"
3338 * and use them like this:
3339 * ${template1 node name}
3340 * ${template2 root /}
3341 * ${template2 cdrom /mnt/cdrom}
3343 static char *handle_template(const char *tmpl, const char *args)
3345 char *args_dup = NULL;
3347 char **argsp = NULL;
3348 unsigned int argcnt = 0, template_idx, i;
3351 if ((sscanf(tmpl, "template%u", &template_idx) != 1) ||
3352 (template_idx >= MAX_TEMPLATES))
3356 args_dup = strdup(args);
3359 while (*p && (*p == ' ' && (p == args_dup || *(p - 1) != '\\')))
3361 if (p > args_dup && *(p - 1) == '\\')
3364 while (*p && (*p != ' ' || (p > args_dup && *(p - 1) == '\\')))
3370 argsp = realloc(argsp, ++argcnt * sizeof(char *));
3371 argsp[argcnt - 1] = p_old;
3373 for (i = 0; i < argcnt; i++) {
3375 tmp = backslash_escape(argsp[i], NULL, 0);
3376 DBGP2("%s: substituted arg '%s' to '%s'", tmpl, argsp[i], tmp);
3381 eval_text = backslash_escape(template[template_idx], argsp, argcnt);
3382 DBGP("substituted %s, output is '%s'", tmpl, eval_text);
3384 for (i = 0; i < argcnt; i++)
3390 static char *find_and_replace_templates(const char *inbuf)
3392 char *outbuf, *indup, *p, *o, *templ, *args, *tmpl_out;
3395 outlen = strlen(inbuf) + 1;
3396 o = outbuf = calloc(outlen, sizeof(char));
3397 memset(outbuf, 0, outlen * sizeof(char));
3399 p = indup = strdup(inbuf);
3401 while (*p && *p != '$')
3407 if (strncmp(p, "$template", 9) && strncmp(p, "${template", 10)) {
3412 if (*(p + 1) == '{') {
3415 while (*p && !isspace(*p) && *p != '{' && *p != '}')
3423 while (*p && stack > 0) {
3431 // stack is empty. that means the previous char was }, so we zero it
3434 // we ran into the end of string without finding a closing }, bark
3435 CRIT_ERR(NULL, NULL, "cannot find a closing '}' in template expansion");
3439 while (*p && !isspace(*p))
3443 tmpl_out = handle_template(templ, args);
3445 outlen += strlen(tmpl_out);
3447 outbuf = realloc(outbuf, outlen * sizeof(char));
3448 strcat (outbuf, tmpl_out);
3450 o = outbuf + strlen(outbuf);
3452 NORM_ERR("failed to handle template '%s' with args '%s'", templ, args);
3456 outbuf = realloc(outbuf, (strlen(outbuf) + 1) * sizeof(char));
3461 static int text_contains_templates(const char *text)
3463 if (strcasestr(text, "${template") != NULL)
3465 if (strcasestr(text, "$template") != NULL)
3471 * - assumes that *string is '#'
3472 * - removes the part from '#' to the end of line ('\n' or '\0')
3473 * - it removes the '\n'
3474 * - copies the last char into 'char *last' argument, which should be a pointer
3475 * to a char rather than a string.
3477 static size_t remove_comment(char *string, char *last)
3480 while (*end != '\0' && *end != '\n') {
3483 if (last) *last = *end;
3484 if (*end == '\n') end++;
3485 strfold(string, end - string);
3486 return end - string;
3489 static size_t remove_comments(char *string)
3493 for (curplace = string; *curplace != 0; curplace++) {
3494 if (*curplace == '\\' && *(curplace + 1) == '#') {
3495 // strcpy can't be used for overlapping strings
3496 strfold(curplace, 1);
3498 } else if (*curplace == '#') {
3499 folded += remove_comment(curplace, 0);
3505 static int extract_variable_text_internal(struct text_object *retval, const char *const_p)
3507 struct text_object *obj;
3508 char *p, *s, *orig_p;
3510 void *ifblock_opaque = NULL;
3515 p = strndup(const_p, max_user_text - 1);
3516 while (text_contains_templates(p)) {
3518 tmp = find_and_replace_templates(p);
3524 if (strcmp(p, const_p)) {
3525 DBGP("replaced all templates in text: input is\n'%s'\noutput is\n'%s'", const_p, p);
3527 DBGP("no templates to replace");
3530 memset(retval, 0, sizeof(struct text_object));
3532 line = global_text_lines;
3540 obj = create_plain_text(s);
3542 append_object(retval, obj);
3552 /* variable is either $foo or ${foo} */
3554 unsigned int brl = 1, brr = 0;
3558 while (*p && brl != brr) {
3573 while (*p && (isalnum((int) *p) || *p == '_')) {
3578 /* copy variable to buffer */
3579 len = (p - s > 255) ? 255 : (p - s);
3580 strncpy(buf, s, len);
3588 /* search for variable in environment */
3592 obj = create_plain_text(var);
3594 append_object(retval, obj);
3599 /* if variable wasn't found in environment, use some special */
3604 if (strchr(buf, ' ')) {
3605 arg = strchr(buf, ' ');
3608 while (isspace((int) *arg)) {
3616 /* lowercase variable name */
3619 *tmp_p = tolower(*tmp_p);
3623 obj = construct_text_object(buf, arg,
3624 line, &ifblock_opaque, orig_p);
3626 append_object(retval, obj);
3630 obj = create_plain_text("$");
3633 append_object(retval, obj);
3636 } else if (*p == '\\' && *(p+1) == '#') {
3638 } else if (*p == '#') {
3640 if (remove_comment(p, &c) && p > orig_p && c == '\n') {
3641 /* if remove_comment removed a newline, we need to 'back up' with p */
3647 obj = create_plain_text(s);
3649 append_object(retval, obj);
3652 if (!ifblock_stack_empty(&ifblock_opaque)) {
3653 NORM_ERR("one or more $endif's are missing");
3660 static void extract_variable_text(const char *p)
3662 free_text_objects(&global_root_object, 0);
3676 extract_variable_text_internal(&global_root_object, p);
3679 void parse_conky_vars(struct text_object *root, const char *txt, char *p, struct information *cur)
3681 extract_variable_text_internal(root, txt);
3682 generate_text_internal(p, max_user_text, *root, cur);
3685 static inline struct mail_s *ensure_mail_thread(struct text_object *obj,
3686 void *thread(void *), const char *text)
3688 if (obj->char_b && info.mail) {
3689 // this means we use info
3690 if (!info.mail->p_timed_thread) {
3691 info.mail->p_timed_thread =
3692 timed_thread_create(thread,
3693 (void *) info.mail, info.mail->interval * 1000000);
3694 if (!info.mail->p_timed_thread) {
3695 NORM_ERR("Error creating %s timed thread", text);
3697 timed_thread_register(info.mail->p_timed_thread,
3698 &info.mail->p_timed_thread);
3699 if (timed_thread_run(info.mail->p_timed_thread)) {
3700 NORM_ERR("Error running %s timed thread", text);
3704 } else if (obj->data.mail) {
3705 // this means we use obj
3706 if (!obj->data.mail->p_timed_thread) {
3707 obj->data.mail->p_timed_thread =
3708 timed_thread_create(thread,
3709 (void *) obj->data.mail,
3710 obj->data.mail->interval * 1000000);
3711 if (!obj->data.mail->p_timed_thread) {
3712 NORM_ERR("Error creating %s timed thread", text);
3714 timed_thread_register(obj->data.mail->p_timed_thread,
3715 &obj->data.mail->p_timed_thread);
3716 if (timed_thread_run(obj->data.mail->p_timed_thread)) {
3717 NORM_ERR("Error running %s timed thread", text);
3720 return obj->data.mail;
3721 } else if (!obj->a) {
3722 // something is wrong, warn once then stop
3723 NORM_ERR("There's a problem with your mail settings. "
3724 "Check that the global mail settings are properly defined"
3725 " (line %li).", obj->line);
3731 char *format_time(unsigned long timeval, const int width)
3734 unsigned long nt; // narrow time, for speed on 32-bit
3735 unsigned cc; // centiseconds
3736 unsigned nn; // multi-purpose whatever
3739 cc = nt % 100; // centiseconds past second
3740 nt /= 100; // total seconds
3741 nn = nt % 60; // seconds past the minute
3742 nt /= 60; // total minutes
3743 if (width >= snprintf(buf, sizeof buf, "%lu:%02u.%02u",
3745 return strndup(buf, text_buffer_size);
3747 if (width >= snprintf(buf, sizeof buf, "%lu:%02u", nt, nn)) {
3748 return strndup(buf, text_buffer_size);
3750 nn = nt % 60; // minutes past the hour
3751 nt /= 60; // total hours
3752 if (width >= snprintf(buf, sizeof buf, "%lu,%02u", nt, nn)) {
3753 return strndup(buf, text_buffer_size);
3755 nn = nt; // now also hours
3756 if (width >= snprintf(buf, sizeof buf, "%uh", nn)) {
3757 return strndup(buf, text_buffer_size);
3759 nn /= 24; // now days
3760 if (width >= snprintf(buf, sizeof buf, "%ud", nn)) {
3761 return strndup(buf, text_buffer_size);
3763 nn /= 7; // now weeks
3764 if (width >= snprintf(buf, sizeof buf, "%uw", nn)) {
3765 return strndup(buf, text_buffer_size);
3767 // well shoot, this outta' fit...
3768 return strndup("<inf>", text_buffer_size);
3771 //remove backspaced chars, example: "dog^H^H^Hcat" becomes "cat"
3772 //string has to end with \0 and it's length should fit in a int
3774 void remove_deleted_chars(char *string){
3776 while(string[i] != 0){
3777 if(string[i] == BACKSPACE){
3779 strcpy( &(string[i-1]), &(string[i+1]) );
3781 }else strcpy( &(string[i]), &(string[i+1]) ); //necessary for ^H's at the start of a string
3786 static inline void format_media_player_time(char *buf, const int size,
3789 int days, hours, minutes;
3791 days = seconds / (24 * 60 * 60);
3792 seconds %= (24 * 60 * 60);
3793 hours = seconds / (60 * 60);
3794 seconds %= (60 * 60);
3795 minutes = seconds / 60;
3799 snprintf(buf, size, "%i days %i:%02i:%02i", days,
3800 hours, minutes, seconds);
3801 } else if (hours > 0) {
3802 snprintf(buf, size, "%i:%02i:%02i", hours, minutes,
3805 snprintf(buf, size, "%i:%02i", minutes, seconds);
3809 static inline double get_barnum(char *buf)
3821 if (sscanf(buf, "%lf", &barnum) == 0) {
3822 NORM_ERR("reading exec value failed (perhaps it's not the "
3823 "correct format?)");
3826 if (barnum > 100.0 || barnum < 0.0) {
3827 NORM_ERR("your exec value is not between 0 and 100, "
3828 "therefore it will be ignored");
3834 /* substitutes all occurrences of '\n' with SECRIT_MULTILINE_CHAR, which allows
3835 * multiline objects like $exec work with $align[rc] and friends
3837 void substitute_newlines(char *p, long l)
3841 while (p && *p && p < s + l) {
3843 /* only substitute if it's not the last newline */
3844 *p = SECRIT_MULTILINE_CHAR;
3850 static void generate_text_internal(char *p, int p_max_size,
3851 struct text_object root, struct information *cur)
3853 struct text_object *obj;
3855 int need_to_load_fonts = 0;
3858 /* for the OBJ_top* handler */
3859 struct process **needed = 0;
3862 char buff_in[p_max_size];
3864 iconv_converting = 0;
3865 #endif /* HAVE_ICONV */
3869 while (obj && p_max_size > 0) {
3870 needed = 0; /* reset for top stuff */
3872 /* IFBLOCK jumping algorithm
3874 * This is easier as it looks like:
3875 * - each IF checks it's condition
3876 * - on FALSE: call DO_JUMP
3877 * - on TRUE: don't care
3878 * - each ELSE calls DO_JUMP unconditionally
3879 * - each ENDIF is silently being ignored
3882 * DO_JUMP overwrites the "obj" variable of the loop and sets it to the target
3883 * (i.e. the corresponding ELSE or ENDIF). After that, processing for the given
3884 * object can continue, free()ing stuff e.g., then the for-loop does the rest: as
3885 * regularly, "obj" is being updated to point to obj->next, so object parsing
3886 * continues right after the corresponding ELSE or ENDIF. This means that if we
3887 * find an ELSE, it's corresponding IF must not have jumped, so we need to jump
3888 * always. If we encounter an ENDIF, it's corresponding IF or ELSE has not
3889 * jumped, and there is nothing to do.
3893 obj = obj->data.ifblock.next; \
3896 #define OBJ(a) break; case OBJ_##a:
3898 switch (obj->type) {
3900 NORM_ERR("not implemented obj type %d", obj->type);
3903 struct sockaddr_in addr;
3904 struct hostent* he = gethostbyname(obj->data.read_tcp.host);
3906 sock = socket(he->h_addrtype, SOCK_STREAM, 0);
3908 memset(&addr, 0, sizeof(addr));
3909 addr.sin_family = AF_INET;
3910 addr.sin_port = obj->data.read_tcp.port;
3911 memcpy(&addr.sin_addr, he->h_addr, he->h_length);
3912 if (connect(sock, (struct sockaddr*)&addr, sizeof(struct sockaddr)) == 0) {
3916 FD_SET(sock, &readfds);
3919 if(select(sock + 1, &readfds, NULL, NULL, &tv) > 0){
3920 received = recv(sock, p, p_max_size, 0);
3925 NORM_ERR("read_tcp: Couldn't create a connection");
3928 NORM_ERR("read_tcp: Couldn't create a socket");
3931 NORM_ERR("read_tcp: Problem with resolving the hostname");
3936 temp_print(p, p_max_size, get_acpi_temperature(obj->data.i), TEMP_CELSIUS);
3938 #endif /* !__OpenBSD__ */
3941 obj->a = get_freq(p, p_max_size, "%.0f", 1,
3942 obj->data.cpu_index);
3948 obj->a = get_freq(p, p_max_size, "%'.2f", 1000,
3949 obj->data.cpu_index);
3951 /* OpenBSD has no such flag (SUSv2) */
3952 obj->a = get_freq(p, p_max_size, "%.2f", 1000,
3953 obj->data.cpu_index);
3954 #endif /* __OpenBSD */
3957 #if defined(__linux__)
3960 obj->a = get_voltage(p, p_max_size, "%.0f", 1,
3961 obj->data.cpu_index);
3966 obj->a = get_voltage(p, p_max_size, "%'.3f", 1000,
3967 obj->data.cpu_index);
3972 OBJ(wireless_essid) {
3973 snprintf(p, p_max_size, "%s", obj->data.net->essid);
3975 OBJ(wireless_mode) {
3976 snprintf(p, p_max_size, "%s", obj->data.net->mode);
3978 OBJ(wireless_bitrate) {
3979 snprintf(p, p_max_size, "%s", obj->data.net->bitrate);
3982 snprintf(p, p_max_size, "%s", obj->data.net->ap);
3984 OBJ(wireless_link_qual) {
3985 spaced_print(p, p_max_size, "%d", 4,
3986 obj->data.net->link_qual);
3988 OBJ(wireless_link_qual_max) {
3989 spaced_print(p, p_max_size, "%d", 4,
3990 obj->data.net->link_qual_max);
3992 OBJ(wireless_link_qual_perc) {
3993 if (obj->data.net->link_qual_max > 0) {
3994 spaced_print(p, p_max_size, "%.0f", 5,
3995 (double) obj->data.net->link_qual /
3996 obj->data.net->link_qual_max * 100);
3998 spaced_print(p, p_max_size, "unk", 5);
4001 OBJ(wireless_link_bar) {
4003 if(output_methods & TO_X) {
4004 new_bar(p, obj->a, obj->b, ((double) obj->data.net->link_qual /
4005 obj->data.net->link_qual_max) * 255.0);
4008 if(!obj->a) obj->a = DEFAULT_BAR_WIDTH_NO_X;
4009 new_bar_in_shell(p, p_max_size, ((double) obj->data.net->link_qual /
4010 obj->data.net->link_qual_max) * 100.0, obj->a);
4015 #endif /* HAVE_IWLIB */
4017 #endif /* __linux__ */
4021 get_adt746x_cpu(p, p_max_size);
4024 get_adt746x_fan(p, p_max_size);
4027 get_acpi_fan(p, p_max_size);
4029 OBJ(acpiacadapter) {
4030 get_acpi_ac_adapter(p, p_max_size);
4033 get_battery_stuff(p, p_max_size, obj->data.s, BATTERY_STATUS);
4036 get_battery_stuff(p, p_max_size, obj->data.s, BATTERY_TIME);
4038 OBJ(battery_percent) {
4039 percent_print(p, p_max_size, get_battery_perct(obj->data.s));
4043 if(output_methods & TO_X) {
4044 new_bar(p, obj->a, obj->b, get_battery_perct_bar(obj->data.s));
4047 if(!obj->a) obj->a = DEFAULT_BAR_WIDTH_NO_X;
4048 new_bar_in_shell(p, p_max_size, get_battery_perct_bar(obj->data.s) / 2.55, obj->a);
4053 OBJ(battery_short) {
4054 get_battery_short_status(p, p_max_size, obj->data.s);
4056 #endif /* __OpenBSD__ */
4059 human_readable(cur->buffers * 1024, p, 255);
4062 human_readable(cur->cached * 1024, p, 255);
4065 if (obj->data.cpu_index > info.cpu_count) {
4066 NORM_ERR("obj->data.cpu_index %i info.cpu_count %i",
4067 obj->data.cpu_index, info.cpu_count);
4068 CRIT_ERR(NULL, NULL, "attempting to use more CPUs than you have!");
4070 percent_print(p, p_max_size,
4071 round_to_int(cur->cpu_usage[obj->data.cpu_index] * 100.0));
4075 new_gauge(p, obj->a, obj->b,
4076 round_to_int(cur->cpu_usage[obj->data.cpu_index] * 255.0));
4080 if(output_methods & TO_X) {
4081 new_bar(p, obj->a, obj->b,
4082 round_to_int(cur->cpu_usage[obj->data.cpu_index] * 255.0));
4085 if(!obj->a) obj->a = DEFAULT_BAR_WIDTH_NO_X;
4086 new_bar_in_shell(p, p_max_size, round_to_int(cur->cpu_usage[obj->data.cpu_index] * 100), obj->a);
4093 new_graph(p, obj->a, obj->b, obj->c, obj->d,
4094 round_to_int(cur->cpu_usage[obj->data.cpu_index] * 100),
4095 100, 1, obj->char_a, obj->char_b);
4098 new_graph(p, obj->a, obj->b, obj->c, obj->d, cur->loadavg[0],
4099 obj->e, 1, obj->char_a, obj->char_b);
4102 new_fg(p, obj->data.l);
4135 OBJ(conky_version) {
4136 snprintf(p, p_max_size, "%s", VERSION);
4138 OBJ(conky_build_date) {
4139 snprintf(p, p_max_size, "%s", BUILD_DATE);
4141 OBJ(conky_build_arch) {
4142 snprintf(p, p_max_size, "%s", BUILD_ARCH);
4144 #if defined(__linux__)
4146 snprintf(p, p_max_size, "%s",
4147 get_disk_protect_queue(obj->data.s));
4150 snprintf(p, p_max_size, "%s", i8k.version);
4153 snprintf(p, p_max_size, "%s", i8k.bios);
4156 snprintf(p, p_max_size, "%s", i8k.serial);
4161 sscanf(i8k.cpu_temp, "%d", &cpu_temp);
4162 temp_print(p, p_max_size, (double)cpu_temp, TEMP_CELSIUS);
4164 OBJ(i8k_left_fan_status) {
4165 int left_fan_status;
4167 sscanf(i8k.left_fan_status, "%d", &left_fan_status);
4168 if (left_fan_status == 0) {
4169 snprintf(p, p_max_size, "off");
4171 if (left_fan_status == 1) {
4172 snprintf(p, p_max_size, "low");
4174 if (left_fan_status == 2) {
4175 snprintf(p, p_max_size, "high");
4178 OBJ(i8k_right_fan_status) {
4179 int right_fan_status;
4181 sscanf(i8k.right_fan_status, "%d", &right_fan_status);
4182 if (right_fan_status == 0) {
4183 snprintf(p, p_max_size, "off");
4185 if (right_fan_status == 1) {
4186 snprintf(p, p_max_size, "low");
4188 if (right_fan_status == 2) {
4189 snprintf(p, p_max_size, "high");
4192 OBJ(i8k_left_fan_rpm) {
4193 snprintf(p, p_max_size, "%s", i8k.left_fan_rpm);
4195 OBJ(i8k_right_fan_rpm) {
4196 snprintf(p, p_max_size, "%s", i8k.right_fan_rpm);
4198 OBJ(i8k_ac_status) {
4201 sscanf(i8k.ac_status, "%d", &ac_status);
4202 if (ac_status == -1) {
4203 snprintf(p, p_max_size, "disabled (read i8k docs)");
4205 if (ac_status == 0) {
4206 snprintf(p, p_max_size, "off");
4208 if (ac_status == 1) {
4209 snprintf(p, p_max_size, "on");
4212 OBJ(i8k_buttons_status) {
4213 snprintf(p, p_max_size, "%s", i8k.buttons_status);
4217 get_ibm_acpi_fan(p, p_max_size);
4220 get_ibm_acpi_temps();
4221 temp_print(p, p_max_size,
4222 ibm_acpi.temps[obj->data.sensor], TEMP_CELSIUS);
4225 get_ibm_acpi_volume(p, p_max_size);
4227 OBJ(ibm_brightness) {
4228 get_ibm_acpi_brightness(p, p_max_size);
4231 /* information from sony_laptop kernel module
4232 * /sys/devices/platform/sony-laptop */
4233 OBJ(sony_fanspeed) {
4234 get_sony_fanspeed(p, p_max_size);
4237 if (!cur->gw_info.count) {
4242 snprintf(p, p_max_size, "%s", cur->gw_info.iface);
4245 snprintf(p, p_max_size, "%s", cur->gw_info.ip);
4248 snprintf(p, p_max_size, "%d", get_laptop_mode());
4251 get_powerbook_batt_info(p, p_max_size, obj->data.i);
4253 #endif /* __linux__ */
4254 #if (defined(__FreeBSD__) || defined(__linux__))
4256 if ((obj->data.ifblock.s)
4257 && (!interface_up(obj->data.ifblock.s))) {
4263 OBJ(obsd_sensors_temp) {
4264 obsd_sensors.device = sensor_device;
4265 update_obsd_sensors();
4266 temp_print(p, p_max_size,
4267 obsd_sensors.temp[obsd_sensors.device][obj->data.sensor],
4270 OBJ(obsd_sensors_fan) {
4271 obsd_sensors.device = sensor_device;
4272 update_obsd_sensors();
4273 snprintf(p, p_max_size, "%d",
4274 obsd_sensors.fan[obsd_sensors.device][obj->data.sensor]);
4276 OBJ(obsd_sensors_volt) {
4277 obsd_sensors.device = sensor_device;
4278 update_obsd_sensors();
4279 snprintf(p, p_max_size, "%.2f",
4280 obsd_sensors.volt[obsd_sensors.device][obj->data.sensor]);
4283 get_obsd_vendor(p, p_max_size);
4286 get_obsd_product(p, p_max_size);
4288 #endif /* __OpenBSD__ */
4291 new_font(p, obj->data.s);
4292 need_to_load_fonts = 1;
4295 /* TODO: move this correction from kB to kB/s elsewhere
4296 * (or get rid of it??) */
4298 human_readable((obj->data.diskio->current / update_interval) * 1024LL,
4302 human_readable((obj->data.diskio->current_write / update_interval) * 1024LL,
4306 human_readable((obj->data.diskio->current_read / update_interval) * 1024LL,
4311 new_graph(p, obj->a, obj->b, obj->c, obj->d,
4312 obj->data.diskio->current, obj->e, 1, obj->char_a, obj->char_b);
4314 OBJ(diskiograph_read) {
4315 new_graph(p, obj->a, obj->b, obj->c, obj->d,
4316 obj->data.diskio->current_read, obj->e, 1, obj->char_a, obj->char_b);
4318 OBJ(diskiograph_write) {
4319 new_graph(p, obj->a, obj->b, obj->c, obj->d,
4320 obj->data.diskio->current_write, obj->e, 1, obj->char_a, obj->char_b);
4324 human_readable(obj->data.net->recv_speed, p, 255);
4327 spaced_print(p, p_max_size, "%.1f", 8,
4328 obj->data.net->recv_speed / 1024.0);
4331 OBJ(downspeedgraph) {
4332 new_graph(p, obj->a, obj->b, obj->c, obj->d,
4333 obj->data.net->recv_speed / 1024.0, obj->e, 1, obj->char_a, obj->char_b);
4337 /* Since we see you, you're if has not jumped.
4338 * Do Ninja jump here: without leaving traces.
4339 * This is to prevent us from stale jumped flags.
4341 obj = obj->data.ifblock.next;
4345 /* harmless object, just ignore */
4348 if ((obj->data.net->addr.sa_data[2] & 255) == 0
4349 && (obj->data.net->addr.sa_data[3] & 255) == 0
4350 && (obj->data.net->addr.sa_data[4] & 255) == 0
4351 && (obj->data.net->addr.sa_data[5] & 255) == 0) {
4352 snprintf(p, p_max_size, "No Address");
4354 snprintf(p, p_max_size, "%u.%u.%u.%u",
4355 obj->data.net->addr.sa_data[2] & 255,
4356 obj->data.net->addr.sa_data[3] & 255,
4357 obj->data.net->addr.sa_data[4] & 255,
4358 obj->data.net->addr.sa_data[5] & 255);
4361 #if defined(__linux__)
4363 if (NULL != obj->data.net->addrs && strlen(obj->data.net->addrs) > 2) {
4364 obj->data.net->addrs[strlen(obj->data.net->addrs) - 2] = 0; /* remove ", " from end of string */
4365 strcpy(p, obj->data.net->addrs);
4367 strcpy(p, "0.0.0.0");
4370 #endif /* __linux__ */
4371 #if defined(IMLIB2) && defined(X11)
4373 /* doesn't actually draw anything, just queues it omp. the
4374 * image will get drawn after the X event loop */
4375 cimlib_add_image(obj->data.s);
4379 evaluate(obj->data.s, p);
4382 read_exec(obj->data.s, p, text_buffer_size);
4383 remove_deleted_chars(p);
4386 struct information *tmp_info;
4387 struct text_object subroot;
4389 read_exec(obj->data.s, p, text_buffer_size);
4391 tmp_info = malloc(sizeof(struct information));
4392 memcpy(tmp_info, cur, sizeof(struct information));
4393 parse_conky_vars(&subroot, p, p, tmp_info);
4395 free_text_objects(&subroot, 1);
4402 read_exec(obj->data.s, p, text_buffer_size);
4403 barnum = get_barnum(p); /*using the same function*/
4405 if (barnum >= 0.0) {
4407 new_gauge(p, obj->a, obj->b, round_to_int(barnum * 255.0));
4414 read_exec(obj->data.s, p, text_buffer_size);
4415 barnum = get_barnum(p);
4417 if (barnum >= 0.0) {
4419 if(output_methods & TO_X) {
4421 new_bar(p, obj->a, obj->b, round_to_int(barnum * 255.0));
4424 if(!obj->a) obj->a = DEFAULT_BAR_WIDTH_NO_X;
4425 new_bar_in_shell(p, p_max_size, barnum, obj->a);
4433 char showaslog = FALSE;
4434 char tempgrad = FALSE;
4436 char *cmd = obj->data.s;
4438 if (strstr(cmd, " "TEMPGRAD) && strlen(cmd) > strlen(" "TEMPGRAD)) {
4440 cmd += strlen(" "TEMPGRAD);
4442 if (strstr(cmd, " "LOGGRAPH) && strlen(cmd) > strlen(" "LOGGRAPH)) {
4444 cmd += strlen(" "LOGGRAPH);
4446 read_exec(cmd, p, text_buffer_size);
4447 barnum = get_barnum(p);
4450 new_graph(p, obj->a, obj->b, obj->c, obj->d, round_to_int(barnum),
4451 100, 1, showaslog, tempgrad);
4456 if (current_update_time - obj->data.execi.last_update
4457 >= obj->data.execi.interval) {
4460 read_exec(obj->data.execi.cmd, p, text_buffer_size);
4461 barnum = get_barnum(p);
4463 if (barnum >= 0.0) {
4466 obj->data.execi.last_update = current_update_time;
4469 if(output_methods & TO_X) {
4470 new_bar(p, obj->a, obj->b, round_to_int(obj->f * 2.55));
4473 if(!obj->a) obj->a = DEFAULT_BAR_WIDTH_NO_X;
4474 new_bar_in_shell(p, p_max_size, round_to_int(obj->f), obj->a);
4481 if (current_update_time - obj->data.execi.last_update
4482 >= obj->data.execi.interval) {
4484 char showaslog = FALSE;
4485 char tempgrad = FALSE;
4486 char *cmd = obj->data.execi.cmd;
4488 if (strstr(cmd, " "TEMPGRAD) && strlen(cmd) > strlen(" "TEMPGRAD)) {
4490 cmd += strlen(" "TEMPGRAD);
4492 if (strstr(cmd, " "LOGGRAPH) && strlen(cmd) > strlen(" "LOGGRAPH)) {
4494 cmd += strlen(" "LOGGRAPH);
4496 obj->char_a = showaslog;
4497 obj->char_b = tempgrad;
4498 read_exec(cmd, p, text_buffer_size);
4499 barnum = get_barnum(p);
4501 if (barnum >= 0.0) {
4504 obj->data.execi.last_update = current_update_time;
4506 new_graph(p, obj->a, obj->b, obj->c, obj->d, (int) (obj->f), 100, 1, obj->char_a, obj->char_b);
4509 if (current_update_time - obj->data.execi.last_update
4510 >= obj->data.execi.interval) {
4513 read_exec(obj->data.execi.cmd, p, text_buffer_size);
4514 barnum = get_barnum(p);
4516 if (barnum >= 0.0) {
4517 obj->f = 255 * barnum / 100.0;
4519 obj->data.execi.last_update = current_update_time;
4521 new_gauge(p, obj->a, obj->b, round_to_int(obj->f));
4525 if (current_update_time - obj->data.execi.last_update
4526 >= obj->data.execi.interval
4527 && obj->data.execi.interval != 0) {
4528 read_exec(obj->data.execi.cmd, obj->data.execi.buffer,
4530 obj->data.execi.last_update = current_update_time;
4532 snprintf(p, text_buffer_size, "%s", obj->data.execi.buffer);
4535 struct text_object subroot;
4536 struct information *tmp_info =
4537 malloc(sizeof(struct information));
4538 memcpy(tmp_info, cur, sizeof(struct information));
4540 if (current_update_time - obj->data.execi.last_update
4541 < obj->data.execi.interval
4542 || obj->data.execi.interval == 0) {
4543 parse_conky_vars(&subroot, obj->data.execi.buffer, p, tmp_info);
4545 char *output = obj->data.execi.buffer;
4546 FILE *fp = pid_popen(obj->data.execi.cmd, "r", &childpid);
4547 int length = fread(output, 1, text_buffer_size, fp);
4551 output[length] = '\0';
4552 if (length > 0 && output[length - 1] == '\n') {
4553 output[length - 1] = '\0';
4556 parse_conky_vars(&subroot, obj->data.execi.buffer, p, tmp_info);
4557 obj->data.execi.last_update = current_update_time;
4559 free_text_objects(&subroot, 1);
4563 if (!obj->data.texeci.p_timed_thread) {
4564 obj->data.texeci.p_timed_thread =
4565 timed_thread_create(&threaded_exec,
4566 (void *) obj, obj->data.texeci.interval * 1000000);
4567 if (!obj->data.texeci.p_timed_thread) {
4568 NORM_ERR("Error creating texeci timed thread");
4571 * note that we don't register this thread with the
4572 * timed_thread list, because we destroy it manually
4574 if (timed_thread_run(obj->data.texeci.p_timed_thread)) {
4575 NORM_ERR("Error running texeci timed thread");
4578 timed_thread_lock(obj->data.texeci.p_timed_thread);
4579 snprintf(p, text_buffer_size, "%s", obj->data.texeci.buffer);
4580 timed_thread_unlock(obj->data.texeci.p_timed_thread);
4584 struct mail_s *mail = ensure_mail_thread(obj, imap_thread, "imap");
4586 if (mail && mail->p_timed_thread) {
4587 timed_thread_lock(mail->p_timed_thread);
4588 snprintf(p, p_max_size, "%lu", mail->unseen);
4589 timed_thread_unlock(mail->p_timed_thread);
4592 OBJ(imap_messages) {
4593 struct mail_s *mail = ensure_mail_thread(obj, imap_thread, "imap");
4595 if (mail && mail->p_timed_thread) {
4596 timed_thread_lock(mail->p_timed_thread);
4597 snprintf(p, p_max_size, "%lu", mail->messages);
4598 timed_thread_unlock(mail->p_timed_thread);
4602 struct mail_s *mail = ensure_mail_thread(obj, pop3_thread, "pop3");
4604 if (mail && mail->p_timed_thread) {
4605 timed_thread_lock(mail->p_timed_thread);
4606 snprintf(p, p_max_size, "%lu", mail->unseen);
4607 timed_thread_unlock(mail->p_timed_thread);
4611 struct mail_s *mail = ensure_mail_thread(obj, pop3_thread, "pop3");
4613 if (mail && mail->p_timed_thread) {
4614 timed_thread_lock(mail->p_timed_thread);
4615 snprintf(p, p_max_size, "%.1f",
4616 mail->used / 1024.0 / 1024.0);
4617 timed_thread_unlock(mail->p_timed_thread);
4621 if (obj->data.fs != NULL) {
4622 if (obj->data.fs->size == 0) {
4624 if(output_methods & TO_X) {
4625 new_bar(p, obj->data.fsbar.w, obj->data.fsbar.h, 255);
4628 if(!obj->data.fsbar.w) obj->data.fsbar.w = DEFAULT_BAR_WIDTH_NO_X;
4629 new_bar_in_shell(p, p_max_size, 100, obj->data.fsbar.w);
4635 if(output_methods & TO_X) {
4636 new_bar(p, obj->data.fsbar.w, obj->data.fsbar.h,
4637 (int) (255 - obj->data.fsbar.fs->avail * 255 /
4638 obj->data.fs->size));
4641 if(!obj->data.fsbar.w) obj->data.fsbar.w = DEFAULT_BAR_WIDTH_NO_X;
4642 new_bar_in_shell(p, p_max_size,
4643 (int) (100 - obj->data.fsbar.fs->avail * 100 / obj->data.fs->size), obj->data.fsbar.w);
4651 if (obj->data.fs != NULL) {
4652 human_readable(obj->data.fs->avail, p, 255);
4656 if (obj->data.fs != NULL) {
4659 if (obj->data.fs->size) {
4660 val = obj->data.fs->avail * 100 / obj->data.fs->size;
4663 percent_print(p, p_max_size, val);
4667 if (obj->data.fs != NULL) {
4668 human_readable(obj->data.fs->size, p, 255);
4672 if (obj->data.fs != NULL)
4673 snprintf(p, p_max_size, "%s", obj->data.fs->type);
4676 if (obj->data.fs != NULL) {
4677 human_readable(obj->data.fs->size - obj->data.fs->free, p,
4682 if (obj->data.fs != NULL) {
4683 if (obj->data.fs->size == 0) {
4685 if(output_methods & TO_X) {
4686 new_bar(p, obj->data.fsbar.w, obj->data.fsbar.h, 255);
4689 if(!obj->data.fsbar.w) obj->data.fsbar.w = DEFAULT_BAR_WIDTH_NO_X;
4690 new_bar_in_shell(p, p_max_size, 100, obj->data.fsbar.w);
4696 if(output_methods & TO_X) {
4697 new_bar(p, obj->data.fsbar.w, obj->data.fsbar.h,
4698 (int) (obj->data.fsbar.fs->avail * 255 /
4699 obj->data.fs->size));
4702 if(!obj->data.fsbar.w) obj->data.fsbar.w = DEFAULT_BAR_WIDTH_NO_X;
4703 new_bar_in_shell(p, p_max_size,
4704 (int) (obj->data.fsbar.fs->avail * 100 / obj->data.fs->size), obj->data.fsbar.w);
4712 if (obj->data.fs != NULL) {
4715 if (obj->data.fs->size) {
4716 val = obj->data.fs->free
4721 percent_print(p, p_max_size, 100 - val);
4725 float *v = info.loadavg;
4727 if (obj->data.loadavg[2]) {
4728 snprintf(p, p_max_size, "%.2f %.2f %.2f",
4729 v[obj->data.loadavg[0] - 1],
4730 v[obj->data.loadavg[1] - 1],
4731 v[obj->data.loadavg[2] - 1]);
4732 } else if (obj->data.loadavg[1]) {
4733 snprintf(p, p_max_size, "%.2f %.2f",
4734 v[obj->data.loadavg[0] - 1],
4735 v[obj->data.loadavg[1] - 1]);
4736 } else if (obj->data.loadavg[0]) {
4737 snprintf(p, p_max_size, "%.2f",
4738 v[obj->data.loadavg[0] - 1]);
4742 new_goto(p, obj->data.i);
4745 new_tab(p, obj->data.pair.a, obj->data.pair.b);
4749 new_hr(p, obj->data.i);
4753 if (cur->nameserver_info.nscount > obj->data.i)
4754 snprintf(p, p_max_size, "%s",
4755 cur->nameserver_info.ns_list[obj->data.i]);
4759 char *skill = eve(obj->data.eve.userid, obj->data.eve.apikey, obj->data.eve.charid);
4760 snprintf(p, p_max_size, "%s", skill);
4765 if (obj->data.curl.uri != NULL) {
4766 ccurl_process_info(p, p_max_size, obj->data.curl.uri, obj->data.curl.interval);
4768 NORM_ERR("error processing Curl data");
4774 if (obj->data.rss.uri != NULL) {
4775 rss_process_info(p, p_max_size, obj->data.rss.uri, obj->data.rss.action, obj->data.rss.act_par, obj->data.rss.interval, obj->data.rss.nrspaces);
4777 NORM_ERR("error processing RSS data");
4783 if (obj->data.weather.uri != NULL) {
4784 weather_process_info(p, p_max_size, obj->data.weather.uri, obj->data.weather.data_type, obj->data.weather.interval);
4786 NORM_ERR("error processing weather data, check that you have a valid XOAP key if using XOAP.");
4792 char *str = llua_getstring(obj->data.s);
4794 snprintf(p, p_max_size, "%s", str);
4799 char *str = llua_getstring(obj->data.s);
4807 if (llua_getnumber(obj->data.s, &per)) {
4809 if(output_methods & TO_X) {
4810 new_bar(p, obj->a, obj->b, (per/100.0 * 255));
4813 if(!obj->a) obj->a = DEFAULT_BAR_WIDTH_NO_X;
4814 new_bar_in_shell(p, p_max_size, per, obj->a);
4823 if (llua_getnumber(obj->data.s, &per)) {
4824 new_graph(p, obj->a, obj->b, obj->c, obj->d,
4825 per, obj->e, 1, obj->char_a, obj->char_b);
4830 if (llua_getnumber(obj->data.s, &per)) {
4831 new_gauge(p, obj->a, obj->b, (per/100.0 * 255));
4835 #endif /* HAVE_LUA */
4840 if (obj->data.hddtemp.update_time < current_update_time - 30) {
4841 if (obj->data.hddtemp.temp)
4842 free(obj->data.hddtemp.temp);
4843 obj->data.hddtemp.temp = get_hddtemp_info(obj->data.hddtemp.dev,
4844 obj->data.hddtemp.addr, obj->data.hddtemp.port);
4845 obj->data.hddtemp.update_time = current_update_time;
4847 if (!obj->data.hddtemp.temp) {
4848 snprintf(p, p_max_size, "N/A");
4850 val = strtol(obj->data.hddtemp.temp + 1, &endptr, 10);
4851 unit = obj->data.hddtemp.temp[0];
4853 if (*endptr != '\0')
4854 snprintf(p, p_max_size, "N/A");
4855 else if (unit == 'C')
4856 temp_print(p, p_max_size, (double)val, TEMP_CELSIUS);
4857 else if (unit == 'F')
4858 temp_print(p, p_max_size, (double)val, TEMP_FAHRENHEIT);
4860 snprintf(p, p_max_size, "N/A");
4865 new_offset(p, obj->data.i);
4868 new_voffset(p, obj->data.i);
4874 r = get_sysfs_info(&obj->data.sysfs.fd, obj->data.sysfs.arg,
4875 obj->data.sysfs.devtype, obj->data.sysfs.type);
4877 r = r * obj->data.sysfs.factor + obj->data.sysfs.offset;
4879 if (!strncmp(obj->data.sysfs.type, "temp", 4)) {
4880 temp_print(p, p_max_size, r, TEMP_CELSIUS);
4881 } else if (r >= 100.0 || r == 0) {
4882 snprintf(p, p_max_size, "%d", (int) r);
4884 snprintf(p, p_max_size, "%.1f", r);
4890 r = get_sysfs_info(&obj->data.sysfs.fd, obj->data.sysfs.arg,
4891 obj->data.sysfs.devtype, obj->data.sysfs.type);
4893 r = r * obj->data.sysfs.factor + obj->data.sysfs.offset;
4895 if (!strncmp(obj->data.sysfs.type, "temp", 4)) {
4896 temp_print(p, p_max_size, r, TEMP_CELSIUS);
4897 } else if (r >= 100.0 || r == 0) {
4898 snprintf(p, p_max_size, "%d", (int) r);
4900 snprintf(p, p_max_size, "%.1f", r);
4906 r = get_sysfs_info(&obj->data.sysfs.fd, obj->data.sysfs.arg,
4907 obj->data.sysfs.devtype, obj->data.sysfs.type);
4909 r = r * obj->data.sysfs.factor + obj->data.sysfs.offset;
4911 if (!strncmp(obj->data.sysfs.type, "temp", 4)) {
4912 temp_print(p, p_max_size, r, TEMP_CELSIUS);
4913 } else if (r >= 100.0 || r == 0) {
4914 snprintf(p, p_max_size, "%d", (int) r);
4916 snprintf(p, p_max_size, "%.1f", r);
4919 #endif /* __linux__ */
4921 new_alignr(p, obj->data.i);
4924 new_alignc(p, obj->data.i);
4927 char buf[max_user_text];
4928 struct information *tmp_info =
4929 malloc(sizeof(struct information));
4930 memcpy(tmp_info, cur, sizeof(struct information));
4931 generate_text_internal(buf, max_user_text,
4932 *obj->sub, tmp_info);
4934 if (strlen(buf) != 0) {
4940 char expression[max_user_text];
4942 struct information *tmp_info;
4944 tmp_info = malloc(sizeof(struct information));
4945 memcpy(tmp_info, cur, sizeof(struct information));
4946 generate_text_internal(expression, max_user_text,
4947 *obj->sub, tmp_info);
4948 DBGP("parsed arg into '%s'", expression);
4950 val = compare(expression);
4952 NORM_ERR("compare failed for expression '%s'",
4960 if (obj->data.ifblock.str
4961 && !check_contains(obj->data.ifblock.s,
4962 obj->data.ifblock.str)) {
4964 } else if (obj->data.ifblock.s
4965 && access(obj->data.ifblock.s, F_OK)) {
4970 if ((obj->data.ifblock.s)
4971 && (!check_mount(obj->data.ifblock.s))) {
4977 if (!get_process_by_name(obj->data.ifblock.s)) {
4979 if ((obj->data.ifblock.s) && system(obj->data.ifblock.s)) {
4984 #if defined(__linux__)
4986 snprintf(p, p_max_size, "%s", get_ioscheduler(obj->data.s));
4990 snprintf(p, p_max_size, "%s", cur->uname_s.release);
4993 snprintf(p, p_max_size, "%s", cur->uname_s.machine);
4998 human_readable(cur->mem * 1024, p, 255);
5001 human_readable(cur->memeasyfree * 1024, p, 255);
5004 human_readable(cur->memfree * 1024, p, 255);
5007 human_readable(cur->memmax * 1024, p, 255);
5011 percent_print(p, p_max_size, cur->mem * 100 / cur->memmax);
5015 new_gauge(p, obj->data.pair.a, obj->data.pair.b,
5016 cur->memmax ? (cur->mem * 255) / (cur->memmax) : 0);
5021 if(output_methods & TO_X) {
5022 new_bar(p, obj->data.pair.a, obj->data.pair.b,
5023 cur->memmax ? (cur->mem * 255) / (cur->memmax) : 0);
5026 if(!obj->data.pair.a) obj->data.pair.a = DEFAULT_BAR_WIDTH_NO_X;
5027 new_bar_in_shell(p, p_max_size, cur->memmax ? (cur->mem * 100) / (cur->memmax) : 0, obj->data.pair.a);
5034 new_graph(p, obj->a, obj->b, obj->c, obj->d,
5035 cur->memmax ? (cur->mem * 100.0) / (cur->memmax) : 0.0,
5036 100, 1, obj->char_a, obj->char_b);
5041 percent_print(p, p_max_size, mixer_get_avg(obj->data.l));
5044 percent_print(p, p_max_size, mixer_get_left(obj->data.l));
5047 percent_print(p, p_max_size, mixer_get_right(obj->data.l));
5051 new_bar(p, obj->data.mixerbar.w, obj->data.mixerbar.h,
5052 mixer_to_255(obj->data.mixerbar.l,mixer_get_avg(obj->data.mixerbar.l)));
5055 new_bar(p, obj->data.mixerbar.w, obj->data.mixerbar.h,
5056 mixer_to_255(obj->data.mixerbar.l,mixer_get_left(obj->data.mixerbar.l)));
5059 new_bar(p, obj->data.mixerbar.w, obj->data.mixerbar.h,
5060 mixer_to_255(obj->data.mixerbar.l,mixer_get_right(obj->data.mixerbar.l)));
5063 OBJ(if_mixer_mute) {
5064 if (!mixer_is_mute(obj->data.ifblock.i)) {
5069 #define NOT_IN_X "Not running in X"
5071 if(x_initialised != YES) {
5072 strncpy(p, NOT_IN_X, p_max_size);
5074 snprintf(p, p_max_size, "%d", cur->x11.monitor.current);
5077 OBJ(monitor_number) {
5078 if(x_initialised != YES) {
5079 strncpy(p, NOT_IN_X, p_max_size);
5081 snprintf(p, p_max_size, "%d", cur->x11.monitor.number);
5085 if(x_initialised != YES) {
5086 strncpy(p, NOT_IN_X, p_max_size);
5088 snprintf(p, p_max_size, "%d", cur->x11.desktop.current);
5091 OBJ(desktop_number) {
5092 if(x_initialised != YES) {
5093 strncpy(p, NOT_IN_X, p_max_size);
5095 snprintf(p, p_max_size, "%d", cur->x11.desktop.number);
5099 if(x_initialised != YES) {
5100 strncpy(p, NOT_IN_X, p_max_size);
5101 }else if(cur->x11.desktop.name != NULL) {
5102 strncpy(p, cur->x11.desktop.name, p_max_size);
5109 update_mail_count(&obj->data.local_mail);
5110 snprintf(p, p_max_size, "%d", obj->data.local_mail.mail_count);
5113 update_mail_count(&obj->data.local_mail);
5114 snprintf(p, p_max_size, "%d",
5115 obj->data.local_mail.new_mail_count);
5118 update_mail_count(&obj->data.local_mail);
5119 snprintf(p, p_max_size, "%d",
5120 obj->data.local_mail.seen_mail_count);
5123 update_mail_count(&obj->data.local_mail);
5124 snprintf(p, p_max_size, "%d",
5125 obj->data.local_mail.unseen_mail_count);
5127 OBJ(flagged_mails) {
5128 update_mail_count(&obj->data.local_mail);
5129 snprintf(p, p_max_size, "%d",
5130 obj->data.local_mail.flagged_mail_count);
5132 OBJ(unflagged_mails) {
5133 update_mail_count(&obj->data.local_mail);
5134 snprintf(p, p_max_size, "%d",
5135 obj->data.local_mail.unflagged_mail_count);
5137 OBJ(forwarded_mails) {
5138 update_mail_count(&obj->data.local_mail);
5139 snprintf(p, p_max_size, "%d",
5140 obj->data.local_mail.forwarded_mail_count);
5142 OBJ(unforwarded_mails) {
5143 update_mail_count(&obj->data.local_mail);
5144 snprintf(p, p_max_size, "%d",
5145 obj->data.local_mail.unforwarded_mail_count);
5147 OBJ(replied_mails) {
5148 update_mail_count(&obj->data.local_mail);
5149 snprintf(p, p_max_size, "%d",
5150 obj->data.local_mail.replied_mail_count);
5152 OBJ(unreplied_mails) {
5153 update_mail_count(&obj->data.local_mail);
5154 snprintf(p, p_max_size, "%d",
5155 obj->data.local_mail.unreplied_mail_count);
5158 update_mail_count(&obj->data.local_mail);
5159 snprintf(p, p_max_size, "%d",
5160 obj->data.local_mail.draft_mail_count);
5162 OBJ(trashed_mails) {
5163 update_mail_count(&obj->data.local_mail);
5164 snprintf(p, p_max_size, "%d",
5165 obj->data.local_mail.trashed_mail_count);
5168 mbox_scan(obj->data.mboxscan.args, obj->data.mboxscan.output,
5170 snprintf(p, p_max_size, "%s", obj->data.mboxscan.output);
5173 snprintf(p, p_max_size, "%s", cur->uname_s.nodename);
5176 new_outline(p, obj->data.l);
5179 spaced_print(p, p_max_size, "%hu", 4, cur->procs);
5181 OBJ(running_processes) {
5182 spaced_print(p, p_max_size, "%hu", 4, cur->run_procs);
5185 snprintf(p, p_max_size, "%s", obj->data.s);
5189 new_bg(p, obj->data.l);
5192 new_stippled_hr(p, obj->data.pair.a, obj->data.pair.b);
5196 human_readable(cur->swap * 1024, p, 255);
5199 human_readable(cur->swapfree * 1024, p, 255);
5202 human_readable(cur->swapmax * 1024, p, 255);
5205 if (cur->swapmax == 0) {
5206 strncpy(p, "No swap", p_max_size);
5208 percent_print(p, p_max_size, cur->swap * 100 / cur->swapmax);
5213 if(output_methods & TO_X) {
5214 new_bar(p, obj->data.pair.a, obj->data.pair.b,
5215 cur->swapmax ? (cur->swap * 255) / (cur->swapmax) : 0);
5218 if(!obj->data.pair.a) obj->data.pair.a = DEFAULT_BAR_WIDTH_NO_X;
5219 new_bar_in_shell(p, p_max_size, cur->swapmax ? (cur->swap * 100) / (cur->swapmax) : 0, obj->data.pair.a);
5225 snprintf(p, p_max_size, "%s", cur->uname_s.sysname);
5228 time_t t = time(NULL);
5229 struct tm *tm = localtime(&t);
5231 setlocale(LC_TIME, "");
5232 strftime(p, p_max_size, obj->data.s, tm);
5235 time_t t = time(NULL);
5236 struct tm *tm = gmtime(&t);
5238 strftime(p, p_max_size, obj->data.s, tm);
5245 if (obj->data.tztime.tz) {
5246 oldTZ = getenv("TZ");
5247 setenv("TZ", obj->data.tztime.tz, 1);
5253 setlocale(LC_TIME, "");
5254 strftime(p, p_max_size, obj->data.tztime.fmt, tm);
5256 setenv("TZ", oldTZ, 1);
5261 // Needless to free oldTZ since getenv gives ptr to static data
5264 human_readable(obj->data.net->recv, p, 255);
5267 human_readable(obj->data.net->trans, p, 255);
5270 snprintf(p, p_max_size, "%d", total_updates);
5273 if(total_updates % updatereset != obj->data.ifblock.i - 1) {
5278 human_readable(obj->data.net->trans_speed, p, 255);
5281 spaced_print(p, p_max_size, "%.1f", 8,
5282 obj->data.net->trans_speed / 1024.0);
5286 new_graph(p, obj->a, obj->b, obj->c, obj->d,
5287 obj->data.net->trans_speed / 1024.0, obj->e, 1, obj->char_a, obj->char_b);
5291 format_seconds_short(p, p_max_size, (int) cur->uptime);
5294 format_seconds(p, p_max_size, (int) cur->uptime);
5297 snprintf(p, p_max_size, "%s", cur->users.names);
5300 snprintf(p, p_max_size, "%s", cur->users.terms);
5303 snprintf(p, p_max_size, "%s", cur->users.times);
5306 snprintf(p, p_max_size, "%d", cur->users.number);
5308 #if (defined(__FreeBSD__) || defined(__FreeBSD_kernel__) \
5309 || defined(__OpenBSD__)) && (defined(i386) || defined(__i386__))
5313 msg = get_apm_adapter();
5314 snprintf(p, p_max_size, "%s", msg);
5317 OBJ(apm_battery_life) {
5320 msg = get_apm_battery_life();
5321 snprintf(p, p_max_size, "%s", msg);
5324 OBJ(apm_battery_time) {
5327 msg = get_apm_battery_time();
5328 snprintf(p, p_max_size, "%s", msg);
5331 #endif /* __FreeBSD__ __OpenBSD__ */
5334 #define mpd_printf(fmt, val) \
5335 snprintf(p, p_max_size, fmt, mpd_get_info()->val)
5336 #define mpd_sprintf(val) { \
5337 if (!obj->data.i || obj->data.i > p_max_size) \
5338 mpd_printf("%s", val); \
5340 snprintf(p, obj->data.i, "%s", mpd_get_info()->val); \
5345 mpd_sprintf(artist);
5349 mpd_printf("%s", random);
5351 mpd_printf("%s", repeat);
5359 mpd_printf("%d", volume);
5361 mpd_printf("%d", bitrate);
5363 mpd_printf("%s", status);
5365 format_media_player_time(p, p_max_size, mpd_get_info()->elapsed);
5368 format_media_player_time(p, p_max_size, mpd_get_info()->length);
5371 percent_print(p, p_max_size, (int)(mpd_get_info()->progress * 100));
5375 if(output_methods & TO_X) {
5376 new_bar(p, obj->data.pair.a, obj->data.pair.b,
5377 (int) (mpd_get_info()->progress * 255.0f));
5380 if(!obj->data.pair.a) obj->data.pair.a = DEFAULT_BAR_WIDTH_NO_X;
5381 new_bar_in_shell(p, p_max_size, (int) (mpd_get_info()->progress * 100.0f), obj->data.pair.a);
5387 struct mpd_s *mpd = mpd_get_info();
5388 int len = obj->data.i;
5389 if (len == 0 || len > p_max_size)
5392 memset(p, 0, p_max_size);
5393 if (mpd->artist && *mpd->artist &&
5394 mpd->title && *mpd->title) {
5395 snprintf(p, len, "%s - %s", mpd->artist,
5397 } else if (mpd->title && *mpd->title) {
5398 snprintf(p, len, "%s", mpd->title);
5399 } else if (mpd->artist && *mpd->artist) {
5400 snprintf(p, len, "%s", mpd->artist);
5401 } else if (mpd->file && *mpd->file) {
5402 snprintf(p, len, "%s", mpd->file);
5407 OBJ(if_mpd_playing) {
5408 if (!mpd_get_info()->is_playing) {
5417 #define MOC_PRINT(t, a) \
5418 snprintf(p, p_max_size, "%s", (moc.t ? moc.t : a))
5420 MOC_PRINT(state, "??");
5423 MOC_PRINT(file, "no file");
5426 MOC_PRINT(title, "no title");
5429 MOC_PRINT(artist, "no artist");
5432 MOC_PRINT(song, "no song");
5435 MOC_PRINT(album, "no album");
5437 OBJ(moc_totaltime) {
5438 MOC_PRINT(totaltime, "0:00");
5441 MOC_PRINT(timeleft, "0:00");
5444 MOC_PRINT(curtime, "0:00");
5447 MOC_PRINT(bitrate, "0Kbps");
5450 MOC_PRINT(rate, "0KHz");
5456 snprintf(p, p_max_size, "%s", cur->xmms2.artist);
5459 snprintf(p, p_max_size, "%s", cur->xmms2.album);
5462 snprintf(p, p_max_size, "%s", cur->xmms2.title);
5465 snprintf(p, p_max_size, "%s", cur->xmms2.genre);
5467 OBJ(xmms2_comment) {
5468 snprintf(p, p_max_size, "%s", cur->xmms2.comment);
5471 snprintf(p, p_max_size, "%s", cur->xmms2.url);
5474 snprintf(p, p_max_size, "%s", cur->xmms2.status);
5477 snprintf(p, p_max_size, "%s", cur->xmms2.date);
5479 OBJ(xmms2_tracknr) {
5480 if (cur->xmms2.tracknr != -1) {
5481 snprintf(p, p_max_size, "%i", cur->xmms2.tracknr);
5484 OBJ(xmms2_bitrate) {
5485 snprintf(p, p_max_size, "%i", cur->xmms2.bitrate);
5488 snprintf(p, p_max_size, "%u", cur->xmms2.id);
5491 snprintf(p, p_max_size, "%2.1f", cur->xmms2.size);
5493 OBJ(xmms2_elapsed) {
5494 snprintf(p, p_max_size, "%02d:%02d", cur->xmms2.elapsed / 60000,
5495 (cur->xmms2.elapsed / 1000) % 60);
5497 OBJ(xmms2_duration) {
5498 snprintf(p, p_max_size, "%02d:%02d",
5499 cur->xmms2.duration / 60000,
5500 (cur->xmms2.duration / 1000) % 60);
5502 OBJ(xmms2_percent) {
5503 snprintf(p, p_max_size, "%2.0f", cur->xmms2.progress * 100);
5507 new_bar(p, obj->data.pair.a, obj->data.pair.b,
5508 (int) (cur->xmms2.progress * 255.0f));
5511 OBJ(xmms2_playlist) {
5512 snprintf(p, p_max_size, "%s", cur->xmms2.playlist);
5514 OBJ(xmms2_timesplayed) {
5515 snprintf(p, p_max_size, "%i", cur->xmms2.timesplayed);
5518 if (strlen(cur->xmms2.title) < 2
5519 && strlen(cur->xmms2.title) < 2) {
5520 snprintf(p, p_max_size, "%s", cur->xmms2.url);
5522 snprintf(p, p_max_size, "%s - %s", cur->xmms2.artist,
5526 OBJ(if_xmms2_connected) {
5527 if (cur->xmms2.conn_state != 1) {
5533 OBJ(audacious_status) {
5534 snprintf(p, p_max_size, "%s",
5535 cur->audacious.items[AUDACIOUS_STATUS]);
5537 OBJ(audacious_title) {
5538 snprintf(p, cur->audacious.max_title_len > 0
5539 ? cur->audacious.max_title_len : p_max_size, "%s",
5540 cur->audacious.items[AUDACIOUS_TITLE]);
5542 OBJ(audacious_length) {
5543 snprintf(p, p_max_size, "%s",
5544 cur->audacious.items[AUDACIOUS_LENGTH]);
5546 OBJ(audacious_length_seconds) {
5547 snprintf(p, p_max_size, "%s",
5548 cur->audacious.items[AUDACIOUS_LENGTH_SECONDS]);
5550 OBJ(audacious_position) {
5551 snprintf(p, p_max_size, "%s",
5552 cur->audacious.items[AUDACIOUS_POSITION]);
5554 OBJ(audacious_position_seconds) {
5555 snprintf(p, p_max_size, "%s",
5556 cur->audacious.items[AUDACIOUS_POSITION_SECONDS]);
5558 OBJ(audacious_bitrate) {
5559 snprintf(p, p_max_size, "%s",
5560 cur->audacious.items[AUDACIOUS_BITRATE]);
5562 OBJ(audacious_frequency) {
5563 snprintf(p, p_max_size, "%s",
5564 cur->audacious.items[AUDACIOUS_FREQUENCY]);
5566 OBJ(audacious_channels) {
5567 snprintf(p, p_max_size, "%s",
5568 cur->audacious.items[AUDACIOUS_CHANNELS]);
5570 OBJ(audacious_filename) {
5571 snprintf(p, p_max_size, "%s",
5572 cur->audacious.items[AUDACIOUS_FILENAME]);
5574 OBJ(audacious_playlist_length) {
5575 snprintf(p, p_max_size, "%s",
5576 cur->audacious.items[AUDACIOUS_PLAYLIST_LENGTH]);
5578 OBJ(audacious_playlist_position) {
5579 snprintf(p, p_max_size, "%s",
5580 cur->audacious.items[AUDACIOUS_PLAYLIST_POSITION]);
5582 OBJ(audacious_main_volume) {
5583 snprintf(p, p_max_size, "%s",
5584 cur->audacious.items[AUDACIOUS_MAIN_VOLUME]);
5587 OBJ(audacious_bar) {
5591 atof(cur->audacious.items[AUDACIOUS_POSITION_SECONDS]) /
5592 atof(cur->audacious.items[AUDACIOUS_LENGTH_SECONDS]);
5593 new_bar(p, obj->a, obj->b, (int) (progress * 255.0f));
5596 #endif /* AUDACIOUS */
5600 snprintf(p, p_max_size, "%s", cur->bmpx.title);
5603 snprintf(p, p_max_size, "%s", cur->bmpx.artist);
5606 snprintf(p, p_max_size, "%s", cur->bmpx.album);
5609 snprintf(p, p_max_size, "%s", cur->bmpx.uri);
5612 snprintf(p, p_max_size, "%i", cur->bmpx.track);
5615 snprintf(p, p_max_size, "%i", cur->bmpx.bitrate);
5618 /* we have four different types of top (top, top_mem,
5619 * top_time and top_io). To avoid having almost-same code four
5620 * times, we have this special handler. */
5623 parse_top_args("top", obj->data.top.s, obj);
5624 if (!needed) needed = cur->cpu;
5626 parse_top_args("top_mem", obj->data.top.s, obj);
5627 if (!needed) needed = cur->memu;
5629 parse_top_args("top_time", obj->data.top.s, obj);
5630 if (!needed) needed = cur->time;
5633 parse_top_args("top_io", obj->data.top.s, obj);
5634 if (!needed) needed = cur->io;
5637 if (needed[obj->data.top.num]) {
5640 switch (obj->data.top.type) {
5642 snprintf(p, top_name_width + 1, "%-*s", top_name_width,
5643 needed[obj->data.top.num]->name);
5646 snprintf(p, 7, "%6.2f",
5647 needed[obj->data.top.num]->amount);
5650 snprintf(p, 6, "%5i",
5651 needed[obj->data.top.num]->pid);
5654 snprintf(p, 7, "%6.2f",
5655 needed[obj->data.top.num]->totalmem);
5658 timeval = format_time(
5659 needed[obj->data.top.num]->total_cpu_time, 9);
5660 snprintf(p, 10, "%9s", timeval);
5664 human_readable(needed[obj->data.top.num]->rss,
5668 human_readable(needed[obj->data.top.num]->vsize,
5672 case TOP_READ_BYTES:
5673 human_readable(needed[obj->data.top.num]->read_bytes / update_interval,
5676 case TOP_WRITE_BYTES:
5677 human_readable(needed[obj->data.top.num]->write_bytes / update_interval,
5681 snprintf(p, 7, "%6.2f",
5682 needed[obj->data.top.num]->io_perc);
5688 print_tailhead("tail", obj, p, p_max_size);
5691 print_tailhead("head", obj, p, p_max_size);
5694 FILE *fp = open_file(obj->data.s, &obj->a);
5697 /* FIXME: use something more general (see also tail.c, head.c */
5698 #define BUFSZ 0x1000
5703 while(fgets(buf, BUFSZ, fp) != NULL){
5704 for(j = 0; buf[j] != 0; j++) {
5705 if(buf[j] == '\n') {
5710 sprintf(p, "%d", lines);
5713 sprintf(p, "File Unreadable");
5718 FILE *fp = open_file(obj->data.s, &obj->a);
5723 char inword = FALSE;
5726 while(fgets(buf, BUFSZ, fp) != NULL){
5727 for(j = 0; buf[j] != 0; j++) {
5728 if(!isspace(buf[j])) {
5729 if(inword == FALSE) {
5738 sprintf(p, "%d", words);
5741 sprintf(p, "File Unreadable");
5744 #ifdef TCP_PORT_MONITOR
5746 tcp_portmon_action(p, p_max_size,
5747 &obj->data.tcp_port_monitor);
5749 #endif /* TCP_PORT_MONITOR */
5753 iconv_converting = 1;
5754 iconv_selected = obj->a;
5757 iconv_converting = 0;
5760 #endif /* HAVE_ICONV */
5762 OBJ(entropy_avail) {
5763 snprintf(p, p_max_size, "%d", cur->entropy.entropy_avail);
5766 percent_print(p, p_max_size,
5767 cur->entropy.entropy_avail *
5768 100 / cur->entropy.poolsize);
5770 OBJ(entropy_poolsize) {
5771 snprintf(p, p_max_size, "%d", cur->entropy.poolsize);
5774 double entropy_perc;
5776 entropy_perc = (double) cur->entropy.entropy_avail /
5777 (double) cur->entropy.poolsize;
5779 if(output_methods & TO_X) {
5780 new_bar(p, obj->a, obj->b, (int) (entropy_perc * 255.0f));
5783 if(!obj->a) obj->a = DEFAULT_BAR_WIDTH_NO_X;
5784 new_bar_in_shell(p, p_max_size, (int) (entropy_perc * 100.0f), obj->a);
5793 s = smapi_get_val(obj->data.s);
5794 snprintf(p, p_max_size, "%s", s);
5798 OBJ(if_smapi_bat_installed) {
5800 if(obj->data.ifblock.s && sscanf(obj->data.ifblock.s, "%i", &idx) == 1) {
5801 if(!smapi_bat_installed(idx)) {
5805 NORM_ERR("argument to if_smapi_bat_installed must be an integer");
5807 OBJ(smapi_bat_perc) {
5809 if(obj->data.s && sscanf(obj->data.s, "%i", &idx) == 1) {
5810 val = smapi_bat_installed(idx) ?
5811 smapi_get_bat_int(idx, "remaining_percent") : 0;
5812 percent_print(p, p_max_size, val);
5814 NORM_ERR("argument to smapi_bat_perc must be an integer");
5816 OBJ(smapi_bat_temp) {
5818 if(obj->data.s && sscanf(obj->data.s, "%i", &idx) == 1) {
5819 val = smapi_bat_installed(idx) ?
5820 smapi_get_bat_int(idx, "temperature") : 0;
5821 /* temperature is in milli degree celsius */
5822 temp_print(p, p_max_size, val / 1000, TEMP_CELSIUS);
5824 NORM_ERR("argument to smapi_bat_temp must be an integer");
5826 OBJ(smapi_bat_power) {
5828 if(obj->data.s && sscanf(obj->data.s, "%i", &idx) == 1) {
5829 val = smapi_bat_installed(idx) ?
5830 smapi_get_bat_int(idx, "power_now") : 0;
5831 /* power_now is in mW, set to W with one digit precision */
5832 snprintf(p, p_max_size, "%.1f", ((double)val / 1000));
5834 NORM_ERR("argument to smapi_bat_power must be an integer");
5837 OBJ(smapi_bat_bar) {
5838 if(obj->data.i >= 0 && smapi_bat_installed(obj->data.i))
5839 new_bar(p, obj->a, obj->b, (int)
5840 (255 * smapi_get_bat_int(obj->data.i, "remaining_percent") / 100));
5842 new_bar(p, obj->a, obj->b, 0);
5848 char buf[max_user_text];
5850 generate_text_internal(buf, max_user_text, *obj->sub, cur);
5851 snprintf(p, p_max_size, "%s", buf);
5857 //blinking like this can look a bit ugly if the chars in the font don't have the same width
5858 char buf[max_user_text];
5861 generate_text_internal(buf, max_user_text, *obj->sub, cur);
5862 snprintf(p, p_max_size, "%s", buf);
5863 if(total_updates % 2) {
5864 for(j=0; p[j] != 0; j++) {
5870 char buf[max_user_text];
5872 char unit[16]; // 16 because we can also have long names (like mega-bytes)
5874 generate_text_internal(buf, max_user_text, *obj->sub, cur);
5875 if(sscanf(buf, "%lli%s", &bytes, unit) == 2 && strlen(unit) < 16){
5876 if(strncasecmp("b", unit, 1) == 0) snprintf(buf, max_user_text, "%lli", bytes);
5877 else if(strncasecmp("k", unit, 1) == 0) snprintf(buf, max_user_text, "%lli", bytes * 1024);
5878 else if(strncasecmp("m", unit, 1) == 0) snprintf(buf, max_user_text, "%lli", bytes * 1024 * 1024);
5879 else if(strncasecmp("g", unit, 1) == 0) snprintf(buf, max_user_text, "%lli", bytes * 1024 * 1024 * 1024);
5880 else if(strncasecmp("t", unit, 1) == 0) snprintf(buf, max_user_text, "%lli", bytes * 1024 * 1024 * 1024 * 1024);
5882 snprintf(p, p_max_size, "%s", buf);
5885 unsigned int j, colorchanges = 0, frontcolorchanges = 0, visibcolorchanges = 0, strend;
5887 char buf[max_user_text];
5888 generate_text_internal(buf, max_user_text,
5890 for(j = 0; buf[j] != 0; j++) {
5892 case '\n': //place all the lines behind each other with LINESEPARATOR between them
5893 #define LINESEPARATOR '|'
5894 buf[j]=LINESEPARATOR;
5901 //no scrolling necessary if the length of the text to scroll is too short
5902 if (strlen(buf) - colorchanges <= obj->data.scroll.show) {
5903 snprintf(p, p_max_size, "%s", buf);
5906 //make sure a colorchange at the front is not part of the string we are going to show
5907 while(*(buf + obj->data.scroll.start) == SPECIAL_CHAR) {
5908 obj->data.scroll.start++;
5910 //place all chars that should be visible in p, including colorchanges
5911 for(j=0; j < obj->data.scroll.show + visibcolorchanges; j++) {
5912 p[j] = *(buf + obj->data.scroll.start + j);
5913 if(p[j] == SPECIAL_CHAR) {
5914 visibcolorchanges++;
5916 //if there is still room fill it with spaces
5919 for(; j < obj->data.scroll.show + visibcolorchanges; j++) {
5923 //count colorchanges in front of the visible part and place that many colorchanges in front of the visible part
5924 for(j = 0; j < obj->data.scroll.start; j++) {
5925 if(buf[j] == SPECIAL_CHAR) frontcolorchanges++;
5927 pwithcolors=malloc(strlen(p) + 1 + colorchanges - visibcolorchanges);
5928 for(j = 0; j < frontcolorchanges; j++) {
5929 pwithcolors[j] = SPECIAL_CHAR;
5932 strcat(pwithcolors,p);
5933 strend = strlen(pwithcolors);
5934 //and place the colorchanges not in front or in the visible part behind the visible part
5935 for(j = 0; j < colorchanges - frontcolorchanges - visibcolorchanges; j++) {
5936 pwithcolors[strend + j] = SPECIAL_CHAR;
5938 pwithcolors[strend + j] = 0;
5939 strcpy(p, pwithcolors);
5942 obj->data.scroll.start += obj->data.scroll.step;
5943 if(buf[obj->data.scroll.start] == 0){
5944 obj->data.scroll.start = 0;
5947 //reset color when scroll is finished
5948 new_fg(p + strlen(p), obj->data.scroll.resetcolor);
5952 char buf[2][max_user_text];
5959 struct llrows* next;
5961 struct llrows *ll_rows[2], *current[2];
5962 struct text_object * objsub = obj->sub;
5965 for(i=0; i<2; i++) {
5968 ll_rows[i] = malloc(sizeof(struct llrows));
5969 current[i] = ll_rows[i];
5970 for(j=0; j<i; j++) objsub = objsub->sub;
5971 generate_text_internal(buf[i], max_user_text, *objsub, cur);
5972 for(j=0; buf[i][j] != 0; j++) {
5973 if(buf[i][j] == '\t') buf[i][j] = ' ';
5974 if(buf[i][j] == '\n') {
5976 current[i]->row = strdup(buf[i]+nextstart);
5977 if(i==0 && (long)strlen(current[i]->row) > longest) longest = (long)strlen(current[i]->row);
5978 current[i]->next = malloc(sizeof(struct llrows));
5979 current[i] = current[i]->next;
5984 current[i]->row = strdup(buf[i]+nextstart);
5985 if(i==0 && (long)strlen(current[i]->row) > longest) longest = (long)strlen(current[i]->row);
5986 current[i]->next = NULL;
5987 current[i] = ll_rows[i];
5989 for(j=0; j < (nr_rows[0] > nr_rows[1] ? nr_rows[0] : nr_rows[1] ); j++) {
5991 strcat(p, current[0]->row);
5992 i=strlen(current[0]->row);
5994 while(i < longest) {
5999 strcat(p, obj->data.combine.seperation);
6000 strcat(p, current[1]->row);
6004 #pragma omp parallel for schedule(dynamic,10)
6005 #endif /* HAVE_OPENMP */
6006 for(i=0; i<2; i++) if(current[i]) current[i]=current[i]->next;
6009 #pragma omp parallel for schedule(dynamic,10)
6010 #endif /* HAVE_OPENMP */
6011 for(i=0; i<2; i++) {
6012 while(ll_rows[i] != NULL) {
6013 current[i]=ll_rows[i];
6014 free(current[i]->row);
6015 ll_rows[i]=current[i]->next;
6022 int value = get_nvidia_value(obj->data.nvidia.type, display);
6024 snprintf(p, p_max_size, "N/A");
6025 else if (obj->data.nvidia.type == NV_TEMP)
6026 temp_print(p, p_max_size, (double)value, TEMP_CELSIUS);
6027 else if (obj->data.nvidia.print_as_float &&
6028 value > 0 && value < 100)
6029 snprintf(p, p_max_size, "%.1f", (float)value);
6031 snprintf(p, p_max_size, "%d", value);
6036 /* This is just a meta-object to set host:port */
6039 snprintf(p, p_max_size, "%s",
6040 cur->apcupsd.items[APCUPSD_NAME]);
6042 OBJ(apcupsd_model) {
6043 snprintf(p, p_max_size, "%s",
6044 cur->apcupsd.items[APCUPSD_MODEL]);
6046 OBJ(apcupsd_upsmode) {
6047 snprintf(p, p_max_size, "%s",
6048 cur->apcupsd.items[APCUPSD_UPSMODE]);
6050 OBJ(apcupsd_cable) {
6051 snprintf(p, p_max_size, "%s",
6052 cur->apcupsd.items[APCUPSD_CABLE]);
6054 OBJ(apcupsd_status) {
6055 snprintf(p, p_max_size, "%s",
6056 cur->apcupsd.items[APCUPSD_STATUS]);
6058 OBJ(apcupsd_linev) {
6059 snprintf(p, p_max_size, "%s",
6060 cur->apcupsd.items[APCUPSD_LINEV]);
6063 snprintf(p, p_max_size, "%s",
6064 cur->apcupsd.items[APCUPSD_LOAD]);
6066 OBJ(apcupsd_loadbar) {
6069 if(output_methods & TO_X) {
6070 progress = atof(cur->apcupsd.items[APCUPSD_LOAD]) / 100.0 * 255.0;
6071 new_bar(p, obj->a, obj->b, (int) progress);
6074 progress = atof(cur->apcupsd.items[APCUPSD_LOAD]);
6075 if(!obj->a) obj->a = DEFAULT_BAR_WIDTH_NO_X;
6076 new_bar_in_shell(p, p_max_size, (int) progress, obj->a);
6082 OBJ(apcupsd_loadgraph) {
6084 progress = atof(cur->apcupsd.items[APCUPSD_LOAD]);
6085 new_graph(p, obj->a, obj->b, obj->c, obj->d,
6086 (int)progress, 100, 1, obj->char_a, obj->char_b);
6088 OBJ(apcupsd_loadgauge) {
6090 progress = atof(cur->apcupsd.items[APCUPSD_LOAD]) / 100.0 * 255.0;
6091 new_gauge(p, obj->a, obj->b,
6095 OBJ(apcupsd_charge) {
6096 snprintf(p, p_max_size, "%s",
6097 cur->apcupsd.items[APCUPSD_CHARGE]);
6099 OBJ(apcupsd_timeleft) {
6100 snprintf(p, p_max_size, "%s",
6101 cur->apcupsd.items[APCUPSD_TIMELEFT]);
6104 snprintf(p, p_max_size, "%s",
6105 cur->apcupsd.items[APCUPSD_TEMP]);
6107 OBJ(apcupsd_lastxfer) {
6108 snprintf(p, p_max_size, "%s",
6109 cur->apcupsd.items[APCUPSD_LASTXFER]);
6111 #endif /* APCUPSD */
6118 unsigned int a = strlen(p);
6121 if (a > 0 && iconv_converting && iconv_selected > 0
6122 && (iconv_cd[iconv_selected - 1] != (iconv_t) (-1))) {
6124 size_t dummy1, dummy2;
6126 const char *ptr = buff_in;
6128 char *ptr = buff_in;
6132 dummy1 = dummy2 = a;
6134 strncpy(buff_in, p, p_max_size);
6136 iconv(*iconv_cd[iconv_selected - 1], NULL, NULL, NULL, NULL);
6137 while (dummy1 > 0) {
6138 bytes = iconv(*iconv_cd[iconv_selected - 1], &ptr, &dummy1,
6141 NORM_ERR("Iconv codeset conversion failed");
6146 /* It is nessecary when we are converting from multibyte to
6147 * singlebyte codepage */
6150 #endif /* HAVE_ICONV */
6151 if (obj->type != OBJ_text && obj->type != OBJ_execp && obj->type != OBJ_execpi) {
6152 substitute_newlines(p, a - 2);
6160 /* load any new fonts we may have had */
6161 if (need_to_load_fonts) {
6167 void evaluate(const char *text, char *buffer)
6169 struct information *tmp_info;
6170 struct text_object subroot;
6172 tmp_info = malloc(sizeof(struct information));
6173 memcpy(tmp_info, &info, sizeof(struct information));
6174 parse_conky_vars(&subroot, text, buffer, tmp_info);
6175 DBGP("evaluated '%s' to '%s'", text, buffer);
6177 free_text_objects(&subroot, 1);
6181 double current_update_time, next_update_time, last_update_time;
6183 static void generate_text(void)
6185 struct information *cur = &info;
6192 current_update_time = get_time();
6196 /* add things to the buffer */
6202 generate_text_internal(p, max_user_text, global_root_object, cur);
6204 if (stuff_in_uppercase) {
6207 tmp_p = text_buffer;
6209 *tmp_p = toupper(*tmp_p);
6214 next_update_time += update_interval;
6215 if (next_update_time < get_time()) {
6216 next_update_time = get_time() + update_interval;
6217 } else if (next_update_time > get_time() + update_interval) {
6218 next_update_time = get_time() + update_interval;
6220 last_update_time = current_update_time;
6224 void set_update_interval(double interval)
6226 update_interval = interval;
6227 update_interval_old = interval;
6230 static inline int get_string_width(const char *s)
6233 if (output_methods & TO_X) {
6234 return *s ? calc_text_width(s, strlen(s)) : 0;
6241 static int get_string_width_special(char *s, int special_index)
6248 if ((output_methods & TO_X) == 0) {
6249 return (s) ? strlen(s) : 0;
6256 p = strndup(s, text_buffer_size);
6260 if (*p == SPECIAL_CHAR) {
6261 /* shift everything over by 1 so that the special char
6262 * doesn't mess up the size calculation */
6263 for (i = 0; i < (long)strlen(p); i++) {
6264 *(p + i) = *(p + i + 1);
6266 if (specials[special_index + idx].type == GRAPH
6267 || specials[special_index + idx].type == GAUGE
6268 || specials[special_index + idx].type == BAR) {
6269 width += specials[special_index + idx].width;
6272 } else if (*p == SECRIT_MULTILINE_CHAR) {
6279 if (strlen(final) > 1) {
6280 width += calc_text_width(final, strlen(final));
6286 static int text_size_updater(char *s, int special_index);
6288 int last_font_height;
6289 static void update_text_area(void)
6293 if ((output_methods & TO_X) == 0)
6295 /* update text size if it isn't fixed */
6300 text_width = minimum_width;
6302 last_font_height = font_height();
6303 for_each_line(text_buffer, text_size_updater);
6305 if (text_height < minimum_height) {
6306 text_height = minimum_height;
6308 if (text_width > maximum_width && maximum_width > 0) {
6309 text_width = maximum_width;
6313 /* get text position on workarea */
6314 switch (text_alignment) {
6321 x = workarea[2] - text_width - gap_x;
6326 x = workarea[2] / 2 - text_width / 2 - gap_x;
6333 y = workarea[3] - text_height - gap_y;
6337 x = workarea[2] - text_width - gap_x;
6338 y = workarea[3] - text_height - gap_y;
6342 x = workarea[2] / 2 - text_width / 2 - gap_x;
6343 y = workarea[3] - text_height - gap_y;
6348 y = workarea[3] / 2 - text_height / 2 - gap_y;
6352 x = workarea[2] - text_width - gap_x;
6353 y = workarea[3] / 2 - text_height / 2 - gap_y;
6357 case NONE: // Let the WM manage the window
6368 if (own_window && !fixed_pos) {
6371 text_start_x = window.border_inner_margin + window.border_outer_margin + window.border_width;
6372 text_start_y = window.border_inner_margin + window.border_outer_margin + window.border_width;
6373 window.x = x - window.border_inner_margin - window.border_outer_margin - window.border_width;
6374 window.y = y - window.border_inner_margin - window.border_outer_margin - window.border_width;
6378 /* If window size doesn't match to workarea's size,
6379 * then window probably includes panels (gnome).
6380 * Blah, doesn't work on KDE. */
6381 if (workarea[2] != window.width || workarea[3] != window.height) {
6390 /* update lua window globals */
6391 llua_update_window_table(text_start_x, text_start_y, text_width, text_height);
6392 #endif /* HAVE_LUA */
6397 static int cur_x, cur_y; /* current x and y for drawing */
6399 //draw_mode also without X11 because we only need to print to stdout with FG
6400 static int draw_mode; /* FG, BG or OUTLINE */
6402 static long current_color;
6404 static int text_size_updater(char *s, int special_index)
6409 if ((output_methods & TO_X) == 0)
6411 /* get string widths and skip specials */
6414 if (*p == SPECIAL_CHAR) {
6416 w += get_string_width(s);
6419 if (specials[special_index].type == BAR
6420 || specials[special_index].type == GAUGE
6421 || specials[special_index].type == GRAPH) {
6422 w += specials[special_index].width;
6423 if (specials[special_index].height > last_font_height) {
6424 last_font_height = specials[special_index].height;
6425 last_font_height += font_height();
6427 } else if (specials[special_index].type == OFFSET) {
6428 if (specials[special_index].arg > 0) {
6429 w += specials[special_index].arg;
6431 } else if (specials[special_index].type == VOFFSET) {
6432 last_font_height += specials[special_index].arg;
6433 } else if (specials[special_index].type == GOTO) {
6434 if (specials[special_index].arg > cur_x) {
6435 w = (int) specials[special_index].arg;
6437 } else if (specials[special_index].type == TAB) {
6438 int start = specials[special_index].arg;
6439 int step = specials[special_index].width;
6441 if (!step || step < 0) {
6444 w += step - (cur_x - text_start_x - start) % step;
6445 } else if (specials[special_index].type == FONT) {
6446 selected_font = specials[special_index].font_added;
6447 if (font_height() > last_font_height) {
6448 last_font_height = font_height();
6454 } else if (*p == SECRIT_MULTILINE_CHAR) {
6457 lw = get_string_width(s);
6458 *p = SECRIT_MULTILINE_CHAR;
6460 w = lw > w ? lw : w;
6461 text_height += last_font_height;
6465 w += get_string_width(s);
6466 if (w > text_width) {
6469 if (text_width > maximum_width && maximum_width) {
6470 text_width = maximum_width;
6473 text_height += last_font_height;
6474 last_font_height = font_height();
6475 return special_index;
6478 static inline void set_foreground_color(long c)
6480 if ((output_methods & TO_X) == 0)
6483 XSetForeground(display, window.gc, c);
6487 static void draw_string(const char *s)
6489 int i, i2, pos, width_of_s;
6492 char *s_with_newlines;
6498 width_of_s = get_string_width(s);
6499 s_with_newlines = strdup(s);
6500 for(i = 0; i < (int) strlen(s_with_newlines); i++) {
6501 if(s_with_newlines[i] == SECRIT_MULTILINE_CHAR) {
6502 s_with_newlines[i] = '\n';
6505 if ((output_methods & TO_STDOUT) && draw_mode == FG) {
6506 printf("%s\n", s_with_newlines);
6507 if (extra_newline) fputc('\n', stdout);
6508 fflush(stdout); /* output immediately, don't buffer */
6510 if ((output_methods & TO_STDERR) && draw_mode == FG) {
6511 fprintf(stderr, "%s\n", s_with_newlines);
6512 fflush(stderr); /* output immediately, don't buffer */
6514 if ((output_methods & OVERWRITE_FILE) && draw_mode == FG && overwrite_fpointer) {
6515 fprintf(overwrite_fpointer, "%s\n", s_with_newlines);
6517 if ((output_methods & APPEND_FILE) && draw_mode == FG && append_fpointer) {
6518 fprintf(append_fpointer, "%s\n", s_with_newlines);
6521 if ((output_methods & TO_NCURSES) && draw_mode == FG) {
6522 printw("%s\n", s_with_newlines);
6525 free(s_with_newlines);
6526 memset(tmpstring1, 0, text_buffer_size);
6527 memset(tmpstring2, 0, text_buffer_size);
6528 strncpy(tmpstring1, s, text_buffer_size - 1);
6533 if (output_methods & TO_X) {
6534 max = ((text_width - width_of_s) / get_string_width(" "));
6537 /* This code looks for tabs in the text and coverts them to spaces.
6538 * The trick is getting the correct number of spaces, and not going
6539 * over the window's size without forcing the window larger. */
6540 for (i = 0; i < (int) text_buffer_size; i++) {
6541 if (tmpstring1[i] == '\t') {
6543 for (i2 = 0; i2 < (8 - (1 + pos) % 8) && added <= max; i2++) {
6544 /* guard against overrun */
6545 tmpstring2[MIN(pos + i2, (int)text_buffer_size - 1)] = ' ';
6550 /* guard against overrun */
6551 tmpstring2[MIN(pos, (int) text_buffer_size - 1)] = tmpstring1[i];
6556 if (output_methods & TO_X) {
6557 if (text_width == maximum_width) {
6558 /* this means the text is probably pushing the limit,
6559 * so we'll chop it */
6560 while (cur_x + get_string_width(tmpstring2) - text_start_x
6561 > maximum_width && strlen(tmpstring2) > 0) {
6562 tmpstring2[strlen(tmpstring2) - 1] = '\0';
6569 if (output_methods & TO_X) {
6575 c.pixel = current_color;
6576 XQueryColor(display, DefaultColormap(display, screen), &c);
6579 c2.color.red = c.red;
6580 c2.color.green = c.green;
6581 c2.color.blue = c.blue;
6582 c2.color.alpha = fonts[selected_font].font_alpha;
6584 XftDrawStringUtf8(window.xftdraw, &c2, fonts[selected_font].xftfont,
6585 cur_x, cur_y, (const XftChar8 *) s, strlen(s));
6587 XftDrawString8(window.xftdraw, &c2, fonts[selected_font].xftfont,
6588 cur_x, cur_y, (const XftChar8 *) s, strlen(s));
6593 XDrawString(display, window.drawable, window.gc, cur_x, cur_y, s,
6596 cur_x += width_of_s;
6599 memcpy(tmpstring1, s, text_buffer_size);
6603 int draw_each_line_inner(char *s, int special_index, int last_special_applied)
6605 int font_h = font_height();
6609 int last_special_needed = -1;
6610 int orig_special_index = special_index;
6612 cur_x = text_start_x;
6613 cur_y += font_ascent();
6616 if (*p == SECRIT_MULTILINE_CHAR) {
6617 /* special newline marker for multiline objects */
6622 if (*p == SPECIAL_CHAR || last_special_applied > -1) {
6625 /* draw string before special, unless we're dealing multiline
6627 if (last_special_applied > -1) {
6628 special_index = last_special_applied;
6636 switch (specials[special_index].type) {
6637 case HORIZONTAL_LINE:
6639 int h = specials[special_index].height;
6640 int mid = font_ascent() / 2;
6642 w = text_start_x + text_width - cur_x;
6644 XSetLineAttributes(display, window.gc, h, LineSolid,
6645 CapButt, JoinMiter);
6646 XDrawLine(display, window.drawable, window.gc, cur_x,
6647 cur_y - mid / 2, cur_x + w, cur_y - mid / 2);
6653 int h = specials[special_index].height;
6654 int tmp_s = specials[special_index].arg;
6655 int mid = font_ascent() / 2;
6656 char ss[2] = { tmp_s, tmp_s };
6658 w = text_start_x + text_width - cur_x - 1;
6659 XSetLineAttributes(display, window.gc, h, LineOnOffDash,
6660 CapButt, JoinMiter);
6661 XSetDashes(display, window.gc, 0, ss, 2);
6662 XDrawLine(display, window.drawable, window.gc, cur_x,
6663 cur_y - mid / 2, cur_x + w, cur_y - mid / 2);
6669 int h, bar_usage, by;
6670 if (cur_x - text_start_x > maximum_width
6671 && maximum_width > 0) {
6674 h = specials[special_index].height;
6675 bar_usage = specials[special_index].arg;
6676 by = cur_y - (font_ascent() / 2) - 1;
6681 w = specials[special_index].width;
6683 w = text_start_x + text_width - cur_x - 1;
6689 XSetLineAttributes(display, window.gc, 1, LineSolid,
6690 CapButt, JoinMiter);
6692 XDrawRectangle(display, window.drawable, window.gc, cur_x,
6694 XFillRectangle(display, window.drawable, window.gc, cur_x,
6695 by, w * bar_usage / 255, h);
6703 case GAUGE: /* new GAUGE */
6706 unsigned long last_colour = current_color;
6708 float angle, px, py;
6712 if (cur_x - text_start_x > maximum_width
6713 && maximum_width > 0) {
6717 h = specials[special_index].height;
6718 by = cur_y - (font_ascent() / 2) - 1;
6723 w = specials[special_index].width;
6725 w = text_start_x + text_width - cur_x - 1;
6731 XSetLineAttributes(display, window.gc, 1, LineSolid,
6732 CapButt, JoinMiter);
6734 XDrawArc(display, window.drawable, window.gc,
6735 cur_x, by, w, h * 2, 0, 180*64);
6738 usage = specials[special_index].arg;
6739 angle = (M_PI)*(float)(usage)/255.;
6740 px = (float)(cur_x+(w/2.))-(float)(w/2.)*cos(angle);
6741 py = (float)(by+(h))-(float)(h)*sin(angle);
6743 XDrawLine(display, window.drawable, window.gc,
6744 cur_x + (w/2.), by+(h), (int)(px), (int)(py));
6752 set_foreground_color(last_colour);
6760 int h, by, i = 0, j = 0;
6762 unsigned long last_colour = current_color;
6763 unsigned long *tmpcolour = 0;
6764 if (cur_x - text_start_x > maximum_width
6765 && maximum_width > 0) {
6768 h = specials[special_index].height;
6769 by = cur_y - (font_ascent() / 2) - 1;
6774 w = specials[special_index].width;
6776 w = text_start_x + text_width - cur_x - 1;
6781 if (draw_graph_borders) {
6782 XSetLineAttributes(display, window.gc, 1, LineSolid,
6783 CapButt, JoinMiter);
6784 XDrawRectangle(display, window.drawable, window.gc,
6787 XSetLineAttributes(display, window.gc, 1, LineSolid,
6788 CapButt, JoinMiter);
6790 if (specials[special_index].last_colour != 0
6791 || specials[special_index].first_colour != 0) {
6792 tmpcolour = do_gradient(w - 1, specials[special_index].last_colour, specials[special_index].first_colour);
6795 for (i = w - 2; i > -1; i--) {
6796 if (specials[special_index].last_colour != 0
6797 || specials[special_index].first_colour != 0) {
6798 if (specials[special_index].tempgrad) {
6801 (int)((float)(w - 2) - specials[special_index].graph[j] *
6802 (w - 2) / (float)specials[special_index].graph_scale)
6806 (int)((float)(w - 2) - specials[special_index].graph[j] *
6807 (w - 2) / (float)specials[special_index].graph_scale)
6810 if (specials[special_index].graph[j] == specials[special_index].graph_scale) {
6812 (int)((float)(w - 2) - specials[special_index].graph[j] *
6813 (w - 2) / (float)specials[special_index].graph_scale)
6817 #endif /* DEBUG_lol */
6818 XSetForeground(display, window.gc, tmpcolour[
6819 (int)((float)(w - 2) - specials[special_index].graph[j] *
6820 (w - 2) / (float)specials[special_index].graph_scale)
6823 XSetForeground(display, window.gc, tmpcolour[colour_idx++]);
6826 /* this is mugfugly, but it works */
6827 XDrawLine(display, window.drawable, window.gc,
6828 cur_x + i + 1, by + h, cur_x + i + 1,
6829 round_to_int((double)by + h - specials[special_index].graph[j] *
6830 (h - 1) / specials[special_index].graph_scale));
6831 if ((w - i) / ((float) (w - 2) /
6832 (specials[special_index].graph_width)) > j
6833 && j < MAX_GRAPH_DEPTH - 3) {
6837 if (tmpcolour) free(tmpcolour);
6842 /* if (draw_mode == BG) {
6843 set_foreground_color(default_bg_color);
6844 } else if (draw_mode == OUTLINE) {
6845 set_foreground_color(default_out_color);
6847 set_foreground_color(default_fg_color);
6849 if (show_graph_range) {
6852 unsigned short int seconds = update_interval * w;
6858 unsigned short int timeunits;
6860 timeunits = seconds / 86400; seconds %= 86400;
6861 if (timeunits > 0) {
6862 asprintf(&tmp_day_str, "%dd", timeunits);
6864 tmp_day_str = strdup("");
6866 timeunits = seconds / 3600; seconds %= 3600;
6867 if (timeunits > 0) {
6868 asprintf(&tmp_hour_str, "%dh", timeunits);
6870 tmp_hour_str = strdup("");
6872 timeunits = seconds / 60; seconds %= 60;
6873 if (timeunits > 0) {
6874 asprintf(&tmp_min_str, "%dm", timeunits);
6876 tmp_min_str = strdup("");
6879 asprintf(&tmp_sec_str, "%ds", seconds);
6881 tmp_sec_str = strdup("");
6883 asprintf(&tmp_str, "%s%s%s%s", tmp_day_str, tmp_hour_str, tmp_min_str, tmp_sec_str);
6884 free(tmp_day_str); free(tmp_hour_str); free(tmp_min_str); free(tmp_sec_str);
6886 asprintf(&tmp_str, "Range not possible"); // should never happen, but better safe then sorry
6888 cur_x += (w / 2) - (font_ascent() * (strlen(tmp_str) / 2));
6889 cur_y += font_h / 2;
6890 draw_string(tmp_str);
6896 if (show_graph_scale && (specials[special_index].show_scale == 1)) {
6900 cur_x += font_ascent() / 2;
6901 cur_y += font_h / 2;
6903 calloc(log10(floor(specials[special_index].graph_scale)) + 4,
6905 sprintf(tmp_str, "%.1f", specials[special_index].graph_scale);
6906 draw_string(tmp_str);
6912 set_foreground_color(last_colour);
6918 int old = font_ascent();
6920 cur_y -= font_ascent();
6921 selected_font = specials[special_index].font_added;
6923 if (cur_y + font_ascent() < cur_y + old) {
6926 cur_y += font_ascent();
6928 font_h = font_height();
6932 if (draw_mode == FG) {
6933 set_foreground_color(specials[special_index].arg);
6938 if (draw_mode == BG) {
6939 set_foreground_color(specials[special_index].arg);
6944 if (draw_mode == OUTLINE) {
6945 set_foreground_color(specials[special_index].arg);
6950 w += specials[special_index].arg;
6951 last_special_needed = special_index;
6955 cur_y += specials[special_index].arg;
6959 if (specials[special_index].arg >= 0) {
6960 cur_x = (int) specials[special_index].arg;
6962 last_special_needed = special_index;
6967 int start = specials[special_index].arg;
6968 int step = specials[special_index].width;
6970 if (!step || step < 0) {
6973 w = step - (cur_x - text_start_x - start) % step;
6974 last_special_needed = special_index;
6980 /* TODO: add back in "+ window.border_inner_margin" to the end of
6982 int pos_x = text_start_x + text_width -
6983 get_string_width_special(s, special_index);
6985 /* printf("pos_x %i text_start_x %i text_width %i cur_x %i "
6986 "get_string_width(p) %i gap_x %i "
6987 "specials[special_index].arg %i window.border_inner_margin %i "
6988 "window.border_width %i\n", pos_x, text_start_x, text_width,
6989 cur_x, get_string_width_special(s), gap_x,
6990 specials[special_index].arg, window.border_inner_margin,
6991 window.border_width); */
6992 if (pos_x > specials[special_index].arg && pos_x > cur_x) {
6993 cur_x = pos_x - specials[special_index].arg;
6995 last_special_needed = special_index;
7001 int pos_x = (text_width) / 2 - get_string_width_special(s,
7002 special_index) / 2 - (cur_x -
7004 /* int pos_x = text_start_x + text_width / 2 -
7005 get_string_width_special(s) / 2; */
7007 /* printf("pos_x %i text_start_x %i text_width %i cur_x %i "
7008 "get_string_width(p) %i gap_x %i "
7009 "specials[special_index].arg %i\n", pos_x, text_start_x,
7010 text_width, cur_x, get_string_width(s), gap_x,
7011 specials[special_index].arg); */
7012 if (pos_x > specials[special_index].arg) {
7013 w = pos_x - specials[special_index].arg;
7015 last_special_needed = special_index;
7022 if (special_index != last_special_applied) {
7025 special_index = orig_special_index;
7026 last_special_applied = -1;
7034 cur_y += font_descent();
7035 if (recurse && *recurse) {
7036 special_index = draw_each_line_inner(recurse, special_index, last_special_needed);
7037 *(recurse - 1) = SECRIT_MULTILINE_CHAR;
7039 return special_index;
7043 static int draw_line(char *s, int special_index)
7046 if ((output_methods & TO_X) == 0) {
7049 //'special_index - special_index' instead of 0 otherwise gcc complains about not using special_index when build without X11
7050 return special_index - special_index;
7054 /* find specials and draw stuff */
7055 return draw_each_line_inner(s, special_index, -1);
7059 static void draw_text(void)
7063 llua_draw_pre_hook();
7064 #endif /* HAVE_LUA */
7065 if (output_methods & TO_X) {
7066 cur_y = text_start_y;
7069 if (draw_borders && window.border_width > 0) {
7070 if (stippled_borders) {
7071 char ss[2] = { stippled_borders, stippled_borders };
7072 XSetLineAttributes(display, window.gc, window.border_width, LineOnOffDash,
7073 CapButt, JoinMiter);
7074 XSetDashes(display, window.gc, 0, ss, 2);
7076 XSetLineAttributes(display, window.gc, window.border_width, LineSolid,
7077 CapButt, JoinMiter);
7080 XDrawRectangle(display, window.drawable, window.gc,
7081 text_start_x - window.border_inner_margin - window.border_width,
7082 text_start_y - window.border_inner_margin - window.border_width,
7083 text_width + window.border_inner_margin * 2 + window.border_width * 2,
7084 text_height + window.border_inner_margin * 2 + window.border_width * 2);
7091 for_each_line(text_buffer, draw_line);
7092 #if defined(HAVE_LUA) && defined(X11)
7093 llua_draw_post_hook();
7094 #endif /* HAVE_LUA */
7097 static void draw_stuff(void)
7099 if (overwrite_file) {
7100 overwrite_fpointer = fopen(overwrite_file, "w");
7101 if(!overwrite_fpointer)
7102 NORM_ERR("Can't overwrite '%s' anymore", overwrite_file);
7105 append_fpointer = fopen(append_file, "a");
7106 if(!append_fpointer)
7107 NORM_ERR("Can't append '%s' anymore", append_file);
7110 if (output_methods & TO_X) {
7112 if (draw_shades && !draw_outline) {
7115 set_foreground_color(default_bg_color);
7126 for (i = -1; i < 2; i++) {
7127 for (j = -1; j < 2; j++) {
7128 if (i == 0 && j == 0) {
7133 set_foreground_color(default_out_color);
7134 draw_mode = OUTLINE;
7142 set_foreground_color(default_fg_color);
7148 if (output_methods & TO_X) {
7153 swap.swap_window = window.window;
7154 swap.swap_action = XdbeBackground;
7155 XdbeSwapBuffers(display, &swap, 1);
7160 if(overwrite_fpointer) {
7161 fclose(overwrite_fpointer);
7162 overwrite_fpointer = 0;
7164 if(append_fpointer) {
7165 fclose(append_fpointer);
7166 append_fpointer = 0;
7171 static void clear_text(int exposures)
7175 /* The swap action is XdbeBackground, which clears */
7179 if (display && window.window) { // make sure these are !null
7180 /* there is some extra space for borders and outlines */
7181 XClearArea(display, window.window, text_start_x - window.border_inner_margin - window.border_outer_margin - window.border_width,
7182 text_start_y - window.border_inner_margin - window.border_outer_margin - window.border_width,
7183 text_width + window.border_inner_margin * 2 + window.border_outer_margin * 2 + window.border_width * 2,
7184 text_height + window.border_inner_margin * 2 + window.border_outer_margin * 2 + window.border_width * 2, exposures ? True : 0);
7189 static int need_to_update;
7191 /* update_text() generates new text and clears old text area */
7192 static void update_text(void)
7199 if (output_methods & TO_X)
7204 llua_update_info(&info, update_interval);
7205 #endif /* HAVE_LUA */
7208 #ifdef HAVE_SYS_INOTIFY_H
7212 static void main_loop(void)
7215 #ifdef SIGNAL_BLOCKING
7216 sigset_t newmask, oldmask;
7219 #ifdef HAVE_SYS_INOTIFY_H
7220 int inotify_config_wd = -1;
7221 #define INOTIFY_EVENT_SIZE (sizeof(struct inotify_event))
7222 #define INOTIFY_BUF_LEN (20 * (INOTIFY_EVENT_SIZE + 16))
7223 char inotify_buff[INOTIFY_BUF_LEN];
7224 #endif /* HAVE_SYS_INOTIFY_H */
7227 #ifdef SIGNAL_BLOCKING
7228 sigemptyset(&newmask);
7229 sigaddset(&newmask, SIGINT);
7230 sigaddset(&newmask, SIGTERM);
7231 sigaddset(&newmask, SIGUSR1);
7234 last_update_time = 0.0;
7235 next_update_time = get_time();
7237 while (terminate == 0 && (total_run_times == 0 || info.looped < total_run_times)) {
7238 if(update_interval_bat != NOBATTERY && update_interval_bat != update_interval_old) {
7239 char buf[max_user_text];
7241 get_battery_short_status(buf, max_user_text, "BAT0");
7243 update_interval = update_interval_bat;
7245 update_interval = update_interval_old;
7250 #ifdef SIGNAL_BLOCKING
7251 /* block signals. we will inspect for pending signals later */
7252 if (sigprocmask(SIG_BLOCK, &newmask, &oldmask) < 0) {
7253 CRIT_ERR(NULL, NULL, "unable to sigprocmask()");
7258 if (output_methods & TO_X) {
7261 /* wait for X event or timeout */
7263 if (!XPending(display)) {
7267 t = next_update_time - get_time();
7271 } else if (t > update_interval) {
7272 t = update_interval;
7275 tv.tv_sec = (long) t;
7276 tv.tv_usec = (long) (t * 1000000) % 1000000;
7278 FD_SET(ConnectionNumber(display), &fdsr);
7280 s = select(ConnectionNumber(display) + 1, &fdsr, 0, 0, &tv);
7282 if (errno != EINTR) {
7283 NORM_ERR("can't select(): %s", strerror(errno));
7293 if (need_to_update) {
7295 int wx = window.x, wy = window.y;
7305 /* resize window if it isn't right size */
7307 && (text_width + window.border_inner_margin * 2 + window.border_outer_margin * 2 + window.border_width * 2 != window.width
7308 || text_height + window.border_inner_margin * 2 + window.border_outer_margin * 2 + window.border_width * 2 != window.height)) {
7309 window.width = text_width + window.border_inner_margin * 2 + window.border_outer_margin * 2 + window.border_width * 2;
7310 window.height = text_height + window.border_inner_margin * 2 + window.border_outer_margin * 2 + window.border_width * 2;
7311 XResizeWindow(display, window.window, window.width,
7313 set_transparent_background(window.window);
7318 /* move window if it isn't in right position */
7319 if (!fixed_pos && (window.x != wx || window.y != wy)) {
7320 XMoveWindow(display, window.window, window.x, window.y);
7325 if (changed && window.type == TYPE_PANEL) {
7328 fprintf(stderr, PACKAGE_NAME": defining struts\n");
7331 switch (text_alignment) {
7358 set_struts(sidenum);
7369 r.x = text_start_x - window.border_inner_margin - window.border_outer_margin - window.border_width;
7370 r.y = text_start_y - window.border_inner_margin - window.border_outer_margin - window.border_width;
7371 r.width = text_width + window.border_inner_margin * 2 + window.border_outer_margin * 2 + window.border_width * 2;
7372 r.height = text_height + window.border_inner_margin * 2 + window.border_outer_margin * 2 + window.border_width * 2;
7373 XUnionRectWithRegion(&r, x11_stuff.region, x11_stuff.region);
7378 /* handle X events */
7379 while (XPending(display)) {
7382 XNextEvent(display, &ev);
7389 r.width = ev.xexpose.width;
7390 r.height = ev.xexpose.height;
7391 XUnionRectWithRegion(&r, x11_stuff.region, x11_stuff.region);
7395 case PropertyNotify:
7397 if ( ev.xproperty.state == PropertyNewValue ) {
7398 get_x11_desktop_info( ev.xproperty.display, ev.xproperty.atom );
7404 case ReparentNotify:
7405 /* set background to ParentRelative for all parents */
7407 set_transparent_background(window.window);
7411 case ConfigureNotify:
7413 /* if window size isn't what expected, set fixed size */
7414 if (ev.xconfigure.width != window.width
7415 || ev.xconfigure.height != window.height) {
7416 if (window.width != 0 && window.height != 0) {
7420 /* clear old stuff before screwing up
7425 XWindowAttributes attrs;
7426 if (XGetWindowAttributes(display,
7427 window.window, &attrs)) {
7428 window.width = attrs.width;
7429 window.height = attrs.height;
7433 text_width = window.width - window.border_inner_margin * 2 - window.border_outer_margin * 2 - window.border_width * 2;
7434 text_height = window.height - window.border_inner_margin * 2 - window.border_outer_margin * 2 - window.border_width * 2;
7435 if (text_width > maximum_width
7436 && maximum_width > 0) {
7437 text_width = maximum_width;
7441 /* if position isn't what expected, set fixed pos
7442 * total_updates avoids setting fixed_pos when window
7443 * is set to weird locations when started */
7444 /* // this is broken
7445 if (total_updates >= 2 && !fixed_pos
7446 && (window.x != ev.xconfigure.x
7447 || window.y != ev.xconfigure.y)
7448 && (ev.xconfigure.x != 0
7449 || ev.xconfigure.y != 0)) {
7457 /* if an ordinary window with decorations */
7458 if ((window.type == TYPE_NORMAL)
7459 && (!TEST_HINT(window.hints,
7460 HINT_UNDECORATED))) {
7461 /* allow conky to hold input focus. */
7464 /* forward the click to the desktop window */
7465 XUngrabPointer(display, ev.xbutton.time);
7466 ev.xbutton.window = window.desktop;
7467 ev.xbutton.x = ev.xbutton.x_root;
7468 ev.xbutton.y = ev.xbutton.y_root;
7469 XSendEvent(display, ev.xbutton.window, False,
7470 ButtonPressMask, &ev);
7471 XSetInputFocus(display, ev.xbutton.window,
7472 RevertToParent, ev.xbutton.time);
7479 /* if an ordinary window with decorations */
7480 if ((window.type == TYPE_NORMAL)
7481 && (!TEST_HINT(window.hints,
7482 HINT_UNDECORATED))) {
7483 /* allow conky to hold input focus. */
7486 /* forward the release to the desktop window */
7487 ev.xbutton.window = window.desktop;
7488 ev.xbutton.x = ev.xbutton.x_root;
7489 ev.xbutton.y = ev.xbutton.y_root;
7490 XSendEvent(display, ev.xbutton.window, False,
7491 ButtonReleaseMask, &ev);
7500 if (ev.type == x11_stuff.event_base + XDamageNotify) {
7501 XDamageNotifyEvent *dev = (XDamageNotifyEvent *) &ev;
7503 XFixesSetRegion(display, x11_stuff.part, &dev->area, 1);
7504 XFixesUnionRegion(display, x11_stuff.region2, x11_stuff.region2, x11_stuff.part);
7506 #endif /* HAVE_XDAMAGE */
7512 XDamageSubtract(display, x11_stuff.damage, x11_stuff.region2, None);
7513 XFixesSetRegion(display, x11_stuff.region2, 0, 0);
7514 #endif /* HAVE_XDAMAGE */
7516 /* XDBE doesn't seem to provide a way to clear the back buffer without
7517 * interfering with the front buffer, other than passing XdbeBackground
7518 * to XdbeSwapBuffers. That means that if we're using XDBE, we need to
7519 * redraw the text even if it wasn't part of the exposed area. OTOH,
7520 * if we're not going to call draw_stuff at all, then no swap happens
7521 * and we can safely do nothing. */
7523 if (!XEmptyRegion(x11_stuff.region)) {
7528 r.x = text_start_x - window.border_inner_margin - window.border_outer_margin - window.border_width;
7529 r.y = text_start_y - window.border_inner_margin - window.border_outer_margin - window.border_width;
7530 r.width = text_width + window.border_inner_margin * 2 + window.border_outer_margin * 2 + window.border_width * 2;
7531 r.height = text_height + window.border_inner_margin * 2 + window.border_outer_margin * 2 + window.border_width * 2;
7532 XUnionRectWithRegion(&r, x11_stuff.region, x11_stuff.region);
7535 XSetRegion(display, window.gc, x11_stuff.region);
7538 XftDrawSetClip(window.xftdraw, x11_stuff.region);
7542 cimlib_render(text_start_x, text_start_y, window.width, window.height);
7545 XDestroyRegion(x11_stuff.region);
7546 x11_stuff.region = XCreateRegion();
7550 t = (next_update_time - get_time()) * 1000000;
7551 if(t > 0) usleep((useconds_t)t);
7555 if(output_methods & TO_NCURSES) {
7564 #ifdef SIGNAL_BLOCKING
7565 /* unblock signals of interest and let handler fly */
7566 if (sigprocmask(SIG_SETMASK, &oldmask, NULL) < 0) {
7567 CRIT_ERR(NULL, NULL, "unable to sigprocmask()");
7571 switch (g_signal_pending) {
7574 NORM_ERR("received SIGHUP or SIGUSR1. reloading the config file.");
7579 NORM_ERR("received SIGINT or SIGTERM to terminate. bye!");
7582 if (output_methods & TO_X) {
7583 XDestroyRegion(x11_stuff.region);
7584 x11_stuff.region = NULL;
7586 XDamageDestroy(display, x11_stuff.damage);
7587 XFixesDestroyRegion(display, x11_stuff.region2);
7588 XFixesDestroyRegion(display, x11_stuff.part);
7589 #endif /* HAVE_XDAMAGE */
7595 if(overwrite_file) {
7596 free(overwrite_file);
7605 /* Reaching here means someone set a signal
7606 * (SIGXXXX, signal_handler), but didn't write any code
7608 * If you don't want to handle a signal, don't set a handler on
7609 * it in the first place. */
7610 if (g_signal_pending) {
7611 NORM_ERR("ignoring signal (%d)", g_signal_pending);
7615 #ifdef HAVE_SYS_INOTIFY_H
7616 if (inotify_fd != -1 && inotify_config_wd == -1 && current_config != 0) {
7617 inotify_config_wd = inotify_add_watch(inotify_fd,
7621 if (inotify_fd != -1 && inotify_config_wd != -1 && current_config != 0) {
7622 int len = 0, idx = 0;
7624 struct timeval time_to_wait;
7626 FD_ZERO(&descriptors);
7627 FD_SET(inotify_fd, &descriptors);
7629 time_to_wait.tv_sec = time_to_wait.tv_usec = 0;
7631 select(inotify_fd + 1, &descriptors, NULL, NULL, &time_to_wait);
7632 if (FD_ISSET(inotify_fd, &descriptors)) {
7633 /* process inotify events */
7634 len = read(inotify_fd, inotify_buff, INOTIFY_BUF_LEN);
7635 while (len > 0 && idx < len) {
7636 struct inotify_event *ev = (struct inotify_event *) &inotify_buff[idx];
7637 if (ev->wd == inotify_config_wd && (ev->mask & IN_MODIFY || ev->mask & IN_IGNORED)) {
7638 /* current_config should be reloaded */
7639 NORM_ERR("'%s' modified, reloading...", current_config);
7641 if (ev->mask & IN_IGNORED) {
7642 /* for some reason we get IN_IGNORED here
7643 * sometimes, so we need to re-add the watch */
7644 inotify_config_wd = inotify_add_watch(inotify_fd,
7651 llua_inotify_query(ev->wd, ev->mask);
7653 #endif /* HAVE_LUA */
7654 idx += INOTIFY_EVENT_SIZE + ev->len;
7658 #endif /* HAVE_SYS_INOTIFY_H */
7661 llua_update_info(&info, update_interval);
7662 #endif /* HAVE_LUA */
7663 g_signal_pending = 0;
7665 clean_up(NULL, NULL);
7667 #ifdef HAVE_SYS_INOTIFY_H
7668 if (inotify_fd != -1) {
7669 inotify_rm_watch(inotify_fd, inotify_config_wd);
7671 inotify_fd = inotify_config_wd = 0;
7673 #endif /* HAVE_SYS_INOTIFY_H */
7677 static void load_config_file_x11(const char *);
7679 void initialisation(int argc, char** argv);
7681 /* reload the config file */
7682 static void reload_config(void)
7684 char *current_config_copy = strdup(current_config);
7685 clean_up(NULL, NULL);
7686 current_config = current_config_copy;
7687 initialisation(argc_copy, argv_copy);
7690 void clean_up(void *memtofree1, void* memtofree2)
7695 if(output_methods & TO_NCURSES) {
7700 conftree_empty(currentconffile);
7701 currentconffile = NULL;
7708 timed_thread_destroy_registered_threads();
7710 if (info.cpu_usage) {
7711 free(info.cpu_usage);
7712 info.cpu_usage = NULL;
7715 if (x_initialised == YES) {
7718 if(x11_stuff.region) {
7719 XDestroyRegion(x11_stuff.region);
7720 x11_stuff.region = NULL;
7722 XClearWindow(display, RootWindow(display, screen));
7723 XCloseDisplay(display);
7725 if(info.x11.desktop.all_names) {
7726 free(info.x11.desktop.all_names);
7727 info.x11.desktop.all_names = NULL;
7729 if (info.x11.desktop.name) {
7730 free(info.x11.desktop.name);
7731 info.x11.desktop.name = NULL;
7735 free(fonts); //in set_default_configurations a font is set but not loaded
7741 for (i = 0; i < MAX_TEMPLATES; i++) {
7748 free_text_objects(&global_root_object, 0);
7767 free(current_config);
7770 #ifdef TCP_PORT_MONITOR
7771 tcp_portmon_clear();
7780 weather_free_info();
7783 llua_shutdown_hook();
7785 #endif /* HAVE_LUA */
7788 for (i = 0; i < special_count; i++) {
7789 if (specials[i].type == GRAPH) {
7790 free(specials[i].graph);
7798 clear_diskio_stats();
7799 if(global_cpu != NULL) {
7805 static int string_to_bool(const char *s)
7808 // Assumes an option without a true/false means true
7810 } else if (strcasecmp(s, "yes") == EQUAL) {
7812 } else if (strcasecmp(s, "true") == EQUAL) {
7814 } else if (strcasecmp(s, "1") == EQUAL) {
7821 static enum alignment string_to_alignment(const char *s)
7823 if (strcasecmp(s, "top_left") == EQUAL) {
7825 } else if (strcasecmp(s, "top_right") == EQUAL) {
7827 } else if (strcasecmp(s, "top_middle") == EQUAL) {
7829 } else if (strcasecmp(s, "bottom_left") == EQUAL) {
7831 } else if (strcasecmp(s, "bottom_right") == EQUAL) {
7832 return BOTTOM_RIGHT;
7833 } else if (strcasecmp(s, "bottom_middle") == EQUAL) {
7834 return BOTTOM_MIDDLE;
7835 } else if (strcasecmp(s, "middle_left") == EQUAL) {
7837 } else if (strcasecmp(s, "middle_right") == EQUAL) {
7838 return MIDDLE_RIGHT;
7839 } else if (strcasecmp(s, "tl") == EQUAL) {
7841 } else if (strcasecmp(s, "tr") == EQUAL) {
7843 } else if (strcasecmp(s, "tm") == EQUAL) {
7845 } else if (strcasecmp(s, "bl") == EQUAL) {
7847 } else if (strcasecmp(s, "br") == EQUAL) {
7848 return BOTTOM_RIGHT;
7849 } else if (strcasecmp(s, "bm") == EQUAL) {
7850 return BOTTOM_MIDDLE;
7851 } else if (strcasecmp(s, "ml") == EQUAL) {
7853 } else if (strcasecmp(s, "mr") == EQUAL) {
7854 return MIDDLE_RIGHT;
7855 } else if (strcasecmp(s, "none") == EQUAL) {
7863 static void set_default_configurations_for_x(void)
7865 default_fg_color = WhitePixel(display, screen);
7866 default_bg_color = BlackPixel(display, screen);
7867 default_out_color = BlackPixel(display, screen);
7868 color0 = default_fg_color;
7869 color1 = default_fg_color;
7870 color2 = default_fg_color;
7871 color3 = default_fg_color;
7872 color4 = default_fg_color;
7873 color5 = default_fg_color;
7874 color6 = default_fg_color;
7875 color7 = default_fg_color;
7876 color8 = default_fg_color;
7877 color9 = default_fg_color;
7878 current_text_color = default_fg_color;
7882 static void set_default_configurations(void)
7890 fork_to_background = 0;
7891 total_run_times = 0;
7892 info.cpu_avg_samples = 2;
7893 info.net_avg_samples = 2;
7894 info.diskio_avg_samples = 2;
7899 format_human_readable = 1;
7906 mpd_env_host = getenv("MPD_HOST");
7907 mpd_env_port = getenv("MPD_PORT");
7909 if (!mpd_env_host || !strlen(mpd_env_host)) {
7910 mpd_set_host("localhost");
7912 /* MPD_HOST environment variable is set */
7913 char *mpd_hostpart = strchr(mpd_env_host, '@');
7914 if (!mpd_hostpart) {
7915 mpd_set_host(mpd_env_host);
7917 /* MPD_HOST contains a password */
7918 char mpd_password[mpd_hostpart - mpd_env_host + 1];
7919 snprintf(mpd_password, mpd_hostpart - mpd_env_host + 1, "%s", mpd_env_host);
7921 if (!strlen(mpd_hostpart + 1)) {
7922 mpd_set_host("localhost");
7924 mpd_set_host(mpd_hostpart + 1);
7927 mpd_set_password(mpd_password, 1);
7932 if (!mpd_env_port || mpd_set_port(mpd_env_port)) {
7933 /* failed to set port from environment variable */
7934 mpd_set_port("6600");
7938 info.xmms2.artist = NULL;
7939 info.xmms2.album = NULL;
7940 info.xmms2.title = NULL;
7941 info.xmms2.genre = NULL;
7942 info.xmms2.comment = NULL;
7943 info.xmms2.url = NULL;
7944 info.xmms2.status = NULL;
7945 info.xmms2.playlist = NULL;
7947 use_spacer = NO_SPACER;
7949 output_methods = TO_X;
7951 output_methods = TO_STDOUT;
7954 show_graph_scale = 0;
7955 show_graph_range = 0;
7958 draw_graph_borders = 1;
7960 set_first_font("6x10");
7968 window.type = TYPE_NORMAL;
7970 strcpy(window.class_name, PACKAGE_NAME);
7971 sprintf(window.title, PACKAGE_NAME" (%s)", info.uname_s.nodename);
7973 stippled_borders = 0;
7974 window.border_inner_margin = 3;
7975 window.border_outer_margin = 1;
7976 window.border_width = 1;
7977 text_alignment = BOTTOM_LEFT;
7978 info.x11.monitor.number = 1;
7979 info.x11.monitor.current = 0;
7980 info.x11.desktop.current = 1;
7981 info.x11.desktop.number = 1;
7982 info.x11.desktop.nitems = 0;
7983 info.x11.desktop.all_names = NULL;
7984 info.x11.desktop.name = NULL;
7987 for (i = 0; i < MAX_TEMPLATES; i++) {
7990 template[i] = strdup("");
7993 free(current_mail_spool);
7997 variable_substitute(MAIL_FILE, buf, 256);
7998 if (buf[0] != '\0') {
7999 current_mail_spool = strndup(buf, text_buffer_size);
8004 set_update_interval(3);
8005 update_interval_bat = NOBATTERY;
8006 info.music_player_interval = 1.0;
8007 stuff_in_uppercase = 0;
8008 info.users.number = 1;
8010 #ifdef TCP_PORT_MONITOR
8011 /* set default connection limit */
8012 tcp_portmon_set_max_connections(0);
8016 /* returns 1 if you can overwrite or create the file at 'path' */
8017 static _Bool overwrite_works(const char *path)
8021 if (!(filepointer = fopen(path, "w")))
8023 fclose(filepointer);
8027 /* returns 1 if you can append or create the file at 'path' */
8028 static _Bool append_works(const char *path)
8032 if (!(filepointer = fopen(path, "a")))
8034 fclose(filepointer);
8040 /* WARNING, this type not in Xlib spec */
8041 int x11_error_handler(Display *d, XErrorEvent *err)
8042 __attribute__((noreturn));
8043 int x11_error_handler(Display *d, XErrorEvent *err)
8045 NORM_ERR("X Error: type %i Display %lx XID %li serial %lu error_code %i request_code %i minor_code %i other Display: %lx\n",
8047 (long unsigned)err->display,
8048 (long)err->resourceid,
8058 int x11_ioerror_handler(Display *d)
8059 __attribute__((noreturn));
8060 int x11_ioerror_handler(Display *d)
8062 NORM_ERR("X Error: Display %lx\n",
8069 static void X11_initialisation(void)
8071 if (x_initialised == YES) return;
8072 output_methods |= TO_X;
8074 set_default_configurations_for_x();
8075 x_initialised = YES;
8078 /* WARNING, this type not in Xlib spec */
8079 XSetErrorHandler(&x11_error_handler);
8080 XSetIOErrorHandler(&x11_ioerror_handler);
8084 static char **xargv = 0;
8085 static int xargc = 0;
8087 static void X11_create_window(void)
8089 if (output_methods & TO_X) {
8091 init_window(own_window, text_width + window.border_inner_margin * 2 + window.border_outer_margin * 2 + window.border_width * 2,
8092 text_height + window.border_inner_margin * 2 + window.border_outer_margin * 2 + window.border_width * 2, set_transparent, background_colour,
8094 #else /* OWN_WINDOW */
8095 init_window(0, text_width + window.border_inner_margin * 2 + window.border_outer_margin * 2 + window.border_width * 2,
8096 text_height + window.border_inner_margin * 2 + window.border_outer_margin * 2 + window.border_width * 2, set_transparent, 0,
8098 #endif /* OWN_WINDOW */
8102 update_text_area(); /* to position text/window on screen */
8105 if (own_window && !fixed_pos) {
8106 XMoveWindow(display, window.window, window.x, window.y);
8109 set_transparent_background(window.window);
8117 x11_stuff.region = XCreateRegion();
8119 if (!XDamageQueryExtension(display, &x11_stuff.event_base, &x11_stuff.error_base)) {
8120 NORM_ERR("Xdamage extension unavailable");
8122 x11_stuff.damage = XDamageCreate(display, window.window, XDamageReportNonEmpty);
8123 x11_stuff.region2 = XFixesCreateRegionFromWindow(display, window.window, 0);
8124 x11_stuff.part = XFixesCreateRegionFromWindow(display, window.window, 0);
8125 #endif /* HAVE_XDAMAGE */
8128 update_text_area(); /* to get initial size of the window */
8131 /* setup lua window globals */
8132 llua_setup_window_table(text_start_x, text_start_y, text_width, text_height);
8133 #endif /* HAVE_LUA */
8137 #define CONF_ERR NORM_ERR("%s: %d: config file error", f, line)
8138 #define CONF_ERR2(a) NORM_ERR("%s: %d: config file error: %s", f, line, a)
8139 #define CONF2(a) if (strcasecmp(name, a) == 0)
8140 #define CONF(a) else CONF2(a)
8141 #define CONF3(a, b) else if (strcasecmp(name, a) == 0 \
8142 || strcasecmp(name, b) == 0)
8143 #define CONF_CONTINUE 1
8144 #define CONF_BREAK 2
8145 #define CONF_BUFF_SIZE 512
8147 static FILE *open_config_file(const char *f)
8149 #ifdef CONFIG_OUTPUT
8150 if (!strcmp(f, "==builtin==")) {
8151 return conf_cookie_open();
8153 #endif /* CONFIG_OUTPUT */
8154 return fopen(f, "r");
8157 static int do_config_step(int *line, FILE *fp, char *buf, char **name, char **value)
8161 if (fgets(buf, CONF_BUFF_SIZE, fp) == NULL) {
8164 remove_comments(buf);
8169 while (*p && isspace((int) *p)) {
8173 return CONF_CONTINUE; /* empty line */
8180 while (*p2 && !isspace((int) *p2)) {
8184 *p2 = '\0'; /* break at name's end */
8191 while (*p && isspace((int) *p)) {
8197 p2 = *value + strlen(*value);
8198 while (isspace((int) *(p2 - 1))) {
8207 char load_config_file(const char *f)
8212 fp = open_config_file(f);
8216 DBGP("reading contents from config file '%s'", f);
8219 char buff[CONF_BUFF_SIZE], *name, *value;
8220 int ret = do_config_step(&line, fp, buff, &name, &value);
8221 if (ret == CONF_BREAK) {
8223 } else if (ret == CONF_CONTINUE) {
8229 /* don't listen if X is already initialised or
8230 * if we already know we don't want it */
8231 if(x_initialised != YES) {
8232 if (string_to_bool(value)) {
8233 output_methods &= TO_X;
8235 output_methods &= ~TO_X;
8236 x_initialised = NEVER;
8241 if (!value || x_initialised == YES) {
8246 disp = strdup(value);
8251 if (window.type == TYPE_DOCK)
8254 #endif /*OWN_WINDOW */
8256 int a = string_to_alignment(value);
8267 CONF("background") {
8268 fork_to_background = string_to_bool(value);
8271 CONF2("background") {
8272 fork_to_background = string_to_bool(value);
8276 CONF("show_graph_scale") {
8277 show_graph_scale = string_to_bool(value);
8279 CONF("show_graph_range") {
8280 show_graph_range = string_to_bool(value);
8282 CONF("border_inner_margin") {
8284 window.border_inner_margin = strtol(value, 0, 0);
8285 if (window.border_inner_margin < 0) window.border_inner_margin = 0;
8290 CONF("border_outer_margin") {
8292 window.border_outer_margin = strtol(value, 0, 0);
8293 if (window.border_outer_margin < 0) window.border_outer_margin = 0;
8298 CONF("border_width") {
8300 window.border_width = strtol(value, 0, 0);
8301 if (window.border_width < 0) window.border_width = 0;
8307 #define TEMPLATE_CONF(n) \
8308 CONF("template"#n) { \
8310 free(template[n]); \
8311 template[n] = strdup(value); \
8328 info.mail = parse_mail_args(IMAP_TYPE, value);
8335 info.mail = parse_mail_args(POP3_TYPE, value);
8340 CONF("default_bar_size") {
8343 if (sscanf(value, "%d %d", &default_bar_width, &default_bar_height) != 2) {
8350 CONF_ERR2("default_bar_size takes 2 integer arguments (ie. 'default_bar_size 0 6')")
8354 CONF("default_graph_size") {
8357 if (sscanf(value, "%d %d", &default_graph_width, &default_graph_height) != 2) {
8364 CONF_ERR2("default_graph_size takes 2 integer arguments (ie. 'default_graph_size 0 6')")
8367 CONF("default_gauge_size") {
8370 if (sscanf(value, "%d %d", &default_gauge_width, &default_gauge_height) != 2) {
8377 CONF_ERR2("default_gauge_size takes 2 integer arguments (ie. 'default_gauge_size 0 6')")
8384 mpd_set_host(value);
8390 if (value && mpd_set_port(value)) {
8394 CONF("mpd_password") {
8396 mpd_set_password(value, 0);
8402 CONF("music_player_interval") {
8404 info.music_player_interval = strtod(value, 0);
8410 CONF("sensor_device") {
8412 sensor_device = strtol(value, 0, 0);
8418 CONF("cpu_avg_samples") {
8420 cpu_avg_samples = strtol(value, 0, 0);
8421 if (cpu_avg_samples < 1 || cpu_avg_samples > 14) {
8424 info.cpu_avg_samples = cpu_avg_samples;
8430 CONF("net_avg_samples") {
8432 net_avg_samples = strtol(value, 0, 0);
8433 if (net_avg_samples < 1 || net_avg_samples > 14) {
8436 info.net_avg_samples = net_avg_samples;
8442 CONF("diskio_avg_samples") {
8444 diskio_avg_samples = strtol(value, 0, 0);
8445 if (diskio_avg_samples < 1 || diskio_avg_samples > 14) {
8448 info.diskio_avg_samples = diskio_avg_samples;
8456 CONF("double_buffer") {
8457 use_xdbe = string_to_bool(value);
8461 CONF("override_utf8_locale") {
8462 utf8_mode = string_to_bool(value);
8464 CONF("draw_borders") {
8465 draw_borders = string_to_bool(value);
8467 CONF("draw_graph_borders") {
8468 draw_graph_borders = string_to_bool(value);
8470 CONF("draw_shades") {
8471 draw_shades = string_to_bool(value);
8473 CONF("draw_outline") {
8474 draw_outline = string_to_bool(value);
8477 CONF("out_to_console") {
8478 if(string_to_bool(value)) {
8479 output_methods |= TO_STDOUT;
8481 output_methods &= ~TO_STDOUT;
8484 CONF("extra_newline") {
8485 extra_newline = string_to_bool(value);
8487 CONF("out_to_stderr") {
8488 if(string_to_bool(value))
8489 output_methods |= TO_STDERR;
8492 CONF("out_to_ncurses") {
8493 if(string_to_bool(value)) {
8495 output_methods |= TO_NCURSES;
8499 CONF("overwrite_file") {
8500 if(overwrite_file) {
8501 free(overwrite_file);
8504 if(overwrite_works(value)) {
8505 overwrite_file = strdup(value);
8506 output_methods |= OVERWRITE_FILE;
8508 NORM_ERR("overwrite_file won't be able to create/overwrite '%s'", value);
8510 CONF("append_file") {
8515 if(append_works(value)) {
8516 append_file = strdup(value);
8517 output_methods |= APPEND_FILE;
8519 NORM_ERR("append_file won't be able to create/append '%s'", value);
8521 CONF("use_spacer") {
8523 if (strcasecmp(value, "left") == EQUAL) {
8524 use_spacer = LEFT_SPACER;
8525 } else if (strcasecmp(value, "right") == EQUAL) {
8526 use_spacer = RIGHT_SPACER;
8527 } else if (strcasecmp(value, "none") == EQUAL) {
8528 use_spacer = NO_SPACER;
8530 use_spacer = string_to_bool(value);
8531 NORM_ERR("use_spacer should have an argument of left, right, or"
8532 " none. '%s' seems to be some form of '%s', so"
8533 " defaulting to %s.", value,
8534 use_spacer ? "true" : "false",
8535 use_spacer ? "right" : "none");
8537 use_spacer = RIGHT_SPACER;
8539 use_spacer = NO_SPACER;
8543 NORM_ERR("use_spacer should have an argument. Defaulting to right.");
8544 use_spacer = RIGHT_SPACER;
8550 use_xft = string_to_bool(value);
8554 set_first_font(value);
8558 if (value && font_count >= 0) {
8559 fonts[0].font_alpha = atof(value) * 65535.0;
8566 if (string_to_bool(value)) {
8567 NORM_ERR("Xft not enabled at compile time");
8571 /* xftfont silently ignored when no Xft */
8574 /* xftalpha is silently ignored when no Xft */
8579 set_first_font(value);
8587 gap_x = atoi(value);
8594 gap_y = atoi(value);
8600 CONF("mail_spool") {
8604 variable_substitute(value, buffer, 256);
8606 if (buffer[0] != '\0') {
8607 if (current_mail_spool) {
8608 free(current_mail_spool);
8610 current_mail_spool = strndup(buffer, text_buffer_size);
8617 CONF("minimum_size") {
8619 if (sscanf(value, "%d %d", &minimum_width, &minimum_height)
8621 if (sscanf(value, "%d", &minimum_width) != 1) {
8629 CONF("maximum_width") {
8631 if (sscanf(value, "%d", &maximum_width) != 1) {
8639 CONF("no_buffers") {
8640 no_buffers = string_to_bool(value);
8642 CONF("top_name_width") {
8644 if (sscanf(value, "%u", &top_name_width) != 1) {
8650 if (top_name_width >= max_user_text) {
8651 top_name_width = max_user_text - 1;
8654 CONF("top_cpu_separate") {
8655 cpu_separate = string_to_bool(value);
8657 CONF("short_units") {
8658 short_units = string_to_bool(value);
8660 CONF("format_human_readable") {
8661 format_human_readable = string_to_bool(value);
8663 CONF("pad_percents") {
8664 pad_percents = atoi(value);
8668 CONF("own_window") {
8670 own_window = string_to_bool(value);
8673 CONF("own_window_class") {
8675 memset(window.class_name, 0, sizeof(window.class_name));
8676 strncpy(window.class_name, value,
8677 sizeof(window.class_name) - 1);
8680 CONF("own_window_title") {
8682 memset(window.title, 0, sizeof(window.title));
8683 strncpy(window.title, value, sizeof(window.title) - 1);
8686 CONF("own_window_transparent") {
8688 set_transparent = string_to_bool(value);
8691 CONF("own_window_hints") {
8693 char *p_hint, *p_save;
8694 char delim[] = ", ";
8696 /* tokenize the value into individual hints */
8697 if ((p_hint = strtok_r(value, delim, &p_save)) != NULL) {
8699 /* fprintf(stderr, "hint [%s] parsed\n", p_hint); */
8700 if (strncmp(p_hint, "undecorate", 10) == EQUAL) {
8701 SET_HINT(window.hints, HINT_UNDECORATED);
8702 } else if (strncmp(p_hint, "below", 5) == EQUAL) {
8703 SET_HINT(window.hints, HINT_BELOW);
8704 } else if (strncmp(p_hint, "above", 5) == EQUAL) {
8705 SET_HINT(window.hints, HINT_ABOVE);
8706 } else if (strncmp(p_hint, "sticky", 6) == EQUAL) {
8707 SET_HINT(window.hints, HINT_STICKY);
8708 } else if (strncmp(p_hint, "skip_taskbar", 12) == EQUAL) {
8709 SET_HINT(window.hints, HINT_SKIP_TASKBAR);
8710 } else if (strncmp(p_hint, "skip_pager", 10) == EQUAL) {
8711 SET_HINT(window.hints, HINT_SKIP_PAGER);
8716 p_hint = strtok_r(NULL, delim, &p_save);
8717 } while (p_hint != NULL);
8723 CONF("own_window_type") {
8725 if (strncmp(value, "normal", 6) == EQUAL) {
8726 window.type = TYPE_NORMAL;
8727 } else if (strncmp(value, "desktop", 7) == EQUAL) {
8728 window.type = TYPE_DESKTOP;
8729 } else if (strncmp(value, "dock", 4) == EQUAL) {
8730 window.type = TYPE_DOCK;
8731 text_alignment = TOP_LEFT;
8732 } else if (strncmp(value, "panel", 5) == EQUAL) {
8733 window.type = TYPE_PANEL;
8734 } else if (strncmp(value, "override", 8) == EQUAL) {
8735 window.type = TYPE_OVERRIDE;
8744 CONF("stippled_borders") {
8746 stippled_borders = strtol(value, 0, 0);
8748 stippled_borders = 4;
8752 CONF("imlib_cache_size") {
8754 cimlib_set_cache_size(atoi(value));
8757 CONF("imlib_cache_flush_interval") {
8759 cimlib_set_cache_flush_interval(atoi(value));
8764 CONF("update_interval_on_battery") {
8766 update_interval_bat = strtod(value, 0);
8771 CONF("update_interval") {
8773 set_update_interval(strtod(value, 0));
8777 if (info.music_player_interval == 0) {
8778 // default to update_interval
8779 info.music_player_interval = update_interval;
8782 CONF("total_run_times") {
8784 total_run_times = strtod(value, 0);
8790 stuff_in_uppercase = string_to_bool(value);
8792 CONF("max_specials") {
8794 max_specials = atoi(value);
8799 CONF("max_user_text") {
8801 max_user_text = atoi(value);
8806 CONF("text_buffer_size") {
8808 text_buffer_size = atoi(value);
8809 if (text_buffer_size < DEFAULT_TEXT_BUFFER_SIZE) {
8810 NORM_ERR("text_buffer_size must be >=%i bytes", DEFAULT_TEXT_BUFFER_SIZE);
8811 text_buffer_size = DEFAULT_TEXT_BUFFER_SIZE;
8819 if (output_methods & TO_X) {
8820 X11_initialisation();
8829 global_text = (char *) malloc(1);
8830 global_text[0] = '\0';
8833 unsigned int l = strlen(global_text);
8835 char buf[CONF_BUFF_SIZE];
8837 if (fgets(buf, CONF_BUFF_SIZE, fp) == NULL) {
8843 if (bl >= 2 && buf[bl-2] == '\\' && buf[bl-1] == '\n') {
8851 /* Check for continuation of \\-\n. */
8852 if (l > 0 && buf[0] == '\n' && global_text[l-1] == '\\') {
8853 global_text[l-1] = '\0';
8857 global_text = (char *) realloc(global_text, l + bl + 1);
8858 strcat(global_text, buf);
8860 if (strlen(global_text) > max_user_text) {
8865 if (strlen(global_text) < 1) {
8866 CRIT_ERR(NULL, NULL, "no text supplied in configuration; exiting");
8868 global_text_lines = line + 1;
8871 #ifdef TCP_PORT_MONITOR
8872 CONF("max_port_monitor_connections") {
8874 if (!value || (sscanf(value, "%d", &max) != 1)) {
8875 /* an error. use default, warn and continue. */
8876 tcp_portmon_set_max_connections(0);
8878 } else if (tcp_portmon_set_max_connections(max)) {
8879 /* max is < 0, default has been set*/
8884 CONF("if_up_strictness") {
8886 NORM_ERR("incorrect if_up_strictness value, defaulting to 'up'");
8887 ifup_strictness = IFUP_UP;
8888 } else if (strcasecmp(value, "up") == EQUAL) {
8889 ifup_strictness = IFUP_UP;
8890 } else if (strcasecmp(value, "link") == EQUAL) {
8891 ifup_strictness = IFUP_LINK;
8892 } else if (strcasecmp(value, "address") == EQUAL) {
8893 ifup_strictness = IFUP_ADDR;
8895 NORM_ERR("incorrect if_up_strictness value, defaulting to 'up'");
8896 ifup_strictness = IFUP_UP;
8900 CONF("temperature_unit") {
8902 NORM_ERR("config option 'temperature_unit' needs an argument, either 'celsius' or 'fahrenheit'");
8903 } else if (set_temp_output_unit(value)) {
8904 NORM_ERR("temperature_unit: incorrect argument");
8911 char *ptr = strtok(value, " ");
8914 ptr = strtok(NULL, " ");
8921 CONF("lua_draw_hook_pre") {
8923 llua_set_draw_pre_hook(value);
8928 CONF("lua_draw_hook_post") {
8930 llua_set_draw_post_hook(value);
8935 CONF("lua_startup_hook") {
8937 llua_set_startup_hook(value);
8942 CONF("lua_shutdown_hook") {
8944 llua_set_shutdown_hook(value);
8950 #endif /* HAVE_LUA */
8962 CONF("default_color"){}
8963 CONF3("default_shade_color", "default_shadecolor"){}
8964 CONF3("default_outline_color", "default_outlinecolor") {}
8965 CONF("own_window_colour") {}
8968 NORM_ERR("%s: %d: no such configuration: '%s'", f, line, name);
8974 if (info.music_player_interval == 0) {
8975 // default to update_interval
8976 info.music_player_interval = update_interval;
8978 if (!global_text) { // didn't supply any text
8979 CRIT_ERR(NULL, NULL, "missing text block in configuration; exiting");
8985 static void load_config_file_x11(const char *f)
8990 fp = open_config_file(f);
8994 DBGP("reading contents from config file '%s'", f);
8997 char buff[CONF_BUFF_SIZE], *name, *value;
8998 int ret = do_config_step(&line, fp, buff, &name, &value);
8999 if (ret == CONF_BREAK) {
9001 } else if (ret == CONF_CONTINUE) {
9006 X11_initialisation();
9007 if (x_initialised == YES) {
9009 color0 = get_x11_color(value);
9016 X11_initialisation();
9017 if (x_initialised == YES) {
9019 color1 = get_x11_color(value);
9026 X11_initialisation();
9027 if (x_initialised == YES) {
9029 color2 = get_x11_color(value);
9036 X11_initialisation();
9037 if (x_initialised == YES) {
9039 color3 = get_x11_color(value);
9046 X11_initialisation();
9047 if (x_initialised == YES) {
9049 color4 = get_x11_color(value);
9056 X11_initialisation();
9057 if (x_initialised == YES) {
9059 color5 = get_x11_color(value);
9066 X11_initialisation();
9067 if (x_initialised == YES) {
9069 color6 = get_x11_color(value);
9076 X11_initialisation();
9077 if (x_initialised == YES) {
9079 color7 = get_x11_color(value);
9086 X11_initialisation();
9087 if (x_initialised == YES) {
9089 color8 = get_x11_color(value);
9096 X11_initialisation();
9097 if (x_initialised == YES) {
9099 color9 = get_x11_color(value);
9105 CONF("default_color") {
9106 X11_initialisation();
9107 if (x_initialised == YES) {
9109 default_fg_color = get_x11_color(value);
9115 CONF3("default_shade_color", "default_shadecolor") {
9116 X11_initialisation();
9117 if (x_initialised == YES) {
9119 default_bg_color = get_x11_color(value);
9125 CONF3("default_outline_color", "default_outlinecolor") {
9126 X11_initialisation();
9127 if (x_initialised == YES) {
9129 default_out_color = get_x11_color(value);
9136 CONF("own_window_colour") {
9137 X11_initialisation();
9138 if (x_initialised == YES) {
9140 background_colour = get_x11_color(value);
9142 NORM_ERR("Invalid colour for own_window_colour (try omitting the "
9143 "'#' for hex colours");
9149 /* initialize X11 if nothing X11-related is mentioned before TEXT (and if X11 is the default outputmethod) */
9150 if(output_methods & TO_X) {
9151 X11_initialisation();
9160 #undef CONF_CONTINUE
9161 #undef CONF_BUFF_SIZE
9169 static void print_help(const char *prog_name) {
9170 printf("Usage: %s [OPTION]...\n"
9171 PACKAGE_NAME" is a system monitor that renders text on desktop or to own transparent\n"
9172 "window. Command line options will override configurations defined in config\n"
9174 " -v, --version version\n"
9175 " -q, --quiet quiet mode\n"
9176 " -D, --debug increase debugging output, ie. -DD for more debugging\n"
9177 " -c, --config=FILE config file to load\n"
9178 #ifdef CONFIG_OUTPUT
9179 " -C, --print-config print the builtin default config to stdout\n"
9180 " e.g. 'conky -C > ~/.conkyrc' will create a new default config\n"
9182 " -d, --daemonize daemonize, fork to background\n"
9183 " -h, --help help\n"
9185 " -a, --alignment=ALIGNMENT text alignment on screen, {top,bottom,middle}_{left,right,middle}\n"
9186 " -f, --font=FONT font to use\n"
9187 " -X, --display=DISPLAY X11 display to use\n"
9189 " -o, --own-window create own window to draw\n"
9192 " -b, --double-buffer double buffer (prevents flickering)\n"
9194 " -w, --window-id=WIN_ID window id to draw\n"
9195 " -x X x position\n"
9196 " -y Y y position\n"
9198 " -t, --text=TEXT text to render, remember single quotes, like -t '$uptime'\n"
9199 " -u, --interval=SECS update interval\n"
9200 " -i COUNT number of times to update "PACKAGE_NAME" (and quit)\n",
9205 /* : means that character before that takes an argument */
9206 static const char *getopt_string = "vVqdDt:u:i:hc:"
9216 #ifdef CONFIG_OUTPUT
9221 static const struct option longopts[] = {
9222 { "help", 0, NULL, 'h' },
9223 { "version", 0, NULL, 'V' },
9224 { "debug", 0, NULL, 'D' },
9225 { "config", 1, NULL, 'c' },
9226 #ifdef CONFIG_OUTPUT
9227 { "print-config", 0, NULL, 'C' },
9229 { "daemonize", 0, NULL, 'd' },
9231 { "alignment", 1, NULL, 'a' },
9232 { "font", 1, NULL, 'f' },
9233 { "display", 1, NULL, 'X' },
9235 { "own-window", 0, NULL, 'o' },
9238 { "double-buffer", 0, NULL, 'b' },
9240 { "window-id", 1, NULL, 'w' },
9242 { "text", 1, NULL, 't' },
9243 { "interval", 0, NULL, 'u' },
9247 void initialisation(int argc, char **argv) {
9248 struct sigaction act, oact;
9250 set_default_configurations();
9251 load_config_file(current_config);
9252 currentconffile = conftree_add(currentconffile, current_config);
9254 /* init specials array */
9255 if ((specials = calloc(sizeof(struct special_t), max_specials)) == 0) {
9256 NORM_ERR("failed to create specials array");
9260 if (current_mail_spool == NULL) {
9263 variable_substitute(MAIL_FILE, buf, 256);
9265 if (buf[0] != '\0') {
9266 current_mail_spool = strndup(buf, text_buffer_size);
9271 /* handle other command line arguments */
9273 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__OpenBSD__) \
9274 || defined(__NetBSD__)
9275 optind = optreset = 1;
9280 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
9281 if ((kd = kvm_open("/dev/null", "/dev/null", "/dev/null", O_RDONLY,
9282 "kvm_open")) == NULL) {
9283 CRIT_ERR(NULL, NULL, "cannot read kvm");
9288 int c = getopt_long(argc, argv, getopt_string, longopts, NULL);
9296 fork_to_background = 1;
9299 global_debug_level++;
9303 set_first_font(optarg);
9306 text_alignment = string_to_alignment(optarg);
9325 global_text = strndup(optarg, max_user_text);
9326 convert_escapes(global_text);
9330 update_interval = strtod(optarg, 0);
9331 update_interval_old = update_interval;
9332 if (info.music_player_interval == 0) {
9333 // default to update_interval
9334 info.music_player_interval = update_interval;
9339 total_run_times = strtod(optarg, 0);
9343 gap_x = atoi(optarg);
9347 gap_y = atoi(optarg);
9358 if (output_methods & TO_X) {
9359 load_config_file_x11(current_config);
9363 /* generate text and get initial size */
9364 extract_variable_text(global_text);
9371 if (fork_to_background) {
9376 NORM_ERR(PACKAGE_NAME": couldn't fork() to background: %s",
9383 fprintf(stderr, "\n");
9388 /* parent process */
9389 fprintf(stderr, PACKAGE_NAME": forked to background, pid is %d\n",
9396 text_buffer = malloc(max_user_text);
9397 memset(text_buffer, 0, max_user_text);
9398 tmpstring1 = malloc(text_buffer_size);
9399 memset(tmpstring1, 0, text_buffer_size);
9400 tmpstring2 = malloc(text_buffer_size);
9401 memset(tmpstring2, 0, text_buffer_size);
9406 X11_create_window();
9409 llua_setup_info(&info, update_interval);
9410 #endif /* HAVE_LUA */
9412 /* Set signal handlers */
9413 act.sa_handler = signal_handler;
9414 sigemptyset(&act.sa_mask);
9417 act.sa_flags |= SA_RESTART;
9420 if ( sigaction(SIGINT, &act, &oact) < 0
9421 || sigaction(SIGALRM, &act, &oact) < 0
9422 || sigaction(SIGUSR1, &act, &oact) < 0
9423 || sigaction(SIGHUP, &act, &oact) < 0
9424 || sigaction(SIGTERM, &act, &oact) < 0) {
9425 NORM_ERR("error setting signal handler: %s", strerror(errno));
9429 llua_startup_hook();
9430 #endif /* HAVE_LUA */
9433 int main(int argc, char **argv)
9442 g_signal_pending = 0;
9443 max_user_text = MAX_USER_TEXT_DEFAULT;
9445 memset(&info, 0, sizeof(info));
9446 memset(template, 0, sizeof(template));
9449 #ifdef TCP_PORT_MONITOR
9450 /* set default connection limit */
9451 tcp_portmon_set_max_connections(0);
9454 /* handle command line parameters that don't change configs */
9456 if (((s = getenv("LC_ALL")) && *s) || ((s = getenv("LC_CTYPE")) && *s)
9457 || ((s = getenv("LANG")) && *s)) {
9458 temp = (char *) malloc((strlen(s) + 1) * sizeof(char));
9460 NORM_ERR("malloc failed");
9462 for (x = 0; x < strlen(s); x++) {
9463 temp[x] = tolower(s[x]);
9466 if (strstr(temp, "utf-8") || strstr(temp, "utf8")) {
9472 if (!setlocale(LC_CTYPE, "")) {
9473 NORM_ERR("Can't set the specified locale!\nCheck LANG, LC_CTYPE, LC_ALL.");
9477 int c = getopt_long(argc, argv, getopt_string, longopts, NULL);
9488 if (current_config) {
9489 free(current_config);
9491 current_config = strndup(optarg, max_user_text);
9494 freopen("/dev/null", "w", stderr);
9497 print_help(argv[0]);
9499 #ifdef CONFIG_OUTPUT
9506 window.window = strtol(optarg, 0, 0);
9511 disp = strdup(optarg);
9520 /* check if specified config file is valid */
9521 if (current_config) {
9523 if (stat(current_config, &sb) ||
9524 (!S_ISREG(sb.st_mode) && !S_ISLNK(sb.st_mode))) {
9525 NORM_ERR("invalid configuration file '%s'\n", current_config);
9526 free(current_config);
9531 /* load current_config, CONFIG_FILE or SYSTEM_CONFIG_FILE */
9533 if (!current_config) {
9534 /* load default config file */
9535 char buf[DEFAULT_TEXT_BUFFER_SIZE];
9538 /* Try to use personal config file first */
9539 to_real_path(buf, CONFIG_FILE);
9540 if (buf[0] && (fp = fopen(buf, "r"))) {
9541 current_config = strndup(buf, max_user_text);
9545 /* Try to use system config file if personal config not readable */
9546 if (!current_config && (fp = fopen(SYSTEM_CONFIG_FILE, "r"))) {
9547 current_config = strndup(SYSTEM_CONFIG_FILE, max_user_text);
9551 /* No readable config found */
9552 if (!current_config) {
9553 #ifdef CONFIG_OUTPUT
9554 current_config = strdup("==builtin==");
9555 NORM_ERR("no readable personal or system-wide config file found,"
9556 " using builtin default");
9558 CRIT_ERR(NULL, NULL, "no readable personal or system-wide config file found");
9559 #endif /* ! CONF_OUTPUT */
9564 /* Load xoap keys, if existing */
9568 #ifdef HAVE_SYS_INOTIFY_H
9569 inotify_fd = inotify_init();
9570 #endif /* HAVE_SYS_INOTIFY_H */
9572 initialisation(argc, argv);
9576 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
9584 void alarm_handler(void) {
9586 kill(childpid, SIGTERM);
9590 static void signal_handler(int sig)
9592 /* signal handler is light as a feather, as it should be.
9593 * we will poll g_signal_pending with each loop of conky
9594 * and do any signal processing there, NOT here (except
9595 * SIGALRM because this is caused when conky is hanging) */
9596 if(sig == SIGALRM) {
9599 g_signal_pending = sig;