1 /* Conky, a system monitor, based on torsmo
3 * Any original torsmo code is licensed under the BSD license
5 * All code written since the fork of torsmo is licensed under the GPL
7 * Please see COPYING for details
9 * Copyright (c) 2004, Hannu Saransaari and Lauri Hakkarainen
10 * Copyright (c) 2005-2009 Brenden Matthews, Philip Kovacs, et. al.
12 * All rights reserved.
14 * This program is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation, either version 3 of the License, or
17 * (at your option) any later version.
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program. If not, see <http://www.gnu.org/licenses/>.
29 #include "text_object.h"
44 #include <sys/param.h>
45 #ifdef HAVE_SYS_INOTIFY_H
46 #include <sys/inotify.h>
47 #endif /* HAVE_SYS_INOTIFY_H */
50 #include <X11/Xutil.h>
52 #include <X11/extensions/Xdamage.h>
58 #include <sys/types.h>
60 #include <netinet/in.h>
79 #include "temphelper.h"
83 /* check for OS and include appropriate headers */
84 #if defined(__linux__)
86 #elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
88 #elif defined(__OpenBSD__)
92 #if defined(__FreeBSD_kernel__)
96 /* FIXME: apm_getinfo is unused here. maybe it's meant for common.c */
97 #if (defined(__FreeBSD__) || defined(__FreeBSD_kernel__) \
98 || defined(__OpenBSD__)) && (defined(i386) || defined(__i386__))
99 int apm_getinfo(int fd, apm_info_t aip);
100 char *get_apm_adapter(void);
101 char *get_apm_battery_life(void);
102 char *get_apm_battery_time(void);
110 #include "defconfig.h"
111 #ifdef HAVE_FOPENCOOKIE
112 #include "conf_cookie.h"
117 #define S_ISSOCK(x) ((x & S_IFMT) == S_IFSOCK)
120 #define MAIL_FILE "$MAIL"
121 #define MAX_IF_BLOCK_DEPTH 5
123 //#define SIGNAL_BLOCKING
124 #undef SIGNAL_BLOCKING
126 /* debugging level, used by logging.h */
127 int global_debug_level = 0;
129 /* two strings for internal use */
130 static char *tmpstring1, *tmpstring2;
132 /* variables holding various config settings */
134 int format_human_readable;
141 int top_cpu, top_mem, top_time;
145 static unsigned int top_name_width = 15;
147 enum x_initialiser_state x_initialised = NO;
148 static volatile int g_signal_pending;
149 /* Update interval */
150 double update_interval;
153 /* prototypes for internally used functions */
154 static void signal_handler(int);
155 static void print_version(void) __attribute__((noreturn));
156 static void reload_config(void);
157 static void clean_up(void);
158 static void generate_text_internal(char *, int, struct text_object,
159 struct information *);
160 static int extract_variable_text_internal(struct text_object *,
163 static void print_version(void)
165 printf(PACKAGE_NAME" "VERSION" compiled "BUILD_DATE" for "BUILD_ARCH"\n");
167 printf("\nCompiled in features:\n\n"
168 "System config file: "SYSTEM_CONFIG_FILE"\n\n"
172 " * Xdamage extension\n"
173 # endif /* HAVE_XDAMAGE */
175 " * XDBE (double buffer extension)\n"
176 # endif /* HAVE_XDBE */
181 "\n Music detection:\n"
184 #endif /* AUDACIOUS */
200 #endif /* HAVE_OPENMP */
207 #ifdef TCP_PORT_MONITOR
209 #endif /* TCP_PORT_MONITOR */
215 #endif /* HAVE_LUA */
218 #endif /* HAVE_IWLIB */
220 " * support for IBM/Lenovo notebooks\n"
230 #endif /* CONFIG_OUTPUT */
235 " * ALSA mixer support\n"
236 #endif /* MIXER_IS_ALSA */
248 static const char *suffixes[] = { "B", "KiB", "MiB", "GiB", "TiB", "PiB", "" };
253 static void X11_destroy_window(void);
254 static void X11_create_window(void);
255 static void X11_initialisation(void);
257 struct _x11_stuff_s {
261 XserverRegion region2, part;
262 int event_base, error_base;
268 static int text_start_x, text_start_y; /* text start position in window */
269 static int text_width, text_height;
284 /* display to connect to */
285 static char *disp = NULL;
289 /* struct that has all info to be shared between
290 * instances of the same text object */
291 struct information info;
293 /* default config file */
294 static char *current_config;
296 /* set to 1 if you want all text to be in uppercase */
297 static unsigned int stuff_in_upper_case;
299 /* Run how many times? */
300 static unsigned long total_run_times;
303 static int fork_to_background;
305 static int cpu_avg_samples, net_avg_samples, diskio_avg_samples;
307 /* filenames for output */
308 char *overwrite_file = NULL; FILE *overwrite_fpointer = NULL;
309 char *append_file = NULL; FILE *append_fpointer = NULL;
313 static int show_graph_scale;
314 static int show_graph_range;
316 /* Position on the screen */
317 static int text_alignment;
318 static int gap_x, gap_y;
321 static int draw_borders;
322 static int draw_graph_borders;
323 static int stippled_borders;
325 static int draw_shades, draw_outline;
327 static long border_inner_margin, border_outer_margin, border_width;
329 static long default_fg_color, default_bg_color, default_out_color;
331 /* create own window or draw stuff to root? */
332 static int set_transparent = 0;
335 static int own_window = 0;
336 static int background_colour = 0;
338 /* fixed size/pos is set if wm/user changes them */
339 static int fixed_size = 0, fixed_pos = 0;
342 static int minimum_width, minimum_height;
343 static int maximum_width;
348 static int sensor_device;
351 static long color0, color1, color2, color3, color4, color5, color6, color7,
354 #define MAX_TEMPLATES 10
355 static char *template[MAX_TEMPLATES];
357 /* maximum size of config TEXT buffer, i.e. below TEXT line. */
358 static unsigned int max_user_text = MAX_USER_TEXT_DEFAULT;
360 /* maximum size of individual text buffers, ie $exec buffer size */
361 unsigned int text_buffer_size = DEFAULT_TEXT_BUFFER_SIZE;
364 #define CODEPAGE_LENGTH 20
366 long iconv_count = 0;
367 char iconv_converting;
368 static iconv_t **iconv_cd = 0;
370 int register_iconv(iconv_t *new_iconv)
372 iconv_cd = realloc(iconv_cd, sizeof(iconv_t *) * (iconv_count + 1));
374 CRIT_ERR("Out of memory");
376 iconv_cd[iconv_count] = malloc(sizeof(iconv_t));
377 if (!iconv_cd[iconv_count]) {
378 CRIT_ERR("Out of memory");
380 memcpy(iconv_cd[iconv_count], new_iconv, sizeof(iconv_t));
385 void free_iconv(void)
390 for (i = 0; i < iconv_count; i++) {
392 iconv_close(*iconv_cd[i]);
406 /* no buffers in used memory? */
409 /* pad percentages to decimals? */
410 static int pad_percents = 0;
412 static char *global_text = 0;
413 long global_text_lines;
415 static int total_updates;
416 static int updatereset;
418 int check_contains(char *f, char *s)
421 FILE *where = open_file(f, 0);
426 while (fgets(buf1, 256, where)) {
427 if (strstr(buf1, s)) {
434 ERR("Could not open the file");
440 static inline int calc_text_width(const char *s, int l)
442 if ((output_methods & TO_X) == 0)
449 XftTextExtentsUtf8(display, fonts[selected_font].xftfont,
450 (const FcChar8 *) s, l, &gi);
452 XftTextExtents8(display, fonts[selected_font].xftfont,
453 (const FcChar8 *) s, l, &gi);
459 return XTextWidth(fonts[selected_font].font, s, l);
464 /* formatted text to render on screen, generated in generate_text(),
465 * drawn in draw_stuff() */
467 static char *text_buffer;
470 static unsigned int special_index; /* used when drawing */
473 /* quite boring functions */
475 static inline void for_each_line(char *b, void f(char *))
479 for (ps = b, pe = b; *pe; pe++) {
493 static void convert_escapes(char *buf)
495 char *p = buf, *s = buf;
502 } else if (*s == '\\') {
513 /* Prints anything normally printed with snprintf according to the current value
514 * of use_spacer. Actually slightly more flexible than snprintf, as you can
515 * safely specify the destination buffer as one of your inputs. */
516 int spaced_print(char *buf, int size, const char *format, int width, ...)
525 tempbuf = malloc(size * sizeof(char));
527 // Passes the varargs along to vsnprintf
528 va_start(argp, width);
529 vsnprintf(tempbuf, size, format, argp);
532 switch (use_spacer) {
534 len = snprintf(buf, size, "%s", tempbuf);
537 len = snprintf(buf, size, "%*s", width, tempbuf);
540 len = snprintf(buf, size, "%-*s", width, tempbuf);
547 /* print percentage values
549 * - i.e., unsigned values between 0 and 100
550 * - respect the value of pad_percents */
551 static int percent_print(char *buf, int size, unsigned value)
553 return spaced_print(buf, size, "%u", pad_percents, value);
556 /* converts from bytes to human readable format (K, M, G, T)
558 * The algorithm always divides by 1024, as unit-conversion of byte
559 * counts suggests. But for output length determination we need to
560 * compare with 1000 here, as we print in decimal form. */
561 static void human_readable(long long num, char *buf, int size)
563 const char **suffix = suffixes;
569 /* Possibly just output as usual, for example for stdout usage */
570 if (!format_human_readable) {
571 spaced_print(buf, size, "%d", 6, round_to_int(num));
582 if (llabs(num) < 1000LL) {
583 spaced_print(buf, size, format, width, 0, (float)num, *suffix);
587 while (llabs(num / 1024) >= 1000LL && **(suffix + 2)) {
595 /* fnum should now be < 1000, so looks like 'AAA.BBBBB'
597 * The goal is to always have a significance of 3, by
598 * adjusting the decimal part of the number. Sample output:
602 * so the point of alignment resides between number and unit. The
603 * upside of this is that there is minimal padding necessary, though
604 * there should be a way to make alignment take place at the decimal
605 * dot (then with fixed width decimal part).
607 * Note the repdigits below: when given a precision value, printf()
608 * rounds the float to it, not just cuts off the remaining digits. So
609 * e.g. 99.95 with a precision of 1 gets 100.0, which again should be
610 * printed with a precision of 0. Yay. */
612 precision = 0; /* print 100-999 without decimal part */
614 precision = 1; /* print 10-99 with one decimal place */
616 precision = 2; /* print 0-9 with two decimal places */
618 spaced_print(buf, size, format, width, precision, fnum, *suffix);
621 /* global object list root element */
622 static struct text_object global_root_object;
624 static inline void read_exec(const char *data, char *buf, const int size)
626 FILE *fp = popen(data, "r");
627 int length = fread(buf, 1, size, fp);
631 if (length > 0 && buf[length - 1] == '\n') {
632 buf[length - 1] = '\0';
636 void *threaded_exec(void *) __attribute__((noreturn));
638 void *threaded_exec(void *arg)
641 struct text_object *obj = (struct text_object *)arg;
644 buff = malloc(text_buffer_size);
645 read_exec(obj->data.texeci.cmd, buff,
654 timed_thread_lock(obj->data.texeci.p_timed_thread);
655 strncpy(obj->data.texeci.buffer, buff, text_buffer_size);
656 timed_thread_unlock(obj->data.texeci.p_timed_thread);
658 if (timed_thread_test(obj->data.texeci.p_timed_thread, 0)) {
659 timed_thread_exit(obj->data.texeci.p_timed_thread);
665 static struct text_object *new_text_object_internal(void)
667 struct text_object *obj = malloc(sizeof(struct text_object));
668 memset(obj, 0, sizeof(struct text_object));
673 * Frees the list of text objects root points to. When internal = 1, it won't
674 * free global objects.
676 static void free_text_objects(struct text_object *root, int internal)
678 struct text_object *obj;
684 #define data obj->data
685 for (obj = root->prev; obj; obj = root->prev) {
686 root->prev = obj->prev;
692 #endif /* !__OpenBSD__ */
697 close(data.sysfs.fd);
699 #endif /* __linux__ */
701 free(data.read_tcp.host);
708 free(data.tztime.tz);
709 free(data.tztime.fmt);
712 free(data.mboxscan.args);
713 free(data.mboxscan.output);
718 case OBJ_unseen_mails:
719 case OBJ_flagged_mails:
720 case OBJ_unflagged_mails:
721 case OBJ_forwarded_mails:
722 case OBJ_unforwarded_mails:
723 case OBJ_replied_mails:
724 case OBJ_unreplied_mails:
725 case OBJ_draft_mails:
726 case OBJ_trashed_mails:
727 free(data.local_mail.box);
729 case OBJ_imap_unseen:
734 case OBJ_imap_messages:
739 case OBJ_pop3_unseen:
751 free_text_objects(obj->sub, 1);
754 case OBJ_if_existing:
757 free(data.ifblock.s);
758 free(data.ifblock.str);
761 free(data.tail.logfile);
762 free(data.tail.buffer);
778 case OBJ_iconv_start:
783 case OBJ_disk_protect:
787 free(data.ifblock.s);
788 free(data.ifblock.str);
791 if (info.gw_info.iface) {
792 free(info.gw_info.iface);
793 info.gw_info.iface = 0;
795 if (info.gw_info.ip) {
796 free(info.gw_info.ip);
800 case OBJ_ioscheduler:
805 #if (defined(__FreeBSD__) || defined(__linux__))
807 free(data.ifblock.s);
808 free(data.ifblock.str);
812 case OBJ_xmms2_artist:
813 if (info.xmms2.artist) {
814 free(info.xmms2.artist);
815 info.xmms2.artist = 0;
818 case OBJ_xmms2_album:
819 if (info.xmms2.album) {
820 free(info.xmms2.album);
821 info.xmms2.album = 0;
824 case OBJ_xmms2_title:
825 if (info.xmms2.title) {
826 free(info.xmms2.title);
827 info.xmms2.title = 0;
830 case OBJ_xmms2_genre:
831 if (info.xmms2.genre) {
832 free(info.xmms2.genre);
833 info.xmms2.genre = 0;
836 case OBJ_xmms2_comment:
837 if (info.xmms2.comment) {
838 free(info.xmms2.comment);
839 info.xmms2.comment = 0;
843 if (info.xmms2.url) {
844 free(info.xmms2.url);
849 if (info.xmms2.date) {
850 free(info.xmms2.date);
854 case OBJ_xmms2_status:
855 if (info.xmms2.status) {
856 free(info.xmms2.status);
857 info.xmms2.status = 0;
860 case OBJ_xmms2_playlist:
861 if (info.xmms2.playlist) {
862 free(info.xmms2.playlist);
863 info.xmms2.playlist = 0;
866 case OBJ_xmms2_smart:
867 if (info.xmms2.artist) {
868 free(info.xmms2.artist);
869 info.xmms2.artist = 0;
871 if (info.xmms2.title) {
872 free(info.xmms2.title);
873 info.xmms2.title = 0;
875 if (info.xmms2.url) {
876 free(info.xmms2.url);
883 case OBJ_bmpx_artist:
887 case OBJ_bmpx_bitrate:
897 free(data.rss.action);
903 case OBJ_lua_read_parse:
911 #endif /* HAVE_LUA */
918 case OBJ_battery_short:
921 case OBJ_battery_time:
924 #endif /* !__OpenBSD__ */
932 free(data.execi.cmd);
933 free(data.execi.buffer);
936 free(data.texeci.cmd);
937 free(data.texeci.buffer);
948 if (info.first_process && !internal) {
949 free_all_processes();
950 info.first_process = NULL;
952 if (data.top.s) free(data.top.s);
956 free(data.hddtemp.dev);
957 free(data.hddtemp.addr);
958 if (data.hddtemp.temp)
959 free(data.hddtemp.temp);
962 case OBJ_entropy_avail:
963 case OBJ_entropy_perc:
964 case OBJ_entropy_poolsize:
965 case OBJ_entropy_bar:
968 if (info.users.names) {
969 free(info.users.names);
970 info.users.names = 0;
974 if (info.users.terms) {
975 free(info.users.terms);
976 info.users.terms = 0;
980 if (info.users.times) {
981 free(info.users.times);
982 info.users.times = 0;
987 case OBJ_smapi_bat_perc:
988 case OBJ_smapi_bat_temp:
989 case OBJ_smapi_bat_power:
992 case OBJ_if_smapi_bat_installed:
993 free(data.ifblock.s);
994 free(data.ifblock.str);
1003 case OBJ_mpd_artist:
1005 case OBJ_mpd_random:
1006 case OBJ_mpd_repeat:
1008 case OBJ_mpd_bitrate:
1009 case OBJ_mpd_status:
1011 case OBJ_mpd_elapsed:
1012 case OBJ_mpd_length:
1016 case OBJ_mpd_percent:
1018 case OBJ_if_mpd_playing:
1026 case OBJ_moc_artist:
1029 case OBJ_moc_totaltime:
1030 case OBJ_moc_timeleft:
1031 case OBJ_moc_curtime:
1032 case OBJ_moc_bitrate:
1038 free_text_objects(obj->sub, 1);
1042 free(data.scroll.text);
1043 free_text_objects(obj->sub, 1);
1047 free(data.combine.left);
1048 free(data.combine.seperation);
1049 free(data.combine.right);
1050 free_text_objects(obj->sub, 1);
1055 case OBJ_apcupsd_name:
1056 case OBJ_apcupsd_model:
1057 case OBJ_apcupsd_upsmode:
1058 case OBJ_apcupsd_cable:
1059 case OBJ_apcupsd_status:
1060 case OBJ_apcupsd_linev:
1061 case OBJ_apcupsd_load:
1062 case OBJ_apcupsd_loadbar:
1064 case OBJ_apcupsd_loadgraph:
1065 case OBJ_apcupsd_loadgauge:
1067 case OBJ_apcupsd_charge:
1068 case OBJ_apcupsd_timeleft:
1069 case OBJ_apcupsd_temp:
1070 case OBJ_apcupsd_lastxfer:
1072 #endif /* APCUPSD */
1080 void scan_mixer_bar(const char *arg, int *a, int *w, int *h)
1085 if (arg && sscanf(arg, "%63s %n", buf1, &n) >= 1) {
1086 *a = mixer_init(buf1);
1087 scan_bar(arg + n, w, h);
1089 *a = mixer_init(NULL);
1090 scan_bar(arg, w, h);
1095 /* strip a leading /dev/ if any, following symlinks first
1097 * BEWARE: this function returns a pointer to static content
1098 * which gets overwritten in consecutive calls. I.e.:
1099 * this function is NOT reentrant.
1101 static const char *dev_name(const char *path)
1103 static char buf[255]; /* should be enough for pathnames */
1109 #define DEV_NAME(x) \
1110 x != NULL && strlen(x) > 5 && strncmp(x, "/dev/", 5) == 0 ? x + 5 : x
1111 if ((buflen = readlink(path, buf, 254)) == -1)
1112 return DEV_NAME(path);
1114 return DEV_NAME(buf);
1118 static int parse_top_args(const char *s, const char *arg, struct text_object *obj)
1123 if (obj->data.top.was_parsed) {
1126 obj->data.top.was_parsed = 1;
1128 if (arg && !obj->data.top.s) {
1129 obj->data.top.s = strndup(arg, text_buffer_size);
1132 need_mask |= (1 << INFO_TOP);
1135 obj->type = OBJ_top;
1137 } else if (strcmp(&s[3], "_mem") == EQUAL) {
1138 obj->type = OBJ_top_mem;
1140 } else if (strcmp(&s[3], "_time") == EQUAL) {
1141 obj->type = OBJ_top_time;
1144 } else if (strcmp(&s[3], "_io") == EQUAL) {
1145 obj->type = OBJ_top_io;
1150 ERR("Must be top, top_mem, top_time or top_io");
1152 ERR("Must be top, top_mem or top_time");
1158 ERR("top needs arguments");
1162 if (sscanf(arg, "%63s %i", buf, &n) == 2) {
1163 if (strcmp(buf, "name") == EQUAL) {
1164 obj->data.top.type = TOP_NAME;
1165 } else if (strcmp(buf, "cpu") == EQUAL) {
1166 obj->data.top.type = TOP_CPU;
1167 } else if (strcmp(buf, "pid") == EQUAL) {
1168 obj->data.top.type = TOP_PID;
1169 } else if (strcmp(buf, "mem") == EQUAL) {
1170 obj->data.top.type = TOP_MEM;
1171 } else if (strcmp(buf, "time") == EQUAL) {
1172 obj->data.top.type = TOP_TIME;
1173 } else if (strcmp(buf, "mem_res") == EQUAL) {
1174 obj->data.top.type = TOP_MEM_RES;
1175 } else if (strcmp(buf, "mem_vsize") == EQUAL) {
1176 obj->data.top.type = TOP_MEM_VSIZE;
1178 } else if (strcmp(buf, "io_read") == EQUAL) {
1179 obj->data.top.type = TOP_READ_BYTES;
1180 } else if (strcmp(buf, "io_write") == EQUAL) {
1181 obj->data.top.type = TOP_WRITE_BYTES;
1182 } else if (strcmp(buf, "io_perc") == EQUAL) {
1183 obj->data.top.type = TOP_IO_PERC;
1186 ERR("invalid type arg for top");
1188 ERR("must be one of: name, cpu, pid, mem, time, mem_res, mem_vsize, "
1189 "io_read, io_write, io_perc");
1191 ERR("must be one of: name, cpu, pid, mem, time, mem_res, mem_vsize");
1195 if (n < 1 || n > 10) {
1196 ERR("invalid num arg for top. Must be between 1 and 10.");
1199 obj->data.top.num = n - 1;
1202 ERR("invalid argument count for top");
1208 /* construct_text_object() creates a new text_object */
1209 static struct text_object *construct_text_object(const char *s,
1210 const char *arg, long line, char allow_threaded, void **ifblock_opaque)
1212 // struct text_object *obj = new_text_object();
1213 struct text_object *obj = new_text_object_internal();
1217 #define OBJ(a, n) if (strcmp(s, #a) == 0) { \
1218 obj->type = OBJ_##a; need_mask |= (1ULL << n); {
1219 #define OBJ_IF(a, n) if (strcmp(s, #a) == 0) { \
1220 obj->type = OBJ_##a; need_mask |= (1ULL << n); \
1221 obj_be_ifblock_if(ifblock_opaque, obj); {
1222 #define OBJ_THREAD(a, n) if (strcmp(s, #a) == 0 && allow_threaded) { \
1223 obj->type = OBJ_##a; need_mask |= (1ULL << n); {
1224 #define END } } else
1226 #define SIZE_DEFAULTS(arg) { \
1227 obj->a = default_##arg##_width; \
1228 obj->b = default_##arg##_height; \
1233 obj->type = OBJ_color;
1234 obj->data.l = get_x11_color(s);
1238 OBJ(freq, INFO_FREQ)
1241 obj->data.i = open_acpi_temperature(arg);
1242 END OBJ(acpiacadapter, 0)
1243 END OBJ(freq, INFO_FREQ)
1244 #endif /* !__OpenBSD__ */
1246 if (!arg || !isdigit(arg[0]) || strlen(arg) >= 2 || atoi(&arg[0]) == 0
1247 || (unsigned int) atoi(&arg[0]) > info.cpu_count) {
1248 obj->data.cpu_index = 1;
1249 /* ERR("freq: Invalid CPU number or you don't have that many CPUs! "
1250 "Displaying the clock for CPU 1."); */
1252 obj->data.cpu_index = atoi(&arg[0]);
1255 END OBJ(freq_g, INFO_FREQ)
1257 if (!arg || !isdigit(arg[0]) || strlen(arg) >= 2 || atoi(&arg[0]) == 0
1258 || (unsigned int) atoi(&arg[0]) > info.cpu_count) {
1259 obj->data.cpu_index = 1;
1260 /* ERR("freq_g: Invalid CPU number or you don't have that many "
1261 "CPUs! Displaying the clock for CPU 1."); */
1263 obj->data.cpu_index = atoi(&arg[0]);
1266 END OBJ(read_tcp, 0)
1268 obj->data.read_tcp.host = malloc(text_buffer_size);
1269 sscanf(arg, "%s", obj->data.read_tcp.host);
1270 sscanf(arg+strlen(obj->data.read_tcp.host), "%u", &(obj->data.read_tcp.port));
1271 if(obj->data.read_tcp.port == 0) {
1272 obj->data.read_tcp.port = atoi(obj->data.read_tcp.host);
1273 strcpy(obj->data.read_tcp.host,"localhost");
1275 obj->data.read_tcp.port = htons(obj->data.read_tcp.port);
1276 if(obj->data.read_tcp.port < 1 || obj->data.read_tcp.port > 65535) {
1277 CRIT_ERR("read_tcp: Needs \"(host) port\" as argument(s)");
1280 CRIT_ERR("read_tcp: Needs \"(host) port\" as argument(s)");
1282 #if defined(__linux__)
1283 END OBJ(voltage_mv, 0)
1285 if (!arg || !isdigit(arg[0]) || strlen(arg) >= 2 || atoi(&arg[0]) == 0
1286 || (unsigned int) atoi(&arg[0]) > info.cpu_count) {
1287 obj->data.cpu_index = 1;
1288 /* ERR("voltage_mv: Invalid CPU number or you don't have that many "
1289 "CPUs! Displaying voltage for CPU 1."); */
1291 obj->data.cpu_index = atoi(&arg[0]);
1294 END OBJ(voltage_v, 0)
1296 if (!arg || !isdigit(arg[0]) || strlen(arg) >= 2 || atoi(&arg[0]) == 0
1297 || (unsigned int) atoi(&arg[0]) > info.cpu_count) {
1298 obj->data.cpu_index = 1;
1299 /* ERR("voltage_v: Invalid CPU number or you don't have that many "
1300 "CPUs! Displaying voltage for CPU 1."); */
1302 obj->data.cpu_index = atoi(&arg[0]);
1307 END OBJ(wireless_essid, INFO_NET)
1309 obj->data.net = get_net_stat(arg);
1311 // default to DEFAULTNETDEV
1312 char *buf = strndup(DEFAULTNETDEV, text_buffer_size);
1313 obj->data.net = get_net_stat(buf);
1316 END OBJ(wireless_mode, INFO_NET)
1318 obj->data.net = get_net_stat(arg);
1320 // default to DEFAULTNETDEV
1321 char *buf = strndup(DEFAULTNETDEV, text_buffer_size);
1322 obj->data.net = get_net_stat(buf);
1325 END OBJ(wireless_bitrate, INFO_NET)
1327 obj->data.net = get_net_stat(arg);
1329 // default to DEFAULTNETDEV
1330 char *buf = strndup(DEFAULTNETDEV, text_buffer_size);
1331 obj->data.net = get_net_stat(buf);
1334 END OBJ(wireless_ap, INFO_NET)
1336 obj->data.net = get_net_stat(arg);
1338 // default to DEFAULTNETDEV
1339 char *buf = strndup(DEFAULTNETDEV, text_buffer_size);
1340 obj->data.net = get_net_stat(buf);
1343 END OBJ(wireless_link_qual, INFO_NET)
1345 obj->data.net = get_net_stat(arg);
1347 // default to DEFAULTNETDEV
1348 char *buf = strndup(DEFAULTNETDEV, text_buffer_size);
1349 obj->data.net = get_net_stat(buf);
1352 END OBJ(wireless_link_qual_max, INFO_NET)
1354 obj->data.net = get_net_stat(arg);
1356 // default to DEFAULTNETDEV
1357 char *buf = strndup(DEFAULTNETDEV, text_buffer_size);
1358 obj->data.net = get_net_stat(buf);
1361 END OBJ(wireless_link_qual_perc, INFO_NET)
1363 obj->data.net = get_net_stat(arg);
1365 // default to DEFAULTNETDEV
1366 char *buf = strndup(DEFAULTNETDEV, text_buffer_size);
1367 obj->data.net = get_net_stat(buf);
1370 END OBJ(wireless_link_bar, INFO_NET)
1373 arg = scan_bar(arg, &obj->a, &obj->b);
1374 obj->data.net = get_net_stat(arg);
1376 // default to DEFAULTNETDEV
1377 char *buf = strndup(DEFAULTNETDEV, text_buffer_size);
1378 obj->data.net = get_net_stat(buf);
1381 #endif /* HAVE_IWLIB */
1383 #endif /* __linux__ */
1391 sscanf(arg, "%63s", bat);
1393 strcpy(bat, "BAT0");
1395 obj->data.s = strndup(bat, text_buffer_size);
1396 END OBJ(battery_short, 0)
1400 sscanf(arg, "%63s", bat);
1402 strcpy(bat, "BAT0");
1404 obj->data.s = strndup(bat, text_buffer_size);
1405 END OBJ(battery_time, 0)
1409 sscanf(arg, "%63s", bat);
1411 strcpy(bat, "BAT0");
1413 obj->data.s = strndup(bat, text_buffer_size);
1414 END OBJ(battery_percent, 0)
1418 sscanf(arg, "%63s", bat);
1420 strcpy(bat, "BAT0");
1422 obj->data.s = strndup(bat, text_buffer_size);
1423 END OBJ(battery_bar, 0)
1428 arg = scan_bar(arg, &obj->a, &obj->b);
1429 sscanf(arg, "%63s", bat);
1431 strcpy(bat, "BAT0");
1433 obj->data.s = strndup(bat, text_buffer_size);
1434 #endif /* !__OpenBSD__ */
1436 #if defined(__linux__)
1437 END OBJ(disk_protect, 0)
1439 obj->data.s = strndup(dev_name(arg), text_buffer_size);
1441 CRIT_ERR("disk_protect needs an argument");
1442 END OBJ(i8k_version, INFO_I8K)
1443 END OBJ(i8k_bios, INFO_I8K)
1444 END OBJ(i8k_serial, INFO_I8K)
1445 END OBJ(i8k_cpu_temp, INFO_I8K)
1446 END OBJ(i8k_left_fan_status, INFO_I8K)
1447 END OBJ(i8k_right_fan_status, INFO_I8K)
1448 END OBJ(i8k_left_fan_rpm, INFO_I8K)
1449 END OBJ(i8k_right_fan_rpm, INFO_I8K)
1450 END OBJ(i8k_ac_status, INFO_I8K)
1451 END OBJ(i8k_buttons_status, INFO_I8K)
1454 END OBJ(ibm_temps, 0)
1456 CRIT_ERR("ibm_temps: needs an argument");
1458 if (!isdigit(arg[0]) || strlen(arg) >= 2 || atoi(&arg[0]) >= 8) {
1459 obj->data.sensor = 0;
1460 ERR("Invalid temperature sensor! Sensor number must be 0 to 7. "
1461 "Using 0 (CPU temp sensor).");
1463 obj->data.sensor = atoi(&arg[0]);
1464 END OBJ(ibm_volume, 0)
1465 END OBJ(ibm_brightness, 0)
1467 /* information from sony_laptop kernel module
1468 * /sys/devices/platform/sony-laptop */
1469 END OBJ(sony_fanspeed, 0)
1470 END OBJ_IF(if_gw, INFO_GW)
1471 END OBJ(ioscheduler, 0)
1473 CRIT_ERR("get_ioscheduler needs an argument (e.g. hda)");
1476 obj->data.s = strndup(dev_name(arg), text_buffer_size);
1477 END OBJ(laptop_mode, 0)
1478 END OBJ(pb_battery, 0)
1479 if (arg && strcmp(arg, "status") == EQUAL) {
1480 obj->data.i = PB_BATT_STATUS;
1481 } else if (arg && strcmp(arg, "percent") == EQUAL) {
1482 obj->data.i = PB_BATT_PERCENT;
1483 } else if (arg && strcmp(arg, "time") == EQUAL) {
1484 obj->data.i = PB_BATT_TIME;
1486 ERR("pb_battery: needs one argument: status, percent or time");
1491 #endif /* __linux__ */
1492 #if (defined(__FreeBSD__) || defined(__linux__))
1493 END OBJ_IF(if_up, 0)
1495 ERR("if_up needs an argument");
1496 obj->data.ifblock.s = 0;
1498 obj->data.ifblock.s = strndup(arg, text_buffer_size);
1501 #if defined(__OpenBSD__)
1502 END OBJ(obsd_sensors_temp, 0)
1504 CRIT_ERR("obsd_sensors_temp: needs an argument");
1506 if (!isdigit(arg[0]) || atoi(&arg[0]) < 0
1507 || atoi(&arg[0]) > OBSD_MAX_SENSORS - 1) {
1508 obj->data.sensor = 0;
1509 ERR("Invalid temperature sensor number!");
1511 obj->data.sensor = atoi(&arg[0]);
1512 END OBJ(obsd_sensors_fan, 0)
1514 CRIT_ERR("obsd_sensors_fan: needs 2 arguments (device and sensor "
1517 if (!isdigit(arg[0]) || atoi(&arg[0]) < 0
1518 || atoi(&arg[0]) > OBSD_MAX_SENSORS - 1) {
1519 obj->data.sensor = 0;
1520 ERR("Invalid fan sensor number!");
1522 obj->data.sensor = atoi(&arg[0]);
1523 END OBJ(obsd_sensors_volt, 0)
1525 CRIT_ERR("obsd_sensors_volt: needs 2 arguments (device and sensor "
1528 if (!isdigit(arg[0]) || atoi(&arg[0]) < 0
1529 || atoi(&arg[0]) > OBSD_MAX_SENSORS - 1) {
1530 obj->data.sensor = 0;
1531 ERR("Invalid voltage sensor number!");
1533 obj->data.sensor = atoi(&arg[0]);
1534 END OBJ(obsd_vendor, 0)
1535 END OBJ(obsd_product, 0)
1536 #endif /* __OpenBSD__ */
1537 END OBJ(buffers, INFO_BUFFERS)
1538 END OBJ(cached, INFO_BUFFERS)
1539 #define SCAN_CPU(__arg, __var) { \
1541 if (__arg && sscanf(__arg, " cpu%u %n", &__var, &__offset) > 0) \
1542 __arg += __offset; \
1546 END OBJ(cpu, INFO_CPU)
1547 SCAN_CPU(arg, obj->data.cpu_index);
1548 DBGP2("Adding $cpu for CPU %d", obj->data.cpu_index);
1550 END OBJ(cpugauge, INFO_CPU)
1551 SIZE_DEFAULTS(gauge);
1552 SCAN_CPU(arg, obj->data.cpu_index);
1553 scan_gauge(arg, &obj->a, &obj->b);
1554 DBGP2("Adding $cpugauge for CPU %d", obj->data.cpu_index);
1556 END OBJ(cpubar, INFO_CPU)
1558 SCAN_CPU(arg, obj->data.cpu_index);
1559 scan_bar(arg, &obj->a, &obj->b);
1560 DBGP2("Adding $cpubar for CPU %d", obj->data.cpu_index);
1562 END OBJ(cpugraph, INFO_CPU)
1563 SIZE_DEFAULTS(graph);
1564 SCAN_CPU(arg, obj->data.cpu_index);
1565 scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
1566 &obj->e, &obj->char_a, &obj->char_b);
1567 DBGP2("Adding $cpugraph for CPU %d", obj->data.cpu_index);
1568 END OBJ(loadgraph, INFO_LOADAVG)
1570 SIZE_DEFAULTS(graph);
1571 buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
1572 &obj->e, &obj->char_a, &obj->char_b);
1576 r = sscanf(arg, "%d", &a);
1578 obj->data.loadavg[0] = (r >= 1) ? (unsigned char) a : 0;
1582 END OBJ(diskio, INFO_DISKIO)
1583 obj->data.diskio = prepare_diskio_stat(dev_name(arg));
1584 END OBJ(diskio_read, INFO_DISKIO)
1585 obj->data.diskio = prepare_diskio_stat(dev_name(arg));
1586 END OBJ(diskio_write, INFO_DISKIO)
1587 obj->data.diskio = prepare_diskio_stat(dev_name(arg));
1589 END OBJ(diskiograph, INFO_DISKIO)
1591 SIZE_DEFAULTS(graph);
1592 buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
1593 &obj->e, &obj->char_a, &obj->char_b);
1595 obj->data.diskio = prepare_diskio_stat(dev_name(buf));
1598 END OBJ(diskiograph_read, INFO_DISKIO)
1600 SIZE_DEFAULTS(graph);
1601 buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
1602 &obj->e, &obj->char_a, &obj->char_b);
1604 obj->data.diskio = prepare_diskio_stat(dev_name(buf));
1607 END OBJ(diskiograph_write, INFO_DISKIO)
1609 SIZE_DEFAULTS(graph);
1610 buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
1611 &obj->e, &obj->char_a, &obj->char_b);
1613 obj->data.diskio = prepare_diskio_stat(dev_name(buf));
1619 if (output_methods & TO_X) {
1620 obj->data.l = arg ? get_x11_color(arg) : default_fg_color;
1624 obj->data.l = color0;
1626 obj->data.l = color1;
1628 obj->data.l = color2;
1630 obj->data.l = color3;
1632 obj->data.l = color4;
1634 obj->data.l = color5;
1636 obj->data.l = color6;
1638 obj->data.l = color7;
1640 obj->data.l = color8;
1642 obj->data.l = color9;
1645 obj->data.s = scan_font(arg);
1647 END OBJ(conky_version, 0)
1648 END OBJ(conky_build_date, 0)
1649 END OBJ(conky_build_arch, 0)
1650 END OBJ(downspeed, INFO_NET)
1652 obj->data.net = get_net_stat(arg);
1654 // default to DEFAULTNETDEV
1655 char *buf = strndup(DEFAULTNETDEV, text_buffer_size);
1656 obj->data.net = get_net_stat(buf);
1659 END OBJ(downspeedf, INFO_NET)
1661 obj->data.net = get_net_stat(arg);
1663 // default to DEFAULTNETDEV
1664 char *buf = strndup(DEFAULTNETDEV, text_buffer_size);
1665 obj->data.net = get_net_stat(buf);
1669 END OBJ(downspeedgraph, INFO_NET)
1671 SIZE_DEFAULTS(graph);
1672 buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
1673 &obj->e, &obj->char_a, &obj->char_b);
1675 // default to DEFAULTNETDEV
1676 buf = strndup(buf ? buf : DEFAULTNETDEV, text_buffer_size);
1677 obj->data.net = get_net_stat(buf);
1681 obj_be_ifblock_else(ifblock_opaque, obj);
1683 obj_be_ifblock_endif(ifblock_opaque, obj);
1685 obj->data.s = strndup(arg ? arg : "", text_buffer_size);
1687 obj->data.s = strndup(arg ? arg : "", text_buffer_size);
1690 obj->data.s = strndup(arg ? arg : "", text_buffer_size);
1692 obj->data.s = strndup(arg ? arg : "", text_buffer_size);
1695 obj->data.s = strndup(arg ? arg : "", text_buffer_size);
1697 END OBJ(execgauge, 0)
1698 SIZE_DEFAULTS(gauge);
1699 obj->data.s = strndup(arg ? arg : "", text_buffer_size);
1700 END OBJ(execgraph, 0)
1701 SIZE_DEFAULTS(graph);
1702 obj->data.s = strndup(arg ? arg : "", text_buffer_size);
1704 END OBJ(execibar, 0)
1708 if (!arg || sscanf(arg, "%f %n", &obj->data.execi.interval, &n) <= 0) {
1711 ERR("${execibar <interval> command}");
1712 obj->type = OBJ_text;
1713 snprintf(buf, 256, "${%s}", s);
1714 obj->data.s = strndup(buf, text_buffer_size);
1716 obj->data.execi.cmd = strndup(arg + n, text_buffer_size);
1719 END OBJ(execigraph, 0)
1721 SIZE_DEFAULTS(graph);
1723 if (!arg || sscanf(arg, "%f %n", &obj->data.execi.interval, &n) <= 0) {
1726 ERR("${execigraph <interval> command}");
1727 obj->type = OBJ_text;
1728 snprintf(buf, 256, "${%s}", s);
1729 obj->data.s = strndup(buf, text_buffer_size);
1731 obj->data.execi.cmd = strndup(arg + n, text_buffer_size);
1733 END OBJ(execigauge, 0)
1735 SIZE_DEFAULTS(gauge);
1737 if (!arg || sscanf(arg, "%f %n", &obj->data.execi.interval, &n) <= 0) {
1740 ERR("${execigauge <interval> command}");
1741 obj->type = OBJ_text;
1742 snprintf(buf, 256, "${%s}", s);
1743 obj->data.s = strndup(buf, text_buffer_size);
1745 obj->data.execi.cmd = strndup(arg + n, text_buffer_size);
1751 if (!arg || sscanf(arg, "%f %n", &obj->data.execi.interval, &n) <= 0) {
1754 ERR("${execi <interval> command}");
1755 obj->type = OBJ_text;
1756 snprintf(buf, 256, "${%s}", s);
1757 obj->data.s = strndup(buf, text_buffer_size);
1759 obj->data.execi.cmd = strndup(arg + n, text_buffer_size);
1760 obj->data.execi.buffer = malloc(text_buffer_size);
1765 if (!arg || sscanf(arg, "%f %n", &obj->data.execi.interval, &n) <= 0) {
1768 ERR("${execi <interval> command}");
1769 obj->type = OBJ_text;
1770 snprintf(buf, 256, "${%s}", s);
1771 obj->data.s = strndup(buf, text_buffer_size);
1773 obj->data.execi.cmd = strndup(arg + n, text_buffer_size);
1774 obj->data.execi.buffer = malloc(text_buffer_size);
1776 END OBJ_THREAD(texeci, 0)
1779 if (!arg || sscanf(arg, "%f %n", &obj->data.texeci.interval, &n) <= 0) {
1782 ERR("${texeci <interval> command}");
1783 obj->type = OBJ_text;
1784 snprintf(buf, 256, "${%s}", s);
1785 obj->data.s = strndup(buf, text_buffer_size);
1787 obj->data.texeci.cmd = strndup(arg + n, text_buffer_size);
1788 obj->data.texeci.buffer = malloc(text_buffer_size);
1790 obj->data.texeci.p_timed_thread = NULL;
1791 END OBJ(pre_exec, 0)
1792 obj->type = OBJ_text;
1796 read_exec(arg, buf, sizeof(buf));
1797 obj->data.s = strndup(buf, text_buffer_size);
1799 obj->data.s = strndup("", text_buffer_size);
1802 END OBJ(fs_bar, INFO_FS)
1804 arg = scan_bar(arg, &obj->data.fsbar.w, &obj->data.fsbar.h);
1806 while (isspace(*arg)) {
1815 obj->data.fsbar.fs = prepare_fs_stat(arg);
1816 END OBJ(fs_bar_free, INFO_FS)
1818 arg = scan_bar(arg, &obj->data.fsbar.w, &obj->data.fsbar.h);
1820 while (isspace(*arg)) {
1830 obj->data.fsbar.fs = prepare_fs_stat(arg);
1831 END OBJ(fs_free, INFO_FS)
1835 obj->data.fs = prepare_fs_stat(arg);
1836 END OBJ(fs_used_perc, INFO_FS)
1840 obj->data.fs = prepare_fs_stat(arg);
1841 END OBJ(fs_free_perc, INFO_FS)
1845 obj->data.fs = prepare_fs_stat(arg);
1846 END OBJ(fs_size, INFO_FS)
1850 obj->data.fs = prepare_fs_stat(arg);
1851 END OBJ(fs_type, INFO_FS)
1855 obj->data.fs = prepare_fs_stat(arg);
1856 END OBJ(fs_used, INFO_FS)
1860 obj->data.fs = prepare_fs_stat(arg);
1862 obj->data.i = arg ? atoi(arg) : 1;
1863 END OBJ(nameserver, INFO_DNS)
1864 obj->data.i = arg ? atoi(arg) : 0;
1866 obj->data.i = arg ? atoi(arg) : 1;
1868 obj->data.i = arg ? atoi(arg) : 1;
1872 ERR("goto needs arguments");
1873 obj->type = OBJ_text;
1874 obj->data.s = strndup("${goto}", text_buffer_size);
1878 obj->data.i = atoi(arg);
1884 if (sscanf(arg, "%d %d", &a, &b) != 2) {
1885 sscanf(arg, "%d", &b);
1891 obj->data.pair.a = a;
1892 obj->data.pair.b = b;
1895 END OBJ(i2c, INFO_SYSFS)
1896 char buf1[64], buf2[64];
1897 float factor, offset;
1901 ERR("i2c needs arguments");
1902 obj->type = OBJ_text;
1903 // obj->data.s = strndup("${i2c}", text_buffer_size);
1907 #define HWMON_RESET() {\
1912 if (sscanf(arg, "%63s %d %f %f", buf2, &n, &factor, &offset) == 4) found = 1; else HWMON_RESET();
1913 if (!found && sscanf(arg, "%63s %63s %d %f %f", buf1, buf2, &n, &factor, &offset) == 5) found = 1; else if (!found) HWMON_RESET();
1914 if (!found && sscanf(arg, "%63s %63s %d", buf1, buf2, &n) == 3) found = 1; else if (!found) HWMON_RESET();
1915 if (!found && sscanf(arg, "%63s %d", buf2, &n) == 2) found = 1; else if (!found) HWMON_RESET();
1918 ERR("i2c failed to parse arguments");
1919 obj->type = OBJ_text;
1922 DBGP("parsed i2c args: '%s' '%s' %d %f %f\n", buf1, buf2, n, factor, offset);
1923 obj->data.sysfs.fd = open_i2c_sensor((*buf1) ? buf1 : 0, buf2, n,
1924 &obj->data.sysfs.arg, obj->data.sysfs.devtype);
1925 strncpy(obj->data.sysfs.type, buf2, 63);
1926 obj->data.sysfs.factor = factor;
1927 obj->data.sysfs.offset = offset;
1929 END OBJ(platform, INFO_SYSFS)
1930 char buf1[64], buf2[64];
1931 float factor, offset;
1935 ERR("platform needs arguments");
1936 obj->type = OBJ_text;
1940 if (sscanf(arg, "%63s %d %f %f", buf2, &n, &factor, &offset) == 4) found = 1; else HWMON_RESET();
1941 if (!found && sscanf(arg, "%63s %63s %d %f %f", buf1, buf2, &n, &factor, &offset) == 5) found = 1; else if (!found) HWMON_RESET();
1942 if (!found && sscanf(arg, "%63s %63s %d", buf1, buf2, &n) == 3) found = 1; else if (!found) HWMON_RESET();
1943 if (!found && sscanf(arg, "%63s %d", buf2, &n) == 2) found = 1; else if (!found) HWMON_RESET();
1946 ERR("platform failed to parse arguments");
1947 obj->type = OBJ_text;
1950 DBGP("parsed platform args: '%s' '%s' %d %f %f\n", buf1, buf2, n, factor, offset);
1951 obj->data.sysfs.fd = open_platform_sensor((*buf1) ? buf1 : 0, buf2, n,
1952 &obj->data.sysfs.arg, obj->data.sysfs.devtype);
1953 strncpy(obj->data.sysfs.type, buf2, 63);
1954 obj->data.sysfs.factor = factor;
1955 obj->data.sysfs.offset = offset;
1957 END OBJ(hwmon, INFO_SYSFS)
1958 char buf1[64], buf2[64];
1959 float factor, offset;
1963 ERR("hwmon needs argumanets");
1964 obj->type = OBJ_text;
1968 if (sscanf(arg, "%63s %d %f %f", buf2, &n, &factor, &offset) == 4) found = 1; else HWMON_RESET();
1969 if (!found && sscanf(arg, "%63s %63s %d %f %f", buf1, buf2, &n, &factor, &offset) == 5) found = 1; else if (!found) HWMON_RESET();
1970 if (!found && sscanf(arg, "%63s %63s %d", buf1, buf2, &n) == 3) found = 1; else if (!found) HWMON_RESET();
1971 if (!found && sscanf(arg, "%63s %d", buf2, &n) == 2) found = 1; else if (!found) HWMON_RESET();
1976 ERR("hwmon failed to parse arguments");
1977 obj->type = OBJ_text;
1980 DBGP("parsed hwmon args: '%s' '%s' %d %f %f\n", buf1, buf2, n, factor, offset);
1981 obj->data.sysfs.fd = open_hwmon_sensor((*buf1) ? buf1 : 0, buf2, n,
1982 &obj->data.sysfs.arg, obj->data.sysfs.devtype);
1983 strncpy(obj->data.sysfs.type, buf2, 63);
1984 obj->data.sysfs.factor = factor;
1985 obj->data.sysfs.offset = offset;
1987 #endif /* !__OpenBSD__ */
1990 /* we have four different types of top (top, top_mem, top_time and top_io). To
1991 * avoid having almost-same code four times, we have this special
1993 if (strncmp(s, "top", 3) == EQUAL) {
1994 if (!parse_top_args(s, arg, obj)) {
1997 } else OBJ(addr, INFO_NET)
1999 obj->data.net = get_net_stat(arg);
2001 // default to DEFAULTNETDEV
2002 char *buf = strndup(DEFAULTNETDEV, text_buffer_size);
2003 obj->data.net = get_net_stat(buf);
2006 #if defined(__linux__)
2007 END OBJ(addrs, INFO_NET)
2009 obj->data.net = get_net_stat(arg);
2011 // default to DEFAULTNETDEV
2012 char *buf = strndup(DEFAULTNETDEV, text_buffer_size);
2013 obj->data.net = get_net_stat(buf);
2016 #endif /* __linux__ */
2018 if (init_tail_object(obj, arg)) {
2019 obj->type = OBJ_text;
2020 obj->data.s = strndup("${tail}", text_buffer_size);
2023 if (init_head_object(obj, arg)) {
2024 obj->type = OBJ_text;
2025 obj->data.s = strndup("${head}", text_buffer_size);
2029 obj->data.s = strndup(arg, text_buffer_size);
2031 CRIT_ERR("lines needs a argument");
2035 obj->data.s = strndup(arg, text_buffer_size);
2037 CRIT_ERR("words needs a argument");
2039 END OBJ(loadavg, INFO_LOADAVG)
2040 int a = 1, b = 2, c = 3, r = 3;
2043 r = sscanf(arg, "%d %d %d", &a, &b, &c);
2044 if (r >= 3 && (c < 1 || c > 3)) {
2047 if (r >= 2 && (b < 1 || b > 3)) {
2050 if (r >= 1 && (a < 1 || a > 3)) {
2054 obj->data.loadavg[0] = (r >= 1) ? (unsigned char) a : 0;
2055 obj->data.loadavg[1] = (r >= 2) ? (unsigned char) b : 0;
2056 obj->data.loadavg[2] = (r >= 3) ? (unsigned char) c : 0;
2057 END OBJ_IF(if_empty, 0)
2059 ERR("if_empty needs an argument");
2060 obj->data.ifblock.s = 0;
2062 obj->data.ifblock.s = strndup(arg, text_buffer_size);
2063 obj->sub = malloc(sizeof(struct text_object));
2064 extract_variable_text_internal(obj->sub,
2065 obj->data.ifblock.s, 0);
2067 END OBJ_IF(if_match, 0)
2069 ERR("if_match needs arguments");
2070 obj->data.ifblock.s = 0;
2072 obj->data.ifblock.s = strndup(arg, text_buffer_size);
2073 obj->sub = malloc(sizeof(struct text_object));
2074 extract_variable_text_internal(obj->sub,
2075 obj->data.ifblock.s, 0);
2077 END OBJ_IF(if_existing, 0)
2079 ERR("if_existing needs an argument or two");
2080 obj->data.ifblock.s = NULL;
2081 obj->data.ifblock.str = NULL;
2083 char buf1[256], buf2[256];
2084 int r = sscanf(arg, "%255s %255[^\n]", buf1, buf2);
2087 obj->data.ifblock.s = strndup(buf1, text_buffer_size);
2088 obj->data.ifblock.str = NULL;
2090 obj->data.ifblock.s = strndup(buf1, text_buffer_size);
2091 obj->data.ifblock.str = strndup(buf2, text_buffer_size);
2094 DBGP("if_existing: '%s' '%s'", obj->data.ifblock.s, obj->data.ifblock.str);
2095 END OBJ_IF(if_mounted, 0)
2097 ERR("if_mounted needs an argument");
2098 obj->data.ifblock.s = 0;
2100 obj->data.ifblock.s = strndup(arg, text_buffer_size);
2102 END OBJ_IF(if_running, 0)
2106 snprintf(buf, 256, "pidof %s >/dev/null", arg);
2107 obj->data.ifblock.s = strndup(buf, text_buffer_size);
2109 ERR("if_running needs an argument");
2110 obj->data.ifblock.s = 0;
2116 char box[256], dst[256];
2120 /* Kapil: Changed from MAIL_FILE to
2121 current_mail_spool since the latter
2122 is a copy of the former if undefined
2123 but the latter should take precedence
2125 strncpy(box, current_mail_spool, sizeof(box));
2127 if (sscanf(arg, "%s %f", box, &n1) != 2) {
2129 strncpy(box, arg, sizeof(box));
2133 variable_substitute(box, dst, sizeof(dst));
2134 obj->data.local_mail.box = strndup(dst, text_buffer_size);
2135 obj->data.local_mail.interval = n1;
2136 END OBJ(new_mails, 0)
2138 char box[256], dst[256];
2142 strncpy(box, current_mail_spool, sizeof(box));
2144 if (sscanf(arg, "%s %f", box, &n1) != 2) {
2146 strncpy(box, arg, sizeof(box));
2150 variable_substitute(box, dst, sizeof(dst));
2151 obj->data.local_mail.box = strndup(dst, text_buffer_size);
2152 obj->data.local_mail.interval = n1;
2153 END OBJ(seen_mails, 0)
2155 char box[256], dst[256];
2159 strncpy(box, current_mail_spool, sizeof(box));
2161 if (sscanf(arg, "%s %f", box, &n1) != 2) {
2163 strncpy(box, arg, sizeof(box));
2167 variable_substitute(box, dst, sizeof(dst));
2168 obj->data.local_mail.box = strndup(dst, text_buffer_size);
2169 obj->data.local_mail.interval = n1;
2170 END OBJ(unseen_mails, 0)
2172 char box[256], dst[256];
2176 strncpy(box, current_mail_spool, sizeof(box));
2178 if (sscanf(arg, "%s %f", box, &n1) != 2) {
2180 strncpy(box, arg, sizeof(box));
2184 variable_substitute(box, dst, sizeof(dst));
2185 obj->data.local_mail.box = strndup(dst, text_buffer_size);
2186 obj->data.local_mail.interval = n1;
2187 END OBJ(flagged_mails, 0)
2189 char box[256], dst[256];
2193 strncpy(box, current_mail_spool, sizeof(box));
2195 if (sscanf(arg, "%s %f", box, &n1) != 2) {
2197 strncpy(box, arg, sizeof(box));
2201 variable_substitute(box, dst, sizeof(dst));
2202 obj->data.local_mail.box = strndup(dst, text_buffer_size);
2203 obj->data.local_mail.interval = n1;
2204 END OBJ(unflagged_mails, 0)
2206 char box[256], dst[256];
2210 strncpy(box, current_mail_spool, sizeof(box));
2212 if (sscanf(arg, "%s %f", box, &n1) != 2) {
2214 strncpy(box, arg, sizeof(box));
2218 variable_substitute(box, dst, sizeof(dst));
2219 obj->data.local_mail.box = strndup(dst, text_buffer_size);
2220 obj->data.local_mail.interval = n1;
2221 END OBJ(forwarded_mails, 0)
2223 char box[256], dst[256];
2227 strncpy(box, current_mail_spool, sizeof(box));
2229 if (sscanf(arg, "%s %f", box, &n1) != 2) {
2231 strncpy(box, arg, sizeof(box));
2235 variable_substitute(box, dst, sizeof(dst));
2236 obj->data.local_mail.box = strndup(dst, text_buffer_size);
2237 obj->data.local_mail.interval = n1;
2238 END OBJ(unforwarded_mails, 0)
2240 char box[256], dst[256];
2244 strncpy(box, current_mail_spool, sizeof(box));
2246 if (sscanf(arg, "%s %f", box, &n1) != 2) {
2248 strncpy(box, arg, sizeof(box));
2252 variable_substitute(box, dst, sizeof(dst));
2253 obj->data.local_mail.box = strndup(dst, text_buffer_size);
2254 obj->data.local_mail.interval = n1;
2255 END OBJ(replied_mails, 0)
2257 char box[256], dst[256];
2261 strncpy(box, current_mail_spool, sizeof(box));
2263 if (sscanf(arg, "%s %f", box, &n1) != 2) {
2265 strncpy(box, arg, sizeof(box));
2269 variable_substitute(box, dst, sizeof(dst));
2270 obj->data.local_mail.box = strndup(dst, text_buffer_size);
2271 obj->data.local_mail.interval = n1;
2272 END OBJ(unreplied_mails, 0)
2274 char box[256], dst[256];
2278 strncpy(box, current_mail_spool, sizeof(box));
2280 if (sscanf(arg, "%s %f", box, &n1) != 2) {
2282 strncpy(box, arg, sizeof(box));
2286 variable_substitute(box, dst, sizeof(dst));
2287 obj->data.local_mail.box = strndup(dst, text_buffer_size);
2288 obj->data.local_mail.interval = n1;
2289 END OBJ(draft_mails, 0)
2291 char box[256], dst[256];
2295 strncpy(box, current_mail_spool, sizeof(box));
2297 if (sscanf(arg, "%s %f", box, &n1) != 2) {
2299 strncpy(box, arg, sizeof(box));
2303 variable_substitute(box, dst, sizeof(dst));
2304 obj->data.local_mail.box = strndup(dst, text_buffer_size);
2305 obj->data.local_mail.interval = n1;
2306 END OBJ(trashed_mails, 0)
2308 char box[256], dst[256];
2312 strncpy(box, current_mail_spool, sizeof(box));
2314 if (sscanf(arg, "%s %f", box, &n1) != 2) {
2316 strncpy(box, arg, sizeof(box));
2320 variable_substitute(box, dst, sizeof(dst));
2321 obj->data.local_mail.box = strndup(dst, text_buffer_size);
2322 obj->data.local_mail.interval = n1;
2323 END OBJ(mboxscan, 0)
2324 obj->data.mboxscan.args = (char *) malloc(text_buffer_size);
2325 obj->data.mboxscan.output = (char *) malloc(text_buffer_size);
2326 /* if '1' (in mboxscan.c) then there was SIGUSR1, hmm */
2327 obj->data.mboxscan.output[0] = 1;
2328 strncpy(obj->data.mboxscan.args, arg, text_buffer_size);
2329 END OBJ(mem, INFO_MEM)
2330 END OBJ(memeasyfree, INFO_MEM)
2331 END OBJ(memfree, INFO_MEM)
2332 END OBJ(memmax, INFO_MEM)
2333 END OBJ(memperc, INFO_MEM)
2335 END OBJ(memgauge, INFO_MEM)
2336 SIZE_DEFAULTS(gauge);
2337 scan_gauge(arg, &obj->data.pair.a, &obj->data.pair.b);
2339 END OBJ(membar, INFO_MEM)
2341 scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
2343 END OBJ(memgraph, INFO_MEM)
2345 SIZE_DEFAULTS(graph);
2346 buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
2347 &obj->e, &obj->char_a, &obj->char_b);
2353 END OBJ(mixer, INFO_MIXER)
2354 obj->data.l = mixer_init(arg);
2355 END OBJ(mixerl, INFO_MIXER)
2356 obj->data.l = mixer_init(arg);
2357 END OBJ(mixerr, INFO_MIXER)
2358 obj->data.l = mixer_init(arg);
2360 END OBJ(mixerbar, INFO_MIXER)
2362 scan_mixer_bar(arg, &obj->data.mixerbar.l, &obj->data.mixerbar.w,
2363 &obj->data.mixerbar.h);
2364 END OBJ(mixerlbar, INFO_MIXER)
2366 scan_mixer_bar(arg, &obj->data.mixerbar.l, &obj->data.mixerbar.w,
2367 &obj->data.mixerbar.h);
2368 END OBJ(mixerrbar, INFO_MIXER)
2370 scan_mixer_bar(arg, &obj->data.mixerbar.l, &obj->data.mixerbar.w,
2371 &obj->data.mixerbar.h);
2373 END OBJ_IF(if_mixer_mute, INFO_MIXER)
2374 obj->data.ifblock.i = mixer_init(arg);
2376 END OBJ(monitor, INFO_X11)
2377 END OBJ(monitor_number, INFO_X11)
2379 END OBJ(nodename, 0)
2380 END OBJ(processes, INFO_PROCS)
2381 END OBJ(running_processes, INFO_RUN_PROCS)
2382 END OBJ(shadecolor, 0)
2384 obj->data.l = arg ? get_x11_color(arg) : default_bg_color;
2386 END OBJ(outlinecolor, 0)
2388 obj->data.l = arg ? get_x11_color(arg) : default_out_color;
2390 END OBJ(stippled_hr, 0)
2392 int a = stippled_borders, b = 1;
2395 if (sscanf(arg, "%d %d", &a, &b) != 2) {
2396 sscanf(arg, "%d", &b);
2402 obj->data.pair.a = a;
2403 obj->data.pair.b = b;
2405 END OBJ(swap, INFO_MEM)
2406 END OBJ(swapmax, INFO_MEM)
2407 END OBJ(swapperc, INFO_MEM)
2408 END OBJ(swapbar, INFO_MEM)
2410 scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
2413 obj->data.s = strndup(arg ? arg : "%F %T", text_buffer_size);
2415 obj->data.s = strndup(arg ? arg : "%F %T", text_buffer_size);
2417 char buf1[256], buf2[256], *fmt, *tz;
2421 int nArgs = sscanf(arg, "%255s %255[^\n]", buf1, buf2);
2431 obj->data.tztime.fmt = strndup(fmt ? fmt : "%F %T", text_buffer_size);
2432 obj->data.tztime.tz = tz ? strndup(tz, text_buffer_size) : NULL;
2434 END OBJ(iconv_start, 0)
2435 if (iconv_converting) {
2436 CRIT_ERR("You must stop your last iconv conversion before "
2437 "starting another");
2440 char iconv_from[CODEPAGE_LENGTH];
2441 char iconv_to[CODEPAGE_LENGTH];
2443 if (sscanf(arg, "%s %s", iconv_from, iconv_to) != 2) {
2444 CRIT_ERR("Invalid arguments for iconv_start");
2448 new_iconv = iconv_open(iconv_to, iconv_from);
2449 if (new_iconv == (iconv_t) (-1)) {
2450 ERR("Can't convert from %s to %s.", iconv_from, iconv_to);
2452 obj->a = register_iconv(&new_iconv);
2453 iconv_converting = 1;
2457 CRIT_ERR("Iconv requires arguments");
2459 END OBJ(iconv_stop, 0)
2460 iconv_converting = 0;
2463 END OBJ(totaldown, INFO_NET)
2465 obj->data.net = get_net_stat(arg);
2467 // default to DEFAULTNETDEV
2468 char *buf = strndup(DEFAULTNETDEV, text_buffer_size);
2469 obj->data.net = get_net_stat(buf);
2472 END OBJ(totalup, INFO_NET)
2473 obj->data.net = get_net_stat(arg);
2475 obj->data.net = get_net_stat(arg);
2477 // default to DEFAULTNETDEV
2478 char *buf = strndup(DEFAULTNETDEV, text_buffer_size);
2479 obj->data.net = get_net_stat(buf);
2483 END OBJ_IF(if_updatenr, 0)
2484 obj->data.ifblock.i = arg ? atoi(arg) : 0;
2485 if(obj->data.ifblock.i == 0) CRIT_ERR("if_updatenr needs a number above 0 as argument");
2486 updatereset = obj->data.ifblock.i > updatereset ? obj->data.ifblock.i : updatereset;
2488 obj->data.i = arg ? atoi(arg) : 0;
2490 obj->data.i = arg ? atoi(arg) : 0;
2491 END OBJ(upspeed, INFO_NET)
2493 obj->data.net = get_net_stat(arg);
2495 // default to DEFAULTNETDEV
2496 char *buf = strndup(DEFAULTNETDEV, text_buffer_size);
2497 obj->data.net = get_net_stat(buf);
2500 END OBJ(upspeedf, INFO_NET)
2502 obj->data.net = get_net_stat(arg);
2504 // default to DEFAULTNETDEV
2505 char *buf = strndup(DEFAULTNETDEV, text_buffer_size);
2506 obj->data.net = get_net_stat(buf);
2511 END OBJ(upspeedgraph, INFO_NET)
2513 SIZE_DEFAULTS(graph);
2514 buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
2515 &obj->e, &obj->char_a, &obj->char_b);
2517 // default to DEFAULTNETDEV
2518 buf = strndup(buf ? buf : DEFAULTNETDEV, text_buffer_size);
2519 obj->data.net = get_net_stat(buf);
2522 END OBJ(uptime_short, INFO_UPTIME)
2523 END OBJ(uptime, INFO_UPTIME)
2524 END OBJ(user_names, INFO_USERS)
2525 END OBJ(user_times, INFO_USERS)
2526 END OBJ(user_terms, INFO_USERS)
2527 END OBJ(user_number, INFO_USERS)
2528 #if defined(__linux__)
2529 END OBJ(gw_iface, INFO_GW)
2530 END OBJ(gw_ip, INFO_GW)
2531 #endif /* !__linux__ */
2533 END OBJ(adt746xcpu, 0)
2534 END OBJ(adt746xfan, 0)
2535 #endif /* !__OpenBSD__ */
2536 #if (defined(__FreeBSD__) || defined(__FreeBSD_kernel__) \
2537 || defined(__OpenBSD__)) && (defined(i386) || defined(__i386__))
2538 END OBJ(apm_adapter, 0)
2539 END OBJ(apm_battery_life, 0)
2540 END OBJ(apm_battery_time, 0)
2541 #endif /* __FreeBSD__ */
2542 END OBJ_THREAD(imap_unseen, 0)
2545 obj->data.mail = parse_mail_args(IMAP_TYPE, arg);
2550 END OBJ_THREAD(imap_messages, 0)
2553 obj->data.mail = parse_mail_args(IMAP_TYPE, arg);
2558 END OBJ_THREAD(pop3_unseen, 0)
2561 obj->data.mail = parse_mail_args(POP3_TYPE, arg);
2566 END OBJ_THREAD(pop3_used, 0)
2569 obj->data.mail = parse_mail_args(POP3_TYPE, arg);
2577 obj->data.s = strndup(arg, text_buffer_size);
2579 ERR("smapi needs an argument");
2580 END OBJ_IF(if_smapi_bat_installed, 0)
2582 ERR("if_smapi_bat_installed needs an argument");
2583 obj->data.ifblock.s = 0;
2585 obj->data.ifblock.s = strndup(arg, text_buffer_size);
2586 END OBJ(smapi_bat_perc, 0)
2588 obj->data.s = strndup(arg, text_buffer_size);
2590 ERR("smapi_bat_perc needs an argument");
2591 END OBJ(smapi_bat_temp, 0)
2593 obj->data.s = strndup(arg, text_buffer_size);
2595 ERR("smapi_bat_temp needs an argument");
2596 END OBJ(smapi_bat_power, 0)
2598 obj->data.s = strndup(arg, text_buffer_size);
2600 ERR("smapi_bat_power needs an argument");
2602 END OBJ(smapi_bat_bar, 0)
2606 if(sscanf(arg, "%i %n", &obj->data.i, &cnt) <= 0) {
2607 ERR("first argument to smapi_bat_bar must be an integer value");
2611 arg = scan_bar(arg + cnt, &obj->a, &obj->b);
2614 ERR("smapi_bat_bar needs an argument");
2618 #define mpd_set_maxlen(name) \
2621 sscanf(arg, "%d", &i); \
2623 obj->data.i = i + 1; \
2625 ERR(#name ": invalid length argument"); \
2627 END OBJ(mpd_artist, INFO_MPD)
2628 mpd_set_maxlen(mpd_artist);
2630 END OBJ(mpd_title, INFO_MPD)
2631 mpd_set_maxlen(mpd_title);
2633 END OBJ(mpd_random, INFO_MPD) init_mpd();
2634 END OBJ(mpd_repeat, INFO_MPD) init_mpd();
2635 END OBJ(mpd_elapsed, INFO_MPD) init_mpd();
2636 END OBJ(mpd_length, INFO_MPD) init_mpd();
2637 END OBJ(mpd_track, INFO_MPD)
2638 mpd_set_maxlen(mpd_track);
2640 END OBJ(mpd_name, INFO_MPD)
2641 mpd_set_maxlen(mpd_name);
2643 END OBJ(mpd_file, INFO_MPD)
2644 mpd_set_maxlen(mpd_file);
2646 END OBJ(mpd_percent, INFO_MPD) init_mpd();
2647 END OBJ(mpd_album, INFO_MPD)
2648 mpd_set_maxlen(mpd_album);
2650 END OBJ(mpd_vol, INFO_MPD) init_mpd();
2651 END OBJ(mpd_bitrate, INFO_MPD) init_mpd();
2652 END OBJ(mpd_status, INFO_MPD) init_mpd();
2653 END OBJ(mpd_bar, INFO_MPD)
2655 scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
2657 END OBJ(mpd_smart, INFO_MPD)
2658 mpd_set_maxlen(mpd_smart);
2660 END OBJ_IF(if_mpd_playing, INFO_MPD)
2662 #undef mpd_set_maxlen
2665 END OBJ(moc_state, INFO_MOC)
2666 END OBJ(moc_file, INFO_MOC)
2667 END OBJ(moc_title, INFO_MOC)
2668 END OBJ(moc_artist, INFO_MOC)
2669 END OBJ(moc_song, INFO_MOC)
2670 END OBJ(moc_album, INFO_MOC)
2671 END OBJ(moc_totaltime, INFO_MOC)
2672 END OBJ(moc_timeleft, INFO_MOC)
2673 END OBJ(moc_curtime, INFO_MOC)
2674 END OBJ(moc_bitrate, INFO_MOC)
2675 END OBJ(moc_rate, INFO_MOC)
2678 END OBJ(xmms2_artist, INFO_XMMS2)
2679 END OBJ(xmms2_album, INFO_XMMS2)
2680 END OBJ(xmms2_title, INFO_XMMS2)
2681 END OBJ(xmms2_genre, INFO_XMMS2)
2682 END OBJ(xmms2_comment, INFO_XMMS2)
2683 END OBJ(xmms2_url, INFO_XMMS2)
2684 END OBJ(xmms2_tracknr, INFO_XMMS2)
2685 END OBJ(xmms2_bitrate, INFO_XMMS2)
2686 END OBJ(xmms2_date, INFO_XMMS2)
2687 END OBJ(xmms2_id, INFO_XMMS2)
2688 END OBJ(xmms2_duration, INFO_XMMS2)
2689 END OBJ(xmms2_elapsed, INFO_XMMS2)
2690 END OBJ(xmms2_size, INFO_XMMS2)
2691 END OBJ(xmms2_status, INFO_XMMS2)
2692 END OBJ(xmms2_percent, INFO_XMMS2)
2694 END OBJ(xmms2_bar, INFO_XMMS2)
2696 scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
2698 END OBJ(xmms2_smart, INFO_XMMS2)
2699 END OBJ(xmms2_playlist, INFO_XMMS2)
2700 END OBJ(xmms2_timesplayed, INFO_XMMS2)
2701 END OBJ_IF(if_xmms2_connected, INFO_XMMS2)
2704 END OBJ(audacious_status, INFO_AUDACIOUS)
2705 END OBJ(audacious_title, INFO_AUDACIOUS)
2707 sscanf(arg, "%d", &info.audacious.max_title_len);
2708 if (info.audacious.max_title_len > 0) {
2709 info.audacious.max_title_len++;
2711 CRIT_ERR("audacious_title: invalid length argument");
2714 END OBJ(audacious_length, INFO_AUDACIOUS)
2715 END OBJ(audacious_length_seconds, INFO_AUDACIOUS)
2716 END OBJ(audacious_position, INFO_AUDACIOUS)
2717 END OBJ(audacious_position_seconds, INFO_AUDACIOUS)
2718 END OBJ(audacious_bitrate, INFO_AUDACIOUS)
2719 END OBJ(audacious_frequency, INFO_AUDACIOUS)
2720 END OBJ(audacious_channels, INFO_AUDACIOUS)
2721 END OBJ(audacious_filename, INFO_AUDACIOUS)
2722 END OBJ(audacious_playlist_length, INFO_AUDACIOUS)
2723 END OBJ(audacious_playlist_position, INFO_AUDACIOUS)
2724 END OBJ(audacious_main_volume, INFO_AUDACIOUS)
2726 END OBJ(audacious_bar, INFO_AUDACIOUS)
2728 scan_bar(arg, &obj->a, &obj->b);
2732 END OBJ(bmpx_title, INFO_BMPX)
2733 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
2734 END OBJ(bmpx_artist, INFO_BMPX)
2735 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
2736 END OBJ(bmpx_album, INFO_BMPX)
2737 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
2738 END OBJ(bmpx_track, INFO_BMPX)
2739 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
2740 END OBJ(bmpx_uri, INFO_BMPX)
2741 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
2742 END OBJ(bmpx_bitrate, INFO_BMPX)
2743 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
2749 char *userid = (char *) malloc(20 * sizeof(char));
2750 char *apikey = (char *) malloc(64 * sizeof(char));
2751 char *charid = (char *) malloc(20 * sizeof(char));
2753 argc = sscanf(arg, "%20s %64s %20s", userid, apikey, charid);
2754 obj->data.eve.charid = charid;
2755 obj->data.eve.userid = userid;
2756 obj->data.eve.apikey = apikey;
2760 CRIT_ERR("eve needs arguments: <userid> <apikey> <characterid>");
2766 int argc, delay, act_par;
2767 unsigned int nrspaces = 0;
2768 char *uri = (char *) malloc(128 * sizeof(char));
2769 char *action = (char *) malloc(64 * sizeof(char));
2771 argc = sscanf(arg, "%127s %d %63s %d %u", uri, &delay, action,
2772 &act_par, &nrspaces);
2773 obj->data.rss.uri = uri;
2774 obj->data.rss.delay = delay;
2775 obj->data.rss.action = action;
2776 obj->data.rss.act_par = act_par;
2777 obj->data.rss.nrspaces = nrspaces;
2781 CRIT_ERR("rss needs arguments: <uri> <delay in minutes> <action> "
2782 "[act_par] [spaces in front]");
2788 obj->data.s = strndup(arg, text_buffer_size);
2790 CRIT_ERR("lua needs arguments: <function name> [function parameters]");
2792 END OBJ(lua_parse, 0)
2794 obj->data.s = strndup(arg, text_buffer_size);
2796 CRIT_ERR("lua_parse needs arguments: <function name> [function parameters]");
2798 END OBJ(lua_read_parse, 0)
2800 obj->data.s = strndup(arg, text_buffer_size);
2802 CRIT_ERR("lua_read_parse needs arguments: <function name> <string to pass>");
2807 arg = scan_bar(arg, &obj->a, &obj->b);
2809 obj->data.s = strndup(arg, text_buffer_size);
2811 CRIT_ERR("lua_bar needs arguments: <height>,<width> <function name> [function parameters]");
2814 CRIT_ERR("lua_bar needs arguments: <height>,<width> <function name> [function parameters]");
2817 END OBJ(lua_graph, 0)
2818 SIZE_DEFAULTS(graph);
2820 arg = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
2821 &obj->e, &obj->char_a, &obj->char_b);
2823 obj->data.s = strndup(arg, text_buffer_size);
2825 CRIT_ERR("lua_graph needs arguments: <\"normal\"|\"log\"> <height>,<width> <gradient colour 1> <gradient colour 2> <scale> <function name> [function parameters]");
2828 CRIT_ERR("lua_graph needs arguments: <\"normal\"|\"log\"> <height>,<width> <gradient colour 1> <gradient colour 2> <scale> <function name> [function parameters]");
2830 END OBJ(lua_gauge, 0)
2831 SIZE_DEFAULTS(gauge);
2833 arg = scan_gauge(arg, &obj->a, &obj->b);
2835 obj->data.s = strndup(arg, text_buffer_size);
2837 CRIT_ERR("lua_gauge needs arguments: <height>,<width> <function name> [function parameters]");
2840 CRIT_ERR("lua_gauge needs arguments: <height>,<width> <function name> [function parameters]");
2843 #endif /* HAVE_LUA */
2846 if (scan_hddtemp(arg, &obj->data.hddtemp.dev,
2847 &obj->data.hddtemp.addr, &obj->data.hddtemp.port)) {
2848 ERR("hddtemp needs arguments");
2849 obj->type = OBJ_text;
2850 obj->data.s = strndup("${hddtemp}", text_buffer_size);
2851 obj->data.hddtemp.update_time = 0;
2853 obj->data.hddtemp.temp = NULL;
2854 #endif /* HDDTEMP */
2855 #ifdef TCP_PORT_MONITOR
2856 END OBJ(tcp_portmon, INFO_TCP_PORT_MONITOR)
2857 tcp_portmon_init(arg, &obj->data.tcp_port_monitor);
2858 #endif /* TCP_PORT_MONITOR */
2859 END OBJ(entropy_avail, INFO_ENTROPY)
2860 END OBJ(entropy_perc, INFO_ENTROPY)
2861 END OBJ(entropy_poolsize, INFO_ENTROPY)
2862 END OBJ(entropy_bar, INFO_ENTROPY)
2864 scan_bar(arg, &obj->a, &obj->b);
2865 END OBJ(to_bytes, 0)
2867 obj->sub = malloc(sizeof(struct text_object));
2868 extract_variable_text_internal(obj->sub, arg, 0);
2870 CRIT_ERR("to_bytes needs a argument");
2875 obj->data.scroll.step = 1;
2876 if (arg && sscanf(arg, "%u %n", &obj->data.scroll.show, &n1) > 0) {
2877 if (sscanf(arg + n1, "%u %n", &obj->data.scroll.step, &n2) > 0)
2879 obj->data.scroll.text = strndup(arg + n1, text_buffer_size);
2880 obj->data.scroll.start = 0;
2881 obj->sub = malloc(sizeof(struct text_object));
2882 extract_variable_text_internal(obj->sub,
2883 obj->data.scroll.text, 0);
2885 CRIT_ERR("scroll needs arguments: <length> [<step>] <text>");
2890 unsigned int indenting = 0; //vars can be used as args for other vars
2893 startvar[0] = endvar[0] = startvar[1] = endvar[1] = -1;
2895 for (i=0; arg[i] != 0 && j < 2; i++) {
2896 if(startvar[j] == -1) {
2900 }else if(endvar[j] == -1) {
2903 }else if(arg[i] == '}') {
2906 if (indenting == 0 && arg[i+1] < 48) { //<48 has 0, $, and the most used chars not used in varnames but not { or }
2912 if(startvar[0] >= 0 && endvar[0] >= 0 && startvar[1] >= 0 && endvar[1] >= 0) {
2913 obj->data.combine.left = malloc(endvar[0]-startvar[0] + 1);
2914 obj->data.combine.seperation = malloc(startvar[1] - endvar[0] + 1);
2915 obj->data.combine.right= malloc(endvar[1]-startvar[1] + 1);
2917 strncpy(obj->data.combine.left, arg + startvar[0], endvar[0] - startvar[0]);
2918 obj->data.combine.left[endvar[0] - startvar[0]] = 0;
2920 strncpy(obj->data.combine.seperation, arg + endvar[0], startvar[1] - endvar[0]);
2921 obj->data.combine.seperation[startvar[1] - endvar[0]] = 0;
2923 strncpy(obj->data.combine.right, arg + startvar[1], endvar[1] - startvar[1]);
2924 obj->data.combine.right[endvar[1] - startvar[1]] = 0;
2926 obj->sub = malloc(sizeof(struct text_object));
2927 extract_variable_text_internal(obj->sub, obj->data.combine.left, 0);
2928 obj->sub->sub = malloc(sizeof(struct text_object));
2929 extract_variable_text_internal(obj->sub->sub, obj->data.combine.right, 0);
2931 CRIT_ERR("combine needs arguments: <text1> <text2>");
2934 CRIT_ERR("combine needs arguments: <text1> <text2>");
2939 CRIT_ERR("nvidia needs an argument\n");
2940 } else if (set_nvidia_type(&obj->data.nvidia, arg)) {
2941 CRIT_ERR("nvidia: invalid argument"
2942 " specified: '%s'\n", arg);
2947 END OBJ(apcupsd, INFO_APCUPSD)
2951 if (sscanf(arg, "%63s %d", host, &port) != 2) {
2952 CRIT_ERR("apcupsd needs arguments: <host> <port>");
2954 info.apcupsd.port = htons(port);
2955 strncpy(info.apcupsd.host, host, sizeof(info.apcupsd.host));
2958 CRIT_ERR("apcupsd needs arguments: <host> <port>");
2960 END OBJ(apcupsd_name, INFO_APCUPSD)
2961 END OBJ(apcupsd_model, INFO_APCUPSD)
2962 END OBJ(apcupsd_upsmode, INFO_APCUPSD)
2963 END OBJ(apcupsd_cable, INFO_APCUPSD)
2964 END OBJ(apcupsd_status, INFO_APCUPSD)
2965 END OBJ(apcupsd_linev, INFO_APCUPSD)
2966 END OBJ(apcupsd_load, INFO_APCUPSD)
2967 END OBJ(apcupsd_loadbar, INFO_APCUPSD)
2969 scan_bar(arg, &obj->a, &obj->b);
2971 END OBJ(apcupsd_loadgraph, INFO_APCUPSD)
2973 SIZE_DEFAULTS(graph);
2974 buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
2975 &obj->e, &obj->char_a, &obj->char_b);
2977 END OBJ(apcupsd_loadgauge, INFO_APCUPSD)
2978 SIZE_DEFAULTS(gauge);
2979 scan_gauge(arg, &obj->a, &obj->b);
2981 END OBJ(apcupsd_charge, INFO_APCUPSD)
2982 END OBJ(apcupsd_timeleft, INFO_APCUPSD)
2983 END OBJ(apcupsd_temp, INFO_APCUPSD)
2984 END OBJ(apcupsd_lastxfer, INFO_APCUPSD)
2985 #endif /* APCUPSD */
2989 ERR("unknown variable %s", s);
2990 obj->type = OBJ_text;
2991 snprintf(buf, 256, "${%s}", s);
2992 obj->data.s = strndup(buf, text_buffer_size);
2999 static struct text_object *create_plain_text(const char *s)
3001 struct text_object *obj;
3003 if (s == NULL || *s == '\0') {
3007 obj = new_text_object_internal();
3009 obj->type = OBJ_text;
3010 obj->data.s = strndup(s, text_buffer_size);
3014 /* backslash_escape - do the actual substitution task for template objects
3016 * The field templates is used for substituting the \N occurences. Set it to
3017 * NULL to leave them as they are.
3019 static char *backslash_escape(const char *src, char **templates, unsigned int template_count)
3023 unsigned int dup_idx = 0, dup_len;
3025 dup_len = strlen(src) + 1;
3026 src_dup = malloc(dup_len * sizeof(char));
3034 if (*(p + 1) == '\\') {
3035 src_dup[dup_idx++] = '\\';
3037 } else if (*(p + 1) == ' ') {
3038 src_dup[dup_idx++] = ' ';
3040 } else if (*(p + 1) == 'n') {
3041 src_dup[dup_idx++] = '\n';
3043 } else if (templates) {
3044 unsigned int tmpl_num;
3046 if ((sscanf(p + 1, "%u%n", &tmpl_num, &digits) <= 0) ||
3047 (tmpl_num > template_count))
3049 dup_len += strlen(templates[tmpl_num - 1]);
3050 src_dup = realloc(src_dup, dup_len * sizeof(char));
3051 sprintf(src_dup + dup_idx, "%s", templates[tmpl_num - 1]);
3052 dup_idx += strlen(templates[tmpl_num - 1]);
3057 src_dup[dup_idx++] = *p;
3062 src_dup[dup_idx] = '\0';
3063 src_dup = realloc(src_dup, (strlen(src_dup) + 1) * sizeof(char));
3067 /* handle_template_object - core logic of the template object
3069 * use config variables like this:
3070 * template1 = "$\1\2"
3071 * template2 = "\1: ${fs_bar 4,100 \2} ${fs_used \2} / ${fs_size \2}"
3073 * and use them like this:
3074 * ${template1 node name}
3075 * ${template2 root /}
3076 * ${template2 cdrom /mnt/cdrom}
3078 static char *handle_template(const char *tmpl, const char *args)
3080 char *args_dup = NULL;
3082 char **argsp = NULL;
3083 unsigned int argcnt = 0, template_idx, i;
3086 if ((sscanf(tmpl, "template%u", &template_idx) != 1) ||
3087 (template_idx >= MAX_TEMPLATES))
3091 args_dup = strdup(args);
3094 while (*p && (*p == ' ' && (p == args_dup || *(p - 1) != '\\')))
3096 if (p > args_dup && *(p - 1) == '\\')
3099 while (*p && (*p != ' ' || (p > args_dup && *(p - 1) == '\\')))
3105 argsp = realloc(argsp, ++argcnt * sizeof(char *));
3106 argsp[argcnt - 1] = p_old;
3108 for (i = 0; i < argcnt; i++) {
3110 tmp = backslash_escape(argsp[i], NULL, 0);
3111 DBGP2("%s: substituted arg '%s' to '%s'", tmpl, argsp[i], tmp);
3116 eval_text = backslash_escape(template[template_idx], argsp, argcnt);
3117 DBGP("substituted %s, output is '%s'", tmpl, eval_text);
3119 for (i = 0; i < argcnt; i++)
3125 static char *find_and_replace_templates(const char *inbuf)
3127 char *outbuf, *indup, *p, *o, *templ, *args, *tmpl_out;
3130 outlen = strlen(inbuf) + 1;
3131 o = outbuf = calloc(outlen, sizeof(char));
3132 memset(outbuf, 0, outlen * sizeof(char));
3134 p = indup = strdup(inbuf);
3136 while (*p && *p != '$')
3142 if (strncmp(p, "$template", 9) && strncmp(p, "${template", 10)) {
3147 if (*(p + 1) == '{') {
3150 while (*p && !isspace(*p) && *p != '{' && *p != '}')
3158 while (*p && stack > 0) {
3166 // stack is empty. that means the previous char was }, so we zero it
3169 // we ran into the end of string without finding a closing }, bark
3170 CRIT_ERR("cannot find a closing '}' in template expansion");
3174 while (*p && !isspace(*p))
3178 tmpl_out = handle_template(templ, args);
3180 outlen += strlen(tmpl_out);
3182 outbuf = realloc(outbuf, outlen * sizeof(char));
3183 strcat (outbuf, tmpl_out);
3185 o = outbuf + strlen(outbuf);
3187 ERR("failed to handle template '%s' with args '%s'", templ, args);
3191 outbuf = realloc(outbuf, (strlen(outbuf) + 1) * sizeof(char));
3196 static int text_contains_templates(const char *text)
3198 if (strcasestr(text, "${template") != NULL)
3200 if (strcasestr(text, "$template") != NULL)
3205 static void strfold(char *start, int count)
3208 for (curplace = start + count; *curplace != 0; curplace++) {
3209 *(curplace - count) = *curplace;
3211 *(curplace - count) = 0;
3215 * - assumes that *string is '#'
3216 * - removes the part from '#' to the end of line ('\n' or '\0')
3217 * - BUT, it leaves the '\n'
3219 static size_t remove_comment(char *string)
3222 while(*end != '\0' && *end != '\n')
3224 strfold(string, end - string);
3225 return end - string;
3228 static size_t remove_comments(char *string)
3232 for (curplace = string; *curplace != 0; curplace++) {
3233 if (*curplace == '\\' && *(curplace + 1) == '#') {
3234 // strcpy can't be used for overlapping strings
3235 strfold(curplace, 1);
3237 } else if (*curplace == '#') {
3238 folded += remove_comment(curplace);
3244 static int extract_variable_text_internal(struct text_object *retval, const char *const_p, char allow_threaded)
3246 struct text_object *obj;
3247 char *p, *s, *orig_p;
3249 void *ifblock_opaque = NULL;
3254 p = strndup(const_p, max_user_text - 1);
3255 while (text_contains_templates(p)) {
3257 tmp = find_and_replace_templates(p);
3263 if (strcmp(p, const_p)) {
3264 DBGP("replaced all templates in text: input is\n'%s'\noutput is\n'%s'", const_p, p);
3266 DBGP("no templates to replace");
3269 memset(retval, 0, sizeof(struct text_object));
3271 line = global_text_lines;
3279 obj = create_plain_text(s);
3281 append_object(retval, obj);
3291 /* variable is either $foo or ${foo} */
3293 unsigned int brl = 1, brr = 0;
3297 while (*p && brl != brr) {
3312 while (*p && (isalnum((int) *p) || *p == '_')) {
3317 /* copy variable to buffer */
3318 len = (p - s > 255) ? 255 : (p - s);
3319 strncpy(buf, s, len);
3327 /* search for variable in environment */
3331 obj = create_plain_text(var);
3333 append_object(retval, obj);
3338 /* if variable wasn't found in environment, use some special */
3343 if (strchr(buf, ' ')) {
3344 arg = strchr(buf, ' ');
3347 while (isspace((int) *arg)) {
3355 /* lowercase variable name */
3358 *tmp_p = tolower(*tmp_p);
3362 obj = construct_text_object(buf, arg,
3363 line, allow_threaded,
3366 append_object(retval, obj);
3370 obj = create_plain_text("$");
3373 append_object(retval, obj);
3376 } else if (*p == '#') {
3381 obj = create_plain_text(s);
3383 append_object(retval, obj);
3386 if (!ifblock_stack_empty(&ifblock_opaque)) {
3387 ERR("one or more $endif's are missing");
3394 static void extract_variable_text(const char *p)
3396 free_text_objects(&global_root_object, 0);
3410 extract_variable_text_internal(&global_root_object, p, 1);
3413 int parse_conky_vars(struct text_object *root, char *txt, char *p, struct information *cur)
3415 extract_variable_text_internal(root, txt, 0);
3416 generate_text_internal(p, max_user_text, *root, cur);
3420 static inline struct mail_s *ensure_mail_thread(struct text_object *obj,
3421 void *thread(void *), const char *text)
3423 if (obj->char_b && info.mail) {
3424 // this means we use info
3425 if (!info.mail->p_timed_thread) {
3426 info.mail->p_timed_thread =
3427 timed_thread_create(thread,
3428 (void *) info.mail, info.mail->interval * 1000000);
3429 if (!info.mail->p_timed_thread) {
3430 ERR("Error creating %s timed thread", text);
3432 timed_thread_register(info.mail->p_timed_thread,
3433 &info.mail->p_timed_thread);
3434 if (timed_thread_run(info.mail->p_timed_thread)) {
3435 ERR("Error running %s timed thread", text);
3439 } else if (obj->data.mail) {
3440 // this means we use obj
3441 if (!obj->data.mail->p_timed_thread) {
3442 obj->data.mail->p_timed_thread =
3443 timed_thread_create(thread,
3444 (void *) obj->data.mail,
3445 obj->data.mail->interval * 1000000);
3446 if (!obj->data.mail->p_timed_thread) {
3447 ERR("Error creating %s timed thread", text);
3449 timed_thread_register(obj->data.mail->p_timed_thread,
3450 &obj->data.mail->p_timed_thread);
3451 if (timed_thread_run(obj->data.mail->p_timed_thread)) {
3452 ERR("Error running %s timed thread", text);
3455 return obj->data.mail;
3456 } else if (!obj->a) {
3457 // something is wrong, warn once then stop
3458 ERR("There's a problem with your mail settings. "
3459 "Check that the global mail settings are properly defined"
3460 " (line %li).", obj->line);
3466 char *format_time(unsigned long timeval, const int width)
3469 unsigned long nt; // narrow time, for speed on 32-bit
3470 unsigned cc; // centiseconds
3471 unsigned nn; // multi-purpose whatever
3474 cc = nt % 100; // centiseconds past second
3475 nt /= 100; // total seconds
3476 nn = nt % 60; // seconds past the minute
3477 nt /= 60; // total minutes
3478 if (width >= snprintf(buf, sizeof buf, "%lu:%02u.%02u",
3480 return strndup(buf, text_buffer_size);
3482 if (width >= snprintf(buf, sizeof buf, "%lu:%02u", nt, nn)) {
3483 return strndup(buf, text_buffer_size);
3485 nn = nt % 60; // minutes past the hour
3486 nt /= 60; // total hours
3487 if (width >= snprintf(buf, sizeof buf, "%lu,%02u", nt, nn)) {
3488 return strndup(buf, text_buffer_size);
3490 nn = nt; // now also hours
3491 if (width >= snprintf(buf, sizeof buf, "%uh", nn)) {
3492 return strndup(buf, text_buffer_size);
3494 nn /= 24; // now days
3495 if (width >= snprintf(buf, sizeof buf, "%ud", nn)) {
3496 return strndup(buf, text_buffer_size);
3498 nn /= 7; // now weeks
3499 if (width >= snprintf(buf, sizeof buf, "%uw", nn)) {
3500 return strndup(buf, text_buffer_size);
3502 // well shoot, this outta' fit...
3503 return strndup("<inf>", text_buffer_size);
3506 //remove backspaced chars, example: "dog^H^H^Hcat" becomes "cat"
3507 //string has to end with \0 and it's length should fit in a int
3509 void remove_deleted_chars(char *string){
3511 while(string[i] != 0){
3512 if(string[i] == BACKSPACE){
3514 strcpy( &(string[i-1]), &(string[i+1]) );
3516 }else strcpy( &(string[i]), &(string[i+1]) ); //necessary for ^H's at the start of a string
3521 static inline void format_media_player_time(char *buf, const int size,
3524 int days, hours, minutes;
3526 days = seconds / (24 * 60 * 60);
3527 seconds %= (24 * 60 * 60);
3528 hours = seconds / (60 * 60);
3529 seconds %= (60 * 60);
3530 minutes = seconds / 60;
3534 snprintf(buf, size, "%i days %i:%02i:%02i", days,
3535 hours, minutes, seconds);
3536 } else if (hours > 0) {
3537 snprintf(buf, size, "%i:%02i:%02i", hours, minutes,
3540 snprintf(buf, size, "%i:%02i", minutes, seconds);
3544 static inline double get_barnum(char *buf)
3556 if (sscanf(buf, "%lf", &barnum) == 0) {
3557 ERR("reading exec value failed (perhaps it's not the "
3558 "correct format?)");
3561 if (barnum > 100.0 || barnum < 0.0) {
3562 ERR("your exec value is not between 0 and 100, "
3563 "therefore it will be ignored");
3569 static void generate_text_internal(char *p, int p_max_size,
3570 struct text_object root, struct information *cur)
3572 struct text_object *obj;
3574 int need_to_load_fonts = 0;
3577 /* for the OBJ_top* handler */
3578 struct process **needed = 0;
3581 char buff_in[p_max_size];
3583 iconv_converting = 0;
3584 #endif /* HAVE_ICONV */
3588 while (obj && p_max_size > 0) {
3589 needed = 0; // reset for top stuff
3591 /* IFBLOCK jumping algorithm
3593 * This is easier as it looks like:
3594 * - each IF checks it's condition
3595 * - on FALSE: call DO_JUMP
3596 * - on TRUE: don't care
3597 * - each ELSE calls DO_JUMP unconditionally
3598 * - each ENDIF is silently being ignored
3601 * DO_JUMP overwrites the "obj" variable of the loop and sets it to the target
3602 * (i.e. the corresponding ELSE or ENDIF). After that, processing for the given
3603 * object can continue, free()ing stuff e.g., then the for-loop does the rest: as
3604 * regularly, "obj" is being updated to point to obj->next, so object parsing
3605 * continues right after the corresponding ELSE or ENDIF. This means that if we
3606 * find an ELSE, it's corresponding IF must not have jumped, so we need to jump
3607 * always. If we encounter an ENDIF, it's corresponding IF or ELSE has not
3608 * jumped, and there is nothing to do.
3612 obj = obj->data.ifblock.next; \
3615 #define OBJ(a) break; case OBJ_##a:
3617 switch (obj->type) {
3619 ERR("not implemented obj type %d", obj->type);
3622 struct sockaddr_in addr;
3623 struct hostent* he = gethostbyname(obj->data.read_tcp.host);
3625 sock = socket(he->h_addrtype, SOCK_STREAM, 0);
3627 memset(&addr, 0, sizeof(addr));
3628 addr.sin_family = AF_INET;
3629 addr.sin_port = obj->data.read_tcp.port;
3630 memcpy(&addr.sin_addr, he->h_addr, he->h_length);
3631 if (connect(sock, (struct sockaddr*)&addr, sizeof(struct sockaddr)) == 0) {
3635 FD_SET(sock, &readfds);
3638 if(select(sock + 1, &readfds, NULL, NULL, &tv) > 0){
3639 received = recv(sock, p, p_max_size, 0);
3644 ERR("read_tcp: Couldn't create a connection");
3647 ERR("read_tcp: Couldn't create a socket");
3650 ERR("read_tcp: Problem with resolving the hostname");
3655 temp_print(p, p_max_size, get_acpi_temperature(obj->data.i), TEMP_CELSIUS);
3657 #endif /* !__OpenBSD__ */
3660 obj->a = get_freq(p, p_max_size, "%.0f", 1,
3661 obj->data.cpu_index);
3667 obj->a = get_freq(p, p_max_size, "%'.2f", 1000,
3668 obj->data.cpu_index);
3670 /* OpenBSD has no such flag (SUSv2) */
3671 obj->a = get_freq(p, p_max_size, "%.2f", 1000,
3672 obj->data.cpu_index);
3673 #endif /* __OpenBSD */
3676 #if defined(__linux__)
3679 obj->a = get_voltage(p, p_max_size, "%.0f", 1,
3680 obj->data.cpu_index);
3685 obj->a = get_voltage(p, p_max_size, "%'.3f", 1000,
3686 obj->data.cpu_index);
3691 OBJ(wireless_essid) {
3692 snprintf(p, p_max_size, "%s", obj->data.net->essid);
3694 OBJ(wireless_mode) {
3695 snprintf(p, p_max_size, "%s", obj->data.net->mode);
3697 OBJ(wireless_bitrate) {
3698 snprintf(p, p_max_size, "%s", obj->data.net->bitrate);
3701 snprintf(p, p_max_size, "%s", obj->data.net->ap);
3703 OBJ(wireless_link_qual) {
3704 spaced_print(p, p_max_size, "%d", 4,
3705 obj->data.net->link_qual);
3707 OBJ(wireless_link_qual_max) {
3708 spaced_print(p, p_max_size, "%d", 4,
3709 obj->data.net->link_qual_max);
3711 OBJ(wireless_link_qual_perc) {
3712 if (obj->data.net->link_qual_max > 0) {
3713 spaced_print(p, p_max_size, "%.0f", 5,
3714 (double) obj->data.net->link_qual /
3715 obj->data.net->link_qual_max * 100);
3717 spaced_print(p, p_max_size, "unk", 5);
3720 OBJ(wireless_link_bar) {
3722 if(output_methods & TO_X) {
3723 new_bar(p, obj->a, obj->b, ((double) obj->data.net->link_qual /
3724 obj->data.net->link_qual_max) * 255.0);
3727 if(!obj->a) obj->a = DEFAULT_BAR_WIDTH_NO_X;
3728 new_bar_in_shell(p, p_max_size, ((double) obj->data.net->link_qual /
3729 obj->data.net->link_qual_max) * 100.0, obj->a);
3734 #endif /* HAVE_IWLIB */
3736 #endif /* __linux__ */
3740 get_adt746x_cpu(p, p_max_size);
3743 get_adt746x_fan(p, p_max_size);
3746 get_acpi_fan(p, p_max_size);
3748 OBJ(acpiacadapter) {
3749 get_acpi_ac_adapter(p, p_max_size);
3752 get_battery_stuff(p, p_max_size, obj->data.s, BATTERY_STATUS);
3755 get_battery_stuff(p, p_max_size, obj->data.s, BATTERY_TIME);
3757 OBJ(battery_percent) {
3758 percent_print(p, p_max_size, get_battery_perct(obj->data.s));
3762 if(output_methods & TO_X) {
3763 new_bar(p, obj->a, obj->b, get_battery_perct_bar(obj->data.s));
3766 if(!obj->a) obj->a = DEFAULT_BAR_WIDTH_NO_X;
3767 new_bar_in_shell(p, p_max_size, get_battery_perct_bar(obj->data.s) / 2.55, obj->a);
3772 OBJ(battery_short) {
3773 get_battery_short_status(p, p_max_size, obj->data.s);
3775 #endif /* __OpenBSD__ */
3778 human_readable(cur->buffers * 1024, p, 255);
3781 human_readable(cur->cached * 1024, p, 255);
3784 if (obj->data.cpu_index > info.cpu_count) {
3785 ERR("obj->data.cpu_index %i info.cpu_count %i",
3786 obj->data.cpu_index, info.cpu_count);
3787 CRIT_ERR("attempting to use more CPUs than you have!");
3789 percent_print(p, p_max_size,
3790 round_to_int(cur->cpu_usage[obj->data.cpu_index] * 100.0));
3794 new_gauge(p, obj->a, obj->b,
3795 round_to_int(cur->cpu_usage[obj->data.cpu_index] * 255.0));
3799 if(output_methods & TO_X) {
3800 new_bar(p, obj->a, obj->b,
3801 round_to_int(cur->cpu_usage[obj->data.cpu_index] * 255.0));
3804 if(!obj->a) obj->a = DEFAULT_BAR_WIDTH_NO_X;
3805 new_bar_in_shell(p, p_max_size, round_to_int(cur->cpu_usage[obj->data.cpu_index] * 100), obj->a);
3812 new_graph(p, obj->a, obj->b, obj->c, obj->d,
3813 round_to_int(cur->cpu_usage[obj->data.cpu_index] * 100),
3814 100, 1, obj->char_a, obj->char_b);
3817 new_graph(p, obj->a, obj->b, obj->c, obj->d, cur->loadavg[0],
3818 obj->e, 1, obj->char_a, obj->char_b);
3821 new_fg(p, obj->data.l);
3854 OBJ(conky_version) {
3855 snprintf(p, p_max_size, "%s", VERSION);
3857 OBJ(conky_build_date) {
3858 snprintf(p, p_max_size, "%s", BUILD_DATE);
3860 OBJ(conky_build_arch) {
3861 snprintf(p, p_max_size, "%s", BUILD_ARCH);
3863 #if defined(__linux__)
3865 snprintf(p, p_max_size, "%s",
3866 get_disk_protect_queue(obj->data.s));
3869 snprintf(p, p_max_size, "%s", i8k.version);
3872 snprintf(p, p_max_size, "%s", i8k.bios);
3875 snprintf(p, p_max_size, "%s", i8k.serial);
3880 sscanf(i8k.cpu_temp, "%d", &cpu_temp);
3881 temp_print(p, p_max_size, (double)cpu_temp, TEMP_CELSIUS);
3883 OBJ(i8k_left_fan_status) {
3884 int left_fan_status;
3886 sscanf(i8k.left_fan_status, "%d", &left_fan_status);
3887 if (left_fan_status == 0) {
3888 snprintf(p, p_max_size, "off");
3890 if (left_fan_status == 1) {
3891 snprintf(p, p_max_size, "low");
3893 if (left_fan_status == 2) {
3894 snprintf(p, p_max_size, "high");
3897 OBJ(i8k_right_fan_status) {
3898 int right_fan_status;
3900 sscanf(i8k.right_fan_status, "%d", &right_fan_status);
3901 if (right_fan_status == 0) {
3902 snprintf(p, p_max_size, "off");
3904 if (right_fan_status == 1) {
3905 snprintf(p, p_max_size, "low");
3907 if (right_fan_status == 2) {
3908 snprintf(p, p_max_size, "high");
3911 OBJ(i8k_left_fan_rpm) {
3912 snprintf(p, p_max_size, "%s", i8k.left_fan_rpm);
3914 OBJ(i8k_right_fan_rpm) {
3915 snprintf(p, p_max_size, "%s", i8k.right_fan_rpm);
3917 OBJ(i8k_ac_status) {
3920 sscanf(i8k.ac_status, "%d", &ac_status);
3921 if (ac_status == -1) {
3922 snprintf(p, p_max_size, "disabled (read i8k docs)");
3924 if (ac_status == 0) {
3925 snprintf(p, p_max_size, "off");
3927 if (ac_status == 1) {
3928 snprintf(p, p_max_size, "on");
3931 OBJ(i8k_buttons_status) {
3932 snprintf(p, p_max_size, "%s", i8k.buttons_status);
3936 get_ibm_acpi_fan(p, p_max_size);
3939 get_ibm_acpi_temps();
3940 temp_print(p, p_max_size,
3941 ibm_acpi.temps[obj->data.sensor], TEMP_CELSIUS);
3944 get_ibm_acpi_volume(p, p_max_size);
3946 OBJ(ibm_brightness) {
3947 get_ibm_acpi_brightness(p, p_max_size);
3950 /* information from sony_laptop kernel module
3951 * /sys/devices/platform/sony-laptop */
3952 OBJ(sony_fanspeed) {
3953 get_sony_fanspeed(p, p_max_size);
3956 if (!cur->gw_info.count) {
3961 snprintf(p, p_max_size, "%s", cur->gw_info.iface);
3964 snprintf(p, p_max_size, "%s", cur->gw_info.ip);
3967 snprintf(p, p_max_size, "%d", get_laptop_mode());
3970 get_powerbook_batt_info(p, p_max_size, obj->data.i);
3972 #endif /* __linux__ */
3973 #if (defined(__FreeBSD__) || defined(__linux__))
3975 if ((obj->data.ifblock.s)
3976 && (!interface_up(obj->data.ifblock.s))) {
3982 OBJ(obsd_sensors_temp) {
3983 obsd_sensors.device = sensor_device;
3984 update_obsd_sensors();
3985 temp_print(p, p_max_size,
3986 obsd_sensors.temp[obsd_sensors.device][obj->data.sensor],
3989 OBJ(obsd_sensors_fan) {
3990 obsd_sensors.device = sensor_device;
3991 update_obsd_sensors();
3992 snprintf(p, p_max_size, "%d",
3993 obsd_sensors.fan[obsd_sensors.device][obj->data.sensor]);
3995 OBJ(obsd_sensors_volt) {
3996 obsd_sensors.device = sensor_device;
3997 update_obsd_sensors();
3998 snprintf(p, p_max_size, "%.2f",
3999 obsd_sensors.volt[obsd_sensors.device][obj->data.sensor]);
4002 get_obsd_vendor(p, p_max_size);
4005 get_obsd_product(p, p_max_size);
4007 #endif /* __OpenBSD__ */
4010 new_font(p, obj->data.s);
4011 need_to_load_fonts = 1;
4014 /* TODO: move this correction from kB to kB/s elsewhere
4015 * (or get rid of it??) */
4017 human_readable((obj->data.diskio->current / update_interval) * 1024LL,
4021 human_readable((obj->data.diskio->current_write / update_interval) * 1024LL,
4025 human_readable((obj->data.diskio->current_read / update_interval) * 1024LL,
4030 new_graph(p, obj->a, obj->b, obj->c, obj->d,
4031 obj->data.diskio->current, obj->e, 1, obj->char_a, obj->char_b);
4033 OBJ(diskiograph_read) {
4034 new_graph(p, obj->a, obj->b, obj->c, obj->d,
4035 obj->data.diskio->current_read, obj->e, 1, obj->char_a, obj->char_b);
4037 OBJ(diskiograph_write) {
4038 new_graph(p, obj->a, obj->b, obj->c, obj->d,
4039 obj->data.diskio->current_write, obj->e, 1, obj->char_a, obj->char_b);
4043 human_readable(obj->data.net->recv_speed, p, 255);
4046 spaced_print(p, p_max_size, "%.1f", 8,
4047 obj->data.net->recv_speed / 1024.0);
4050 OBJ(downspeedgraph) {
4051 new_graph(p, obj->a, obj->b, obj->c, obj->d,
4052 obj->data.net->recv_speed / 1024.0, obj->e, 1, obj->char_a, obj->char_b);
4056 /* Since we see you, you're if has not jumped.
4057 * Do Ninja jump here: without leaving traces.
4058 * This is to prevent us from stale jumped flags.
4060 obj = obj->data.ifblock.next;
4064 /* harmless object, just ignore */
4068 if ((obj->data.net->addr.sa_data[2] & 255) == 0
4069 && (obj->data.net->addr.sa_data[3] & 255) == 0
4070 && (obj->data.net->addr.sa_data[4] & 255) == 0
4071 && (obj->data.net->addr.sa_data[5] & 255) == 0) {
4072 snprintf(p, p_max_size, "No Address");
4074 snprintf(p, p_max_size, "%u.%u.%u.%u",
4075 obj->data.net->addr.sa_data[2] & 255,
4076 obj->data.net->addr.sa_data[3] & 255,
4077 obj->data.net->addr.sa_data[4] & 255,
4078 obj->data.net->addr.sa_data[5] & 255);
4081 #if defined(__linux__)
4083 if(NULL != obj->data.net->addrs && strlen(obj->data.net->addrs) > 2)
4085 obj->data.net->addrs[strlen(obj->data.net->addrs) - 2] = 0; /* remove ", " from end of string */
4086 strcpy(p, obj->data.net->addrs);
4089 strcpy(p, "0.0.0.0");
4091 #endif /* __linux__ */
4092 #if defined(IMLIB2) && defined(X11)
4094 /* doesn't actually draw anything, just queues it omp. the
4095 * image will get drawn after the X event loop */
4096 cimlib_add_image(obj->data.s);
4100 struct information *tmp_info;
4101 struct text_object subroot, subroot2;
4103 tmp_info = malloc(sizeof(struct information));
4104 memcpy(tmp_info, cur, sizeof(struct information));
4105 parse_conky_vars(&subroot, obj->data.s, p, tmp_info);
4106 DBGP("evaluated '%s' to '%s'", obj->data.s, p);
4107 parse_conky_vars(&subroot2, p, p, tmp_info);
4109 free_text_objects(&subroot, 1);
4110 free_text_objects(&subroot2, 1);
4114 read_exec(obj->data.s, p, text_buffer_size);
4115 remove_deleted_chars(p);
4118 struct information *tmp_info;
4119 struct text_object subroot;
4121 read_exec(obj->data.s, p, text_buffer_size);
4123 tmp_info = malloc(sizeof(struct information));
4124 memcpy(tmp_info, cur, sizeof(struct information));
4125 parse_conky_vars(&subroot, p, p, tmp_info);
4127 free_text_objects(&subroot, 1);
4134 read_exec(obj->data.s, p, text_buffer_size);
4135 barnum = get_barnum(p); /*using the same function*/
4137 if (barnum >= 0.0) {
4139 new_gauge(p, obj->a, obj->b, round_to_int(barnum * 255.0));
4146 read_exec(obj->data.s, p, text_buffer_size);
4147 barnum = get_barnum(p);
4149 if (barnum >= 0.0) {
4151 if(output_methods & TO_X) {
4153 new_bar(p, obj->a, obj->b, round_to_int(barnum * 255.0));
4156 if(!obj->a) obj->a = DEFAULT_BAR_WIDTH_NO_X;
4157 new_bar_in_shell(p, p_max_size, barnum, obj->a);
4165 char showaslog = FALSE;
4166 char tempgrad = FALSE;
4168 char *cmd = obj->data.s;
4170 if (strncasecmp(obj->data.execi.cmd, LOGGRAPH" ", strlen(LOGGRAPH" ")) == EQUAL) {
4172 cmd = cmd + strlen(LOGGRAPH" ") * sizeof(char);
4173 } else if(strncasecmp(obj->data.s, NORMGRAPH" ", strlen(NORMGRAPH" ")) == EQUAL) {
4174 cmd = cmd + strlen(NORMGRAPH" ") * sizeof(char);
4176 if (strstr(cmd, " "TEMPGRAD) && strlen(cmd) > strlen(" "TEMPGRAD)) {
4178 cmd += strlen(" "TEMPGRAD);
4180 read_exec(cmd, p, text_buffer_size);
4181 barnum = get_barnum(p);
4184 new_graph(p, obj->a, obj->b, obj->c, obj->d, round_to_int(barnum),
4185 100, 1, showaslog, tempgrad);
4190 if (current_update_time - obj->data.execi.last_update
4191 >= obj->data.execi.interval) {
4194 read_exec(obj->data.execi.cmd, p, text_buffer_size);
4195 barnum = get_barnum(p);
4197 if (barnum >= 0.0) {
4200 obj->data.execi.last_update = current_update_time;
4203 if(output_methods & TO_X) {
4204 new_bar(p, obj->a, obj->b, round_to_int(obj->f * 2.55));
4207 if(!obj->a) obj->a = DEFAULT_BAR_WIDTH_NO_X;
4208 new_bar_in_shell(p, p_max_size, round_to_int(obj->f), obj->a);
4215 if (current_update_time - obj->data.execi.last_update
4216 >= obj->data.execi.interval) {
4218 char showaslog = FALSE;
4219 char tempgrad = FALSE;
4220 char *cmd = obj->data.execi.cmd;
4222 if (strncasecmp(obj->data.execi.cmd, LOGGRAPH" ", strlen(LOGGRAPH" ")) == EQUAL) {
4224 cmd = cmd + strlen(LOGGRAPH" ") * sizeof(char);
4225 } else if(strncasecmp(obj->data.s, NORMGRAPH" ", strlen(NORMGRAPH" ")) == EQUAL) {
4226 cmd = cmd + strlen(NORMGRAPH" ") * sizeof(char);
4228 if (strstr(cmd, " "TEMPGRAD) && strlen(cmd) > strlen(" "TEMPGRAD)) {
4230 cmd += strlen(" "TEMPGRAD);
4232 obj->char_a = showaslog;
4233 obj->char_b = tempgrad;
4234 read_exec(cmd, p, text_buffer_size);
4235 barnum = get_barnum(p);
4237 if (barnum >= 0.0) {
4240 obj->data.execi.last_update = current_update_time;
4242 new_graph(p, obj->a, obj->b, obj->c, obj->d, (int) (obj->f), 100, 1, obj->char_a, obj->char_b);
4245 if (current_update_time - obj->data.execi.last_update
4246 >= obj->data.execi.interval) {
4249 read_exec(obj->data.execi.cmd, p, text_buffer_size);
4250 barnum = get_barnum(p);
4252 if (barnum >= 0.0) {
4253 obj->f = 255 * barnum / 100.0;
4255 obj->data.execi.last_update = current_update_time;
4257 new_gauge(p, obj->a, obj->b, round_to_int(obj->f));
4261 if (current_update_time - obj->data.execi.last_update
4262 >= obj->data.execi.interval
4263 && obj->data.execi.interval != 0) {
4264 read_exec(obj->data.execi.cmd, obj->data.execi.buffer,
4266 obj->data.execi.last_update = current_update_time;
4268 snprintf(p, text_buffer_size, "%s", obj->data.execi.buffer);
4271 struct text_object subroot;
4272 struct information *tmp_info =
4273 malloc(sizeof(struct information));
4274 memcpy(tmp_info, cur, sizeof(struct information));
4276 if (current_update_time - obj->data.execi.last_update
4277 < obj->data.execi.interval
4278 || obj->data.execi.interval == 0) {
4279 parse_conky_vars(&subroot, obj->data.execi.buffer, p, tmp_info);
4281 char *output = obj->data.execi.buffer;
4282 FILE *fp = popen(obj->data.execi.cmd, "r");
4283 int length = fread(output, 1, text_buffer_size, fp);
4287 output[length] = '\0';
4288 if (length > 0 && output[length - 1] == '\n') {
4289 output[length - 1] = '\0';
4292 parse_conky_vars(&subroot, obj->data.execi.buffer, p, tmp_info);
4293 obj->data.execi.last_update = current_update_time;
4295 free_text_objects(&subroot, 1);
4299 if (!obj->data.texeci.p_timed_thread) {
4300 obj->data.texeci.p_timed_thread =
4301 timed_thread_create(&threaded_exec,
4302 (void *) obj, obj->data.texeci.interval * 1000000);
4303 if (!obj->data.texeci.p_timed_thread) {
4304 ERR("Error creating texeci timed thread");
4306 timed_thread_register(obj->data.texeci.p_timed_thread,
4307 &obj->data.texeci.p_timed_thread);
4308 if (timed_thread_run(obj->data.texeci.p_timed_thread)) {
4309 ERR("Error running texeci timed thread");
4312 timed_thread_lock(obj->data.texeci.p_timed_thread);
4313 snprintf(p, text_buffer_size, "%s", obj->data.texeci.buffer);
4314 timed_thread_unlock(obj->data.texeci.p_timed_thread);
4317 #endif /* HAVE_POPEN */
4319 struct mail_s *mail = ensure_mail_thread(obj, imap_thread, "imap");
4321 if (mail && mail->p_timed_thread) {
4322 timed_thread_lock(mail->p_timed_thread);
4323 snprintf(p, p_max_size, "%lu", mail->unseen);
4324 timed_thread_unlock(mail->p_timed_thread);
4327 OBJ(imap_messages) {
4328 struct mail_s *mail = ensure_mail_thread(obj, imap_thread, "imap");
4330 if (mail && mail->p_timed_thread) {
4331 timed_thread_lock(mail->p_timed_thread);
4332 snprintf(p, p_max_size, "%lu", mail->messages);
4333 timed_thread_unlock(mail->p_timed_thread);
4337 struct mail_s *mail = ensure_mail_thread(obj, pop3_thread, "pop3");
4339 if (mail && mail->p_timed_thread) {
4340 timed_thread_lock(mail->p_timed_thread);
4341 snprintf(p, p_max_size, "%lu", mail->unseen);
4342 timed_thread_unlock(mail->p_timed_thread);
4346 struct mail_s *mail = ensure_mail_thread(obj, pop3_thread, "pop3");
4348 if (mail && mail->p_timed_thread) {
4349 timed_thread_lock(mail->p_timed_thread);
4350 snprintf(p, p_max_size, "%.1f",
4351 mail->used / 1024.0 / 1024.0);
4352 timed_thread_unlock(mail->p_timed_thread);
4356 if (obj->data.fs != NULL) {
4357 if (obj->data.fs->size == 0) {
4359 if(output_methods & TO_X) {
4360 new_bar(p, obj->data.fsbar.w, obj->data.fsbar.h, 255);
4363 if(!obj->data.fsbar.w) obj->data.fsbar.w = DEFAULT_BAR_WIDTH_NO_X;
4364 new_bar_in_shell(p, p_max_size, 100, obj->data.fsbar.w);
4370 if(output_methods & TO_X) {
4371 new_bar(p, obj->data.fsbar.w, obj->data.fsbar.h,
4372 (int) (255 - obj->data.fsbar.fs->avail * 255 /
4373 obj->data.fs->size));
4376 if(!obj->data.fsbar.w) obj->data.fsbar.w = DEFAULT_BAR_WIDTH_NO_X;
4377 new_bar_in_shell(p, p_max_size,
4378 (int) (100 - obj->data.fsbar.fs->avail * 100 / obj->data.fs->size), obj->data.fsbar.w);
4386 if (obj->data.fs != NULL) {
4387 human_readable(obj->data.fs->avail, p, 255);
4391 if (obj->data.fs != NULL) {
4394 if (obj->data.fs->size) {
4395 val = obj->data.fs->avail * 100 / obj->data.fs->size;
4398 percent_print(p, p_max_size, val);
4402 if (obj->data.fs != NULL) {
4403 human_readable(obj->data.fs->size, p, 255);
4407 if (obj->data.fs != NULL)
4408 snprintf(p, p_max_size, "%s", obj->data.fs->type);
4411 if (obj->data.fs != NULL) {
4412 human_readable(obj->data.fs->size - obj->data.fs->free, p,
4417 if (obj->data.fs != NULL) {
4418 if (obj->data.fs->size == 0) {
4420 if(output_methods & TO_X) {
4421 new_bar(p, obj->data.fsbar.w, obj->data.fsbar.h, 255);
4424 if(!obj->data.fsbar.w) obj->data.fsbar.w = DEFAULT_BAR_WIDTH_NO_X;
4425 new_bar_in_shell(p, p_max_size, 100, obj->data.fsbar.w);
4431 if(output_methods & TO_X) {
4432 new_bar(p, obj->data.fsbar.w, obj->data.fsbar.h,
4433 (int) (obj->data.fsbar.fs->avail * 255 /
4434 obj->data.fs->size));
4437 if(!obj->data.fsbar.w) obj->data.fsbar.w = DEFAULT_BAR_WIDTH_NO_X;
4438 new_bar_in_shell(p, p_max_size,
4439 (int) (obj->data.fsbar.fs->avail * 100 / obj->data.fs->size), obj->data.fsbar.w);
4447 if (obj->data.fs != NULL) {
4450 if (obj->data.fs->size) {
4451 val = obj->data.fs->free
4456 percent_print(p, p_max_size, 100 - val);
4460 float *v = info.loadavg;
4462 if (obj->data.loadavg[2]) {
4463 snprintf(p, p_max_size, "%.2f %.2f %.2f",
4464 v[obj->data.loadavg[0] - 1],
4465 v[obj->data.loadavg[1] - 1],
4466 v[obj->data.loadavg[2] - 1]);
4467 } else if (obj->data.loadavg[1]) {
4468 snprintf(p, p_max_size, "%.2f %.2f",
4469 v[obj->data.loadavg[0] - 1],
4470 v[obj->data.loadavg[1] - 1]);
4471 } else if (obj->data.loadavg[0]) {
4472 snprintf(p, p_max_size, "%.2f",
4473 v[obj->data.loadavg[0] - 1]);
4477 new_goto(p, obj->data.i);
4480 new_tab(p, obj->data.pair.a, obj->data.pair.b);
4484 new_hr(p, obj->data.i);
4488 if (cur->nameserver_info.nscount > obj->data.i)
4489 snprintf(p, p_max_size, "%s",
4490 cur->nameserver_info.ns_list[obj->data.i]);
4494 char *skill = eve(obj->data.eve.userid, obj->data.eve.apikey, obj->data.eve.charid);
4495 snprintf(p, p_max_size, "%s", skill);
4500 PRSS *data = get_rss_info(obj->data.rss.uri,
4501 obj->data.rss.delay);
4505 snprintf(p, p_max_size, "prss: Error reading RSS data\n");
4507 if (strcmp(obj->data.rss.action, "feed_title") == EQUAL) {
4509 // remove trailing new line if one exists
4510 if (str[strlen(str) - 1] == '\n') {
4511 str[strlen(str) - 1] = 0;
4513 snprintf(p, p_max_size, "%s", str);
4514 } else if (strcmp(obj->data.rss.action, "item_title") == EQUAL) {
4515 if (obj->data.rss.act_par < data->item_count) {
4516 str = data->items[obj->data.rss.act_par].title;
4517 // remove trailing new line if one exists
4518 if (str[strlen(str) - 1] == '\n') {
4519 str[strlen(str) - 1] = 0;
4521 snprintf(p, p_max_size, "%s", str);
4523 } else if (strcmp(obj->data.rss.action, "item_desc") == EQUAL) {
4524 if (obj->data.rss.act_par < data->item_count) {
4526 data->items[obj->data.rss.act_par].description;
4527 // remove trailing new line if one exists
4528 if (str[strlen(str) - 1] == '\n') {
4529 str[strlen(str) - 1] = 0;
4531 snprintf(p, p_max_size, "%s", str);
4533 } else if (strcmp(obj->data.rss.action, "item_titles") == EQUAL) {
4534 if (data->item_count > 0) {
4537 //'tmpspaces' is a string with spaces too be placed in front of each title
4538 char *tmpspaces = malloc(obj->data.rss.nrspaces + 1);
4539 memset(tmpspaces, ' ', obj->data.rss.nrspaces);
4540 tmpspaces[obj->data.rss.nrspaces]=0;
4544 if (obj->data.rss.act_par > data->item_count) {
4545 show = data->item_count;
4547 show = obj->data.rss.act_par;
4549 for (itmp = 0; itmp < show; itmp++) {
4550 PRSS_Item *item = &data->items[itmp];
4554 // don't add new line before first item
4556 strncat(p, "\n", p_max_size);
4558 /* remove trailing new line if one exists,
4559 * we have our own */
4560 if (str[strlen(str) - 1] == '\n') {
4561 str[strlen(str) - 1] = 0;
4563 strncat(p, tmpspaces, p_max_size);
4564 strncat(p, str, p_max_size);
4575 char *str = llua_getstring(obj->data.s);
4577 snprintf(p, p_max_size, "%s", str);
4582 char *str = llua_getstring(obj->data.s);
4584 struct information *tmp_info;
4585 struct text_object subroot;
4587 tmp_info = malloc(sizeof(struct information));
4588 memcpy(tmp_info, cur, sizeof(struct information));
4589 parse_conky_vars(&subroot, str, p, tmp_info);
4591 free_text_objects(&subroot, 1);
4596 OBJ(lua_read_parse) {
4597 struct information *tmp_info;
4598 struct text_object subroot, subroot2;
4601 sscanf(obj->data.s, "%64s", func);
4602 text = obj->data.s + strlen(func) + 1;
4604 tmp_info = malloc(sizeof(struct information));
4605 memcpy(tmp_info, cur, sizeof(struct information));
4606 parse_conky_vars(&subroot, text, p, tmp_info);
4607 DBGP("evaluated '%s' to '%s'", text, p);
4609 str = llua_getstring_read(func, p);
4611 parse_conky_vars(&subroot2, str, p, tmp_info);
4612 DBGP("evaluated '%s' to '%s'", str, p);
4615 free_text_objects(&subroot2, 1);
4617 free_text_objects(&subroot, 1);
4622 if (llua_getnumber(obj->data.s, &per)) {
4624 if(output_methods & TO_X) {
4625 new_bar(p, obj->a, obj->b, (per/100.0 * 255));
4628 if(!obj->a) obj->a = DEFAULT_BAR_WIDTH_NO_X;
4629 new_bar_in_shell(p, p_max_size, per, obj->a);
4638 if (llua_getnumber(obj->data.s, &per)) {
4639 new_graph(p, obj->a, obj->b, obj->c, obj->d,
4640 per, obj->e, 1, obj->char_a, obj->char_b);
4645 if (llua_getnumber(obj->data.s, &per)) {
4646 new_gauge(p, obj->a, obj->b, (per/100.0 * 255));
4650 #endif /* HAVE_LUA */
4655 if (obj->data.hddtemp.update_time < current_update_time - 30) {
4656 if (obj->data.hddtemp.temp)
4657 free(obj->data.hddtemp.temp);
4658 obj->data.hddtemp.temp = get_hddtemp_info(obj->data.hddtemp.dev,
4659 obj->data.hddtemp.addr, obj->data.hddtemp.port);
4660 obj->data.hddtemp.update_time = current_update_time;
4662 if (!obj->data.hddtemp.temp) {
4663 snprintf(p, p_max_size, "N/A");
4665 val = strtol(obj->data.hddtemp.temp + 1, &endptr, 10);
4666 unit = obj->data.hddtemp.temp[0];
4668 if (*endptr != '\0')
4669 snprintf(p, p_max_size, "N/A");
4670 else if (unit == 'C')
4671 temp_print(p, p_max_size, (double)val, TEMP_CELSIUS);
4672 else if (unit == 'F')
4673 temp_print(p, p_max_size, (double)val, TEMP_FAHRENHEIT);
4675 snprintf(p, p_max_size, "N/A");
4680 new_offset(p, obj->data.i);
4683 new_voffset(p, obj->data.i);
4689 r = get_sysfs_info(&obj->data.sysfs.fd, obj->data.sysfs.arg,
4690 obj->data.sysfs.devtype, obj->data.sysfs.type);
4692 r = r * obj->data.sysfs.factor + obj->data.sysfs.offset;
4694 if (!strncmp(obj->data.sysfs.type, "temp", 4)) {
4695 temp_print(p, p_max_size, r, TEMP_CELSIUS);
4696 } else if (r >= 100.0 || r == 0) {
4697 snprintf(p, p_max_size, "%d", (int) r);
4699 snprintf(p, p_max_size, "%.1f", r);
4705 r = get_sysfs_info(&obj->data.sysfs.fd, obj->data.sysfs.arg,
4706 obj->data.sysfs.devtype, obj->data.sysfs.type);
4708 r = r * obj->data.sysfs.factor + obj->data.sysfs.offset;
4710 if (!strncmp(obj->data.sysfs.type, "temp", 4)) {
4711 temp_print(p, p_max_size, r, TEMP_CELSIUS);
4712 } else if (r >= 100.0 || r == 0) {
4713 snprintf(p, p_max_size, "%d", (int) r);
4715 snprintf(p, p_max_size, "%.1f", r);
4721 r = get_sysfs_info(&obj->data.sysfs.fd, obj->data.sysfs.arg,
4722 obj->data.sysfs.devtype, obj->data.sysfs.type);
4724 r = r * obj->data.sysfs.factor + obj->data.sysfs.offset;
4726 if (!strncmp(obj->data.sysfs.type, "temp", 4)) {
4727 temp_print(p, p_max_size, r, TEMP_CELSIUS);
4728 } else if (r >= 100.0 || r == 0) {
4729 snprintf(p, p_max_size, "%d", (int) r);
4731 snprintf(p, p_max_size, "%.1f", r);
4734 #endif /* __linux__ */
4736 new_alignr(p, obj->data.i);
4739 new_alignc(p, obj->data.i);
4742 char buf[max_user_text];
4743 struct information *tmp_info =
4744 malloc(sizeof(struct information));
4745 memcpy(tmp_info, cur, sizeof(struct information));
4746 generate_text_internal(buf, max_user_text,
4747 *obj->sub, tmp_info);
4749 if (strlen(buf) != 0) {
4755 char expression[max_user_text];
4757 struct information *tmp_info;
4759 tmp_info = malloc(sizeof(struct information));
4760 memcpy(tmp_info, cur, sizeof(struct information));
4761 generate_text_internal(expression, max_user_text,
4762 *obj->sub, tmp_info);
4763 DBGP("parsed arg into '%s'", expression);
4765 val = compare(expression);
4767 ERR("compare failed for expression '%s'",
4775 if (obj->data.ifblock.str
4776 && !check_contains(obj->data.ifblock.s,
4777 obj->data.ifblock.str)) {
4779 } else if (obj->data.ifblock.s
4780 && access(obj->data.ifblock.s, F_OK)) {
4785 if ((obj->data.ifblock.s)
4786 && (!check_mount(obj->data.ifblock.s))) {
4791 if ((obj->data.ifblock.s) && system(obj->data.ifblock.s)) {
4795 #if defined(__linux__)
4797 snprintf(p, p_max_size, "%s", get_ioscheduler(obj->data.s));
4801 snprintf(p, p_max_size, "%s", cur->uname_s.release);
4804 snprintf(p, p_max_size, "%s", cur->uname_s.machine);
4809 human_readable(cur->mem * 1024, p, 255);
4812 human_readable(cur->memeasyfree * 1024, p, 255);
4815 human_readable(cur->memfree * 1024, p, 255);
4818 human_readable(cur->memmax * 1024, p, 255);
4822 percent_print(p, p_max_size, cur->mem * 100 / cur->memmax);
4826 new_gauge(p, obj->data.pair.a, obj->data.pair.b,
4827 cur->memmax ? (cur->mem * 255) / (cur->memmax) : 0);
4832 if(output_methods & TO_X) {
4833 new_bar(p, obj->data.pair.a, obj->data.pair.b,
4834 cur->memmax ? (cur->mem * 255) / (cur->memmax) : 0);
4837 if(!obj->data.pair.a) obj->data.pair.a = DEFAULT_BAR_WIDTH_NO_X;
4838 new_bar_in_shell(p, p_max_size, cur->memmax ? (cur->mem * 100) / (cur->memmax) : 0, obj->data.pair.a);
4845 new_graph(p, obj->a, obj->b, obj->c, obj->d,
4846 cur->memmax ? (cur->mem * 100.0) / (cur->memmax) : 0.0,
4847 100, 1, obj->char_a, obj->char_b);
4852 percent_print(p, p_max_size, mixer_get_avg(obj->data.l));
4855 percent_print(p, p_max_size, mixer_get_left(obj->data.l));
4858 percent_print(p, p_max_size, mixer_get_right(obj->data.l));
4862 new_bar(p, obj->data.mixerbar.w, obj->data.mixerbar.h,
4863 mixer_to_255(obj->data.mixerbar.l,mixer_get_avg(obj->data.mixerbar.l)));
4866 new_bar(p, obj->data.mixerbar.w, obj->data.mixerbar.h,
4867 mixer_to_255(obj->data.mixerbar.l,mixer_get_left(obj->data.mixerbar.l)));
4870 new_bar(p, obj->data.mixerbar.w, obj->data.mixerbar.h,
4871 mixer_to_255(obj->data.mixerbar.l,mixer_get_right(obj->data.mixerbar.l)));
4874 OBJ(if_mixer_mute) {
4875 if (!mixer_is_mute(obj->data.ifblock.i)) {
4881 snprintf(p, p_max_size, "%d", cur->x11.monitor.current);
4883 OBJ(monitor_number) {
4884 snprintf(p, p_max_size, "%d", cur->x11.monitor.number);
4890 update_mail_count(&obj->data.local_mail);
4891 snprintf(p, p_max_size, "%d", obj->data.local_mail.mail_count);
4894 update_mail_count(&obj->data.local_mail);
4895 snprintf(p, p_max_size, "%d",
4896 obj->data.local_mail.new_mail_count);
4899 update_mail_count(&obj->data.local_mail);
4900 snprintf(p, p_max_size, "%d",
4901 obj->data.local_mail.seen_mail_count);
4904 update_mail_count(&obj->data.local_mail);
4905 snprintf(p, p_max_size, "%d",
4906 obj->data.local_mail.unseen_mail_count);
4908 OBJ(flagged_mails) {
4909 update_mail_count(&obj->data.local_mail);
4910 snprintf(p, p_max_size, "%d",
4911 obj->data.local_mail.flagged_mail_count);
4913 OBJ(unflagged_mails) {
4914 update_mail_count(&obj->data.local_mail);
4915 snprintf(p, p_max_size, "%d",
4916 obj->data.local_mail.unflagged_mail_count);
4918 OBJ(forwarded_mails) {
4919 update_mail_count(&obj->data.local_mail);
4920 snprintf(p, p_max_size, "%d",
4921 obj->data.local_mail.forwarded_mail_count);
4923 OBJ(unforwarded_mails) {
4924 update_mail_count(&obj->data.local_mail);
4925 snprintf(p, p_max_size, "%d",
4926 obj->data.local_mail.unforwarded_mail_count);
4928 OBJ(replied_mails) {
4929 update_mail_count(&obj->data.local_mail);
4930 snprintf(p, p_max_size, "%d",
4931 obj->data.local_mail.replied_mail_count);
4933 OBJ(unreplied_mails) {
4934 update_mail_count(&obj->data.local_mail);
4935 snprintf(p, p_max_size, "%d",
4936 obj->data.local_mail.unreplied_mail_count);
4939 update_mail_count(&obj->data.local_mail);
4940 snprintf(p, p_max_size, "%d",
4941 obj->data.local_mail.draft_mail_count);
4943 OBJ(trashed_mails) {
4944 update_mail_count(&obj->data.local_mail);
4945 snprintf(p, p_max_size, "%d",
4946 obj->data.local_mail.trashed_mail_count);
4949 mbox_scan(obj->data.mboxscan.args, obj->data.mboxscan.output,
4951 snprintf(p, p_max_size, "%s", obj->data.mboxscan.output);
4954 snprintf(p, p_max_size, "%s", cur->uname_s.nodename);
4957 new_outline(p, obj->data.l);
4960 spaced_print(p, p_max_size, "%hu", 4, cur->procs);
4962 OBJ(running_processes) {
4963 spaced_print(p, p_max_size, "%hu", 4, cur->run_procs);
4966 snprintf(p, p_max_size, "%s", obj->data.s);
4970 new_bg(p, obj->data.l);
4973 new_stippled_hr(p, obj->data.pair.a, obj->data.pair.b);
4977 human_readable(cur->swap * 1024, p, 255);
4980 human_readable(cur->swapmax * 1024, p, 255);
4983 if (cur->swapmax == 0) {
4984 strncpy(p, "No swap", p_max_size);
4986 percent_print(p, p_max_size, cur->swap * 100 / cur->swapmax);
4991 if(output_methods & TO_X) {
4992 new_bar(p, obj->data.pair.a, obj->data.pair.b,
4993 cur->swapmax ? (cur->swap * 255) / (cur->swapmax) : 0);
4996 if(!obj->data.pair.a) obj->data.pair.a = DEFAULT_BAR_WIDTH_NO_X;
4997 new_bar_in_shell(p, p_max_size, cur->swapmax ? (cur->swap * 100) / (cur->swapmax) : 0, obj->data.pair.a);
5003 snprintf(p, p_max_size, "%s", cur->uname_s.sysname);
5006 time_t t = time(NULL);
5007 struct tm *tm = localtime(&t);
5009 setlocale(LC_TIME, "");
5010 strftime(p, p_max_size, obj->data.s, tm);
5013 time_t t = time(NULL);
5014 struct tm *tm = gmtime(&t);
5016 strftime(p, p_max_size, obj->data.s, tm);
5023 if (obj->data.tztime.tz) {
5024 oldTZ = getenv("TZ");
5025 setenv("TZ", obj->data.tztime.tz, 1);
5031 setlocale(LC_TIME, "");
5032 strftime(p, p_max_size, obj->data.tztime.fmt, tm);
5034 setenv("TZ", oldTZ, 1);
5039 // Needless to free oldTZ since getenv gives ptr to static data
5042 human_readable(obj->data.net->recv, p, 255);
5045 human_readable(obj->data.net->trans, p, 255);
5048 snprintf(p, p_max_size, "%d", total_updates);
5051 if(total_updates % updatereset != obj->data.ifblock.i - 1) {
5056 human_readable(obj->data.net->trans_speed, p, 255);
5059 spaced_print(p, p_max_size, "%.1f", 8,
5060 obj->data.net->trans_speed / 1024.0);
5064 new_graph(p, obj->a, obj->b, obj->c, obj->d,
5065 obj->data.net->trans_speed / 1024.0, obj->e, 1, obj->char_a, obj->char_b);
5069 format_seconds_short(p, p_max_size, (int) cur->uptime);
5072 format_seconds(p, p_max_size, (int) cur->uptime);
5075 snprintf(p, p_max_size, "%s", cur->users.names);
5078 snprintf(p, p_max_size, "%s", cur->users.terms);
5081 snprintf(p, p_max_size, "%s", cur->users.times);
5084 snprintf(p, p_max_size, "%d", cur->users.number);
5086 #if (defined(__FreeBSD__) || defined(__FreeBSD_kernel__) \
5087 || defined(__OpenBSD__)) && (defined(i386) || defined(__i386__))
5091 msg = get_apm_adapter();
5092 snprintf(p, p_max_size, "%s", msg);
5095 OBJ(apm_battery_life) {
5098 msg = get_apm_battery_life();
5099 snprintf(p, p_max_size, "%s", msg);
5102 OBJ(apm_battery_time) {
5105 msg = get_apm_battery_time();
5106 snprintf(p, p_max_size, "%s", msg);
5109 #endif /* __FreeBSD__ __OpenBSD__ */
5112 #define mpd_printf(fmt, val) \
5113 snprintf(p, p_max_size, fmt, mpd_get_info()->val)
5114 #define mpd_sprintf(val) { \
5115 if (!obj->data.i || obj->data.i > p_max_size) \
5116 mpd_printf("%s", val); \
5118 snprintf(p, obj->data.i, "%s", mpd_get_info()->val); \
5123 mpd_sprintf(artist);
5127 mpd_printf("%s", random);
5129 mpd_printf("%s", repeat);
5137 mpd_printf("%d", volume);
5139 mpd_printf("%d", bitrate);
5141 mpd_printf("%s", status);
5143 format_media_player_time(p, p_max_size, mpd_get_info()->elapsed);
5146 format_media_player_time(p, p_max_size, mpd_get_info()->length);
5149 percent_print(p, p_max_size, (int)(mpd_get_info()->progress * 100));
5153 if(output_methods & TO_X) {
5154 new_bar(p, obj->data.pair.a, obj->data.pair.b,
5155 (int) (mpd_get_info()->progress * 255.0f));
5158 if(!obj->data.pair.a) obj->data.pair.a = DEFAULT_BAR_WIDTH_NO_X;
5159 new_bar_in_shell(p, p_max_size, (int) (mpd_get_info()->progress * 100.0f), obj->data.pair.a);
5165 struct mpd_s *mpd = mpd_get_info();
5166 int len = obj->data.i;
5167 if (len == 0 || len > p_max_size)
5170 memset(p, 0, p_max_size);
5171 if (mpd->artist && *mpd->artist &&
5172 mpd->title && *mpd->title) {
5173 snprintf(p, len, "%s - %s", mpd->artist,
5175 } else if (mpd->title && *mpd->title) {
5176 snprintf(p, len, "%s", mpd->title);
5177 } else if (mpd->artist && *mpd->artist) {
5178 snprintf(p, len, "%s", mpd->artist);
5179 } else if (mpd->file && *mpd->file) {
5180 snprintf(p, len, "%s", mpd->file);
5185 OBJ(if_mpd_playing) {
5186 if (!mpd_get_info()->is_playing) {
5199 #define MOC_PRINT(t, a) \
5200 snprintf(p, p_max_size, "%s", (moc.t ? moc.t : a))
5202 MOC_PRINT(state, "??");
5205 MOC_PRINT(file, "no file");
5208 MOC_PRINT(title, "no title");
5211 MOC_PRINT(artist, "no artist");
5214 MOC_PRINT(song, "no song");
5217 MOC_PRINT(album, "no album");
5219 OBJ(moc_totaltime) {
5220 MOC_PRINT(totaltime, "0:00");
5223 MOC_PRINT(timeleft, "0:00");
5226 MOC_PRINT(curtime, "0:00");
5229 MOC_PRINT(bitrate, "0Kbps");
5232 MOC_PRINT(rate, "0KHz");
5238 snprintf(p, p_max_size, "%s", cur->xmms2.artist);
5241 snprintf(p, p_max_size, "%s", cur->xmms2.album);
5244 snprintf(p, p_max_size, "%s", cur->xmms2.title);
5247 snprintf(p, p_max_size, "%s", cur->xmms2.genre);
5249 OBJ(xmms2_comment) {
5250 snprintf(p, p_max_size, "%s", cur->xmms2.comment);
5253 snprintf(p, p_max_size, "%s", cur->xmms2.url);
5256 snprintf(p, p_max_size, "%s", cur->xmms2.status);
5259 snprintf(p, p_max_size, "%s", cur->xmms2.date);
5261 OBJ(xmms2_tracknr) {
5262 if (cur->xmms2.tracknr != -1) {
5263 snprintf(p, p_max_size, "%i", cur->xmms2.tracknr);
5266 OBJ(xmms2_bitrate) {
5267 snprintf(p, p_max_size, "%i", cur->xmms2.bitrate);
5270 snprintf(p, p_max_size, "%u", cur->xmms2.id);
5273 snprintf(p, p_max_size, "%2.1f", cur->xmms2.size);
5275 OBJ(xmms2_elapsed) {
5276 snprintf(p, p_max_size, "%02d:%02d", cur->xmms2.elapsed / 60000,
5277 (cur->xmms2.elapsed / 1000) % 60);
5279 OBJ(xmms2_duration) {
5280 snprintf(p, p_max_size, "%02d:%02d",
5281 cur->xmms2.duration / 60000,
5282 (cur->xmms2.duration / 1000) % 60);
5284 OBJ(xmms2_percent) {
5285 snprintf(p, p_max_size, "%2.0f", cur->xmms2.progress * 100);
5289 new_bar(p, obj->data.pair.a, obj->data.pair.b,
5290 (int) (cur->xmms2.progress * 255.0f));
5293 OBJ(xmms2_playlist) {
5294 snprintf(p, p_max_size, "%s", cur->xmms2.playlist);
5296 OBJ(xmms2_timesplayed) {
5297 snprintf(p, p_max_size, "%i", cur->xmms2.timesplayed);
5300 if (strlen(cur->xmms2.title) < 2
5301 && strlen(cur->xmms2.title) < 2) {
5302 snprintf(p, p_max_size, "%s", cur->xmms2.url);
5304 snprintf(p, p_max_size, "%s - %s", cur->xmms2.artist,
5308 OBJ(if_xmms2_connected) {
5309 if (cur->xmms2.conn_state != 1) {
5315 OBJ(audacious_status) {
5316 snprintf(p, p_max_size, "%s",
5317 cur->audacious.items[AUDACIOUS_STATUS]);
5319 OBJ(audacious_title) {
5320 snprintf(p, cur->audacious.max_title_len > 0
5321 ? cur->audacious.max_title_len : p_max_size, "%s",
5322 cur->audacious.items[AUDACIOUS_TITLE]);
5324 OBJ(audacious_length) {
5325 snprintf(p, p_max_size, "%s",
5326 cur->audacious.items[AUDACIOUS_LENGTH]);
5328 OBJ(audacious_length_seconds) {
5329 snprintf(p, p_max_size, "%s",
5330 cur->audacious.items[AUDACIOUS_LENGTH_SECONDS]);
5332 OBJ(audacious_position) {
5333 snprintf(p, p_max_size, "%s",
5334 cur->audacious.items[AUDACIOUS_POSITION]);
5336 OBJ(audacious_position_seconds) {
5337 snprintf(p, p_max_size, "%s",
5338 cur->audacious.items[AUDACIOUS_POSITION_SECONDS]);
5340 OBJ(audacious_bitrate) {
5341 snprintf(p, p_max_size, "%s",
5342 cur->audacious.items[AUDACIOUS_BITRATE]);
5344 OBJ(audacious_frequency) {
5345 snprintf(p, p_max_size, "%s",
5346 cur->audacious.items[AUDACIOUS_FREQUENCY]);
5348 OBJ(audacious_channels) {
5349 snprintf(p, p_max_size, "%s",
5350 cur->audacious.items[AUDACIOUS_CHANNELS]);
5352 OBJ(audacious_filename) {
5353 snprintf(p, p_max_size, "%s",
5354 cur->audacious.items[AUDACIOUS_FILENAME]);
5356 OBJ(audacious_playlist_length) {
5357 snprintf(p, p_max_size, "%s",
5358 cur->audacious.items[AUDACIOUS_PLAYLIST_LENGTH]);
5360 OBJ(audacious_playlist_position) {
5361 snprintf(p, p_max_size, "%s",
5362 cur->audacious.items[AUDACIOUS_PLAYLIST_POSITION]);
5364 OBJ(audacious_main_volume) {
5365 snprintf(p, p_max_size, "%s",
5366 cur->audacious.items[AUDACIOUS_MAIN_VOLUME]);
5369 OBJ(audacious_bar) {
5373 atof(cur->audacious.items[AUDACIOUS_POSITION_SECONDS]) /
5374 atof(cur->audacious.items[AUDACIOUS_LENGTH_SECONDS]);
5375 new_bar(p, obj->a, obj->b, (int) (progress * 255.0f));
5378 #endif /* AUDACIOUS */
5382 snprintf(p, p_max_size, "%s", cur->bmpx.title);
5385 snprintf(p, p_max_size, "%s", cur->bmpx.artist);
5388 snprintf(p, p_max_size, "%s", cur->bmpx.album);
5391 snprintf(p, p_max_size, "%s", cur->bmpx.uri);
5394 snprintf(p, p_max_size, "%i", cur->bmpx.track);
5397 snprintf(p, p_max_size, "%i", cur->bmpx.bitrate);
5400 /* we have four different types of top (top, top_mem,
5401 * top_time and top_io). To avoid having almost-same code four
5402 * times, we have this special handler. */
5405 parse_top_args("top", obj->data.top.s, obj);
5406 if (!needed) needed = cur->cpu;
5408 parse_top_args("top_mem", obj->data.top.s, obj);
5409 if (!needed) needed = cur->memu;
5411 parse_top_args("top_time", obj->data.top.s, obj);
5412 if (!needed) needed = cur->time;
5415 parse_top_args("top_io", obj->data.top.s, obj);
5416 if (!needed) needed = cur->io;
5419 if (needed[obj->data.top.num]) {
5422 switch (obj->data.top.type) {
5424 snprintf(p, top_name_width + 1, "%-*s", top_name_width,
5425 needed[obj->data.top.num]->name);
5428 snprintf(p, 7, "%6.2f",
5429 needed[obj->data.top.num]->amount);
5432 snprintf(p, 6, "%5i",
5433 needed[obj->data.top.num]->pid);
5436 snprintf(p, 7, "%6.2f",
5437 needed[obj->data.top.num]->totalmem);
5440 timeval = format_time(
5441 needed[obj->data.top.num]->total_cpu_time, 9);
5442 snprintf(p, 10, "%9s", timeval);
5446 human_readable(needed[obj->data.top.num]->rss,
5450 human_readable(needed[obj->data.top.num]->vsize,
5454 case TOP_READ_BYTES:
5455 human_readable(needed[obj->data.top.num]->read_bytes / update_interval,
5458 case TOP_WRITE_BYTES:
5459 human_readable(needed[obj->data.top.num]->write_bytes / update_interval,
5463 snprintf(p, 7, "%6.2f",
5464 needed[obj->data.top.num]->io_perc);
5470 print_tail_object(obj, p, p_max_size);
5472 print_head_object(obj, p, p_max_size);
5474 FILE *fp = open_file(obj->data.s, &obj->a);
5477 /* FIXME: use something more general (see also tail.c, head.c */
5478 #define BUFSZ 0x1000
5483 while(fgets(buf, BUFSZ, fp) != NULL){
5484 for(j = 0; buf[j] != 0; j++) {
5485 if(buf[j] == '\n') {
5490 sprintf(p, "%d", lines);
5493 sprintf(p, "File Unreadable");
5498 FILE *fp = open_file(obj->data.s, &obj->a);
5503 char inword = FALSE;
5506 while(fgets(buf, BUFSZ, fp) != NULL){
5507 for(j = 0; buf[j] != 0; j++) {
5508 if(!isspace(buf[j])) {
5509 if(inword == FALSE) {
5518 sprintf(p, "%d", words);
5521 sprintf(p, "File Unreadable");
5524 #ifdef TCP_PORT_MONITOR
5526 tcp_portmon_action(p, p_max_size,
5527 &obj->data.tcp_port_monitor);
5529 #endif /* TCP_PORT_MONITOR */
5533 iconv_converting = 1;
5534 iconv_selected = obj->a;
5537 iconv_converting = 0;
5540 #endif /* HAVE_ICONV */
5542 OBJ(entropy_avail) {
5543 snprintf(p, p_max_size, "%d", cur->entropy.entropy_avail);
5546 percent_print(p, p_max_size,
5547 cur->entropy.entropy_avail *
5548 100 / cur->entropy.poolsize);
5550 OBJ(entropy_poolsize) {
5551 snprintf(p, p_max_size, "%d", cur->entropy.poolsize);
5554 double entropy_perc;
5556 entropy_perc = (double) cur->entropy.entropy_avail /
5557 (double) cur->entropy.poolsize;
5559 if(output_methods & TO_X) {
5560 new_bar(p, obj->a, obj->b, (int) (entropy_perc * 255.0f));
5563 if(!obj->a) obj->a = DEFAULT_BAR_WIDTH_NO_X;
5564 new_bar_in_shell(p, p_max_size, (int) (entropy_perc * 100.0f), obj->a);
5573 s = smapi_get_val(obj->data.s);
5574 snprintf(p, p_max_size, "%s", s);
5578 OBJ(if_smapi_bat_installed) {
5580 if(obj->data.ifblock.s && sscanf(obj->data.ifblock.s, "%i", &idx) == 1) {
5581 if(!smapi_bat_installed(idx)) {
5585 ERR("argument to if_smapi_bat_installed must be an integer");
5587 OBJ(smapi_bat_perc) {
5589 if(obj->data.s && sscanf(obj->data.s, "%i", &idx) == 1) {
5590 val = smapi_bat_installed(idx) ?
5591 smapi_get_bat_int(idx, "remaining_percent") : 0;
5592 percent_print(p, p_max_size, val);
5594 ERR("argument to smapi_bat_perc must be an integer");
5596 OBJ(smapi_bat_temp) {
5598 if(obj->data.s && sscanf(obj->data.s, "%i", &idx) == 1) {
5599 val = smapi_bat_installed(idx) ?
5600 smapi_get_bat_int(idx, "temperature") : 0;
5601 /* temperature is in milli degree celsius */
5602 temp_print(p, p_max_size, val / 1000, TEMP_CELSIUS);
5604 ERR("argument to smapi_bat_temp must be an integer");
5606 OBJ(smapi_bat_power) {
5608 if(obj->data.s && sscanf(obj->data.s, "%i", &idx) == 1) {
5609 val = smapi_bat_installed(idx) ?
5610 smapi_get_bat_int(idx, "power_now") : 0;
5611 /* power_now is in mW, set to W with one digit precision */
5612 snprintf(p, p_max_size, "%.1f", ((double)val / 1000));
5614 ERR("argument to smapi_bat_power must be an integer");
5617 OBJ(smapi_bat_bar) {
5618 if(obj->data.i >= 0 && smapi_bat_installed(obj->data.i))
5619 new_bar(p, obj->a, obj->b, (int)
5620 (255 * smapi_get_bat_int(obj->data.i, "remaining_percent") / 100));
5622 new_bar(p, obj->a, obj->b, 0);
5627 char buf[max_user_text];
5629 char unit[16]; //16 because we can also have long names (like mega-bytes)
5631 generate_text_internal(buf, max_user_text, *obj->sub, cur);
5632 if(sscanf(buf, "%lli%s", &bytes, unit) == 2 && strlen(unit) < 16){
5633 if(strncasecmp("b", unit, 1) == 0) snprintf(buf, max_user_text, "%lli", bytes);
5634 else if(strncasecmp("k", unit, 1) == 0) snprintf(buf, max_user_text, "%lli", bytes * 1024);
5635 else if(strncasecmp("m", unit, 1) == 0) snprintf(buf, max_user_text, "%lli", bytes * 1024 * 1024);
5636 else if(strncasecmp("g", unit, 1) == 0) snprintf(buf, max_user_text, "%lli", bytes * 1024 * 1024 * 1024);
5637 else if(strncasecmp("t", unit, 1) == 0) snprintf(buf, max_user_text, "%lli", bytes * 1024 * 1024 * 1024 * 1024);
5639 snprintf(p, p_max_size, "%s", buf);
5643 char *tmp, buf[max_user_text];
5644 generate_text_internal(buf, max_user_text,
5647 if (strlen(buf) <= obj->data.scroll.show) {
5648 snprintf(p, p_max_size, "%s", buf);
5651 #define LINESEPARATOR '|'
5652 //place all the lines behind each other with LINESEPARATOR between them
5653 for(j = 0; buf[j] != 0; j++) {
5655 buf[j]=LINESEPARATOR;
5658 //scroll the output obj->data.scroll.start places by copying that many chars from
5659 //the front of the string to tmp, scrolling the rest to the front and placing tmp
5660 //at the back of the string
5661 tmp = calloc(obj->data.scroll.start + 1, sizeof(char));
5662 strncpy(tmp, buf, obj->data.scroll.start); tmp[obj->data.scroll.start] = 0;
5663 for(j = obj->data.scroll.start; buf[j] != 0; j++){
5664 buf[j - obj->data.scroll.start] = buf[j];
5666 strcpy(&buf[j - obj->data.scroll.start], tmp);
5668 //only show the requested number of chars
5669 if(obj->data.scroll.show < j) {
5670 buf[obj->data.scroll.show] = 0;
5672 //next time, scroll a place more or reset scrolling if we are at the end
5673 obj->data.scroll.start += obj->data.scroll.step;
5674 if(obj->data.scroll.start >= j){
5675 obj->data.scroll.start = 0;
5677 snprintf(p, p_max_size, "%s", buf);
5680 char buf[2][max_user_text];
5687 struct llrows* next;
5689 struct llrows *ll_rows[2], *current[2];
5690 struct text_object * objsub = obj->sub;
5693 for(i=0; i<2; i++) {
5696 ll_rows[i] = malloc(sizeof(struct llrows));
5697 current[i] = ll_rows[i];
5698 for(j=0; j<i; j++) objsub = objsub->sub;
5699 generate_text_internal(buf[i], max_user_text, *objsub, cur);
5700 for(j=0; buf[i][j] != 0; j++) {
5701 if(buf[i][j] == '\t') buf[i][j] = ' ';
5702 if(buf[i][j] == '\n') {
5704 current[i]->row = strdup(buf[i]+nextstart);
5705 if(i==0 && (long)strlen(current[i]->row) > longest) longest = (long)strlen(current[i]->row);
5706 current[i]->next = malloc(sizeof(struct llrows));
5707 current[i] = current[i]->next;
5712 current[i]->row = strdup(buf[i]+nextstart);
5713 if(i==0 && (long)strlen(current[i]->row) > longest) longest = (long)strlen(current[i]->row);
5714 current[i]->next = NULL;
5715 current[i] = ll_rows[i];
5717 for(j=0; j < (nr_rows[0] > nr_rows[1] ? nr_rows[0] : nr_rows[1] ); j++) {
5719 strcat(p, current[0]->row);
5720 i=strlen(current[0]->row);
5722 while(i < longest) {
5727 strcat(p, obj->data.combine.seperation);
5728 strcat(p, current[1]->row);
5732 #pragma omp parallel for
5733 #endif /* HAVE_OPENMP */
5734 for(i=0; i<2; i++) if(current[i]) current[i]=current[i]->next;
5737 #pragma omp parallel for
5738 #endif /* HAVE_OPENMP */
5739 for(i=0; i<2; i++) {
5740 while(ll_rows[i] != NULL) {
5741 current[i]=ll_rows[i];
5742 free(current[i]->row);
5743 ll_rows[i]=current[i]->next;
5750 int value = get_nvidia_value(obj->data.nvidia.type, display);
5752 snprintf(p, p_max_size, "N/A");
5753 else if (obj->data.nvidia.type == NV_TEMP)
5754 temp_print(p, p_max_size, (double)value, TEMP_CELSIUS);
5755 else if (obj->data.nvidia.print_as_float &&
5756 value > 0 && value < 100)
5757 snprintf(p, p_max_size, "%.1f", (float)value);
5759 snprintf(p, p_max_size, "%d", value);
5764 /* This is just a meta-object to set host:port */
5767 snprintf(p, p_max_size, "%s",
5768 cur->apcupsd.items[APCUPSD_NAME]);
5770 OBJ(apcupsd_model) {
5771 snprintf(p, p_max_size, "%s",
5772 cur->apcupsd.items[APCUPSD_MODEL]);
5774 OBJ(apcupsd_upsmode) {
5775 snprintf(p, p_max_size, "%s",
5776 cur->apcupsd.items[APCUPSD_UPSMODE]);
5778 OBJ(apcupsd_cable) {
5779 snprintf(p, p_max_size, "%s",
5780 cur->apcupsd.items[APCUPSD_CABLE]);
5782 OBJ(apcupsd_status) {
5783 snprintf(p, p_max_size, "%s",
5784 cur->apcupsd.items[APCUPSD_STATUS]);
5786 OBJ(apcupsd_linev) {
5787 snprintf(p, p_max_size, "%s",
5788 cur->apcupsd.items[APCUPSD_LINEV]);
5791 snprintf(p, p_max_size, "%s",
5792 cur->apcupsd.items[APCUPSD_LOAD]);
5794 OBJ(apcupsd_loadbar) {
5797 if(output_methods & TO_X) {
5798 progress = atof(cur->apcupsd.items[APCUPSD_LOAD]) / 100.0 * 255.0;
5799 new_bar(p, obj->a, obj->b, (int) progress);
5802 progress = atof(cur->apcupsd.items[APCUPSD_LOAD]);
5803 if(!obj->a) obj->a = DEFAULT_BAR_WIDTH_NO_X;
5804 new_bar_in_shell(p, p_max_size, (int) progress, obj->a);
5810 OBJ(apcupsd_loadgraph) {
5812 progress = atof(cur->apcupsd.items[APCUPSD_LOAD]);
5813 new_graph(p, obj->a, obj->b, obj->c, obj->d,
5814 (int)progress, 100, 1, obj->char_a, obj->char_b);
5816 OBJ(apcupsd_loadgauge) {
5818 progress = atof(cur->apcupsd.items[APCUPSD_LOAD]) / 100.0 * 255.0;
5819 new_gauge(p, obj->a, obj->b,
5823 OBJ(apcupsd_charge) {
5824 snprintf(p, p_max_size, "%s",
5825 cur->apcupsd.items[APCUPSD_CHARGE]);
5827 OBJ(apcupsd_timeleft) {
5828 snprintf(p, p_max_size, "%s",
5829 cur->apcupsd.items[APCUPSD_TIMELEFT]);
5832 snprintf(p, p_max_size, "%s",
5833 cur->apcupsd.items[APCUPSD_TEMP]);
5835 OBJ(apcupsd_lastxfer) {
5836 snprintf(p, p_max_size, "%s",
5837 cur->apcupsd.items[APCUPSD_LASTXFER]);
5839 #endif /* APCUPSD */
5846 unsigned int a = strlen(p);
5849 if (a > 0 && iconv_converting && iconv_selected > 0
5850 && (iconv_cd[iconv_selected - 1] != (iconv_t) (-1))) {
5852 size_t dummy1, dummy2;
5853 char *ptr = buff_in;
5856 dummy1 = dummy2 = a;
5858 strncpy(buff_in, p, p_max_size);
5860 iconv(*iconv_cd[iconv_selected - 1], NULL, NULL, NULL, NULL);
5861 while (dummy1 > 0) {
5862 bytes = iconv(*iconv_cd[iconv_selected - 1], &ptr, &dummy1,
5865 ERR("Iconv codeset conversion failed");
5870 /* It is nessecary when we are converting from multibyte to
5871 * singlebyte codepage */
5874 #endif /* HAVE_ICONV */
5881 /* load any new fonts we may have had */
5882 if (need_to_load_fonts) {
5888 double current_update_time, next_update_time, last_update_time;
5890 static void generate_text(void)
5892 struct information *cur = &info;
5899 current_update_time = get_time();
5903 /* add things to the buffer */
5909 generate_text_internal(p, max_user_text, global_root_object, cur);
5911 if (stuff_in_upper_case) {
5914 tmp_p = text_buffer;
5916 *tmp_p = toupper(*tmp_p);
5921 next_update_time += update_interval;
5922 if (next_update_time < get_time()) {
5923 next_update_time = get_time() + update_interval;
5924 } else if (next_update_time > get_time() + update_interval) {
5925 next_update_time = get_time() + update_interval;
5927 last_update_time = current_update_time;
5932 static inline int get_string_width(const char *s)
5935 if (output_methods & TO_X) {
5936 return *s ? calc_text_width(s, strlen(s)) : 0;
5942 static inline int get_string_width_special(char *s)
5950 if ((output_methods & TO_X) == 0) {
5952 return (s) ? strlen(s) : 0;
5960 p = strndup(s, text_buffer_size);
5964 if (*p == SPECIAL_CHAR) {
5965 /* shift everything over by 1 so that the special char
5966 * doesn't mess up the size calculation */
5967 for (i = 0; i < (long)strlen(p); i++) {
5968 *(p + i) = *(p + i + 1);
5970 if (specials[special_index + idx].type == GRAPH
5971 || specials[special_index + idx].type == GAUGE
5972 || specials[special_index + idx].type == BAR) {
5973 width += specials[special_index + idx].width;
5980 if (strlen(final) > 1) {
5981 width += calc_text_width(final, strlen(final));
5989 static void text_size_updater(char *s);
5991 int last_font_height;
5992 static void update_text_area(void)
5996 if ((output_methods & TO_X) == 0)
5998 /* update text size if it isn't fixed */
6003 text_width = minimum_width;
6006 last_font_height = font_height();
6007 for_each_line(text_buffer, text_size_updater);
6009 if (text_height < minimum_height) {
6010 text_height = minimum_height;
6012 if (text_width > maximum_width && maximum_width > 0) {
6013 text_width = maximum_width;
6017 /* get text position on workarea */
6018 switch (text_alignment) {
6025 x = workarea[2] - text_width - gap_x;
6030 x = workarea[2] / 2 - text_width / 2 - gap_x;
6037 y = workarea[3] - text_height - gap_y;
6041 x = workarea[2] - text_width - gap_x;
6042 y = workarea[3] - text_height - gap_y;
6046 x = workarea[2] / 2 - text_width / 2 - gap_x;
6047 y = workarea[3] - text_height - gap_y;
6052 y = workarea[3] / 2 - text_height / 2 - gap_y;
6056 x = workarea[2] - text_width - gap_x;
6057 y = workarea[3] / 2 - text_height / 2 - gap_y;
6061 case NONE: // Let the WM manage the window
6072 if (own_window && !fixed_pos) {
6075 text_start_x = border_inner_margin + border_outer_margin + border_width;
6076 text_start_y = border_inner_margin + border_outer_margin + border_width;
6077 window.x = x - border_inner_margin - border_outer_margin - border_width;
6078 window.y = y - border_inner_margin - border_outer_margin - border_width;
6082 /* If window size doesn't match to workarea's size,
6083 * then window probably includes panels (gnome).
6084 * Blah, doesn't work on KDE. */
6085 if (workarea[2] != window.width || workarea[3] != window.height) {
6097 static int cur_x, cur_y; /* current x and y for drawing */
6099 //draw_mode also without X11 because we only need to print to stdout with FG
6100 static int draw_mode; /* FG, BG or OUTLINE */
6102 static long current_color;
6104 static void text_size_updater(char *s)
6109 if ((output_methods & TO_X) == 0)
6111 /* get string widths and skip specials */
6114 if (*p == SPECIAL_CHAR) {
6116 w += get_string_width(s);
6119 if (specials[special_index].type == BAR
6120 || specials[special_index].type == GAUGE
6121 || specials[special_index].type == GRAPH) {
6122 w += specials[special_index].width;
6123 if (specials[special_index].height > last_font_height) {
6124 last_font_height = specials[special_index].height;
6125 last_font_height += font_height();
6127 } else if (specials[special_index].type == OFFSET) {
6128 if (specials[special_index].arg > 0) {
6129 w += specials[special_index].arg;
6131 } else if (specials[special_index].type == VOFFSET) {
6132 last_font_height += specials[special_index].arg;
6133 } else if (specials[special_index].type == GOTO) {
6134 if (specials[special_index].arg > cur_x) {
6135 w = (int) specials[special_index].arg;
6137 } else if (specials[special_index].type == TAB) {
6138 int start = specials[special_index].arg;
6139 int step = specials[special_index].width;
6141 if (!step || step < 0) {
6144 w += step - (cur_x - text_start_x - start) % step;
6145 } else if (specials[special_index].type == FONT) {
6146 selected_font = specials[special_index].font_added;
6147 if (font_height() > last_font_height) {
6148 last_font_height = font_height();
6157 w += get_string_width(s);
6158 if (w > text_width) {
6161 if (text_width > maximum_width && maximum_width) {
6162 text_width = maximum_width;
6165 text_height += last_font_height;
6166 last_font_height = font_height();
6169 static inline void set_foreground_color(long c)
6171 if ((output_methods & TO_X) == 0)
6174 XSetForeground(display, window.gc, c);
6178 static void draw_string(const char *s)
6180 int i, i2, pos, width_of_s;
6188 width_of_s = get_string_width(s);
6189 if ((output_methods & TO_STDOUT) && draw_mode == FG) {
6191 fflush(stdout); /* output immediately, don't buffer */
6193 if ((output_methods & TO_STDERR) && draw_mode == FG) {
6194 fprintf(stderr, "%s\n", s);
6195 fflush(stderr); /* output immediately, don't buffer */
6197 if ((output_methods & OVERWRITE_FILE) && draw_mode == FG && overwrite_fpointer) {
6198 fprintf(overwrite_fpointer, "%s\n", s);
6200 if ((output_methods & APPEND_FILE) && draw_mode == FG && append_fpointer) {
6201 fprintf(append_fpointer, "%s\n", s);
6203 memset(tmpstring1, 0, text_buffer_size);
6204 memset(tmpstring2, 0, text_buffer_size);
6205 strncpy(tmpstring1, s, text_buffer_size - 1);
6210 if (output_methods & TO_X) {
6211 max = ((text_width - width_of_s) / get_string_width(" "));
6214 /* This code looks for tabs in the text and coverts them to spaces.
6215 * The trick is getting the correct number of spaces, and not going
6216 * over the window's size without forcing the window larger. */
6217 for (i = 0; i < (int) text_buffer_size; i++) {
6218 if (tmpstring1[i] == '\t') {
6220 for (i2 = 0; i2 < (8 - (1 + pos) % 8) && added <= max; i2++) {
6221 /* guard against overrun */
6222 tmpstring2[MIN(pos + i2, (int)text_buffer_size - 1)] = ' ';
6227 /* guard against overrun */
6228 tmpstring2[MIN(pos, (int) text_buffer_size - 1)] = tmpstring1[i];
6233 if (output_methods & TO_X) {
6234 if (text_width == maximum_width) {
6235 /* this means the text is probably pushing the limit,
6236 * so we'll chop it */
6237 while (cur_x + get_string_width(tmpstring2) - text_start_x
6238 > maximum_width && strlen(tmpstring2) > 0) {
6239 tmpstring2[strlen(tmpstring2) - 1] = '\0';
6246 if (output_methods & TO_X) {
6252 c.pixel = current_color;
6253 XQueryColor(display, DefaultColormap(display, screen), &c);
6256 c2.color.red = c.red;
6257 c2.color.green = c.green;
6258 c2.color.blue = c.blue;
6259 c2.color.alpha = fonts[selected_font].font_alpha;
6261 XftDrawStringUtf8(window.xftdraw, &c2, fonts[selected_font].xftfont,
6262 cur_x, cur_y, (const XftChar8 *) s, strlen(s));
6264 XftDrawString8(window.xftdraw, &c2, fonts[selected_font].xftfont,
6265 cur_x, cur_y, (const XftChar8 *) s, strlen(s));
6270 XDrawString(display, window.drawable, window.gc, cur_x, cur_y, s,
6273 cur_x += width_of_s;
6276 memcpy(tmpstring1, s, text_buffer_size);
6279 static void draw_line(char *s)
6287 if ((output_methods & TO_X) == 0) {
6293 cur_x = text_start_x;
6294 cur_y += font_ascent();
6295 font_h = font_height();
6297 /* find specials and draw stuff */
6300 if (*p == SPECIAL_CHAR) {
6303 /* draw string before special */
6310 switch (specials[special_index].type) {
6311 case HORIZONTAL_LINE:
6313 int h = specials[special_index].height;
6314 int mid = font_ascent() / 2;
6316 w = text_start_x + text_width - cur_x;
6318 XSetLineAttributes(display, window.gc, h, LineSolid,
6319 CapButt, JoinMiter);
6320 XDrawLine(display, window.drawable, window.gc, cur_x,
6321 cur_y - mid / 2, cur_x + w, cur_y - mid / 2);
6327 int h = specials[special_index].height;
6328 int tmp_s = specials[special_index].arg;
6329 int mid = font_ascent() / 2;
6330 char ss[2] = { tmp_s, tmp_s };
6332 w = text_start_x + text_width - cur_x - 1;
6333 XSetLineAttributes(display, window.gc, h, LineOnOffDash,
6334 CapButt, JoinMiter);
6335 XSetDashes(display, window.gc, 0, ss, 2);
6336 XDrawLine(display, window.drawable, window.gc, cur_x,
6337 cur_y - mid / 2, cur_x + w, cur_y - mid / 2);
6343 int h, bar_usage, by;
6344 if (cur_x - text_start_x > maximum_width
6345 && maximum_width > 0) {
6348 h = specials[special_index].height;
6349 bar_usage = specials[special_index].arg;
6350 by = cur_y - (font_ascent() / 2) - 1;
6355 w = specials[special_index].width;
6357 w = text_start_x + text_width - cur_x - 1;
6363 XSetLineAttributes(display, window.gc, 1, LineSolid,
6364 CapButt, JoinMiter);
6366 XDrawRectangle(display, window.drawable, window.gc, cur_x,
6368 XFillRectangle(display, window.drawable, window.gc, cur_x,
6369 by, w * bar_usage / 255, h);
6377 case GAUGE: /* new GAUGE */
6380 unsigned long last_colour = current_color;
6381 float angle, px, py;
6384 if (cur_x - text_start_x > maximum_width
6385 && maximum_width > 0) {
6389 h = specials[special_index].height;
6390 by = cur_y - (font_ascent() / 2) - 1;
6395 w = specials[special_index].width;
6397 w = text_start_x + text_width - cur_x - 1;
6403 XSetLineAttributes(display, window.gc, 1, LineSolid,
6404 CapButt, JoinMiter);
6406 XDrawArc(display, window.drawable, window.gc,
6407 cur_x, by, w, h * 2, 0, 180*64);
6410 usage = specials[special_index].arg;
6411 angle = (M_PI)*(float)(usage)/255.;
6412 px = (float)(cur_x+(w/2.))-(float)(w/2.)*cos(angle);
6413 py = (float)(by+(h))-(float)(h)*sin(angle);
6415 XDrawLine(display, window.drawable, window.gc,
6416 cur_x + (w/2.), by+(h), (int)(px), (int)(py));
6424 set_foreground_color(last_colour);
6432 int h, by, i = 0, j = 0;
6434 unsigned long last_colour = current_color;
6435 unsigned long *tmpcolour = 0;
6436 if (cur_x - text_start_x > maximum_width
6437 && maximum_width > 0) {
6440 h = specials[special_index].height;
6441 by = cur_y - (font_ascent() / 2) - 1;
6446 w = specials[special_index].width;
6448 w = text_start_x + text_width - cur_x - 1;
6453 if (draw_graph_borders) {
6454 XSetLineAttributes(display, window.gc, 1, LineSolid,
6455 CapButt, JoinMiter);
6456 XDrawRectangle(display, window.drawable, window.gc,
6459 XSetLineAttributes(display, window.gc, 1, LineSolid,
6460 CapButt, JoinMiter);
6462 if (specials[special_index].last_colour != 0
6463 || specials[special_index].first_colour != 0) {
6464 tmpcolour = do_gradient(w - 1, specials[special_index].last_colour, specials[special_index].first_colour);
6467 for (i = w - 2; i > -1; i--) {
6468 if (specials[special_index].last_colour != 0
6469 || specials[special_index].first_colour != 0) {
6470 if (specials[special_index].tempgrad) {
6473 (int)((float)(w - 2) - specials[special_index].graph[j] *
6474 (w - 2) / (float)specials[special_index].graph_scale)
6478 (int)((float)(w - 2) - specials[special_index].graph[j] *
6479 (w - 2) / (float)specials[special_index].graph_scale)
6482 if (specials[special_index].graph[j] == specials[special_index].graph_scale) {
6484 (int)((float)(w - 2) - specials[special_index].graph[j] *
6485 (w - 2) / (float)specials[special_index].graph_scale)
6489 #endif /* DEBUG_lol */
6490 XSetForeground(display, window.gc, tmpcolour[
6491 (int)((float)(w - 2) - specials[special_index].graph[j] *
6492 (w - 2) / (float)specials[special_index].graph_scale)
6495 XSetForeground(display, window.gc, tmpcolour[colour_idx++]);
6498 /* this is mugfugly, but it works */
6499 XDrawLine(display, window.drawable, window.gc,
6500 cur_x + i + 1, by + h, cur_x + i + 1,
6501 round_to_int((double)by + h - specials[special_index].graph[j] *
6502 (h - 1) / specials[special_index].graph_scale));
6503 if ((w - i) / ((float) (w - 2) /
6504 (specials[special_index].graph_width)) > j
6505 && j < MAX_GRAPH_DEPTH - 3) {
6509 if (tmpcolour) free(tmpcolour);
6514 /* if (draw_mode == BG) {
6515 set_foreground_color(default_bg_color);
6516 } else if (draw_mode == OUTLINE) {
6517 set_foreground_color(default_out_color);
6519 set_foreground_color(default_fg_color);
6521 if (show_graph_range) {
6524 unsigned short int seconds = update_interval * w;
6529 unsigned short int timeunits;
6531 timeunits = seconds / 86400; seconds %= 86400;
6532 if (timeunits > 0) {
6533 asprintf(&tmp_day_str, "%dd", timeunits);
6535 tmp_day_str = strdup("");
6537 timeunits = seconds / 3600; seconds %= 3600;
6538 if (timeunits > 0) {
6539 asprintf(&tmp_hour_str, "%dh", timeunits);
6541 tmp_hour_str = strdup("");
6543 timeunits = seconds / 60; seconds %= 60;
6544 if (timeunits > 0) {
6545 asprintf(&tmp_min_str, "%dm", timeunits);
6547 tmp_min_str = strdup("");
6550 asprintf(&tmp_sec_str, "%ds", seconds);
6552 tmp_sec_str = strdup("");
6554 asprintf(&tmp_str, "%s%s%s%s", tmp_day_str, tmp_hour_str, tmp_min_str, tmp_sec_str);
6555 free(tmp_day_str); free(tmp_hour_str); free(tmp_min_str); free(tmp_sec_str);
6557 asprintf(&tmp_str, "Range not possible"); // should never happen, but better safe then sorry
6559 cur_x += (w / 2) - (font_ascent() * (strlen(tmp_str) / 2));
6560 cur_y += font_h / 2;
6561 draw_string(tmp_str);
6567 if (show_graph_scale && (specials[special_index].show_scale == 1)) {
6570 cur_x += font_ascent() / 2;
6571 cur_y += font_h / 2;
6573 calloc(log10(floor(specials[special_index].graph_scale)) + 4,
6575 sprintf(tmp_str, "%.1f", specials[special_index].graph_scale);
6576 draw_string(tmp_str);
6582 set_foreground_color(last_colour);
6588 int old = font_ascent();
6590 cur_y -= font_ascent();
6591 selected_font = specials[special_index].font_added;
6593 if (cur_y + font_ascent() < cur_y + old) {
6596 cur_y += font_ascent();
6598 font_h = font_height();
6602 if (draw_mode == FG) {
6603 set_foreground_color(specials[special_index].arg);
6608 if (draw_mode == BG) {
6609 set_foreground_color(specials[special_index].arg);
6614 if (draw_mode == OUTLINE) {
6615 set_foreground_color(specials[special_index].arg);
6620 w += specials[special_index].arg;
6624 cur_y += specials[special_index].arg;
6628 if (specials[special_index].arg >= 0) {
6629 cur_x = (int) specials[special_index].arg;
6635 int start = specials[special_index].arg;
6636 int step = specials[special_index].width;
6638 if (!step || step < 0) {
6641 w = step - (cur_x - text_start_x - start) % step;
6647 /* TODO: add back in "+ border_inner_margin" to the end of
6649 int pos_x = text_start_x + text_width -
6650 get_string_width_special(s);
6652 /* printf("pos_x %i text_start_x %i text_width %i cur_x %i "
6653 "get_string_width(p) %i gap_x %i "
6654 "specials[special_index].arg %i border_inner_margin %i "
6655 "border_width %i\n", pos_x, text_start_x, text_width,
6656 cur_x, get_string_width_special(s), gap_x,
6657 specials[special_index].arg, border_inner_margin,
6659 if (pos_x > specials[special_index].arg && pos_x > cur_x) {
6660 cur_x = pos_x - specials[special_index].arg;
6667 int pos_x = (text_width) / 2 - get_string_width_special(s) /
6668 2 - (cur_x - text_start_x);
6669 /* int pos_x = text_start_x + text_width / 2 -
6670 get_string_width_special(s) / 2; */
6672 /* printf("pos_x %i text_start_x %i text_width %i cur_x %i "
6673 "get_string_width(p) %i gap_x %i "
6674 "specials[special_index].arg %i\n", pos_x, text_start_x,
6675 text_width, cur_x, get_string_width(s), gap_x,
6676 specials[special_index].arg); */
6677 if (pos_x > specials[special_index].arg) {
6678 w = pos_x - specials[special_index].arg;
6692 if (cur_y_add > 0) {
6696 cur_y += font_descent();
6701 static void draw_text(void)
6704 if (output_methods & TO_X) {
6705 cur_y = text_start_y;
6708 if (draw_borders && border_width > 0) {
6709 if (stippled_borders) {
6710 char ss[2] = { stippled_borders, stippled_borders };
6711 XSetLineAttributes(display, window.gc, border_width, LineOnOffDash,
6712 CapButt, JoinMiter);
6713 XSetDashes(display, window.gc, 0, ss, 2);
6715 XSetLineAttributes(display, window.gc, border_width, LineSolid,
6716 CapButt, JoinMiter);
6719 XDrawRectangle(display, window.drawable, window.gc,
6720 text_start_x - border_inner_margin - border_width,
6721 text_start_y - border_inner_margin - border_width,
6722 text_width + border_inner_margin * 2 + border_width * 2,
6723 text_height + border_inner_margin * 2 + border_width * 2);
6731 for_each_line(text_buffer, draw_line);
6734 static void draw_stuff(void)
6736 if (overwrite_file) {
6737 overwrite_fpointer = fopen(overwrite_file, "w");
6738 if(!overwrite_fpointer)
6739 ERR("Can't overwrite '%s' anymore", overwrite_file);
6742 append_fpointer = fopen(append_file, "a");
6743 if(!append_fpointer)
6744 ERR("Can't append '%s' anymore", append_file);
6747 if (output_methods & TO_X) {
6749 if (draw_shades && !draw_outline) {
6752 set_foreground_color(default_bg_color);
6763 for (i = -1; i < 2; i++) {
6764 for (j = -1; j < 2; j++) {
6765 if (i == 0 && j == 0) {
6770 set_foreground_color(default_out_color);
6771 draw_mode = OUTLINE;
6779 set_foreground_color(default_fg_color);
6785 if (output_methods & TO_X) {
6790 swap.swap_window = window.window;
6791 swap.swap_action = XdbeBackground;
6792 XdbeSwapBuffers(display, &swap, 1);
6797 if(overwrite_fpointer) {
6798 fclose(overwrite_fpointer);
6799 overwrite_fpointer = 0;
6801 if(append_fpointer) {
6802 fclose(append_fpointer);
6803 append_fpointer = 0;
6808 static void clear_text(int exposures)
6812 /* The swap action is XdbeBackground, which clears */
6816 if (display && window.window) { // make sure these are !null
6817 /* there is some extra space for borders and outlines */
6818 XClearArea(display, window.window, text_start_x - border_inner_margin - border_outer_margin - border_width,
6819 text_start_y - border_inner_margin - border_outer_margin - border_width,
6820 text_width + border_inner_margin * 2 + border_outer_margin * 2 + border_width * 2,
6821 text_height + border_inner_margin * 2 + border_outer_margin * 2 + border_width * 2, exposures ? True : 0);
6826 static int need_to_update;
6828 /* update_text() generates new text and clears old text area */
6829 static void update_text(void)
6836 if (output_methods & TO_X)
6842 #ifdef HAVE_SYS_INOTIFY_H
6846 static void main_loop(void)
6849 #ifdef SIGNAL_BLOCKING
6850 sigset_t newmask, oldmask;
6853 #ifdef HAVE_SYS_INOTIFY_H
6854 int inotify_config_wd = -1;
6855 #define INOTIFY_EVENT_SIZE (sizeof(struct inotify_event))
6856 #define INOTIFY_BUF_LEN (20 * (INOTIFY_EVENT_SIZE + 16))
6857 char inotify_buff[INOTIFY_BUF_LEN];
6858 #endif /* HAVE_SYS_INOTIFY_H */
6861 #ifdef SIGNAL_BLOCKING
6862 sigemptyset(&newmask);
6863 sigaddset(&newmask, SIGINT);
6864 sigaddset(&newmask, SIGTERM);
6865 sigaddset(&newmask, SIGUSR1);
6868 last_update_time = 0.0;
6869 next_update_time = get_time();
6871 while (terminate == 0 && (total_run_times == 0 || info.looped < total_run_times)) {
6874 #ifdef SIGNAL_BLOCKING
6875 /* block signals. we will inspect for pending signals later */
6876 if (sigprocmask(SIG_BLOCK, &newmask, &oldmask) < 0) {
6877 CRIT_ERR("unable to sigprocmask()");
6882 if (output_methods & TO_X) {
6885 /* wait for X event or timeout */
6887 if (!XPending(display)) {
6891 t = next_update_time - get_time();
6895 } else if (t > update_interval) {
6896 t = update_interval;
6899 tv.tv_sec = (long) t;
6900 tv.tv_usec = (long) (t * 1000000) % 1000000;
6902 FD_SET(ConnectionNumber(display), &fdsr);
6904 s = select(ConnectionNumber(display) + 1, &fdsr, 0, 0, &tv);
6906 if (errno != EINTR) {
6907 ERR("can't select(): %s", strerror(errno));
6917 if (need_to_update) {
6919 int wx = window.x, wy = window.y;
6927 /* resize window if it isn't right size */
6929 && (text_width + border_inner_margin * 2 + border_outer_margin * 2 + border_width * 2 != window.width
6930 || text_height + border_inner_margin * 2 + border_outer_margin * 2 + border_width * 2 != window.height)) {
6931 window.width = text_width + border_inner_margin * 2 + border_outer_margin * 2 + border_width * 2;
6932 window.height = text_height + border_inner_margin * 2 + border_outer_margin * 2 + border_width * 2;
6933 XResizeWindow(display, window.window, window.width,
6936 set_transparent_background(window.window);
6940 /* move window if it isn't in right position */
6941 if (!fixed_pos && (window.x != wx || window.y != wy)) {
6942 XMoveWindow(display, window.window, window.x, window.y);
6953 r.x = text_start_x - border_inner_margin - border_outer_margin - border_width;
6954 r.y = text_start_y - border_inner_margin - border_outer_margin - border_width;
6955 r.width = text_width + border_inner_margin * 2 + border_outer_margin * 2 + border_width * 2;
6956 r.height = text_height + border_inner_margin * 2 + border_outer_margin * 2 + border_width * 2;
6957 XUnionRectWithRegion(&r, x11_stuff.region, x11_stuff.region);
6962 /* handle X events */
6963 while (XPending(display)) {
6966 XNextEvent(display, &ev);
6973 r.width = ev.xexpose.width;
6974 r.height = ev.xexpose.height;
6975 XUnionRectWithRegion(&r, x11_stuff.region, x11_stuff.region);
6980 case ReparentNotify:
6981 /* set background to ParentRelative for all parents */
6983 set_transparent_background(window.window);
6987 case ConfigureNotify:
6989 /* if window size isn't what expected, set fixed size */
6990 if (ev.xconfigure.width != window.width
6991 || ev.xconfigure.height != window.height) {
6992 if (window.width != 0 && window.height != 0) {
6996 /* clear old stuff before screwing up
7001 XWindowAttributes attrs;
7002 if (XGetWindowAttributes(display,
7003 window.window, &attrs)) {
7004 window.width = attrs.width;
7005 window.height = attrs.height;
7009 text_width = window.width - border_inner_margin * 2 - border_outer_margin * 2 - border_width * 2;
7010 text_height = window.height - border_inner_margin * 2 - border_outer_margin * 2 - border_width * 2;
7011 if (text_width > maximum_width
7012 && maximum_width > 0) {
7013 text_width = maximum_width;
7017 /* if position isn't what expected, set fixed pos
7018 * total_updates avoids setting fixed_pos when window
7019 * is set to weird locations when started */
7020 /* // this is broken
7021 if (total_updates >= 2 && !fixed_pos
7022 && (window.x != ev.xconfigure.x
7023 || window.y != ev.xconfigure.y)
7024 && (ev.xconfigure.x != 0
7025 || ev.xconfigure.y != 0)) {
7033 /* if an ordinary window with decorations */
7034 if ((window.type == TYPE_NORMAL)
7035 && (!TEST_HINT(window.hints,
7036 HINT_UNDECORATED))) {
7037 /* allow conky to hold input focus. */
7040 /* forward the click to the desktop window */
7041 XUngrabPointer(display, ev.xbutton.time);
7042 ev.xbutton.window = window.desktop;
7043 ev.xbutton.x = ev.xbutton.x_root;
7044 ev.xbutton.y = ev.xbutton.y_root;
7045 XSendEvent(display, ev.xbutton.window, False,
7046 ButtonPressMask, &ev);
7047 XSetInputFocus(display, ev.xbutton.window,
7048 RevertToParent, ev.xbutton.time);
7055 /* if an ordinary window with decorations */
7056 if ((window.type == TYPE_NORMAL)
7057 && (!TEST_HINT(window.hints,
7058 HINT_UNDECORATED))) {
7059 /* allow conky to hold input focus. */
7062 /* forward the release to the desktop window */
7063 ev.xbutton.window = window.desktop;
7064 ev.xbutton.x = ev.xbutton.x_root;
7065 ev.xbutton.y = ev.xbutton.y_root;
7066 XSendEvent(display, ev.xbutton.window, False,
7067 ButtonReleaseMask, &ev);
7076 if (ev.type == x11_stuff.event_base + XDamageNotify) {
7077 XDamageNotifyEvent *dev = (XDamageNotifyEvent *) &ev;
7079 XFixesSetRegion(display, x11_stuff.part, &dev->area, 1);
7080 XFixesUnionRegion(display, x11_stuff.region2, x11_stuff.region2, x11_stuff.part);
7082 #endif /* HAVE_XDAMAGE */
7088 XDamageSubtract(display, x11_stuff.damage, x11_stuff.region2, None);
7089 XFixesSetRegion(display, x11_stuff.region2, 0, 0);
7090 #endif /* HAVE_XDAMAGE */
7092 /* XDBE doesn't seem to provide a way to clear the back buffer without
7093 * interfering with the front buffer, other than passing XdbeBackground
7094 * to XdbeSwapBuffers. That means that if we're using XDBE, we need to
7095 * redraw the text even if it wasn't part of the exposed area. OTOH,
7096 * if we're not going to call draw_stuff at all, then no swap happens
7097 * and we can safely do nothing. */
7099 if (!XEmptyRegion(x11_stuff.region)) {
7104 r.x = text_start_x - border_inner_margin - border_outer_margin - border_width;
7105 r.y = text_start_y - border_inner_margin - border_outer_margin - border_width;
7106 r.width = text_width + border_inner_margin * 2 + border_outer_margin * 2 + border_width * 2;
7107 r.height = text_height + border_inner_margin * 2 + border_outer_margin * 2 + border_width * 2;
7108 XUnionRectWithRegion(&r, x11_stuff.region, x11_stuff.region);
7111 XSetRegion(display, window.gc, x11_stuff.region);
7114 XftDrawSetClip(window.xftdraw, x11_stuff.region);
7118 cimlib_render(text_start_x, text_start_y, window.width, window.height);
7121 XDestroyRegion(x11_stuff.region);
7122 x11_stuff.region = XCreateRegion();
7126 t = (next_update_time - get_time()) * 1000000;
7127 if(t > 0) usleep((useconds_t)t);
7134 #ifdef SIGNAL_BLOCKING
7135 /* unblock signals of interest and let handler fly */
7136 if (sigprocmask(SIG_SETMASK, &oldmask, NULL) < 0) {
7137 CRIT_ERR("unable to sigprocmask()");
7141 switch (g_signal_pending) {
7144 ERR("received SIGHUP or SIGUSR1. reloading the config file.");
7149 ERR("received SIGINT or SIGTERM to terminate. bye!");
7153 if (output_methods & TO_X) {
7154 XDestroyRegion(x11_stuff.region);
7155 x11_stuff.region = NULL;
7157 XDamageDestroy(display, x11_stuff.damage);
7158 XFixesDestroyRegion(display, x11_stuff.region2);
7159 XFixesDestroyRegion(display, x11_stuff.part);
7160 #endif /* HAVE_XDAMAGE */
7166 if(overwrite_file) {
7167 free(overwrite_file);
7176 /* Reaching here means someone set a signal
7177 * (SIGXXXX, signal_handler), but didn't write any code
7179 * If you don't want to handle a signal, don't set a handler on
7180 * it in the first place. */
7181 if (g_signal_pending) {
7182 ERR("ignoring signal (%d)", g_signal_pending);
7186 #ifdef HAVE_SYS_INOTIFY_H
7187 if (inotify_fd != -1 && inotify_config_wd != -1) {
7188 inotify_config_wd = inotify_add_watch(inotify_fd,
7192 if (inotify_fd != -1 && inotify_config_wd != -1) {
7193 int len = 0, idx = 0;
7195 struct timeval time_to_wait;
7197 FD_ZERO(&descriptors);
7198 FD_SET(inotify_fd, &descriptors);
7200 time_to_wait.tv_sec = time_to_wait.tv_usec = 0;
7202 select(inotify_fd + 1, &descriptors, NULL, NULL, &time_to_wait);
7203 if (FD_ISSET(inotify_fd, &descriptors)) {
7204 /* process inotify events */
7205 len = read(inotify_fd, inotify_buff, INOTIFY_BUF_LEN);
7206 while (len > 0 && idx < len) {
7207 struct inotify_event *ev = (struct inotify_event *) &inotify_buff[idx];
7208 if (ev->wd == inotify_config_wd && (ev->mask & IN_MODIFY || ev->mask & IN_IGNORED)) {
7209 /* current_config should be reloaded */
7210 ERR("'%s' modified, reloading...", current_config);
7212 if (ev->mask & IN_IGNORED) {
7213 /* for some reason we get IN_IGNORED here
7214 * sometimes, so we need to re-add the watch */
7215 inotify_config_wd = inotify_add_watch(inotify_fd,
7222 llua_inotify_query(ev->wd, ev->mask);
7224 #endif /* HAVE_LUA */
7225 idx += INOTIFY_EVENT_SIZE + ev->len;
7229 #endif /* HAVE_SYS_INOTIFY_H */
7231 g_signal_pending = 0;
7234 #ifdef HAVE_SYS_INOTIFY_H
7235 if (inotify_fd != -1) {
7236 inotify_rm_watch(inotify_fd, inotify_config_wd);
7238 inotify_fd = inotify_config_wd = 0;
7240 #endif /* HAVE_SYS_INOTIFY_H */
7243 X11_destroy_window();
7247 static void load_config_file(const char *);
7248 static void load_config_file_x11(const char *);
7250 /* reload the config file */
7251 static void reload_config(void)
7253 timed_thread_destroy_registered_threads();
7255 if (info.cpu_usage) {
7256 free(info.cpu_usage);
7257 info.cpu_usage = NULL;
7268 #ifdef TCP_PORT_MONITOR
7269 tcp_portmon_clear();
7274 #endif /* HAVE_LUA */
7277 X11_destroy_window();
7280 if (current_config) {
7282 load_config_file(current_config);
7283 load_config_file_x11(current_config);
7285 /* re-init specials array */
7286 if ((specials = realloc((void *) specials,
7287 sizeof(struct special_t) * max_specials)) == 0) {
7288 ERR("failed to realloc specials array");
7292 if (output_methods & TO_X) {
7293 X11_initialisation();
7296 extract_variable_text(global_text);
7302 tmpstring1 = malloc(text_buffer_size);
7303 memset(tmpstring1, 0, text_buffer_size);
7307 tmpstring2 = malloc(text_buffer_size);
7308 memset(tmpstring2, 0, text_buffer_size);
7312 text_buffer = malloc(max_user_text);
7313 memset(text_buffer, 0, max_user_text);
7315 X11_create_window();
7321 static void clean_up(void)
7324 timed_thread_destroy_registered_threads();
7326 if (info.cpu_usage) {
7327 free(info.cpu_usage);
7328 info.cpu_usage = NULL;
7331 if (output_methods & TO_X) {
7334 XdbeDeallocateBackBufferName(display, window.back_buffer);
7339 XDestroyWindow(display, window.window);
7340 XClearWindow(display, RootWindow(display, screen));
7345 XClearWindow(display, RootWindow(display, screen));
7350 XFreeGC(display, window.gc);
7356 for (i = 0; i < MAX_TEMPLATES; i++) {
7363 free_text_objects(&global_root_object, 0);
7382 free(current_config);
7384 #ifdef TCP_PORT_MONITOR
7385 tcp_portmon_clear();
7392 #endif /* HAVE_LUA */
7395 for (i = 0; i < special_count; i++) {
7396 if (specials[i].type == GRAPH) {
7397 free(specials[i].graph);
7404 clear_diskio_stats();
7407 static int string_to_bool(const char *s)
7410 // Assumes an option without a true/false means true
7412 } else if (strcasecmp(s, "yes") == EQUAL) {
7414 } else if (strcasecmp(s, "true") == EQUAL) {
7416 } else if (strcasecmp(s, "1") == EQUAL) {
7423 static enum alignment string_to_alignment(const char *s)
7425 if (strcasecmp(s, "top_left") == EQUAL) {
7427 } else if (strcasecmp(s, "top_right") == EQUAL) {
7429 } else if (strcasecmp(s, "top_middle") == EQUAL) {
7431 } else if (strcasecmp(s, "bottom_left") == EQUAL) {
7433 } else if (strcasecmp(s, "bottom_right") == EQUAL) {
7434 return BOTTOM_RIGHT;
7435 } else if (strcasecmp(s, "bottom_middle") == EQUAL) {
7436 return BOTTOM_MIDDLE;
7437 } else if (strcasecmp(s, "middle_left") == EQUAL) {
7439 } else if (strcasecmp(s, "middle_right") == EQUAL) {
7440 return MIDDLE_RIGHT;
7441 } else if (strcasecmp(s, "tl") == EQUAL) {
7443 } else if (strcasecmp(s, "tr") == EQUAL) {
7445 } else if (strcasecmp(s, "tm") == EQUAL) {
7447 } else if (strcasecmp(s, "bl") == EQUAL) {
7449 } else if (strcasecmp(s, "br") == EQUAL) {
7450 return BOTTOM_RIGHT;
7451 } else if (strcasecmp(s, "bm") == EQUAL) {
7452 return BOTTOM_MIDDLE;
7453 } else if (strcasecmp(s, "ml") == EQUAL) {
7455 } else if (strcasecmp(s, "mr") == EQUAL) {
7456 return MIDDLE_RIGHT;
7457 } else if (strcasecmp(s, "none") == EQUAL) {
7465 static void set_default_configurations_for_x(void)
7467 default_fg_color = WhitePixel(display, screen);
7468 default_bg_color = BlackPixel(display, screen);
7469 default_out_color = BlackPixel(display, screen);
7470 color0 = default_fg_color;
7471 color1 = default_fg_color;
7472 color2 = default_fg_color;
7473 color3 = default_fg_color;
7474 color4 = default_fg_color;
7475 color5 = default_fg_color;
7476 color6 = default_fg_color;
7477 color7 = default_fg_color;
7478 color8 = default_fg_color;
7479 color9 = default_fg_color;
7483 static void set_default_configurations(void)
7487 fork_to_background = 0;
7488 total_run_times = 0;
7489 info.cpu_avg_samples = 2;
7490 info.net_avg_samples = 2;
7491 info.diskio_avg_samples = 2;
7496 format_human_readable = 1;
7503 mpd_set_host("localhost");
7504 mpd_set_port("6600");
7507 info.xmms2.artist = NULL;
7508 info.xmms2.album = NULL;
7509 info.xmms2.title = NULL;
7510 info.xmms2.genre = NULL;
7511 info.xmms2.comment = NULL;
7512 info.xmms2.url = NULL;
7513 info.xmms2.status = NULL;
7514 info.xmms2.playlist = NULL;
7516 use_spacer = NO_SPACER;
7518 output_methods = TO_X;
7520 output_methods = TO_STDOUT;
7523 show_graph_scale = 0;
7524 show_graph_range = 0;
7527 draw_graph_borders = 1;
7529 set_first_font("6x10");
7537 window.type = TYPE_NORMAL;
7539 strcpy(window.class_name, PACKAGE_NAME);
7540 sprintf(window.title, PACKAGE_NAME" (%s)", info.uname_s.nodename);
7542 stippled_borders = 0;
7543 border_inner_margin = 3;
7544 border_outer_margin = 1;
7546 text_alignment = BOTTOM_LEFT;
7547 info.x11.monitor.number = 1;
7548 info.x11.monitor.current = 0;
7551 for (i = 0; i < MAX_TEMPLATES; i++) {
7552 template[i] = strdup("");
7555 free(current_mail_spool);
7559 variable_substitute(MAIL_FILE, buf, 256);
7560 if (buf[0] != '\0') {
7561 current_mail_spool = strndup(buf, text_buffer_size);
7566 update_interval = 3.0;
7567 info.music_player_interval = 1.0;
7568 stuff_in_upper_case = 0;
7569 info.users.number = 1;
7571 #ifdef TCP_PORT_MONITOR
7572 /* set default connection limit */
7573 tcp_portmon_set_max_connections(0);
7577 /* returns 1 if you can overwrite or create the file at 'path' */
7578 static _Bool overwrite_works(const char *path)
7582 if (!(filepointer = fopen(path, "w")))
7584 fclose(filepointer);
7588 /* returns 1 if you can append or create the file at 'path' */
7589 static _Bool append_works(const char *path)
7593 if (!(filepointer = fopen(path, "a")))
7595 fclose(filepointer);
7601 /* WARNING, this type not in Xlib spec */
7602 int x11_error_handler(Display *d, XErrorEvent *err)
7603 __attribute__((noreturn));
7604 int x11_error_handler(Display *d, XErrorEvent *err)
7606 ERR("X Error: type %i Display %lx XID %li serial %lu error_code %i request_code %i minor_code %i other Display: %lx\n",
7608 (long unsigned)err->display,
7609 (long)err->resourceid,
7619 int x11_ioerror_handler(Display *d)
7620 __attribute__((noreturn));
7621 int x11_ioerror_handler(Display *d)
7623 ERR("X Error: Display %lx\n",
7630 static void X11_initialisation(void)
7632 if (x_initialised == YES) return;
7633 output_methods |= TO_X;
7635 set_default_configurations_for_x();
7636 x_initialised = YES;
7639 /* WARNING, this type not in Xlib spec */
7640 XSetErrorHandler(&x11_error_handler);
7641 XSetIOErrorHandler(&x11_ioerror_handler);
7645 static void X11_destroy_window(void)
7647 /* this function only exists for the sake of consistency */
7648 if (output_methods & TO_X) {
7650 XDamageDestroy(display, x11_stuff.damage);
7651 XFixesDestroyRegion(display, x11_stuff.region2);
7652 XFixesDestroyRegion(display, x11_stuff.part);
7653 if (x11_stuff.region) {
7654 XDestroyRegion(x11_stuff.region);
7656 x11_stuff.region = NULL;
7657 #endif /* HAVE_XDAMAGE */
7663 static char **xargv = 0;
7664 static int xargc = 0;
7666 static void X11_create_window(void)
7668 if (output_methods & TO_X) {
7670 init_window(own_window, text_width + border_inner_margin * 2 + border_outer_margin * 2 + border_width * 2,
7671 text_height + border_inner_margin * 2 + border_outer_margin * 2 + border_width * 2, set_transparent, background_colour,
7673 #else /* OWN_WINDOW */
7674 init_window(0, text_width + border_inner_margin * 2 + border_outer_margin * 2 + border_width * 2,
7675 text_height + border_inner_margin * 2 + border_outer_margin * 2 + border_width * 2, set_transparent, 0,
7677 #endif /* OWN_WINDOW */
7681 update_text_area(); /* to position text/window on screen */
7684 if (own_window && !fixed_pos) {
7685 XMoveWindow(display, window.window, window.x, window.y);
7688 set_transparent_background(window.window);
7696 x11_stuff.region = XCreateRegion();
7698 if (!XDamageQueryExtension(display, &x11_stuff.event_base, &x11_stuff.error_base)) {
7699 ERR("Xdamage extension unavailable");
7701 x11_stuff.damage = XDamageCreate(display, window.window, XDamageReportNonEmpty);
7702 x11_stuff.region2 = XFixesCreateRegionFromWindow(display, window.window, 0);
7703 x11_stuff.part = XFixesCreateRegionFromWindow(display, window.window, 0);
7704 #endif /* HAVE_XDAMAGE */
7707 update_text_area(); /* to get initial size of the window */
7712 #define CONF_ERR ERR("%s: %d: config file error", f, line)
7713 #define CONF_ERR2(a) ERR("%s: %d: config file error: %s", f, line, a)
7714 #define CONF2(a) if (strcasecmp(name, a) == 0)
7715 #define CONF(a) else CONF2(a)
7716 #define CONF3(a, b) else if (strcasecmp(name, a) == 0 \
7717 || strcasecmp(name, b) == 0)
7718 #define CONF_CONTINUE 1
7719 #define CONF_BREAK 2
7720 #define CONF_BUFF_SIZE 512
7722 static FILE *open_config_file(const char *f)
7724 #ifdef CONFIG_OUTPUT
7725 if (!strcmp(f, "==builtin==")) {
7726 #ifdef HAVE_FOPENCOOKIE
7727 return fopencookie(NULL, "r", conf_cookie);
7728 #endif /* HAVE_FOPENCOOKIE */
7730 #endif /* CONFIG_OUTPUT */
7731 return fopen(f, "r");
7734 static int do_config_step(int *line, FILE *fp, char *buf, char **name, char **value)
7738 if (fgets(buf, CONF_BUFF_SIZE, fp) == NULL) {
7741 remove_comments(buf);
7746 while (*p && isspace((int) *p)) {
7750 return CONF_CONTINUE; /* empty line */
7757 while (*p2 && !isspace((int) *p2)) {
7761 *p2 = '\0'; /* break at name's end */
7768 while (*p && isspace((int) *p)) {
7774 p2 = *value + strlen(*value);
7775 while (isspace((int) *(p2 - 1))) {
7784 static void load_config_file(const char *f)
7789 set_default_configurations();
7790 fp = open_config_file(f);
7794 DBGP("reading contents from config file '%s'", f);
7797 char buff[CONF_BUFF_SIZE], *name, *value;
7798 int ret = do_config_step(&line, fp, buff, &name, &value);
7799 if (ret == CONF_BREAK) {
7801 } else if (ret == CONF_CONTINUE) {
7807 /* don't listen if X is already initialised or
7808 * if we already know we don't want it */
7809 if(x_initialised == NO) {
7810 if (string_to_bool(value)) {
7811 output_methods &= TO_X;
7813 output_methods &= ~TO_X;
7814 x_initialised = NEVER;
7819 if (!value || x_initialised == YES) {
7824 disp = strdup(value);
7828 if (window.type == TYPE_DOCK)
7831 int a = string_to_alignment(value);
7842 CONF("background") {
7843 fork_to_background = string_to_bool(value);
7846 CONF2("background") {
7847 fork_to_background = string_to_bool(value);
7851 CONF("show_graph_scale") {
7852 show_graph_scale = string_to_bool(value);
7854 CONF("show_graph_range") {
7855 show_graph_range = string_to_bool(value);
7857 CONF("border_margin") {
7858 ERR("border_margin is deprecated, please use border_inner_margin instead");
7860 CONF("border_inner_margin") {
7862 border_inner_margin = strtol(value, 0, 0);
7863 if (border_inner_margin < 0) border_inner_margin = 0;
7868 CONF("border_outer_margin") {
7870 border_outer_margin = strtol(value, 0, 0);
7871 if (border_outer_margin < 0) border_outer_margin = 0;
7876 CONF("border_width") {
7878 border_width = strtol(value, 0, 0);
7879 if (border_width < 0) border_width = 0;
7885 #define TEMPLATE_CONF(n) \
7886 CONF("template"#n) { \
7888 free(template[n]); \
7889 template[n] = strdup(value); \
7906 info.mail = parse_mail_args(IMAP_TYPE, value);
7913 info.mail = parse_mail_args(POP3_TYPE, value);
7918 CONF("default_bar_size") {
7921 if (sscanf(value, "%d %d", &default_bar_width, &default_bar_height) != 2) {
7928 CONF_ERR2("default_bar_size takes 2 integer arguments (ie. 'default_bar_size 0 6')")
7932 CONF("default_graph_size") {
7935 if (sscanf(value, "%d %d", &default_graph_width, &default_graph_height) != 2) {
7942 CONF_ERR2("default_graph_size takes 2 integer arguments (ie. 'default_graph_size 0 6')")
7945 CONF("default_gauge_size") {
7948 if (sscanf(value, "%d %d", &default_gauge_width, &default_gauge_height) != 2) {
7955 CONF_ERR2("default_gauge_size takes 2 integer arguments (ie. 'default_gauge_size 0 6')")
7962 mpd_set_host(value);
7968 if (value && mpd_set_port(value)) {
7972 CONF("mpd_password") {
7974 mpd_set_password(value);
7980 CONF("music_player_interval") {
7982 info.music_player_interval = strtod(value, 0);
7988 CONF("sensor_device") {
7990 sensor_device = strtol(value, 0, 0);
7996 CONF("cpu_avg_samples") {
7998 cpu_avg_samples = strtol(value, 0, 0);
7999 if (cpu_avg_samples < 1 || cpu_avg_samples > 14) {
8002 info.cpu_avg_samples = cpu_avg_samples;
8008 CONF("net_avg_samples") {
8010 net_avg_samples = strtol(value, 0, 0);
8011 if (net_avg_samples < 1 || net_avg_samples > 14) {
8014 info.net_avg_samples = net_avg_samples;
8020 CONF("diskio_avg_samples") {
8022 diskio_avg_samples = strtol(value, 0, 0);
8023 if (diskio_avg_samples < 1 || diskio_avg_samples > 14) {
8026 info.diskio_avg_samples = diskio_avg_samples;
8034 CONF("double_buffer") {
8035 use_xdbe = string_to_bool(value);
8039 CONF("override_utf8_locale") {
8040 utf8_mode = string_to_bool(value);
8042 CONF("draw_borders") {
8043 draw_borders = string_to_bool(value);
8045 CONF("draw_graph_borders") {
8046 draw_graph_borders = string_to_bool(value);
8048 CONF("draw_shades") {
8049 draw_shades = string_to_bool(value);
8051 CONF("draw_outline") {
8052 draw_outline = string_to_bool(value);
8055 CONF("out_to_console") {
8056 if(string_to_bool(value))
8057 output_methods |= TO_STDOUT;
8059 CONF("out_to_stderr") {
8060 if(string_to_bool(value))
8061 output_methods |= TO_STDERR;
8063 CONF("overwrite_file") {
8064 if(overwrite_file) {
8065 free(overwrite_file);
8068 if(overwrite_works(value)) {
8069 overwrite_file = strdup(value);
8070 output_methods |= OVERWRITE_FILE;
8072 ERR("overwrite_file won't be able to create/overwrite '%s'", value);
8074 CONF("append_file") {
8079 if(append_works(value)) {
8080 append_file = strdup(value);
8081 output_methods |= APPEND_FILE;
8083 ERR("append_file won't be able to create/append '%s'", value);
8085 CONF("use_spacer") {
8087 if (strcasecmp(value, "left") == EQUAL) {
8088 use_spacer = LEFT_SPACER;
8089 } else if (strcasecmp(value, "right") == EQUAL) {
8090 use_spacer = RIGHT_SPACER;
8091 } else if (strcasecmp(value, "none") == EQUAL) {
8092 use_spacer = NO_SPACER;
8094 use_spacer = string_to_bool(value);
8095 ERR("use_spacer should have an argument of left, right, or"
8096 " none. '%s' seems to be some form of '%s', so"
8097 " defaulting to %s.", value,
8098 use_spacer ? "true" : "false",
8099 use_spacer ? "right" : "none");
8101 use_spacer = RIGHT_SPACER;
8103 use_spacer = NO_SPACER;
8107 ERR("use_spacer should have an argument. Defaulting to right.");
8108 use_spacer = RIGHT_SPACER;
8114 use_xft = string_to_bool(value);
8118 set_first_font(value);
8122 if (value && font_count >= 0) {
8123 fonts[0].font_alpha = atof(value) * 65535.0;
8130 if (string_to_bool(value)) {
8131 ERR("Xft not enabled at compile time");
8135 /* xftfont silently ignored when no Xft */
8138 /* xftalpha is silently ignored when no Xft */
8143 set_first_font(value);
8151 gap_x = atoi(value);
8158 gap_y = atoi(value);
8164 CONF("mail_spool") {
8168 variable_substitute(value, buffer, 256);
8170 if (buffer[0] != '\0') {
8171 if (current_mail_spool) {
8172 free(current_mail_spool);
8174 current_mail_spool = strndup(buffer, text_buffer_size);
8181 CONF("minimum_size") {
8183 if (sscanf(value, "%d %d", &minimum_width, &minimum_height)
8185 if (sscanf(value, "%d", &minimum_width) != 1) {
8193 CONF("maximum_width") {
8195 if (sscanf(value, "%d", &maximum_width) != 1) {
8203 CONF("no_buffers") {
8204 no_buffers = string_to_bool(value);
8206 CONF("top_name_width") {
8208 if (sscanf(value, "%u", &top_name_width) != 1) {
8214 if (top_name_width >= max_user_text) {
8215 top_name_width = max_user_text - 1;
8218 CONF("top_cpu_separate") {
8219 cpu_separate = string_to_bool(value);
8221 CONF("short_units") {
8222 short_units = string_to_bool(value);
8224 CONF("format_human_readable") {
8225 format_human_readable = string_to_bool(value);
8227 CONF("pad_percents") {
8228 pad_percents = atoi(value);
8232 CONF("own_window") {
8234 own_window = string_to_bool(value);
8237 CONF("own_window_class") {
8239 memset(window.class_name, 0, sizeof(window.class_name));
8240 strncpy(window.class_name, value,
8241 sizeof(window.class_name) - 1);
8244 CONF("own_window_title") {
8246 memset(window.title, 0, sizeof(window.title));
8247 strncpy(window.title, value, sizeof(window.title) - 1);
8250 CONF("own_window_transparent") {
8252 set_transparent = string_to_bool(value);
8255 CONF("own_window_hints") {
8257 char *p_hint, *p_save;
8258 char delim[] = ", ";
8260 /* tokenize the value into individual hints */
8261 if ((p_hint = strtok_r(value, delim, &p_save)) != NULL) {
8263 /* fprintf(stderr, "hint [%s] parsed\n", p_hint); */
8264 if (strncmp(p_hint, "undecorate", 10) == EQUAL) {
8265 SET_HINT(window.hints, HINT_UNDECORATED);
8266 } else if (strncmp(p_hint, "below", 5) == EQUAL) {
8267 SET_HINT(window.hints, HINT_BELOW);
8268 } else if (strncmp(p_hint, "above", 5) == EQUAL) {
8269 SET_HINT(window.hints, HINT_ABOVE);
8270 } else if (strncmp(p_hint, "sticky", 6) == EQUAL) {
8271 SET_HINT(window.hints, HINT_STICKY);
8272 } else if (strncmp(p_hint, "skip_taskbar", 12) == EQUAL) {
8273 SET_HINT(window.hints, HINT_SKIP_TASKBAR);
8274 } else if (strncmp(p_hint, "skip_pager", 10) == EQUAL) {
8275 SET_HINT(window.hints, HINT_SKIP_PAGER);
8280 p_hint = strtok_r(NULL, delim, &p_save);
8281 } while (p_hint != NULL);
8287 CONF("own_window_type") {
8289 if (strncmp(value, "normal", 6) == EQUAL) {
8290 window.type = TYPE_NORMAL;
8291 } else if (strncmp(value, "desktop", 7) == EQUAL) {
8292 window.type = TYPE_DESKTOP;
8293 } else if (strncmp(value, "dock", 7) == EQUAL) {
8294 window.type = TYPE_DOCK;
8295 text_alignment = TOP_LEFT;
8296 } else if (strncmp(value, "override", 8) == EQUAL) {
8297 window.type = TYPE_OVERRIDE;
8306 CONF("stippled_borders") {
8308 stippled_borders = strtol(value, 0, 0);
8310 stippled_borders = 4;
8314 CONF("imlib_cache_size") {
8316 cimlib_set_cache_size(atoi(value));
8319 CONF("imlib_cache_flush_interval") {
8321 cimlib_set_cache_flush_interval(atoi(value));
8326 CONF("update_interval") {
8328 update_interval = strtod(value, 0);
8332 if (info.music_player_interval == 0) {
8333 // default to update_interval
8334 info.music_player_interval = update_interval;
8337 CONF("total_run_times") {
8339 total_run_times = strtod(value, 0);
8345 stuff_in_upper_case = string_to_bool(value);
8347 CONF("max_specials") {
8349 max_specials = atoi(value);
8354 CONF("max_user_text") {
8356 max_user_text = atoi(value);
8361 CONF("text_buffer_size") {
8363 text_buffer_size = atoi(value);
8364 if (text_buffer_size < DEFAULT_TEXT_BUFFER_SIZE) {
8365 ERR("text_buffer_size must be >=%i bytes", DEFAULT_TEXT_BUFFER_SIZE);
8366 text_buffer_size = DEFAULT_TEXT_BUFFER_SIZE;
8374 if (output_methods & TO_X) {
8375 X11_initialisation();
8384 global_text = (char *) malloc(1);
8385 global_text[0] = '\0';
8388 unsigned int l = strlen(global_text);
8390 char buf[CONF_BUFF_SIZE];
8392 if (fgets(buf, CONF_BUFF_SIZE, fp) == NULL) {
8398 if (bl >= 2 && buf[bl-2] == '\\' && buf[bl-1] == '\n') {
8406 /* Check for continuation of \\-\n. */
8407 if (l > 0 && buf[0] == '\n' && global_text[l-1] == '\\') {
8408 global_text[l-1] = '\0';
8412 global_text = (char *) realloc(global_text, l + bl + 1);
8413 strcat(global_text, buf);
8415 if (strlen(global_text) > max_user_text) {
8420 if (strlen(global_text) < 1) {
8421 CRIT_ERR("no text supplied in configuration; exiting");
8423 global_text_lines = line + 1;
8426 #ifdef TCP_PORT_MONITOR
8427 CONF("max_port_monitor_connections") {
8429 if (!value || (sscanf(value, "%d", &max) != 1)) {
8430 /* an error. use default, warn and continue. */
8431 tcp_portmon_set_max_connections(0);
8433 } else if (tcp_portmon_set_max_connections(max)) {
8434 /* max is < 0, default has been set*/
8439 CONF("if_up_strictness") {
8441 ERR("incorrect if_up_strictness value, defaulting to 'up'");
8442 ifup_strictness = IFUP_UP;
8443 } else if (strcasecmp(value, "up") == EQUAL) {
8444 ifup_strictness = IFUP_UP;
8445 } else if (strcasecmp(value, "link") == EQUAL) {
8446 ifup_strictness = IFUP_LINK;
8447 } else if (strcasecmp(value, "address") == EQUAL) {
8448 ifup_strictness = IFUP_ADDR;
8450 ERR("incorrect if_up_strictness value, defaulting to 'up'");
8451 ifup_strictness = IFUP_UP;
8455 CONF("temperature_unit") {
8457 ERR("config option 'temperature_unit' needs an argument, either 'celsius' or 'fahrenheit'");
8458 } else if (set_temp_output_unit(value)) {
8459 ERR("temperature_unit: incorrect argument");
8465 size_t maxlength = strlen(value); //+1 for terminating 0 not needed, 'cause of the space in the middle of value
8466 char *skey = malloc(maxlength);
8467 char *svalue = malloc(maxlength);
8469 if (sscanf(value, "%[0-9a-zA-Z_] %[^\n]", skey, svalue) == 2) {
8470 oldvalue = getenv(skey);
8471 if (oldvalue == NULL) {
8472 setenv(skey, svalue, 0);
8474 //PS: Don't free oldvalue, it's the real envvar, not a copy
8488 char *ptr = strtok(value, " ");
8491 ptr = strtok(NULL, " ");
8497 #endif /* HAVE_LUA */
8509 CONF("default_color"){}
8510 CONF3("default_shade_color", "default_shadecolor"){}
8511 CONF3("default_outline_color", "default_outlinecolor") {}
8512 CONF("own_window_colour") {}
8515 ERR("%s: %d: no such configuration: '%s'", f, line, name);
8521 if (info.music_player_interval == 0) {
8522 // default to update_interval
8523 info.music_player_interval = update_interval;
8525 if (!global_text) { // didn't supply any text
8526 CRIT_ERR("missing text block in configuration; exiting");
8530 static void load_config_file_x11(const char *f)
8535 fp = open_config_file(f);
8539 DBGP("reading contents from config file '%s'", f);
8542 char buff[CONF_BUFF_SIZE], *name, *value;
8543 int ret = do_config_step(&line, fp, buff, &name, &value);
8544 if (ret == CONF_BREAK) {
8546 } else if (ret == CONF_CONTINUE) {
8552 X11_initialisation();
8553 if (x_initialised == YES) {
8555 color0 = get_x11_color(value);
8562 X11_initialisation();
8563 if (x_initialised == YES) {
8565 color1 = get_x11_color(value);
8572 X11_initialisation();
8573 if (x_initialised == YES) {
8575 color2 = get_x11_color(value);
8582 X11_initialisation();
8583 if (x_initialised == YES) {
8585 color3 = get_x11_color(value);
8592 X11_initialisation();
8593 if (x_initialised == YES) {
8595 color4 = get_x11_color(value);
8602 X11_initialisation();
8603 if (x_initialised == YES) {
8605 color5 = get_x11_color(value);
8612 X11_initialisation();
8613 if (x_initialised == YES) {
8615 color6 = get_x11_color(value);
8622 X11_initialisation();
8623 if (x_initialised == YES) {
8625 color7 = get_x11_color(value);
8632 X11_initialisation();
8633 if (x_initialised == YES) {
8635 color8 = get_x11_color(value);
8642 X11_initialisation();
8643 if (x_initialised == YES) {
8645 color9 = get_x11_color(value);
8651 CONF("default_color") {
8652 X11_initialisation();
8653 if (x_initialised == YES) {
8655 default_fg_color = get_x11_color(value);
8661 CONF3("default_shade_color", "default_shadecolor") {
8662 X11_initialisation();
8663 if (x_initialised == YES) {
8665 default_bg_color = get_x11_color(value);
8671 CONF3("default_outline_color", "default_outlinecolor") {
8672 X11_initialisation();
8673 if (x_initialised == YES) {
8675 default_out_color = get_x11_color(value);
8682 CONF("own_window_colour") {
8683 X11_initialisation();
8684 if (x_initialised == YES) {
8686 background_colour = get_x11_color(value);
8688 ERR("Invalid colour for own_window_colour (try omitting the "
8689 "'#' for hex colours");
8695 //initialize X11 if nothing X11-related is mentioned before TEXT (and if X11 is the default outputmethod)
8696 if(output_methods & TO_X) {
8697 X11_initialisation();
8707 #undef CONF_CONTINUE
8708 #undef CONF_BUFF_SIZE
8715 static void print_help(const char *prog_name) {
8716 printf("Usage: %s [OPTION]...\n"
8717 PACKAGE_NAME" is a system monitor that renders text on desktop or to own transparent\n"
8718 "window. Command line options will override configurations defined in config\n"
8720 " -v, --version version\n"
8721 " -q, --quiet quiet mode\n"
8722 " -D, --debug increase debugging output, ie. -DD for more debugging\n"
8723 " -c, --config=FILE config file to load\n"
8724 #ifdef CONFIG_OUTPUT
8725 " -C, --print-config print the builtin default config to stdout\n"
8726 " e.g. 'conky -C > ~/.conkyrc' will create a new default config\n"
8728 " -d, --daemonize daemonize, fork to background\n"
8729 " -h, --help help\n"
8731 " -a, --alignment=ALIGNMENT text alignment on screen, {top,bottom,middle}_{left,right,middle}\n"
8732 " -f, --font=FONT font to use\n"
8733 " -X, --display=DISPLAY X11 display to use\n"
8735 " -o, --own-window create own window to draw\n"
8738 " -b, --double-buffer double buffer (prevents flickering)\n"
8740 " -w, --window-id=WIN_ID window id to draw\n"
8741 " -x X x position\n"
8742 " -y Y y position\n"
8744 " -t, --text=TEXT text to render, remember single quotes, like -t '$uptime'\n"
8745 " -u, --interval=SECS update interval\n"
8746 " -i COUNT number of times to update "PACKAGE_NAME" (and quit)\n",
8751 /* : means that character before that takes an argument */
8752 static const char *getopt_string = "vVqdDt:u:i:hc:"
8762 #ifdef CONFIG_OUTPUT
8767 static const struct option longopts[] = {
8768 { "help", 0, NULL, 'h' },
8769 { "version", 0, NULL, 'V' },
8770 { "debug", 0, NULL, 'D' },
8771 { "config", 1, NULL, 'c' },
8772 #ifdef CONFIG_OUTPUT
8773 { "print-config", 0, NULL, 'C' },
8775 { "daemonize", 0, NULL, 'd' },
8777 { "alignment", 1, NULL, 'a' },
8778 { "font", 1, NULL, 'f' },
8779 { "display", 1, NULL, 'X' },
8781 { "own-window", 0, NULL, 'o' },
8784 { "double-buffer", 0, NULL, 'b' },
8786 { "window-id", 1, NULL, 'w' },
8788 { "text", 1, NULL, 't' },
8789 { "interval", 0, NULL, 'u' },
8793 int main(int argc, char **argv)
8799 struct sigaction act, oact;
8801 g_signal_pending = 0;
8802 memset(&info, 0, sizeof(info));
8805 #ifdef TCP_PORT_MONITOR
8806 /* set default connection limit */
8807 tcp_portmon_set_max_connections(0);
8810 /* handle command line parameters that don't change configs */
8812 if (((s = getenv("LC_ALL")) && *s) || ((s = getenv("LC_CTYPE")) && *s)
8813 || ((s = getenv("LANG")) && *s)) {
8814 temp = (char *) malloc((strlen(s) + 1) * sizeof(char));
8816 ERR("malloc failed");
8818 for (x = 0; x < strlen(s); x++) {
8819 temp[x] = tolower(s[x]);
8822 if (strstr(temp, "utf-8") || strstr(temp, "utf8")) {
8828 if (!setlocale(LC_CTYPE, "")) {
8829 ERR("Can't set the specified locale!\nCheck LANG, LC_CTYPE, LC_ALL.");
8833 int c = getopt_long(argc, argv, getopt_string, longopts, NULL);
8844 if (current_config) {
8845 free(current_config);
8847 current_config = strndup(optarg, max_user_text);
8850 freopen("/dev/null", "w", stderr);
8853 print_help(argv[0]);
8855 #ifdef CONFIG_OUTPUT
8862 window.window = strtol(optarg, 0, 0);
8871 /* check if specified config file is valid */
8872 if (current_config) {
8874 if (stat(current_config, &sb) ||
8875 (!S_ISREG(sb.st_mode) && !S_ISLNK(sb.st_mode))) {
8876 ERR("invalid configuration file '%s'\n", current_config);
8877 free(current_config);
8882 /* load current_config, CONFIG_FILE or SYSTEM_CONFIG_FILE */
8884 if (!current_config) {
8885 /* load default config file */
8886 char buf[DEFAULT_TEXT_BUFFER_SIZE];
8889 /* Try to use personal config file first */
8890 to_real_path(buf, CONFIG_FILE);
8891 if (buf[0] && (fp = fopen(buf, "r"))) {
8892 current_config = strndup(buf, max_user_text);
8896 /* Try to use system config file if personal config not readable */
8897 if (!current_config && (fp = fopen(SYSTEM_CONFIG_FILE, "r"))) {
8898 current_config = strndup(SYSTEM_CONFIG_FILE, max_user_text);
8902 /* No readable config found */
8903 if (!current_config) {
8904 #ifdef CONFIG_OUTPUT
8905 current_config = strdup("==builtin==");
8906 ERR("no readable personal or system-wide config file found,"
8907 " using builtin default");
8909 CRIT_ERR("no readable personal or system-wide config file found");
8910 #endif /* ! CONF_OUTPUT */
8913 #ifdef HAVE_SYS_INOTIFY_H
8914 inotify_fd = inotify_init();
8915 #endif /* HAVE_SYS_INOTIFY_H */
8917 load_config_file(current_config);
8919 /* init specials array */
8920 if ((specials = calloc(sizeof(struct special_t), max_specials)) == 0) {
8921 ERR("failed to create specials array");
8925 if (current_mail_spool == NULL) {
8928 variable_substitute(MAIL_FILE, buf, 256);
8930 if (buf[0] != '\0') {
8931 current_mail_spool = strndup(buf, text_buffer_size);
8936 /* handle other command line arguments */
8938 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__OpenBSD__) \
8939 || defined(__NetBSD__)
8940 optind = optreset = 1;
8945 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
8946 if ((kd = kvm_open("/dev/null", "/dev/null", "/dev/null", O_RDONLY,
8947 "kvm_open")) == NULL) {
8948 CRIT_ERR("cannot read kvm");
8953 int c = getopt_long(argc, argv, getopt_string, longopts, NULL);
8961 fork_to_background = 1;
8964 global_debug_level++;
8968 set_first_font(optarg);
8971 text_alignment = string_to_alignment(optarg);
8976 disp = strdup(optarg);
8995 global_text = strndup(optarg, max_user_text);
8996 convert_escapes(global_text);
9000 update_interval = strtod(optarg, 0);
9001 if (info.music_player_interval == 0) {
9002 // default to update_interval
9003 info.music_player_interval = update_interval;
9008 total_run_times = strtod(optarg, 0);
9012 gap_x = atoi(optarg);
9016 gap_y = atoi(optarg);
9027 if (output_methods & TO_X) {
9028 load_config_file_x11(current_config);
9032 /* generate text and get initial size */
9033 extract_variable_text(global_text);
9040 if (fork_to_background) {
9045 ERR(PACKAGE_NAME": couldn't fork() to background: %s",
9052 fprintf(stderr, "\n");
9057 /* parent process */
9058 fprintf(stderr, PACKAGE_NAME": forked to background, pid is %d\n",
9065 text_buffer = malloc(max_user_text);
9066 memset(text_buffer, 0, max_user_text);
9067 tmpstring1 = malloc(text_buffer_size);
9068 memset(tmpstring1, 0, text_buffer_size);
9069 tmpstring2 = malloc(text_buffer_size);
9070 memset(tmpstring2, 0, text_buffer_size);
9075 X11_create_window();
9078 /* Set signal handlers */
9079 act.sa_handler = signal_handler;
9080 sigemptyset(&act.sa_mask);
9083 act.sa_flags |= SA_RESTART;
9086 if ( sigaction(SIGINT, &act, &oact) < 0
9087 || sigaction(SIGUSR1, &act, &oact) < 0
9088 || sigaction(SIGHUP, &act, &oact) < 0
9089 || sigaction(SIGTERM, &act, &oact) < 0) {
9090 ERR("error setting signal handler: %s", strerror(errno));
9095 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
9102 static void signal_handler(int sig)
9104 /* signal handler is light as a feather, as it should be.
9105 * we will poll g_signal_pending with each loop of conky
9106 * and do any signal processing there, NOT here. */
9107 g_signal_pending = sig;