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 */
192 #endif /* HAVE_OPENMP */
199 #ifdef TCP_PORT_MONITOR
201 #endif /* TCP_PORT_MONITOR */
207 #endif /* HAVE_LUA */
210 #endif /* HAVE_IWLIB */
212 " * support for IBM/Lenovo notebooks\n"
222 #endif /* CONFIG_OUTPUT */
227 " * ALSA mixer support\n"
228 #endif /* MIXER_IS_ALSA */
237 static const char *suffixes[] = { "B", "KiB", "MiB", "GiB", "TiB", "PiB", "" };
242 static void X11_destroy_window(void);
243 static void X11_create_window(void);
245 struct _x11_stuff_s {
249 XserverRegion region2, part;
250 int event_base, error_base;
256 static int text_start_x, text_start_y; /* text start position in window */
257 static int text_width, text_height;
272 /* display to connect to */
273 static char *disp = NULL;
277 /* struct that has all info to be shared between
278 * instances of the same text object */
279 struct information info;
281 /* default config file */
282 static char *current_config;
284 /* set to 1 if you want all text to be in uppercase */
285 static unsigned int stuff_in_upper_case;
287 /* Run how many times? */
288 static unsigned long total_run_times;
291 static int fork_to_background;
293 static int cpu_avg_samples, net_avg_samples, diskio_avg_samples;
295 /* filenames for output */
296 char *overwrite_file = NULL; FILE *overwrite_fpointer = NULL;
297 char *append_file = NULL; FILE *append_fpointer = NULL;
301 static int show_graph_scale;
302 static int show_graph_range;
304 /* Position on the screen */
305 static int text_alignment;
306 static int gap_x, gap_y;
309 static int draw_borders;
310 static int draw_graph_borders;
311 static int stippled_borders;
313 static int draw_shades, draw_outline;
315 static int border_margin, border_width;
317 static long default_fg_color, default_bg_color, default_out_color;
319 /* create own window or draw stuff to root? */
320 static int set_transparent = 0;
323 static int own_window = 0;
324 static int background_colour = 0;
326 /* fixed size/pos is set if wm/user changes them */
327 static int fixed_size = 0, fixed_pos = 0;
330 static int minimum_width, minimum_height;
331 static int maximum_width;
336 static int sensor_device;
339 static long color0, color1, color2, color3, color4, color5, color6, color7,
342 static char *template[10];
344 /* maximum size of config TEXT buffer, i.e. below TEXT line. */
345 static unsigned int max_user_text = MAX_USER_TEXT_DEFAULT;
347 /* maximum size of individual text buffers, ie $exec buffer size */
348 unsigned int text_buffer_size = DEFAULT_TEXT_BUFFER_SIZE;
351 #define CODEPAGE_LENGTH 20
353 long iconv_count = 0;
354 char iconv_converting;
355 static iconv_t **iconv_cd = 0;
357 int register_iconv(iconv_t *new_iconv)
359 iconv_cd = realloc(iconv_cd, sizeof(iconv_t *) * (iconv_count + 1));
361 CRIT_ERR("Out of memory");
363 iconv_cd[iconv_count] = malloc(sizeof(iconv_t));
364 if (!iconv_cd[iconv_count]) {
365 CRIT_ERR("Out of memory");
367 memcpy(iconv_cd[iconv_count], new_iconv, sizeof(iconv_t));
372 void free_iconv(void)
377 for (i = 0; i < iconv_count; i++) {
379 iconv_close(*iconv_cd[i]);
393 /* no buffers in used memory? */
396 /* pad percentages to decimals? */
397 static int pad_percents = 0;
399 static char *global_text = 0;
400 long global_text_lines;
402 static int total_updates;
403 static int updatereset;
405 int check_contains(char *f, char *s)
408 FILE *where = open_file(f, 0);
411 char buf1[256], buf2[256];
413 while (fgets(buf1, 256, where)) {
414 sscanf(buf1, "%255s", buf2);
415 if (strstr(buf2, s)) {
422 ERR("Could not open the file");
428 static inline int calc_text_width(const char *s, int l)
430 if ((output_methods & TO_X) == 0)
437 XftTextExtentsUtf8(display, fonts[selected_font].xftfont,
438 (const FcChar8 *) s, l, &gi);
440 XftTextExtents8(display, fonts[selected_font].xftfont,
441 (const FcChar8 *) s, l, &gi);
447 return XTextWidth(fonts[selected_font].font, s, l);
452 /* formatted text to render on screen, generated in generate_text(),
453 * drawn in draw_stuff() */
455 static char *text_buffer;
458 static unsigned int special_index; /* used when drawing */
461 /* quite boring functions */
463 static inline void for_each_line(char *b, void f(char *))
467 for (ps = b, pe = b; *pe; pe++) {
481 static void convert_escapes(char *buf)
483 char *p = buf, *s = buf;
490 } else if (*s == '\\') {
501 /* Prints anything normally printed with snprintf according to the current value
502 * of use_spacer. Actually slightly more flexible than snprintf, as you can
503 * safely specify the destination buffer as one of your inputs. */
504 int spaced_print(char *buf, int size, const char *format, int width, ...)
513 tempbuf = malloc(size * sizeof(char));
515 // Passes the varargs along to vsnprintf
516 va_start(argp, width);
517 vsnprintf(tempbuf, size, format, argp);
520 switch (use_spacer) {
522 len = snprintf(buf, size, "%s", tempbuf);
525 len = snprintf(buf, size, "%*s", width, tempbuf);
528 len = snprintf(buf, size, "%-*s", width, tempbuf);
535 /* print percentage values
537 * - i.e., unsigned values between 0 and 100
538 * - respect the value of pad_percents */
539 static int percent_print(char *buf, int size, unsigned value)
541 return spaced_print(buf, size, "%u", pad_percents, value);
544 /* converts from bytes to human readable format (K, M, G, T)
546 * The algorithm always divides by 1024, as unit-conversion of byte
547 * counts suggests. But for output length determination we need to
548 * compare with 1000 here, as we print in decimal form. */
549 static void human_readable(long long num, char *buf, int size)
551 const char **suffix = suffixes;
565 if (llabs(num) < 1000LL) {
566 spaced_print(buf, size, format, width, 0, (float)num, *suffix);
570 while (llabs(num / 1024) >= 1000LL && **(suffix + 2)) {
578 /* fnum should now be < 1000, so looks like 'AAA.BBBBB'
580 * The goal is to always have a significance of 3, by
581 * adjusting the decimal part of the number. Sample output:
585 * so the point of alignment resides between number and unit. The
586 * upside of this is that there is minimal padding necessary, though
587 * there should be a way to make alignment take place at the decimal
588 * dot (then with fixed width decimal part).
590 * Note the repdigits below: when given a precision value, printf()
591 * rounds the float to it, not just cuts off the remaining digits. So
592 * e.g. 99.95 with a precision of 1 gets 100.0, which again should be
593 * printed with a precision of 0. Yay. */
595 precision = 0; /* print 100-999 without decimal part */
597 precision = 1; /* print 10-99 with one decimal place */
599 precision = 2; /* print 0-9 with two decimal places */
601 spaced_print(buf, size, format, width, precision, fnum, *suffix);
604 /* global object list root element */
605 static struct text_object global_root_object;
607 static inline void read_exec(const char *data, char *buf, const int size)
609 FILE *fp = popen(data, "r");
610 int length = fread(buf, 1, size, fp);
614 if (length > 0 && buf[length - 1] == '\n') {
615 buf[length - 1] = '\0';
619 void *threaded_exec(void *) __attribute__((noreturn));
621 void *threaded_exec(void *arg)
624 struct text_object *obj = (struct text_object *)arg;
627 buff = malloc(text_buffer_size);
628 read_exec(obj->data.texeci.cmd, buff,
637 timed_thread_lock(obj->data.texeci.p_timed_thread);
638 strncpy(obj->data.texeci.buffer, buff, text_buffer_size);
639 timed_thread_unlock(obj->data.texeci.p_timed_thread);
641 if (timed_thread_test(obj->data.texeci.p_timed_thread, 0)) {
642 timed_thread_exit(obj->data.texeci.p_timed_thread);
648 static struct text_object *new_text_object_internal(void)
650 struct text_object *obj = malloc(sizeof(struct text_object));
651 memset(obj, 0, sizeof(struct text_object));
656 * Frees the list of text objects root points to. When internal = 1, it won't
657 * free global objects.
659 static void free_text_objects(struct text_object *root, int internal)
661 struct text_object *obj;
667 #define data obj->data
668 for (obj = root->prev; obj; obj = root->prev) {
669 root->prev = obj->prev;
675 #endif /* !__OpenBSD__ */
680 close(data.sysfs.fd);
682 #endif /* __linux__ */
688 free(data.tztime.tz);
689 free(data.tztime.fmt);
692 free(data.mboxscan.args);
693 free(data.mboxscan.output);
698 case OBJ_unseen_mails:
699 case OBJ_flagged_mails:
700 case OBJ_unflagged_mails:
701 case OBJ_forwarded_mails:
702 case OBJ_unforwarded_mails:
703 case OBJ_replied_mails:
704 case OBJ_unreplied_mails:
705 case OBJ_draft_mails:
706 case OBJ_trashed_mails:
707 free(data.local_mail.box);
709 case OBJ_imap_unseen:
714 case OBJ_imap_messages:
719 case OBJ_pop3_unseen:
731 free_text_objects(obj->sub, 1);
734 case OBJ_if_existing:
737 free(data.ifblock.s);
738 free(data.ifblock.str);
741 free(data.tail.logfile);
742 free(data.tail.buffer);
758 case OBJ_iconv_start:
763 case OBJ_disk_protect:
767 free(data.ifblock.s);
768 free(data.ifblock.str);
771 if (info.gw_info.iface) {
772 free(info.gw_info.iface);
773 info.gw_info.iface = 0;
775 if (info.gw_info.ip) {
776 free(info.gw_info.ip);
780 case OBJ_ioscheduler:
785 #if (defined(__FreeBSD__) || defined(__linux__))
787 free(data.ifblock.s);
788 free(data.ifblock.str);
791 case OBJ_xmms2_artist:
792 if (info.xmms2.artist) {
793 free(info.xmms2.artist);
794 info.xmms2.artist = 0;
797 case OBJ_xmms2_album:
798 if (info.xmms2.album) {
799 free(info.xmms2.album);
800 info.xmms2.album = 0;
803 case OBJ_xmms2_title:
804 if (info.xmms2.title) {
805 free(info.xmms2.title);
806 info.xmms2.title = 0;
809 case OBJ_xmms2_genre:
810 if (info.xmms2.genre) {
811 free(info.xmms2.genre);
812 info.xmms2.genre = 0;
815 case OBJ_xmms2_comment:
816 if (info.xmms2.comment) {
817 free(info.xmms2.comment);
818 info.xmms2.comment = 0;
822 if (info.xmms2.url) {
823 free(info.xmms2.url);
828 if (info.xmms2.date) {
829 free(info.xmms2.date);
833 case OBJ_xmms2_status:
834 if (info.xmms2.status) {
835 free(info.xmms2.status);
836 info.xmms2.status = 0;
839 case OBJ_xmms2_playlist:
840 if (info.xmms2.playlist) {
841 free(info.xmms2.playlist);
842 info.xmms2.playlist = 0;
845 case OBJ_xmms2_smart:
846 if (info.xmms2.artist) {
847 free(info.xmms2.artist);
848 info.xmms2.artist = 0;
850 if (info.xmms2.title) {
851 free(info.xmms2.title);
852 info.xmms2.title = 0;
854 if (info.xmms2.url) {
855 free(info.xmms2.url);
862 case OBJ_bmpx_artist:
866 case OBJ_bmpx_bitrate:
876 free(data.rss.action);
882 case OBJ_lua_read_parse:
890 #endif /* HAVE_LUA */
897 case OBJ_battery_short:
900 case OBJ_battery_time:
903 #endif /* !__OpenBSD__ */
911 free(data.execi.cmd);
912 free(data.execi.buffer);
915 free(data.texeci.cmd);
916 free(data.texeci.buffer);
924 if (info.first_process && !internal) {
925 free_all_processes();
926 info.first_process = NULL;
928 if (data.top.s) free(data.top.s);
932 free(data.hddtemp.dev);
933 free(data.hddtemp.addr);
934 if (data.hddtemp.temp)
935 free(data.hddtemp.temp);
938 case OBJ_entropy_avail:
939 case OBJ_entropy_poolsize:
941 case OBJ_entropy_bar:
945 if (info.users.names) {
946 free(info.users.names);
947 info.users.names = 0;
951 if (info.users.terms) {
952 free(info.users.terms);
953 info.users.terms = 0;
957 if (info.users.times) {
958 free(info.users.times);
959 info.users.times = 0;
964 case OBJ_smapi_bat_perc:
965 case OBJ_smapi_bat_temp:
966 case OBJ_smapi_bat_power:
969 case OBJ_if_smapi_bat_installed:
970 free(data.ifblock.s);
971 free(data.ifblock.str);
985 case OBJ_mpd_bitrate:
990 case OBJ_mpd_elapsed:
995 case OBJ_mpd_percent:
997 case OBJ_if_mpd_playing:
1005 case OBJ_moc_artist:
1008 case OBJ_moc_totaltime:
1009 case OBJ_moc_timeleft:
1010 case OBJ_moc_curtime:
1011 case OBJ_moc_bitrate:
1017 free(data.scroll.text);
1018 free_text_objects(obj->sub, 1);
1022 free(data.combine.left);
1023 free(data.combine.seperation);
1024 free(data.combine.right);
1025 free_text_objects(obj->sub, 1);
1030 case OBJ_apcupsd_name:
1031 case OBJ_apcupsd_model:
1032 case OBJ_apcupsd_upsmode:
1033 case OBJ_apcupsd_cable:
1034 case OBJ_apcupsd_status:
1035 case OBJ_apcupsd_linev:
1036 case OBJ_apcupsd_load:
1038 case OBJ_apcupsd_loadbar:
1039 case OBJ_apcupsd_loadgraph:
1040 case OBJ_apcupsd_loadgauge:
1042 case OBJ_apcupsd_charge:
1043 case OBJ_apcupsd_timeleft:
1044 case OBJ_apcupsd_temp:
1045 case OBJ_apcupsd_lastxfer:
1047 #endif /* APCUPSD */
1055 void scan_mixer_bar(const char *arg, int *a, int *w, int *h)
1060 if (arg && sscanf(arg, "%63s %n", buf1, &n) >= 1) {
1061 *a = mixer_init(buf1);
1062 scan_bar(arg + n, w, h);
1064 *a = mixer_init(NULL);
1065 scan_bar(arg, w, h);
1070 /* strip a leading /dev/ if any, following symlinks first
1072 * BEWARE: this function returns a pointer to static content
1073 * which gets overwritten in consecutive calls. I.e.:
1074 * this function is NOT reentrant.
1076 static const char *dev_name(const char *path)
1078 static char buf[255]; /* should be enough for pathnames */
1084 #define DEV_NAME(x) \
1085 x != NULL && strlen(x) > 5 && strncmp(x, "/dev/", 5) == 0 ? x + 5 : x
1086 if ((buflen = readlink(path, buf, 254)) == -1)
1087 return DEV_NAME(path);
1089 return DEV_NAME(buf);
1093 static int parse_top_args(const char *s, const char *arg, struct text_object *obj)
1098 if (obj->data.top.was_parsed) {
1101 obj->data.top.was_parsed = 1;
1103 if (arg && !obj->data.top.s) {
1104 obj->data.top.s = strndup(arg, text_buffer_size);
1107 need_mask |= (1 << INFO_TOP);
1110 obj->type = OBJ_top;
1112 } else if (strcmp(&s[3], "_mem") == EQUAL) {
1113 obj->type = OBJ_top_mem;
1115 } else if (strcmp(&s[3], "_time") == EQUAL) {
1116 obj->type = OBJ_top_time;
1119 ERR("Must be top, top_mem or top_time");
1124 ERR("top needs arguments");
1128 if (sscanf(arg, "%63s %i", buf, &n) == 2) {
1129 if (strcmp(buf, "name") == EQUAL) {
1130 obj->data.top.type = TOP_NAME;
1131 } else if (strcmp(buf, "cpu") == EQUAL) {
1132 obj->data.top.type = TOP_CPU;
1133 } else if (strcmp(buf, "pid") == EQUAL) {
1134 obj->data.top.type = TOP_PID;
1135 } else if (strcmp(buf, "mem") == EQUAL) {
1136 obj->data.top.type = TOP_MEM;
1137 } else if (strcmp(buf, "time") == EQUAL) {
1138 obj->data.top.type = TOP_TIME;
1139 } else if (strcmp(buf, "mem_res") == EQUAL) {
1140 obj->data.top.type = TOP_MEM_RES;
1141 } else if (strcmp(buf, "mem_vsize") == EQUAL) {
1142 obj->data.top.type = TOP_MEM_VSIZE;
1144 ERR("invalid type arg for top");
1145 ERR("must be one of: name, cpu, pid, mem, time, mem_res, mem_vsize");
1148 if (n < 1 || n > 10) {
1149 ERR("invalid num arg for top. Must be between 1 and 10.");
1152 obj->data.top.num = n - 1;
1155 ERR("invalid argument count for top");
1161 /* construct_text_object() creates a new text_object */
1162 static struct text_object *construct_text_object(const char *s,
1163 const char *arg, long line, char allow_threaded, void **ifblock_opaque)
1165 // struct text_object *obj = new_text_object();
1166 struct text_object *obj = new_text_object_internal();
1170 #define OBJ(a, n) if (strcmp(s, #a) == 0) { \
1171 obj->type = OBJ_##a; need_mask |= (1ULL << n); {
1172 #define OBJ_IF(a, n) if (strcmp(s, #a) == 0) { \
1173 obj->type = OBJ_##a; need_mask |= (1ULL << n); \
1174 obj_be_ifblock_if(ifblock_opaque, obj); {
1175 #define OBJ_THREAD(a, n) if (strcmp(s, #a) == 0 && allow_threaded) { \
1176 obj->type = OBJ_##a; need_mask |= (1ULL << n); {
1177 #define END } } else
1181 obj->type = OBJ_color;
1182 obj->data.l = get_x11_color(s);
1186 OBJ(freq, INFO_FREQ)
1189 obj->data.i = open_acpi_temperature(arg);
1190 END OBJ(acpiacadapter, 0)
1191 END OBJ(freq, INFO_FREQ)
1192 #endif /* !__OpenBSD__ */
1194 if (!arg || !isdigit(arg[0]) || strlen(arg) >= 2 || atoi(&arg[0]) == 0
1195 || (unsigned int) atoi(&arg[0]) > info.cpu_count) {
1196 obj->data.cpu_index = 1;
1197 /* ERR("freq: Invalid CPU number or you don't have that many CPUs! "
1198 "Displaying the clock for CPU 1."); */
1200 obj->data.cpu_index = atoi(&arg[0]);
1203 END OBJ(freq_g, INFO_FREQ)
1205 if (!arg || !isdigit(arg[0]) || strlen(arg) >= 2 || atoi(&arg[0]) == 0
1206 || (unsigned int) atoi(&arg[0]) > info.cpu_count) {
1207 obj->data.cpu_index = 1;
1208 /* ERR("freq_g: Invalid CPU number or you don't have that many "
1209 "CPUs! Displaying the clock for CPU 1."); */
1211 obj->data.cpu_index = atoi(&arg[0]);
1214 #if defined(__linux__)
1215 END OBJ(voltage_mv, 0)
1217 if (!arg || !isdigit(arg[0]) || strlen(arg) >= 2 || atoi(&arg[0]) == 0
1218 || (unsigned int) atoi(&arg[0]) > info.cpu_count) {
1219 obj->data.cpu_index = 1;
1220 /* ERR("voltage_mv: Invalid CPU number or you don't have that many "
1221 "CPUs! Displaying voltage for CPU 1."); */
1223 obj->data.cpu_index = atoi(&arg[0]);
1226 END OBJ(voltage_v, 0)
1228 if (!arg || !isdigit(arg[0]) || strlen(arg) >= 2 || atoi(&arg[0]) == 0
1229 || (unsigned int) atoi(&arg[0]) > info.cpu_count) {
1230 obj->data.cpu_index = 1;
1231 /* ERR("voltage_v: Invalid CPU number or you don't have that many "
1232 "CPUs! Displaying voltage for CPU 1."); */
1234 obj->data.cpu_index = atoi(&arg[0]);
1239 END OBJ(wireless_essid, INFO_NET)
1241 obj->data.net = get_net_stat(arg);
1243 CRIT_ERR("wireless_essid: needs an argument");
1245 END OBJ(wireless_mode, INFO_NET)
1247 obj->data.net = get_net_stat(arg);
1249 CRIT_ERR("wireless_mode: needs an argument");
1251 END OBJ(wireless_bitrate, INFO_NET)
1253 obj->data.net = get_net_stat(arg);
1255 CRIT_ERR("wireless_bitrate: needs an argument");
1257 END OBJ(wireless_ap, INFO_NET)
1259 obj->data.net = get_net_stat(arg);
1261 CRIT_ERR("wireless_ap: needs an argument");
1263 END OBJ(wireless_link_qual, INFO_NET)
1265 obj->data.net = get_net_stat(arg);
1267 CRIT_ERR("wireless_link_qual: needs an argument");
1269 END OBJ(wireless_link_qual_max, INFO_NET)
1271 obj->data.net = get_net_stat(arg);
1273 CRIT_ERR("wireless_link_qual_max: needs an argument");
1275 END OBJ(wireless_link_qual_perc, INFO_NET)
1277 obj->data.net = get_net_stat(arg);
1279 CRIT_ERR("wireless_link_qual_perc: needs an argument");
1281 END OBJ(wireless_link_bar, INFO_NET)
1283 arg = scan_bar(arg, &obj->a, &obj->b);
1284 obj->data.net = get_net_stat(arg);
1286 CRIT_ERR("wireless_link_bar: needs an argument");
1288 #endif /* HAVE_IWLIB */
1290 #endif /* __linux__ */
1298 sscanf(arg, "%63s", bat);
1300 strcpy(bat, "BAT0");
1302 obj->data.s = strndup(bat, text_buffer_size);
1303 END OBJ(battery_short, 0)
1307 sscanf(arg, "%63s", bat);
1309 strcpy(bat, "BAT0");
1311 obj->data.s = strndup(bat, text_buffer_size);
1312 END OBJ(battery_time, 0)
1316 sscanf(arg, "%63s", bat);
1318 strcpy(bat, "BAT0");
1320 obj->data.s = strndup(bat, text_buffer_size);
1321 END OBJ(battery_percent, 0)
1325 sscanf(arg, "%63s", bat);
1327 strcpy(bat, "BAT0");
1329 obj->data.s = strndup(bat, text_buffer_size);
1331 END OBJ(battery_bar, 0)
1335 arg = scan_bar(arg, &obj->a, &obj->b);
1336 sscanf(arg, "%63s", bat);
1338 strcpy(bat, "BAT0");
1340 obj->data.s = strndup(bat, text_buffer_size);
1342 #endif /* !__OpenBSD__ */
1344 #if defined(__linux__)
1345 END OBJ(disk_protect, 0)
1347 obj->data.s = strndup(dev_name(arg), text_buffer_size);
1349 CRIT_ERR("disk_protect needs an argument");
1350 END OBJ(i8k_version, INFO_I8K)
1351 END OBJ(i8k_bios, INFO_I8K)
1352 END OBJ(i8k_serial, INFO_I8K)
1353 END OBJ(i8k_cpu_temp, INFO_I8K)
1354 END OBJ(i8k_left_fan_status, INFO_I8K)
1355 END OBJ(i8k_right_fan_status, INFO_I8K)
1356 END OBJ(i8k_left_fan_rpm, INFO_I8K)
1357 END OBJ(i8k_right_fan_rpm, INFO_I8K)
1358 END OBJ(i8k_ac_status, INFO_I8K)
1359 END OBJ(i8k_buttons_status, INFO_I8K)
1362 END OBJ(ibm_temps, 0)
1364 CRIT_ERR("ibm_temps: needs an argument");
1366 if (!isdigit(arg[0]) || strlen(arg) >= 2 || atoi(&arg[0]) >= 8) {
1367 obj->data.sensor = 0;
1368 ERR("Invalid temperature sensor! Sensor number must be 0 to 7. "
1369 "Using 0 (CPU temp sensor).");
1371 obj->data.sensor = atoi(&arg[0]);
1372 END OBJ(ibm_volume, 0)
1373 END OBJ(ibm_brightness, 0)
1375 /* information from sony_laptop kernel module
1376 * /sys/devices/platform/sony-laptop */
1377 END OBJ(sony_fanspeed, 0)
1378 END OBJ_IF(if_gw, INFO_GW)
1379 END OBJ(ioscheduler, 0)
1381 CRIT_ERR("get_ioscheduler needs an argument (e.g. hda)");
1384 obj->data.s = strndup(dev_name(arg), text_buffer_size);
1385 END OBJ(laptop_mode, 0)
1386 END OBJ(pb_battery, 0)
1387 if (arg && strcmp(arg, "status") == EQUAL) {
1388 obj->data.i = PB_BATT_STATUS;
1389 } else if (arg && strcmp(arg, "percent") == EQUAL) {
1390 obj->data.i = PB_BATT_PERCENT;
1391 } else if (arg && strcmp(arg, "time") == EQUAL) {
1392 obj->data.i = PB_BATT_TIME;
1394 ERR("pb_battery: needs one argument: status, percent or time");
1399 #endif /* __linux__ */
1400 #if (defined(__FreeBSD__) || defined(__linux__))
1401 END OBJ_IF(if_up, 0)
1403 ERR("if_up needs an argument");
1404 obj->data.ifblock.s = 0;
1406 obj->data.ifblock.s = strndup(arg, text_buffer_size);
1408 #if defined(__OpenBSD__)
1409 END OBJ(obsd_sensors_temp, 0)
1411 CRIT_ERR("obsd_sensors_temp: needs an argument");
1413 if (!isdigit(arg[0]) || atoi(&arg[0]) < 0
1414 || atoi(&arg[0]) > OBSD_MAX_SENSORS - 1) {
1415 obj->data.sensor = 0;
1416 ERR("Invalid temperature sensor number!");
1418 obj->data.sensor = atoi(&arg[0]);
1419 END OBJ(obsd_sensors_fan, 0)
1421 CRIT_ERR("obsd_sensors_fan: needs 2 arguments (device and sensor "
1424 if (!isdigit(arg[0]) || atoi(&arg[0]) < 0
1425 || atoi(&arg[0]) > OBSD_MAX_SENSORS - 1) {
1426 obj->data.sensor = 0;
1427 ERR("Invalid fan sensor number!");
1429 obj->data.sensor = atoi(&arg[0]);
1430 END OBJ(obsd_sensors_volt, 0)
1432 CRIT_ERR("obsd_sensors_volt: needs 2 arguments (device and sensor "
1435 if (!isdigit(arg[0]) || atoi(&arg[0]) < 0
1436 || atoi(&arg[0]) > OBSD_MAX_SENSORS - 1) {
1437 obj->data.sensor = 0;
1438 ERR("Invalid voltage sensor number!");
1440 obj->data.sensor = atoi(&arg[0]);
1441 END OBJ(obsd_vendor, 0)
1442 END OBJ(obsd_product, 0)
1443 #endif /* __OpenBSD__ */
1444 END OBJ(buffers, INFO_BUFFERS)
1445 END OBJ(cached, INFO_BUFFERS)
1446 #define SCAN_CPU(__arg, __var) { \
1448 if (__arg && sscanf(__arg, " cpu%u %n", &__var, &__offset) > 0) \
1449 __arg += __offset; \
1453 END OBJ(cpu, INFO_CPU)
1454 SCAN_CPU(arg, obj->data.cpu_index);
1455 DBGP2("Adding $cpu for CPU %d", obj->data.cpu_index);
1457 END OBJ(cpugauge, INFO_CPU)
1458 SCAN_CPU(arg, obj->data.cpu_index);
1459 scan_gauge(arg, &obj->a, &obj->b);
1460 DBGP2("Adding $cpugauge for CPU %d", obj->data.cpu_index);
1461 END OBJ(cpubar, INFO_CPU)
1462 SCAN_CPU(arg, obj->data.cpu_index);
1463 scan_bar(arg, &obj->a, &obj->b);
1464 DBGP2("Adding $cpubar for CPU %d", obj->data.cpu_index);
1465 END OBJ(cpugraph, INFO_CPU)
1466 SCAN_CPU(arg, obj->data.cpu_index);
1467 scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
1468 &obj->e, &obj->char_a, &obj->char_b);
1469 DBGP2("Adding $cpugraph for CPU %d", obj->data.cpu_index);
1470 END OBJ(loadgraph, INFO_LOADAVG)
1471 char *buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
1472 &obj->e, &obj->char_a, &obj->char_b);
1476 r = sscanf(arg, "%d", &a);
1478 obj->data.loadavg[0] = (r >= 1) ? (unsigned char) a : 0;
1482 END OBJ(diskio, INFO_DISKIO)
1483 obj->data.diskio = prepare_diskio_stat(dev_name(arg));
1484 END OBJ(diskio_read, INFO_DISKIO)
1485 obj->data.diskio = prepare_diskio_stat(dev_name(arg));
1486 END OBJ(diskio_write, INFO_DISKIO)
1487 obj->data.diskio = prepare_diskio_stat(dev_name(arg));
1489 END OBJ(diskiograph, INFO_DISKIO)
1490 char *buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
1491 &obj->e, &obj->char_a, &obj->char_b);
1493 obj->data.diskio = prepare_diskio_stat(dev_name(buf));
1496 END OBJ(diskiograph_read, INFO_DISKIO)
1497 char *buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
1498 &obj->e, &obj->char_a, &obj->char_b);
1500 obj->data.diskio = prepare_diskio_stat(dev_name(buf));
1503 END OBJ(diskiograph_write, INFO_DISKIO)
1504 char *buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
1505 &obj->e, &obj->char_a, &obj->char_b);
1507 obj->data.diskio = prepare_diskio_stat(dev_name(buf));
1513 if (output_methods & TO_X) {
1514 obj->data.l = arg ? get_x11_color(arg) : default_fg_color;
1518 obj->data.l = color0;
1520 obj->data.l = color1;
1522 obj->data.l = color2;
1524 obj->data.l = color3;
1526 obj->data.l = color4;
1528 obj->data.l = color5;
1530 obj->data.l = color6;
1532 obj->data.l = color7;
1534 obj->data.l = color8;
1536 obj->data.l = color9;
1539 obj->data.s = scan_font(arg);
1541 END OBJ(conky_version, 0)
1542 END OBJ(conky_build_date, 0)
1543 END OBJ(conky_build_arch, 0)
1544 END OBJ(downspeed, INFO_NET)
1546 obj->data.net = get_net_stat(arg);
1548 CRIT_ERR("downspeed needs argument");
1550 END OBJ(downspeedf, INFO_NET)
1552 obj->data.net = get_net_stat(arg);
1554 CRIT_ERR("downspeedf needs argument");
1557 END OBJ(downspeedgraph, INFO_NET)
1558 char *buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
1559 &obj->e, &obj->char_a, &obj->char_b);
1561 // default to DEFAULTNETDEV
1562 buf = strndup(buf ? buf : "DEFAULTNETDEV", text_buffer_size);
1563 obj->data.net = get_net_stat(buf);
1567 obj_be_ifblock_else(ifblock_opaque, obj);
1569 obj_be_ifblock_endif(ifblock_opaque, obj);
1571 obj->data.s = strndup(arg ? arg : "", text_buffer_size);
1573 obj->data.s = strndup(arg ? arg : "", text_buffer_size);
1576 obj->data.s = strndup(arg ? arg : "", text_buffer_size);
1578 obj->data.s = strndup(arg ? arg : "", text_buffer_size);
1579 #define SIZE_DEFAULTS(arg) { \
1580 obj->a = default_##arg##_width; \
1581 obj->b = default_##arg##_height; \
1585 obj->data.s = strndup(arg ? arg : "", text_buffer_size);
1587 END OBJ(execgauge, 0)
1588 SIZE_DEFAULTS(gauge);
1589 obj->data.s = strndup(arg ? arg : "", text_buffer_size);
1590 END OBJ(execgraph, 0)
1591 SIZE_DEFAULTS(graph);
1592 obj->data.s = strndup(arg ? arg : "", text_buffer_size);
1593 END OBJ(execibar, 0)
1597 if (!arg || sscanf(arg, "%f %n", &obj->data.execi.interval, &n) <= 0) {
1600 ERR("${execibar <interval> command}");
1601 obj->type = OBJ_text;
1602 snprintf(buf, 256, "${%s}", s);
1603 obj->data.s = strndup(buf, text_buffer_size);
1605 obj->data.execi.cmd = strndup(arg + n, text_buffer_size);
1607 END OBJ(execigraph, 0)
1609 SIZE_DEFAULTS(graph);
1611 if (!arg || sscanf(arg, "%f %n", &obj->data.execi.interval, &n) <= 0) {
1614 ERR("${execigraph <interval> command}");
1615 obj->type = OBJ_text;
1616 snprintf(buf, 256, "${%s}", s);
1617 obj->data.s = strndup(buf, text_buffer_size);
1619 obj->data.execi.cmd = strndup(arg + n, text_buffer_size);
1621 END OBJ(execigauge, 0)
1623 SIZE_DEFAULTS(gauge);
1625 if (!arg || sscanf(arg, "%f %n", &obj->data.execi.interval, &n) <= 0) {
1628 ERR("${execigauge <interval> command}");
1629 obj->type = OBJ_text;
1630 snprintf(buf, 256, "${%s}", s);
1631 obj->data.s = strndup(buf, text_buffer_size);
1633 obj->data.execi.cmd = strndup(arg + n, text_buffer_size);
1639 if (!arg || sscanf(arg, "%f %n", &obj->data.execi.interval, &n) <= 0) {
1642 ERR("${execi <interval> command}");
1643 obj->type = OBJ_text;
1644 snprintf(buf, 256, "${%s}", s);
1645 obj->data.s = strndup(buf, text_buffer_size);
1647 obj->data.execi.cmd = strndup(arg + n, text_buffer_size);
1648 obj->data.execi.buffer = malloc(text_buffer_size);
1653 if (!arg || sscanf(arg, "%f %n", &obj->data.execi.interval, &n) <= 0) {
1656 ERR("${execi <interval> command}");
1657 obj->type = OBJ_text;
1658 snprintf(buf, 256, "${%s}", s);
1659 obj->data.s = strndup(buf, text_buffer_size);
1661 obj->data.execi.cmd = strndup(arg + n, text_buffer_size);
1662 obj->data.execi.buffer = malloc(text_buffer_size);
1664 END OBJ_THREAD(texeci, 0)
1667 if (!arg || sscanf(arg, "%f %n", &obj->data.texeci.interval, &n) <= 0) {
1670 ERR("${texeci <interval> command}");
1671 obj->type = OBJ_text;
1672 snprintf(buf, 256, "${%s}", s);
1673 obj->data.s = strndup(buf, text_buffer_size);
1675 obj->data.texeci.cmd = strndup(arg + n, text_buffer_size);
1676 obj->data.texeci.buffer = malloc(text_buffer_size);
1678 obj->data.texeci.p_timed_thread = NULL;
1679 END OBJ(pre_exec, 0)
1680 obj->type = OBJ_text;
1684 read_exec(arg, buf, sizeof(buf));
1685 obj->data.s = strndup(buf, text_buffer_size);
1687 obj->data.s = strndup("", text_buffer_size);
1691 END OBJ(fs_bar, INFO_FS)
1692 arg = scan_bar(arg, &obj->data.fsbar.w, &obj->data.fsbar.h);
1694 while (isspace(*arg)) {
1703 obj->data.fsbar.fs = prepare_fs_stat(arg);
1704 END OBJ(fs_bar_free, INFO_FS)
1705 arg = scan_bar(arg, &obj->data.fsbar.w, &obj->data.fsbar.h);
1707 while (isspace(*arg)) {
1717 obj->data.fsbar.fs = prepare_fs_stat(arg);
1719 END OBJ(fs_free, INFO_FS)
1723 obj->data.fs = prepare_fs_stat(arg);
1724 END OBJ(fs_used_perc, INFO_FS)
1728 obj->data.fs = prepare_fs_stat(arg);
1729 END OBJ(fs_free_perc, INFO_FS)
1733 obj->data.fs = prepare_fs_stat(arg);
1734 END OBJ(fs_size, INFO_FS)
1738 obj->data.fs = prepare_fs_stat(arg);
1739 END OBJ(fs_type, INFO_FS)
1743 obj->data.fs = prepare_fs_stat(arg);
1744 END OBJ(fs_used, INFO_FS)
1748 obj->data.fs = prepare_fs_stat(arg);
1750 obj->data.i = arg ? atoi(arg) : 1;
1751 END OBJ(nameserver, INFO_DNS)
1752 obj->data.i = arg ? atoi(arg) : 0;
1754 obj->data.i = arg ? atoi(arg) : 1;
1756 obj->data.i = arg ? atoi(arg) : 1;
1760 ERR("goto needs arguments");
1761 obj->type = OBJ_text;
1762 obj->data.s = strndup("${goto}", text_buffer_size);
1766 obj->data.i = atoi(arg);
1772 if (sscanf(arg, "%d %d", &a, &b) != 2) {
1773 sscanf(arg, "%d", &b);
1779 obj->data.pair.a = a;
1780 obj->data.pair.b = b;
1783 END OBJ(i2c, INFO_SYSFS)
1784 char buf1[64], buf2[64];
1785 float factor, offset;
1789 ERR("i2c needs arguments");
1790 obj->type = OBJ_text;
1791 // obj->data.s = strndup("${i2c}", text_buffer_size);
1795 #define HWMON_RESET() {\
1800 if (sscanf(arg, "%63s %d %f %f", buf2, &n, &factor, &offset) == 4) found = 1; else HWMON_RESET();
1801 if (!found && sscanf(arg, "%63s %63s %d %f %f", buf1, buf2, &n, &factor, &offset) == 5) found = 1; else if (!found) HWMON_RESET();
1802 if (!found && sscanf(arg, "%63s %63s %d", buf1, buf2, &n) == 3) found = 1; else if (!found) HWMON_RESET();
1803 if (!found && sscanf(arg, "%63s %d", buf2, &n) == 2) found = 1; else if (!found) HWMON_RESET();
1806 ERR("i2c failed to parse arguments");
1807 obj->type = OBJ_text;
1810 DBGP("parsed i2c args: '%s' '%s' %d %f %f\n", buf1, buf2, n, factor, offset);
1811 obj->data.sysfs.fd = open_i2c_sensor((*buf1) ? buf1 : 0, buf2, n,
1812 &obj->data.sysfs.arg, obj->data.sysfs.devtype);
1813 strncpy(obj->data.sysfs.type, buf2, 63);
1814 obj->data.sysfs.factor = factor;
1815 obj->data.sysfs.offset = offset;
1817 END OBJ(platform, INFO_SYSFS)
1818 char buf1[64], buf2[64];
1819 float factor, offset;
1823 ERR("platform needs arguments");
1824 obj->type = OBJ_text;
1828 if (sscanf(arg, "%63s %d %f %f", buf2, &n, &factor, &offset) == 4) found = 1; else HWMON_RESET();
1829 if (!found && sscanf(arg, "%63s %63s %d %f %f", buf1, buf2, &n, &factor, &offset) == 5) found = 1; else if (!found) HWMON_RESET();
1830 if (!found && sscanf(arg, "%63s %63s %d", buf1, buf2, &n) == 3) found = 1; else if (!found) HWMON_RESET();
1831 if (!found && sscanf(arg, "%63s %d", buf2, &n) == 2) found = 1; else if (!found) HWMON_RESET();
1834 ERR("platform failed to parse arguments");
1835 obj->type = OBJ_text;
1838 DBGP("parsed platform args: '%s' '%s' %d %f %f\n", buf1, buf2, n, factor, offset);
1839 obj->data.sysfs.fd = open_platform_sensor((*buf1) ? buf1 : 0, buf2, n,
1840 &obj->data.sysfs.arg, obj->data.sysfs.devtype);
1841 strncpy(obj->data.sysfs.type, buf2, 63);
1842 obj->data.sysfs.factor = factor;
1843 obj->data.sysfs.offset = offset;
1845 END OBJ(hwmon, INFO_SYSFS)
1846 char buf1[64], buf2[64];
1847 float factor, offset;
1851 ERR("hwmon needs argumanets");
1852 obj->type = OBJ_text;
1856 if (sscanf(arg, "%63s %d %f %f", buf2, &n, &factor, &offset) == 4) found = 1; else HWMON_RESET();
1857 if (!found && sscanf(arg, "%63s %63s %d %f %f", buf1, buf2, &n, &factor, &offset) == 5) found = 1; else if (!found) HWMON_RESET();
1858 if (!found && sscanf(arg, "%63s %63s %d", buf1, buf2, &n) == 3) found = 1; else if (!found) HWMON_RESET();
1859 if (!found && sscanf(arg, "%63s %d", buf2, &n) == 2) found = 1; else if (!found) HWMON_RESET();
1864 ERR("hwmon failed to parse arguments");
1865 obj->type = OBJ_text;
1868 DBGP("parsed hwmon args: '%s' '%s' %d %f %f\n", buf1, buf2, n, factor, offset);
1869 obj->data.sysfs.fd = open_hwmon_sensor((*buf1) ? buf1 : 0, buf2, n,
1870 &obj->data.sysfs.arg, obj->data.sysfs.devtype);
1871 strncpy(obj->data.sysfs.type, buf2, 63);
1872 obj->data.sysfs.factor = factor;
1873 obj->data.sysfs.offset = offset;
1875 #endif /* !__OpenBSD__ */
1878 /* we have three different types of top (top, top_mem and top_time). To
1879 * avoid having almost-same code three times, we have this special
1881 if (strncmp(s, "top", 3) == EQUAL) {
1882 if (!parse_top_args(s, arg, obj)) {
1885 } else OBJ(addr, INFO_NET)
1887 obj->data.net = get_net_stat(arg);
1889 CRIT_ERR("addr needs argument");
1891 #if defined(__linux__)
1892 END OBJ(addrs, INFO_NET)
1894 obj->data.net = get_net_stat(arg);
1896 CRIT_ERR("addrs needs argument");
1898 #endif /* __linux__ */
1900 if (init_tail_object(obj, arg)) {
1901 obj->type = OBJ_text;
1902 obj->data.s = strndup("${tail}", text_buffer_size);
1905 if (init_head_object(obj, arg)) {
1906 obj->type = OBJ_text;
1907 obj->data.s = strndup("${head}", text_buffer_size);
1911 obj->data.s = strndup(arg, text_buffer_size);
1913 CRIT_ERR("lines needs a argument");
1917 obj->data.s = strndup(arg, text_buffer_size);
1919 CRIT_ERR("words needs a argument");
1921 END OBJ(loadavg, INFO_LOADAVG)
1922 int a = 1, b = 2, c = 3, r = 3;
1925 r = sscanf(arg, "%d %d %d", &a, &b, &c);
1926 if (r >= 3 && (c < 1 || c > 3)) {
1929 if (r >= 2 && (b < 1 || b > 3)) {
1932 if (r >= 1 && (a < 1 || a > 3)) {
1936 obj->data.loadavg[0] = (r >= 1) ? (unsigned char) a : 0;
1937 obj->data.loadavg[1] = (r >= 2) ? (unsigned char) b : 0;
1938 obj->data.loadavg[2] = (r >= 3) ? (unsigned char) c : 0;
1939 END OBJ_IF(if_empty, 0)
1941 ERR("if_empty needs an argument");
1942 obj->data.ifblock.s = 0;
1944 obj->data.ifblock.s = strndup(arg, text_buffer_size);
1945 obj->sub = malloc(sizeof(struct text_object));
1946 extract_variable_text_internal(obj->sub,
1947 obj->data.ifblock.s, 0);
1949 END OBJ_IF(if_match, 0)
1951 ERR("if_match needs arguments");
1952 obj->data.ifblock.s = 0;
1954 obj->data.ifblock.s = strndup(arg, text_buffer_size);
1955 obj->sub = malloc(sizeof(struct text_object));
1956 extract_variable_text_internal(obj->sub,
1957 obj->data.ifblock.s, 0);
1959 END OBJ_IF(if_existing, 0)
1961 ERR("if_existing needs an argument or two");
1962 obj->data.ifblock.s = NULL;
1963 obj->data.ifblock.str = NULL;
1965 char buf1[256], buf2[256];
1966 int r = sscanf(arg, "%255s %255[^\n]", buf1, buf2);
1969 obj->data.ifblock.s = strndup(buf1, text_buffer_size);
1970 obj->data.ifblock.str = NULL;
1972 obj->data.ifblock.s = strndup(buf1, text_buffer_size);
1973 obj->data.ifblock.str = strndup(buf2, text_buffer_size);
1976 DBGP("if_existing: '%s' '%s'", obj->data.ifblock.s, obj->data.ifblock.str);
1977 END OBJ_IF(if_mounted, 0)
1979 ERR("if_mounted needs an argument");
1980 obj->data.ifblock.s = 0;
1982 obj->data.ifblock.s = strndup(arg, text_buffer_size);
1984 END OBJ_IF(if_running, 0)
1988 snprintf(buf, 256, "pidof %s >/dev/null", arg);
1989 obj->data.ifblock.s = strndup(buf, text_buffer_size);
1991 ERR("if_running needs an argument");
1992 obj->data.ifblock.s = 0;
1998 char box[256], dst[256];
2002 /* Kapil: Changed from MAIL_FILE to
2003 current_mail_spool since the latter
2004 is a copy of the former if undefined
2005 but the latter should take precedence
2007 strncpy(box, current_mail_spool, sizeof(box));
2009 if (sscanf(arg, "%s %f", box, &n1) != 2) {
2011 strncpy(box, arg, sizeof(box));
2015 variable_substitute(box, dst, sizeof(dst));
2016 obj->data.local_mail.box = strndup(dst, text_buffer_size);
2017 obj->data.local_mail.interval = n1;
2018 END OBJ(new_mails, 0)
2020 char box[256], dst[256];
2024 strncpy(box, current_mail_spool, sizeof(box));
2026 if (sscanf(arg, "%s %f", box, &n1) != 2) {
2028 strncpy(box, arg, sizeof(box));
2032 variable_substitute(box, dst, sizeof(dst));
2033 obj->data.local_mail.box = strndup(dst, text_buffer_size);
2034 obj->data.local_mail.interval = n1;
2035 END OBJ(seen_mails, 0)
2037 char box[256], dst[256];
2041 strncpy(box, current_mail_spool, sizeof(box));
2043 if (sscanf(arg, "%s %f", box, &n1) != 2) {
2045 strncpy(box, arg, sizeof(box));
2049 variable_substitute(box, dst, sizeof(dst));
2050 obj->data.local_mail.box = strndup(dst, text_buffer_size);
2051 obj->data.local_mail.interval = n1;
2052 END OBJ(unseen_mails, 0)
2054 char box[256], dst[256];
2058 strncpy(box, current_mail_spool, sizeof(box));
2060 if (sscanf(arg, "%s %f", box, &n1) != 2) {
2062 strncpy(box, arg, sizeof(box));
2066 variable_substitute(box, dst, sizeof(dst));
2067 obj->data.local_mail.box = strndup(dst, text_buffer_size);
2068 obj->data.local_mail.interval = n1;
2069 END OBJ(flagged_mails, 0)
2071 char box[256], dst[256];
2075 strncpy(box, current_mail_spool, sizeof(box));
2077 if (sscanf(arg, "%s %f", box, &n1) != 2) {
2079 strncpy(box, arg, sizeof(box));
2083 variable_substitute(box, dst, sizeof(dst));
2084 obj->data.local_mail.box = strndup(dst, text_buffer_size);
2085 obj->data.local_mail.interval = n1;
2086 END OBJ(unflagged_mails, 0)
2088 char box[256], dst[256];
2092 strncpy(box, current_mail_spool, sizeof(box));
2094 if (sscanf(arg, "%s %f", box, &n1) != 2) {
2096 strncpy(box, arg, sizeof(box));
2100 variable_substitute(box, dst, sizeof(dst));
2101 obj->data.local_mail.box = strndup(dst, text_buffer_size);
2102 obj->data.local_mail.interval = n1;
2103 END OBJ(forwarded_mails, 0)
2105 char box[256], dst[256];
2109 strncpy(box, current_mail_spool, sizeof(box));
2111 if (sscanf(arg, "%s %f", box, &n1) != 2) {
2113 strncpy(box, arg, sizeof(box));
2117 variable_substitute(box, dst, sizeof(dst));
2118 obj->data.local_mail.box = strndup(dst, text_buffer_size);
2119 obj->data.local_mail.interval = n1;
2120 END OBJ(unforwarded_mails, 0)
2122 char box[256], dst[256];
2126 strncpy(box, current_mail_spool, sizeof(box));
2128 if (sscanf(arg, "%s %f", box, &n1) != 2) {
2130 strncpy(box, arg, sizeof(box));
2134 variable_substitute(box, dst, sizeof(dst));
2135 obj->data.local_mail.box = strndup(dst, text_buffer_size);
2136 obj->data.local_mail.interval = n1;
2137 END OBJ(replied_mails, 0)
2139 char box[256], dst[256];
2143 strncpy(box, current_mail_spool, sizeof(box));
2145 if (sscanf(arg, "%s %f", box, &n1) != 2) {
2147 strncpy(box, arg, sizeof(box));
2151 variable_substitute(box, dst, sizeof(dst));
2152 obj->data.local_mail.box = strndup(dst, text_buffer_size);
2153 obj->data.local_mail.interval = n1;
2154 END OBJ(unreplied_mails, 0)
2156 char box[256], dst[256];
2160 strncpy(box, current_mail_spool, sizeof(box));
2162 if (sscanf(arg, "%s %f", box, &n1) != 2) {
2164 strncpy(box, arg, sizeof(box));
2168 variable_substitute(box, dst, sizeof(dst));
2169 obj->data.local_mail.box = strndup(dst, text_buffer_size);
2170 obj->data.local_mail.interval = n1;
2171 END OBJ(draft_mails, 0)
2173 char box[256], dst[256];
2177 strncpy(box, current_mail_spool, sizeof(box));
2179 if (sscanf(arg, "%s %f", box, &n1) != 2) {
2181 strncpy(box, arg, sizeof(box));
2185 variable_substitute(box, dst, sizeof(dst));
2186 obj->data.local_mail.box = strndup(dst, text_buffer_size);
2187 obj->data.local_mail.interval = n1;
2188 END OBJ(trashed_mails, 0)
2190 char box[256], dst[256];
2194 strncpy(box, current_mail_spool, sizeof(box));
2196 if (sscanf(arg, "%s %f", box, &n1) != 2) {
2198 strncpy(box, arg, sizeof(box));
2202 variable_substitute(box, dst, sizeof(dst));
2203 obj->data.local_mail.box = strndup(dst, text_buffer_size);
2204 obj->data.local_mail.interval = n1;
2205 END OBJ(mboxscan, 0)
2206 obj->data.mboxscan.args = (char *) malloc(text_buffer_size);
2207 obj->data.mboxscan.output = (char *) malloc(text_buffer_size);
2208 /* if '1' (in mboxscan.c) then there was SIGUSR1, hmm */
2209 obj->data.mboxscan.output[0] = 1;
2210 strncpy(obj->data.mboxscan.args, arg, text_buffer_size);
2211 END OBJ(mem, INFO_MEM)
2212 END OBJ(memeasyfree, INFO_MEM)
2213 END OBJ(memfree, INFO_MEM)
2214 END OBJ(memmax, INFO_MEM)
2215 END OBJ(memperc, INFO_MEM)
2217 END OBJ(memgauge, INFO_MEM)
2218 scan_gauge(arg, &obj->data.pair.a, &obj->data.pair.b);
2219 END OBJ(membar, INFO_MEM)
2220 scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
2221 END OBJ(memgraph, INFO_MEM)
2222 char *buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
2223 &obj->e, &obj->char_a, &obj->char_b);
2229 END OBJ(mixer, INFO_MIXER)
2230 obj->data.l = mixer_init(arg);
2231 END OBJ(mixerl, INFO_MIXER)
2232 obj->data.l = mixer_init(arg);
2233 END OBJ(mixerr, INFO_MIXER)
2234 obj->data.l = mixer_init(arg);
2236 END OBJ(mixerbar, INFO_MIXER)
2237 scan_mixer_bar(arg, &obj->data.mixerbar.l, &obj->data.mixerbar.w,
2238 &obj->data.mixerbar.h);
2239 END OBJ(mixerlbar, INFO_MIXER)
2240 scan_mixer_bar(arg, &obj->data.mixerbar.l, &obj->data.mixerbar.w,
2241 &obj->data.mixerbar.h);
2242 END OBJ(mixerrbar, INFO_MIXER)
2243 scan_mixer_bar(arg, &obj->data.mixerbar.l, &obj->data.mixerbar.w,
2244 &obj->data.mixerbar.h);
2246 END OBJ_IF(if_mixer_mute, INFO_MIXER)
2247 obj->data.ifblock.i = mixer_init(arg);
2249 END OBJ(monitor, INFO_X11)
2250 END OBJ(monitor_number, INFO_X11)
2252 END OBJ(nodename, 0)
2253 END OBJ(processes, INFO_PROCS)
2254 END OBJ(running_processes, INFO_RUN_PROCS)
2255 END OBJ(shadecolor, 0)
2257 obj->data.l = arg ? get_x11_color(arg) : default_bg_color;
2259 END OBJ(outlinecolor, 0)
2261 obj->data.l = arg ? get_x11_color(arg) : default_out_color;
2263 END OBJ(stippled_hr, 0)
2265 int a = stippled_borders, b = 1;
2268 if (sscanf(arg, "%d %d", &a, &b) != 2) {
2269 sscanf(arg, "%d", &b);
2275 obj->data.pair.a = a;
2276 obj->data.pair.b = b;
2278 END OBJ(swap, INFO_MEM)
2279 END OBJ(swapmax, INFO_MEM)
2280 END OBJ(swapperc, INFO_MEM)
2282 END OBJ(swapbar, INFO_MEM)
2283 scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
2287 obj->data.s = strndup(arg ? arg : "%F %T", text_buffer_size);
2289 obj->data.s = strndup(arg ? arg : "%F %T", text_buffer_size);
2291 char buf1[256], buf2[256], *fmt, *tz;
2295 int nArgs = sscanf(arg, "%255s %255[^\n]", buf1, buf2);
2305 obj->data.tztime.fmt = strndup(fmt ? fmt : "%F %T", text_buffer_size);
2306 obj->data.tztime.tz = tz ? strndup(tz, text_buffer_size) : NULL;
2308 END OBJ(iconv_start, 0)
2309 if (iconv_converting) {
2310 CRIT_ERR("You must stop your last iconv conversion before "
2311 "starting another");
2314 char iconv_from[CODEPAGE_LENGTH];
2315 char iconv_to[CODEPAGE_LENGTH];
2317 if (sscanf(arg, "%s %s", iconv_from, iconv_to) != 2) {
2318 CRIT_ERR("Invalid arguments for iconv_start");
2322 new_iconv = iconv_open(iconv_to, iconv_from);
2323 if (new_iconv == (iconv_t) (-1)) {
2324 ERR("Can't convert from %s to %s.", iconv_from, iconv_to);
2326 obj->a = register_iconv(&new_iconv);
2327 iconv_converting = 1;
2331 CRIT_ERR("Iconv requires arguments");
2333 END OBJ(iconv_stop, 0)
2334 iconv_converting = 0;
2337 END OBJ(totaldown, INFO_NET)
2339 obj->data.net = get_net_stat(arg);
2341 CRIT_ERR("totaldown needs argument");
2343 END OBJ(totalup, INFO_NET)
2344 obj->data.net = get_net_stat(arg);
2346 obj->data.net = get_net_stat(arg);
2348 CRIT_ERR("totalup needs argument");
2351 END OBJ_IF(if_updatenr, 0)
2352 obj->data.ifblock.i = arg ? atoi(arg) : 0;
2353 if(obj->data.ifblock.i == 0) CRIT_ERR("if_updatenr needs a number above 0 as argument");
2354 updatereset = obj->data.ifblock.i > updatereset ? obj->data.ifblock.i : updatereset;
2356 obj->data.i = arg ? atoi(arg) : 0;
2358 obj->data.i = arg ? atoi(arg) : 0;
2359 END OBJ(upspeed, INFO_NET)
2361 obj->data.net = get_net_stat(arg);
2363 CRIT_ERR("upspeed needs argument");
2365 END OBJ(upspeedf, INFO_NET)
2367 obj->data.net = get_net_stat(arg);
2369 CRIT_ERR("upspeedf needs argument");
2373 END OBJ(upspeedgraph, INFO_NET)
2374 char *buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
2375 &obj->e, &obj->char_a, &obj->char_b);
2377 // default to DEFAULTNETDEV
2378 buf = strndup(buf ? buf : "DEFAULTNETDEV", text_buffer_size);
2379 obj->data.net = get_net_stat(buf);
2382 END OBJ(uptime_short, INFO_UPTIME)
2383 END OBJ(uptime, INFO_UPTIME)
2384 END OBJ(user_names, INFO_USERS)
2385 END OBJ(user_times, INFO_USERS)
2386 END OBJ(user_terms, INFO_USERS)
2387 END OBJ(user_number, INFO_USERS)
2388 #if defined(__linux__)
2389 END OBJ(gw_iface, INFO_GW)
2390 END OBJ(gw_ip, INFO_GW)
2391 #endif /* !__linux__ */
2393 END OBJ(adt746xcpu, 0)
2394 END OBJ(adt746xfan, 0)
2395 #endif /* !__OpenBSD__ */
2396 #if (defined(__FreeBSD__) || defined(__FreeBSD_kernel__) \
2397 || defined(__OpenBSD__)) && (defined(i386) || defined(__i386__))
2398 END OBJ(apm_adapter, 0)
2399 END OBJ(apm_battery_life, 0)
2400 END OBJ(apm_battery_time, 0)
2401 #endif /* __FreeBSD__ */
2402 END OBJ_THREAD(imap_unseen, 0)
2405 obj->data.mail = parse_mail_args(IMAP_TYPE, arg);
2410 END OBJ_THREAD(imap_messages, 0)
2413 obj->data.mail = parse_mail_args(IMAP_TYPE, arg);
2418 END OBJ_THREAD(pop3_unseen, 0)
2421 obj->data.mail = parse_mail_args(POP3_TYPE, arg);
2426 END OBJ_THREAD(pop3_used, 0)
2429 obj->data.mail = parse_mail_args(POP3_TYPE, arg);
2437 obj->data.s = strndup(arg, text_buffer_size);
2439 ERR("smapi needs an argument");
2440 END OBJ_IF(if_smapi_bat_installed, 0)
2442 ERR("if_smapi_bat_installed needs an argument");
2443 obj->data.ifblock.s = 0;
2445 obj->data.ifblock.s = strndup(arg, text_buffer_size);
2446 END OBJ(smapi_bat_perc, 0)
2448 obj->data.s = strndup(arg, text_buffer_size);
2450 ERR("smapi_bat_perc needs an argument");
2451 END OBJ(smapi_bat_temp, 0)
2453 obj->data.s = strndup(arg, text_buffer_size);
2455 ERR("smapi_bat_temp needs an argument");
2456 END OBJ(smapi_bat_power, 0)
2458 obj->data.s = strndup(arg, text_buffer_size);
2460 ERR("smapi_bat_power needs an argument");
2461 END OBJ(smapi_bat_bar, 0)
2464 if(sscanf(arg, "%i %n", &obj->data.i, &cnt) <= 0) {
2465 ERR("first argument to smapi_bat_bar must be an integer value");
2469 arg = scan_bar(arg + cnt, &obj->a, &obj->b);
2472 ERR("smapi_bat_bar needs an argument");
2475 #define mpd_set_maxlen(name) \
2478 sscanf(arg, "%d", &i); \
2480 obj->data.i = i + 1; \
2482 ERR(#name ": invalid length argument"); \
2484 END OBJ(mpd_artist, INFO_MPD)
2485 mpd_set_maxlen(mpd_artist);
2487 END OBJ(mpd_title, INFO_MPD)
2488 mpd_set_maxlen(mpd_title);
2490 END OBJ(mpd_random, INFO_MPD) init_mpd();
2491 END OBJ(mpd_repeat, INFO_MPD) init_mpd();
2492 END OBJ(mpd_elapsed, INFO_MPD) init_mpd();
2493 END OBJ(mpd_length, INFO_MPD) init_mpd();
2494 END OBJ(mpd_track, INFO_MPD)
2495 mpd_set_maxlen(mpd_track);
2497 END OBJ(mpd_name, INFO_MPD)
2498 mpd_set_maxlen(mpd_name);
2500 END OBJ(mpd_file, INFO_MPD)
2501 mpd_set_maxlen(mpd_file);
2503 END OBJ(mpd_percent, INFO_MPD) init_mpd();
2504 END OBJ(mpd_album, INFO_MPD)
2505 mpd_set_maxlen(mpd_album);
2507 END OBJ(mpd_vol, INFO_MPD) init_mpd();
2508 END OBJ(mpd_bitrate, INFO_MPD) init_mpd();
2509 END OBJ(mpd_status, INFO_MPD) init_mpd();
2511 END OBJ(mpd_bar, INFO_MPD)
2512 scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
2515 END OBJ(mpd_smart, INFO_MPD)
2516 mpd_set_maxlen(mpd_smart);
2518 END OBJ_IF(if_mpd_playing, INFO_MPD)
2520 #undef mpd_set_maxlen
2523 END OBJ(moc_state, INFO_MOC)
2524 END OBJ(moc_file, INFO_MOC)
2525 END OBJ(moc_title, INFO_MOC)
2526 END OBJ(moc_artist, INFO_MOC)
2527 END OBJ(moc_song, INFO_MOC)
2528 END OBJ(moc_album, INFO_MOC)
2529 END OBJ(moc_totaltime, INFO_MOC)
2530 END OBJ(moc_timeleft, INFO_MOC)
2531 END OBJ(moc_curtime, INFO_MOC)
2532 END OBJ(moc_bitrate, INFO_MOC)
2533 END OBJ(moc_rate, INFO_MOC)
2536 END OBJ(xmms2_artist, INFO_XMMS2)
2537 END OBJ(xmms2_album, INFO_XMMS2)
2538 END OBJ(xmms2_title, INFO_XMMS2)
2539 END OBJ(xmms2_genre, INFO_XMMS2)
2540 END OBJ(xmms2_comment, INFO_XMMS2)
2541 END OBJ(xmms2_url, INFO_XMMS2)
2542 END OBJ(xmms2_tracknr, INFO_XMMS2)
2543 END OBJ(xmms2_bitrate, INFO_XMMS2)
2544 END OBJ(xmms2_date, INFO_XMMS2)
2545 END OBJ(xmms2_id, INFO_XMMS2)
2546 END OBJ(xmms2_duration, INFO_XMMS2)
2547 END OBJ(xmms2_elapsed, INFO_XMMS2)
2548 END OBJ(xmms2_size, INFO_XMMS2)
2549 END OBJ(xmms2_status, INFO_XMMS2)
2550 END OBJ(xmms2_percent, INFO_XMMS2)
2551 END OBJ(xmms2_bar, INFO_XMMS2)
2552 scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
2553 END OBJ(xmms2_smart, INFO_XMMS2)
2554 END OBJ(xmms2_playlist, INFO_XMMS2)
2555 END OBJ(xmms2_timesplayed, INFO_XMMS2)
2556 END OBJ_IF(if_xmms2_connected, INFO_XMMS2)
2559 END OBJ(audacious_status, INFO_AUDACIOUS)
2560 END OBJ(audacious_title, INFO_AUDACIOUS)
2562 sscanf(arg, "%d", &info.audacious.max_title_len);
2563 if (info.audacious.max_title_len > 0) {
2564 info.audacious.max_title_len++;
2566 CRIT_ERR("audacious_title: invalid length argument");
2569 END OBJ(audacious_length, INFO_AUDACIOUS)
2570 END OBJ(audacious_length_seconds, INFO_AUDACIOUS)
2571 END OBJ(audacious_position, INFO_AUDACIOUS)
2572 END OBJ(audacious_position_seconds, INFO_AUDACIOUS)
2573 END OBJ(audacious_bitrate, INFO_AUDACIOUS)
2574 END OBJ(audacious_frequency, INFO_AUDACIOUS)
2575 END OBJ(audacious_channels, INFO_AUDACIOUS)
2576 END OBJ(audacious_filename, INFO_AUDACIOUS)
2577 END OBJ(audacious_playlist_length, INFO_AUDACIOUS)
2578 END OBJ(audacious_playlist_position, INFO_AUDACIOUS)
2579 END OBJ(audacious_main_volume, INFO_AUDACIOUS)
2580 END OBJ(audacious_bar, INFO_AUDACIOUS)
2581 scan_bar(arg, &obj->a, &obj->b);
2584 END OBJ(bmpx_title, INFO_BMPX)
2585 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
2586 END OBJ(bmpx_artist, INFO_BMPX)
2587 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
2588 END OBJ(bmpx_album, INFO_BMPX)
2589 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
2590 END OBJ(bmpx_track, INFO_BMPX)
2591 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
2592 END OBJ(bmpx_uri, INFO_BMPX)
2593 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
2594 END OBJ(bmpx_bitrate, INFO_BMPX)
2595 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
2601 char *userid = (char *) malloc(20 * sizeof(char));
2602 char *apikey = (char *) malloc(64 * sizeof(char));
2603 char *charid = (char *) malloc(20 * sizeof(char));
2605 argc = sscanf(arg, "%20s %64s %20s", userid, apikey, charid);
2606 obj->data.eve.charid = charid;
2607 obj->data.eve.userid = userid;
2608 obj->data.eve.apikey = apikey;
2612 CRIT_ERR("eve needs arguments: <userid> <apikey> <characterid>");
2618 int argc, delay, act_par;
2619 unsigned int nrspaces = 0;
2620 char *uri = (char *) malloc(128 * sizeof(char));
2621 char *action = (char *) malloc(64 * sizeof(char));
2623 argc = sscanf(arg, "%127s %d %63s %d %u", uri, &delay, action,
2624 &act_par, &nrspaces);
2625 obj->data.rss.uri = uri;
2626 obj->data.rss.delay = delay;
2627 obj->data.rss.action = action;
2628 obj->data.rss.act_par = act_par;
2629 obj->data.rss.nrspaces = nrspaces;
2633 CRIT_ERR("rss needs arguments: <uri> <delay in minutes> <action> "
2634 "[act_par] [spaces in front]");
2640 obj->data.s = strndup(arg, text_buffer_size);
2642 CRIT_ERR("lua needs arguments: <function name> [function parameters]");
2644 END OBJ(lua_parse, 0)
2646 obj->data.s = strndup(arg, text_buffer_size);
2648 CRIT_ERR("lua_parse needs arguments: <function name> [function parameters]");
2650 END OBJ(lua_read_parse, 0)
2652 obj->data.s = strndup(arg, text_buffer_size);
2654 CRIT_ERR("lua_read_parse needs arguments: <function name> <string to pass>");
2659 arg = scan_bar(arg, &obj->a, &obj->b);
2661 obj->data.s = strndup(arg, text_buffer_size);
2663 CRIT_ERR("lua_bar needs arguments: <height>,<width> <function name> [function parameters]");
2666 CRIT_ERR("lua_bar needs arguments: <height>,<width> <function name> [function parameters]");
2668 END OBJ(lua_graph, 0)
2670 arg = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
2671 &obj->e, &obj->char_a, &obj->char_b);
2673 obj->data.s = strndup(arg, text_buffer_size);
2675 CRIT_ERR("lua_graph needs arguments: <\"normal\"|\"log\"> <height>,<width> <gradient colour 1> <gradient colour 2> <scale> <function name> [function parameters]");
2678 CRIT_ERR("lua_graph needs arguments: <\"normal\"|\"log\"> <height>,<width> <gradient colour 1> <gradient colour 2> <scale> <function name> [function parameters]");
2680 END OBJ(lua_gauge, 0)
2682 arg = scan_gauge(arg, &obj->a, &obj->b);
2684 obj->data.s = strndup(arg, text_buffer_size);
2686 CRIT_ERR("lua_gauge needs arguments: <height>,<width> <function name> [function parameters]");
2689 CRIT_ERR("lua_gauge needs arguments: <height>,<width> <function name> [function parameters]");
2692 #endif /* HAVE_LUA */
2695 if (scan_hddtemp(arg, &obj->data.hddtemp.dev,
2696 &obj->data.hddtemp.addr, &obj->data.hddtemp.port)) {
2697 ERR("hddtemp needs arguments");
2698 obj->type = OBJ_text;
2699 obj->data.s = strndup("${hddtemp}", text_buffer_size);
2700 obj->data.hddtemp.update_time = 0;
2702 obj->data.hddtemp.temp = NULL;
2704 #ifdef TCP_PORT_MONITOR
2705 END OBJ(tcp_portmon, INFO_TCP_PORT_MONITOR)
2706 tcp_portmon_init(arg, &obj->data.tcp_port_monitor);
2708 END OBJ(entropy_avail, INFO_ENTROPY)
2709 END OBJ(entropy_poolsize, INFO_ENTROPY)
2711 END OBJ(entropy_bar, INFO_ENTROPY)
2712 scan_bar(arg, &obj->a, &obj->b);
2717 obj->data.scroll.step = 1;
2718 if (arg && sscanf(arg, "%u %n", &obj->data.scroll.show, &n1) > 0) {
2719 if (sscanf(arg + n1, "%u %n", &obj->data.scroll.step, &n2) > 0)
2721 obj->data.scroll.text = strndup(arg + n1, text_buffer_size);
2722 obj->data.scroll.start = 0;
2723 obj->sub = malloc(sizeof(struct text_object));
2724 extract_variable_text_internal(obj->sub,
2725 obj->data.scroll.text, 0);
2727 CRIT_ERR("scroll needs arguments: <length> [<step>] <text>");
2732 unsigned int indenting = 0; //vars can be used as args for other vars
2735 startvar[0] = endvar[0] = startvar[1] = endvar[1] = -1;
2737 for(i=0; arg[i] != 0 && j < 2; i++) {
2738 if(startvar[j] == -1) {
2742 }else if(endvar[j] == -1) {
2745 }else if(arg[i] == '}') {
2748 if (indenting == 0 && arg[i+1] < 48) { //<48 has 0, $, and the most used chars not used in varnames but not { or }
2754 if(startvar[0] >= 0 && endvar[0] >= 0 && startvar[1] >= 0 && endvar[1] >= 0) {
2755 obj->data.combine.left=malloc(endvar[0]-startvar[0]+1);
2756 obj->data.combine.seperation=malloc(startvar[1]-endvar[0]+1);
2757 obj->data.combine.right=malloc(endvar[1]-startvar[1]+1);
2758 strncpy(obj->data.combine.left, arg+startvar[0], endvar[0]-startvar[0]); obj->data.combine.left[endvar[0]-startvar[0]]=0;
2759 strncpy(obj->data.combine.seperation, arg+endvar[0], startvar[1]-endvar[0]); obj->data.combine.seperation[startvar[1]-endvar[0]]=0;
2760 strncpy(obj->data.combine.right, arg+startvar[1], endvar[1]-startvar[1]); obj->data.combine.right[endvar[1]-startvar[1]]=0;
2761 obj->sub = malloc(sizeof(struct text_object));
2762 extract_variable_text_internal(obj->sub, obj->data.combine.left, 0);
2763 obj->sub->sub = malloc(sizeof(struct text_object));
2764 extract_variable_text_internal(obj->sub->sub, obj->data.combine.right, 0);
2766 CRIT_ERR("combine needs arguments: <text1> <text2>");
2769 CRIT_ERR("combine needs arguments: <text1> <text2>");
2774 CRIT_ERR("nvidia needs an argument\n");
2775 } else if (set_nvidia_type(&obj->data.nvidia, arg)) {
2776 CRIT_ERR("nvidia: invalid argument"
2777 " specified: '%s'\n", arg);
2782 END OBJ(apcupsd, INFO_APCUPSD)
2786 if (sscanf(arg, "%63s %d", host, &port) != 2) {
2787 CRIT_ERR("apcupsd needs arguments: <host> <port>");
2789 info.apcupsd.port = htons(port);
2790 strncpy(info.apcupsd.host, host, sizeof(info.apcupsd.host));
2793 CRIT_ERR("apcupsd needs arguments: <host> <port>");
2795 END OBJ(apcupsd_name, INFO_APCUPSD)
2796 END OBJ(apcupsd_model, INFO_APCUPSD)
2797 END OBJ(apcupsd_upsmode, INFO_APCUPSD)
2798 END OBJ(apcupsd_cable, INFO_APCUPSD)
2799 END OBJ(apcupsd_status, INFO_APCUPSD)
2800 END OBJ(apcupsd_linev, INFO_APCUPSD)
2801 END OBJ(apcupsd_load, INFO_APCUPSD)
2803 END OBJ(apcupsd_loadbar, INFO_APCUPSD)
2804 scan_bar(arg, &obj->a, &obj->b);
2805 END OBJ(apcupsd_loadgraph, INFO_APCUPSD)
2806 char* buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
2807 &obj->e, &obj->char_a, &obj->char_b);
2809 END OBJ(apcupsd_loadgauge, INFO_APCUPSD)
2810 scan_gauge(arg, &obj->a, &obj->b);
2812 END OBJ(apcupsd_charge, INFO_APCUPSD)
2813 END OBJ(apcupsd_timeleft, INFO_APCUPSD)
2814 END OBJ(apcupsd_temp, INFO_APCUPSD)
2815 END OBJ(apcupsd_lastxfer, INFO_APCUPSD)
2816 #endif /* APCUPSD */
2820 ERR("unknown variable %s", s);
2821 obj->type = OBJ_text;
2822 snprintf(buf, 256, "${%s}", s);
2823 obj->data.s = strndup(buf, text_buffer_size);
2830 static struct text_object *create_plain_text(const char *s)
2832 struct text_object *obj;
2834 if (s == NULL || *s == '\0') {
2838 obj = new_text_object_internal();
2840 obj->type = OBJ_text;
2841 obj->data.s = strndup(s, text_buffer_size);
2845 /* backslash_escape - do the actual substitution task for template objects
2847 * The field templates is used for substituting the \N occurences. Set it to
2848 * NULL to leave them as they are.
2850 static char *backslash_escape(const char *src, char **templates, unsigned int template_count)
2854 unsigned int dup_idx = 0, dup_len;
2856 dup_len = strlen(src) + 1;
2857 src_dup = malloc(dup_len * sizeof(char));
2865 if (*(p + 1) == '\\') {
2866 src_dup[dup_idx++] = '\\';
2868 } else if (*(p + 1) == ' ') {
2869 src_dup[dup_idx++] = ' ';
2871 } else if (*(p + 1) == 'n') {
2872 src_dup[dup_idx++] = '\n';
2874 } else if (templates) {
2875 unsigned int tmpl_num;
2877 if ((sscanf(p + 1, "%u%n", &tmpl_num, &digits) <= 0) ||
2878 (tmpl_num > template_count))
2880 dup_len += strlen(templates[tmpl_num - 1]);
2881 src_dup = realloc(src_dup, dup_len * sizeof(char));
2882 sprintf(src_dup + dup_idx, "%s", templates[tmpl_num - 1]);
2883 dup_idx += strlen(templates[tmpl_num - 1]);
2888 src_dup[dup_idx++] = *p;
2893 src_dup[dup_idx] = '\0';
2894 src_dup = realloc(src_dup, (strlen(src_dup) + 1) * sizeof(char));
2898 /* handle_template_object - core logic of the template object
2900 * use config variables like this:
2901 * template1 = "$\1\2"
2902 * template2 = "\1: ${fs_bar 4,100 \2} ${fs_used \2} / ${fs_size \2}"
2904 * and use them like this:
2905 * ${template1 node name}
2906 * ${template2 root /}
2907 * ${template2 cdrom /mnt/cdrom}
2909 static char *handle_template(const char *tmpl, const char *args)
2911 char *args_dup, *p, *p_old;
2912 char **argsp = NULL;
2913 unsigned int argcnt = 0, template_idx, i;
2916 if ((sscanf(tmpl, "template%u", &template_idx) != 1) ||
2920 args_dup = strdup(args);
2923 while (*p && (*p == ' ' && *(p - 1) != '\\'))
2925 if (*(p - 1) == '\\')
2928 while (*p && (*p != ' ' || *(p - 1) == '\\'))
2934 argsp = realloc(argsp, ++argcnt * sizeof(char *));
2935 argsp[argcnt - 1] = p_old;
2937 for (i = 0; i < argcnt; i++) {
2939 tmp = backslash_escape(argsp[i], NULL, 0);
2940 DBGP2("%s: substituted arg '%s' to '%s'", tmpl, argsp[i], tmp);
2944 eval_text = backslash_escape(template[template_idx], argsp, argcnt);
2945 DBGP("substituted %s, output is '%s'", tmpl, eval_text);
2947 for (i = 0; i < argcnt; i++)
2953 static char *find_and_replace_templates(const char *inbuf)
2955 char *outbuf, *indup, *p, *o, *templ, *args, *tmpl_out;
2958 outlen = strlen(inbuf) + 1;
2959 o = outbuf = calloc(outlen, sizeof(char));
2960 memset(outbuf, 0, outlen * sizeof(char));
2962 p = indup = strdup(inbuf);
2964 while (*p && *p != '$')
2970 if (strncmp(p, "$template", 9) && strncmp(p, "${template", 10)) {
2975 if (*(p + 1) == '{') {
2997 tmpl_out = handle_template(templ, args);
2999 outlen += strlen(tmpl_out);
3000 outbuf = realloc(outbuf, outlen * sizeof(char));
3001 strcat (outbuf, tmpl_out);
3003 o = outbuf + strlen(outbuf);
3005 ERR("failed to handle template '%s' with args '%s'", templ, args);
3009 outbuf = realloc(outbuf, (strlen(outbuf) + 1) * sizeof(char));
3014 static int text_contains_templates(const char *text)
3016 if (strcasestr(text, "${template") != NULL)
3018 if (strcasestr(text, "$template") != NULL)
3023 static void strfold(char *start, int count)
3026 for (curplace = start + count; *curplace != 0; curplace++) {
3027 *(curplace - count) = *curplace;
3029 *(curplace - count - 1) = 0;
3032 static size_t remove_comments(char *string)
3034 char *curplace, *curplace2;
3036 for (curplace = string; *curplace != 0; curplace++) {
3037 if (*curplace == '\\' && *(curplace + 1) == '#') {
3038 // strcpy can't be used for overlapping strings
3039 strfold(curplace, 1);
3041 } else if (*curplace == '#') {
3042 // remove everything until we hit a '\n'
3043 curplace2 = curplace;
3044 while (*curplace2) {
3046 if (*curplace2 == '\n' &&
3047 *(curplace2 + 1) != '#') break;
3050 strfold(curplace, curplace2 - curplace);
3051 folded += curplace2 - curplace;
3060 static int extract_variable_text_internal(struct text_object *retval, const char *const_p, char allow_threaded)
3062 struct text_object *obj;
3063 char *p, *s, *orig_p;
3065 void *ifblock_opaque = NULL;
3070 p = strndup(const_p, max_user_text - 1);
3071 while (text_contains_templates(p)) {
3073 tmp = find_and_replace_templates(p);
3079 if (strcmp(p, const_p)) {
3080 DBGP("replaced all templates in text: input is\n'%s'\noutput is\n'%s'", const_p, p);
3082 DBGP("no templates to replace");
3085 memset(retval, 0, sizeof(struct text_object));
3087 line = global_text_lines;
3095 obj = create_plain_text(s);
3097 append_object(retval, obj);
3107 /* variable is either $foo or ${foo} */
3109 unsigned int brl = 1, brr = 0;
3113 while (*p && brl != brr) {
3128 while (*p && (isalnum((int) *p) || *p == '_')) {
3133 /* copy variable to buffer */
3134 len = (p - s > 255) ? 255 : (p - s);
3135 strncpy(buf, s, len);
3143 /* search for variable in environment */
3147 obj = create_plain_text(var);
3149 append_object(retval, obj);
3154 /* if variable wasn't found in environment, use some special */
3159 if (strchr(buf, ' ')) {
3160 arg = strchr(buf, ' ');
3163 while (isspace((int) *arg)) {
3171 /* lowercase variable name */
3174 *tmp_p = tolower(*tmp_p);
3178 obj = construct_text_object(buf, arg,
3179 line, allow_threaded,
3182 append_object(retval, obj);
3186 obj = create_plain_text("$");
3189 append_object(retval, obj);
3192 } else if (*p == '#') {
3198 obj = create_plain_text(s);
3200 append_object(retval, obj);
3203 if (!ifblock_stack_empty(&ifblock_opaque)) {
3204 ERR("one or more $endif's are missing");
3211 static void extract_variable_text(const char *p)
3213 free_text_objects(&global_root_object, 0);
3227 extract_variable_text_internal(&global_root_object, p, 1);
3230 int parse_conky_vars(struct text_object *root, char *txt, char *p, struct information *cur)
3232 extract_variable_text_internal(root, txt, 0);
3233 generate_text_internal(p, max_user_text, *root, cur);
3237 static inline struct mail_s *ensure_mail_thread(struct text_object *obj,
3238 void *thread(void *), const char *text)
3240 if (obj->char_b && info.mail) {
3241 // this means we use info
3242 if (!info.mail->p_timed_thread) {
3243 info.mail->p_timed_thread =
3244 timed_thread_create(thread,
3245 (void *) info.mail, info.mail->interval * 1000000);
3246 if (!info.mail->p_timed_thread) {
3247 ERR("Error creating %s timed thread", text);
3249 timed_thread_register(info.mail->p_timed_thread,
3250 &info.mail->p_timed_thread);
3251 if (timed_thread_run(info.mail->p_timed_thread)) {
3252 ERR("Error running %s timed thread", text);
3256 } else if (obj->data.mail) {
3257 // this means we use obj
3258 if (!obj->data.mail->p_timed_thread) {
3259 obj->data.mail->p_timed_thread =
3260 timed_thread_create(thread,
3261 (void *) obj->data.mail,
3262 obj->data.mail->interval * 1000000);
3263 if (!obj->data.mail->p_timed_thread) {
3264 ERR("Error creating %s timed thread", text);
3266 timed_thread_register(obj->data.mail->p_timed_thread,
3267 &obj->data.mail->p_timed_thread);
3268 if (timed_thread_run(obj->data.mail->p_timed_thread)) {
3269 ERR("Error running %s timed thread", text);
3272 return obj->data.mail;
3273 } else if (!obj->a) {
3274 // something is wrong, warn once then stop
3275 ERR("There's a problem with your mail settings. "
3276 "Check that the global mail settings are properly defined"
3277 " (line %li).", obj->line);
3283 char *format_time(unsigned long timeval, const int width)
3286 unsigned long nt; // narrow time, for speed on 32-bit
3287 unsigned cc; // centiseconds
3288 unsigned nn; // multi-purpose whatever
3291 cc = nt % 100; // centiseconds past second
3292 nt /= 100; // total seconds
3293 nn = nt % 60; // seconds past the minute
3294 nt /= 60; // total minutes
3295 if (width >= snprintf(buf, sizeof buf, "%lu:%02u.%02u",
3297 return strndup(buf, text_buffer_size);
3299 if (width >= snprintf(buf, sizeof buf, "%lu:%02u", nt, nn)) {
3300 return strndup(buf, text_buffer_size);
3302 nn = nt % 60; // minutes past the hour
3303 nt /= 60; // total hours
3304 if (width >= snprintf(buf, sizeof buf, "%lu,%02u", nt, nn)) {
3305 return strndup(buf, text_buffer_size);
3307 nn = nt; // now also hours
3308 if (width >= snprintf(buf, sizeof buf, "%uh", nn)) {
3309 return strndup(buf, text_buffer_size);
3311 nn /= 24; // now days
3312 if (width >= snprintf(buf, sizeof buf, "%ud", nn)) {
3313 return strndup(buf, text_buffer_size);
3315 nn /= 7; // now weeks
3316 if (width >= snprintf(buf, sizeof buf, "%uw", nn)) {
3317 return strndup(buf, text_buffer_size);
3319 // well shoot, this outta' fit...
3320 return strndup("<inf>", text_buffer_size);
3323 //remove backspaced chars, example: "dog^H^H^Hcat" becomes "cat"
3324 //string has to end with \0 and it's length should fit in a int
3326 void remove_deleted_chars(char *string){
3328 while(string[i] != 0){
3329 if(string[i] == BACKSPACE){
3331 strcpy( &(string[i-1]), &(string[i+1]) );
3333 }else strcpy( &(string[i]), &(string[i+1]) ); //necessary for ^H's at the start of a string
3338 static inline void format_media_player_time(char *buf, const int size,
3341 int days, hours, minutes;
3343 days = seconds / (24 * 60 * 60);
3344 seconds %= (24 * 60 * 60);
3345 hours = seconds / (60 * 60);
3346 seconds %= (60 * 60);
3347 minutes = seconds / 60;
3351 snprintf(buf, size, "%i days %i:%02i:%02i", days,
3352 hours, minutes, seconds);
3353 } else if (hours > 0) {
3354 snprintf(buf, size, "%i:%02i:%02i", hours, minutes,
3357 snprintf(buf, size, "%i:%02i", minutes, seconds);
3361 static inline double get_barnum(char *buf)
3373 if (sscanf(buf, "%lf", &barnum) == 0) {
3374 ERR("reading exec value failed (perhaps it's not the "
3375 "correct format?)");
3378 if (barnum > 100.0 || barnum < 0.0) {
3379 ERR("your exec value is not between 0 and 100, "
3380 "therefore it will be ignored");
3386 static void generate_text_internal(char *p, int p_max_size,
3387 struct text_object root, struct information *cur)
3389 struct text_object *obj;
3391 /* for the OBJ_top* handler */
3392 struct process **needed = 0;
3395 char buff_in[p_max_size];
3397 iconv_converting = 0;
3402 while (obj && p_max_size > 0) {
3403 needed = 0; // reset for top stuff
3405 /* IFBLOCK jumping algorithm
3407 * This is easier as it looks like:
3408 * - each IF checks it's condition
3409 * - on FALSE: call DO_JUMP
3410 * - on TRUE: don't care
3411 * - each ELSE calls DO_JUMP unconditionally
3412 * - each ENDIF is silently being ignored
3415 * DO_JUMP overwrites the "obj" variable of the loop and sets it to the target
3416 * (i.e. the corresponding ELSE or ENDIF). After that, processing for the given
3417 * object can continue, free()ing stuff e.g., then the for-loop does the rest: as
3418 * regularly, "obj" is being updated to point to obj->next, so object parsing
3419 * continues right after the corresponding ELSE or ENDIF. This means that if we
3420 * find an ELSE, it's corresponding IF must not have jumped, so we need to jump
3421 * always. If we encounter an ENDIF, it's corresponding IF or ELSE has not
3422 * jumped, and there is nothing to do.
3426 obj = obj->data.ifblock.next; \
3429 #define OBJ(a) break; case OBJ_##a:
3431 switch (obj->type) {
3433 ERR("not implemented obj type %d", obj->type);
3436 temp_print(p, p_max_size, get_acpi_temperature(obj->data.i), TEMP_CELSIUS);
3438 #endif /* !__OpenBSD__ */
3441 obj->a = get_freq(p, p_max_size, "%.0f", 1,
3442 obj->data.cpu_index);
3448 obj->a = get_freq(p, p_max_size, "%'.2f", 1000,
3449 obj->data.cpu_index);
3451 /* OpenBSD has no such flag (SUSv2) */
3452 obj->a = get_freq(p, p_max_size, "%.2f", 1000,
3453 obj->data.cpu_index);
3457 #if defined(__linux__)
3460 obj->a = get_voltage(p, p_max_size, "%.0f", 1,
3461 obj->data.cpu_index);
3466 obj->a = get_voltage(p, p_max_size, "%'.3f", 1000,
3467 obj->data.cpu_index);
3472 OBJ(wireless_essid) {
3473 snprintf(p, p_max_size, "%s", obj->data.net->essid);
3475 OBJ(wireless_mode) {
3476 snprintf(p, p_max_size, "%s", obj->data.net->mode);
3478 OBJ(wireless_bitrate) {
3479 snprintf(p, p_max_size, "%s", obj->data.net->bitrate);
3482 snprintf(p, p_max_size, "%s", obj->data.net->ap);
3484 OBJ(wireless_link_qual) {
3485 spaced_print(p, p_max_size, "%d", 4,
3486 obj->data.net->link_qual);
3488 OBJ(wireless_link_qual_max) {
3489 spaced_print(p, p_max_size, "%d", 4,
3490 obj->data.net->link_qual_max);
3492 OBJ(wireless_link_qual_perc) {
3493 if (obj->data.net->link_qual_max > 0) {
3494 spaced_print(p, p_max_size, "%.0f", 5,
3495 (double) obj->data.net->link_qual /
3496 obj->data.net->link_qual_max * 100);
3498 spaced_print(p, p_max_size, "unk", 5);
3501 OBJ(wireless_link_bar) {
3502 new_bar(p, obj->a, obj->b, ((double) obj->data.net->link_qual /
3503 obj->data.net->link_qual_max) * 255.0);
3505 #endif /* HAVE_IWLIB */
3507 #endif /* __linux__ */
3511 get_adt746x_cpu(p, p_max_size);
3514 get_adt746x_fan(p, p_max_size);
3517 get_acpi_fan(p, p_max_size);
3519 OBJ(acpiacadapter) {
3520 get_acpi_ac_adapter(p, p_max_size);
3523 get_battery_stuff(p, p_max_size, obj->data.s, BATTERY_STATUS);
3526 get_battery_stuff(p, p_max_size, obj->data.s, BATTERY_TIME);
3528 OBJ(battery_percent) {
3529 percent_print(p, p_max_size, get_battery_perct(obj->data.s));
3533 new_bar(p, obj->a, obj->b, get_battery_perct_bar(obj->data.s));
3536 OBJ(battery_short) {
3537 get_battery_short_status(p, p_max_size, obj->data.s);
3539 #endif /* __OpenBSD__ */
3542 human_readable(cur->buffers * 1024, p, 255);
3545 human_readable(cur->cached * 1024, p, 255);
3548 if (obj->data.cpu_index > info.cpu_count) {
3549 ERR("obj->data.cpu_index %i info.cpu_count %i",
3550 obj->data.cpu_index, info.cpu_count);
3551 CRIT_ERR("attempting to use more CPUs than you have!");
3553 percent_print(p, p_max_size,
3554 round_to_int(cur->cpu_usage[obj->data.cpu_index] * 100.0));
3558 new_gauge(p, obj->a, obj->b,
3559 round_to_int(cur->cpu_usage[obj->data.cpu_index] * 255.0));
3561 new_bar(p, obj->a, obj->b,
3562 round_to_int(cur->cpu_usage[obj->data.cpu_index] * 255.0));
3565 new_graph(p, obj->a, obj->b, obj->c, obj->d,
3566 round_to_int(cur->cpu_usage[obj->data.cpu_index] * 100),
3567 100, 1, obj->char_a, obj->char_b);
3570 new_graph(p, obj->a, obj->b, obj->c, obj->d, cur->loadavg[0],
3571 obj->e, 1, obj->char_a, obj->char_b);
3574 new_fg(p, obj->data.l);
3607 OBJ(conky_version) {
3608 snprintf(p, p_max_size, "%s", VERSION);
3610 OBJ(conky_build_date) {
3611 snprintf(p, p_max_size, "%s", BUILD_DATE);
3613 OBJ(conky_build_arch) {
3614 snprintf(p, p_max_size, "%s", BUILD_ARCH);
3616 #if defined(__linux__)
3618 snprintf(p, p_max_size, "%s",
3619 get_disk_protect_queue(obj->data.s));
3622 snprintf(p, p_max_size, "%s", i8k.version);
3625 snprintf(p, p_max_size, "%s", i8k.bios);
3628 snprintf(p, p_max_size, "%s", i8k.serial);
3633 sscanf(i8k.cpu_temp, "%d", &cpu_temp);
3634 temp_print(p, p_max_size, (double)cpu_temp, TEMP_CELSIUS);
3636 OBJ(i8k_left_fan_status) {
3637 int left_fan_status;
3639 sscanf(i8k.left_fan_status, "%d", &left_fan_status);
3640 if (left_fan_status == 0) {
3641 snprintf(p, p_max_size, "off");
3643 if (left_fan_status == 1) {
3644 snprintf(p, p_max_size, "low");
3646 if (left_fan_status == 2) {
3647 snprintf(p, p_max_size, "high");
3650 OBJ(i8k_right_fan_status) {
3651 int right_fan_status;
3653 sscanf(i8k.right_fan_status, "%d", &right_fan_status);
3654 if (right_fan_status == 0) {
3655 snprintf(p, p_max_size, "off");
3657 if (right_fan_status == 1) {
3658 snprintf(p, p_max_size, "low");
3660 if (right_fan_status == 2) {
3661 snprintf(p, p_max_size, "high");
3664 OBJ(i8k_left_fan_rpm) {
3665 snprintf(p, p_max_size, "%s", i8k.left_fan_rpm);
3667 OBJ(i8k_right_fan_rpm) {
3668 snprintf(p, p_max_size, "%s", i8k.right_fan_rpm);
3670 OBJ(i8k_ac_status) {
3673 sscanf(i8k.ac_status, "%d", &ac_status);
3674 if (ac_status == -1) {
3675 snprintf(p, p_max_size, "disabled (read i8k docs)");
3677 if (ac_status == 0) {
3678 snprintf(p, p_max_size, "off");
3680 if (ac_status == 1) {
3681 snprintf(p, p_max_size, "on");
3684 OBJ(i8k_buttons_status) {
3685 snprintf(p, p_max_size, "%s", i8k.buttons_status);
3689 get_ibm_acpi_fan(p, p_max_size);
3692 get_ibm_acpi_temps();
3693 temp_print(p, p_max_size,
3694 ibm_acpi.temps[obj->data.sensor], TEMP_CELSIUS);
3697 get_ibm_acpi_volume(p, p_max_size);
3699 OBJ(ibm_brightness) {
3700 get_ibm_acpi_brightness(p, p_max_size);
3703 /* information from sony_laptop kernel module
3704 * /sys/devices/platform/sony-laptop */
3705 OBJ(sony_fanspeed) {
3706 get_sony_fanspeed(p, p_max_size);
3709 if (!cur->gw_info.count) {
3714 snprintf(p, p_max_size, "%s", cur->gw_info.iface);
3717 snprintf(p, p_max_size, "%s", cur->gw_info.ip);
3720 snprintf(p, p_max_size, "%d", get_laptop_mode());
3723 get_powerbook_batt_info(p, p_max_size, obj->data.i);
3725 #endif /* __linux__ */
3726 #if (defined(__FreeBSD__) || defined(__linux__))
3728 if ((obj->data.ifblock.s)
3729 && (!interface_up(obj->data.ifblock.s))) {
3735 OBJ(obsd_sensors_temp) {
3736 obsd_sensors.device = sensor_device;
3737 update_obsd_sensors();
3738 temp_print(p, p_max_size,
3739 obsd_sensors.temp[obsd_sensors.device][obj->data.sensor],
3742 OBJ(obsd_sensors_fan) {
3743 obsd_sensors.device = sensor_device;
3744 update_obsd_sensors();
3745 snprintf(p, p_max_size, "%d",
3746 obsd_sensors.fan[obsd_sensors.device][obj->data.sensor]);
3748 OBJ(obsd_sensors_volt) {
3749 obsd_sensors.device = sensor_device;
3750 update_obsd_sensors();
3751 snprintf(p, p_max_size, "%.2f",
3752 obsd_sensors.volt[obsd_sensors.device][obj->data.sensor]);
3755 get_obsd_vendor(p, p_max_size);
3758 get_obsd_product(p, p_max_size);
3760 #endif /* __OpenBSD__ */
3763 new_font(p, obj->data.s);
3766 /* TODO: move this correction from kB to kB/s elsewhere
3767 * (or get rid of it??) */
3769 human_readable((obj->data.diskio->current / update_interval) * 1024LL,
3773 human_readable((obj->data.diskio->current_write / update_interval) * 1024LL,
3777 human_readable((obj->data.diskio->current_read / update_interval) * 1024LL,
3782 new_graph(p, obj->a, obj->b, obj->c, obj->d,
3783 obj->data.diskio->current, obj->e, 1, obj->char_a, obj->char_b);
3785 OBJ(diskiograph_read) {
3786 new_graph(p, obj->a, obj->b, obj->c, obj->d,
3787 obj->data.diskio->current_read, obj->e, 1, obj->char_a, obj->char_b);
3789 OBJ(diskiograph_write) {
3790 new_graph(p, obj->a, obj->b, obj->c, obj->d,
3791 obj->data.diskio->current_write, obj->e, 1, obj->char_a, obj->char_b);
3795 human_readable(obj->data.net->recv_speed, p, 255);
3798 spaced_print(p, p_max_size, "%.1f", 8,
3799 obj->data.net->recv_speed / 1024.0);
3802 OBJ(downspeedgraph) {
3803 new_graph(p, obj->a, obj->b, obj->c, obj->d,
3804 obj->data.net->recv_speed / 1024.0, obj->e, 1, obj->char_a, obj->char_b);
3808 /* Since we see you, you're if has not jumped.
3809 * Do Ninja jump here: without leaving traces.
3810 * This is to prevent us from stale jumped flags.
3812 obj = obj->data.ifblock.next;
3816 /* harmless object, just ignore */
3820 if ((obj->data.net->addr.sa_data[2] & 255) == 0
3821 && (obj->data.net->addr.sa_data[3] & 255) == 0
3822 && (obj->data.net->addr.sa_data[4] & 255) == 0
3823 && (obj->data.net->addr.sa_data[5] & 255) == 0) {
3824 snprintf(p, p_max_size, "No Address");
3826 snprintf(p, p_max_size, "%u.%u.%u.%u",
3827 obj->data.net->addr.sa_data[2] & 255,
3828 obj->data.net->addr.sa_data[3] & 255,
3829 obj->data.net->addr.sa_data[4] & 255,
3830 obj->data.net->addr.sa_data[5] & 255);
3833 #if defined(__linux__)
3835 if(NULL != obj->data.net->addrs && strlen(obj->data.net->addrs) > 2)
3837 obj->data.net->addrs[strlen(obj->data.net->addrs) - 2] = 0; /* remove ", " from end of string */
3838 strcpy(p, obj->data.net->addrs);
3841 strcpy(p, "0.0.0.0");
3843 #endif /* __linux__ */
3844 #if defined(IMLIB2) && defined(X11)
3846 /* doesn't actually draw anything, just queues it omp. the
3847 * image will get drawn after the X event loop */
3848 cimlib_add_image(obj->data.s);
3852 struct information *tmp_info;
3853 struct text_object subroot, subroot2;
3855 tmp_info = malloc(sizeof(struct information));
3856 memcpy(tmp_info, cur, sizeof(struct information));
3857 parse_conky_vars(&subroot, obj->data.s, p, tmp_info);
3858 DBGP("evaluated '%s' to '%s'", obj->data.s, p);
3859 parse_conky_vars(&subroot2, p, p, tmp_info);
3861 free_text_objects(&subroot, 1);
3862 free_text_objects(&subroot2, 1);
3866 read_exec(obj->data.s, p, text_buffer_size);
3867 remove_deleted_chars(p);
3870 struct information *tmp_info;
3871 struct text_object subroot;
3873 read_exec(obj->data.s, p, text_buffer_size);
3875 tmp_info = malloc(sizeof(struct information));
3876 memcpy(tmp_info, cur, sizeof(struct information));
3877 parse_conky_vars(&subroot, p, p, tmp_info);
3879 free_text_objects(&subroot, 1);
3886 read_exec(obj->data.s, p, text_buffer_size);
3887 barnum = get_barnum(p); /*using the same function*/
3889 if (barnum >= 0.0) {
3891 new_gauge(p, obj->a, obj->b, round_to_int(barnum * 255.0));
3899 read_exec(obj->data.s, p, text_buffer_size);
3900 barnum = get_barnum(p);
3902 if (barnum >= 0.0) {
3904 if(output_methods & TO_X) {
3906 new_bar(p, obj->a, obj->b, round_to_int(barnum * 255.0));
3909 if(!obj->a) obj->a = DEFAULT_BAR_WIDTH_NO_X;
3910 barnum = round_to_int( ( barnum * obj->a ) / 100);
3912 #pragma omp parallel for
3913 #endif /* HAVE_OPENMP */
3914 for(i=0; i<(int)barnum; i++) {
3917 /* gcc seems to think i is not initialized properly :/ */
3920 #pragma omp parallel for
3921 #endif /* HAVE_OPENMP */
3922 for(i = j/* cheats */; i < obj->a; i++) {
3933 char showaslog = FALSE;
3934 char tempgrad = FALSE;
3936 char *cmd = obj->data.s;
3938 if (strncasecmp(obj->data.execi.cmd, LOGGRAPH" ", strlen(LOGGRAPH" ")) == EQUAL) {
3940 cmd = cmd + strlen(LOGGRAPH" ") * sizeof(char);
3941 } else if(strncasecmp(obj->data.s, NORMGRAPH" ", strlen(NORMGRAPH" ")) == EQUAL) {
3942 cmd = cmd + strlen(NORMGRAPH" ") * sizeof(char);
3944 if (strstr(cmd, " "TEMPGRAD) && strlen(cmd) > strlen(" "TEMPGRAD)) {
3946 cmd += strlen(" "TEMPGRAD);
3948 read_exec(cmd, p, text_buffer_size);
3949 barnum = get_barnum(p);
3951 if (barnum >= 0.0) {
3952 new_graph(p, obj->a, obj->b, obj->c, obj->d, round_to_int(barnum),
3953 100, 1, showaslog, tempgrad);
3957 if (current_update_time - obj->data.execi.last_update
3958 >= obj->data.execi.interval) {
3961 read_exec(obj->data.execi.cmd, p, text_buffer_size);
3962 barnum = get_barnum(p);
3964 if (barnum >= 0.0) {
3965 obj->f = 255 * barnum / 100.0;
3967 obj->data.execi.last_update = current_update_time;
3969 new_bar(p, obj->a, obj->b, round_to_int(obj->f));
3972 if (current_update_time - obj->data.execi.last_update
3973 >= obj->data.execi.interval) {
3975 char showaslog = FALSE;
3976 char tempgrad = FALSE;
3977 char *cmd = obj->data.execi.cmd;
3979 if (strncasecmp(obj->data.execi.cmd, LOGGRAPH" ", strlen(LOGGRAPH" ")) == EQUAL) {
3981 cmd = cmd + strlen(LOGGRAPH" ") * sizeof(char);
3982 } else if(strncasecmp(obj->data.s, NORMGRAPH" ", strlen(NORMGRAPH" ")) == EQUAL) {
3983 cmd = cmd + strlen(NORMGRAPH" ") * sizeof(char);
3985 if (strstr(cmd, " "TEMPGRAD) && strlen(cmd) > strlen(" "TEMPGRAD)) {
3987 cmd += strlen(" "TEMPGRAD);
3989 obj->char_a = showaslog;
3990 obj->char_b = tempgrad;
3991 read_exec(cmd, p, text_buffer_size);
3992 barnum = get_barnum(p);
3994 if (barnum >= 0.0) {
3997 obj->data.execi.last_update = current_update_time;
3999 new_graph(p, obj->a, obj->b, obj->c, obj->d, (int) (obj->f), 100, 1, obj->char_a, obj->char_b);
4002 if (current_update_time - obj->data.execi.last_update
4003 >= obj->data.execi.interval) {
4006 read_exec(obj->data.execi.cmd, p, text_buffer_size);
4007 barnum = get_barnum(p);
4009 if (barnum >= 0.0) {
4010 obj->f = 255 * barnum / 100.0;
4012 obj->data.execi.last_update = current_update_time;
4014 new_gauge(p, obj->a, obj->b, round_to_int(obj->f));
4018 if (current_update_time - obj->data.execi.last_update
4019 >= obj->data.execi.interval
4020 && obj->data.execi.interval != 0) {
4021 read_exec(obj->data.execi.cmd, obj->data.execi.buffer,
4023 obj->data.execi.last_update = current_update_time;
4025 snprintf(p, text_buffer_size, "%s", obj->data.execi.buffer);
4028 struct text_object subroot;
4029 struct information *tmp_info =
4030 malloc(sizeof(struct information));
4031 memcpy(tmp_info, cur, sizeof(struct information));
4033 if (current_update_time - obj->data.execi.last_update
4034 < obj->data.execi.interval
4035 || obj->data.execi.interval == 0) {
4036 parse_conky_vars(&subroot, obj->data.execi.buffer, p, tmp_info);
4038 char *output = obj->data.execi.buffer;
4039 FILE *fp = popen(obj->data.execi.cmd, "r");
4040 int length = fread(output, 1, text_buffer_size, fp);
4044 output[length] = '\0';
4045 if (length > 0 && output[length - 1] == '\n') {
4046 output[length - 1] = '\0';
4049 parse_conky_vars(&subroot, obj->data.execi.buffer, p, tmp_info);
4050 obj->data.execi.last_update = current_update_time;
4052 free_text_objects(&subroot, 1);
4056 if (!obj->data.texeci.p_timed_thread) {
4057 obj->data.texeci.p_timed_thread =
4058 timed_thread_create(&threaded_exec,
4059 (void *) obj, obj->data.texeci.interval * 1000000);
4060 if (!obj->data.texeci.p_timed_thread) {
4061 ERR("Error creating texeci timed thread");
4063 timed_thread_register(obj->data.texeci.p_timed_thread,
4064 &obj->data.texeci.p_timed_thread);
4065 if (timed_thread_run(obj->data.texeci.p_timed_thread)) {
4066 ERR("Error running texeci timed thread");
4069 timed_thread_lock(obj->data.texeci.p_timed_thread);
4070 snprintf(p, text_buffer_size, "%s", obj->data.texeci.buffer);
4071 timed_thread_unlock(obj->data.texeci.p_timed_thread);
4074 #endif /* HAVE_POPEN */
4076 struct mail_s *mail = ensure_mail_thread(obj, imap_thread, "imap");
4078 if (mail && mail->p_timed_thread) {
4079 timed_thread_lock(mail->p_timed_thread);
4080 snprintf(p, p_max_size, "%lu", mail->unseen);
4081 timed_thread_unlock(mail->p_timed_thread);
4084 OBJ(imap_messages) {
4085 struct mail_s *mail = ensure_mail_thread(obj, imap_thread, "imap");
4087 if (mail && mail->p_timed_thread) {
4088 timed_thread_lock(mail->p_timed_thread);
4089 snprintf(p, p_max_size, "%lu", mail->messages);
4090 timed_thread_unlock(mail->p_timed_thread);
4094 struct mail_s *mail = ensure_mail_thread(obj, pop3_thread, "pop3");
4096 if (mail && mail->p_timed_thread) {
4097 timed_thread_lock(mail->p_timed_thread);
4098 snprintf(p, p_max_size, "%lu", mail->unseen);
4099 timed_thread_unlock(mail->p_timed_thread);
4103 struct mail_s *mail = ensure_mail_thread(obj, pop3_thread, "pop3");
4105 if (mail && mail->p_timed_thread) {
4106 timed_thread_lock(mail->p_timed_thread);
4107 snprintf(p, p_max_size, "%.1f",
4108 mail->used / 1024.0 / 1024.0);
4109 timed_thread_unlock(mail->p_timed_thread);
4114 if (obj->data.fs != NULL) {
4115 if (obj->data.fs->size == 0) {
4116 new_bar(p, obj->data.fsbar.w, obj->data.fsbar.h, 255);
4118 new_bar(p, obj->data.fsbar.w, obj->data.fsbar.h,
4119 (int) (255 - obj->data.fsbar.fs->avail * 255 /
4120 obj->data.fs->size));
4126 if (obj->data.fs != NULL) {
4127 human_readable( (obj->data.fs->free ? obj->data.fs->free :
4128 obj->data.fs->avail), p, 255);
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, val);
4145 if (obj->data.fs != NULL) {
4146 human_readable(obj->data.fs->size, p, 255);
4150 if (obj->data.fs != NULL)
4151 snprintf(p, p_max_size, "%s", obj->data.fs->type);
4154 if (obj->data.fs != NULL) {
4155 human_readable(obj->data.fs->size - (obj->data.fs->free
4156 ? obj->data.fs->free : obj->data.fs->avail), p, 255);
4161 if (obj->data.fs != NULL) {
4162 if (obj->data.fs->size == 0) {
4163 new_bar(p, obj->data.fsbar.w, obj->data.fsbar.h, 255);
4165 new_bar(p, obj->data.fsbar.w, obj->data.fsbar.h,
4166 (int) (obj->data.fsbar.fs->avail * 255 /
4167 obj->data.fs->size));
4173 if (obj->data.fs != NULL) {
4176 if (obj->data.fs->size) {
4177 val = (obj->data.fs->free ? obj->data.fs->free :
4178 obj->data.fs->avail) * 100 /
4182 percent_print(p, p_max_size, 100 - val);
4186 float *v = info.loadavg;
4188 if (obj->data.loadavg[2]) {
4189 snprintf(p, p_max_size, "%.2f %.2f %.2f",
4190 v[obj->data.loadavg[0] - 1],
4191 v[obj->data.loadavg[1] - 1],
4192 v[obj->data.loadavg[2] - 1]);
4193 } else if (obj->data.loadavg[1]) {
4194 snprintf(p, p_max_size, "%.2f %.2f",
4195 v[obj->data.loadavg[0] - 1],
4196 v[obj->data.loadavg[1] - 1]);
4197 } else if (obj->data.loadavg[0]) {
4198 snprintf(p, p_max_size, "%.2f",
4199 v[obj->data.loadavg[0] - 1]);
4203 new_goto(p, obj->data.i);
4206 new_tab(p, obj->data.pair.a, obj->data.pair.b);
4210 new_hr(p, obj->data.i);
4214 if (cur->nameserver_info.nscount > obj->data.i)
4215 snprintf(p, p_max_size, "%s",
4216 cur->nameserver_info.ns_list[obj->data.i]);
4220 char *skill = eve(obj->data.eve.userid, obj->data.eve.apikey, obj->data.eve.charid);
4221 snprintf(p, p_max_size, "%s", skill);
4226 PRSS *data = get_rss_info(obj->data.rss.uri,
4227 obj->data.rss.delay);
4231 snprintf(p, p_max_size, "prss: Error reading RSS data\n");
4233 if (strcmp(obj->data.rss.action, "feed_title") == EQUAL) {
4235 // remove trailing new line if one exists
4236 if (str[strlen(str) - 1] == '\n') {
4237 str[strlen(str) - 1] = 0;
4239 snprintf(p, p_max_size, "%s", str);
4240 } else if (strcmp(obj->data.rss.action, "item_title") == EQUAL) {
4241 if (obj->data.rss.act_par < data->item_count) {
4242 str = data->items[obj->data.rss.act_par].title;
4243 // remove trailing new line if one exists
4244 if (str[strlen(str) - 1] == '\n') {
4245 str[strlen(str) - 1] = 0;
4247 snprintf(p, p_max_size, "%s", str);
4249 } else if (strcmp(obj->data.rss.action, "item_desc") == EQUAL) {
4250 if (obj->data.rss.act_par < data->item_count) {
4252 data->items[obj->data.rss.act_par].description;
4253 // remove trailing new line if one exists
4254 if (str[strlen(str) - 1] == '\n') {
4255 str[strlen(str) - 1] = 0;
4257 snprintf(p, p_max_size, "%s", str);
4259 } else if (strcmp(obj->data.rss.action, "item_titles") == EQUAL) {
4260 if (data->item_count > 0) {
4263 //'tmpspaces' is a string with spaces too be placed in front of each title
4264 char *tmpspaces = malloc(obj->data.rss.nrspaces + 1);
4265 memset(tmpspaces, ' ', obj->data.rss.nrspaces);
4266 tmpspaces[obj->data.rss.nrspaces]=0;
4270 if (obj->data.rss.act_par > data->item_count) {
4271 show = data->item_count;
4273 show = obj->data.rss.act_par;
4275 for (itmp = 0; itmp < show; itmp++) {
4276 PRSS_Item *item = &data->items[itmp];
4280 // don't add new line before first item
4282 strncat(p, "\n", p_max_size);
4284 /* remove trailing new line if one exists,
4285 * we have our own */
4286 if (str[strlen(str) - 1] == '\n') {
4287 str[strlen(str) - 1] = 0;
4289 strncat(p, tmpspaces, p_max_size);
4290 strncat(p, str, p_max_size);
4301 char *str = llua_getstring(obj->data.s);
4303 snprintf(p, p_max_size, "%s", str);
4308 char *str = llua_getstring(obj->data.s);
4310 struct information *tmp_info;
4311 struct text_object subroot;
4313 tmp_info = malloc(sizeof(struct information));
4314 memcpy(tmp_info, cur, sizeof(struct information));
4315 parse_conky_vars(&subroot, str, p, tmp_info);
4317 free_text_objects(&subroot, 1);
4322 OBJ(lua_read_parse) {
4323 struct information *tmp_info;
4324 struct text_object subroot, subroot2;
4327 sscanf(obj->data.s, "%64s", func);
4328 text = obj->data.s + strlen(func) + 1;
4330 tmp_info = malloc(sizeof(struct information));
4331 memcpy(tmp_info, cur, sizeof(struct information));
4332 parse_conky_vars(&subroot, text, p, tmp_info);
4333 DBGP("evaluated '%s' to '%s'", text, p);
4335 str = llua_getstring_read(func, p);
4337 parse_conky_vars(&subroot2, str, p, tmp_info);
4338 DBGP("evaluated '%s' to '%s'", str, p);
4341 free_text_objects(&subroot2, 1);
4343 free_text_objects(&subroot, 1);
4349 if (llua_getinteger(obj->data.s, &per)) {
4350 new_bar(p, obj->a, obj->b, (per/100.0 * 255));
4355 if (llua_getinteger(obj->data.s, &per)) {
4356 new_graph(p, obj->a, obj->b, obj->c, obj->d,
4357 (per/100.0 * 255), 100, 1, obj->char_a, obj->char_b);
4362 if (llua_getinteger(obj->data.s, &per)) {
4363 new_gauge(p, obj->a, obj->b, (per/100.0 * 255));
4367 #endif /* HAVE_LUA */
4372 if (obj->data.hddtemp.update_time < current_update_time - 30) {
4373 if (obj->data.hddtemp.temp)
4374 free(obj->data.hddtemp.temp);
4375 obj->data.hddtemp.temp = get_hddtemp_info(obj->data.hddtemp.dev,
4376 obj->data.hddtemp.addr, obj->data.hddtemp.port);
4377 obj->data.hddtemp.update_time = current_update_time;
4379 if (!obj->data.hddtemp.temp) {
4380 snprintf(p, p_max_size, "N/A");
4382 val = strtol(obj->data.hddtemp.temp + 1, &endptr, 10);
4383 unit = obj->data.hddtemp.temp[0];
4385 if (*endptr != '\0')
4386 snprintf(p, p_max_size, "N/A");
4387 else if (unit == 'C')
4388 temp_print(p, p_max_size, (double)val, TEMP_CELSIUS);
4389 else if (unit == 'F')
4390 temp_print(p, p_max_size, (double)val, TEMP_FAHRENHEIT);
4392 snprintf(p, p_max_size, "N/A");
4397 new_offset(p, obj->data.i);
4400 new_voffset(p, obj->data.i);
4406 r = get_sysfs_info(&obj->data.sysfs.fd, obj->data.sysfs.arg,
4407 obj->data.sysfs.devtype, obj->data.sysfs.type);
4409 r = r * obj->data.sysfs.factor + obj->data.sysfs.offset;
4411 if (!strncmp(obj->data.sysfs.type, "temp", 4)) {
4412 temp_print(p, p_max_size, r, TEMP_CELSIUS);
4413 } else if (r >= 100.0 || r == 0) {
4414 snprintf(p, p_max_size, "%d", (int) r);
4416 snprintf(p, p_max_size, "%.1f", r);
4422 r = get_sysfs_info(&obj->data.sysfs.fd, obj->data.sysfs.arg,
4423 obj->data.sysfs.devtype, obj->data.sysfs.type);
4425 r = r * obj->data.sysfs.factor + obj->data.sysfs.offset;
4427 if (!strncmp(obj->data.sysfs.type, "temp", 4)) {
4428 temp_print(p, p_max_size, r, TEMP_CELSIUS);
4429 } else if (r >= 100.0 || r == 0) {
4430 snprintf(p, p_max_size, "%d", (int) r);
4432 snprintf(p, p_max_size, "%.1f", r);
4438 r = get_sysfs_info(&obj->data.sysfs.fd, obj->data.sysfs.arg,
4439 obj->data.sysfs.devtype, obj->data.sysfs.type);
4441 r = r * obj->data.sysfs.factor + obj->data.sysfs.offset;
4443 if (!strncmp(obj->data.sysfs.type, "temp", 4)) {
4444 temp_print(p, p_max_size, r, TEMP_CELSIUS);
4445 } else if (r >= 100.0 || r == 0) {
4446 snprintf(p, p_max_size, "%d", (int) r);
4448 snprintf(p, p_max_size, "%.1f", r);
4451 #endif /* __linux__ */
4453 new_alignr(p, obj->data.i);
4456 new_alignc(p, obj->data.i);
4459 char buf[max_user_text];
4460 struct information *tmp_info =
4461 malloc(sizeof(struct information));
4462 memcpy(tmp_info, cur, sizeof(struct information));
4463 generate_text_internal(buf, max_user_text,
4464 *obj->sub, tmp_info);
4466 if (strlen(buf) != 0) {
4472 char expression[max_user_text];
4474 struct information *tmp_info;
4476 tmp_info = malloc(sizeof(struct information));
4477 memcpy(tmp_info, cur, sizeof(struct information));
4478 generate_text_internal(expression, max_user_text,
4479 *obj->sub, tmp_info);
4480 DBGP("parsed arg into '%s'", expression);
4482 val = compare(expression);
4484 ERR("compare failed for expression '%s'",
4492 if (obj->data.ifblock.str
4493 && !check_contains(obj->data.ifblock.s,
4494 obj->data.ifblock.str)) {
4496 } else if (obj->data.ifblock.s
4497 && access(obj->data.ifblock.s, F_OK)) {
4502 if ((obj->data.ifblock.s)
4503 && (!check_mount(obj->data.ifblock.s))) {
4508 if ((obj->data.ifblock.s) && system(obj->data.ifblock.s)) {
4512 #if defined(__linux__)
4514 snprintf(p, p_max_size, "%s", get_ioscheduler(obj->data.s));
4518 snprintf(p, p_max_size, "%s", cur->uname_s.release);
4521 snprintf(p, p_max_size, "%s", cur->uname_s.machine);
4526 human_readable(cur->mem * 1024, p, 255);
4529 human_readable(cur->memeasyfree * 1024, p, 255);
4532 human_readable(cur->memfree * 1024, p, 255);
4535 human_readable(cur->memmax * 1024, p, 255);
4539 percent_print(p, p_max_size, cur->mem * 100 / cur->memmax);
4543 new_gauge(p, obj->data.pair.a, obj->data.pair.b,
4544 cur->memmax ? (cur->mem * 255) / (cur->memmax) : 0);
4547 new_bar(p, obj->data.pair.a, obj->data.pair.b,
4548 cur->memmax ? (cur->mem * 255) / (cur->memmax) : 0);
4551 new_graph(p, obj->a, obj->b, obj->c, obj->d,
4552 cur->memmax ? (cur->mem * 100.0) / (cur->memmax) : 0.0,
4553 100, 1, obj->char_a, obj->char_b);
4558 percent_print(p, p_max_size, mixer_get_avg(obj->data.l));
4561 percent_print(p, p_max_size, mixer_get_left(obj->data.l));
4564 percent_print(p, p_max_size, mixer_get_right(obj->data.l));
4568 new_bar(p, obj->data.mixerbar.w, obj->data.mixerbar.h,
4569 mixer_to_255(obj->data.mixerbar.l,mixer_get_avg(obj->data.mixerbar.l)));
4572 new_bar(p, obj->data.mixerbar.w, obj->data.mixerbar.h,
4573 mixer_to_255(obj->data.mixerbar.l,mixer_get_left(obj->data.mixerbar.l)));
4576 new_bar(p, obj->data.mixerbar.w, obj->data.mixerbar.h,
4577 mixer_to_255(obj->data.mixerbar.l,mixer_get_right(obj->data.mixerbar.l)));
4580 OBJ(if_mixer_mute) {
4581 if (!mixer_is_mute(obj->data.ifblock.i)) {
4587 snprintf(p, p_max_size, "%d", cur->x11.monitor.current);
4589 OBJ(monitor_number) {
4590 snprintf(p, p_max_size, "%d", cur->x11.monitor.number);
4596 update_mail_count(&obj->data.local_mail);
4597 snprintf(p, p_max_size, "%d", obj->data.local_mail.mail_count);
4600 update_mail_count(&obj->data.local_mail);
4601 snprintf(p, p_max_size, "%d",
4602 obj->data.local_mail.new_mail_count);
4605 update_mail_count(&obj->data.local_mail);
4606 snprintf(p, p_max_size, "%d",
4607 obj->data.local_mail.seen_mail_count);
4610 update_mail_count(&obj->data.local_mail);
4611 snprintf(p, p_max_size, "%d",
4612 obj->data.local_mail.unseen_mail_count);
4614 OBJ(flagged_mails) {
4615 update_mail_count(&obj->data.local_mail);
4616 snprintf(p, p_max_size, "%d",
4617 obj->data.local_mail.flagged_mail_count);
4619 OBJ(unflagged_mails) {
4620 update_mail_count(&obj->data.local_mail);
4621 snprintf(p, p_max_size, "%d",
4622 obj->data.local_mail.unflagged_mail_count);
4624 OBJ(forwarded_mails) {
4625 update_mail_count(&obj->data.local_mail);
4626 snprintf(p, p_max_size, "%d",
4627 obj->data.local_mail.forwarded_mail_count);
4629 OBJ(unforwarded_mails) {
4630 update_mail_count(&obj->data.local_mail);
4631 snprintf(p, p_max_size, "%d",
4632 obj->data.local_mail.unforwarded_mail_count);
4634 OBJ(replied_mails) {
4635 update_mail_count(&obj->data.local_mail);
4636 snprintf(p, p_max_size, "%d",
4637 obj->data.local_mail.replied_mail_count);
4639 OBJ(unreplied_mails) {
4640 update_mail_count(&obj->data.local_mail);
4641 snprintf(p, p_max_size, "%d",
4642 obj->data.local_mail.unreplied_mail_count);
4645 update_mail_count(&obj->data.local_mail);
4646 snprintf(p, p_max_size, "%d",
4647 obj->data.local_mail.draft_mail_count);
4649 OBJ(trashed_mails) {
4650 update_mail_count(&obj->data.local_mail);
4651 snprintf(p, p_max_size, "%d",
4652 obj->data.local_mail.trashed_mail_count);
4655 mbox_scan(obj->data.mboxscan.args, obj->data.mboxscan.output,
4657 snprintf(p, p_max_size, "%s", obj->data.mboxscan.output);
4660 snprintf(p, p_max_size, "%s", cur->uname_s.nodename);
4663 new_outline(p, obj->data.l);
4666 spaced_print(p, p_max_size, "%hu", 4, cur->procs);
4668 OBJ(running_processes) {
4669 spaced_print(p, p_max_size, "%hu", 4, cur->run_procs);
4672 snprintf(p, p_max_size, "%s", obj->data.s);
4676 new_bg(p, obj->data.l);
4679 new_stippled_hr(p, obj->data.pair.a, obj->data.pair.b);
4683 human_readable(cur->swap * 1024, p, 255);
4686 human_readable(cur->swapmax * 1024, p, 255);
4689 if (cur->swapmax == 0) {
4690 strncpy(p, "No swap", p_max_size);
4692 percent_print(p, p_max_size, cur->swap * 100 / cur->swapmax);
4697 new_bar(p, obj->data.pair.a, obj->data.pair.b,
4698 cur->swapmax ? (cur->swap * 255) / (cur->swapmax) : 0);
4702 snprintf(p, p_max_size, "%s", cur->uname_s.sysname);
4705 time_t t = time(NULL);
4706 struct tm *tm = localtime(&t);
4708 setlocale(LC_TIME, "");
4709 strftime(p, p_max_size, obj->data.s, tm);
4712 time_t t = time(NULL);
4713 struct tm *tm = gmtime(&t);
4715 strftime(p, p_max_size, obj->data.s, tm);
4722 if (obj->data.tztime.tz) {
4723 oldTZ = getenv("TZ");
4724 setenv("TZ", obj->data.tztime.tz, 1);
4730 setlocale(LC_TIME, "");
4731 strftime(p, p_max_size, obj->data.tztime.fmt, tm);
4733 setenv("TZ", oldTZ, 1);
4738 // Needless to free oldTZ since getenv gives ptr to static data
4741 human_readable(obj->data.net->recv, p, 255);
4744 human_readable(obj->data.net->trans, p, 255);
4747 snprintf(p, p_max_size, "%d", total_updates);
4750 if(total_updates % updatereset != obj->data.ifblock.i - 1) {
4755 human_readable(obj->data.net->trans_speed, p, 255);
4758 spaced_print(p, p_max_size, "%.1f", 8,
4759 obj->data.net->trans_speed / 1024.0);
4763 new_graph(p, obj->a, obj->b, obj->c, obj->d,
4764 obj->data.net->trans_speed / 1024.0, obj->e, 1, obj->char_a, obj->char_b);
4768 format_seconds_short(p, p_max_size, (int) cur->uptime);
4771 format_seconds(p, p_max_size, (int) cur->uptime);
4774 snprintf(p, p_max_size, "%s", cur->users.names);
4777 snprintf(p, p_max_size, "%s", cur->users.terms);
4780 snprintf(p, p_max_size, "%s", cur->users.times);
4783 snprintf(p, p_max_size, "%d", cur->users.number);
4785 #if (defined(__FreeBSD__) || defined(__FreeBSD_kernel__) \
4786 || defined(__OpenBSD__)) && (defined(i386) || defined(__i386__))
4790 msg = get_apm_adapter();
4791 snprintf(p, p_max_size, "%s", msg);
4794 OBJ(apm_battery_life) {
4797 msg = get_apm_battery_life();
4798 snprintf(p, p_max_size, "%s", msg);
4801 OBJ(apm_battery_time) {
4804 msg = get_apm_battery_time();
4805 snprintf(p, p_max_size, "%s", msg);
4808 #endif /* __FreeBSD__ __OpenBSD__ */
4811 #define mpd_printf(fmt, val) \
4812 snprintf(p, p_max_size, fmt, mpd_get_info()->val)
4813 #define mpd_sprintf(val) { \
4814 if (!obj->data.i || obj->data.i > p_max_size) \
4815 mpd_printf("%s", val); \
4817 snprintf(p, obj->data.i, "%s", mpd_get_info()->val); \
4822 mpd_sprintf(artist);
4826 mpd_printf("%s", random);
4828 mpd_printf("%s", repeat);
4836 mpd_printf("%d", volume);
4838 mpd_printf("%d", bitrate);
4840 mpd_printf("%s", status);
4842 format_media_player_time(p, p_max_size, mpd_get_info()->elapsed);
4845 format_media_player_time(p, p_max_size, mpd_get_info()->length);
4848 percent_print(p, p_max_size, (int)(mpd_get_info()->progress * 100));
4852 new_bar(p, obj->data.pair.a, obj->data.pair.b,
4853 (int) (mpd_get_info()->progress * 255.0f));
4857 struct mpd_s *mpd = mpd_get_info();
4858 int len = obj->data.i;
4859 if (len == 0 || len > p_max_size)
4862 memset(p, 0, p_max_size);
4863 if (mpd->artist && *mpd->artist &&
4864 mpd->title && *mpd->title) {
4865 snprintf(p, len, "%s - %s", mpd->artist,
4867 } else if (mpd->title && *mpd->title) {
4868 snprintf(p, len, "%s", mpd->title);
4869 } else if (mpd->artist && *mpd->artist) {
4870 snprintf(p, len, "%s", mpd->artist);
4871 } else if (mpd->file && *mpd->file) {
4872 snprintf(p, len, "%s", mpd->file);
4877 OBJ(if_mpd_playing) {
4878 if (!mpd_get_info()->is_playing) {
4891 #define MOC_PRINT(t, a) \
4892 snprintf(p, p_max_size, "%s", (moc.t ? moc.t : a))
4894 MOC_PRINT(state, "??");
4897 MOC_PRINT(file, "no file");
4900 MOC_PRINT(title, "no title");
4903 MOC_PRINT(artist, "no artist");
4906 MOC_PRINT(song, "no song");
4909 MOC_PRINT(album, "no album");
4911 OBJ(moc_totaltime) {
4912 MOC_PRINT(totaltime, "0:00");
4915 MOC_PRINT(timeleft, "0:00");
4918 MOC_PRINT(curtime, "0:00");
4921 MOC_PRINT(bitrate, "0Kbps");
4924 MOC_PRINT(rate, "0KHz");
4930 snprintf(p, p_max_size, "%s", cur->xmms2.artist);
4933 snprintf(p, p_max_size, "%s", cur->xmms2.album);
4936 snprintf(p, p_max_size, "%s", cur->xmms2.title);
4939 snprintf(p, p_max_size, "%s", cur->xmms2.genre);
4941 OBJ(xmms2_comment) {
4942 snprintf(p, p_max_size, "%s", cur->xmms2.comment);
4945 snprintf(p, p_max_size, "%s", cur->xmms2.url);
4948 snprintf(p, p_max_size, "%s", cur->xmms2.status);
4951 snprintf(p, p_max_size, "%s", cur->xmms2.date);
4953 OBJ(xmms2_tracknr) {
4954 if (cur->xmms2.tracknr != -1) {
4955 snprintf(p, p_max_size, "%i", cur->xmms2.tracknr);
4958 OBJ(xmms2_bitrate) {
4959 snprintf(p, p_max_size, "%i", cur->xmms2.bitrate);
4962 snprintf(p, p_max_size, "%u", cur->xmms2.id);
4965 snprintf(p, p_max_size, "%2.1f", cur->xmms2.size);
4967 OBJ(xmms2_elapsed) {
4968 snprintf(p, p_max_size, "%02d:%02d", cur->xmms2.elapsed / 60000,
4969 (cur->xmms2.elapsed / 1000) % 60);
4971 OBJ(xmms2_duration) {
4972 snprintf(p, p_max_size, "%02d:%02d",
4973 cur->xmms2.duration / 60000,
4974 (cur->xmms2.duration / 1000) % 60);
4976 OBJ(xmms2_percent) {
4977 snprintf(p, p_max_size, "%2.0f", cur->xmms2.progress * 100);
4980 new_bar(p, obj->data.pair.a, obj->data.pair.b,
4981 (int) (cur->xmms2.progress * 255.0f));
4983 OBJ(xmms2_playlist) {
4984 snprintf(p, p_max_size, "%s", cur->xmms2.playlist);
4986 OBJ(xmms2_timesplayed) {
4987 snprintf(p, p_max_size, "%i", cur->xmms2.timesplayed);
4990 if (strlen(cur->xmms2.title) < 2
4991 && strlen(cur->xmms2.title) < 2) {
4992 snprintf(p, p_max_size, "%s", cur->xmms2.url);
4994 snprintf(p, p_max_size, "%s - %s", cur->xmms2.artist,
4998 OBJ(if_xmms2_connected) {
4999 if (cur->xmms2.conn_state != 1) {
5005 OBJ(audacious_status) {
5006 snprintf(p, p_max_size, "%s",
5007 cur->audacious.items[AUDACIOUS_STATUS]);
5009 OBJ(audacious_title) {
5010 snprintf(p, cur->audacious.max_title_len > 0
5011 ? cur->audacious.max_title_len : p_max_size, "%s",
5012 cur->audacious.items[AUDACIOUS_TITLE]);
5014 OBJ(audacious_length) {
5015 snprintf(p, p_max_size, "%s",
5016 cur->audacious.items[AUDACIOUS_LENGTH]);
5018 OBJ(audacious_length_seconds) {
5019 snprintf(p, p_max_size, "%s",
5020 cur->audacious.items[AUDACIOUS_LENGTH_SECONDS]);
5022 OBJ(audacious_position) {
5023 snprintf(p, p_max_size, "%s",
5024 cur->audacious.items[AUDACIOUS_POSITION]);
5026 OBJ(audacious_position_seconds) {
5027 snprintf(p, p_max_size, "%s",
5028 cur->audacious.items[AUDACIOUS_POSITION_SECONDS]);
5030 OBJ(audacious_bitrate) {
5031 snprintf(p, p_max_size, "%s",
5032 cur->audacious.items[AUDACIOUS_BITRATE]);
5034 OBJ(audacious_frequency) {
5035 snprintf(p, p_max_size, "%s",
5036 cur->audacious.items[AUDACIOUS_FREQUENCY]);
5038 OBJ(audacious_channels) {
5039 snprintf(p, p_max_size, "%s",
5040 cur->audacious.items[AUDACIOUS_CHANNELS]);
5042 OBJ(audacious_filename) {
5043 snprintf(p, p_max_size, "%s",
5044 cur->audacious.items[AUDACIOUS_FILENAME]);
5046 OBJ(audacious_playlist_length) {
5047 snprintf(p, p_max_size, "%s",
5048 cur->audacious.items[AUDACIOUS_PLAYLIST_LENGTH]);
5050 OBJ(audacious_playlist_position) {
5051 snprintf(p, p_max_size, "%s",
5052 cur->audacious.items[AUDACIOUS_PLAYLIST_POSITION]);
5054 OBJ(audacious_main_volume) {
5055 snprintf(p, p_max_size, "%s",
5056 cur->audacious.items[AUDACIOUS_MAIN_VOLUME]);
5058 OBJ(audacious_bar) {
5062 atof(cur->audacious.items[AUDACIOUS_POSITION_SECONDS]) /
5063 atof(cur->audacious.items[AUDACIOUS_LENGTH_SECONDS]);
5064 new_bar(p, obj->a, obj->b, (int) (progress * 255.0f));
5070 snprintf(p, p_max_size, "%s", cur->bmpx.title);
5073 snprintf(p, p_max_size, "%s", cur->bmpx.artist);
5076 snprintf(p, p_max_size, "%s", cur->bmpx.album);
5079 snprintf(p, p_max_size, "%s", cur->bmpx.uri);
5082 snprintf(p, p_max_size, "%i", cur->bmpx.track);
5085 snprintf(p, p_max_size, "%i", cur->bmpx.bitrate);
5088 /* we have three different types of top (top, top_mem
5089 * and top_time). To avoid having almost-same code three
5090 * times, we have this special handler. */
5093 parse_top_args("top", obj->data.top.s, obj);
5094 if (!needed) needed = cur->cpu;
5096 parse_top_args("top_mem", obj->data.top.s, obj);
5097 if (!needed) needed = cur->memu;
5099 parse_top_args("top_time", obj->data.top.s, obj);
5100 if (!needed) needed = cur->time;
5102 if (needed[obj->data.top.num]) {
5105 switch (obj->data.top.type) {
5107 snprintf(p, top_name_width + 1, "%-*s", top_name_width,
5108 needed[obj->data.top.num]->name);
5111 snprintf(p, 7, "%6.2f",
5112 needed[obj->data.top.num]->amount);
5115 snprintf(p, 6, "%5i",
5116 needed[obj->data.top.num]->pid);
5119 snprintf(p, 7, "%6.2f",
5120 needed[obj->data.top.num]->totalmem);
5123 timeval = format_time(
5124 needed[obj->data.top.num]->total_cpu_time, 9);
5125 snprintf(p, 10, "%9s", timeval);
5129 human_readable(needed[obj->data.top.num]->rss,
5133 human_readable(needed[obj->data.top.num]->vsize,
5139 print_tail_object(obj, p, p_max_size);
5141 print_head_object(obj, p, p_max_size);
5143 FILE *fp = open_file(obj->data.s, &obj->a);
5146 /* FIXME: use something more general (see also tail.c, head.c */
5147 #define BUFSZ 0x1000
5152 while(fgets(buf, BUFSZ, fp) != NULL){
5153 for(j = 0; buf[j] != 0; j++) {
5154 if(buf[j] == '\n') {
5159 sprintf(p, "%d", lines);
5162 sprintf(p, "File Unreadable");
5167 FILE *fp = open_file(obj->data.s, &obj->a);
5172 char inword = FALSE;
5175 while(fgets(buf, BUFSZ, fp) != NULL){
5176 for(j = 0; buf[j] != 0; j++) {
5177 if(!isspace(buf[j])) {
5178 if(inword == FALSE) {
5187 sprintf(p, "%d", words);
5190 sprintf(p, "File Unreadable");
5193 #ifdef TCP_PORT_MONITOR
5195 tcp_portmon_action(p, p_max_size,
5196 &obj->data.tcp_port_monitor);
5202 iconv_converting = 1;
5203 iconv_selected = obj->a;
5206 iconv_converting = 0;
5211 OBJ(entropy_avail) {
5212 snprintf(p, p_max_size, "%d", cur->entropy.entropy_avail);
5214 OBJ(entropy_poolsize) {
5215 snprintf(p, p_max_size, "%d", cur->entropy.poolsize);
5219 double entropy_perc;
5221 entropy_perc = (double) cur->entropy.entropy_avail /
5222 (double) cur->entropy.poolsize;
5223 new_bar(p, obj->a, obj->b, (int) (entropy_perc * 255.0f));
5230 s = smapi_get_val(obj->data.s);
5231 snprintf(p, p_max_size, "%s", s);
5235 OBJ(if_smapi_bat_installed) {
5237 if(obj->data.ifblock.s && sscanf(obj->data.ifblock.s, "%i", &idx) == 1) {
5238 if(!smapi_bat_installed(idx)) {
5242 ERR("argument to if_smapi_bat_installed must be an integer");
5244 OBJ(smapi_bat_perc) {
5246 if(obj->data.s && sscanf(obj->data.s, "%i", &idx) == 1) {
5247 val = smapi_bat_installed(idx) ?
5248 smapi_get_bat_int(idx, "remaining_percent") : 0;
5249 percent_print(p, p_max_size, val);
5251 ERR("argument to smapi_bat_perc must be an integer");
5253 OBJ(smapi_bat_temp) {
5255 if(obj->data.s && sscanf(obj->data.s, "%i", &idx) == 1) {
5256 val = smapi_bat_installed(idx) ?
5257 smapi_get_bat_int(idx, "temperature") : 0;
5258 /* temperature is in milli degree celsius */
5259 temp_print(p, p_max_size, val / 1000, TEMP_CELSIUS);
5261 ERR("argument to smapi_bat_temp must be an integer");
5263 OBJ(smapi_bat_power) {
5265 if(obj->data.s && sscanf(obj->data.s, "%i", &idx) == 1) {
5266 val = smapi_bat_installed(idx) ?
5267 smapi_get_bat_int(idx, "power_now") : 0;
5268 /* power_now is in mW, set to W with one digit precision */
5269 snprintf(p, p_max_size, "%.1f", ((double)val / 1000));
5271 ERR("argument to smapi_bat_power must be an integer");
5273 OBJ(smapi_bat_bar) {
5274 if(obj->data.i >= 0 && smapi_bat_installed(obj->data.i))
5275 new_bar(p, obj->a, obj->b, (int)
5276 (255 * smapi_get_bat_int(obj->data.i, "remaining_percent") / 100));
5278 new_bar(p, obj->a, obj->b, 0);
5283 char *tmp, buf[max_user_text];
5284 generate_text_internal(buf, max_user_text,
5287 if (strlen(buf) <= obj->data.scroll.show) {
5288 snprintf(p, p_max_size, "%s", buf);
5291 #define LINESEPARATOR '|'
5292 //place all the lines behind each other with LINESEPARATOR between them
5293 for(j = 0; buf[j] != 0; j++) {
5295 buf[j]=LINESEPARATOR;
5298 //scroll the output obj->data.scroll.start places by copying that many chars from
5299 //the front of the string to tmp, scrolling the rest to the front and placing tmp
5300 //at the back of the string
5301 tmp = calloc(obj->data.scroll.start + 1, sizeof(char));
5302 strncpy(tmp, buf, obj->data.scroll.start); tmp[obj->data.scroll.start] = 0;
5303 for(j = obj->data.scroll.start; buf[j] != 0; j++){
5304 buf[j - obj->data.scroll.start] = buf[j];
5306 strcpy(&buf[j - obj->data.scroll.start], tmp);
5308 //only show the requested number of chars
5309 if(obj->data.scroll.show < j) {
5310 buf[obj->data.scroll.show] = 0;
5312 //next time, scroll a place more or reset scrolling if we are at the end
5313 obj->data.scroll.start += obj->data.scroll.step;
5314 if(obj->data.scroll.start >= j){
5315 obj->data.scroll.start = 0;
5317 snprintf(p, p_max_size, "%s", buf);
5320 char buf[2][max_user_text];
5327 struct llrows* next;
5329 struct llrows *ll_rows[2], *current[2];
5330 struct text_object * objsub = obj->sub;
5334 #pragma omp parallel for
5335 #endif /* HAVE_OPENMP */
5336 for(i=0; i<2; i++) {
5339 ll_rows[i] = malloc(sizeof(struct llrows));
5340 current[i] = ll_rows[i];
5342 #pragma omp parallel for
5343 #endif /* HAVE_OPENMP */
5344 for(j=0; j<i; j++) objsub = objsub->sub;
5345 generate_text_internal(buf[i], max_user_text, *objsub, cur);
5347 * #ifdef HAVE_OPENMP
5348 * #pragma omp parallel for reduction (+:nr_rows[i])
5349 * #endif HAVE_OPENMP */
5350 for(j=0; buf[i][j] != 0; j++) {
5351 if(buf[i][j] == '\t') buf[i][j] = ' ';
5352 if(buf[i][j] == '\n') {
5354 current[i]->row = strdup(buf[i]+nextstart);
5355 if(i==0 && (long)strlen(current[i]->row) > longest) longest = (long)strlen(current[i]->row);
5356 current[i]->next = malloc(sizeof(struct llrows));
5357 current[i] = current[i]->next;
5362 current[i]->row = strdup(buf[i]+nextstart);
5363 if(i==0 && (long)strlen(current[i]->row) > longest) longest = (long)strlen(current[i]->row);
5364 current[i]->next = NULL;
5365 current[i] = ll_rows[i];
5367 for(j=0; j < (nr_rows[0] > nr_rows[1] ? nr_rows[0] : nr_rows[1] ); j++) {
5369 strcat(p, current[0]->row);
5370 i=strlen(current[0]->row);
5372 while(i < longest) {
5377 strcat(p, obj->data.combine.seperation);
5378 strcat(p, current[1]->row);
5382 #pragma omp parallel for
5383 #endif /* HAVE_OPENMP */
5384 for(i=0; i<2; i++) if(current[i]) current[i]=current[i]->next;
5387 #pragma omp parallel for
5388 #endif /* HAVE_OPENMP */
5389 for(i=0; i<2; i++) {
5390 while(ll_rows[i] != NULL) {
5391 current[i]=ll_rows[i];
5392 free(current[i]->row);
5393 ll_rows[i]=current[i]->next;
5400 int value = get_nvidia_value(obj->data.nvidia.type, display);
5402 snprintf(p, p_max_size, "N/A");
5403 else if (obj->data.nvidia.type == NV_TEMP)
5404 temp_print(p, p_max_size, (double)value, TEMP_CELSIUS);
5405 else if (obj->data.nvidia.print_as_float &&
5406 value > 0 && value < 100)
5407 snprintf(p, p_max_size, "%.1f", (float)value);
5409 snprintf(p, p_max_size, "%d", value);
5414 /* This is just a meta-object to set host:port */
5417 snprintf(p, p_max_size, "%s",
5418 cur->apcupsd.items[APCUPSD_NAME]);
5420 OBJ(apcupsd_model) {
5421 snprintf(p, p_max_size, "%s",
5422 cur->apcupsd.items[APCUPSD_MODEL]);
5424 OBJ(apcupsd_upsmode) {
5425 snprintf(p, p_max_size, "%s",
5426 cur->apcupsd.items[APCUPSD_UPSMODE]);
5428 OBJ(apcupsd_cable) {
5429 snprintf(p, p_max_size, "%s",
5430 cur->apcupsd.items[APCUPSD_CABLE]);
5432 OBJ(apcupsd_status) {
5433 snprintf(p, p_max_size, "%s",
5434 cur->apcupsd.items[APCUPSD_STATUS]);
5436 OBJ(apcupsd_linev) {
5437 snprintf(p, p_max_size, "%s",
5438 cur->apcupsd.items[APCUPSD_LINEV]);
5441 snprintf(p, p_max_size, "%s",
5442 cur->apcupsd.items[APCUPSD_LOAD]);
5445 OBJ(apcupsd_loadbar) {
5447 progress = atof(cur->apcupsd.items[APCUPSD_LOAD]) / 100.0 * 255.0;
5448 new_bar(p, obj->a, obj->b, (int)progress);
5450 OBJ(apcupsd_loadgraph) {
5452 progress = atof(cur->apcupsd.items[APCUPSD_LOAD]);
5453 new_graph(p, obj->a, obj->b, obj->c, obj->d,
5454 (int)progress, 100, 1, obj->char_a, obj->char_b);
5456 OBJ(apcupsd_loadgauge) {
5458 progress = atof(cur->apcupsd.items[APCUPSD_LOAD]) / 100.0 * 255.0;
5459 new_gauge(p, obj->a, obj->b,
5463 OBJ(apcupsd_charge) {
5464 snprintf(p, p_max_size, "%s",
5465 cur->apcupsd.items[APCUPSD_CHARGE]);
5467 OBJ(apcupsd_timeleft) {
5468 snprintf(p, p_max_size, "%s",
5469 cur->apcupsd.items[APCUPSD_TIMELEFT]);
5472 snprintf(p, p_max_size, "%s",
5473 cur->apcupsd.items[APCUPSD_TEMP]);
5475 OBJ(apcupsd_lastxfer) {
5476 snprintf(p, p_max_size, "%s",
5477 cur->apcupsd.items[APCUPSD_LASTXFER]);
5479 #endif /* APCUPSD */
5486 unsigned int a = strlen(p);
5489 if (a > 0 && iconv_converting && iconv_selected > 0
5490 && (iconv_cd[iconv_selected - 1] != (iconv_t) (-1))) {
5492 size_t dummy1, dummy2;
5493 char *ptr = buff_in;
5496 dummy1 = dummy2 = a;
5498 strncpy(buff_in, p, p_max_size);
5500 iconv(*iconv_cd[iconv_selected - 1], NULL, NULL, NULL, NULL);
5501 while (dummy1 > 0) {
5502 bytes = iconv(*iconv_cd[iconv_selected - 1], &ptr, &dummy1,
5505 ERR("Iconv codeset conversion failed");
5510 /* It is nessecary when we are converting from multibyte to
5511 * singlebyte codepage */
5514 #endif /* HAVE_ICONV */
5522 double current_update_time, next_update_time, last_update_time;
5524 static void generate_text(void)
5526 struct information *cur = &info;
5533 current_update_time = get_time();
5537 /* add things to the buffer */
5543 generate_text_internal(p, max_user_text, global_root_object, cur);
5545 if (stuff_in_upper_case) {
5548 tmp_p = text_buffer;
5550 *tmp_p = toupper(*tmp_p);
5555 next_update_time += update_interval;
5556 if (next_update_time < get_time()) {
5557 next_update_time = get_time() + update_interval;
5558 } else if (next_update_time > get_time() + update_interval) {
5559 next_update_time = get_time() + update_interval;
5561 last_update_time = current_update_time;
5566 static inline int get_string_width(const char *s)
5569 if (output_methods & TO_X) {
5570 return *s ? calc_text_width(s, strlen(s)) : 0;
5576 static inline int get_string_width_special(char *s)
5584 if ((output_methods & TO_X) == 0) {
5586 return (s) ? strlen(s) : 0;
5594 p = strndup(s, text_buffer_size);
5598 if (*p == SPECIAL_CHAR) {
5599 /* shift everything over by 1 so that the special char
5600 * doesn't mess up the size calculation */
5601 for (i = 0; i < (long)strlen(p); i++) {
5602 *(p + i) = *(p + i + 1);
5604 if (specials[special_index + idx].type == GRAPH
5605 || specials[special_index + idx].type == GAUGE
5606 || specials[special_index + idx].type == BAR) {
5607 width += specials[special_index + idx].width;
5614 if (strlen(final) > 1) {
5615 width += calc_text_width(final, strlen(final));
5623 static void text_size_updater(char *s);
5625 int last_font_height;
5626 static void update_text_area(void)
5630 if ((output_methods & TO_X) == 0)
5632 /* update text size if it isn't fixed */
5637 text_width = minimum_width;
5640 last_font_height = font_height();
5641 for_each_line(text_buffer, text_size_updater);
5643 if (text_height < minimum_height) {
5644 text_height = minimum_height;
5646 if (text_width > maximum_width && maximum_width > 0) {
5647 text_width = maximum_width;
5651 /* get text position on workarea */
5652 switch (text_alignment) {
5659 x = workarea[2] - text_width - gap_x;
5664 x = workarea[2] / 2 - text_width / 2 - gap_x;
5671 y = workarea[3] - text_height - gap_y;
5675 x = workarea[2] - text_width - gap_x;
5676 y = workarea[3] - text_height - gap_y;
5680 x = workarea[2] / 2 - text_width / 2 - gap_x;
5681 y = workarea[3] - text_height - gap_y;
5686 y = workarea[3] / 2 - text_height / 2 - gap_y;
5690 x = workarea[2] - text_width - gap_x;
5691 y = workarea[3] / 2 - text_height / 2 - gap_y;
5695 case NONE: // Let the WM manage the window
5706 if (own_window && !fixed_pos) {
5709 text_start_x = border_margin + 1;
5710 text_start_y = border_margin + 1;
5711 window.x = x - border_margin - 1;
5712 window.y = y - border_margin - 1;
5716 /* If window size doesn't match to workarea's size,
5717 * then window probably includes panels (gnome).
5718 * Blah, doesn't work on KDE. */
5719 if (workarea[2] != window.width || workarea[3] != window.height) {
5731 static int cur_x, cur_y; /* current x and y for drawing */
5733 //draw_mode also without X11 because we only need to print to stdout with FG
5734 static int draw_mode; /* FG, BG or OUTLINE */
5736 static long current_color;
5738 static void text_size_updater(char *s)
5743 if ((output_methods & TO_X) == 0)
5745 /* get string widths and skip specials */
5748 if (*p == SPECIAL_CHAR) {
5750 w += get_string_width(s);
5753 if (specials[special_index].type == BAR
5754 || specials[special_index].type == GAUGE
5755 || specials[special_index].type == GRAPH) {
5756 w += specials[special_index].width;
5757 if (specials[special_index].height > last_font_height) {
5758 last_font_height = specials[special_index].height;
5759 last_font_height += font_height();
5761 } else if (specials[special_index].type == OFFSET) {
5762 if (specials[special_index].arg > 0) {
5763 w += specials[special_index].arg;
5765 } else if (specials[special_index].type == VOFFSET) {
5766 last_font_height += specials[special_index].arg;
5767 } else if (specials[special_index].type == GOTO) {
5768 if (specials[special_index].arg > cur_x) {
5769 w = (int) specials[special_index].arg;
5771 } else if (specials[special_index].type == TAB) {
5772 int start = specials[special_index].arg;
5773 int step = specials[special_index].width;
5775 if (!step || step < 0) {
5778 w += step - (cur_x - text_start_x - start) % step;
5779 } else if (specials[special_index].type == FONT) {
5780 selected_font = specials[special_index].font_added;
5781 if (font_height() > last_font_height) {
5782 last_font_height = font_height();
5791 w += get_string_width(s);
5792 if (w > text_width) {
5795 if (text_width > maximum_width && maximum_width) {
5796 text_width = maximum_width;
5799 text_height += last_font_height;
5800 last_font_height = font_height();
5803 static inline void set_foreground_color(long c)
5805 if ((output_methods & TO_X) == 0)
5808 XSetForeground(display, window.gc, c);
5812 static void draw_string(const char *s)
5814 int i, i2, pos, width_of_s;
5822 width_of_s = get_string_width(s);
5823 if ((output_methods & TO_STDOUT) && draw_mode == FG) {
5825 fflush(stdout); /* output immediately, don't buffer */
5827 if ((output_methods & TO_STDERR) && draw_mode == FG) {
5828 fprintf(stderr, "%s\n", s);
5829 fflush(stderr); /* output immediately, don't buffer */
5831 if ((output_methods & OVERWRITE_FILE) && draw_mode == FG && overwrite_fpointer) {
5832 fprintf(overwrite_fpointer, "%s\n", s);
5834 if ((output_methods & APPEND_FILE) && draw_mode == FG && append_fpointer) {
5835 fprintf(append_fpointer, "%s\n", s);
5837 memset(tmpstring1, 0, text_buffer_size);
5838 memset(tmpstring2, 0, text_buffer_size);
5839 strncpy(tmpstring1, s, text_buffer_size - 1);
5844 if (output_methods & TO_X) {
5845 max = ((text_width - width_of_s) / get_string_width(" "));
5848 /* This code looks for tabs in the text and coverts them to spaces.
5849 * The trick is getting the correct number of spaces, and not going
5850 * over the window's size without forcing the window larger. */
5851 for (i = 0; i < (int) text_buffer_size; i++) {
5852 if (tmpstring1[i] == '\t') {
5854 for (i2 = 0; i2 < (8 - (1 + pos) % 8) && added <= max; i2++) {
5855 /* guard against overrun */
5856 tmpstring2[MIN(pos + i2, (int)text_buffer_size - 1)] = ' ';
5861 /* guard against overrun */
5862 tmpstring2[MIN(pos, (int) text_buffer_size - 1)] = tmpstring1[i];
5867 if (output_methods & TO_X) {
5868 if (text_width == maximum_width) {
5869 /* this means the text is probably pushing the limit,
5870 * so we'll chop it */
5871 while (cur_x + get_string_width(tmpstring2) - text_start_x
5872 > maximum_width && strlen(tmpstring2) > 0) {
5873 tmpstring2[strlen(tmpstring2) - 1] = '\0';
5880 if (output_methods & TO_X) {
5886 c.pixel = current_color;
5887 XQueryColor(display, DefaultColormap(display, screen), &c);
5890 c2.color.red = c.red;
5891 c2.color.green = c.green;
5892 c2.color.blue = c.blue;
5893 c2.color.alpha = fonts[selected_font].font_alpha;
5895 XftDrawStringUtf8(window.xftdraw, &c2, fonts[selected_font].xftfont,
5896 cur_x, cur_y, (const XftChar8 *) s, strlen(s));
5898 XftDrawString8(window.xftdraw, &c2, fonts[selected_font].xftfont,
5899 cur_x, cur_y, (const XftChar8 *) s, strlen(s));
5904 XDrawString(display, window.drawable, window.gc, cur_x, cur_y, s,
5907 cur_x += width_of_s;
5910 memcpy(tmpstring1, s, text_buffer_size);
5913 static void draw_line(char *s)
5922 if ((output_methods & TO_X) == 0) {
5927 cur_x = text_start_x;
5928 cur_y += font_ascent();
5929 font_h = font_height();
5931 /* find specials and draw stuff */
5934 if (*p == SPECIAL_CHAR) {
5937 /* draw string before special */
5944 switch (specials[special_index].type) {
5945 case HORIZONTAL_LINE:
5947 int h = specials[special_index].height;
5948 int mid = font_ascent() / 2;
5950 w = text_start_x + text_width - cur_x;
5952 XSetLineAttributes(display, window.gc, h, LineSolid,
5953 CapButt, JoinMiter);
5954 XDrawLine(display, window.drawable, window.gc, cur_x,
5955 cur_y - mid / 2, cur_x + w, cur_y - mid / 2);
5961 int h = specials[special_index].height;
5962 int tmp_s = specials[special_index].arg;
5963 int mid = font_ascent() / 2;
5964 char ss[2] = { tmp_s, tmp_s };
5966 w = text_start_x + text_width - cur_x - 1;
5967 XSetLineAttributes(display, window.gc, h, LineOnOffDash,
5968 CapButt, JoinMiter);
5969 XSetDashes(display, window.gc, 0, ss, 2);
5970 XDrawLine(display, window.drawable, window.gc, cur_x,
5971 cur_y - mid / 2, cur_x + w, cur_y - mid / 2);
5977 int h, bar_usage, by;
5978 if (cur_x - text_start_x > maximum_width
5979 && maximum_width > 0) {
5982 h = specials[special_index].height;
5983 bar_usage = specials[special_index].arg;
5984 by = cur_y - (font_ascent() / 2) - 1;
5989 w = specials[special_index].width;
5991 w = text_start_x + text_width - cur_x - 1;
5997 XSetLineAttributes(display, window.gc, 1, LineSolid,
5998 CapButt, JoinMiter);
6000 XDrawRectangle(display, window.drawable, window.gc, cur_x,
6002 XFillRectangle(display, window.drawable, window.gc, cur_x,
6003 by, w * bar_usage / 255, h);
6011 case GAUGE: /* new GAUGE */
6014 unsigned long last_colour = current_color;
6015 float angle, px, py;
6018 if (cur_x - text_start_x > maximum_width
6019 && maximum_width > 0) {
6023 h = specials[special_index].height;
6024 by = cur_y - (font_ascent() / 2) - 1;
6029 w = specials[special_index].width;
6031 w = text_start_x + text_width - cur_x - 1;
6037 XSetLineAttributes(display, window.gc, 1, LineSolid,
6038 CapButt, JoinMiter);
6040 XDrawArc(display, window.drawable, window.gc,
6041 cur_x, by, w, h * 2, 0, 180*64);
6044 usage = specials[special_index].arg;
6045 angle = (M_PI)*(float)(usage)/255.;
6046 px = (float)(cur_x+(w/2.))-(float)(w/2.)*cos(angle);
6047 py = (float)(by+(h))-(float)(h)*sin(angle);
6049 XDrawLine(display, window.drawable, window.gc,
6050 cur_x + (w/2.), by+(h), (int)(px), (int)(py));
6058 set_foreground_color(last_colour);
6066 int h, by, i = 0, j = 0;
6068 unsigned long last_colour = current_color;
6069 unsigned long *tmpcolour = 0;
6070 if (cur_x - text_start_x > maximum_width
6071 && maximum_width > 0) {
6074 h = specials[special_index].height;
6075 by = cur_y - (font_ascent() / 2) - 1;
6080 w = specials[special_index].width;
6082 w = text_start_x + text_width - cur_x - 1;
6087 if (draw_graph_borders) {
6088 XSetLineAttributes(display, window.gc, 1, LineSolid,
6089 CapButt, JoinMiter);
6090 XDrawRectangle(display, window.drawable, window.gc,
6093 XSetLineAttributes(display, window.gc, 1, LineSolid,
6094 CapButt, JoinMiter);
6096 if (specials[special_index].last_colour != 0
6097 || specials[special_index].first_colour != 0) {
6098 tmpcolour = do_gradient(w - 1, specials[special_index].last_colour, specials[special_index].first_colour);
6101 for (i = w - 2; i > -1; i--) {
6102 if (specials[special_index].last_colour != 0
6103 || specials[special_index].first_colour != 0) {
6104 if (specials[special_index].tempgrad) {
6107 (int)((float)(w - 2) - specials[special_index].graph[j] *
6108 (w - 2) / (float)specials[special_index].graph_scale)
6112 (int)((float)(w - 2) - specials[special_index].graph[j] *
6113 (w - 2) / (float)specials[special_index].graph_scale)
6116 if (specials[special_index].graph[j] == specials[special_index].graph_scale) {
6118 (int)((float)(w - 2) - specials[special_index].graph[j] *
6119 (w - 2) / (float)specials[special_index].graph_scale)
6123 #endif /* DEBUG_lol */
6124 XSetForeground(display, window.gc, tmpcolour[
6125 (int)((float)(w - 2) - specials[special_index].graph[j] *
6126 (w - 2) / (float)specials[special_index].graph_scale)
6129 XSetForeground(display, window.gc, tmpcolour[colour_idx++]);
6132 /* this is mugfugly, but it works */
6133 XDrawLine(display, window.drawable, window.gc,
6134 cur_x + i + 1, by + h, cur_x + i + 1,
6135 round_to_int((double)by + h - specials[special_index].graph[j] *
6136 (h - 1) / specials[special_index].graph_scale));
6137 if ((w - i) / ((float) (w - 2) /
6138 (specials[special_index].graph_width)) > j
6139 && j < MAX_GRAPH_DEPTH - 3) {
6143 if (tmpcolour) free(tmpcolour);
6148 /* if (draw_mode == BG) {
6149 set_foreground_color(default_bg_color);
6150 } else if (draw_mode == OUTLINE) {
6151 set_foreground_color(default_out_color);
6153 set_foreground_color(default_fg_color);
6155 if (show_graph_range) {
6158 unsigned short int seconds = update_interval * w;
6163 unsigned short int timeunits;
6165 timeunits = seconds / 86400; seconds %= 86400;
6166 if (timeunits > 0) {
6167 asprintf(&tmp_day_str, "%dd", timeunits);
6169 tmp_day_str = strdup("");
6171 timeunits = seconds / 3600; seconds %= 3600;
6172 if (timeunits > 0) {
6173 asprintf(&tmp_hour_str, "%dh", timeunits);
6175 tmp_hour_str = strdup("");
6177 timeunits = seconds / 60; seconds %= 60;
6178 if (timeunits > 0) {
6179 asprintf(&tmp_min_str, "%dm", timeunits);
6181 tmp_min_str = strdup("");
6184 asprintf(&tmp_sec_str, "%ds", seconds);
6186 tmp_sec_str = strdup("");
6188 asprintf(&tmp_str, "%s%s%s%s", tmp_day_str, tmp_hour_str, tmp_min_str, tmp_sec_str);
6189 free(tmp_day_str); free(tmp_hour_str); free(tmp_min_str); free(tmp_sec_str);
6191 asprintf(&tmp_str, "Range not possible"); // should never happen, but better safe then sorry
6193 cur_x += (w / 2) - (font_ascent() * (strlen(tmp_str) / 2));
6194 cur_y += font_h / 2;
6195 draw_string(tmp_str);
6201 if (show_graph_scale && (specials[special_index].show_scale == 1)) {
6204 cur_x += font_ascent() / 2;
6205 cur_y += font_h / 2;
6207 calloc(log10(floor(specials[special_index].graph_scale)) + 4,
6209 sprintf(tmp_str, "%.1f", specials[special_index].graph_scale);
6210 draw_string(tmp_str);
6216 set_foreground_color(last_colour);
6222 int old = font_ascent();
6224 cur_y -= font_ascent();
6225 selected_font = specials[special_index].font_added;
6226 if (cur_y + font_ascent() < cur_y + old) {
6229 cur_y += font_ascent();
6232 font_h = font_height();
6236 if (draw_mode == FG) {
6237 set_foreground_color(specials[special_index].arg);
6242 if (draw_mode == BG) {
6243 set_foreground_color(specials[special_index].arg);
6248 if (draw_mode == OUTLINE) {
6249 set_foreground_color(specials[special_index].arg);
6254 w += specials[special_index].arg;
6258 cur_y += specials[special_index].arg;
6262 if (specials[special_index].arg >= 0) {
6263 cur_x = (int) specials[special_index].arg;
6269 int start = specials[special_index].arg;
6270 int step = specials[special_index].width;
6272 if (!step || step < 0) {
6275 w = step - (cur_x - text_start_x - start) % step;
6281 /* TODO: add back in "+ border_margin" to the end of
6283 int pos_x = text_start_x + text_width -
6284 get_string_width_special(s);
6286 /* printf("pos_x %i text_start_x %i text_width %i cur_x %i "
6287 "get_string_width(p) %i gap_x %i "
6288 "specials[special_index].arg %i border_margin %i "
6289 "border_width %i\n", pos_x, text_start_x, text_width,
6290 cur_x, get_string_width_special(s), gap_x,
6291 specials[special_index].arg, border_margin,
6293 if (pos_x > specials[special_index].arg && pos_x > cur_x) {
6294 cur_x = pos_x - specials[special_index].arg;
6301 int pos_x = (text_width) / 2 - get_string_width_special(s) /
6302 2 - (cur_x - text_start_x);
6303 /* int pos_x = text_start_x + text_width / 2 -
6304 get_string_width_special(s) / 2; */
6306 /* printf("pos_x %i text_start_x %i text_width %i cur_x %i "
6307 "get_string_width(p) %i gap_x %i "
6308 "specials[special_index].arg %i\n", pos_x, text_start_x,
6309 text_width, cur_x, get_string_width(s), gap_x,
6310 specials[special_index].arg); */
6311 if (pos_x > specials[special_index].arg) {
6312 w = pos_x - specials[special_index].arg;
6326 if (cur_y_add > 0) {
6330 cur_y += font_descent();
6335 static void draw_text(void)
6338 if (output_methods & TO_X) {
6339 cur_y = text_start_y;
6342 if (draw_borders && border_width > 0) {
6343 unsigned int b = (border_width + 1) / 2;
6345 if (stippled_borders) {
6346 char ss[2] = { stippled_borders, stippled_borders };
6347 XSetLineAttributes(display, window.gc, border_width, LineOnOffDash,
6348 CapButt, JoinMiter);
6349 XSetDashes(display, window.gc, 0, ss, 2);
6351 XSetLineAttributes(display, window.gc, border_width, LineSolid,
6352 CapButt, JoinMiter);
6355 XDrawRectangle(display, window.drawable, window.gc,
6356 text_start_x - border_margin + b, text_start_y - border_margin + b,
6357 text_width + border_margin * 2 - 1 - b * 2,
6358 text_height + border_margin * 2 - 1 - b * 2);
6365 for_each_line(text_buffer, draw_line);
6368 static void draw_stuff(void)
6370 if (overwrite_file) {
6371 overwrite_fpointer = fopen(overwrite_file, "w");
6372 if(!overwrite_fpointer)
6373 ERR("Can't overwrite '%s' anymore", overwrite_file);
6376 append_fpointer = fopen(append_file, "a");
6377 if(!append_fpointer)
6378 ERR("Can't append '%s' anymore", append_file);
6381 if (output_methods & TO_X) {
6383 if (draw_shades && !draw_outline) {
6386 set_foreground_color(default_bg_color);
6397 for (i = -1; i < 2; i++) {
6398 for (j = -1; j < 2; j++) {
6399 if (i == 0 && j == 0) {
6404 set_foreground_color(default_out_color);
6405 draw_mode = OUTLINE;
6413 set_foreground_color(default_fg_color);
6419 if (output_methods & TO_X) {
6424 swap.swap_window = window.window;
6425 swap.swap_action = XdbeBackground;
6426 XdbeSwapBuffers(display, &swap, 1);
6431 if(overwrite_fpointer) {
6432 fclose(overwrite_fpointer);
6433 overwrite_fpointer = 0;
6435 if(append_fpointer) {
6436 fclose(append_fpointer);
6437 append_fpointer = 0;
6442 static void clear_text(int exposures)
6446 /* The swap action is XdbeBackground, which clears */
6451 /* there is some extra space for borders and outlines */
6452 XClearArea(display, window.window, text_start_x - border_margin - 1,
6453 text_start_y - border_margin - 1,
6454 text_width + border_margin * 2 + 2,
6455 text_height + border_margin * 2 + 2, exposures ? True : 0);
6460 static int need_to_update;
6462 /* update_text() generates new text and clears old text area */
6463 static void update_text(void)
6470 if (output_methods & TO_X)
6476 #ifdef HAVE_SYS_INOTIFY_H
6480 static void main_loop(void)
6482 #ifdef SIGNAL_BLOCKING
6483 sigset_t newmask, oldmask;
6486 #ifdef HAVE_SYS_INOTIFY_H
6487 int inotify_config_wd = 0;
6488 #define INOTIFY_EVENT_SIZE (sizeof(struct inotify_event))
6489 #define INOTIFY_BUF_LEN (20 * (INOTIFY_EVENT_SIZE + 16))
6490 char inotify_buff[INOTIFY_BUF_LEN];
6491 #endif /* HAVE_SYS_INOTIFY_H */
6494 #ifdef SIGNAL_BLOCKING
6495 sigemptyset(&newmask);
6496 sigaddset(&newmask, SIGINT);
6497 sigaddset(&newmask, SIGTERM);
6498 sigaddset(&newmask, SIGUSR1);
6501 next_update_time = last_update_time = get_time();
6503 while (total_run_times == 0 || info.looped < total_run_times) {
6506 #ifdef SIGNAL_BLOCKING
6507 /* block signals. we will inspect for pending signals later */
6508 if (sigprocmask(SIG_BLOCK, &newmask, &oldmask) < 0) {
6509 CRIT_ERR("unable to sigprocmask()");
6514 if (output_methods & TO_X) {
6517 /* wait for X event or timeout */
6519 if (!XPending(display)) {
6523 t = next_update_time - get_time();
6527 } else if (t > update_interval) {
6528 t = update_interval;
6531 tv.tv_sec = (long) t;
6532 tv.tv_usec = (long) (t * 1000000) % 1000000;
6534 FD_SET(ConnectionNumber(display), &fdsr);
6536 s = select(ConnectionNumber(display) + 1, &fdsr, 0, 0, &tv);
6538 if (errno != EINTR) {
6539 ERR("can't select(): %s", strerror(errno));
6549 if (need_to_update) {
6551 int wx = window.x, wy = window.y;
6559 /* resize window if it isn't right size */
6561 && (text_width + border_margin * 2 + 1 != window.width
6562 || text_height + border_margin * 2 + 1 != window.height)) {
6563 window.width = text_width + border_margin * 2 + 1;
6564 window.height = text_height + border_margin * 2 + 1;
6565 XResizeWindow(display, window.window, window.width,
6568 set_transparent_background(window.window);
6572 /* move window if it isn't in right position */
6573 if (!fixed_pos && (window.x != wx || window.y != wy)) {
6574 XMoveWindow(display, window.window, window.x, window.y);
6585 r.x = text_start_x - border_margin;
6586 r.y = text_start_y - border_margin;
6587 r.width = text_width + border_margin * 2;
6588 r.height = text_height + border_margin * 2;
6589 XUnionRectWithRegion(&r, x11_stuff.region, x11_stuff.region);
6594 /* handle X events */
6595 while (XPending(display)) {
6598 XNextEvent(display, &ev);
6605 r.width = ev.xexpose.width;
6606 r.height = ev.xexpose.height;
6607 XUnionRectWithRegion(&r, x11_stuff.region, x11_stuff.region);
6612 case ReparentNotify:
6613 /* set background to ParentRelative for all parents */
6615 set_transparent_background(window.window);
6619 case ConfigureNotify:
6621 /* if window size isn't what expected, set fixed size */
6622 if (ev.xconfigure.width != window.width
6623 || ev.xconfigure.height != window.height) {
6624 if (window.width != 0 && window.height != 0) {
6628 /* clear old stuff before screwing up
6633 XWindowAttributes attrs;
6634 if (XGetWindowAttributes(display,
6635 window.window, &attrs)) {
6636 window.width = attrs.width;
6637 window.height = attrs.height;
6641 text_width = window.width - border_margin * 2 - 1;
6642 text_height = window.height - border_margin * 2 - 1;
6643 if (text_width > maximum_width
6644 && maximum_width > 0) {
6645 text_width = maximum_width;
6649 /* if position isn't what expected, set fixed pos
6650 * total_updates avoids setting fixed_pos when window
6651 * is set to weird locations when started */
6652 /* // this is broken
6653 if (total_updates >= 2 && !fixed_pos
6654 && (window.x != ev.xconfigure.x
6655 || window.y != ev.xconfigure.y)
6656 && (ev.xconfigure.x != 0
6657 || ev.xconfigure.y != 0)) {
6666 /* if an ordinary window with decorations */
6667 if ((window.type == TYPE_NORMAL)
6668 && (!TEST_HINT(window.hints,
6669 HINT_UNDECORATED))) {
6670 /* allow conky to hold input focus. */
6673 /* forward the click to the desktop window */
6674 XUngrabPointer(display, ev.xbutton.time);
6675 ev.xbutton.window = window.desktop;
6676 XSendEvent(display, ev.xbutton.window, False,
6677 ButtonPressMask, &ev);
6678 XSetInputFocus(display, ev.xbutton.window,
6679 RevertToParent, ev.xbutton.time);
6686 /* if an ordinary window with decorations */
6687 if ((window.type == TYPE_NORMAL)
6688 && (!TEST_HINT(window.hints,
6689 HINT_UNDECORATED))) {
6690 /* allow conky to hold input focus. */
6693 /* forward the release to the desktop window */
6694 ev.xbutton.window = window.desktop;
6695 XSendEvent(display, ev.xbutton.window, False,
6696 ButtonReleaseMask, &ev);
6705 if (ev.type == x11_stuff.event_base + XDamageNotify) {
6706 XDamageNotifyEvent *dev = (XDamageNotifyEvent *) &ev;
6708 XFixesSetRegion(display, x11_stuff.part, &dev->area, 1);
6709 XFixesUnionRegion(display, x11_stuff.region2, x11_stuff.region2, x11_stuff.part);
6711 #endif /* HAVE_XDAMAGE */
6717 XDamageSubtract(display, x11_stuff.damage, x11_stuff.region2, None);
6718 XFixesSetRegion(display, x11_stuff.region2, 0, 0);
6719 #endif /* HAVE_XDAMAGE */
6721 /* XDBE doesn't seem to provide a way to clear the back buffer without
6722 * interfering with the front buffer, other than passing XdbeBackground
6723 * to XdbeSwapBuffers. That means that if we're using XDBE, we need to
6724 * redraw the text even if it wasn't part of the exposed area. OTOH,
6725 * if we're not going to call draw_stuff at all, then no swap happens
6726 * and we can safely do nothing. */
6728 if (!XEmptyRegion(x11_stuff.region)) {
6733 r.x = text_start_x - border_margin;
6734 r.y = text_start_y - border_margin;
6735 r.width = text_width + border_margin * 2;
6736 r.height = text_height + border_margin * 2;
6737 XUnionRectWithRegion(&r, x11_stuff.region, x11_stuff.region);
6740 XSetRegion(display, window.gc, x11_stuff.region);
6743 XftDrawSetClip(window.xftdraw, x11_stuff.region);
6747 cimlib_render(text_start_x, text_start_y, window.width, window.height);
6750 XDestroyRegion(x11_stuff.region);
6751 x11_stuff.region = XCreateRegion();
6755 t = (next_update_time - get_time()) * 1000000;
6756 if(t > 0) usleep((useconds_t)t);
6763 #ifdef SIGNAL_BLOCKING
6764 /* unblock signals of interest and let handler fly */
6765 if (sigprocmask(SIG_SETMASK, &oldmask, NULL) < 0) {
6766 CRIT_ERR("unable to sigprocmask()");
6770 switch (g_signal_pending) {
6773 ERR("received SIGHUP or SIGUSR1. reloading the config file.");
6778 ERR("received SIGINT or SIGTERM to terminate. bye!");
6781 if (output_methods & TO_X) {
6782 XDestroyRegion(x11_stuff.region);
6783 x11_stuff.region = NULL;
6785 XDamageDestroy(display, x11_stuff.damage);
6786 XFixesDestroyRegion(display, x11_stuff.region2);
6787 XFixesDestroyRegion(display, x11_stuff.part);
6788 #endif /* HAVE_XDAMAGE */
6791 if(overwrite_file) {
6792 free(overwrite_file);
6799 return; /* return from main_loop */
6802 /* Reaching here means someone set a signal
6803 * (SIGXXXX, signal_handler), but didn't write any code
6805 * If you don't want to handle a signal, don't set a handler on
6806 * it in the first place. */
6807 if (g_signal_pending) {
6808 ERR("ignoring signal (%d)", g_signal_pending);
6812 #ifdef HAVE_SYS_INOTIFY_H
6813 if (inotify_fd && !inotify_config_wd) {
6814 inotify_config_wd = inotify_add_watch(inotify_fd,
6818 if (inotify_fd && inotify_config_wd) {
6819 int len = 0, idx = 0;
6821 struct timeval time_to_wait;
6823 FD_ZERO (&descriptors);
6824 FD_SET(inotify_fd, &descriptors);
6826 time_to_wait.tv_sec = time_to_wait.tv_usec = 0;
6828 select(inotify_fd + 1, &descriptors, NULL, NULL, &time_to_wait);
6829 if (FD_ISSET(inotify_fd, &descriptors)) {
6830 /* process inotify events */
6831 len = read(inotify_fd, inotify_buff, INOTIFY_BUF_LEN);
6832 while (len > 0 && idx < len) {
6833 struct inotify_event *ev = (struct inotify_event *) &inotify_buff[idx];
6834 if (ev->wd == inotify_config_wd && (ev->mask & IN_MODIFY || ev->mask & IN_IGNORED)) {
6835 /* current_config should be reloaded */
6836 ERR("'%s' modified, reloading...", current_config);
6838 if (ev->mask & IN_IGNORED) {
6839 /* for some reason we get IN_IGNORED here
6840 * sometimes, so we need to re-add the watch */
6841 inotify_config_wd = inotify_add_watch(inotify_fd,
6848 llua_inotify_query(ev->wd, ev->mask);
6850 #endif /* HAVE_LUA */
6851 idx += INOTIFY_EVENT_SIZE + ev->len;
6855 #endif /* HAVE_SYS_INOTIFY_H */
6857 g_signal_pending = 0;
6860 #ifdef HAVE_SYS_INOTIFY_H
6862 inotify_rm_watch(inotify_fd, inotify_config_wd);
6864 inotify_fd = inotify_config_wd = 0;
6866 #endif /* HAVE_SYS_INOTIFY_H */
6868 #if defined(X11) && defined(HAVE_XDAMAGE)
6869 X11_destroy_window();
6870 #endif /* X11 && HAVE_XDAMAGE */
6873 static void load_config_file(const char *);
6874 static void load_config_file_x11(const char *);
6876 /* reload the config file */
6877 static void reload_config(void)
6879 timed_thread_destroy_registered_threads();
6881 if (info.cpu_usage) {
6882 free(info.cpu_usage);
6883 info.cpu_usage = NULL;
6894 #ifdef TCP_PORT_MONITOR
6895 tcp_portmon_clear();
6900 #endif /* HAVE_LUA */
6903 X11_destroy_window();
6906 if (current_config) {
6908 load_config_file(current_config);
6909 load_config_file_x11(current_config);
6911 /* re-init specials array */
6912 if ((specials = realloc((void *) specials,
6913 sizeof(struct special_t) * max_specials)) == 0) {
6914 ERR("failed to realloc specials array");
6920 extract_variable_text(global_text);
6926 tmpstring1 = malloc(text_buffer_size);
6927 memset(tmpstring1, 0, text_buffer_size);
6931 tmpstring2 = malloc(text_buffer_size);
6932 memset(tmpstring2, 0, text_buffer_size);
6936 text_buffer = malloc(max_user_text);
6937 memset(text_buffer, 0, max_user_text);
6940 X11_create_window();
6945 static void clean_up(void)
6947 timed_thread_destroy_registered_threads();
6949 if (info.cpu_usage) {
6950 free(info.cpu_usage);
6951 info.cpu_usage = NULL;
6954 if (output_methods & TO_X) {
6957 XdbeDeallocateBackBufferName(display, window.back_buffer);
6962 XDestroyWindow(display, window.window);
6963 XClearWindow(display, RootWindow(display, screen));
6968 XClearWindow(display, RootWindow(display, screen));
6973 XFreeGC(display, window.gc);
6979 free_text_objects(&global_root_object, 0);
6998 free(current_config);
7000 #ifdef TCP_PORT_MONITOR
7001 tcp_portmon_clear();
7008 #endif /* HAVE_LUA */
7013 for (i = 0; i < special_count; i++) {
7014 if (specials[i].type == GRAPH) {
7015 free(specials[i].graph);
7022 clear_diskio_stats();
7025 static int string_to_bool(const char *s)
7028 // Assumes an option without a true/false means true
7030 } else if (strcasecmp(s, "yes") == EQUAL) {
7032 } else if (strcasecmp(s, "true") == EQUAL) {
7034 } else if (strcasecmp(s, "1") == EQUAL) {
7041 static enum alignment string_to_alignment(const char *s)
7043 if (strcasecmp(s, "top_left") == EQUAL) {
7045 } else if (strcasecmp(s, "top_right") == EQUAL) {
7047 } else if (strcasecmp(s, "top_middle") == EQUAL) {
7049 } else if (strcasecmp(s, "bottom_left") == EQUAL) {
7051 } else if (strcasecmp(s, "bottom_right") == EQUAL) {
7052 return BOTTOM_RIGHT;
7053 } else if (strcasecmp(s, "bottom_middle") == EQUAL) {
7054 return BOTTOM_MIDDLE;
7055 } else if (strcasecmp(s, "middle_left") == EQUAL) {
7057 } else if (strcasecmp(s, "middle_right") == EQUAL) {
7058 return MIDDLE_RIGHT;
7059 } else if (strcasecmp(s, "tl") == EQUAL) {
7061 } else if (strcasecmp(s, "tr") == EQUAL) {
7063 } else if (strcasecmp(s, "tm") == EQUAL) {
7065 } else if (strcasecmp(s, "bl") == EQUAL) {
7067 } else if (strcasecmp(s, "br") == EQUAL) {
7068 return BOTTOM_RIGHT;
7069 } else if (strcasecmp(s, "bm") == EQUAL) {
7070 return BOTTOM_MIDDLE;
7071 } else if (strcasecmp(s, "ml") == EQUAL) {
7073 } else if (strcasecmp(s, "mr") == EQUAL) {
7074 return MIDDLE_RIGHT;
7075 } else if (strcasecmp(s, "none") == EQUAL) {
7083 static void set_default_configurations_for_x(void)
7085 default_fg_color = WhitePixel(display, screen);
7086 default_bg_color = BlackPixel(display, screen);
7087 default_out_color = BlackPixel(display, screen);
7088 color0 = default_fg_color;
7089 color1 = default_fg_color;
7090 color2 = default_fg_color;
7091 color3 = default_fg_color;
7092 color4 = default_fg_color;
7093 color5 = default_fg_color;
7094 color6 = default_fg_color;
7095 color7 = default_fg_color;
7096 color8 = default_fg_color;
7097 color9 = default_fg_color;
7101 static void set_default_configurations(void)
7104 fork_to_background = 0;
7105 total_run_times = 0;
7106 info.cpu_avg_samples = 2;
7107 info.net_avg_samples = 2;
7108 info.diskio_avg_samples = 2;
7116 mpd_set_host("localhost");
7117 mpd_set_port("6600");
7120 info.xmms2.artist = NULL;
7121 info.xmms2.album = NULL;
7122 info.xmms2.title = NULL;
7123 info.xmms2.genre = NULL;
7124 info.xmms2.comment = NULL;
7125 info.xmms2.url = NULL;
7126 info.xmms2.status = NULL;
7127 info.xmms2.playlist = NULL;
7129 use_spacer = NO_SPACER;
7131 output_methods = TO_X;
7133 output_methods = TO_STDOUT;
7136 show_graph_scale = 0;
7137 show_graph_range = 0;
7138 template[0] = strdup("");
7139 template[1] = strdup("");
7140 template[2] = strdup("");
7141 template[3] = strdup("");
7142 template[4] = strdup("");
7143 template[5] = strdup("");
7144 template[6] = strdup("");
7145 template[7] = strdup("");
7146 template[8] = strdup("");
7147 template[9] = strdup("");
7150 draw_graph_borders = 1;
7152 set_first_font("6x10");
7160 window.type = TYPE_NORMAL;
7162 strcpy(window.class_name, PACKAGE_NAME);
7163 sprintf(window.title, PACKAGE_NAME" (%s)", info.uname_s.nodename);
7165 stippled_borders = 0;
7168 text_alignment = BOTTOM_LEFT;
7169 info.x11.monitor.number = 1;
7170 info.x11.monitor.current = 0;
7173 free(current_mail_spool);
7177 variable_substitute(MAIL_FILE, buf, 256);
7178 if (buf[0] != '\0') {
7179 current_mail_spool = strndup(buf, text_buffer_size);
7184 update_interval = 3.0;
7185 info.music_player_interval = 1.0;
7186 stuff_in_upper_case = 0;
7187 info.users.number = 1;
7189 #ifdef TCP_PORT_MONITOR
7190 /* set default connection limit */
7191 tcp_portmon_set_max_connections(0);
7195 /* returns 1 if you can overwrite or create the file at 'path' */
7196 static _Bool overwrite_works(const char *path)
7200 if (!(filepointer = fopen(path, "w")))
7202 fclose(filepointer);
7206 /* returns 1 if you can append or create the file at 'path' */
7207 static _Bool append_works(const char *path)
7211 if (!(filepointer = fopen(path, "a")))
7213 fclose(filepointer);
7218 static void X11_initialisation(void)
7220 if (x_initialised == YES) return;
7221 output_methods |= TO_X;
7223 set_default_configurations_for_x();
7224 x_initialised = YES;
7227 static void X11_destroy_window(void)
7229 /* this function only exists for the sake of consistency */
7230 if (output_methods & TO_X) {
7232 XDamageDestroy(display, x11_stuff.damage);
7233 XFixesDestroyRegion(display, x11_stuff.region2);
7234 XFixesDestroyRegion(display, x11_stuff.part);
7235 XDestroyRegion(x11_stuff.region);
7236 x11_stuff.region = NULL;
7237 #endif /* HAVE_XDAMAGE */
7242 static char **xargv = 0;
7243 static int xargc = 0;
7245 static void X11_create_window(void)
7247 if (output_methods & TO_X) {
7249 init_window(own_window, text_width + border_margin * 2 + 1,
7250 text_height + border_margin * 2 + 1, set_transparent, background_colour,
7252 #else /* OWN_WINDOW */
7253 init_window(0, text_width + border_margin * 2 + 1,
7254 text_height + border_margin * 2 + 1, set_transparent, 0,
7256 #endif /* OWN_WINDOW */
7260 update_text_area(); /* to position text/window on screen */
7263 if (own_window && !fixed_pos) {
7264 XMoveWindow(display, window.window, window.x, window.y);
7267 set_transparent_background(window.window);
7276 x11_stuff.region = XCreateRegion();
7278 if (!XDamageQueryExtension(display, &x11_stuff.event_base, &x11_stuff.error_base)) {
7279 ERR("Xdamage extension unavailable");
7281 x11_stuff.damage = XDamageCreate(display, window.window, XDamageReportNonEmpty);
7282 x11_stuff.region2 = XFixesCreateRegionFromWindow(display, window.window, 0);
7283 x11_stuff.part = XFixesCreateRegionFromWindow(display, window.window, 0);
7284 #endif /* HAVE_XDAMAGE */
7287 update_text_area(); /* to get initial size of the window */
7292 #define CONF_ERR ERR("%s: %d: config file error", f, line)
7293 #define CONF_ERR2(a) ERR("%s: %d: config file error: %s", f, line, a)
7294 #define CONF2(a) if (strcasecmp(name, a) == 0)
7295 #define CONF(a) else CONF2(a)
7296 #define CONF3(a, b) else if (strcasecmp(name, a) == 0 \
7297 || strcasecmp(name, b) == 0)
7298 #define CONF_CONTINUE 1
7299 #define CONF_BREAK 2
7300 #define CONF_BUFF_SIZE 512
7302 static FILE *open_config_file(const char *f)
7304 #ifdef CONFIG_OUTPUT
7305 if (!strcmp(f, "==builtin==")) {
7306 #ifdef HAVE_FOPENCOOKIE
7307 return fopencookie(NULL, "r", conf_cookie);
7308 #endif /* HAVE_FOPENCOOKIE */
7310 #endif /* CONFIG_OUTPUT */
7311 return fopen(f, "r");
7314 static int do_config_step(int *line, FILE *fp, char *buf, char **name, char **value)
7318 if (fgets(buf, CONF_BUFF_SIZE, fp) == NULL) {
7321 remove_comments(buf);
7326 while (*p && isspace((int) *p)) {
7330 return CONF_CONTINUE; /* empty line */
7337 while (*p2 && !isspace((int) *p2)) {
7341 *p2 = '\0'; /* break at name's end */
7348 while (*p && isspace((int) *p)) {
7354 p2 = *value + strlen(*value);
7355 while (isspace((int) *(p2 - 1))) {
7364 static void load_config_file(const char *f)
7369 set_default_configurations();
7370 fp = open_config_file(f);
7374 DBGP("reading contents from config file '%s'", f);
7377 char buff[CONF_BUFF_SIZE], *name, *value;
7378 int ret = do_config_step(&line, fp, buff, &name, &value);
7379 if (ret == CONF_BREAK) {
7381 } else if (ret == CONF_CONTINUE) {
7387 /* don't listen if X is already initialised or
7388 * if we already know we don't want it */
7389 if(x_initialised == NO) {
7390 if (string_to_bool(value)) {
7391 output_methods &= TO_X;
7393 output_methods &= ~TO_X;
7394 x_initialised = NEVER;
7399 if (!value || x_initialised == YES) {
7404 disp = strdup(value);
7408 if (window.type == TYPE_DOCK)
7411 int a = string_to_alignment(value);
7422 CONF("background") {
7423 fork_to_background = string_to_bool(value);
7426 CONF2("background") {
7427 fork_to_background = string_to_bool(value);
7431 CONF("show_graph_scale") {
7432 show_graph_scale = string_to_bool(value);
7434 CONF("show_graph_range") {
7435 show_graph_range = string_to_bool(value);
7437 CONF("border_margin") {
7439 border_margin = strtol(value, 0, 0);
7444 CONF("border_width") {
7446 border_width = strtol(value, 0, 0);
7451 #define TEMPLATE_CONF(n) \
7452 CONF("template"#n) { \
7454 free(template[n]); \
7455 template[n] = strdup(value); \
7473 info.mail = parse_mail_args(IMAP_TYPE, value);
7480 info.mail = parse_mail_args(POP3_TYPE, value);
7485 CONF("default_bar_size") {
7488 if (sscanf(value, "%d %d", &default_bar_width, &default_bar_height) != 2) {
7495 CONF_ERR2("default_bar_size takes 2 integer arguments (ie. 'default_bar_size 0 6')")
7499 CONF("default_graph_size") {
7502 if (sscanf(value, "%d %d", &default_graph_width, &default_graph_height) != 2) {
7509 CONF_ERR2("default_graph_size takes 2 integer arguments (ie. 'default_graph_size 0 6')")
7512 CONF("default_gauge_size") {
7515 if (sscanf(value, "%d %d", &default_gauge_width, &default_gauge_height) != 2) {
7522 CONF_ERR2("default_gauge_size takes 2 integer arguments (ie. 'default_gauge_size 0 6')")
7529 mpd_set_host(value);
7535 if (value && mpd_set_port(value)) {
7539 CONF("mpd_password") {
7541 mpd_set_password(value);
7547 CONF("music_player_interval") {
7549 info.music_player_interval = strtod(value, 0);
7555 CONF("sensor_device") {
7557 sensor_device = strtol(value, 0, 0);
7563 CONF("cpu_avg_samples") {
7565 cpu_avg_samples = strtol(value, 0, 0);
7566 if (cpu_avg_samples < 1 || cpu_avg_samples > 14) {
7569 info.cpu_avg_samples = cpu_avg_samples;
7575 CONF("net_avg_samples") {
7577 net_avg_samples = strtol(value, 0, 0);
7578 if (net_avg_samples < 1 || net_avg_samples > 14) {
7581 info.net_avg_samples = net_avg_samples;
7587 CONF("diskio_avg_samples") {
7589 diskio_avg_samples = strtol(value, 0, 0);
7590 if (diskio_avg_samples < 1 || diskio_avg_samples > 14) {
7593 info.diskio_avg_samples = diskio_avg_samples;
7601 CONF("double_buffer") {
7602 use_xdbe = string_to_bool(value);
7606 CONF("override_utf8_locale") {
7607 utf8_mode = string_to_bool(value);
7609 CONF("draw_borders") {
7610 draw_borders = string_to_bool(value);
7612 CONF("draw_graph_borders") {
7613 draw_graph_borders = string_to_bool(value);
7615 CONF("draw_shades") {
7616 draw_shades = string_to_bool(value);
7618 CONF("draw_outline") {
7619 draw_outline = string_to_bool(value);
7622 CONF("out_to_console") {
7623 if(string_to_bool(value))
7624 output_methods |= TO_STDOUT;
7626 CONF("out_to_stderr") {
7627 if(string_to_bool(value))
7628 output_methods |= TO_STDERR;
7630 CONF("overwrite_file") {
7631 if(overwrite_file) {
7632 free(overwrite_file);
7635 if(overwrite_works(value)) {
7636 overwrite_file = strdup(value);
7637 output_methods |= OVERWRITE_FILE;
7639 ERR("overwrite_file won't be able to create/overwrite '%s'", value);
7641 CONF("append_file") {
7646 if(append_works(value)) {
7647 append_file = strdup(value);
7648 output_methods |= APPEND_FILE;
7650 ERR("append_file won't be able to create/append '%s'", value);
7652 CONF("use_spacer") {
7654 if (strcasecmp(value, "left") == EQUAL) {
7655 use_spacer = LEFT_SPACER;
7656 } else if (strcasecmp(value, "right") == EQUAL) {
7657 use_spacer = RIGHT_SPACER;
7658 } else if (strcasecmp(value, "none") == EQUAL) {
7659 use_spacer = NO_SPACER;
7661 use_spacer = string_to_bool(value);
7662 ERR("use_spacer should have an argument of left, right, or"
7663 " none. '%s' seems to be some form of '%s', so"
7664 " defaulting to %s.", value,
7665 use_spacer ? "true" : "false",
7666 use_spacer ? "right" : "none");
7668 use_spacer = RIGHT_SPACER;
7670 use_spacer = NO_SPACER;
7674 ERR("use_spacer should have an argument. Defaulting to right.");
7675 use_spacer = RIGHT_SPACER;
7681 use_xft = string_to_bool(value);
7685 set_first_font(value);
7689 if (value && font_count >= 0) {
7690 fonts[0].font_alpha = atof(value) * 65535.0;
7697 if (string_to_bool(value)) {
7698 ERR("Xft not enabled");
7702 /* xftfont silently ignored when no Xft */
7705 /* xftalpha is silently ignored when no Xft */
7710 set_first_font(value);
7718 gap_x = atoi(value);
7725 gap_y = atoi(value);
7731 CONF("mail_spool") {
7735 variable_substitute(value, buffer, 256);
7737 if (buffer[0] != '\0') {
7738 if (current_mail_spool) {
7739 free(current_mail_spool);
7741 current_mail_spool = strndup(buffer, text_buffer_size);
7748 CONF("minimum_size") {
7750 if (sscanf(value, "%d %d", &minimum_width, &minimum_height)
7752 if (sscanf(value, "%d", &minimum_width) != 1) {
7760 CONF("maximum_width") {
7762 if (sscanf(value, "%d", &maximum_width) != 1) {
7770 CONF("no_buffers") {
7771 no_buffers = string_to_bool(value);
7773 CONF("top_name_width") {
7775 if (sscanf(value, "%u", &top_name_width) != 1) {
7781 if (top_name_width >= max_user_text) {
7782 top_name_width = max_user_text - 1;
7785 CONF("top_cpu_separate") {
7786 cpu_separate = string_to_bool(value);
7788 CONF("short_units") {
7789 short_units = string_to_bool(value);
7791 CONF("pad_percents") {
7792 pad_percents = atoi(value);
7796 CONF("own_window") {
7798 own_window = string_to_bool(value);
7801 CONF("own_window_class") {
7803 memset(window.class_name, 0, sizeof(window.class_name));
7804 strncpy(window.class_name, value,
7805 sizeof(window.class_name) - 1);
7808 CONF("own_window_title") {
7810 memset(window.title, 0, sizeof(window.title));
7811 strncpy(window.title, value, sizeof(window.title) - 1);
7814 CONF("own_window_transparent") {
7816 set_transparent = string_to_bool(value);
7819 CONF("own_window_hints") {
7821 char *p_hint, *p_save;
7822 char delim[] = ", ";
7824 /* tokenize the value into individual hints */
7825 if ((p_hint = strtok_r(value, delim, &p_save)) != NULL) {
7827 /* fprintf(stderr, "hint [%s] parsed\n", p_hint); */
7828 if (strncmp(p_hint, "undecorate", 10) == EQUAL) {
7829 SET_HINT(window.hints, HINT_UNDECORATED);
7830 } else if (strncmp(p_hint, "below", 5) == EQUAL) {
7831 SET_HINT(window.hints, HINT_BELOW);
7832 } else if (strncmp(p_hint, "above", 5) == EQUAL) {
7833 SET_HINT(window.hints, HINT_ABOVE);
7834 } else if (strncmp(p_hint, "sticky", 6) == EQUAL) {
7835 SET_HINT(window.hints, HINT_STICKY);
7836 } else if (strncmp(p_hint, "skip_taskbar", 12) == EQUAL) {
7837 SET_HINT(window.hints, HINT_SKIP_TASKBAR);
7838 } else if (strncmp(p_hint, "skip_pager", 10) == EQUAL) {
7839 SET_HINT(window.hints, HINT_SKIP_PAGER);
7844 p_hint = strtok_r(NULL, delim, &p_save);
7845 } while (p_hint != NULL);
7851 CONF("own_window_type") {
7853 if (strncmp(value, "normal", 6) == EQUAL) {
7854 window.type = TYPE_NORMAL;
7855 } else if (strncmp(value, "desktop", 7) == EQUAL) {
7856 window.type = TYPE_DESKTOP;
7857 } else if (strncmp(value, "dock", 7) == EQUAL) {
7858 window.type = TYPE_DOCK;
7859 text_alignment = TOP_LEFT;
7860 } else if (strncmp(value, "override", 8) == EQUAL) {
7861 window.type = TYPE_OVERRIDE;
7870 CONF("stippled_borders") {
7872 stippled_borders = strtol(value, 0, 0);
7874 stippled_borders = 4;
7878 CONF("imlib_cache_size") {
7880 cimlib_set_cache_size(atoi(value));
7885 CONF("update_interval") {
7887 update_interval = strtod(value, 0);
7891 if (info.music_player_interval == 0) {
7892 // default to update_interval
7893 info.music_player_interval = update_interval;
7896 CONF("total_run_times") {
7898 total_run_times = strtod(value, 0);
7904 stuff_in_upper_case = string_to_bool(value);
7906 CONF("max_specials") {
7908 max_specials = atoi(value);
7913 CONF("max_user_text") {
7915 max_user_text = atoi(value);
7920 CONF("text_buffer_size") {
7922 text_buffer_size = atoi(value);
7923 if (text_buffer_size < DEFAULT_TEXT_BUFFER_SIZE) {
7924 ERR("text_buffer_size must be >=%i bytes", DEFAULT_TEXT_BUFFER_SIZE);
7925 text_buffer_size = DEFAULT_TEXT_BUFFER_SIZE;
7933 if(output_methods & TO_X) {
7934 X11_initialisation();
7943 global_text = (char *) malloc(1);
7944 global_text[0] = '\0';
7947 unsigned int l = strlen(global_text);
7949 char buf[CONF_BUFF_SIZE];
7951 if (fgets(buf, CONF_BUFF_SIZE, fp) == NULL) {
7957 if (bl >= 2 && buf[bl-2] == '\\' && buf[bl-1] == '\n') {
7965 /* Check for continuation of \\-\n. */
7966 if (l > 0 && buf[0] == '\n' && global_text[l-1] == '\\') {
7967 global_text[l-1] = '\0';
7971 global_text = (char *) realloc(global_text, l + bl + 1);
7972 strcat(global_text, buf);
7974 if (strlen(global_text) > max_user_text) {
7979 if (strlen(global_text) < 1) {
7980 CRIT_ERR("no text supplied in configuration; exiting");
7982 global_text_lines = line + 1;
7985 #ifdef TCP_PORT_MONITOR
7986 CONF("max_port_monitor_connections") {
7988 if (!value || (sscanf(value, "%d", &max) != 1)) {
7989 /* an error. use default, warn and continue. */
7990 tcp_portmon_set_max_connections(0);
7992 } else if (tcp_portmon_set_max_connections(max)) {
7993 /* max is < 0, default has been set*/
7998 CONF("if_up_strictness") {
8000 ERR("incorrect if_up_strictness value, defaulting to 'up'");
8001 ifup_strictness = IFUP_UP;
8002 } else if (strcasecmp(value, "up") == EQUAL) {
8003 ifup_strictness = IFUP_UP;
8004 } else if (strcasecmp(value, "link") == EQUAL) {
8005 ifup_strictness = IFUP_LINK;
8006 } else if (strcasecmp(value, "address") == EQUAL) {
8007 ifup_strictness = IFUP_ADDR;
8009 ERR("incorrect if_up_strictness value, defaulting to 'up'");
8010 ifup_strictness = IFUP_UP;
8014 CONF("temperature_unit") {
8016 ERR("config option 'temperature_unit' needs an argument, either 'celsius' or 'fahrenheit'");
8017 } else if (set_temp_output_unit(value)) {
8018 ERR("temperature_unit: incorrect argument");
8024 size_t maxlength = strlen(value); //+1 for terminating 0 not needed, 'cause of the space in the middle of value
8025 char *skey = malloc(maxlength);
8026 char *svalue = malloc(maxlength);
8028 if (sscanf(value, "%[0-9a-zA-Z_] %[^\n]", skey, svalue) == 2) {
8029 oldvalue = getenv(skey);
8030 if (oldvalue == NULL) {
8031 setenv(skey, svalue, 0);
8033 //PS: Don't free oldvalue, it's the real envvar, not a copy
8047 char *ptr = strtok(value, " ");
8050 ptr = strtok(NULL, " ");
8056 #endif /* HAVE_LUA */
8068 CONF("default_color"){}
8069 CONF3("default_shade_color", "default_shadecolor"){}
8070 CONF3("default_outline_color", "default_outlinecolor") {}
8071 CONF("own_window_colour") {}
8074 ERR("%s: %d: no such configuration: '%s'", f, line, name);
8080 if (info.music_player_interval == 0) {
8081 // default to update_interval
8082 info.music_player_interval = update_interval;
8084 if (!global_text) { // didn't supply any text
8085 CRIT_ERR("missing text block in configuration; exiting");
8089 static void load_config_file_x11(const char *f)
8094 fp = open_config_file(f);
8098 DBGP("reading contents from config file '%s'", f);
8101 char buff[CONF_BUFF_SIZE], *name, *value;
8102 int ret = do_config_step(&line, fp, buff, &name, &value);
8103 if (ret == CONF_BREAK) {
8105 } else if (ret == CONF_CONTINUE) {
8111 X11_initialisation();
8112 if (x_initialised == YES) {
8114 color0 = get_x11_color(value);
8121 X11_initialisation();
8122 if (x_initialised == YES) {
8124 color1 = get_x11_color(value);
8131 X11_initialisation();
8132 if (x_initialised == YES) {
8134 color2 = get_x11_color(value);
8141 X11_initialisation();
8142 if (x_initialised == YES) {
8144 color3 = get_x11_color(value);
8151 X11_initialisation();
8152 if (x_initialised == YES) {
8154 color4 = get_x11_color(value);
8161 X11_initialisation();
8162 if (x_initialised == YES) {
8164 color5 = get_x11_color(value);
8171 X11_initialisation();
8172 if (x_initialised == YES) {
8174 color6 = get_x11_color(value);
8181 X11_initialisation();
8182 if (x_initialised == YES) {
8184 color7 = get_x11_color(value);
8191 X11_initialisation();
8192 if (x_initialised == YES) {
8194 color8 = get_x11_color(value);
8201 X11_initialisation();
8202 if (x_initialised == YES) {
8204 color9 = get_x11_color(value);
8210 CONF("default_color") {
8211 X11_initialisation();
8212 if (x_initialised == YES) {
8214 default_fg_color = get_x11_color(value);
8220 CONF3("default_shade_color", "default_shadecolor") {
8221 X11_initialisation();
8222 if (x_initialised == YES) {
8224 default_bg_color = get_x11_color(value);
8230 CONF3("default_outline_color", "default_outlinecolor") {
8231 X11_initialisation();
8232 if (x_initialised == YES) {
8234 default_out_color = get_x11_color(value);
8241 CONF("own_window_colour") {
8242 X11_initialisation();
8243 if (x_initialised == YES) {
8245 background_colour = get_x11_color(value);
8247 ERR("Invalid colour for own_window_colour (try omitting the "
8248 "'#' for hex colours");
8254 //initialize X11 if nothing X11-related is mentioned before TEXT (and if X11 is the default outputmethod)
8255 if(output_methods & TO_X) {
8256 X11_initialisation();
8266 #undef CONF_CONTINUE
8267 #undef CONF_BUFF_SIZE
8274 static void print_help(const char *prog_name) {
8275 printf("Usage: %s [OPTION]...\n"
8276 PACKAGE_NAME" is a system monitor that renders text on desktop or to own transparent\n"
8277 "window. Command line options will override configurations defined in config\n"
8279 " -v, --version version\n"
8280 " -q, --quiet quiet mode\n"
8281 " -D, --debug increase debugging output\n"
8282 " -c, --config=FILE config file to load\n"
8283 #ifdef CONFIG_OUTPUT
8284 " -C, --print-config print the builtin default config to stdout\n"
8285 " e.g. 'conky -C > ~/.conkyrc' will create a new default config\n"
8287 " -d, --daemonize daemonize, fork to background\n"
8288 " -h, --help help\n"
8290 " -a, --alignment=ALIGNMENT text alignment on screen, {top,bottom,middle}_{left,right,middle}\n"
8291 " -f, --font=FONT font to use\n"
8292 " -X, --display=DISPLAY X11 display to use\n"
8294 " -o, --own-window create own window to draw\n"
8297 " -b, --double-buffer double buffer (prevents flickering)\n"
8299 " -w, --window-id=WIN_ID window id to draw\n"
8300 " -x X x position\n"
8301 " -y Y y position\n"
8303 " -t, --text=TEXT text to render, remember single quotes, like -t '$uptime'\n"
8304 " -u, --interval=SECS update interval\n"
8305 " -i COUNT number of times to update "PACKAGE_NAME" (and quit)\n",
8310 /* : means that character before that takes an argument */
8311 static const char *getopt_string = "vVqdDt:u:i:hc:"
8321 #ifdef CONFIG_OUTPUT
8326 static const struct option longopts[] = {
8327 { "help", 0, NULL, 'h' },
8328 { "version", 0, NULL, 'V' },
8329 { "debug", 0, NULL, 'D' },
8330 { "config", 1, NULL, 'c' },
8331 #ifdef CONFIG_OUTPUT
8332 { "print-config", 0, NULL, 'C' },
8334 { "daemonize", 0, NULL, 'd' },
8336 { "alignment", 1, NULL, 'a' },
8337 { "font", 1, NULL, 'f' },
8338 { "display", 1, NULL, 'X' },
8340 { "own-window", 0, NULL, 'o' },
8343 { "double-buffer", 0, NULL, 'b' },
8345 { "window-id", 1, NULL, 'w' },
8347 { "text", 1, NULL, 't' },
8348 { "interval", 0, NULL, 'u' },
8352 int main(int argc, char **argv)
8358 struct sigaction act, oact;
8360 g_signal_pending = 0;
8361 memset(&info, 0, sizeof(info));
8364 #ifdef TCP_PORT_MONITOR
8365 /* set default connection limit */
8366 tcp_portmon_set_max_connections(0);
8369 /* handle command line parameters that don't change configs */
8371 if (((s = getenv("LC_ALL")) && *s) || ((s = getenv("LC_CTYPE")) && *s)
8372 || ((s = getenv("LANG")) && *s)) {
8373 temp = (char *) malloc((strlen(s) + 1) * sizeof(char));
8375 ERR("malloc failed");
8377 for (x = 0; x < strlen(s); x++) {
8378 temp[x] = tolower(s[x]);
8381 if (strstr(temp, "utf-8") || strstr(temp, "utf8")) {
8387 if (!setlocale(LC_CTYPE, "")) {
8388 ERR("Can't set the specified locale!\nCheck LANG, LC_CTYPE, LC_ALL.");
8392 int c = getopt_long(argc, argv, getopt_string, longopts, NULL);
8403 if (current_config) {
8404 free(current_config);
8406 current_config = strndup(optarg, max_user_text);
8409 freopen("/dev/null", "w", stderr);
8412 print_help(argv[0]);
8414 #ifdef CONFIG_OUTPUT
8421 window.window = strtol(optarg, 0, 0);
8430 /* check if specified config file is valid */
8431 if (current_config) {
8433 if (stat(current_config, &sb) ||
8434 (!S_ISREG(sb.st_mode) && !S_ISLNK(sb.st_mode))) {
8435 ERR("invalid configuration file '%s'\n", current_config);
8436 free(current_config);
8441 /* load current_config, CONFIG_FILE or SYSTEM_CONFIG_FILE */
8443 if (!current_config) {
8444 /* load default config file */
8445 char buf[DEFAULT_TEXT_BUFFER_SIZE];
8448 /* Try to use personal config file first */
8449 to_real_path(buf, CONFIG_FILE);
8450 if (buf[0] && (fp = fopen(buf, "r"))) {
8451 current_config = strndup(buf, max_user_text);
8455 /* Try to use system config file if personal config not readable */
8456 if (!current_config && (fp = fopen(SYSTEM_CONFIG_FILE, "r"))) {
8457 current_config = strndup(SYSTEM_CONFIG_FILE, max_user_text);
8461 /* No readable config found */
8462 if (!current_config) {
8463 #ifdef CONFIG_OUTPUT
8464 current_config = strdup("==builtin==");
8465 ERR("no readable personal or system-wide config file found,"
8466 " using builtin default");
8468 CRIT_ERR("no readable personal or system-wide config file found");
8469 #endif /* ! CONF_OUTPUT */
8472 #ifdef HAVE_SYS_INOTIFY_H
8473 inotify_fd = inotify_init();
8474 #endif /* HAVE_SYS_INOTIFY_H */
8476 load_config_file(current_config);
8478 /* init specials array */
8479 if ((specials = calloc(sizeof(struct special_t), max_specials)) == 0) {
8480 ERR("failed to create specials array");
8484 if (current_mail_spool == NULL) {
8487 variable_substitute(MAIL_FILE, buf, 256);
8489 if (buf[0] != '\0') {
8490 current_mail_spool = strndup(buf, text_buffer_size);
8495 /* handle other command line arguments */
8497 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__OpenBSD__) \
8498 || defined(__NetBSD__)
8499 optind = optreset = 1;
8504 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
8505 if ((kd = kvm_open("/dev/null", "/dev/null", "/dev/null", O_RDONLY,
8506 "kvm_open")) == NULL) {
8507 CRIT_ERR("cannot read kvm");
8512 int c = getopt_long(argc, argv, getopt_string, longopts, NULL);
8520 fork_to_background = 1;
8523 global_debug_level++;
8527 set_first_font(optarg);
8530 text_alignment = string_to_alignment(optarg);
8535 disp = strdup(optarg);
8554 global_text = strndup(optarg, max_user_text);
8555 convert_escapes(global_text);
8559 update_interval = strtod(optarg, 0);
8560 if (info.music_player_interval == 0) {
8561 // default to update_interval
8562 info.music_player_interval = update_interval;
8567 total_run_times = strtod(optarg, 0);
8571 gap_x = atoi(optarg);
8575 gap_y = atoi(optarg);
8586 if (output_methods & TO_X) {
8587 load_config_file_x11(current_config);
8592 /* generate text and get initial size */
8593 extract_variable_text(global_text);
8600 if (fork_to_background) {
8605 ERR(PACKAGE_NAME": couldn't fork() to background: %s",
8612 fprintf(stderr, "\n");
8617 /* parent process */
8618 fprintf(stderr, PACKAGE_NAME": forked to background, pid is %d\n",
8625 text_buffer = malloc(max_user_text);
8626 memset(text_buffer, 0, max_user_text);
8627 tmpstring1 = malloc(text_buffer_size);
8628 memset(tmpstring1, 0, text_buffer_size);
8629 tmpstring2 = malloc(text_buffer_size);
8630 memset(tmpstring2, 0, text_buffer_size);
8635 X11_create_window();
8638 /* Set signal handlers */
8639 act.sa_handler = signal_handler;
8640 sigemptyset(&act.sa_mask);
8643 act.sa_flags |= SA_RESTART;
8646 if ( sigaction(SIGINT, &act, &oact) < 0
8647 || sigaction(SIGUSR1, &act, &oact) < 0
8648 || sigaction(SIGHUP, &act, &oact) < 0
8649 || sigaction(SIGTERM, &act, &oact) < 0) {
8650 ERR("error setting signal handler: %s", strerror(errno));
8655 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
8662 static void signal_handler(int sig)
8664 /* signal handler is light as a feather, as it should be.
8665 * we will poll g_signal_pending with each loop of conky
8666 * and do any signal processing there, NOT here. */
8667 g_signal_pending = sig;