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;
142 static unsigned int top_name_width = 15;
144 enum x_initialiser_state x_initialised = NO;
145 static volatile int g_signal_pending;
146 /* Update interval */
147 double update_interval;
150 /* prototypes for internally used functions */
151 static void signal_handler(int);
152 static void print_version(void) __attribute__((noreturn));
153 static void reload_config(void);
154 static void clean_up(void);
155 static void generate_text_internal(char *, int, struct text_object,
156 struct information *);
157 static int extract_variable_text_internal(struct text_object *,
160 static void print_version(void)
162 printf(PACKAGE_NAME" "VERSION" compiled "BUILD_DATE" for "BUILD_ARCH"\n");
164 printf("\nCompiled in features:\n\n"
165 "System config file: "SYSTEM_CONFIG_FILE"\n\n"
169 " * Xdamage extension\n"
170 # endif /* HAVE_XDAMAGE */
172 " * XDBE (double buffer extension)\n"
173 # endif /* HAVE_XDBE */
178 "\n Music detection:\n"
181 #endif /* AUDACIOUS */
197 #endif /* HAVE_OPENMP */
204 #ifdef TCP_PORT_MONITOR
206 #endif /* TCP_PORT_MONITOR */
212 #endif /* HAVE_LUA */
215 #endif /* HAVE_IWLIB */
217 " * support for IBM/Lenovo notebooks\n"
227 #endif /* CONFIG_OUTPUT */
232 " * ALSA mixer support\n"
233 #endif /* MIXER_IS_ALSA */
242 static const char *suffixes[] = { "B", "KiB", "MiB", "GiB", "TiB", "PiB", "" };
247 static void X11_destroy_window(void);
248 static void X11_create_window(void);
249 static void X11_initialisation(void);
251 struct _x11_stuff_s {
255 XserverRegion region2, part;
256 int event_base, error_base;
262 static int text_start_x, text_start_y; /* text start position in window */
263 static int text_width, text_height;
278 /* display to connect to */
279 static char *disp = NULL;
283 /* struct that has all info to be shared between
284 * instances of the same text object */
285 struct information info;
287 /* default config file */
288 static char *current_config;
290 /* set to 1 if you want all text to be in uppercase */
291 static unsigned int stuff_in_upper_case;
293 /* Run how many times? */
294 static unsigned long total_run_times;
297 static int fork_to_background;
299 static int cpu_avg_samples, net_avg_samples, diskio_avg_samples;
301 /* filenames for output */
302 char *overwrite_file = NULL; FILE *overwrite_fpointer = NULL;
303 char *append_file = NULL; FILE *append_fpointer = NULL;
307 static int show_graph_scale;
308 static int show_graph_range;
310 /* Position on the screen */
311 static int text_alignment;
312 static int gap_x, gap_y;
315 static int draw_borders;
316 static int draw_graph_borders;
317 static int stippled_borders;
319 static int draw_shades, draw_outline;
321 static int border_margin, border_width;
323 static long default_fg_color, default_bg_color, default_out_color;
325 /* create own window or draw stuff to root? */
326 static int set_transparent = 0;
329 static int own_window = 0;
330 static int background_colour = 0;
332 /* fixed size/pos is set if wm/user changes them */
333 static int fixed_size = 0, fixed_pos = 0;
336 static int minimum_width, minimum_height;
337 static int maximum_width;
342 static int sensor_device;
345 static long color0, color1, color2, color3, color4, color5, color6, color7,
348 #define MAX_TEMPLATES 10
349 static char *template[MAX_TEMPLATES];
351 /* maximum size of config TEXT buffer, i.e. below TEXT line. */
352 static unsigned int max_user_text = MAX_USER_TEXT_DEFAULT;
354 /* maximum size of individual text buffers, ie $exec buffer size */
355 unsigned int text_buffer_size = DEFAULT_TEXT_BUFFER_SIZE;
358 #define CODEPAGE_LENGTH 20
360 long iconv_count = 0;
361 char iconv_converting;
362 static iconv_t **iconv_cd = 0;
364 int register_iconv(iconv_t *new_iconv)
366 iconv_cd = realloc(iconv_cd, sizeof(iconv_t *) * (iconv_count + 1));
368 CRIT_ERR("Out of memory");
370 iconv_cd[iconv_count] = malloc(sizeof(iconv_t));
371 if (!iconv_cd[iconv_count]) {
372 CRIT_ERR("Out of memory");
374 memcpy(iconv_cd[iconv_count], new_iconv, sizeof(iconv_t));
379 void free_iconv(void)
384 for (i = 0; i < iconv_count; i++) {
386 iconv_close(*iconv_cd[i]);
400 /* no buffers in used memory? */
403 /* pad percentages to decimals? */
404 static int pad_percents = 0;
406 static char *global_text = 0;
407 long global_text_lines;
409 static int total_updates;
410 static int updatereset;
412 int check_contains(char *f, char *s)
415 FILE *where = open_file(f, 0);
420 while (fgets(buf1, 256, where)) {
421 if (strstr(buf1, s)) {
428 ERR("Could not open the file");
434 static inline int calc_text_width(const char *s, int l)
436 if ((output_methods & TO_X) == 0)
443 XftTextExtentsUtf8(display, fonts[selected_font].xftfont,
444 (const FcChar8 *) s, l, &gi);
446 XftTextExtents8(display, fonts[selected_font].xftfont,
447 (const FcChar8 *) s, l, &gi);
453 return XTextWidth(fonts[selected_font].font, s, l);
458 /* formatted text to render on screen, generated in generate_text(),
459 * drawn in draw_stuff() */
461 static char *text_buffer;
464 static unsigned int special_index; /* used when drawing */
467 /* quite boring functions */
469 static inline void for_each_line(char *b, void f(char *))
473 for (ps = b, pe = b; *pe; pe++) {
487 static void convert_escapes(char *buf)
489 char *p = buf, *s = buf;
496 } else if (*s == '\\') {
507 /* Prints anything normally printed with snprintf according to the current value
508 * of use_spacer. Actually slightly more flexible than snprintf, as you can
509 * safely specify the destination buffer as one of your inputs. */
510 int spaced_print(char *buf, int size, const char *format, int width, ...)
519 tempbuf = malloc(size * sizeof(char));
521 // Passes the varargs along to vsnprintf
522 va_start(argp, width);
523 vsnprintf(tempbuf, size, format, argp);
526 switch (use_spacer) {
528 len = snprintf(buf, size, "%s", tempbuf);
531 len = snprintf(buf, size, "%*s", width, tempbuf);
534 len = snprintf(buf, size, "%-*s", width, tempbuf);
541 /* print percentage values
543 * - i.e., unsigned values between 0 and 100
544 * - respect the value of pad_percents */
545 static int percent_print(char *buf, int size, unsigned value)
547 return spaced_print(buf, size, "%u", pad_percents, value);
550 /* converts from bytes to human readable format (K, M, G, T)
552 * The algorithm always divides by 1024, as unit-conversion of byte
553 * counts suggests. But for output length determination we need to
554 * compare with 1000 here, as we print in decimal form. */
555 static void human_readable(long long num, char *buf, int size)
557 const char **suffix = suffixes;
563 /* Possibly just output as usual, for example for stdout usage */
564 if (!format_human_readable) {
565 spaced_print(buf, size, "%d", 6, round_to_int(num));
576 if (llabs(num) < 1000LL) {
577 spaced_print(buf, size, format, width, 0, (float)num, *suffix);
581 while (llabs(num / 1024) >= 1000LL && **(suffix + 2)) {
589 /* fnum should now be < 1000, so looks like 'AAA.BBBBB'
591 * The goal is to always have a significance of 3, by
592 * adjusting the decimal part of the number. Sample output:
596 * so the point of alignment resides between number and unit. The
597 * upside of this is that there is minimal padding necessary, though
598 * there should be a way to make alignment take place at the decimal
599 * dot (then with fixed width decimal part).
601 * Note the repdigits below: when given a precision value, printf()
602 * rounds the float to it, not just cuts off the remaining digits. So
603 * e.g. 99.95 with a precision of 1 gets 100.0, which again should be
604 * printed with a precision of 0. Yay. */
606 precision = 0; /* print 100-999 without decimal part */
608 precision = 1; /* print 10-99 with one decimal place */
610 precision = 2; /* print 0-9 with two decimal places */
612 spaced_print(buf, size, format, width, precision, fnum, *suffix);
615 /* global object list root element */
616 static struct text_object global_root_object;
618 static inline void read_exec(const char *data, char *buf, const int size)
620 FILE *fp = popen(data, "r");
621 int length = fread(buf, 1, size, fp);
625 if (length > 0 && buf[length - 1] == '\n') {
626 buf[length - 1] = '\0';
630 void *threaded_exec(void *) __attribute__((noreturn));
632 void *threaded_exec(void *arg)
635 struct text_object *obj = (struct text_object *)arg;
638 buff = malloc(text_buffer_size);
639 read_exec(obj->data.texeci.cmd, buff,
648 timed_thread_lock(obj->data.texeci.p_timed_thread);
649 strncpy(obj->data.texeci.buffer, buff, text_buffer_size);
650 timed_thread_unlock(obj->data.texeci.p_timed_thread);
652 if (timed_thread_test(obj->data.texeci.p_timed_thread, 0)) {
653 timed_thread_exit(obj->data.texeci.p_timed_thread);
659 static struct text_object *new_text_object_internal(void)
661 struct text_object *obj = malloc(sizeof(struct text_object));
662 memset(obj, 0, sizeof(struct text_object));
667 * Frees the list of text objects root points to. When internal = 1, it won't
668 * free global objects.
670 static void free_text_objects(struct text_object *root, int internal)
672 struct text_object *obj;
678 #define data obj->data
679 for (obj = root->prev; obj; obj = root->prev) {
680 root->prev = obj->prev;
686 #endif /* !__OpenBSD__ */
691 close(data.sysfs.fd);
693 #endif /* __linux__ */
695 free(data.read_tcp.host);
702 free(data.tztime.tz);
703 free(data.tztime.fmt);
706 free(data.mboxscan.args);
707 free(data.mboxscan.output);
712 case OBJ_unseen_mails:
713 case OBJ_flagged_mails:
714 case OBJ_unflagged_mails:
715 case OBJ_forwarded_mails:
716 case OBJ_unforwarded_mails:
717 case OBJ_replied_mails:
718 case OBJ_unreplied_mails:
719 case OBJ_draft_mails:
720 case OBJ_trashed_mails:
721 free(data.local_mail.box);
723 case OBJ_imap_unseen:
728 case OBJ_imap_messages:
733 case OBJ_pop3_unseen:
745 free_text_objects(obj->sub, 1);
748 case OBJ_if_existing:
751 free(data.ifblock.s);
752 free(data.ifblock.str);
755 free(data.tail.logfile);
756 free(data.tail.buffer);
772 case OBJ_iconv_start:
777 case OBJ_disk_protect:
781 free(data.ifblock.s);
782 free(data.ifblock.str);
785 if (info.gw_info.iface) {
786 free(info.gw_info.iface);
787 info.gw_info.iface = 0;
789 if (info.gw_info.ip) {
790 free(info.gw_info.ip);
794 case OBJ_ioscheduler:
799 #if (defined(__FreeBSD__) || defined(__linux__))
801 free(data.ifblock.s);
802 free(data.ifblock.str);
806 case OBJ_xmms2_artist:
807 if (info.xmms2.artist) {
808 free(info.xmms2.artist);
809 info.xmms2.artist = 0;
812 case OBJ_xmms2_album:
813 if (info.xmms2.album) {
814 free(info.xmms2.album);
815 info.xmms2.album = 0;
818 case OBJ_xmms2_title:
819 if (info.xmms2.title) {
820 free(info.xmms2.title);
821 info.xmms2.title = 0;
824 case OBJ_xmms2_genre:
825 if (info.xmms2.genre) {
826 free(info.xmms2.genre);
827 info.xmms2.genre = 0;
830 case OBJ_xmms2_comment:
831 if (info.xmms2.comment) {
832 free(info.xmms2.comment);
833 info.xmms2.comment = 0;
837 if (info.xmms2.url) {
838 free(info.xmms2.url);
843 if (info.xmms2.date) {
844 free(info.xmms2.date);
848 case OBJ_xmms2_status:
849 if (info.xmms2.status) {
850 free(info.xmms2.status);
851 info.xmms2.status = 0;
854 case OBJ_xmms2_playlist:
855 if (info.xmms2.playlist) {
856 free(info.xmms2.playlist);
857 info.xmms2.playlist = 0;
860 case OBJ_xmms2_smart:
861 if (info.xmms2.artist) {
862 free(info.xmms2.artist);
863 info.xmms2.artist = 0;
865 if (info.xmms2.title) {
866 free(info.xmms2.title);
867 info.xmms2.title = 0;
869 if (info.xmms2.url) {
870 free(info.xmms2.url);
877 case OBJ_bmpx_artist:
881 case OBJ_bmpx_bitrate:
891 free(data.rss.action);
897 case OBJ_lua_read_parse:
905 #endif /* HAVE_LUA */
912 case OBJ_battery_short:
915 case OBJ_battery_time:
918 #endif /* !__OpenBSD__ */
926 free(data.execi.cmd);
927 free(data.execi.buffer);
930 free(data.texeci.cmd);
931 free(data.texeci.buffer);
939 if (info.first_process && !internal) {
940 free_all_processes();
941 info.first_process = NULL;
943 if (data.top.s) free(data.top.s);
947 free(data.hddtemp.dev);
948 free(data.hddtemp.addr);
949 if (data.hddtemp.temp)
950 free(data.hddtemp.temp);
953 case OBJ_entropy_avail:
954 case OBJ_entropy_perc:
955 case OBJ_entropy_poolsize:
956 case OBJ_entropy_bar:
959 if (info.users.names) {
960 free(info.users.names);
961 info.users.names = 0;
965 if (info.users.terms) {
966 free(info.users.terms);
967 info.users.terms = 0;
971 if (info.users.times) {
972 free(info.users.times);
973 info.users.times = 0;
978 case OBJ_smapi_bat_perc:
979 case OBJ_smapi_bat_temp:
980 case OBJ_smapi_bat_power:
983 case OBJ_if_smapi_bat_installed:
984 free(data.ifblock.s);
985 free(data.ifblock.str);
999 case OBJ_mpd_bitrate:
1000 case OBJ_mpd_status:
1002 case OBJ_mpd_elapsed:
1003 case OBJ_mpd_length:
1007 case OBJ_mpd_percent:
1009 case OBJ_if_mpd_playing:
1017 case OBJ_moc_artist:
1020 case OBJ_moc_totaltime:
1021 case OBJ_moc_timeleft:
1022 case OBJ_moc_curtime:
1023 case OBJ_moc_bitrate:
1029 free(data.scroll.text);
1030 free_text_objects(obj->sub, 1);
1034 free(data.combine.left);
1035 free(data.combine.seperation);
1036 free(data.combine.right);
1037 free_text_objects(obj->sub, 1);
1042 case OBJ_apcupsd_name:
1043 case OBJ_apcupsd_model:
1044 case OBJ_apcupsd_upsmode:
1045 case OBJ_apcupsd_cable:
1046 case OBJ_apcupsd_status:
1047 case OBJ_apcupsd_linev:
1048 case OBJ_apcupsd_load:
1049 case OBJ_apcupsd_loadbar:
1051 case OBJ_apcupsd_loadgraph:
1052 case OBJ_apcupsd_loadgauge:
1054 case OBJ_apcupsd_charge:
1055 case OBJ_apcupsd_timeleft:
1056 case OBJ_apcupsd_temp:
1057 case OBJ_apcupsd_lastxfer:
1059 #endif /* APCUPSD */
1067 void scan_mixer_bar(const char *arg, int *a, int *w, int *h)
1072 if (arg && sscanf(arg, "%63s %n", buf1, &n) >= 1) {
1073 *a = mixer_init(buf1);
1074 scan_bar(arg + n, w, h);
1076 *a = mixer_init(NULL);
1077 scan_bar(arg, w, h);
1082 /* strip a leading /dev/ if any, following symlinks first
1084 * BEWARE: this function returns a pointer to static content
1085 * which gets overwritten in consecutive calls. I.e.:
1086 * this function is NOT reentrant.
1088 static const char *dev_name(const char *path)
1090 static char buf[255]; /* should be enough for pathnames */
1096 #define DEV_NAME(x) \
1097 x != NULL && strlen(x) > 5 && strncmp(x, "/dev/", 5) == 0 ? x + 5 : x
1098 if ((buflen = readlink(path, buf, 254)) == -1)
1099 return DEV_NAME(path);
1101 return DEV_NAME(buf);
1105 static int parse_top_args(const char *s, const char *arg, struct text_object *obj)
1110 if (obj->data.top.was_parsed) {
1113 obj->data.top.was_parsed = 1;
1115 if (arg && !obj->data.top.s) {
1116 obj->data.top.s = strndup(arg, text_buffer_size);
1119 need_mask |= (1 << INFO_TOP);
1122 obj->type = OBJ_top;
1124 } else if (strcmp(&s[3], "_mem") == EQUAL) {
1125 obj->type = OBJ_top_mem;
1127 } else if (strcmp(&s[3], "_time") == EQUAL) {
1128 obj->type = OBJ_top_time;
1131 ERR("Must be top, top_mem or top_time");
1136 ERR("top needs arguments");
1140 if (sscanf(arg, "%63s %i", buf, &n) == 2) {
1141 if (strcmp(buf, "name") == EQUAL) {
1142 obj->data.top.type = TOP_NAME;
1143 } else if (strcmp(buf, "cpu") == EQUAL) {
1144 obj->data.top.type = TOP_CPU;
1145 } else if (strcmp(buf, "pid") == EQUAL) {
1146 obj->data.top.type = TOP_PID;
1147 } else if (strcmp(buf, "mem") == EQUAL) {
1148 obj->data.top.type = TOP_MEM;
1149 } else if (strcmp(buf, "time") == EQUAL) {
1150 obj->data.top.type = TOP_TIME;
1151 } else if (strcmp(buf, "mem_res") == EQUAL) {
1152 obj->data.top.type = TOP_MEM_RES;
1153 } else if (strcmp(buf, "mem_vsize") == EQUAL) {
1154 obj->data.top.type = TOP_MEM_VSIZE;
1156 ERR("invalid type arg for top");
1157 ERR("must be one of: name, cpu, pid, mem, time, mem_res, mem_vsize");
1160 if (n < 1 || n > 10) {
1161 ERR("invalid num arg for top. Must be between 1 and 10.");
1164 obj->data.top.num = n - 1;
1167 ERR("invalid argument count for top");
1173 /* construct_text_object() creates a new text_object */
1174 static struct text_object *construct_text_object(const char *s,
1175 const char *arg, long line, char allow_threaded, void **ifblock_opaque)
1177 // struct text_object *obj = new_text_object();
1178 struct text_object *obj = new_text_object_internal();
1182 #define OBJ(a, n) if (strcmp(s, #a) == 0) { \
1183 obj->type = OBJ_##a; need_mask |= (1ULL << n); {
1184 #define OBJ_IF(a, n) if (strcmp(s, #a) == 0) { \
1185 obj->type = OBJ_##a; need_mask |= (1ULL << n); \
1186 obj_be_ifblock_if(ifblock_opaque, obj); {
1187 #define OBJ_THREAD(a, n) if (strcmp(s, #a) == 0 && allow_threaded) { \
1188 obj->type = OBJ_##a; need_mask |= (1ULL << n); {
1189 #define END } } else
1191 #define SIZE_DEFAULTS(arg) { \
1192 obj->a = default_##arg##_width; \
1193 obj->b = default_##arg##_height; \
1198 obj->type = OBJ_color;
1199 obj->data.l = get_x11_color(s);
1203 OBJ(freq, INFO_FREQ)
1206 obj->data.i = open_acpi_temperature(arg);
1207 END OBJ(acpiacadapter, 0)
1208 END OBJ(freq, INFO_FREQ)
1209 #endif /* !__OpenBSD__ */
1211 if (!arg || !isdigit(arg[0]) || strlen(arg) >= 2 || atoi(&arg[0]) == 0
1212 || (unsigned int) atoi(&arg[0]) > info.cpu_count) {
1213 obj->data.cpu_index = 1;
1214 /* ERR("freq: Invalid CPU number or you don't have that many CPUs! "
1215 "Displaying the clock for CPU 1."); */
1217 obj->data.cpu_index = atoi(&arg[0]);
1220 END OBJ(freq_g, INFO_FREQ)
1222 if (!arg || !isdigit(arg[0]) || strlen(arg) >= 2 || atoi(&arg[0]) == 0
1223 || (unsigned int) atoi(&arg[0]) > info.cpu_count) {
1224 obj->data.cpu_index = 1;
1225 /* ERR("freq_g: Invalid CPU number or you don't have that many "
1226 "CPUs! Displaying the clock for CPU 1."); */
1228 obj->data.cpu_index = atoi(&arg[0]);
1231 END OBJ(read_tcp, 0)
1233 obj->data.read_tcp.host = malloc(text_buffer_size);
1234 sscanf(arg, "%s", obj->data.read_tcp.host);
1235 sscanf(arg+strlen(obj->data.read_tcp.host), "%u", &(obj->data.read_tcp.port));
1236 if(obj->data.read_tcp.port == 0) {
1237 obj->data.read_tcp.port = atoi(obj->data.read_tcp.host);
1238 strcpy(obj->data.read_tcp.host,"localhost");
1240 obj->data.read_tcp.port = htons(obj->data.read_tcp.port);
1241 if(obj->data.read_tcp.port < 1 || obj->data.read_tcp.port > 65535) {
1242 CRIT_ERR("read_tcp: Needs \"(host) port\" as argument(s)");
1245 CRIT_ERR("read_tcp: Needs \"(host) port\" as argument(s)");
1247 #if defined(__linux__)
1248 END OBJ(voltage_mv, 0)
1250 if (!arg || !isdigit(arg[0]) || strlen(arg) >= 2 || atoi(&arg[0]) == 0
1251 || (unsigned int) atoi(&arg[0]) > info.cpu_count) {
1252 obj->data.cpu_index = 1;
1253 /* ERR("voltage_mv: Invalid CPU number or you don't have that many "
1254 "CPUs! Displaying voltage for CPU 1."); */
1256 obj->data.cpu_index = atoi(&arg[0]);
1259 END OBJ(voltage_v, 0)
1261 if (!arg || !isdigit(arg[0]) || strlen(arg) >= 2 || atoi(&arg[0]) == 0
1262 || (unsigned int) atoi(&arg[0]) > info.cpu_count) {
1263 obj->data.cpu_index = 1;
1264 /* ERR("voltage_v: Invalid CPU number or you don't have that many "
1265 "CPUs! Displaying voltage for CPU 1."); */
1267 obj->data.cpu_index = atoi(&arg[0]);
1272 END OBJ(wireless_essid, INFO_NET)
1274 obj->data.net = get_net_stat(arg);
1276 // default to DEFAULTNETDEV
1277 char *buf = strndup(DEFAULTNETDEV, text_buffer_size);
1278 obj->data.net = get_net_stat(buf);
1281 END OBJ(wireless_mode, INFO_NET)
1283 obj->data.net = get_net_stat(arg);
1285 // default to DEFAULTNETDEV
1286 char *buf = strndup(DEFAULTNETDEV, text_buffer_size);
1287 obj->data.net = get_net_stat(buf);
1290 END OBJ(wireless_bitrate, INFO_NET)
1292 obj->data.net = get_net_stat(arg);
1294 // default to DEFAULTNETDEV
1295 char *buf = strndup(DEFAULTNETDEV, text_buffer_size);
1296 obj->data.net = get_net_stat(buf);
1299 END OBJ(wireless_ap, INFO_NET)
1301 obj->data.net = get_net_stat(arg);
1303 // default to DEFAULTNETDEV
1304 char *buf = strndup(DEFAULTNETDEV, text_buffer_size);
1305 obj->data.net = get_net_stat(buf);
1308 END OBJ(wireless_link_qual, INFO_NET)
1310 obj->data.net = get_net_stat(arg);
1312 // default to DEFAULTNETDEV
1313 char *buf = strndup(DEFAULTNETDEV, text_buffer_size);
1314 obj->data.net = get_net_stat(buf);
1317 END OBJ(wireless_link_qual_max, INFO_NET)
1319 obj->data.net = get_net_stat(arg);
1321 // default to DEFAULTNETDEV
1322 char *buf = strndup(DEFAULTNETDEV, text_buffer_size);
1323 obj->data.net = get_net_stat(buf);
1326 END OBJ(wireless_link_qual_perc, INFO_NET)
1328 obj->data.net = get_net_stat(arg);
1330 // default to DEFAULTNETDEV
1331 char *buf = strndup(DEFAULTNETDEV, text_buffer_size);
1332 obj->data.net = get_net_stat(buf);
1335 END OBJ(wireless_link_bar, INFO_NET)
1338 arg = scan_bar(arg, &obj->a, &obj->b);
1339 obj->data.net = get_net_stat(arg);
1341 // default to DEFAULTNETDEV
1342 char *buf = strndup(DEFAULTNETDEV, text_buffer_size);
1343 obj->data.net = get_net_stat(buf);
1346 #endif /* HAVE_IWLIB */
1348 #endif /* __linux__ */
1356 sscanf(arg, "%63s", bat);
1358 strcpy(bat, "BAT0");
1360 obj->data.s = strndup(bat, text_buffer_size);
1361 END OBJ(battery_short, 0)
1365 sscanf(arg, "%63s", bat);
1367 strcpy(bat, "BAT0");
1369 obj->data.s = strndup(bat, text_buffer_size);
1370 END OBJ(battery_time, 0)
1374 sscanf(arg, "%63s", bat);
1376 strcpy(bat, "BAT0");
1378 obj->data.s = strndup(bat, text_buffer_size);
1379 END OBJ(battery_percent, 0)
1383 sscanf(arg, "%63s", bat);
1385 strcpy(bat, "BAT0");
1387 obj->data.s = strndup(bat, text_buffer_size);
1388 END OBJ(battery_bar, 0)
1393 arg = scan_bar(arg, &obj->a, &obj->b);
1394 sscanf(arg, "%63s", bat);
1396 strcpy(bat, "BAT0");
1398 obj->data.s = strndup(bat, text_buffer_size);
1399 #endif /* !__OpenBSD__ */
1401 #if defined(__linux__)
1402 END OBJ(disk_protect, 0)
1404 obj->data.s = strndup(dev_name(arg), text_buffer_size);
1406 CRIT_ERR("disk_protect needs an argument");
1407 END OBJ(i8k_version, INFO_I8K)
1408 END OBJ(i8k_bios, INFO_I8K)
1409 END OBJ(i8k_serial, INFO_I8K)
1410 END OBJ(i8k_cpu_temp, INFO_I8K)
1411 END OBJ(i8k_left_fan_status, INFO_I8K)
1412 END OBJ(i8k_right_fan_status, INFO_I8K)
1413 END OBJ(i8k_left_fan_rpm, INFO_I8K)
1414 END OBJ(i8k_right_fan_rpm, INFO_I8K)
1415 END OBJ(i8k_ac_status, INFO_I8K)
1416 END OBJ(i8k_buttons_status, INFO_I8K)
1419 END OBJ(ibm_temps, 0)
1421 CRIT_ERR("ibm_temps: needs an argument");
1423 if (!isdigit(arg[0]) || strlen(arg) >= 2 || atoi(&arg[0]) >= 8) {
1424 obj->data.sensor = 0;
1425 ERR("Invalid temperature sensor! Sensor number must be 0 to 7. "
1426 "Using 0 (CPU temp sensor).");
1428 obj->data.sensor = atoi(&arg[0]);
1429 END OBJ(ibm_volume, 0)
1430 END OBJ(ibm_brightness, 0)
1432 /* information from sony_laptop kernel module
1433 * /sys/devices/platform/sony-laptop */
1434 END OBJ(sony_fanspeed, 0)
1435 END OBJ_IF(if_gw, INFO_GW)
1436 END OBJ(ioscheduler, 0)
1438 CRIT_ERR("get_ioscheduler needs an argument (e.g. hda)");
1441 obj->data.s = strndup(dev_name(arg), text_buffer_size);
1442 END OBJ(laptop_mode, 0)
1443 END OBJ(pb_battery, 0)
1444 if (arg && strcmp(arg, "status") == EQUAL) {
1445 obj->data.i = PB_BATT_STATUS;
1446 } else if (arg && strcmp(arg, "percent") == EQUAL) {
1447 obj->data.i = PB_BATT_PERCENT;
1448 } else if (arg && strcmp(arg, "time") == EQUAL) {
1449 obj->data.i = PB_BATT_TIME;
1451 ERR("pb_battery: needs one argument: status, percent or time");
1456 #endif /* __linux__ */
1457 #if (defined(__FreeBSD__) || defined(__linux__))
1458 END OBJ_IF(if_up, 0)
1460 ERR("if_up needs an argument");
1461 obj->data.ifblock.s = 0;
1463 obj->data.ifblock.s = strndup(arg, text_buffer_size);
1466 #if defined(__OpenBSD__)
1467 END OBJ(obsd_sensors_temp, 0)
1469 CRIT_ERR("obsd_sensors_temp: needs an argument");
1471 if (!isdigit(arg[0]) || atoi(&arg[0]) < 0
1472 || atoi(&arg[0]) > OBSD_MAX_SENSORS - 1) {
1473 obj->data.sensor = 0;
1474 ERR("Invalid temperature sensor number!");
1476 obj->data.sensor = atoi(&arg[0]);
1477 END OBJ(obsd_sensors_fan, 0)
1479 CRIT_ERR("obsd_sensors_fan: needs 2 arguments (device and sensor "
1482 if (!isdigit(arg[0]) || atoi(&arg[0]) < 0
1483 || atoi(&arg[0]) > OBSD_MAX_SENSORS - 1) {
1484 obj->data.sensor = 0;
1485 ERR("Invalid fan sensor number!");
1487 obj->data.sensor = atoi(&arg[0]);
1488 END OBJ(obsd_sensors_volt, 0)
1490 CRIT_ERR("obsd_sensors_volt: needs 2 arguments (device and sensor "
1493 if (!isdigit(arg[0]) || atoi(&arg[0]) < 0
1494 || atoi(&arg[0]) > OBSD_MAX_SENSORS - 1) {
1495 obj->data.sensor = 0;
1496 ERR("Invalid voltage sensor number!");
1498 obj->data.sensor = atoi(&arg[0]);
1499 END OBJ(obsd_vendor, 0)
1500 END OBJ(obsd_product, 0)
1501 #endif /* __OpenBSD__ */
1502 END OBJ(buffers, INFO_BUFFERS)
1503 END OBJ(cached, INFO_BUFFERS)
1504 #define SCAN_CPU(__arg, __var) { \
1506 if (__arg && sscanf(__arg, " cpu%u %n", &__var, &__offset) > 0) \
1507 __arg += __offset; \
1511 END OBJ(cpu, INFO_CPU)
1512 SCAN_CPU(arg, obj->data.cpu_index);
1513 DBGP2("Adding $cpu for CPU %d", obj->data.cpu_index);
1515 END OBJ(cpugauge, INFO_CPU)
1516 SIZE_DEFAULTS(gauge);
1517 SCAN_CPU(arg, obj->data.cpu_index);
1518 scan_gauge(arg, &obj->a, &obj->b);
1519 DBGP2("Adding $cpugauge for CPU %d", obj->data.cpu_index);
1521 END OBJ(cpubar, INFO_CPU)
1523 SCAN_CPU(arg, obj->data.cpu_index);
1524 scan_bar(arg, &obj->a, &obj->b);
1525 DBGP2("Adding $cpubar for CPU %d", obj->data.cpu_index);
1527 END OBJ(cpugraph, INFO_CPU)
1528 SIZE_DEFAULTS(graph);
1529 SCAN_CPU(arg, obj->data.cpu_index);
1530 scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
1531 &obj->e, &obj->char_a, &obj->char_b);
1532 DBGP2("Adding $cpugraph for CPU %d", obj->data.cpu_index);
1533 END OBJ(loadgraph, INFO_LOADAVG)
1535 SIZE_DEFAULTS(graph);
1536 buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
1537 &obj->e, &obj->char_a, &obj->char_b);
1541 r = sscanf(arg, "%d", &a);
1543 obj->data.loadavg[0] = (r >= 1) ? (unsigned char) a : 0;
1547 END OBJ(diskio, INFO_DISKIO)
1548 obj->data.diskio = prepare_diskio_stat(dev_name(arg));
1549 END OBJ(diskio_read, INFO_DISKIO)
1550 obj->data.diskio = prepare_diskio_stat(dev_name(arg));
1551 END OBJ(diskio_write, INFO_DISKIO)
1552 obj->data.diskio = prepare_diskio_stat(dev_name(arg));
1554 END OBJ(diskiograph, INFO_DISKIO)
1556 SIZE_DEFAULTS(graph);
1557 buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
1558 &obj->e, &obj->char_a, &obj->char_b);
1560 obj->data.diskio = prepare_diskio_stat(dev_name(buf));
1563 END OBJ(diskiograph_read, INFO_DISKIO)
1565 SIZE_DEFAULTS(graph);
1566 buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
1567 &obj->e, &obj->char_a, &obj->char_b);
1569 obj->data.diskio = prepare_diskio_stat(dev_name(buf));
1572 END OBJ(diskiograph_write, INFO_DISKIO)
1574 SIZE_DEFAULTS(graph);
1575 buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
1576 &obj->e, &obj->char_a, &obj->char_b);
1578 obj->data.diskio = prepare_diskio_stat(dev_name(buf));
1584 if (output_methods & TO_X) {
1585 obj->data.l = arg ? get_x11_color(arg) : default_fg_color;
1589 obj->data.l = color0;
1591 obj->data.l = color1;
1593 obj->data.l = color2;
1595 obj->data.l = color3;
1597 obj->data.l = color4;
1599 obj->data.l = color5;
1601 obj->data.l = color6;
1603 obj->data.l = color7;
1605 obj->data.l = color8;
1607 obj->data.l = color9;
1610 obj->data.s = scan_font(arg);
1612 END OBJ(conky_version, 0)
1613 END OBJ(conky_build_date, 0)
1614 END OBJ(conky_build_arch, 0)
1615 END OBJ(downspeed, INFO_NET)
1617 obj->data.net = get_net_stat(arg);
1619 // default to DEFAULTNETDEV
1620 char *buf = strndup(DEFAULTNETDEV, text_buffer_size);
1621 obj->data.net = get_net_stat(buf);
1624 END OBJ(downspeedf, INFO_NET)
1626 obj->data.net = get_net_stat(arg);
1628 // default to DEFAULTNETDEV
1629 char *buf = strndup(DEFAULTNETDEV, text_buffer_size);
1630 obj->data.net = get_net_stat(buf);
1634 END OBJ(downspeedgraph, INFO_NET)
1636 SIZE_DEFAULTS(graph);
1637 buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
1638 &obj->e, &obj->char_a, &obj->char_b);
1640 // default to DEFAULTNETDEV
1641 buf = strndup(buf ? buf : DEFAULTNETDEV, text_buffer_size);
1642 obj->data.net = get_net_stat(buf);
1646 obj_be_ifblock_else(ifblock_opaque, obj);
1648 obj_be_ifblock_endif(ifblock_opaque, obj);
1650 obj->data.s = strndup(arg ? arg : "", text_buffer_size);
1652 obj->data.s = strndup(arg ? arg : "", text_buffer_size);
1655 obj->data.s = strndup(arg ? arg : "", text_buffer_size);
1657 obj->data.s = strndup(arg ? arg : "", text_buffer_size);
1660 obj->data.s = strndup(arg ? arg : "", text_buffer_size);
1662 END OBJ(execgauge, 0)
1663 SIZE_DEFAULTS(gauge);
1664 obj->data.s = strndup(arg ? arg : "", text_buffer_size);
1665 END OBJ(execgraph, 0)
1666 SIZE_DEFAULTS(graph);
1667 obj->data.s = strndup(arg ? arg : "", text_buffer_size);
1669 END OBJ(execibar, 0)
1673 if (!arg || sscanf(arg, "%f %n", &obj->data.execi.interval, &n) <= 0) {
1676 ERR("${execibar <interval> command}");
1677 obj->type = OBJ_text;
1678 snprintf(buf, 256, "${%s}", s);
1679 obj->data.s = strndup(buf, text_buffer_size);
1681 obj->data.execi.cmd = strndup(arg + n, text_buffer_size);
1684 END OBJ(execigraph, 0)
1686 SIZE_DEFAULTS(graph);
1688 if (!arg || sscanf(arg, "%f %n", &obj->data.execi.interval, &n) <= 0) {
1691 ERR("${execigraph <interval> command}");
1692 obj->type = OBJ_text;
1693 snprintf(buf, 256, "${%s}", s);
1694 obj->data.s = strndup(buf, text_buffer_size);
1696 obj->data.execi.cmd = strndup(arg + n, text_buffer_size);
1698 END OBJ(execigauge, 0)
1700 SIZE_DEFAULTS(gauge);
1702 if (!arg || sscanf(arg, "%f %n", &obj->data.execi.interval, &n) <= 0) {
1705 ERR("${execigauge <interval> command}");
1706 obj->type = OBJ_text;
1707 snprintf(buf, 256, "${%s}", s);
1708 obj->data.s = strndup(buf, text_buffer_size);
1710 obj->data.execi.cmd = strndup(arg + n, text_buffer_size);
1716 if (!arg || sscanf(arg, "%f %n", &obj->data.execi.interval, &n) <= 0) {
1719 ERR("${execi <interval> command}");
1720 obj->type = OBJ_text;
1721 snprintf(buf, 256, "${%s}", s);
1722 obj->data.s = strndup(buf, text_buffer_size);
1724 obj->data.execi.cmd = strndup(arg + n, text_buffer_size);
1725 obj->data.execi.buffer = malloc(text_buffer_size);
1730 if (!arg || sscanf(arg, "%f %n", &obj->data.execi.interval, &n) <= 0) {
1733 ERR("${execi <interval> command}");
1734 obj->type = OBJ_text;
1735 snprintf(buf, 256, "${%s}", s);
1736 obj->data.s = strndup(buf, text_buffer_size);
1738 obj->data.execi.cmd = strndup(arg + n, text_buffer_size);
1739 obj->data.execi.buffer = malloc(text_buffer_size);
1741 END OBJ_THREAD(texeci, 0)
1744 if (!arg || sscanf(arg, "%f %n", &obj->data.texeci.interval, &n) <= 0) {
1747 ERR("${texeci <interval> command}");
1748 obj->type = OBJ_text;
1749 snprintf(buf, 256, "${%s}", s);
1750 obj->data.s = strndup(buf, text_buffer_size);
1752 obj->data.texeci.cmd = strndup(arg + n, text_buffer_size);
1753 obj->data.texeci.buffer = malloc(text_buffer_size);
1755 obj->data.texeci.p_timed_thread = NULL;
1756 END OBJ(pre_exec, 0)
1757 obj->type = OBJ_text;
1761 read_exec(arg, buf, sizeof(buf));
1762 obj->data.s = strndup(buf, text_buffer_size);
1764 obj->data.s = strndup("", text_buffer_size);
1767 END OBJ(fs_bar, INFO_FS)
1769 arg = scan_bar(arg, &obj->data.fsbar.w, &obj->data.fsbar.h);
1771 while (isspace(*arg)) {
1780 obj->data.fsbar.fs = prepare_fs_stat(arg);
1781 END OBJ(fs_bar_free, INFO_FS)
1783 arg = scan_bar(arg, &obj->data.fsbar.w, &obj->data.fsbar.h);
1785 while (isspace(*arg)) {
1795 obj->data.fsbar.fs = prepare_fs_stat(arg);
1796 END OBJ(fs_free, INFO_FS)
1800 obj->data.fs = prepare_fs_stat(arg);
1801 END OBJ(fs_used_perc, INFO_FS)
1805 obj->data.fs = prepare_fs_stat(arg);
1806 END OBJ(fs_free_perc, INFO_FS)
1810 obj->data.fs = prepare_fs_stat(arg);
1811 END OBJ(fs_size, INFO_FS)
1815 obj->data.fs = prepare_fs_stat(arg);
1816 END OBJ(fs_type, INFO_FS)
1820 obj->data.fs = prepare_fs_stat(arg);
1821 END OBJ(fs_used, INFO_FS)
1825 obj->data.fs = prepare_fs_stat(arg);
1827 obj->data.i = arg ? atoi(arg) : 1;
1828 END OBJ(nameserver, INFO_DNS)
1829 obj->data.i = arg ? atoi(arg) : 0;
1831 obj->data.i = arg ? atoi(arg) : 1;
1833 obj->data.i = arg ? atoi(arg) : 1;
1837 ERR("goto needs arguments");
1838 obj->type = OBJ_text;
1839 obj->data.s = strndup("${goto}", text_buffer_size);
1843 obj->data.i = atoi(arg);
1849 if (sscanf(arg, "%d %d", &a, &b) != 2) {
1850 sscanf(arg, "%d", &b);
1856 obj->data.pair.a = a;
1857 obj->data.pair.b = b;
1860 END OBJ(i2c, INFO_SYSFS)
1861 char buf1[64], buf2[64];
1862 float factor, offset;
1866 ERR("i2c needs arguments");
1867 obj->type = OBJ_text;
1868 // obj->data.s = strndup("${i2c}", text_buffer_size);
1872 #define HWMON_RESET() {\
1877 if (sscanf(arg, "%63s %d %f %f", buf2, &n, &factor, &offset) == 4) found = 1; else HWMON_RESET();
1878 if (!found && sscanf(arg, "%63s %63s %d %f %f", buf1, buf2, &n, &factor, &offset) == 5) found = 1; else if (!found) HWMON_RESET();
1879 if (!found && sscanf(arg, "%63s %63s %d", buf1, buf2, &n) == 3) found = 1; else if (!found) HWMON_RESET();
1880 if (!found && sscanf(arg, "%63s %d", buf2, &n) == 2) found = 1; else if (!found) HWMON_RESET();
1883 ERR("i2c failed to parse arguments");
1884 obj->type = OBJ_text;
1887 DBGP("parsed i2c args: '%s' '%s' %d %f %f\n", buf1, buf2, n, factor, offset);
1888 obj->data.sysfs.fd = open_i2c_sensor((*buf1) ? buf1 : 0, buf2, n,
1889 &obj->data.sysfs.arg, obj->data.sysfs.devtype);
1890 strncpy(obj->data.sysfs.type, buf2, 63);
1891 obj->data.sysfs.factor = factor;
1892 obj->data.sysfs.offset = offset;
1894 END OBJ(platform, INFO_SYSFS)
1895 char buf1[64], buf2[64];
1896 float factor, offset;
1900 ERR("platform needs arguments");
1901 obj->type = OBJ_text;
1905 if (sscanf(arg, "%63s %d %f %f", buf2, &n, &factor, &offset) == 4) found = 1; else HWMON_RESET();
1906 if (!found && sscanf(arg, "%63s %63s %d %f %f", buf1, buf2, &n, &factor, &offset) == 5) found = 1; else if (!found) HWMON_RESET();
1907 if (!found && sscanf(arg, "%63s %63s %d", buf1, buf2, &n) == 3) found = 1; else if (!found) HWMON_RESET();
1908 if (!found && sscanf(arg, "%63s %d", buf2, &n) == 2) found = 1; else if (!found) HWMON_RESET();
1911 ERR("platform failed to parse arguments");
1912 obj->type = OBJ_text;
1915 DBGP("parsed platform args: '%s' '%s' %d %f %f\n", buf1, buf2, n, factor, offset);
1916 obj->data.sysfs.fd = open_platform_sensor((*buf1) ? buf1 : 0, buf2, n,
1917 &obj->data.sysfs.arg, obj->data.sysfs.devtype);
1918 strncpy(obj->data.sysfs.type, buf2, 63);
1919 obj->data.sysfs.factor = factor;
1920 obj->data.sysfs.offset = offset;
1922 END OBJ(hwmon, INFO_SYSFS)
1923 char buf1[64], buf2[64];
1924 float factor, offset;
1928 ERR("hwmon needs argumanets");
1929 obj->type = OBJ_text;
1933 if (sscanf(arg, "%63s %d %f %f", buf2, &n, &factor, &offset) == 4) found = 1; else HWMON_RESET();
1934 if (!found && sscanf(arg, "%63s %63s %d %f %f", buf1, buf2, &n, &factor, &offset) == 5) found = 1; else if (!found) HWMON_RESET();
1935 if (!found && sscanf(arg, "%63s %63s %d", buf1, buf2, &n) == 3) found = 1; else if (!found) HWMON_RESET();
1936 if (!found && sscanf(arg, "%63s %d", buf2, &n) == 2) found = 1; else if (!found) HWMON_RESET();
1941 ERR("hwmon failed to parse arguments");
1942 obj->type = OBJ_text;
1945 DBGP("parsed hwmon args: '%s' '%s' %d %f %f\n", buf1, buf2, n, factor, offset);
1946 obj->data.sysfs.fd = open_hwmon_sensor((*buf1) ? buf1 : 0, buf2, n,
1947 &obj->data.sysfs.arg, obj->data.sysfs.devtype);
1948 strncpy(obj->data.sysfs.type, buf2, 63);
1949 obj->data.sysfs.factor = factor;
1950 obj->data.sysfs.offset = offset;
1952 #endif /* !__OpenBSD__ */
1955 /* we have three different types of top (top, top_mem and top_time). To
1956 * avoid having almost-same code three times, we have this special
1958 if (strncmp(s, "top", 3) == EQUAL) {
1959 if (!parse_top_args(s, arg, obj)) {
1962 } else OBJ(addr, INFO_NET)
1964 obj->data.net = get_net_stat(arg);
1966 // default to DEFAULTNETDEV
1967 char *buf = strndup(DEFAULTNETDEV, text_buffer_size);
1968 obj->data.net = get_net_stat(buf);
1971 #if defined(__linux__)
1972 END OBJ(addrs, INFO_NET)
1974 obj->data.net = get_net_stat(arg);
1976 // default to DEFAULTNETDEV
1977 char *buf = strndup(DEFAULTNETDEV, text_buffer_size);
1978 obj->data.net = get_net_stat(buf);
1981 #endif /* __linux__ */
1983 if (init_tail_object(obj, arg)) {
1984 obj->type = OBJ_text;
1985 obj->data.s = strndup("${tail}", text_buffer_size);
1988 if (init_head_object(obj, arg)) {
1989 obj->type = OBJ_text;
1990 obj->data.s = strndup("${head}", text_buffer_size);
1994 obj->data.s = strndup(arg, text_buffer_size);
1996 CRIT_ERR("lines needs a argument");
2000 obj->data.s = strndup(arg, text_buffer_size);
2002 CRIT_ERR("words needs a argument");
2004 END OBJ(loadavg, INFO_LOADAVG)
2005 int a = 1, b = 2, c = 3, r = 3;
2008 r = sscanf(arg, "%d %d %d", &a, &b, &c);
2009 if (r >= 3 && (c < 1 || c > 3)) {
2012 if (r >= 2 && (b < 1 || b > 3)) {
2015 if (r >= 1 && (a < 1 || a > 3)) {
2019 obj->data.loadavg[0] = (r >= 1) ? (unsigned char) a : 0;
2020 obj->data.loadavg[1] = (r >= 2) ? (unsigned char) b : 0;
2021 obj->data.loadavg[2] = (r >= 3) ? (unsigned char) c : 0;
2022 END OBJ_IF(if_empty, 0)
2024 ERR("if_empty needs an argument");
2025 obj->data.ifblock.s = 0;
2027 obj->data.ifblock.s = strndup(arg, text_buffer_size);
2028 obj->sub = malloc(sizeof(struct text_object));
2029 extract_variable_text_internal(obj->sub,
2030 obj->data.ifblock.s, 0);
2032 END OBJ_IF(if_match, 0)
2034 ERR("if_match needs arguments");
2035 obj->data.ifblock.s = 0;
2037 obj->data.ifblock.s = strndup(arg, text_buffer_size);
2038 obj->sub = malloc(sizeof(struct text_object));
2039 extract_variable_text_internal(obj->sub,
2040 obj->data.ifblock.s, 0);
2042 END OBJ_IF(if_existing, 0)
2044 ERR("if_existing needs an argument or two");
2045 obj->data.ifblock.s = NULL;
2046 obj->data.ifblock.str = NULL;
2048 char buf1[256], buf2[256];
2049 int r = sscanf(arg, "%255s %255[^\n]", buf1, buf2);
2052 obj->data.ifblock.s = strndup(buf1, text_buffer_size);
2053 obj->data.ifblock.str = NULL;
2055 obj->data.ifblock.s = strndup(buf1, text_buffer_size);
2056 obj->data.ifblock.str = strndup(buf2, text_buffer_size);
2059 DBGP("if_existing: '%s' '%s'", obj->data.ifblock.s, obj->data.ifblock.str);
2060 END OBJ_IF(if_mounted, 0)
2062 ERR("if_mounted needs an argument");
2063 obj->data.ifblock.s = 0;
2065 obj->data.ifblock.s = strndup(arg, text_buffer_size);
2067 END OBJ_IF(if_running, 0)
2071 snprintf(buf, 256, "pidof %s >/dev/null", arg);
2072 obj->data.ifblock.s = strndup(buf, text_buffer_size);
2074 ERR("if_running needs an argument");
2075 obj->data.ifblock.s = 0;
2081 char box[256], dst[256];
2085 /* Kapil: Changed from MAIL_FILE to
2086 current_mail_spool since the latter
2087 is a copy of the former if undefined
2088 but the latter should take precedence
2090 strncpy(box, current_mail_spool, sizeof(box));
2092 if (sscanf(arg, "%s %f", box, &n1) != 2) {
2094 strncpy(box, arg, sizeof(box));
2098 variable_substitute(box, dst, sizeof(dst));
2099 obj->data.local_mail.box = strndup(dst, text_buffer_size);
2100 obj->data.local_mail.interval = n1;
2101 END OBJ(new_mails, 0)
2103 char box[256], dst[256];
2107 strncpy(box, current_mail_spool, sizeof(box));
2109 if (sscanf(arg, "%s %f", box, &n1) != 2) {
2111 strncpy(box, arg, sizeof(box));
2115 variable_substitute(box, dst, sizeof(dst));
2116 obj->data.local_mail.box = strndup(dst, text_buffer_size);
2117 obj->data.local_mail.interval = n1;
2118 END OBJ(seen_mails, 0)
2120 char box[256], dst[256];
2124 strncpy(box, current_mail_spool, sizeof(box));
2126 if (sscanf(arg, "%s %f", box, &n1) != 2) {
2128 strncpy(box, arg, sizeof(box));
2132 variable_substitute(box, dst, sizeof(dst));
2133 obj->data.local_mail.box = strndup(dst, text_buffer_size);
2134 obj->data.local_mail.interval = n1;
2135 END OBJ(unseen_mails, 0)
2137 char box[256], dst[256];
2141 strncpy(box, current_mail_spool, sizeof(box));
2143 if (sscanf(arg, "%s %f", box, &n1) != 2) {
2145 strncpy(box, arg, sizeof(box));
2149 variable_substitute(box, dst, sizeof(dst));
2150 obj->data.local_mail.box = strndup(dst, text_buffer_size);
2151 obj->data.local_mail.interval = n1;
2152 END OBJ(flagged_mails, 0)
2154 char box[256], dst[256];
2158 strncpy(box, current_mail_spool, sizeof(box));
2160 if (sscanf(arg, "%s %f", box, &n1) != 2) {
2162 strncpy(box, arg, sizeof(box));
2166 variable_substitute(box, dst, sizeof(dst));
2167 obj->data.local_mail.box = strndup(dst, text_buffer_size);
2168 obj->data.local_mail.interval = n1;
2169 END OBJ(unflagged_mails, 0)
2171 char box[256], dst[256];
2175 strncpy(box, current_mail_spool, sizeof(box));
2177 if (sscanf(arg, "%s %f", box, &n1) != 2) {
2179 strncpy(box, arg, sizeof(box));
2183 variable_substitute(box, dst, sizeof(dst));
2184 obj->data.local_mail.box = strndup(dst, text_buffer_size);
2185 obj->data.local_mail.interval = n1;
2186 END OBJ(forwarded_mails, 0)
2188 char box[256], dst[256];
2192 strncpy(box, current_mail_spool, sizeof(box));
2194 if (sscanf(arg, "%s %f", box, &n1) != 2) {
2196 strncpy(box, arg, sizeof(box));
2200 variable_substitute(box, dst, sizeof(dst));
2201 obj->data.local_mail.box = strndup(dst, text_buffer_size);
2202 obj->data.local_mail.interval = n1;
2203 END OBJ(unforwarded_mails, 0)
2205 char box[256], dst[256];
2209 strncpy(box, current_mail_spool, sizeof(box));
2211 if (sscanf(arg, "%s %f", box, &n1) != 2) {
2213 strncpy(box, arg, sizeof(box));
2217 variable_substitute(box, dst, sizeof(dst));
2218 obj->data.local_mail.box = strndup(dst, text_buffer_size);
2219 obj->data.local_mail.interval = n1;
2220 END OBJ(replied_mails, 0)
2222 char box[256], dst[256];
2226 strncpy(box, current_mail_spool, sizeof(box));
2228 if (sscanf(arg, "%s %f", box, &n1) != 2) {
2230 strncpy(box, arg, sizeof(box));
2234 variable_substitute(box, dst, sizeof(dst));
2235 obj->data.local_mail.box = strndup(dst, text_buffer_size);
2236 obj->data.local_mail.interval = n1;
2237 END OBJ(unreplied_mails, 0)
2239 char box[256], dst[256];
2243 strncpy(box, current_mail_spool, sizeof(box));
2245 if (sscanf(arg, "%s %f", box, &n1) != 2) {
2247 strncpy(box, arg, sizeof(box));
2251 variable_substitute(box, dst, sizeof(dst));
2252 obj->data.local_mail.box = strndup(dst, text_buffer_size);
2253 obj->data.local_mail.interval = n1;
2254 END OBJ(draft_mails, 0)
2256 char box[256], dst[256];
2260 strncpy(box, current_mail_spool, sizeof(box));
2262 if (sscanf(arg, "%s %f", box, &n1) != 2) {
2264 strncpy(box, arg, sizeof(box));
2268 variable_substitute(box, dst, sizeof(dst));
2269 obj->data.local_mail.box = strndup(dst, text_buffer_size);
2270 obj->data.local_mail.interval = n1;
2271 END OBJ(trashed_mails, 0)
2273 char box[256], dst[256];
2277 strncpy(box, current_mail_spool, sizeof(box));
2279 if (sscanf(arg, "%s %f", box, &n1) != 2) {
2281 strncpy(box, arg, sizeof(box));
2285 variable_substitute(box, dst, sizeof(dst));
2286 obj->data.local_mail.box = strndup(dst, text_buffer_size);
2287 obj->data.local_mail.interval = n1;
2288 END OBJ(mboxscan, 0)
2289 obj->data.mboxscan.args = (char *) malloc(text_buffer_size);
2290 obj->data.mboxscan.output = (char *) malloc(text_buffer_size);
2291 /* if '1' (in mboxscan.c) then there was SIGUSR1, hmm */
2292 obj->data.mboxscan.output[0] = 1;
2293 strncpy(obj->data.mboxscan.args, arg, text_buffer_size);
2294 END OBJ(mem, INFO_MEM)
2295 END OBJ(memeasyfree, INFO_MEM)
2296 END OBJ(memfree, INFO_MEM)
2297 END OBJ(memmax, INFO_MEM)
2298 END OBJ(memperc, INFO_MEM)
2300 END OBJ(memgauge, INFO_MEM)
2301 SIZE_DEFAULTS(gauge);
2302 scan_gauge(arg, &obj->data.pair.a, &obj->data.pair.b);
2304 END OBJ(membar, INFO_MEM)
2306 scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
2308 END OBJ(memgraph, INFO_MEM)
2310 SIZE_DEFAULTS(graph);
2311 buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
2312 &obj->e, &obj->char_a, &obj->char_b);
2318 END OBJ(mixer, INFO_MIXER)
2319 obj->data.l = mixer_init(arg);
2320 END OBJ(mixerl, INFO_MIXER)
2321 obj->data.l = mixer_init(arg);
2322 END OBJ(mixerr, INFO_MIXER)
2323 obj->data.l = mixer_init(arg);
2325 END OBJ(mixerbar, INFO_MIXER)
2327 scan_mixer_bar(arg, &obj->data.mixerbar.l, &obj->data.mixerbar.w,
2328 &obj->data.mixerbar.h);
2329 END OBJ(mixerlbar, INFO_MIXER)
2331 scan_mixer_bar(arg, &obj->data.mixerbar.l, &obj->data.mixerbar.w,
2332 &obj->data.mixerbar.h);
2333 END OBJ(mixerrbar, INFO_MIXER)
2335 scan_mixer_bar(arg, &obj->data.mixerbar.l, &obj->data.mixerbar.w,
2336 &obj->data.mixerbar.h);
2338 END OBJ_IF(if_mixer_mute, INFO_MIXER)
2339 obj->data.ifblock.i = mixer_init(arg);
2341 END OBJ(monitor, INFO_X11)
2342 END OBJ(monitor_number, INFO_X11)
2344 END OBJ(nodename, 0)
2345 END OBJ(processes, INFO_PROCS)
2346 END OBJ(running_processes, INFO_RUN_PROCS)
2347 END OBJ(shadecolor, 0)
2349 obj->data.l = arg ? get_x11_color(arg) : default_bg_color;
2351 END OBJ(outlinecolor, 0)
2353 obj->data.l = arg ? get_x11_color(arg) : default_out_color;
2355 END OBJ(stippled_hr, 0)
2357 int a = stippled_borders, b = 1;
2360 if (sscanf(arg, "%d %d", &a, &b) != 2) {
2361 sscanf(arg, "%d", &b);
2367 obj->data.pair.a = a;
2368 obj->data.pair.b = b;
2370 END OBJ(swap, INFO_MEM)
2371 END OBJ(swapmax, INFO_MEM)
2372 END OBJ(swapperc, INFO_MEM)
2373 END OBJ(swapbar, INFO_MEM)
2375 scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
2378 obj->data.s = strndup(arg ? arg : "%F %T", text_buffer_size);
2380 obj->data.s = strndup(arg ? arg : "%F %T", text_buffer_size);
2382 char buf1[256], buf2[256], *fmt, *tz;
2386 int nArgs = sscanf(arg, "%255s %255[^\n]", buf1, buf2);
2396 obj->data.tztime.fmt = strndup(fmt ? fmt : "%F %T", text_buffer_size);
2397 obj->data.tztime.tz = tz ? strndup(tz, text_buffer_size) : NULL;
2399 END OBJ(iconv_start, 0)
2400 if (iconv_converting) {
2401 CRIT_ERR("You must stop your last iconv conversion before "
2402 "starting another");
2405 char iconv_from[CODEPAGE_LENGTH];
2406 char iconv_to[CODEPAGE_LENGTH];
2408 if (sscanf(arg, "%s %s", iconv_from, iconv_to) != 2) {
2409 CRIT_ERR("Invalid arguments for iconv_start");
2413 new_iconv = iconv_open(iconv_to, iconv_from);
2414 if (new_iconv == (iconv_t) (-1)) {
2415 ERR("Can't convert from %s to %s.", iconv_from, iconv_to);
2417 obj->a = register_iconv(&new_iconv);
2418 iconv_converting = 1;
2422 CRIT_ERR("Iconv requires arguments");
2424 END OBJ(iconv_stop, 0)
2425 iconv_converting = 0;
2428 END OBJ(totaldown, INFO_NET)
2430 obj->data.net = get_net_stat(arg);
2432 // default to DEFAULTNETDEV
2433 char *buf = strndup(DEFAULTNETDEV, text_buffer_size);
2434 obj->data.net = get_net_stat(buf);
2437 END OBJ(totalup, INFO_NET)
2438 obj->data.net = get_net_stat(arg);
2440 obj->data.net = get_net_stat(arg);
2442 // default to DEFAULTNETDEV
2443 char *buf = strndup(DEFAULTNETDEV, text_buffer_size);
2444 obj->data.net = get_net_stat(buf);
2448 END OBJ_IF(if_updatenr, 0)
2449 obj->data.ifblock.i = arg ? atoi(arg) : 0;
2450 if(obj->data.ifblock.i == 0) CRIT_ERR("if_updatenr needs a number above 0 as argument");
2451 updatereset = obj->data.ifblock.i > updatereset ? obj->data.ifblock.i : updatereset;
2453 obj->data.i = arg ? atoi(arg) : 0;
2455 obj->data.i = arg ? atoi(arg) : 0;
2456 END OBJ(upspeed, INFO_NET)
2458 obj->data.net = get_net_stat(arg);
2460 // default to DEFAULTNETDEV
2461 char *buf = strndup(DEFAULTNETDEV, text_buffer_size);
2462 obj->data.net = get_net_stat(buf);
2465 END OBJ(upspeedf, INFO_NET)
2467 obj->data.net = get_net_stat(arg);
2469 // default to DEFAULTNETDEV
2470 char *buf = strndup(DEFAULTNETDEV, text_buffer_size);
2471 obj->data.net = get_net_stat(buf);
2476 END OBJ(upspeedgraph, INFO_NET)
2478 SIZE_DEFAULTS(graph);
2479 buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
2480 &obj->e, &obj->char_a, &obj->char_b);
2482 // default to DEFAULTNETDEV
2483 buf = strndup(buf ? buf : DEFAULTNETDEV, text_buffer_size);
2484 obj->data.net = get_net_stat(buf);
2487 END OBJ(uptime_short, INFO_UPTIME)
2488 END OBJ(uptime, INFO_UPTIME)
2489 END OBJ(user_names, INFO_USERS)
2490 END OBJ(user_times, INFO_USERS)
2491 END OBJ(user_terms, INFO_USERS)
2492 END OBJ(user_number, INFO_USERS)
2493 #if defined(__linux__)
2494 END OBJ(gw_iface, INFO_GW)
2495 END OBJ(gw_ip, INFO_GW)
2496 #endif /* !__linux__ */
2498 END OBJ(adt746xcpu, 0)
2499 END OBJ(adt746xfan, 0)
2500 #endif /* !__OpenBSD__ */
2501 #if (defined(__FreeBSD__) || defined(__FreeBSD_kernel__) \
2502 || defined(__OpenBSD__)) && (defined(i386) || defined(__i386__))
2503 END OBJ(apm_adapter, 0)
2504 END OBJ(apm_battery_life, 0)
2505 END OBJ(apm_battery_time, 0)
2506 #endif /* __FreeBSD__ */
2507 END OBJ_THREAD(imap_unseen, 0)
2510 obj->data.mail = parse_mail_args(IMAP_TYPE, arg);
2515 END OBJ_THREAD(imap_messages, 0)
2518 obj->data.mail = parse_mail_args(IMAP_TYPE, arg);
2523 END OBJ_THREAD(pop3_unseen, 0)
2526 obj->data.mail = parse_mail_args(POP3_TYPE, arg);
2531 END OBJ_THREAD(pop3_used, 0)
2534 obj->data.mail = parse_mail_args(POP3_TYPE, arg);
2542 obj->data.s = strndup(arg, text_buffer_size);
2544 ERR("smapi needs an argument");
2545 END OBJ_IF(if_smapi_bat_installed, 0)
2547 ERR("if_smapi_bat_installed needs an argument");
2548 obj->data.ifblock.s = 0;
2550 obj->data.ifblock.s = strndup(arg, text_buffer_size);
2551 END OBJ(smapi_bat_perc, 0)
2553 obj->data.s = strndup(arg, text_buffer_size);
2555 ERR("smapi_bat_perc needs an argument");
2556 END OBJ(smapi_bat_temp, 0)
2558 obj->data.s = strndup(arg, text_buffer_size);
2560 ERR("smapi_bat_temp needs an argument");
2561 END OBJ(smapi_bat_power, 0)
2563 obj->data.s = strndup(arg, text_buffer_size);
2565 ERR("smapi_bat_power needs an argument");
2567 END OBJ(smapi_bat_bar, 0)
2571 if(sscanf(arg, "%i %n", &obj->data.i, &cnt) <= 0) {
2572 ERR("first argument to smapi_bat_bar must be an integer value");
2576 arg = scan_bar(arg + cnt, &obj->a, &obj->b);
2579 ERR("smapi_bat_bar needs an argument");
2583 #define mpd_set_maxlen(name) \
2586 sscanf(arg, "%d", &i); \
2588 obj->data.i = i + 1; \
2590 ERR(#name ": invalid length argument"); \
2592 END OBJ(mpd_artist, INFO_MPD)
2593 mpd_set_maxlen(mpd_artist);
2595 END OBJ(mpd_title, INFO_MPD)
2596 mpd_set_maxlen(mpd_title);
2598 END OBJ(mpd_random, INFO_MPD) init_mpd();
2599 END OBJ(mpd_repeat, INFO_MPD) init_mpd();
2600 END OBJ(mpd_elapsed, INFO_MPD) init_mpd();
2601 END OBJ(mpd_length, INFO_MPD) init_mpd();
2602 END OBJ(mpd_track, INFO_MPD)
2603 mpd_set_maxlen(mpd_track);
2605 END OBJ(mpd_name, INFO_MPD)
2606 mpd_set_maxlen(mpd_name);
2608 END OBJ(mpd_file, INFO_MPD)
2609 mpd_set_maxlen(mpd_file);
2611 END OBJ(mpd_percent, INFO_MPD) init_mpd();
2612 END OBJ(mpd_album, INFO_MPD)
2613 mpd_set_maxlen(mpd_album);
2615 END OBJ(mpd_vol, INFO_MPD) init_mpd();
2616 END OBJ(mpd_bitrate, INFO_MPD) init_mpd();
2617 END OBJ(mpd_status, INFO_MPD) init_mpd();
2618 END OBJ(mpd_bar, INFO_MPD)
2620 scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
2622 END OBJ(mpd_smart, INFO_MPD)
2623 mpd_set_maxlen(mpd_smart);
2625 END OBJ_IF(if_mpd_playing, INFO_MPD)
2627 #undef mpd_set_maxlen
2630 END OBJ(moc_state, INFO_MOC)
2631 END OBJ(moc_file, INFO_MOC)
2632 END OBJ(moc_title, INFO_MOC)
2633 END OBJ(moc_artist, INFO_MOC)
2634 END OBJ(moc_song, INFO_MOC)
2635 END OBJ(moc_album, INFO_MOC)
2636 END OBJ(moc_totaltime, INFO_MOC)
2637 END OBJ(moc_timeleft, INFO_MOC)
2638 END OBJ(moc_curtime, INFO_MOC)
2639 END OBJ(moc_bitrate, INFO_MOC)
2640 END OBJ(moc_rate, INFO_MOC)
2643 END OBJ(xmms2_artist, INFO_XMMS2)
2644 END OBJ(xmms2_album, INFO_XMMS2)
2645 END OBJ(xmms2_title, INFO_XMMS2)
2646 END OBJ(xmms2_genre, INFO_XMMS2)
2647 END OBJ(xmms2_comment, INFO_XMMS2)
2648 END OBJ(xmms2_url, INFO_XMMS2)
2649 END OBJ(xmms2_tracknr, INFO_XMMS2)
2650 END OBJ(xmms2_bitrate, INFO_XMMS2)
2651 END OBJ(xmms2_date, INFO_XMMS2)
2652 END OBJ(xmms2_id, INFO_XMMS2)
2653 END OBJ(xmms2_duration, INFO_XMMS2)
2654 END OBJ(xmms2_elapsed, INFO_XMMS2)
2655 END OBJ(xmms2_size, INFO_XMMS2)
2656 END OBJ(xmms2_status, INFO_XMMS2)
2657 END OBJ(xmms2_percent, INFO_XMMS2)
2659 END OBJ(xmms2_bar, INFO_XMMS2)
2661 scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
2663 END OBJ(xmms2_smart, INFO_XMMS2)
2664 END OBJ(xmms2_playlist, INFO_XMMS2)
2665 END OBJ(xmms2_timesplayed, INFO_XMMS2)
2666 END OBJ_IF(if_xmms2_connected, INFO_XMMS2)
2669 END OBJ(audacious_status, INFO_AUDACIOUS)
2670 END OBJ(audacious_title, INFO_AUDACIOUS)
2672 sscanf(arg, "%d", &info.audacious.max_title_len);
2673 if (info.audacious.max_title_len > 0) {
2674 info.audacious.max_title_len++;
2676 CRIT_ERR("audacious_title: invalid length argument");
2679 END OBJ(audacious_length, INFO_AUDACIOUS)
2680 END OBJ(audacious_length_seconds, INFO_AUDACIOUS)
2681 END OBJ(audacious_position, INFO_AUDACIOUS)
2682 END OBJ(audacious_position_seconds, INFO_AUDACIOUS)
2683 END OBJ(audacious_bitrate, INFO_AUDACIOUS)
2684 END OBJ(audacious_frequency, INFO_AUDACIOUS)
2685 END OBJ(audacious_channels, INFO_AUDACIOUS)
2686 END OBJ(audacious_filename, INFO_AUDACIOUS)
2687 END OBJ(audacious_playlist_length, INFO_AUDACIOUS)
2688 END OBJ(audacious_playlist_position, INFO_AUDACIOUS)
2689 END OBJ(audacious_main_volume, INFO_AUDACIOUS)
2691 END OBJ(audacious_bar, INFO_AUDACIOUS)
2693 scan_bar(arg, &obj->a, &obj->b);
2697 END OBJ(bmpx_title, INFO_BMPX)
2698 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
2699 END OBJ(bmpx_artist, INFO_BMPX)
2700 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
2701 END OBJ(bmpx_album, INFO_BMPX)
2702 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
2703 END OBJ(bmpx_track, INFO_BMPX)
2704 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
2705 END OBJ(bmpx_uri, INFO_BMPX)
2706 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
2707 END OBJ(bmpx_bitrate, INFO_BMPX)
2708 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
2714 char *userid = (char *) malloc(20 * sizeof(char));
2715 char *apikey = (char *) malloc(64 * sizeof(char));
2716 char *charid = (char *) malloc(20 * sizeof(char));
2718 argc = sscanf(arg, "%20s %64s %20s", userid, apikey, charid);
2719 obj->data.eve.charid = charid;
2720 obj->data.eve.userid = userid;
2721 obj->data.eve.apikey = apikey;
2725 CRIT_ERR("eve needs arguments: <userid> <apikey> <characterid>");
2731 int argc, delay, act_par;
2732 unsigned int nrspaces = 0;
2733 char *uri = (char *) malloc(128 * sizeof(char));
2734 char *action = (char *) malloc(64 * sizeof(char));
2736 argc = sscanf(arg, "%127s %d %63s %d %u", uri, &delay, action,
2737 &act_par, &nrspaces);
2738 obj->data.rss.uri = uri;
2739 obj->data.rss.delay = delay;
2740 obj->data.rss.action = action;
2741 obj->data.rss.act_par = act_par;
2742 obj->data.rss.nrspaces = nrspaces;
2746 CRIT_ERR("rss needs arguments: <uri> <delay in minutes> <action> "
2747 "[act_par] [spaces in front]");
2753 obj->data.s = strndup(arg, text_buffer_size);
2755 CRIT_ERR("lua needs arguments: <function name> [function parameters]");
2757 END OBJ(lua_parse, 0)
2759 obj->data.s = strndup(arg, text_buffer_size);
2761 CRIT_ERR("lua_parse needs arguments: <function name> [function parameters]");
2763 END OBJ(lua_read_parse, 0)
2765 obj->data.s = strndup(arg, text_buffer_size);
2767 CRIT_ERR("lua_read_parse needs arguments: <function name> <string to pass>");
2772 arg = scan_bar(arg, &obj->a, &obj->b);
2774 obj->data.s = strndup(arg, text_buffer_size);
2776 CRIT_ERR("lua_bar needs arguments: <height>,<width> <function name> [function parameters]");
2779 CRIT_ERR("lua_bar needs arguments: <height>,<width> <function name> [function parameters]");
2782 END OBJ(lua_graph, 0)
2783 SIZE_DEFAULTS(graph);
2785 arg = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
2786 &obj->e, &obj->char_a, &obj->char_b);
2788 obj->data.s = strndup(arg, text_buffer_size);
2790 CRIT_ERR("lua_graph needs arguments: <\"normal\"|\"log\"> <height>,<width> <gradient colour 1> <gradient colour 2> <scale> <function name> [function parameters]");
2793 CRIT_ERR("lua_graph needs arguments: <\"normal\"|\"log\"> <height>,<width> <gradient colour 1> <gradient colour 2> <scale> <function name> [function parameters]");
2795 END OBJ(lua_gauge, 0)
2796 SIZE_DEFAULTS(gauge);
2798 arg = scan_gauge(arg, &obj->a, &obj->b);
2800 obj->data.s = strndup(arg, text_buffer_size);
2802 CRIT_ERR("lua_gauge needs arguments: <height>,<width> <function name> [function parameters]");
2805 CRIT_ERR("lua_gauge needs arguments: <height>,<width> <function name> [function parameters]");
2808 #endif /* HAVE_LUA */
2811 if (scan_hddtemp(arg, &obj->data.hddtemp.dev,
2812 &obj->data.hddtemp.addr, &obj->data.hddtemp.port)) {
2813 ERR("hddtemp needs arguments");
2814 obj->type = OBJ_text;
2815 obj->data.s = strndup("${hddtemp}", text_buffer_size);
2816 obj->data.hddtemp.update_time = 0;
2818 obj->data.hddtemp.temp = NULL;
2819 #endif /* HDDTEMP */
2820 #ifdef TCP_PORT_MONITOR
2821 END OBJ(tcp_portmon, INFO_TCP_PORT_MONITOR)
2822 tcp_portmon_init(arg, &obj->data.tcp_port_monitor);
2823 #endif /* TCP_PORT_MONITOR */
2824 END OBJ(entropy_avail, INFO_ENTROPY)
2825 END OBJ(entropy_perc, INFO_ENTROPY)
2826 END OBJ(entropy_poolsize, INFO_ENTROPY)
2827 END OBJ(entropy_bar, INFO_ENTROPY)
2829 scan_bar(arg, &obj->a, &obj->b);
2833 obj->data.scroll.step = 1;
2834 if (arg && sscanf(arg, "%u %n", &obj->data.scroll.show, &n1) > 0) {
2835 if (sscanf(arg + n1, "%u %n", &obj->data.scroll.step, &n2) > 0)
2837 obj->data.scroll.text = strndup(arg + n1, text_buffer_size);
2838 obj->data.scroll.start = 0;
2839 obj->sub = malloc(sizeof(struct text_object));
2840 extract_variable_text_internal(obj->sub,
2841 obj->data.scroll.text, 0);
2843 CRIT_ERR("scroll needs arguments: <length> [<step>] <text>");
2848 unsigned int indenting = 0; //vars can be used as args for other vars
2851 startvar[0] = endvar[0] = startvar[1] = endvar[1] = -1;
2853 for (i=0; arg[i] != 0 && j < 2; i++) {
2854 if(startvar[j] == -1) {
2858 }else if(endvar[j] == -1) {
2861 }else if(arg[i] == '}') {
2864 if (indenting == 0 && arg[i+1] < 48) { //<48 has 0, $, and the most used chars not used in varnames but not { or }
2870 if(startvar[0] >= 0 && endvar[0] >= 0 && startvar[1] >= 0 && endvar[1] >= 0) {
2871 obj->data.combine.left = malloc(endvar[0]-startvar[0] + 1);
2872 obj->data.combine.seperation = malloc(startvar[1] - endvar[0] + 1);
2873 obj->data.combine.right= malloc(endvar[1]-startvar[1] + 1);
2875 strncpy(obj->data.combine.left, arg + startvar[0], endvar[0] - startvar[0]);
2876 obj->data.combine.left[endvar[0] - startvar[0]] = 0;
2878 strncpy(obj->data.combine.seperation, arg + endvar[0], startvar[1] - endvar[0]);
2879 obj->data.combine.seperation[startvar[1] - endvar[0]] = 0;
2881 strncpy(obj->data.combine.right, arg + startvar[1], endvar[1] - startvar[1]);
2882 obj->data.combine.right[endvar[1] - startvar[1]] = 0;
2884 obj->sub = malloc(sizeof(struct text_object));
2885 extract_variable_text_internal(obj->sub, obj->data.combine.left, 0);
2886 obj->sub->sub = malloc(sizeof(struct text_object));
2887 extract_variable_text_internal(obj->sub->sub, obj->data.combine.right, 0);
2889 CRIT_ERR("combine needs arguments: <text1> <text2>");
2892 CRIT_ERR("combine needs arguments: <text1> <text2>");
2897 CRIT_ERR("nvidia needs an argument\n");
2898 } else if (set_nvidia_type(&obj->data.nvidia, arg)) {
2899 CRIT_ERR("nvidia: invalid argument"
2900 " specified: '%s'\n", arg);
2905 END OBJ(apcupsd, INFO_APCUPSD)
2909 if (sscanf(arg, "%63s %d", host, &port) != 2) {
2910 CRIT_ERR("apcupsd needs arguments: <host> <port>");
2912 info.apcupsd.port = htons(port);
2913 strncpy(info.apcupsd.host, host, sizeof(info.apcupsd.host));
2916 CRIT_ERR("apcupsd needs arguments: <host> <port>");
2918 END OBJ(apcupsd_name, INFO_APCUPSD)
2919 END OBJ(apcupsd_model, INFO_APCUPSD)
2920 END OBJ(apcupsd_upsmode, INFO_APCUPSD)
2921 END OBJ(apcupsd_cable, INFO_APCUPSD)
2922 END OBJ(apcupsd_status, INFO_APCUPSD)
2923 END OBJ(apcupsd_linev, INFO_APCUPSD)
2924 END OBJ(apcupsd_load, INFO_APCUPSD)
2925 END OBJ(apcupsd_loadbar, INFO_APCUPSD)
2927 scan_bar(arg, &obj->a, &obj->b);
2929 END OBJ(apcupsd_loadgraph, INFO_APCUPSD)
2931 SIZE_DEFAULTS(graph);
2932 buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
2933 &obj->e, &obj->char_a, &obj->char_b);
2935 END OBJ(apcupsd_loadgauge, INFO_APCUPSD)
2936 SIZE_DEFAULTS(gauge);
2937 scan_gauge(arg, &obj->a, &obj->b);
2939 END OBJ(apcupsd_charge, INFO_APCUPSD)
2940 END OBJ(apcupsd_timeleft, INFO_APCUPSD)
2941 END OBJ(apcupsd_temp, INFO_APCUPSD)
2942 END OBJ(apcupsd_lastxfer, INFO_APCUPSD)
2943 #endif /* APCUPSD */
2947 ERR("unknown variable %s", s);
2948 obj->type = OBJ_text;
2949 snprintf(buf, 256, "${%s}", s);
2950 obj->data.s = strndup(buf, text_buffer_size);
2957 static struct text_object *create_plain_text(const char *s)
2959 struct text_object *obj;
2961 if (s == NULL || *s == '\0') {
2965 obj = new_text_object_internal();
2967 obj->type = OBJ_text;
2968 obj->data.s = strndup(s, text_buffer_size);
2972 /* backslash_escape - do the actual substitution task for template objects
2974 * The field templates is used for substituting the \N occurences. Set it to
2975 * NULL to leave them as they are.
2977 static char *backslash_escape(const char *src, char **templates, unsigned int template_count)
2981 unsigned int dup_idx = 0, dup_len;
2983 dup_len = strlen(src) + 1;
2984 src_dup = malloc(dup_len * sizeof(char));
2992 if (*(p + 1) == '\\') {
2993 src_dup[dup_idx++] = '\\';
2995 } else if (*(p + 1) == ' ') {
2996 src_dup[dup_idx++] = ' ';
2998 } else if (*(p + 1) == 'n') {
2999 src_dup[dup_idx++] = '\n';
3001 } else if (templates) {
3002 unsigned int tmpl_num;
3004 if ((sscanf(p + 1, "%u%n", &tmpl_num, &digits) <= 0) ||
3005 (tmpl_num > template_count))
3007 dup_len += strlen(templates[tmpl_num - 1]);
3008 src_dup = realloc(src_dup, dup_len * sizeof(char));
3009 sprintf(src_dup + dup_idx, "%s", templates[tmpl_num - 1]);
3010 dup_idx += strlen(templates[tmpl_num - 1]);
3015 src_dup[dup_idx++] = *p;
3020 src_dup[dup_idx] = '\0';
3021 src_dup = realloc(src_dup, (strlen(src_dup) + 1) * sizeof(char));
3025 /* handle_template_object - core logic of the template object
3027 * use config variables like this:
3028 * template1 = "$\1\2"
3029 * template2 = "\1: ${fs_bar 4,100 \2} ${fs_used \2} / ${fs_size \2}"
3031 * and use them like this:
3032 * ${template1 node name}
3033 * ${template2 root /}
3034 * ${template2 cdrom /mnt/cdrom}
3036 static char *handle_template(const char *tmpl, const char *args)
3038 char *args_dup = NULL;
3040 char **argsp = NULL;
3041 unsigned int argcnt = 0, template_idx, i;
3044 if ((sscanf(tmpl, "template%u", &template_idx) != 1) ||
3045 (template_idx >= MAX_TEMPLATES))
3049 args_dup = strdup(args);
3052 while (*p && (*p == ' ' && (p == args_dup || *(p - 1) != '\\')))
3054 if (p > args_dup && *(p - 1) == '\\')
3057 while (*p && (*p != ' ' || (p > args_dup && *(p - 1) == '\\')))
3063 argsp = realloc(argsp, ++argcnt * sizeof(char *));
3064 argsp[argcnt - 1] = p_old;
3066 for (i = 0; i < argcnt; i++) {
3068 tmp = backslash_escape(argsp[i], NULL, 0);
3069 DBGP2("%s: substituted arg '%s' to '%s'", tmpl, argsp[i], tmp);
3074 eval_text = backslash_escape(template[template_idx], argsp, argcnt);
3075 DBGP("substituted %s, output is '%s'", tmpl, eval_text);
3077 for (i = 0; i < argcnt; i++)
3083 static char *find_and_replace_templates(const char *inbuf)
3085 char *outbuf, *indup, *p, *o, *templ, *args, *tmpl_out;
3088 outlen = strlen(inbuf) + 1;
3089 o = outbuf = calloc(outlen, sizeof(char));
3090 memset(outbuf, 0, outlen * sizeof(char));
3092 p = indup = strdup(inbuf);
3094 while (*p && *p != '$')
3100 if (strncmp(p, "$template", 9) && strncmp(p, "${template", 10)) {
3105 if (*(p + 1) == '{') {
3108 while (*p && !isspace(*p) && *p != '{' && *p != '}')
3116 while (*p && stack > 0) {
3124 // stack is empty. that means the previous char was }, so we zero it
3127 // we ran into the end of string without finding a closing }, bark
3128 CRIT_ERR("cannot find a closing '}' in template expansion");
3132 while (*p && !isspace(*p))
3136 tmpl_out = handle_template(templ, args);
3138 outlen += strlen(tmpl_out);
3140 outbuf = realloc(outbuf, outlen * sizeof(char));
3141 strcat (outbuf, tmpl_out);
3143 o = outbuf + strlen(outbuf);
3145 ERR("failed to handle template '%s' with args '%s'", templ, args);
3149 outbuf = realloc(outbuf, (strlen(outbuf) + 1) * sizeof(char));
3154 static int text_contains_templates(const char *text)
3156 if (strcasestr(text, "${template") != NULL)
3158 if (strcasestr(text, "$template") != NULL)
3163 static void strfold(char *start, int count)
3166 for (curplace = start + count; *curplace != 0; curplace++) {
3167 *(curplace - count) = *curplace;
3169 *(curplace - count) = 0;
3173 * - assumes that *string is '#'
3174 * - removes the part from '#' to the end of line ('\n' or '\0')
3175 * - BUT, it leaves the '\n'
3177 static size_t remove_comment(char *string)
3180 while(*end != '\0' && *end != '\n')
3182 strfold(string, end - string);
3183 return end - string;
3186 static size_t remove_comments(char *string)
3190 for (curplace = string; *curplace != 0; curplace++) {
3191 if (*curplace == '\\' && *(curplace + 1) == '#') {
3192 // strcpy can't be used for overlapping strings
3193 strfold(curplace, 1);
3195 } else if (*curplace == '#') {
3196 folded += remove_comment(curplace);
3202 static int extract_variable_text_internal(struct text_object *retval, const char *const_p, char allow_threaded)
3204 struct text_object *obj;
3205 char *p, *s, *orig_p;
3207 void *ifblock_opaque = NULL;
3212 p = strndup(const_p, max_user_text - 1);
3213 while (text_contains_templates(p)) {
3215 tmp = find_and_replace_templates(p);
3221 if (strcmp(p, const_p)) {
3222 DBGP("replaced all templates in text: input is\n'%s'\noutput is\n'%s'", const_p, p);
3224 DBGP("no templates to replace");
3227 memset(retval, 0, sizeof(struct text_object));
3229 line = global_text_lines;
3237 obj = create_plain_text(s);
3239 append_object(retval, obj);
3249 /* variable is either $foo or ${foo} */
3251 unsigned int brl = 1, brr = 0;
3255 while (*p && brl != brr) {
3270 while (*p && (isalnum((int) *p) || *p == '_')) {
3275 /* copy variable to buffer */
3276 len = (p - s > 255) ? 255 : (p - s);
3277 strncpy(buf, s, len);
3285 /* search for variable in environment */
3289 obj = create_plain_text(var);
3291 append_object(retval, obj);
3296 /* if variable wasn't found in environment, use some special */
3301 if (strchr(buf, ' ')) {
3302 arg = strchr(buf, ' ');
3305 while (isspace((int) *arg)) {
3313 /* lowercase variable name */
3316 *tmp_p = tolower(*tmp_p);
3320 obj = construct_text_object(buf, arg,
3321 line, allow_threaded,
3324 append_object(retval, obj);
3328 obj = create_plain_text("$");
3331 append_object(retval, obj);
3334 } else if (*p == '#') {
3339 obj = create_plain_text(s);
3341 append_object(retval, obj);
3344 if (!ifblock_stack_empty(&ifblock_opaque)) {
3345 ERR("one or more $endif's are missing");
3352 static void extract_variable_text(const char *p)
3354 free_text_objects(&global_root_object, 0);
3368 extract_variable_text_internal(&global_root_object, p, 1);
3371 int parse_conky_vars(struct text_object *root, char *txt, char *p, struct information *cur)
3373 extract_variable_text_internal(root, txt, 0);
3374 generate_text_internal(p, max_user_text, *root, cur);
3378 static inline struct mail_s *ensure_mail_thread(struct text_object *obj,
3379 void *thread(void *), const char *text)
3381 if (obj->char_b && info.mail) {
3382 // this means we use info
3383 if (!info.mail->p_timed_thread) {
3384 info.mail->p_timed_thread =
3385 timed_thread_create(thread,
3386 (void *) info.mail, info.mail->interval * 1000000);
3387 if (!info.mail->p_timed_thread) {
3388 ERR("Error creating %s timed thread", text);
3390 timed_thread_register(info.mail->p_timed_thread,
3391 &info.mail->p_timed_thread);
3392 if (timed_thread_run(info.mail->p_timed_thread)) {
3393 ERR("Error running %s timed thread", text);
3397 } else if (obj->data.mail) {
3398 // this means we use obj
3399 if (!obj->data.mail->p_timed_thread) {
3400 obj->data.mail->p_timed_thread =
3401 timed_thread_create(thread,
3402 (void *) obj->data.mail,
3403 obj->data.mail->interval * 1000000);
3404 if (!obj->data.mail->p_timed_thread) {
3405 ERR("Error creating %s timed thread", text);
3407 timed_thread_register(obj->data.mail->p_timed_thread,
3408 &obj->data.mail->p_timed_thread);
3409 if (timed_thread_run(obj->data.mail->p_timed_thread)) {
3410 ERR("Error running %s timed thread", text);
3413 return obj->data.mail;
3414 } else if (!obj->a) {
3415 // something is wrong, warn once then stop
3416 ERR("There's a problem with your mail settings. "
3417 "Check that the global mail settings are properly defined"
3418 " (line %li).", obj->line);
3424 char *format_time(unsigned long timeval, const int width)
3427 unsigned long nt; // narrow time, for speed on 32-bit
3428 unsigned cc; // centiseconds
3429 unsigned nn; // multi-purpose whatever
3432 cc = nt % 100; // centiseconds past second
3433 nt /= 100; // total seconds
3434 nn = nt % 60; // seconds past the minute
3435 nt /= 60; // total minutes
3436 if (width >= snprintf(buf, sizeof buf, "%lu:%02u.%02u",
3438 return strndup(buf, text_buffer_size);
3440 if (width >= snprintf(buf, sizeof buf, "%lu:%02u", nt, nn)) {
3441 return strndup(buf, text_buffer_size);
3443 nn = nt % 60; // minutes past the hour
3444 nt /= 60; // total hours
3445 if (width >= snprintf(buf, sizeof buf, "%lu,%02u", nt, nn)) {
3446 return strndup(buf, text_buffer_size);
3448 nn = nt; // now also hours
3449 if (width >= snprintf(buf, sizeof buf, "%uh", nn)) {
3450 return strndup(buf, text_buffer_size);
3452 nn /= 24; // now days
3453 if (width >= snprintf(buf, sizeof buf, "%ud", nn)) {
3454 return strndup(buf, text_buffer_size);
3456 nn /= 7; // now weeks
3457 if (width >= snprintf(buf, sizeof buf, "%uw", nn)) {
3458 return strndup(buf, text_buffer_size);
3460 // well shoot, this outta' fit...
3461 return strndup("<inf>", text_buffer_size);
3464 //remove backspaced chars, example: "dog^H^H^Hcat" becomes "cat"
3465 //string has to end with \0 and it's length should fit in a int
3467 void remove_deleted_chars(char *string){
3469 while(string[i] != 0){
3470 if(string[i] == BACKSPACE){
3472 strcpy( &(string[i-1]), &(string[i+1]) );
3474 }else strcpy( &(string[i]), &(string[i+1]) ); //necessary for ^H's at the start of a string
3479 static inline void format_media_player_time(char *buf, const int size,
3482 int days, hours, minutes;
3484 days = seconds / (24 * 60 * 60);
3485 seconds %= (24 * 60 * 60);
3486 hours = seconds / (60 * 60);
3487 seconds %= (60 * 60);
3488 minutes = seconds / 60;
3492 snprintf(buf, size, "%i days %i:%02i:%02i", days,
3493 hours, minutes, seconds);
3494 } else if (hours > 0) {
3495 snprintf(buf, size, "%i:%02i:%02i", hours, minutes,
3498 snprintf(buf, size, "%i:%02i", minutes, seconds);
3502 static inline double get_barnum(char *buf)
3514 if (sscanf(buf, "%lf", &barnum) == 0) {
3515 ERR("reading exec value failed (perhaps it's not the "
3516 "correct format?)");
3519 if (barnum > 100.0 || barnum < 0.0) {
3520 ERR("your exec value is not between 0 and 100, "
3521 "therefore it will be ignored");
3527 static void generate_text_internal(char *p, int p_max_size,
3528 struct text_object root, struct information *cur)
3530 struct text_object *obj;
3532 int need_to_load_fonts = 0;
3535 /* for the OBJ_top* handler */
3536 struct process **needed = 0;
3539 char buff_in[p_max_size];
3541 iconv_converting = 0;
3542 #endif /* HAVE_ICONV */
3546 while (obj && p_max_size > 0) {
3547 needed = 0; // reset for top stuff
3549 /* IFBLOCK jumping algorithm
3551 * This is easier as it looks like:
3552 * - each IF checks it's condition
3553 * - on FALSE: call DO_JUMP
3554 * - on TRUE: don't care
3555 * - each ELSE calls DO_JUMP unconditionally
3556 * - each ENDIF is silently being ignored
3559 * DO_JUMP overwrites the "obj" variable of the loop and sets it to the target
3560 * (i.e. the corresponding ELSE or ENDIF). After that, processing for the given
3561 * object can continue, free()ing stuff e.g., then the for-loop does the rest: as
3562 * regularly, "obj" is being updated to point to obj->next, so object parsing
3563 * continues right after the corresponding ELSE or ENDIF. This means that if we
3564 * find an ELSE, it's corresponding IF must not have jumped, so we need to jump
3565 * always. If we encounter an ENDIF, it's corresponding IF or ELSE has not
3566 * jumped, and there is nothing to do.
3570 obj = obj->data.ifblock.next; \
3573 #define OBJ(a) break; case OBJ_##a:
3575 switch (obj->type) {
3577 ERR("not implemented obj type %d", obj->type);
3580 struct sockaddr_in addr;
3581 struct hostent* he = gethostbyname(obj->data.read_tcp.host);
3583 sock = socket(he->h_addrtype, SOCK_STREAM, 0);
3585 memset(&addr, 0, sizeof(addr));
3586 addr.sin_family = AF_INET;
3587 addr.sin_port = obj->data.read_tcp.port;
3588 memcpy(&addr.sin_addr, he->h_addr, he->h_length);
3589 if (connect(sock, (struct sockaddr*)&addr, sizeof(struct sockaddr)) == 0) {
3593 FD_SET(sock, &readfds);
3596 if(select(sock + 1, &readfds, NULL, NULL, &tv) > 0){
3597 received = recv(sock, p, p_max_size, 0);
3602 ERR("read_tcp: Couldn't create a connection");
3605 ERR("read_tcp: Couldn't create a socket");
3608 ERR("read_tcp: Problem with resolving the hostname");
3613 temp_print(p, p_max_size, get_acpi_temperature(obj->data.i), TEMP_CELSIUS);
3615 #endif /* !__OpenBSD__ */
3618 obj->a = get_freq(p, p_max_size, "%.0f", 1,
3619 obj->data.cpu_index);
3625 obj->a = get_freq(p, p_max_size, "%'.2f", 1000,
3626 obj->data.cpu_index);
3628 /* OpenBSD has no such flag (SUSv2) */
3629 obj->a = get_freq(p, p_max_size, "%.2f", 1000,
3630 obj->data.cpu_index);
3631 #endif /* __OpenBSD */
3634 #if defined(__linux__)
3637 obj->a = get_voltage(p, p_max_size, "%.0f", 1,
3638 obj->data.cpu_index);
3643 obj->a = get_voltage(p, p_max_size, "%'.3f", 1000,
3644 obj->data.cpu_index);
3649 OBJ(wireless_essid) {
3650 snprintf(p, p_max_size, "%s", obj->data.net->essid);
3652 OBJ(wireless_mode) {
3653 snprintf(p, p_max_size, "%s", obj->data.net->mode);
3655 OBJ(wireless_bitrate) {
3656 snprintf(p, p_max_size, "%s", obj->data.net->bitrate);
3659 snprintf(p, p_max_size, "%s", obj->data.net->ap);
3661 OBJ(wireless_link_qual) {
3662 spaced_print(p, p_max_size, "%d", 4,
3663 obj->data.net->link_qual);
3665 OBJ(wireless_link_qual_max) {
3666 spaced_print(p, p_max_size, "%d", 4,
3667 obj->data.net->link_qual_max);
3669 OBJ(wireless_link_qual_perc) {
3670 if (obj->data.net->link_qual_max > 0) {
3671 spaced_print(p, p_max_size, "%.0f", 5,
3672 (double) obj->data.net->link_qual /
3673 obj->data.net->link_qual_max * 100);
3675 spaced_print(p, p_max_size, "unk", 5);
3678 OBJ(wireless_link_bar) {
3680 if(output_methods & TO_X) {
3681 new_bar(p, obj->a, obj->b, ((double) obj->data.net->link_qual /
3682 obj->data.net->link_qual_max) * 255.0);
3685 if(!obj->a) obj->a = DEFAULT_BAR_WIDTH_NO_X;
3686 new_bar_in_shell(p, p_max_size, ((double) obj->data.net->link_qual /
3687 obj->data.net->link_qual_max) * 100.0, obj->a);
3692 #endif /* HAVE_IWLIB */
3694 #endif /* __linux__ */
3698 get_adt746x_cpu(p, p_max_size);
3701 get_adt746x_fan(p, p_max_size);
3704 get_acpi_fan(p, p_max_size);
3706 OBJ(acpiacadapter) {
3707 get_acpi_ac_adapter(p, p_max_size);
3710 get_battery_stuff(p, p_max_size, obj->data.s, BATTERY_STATUS);
3713 get_battery_stuff(p, p_max_size, obj->data.s, BATTERY_TIME);
3715 OBJ(battery_percent) {
3716 percent_print(p, p_max_size, get_battery_perct(obj->data.s));
3720 if(output_methods & TO_X) {
3721 new_bar(p, obj->a, obj->b, get_battery_perct_bar(obj->data.s));
3724 if(!obj->a) obj->a = DEFAULT_BAR_WIDTH_NO_X;
3725 new_bar_in_shell(p, p_max_size, get_battery_perct_bar(obj->data.s) / 2.55, obj->a);
3730 OBJ(battery_short) {
3731 get_battery_short_status(p, p_max_size, obj->data.s);
3733 #endif /* __OpenBSD__ */
3736 human_readable(cur->buffers * 1024, p, 255);
3739 human_readable(cur->cached * 1024, p, 255);
3742 if (obj->data.cpu_index > info.cpu_count) {
3743 ERR("obj->data.cpu_index %i info.cpu_count %i",
3744 obj->data.cpu_index, info.cpu_count);
3745 CRIT_ERR("attempting to use more CPUs than you have!");
3747 percent_print(p, p_max_size,
3748 round_to_int(cur->cpu_usage[obj->data.cpu_index] * 100.0));
3752 new_gauge(p, obj->a, obj->b,
3753 round_to_int(cur->cpu_usage[obj->data.cpu_index] * 255.0));
3757 if(output_methods & TO_X) {
3758 new_bar(p, obj->a, obj->b,
3759 round_to_int(cur->cpu_usage[obj->data.cpu_index] * 255.0));
3762 if(!obj->a) obj->a = DEFAULT_BAR_WIDTH_NO_X;
3763 new_bar_in_shell(p, p_max_size, round_to_int(cur->cpu_usage[obj->data.cpu_index] * 100), obj->a);
3770 new_graph(p, obj->a, obj->b, obj->c, obj->d,
3771 round_to_int(cur->cpu_usage[obj->data.cpu_index] * 100),
3772 100, 1, obj->char_a, obj->char_b);
3775 new_graph(p, obj->a, obj->b, obj->c, obj->d, cur->loadavg[0],
3776 obj->e, 1, obj->char_a, obj->char_b);
3779 new_fg(p, obj->data.l);
3812 OBJ(conky_version) {
3813 snprintf(p, p_max_size, "%s", VERSION);
3815 OBJ(conky_build_date) {
3816 snprintf(p, p_max_size, "%s", BUILD_DATE);
3818 OBJ(conky_build_arch) {
3819 snprintf(p, p_max_size, "%s", BUILD_ARCH);
3821 #if defined(__linux__)
3823 snprintf(p, p_max_size, "%s",
3824 get_disk_protect_queue(obj->data.s));
3827 snprintf(p, p_max_size, "%s", i8k.version);
3830 snprintf(p, p_max_size, "%s", i8k.bios);
3833 snprintf(p, p_max_size, "%s", i8k.serial);
3838 sscanf(i8k.cpu_temp, "%d", &cpu_temp);
3839 temp_print(p, p_max_size, (double)cpu_temp, TEMP_CELSIUS);
3841 OBJ(i8k_left_fan_status) {
3842 int left_fan_status;
3844 sscanf(i8k.left_fan_status, "%d", &left_fan_status);
3845 if (left_fan_status == 0) {
3846 snprintf(p, p_max_size, "off");
3848 if (left_fan_status == 1) {
3849 snprintf(p, p_max_size, "low");
3851 if (left_fan_status == 2) {
3852 snprintf(p, p_max_size, "high");
3855 OBJ(i8k_right_fan_status) {
3856 int right_fan_status;
3858 sscanf(i8k.right_fan_status, "%d", &right_fan_status);
3859 if (right_fan_status == 0) {
3860 snprintf(p, p_max_size, "off");
3862 if (right_fan_status == 1) {
3863 snprintf(p, p_max_size, "low");
3865 if (right_fan_status == 2) {
3866 snprintf(p, p_max_size, "high");
3869 OBJ(i8k_left_fan_rpm) {
3870 snprintf(p, p_max_size, "%s", i8k.left_fan_rpm);
3872 OBJ(i8k_right_fan_rpm) {
3873 snprintf(p, p_max_size, "%s", i8k.right_fan_rpm);
3875 OBJ(i8k_ac_status) {
3878 sscanf(i8k.ac_status, "%d", &ac_status);
3879 if (ac_status == -1) {
3880 snprintf(p, p_max_size, "disabled (read i8k docs)");
3882 if (ac_status == 0) {
3883 snprintf(p, p_max_size, "off");
3885 if (ac_status == 1) {
3886 snprintf(p, p_max_size, "on");
3889 OBJ(i8k_buttons_status) {
3890 snprintf(p, p_max_size, "%s", i8k.buttons_status);
3894 get_ibm_acpi_fan(p, p_max_size);
3897 get_ibm_acpi_temps();
3898 temp_print(p, p_max_size,
3899 ibm_acpi.temps[obj->data.sensor], TEMP_CELSIUS);
3902 get_ibm_acpi_volume(p, p_max_size);
3904 OBJ(ibm_brightness) {
3905 get_ibm_acpi_brightness(p, p_max_size);
3908 /* information from sony_laptop kernel module
3909 * /sys/devices/platform/sony-laptop */
3910 OBJ(sony_fanspeed) {
3911 get_sony_fanspeed(p, p_max_size);
3914 if (!cur->gw_info.count) {
3919 snprintf(p, p_max_size, "%s", cur->gw_info.iface);
3922 snprintf(p, p_max_size, "%s", cur->gw_info.ip);
3925 snprintf(p, p_max_size, "%d", get_laptop_mode());
3928 get_powerbook_batt_info(p, p_max_size, obj->data.i);
3930 #endif /* __linux__ */
3931 #if (defined(__FreeBSD__) || defined(__linux__))
3933 if ((obj->data.ifblock.s)
3934 && (!interface_up(obj->data.ifblock.s))) {
3940 OBJ(obsd_sensors_temp) {
3941 obsd_sensors.device = sensor_device;
3942 update_obsd_sensors();
3943 temp_print(p, p_max_size,
3944 obsd_sensors.temp[obsd_sensors.device][obj->data.sensor],
3947 OBJ(obsd_sensors_fan) {
3948 obsd_sensors.device = sensor_device;
3949 update_obsd_sensors();
3950 snprintf(p, p_max_size, "%d",
3951 obsd_sensors.fan[obsd_sensors.device][obj->data.sensor]);
3953 OBJ(obsd_sensors_volt) {
3954 obsd_sensors.device = sensor_device;
3955 update_obsd_sensors();
3956 snprintf(p, p_max_size, "%.2f",
3957 obsd_sensors.volt[obsd_sensors.device][obj->data.sensor]);
3960 get_obsd_vendor(p, p_max_size);
3963 get_obsd_product(p, p_max_size);
3965 #endif /* __OpenBSD__ */
3968 new_font(p, obj->data.s);
3969 need_to_load_fonts = 1;
3972 /* TODO: move this correction from kB to kB/s elsewhere
3973 * (or get rid of it??) */
3975 human_readable((obj->data.diskio->current / update_interval) * 1024LL,
3979 human_readable((obj->data.diskio->current_write / update_interval) * 1024LL,
3983 human_readable((obj->data.diskio->current_read / update_interval) * 1024LL,
3988 new_graph(p, obj->a, obj->b, obj->c, obj->d,
3989 obj->data.diskio->current, obj->e, 1, obj->char_a, obj->char_b);
3991 OBJ(diskiograph_read) {
3992 new_graph(p, obj->a, obj->b, obj->c, obj->d,
3993 obj->data.diskio->current_read, obj->e, 1, obj->char_a, obj->char_b);
3995 OBJ(diskiograph_write) {
3996 new_graph(p, obj->a, obj->b, obj->c, obj->d,
3997 obj->data.diskio->current_write, obj->e, 1, obj->char_a, obj->char_b);
4001 human_readable(obj->data.net->recv_speed, p, 255);
4004 spaced_print(p, p_max_size, "%.1f", 8,
4005 obj->data.net->recv_speed / 1024.0);
4008 OBJ(downspeedgraph) {
4009 new_graph(p, obj->a, obj->b, obj->c, obj->d,
4010 obj->data.net->recv_speed / 1024.0, obj->e, 1, obj->char_a, obj->char_b);
4014 /* Since we see you, you're if has not jumped.
4015 * Do Ninja jump here: without leaving traces.
4016 * This is to prevent us from stale jumped flags.
4018 obj = obj->data.ifblock.next;
4022 /* harmless object, just ignore */
4026 if ((obj->data.net->addr.sa_data[2] & 255) == 0
4027 && (obj->data.net->addr.sa_data[3] & 255) == 0
4028 && (obj->data.net->addr.sa_data[4] & 255) == 0
4029 && (obj->data.net->addr.sa_data[5] & 255) == 0) {
4030 snprintf(p, p_max_size, "No Address");
4032 snprintf(p, p_max_size, "%u.%u.%u.%u",
4033 obj->data.net->addr.sa_data[2] & 255,
4034 obj->data.net->addr.sa_data[3] & 255,
4035 obj->data.net->addr.sa_data[4] & 255,
4036 obj->data.net->addr.sa_data[5] & 255);
4039 #if defined(__linux__)
4041 if(NULL != obj->data.net->addrs && strlen(obj->data.net->addrs) > 2)
4043 obj->data.net->addrs[strlen(obj->data.net->addrs) - 2] = 0; /* remove ", " from end of string */
4044 strcpy(p, obj->data.net->addrs);
4047 strcpy(p, "0.0.0.0");
4049 #endif /* __linux__ */
4050 #if defined(IMLIB2) && defined(X11)
4052 /* doesn't actually draw anything, just queues it omp. the
4053 * image will get drawn after the X event loop */
4054 cimlib_add_image(obj->data.s);
4058 struct information *tmp_info;
4059 struct text_object subroot, subroot2;
4061 tmp_info = malloc(sizeof(struct information));
4062 memcpy(tmp_info, cur, sizeof(struct information));
4063 parse_conky_vars(&subroot, obj->data.s, p, tmp_info);
4064 DBGP("evaluated '%s' to '%s'", obj->data.s, p);
4065 parse_conky_vars(&subroot2, p, p, tmp_info);
4067 free_text_objects(&subroot, 1);
4068 free_text_objects(&subroot2, 1);
4072 read_exec(obj->data.s, p, text_buffer_size);
4073 remove_deleted_chars(p);
4076 struct information *tmp_info;
4077 struct text_object subroot;
4079 read_exec(obj->data.s, p, text_buffer_size);
4081 tmp_info = malloc(sizeof(struct information));
4082 memcpy(tmp_info, cur, sizeof(struct information));
4083 parse_conky_vars(&subroot, p, p, tmp_info);
4085 free_text_objects(&subroot, 1);
4092 read_exec(obj->data.s, p, text_buffer_size);
4093 barnum = get_barnum(p); /*using the same function*/
4095 if (barnum >= 0.0) {
4097 new_gauge(p, obj->a, obj->b, round_to_int(barnum * 255.0));
4104 read_exec(obj->data.s, p, text_buffer_size);
4105 barnum = get_barnum(p);
4107 if (barnum >= 0.0) {
4109 if(output_methods & TO_X) {
4111 new_bar(p, obj->a, obj->b, round_to_int(barnum * 255.0));
4114 if(!obj->a) obj->a = DEFAULT_BAR_WIDTH_NO_X;
4115 new_bar_in_shell(p, p_max_size, barnum, obj->a);
4123 char showaslog = FALSE;
4124 char tempgrad = FALSE;
4126 char *cmd = obj->data.s;
4128 if (strncasecmp(obj->data.execi.cmd, LOGGRAPH" ", strlen(LOGGRAPH" ")) == EQUAL) {
4130 cmd = cmd + strlen(LOGGRAPH" ") * sizeof(char);
4131 } else if(strncasecmp(obj->data.s, NORMGRAPH" ", strlen(NORMGRAPH" ")) == EQUAL) {
4132 cmd = cmd + strlen(NORMGRAPH" ") * sizeof(char);
4134 if (strstr(cmd, " "TEMPGRAD) && strlen(cmd) > strlen(" "TEMPGRAD)) {
4136 cmd += strlen(" "TEMPGRAD);
4138 read_exec(cmd, p, text_buffer_size);
4139 barnum = get_barnum(p);
4142 new_graph(p, obj->a, obj->b, obj->c, obj->d, round_to_int(barnum),
4143 100, 1, showaslog, tempgrad);
4148 if (current_update_time - obj->data.execi.last_update
4149 >= obj->data.execi.interval) {
4152 read_exec(obj->data.execi.cmd, p, text_buffer_size);
4153 barnum = get_barnum(p);
4155 if (barnum >= 0.0) {
4158 obj->data.execi.last_update = current_update_time;
4161 if(output_methods & TO_X) {
4162 new_bar(p, obj->a, obj->b, round_to_int(obj->f * 2.55));
4165 if(!obj->a) obj->a = DEFAULT_BAR_WIDTH_NO_X;
4166 new_bar_in_shell(p, p_max_size, round_to_int(obj->f), obj->a);
4173 if (current_update_time - obj->data.execi.last_update
4174 >= obj->data.execi.interval) {
4176 char showaslog = FALSE;
4177 char tempgrad = FALSE;
4178 char *cmd = obj->data.execi.cmd;
4180 if (strncasecmp(obj->data.execi.cmd, LOGGRAPH" ", strlen(LOGGRAPH" ")) == EQUAL) {
4182 cmd = cmd + strlen(LOGGRAPH" ") * sizeof(char);
4183 } else if(strncasecmp(obj->data.s, NORMGRAPH" ", strlen(NORMGRAPH" ")) == EQUAL) {
4184 cmd = cmd + strlen(NORMGRAPH" ") * sizeof(char);
4186 if (strstr(cmd, " "TEMPGRAD) && strlen(cmd) > strlen(" "TEMPGRAD)) {
4188 cmd += strlen(" "TEMPGRAD);
4190 obj->char_a = showaslog;
4191 obj->char_b = tempgrad;
4192 read_exec(cmd, p, text_buffer_size);
4193 barnum = get_barnum(p);
4195 if (barnum >= 0.0) {
4198 obj->data.execi.last_update = current_update_time;
4200 new_graph(p, obj->a, obj->b, obj->c, obj->d, (int) (obj->f), 100, 1, obj->char_a, obj->char_b);
4203 if (current_update_time - obj->data.execi.last_update
4204 >= obj->data.execi.interval) {
4207 read_exec(obj->data.execi.cmd, p, text_buffer_size);
4208 barnum = get_barnum(p);
4210 if (barnum >= 0.0) {
4211 obj->f = 255 * barnum / 100.0;
4213 obj->data.execi.last_update = current_update_time;
4215 new_gauge(p, obj->a, obj->b, round_to_int(obj->f));
4219 if (current_update_time - obj->data.execi.last_update
4220 >= obj->data.execi.interval
4221 && obj->data.execi.interval != 0) {
4222 read_exec(obj->data.execi.cmd, obj->data.execi.buffer,
4224 obj->data.execi.last_update = current_update_time;
4226 snprintf(p, text_buffer_size, "%s", obj->data.execi.buffer);
4229 struct text_object subroot;
4230 struct information *tmp_info =
4231 malloc(sizeof(struct information));
4232 memcpy(tmp_info, cur, sizeof(struct information));
4234 if (current_update_time - obj->data.execi.last_update
4235 < obj->data.execi.interval
4236 || obj->data.execi.interval == 0) {
4237 parse_conky_vars(&subroot, obj->data.execi.buffer, p, tmp_info);
4239 char *output = obj->data.execi.buffer;
4240 FILE *fp = popen(obj->data.execi.cmd, "r");
4241 int length = fread(output, 1, text_buffer_size, fp);
4245 output[length] = '\0';
4246 if (length > 0 && output[length - 1] == '\n') {
4247 output[length - 1] = '\0';
4250 parse_conky_vars(&subroot, obj->data.execi.buffer, p, tmp_info);
4251 obj->data.execi.last_update = current_update_time;
4253 free_text_objects(&subroot, 1);
4257 if (!obj->data.texeci.p_timed_thread) {
4258 obj->data.texeci.p_timed_thread =
4259 timed_thread_create(&threaded_exec,
4260 (void *) obj, obj->data.texeci.interval * 1000000);
4261 if (!obj->data.texeci.p_timed_thread) {
4262 ERR("Error creating texeci timed thread");
4264 timed_thread_register(obj->data.texeci.p_timed_thread,
4265 &obj->data.texeci.p_timed_thread);
4266 if (timed_thread_run(obj->data.texeci.p_timed_thread)) {
4267 ERR("Error running texeci timed thread");
4270 timed_thread_lock(obj->data.texeci.p_timed_thread);
4271 snprintf(p, text_buffer_size, "%s", obj->data.texeci.buffer);
4272 timed_thread_unlock(obj->data.texeci.p_timed_thread);
4275 #endif /* HAVE_POPEN */
4277 struct mail_s *mail = ensure_mail_thread(obj, imap_thread, "imap");
4279 if (mail && mail->p_timed_thread) {
4280 timed_thread_lock(mail->p_timed_thread);
4281 snprintf(p, p_max_size, "%lu", mail->unseen);
4282 timed_thread_unlock(mail->p_timed_thread);
4285 OBJ(imap_messages) {
4286 struct mail_s *mail = ensure_mail_thread(obj, imap_thread, "imap");
4288 if (mail && mail->p_timed_thread) {
4289 timed_thread_lock(mail->p_timed_thread);
4290 snprintf(p, p_max_size, "%lu", mail->messages);
4291 timed_thread_unlock(mail->p_timed_thread);
4295 struct mail_s *mail = ensure_mail_thread(obj, pop3_thread, "pop3");
4297 if (mail && mail->p_timed_thread) {
4298 timed_thread_lock(mail->p_timed_thread);
4299 snprintf(p, p_max_size, "%lu", mail->unseen);
4300 timed_thread_unlock(mail->p_timed_thread);
4304 struct mail_s *mail = ensure_mail_thread(obj, pop3_thread, "pop3");
4306 if (mail && mail->p_timed_thread) {
4307 timed_thread_lock(mail->p_timed_thread);
4308 snprintf(p, p_max_size, "%.1f",
4309 mail->used / 1024.0 / 1024.0);
4310 timed_thread_unlock(mail->p_timed_thread);
4314 if (obj->data.fs != NULL) {
4315 if (obj->data.fs->size == 0) {
4317 if(output_methods & TO_X) {
4318 new_bar(p, obj->data.fsbar.w, obj->data.fsbar.h, 255);
4321 if(!obj->data.fsbar.w) obj->data.fsbar.w = DEFAULT_BAR_WIDTH_NO_X;
4322 new_bar_in_shell(p, p_max_size, 100, obj->data.fsbar.w);
4328 if(output_methods & TO_X) {
4329 new_bar(p, obj->data.fsbar.w, obj->data.fsbar.h,
4330 (int) (255 - obj->data.fsbar.fs->avail * 255 /
4331 obj->data.fs->size));
4334 if(!obj->data.fsbar.w) obj->data.fsbar.w = DEFAULT_BAR_WIDTH_NO_X;
4335 new_bar_in_shell(p, p_max_size,
4336 (int) (100 - obj->data.fsbar.fs->avail * 100 / obj->data.fs->size), obj->data.fsbar.w);
4344 if (obj->data.fs != NULL) {
4345 human_readable( (obj->data.fs->free ? obj->data.fs->free :
4346 obj->data.fs->avail), p, 255);
4350 if (obj->data.fs != NULL) {
4353 if (obj->data.fs->size) {
4354 val = (obj->data.fs->free ? obj->data.fs->free :
4355 obj->data.fs->avail) * 100 /
4359 percent_print(p, p_max_size, val);
4363 if (obj->data.fs != NULL) {
4364 human_readable(obj->data.fs->size, p, 255);
4368 if (obj->data.fs != NULL)
4369 snprintf(p, p_max_size, "%s", obj->data.fs->type);
4372 if (obj->data.fs != NULL) {
4373 human_readable(obj->data.fs->size - (obj->data.fs->free
4374 ? obj->data.fs->free : obj->data.fs->avail), p, 255);
4378 if (obj->data.fs != NULL) {
4379 if (obj->data.fs->size == 0) {
4381 if(output_methods & TO_X) {
4382 new_bar(p, obj->data.fsbar.w, obj->data.fsbar.h, 255);
4385 if(!obj->data.fsbar.w) obj->data.fsbar.w = DEFAULT_BAR_WIDTH_NO_X;
4386 new_bar_in_shell(p, p_max_size, 100, obj->data.fsbar.w);
4392 if(output_methods & TO_X) {
4393 new_bar(p, obj->data.fsbar.w, obj->data.fsbar.h,
4394 (int) (obj->data.fsbar.fs->avail * 255 /
4395 obj->data.fs->size));
4398 if(!obj->data.fsbar.w) obj->data.fsbar.w = DEFAULT_BAR_WIDTH_NO_X;
4399 new_bar_in_shell(p, p_max_size,
4400 (int) (obj->data.fsbar.fs->avail * 100 / obj->data.fs->size), obj->data.fsbar.w);
4408 if (obj->data.fs != NULL) {
4411 if (obj->data.fs->size) {
4412 val = (obj->data.fs->free ? obj->data.fs->free :
4413 obj->data.fs->avail) * 100 /
4417 percent_print(p, p_max_size, 100 - val);
4421 float *v = info.loadavg;
4423 if (obj->data.loadavg[2]) {
4424 snprintf(p, p_max_size, "%.2f %.2f %.2f",
4425 v[obj->data.loadavg[0] - 1],
4426 v[obj->data.loadavg[1] - 1],
4427 v[obj->data.loadavg[2] - 1]);
4428 } else if (obj->data.loadavg[1]) {
4429 snprintf(p, p_max_size, "%.2f %.2f",
4430 v[obj->data.loadavg[0] - 1],
4431 v[obj->data.loadavg[1] - 1]);
4432 } else if (obj->data.loadavg[0]) {
4433 snprintf(p, p_max_size, "%.2f",
4434 v[obj->data.loadavg[0] - 1]);
4438 new_goto(p, obj->data.i);
4441 new_tab(p, obj->data.pair.a, obj->data.pair.b);
4445 new_hr(p, obj->data.i);
4449 if (cur->nameserver_info.nscount > obj->data.i)
4450 snprintf(p, p_max_size, "%s",
4451 cur->nameserver_info.ns_list[obj->data.i]);
4455 char *skill = eve(obj->data.eve.userid, obj->data.eve.apikey, obj->data.eve.charid);
4456 snprintf(p, p_max_size, "%s", skill);
4461 PRSS *data = get_rss_info(obj->data.rss.uri,
4462 obj->data.rss.delay);
4466 snprintf(p, p_max_size, "prss: Error reading RSS data\n");
4468 if (strcmp(obj->data.rss.action, "feed_title") == EQUAL) {
4470 // remove trailing new line if one exists
4471 if (str[strlen(str) - 1] == '\n') {
4472 str[strlen(str) - 1] = 0;
4474 snprintf(p, p_max_size, "%s", str);
4475 } else if (strcmp(obj->data.rss.action, "item_title") == EQUAL) {
4476 if (obj->data.rss.act_par < data->item_count) {
4477 str = data->items[obj->data.rss.act_par].title;
4478 // remove trailing new line if one exists
4479 if (str[strlen(str) - 1] == '\n') {
4480 str[strlen(str) - 1] = 0;
4482 snprintf(p, p_max_size, "%s", str);
4484 } else if (strcmp(obj->data.rss.action, "item_desc") == EQUAL) {
4485 if (obj->data.rss.act_par < data->item_count) {
4487 data->items[obj->data.rss.act_par].description;
4488 // remove trailing new line if one exists
4489 if (str[strlen(str) - 1] == '\n') {
4490 str[strlen(str) - 1] = 0;
4492 snprintf(p, p_max_size, "%s", str);
4494 } else if (strcmp(obj->data.rss.action, "item_titles") == EQUAL) {
4495 if (data->item_count > 0) {
4498 //'tmpspaces' is a string with spaces too be placed in front of each title
4499 char *tmpspaces = malloc(obj->data.rss.nrspaces + 1);
4500 memset(tmpspaces, ' ', obj->data.rss.nrspaces);
4501 tmpspaces[obj->data.rss.nrspaces]=0;
4505 if (obj->data.rss.act_par > data->item_count) {
4506 show = data->item_count;
4508 show = obj->data.rss.act_par;
4510 for (itmp = 0; itmp < show; itmp++) {
4511 PRSS_Item *item = &data->items[itmp];
4515 // don't add new line before first item
4517 strncat(p, "\n", p_max_size);
4519 /* remove trailing new line if one exists,
4520 * we have our own */
4521 if (str[strlen(str) - 1] == '\n') {
4522 str[strlen(str) - 1] = 0;
4524 strncat(p, tmpspaces, p_max_size);
4525 strncat(p, str, p_max_size);
4536 char *str = llua_getstring(obj->data.s);
4538 snprintf(p, p_max_size, "%s", str);
4543 char *str = llua_getstring(obj->data.s);
4545 struct information *tmp_info;
4546 struct text_object subroot;
4548 tmp_info = malloc(sizeof(struct information));
4549 memcpy(tmp_info, cur, sizeof(struct information));
4550 parse_conky_vars(&subroot, str, p, tmp_info);
4552 free_text_objects(&subroot, 1);
4557 OBJ(lua_read_parse) {
4558 struct information *tmp_info;
4559 struct text_object subroot, subroot2;
4562 sscanf(obj->data.s, "%64s", func);
4563 text = obj->data.s + strlen(func) + 1;
4565 tmp_info = malloc(sizeof(struct information));
4566 memcpy(tmp_info, cur, sizeof(struct information));
4567 parse_conky_vars(&subroot, text, p, tmp_info);
4568 DBGP("evaluated '%s' to '%s'", text, p);
4570 str = llua_getstring_read(func, p);
4572 parse_conky_vars(&subroot2, str, p, tmp_info);
4573 DBGP("evaluated '%s' to '%s'", str, p);
4576 free_text_objects(&subroot2, 1);
4578 free_text_objects(&subroot, 1);
4583 if (llua_getnumber(obj->data.s, &per)) {
4585 if(output_methods & TO_X) {
4586 new_bar(p, obj->a, obj->b, (per/100.0 * 255));
4589 if(!obj->a) obj->a = DEFAULT_BAR_WIDTH_NO_X;
4590 new_bar_in_shell(p, p_max_size, per, obj->a);
4599 if (llua_getnumber(obj->data.s, &per)) {
4600 new_graph(p, obj->a, obj->b, obj->c, obj->d,
4601 per, obj->e, 1, obj->char_a, obj->char_b);
4606 if (llua_getnumber(obj->data.s, &per)) {
4607 new_gauge(p, obj->a, obj->b, (per/100.0 * 255));
4611 #endif /* HAVE_LUA */
4616 if (obj->data.hddtemp.update_time < current_update_time - 30) {
4617 if (obj->data.hddtemp.temp)
4618 free(obj->data.hddtemp.temp);
4619 obj->data.hddtemp.temp = get_hddtemp_info(obj->data.hddtemp.dev,
4620 obj->data.hddtemp.addr, obj->data.hddtemp.port);
4621 obj->data.hddtemp.update_time = current_update_time;
4623 if (!obj->data.hddtemp.temp) {
4624 snprintf(p, p_max_size, "N/A");
4626 val = strtol(obj->data.hddtemp.temp + 1, &endptr, 10);
4627 unit = obj->data.hddtemp.temp[0];
4629 if (*endptr != '\0')
4630 snprintf(p, p_max_size, "N/A");
4631 else if (unit == 'C')
4632 temp_print(p, p_max_size, (double)val, TEMP_CELSIUS);
4633 else if (unit == 'F')
4634 temp_print(p, p_max_size, (double)val, TEMP_FAHRENHEIT);
4636 snprintf(p, p_max_size, "N/A");
4641 new_offset(p, obj->data.i);
4644 new_voffset(p, obj->data.i);
4650 r = get_sysfs_info(&obj->data.sysfs.fd, obj->data.sysfs.arg,
4651 obj->data.sysfs.devtype, obj->data.sysfs.type);
4653 r = r * obj->data.sysfs.factor + obj->data.sysfs.offset;
4655 if (!strncmp(obj->data.sysfs.type, "temp", 4)) {
4656 temp_print(p, p_max_size, r, TEMP_CELSIUS);
4657 } else if (r >= 100.0 || r == 0) {
4658 snprintf(p, p_max_size, "%d", (int) r);
4660 snprintf(p, p_max_size, "%.1f", r);
4666 r = get_sysfs_info(&obj->data.sysfs.fd, obj->data.sysfs.arg,
4667 obj->data.sysfs.devtype, obj->data.sysfs.type);
4669 r = r * obj->data.sysfs.factor + obj->data.sysfs.offset;
4671 if (!strncmp(obj->data.sysfs.type, "temp", 4)) {
4672 temp_print(p, p_max_size, r, TEMP_CELSIUS);
4673 } else if (r >= 100.0 || r == 0) {
4674 snprintf(p, p_max_size, "%d", (int) r);
4676 snprintf(p, p_max_size, "%.1f", r);
4682 r = get_sysfs_info(&obj->data.sysfs.fd, obj->data.sysfs.arg,
4683 obj->data.sysfs.devtype, obj->data.sysfs.type);
4685 r = r * obj->data.sysfs.factor + obj->data.sysfs.offset;
4687 if (!strncmp(obj->data.sysfs.type, "temp", 4)) {
4688 temp_print(p, p_max_size, r, TEMP_CELSIUS);
4689 } else if (r >= 100.0 || r == 0) {
4690 snprintf(p, p_max_size, "%d", (int) r);
4692 snprintf(p, p_max_size, "%.1f", r);
4695 #endif /* __linux__ */
4697 new_alignr(p, obj->data.i);
4700 new_alignc(p, obj->data.i);
4703 char buf[max_user_text];
4704 struct information *tmp_info =
4705 malloc(sizeof(struct information));
4706 memcpy(tmp_info, cur, sizeof(struct information));
4707 generate_text_internal(buf, max_user_text,
4708 *obj->sub, tmp_info);
4710 if (strlen(buf) != 0) {
4716 char expression[max_user_text];
4718 struct information *tmp_info;
4720 tmp_info = malloc(sizeof(struct information));
4721 memcpy(tmp_info, cur, sizeof(struct information));
4722 generate_text_internal(expression, max_user_text,
4723 *obj->sub, tmp_info);
4724 DBGP("parsed arg into '%s'", expression);
4726 val = compare(expression);
4728 ERR("compare failed for expression '%s'",
4736 if (obj->data.ifblock.str
4737 && !check_contains(obj->data.ifblock.s,
4738 obj->data.ifblock.str)) {
4740 } else if (obj->data.ifblock.s
4741 && access(obj->data.ifblock.s, F_OK)) {
4746 if ((obj->data.ifblock.s)
4747 && (!check_mount(obj->data.ifblock.s))) {
4752 if ((obj->data.ifblock.s) && system(obj->data.ifblock.s)) {
4756 #if defined(__linux__)
4758 snprintf(p, p_max_size, "%s", get_ioscheduler(obj->data.s));
4762 snprintf(p, p_max_size, "%s", cur->uname_s.release);
4765 snprintf(p, p_max_size, "%s", cur->uname_s.machine);
4770 human_readable(cur->mem * 1024, p, 255);
4773 human_readable(cur->memeasyfree * 1024, p, 255);
4776 human_readable(cur->memfree * 1024, p, 255);
4779 human_readable(cur->memmax * 1024, p, 255);
4783 percent_print(p, p_max_size, cur->mem * 100 / cur->memmax);
4787 new_gauge(p, obj->data.pair.a, obj->data.pair.b,
4788 cur->memmax ? (cur->mem * 255) / (cur->memmax) : 0);
4793 if(output_methods & TO_X) {
4794 new_bar(p, obj->data.pair.a, obj->data.pair.b,
4795 cur->memmax ? (cur->mem * 255) / (cur->memmax) : 0);
4798 if(!obj->data.pair.a) obj->data.pair.a = DEFAULT_BAR_WIDTH_NO_X;
4799 new_bar_in_shell(p, p_max_size, cur->memmax ? (cur->mem * 100) / (cur->memmax) : 0, obj->data.pair.a);
4806 new_graph(p, obj->a, obj->b, obj->c, obj->d,
4807 cur->memmax ? (cur->mem * 100.0) / (cur->memmax) : 0.0,
4808 100, 1, obj->char_a, obj->char_b);
4813 percent_print(p, p_max_size, mixer_get_avg(obj->data.l));
4816 percent_print(p, p_max_size, mixer_get_left(obj->data.l));
4819 percent_print(p, p_max_size, mixer_get_right(obj->data.l));
4823 new_bar(p, obj->data.mixerbar.w, obj->data.mixerbar.h,
4824 mixer_to_255(obj->data.mixerbar.l,mixer_get_avg(obj->data.mixerbar.l)));
4827 new_bar(p, obj->data.mixerbar.w, obj->data.mixerbar.h,
4828 mixer_to_255(obj->data.mixerbar.l,mixer_get_left(obj->data.mixerbar.l)));
4831 new_bar(p, obj->data.mixerbar.w, obj->data.mixerbar.h,
4832 mixer_to_255(obj->data.mixerbar.l,mixer_get_right(obj->data.mixerbar.l)));
4835 OBJ(if_mixer_mute) {
4836 if (!mixer_is_mute(obj->data.ifblock.i)) {
4842 snprintf(p, p_max_size, "%d", cur->x11.monitor.current);
4844 OBJ(monitor_number) {
4845 snprintf(p, p_max_size, "%d", cur->x11.monitor.number);
4851 update_mail_count(&obj->data.local_mail);
4852 snprintf(p, p_max_size, "%d", obj->data.local_mail.mail_count);
4855 update_mail_count(&obj->data.local_mail);
4856 snprintf(p, p_max_size, "%d",
4857 obj->data.local_mail.new_mail_count);
4860 update_mail_count(&obj->data.local_mail);
4861 snprintf(p, p_max_size, "%d",
4862 obj->data.local_mail.seen_mail_count);
4865 update_mail_count(&obj->data.local_mail);
4866 snprintf(p, p_max_size, "%d",
4867 obj->data.local_mail.unseen_mail_count);
4869 OBJ(flagged_mails) {
4870 update_mail_count(&obj->data.local_mail);
4871 snprintf(p, p_max_size, "%d",
4872 obj->data.local_mail.flagged_mail_count);
4874 OBJ(unflagged_mails) {
4875 update_mail_count(&obj->data.local_mail);
4876 snprintf(p, p_max_size, "%d",
4877 obj->data.local_mail.unflagged_mail_count);
4879 OBJ(forwarded_mails) {
4880 update_mail_count(&obj->data.local_mail);
4881 snprintf(p, p_max_size, "%d",
4882 obj->data.local_mail.forwarded_mail_count);
4884 OBJ(unforwarded_mails) {
4885 update_mail_count(&obj->data.local_mail);
4886 snprintf(p, p_max_size, "%d",
4887 obj->data.local_mail.unforwarded_mail_count);
4889 OBJ(replied_mails) {
4890 update_mail_count(&obj->data.local_mail);
4891 snprintf(p, p_max_size, "%d",
4892 obj->data.local_mail.replied_mail_count);
4894 OBJ(unreplied_mails) {
4895 update_mail_count(&obj->data.local_mail);
4896 snprintf(p, p_max_size, "%d",
4897 obj->data.local_mail.unreplied_mail_count);
4900 update_mail_count(&obj->data.local_mail);
4901 snprintf(p, p_max_size, "%d",
4902 obj->data.local_mail.draft_mail_count);
4904 OBJ(trashed_mails) {
4905 update_mail_count(&obj->data.local_mail);
4906 snprintf(p, p_max_size, "%d",
4907 obj->data.local_mail.trashed_mail_count);
4910 mbox_scan(obj->data.mboxscan.args, obj->data.mboxscan.output,
4912 snprintf(p, p_max_size, "%s", obj->data.mboxscan.output);
4915 snprintf(p, p_max_size, "%s", cur->uname_s.nodename);
4918 new_outline(p, obj->data.l);
4921 spaced_print(p, p_max_size, "%hu", 4, cur->procs);
4923 OBJ(running_processes) {
4924 spaced_print(p, p_max_size, "%hu", 4, cur->run_procs);
4927 snprintf(p, p_max_size, "%s", obj->data.s);
4931 new_bg(p, obj->data.l);
4934 new_stippled_hr(p, obj->data.pair.a, obj->data.pair.b);
4938 human_readable(cur->swap * 1024, p, 255);
4941 human_readable(cur->swapmax * 1024, p, 255);
4944 if (cur->swapmax == 0) {
4945 strncpy(p, "No swap", p_max_size);
4947 percent_print(p, p_max_size, cur->swap * 100 / cur->swapmax);
4952 if(output_methods & TO_X) {
4953 new_bar(p, obj->data.pair.a, obj->data.pair.b,
4954 cur->swapmax ? (cur->swap * 255) / (cur->swapmax) : 0);
4957 if(!obj->data.pair.a) obj->data.pair.a = DEFAULT_BAR_WIDTH_NO_X;
4958 new_bar_in_shell(p, p_max_size, cur->swapmax ? (cur->swap * 100) / (cur->swapmax) : 0, obj->data.pair.a);
4964 snprintf(p, p_max_size, "%s", cur->uname_s.sysname);
4967 time_t t = time(NULL);
4968 struct tm *tm = localtime(&t);
4970 setlocale(LC_TIME, "");
4971 strftime(p, p_max_size, obj->data.s, tm);
4974 time_t t = time(NULL);
4975 struct tm *tm = gmtime(&t);
4977 strftime(p, p_max_size, obj->data.s, tm);
4984 if (obj->data.tztime.tz) {
4985 oldTZ = getenv("TZ");
4986 setenv("TZ", obj->data.tztime.tz, 1);
4992 setlocale(LC_TIME, "");
4993 strftime(p, p_max_size, obj->data.tztime.fmt, tm);
4995 setenv("TZ", oldTZ, 1);
5000 // Needless to free oldTZ since getenv gives ptr to static data
5003 human_readable(obj->data.net->recv, p, 255);
5006 human_readable(obj->data.net->trans, p, 255);
5009 snprintf(p, p_max_size, "%d", total_updates);
5012 if(total_updates % updatereset != obj->data.ifblock.i - 1) {
5017 human_readable(obj->data.net->trans_speed, p, 255);
5020 spaced_print(p, p_max_size, "%.1f", 8,
5021 obj->data.net->trans_speed / 1024.0);
5025 new_graph(p, obj->a, obj->b, obj->c, obj->d,
5026 obj->data.net->trans_speed / 1024.0, obj->e, 1, obj->char_a, obj->char_b);
5030 format_seconds_short(p, p_max_size, (int) cur->uptime);
5033 format_seconds(p, p_max_size, (int) cur->uptime);
5036 snprintf(p, p_max_size, "%s", cur->users.names);
5039 snprintf(p, p_max_size, "%s", cur->users.terms);
5042 snprintf(p, p_max_size, "%s", cur->users.times);
5045 snprintf(p, p_max_size, "%d", cur->users.number);
5047 #if (defined(__FreeBSD__) || defined(__FreeBSD_kernel__) \
5048 || defined(__OpenBSD__)) && (defined(i386) || defined(__i386__))
5052 msg = get_apm_adapter();
5053 snprintf(p, p_max_size, "%s", msg);
5056 OBJ(apm_battery_life) {
5059 msg = get_apm_battery_life();
5060 snprintf(p, p_max_size, "%s", msg);
5063 OBJ(apm_battery_time) {
5066 msg = get_apm_battery_time();
5067 snprintf(p, p_max_size, "%s", msg);
5070 #endif /* __FreeBSD__ __OpenBSD__ */
5073 #define mpd_printf(fmt, val) \
5074 snprintf(p, p_max_size, fmt, mpd_get_info()->val)
5075 #define mpd_sprintf(val) { \
5076 if (!obj->data.i || obj->data.i > p_max_size) \
5077 mpd_printf("%s", val); \
5079 snprintf(p, obj->data.i, "%s", mpd_get_info()->val); \
5084 mpd_sprintf(artist);
5088 mpd_printf("%s", random);
5090 mpd_printf("%s", repeat);
5098 mpd_printf("%d", volume);
5100 mpd_printf("%d", bitrate);
5102 mpd_printf("%s", status);
5104 format_media_player_time(p, p_max_size, mpd_get_info()->elapsed);
5107 format_media_player_time(p, p_max_size, mpd_get_info()->length);
5110 percent_print(p, p_max_size, (int)(mpd_get_info()->progress * 100));
5114 if(output_methods & TO_X) {
5115 new_bar(p, obj->data.pair.a, obj->data.pair.b,
5116 (int) (mpd_get_info()->progress * 255.0f));
5119 if(!obj->data.pair.a) obj->data.pair.a = DEFAULT_BAR_WIDTH_NO_X;
5120 new_bar_in_shell(p, p_max_size, (int) (mpd_get_info()->progress * 100.0f), obj->data.pair.a);
5126 struct mpd_s *mpd = mpd_get_info();
5127 int len = obj->data.i;
5128 if (len == 0 || len > p_max_size)
5131 memset(p, 0, p_max_size);
5132 if (mpd->artist && *mpd->artist &&
5133 mpd->title && *mpd->title) {
5134 snprintf(p, len, "%s - %s", mpd->artist,
5136 } else if (mpd->title && *mpd->title) {
5137 snprintf(p, len, "%s", mpd->title);
5138 } else if (mpd->artist && *mpd->artist) {
5139 snprintf(p, len, "%s", mpd->artist);
5140 } else if (mpd->file && *mpd->file) {
5141 snprintf(p, len, "%s", mpd->file);
5146 OBJ(if_mpd_playing) {
5147 if (!mpd_get_info()->is_playing) {
5160 #define MOC_PRINT(t, a) \
5161 snprintf(p, p_max_size, "%s", (moc.t ? moc.t : a))
5163 MOC_PRINT(state, "??");
5166 MOC_PRINT(file, "no file");
5169 MOC_PRINT(title, "no title");
5172 MOC_PRINT(artist, "no artist");
5175 MOC_PRINT(song, "no song");
5178 MOC_PRINT(album, "no album");
5180 OBJ(moc_totaltime) {
5181 MOC_PRINT(totaltime, "0:00");
5184 MOC_PRINT(timeleft, "0:00");
5187 MOC_PRINT(curtime, "0:00");
5190 MOC_PRINT(bitrate, "0Kbps");
5193 MOC_PRINT(rate, "0KHz");
5199 snprintf(p, p_max_size, "%s", cur->xmms2.artist);
5202 snprintf(p, p_max_size, "%s", cur->xmms2.album);
5205 snprintf(p, p_max_size, "%s", cur->xmms2.title);
5208 snprintf(p, p_max_size, "%s", cur->xmms2.genre);
5210 OBJ(xmms2_comment) {
5211 snprintf(p, p_max_size, "%s", cur->xmms2.comment);
5214 snprintf(p, p_max_size, "%s", cur->xmms2.url);
5217 snprintf(p, p_max_size, "%s", cur->xmms2.status);
5220 snprintf(p, p_max_size, "%s", cur->xmms2.date);
5222 OBJ(xmms2_tracknr) {
5223 if (cur->xmms2.tracknr != -1) {
5224 snprintf(p, p_max_size, "%i", cur->xmms2.tracknr);
5227 OBJ(xmms2_bitrate) {
5228 snprintf(p, p_max_size, "%i", cur->xmms2.bitrate);
5231 snprintf(p, p_max_size, "%u", cur->xmms2.id);
5234 snprintf(p, p_max_size, "%2.1f", cur->xmms2.size);
5236 OBJ(xmms2_elapsed) {
5237 snprintf(p, p_max_size, "%02d:%02d", cur->xmms2.elapsed / 60000,
5238 (cur->xmms2.elapsed / 1000) % 60);
5240 OBJ(xmms2_duration) {
5241 snprintf(p, p_max_size, "%02d:%02d",
5242 cur->xmms2.duration / 60000,
5243 (cur->xmms2.duration / 1000) % 60);
5245 OBJ(xmms2_percent) {
5246 snprintf(p, p_max_size, "%2.0f", cur->xmms2.progress * 100);
5250 new_bar(p, obj->data.pair.a, obj->data.pair.b,
5251 (int) (cur->xmms2.progress * 255.0f));
5254 OBJ(xmms2_playlist) {
5255 snprintf(p, p_max_size, "%s", cur->xmms2.playlist);
5257 OBJ(xmms2_timesplayed) {
5258 snprintf(p, p_max_size, "%i", cur->xmms2.timesplayed);
5261 if (strlen(cur->xmms2.title) < 2
5262 && strlen(cur->xmms2.title) < 2) {
5263 snprintf(p, p_max_size, "%s", cur->xmms2.url);
5265 snprintf(p, p_max_size, "%s - %s", cur->xmms2.artist,
5269 OBJ(if_xmms2_connected) {
5270 if (cur->xmms2.conn_state != 1) {
5276 OBJ(audacious_status) {
5277 snprintf(p, p_max_size, "%s",
5278 cur->audacious.items[AUDACIOUS_STATUS]);
5280 OBJ(audacious_title) {
5281 snprintf(p, cur->audacious.max_title_len > 0
5282 ? cur->audacious.max_title_len : p_max_size, "%s",
5283 cur->audacious.items[AUDACIOUS_TITLE]);
5285 OBJ(audacious_length) {
5286 snprintf(p, p_max_size, "%s",
5287 cur->audacious.items[AUDACIOUS_LENGTH]);
5289 OBJ(audacious_length_seconds) {
5290 snprintf(p, p_max_size, "%s",
5291 cur->audacious.items[AUDACIOUS_LENGTH_SECONDS]);
5293 OBJ(audacious_position) {
5294 snprintf(p, p_max_size, "%s",
5295 cur->audacious.items[AUDACIOUS_POSITION]);
5297 OBJ(audacious_position_seconds) {
5298 snprintf(p, p_max_size, "%s",
5299 cur->audacious.items[AUDACIOUS_POSITION_SECONDS]);
5301 OBJ(audacious_bitrate) {
5302 snprintf(p, p_max_size, "%s",
5303 cur->audacious.items[AUDACIOUS_BITRATE]);
5305 OBJ(audacious_frequency) {
5306 snprintf(p, p_max_size, "%s",
5307 cur->audacious.items[AUDACIOUS_FREQUENCY]);
5309 OBJ(audacious_channels) {
5310 snprintf(p, p_max_size, "%s",
5311 cur->audacious.items[AUDACIOUS_CHANNELS]);
5313 OBJ(audacious_filename) {
5314 snprintf(p, p_max_size, "%s",
5315 cur->audacious.items[AUDACIOUS_FILENAME]);
5317 OBJ(audacious_playlist_length) {
5318 snprintf(p, p_max_size, "%s",
5319 cur->audacious.items[AUDACIOUS_PLAYLIST_LENGTH]);
5321 OBJ(audacious_playlist_position) {
5322 snprintf(p, p_max_size, "%s",
5323 cur->audacious.items[AUDACIOUS_PLAYLIST_POSITION]);
5325 OBJ(audacious_main_volume) {
5326 snprintf(p, p_max_size, "%s",
5327 cur->audacious.items[AUDACIOUS_MAIN_VOLUME]);
5330 OBJ(audacious_bar) {
5334 atof(cur->audacious.items[AUDACIOUS_POSITION_SECONDS]) /
5335 atof(cur->audacious.items[AUDACIOUS_LENGTH_SECONDS]);
5336 new_bar(p, obj->a, obj->b, (int) (progress * 255.0f));
5339 #endif /* AUDACIOUS */
5343 snprintf(p, p_max_size, "%s", cur->bmpx.title);
5346 snprintf(p, p_max_size, "%s", cur->bmpx.artist);
5349 snprintf(p, p_max_size, "%s", cur->bmpx.album);
5352 snprintf(p, p_max_size, "%s", cur->bmpx.uri);
5355 snprintf(p, p_max_size, "%i", cur->bmpx.track);
5358 snprintf(p, p_max_size, "%i", cur->bmpx.bitrate);
5361 /* we have three different types of top (top, top_mem
5362 * and top_time). To avoid having almost-same code three
5363 * times, we have this special handler. */
5366 parse_top_args("top", obj->data.top.s, obj);
5367 if (!needed) needed = cur->cpu;
5369 parse_top_args("top_mem", obj->data.top.s, obj);
5370 if (!needed) needed = cur->memu;
5372 parse_top_args("top_time", obj->data.top.s, obj);
5373 if (!needed) needed = cur->time;
5375 if (needed[obj->data.top.num]) {
5378 switch (obj->data.top.type) {
5380 snprintf(p, top_name_width + 1, "%-*s", top_name_width,
5381 needed[obj->data.top.num]->name);
5384 snprintf(p, 7, "%6.2f",
5385 needed[obj->data.top.num]->amount);
5388 snprintf(p, 6, "%5i",
5389 needed[obj->data.top.num]->pid);
5392 snprintf(p, 7, "%6.2f",
5393 needed[obj->data.top.num]->totalmem);
5396 timeval = format_time(
5397 needed[obj->data.top.num]->total_cpu_time, 9);
5398 snprintf(p, 10, "%9s", timeval);
5402 human_readable(needed[obj->data.top.num]->rss,
5406 human_readable(needed[obj->data.top.num]->vsize,
5412 print_tail_object(obj, p, p_max_size);
5414 print_head_object(obj, p, p_max_size);
5416 FILE *fp = open_file(obj->data.s, &obj->a);
5419 /* FIXME: use something more general (see also tail.c, head.c */
5420 #define BUFSZ 0x1000
5425 while(fgets(buf, BUFSZ, fp) != NULL){
5426 for(j = 0; buf[j] != 0; j++) {
5427 if(buf[j] == '\n') {
5432 sprintf(p, "%d", lines);
5435 sprintf(p, "File Unreadable");
5440 FILE *fp = open_file(obj->data.s, &obj->a);
5445 char inword = FALSE;
5448 while(fgets(buf, BUFSZ, fp) != NULL){
5449 for(j = 0; buf[j] != 0; j++) {
5450 if(!isspace(buf[j])) {
5451 if(inword == FALSE) {
5460 sprintf(p, "%d", words);
5463 sprintf(p, "File Unreadable");
5466 #ifdef TCP_PORT_MONITOR
5468 tcp_portmon_action(p, p_max_size,
5469 &obj->data.tcp_port_monitor);
5471 #endif /* TCP_PORT_MONITOR */
5475 iconv_converting = 1;
5476 iconv_selected = obj->a;
5479 iconv_converting = 0;
5482 #endif /* HAVE_ICONV */
5484 OBJ(entropy_avail) {
5485 snprintf(p, p_max_size, "%d", cur->entropy.entropy_avail);
5488 percent_print(p, p_max_size,
5489 cur->entropy.entropy_avail *
5490 100 / cur->entropy.poolsize);
5492 OBJ(entropy_poolsize) {
5493 snprintf(p, p_max_size, "%d", cur->entropy.poolsize);
5496 double entropy_perc;
5498 entropy_perc = (double) cur->entropy.entropy_avail /
5499 (double) cur->entropy.poolsize;
5501 if(output_methods & TO_X) {
5502 new_bar(p, obj->a, obj->b, (int) (entropy_perc * 255.0f));
5505 if(!obj->a) obj->a = DEFAULT_BAR_WIDTH_NO_X;
5506 new_bar_in_shell(p, p_max_size, (int) (entropy_perc * 100.0f), obj->a);
5515 s = smapi_get_val(obj->data.s);
5516 snprintf(p, p_max_size, "%s", s);
5520 OBJ(if_smapi_bat_installed) {
5522 if(obj->data.ifblock.s && sscanf(obj->data.ifblock.s, "%i", &idx) == 1) {
5523 if(!smapi_bat_installed(idx)) {
5527 ERR("argument to if_smapi_bat_installed must be an integer");
5529 OBJ(smapi_bat_perc) {
5531 if(obj->data.s && sscanf(obj->data.s, "%i", &idx) == 1) {
5532 val = smapi_bat_installed(idx) ?
5533 smapi_get_bat_int(idx, "remaining_percent") : 0;
5534 percent_print(p, p_max_size, val);
5536 ERR("argument to smapi_bat_perc must be an integer");
5538 OBJ(smapi_bat_temp) {
5540 if(obj->data.s && sscanf(obj->data.s, "%i", &idx) == 1) {
5541 val = smapi_bat_installed(idx) ?
5542 smapi_get_bat_int(idx, "temperature") : 0;
5543 /* temperature is in milli degree celsius */
5544 temp_print(p, p_max_size, val / 1000, TEMP_CELSIUS);
5546 ERR("argument to smapi_bat_temp must be an integer");
5548 OBJ(smapi_bat_power) {
5550 if(obj->data.s && sscanf(obj->data.s, "%i", &idx) == 1) {
5551 val = smapi_bat_installed(idx) ?
5552 smapi_get_bat_int(idx, "power_now") : 0;
5553 /* power_now is in mW, set to W with one digit precision */
5554 snprintf(p, p_max_size, "%.1f", ((double)val / 1000));
5556 ERR("argument to smapi_bat_power must be an integer");
5559 OBJ(smapi_bat_bar) {
5560 if(obj->data.i >= 0 && smapi_bat_installed(obj->data.i))
5561 new_bar(p, obj->a, obj->b, (int)
5562 (255 * smapi_get_bat_int(obj->data.i, "remaining_percent") / 100));
5564 new_bar(p, obj->a, obj->b, 0);
5570 char *tmp, buf[max_user_text];
5571 generate_text_internal(buf, max_user_text,
5574 if (strlen(buf) <= obj->data.scroll.show) {
5575 snprintf(p, p_max_size, "%s", buf);
5578 #define LINESEPARATOR '|'
5579 //place all the lines behind each other with LINESEPARATOR between them
5580 for(j = 0; buf[j] != 0; j++) {
5582 buf[j]=LINESEPARATOR;
5585 //scroll the output obj->data.scroll.start places by copying that many chars from
5586 //the front of the string to tmp, scrolling the rest to the front and placing tmp
5587 //at the back of the string
5588 tmp = calloc(obj->data.scroll.start + 1, sizeof(char));
5589 strncpy(tmp, buf, obj->data.scroll.start); tmp[obj->data.scroll.start] = 0;
5590 for(j = obj->data.scroll.start; buf[j] != 0; j++){
5591 buf[j - obj->data.scroll.start] = buf[j];
5593 strcpy(&buf[j - obj->data.scroll.start], tmp);
5595 //only show the requested number of chars
5596 if(obj->data.scroll.show < j) {
5597 buf[obj->data.scroll.show] = 0;
5599 //next time, scroll a place more or reset scrolling if we are at the end
5600 obj->data.scroll.start += obj->data.scroll.step;
5601 if(obj->data.scroll.start >= j){
5602 obj->data.scroll.start = 0;
5604 snprintf(p, p_max_size, "%s", buf);
5607 char buf[2][max_user_text];
5614 struct llrows* next;
5616 struct llrows *ll_rows[2], *current[2];
5617 struct text_object * objsub = obj->sub;
5620 for(i=0; i<2; i++) {
5623 ll_rows[i] = malloc(sizeof(struct llrows));
5624 current[i] = ll_rows[i];
5625 for(j=0; j<i; j++) objsub = objsub->sub;
5626 generate_text_internal(buf[i], max_user_text, *objsub, cur);
5627 for(j=0; buf[i][j] != 0; j++) {
5628 if(buf[i][j] == '\t') buf[i][j] = ' ';
5629 if(buf[i][j] == '\n') {
5631 current[i]->row = strdup(buf[i]+nextstart);
5632 if(i==0 && (long)strlen(current[i]->row) > longest) longest = (long)strlen(current[i]->row);
5633 current[i]->next = malloc(sizeof(struct llrows));
5634 current[i] = current[i]->next;
5639 current[i]->row = strdup(buf[i]+nextstart);
5640 if(i==0 && (long)strlen(current[i]->row) > longest) longest = (long)strlen(current[i]->row);
5641 current[i]->next = NULL;
5642 current[i] = ll_rows[i];
5644 for(j=0; j < (nr_rows[0] > nr_rows[1] ? nr_rows[0] : nr_rows[1] ); j++) {
5646 strcat(p, current[0]->row);
5647 i=strlen(current[0]->row);
5649 while(i < longest) {
5654 strcat(p, obj->data.combine.seperation);
5655 strcat(p, current[1]->row);
5659 #pragma omp parallel for
5660 #endif /* HAVE_OPENMP */
5661 for(i=0; i<2; i++) if(current[i]) current[i]=current[i]->next;
5664 #pragma omp parallel for
5665 #endif /* HAVE_OPENMP */
5666 for(i=0; i<2; i++) {
5667 while(ll_rows[i] != NULL) {
5668 current[i]=ll_rows[i];
5669 free(current[i]->row);
5670 ll_rows[i]=current[i]->next;
5677 int value = get_nvidia_value(obj->data.nvidia.type, display);
5679 snprintf(p, p_max_size, "N/A");
5680 else if (obj->data.nvidia.type == NV_TEMP)
5681 temp_print(p, p_max_size, (double)value, TEMP_CELSIUS);
5682 else if (obj->data.nvidia.print_as_float &&
5683 value > 0 && value < 100)
5684 snprintf(p, p_max_size, "%.1f", (float)value);
5686 snprintf(p, p_max_size, "%d", value);
5691 /* This is just a meta-object to set host:port */
5694 snprintf(p, p_max_size, "%s",
5695 cur->apcupsd.items[APCUPSD_NAME]);
5697 OBJ(apcupsd_model) {
5698 snprintf(p, p_max_size, "%s",
5699 cur->apcupsd.items[APCUPSD_MODEL]);
5701 OBJ(apcupsd_upsmode) {
5702 snprintf(p, p_max_size, "%s",
5703 cur->apcupsd.items[APCUPSD_UPSMODE]);
5705 OBJ(apcupsd_cable) {
5706 snprintf(p, p_max_size, "%s",
5707 cur->apcupsd.items[APCUPSD_CABLE]);
5709 OBJ(apcupsd_status) {
5710 snprintf(p, p_max_size, "%s",
5711 cur->apcupsd.items[APCUPSD_STATUS]);
5713 OBJ(apcupsd_linev) {
5714 snprintf(p, p_max_size, "%s",
5715 cur->apcupsd.items[APCUPSD_LINEV]);
5718 snprintf(p, p_max_size, "%s",
5719 cur->apcupsd.items[APCUPSD_LOAD]);
5721 OBJ(apcupsd_loadbar) {
5724 if(output_methods & TO_X) {
5725 progress = atof(cur->apcupsd.items[APCUPSD_LOAD]) / 100.0 * 255.0;
5726 new_bar(p, obj->a, obj->b, (int) progress);
5729 progress = atof(cur->apcupsd.items[APCUPSD_LOAD]);
5730 if(!obj->a) obj->a = DEFAULT_BAR_WIDTH_NO_X;
5731 new_bar_in_shell(p, p_max_size, (int) progress, obj->a);
5737 OBJ(apcupsd_loadgraph) {
5739 progress = atof(cur->apcupsd.items[APCUPSD_LOAD]);
5740 new_graph(p, obj->a, obj->b, obj->c, obj->d,
5741 (int)progress, 100, 1, obj->char_a, obj->char_b);
5743 OBJ(apcupsd_loadgauge) {
5745 progress = atof(cur->apcupsd.items[APCUPSD_LOAD]) / 100.0 * 255.0;
5746 new_gauge(p, obj->a, obj->b,
5750 OBJ(apcupsd_charge) {
5751 snprintf(p, p_max_size, "%s",
5752 cur->apcupsd.items[APCUPSD_CHARGE]);
5754 OBJ(apcupsd_timeleft) {
5755 snprintf(p, p_max_size, "%s",
5756 cur->apcupsd.items[APCUPSD_TIMELEFT]);
5759 snprintf(p, p_max_size, "%s",
5760 cur->apcupsd.items[APCUPSD_TEMP]);
5762 OBJ(apcupsd_lastxfer) {
5763 snprintf(p, p_max_size, "%s",
5764 cur->apcupsd.items[APCUPSD_LASTXFER]);
5766 #endif /* APCUPSD */
5773 unsigned int a = strlen(p);
5776 if (a > 0 && iconv_converting && iconv_selected > 0
5777 && (iconv_cd[iconv_selected - 1] != (iconv_t) (-1))) {
5779 size_t dummy1, dummy2;
5780 char *ptr = buff_in;
5783 dummy1 = dummy2 = a;
5785 strncpy(buff_in, p, p_max_size);
5787 iconv(*iconv_cd[iconv_selected - 1], NULL, NULL, NULL, NULL);
5788 while (dummy1 > 0) {
5789 bytes = iconv(*iconv_cd[iconv_selected - 1], &ptr, &dummy1,
5792 ERR("Iconv codeset conversion failed");
5797 /* It is nessecary when we are converting from multibyte to
5798 * singlebyte codepage */
5801 #endif /* HAVE_ICONV */
5808 /* load any new fonts we may have had */
5809 if (need_to_load_fonts) {
5815 double current_update_time, next_update_time, last_update_time;
5817 static void generate_text(void)
5819 struct information *cur = &info;
5826 current_update_time = get_time();
5830 /* add things to the buffer */
5836 generate_text_internal(p, max_user_text, global_root_object, cur);
5838 if (stuff_in_upper_case) {
5841 tmp_p = text_buffer;
5843 *tmp_p = toupper(*tmp_p);
5848 next_update_time += update_interval;
5849 if (next_update_time < get_time()) {
5850 next_update_time = get_time() + update_interval;
5851 } else if (next_update_time > get_time() + update_interval) {
5852 next_update_time = get_time() + update_interval;
5854 last_update_time = current_update_time;
5859 static inline int get_string_width(const char *s)
5862 if (output_methods & TO_X) {
5863 return *s ? calc_text_width(s, strlen(s)) : 0;
5869 static inline int get_string_width_special(char *s)
5877 if ((output_methods & TO_X) == 0) {
5879 return (s) ? strlen(s) : 0;
5887 p = strndup(s, text_buffer_size);
5891 if (*p == SPECIAL_CHAR) {
5892 /* shift everything over by 1 so that the special char
5893 * doesn't mess up the size calculation */
5894 for (i = 0; i < (long)strlen(p); i++) {
5895 *(p + i) = *(p + i + 1);
5897 if (specials[special_index + idx].type == GRAPH
5898 || specials[special_index + idx].type == GAUGE
5899 || specials[special_index + idx].type == BAR) {
5900 width += specials[special_index + idx].width;
5907 if (strlen(final) > 1) {
5908 width += calc_text_width(final, strlen(final));
5916 static void text_size_updater(char *s);
5918 int last_font_height;
5919 static void update_text_area(void)
5923 if ((output_methods & TO_X) == 0)
5925 /* update text size if it isn't fixed */
5930 text_width = minimum_width;
5933 last_font_height = font_height();
5934 for_each_line(text_buffer, text_size_updater);
5936 if (text_height < minimum_height) {
5937 text_height = minimum_height;
5939 if (text_width > maximum_width && maximum_width > 0) {
5940 text_width = maximum_width;
5944 /* get text position on workarea */
5945 switch (text_alignment) {
5952 x = workarea[2] - text_width - gap_x;
5957 x = workarea[2] / 2 - text_width / 2 - gap_x;
5964 y = workarea[3] - text_height - gap_y;
5968 x = workarea[2] - text_width - gap_x;
5969 y = workarea[3] - text_height - gap_y;
5973 x = workarea[2] / 2 - text_width / 2 - gap_x;
5974 y = workarea[3] - text_height - gap_y;
5979 y = workarea[3] / 2 - text_height / 2 - gap_y;
5983 x = workarea[2] - text_width - gap_x;
5984 y = workarea[3] / 2 - text_height / 2 - gap_y;
5988 case NONE: // Let the WM manage the window
5999 if (own_window && !fixed_pos) {
6002 text_start_x = border_margin + 1;
6003 text_start_y = border_margin + 1;
6004 window.x = x - border_margin - 1;
6005 window.y = y - border_margin - 1;
6009 /* If window size doesn't match to workarea's size,
6010 * then window probably includes panels (gnome).
6011 * Blah, doesn't work on KDE. */
6012 if (workarea[2] != window.width || workarea[3] != window.height) {
6024 static int cur_x, cur_y; /* current x and y for drawing */
6026 //draw_mode also without X11 because we only need to print to stdout with FG
6027 static int draw_mode; /* FG, BG or OUTLINE */
6029 static long current_color;
6031 static void text_size_updater(char *s)
6036 if ((output_methods & TO_X) == 0)
6038 /* get string widths and skip specials */
6041 if (*p == SPECIAL_CHAR) {
6043 w += get_string_width(s);
6046 if (specials[special_index].type == BAR
6047 || specials[special_index].type == GAUGE
6048 || specials[special_index].type == GRAPH) {
6049 w += specials[special_index].width;
6050 if (specials[special_index].height > last_font_height) {
6051 last_font_height = specials[special_index].height;
6052 last_font_height += font_height();
6054 } else if (specials[special_index].type == OFFSET) {
6055 if (specials[special_index].arg > 0) {
6056 w += specials[special_index].arg;
6058 } else if (specials[special_index].type == VOFFSET) {
6059 last_font_height += specials[special_index].arg;
6060 } else if (specials[special_index].type == GOTO) {
6061 if (specials[special_index].arg > cur_x) {
6062 w = (int) specials[special_index].arg;
6064 } else if (specials[special_index].type == TAB) {
6065 int start = specials[special_index].arg;
6066 int step = specials[special_index].width;
6068 if (!step || step < 0) {
6071 w += step - (cur_x - text_start_x - start) % step;
6072 } else if (specials[special_index].type == FONT) {
6073 selected_font = specials[special_index].font_added;
6074 if (font_height() > last_font_height) {
6075 last_font_height = font_height();
6084 w += get_string_width(s);
6085 if (w > text_width) {
6088 if (text_width > maximum_width && maximum_width) {
6089 text_width = maximum_width;
6092 text_height += last_font_height;
6093 last_font_height = font_height();
6096 static inline void set_foreground_color(long c)
6098 if ((output_methods & TO_X) == 0)
6101 XSetForeground(display, window.gc, c);
6105 static void draw_string(const char *s)
6107 int i, i2, pos, width_of_s;
6115 width_of_s = get_string_width(s);
6116 if ((output_methods & TO_STDOUT) && draw_mode == FG) {
6118 fflush(stdout); /* output immediately, don't buffer */
6120 if ((output_methods & TO_STDERR) && draw_mode == FG) {
6121 fprintf(stderr, "%s\n", s);
6122 fflush(stderr); /* output immediately, don't buffer */
6124 if ((output_methods & OVERWRITE_FILE) && draw_mode == FG && overwrite_fpointer) {
6125 fprintf(overwrite_fpointer, "%s\n", s);
6127 if ((output_methods & APPEND_FILE) && draw_mode == FG && append_fpointer) {
6128 fprintf(append_fpointer, "%s\n", s);
6130 memset(tmpstring1, 0, text_buffer_size);
6131 memset(tmpstring2, 0, text_buffer_size);
6132 strncpy(tmpstring1, s, text_buffer_size - 1);
6137 if (output_methods & TO_X) {
6138 max = ((text_width - width_of_s) / get_string_width(" "));
6141 /* This code looks for tabs in the text and coverts them to spaces.
6142 * The trick is getting the correct number of spaces, and not going
6143 * over the window's size without forcing the window larger. */
6144 for (i = 0; i < (int) text_buffer_size; i++) {
6145 if (tmpstring1[i] == '\t') {
6147 for (i2 = 0; i2 < (8 - (1 + pos) % 8) && added <= max; i2++) {
6148 /* guard against overrun */
6149 tmpstring2[MIN(pos + i2, (int)text_buffer_size - 1)] = ' ';
6154 /* guard against overrun */
6155 tmpstring2[MIN(pos, (int) text_buffer_size - 1)] = tmpstring1[i];
6160 if (output_methods & TO_X) {
6161 if (text_width == maximum_width) {
6162 /* this means the text is probably pushing the limit,
6163 * so we'll chop it */
6164 while (cur_x + get_string_width(tmpstring2) - text_start_x
6165 > maximum_width && strlen(tmpstring2) > 0) {
6166 tmpstring2[strlen(tmpstring2) - 1] = '\0';
6173 if (output_methods & TO_X) {
6179 c.pixel = current_color;
6180 XQueryColor(display, DefaultColormap(display, screen), &c);
6183 c2.color.red = c.red;
6184 c2.color.green = c.green;
6185 c2.color.blue = c.blue;
6186 c2.color.alpha = fonts[selected_font].font_alpha;
6188 XftDrawStringUtf8(window.xftdraw, &c2, fonts[selected_font].xftfont,
6189 cur_x, cur_y, (const XftChar8 *) s, strlen(s));
6191 XftDrawString8(window.xftdraw, &c2, fonts[selected_font].xftfont,
6192 cur_x, cur_y, (const XftChar8 *) s, strlen(s));
6197 XDrawString(display, window.drawable, window.gc, cur_x, cur_y, s,
6200 cur_x += width_of_s;
6203 memcpy(tmpstring1, s, text_buffer_size);
6206 static void draw_line(char *s)
6214 if ((output_methods & TO_X) == 0) {
6220 cur_x = text_start_x;
6221 cur_y += font_ascent();
6222 font_h = font_height();
6224 /* find specials and draw stuff */
6227 if (*p == SPECIAL_CHAR) {
6230 /* draw string before special */
6237 switch (specials[special_index].type) {
6238 case HORIZONTAL_LINE:
6240 int h = specials[special_index].height;
6241 int mid = font_ascent() / 2;
6243 w = text_start_x + text_width - cur_x;
6245 XSetLineAttributes(display, window.gc, h, LineSolid,
6246 CapButt, JoinMiter);
6247 XDrawLine(display, window.drawable, window.gc, cur_x,
6248 cur_y - mid / 2, cur_x + w, cur_y - mid / 2);
6254 int h = specials[special_index].height;
6255 int tmp_s = specials[special_index].arg;
6256 int mid = font_ascent() / 2;
6257 char ss[2] = { tmp_s, tmp_s };
6259 w = text_start_x + text_width - cur_x - 1;
6260 XSetLineAttributes(display, window.gc, h, LineOnOffDash,
6261 CapButt, JoinMiter);
6262 XSetDashes(display, window.gc, 0, ss, 2);
6263 XDrawLine(display, window.drawable, window.gc, cur_x,
6264 cur_y - mid / 2, cur_x + w, cur_y - mid / 2);
6270 int h, bar_usage, by;
6271 if (cur_x - text_start_x > maximum_width
6272 && maximum_width > 0) {
6275 h = specials[special_index].height;
6276 bar_usage = specials[special_index].arg;
6277 by = cur_y - (font_ascent() / 2) - 1;
6282 w = specials[special_index].width;
6284 w = text_start_x + text_width - cur_x - 1;
6290 XSetLineAttributes(display, window.gc, 1, LineSolid,
6291 CapButt, JoinMiter);
6293 XDrawRectangle(display, window.drawable, window.gc, cur_x,
6295 XFillRectangle(display, window.drawable, window.gc, cur_x,
6296 by, w * bar_usage / 255, h);
6304 case GAUGE: /* new GAUGE */
6307 unsigned long last_colour = current_color;
6308 float angle, px, py;
6311 if (cur_x - text_start_x > maximum_width
6312 && maximum_width > 0) {
6316 h = specials[special_index].height;
6317 by = cur_y - (font_ascent() / 2) - 1;
6322 w = specials[special_index].width;
6324 w = text_start_x + text_width - cur_x - 1;
6330 XSetLineAttributes(display, window.gc, 1, LineSolid,
6331 CapButt, JoinMiter);
6333 XDrawArc(display, window.drawable, window.gc,
6334 cur_x, by, w, h * 2, 0, 180*64);
6337 usage = specials[special_index].arg;
6338 angle = (M_PI)*(float)(usage)/255.;
6339 px = (float)(cur_x+(w/2.))-(float)(w/2.)*cos(angle);
6340 py = (float)(by+(h))-(float)(h)*sin(angle);
6342 XDrawLine(display, window.drawable, window.gc,
6343 cur_x + (w/2.), by+(h), (int)(px), (int)(py));
6351 set_foreground_color(last_colour);
6359 int h, by, i = 0, j = 0;
6361 unsigned long last_colour = current_color;
6362 unsigned long *tmpcolour = 0;
6363 if (cur_x - text_start_x > maximum_width
6364 && maximum_width > 0) {
6367 h = specials[special_index].height;
6368 by = cur_y - (font_ascent() / 2) - 1;
6373 w = specials[special_index].width;
6375 w = text_start_x + text_width - cur_x - 1;
6380 if (draw_graph_borders) {
6381 XSetLineAttributes(display, window.gc, 1, LineSolid,
6382 CapButt, JoinMiter);
6383 XDrawRectangle(display, window.drawable, window.gc,
6386 XSetLineAttributes(display, window.gc, 1, LineSolid,
6387 CapButt, JoinMiter);
6389 if (specials[special_index].last_colour != 0
6390 || specials[special_index].first_colour != 0) {
6391 tmpcolour = do_gradient(w - 1, specials[special_index].last_colour, specials[special_index].first_colour);
6394 for (i = w - 2; i > -1; i--) {
6395 if (specials[special_index].last_colour != 0
6396 || specials[special_index].first_colour != 0) {
6397 if (specials[special_index].tempgrad) {
6400 (int)((float)(w - 2) - specials[special_index].graph[j] *
6401 (w - 2) / (float)specials[special_index].graph_scale)
6405 (int)((float)(w - 2) - specials[special_index].graph[j] *
6406 (w - 2) / (float)specials[special_index].graph_scale)
6409 if (specials[special_index].graph[j] == specials[special_index].graph_scale) {
6411 (int)((float)(w - 2) - specials[special_index].graph[j] *
6412 (w - 2) / (float)specials[special_index].graph_scale)
6416 #endif /* DEBUG_lol */
6417 XSetForeground(display, window.gc, tmpcolour[
6418 (int)((float)(w - 2) - specials[special_index].graph[j] *
6419 (w - 2) / (float)specials[special_index].graph_scale)
6422 XSetForeground(display, window.gc, tmpcolour[colour_idx++]);
6425 /* this is mugfugly, but it works */
6426 XDrawLine(display, window.drawable, window.gc,
6427 cur_x + i + 1, by + h, cur_x + i + 1,
6428 round_to_int((double)by + h - specials[special_index].graph[j] *
6429 (h - 1) / specials[special_index].graph_scale));
6430 if ((w - i) / ((float) (w - 2) /
6431 (specials[special_index].graph_width)) > j
6432 && j < MAX_GRAPH_DEPTH - 3) {
6436 if (tmpcolour) free(tmpcolour);
6441 /* if (draw_mode == BG) {
6442 set_foreground_color(default_bg_color);
6443 } else if (draw_mode == OUTLINE) {
6444 set_foreground_color(default_out_color);
6446 set_foreground_color(default_fg_color);
6448 if (show_graph_range) {
6451 unsigned short int seconds = update_interval * w;
6456 unsigned short int timeunits;
6458 timeunits = seconds / 86400; seconds %= 86400;
6459 if (timeunits > 0) {
6460 asprintf(&tmp_day_str, "%dd", timeunits);
6462 tmp_day_str = strdup("");
6464 timeunits = seconds / 3600; seconds %= 3600;
6465 if (timeunits > 0) {
6466 asprintf(&tmp_hour_str, "%dh", timeunits);
6468 tmp_hour_str = strdup("");
6470 timeunits = seconds / 60; seconds %= 60;
6471 if (timeunits > 0) {
6472 asprintf(&tmp_min_str, "%dm", timeunits);
6474 tmp_min_str = strdup("");
6477 asprintf(&tmp_sec_str, "%ds", seconds);
6479 tmp_sec_str = strdup("");
6481 asprintf(&tmp_str, "%s%s%s%s", tmp_day_str, tmp_hour_str, tmp_min_str, tmp_sec_str);
6482 free(tmp_day_str); free(tmp_hour_str); free(tmp_min_str); free(tmp_sec_str);
6484 asprintf(&tmp_str, "Range not possible"); // should never happen, but better safe then sorry
6486 cur_x += (w / 2) - (font_ascent() * (strlen(tmp_str) / 2));
6487 cur_y += font_h / 2;
6488 draw_string(tmp_str);
6494 if (show_graph_scale && (specials[special_index].show_scale == 1)) {
6497 cur_x += font_ascent() / 2;
6498 cur_y += font_h / 2;
6500 calloc(log10(floor(specials[special_index].graph_scale)) + 4,
6502 sprintf(tmp_str, "%.1f", specials[special_index].graph_scale);
6503 draw_string(tmp_str);
6509 set_foreground_color(last_colour);
6515 int old = font_ascent();
6517 cur_y -= font_ascent();
6518 selected_font = specials[special_index].font_added;
6519 if (cur_y + font_ascent() < cur_y + old) {
6522 cur_y += font_ascent();
6524 font_h = font_height();
6528 if (draw_mode == FG) {
6529 set_foreground_color(specials[special_index].arg);
6534 if (draw_mode == BG) {
6535 set_foreground_color(specials[special_index].arg);
6540 if (draw_mode == OUTLINE) {
6541 set_foreground_color(specials[special_index].arg);
6546 w += specials[special_index].arg;
6550 cur_y += specials[special_index].arg;
6554 if (specials[special_index].arg >= 0) {
6555 cur_x = (int) specials[special_index].arg;
6561 int start = specials[special_index].arg;
6562 int step = specials[special_index].width;
6564 if (!step || step < 0) {
6567 w = step - (cur_x - text_start_x - start) % step;
6573 /* TODO: add back in "+ border_margin" to the end of
6575 int pos_x = text_start_x + text_width -
6576 get_string_width_special(s);
6578 /* printf("pos_x %i text_start_x %i text_width %i cur_x %i "
6579 "get_string_width(p) %i gap_x %i "
6580 "specials[special_index].arg %i border_margin %i "
6581 "border_width %i\n", pos_x, text_start_x, text_width,
6582 cur_x, get_string_width_special(s), gap_x,
6583 specials[special_index].arg, border_margin,
6585 if (pos_x > specials[special_index].arg && pos_x > cur_x) {
6586 cur_x = pos_x - specials[special_index].arg;
6593 int pos_x = (text_width) / 2 - get_string_width_special(s) /
6594 2 - (cur_x - text_start_x);
6595 /* int pos_x = text_start_x + text_width / 2 -
6596 get_string_width_special(s) / 2; */
6598 /* printf("pos_x %i text_start_x %i text_width %i cur_x %i "
6599 "get_string_width(p) %i gap_x %i "
6600 "specials[special_index].arg %i\n", pos_x, text_start_x,
6601 text_width, cur_x, get_string_width(s), gap_x,
6602 specials[special_index].arg); */
6603 if (pos_x > specials[special_index].arg) {
6604 w = pos_x - specials[special_index].arg;
6618 if (cur_y_add > 0) {
6622 cur_y += font_descent();
6627 static void draw_text(void)
6630 if (output_methods & TO_X) {
6631 cur_y = text_start_y;
6634 if (draw_borders && border_width > 0) {
6635 unsigned int b = (border_width + 1) / 2;
6637 if (stippled_borders) {
6638 char ss[2] = { stippled_borders, stippled_borders };
6639 XSetLineAttributes(display, window.gc, border_width, LineOnOffDash,
6640 CapButt, JoinMiter);
6641 XSetDashes(display, window.gc, 0, ss, 2);
6643 XSetLineAttributes(display, window.gc, border_width, LineSolid,
6644 CapButt, JoinMiter);
6647 XDrawRectangle(display, window.drawable, window.gc,
6648 text_start_x - border_margin + b, text_start_y - border_margin + b,
6649 text_width + border_margin * 2 - 1 - b * 2,
6650 text_height + border_margin * 2 - 1 - b * 2);
6657 for_each_line(text_buffer, draw_line);
6660 static void draw_stuff(void)
6662 if (overwrite_file) {
6663 overwrite_fpointer = fopen(overwrite_file, "w");
6664 if(!overwrite_fpointer)
6665 ERR("Can't overwrite '%s' anymore", overwrite_file);
6668 append_fpointer = fopen(append_file, "a");
6669 if(!append_fpointer)
6670 ERR("Can't append '%s' anymore", append_file);
6673 if (output_methods & TO_X) {
6675 if (draw_shades && !draw_outline) {
6678 set_foreground_color(default_bg_color);
6689 for (i = -1; i < 2; i++) {
6690 for (j = -1; j < 2; j++) {
6691 if (i == 0 && j == 0) {
6696 set_foreground_color(default_out_color);
6697 draw_mode = OUTLINE;
6705 set_foreground_color(default_fg_color);
6711 if (output_methods & TO_X) {
6716 swap.swap_window = window.window;
6717 swap.swap_action = XdbeBackground;
6718 XdbeSwapBuffers(display, &swap, 1);
6723 if(overwrite_fpointer) {
6724 fclose(overwrite_fpointer);
6725 overwrite_fpointer = 0;
6727 if(append_fpointer) {
6728 fclose(append_fpointer);
6729 append_fpointer = 0;
6734 static void clear_text(int exposures)
6738 /* The swap action is XdbeBackground, which clears */
6742 if (display && window.window) { // make sure these are !null
6743 /* there is some extra space for borders and outlines */
6744 XClearArea(display, window.window, text_start_x - border_margin - 1,
6745 text_start_y - border_margin - 1,
6746 text_width + border_margin * 2 + 2,
6747 text_height + border_margin * 2 + 2, exposures ? True : 0);
6752 static int need_to_update;
6754 /* update_text() generates new text and clears old text area */
6755 static void update_text(void)
6762 if (output_methods & TO_X)
6768 #ifdef HAVE_SYS_INOTIFY_H
6772 static void main_loop(void)
6775 #ifdef SIGNAL_BLOCKING
6776 sigset_t newmask, oldmask;
6779 #ifdef HAVE_SYS_INOTIFY_H
6780 int inotify_config_wd = 0;
6781 #define INOTIFY_EVENT_SIZE (sizeof(struct inotify_event))
6782 #define INOTIFY_BUF_LEN (20 * (INOTIFY_EVENT_SIZE + 16))
6783 char inotify_buff[INOTIFY_BUF_LEN];
6784 #endif /* HAVE_SYS_INOTIFY_H */
6787 #ifdef SIGNAL_BLOCKING
6788 sigemptyset(&newmask);
6789 sigaddset(&newmask, SIGINT);
6790 sigaddset(&newmask, SIGTERM);
6791 sigaddset(&newmask, SIGUSR1);
6794 last_update_time = 0.0;
6795 next_update_time = get_time();
6797 while (terminate == 0 && (total_run_times == 0 || info.looped < total_run_times)) {
6800 #ifdef SIGNAL_BLOCKING
6801 /* block signals. we will inspect for pending signals later */
6802 if (sigprocmask(SIG_BLOCK, &newmask, &oldmask) < 0) {
6803 CRIT_ERR("unable to sigprocmask()");
6808 if (output_methods & TO_X) {
6811 /* wait for X event or timeout */
6813 if (!XPending(display)) {
6817 t = next_update_time - get_time();
6821 } else if (t > update_interval) {
6822 t = update_interval;
6825 tv.tv_sec = (long) t;
6826 tv.tv_usec = (long) (t * 1000000) % 1000000;
6828 FD_SET(ConnectionNumber(display), &fdsr);
6830 s = select(ConnectionNumber(display) + 1, &fdsr, 0, 0, &tv);
6832 if (errno != EINTR) {
6833 ERR("can't select(): %s", strerror(errno));
6843 if (need_to_update) {
6845 int wx = window.x, wy = window.y;
6853 /* resize window if it isn't right size */
6855 && (text_width + border_margin * 2 + 1 != window.width
6856 || text_height + border_margin * 2 + 1 != window.height)) {
6857 window.width = text_width + border_margin * 2 + 1;
6858 window.height = text_height + border_margin * 2 + 1;
6859 XResizeWindow(display, window.window, window.width,
6862 set_transparent_background(window.window);
6866 /* move window if it isn't in right position */
6867 if (!fixed_pos && (window.x != wx || window.y != wy)) {
6868 XMoveWindow(display, window.window, window.x, window.y);
6879 r.x = text_start_x - border_margin;
6880 r.y = text_start_y - border_margin;
6881 r.width = text_width + border_margin * 2;
6882 r.height = text_height + border_margin * 2;
6883 XUnionRectWithRegion(&r, x11_stuff.region, x11_stuff.region);
6888 /* handle X events */
6889 while (XPending(display)) {
6892 XNextEvent(display, &ev);
6899 r.width = ev.xexpose.width;
6900 r.height = ev.xexpose.height;
6901 XUnionRectWithRegion(&r, x11_stuff.region, x11_stuff.region);
6906 case ReparentNotify:
6907 /* set background to ParentRelative for all parents */
6909 set_transparent_background(window.window);
6913 case ConfigureNotify:
6915 /* if window size isn't what expected, set fixed size */
6916 if (ev.xconfigure.width != window.width
6917 || ev.xconfigure.height != window.height) {
6918 if (window.width != 0 && window.height != 0) {
6922 /* clear old stuff before screwing up
6927 XWindowAttributes attrs;
6928 if (XGetWindowAttributes(display,
6929 window.window, &attrs)) {
6930 window.width = attrs.width;
6931 window.height = attrs.height;
6935 text_width = window.width - border_margin * 2 - 1;
6936 text_height = window.height - border_margin * 2 - 1;
6937 if (text_width > maximum_width
6938 && maximum_width > 0) {
6939 text_width = maximum_width;
6943 /* if position isn't what expected, set fixed pos
6944 * total_updates avoids setting fixed_pos when window
6945 * is set to weird locations when started */
6946 /* // this is broken
6947 if (total_updates >= 2 && !fixed_pos
6948 && (window.x != ev.xconfigure.x
6949 || window.y != ev.xconfigure.y)
6950 && (ev.xconfigure.x != 0
6951 || ev.xconfigure.y != 0)) {
6959 /* if an ordinary window with decorations */
6960 if ((window.type == TYPE_NORMAL)
6961 && (!TEST_HINT(window.hints,
6962 HINT_UNDECORATED))) {
6963 /* allow conky to hold input focus. */
6966 /* forward the click to the desktop window */
6967 XUngrabPointer(display, ev.xbutton.time);
6968 ev.xbutton.window = window.desktop;
6969 ev.xbutton.x = ev.xbutton.x_root;
6970 ev.xbutton.y = ev.xbutton.y_root;
6971 XSendEvent(display, ev.xbutton.window, False,
6972 ButtonPressMask, &ev);
6973 XSetInputFocus(display, ev.xbutton.window,
6974 RevertToParent, ev.xbutton.time);
6981 /* if an ordinary window with decorations */
6982 if ((window.type == TYPE_NORMAL)
6983 && (!TEST_HINT(window.hints,
6984 HINT_UNDECORATED))) {
6985 /* allow conky to hold input focus. */
6988 /* forward the release to the desktop window */
6989 ev.xbutton.window = window.desktop;
6990 ev.xbutton.x = ev.xbutton.x_root;
6991 ev.xbutton.y = ev.xbutton.y_root;
6992 XSendEvent(display, ev.xbutton.window, False,
6993 ButtonReleaseMask, &ev);
7002 if (ev.type == x11_stuff.event_base + XDamageNotify) {
7003 XDamageNotifyEvent *dev = (XDamageNotifyEvent *) &ev;
7005 XFixesSetRegion(display, x11_stuff.part, &dev->area, 1);
7006 XFixesUnionRegion(display, x11_stuff.region2, x11_stuff.region2, x11_stuff.part);
7008 #endif /* HAVE_XDAMAGE */
7014 XDamageSubtract(display, x11_stuff.damage, x11_stuff.region2, None);
7015 XFixesSetRegion(display, x11_stuff.region2, 0, 0);
7016 #endif /* HAVE_XDAMAGE */
7018 /* XDBE doesn't seem to provide a way to clear the back buffer without
7019 * interfering with the front buffer, other than passing XdbeBackground
7020 * to XdbeSwapBuffers. That means that if we're using XDBE, we need to
7021 * redraw the text even if it wasn't part of the exposed area. OTOH,
7022 * if we're not going to call draw_stuff at all, then no swap happens
7023 * and we can safely do nothing. */
7025 if (!XEmptyRegion(x11_stuff.region)) {
7030 r.x = text_start_x - border_margin;
7031 r.y = text_start_y - border_margin;
7032 r.width = text_width + border_margin * 2;
7033 r.height = text_height + border_margin * 2;
7034 XUnionRectWithRegion(&r, x11_stuff.region, x11_stuff.region);
7037 XSetRegion(display, window.gc, x11_stuff.region);
7040 XftDrawSetClip(window.xftdraw, x11_stuff.region);
7044 cimlib_render(text_start_x, text_start_y, window.width, window.height);
7047 XDestroyRegion(x11_stuff.region);
7048 x11_stuff.region = XCreateRegion();
7052 t = (next_update_time - get_time()) * 1000000;
7053 if(t > 0) usleep((useconds_t)t);
7060 #ifdef SIGNAL_BLOCKING
7061 /* unblock signals of interest and let handler fly */
7062 if (sigprocmask(SIG_SETMASK, &oldmask, NULL) < 0) {
7063 CRIT_ERR("unable to sigprocmask()");
7067 switch (g_signal_pending) {
7070 ERR("received SIGHUP or SIGUSR1. reloading the config file.");
7075 ERR("received SIGINT or SIGTERM to terminate. bye!");
7079 if (output_methods & TO_X) {
7080 XDestroyRegion(x11_stuff.region);
7081 x11_stuff.region = NULL;
7083 XDamageDestroy(display, x11_stuff.damage);
7084 XFixesDestroyRegion(display, x11_stuff.region2);
7085 XFixesDestroyRegion(display, x11_stuff.part);
7086 #endif /* HAVE_XDAMAGE */
7092 if(overwrite_file) {
7093 free(overwrite_file);
7102 /* Reaching here means someone set a signal
7103 * (SIGXXXX, signal_handler), but didn't write any code
7105 * If you don't want to handle a signal, don't set a handler on
7106 * it in the first place. */
7107 if (g_signal_pending) {
7108 ERR("ignoring signal (%d)", g_signal_pending);
7112 #ifdef HAVE_SYS_INOTIFY_H
7113 if (inotify_fd && !inotify_config_wd) {
7114 inotify_config_wd = inotify_add_watch(inotify_fd,
7118 if (inotify_fd && inotify_config_wd) {
7119 int len = 0, idx = 0;
7121 struct timeval time_to_wait;
7123 FD_ZERO (&descriptors);
7124 FD_SET(inotify_fd, &descriptors);
7126 time_to_wait.tv_sec = time_to_wait.tv_usec = 0;
7128 select(inotify_fd + 1, &descriptors, NULL, NULL, &time_to_wait);
7129 if (FD_ISSET(inotify_fd, &descriptors)) {
7130 /* process inotify events */
7131 len = read(inotify_fd, inotify_buff, INOTIFY_BUF_LEN);
7132 while (len > 0 && idx < len) {
7133 struct inotify_event *ev = (struct inotify_event *) &inotify_buff[idx];
7134 if (ev->wd == inotify_config_wd && (ev->mask & IN_MODIFY || ev->mask & IN_IGNORED)) {
7135 /* current_config should be reloaded */
7136 ERR("'%s' modified, reloading...", current_config);
7138 if (ev->mask & IN_IGNORED) {
7139 /* for some reason we get IN_IGNORED here
7140 * sometimes, so we need to re-add the watch */
7141 inotify_config_wd = inotify_add_watch(inotify_fd,
7148 llua_inotify_query(ev->wd, ev->mask);
7150 #endif /* HAVE_LUA */
7151 idx += INOTIFY_EVENT_SIZE + ev->len;
7155 #endif /* HAVE_SYS_INOTIFY_H */
7157 g_signal_pending = 0;
7160 #ifdef HAVE_SYS_INOTIFY_H
7162 inotify_rm_watch(inotify_fd, inotify_config_wd);
7164 inotify_fd = inotify_config_wd = 0;
7166 #endif /* HAVE_SYS_INOTIFY_H */
7169 X11_destroy_window();
7173 static void load_config_file(const char *);
7174 static void load_config_file_x11(const char *);
7176 /* reload the config file */
7177 static void reload_config(void)
7179 timed_thread_destroy_registered_threads();
7181 if (info.cpu_usage) {
7182 free(info.cpu_usage);
7183 info.cpu_usage = NULL;
7194 #ifdef TCP_PORT_MONITOR
7195 tcp_portmon_clear();
7200 #endif /* HAVE_LUA */
7203 X11_destroy_window();
7206 if (current_config) {
7208 load_config_file(current_config);
7209 load_config_file_x11(current_config);
7211 /* re-init specials array */
7212 if ((specials = realloc((void *) specials,
7213 sizeof(struct special_t) * max_specials)) == 0) {
7214 ERR("failed to realloc specials array");
7218 if (output_methods & TO_X) {
7219 X11_initialisation();
7222 extract_variable_text(global_text);
7228 tmpstring1 = malloc(text_buffer_size);
7229 memset(tmpstring1, 0, text_buffer_size);
7233 tmpstring2 = malloc(text_buffer_size);
7234 memset(tmpstring2, 0, text_buffer_size);
7238 text_buffer = malloc(max_user_text);
7239 memset(text_buffer, 0, max_user_text);
7241 X11_create_window();
7247 static void clean_up(void)
7250 timed_thread_destroy_registered_threads();
7252 if (info.cpu_usage) {
7253 free(info.cpu_usage);
7254 info.cpu_usage = NULL;
7257 if (output_methods & TO_X) {
7260 XdbeDeallocateBackBufferName(display, window.back_buffer);
7265 XDestroyWindow(display, window.window);
7266 XClearWindow(display, RootWindow(display, screen));
7271 XClearWindow(display, RootWindow(display, screen));
7276 XFreeGC(display, window.gc);
7282 for (i = 0; i < MAX_TEMPLATES; i++) {
7289 free_text_objects(&global_root_object, 0);
7308 free(current_config);
7310 #ifdef TCP_PORT_MONITOR
7311 tcp_portmon_clear();
7318 #endif /* HAVE_LUA */
7321 for (i = 0; i < special_count; i++) {
7322 if (specials[i].type == GRAPH) {
7323 free(specials[i].graph);
7330 clear_diskio_stats();
7333 static int string_to_bool(const char *s)
7336 // Assumes an option without a true/false means true
7338 } else if (strcasecmp(s, "yes") == EQUAL) {
7340 } else if (strcasecmp(s, "true") == EQUAL) {
7342 } else if (strcasecmp(s, "1") == EQUAL) {
7349 static enum alignment string_to_alignment(const char *s)
7351 if (strcasecmp(s, "top_left") == EQUAL) {
7353 } else if (strcasecmp(s, "top_right") == EQUAL) {
7355 } else if (strcasecmp(s, "top_middle") == EQUAL) {
7357 } else if (strcasecmp(s, "bottom_left") == EQUAL) {
7359 } else if (strcasecmp(s, "bottom_right") == EQUAL) {
7360 return BOTTOM_RIGHT;
7361 } else if (strcasecmp(s, "bottom_middle") == EQUAL) {
7362 return BOTTOM_MIDDLE;
7363 } else if (strcasecmp(s, "middle_left") == EQUAL) {
7365 } else if (strcasecmp(s, "middle_right") == EQUAL) {
7366 return MIDDLE_RIGHT;
7367 } else if (strcasecmp(s, "tl") == EQUAL) {
7369 } else if (strcasecmp(s, "tr") == EQUAL) {
7371 } else if (strcasecmp(s, "tm") == EQUAL) {
7373 } else if (strcasecmp(s, "bl") == EQUAL) {
7375 } else if (strcasecmp(s, "br") == EQUAL) {
7376 return BOTTOM_RIGHT;
7377 } else if (strcasecmp(s, "bm") == EQUAL) {
7378 return BOTTOM_MIDDLE;
7379 } else if (strcasecmp(s, "ml") == EQUAL) {
7381 } else if (strcasecmp(s, "mr") == EQUAL) {
7382 return MIDDLE_RIGHT;
7383 } else if (strcasecmp(s, "none") == EQUAL) {
7391 static void set_default_configurations_for_x(void)
7393 default_fg_color = WhitePixel(display, screen);
7394 default_bg_color = BlackPixel(display, screen);
7395 default_out_color = BlackPixel(display, screen);
7396 color0 = default_fg_color;
7397 color1 = default_fg_color;
7398 color2 = default_fg_color;
7399 color3 = default_fg_color;
7400 color4 = default_fg_color;
7401 color5 = default_fg_color;
7402 color6 = default_fg_color;
7403 color7 = default_fg_color;
7404 color8 = default_fg_color;
7405 color9 = default_fg_color;
7409 static void set_default_configurations(void)
7413 fork_to_background = 0;
7414 total_run_times = 0;
7415 info.cpu_avg_samples = 2;
7416 info.net_avg_samples = 2;
7417 info.diskio_avg_samples = 2;
7422 format_human_readable = 1;
7426 mpd_set_host("localhost");
7427 mpd_set_port("6600");
7430 info.xmms2.artist = NULL;
7431 info.xmms2.album = NULL;
7432 info.xmms2.title = NULL;
7433 info.xmms2.genre = NULL;
7434 info.xmms2.comment = NULL;
7435 info.xmms2.url = NULL;
7436 info.xmms2.status = NULL;
7437 info.xmms2.playlist = NULL;
7439 use_spacer = NO_SPACER;
7441 output_methods = TO_X;
7443 output_methods = TO_STDOUT;
7446 show_graph_scale = 0;
7447 show_graph_range = 0;
7450 draw_graph_borders = 1;
7452 set_first_font("6x10");
7460 window.type = TYPE_NORMAL;
7462 strcpy(window.class_name, PACKAGE_NAME);
7463 sprintf(window.title, PACKAGE_NAME" (%s)", info.uname_s.nodename);
7465 stippled_borders = 0;
7468 text_alignment = BOTTOM_LEFT;
7469 info.x11.monitor.number = 1;
7470 info.x11.monitor.current = 0;
7473 for (i = 0; i < MAX_TEMPLATES; i++) {
7474 template[i] = strdup("");
7477 free(current_mail_spool);
7481 variable_substitute(MAIL_FILE, buf, 256);
7482 if (buf[0] != '\0') {
7483 current_mail_spool = strndup(buf, text_buffer_size);
7488 update_interval = 3.0;
7489 info.music_player_interval = 1.0;
7490 stuff_in_upper_case = 0;
7491 info.users.number = 1;
7493 #ifdef TCP_PORT_MONITOR
7494 /* set default connection limit */
7495 tcp_portmon_set_max_connections(0);
7499 /* returns 1 if you can overwrite or create the file at 'path' */
7500 static _Bool overwrite_works(const char *path)
7504 if (!(filepointer = fopen(path, "w")))
7506 fclose(filepointer);
7510 /* returns 1 if you can append or create the file at 'path' */
7511 static _Bool append_works(const char *path)
7515 if (!(filepointer = fopen(path, "a")))
7517 fclose(filepointer);
7523 /* WARNING, this type not in Xlib spec */
7524 int x11_error_handler(Display *d, XErrorEvent *err)
7525 __attribute__((noreturn));
7526 int x11_error_handler(Display *d, XErrorEvent *err)
7528 ERR("X Error: type %i Display %lx XID %li serial %lu error_code %i request_code %i minor_code %i other Display: %lx\n",
7530 (long unsigned)err->display,
7531 (long)err->resourceid,
7541 int x11_ioerror_handler(Display *d)
7542 __attribute__((noreturn));
7543 int x11_ioerror_handler(Display *d)
7545 ERR("X Error: Display %lx\n",
7552 static void X11_initialisation(void)
7554 if (x_initialised == YES) return;
7555 output_methods |= TO_X;
7557 set_default_configurations_for_x();
7558 x_initialised = YES;
7561 /* WARNING, this type not in Xlib spec */
7562 XSetErrorHandler(&x11_error_handler);
7563 XSetIOErrorHandler(&x11_ioerror_handler);
7567 static void X11_destroy_window(void)
7569 /* this function only exists for the sake of consistency */
7570 if (output_methods & TO_X) {
7572 XDamageDestroy(display, x11_stuff.damage);
7573 XFixesDestroyRegion(display, x11_stuff.region2);
7574 XFixesDestroyRegion(display, x11_stuff.part);
7575 if (x11_stuff.region) {
7576 XDestroyRegion(x11_stuff.region);
7578 x11_stuff.region = NULL;
7579 #endif /* HAVE_XDAMAGE */
7585 static char **xargv = 0;
7586 static int xargc = 0;
7588 static void X11_create_window(void)
7590 if (output_methods & TO_X) {
7592 init_window(own_window, text_width + border_margin * 2 + 1,
7593 text_height + border_margin * 2 + 1, set_transparent, background_colour,
7595 #else /* OWN_WINDOW */
7596 init_window(0, text_width + border_margin * 2 + 1,
7597 text_height + border_margin * 2 + 1, set_transparent, 0,
7599 #endif /* OWN_WINDOW */
7603 update_text_area(); /* to position text/window on screen */
7606 if (own_window && !fixed_pos) {
7607 XMoveWindow(display, window.window, window.x, window.y);
7610 set_transparent_background(window.window);
7618 x11_stuff.region = XCreateRegion();
7620 if (!XDamageQueryExtension(display, &x11_stuff.event_base, &x11_stuff.error_base)) {
7621 ERR("Xdamage extension unavailable");
7623 x11_stuff.damage = XDamageCreate(display, window.window, XDamageReportNonEmpty);
7624 x11_stuff.region2 = XFixesCreateRegionFromWindow(display, window.window, 0);
7625 x11_stuff.part = XFixesCreateRegionFromWindow(display, window.window, 0);
7626 #endif /* HAVE_XDAMAGE */
7629 update_text_area(); /* to get initial size of the window */
7634 #define CONF_ERR ERR("%s: %d: config file error", f, line)
7635 #define CONF_ERR2(a) ERR("%s: %d: config file error: %s", f, line, a)
7636 #define CONF2(a) if (strcasecmp(name, a) == 0)
7637 #define CONF(a) else CONF2(a)
7638 #define CONF3(a, b) else if (strcasecmp(name, a) == 0 \
7639 || strcasecmp(name, b) == 0)
7640 #define CONF_CONTINUE 1
7641 #define CONF_BREAK 2
7642 #define CONF_BUFF_SIZE 512
7644 static FILE *open_config_file(const char *f)
7646 #ifdef CONFIG_OUTPUT
7647 if (!strcmp(f, "==builtin==")) {
7648 #ifdef HAVE_FOPENCOOKIE
7649 return fopencookie(NULL, "r", conf_cookie);
7650 #endif /* HAVE_FOPENCOOKIE */
7652 #endif /* CONFIG_OUTPUT */
7653 return fopen(f, "r");
7656 static int do_config_step(int *line, FILE *fp, char *buf, char **name, char **value)
7660 if (fgets(buf, CONF_BUFF_SIZE, fp) == NULL) {
7663 remove_comments(buf);
7668 while (*p && isspace((int) *p)) {
7672 return CONF_CONTINUE; /* empty line */
7679 while (*p2 && !isspace((int) *p2)) {
7683 *p2 = '\0'; /* break at name's end */
7690 while (*p && isspace((int) *p)) {
7696 p2 = *value + strlen(*value);
7697 while (isspace((int) *(p2 - 1))) {
7706 static void load_config_file(const char *f)
7711 set_default_configurations();
7712 fp = open_config_file(f);
7716 DBGP("reading contents from config file '%s'", f);
7719 char buff[CONF_BUFF_SIZE], *name, *value;
7720 int ret = do_config_step(&line, fp, buff, &name, &value);
7721 if (ret == CONF_BREAK) {
7723 } else if (ret == CONF_CONTINUE) {
7729 /* don't listen if X is already initialised or
7730 * if we already know we don't want it */
7731 if(x_initialised == NO) {
7732 if (string_to_bool(value)) {
7733 output_methods &= TO_X;
7735 output_methods &= ~TO_X;
7736 x_initialised = NEVER;
7741 if (!value || x_initialised == YES) {
7746 disp = strdup(value);
7750 if (window.type == TYPE_DOCK)
7753 int a = string_to_alignment(value);
7764 CONF("background") {
7765 fork_to_background = string_to_bool(value);
7768 CONF2("background") {
7769 fork_to_background = string_to_bool(value);
7773 CONF("show_graph_scale") {
7774 show_graph_scale = string_to_bool(value);
7776 CONF("show_graph_range") {
7777 show_graph_range = string_to_bool(value);
7779 CONF("border_margin") {
7781 border_margin = strtol(value, 0, 0);
7786 CONF("border_width") {
7788 border_width = strtol(value, 0, 0);
7794 #define TEMPLATE_CONF(n) \
7795 CONF("template"#n) { \
7797 free(template[n]); \
7798 template[n] = strdup(value); \
7815 info.mail = parse_mail_args(IMAP_TYPE, value);
7822 info.mail = parse_mail_args(POP3_TYPE, value);
7827 CONF("default_bar_size") {
7830 if (sscanf(value, "%d %d", &default_bar_width, &default_bar_height) != 2) {
7837 CONF_ERR2("default_bar_size takes 2 integer arguments (ie. 'default_bar_size 0 6')")
7841 CONF("default_graph_size") {
7844 if (sscanf(value, "%d %d", &default_graph_width, &default_graph_height) != 2) {
7851 CONF_ERR2("default_graph_size takes 2 integer arguments (ie. 'default_graph_size 0 6')")
7854 CONF("default_gauge_size") {
7857 if (sscanf(value, "%d %d", &default_gauge_width, &default_gauge_height) != 2) {
7864 CONF_ERR2("default_gauge_size takes 2 integer arguments (ie. 'default_gauge_size 0 6')")
7871 mpd_set_host(value);
7877 if (value && mpd_set_port(value)) {
7881 CONF("mpd_password") {
7883 mpd_set_password(value);
7889 CONF("music_player_interval") {
7891 info.music_player_interval = strtod(value, 0);
7897 CONF("sensor_device") {
7899 sensor_device = strtol(value, 0, 0);
7905 CONF("cpu_avg_samples") {
7907 cpu_avg_samples = strtol(value, 0, 0);
7908 if (cpu_avg_samples < 1 || cpu_avg_samples > 14) {
7911 info.cpu_avg_samples = cpu_avg_samples;
7917 CONF("net_avg_samples") {
7919 net_avg_samples = strtol(value, 0, 0);
7920 if (net_avg_samples < 1 || net_avg_samples > 14) {
7923 info.net_avg_samples = net_avg_samples;
7929 CONF("diskio_avg_samples") {
7931 diskio_avg_samples = strtol(value, 0, 0);
7932 if (diskio_avg_samples < 1 || diskio_avg_samples > 14) {
7935 info.diskio_avg_samples = diskio_avg_samples;
7943 CONF("double_buffer") {
7944 use_xdbe = string_to_bool(value);
7948 CONF("override_utf8_locale") {
7949 utf8_mode = string_to_bool(value);
7951 CONF("draw_borders") {
7952 draw_borders = string_to_bool(value);
7954 CONF("draw_graph_borders") {
7955 draw_graph_borders = string_to_bool(value);
7957 CONF("draw_shades") {
7958 draw_shades = string_to_bool(value);
7960 CONF("draw_outline") {
7961 draw_outline = string_to_bool(value);
7964 CONF("out_to_console") {
7965 if(string_to_bool(value))
7966 output_methods |= TO_STDOUT;
7968 CONF("out_to_stderr") {
7969 if(string_to_bool(value))
7970 output_methods |= TO_STDERR;
7972 CONF("overwrite_file") {
7973 if(overwrite_file) {
7974 free(overwrite_file);
7977 if(overwrite_works(value)) {
7978 overwrite_file = strdup(value);
7979 output_methods |= OVERWRITE_FILE;
7981 ERR("overwrite_file won't be able to create/overwrite '%s'", value);
7983 CONF("append_file") {
7988 if(append_works(value)) {
7989 append_file = strdup(value);
7990 output_methods |= APPEND_FILE;
7992 ERR("append_file won't be able to create/append '%s'", value);
7994 CONF("use_spacer") {
7996 if (strcasecmp(value, "left") == EQUAL) {
7997 use_spacer = LEFT_SPACER;
7998 } else if (strcasecmp(value, "right") == EQUAL) {
7999 use_spacer = RIGHT_SPACER;
8000 } else if (strcasecmp(value, "none") == EQUAL) {
8001 use_spacer = NO_SPACER;
8003 use_spacer = string_to_bool(value);
8004 ERR("use_spacer should have an argument of left, right, or"
8005 " none. '%s' seems to be some form of '%s', so"
8006 " defaulting to %s.", value,
8007 use_spacer ? "true" : "false",
8008 use_spacer ? "right" : "none");
8010 use_spacer = RIGHT_SPACER;
8012 use_spacer = NO_SPACER;
8016 ERR("use_spacer should have an argument. Defaulting to right.");
8017 use_spacer = RIGHT_SPACER;
8023 use_xft = string_to_bool(value);
8027 set_first_font(value);
8031 if (value && font_count >= 0) {
8032 fonts[0].font_alpha = atof(value) * 65535.0;
8039 if (string_to_bool(value)) {
8040 ERR("Xft not enabled at compile time");
8044 /* xftfont silently ignored when no Xft */
8047 /* xftalpha is silently ignored when no Xft */
8052 set_first_font(value);
8060 gap_x = atoi(value);
8067 gap_y = atoi(value);
8073 CONF("mail_spool") {
8077 variable_substitute(value, buffer, 256);
8079 if (buffer[0] != '\0') {
8080 if (current_mail_spool) {
8081 free(current_mail_spool);
8083 current_mail_spool = strndup(buffer, text_buffer_size);
8090 CONF("minimum_size") {
8092 if (sscanf(value, "%d %d", &minimum_width, &minimum_height)
8094 if (sscanf(value, "%d", &minimum_width) != 1) {
8102 CONF("maximum_width") {
8104 if (sscanf(value, "%d", &maximum_width) != 1) {
8112 CONF("no_buffers") {
8113 no_buffers = string_to_bool(value);
8115 CONF("top_name_width") {
8117 if (sscanf(value, "%u", &top_name_width) != 1) {
8123 if (top_name_width >= max_user_text) {
8124 top_name_width = max_user_text - 1;
8127 CONF("top_cpu_separate") {
8128 cpu_separate = string_to_bool(value);
8130 CONF("short_units") {
8131 short_units = string_to_bool(value);
8133 CONF("format_human_readable") {
8134 format_human_readable = string_to_bool(value);
8136 CONF("pad_percents") {
8137 pad_percents = atoi(value);
8141 CONF("own_window") {
8143 own_window = string_to_bool(value);
8146 CONF("own_window_class") {
8148 memset(window.class_name, 0, sizeof(window.class_name));
8149 strncpy(window.class_name, value,
8150 sizeof(window.class_name) - 1);
8153 CONF("own_window_title") {
8155 memset(window.title, 0, sizeof(window.title));
8156 strncpy(window.title, value, sizeof(window.title) - 1);
8159 CONF("own_window_transparent") {
8161 set_transparent = string_to_bool(value);
8164 CONF("own_window_hints") {
8166 char *p_hint, *p_save;
8167 char delim[] = ", ";
8169 /* tokenize the value into individual hints */
8170 if ((p_hint = strtok_r(value, delim, &p_save)) != NULL) {
8172 /* fprintf(stderr, "hint [%s] parsed\n", p_hint); */
8173 if (strncmp(p_hint, "undecorate", 10) == EQUAL) {
8174 SET_HINT(window.hints, HINT_UNDECORATED);
8175 } else if (strncmp(p_hint, "below", 5) == EQUAL) {
8176 SET_HINT(window.hints, HINT_BELOW);
8177 } else if (strncmp(p_hint, "above", 5) == EQUAL) {
8178 SET_HINT(window.hints, HINT_ABOVE);
8179 } else if (strncmp(p_hint, "sticky", 6) == EQUAL) {
8180 SET_HINT(window.hints, HINT_STICKY);
8181 } else if (strncmp(p_hint, "skip_taskbar", 12) == EQUAL) {
8182 SET_HINT(window.hints, HINT_SKIP_TASKBAR);
8183 } else if (strncmp(p_hint, "skip_pager", 10) == EQUAL) {
8184 SET_HINT(window.hints, HINT_SKIP_PAGER);
8189 p_hint = strtok_r(NULL, delim, &p_save);
8190 } while (p_hint != NULL);
8196 CONF("own_window_type") {
8198 if (strncmp(value, "normal", 6) == EQUAL) {
8199 window.type = TYPE_NORMAL;
8200 } else if (strncmp(value, "desktop", 7) == EQUAL) {
8201 window.type = TYPE_DESKTOP;
8202 } else if (strncmp(value, "dock", 7) == EQUAL) {
8203 window.type = TYPE_DOCK;
8204 text_alignment = TOP_LEFT;
8205 } else if (strncmp(value, "override", 8) == EQUAL) {
8206 window.type = TYPE_OVERRIDE;
8215 CONF("stippled_borders") {
8217 stippled_borders = strtol(value, 0, 0);
8219 stippled_borders = 4;
8223 CONF("imlib_cache_size") {
8225 cimlib_set_cache_size(atoi(value));
8228 CONF("imlib_cache_flush_interval") {
8230 cimlib_set_cache_flush_interval(atoi(value));
8235 CONF("update_interval") {
8237 update_interval = strtod(value, 0);
8241 if (info.music_player_interval == 0) {
8242 // default to update_interval
8243 info.music_player_interval = update_interval;
8246 CONF("total_run_times") {
8248 total_run_times = strtod(value, 0);
8254 stuff_in_upper_case = string_to_bool(value);
8256 CONF("max_specials") {
8258 max_specials = atoi(value);
8263 CONF("max_user_text") {
8265 max_user_text = atoi(value);
8270 CONF("text_buffer_size") {
8272 text_buffer_size = atoi(value);
8273 if (text_buffer_size < DEFAULT_TEXT_BUFFER_SIZE) {
8274 ERR("text_buffer_size must be >=%i bytes", DEFAULT_TEXT_BUFFER_SIZE);
8275 text_buffer_size = DEFAULT_TEXT_BUFFER_SIZE;
8283 if (output_methods & TO_X) {
8284 X11_initialisation();
8293 global_text = (char *) malloc(1);
8294 global_text[0] = '\0';
8297 unsigned int l = strlen(global_text);
8299 char buf[CONF_BUFF_SIZE];
8301 if (fgets(buf, CONF_BUFF_SIZE, fp) == NULL) {
8307 if (bl >= 2 && buf[bl-2] == '\\' && buf[bl-1] == '\n') {
8315 /* Check for continuation of \\-\n. */
8316 if (l > 0 && buf[0] == '\n' && global_text[l-1] == '\\') {
8317 global_text[l-1] = '\0';
8321 global_text = (char *) realloc(global_text, l + bl + 1);
8322 strcat(global_text, buf);
8324 if (strlen(global_text) > max_user_text) {
8329 if (strlen(global_text) < 1) {
8330 CRIT_ERR("no text supplied in configuration; exiting");
8332 global_text_lines = line + 1;
8335 #ifdef TCP_PORT_MONITOR
8336 CONF("max_port_monitor_connections") {
8338 if (!value || (sscanf(value, "%d", &max) != 1)) {
8339 /* an error. use default, warn and continue. */
8340 tcp_portmon_set_max_connections(0);
8342 } else if (tcp_portmon_set_max_connections(max)) {
8343 /* max is < 0, default has been set*/
8348 CONF("if_up_strictness") {
8350 ERR("incorrect if_up_strictness value, defaulting to 'up'");
8351 ifup_strictness = IFUP_UP;
8352 } else if (strcasecmp(value, "up") == EQUAL) {
8353 ifup_strictness = IFUP_UP;
8354 } else if (strcasecmp(value, "link") == EQUAL) {
8355 ifup_strictness = IFUP_LINK;
8356 } else if (strcasecmp(value, "address") == EQUAL) {
8357 ifup_strictness = IFUP_ADDR;
8359 ERR("incorrect if_up_strictness value, defaulting to 'up'");
8360 ifup_strictness = IFUP_UP;
8364 CONF("temperature_unit") {
8366 ERR("config option 'temperature_unit' needs an argument, either 'celsius' or 'fahrenheit'");
8367 } else if (set_temp_output_unit(value)) {
8368 ERR("temperature_unit: incorrect argument");
8374 size_t maxlength = strlen(value); //+1 for terminating 0 not needed, 'cause of the space in the middle of value
8375 char *skey = malloc(maxlength);
8376 char *svalue = malloc(maxlength);
8378 if (sscanf(value, "%[0-9a-zA-Z_] %[^\n]", skey, svalue) == 2) {
8379 oldvalue = getenv(skey);
8380 if (oldvalue == NULL) {
8381 setenv(skey, svalue, 0);
8383 //PS: Don't free oldvalue, it's the real envvar, not a copy
8397 char *ptr = strtok(value, " ");
8400 ptr = strtok(NULL, " ");
8406 #endif /* HAVE_LUA */
8418 CONF("default_color"){}
8419 CONF3("default_shade_color", "default_shadecolor"){}
8420 CONF3("default_outline_color", "default_outlinecolor") {}
8421 CONF("own_window_colour") {}
8424 ERR("%s: %d: no such configuration: '%s'", f, line, name);
8430 if (info.music_player_interval == 0) {
8431 // default to update_interval
8432 info.music_player_interval = update_interval;
8434 if (!global_text) { // didn't supply any text
8435 CRIT_ERR("missing text block in configuration; exiting");
8439 static void load_config_file_x11(const char *f)
8444 fp = open_config_file(f);
8448 DBGP("reading contents from config file '%s'", f);
8451 char buff[CONF_BUFF_SIZE], *name, *value;
8452 int ret = do_config_step(&line, fp, buff, &name, &value);
8453 if (ret == CONF_BREAK) {
8455 } else if (ret == CONF_CONTINUE) {
8461 X11_initialisation();
8462 if (x_initialised == YES) {
8464 color0 = get_x11_color(value);
8471 X11_initialisation();
8472 if (x_initialised == YES) {
8474 color1 = get_x11_color(value);
8481 X11_initialisation();
8482 if (x_initialised == YES) {
8484 color2 = get_x11_color(value);
8491 X11_initialisation();
8492 if (x_initialised == YES) {
8494 color3 = get_x11_color(value);
8501 X11_initialisation();
8502 if (x_initialised == YES) {
8504 color4 = get_x11_color(value);
8511 X11_initialisation();
8512 if (x_initialised == YES) {
8514 color5 = get_x11_color(value);
8521 X11_initialisation();
8522 if (x_initialised == YES) {
8524 color6 = get_x11_color(value);
8531 X11_initialisation();
8532 if (x_initialised == YES) {
8534 color7 = get_x11_color(value);
8541 X11_initialisation();
8542 if (x_initialised == YES) {
8544 color8 = get_x11_color(value);
8551 X11_initialisation();
8552 if (x_initialised == YES) {
8554 color9 = get_x11_color(value);
8560 CONF("default_color") {
8561 X11_initialisation();
8562 if (x_initialised == YES) {
8564 default_fg_color = get_x11_color(value);
8570 CONF3("default_shade_color", "default_shadecolor") {
8571 X11_initialisation();
8572 if (x_initialised == YES) {
8574 default_bg_color = get_x11_color(value);
8580 CONF3("default_outline_color", "default_outlinecolor") {
8581 X11_initialisation();
8582 if (x_initialised == YES) {
8584 default_out_color = get_x11_color(value);
8591 CONF("own_window_colour") {
8592 X11_initialisation();
8593 if (x_initialised == YES) {
8595 background_colour = get_x11_color(value);
8597 ERR("Invalid colour for own_window_colour (try omitting the "
8598 "'#' for hex colours");
8604 //initialize X11 if nothing X11-related is mentioned before TEXT (and if X11 is the default outputmethod)
8605 if(output_methods & TO_X) {
8606 X11_initialisation();
8616 #undef CONF_CONTINUE
8617 #undef CONF_BUFF_SIZE
8624 static void print_help(const char *prog_name) {
8625 printf("Usage: %s [OPTION]...\n"
8626 PACKAGE_NAME" is a system monitor that renders text on desktop or to own transparent\n"
8627 "window. Command line options will override configurations defined in config\n"
8629 " -v, --version version\n"
8630 " -q, --quiet quiet mode\n"
8631 " -D, --debug increase debugging output, ie. -DD for more debugging\n"
8632 " -c, --config=FILE config file to load\n"
8633 #ifdef CONFIG_OUTPUT
8634 " -C, --print-config print the builtin default config to stdout\n"
8635 " e.g. 'conky -C > ~/.conkyrc' will create a new default config\n"
8637 " -d, --daemonize daemonize, fork to background\n"
8638 " -h, --help help\n"
8640 " -a, --alignment=ALIGNMENT text alignment on screen, {top,bottom,middle}_{left,right,middle}\n"
8641 " -f, --font=FONT font to use\n"
8642 " -X, --display=DISPLAY X11 display to use\n"
8644 " -o, --own-window create own window to draw\n"
8647 " -b, --double-buffer double buffer (prevents flickering)\n"
8649 " -w, --window-id=WIN_ID window id to draw\n"
8650 " -x X x position\n"
8651 " -y Y y position\n"
8653 " -t, --text=TEXT text to render, remember single quotes, like -t '$uptime'\n"
8654 " -u, --interval=SECS update interval\n"
8655 " -i COUNT number of times to update "PACKAGE_NAME" (and quit)\n",
8660 /* : means that character before that takes an argument */
8661 static const char *getopt_string = "vVqdDt:u:i:hc:"
8671 #ifdef CONFIG_OUTPUT
8676 static const struct option longopts[] = {
8677 { "help", 0, NULL, 'h' },
8678 { "version", 0, NULL, 'V' },
8679 { "debug", 0, NULL, 'D' },
8680 { "config", 1, NULL, 'c' },
8681 #ifdef CONFIG_OUTPUT
8682 { "print-config", 0, NULL, 'C' },
8684 { "daemonize", 0, NULL, 'd' },
8686 { "alignment", 1, NULL, 'a' },
8687 { "font", 1, NULL, 'f' },
8688 { "display", 1, NULL, 'X' },
8690 { "own-window", 0, NULL, 'o' },
8693 { "double-buffer", 0, NULL, 'b' },
8695 { "window-id", 1, NULL, 'w' },
8697 { "text", 1, NULL, 't' },
8698 { "interval", 0, NULL, 'u' },
8702 int main(int argc, char **argv)
8708 struct sigaction act, oact;
8710 g_signal_pending = 0;
8711 memset(&info, 0, sizeof(info));
8714 #ifdef TCP_PORT_MONITOR
8715 /* set default connection limit */
8716 tcp_portmon_set_max_connections(0);
8719 /* handle command line parameters that don't change configs */
8721 if (((s = getenv("LC_ALL")) && *s) || ((s = getenv("LC_CTYPE")) && *s)
8722 || ((s = getenv("LANG")) && *s)) {
8723 temp = (char *) malloc((strlen(s) + 1) * sizeof(char));
8725 ERR("malloc failed");
8727 for (x = 0; x < strlen(s); x++) {
8728 temp[x] = tolower(s[x]);
8731 if (strstr(temp, "utf-8") || strstr(temp, "utf8")) {
8737 if (!setlocale(LC_CTYPE, "")) {
8738 ERR("Can't set the specified locale!\nCheck LANG, LC_CTYPE, LC_ALL.");
8742 int c = getopt_long(argc, argv, getopt_string, longopts, NULL);
8753 if (current_config) {
8754 free(current_config);
8756 current_config = strndup(optarg, max_user_text);
8759 freopen("/dev/null", "w", stderr);
8762 print_help(argv[0]);
8764 #ifdef CONFIG_OUTPUT
8771 window.window = strtol(optarg, 0, 0);
8780 /* check if specified config file is valid */
8781 if (current_config) {
8783 if (stat(current_config, &sb) ||
8784 (!S_ISREG(sb.st_mode) && !S_ISLNK(sb.st_mode))) {
8785 ERR("invalid configuration file '%s'\n", current_config);
8786 free(current_config);
8791 /* load current_config, CONFIG_FILE or SYSTEM_CONFIG_FILE */
8793 if (!current_config) {
8794 /* load default config file */
8795 char buf[DEFAULT_TEXT_BUFFER_SIZE];
8798 /* Try to use personal config file first */
8799 to_real_path(buf, CONFIG_FILE);
8800 if (buf[0] && (fp = fopen(buf, "r"))) {
8801 current_config = strndup(buf, max_user_text);
8805 /* Try to use system config file if personal config not readable */
8806 if (!current_config && (fp = fopen(SYSTEM_CONFIG_FILE, "r"))) {
8807 current_config = strndup(SYSTEM_CONFIG_FILE, max_user_text);
8811 /* No readable config found */
8812 if (!current_config) {
8813 #ifdef CONFIG_OUTPUT
8814 current_config = strdup("==builtin==");
8815 ERR("no readable personal or system-wide config file found,"
8816 " using builtin default");
8818 CRIT_ERR("no readable personal or system-wide config file found");
8819 #endif /* ! CONF_OUTPUT */
8822 #ifdef HAVE_SYS_INOTIFY_H
8823 inotify_fd = inotify_init();
8824 #endif /* HAVE_SYS_INOTIFY_H */
8826 load_config_file(current_config);
8828 /* init specials array */
8829 if ((specials = calloc(sizeof(struct special_t), max_specials)) == 0) {
8830 ERR("failed to create specials array");
8834 if (current_mail_spool == NULL) {
8837 variable_substitute(MAIL_FILE, buf, 256);
8839 if (buf[0] != '\0') {
8840 current_mail_spool = strndup(buf, text_buffer_size);
8845 /* handle other command line arguments */
8847 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__OpenBSD__) \
8848 || defined(__NetBSD__)
8849 optind = optreset = 1;
8854 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
8855 if ((kd = kvm_open("/dev/null", "/dev/null", "/dev/null", O_RDONLY,
8856 "kvm_open")) == NULL) {
8857 CRIT_ERR("cannot read kvm");
8862 int c = getopt_long(argc, argv, getopt_string, longopts, NULL);
8870 fork_to_background = 1;
8873 global_debug_level++;
8877 set_first_font(optarg);
8880 text_alignment = string_to_alignment(optarg);
8885 disp = strdup(optarg);
8904 global_text = strndup(optarg, max_user_text);
8905 convert_escapes(global_text);
8909 update_interval = strtod(optarg, 0);
8910 if (info.music_player_interval == 0) {
8911 // default to update_interval
8912 info.music_player_interval = update_interval;
8917 total_run_times = strtod(optarg, 0);
8921 gap_x = atoi(optarg);
8925 gap_y = atoi(optarg);
8936 if (output_methods & TO_X) {
8937 load_config_file_x11(current_config);
8941 /* generate text and get initial size */
8942 extract_variable_text(global_text);
8949 if (fork_to_background) {
8954 ERR(PACKAGE_NAME": couldn't fork() to background: %s",
8961 fprintf(stderr, "\n");
8966 /* parent process */
8967 fprintf(stderr, PACKAGE_NAME": forked to background, pid is %d\n",
8974 text_buffer = malloc(max_user_text);
8975 memset(text_buffer, 0, max_user_text);
8976 tmpstring1 = malloc(text_buffer_size);
8977 memset(tmpstring1, 0, text_buffer_size);
8978 tmpstring2 = malloc(text_buffer_size);
8979 memset(tmpstring2, 0, text_buffer_size);
8984 X11_create_window();
8987 /* Set signal handlers */
8988 act.sa_handler = signal_handler;
8989 sigemptyset(&act.sa_mask);
8992 act.sa_flags |= SA_RESTART;
8995 if ( sigaction(SIGINT, &act, &oact) < 0
8996 || sigaction(SIGUSR1, &act, &oact) < 0
8997 || sigaction(SIGHUP, &act, &oact) < 0
8998 || sigaction(SIGTERM, &act, &oact) < 0) {
8999 ERR("error setting signal handler: %s", strerror(errno));
9004 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
9011 static void signal_handler(int sig)
9013 /* signal handler is light as a feather, as it should be.
9014 * we will poll g_signal_pending with each loop of conky
9015 * and do any signal processing there, NOT here. */
9016 g_signal_pending = sig;