1 /* Conky, a system monitor, based on torsmo
3 * Any original torsmo code is licensed under the BSD license
5 * All code written since the fork of torsmo is licensed under the GPL
7 * Please see COPYING for details
9 * Copyright (c) 2004, Hannu Saransaari and Lauri Hakkarainen
10 * Copyright (c) 2005-2009 Brenden Matthews, Philip Kovacs, et. al.
12 * All rights reserved.
14 * This program is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation, either version 3 of the License, or
17 * (at your option) any later version.
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program. If not, see <http://www.gnu.org/licenses/>.
29 #include "text_object.h"
44 #include <sys/param.h>
45 #ifdef HAVE_SYS_INOTIFY_H
46 #include <sys/inotify.h>
47 #endif /* HAVE_SYS_INOTIFY_H */
50 #include <X11/Xutil.h>
52 #include <X11/extensions/Xdamage.h>
58 #include <sys/types.h>
60 #include <netinet/in.h>
79 #include "temphelper.h"
83 /* check for OS and include appropriate headers */
84 #if defined(__linux__)
86 #elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
88 #elif defined(__OpenBSD__)
92 #if defined(__FreeBSD_kernel__)
96 /* FIXME: apm_getinfo is unused here. maybe it's meant for common.c */
97 #if (defined(__FreeBSD__) || defined(__FreeBSD_kernel__) \
98 || defined(__OpenBSD__)) && (defined(i386) || defined(__i386__))
99 int apm_getinfo(int fd, apm_info_t aip);
100 char *get_apm_adapter(void);
101 char *get_apm_battery_life(void);
102 char *get_apm_battery_time(void);
110 #include "defconfig.h"
111 #ifdef HAVE_FOPENCOOKIE
112 #include "conf_cookie.h"
117 #define S_ISSOCK(x) ((x & S_IFMT) == S_IFSOCK)
120 #define MAIL_FILE "$MAIL"
121 #define MAX_IF_BLOCK_DEPTH 5
123 //#define SIGNAL_BLOCKING
124 #undef SIGNAL_BLOCKING
126 /* debugging level, used by logging.h */
127 int global_debug_level = 0;
129 /* two strings for internal use */
130 static char *tmpstring1, *tmpstring2;
132 /* variables holding various config settings */
140 int top_cpu, top_mem, top_time;
141 static unsigned int top_name_width = 15;
143 enum x_initialiser_state x_initialised = NO;
144 static volatile int g_signal_pending;
145 /* Update interval */
146 double update_interval;
149 /* prototypes for internally used functions */
150 static void signal_handler(int);
151 static void print_version(void) __attribute__((noreturn));
152 static void reload_config(void);
153 static void clean_up(void);
154 static void generate_text_internal(char *, int, struct text_object,
155 struct information *);
156 static int extract_variable_text_internal(struct text_object *,
159 static void print_version(void)
161 printf(PACKAGE_NAME" "VERSION" compiled "BUILD_DATE" for "BUILD_ARCH"\n");
163 printf("\nCompiled in features:\n\n"
164 "System config file: "SYSTEM_CONFIG_FILE"\n\n"
168 " * Xdamage extension\n"
169 # endif /* HAVE_XDAMAGE */
171 " * XDBE (double buffer extension)\n"
172 # endif /* HAVE_XDBE */
177 "\n Music detection:\n"
180 #endif /* AUDACIOUS */
196 #endif /* HAVE_OPENMP */
203 #ifdef TCP_PORT_MONITOR
205 #endif /* TCP_PORT_MONITOR */
211 #endif /* HAVE_LUA */
214 #endif /* HAVE_IWLIB */
216 " * support for IBM/Lenovo notebooks\n"
226 #endif /* CONFIG_OUTPUT */
231 " * ALSA mixer support\n"
232 #endif /* MIXER_IS_ALSA */
241 static const char *suffixes[] = { "B", "KiB", "MiB", "GiB", "TiB", "PiB", "" };
246 static void X11_destroy_window(void);
247 static void X11_create_window(void);
248 static void X11_initialisation(void);
250 struct _x11_stuff_s {
254 XserverRegion region2, part;
255 int event_base, error_base;
261 static int text_start_x, text_start_y; /* text start position in window */
262 static int text_width, text_height;
277 /* display to connect to */
278 static char *disp = NULL;
282 /* struct that has all info to be shared between
283 * instances of the same text object */
284 struct information info;
286 /* default config file */
287 static char *current_config;
289 /* set to 1 if you want all text to be in uppercase */
290 static unsigned int stuff_in_upper_case;
292 /* Run how many times? */
293 static unsigned long total_run_times;
296 static int fork_to_background;
298 static int cpu_avg_samples, net_avg_samples, diskio_avg_samples;
300 /* filenames for output */
301 char *overwrite_file = NULL; FILE *overwrite_fpointer = NULL;
302 char *append_file = NULL; FILE *append_fpointer = NULL;
306 static int show_graph_scale;
307 static int show_graph_range;
309 /* Position on the screen */
310 static int text_alignment;
311 static int gap_x, gap_y;
314 static int draw_borders;
315 static int draw_graph_borders;
316 static int stippled_borders;
318 static int draw_shades, draw_outline;
320 static int border_margin, border_width;
322 static long default_fg_color, default_bg_color, default_out_color;
324 /* create own window or draw stuff to root? */
325 static int set_transparent = 0;
328 static int own_window = 0;
329 static int background_colour = 0;
331 /* fixed size/pos is set if wm/user changes them */
332 static int fixed_size = 0, fixed_pos = 0;
335 static int minimum_width, minimum_height;
336 static int maximum_width;
341 static int sensor_device;
344 static long color0, color1, color2, color3, color4, color5, color6, color7,
347 #define MAX_TEMPLATES 10
348 static char *template[MAX_TEMPLATES];
350 /* maximum size of config TEXT buffer, i.e. below TEXT line. */
351 static unsigned int max_user_text = MAX_USER_TEXT_DEFAULT;
353 /* maximum size of individual text buffers, ie $exec buffer size */
354 unsigned int text_buffer_size = DEFAULT_TEXT_BUFFER_SIZE;
357 #define CODEPAGE_LENGTH 20
359 long iconv_count = 0;
360 char iconv_converting;
361 static iconv_t **iconv_cd = 0;
363 int register_iconv(iconv_t *new_iconv)
365 iconv_cd = realloc(iconv_cd, sizeof(iconv_t *) * (iconv_count + 1));
367 CRIT_ERR("Out of memory");
369 iconv_cd[iconv_count] = malloc(sizeof(iconv_t));
370 if (!iconv_cd[iconv_count]) {
371 CRIT_ERR("Out of memory");
373 memcpy(iconv_cd[iconv_count], new_iconv, sizeof(iconv_t));
378 void free_iconv(void)
383 for (i = 0; i < iconv_count; i++) {
385 iconv_close(*iconv_cd[i]);
399 /* no buffers in used memory? */
402 /* pad percentages to decimals? */
403 static int pad_percents = 0;
405 static char *global_text = 0;
406 long global_text_lines;
408 static int total_updates;
409 static int updatereset;
411 int check_contains(char *f, char *s)
414 FILE *where = open_file(f, 0);
419 while (fgets(buf1, 256, where)) {
420 if (strstr(buf1, s)) {
427 ERR("Could not open the file");
433 static inline int calc_text_width(const char *s, int l)
435 if ((output_methods & TO_X) == 0)
442 XftTextExtentsUtf8(display, fonts[selected_font].xftfont,
443 (const FcChar8 *) s, l, &gi);
445 XftTextExtents8(display, fonts[selected_font].xftfont,
446 (const FcChar8 *) s, l, &gi);
452 return XTextWidth(fonts[selected_font].font, s, l);
457 /* formatted text to render on screen, generated in generate_text(),
458 * drawn in draw_stuff() */
460 static char *text_buffer;
463 static unsigned int special_index; /* used when drawing */
466 /* quite boring functions */
468 static inline void for_each_line(char *b, void f(char *))
472 for (ps = b, pe = b; *pe; pe++) {
486 static void convert_escapes(char *buf)
488 char *p = buf, *s = buf;
495 } else if (*s == '\\') {
506 /* Prints anything normally printed with snprintf according to the current value
507 * of use_spacer. Actually slightly more flexible than snprintf, as you can
508 * safely specify the destination buffer as one of your inputs. */
509 int spaced_print(char *buf, int size, const char *format, int width, ...)
518 tempbuf = malloc(size * sizeof(char));
520 // Passes the varargs along to vsnprintf
521 va_start(argp, width);
522 vsnprintf(tempbuf, size, format, argp);
525 switch (use_spacer) {
527 len = snprintf(buf, size, "%s", tempbuf);
530 len = snprintf(buf, size, "%*s", width, tempbuf);
533 len = snprintf(buf, size, "%-*s", width, tempbuf);
540 /* print percentage values
542 * - i.e., unsigned values between 0 and 100
543 * - respect the value of pad_percents */
544 static int percent_print(char *buf, int size, unsigned value)
546 return spaced_print(buf, size, "%u", pad_percents, value);
549 /* converts from bytes to human readable format (K, M, G, T)
551 * The algorithm always divides by 1024, as unit-conversion of byte
552 * counts suggests. But for output length determination we need to
553 * compare with 1000 here, as we print in decimal form. */
554 static void human_readable(long long num, char *buf, int size)
556 const char **suffix = suffixes;
570 if (llabs(num) < 1000LL) {
571 spaced_print(buf, size, format, width, 0, (float)num, *suffix);
575 while (llabs(num / 1024) >= 1000LL && **(suffix + 2)) {
583 /* fnum should now be < 1000, so looks like 'AAA.BBBBB'
585 * The goal is to always have a significance of 3, by
586 * adjusting the decimal part of the number. Sample output:
590 * so the point of alignment resides between number and unit. The
591 * upside of this is that there is minimal padding necessary, though
592 * there should be a way to make alignment take place at the decimal
593 * dot (then with fixed width decimal part).
595 * Note the repdigits below: when given a precision value, printf()
596 * rounds the float to it, not just cuts off the remaining digits. So
597 * e.g. 99.95 with a precision of 1 gets 100.0, which again should be
598 * printed with a precision of 0. Yay. */
600 precision = 0; /* print 100-999 without decimal part */
602 precision = 1; /* print 10-99 with one decimal place */
604 precision = 2; /* print 0-9 with two decimal places */
606 spaced_print(buf, size, format, width, precision, fnum, *suffix);
609 /* global object list root element */
610 static struct text_object global_root_object;
612 static inline void read_exec(const char *data, char *buf, const int size)
614 FILE *fp = popen(data, "r");
615 int length = fread(buf, 1, size, fp);
619 if (length > 0 && buf[length - 1] == '\n') {
620 buf[length - 1] = '\0';
624 void *threaded_exec(void *) __attribute__((noreturn));
626 void *threaded_exec(void *arg)
629 struct text_object *obj = (struct text_object *)arg;
632 buff = malloc(text_buffer_size);
633 read_exec(obj->data.texeci.cmd, buff,
642 timed_thread_lock(obj->data.texeci.p_timed_thread);
643 strncpy(obj->data.texeci.buffer, buff, text_buffer_size);
644 timed_thread_unlock(obj->data.texeci.p_timed_thread);
646 if (timed_thread_test(obj->data.texeci.p_timed_thread, 0)) {
647 timed_thread_exit(obj->data.texeci.p_timed_thread);
653 static struct text_object *new_text_object_internal(void)
655 struct text_object *obj = malloc(sizeof(struct text_object));
656 memset(obj, 0, sizeof(struct text_object));
661 * Frees the list of text objects root points to. When internal = 1, it won't
662 * free global objects.
664 static void free_text_objects(struct text_object *root, int internal)
666 struct text_object *obj;
672 #define data obj->data
673 for (obj = root->prev; obj; obj = root->prev) {
674 root->prev = obj->prev;
680 #endif /* !__OpenBSD__ */
685 close(data.sysfs.fd);
687 #endif /* __linux__ */
693 free(data.tztime.tz);
694 free(data.tztime.fmt);
697 free(data.mboxscan.args);
698 free(data.mboxscan.output);
703 case OBJ_unseen_mails:
704 case OBJ_flagged_mails:
705 case OBJ_unflagged_mails:
706 case OBJ_forwarded_mails:
707 case OBJ_unforwarded_mails:
708 case OBJ_replied_mails:
709 case OBJ_unreplied_mails:
710 case OBJ_draft_mails:
711 case OBJ_trashed_mails:
712 free(data.local_mail.box);
714 case OBJ_imap_unseen:
719 case OBJ_imap_messages:
724 case OBJ_pop3_unseen:
736 free_text_objects(obj->sub, 1);
739 case OBJ_if_existing:
742 free(data.ifblock.s);
743 free(data.ifblock.str);
746 free(data.tail.logfile);
747 free(data.tail.buffer);
763 case OBJ_iconv_start:
768 case OBJ_disk_protect:
772 free(data.ifblock.s);
773 free(data.ifblock.str);
776 if (info.gw_info.iface) {
777 free(info.gw_info.iface);
778 info.gw_info.iface = 0;
780 if (info.gw_info.ip) {
781 free(info.gw_info.ip);
785 case OBJ_ioscheduler:
790 #if (defined(__FreeBSD__) || defined(__linux__))
792 free(data.ifblock.s);
793 free(data.ifblock.str);
797 case OBJ_xmms2_artist:
798 if (info.xmms2.artist) {
799 free(info.xmms2.artist);
800 info.xmms2.artist = 0;
803 case OBJ_xmms2_album:
804 if (info.xmms2.album) {
805 free(info.xmms2.album);
806 info.xmms2.album = 0;
809 case OBJ_xmms2_title:
810 if (info.xmms2.title) {
811 free(info.xmms2.title);
812 info.xmms2.title = 0;
815 case OBJ_xmms2_genre:
816 if (info.xmms2.genre) {
817 free(info.xmms2.genre);
818 info.xmms2.genre = 0;
821 case OBJ_xmms2_comment:
822 if (info.xmms2.comment) {
823 free(info.xmms2.comment);
824 info.xmms2.comment = 0;
828 if (info.xmms2.url) {
829 free(info.xmms2.url);
834 if (info.xmms2.date) {
835 free(info.xmms2.date);
839 case OBJ_xmms2_status:
840 if (info.xmms2.status) {
841 free(info.xmms2.status);
842 info.xmms2.status = 0;
845 case OBJ_xmms2_playlist:
846 if (info.xmms2.playlist) {
847 free(info.xmms2.playlist);
848 info.xmms2.playlist = 0;
851 case OBJ_xmms2_smart:
852 if (info.xmms2.artist) {
853 free(info.xmms2.artist);
854 info.xmms2.artist = 0;
856 if (info.xmms2.title) {
857 free(info.xmms2.title);
858 info.xmms2.title = 0;
860 if (info.xmms2.url) {
861 free(info.xmms2.url);
868 case OBJ_bmpx_artist:
872 case OBJ_bmpx_bitrate:
882 free(data.rss.action);
888 case OBJ_lua_read_parse:
896 #endif /* HAVE_LUA */
903 case OBJ_battery_short:
906 case OBJ_battery_time:
909 #endif /* !__OpenBSD__ */
917 free(data.execi.cmd);
918 free(data.execi.buffer);
921 free(data.texeci.cmd);
922 free(data.texeci.buffer);
930 if (info.first_process && !internal) {
931 free_all_processes();
932 info.first_process = NULL;
934 if (data.top.s) free(data.top.s);
938 free(data.hddtemp.dev);
939 free(data.hddtemp.addr);
940 if (data.hddtemp.temp)
941 free(data.hddtemp.temp);
944 case OBJ_entropy_avail:
945 case OBJ_entropy_poolsize:
947 case OBJ_entropy_bar:
951 if (info.users.names) {
952 free(info.users.names);
953 info.users.names = 0;
957 if (info.users.terms) {
958 free(info.users.terms);
959 info.users.terms = 0;
963 if (info.users.times) {
964 free(info.users.times);
965 info.users.times = 0;
970 case OBJ_smapi_bat_perc:
971 case OBJ_smapi_bat_temp:
972 case OBJ_smapi_bat_power:
975 case OBJ_if_smapi_bat_installed:
976 free(data.ifblock.s);
977 free(data.ifblock.str);
991 case OBJ_mpd_bitrate:
996 case OBJ_mpd_elapsed:
1001 case OBJ_mpd_percent:
1003 case OBJ_if_mpd_playing:
1011 case OBJ_moc_artist:
1014 case OBJ_moc_totaltime:
1015 case OBJ_moc_timeleft:
1016 case OBJ_moc_curtime:
1017 case OBJ_moc_bitrate:
1023 free(data.scroll.text);
1024 free_text_objects(obj->sub, 1);
1028 free(data.combine.left);
1029 free(data.combine.seperation);
1030 free(data.combine.right);
1031 free_text_objects(obj->sub, 1);
1036 case OBJ_apcupsd_name:
1037 case OBJ_apcupsd_model:
1038 case OBJ_apcupsd_upsmode:
1039 case OBJ_apcupsd_cable:
1040 case OBJ_apcupsd_status:
1041 case OBJ_apcupsd_linev:
1042 case OBJ_apcupsd_load:
1044 case OBJ_apcupsd_loadbar:
1045 case OBJ_apcupsd_loadgraph:
1046 case OBJ_apcupsd_loadgauge:
1048 case OBJ_apcupsd_charge:
1049 case OBJ_apcupsd_timeleft:
1050 case OBJ_apcupsd_temp:
1051 case OBJ_apcupsd_lastxfer:
1053 #endif /* APCUPSD */
1061 void scan_mixer_bar(const char *arg, int *a, int *w, int *h)
1066 if (arg && sscanf(arg, "%63s %n", buf1, &n) >= 1) {
1067 *a = mixer_init(buf1);
1068 scan_bar(arg + n, w, h);
1070 *a = mixer_init(NULL);
1071 scan_bar(arg, w, h);
1076 /* strip a leading /dev/ if any, following symlinks first
1078 * BEWARE: this function returns a pointer to static content
1079 * which gets overwritten in consecutive calls. I.e.:
1080 * this function is NOT reentrant.
1082 static const char *dev_name(const char *path)
1084 static char buf[255]; /* should be enough for pathnames */
1090 #define DEV_NAME(x) \
1091 x != NULL && strlen(x) > 5 && strncmp(x, "/dev/", 5) == 0 ? x + 5 : x
1092 if ((buflen = readlink(path, buf, 254)) == -1)
1093 return DEV_NAME(path);
1095 return DEV_NAME(buf);
1099 static int parse_top_args(const char *s, const char *arg, struct text_object *obj)
1104 if (obj->data.top.was_parsed) {
1107 obj->data.top.was_parsed = 1;
1109 if (arg && !obj->data.top.s) {
1110 obj->data.top.s = strndup(arg, text_buffer_size);
1113 need_mask |= (1 << INFO_TOP);
1116 obj->type = OBJ_top;
1118 } else if (strcmp(&s[3], "_mem") == EQUAL) {
1119 obj->type = OBJ_top_mem;
1121 } else if (strcmp(&s[3], "_time") == EQUAL) {
1122 obj->type = OBJ_top_time;
1125 ERR("Must be top, top_mem or top_time");
1130 ERR("top needs arguments");
1134 if (sscanf(arg, "%63s %i", buf, &n) == 2) {
1135 if (strcmp(buf, "name") == EQUAL) {
1136 obj->data.top.type = TOP_NAME;
1137 } else if (strcmp(buf, "cpu") == EQUAL) {
1138 obj->data.top.type = TOP_CPU;
1139 } else if (strcmp(buf, "pid") == EQUAL) {
1140 obj->data.top.type = TOP_PID;
1141 } else if (strcmp(buf, "mem") == EQUAL) {
1142 obj->data.top.type = TOP_MEM;
1143 } else if (strcmp(buf, "time") == EQUAL) {
1144 obj->data.top.type = TOP_TIME;
1145 } else if (strcmp(buf, "mem_res") == EQUAL) {
1146 obj->data.top.type = TOP_MEM_RES;
1147 } else if (strcmp(buf, "mem_vsize") == EQUAL) {
1148 obj->data.top.type = TOP_MEM_VSIZE;
1150 ERR("invalid type arg for top");
1151 ERR("must be one of: name, cpu, pid, mem, time, mem_res, mem_vsize");
1154 if (n < 1 || n > 10) {
1155 ERR("invalid num arg for top. Must be between 1 and 10.");
1158 obj->data.top.num = n - 1;
1161 ERR("invalid argument count for top");
1167 /* construct_text_object() creates a new text_object */
1168 static struct text_object *construct_text_object(const char *s,
1169 const char *arg, long line, char allow_threaded, void **ifblock_opaque)
1171 // struct text_object *obj = new_text_object();
1172 struct text_object *obj = new_text_object_internal();
1176 #define OBJ(a, n) if (strcmp(s, #a) == 0) { \
1177 obj->type = OBJ_##a; need_mask |= (1ULL << n); {
1178 #define OBJ_IF(a, n) if (strcmp(s, #a) == 0) { \
1179 obj->type = OBJ_##a; need_mask |= (1ULL << n); \
1180 obj_be_ifblock_if(ifblock_opaque, obj); {
1181 #define OBJ_THREAD(a, n) if (strcmp(s, #a) == 0 && allow_threaded) { \
1182 obj->type = OBJ_##a; need_mask |= (1ULL << n); {
1183 #define END } } else
1185 #define SIZE_DEFAULTS(arg) { \
1186 obj->a = default_##arg##_width; \
1187 obj->b = default_##arg##_height; \
1192 obj->type = OBJ_color;
1193 obj->data.l = get_x11_color(s);
1197 OBJ(freq, INFO_FREQ)
1200 obj->data.i = open_acpi_temperature(arg);
1201 END OBJ(acpiacadapter, 0)
1202 END OBJ(freq, INFO_FREQ)
1203 #endif /* !__OpenBSD__ */
1205 if (!arg || !isdigit(arg[0]) || strlen(arg) >= 2 || atoi(&arg[0]) == 0
1206 || (unsigned int) atoi(&arg[0]) > info.cpu_count) {
1207 obj->data.cpu_index = 1;
1208 /* ERR("freq: Invalid CPU number or you don't have that many CPUs! "
1209 "Displaying the clock for CPU 1."); */
1211 obj->data.cpu_index = atoi(&arg[0]);
1214 END OBJ(freq_g, INFO_FREQ)
1216 if (!arg || !isdigit(arg[0]) || strlen(arg) >= 2 || atoi(&arg[0]) == 0
1217 || (unsigned int) atoi(&arg[0]) > info.cpu_count) {
1218 obj->data.cpu_index = 1;
1219 /* ERR("freq_g: Invalid CPU number or you don't have that many "
1220 "CPUs! Displaying the clock for CPU 1."); */
1222 obj->data.cpu_index = atoi(&arg[0]);
1225 #if defined(__linux__)
1226 END OBJ(voltage_mv, 0)
1228 if (!arg || !isdigit(arg[0]) || strlen(arg) >= 2 || atoi(&arg[0]) == 0
1229 || (unsigned int) atoi(&arg[0]) > info.cpu_count) {
1230 obj->data.cpu_index = 1;
1231 /* ERR("voltage_mv: Invalid CPU number or you don't have that many "
1232 "CPUs! Displaying voltage for CPU 1."); */
1234 obj->data.cpu_index = atoi(&arg[0]);
1237 END OBJ(voltage_v, 0)
1239 if (!arg || !isdigit(arg[0]) || strlen(arg) >= 2 || atoi(&arg[0]) == 0
1240 || (unsigned int) atoi(&arg[0]) > info.cpu_count) {
1241 obj->data.cpu_index = 1;
1242 /* ERR("voltage_v: Invalid CPU number or you don't have that many "
1243 "CPUs! Displaying voltage for CPU 1."); */
1245 obj->data.cpu_index = atoi(&arg[0]);
1250 END OBJ(wireless_essid, INFO_NET)
1252 obj->data.net = get_net_stat(arg);
1254 CRIT_ERR("wireless_essid: needs an argument");
1256 END OBJ(wireless_mode, INFO_NET)
1258 obj->data.net = get_net_stat(arg);
1260 CRIT_ERR("wireless_mode: needs an argument");
1262 END OBJ(wireless_bitrate, INFO_NET)
1264 obj->data.net = get_net_stat(arg);
1266 CRIT_ERR("wireless_bitrate: needs an argument");
1268 END OBJ(wireless_ap, INFO_NET)
1270 obj->data.net = get_net_stat(arg);
1272 CRIT_ERR("wireless_ap: needs an argument");
1274 END OBJ(wireless_link_qual, INFO_NET)
1276 obj->data.net = get_net_stat(arg);
1278 CRIT_ERR("wireless_link_qual: needs an argument");
1280 END OBJ(wireless_link_qual_max, INFO_NET)
1282 obj->data.net = get_net_stat(arg);
1284 CRIT_ERR("wireless_link_qual_max: needs an argument");
1286 END OBJ(wireless_link_qual_perc, INFO_NET)
1288 obj->data.net = get_net_stat(arg);
1290 CRIT_ERR("wireless_link_qual_perc: needs an argument");
1292 END OBJ(wireless_link_bar, INFO_NET)
1295 arg = scan_bar(arg, &obj->a, &obj->b);
1296 obj->data.net = get_net_stat(arg);
1298 CRIT_ERR("wireless_link_bar: needs an argument");
1300 #endif /* HAVE_IWLIB */
1302 #endif /* __linux__ */
1310 sscanf(arg, "%63s", bat);
1312 strcpy(bat, "BAT0");
1314 obj->data.s = strndup(bat, text_buffer_size);
1315 END OBJ(battery_short, 0)
1319 sscanf(arg, "%63s", bat);
1321 strcpy(bat, "BAT0");
1323 obj->data.s = strndup(bat, text_buffer_size);
1324 END OBJ(battery_time, 0)
1328 sscanf(arg, "%63s", bat);
1330 strcpy(bat, "BAT0");
1332 obj->data.s = strndup(bat, text_buffer_size);
1333 END OBJ(battery_percent, 0)
1337 sscanf(arg, "%63s", bat);
1339 strcpy(bat, "BAT0");
1341 obj->data.s = strndup(bat, text_buffer_size);
1342 END OBJ(battery_bar, 0)
1347 arg = scan_bar(arg, &obj->a, &obj->b);
1348 sscanf(arg, "%63s", bat);
1350 strcpy(bat, "BAT0");
1352 obj->data.s = strndup(bat, text_buffer_size);
1353 #endif /* !__OpenBSD__ */
1355 #if defined(__linux__)
1356 END OBJ(disk_protect, 0)
1358 obj->data.s = strndup(dev_name(arg), text_buffer_size);
1360 CRIT_ERR("disk_protect needs an argument");
1361 END OBJ(i8k_version, INFO_I8K)
1362 END OBJ(i8k_bios, INFO_I8K)
1363 END OBJ(i8k_serial, INFO_I8K)
1364 END OBJ(i8k_cpu_temp, INFO_I8K)
1365 END OBJ(i8k_left_fan_status, INFO_I8K)
1366 END OBJ(i8k_right_fan_status, INFO_I8K)
1367 END OBJ(i8k_left_fan_rpm, INFO_I8K)
1368 END OBJ(i8k_right_fan_rpm, INFO_I8K)
1369 END OBJ(i8k_ac_status, INFO_I8K)
1370 END OBJ(i8k_buttons_status, INFO_I8K)
1373 END OBJ(ibm_temps, 0)
1375 CRIT_ERR("ibm_temps: needs an argument");
1377 if (!isdigit(arg[0]) || strlen(arg) >= 2 || atoi(&arg[0]) >= 8) {
1378 obj->data.sensor = 0;
1379 ERR("Invalid temperature sensor! Sensor number must be 0 to 7. "
1380 "Using 0 (CPU temp sensor).");
1382 obj->data.sensor = atoi(&arg[0]);
1383 END OBJ(ibm_volume, 0)
1384 END OBJ(ibm_brightness, 0)
1386 /* information from sony_laptop kernel module
1387 * /sys/devices/platform/sony-laptop */
1388 END OBJ(sony_fanspeed, 0)
1389 END OBJ_IF(if_gw, INFO_GW)
1390 END OBJ(ioscheduler, 0)
1392 CRIT_ERR("get_ioscheduler needs an argument (e.g. hda)");
1395 obj->data.s = strndup(dev_name(arg), text_buffer_size);
1396 END OBJ(laptop_mode, 0)
1397 END OBJ(pb_battery, 0)
1398 if (arg && strcmp(arg, "status") == EQUAL) {
1399 obj->data.i = PB_BATT_STATUS;
1400 } else if (arg && strcmp(arg, "percent") == EQUAL) {
1401 obj->data.i = PB_BATT_PERCENT;
1402 } else if (arg && strcmp(arg, "time") == EQUAL) {
1403 obj->data.i = PB_BATT_TIME;
1405 ERR("pb_battery: needs one argument: status, percent or time");
1410 #endif /* __linux__ */
1411 #if (defined(__FreeBSD__) || defined(__linux__))
1412 END OBJ_IF(if_up, 0)
1414 ERR("if_up needs an argument");
1415 obj->data.ifblock.s = 0;
1417 obj->data.ifblock.s = strndup(arg, text_buffer_size);
1420 #if defined(__OpenBSD__)
1421 END OBJ(obsd_sensors_temp, 0)
1423 CRIT_ERR("obsd_sensors_temp: needs an argument");
1425 if (!isdigit(arg[0]) || atoi(&arg[0]) < 0
1426 || atoi(&arg[0]) > OBSD_MAX_SENSORS - 1) {
1427 obj->data.sensor = 0;
1428 ERR("Invalid temperature sensor number!");
1430 obj->data.sensor = atoi(&arg[0]);
1431 END OBJ(obsd_sensors_fan, 0)
1433 CRIT_ERR("obsd_sensors_fan: needs 2 arguments (device and sensor "
1436 if (!isdigit(arg[0]) || atoi(&arg[0]) < 0
1437 || atoi(&arg[0]) > OBSD_MAX_SENSORS - 1) {
1438 obj->data.sensor = 0;
1439 ERR("Invalid fan sensor number!");
1441 obj->data.sensor = atoi(&arg[0]);
1442 END OBJ(obsd_sensors_volt, 0)
1444 CRIT_ERR("obsd_sensors_volt: needs 2 arguments (device and sensor "
1447 if (!isdigit(arg[0]) || atoi(&arg[0]) < 0
1448 || atoi(&arg[0]) > OBSD_MAX_SENSORS - 1) {
1449 obj->data.sensor = 0;
1450 ERR("Invalid voltage sensor number!");
1452 obj->data.sensor = atoi(&arg[0]);
1453 END OBJ(obsd_vendor, 0)
1454 END OBJ(obsd_product, 0)
1455 #endif /* __OpenBSD__ */
1456 END OBJ(buffers, INFO_BUFFERS)
1457 END OBJ(cached, INFO_BUFFERS)
1458 #define SCAN_CPU(__arg, __var) { \
1460 if (__arg && sscanf(__arg, " cpu%u %n", &__var, &__offset) > 0) \
1461 __arg += __offset; \
1465 END OBJ(cpu, INFO_CPU)
1466 SCAN_CPU(arg, obj->data.cpu_index);
1467 DBGP2("Adding $cpu for CPU %d", obj->data.cpu_index);
1469 END OBJ(cpugauge, INFO_CPU)
1470 SIZE_DEFAULTS(gauge);
1471 SCAN_CPU(arg, obj->data.cpu_index);
1472 scan_gauge(arg, &obj->a, &obj->b);
1473 DBGP2("Adding $cpugauge for CPU %d", obj->data.cpu_index);
1475 END OBJ(cpubar, INFO_CPU)
1477 SCAN_CPU(arg, obj->data.cpu_index);
1478 scan_bar(arg, &obj->a, &obj->b);
1479 DBGP2("Adding $cpubar for CPU %d", obj->data.cpu_index);
1481 END OBJ(cpugraph, INFO_CPU)
1482 SIZE_DEFAULTS(graph);
1483 SCAN_CPU(arg, obj->data.cpu_index);
1484 scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
1485 &obj->e, &obj->char_a, &obj->char_b);
1486 DBGP2("Adding $cpugraph for CPU %d", obj->data.cpu_index);
1487 END OBJ(loadgraph, INFO_LOADAVG)
1489 SIZE_DEFAULTS(graph);
1490 buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
1491 &obj->e, &obj->char_a, &obj->char_b);
1495 r = sscanf(arg, "%d", &a);
1497 obj->data.loadavg[0] = (r >= 1) ? (unsigned char) a : 0;
1501 END OBJ(diskio, INFO_DISKIO)
1502 obj->data.diskio = prepare_diskio_stat(dev_name(arg));
1503 END OBJ(diskio_read, INFO_DISKIO)
1504 obj->data.diskio = prepare_diskio_stat(dev_name(arg));
1505 END OBJ(diskio_write, INFO_DISKIO)
1506 obj->data.diskio = prepare_diskio_stat(dev_name(arg));
1508 END OBJ(diskiograph, INFO_DISKIO)
1510 SIZE_DEFAULTS(graph);
1511 buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
1512 &obj->e, &obj->char_a, &obj->char_b);
1514 obj->data.diskio = prepare_diskio_stat(dev_name(buf));
1517 END OBJ(diskiograph_read, INFO_DISKIO)
1519 SIZE_DEFAULTS(graph);
1520 buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
1521 &obj->e, &obj->char_a, &obj->char_b);
1523 obj->data.diskio = prepare_diskio_stat(dev_name(buf));
1526 END OBJ(diskiograph_write, INFO_DISKIO)
1528 SIZE_DEFAULTS(graph);
1529 buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
1530 &obj->e, &obj->char_a, &obj->char_b);
1532 obj->data.diskio = prepare_diskio_stat(dev_name(buf));
1538 if (output_methods & TO_X) {
1539 obj->data.l = arg ? get_x11_color(arg) : default_fg_color;
1543 obj->data.l = color0;
1545 obj->data.l = color1;
1547 obj->data.l = color2;
1549 obj->data.l = color3;
1551 obj->data.l = color4;
1553 obj->data.l = color5;
1555 obj->data.l = color6;
1557 obj->data.l = color7;
1559 obj->data.l = color8;
1561 obj->data.l = color9;
1564 obj->data.s = scan_font(arg);
1566 END OBJ(conky_version, 0)
1567 END OBJ(conky_build_date, 0)
1568 END OBJ(conky_build_arch, 0)
1569 END OBJ(downspeed, INFO_NET)
1571 obj->data.net = get_net_stat(arg);
1573 CRIT_ERR("downspeed needs argument");
1575 END OBJ(downspeedf, INFO_NET)
1577 obj->data.net = get_net_stat(arg);
1579 CRIT_ERR("downspeedf needs argument");
1582 END OBJ(downspeedgraph, INFO_NET)
1584 SIZE_DEFAULTS(graph);
1585 buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
1586 &obj->e, &obj->char_a, &obj->char_b);
1588 // default to DEFAULTNETDEV
1589 buf = strndup(buf ? buf : "DEFAULTNETDEV", text_buffer_size);
1590 obj->data.net = get_net_stat(buf);
1594 obj_be_ifblock_else(ifblock_opaque, obj);
1596 obj_be_ifblock_endif(ifblock_opaque, obj);
1598 obj->data.s = strndup(arg ? arg : "", text_buffer_size);
1600 obj->data.s = strndup(arg ? arg : "", text_buffer_size);
1603 obj->data.s = strndup(arg ? arg : "", text_buffer_size);
1605 obj->data.s = strndup(arg ? arg : "", text_buffer_size);
1608 obj->data.s = strndup(arg ? arg : "", text_buffer_size);
1610 END OBJ(execgauge, 0)
1611 SIZE_DEFAULTS(gauge);
1612 obj->data.s = strndup(arg ? arg : "", text_buffer_size);
1613 END OBJ(execgraph, 0)
1614 SIZE_DEFAULTS(graph);
1615 obj->data.s = strndup(arg ? arg : "", text_buffer_size);
1617 END OBJ(execibar, 0)
1621 if (!arg || sscanf(arg, "%f %n", &obj->data.execi.interval, &n) <= 0) {
1624 ERR("${execibar <interval> command}");
1625 obj->type = OBJ_text;
1626 snprintf(buf, 256, "${%s}", s);
1627 obj->data.s = strndup(buf, text_buffer_size);
1629 obj->data.execi.cmd = strndup(arg + n, text_buffer_size);
1632 END OBJ(execigraph, 0)
1634 SIZE_DEFAULTS(graph);
1636 if (!arg || sscanf(arg, "%f %n", &obj->data.execi.interval, &n) <= 0) {
1639 ERR("${execigraph <interval> command}");
1640 obj->type = OBJ_text;
1641 snprintf(buf, 256, "${%s}", s);
1642 obj->data.s = strndup(buf, text_buffer_size);
1644 obj->data.execi.cmd = strndup(arg + n, text_buffer_size);
1646 END OBJ(execigauge, 0)
1648 SIZE_DEFAULTS(gauge);
1650 if (!arg || sscanf(arg, "%f %n", &obj->data.execi.interval, &n) <= 0) {
1653 ERR("${execigauge <interval> command}");
1654 obj->type = OBJ_text;
1655 snprintf(buf, 256, "${%s}", s);
1656 obj->data.s = strndup(buf, text_buffer_size);
1658 obj->data.execi.cmd = strndup(arg + n, text_buffer_size);
1664 if (!arg || sscanf(arg, "%f %n", &obj->data.execi.interval, &n) <= 0) {
1667 ERR("${execi <interval> command}");
1668 obj->type = OBJ_text;
1669 snprintf(buf, 256, "${%s}", s);
1670 obj->data.s = strndup(buf, text_buffer_size);
1672 obj->data.execi.cmd = strndup(arg + n, text_buffer_size);
1673 obj->data.execi.buffer = malloc(text_buffer_size);
1678 if (!arg || sscanf(arg, "%f %n", &obj->data.execi.interval, &n) <= 0) {
1681 ERR("${execi <interval> command}");
1682 obj->type = OBJ_text;
1683 snprintf(buf, 256, "${%s}", s);
1684 obj->data.s = strndup(buf, text_buffer_size);
1686 obj->data.execi.cmd = strndup(arg + n, text_buffer_size);
1687 obj->data.execi.buffer = malloc(text_buffer_size);
1689 END OBJ_THREAD(texeci, 0)
1692 if (!arg || sscanf(arg, "%f %n", &obj->data.texeci.interval, &n) <= 0) {
1695 ERR("${texeci <interval> command}");
1696 obj->type = OBJ_text;
1697 snprintf(buf, 256, "${%s}", s);
1698 obj->data.s = strndup(buf, text_buffer_size);
1700 obj->data.texeci.cmd = strndup(arg + n, text_buffer_size);
1701 obj->data.texeci.buffer = malloc(text_buffer_size);
1703 obj->data.texeci.p_timed_thread = NULL;
1704 END OBJ(pre_exec, 0)
1705 obj->type = OBJ_text;
1709 read_exec(arg, buf, sizeof(buf));
1710 obj->data.s = strndup(buf, text_buffer_size);
1712 obj->data.s = strndup("", text_buffer_size);
1715 END OBJ(fs_bar, INFO_FS)
1717 arg = scan_bar(arg, &obj->data.fsbar.w, &obj->data.fsbar.h);
1719 while (isspace(*arg)) {
1728 obj->data.fsbar.fs = prepare_fs_stat(arg);
1729 END OBJ(fs_bar_free, INFO_FS)
1731 arg = scan_bar(arg, &obj->data.fsbar.w, &obj->data.fsbar.h);
1733 while (isspace(*arg)) {
1743 obj->data.fsbar.fs = prepare_fs_stat(arg);
1744 END OBJ(fs_free, INFO_FS)
1748 obj->data.fs = prepare_fs_stat(arg);
1749 END OBJ(fs_used_perc, INFO_FS)
1753 obj->data.fs = prepare_fs_stat(arg);
1754 END OBJ(fs_free_perc, INFO_FS)
1758 obj->data.fs = prepare_fs_stat(arg);
1759 END OBJ(fs_size, INFO_FS)
1763 obj->data.fs = prepare_fs_stat(arg);
1764 END OBJ(fs_type, INFO_FS)
1768 obj->data.fs = prepare_fs_stat(arg);
1769 END OBJ(fs_used, INFO_FS)
1773 obj->data.fs = prepare_fs_stat(arg);
1775 obj->data.i = arg ? atoi(arg) : 1;
1776 END OBJ(nameserver, INFO_DNS)
1777 obj->data.i = arg ? atoi(arg) : 0;
1779 obj->data.i = arg ? atoi(arg) : 1;
1781 obj->data.i = arg ? atoi(arg) : 1;
1785 ERR("goto needs arguments");
1786 obj->type = OBJ_text;
1787 obj->data.s = strndup("${goto}", text_buffer_size);
1791 obj->data.i = atoi(arg);
1797 if (sscanf(arg, "%d %d", &a, &b) != 2) {
1798 sscanf(arg, "%d", &b);
1804 obj->data.pair.a = a;
1805 obj->data.pair.b = b;
1808 END OBJ(i2c, INFO_SYSFS)
1809 char buf1[64], buf2[64];
1810 float factor, offset;
1814 ERR("i2c needs arguments");
1815 obj->type = OBJ_text;
1816 // obj->data.s = strndup("${i2c}", text_buffer_size);
1820 #define HWMON_RESET() {\
1825 if (sscanf(arg, "%63s %d %f %f", buf2, &n, &factor, &offset) == 4) found = 1; else HWMON_RESET();
1826 if (!found && sscanf(arg, "%63s %63s %d %f %f", buf1, buf2, &n, &factor, &offset) == 5) found = 1; else if (!found) HWMON_RESET();
1827 if (!found && sscanf(arg, "%63s %63s %d", buf1, buf2, &n) == 3) found = 1; else if (!found) HWMON_RESET();
1828 if (!found && sscanf(arg, "%63s %d", buf2, &n) == 2) found = 1; else if (!found) HWMON_RESET();
1831 ERR("i2c failed to parse arguments");
1832 obj->type = OBJ_text;
1835 DBGP("parsed i2c args: '%s' '%s' %d %f %f\n", buf1, buf2, n, factor, offset);
1836 obj->data.sysfs.fd = open_i2c_sensor((*buf1) ? buf1 : 0, buf2, n,
1837 &obj->data.sysfs.arg, obj->data.sysfs.devtype);
1838 strncpy(obj->data.sysfs.type, buf2, 63);
1839 obj->data.sysfs.factor = factor;
1840 obj->data.sysfs.offset = offset;
1842 END OBJ(platform, INFO_SYSFS)
1843 char buf1[64], buf2[64];
1844 float factor, offset;
1848 ERR("platform needs arguments");
1849 obj->type = OBJ_text;
1853 if (sscanf(arg, "%63s %d %f %f", buf2, &n, &factor, &offset) == 4) found = 1; else HWMON_RESET();
1854 if (!found && sscanf(arg, "%63s %63s %d %f %f", buf1, buf2, &n, &factor, &offset) == 5) found = 1; else if (!found) HWMON_RESET();
1855 if (!found && sscanf(arg, "%63s %63s %d", buf1, buf2, &n) == 3) found = 1; else if (!found) HWMON_RESET();
1856 if (!found && sscanf(arg, "%63s %d", buf2, &n) == 2) found = 1; else if (!found) HWMON_RESET();
1859 ERR("platform failed to parse arguments");
1860 obj->type = OBJ_text;
1863 DBGP("parsed platform args: '%s' '%s' %d %f %f\n", buf1, buf2, n, factor, offset);
1864 obj->data.sysfs.fd = open_platform_sensor((*buf1) ? buf1 : 0, buf2, n,
1865 &obj->data.sysfs.arg, obj->data.sysfs.devtype);
1866 strncpy(obj->data.sysfs.type, buf2, 63);
1867 obj->data.sysfs.factor = factor;
1868 obj->data.sysfs.offset = offset;
1870 END OBJ(hwmon, INFO_SYSFS)
1871 char buf1[64], buf2[64];
1872 float factor, offset;
1876 ERR("hwmon needs argumanets");
1877 obj->type = OBJ_text;
1881 if (sscanf(arg, "%63s %d %f %f", buf2, &n, &factor, &offset) == 4) found = 1; else HWMON_RESET();
1882 if (!found && sscanf(arg, "%63s %63s %d %f %f", buf1, buf2, &n, &factor, &offset) == 5) found = 1; else if (!found) HWMON_RESET();
1883 if (!found && sscanf(arg, "%63s %63s %d", buf1, buf2, &n) == 3) found = 1; else if (!found) HWMON_RESET();
1884 if (!found && sscanf(arg, "%63s %d", buf2, &n) == 2) found = 1; else if (!found) HWMON_RESET();
1889 ERR("hwmon failed to parse arguments");
1890 obj->type = OBJ_text;
1893 DBGP("parsed hwmon args: '%s' '%s' %d %f %f\n", buf1, buf2, n, factor, offset);
1894 obj->data.sysfs.fd = open_hwmon_sensor((*buf1) ? buf1 : 0, buf2, n,
1895 &obj->data.sysfs.arg, obj->data.sysfs.devtype);
1896 strncpy(obj->data.sysfs.type, buf2, 63);
1897 obj->data.sysfs.factor = factor;
1898 obj->data.sysfs.offset = offset;
1900 #endif /* !__OpenBSD__ */
1903 /* we have three different types of top (top, top_mem and top_time). To
1904 * avoid having almost-same code three times, we have this special
1906 if (strncmp(s, "top", 3) == EQUAL) {
1907 if (!parse_top_args(s, arg, obj)) {
1910 } else OBJ(addr, INFO_NET)
1912 obj->data.net = get_net_stat(arg);
1914 CRIT_ERR("addr needs argument");
1916 #if defined(__linux__)
1917 END OBJ(addrs, INFO_NET)
1919 obj->data.net = get_net_stat(arg);
1921 CRIT_ERR("addrs needs argument");
1923 #endif /* __linux__ */
1925 if (init_tail_object(obj, arg)) {
1926 obj->type = OBJ_text;
1927 obj->data.s = strndup("${tail}", text_buffer_size);
1930 if (init_head_object(obj, arg)) {
1931 obj->type = OBJ_text;
1932 obj->data.s = strndup("${head}", text_buffer_size);
1936 obj->data.s = strndup(arg, text_buffer_size);
1938 CRIT_ERR("lines needs a argument");
1942 obj->data.s = strndup(arg, text_buffer_size);
1944 CRIT_ERR("words needs a argument");
1946 END OBJ(loadavg, INFO_LOADAVG)
1947 int a = 1, b = 2, c = 3, r = 3;
1950 r = sscanf(arg, "%d %d %d", &a, &b, &c);
1951 if (r >= 3 && (c < 1 || c > 3)) {
1954 if (r >= 2 && (b < 1 || b > 3)) {
1957 if (r >= 1 && (a < 1 || a > 3)) {
1961 obj->data.loadavg[0] = (r >= 1) ? (unsigned char) a : 0;
1962 obj->data.loadavg[1] = (r >= 2) ? (unsigned char) b : 0;
1963 obj->data.loadavg[2] = (r >= 3) ? (unsigned char) c : 0;
1964 END OBJ_IF(if_empty, 0)
1966 ERR("if_empty needs an argument");
1967 obj->data.ifblock.s = 0;
1969 obj->data.ifblock.s = strndup(arg, text_buffer_size);
1970 obj->sub = malloc(sizeof(struct text_object));
1971 extract_variable_text_internal(obj->sub,
1972 obj->data.ifblock.s, 0);
1974 END OBJ_IF(if_match, 0)
1976 ERR("if_match needs arguments");
1977 obj->data.ifblock.s = 0;
1979 obj->data.ifblock.s = strndup(arg, text_buffer_size);
1980 obj->sub = malloc(sizeof(struct text_object));
1981 extract_variable_text_internal(obj->sub,
1982 obj->data.ifblock.s, 0);
1984 END OBJ_IF(if_existing, 0)
1986 ERR("if_existing needs an argument or two");
1987 obj->data.ifblock.s = NULL;
1988 obj->data.ifblock.str = NULL;
1990 char buf1[256], buf2[256];
1991 int r = sscanf(arg, "%255s %255[^\n]", buf1, buf2);
1994 obj->data.ifblock.s = strndup(buf1, text_buffer_size);
1995 obj->data.ifblock.str = NULL;
1997 obj->data.ifblock.s = strndup(buf1, text_buffer_size);
1998 obj->data.ifblock.str = strndup(buf2, text_buffer_size);
2001 DBGP("if_existing: '%s' '%s'", obj->data.ifblock.s, obj->data.ifblock.str);
2002 END OBJ_IF(if_mounted, 0)
2004 ERR("if_mounted needs an argument");
2005 obj->data.ifblock.s = 0;
2007 obj->data.ifblock.s = strndup(arg, text_buffer_size);
2009 END OBJ_IF(if_running, 0)
2013 snprintf(buf, 256, "pidof %s >/dev/null", arg);
2014 obj->data.ifblock.s = strndup(buf, text_buffer_size);
2016 ERR("if_running needs an argument");
2017 obj->data.ifblock.s = 0;
2023 char box[256], dst[256];
2027 /* Kapil: Changed from MAIL_FILE to
2028 current_mail_spool since the latter
2029 is a copy of the former if undefined
2030 but the latter should take precedence
2032 strncpy(box, current_mail_spool, sizeof(box));
2034 if (sscanf(arg, "%s %f", box, &n1) != 2) {
2036 strncpy(box, arg, sizeof(box));
2040 variable_substitute(box, dst, sizeof(dst));
2041 obj->data.local_mail.box = strndup(dst, text_buffer_size);
2042 obj->data.local_mail.interval = n1;
2043 END OBJ(new_mails, 0)
2045 char box[256], dst[256];
2049 strncpy(box, current_mail_spool, sizeof(box));
2051 if (sscanf(arg, "%s %f", box, &n1) != 2) {
2053 strncpy(box, arg, sizeof(box));
2057 variable_substitute(box, dst, sizeof(dst));
2058 obj->data.local_mail.box = strndup(dst, text_buffer_size);
2059 obj->data.local_mail.interval = n1;
2060 END OBJ(seen_mails, 0)
2062 char box[256], dst[256];
2066 strncpy(box, current_mail_spool, sizeof(box));
2068 if (sscanf(arg, "%s %f", box, &n1) != 2) {
2070 strncpy(box, arg, sizeof(box));
2074 variable_substitute(box, dst, sizeof(dst));
2075 obj->data.local_mail.box = strndup(dst, text_buffer_size);
2076 obj->data.local_mail.interval = n1;
2077 END OBJ(unseen_mails, 0)
2079 char box[256], dst[256];
2083 strncpy(box, current_mail_spool, sizeof(box));
2085 if (sscanf(arg, "%s %f", box, &n1) != 2) {
2087 strncpy(box, arg, sizeof(box));
2091 variable_substitute(box, dst, sizeof(dst));
2092 obj->data.local_mail.box = strndup(dst, text_buffer_size);
2093 obj->data.local_mail.interval = n1;
2094 END OBJ(flagged_mails, 0)
2096 char box[256], dst[256];
2100 strncpy(box, current_mail_spool, sizeof(box));
2102 if (sscanf(arg, "%s %f", box, &n1) != 2) {
2104 strncpy(box, arg, sizeof(box));
2108 variable_substitute(box, dst, sizeof(dst));
2109 obj->data.local_mail.box = strndup(dst, text_buffer_size);
2110 obj->data.local_mail.interval = n1;
2111 END OBJ(unflagged_mails, 0)
2113 char box[256], dst[256];
2117 strncpy(box, current_mail_spool, sizeof(box));
2119 if (sscanf(arg, "%s %f", box, &n1) != 2) {
2121 strncpy(box, arg, sizeof(box));
2125 variable_substitute(box, dst, sizeof(dst));
2126 obj->data.local_mail.box = strndup(dst, text_buffer_size);
2127 obj->data.local_mail.interval = n1;
2128 END OBJ(forwarded_mails, 0)
2130 char box[256], dst[256];
2134 strncpy(box, current_mail_spool, sizeof(box));
2136 if (sscanf(arg, "%s %f", box, &n1) != 2) {
2138 strncpy(box, arg, sizeof(box));
2142 variable_substitute(box, dst, sizeof(dst));
2143 obj->data.local_mail.box = strndup(dst, text_buffer_size);
2144 obj->data.local_mail.interval = n1;
2145 END OBJ(unforwarded_mails, 0)
2147 char box[256], dst[256];
2151 strncpy(box, current_mail_spool, sizeof(box));
2153 if (sscanf(arg, "%s %f", box, &n1) != 2) {
2155 strncpy(box, arg, sizeof(box));
2159 variable_substitute(box, dst, sizeof(dst));
2160 obj->data.local_mail.box = strndup(dst, text_buffer_size);
2161 obj->data.local_mail.interval = n1;
2162 END OBJ(replied_mails, 0)
2164 char box[256], dst[256];
2168 strncpy(box, current_mail_spool, sizeof(box));
2170 if (sscanf(arg, "%s %f", box, &n1) != 2) {
2172 strncpy(box, arg, sizeof(box));
2176 variable_substitute(box, dst, sizeof(dst));
2177 obj->data.local_mail.box = strndup(dst, text_buffer_size);
2178 obj->data.local_mail.interval = n1;
2179 END OBJ(unreplied_mails, 0)
2181 char box[256], dst[256];
2185 strncpy(box, current_mail_spool, sizeof(box));
2187 if (sscanf(arg, "%s %f", box, &n1) != 2) {
2189 strncpy(box, arg, sizeof(box));
2193 variable_substitute(box, dst, sizeof(dst));
2194 obj->data.local_mail.box = strndup(dst, text_buffer_size);
2195 obj->data.local_mail.interval = n1;
2196 END OBJ(draft_mails, 0)
2198 char box[256], dst[256];
2202 strncpy(box, current_mail_spool, sizeof(box));
2204 if (sscanf(arg, "%s %f", box, &n1) != 2) {
2206 strncpy(box, arg, sizeof(box));
2210 variable_substitute(box, dst, sizeof(dst));
2211 obj->data.local_mail.box = strndup(dst, text_buffer_size);
2212 obj->data.local_mail.interval = n1;
2213 END OBJ(trashed_mails, 0)
2215 char box[256], dst[256];
2219 strncpy(box, current_mail_spool, sizeof(box));
2221 if (sscanf(arg, "%s %f", box, &n1) != 2) {
2223 strncpy(box, arg, sizeof(box));
2227 variable_substitute(box, dst, sizeof(dst));
2228 obj->data.local_mail.box = strndup(dst, text_buffer_size);
2229 obj->data.local_mail.interval = n1;
2230 END OBJ(mboxscan, 0)
2231 obj->data.mboxscan.args = (char *) malloc(text_buffer_size);
2232 obj->data.mboxscan.output = (char *) malloc(text_buffer_size);
2233 /* if '1' (in mboxscan.c) then there was SIGUSR1, hmm */
2234 obj->data.mboxscan.output[0] = 1;
2235 strncpy(obj->data.mboxscan.args, arg, text_buffer_size);
2236 END OBJ(mem, INFO_MEM)
2237 END OBJ(memeasyfree, INFO_MEM)
2238 END OBJ(memfree, INFO_MEM)
2239 END OBJ(memmax, INFO_MEM)
2240 END OBJ(memperc, INFO_MEM)
2242 END OBJ(memgauge, INFO_MEM)
2243 SIZE_DEFAULTS(gauge);
2244 scan_gauge(arg, &obj->data.pair.a, &obj->data.pair.b);
2246 END OBJ(membar, INFO_MEM)
2248 scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
2250 END OBJ(memgraph, INFO_MEM)
2252 SIZE_DEFAULTS(graph);
2253 buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
2254 &obj->e, &obj->char_a, &obj->char_b);
2260 END OBJ(mixer, INFO_MIXER)
2261 obj->data.l = mixer_init(arg);
2262 END OBJ(mixerl, INFO_MIXER)
2263 obj->data.l = mixer_init(arg);
2264 END OBJ(mixerr, INFO_MIXER)
2265 obj->data.l = mixer_init(arg);
2267 END OBJ(mixerbar, INFO_MIXER)
2269 scan_mixer_bar(arg, &obj->data.mixerbar.l, &obj->data.mixerbar.w,
2270 &obj->data.mixerbar.h);
2271 END OBJ(mixerlbar, INFO_MIXER)
2273 scan_mixer_bar(arg, &obj->data.mixerbar.l, &obj->data.mixerbar.w,
2274 &obj->data.mixerbar.h);
2275 END OBJ(mixerrbar, INFO_MIXER)
2277 scan_mixer_bar(arg, &obj->data.mixerbar.l, &obj->data.mixerbar.w,
2278 &obj->data.mixerbar.h);
2280 END OBJ_IF(if_mixer_mute, INFO_MIXER)
2281 obj->data.ifblock.i = mixer_init(arg);
2283 END OBJ(monitor, INFO_X11)
2284 END OBJ(monitor_number, INFO_X11)
2286 END OBJ(nodename, 0)
2287 END OBJ(processes, INFO_PROCS)
2288 END OBJ(running_processes, INFO_RUN_PROCS)
2289 END OBJ(shadecolor, 0)
2291 obj->data.l = arg ? get_x11_color(arg) : default_bg_color;
2293 END OBJ(outlinecolor, 0)
2295 obj->data.l = arg ? get_x11_color(arg) : default_out_color;
2297 END OBJ(stippled_hr, 0)
2299 int a = stippled_borders, b = 1;
2302 if (sscanf(arg, "%d %d", &a, &b) != 2) {
2303 sscanf(arg, "%d", &b);
2309 obj->data.pair.a = a;
2310 obj->data.pair.b = b;
2312 END OBJ(swap, INFO_MEM)
2313 END OBJ(swapmax, INFO_MEM)
2314 END OBJ(swapperc, INFO_MEM)
2315 END OBJ(swapbar, INFO_MEM)
2317 scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
2320 obj->data.s = strndup(arg ? arg : "%F %T", text_buffer_size);
2322 obj->data.s = strndup(arg ? arg : "%F %T", text_buffer_size);
2324 char buf1[256], buf2[256], *fmt, *tz;
2328 int nArgs = sscanf(arg, "%255s %255[^\n]", buf1, buf2);
2338 obj->data.tztime.fmt = strndup(fmt ? fmt : "%F %T", text_buffer_size);
2339 obj->data.tztime.tz = tz ? strndup(tz, text_buffer_size) : NULL;
2341 END OBJ(iconv_start, 0)
2342 if (iconv_converting) {
2343 CRIT_ERR("You must stop your last iconv conversion before "
2344 "starting another");
2347 char iconv_from[CODEPAGE_LENGTH];
2348 char iconv_to[CODEPAGE_LENGTH];
2350 if (sscanf(arg, "%s %s", iconv_from, iconv_to) != 2) {
2351 CRIT_ERR("Invalid arguments for iconv_start");
2355 new_iconv = iconv_open(iconv_to, iconv_from);
2356 if (new_iconv == (iconv_t) (-1)) {
2357 ERR("Can't convert from %s to %s.", iconv_from, iconv_to);
2359 obj->a = register_iconv(&new_iconv);
2360 iconv_converting = 1;
2364 CRIT_ERR("Iconv requires arguments");
2366 END OBJ(iconv_stop, 0)
2367 iconv_converting = 0;
2370 END OBJ(totaldown, INFO_NET)
2372 obj->data.net = get_net_stat(arg);
2374 CRIT_ERR("totaldown needs argument");
2376 END OBJ(totalup, INFO_NET)
2377 obj->data.net = get_net_stat(arg);
2379 obj->data.net = get_net_stat(arg);
2381 CRIT_ERR("totalup needs argument");
2384 END OBJ_IF(if_updatenr, 0)
2385 obj->data.ifblock.i = arg ? atoi(arg) : 0;
2386 if(obj->data.ifblock.i == 0) CRIT_ERR("if_updatenr needs a number above 0 as argument");
2387 updatereset = obj->data.ifblock.i > updatereset ? obj->data.ifblock.i : updatereset;
2389 obj->data.i = arg ? atoi(arg) : 0;
2391 obj->data.i = arg ? atoi(arg) : 0;
2392 END OBJ(upspeed, INFO_NET)
2394 obj->data.net = get_net_stat(arg);
2396 CRIT_ERR("upspeed needs argument");
2398 END OBJ(upspeedf, INFO_NET)
2400 obj->data.net = get_net_stat(arg);
2402 CRIT_ERR("upspeedf needs argument");
2406 END OBJ(upspeedgraph, INFO_NET)
2408 SIZE_DEFAULTS(graph);
2409 buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
2410 &obj->e, &obj->char_a, &obj->char_b);
2412 // default to DEFAULTNETDEV
2413 buf = strndup(buf ? buf : "DEFAULTNETDEV", text_buffer_size);
2414 obj->data.net = get_net_stat(buf);
2417 END OBJ(uptime_short, INFO_UPTIME)
2418 END OBJ(uptime, INFO_UPTIME)
2419 END OBJ(user_names, INFO_USERS)
2420 END OBJ(user_times, INFO_USERS)
2421 END OBJ(user_terms, INFO_USERS)
2422 END OBJ(user_number, INFO_USERS)
2423 #if defined(__linux__)
2424 END OBJ(gw_iface, INFO_GW)
2425 END OBJ(gw_ip, INFO_GW)
2426 #endif /* !__linux__ */
2428 END OBJ(adt746xcpu, 0)
2429 END OBJ(adt746xfan, 0)
2430 #endif /* !__OpenBSD__ */
2431 #if (defined(__FreeBSD__) || defined(__FreeBSD_kernel__) \
2432 || defined(__OpenBSD__)) && (defined(i386) || defined(__i386__))
2433 END OBJ(apm_adapter, 0)
2434 END OBJ(apm_battery_life, 0)
2435 END OBJ(apm_battery_time, 0)
2436 #endif /* __FreeBSD__ */
2437 END OBJ_THREAD(imap_unseen, 0)
2440 obj->data.mail = parse_mail_args(IMAP_TYPE, arg);
2445 END OBJ_THREAD(imap_messages, 0)
2448 obj->data.mail = parse_mail_args(IMAP_TYPE, arg);
2453 END OBJ_THREAD(pop3_unseen, 0)
2456 obj->data.mail = parse_mail_args(POP3_TYPE, arg);
2461 END OBJ_THREAD(pop3_used, 0)
2464 obj->data.mail = parse_mail_args(POP3_TYPE, arg);
2472 obj->data.s = strndup(arg, text_buffer_size);
2474 ERR("smapi needs an argument");
2475 END OBJ_IF(if_smapi_bat_installed, 0)
2477 ERR("if_smapi_bat_installed needs an argument");
2478 obj->data.ifblock.s = 0;
2480 obj->data.ifblock.s = strndup(arg, text_buffer_size);
2481 END OBJ(smapi_bat_perc, 0)
2483 obj->data.s = strndup(arg, text_buffer_size);
2485 ERR("smapi_bat_perc needs an argument");
2486 END OBJ(smapi_bat_temp, 0)
2488 obj->data.s = strndup(arg, text_buffer_size);
2490 ERR("smapi_bat_temp needs an argument");
2491 END OBJ(smapi_bat_power, 0)
2493 obj->data.s = strndup(arg, text_buffer_size);
2495 ERR("smapi_bat_power needs an argument");
2496 END OBJ(smapi_bat_bar, 0)
2500 if(sscanf(arg, "%i %n", &obj->data.i, &cnt) <= 0) {
2501 ERR("first argument to smapi_bat_bar must be an integer value");
2505 arg = scan_bar(arg + cnt, &obj->a, &obj->b);
2508 ERR("smapi_bat_bar needs an argument");
2511 #define mpd_set_maxlen(name) \
2514 sscanf(arg, "%d", &i); \
2516 obj->data.i = i + 1; \
2518 ERR(#name ": invalid length argument"); \
2520 END OBJ(mpd_artist, INFO_MPD)
2521 mpd_set_maxlen(mpd_artist);
2523 END OBJ(mpd_title, INFO_MPD)
2524 mpd_set_maxlen(mpd_title);
2526 END OBJ(mpd_random, INFO_MPD) init_mpd();
2527 END OBJ(mpd_repeat, INFO_MPD) init_mpd();
2528 END OBJ(mpd_elapsed, INFO_MPD) init_mpd();
2529 END OBJ(mpd_length, INFO_MPD) init_mpd();
2530 END OBJ(mpd_track, INFO_MPD)
2531 mpd_set_maxlen(mpd_track);
2533 END OBJ(mpd_name, INFO_MPD)
2534 mpd_set_maxlen(mpd_name);
2536 END OBJ(mpd_file, INFO_MPD)
2537 mpd_set_maxlen(mpd_file);
2539 END OBJ(mpd_percent, INFO_MPD) init_mpd();
2540 END OBJ(mpd_album, INFO_MPD)
2541 mpd_set_maxlen(mpd_album);
2543 END OBJ(mpd_vol, INFO_MPD) init_mpd();
2544 END OBJ(mpd_bitrate, INFO_MPD) init_mpd();
2545 END OBJ(mpd_status, INFO_MPD) init_mpd();
2547 END OBJ(mpd_bar, INFO_MPD)
2549 scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
2552 END OBJ(mpd_smart, INFO_MPD)
2553 mpd_set_maxlen(mpd_smart);
2555 END OBJ_IF(if_mpd_playing, INFO_MPD)
2557 #undef mpd_set_maxlen
2560 END OBJ(moc_state, INFO_MOC)
2561 END OBJ(moc_file, INFO_MOC)
2562 END OBJ(moc_title, INFO_MOC)
2563 END OBJ(moc_artist, INFO_MOC)
2564 END OBJ(moc_song, INFO_MOC)
2565 END OBJ(moc_album, INFO_MOC)
2566 END OBJ(moc_totaltime, INFO_MOC)
2567 END OBJ(moc_timeleft, INFO_MOC)
2568 END OBJ(moc_curtime, INFO_MOC)
2569 END OBJ(moc_bitrate, INFO_MOC)
2570 END OBJ(moc_rate, INFO_MOC)
2573 END OBJ(xmms2_artist, INFO_XMMS2)
2574 END OBJ(xmms2_album, INFO_XMMS2)
2575 END OBJ(xmms2_title, INFO_XMMS2)
2576 END OBJ(xmms2_genre, INFO_XMMS2)
2577 END OBJ(xmms2_comment, INFO_XMMS2)
2578 END OBJ(xmms2_url, INFO_XMMS2)
2579 END OBJ(xmms2_tracknr, INFO_XMMS2)
2580 END OBJ(xmms2_bitrate, INFO_XMMS2)
2581 END OBJ(xmms2_date, INFO_XMMS2)
2582 END OBJ(xmms2_id, INFO_XMMS2)
2583 END OBJ(xmms2_duration, INFO_XMMS2)
2584 END OBJ(xmms2_elapsed, INFO_XMMS2)
2585 END OBJ(xmms2_size, INFO_XMMS2)
2586 END OBJ(xmms2_status, INFO_XMMS2)
2587 END OBJ(xmms2_percent, INFO_XMMS2)
2588 END OBJ(xmms2_bar, INFO_XMMS2)
2590 scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
2591 END OBJ(xmms2_smart, INFO_XMMS2)
2592 END OBJ(xmms2_playlist, INFO_XMMS2)
2593 END OBJ(xmms2_timesplayed, INFO_XMMS2)
2594 END OBJ_IF(if_xmms2_connected, INFO_XMMS2)
2597 END OBJ(audacious_status, INFO_AUDACIOUS)
2598 END OBJ(audacious_title, INFO_AUDACIOUS)
2600 sscanf(arg, "%d", &info.audacious.max_title_len);
2601 if (info.audacious.max_title_len > 0) {
2602 info.audacious.max_title_len++;
2604 CRIT_ERR("audacious_title: invalid length argument");
2607 END OBJ(audacious_length, INFO_AUDACIOUS)
2608 END OBJ(audacious_length_seconds, INFO_AUDACIOUS)
2609 END OBJ(audacious_position, INFO_AUDACIOUS)
2610 END OBJ(audacious_position_seconds, INFO_AUDACIOUS)
2611 END OBJ(audacious_bitrate, INFO_AUDACIOUS)
2612 END OBJ(audacious_frequency, INFO_AUDACIOUS)
2613 END OBJ(audacious_channels, INFO_AUDACIOUS)
2614 END OBJ(audacious_filename, INFO_AUDACIOUS)
2615 END OBJ(audacious_playlist_length, INFO_AUDACIOUS)
2616 END OBJ(audacious_playlist_position, INFO_AUDACIOUS)
2617 END OBJ(audacious_main_volume, INFO_AUDACIOUS)
2618 END OBJ(audacious_bar, INFO_AUDACIOUS)
2620 scan_bar(arg, &obj->a, &obj->b);
2623 END OBJ(bmpx_title, INFO_BMPX)
2624 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
2625 END OBJ(bmpx_artist, INFO_BMPX)
2626 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
2627 END OBJ(bmpx_album, INFO_BMPX)
2628 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
2629 END OBJ(bmpx_track, INFO_BMPX)
2630 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
2631 END OBJ(bmpx_uri, INFO_BMPX)
2632 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
2633 END OBJ(bmpx_bitrate, INFO_BMPX)
2634 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
2640 char *userid = (char *) malloc(20 * sizeof(char));
2641 char *apikey = (char *) malloc(64 * sizeof(char));
2642 char *charid = (char *) malloc(20 * sizeof(char));
2644 argc = sscanf(arg, "%20s %64s %20s", userid, apikey, charid);
2645 obj->data.eve.charid = charid;
2646 obj->data.eve.userid = userid;
2647 obj->data.eve.apikey = apikey;
2651 CRIT_ERR("eve needs arguments: <userid> <apikey> <characterid>");
2657 int argc, delay, act_par;
2658 unsigned int nrspaces = 0;
2659 char *uri = (char *) malloc(128 * sizeof(char));
2660 char *action = (char *) malloc(64 * sizeof(char));
2662 argc = sscanf(arg, "%127s %d %63s %d %u", uri, &delay, action,
2663 &act_par, &nrspaces);
2664 obj->data.rss.uri = uri;
2665 obj->data.rss.delay = delay;
2666 obj->data.rss.action = action;
2667 obj->data.rss.act_par = act_par;
2668 obj->data.rss.nrspaces = nrspaces;
2672 CRIT_ERR("rss needs arguments: <uri> <delay in minutes> <action> "
2673 "[act_par] [spaces in front]");
2679 obj->data.s = strndup(arg, text_buffer_size);
2681 CRIT_ERR("lua needs arguments: <function name> [function parameters]");
2683 END OBJ(lua_parse, 0)
2685 obj->data.s = strndup(arg, text_buffer_size);
2687 CRIT_ERR("lua_parse needs arguments: <function name> [function parameters]");
2689 END OBJ(lua_read_parse, 0)
2691 obj->data.s = strndup(arg, text_buffer_size);
2693 CRIT_ERR("lua_read_parse needs arguments: <function name> <string to pass>");
2698 arg = scan_bar(arg, &obj->a, &obj->b);
2700 obj->data.s = strndup(arg, text_buffer_size);
2702 CRIT_ERR("lua_bar needs arguments: <height>,<width> <function name> [function parameters]");
2705 CRIT_ERR("lua_bar needs arguments: <height>,<width> <function name> [function parameters]");
2708 END OBJ(lua_graph, 0)
2709 SIZE_DEFAULTS(graph);
2711 arg = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
2712 &obj->e, &obj->char_a, &obj->char_b);
2714 obj->data.s = strndup(arg, text_buffer_size);
2716 CRIT_ERR("lua_graph needs arguments: <\"normal\"|\"log\"> <height>,<width> <gradient colour 1> <gradient colour 2> <scale> <function name> [function parameters]");
2719 CRIT_ERR("lua_graph needs arguments: <\"normal\"|\"log\"> <height>,<width> <gradient colour 1> <gradient colour 2> <scale> <function name> [function parameters]");
2721 END OBJ(lua_gauge, 0)
2722 SIZE_DEFAULTS(gauge);
2724 arg = scan_gauge(arg, &obj->a, &obj->b);
2726 obj->data.s = strndup(arg, text_buffer_size);
2728 CRIT_ERR("lua_gauge needs arguments: <height>,<width> <function name> [function parameters]");
2731 CRIT_ERR("lua_gauge needs arguments: <height>,<width> <function name> [function parameters]");
2734 #endif /* HAVE_LUA */
2737 if (scan_hddtemp(arg, &obj->data.hddtemp.dev,
2738 &obj->data.hddtemp.addr, &obj->data.hddtemp.port)) {
2739 ERR("hddtemp needs arguments");
2740 obj->type = OBJ_text;
2741 obj->data.s = strndup("${hddtemp}", text_buffer_size);
2742 obj->data.hddtemp.update_time = 0;
2744 obj->data.hddtemp.temp = NULL;
2746 #ifdef TCP_PORT_MONITOR
2747 END OBJ(tcp_portmon, INFO_TCP_PORT_MONITOR)
2748 tcp_portmon_init(arg, &obj->data.tcp_port_monitor);
2750 END OBJ(entropy_avail, INFO_ENTROPY)
2751 END OBJ(entropy_poolsize, INFO_ENTROPY)
2753 END OBJ(entropy_bar, INFO_ENTROPY)
2755 scan_bar(arg, &obj->a, &obj->b);
2760 obj->data.scroll.step = 1;
2761 if (arg && sscanf(arg, "%u %n", &obj->data.scroll.show, &n1) > 0) {
2762 if (sscanf(arg + n1, "%u %n", &obj->data.scroll.step, &n2) > 0)
2764 obj->data.scroll.text = strndup(arg + n1, text_buffer_size);
2765 obj->data.scroll.start = 0;
2766 obj->sub = malloc(sizeof(struct text_object));
2767 extract_variable_text_internal(obj->sub,
2768 obj->data.scroll.text, 0);
2770 CRIT_ERR("scroll needs arguments: <length> [<step>] <text>");
2775 unsigned int indenting = 0; //vars can be used as args for other vars
2778 startvar[0] = endvar[0] = startvar[1] = endvar[1] = -1;
2780 for(i=0; arg[i] != 0 && j < 2; i++) {
2781 if(startvar[j] == -1) {
2785 }else if(endvar[j] == -1) {
2788 }else if(arg[i] == '}') {
2791 if (indenting == 0 && arg[i+1] < 48) { //<48 has 0, $, and the most used chars not used in varnames but not { or }
2797 if(startvar[0] >= 0 && endvar[0] >= 0 && startvar[1] >= 0 && endvar[1] >= 0) {
2798 obj->data.combine.left=malloc(endvar[0]-startvar[0]+1);
2799 obj->data.combine.seperation=malloc(startvar[1]-endvar[0]+1);
2800 obj->data.combine.right=malloc(endvar[1]-startvar[1]+1);
2801 strncpy(obj->data.combine.left, arg+startvar[0], endvar[0]-startvar[0]); obj->data.combine.left[endvar[0]-startvar[0]]=0;
2802 strncpy(obj->data.combine.seperation, arg+endvar[0], startvar[1]-endvar[0]); obj->data.combine.seperation[startvar[1]-endvar[0]]=0;
2803 strncpy(obj->data.combine.right, arg+startvar[1], endvar[1]-startvar[1]); obj->data.combine.right[endvar[1]-startvar[1]]=0;
2804 obj->sub = malloc(sizeof(struct text_object));
2805 extract_variable_text_internal(obj->sub, obj->data.combine.left, 0);
2806 obj->sub->sub = malloc(sizeof(struct text_object));
2807 extract_variable_text_internal(obj->sub->sub, obj->data.combine.right, 0);
2809 CRIT_ERR("combine needs arguments: <text1> <text2>");
2812 CRIT_ERR("combine needs arguments: <text1> <text2>");
2817 CRIT_ERR("nvidia needs an argument\n");
2818 } else if (set_nvidia_type(&obj->data.nvidia, arg)) {
2819 CRIT_ERR("nvidia: invalid argument"
2820 " specified: '%s'\n", arg);
2825 END OBJ(apcupsd, INFO_APCUPSD)
2829 if (sscanf(arg, "%63s %d", host, &port) != 2) {
2830 CRIT_ERR("apcupsd needs arguments: <host> <port>");
2832 info.apcupsd.port = htons(port);
2833 strncpy(info.apcupsd.host, host, sizeof(info.apcupsd.host));
2836 CRIT_ERR("apcupsd needs arguments: <host> <port>");
2838 END OBJ(apcupsd_name, INFO_APCUPSD)
2839 END OBJ(apcupsd_model, INFO_APCUPSD)
2840 END OBJ(apcupsd_upsmode, INFO_APCUPSD)
2841 END OBJ(apcupsd_cable, INFO_APCUPSD)
2842 END OBJ(apcupsd_status, INFO_APCUPSD)
2843 END OBJ(apcupsd_linev, INFO_APCUPSD)
2844 END OBJ(apcupsd_load, INFO_APCUPSD)
2846 END OBJ(apcupsd_loadbar, INFO_APCUPSD)
2848 scan_bar(arg, &obj->a, &obj->b);
2849 END OBJ(apcupsd_loadgraph, INFO_APCUPSD)
2851 SIZE_DEFAULTS(graph);
2852 buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
2853 &obj->e, &obj->char_a, &obj->char_b);
2855 END OBJ(apcupsd_loadgauge, INFO_APCUPSD)
2856 SIZE_DEFAULTS(gauge);
2857 scan_gauge(arg, &obj->a, &obj->b);
2859 END OBJ(apcupsd_charge, INFO_APCUPSD)
2860 END OBJ(apcupsd_timeleft, INFO_APCUPSD)
2861 END OBJ(apcupsd_temp, INFO_APCUPSD)
2862 END OBJ(apcupsd_lastxfer, INFO_APCUPSD)
2863 #endif /* APCUPSD */
2867 ERR("unknown variable %s", s);
2868 obj->type = OBJ_text;
2869 snprintf(buf, 256, "${%s}", s);
2870 obj->data.s = strndup(buf, text_buffer_size);
2877 static struct text_object *create_plain_text(const char *s)
2879 struct text_object *obj;
2881 if (s == NULL || *s == '\0') {
2885 obj = new_text_object_internal();
2887 obj->type = OBJ_text;
2888 obj->data.s = strndup(s, text_buffer_size);
2892 /* backslash_escape - do the actual substitution task for template objects
2894 * The field templates is used for substituting the \N occurences. Set it to
2895 * NULL to leave them as they are.
2897 static char *backslash_escape(const char *src, char **templates, unsigned int template_count)
2901 unsigned int dup_idx = 0, dup_len;
2903 dup_len = strlen(src) + 1;
2904 src_dup = malloc(dup_len * sizeof(char));
2912 if (*(p + 1) == '\\') {
2913 src_dup[dup_idx++] = '\\';
2915 } else if (*(p + 1) == ' ') {
2916 src_dup[dup_idx++] = ' ';
2918 } else if (*(p + 1) == 'n') {
2919 src_dup[dup_idx++] = '\n';
2921 } else if (templates) {
2922 unsigned int tmpl_num;
2924 if ((sscanf(p + 1, "%u%n", &tmpl_num, &digits) <= 0) ||
2925 (tmpl_num > template_count))
2927 dup_len += strlen(templates[tmpl_num - 1]);
2928 src_dup = realloc(src_dup, dup_len * sizeof(char));
2929 sprintf(src_dup + dup_idx, "%s", templates[tmpl_num - 1]);
2930 dup_idx += strlen(templates[tmpl_num - 1]);
2935 src_dup[dup_idx++] = *p;
2940 src_dup[dup_idx] = '\0';
2941 src_dup = realloc(src_dup, (strlen(src_dup) + 1) * sizeof(char));
2945 /* handle_template_object - core logic of the template object
2947 * use config variables like this:
2948 * template1 = "$\1\2"
2949 * template2 = "\1: ${fs_bar 4,100 \2} ${fs_used \2} / ${fs_size \2}"
2951 * and use them like this:
2952 * ${template1 node name}
2953 * ${template2 root /}
2954 * ${template2 cdrom /mnt/cdrom}
2956 static char *handle_template(const char *tmpl, const char *args)
2958 char *args_dup = NULL;
2960 char **argsp = NULL;
2961 unsigned int argcnt = 0, template_idx, i;
2964 if ((sscanf(tmpl, "template%u", &template_idx) != 1) ||
2965 (template_idx >= MAX_TEMPLATES))
2969 args_dup = strdup(args);
2972 while (*p && (*p == ' ' && *(p - 1) != '\\'))
2974 if (*(p - 1) == '\\')
2977 while (*p && (*p != ' ' || *(p - 1) == '\\'))
2983 argsp = realloc(argsp, ++argcnt * sizeof(char *));
2984 argsp[argcnt - 1] = p_old;
2986 for (i = 0; i < argcnt; i++) {
2988 tmp = backslash_escape(argsp[i], NULL, 0);
2989 DBGP2("%s: substituted arg '%s' to '%s'", tmpl, argsp[i], tmp);
2994 eval_text = backslash_escape(template[template_idx], argsp, argcnt);
2995 DBGP("substituted %s, output is '%s'", tmpl, eval_text);
2997 for (i = 0; i < argcnt; i++)
3003 static char *find_and_replace_templates(const char *inbuf)
3005 char *outbuf, *indup, *p, *o, *templ, *args, *tmpl_out;
3008 outlen = strlen(inbuf) + 1;
3009 o = outbuf = calloc(outlen, sizeof(char));
3010 memset(outbuf, 0, outlen * sizeof(char));
3012 p = indup = strdup(inbuf);
3014 while (*p && *p != '$')
3020 if (strncmp(p, "$template", 9) && strncmp(p, "${template", 10)) {
3025 if (*(p + 1) == '{') {
3028 while (*p && !isspace(*p) && *p != '{' && *p != '}')
3036 while (*p && stack > 0) {
3044 // stack is empty. that means the previous char was }, so we zero it
3047 // we ran into the end of string without finding a closing }, bark
3048 CRIT_ERR("cannot find a closing '}' in template expansion");
3052 while (*p && !isspace(*p))
3056 tmpl_out = handle_template(templ, args);
3058 outlen += strlen(tmpl_out);
3059 outbuf = realloc(outbuf, outlen * sizeof(char));
3060 strcat (outbuf, tmpl_out);
3062 o = outbuf + strlen(outbuf);
3064 ERR("failed to handle template '%s' with args '%s'", templ, args);
3068 outbuf = realloc(outbuf, (strlen(outbuf) + 1) * sizeof(char));
3073 static int text_contains_templates(const char *text)
3075 if (strcasestr(text, "${template") != NULL)
3077 if (strcasestr(text, "$template") != NULL)
3082 static void strfold(char *start, int count)
3085 for (curplace = start + count; *curplace != 0; curplace++) {
3086 *(curplace - count) = *curplace;
3088 *(curplace - count - 1) = 0;
3091 static size_t remove_comments(char *string)
3093 char *curplace, *curplace2;
3095 for (curplace = string; *curplace != 0; curplace++) {
3096 if (*curplace == '\\' && *(curplace + 1) == '#') {
3097 // strcpy can't be used for overlapping strings
3098 strfold(curplace, 1);
3100 } else if (*curplace == '#') {
3101 // remove everything until we hit a '\n'
3102 curplace2 = curplace;
3103 while (*curplace2) {
3105 if (*curplace2 == '\n' &&
3106 *(curplace2 + 1) != '#') break;
3109 strfold(curplace, curplace2 - curplace);
3110 folded += curplace2 - curplace;
3119 static int extract_variable_text_internal(struct text_object *retval, const char *const_p, char allow_threaded)
3121 struct text_object *obj;
3122 char *p, *s, *orig_p;
3124 void *ifblock_opaque = NULL;
3129 p = strndup(const_p, max_user_text - 1);
3130 while (text_contains_templates(p)) {
3132 tmp = find_and_replace_templates(p);
3138 if (strcmp(p, const_p)) {
3139 DBGP("replaced all templates in text: input is\n'%s'\noutput is\n'%s'", const_p, p);
3141 DBGP("no templates to replace");
3144 memset(retval, 0, sizeof(struct text_object));
3146 line = global_text_lines;
3154 obj = create_plain_text(s);
3156 append_object(retval, obj);
3166 /* variable is either $foo or ${foo} */
3168 unsigned int brl = 1, brr = 0;
3172 while (*p && brl != brr) {
3187 while (*p && (isalnum((int) *p) || *p == '_')) {
3192 /* copy variable to buffer */
3193 len = (p - s > 255) ? 255 : (p - s);
3194 strncpy(buf, s, len);
3202 /* search for variable in environment */
3206 obj = create_plain_text(var);
3208 append_object(retval, obj);
3213 /* if variable wasn't found in environment, use some special */
3218 if (strchr(buf, ' ')) {
3219 arg = strchr(buf, ' ');
3222 while (isspace((int) *arg)) {
3230 /* lowercase variable name */
3233 *tmp_p = tolower(*tmp_p);
3237 obj = construct_text_object(buf, arg,
3238 line, allow_threaded,
3241 append_object(retval, obj);
3245 obj = create_plain_text("$");
3248 append_object(retval, obj);
3251 } else if (*p == '#') {
3257 obj = create_plain_text(s);
3259 append_object(retval, obj);
3262 if (!ifblock_stack_empty(&ifblock_opaque)) {
3263 ERR("one or more $endif's are missing");
3270 static void extract_variable_text(const char *p)
3272 free_text_objects(&global_root_object, 0);
3286 extract_variable_text_internal(&global_root_object, p, 1);
3289 int parse_conky_vars(struct text_object *root, char *txt, char *p, struct information *cur)
3291 extract_variable_text_internal(root, txt, 0);
3292 generate_text_internal(p, max_user_text, *root, cur);
3296 static inline struct mail_s *ensure_mail_thread(struct text_object *obj,
3297 void *thread(void *), const char *text)
3299 if (obj->char_b && info.mail) {
3300 // this means we use info
3301 if (!info.mail->p_timed_thread) {
3302 info.mail->p_timed_thread =
3303 timed_thread_create(thread,
3304 (void *) info.mail, info.mail->interval * 1000000);
3305 if (!info.mail->p_timed_thread) {
3306 ERR("Error creating %s timed thread", text);
3308 timed_thread_register(info.mail->p_timed_thread,
3309 &info.mail->p_timed_thread);
3310 if (timed_thread_run(info.mail->p_timed_thread)) {
3311 ERR("Error running %s timed thread", text);
3315 } else if (obj->data.mail) {
3316 // this means we use obj
3317 if (!obj->data.mail->p_timed_thread) {
3318 obj->data.mail->p_timed_thread =
3319 timed_thread_create(thread,
3320 (void *) obj->data.mail,
3321 obj->data.mail->interval * 1000000);
3322 if (!obj->data.mail->p_timed_thread) {
3323 ERR("Error creating %s timed thread", text);
3325 timed_thread_register(obj->data.mail->p_timed_thread,
3326 &obj->data.mail->p_timed_thread);
3327 if (timed_thread_run(obj->data.mail->p_timed_thread)) {
3328 ERR("Error running %s timed thread", text);
3331 return obj->data.mail;
3332 } else if (!obj->a) {
3333 // something is wrong, warn once then stop
3334 ERR("There's a problem with your mail settings. "
3335 "Check that the global mail settings are properly defined"
3336 " (line %li).", obj->line);
3342 char *format_time(unsigned long timeval, const int width)
3345 unsigned long nt; // narrow time, for speed on 32-bit
3346 unsigned cc; // centiseconds
3347 unsigned nn; // multi-purpose whatever
3350 cc = nt % 100; // centiseconds past second
3351 nt /= 100; // total seconds
3352 nn = nt % 60; // seconds past the minute
3353 nt /= 60; // total minutes
3354 if (width >= snprintf(buf, sizeof buf, "%lu:%02u.%02u",
3356 return strndup(buf, text_buffer_size);
3358 if (width >= snprintf(buf, sizeof buf, "%lu:%02u", nt, nn)) {
3359 return strndup(buf, text_buffer_size);
3361 nn = nt % 60; // minutes past the hour
3362 nt /= 60; // total hours
3363 if (width >= snprintf(buf, sizeof buf, "%lu,%02u", nt, nn)) {
3364 return strndup(buf, text_buffer_size);
3366 nn = nt; // now also hours
3367 if (width >= snprintf(buf, sizeof buf, "%uh", nn)) {
3368 return strndup(buf, text_buffer_size);
3370 nn /= 24; // now days
3371 if (width >= snprintf(buf, sizeof buf, "%ud", nn)) {
3372 return strndup(buf, text_buffer_size);
3374 nn /= 7; // now weeks
3375 if (width >= snprintf(buf, sizeof buf, "%uw", nn)) {
3376 return strndup(buf, text_buffer_size);
3378 // well shoot, this outta' fit...
3379 return strndup("<inf>", text_buffer_size);
3382 //remove backspaced chars, example: "dog^H^H^Hcat" becomes "cat"
3383 //string has to end with \0 and it's length should fit in a int
3385 void remove_deleted_chars(char *string){
3387 while(string[i] != 0){
3388 if(string[i] == BACKSPACE){
3390 strcpy( &(string[i-1]), &(string[i+1]) );
3392 }else strcpy( &(string[i]), &(string[i+1]) ); //necessary for ^H's at the start of a string
3397 static inline void format_media_player_time(char *buf, const int size,
3400 int days, hours, minutes;
3402 days = seconds / (24 * 60 * 60);
3403 seconds %= (24 * 60 * 60);
3404 hours = seconds / (60 * 60);
3405 seconds %= (60 * 60);
3406 minutes = seconds / 60;
3410 snprintf(buf, size, "%i days %i:%02i:%02i", days,
3411 hours, minutes, seconds);
3412 } else if (hours > 0) {
3413 snprintf(buf, size, "%i:%02i:%02i", hours, minutes,
3416 snprintf(buf, size, "%i:%02i", minutes, seconds);
3420 static inline double get_barnum(char *buf)
3432 if (sscanf(buf, "%lf", &barnum) == 0) {
3433 ERR("reading exec value failed (perhaps it's not the "
3434 "correct format?)");
3437 if (barnum > 100.0 || barnum < 0.0) {
3438 ERR("your exec value is not between 0 and 100, "
3439 "therefore it will be ignored");
3445 static void generate_text_internal(char *p, int p_max_size,
3446 struct text_object root, struct information *cur)
3448 struct text_object *obj;
3450 /* for the OBJ_top* handler */
3451 struct process **needed = 0;
3454 char buff_in[p_max_size];
3456 iconv_converting = 0;
3461 while (obj && p_max_size > 0) {
3462 needed = 0; // reset for top stuff
3464 /* IFBLOCK jumping algorithm
3466 * This is easier as it looks like:
3467 * - each IF checks it's condition
3468 * - on FALSE: call DO_JUMP
3469 * - on TRUE: don't care
3470 * - each ELSE calls DO_JUMP unconditionally
3471 * - each ENDIF is silently being ignored
3474 * DO_JUMP overwrites the "obj" variable of the loop and sets it to the target
3475 * (i.e. the corresponding ELSE or ENDIF). After that, processing for the given
3476 * object can continue, free()ing stuff e.g., then the for-loop does the rest: as
3477 * regularly, "obj" is being updated to point to obj->next, so object parsing
3478 * continues right after the corresponding ELSE or ENDIF. This means that if we
3479 * find an ELSE, it's corresponding IF must not have jumped, so we need to jump
3480 * always. If we encounter an ENDIF, it's corresponding IF or ELSE has not
3481 * jumped, and there is nothing to do.
3485 obj = obj->data.ifblock.next; \
3488 #define OBJ(a) break; case OBJ_##a:
3490 switch (obj->type) {
3492 ERR("not implemented obj type %d", obj->type);
3495 temp_print(p, p_max_size, get_acpi_temperature(obj->data.i), TEMP_CELSIUS);
3497 #endif /* !__OpenBSD__ */
3500 obj->a = get_freq(p, p_max_size, "%.0f", 1,
3501 obj->data.cpu_index);
3507 obj->a = get_freq(p, p_max_size, "%'.2f", 1000,
3508 obj->data.cpu_index);
3510 /* OpenBSD has no such flag (SUSv2) */
3511 obj->a = get_freq(p, p_max_size, "%.2f", 1000,
3512 obj->data.cpu_index);
3516 #if defined(__linux__)
3519 obj->a = get_voltage(p, p_max_size, "%.0f", 1,
3520 obj->data.cpu_index);
3525 obj->a = get_voltage(p, p_max_size, "%'.3f", 1000,
3526 obj->data.cpu_index);
3531 OBJ(wireless_essid) {
3532 snprintf(p, p_max_size, "%s", obj->data.net->essid);
3534 OBJ(wireless_mode) {
3535 snprintf(p, p_max_size, "%s", obj->data.net->mode);
3537 OBJ(wireless_bitrate) {
3538 snprintf(p, p_max_size, "%s", obj->data.net->bitrate);
3541 snprintf(p, p_max_size, "%s", obj->data.net->ap);
3543 OBJ(wireless_link_qual) {
3544 spaced_print(p, p_max_size, "%d", 4,
3545 obj->data.net->link_qual);
3547 OBJ(wireless_link_qual_max) {
3548 spaced_print(p, p_max_size, "%d", 4,
3549 obj->data.net->link_qual_max);
3551 OBJ(wireless_link_qual_perc) {
3552 if (obj->data.net->link_qual_max > 0) {
3553 spaced_print(p, p_max_size, "%.0f", 5,
3554 (double) obj->data.net->link_qual /
3555 obj->data.net->link_qual_max * 100);
3557 spaced_print(p, p_max_size, "unk", 5);
3560 OBJ(wireless_link_bar) {
3561 new_bar(p, obj->a, obj->b, ((double) obj->data.net->link_qual /
3562 obj->data.net->link_qual_max) * 255.0);
3564 #endif /* HAVE_IWLIB */
3566 #endif /* __linux__ */
3570 get_adt746x_cpu(p, p_max_size);
3573 get_adt746x_fan(p, p_max_size);
3576 get_acpi_fan(p, p_max_size);
3578 OBJ(acpiacadapter) {
3579 get_acpi_ac_adapter(p, p_max_size);
3582 get_battery_stuff(p, p_max_size, obj->data.s, BATTERY_STATUS);
3585 get_battery_stuff(p, p_max_size, obj->data.s, BATTERY_TIME);
3587 OBJ(battery_percent) {
3588 percent_print(p, p_max_size, get_battery_perct(obj->data.s));
3592 if(output_methods & TO_X) {
3593 new_bar(p, obj->a, obj->b, get_battery_perct_bar(obj->data.s));
3596 if(!obj->a) obj->a = DEFAULT_BAR_WIDTH_NO_X;
3597 new_bar_in_shell(p, p_max_size, get_battery_perct_bar(obj->data.s) / 2.55, obj->a);
3602 OBJ(battery_short) {
3603 get_battery_short_status(p, p_max_size, obj->data.s);
3605 #endif /* __OpenBSD__ */
3608 human_readable(cur->buffers * 1024, p, 255);
3611 human_readable(cur->cached * 1024, p, 255);
3614 if (obj->data.cpu_index > info.cpu_count) {
3615 ERR("obj->data.cpu_index %i info.cpu_count %i",
3616 obj->data.cpu_index, info.cpu_count);
3617 CRIT_ERR("attempting to use more CPUs than you have!");
3619 percent_print(p, p_max_size,
3620 round_to_int(cur->cpu_usage[obj->data.cpu_index] * 100.0));
3624 new_gauge(p, obj->a, obj->b,
3625 round_to_int(cur->cpu_usage[obj->data.cpu_index] * 255.0));
3629 if(output_methods & TO_X) {
3630 new_bar(p, obj->a, obj->b,
3631 round_to_int(cur->cpu_usage[obj->data.cpu_index] * 255.0));
3634 if(!obj->a) obj->a = DEFAULT_BAR_WIDTH_NO_X;
3635 new_bar_in_shell(p, p_max_size, round_to_int(cur->cpu_usage[obj->data.cpu_index] * 100), obj->a);
3642 new_graph(p, obj->a, obj->b, obj->c, obj->d,
3643 round_to_int(cur->cpu_usage[obj->data.cpu_index] * 100),
3644 100, 1, obj->char_a, obj->char_b);
3647 new_graph(p, obj->a, obj->b, obj->c, obj->d, cur->loadavg[0],
3648 obj->e, 1, obj->char_a, obj->char_b);
3651 new_fg(p, obj->data.l);
3684 OBJ(conky_version) {
3685 snprintf(p, p_max_size, "%s", VERSION);
3687 OBJ(conky_build_date) {
3688 snprintf(p, p_max_size, "%s", BUILD_DATE);
3690 OBJ(conky_build_arch) {
3691 snprintf(p, p_max_size, "%s", BUILD_ARCH);
3693 #if defined(__linux__)
3695 snprintf(p, p_max_size, "%s",
3696 get_disk_protect_queue(obj->data.s));
3699 snprintf(p, p_max_size, "%s", i8k.version);
3702 snprintf(p, p_max_size, "%s", i8k.bios);
3705 snprintf(p, p_max_size, "%s", i8k.serial);
3710 sscanf(i8k.cpu_temp, "%d", &cpu_temp);
3711 temp_print(p, p_max_size, (double)cpu_temp, TEMP_CELSIUS);
3713 OBJ(i8k_left_fan_status) {
3714 int left_fan_status;
3716 sscanf(i8k.left_fan_status, "%d", &left_fan_status);
3717 if (left_fan_status == 0) {
3718 snprintf(p, p_max_size, "off");
3720 if (left_fan_status == 1) {
3721 snprintf(p, p_max_size, "low");
3723 if (left_fan_status == 2) {
3724 snprintf(p, p_max_size, "high");
3727 OBJ(i8k_right_fan_status) {
3728 int right_fan_status;
3730 sscanf(i8k.right_fan_status, "%d", &right_fan_status);
3731 if (right_fan_status == 0) {
3732 snprintf(p, p_max_size, "off");
3734 if (right_fan_status == 1) {
3735 snprintf(p, p_max_size, "low");
3737 if (right_fan_status == 2) {
3738 snprintf(p, p_max_size, "high");
3741 OBJ(i8k_left_fan_rpm) {
3742 snprintf(p, p_max_size, "%s", i8k.left_fan_rpm);
3744 OBJ(i8k_right_fan_rpm) {
3745 snprintf(p, p_max_size, "%s", i8k.right_fan_rpm);
3747 OBJ(i8k_ac_status) {
3750 sscanf(i8k.ac_status, "%d", &ac_status);
3751 if (ac_status == -1) {
3752 snprintf(p, p_max_size, "disabled (read i8k docs)");
3754 if (ac_status == 0) {
3755 snprintf(p, p_max_size, "off");
3757 if (ac_status == 1) {
3758 snprintf(p, p_max_size, "on");
3761 OBJ(i8k_buttons_status) {
3762 snprintf(p, p_max_size, "%s", i8k.buttons_status);
3766 get_ibm_acpi_fan(p, p_max_size);
3769 get_ibm_acpi_temps();
3770 temp_print(p, p_max_size,
3771 ibm_acpi.temps[obj->data.sensor], TEMP_CELSIUS);
3774 get_ibm_acpi_volume(p, p_max_size);
3776 OBJ(ibm_brightness) {
3777 get_ibm_acpi_brightness(p, p_max_size);
3780 /* information from sony_laptop kernel module
3781 * /sys/devices/platform/sony-laptop */
3782 OBJ(sony_fanspeed) {
3783 get_sony_fanspeed(p, p_max_size);
3786 if (!cur->gw_info.count) {
3791 snprintf(p, p_max_size, "%s", cur->gw_info.iface);
3794 snprintf(p, p_max_size, "%s", cur->gw_info.ip);
3797 snprintf(p, p_max_size, "%d", get_laptop_mode());
3800 get_powerbook_batt_info(p, p_max_size, obj->data.i);
3802 #endif /* __linux__ */
3803 #if (defined(__FreeBSD__) || defined(__linux__))
3805 if ((obj->data.ifblock.s)
3806 && (!interface_up(obj->data.ifblock.s))) {
3812 OBJ(obsd_sensors_temp) {
3813 obsd_sensors.device = sensor_device;
3814 update_obsd_sensors();
3815 temp_print(p, p_max_size,
3816 obsd_sensors.temp[obsd_sensors.device][obj->data.sensor],
3819 OBJ(obsd_sensors_fan) {
3820 obsd_sensors.device = sensor_device;
3821 update_obsd_sensors();
3822 snprintf(p, p_max_size, "%d",
3823 obsd_sensors.fan[obsd_sensors.device][obj->data.sensor]);
3825 OBJ(obsd_sensors_volt) {
3826 obsd_sensors.device = sensor_device;
3827 update_obsd_sensors();
3828 snprintf(p, p_max_size, "%.2f",
3829 obsd_sensors.volt[obsd_sensors.device][obj->data.sensor]);
3832 get_obsd_vendor(p, p_max_size);
3835 get_obsd_product(p, p_max_size);
3837 #endif /* __OpenBSD__ */
3840 new_font(p, obj->data.s);
3843 /* TODO: move this correction from kB to kB/s elsewhere
3844 * (or get rid of it??) */
3846 human_readable((obj->data.diskio->current / update_interval) * 1024LL,
3850 human_readable((obj->data.diskio->current_write / update_interval) * 1024LL,
3854 human_readable((obj->data.diskio->current_read / update_interval) * 1024LL,
3859 new_graph(p, obj->a, obj->b, obj->c, obj->d,
3860 obj->data.diskio->current, obj->e, 1, obj->char_a, obj->char_b);
3862 OBJ(diskiograph_read) {
3863 new_graph(p, obj->a, obj->b, obj->c, obj->d,
3864 obj->data.diskio->current_read, obj->e, 1, obj->char_a, obj->char_b);
3866 OBJ(diskiograph_write) {
3867 new_graph(p, obj->a, obj->b, obj->c, obj->d,
3868 obj->data.diskio->current_write, obj->e, 1, obj->char_a, obj->char_b);
3872 human_readable(obj->data.net->recv_speed, p, 255);
3875 spaced_print(p, p_max_size, "%.1f", 8,
3876 obj->data.net->recv_speed / 1024.0);
3879 OBJ(downspeedgraph) {
3880 new_graph(p, obj->a, obj->b, obj->c, obj->d,
3881 obj->data.net->recv_speed / 1024.0, obj->e, 1, obj->char_a, obj->char_b);
3885 /* Since we see you, you're if has not jumped.
3886 * Do Ninja jump here: without leaving traces.
3887 * This is to prevent us from stale jumped flags.
3889 obj = obj->data.ifblock.next;
3893 /* harmless object, just ignore */
3897 if ((obj->data.net->addr.sa_data[2] & 255) == 0
3898 && (obj->data.net->addr.sa_data[3] & 255) == 0
3899 && (obj->data.net->addr.sa_data[4] & 255) == 0
3900 && (obj->data.net->addr.sa_data[5] & 255) == 0) {
3901 snprintf(p, p_max_size, "No Address");
3903 snprintf(p, p_max_size, "%u.%u.%u.%u",
3904 obj->data.net->addr.sa_data[2] & 255,
3905 obj->data.net->addr.sa_data[3] & 255,
3906 obj->data.net->addr.sa_data[4] & 255,
3907 obj->data.net->addr.sa_data[5] & 255);
3910 #if defined(__linux__)
3912 if(NULL != obj->data.net->addrs && strlen(obj->data.net->addrs) > 2)
3914 obj->data.net->addrs[strlen(obj->data.net->addrs) - 2] = 0; /* remove ", " from end of string */
3915 strcpy(p, obj->data.net->addrs);
3918 strcpy(p, "0.0.0.0");
3920 #endif /* __linux__ */
3921 #if defined(IMLIB2) && defined(X11)
3923 /* doesn't actually draw anything, just queues it omp. the
3924 * image will get drawn after the X event loop */
3925 cimlib_add_image(obj->data.s);
3929 struct information *tmp_info;
3930 struct text_object subroot, subroot2;
3932 tmp_info = malloc(sizeof(struct information));
3933 memcpy(tmp_info, cur, sizeof(struct information));
3934 parse_conky_vars(&subroot, obj->data.s, p, tmp_info);
3935 DBGP("evaluated '%s' to '%s'", obj->data.s, p);
3936 parse_conky_vars(&subroot2, p, p, tmp_info);
3938 free_text_objects(&subroot, 1);
3939 free_text_objects(&subroot2, 1);
3943 read_exec(obj->data.s, p, text_buffer_size);
3944 remove_deleted_chars(p);
3947 struct information *tmp_info;
3948 struct text_object subroot;
3950 read_exec(obj->data.s, p, text_buffer_size);
3952 tmp_info = malloc(sizeof(struct information));
3953 memcpy(tmp_info, cur, sizeof(struct information));
3954 parse_conky_vars(&subroot, p, p, tmp_info);
3956 free_text_objects(&subroot, 1);
3963 read_exec(obj->data.s, p, text_buffer_size);
3964 barnum = get_barnum(p); /*using the same function*/
3966 if (barnum >= 0.0) {
3968 new_gauge(p, obj->a, obj->b, round_to_int(barnum * 255.0));
3975 read_exec(obj->data.s, p, text_buffer_size);
3976 barnum = get_barnum(p);
3978 if (barnum >= 0.0) {
3980 if(output_methods & TO_X) {
3982 new_bar(p, obj->a, obj->b, round_to_int(barnum * 255.0));
3985 if(!obj->a) obj->a = DEFAULT_BAR_WIDTH_NO_X;
3986 new_bar_in_shell(p, p_max_size, barnum, obj->a);
3994 char showaslog = FALSE;
3995 char tempgrad = FALSE;
3997 char *cmd = obj->data.s;
3999 if (strncasecmp(obj->data.execi.cmd, LOGGRAPH" ", strlen(LOGGRAPH" ")) == EQUAL) {
4001 cmd = cmd + strlen(LOGGRAPH" ") * sizeof(char);
4002 } else if(strncasecmp(obj->data.s, NORMGRAPH" ", strlen(NORMGRAPH" ")) == EQUAL) {
4003 cmd = cmd + strlen(NORMGRAPH" ") * sizeof(char);
4005 if (strstr(cmd, " "TEMPGRAD) && strlen(cmd) > strlen(" "TEMPGRAD)) {
4007 cmd += strlen(" "TEMPGRAD);
4009 read_exec(cmd, p, text_buffer_size);
4010 barnum = get_barnum(p);
4012 if (barnum >= 0.0) {
4013 new_graph(p, obj->a, obj->b, obj->c, obj->d, round_to_int(barnum),
4014 100, 1, showaslog, tempgrad);
4019 if (current_update_time - obj->data.execi.last_update
4020 >= obj->data.execi.interval) {
4023 read_exec(obj->data.execi.cmd, p, text_buffer_size);
4024 barnum = get_barnum(p);
4026 if (barnum >= 0.0) {
4029 obj->data.execi.last_update = current_update_time;
4032 if(output_methods & TO_X) {
4033 new_bar(p, obj->a, obj->b, round_to_int(obj->f * 2.55));
4036 if(!obj->a) obj->a = DEFAULT_BAR_WIDTH_NO_X;
4037 new_bar_in_shell(p, p_max_size, round_to_int(obj->f), obj->a);
4044 if (current_update_time - obj->data.execi.last_update
4045 >= obj->data.execi.interval) {
4047 char showaslog = FALSE;
4048 char tempgrad = FALSE;
4049 char *cmd = obj->data.execi.cmd;
4051 if (strncasecmp(obj->data.execi.cmd, LOGGRAPH" ", strlen(LOGGRAPH" ")) == EQUAL) {
4053 cmd = cmd + strlen(LOGGRAPH" ") * sizeof(char);
4054 } else if(strncasecmp(obj->data.s, NORMGRAPH" ", strlen(NORMGRAPH" ")) == EQUAL) {
4055 cmd = cmd + strlen(NORMGRAPH" ") * sizeof(char);
4057 if (strstr(cmd, " "TEMPGRAD) && strlen(cmd) > strlen(" "TEMPGRAD)) {
4059 cmd += strlen(" "TEMPGRAD);
4061 obj->char_a = showaslog;
4062 obj->char_b = tempgrad;
4063 read_exec(cmd, p, text_buffer_size);
4064 barnum = get_barnum(p);
4066 if (barnum >= 0.0) {
4069 obj->data.execi.last_update = current_update_time;
4071 new_graph(p, obj->a, obj->b, obj->c, obj->d, (int) (obj->f), 100, 1, obj->char_a, obj->char_b);
4074 if (current_update_time - obj->data.execi.last_update
4075 >= obj->data.execi.interval) {
4078 read_exec(obj->data.execi.cmd, p, text_buffer_size);
4079 barnum = get_barnum(p);
4081 if (barnum >= 0.0) {
4082 obj->f = 255 * barnum / 100.0;
4084 obj->data.execi.last_update = current_update_time;
4086 new_gauge(p, obj->a, obj->b, round_to_int(obj->f));
4090 if (current_update_time - obj->data.execi.last_update
4091 >= obj->data.execi.interval
4092 && obj->data.execi.interval != 0) {
4093 read_exec(obj->data.execi.cmd, obj->data.execi.buffer,
4095 obj->data.execi.last_update = current_update_time;
4097 snprintf(p, text_buffer_size, "%s", obj->data.execi.buffer);
4100 struct text_object subroot;
4101 struct information *tmp_info =
4102 malloc(sizeof(struct information));
4103 memcpy(tmp_info, cur, sizeof(struct information));
4105 if (current_update_time - obj->data.execi.last_update
4106 < obj->data.execi.interval
4107 || obj->data.execi.interval == 0) {
4108 parse_conky_vars(&subroot, obj->data.execi.buffer, p, tmp_info);
4110 char *output = obj->data.execi.buffer;
4111 FILE *fp = popen(obj->data.execi.cmd, "r");
4112 int length = fread(output, 1, text_buffer_size, fp);
4116 output[length] = '\0';
4117 if (length > 0 && output[length - 1] == '\n') {
4118 output[length - 1] = '\0';
4121 parse_conky_vars(&subroot, obj->data.execi.buffer, p, tmp_info);
4122 obj->data.execi.last_update = current_update_time;
4124 free_text_objects(&subroot, 1);
4128 if (!obj->data.texeci.p_timed_thread) {
4129 obj->data.texeci.p_timed_thread =
4130 timed_thread_create(&threaded_exec,
4131 (void *) obj, obj->data.texeci.interval * 1000000);
4132 if (!obj->data.texeci.p_timed_thread) {
4133 ERR("Error creating texeci timed thread");
4135 timed_thread_register(obj->data.texeci.p_timed_thread,
4136 &obj->data.texeci.p_timed_thread);
4137 if (timed_thread_run(obj->data.texeci.p_timed_thread)) {
4138 ERR("Error running texeci timed thread");
4141 timed_thread_lock(obj->data.texeci.p_timed_thread);
4142 snprintf(p, text_buffer_size, "%s", obj->data.texeci.buffer);
4143 timed_thread_unlock(obj->data.texeci.p_timed_thread);
4146 #endif /* HAVE_POPEN */
4148 struct mail_s *mail = ensure_mail_thread(obj, imap_thread, "imap");
4150 if (mail && mail->p_timed_thread) {
4151 timed_thread_lock(mail->p_timed_thread);
4152 snprintf(p, p_max_size, "%lu", mail->unseen);
4153 timed_thread_unlock(mail->p_timed_thread);
4156 OBJ(imap_messages) {
4157 struct mail_s *mail = ensure_mail_thread(obj, imap_thread, "imap");
4159 if (mail && mail->p_timed_thread) {
4160 timed_thread_lock(mail->p_timed_thread);
4161 snprintf(p, p_max_size, "%lu", mail->messages);
4162 timed_thread_unlock(mail->p_timed_thread);
4166 struct mail_s *mail = ensure_mail_thread(obj, pop3_thread, "pop3");
4168 if (mail && mail->p_timed_thread) {
4169 timed_thread_lock(mail->p_timed_thread);
4170 snprintf(p, p_max_size, "%lu", mail->unseen);
4171 timed_thread_unlock(mail->p_timed_thread);
4175 struct mail_s *mail = ensure_mail_thread(obj, pop3_thread, "pop3");
4177 if (mail && mail->p_timed_thread) {
4178 timed_thread_lock(mail->p_timed_thread);
4179 snprintf(p, p_max_size, "%.1f",
4180 mail->used / 1024.0 / 1024.0);
4181 timed_thread_unlock(mail->p_timed_thread);
4185 if (obj->data.fs != NULL) {
4186 if (obj->data.fs->size == 0) {
4188 if(output_methods & TO_X) {
4189 new_bar(p, obj->data.fsbar.w, obj->data.fsbar.h, 255);
4192 if(!obj->data.fsbar.w) obj->data.fsbar.w = DEFAULT_BAR_WIDTH_NO_X;
4193 new_bar_in_shell(p, p_max_size, 100, obj->data.fsbar.w);
4199 if(output_methods & TO_X) {
4200 new_bar(p, obj->data.fsbar.w, obj->data.fsbar.h,
4201 (int) (255 - obj->data.fsbar.fs->avail * 255 /
4202 obj->data.fs->size));
4205 if(!obj->data.fsbar.w) obj->data.fsbar.w = DEFAULT_BAR_WIDTH_NO_X;
4206 new_bar_in_shell(p, p_max_size,
4207 (int) (100 - obj->data.fsbar.fs->avail * 100 / obj->data.fs->size), obj->data.fsbar.w);
4215 if (obj->data.fs != NULL) {
4216 human_readable( (obj->data.fs->free ? obj->data.fs->free :
4217 obj->data.fs->avail), p, 255);
4221 if (obj->data.fs != NULL) {
4224 if (obj->data.fs->size) {
4225 val = (obj->data.fs->free ? obj->data.fs->free :
4226 obj->data.fs->avail) * 100 /
4230 percent_print(p, p_max_size, val);
4234 if (obj->data.fs != NULL) {
4235 human_readable(obj->data.fs->size, p, 255);
4239 if (obj->data.fs != NULL)
4240 snprintf(p, p_max_size, "%s", obj->data.fs->type);
4243 if (obj->data.fs != NULL) {
4244 human_readable(obj->data.fs->size - (obj->data.fs->free
4245 ? obj->data.fs->free : obj->data.fs->avail), p, 255);
4249 if (obj->data.fs != NULL) {
4250 if (obj->data.fs->size == 0) {
4252 if(output_methods & TO_X) {
4253 new_bar(p, obj->data.fsbar.w, obj->data.fsbar.h, 255);
4256 if(!obj->data.fsbar.w) obj->data.fsbar.w = DEFAULT_BAR_WIDTH_NO_X;
4257 new_bar_in_shell(p, p_max_size, 100, obj->data.fsbar.w);
4263 if(output_methods & TO_X) {
4264 new_bar(p, obj->data.fsbar.w, obj->data.fsbar.h,
4265 (int) (obj->data.fsbar.fs->avail * 255 /
4266 obj->data.fs->size));
4269 if(!obj->data.fsbar.w) obj->data.fsbar.w = DEFAULT_BAR_WIDTH_NO_X;
4270 new_bar_in_shell(p, p_max_size,
4271 (int) (obj->data.fsbar.fs->avail * 100 / obj->data.fs->size), obj->data.fsbar.w);
4279 if (obj->data.fs != NULL) {
4282 if (obj->data.fs->size) {
4283 val = (obj->data.fs->free ? obj->data.fs->free :
4284 obj->data.fs->avail) * 100 /
4288 percent_print(p, p_max_size, 100 - val);
4292 float *v = info.loadavg;
4294 if (obj->data.loadavg[2]) {
4295 snprintf(p, p_max_size, "%.2f %.2f %.2f",
4296 v[obj->data.loadavg[0] - 1],
4297 v[obj->data.loadavg[1] - 1],
4298 v[obj->data.loadavg[2] - 1]);
4299 } else if (obj->data.loadavg[1]) {
4300 snprintf(p, p_max_size, "%.2f %.2f",
4301 v[obj->data.loadavg[0] - 1],
4302 v[obj->data.loadavg[1] - 1]);
4303 } else if (obj->data.loadavg[0]) {
4304 snprintf(p, p_max_size, "%.2f",
4305 v[obj->data.loadavg[0] - 1]);
4309 new_goto(p, obj->data.i);
4312 new_tab(p, obj->data.pair.a, obj->data.pair.b);
4316 new_hr(p, obj->data.i);
4320 if (cur->nameserver_info.nscount > obj->data.i)
4321 snprintf(p, p_max_size, "%s",
4322 cur->nameserver_info.ns_list[obj->data.i]);
4326 char *skill = eve(obj->data.eve.userid, obj->data.eve.apikey, obj->data.eve.charid);
4327 snprintf(p, p_max_size, "%s", skill);
4332 PRSS *data = get_rss_info(obj->data.rss.uri,
4333 obj->data.rss.delay);
4337 snprintf(p, p_max_size, "prss: Error reading RSS data\n");
4339 if (strcmp(obj->data.rss.action, "feed_title") == EQUAL) {
4341 // remove trailing new line if one exists
4342 if (str[strlen(str) - 1] == '\n') {
4343 str[strlen(str) - 1] = 0;
4345 snprintf(p, p_max_size, "%s", str);
4346 } else if (strcmp(obj->data.rss.action, "item_title") == EQUAL) {
4347 if (obj->data.rss.act_par < data->item_count) {
4348 str = data->items[obj->data.rss.act_par].title;
4349 // remove trailing new line if one exists
4350 if (str[strlen(str) - 1] == '\n') {
4351 str[strlen(str) - 1] = 0;
4353 snprintf(p, p_max_size, "%s", str);
4355 } else if (strcmp(obj->data.rss.action, "item_desc") == EQUAL) {
4356 if (obj->data.rss.act_par < data->item_count) {
4358 data->items[obj->data.rss.act_par].description;
4359 // remove trailing new line if one exists
4360 if (str[strlen(str) - 1] == '\n') {
4361 str[strlen(str) - 1] = 0;
4363 snprintf(p, p_max_size, "%s", str);
4365 } else if (strcmp(obj->data.rss.action, "item_titles") == EQUAL) {
4366 if (data->item_count > 0) {
4369 //'tmpspaces' is a string with spaces too be placed in front of each title
4370 char *tmpspaces = malloc(obj->data.rss.nrspaces + 1);
4371 memset(tmpspaces, ' ', obj->data.rss.nrspaces);
4372 tmpspaces[obj->data.rss.nrspaces]=0;
4376 if (obj->data.rss.act_par > data->item_count) {
4377 show = data->item_count;
4379 show = obj->data.rss.act_par;
4381 for (itmp = 0; itmp < show; itmp++) {
4382 PRSS_Item *item = &data->items[itmp];
4386 // don't add new line before first item
4388 strncat(p, "\n", p_max_size);
4390 /* remove trailing new line if one exists,
4391 * we have our own */
4392 if (str[strlen(str) - 1] == '\n') {
4393 str[strlen(str) - 1] = 0;
4395 strncat(p, tmpspaces, p_max_size);
4396 strncat(p, str, p_max_size);
4407 char *str = llua_getstring(obj->data.s);
4409 snprintf(p, p_max_size, "%s", str);
4414 char *str = llua_getstring(obj->data.s);
4416 struct information *tmp_info;
4417 struct text_object subroot;
4419 tmp_info = malloc(sizeof(struct information));
4420 memcpy(tmp_info, cur, sizeof(struct information));
4421 parse_conky_vars(&subroot, str, p, tmp_info);
4423 free_text_objects(&subroot, 1);
4428 OBJ(lua_read_parse) {
4429 struct information *tmp_info;
4430 struct text_object subroot, subroot2;
4433 sscanf(obj->data.s, "%64s", func);
4434 text = obj->data.s + strlen(func) + 1;
4436 tmp_info = malloc(sizeof(struct information));
4437 memcpy(tmp_info, cur, sizeof(struct information));
4438 parse_conky_vars(&subroot, text, p, tmp_info);
4439 DBGP("evaluated '%s' to '%s'", text, p);
4441 str = llua_getstring_read(func, p);
4443 parse_conky_vars(&subroot2, str, p, tmp_info);
4444 DBGP("evaluated '%s' to '%s'", str, p);
4447 free_text_objects(&subroot2, 1);
4449 free_text_objects(&subroot, 1);
4454 if (llua_getinteger(obj->data.s, &per)) {
4456 if(output_methods & TO_X) {
4457 new_bar(p, obj->a, obj->b, (per/100.0 * 255));
4460 if(!obj->a) obj->a = DEFAULT_BAR_WIDTH_NO_X;
4461 new_bar_in_shell(p, p_max_size, per, obj->a);
4470 if (llua_getinteger(obj->data.s, &per)) {
4471 new_graph(p, obj->a, obj->b, obj->c, obj->d,
4472 (per/100.0 * 255), 100, 1, obj->char_a, obj->char_b);
4477 if (llua_getinteger(obj->data.s, &per)) {
4478 new_gauge(p, obj->a, obj->b, (per/100.0 * 255));
4482 #endif /* HAVE_LUA */
4487 if (obj->data.hddtemp.update_time < current_update_time - 30) {
4488 if (obj->data.hddtemp.temp)
4489 free(obj->data.hddtemp.temp);
4490 obj->data.hddtemp.temp = get_hddtemp_info(obj->data.hddtemp.dev,
4491 obj->data.hddtemp.addr, obj->data.hddtemp.port);
4492 obj->data.hddtemp.update_time = current_update_time;
4494 if (!obj->data.hddtemp.temp) {
4495 snprintf(p, p_max_size, "N/A");
4497 val = strtol(obj->data.hddtemp.temp + 1, &endptr, 10);
4498 unit = obj->data.hddtemp.temp[0];
4500 if (*endptr != '\0')
4501 snprintf(p, p_max_size, "N/A");
4502 else if (unit == 'C')
4503 temp_print(p, p_max_size, (double)val, TEMP_CELSIUS);
4504 else if (unit == 'F')
4505 temp_print(p, p_max_size, (double)val, TEMP_FAHRENHEIT);
4507 snprintf(p, p_max_size, "N/A");
4512 new_offset(p, obj->data.i);
4515 new_voffset(p, obj->data.i);
4521 r = get_sysfs_info(&obj->data.sysfs.fd, obj->data.sysfs.arg,
4522 obj->data.sysfs.devtype, obj->data.sysfs.type);
4524 r = r * obj->data.sysfs.factor + obj->data.sysfs.offset;
4526 if (!strncmp(obj->data.sysfs.type, "temp", 4)) {
4527 temp_print(p, p_max_size, r, TEMP_CELSIUS);
4528 } else if (r >= 100.0 || r == 0) {
4529 snprintf(p, p_max_size, "%d", (int) r);
4531 snprintf(p, p_max_size, "%.1f", r);
4537 r = get_sysfs_info(&obj->data.sysfs.fd, obj->data.sysfs.arg,
4538 obj->data.sysfs.devtype, obj->data.sysfs.type);
4540 r = r * obj->data.sysfs.factor + obj->data.sysfs.offset;
4542 if (!strncmp(obj->data.sysfs.type, "temp", 4)) {
4543 temp_print(p, p_max_size, r, TEMP_CELSIUS);
4544 } else if (r >= 100.0 || r == 0) {
4545 snprintf(p, p_max_size, "%d", (int) r);
4547 snprintf(p, p_max_size, "%.1f", r);
4553 r = get_sysfs_info(&obj->data.sysfs.fd, obj->data.sysfs.arg,
4554 obj->data.sysfs.devtype, obj->data.sysfs.type);
4556 r = r * obj->data.sysfs.factor + obj->data.sysfs.offset;
4558 if (!strncmp(obj->data.sysfs.type, "temp", 4)) {
4559 temp_print(p, p_max_size, r, TEMP_CELSIUS);
4560 } else if (r >= 100.0 || r == 0) {
4561 snprintf(p, p_max_size, "%d", (int) r);
4563 snprintf(p, p_max_size, "%.1f", r);
4566 #endif /* __linux__ */
4568 new_alignr(p, obj->data.i);
4571 new_alignc(p, obj->data.i);
4574 char buf[max_user_text];
4575 struct information *tmp_info =
4576 malloc(sizeof(struct information));
4577 memcpy(tmp_info, cur, sizeof(struct information));
4578 generate_text_internal(buf, max_user_text,
4579 *obj->sub, tmp_info);
4581 if (strlen(buf) != 0) {
4587 char expression[max_user_text];
4589 struct information *tmp_info;
4591 tmp_info = malloc(sizeof(struct information));
4592 memcpy(tmp_info, cur, sizeof(struct information));
4593 generate_text_internal(expression, max_user_text,
4594 *obj->sub, tmp_info);
4595 DBGP("parsed arg into '%s'", expression);
4597 val = compare(expression);
4599 ERR("compare failed for expression '%s'",
4607 if (obj->data.ifblock.str
4608 && !check_contains(obj->data.ifblock.s,
4609 obj->data.ifblock.str)) {
4611 } else if (obj->data.ifblock.s
4612 && access(obj->data.ifblock.s, F_OK)) {
4617 if ((obj->data.ifblock.s)
4618 && (!check_mount(obj->data.ifblock.s))) {
4623 if ((obj->data.ifblock.s) && system(obj->data.ifblock.s)) {
4627 #if defined(__linux__)
4629 snprintf(p, p_max_size, "%s", get_ioscheduler(obj->data.s));
4633 snprintf(p, p_max_size, "%s", cur->uname_s.release);
4636 snprintf(p, p_max_size, "%s", cur->uname_s.machine);
4641 human_readable(cur->mem * 1024, p, 255);
4644 human_readable(cur->memeasyfree * 1024, p, 255);
4647 human_readable(cur->memfree * 1024, p, 255);
4650 human_readable(cur->memmax * 1024, p, 255);
4654 percent_print(p, p_max_size, cur->mem * 100 / cur->memmax);
4658 new_gauge(p, obj->data.pair.a, obj->data.pair.b,
4659 cur->memmax ? (cur->mem * 255) / (cur->memmax) : 0);
4664 if(output_methods & TO_X) {
4665 new_bar(p, obj->data.pair.a, obj->data.pair.b,
4666 cur->memmax ? (cur->mem * 255) / (cur->memmax) : 0);
4669 if(!obj->data.pair.a) obj->data.pair.a = DEFAULT_BAR_WIDTH_NO_X;
4670 new_bar_in_shell(p, p_max_size, cur->memmax ? (cur->mem * 100) / (cur->memmax) : 0, obj->data.pair.a);
4677 new_graph(p, obj->a, obj->b, obj->c, obj->d,
4678 cur->memmax ? (cur->mem * 100.0) / (cur->memmax) : 0.0,
4679 100, 1, obj->char_a, obj->char_b);
4684 percent_print(p, p_max_size, mixer_get_avg(obj->data.l));
4687 percent_print(p, p_max_size, mixer_get_left(obj->data.l));
4690 percent_print(p, p_max_size, mixer_get_right(obj->data.l));
4694 new_bar(p, obj->data.mixerbar.w, obj->data.mixerbar.h,
4695 mixer_to_255(obj->data.mixerbar.l,mixer_get_avg(obj->data.mixerbar.l)));
4698 new_bar(p, obj->data.mixerbar.w, obj->data.mixerbar.h,
4699 mixer_to_255(obj->data.mixerbar.l,mixer_get_left(obj->data.mixerbar.l)));
4702 new_bar(p, obj->data.mixerbar.w, obj->data.mixerbar.h,
4703 mixer_to_255(obj->data.mixerbar.l,mixer_get_right(obj->data.mixerbar.l)));
4706 OBJ(if_mixer_mute) {
4707 if (!mixer_is_mute(obj->data.ifblock.i)) {
4713 snprintf(p, p_max_size, "%d", cur->x11.monitor.current);
4715 OBJ(monitor_number) {
4716 snprintf(p, p_max_size, "%d", cur->x11.monitor.number);
4722 update_mail_count(&obj->data.local_mail);
4723 snprintf(p, p_max_size, "%d", obj->data.local_mail.mail_count);
4726 update_mail_count(&obj->data.local_mail);
4727 snprintf(p, p_max_size, "%d",
4728 obj->data.local_mail.new_mail_count);
4731 update_mail_count(&obj->data.local_mail);
4732 snprintf(p, p_max_size, "%d",
4733 obj->data.local_mail.seen_mail_count);
4736 update_mail_count(&obj->data.local_mail);
4737 snprintf(p, p_max_size, "%d",
4738 obj->data.local_mail.unseen_mail_count);
4740 OBJ(flagged_mails) {
4741 update_mail_count(&obj->data.local_mail);
4742 snprintf(p, p_max_size, "%d",
4743 obj->data.local_mail.flagged_mail_count);
4745 OBJ(unflagged_mails) {
4746 update_mail_count(&obj->data.local_mail);
4747 snprintf(p, p_max_size, "%d",
4748 obj->data.local_mail.unflagged_mail_count);
4750 OBJ(forwarded_mails) {
4751 update_mail_count(&obj->data.local_mail);
4752 snprintf(p, p_max_size, "%d",
4753 obj->data.local_mail.forwarded_mail_count);
4755 OBJ(unforwarded_mails) {
4756 update_mail_count(&obj->data.local_mail);
4757 snprintf(p, p_max_size, "%d",
4758 obj->data.local_mail.unforwarded_mail_count);
4760 OBJ(replied_mails) {
4761 update_mail_count(&obj->data.local_mail);
4762 snprintf(p, p_max_size, "%d",
4763 obj->data.local_mail.replied_mail_count);
4765 OBJ(unreplied_mails) {
4766 update_mail_count(&obj->data.local_mail);
4767 snprintf(p, p_max_size, "%d",
4768 obj->data.local_mail.unreplied_mail_count);
4771 update_mail_count(&obj->data.local_mail);
4772 snprintf(p, p_max_size, "%d",
4773 obj->data.local_mail.draft_mail_count);
4775 OBJ(trashed_mails) {
4776 update_mail_count(&obj->data.local_mail);
4777 snprintf(p, p_max_size, "%d",
4778 obj->data.local_mail.trashed_mail_count);
4781 mbox_scan(obj->data.mboxscan.args, obj->data.mboxscan.output,
4783 snprintf(p, p_max_size, "%s", obj->data.mboxscan.output);
4786 snprintf(p, p_max_size, "%s", cur->uname_s.nodename);
4789 new_outline(p, obj->data.l);
4792 spaced_print(p, p_max_size, "%hu", 4, cur->procs);
4794 OBJ(running_processes) {
4795 spaced_print(p, p_max_size, "%hu", 4, cur->run_procs);
4798 snprintf(p, p_max_size, "%s", obj->data.s);
4802 new_bg(p, obj->data.l);
4805 new_stippled_hr(p, obj->data.pair.a, obj->data.pair.b);
4809 human_readable(cur->swap * 1024, p, 255);
4812 human_readable(cur->swapmax * 1024, p, 255);
4815 if (cur->swapmax == 0) {
4816 strncpy(p, "No swap", p_max_size);
4818 percent_print(p, p_max_size, cur->swap * 100 / cur->swapmax);
4823 if(output_methods & TO_X) {
4824 new_bar(p, obj->data.pair.a, obj->data.pair.b,
4825 cur->swapmax ? (cur->swap * 255) / (cur->swapmax) : 0);
4828 if(!obj->data.pair.a) obj->data.pair.a = DEFAULT_BAR_WIDTH_NO_X;
4829 new_bar_in_shell(p, p_max_size, cur->swapmax ? (cur->swap * 100) / (cur->swapmax) : 0, obj->data.pair.a);
4835 snprintf(p, p_max_size, "%s", cur->uname_s.sysname);
4838 time_t t = time(NULL);
4839 struct tm *tm = localtime(&t);
4841 setlocale(LC_TIME, "");
4842 strftime(p, p_max_size, obj->data.s, tm);
4845 time_t t = time(NULL);
4846 struct tm *tm = gmtime(&t);
4848 strftime(p, p_max_size, obj->data.s, tm);
4855 if (obj->data.tztime.tz) {
4856 oldTZ = getenv("TZ");
4857 setenv("TZ", obj->data.tztime.tz, 1);
4863 setlocale(LC_TIME, "");
4864 strftime(p, p_max_size, obj->data.tztime.fmt, tm);
4866 setenv("TZ", oldTZ, 1);
4871 // Needless to free oldTZ since getenv gives ptr to static data
4874 human_readable(obj->data.net->recv, p, 255);
4877 human_readable(obj->data.net->trans, p, 255);
4880 snprintf(p, p_max_size, "%d", total_updates);
4883 if(total_updates % updatereset != obj->data.ifblock.i - 1) {
4888 human_readable(obj->data.net->trans_speed, p, 255);
4891 spaced_print(p, p_max_size, "%.1f", 8,
4892 obj->data.net->trans_speed / 1024.0);
4896 new_graph(p, obj->a, obj->b, obj->c, obj->d,
4897 obj->data.net->trans_speed / 1024.0, obj->e, 1, obj->char_a, obj->char_b);
4901 format_seconds_short(p, p_max_size, (int) cur->uptime);
4904 format_seconds(p, p_max_size, (int) cur->uptime);
4907 snprintf(p, p_max_size, "%s", cur->users.names);
4910 snprintf(p, p_max_size, "%s", cur->users.terms);
4913 snprintf(p, p_max_size, "%s", cur->users.times);
4916 snprintf(p, p_max_size, "%d", cur->users.number);
4918 #if (defined(__FreeBSD__) || defined(__FreeBSD_kernel__) \
4919 || defined(__OpenBSD__)) && (defined(i386) || defined(__i386__))
4923 msg = get_apm_adapter();
4924 snprintf(p, p_max_size, "%s", msg);
4927 OBJ(apm_battery_life) {
4930 msg = get_apm_battery_life();
4931 snprintf(p, p_max_size, "%s", msg);
4934 OBJ(apm_battery_time) {
4937 msg = get_apm_battery_time();
4938 snprintf(p, p_max_size, "%s", msg);
4941 #endif /* __FreeBSD__ __OpenBSD__ */
4944 #define mpd_printf(fmt, val) \
4945 snprintf(p, p_max_size, fmt, mpd_get_info()->val)
4946 #define mpd_sprintf(val) { \
4947 if (!obj->data.i || obj->data.i > p_max_size) \
4948 mpd_printf("%s", val); \
4950 snprintf(p, obj->data.i, "%s", mpd_get_info()->val); \
4955 mpd_sprintf(artist);
4959 mpd_printf("%s", random);
4961 mpd_printf("%s", repeat);
4969 mpd_printf("%d", volume);
4971 mpd_printf("%d", bitrate);
4973 mpd_printf("%s", status);
4975 format_media_player_time(p, p_max_size, mpd_get_info()->elapsed);
4978 format_media_player_time(p, p_max_size, mpd_get_info()->length);
4981 percent_print(p, p_max_size, (int)(mpd_get_info()->progress * 100));
4985 new_bar(p, obj->data.pair.a, obj->data.pair.b,
4986 (int) (mpd_get_info()->progress * 255.0f));
4990 struct mpd_s *mpd = mpd_get_info();
4991 int len = obj->data.i;
4992 if (len == 0 || len > p_max_size)
4995 memset(p, 0, p_max_size);
4996 if (mpd->artist && *mpd->artist &&
4997 mpd->title && *mpd->title) {
4998 snprintf(p, len, "%s - %s", mpd->artist,
5000 } else if (mpd->title && *mpd->title) {
5001 snprintf(p, len, "%s", mpd->title);
5002 } else if (mpd->artist && *mpd->artist) {
5003 snprintf(p, len, "%s", mpd->artist);
5004 } else if (mpd->file && *mpd->file) {
5005 snprintf(p, len, "%s", mpd->file);
5010 OBJ(if_mpd_playing) {
5011 if (!mpd_get_info()->is_playing) {
5024 #define MOC_PRINT(t, a) \
5025 snprintf(p, p_max_size, "%s", (moc.t ? moc.t : a))
5027 MOC_PRINT(state, "??");
5030 MOC_PRINT(file, "no file");
5033 MOC_PRINT(title, "no title");
5036 MOC_PRINT(artist, "no artist");
5039 MOC_PRINT(song, "no song");
5042 MOC_PRINT(album, "no album");
5044 OBJ(moc_totaltime) {
5045 MOC_PRINT(totaltime, "0:00");
5048 MOC_PRINT(timeleft, "0:00");
5051 MOC_PRINT(curtime, "0:00");
5054 MOC_PRINT(bitrate, "0Kbps");
5057 MOC_PRINT(rate, "0KHz");
5063 snprintf(p, p_max_size, "%s", cur->xmms2.artist);
5066 snprintf(p, p_max_size, "%s", cur->xmms2.album);
5069 snprintf(p, p_max_size, "%s", cur->xmms2.title);
5072 snprintf(p, p_max_size, "%s", cur->xmms2.genre);
5074 OBJ(xmms2_comment) {
5075 snprintf(p, p_max_size, "%s", cur->xmms2.comment);
5078 snprintf(p, p_max_size, "%s", cur->xmms2.url);
5081 snprintf(p, p_max_size, "%s", cur->xmms2.status);
5084 snprintf(p, p_max_size, "%s", cur->xmms2.date);
5086 OBJ(xmms2_tracknr) {
5087 if (cur->xmms2.tracknr != -1) {
5088 snprintf(p, p_max_size, "%i", cur->xmms2.tracknr);
5091 OBJ(xmms2_bitrate) {
5092 snprintf(p, p_max_size, "%i", cur->xmms2.bitrate);
5095 snprintf(p, p_max_size, "%u", cur->xmms2.id);
5098 snprintf(p, p_max_size, "%2.1f", cur->xmms2.size);
5100 OBJ(xmms2_elapsed) {
5101 snprintf(p, p_max_size, "%02d:%02d", cur->xmms2.elapsed / 60000,
5102 (cur->xmms2.elapsed / 1000) % 60);
5104 OBJ(xmms2_duration) {
5105 snprintf(p, p_max_size, "%02d:%02d",
5106 cur->xmms2.duration / 60000,
5107 (cur->xmms2.duration / 1000) % 60);
5109 OBJ(xmms2_percent) {
5110 snprintf(p, p_max_size, "%2.0f", cur->xmms2.progress * 100);
5113 new_bar(p, obj->data.pair.a, obj->data.pair.b,
5114 (int) (cur->xmms2.progress * 255.0f));
5116 OBJ(xmms2_playlist) {
5117 snprintf(p, p_max_size, "%s", cur->xmms2.playlist);
5119 OBJ(xmms2_timesplayed) {
5120 snprintf(p, p_max_size, "%i", cur->xmms2.timesplayed);
5123 if (strlen(cur->xmms2.title) < 2
5124 && strlen(cur->xmms2.title) < 2) {
5125 snprintf(p, p_max_size, "%s", cur->xmms2.url);
5127 snprintf(p, p_max_size, "%s - %s", cur->xmms2.artist,
5131 OBJ(if_xmms2_connected) {
5132 if (cur->xmms2.conn_state != 1) {
5138 OBJ(audacious_status) {
5139 snprintf(p, p_max_size, "%s",
5140 cur->audacious.items[AUDACIOUS_STATUS]);
5142 OBJ(audacious_title) {
5143 snprintf(p, cur->audacious.max_title_len > 0
5144 ? cur->audacious.max_title_len : p_max_size, "%s",
5145 cur->audacious.items[AUDACIOUS_TITLE]);
5147 OBJ(audacious_length) {
5148 snprintf(p, p_max_size, "%s",
5149 cur->audacious.items[AUDACIOUS_LENGTH]);
5151 OBJ(audacious_length_seconds) {
5152 snprintf(p, p_max_size, "%s",
5153 cur->audacious.items[AUDACIOUS_LENGTH_SECONDS]);
5155 OBJ(audacious_position) {
5156 snprintf(p, p_max_size, "%s",
5157 cur->audacious.items[AUDACIOUS_POSITION]);
5159 OBJ(audacious_position_seconds) {
5160 snprintf(p, p_max_size, "%s",
5161 cur->audacious.items[AUDACIOUS_POSITION_SECONDS]);
5163 OBJ(audacious_bitrate) {
5164 snprintf(p, p_max_size, "%s",
5165 cur->audacious.items[AUDACIOUS_BITRATE]);
5167 OBJ(audacious_frequency) {
5168 snprintf(p, p_max_size, "%s",
5169 cur->audacious.items[AUDACIOUS_FREQUENCY]);
5171 OBJ(audacious_channels) {
5172 snprintf(p, p_max_size, "%s",
5173 cur->audacious.items[AUDACIOUS_CHANNELS]);
5175 OBJ(audacious_filename) {
5176 snprintf(p, p_max_size, "%s",
5177 cur->audacious.items[AUDACIOUS_FILENAME]);
5179 OBJ(audacious_playlist_length) {
5180 snprintf(p, p_max_size, "%s",
5181 cur->audacious.items[AUDACIOUS_PLAYLIST_LENGTH]);
5183 OBJ(audacious_playlist_position) {
5184 snprintf(p, p_max_size, "%s",
5185 cur->audacious.items[AUDACIOUS_PLAYLIST_POSITION]);
5187 OBJ(audacious_main_volume) {
5188 snprintf(p, p_max_size, "%s",
5189 cur->audacious.items[AUDACIOUS_MAIN_VOLUME]);
5191 OBJ(audacious_bar) {
5195 atof(cur->audacious.items[AUDACIOUS_POSITION_SECONDS]) /
5196 atof(cur->audacious.items[AUDACIOUS_LENGTH_SECONDS]);
5197 new_bar(p, obj->a, obj->b, (int) (progress * 255.0f));
5203 snprintf(p, p_max_size, "%s", cur->bmpx.title);
5206 snprintf(p, p_max_size, "%s", cur->bmpx.artist);
5209 snprintf(p, p_max_size, "%s", cur->bmpx.album);
5212 snprintf(p, p_max_size, "%s", cur->bmpx.uri);
5215 snprintf(p, p_max_size, "%i", cur->bmpx.track);
5218 snprintf(p, p_max_size, "%i", cur->bmpx.bitrate);
5221 /* we have three different types of top (top, top_mem
5222 * and top_time). To avoid having almost-same code three
5223 * times, we have this special handler. */
5226 parse_top_args("top", obj->data.top.s, obj);
5227 if (!needed) needed = cur->cpu;
5229 parse_top_args("top_mem", obj->data.top.s, obj);
5230 if (!needed) needed = cur->memu;
5232 parse_top_args("top_time", obj->data.top.s, obj);
5233 if (!needed) needed = cur->time;
5235 if (needed[obj->data.top.num]) {
5238 switch (obj->data.top.type) {
5240 snprintf(p, top_name_width + 1, "%-*s", top_name_width,
5241 needed[obj->data.top.num]->name);
5244 snprintf(p, 7, "%6.2f",
5245 needed[obj->data.top.num]->amount);
5248 snprintf(p, 6, "%5i",
5249 needed[obj->data.top.num]->pid);
5252 snprintf(p, 7, "%6.2f",
5253 needed[obj->data.top.num]->totalmem);
5256 timeval = format_time(
5257 needed[obj->data.top.num]->total_cpu_time, 9);
5258 snprintf(p, 10, "%9s", timeval);
5262 human_readable(needed[obj->data.top.num]->rss,
5266 human_readable(needed[obj->data.top.num]->vsize,
5272 print_tail_object(obj, p, p_max_size);
5274 print_head_object(obj, p, p_max_size);
5276 FILE *fp = open_file(obj->data.s, &obj->a);
5279 /* FIXME: use something more general (see also tail.c, head.c */
5280 #define BUFSZ 0x1000
5285 while(fgets(buf, BUFSZ, fp) != NULL){
5286 for(j = 0; buf[j] != 0; j++) {
5287 if(buf[j] == '\n') {
5292 sprintf(p, "%d", lines);
5295 sprintf(p, "File Unreadable");
5300 FILE *fp = open_file(obj->data.s, &obj->a);
5305 char inword = FALSE;
5308 while(fgets(buf, BUFSZ, fp) != NULL){
5309 for(j = 0; buf[j] != 0; j++) {
5310 if(!isspace(buf[j])) {
5311 if(inword == FALSE) {
5320 sprintf(p, "%d", words);
5323 sprintf(p, "File Unreadable");
5326 #ifdef TCP_PORT_MONITOR
5328 tcp_portmon_action(p, p_max_size,
5329 &obj->data.tcp_port_monitor);
5335 iconv_converting = 1;
5336 iconv_selected = obj->a;
5339 iconv_converting = 0;
5344 OBJ(entropy_avail) {
5345 snprintf(p, p_max_size, "%d", cur->entropy.entropy_avail);
5347 OBJ(entropy_poolsize) {
5348 snprintf(p, p_max_size, "%d", cur->entropy.poolsize);
5352 double entropy_perc;
5354 entropy_perc = (double) cur->entropy.entropy_avail /
5355 (double) cur->entropy.poolsize;
5356 new_bar(p, obj->a, obj->b, (int) (entropy_perc * 255.0f));
5363 s = smapi_get_val(obj->data.s);
5364 snprintf(p, p_max_size, "%s", s);
5368 OBJ(if_smapi_bat_installed) {
5370 if(obj->data.ifblock.s && sscanf(obj->data.ifblock.s, "%i", &idx) == 1) {
5371 if(!smapi_bat_installed(idx)) {
5375 ERR("argument to if_smapi_bat_installed must be an integer");
5377 OBJ(smapi_bat_perc) {
5379 if(obj->data.s && sscanf(obj->data.s, "%i", &idx) == 1) {
5380 val = smapi_bat_installed(idx) ?
5381 smapi_get_bat_int(idx, "remaining_percent") : 0;
5382 percent_print(p, p_max_size, val);
5384 ERR("argument to smapi_bat_perc must be an integer");
5386 OBJ(smapi_bat_temp) {
5388 if(obj->data.s && sscanf(obj->data.s, "%i", &idx) == 1) {
5389 val = smapi_bat_installed(idx) ?
5390 smapi_get_bat_int(idx, "temperature") : 0;
5391 /* temperature is in milli degree celsius */
5392 temp_print(p, p_max_size, val / 1000, TEMP_CELSIUS);
5394 ERR("argument to smapi_bat_temp must be an integer");
5396 OBJ(smapi_bat_power) {
5398 if(obj->data.s && sscanf(obj->data.s, "%i", &idx) == 1) {
5399 val = smapi_bat_installed(idx) ?
5400 smapi_get_bat_int(idx, "power_now") : 0;
5401 /* power_now is in mW, set to W with one digit precision */
5402 snprintf(p, p_max_size, "%.1f", ((double)val / 1000));
5404 ERR("argument to smapi_bat_power must be an integer");
5406 OBJ(smapi_bat_bar) {
5407 if(obj->data.i >= 0 && smapi_bat_installed(obj->data.i))
5408 new_bar(p, obj->a, obj->b, (int)
5409 (255 * smapi_get_bat_int(obj->data.i, "remaining_percent") / 100));
5411 new_bar(p, obj->a, obj->b, 0);
5416 char *tmp, buf[max_user_text];
5417 generate_text_internal(buf, max_user_text,
5420 if (strlen(buf) <= obj->data.scroll.show) {
5421 snprintf(p, p_max_size, "%s", buf);
5424 #define LINESEPARATOR '|'
5425 //place all the lines behind each other with LINESEPARATOR between them
5426 for(j = 0; buf[j] != 0; j++) {
5428 buf[j]=LINESEPARATOR;
5431 //scroll the output obj->data.scroll.start places by copying that many chars from
5432 //the front of the string to tmp, scrolling the rest to the front and placing tmp
5433 //at the back of the string
5434 tmp = calloc(obj->data.scroll.start + 1, sizeof(char));
5435 strncpy(tmp, buf, obj->data.scroll.start); tmp[obj->data.scroll.start] = 0;
5436 for(j = obj->data.scroll.start; buf[j] != 0; j++){
5437 buf[j - obj->data.scroll.start] = buf[j];
5439 strcpy(&buf[j - obj->data.scroll.start], tmp);
5441 //only show the requested number of chars
5442 if(obj->data.scroll.show < j) {
5443 buf[obj->data.scroll.show] = 0;
5445 //next time, scroll a place more or reset scrolling if we are at the end
5446 obj->data.scroll.start += obj->data.scroll.step;
5447 if(obj->data.scroll.start >= j){
5448 obj->data.scroll.start = 0;
5450 snprintf(p, p_max_size, "%s", buf);
5453 char buf[2][max_user_text];
5460 struct llrows* next;
5462 struct llrows *ll_rows[2], *current[2];
5463 struct text_object * objsub = obj->sub;
5467 #pragma omp parallel for
5468 #endif /* HAVE_OPENMP */
5469 for(i=0; i<2; i++) {
5472 ll_rows[i] = malloc(sizeof(struct llrows));
5473 current[i] = ll_rows[i];
5475 #pragma omp parallel for
5476 #endif /* HAVE_OPENMP */
5477 for(j=0; j<i; j++) objsub = objsub->sub;
5478 generate_text_internal(buf[i], max_user_text, *objsub, cur);
5480 * #ifdef HAVE_OPENMP
5481 * #pragma omp parallel for reduction (+:nr_rows[i])
5482 * #endif HAVE_OPENMP */
5483 for(j=0; buf[i][j] != 0; j++) {
5484 if(buf[i][j] == '\t') buf[i][j] = ' ';
5485 if(buf[i][j] == '\n') {
5487 current[i]->row = strdup(buf[i]+nextstart);
5488 if(i==0 && (long)strlen(current[i]->row) > longest) longest = (long)strlen(current[i]->row);
5489 current[i]->next = malloc(sizeof(struct llrows));
5490 current[i] = current[i]->next;
5495 current[i]->row = strdup(buf[i]+nextstart);
5496 if(i==0 && (long)strlen(current[i]->row) > longest) longest = (long)strlen(current[i]->row);
5497 current[i]->next = NULL;
5498 current[i] = ll_rows[i];
5500 for(j=0; j < (nr_rows[0] > nr_rows[1] ? nr_rows[0] : nr_rows[1] ); j++) {
5502 strcat(p, current[0]->row);
5503 i=strlen(current[0]->row);
5505 while(i < longest) {
5510 strcat(p, obj->data.combine.seperation);
5511 strcat(p, current[1]->row);
5515 #pragma omp parallel for
5516 #endif /* HAVE_OPENMP */
5517 for(i=0; i<2; i++) if(current[i]) current[i]=current[i]->next;
5520 #pragma omp parallel for
5521 #endif /* HAVE_OPENMP */
5522 for(i=0; i<2; i++) {
5523 while(ll_rows[i] != NULL) {
5524 current[i]=ll_rows[i];
5525 free(current[i]->row);
5526 ll_rows[i]=current[i]->next;
5533 int value = get_nvidia_value(obj->data.nvidia.type, display);
5535 snprintf(p, p_max_size, "N/A");
5536 else if (obj->data.nvidia.type == NV_TEMP)
5537 temp_print(p, p_max_size, (double)value, TEMP_CELSIUS);
5538 else if (obj->data.nvidia.print_as_float &&
5539 value > 0 && value < 100)
5540 snprintf(p, p_max_size, "%.1f", (float)value);
5542 snprintf(p, p_max_size, "%d", value);
5547 /* This is just a meta-object to set host:port */
5550 snprintf(p, p_max_size, "%s",
5551 cur->apcupsd.items[APCUPSD_NAME]);
5553 OBJ(apcupsd_model) {
5554 snprintf(p, p_max_size, "%s",
5555 cur->apcupsd.items[APCUPSD_MODEL]);
5557 OBJ(apcupsd_upsmode) {
5558 snprintf(p, p_max_size, "%s",
5559 cur->apcupsd.items[APCUPSD_UPSMODE]);
5561 OBJ(apcupsd_cable) {
5562 snprintf(p, p_max_size, "%s",
5563 cur->apcupsd.items[APCUPSD_CABLE]);
5565 OBJ(apcupsd_status) {
5566 snprintf(p, p_max_size, "%s",
5567 cur->apcupsd.items[APCUPSD_STATUS]);
5569 OBJ(apcupsd_linev) {
5570 snprintf(p, p_max_size, "%s",
5571 cur->apcupsd.items[APCUPSD_LINEV]);
5574 snprintf(p, p_max_size, "%s",
5575 cur->apcupsd.items[APCUPSD_LOAD]);
5578 OBJ(apcupsd_loadbar) {
5580 progress = atof(cur->apcupsd.items[APCUPSD_LOAD]) / 100.0 * 255.0;
5581 new_bar(p, obj->a, obj->b, (int)progress);
5583 OBJ(apcupsd_loadgraph) {
5585 progress = atof(cur->apcupsd.items[APCUPSD_LOAD]);
5586 new_graph(p, obj->a, obj->b, obj->c, obj->d,
5587 (int)progress, 100, 1, obj->char_a, obj->char_b);
5589 OBJ(apcupsd_loadgauge) {
5591 progress = atof(cur->apcupsd.items[APCUPSD_LOAD]) / 100.0 * 255.0;
5592 new_gauge(p, obj->a, obj->b,
5596 OBJ(apcupsd_charge) {
5597 snprintf(p, p_max_size, "%s",
5598 cur->apcupsd.items[APCUPSD_CHARGE]);
5600 OBJ(apcupsd_timeleft) {
5601 snprintf(p, p_max_size, "%s",
5602 cur->apcupsd.items[APCUPSD_TIMELEFT]);
5605 snprintf(p, p_max_size, "%s",
5606 cur->apcupsd.items[APCUPSD_TEMP]);
5608 OBJ(apcupsd_lastxfer) {
5609 snprintf(p, p_max_size, "%s",
5610 cur->apcupsd.items[APCUPSD_LASTXFER]);
5612 #endif /* APCUPSD */
5619 unsigned int a = strlen(p);
5622 if (a > 0 && iconv_converting && iconv_selected > 0
5623 && (iconv_cd[iconv_selected - 1] != (iconv_t) (-1))) {
5625 size_t dummy1, dummy2;
5626 char *ptr = buff_in;
5629 dummy1 = dummy2 = a;
5631 strncpy(buff_in, p, p_max_size);
5633 iconv(*iconv_cd[iconv_selected - 1], NULL, NULL, NULL, NULL);
5634 while (dummy1 > 0) {
5635 bytes = iconv(*iconv_cd[iconv_selected - 1], &ptr, &dummy1,
5638 ERR("Iconv codeset conversion failed");
5643 /* It is nessecary when we are converting from multibyte to
5644 * singlebyte codepage */
5647 #endif /* HAVE_ICONV */
5655 double current_update_time, next_update_time, last_update_time;
5657 static void generate_text(void)
5659 struct information *cur = &info;
5666 current_update_time = get_time();
5670 /* add things to the buffer */
5676 generate_text_internal(p, max_user_text, global_root_object, cur);
5678 if (stuff_in_upper_case) {
5681 tmp_p = text_buffer;
5683 *tmp_p = toupper(*tmp_p);
5688 next_update_time += update_interval;
5689 if (next_update_time < get_time()) {
5690 next_update_time = get_time() + update_interval;
5691 } else if (next_update_time > get_time() + update_interval) {
5692 next_update_time = get_time() + update_interval;
5694 last_update_time = current_update_time;
5699 static inline int get_string_width(const char *s)
5702 if (output_methods & TO_X) {
5703 return *s ? calc_text_width(s, strlen(s)) : 0;
5709 static inline int get_string_width_special(char *s)
5717 if ((output_methods & TO_X) == 0) {
5719 return (s) ? strlen(s) : 0;
5727 p = strndup(s, text_buffer_size);
5731 if (*p == SPECIAL_CHAR) {
5732 /* shift everything over by 1 so that the special char
5733 * doesn't mess up the size calculation */
5734 for (i = 0; i < (long)strlen(p); i++) {
5735 *(p + i) = *(p + i + 1);
5737 if (specials[special_index + idx].type == GRAPH
5738 || specials[special_index + idx].type == GAUGE
5739 || specials[special_index + idx].type == BAR) {
5740 width += specials[special_index + idx].width;
5747 if (strlen(final) > 1) {
5748 width += calc_text_width(final, strlen(final));
5756 static void text_size_updater(char *s);
5758 int last_font_height;
5759 static void update_text_area(void)
5763 if ((output_methods & TO_X) == 0)
5765 /* update text size if it isn't fixed */
5770 text_width = minimum_width;
5773 last_font_height = font_height();
5774 for_each_line(text_buffer, text_size_updater);
5776 if (text_height < minimum_height) {
5777 text_height = minimum_height;
5779 if (text_width > maximum_width && maximum_width > 0) {
5780 text_width = maximum_width;
5784 /* get text position on workarea */
5785 switch (text_alignment) {
5792 x = workarea[2] - text_width - gap_x;
5797 x = workarea[2] / 2 - text_width / 2 - gap_x;
5804 y = workarea[3] - text_height - gap_y;
5808 x = workarea[2] - text_width - gap_x;
5809 y = workarea[3] - text_height - gap_y;
5813 x = workarea[2] / 2 - text_width / 2 - gap_x;
5814 y = workarea[3] - text_height - gap_y;
5819 y = workarea[3] / 2 - text_height / 2 - gap_y;
5823 x = workarea[2] - text_width - gap_x;
5824 y = workarea[3] / 2 - text_height / 2 - gap_y;
5828 case NONE: // Let the WM manage the window
5839 if (own_window && !fixed_pos) {
5842 text_start_x = border_margin + 1;
5843 text_start_y = border_margin + 1;
5844 window.x = x - border_margin - 1;
5845 window.y = y - border_margin - 1;
5849 /* If window size doesn't match to workarea's size,
5850 * then window probably includes panels (gnome).
5851 * Blah, doesn't work on KDE. */
5852 if (workarea[2] != window.width || workarea[3] != window.height) {
5864 static int cur_x, cur_y; /* current x and y for drawing */
5866 //draw_mode also without X11 because we only need to print to stdout with FG
5867 static int draw_mode; /* FG, BG or OUTLINE */
5869 static long current_color;
5871 static void text_size_updater(char *s)
5876 if ((output_methods & TO_X) == 0)
5878 /* get string widths and skip specials */
5881 if (*p == SPECIAL_CHAR) {
5883 w += get_string_width(s);
5886 if (specials[special_index].type == BAR
5887 || specials[special_index].type == GAUGE
5888 || specials[special_index].type == GRAPH) {
5889 w += specials[special_index].width;
5890 if (specials[special_index].height > last_font_height) {
5891 last_font_height = specials[special_index].height;
5892 last_font_height += font_height();
5894 } else if (specials[special_index].type == OFFSET) {
5895 if (specials[special_index].arg > 0) {
5896 w += specials[special_index].arg;
5898 } else if (specials[special_index].type == VOFFSET) {
5899 last_font_height += specials[special_index].arg;
5900 } else if (specials[special_index].type == GOTO) {
5901 if (specials[special_index].arg > cur_x) {
5902 w = (int) specials[special_index].arg;
5904 } else if (specials[special_index].type == TAB) {
5905 int start = specials[special_index].arg;
5906 int step = specials[special_index].width;
5908 if (!step || step < 0) {
5911 w += step - (cur_x - text_start_x - start) % step;
5912 } else if (specials[special_index].type == FONT) {
5913 selected_font = specials[special_index].font_added;
5914 if (font_height() > last_font_height) {
5915 last_font_height = font_height();
5924 w += get_string_width(s);
5925 if (w > text_width) {
5928 if (text_width > maximum_width && maximum_width) {
5929 text_width = maximum_width;
5932 text_height += last_font_height;
5933 last_font_height = font_height();
5936 static inline void set_foreground_color(long c)
5938 if ((output_methods & TO_X) == 0)
5941 XSetForeground(display, window.gc, c);
5945 static void draw_string(const char *s)
5947 int i, i2, pos, width_of_s;
5955 width_of_s = get_string_width(s);
5956 if ((output_methods & TO_STDOUT) && draw_mode == FG) {
5958 fflush(stdout); /* output immediately, don't buffer */
5960 if ((output_methods & TO_STDERR) && draw_mode == FG) {
5961 fprintf(stderr, "%s\n", s);
5962 fflush(stderr); /* output immediately, don't buffer */
5964 if ((output_methods & OVERWRITE_FILE) && draw_mode == FG && overwrite_fpointer) {
5965 fprintf(overwrite_fpointer, "%s\n", s);
5967 if ((output_methods & APPEND_FILE) && draw_mode == FG && append_fpointer) {
5968 fprintf(append_fpointer, "%s\n", s);
5970 memset(tmpstring1, 0, text_buffer_size);
5971 memset(tmpstring2, 0, text_buffer_size);
5972 strncpy(tmpstring1, s, text_buffer_size - 1);
5977 if (output_methods & TO_X) {
5978 max = ((text_width - width_of_s) / get_string_width(" "));
5981 /* This code looks for tabs in the text and coverts them to spaces.
5982 * The trick is getting the correct number of spaces, and not going
5983 * over the window's size without forcing the window larger. */
5984 for (i = 0; i < (int) text_buffer_size; i++) {
5985 if (tmpstring1[i] == '\t') {
5987 for (i2 = 0; i2 < (8 - (1 + pos) % 8) && added <= max; i2++) {
5988 /* guard against overrun */
5989 tmpstring2[MIN(pos + i2, (int)text_buffer_size - 1)] = ' ';
5994 /* guard against overrun */
5995 tmpstring2[MIN(pos, (int) text_buffer_size - 1)] = tmpstring1[i];
6000 if (output_methods & TO_X) {
6001 if (text_width == maximum_width) {
6002 /* this means the text is probably pushing the limit,
6003 * so we'll chop it */
6004 while (cur_x + get_string_width(tmpstring2) - text_start_x
6005 > maximum_width && strlen(tmpstring2) > 0) {
6006 tmpstring2[strlen(tmpstring2) - 1] = '\0';
6013 if (output_methods & TO_X) {
6019 c.pixel = current_color;
6020 XQueryColor(display, DefaultColormap(display, screen), &c);
6023 c2.color.red = c.red;
6024 c2.color.green = c.green;
6025 c2.color.blue = c.blue;
6026 c2.color.alpha = fonts[selected_font].font_alpha;
6028 XftDrawStringUtf8(window.xftdraw, &c2, fonts[selected_font].xftfont,
6029 cur_x, cur_y, (const XftChar8 *) s, strlen(s));
6031 XftDrawString8(window.xftdraw, &c2, fonts[selected_font].xftfont,
6032 cur_x, cur_y, (const XftChar8 *) s, strlen(s));
6037 XDrawString(display, window.drawable, window.gc, cur_x, cur_y, s,
6040 cur_x += width_of_s;
6043 memcpy(tmpstring1, s, text_buffer_size);
6046 static void draw_line(char *s)
6054 if ((output_methods & TO_X) == 0) {
6060 cur_x = text_start_x;
6061 cur_y += font_ascent();
6062 font_h = font_height();
6064 /* find specials and draw stuff */
6067 if (*p == SPECIAL_CHAR) {
6070 /* draw string before special */
6077 switch (specials[special_index].type) {
6078 case HORIZONTAL_LINE:
6080 int h = specials[special_index].height;
6081 int mid = font_ascent() / 2;
6083 w = text_start_x + text_width - cur_x;
6085 XSetLineAttributes(display, window.gc, h, LineSolid,
6086 CapButt, JoinMiter);
6087 XDrawLine(display, window.drawable, window.gc, cur_x,
6088 cur_y - mid / 2, cur_x + w, cur_y - mid / 2);
6094 int h = specials[special_index].height;
6095 int tmp_s = specials[special_index].arg;
6096 int mid = font_ascent() / 2;
6097 char ss[2] = { tmp_s, tmp_s };
6099 w = text_start_x + text_width - cur_x - 1;
6100 XSetLineAttributes(display, window.gc, h, LineOnOffDash,
6101 CapButt, JoinMiter);
6102 XSetDashes(display, window.gc, 0, ss, 2);
6103 XDrawLine(display, window.drawable, window.gc, cur_x,
6104 cur_y - mid / 2, cur_x + w, cur_y - mid / 2);
6110 int h, bar_usage, by;
6111 if (cur_x - text_start_x > maximum_width
6112 && maximum_width > 0) {
6115 h = specials[special_index].height;
6116 bar_usage = specials[special_index].arg;
6117 by = cur_y - (font_ascent() / 2) - 1;
6122 w = specials[special_index].width;
6124 w = text_start_x + text_width - cur_x - 1;
6130 XSetLineAttributes(display, window.gc, 1, LineSolid,
6131 CapButt, JoinMiter);
6133 XDrawRectangle(display, window.drawable, window.gc, cur_x,
6135 XFillRectangle(display, window.drawable, window.gc, cur_x,
6136 by, w * bar_usage / 255, h);
6144 case GAUGE: /* new GAUGE */
6147 unsigned long last_colour = current_color;
6148 float angle, px, py;
6151 if (cur_x - text_start_x > maximum_width
6152 && maximum_width > 0) {
6156 h = specials[special_index].height;
6157 by = cur_y - (font_ascent() / 2) - 1;
6162 w = specials[special_index].width;
6164 w = text_start_x + text_width - cur_x - 1;
6170 XSetLineAttributes(display, window.gc, 1, LineSolid,
6171 CapButt, JoinMiter);
6173 XDrawArc(display, window.drawable, window.gc,
6174 cur_x, by, w, h * 2, 0, 180*64);
6177 usage = specials[special_index].arg;
6178 angle = (M_PI)*(float)(usage)/255.;
6179 px = (float)(cur_x+(w/2.))-(float)(w/2.)*cos(angle);
6180 py = (float)(by+(h))-(float)(h)*sin(angle);
6182 XDrawLine(display, window.drawable, window.gc,
6183 cur_x + (w/2.), by+(h), (int)(px), (int)(py));
6191 set_foreground_color(last_colour);
6199 int h, by, i = 0, j = 0;
6201 unsigned long last_colour = current_color;
6202 unsigned long *tmpcolour = 0;
6203 if (cur_x - text_start_x > maximum_width
6204 && maximum_width > 0) {
6207 h = specials[special_index].height;
6208 by = cur_y - (font_ascent() / 2) - 1;
6213 w = specials[special_index].width;
6215 w = text_start_x + text_width - cur_x - 1;
6220 if (draw_graph_borders) {
6221 XSetLineAttributes(display, window.gc, 1, LineSolid,
6222 CapButt, JoinMiter);
6223 XDrawRectangle(display, window.drawable, window.gc,
6226 XSetLineAttributes(display, window.gc, 1, LineSolid,
6227 CapButt, JoinMiter);
6229 if (specials[special_index].last_colour != 0
6230 || specials[special_index].first_colour != 0) {
6231 tmpcolour = do_gradient(w - 1, specials[special_index].last_colour, specials[special_index].first_colour);
6234 for (i = w - 2; i > -1; i--) {
6235 if (specials[special_index].last_colour != 0
6236 || specials[special_index].first_colour != 0) {
6237 if (specials[special_index].tempgrad) {
6240 (int)((float)(w - 2) - specials[special_index].graph[j] *
6241 (w - 2) / (float)specials[special_index].graph_scale)
6245 (int)((float)(w - 2) - specials[special_index].graph[j] *
6246 (w - 2) / (float)specials[special_index].graph_scale)
6249 if (specials[special_index].graph[j] == specials[special_index].graph_scale) {
6251 (int)((float)(w - 2) - specials[special_index].graph[j] *
6252 (w - 2) / (float)specials[special_index].graph_scale)
6256 #endif /* DEBUG_lol */
6257 XSetForeground(display, window.gc, tmpcolour[
6258 (int)((float)(w - 2) - specials[special_index].graph[j] *
6259 (w - 2) / (float)specials[special_index].graph_scale)
6262 XSetForeground(display, window.gc, tmpcolour[colour_idx++]);
6265 /* this is mugfugly, but it works */
6266 XDrawLine(display, window.drawable, window.gc,
6267 cur_x + i + 1, by + h, cur_x + i + 1,
6268 round_to_int((double)by + h - specials[special_index].graph[j] *
6269 (h - 1) / specials[special_index].graph_scale));
6270 if ((w - i) / ((float) (w - 2) /
6271 (specials[special_index].graph_width)) > j
6272 && j < MAX_GRAPH_DEPTH - 3) {
6276 if (tmpcolour) free(tmpcolour);
6281 /* if (draw_mode == BG) {
6282 set_foreground_color(default_bg_color);
6283 } else if (draw_mode == OUTLINE) {
6284 set_foreground_color(default_out_color);
6286 set_foreground_color(default_fg_color);
6288 if (show_graph_range) {
6291 unsigned short int seconds = update_interval * w;
6296 unsigned short int timeunits;
6298 timeunits = seconds / 86400; seconds %= 86400;
6299 if (timeunits > 0) {
6300 asprintf(&tmp_day_str, "%dd", timeunits);
6302 tmp_day_str = strdup("");
6304 timeunits = seconds / 3600; seconds %= 3600;
6305 if (timeunits > 0) {
6306 asprintf(&tmp_hour_str, "%dh", timeunits);
6308 tmp_hour_str = strdup("");
6310 timeunits = seconds / 60; seconds %= 60;
6311 if (timeunits > 0) {
6312 asprintf(&tmp_min_str, "%dm", timeunits);
6314 tmp_min_str = strdup("");
6317 asprintf(&tmp_sec_str, "%ds", seconds);
6319 tmp_sec_str = strdup("");
6321 asprintf(&tmp_str, "%s%s%s%s", tmp_day_str, tmp_hour_str, tmp_min_str, tmp_sec_str);
6322 free(tmp_day_str); free(tmp_hour_str); free(tmp_min_str); free(tmp_sec_str);
6324 asprintf(&tmp_str, "Range not possible"); // should never happen, but better safe then sorry
6326 cur_x += (w / 2) - (font_ascent() * (strlen(tmp_str) / 2));
6327 cur_y += font_h / 2;
6328 draw_string(tmp_str);
6334 if (show_graph_scale && (specials[special_index].show_scale == 1)) {
6337 cur_x += font_ascent() / 2;
6338 cur_y += font_h / 2;
6340 calloc(log10(floor(specials[special_index].graph_scale)) + 4,
6342 sprintf(tmp_str, "%.1f", specials[special_index].graph_scale);
6343 draw_string(tmp_str);
6349 set_foreground_color(last_colour);
6355 int old = font_ascent();
6357 cur_y -= font_ascent();
6358 selected_font = specials[special_index].font_added;
6359 if (cur_y + font_ascent() < cur_y + old) {
6362 cur_y += font_ascent();
6365 font_h = font_height();
6369 if (draw_mode == FG) {
6370 set_foreground_color(specials[special_index].arg);
6375 if (draw_mode == BG) {
6376 set_foreground_color(specials[special_index].arg);
6381 if (draw_mode == OUTLINE) {
6382 set_foreground_color(specials[special_index].arg);
6387 w += specials[special_index].arg;
6391 cur_y += specials[special_index].arg;
6395 if (specials[special_index].arg >= 0) {
6396 cur_x = (int) specials[special_index].arg;
6402 int start = specials[special_index].arg;
6403 int step = specials[special_index].width;
6405 if (!step || step < 0) {
6408 w = step - (cur_x - text_start_x - start) % step;
6414 /* TODO: add back in "+ border_margin" to the end of
6416 int pos_x = text_start_x + text_width -
6417 get_string_width_special(s);
6419 /* printf("pos_x %i text_start_x %i text_width %i cur_x %i "
6420 "get_string_width(p) %i gap_x %i "
6421 "specials[special_index].arg %i border_margin %i "
6422 "border_width %i\n", pos_x, text_start_x, text_width,
6423 cur_x, get_string_width_special(s), gap_x,
6424 specials[special_index].arg, border_margin,
6426 if (pos_x > specials[special_index].arg && pos_x > cur_x) {
6427 cur_x = pos_x - specials[special_index].arg;
6434 int pos_x = (text_width) / 2 - get_string_width_special(s) /
6435 2 - (cur_x - text_start_x);
6436 /* int pos_x = text_start_x + text_width / 2 -
6437 get_string_width_special(s) / 2; */
6439 /* printf("pos_x %i text_start_x %i text_width %i cur_x %i "
6440 "get_string_width(p) %i gap_x %i "
6441 "specials[special_index].arg %i\n", pos_x, text_start_x,
6442 text_width, cur_x, get_string_width(s), gap_x,
6443 specials[special_index].arg); */
6444 if (pos_x > specials[special_index].arg) {
6445 w = pos_x - specials[special_index].arg;
6459 if (cur_y_add > 0) {
6463 cur_y += font_descent();
6468 static void draw_text(void)
6471 if (output_methods & TO_X) {
6472 cur_y = text_start_y;
6475 if (draw_borders && border_width > 0) {
6476 unsigned int b = (border_width + 1) / 2;
6478 if (stippled_borders) {
6479 char ss[2] = { stippled_borders, stippled_borders };
6480 XSetLineAttributes(display, window.gc, border_width, LineOnOffDash,
6481 CapButt, JoinMiter);
6482 XSetDashes(display, window.gc, 0, ss, 2);
6484 XSetLineAttributes(display, window.gc, border_width, LineSolid,
6485 CapButt, JoinMiter);
6488 XDrawRectangle(display, window.drawable, window.gc,
6489 text_start_x - border_margin + b, text_start_y - border_margin + b,
6490 text_width + border_margin * 2 - 1 - b * 2,
6491 text_height + border_margin * 2 - 1 - b * 2);
6498 for_each_line(text_buffer, draw_line);
6501 static void draw_stuff(void)
6503 if (overwrite_file) {
6504 overwrite_fpointer = fopen(overwrite_file, "w");
6505 if(!overwrite_fpointer)
6506 ERR("Can't overwrite '%s' anymore", overwrite_file);
6509 append_fpointer = fopen(append_file, "a");
6510 if(!append_fpointer)
6511 ERR("Can't append '%s' anymore", append_file);
6514 if (output_methods & TO_X) {
6516 if (draw_shades && !draw_outline) {
6519 set_foreground_color(default_bg_color);
6530 for (i = -1; i < 2; i++) {
6531 for (j = -1; j < 2; j++) {
6532 if (i == 0 && j == 0) {
6537 set_foreground_color(default_out_color);
6538 draw_mode = OUTLINE;
6546 set_foreground_color(default_fg_color);
6552 if (output_methods & TO_X) {
6557 swap.swap_window = window.window;
6558 swap.swap_action = XdbeBackground;
6559 XdbeSwapBuffers(display, &swap, 1);
6564 if(overwrite_fpointer) {
6565 fclose(overwrite_fpointer);
6566 overwrite_fpointer = 0;
6568 if(append_fpointer) {
6569 fclose(append_fpointer);
6570 append_fpointer = 0;
6575 static void clear_text(int exposures)
6579 /* The swap action is XdbeBackground, which clears */
6583 if (display && window.window) { // make sure these are !null
6584 /* there is some extra space for borders and outlines */
6585 XClearArea(display, window.window, text_start_x - border_margin - 1,
6586 text_start_y - border_margin - 1,
6587 text_width + border_margin * 2 + 2,
6588 text_height + border_margin * 2 + 2, exposures ? True : 0);
6593 static int need_to_update;
6595 /* update_text() generates new text and clears old text area */
6596 static void update_text(void)
6603 if (output_methods & TO_X)
6609 #ifdef HAVE_SYS_INOTIFY_H
6613 static void main_loop(void)
6616 #ifdef SIGNAL_BLOCKING
6617 sigset_t newmask, oldmask;
6620 #ifdef HAVE_SYS_INOTIFY_H
6621 int inotify_config_wd = 0;
6622 #define INOTIFY_EVENT_SIZE (sizeof(struct inotify_event))
6623 #define INOTIFY_BUF_LEN (20 * (INOTIFY_EVENT_SIZE + 16))
6624 char inotify_buff[INOTIFY_BUF_LEN];
6625 #endif /* HAVE_SYS_INOTIFY_H */
6628 #ifdef SIGNAL_BLOCKING
6629 sigemptyset(&newmask);
6630 sigaddset(&newmask, SIGINT);
6631 sigaddset(&newmask, SIGTERM);
6632 sigaddset(&newmask, SIGUSR1);
6635 next_update_time = last_update_time = get_time();
6637 while (terminate == 0 && (total_run_times == 0 || info.looped < total_run_times)) {
6640 #ifdef SIGNAL_BLOCKING
6641 /* block signals. we will inspect for pending signals later */
6642 if (sigprocmask(SIG_BLOCK, &newmask, &oldmask) < 0) {
6643 CRIT_ERR("unable to sigprocmask()");
6648 if (output_methods & TO_X) {
6651 /* wait for X event or timeout */
6653 if (!XPending(display)) {
6657 t = next_update_time - get_time();
6661 } else if (t > update_interval) {
6662 t = update_interval;
6665 tv.tv_sec = (long) t;
6666 tv.tv_usec = (long) (t * 1000000) % 1000000;
6668 FD_SET(ConnectionNumber(display), &fdsr);
6670 s = select(ConnectionNumber(display) + 1, &fdsr, 0, 0, &tv);
6672 if (errno != EINTR) {
6673 ERR("can't select(): %s", strerror(errno));
6683 if (need_to_update) {
6685 int wx = window.x, wy = window.y;
6693 /* resize window if it isn't right size */
6695 && (text_width + border_margin * 2 + 1 != window.width
6696 || text_height + border_margin * 2 + 1 != window.height)) {
6697 window.width = text_width + border_margin * 2 + 1;
6698 window.height = text_height + border_margin * 2 + 1;
6699 XResizeWindow(display, window.window, window.width,
6702 set_transparent_background(window.window);
6706 /* move window if it isn't in right position */
6707 if (!fixed_pos && (window.x != wx || window.y != wy)) {
6708 XMoveWindow(display, window.window, window.x, window.y);
6719 r.x = text_start_x - border_margin;
6720 r.y = text_start_y - border_margin;
6721 r.width = text_width + border_margin * 2;
6722 r.height = text_height + border_margin * 2;
6723 XUnionRectWithRegion(&r, x11_stuff.region, x11_stuff.region);
6728 /* handle X events */
6729 while (XPending(display)) {
6732 XNextEvent(display, &ev);
6739 r.width = ev.xexpose.width;
6740 r.height = ev.xexpose.height;
6741 XUnionRectWithRegion(&r, x11_stuff.region, x11_stuff.region);
6746 case ReparentNotify:
6747 /* set background to ParentRelative for all parents */
6749 set_transparent_background(window.window);
6753 case ConfigureNotify:
6755 /* if window size isn't what expected, set fixed size */
6756 if (ev.xconfigure.width != window.width
6757 || ev.xconfigure.height != window.height) {
6758 if (window.width != 0 && window.height != 0) {
6762 /* clear old stuff before screwing up
6767 XWindowAttributes attrs;
6768 if (XGetWindowAttributes(display,
6769 window.window, &attrs)) {
6770 window.width = attrs.width;
6771 window.height = attrs.height;
6775 text_width = window.width - border_margin * 2 - 1;
6776 text_height = window.height - border_margin * 2 - 1;
6777 if (text_width > maximum_width
6778 && maximum_width > 0) {
6779 text_width = maximum_width;
6783 /* if position isn't what expected, set fixed pos
6784 * total_updates avoids setting fixed_pos when window
6785 * is set to weird locations when started */
6786 /* // this is broken
6787 if (total_updates >= 2 && !fixed_pos
6788 && (window.x != ev.xconfigure.x
6789 || window.y != ev.xconfigure.y)
6790 && (ev.xconfigure.x != 0
6791 || ev.xconfigure.y != 0)) {
6800 /* if an ordinary window with decorations */
6801 if ((window.type == TYPE_NORMAL)
6802 && (!TEST_HINT(window.hints,
6803 HINT_UNDECORATED))) {
6804 /* allow conky to hold input focus. */
6807 /* forward the click to the desktop window */
6808 XUngrabPointer(display, ev.xbutton.time);
6809 ev.xbutton.window = window.desktop;
6810 ev.xbutton.x = ev.xbutton.x_root;
6811 ev.xbutton.y = ev.xbutton.y_root;
6812 XSendEvent(display, ev.xbutton.window, False,
6813 ButtonPressMask, &ev);
6814 XSetInputFocus(display, ev.xbutton.window,
6815 RevertToParent, ev.xbutton.time);
6822 /* if an ordinary window with decorations */
6823 if ((window.type == TYPE_NORMAL)
6824 && (!TEST_HINT(window.hints,
6825 HINT_UNDECORATED))) {
6826 /* allow conky to hold input focus. */
6829 /* forward the release to the desktop window */
6830 ev.xbutton.window = window.desktop;
6831 ev.xbutton.x = ev.xbutton.x_root;
6832 ev.xbutton.y = ev.xbutton.y_root;
6833 XSendEvent(display, ev.xbutton.window, False,
6834 ButtonReleaseMask, &ev);
6843 if (ev.type == x11_stuff.event_base + XDamageNotify) {
6844 XDamageNotifyEvent *dev = (XDamageNotifyEvent *) &ev;
6846 XFixesSetRegion(display, x11_stuff.part, &dev->area, 1);
6847 XFixesUnionRegion(display, x11_stuff.region2, x11_stuff.region2, x11_stuff.part);
6849 #endif /* HAVE_XDAMAGE */
6855 XDamageSubtract(display, x11_stuff.damage, x11_stuff.region2, None);
6856 XFixesSetRegion(display, x11_stuff.region2, 0, 0);
6857 #endif /* HAVE_XDAMAGE */
6859 /* XDBE doesn't seem to provide a way to clear the back buffer without
6860 * interfering with the front buffer, other than passing XdbeBackground
6861 * to XdbeSwapBuffers. That means that if we're using XDBE, we need to
6862 * redraw the text even if it wasn't part of the exposed area. OTOH,
6863 * if we're not going to call draw_stuff at all, then no swap happens
6864 * and we can safely do nothing. */
6866 if (!XEmptyRegion(x11_stuff.region)) {
6871 r.x = text_start_x - border_margin;
6872 r.y = text_start_y - border_margin;
6873 r.width = text_width + border_margin * 2;
6874 r.height = text_height + border_margin * 2;
6875 XUnionRectWithRegion(&r, x11_stuff.region, x11_stuff.region);
6878 XSetRegion(display, window.gc, x11_stuff.region);
6881 XftDrawSetClip(window.xftdraw, x11_stuff.region);
6885 cimlib_render(text_start_x, text_start_y, window.width, window.height);
6888 XDestroyRegion(x11_stuff.region);
6889 x11_stuff.region = XCreateRegion();
6893 t = (next_update_time - get_time()) * 1000000;
6894 if(t > 0) usleep((useconds_t)t);
6901 #ifdef SIGNAL_BLOCKING
6902 /* unblock signals of interest and let handler fly */
6903 if (sigprocmask(SIG_SETMASK, &oldmask, NULL) < 0) {
6904 CRIT_ERR("unable to sigprocmask()");
6908 switch (g_signal_pending) {
6911 ERR("received SIGHUP or SIGUSR1. reloading the config file.");
6916 ERR("received SIGINT or SIGTERM to terminate. bye!");
6920 if (output_methods & TO_X) {
6921 XDestroyRegion(x11_stuff.region);
6922 x11_stuff.region = NULL;
6924 XDamageDestroy(display, x11_stuff.damage);
6925 XFixesDestroyRegion(display, x11_stuff.region2);
6926 XFixesDestroyRegion(display, x11_stuff.part);
6927 #endif /* HAVE_XDAMAGE */
6933 if(overwrite_file) {
6934 free(overwrite_file);
6943 /* Reaching here means someone set a signal
6944 * (SIGXXXX, signal_handler), but didn't write any code
6946 * If you don't want to handle a signal, don't set a handler on
6947 * it in the first place. */
6948 if (g_signal_pending) {
6949 ERR("ignoring signal (%d)", g_signal_pending);
6953 #ifdef HAVE_SYS_INOTIFY_H
6954 if (inotify_fd && !inotify_config_wd) {
6955 inotify_config_wd = inotify_add_watch(inotify_fd,
6959 if (inotify_fd && inotify_config_wd) {
6960 int len = 0, idx = 0;
6962 struct timeval time_to_wait;
6964 FD_ZERO (&descriptors);
6965 FD_SET(inotify_fd, &descriptors);
6967 time_to_wait.tv_sec = time_to_wait.tv_usec = 0;
6969 select(inotify_fd + 1, &descriptors, NULL, NULL, &time_to_wait);
6970 if (FD_ISSET(inotify_fd, &descriptors)) {
6971 /* process inotify events */
6972 len = read(inotify_fd, inotify_buff, INOTIFY_BUF_LEN);
6973 while (len > 0 && idx < len) {
6974 struct inotify_event *ev = (struct inotify_event *) &inotify_buff[idx];
6975 if (ev->wd == inotify_config_wd && (ev->mask & IN_MODIFY || ev->mask & IN_IGNORED)) {
6976 /* current_config should be reloaded */
6977 ERR("'%s' modified, reloading...", current_config);
6979 if (ev->mask & IN_IGNORED) {
6980 /* for some reason we get IN_IGNORED here
6981 * sometimes, so we need to re-add the watch */
6982 inotify_config_wd = inotify_add_watch(inotify_fd,
6989 llua_inotify_query(ev->wd, ev->mask);
6991 #endif /* HAVE_LUA */
6992 idx += INOTIFY_EVENT_SIZE + ev->len;
6996 #endif /* HAVE_SYS_INOTIFY_H */
6998 g_signal_pending = 0;
7001 #ifdef HAVE_SYS_INOTIFY_H
7003 inotify_rm_watch(inotify_fd, inotify_config_wd);
7005 inotify_fd = inotify_config_wd = 0;
7007 #endif /* HAVE_SYS_INOTIFY_H */
7010 X11_destroy_window();
7014 static void load_config_file(const char *);
7015 static void load_config_file_x11(const char *);
7017 /* reload the config file */
7018 static void reload_config(void)
7020 timed_thread_destroy_registered_threads();
7022 if (info.cpu_usage) {
7023 free(info.cpu_usage);
7024 info.cpu_usage = NULL;
7035 #ifdef TCP_PORT_MONITOR
7036 tcp_portmon_clear();
7041 #endif /* HAVE_LUA */
7044 X11_destroy_window();
7047 if (current_config) {
7049 load_config_file(current_config);
7050 load_config_file_x11(current_config);
7052 /* re-init specials array */
7053 if ((specials = realloc((void *) specials,
7054 sizeof(struct special_t) * max_specials)) == 0) {
7055 ERR("failed to realloc specials array");
7060 if (output_methods & TO_X) {
7061 X11_initialisation();
7064 extract_variable_text(global_text);
7070 tmpstring1 = malloc(text_buffer_size);
7071 memset(tmpstring1, 0, text_buffer_size);
7075 tmpstring2 = malloc(text_buffer_size);
7076 memset(tmpstring2, 0, text_buffer_size);
7080 text_buffer = malloc(max_user_text);
7081 memset(text_buffer, 0, max_user_text);
7084 X11_create_window();
7089 static void clean_up(void)
7092 timed_thread_destroy_registered_threads();
7094 if (info.cpu_usage) {
7095 free(info.cpu_usage);
7096 info.cpu_usage = NULL;
7099 if (output_methods & TO_X) {
7102 XdbeDeallocateBackBufferName(display, window.back_buffer);
7107 XDestroyWindow(display, window.window);
7108 XClearWindow(display, RootWindow(display, screen));
7113 XClearWindow(display, RootWindow(display, screen));
7118 XFreeGC(display, window.gc);
7125 #pragma omp parallel for
7126 #endif /* HAVE_OPENMP */
7127 for (i = 0; i < MAX_TEMPLATES; i++) {
7134 free_text_objects(&global_root_object, 0);
7153 free(current_config);
7155 #ifdef TCP_PORT_MONITOR
7156 tcp_portmon_clear();
7163 #endif /* HAVE_LUA */
7166 for (i = 0; i < special_count; i++) {
7167 if (specials[i].type == GRAPH) {
7168 free(specials[i].graph);
7175 clear_diskio_stats();
7178 static int string_to_bool(const char *s)
7181 // Assumes an option without a true/false means true
7183 } else if (strcasecmp(s, "yes") == EQUAL) {
7185 } else if (strcasecmp(s, "true") == EQUAL) {
7187 } else if (strcasecmp(s, "1") == EQUAL) {
7194 static enum alignment string_to_alignment(const char *s)
7196 if (strcasecmp(s, "top_left") == EQUAL) {
7198 } else if (strcasecmp(s, "top_right") == EQUAL) {
7200 } else if (strcasecmp(s, "top_middle") == EQUAL) {
7202 } else if (strcasecmp(s, "bottom_left") == EQUAL) {
7204 } else if (strcasecmp(s, "bottom_right") == EQUAL) {
7205 return BOTTOM_RIGHT;
7206 } else if (strcasecmp(s, "bottom_middle") == EQUAL) {
7207 return BOTTOM_MIDDLE;
7208 } else if (strcasecmp(s, "middle_left") == EQUAL) {
7210 } else if (strcasecmp(s, "middle_right") == EQUAL) {
7211 return MIDDLE_RIGHT;
7212 } else if (strcasecmp(s, "tl") == EQUAL) {
7214 } else if (strcasecmp(s, "tr") == EQUAL) {
7216 } else if (strcasecmp(s, "tm") == EQUAL) {
7218 } else if (strcasecmp(s, "bl") == EQUAL) {
7220 } else if (strcasecmp(s, "br") == EQUAL) {
7221 return BOTTOM_RIGHT;
7222 } else if (strcasecmp(s, "bm") == EQUAL) {
7223 return BOTTOM_MIDDLE;
7224 } else if (strcasecmp(s, "ml") == EQUAL) {
7226 } else if (strcasecmp(s, "mr") == EQUAL) {
7227 return MIDDLE_RIGHT;
7228 } else if (strcasecmp(s, "none") == EQUAL) {
7236 static void set_default_configurations_for_x(void)
7238 default_fg_color = WhitePixel(display, screen);
7239 default_bg_color = BlackPixel(display, screen);
7240 default_out_color = BlackPixel(display, screen);
7241 color0 = default_fg_color;
7242 color1 = default_fg_color;
7243 color2 = default_fg_color;
7244 color3 = default_fg_color;
7245 color4 = default_fg_color;
7246 color5 = default_fg_color;
7247 color6 = default_fg_color;
7248 color7 = default_fg_color;
7249 color8 = default_fg_color;
7250 color9 = default_fg_color;
7254 static void set_default_configurations(void)
7258 fork_to_background = 0;
7259 total_run_times = 0;
7260 info.cpu_avg_samples = 2;
7261 info.net_avg_samples = 2;
7262 info.diskio_avg_samples = 2;
7270 mpd_set_host("localhost");
7271 mpd_set_port("6600");
7274 info.xmms2.artist = NULL;
7275 info.xmms2.album = NULL;
7276 info.xmms2.title = NULL;
7277 info.xmms2.genre = NULL;
7278 info.xmms2.comment = NULL;
7279 info.xmms2.url = NULL;
7280 info.xmms2.status = NULL;
7281 info.xmms2.playlist = NULL;
7283 use_spacer = NO_SPACER;
7285 output_methods = TO_X;
7287 output_methods = TO_STDOUT;
7290 show_graph_scale = 0;
7291 show_graph_range = 0;
7294 draw_graph_borders = 1;
7296 set_first_font("6x10");
7304 window.type = TYPE_NORMAL;
7306 strcpy(window.class_name, PACKAGE_NAME);
7307 sprintf(window.title, PACKAGE_NAME" (%s)", info.uname_s.nodename);
7309 stippled_borders = 0;
7312 text_alignment = BOTTOM_LEFT;
7313 info.x11.monitor.number = 1;
7314 info.x11.monitor.current = 0;
7318 #pragma omp parallel for
7319 #endif /* HAVE_OPENMP */
7320 for (i = 0; i < MAX_TEMPLATES; i++) {
7321 template[i] = strdup("");
7324 free(current_mail_spool);
7328 variable_substitute(MAIL_FILE, buf, 256);
7329 if (buf[0] != '\0') {
7330 current_mail_spool = strndup(buf, text_buffer_size);
7335 update_interval = 3.0;
7336 info.music_player_interval = 1.0;
7337 stuff_in_upper_case = 0;
7338 info.users.number = 1;
7340 #ifdef TCP_PORT_MONITOR
7341 /* set default connection limit */
7342 tcp_portmon_set_max_connections(0);
7346 /* returns 1 if you can overwrite or create the file at 'path' */
7347 static _Bool overwrite_works(const char *path)
7351 if (!(filepointer = fopen(path, "w")))
7353 fclose(filepointer);
7357 /* returns 1 if you can append or create the file at 'path' */
7358 static _Bool append_works(const char *path)
7362 if (!(filepointer = fopen(path, "a")))
7364 fclose(filepointer);
7369 static void X11_initialisation(void)
7371 if (x_initialised == YES) return;
7372 output_methods |= TO_X;
7374 set_default_configurations_for_x();
7375 x_initialised = YES;
7378 static void X11_destroy_window(void)
7380 /* this function only exists for the sake of consistency */
7381 if (output_methods & TO_X) {
7383 XDamageDestroy(display, x11_stuff.damage);
7384 XFixesDestroyRegion(display, x11_stuff.region2);
7385 XFixesDestroyRegion(display, x11_stuff.part);
7386 if (x11_stuff.region) {
7387 XDestroyRegion(x11_stuff.region);
7389 x11_stuff.region = NULL;
7390 #endif /* HAVE_XDAMAGE */
7395 static char **xargv = 0;
7396 static int xargc = 0;
7398 static void X11_create_window(void)
7400 if (output_methods & TO_X) {
7402 init_window(own_window, text_width + border_margin * 2 + 1,
7403 text_height + border_margin * 2 + 1, set_transparent, background_colour,
7405 #else /* OWN_WINDOW */
7406 init_window(0, text_width + border_margin * 2 + 1,
7407 text_height + border_margin * 2 + 1, set_transparent, 0,
7409 #endif /* OWN_WINDOW */
7413 update_text_area(); /* to position text/window on screen */
7416 if (own_window && !fixed_pos) {
7417 XMoveWindow(display, window.window, window.x, window.y);
7420 set_transparent_background(window.window);
7429 x11_stuff.region = XCreateRegion();
7431 if (!XDamageQueryExtension(display, &x11_stuff.event_base, &x11_stuff.error_base)) {
7432 ERR("Xdamage extension unavailable");
7434 x11_stuff.damage = XDamageCreate(display, window.window, XDamageReportNonEmpty);
7435 x11_stuff.region2 = XFixesCreateRegionFromWindow(display, window.window, 0);
7436 x11_stuff.part = XFixesCreateRegionFromWindow(display, window.window, 0);
7437 #endif /* HAVE_XDAMAGE */
7440 update_text_area(); /* to get initial size of the window */
7445 #define CONF_ERR ERR("%s: %d: config file error", f, line)
7446 #define CONF_ERR2(a) ERR("%s: %d: config file error: %s", f, line, a)
7447 #define CONF2(a) if (strcasecmp(name, a) == 0)
7448 #define CONF(a) else CONF2(a)
7449 #define CONF3(a, b) else if (strcasecmp(name, a) == 0 \
7450 || strcasecmp(name, b) == 0)
7451 #define CONF_CONTINUE 1
7452 #define CONF_BREAK 2
7453 #define CONF_BUFF_SIZE 512
7455 static FILE *open_config_file(const char *f)
7457 #ifdef CONFIG_OUTPUT
7458 if (!strcmp(f, "==builtin==")) {
7459 #ifdef HAVE_FOPENCOOKIE
7460 return fopencookie(NULL, "r", conf_cookie);
7461 #endif /* HAVE_FOPENCOOKIE */
7463 #endif /* CONFIG_OUTPUT */
7464 return fopen(f, "r");
7467 static int do_config_step(int *line, FILE *fp, char *buf, char **name, char **value)
7471 if (fgets(buf, CONF_BUFF_SIZE, fp) == NULL) {
7474 remove_comments(buf);
7479 while (*p && isspace((int) *p)) {
7483 return CONF_CONTINUE; /* empty line */
7490 while (*p2 && !isspace((int) *p2)) {
7494 *p2 = '\0'; /* break at name's end */
7501 while (*p && isspace((int) *p)) {
7507 p2 = *value + strlen(*value);
7508 while (isspace((int) *(p2 - 1))) {
7517 static void load_config_file(const char *f)
7522 set_default_configurations();
7523 fp = open_config_file(f);
7527 DBGP("reading contents from config file '%s'", f);
7530 char buff[CONF_BUFF_SIZE], *name, *value;
7531 int ret = do_config_step(&line, fp, buff, &name, &value);
7532 if (ret == CONF_BREAK) {
7534 } else if (ret == CONF_CONTINUE) {
7540 /* don't listen if X is already initialised or
7541 * if we already know we don't want it */
7542 if(x_initialised == NO) {
7543 if (string_to_bool(value)) {
7544 output_methods &= TO_X;
7546 output_methods &= ~TO_X;
7547 x_initialised = NEVER;
7552 if (!value || x_initialised == YES) {
7557 disp = strdup(value);
7561 if (window.type == TYPE_DOCK)
7564 int a = string_to_alignment(value);
7575 CONF("background") {
7576 fork_to_background = string_to_bool(value);
7579 CONF2("background") {
7580 fork_to_background = string_to_bool(value);
7584 CONF("show_graph_scale") {
7585 show_graph_scale = string_to_bool(value);
7587 CONF("show_graph_range") {
7588 show_graph_range = string_to_bool(value);
7590 CONF("border_margin") {
7592 border_margin = strtol(value, 0, 0);
7597 CONF("border_width") {
7599 border_width = strtol(value, 0, 0);
7605 #define TEMPLATE_CONF(n) \
7606 CONF("template"#n) { \
7608 free(template[n]); \
7609 template[n] = strdup(value); \
7626 info.mail = parse_mail_args(IMAP_TYPE, value);
7633 info.mail = parse_mail_args(POP3_TYPE, value);
7638 CONF("default_bar_size") {
7641 if (sscanf(value, "%d %d", &default_bar_width, &default_bar_height) != 2) {
7648 CONF_ERR2("default_bar_size takes 2 integer arguments (ie. 'default_bar_size 0 6')")
7652 CONF("default_graph_size") {
7655 if (sscanf(value, "%d %d", &default_graph_width, &default_graph_height) != 2) {
7662 CONF_ERR2("default_graph_size takes 2 integer arguments (ie. 'default_graph_size 0 6')")
7665 CONF("default_gauge_size") {
7668 if (sscanf(value, "%d %d", &default_gauge_width, &default_gauge_height) != 2) {
7675 CONF_ERR2("default_gauge_size takes 2 integer arguments (ie. 'default_gauge_size 0 6')")
7682 mpd_set_host(value);
7688 if (value && mpd_set_port(value)) {
7692 CONF("mpd_password") {
7694 mpd_set_password(value);
7700 CONF("music_player_interval") {
7702 info.music_player_interval = strtod(value, 0);
7708 CONF("sensor_device") {
7710 sensor_device = strtol(value, 0, 0);
7716 CONF("cpu_avg_samples") {
7718 cpu_avg_samples = strtol(value, 0, 0);
7719 if (cpu_avg_samples < 1 || cpu_avg_samples > 14) {
7722 info.cpu_avg_samples = cpu_avg_samples;
7728 CONF("net_avg_samples") {
7730 net_avg_samples = strtol(value, 0, 0);
7731 if (net_avg_samples < 1 || net_avg_samples > 14) {
7734 info.net_avg_samples = net_avg_samples;
7740 CONF("diskio_avg_samples") {
7742 diskio_avg_samples = strtol(value, 0, 0);
7743 if (diskio_avg_samples < 1 || diskio_avg_samples > 14) {
7746 info.diskio_avg_samples = diskio_avg_samples;
7754 CONF("double_buffer") {
7755 use_xdbe = string_to_bool(value);
7759 CONF("override_utf8_locale") {
7760 utf8_mode = string_to_bool(value);
7762 CONF("draw_borders") {
7763 draw_borders = string_to_bool(value);
7765 CONF("draw_graph_borders") {
7766 draw_graph_borders = string_to_bool(value);
7768 CONF("draw_shades") {
7769 draw_shades = string_to_bool(value);
7771 CONF("draw_outline") {
7772 draw_outline = string_to_bool(value);
7775 CONF("out_to_console") {
7776 if(string_to_bool(value))
7777 output_methods |= TO_STDOUT;
7779 CONF("out_to_stderr") {
7780 if(string_to_bool(value))
7781 output_methods |= TO_STDERR;
7783 CONF("overwrite_file") {
7784 if(overwrite_file) {
7785 free(overwrite_file);
7788 if(overwrite_works(value)) {
7789 overwrite_file = strdup(value);
7790 output_methods |= OVERWRITE_FILE;
7792 ERR("overwrite_file won't be able to create/overwrite '%s'", value);
7794 CONF("append_file") {
7799 if(append_works(value)) {
7800 append_file = strdup(value);
7801 output_methods |= APPEND_FILE;
7803 ERR("append_file won't be able to create/append '%s'", value);
7805 CONF("use_spacer") {
7807 if (strcasecmp(value, "left") == EQUAL) {
7808 use_spacer = LEFT_SPACER;
7809 } else if (strcasecmp(value, "right") == EQUAL) {
7810 use_spacer = RIGHT_SPACER;
7811 } else if (strcasecmp(value, "none") == EQUAL) {
7812 use_spacer = NO_SPACER;
7814 use_spacer = string_to_bool(value);
7815 ERR("use_spacer should have an argument of left, right, or"
7816 " none. '%s' seems to be some form of '%s', so"
7817 " defaulting to %s.", value,
7818 use_spacer ? "true" : "false",
7819 use_spacer ? "right" : "none");
7821 use_spacer = RIGHT_SPACER;
7823 use_spacer = NO_SPACER;
7827 ERR("use_spacer should have an argument. Defaulting to right.");
7828 use_spacer = RIGHT_SPACER;
7834 use_xft = string_to_bool(value);
7838 set_first_font(value);
7842 if (value && font_count >= 0) {
7843 fonts[0].font_alpha = atof(value) * 65535.0;
7850 if (string_to_bool(value)) {
7851 ERR("Xft not enabled");
7855 /* xftfont silently ignored when no Xft */
7858 /* xftalpha is silently ignored when no Xft */
7863 set_first_font(value);
7871 gap_x = atoi(value);
7878 gap_y = atoi(value);
7884 CONF("mail_spool") {
7888 variable_substitute(value, buffer, 256);
7890 if (buffer[0] != '\0') {
7891 if (current_mail_spool) {
7892 free(current_mail_spool);
7894 current_mail_spool = strndup(buffer, text_buffer_size);
7901 CONF("minimum_size") {
7903 if (sscanf(value, "%d %d", &minimum_width, &minimum_height)
7905 if (sscanf(value, "%d", &minimum_width) != 1) {
7913 CONF("maximum_width") {
7915 if (sscanf(value, "%d", &maximum_width) != 1) {
7923 CONF("no_buffers") {
7924 no_buffers = string_to_bool(value);
7926 CONF("top_name_width") {
7928 if (sscanf(value, "%u", &top_name_width) != 1) {
7934 if (top_name_width >= max_user_text) {
7935 top_name_width = max_user_text - 1;
7938 CONF("top_cpu_separate") {
7939 cpu_separate = string_to_bool(value);
7941 CONF("short_units") {
7942 short_units = string_to_bool(value);
7944 CONF("pad_percents") {
7945 pad_percents = atoi(value);
7949 CONF("own_window") {
7951 own_window = string_to_bool(value);
7954 CONF("own_window_class") {
7956 memset(window.class_name, 0, sizeof(window.class_name));
7957 strncpy(window.class_name, value,
7958 sizeof(window.class_name) - 1);
7961 CONF("own_window_title") {
7963 memset(window.title, 0, sizeof(window.title));
7964 strncpy(window.title, value, sizeof(window.title) - 1);
7967 CONF("own_window_transparent") {
7969 set_transparent = string_to_bool(value);
7972 CONF("own_window_hints") {
7974 char *p_hint, *p_save;
7975 char delim[] = ", ";
7977 /* tokenize the value into individual hints */
7978 if ((p_hint = strtok_r(value, delim, &p_save)) != NULL) {
7980 /* fprintf(stderr, "hint [%s] parsed\n", p_hint); */
7981 if (strncmp(p_hint, "undecorate", 10) == EQUAL) {
7982 SET_HINT(window.hints, HINT_UNDECORATED);
7983 } else if (strncmp(p_hint, "below", 5) == EQUAL) {
7984 SET_HINT(window.hints, HINT_BELOW);
7985 } else if (strncmp(p_hint, "above", 5) == EQUAL) {
7986 SET_HINT(window.hints, HINT_ABOVE);
7987 } else if (strncmp(p_hint, "sticky", 6) == EQUAL) {
7988 SET_HINT(window.hints, HINT_STICKY);
7989 } else if (strncmp(p_hint, "skip_taskbar", 12) == EQUAL) {
7990 SET_HINT(window.hints, HINT_SKIP_TASKBAR);
7991 } else if (strncmp(p_hint, "skip_pager", 10) == EQUAL) {
7992 SET_HINT(window.hints, HINT_SKIP_PAGER);
7997 p_hint = strtok_r(NULL, delim, &p_save);
7998 } while (p_hint != NULL);
8004 CONF("own_window_type") {
8006 if (strncmp(value, "normal", 6) == EQUAL) {
8007 window.type = TYPE_NORMAL;
8008 } else if (strncmp(value, "desktop", 7) == EQUAL) {
8009 window.type = TYPE_DESKTOP;
8010 } else if (strncmp(value, "dock", 7) == EQUAL) {
8011 window.type = TYPE_DOCK;
8012 text_alignment = TOP_LEFT;
8013 } else if (strncmp(value, "override", 8) == EQUAL) {
8014 window.type = TYPE_OVERRIDE;
8023 CONF("stippled_borders") {
8025 stippled_borders = strtol(value, 0, 0);
8027 stippled_borders = 4;
8031 CONF("imlib_cache_size") {
8033 cimlib_set_cache_size(atoi(value));
8038 CONF("update_interval") {
8040 update_interval = strtod(value, 0);
8044 if (info.music_player_interval == 0) {
8045 // default to update_interval
8046 info.music_player_interval = update_interval;
8049 CONF("total_run_times") {
8051 total_run_times = strtod(value, 0);
8057 stuff_in_upper_case = string_to_bool(value);
8059 CONF("max_specials") {
8061 max_specials = atoi(value);
8066 CONF("max_user_text") {
8068 max_user_text = atoi(value);
8073 CONF("text_buffer_size") {
8075 text_buffer_size = atoi(value);
8076 if (text_buffer_size < DEFAULT_TEXT_BUFFER_SIZE) {
8077 ERR("text_buffer_size must be >=%i bytes", DEFAULT_TEXT_BUFFER_SIZE);
8078 text_buffer_size = DEFAULT_TEXT_BUFFER_SIZE;
8086 if (output_methods & TO_X) {
8087 X11_initialisation();
8096 global_text = (char *) malloc(1);
8097 global_text[0] = '\0';
8100 unsigned int l = strlen(global_text);
8102 char buf[CONF_BUFF_SIZE];
8104 if (fgets(buf, CONF_BUFF_SIZE, fp) == NULL) {
8110 if (bl >= 2 && buf[bl-2] == '\\' && buf[bl-1] == '\n') {
8118 /* Check for continuation of \\-\n. */
8119 if (l > 0 && buf[0] == '\n' && global_text[l-1] == '\\') {
8120 global_text[l-1] = '\0';
8124 global_text = (char *) realloc(global_text, l + bl + 1);
8125 strcat(global_text, buf);
8127 if (strlen(global_text) > max_user_text) {
8132 if (strlen(global_text) < 1) {
8133 CRIT_ERR("no text supplied in configuration; exiting");
8135 global_text_lines = line + 1;
8138 #ifdef TCP_PORT_MONITOR
8139 CONF("max_port_monitor_connections") {
8141 if (!value || (sscanf(value, "%d", &max) != 1)) {
8142 /* an error. use default, warn and continue. */
8143 tcp_portmon_set_max_connections(0);
8145 } else if (tcp_portmon_set_max_connections(max)) {
8146 /* max is < 0, default has been set*/
8151 CONF("if_up_strictness") {
8153 ERR("incorrect if_up_strictness value, defaulting to 'up'");
8154 ifup_strictness = IFUP_UP;
8155 } else if (strcasecmp(value, "up") == EQUAL) {
8156 ifup_strictness = IFUP_UP;
8157 } else if (strcasecmp(value, "link") == EQUAL) {
8158 ifup_strictness = IFUP_LINK;
8159 } else if (strcasecmp(value, "address") == EQUAL) {
8160 ifup_strictness = IFUP_ADDR;
8162 ERR("incorrect if_up_strictness value, defaulting to 'up'");
8163 ifup_strictness = IFUP_UP;
8167 CONF("temperature_unit") {
8169 ERR("config option 'temperature_unit' needs an argument, either 'celsius' or 'fahrenheit'");
8170 } else if (set_temp_output_unit(value)) {
8171 ERR("temperature_unit: incorrect argument");
8177 size_t maxlength = strlen(value); //+1 for terminating 0 not needed, 'cause of the space in the middle of value
8178 char *skey = malloc(maxlength);
8179 char *svalue = malloc(maxlength);
8181 if (sscanf(value, "%[0-9a-zA-Z_] %[^\n]", skey, svalue) == 2) {
8182 oldvalue = getenv(skey);
8183 if (oldvalue == NULL) {
8184 setenv(skey, svalue, 0);
8186 //PS: Don't free oldvalue, it's the real envvar, not a copy
8200 char *ptr = strtok(value, " ");
8203 ptr = strtok(NULL, " ");
8209 #endif /* HAVE_LUA */
8221 CONF("default_color"){}
8222 CONF3("default_shade_color", "default_shadecolor"){}
8223 CONF3("default_outline_color", "default_outlinecolor") {}
8224 CONF("own_window_colour") {}
8227 ERR("%s: %d: no such configuration: '%s'", f, line, name);
8233 if (info.music_player_interval == 0) {
8234 // default to update_interval
8235 info.music_player_interval = update_interval;
8237 if (!global_text) { // didn't supply any text
8238 CRIT_ERR("missing text block in configuration; exiting");
8242 static void load_config_file_x11(const char *f)
8247 fp = open_config_file(f);
8251 DBGP("reading contents from config file '%s'", f);
8254 char buff[CONF_BUFF_SIZE], *name, *value;
8255 int ret = do_config_step(&line, fp, buff, &name, &value);
8256 if (ret == CONF_BREAK) {
8258 } else if (ret == CONF_CONTINUE) {
8264 X11_initialisation();
8265 if (x_initialised == YES) {
8267 color0 = get_x11_color(value);
8274 X11_initialisation();
8275 if (x_initialised == YES) {
8277 color1 = get_x11_color(value);
8284 X11_initialisation();
8285 if (x_initialised == YES) {
8287 color2 = get_x11_color(value);
8294 X11_initialisation();
8295 if (x_initialised == YES) {
8297 color3 = get_x11_color(value);
8304 X11_initialisation();
8305 if (x_initialised == YES) {
8307 color4 = get_x11_color(value);
8314 X11_initialisation();
8315 if (x_initialised == YES) {
8317 color5 = get_x11_color(value);
8324 X11_initialisation();
8325 if (x_initialised == YES) {
8327 color6 = get_x11_color(value);
8334 X11_initialisation();
8335 if (x_initialised == YES) {
8337 color7 = get_x11_color(value);
8344 X11_initialisation();
8345 if (x_initialised == YES) {
8347 color8 = get_x11_color(value);
8354 X11_initialisation();
8355 if (x_initialised == YES) {
8357 color9 = get_x11_color(value);
8363 CONF("default_color") {
8364 X11_initialisation();
8365 if (x_initialised == YES) {
8367 default_fg_color = get_x11_color(value);
8373 CONF3("default_shade_color", "default_shadecolor") {
8374 X11_initialisation();
8375 if (x_initialised == YES) {
8377 default_bg_color = get_x11_color(value);
8383 CONF3("default_outline_color", "default_outlinecolor") {
8384 X11_initialisation();
8385 if (x_initialised == YES) {
8387 default_out_color = get_x11_color(value);
8394 CONF("own_window_colour") {
8395 X11_initialisation();
8396 if (x_initialised == YES) {
8398 background_colour = get_x11_color(value);
8400 ERR("Invalid colour for own_window_colour (try omitting the "
8401 "'#' for hex colours");
8407 //initialize X11 if nothing X11-related is mentioned before TEXT (and if X11 is the default outputmethod)
8408 if(output_methods & TO_X) {
8409 X11_initialisation();
8419 #undef CONF_CONTINUE
8420 #undef CONF_BUFF_SIZE
8427 static void print_help(const char *prog_name) {
8428 printf("Usage: %s [OPTION]...\n"
8429 PACKAGE_NAME" is a system monitor that renders text on desktop or to own transparent\n"
8430 "window. Command line options will override configurations defined in config\n"
8432 " -v, --version version\n"
8433 " -q, --quiet quiet mode\n"
8434 " -D, --debug increase debugging output\n"
8435 " -c, --config=FILE config file to load\n"
8436 #ifdef CONFIG_OUTPUT
8437 " -C, --print-config print the builtin default config to stdout\n"
8438 " e.g. 'conky -C > ~/.conkyrc' will create a new default config\n"
8440 " -d, --daemonize daemonize, fork to background\n"
8441 " -h, --help help\n"
8443 " -a, --alignment=ALIGNMENT text alignment on screen, {top,bottom,middle}_{left,right,middle}\n"
8444 " -f, --font=FONT font to use\n"
8445 " -X, --display=DISPLAY X11 display to use\n"
8447 " -o, --own-window create own window to draw\n"
8450 " -b, --double-buffer double buffer (prevents flickering)\n"
8452 " -w, --window-id=WIN_ID window id to draw\n"
8453 " -x X x position\n"
8454 " -y Y y position\n"
8456 " -t, --text=TEXT text to render, remember single quotes, like -t '$uptime'\n"
8457 " -u, --interval=SECS update interval\n"
8458 " -i COUNT number of times to update "PACKAGE_NAME" (and quit)\n",
8463 /* : means that character before that takes an argument */
8464 static const char *getopt_string = "vVqdDt:u:i:hc:"
8474 #ifdef CONFIG_OUTPUT
8479 static const struct option longopts[] = {
8480 { "help", 0, NULL, 'h' },
8481 { "version", 0, NULL, 'V' },
8482 { "debug", 0, NULL, 'D' },
8483 { "config", 1, NULL, 'c' },
8484 #ifdef CONFIG_OUTPUT
8485 { "print-config", 0, NULL, 'C' },
8487 { "daemonize", 0, NULL, 'd' },
8489 { "alignment", 1, NULL, 'a' },
8490 { "font", 1, NULL, 'f' },
8491 { "display", 1, NULL, 'X' },
8493 { "own-window", 0, NULL, 'o' },
8496 { "double-buffer", 0, NULL, 'b' },
8498 { "window-id", 1, NULL, 'w' },
8500 { "text", 1, NULL, 't' },
8501 { "interval", 0, NULL, 'u' },
8505 int main(int argc, char **argv)
8511 struct sigaction act, oact;
8513 g_signal_pending = 0;
8514 memset(&info, 0, sizeof(info));
8517 #ifdef TCP_PORT_MONITOR
8518 /* set default connection limit */
8519 tcp_portmon_set_max_connections(0);
8522 /* handle command line parameters that don't change configs */
8524 if (((s = getenv("LC_ALL")) && *s) || ((s = getenv("LC_CTYPE")) && *s)
8525 || ((s = getenv("LANG")) && *s)) {
8526 temp = (char *) malloc((strlen(s) + 1) * sizeof(char));
8528 ERR("malloc failed");
8530 for (x = 0; x < strlen(s); x++) {
8531 temp[x] = tolower(s[x]);
8534 if (strstr(temp, "utf-8") || strstr(temp, "utf8")) {
8540 if (!setlocale(LC_CTYPE, "")) {
8541 ERR("Can't set the specified locale!\nCheck LANG, LC_CTYPE, LC_ALL.");
8545 int c = getopt_long(argc, argv, getopt_string, longopts, NULL);
8556 if (current_config) {
8557 free(current_config);
8559 current_config = strndup(optarg, max_user_text);
8562 freopen("/dev/null", "w", stderr);
8565 print_help(argv[0]);
8567 #ifdef CONFIG_OUTPUT
8574 window.window = strtol(optarg, 0, 0);
8583 /* check if specified config file is valid */
8584 if (current_config) {
8586 if (stat(current_config, &sb) ||
8587 (!S_ISREG(sb.st_mode) && !S_ISLNK(sb.st_mode))) {
8588 ERR("invalid configuration file '%s'\n", current_config);
8589 free(current_config);
8594 /* load current_config, CONFIG_FILE or SYSTEM_CONFIG_FILE */
8596 if (!current_config) {
8597 /* load default config file */
8598 char buf[DEFAULT_TEXT_BUFFER_SIZE];
8601 /* Try to use personal config file first */
8602 to_real_path(buf, CONFIG_FILE);
8603 if (buf[0] && (fp = fopen(buf, "r"))) {
8604 current_config = strndup(buf, max_user_text);
8608 /* Try to use system config file if personal config not readable */
8609 if (!current_config && (fp = fopen(SYSTEM_CONFIG_FILE, "r"))) {
8610 current_config = strndup(SYSTEM_CONFIG_FILE, max_user_text);
8614 /* No readable config found */
8615 if (!current_config) {
8616 #ifdef CONFIG_OUTPUT
8617 current_config = strdup("==builtin==");
8618 ERR("no readable personal or system-wide config file found,"
8619 " using builtin default");
8621 CRIT_ERR("no readable personal or system-wide config file found");
8622 #endif /* ! CONF_OUTPUT */
8625 #ifdef HAVE_SYS_INOTIFY_H
8626 inotify_fd = inotify_init();
8627 #endif /* HAVE_SYS_INOTIFY_H */
8629 load_config_file(current_config);
8631 /* init specials array */
8632 if ((specials = calloc(sizeof(struct special_t), max_specials)) == 0) {
8633 ERR("failed to create specials array");
8637 if (current_mail_spool == NULL) {
8640 variable_substitute(MAIL_FILE, buf, 256);
8642 if (buf[0] != '\0') {
8643 current_mail_spool = strndup(buf, text_buffer_size);
8648 /* handle other command line arguments */
8650 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__OpenBSD__) \
8651 || defined(__NetBSD__)
8652 optind = optreset = 1;
8657 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
8658 if ((kd = kvm_open("/dev/null", "/dev/null", "/dev/null", O_RDONLY,
8659 "kvm_open")) == NULL) {
8660 CRIT_ERR("cannot read kvm");
8665 int c = getopt_long(argc, argv, getopt_string, longopts, NULL);
8673 fork_to_background = 1;
8676 global_debug_level++;
8680 set_first_font(optarg);
8683 text_alignment = string_to_alignment(optarg);
8688 disp = strdup(optarg);
8707 global_text = strndup(optarg, max_user_text);
8708 convert_escapes(global_text);
8712 update_interval = strtod(optarg, 0);
8713 if (info.music_player_interval == 0) {
8714 // default to update_interval
8715 info.music_player_interval = update_interval;
8720 total_run_times = strtod(optarg, 0);
8724 gap_x = atoi(optarg);
8728 gap_y = atoi(optarg);
8739 if (output_methods & TO_X) {
8740 load_config_file_x11(current_config);
8744 /* generate text and get initial size */
8745 extract_variable_text(global_text);
8752 if (fork_to_background) {
8757 ERR(PACKAGE_NAME": couldn't fork() to background: %s",
8764 fprintf(stderr, "\n");
8769 /* parent process */
8770 fprintf(stderr, PACKAGE_NAME": forked to background, pid is %d\n",
8777 text_buffer = malloc(max_user_text);
8778 memset(text_buffer, 0, max_user_text);
8779 tmpstring1 = malloc(text_buffer_size);
8780 memset(tmpstring1, 0, text_buffer_size);
8781 tmpstring2 = malloc(text_buffer_size);
8782 memset(tmpstring2, 0, text_buffer_size);
8787 X11_create_window();
8790 /* Set signal handlers */
8791 act.sa_handler = signal_handler;
8792 sigemptyset(&act.sa_mask);
8795 act.sa_flags |= SA_RESTART;
8798 if ( sigaction(SIGINT, &act, &oact) < 0
8799 || sigaction(SIGUSR1, &act, &oact) < 0
8800 || sigaction(SIGHUP, &act, &oact) < 0
8801 || sigaction(SIGTERM, &act, &oact) < 0) {
8802 ERR("error setting signal handler: %s", strerror(errno));
8807 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
8814 static void signal_handler(int sig)
8816 /* signal handler is light as a feather, as it should be.
8817 * we will poll g_signal_pending with each loop of conky
8818 * and do any signal processing there, NOT here. */
8819 g_signal_pending = sig;