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 static char *template[10];
349 /* maximum size of config TEXT buffer, i.e. below TEXT line. */
350 static unsigned int max_user_text = MAX_USER_TEXT_DEFAULT;
352 /* maximum size of individual text buffers, ie $exec buffer size */
353 unsigned int text_buffer_size = DEFAULT_TEXT_BUFFER_SIZE;
356 #define CODEPAGE_LENGTH 20
358 long iconv_count = 0;
359 char iconv_converting;
360 static iconv_t **iconv_cd = 0;
362 int register_iconv(iconv_t *new_iconv)
364 iconv_cd = realloc(iconv_cd, sizeof(iconv_t *) * (iconv_count + 1));
366 CRIT_ERR("Out of memory");
368 iconv_cd[iconv_count] = malloc(sizeof(iconv_t));
369 if (!iconv_cd[iconv_count]) {
370 CRIT_ERR("Out of memory");
372 memcpy(iconv_cd[iconv_count], new_iconv, sizeof(iconv_t));
377 void free_iconv(void)
382 for (i = 0; i < iconv_count; i++) {
384 iconv_close(*iconv_cd[i]);
398 /* no buffers in used memory? */
401 /* pad percentages to decimals? */
402 static int pad_percents = 0;
404 static char *global_text = 0;
405 long global_text_lines;
407 static int total_updates;
408 static int updatereset;
410 int check_contains(char *f, char *s)
413 FILE *where = open_file(f, 0);
418 while (fgets(buf1, 256, where)) {
419 if (strstr(buf1, s)) {
426 ERR("Could not open the file");
432 static inline int calc_text_width(const char *s, int l)
434 if ((output_methods & TO_X) == 0)
441 XftTextExtentsUtf8(display, fonts[selected_font].xftfont,
442 (const FcChar8 *) s, l, &gi);
444 XftTextExtents8(display, fonts[selected_font].xftfont,
445 (const FcChar8 *) s, l, &gi);
451 return XTextWidth(fonts[selected_font].font, s, l);
456 /* formatted text to render on screen, generated in generate_text(),
457 * drawn in draw_stuff() */
459 static char *text_buffer;
462 static unsigned int special_index; /* used when drawing */
465 /* quite boring functions */
467 static inline void for_each_line(char *b, void f(char *))
471 for (ps = b, pe = b; *pe; pe++) {
485 static void convert_escapes(char *buf)
487 char *p = buf, *s = buf;
494 } else if (*s == '\\') {
505 /* Prints anything normally printed with snprintf according to the current value
506 * of use_spacer. Actually slightly more flexible than snprintf, as you can
507 * safely specify the destination buffer as one of your inputs. */
508 int spaced_print(char *buf, int size, const char *format, int width, ...)
517 tempbuf = malloc(size * sizeof(char));
519 // Passes the varargs along to vsnprintf
520 va_start(argp, width);
521 vsnprintf(tempbuf, size, format, argp);
524 switch (use_spacer) {
526 len = snprintf(buf, size, "%s", tempbuf);
529 len = snprintf(buf, size, "%*s", width, tempbuf);
532 len = snprintf(buf, size, "%-*s", width, tempbuf);
539 /* print percentage values
541 * - i.e., unsigned values between 0 and 100
542 * - respect the value of pad_percents */
543 static int percent_print(char *buf, int size, unsigned value)
545 return spaced_print(buf, size, "%u", pad_percents, value);
548 /* converts from bytes to human readable format (K, M, G, T)
550 * The algorithm always divides by 1024, as unit-conversion of byte
551 * counts suggests. But for output length determination we need to
552 * compare with 1000 here, as we print in decimal form. */
553 static void human_readable(long long num, char *buf, int size)
555 const char **suffix = suffixes;
569 if (llabs(num) < 1000LL) {
570 spaced_print(buf, size, format, width, 0, (float)num, *suffix);
574 while (llabs(num / 1024) >= 1000LL && **(suffix + 2)) {
582 /* fnum should now be < 1000, so looks like 'AAA.BBBBB'
584 * The goal is to always have a significance of 3, by
585 * adjusting the decimal part of the number. Sample output:
589 * so the point of alignment resides between number and unit. The
590 * upside of this is that there is minimal padding necessary, though
591 * there should be a way to make alignment take place at the decimal
592 * dot (then with fixed width decimal part).
594 * Note the repdigits below: when given a precision value, printf()
595 * rounds the float to it, not just cuts off the remaining digits. So
596 * e.g. 99.95 with a precision of 1 gets 100.0, which again should be
597 * printed with a precision of 0. Yay. */
599 precision = 0; /* print 100-999 without decimal part */
601 precision = 1; /* print 10-99 with one decimal place */
603 precision = 2; /* print 0-9 with two decimal places */
605 spaced_print(buf, size, format, width, precision, fnum, *suffix);
608 /* global object list root element */
609 static struct text_object global_root_object;
611 static inline void read_exec(const char *data, char *buf, const int size)
613 FILE *fp = popen(data, "r");
614 int length = fread(buf, 1, size, fp);
618 if (length > 0 && buf[length - 1] == '\n') {
619 buf[length - 1] = '\0';
623 void *threaded_exec(void *) __attribute__((noreturn));
625 void *threaded_exec(void *arg)
628 struct text_object *obj = (struct text_object *)arg;
631 buff = malloc(text_buffer_size);
632 read_exec(obj->data.texeci.cmd, buff,
641 timed_thread_lock(obj->data.texeci.p_timed_thread);
642 strncpy(obj->data.texeci.buffer, buff, text_buffer_size);
643 timed_thread_unlock(obj->data.texeci.p_timed_thread);
645 if (timed_thread_test(obj->data.texeci.p_timed_thread, 0)) {
646 timed_thread_exit(obj->data.texeci.p_timed_thread);
652 static struct text_object *new_text_object_internal(void)
654 struct text_object *obj = malloc(sizeof(struct text_object));
655 memset(obj, 0, sizeof(struct text_object));
660 * Frees the list of text objects root points to. When internal = 1, it won't
661 * free global objects.
663 static void free_text_objects(struct text_object *root, int internal)
665 struct text_object *obj;
671 #define data obj->data
672 for (obj = root->prev; obj; obj = root->prev) {
673 root->prev = obj->prev;
679 #endif /* !__OpenBSD__ */
684 close(data.sysfs.fd);
686 #endif /* __linux__ */
692 free(data.tztime.tz);
693 free(data.tztime.fmt);
696 free(data.mboxscan.args);
697 free(data.mboxscan.output);
702 case OBJ_unseen_mails:
703 case OBJ_flagged_mails:
704 case OBJ_unflagged_mails:
705 case OBJ_forwarded_mails:
706 case OBJ_unforwarded_mails:
707 case OBJ_replied_mails:
708 case OBJ_unreplied_mails:
709 case OBJ_draft_mails:
710 case OBJ_trashed_mails:
711 free(data.local_mail.box);
713 case OBJ_imap_unseen:
718 case OBJ_imap_messages:
723 case OBJ_pop3_unseen:
735 free_text_objects(obj->sub, 1);
738 case OBJ_if_existing:
741 free(data.ifblock.s);
742 free(data.ifblock.str);
745 free(data.tail.logfile);
746 free(data.tail.buffer);
762 case OBJ_iconv_start:
767 case OBJ_disk_protect:
771 free(data.ifblock.s);
772 free(data.ifblock.str);
775 if (info.gw_info.iface) {
776 free(info.gw_info.iface);
777 info.gw_info.iface = 0;
779 if (info.gw_info.ip) {
780 free(info.gw_info.ip);
784 case OBJ_ioscheduler:
789 #if (defined(__FreeBSD__) || defined(__linux__))
791 free(data.ifblock.s);
792 free(data.ifblock.str);
796 case OBJ_xmms2_artist:
797 if (info.xmms2.artist) {
798 free(info.xmms2.artist);
799 info.xmms2.artist = 0;
802 case OBJ_xmms2_album:
803 if (info.xmms2.album) {
804 free(info.xmms2.album);
805 info.xmms2.album = 0;
808 case OBJ_xmms2_title:
809 if (info.xmms2.title) {
810 free(info.xmms2.title);
811 info.xmms2.title = 0;
814 case OBJ_xmms2_genre:
815 if (info.xmms2.genre) {
816 free(info.xmms2.genre);
817 info.xmms2.genre = 0;
820 case OBJ_xmms2_comment:
821 if (info.xmms2.comment) {
822 free(info.xmms2.comment);
823 info.xmms2.comment = 0;
827 if (info.xmms2.url) {
828 free(info.xmms2.url);
833 if (info.xmms2.date) {
834 free(info.xmms2.date);
838 case OBJ_xmms2_status:
839 if (info.xmms2.status) {
840 free(info.xmms2.status);
841 info.xmms2.status = 0;
844 case OBJ_xmms2_playlist:
845 if (info.xmms2.playlist) {
846 free(info.xmms2.playlist);
847 info.xmms2.playlist = 0;
850 case OBJ_xmms2_smart:
851 if (info.xmms2.artist) {
852 free(info.xmms2.artist);
853 info.xmms2.artist = 0;
855 if (info.xmms2.title) {
856 free(info.xmms2.title);
857 info.xmms2.title = 0;
859 if (info.xmms2.url) {
860 free(info.xmms2.url);
867 case OBJ_bmpx_artist:
871 case OBJ_bmpx_bitrate:
881 free(data.rss.action);
887 case OBJ_lua_read_parse:
895 #endif /* HAVE_LUA */
902 case OBJ_battery_short:
905 case OBJ_battery_time:
908 #endif /* !__OpenBSD__ */
916 free(data.execi.cmd);
917 free(data.execi.buffer);
920 free(data.texeci.cmd);
921 free(data.texeci.buffer);
929 if (info.first_process && !internal) {
930 free_all_processes();
931 info.first_process = NULL;
933 if (data.top.s) free(data.top.s);
937 free(data.hddtemp.dev);
938 free(data.hddtemp.addr);
939 if (data.hddtemp.temp)
940 free(data.hddtemp.temp);
943 case OBJ_entropy_avail:
944 case OBJ_entropy_poolsize:
946 case OBJ_entropy_bar:
950 if (info.users.names) {
951 free(info.users.names);
952 info.users.names = 0;
956 if (info.users.terms) {
957 free(info.users.terms);
958 info.users.terms = 0;
962 if (info.users.times) {
963 free(info.users.times);
964 info.users.times = 0;
969 case OBJ_smapi_bat_perc:
970 case OBJ_smapi_bat_temp:
971 case OBJ_smapi_bat_power:
974 case OBJ_if_smapi_bat_installed:
975 free(data.ifblock.s);
976 free(data.ifblock.str);
990 case OBJ_mpd_bitrate:
995 case OBJ_mpd_elapsed:
1000 case OBJ_mpd_percent:
1002 case OBJ_if_mpd_playing:
1010 case OBJ_moc_artist:
1013 case OBJ_moc_totaltime:
1014 case OBJ_moc_timeleft:
1015 case OBJ_moc_curtime:
1016 case OBJ_moc_bitrate:
1022 free(data.scroll.text);
1023 free_text_objects(obj->sub, 1);
1027 free(data.combine.left);
1028 free(data.combine.seperation);
1029 free(data.combine.right);
1030 free_text_objects(obj->sub, 1);
1035 case OBJ_apcupsd_name:
1036 case OBJ_apcupsd_model:
1037 case OBJ_apcupsd_upsmode:
1038 case OBJ_apcupsd_cable:
1039 case OBJ_apcupsd_status:
1040 case OBJ_apcupsd_linev:
1041 case OBJ_apcupsd_load:
1043 case OBJ_apcupsd_loadbar:
1044 case OBJ_apcupsd_loadgraph:
1045 case OBJ_apcupsd_loadgauge:
1047 case OBJ_apcupsd_charge:
1048 case OBJ_apcupsd_timeleft:
1049 case OBJ_apcupsd_temp:
1050 case OBJ_apcupsd_lastxfer:
1052 #endif /* APCUPSD */
1060 void scan_mixer_bar(const char *arg, int *a, int *w, int *h)
1065 if (arg && sscanf(arg, "%63s %n", buf1, &n) >= 1) {
1066 *a = mixer_init(buf1);
1067 scan_bar(arg + n, w, h);
1069 *a = mixer_init(NULL);
1070 scan_bar(arg, w, h);
1075 /* strip a leading /dev/ if any, following symlinks first
1077 * BEWARE: this function returns a pointer to static content
1078 * which gets overwritten in consecutive calls. I.e.:
1079 * this function is NOT reentrant.
1081 static const char *dev_name(const char *path)
1083 static char buf[255]; /* should be enough for pathnames */
1089 #define DEV_NAME(x) \
1090 x != NULL && strlen(x) > 5 && strncmp(x, "/dev/", 5) == 0 ? x + 5 : x
1091 if ((buflen = readlink(path, buf, 254)) == -1)
1092 return DEV_NAME(path);
1094 return DEV_NAME(buf);
1098 static int parse_top_args(const char *s, const char *arg, struct text_object *obj)
1103 if (obj->data.top.was_parsed) {
1106 obj->data.top.was_parsed = 1;
1108 if (arg && !obj->data.top.s) {
1109 obj->data.top.s = strndup(arg, text_buffer_size);
1112 need_mask |= (1 << INFO_TOP);
1115 obj->type = OBJ_top;
1117 } else if (strcmp(&s[3], "_mem") == EQUAL) {
1118 obj->type = OBJ_top_mem;
1120 } else if (strcmp(&s[3], "_time") == EQUAL) {
1121 obj->type = OBJ_top_time;
1124 ERR("Must be top, top_mem or top_time");
1129 ERR("top needs arguments");
1133 if (sscanf(arg, "%63s %i", buf, &n) == 2) {
1134 if (strcmp(buf, "name") == EQUAL) {
1135 obj->data.top.type = TOP_NAME;
1136 } else if (strcmp(buf, "cpu") == EQUAL) {
1137 obj->data.top.type = TOP_CPU;
1138 } else if (strcmp(buf, "pid") == EQUAL) {
1139 obj->data.top.type = TOP_PID;
1140 } else if (strcmp(buf, "mem") == EQUAL) {
1141 obj->data.top.type = TOP_MEM;
1142 } else if (strcmp(buf, "time") == EQUAL) {
1143 obj->data.top.type = TOP_TIME;
1144 } else if (strcmp(buf, "mem_res") == EQUAL) {
1145 obj->data.top.type = TOP_MEM_RES;
1146 } else if (strcmp(buf, "mem_vsize") == EQUAL) {
1147 obj->data.top.type = TOP_MEM_VSIZE;
1149 ERR("invalid type arg for top");
1150 ERR("must be one of: name, cpu, pid, mem, time, mem_res, mem_vsize");
1153 if (n < 1 || n > 10) {
1154 ERR("invalid num arg for top. Must be between 1 and 10.");
1157 obj->data.top.num = n - 1;
1160 ERR("invalid argument count for top");
1166 /* construct_text_object() creates a new text_object */
1167 static struct text_object *construct_text_object(const char *s,
1168 const char *arg, long line, char allow_threaded, void **ifblock_opaque)
1170 // struct text_object *obj = new_text_object();
1171 struct text_object *obj = new_text_object_internal();
1175 #define OBJ(a, n) if (strcmp(s, #a) == 0) { \
1176 obj->type = OBJ_##a; need_mask |= (1ULL << n); {
1177 #define OBJ_IF(a, n) if (strcmp(s, #a) == 0) { \
1178 obj->type = OBJ_##a; need_mask |= (1ULL << n); \
1179 obj_be_ifblock_if(ifblock_opaque, obj); {
1180 #define OBJ_THREAD(a, n) if (strcmp(s, #a) == 0 && allow_threaded) { \
1181 obj->type = OBJ_##a; need_mask |= (1ULL << n); {
1182 #define END } } else
1184 #define SIZE_DEFAULTS(arg) { \
1185 obj->a = default_##arg##_width; \
1186 obj->b = default_##arg##_height; \
1191 obj->type = OBJ_color;
1192 obj->data.l = get_x11_color(s);
1196 OBJ(freq, INFO_FREQ)
1199 obj->data.i = open_acpi_temperature(arg);
1200 END OBJ(acpiacadapter, 0)
1201 END OBJ(freq, INFO_FREQ)
1202 #endif /* !__OpenBSD__ */
1204 if (!arg || !isdigit(arg[0]) || strlen(arg) >= 2 || atoi(&arg[0]) == 0
1205 || (unsigned int) atoi(&arg[0]) > info.cpu_count) {
1206 obj->data.cpu_index = 1;
1207 /* ERR("freq: Invalid CPU number or you don't have that many CPUs! "
1208 "Displaying the clock for CPU 1."); */
1210 obj->data.cpu_index = atoi(&arg[0]);
1213 END OBJ(freq_g, INFO_FREQ)
1215 if (!arg || !isdigit(arg[0]) || strlen(arg) >= 2 || atoi(&arg[0]) == 0
1216 || (unsigned int) atoi(&arg[0]) > info.cpu_count) {
1217 obj->data.cpu_index = 1;
1218 /* ERR("freq_g: Invalid CPU number or you don't have that many "
1219 "CPUs! Displaying the clock for CPU 1."); */
1221 obj->data.cpu_index = atoi(&arg[0]);
1224 #if defined(__linux__)
1225 END OBJ(voltage_mv, 0)
1227 if (!arg || !isdigit(arg[0]) || strlen(arg) >= 2 || atoi(&arg[0]) == 0
1228 || (unsigned int) atoi(&arg[0]) > info.cpu_count) {
1229 obj->data.cpu_index = 1;
1230 /* ERR("voltage_mv: Invalid CPU number or you don't have that many "
1231 "CPUs! Displaying voltage for CPU 1."); */
1233 obj->data.cpu_index = atoi(&arg[0]);
1236 END OBJ(voltage_v, 0)
1238 if (!arg || !isdigit(arg[0]) || strlen(arg) >= 2 || atoi(&arg[0]) == 0
1239 || (unsigned int) atoi(&arg[0]) > info.cpu_count) {
1240 obj->data.cpu_index = 1;
1241 /* ERR("voltage_v: Invalid CPU number or you don't have that many "
1242 "CPUs! Displaying voltage for CPU 1."); */
1244 obj->data.cpu_index = atoi(&arg[0]);
1249 END OBJ(wireless_essid, INFO_NET)
1251 obj->data.net = get_net_stat(arg);
1253 CRIT_ERR("wireless_essid: needs an argument");
1255 END OBJ(wireless_mode, INFO_NET)
1257 obj->data.net = get_net_stat(arg);
1259 CRIT_ERR("wireless_mode: needs an argument");
1261 END OBJ(wireless_bitrate, INFO_NET)
1263 obj->data.net = get_net_stat(arg);
1265 CRIT_ERR("wireless_bitrate: needs an argument");
1267 END OBJ(wireless_ap, INFO_NET)
1269 obj->data.net = get_net_stat(arg);
1271 CRIT_ERR("wireless_ap: needs an argument");
1273 END OBJ(wireless_link_qual, INFO_NET)
1275 obj->data.net = get_net_stat(arg);
1277 CRIT_ERR("wireless_link_qual: needs an argument");
1279 END OBJ(wireless_link_qual_max, INFO_NET)
1281 obj->data.net = get_net_stat(arg);
1283 CRIT_ERR("wireless_link_qual_max: needs an argument");
1285 END OBJ(wireless_link_qual_perc, INFO_NET)
1287 obj->data.net = get_net_stat(arg);
1289 CRIT_ERR("wireless_link_qual_perc: needs an argument");
1291 END OBJ(wireless_link_bar, INFO_NET)
1294 arg = scan_bar(arg, &obj->a, &obj->b);
1295 obj->data.net = get_net_stat(arg);
1297 CRIT_ERR("wireless_link_bar: needs an argument");
1299 #endif /* HAVE_IWLIB */
1301 #endif /* __linux__ */
1309 sscanf(arg, "%63s", bat);
1311 strcpy(bat, "BAT0");
1313 obj->data.s = strndup(bat, text_buffer_size);
1314 END OBJ(battery_short, 0)
1318 sscanf(arg, "%63s", bat);
1320 strcpy(bat, "BAT0");
1322 obj->data.s = strndup(bat, text_buffer_size);
1323 END OBJ(battery_time, 0)
1327 sscanf(arg, "%63s", bat);
1329 strcpy(bat, "BAT0");
1331 obj->data.s = strndup(bat, text_buffer_size);
1332 END OBJ(battery_percent, 0)
1336 sscanf(arg, "%63s", bat);
1338 strcpy(bat, "BAT0");
1340 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);
1354 #endif /* !__OpenBSD__ */
1356 #if defined(__linux__)
1357 END OBJ(disk_protect, 0)
1359 obj->data.s = strndup(dev_name(arg), text_buffer_size);
1361 CRIT_ERR("disk_protect needs an argument");
1362 END OBJ(i8k_version, INFO_I8K)
1363 END OBJ(i8k_bios, INFO_I8K)
1364 END OBJ(i8k_serial, INFO_I8K)
1365 END OBJ(i8k_cpu_temp, INFO_I8K)
1366 END OBJ(i8k_left_fan_status, INFO_I8K)
1367 END OBJ(i8k_right_fan_status, INFO_I8K)
1368 END OBJ(i8k_left_fan_rpm, INFO_I8K)
1369 END OBJ(i8k_right_fan_rpm, INFO_I8K)
1370 END OBJ(i8k_ac_status, INFO_I8K)
1371 END OBJ(i8k_buttons_status, INFO_I8K)
1374 END OBJ(ibm_temps, 0)
1376 CRIT_ERR("ibm_temps: needs an argument");
1378 if (!isdigit(arg[0]) || strlen(arg) >= 2 || atoi(&arg[0]) >= 8) {
1379 obj->data.sensor = 0;
1380 ERR("Invalid temperature sensor! Sensor number must be 0 to 7. "
1381 "Using 0 (CPU temp sensor).");
1383 obj->data.sensor = atoi(&arg[0]);
1384 END OBJ(ibm_volume, 0)
1385 END OBJ(ibm_brightness, 0)
1387 /* information from sony_laptop kernel module
1388 * /sys/devices/platform/sony-laptop */
1389 END OBJ(sony_fanspeed, 0)
1390 END OBJ_IF(if_gw, INFO_GW)
1391 END OBJ(ioscheduler, 0)
1393 CRIT_ERR("get_ioscheduler needs an argument (e.g. hda)");
1396 obj->data.s = strndup(dev_name(arg), text_buffer_size);
1397 END OBJ(laptop_mode, 0)
1398 END OBJ(pb_battery, 0)
1399 if (arg && strcmp(arg, "status") == EQUAL) {
1400 obj->data.i = PB_BATT_STATUS;
1401 } else if (arg && strcmp(arg, "percent") == EQUAL) {
1402 obj->data.i = PB_BATT_PERCENT;
1403 } else if (arg && strcmp(arg, "time") == EQUAL) {
1404 obj->data.i = PB_BATT_TIME;
1406 ERR("pb_battery: needs one argument: status, percent or time");
1411 #endif /* __linux__ */
1412 #if (defined(__FreeBSD__) || defined(__linux__))
1413 END OBJ_IF(if_up, 0)
1415 ERR("if_up needs an argument");
1416 obj->data.ifblock.s = 0;
1418 obj->data.ifblock.s = strndup(arg, text_buffer_size);
1421 #if defined(__OpenBSD__)
1422 END OBJ(obsd_sensors_temp, 0)
1424 CRIT_ERR("obsd_sensors_temp: needs an argument");
1426 if (!isdigit(arg[0]) || atoi(&arg[0]) < 0
1427 || atoi(&arg[0]) > OBSD_MAX_SENSORS - 1) {
1428 obj->data.sensor = 0;
1429 ERR("Invalid temperature sensor number!");
1431 obj->data.sensor = atoi(&arg[0]);
1432 END OBJ(obsd_sensors_fan, 0)
1434 CRIT_ERR("obsd_sensors_fan: needs 2 arguments (device and sensor "
1437 if (!isdigit(arg[0]) || atoi(&arg[0]) < 0
1438 || atoi(&arg[0]) > OBSD_MAX_SENSORS - 1) {
1439 obj->data.sensor = 0;
1440 ERR("Invalid fan sensor number!");
1442 obj->data.sensor = atoi(&arg[0]);
1443 END OBJ(obsd_sensors_volt, 0)
1445 CRIT_ERR("obsd_sensors_volt: needs 2 arguments (device and sensor "
1448 if (!isdigit(arg[0]) || atoi(&arg[0]) < 0
1449 || atoi(&arg[0]) > OBSD_MAX_SENSORS - 1) {
1450 obj->data.sensor = 0;
1451 ERR("Invalid voltage sensor number!");
1453 obj->data.sensor = atoi(&arg[0]);
1454 END OBJ(obsd_vendor, 0)
1455 END OBJ(obsd_product, 0)
1456 #endif /* __OpenBSD__ */
1457 END OBJ(buffers, INFO_BUFFERS)
1458 END OBJ(cached, INFO_BUFFERS)
1459 #define SCAN_CPU(__arg, __var) { \
1461 if (__arg && sscanf(__arg, " cpu%u %n", &__var, &__offset) > 0) \
1462 __arg += __offset; \
1466 END OBJ(cpu, INFO_CPU)
1467 SCAN_CPU(arg, obj->data.cpu_index);
1468 DBGP2("Adding $cpu for CPU %d", obj->data.cpu_index);
1470 END OBJ(cpugauge, INFO_CPU)
1471 SIZE_DEFAULTS(gauge);
1472 SCAN_CPU(arg, obj->data.cpu_index);
1473 scan_gauge(arg, &obj->a, &obj->b);
1474 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);
1480 END OBJ(cpugraph, INFO_CPU)
1481 SIZE_DEFAULTS(graph);
1482 SCAN_CPU(arg, obj->data.cpu_index);
1483 scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
1484 &obj->e, &obj->char_a, &obj->char_b);
1485 DBGP2("Adding $cpugraph for CPU %d", obj->data.cpu_index);
1486 END OBJ(loadgraph, INFO_LOADAVG)
1488 SIZE_DEFAULTS(graph);
1489 buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
1490 &obj->e, &obj->char_a, &obj->char_b);
1494 r = sscanf(arg, "%d", &a);
1496 obj->data.loadavg[0] = (r >= 1) ? (unsigned char) a : 0;
1500 END OBJ(diskio, INFO_DISKIO)
1501 obj->data.diskio = prepare_diskio_stat(dev_name(arg));
1502 END OBJ(diskio_read, INFO_DISKIO)
1503 obj->data.diskio = prepare_diskio_stat(dev_name(arg));
1504 END OBJ(diskio_write, INFO_DISKIO)
1505 obj->data.diskio = prepare_diskio_stat(dev_name(arg));
1507 END OBJ(diskiograph, INFO_DISKIO)
1509 SIZE_DEFAULTS(graph);
1510 buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
1511 &obj->e, &obj->char_a, &obj->char_b);
1513 obj->data.diskio = prepare_diskio_stat(dev_name(buf));
1516 END OBJ(diskiograph_read, INFO_DISKIO)
1518 SIZE_DEFAULTS(graph);
1519 buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
1520 &obj->e, &obj->char_a, &obj->char_b);
1522 obj->data.diskio = prepare_diskio_stat(dev_name(buf));
1525 END OBJ(diskiograph_write, INFO_DISKIO)
1527 SIZE_DEFAULTS(graph);
1528 buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
1529 &obj->e, &obj->char_a, &obj->char_b);
1531 obj->data.diskio = prepare_diskio_stat(dev_name(buf));
1537 if (output_methods & TO_X) {
1538 obj->data.l = arg ? get_x11_color(arg) : default_fg_color;
1542 obj->data.l = color0;
1544 obj->data.l = color1;
1546 obj->data.l = color2;
1548 obj->data.l = color3;
1550 obj->data.l = color4;
1552 obj->data.l = color5;
1554 obj->data.l = color6;
1556 obj->data.l = color7;
1558 obj->data.l = color8;
1560 obj->data.l = color9;
1563 obj->data.s = scan_font(arg);
1565 END OBJ(conky_version, 0)
1566 END OBJ(conky_build_date, 0)
1567 END OBJ(conky_build_arch, 0)
1568 END OBJ(downspeed, INFO_NET)
1570 obj->data.net = get_net_stat(arg);
1572 CRIT_ERR("downspeed needs argument");
1574 END OBJ(downspeedf, INFO_NET)
1576 obj->data.net = get_net_stat(arg);
1578 CRIT_ERR("downspeedf needs argument");
1581 END OBJ(downspeedgraph, INFO_NET)
1583 SIZE_DEFAULTS(graph);
1584 buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
1585 &obj->e, &obj->char_a, &obj->char_b);
1587 // default to DEFAULTNETDEV
1588 buf = strndup(buf ? buf : "DEFAULTNETDEV", text_buffer_size);
1589 obj->data.net = get_net_stat(buf);
1593 obj_be_ifblock_else(ifblock_opaque, obj);
1595 obj_be_ifblock_endif(ifblock_opaque, obj);
1597 obj->data.s = strndup(arg ? arg : "", text_buffer_size);
1599 obj->data.s = strndup(arg ? arg : "", text_buffer_size);
1602 obj->data.s = strndup(arg ? arg : "", text_buffer_size);
1604 obj->data.s = strndup(arg ? arg : "", text_buffer_size);
1607 obj->data.s = strndup(arg ? arg : "", text_buffer_size);
1609 END OBJ(execgauge, 0)
1610 SIZE_DEFAULTS(gauge);
1611 obj->data.s = strndup(arg ? arg : "", text_buffer_size);
1612 END OBJ(execgraph, 0)
1613 SIZE_DEFAULTS(graph);
1614 obj->data.s = strndup(arg ? arg : "", text_buffer_size);
1615 END OBJ(execibar, 0)
1619 if (!arg || sscanf(arg, "%f %n", &obj->data.execi.interval, &n) <= 0) {
1622 ERR("${execibar <interval> command}");
1623 obj->type = OBJ_text;
1624 snprintf(buf, 256, "${%s}", s);
1625 obj->data.s = strndup(buf, text_buffer_size);
1627 obj->data.execi.cmd = strndup(arg + n, text_buffer_size);
1629 END OBJ(execigraph, 0)
1631 SIZE_DEFAULTS(graph);
1633 if (!arg || sscanf(arg, "%f %n", &obj->data.execi.interval, &n) <= 0) {
1636 ERR("${execigraph <interval> command}");
1637 obj->type = OBJ_text;
1638 snprintf(buf, 256, "${%s}", s);
1639 obj->data.s = strndup(buf, text_buffer_size);
1641 obj->data.execi.cmd = strndup(arg + n, text_buffer_size);
1643 END OBJ(execigauge, 0)
1645 SIZE_DEFAULTS(gauge);
1647 if (!arg || sscanf(arg, "%f %n", &obj->data.execi.interval, &n) <= 0) {
1650 ERR("${execigauge <interval> command}");
1651 obj->type = OBJ_text;
1652 snprintf(buf, 256, "${%s}", s);
1653 obj->data.s = strndup(buf, text_buffer_size);
1655 obj->data.execi.cmd = strndup(arg + n, text_buffer_size);
1661 if (!arg || sscanf(arg, "%f %n", &obj->data.execi.interval, &n) <= 0) {
1664 ERR("${execi <interval> command}");
1665 obj->type = OBJ_text;
1666 snprintf(buf, 256, "${%s}", s);
1667 obj->data.s = strndup(buf, text_buffer_size);
1669 obj->data.execi.cmd = strndup(arg + n, text_buffer_size);
1670 obj->data.execi.buffer = malloc(text_buffer_size);
1675 if (!arg || sscanf(arg, "%f %n", &obj->data.execi.interval, &n) <= 0) {
1678 ERR("${execi <interval> command}");
1679 obj->type = OBJ_text;
1680 snprintf(buf, 256, "${%s}", s);
1681 obj->data.s = strndup(buf, text_buffer_size);
1683 obj->data.execi.cmd = strndup(arg + n, text_buffer_size);
1684 obj->data.execi.buffer = malloc(text_buffer_size);
1686 END OBJ_THREAD(texeci, 0)
1689 if (!arg || sscanf(arg, "%f %n", &obj->data.texeci.interval, &n) <= 0) {
1692 ERR("${texeci <interval> command}");
1693 obj->type = OBJ_text;
1694 snprintf(buf, 256, "${%s}", s);
1695 obj->data.s = strndup(buf, text_buffer_size);
1697 obj->data.texeci.cmd = strndup(arg + n, text_buffer_size);
1698 obj->data.texeci.buffer = malloc(text_buffer_size);
1700 obj->data.texeci.p_timed_thread = NULL;
1701 END OBJ(pre_exec, 0)
1702 obj->type = OBJ_text;
1706 read_exec(arg, buf, sizeof(buf));
1707 obj->data.s = strndup(buf, text_buffer_size);
1709 obj->data.s = strndup("", text_buffer_size);
1713 END OBJ(fs_bar, INFO_FS)
1715 arg = scan_bar(arg, &obj->data.fsbar.w, &obj->data.fsbar.h);
1717 while (isspace(*arg)) {
1726 obj->data.fsbar.fs = prepare_fs_stat(arg);
1727 END OBJ(fs_bar_free, INFO_FS)
1729 arg = scan_bar(arg, &obj->data.fsbar.w, &obj->data.fsbar.h);
1731 while (isspace(*arg)) {
1741 obj->data.fsbar.fs = prepare_fs_stat(arg);
1743 END OBJ(fs_free, INFO_FS)
1747 obj->data.fs = prepare_fs_stat(arg);
1748 END OBJ(fs_used_perc, INFO_FS)
1752 obj->data.fs = prepare_fs_stat(arg);
1753 END OBJ(fs_free_perc, INFO_FS)
1757 obj->data.fs = prepare_fs_stat(arg);
1758 END OBJ(fs_size, INFO_FS)
1762 obj->data.fs = prepare_fs_stat(arg);
1763 END OBJ(fs_type, INFO_FS)
1767 obj->data.fs = prepare_fs_stat(arg);
1768 END OBJ(fs_used, INFO_FS)
1772 obj->data.fs = prepare_fs_stat(arg);
1774 obj->data.i = arg ? atoi(arg) : 1;
1775 END OBJ(nameserver, INFO_DNS)
1776 obj->data.i = arg ? atoi(arg) : 0;
1778 obj->data.i = arg ? atoi(arg) : 1;
1780 obj->data.i = arg ? atoi(arg) : 1;
1784 ERR("goto needs arguments");
1785 obj->type = OBJ_text;
1786 obj->data.s = strndup("${goto}", text_buffer_size);
1790 obj->data.i = atoi(arg);
1796 if (sscanf(arg, "%d %d", &a, &b) != 2) {
1797 sscanf(arg, "%d", &b);
1803 obj->data.pair.a = a;
1804 obj->data.pair.b = b;
1807 END OBJ(i2c, INFO_SYSFS)
1808 char buf1[64], buf2[64];
1809 float factor, offset;
1813 ERR("i2c needs arguments");
1814 obj->type = OBJ_text;
1815 // obj->data.s = strndup("${i2c}", text_buffer_size);
1819 #define HWMON_RESET() {\
1824 if (sscanf(arg, "%63s %d %f %f", buf2, &n, &factor, &offset) == 4) found = 1; else HWMON_RESET();
1825 if (!found && sscanf(arg, "%63s %63s %d %f %f", buf1, buf2, &n, &factor, &offset) == 5) found = 1; else if (!found) HWMON_RESET();
1826 if (!found && sscanf(arg, "%63s %63s %d", buf1, buf2, &n) == 3) found = 1; else if (!found) HWMON_RESET();
1827 if (!found && sscanf(arg, "%63s %d", buf2, &n) == 2) found = 1; else if (!found) HWMON_RESET();
1830 ERR("i2c failed to parse arguments");
1831 obj->type = OBJ_text;
1834 DBGP("parsed i2c args: '%s' '%s' %d %f %f\n", buf1, buf2, n, factor, offset);
1835 obj->data.sysfs.fd = open_i2c_sensor((*buf1) ? buf1 : 0, buf2, n,
1836 &obj->data.sysfs.arg, obj->data.sysfs.devtype);
1837 strncpy(obj->data.sysfs.type, buf2, 63);
1838 obj->data.sysfs.factor = factor;
1839 obj->data.sysfs.offset = offset;
1841 END OBJ(platform, INFO_SYSFS)
1842 char buf1[64], buf2[64];
1843 float factor, offset;
1847 ERR("platform needs arguments");
1848 obj->type = OBJ_text;
1852 if (sscanf(arg, "%63s %d %f %f", buf2, &n, &factor, &offset) == 4) found = 1; else HWMON_RESET();
1853 if (!found && sscanf(arg, "%63s %63s %d %f %f", buf1, buf2, &n, &factor, &offset) == 5) found = 1; else if (!found) HWMON_RESET();
1854 if (!found && sscanf(arg, "%63s %63s %d", buf1, buf2, &n) == 3) found = 1; else if (!found) HWMON_RESET();
1855 if (!found && sscanf(arg, "%63s %d", buf2, &n) == 2) found = 1; else if (!found) HWMON_RESET();
1858 ERR("platform failed to parse arguments");
1859 obj->type = OBJ_text;
1862 DBGP("parsed platform args: '%s' '%s' %d %f %f\n", buf1, buf2, n, factor, offset);
1863 obj->data.sysfs.fd = open_platform_sensor((*buf1) ? buf1 : 0, buf2, n,
1864 &obj->data.sysfs.arg, obj->data.sysfs.devtype);
1865 strncpy(obj->data.sysfs.type, buf2, 63);
1866 obj->data.sysfs.factor = factor;
1867 obj->data.sysfs.offset = offset;
1869 END OBJ(hwmon, INFO_SYSFS)
1870 char buf1[64], buf2[64];
1871 float factor, offset;
1875 ERR("hwmon needs argumanets");
1876 obj->type = OBJ_text;
1880 if (sscanf(arg, "%63s %d %f %f", buf2, &n, &factor, &offset) == 4) found = 1; else HWMON_RESET();
1881 if (!found && sscanf(arg, "%63s %63s %d %f %f", buf1, buf2, &n, &factor, &offset) == 5) found = 1; else if (!found) HWMON_RESET();
1882 if (!found && sscanf(arg, "%63s %63s %d", buf1, buf2, &n) == 3) found = 1; else if (!found) HWMON_RESET();
1883 if (!found && sscanf(arg, "%63s %d", buf2, &n) == 2) found = 1; else if (!found) HWMON_RESET();
1888 ERR("hwmon failed to parse arguments");
1889 obj->type = OBJ_text;
1892 DBGP("parsed hwmon args: '%s' '%s' %d %f %f\n", buf1, buf2, n, factor, offset);
1893 obj->data.sysfs.fd = open_hwmon_sensor((*buf1) ? buf1 : 0, buf2, n,
1894 &obj->data.sysfs.arg, obj->data.sysfs.devtype);
1895 strncpy(obj->data.sysfs.type, buf2, 63);
1896 obj->data.sysfs.factor = factor;
1897 obj->data.sysfs.offset = offset;
1899 #endif /* !__OpenBSD__ */
1902 /* we have three different types of top (top, top_mem and top_time). To
1903 * avoid having almost-same code three times, we have this special
1905 if (strncmp(s, "top", 3) == EQUAL) {
1906 if (!parse_top_args(s, arg, obj)) {
1909 } else OBJ(addr, INFO_NET)
1911 obj->data.net = get_net_stat(arg);
1913 CRIT_ERR("addr needs argument");
1915 #if defined(__linux__)
1916 END OBJ(addrs, INFO_NET)
1918 obj->data.net = get_net_stat(arg);
1920 CRIT_ERR("addrs needs argument");
1922 #endif /* __linux__ */
1924 if (init_tail_object(obj, arg)) {
1925 obj->type = OBJ_text;
1926 obj->data.s = strndup("${tail}", text_buffer_size);
1929 if (init_head_object(obj, arg)) {
1930 obj->type = OBJ_text;
1931 obj->data.s = strndup("${head}", text_buffer_size);
1935 obj->data.s = strndup(arg, text_buffer_size);
1937 CRIT_ERR("lines needs a argument");
1941 obj->data.s = strndup(arg, text_buffer_size);
1943 CRIT_ERR("words needs a argument");
1945 END OBJ(loadavg, INFO_LOADAVG)
1946 int a = 1, b = 2, c = 3, r = 3;
1949 r = sscanf(arg, "%d %d %d", &a, &b, &c);
1950 if (r >= 3 && (c < 1 || c > 3)) {
1953 if (r >= 2 && (b < 1 || b > 3)) {
1956 if (r >= 1 && (a < 1 || a > 3)) {
1960 obj->data.loadavg[0] = (r >= 1) ? (unsigned char) a : 0;
1961 obj->data.loadavg[1] = (r >= 2) ? (unsigned char) b : 0;
1962 obj->data.loadavg[2] = (r >= 3) ? (unsigned char) c : 0;
1963 END OBJ_IF(if_empty, 0)
1965 ERR("if_empty needs an argument");
1966 obj->data.ifblock.s = 0;
1968 obj->data.ifblock.s = strndup(arg, text_buffer_size);
1969 obj->sub = malloc(sizeof(struct text_object));
1970 extract_variable_text_internal(obj->sub,
1971 obj->data.ifblock.s, 0);
1973 END OBJ_IF(if_match, 0)
1975 ERR("if_match needs arguments");
1976 obj->data.ifblock.s = 0;
1978 obj->data.ifblock.s = strndup(arg, text_buffer_size);
1979 obj->sub = malloc(sizeof(struct text_object));
1980 extract_variable_text_internal(obj->sub,
1981 obj->data.ifblock.s, 0);
1983 END OBJ_IF(if_existing, 0)
1985 ERR("if_existing needs an argument or two");
1986 obj->data.ifblock.s = NULL;
1987 obj->data.ifblock.str = NULL;
1989 char buf1[256], buf2[256];
1990 int r = sscanf(arg, "%255s %255[^\n]", buf1, buf2);
1993 obj->data.ifblock.s = strndup(buf1, text_buffer_size);
1994 obj->data.ifblock.str = NULL;
1996 obj->data.ifblock.s = strndup(buf1, text_buffer_size);
1997 obj->data.ifblock.str = strndup(buf2, text_buffer_size);
2000 DBGP("if_existing: '%s' '%s'", obj->data.ifblock.s, obj->data.ifblock.str);
2001 END OBJ_IF(if_mounted, 0)
2003 ERR("if_mounted needs an argument");
2004 obj->data.ifblock.s = 0;
2006 obj->data.ifblock.s = strndup(arg, text_buffer_size);
2008 END OBJ_IF(if_running, 0)
2012 snprintf(buf, 256, "pidof %s >/dev/null", arg);
2013 obj->data.ifblock.s = strndup(buf, text_buffer_size);
2015 ERR("if_running needs an argument");
2016 obj->data.ifblock.s = 0;
2022 char box[256], dst[256];
2026 /* Kapil: Changed from MAIL_FILE to
2027 current_mail_spool since the latter
2028 is a copy of the former if undefined
2029 but the latter should take precedence
2031 strncpy(box, current_mail_spool, sizeof(box));
2033 if (sscanf(arg, "%s %f", box, &n1) != 2) {
2035 strncpy(box, arg, sizeof(box));
2039 variable_substitute(box, dst, sizeof(dst));
2040 obj->data.local_mail.box = strndup(dst, text_buffer_size);
2041 obj->data.local_mail.interval = n1;
2042 END OBJ(new_mails, 0)
2044 char box[256], dst[256];
2048 strncpy(box, current_mail_spool, sizeof(box));
2050 if (sscanf(arg, "%s %f", box, &n1) != 2) {
2052 strncpy(box, arg, sizeof(box));
2056 variable_substitute(box, dst, sizeof(dst));
2057 obj->data.local_mail.box = strndup(dst, text_buffer_size);
2058 obj->data.local_mail.interval = n1;
2059 END OBJ(seen_mails, 0)
2061 char box[256], dst[256];
2065 strncpy(box, current_mail_spool, sizeof(box));
2067 if (sscanf(arg, "%s %f", box, &n1) != 2) {
2069 strncpy(box, arg, sizeof(box));
2073 variable_substitute(box, dst, sizeof(dst));
2074 obj->data.local_mail.box = strndup(dst, text_buffer_size);
2075 obj->data.local_mail.interval = n1;
2076 END OBJ(unseen_mails, 0)
2078 char box[256], dst[256];
2082 strncpy(box, current_mail_spool, sizeof(box));
2084 if (sscanf(arg, "%s %f", box, &n1) != 2) {
2086 strncpy(box, arg, sizeof(box));
2090 variable_substitute(box, dst, sizeof(dst));
2091 obj->data.local_mail.box = strndup(dst, text_buffer_size);
2092 obj->data.local_mail.interval = n1;
2093 END OBJ(flagged_mails, 0)
2095 char box[256], dst[256];
2099 strncpy(box, current_mail_spool, sizeof(box));
2101 if (sscanf(arg, "%s %f", box, &n1) != 2) {
2103 strncpy(box, arg, sizeof(box));
2107 variable_substitute(box, dst, sizeof(dst));
2108 obj->data.local_mail.box = strndup(dst, text_buffer_size);
2109 obj->data.local_mail.interval = n1;
2110 END OBJ(unflagged_mails, 0)
2112 char box[256], dst[256];
2116 strncpy(box, current_mail_spool, sizeof(box));
2118 if (sscanf(arg, "%s %f", box, &n1) != 2) {
2120 strncpy(box, arg, sizeof(box));
2124 variable_substitute(box, dst, sizeof(dst));
2125 obj->data.local_mail.box = strndup(dst, text_buffer_size);
2126 obj->data.local_mail.interval = n1;
2127 END OBJ(forwarded_mails, 0)
2129 char box[256], dst[256];
2133 strncpy(box, current_mail_spool, sizeof(box));
2135 if (sscanf(arg, "%s %f", box, &n1) != 2) {
2137 strncpy(box, arg, sizeof(box));
2141 variable_substitute(box, dst, sizeof(dst));
2142 obj->data.local_mail.box = strndup(dst, text_buffer_size);
2143 obj->data.local_mail.interval = n1;
2144 END OBJ(unforwarded_mails, 0)
2146 char box[256], dst[256];
2150 strncpy(box, current_mail_spool, sizeof(box));
2152 if (sscanf(arg, "%s %f", box, &n1) != 2) {
2154 strncpy(box, arg, sizeof(box));
2158 variable_substitute(box, dst, sizeof(dst));
2159 obj->data.local_mail.box = strndup(dst, text_buffer_size);
2160 obj->data.local_mail.interval = n1;
2161 END OBJ(replied_mails, 0)
2163 char box[256], dst[256];
2167 strncpy(box, current_mail_spool, sizeof(box));
2169 if (sscanf(arg, "%s %f", box, &n1) != 2) {
2171 strncpy(box, arg, sizeof(box));
2175 variable_substitute(box, dst, sizeof(dst));
2176 obj->data.local_mail.box = strndup(dst, text_buffer_size);
2177 obj->data.local_mail.interval = n1;
2178 END OBJ(unreplied_mails, 0)
2180 char box[256], dst[256];
2184 strncpy(box, current_mail_spool, sizeof(box));
2186 if (sscanf(arg, "%s %f", box, &n1) != 2) {
2188 strncpy(box, arg, sizeof(box));
2192 variable_substitute(box, dst, sizeof(dst));
2193 obj->data.local_mail.box = strndup(dst, text_buffer_size);
2194 obj->data.local_mail.interval = n1;
2195 END OBJ(draft_mails, 0)
2197 char box[256], dst[256];
2201 strncpy(box, current_mail_spool, sizeof(box));
2203 if (sscanf(arg, "%s %f", box, &n1) != 2) {
2205 strncpy(box, arg, sizeof(box));
2209 variable_substitute(box, dst, sizeof(dst));
2210 obj->data.local_mail.box = strndup(dst, text_buffer_size);
2211 obj->data.local_mail.interval = n1;
2212 END OBJ(trashed_mails, 0)
2214 char box[256], dst[256];
2218 strncpy(box, current_mail_spool, sizeof(box));
2220 if (sscanf(arg, "%s %f", box, &n1) != 2) {
2222 strncpy(box, arg, sizeof(box));
2226 variable_substitute(box, dst, sizeof(dst));
2227 obj->data.local_mail.box = strndup(dst, text_buffer_size);
2228 obj->data.local_mail.interval = n1;
2229 END OBJ(mboxscan, 0)
2230 obj->data.mboxscan.args = (char *) malloc(text_buffer_size);
2231 obj->data.mboxscan.output = (char *) malloc(text_buffer_size);
2232 /* if '1' (in mboxscan.c) then there was SIGUSR1, hmm */
2233 obj->data.mboxscan.output[0] = 1;
2234 strncpy(obj->data.mboxscan.args, arg, text_buffer_size);
2235 END OBJ(mem, INFO_MEM)
2236 END OBJ(memeasyfree, INFO_MEM)
2237 END OBJ(memfree, INFO_MEM)
2238 END OBJ(memmax, INFO_MEM)
2239 END OBJ(memperc, INFO_MEM)
2241 END OBJ(memgauge, INFO_MEM)
2242 SIZE_DEFAULTS(gauge);
2243 scan_gauge(arg, &obj->data.pair.a, &obj->data.pair.b);
2244 END OBJ(membar, INFO_MEM)
2246 scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
2247 END OBJ(memgraph, INFO_MEM)
2249 SIZE_DEFAULTS(graph);
2250 buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
2251 &obj->e, &obj->char_a, &obj->char_b);
2257 END OBJ(mixer, INFO_MIXER)
2258 obj->data.l = mixer_init(arg);
2259 END OBJ(mixerl, INFO_MIXER)
2260 obj->data.l = mixer_init(arg);
2261 END OBJ(mixerr, INFO_MIXER)
2262 obj->data.l = mixer_init(arg);
2264 END OBJ(mixerbar, INFO_MIXER)
2266 scan_mixer_bar(arg, &obj->data.mixerbar.l, &obj->data.mixerbar.w,
2267 &obj->data.mixerbar.h);
2268 END OBJ(mixerlbar, INFO_MIXER)
2270 scan_mixer_bar(arg, &obj->data.mixerbar.l, &obj->data.mixerbar.w,
2271 &obj->data.mixerbar.h);
2272 END OBJ(mixerrbar, INFO_MIXER)
2274 scan_mixer_bar(arg, &obj->data.mixerbar.l, &obj->data.mixerbar.w,
2275 &obj->data.mixerbar.h);
2277 END OBJ_IF(if_mixer_mute, INFO_MIXER)
2278 obj->data.ifblock.i = mixer_init(arg);
2280 END OBJ(monitor, INFO_X11)
2281 END OBJ(monitor_number, INFO_X11)
2283 END OBJ(nodename, 0)
2284 END OBJ(processes, INFO_PROCS)
2285 END OBJ(running_processes, INFO_RUN_PROCS)
2286 END OBJ(shadecolor, 0)
2288 obj->data.l = arg ? get_x11_color(arg) : default_bg_color;
2290 END OBJ(outlinecolor, 0)
2292 obj->data.l = arg ? get_x11_color(arg) : default_out_color;
2294 END OBJ(stippled_hr, 0)
2296 int a = stippled_borders, b = 1;
2299 if (sscanf(arg, "%d %d", &a, &b) != 2) {
2300 sscanf(arg, "%d", &b);
2306 obj->data.pair.a = a;
2307 obj->data.pair.b = b;
2309 END OBJ(swap, INFO_MEM)
2310 END OBJ(swapmax, INFO_MEM)
2311 END OBJ(swapperc, INFO_MEM)
2313 END OBJ(swapbar, INFO_MEM)
2315 scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
2319 obj->data.s = strndup(arg ? arg : "%F %T", text_buffer_size);
2321 obj->data.s = strndup(arg ? arg : "%F %T", text_buffer_size);
2323 char buf1[256], buf2[256], *fmt, *tz;
2327 int nArgs = sscanf(arg, "%255s %255[^\n]", buf1, buf2);
2337 obj->data.tztime.fmt = strndup(fmt ? fmt : "%F %T", text_buffer_size);
2338 obj->data.tztime.tz = tz ? strndup(tz, text_buffer_size) : NULL;
2340 END OBJ(iconv_start, 0)
2341 if (iconv_converting) {
2342 CRIT_ERR("You must stop your last iconv conversion before "
2343 "starting another");
2346 char iconv_from[CODEPAGE_LENGTH];
2347 char iconv_to[CODEPAGE_LENGTH];
2349 if (sscanf(arg, "%s %s", iconv_from, iconv_to) != 2) {
2350 CRIT_ERR("Invalid arguments for iconv_start");
2354 new_iconv = iconv_open(iconv_to, iconv_from);
2355 if (new_iconv == (iconv_t) (-1)) {
2356 ERR("Can't convert from %s to %s.", iconv_from, iconv_to);
2358 obj->a = register_iconv(&new_iconv);
2359 iconv_converting = 1;
2363 CRIT_ERR("Iconv requires arguments");
2365 END OBJ(iconv_stop, 0)
2366 iconv_converting = 0;
2369 END OBJ(totaldown, INFO_NET)
2371 obj->data.net = get_net_stat(arg);
2373 CRIT_ERR("totaldown needs argument");
2375 END OBJ(totalup, INFO_NET)
2376 obj->data.net = get_net_stat(arg);
2378 obj->data.net = get_net_stat(arg);
2380 CRIT_ERR("totalup needs argument");
2383 END OBJ_IF(if_updatenr, 0)
2384 obj->data.ifblock.i = arg ? atoi(arg) : 0;
2385 if(obj->data.ifblock.i == 0) CRIT_ERR("if_updatenr needs a number above 0 as argument");
2386 updatereset = obj->data.ifblock.i > updatereset ? obj->data.ifblock.i : updatereset;
2388 obj->data.i = arg ? atoi(arg) : 0;
2390 obj->data.i = arg ? atoi(arg) : 0;
2391 END OBJ(upspeed, INFO_NET)
2393 obj->data.net = get_net_stat(arg);
2395 CRIT_ERR("upspeed needs argument");
2397 END OBJ(upspeedf, INFO_NET)
2399 obj->data.net = get_net_stat(arg);
2401 CRIT_ERR("upspeedf needs argument");
2405 END OBJ(upspeedgraph, INFO_NET)
2407 SIZE_DEFAULTS(graph);
2408 buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
2409 &obj->e, &obj->char_a, &obj->char_b);
2411 // default to DEFAULTNETDEV
2412 buf = strndup(buf ? buf : "DEFAULTNETDEV", text_buffer_size);
2413 obj->data.net = get_net_stat(buf);
2416 END OBJ(uptime_short, INFO_UPTIME)
2417 END OBJ(uptime, INFO_UPTIME)
2418 END OBJ(user_names, INFO_USERS)
2419 END OBJ(user_times, INFO_USERS)
2420 END OBJ(user_terms, INFO_USERS)
2421 END OBJ(user_number, INFO_USERS)
2422 #if defined(__linux__)
2423 END OBJ(gw_iface, INFO_GW)
2424 END OBJ(gw_ip, INFO_GW)
2425 #endif /* !__linux__ */
2427 END OBJ(adt746xcpu, 0)
2428 END OBJ(adt746xfan, 0)
2429 #endif /* !__OpenBSD__ */
2430 #if (defined(__FreeBSD__) || defined(__FreeBSD_kernel__) \
2431 || defined(__OpenBSD__)) && (defined(i386) || defined(__i386__))
2432 END OBJ(apm_adapter, 0)
2433 END OBJ(apm_battery_life, 0)
2434 END OBJ(apm_battery_time, 0)
2435 #endif /* __FreeBSD__ */
2436 END OBJ_THREAD(imap_unseen, 0)
2439 obj->data.mail = parse_mail_args(IMAP_TYPE, arg);
2444 END OBJ_THREAD(imap_messages, 0)
2447 obj->data.mail = parse_mail_args(IMAP_TYPE, arg);
2452 END OBJ_THREAD(pop3_unseen, 0)
2455 obj->data.mail = parse_mail_args(POP3_TYPE, arg);
2460 END OBJ_THREAD(pop3_used, 0)
2463 obj->data.mail = parse_mail_args(POP3_TYPE, arg);
2471 obj->data.s = strndup(arg, text_buffer_size);
2473 ERR("smapi needs an argument");
2474 END OBJ_IF(if_smapi_bat_installed, 0)
2476 ERR("if_smapi_bat_installed needs an argument");
2477 obj->data.ifblock.s = 0;
2479 obj->data.ifblock.s = strndup(arg, text_buffer_size);
2480 END OBJ(smapi_bat_perc, 0)
2482 obj->data.s = strndup(arg, text_buffer_size);
2484 ERR("smapi_bat_perc needs an argument");
2485 END OBJ(smapi_bat_temp, 0)
2487 obj->data.s = strndup(arg, text_buffer_size);
2489 ERR("smapi_bat_temp needs an argument");
2490 END OBJ(smapi_bat_power, 0)
2492 obj->data.s = strndup(arg, text_buffer_size);
2494 ERR("smapi_bat_power needs an argument");
2495 END OBJ(smapi_bat_bar, 0)
2499 if(sscanf(arg, "%i %n", &obj->data.i, &cnt) <= 0) {
2500 ERR("first argument to smapi_bat_bar must be an integer value");
2504 arg = scan_bar(arg + cnt, &obj->a, &obj->b);
2507 ERR("smapi_bat_bar needs an argument");
2510 #define mpd_set_maxlen(name) \
2513 sscanf(arg, "%d", &i); \
2515 obj->data.i = i + 1; \
2517 ERR(#name ": invalid length argument"); \
2519 END OBJ(mpd_artist, INFO_MPD)
2520 mpd_set_maxlen(mpd_artist);
2522 END OBJ(mpd_title, INFO_MPD)
2523 mpd_set_maxlen(mpd_title);
2525 END OBJ(mpd_random, INFO_MPD) init_mpd();
2526 END OBJ(mpd_repeat, INFO_MPD) init_mpd();
2527 END OBJ(mpd_elapsed, INFO_MPD) init_mpd();
2528 END OBJ(mpd_length, INFO_MPD) init_mpd();
2529 END OBJ(mpd_track, INFO_MPD)
2530 mpd_set_maxlen(mpd_track);
2532 END OBJ(mpd_name, INFO_MPD)
2533 mpd_set_maxlen(mpd_name);
2535 END OBJ(mpd_file, INFO_MPD)
2536 mpd_set_maxlen(mpd_file);
2538 END OBJ(mpd_percent, INFO_MPD) init_mpd();
2539 END OBJ(mpd_album, INFO_MPD)
2540 mpd_set_maxlen(mpd_album);
2542 END OBJ(mpd_vol, INFO_MPD) init_mpd();
2543 END OBJ(mpd_bitrate, INFO_MPD) init_mpd();
2544 END OBJ(mpd_status, INFO_MPD) init_mpd();
2546 END OBJ(mpd_bar, INFO_MPD)
2548 scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
2551 END OBJ(mpd_smart, INFO_MPD)
2552 mpd_set_maxlen(mpd_smart);
2554 END OBJ_IF(if_mpd_playing, INFO_MPD)
2556 #undef mpd_set_maxlen
2559 END OBJ(moc_state, INFO_MOC)
2560 END OBJ(moc_file, INFO_MOC)
2561 END OBJ(moc_title, INFO_MOC)
2562 END OBJ(moc_artist, INFO_MOC)
2563 END OBJ(moc_song, INFO_MOC)
2564 END OBJ(moc_album, INFO_MOC)
2565 END OBJ(moc_totaltime, INFO_MOC)
2566 END OBJ(moc_timeleft, INFO_MOC)
2567 END OBJ(moc_curtime, INFO_MOC)
2568 END OBJ(moc_bitrate, INFO_MOC)
2569 END OBJ(moc_rate, INFO_MOC)
2572 END OBJ(xmms2_artist, INFO_XMMS2)
2573 END OBJ(xmms2_album, INFO_XMMS2)
2574 END OBJ(xmms2_title, INFO_XMMS2)
2575 END OBJ(xmms2_genre, INFO_XMMS2)
2576 END OBJ(xmms2_comment, INFO_XMMS2)
2577 END OBJ(xmms2_url, INFO_XMMS2)
2578 END OBJ(xmms2_tracknr, INFO_XMMS2)
2579 END OBJ(xmms2_bitrate, INFO_XMMS2)
2580 END OBJ(xmms2_date, INFO_XMMS2)
2581 END OBJ(xmms2_id, INFO_XMMS2)
2582 END OBJ(xmms2_duration, INFO_XMMS2)
2583 END OBJ(xmms2_elapsed, INFO_XMMS2)
2584 END OBJ(xmms2_size, INFO_XMMS2)
2585 END OBJ(xmms2_status, INFO_XMMS2)
2586 END OBJ(xmms2_percent, INFO_XMMS2)
2587 END OBJ(xmms2_bar, INFO_XMMS2)
2589 scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
2590 END OBJ(xmms2_smart, INFO_XMMS2)
2591 END OBJ(xmms2_playlist, INFO_XMMS2)
2592 END OBJ(xmms2_timesplayed, INFO_XMMS2)
2593 END OBJ_IF(if_xmms2_connected, INFO_XMMS2)
2596 END OBJ(audacious_status, INFO_AUDACIOUS)
2597 END OBJ(audacious_title, INFO_AUDACIOUS)
2599 sscanf(arg, "%d", &info.audacious.max_title_len);
2600 if (info.audacious.max_title_len > 0) {
2601 info.audacious.max_title_len++;
2603 CRIT_ERR("audacious_title: invalid length argument");
2606 END OBJ(audacious_length, INFO_AUDACIOUS)
2607 END OBJ(audacious_length_seconds, INFO_AUDACIOUS)
2608 END OBJ(audacious_position, INFO_AUDACIOUS)
2609 END OBJ(audacious_position_seconds, INFO_AUDACIOUS)
2610 END OBJ(audacious_bitrate, INFO_AUDACIOUS)
2611 END OBJ(audacious_frequency, INFO_AUDACIOUS)
2612 END OBJ(audacious_channels, INFO_AUDACIOUS)
2613 END OBJ(audacious_filename, INFO_AUDACIOUS)
2614 END OBJ(audacious_playlist_length, INFO_AUDACIOUS)
2615 END OBJ(audacious_playlist_position, INFO_AUDACIOUS)
2616 END OBJ(audacious_main_volume, INFO_AUDACIOUS)
2617 END OBJ(audacious_bar, INFO_AUDACIOUS)
2619 scan_bar(arg, &obj->a, &obj->b);
2622 END OBJ(bmpx_title, INFO_BMPX)
2623 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
2624 END OBJ(bmpx_artist, INFO_BMPX)
2625 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
2626 END OBJ(bmpx_album, INFO_BMPX)
2627 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
2628 END OBJ(bmpx_track, INFO_BMPX)
2629 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
2630 END OBJ(bmpx_uri, INFO_BMPX)
2631 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
2632 END OBJ(bmpx_bitrate, INFO_BMPX)
2633 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
2639 char *userid = (char *) malloc(20 * sizeof(char));
2640 char *apikey = (char *) malloc(64 * sizeof(char));
2641 char *charid = (char *) malloc(20 * sizeof(char));
2643 argc = sscanf(arg, "%20s %64s %20s", userid, apikey, charid);
2644 obj->data.eve.charid = charid;
2645 obj->data.eve.userid = userid;
2646 obj->data.eve.apikey = apikey;
2650 CRIT_ERR("eve needs arguments: <userid> <apikey> <characterid>");
2656 int argc, delay, act_par;
2657 unsigned int nrspaces = 0;
2658 char *uri = (char *) malloc(128 * sizeof(char));
2659 char *action = (char *) malloc(64 * sizeof(char));
2661 argc = sscanf(arg, "%127s %d %63s %d %u", uri, &delay, action,
2662 &act_par, &nrspaces);
2663 obj->data.rss.uri = uri;
2664 obj->data.rss.delay = delay;
2665 obj->data.rss.action = action;
2666 obj->data.rss.act_par = act_par;
2667 obj->data.rss.nrspaces = nrspaces;
2671 CRIT_ERR("rss needs arguments: <uri> <delay in minutes> <action> "
2672 "[act_par] [spaces in front]");
2678 obj->data.s = strndup(arg, text_buffer_size);
2680 CRIT_ERR("lua needs arguments: <function name> [function parameters]");
2682 END OBJ(lua_parse, 0)
2684 obj->data.s = strndup(arg, text_buffer_size);
2686 CRIT_ERR("lua_parse needs arguments: <function name> [function parameters]");
2688 END OBJ(lua_read_parse, 0)
2690 obj->data.s = strndup(arg, text_buffer_size);
2692 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]");
2707 END OBJ(lua_graph, 0)
2708 SIZE_DEFAULTS(graph);
2710 arg = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
2711 &obj->e, &obj->char_a, &obj->char_b);
2713 obj->data.s = strndup(arg, text_buffer_size);
2715 CRIT_ERR("lua_graph needs arguments: <\"normal\"|\"log\"> <height>,<width> <gradient colour 1> <gradient colour 2> <scale> <function name> [function parameters]");
2718 CRIT_ERR("lua_graph needs arguments: <\"normal\"|\"log\"> <height>,<width> <gradient colour 1> <gradient colour 2> <scale> <function name> [function parameters]");
2720 END OBJ(lua_gauge, 0)
2721 SIZE_DEFAULTS(gauge);
2723 arg = scan_gauge(arg, &obj->a, &obj->b);
2725 obj->data.s = strndup(arg, text_buffer_size);
2727 CRIT_ERR("lua_gauge needs arguments: <height>,<width> <function name> [function parameters]");
2730 CRIT_ERR("lua_gauge needs arguments: <height>,<width> <function name> [function parameters]");
2733 #endif /* HAVE_LUA */
2736 if (scan_hddtemp(arg, &obj->data.hddtemp.dev,
2737 &obj->data.hddtemp.addr, &obj->data.hddtemp.port)) {
2738 ERR("hddtemp needs arguments");
2739 obj->type = OBJ_text;
2740 obj->data.s = strndup("${hddtemp}", text_buffer_size);
2741 obj->data.hddtemp.update_time = 0;
2743 obj->data.hddtemp.temp = NULL;
2745 #ifdef TCP_PORT_MONITOR
2746 END OBJ(tcp_portmon, INFO_TCP_PORT_MONITOR)
2747 tcp_portmon_init(arg, &obj->data.tcp_port_monitor);
2749 END OBJ(entropy_avail, INFO_ENTROPY)
2750 END OBJ(entropy_poolsize, INFO_ENTROPY)
2752 END OBJ(entropy_bar, INFO_ENTROPY)
2754 scan_bar(arg, &obj->a, &obj->b);
2759 obj->data.scroll.step = 1;
2760 if (arg && sscanf(arg, "%u %n", &obj->data.scroll.show, &n1) > 0) {
2761 if (sscanf(arg + n1, "%u %n", &obj->data.scroll.step, &n2) > 0)
2763 obj->data.scroll.text = strndup(arg + n1, text_buffer_size);
2764 obj->data.scroll.start = 0;
2765 obj->sub = malloc(sizeof(struct text_object));
2766 extract_variable_text_internal(obj->sub,
2767 obj->data.scroll.text, 0);
2769 CRIT_ERR("scroll needs arguments: <length> [<step>] <text>");
2774 unsigned int indenting = 0; //vars can be used as args for other vars
2777 startvar[0] = endvar[0] = startvar[1] = endvar[1] = -1;
2779 for(i=0; arg[i] != 0 && j < 2; i++) {
2780 if(startvar[j] == -1) {
2784 }else if(endvar[j] == -1) {
2787 }else if(arg[i] == '}') {
2790 if (indenting == 0 && arg[i+1] < 48) { //<48 has 0, $, and the most used chars not used in varnames but not { or }
2796 if(startvar[0] >= 0 && endvar[0] >= 0 && startvar[1] >= 0 && endvar[1] >= 0) {
2797 obj->data.combine.left=malloc(endvar[0]-startvar[0]+1);
2798 obj->data.combine.seperation=malloc(startvar[1]-endvar[0]+1);
2799 obj->data.combine.right=malloc(endvar[1]-startvar[1]+1);
2800 strncpy(obj->data.combine.left, arg+startvar[0], endvar[0]-startvar[0]); obj->data.combine.left[endvar[0]-startvar[0]]=0;
2801 strncpy(obj->data.combine.seperation, arg+endvar[0], startvar[1]-endvar[0]); obj->data.combine.seperation[startvar[1]-endvar[0]]=0;
2802 strncpy(obj->data.combine.right, arg+startvar[1], endvar[1]-startvar[1]); obj->data.combine.right[endvar[1]-startvar[1]]=0;
2803 obj->sub = malloc(sizeof(struct text_object));
2804 extract_variable_text_internal(obj->sub, obj->data.combine.left, 0);
2805 obj->sub->sub = malloc(sizeof(struct text_object));
2806 extract_variable_text_internal(obj->sub->sub, obj->data.combine.right, 0);
2808 CRIT_ERR("combine needs arguments: <text1> <text2>");
2811 CRIT_ERR("combine needs arguments: <text1> <text2>");
2816 CRIT_ERR("nvidia needs an argument\n");
2817 } else if (set_nvidia_type(&obj->data.nvidia, arg)) {
2818 CRIT_ERR("nvidia: invalid argument"
2819 " specified: '%s'\n", arg);
2824 END OBJ(apcupsd, INFO_APCUPSD)
2828 if (sscanf(arg, "%63s %d", host, &port) != 2) {
2829 CRIT_ERR("apcupsd needs arguments: <host> <port>");
2831 info.apcupsd.port = htons(port);
2832 strncpy(info.apcupsd.host, host, sizeof(info.apcupsd.host));
2835 CRIT_ERR("apcupsd needs arguments: <host> <port>");
2837 END OBJ(apcupsd_name, INFO_APCUPSD)
2838 END OBJ(apcupsd_model, INFO_APCUPSD)
2839 END OBJ(apcupsd_upsmode, INFO_APCUPSD)
2840 END OBJ(apcupsd_cable, INFO_APCUPSD)
2841 END OBJ(apcupsd_status, INFO_APCUPSD)
2842 END OBJ(apcupsd_linev, INFO_APCUPSD)
2843 END OBJ(apcupsd_load, INFO_APCUPSD)
2845 END OBJ(apcupsd_loadbar, INFO_APCUPSD)
2847 scan_bar(arg, &obj->a, &obj->b);
2848 END OBJ(apcupsd_loadgraph, INFO_APCUPSD)
2850 SIZE_DEFAULTS(graph);
2851 buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
2852 &obj->e, &obj->char_a, &obj->char_b);
2854 END OBJ(apcupsd_loadgauge, INFO_APCUPSD)
2855 SIZE_DEFAULTS(gauge);
2856 scan_gauge(arg, &obj->a, &obj->b);
2858 END OBJ(apcupsd_charge, INFO_APCUPSD)
2859 END OBJ(apcupsd_timeleft, INFO_APCUPSD)
2860 END OBJ(apcupsd_temp, INFO_APCUPSD)
2861 END OBJ(apcupsd_lastxfer, INFO_APCUPSD)
2862 #endif /* APCUPSD */
2866 ERR("unknown variable %s", s);
2867 obj->type = OBJ_text;
2868 snprintf(buf, 256, "${%s}", s);
2869 obj->data.s = strndup(buf, text_buffer_size);
2876 static struct text_object *create_plain_text(const char *s)
2878 struct text_object *obj;
2880 if (s == NULL || *s == '\0') {
2884 obj = new_text_object_internal();
2886 obj->type = OBJ_text;
2887 obj->data.s = strndup(s, text_buffer_size);
2891 /* backslash_escape - do the actual substitution task for template objects
2893 * The field templates is used for substituting the \N occurences. Set it to
2894 * NULL to leave them as they are.
2896 static char *backslash_escape(const char *src, char **templates, unsigned int template_count)
2900 unsigned int dup_idx = 0, dup_len;
2902 dup_len = strlen(src) + 1;
2903 src_dup = malloc(dup_len * sizeof(char));
2911 if (*(p + 1) == '\\') {
2912 src_dup[dup_idx++] = '\\';
2914 } else if (*(p + 1) == ' ') {
2915 src_dup[dup_idx++] = ' ';
2917 } else if (*(p + 1) == 'n') {
2918 src_dup[dup_idx++] = '\n';
2920 } else if (templates) {
2921 unsigned int tmpl_num;
2923 if ((sscanf(p + 1, "%u%n", &tmpl_num, &digits) <= 0) ||
2924 (tmpl_num > template_count))
2926 dup_len += strlen(templates[tmpl_num - 1]);
2927 src_dup = realloc(src_dup, dup_len * sizeof(char));
2928 sprintf(src_dup + dup_idx, "%s", templates[tmpl_num - 1]);
2929 dup_idx += strlen(templates[tmpl_num - 1]);
2934 src_dup[dup_idx++] = *p;
2939 src_dup[dup_idx] = '\0';
2940 src_dup = realloc(src_dup, (strlen(src_dup) + 1) * sizeof(char));
2944 /* handle_template_object - core logic of the template object
2946 * use config variables like this:
2947 * template1 = "$\1\2"
2948 * template2 = "\1: ${fs_bar 4,100 \2} ${fs_used \2} / ${fs_size \2}"
2950 * and use them like this:
2951 * ${template1 node name}
2952 * ${template2 root /}
2953 * ${template2 cdrom /mnt/cdrom}
2955 static char *handle_template(const char *tmpl, const char *args)
2957 char *args_dup, *p, *p_old;
2958 char **argsp = NULL;
2959 unsigned int argcnt = 0, template_idx, i;
2962 if ((sscanf(tmpl, "template%u", &template_idx) != 1) ||
2966 args_dup = strdup(args);
2969 while (*p && (*p == ' ' && *(p - 1) != '\\'))
2971 if (*(p - 1) == '\\')
2974 while (*p && (*p != ' ' || *(p - 1) == '\\'))
2980 argsp = realloc(argsp, ++argcnt * sizeof(char *));
2981 argsp[argcnt - 1] = p_old;
2983 for (i = 0; i < argcnt; i++) {
2985 tmp = backslash_escape(argsp[i], NULL, 0);
2986 DBGP2("%s: substituted arg '%s' to '%s'", tmpl, argsp[i], tmp);
2990 eval_text = backslash_escape(template[template_idx], argsp, argcnt);
2991 DBGP("substituted %s, output is '%s'", tmpl, eval_text);
2993 for (i = 0; i < argcnt; i++)
2999 static char *find_and_replace_templates(const char *inbuf)
3001 char *outbuf, *indup, *p, *o, *templ, *args, *tmpl_out;
3004 outlen = strlen(inbuf) + 1;
3005 o = outbuf = calloc(outlen, sizeof(char));
3006 memset(outbuf, 0, outlen * sizeof(char));
3008 p = indup = strdup(inbuf);
3010 while (*p && *p != '$')
3016 if (strncmp(p, "$template", 9) && strncmp(p, "${template", 10)) {
3021 if (*(p + 1) == '{') {
3043 tmpl_out = handle_template(templ, args);
3045 outlen += strlen(tmpl_out);
3046 outbuf = realloc(outbuf, outlen * sizeof(char));
3047 strcat (outbuf, tmpl_out);
3049 o = outbuf + strlen(outbuf);
3051 ERR("failed to handle template '%s' with args '%s'", templ, args);
3055 outbuf = realloc(outbuf, (strlen(outbuf) + 1) * sizeof(char));
3060 static int text_contains_templates(const char *text)
3062 if (strcasestr(text, "${template") != NULL)
3064 if (strcasestr(text, "$template") != NULL)
3069 static void strfold(char *start, int count)
3072 for (curplace = start + count; *curplace != 0; curplace++) {
3073 *(curplace - count) = *curplace;
3075 *(curplace - count - 1) = 0;
3078 static size_t remove_comments(char *string)
3080 char *curplace, *curplace2;
3082 for (curplace = string; *curplace != 0; curplace++) {
3083 if (*curplace == '\\' && *(curplace + 1) == '#') {
3084 // strcpy can't be used for overlapping strings
3085 strfold(curplace, 1);
3087 } else if (*curplace == '#') {
3088 // remove everything until we hit a '\n'
3089 curplace2 = curplace;
3090 while (*curplace2) {
3092 if (*curplace2 == '\n' &&
3093 *(curplace2 + 1) != '#') break;
3096 strfold(curplace, curplace2 - curplace);
3097 folded += curplace2 - curplace;
3106 static int extract_variable_text_internal(struct text_object *retval, const char *const_p, char allow_threaded)
3108 struct text_object *obj;
3109 char *p, *s, *orig_p;
3111 void *ifblock_opaque = NULL;
3116 p = strndup(const_p, max_user_text - 1);
3117 while (text_contains_templates(p)) {
3119 tmp = find_and_replace_templates(p);
3125 if (strcmp(p, const_p)) {
3126 DBGP("replaced all templates in text: input is\n'%s'\noutput is\n'%s'", const_p, p);
3128 DBGP("no templates to replace");
3131 memset(retval, 0, sizeof(struct text_object));
3133 line = global_text_lines;
3141 obj = create_plain_text(s);
3143 append_object(retval, obj);
3153 /* variable is either $foo or ${foo} */
3155 unsigned int brl = 1, brr = 0;
3159 while (*p && brl != brr) {
3174 while (*p && (isalnum((int) *p) || *p == '_')) {
3179 /* copy variable to buffer */
3180 len = (p - s > 255) ? 255 : (p - s);
3181 strncpy(buf, s, len);
3189 /* search for variable in environment */
3193 obj = create_plain_text(var);
3195 append_object(retval, obj);
3200 /* if variable wasn't found in environment, use some special */
3205 if (strchr(buf, ' ')) {
3206 arg = strchr(buf, ' ');
3209 while (isspace((int) *arg)) {
3217 /* lowercase variable name */
3220 *tmp_p = tolower(*tmp_p);
3224 obj = construct_text_object(buf, arg,
3225 line, allow_threaded,
3228 append_object(retval, obj);
3232 obj = create_plain_text("$");
3235 append_object(retval, obj);
3238 } else if (*p == '#') {
3244 obj = create_plain_text(s);
3246 append_object(retval, obj);
3249 if (!ifblock_stack_empty(&ifblock_opaque)) {
3250 ERR("one or more $endif's are missing");
3257 static void extract_variable_text(const char *p)
3259 free_text_objects(&global_root_object, 0);
3273 extract_variable_text_internal(&global_root_object, p, 1);
3276 int parse_conky_vars(struct text_object *root, char *txt, char *p, struct information *cur)
3278 extract_variable_text_internal(root, txt, 0);
3279 generate_text_internal(p, max_user_text, *root, cur);
3283 static inline struct mail_s *ensure_mail_thread(struct text_object *obj,
3284 void *thread(void *), const char *text)
3286 if (obj->char_b && info.mail) {
3287 // this means we use info
3288 if (!info.mail->p_timed_thread) {
3289 info.mail->p_timed_thread =
3290 timed_thread_create(thread,
3291 (void *) info.mail, info.mail->interval * 1000000);
3292 if (!info.mail->p_timed_thread) {
3293 ERR("Error creating %s timed thread", text);
3295 timed_thread_register(info.mail->p_timed_thread,
3296 &info.mail->p_timed_thread);
3297 if (timed_thread_run(info.mail->p_timed_thread)) {
3298 ERR("Error running %s timed thread", text);
3302 } else if (obj->data.mail) {
3303 // this means we use obj
3304 if (!obj->data.mail->p_timed_thread) {
3305 obj->data.mail->p_timed_thread =
3306 timed_thread_create(thread,
3307 (void *) obj->data.mail,
3308 obj->data.mail->interval * 1000000);
3309 if (!obj->data.mail->p_timed_thread) {
3310 ERR("Error creating %s timed thread", text);
3312 timed_thread_register(obj->data.mail->p_timed_thread,
3313 &obj->data.mail->p_timed_thread);
3314 if (timed_thread_run(obj->data.mail->p_timed_thread)) {
3315 ERR("Error running %s timed thread", text);
3318 return obj->data.mail;
3319 } else if (!obj->a) {
3320 // something is wrong, warn once then stop
3321 ERR("There's a problem with your mail settings. "
3322 "Check that the global mail settings are properly defined"
3323 " (line %li).", obj->line);
3329 char *format_time(unsigned long timeval, const int width)
3332 unsigned long nt; // narrow time, for speed on 32-bit
3333 unsigned cc; // centiseconds
3334 unsigned nn; // multi-purpose whatever
3337 cc = nt % 100; // centiseconds past second
3338 nt /= 100; // total seconds
3339 nn = nt % 60; // seconds past the minute
3340 nt /= 60; // total minutes
3341 if (width >= snprintf(buf, sizeof buf, "%lu:%02u.%02u",
3343 return strndup(buf, text_buffer_size);
3345 if (width >= snprintf(buf, sizeof buf, "%lu:%02u", nt, nn)) {
3346 return strndup(buf, text_buffer_size);
3348 nn = nt % 60; // minutes past the hour
3349 nt /= 60; // total hours
3350 if (width >= snprintf(buf, sizeof buf, "%lu,%02u", nt, nn)) {
3351 return strndup(buf, text_buffer_size);
3353 nn = nt; // now also hours
3354 if (width >= snprintf(buf, sizeof buf, "%uh", nn)) {
3355 return strndup(buf, text_buffer_size);
3357 nn /= 24; // now days
3358 if (width >= snprintf(buf, sizeof buf, "%ud", nn)) {
3359 return strndup(buf, text_buffer_size);
3361 nn /= 7; // now weeks
3362 if (width >= snprintf(buf, sizeof buf, "%uw", nn)) {
3363 return strndup(buf, text_buffer_size);
3365 // well shoot, this outta' fit...
3366 return strndup("<inf>", text_buffer_size);
3369 //remove backspaced chars, example: "dog^H^H^Hcat" becomes "cat"
3370 //string has to end with \0 and it's length should fit in a int
3372 void remove_deleted_chars(char *string){
3374 while(string[i] != 0){
3375 if(string[i] == BACKSPACE){
3377 strcpy( &(string[i-1]), &(string[i+1]) );
3379 }else strcpy( &(string[i]), &(string[i+1]) ); //necessary for ^H's at the start of a string
3384 static inline void format_media_player_time(char *buf, const int size,
3387 int days, hours, minutes;
3389 days = seconds / (24 * 60 * 60);
3390 seconds %= (24 * 60 * 60);
3391 hours = seconds / (60 * 60);
3392 seconds %= (60 * 60);
3393 minutes = seconds / 60;
3397 snprintf(buf, size, "%i days %i:%02i:%02i", days,
3398 hours, minutes, seconds);
3399 } else if (hours > 0) {
3400 snprintf(buf, size, "%i:%02i:%02i", hours, minutes,
3403 snprintf(buf, size, "%i:%02i", minutes, seconds);
3407 static inline double get_barnum(char *buf)
3419 if (sscanf(buf, "%lf", &barnum) == 0) {
3420 ERR("reading exec value failed (perhaps it's not the "
3421 "correct format?)");
3424 if (barnum > 100.0 || barnum < 0.0) {
3425 ERR("your exec value is not between 0 and 100, "
3426 "therefore it will be ignored");
3432 static void generate_text_internal(char *p, int p_max_size,
3433 struct text_object root, struct information *cur)
3435 struct text_object *obj;
3437 /* for the OBJ_top* handler */
3438 struct process **needed = 0;
3441 char buff_in[p_max_size];
3443 iconv_converting = 0;
3448 while (obj && p_max_size > 0) {
3449 needed = 0; // reset for top stuff
3451 /* IFBLOCK jumping algorithm
3453 * This is easier as it looks like:
3454 * - each IF checks it's condition
3455 * - on FALSE: call DO_JUMP
3456 * - on TRUE: don't care
3457 * - each ELSE calls DO_JUMP unconditionally
3458 * - each ENDIF is silently being ignored
3461 * DO_JUMP overwrites the "obj" variable of the loop and sets it to the target
3462 * (i.e. the corresponding ELSE or ENDIF). After that, processing for the given
3463 * object can continue, free()ing stuff e.g., then the for-loop does the rest: as
3464 * regularly, "obj" is being updated to point to obj->next, so object parsing
3465 * continues right after the corresponding ELSE or ENDIF. This means that if we
3466 * find an ELSE, it's corresponding IF must not have jumped, so we need to jump
3467 * always. If we encounter an ENDIF, it's corresponding IF or ELSE has not
3468 * jumped, and there is nothing to do.
3472 obj = obj->data.ifblock.next; \
3475 #define OBJ(a) break; case OBJ_##a:
3477 switch (obj->type) {
3479 ERR("not implemented obj type %d", obj->type);
3482 temp_print(p, p_max_size, get_acpi_temperature(obj->data.i), TEMP_CELSIUS);
3484 #endif /* !__OpenBSD__ */
3487 obj->a = get_freq(p, p_max_size, "%.0f", 1,
3488 obj->data.cpu_index);
3494 obj->a = get_freq(p, p_max_size, "%'.2f", 1000,
3495 obj->data.cpu_index);
3497 /* OpenBSD has no such flag (SUSv2) */
3498 obj->a = get_freq(p, p_max_size, "%.2f", 1000,
3499 obj->data.cpu_index);
3503 #if defined(__linux__)
3506 obj->a = get_voltage(p, p_max_size, "%.0f", 1,
3507 obj->data.cpu_index);
3512 obj->a = get_voltage(p, p_max_size, "%'.3f", 1000,
3513 obj->data.cpu_index);
3518 OBJ(wireless_essid) {
3519 snprintf(p, p_max_size, "%s", obj->data.net->essid);
3521 OBJ(wireless_mode) {
3522 snprintf(p, p_max_size, "%s", obj->data.net->mode);
3524 OBJ(wireless_bitrate) {
3525 snprintf(p, p_max_size, "%s", obj->data.net->bitrate);
3528 snprintf(p, p_max_size, "%s", obj->data.net->ap);
3530 OBJ(wireless_link_qual) {
3531 spaced_print(p, p_max_size, "%d", 4,
3532 obj->data.net->link_qual);
3534 OBJ(wireless_link_qual_max) {
3535 spaced_print(p, p_max_size, "%d", 4,
3536 obj->data.net->link_qual_max);
3538 OBJ(wireless_link_qual_perc) {
3539 if (obj->data.net->link_qual_max > 0) {
3540 spaced_print(p, p_max_size, "%.0f", 5,
3541 (double) obj->data.net->link_qual /
3542 obj->data.net->link_qual_max * 100);
3544 spaced_print(p, p_max_size, "unk", 5);
3547 OBJ(wireless_link_bar) {
3548 new_bar(p, obj->a, obj->b, ((double) obj->data.net->link_qual /
3549 obj->data.net->link_qual_max) * 255.0);
3551 #endif /* HAVE_IWLIB */
3553 #endif /* __linux__ */
3557 get_adt746x_cpu(p, p_max_size);
3560 get_adt746x_fan(p, p_max_size);
3563 get_acpi_fan(p, p_max_size);
3565 OBJ(acpiacadapter) {
3566 get_acpi_ac_adapter(p, p_max_size);
3569 get_battery_stuff(p, p_max_size, obj->data.s, BATTERY_STATUS);
3572 get_battery_stuff(p, p_max_size, obj->data.s, BATTERY_TIME);
3574 OBJ(battery_percent) {
3575 percent_print(p, p_max_size, get_battery_perct(obj->data.s));
3579 new_bar(p, obj->a, obj->b, get_battery_perct_bar(obj->data.s));
3582 OBJ(battery_short) {
3583 get_battery_short_status(p, p_max_size, obj->data.s);
3585 #endif /* __OpenBSD__ */
3588 human_readable(cur->buffers * 1024, p, 255);
3591 human_readable(cur->cached * 1024, p, 255);
3594 if (obj->data.cpu_index > info.cpu_count) {
3595 ERR("obj->data.cpu_index %i info.cpu_count %i",
3596 obj->data.cpu_index, info.cpu_count);
3597 CRIT_ERR("attempting to use more CPUs than you have!");
3599 percent_print(p, p_max_size,
3600 round_to_int(cur->cpu_usage[obj->data.cpu_index] * 100.0));
3604 new_gauge(p, obj->a, obj->b,
3605 round_to_int(cur->cpu_usage[obj->data.cpu_index] * 255.0));
3607 new_bar(p, obj->a, obj->b,
3608 round_to_int(cur->cpu_usage[obj->data.cpu_index] * 255.0));
3611 new_graph(p, obj->a, obj->b, obj->c, obj->d,
3612 round_to_int(cur->cpu_usage[obj->data.cpu_index] * 100),
3613 100, 1, obj->char_a, obj->char_b);
3616 new_graph(p, obj->a, obj->b, obj->c, obj->d, cur->loadavg[0],
3617 obj->e, 1, obj->char_a, obj->char_b);
3620 new_fg(p, obj->data.l);
3653 OBJ(conky_version) {
3654 snprintf(p, p_max_size, "%s", VERSION);
3656 OBJ(conky_build_date) {
3657 snprintf(p, p_max_size, "%s", BUILD_DATE);
3659 OBJ(conky_build_arch) {
3660 snprintf(p, p_max_size, "%s", BUILD_ARCH);
3662 #if defined(__linux__)
3664 snprintf(p, p_max_size, "%s",
3665 get_disk_protect_queue(obj->data.s));
3668 snprintf(p, p_max_size, "%s", i8k.version);
3671 snprintf(p, p_max_size, "%s", i8k.bios);
3674 snprintf(p, p_max_size, "%s", i8k.serial);
3679 sscanf(i8k.cpu_temp, "%d", &cpu_temp);
3680 temp_print(p, p_max_size, (double)cpu_temp, TEMP_CELSIUS);
3682 OBJ(i8k_left_fan_status) {
3683 int left_fan_status;
3685 sscanf(i8k.left_fan_status, "%d", &left_fan_status);
3686 if (left_fan_status == 0) {
3687 snprintf(p, p_max_size, "off");
3689 if (left_fan_status == 1) {
3690 snprintf(p, p_max_size, "low");
3692 if (left_fan_status == 2) {
3693 snprintf(p, p_max_size, "high");
3696 OBJ(i8k_right_fan_status) {
3697 int right_fan_status;
3699 sscanf(i8k.right_fan_status, "%d", &right_fan_status);
3700 if (right_fan_status == 0) {
3701 snprintf(p, p_max_size, "off");
3703 if (right_fan_status == 1) {
3704 snprintf(p, p_max_size, "low");
3706 if (right_fan_status == 2) {
3707 snprintf(p, p_max_size, "high");
3710 OBJ(i8k_left_fan_rpm) {
3711 snprintf(p, p_max_size, "%s", i8k.left_fan_rpm);
3713 OBJ(i8k_right_fan_rpm) {
3714 snprintf(p, p_max_size, "%s", i8k.right_fan_rpm);
3716 OBJ(i8k_ac_status) {
3719 sscanf(i8k.ac_status, "%d", &ac_status);
3720 if (ac_status == -1) {
3721 snprintf(p, p_max_size, "disabled (read i8k docs)");
3723 if (ac_status == 0) {
3724 snprintf(p, p_max_size, "off");
3726 if (ac_status == 1) {
3727 snprintf(p, p_max_size, "on");
3730 OBJ(i8k_buttons_status) {
3731 snprintf(p, p_max_size, "%s", i8k.buttons_status);
3735 get_ibm_acpi_fan(p, p_max_size);
3738 get_ibm_acpi_temps();
3739 temp_print(p, p_max_size,
3740 ibm_acpi.temps[obj->data.sensor], TEMP_CELSIUS);
3743 get_ibm_acpi_volume(p, p_max_size);
3745 OBJ(ibm_brightness) {
3746 get_ibm_acpi_brightness(p, p_max_size);
3749 /* information from sony_laptop kernel module
3750 * /sys/devices/platform/sony-laptop */
3751 OBJ(sony_fanspeed) {
3752 get_sony_fanspeed(p, p_max_size);
3755 if (!cur->gw_info.count) {
3760 snprintf(p, p_max_size, "%s", cur->gw_info.iface);
3763 snprintf(p, p_max_size, "%s", cur->gw_info.ip);
3766 snprintf(p, p_max_size, "%d", get_laptop_mode());
3769 get_powerbook_batt_info(p, p_max_size, obj->data.i);
3771 #endif /* __linux__ */
3772 #if (defined(__FreeBSD__) || defined(__linux__))
3774 if ((obj->data.ifblock.s)
3775 && (!interface_up(obj->data.ifblock.s))) {
3781 OBJ(obsd_sensors_temp) {
3782 obsd_sensors.device = sensor_device;
3783 update_obsd_sensors();
3784 temp_print(p, p_max_size,
3785 obsd_sensors.temp[obsd_sensors.device][obj->data.sensor],
3788 OBJ(obsd_sensors_fan) {
3789 obsd_sensors.device = sensor_device;
3790 update_obsd_sensors();
3791 snprintf(p, p_max_size, "%d",
3792 obsd_sensors.fan[obsd_sensors.device][obj->data.sensor]);
3794 OBJ(obsd_sensors_volt) {
3795 obsd_sensors.device = sensor_device;
3796 update_obsd_sensors();
3797 snprintf(p, p_max_size, "%.2f",
3798 obsd_sensors.volt[obsd_sensors.device][obj->data.sensor]);
3801 get_obsd_vendor(p, p_max_size);
3804 get_obsd_product(p, p_max_size);
3806 #endif /* __OpenBSD__ */
3809 new_font(p, obj->data.s);
3812 /* TODO: move this correction from kB to kB/s elsewhere
3813 * (or get rid of it??) */
3815 human_readable((obj->data.diskio->current / update_interval) * 1024LL,
3819 human_readable((obj->data.diskio->current_write / update_interval) * 1024LL,
3823 human_readable((obj->data.diskio->current_read / update_interval) * 1024LL,
3828 new_graph(p, obj->a, obj->b, obj->c, obj->d,
3829 obj->data.diskio->current, obj->e, 1, obj->char_a, obj->char_b);
3831 OBJ(diskiograph_read) {
3832 new_graph(p, obj->a, obj->b, obj->c, obj->d,
3833 obj->data.diskio->current_read, obj->e, 1, obj->char_a, obj->char_b);
3835 OBJ(diskiograph_write) {
3836 new_graph(p, obj->a, obj->b, obj->c, obj->d,
3837 obj->data.diskio->current_write, obj->e, 1, obj->char_a, obj->char_b);
3841 human_readable(obj->data.net->recv_speed, p, 255);
3844 spaced_print(p, p_max_size, "%.1f", 8,
3845 obj->data.net->recv_speed / 1024.0);
3848 OBJ(downspeedgraph) {
3849 new_graph(p, obj->a, obj->b, obj->c, obj->d,
3850 obj->data.net->recv_speed / 1024.0, obj->e, 1, obj->char_a, obj->char_b);
3854 /* Since we see you, you're if has not jumped.
3855 * Do Ninja jump here: without leaving traces.
3856 * This is to prevent us from stale jumped flags.
3858 obj = obj->data.ifblock.next;
3862 /* harmless object, just ignore */
3866 if ((obj->data.net->addr.sa_data[2] & 255) == 0
3867 && (obj->data.net->addr.sa_data[3] & 255) == 0
3868 && (obj->data.net->addr.sa_data[4] & 255) == 0
3869 && (obj->data.net->addr.sa_data[5] & 255) == 0) {
3870 snprintf(p, p_max_size, "No Address");
3872 snprintf(p, p_max_size, "%u.%u.%u.%u",
3873 obj->data.net->addr.sa_data[2] & 255,
3874 obj->data.net->addr.sa_data[3] & 255,
3875 obj->data.net->addr.sa_data[4] & 255,
3876 obj->data.net->addr.sa_data[5] & 255);
3879 #if defined(__linux__)
3881 if(NULL != obj->data.net->addrs && strlen(obj->data.net->addrs) > 2)
3883 obj->data.net->addrs[strlen(obj->data.net->addrs) - 2] = 0; /* remove ", " from end of string */
3884 strcpy(p, obj->data.net->addrs);
3887 strcpy(p, "0.0.0.0");
3889 #endif /* __linux__ */
3890 #if defined(IMLIB2) && defined(X11)
3892 /* doesn't actually draw anything, just queues it omp. the
3893 * image will get drawn after the X event loop */
3894 cimlib_add_image(obj->data.s);
3898 struct information *tmp_info;
3899 struct text_object subroot, subroot2;
3901 tmp_info = malloc(sizeof(struct information));
3902 memcpy(tmp_info, cur, sizeof(struct information));
3903 parse_conky_vars(&subroot, obj->data.s, p, tmp_info);
3904 DBGP("evaluated '%s' to '%s'", obj->data.s, p);
3905 parse_conky_vars(&subroot2, p, p, tmp_info);
3907 free_text_objects(&subroot, 1);
3908 free_text_objects(&subroot2, 1);
3912 read_exec(obj->data.s, p, text_buffer_size);
3913 remove_deleted_chars(p);
3916 struct information *tmp_info;
3917 struct text_object subroot;
3919 read_exec(obj->data.s, p, text_buffer_size);
3921 tmp_info = malloc(sizeof(struct information));
3922 memcpy(tmp_info, cur, sizeof(struct information));
3923 parse_conky_vars(&subroot, p, p, tmp_info);
3925 free_text_objects(&subroot, 1);
3932 read_exec(obj->data.s, p, text_buffer_size);
3933 barnum = get_barnum(p); /*using the same function*/
3935 if (barnum >= 0.0) {
3937 new_gauge(p, obj->a, obj->b, round_to_int(barnum * 255.0));
3944 read_exec(obj->data.s, p, text_buffer_size);
3945 barnum = get_barnum(p);
3947 if (barnum >= 0.0) {
3949 if(output_methods & TO_X) {
3951 new_bar(p, obj->a, obj->b, round_to_int(barnum * 255.0));
3954 if(!obj->a) obj->a = DEFAULT_BAR_WIDTH_NO_X;
3955 new_bar_in_shell(p, p_max_size, barnum, obj->a);
3963 char showaslog = FALSE;
3964 char tempgrad = FALSE;
3966 char *cmd = obj->data.s;
3968 if (strncasecmp(obj->data.execi.cmd, LOGGRAPH" ", strlen(LOGGRAPH" ")) == EQUAL) {
3970 cmd = cmd + strlen(LOGGRAPH" ") * sizeof(char);
3971 } else if(strncasecmp(obj->data.s, NORMGRAPH" ", strlen(NORMGRAPH" ")) == EQUAL) {
3972 cmd = cmd + strlen(NORMGRAPH" ") * sizeof(char);
3974 if (strstr(cmd, " "TEMPGRAD) && strlen(cmd) > strlen(" "TEMPGRAD)) {
3976 cmd += strlen(" "TEMPGRAD);
3978 read_exec(cmd, p, text_buffer_size);
3979 barnum = get_barnum(p);
3981 if (barnum >= 0.0) {
3982 new_graph(p, obj->a, obj->b, obj->c, obj->d, round_to_int(barnum),
3983 100, 1, showaslog, tempgrad);
3987 if (current_update_time - obj->data.execi.last_update
3988 >= obj->data.execi.interval) {
3991 read_exec(obj->data.execi.cmd, p, text_buffer_size);
3992 barnum = get_barnum(p);
3994 if (barnum >= 0.0) {
3995 obj->f = 255 * barnum / 100.0;
3997 obj->data.execi.last_update = current_update_time;
3999 new_bar(p, obj->a, obj->b, round_to_int(obj->f));
4002 if (current_update_time - obj->data.execi.last_update
4003 >= obj->data.execi.interval) {
4005 char showaslog = FALSE;
4006 char tempgrad = FALSE;
4007 char *cmd = obj->data.execi.cmd;
4009 if (strncasecmp(obj->data.execi.cmd, LOGGRAPH" ", strlen(LOGGRAPH" ")) == EQUAL) {
4011 cmd = cmd + strlen(LOGGRAPH" ") * sizeof(char);
4012 } else if(strncasecmp(obj->data.s, NORMGRAPH" ", strlen(NORMGRAPH" ")) == EQUAL) {
4013 cmd = cmd + strlen(NORMGRAPH" ") * sizeof(char);
4015 if (strstr(cmd, " "TEMPGRAD) && strlen(cmd) > strlen(" "TEMPGRAD)) {
4017 cmd += strlen(" "TEMPGRAD);
4019 obj->char_a = showaslog;
4020 obj->char_b = tempgrad;
4021 read_exec(cmd, p, text_buffer_size);
4022 barnum = get_barnum(p);
4024 if (barnum >= 0.0) {
4027 obj->data.execi.last_update = current_update_time;
4029 new_graph(p, obj->a, obj->b, obj->c, obj->d, (int) (obj->f), 100, 1, obj->char_a, obj->char_b);
4032 if (current_update_time - obj->data.execi.last_update
4033 >= obj->data.execi.interval) {
4036 read_exec(obj->data.execi.cmd, p, text_buffer_size);
4037 barnum = get_barnum(p);
4039 if (barnum >= 0.0) {
4040 obj->f = 255 * barnum / 100.0;
4042 obj->data.execi.last_update = current_update_time;
4044 new_gauge(p, obj->a, obj->b, round_to_int(obj->f));
4048 if (current_update_time - obj->data.execi.last_update
4049 >= obj->data.execi.interval
4050 && obj->data.execi.interval != 0) {
4051 read_exec(obj->data.execi.cmd, obj->data.execi.buffer,
4053 obj->data.execi.last_update = current_update_time;
4055 snprintf(p, text_buffer_size, "%s", obj->data.execi.buffer);
4058 struct text_object subroot;
4059 struct information *tmp_info =
4060 malloc(sizeof(struct information));
4061 memcpy(tmp_info, cur, sizeof(struct information));
4063 if (current_update_time - obj->data.execi.last_update
4064 < obj->data.execi.interval
4065 || obj->data.execi.interval == 0) {
4066 parse_conky_vars(&subroot, obj->data.execi.buffer, p, tmp_info);
4068 char *output = obj->data.execi.buffer;
4069 FILE *fp = popen(obj->data.execi.cmd, "r");
4070 int length = fread(output, 1, text_buffer_size, fp);
4074 output[length] = '\0';
4075 if (length > 0 && output[length - 1] == '\n') {
4076 output[length - 1] = '\0';
4079 parse_conky_vars(&subroot, obj->data.execi.buffer, p, tmp_info);
4080 obj->data.execi.last_update = current_update_time;
4082 free_text_objects(&subroot, 1);
4086 if (!obj->data.texeci.p_timed_thread) {
4087 obj->data.texeci.p_timed_thread =
4088 timed_thread_create(&threaded_exec,
4089 (void *) obj, obj->data.texeci.interval * 1000000);
4090 if (!obj->data.texeci.p_timed_thread) {
4091 ERR("Error creating texeci timed thread");
4093 timed_thread_register(obj->data.texeci.p_timed_thread,
4094 &obj->data.texeci.p_timed_thread);
4095 if (timed_thread_run(obj->data.texeci.p_timed_thread)) {
4096 ERR("Error running texeci timed thread");
4099 timed_thread_lock(obj->data.texeci.p_timed_thread);
4100 snprintf(p, text_buffer_size, "%s", obj->data.texeci.buffer);
4101 timed_thread_unlock(obj->data.texeci.p_timed_thread);
4104 #endif /* HAVE_POPEN */
4106 struct mail_s *mail = ensure_mail_thread(obj, imap_thread, "imap");
4108 if (mail && mail->p_timed_thread) {
4109 timed_thread_lock(mail->p_timed_thread);
4110 snprintf(p, p_max_size, "%lu", mail->unseen);
4111 timed_thread_unlock(mail->p_timed_thread);
4114 OBJ(imap_messages) {
4115 struct mail_s *mail = ensure_mail_thread(obj, imap_thread, "imap");
4117 if (mail && mail->p_timed_thread) {
4118 timed_thread_lock(mail->p_timed_thread);
4119 snprintf(p, p_max_size, "%lu", mail->messages);
4120 timed_thread_unlock(mail->p_timed_thread);
4124 struct mail_s *mail = ensure_mail_thread(obj, pop3_thread, "pop3");
4126 if (mail && mail->p_timed_thread) {
4127 timed_thread_lock(mail->p_timed_thread);
4128 snprintf(p, p_max_size, "%lu", mail->unseen);
4129 timed_thread_unlock(mail->p_timed_thread);
4133 struct mail_s *mail = ensure_mail_thread(obj, pop3_thread, "pop3");
4135 if (mail && mail->p_timed_thread) {
4136 timed_thread_lock(mail->p_timed_thread);
4137 snprintf(p, p_max_size, "%.1f",
4138 mail->used / 1024.0 / 1024.0);
4139 timed_thread_unlock(mail->p_timed_thread);
4144 if (obj->data.fs != NULL) {
4145 if (obj->data.fs->size == 0) {
4146 new_bar(p, obj->data.fsbar.w, obj->data.fsbar.h, 255);
4148 new_bar(p, obj->data.fsbar.w, obj->data.fsbar.h,
4149 (int) (255 - obj->data.fsbar.fs->avail * 255 /
4150 obj->data.fs->size));
4156 if (obj->data.fs != NULL) {
4157 human_readable( (obj->data.fs->free ? obj->data.fs->free :
4158 obj->data.fs->avail), p, 255);
4162 if (obj->data.fs != NULL) {
4165 if (obj->data.fs->size) {
4166 val = (obj->data.fs->free ? obj->data.fs->free :
4167 obj->data.fs->avail) * 100 /
4171 percent_print(p, p_max_size, val);
4175 if (obj->data.fs != NULL) {
4176 human_readable(obj->data.fs->size, p, 255);
4180 if (obj->data.fs != NULL)
4181 snprintf(p, p_max_size, "%s", obj->data.fs->type);
4184 if (obj->data.fs != NULL) {
4185 human_readable(obj->data.fs->size - (obj->data.fs->free
4186 ? obj->data.fs->free : obj->data.fs->avail), p, 255);
4191 if (obj->data.fs != NULL) {
4192 if (obj->data.fs->size == 0) {
4193 new_bar(p, obj->data.fsbar.w, obj->data.fsbar.h, 255);
4195 new_bar(p, obj->data.fsbar.w, obj->data.fsbar.h,
4196 (int) (obj->data.fsbar.fs->avail * 255 /
4197 obj->data.fs->size));
4203 if (obj->data.fs != NULL) {
4206 if (obj->data.fs->size) {
4207 val = (obj->data.fs->free ? obj->data.fs->free :
4208 obj->data.fs->avail) * 100 /
4212 percent_print(p, p_max_size, 100 - val);
4216 float *v = info.loadavg;
4218 if (obj->data.loadavg[2]) {
4219 snprintf(p, p_max_size, "%.2f %.2f %.2f",
4220 v[obj->data.loadavg[0] - 1],
4221 v[obj->data.loadavg[1] - 1],
4222 v[obj->data.loadavg[2] - 1]);
4223 } else if (obj->data.loadavg[1]) {
4224 snprintf(p, p_max_size, "%.2f %.2f",
4225 v[obj->data.loadavg[0] - 1],
4226 v[obj->data.loadavg[1] - 1]);
4227 } else if (obj->data.loadavg[0]) {
4228 snprintf(p, p_max_size, "%.2f",
4229 v[obj->data.loadavg[0] - 1]);
4233 new_goto(p, obj->data.i);
4236 new_tab(p, obj->data.pair.a, obj->data.pair.b);
4240 new_hr(p, obj->data.i);
4244 if (cur->nameserver_info.nscount > obj->data.i)
4245 snprintf(p, p_max_size, "%s",
4246 cur->nameserver_info.ns_list[obj->data.i]);
4250 char *skill = eve(obj->data.eve.userid, obj->data.eve.apikey, obj->data.eve.charid);
4251 snprintf(p, p_max_size, "%s", skill);
4256 PRSS *data = get_rss_info(obj->data.rss.uri,
4257 obj->data.rss.delay);
4261 snprintf(p, p_max_size, "prss: Error reading RSS data\n");
4263 if (strcmp(obj->data.rss.action, "feed_title") == EQUAL) {
4265 // remove trailing new line if one exists
4266 if (str[strlen(str) - 1] == '\n') {
4267 str[strlen(str) - 1] = 0;
4269 snprintf(p, p_max_size, "%s", str);
4270 } else if (strcmp(obj->data.rss.action, "item_title") == EQUAL) {
4271 if (obj->data.rss.act_par < data->item_count) {
4272 str = data->items[obj->data.rss.act_par].title;
4273 // remove trailing new line if one exists
4274 if (str[strlen(str) - 1] == '\n') {
4275 str[strlen(str) - 1] = 0;
4277 snprintf(p, p_max_size, "%s", str);
4279 } else if (strcmp(obj->data.rss.action, "item_desc") == EQUAL) {
4280 if (obj->data.rss.act_par < data->item_count) {
4282 data->items[obj->data.rss.act_par].description;
4283 // remove trailing new line if one exists
4284 if (str[strlen(str) - 1] == '\n') {
4285 str[strlen(str) - 1] = 0;
4287 snprintf(p, p_max_size, "%s", str);
4289 } else if (strcmp(obj->data.rss.action, "item_titles") == EQUAL) {
4290 if (data->item_count > 0) {
4293 //'tmpspaces' is a string with spaces too be placed in front of each title
4294 char *tmpspaces = malloc(obj->data.rss.nrspaces + 1);
4295 memset(tmpspaces, ' ', obj->data.rss.nrspaces);
4296 tmpspaces[obj->data.rss.nrspaces]=0;
4300 if (obj->data.rss.act_par > data->item_count) {
4301 show = data->item_count;
4303 show = obj->data.rss.act_par;
4305 for (itmp = 0; itmp < show; itmp++) {
4306 PRSS_Item *item = &data->items[itmp];
4310 // don't add new line before first item
4312 strncat(p, "\n", p_max_size);
4314 /* remove trailing new line if one exists,
4315 * we have our own */
4316 if (str[strlen(str) - 1] == '\n') {
4317 str[strlen(str) - 1] = 0;
4319 strncat(p, tmpspaces, p_max_size);
4320 strncat(p, str, p_max_size);
4331 char *str = llua_getstring(obj->data.s);
4333 snprintf(p, p_max_size, "%s", str);
4338 char *str = llua_getstring(obj->data.s);
4340 struct information *tmp_info;
4341 struct text_object subroot;
4343 tmp_info = malloc(sizeof(struct information));
4344 memcpy(tmp_info, cur, sizeof(struct information));
4345 parse_conky_vars(&subroot, str, p, tmp_info);
4347 free_text_objects(&subroot, 1);
4352 OBJ(lua_read_parse) {
4353 struct information *tmp_info;
4354 struct text_object subroot, subroot2;
4357 sscanf(obj->data.s, "%64s", func);
4358 text = obj->data.s + strlen(func) + 1;
4360 tmp_info = malloc(sizeof(struct information));
4361 memcpy(tmp_info, cur, sizeof(struct information));
4362 parse_conky_vars(&subroot, text, p, tmp_info);
4363 DBGP("evaluated '%s' to '%s'", text, p);
4365 str = llua_getstring_read(func, p);
4367 parse_conky_vars(&subroot2, str, p, tmp_info);
4368 DBGP("evaluated '%s' to '%s'", str, p);
4371 free_text_objects(&subroot2, 1);
4373 free_text_objects(&subroot, 1);
4379 if (llua_getinteger(obj->data.s, &per)) {
4380 new_bar(p, obj->a, obj->b, (per/100.0 * 255));
4385 if (llua_getinteger(obj->data.s, &per)) {
4386 new_graph(p, obj->a, obj->b, obj->c, obj->d,
4387 (per/100.0 * 255), 100, 1, obj->char_a, obj->char_b);
4392 if (llua_getinteger(obj->data.s, &per)) {
4393 new_gauge(p, obj->a, obj->b, (per/100.0 * 255));
4397 #endif /* HAVE_LUA */
4402 if (obj->data.hddtemp.update_time < current_update_time - 30) {
4403 if (obj->data.hddtemp.temp)
4404 free(obj->data.hddtemp.temp);
4405 obj->data.hddtemp.temp = get_hddtemp_info(obj->data.hddtemp.dev,
4406 obj->data.hddtemp.addr, obj->data.hddtemp.port);
4407 obj->data.hddtemp.update_time = current_update_time;
4409 if (!obj->data.hddtemp.temp) {
4410 snprintf(p, p_max_size, "N/A");
4412 val = strtol(obj->data.hddtemp.temp + 1, &endptr, 10);
4413 unit = obj->data.hddtemp.temp[0];
4415 if (*endptr != '\0')
4416 snprintf(p, p_max_size, "N/A");
4417 else if (unit == 'C')
4418 temp_print(p, p_max_size, (double)val, TEMP_CELSIUS);
4419 else if (unit == 'F')
4420 temp_print(p, p_max_size, (double)val, TEMP_FAHRENHEIT);
4422 snprintf(p, p_max_size, "N/A");
4427 new_offset(p, obj->data.i);
4430 new_voffset(p, obj->data.i);
4436 r = get_sysfs_info(&obj->data.sysfs.fd, obj->data.sysfs.arg,
4437 obj->data.sysfs.devtype, obj->data.sysfs.type);
4439 r = r * obj->data.sysfs.factor + obj->data.sysfs.offset;
4441 if (!strncmp(obj->data.sysfs.type, "temp", 4)) {
4442 temp_print(p, p_max_size, r, TEMP_CELSIUS);
4443 } else if (r >= 100.0 || r == 0) {
4444 snprintf(p, p_max_size, "%d", (int) r);
4446 snprintf(p, p_max_size, "%.1f", r);
4452 r = get_sysfs_info(&obj->data.sysfs.fd, obj->data.sysfs.arg,
4453 obj->data.sysfs.devtype, obj->data.sysfs.type);
4455 r = r * obj->data.sysfs.factor + obj->data.sysfs.offset;
4457 if (!strncmp(obj->data.sysfs.type, "temp", 4)) {
4458 temp_print(p, p_max_size, r, TEMP_CELSIUS);
4459 } else if (r >= 100.0 || r == 0) {
4460 snprintf(p, p_max_size, "%d", (int) r);
4462 snprintf(p, p_max_size, "%.1f", r);
4468 r = get_sysfs_info(&obj->data.sysfs.fd, obj->data.sysfs.arg,
4469 obj->data.sysfs.devtype, obj->data.sysfs.type);
4471 r = r * obj->data.sysfs.factor + obj->data.sysfs.offset;
4473 if (!strncmp(obj->data.sysfs.type, "temp", 4)) {
4474 temp_print(p, p_max_size, r, TEMP_CELSIUS);
4475 } else if (r >= 100.0 || r == 0) {
4476 snprintf(p, p_max_size, "%d", (int) r);
4478 snprintf(p, p_max_size, "%.1f", r);
4481 #endif /* __linux__ */
4483 new_alignr(p, obj->data.i);
4486 new_alignc(p, obj->data.i);
4489 char buf[max_user_text];
4490 struct information *tmp_info =
4491 malloc(sizeof(struct information));
4492 memcpy(tmp_info, cur, sizeof(struct information));
4493 generate_text_internal(buf, max_user_text,
4494 *obj->sub, tmp_info);
4496 if (strlen(buf) != 0) {
4502 char expression[max_user_text];
4504 struct information *tmp_info;
4506 tmp_info = malloc(sizeof(struct information));
4507 memcpy(tmp_info, cur, sizeof(struct information));
4508 generate_text_internal(expression, max_user_text,
4509 *obj->sub, tmp_info);
4510 DBGP("parsed arg into '%s'", expression);
4512 val = compare(expression);
4514 ERR("compare failed for expression '%s'",
4522 if (obj->data.ifblock.str
4523 && !check_contains(obj->data.ifblock.s,
4524 obj->data.ifblock.str)) {
4526 } else if (obj->data.ifblock.s
4527 && access(obj->data.ifblock.s, F_OK)) {
4532 if ((obj->data.ifblock.s)
4533 && (!check_mount(obj->data.ifblock.s))) {
4538 if ((obj->data.ifblock.s) && system(obj->data.ifblock.s)) {
4542 #if defined(__linux__)
4544 snprintf(p, p_max_size, "%s", get_ioscheduler(obj->data.s));
4548 snprintf(p, p_max_size, "%s", cur->uname_s.release);
4551 snprintf(p, p_max_size, "%s", cur->uname_s.machine);
4556 human_readable(cur->mem * 1024, p, 255);
4559 human_readable(cur->memeasyfree * 1024, p, 255);
4562 human_readable(cur->memfree * 1024, p, 255);
4565 human_readable(cur->memmax * 1024, p, 255);
4569 percent_print(p, p_max_size, cur->mem * 100 / cur->memmax);
4573 new_gauge(p, obj->data.pair.a, obj->data.pair.b,
4574 cur->memmax ? (cur->mem * 255) / (cur->memmax) : 0);
4577 new_bar(p, obj->data.pair.a, obj->data.pair.b,
4578 cur->memmax ? (cur->mem * 255) / (cur->memmax) : 0);
4581 new_graph(p, obj->a, obj->b, obj->c, obj->d,
4582 cur->memmax ? (cur->mem * 100.0) / (cur->memmax) : 0.0,
4583 100, 1, obj->char_a, obj->char_b);
4588 percent_print(p, p_max_size, mixer_get_avg(obj->data.l));
4591 percent_print(p, p_max_size, mixer_get_left(obj->data.l));
4594 percent_print(p, p_max_size, mixer_get_right(obj->data.l));
4598 new_bar(p, obj->data.mixerbar.w, obj->data.mixerbar.h,
4599 mixer_to_255(obj->data.mixerbar.l,mixer_get_avg(obj->data.mixerbar.l)));
4602 new_bar(p, obj->data.mixerbar.w, obj->data.mixerbar.h,
4603 mixer_to_255(obj->data.mixerbar.l,mixer_get_left(obj->data.mixerbar.l)));
4606 new_bar(p, obj->data.mixerbar.w, obj->data.mixerbar.h,
4607 mixer_to_255(obj->data.mixerbar.l,mixer_get_right(obj->data.mixerbar.l)));
4610 OBJ(if_mixer_mute) {
4611 if (!mixer_is_mute(obj->data.ifblock.i)) {
4617 snprintf(p, p_max_size, "%d", cur->x11.monitor.current);
4619 OBJ(monitor_number) {
4620 snprintf(p, p_max_size, "%d", cur->x11.monitor.number);
4626 update_mail_count(&obj->data.local_mail);
4627 snprintf(p, p_max_size, "%d", obj->data.local_mail.mail_count);
4630 update_mail_count(&obj->data.local_mail);
4631 snprintf(p, p_max_size, "%d",
4632 obj->data.local_mail.new_mail_count);
4635 update_mail_count(&obj->data.local_mail);
4636 snprintf(p, p_max_size, "%d",
4637 obj->data.local_mail.seen_mail_count);
4640 update_mail_count(&obj->data.local_mail);
4641 snprintf(p, p_max_size, "%d",
4642 obj->data.local_mail.unseen_mail_count);
4644 OBJ(flagged_mails) {
4645 update_mail_count(&obj->data.local_mail);
4646 snprintf(p, p_max_size, "%d",
4647 obj->data.local_mail.flagged_mail_count);
4649 OBJ(unflagged_mails) {
4650 update_mail_count(&obj->data.local_mail);
4651 snprintf(p, p_max_size, "%d",
4652 obj->data.local_mail.unflagged_mail_count);
4654 OBJ(forwarded_mails) {
4655 update_mail_count(&obj->data.local_mail);
4656 snprintf(p, p_max_size, "%d",
4657 obj->data.local_mail.forwarded_mail_count);
4659 OBJ(unforwarded_mails) {
4660 update_mail_count(&obj->data.local_mail);
4661 snprintf(p, p_max_size, "%d",
4662 obj->data.local_mail.unforwarded_mail_count);
4664 OBJ(replied_mails) {
4665 update_mail_count(&obj->data.local_mail);
4666 snprintf(p, p_max_size, "%d",
4667 obj->data.local_mail.replied_mail_count);
4669 OBJ(unreplied_mails) {
4670 update_mail_count(&obj->data.local_mail);
4671 snprintf(p, p_max_size, "%d",
4672 obj->data.local_mail.unreplied_mail_count);
4675 update_mail_count(&obj->data.local_mail);
4676 snprintf(p, p_max_size, "%d",
4677 obj->data.local_mail.draft_mail_count);
4679 OBJ(trashed_mails) {
4680 update_mail_count(&obj->data.local_mail);
4681 snprintf(p, p_max_size, "%d",
4682 obj->data.local_mail.trashed_mail_count);
4685 mbox_scan(obj->data.mboxscan.args, obj->data.mboxscan.output,
4687 snprintf(p, p_max_size, "%s", obj->data.mboxscan.output);
4690 snprintf(p, p_max_size, "%s", cur->uname_s.nodename);
4693 new_outline(p, obj->data.l);
4696 spaced_print(p, p_max_size, "%hu", 4, cur->procs);
4698 OBJ(running_processes) {
4699 spaced_print(p, p_max_size, "%hu", 4, cur->run_procs);
4702 snprintf(p, p_max_size, "%s", obj->data.s);
4706 new_bg(p, obj->data.l);
4709 new_stippled_hr(p, obj->data.pair.a, obj->data.pair.b);
4713 human_readable(cur->swap * 1024, p, 255);
4716 human_readable(cur->swapmax * 1024, p, 255);
4719 if (cur->swapmax == 0) {
4720 strncpy(p, "No swap", p_max_size);
4722 percent_print(p, p_max_size, cur->swap * 100 / cur->swapmax);
4727 new_bar(p, obj->data.pair.a, obj->data.pair.b,
4728 cur->swapmax ? (cur->swap * 255) / (cur->swapmax) : 0);
4732 snprintf(p, p_max_size, "%s", cur->uname_s.sysname);
4735 time_t t = time(NULL);
4736 struct tm *tm = localtime(&t);
4738 setlocale(LC_TIME, "");
4739 strftime(p, p_max_size, obj->data.s, tm);
4742 time_t t = time(NULL);
4743 struct tm *tm = gmtime(&t);
4745 strftime(p, p_max_size, obj->data.s, tm);
4752 if (obj->data.tztime.tz) {
4753 oldTZ = getenv("TZ");
4754 setenv("TZ", obj->data.tztime.tz, 1);
4760 setlocale(LC_TIME, "");
4761 strftime(p, p_max_size, obj->data.tztime.fmt, tm);
4763 setenv("TZ", oldTZ, 1);
4768 // Needless to free oldTZ since getenv gives ptr to static data
4771 human_readable(obj->data.net->recv, p, 255);
4774 human_readable(obj->data.net->trans, p, 255);
4777 snprintf(p, p_max_size, "%d", total_updates);
4780 if(total_updates % updatereset != obj->data.ifblock.i - 1) {
4785 human_readable(obj->data.net->trans_speed, p, 255);
4788 spaced_print(p, p_max_size, "%.1f", 8,
4789 obj->data.net->trans_speed / 1024.0);
4793 new_graph(p, obj->a, obj->b, obj->c, obj->d,
4794 obj->data.net->trans_speed / 1024.0, obj->e, 1, obj->char_a, obj->char_b);
4798 format_seconds_short(p, p_max_size, (int) cur->uptime);
4801 format_seconds(p, p_max_size, (int) cur->uptime);
4804 snprintf(p, p_max_size, "%s", cur->users.names);
4807 snprintf(p, p_max_size, "%s", cur->users.terms);
4810 snprintf(p, p_max_size, "%s", cur->users.times);
4813 snprintf(p, p_max_size, "%d", cur->users.number);
4815 #if (defined(__FreeBSD__) || defined(__FreeBSD_kernel__) \
4816 || defined(__OpenBSD__)) && (defined(i386) || defined(__i386__))
4820 msg = get_apm_adapter();
4821 snprintf(p, p_max_size, "%s", msg);
4824 OBJ(apm_battery_life) {
4827 msg = get_apm_battery_life();
4828 snprintf(p, p_max_size, "%s", msg);
4831 OBJ(apm_battery_time) {
4834 msg = get_apm_battery_time();
4835 snprintf(p, p_max_size, "%s", msg);
4838 #endif /* __FreeBSD__ __OpenBSD__ */
4841 #define mpd_printf(fmt, val) \
4842 snprintf(p, p_max_size, fmt, mpd_get_info()->val)
4843 #define mpd_sprintf(val) { \
4844 if (!obj->data.i || obj->data.i > p_max_size) \
4845 mpd_printf("%s", val); \
4847 snprintf(p, obj->data.i, "%s", mpd_get_info()->val); \
4852 mpd_sprintf(artist);
4856 mpd_printf("%s", random);
4858 mpd_printf("%s", repeat);
4866 mpd_printf("%d", volume);
4868 mpd_printf("%d", bitrate);
4870 mpd_printf("%s", status);
4872 format_media_player_time(p, p_max_size, mpd_get_info()->elapsed);
4875 format_media_player_time(p, p_max_size, mpd_get_info()->length);
4878 percent_print(p, p_max_size, (int)(mpd_get_info()->progress * 100));
4882 new_bar(p, obj->data.pair.a, obj->data.pair.b,
4883 (int) (mpd_get_info()->progress * 255.0f));
4887 struct mpd_s *mpd = mpd_get_info();
4888 int len = obj->data.i;
4889 if (len == 0 || len > p_max_size)
4892 memset(p, 0, p_max_size);
4893 if (mpd->artist && *mpd->artist &&
4894 mpd->title && *mpd->title) {
4895 snprintf(p, len, "%s - %s", mpd->artist,
4897 } else if (mpd->title && *mpd->title) {
4898 snprintf(p, len, "%s", mpd->title);
4899 } else if (mpd->artist && *mpd->artist) {
4900 snprintf(p, len, "%s", mpd->artist);
4901 } else if (mpd->file && *mpd->file) {
4902 snprintf(p, len, "%s", mpd->file);
4907 OBJ(if_mpd_playing) {
4908 if (!mpd_get_info()->is_playing) {
4921 #define MOC_PRINT(t, a) \
4922 snprintf(p, p_max_size, "%s", (moc.t ? moc.t : a))
4924 MOC_PRINT(state, "??");
4927 MOC_PRINT(file, "no file");
4930 MOC_PRINT(title, "no title");
4933 MOC_PRINT(artist, "no artist");
4936 MOC_PRINT(song, "no song");
4939 MOC_PRINT(album, "no album");
4941 OBJ(moc_totaltime) {
4942 MOC_PRINT(totaltime, "0:00");
4945 MOC_PRINT(timeleft, "0:00");
4948 MOC_PRINT(curtime, "0:00");
4951 MOC_PRINT(bitrate, "0Kbps");
4954 MOC_PRINT(rate, "0KHz");
4960 snprintf(p, p_max_size, "%s", cur->xmms2.artist);
4963 snprintf(p, p_max_size, "%s", cur->xmms2.album);
4966 snprintf(p, p_max_size, "%s", cur->xmms2.title);
4969 snprintf(p, p_max_size, "%s", cur->xmms2.genre);
4971 OBJ(xmms2_comment) {
4972 snprintf(p, p_max_size, "%s", cur->xmms2.comment);
4975 snprintf(p, p_max_size, "%s", cur->xmms2.url);
4978 snprintf(p, p_max_size, "%s", cur->xmms2.status);
4981 snprintf(p, p_max_size, "%s", cur->xmms2.date);
4983 OBJ(xmms2_tracknr) {
4984 if (cur->xmms2.tracknr != -1) {
4985 snprintf(p, p_max_size, "%i", cur->xmms2.tracknr);
4988 OBJ(xmms2_bitrate) {
4989 snprintf(p, p_max_size, "%i", cur->xmms2.bitrate);
4992 snprintf(p, p_max_size, "%u", cur->xmms2.id);
4995 snprintf(p, p_max_size, "%2.1f", cur->xmms2.size);
4997 OBJ(xmms2_elapsed) {
4998 snprintf(p, p_max_size, "%02d:%02d", cur->xmms2.elapsed / 60000,
4999 (cur->xmms2.elapsed / 1000) % 60);
5001 OBJ(xmms2_duration) {
5002 snprintf(p, p_max_size, "%02d:%02d",
5003 cur->xmms2.duration / 60000,
5004 (cur->xmms2.duration / 1000) % 60);
5006 OBJ(xmms2_percent) {
5007 snprintf(p, p_max_size, "%2.0f", cur->xmms2.progress * 100);
5010 new_bar(p, obj->data.pair.a, obj->data.pair.b,
5011 (int) (cur->xmms2.progress * 255.0f));
5013 OBJ(xmms2_playlist) {
5014 snprintf(p, p_max_size, "%s", cur->xmms2.playlist);
5016 OBJ(xmms2_timesplayed) {
5017 snprintf(p, p_max_size, "%i", cur->xmms2.timesplayed);
5020 if (strlen(cur->xmms2.title) < 2
5021 && strlen(cur->xmms2.title) < 2) {
5022 snprintf(p, p_max_size, "%s", cur->xmms2.url);
5024 snprintf(p, p_max_size, "%s - %s", cur->xmms2.artist,
5028 OBJ(if_xmms2_connected) {
5029 if (cur->xmms2.conn_state != 1) {
5035 OBJ(audacious_status) {
5036 snprintf(p, p_max_size, "%s",
5037 cur->audacious.items[AUDACIOUS_STATUS]);
5039 OBJ(audacious_title) {
5040 snprintf(p, cur->audacious.max_title_len > 0
5041 ? cur->audacious.max_title_len : p_max_size, "%s",
5042 cur->audacious.items[AUDACIOUS_TITLE]);
5044 OBJ(audacious_length) {
5045 snprintf(p, p_max_size, "%s",
5046 cur->audacious.items[AUDACIOUS_LENGTH]);
5048 OBJ(audacious_length_seconds) {
5049 snprintf(p, p_max_size, "%s",
5050 cur->audacious.items[AUDACIOUS_LENGTH_SECONDS]);
5052 OBJ(audacious_position) {
5053 snprintf(p, p_max_size, "%s",
5054 cur->audacious.items[AUDACIOUS_POSITION]);
5056 OBJ(audacious_position_seconds) {
5057 snprintf(p, p_max_size, "%s",
5058 cur->audacious.items[AUDACIOUS_POSITION_SECONDS]);
5060 OBJ(audacious_bitrate) {
5061 snprintf(p, p_max_size, "%s",
5062 cur->audacious.items[AUDACIOUS_BITRATE]);
5064 OBJ(audacious_frequency) {
5065 snprintf(p, p_max_size, "%s",
5066 cur->audacious.items[AUDACIOUS_FREQUENCY]);
5068 OBJ(audacious_channels) {
5069 snprintf(p, p_max_size, "%s",
5070 cur->audacious.items[AUDACIOUS_CHANNELS]);
5072 OBJ(audacious_filename) {
5073 snprintf(p, p_max_size, "%s",
5074 cur->audacious.items[AUDACIOUS_FILENAME]);
5076 OBJ(audacious_playlist_length) {
5077 snprintf(p, p_max_size, "%s",
5078 cur->audacious.items[AUDACIOUS_PLAYLIST_LENGTH]);
5080 OBJ(audacious_playlist_position) {
5081 snprintf(p, p_max_size, "%s",
5082 cur->audacious.items[AUDACIOUS_PLAYLIST_POSITION]);
5084 OBJ(audacious_main_volume) {
5085 snprintf(p, p_max_size, "%s",
5086 cur->audacious.items[AUDACIOUS_MAIN_VOLUME]);
5088 OBJ(audacious_bar) {
5092 atof(cur->audacious.items[AUDACIOUS_POSITION_SECONDS]) /
5093 atof(cur->audacious.items[AUDACIOUS_LENGTH_SECONDS]);
5094 new_bar(p, obj->a, obj->b, (int) (progress * 255.0f));
5100 snprintf(p, p_max_size, "%s", cur->bmpx.title);
5103 snprintf(p, p_max_size, "%s", cur->bmpx.artist);
5106 snprintf(p, p_max_size, "%s", cur->bmpx.album);
5109 snprintf(p, p_max_size, "%s", cur->bmpx.uri);
5112 snprintf(p, p_max_size, "%i", cur->bmpx.track);
5115 snprintf(p, p_max_size, "%i", cur->bmpx.bitrate);
5118 /* we have three different types of top (top, top_mem
5119 * and top_time). To avoid having almost-same code three
5120 * times, we have this special handler. */
5123 parse_top_args("top", obj->data.top.s, obj);
5124 if (!needed) needed = cur->cpu;
5126 parse_top_args("top_mem", obj->data.top.s, obj);
5127 if (!needed) needed = cur->memu;
5129 parse_top_args("top_time", obj->data.top.s, obj);
5130 if (!needed) needed = cur->time;
5132 if (needed[obj->data.top.num]) {
5135 switch (obj->data.top.type) {
5137 snprintf(p, top_name_width + 1, "%-*s", top_name_width,
5138 needed[obj->data.top.num]->name);
5141 snprintf(p, 7, "%6.2f",
5142 needed[obj->data.top.num]->amount);
5145 snprintf(p, 6, "%5i",
5146 needed[obj->data.top.num]->pid);
5149 snprintf(p, 7, "%6.2f",
5150 needed[obj->data.top.num]->totalmem);
5153 timeval = format_time(
5154 needed[obj->data.top.num]->total_cpu_time, 9);
5155 snprintf(p, 10, "%9s", timeval);
5159 human_readable(needed[obj->data.top.num]->rss,
5163 human_readable(needed[obj->data.top.num]->vsize,
5169 print_tail_object(obj, p, p_max_size);
5171 print_head_object(obj, p, p_max_size);
5173 FILE *fp = open_file(obj->data.s, &obj->a);
5176 /* FIXME: use something more general (see also tail.c, head.c */
5177 #define BUFSZ 0x1000
5182 while(fgets(buf, BUFSZ, fp) != NULL){
5183 for(j = 0; buf[j] != 0; j++) {
5184 if(buf[j] == '\n') {
5189 sprintf(p, "%d", lines);
5192 sprintf(p, "File Unreadable");
5197 FILE *fp = open_file(obj->data.s, &obj->a);
5202 char inword = FALSE;
5205 while(fgets(buf, BUFSZ, fp) != NULL){
5206 for(j = 0; buf[j] != 0; j++) {
5207 if(!isspace(buf[j])) {
5208 if(inword == FALSE) {
5217 sprintf(p, "%d", words);
5220 sprintf(p, "File Unreadable");
5223 #ifdef TCP_PORT_MONITOR
5225 tcp_portmon_action(p, p_max_size,
5226 &obj->data.tcp_port_monitor);
5232 iconv_converting = 1;
5233 iconv_selected = obj->a;
5236 iconv_converting = 0;
5241 OBJ(entropy_avail) {
5242 snprintf(p, p_max_size, "%d", cur->entropy.entropy_avail);
5244 OBJ(entropy_poolsize) {
5245 snprintf(p, p_max_size, "%d", cur->entropy.poolsize);
5249 double entropy_perc;
5251 entropy_perc = (double) cur->entropy.entropy_avail /
5252 (double) cur->entropy.poolsize;
5253 new_bar(p, obj->a, obj->b, (int) (entropy_perc * 255.0f));
5260 s = smapi_get_val(obj->data.s);
5261 snprintf(p, p_max_size, "%s", s);
5265 OBJ(if_smapi_bat_installed) {
5267 if(obj->data.ifblock.s && sscanf(obj->data.ifblock.s, "%i", &idx) == 1) {
5268 if(!smapi_bat_installed(idx)) {
5272 ERR("argument to if_smapi_bat_installed must be an integer");
5274 OBJ(smapi_bat_perc) {
5276 if(obj->data.s && sscanf(obj->data.s, "%i", &idx) == 1) {
5277 val = smapi_bat_installed(idx) ?
5278 smapi_get_bat_int(idx, "remaining_percent") : 0;
5279 percent_print(p, p_max_size, val);
5281 ERR("argument to smapi_bat_perc must be an integer");
5283 OBJ(smapi_bat_temp) {
5285 if(obj->data.s && sscanf(obj->data.s, "%i", &idx) == 1) {
5286 val = smapi_bat_installed(idx) ?
5287 smapi_get_bat_int(idx, "temperature") : 0;
5288 /* temperature is in milli degree celsius */
5289 temp_print(p, p_max_size, val / 1000, TEMP_CELSIUS);
5291 ERR("argument to smapi_bat_temp must be an integer");
5293 OBJ(smapi_bat_power) {
5295 if(obj->data.s && sscanf(obj->data.s, "%i", &idx) == 1) {
5296 val = smapi_bat_installed(idx) ?
5297 smapi_get_bat_int(idx, "power_now") : 0;
5298 /* power_now is in mW, set to W with one digit precision */
5299 snprintf(p, p_max_size, "%.1f", ((double)val / 1000));
5301 ERR("argument to smapi_bat_power must be an integer");
5303 OBJ(smapi_bat_bar) {
5304 if(obj->data.i >= 0 && smapi_bat_installed(obj->data.i))
5305 new_bar(p, obj->a, obj->b, (int)
5306 (255 * smapi_get_bat_int(obj->data.i, "remaining_percent") / 100));
5308 new_bar(p, obj->a, obj->b, 0);
5313 char *tmp, buf[max_user_text];
5314 generate_text_internal(buf, max_user_text,
5317 if (strlen(buf) <= obj->data.scroll.show) {
5318 snprintf(p, p_max_size, "%s", buf);
5321 #define LINESEPARATOR '|'
5322 //place all the lines behind each other with LINESEPARATOR between them
5323 for(j = 0; buf[j] != 0; j++) {
5325 buf[j]=LINESEPARATOR;
5328 //scroll the output obj->data.scroll.start places by copying that many chars from
5329 //the front of the string to tmp, scrolling the rest to the front and placing tmp
5330 //at the back of the string
5331 tmp = calloc(obj->data.scroll.start + 1, sizeof(char));
5332 strncpy(tmp, buf, obj->data.scroll.start); tmp[obj->data.scroll.start] = 0;
5333 for(j = obj->data.scroll.start; buf[j] != 0; j++){
5334 buf[j - obj->data.scroll.start] = buf[j];
5336 strcpy(&buf[j - obj->data.scroll.start], tmp);
5338 //only show the requested number of chars
5339 if(obj->data.scroll.show < j) {
5340 buf[obj->data.scroll.show] = 0;
5342 //next time, scroll a place more or reset scrolling if we are at the end
5343 obj->data.scroll.start += obj->data.scroll.step;
5344 if(obj->data.scroll.start >= j){
5345 obj->data.scroll.start = 0;
5347 snprintf(p, p_max_size, "%s", buf);
5350 char buf[2][max_user_text];
5357 struct llrows* next;
5359 struct llrows *ll_rows[2], *current[2];
5360 struct text_object * objsub = obj->sub;
5364 #pragma omp parallel for
5365 #endif /* HAVE_OPENMP */
5366 for(i=0; i<2; i++) {
5369 ll_rows[i] = malloc(sizeof(struct llrows));
5370 current[i] = ll_rows[i];
5372 #pragma omp parallel for
5373 #endif /* HAVE_OPENMP */
5374 for(j=0; j<i; j++) objsub = objsub->sub;
5375 generate_text_internal(buf[i], max_user_text, *objsub, cur);
5377 * #ifdef HAVE_OPENMP
5378 * #pragma omp parallel for reduction (+:nr_rows[i])
5379 * #endif HAVE_OPENMP */
5380 for(j=0; buf[i][j] != 0; j++) {
5381 if(buf[i][j] == '\t') buf[i][j] = ' ';
5382 if(buf[i][j] == '\n') {
5384 current[i]->row = strdup(buf[i]+nextstart);
5385 if(i==0 && (long)strlen(current[i]->row) > longest) longest = (long)strlen(current[i]->row);
5386 current[i]->next = malloc(sizeof(struct llrows));
5387 current[i] = current[i]->next;
5392 current[i]->row = strdup(buf[i]+nextstart);
5393 if(i==0 && (long)strlen(current[i]->row) > longest) longest = (long)strlen(current[i]->row);
5394 current[i]->next = NULL;
5395 current[i] = ll_rows[i];
5397 for(j=0; j < (nr_rows[0] > nr_rows[1] ? nr_rows[0] : nr_rows[1] ); j++) {
5399 strcat(p, current[0]->row);
5400 i=strlen(current[0]->row);
5402 while(i < longest) {
5407 strcat(p, obj->data.combine.seperation);
5408 strcat(p, current[1]->row);
5412 #pragma omp parallel for
5413 #endif /* HAVE_OPENMP */
5414 for(i=0; i<2; i++) if(current[i]) current[i]=current[i]->next;
5417 #pragma omp parallel for
5418 #endif /* HAVE_OPENMP */
5419 for(i=0; i<2; i++) {
5420 while(ll_rows[i] != NULL) {
5421 current[i]=ll_rows[i];
5422 free(current[i]->row);
5423 ll_rows[i]=current[i]->next;
5430 int value = get_nvidia_value(obj->data.nvidia.type, display);
5432 snprintf(p, p_max_size, "N/A");
5433 else if (obj->data.nvidia.type == NV_TEMP)
5434 temp_print(p, p_max_size, (double)value, TEMP_CELSIUS);
5435 else if (obj->data.nvidia.print_as_float &&
5436 value > 0 && value < 100)
5437 snprintf(p, p_max_size, "%.1f", (float)value);
5439 snprintf(p, p_max_size, "%d", value);
5444 /* This is just a meta-object to set host:port */
5447 snprintf(p, p_max_size, "%s",
5448 cur->apcupsd.items[APCUPSD_NAME]);
5450 OBJ(apcupsd_model) {
5451 snprintf(p, p_max_size, "%s",
5452 cur->apcupsd.items[APCUPSD_MODEL]);
5454 OBJ(apcupsd_upsmode) {
5455 snprintf(p, p_max_size, "%s",
5456 cur->apcupsd.items[APCUPSD_UPSMODE]);
5458 OBJ(apcupsd_cable) {
5459 snprintf(p, p_max_size, "%s",
5460 cur->apcupsd.items[APCUPSD_CABLE]);
5462 OBJ(apcupsd_status) {
5463 snprintf(p, p_max_size, "%s",
5464 cur->apcupsd.items[APCUPSD_STATUS]);
5466 OBJ(apcupsd_linev) {
5467 snprintf(p, p_max_size, "%s",
5468 cur->apcupsd.items[APCUPSD_LINEV]);
5471 snprintf(p, p_max_size, "%s",
5472 cur->apcupsd.items[APCUPSD_LOAD]);
5475 OBJ(apcupsd_loadbar) {
5477 progress = atof(cur->apcupsd.items[APCUPSD_LOAD]) / 100.0 * 255.0;
5478 new_bar(p, obj->a, obj->b, (int)progress);
5480 OBJ(apcupsd_loadgraph) {
5482 progress = atof(cur->apcupsd.items[APCUPSD_LOAD]);
5483 new_graph(p, obj->a, obj->b, obj->c, obj->d,
5484 (int)progress, 100, 1, obj->char_a, obj->char_b);
5486 OBJ(apcupsd_loadgauge) {
5488 progress = atof(cur->apcupsd.items[APCUPSD_LOAD]) / 100.0 * 255.0;
5489 new_gauge(p, obj->a, obj->b,
5493 OBJ(apcupsd_charge) {
5494 snprintf(p, p_max_size, "%s",
5495 cur->apcupsd.items[APCUPSD_CHARGE]);
5497 OBJ(apcupsd_timeleft) {
5498 snprintf(p, p_max_size, "%s",
5499 cur->apcupsd.items[APCUPSD_TIMELEFT]);
5502 snprintf(p, p_max_size, "%s",
5503 cur->apcupsd.items[APCUPSD_TEMP]);
5505 OBJ(apcupsd_lastxfer) {
5506 snprintf(p, p_max_size, "%s",
5507 cur->apcupsd.items[APCUPSD_LASTXFER]);
5509 #endif /* APCUPSD */
5516 unsigned int a = strlen(p);
5519 if (a > 0 && iconv_converting && iconv_selected > 0
5520 && (iconv_cd[iconv_selected - 1] != (iconv_t) (-1))) {
5522 size_t dummy1, dummy2;
5523 char *ptr = buff_in;
5526 dummy1 = dummy2 = a;
5528 strncpy(buff_in, p, p_max_size);
5530 iconv(*iconv_cd[iconv_selected - 1], NULL, NULL, NULL, NULL);
5531 while (dummy1 > 0) {
5532 bytes = iconv(*iconv_cd[iconv_selected - 1], &ptr, &dummy1,
5535 ERR("Iconv codeset conversion failed");
5540 /* It is nessecary when we are converting from multibyte to
5541 * singlebyte codepage */
5544 #endif /* HAVE_ICONV */
5552 double current_update_time, next_update_time, last_update_time;
5554 static void generate_text(void)
5556 struct information *cur = &info;
5563 current_update_time = get_time();
5567 /* add things to the buffer */
5573 generate_text_internal(p, max_user_text, global_root_object, cur);
5575 if (stuff_in_upper_case) {
5578 tmp_p = text_buffer;
5580 *tmp_p = toupper(*tmp_p);
5585 next_update_time += update_interval;
5586 if (next_update_time < get_time()) {
5587 next_update_time = get_time() + update_interval;
5588 } else if (next_update_time > get_time() + update_interval) {
5589 next_update_time = get_time() + update_interval;
5591 last_update_time = current_update_time;
5596 static inline int get_string_width(const char *s)
5599 if (output_methods & TO_X) {
5600 return *s ? calc_text_width(s, strlen(s)) : 0;
5606 static inline int get_string_width_special(char *s)
5614 if ((output_methods & TO_X) == 0) {
5616 return (s) ? strlen(s) : 0;
5624 p = strndup(s, text_buffer_size);
5628 if (*p == SPECIAL_CHAR) {
5629 /* shift everything over by 1 so that the special char
5630 * doesn't mess up the size calculation */
5631 for (i = 0; i < (long)strlen(p); i++) {
5632 *(p + i) = *(p + i + 1);
5634 if (specials[special_index + idx].type == GRAPH
5635 || specials[special_index + idx].type == GAUGE
5636 || specials[special_index + idx].type == BAR) {
5637 width += specials[special_index + idx].width;
5644 if (strlen(final) > 1) {
5645 width += calc_text_width(final, strlen(final));
5653 static void text_size_updater(char *s);
5655 int last_font_height;
5656 static void update_text_area(void)
5660 if ((output_methods & TO_X) == 0)
5662 /* update text size if it isn't fixed */
5667 text_width = minimum_width;
5670 last_font_height = font_height();
5671 for_each_line(text_buffer, text_size_updater);
5673 if (text_height < minimum_height) {
5674 text_height = minimum_height;
5676 if (text_width > maximum_width && maximum_width > 0) {
5677 text_width = maximum_width;
5681 /* get text position on workarea */
5682 switch (text_alignment) {
5689 x = workarea[2] - text_width - gap_x;
5694 x = workarea[2] / 2 - text_width / 2 - gap_x;
5701 y = workarea[3] - text_height - gap_y;
5705 x = workarea[2] - text_width - gap_x;
5706 y = workarea[3] - text_height - gap_y;
5710 x = workarea[2] / 2 - text_width / 2 - gap_x;
5711 y = workarea[3] - text_height - gap_y;
5716 y = workarea[3] / 2 - text_height / 2 - gap_y;
5720 x = workarea[2] - text_width - gap_x;
5721 y = workarea[3] / 2 - text_height / 2 - gap_y;
5725 case NONE: // Let the WM manage the window
5736 if (own_window && !fixed_pos) {
5739 text_start_x = border_margin + 1;
5740 text_start_y = border_margin + 1;
5741 window.x = x - border_margin - 1;
5742 window.y = y - border_margin - 1;
5746 /* If window size doesn't match to workarea's size,
5747 * then window probably includes panels (gnome).
5748 * Blah, doesn't work on KDE. */
5749 if (workarea[2] != window.width || workarea[3] != window.height) {
5761 static int cur_x, cur_y; /* current x and y for drawing */
5763 //draw_mode also without X11 because we only need to print to stdout with FG
5764 static int draw_mode; /* FG, BG or OUTLINE */
5766 static long current_color;
5768 static void text_size_updater(char *s)
5773 if ((output_methods & TO_X) == 0)
5775 /* get string widths and skip specials */
5778 if (*p == SPECIAL_CHAR) {
5780 w += get_string_width(s);
5783 if (specials[special_index].type == BAR
5784 || specials[special_index].type == GAUGE
5785 || specials[special_index].type == GRAPH) {
5786 w += specials[special_index].width;
5787 if (specials[special_index].height > last_font_height) {
5788 last_font_height = specials[special_index].height;
5789 last_font_height += font_height();
5791 } else if (specials[special_index].type == OFFSET) {
5792 if (specials[special_index].arg > 0) {
5793 w += specials[special_index].arg;
5795 } else if (specials[special_index].type == VOFFSET) {
5796 last_font_height += specials[special_index].arg;
5797 } else if (specials[special_index].type == GOTO) {
5798 if (specials[special_index].arg > cur_x) {
5799 w = (int) specials[special_index].arg;
5801 } else if (specials[special_index].type == TAB) {
5802 int start = specials[special_index].arg;
5803 int step = specials[special_index].width;
5805 if (!step || step < 0) {
5808 w += step - (cur_x - text_start_x - start) % step;
5809 } else if (specials[special_index].type == FONT) {
5810 selected_font = specials[special_index].font_added;
5811 if (font_height() > last_font_height) {
5812 last_font_height = font_height();
5821 w += get_string_width(s);
5822 if (w > text_width) {
5825 if (text_width > maximum_width && maximum_width) {
5826 text_width = maximum_width;
5829 text_height += last_font_height;
5830 last_font_height = font_height();
5833 static inline void set_foreground_color(long c)
5835 if ((output_methods & TO_X) == 0)
5838 XSetForeground(display, window.gc, c);
5842 static void draw_string(const char *s)
5844 int i, i2, pos, width_of_s;
5852 width_of_s = get_string_width(s);
5853 if ((output_methods & TO_STDOUT) && draw_mode == FG) {
5855 fflush(stdout); /* output immediately, don't buffer */
5857 if ((output_methods & TO_STDERR) && draw_mode == FG) {
5858 fprintf(stderr, "%s\n", s);
5859 fflush(stderr); /* output immediately, don't buffer */
5861 if ((output_methods & OVERWRITE_FILE) && draw_mode == FG && overwrite_fpointer) {
5862 fprintf(overwrite_fpointer, "%s\n", s);
5864 if ((output_methods & APPEND_FILE) && draw_mode == FG && append_fpointer) {
5865 fprintf(append_fpointer, "%s\n", s);
5867 memset(tmpstring1, 0, text_buffer_size);
5868 memset(tmpstring2, 0, text_buffer_size);
5869 strncpy(tmpstring1, s, text_buffer_size - 1);
5874 if (output_methods & TO_X) {
5875 max = ((text_width - width_of_s) / get_string_width(" "));
5878 /* This code looks for tabs in the text and coverts them to spaces.
5879 * The trick is getting the correct number of spaces, and not going
5880 * over the window's size without forcing the window larger. */
5881 for (i = 0; i < (int) text_buffer_size; i++) {
5882 if (tmpstring1[i] == '\t') {
5884 for (i2 = 0; i2 < (8 - (1 + pos) % 8) && added <= max; i2++) {
5885 /* guard against overrun */
5886 tmpstring2[MIN(pos + i2, (int)text_buffer_size - 1)] = ' ';
5891 /* guard against overrun */
5892 tmpstring2[MIN(pos, (int) text_buffer_size - 1)] = tmpstring1[i];
5897 if (output_methods & TO_X) {
5898 if (text_width == maximum_width) {
5899 /* this means the text is probably pushing the limit,
5900 * so we'll chop it */
5901 while (cur_x + get_string_width(tmpstring2) - text_start_x
5902 > maximum_width && strlen(tmpstring2) > 0) {
5903 tmpstring2[strlen(tmpstring2) - 1] = '\0';
5910 if (output_methods & TO_X) {
5916 c.pixel = current_color;
5917 XQueryColor(display, DefaultColormap(display, screen), &c);
5920 c2.color.red = c.red;
5921 c2.color.green = c.green;
5922 c2.color.blue = c.blue;
5923 c2.color.alpha = fonts[selected_font].font_alpha;
5925 XftDrawStringUtf8(window.xftdraw, &c2, fonts[selected_font].xftfont,
5926 cur_x, cur_y, (const XftChar8 *) s, strlen(s));
5928 XftDrawString8(window.xftdraw, &c2, fonts[selected_font].xftfont,
5929 cur_x, cur_y, (const XftChar8 *) s, strlen(s));
5934 XDrawString(display, window.drawable, window.gc, cur_x, cur_y, s,
5937 cur_x += width_of_s;
5940 memcpy(tmpstring1, s, text_buffer_size);
5943 static void draw_line(char *s)
5951 if ((output_methods & TO_X) == 0) {
5957 cur_x = text_start_x;
5958 cur_y += font_ascent();
5959 font_h = font_height();
5961 /* find specials and draw stuff */
5964 if (*p == SPECIAL_CHAR) {
5967 /* draw string before special */
5974 switch (specials[special_index].type) {
5975 case HORIZONTAL_LINE:
5977 int h = specials[special_index].height;
5978 int mid = font_ascent() / 2;
5980 w = text_start_x + text_width - cur_x;
5982 XSetLineAttributes(display, window.gc, h, LineSolid,
5983 CapButt, JoinMiter);
5984 XDrawLine(display, window.drawable, window.gc, cur_x,
5985 cur_y - mid / 2, cur_x + w, cur_y - mid / 2);
5991 int h = specials[special_index].height;
5992 int tmp_s = specials[special_index].arg;
5993 int mid = font_ascent() / 2;
5994 char ss[2] = { tmp_s, tmp_s };
5996 w = text_start_x + text_width - cur_x - 1;
5997 XSetLineAttributes(display, window.gc, h, LineOnOffDash,
5998 CapButt, JoinMiter);
5999 XSetDashes(display, window.gc, 0, ss, 2);
6000 XDrawLine(display, window.drawable, window.gc, cur_x,
6001 cur_y - mid / 2, cur_x + w, cur_y - mid / 2);
6007 int h, bar_usage, by;
6008 if (cur_x - text_start_x > maximum_width
6009 && maximum_width > 0) {
6012 h = specials[special_index].height;
6013 bar_usage = specials[special_index].arg;
6014 by = cur_y - (font_ascent() / 2) - 1;
6019 w = specials[special_index].width;
6021 w = text_start_x + text_width - cur_x - 1;
6027 XSetLineAttributes(display, window.gc, 1, LineSolid,
6028 CapButt, JoinMiter);
6030 XDrawRectangle(display, window.drawable, window.gc, cur_x,
6032 XFillRectangle(display, window.drawable, window.gc, cur_x,
6033 by, w * bar_usage / 255, h);
6041 case GAUGE: /* new GAUGE */
6044 unsigned long last_colour = current_color;
6045 float angle, px, py;
6048 if (cur_x - text_start_x > maximum_width
6049 && maximum_width > 0) {
6053 h = specials[special_index].height;
6054 by = cur_y - (font_ascent() / 2) - 1;
6059 w = specials[special_index].width;
6061 w = text_start_x + text_width - cur_x - 1;
6067 XSetLineAttributes(display, window.gc, 1, LineSolid,
6068 CapButt, JoinMiter);
6070 XDrawArc(display, window.drawable, window.gc,
6071 cur_x, by, w, h * 2, 0, 180*64);
6074 usage = specials[special_index].arg;
6075 angle = (M_PI)*(float)(usage)/255.;
6076 px = (float)(cur_x+(w/2.))-(float)(w/2.)*cos(angle);
6077 py = (float)(by+(h))-(float)(h)*sin(angle);
6079 XDrawLine(display, window.drawable, window.gc,
6080 cur_x + (w/2.), by+(h), (int)(px), (int)(py));
6088 set_foreground_color(last_colour);
6096 int h, by, i = 0, j = 0;
6098 unsigned long last_colour = current_color;
6099 unsigned long *tmpcolour = 0;
6100 if (cur_x - text_start_x > maximum_width
6101 && maximum_width > 0) {
6104 h = specials[special_index].height;
6105 by = cur_y - (font_ascent() / 2) - 1;
6110 w = specials[special_index].width;
6112 w = text_start_x + text_width - cur_x - 1;
6117 if (draw_graph_borders) {
6118 XSetLineAttributes(display, window.gc, 1, LineSolid,
6119 CapButt, JoinMiter);
6120 XDrawRectangle(display, window.drawable, window.gc,
6123 XSetLineAttributes(display, window.gc, 1, LineSolid,
6124 CapButt, JoinMiter);
6126 if (specials[special_index].last_colour != 0
6127 || specials[special_index].first_colour != 0) {
6128 tmpcolour = do_gradient(w - 1, specials[special_index].last_colour, specials[special_index].first_colour);
6131 for (i = w - 2; i > -1; i--) {
6132 if (specials[special_index].last_colour != 0
6133 || specials[special_index].first_colour != 0) {
6134 if (specials[special_index].tempgrad) {
6137 (int)((float)(w - 2) - specials[special_index].graph[j] *
6138 (w - 2) / (float)specials[special_index].graph_scale)
6142 (int)((float)(w - 2) - specials[special_index].graph[j] *
6143 (w - 2) / (float)specials[special_index].graph_scale)
6146 if (specials[special_index].graph[j] == specials[special_index].graph_scale) {
6148 (int)((float)(w - 2) - specials[special_index].graph[j] *
6149 (w - 2) / (float)specials[special_index].graph_scale)
6153 #endif /* DEBUG_lol */
6154 XSetForeground(display, window.gc, tmpcolour[
6155 (int)((float)(w - 2) - specials[special_index].graph[j] *
6156 (w - 2) / (float)specials[special_index].graph_scale)
6159 XSetForeground(display, window.gc, tmpcolour[colour_idx++]);
6162 /* this is mugfugly, but it works */
6163 XDrawLine(display, window.drawable, window.gc,
6164 cur_x + i + 1, by + h, cur_x + i + 1,
6165 round_to_int((double)by + h - specials[special_index].graph[j] *
6166 (h - 1) / specials[special_index].graph_scale));
6167 if ((w - i) / ((float) (w - 2) /
6168 (specials[special_index].graph_width)) > j
6169 && j < MAX_GRAPH_DEPTH - 3) {
6173 if (tmpcolour) free(tmpcolour);
6178 /* if (draw_mode == BG) {
6179 set_foreground_color(default_bg_color);
6180 } else if (draw_mode == OUTLINE) {
6181 set_foreground_color(default_out_color);
6183 set_foreground_color(default_fg_color);
6185 if (show_graph_range) {
6188 unsigned short int seconds = update_interval * w;
6193 unsigned short int timeunits;
6195 timeunits = seconds / 86400; seconds %= 86400;
6196 if (timeunits > 0) {
6197 asprintf(&tmp_day_str, "%dd", timeunits);
6199 tmp_day_str = strdup("");
6201 timeunits = seconds / 3600; seconds %= 3600;
6202 if (timeunits > 0) {
6203 asprintf(&tmp_hour_str, "%dh", timeunits);
6205 tmp_hour_str = strdup("");
6207 timeunits = seconds / 60; seconds %= 60;
6208 if (timeunits > 0) {
6209 asprintf(&tmp_min_str, "%dm", timeunits);
6211 tmp_min_str = strdup("");
6214 asprintf(&tmp_sec_str, "%ds", seconds);
6216 tmp_sec_str = strdup("");
6218 asprintf(&tmp_str, "%s%s%s%s", tmp_day_str, tmp_hour_str, tmp_min_str, tmp_sec_str);
6219 free(tmp_day_str); free(tmp_hour_str); free(tmp_min_str); free(tmp_sec_str);
6221 asprintf(&tmp_str, "Range not possible"); // should never happen, but better safe then sorry
6223 cur_x += (w / 2) - (font_ascent() * (strlen(tmp_str) / 2));
6224 cur_y += font_h / 2;
6225 draw_string(tmp_str);
6231 if (show_graph_scale && (specials[special_index].show_scale == 1)) {
6234 cur_x += font_ascent() / 2;
6235 cur_y += font_h / 2;
6237 calloc(log10(floor(specials[special_index].graph_scale)) + 4,
6239 sprintf(tmp_str, "%.1f", specials[special_index].graph_scale);
6240 draw_string(tmp_str);
6246 set_foreground_color(last_colour);
6252 int old = font_ascent();
6254 cur_y -= font_ascent();
6255 selected_font = specials[special_index].font_added;
6256 if (cur_y + font_ascent() < cur_y + old) {
6259 cur_y += font_ascent();
6262 font_h = font_height();
6266 if (draw_mode == FG) {
6267 set_foreground_color(specials[special_index].arg);
6272 if (draw_mode == BG) {
6273 set_foreground_color(specials[special_index].arg);
6278 if (draw_mode == OUTLINE) {
6279 set_foreground_color(specials[special_index].arg);
6284 w += specials[special_index].arg;
6288 cur_y += specials[special_index].arg;
6292 if (specials[special_index].arg >= 0) {
6293 cur_x = (int) specials[special_index].arg;
6299 int start = specials[special_index].arg;
6300 int step = specials[special_index].width;
6302 if (!step || step < 0) {
6305 w = step - (cur_x - text_start_x - start) % step;
6311 /* TODO: add back in "+ border_margin" to the end of
6313 int pos_x = text_start_x + text_width -
6314 get_string_width_special(s);
6316 /* printf("pos_x %i text_start_x %i text_width %i cur_x %i "
6317 "get_string_width(p) %i gap_x %i "
6318 "specials[special_index].arg %i border_margin %i "
6319 "border_width %i\n", pos_x, text_start_x, text_width,
6320 cur_x, get_string_width_special(s), gap_x,
6321 specials[special_index].arg, border_margin,
6323 if (pos_x > specials[special_index].arg && pos_x > cur_x) {
6324 cur_x = pos_x - specials[special_index].arg;
6331 int pos_x = (text_width) / 2 - get_string_width_special(s) /
6332 2 - (cur_x - text_start_x);
6333 /* int pos_x = text_start_x + text_width / 2 -
6334 get_string_width_special(s) / 2; */
6336 /* printf("pos_x %i text_start_x %i text_width %i cur_x %i "
6337 "get_string_width(p) %i gap_x %i "
6338 "specials[special_index].arg %i\n", pos_x, text_start_x,
6339 text_width, cur_x, get_string_width(s), gap_x,
6340 specials[special_index].arg); */
6341 if (pos_x > specials[special_index].arg) {
6342 w = pos_x - specials[special_index].arg;
6356 if (cur_y_add > 0) {
6360 cur_y += font_descent();
6365 static void draw_text(void)
6368 if (output_methods & TO_X) {
6369 cur_y = text_start_y;
6372 if (draw_borders && border_width > 0) {
6373 unsigned int b = (border_width + 1) / 2;
6375 if (stippled_borders) {
6376 char ss[2] = { stippled_borders, stippled_borders };
6377 XSetLineAttributes(display, window.gc, border_width, LineOnOffDash,
6378 CapButt, JoinMiter);
6379 XSetDashes(display, window.gc, 0, ss, 2);
6381 XSetLineAttributes(display, window.gc, border_width, LineSolid,
6382 CapButt, JoinMiter);
6385 XDrawRectangle(display, window.drawable, window.gc,
6386 text_start_x - border_margin + b, text_start_y - border_margin + b,
6387 text_width + border_margin * 2 - 1 - b * 2,
6388 text_height + border_margin * 2 - 1 - b * 2);
6395 for_each_line(text_buffer, draw_line);
6398 static void draw_stuff(void)
6400 if (overwrite_file) {
6401 overwrite_fpointer = fopen(overwrite_file, "w");
6402 if(!overwrite_fpointer)
6403 ERR("Can't overwrite '%s' anymore", overwrite_file);
6406 append_fpointer = fopen(append_file, "a");
6407 if(!append_fpointer)
6408 ERR("Can't append '%s' anymore", append_file);
6411 if (output_methods & TO_X) {
6413 if (draw_shades && !draw_outline) {
6416 set_foreground_color(default_bg_color);
6427 for (i = -1; i < 2; i++) {
6428 for (j = -1; j < 2; j++) {
6429 if (i == 0 && j == 0) {
6434 set_foreground_color(default_out_color);
6435 draw_mode = OUTLINE;
6443 set_foreground_color(default_fg_color);
6449 if (output_methods & TO_X) {
6454 swap.swap_window = window.window;
6455 swap.swap_action = XdbeBackground;
6456 XdbeSwapBuffers(display, &swap, 1);
6461 if(overwrite_fpointer) {
6462 fclose(overwrite_fpointer);
6463 overwrite_fpointer = 0;
6465 if(append_fpointer) {
6466 fclose(append_fpointer);
6467 append_fpointer = 0;
6472 static void clear_text(int exposures)
6476 /* The swap action is XdbeBackground, which clears */
6480 if (display && window.window) { // make sure these are !null
6481 /* there is some extra space for borders and outlines */
6482 XClearArea(display, window.window, text_start_x - border_margin - 1,
6483 text_start_y - border_margin - 1,
6484 text_width + border_margin * 2 + 2,
6485 text_height + border_margin * 2 + 2, exposures ? True : 0);
6490 static int need_to_update;
6492 /* update_text() generates new text and clears old text area */
6493 static void update_text(void)
6500 if (output_methods & TO_X)
6506 #ifdef HAVE_SYS_INOTIFY_H
6510 static void main_loop(void)
6513 #ifdef SIGNAL_BLOCKING
6514 sigset_t newmask, oldmask;
6517 #ifdef HAVE_SYS_INOTIFY_H
6518 int inotify_config_wd = 0;
6519 #define INOTIFY_EVENT_SIZE (sizeof(struct inotify_event))
6520 #define INOTIFY_BUF_LEN (20 * (INOTIFY_EVENT_SIZE + 16))
6521 char inotify_buff[INOTIFY_BUF_LEN];
6522 #endif /* HAVE_SYS_INOTIFY_H */
6525 #ifdef SIGNAL_BLOCKING
6526 sigemptyset(&newmask);
6527 sigaddset(&newmask, SIGINT);
6528 sigaddset(&newmask, SIGTERM);
6529 sigaddset(&newmask, SIGUSR1);
6532 next_update_time = last_update_time = get_time();
6534 while (terminate == 0 && (total_run_times == 0 || info.looped < total_run_times)) {
6537 #ifdef SIGNAL_BLOCKING
6538 /* block signals. we will inspect for pending signals later */
6539 if (sigprocmask(SIG_BLOCK, &newmask, &oldmask) < 0) {
6540 CRIT_ERR("unable to sigprocmask()");
6545 if (output_methods & TO_X) {
6548 /* wait for X event or timeout */
6550 if (!XPending(display)) {
6554 t = next_update_time - get_time();
6558 } else if (t > update_interval) {
6559 t = update_interval;
6562 tv.tv_sec = (long) t;
6563 tv.tv_usec = (long) (t * 1000000) % 1000000;
6565 FD_SET(ConnectionNumber(display), &fdsr);
6567 s = select(ConnectionNumber(display) + 1, &fdsr, 0, 0, &tv);
6569 if (errno != EINTR) {
6570 ERR("can't select(): %s", strerror(errno));
6580 if (need_to_update) {
6582 int wx = window.x, wy = window.y;
6590 /* resize window if it isn't right size */
6592 && (text_width + border_margin * 2 + 1 != window.width
6593 || text_height + border_margin * 2 + 1 != window.height)) {
6594 window.width = text_width + border_margin * 2 + 1;
6595 window.height = text_height + border_margin * 2 + 1;
6596 XResizeWindow(display, window.window, window.width,
6599 set_transparent_background(window.window);
6603 /* move window if it isn't in right position */
6604 if (!fixed_pos && (window.x != wx || window.y != wy)) {
6605 XMoveWindow(display, window.window, window.x, window.y);
6616 r.x = text_start_x - border_margin;
6617 r.y = text_start_y - border_margin;
6618 r.width = text_width + border_margin * 2;
6619 r.height = text_height + border_margin * 2;
6620 XUnionRectWithRegion(&r, x11_stuff.region, x11_stuff.region);
6625 /* handle X events */
6626 while (XPending(display)) {
6629 XNextEvent(display, &ev);
6636 r.width = ev.xexpose.width;
6637 r.height = ev.xexpose.height;
6638 XUnionRectWithRegion(&r, x11_stuff.region, x11_stuff.region);
6643 case ReparentNotify:
6644 /* set background to ParentRelative for all parents */
6646 set_transparent_background(window.window);
6650 case ConfigureNotify:
6652 /* if window size isn't what expected, set fixed size */
6653 if (ev.xconfigure.width != window.width
6654 || ev.xconfigure.height != window.height) {
6655 if (window.width != 0 && window.height != 0) {
6659 /* clear old stuff before screwing up
6664 XWindowAttributes attrs;
6665 if (XGetWindowAttributes(display,
6666 window.window, &attrs)) {
6667 window.width = attrs.width;
6668 window.height = attrs.height;
6672 text_width = window.width - border_margin * 2 - 1;
6673 text_height = window.height - border_margin * 2 - 1;
6674 if (text_width > maximum_width
6675 && maximum_width > 0) {
6676 text_width = maximum_width;
6680 /* if position isn't what expected, set fixed pos
6681 * total_updates avoids setting fixed_pos when window
6682 * is set to weird locations when started */
6683 /* // this is broken
6684 if (total_updates >= 2 && !fixed_pos
6685 && (window.x != ev.xconfigure.x
6686 || window.y != ev.xconfigure.y)
6687 && (ev.xconfigure.x != 0
6688 || ev.xconfigure.y != 0)) {
6697 /* if an ordinary window with decorations */
6698 if ((window.type == TYPE_NORMAL)
6699 && (!TEST_HINT(window.hints,
6700 HINT_UNDECORATED))) {
6701 /* allow conky to hold input focus. */
6704 /* forward the click to the desktop window */
6705 XUngrabPointer(display, ev.xbutton.time);
6706 ev.xbutton.window = window.desktop;
6707 XSendEvent(display, ev.xbutton.window, False,
6708 ButtonPressMask, &ev);
6709 XSetInputFocus(display, ev.xbutton.window,
6710 RevertToParent, ev.xbutton.time);
6717 /* if an ordinary window with decorations */
6718 if ((window.type == TYPE_NORMAL)
6719 && (!TEST_HINT(window.hints,
6720 HINT_UNDECORATED))) {
6721 /* allow conky to hold input focus. */
6724 /* forward the release to the desktop window */
6725 ev.xbutton.window = window.desktop;
6726 XSendEvent(display, ev.xbutton.window, False,
6727 ButtonReleaseMask, &ev);
6736 if (ev.type == x11_stuff.event_base + XDamageNotify) {
6737 XDamageNotifyEvent *dev = (XDamageNotifyEvent *) &ev;
6739 XFixesSetRegion(display, x11_stuff.part, &dev->area, 1);
6740 XFixesUnionRegion(display, x11_stuff.region2, x11_stuff.region2, x11_stuff.part);
6742 #endif /* HAVE_XDAMAGE */
6748 XDamageSubtract(display, x11_stuff.damage, x11_stuff.region2, None);
6749 XFixesSetRegion(display, x11_stuff.region2, 0, 0);
6750 #endif /* HAVE_XDAMAGE */
6752 /* XDBE doesn't seem to provide a way to clear the back buffer without
6753 * interfering with the front buffer, other than passing XdbeBackground
6754 * to XdbeSwapBuffers. That means that if we're using XDBE, we need to
6755 * redraw the text even if it wasn't part of the exposed area. OTOH,
6756 * if we're not going to call draw_stuff at all, then no swap happens
6757 * and we can safely do nothing. */
6759 if (!XEmptyRegion(x11_stuff.region)) {
6764 r.x = text_start_x - border_margin;
6765 r.y = text_start_y - border_margin;
6766 r.width = text_width + border_margin * 2;
6767 r.height = text_height + border_margin * 2;
6768 XUnionRectWithRegion(&r, x11_stuff.region, x11_stuff.region);
6771 XSetRegion(display, window.gc, x11_stuff.region);
6774 XftDrawSetClip(window.xftdraw, x11_stuff.region);
6778 cimlib_render(text_start_x, text_start_y, window.width, window.height);
6781 XDestroyRegion(x11_stuff.region);
6782 x11_stuff.region = XCreateRegion();
6786 t = (next_update_time - get_time()) * 1000000;
6787 if(t > 0) usleep((useconds_t)t);
6794 #ifdef SIGNAL_BLOCKING
6795 /* unblock signals of interest and let handler fly */
6796 if (sigprocmask(SIG_SETMASK, &oldmask, NULL) < 0) {
6797 CRIT_ERR("unable to sigprocmask()");
6801 switch (g_signal_pending) {
6804 ERR("received SIGHUP or SIGUSR1. reloading the config file.");
6809 ERR("received SIGINT or SIGTERM to terminate. bye!");
6813 if (output_methods & TO_X) {
6814 XDestroyRegion(x11_stuff.region);
6815 x11_stuff.region = NULL;
6817 XDamageDestroy(display, x11_stuff.damage);
6818 XFixesDestroyRegion(display, x11_stuff.region2);
6819 XFixesDestroyRegion(display, x11_stuff.part);
6820 #endif /* HAVE_XDAMAGE */
6826 if(overwrite_file) {
6827 free(overwrite_file);
6836 /* Reaching here means someone set a signal
6837 * (SIGXXXX, signal_handler), but didn't write any code
6839 * If you don't want to handle a signal, don't set a handler on
6840 * it in the first place. */
6841 if (g_signal_pending) {
6842 ERR("ignoring signal (%d)", g_signal_pending);
6846 #ifdef HAVE_SYS_INOTIFY_H
6847 if (inotify_fd && !inotify_config_wd) {
6848 inotify_config_wd = inotify_add_watch(inotify_fd,
6852 if (inotify_fd && inotify_config_wd) {
6853 int len = 0, idx = 0;
6855 struct timeval time_to_wait;
6857 FD_ZERO (&descriptors);
6858 FD_SET(inotify_fd, &descriptors);
6860 time_to_wait.tv_sec = time_to_wait.tv_usec = 0;
6862 select(inotify_fd + 1, &descriptors, NULL, NULL, &time_to_wait);
6863 if (FD_ISSET(inotify_fd, &descriptors)) {
6864 /* process inotify events */
6865 len = read(inotify_fd, inotify_buff, INOTIFY_BUF_LEN);
6866 while (len > 0 && idx < len) {
6867 struct inotify_event *ev = (struct inotify_event *) &inotify_buff[idx];
6868 if (ev->wd == inotify_config_wd && (ev->mask & IN_MODIFY || ev->mask & IN_IGNORED)) {
6869 /* current_config should be reloaded */
6870 ERR("'%s' modified, reloading...", current_config);
6872 if (ev->mask & IN_IGNORED) {
6873 /* for some reason we get IN_IGNORED here
6874 * sometimes, so we need to re-add the watch */
6875 inotify_config_wd = inotify_add_watch(inotify_fd,
6882 llua_inotify_query(ev->wd, ev->mask);
6884 #endif /* HAVE_LUA */
6885 idx += INOTIFY_EVENT_SIZE + ev->len;
6889 #endif /* HAVE_SYS_INOTIFY_H */
6891 g_signal_pending = 0;
6894 #ifdef HAVE_SYS_INOTIFY_H
6896 inotify_rm_watch(inotify_fd, inotify_config_wd);
6898 inotify_fd = inotify_config_wd = 0;
6900 #endif /* HAVE_SYS_INOTIFY_H */
6903 X11_destroy_window();
6907 static void load_config_file(const char *);
6908 static void load_config_file_x11(const char *);
6910 /* reload the config file */
6911 static void reload_config(void)
6913 timed_thread_destroy_registered_threads();
6915 if (info.cpu_usage) {
6916 free(info.cpu_usage);
6917 info.cpu_usage = NULL;
6928 #ifdef TCP_PORT_MONITOR
6929 tcp_portmon_clear();
6934 #endif /* HAVE_LUA */
6937 X11_destroy_window();
6940 if (current_config) {
6942 load_config_file(current_config);
6943 load_config_file_x11(current_config);
6945 /* re-init specials array */
6946 if ((specials = realloc((void *) specials,
6947 sizeof(struct special_t) * max_specials)) == 0) {
6948 ERR("failed to realloc specials array");
6953 if (output_methods & TO_X) {
6954 X11_initialisation();
6957 extract_variable_text(global_text);
6963 tmpstring1 = malloc(text_buffer_size);
6964 memset(tmpstring1, 0, text_buffer_size);
6968 tmpstring2 = malloc(text_buffer_size);
6969 memset(tmpstring2, 0, text_buffer_size);
6973 text_buffer = malloc(max_user_text);
6974 memset(text_buffer, 0, max_user_text);
6977 X11_create_window();
6982 static void clean_up(void)
6985 timed_thread_destroy_registered_threads();
6987 if (info.cpu_usage) {
6988 free(info.cpu_usage);
6989 info.cpu_usage = NULL;
6992 if (output_methods & TO_X) {
6995 XdbeDeallocateBackBufferName(display, window.back_buffer);
7000 XDestroyWindow(display, window.window);
7001 XClearWindow(display, RootWindow(display, screen));
7006 XClearWindow(display, RootWindow(display, screen));
7011 XFreeGC(display, window.gc);
7013 for (i = 0; i < 10; i ++) {
7023 free_text_objects(&global_root_object, 0);
7042 free(current_config);
7044 #ifdef TCP_PORT_MONITOR
7045 tcp_portmon_clear();
7052 #endif /* HAVE_LUA */
7055 for (i = 0; i < special_count; i++) {
7056 if (specials[i].type == GRAPH) {
7057 free(specials[i].graph);
7064 clear_diskio_stats();
7067 static int string_to_bool(const char *s)
7070 // Assumes an option without a true/false means true
7072 } else if (strcasecmp(s, "yes") == EQUAL) {
7074 } else if (strcasecmp(s, "true") == EQUAL) {
7076 } else if (strcasecmp(s, "1") == EQUAL) {
7083 static enum alignment string_to_alignment(const char *s)
7085 if (strcasecmp(s, "top_left") == EQUAL) {
7087 } else if (strcasecmp(s, "top_right") == EQUAL) {
7089 } else if (strcasecmp(s, "top_middle") == EQUAL) {
7091 } else if (strcasecmp(s, "bottom_left") == EQUAL) {
7093 } else if (strcasecmp(s, "bottom_right") == EQUAL) {
7094 return BOTTOM_RIGHT;
7095 } else if (strcasecmp(s, "bottom_middle") == EQUAL) {
7096 return BOTTOM_MIDDLE;
7097 } else if (strcasecmp(s, "middle_left") == EQUAL) {
7099 } else if (strcasecmp(s, "middle_right") == EQUAL) {
7100 return MIDDLE_RIGHT;
7101 } else if (strcasecmp(s, "tl") == EQUAL) {
7103 } else if (strcasecmp(s, "tr") == EQUAL) {
7105 } else if (strcasecmp(s, "tm") == EQUAL) {
7107 } else if (strcasecmp(s, "bl") == EQUAL) {
7109 } else if (strcasecmp(s, "br") == EQUAL) {
7110 return BOTTOM_RIGHT;
7111 } else if (strcasecmp(s, "bm") == EQUAL) {
7112 return BOTTOM_MIDDLE;
7113 } else if (strcasecmp(s, "ml") == EQUAL) {
7115 } else if (strcasecmp(s, "mr") == EQUAL) {
7116 return MIDDLE_RIGHT;
7117 } else if (strcasecmp(s, "none") == EQUAL) {
7125 static void set_default_configurations_for_x(void)
7127 default_fg_color = WhitePixel(display, screen);
7128 default_bg_color = BlackPixel(display, screen);
7129 default_out_color = BlackPixel(display, screen);
7130 color0 = default_fg_color;
7131 color1 = default_fg_color;
7132 color2 = default_fg_color;
7133 color3 = default_fg_color;
7134 color4 = default_fg_color;
7135 color5 = default_fg_color;
7136 color6 = default_fg_color;
7137 color7 = default_fg_color;
7138 color8 = default_fg_color;
7139 color9 = default_fg_color;
7143 static void set_default_configurations(void)
7146 fork_to_background = 0;
7147 total_run_times = 0;
7148 info.cpu_avg_samples = 2;
7149 info.net_avg_samples = 2;
7150 info.diskio_avg_samples = 2;
7158 mpd_set_host("localhost");
7159 mpd_set_port("6600");
7162 info.xmms2.artist = NULL;
7163 info.xmms2.album = NULL;
7164 info.xmms2.title = NULL;
7165 info.xmms2.genre = NULL;
7166 info.xmms2.comment = NULL;
7167 info.xmms2.url = NULL;
7168 info.xmms2.status = NULL;
7169 info.xmms2.playlist = NULL;
7171 use_spacer = NO_SPACER;
7173 output_methods = TO_X;
7175 output_methods = TO_STDOUT;
7178 show_graph_scale = 0;
7179 show_graph_range = 0;
7180 template[0] = strdup("");
7181 template[1] = strdup("");
7182 template[2] = strdup("");
7183 template[3] = strdup("");
7184 template[4] = strdup("");
7185 template[5] = strdup("");
7186 template[6] = strdup("");
7187 template[7] = strdup("");
7188 template[8] = strdup("");
7189 template[9] = strdup("");
7192 draw_graph_borders = 1;
7194 set_first_font("6x10");
7202 window.type = TYPE_NORMAL;
7204 strcpy(window.class_name, PACKAGE_NAME);
7205 sprintf(window.title, PACKAGE_NAME" (%s)", info.uname_s.nodename);
7207 stippled_borders = 0;
7210 text_alignment = BOTTOM_LEFT;
7211 info.x11.monitor.number = 1;
7212 info.x11.monitor.current = 0;
7215 free(current_mail_spool);
7219 variable_substitute(MAIL_FILE, buf, 256);
7220 if (buf[0] != '\0') {
7221 current_mail_spool = strndup(buf, text_buffer_size);
7226 update_interval = 3.0;
7227 info.music_player_interval = 1.0;
7228 stuff_in_upper_case = 0;
7229 info.users.number = 1;
7231 #ifdef TCP_PORT_MONITOR
7232 /* set default connection limit */
7233 tcp_portmon_set_max_connections(0);
7237 /* returns 1 if you can overwrite or create the file at 'path' */
7238 static _Bool overwrite_works(const char *path)
7242 if (!(filepointer = fopen(path, "w")))
7244 fclose(filepointer);
7248 /* returns 1 if you can append or create the file at 'path' */
7249 static _Bool append_works(const char *path)
7253 if (!(filepointer = fopen(path, "a")))
7255 fclose(filepointer);
7260 static void X11_initialisation(void)
7262 if (x_initialised == YES) return;
7263 output_methods |= TO_X;
7265 set_default_configurations_for_x();
7266 x_initialised = YES;
7269 static void X11_destroy_window(void)
7271 /* this function only exists for the sake of consistency */
7272 if (output_methods & TO_X) {
7274 XDamageDestroy(display, x11_stuff.damage);
7275 XFixesDestroyRegion(display, x11_stuff.region2);
7276 XFixesDestroyRegion(display, x11_stuff.part);
7277 if (x11_stuff.region) {
7278 XDestroyRegion(x11_stuff.region);
7280 x11_stuff.region = NULL;
7281 #endif /* HAVE_XDAMAGE */
7286 static char **xargv = 0;
7287 static int xargc = 0;
7289 static void X11_create_window(void)
7291 if (output_methods & TO_X) {
7293 init_window(own_window, text_width + border_margin * 2 + 1,
7294 text_height + border_margin * 2 + 1, set_transparent, background_colour,
7296 #else /* OWN_WINDOW */
7297 init_window(0, text_width + border_margin * 2 + 1,
7298 text_height + border_margin * 2 + 1, set_transparent, 0,
7300 #endif /* OWN_WINDOW */
7304 update_text_area(); /* to position text/window on screen */
7307 if (own_window && !fixed_pos) {
7308 XMoveWindow(display, window.window, window.x, window.y);
7311 set_transparent_background(window.window);
7320 x11_stuff.region = XCreateRegion();
7322 if (!XDamageQueryExtension(display, &x11_stuff.event_base, &x11_stuff.error_base)) {
7323 ERR("Xdamage extension unavailable");
7325 x11_stuff.damage = XDamageCreate(display, window.window, XDamageReportNonEmpty);
7326 x11_stuff.region2 = XFixesCreateRegionFromWindow(display, window.window, 0);
7327 x11_stuff.part = XFixesCreateRegionFromWindow(display, window.window, 0);
7328 #endif /* HAVE_XDAMAGE */
7331 update_text_area(); /* to get initial size of the window */
7336 #define CONF_ERR ERR("%s: %d: config file error", f, line)
7337 #define CONF_ERR2(a) ERR("%s: %d: config file error: %s", f, line, a)
7338 #define CONF2(a) if (strcasecmp(name, a) == 0)
7339 #define CONF(a) else CONF2(a)
7340 #define CONF3(a, b) else if (strcasecmp(name, a) == 0 \
7341 || strcasecmp(name, b) == 0)
7342 #define CONF_CONTINUE 1
7343 #define CONF_BREAK 2
7344 #define CONF_BUFF_SIZE 512
7346 static FILE *open_config_file(const char *f)
7348 #ifdef CONFIG_OUTPUT
7349 if (!strcmp(f, "==builtin==")) {
7350 #ifdef HAVE_FOPENCOOKIE
7351 return fopencookie(NULL, "r", conf_cookie);
7352 #endif /* HAVE_FOPENCOOKIE */
7354 #endif /* CONFIG_OUTPUT */
7355 return fopen(f, "r");
7358 static int do_config_step(int *line, FILE *fp, char *buf, char **name, char **value)
7362 if (fgets(buf, CONF_BUFF_SIZE, fp) == NULL) {
7365 remove_comments(buf);
7370 while (*p && isspace((int) *p)) {
7374 return CONF_CONTINUE; /* empty line */
7381 while (*p2 && !isspace((int) *p2)) {
7385 *p2 = '\0'; /* break at name's end */
7392 while (*p && isspace((int) *p)) {
7398 p2 = *value + strlen(*value);
7399 while (isspace((int) *(p2 - 1))) {
7408 static void load_config_file(const char *f)
7413 set_default_configurations();
7414 fp = open_config_file(f);
7418 DBGP("reading contents from config file '%s'", f);
7421 char buff[CONF_BUFF_SIZE], *name, *value;
7422 int ret = do_config_step(&line, fp, buff, &name, &value);
7423 if (ret == CONF_BREAK) {
7425 } else if (ret == CONF_CONTINUE) {
7431 /* don't listen if X is already initialised or
7432 * if we already know we don't want it */
7433 if(x_initialised == NO) {
7434 if (string_to_bool(value)) {
7435 output_methods &= TO_X;
7437 output_methods &= ~TO_X;
7438 x_initialised = NEVER;
7443 if (!value || x_initialised == YES) {
7448 disp = strdup(value);
7452 if (window.type == TYPE_DOCK)
7455 int a = string_to_alignment(value);
7466 CONF("background") {
7467 fork_to_background = string_to_bool(value);
7470 CONF2("background") {
7471 fork_to_background = string_to_bool(value);
7475 CONF("show_graph_scale") {
7476 show_graph_scale = string_to_bool(value);
7478 CONF("show_graph_range") {
7479 show_graph_range = string_to_bool(value);
7481 CONF("border_margin") {
7483 border_margin = strtol(value, 0, 0);
7488 CONF("border_width") {
7490 border_width = strtol(value, 0, 0);
7495 #define TEMPLATE_CONF(n) \
7496 CONF("template"#n) { \
7498 free(template[n]); \
7499 template[n] = strdup(value); \
7517 info.mail = parse_mail_args(IMAP_TYPE, value);
7524 info.mail = parse_mail_args(POP3_TYPE, value);
7529 CONF("default_bar_size") {
7532 if (sscanf(value, "%d %d", &default_bar_width, &default_bar_height) != 2) {
7539 CONF_ERR2("default_bar_size takes 2 integer arguments (ie. 'default_bar_size 0 6')")
7543 CONF("default_graph_size") {
7546 if (sscanf(value, "%d %d", &default_graph_width, &default_graph_height) != 2) {
7553 CONF_ERR2("default_graph_size takes 2 integer arguments (ie. 'default_graph_size 0 6')")
7556 CONF("default_gauge_size") {
7559 if (sscanf(value, "%d %d", &default_gauge_width, &default_gauge_height) != 2) {
7566 CONF_ERR2("default_gauge_size takes 2 integer arguments (ie. 'default_gauge_size 0 6')")
7573 mpd_set_host(value);
7579 if (value && mpd_set_port(value)) {
7583 CONF("mpd_password") {
7585 mpd_set_password(value);
7591 CONF("music_player_interval") {
7593 info.music_player_interval = strtod(value, 0);
7599 CONF("sensor_device") {
7601 sensor_device = strtol(value, 0, 0);
7607 CONF("cpu_avg_samples") {
7609 cpu_avg_samples = strtol(value, 0, 0);
7610 if (cpu_avg_samples < 1 || cpu_avg_samples > 14) {
7613 info.cpu_avg_samples = cpu_avg_samples;
7619 CONF("net_avg_samples") {
7621 net_avg_samples = strtol(value, 0, 0);
7622 if (net_avg_samples < 1 || net_avg_samples > 14) {
7625 info.net_avg_samples = net_avg_samples;
7631 CONF("diskio_avg_samples") {
7633 diskio_avg_samples = strtol(value, 0, 0);
7634 if (diskio_avg_samples < 1 || diskio_avg_samples > 14) {
7637 info.diskio_avg_samples = diskio_avg_samples;
7645 CONF("double_buffer") {
7646 use_xdbe = string_to_bool(value);
7650 CONF("override_utf8_locale") {
7651 utf8_mode = string_to_bool(value);
7653 CONF("draw_borders") {
7654 draw_borders = string_to_bool(value);
7656 CONF("draw_graph_borders") {
7657 draw_graph_borders = string_to_bool(value);
7659 CONF("draw_shades") {
7660 draw_shades = string_to_bool(value);
7662 CONF("draw_outline") {
7663 draw_outline = string_to_bool(value);
7666 CONF("out_to_console") {
7667 if(string_to_bool(value))
7668 output_methods |= TO_STDOUT;
7670 CONF("out_to_stderr") {
7671 if(string_to_bool(value))
7672 output_methods |= TO_STDERR;
7674 CONF("overwrite_file") {
7675 if(overwrite_file) {
7676 free(overwrite_file);
7679 if(overwrite_works(value)) {
7680 overwrite_file = strdup(value);
7681 output_methods |= OVERWRITE_FILE;
7683 ERR("overwrite_file won't be able to create/overwrite '%s'", value);
7685 CONF("append_file") {
7690 if(append_works(value)) {
7691 append_file = strdup(value);
7692 output_methods |= APPEND_FILE;
7694 ERR("append_file won't be able to create/append '%s'", value);
7696 CONF("use_spacer") {
7698 if (strcasecmp(value, "left") == EQUAL) {
7699 use_spacer = LEFT_SPACER;
7700 } else if (strcasecmp(value, "right") == EQUAL) {
7701 use_spacer = RIGHT_SPACER;
7702 } else if (strcasecmp(value, "none") == EQUAL) {
7703 use_spacer = NO_SPACER;
7705 use_spacer = string_to_bool(value);
7706 ERR("use_spacer should have an argument of left, right, or"
7707 " none. '%s' seems to be some form of '%s', so"
7708 " defaulting to %s.", value,
7709 use_spacer ? "true" : "false",
7710 use_spacer ? "right" : "none");
7712 use_spacer = RIGHT_SPACER;
7714 use_spacer = NO_SPACER;
7718 ERR("use_spacer should have an argument. Defaulting to right.");
7719 use_spacer = RIGHT_SPACER;
7725 use_xft = string_to_bool(value);
7729 set_first_font(value);
7733 if (value && font_count >= 0) {
7734 fonts[0].font_alpha = atof(value) * 65535.0;
7741 if (string_to_bool(value)) {
7742 ERR("Xft not enabled");
7746 /* xftfont silently ignored when no Xft */
7749 /* xftalpha is silently ignored when no Xft */
7754 set_first_font(value);
7762 gap_x = atoi(value);
7769 gap_y = atoi(value);
7775 CONF("mail_spool") {
7779 variable_substitute(value, buffer, 256);
7781 if (buffer[0] != '\0') {
7782 if (current_mail_spool) {
7783 free(current_mail_spool);
7785 current_mail_spool = strndup(buffer, text_buffer_size);
7792 CONF("minimum_size") {
7794 if (sscanf(value, "%d %d", &minimum_width, &minimum_height)
7796 if (sscanf(value, "%d", &minimum_width) != 1) {
7804 CONF("maximum_width") {
7806 if (sscanf(value, "%d", &maximum_width) != 1) {
7814 CONF("no_buffers") {
7815 no_buffers = string_to_bool(value);
7817 CONF("top_name_width") {
7819 if (sscanf(value, "%u", &top_name_width) != 1) {
7825 if (top_name_width >= max_user_text) {
7826 top_name_width = max_user_text - 1;
7829 CONF("top_cpu_separate") {
7830 cpu_separate = string_to_bool(value);
7832 CONF("short_units") {
7833 short_units = string_to_bool(value);
7835 CONF("pad_percents") {
7836 pad_percents = atoi(value);
7840 CONF("own_window") {
7842 own_window = string_to_bool(value);
7845 CONF("own_window_class") {
7847 memset(window.class_name, 0, sizeof(window.class_name));
7848 strncpy(window.class_name, value,
7849 sizeof(window.class_name) - 1);
7852 CONF("own_window_title") {
7854 memset(window.title, 0, sizeof(window.title));
7855 strncpy(window.title, value, sizeof(window.title) - 1);
7858 CONF("own_window_transparent") {
7860 set_transparent = string_to_bool(value);
7863 CONF("own_window_hints") {
7865 char *p_hint, *p_save;
7866 char delim[] = ", ";
7868 /* tokenize the value into individual hints */
7869 if ((p_hint = strtok_r(value, delim, &p_save)) != NULL) {
7871 /* fprintf(stderr, "hint [%s] parsed\n", p_hint); */
7872 if (strncmp(p_hint, "undecorate", 10) == EQUAL) {
7873 SET_HINT(window.hints, HINT_UNDECORATED);
7874 } else if (strncmp(p_hint, "below", 5) == EQUAL) {
7875 SET_HINT(window.hints, HINT_BELOW);
7876 } else if (strncmp(p_hint, "above", 5) == EQUAL) {
7877 SET_HINT(window.hints, HINT_ABOVE);
7878 } else if (strncmp(p_hint, "sticky", 6) == EQUAL) {
7879 SET_HINT(window.hints, HINT_STICKY);
7880 } else if (strncmp(p_hint, "skip_taskbar", 12) == EQUAL) {
7881 SET_HINT(window.hints, HINT_SKIP_TASKBAR);
7882 } else if (strncmp(p_hint, "skip_pager", 10) == EQUAL) {
7883 SET_HINT(window.hints, HINT_SKIP_PAGER);
7888 p_hint = strtok_r(NULL, delim, &p_save);
7889 } while (p_hint != NULL);
7895 CONF("own_window_type") {
7897 if (strncmp(value, "normal", 6) == EQUAL) {
7898 window.type = TYPE_NORMAL;
7899 } else if (strncmp(value, "desktop", 7) == EQUAL) {
7900 window.type = TYPE_DESKTOP;
7901 } else if (strncmp(value, "dock", 7) == EQUAL) {
7902 window.type = TYPE_DOCK;
7903 text_alignment = TOP_LEFT;
7904 } else if (strncmp(value, "override", 8) == EQUAL) {
7905 window.type = TYPE_OVERRIDE;
7914 CONF("stippled_borders") {
7916 stippled_borders = strtol(value, 0, 0);
7918 stippled_borders = 4;
7922 CONF("imlib_cache_size") {
7924 cimlib_set_cache_size(atoi(value));
7929 CONF("update_interval") {
7931 update_interval = strtod(value, 0);
7935 if (info.music_player_interval == 0) {
7936 // default to update_interval
7937 info.music_player_interval = update_interval;
7940 CONF("total_run_times") {
7942 total_run_times = strtod(value, 0);
7948 stuff_in_upper_case = string_to_bool(value);
7950 CONF("max_specials") {
7952 max_specials = atoi(value);
7957 CONF("max_user_text") {
7959 max_user_text = atoi(value);
7964 CONF("text_buffer_size") {
7966 text_buffer_size = atoi(value);
7967 if (text_buffer_size < DEFAULT_TEXT_BUFFER_SIZE) {
7968 ERR("text_buffer_size must be >=%i bytes", DEFAULT_TEXT_BUFFER_SIZE);
7969 text_buffer_size = DEFAULT_TEXT_BUFFER_SIZE;
7977 if (output_methods & TO_X) {
7978 X11_initialisation();
7987 global_text = (char *) malloc(1);
7988 global_text[0] = '\0';
7991 unsigned int l = strlen(global_text);
7993 char buf[CONF_BUFF_SIZE];
7995 if (fgets(buf, CONF_BUFF_SIZE, fp) == NULL) {
8001 if (bl >= 2 && buf[bl-2] == '\\' && buf[bl-1] == '\n') {
8009 /* Check for continuation of \\-\n. */
8010 if (l > 0 && buf[0] == '\n' && global_text[l-1] == '\\') {
8011 global_text[l-1] = '\0';
8015 global_text = (char *) realloc(global_text, l + bl + 1);
8016 strcat(global_text, buf);
8018 if (strlen(global_text) > max_user_text) {
8023 if (strlen(global_text) < 1) {
8024 CRIT_ERR("no text supplied in configuration; exiting");
8026 global_text_lines = line + 1;
8029 #ifdef TCP_PORT_MONITOR
8030 CONF("max_port_monitor_connections") {
8032 if (!value || (sscanf(value, "%d", &max) != 1)) {
8033 /* an error. use default, warn and continue. */
8034 tcp_portmon_set_max_connections(0);
8036 } else if (tcp_portmon_set_max_connections(max)) {
8037 /* max is < 0, default has been set*/
8042 CONF("if_up_strictness") {
8044 ERR("incorrect if_up_strictness value, defaulting to 'up'");
8045 ifup_strictness = IFUP_UP;
8046 } else if (strcasecmp(value, "up") == EQUAL) {
8047 ifup_strictness = IFUP_UP;
8048 } else if (strcasecmp(value, "link") == EQUAL) {
8049 ifup_strictness = IFUP_LINK;
8050 } else if (strcasecmp(value, "address") == EQUAL) {
8051 ifup_strictness = IFUP_ADDR;
8053 ERR("incorrect if_up_strictness value, defaulting to 'up'");
8054 ifup_strictness = IFUP_UP;
8058 CONF("temperature_unit") {
8060 ERR("config option 'temperature_unit' needs an argument, either 'celsius' or 'fahrenheit'");
8061 } else if (set_temp_output_unit(value)) {
8062 ERR("temperature_unit: incorrect argument");
8068 size_t maxlength = strlen(value); //+1 for terminating 0 not needed, 'cause of the space in the middle of value
8069 char *skey = malloc(maxlength);
8070 char *svalue = malloc(maxlength);
8072 if (sscanf(value, "%[0-9a-zA-Z_] %[^\n]", skey, svalue) == 2) {
8073 oldvalue = getenv(skey);
8074 if (oldvalue == NULL) {
8075 setenv(skey, svalue, 0);
8077 //PS: Don't free oldvalue, it's the real envvar, not a copy
8091 char *ptr = strtok(value, " ");
8094 ptr = strtok(NULL, " ");
8100 #endif /* HAVE_LUA */
8112 CONF("default_color"){}
8113 CONF3("default_shade_color", "default_shadecolor"){}
8114 CONF3("default_outline_color", "default_outlinecolor") {}
8115 CONF("own_window_colour") {}
8118 ERR("%s: %d: no such configuration: '%s'", f, line, name);
8124 if (info.music_player_interval == 0) {
8125 // default to update_interval
8126 info.music_player_interval = update_interval;
8128 if (!global_text) { // didn't supply any text
8129 CRIT_ERR("missing text block in configuration; exiting");
8133 static void load_config_file_x11(const char *f)
8138 fp = open_config_file(f);
8142 DBGP("reading contents from config file '%s'", f);
8145 char buff[CONF_BUFF_SIZE], *name, *value;
8146 int ret = do_config_step(&line, fp, buff, &name, &value);
8147 if (ret == CONF_BREAK) {
8149 } else if (ret == CONF_CONTINUE) {
8155 X11_initialisation();
8156 if (x_initialised == YES) {
8158 color0 = get_x11_color(value);
8165 X11_initialisation();
8166 if (x_initialised == YES) {
8168 color1 = get_x11_color(value);
8175 X11_initialisation();
8176 if (x_initialised == YES) {
8178 color2 = get_x11_color(value);
8185 X11_initialisation();
8186 if (x_initialised == YES) {
8188 color3 = get_x11_color(value);
8195 X11_initialisation();
8196 if (x_initialised == YES) {
8198 color4 = get_x11_color(value);
8205 X11_initialisation();
8206 if (x_initialised == YES) {
8208 color5 = get_x11_color(value);
8215 X11_initialisation();
8216 if (x_initialised == YES) {
8218 color6 = get_x11_color(value);
8225 X11_initialisation();
8226 if (x_initialised == YES) {
8228 color7 = get_x11_color(value);
8235 X11_initialisation();
8236 if (x_initialised == YES) {
8238 color8 = get_x11_color(value);
8245 X11_initialisation();
8246 if (x_initialised == YES) {
8248 color9 = get_x11_color(value);
8254 CONF("default_color") {
8255 X11_initialisation();
8256 if (x_initialised == YES) {
8258 default_fg_color = get_x11_color(value);
8264 CONF3("default_shade_color", "default_shadecolor") {
8265 X11_initialisation();
8266 if (x_initialised == YES) {
8268 default_bg_color = get_x11_color(value);
8274 CONF3("default_outline_color", "default_outlinecolor") {
8275 X11_initialisation();
8276 if (x_initialised == YES) {
8278 default_out_color = get_x11_color(value);
8285 CONF("own_window_colour") {
8286 X11_initialisation();
8287 if (x_initialised == YES) {
8289 background_colour = get_x11_color(value);
8291 ERR("Invalid colour for own_window_colour (try omitting the "
8292 "'#' for hex colours");
8298 //initialize X11 if nothing X11-related is mentioned before TEXT (and if X11 is the default outputmethod)
8299 if(output_methods & TO_X) {
8300 X11_initialisation();
8310 #undef CONF_CONTINUE
8311 #undef CONF_BUFF_SIZE
8318 static void print_help(const char *prog_name) {
8319 printf("Usage: %s [OPTION]...\n"
8320 PACKAGE_NAME" is a system monitor that renders text on desktop or to own transparent\n"
8321 "window. Command line options will override configurations defined in config\n"
8323 " -v, --version version\n"
8324 " -q, --quiet quiet mode\n"
8325 " -D, --debug increase debugging output\n"
8326 " -c, --config=FILE config file to load\n"
8327 #ifdef CONFIG_OUTPUT
8328 " -C, --print-config print the builtin default config to stdout\n"
8329 " e.g. 'conky -C > ~/.conkyrc' will create a new default config\n"
8331 " -d, --daemonize daemonize, fork to background\n"
8332 " -h, --help help\n"
8334 " -a, --alignment=ALIGNMENT text alignment on screen, {top,bottom,middle}_{left,right,middle}\n"
8335 " -f, --font=FONT font to use\n"
8336 " -X, --display=DISPLAY X11 display to use\n"
8338 " -o, --own-window create own window to draw\n"
8341 " -b, --double-buffer double buffer (prevents flickering)\n"
8343 " -w, --window-id=WIN_ID window id to draw\n"
8344 " -x X x position\n"
8345 " -y Y y position\n"
8347 " -t, --text=TEXT text to render, remember single quotes, like -t '$uptime'\n"
8348 " -u, --interval=SECS update interval\n"
8349 " -i COUNT number of times to update "PACKAGE_NAME" (and quit)\n",
8354 /* : means that character before that takes an argument */
8355 static const char *getopt_string = "vVqdDt:u:i:hc:"
8365 #ifdef CONFIG_OUTPUT
8370 static const struct option longopts[] = {
8371 { "help", 0, NULL, 'h' },
8372 { "version", 0, NULL, 'V' },
8373 { "debug", 0, NULL, 'D' },
8374 { "config", 1, NULL, 'c' },
8375 #ifdef CONFIG_OUTPUT
8376 { "print-config", 0, NULL, 'C' },
8378 { "daemonize", 0, NULL, 'd' },
8380 { "alignment", 1, NULL, 'a' },
8381 { "font", 1, NULL, 'f' },
8382 { "display", 1, NULL, 'X' },
8384 { "own-window", 0, NULL, 'o' },
8387 { "double-buffer", 0, NULL, 'b' },
8389 { "window-id", 1, NULL, 'w' },
8391 { "text", 1, NULL, 't' },
8392 { "interval", 0, NULL, 'u' },
8396 int main(int argc, char **argv)
8402 struct sigaction act, oact;
8404 g_signal_pending = 0;
8405 memset(&info, 0, sizeof(info));
8408 #ifdef TCP_PORT_MONITOR
8409 /* set default connection limit */
8410 tcp_portmon_set_max_connections(0);
8413 /* handle command line parameters that don't change configs */
8415 if (((s = getenv("LC_ALL")) && *s) || ((s = getenv("LC_CTYPE")) && *s)
8416 || ((s = getenv("LANG")) && *s)) {
8417 temp = (char *) malloc((strlen(s) + 1) * sizeof(char));
8419 ERR("malloc failed");
8421 for (x = 0; x < strlen(s); x++) {
8422 temp[x] = tolower(s[x]);
8425 if (strstr(temp, "utf-8") || strstr(temp, "utf8")) {
8431 if (!setlocale(LC_CTYPE, "")) {
8432 ERR("Can't set the specified locale!\nCheck LANG, LC_CTYPE, LC_ALL.");
8436 int c = getopt_long(argc, argv, getopt_string, longopts, NULL);
8447 if (current_config) {
8448 free(current_config);
8450 current_config = strndup(optarg, max_user_text);
8453 freopen("/dev/null", "w", stderr);
8456 print_help(argv[0]);
8458 #ifdef CONFIG_OUTPUT
8465 window.window = strtol(optarg, 0, 0);
8474 /* check if specified config file is valid */
8475 if (current_config) {
8477 if (stat(current_config, &sb) ||
8478 (!S_ISREG(sb.st_mode) && !S_ISLNK(sb.st_mode))) {
8479 ERR("invalid configuration file '%s'\n", current_config);
8480 free(current_config);
8485 /* load current_config, CONFIG_FILE or SYSTEM_CONFIG_FILE */
8487 if (!current_config) {
8488 /* load default config file */
8489 char buf[DEFAULT_TEXT_BUFFER_SIZE];
8492 /* Try to use personal config file first */
8493 to_real_path(buf, CONFIG_FILE);
8494 if (buf[0] && (fp = fopen(buf, "r"))) {
8495 current_config = strndup(buf, max_user_text);
8499 /* Try to use system config file if personal config not readable */
8500 if (!current_config && (fp = fopen(SYSTEM_CONFIG_FILE, "r"))) {
8501 current_config = strndup(SYSTEM_CONFIG_FILE, max_user_text);
8505 /* No readable config found */
8506 if (!current_config) {
8507 #ifdef CONFIG_OUTPUT
8508 current_config = strdup("==builtin==");
8509 ERR("no readable personal or system-wide config file found,"
8510 " using builtin default");
8512 CRIT_ERR("no readable personal or system-wide config file found");
8513 #endif /* ! CONF_OUTPUT */
8516 #ifdef HAVE_SYS_INOTIFY_H
8517 inotify_fd = inotify_init();
8518 #endif /* HAVE_SYS_INOTIFY_H */
8520 load_config_file(current_config);
8522 /* init specials array */
8523 if ((specials = calloc(sizeof(struct special_t), max_specials)) == 0) {
8524 ERR("failed to create specials array");
8528 if (current_mail_spool == NULL) {
8531 variable_substitute(MAIL_FILE, buf, 256);
8533 if (buf[0] != '\0') {
8534 current_mail_spool = strndup(buf, text_buffer_size);
8539 /* handle other command line arguments */
8541 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__OpenBSD__) \
8542 || defined(__NetBSD__)
8543 optind = optreset = 1;
8548 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
8549 if ((kd = kvm_open("/dev/null", "/dev/null", "/dev/null", O_RDONLY,
8550 "kvm_open")) == NULL) {
8551 CRIT_ERR("cannot read kvm");
8556 int c = getopt_long(argc, argv, getopt_string, longopts, NULL);
8564 fork_to_background = 1;
8567 global_debug_level++;
8571 set_first_font(optarg);
8574 text_alignment = string_to_alignment(optarg);
8579 disp = strdup(optarg);
8598 global_text = strndup(optarg, max_user_text);
8599 convert_escapes(global_text);
8603 update_interval = strtod(optarg, 0);
8604 if (info.music_player_interval == 0) {
8605 // default to update_interval
8606 info.music_player_interval = update_interval;
8611 total_run_times = strtod(optarg, 0);
8615 gap_x = atoi(optarg);
8619 gap_y = atoi(optarg);
8630 if (output_methods & TO_X) {
8631 load_config_file_x11(current_config);
8635 /* generate text and get initial size */
8636 extract_variable_text(global_text);
8643 if (fork_to_background) {
8648 ERR(PACKAGE_NAME": couldn't fork() to background: %s",
8655 fprintf(stderr, "\n");
8660 /* parent process */
8661 fprintf(stderr, PACKAGE_NAME": forked to background, pid is %d\n",
8668 text_buffer = malloc(max_user_text);
8669 memset(text_buffer, 0, max_user_text);
8670 tmpstring1 = malloc(text_buffer_size);
8671 memset(tmpstring1, 0, text_buffer_size);
8672 tmpstring2 = malloc(text_buffer_size);
8673 memset(tmpstring2, 0, text_buffer_size);
8678 X11_create_window();
8681 /* Set signal handlers */
8682 act.sa_handler = signal_handler;
8683 sigemptyset(&act.sa_mask);
8686 act.sa_flags |= SA_RESTART;
8689 if ( sigaction(SIGINT, &act, &oact) < 0
8690 || sigaction(SIGUSR1, &act, &oact) < 0
8691 || sigaction(SIGHUP, &act, &oact) < 0
8692 || sigaction(SIGTERM, &act, &oact) < 0) {
8693 ERR("error setting signal handler: %s", strerror(errno));
8698 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
8705 static void signal_handler(int sig)
8707 /* signal handler is light as a feather, as it should be.
8708 * we will poll g_signal_pending with each loop of conky
8709 * and do any signal processing there, NOT here. */
8710 g_signal_pending = sig;