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 /* FIXME: apm_getinfo is unused here. maybe it's meant for common.c */
93 #if (defined(__FreeBSD__) || defined(__FreeBSD_kernel__) \
94 || defined(__OpenBSD__)) && (defined(i386) || defined(__i386__))
95 int apm_getinfo(int fd, apm_info_t aip);
96 char *get_apm_adapter(void);
97 char *get_apm_battery_life(void);
98 char *get_apm_battery_time(void);
106 #include "defconfig.h"
107 #ifdef HAVE_FOPENCOOKIE
108 #include "conf_cookie.h"
113 #define S_ISSOCK(x) ((x & S_IFMT) == S_IFSOCK)
116 #define MAIL_FILE "$MAIL"
117 #define MAX_IF_BLOCK_DEPTH 5
119 //#define SIGNAL_BLOCKING
120 #undef SIGNAL_BLOCKING
122 /* debugging level, used by logging.h */
123 int global_debug_level = 0;
125 /* two strings for internal use */
126 static char *tmpstring1, *tmpstring2;
128 /* variables holding various config settings */
136 int top_cpu, top_mem, top_time;
137 static unsigned int top_name_width = 15;
139 enum x_initialiser_state x_initialised = NO;
140 static volatile int g_signal_pending;
141 /* Update interval */
142 double update_interval;
145 /* prototypes for internally used functions */
146 static void signal_handler(int);
147 static void print_version(void) __attribute__((noreturn));
148 static void reload_config(void);
149 static void clean_up(void);
150 static void generate_text_internal(char *, int, struct text_object,
151 struct information *);
152 static int extract_variable_text_internal(struct text_object *,
155 static void print_version(void)
157 printf(PACKAGE_NAME" "VERSION" compiled "BUILD_DATE" for "BUILD_ARCH"\n");
159 printf("\nCompiled in features:\n\n"
160 "System config file: "SYSTEM_CONFIG_FILE"\n\n"
164 " * Xdamage extension\n"
165 # endif /* HAVE_XDAMAGE */
167 " * XDBE (double buffer extension)\n"
168 # endif /* HAVE_XDBE */
173 "\n Music detection:\n"
176 #endif /* AUDACIOUS */
196 #ifdef TCP_PORT_MONITOR
198 #endif /* TCP_PORT_MONITOR */
204 #endif /* HAVE_LUA */
207 #endif /* HAVE_IWLIB */
209 " * support for IBM/Lenovo notebooks\n"
219 #endif /* CONFIG_OUTPUT */
224 " * ALSA mixer support\n"
225 #endif /* MIXER_IS_ALSA */
234 static const char *suffixes[] = { "B", "KiB", "MiB", "GiB", "TiB", "PiB", "" };
239 static void X11_destroy_window(void);
240 static void X11_create_window(void);
242 struct _x11_stuff_s {
246 XserverRegion region2, part;
247 int event_base, error_base;
253 static int text_start_x, text_start_y; /* text start position in window */
254 static int text_width, text_height;
269 /* display to connect to */
270 static char *disp = NULL;
274 /* struct that has all info to be shared between
275 * instances of the same text object */
276 struct information info;
278 /* default config file */
279 static char *current_config;
281 /* set to 1 if you want all text to be in uppercase */
282 static unsigned int stuff_in_upper_case;
284 /* Run how many times? */
285 static unsigned long total_run_times;
288 static int fork_to_background;
290 static int cpu_avg_samples, net_avg_samples, diskio_avg_samples;
292 /* filenames for output */
293 char *overwrite_file = NULL; FILE *overwrite_fpointer = NULL;
294 char *append_file = NULL; FILE *append_fpointer = NULL;
298 static int show_graph_scale;
299 static int show_graph_range;
301 /* Position on the screen */
302 static int text_alignment;
303 static int gap_x, gap_y;
306 static int draw_borders;
307 static int draw_graph_borders;
308 static int stippled_borders;
310 static int draw_shades, draw_outline;
312 static int border_margin, border_width;
314 static long default_fg_color, default_bg_color, default_out_color;
316 /* create own window or draw stuff to root? */
317 static int set_transparent = 0;
320 static int own_window = 0;
321 static int background_colour = 0;
323 /* fixed size/pos is set if wm/user changes them */
324 static int fixed_size = 0, fixed_pos = 0;
327 static int minimum_width, minimum_height;
328 static int maximum_width;
333 static int sensor_device;
336 static long color0, color1, color2, color3, color4, color5, color6, color7,
339 static char *template[10];
341 /* maximum size of config TEXT buffer, i.e. below TEXT line. */
342 static unsigned int max_user_text = MAX_USER_TEXT_DEFAULT;
344 /* maximum size of individual text buffers, ie $exec buffer size */
345 unsigned int text_buffer_size = DEFAULT_TEXT_BUFFER_SIZE;
348 #define CODEPAGE_LENGTH 20
350 long iconv_count = 0;
351 char iconv_converting;
352 static iconv_t **iconv_cd = 0;
354 int register_iconv(iconv_t *new_iconv)
356 iconv_cd = realloc(iconv_cd, sizeof(iconv_t *) * (iconv_count + 1));
358 CRIT_ERR("Out of memory");
360 iconv_cd[iconv_count] = malloc(sizeof(iconv_t));
361 if (!iconv_cd[iconv_count]) {
362 CRIT_ERR("Out of memory");
364 memcpy(iconv_cd[iconv_count], new_iconv, sizeof(iconv_t));
369 void free_iconv(void)
374 for (i = 0; i < iconv_count; i++) {
376 iconv_close(*iconv_cd[i]);
390 /* no buffers in used memory? */
393 /* pad percentages to decimals? */
394 static int pad_percents = 0;
396 static char *global_text = 0;
397 long global_text_lines;
399 static int total_updates;
400 static int updatereset;
402 int check_contains(char *f, char *s)
405 FILE *where = fopen(f, "r");
408 char buf1[256], buf2[256];
410 while (fgets(buf1, 256, where)) {
411 sscanf(buf1, "%255s", buf2);
412 if (strstr(buf2, s)) {
419 ERR("Could not open the file");
425 static inline int calc_text_width(const char *s, int l)
427 if ((output_methods & TO_X) == 0)
434 XftTextExtentsUtf8(display, fonts[selected_font].xftfont,
435 (const FcChar8 *) s, l, &gi);
437 XftTextExtents8(display, fonts[selected_font].xftfont,
438 (const FcChar8 *) s, l, &gi);
444 return XTextWidth(fonts[selected_font].font, s, l);
449 /* formatted text to render on screen, generated in generate_text(),
450 * drawn in draw_stuff() */
452 static char *text_buffer;
455 static unsigned int special_index; /* used when drawing */
458 /* quite boring functions */
460 static inline void for_each_line(char *b, void f(char *))
464 for (ps = b, pe = b; *pe; pe++) {
478 static void convert_escapes(char *buf)
480 char *p = buf, *s = buf;
487 } else if (*s == '\\') {
498 /* Prints anything normally printed with snprintf according to the current value
499 * of use_spacer. Actually slightly more flexible than snprintf, as you can
500 * safely specify the destination buffer as one of your inputs. */
501 int spaced_print(char *buf, int size, const char *format, int width, ...)
510 tempbuf = malloc(size * sizeof(char));
512 // Passes the varargs along to vsnprintf
513 va_start(argp, width);
514 vsnprintf(tempbuf, size, format, argp);
517 switch (use_spacer) {
519 len = snprintf(buf, size, "%s", tempbuf);
522 len = snprintf(buf, size, "%*s", width, tempbuf);
525 len = snprintf(buf, size, "%-*s", width, tempbuf);
532 /* print percentage values
534 * - i.e., unsigned values between 0 and 100
535 * - respect the value of pad_percents */
536 static int percent_print(char *buf, int size, unsigned value)
538 return spaced_print(buf, size, "%u", pad_percents, value);
541 /* converts from bytes to human readable format (K, M, G, T)
543 * The algorithm always divides by 1024, as unit-conversion of byte
544 * counts suggests. But for output length determination we need to
545 * compare with 1000 here, as we print in decimal form. */
546 static void human_readable(long long num, char *buf, int size)
548 const char **suffix = suffixes;
562 if (llabs(num) < 1000LL) {
563 spaced_print(buf, size, format, width, 0, (float)num, *suffix);
567 while (llabs(num / 1024) >= 1000LL && **(suffix + 2)) {
575 /* fnum should now be < 1000, so looks like 'AAA.BBBBB'
577 * The goal is to always have a significance of 3, by
578 * adjusting the decimal part of the number. Sample output:
582 * so the point of alignment resides between number and unit. The
583 * upside of this is that there is minimal padding necessary, though
584 * there should be a way to make alignment take place at the decimal
585 * dot (then with fixed width decimal part).
587 * Note the repdigits below: when given a precision value, printf()
588 * rounds the float to it, not just cuts off the remaining digits. So
589 * e.g. 99.95 with a precision of 1 gets 100.0, which again should be
590 * printed with a precision of 0. Yay. */
592 precision = 0; /* print 100-999 without decimal part */
594 precision = 1; /* print 10-99 with one decimal place */
596 precision = 2; /* print 0-9 with two decimal places */
598 spaced_print(buf, size, format, width, precision, fnum, *suffix);
601 /* global object list root element */
602 static struct text_object global_root_object;
604 static inline void read_exec(const char *data, char *buf, const int size)
606 FILE *fp = popen(data, "r");
607 int length = fread(buf, 1, size, fp);
611 if (length > 0 && buf[length - 1] == '\n') {
612 buf[length - 1] = '\0';
616 void *threaded_exec(void *) __attribute__((noreturn));
618 void *threaded_exec(void *arg)
621 struct text_object *obj = (struct text_object *)arg;
624 buff = malloc(text_buffer_size);
625 read_exec(obj->data.texeci.cmd, buff,
634 timed_thread_lock(obj->data.texeci.p_timed_thread);
635 strncpy(obj->data.texeci.buffer, buff, text_buffer_size);
636 timed_thread_unlock(obj->data.texeci.p_timed_thread);
638 if (timed_thread_test(obj->data.texeci.p_timed_thread, 0)) {
639 timed_thread_exit(obj->data.texeci.p_timed_thread);
645 static struct text_object *new_text_object_internal(void)
647 struct text_object *obj = malloc(sizeof(struct text_object));
648 memset(obj, 0, sizeof(struct text_object));
653 * Frees the list of text objects root points to. When internal = 1, it won't
654 * free global objects.
656 static void free_text_objects(struct text_object *root, int internal)
658 struct text_object *obj;
664 #define data obj->data
665 for (obj = root->prev; obj; obj = root->prev) {
666 root->prev = obj->prev;
672 #endif /* !__OpenBSD__ */
677 close(data.sysfs.fd);
679 #endif /* __linux__ */
685 free(data.tztime.tz);
686 free(data.tztime.fmt);
689 free(data.mboxscan.args);
690 free(data.mboxscan.output);
695 case OBJ_unseen_mails:
696 case OBJ_flagged_mails:
697 case OBJ_unflagged_mails:
698 case OBJ_forwarded_mails:
699 case OBJ_unforwarded_mails:
700 case OBJ_replied_mails:
701 case OBJ_unreplied_mails:
702 case OBJ_draft_mails:
703 case OBJ_trashed_mails:
704 free(data.local_mail.box);
706 case OBJ_imap_unseen:
707 if (!obj->global_mode) {
711 case OBJ_imap_messages:
712 if (!obj->global_mode) {
716 case OBJ_pop3_unseen:
717 if (!obj->global_mode) {
722 if (!obj->global_mode) {
728 free_text_objects(obj->sub, 1);
731 case OBJ_if_existing:
734 free(data.ifblock.s);
735 free(data.ifblock.str);
738 free(data.tail.logfile);
739 free(data.tail.buffer);
755 case OBJ_iconv_start:
760 case OBJ_disk_protect:
764 free(data.ifblock.s);
765 free(data.ifblock.str);
768 if (info.gw_info.iface) {
769 free(info.gw_info.iface);
770 info.gw_info.iface = 0;
772 if (info.gw_info.ip) {
773 free(info.gw_info.ip);
777 case OBJ_ioscheduler:
782 #if (defined(__FreeBSD__) || defined(__linux__))
784 free(data.ifblock.s);
785 free(data.ifblock.str);
788 case OBJ_xmms2_artist:
789 if (info.xmms2.artist) {
790 free(info.xmms2.artist);
791 info.xmms2.artist = 0;
794 case OBJ_xmms2_album:
795 if (info.xmms2.album) {
796 free(info.xmms2.album);
797 info.xmms2.album = 0;
800 case OBJ_xmms2_title:
801 if (info.xmms2.title) {
802 free(info.xmms2.title);
803 info.xmms2.title = 0;
806 case OBJ_xmms2_genre:
807 if (info.xmms2.genre) {
808 free(info.xmms2.genre);
809 info.xmms2.genre = 0;
812 case OBJ_xmms2_comment:
813 if (info.xmms2.comment) {
814 free(info.xmms2.comment);
815 info.xmms2.comment = 0;
819 if (info.xmms2.url) {
820 free(info.xmms2.url);
825 if (info.xmms2.date) {
826 free(info.xmms2.date);
830 case OBJ_xmms2_status:
831 if (info.xmms2.status) {
832 free(info.xmms2.status);
833 info.xmms2.status = 0;
836 case OBJ_xmms2_playlist:
837 if (info.xmms2.playlist) {
838 free(info.xmms2.playlist);
839 info.xmms2.playlist = 0;
842 case OBJ_xmms2_smart:
843 if (info.xmms2.artist) {
844 free(info.xmms2.artist);
845 info.xmms2.artist = 0;
847 if (info.xmms2.title) {
848 free(info.xmms2.title);
849 info.xmms2.title = 0;
851 if (info.xmms2.url) {
852 free(info.xmms2.url);
859 case OBJ_bmpx_artist:
863 case OBJ_bmpx_bitrate:
873 free(data.rss.action);
879 case OBJ_lua_read_parse:
887 #endif /* HAVE_LUA */
894 case OBJ_battery_short:
897 case OBJ_battery_time:
900 #endif /* !__OpenBSD__ */
908 free(data.execi.cmd);
909 free(data.execi.buffer);
912 free(data.texeci.cmd);
913 free(data.texeci.buffer);
921 if (info.first_process && !internal) {
922 free_all_processes();
923 info.first_process = NULL;
925 if (data.top.s) free(data.top.s);
929 free(data.hddtemp.dev);
930 free(data.hddtemp.addr);
931 if (data.hddtemp.temp)
932 free(data.hddtemp.temp);
935 case OBJ_entropy_avail:
936 case OBJ_entropy_poolsize:
938 case OBJ_entropy_bar:
942 if (info.users.names) {
943 free(info.users.names);
944 info.users.names = 0;
948 if (info.users.terms) {
949 free(info.users.terms);
950 info.users.terms = 0;
954 if (info.users.times) {
955 free(info.users.times);
956 info.users.times = 0;
961 case OBJ_smapi_bat_perc:
962 case OBJ_smapi_bat_temp:
963 case OBJ_smapi_bat_power:
966 case OBJ_if_smapi_bat_installed:
967 free(data.ifblock.s);
968 free(data.ifblock.str);
982 case OBJ_mpd_bitrate:
987 case OBJ_mpd_elapsed:
992 case OBJ_mpd_percent:
994 case OBJ_if_mpd_playing:
1002 case OBJ_moc_artist:
1005 case OBJ_moc_totaltime:
1006 case OBJ_moc_timeleft:
1007 case OBJ_moc_curtime:
1008 case OBJ_moc_bitrate:
1014 free(data.scroll.text);
1015 free_text_objects(obj->sub, 1);
1019 free(data.combine.left);
1020 free(data.combine.seperation);
1021 free(data.combine.right);
1022 free_text_objects(obj->sub, 1);
1027 case OBJ_apcupsd_name:
1028 case OBJ_apcupsd_model:
1029 case OBJ_apcupsd_upsmode:
1030 case OBJ_apcupsd_cable:
1031 case OBJ_apcupsd_status:
1032 case OBJ_apcupsd_linev:
1033 case OBJ_apcupsd_load:
1035 case OBJ_apcupsd_loadbar:
1036 case OBJ_apcupsd_loadgraph:
1037 case OBJ_apcupsd_loadgauge:
1039 case OBJ_apcupsd_charge:
1040 case OBJ_apcupsd_timeleft:
1041 case OBJ_apcupsd_temp:
1042 case OBJ_apcupsd_lastxfer:
1044 #endif /* APCUPSD */
1052 void scan_mixer_bar(const char *arg, int *a, int *w, int *h)
1057 if (arg && sscanf(arg, "%63s %n", buf1, &n) >= 1) {
1058 *a = mixer_init(buf1);
1059 scan_bar(arg + n, w, h);
1061 *a = mixer_init(NULL);
1062 scan_bar(arg, w, h);
1067 /* strip a leading /dev/ if any, following symlinks first
1069 * BEWARE: this function returns a pointer to static content
1070 * which gets overwritten in consecutive calls. I.e.:
1071 * this function is NOT reentrant.
1073 static const char *dev_name(const char *path)
1075 static char buf[255]; /* should be enough for pathnames */
1081 #define DEV_NAME(x) \
1082 x != NULL && strlen(x) > 5 && strncmp(x, "/dev/", 5) == 0 ? x + 5 : x
1083 if ((buflen = readlink(path, buf, 254)) == -1)
1084 return DEV_NAME(path);
1086 return DEV_NAME(buf);
1090 static int parse_top_args(const char *s, const char *arg, struct text_object *obj)
1095 if (obj->data.top.was_parsed) {
1098 obj->data.top.was_parsed = 1;
1100 if (arg && !obj->data.top.s) {
1101 obj->data.top.s = strndup(arg, text_buffer_size);
1104 need_mask |= (1 << INFO_TOP);
1107 obj->type = OBJ_top;
1109 } else if (strcmp(&s[3], "_mem") == EQUAL) {
1110 obj->type = OBJ_top_mem;
1112 } else if (strcmp(&s[3], "_time") == EQUAL) {
1113 obj->type = OBJ_top_time;
1116 ERR("Must be top, top_mem or top_time");
1121 ERR("top needs arguments");
1125 if (sscanf(arg, "%63s %i", buf, &n) == 2) {
1126 if (strcmp(buf, "name") == EQUAL) {
1127 obj->data.top.type = TOP_NAME;
1128 } else if (strcmp(buf, "cpu") == EQUAL) {
1129 obj->data.top.type = TOP_CPU;
1130 } else if (strcmp(buf, "pid") == EQUAL) {
1131 obj->data.top.type = TOP_PID;
1132 } else if (strcmp(buf, "mem") == EQUAL) {
1133 obj->data.top.type = TOP_MEM;
1134 } else if (strcmp(buf, "time") == EQUAL) {
1135 obj->data.top.type = TOP_TIME;
1136 } else if (strcmp(buf, "mem_res") == EQUAL) {
1137 obj->data.top.type = TOP_MEM_RES;
1138 } else if (strcmp(buf, "mem_vsize") == EQUAL) {
1139 obj->data.top.type = TOP_MEM_VSIZE;
1141 ERR("invalid type arg for top");
1142 ERR("must be one of: name, cpu, pid, mem, time, mem_res, mem_vsize");
1145 if (n < 1 || n > 10) {
1146 ERR("invalid num arg for top. Must be between 1 and 10.");
1149 obj->data.top.num = n - 1;
1152 ERR("invalid argument count for top");
1158 /* construct_text_object() creates a new text_object */
1159 static struct text_object *construct_text_object(const char *s,
1160 const char *arg, long line, char allow_threaded, void **ifblock_opaque)
1162 // struct text_object *obj = new_text_object();
1163 struct text_object *obj = new_text_object_internal();
1167 #define OBJ(a, n) if (strcmp(s, #a) == 0) { \
1168 obj->type = OBJ_##a; need_mask |= (1ULL << n); {
1169 #define OBJ_IF(a, n) if (strcmp(s, #a) == 0) { \
1170 obj->type = OBJ_##a; need_mask |= (1ULL << n); \
1171 obj_be_ifblock_if(ifblock_opaque, obj); {
1172 #define OBJ_THREAD(a, n) if (strcmp(s, #a) == 0 && allow_threaded) { \
1173 obj->type = OBJ_##a; need_mask |= (1ULL << n); {
1174 #define END } } else
1178 obj->type = OBJ_color;
1179 obj->data.l = get_x11_color(s);
1183 OBJ(freq, INFO_FREQ)
1186 obj->data.i = open_acpi_temperature(arg);
1187 END OBJ(acpiacadapter, 0)
1188 END OBJ(freq, INFO_FREQ)
1189 #endif /* !__OpenBSD__ */
1191 if (!arg || !isdigit(arg[0]) || strlen(arg) >= 2 || atoi(&arg[0]) == 0
1192 || (unsigned int) atoi(&arg[0]) > info.cpu_count) {
1193 obj->data.cpu_index = 1;
1194 /* ERR("freq: Invalid CPU number or you don't have that many CPUs! "
1195 "Displaying the clock for CPU 1."); */
1197 obj->data.cpu_index = atoi(&arg[0]);
1200 END OBJ(freq_g, INFO_FREQ)
1202 if (!arg || !isdigit(arg[0]) || strlen(arg) >= 2 || atoi(&arg[0]) == 0
1203 || (unsigned int) atoi(&arg[0]) > info.cpu_count) {
1204 obj->data.cpu_index = 1;
1205 /* ERR("freq_g: Invalid CPU number or you don't have that many "
1206 "CPUs! Displaying the clock for CPU 1."); */
1208 obj->data.cpu_index = atoi(&arg[0]);
1211 #if defined(__linux__)
1212 END OBJ(voltage_mv, 0)
1214 if (!arg || !isdigit(arg[0]) || strlen(arg) >= 2 || atoi(&arg[0]) == 0
1215 || (unsigned int) atoi(&arg[0]) > info.cpu_count) {
1216 obj->data.cpu_index = 1;
1217 /* ERR("voltage_mv: Invalid CPU number or you don't have that many "
1218 "CPUs! Displaying voltage for CPU 1."); */
1220 obj->data.cpu_index = atoi(&arg[0]);
1223 END OBJ(voltage_v, 0)
1225 if (!arg || !isdigit(arg[0]) || strlen(arg) >= 2 || atoi(&arg[0]) == 0
1226 || (unsigned int) atoi(&arg[0]) > info.cpu_count) {
1227 obj->data.cpu_index = 1;
1228 /* ERR("voltage_v: Invalid CPU number or you don't have that many "
1229 "CPUs! Displaying voltage for CPU 1."); */
1231 obj->data.cpu_index = atoi(&arg[0]);
1236 END OBJ(wireless_essid, INFO_NET)
1238 obj->data.net = get_net_stat(arg);
1240 CRIT_ERR("wireless_essid: needs an argument");
1242 END OBJ(wireless_mode, INFO_NET)
1244 obj->data.net = get_net_stat(arg);
1246 CRIT_ERR("wireless_mode: needs an argument");
1248 END OBJ(wireless_bitrate, INFO_NET)
1250 obj->data.net = get_net_stat(arg);
1252 CRIT_ERR("wireless_bitrate: needs an argument");
1254 END OBJ(wireless_ap, INFO_NET)
1256 obj->data.net = get_net_stat(arg);
1258 CRIT_ERR("wireless_ap: needs an argument");
1260 END OBJ(wireless_link_qual, INFO_NET)
1262 obj->data.net = get_net_stat(arg);
1264 CRIT_ERR("wireless_link_qual: needs an argument");
1266 END OBJ(wireless_link_qual_max, INFO_NET)
1268 obj->data.net = get_net_stat(arg);
1270 CRIT_ERR("wireless_link_qual_max: needs an argument");
1272 END OBJ(wireless_link_qual_perc, INFO_NET)
1274 obj->data.net = get_net_stat(arg);
1276 CRIT_ERR("wireless_link_qual_perc: needs an argument");
1278 END OBJ(wireless_link_bar, INFO_NET)
1280 arg = scan_bar(arg, &obj->a, &obj->b);
1281 obj->data.net = get_net_stat(arg);
1283 CRIT_ERR("wireless_link_bar: needs an argument");
1285 #endif /* HAVE_IWLIB */
1287 #endif /* __linux__ */
1295 sscanf(arg, "%63s", bat);
1297 strcpy(bat, "BAT0");
1299 obj->data.s = strndup(bat, text_buffer_size);
1300 END OBJ(battery_short, 0)
1304 sscanf(arg, "%63s", bat);
1306 strcpy(bat, "BAT0");
1308 obj->data.s = strndup(bat, text_buffer_size);
1309 END OBJ(battery_time, 0)
1313 sscanf(arg, "%63s", bat);
1315 strcpy(bat, "BAT0");
1317 obj->data.s = strndup(bat, text_buffer_size);
1318 END OBJ(battery_percent, 0)
1322 sscanf(arg, "%63s", bat);
1324 strcpy(bat, "BAT0");
1326 obj->data.s = strndup(bat, text_buffer_size);
1328 END OBJ(battery_bar, 0)
1332 arg = scan_bar(arg, &obj->a, &obj->b);
1333 sscanf(arg, "%63s", bat);
1335 strcpy(bat, "BAT0");
1337 obj->data.s = strndup(bat, text_buffer_size);
1339 #endif /* !__OpenBSD__ */
1341 #if defined(__linux__)
1342 END OBJ(disk_protect, 0)
1344 obj->data.s = strndup(dev_name(arg), text_buffer_size);
1346 CRIT_ERR("disk_protect needs an argument");
1347 END OBJ(i8k_version, INFO_I8K)
1348 END OBJ(i8k_bios, INFO_I8K)
1349 END OBJ(i8k_serial, INFO_I8K)
1350 END OBJ(i8k_cpu_temp, INFO_I8K)
1351 END OBJ(i8k_left_fan_status, INFO_I8K)
1352 END OBJ(i8k_right_fan_status, INFO_I8K)
1353 END OBJ(i8k_left_fan_rpm, INFO_I8K)
1354 END OBJ(i8k_right_fan_rpm, INFO_I8K)
1355 END OBJ(i8k_ac_status, INFO_I8K)
1356 END OBJ(i8k_buttons_status, INFO_I8K)
1359 END OBJ(ibm_temps, 0)
1361 CRIT_ERR("ibm_temps: needs an argument");
1363 if (!isdigit(arg[0]) || strlen(arg) >= 2 || atoi(&arg[0]) >= 8) {
1364 obj->data.sensor = 0;
1365 ERR("Invalid temperature sensor! Sensor number must be 0 to 7. "
1366 "Using 0 (CPU temp sensor).");
1368 obj->data.sensor = atoi(&arg[0]);
1369 END OBJ(ibm_volume, 0)
1370 END OBJ(ibm_brightness, 0)
1372 /* information from sony_laptop kernel module
1373 * /sys/devices/platform/sony-laptop */
1374 END OBJ(sony_fanspeed, 0)
1375 END OBJ_IF(if_gw, INFO_GW)
1376 END OBJ(ioscheduler, 0)
1378 CRIT_ERR("get_ioscheduler needs an argument (e.g. hda)");
1381 obj->data.s = strndup(dev_name(arg), text_buffer_size);
1382 END OBJ(laptop_mode, 0)
1383 END OBJ(pb_battery, 0)
1384 if (arg && strcmp(arg, "status") == EQUAL) {
1385 obj->data.i = PB_BATT_STATUS;
1386 } else if (arg && strcmp(arg, "percent") == EQUAL) {
1387 obj->data.i = PB_BATT_PERCENT;
1388 } else if (arg && strcmp(arg, "time") == EQUAL) {
1389 obj->data.i = PB_BATT_TIME;
1391 ERR("pb_battery: needs one argument: status, percent or time");
1396 #endif /* __linux__ */
1397 #if (defined(__FreeBSD__) || defined(__linux__))
1398 END OBJ_IF(if_up, 0)
1400 ERR("if_up needs an argument");
1401 obj->data.ifblock.s = 0;
1403 obj->data.ifblock.s = strndup(arg, text_buffer_size);
1405 #if defined(__OpenBSD__)
1406 END OBJ(obsd_sensors_temp, 0)
1408 CRIT_ERR("obsd_sensors_temp: needs an argument");
1410 if (!isdigit(arg[0]) || atoi(&arg[0]) < 0
1411 || atoi(&arg[0]) > OBSD_MAX_SENSORS - 1) {
1412 obj->data.sensor = 0;
1413 ERR("Invalid temperature sensor number!");
1415 obj->data.sensor = atoi(&arg[0]);
1416 END OBJ(obsd_sensors_fan, 0)
1418 CRIT_ERR("obsd_sensors_fan: needs 2 arguments (device and sensor "
1421 if (!isdigit(arg[0]) || atoi(&arg[0]) < 0
1422 || atoi(&arg[0]) > OBSD_MAX_SENSORS - 1) {
1423 obj->data.sensor = 0;
1424 ERR("Invalid fan sensor number!");
1426 obj->data.sensor = atoi(&arg[0]);
1427 END OBJ(obsd_sensors_volt, 0)
1429 CRIT_ERR("obsd_sensors_volt: needs 2 arguments (device and sensor "
1432 if (!isdigit(arg[0]) || atoi(&arg[0]) < 0
1433 || atoi(&arg[0]) > OBSD_MAX_SENSORS - 1) {
1434 obj->data.sensor = 0;
1435 ERR("Invalid voltage sensor number!");
1437 obj->data.sensor = atoi(&arg[0]);
1438 END OBJ(obsd_vendor, 0)
1439 END OBJ(obsd_product, 0)
1440 #endif /* __OpenBSD__ */
1441 END OBJ(buffers, INFO_BUFFERS)
1442 END OBJ(cached, INFO_BUFFERS)
1443 #define SCAN_CPU(__arg, __var) { \
1445 if (__arg && sscanf(__arg, " cpu%u %n", &__var, &__offset) > 0) \
1446 __arg += __offset; \
1450 END OBJ(cpu, INFO_CPU)
1451 SCAN_CPU(arg, obj->data.cpu_index);
1452 DBGP2("Adding $cpu for CPU %d", obj->data.cpu_index);
1454 END OBJ(cpugauge, INFO_CPU)
1455 SCAN_CPU(arg, obj->data.cpu_index);
1456 scan_gauge(arg, &obj->a, &obj->b);
1457 DBGP2("Adding $cpugauge for CPU %d", obj->data.cpu_index);
1458 END OBJ(cpubar, INFO_CPU)
1459 SCAN_CPU(arg, obj->data.cpu_index);
1460 scan_bar(arg, &obj->a, &obj->b);
1461 DBGP2("Adding $cpubar for CPU %d", obj->data.cpu_index);
1462 END OBJ(cpugraph, INFO_CPU)
1463 SCAN_CPU(arg, obj->data.cpu_index);
1464 scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
1465 &obj->e, &obj->showaslog);
1466 DBGP2("Adding $cpugraph for CPU %d", obj->data.cpu_index);
1467 END OBJ(loadgraph, INFO_LOADAVG)
1468 char *buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
1469 &obj->e, &obj->showaslog);
1473 r = sscanf(arg, "%d", &a);
1475 obj->data.loadavg[0] = (r >= 1) ? (unsigned char) a : 0;
1479 END OBJ(diskio, INFO_DISKIO)
1480 obj->data.diskio = prepare_diskio_stat(dev_name(arg));
1481 END OBJ(diskio_read, INFO_DISKIO)
1482 obj->data.diskio = prepare_diskio_stat(dev_name(arg));
1483 END OBJ(diskio_write, INFO_DISKIO)
1484 obj->data.diskio = prepare_diskio_stat(dev_name(arg));
1486 END OBJ(diskiograph, INFO_DISKIO)
1487 char *buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
1488 &obj->e, &obj->showaslog);
1490 obj->data.diskio = prepare_diskio_stat(dev_name(buf));
1493 END OBJ(diskiograph_read, INFO_DISKIO)
1494 char *buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
1495 &obj->e, &obj->showaslog);
1497 obj->data.diskio = prepare_diskio_stat(dev_name(buf));
1500 END OBJ(diskiograph_write, INFO_DISKIO)
1501 char *buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
1502 &obj->e, &obj->showaslog);
1504 obj->data.diskio = prepare_diskio_stat(dev_name(buf));
1510 if (output_methods & TO_X) {
1511 obj->data.l = arg ? get_x11_color(arg) : default_fg_color;
1515 obj->data.l = color0;
1517 obj->data.l = color1;
1519 obj->data.l = color2;
1521 obj->data.l = color3;
1523 obj->data.l = color4;
1525 obj->data.l = color5;
1527 obj->data.l = color6;
1529 obj->data.l = color7;
1531 obj->data.l = color8;
1533 obj->data.l = color9;
1536 obj->data.s = scan_font(arg);
1538 END OBJ(conky_version, 0)
1539 END OBJ(conky_build_date, 0)
1540 END OBJ(conky_build_arch, 0)
1541 END OBJ(downspeed, INFO_NET)
1543 obj->data.net = get_net_stat(arg);
1545 CRIT_ERR("downspeed needs argument");
1547 END OBJ(downspeedf, INFO_NET)
1549 obj->data.net = get_net_stat(arg);
1551 CRIT_ERR("downspeedf needs argument");
1554 END OBJ(downspeedgraph, INFO_NET)
1555 char *buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
1556 &obj->e, &obj->showaslog);
1558 // default to DEFAULTNETDEV
1559 buf = strndup(buf ? buf : "DEFAULTNETDEV", text_buffer_size);
1560 obj->data.net = get_net_stat(buf);
1564 obj_be_ifblock_else(ifblock_opaque, obj);
1566 obj_be_ifblock_endif(ifblock_opaque, obj);
1568 obj->data.s = strndup(arg ? arg : "", text_buffer_size);
1570 obj->data.s = strndup(arg ? arg : "", text_buffer_size);
1573 obj->data.s = strndup(arg ? arg : "", text_buffer_size);
1575 obj->data.s = strndup(arg ? arg : "", text_buffer_size);
1576 #define SIZE_DEFAULTS(arg) { \
1577 obj->a = default_##arg##_width; \
1578 obj->b = default_##arg##_height; \
1582 obj->data.s = strndup(arg ? arg : "", text_buffer_size);
1584 END OBJ(execgauge, 0)
1585 SIZE_DEFAULTS(gauge);
1586 obj->data.s = strndup(arg ? arg : "", text_buffer_size);
1587 END OBJ(execgraph, 0)
1588 SIZE_DEFAULTS(graph);
1589 obj->data.s = strndup(arg ? arg : "", text_buffer_size);
1590 END OBJ(execibar, 0)
1594 if (!arg || sscanf(arg, "%f %n", &obj->data.execi.interval, &n) <= 0) {
1597 ERR("${execibar <interval> command}");
1598 obj->type = OBJ_text;
1599 snprintf(buf, 256, "${%s}", s);
1600 obj->data.s = strndup(buf, text_buffer_size);
1602 obj->data.execi.cmd = strndup(arg + n, text_buffer_size);
1604 END OBJ(execigraph, 0)
1606 SIZE_DEFAULTS(graph);
1608 if (!arg || sscanf(arg, "%f %n", &obj->data.execi.interval, &n) <= 0) {
1611 ERR("${execigraph <interval> command}");
1612 obj->type = OBJ_text;
1613 snprintf(buf, 256, "${%s}", s);
1614 obj->data.s = strndup(buf, text_buffer_size);
1616 obj->data.execi.cmd = strndup(arg + n, text_buffer_size);
1618 END OBJ(execigauge, 0)
1620 SIZE_DEFAULTS(gauge);
1622 if (!arg || sscanf(arg, "%f %n", &obj->data.execi.interval, &n) <= 0) {
1625 ERR("${execigauge <interval> command}");
1626 obj->type = OBJ_text;
1627 snprintf(buf, 256, "${%s}", s);
1628 obj->data.s = strndup(buf, text_buffer_size);
1630 obj->data.execi.cmd = strndup(arg + n, text_buffer_size);
1636 if (!arg || sscanf(arg, "%f %n", &obj->data.execi.interval, &n) <= 0) {
1639 ERR("${execi <interval> command}");
1640 obj->type = OBJ_text;
1641 snprintf(buf, 256, "${%s}", s);
1642 obj->data.s = strndup(buf, text_buffer_size);
1644 obj->data.execi.cmd = strndup(arg + n, text_buffer_size);
1645 obj->data.execi.buffer = malloc(text_buffer_size);
1650 if (!arg || sscanf(arg, "%f %n", &obj->data.execi.interval, &n) <= 0) {
1653 ERR("${execi <interval> command}");
1654 obj->type = OBJ_text;
1655 snprintf(buf, 256, "${%s}", s);
1656 obj->data.s = strndup(buf, text_buffer_size);
1658 obj->data.execi.cmd = strndup(arg + n, text_buffer_size);
1659 obj->data.execi.buffer = malloc(text_buffer_size);
1661 END OBJ_THREAD(texeci, 0)
1664 if (!arg || sscanf(arg, "%f %n", &obj->data.texeci.interval, &n) <= 0) {
1667 ERR("${texeci <interval> command}");
1668 obj->type = OBJ_text;
1669 snprintf(buf, 256, "${%s}", s);
1670 obj->data.s = strndup(buf, text_buffer_size);
1672 obj->data.texeci.cmd = strndup(arg + n, text_buffer_size);
1673 obj->data.texeci.buffer = malloc(text_buffer_size);
1675 obj->data.texeci.p_timed_thread = NULL;
1676 END OBJ(pre_exec, 0)
1677 obj->type = OBJ_text;
1681 read_exec(arg, buf, sizeof(buf));
1682 obj->data.s = strndup(buf, text_buffer_size);
1684 obj->data.s = strndup("", text_buffer_size);
1688 END OBJ(fs_bar, INFO_FS)
1689 arg = scan_bar(arg, &obj->data.fsbar.w, &obj->data.fsbar.h);
1691 while (isspace(*arg)) {
1700 obj->data.fsbar.fs = prepare_fs_stat(arg);
1701 END OBJ(fs_bar_free, INFO_FS)
1702 arg = scan_bar(arg, &obj->data.fsbar.w, &obj->data.fsbar.h);
1704 while (isspace(*arg)) {
1714 obj->data.fsbar.fs = prepare_fs_stat(arg);
1716 END OBJ(fs_free, INFO_FS)
1720 obj->data.fs = prepare_fs_stat(arg);
1721 END OBJ(fs_used_perc, INFO_FS)
1725 obj->data.fs = prepare_fs_stat(arg);
1726 END OBJ(fs_free_perc, INFO_FS)
1730 obj->data.fs = prepare_fs_stat(arg);
1731 END OBJ(fs_size, INFO_FS)
1735 obj->data.fs = prepare_fs_stat(arg);
1736 END OBJ(fs_type, INFO_FS)
1740 obj->data.fs = prepare_fs_stat(arg);
1741 END OBJ(fs_used, INFO_FS)
1745 obj->data.fs = prepare_fs_stat(arg);
1747 obj->data.i = arg ? atoi(arg) : 1;
1748 END OBJ(nameserver, INFO_DNS)
1749 obj->data.i = arg ? atoi(arg) : 0;
1751 obj->data.i = arg ? atoi(arg) : 1;
1753 obj->data.i = arg ? atoi(arg) : 1;
1757 ERR("goto needs arguments");
1758 obj->type = OBJ_text;
1759 obj->data.s = strndup("${goto}", text_buffer_size);
1763 obj->data.i = atoi(arg);
1769 if (sscanf(arg, "%d %d", &a, &b) != 2) {
1770 sscanf(arg, "%d", &b);
1776 obj->data.pair.a = a;
1777 obj->data.pair.b = b;
1780 END OBJ(i2c, INFO_SYSFS)
1781 char buf1[64], buf2[64];
1785 ERR("i2c needs arguments");
1786 obj->type = OBJ_text;
1787 // obj->data.s = strndup("${i2c}", text_buffer_size);
1791 if (sscanf(arg, "%63s %63s %d", buf1, buf2, &n) != 3) {
1792 /* if scanf couldn't read three values, read type and num and use
1794 sscanf(arg, "%63s %d", buf2, &n);
1795 obj->data.sysfs.fd = open_i2c_sensor(0, buf2, n,
1796 &obj->data.sysfs.arg, obj->data.sysfs.devtype);
1797 strncpy(obj->data.sysfs.type, buf2, 63);
1799 obj->data.sysfs.fd = open_i2c_sensor(buf1, buf2, n,
1800 &obj->data.sysfs.arg, obj->data.sysfs.devtype);
1801 strncpy(obj->data.sysfs.type, buf2, 63);
1804 END OBJ(platform, INFO_SYSFS)
1805 char buf1[64], buf2[64];
1809 ERR("platform needs arguments");
1810 obj->type = OBJ_text;
1814 if (sscanf(arg, "%63s %63s %d", buf1, buf2, &n) != 3) {
1815 /* if scanf couldn't read three values, read type and num and use
1817 sscanf(arg, "%63s %d", buf2, &n);
1818 obj->data.sysfs.fd = open_platform_sensor(0, buf2, n,
1819 &obj->data.sysfs.arg, obj->data.sysfs.devtype);
1820 strncpy(obj->data.sysfs.type, buf2, 63);
1822 obj->data.sysfs.fd = open_platform_sensor(buf1, buf2, n,
1823 &obj->data.sysfs.arg, obj->data.sysfs.devtype);
1824 strncpy(obj->data.sysfs.type, buf2, 63);
1827 END OBJ(hwmon, INFO_SYSFS)
1828 char buf1[64], buf2[64];
1829 float factor, offset;
1833 ERR("hwmon needs argumanets");
1834 obj->type = OBJ_text;
1842 if (sscanf(arg, "%63s %63s %d %f %f", buf1, buf2, &n, &factor, &offset) == 5)
1844 if (!found && (sscanf(arg, "%63s %d %f %f", buf2, &n, &factor, &offset) == 3))
1846 if (!found && (sscanf(arg, "%63s %63s %d", buf1, buf2, &n) == 3))
1848 if (!found && (sscanf(arg, "%63s %d", buf2, &n) == 2))
1852 ERR("hwmon failed to parse arguments");
1853 obj->type = OBJ_text;
1856 DBGP("parsed hwmon args: %s %s %d %f %f\n", buf1, buf2, n, factor, offset);
1857 obj->data.sysfs.fd = open_hwmon_sensor((*buf1) ? buf1 : 0, buf2, n,
1858 &obj->data.sysfs.arg, obj->data.sysfs.devtype);
1859 strncpy(obj->data.sysfs.type, buf2, 63);
1860 obj->data.sysfs.factor = factor;
1861 obj->data.sysfs.offset = offset;
1863 #endif /* !__OpenBSD__ */
1866 /* we have three different types of top (top, top_mem and top_time). To
1867 * avoid having almost-same code three times, we have this special
1869 if (strncmp(s, "top", 3) == EQUAL) {
1870 if (!parse_top_args(s, arg, obj)) {
1873 } else OBJ(addr, INFO_NET)
1875 obj->data.net = get_net_stat(arg);
1877 CRIT_ERR("addr needs argument");
1879 #if defined(__linux__)
1880 END OBJ(addrs, INFO_NET)
1882 obj->data.net = get_net_stat(arg);
1884 CRIT_ERR("addrs needs argument");
1886 #endif /* __linux__ */
1888 if (init_tail_object(obj, arg)) {
1889 obj->type = OBJ_text;
1890 obj->data.s = strndup("${tail}", text_buffer_size);
1893 if (init_head_object(obj, arg)) {
1894 obj->type = OBJ_text;
1895 obj->data.s = strndup("${head}", text_buffer_size);
1899 obj->data.s = strndup(arg, text_buffer_size);
1901 CRIT_ERR("lines needs a argument");
1905 obj->data.s = strndup(arg, text_buffer_size);
1907 CRIT_ERR("words needs a argument");
1909 END OBJ(loadavg, INFO_LOADAVG)
1910 int a = 1, b = 2, c = 3, r = 3;
1913 r = sscanf(arg, "%d %d %d", &a, &b, &c);
1914 if (r >= 3 && (c < 1 || c > 3)) {
1917 if (r >= 2 && (b < 1 || b > 3)) {
1920 if (r >= 1 && (a < 1 || a > 3)) {
1924 obj->data.loadavg[0] = (r >= 1) ? (unsigned char) a : 0;
1925 obj->data.loadavg[1] = (r >= 2) ? (unsigned char) b : 0;
1926 obj->data.loadavg[2] = (r >= 3) ? (unsigned char) c : 0;
1927 END OBJ_IF(if_empty, 0)
1929 ERR("if_empty needs an argument");
1930 obj->data.ifblock.s = 0;
1932 obj->data.ifblock.s = strndup(arg, text_buffer_size);
1933 obj->sub = malloc(sizeof(struct text_object));
1934 extract_variable_text_internal(obj->sub,
1935 obj->data.ifblock.s, 0);
1937 END OBJ_IF(if_match, 0)
1939 ERR("if_match needs arguments");
1940 obj->data.ifblock.s = 0;
1942 obj->data.ifblock.s = strndup(arg, text_buffer_size);
1943 obj->sub = malloc(sizeof(struct text_object));
1944 extract_variable_text_internal(obj->sub,
1945 obj->data.ifblock.s, 0);
1947 END OBJ_IF(if_existing, 0)
1949 ERR("if_existing needs an argument or two");
1950 obj->data.ifblock.s = NULL;
1951 obj->data.ifblock.str = NULL;
1953 char buf1[256], buf2[256];
1954 int r = sscanf(arg, "%255s %255[^\n]", buf1, buf2);
1957 obj->data.ifblock.s = strndup(buf1, text_buffer_size);
1958 obj->data.ifblock.str = NULL;
1960 obj->data.ifblock.s = strndup(buf1, text_buffer_size);
1961 obj->data.ifblock.str = strndup(buf2, text_buffer_size);
1964 DBGP("if_existing: '%s' '%s'", obj->data.ifblock.s, obj->data.ifblock.str);
1965 END OBJ_IF(if_mounted, 0)
1967 ERR("if_mounted needs an argument");
1968 obj->data.ifblock.s = 0;
1970 obj->data.ifblock.s = strndup(arg, text_buffer_size);
1972 END OBJ_IF(if_running, 0)
1976 snprintf(buf, 256, "pidof %s >/dev/null", arg);
1977 obj->data.ifblock.s = strndup(buf, text_buffer_size);
1979 ERR("if_running needs an argument");
1980 obj->data.ifblock.s = 0;
1986 char box[256], dst[256];
1990 /* Kapil: Changed from MAIL_FILE to
1991 current_mail_spool since the latter
1992 is a copy of the former if undefined
1993 but the latter should take precedence
1995 strncpy(box, current_mail_spool, sizeof(box));
1997 if (sscanf(arg, "%s %f", box, &n1) != 2) {
1999 strncpy(box, arg, sizeof(box));
2003 variable_substitute(box, dst, sizeof(dst));
2004 obj->data.local_mail.box = strndup(dst, text_buffer_size);
2005 obj->data.local_mail.interval = n1;
2006 END OBJ(new_mails, 0)
2008 char box[256], dst[256];
2012 strncpy(box, current_mail_spool, sizeof(box));
2014 if (sscanf(arg, "%s %f", box, &n1) != 2) {
2016 strncpy(box, arg, sizeof(box));
2020 variable_substitute(box, dst, sizeof(dst));
2021 obj->data.local_mail.box = strndup(dst, text_buffer_size);
2022 obj->data.local_mail.interval = n1;
2023 END OBJ(seen_mails, 0)
2025 char box[256], dst[256];
2029 strncpy(box, current_mail_spool, sizeof(box));
2031 if (sscanf(arg, "%s %f", box, &n1) != 2) {
2033 strncpy(box, arg, sizeof(box));
2037 variable_substitute(box, dst, sizeof(dst));
2038 obj->data.local_mail.box = strndup(dst, text_buffer_size);
2039 obj->data.local_mail.interval = n1;
2040 END OBJ(unseen_mails, 0)
2042 char box[256], dst[256];
2046 strncpy(box, current_mail_spool, sizeof(box));
2048 if (sscanf(arg, "%s %f", box, &n1) != 2) {
2050 strncpy(box, arg, sizeof(box));
2054 variable_substitute(box, dst, sizeof(dst));
2055 obj->data.local_mail.box = strndup(dst, text_buffer_size);
2056 obj->data.local_mail.interval = n1;
2057 END OBJ(flagged_mails, 0)
2059 char box[256], dst[256];
2063 strncpy(box, current_mail_spool, sizeof(box));
2065 if (sscanf(arg, "%s %f", box, &n1) != 2) {
2067 strncpy(box, arg, sizeof(box));
2071 variable_substitute(box, dst, sizeof(dst));
2072 obj->data.local_mail.box = strndup(dst, text_buffer_size);
2073 obj->data.local_mail.interval = n1;
2074 END OBJ(unflagged_mails, 0)
2076 char box[256], dst[256];
2080 strncpy(box, current_mail_spool, sizeof(box));
2082 if (sscanf(arg, "%s %f", box, &n1) != 2) {
2084 strncpy(box, arg, sizeof(box));
2088 variable_substitute(box, dst, sizeof(dst));
2089 obj->data.local_mail.box = strndup(dst, text_buffer_size);
2090 obj->data.local_mail.interval = n1;
2091 END OBJ(forwarded_mails, 0)
2093 char box[256], dst[256];
2097 strncpy(box, current_mail_spool, sizeof(box));
2099 if (sscanf(arg, "%s %f", box, &n1) != 2) {
2101 strncpy(box, arg, sizeof(box));
2105 variable_substitute(box, dst, sizeof(dst));
2106 obj->data.local_mail.box = strndup(dst, text_buffer_size);
2107 obj->data.local_mail.interval = n1;
2108 END OBJ(unforwarded_mails, 0)
2110 char box[256], dst[256];
2114 strncpy(box, current_mail_spool, sizeof(box));
2116 if (sscanf(arg, "%s %f", box, &n1) != 2) {
2118 strncpy(box, arg, sizeof(box));
2122 variable_substitute(box, dst, sizeof(dst));
2123 obj->data.local_mail.box = strndup(dst, text_buffer_size);
2124 obj->data.local_mail.interval = n1;
2125 END OBJ(replied_mails, 0)
2127 char box[256], dst[256];
2131 strncpy(box, current_mail_spool, sizeof(box));
2133 if (sscanf(arg, "%s %f", box, &n1) != 2) {
2135 strncpy(box, arg, sizeof(box));
2139 variable_substitute(box, dst, sizeof(dst));
2140 obj->data.local_mail.box = strndup(dst, text_buffer_size);
2141 obj->data.local_mail.interval = n1;
2142 END OBJ(unreplied_mails, 0)
2144 char box[256], dst[256];
2148 strncpy(box, current_mail_spool, sizeof(box));
2150 if (sscanf(arg, "%s %f", box, &n1) != 2) {
2152 strncpy(box, arg, sizeof(box));
2156 variable_substitute(box, dst, sizeof(dst));
2157 obj->data.local_mail.box = strndup(dst, text_buffer_size);
2158 obj->data.local_mail.interval = n1;
2159 END OBJ(draft_mails, 0)
2161 char box[256], dst[256];
2165 strncpy(box, current_mail_spool, sizeof(box));
2167 if (sscanf(arg, "%s %f", box, &n1) != 2) {
2169 strncpy(box, arg, sizeof(box));
2173 variable_substitute(box, dst, sizeof(dst));
2174 obj->data.local_mail.box = strndup(dst, text_buffer_size);
2175 obj->data.local_mail.interval = n1;
2176 END OBJ(trashed_mails, 0)
2178 char box[256], dst[256];
2182 strncpy(box, current_mail_spool, sizeof(box));
2184 if (sscanf(arg, "%s %f", box, &n1) != 2) {
2186 strncpy(box, arg, sizeof(box));
2190 variable_substitute(box, dst, sizeof(dst));
2191 obj->data.local_mail.box = strndup(dst, text_buffer_size);
2192 obj->data.local_mail.interval = n1;
2193 END OBJ(mboxscan, 0)
2194 obj->data.mboxscan.args = (char *) malloc(text_buffer_size);
2195 obj->data.mboxscan.output = (char *) malloc(text_buffer_size);
2196 /* if '1' (in mboxscan.c) then there was SIGUSR1, hmm */
2197 obj->data.mboxscan.output[0] = 1;
2198 strncpy(obj->data.mboxscan.args, arg, text_buffer_size);
2199 END OBJ(mem, INFO_MEM)
2200 END OBJ(memeasyfree, INFO_MEM)
2201 END OBJ(memfree, INFO_MEM)
2202 END OBJ(memmax, INFO_MEM)
2203 END OBJ(memperc, INFO_MEM)
2205 END OBJ(memgauge, INFO_MEM)
2206 scan_gauge(arg, &obj->data.pair.a, &obj->data.pair.b);
2207 END OBJ(membar, INFO_MEM)
2208 scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
2209 END OBJ(memgraph, INFO_MEM)
2210 char *buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
2211 &obj->e, &obj->showaslog);
2217 END OBJ(mixer, INFO_MIXER)
2218 obj->data.l = mixer_init(arg);
2219 END OBJ(mixerl, INFO_MIXER)
2220 obj->data.l = mixer_init(arg);
2221 END OBJ(mixerr, INFO_MIXER)
2222 obj->data.l = mixer_init(arg);
2224 END OBJ(mixerbar, INFO_MIXER)
2225 scan_mixer_bar(arg, &obj->data.mixerbar.l, &obj->data.mixerbar.w,
2226 &obj->data.mixerbar.h);
2227 END OBJ(mixerlbar, INFO_MIXER)
2228 scan_mixer_bar(arg, &obj->data.mixerbar.l, &obj->data.mixerbar.w,
2229 &obj->data.mixerbar.h);
2230 END OBJ(mixerrbar, INFO_MIXER)
2231 scan_mixer_bar(arg, &obj->data.mixerbar.l, &obj->data.mixerbar.w,
2232 &obj->data.mixerbar.h);
2234 END OBJ_IF(if_mixer_mute, INFO_MIXER)
2235 obj->data.ifblock.i = mixer_init(arg);
2237 END OBJ(monitor, INFO_X11)
2238 END OBJ(monitor_number, INFO_X11)
2240 END OBJ(nodename, 0)
2241 END OBJ(processes, INFO_PROCS)
2242 END OBJ(running_processes, INFO_RUN_PROCS)
2243 END OBJ(shadecolor, 0)
2245 obj->data.l = arg ? get_x11_color(arg) : default_bg_color;
2247 END OBJ(outlinecolor, 0)
2249 obj->data.l = arg ? get_x11_color(arg) : default_out_color;
2251 END OBJ(stippled_hr, 0)
2253 int a = stippled_borders, b = 1;
2256 if (sscanf(arg, "%d %d", &a, &b) != 2) {
2257 sscanf(arg, "%d", &b);
2263 obj->data.pair.a = a;
2264 obj->data.pair.b = b;
2266 END OBJ(swap, INFO_MEM)
2267 END OBJ(swapmax, INFO_MEM)
2268 END OBJ(swapperc, INFO_MEM)
2270 END OBJ(swapbar, INFO_MEM)
2271 scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
2275 obj->data.s = strndup(arg ? arg : "%F %T", text_buffer_size);
2277 obj->data.s = strndup(arg ? arg : "%F %T", text_buffer_size);
2279 char buf1[256], buf2[256], *fmt, *tz;
2283 int nArgs = sscanf(arg, "%255s %255[^\n]", buf1, buf2);
2293 obj->data.tztime.fmt = strndup(fmt ? fmt : "%F %T", text_buffer_size);
2294 obj->data.tztime.tz = tz ? strndup(tz, text_buffer_size) : NULL;
2296 END OBJ(iconv_start, 0)
2297 if (iconv_converting) {
2298 CRIT_ERR("You must stop your last iconv conversion before "
2299 "starting another");
2302 char iconv_from[CODEPAGE_LENGTH];
2303 char iconv_to[CODEPAGE_LENGTH];
2305 if (sscanf(arg, "%s %s", iconv_from, iconv_to) != 2) {
2306 CRIT_ERR("Invalid arguments for iconv_start");
2310 new_iconv = iconv_open(iconv_to, iconv_from);
2311 if (new_iconv == (iconv_t) (-1)) {
2312 ERR("Can't convert from %s to %s.", iconv_from, iconv_to);
2314 obj->a = register_iconv(&new_iconv);
2315 iconv_converting = 1;
2319 CRIT_ERR("Iconv requires arguments");
2321 END OBJ(iconv_stop, 0)
2322 iconv_converting = 0;
2325 END OBJ(totaldown, INFO_NET)
2327 obj->data.net = get_net_stat(arg);
2329 CRIT_ERR("totaldown needs argument");
2331 END OBJ(totalup, INFO_NET)
2332 obj->data.net = get_net_stat(arg);
2334 obj->data.net = get_net_stat(arg);
2336 CRIT_ERR("totalup needs argument");
2339 END OBJ_IF(if_updatenr, 0)
2340 obj->data.ifblock.i = arg ? atoi(arg) : 0;
2341 if(obj->data.ifblock.i == 0) CRIT_ERR("if_updatenr needs a number above 0 as argument");
2342 updatereset = obj->data.ifblock.i > updatereset ? obj->data.ifblock.i : updatereset;
2344 obj->data.i = arg ? atoi(arg) : 0;
2346 obj->data.i = arg ? atoi(arg) : 0;
2347 END OBJ(upspeed, INFO_NET)
2349 obj->data.net = get_net_stat(arg);
2351 CRIT_ERR("upspeed needs argument");
2353 END OBJ(upspeedf, INFO_NET)
2355 obj->data.net = get_net_stat(arg);
2357 CRIT_ERR("upspeedf needs argument");
2361 END OBJ(upspeedgraph, INFO_NET)
2362 char *buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
2363 &obj->e, &obj->showaslog);
2365 // default to DEFAULTNETDEV
2366 buf = strndup(buf ? buf : "DEFAULTNETDEV", text_buffer_size);
2367 obj->data.net = get_net_stat(buf);
2370 END OBJ(uptime_short, INFO_UPTIME)
2371 END OBJ(uptime, INFO_UPTIME)
2372 END OBJ(user_names, INFO_USERS)
2373 END OBJ(user_times, INFO_USERS)
2374 END OBJ(user_terms, INFO_USERS)
2375 END OBJ(user_number, INFO_USERS)
2376 #if defined(__linux__)
2377 END OBJ(gw_iface, INFO_GW)
2378 END OBJ(gw_ip, INFO_GW)
2379 #endif /* !__linux__ */
2381 END OBJ(adt746xcpu, 0)
2382 END OBJ(adt746xfan, 0)
2383 #endif /* !__OpenBSD__ */
2384 #if (defined(__FreeBSD__) || defined(__FreeBSD_kernel__) \
2385 || defined(__OpenBSD__)) && (defined(i386) || defined(__i386__))
2386 END OBJ(apm_adapter, 0)
2387 END OBJ(apm_battery_life, 0)
2388 END OBJ(apm_battery_time, 0)
2389 #endif /* __FreeBSD__ */
2390 END OBJ_THREAD(imap_unseen, 0)
2393 obj->data.mail = parse_mail_args(IMAP_TYPE, arg);
2394 obj->global_mode = 0;
2396 obj->global_mode = 1;
2398 END OBJ_THREAD(imap_messages, 0)
2401 obj->data.mail = parse_mail_args(IMAP_TYPE, arg);
2402 obj->global_mode = 0;
2404 obj->global_mode = 1;
2406 END OBJ_THREAD(pop3_unseen, 0)
2409 obj->data.mail = parse_mail_args(POP3_TYPE, arg);
2410 obj->global_mode = 0;
2412 obj->global_mode = 1;
2414 END OBJ_THREAD(pop3_used, 0)
2417 obj->data.mail = parse_mail_args(POP3_TYPE, arg);
2418 obj->global_mode = 0;
2420 obj->global_mode = 1;
2425 obj->data.s = strndup(arg, text_buffer_size);
2427 ERR("smapi needs an argument");
2428 END OBJ_IF(if_smapi_bat_installed, 0)
2430 ERR("if_smapi_bat_installed needs an argument");
2431 obj->data.ifblock.s = 0;
2433 obj->data.ifblock.s = strndup(arg, text_buffer_size);
2434 END OBJ(smapi_bat_perc, 0)
2436 obj->data.s = strndup(arg, text_buffer_size);
2438 ERR("smapi_bat_perc needs an argument");
2439 END OBJ(smapi_bat_temp, 0)
2441 obj->data.s = strndup(arg, text_buffer_size);
2443 ERR("smapi_bat_temp needs an argument");
2444 END OBJ(smapi_bat_power, 0)
2446 obj->data.s = strndup(arg, text_buffer_size);
2448 ERR("smapi_bat_power needs an argument");
2449 END OBJ(smapi_bat_bar, 0)
2452 if(sscanf(arg, "%i %n", &obj->data.i, &cnt) <= 0) {
2453 ERR("first argument to smapi_bat_bar must be an integer value");
2457 arg = scan_bar(arg + cnt, &obj->a, &obj->b);
2460 ERR("smapi_bat_bar needs an argument");
2463 #define mpd_set_maxlen(name) \
2466 sscanf(arg, "%d", &i); \
2468 obj->data.i = i + 1; \
2470 ERR(#name ": invalid length argument"); \
2472 END OBJ(mpd_artist, INFO_MPD)
2473 mpd_set_maxlen(mpd_artist);
2475 END OBJ(mpd_title, INFO_MPD)
2476 mpd_set_maxlen(mpd_title);
2478 END OBJ(mpd_random, INFO_MPD) init_mpd();
2479 END OBJ(mpd_repeat, INFO_MPD) init_mpd();
2480 END OBJ(mpd_elapsed, INFO_MPD) init_mpd();
2481 END OBJ(mpd_length, INFO_MPD) init_mpd();
2482 END OBJ(mpd_track, INFO_MPD)
2483 mpd_set_maxlen(mpd_track);
2485 END OBJ(mpd_name, INFO_MPD)
2486 mpd_set_maxlen(mpd_name);
2488 END OBJ(mpd_file, INFO_MPD)
2489 mpd_set_maxlen(mpd_file);
2491 END OBJ(mpd_percent, INFO_MPD) init_mpd();
2492 END OBJ(mpd_album, INFO_MPD)
2493 mpd_set_maxlen(mpd_album);
2495 END OBJ(mpd_vol, INFO_MPD) init_mpd();
2496 END OBJ(mpd_bitrate, INFO_MPD) init_mpd();
2497 END OBJ(mpd_status, INFO_MPD) init_mpd();
2499 END OBJ(mpd_bar, INFO_MPD)
2500 scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
2503 END OBJ(mpd_smart, INFO_MPD)
2504 mpd_set_maxlen(mpd_smart);
2506 END OBJ_IF(if_mpd_playing, INFO_MPD)
2508 #undef mpd_set_maxlen
2511 END OBJ(moc_state, INFO_MOC)
2512 END OBJ(moc_file, INFO_MOC)
2513 END OBJ(moc_title, INFO_MOC)
2514 END OBJ(moc_artist, INFO_MOC)
2515 END OBJ(moc_song, INFO_MOC)
2516 END OBJ(moc_album, INFO_MOC)
2517 END OBJ(moc_totaltime, INFO_MOC)
2518 END OBJ(moc_timeleft, INFO_MOC)
2519 END OBJ(moc_curtime, INFO_MOC)
2520 END OBJ(moc_bitrate, INFO_MOC)
2521 END OBJ(moc_rate, INFO_MOC)
2524 END OBJ(xmms2_artist, INFO_XMMS2)
2525 END OBJ(xmms2_album, INFO_XMMS2)
2526 END OBJ(xmms2_title, INFO_XMMS2)
2527 END OBJ(xmms2_genre, INFO_XMMS2)
2528 END OBJ(xmms2_comment, INFO_XMMS2)
2529 END OBJ(xmms2_url, INFO_XMMS2)
2530 END OBJ(xmms2_tracknr, INFO_XMMS2)
2531 END OBJ(xmms2_bitrate, INFO_XMMS2)
2532 END OBJ(xmms2_date, INFO_XMMS2)
2533 END OBJ(xmms2_id, INFO_XMMS2)
2534 END OBJ(xmms2_duration, INFO_XMMS2)
2535 END OBJ(xmms2_elapsed, INFO_XMMS2)
2536 END OBJ(xmms2_size, INFO_XMMS2)
2537 END OBJ(xmms2_status, INFO_XMMS2)
2538 END OBJ(xmms2_percent, INFO_XMMS2)
2539 END OBJ(xmms2_bar, INFO_XMMS2)
2540 scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
2541 END OBJ(xmms2_smart, INFO_XMMS2)
2542 END OBJ(xmms2_playlist, INFO_XMMS2)
2543 END OBJ(xmms2_timesplayed, INFO_XMMS2)
2544 END OBJ_IF(if_xmms2_connected, INFO_XMMS2)
2547 END OBJ(audacious_status, INFO_AUDACIOUS)
2548 END OBJ(audacious_title, INFO_AUDACIOUS)
2550 sscanf(arg, "%d", &info.audacious.max_title_len);
2551 if (info.audacious.max_title_len > 0) {
2552 info.audacious.max_title_len++;
2554 CRIT_ERR("audacious_title: invalid length argument");
2557 END OBJ(audacious_length, INFO_AUDACIOUS)
2558 END OBJ(audacious_length_seconds, INFO_AUDACIOUS)
2559 END OBJ(audacious_position, INFO_AUDACIOUS)
2560 END OBJ(audacious_position_seconds, INFO_AUDACIOUS)
2561 END OBJ(audacious_bitrate, INFO_AUDACIOUS)
2562 END OBJ(audacious_frequency, INFO_AUDACIOUS)
2563 END OBJ(audacious_channels, INFO_AUDACIOUS)
2564 END OBJ(audacious_filename, INFO_AUDACIOUS)
2565 END OBJ(audacious_playlist_length, INFO_AUDACIOUS)
2566 END OBJ(audacious_playlist_position, INFO_AUDACIOUS)
2567 END OBJ(audacious_main_volume, INFO_AUDACIOUS)
2568 END OBJ(audacious_bar, INFO_AUDACIOUS)
2569 scan_bar(arg, &obj->a, &obj->b);
2572 END OBJ(bmpx_title, INFO_BMPX)
2573 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
2574 END OBJ(bmpx_artist, INFO_BMPX)
2575 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
2576 END OBJ(bmpx_album, INFO_BMPX)
2577 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
2578 END OBJ(bmpx_track, INFO_BMPX)
2579 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
2580 END OBJ(bmpx_uri, INFO_BMPX)
2581 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
2582 END OBJ(bmpx_bitrate, INFO_BMPX)
2583 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
2589 char *userid = (char *) malloc(20 * sizeof(char));
2590 char *apikey = (char *) malloc(64 * sizeof(char));
2591 char *charid = (char *) malloc(20 * sizeof(char));
2593 argc = sscanf(arg, "%20s %64s %20s", userid, apikey, charid);
2594 obj->data.eve.charid = charid;
2595 obj->data.eve.userid = userid;
2596 obj->data.eve.apikey = apikey;
2600 CRIT_ERR("eve needs arguments: <userid> <apikey> <characterid>");
2606 int argc, delay, act_par;
2607 unsigned int nrspaces = 0;
2608 char *uri = (char *) malloc(128 * sizeof(char));
2609 char *action = (char *) malloc(64 * sizeof(char));
2611 argc = sscanf(arg, "%127s %d %63s %d %u", uri, &delay, action,
2612 &act_par, &nrspaces);
2613 obj->data.rss.uri = uri;
2614 obj->data.rss.delay = delay;
2615 obj->data.rss.action = action;
2616 obj->data.rss.act_par = act_par;
2617 obj->data.rss.nrspaces = nrspaces;
2621 CRIT_ERR("rss needs arguments: <uri> <delay in minutes> <action> "
2622 "[act_par] [spaces in front]");
2628 obj->data.s = strndup(arg, text_buffer_size);
2630 CRIT_ERR("lua needs arguments: <function name> [function parameters]");
2632 END OBJ(lua_parse, 0)
2634 obj->data.s = strndup(arg, text_buffer_size);
2636 CRIT_ERR("lua_parse needs arguments: <function name> [function parameters]");
2638 END OBJ(lua_read_parse, 0)
2640 obj->data.s = strndup(arg, text_buffer_size);
2642 CRIT_ERR("lua_read_parse needs arguments: <function name> <string to pass>");
2647 arg = scan_bar(arg, &obj->a, &obj->b);
2649 obj->data.s = strndup(arg, text_buffer_size);
2651 CRIT_ERR("lua_bar needs arguments: <height>,<width> <function name> [function parameters]");
2654 CRIT_ERR("lua_bar needs arguments: <height>,<width> <function name> [function parameters]");
2656 END OBJ(lua_graph, 0)
2658 arg = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
2659 &obj->e, &obj->showaslog);
2661 obj->data.s = strndup(arg, text_buffer_size);
2663 CRIT_ERR("lua_graph needs arguments: <\"normal\"|\"log\"> <height>,<width> <gradient colour 1> <gradient colour 2> <scale> <function name> [function parameters]");
2666 CRIT_ERR("lua_graph needs arguments: <\"normal\"|\"log\"> <height>,<width> <gradient colour 1> <gradient colour 2> <scale> <function name> [function parameters]");
2668 END OBJ(lua_gauge, 0)
2670 arg = scan_gauge(arg, &obj->a, &obj->b);
2672 obj->data.s = strndup(arg, text_buffer_size);
2674 CRIT_ERR("lua_gauge needs arguments: <height>,<width> <function name> [function parameters]");
2677 CRIT_ERR("lua_gauge needs arguments: <height>,<width> <function name> [function parameters]");
2680 #endif /* HAVE_LUA */
2683 if (scan_hddtemp(arg, &obj->data.hddtemp.dev,
2684 &obj->data.hddtemp.addr, &obj->data.hddtemp.port)) {
2685 ERR("hddtemp needs arguments");
2686 obj->type = OBJ_text;
2687 obj->data.s = strndup("${hddtemp}", text_buffer_size);
2688 obj->data.hddtemp.update_time = 0;
2690 obj->data.hddtemp.temp = NULL;
2692 #ifdef TCP_PORT_MONITOR
2693 END OBJ(tcp_portmon, INFO_TCP_PORT_MONITOR)
2694 tcp_portmon_init(arg, &obj->data.tcp_port_monitor);
2696 END OBJ(entropy_avail, INFO_ENTROPY)
2697 END OBJ(entropy_poolsize, INFO_ENTROPY)
2699 END OBJ(entropy_bar, INFO_ENTROPY)
2700 scan_bar(arg, &obj->a, &obj->b);
2705 obj->data.scroll.step = 1;
2706 if (arg && sscanf(arg, "%u %n", &obj->data.scroll.show, &n1) > 0) {
2707 if (sscanf(arg + n1, "%u %n", &obj->data.scroll.step, &n2) > 0)
2709 obj->data.scroll.text = strndup(arg + n1, text_buffer_size);
2710 obj->data.scroll.start = 0;
2711 obj->sub = malloc(sizeof(struct text_object));
2712 extract_variable_text_internal(obj->sub,
2713 obj->data.scroll.text, 0);
2715 CRIT_ERR("scroll needs arguments: <length> [<step>] <text>");
2720 unsigned int indenting = 0; //vars can be used as args for other vars
2723 startvar[0] = endvar[0] = startvar[1] = endvar[1] = -1;
2725 for(i=0; arg[i] != 0 && j < 2; i++) {
2726 if(startvar[j] == -1) {
2730 }else if(endvar[j] == -1) {
2733 }else if(arg[i] == '}') {
2736 if (indenting == 0 && arg[i+1] < 48) { //<48 has 0, $, and the most used chars not used in varnames but not { or }
2742 if(startvar[0] >= 0 && endvar[0] >= 0 && startvar[1] >= 0 && endvar[1] >= 0) {
2743 obj->data.combine.left=malloc(endvar[0]-startvar[0]+1);
2744 obj->data.combine.seperation=malloc(startvar[1]-endvar[0]+1);
2745 obj->data.combine.right=malloc(endvar[1]-startvar[1]+1);
2746 strncpy(obj->data.combine.left, arg+startvar[0], endvar[0]-startvar[0]); obj->data.combine.left[endvar[0]-startvar[0]]=0;
2747 strncpy(obj->data.combine.seperation, arg+endvar[0], startvar[1]-endvar[0]); obj->data.combine.seperation[startvar[1]-endvar[0]]=0;
2748 strncpy(obj->data.combine.right, arg+startvar[1], endvar[1]-startvar[1]); obj->data.combine.right[endvar[1]-startvar[1]]=0;
2749 obj->sub = malloc(sizeof(struct text_object));
2750 extract_variable_text_internal(obj->sub, obj->data.combine.left, 0);
2751 obj->sub->sub = malloc(sizeof(struct text_object));
2752 extract_variable_text_internal(obj->sub->sub, obj->data.combine.right, 0);
2754 CRIT_ERR("combine needs arguments: <text1> <text2>");
2757 CRIT_ERR("combine needs arguments: <text1> <text2>");
2762 CRIT_ERR("nvidia needs an argument\n");
2763 } else if (set_nvidia_type(&obj->data.nvidia, arg)) {
2764 CRIT_ERR("nvidia: invalid argument"
2765 " specified: '%s'\n", arg);
2770 END OBJ(apcupsd, INFO_APCUPSD)
2774 if (sscanf(arg, "%63s %d", host, &port) != 2) {
2775 CRIT_ERR("apcupsd needs arguments: <host> <port>");
2777 info.apcupsd.port = htons(port);
2778 strncpy(info.apcupsd.host, host, sizeof(info.apcupsd.host));
2781 CRIT_ERR("apcupsd needs arguments: <host> <port>");
2783 END OBJ(apcupsd_name, INFO_APCUPSD)
2784 END OBJ(apcupsd_model, INFO_APCUPSD)
2785 END OBJ(apcupsd_upsmode, INFO_APCUPSD)
2786 END OBJ(apcupsd_cable, INFO_APCUPSD)
2787 END OBJ(apcupsd_status, INFO_APCUPSD)
2788 END OBJ(apcupsd_linev, INFO_APCUPSD)
2789 END OBJ(apcupsd_load, INFO_APCUPSD)
2791 END OBJ(apcupsd_loadbar, INFO_APCUPSD)
2792 scan_bar(arg, &obj->a, &obj->b);
2793 END OBJ(apcupsd_loadgraph, INFO_APCUPSD)
2794 char* buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d, &obj->e, &obj->showaslog);
2796 END OBJ(apcupsd_loadgauge, INFO_APCUPSD)
2797 scan_gauge(arg, &obj->a, &obj->b);
2799 END OBJ(apcupsd_charge, INFO_APCUPSD)
2800 END OBJ(apcupsd_timeleft, INFO_APCUPSD)
2801 END OBJ(apcupsd_temp, INFO_APCUPSD)
2802 END OBJ(apcupsd_lastxfer, INFO_APCUPSD)
2803 #endif /* APCUPSD */
2807 ERR("unknown variable %s", s);
2808 obj->type = OBJ_text;
2809 snprintf(buf, 256, "${%s}", s);
2810 obj->data.s = strndup(buf, text_buffer_size);
2817 static struct text_object *create_plain_text(const char *s)
2819 struct text_object *obj;
2821 if (s == NULL || *s == '\0') {
2825 obj = new_text_object_internal();
2827 obj->type = OBJ_text;
2828 obj->data.s = strndup(s, text_buffer_size);
2832 /* backslash_escape - do the actual substitution task for template objects
2834 * The field templates is used for substituting the \N occurences. Set it to
2835 * NULL to leave them as they are.
2837 static char *backslash_escape(const char *src, char **templates, unsigned int template_count)
2841 unsigned int dup_idx = 0, dup_len;
2843 dup_len = strlen(src) + 1;
2844 src_dup = malloc(dup_len * sizeof(char));
2852 if (*(p + 1) == '\\') {
2853 src_dup[dup_idx++] = '\\';
2855 } else if (*(p + 1) == ' ') {
2856 src_dup[dup_idx++] = ' ';
2858 } else if (*(p + 1) == 'n') {
2859 src_dup[dup_idx++] = '\n';
2861 } else if (templates) {
2862 unsigned int tmpl_num;
2864 if ((sscanf(p + 1, "%u%n", &tmpl_num, &digits) <= 0) ||
2865 (tmpl_num > template_count))
2867 dup_len += strlen(templates[tmpl_num - 1]);
2868 src_dup = realloc(src_dup, dup_len * sizeof(char));
2869 sprintf(src_dup + dup_idx, "%s", templates[tmpl_num - 1]);
2870 dup_idx += strlen(templates[tmpl_num - 1]);
2875 src_dup[dup_idx++] = *p;
2880 src_dup[dup_idx] = '\0';
2881 src_dup = realloc(src_dup, (strlen(src_dup) + 1) * sizeof(char));
2885 /* handle_template_object - core logic of the template object
2887 * use config variables like this:
2888 * template1 = "$\1\2"
2889 * template2 = "\1: ${fs_bar 4,100 \2} ${fs_used \2} / ${fs_size \2}"
2891 * and use them like this:
2892 * ${template1 node name}
2893 * ${template2 root /}
2894 * ${template2 cdrom /mnt/cdrom}
2896 static char *handle_template(const char *tmpl, const char *args)
2898 char *args_dup, *p, *p_old;
2899 char **argsp = NULL;
2900 unsigned int argcnt = 0, template_idx, i;
2903 if ((sscanf(tmpl, "template%u", &template_idx) != 1) ||
2907 args_dup = strdup(args);
2910 while (*p && (*p == ' ' && *(p - 1) != '\\'))
2912 if (*(p - 1) == '\\')
2915 while (*p && (*p != ' ' || *(p - 1) == '\\'))
2921 argsp = realloc(argsp, ++argcnt * sizeof(char *));
2922 argsp[argcnt - 1] = p_old;
2924 for (i = 0; i < argcnt; i++) {
2926 tmp = backslash_escape(argsp[i], NULL, 0);
2927 DBGP2("%s: substituted arg '%s' to '%s'", tmpl, argsp[i], tmp);
2931 eval_text = backslash_escape(template[template_idx], argsp, argcnt);
2932 DBGP("substituted %s, output is '%s'", tmpl, eval_text);
2934 for (i = 0; i < argcnt; i++)
2940 static char *find_and_replace_templates(const char *inbuf)
2942 char *outbuf, *indup, *p, *o, *templ, *args, *tmpl_out;
2945 outlen = strlen(inbuf) + 1;
2946 o = outbuf = calloc(outlen, sizeof(char));
2947 memset(outbuf, 0, outlen * sizeof(char));
2949 p = indup = strdup(inbuf);
2951 while (*p && *p != '$')
2957 if (strncmp(p, "$template", 9) && strncmp(p, "${template", 10)) {
2962 if (*(p + 1) == '{') {
2984 tmpl_out = handle_template(templ, args);
2986 outlen += strlen(tmpl_out);
2987 outbuf = realloc(outbuf, outlen * sizeof(char));
2988 strcat (outbuf, tmpl_out);
2990 o = outbuf + strlen(outbuf);
2992 ERR("failed to handle template '%s' with args '%s'", templ, args);
2996 outbuf = realloc(outbuf, (strlen(outbuf) + 1) * sizeof(char));
3001 static int text_contains_templates(const char *text)
3003 if (strcasestr(text, "${template") != NULL)
3005 if (strcasestr(text, "$template") != NULL)
3010 static void strfold(char *start, int count)
3013 for (curplace = start + count; *curplace != 0; curplace++) {
3014 *(curplace - count) = *curplace;
3016 *(curplace - count - 1) = 0;
3019 static size_t remove_comments(char *string)
3021 char *curplace, *curplace2;
3023 for (curplace = string; *curplace != 0; curplace++) {
3024 if (*curplace == '\\' && *(curplace + 1) == '#') {
3025 // strcpy can't be used for overlapping strings
3026 strfold(curplace, 1);
3028 } else if (*curplace == '#') {
3029 // remove everything until we hit a '\n'
3030 curplace2 = curplace;
3031 while (*curplace2) {
3033 if (*curplace2 == '\n' &&
3034 *(curplace2 + 1) != '#') break;
3037 strfold(curplace, curplace2 - curplace);
3038 folded += curplace2 - curplace;
3047 static int extract_variable_text_internal(struct text_object *retval, const char *const_p, char allow_threaded)
3049 struct text_object *obj;
3050 char *p, *s, *orig_p;
3052 void *ifblock_opaque = NULL;
3057 p = strndup(const_p, max_user_text - 1);
3058 while (text_contains_templates(p)) {
3060 tmp = find_and_replace_templates(p);
3066 if (strcmp(p, const_p)) {
3067 DBGP("replaced all templates in text: input is\n'%s'\noutput is\n'%s'", const_p, p);
3069 DBGP("no templates to replace");
3072 memset(retval, 0, sizeof(struct text_object));
3074 line = global_text_lines;
3082 obj = create_plain_text(s);
3084 append_object(retval, obj);
3094 /* variable is either $foo or ${foo} */
3096 unsigned int brl = 1, brr = 0;
3100 while (*p && brl != brr) {
3115 while (*p && (isalnum((int) *p) || *p == '_')) {
3120 /* copy variable to buffer */
3121 len = (p - s > 255) ? 255 : (p - s);
3122 strncpy(buf, s, len);
3130 /* search for variable in environment */
3134 obj = create_plain_text(var);
3136 append_object(retval, obj);
3141 /* if variable wasn't found in environment, use some special */
3146 if (strchr(buf, ' ')) {
3147 arg = strchr(buf, ' ');
3150 while (isspace((int) *arg)) {
3158 /* lowercase variable name */
3161 *tmp_p = tolower(*tmp_p);
3165 obj = construct_text_object(buf, arg,
3166 line, allow_threaded,
3169 append_object(retval, obj);
3173 obj = create_plain_text("$");
3176 append_object(retval, obj);
3179 } else if (*p == '#') {
3185 obj = create_plain_text(s);
3187 append_object(retval, obj);
3190 if (!ifblock_stack_empty(&ifblock_opaque)) {
3191 ERR("one or more $endif's are missing");
3198 static void extract_variable_text(const char *p)
3200 free_text_objects(&global_root_object, 0);
3214 extract_variable_text_internal(&global_root_object, p, 1);
3217 int parse_conky_vars(struct text_object *root, char *txt, char *p, struct information *cur)
3219 extract_variable_text_internal(root, txt, 0);
3220 generate_text_internal(p, max_user_text, *root, cur);
3224 static inline struct mail_s *ensure_mail_thread(struct text_object *obj,
3225 void *thread(void *), const char *text)
3227 if (obj->global_mode && info.mail) {
3228 // this means we use info
3229 if (!info.mail->p_timed_thread) {
3230 info.mail->p_timed_thread =
3231 timed_thread_create(thread,
3232 (void *) info.mail, info.mail->interval * 1000000);
3233 if (!info.mail->p_timed_thread) {
3234 ERR("Error creating %s timed thread", text);
3236 timed_thread_register(info.mail->p_timed_thread,
3237 &info.mail->p_timed_thread);
3238 if (timed_thread_run(info.mail->p_timed_thread)) {
3239 ERR("Error running %s timed thread", text);
3243 } else if (obj->data.mail) {
3244 // this means we use obj
3245 if (!obj->data.mail->p_timed_thread) {
3246 obj->data.mail->p_timed_thread =
3247 timed_thread_create(thread,
3248 (void *) obj->data.mail,
3249 obj->data.mail->interval * 1000000);
3250 if (!obj->data.mail->p_timed_thread) {
3251 ERR("Error creating %s timed thread", text);
3253 timed_thread_register(obj->data.mail->p_timed_thread,
3254 &obj->data.mail->p_timed_thread);
3255 if (timed_thread_run(obj->data.mail->p_timed_thread)) {
3256 ERR("Error running %s timed thread", text);
3259 return obj->data.mail;
3260 } else if (!obj->a) {
3261 // something is wrong, warn once then stop
3262 ERR("There's a problem with your mail settings. "
3263 "Check that the global mail settings are properly defined"
3264 " (line %li).", obj->line);
3270 char *format_time(unsigned long timeval, const int width)
3273 unsigned long nt; // narrow time, for speed on 32-bit
3274 unsigned cc; // centiseconds
3275 unsigned nn; // multi-purpose whatever
3278 cc = nt % 100; // centiseconds past second
3279 nt /= 100; // total seconds
3280 nn = nt % 60; // seconds past the minute
3281 nt /= 60; // total minutes
3282 if (width >= snprintf(buf, sizeof buf, "%lu:%02u.%02u",
3284 return strndup(buf, text_buffer_size);
3286 if (width >= snprintf(buf, sizeof buf, "%lu:%02u", nt, nn)) {
3287 return strndup(buf, text_buffer_size);
3289 nn = nt % 60; // minutes past the hour
3290 nt /= 60; // total hours
3291 if (width >= snprintf(buf, sizeof buf, "%lu,%02u", nt, nn)) {
3292 return strndup(buf, text_buffer_size);
3294 nn = nt; // now also hours
3295 if (width >= snprintf(buf, sizeof buf, "%uh", nn)) {
3296 return strndup(buf, text_buffer_size);
3298 nn /= 24; // now days
3299 if (width >= snprintf(buf, sizeof buf, "%ud", nn)) {
3300 return strndup(buf, text_buffer_size);
3302 nn /= 7; // now weeks
3303 if (width >= snprintf(buf, sizeof buf, "%uw", nn)) {
3304 return strndup(buf, text_buffer_size);
3306 // well shoot, this outta' fit...
3307 return strndup("<inf>", text_buffer_size);
3310 //remove backspaced chars, example: "dog^H^H^Hcat" becomes "cat"
3311 //string has to end with \0 and it's length should fit in a int
3313 void remove_deleted_chars(char *string){
3315 while(string[i] != 0){
3316 if(string[i] == BACKSPACE){
3318 strcpy( &(string[i-1]), &(string[i+1]) );
3320 }else strcpy( &(string[i]), &(string[i+1]) ); //necessary for ^H's at the start of a string
3325 static inline void format_media_player_time(char *buf, const int size,
3328 int days, hours, minutes;
3330 days = seconds / (24 * 60 * 60);
3331 seconds %= (24 * 60 * 60);
3332 hours = seconds / (60 * 60);
3333 seconds %= (60 * 60);
3334 minutes = seconds / 60;
3338 snprintf(buf, size, "%i days %i:%02i:%02i", days,
3339 hours, minutes, seconds);
3340 } else if (hours > 0) {
3341 snprintf(buf, size, "%i:%02i:%02i", hours, minutes,
3344 snprintf(buf, size, "%i:%02i", minutes, seconds);
3348 static inline double get_barnum(char *buf)
3360 if (sscanf(buf, "%lf", &barnum) == 0) {
3361 ERR("reading exec value failed (perhaps it's not the "
3362 "correct format?)");
3365 if (barnum > 100.0 || barnum < 0.0) {
3366 ERR("your exec value is not between 0 and 100, "
3367 "therefore it will be ignored");
3373 static void generate_text_internal(char *p, int p_max_size,
3374 struct text_object root, struct information *cur)
3376 struct text_object *obj;
3378 /* for the OBJ_top* handler */
3379 struct process **needed = 0;
3382 char buff_in[p_max_size];
3384 iconv_converting = 0;
3389 while (obj && p_max_size > 0) {
3390 needed = 0; // reset for top stuff
3392 /* IFBLOCK jumping algorithm
3394 * This is easier as it looks like:
3395 * - each IF checks it's condition
3396 * - on FALSE: call DO_JUMP
3397 * - on TRUE: don't care
3398 * - each ELSE calls DO_JUMP unconditionally
3399 * - each ENDIF is silently being ignored
3402 * DO_JUMP overwrites the "obj" variable of the loop and sets it to the target
3403 * (i.e. the corresponding ELSE or ENDIF). After that, processing for the given
3404 * object can continue, free()ing stuff e.g., then the for-loop does the rest: as
3405 * regularly, "obj" is being updated to point to obj->next, so object parsing
3406 * continues right after the corresponding ELSE or ENDIF. This means that if we
3407 * find an ELSE, it's corresponding IF must not have jumped, so we need to jump
3408 * always. If we encounter an ENDIF, it's corresponding IF or ELSE has not
3409 * jumped, and there is nothing to do.
3413 obj = obj->data.ifblock.next; \
3416 #define OBJ(a) break; case OBJ_##a:
3418 switch (obj->type) {
3420 ERR("not implemented obj type %d", obj->type);
3423 temp_print(p, p_max_size, get_acpi_temperature(obj->data.i), TEMP_CELSIUS);
3425 #endif /* !__OpenBSD__ */
3428 obj->a = get_freq(p, p_max_size, "%.0f", 1,
3429 obj->data.cpu_index);
3435 obj->a = get_freq(p, p_max_size, "%'.2f", 1000,
3436 obj->data.cpu_index);
3438 /* OpenBSD has no such flag (SUSv2) */
3439 obj->a = get_freq(p, p_max_size, "%.2f", 1000,
3440 obj->data.cpu_index);
3444 #if defined(__linux__)
3447 obj->a = get_voltage(p, p_max_size, "%.0f", 1,
3448 obj->data.cpu_index);
3453 obj->a = get_voltage(p, p_max_size, "%'.3f", 1000,
3454 obj->data.cpu_index);
3459 OBJ(wireless_essid) {
3460 snprintf(p, p_max_size, "%s", obj->data.net->essid);
3462 OBJ(wireless_mode) {
3463 snprintf(p, p_max_size, "%s", obj->data.net->mode);
3465 OBJ(wireless_bitrate) {
3466 snprintf(p, p_max_size, "%s", obj->data.net->bitrate);
3469 snprintf(p, p_max_size, "%s", obj->data.net->ap);
3471 OBJ(wireless_link_qual) {
3472 spaced_print(p, p_max_size, "%d", 4,
3473 obj->data.net->link_qual);
3475 OBJ(wireless_link_qual_max) {
3476 spaced_print(p, p_max_size, "%d", 4,
3477 obj->data.net->link_qual_max);
3479 OBJ(wireless_link_qual_perc) {
3480 if (obj->data.net->link_qual_max > 0) {
3481 spaced_print(p, p_max_size, "%.0f", 5,
3482 (double) obj->data.net->link_qual /
3483 obj->data.net->link_qual_max * 100);
3485 spaced_print(p, p_max_size, "unk", 5);
3488 OBJ(wireless_link_bar) {
3489 new_bar(p, obj->a, obj->b, ((double) obj->data.net->link_qual /
3490 obj->data.net->link_qual_max) * 255.0);
3492 #endif /* HAVE_IWLIB */
3494 #endif /* __linux__ */
3498 get_adt746x_cpu(p, p_max_size);
3501 get_adt746x_fan(p, p_max_size);
3504 get_acpi_fan(p, p_max_size);
3506 OBJ(acpiacadapter) {
3507 get_acpi_ac_adapter(p, p_max_size);
3510 get_battery_stuff(p, p_max_size, obj->data.s, BATTERY_STATUS);
3513 get_battery_stuff(p, p_max_size, obj->data.s, BATTERY_TIME);
3515 OBJ(battery_percent) {
3516 percent_print(p, p_max_size, get_battery_perct(obj->data.s));
3520 new_bar(p, obj->a, obj->b, get_battery_perct_bar(obj->data.s));
3523 OBJ(battery_short) {
3524 get_battery_short_status(p, p_max_size, obj->data.s);
3526 #endif /* __OpenBSD__ */
3529 human_readable(cur->buffers * 1024, p, 255);
3532 human_readable(cur->cached * 1024, p, 255);
3535 if (obj->data.cpu_index > info.cpu_count) {
3536 ERR("obj->data.cpu_index %i info.cpu_count %i",
3537 obj->data.cpu_index, info.cpu_count);
3538 CRIT_ERR("attempting to use more CPUs than you have!");
3540 percent_print(p, p_max_size,
3541 round_to_int(cur->cpu_usage[obj->data.cpu_index] * 100.0));
3545 new_gauge(p, obj->a, obj->b,
3546 round_to_int(cur->cpu_usage[obj->data.cpu_index] * 255.0));
3548 new_bar(p, obj->a, obj->b,
3549 round_to_int(cur->cpu_usage[obj->data.cpu_index] * 255.0));
3552 new_graph(p, obj->a, obj->b, obj->c, obj->d,
3553 round_to_int(cur->cpu_usage[obj->data.cpu_index] * 100),
3554 100, 1, obj->showaslog);
3557 new_graph(p, obj->a, obj->b, obj->c, obj->d, cur->loadavg[0],
3558 obj->e, 1, obj->showaslog);
3561 new_fg(p, obj->data.l);
3594 OBJ(conky_version) {
3595 snprintf(p, p_max_size, "%s", VERSION);
3597 OBJ(conky_build_date) {
3598 snprintf(p, p_max_size, "%s", BUILD_DATE);
3600 OBJ(conky_build_arch) {
3601 snprintf(p, p_max_size, "%s", BUILD_ARCH);
3603 #if defined(__linux__)
3605 snprintf(p, p_max_size, "%s",
3606 get_disk_protect_queue(obj->data.s));
3609 snprintf(p, p_max_size, "%s", i8k.version);
3612 snprintf(p, p_max_size, "%s", i8k.bios);
3615 snprintf(p, p_max_size, "%s", i8k.serial);
3620 sscanf(i8k.cpu_temp, "%d", &cpu_temp);
3621 temp_print(p, p_max_size, (double)cpu_temp, TEMP_CELSIUS);
3623 OBJ(i8k_left_fan_status) {
3624 int left_fan_status;
3626 sscanf(i8k.left_fan_status, "%d", &left_fan_status);
3627 if (left_fan_status == 0) {
3628 snprintf(p, p_max_size, "off");
3630 if (left_fan_status == 1) {
3631 snprintf(p, p_max_size, "low");
3633 if (left_fan_status == 2) {
3634 snprintf(p, p_max_size, "high");
3637 OBJ(i8k_right_fan_status) {
3638 int right_fan_status;
3640 sscanf(i8k.right_fan_status, "%d", &right_fan_status);
3641 if (right_fan_status == 0) {
3642 snprintf(p, p_max_size, "off");
3644 if (right_fan_status == 1) {
3645 snprintf(p, p_max_size, "low");
3647 if (right_fan_status == 2) {
3648 snprintf(p, p_max_size, "high");
3651 OBJ(i8k_left_fan_rpm) {
3652 snprintf(p, p_max_size, "%s", i8k.left_fan_rpm);
3654 OBJ(i8k_right_fan_rpm) {
3655 snprintf(p, p_max_size, "%s", i8k.right_fan_rpm);
3657 OBJ(i8k_ac_status) {
3660 sscanf(i8k.ac_status, "%d", &ac_status);
3661 if (ac_status == -1) {
3662 snprintf(p, p_max_size, "disabled (read i8k docs)");
3664 if (ac_status == 0) {
3665 snprintf(p, p_max_size, "off");
3667 if (ac_status == 1) {
3668 snprintf(p, p_max_size, "on");
3671 OBJ(i8k_buttons_status) {
3672 snprintf(p, p_max_size, "%s", i8k.buttons_status);
3676 get_ibm_acpi_fan(p, p_max_size);
3679 get_ibm_acpi_temps();
3680 temp_print(p, p_max_size,
3681 ibm_acpi.temps[obj->data.sensor], TEMP_CELSIUS);
3684 get_ibm_acpi_volume(p, p_max_size);
3686 OBJ(ibm_brightness) {
3687 get_ibm_acpi_brightness(p, p_max_size);
3690 /* information from sony_laptop kernel module
3691 * /sys/devices/platform/sony-laptop */
3692 OBJ(sony_fanspeed) {
3693 get_sony_fanspeed(p, p_max_size);
3696 if (!cur->gw_info.count) {
3701 snprintf(p, p_max_size, "%s", cur->gw_info.iface);
3704 snprintf(p, p_max_size, "%s", cur->gw_info.ip);
3707 snprintf(p, p_max_size, "%d", get_laptop_mode());
3710 get_powerbook_batt_info(p, p_max_size, obj->data.i);
3712 #endif /* __linux__ */
3713 #if (defined(__FreeBSD__) || defined(__linux__))
3715 if ((obj->data.ifblock.s)
3716 && (!interface_up(obj->data.ifblock.s))) {
3722 OBJ(obsd_sensors_temp) {
3723 obsd_sensors.device = sensor_device;
3724 update_obsd_sensors();
3725 temp_print(p, p_max_size,
3726 obsd_sensors.temp[obsd_sensors.device][obj->data.sensor],
3729 OBJ(obsd_sensors_fan) {
3730 obsd_sensors.device = sensor_device;
3731 update_obsd_sensors();
3732 snprintf(p, p_max_size, "%d",
3733 obsd_sensors.fan[obsd_sensors.device][obj->data.sensor]);
3735 OBJ(obsd_sensors_volt) {
3736 obsd_sensors.device = sensor_device;
3737 update_obsd_sensors();
3738 snprintf(p, p_max_size, "%.2f",
3739 obsd_sensors.volt[obsd_sensors.device][obj->data.sensor]);
3742 get_obsd_vendor(p, p_max_size);
3745 get_obsd_product(p, p_max_size);
3747 #endif /* __OpenBSD__ */
3750 new_font(p, obj->data.s);
3753 /* TODO: move this correction from kB to kB/s elsewhere
3754 * (or get rid of it??) */
3756 human_readable((obj->data.diskio->current / update_interval) * 1024LL,
3760 human_readable((obj->data.diskio->current_write / update_interval) * 1024LL,
3764 human_readable((obj->data.diskio->current_read / update_interval) * 1024LL,
3769 new_graph(p, obj->a, obj->b, obj->c, obj->d,
3770 obj->data.diskio->current, obj->e, 1, obj->showaslog);
3772 OBJ(diskiograph_read) {
3773 new_graph(p, obj->a, obj->b, obj->c, obj->d,
3774 obj->data.diskio->current_read, obj->e, 1, obj->showaslog);
3776 OBJ(diskiograph_write) {
3777 new_graph(p, obj->a, obj->b, obj->c, obj->d,
3778 obj->data.diskio->current_write, obj->e, 1, obj->showaslog);
3782 human_readable(obj->data.net->recv_speed, p, 255);
3785 spaced_print(p, p_max_size, "%.1f", 8,
3786 obj->data.net->recv_speed / 1024.0);
3789 OBJ(downspeedgraph) {
3790 new_graph(p, obj->a, obj->b, obj->c, obj->d,
3791 obj->data.net->recv_speed / 1024.0, obj->e, 1, obj->showaslog);
3795 /* Since we see you, you're if has not jumped.
3796 * Do Ninja jump here: without leaving traces.
3797 * This is to prevent us from stale jumped flags.
3799 obj = obj->data.ifblock.next;
3803 /* harmless object, just ignore */
3807 if ((obj->data.net->addr.sa_data[2] & 255) == 0
3808 && (obj->data.net->addr.sa_data[3] & 255) == 0
3809 && (obj->data.net->addr.sa_data[4] & 255) == 0
3810 && (obj->data.net->addr.sa_data[5] & 255) == 0) {
3811 snprintf(p, p_max_size, "No Address");
3813 snprintf(p, p_max_size, "%u.%u.%u.%u",
3814 obj->data.net->addr.sa_data[2] & 255,
3815 obj->data.net->addr.sa_data[3] & 255,
3816 obj->data.net->addr.sa_data[4] & 255,
3817 obj->data.net->addr.sa_data[5] & 255);
3820 #if defined(__linux__)
3822 if(NULL != obj->data.net->addrs && strlen(obj->data.net->addrs) > 2)
3824 obj->data.net->addrs[strlen(obj->data.net->addrs) - 2] = 0; /* remove ", " from end of string */
3825 strcpy(p, obj->data.net->addrs);
3828 strcpy(p, "0.0.0.0");
3830 #endif /* __linux__ */
3831 #if defined(IMLIB2) && defined(X11)
3833 /* doesn't actually draw anything, just queues it omp. the
3834 * image will get drawn after the X event loop */
3835 cimlib_add_image(obj->data.s);
3839 struct information *tmp_info;
3840 struct text_object subroot, subroot2;
3842 tmp_info = malloc(sizeof(struct information));
3843 memcpy(tmp_info, cur, sizeof(struct information));
3844 parse_conky_vars(&subroot, obj->data.s, p, tmp_info);
3845 DBGP("evaluated '%s' to '%s'", obj->data.s, p);
3846 parse_conky_vars(&subroot2, p, p, tmp_info);
3848 free_text_objects(&subroot, 1);
3849 free_text_objects(&subroot2, 1);
3853 read_exec(obj->data.s, p, text_buffer_size);
3854 remove_deleted_chars(p);
3857 struct information *tmp_info;
3858 struct text_object subroot;
3860 read_exec(obj->data.s, p, text_buffer_size);
3862 tmp_info = malloc(sizeof(struct information));
3863 memcpy(tmp_info, cur, sizeof(struct information));
3864 parse_conky_vars(&subroot, p, p, tmp_info);
3866 free_text_objects(&subroot, 1);
3873 read_exec(obj->data.s, p, text_buffer_size);
3874 barnum = get_barnum(p); /*using the same function*/
3876 if (barnum >= 0.0) {
3878 new_gauge(p, obj->a, obj->b, round_to_int(barnum * 255.0));
3886 read_exec(obj->data.s, p, text_buffer_size);
3887 barnum = get_barnum(p);
3889 if (barnum >= 0.0) {
3891 if(output_methods & TO_X) {
3893 new_bar(p, obj->a, obj->b, round_to_int(barnum * 255.0));
3896 if(!obj->a) obj->a = DEFAULT_BAR_WIDTH_NO_X;
3897 barnum = round_to_int( ( barnum * obj->a ) / 100);
3898 for(i=0; i<barnum; i++) {
3901 for(; i < obj->a; i++) {
3912 char showaslog = FALSE;
3915 if(strncasecmp(obj->data.s, LOGGRAPH" ", strlen(LOGGRAPH" ")) == EQUAL) {
3917 read_exec(obj->data.s + strlen(LOGGRAPH" ") * sizeof(char), p, text_buffer_size);
3918 } else if(strncasecmp(obj->data.s, NORMGRAPH" ", strlen(NORMGRAPH" ")) == EQUAL) {
3919 read_exec(obj->data.s + strlen(NORMGRAPH" ") * sizeof(char), p, text_buffer_size);
3921 read_exec(obj->data.s, p, text_buffer_size);
3923 barnum = get_barnum(p);
3925 if (barnum >= 0.0) {
3926 new_graph(p, obj->a, obj->b, obj->c, obj->d, round_to_int(barnum),
3931 if (current_update_time - obj->data.execi.last_update
3932 >= obj->data.execi.interval) {
3935 read_exec(obj->data.execi.cmd, p, text_buffer_size);
3936 barnum = get_barnum(p);
3938 if (barnum >= 0.0) {
3939 obj->f = 255 * barnum / 100.0;
3941 obj->data.execi.last_update = current_update_time;
3943 new_bar(p, obj->a, obj->b, round_to_int(obj->f));
3946 if (current_update_time - obj->data.execi.last_update
3947 >= obj->data.execi.interval) {
3950 read_exec(obj->data.execi.cmd, p, text_buffer_size);
3951 barnum = get_barnum(p);
3953 if (barnum >= 0.0) {
3956 obj->data.execi.last_update = current_update_time;
3958 new_graph(p, obj->a, obj->b, obj->c, obj->d, (int) (obj->f), 100, 1, FALSE);
3961 if (current_update_time - obj->data.execi.last_update
3962 >= obj->data.execi.interval) {
3965 read_exec(obj->data.execi.cmd, p, text_buffer_size);
3966 barnum = get_barnum(p);
3968 if (barnum >= 0.0) {
3969 obj->f = 255 * barnum / 100.0;
3971 obj->data.execi.last_update = current_update_time;
3973 new_gauge(p, obj->a, obj->b, round_to_int(obj->f));
3977 if (current_update_time - obj->data.execi.last_update
3978 >= obj->data.execi.interval
3979 && obj->data.execi.interval != 0) {
3980 read_exec(obj->data.execi.cmd, obj->data.execi.buffer,
3982 obj->data.execi.last_update = current_update_time;
3984 snprintf(p, text_buffer_size, "%s", obj->data.execi.buffer);
3987 struct text_object subroot;
3988 struct information *tmp_info =
3989 malloc(sizeof(struct information));
3990 memcpy(tmp_info, cur, sizeof(struct information));
3992 if (current_update_time - obj->data.execi.last_update
3993 < obj->data.execi.interval
3994 || obj->data.execi.interval == 0) {
3995 parse_conky_vars(&subroot, obj->data.execi.buffer, p, tmp_info);
3997 char *output = obj->data.execi.buffer;
3998 FILE *fp = popen(obj->data.execi.cmd, "r");
3999 int length = fread(output, 1, text_buffer_size, fp);
4003 output[length] = '\0';
4004 if (length > 0 && output[length - 1] == '\n') {
4005 output[length - 1] = '\0';
4008 parse_conky_vars(&subroot, obj->data.execi.buffer, p, tmp_info);
4009 obj->data.execi.last_update = current_update_time;
4011 free_text_objects(&subroot, 1);
4015 if (!obj->data.texeci.p_timed_thread) {
4016 obj->data.texeci.p_timed_thread =
4017 timed_thread_create(&threaded_exec,
4018 (void *) obj, obj->data.texeci.interval * 1000000);
4019 if (!obj->data.texeci.p_timed_thread) {
4020 ERR("Error creating texeci timed thread");
4022 timed_thread_register(obj->data.texeci.p_timed_thread,
4023 &obj->data.texeci.p_timed_thread);
4024 if (timed_thread_run(obj->data.texeci.p_timed_thread)) {
4025 ERR("Error running texeci timed thread");
4028 timed_thread_lock(obj->data.texeci.p_timed_thread);
4029 snprintf(p, text_buffer_size, "%s", obj->data.texeci.buffer);
4030 timed_thread_unlock(obj->data.texeci.p_timed_thread);
4033 #endif /* HAVE_POPEN */
4035 struct mail_s *mail = ensure_mail_thread(obj, imap_thread, "imap");
4037 if (mail && mail->p_timed_thread) {
4038 timed_thread_lock(mail->p_timed_thread);
4039 snprintf(p, p_max_size, "%lu", mail->unseen);
4040 timed_thread_unlock(mail->p_timed_thread);
4043 OBJ(imap_messages) {
4044 struct mail_s *mail = ensure_mail_thread(obj, imap_thread, "imap");
4046 if (mail && mail->p_timed_thread) {
4047 timed_thread_lock(mail->p_timed_thread);
4048 snprintf(p, p_max_size, "%lu", mail->messages);
4049 timed_thread_unlock(mail->p_timed_thread);
4053 struct mail_s *mail = ensure_mail_thread(obj, pop3_thread, "pop3");
4055 if (mail && mail->p_timed_thread) {
4056 timed_thread_lock(mail->p_timed_thread);
4057 snprintf(p, p_max_size, "%lu", mail->unseen);
4058 timed_thread_unlock(mail->p_timed_thread);
4062 struct mail_s *mail = ensure_mail_thread(obj, pop3_thread, "pop3");
4064 if (mail && mail->p_timed_thread) {
4065 timed_thread_lock(mail->p_timed_thread);
4066 snprintf(p, p_max_size, "%.1f",
4067 mail->used / 1024.0 / 1024.0);
4068 timed_thread_unlock(mail->p_timed_thread);
4073 if (obj->data.fs != NULL) {
4074 if (obj->data.fs->size == 0) {
4075 new_bar(p, obj->data.fsbar.w, obj->data.fsbar.h, 255);
4077 new_bar(p, obj->data.fsbar.w, obj->data.fsbar.h,
4078 (int) (255 - obj->data.fsbar.fs->avail * 255 /
4079 obj->data.fs->size));
4085 if (obj->data.fs != NULL) {
4086 human_readable( (obj->data.fs->free ? obj->data.fs->free :
4087 obj->data.fs->avail), p, 255);
4091 if (obj->data.fs != NULL) {
4094 if (obj->data.fs->size) {
4095 val = (obj->data.fs->free ? obj->data.fs->free :
4096 obj->data.fs->avail) * 100 /
4100 percent_print(p, p_max_size, val);
4104 if (obj->data.fs != NULL) {
4105 human_readable(obj->data.fs->size, p, 255);
4109 if (obj->data.fs != NULL)
4110 snprintf(p, p_max_size, "%s", obj->data.fs->type);
4113 if (obj->data.fs != NULL) {
4114 human_readable(obj->data.fs->size - (obj->data.fs->free
4115 ? obj->data.fs->free : obj->data.fs->avail), p, 255);
4120 if (obj->data.fs != NULL) {
4121 if (obj->data.fs->size == 0) {
4122 new_bar(p, obj->data.fsbar.w, obj->data.fsbar.h, 255);
4124 new_bar(p, obj->data.fsbar.w, obj->data.fsbar.h,
4125 (int) (obj->data.fsbar.fs->avail * 255 /
4126 obj->data.fs->size));
4132 if (obj->data.fs != NULL) {
4135 if (obj->data.fs->size) {
4136 val = (obj->data.fs->free ? obj->data.fs->free :
4137 obj->data.fs->avail) * 100 /
4141 percent_print(p, p_max_size, 100 - val);
4145 float *v = info.loadavg;
4147 if (obj->data.loadavg[2]) {
4148 snprintf(p, p_max_size, "%.2f %.2f %.2f",
4149 v[obj->data.loadavg[0] - 1],
4150 v[obj->data.loadavg[1] - 1],
4151 v[obj->data.loadavg[2] - 1]);
4152 } else if (obj->data.loadavg[1]) {
4153 snprintf(p, p_max_size, "%.2f %.2f",
4154 v[obj->data.loadavg[0] - 1],
4155 v[obj->data.loadavg[1] - 1]);
4156 } else if (obj->data.loadavg[0]) {
4157 snprintf(p, p_max_size, "%.2f",
4158 v[obj->data.loadavg[0] - 1]);
4162 new_goto(p, obj->data.i);
4165 new_tab(p, obj->data.pair.a, obj->data.pair.b);
4169 new_hr(p, obj->data.i);
4173 if (cur->nameserver_info.nscount > obj->data.i)
4174 snprintf(p, p_max_size, "%s",
4175 cur->nameserver_info.ns_list[obj->data.i]);
4179 char *skill = eve(obj->data.eve.userid, obj->data.eve.apikey, obj->data.eve.charid);
4180 snprintf(p, p_max_size, "%s", skill);
4185 PRSS *data = get_rss_info(obj->data.rss.uri,
4186 obj->data.rss.delay);
4190 snprintf(p, p_max_size, "prss: Error reading RSS data\n");
4192 if (strcmp(obj->data.rss.action, "feed_title") == EQUAL) {
4194 // remove trailing new line if one exists
4195 if (str[strlen(str) - 1] == '\n') {
4196 str[strlen(str) - 1] = 0;
4198 snprintf(p, p_max_size, "%s", str);
4199 } else if (strcmp(obj->data.rss.action, "item_title") == EQUAL) {
4200 if (obj->data.rss.act_par < data->item_count) {
4201 str = data->items[obj->data.rss.act_par].title;
4202 // remove trailing new line if one exists
4203 if (str[strlen(str) - 1] == '\n') {
4204 str[strlen(str) - 1] = 0;
4206 snprintf(p, p_max_size, "%s", str);
4208 } else if (strcmp(obj->data.rss.action, "item_desc") == EQUAL) {
4209 if (obj->data.rss.act_par < data->item_count) {
4211 data->items[obj->data.rss.act_par].description;
4212 // remove trailing new line if one exists
4213 if (str[strlen(str) - 1] == '\n') {
4214 str[strlen(str) - 1] = 0;
4216 snprintf(p, p_max_size, "%s", str);
4218 } else if (strcmp(obj->data.rss.action, "item_titles") == EQUAL) {
4219 if (data->item_count > 0) {
4222 //'tmpspaces' is a string with spaces too be placed in front of each title
4223 char *tmpspaces = malloc(obj->data.rss.nrspaces + 1);
4224 memset(tmpspaces, ' ', obj->data.rss.nrspaces);
4225 tmpspaces[obj->data.rss.nrspaces]=0;
4229 if (obj->data.rss.act_par > data->item_count) {
4230 show = data->item_count;
4232 show = obj->data.rss.act_par;
4234 for (itmp = 0; itmp < show; itmp++) {
4235 PRSS_Item *item = &data->items[itmp];
4239 // don't add new line before first item
4241 strncat(p, "\n", p_max_size);
4243 /* remove trailing new line if one exists,
4244 * we have our own */
4245 if (str[strlen(str) - 1] == '\n') {
4246 str[strlen(str) - 1] = 0;
4248 strncat(p, tmpspaces, p_max_size);
4249 strncat(p, str, p_max_size);
4260 char *str = llua_getstring(obj->data.s);
4262 snprintf(p, p_max_size, "%s", str);
4267 char *str = llua_getstring(obj->data.s);
4269 struct information *tmp_info;
4270 struct text_object subroot;
4272 tmp_info = malloc(sizeof(struct information));
4273 memcpy(tmp_info, cur, sizeof(struct information));
4274 parse_conky_vars(&subroot, str, p, tmp_info);
4276 free_text_objects(&subroot, 1);
4281 OBJ(lua_read_parse) {
4282 struct information *tmp_info;
4283 struct text_object subroot, subroot2;
4286 sscanf(obj->data.s, "%64s", func);
4287 text = obj->data.s + strlen(func) + 1;
4289 tmp_info = malloc(sizeof(struct information));
4290 memcpy(tmp_info, cur, sizeof(struct information));
4291 parse_conky_vars(&subroot, text, p, tmp_info);
4292 DBGP("evaluated '%s' to '%s'", text, p);
4294 str = llua_getstring_read(func, p);
4296 parse_conky_vars(&subroot2, str, p, tmp_info);
4297 DBGP("evaluated '%s' to '%s'", str, p);
4300 free_text_objects(&subroot2, 1);
4302 free_text_objects(&subroot, 1);
4308 if (llua_getinteger(obj->data.s, &per)) {
4309 new_bar(p, obj->a, obj->b, (per/100.0 * 255));
4314 if (llua_getinteger(obj->data.s, &per)) {
4315 new_graph(p, obj->a, obj->b, obj->c, obj->d,
4316 (per/100.0 * 255), 100, 1, obj->showaslog);
4321 if (llua_getinteger(obj->data.s, &per)) {
4322 new_gauge(p, obj->a, obj->b, (per/100.0 * 255));
4326 #endif /* HAVE_LUA */
4331 if (obj->data.hddtemp.update_time < current_update_time - 30) {
4332 if (obj->data.hddtemp.temp)
4333 free(obj->data.hddtemp.temp);
4334 obj->data.hddtemp.temp = get_hddtemp_info(obj->data.hddtemp.dev,
4335 obj->data.hddtemp.addr, obj->data.hddtemp.port);
4336 obj->data.hddtemp.update_time = current_update_time;
4338 if (!obj->data.hddtemp.temp) {
4339 snprintf(p, p_max_size, "N/A");
4341 val = strtol(obj->data.hddtemp.temp + 1, &endptr, 10);
4342 unit = obj->data.hddtemp.temp[0];
4344 if (*endptr != '\0')
4345 snprintf(p, p_max_size, "N/A");
4346 else if (unit == 'C')
4347 temp_print(p, p_max_size, (double)val, TEMP_CELSIUS);
4348 else if (unit == 'F')
4349 temp_print(p, p_max_size, (double)val, TEMP_FAHRENHEIT);
4351 snprintf(p, p_max_size, "N/A");
4356 new_offset(p, obj->data.i);
4359 new_voffset(p, obj->data.i);
4365 r = get_sysfs_info(&obj->data.sysfs.fd, obj->data.sysfs.arg,
4366 obj->data.sysfs.devtype, obj->data.sysfs.type);
4368 r = r * obj->data.sysfs.factor + obj->data.sysfs.offset;
4370 if (!strncmp(obj->data.sysfs.type, "temp", 4)) {
4371 temp_print(p, p_max_size, r, TEMP_CELSIUS);
4372 } else if (r >= 100.0 || r == 0) {
4373 snprintf(p, p_max_size, "%d", (int) r);
4375 snprintf(p, p_max_size, "%.1f", r);
4381 r = get_sysfs_info(&obj->data.sysfs.fd, obj->data.sysfs.arg,
4382 obj->data.sysfs.devtype, obj->data.sysfs.type);
4384 if (!strncmp(obj->data.sysfs.type, "temp", 4)) {
4385 temp_print(p, p_max_size, r, TEMP_CELSIUS);
4386 } else if (r >= 100.0 || r == 0) {
4387 snprintf(p, p_max_size, "%d", (int) r);
4389 snprintf(p, p_max_size, "%.1f", r);
4395 r = get_sysfs_info(&obj->data.sysfs.fd, obj->data.sysfs.arg,
4396 obj->data.sysfs.devtype, obj->data.sysfs.type);
4398 if (!strncmp(obj->data.sysfs.type, "temp", 4)) {
4399 temp_print(p, p_max_size, r, TEMP_CELSIUS);
4400 } else if (r >= 100.0 || r == 0) {
4401 snprintf(p, p_max_size, "%d", (int) r);
4403 snprintf(p, p_max_size, "%.1f", r);
4406 #endif /* __linux__ */
4408 new_alignr(p, obj->data.i);
4411 new_alignc(p, obj->data.i);
4414 char buf[max_user_text];
4415 struct information *tmp_info =
4416 malloc(sizeof(struct information));
4417 memcpy(tmp_info, cur, sizeof(struct information));
4418 generate_text_internal(buf, max_user_text,
4419 *obj->sub, tmp_info);
4421 if (strlen(buf) != 0) {
4427 char expression[max_user_text];
4429 struct information *tmp_info;
4431 tmp_info = malloc(sizeof(struct information));
4432 memcpy(tmp_info, cur, sizeof(struct information));
4433 generate_text_internal(expression, max_user_text,
4434 *obj->sub, tmp_info);
4435 DBGP("parsed arg into '%s'", expression);
4437 val = compare(expression);
4439 ERR("compare failed for expression '%s'",
4447 if (obj->data.ifblock.str
4448 && !check_contains(obj->data.ifblock.s,
4449 obj->data.ifblock.str)) {
4451 } else if (obj->data.ifblock.s
4452 && access(obj->data.ifblock.s, F_OK)) {
4457 if ((obj->data.ifblock.s)
4458 && (!check_mount(obj->data.ifblock.s))) {
4463 if ((obj->data.ifblock.s) && system(obj->data.ifblock.s)) {
4467 #if defined(__linux__)
4469 snprintf(p, p_max_size, "%s", get_ioscheduler(obj->data.s));
4473 snprintf(p, p_max_size, "%s", cur->uname_s.release);
4476 snprintf(p, p_max_size, "%s", cur->uname_s.machine);
4481 human_readable(cur->mem * 1024, p, 255);
4484 human_readable(cur->memeasyfree * 1024, p, 255);
4487 human_readable(cur->memfree * 1024, p, 255);
4490 human_readable(cur->memmax * 1024, p, 255);
4494 percent_print(p, p_max_size, cur->mem * 100 / cur->memmax);
4498 new_gauge(p, obj->data.pair.a, obj->data.pair.b,
4499 cur->memmax ? (cur->mem * 255) / (cur->memmax) : 0);
4502 new_bar(p, obj->data.pair.a, obj->data.pair.b,
4503 cur->memmax ? (cur->mem * 255) / (cur->memmax) : 0);
4506 new_graph(p, obj->a, obj->b, obj->c, obj->d,
4507 cur->memmax ? (cur->mem * 100.0) / (cur->memmax) : 0.0,
4508 100, 1, obj->showaslog);
4513 percent_print(p, p_max_size, mixer_get_avg(obj->data.l));
4516 percent_print(p, p_max_size, mixer_get_left(obj->data.l));
4519 percent_print(p, p_max_size, mixer_get_right(obj->data.l));
4523 new_bar(p, obj->data.mixerbar.w, obj->data.mixerbar.h,
4524 mixer_to_255(obj->data.mixerbar.l,mixer_get_avg(obj->data.mixerbar.l)));
4527 new_bar(p, obj->data.mixerbar.w, obj->data.mixerbar.h,
4528 mixer_to_255(obj->data.mixerbar.l,mixer_get_left(obj->data.mixerbar.l)));
4531 new_bar(p, obj->data.mixerbar.w, obj->data.mixerbar.h,
4532 mixer_to_255(obj->data.mixerbar.l,mixer_get_right(obj->data.mixerbar.l)));
4535 OBJ(if_mixer_mute) {
4536 if (!mixer_is_mute(obj->data.ifblock.i)) {
4542 snprintf(p, p_max_size, "%d", cur->x11.monitor.current);
4544 OBJ(monitor_number) {
4545 snprintf(p, p_max_size, "%d", cur->x11.monitor.number);
4551 update_mail_count(&obj->data.local_mail);
4552 snprintf(p, p_max_size, "%d", obj->data.local_mail.mail_count);
4555 update_mail_count(&obj->data.local_mail);
4556 snprintf(p, p_max_size, "%d",
4557 obj->data.local_mail.new_mail_count);
4560 update_mail_count(&obj->data.local_mail);
4561 snprintf(p, p_max_size, "%d",
4562 obj->data.local_mail.seen_mail_count);
4565 update_mail_count(&obj->data.local_mail);
4566 snprintf(p, p_max_size, "%d",
4567 obj->data.local_mail.unseen_mail_count);
4569 OBJ(flagged_mails) {
4570 update_mail_count(&obj->data.local_mail);
4571 snprintf(p, p_max_size, "%d",
4572 obj->data.local_mail.flagged_mail_count);
4574 OBJ(unflagged_mails) {
4575 update_mail_count(&obj->data.local_mail);
4576 snprintf(p, p_max_size, "%d",
4577 obj->data.local_mail.unflagged_mail_count);
4579 OBJ(forwarded_mails) {
4580 update_mail_count(&obj->data.local_mail);
4581 snprintf(p, p_max_size, "%d",
4582 obj->data.local_mail.forwarded_mail_count);
4584 OBJ(unforwarded_mails) {
4585 update_mail_count(&obj->data.local_mail);
4586 snprintf(p, p_max_size, "%d",
4587 obj->data.local_mail.unforwarded_mail_count);
4589 OBJ(replied_mails) {
4590 update_mail_count(&obj->data.local_mail);
4591 snprintf(p, p_max_size, "%d",
4592 obj->data.local_mail.replied_mail_count);
4594 OBJ(unreplied_mails) {
4595 update_mail_count(&obj->data.local_mail);
4596 snprintf(p, p_max_size, "%d",
4597 obj->data.local_mail.unreplied_mail_count);
4600 update_mail_count(&obj->data.local_mail);
4601 snprintf(p, p_max_size, "%d",
4602 obj->data.local_mail.draft_mail_count);
4604 OBJ(trashed_mails) {
4605 update_mail_count(&obj->data.local_mail);
4606 snprintf(p, p_max_size, "%d",
4607 obj->data.local_mail.trashed_mail_count);
4610 mbox_scan(obj->data.mboxscan.args, obj->data.mboxscan.output,
4612 snprintf(p, p_max_size, "%s", obj->data.mboxscan.output);
4615 snprintf(p, p_max_size, "%s", cur->uname_s.nodename);
4618 new_outline(p, obj->data.l);
4621 spaced_print(p, p_max_size, "%hu", 4, cur->procs);
4623 OBJ(running_processes) {
4624 spaced_print(p, p_max_size, "%hu", 4, cur->run_procs);
4627 snprintf(p, p_max_size, "%s", obj->data.s);
4631 new_bg(p, obj->data.l);
4634 new_stippled_hr(p, obj->data.pair.a, obj->data.pair.b);
4638 human_readable(cur->swap * 1024, p, 255);
4641 human_readable(cur->swapmax * 1024, p, 255);
4644 if (cur->swapmax == 0) {
4645 strncpy(p, "No swap", p_max_size);
4647 percent_print(p, p_max_size, cur->swap * 100 / cur->swapmax);
4652 new_bar(p, obj->data.pair.a, obj->data.pair.b,
4653 cur->swapmax ? (cur->swap * 255) / (cur->swapmax) : 0);
4657 snprintf(p, p_max_size, "%s", cur->uname_s.sysname);
4660 time_t t = time(NULL);
4661 struct tm *tm = localtime(&t);
4663 setlocale(LC_TIME, "");
4664 strftime(p, p_max_size, obj->data.s, tm);
4667 time_t t = time(NULL);
4668 struct tm *tm = gmtime(&t);
4670 strftime(p, p_max_size, obj->data.s, tm);
4677 if (obj->data.tztime.tz) {
4678 oldTZ = getenv("TZ");
4679 setenv("TZ", obj->data.tztime.tz, 1);
4685 setlocale(LC_TIME, "");
4686 strftime(p, p_max_size, obj->data.tztime.fmt, tm);
4688 setenv("TZ", oldTZ, 1);
4693 // Needless to free oldTZ since getenv gives ptr to static data
4696 human_readable(obj->data.net->recv, p, 255);
4699 human_readable(obj->data.net->trans, p, 255);
4702 snprintf(p, p_max_size, "%d", total_updates);
4705 if(total_updates % updatereset != obj->data.ifblock.i - 1) {
4710 human_readable(obj->data.net->trans_speed, p, 255);
4713 spaced_print(p, p_max_size, "%.1f", 8,
4714 obj->data.net->trans_speed / 1024.0);
4718 new_graph(p, obj->a, obj->b, obj->c, obj->d,
4719 obj->data.net->trans_speed / 1024.0, obj->e, 1, obj->showaslog);
4723 format_seconds_short(p, p_max_size, (int) cur->uptime);
4726 format_seconds(p, p_max_size, (int) cur->uptime);
4729 snprintf(p, p_max_size, "%s", cur->users.names);
4732 snprintf(p, p_max_size, "%s", cur->users.terms);
4735 snprintf(p, p_max_size, "%s", cur->users.times);
4738 snprintf(p, p_max_size, "%d", cur->users.number);
4740 #if (defined(__FreeBSD__) || defined(__FreeBSD_kernel__) \
4741 || defined(__OpenBSD__)) && (defined(i386) || defined(__i386__))
4745 msg = get_apm_adapter();
4746 snprintf(p, p_max_size, "%s", msg);
4749 OBJ(apm_battery_life) {
4752 msg = get_apm_battery_life();
4753 snprintf(p, p_max_size, "%s", msg);
4756 OBJ(apm_battery_time) {
4759 msg = get_apm_battery_time();
4760 snprintf(p, p_max_size, "%s", msg);
4763 #endif /* __FreeBSD__ __OpenBSD__ */
4766 #define mpd_printf(fmt, val) \
4767 snprintf(p, p_max_size, fmt, mpd_get_info()->val)
4768 #define mpd_sprintf(val) { \
4769 if (!obj->data.i || obj->data.i > p_max_size) \
4770 mpd_printf("%s", val); \
4772 snprintf(p, obj->data.i, "%s", mpd_get_info()->val); \
4777 mpd_sprintf(artist);
4781 mpd_printf("%s", random);
4783 mpd_printf("%s", repeat);
4791 mpd_printf("%d", volume);
4793 mpd_printf("%d", bitrate);
4795 mpd_printf("%s", status);
4797 format_media_player_time(p, p_max_size, mpd_get_info()->elapsed);
4800 format_media_player_time(p, p_max_size, mpd_get_info()->length);
4803 percent_print(p, p_max_size, (int)(mpd_get_info()->progress * 100));
4807 new_bar(p, obj->data.pair.a, obj->data.pair.b,
4808 (int) (mpd_get_info()->progress * 255.0f));
4812 struct mpd_s *mpd = mpd_get_info();
4813 int len = obj->data.i;
4814 if (len == 0 || len > p_max_size)
4817 memset(p, 0, p_max_size);
4818 if (mpd->artist && *mpd->artist &&
4819 mpd->title && *mpd->title) {
4820 snprintf(p, len, "%s - %s", mpd->artist,
4822 } else if (mpd->title && *mpd->title) {
4823 snprintf(p, len, "%s", mpd->title);
4824 } else if (mpd->artist && *mpd->artist) {
4825 snprintf(p, len, "%s", mpd->artist);
4826 } else if (mpd->file && *mpd->file) {
4827 snprintf(p, len, "%s", mpd->file);
4832 OBJ(if_mpd_playing) {
4833 if (!mpd_get_info()->is_playing) {
4846 #define MOC_PRINT(t, a) \
4847 snprintf(p, p_max_size, "%s", (moc.t ? moc.t : a))
4849 MOC_PRINT(state, "??");
4852 MOC_PRINT(file, "no file");
4855 MOC_PRINT(title, "no title");
4858 MOC_PRINT(artist, "no artist");
4861 MOC_PRINT(song, "no song");
4864 MOC_PRINT(album, "no album");
4866 OBJ(moc_totaltime) {
4867 MOC_PRINT(totaltime, "0:00");
4870 MOC_PRINT(timeleft, "0:00");
4873 MOC_PRINT(curtime, "0:00");
4876 MOC_PRINT(bitrate, "0Kbps");
4879 MOC_PRINT(rate, "0KHz");
4885 snprintf(p, p_max_size, "%s", cur->xmms2.artist);
4888 snprintf(p, p_max_size, "%s", cur->xmms2.album);
4891 snprintf(p, p_max_size, "%s", cur->xmms2.title);
4894 snprintf(p, p_max_size, "%s", cur->xmms2.genre);
4896 OBJ(xmms2_comment) {
4897 snprintf(p, p_max_size, "%s", cur->xmms2.comment);
4900 snprintf(p, p_max_size, "%s", cur->xmms2.url);
4903 snprintf(p, p_max_size, "%s", cur->xmms2.status);
4906 snprintf(p, p_max_size, "%s", cur->xmms2.date);
4908 OBJ(xmms2_tracknr) {
4909 if (cur->xmms2.tracknr != -1) {
4910 snprintf(p, p_max_size, "%i", cur->xmms2.tracknr);
4913 OBJ(xmms2_bitrate) {
4914 snprintf(p, p_max_size, "%i", cur->xmms2.bitrate);
4917 snprintf(p, p_max_size, "%u", cur->xmms2.id);
4920 snprintf(p, p_max_size, "%2.1f", cur->xmms2.size);
4922 OBJ(xmms2_elapsed) {
4923 snprintf(p, p_max_size, "%02d:%02d", cur->xmms2.elapsed / 60000,
4924 (cur->xmms2.elapsed / 1000) % 60);
4926 OBJ(xmms2_duration) {
4927 snprintf(p, p_max_size, "%02d:%02d",
4928 cur->xmms2.duration / 60000,
4929 (cur->xmms2.duration / 1000) % 60);
4931 OBJ(xmms2_percent) {
4932 snprintf(p, p_max_size, "%2.0f", cur->xmms2.progress * 100);
4935 new_bar(p, obj->data.pair.a, obj->data.pair.b,
4936 (int) (cur->xmms2.progress * 255.0f));
4938 OBJ(xmms2_playlist) {
4939 snprintf(p, p_max_size, "%s", cur->xmms2.playlist);
4941 OBJ(xmms2_timesplayed) {
4942 snprintf(p, p_max_size, "%i", cur->xmms2.timesplayed);
4945 if (strlen(cur->xmms2.title) < 2
4946 && strlen(cur->xmms2.title) < 2) {
4947 snprintf(p, p_max_size, "%s", cur->xmms2.url);
4949 snprintf(p, p_max_size, "%s - %s", cur->xmms2.artist,
4953 OBJ(if_xmms2_connected) {
4954 if (cur->xmms2.conn_state != 1) {
4960 OBJ(audacious_status) {
4961 snprintf(p, p_max_size, "%s",
4962 cur->audacious.items[AUDACIOUS_STATUS]);
4964 OBJ(audacious_title) {
4965 snprintf(p, cur->audacious.max_title_len > 0
4966 ? cur->audacious.max_title_len : p_max_size, "%s",
4967 cur->audacious.items[AUDACIOUS_TITLE]);
4969 OBJ(audacious_length) {
4970 snprintf(p, p_max_size, "%s",
4971 cur->audacious.items[AUDACIOUS_LENGTH]);
4973 OBJ(audacious_length_seconds) {
4974 snprintf(p, p_max_size, "%s",
4975 cur->audacious.items[AUDACIOUS_LENGTH_SECONDS]);
4977 OBJ(audacious_position) {
4978 snprintf(p, p_max_size, "%s",
4979 cur->audacious.items[AUDACIOUS_POSITION]);
4981 OBJ(audacious_position_seconds) {
4982 snprintf(p, p_max_size, "%s",
4983 cur->audacious.items[AUDACIOUS_POSITION_SECONDS]);
4985 OBJ(audacious_bitrate) {
4986 snprintf(p, p_max_size, "%s",
4987 cur->audacious.items[AUDACIOUS_BITRATE]);
4989 OBJ(audacious_frequency) {
4990 snprintf(p, p_max_size, "%s",
4991 cur->audacious.items[AUDACIOUS_FREQUENCY]);
4993 OBJ(audacious_channels) {
4994 snprintf(p, p_max_size, "%s",
4995 cur->audacious.items[AUDACIOUS_CHANNELS]);
4997 OBJ(audacious_filename) {
4998 snprintf(p, p_max_size, "%s",
4999 cur->audacious.items[AUDACIOUS_FILENAME]);
5001 OBJ(audacious_playlist_length) {
5002 snprintf(p, p_max_size, "%s",
5003 cur->audacious.items[AUDACIOUS_PLAYLIST_LENGTH]);
5005 OBJ(audacious_playlist_position) {
5006 snprintf(p, p_max_size, "%s",
5007 cur->audacious.items[AUDACIOUS_PLAYLIST_POSITION]);
5009 OBJ(audacious_main_volume) {
5010 snprintf(p, p_max_size, "%s",
5011 cur->audacious.items[AUDACIOUS_MAIN_VOLUME]);
5013 OBJ(audacious_bar) {
5017 atof(cur->audacious.items[AUDACIOUS_POSITION_SECONDS]) /
5018 atof(cur->audacious.items[AUDACIOUS_LENGTH_SECONDS]);
5019 new_bar(p, obj->a, obj->b, (int) (progress * 255.0f));
5025 snprintf(p, p_max_size, "%s", cur->bmpx.title);
5028 snprintf(p, p_max_size, "%s", cur->bmpx.artist);
5031 snprintf(p, p_max_size, "%s", cur->bmpx.album);
5034 snprintf(p, p_max_size, "%s", cur->bmpx.uri);
5037 snprintf(p, p_max_size, "%i", cur->bmpx.track);
5040 snprintf(p, p_max_size, "%i", cur->bmpx.bitrate);
5043 /* we have three different types of top (top, top_mem
5044 * and top_time). To avoid having almost-same code three
5045 * times, we have this special handler. */
5048 parse_top_args("top", obj->data.top.s, obj);
5049 if (!needed) needed = cur->cpu;
5051 parse_top_args("top_mem", obj->data.top.s, obj);
5052 if (!needed) needed = cur->memu;
5054 parse_top_args("top_time", obj->data.top.s, obj);
5055 if (!needed) needed = cur->time;
5057 if (needed[obj->data.top.num]) {
5060 switch (obj->data.top.type) {
5062 snprintf(p, top_name_width + 1, "%-*s", top_name_width,
5063 needed[obj->data.top.num]->name);
5066 snprintf(p, 7, "%6.2f",
5067 needed[obj->data.top.num]->amount);
5070 snprintf(p, 6, "%5i",
5071 needed[obj->data.top.num]->pid);
5074 snprintf(p, 7, "%6.2f",
5075 needed[obj->data.top.num]->totalmem);
5078 timeval = format_time(
5079 needed[obj->data.top.num]->total_cpu_time, 9);
5080 snprintf(p, 10, "%9s", timeval);
5084 human_readable(needed[obj->data.top.num]->rss,
5088 human_readable(needed[obj->data.top.num]->vsize,
5094 print_tail_object(obj, p, p_max_size);
5096 print_head_object(obj, p, p_max_size);
5098 FILE *fp = fopen(obj->data.s,"r");
5101 /* FIXME: use something more general (see also tail.c, head.c */
5102 #define BUFSZ 0x1000
5107 while(fgets(buf, BUFSZ, fp) != NULL){
5108 for(j = 0; buf[j] != 0; j++) {
5109 if(buf[j] == '\n') {
5114 sprintf(p, "%d", lines);
5117 sprintf(p, "File Unreadable");
5122 FILE *fp = fopen(obj->data.s,"r");
5127 char inword = FALSE;
5130 while(fgets(buf, BUFSZ, fp) != NULL){
5131 for(j = 0; buf[j] != 0; j++) {
5132 if(!isspace(buf[j])) {
5133 if(inword == FALSE) {
5142 sprintf(p, "%d", words);
5145 sprintf(p, "File Unreadable");
5148 #ifdef TCP_PORT_MONITOR
5150 tcp_portmon_action(p, p_max_size,
5151 &obj->data.tcp_port_monitor);
5157 iconv_converting = 1;
5158 iconv_selected = obj->a;
5161 iconv_converting = 0;
5166 OBJ(entropy_avail) {
5167 snprintf(p, p_max_size, "%d", cur->entropy.entropy_avail);
5169 OBJ(entropy_poolsize) {
5170 snprintf(p, p_max_size, "%d", cur->entropy.poolsize);
5174 double entropy_perc;
5176 entropy_perc = (double) cur->entropy.entropy_avail /
5177 (double) cur->entropy.poolsize;
5178 new_bar(p, obj->a, obj->b, (int) (entropy_perc * 255.0f));
5185 s = smapi_get_val(obj->data.s);
5186 snprintf(p, p_max_size, "%s", s);
5190 OBJ(if_smapi_bat_installed) {
5192 if(obj->data.ifblock.s && sscanf(obj->data.ifblock.s, "%i", &idx) == 1) {
5193 if(!smapi_bat_installed(idx)) {
5197 ERR("argument to if_smapi_bat_installed must be an integer");
5199 OBJ(smapi_bat_perc) {
5201 if(obj->data.s && sscanf(obj->data.s, "%i", &idx) == 1) {
5202 val = smapi_bat_installed(idx) ?
5203 smapi_get_bat_int(idx, "remaining_percent") : 0;
5204 percent_print(p, p_max_size, val);
5206 ERR("argument to smapi_bat_perc must be an integer");
5208 OBJ(smapi_bat_temp) {
5210 if(obj->data.s && sscanf(obj->data.s, "%i", &idx) == 1) {
5211 val = smapi_bat_installed(idx) ?
5212 smapi_get_bat_int(idx, "temperature") : 0;
5213 /* temperature is in milli degree celsius */
5214 temp_print(p, p_max_size, val / 1000, TEMP_CELSIUS);
5216 ERR("argument to smapi_bat_temp must be an integer");
5218 OBJ(smapi_bat_power) {
5220 if(obj->data.s && sscanf(obj->data.s, "%i", &idx) == 1) {
5221 val = smapi_bat_installed(idx) ?
5222 smapi_get_bat_int(idx, "power_now") : 0;
5223 /* power_now is in mW, set to W with one digit precision */
5224 snprintf(p, p_max_size, "%.1f", ((double)val / 1000));
5226 ERR("argument to smapi_bat_power must be an integer");
5228 OBJ(smapi_bat_bar) {
5229 if(obj->data.i >= 0 && smapi_bat_installed(obj->data.i))
5230 new_bar(p, obj->a, obj->b, (int)
5231 (255 * smapi_get_bat_int(obj->data.i, "remaining_percent") / 100));
5233 new_bar(p, obj->a, obj->b, 0);
5238 char *tmp, buf[max_user_text];
5239 generate_text_internal(buf, max_user_text,
5242 if (strlen(buf) <= obj->data.scroll.show) {
5243 snprintf(p, p_max_size, "%s", buf);
5246 #define LINESEPARATOR '|'
5247 //place all the lines behind each other with LINESEPARATOR between them
5248 for(j = 0; buf[j] != 0; j++) {
5250 buf[j]=LINESEPARATOR;
5253 //scroll the output obj->data.scroll.start places by copying that many chars from
5254 //the front of the string to tmp, scrolling the rest to the front and placing tmp
5255 //at the back of the string
5256 tmp = calloc(obj->data.scroll.start + 1, sizeof(char));
5257 strncpy(tmp, buf, obj->data.scroll.start); tmp[obj->data.scroll.start] = 0;
5258 for(j = obj->data.scroll.start; buf[j] != 0; j++){
5259 buf[j - obj->data.scroll.start] = buf[j];
5261 strcpy(&buf[j - obj->data.scroll.start], tmp);
5263 //only show the requested number of chars
5264 if(obj->data.scroll.show < j) {
5265 buf[obj->data.scroll.show] = 0;
5267 //next time, scroll a place more or reset scrolling if we are at the end
5268 obj->data.scroll.start += obj->data.scroll.step;
5269 if(obj->data.scroll.start >= j){
5270 obj->data.scroll.start = 0;
5272 snprintf(p, p_max_size, "%s", buf);
5275 char buf[2][max_user_text];
5277 unsigned int longest=0;
5278 unsigned int nextstart;
5279 unsigned int nr_rows[2];
5282 struct llrows* next;
5284 struct llrows *ll_rows[2], *current[2];
5285 struct text_object * objsub = obj->sub;
5288 for(i=0; i<2; i++) {
5291 ll_rows[i] = malloc(sizeof(struct llrows));
5292 current[i] = ll_rows[i];
5293 for(j=0; j<i; j++) objsub = objsub->sub;
5294 generate_text_internal(buf[i], max_user_text, *objsub, cur);
5295 for(j=0; buf[i][j] != 0; j++) {
5296 if(buf[i][j] == '\t') buf[i][j] = ' ';
5297 if(buf[i][j] == '\n') {
5299 current[i]->row = strdup(buf[i]+nextstart);
5300 if(i==0 && strlen(current[i]->row) > longest) longest = strlen(current[i]->row);
5301 current[i]->next = malloc(sizeof(struct llrows));
5302 current[i] = current[i]->next;
5307 current[i]->row = strdup(buf[i]+nextstart);
5308 if(i==0 && strlen(current[i]->row) > longest) longest = strlen(current[i]->row);
5309 current[i]->next = NULL;
5310 current[i] = ll_rows[i];
5312 for(j=0; j < (nr_rows[0] > nr_rows[1] ? nr_rows[0] : nr_rows[1] ); j++) {
5314 strcat(p, current[0]->row);
5315 i=strlen(current[0]->row);
5317 while(i < longest) {
5322 strcat(p, obj->data.combine.seperation);
5323 strcat(p, current[1]->row);
5326 for(i=0; i<2; i++) if(current[i]) current[i]=current[i]->next;
5328 for(i=0; i<2; i++) {
5329 while(ll_rows[i] != NULL) {
5330 current[i]=ll_rows[i];
5331 free(current[i]->row);
5332 ll_rows[i]=current[i]->next;
5339 int value = get_nvidia_value(obj->data.nvidia.type, display);
5341 snprintf(p, p_max_size, "N/A");
5342 else if (obj->data.nvidia.type == NV_TEMP)
5343 temp_print(p, p_max_size, (double)value, TEMP_CELSIUS);
5344 else if (obj->data.nvidia.print_as_float &&
5345 value > 0 && value < 100)
5346 snprintf(p, p_max_size, "%.1f", (float)value);
5348 snprintf(p, p_max_size, "%d", value);
5353 /* This is just a meta-object to set host:port */
5356 snprintf(p, p_max_size, "%s",
5357 cur->apcupsd.items[APCUPSD_NAME]);
5359 OBJ(apcupsd_model) {
5360 snprintf(p, p_max_size, "%s",
5361 cur->apcupsd.items[APCUPSD_MODEL]);
5363 OBJ(apcupsd_upsmode) {
5364 snprintf(p, p_max_size, "%s",
5365 cur->apcupsd.items[APCUPSD_UPSMODE]);
5367 OBJ(apcupsd_cable) {
5368 snprintf(p, p_max_size, "%s",
5369 cur->apcupsd.items[APCUPSD_CABLE]);
5371 OBJ(apcupsd_status) {
5372 snprintf(p, p_max_size, "%s",
5373 cur->apcupsd.items[APCUPSD_STATUS]);
5375 OBJ(apcupsd_linev) {
5376 snprintf(p, p_max_size, "%s",
5377 cur->apcupsd.items[APCUPSD_LINEV]);
5380 snprintf(p, p_max_size, "%s",
5381 cur->apcupsd.items[APCUPSD_LOAD]);
5384 OBJ(apcupsd_loadbar) {
5386 progress = atof(cur->apcupsd.items[APCUPSD_LOAD]) / 100.0 * 255.0;
5387 new_bar(p, obj->a, obj->b, (int)progress);
5389 OBJ(apcupsd_loadgraph) {
5391 progress = atof(cur->apcupsd.items[APCUPSD_LOAD]);
5392 new_graph(p, obj->a, obj->b, obj->c, obj->d,
5393 (int)progress, 100, 1, obj->showaslog);
5395 OBJ(apcupsd_loadgauge) {
5397 progress = atof(cur->apcupsd.items[APCUPSD_LOAD]) / 100.0 * 255.0;
5398 new_gauge(p, obj->a, obj->b,
5402 OBJ(apcupsd_charge) {
5403 snprintf(p, p_max_size, "%s",
5404 cur->apcupsd.items[APCUPSD_CHARGE]);
5406 OBJ(apcupsd_timeleft) {
5407 snprintf(p, p_max_size, "%s",
5408 cur->apcupsd.items[APCUPSD_TIMELEFT]);
5411 snprintf(p, p_max_size, "%s",
5412 cur->apcupsd.items[APCUPSD_TEMP]);
5414 OBJ(apcupsd_lastxfer) {
5415 snprintf(p, p_max_size, "%s",
5416 cur->apcupsd.items[APCUPSD_LASTXFER]);
5418 #endif /* APCUPSD */
5425 unsigned int a = strlen(p);
5428 if (a > 0 && iconv_converting && iconv_selected > 0
5429 && (iconv_cd[iconv_selected - 1] != (iconv_t) (-1))) {
5431 size_t dummy1, dummy2;
5432 char *ptr = buff_in;
5435 dummy1 = dummy2 = a;
5437 strncpy(buff_in, p, p_max_size);
5439 iconv(*iconv_cd[iconv_selected - 1], NULL, NULL, NULL, NULL);
5440 while (dummy1 > 0) {
5441 bytes = iconv(*iconv_cd[iconv_selected - 1], &ptr, &dummy1,
5444 ERR("Iconv codeset conversion failed");
5449 /* It is nessecary when we are converting from multibyte to
5450 * singlebyte codepage */
5453 #endif /* HAVE_ICONV */
5461 double current_update_time, next_update_time, last_update_time;
5463 static void generate_text(void)
5465 struct information *cur = &info;
5472 current_update_time = get_time();
5476 /* add things to the buffer */
5482 generate_text_internal(p, max_user_text, global_root_object, cur);
5484 if (stuff_in_upper_case) {
5487 tmp_p = text_buffer;
5489 *tmp_p = toupper(*tmp_p);
5494 next_update_time += update_interval;
5495 if (next_update_time < get_time()) {
5496 next_update_time = get_time() + update_interval;
5497 } else if (next_update_time > get_time() + update_interval) {
5498 next_update_time = get_time() + update_interval;
5500 last_update_time = current_update_time;
5505 static inline int get_string_width(const char *s)
5508 if (output_methods & TO_X) {
5509 return *s ? calc_text_width(s, strlen(s)) : 0;
5515 static inline int get_string_width_special(char *s)
5523 if ((output_methods & TO_X) == 0) {
5525 return (s) ? strlen(s) : 0;
5533 p = strndup(s, text_buffer_size);
5537 if (*p == SPECIAL_CHAR) {
5538 /* shift everything over by 1 so that the special char
5539 * doesn't mess up the size calculation */
5540 for (i = 0; i < (long)strlen(p); i++) {
5541 *(p + i) = *(p + i + 1);
5543 if (specials[special_index + idx].type == GRAPH
5544 || specials[special_index + idx].type == GAUGE
5545 || specials[special_index + idx].type == BAR) {
5546 width += specials[special_index + idx].width;
5553 if (strlen(final) > 1) {
5554 width += calc_text_width(final, strlen(final));
5562 static void text_size_updater(char *s);
5564 int last_font_height;
5565 static void update_text_area(void)
5569 if ((output_methods & TO_X) == 0)
5571 /* update text size if it isn't fixed */
5576 text_width = minimum_width;
5579 last_font_height = font_height();
5580 for_each_line(text_buffer, text_size_updater);
5582 if (text_height < minimum_height) {
5583 text_height = minimum_height;
5585 if (text_width > maximum_width && maximum_width > 0) {
5586 text_width = maximum_width;
5590 /* get text position on workarea */
5591 switch (text_alignment) {
5598 x = workarea[2] - text_width - gap_x;
5603 x = workarea[2] / 2 - text_width / 2 - gap_x;
5610 y = workarea[3] - text_height - gap_y;
5614 x = workarea[2] - text_width - gap_x;
5615 y = workarea[3] - text_height - gap_y;
5619 x = workarea[2] / 2 - text_width / 2 - gap_x;
5620 y = workarea[3] - text_height - gap_y;
5625 y = workarea[3] / 2 - text_height / 2 - gap_y;
5629 x = workarea[2] - text_width - gap_x;
5630 y = workarea[3] / 2 - text_height / 2 - gap_y;
5634 case NONE: // Let the WM manage the window
5645 if (own_window && !fixed_pos) {
5648 text_start_x = border_margin + 1;
5649 text_start_y = border_margin + 1;
5650 window.x = x - border_margin - 1;
5651 window.y = y - border_margin - 1;
5655 /* If window size doesn't match to workarea's size,
5656 * then window probably includes panels (gnome).
5657 * Blah, doesn't work on KDE. */
5658 if (workarea[2] != window.width || workarea[3] != window.height) {
5670 static int cur_x, cur_y; /* current x and y for drawing */
5672 //draw_mode also without X11 because we only need to print to stdout with FG
5673 static int draw_mode; /* FG, BG or OUTLINE */
5675 static long current_color;
5677 static void text_size_updater(char *s)
5682 if ((output_methods & TO_X) == 0)
5684 /* get string widths and skip specials */
5687 if (*p == SPECIAL_CHAR) {
5689 w += get_string_width(s);
5692 if (specials[special_index].type == BAR
5693 || specials[special_index].type == GAUGE
5694 || specials[special_index].type == GRAPH) {
5695 w += specials[special_index].width;
5696 if (specials[special_index].height > last_font_height) {
5697 last_font_height = specials[special_index].height;
5698 last_font_height += font_height();
5700 } else if (specials[special_index].type == OFFSET) {
5701 if (specials[special_index].arg > 0) {
5702 w += specials[special_index].arg;
5704 } else if (specials[special_index].type == VOFFSET) {
5705 last_font_height += specials[special_index].arg;
5706 } else if (specials[special_index].type == GOTO) {
5707 if (specials[special_index].arg > cur_x) {
5708 w = (int) specials[special_index].arg;
5710 } else if (specials[special_index].type == TAB) {
5711 int start = specials[special_index].arg;
5712 int step = specials[special_index].width;
5714 if (!step || step < 0) {
5717 w += step - (cur_x - text_start_x - start) % step;
5718 } else if (specials[special_index].type == FONT) {
5719 selected_font = specials[special_index].font_added;
5720 if (font_height() > last_font_height) {
5721 last_font_height = font_height();
5730 w += get_string_width(s);
5731 if (w > text_width) {
5734 if (text_width > maximum_width && maximum_width) {
5735 text_width = maximum_width;
5738 text_height += last_font_height;
5739 last_font_height = font_height();
5742 static inline void set_foreground_color(long c)
5744 if ((output_methods & TO_X) == 0)
5747 XSetForeground(display, window.gc, c);
5751 static void draw_string(const char *s)
5753 int i, i2, pos, width_of_s;
5761 width_of_s = get_string_width(s);
5762 if ((output_methods & TO_STDOUT) && draw_mode == FG) {
5764 fflush(stdout); /* output immediately, don't buffer */
5766 if ((output_methods & TO_STDERR) && draw_mode == FG) {
5767 fprintf(stderr, "%s\n", s);
5768 fflush(stderr); /* output immediately, don't buffer */
5770 if ((output_methods & OVERWRITE_FILE) && draw_mode == FG && overwrite_fpointer) {
5771 fprintf(overwrite_fpointer, "%s\n", s);
5773 if ((output_methods & APPEND_FILE) && draw_mode == FG && append_fpointer) {
5774 fprintf(append_fpointer, "%s\n", s);
5776 memset(tmpstring1, 0, text_buffer_size);
5777 memset(tmpstring2, 0, text_buffer_size);
5778 strncpy(tmpstring1, s, text_buffer_size - 1);
5783 if (output_methods & TO_X) {
5784 max = ((text_width - width_of_s) / get_string_width(" "));
5787 /* This code looks for tabs in the text and coverts them to spaces.
5788 * The trick is getting the correct number of spaces, and not going
5789 * over the window's size without forcing the window larger. */
5790 for (i = 0; i < (int) text_buffer_size; i++) {
5791 if (tmpstring1[i] == '\t') {
5793 for (i2 = 0; i2 < (8 - (1 + pos) % 8) && added <= max; i2++) {
5794 /* guard against overrun */
5795 tmpstring2[MIN(pos + i2, (int)text_buffer_size - 1)] = ' ';
5800 /* guard against overrun */
5801 tmpstring2[MIN(pos, (int) text_buffer_size - 1)] = tmpstring1[i];
5806 if (output_methods & TO_X) {
5807 if (text_width == maximum_width) {
5808 /* this means the text is probably pushing the limit,
5809 * so we'll chop it */
5810 while (cur_x + get_string_width(tmpstring2) - text_start_x
5811 > maximum_width && strlen(tmpstring2) > 0) {
5812 tmpstring2[strlen(tmpstring2) - 1] = '\0';
5819 if (output_methods & TO_X) {
5825 c.pixel = current_color;
5826 XQueryColor(display, DefaultColormap(display, screen), &c);
5829 c2.color.red = c.red;
5830 c2.color.green = c.green;
5831 c2.color.blue = c.blue;
5832 c2.color.alpha = fonts[selected_font].font_alpha;
5834 XftDrawStringUtf8(window.xftdraw, &c2, fonts[selected_font].xftfont,
5835 cur_x, cur_y, (const XftChar8 *) s, strlen(s));
5837 XftDrawString8(window.xftdraw, &c2, fonts[selected_font].xftfont,
5838 cur_x, cur_y, (const XftChar8 *) s, strlen(s));
5843 XDrawString(display, window.drawable, window.gc, cur_x, cur_y, s,
5846 cur_x += width_of_s;
5849 memcpy(tmpstring1, s, text_buffer_size);
5852 static void draw_line(char *s)
5861 if ((output_methods & TO_X) == 0) {
5866 cur_x = text_start_x;
5867 cur_y += font_ascent();
5868 font_h = font_height();
5870 /* find specials and draw stuff */
5873 if (*p == SPECIAL_CHAR) {
5876 /* draw string before special */
5883 switch (specials[special_index].type) {
5884 case HORIZONTAL_LINE:
5886 int h = specials[special_index].height;
5887 int mid = font_ascent() / 2;
5889 w = text_start_x + text_width - cur_x;
5891 XSetLineAttributes(display, window.gc, h, LineSolid,
5892 CapButt, JoinMiter);
5893 XDrawLine(display, window.drawable, window.gc, cur_x,
5894 cur_y - mid / 2, cur_x + w, cur_y - mid / 2);
5900 int h = specials[special_index].height;
5901 int tmp_s = specials[special_index].arg;
5902 int mid = font_ascent() / 2;
5903 char ss[2] = { tmp_s, tmp_s };
5905 w = text_start_x + text_width - cur_x - 1;
5906 XSetLineAttributes(display, window.gc, h, LineOnOffDash,
5907 CapButt, JoinMiter);
5908 XSetDashes(display, window.gc, 0, ss, 2);
5909 XDrawLine(display, window.drawable, window.gc, cur_x,
5910 cur_y - mid / 2, cur_x + w, cur_y - mid / 2);
5916 int h, bar_usage, by;
5917 if (cur_x - text_start_x > maximum_width
5918 && maximum_width > 0) {
5921 h = specials[special_index].height;
5922 bar_usage = specials[special_index].arg;
5923 by = cur_y - (font_ascent() / 2) - 1;
5928 w = specials[special_index].width;
5930 w = text_start_x + text_width - cur_x - 1;
5936 XSetLineAttributes(display, window.gc, 1, LineSolid,
5937 CapButt, JoinMiter);
5939 XDrawRectangle(display, window.drawable, window.gc, cur_x,
5941 XFillRectangle(display, window.drawable, window.gc, cur_x,
5942 by, w * bar_usage / 255, h);
5950 case GAUGE: /* new GAUGE */
5953 unsigned long last_colour = current_color;
5954 float angle, px, py;
5957 if (cur_x - text_start_x > maximum_width
5958 && maximum_width > 0) {
5962 h = specials[special_index].height;
5963 by = cur_y - (font_ascent() / 2) - 1;
5968 w = specials[special_index].width;
5970 w = text_start_x + text_width - cur_x - 1;
5976 XSetLineAttributes(display, window.gc, 1, LineSolid,
5977 CapButt, JoinMiter);
5979 XDrawArc(display, window.drawable, window.gc,
5980 cur_x, by, w, h * 2, 0, 180*64);
5983 usage = specials[special_index].arg;
5984 angle = (M_PI)*(float)(usage)/255.;
5985 px = (float)(cur_x+(w/2.))-(float)(w/2.)*cos(angle);
5986 py = (float)(by+(h))-(float)(h)*sin(angle);
5988 XDrawLine(display, window.drawable, window.gc,
5989 cur_x + (w/2.), by+(h), (int)(px), (int)(py));
5997 set_foreground_color(last_colour);
6005 int h, by, i, j = 0;
6006 int gradient_size = 0;
6007 float gradient_factor = 0;
6008 float gradient_update = 0;
6009 unsigned long last_colour = current_color;
6010 unsigned long tmpcolour = current_color;
6011 if (cur_x - text_start_x > maximum_width
6012 && maximum_width > 0) {
6015 h = specials[special_index].height;
6016 by = cur_y - (font_ascent() / 2) - 1;
6021 w = specials[special_index].width;
6023 w = text_start_x + text_width - cur_x - 1;
6028 if (draw_graph_borders) {
6029 XSetLineAttributes(display, window.gc, 1, LineSolid,
6030 CapButt, JoinMiter);
6031 XDrawRectangle(display, window.drawable, window.gc,
6034 XSetLineAttributes(display, window.gc, 1, LineSolid,
6035 CapButt, JoinMiter);
6037 if (specials[special_index].last_colour != 0
6038 || specials[special_index].first_colour != 0) {
6039 tmpcolour = specials[special_index].last_colour;
6041 gradient_max(specials[special_index].last_colour,
6042 specials[special_index].first_colour);
6043 gradient_factor = (float) gradient_size / (w - 2);
6045 for (i = w - 2; i > -1; i--) {
6046 if (specials[special_index].last_colour != 0
6047 || specials[special_index].first_colour != 0) {
6048 XSetForeground(display, window.gc, tmpcolour);
6049 gradient_update += gradient_factor;
6050 while (gradient_update > 0) {
6051 tmpcolour = do_gradient(tmpcolour,
6052 specials[special_index].first_colour);
6056 if ((w - i) / ((float) (w - 2) /
6057 (specials[special_index].graph_width)) > j
6058 && j < MAX_GRAPH_DEPTH - 3) {
6061 /* this is mugfugly, but it works */
6062 XDrawLine(display, window.drawable, window.gc,
6063 cur_x + i + 1, by + h, cur_x + i + 1,
6064 by + h - specials[special_index].graph[j] *
6065 (h - 1) / specials[special_index].graph_scale);
6071 /* if (draw_mode == BG) {
6072 set_foreground_color(default_bg_color);
6073 } else if (draw_mode == OUTLINE) {
6074 set_foreground_color(default_out_color);
6076 set_foreground_color(default_fg_color);
6078 if (show_graph_range) {
6081 unsigned short int seconds = update_interval * w;
6086 unsigned short int timeunits;
6088 timeunits = seconds / 86400; seconds %= 86400;
6089 if (timeunits > 0) {
6090 asprintf(&tmp_day_str, "%dd", timeunits);
6092 tmp_day_str = strdup("");
6094 timeunits = seconds / 3600; seconds %= 3600;
6095 if (timeunits > 0) {
6096 asprintf(&tmp_hour_str, "%dh", timeunits);
6098 tmp_hour_str = strdup("");
6100 timeunits = seconds / 60; seconds %= 60;
6101 if (timeunits > 0) {
6102 asprintf(&tmp_min_str, "%dm", timeunits);
6104 tmp_min_str = strdup("");
6107 asprintf(&tmp_sec_str, "%ds", seconds);
6109 tmp_sec_str = strdup("");
6111 asprintf(&tmp_str, "%s%s%s%s", tmp_day_str, tmp_hour_str, tmp_min_str, tmp_sec_str);
6112 free(tmp_day_str); free(tmp_hour_str); free(tmp_min_str); free(tmp_sec_str);
6114 asprintf(&tmp_str, "Range not possible"); // should never happen, but better safe then sorry
6116 cur_x += (w / 2) - (font_ascent() * (strlen(tmp_str) / 2));
6117 cur_y += font_h / 2;
6118 draw_string(tmp_str);
6124 if (show_graph_scale && (specials[special_index].show_scale == 1)) {
6127 cur_x += font_ascent() / 2;
6128 cur_y += font_h / 2;
6130 calloc(log10(floor(specials[special_index].graph_scale)) + 4,
6132 sprintf(tmp_str, "%.1f", specials[special_index].graph_scale);
6133 draw_string(tmp_str);
6139 set_foreground_color(last_colour);
6145 int old = font_ascent();
6147 cur_y -= font_ascent();
6148 selected_font = specials[special_index].font_added;
6149 if (cur_y + font_ascent() < cur_y + old) {
6152 cur_y += font_ascent();
6155 font_h = font_height();
6159 if (draw_mode == FG) {
6160 set_foreground_color(specials[special_index].arg);
6165 if (draw_mode == BG) {
6166 set_foreground_color(specials[special_index].arg);
6171 if (draw_mode == OUTLINE) {
6172 set_foreground_color(specials[special_index].arg);
6177 w += specials[special_index].arg;
6181 cur_y += specials[special_index].arg;
6185 if (specials[special_index].arg >= 0) {
6186 cur_x = (int) specials[special_index].arg;
6192 int start = specials[special_index].arg;
6193 int step = specials[special_index].width;
6195 if (!step || step < 0) {
6198 w = step - (cur_x - text_start_x - start) % step;
6204 /* TODO: add back in "+ border_margin" to the end of
6206 int pos_x = text_start_x + text_width -
6207 get_string_width_special(s);
6209 /* printf("pos_x %i text_start_x %i text_width %i cur_x %i "
6210 "get_string_width(p) %i gap_x %i "
6211 "specials[special_index].arg %i border_margin %i "
6212 "border_width %i\n", pos_x, text_start_x, text_width,
6213 cur_x, get_string_width_special(s), gap_x,
6214 specials[special_index].arg, border_margin,
6216 if (pos_x > specials[special_index].arg && pos_x > cur_x) {
6217 cur_x = pos_x - specials[special_index].arg;
6224 int pos_x = (text_width) / 2 - get_string_width_special(s) /
6225 2 - (cur_x - text_start_x);
6226 /* int pos_x = text_start_x + text_width / 2 -
6227 get_string_width_special(s) / 2; */
6229 /* printf("pos_x %i text_start_x %i text_width %i cur_x %i "
6230 "get_string_width(p) %i gap_x %i "
6231 "specials[special_index].arg %i\n", pos_x, text_start_x,
6232 text_width, cur_x, get_string_width(s), gap_x,
6233 specials[special_index].arg); */
6234 if (pos_x > specials[special_index].arg) {
6235 w = pos_x - specials[special_index].arg;
6249 if (cur_y_add > 0) {
6253 cur_y += font_descent();
6258 static void draw_text(void)
6261 if (output_methods & TO_X) {
6262 cur_y = text_start_y;
6265 if (draw_borders && border_width > 0) {
6266 unsigned int b = (border_width + 1) / 2;
6268 if (stippled_borders) {
6269 char ss[2] = { stippled_borders, stippled_borders };
6270 XSetLineAttributes(display, window.gc, border_width, LineOnOffDash,
6271 CapButt, JoinMiter);
6272 XSetDashes(display, window.gc, 0, ss, 2);
6274 XSetLineAttributes(display, window.gc, border_width, LineSolid,
6275 CapButt, JoinMiter);
6278 XDrawRectangle(display, window.drawable, window.gc,
6279 text_start_x - border_margin + b, text_start_y - border_margin + b,
6280 text_width + border_margin * 2 - 1 - b * 2,
6281 text_height + border_margin * 2 - 1 - b * 2);
6288 for_each_line(text_buffer, draw_line);
6291 static void draw_stuff(void)
6293 if(overwrite_file) {
6294 overwrite_fpointer = fopen(overwrite_file, "w");
6295 if(!overwrite_fpointer)
6296 ERR("Can't overwrite '%s' anymore", overwrite_file);
6299 append_fpointer = fopen(append_file, "a");
6300 if(!append_fpointer)
6301 ERR("Can't append '%s' anymore", append_file);
6304 if (output_methods & TO_X) {
6306 if (draw_shades && !draw_outline) {
6309 set_foreground_color(default_bg_color);
6320 for (i = -1; i < 2; i++) {
6321 for (j = -1; j < 2; j++) {
6322 if (i == 0 && j == 0) {
6327 set_foreground_color(default_out_color);
6328 draw_mode = OUTLINE;
6336 set_foreground_color(default_fg_color);
6342 if (output_methods & TO_X) {
6347 swap.swap_window = window.window;
6348 swap.swap_action = XdbeBackground;
6349 XdbeSwapBuffers(display, &swap, 1);
6354 if(overwrite_fpointer) {
6355 fclose(overwrite_fpointer);
6356 overwrite_fpointer = 0;
6358 if(append_fpointer) {
6359 fclose(append_fpointer);
6360 append_fpointer = 0;
6365 static void clear_text(int exposures)
6369 /* The swap action is XdbeBackground, which clears */
6374 /* there is some extra space for borders and outlines */
6375 XClearArea(display, window.window, text_start_x - border_margin - 1,
6376 text_start_y - border_margin - 1,
6377 text_width + border_margin * 2 + 2,
6378 text_height + border_margin * 2 + 2, exposures ? True : 0);
6383 static int need_to_update;
6385 /* update_text() generates new text and clears old text area */
6386 static void update_text(void)
6393 if (output_methods & TO_X)
6399 #ifdef HAVE_SYS_INOTIFY_H
6403 static void main_loop(void)
6405 #ifdef SIGNAL_BLOCKING
6406 sigset_t newmask, oldmask;
6409 #ifdef HAVE_SYS_INOTIFY_H
6410 int inotify_config_wd = 0;
6411 #define INOTIFY_EVENT_SIZE (sizeof(struct inotify_event))
6412 #define INOTIFY_BUF_LEN (20 * (INOTIFY_EVENT_SIZE + 16))
6413 char inotify_buff[INOTIFY_BUF_LEN];
6414 #endif /* HAVE_SYS_INOTIFY_H */
6417 #ifdef SIGNAL_BLOCKING
6418 sigemptyset(&newmask);
6419 sigaddset(&newmask, SIGINT);
6420 sigaddset(&newmask, SIGTERM);
6421 sigaddset(&newmask, SIGUSR1);
6424 next_update_time = last_update_time = get_time();
6426 while (total_run_times == 0 || info.looped < total_run_times) {
6429 #ifdef SIGNAL_BLOCKING
6430 /* block signals. we will inspect for pending signals later */
6431 if (sigprocmask(SIG_BLOCK, &newmask, &oldmask) < 0) {
6432 CRIT_ERR("unable to sigprocmask()");
6437 if (output_methods & TO_X) {
6440 /* wait for X event or timeout */
6442 if (!XPending(display)) {
6446 t = next_update_time - get_time();
6450 } else if (t > update_interval) {
6451 t = update_interval;
6454 tv.tv_sec = (long) t;
6455 tv.tv_usec = (long) (t * 1000000) % 1000000;
6457 FD_SET(ConnectionNumber(display), &fdsr);
6459 s = select(ConnectionNumber(display) + 1, &fdsr, 0, 0, &tv);
6461 if (errno != EINTR) {
6462 ERR("can't select(): %s", strerror(errno));
6472 if (need_to_update) {
6474 int wx = window.x, wy = window.y;
6482 /* resize window if it isn't right size */
6484 && (text_width + border_margin * 2 + 1 != window.width
6485 || text_height + border_margin * 2 + 1 != window.height)) {
6486 window.width = text_width + border_margin * 2 + 1;
6487 window.height = text_height + border_margin * 2 + 1;
6488 XResizeWindow(display, window.window, window.width,
6491 set_transparent_background(window.window);
6495 /* move window if it isn't in right position */
6496 if (!fixed_pos && (window.x != wx || window.y != wy)) {
6497 XMoveWindow(display, window.window, window.x, window.y);
6508 r.x = text_start_x - border_margin;
6509 r.y = text_start_y - border_margin;
6510 r.width = text_width + border_margin * 2;
6511 r.height = text_height + border_margin * 2;
6512 XUnionRectWithRegion(&r, x11_stuff.region, x11_stuff.region);
6517 /* handle X events */
6518 while (XPending(display)) {
6521 XNextEvent(display, &ev);
6528 r.width = ev.xexpose.width;
6529 r.height = ev.xexpose.height;
6530 XUnionRectWithRegion(&r, x11_stuff.region, x11_stuff.region);
6535 case ReparentNotify:
6536 /* set background to ParentRelative for all parents */
6538 set_transparent_background(window.window);
6542 case ConfigureNotify:
6544 /* if window size isn't what expected, set fixed size */
6545 if (ev.xconfigure.width != window.width
6546 || ev.xconfigure.height != window.height) {
6547 if (window.width != 0 && window.height != 0) {
6551 /* clear old stuff before screwing up
6556 XWindowAttributes attrs;
6557 if (XGetWindowAttributes(display,
6558 window.window, &attrs)) {
6559 window.width = attrs.width;
6560 window.height = attrs.height;
6564 text_width = window.width - border_margin * 2 - 1;
6565 text_height = window.height - border_margin * 2 - 1;
6566 if (text_width > maximum_width
6567 && maximum_width > 0) {
6568 text_width = maximum_width;
6572 /* if position isn't what expected, set fixed pos
6573 * total_updates avoids setting fixed_pos when window
6574 * is set to weird locations when started */
6575 /* // this is broken
6576 if (total_updates >= 2 && !fixed_pos
6577 && (window.x != ev.xconfigure.x
6578 || window.y != ev.xconfigure.y)
6579 && (ev.xconfigure.x != 0
6580 || ev.xconfigure.y != 0)) {
6589 /* if an ordinary window with decorations */
6590 if ((window.type == TYPE_NORMAL)
6591 && (!TEST_HINT(window.hints,
6592 HINT_UNDECORATED))) {
6593 /* allow conky to hold input focus. */
6596 /* forward the click to the desktop window */
6597 XUngrabPointer(display, ev.xbutton.time);
6598 ev.xbutton.window = window.desktop;
6599 XSendEvent(display, ev.xbutton.window, False,
6600 ButtonPressMask, &ev);
6601 XSetInputFocus(display, ev.xbutton.window,
6602 RevertToParent, ev.xbutton.time);
6609 /* if an ordinary window with decorations */
6610 if ((window.type == TYPE_NORMAL)
6611 && (!TEST_HINT(window.hints,
6612 HINT_UNDECORATED))) {
6613 /* allow conky to hold input focus. */
6616 /* forward the release to the desktop window */
6617 ev.xbutton.window = window.desktop;
6618 XSendEvent(display, ev.xbutton.window, False,
6619 ButtonReleaseMask, &ev);
6628 if (ev.type == x11_stuff.event_base + XDamageNotify) {
6629 XDamageNotifyEvent *dev = (XDamageNotifyEvent *) &ev;
6631 XFixesSetRegion(display, x11_stuff.part, &dev->area, 1);
6632 XFixesUnionRegion(display, x11_stuff.region2, x11_stuff.region2, x11_stuff.part);
6634 #endif /* HAVE_XDAMAGE */
6640 XDamageSubtract(display, x11_stuff.damage, x11_stuff.region2, None);
6641 XFixesSetRegion(display, x11_stuff.region2, 0, 0);
6642 #endif /* HAVE_XDAMAGE */
6644 /* XDBE doesn't seem to provide a way to clear the back buffer without
6645 * interfering with the front buffer, other than passing XdbeBackground
6646 * to XdbeSwapBuffers. That means that if we're using XDBE, we need to
6647 * redraw the text even if it wasn't part of the exposed area. OTOH,
6648 * if we're not going to call draw_stuff at all, then no swap happens
6649 * and we can safely do nothing. */
6651 if (!XEmptyRegion(x11_stuff.region)) {
6656 r.x = text_start_x - border_margin;
6657 r.y = text_start_y - border_margin;
6658 r.width = text_width + border_margin * 2;
6659 r.height = text_height + border_margin * 2;
6660 XUnionRectWithRegion(&r, x11_stuff.region, x11_stuff.region);
6663 XSetRegion(display, window.gc, x11_stuff.region);
6666 XftDrawSetClip(window.xftdraw, x11_stuff.region);
6670 cimlib_render(text_start_x + border_margin, text_start_y + border_margin, window.width, window.height);
6673 XDestroyRegion(x11_stuff.region);
6674 x11_stuff.region = XCreateRegion();
6678 t = (next_update_time - get_time()) * 1000000;
6679 if(t > 0) usleep((useconds_t)t);
6686 #ifdef SIGNAL_BLOCKING
6687 /* unblock signals of interest and let handler fly */
6688 if (sigprocmask(SIG_SETMASK, &oldmask, NULL) < 0) {
6689 CRIT_ERR("unable to sigprocmask()");
6693 switch (g_signal_pending) {
6696 ERR("received SIGHUP or SIGUSR1. reloading the config file.");
6701 ERR("received SIGINT or SIGTERM to terminate. bye!");
6704 if (output_methods & TO_X) {
6705 XDestroyRegion(x11_stuff.region);
6706 x11_stuff.region = NULL;
6708 XDamageDestroy(display, x11_stuff.damage);
6709 XFixesDestroyRegion(display, x11_stuff.region2);
6710 XFixesDestroyRegion(display, x11_stuff.part);
6711 #endif /* HAVE_XDAMAGE */
6714 if(overwrite_file) {
6715 free(overwrite_file);
6722 return; /* return from main_loop */
6725 /* Reaching here means someone set a signal
6726 * (SIGXXXX, signal_handler), but didn't write any code
6728 * If you don't want to handle a signal, don't set a handler on
6729 * it in the first place. */
6730 if (g_signal_pending) {
6731 ERR("ignoring signal (%d)", g_signal_pending);
6735 #ifdef HAVE_SYS_INOTIFY_H
6736 if (!inotify_config_wd) {
6737 inotify_config_wd = inotify_add_watch(inotify_fd,
6741 if (inotify_fd && inotify_config_wd) {
6742 int len = 0, idx = 0;
6744 struct timeval time_to_wait;
6746 FD_ZERO (&descriptors);
6747 FD_SET(inotify_fd, &descriptors);
6749 time_to_wait.tv_sec = time_to_wait.tv_usec = 0;
6751 select(inotify_fd + 1, &descriptors, NULL, NULL, &time_to_wait);
6752 if (FD_ISSET(inotify_fd, &descriptors)) {
6753 /* process inotify events */
6754 len = read(inotify_fd, inotify_buff, INOTIFY_BUF_LEN);
6755 while (len > 0 && idx < len) {
6756 struct inotify_event *ev = (struct inotify_event *) &inotify_buff[idx];
6757 if (ev->wd == inotify_config_wd && (ev->mask & IN_MODIFY || ev->mask & IN_IGNORED)) {
6758 /* current_config should be reloaded */
6759 ERR("'%s' modified, reloading...", current_config);
6761 if (ev->mask & IN_IGNORED) {
6762 /* for some reason we get IN_IGNORED here
6763 * sometimes, so we need to re-add the watch */
6764 inotify_config_wd = inotify_add_watch(inotify_fd,
6771 llua_inotify_query(ev->wd, ev->mask);
6773 #endif /* HAVE_LUA */
6774 idx += INOTIFY_EVENT_SIZE + ev->len;
6778 #endif /* HAVE_SYS_INOTIFY_H */
6780 g_signal_pending = 0;
6783 #ifdef HAVE_SYS_INOTIFY_H
6785 inotify_rm_watch(inotify_fd, inotify_config_wd);
6787 inotify_fd = inotify_config_wd = 0;
6789 #endif /* HAVE_SYS_INOTIFY_H */
6791 #if defined(X11) && defined(HAVE_XDAMAGE)
6792 X11_destroy_window();
6793 #endif /* X11 && HAVE_XDAMAGE */
6796 static void load_config_file(const char *);
6797 static void load_config_file_x11(const char *);
6799 /* reload the config file */
6800 static void reload_config(void)
6802 timed_thread_destroy_registered_threads();
6804 if (info.cpu_usage) {
6805 free(info.cpu_usage);
6806 info.cpu_usage = NULL;
6817 #ifdef TCP_PORT_MONITOR
6818 tcp_portmon_clear();
6823 #endif /* HAVE_LUA */
6825 if (current_config) {
6827 load_config_file(current_config);
6828 load_config_file_x11(current_config);
6830 /* re-init specials array */
6831 if ((specials = realloc((void *) specials,
6832 sizeof(struct special_t) * max_specials)) == 0) {
6833 ERR("failed to realloc specials array");
6837 X11_destroy_window();
6840 extract_variable_text(global_text);
6846 tmpstring1 = malloc(text_buffer_size);
6847 memset(tmpstring1, 0, text_buffer_size);
6851 tmpstring2 = malloc(text_buffer_size);
6852 memset(tmpstring2, 0, text_buffer_size);
6856 text_buffer = malloc(max_user_text);
6857 memset(text_buffer, 0, max_user_text);
6860 X11_create_window();
6865 static void clean_up(void)
6867 timed_thread_destroy_registered_threads();
6869 if (info.cpu_usage) {
6870 free(info.cpu_usage);
6871 info.cpu_usage = NULL;
6874 if (output_methods & TO_X) {
6877 XdbeDeallocateBackBufferName(display, window.back_buffer);
6882 XDestroyWindow(display, window.window);
6883 XClearWindow(display, RootWindow(display, screen));
6888 XClearWindow(display, RootWindow(display, screen));
6893 XFreeGC(display, window.gc);
6899 free_text_objects(&global_root_object, 0);
6918 free(current_config);
6920 #ifdef TCP_PORT_MONITOR
6921 tcp_portmon_clear();
6928 #endif /* HAVE_LUA */
6933 for (i = 0; i < special_count; i++) {
6934 if (specials[i].type == GRAPH) {
6935 free(specials[i].graph);
6942 clear_diskio_stats();
6945 static int string_to_bool(const char *s)
6948 // Assumes an option without a true/false means true
6950 } else if (strcasecmp(s, "yes") == EQUAL) {
6952 } else if (strcasecmp(s, "true") == EQUAL) {
6954 } else if (strcasecmp(s, "1") == EQUAL) {
6961 static enum alignment string_to_alignment(const char *s)
6963 if (strcasecmp(s, "top_left") == EQUAL) {
6965 } else if (strcasecmp(s, "top_right") == EQUAL) {
6967 } else if (strcasecmp(s, "top_middle") == EQUAL) {
6969 } else if (strcasecmp(s, "bottom_left") == EQUAL) {
6971 } else if (strcasecmp(s, "bottom_right") == EQUAL) {
6972 return BOTTOM_RIGHT;
6973 } else if (strcasecmp(s, "bottom_middle") == EQUAL) {
6974 return BOTTOM_MIDDLE;
6975 } else if (strcasecmp(s, "middle_left") == EQUAL) {
6977 } else if (strcasecmp(s, "middle_right") == EQUAL) {
6978 return MIDDLE_RIGHT;
6979 } else if (strcasecmp(s, "tl") == EQUAL) {
6981 } else if (strcasecmp(s, "tr") == EQUAL) {
6983 } else if (strcasecmp(s, "tm") == EQUAL) {
6985 } else if (strcasecmp(s, "bl") == EQUAL) {
6987 } else if (strcasecmp(s, "br") == EQUAL) {
6988 return BOTTOM_RIGHT;
6989 } else if (strcasecmp(s, "bm") == EQUAL) {
6990 return BOTTOM_MIDDLE;
6991 } else if (strcasecmp(s, "ml") == EQUAL) {
6993 } else if (strcasecmp(s, "mr") == EQUAL) {
6994 return MIDDLE_RIGHT;
6995 } else if (strcasecmp(s, "none") == EQUAL) {
7003 static void set_default_configurations_for_x(void)
7005 default_fg_color = WhitePixel(display, screen);
7006 default_bg_color = BlackPixel(display, screen);
7007 default_out_color = BlackPixel(display, screen);
7008 color0 = default_fg_color;
7009 color1 = default_fg_color;
7010 color2 = default_fg_color;
7011 color3 = default_fg_color;
7012 color4 = default_fg_color;
7013 color5 = default_fg_color;
7014 color6 = default_fg_color;
7015 color7 = default_fg_color;
7016 color8 = default_fg_color;
7017 color9 = default_fg_color;
7021 static void set_default_configurations(void)
7024 fork_to_background = 0;
7025 total_run_times = 0;
7026 info.cpu_avg_samples = 2;
7027 info.net_avg_samples = 2;
7028 info.diskio_avg_samples = 2;
7036 mpd_set_host("localhost");
7037 mpd_set_port("6600");
7040 info.xmms2.artist = NULL;
7041 info.xmms2.album = NULL;
7042 info.xmms2.title = NULL;
7043 info.xmms2.genre = NULL;
7044 info.xmms2.comment = NULL;
7045 info.xmms2.url = NULL;
7046 info.xmms2.status = NULL;
7047 info.xmms2.playlist = NULL;
7049 use_spacer = NO_SPACER;
7051 output_methods = TO_X;
7053 output_methods = TO_STDOUT;
7056 show_graph_scale = 0;
7057 show_graph_range = 0;
7058 template[0] = strdup("");
7059 template[1] = strdup("");
7060 template[2] = strdup("");
7061 template[3] = strdup("");
7062 template[4] = strdup("");
7063 template[5] = strdup("");
7064 template[6] = strdup("");
7065 template[7] = strdup("");
7066 template[8] = strdup("");
7067 template[9] = strdup("");
7070 draw_graph_borders = 1;
7072 set_first_font("6x10");
7080 window.type = TYPE_NORMAL;
7082 strcpy(window.class_name, PACKAGE_NAME);
7083 sprintf(window.title, PACKAGE_NAME" (%s)", info.uname_s.nodename);
7085 stippled_borders = 0;
7088 text_alignment = BOTTOM_LEFT;
7089 info.x11.monitor.number = 1;
7090 info.x11.monitor.current = 0;
7093 free(current_mail_spool);
7097 variable_substitute(MAIL_FILE, buf, 256);
7098 if (buf[0] != '\0') {
7099 current_mail_spool = strndup(buf, text_buffer_size);
7104 update_interval = 3.0;
7105 info.music_player_interval = 1.0;
7106 stuff_in_upper_case = 0;
7107 info.users.number = 1;
7109 #ifdef TCP_PORT_MONITOR
7110 /* set default connection limit */
7111 tcp_portmon_set_max_connections(0);
7115 /* returns 1 if you can overwrite or create the file at 'path' */
7116 static _Bool overwrite_works(const char *path)
7120 if (!(filepointer = fopen(path, "w")))
7122 fclose(filepointer);
7126 /* returns 1 if you can append or create the file at 'path' */
7127 static _Bool append_works(const char *path)
7131 if (!(filepointer = fopen(path, "a")))
7133 fclose(filepointer);
7138 static void X11_initialisation(void)
7140 if (x_initialised == YES) return;
7141 output_methods |= TO_X;
7143 set_default_configurations_for_x();
7144 x_initialised = YES;
7147 static void X11_destroy_window(void)
7149 /* this function only exists for the sake of consistency */
7150 if (output_methods & TO_X) {
7152 XDamageDestroy(display, x11_stuff.damage);
7153 XFixesDestroyRegion(display, x11_stuff.region2);
7154 XFixesDestroyRegion(display, x11_stuff.part);
7155 XDestroyRegion(x11_stuff.region);
7156 x11_stuff.region = NULL;
7157 #endif /* HAVE_XDAMAGE */
7162 static char **xargv = 0;
7163 static int xargc = 0;
7165 static void X11_create_window(void)
7167 if (output_methods & TO_X) {
7169 init_window(own_window, text_width + border_margin * 2 + 1,
7170 text_height + border_margin * 2 + 1, set_transparent, background_colour,
7172 #else /* OWN_WINDOW */
7173 init_window(0, text_width + border_margin * 2 + 1,
7174 text_height + border_margin * 2 + 1, set_transparent, 0,
7176 #endif /* OWN_WINDOW */
7179 update_text_area(); /* to position text/window on screen */
7182 if (own_window && !fixed_pos) {
7183 XMoveWindow(display, window.window, window.x, window.y);
7186 set_transparent_background(window.window);
7195 x11_stuff.region = XCreateRegion();
7197 if (!XDamageQueryExtension(display, &x11_stuff.event_base, &x11_stuff.error_base)) {
7198 ERR("Xdamage extension unavailable");
7200 x11_stuff.damage = XDamageCreate(display, window.window, XDamageReportNonEmpty);
7201 x11_stuff.region2 = XFixesCreateRegionFromWindow(display, window.window, 0);
7202 x11_stuff.part = XFixesCreateRegionFromWindow(display, window.window, 0);
7203 #endif /* HAVE_XDAMAGE */
7206 update_text_area(); /* to get initial size of the window */
7211 #define CONF_ERR ERR("%s: %d: config file error", f, line)
7212 #define CONF_ERR2(a) ERR("%s: %d: config file error: %s", f, line, a)
7213 #define CONF2(a) if (strcasecmp(name, a) == 0)
7214 #define CONF(a) else CONF2(a)
7215 #define CONF3(a, b) else if (strcasecmp(name, a) == 0 \
7216 || strcasecmp(name, b) == 0)
7217 #define CONF_CONTINUE 1
7218 #define CONF_BREAK 2
7219 #define CONF_BUFF_SIZE 512
7221 static FILE *open_config_file(const char *f)
7223 #ifdef CONFIG_OUTPUT
7224 if (!strcmp(f, "==builtin==")) {
7225 #ifdef HAVE_FOPENCOOKIE
7226 return fopencookie(NULL, "r", conf_cookie);
7227 #endif /* HAVE_FOPENCOOKIE */
7229 #endif /* CONFIG_OUTPUT */
7230 return fopen(f, "r");
7233 static int do_config_step(int *line, FILE *fp, char *buf, char **name, char **value)
7237 if (fgets(buf, CONF_BUFF_SIZE, fp) == NULL) {
7240 remove_comments(buf);
7245 while (*p && isspace((int) *p)) {
7249 return CONF_CONTINUE; /* empty line */
7256 while (*p2 && !isspace((int) *p2)) {
7260 *p2 = '\0'; /* break at name's end */
7267 while (*p && isspace((int) *p)) {
7273 p2 = *value + strlen(*value);
7274 while (isspace((int) *(p2 - 1))) {
7283 static void load_config_file(const char *f)
7288 set_default_configurations();
7289 fp = open_config_file(f);
7293 DBGP("reading contents from config file '%s'", f);
7296 char buff[CONF_BUFF_SIZE], *name, *value;
7297 int ret = do_config_step(&line, fp, buff, &name, &value);
7298 if (ret == CONF_BREAK) {
7300 } else if (ret == CONF_CONTINUE) {
7306 /* don't listen if X is already initialised or
7307 * if we already know we don't want it */
7308 if(x_initialised == NO) {
7309 if (string_to_bool(value)) {
7310 output_methods &= TO_X;
7312 output_methods &= ~TO_X;
7313 x_initialised = NEVER;
7318 if (!value || x_initialised == YES) {
7323 disp = strdup(value);
7327 if (window.type == TYPE_DOCK)
7330 int a = string_to_alignment(value);
7341 CONF("background") {
7342 fork_to_background = string_to_bool(value);
7345 CONF2("background") {
7346 fork_to_background = string_to_bool(value);
7350 CONF("show_graph_scale") {
7351 show_graph_scale = string_to_bool(value);
7353 CONF("show_graph_range") {
7354 show_graph_range = string_to_bool(value);
7356 CONF("border_margin") {
7358 border_margin = strtol(value, 0, 0);
7363 CONF("border_width") {
7365 border_width = strtol(value, 0, 0);
7370 #define TEMPLATE_CONF(n) \
7371 CONF("template"#n) { \
7373 free(template[n]); \
7374 template[n] = strdup(value); \
7392 info.mail = parse_mail_args(IMAP_TYPE, value);
7399 info.mail = parse_mail_args(POP3_TYPE, value);
7404 CONF("default_bar_size") {
7407 if (sscanf(value, "%d %d", &default_bar_width, &default_bar_height) != 2) {
7414 CONF_ERR2("default_bar_size takes 2 integer arguments (ie. 'default_bar_size 0 6')")
7418 CONF("default_graph_size") {
7421 if (sscanf(value, "%d %d", &default_graph_width, &default_graph_height) != 2) {
7428 CONF_ERR2("default_graph_size takes 2 integer arguments (ie. 'default_graph_size 0 6')")
7431 CONF("default_gauge_size") {
7434 if (sscanf(value, "%d %d", &default_gauge_width, &default_gauge_height) != 2) {
7441 CONF_ERR2("default_gauge_size takes 2 integer arguments (ie. 'default_gauge_size 0 6')")
7448 mpd_set_host(value);
7454 if (value && mpd_set_port(value)) {
7458 CONF("mpd_password") {
7460 mpd_set_password(value);
7466 CONF("music_player_interval") {
7468 info.music_player_interval = strtod(value, 0);
7474 CONF("sensor_device") {
7476 sensor_device = strtol(value, 0, 0);
7482 CONF("cpu_avg_samples") {
7484 cpu_avg_samples = strtol(value, 0, 0);
7485 if (cpu_avg_samples < 1 || cpu_avg_samples > 14) {
7488 info.cpu_avg_samples = cpu_avg_samples;
7494 CONF("net_avg_samples") {
7496 net_avg_samples = strtol(value, 0, 0);
7497 if (net_avg_samples < 1 || net_avg_samples > 14) {
7500 info.net_avg_samples = net_avg_samples;
7506 CONF("diskio_avg_samples") {
7508 diskio_avg_samples = strtol(value, 0, 0);
7509 if (diskio_avg_samples < 1 || diskio_avg_samples > 14) {
7512 info.diskio_avg_samples = diskio_avg_samples;
7520 CONF("double_buffer") {
7521 use_xdbe = string_to_bool(value);
7525 CONF("override_utf8_locale") {
7526 utf8_mode = string_to_bool(value);
7528 CONF("draw_borders") {
7529 draw_borders = string_to_bool(value);
7531 CONF("draw_graph_borders") {
7532 draw_graph_borders = string_to_bool(value);
7534 CONF("draw_shades") {
7535 draw_shades = string_to_bool(value);
7537 CONF("draw_outline") {
7538 draw_outline = string_to_bool(value);
7541 CONF("out_to_console") {
7542 if(string_to_bool(value))
7543 output_methods |= TO_STDOUT;
7545 CONF("out_to_stderr") {
7546 if(string_to_bool(value))
7547 output_methods |= TO_STDERR;
7549 CONF("overwrite_file") {
7550 if(overwrite_file) {
7551 free(overwrite_file);
7554 if(overwrite_works(value)) {
7555 overwrite_file = strdup(value);
7556 output_methods |= OVERWRITE_FILE;
7558 ERR("overwrite_file won't be able to create/overwrite '%s'", value);
7560 CONF("append_file") {
7565 if(append_works(value)) {
7566 append_file = strdup(value);
7567 output_methods |= APPEND_FILE;
7569 ERR("append_file won't be able to create/append '%s'", value);
7571 CONF("use_spacer") {
7573 if (strcasecmp(value, "left") == EQUAL) {
7574 use_spacer = LEFT_SPACER;
7575 } else if (strcasecmp(value, "right") == EQUAL) {
7576 use_spacer = RIGHT_SPACER;
7577 } else if (strcasecmp(value, "none") == EQUAL) {
7578 use_spacer = NO_SPACER;
7580 use_spacer = string_to_bool(value);
7581 ERR("use_spacer should have an argument of left, right, or"
7582 " none. '%s' seems to be some form of '%s', so"
7583 " defaulting to %s.", value,
7584 use_spacer ? "true" : "false",
7585 use_spacer ? "right" : "none");
7587 use_spacer = RIGHT_SPACER;
7589 use_spacer = NO_SPACER;
7593 ERR("use_spacer should have an argument. Defaulting to right.");
7594 use_spacer = RIGHT_SPACER;
7600 use_xft = string_to_bool(value);
7604 set_first_font(value);
7608 if (value && font_count >= 0) {
7609 fonts[0].font_alpha = atof(value) * 65535.0;
7616 if (string_to_bool(value)) {
7617 ERR("Xft not enabled");
7621 /* xftfont silently ignored when no Xft */
7624 /* xftalpha is silently ignored when no Xft */
7629 set_first_font(value);
7637 gap_x = atoi(value);
7644 gap_y = atoi(value);
7650 CONF("mail_spool") {
7654 variable_substitute(value, buffer, 256);
7656 if (buffer[0] != '\0') {
7657 if (current_mail_spool) {
7658 free(current_mail_spool);
7660 current_mail_spool = strndup(buffer, text_buffer_size);
7667 CONF("minimum_size") {
7669 if (sscanf(value, "%d %d", &minimum_width, &minimum_height)
7671 if (sscanf(value, "%d", &minimum_width) != 1) {
7679 CONF("maximum_width") {
7681 if (sscanf(value, "%d", &maximum_width) != 1) {
7689 CONF("no_buffers") {
7690 no_buffers = string_to_bool(value);
7692 CONF("top_name_width") {
7694 if (sscanf(value, "%u", &top_name_width) != 1) {
7700 if (top_name_width >= max_user_text) {
7701 top_name_width = max_user_text - 1;
7704 CONF("top_cpu_separate") {
7705 cpu_separate = string_to_bool(value);
7707 CONF("short_units") {
7708 short_units = string_to_bool(value);
7710 CONF("pad_percents") {
7711 pad_percents = atoi(value);
7715 CONF("own_window") {
7717 own_window = string_to_bool(value);
7720 CONF("own_window_class") {
7722 memset(window.class_name, 0, sizeof(window.class_name));
7723 strncpy(window.class_name, value,
7724 sizeof(window.class_name) - 1);
7727 CONF("own_window_title") {
7729 memset(window.title, 0, sizeof(window.title));
7730 strncpy(window.title, value, sizeof(window.title) - 1);
7733 CONF("own_window_transparent") {
7735 set_transparent = string_to_bool(value);
7738 CONF("own_window_hints") {
7740 char *p_hint, *p_save;
7741 char delim[] = ", ";
7743 /* tokenize the value into individual hints */
7744 if ((p_hint = strtok_r(value, delim, &p_save)) != NULL) {
7746 /* fprintf(stderr, "hint [%s] parsed\n", p_hint); */
7747 if (strncmp(p_hint, "undecorate", 10) == EQUAL) {
7748 SET_HINT(window.hints, HINT_UNDECORATED);
7749 } else if (strncmp(p_hint, "below", 5) == EQUAL) {
7750 SET_HINT(window.hints, HINT_BELOW);
7751 } else if (strncmp(p_hint, "above", 5) == EQUAL) {
7752 SET_HINT(window.hints, HINT_ABOVE);
7753 } else if (strncmp(p_hint, "sticky", 6) == EQUAL) {
7754 SET_HINT(window.hints, HINT_STICKY);
7755 } else if (strncmp(p_hint, "skip_taskbar", 12) == EQUAL) {
7756 SET_HINT(window.hints, HINT_SKIP_TASKBAR);
7757 } else if (strncmp(p_hint, "skip_pager", 10) == EQUAL) {
7758 SET_HINT(window.hints, HINT_SKIP_PAGER);
7763 p_hint = strtok_r(NULL, delim, &p_save);
7764 } while (p_hint != NULL);
7770 CONF("own_window_type") {
7772 if (strncmp(value, "normal", 6) == EQUAL) {
7773 window.type = TYPE_NORMAL;
7774 } else if (strncmp(value, "desktop", 7) == EQUAL) {
7775 window.type = TYPE_DESKTOP;
7776 } else if (strncmp(value, "dock", 7) == EQUAL) {
7777 window.type = TYPE_DOCK;
7778 text_alignment = TOP_LEFT;
7779 } else if (strncmp(value, "override", 8) == EQUAL) {
7780 window.type = TYPE_OVERRIDE;
7789 CONF("stippled_borders") {
7791 stippled_borders = strtol(value, 0, 0);
7793 stippled_borders = 4;
7797 CONF("imlib_cache_size") {
7799 cimlib_set_cache_size(atoi(value));
7804 CONF("update_interval") {
7806 update_interval = strtod(value, 0);
7810 if (info.music_player_interval == 0) {
7811 // default to update_interval
7812 info.music_player_interval = update_interval;
7815 CONF("total_run_times") {
7817 total_run_times = strtod(value, 0);
7823 stuff_in_upper_case = string_to_bool(value);
7825 CONF("max_specials") {
7827 max_specials = atoi(value);
7832 CONF("max_user_text") {
7834 max_user_text = atoi(value);
7839 CONF("text_buffer_size") {
7841 text_buffer_size = atoi(value);
7842 if (text_buffer_size < DEFAULT_TEXT_BUFFER_SIZE) {
7843 ERR("text_buffer_size must be >=%i bytes", DEFAULT_TEXT_BUFFER_SIZE);
7844 text_buffer_size = DEFAULT_TEXT_BUFFER_SIZE;
7852 if(output_methods & TO_X) {
7853 X11_initialisation();
7862 global_text = (char *) malloc(1);
7863 global_text[0] = '\0';
7866 unsigned int l = strlen(global_text);
7868 char buf[CONF_BUFF_SIZE];
7870 if (fgets(buf, CONF_BUFF_SIZE, fp) == NULL) {
7876 if (bl >= 2 && buf[bl-2] == '\\' && buf[bl-1] == '\n') {
7884 /* Check for continuation of \\-\n. */
7885 if (l > 0 && buf[0] == '\n' && global_text[l-1] == '\\') {
7886 global_text[l-1] = '\0';
7890 global_text = (char *) realloc(global_text, l + bl + 1);
7891 strcat(global_text, buf);
7893 if (strlen(global_text) > max_user_text) {
7898 if (strlen(global_text) < 1) {
7899 CRIT_ERR("no text supplied in configuration; exiting");
7901 global_text_lines = line + 1;
7904 #ifdef TCP_PORT_MONITOR
7905 CONF("max_port_monitor_connections") {
7907 if (!value || (sscanf(value, "%d", &max) != 1)) {
7908 /* an error. use default, warn and continue. */
7909 tcp_portmon_set_max_connections(0);
7911 } else if (tcp_portmon_set_max_connections(max)) {
7912 /* max is < 0, default has been set*/
7917 CONF("if_up_strictness") {
7919 ERR("incorrect if_up_strictness value, defaulting to 'up'");
7920 ifup_strictness = IFUP_UP;
7921 } else if (strcasecmp(value, "up") == EQUAL) {
7922 ifup_strictness = IFUP_UP;
7923 } else if (strcasecmp(value, "link") == EQUAL) {
7924 ifup_strictness = IFUP_LINK;
7925 } else if (strcasecmp(value, "address") == EQUAL) {
7926 ifup_strictness = IFUP_ADDR;
7928 ERR("incorrect if_up_strictness value, defaulting to 'up'");
7929 ifup_strictness = IFUP_UP;
7933 CONF("temperature_unit") {
7935 ERR("config option 'temperature_unit' needs an argument, either 'celsius' or 'fahrenheit'");
7936 } else if (set_temp_output_unit(value)) {
7937 ERR("temperature_unit: incorrect argument");
7943 size_t maxlength = strlen(value); //+1 for terminating 0 not needed, 'cause of the space in the middle of value
7944 char *skey = malloc(maxlength);
7945 char *svalue = malloc(maxlength);
7947 if (sscanf(value, "%[0-9a-zA-Z_] %[^\n]", skey, svalue) == 2) {
7948 oldvalue = getenv(skey);
7949 if (oldvalue == NULL) {
7950 setenv(skey, svalue, 0);
7952 //PS: Don't free oldvalue, it's the real envvar, not a copy
7966 char *ptr = strtok(value, " ");
7969 ptr = strtok(NULL, " ");
7975 #endif /* HAVE_LUA */
7987 CONF("default_color"){}
7988 CONF3("default_shade_color", "default_shadecolor"){}
7989 CONF3("default_outline_color", "default_outlinecolor") {}
7990 CONF("own_window_colour") {}
7993 ERR("%s: %d: no such configuration: '%s'", f, line, name);
7999 if (info.music_player_interval == 0) {
8000 // default to update_interval
8001 info.music_player_interval = update_interval;
8003 if (!global_text) { // didn't supply any text
8004 CRIT_ERR("missing text block in configuration; exiting");
8008 static void load_config_file_x11(const char *f)
8013 fp = open_config_file(f);
8017 DBGP("reading contents from config file '%s'", f);
8020 char buff[CONF_BUFF_SIZE], *name, *value;
8021 int ret = do_config_step(&line, fp, buff, &name, &value);
8022 if (ret == CONF_BREAK) {
8024 } else if (ret == CONF_CONTINUE) {
8030 X11_initialisation();
8031 if (x_initialised == YES) {
8033 color0 = get_x11_color(value);
8040 X11_initialisation();
8041 if (x_initialised == YES) {
8043 color1 = get_x11_color(value);
8050 X11_initialisation();
8051 if (x_initialised == YES) {
8053 color2 = get_x11_color(value);
8060 X11_initialisation();
8061 if (x_initialised == YES) {
8063 color3 = get_x11_color(value);
8070 X11_initialisation();
8071 if (x_initialised == YES) {
8073 color4 = get_x11_color(value);
8080 X11_initialisation();
8081 if (x_initialised == YES) {
8083 color5 = get_x11_color(value);
8090 X11_initialisation();
8091 if (x_initialised == YES) {
8093 color6 = get_x11_color(value);
8100 X11_initialisation();
8101 if (x_initialised == YES) {
8103 color7 = get_x11_color(value);
8110 X11_initialisation();
8111 if (x_initialised == YES) {
8113 color8 = get_x11_color(value);
8120 X11_initialisation();
8121 if (x_initialised == YES) {
8123 color9 = get_x11_color(value);
8129 CONF("default_color") {
8130 X11_initialisation();
8131 if (x_initialised == YES) {
8133 default_fg_color = get_x11_color(value);
8139 CONF3("default_shade_color", "default_shadecolor") {
8140 X11_initialisation();
8141 if (x_initialised == YES) {
8143 default_bg_color = get_x11_color(value);
8149 CONF3("default_outline_color", "default_outlinecolor") {
8150 X11_initialisation();
8151 if (x_initialised == YES) {
8153 default_out_color = get_x11_color(value);
8160 CONF("own_window_colour") {
8161 X11_initialisation();
8162 if (x_initialised == YES) {
8164 background_colour = get_x11_color(value);
8166 ERR("Invalid colour for own_window_colour (try omitting the "
8167 "'#' for hex colours");
8173 //initialize X11 if nothing X11-related is mentioned before TEXT (and if X11 is the default outputmethod)
8174 if(output_methods & TO_X) {
8175 X11_initialisation();
8185 #undef CONF_CONTINUE
8186 #undef CONF_BUFF_SIZE
8193 static void print_help(const char *prog_name) {
8194 printf("Usage: %s [OPTION]...\n"
8195 PACKAGE_NAME" is a system monitor that renders text on desktop or to own transparent\n"
8196 "window. Command line options will override configurations defined in config\n"
8198 " -v, --version version\n"
8199 " -q, --quiet quiet mode\n"
8200 " -D, --debug increase debugging output\n"
8201 " -c, --config=FILE config file to load\n"
8202 #ifdef CONFIG_OUTPUT
8203 " -C, --print-config print the builtin default config to stdout\n"
8204 " e.g. 'conky -C > ~/.conkyrc' will create a new default config\n"
8206 " -d, --daemonize daemonize, fork to background\n"
8207 " -h, --help help\n"
8209 " -a, --alignment=ALIGNMENT text alignment on screen, {top,bottom,middle}_{left,right,middle}\n"
8210 " -f, --font=FONT font to use\n"
8211 " -X, --display=DISPLAY X11 display to use\n"
8213 " -o, --own-window create own window to draw\n"
8216 " -b, --double-buffer double buffer (prevents flickering)\n"
8218 " -w, --window-id=WIN_ID window id to draw\n"
8219 " -x X x position\n"
8220 " -y Y y position\n"
8222 " -t, --text=TEXT text to render, remember single quotes, like -t '$uptime'\n"
8223 " -u, --interval=SECS update interval\n"
8224 " -i COUNT number of times to update "PACKAGE_NAME" (and quit)\n",
8229 /* : means that character before that takes an argument */
8230 static const char *getopt_string = "vVqdDt:u:i:hc:"
8240 #ifdef CONFIG_OUTPUT
8245 static const struct option longopts[] = {
8246 { "help", 0, NULL, 'h' },
8247 { "version", 0, NULL, 'V' },
8248 { "debug", 0, NULL, 'D' },
8249 { "config", 1, NULL, 'c' },
8250 #ifdef CONFIG_OUTPUT
8251 { "print-config", 0, NULL, 'C' },
8253 { "daemonize", 0, NULL, 'd' },
8255 { "alignment", 1, NULL, 'a' },
8256 { "font", 1, NULL, 'f' },
8257 { "display", 1, NULL, 'X' },
8259 { "own-window", 0, NULL, 'o' },
8262 { "double-buffer", 0, NULL, 'b' },
8264 { "window-id", 1, NULL, 'w' },
8266 { "text", 1, NULL, 't' },
8267 { "interval", 0, NULL, 'u' },
8271 int main(int argc, char **argv)
8277 struct sigaction act, oact;
8279 g_signal_pending = 0;
8280 memset(&info, 0, sizeof(info));
8283 #ifdef TCP_PORT_MONITOR
8284 /* set default connection limit */
8285 tcp_portmon_set_max_connections(0);
8288 /* handle command line parameters that don't change configs */
8290 if (((s = getenv("LC_ALL")) && *s) || ((s = getenv("LC_CTYPE")) && *s)
8291 || ((s = getenv("LANG")) && *s)) {
8292 temp = (char *) malloc((strlen(s) + 1) * sizeof(char));
8294 ERR("malloc failed");
8296 for (x = 0; x < strlen(s); x++) {
8297 temp[x] = tolower(s[x]);
8300 if (strstr(temp, "utf-8") || strstr(temp, "utf8")) {
8306 if (!setlocale(LC_CTYPE, "")) {
8307 ERR("Can't set the specified locale!\nCheck LANG, LC_CTYPE, LC_ALL.");
8311 int c = getopt_long(argc, argv, getopt_string, longopts, NULL);
8322 if (current_config) {
8323 free(current_config);
8325 current_config = strndup(optarg, max_user_text);
8328 freopen("/dev/null", "w", stderr);
8331 print_help(argv[0]);
8333 #ifdef CONFIG_OUTPUT
8340 window.window = strtol(optarg, 0, 0);
8349 /* check if specified config file is valid */
8350 if (current_config) {
8352 if (stat(current_config, &sb) ||
8353 (!S_ISREG(sb.st_mode) && !S_ISLNK(sb.st_mode))) {
8354 ERR("invalid configuration file '%s'\n", current_config);
8355 free(current_config);
8360 /* load current_config, CONFIG_FILE or SYSTEM_CONFIG_FILE */
8362 if (!current_config) {
8363 /* load default config file */
8367 /* Try to use personal config file first */
8368 variable_substitute(CONFIG_FILE, buf, sizeof(buf));
8369 if (buf[0] && (fp = fopen(buf, "r"))) {
8370 current_config = strndup(buf, max_user_text);
8374 /* Try to use system config file if personal config not readable */
8375 if (!current_config && (fp = fopen(SYSTEM_CONFIG_FILE, "r"))) {
8376 current_config = strndup(SYSTEM_CONFIG_FILE, max_user_text);
8380 /* No readable config found */
8381 if (!current_config) {
8382 #ifdef CONFIG_OUTPUT
8383 current_config = strdup("==builtin==");
8384 ERR("no readable personal or system-wide config file found,"
8385 " using builtin default");
8387 CRIT_ERR("no readable personal or system-wide config file found");
8388 #endif /* ! CONF_OUTPUT */
8391 #ifdef HAVE_SYS_INOTIFY_H
8392 inotify_fd = inotify_init();
8393 #endif /* HAVE_SYS_INOTIFY_H */
8395 load_config_file(current_config);
8397 /* init specials array */
8398 if ((specials = calloc(sizeof(struct special_t), max_specials)) == 0) {
8399 ERR("failed to create specials array");
8403 if (current_mail_spool == NULL) {
8406 variable_substitute(MAIL_FILE, buf, 256);
8408 if (buf[0] != '\0') {
8409 current_mail_spool = strndup(buf, text_buffer_size);
8414 /* handle other command line arguments */
8416 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__OpenBSD__) \
8417 || defined(__NetBSD__)
8418 optind = optreset = 1;
8423 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
8424 if ((kd = kvm_open("/dev/null", "/dev/null", "/dev/null", O_RDONLY,
8425 "kvm_open")) == NULL) {
8426 CRIT_ERR("cannot read kvm");
8431 int c = getopt_long(argc, argv, getopt_string, longopts, NULL);
8439 fork_to_background = 1;
8442 global_debug_level++;
8446 set_first_font(optarg);
8449 text_alignment = string_to_alignment(optarg);
8454 disp = strdup(optarg);
8473 global_text = strndup(optarg, max_user_text);
8474 convert_escapes(global_text);
8478 update_interval = strtod(optarg, 0);
8479 if (info.music_player_interval == 0) {
8480 // default to update_interval
8481 info.music_player_interval = update_interval;
8486 total_run_times = strtod(optarg, 0);
8490 gap_x = atoi(optarg);
8494 gap_y = atoi(optarg);
8505 if (output_methods & TO_X) {
8506 load_config_file_x11(current_config);
8511 /* generate text and get initial size */
8512 extract_variable_text(global_text);
8519 if (fork_to_background) {
8524 ERR(PACKAGE_NAME": couldn't fork() to background: %s",
8531 fprintf(stderr, "\n");
8536 /* parent process */
8537 fprintf(stderr, PACKAGE_NAME": forked to background, pid is %d\n",
8544 text_buffer = malloc(max_user_text);
8545 memset(text_buffer, 0, max_user_text);
8546 tmpstring1 = malloc(text_buffer_size);
8547 memset(tmpstring1, 0, text_buffer_size);
8548 tmpstring2 = malloc(text_buffer_size);
8549 memset(tmpstring2, 0, text_buffer_size);
8554 X11_create_window();
8557 /* Set signal handlers */
8558 act.sa_handler = signal_handler;
8559 sigemptyset(&act.sa_mask);
8562 act.sa_flags |= SA_RESTART;
8565 if ( sigaction(SIGINT, &act, &oact) < 0
8566 || sigaction(SIGUSR1, &act, &oact) < 0
8567 || sigaction(SIGHUP, &act, &oact) < 0
8568 || sigaction(SIGTERM, &act, &oact) < 0) {
8569 ERR("error setting signal handler: %s", strerror(errno));
8574 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
8581 static void signal_handler(int sig)
8583 /* signal handler is light as a feather, as it should be.
8584 * we will poll g_signal_pending with each loop of conky
8585 * and do any signal processing there, NOT here. */
8586 g_signal_pending = sig;