1 /* Conky, a system monitor, based on torsmo
3 * Any original torsmo code is licensed under the BSD license
5 * All code written since the fork of torsmo is licensed under the GPL
7 * Please see COPYING for details
9 * Copyright (c) 2004, Hannu Saransaari and Lauri Hakkarainen
10 * Copyright (c) 2005-2009 Brenden Matthews, Philip Kovacs, et. al.
12 * All rights reserved.
14 * This program is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation, either version 3 of the License, or
17 * (at your option) any later version.
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program. If not, see <http://www.gnu.org/licenses/>.
29 #include "text_object.h"
44 #include <sys/param.h>
45 #ifdef HAVE_SYS_INOTIFY_H
46 #include <sys/inotify.h>
47 #endif /* HAVE_SYS_INOTIFY_H */
50 #include <X11/Xutil.h>
52 #include <X11/extensions/Xdamage.h>
58 #include <sys/types.h>
60 #include <netinet/in.h>
79 #include "temphelper.h"
83 /* check for OS and include appropriate headers */
84 #if defined(__linux__)
86 #elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
88 #elif defined(__OpenBSD__)
92 #if defined(__FreeBSD_kernel__)
96 /* FIXME: apm_getinfo is unused here. maybe it's meant for common.c */
97 #if (defined(__FreeBSD__) || defined(__FreeBSD_kernel__) \
98 || defined(__OpenBSD__)) && (defined(i386) || defined(__i386__))
99 int apm_getinfo(int fd, apm_info_t aip);
100 char *get_apm_adapter(void);
101 char *get_apm_battery_life(void);
102 char *get_apm_battery_time(void);
110 #include "defconfig.h"
111 #ifdef HAVE_FOPENCOOKIE
112 #include "conf_cookie.h"
117 #define S_ISSOCK(x) ((x & S_IFMT) == S_IFSOCK)
120 #define MAIL_FILE "$MAIL"
121 #define MAX_IF_BLOCK_DEPTH 5
123 //#define SIGNAL_BLOCKING
124 #undef SIGNAL_BLOCKING
126 /* debugging level, used by logging.h */
127 int global_debug_level = 0;
129 /* two strings for internal use */
130 static char *tmpstring1, *tmpstring2;
132 /* variables holding various config settings */
140 int top_cpu, top_mem, top_time;
141 static unsigned int top_name_width = 15;
143 enum x_initialiser_state x_initialised = NO;
144 static volatile int g_signal_pending;
145 /* Update interval */
146 double update_interval;
149 /* prototypes for internally used functions */
150 static void signal_handler(int);
151 static void print_version(void) __attribute__((noreturn));
152 static void reload_config(void);
153 static void clean_up(void);
154 static void generate_text_internal(char *, int, struct text_object,
155 struct information *);
156 static int extract_variable_text_internal(struct text_object *,
159 static void print_version(void)
161 printf(PACKAGE_NAME" "VERSION" compiled "BUILD_DATE" for "BUILD_ARCH"\n");
163 printf("\nCompiled in features:\n\n"
164 "System config file: "SYSTEM_CONFIG_FILE"\n\n"
168 " * Xdamage extension\n"
169 # endif /* HAVE_XDAMAGE */
171 " * XDBE (double buffer extension)\n"
172 # endif /* HAVE_XDBE */
177 "\n Music detection:\n"
180 #endif /* AUDACIOUS */
196 #endif /* HAVE_OPENMP */
203 #ifdef TCP_PORT_MONITOR
205 #endif /* TCP_PORT_MONITOR */
211 #endif /* HAVE_LUA */
214 #endif /* HAVE_IWLIB */
216 " * support for IBM/Lenovo notebooks\n"
226 #endif /* CONFIG_OUTPUT */
231 " * ALSA mixer support\n"
232 #endif /* MIXER_IS_ALSA */
241 static const char *suffixes[] = { "B", "KiB", "MiB", "GiB", "TiB", "PiB", "" };
246 static void X11_destroy_window(void);
247 static void X11_create_window(void);
249 struct _x11_stuff_s {
253 XserverRegion region2, part;
254 int event_base, error_base;
260 static int text_start_x, text_start_y; /* text start position in window */
261 static int text_width, text_height;
276 /* display to connect to */
277 static char *disp = NULL;
281 /* struct that has all info to be shared between
282 * instances of the same text object */
283 struct information info;
285 /* default config file */
286 static char *current_config;
288 /* set to 1 if you want all text to be in uppercase */
289 static unsigned int stuff_in_upper_case;
291 /* Run how many times? */
292 static unsigned long total_run_times;
295 static int fork_to_background;
297 static int cpu_avg_samples, net_avg_samples, diskio_avg_samples;
299 /* filenames for output */
300 char *overwrite_file = NULL; FILE *overwrite_fpointer = NULL;
301 char *append_file = NULL; FILE *append_fpointer = NULL;
305 static int show_graph_scale;
306 static int show_graph_range;
308 /* Position on the screen */
309 static int text_alignment;
310 static int gap_x, gap_y;
313 static int draw_borders;
314 static int draw_graph_borders;
315 static int stippled_borders;
317 static int draw_shades, draw_outline;
319 static int border_margin, border_width;
321 static long default_fg_color, default_bg_color, default_out_color;
323 /* create own window or draw stuff to root? */
324 static int set_transparent = 0;
327 static int own_window = 0;
328 static int background_colour = 0;
330 /* fixed size/pos is set if wm/user changes them */
331 static int fixed_size = 0, fixed_pos = 0;
334 static int minimum_width, minimum_height;
335 static int maximum_width;
340 static int sensor_device;
343 static long color0, color1, color2, color3, color4, color5, color6, color7,
346 static char *template[10];
348 /* maximum size of config TEXT buffer, i.e. below TEXT line. */
349 static unsigned int max_user_text = MAX_USER_TEXT_DEFAULT;
351 /* maximum size of individual text buffers, ie $exec buffer size */
352 unsigned int text_buffer_size = DEFAULT_TEXT_BUFFER_SIZE;
355 #define CODEPAGE_LENGTH 20
357 long iconv_count = 0;
358 char iconv_converting;
359 static iconv_t **iconv_cd = 0;
361 int register_iconv(iconv_t *new_iconv)
363 iconv_cd = realloc(iconv_cd, sizeof(iconv_t *) * (iconv_count + 1));
365 CRIT_ERR("Out of memory");
367 iconv_cd[iconv_count] = malloc(sizeof(iconv_t));
368 if (!iconv_cd[iconv_count]) {
369 CRIT_ERR("Out of memory");
371 memcpy(iconv_cd[iconv_count], new_iconv, sizeof(iconv_t));
376 void free_iconv(void)
381 for (i = 0; i < iconv_count; i++) {
383 iconv_close(*iconv_cd[i]);
397 /* no buffers in used memory? */
400 /* pad percentages to decimals? */
401 static int pad_percents = 0;
403 static char *global_text = 0;
404 long global_text_lines;
406 static int total_updates;
407 static int updatereset;
409 int check_contains(char *f, char *s)
412 FILE *where = open_file(f, 0);
417 while (fgets(buf1, 256, where)) {
418 if (strstr(buf1, s)) {
425 ERR("Could not open the file");
431 static inline int calc_text_width(const char *s, int l)
433 if ((output_methods & TO_X) == 0)
440 XftTextExtentsUtf8(display, fonts[selected_font].xftfont,
441 (const FcChar8 *) s, l, &gi);
443 XftTextExtents8(display, fonts[selected_font].xftfont,
444 (const FcChar8 *) s, l, &gi);
450 return XTextWidth(fonts[selected_font].font, s, l);
455 /* formatted text to render on screen, generated in generate_text(),
456 * drawn in draw_stuff() */
458 static char *text_buffer;
461 static unsigned int special_index; /* used when drawing */
464 /* quite boring functions */
466 static inline void for_each_line(char *b, void f(char *))
470 for (ps = b, pe = b; *pe; pe++) {
484 static void convert_escapes(char *buf)
486 char *p = buf, *s = buf;
493 } else if (*s == '\\') {
504 /* Prints anything normally printed with snprintf according to the current value
505 * of use_spacer. Actually slightly more flexible than snprintf, as you can
506 * safely specify the destination buffer as one of your inputs. */
507 int spaced_print(char *buf, int size, const char *format, int width, ...)
516 tempbuf = malloc(size * sizeof(char));
518 // Passes the varargs along to vsnprintf
519 va_start(argp, width);
520 vsnprintf(tempbuf, size, format, argp);
523 switch (use_spacer) {
525 len = snprintf(buf, size, "%s", tempbuf);
528 len = snprintf(buf, size, "%*s", width, tempbuf);
531 len = snprintf(buf, size, "%-*s", width, tempbuf);
538 /* print percentage values
540 * - i.e., unsigned values between 0 and 100
541 * - respect the value of pad_percents */
542 static int percent_print(char *buf, int size, unsigned value)
544 return spaced_print(buf, size, "%u", pad_percents, value);
547 /* converts from bytes to human readable format (K, M, G, T)
549 * The algorithm always divides by 1024, as unit-conversion of byte
550 * counts suggests. But for output length determination we need to
551 * compare with 1000 here, as we print in decimal form. */
552 static void human_readable(long long num, char *buf, int size)
554 const char **suffix = suffixes;
568 if (llabs(num) < 1000LL) {
569 spaced_print(buf, size, format, width, 0, (float)num, *suffix);
573 while (llabs(num / 1024) >= 1000LL && **(suffix + 2)) {
581 /* fnum should now be < 1000, so looks like 'AAA.BBBBB'
583 * The goal is to always have a significance of 3, by
584 * adjusting the decimal part of the number. Sample output:
588 * so the point of alignment resides between number and unit. The
589 * upside of this is that there is minimal padding necessary, though
590 * there should be a way to make alignment take place at the decimal
591 * dot (then with fixed width decimal part).
593 * Note the repdigits below: when given a precision value, printf()
594 * rounds the float to it, not just cuts off the remaining digits. So
595 * e.g. 99.95 with a precision of 1 gets 100.0, which again should be
596 * printed with a precision of 0. Yay. */
598 precision = 0; /* print 100-999 without decimal part */
600 precision = 1; /* print 10-99 with one decimal place */
602 precision = 2; /* print 0-9 with two decimal places */
604 spaced_print(buf, size, format, width, precision, fnum, *suffix);
607 /* global object list root element */
608 static struct text_object global_root_object;
610 static inline void read_exec(const char *data, char *buf, const int size)
612 FILE *fp = popen(data, "r");
613 int length = fread(buf, 1, size, fp);
617 if (length > 0 && buf[length - 1] == '\n') {
618 buf[length - 1] = '\0';
622 void *threaded_exec(void *) __attribute__((noreturn));
624 void *threaded_exec(void *arg)
627 struct text_object *obj = (struct text_object *)arg;
630 buff = malloc(text_buffer_size);
631 read_exec(obj->data.texeci.cmd, buff,
640 timed_thread_lock(obj->data.texeci.p_timed_thread);
641 strncpy(obj->data.texeci.buffer, buff, text_buffer_size);
642 timed_thread_unlock(obj->data.texeci.p_timed_thread);
644 if (timed_thread_test(obj->data.texeci.p_timed_thread, 0)) {
645 timed_thread_exit(obj->data.texeci.p_timed_thread);
651 static struct text_object *new_text_object_internal(void)
653 struct text_object *obj = malloc(sizeof(struct text_object));
654 memset(obj, 0, sizeof(struct text_object));
659 * Frees the list of text objects root points to. When internal = 1, it won't
660 * free global objects.
662 static void free_text_objects(struct text_object *root, int internal)
664 struct text_object *obj;
670 #define data obj->data
671 for (obj = root->prev; obj; obj = root->prev) {
672 root->prev = obj->prev;
678 #endif /* !__OpenBSD__ */
683 close(data.sysfs.fd);
685 #endif /* __linux__ */
691 free(data.tztime.tz);
692 free(data.tztime.fmt);
695 free(data.mboxscan.args);
696 free(data.mboxscan.output);
701 case OBJ_unseen_mails:
702 case OBJ_flagged_mails:
703 case OBJ_unflagged_mails:
704 case OBJ_forwarded_mails:
705 case OBJ_unforwarded_mails:
706 case OBJ_replied_mails:
707 case OBJ_unreplied_mails:
708 case OBJ_draft_mails:
709 case OBJ_trashed_mails:
710 free(data.local_mail.box);
712 case OBJ_imap_unseen:
717 case OBJ_imap_messages:
722 case OBJ_pop3_unseen:
734 free_text_objects(obj->sub, 1);
737 case OBJ_if_existing:
740 free(data.ifblock.s);
741 free(data.ifblock.str);
744 free(data.tail.logfile);
745 free(data.tail.buffer);
761 case OBJ_iconv_start:
766 case OBJ_disk_protect:
770 free(data.ifblock.s);
771 free(data.ifblock.str);
774 if (info.gw_info.iface) {
775 free(info.gw_info.iface);
776 info.gw_info.iface = 0;
778 if (info.gw_info.ip) {
779 free(info.gw_info.ip);
783 case OBJ_ioscheduler:
788 #if (defined(__FreeBSD__) || defined(__linux__))
790 free(data.ifblock.s);
791 free(data.ifblock.str);
795 case OBJ_xmms2_artist:
796 if (info.xmms2.artist) {
797 free(info.xmms2.artist);
798 info.xmms2.artist = 0;
801 case OBJ_xmms2_album:
802 if (info.xmms2.album) {
803 free(info.xmms2.album);
804 info.xmms2.album = 0;
807 case OBJ_xmms2_title:
808 if (info.xmms2.title) {
809 free(info.xmms2.title);
810 info.xmms2.title = 0;
813 case OBJ_xmms2_genre:
814 if (info.xmms2.genre) {
815 free(info.xmms2.genre);
816 info.xmms2.genre = 0;
819 case OBJ_xmms2_comment:
820 if (info.xmms2.comment) {
821 free(info.xmms2.comment);
822 info.xmms2.comment = 0;
826 if (info.xmms2.url) {
827 free(info.xmms2.url);
832 if (info.xmms2.date) {
833 free(info.xmms2.date);
837 case OBJ_xmms2_status:
838 if (info.xmms2.status) {
839 free(info.xmms2.status);
840 info.xmms2.status = 0;
843 case OBJ_xmms2_playlist:
844 if (info.xmms2.playlist) {
845 free(info.xmms2.playlist);
846 info.xmms2.playlist = 0;
849 case OBJ_xmms2_smart:
850 if (info.xmms2.artist) {
851 free(info.xmms2.artist);
852 info.xmms2.artist = 0;
854 if (info.xmms2.title) {
855 free(info.xmms2.title);
856 info.xmms2.title = 0;
858 if (info.xmms2.url) {
859 free(info.xmms2.url);
866 case OBJ_bmpx_artist:
870 case OBJ_bmpx_bitrate:
880 free(data.rss.action);
886 case OBJ_lua_read_parse:
894 #endif /* HAVE_LUA */
901 case OBJ_battery_short:
904 case OBJ_battery_time:
907 #endif /* !__OpenBSD__ */
915 free(data.execi.cmd);
916 free(data.execi.buffer);
919 free(data.texeci.cmd);
920 free(data.texeci.buffer);
928 if (info.first_process && !internal) {
929 free_all_processes();
930 info.first_process = NULL;
932 if (data.top.s) free(data.top.s);
936 free(data.hddtemp.dev);
937 free(data.hddtemp.addr);
938 if (data.hddtemp.temp)
939 free(data.hddtemp.temp);
942 case OBJ_entropy_avail:
943 case OBJ_entropy_poolsize:
945 case OBJ_entropy_bar:
949 if (info.users.names) {
950 free(info.users.names);
951 info.users.names = 0;
955 if (info.users.terms) {
956 free(info.users.terms);
957 info.users.terms = 0;
961 if (info.users.times) {
962 free(info.users.times);
963 info.users.times = 0;
968 case OBJ_smapi_bat_perc:
969 case OBJ_smapi_bat_temp:
970 case OBJ_smapi_bat_power:
973 case OBJ_if_smapi_bat_installed:
974 free(data.ifblock.s);
975 free(data.ifblock.str);
989 case OBJ_mpd_bitrate:
994 case OBJ_mpd_elapsed:
999 case OBJ_mpd_percent:
1001 case OBJ_if_mpd_playing:
1009 case OBJ_moc_artist:
1012 case OBJ_moc_totaltime:
1013 case OBJ_moc_timeleft:
1014 case OBJ_moc_curtime:
1015 case OBJ_moc_bitrate:
1021 free(data.scroll.text);
1022 free_text_objects(obj->sub, 1);
1026 free(data.combine.left);
1027 free(data.combine.seperation);
1028 free(data.combine.right);
1029 free_text_objects(obj->sub, 1);
1034 case OBJ_apcupsd_name:
1035 case OBJ_apcupsd_model:
1036 case OBJ_apcupsd_upsmode:
1037 case OBJ_apcupsd_cable:
1038 case OBJ_apcupsd_status:
1039 case OBJ_apcupsd_linev:
1040 case OBJ_apcupsd_load:
1042 case OBJ_apcupsd_loadbar:
1043 case OBJ_apcupsd_loadgraph:
1044 case OBJ_apcupsd_loadgauge:
1046 case OBJ_apcupsd_charge:
1047 case OBJ_apcupsd_timeleft:
1048 case OBJ_apcupsd_temp:
1049 case OBJ_apcupsd_lastxfer:
1051 #endif /* APCUPSD */
1059 void scan_mixer_bar(const char *arg, int *a, int *w, int *h)
1064 if (arg && sscanf(arg, "%63s %n", buf1, &n) >= 1) {
1065 *a = mixer_init(buf1);
1066 scan_bar(arg + n, w, h);
1068 *a = mixer_init(NULL);
1069 scan_bar(arg, w, h);
1074 /* strip a leading /dev/ if any, following symlinks first
1076 * BEWARE: this function returns a pointer to static content
1077 * which gets overwritten in consecutive calls. I.e.:
1078 * this function is NOT reentrant.
1080 static const char *dev_name(const char *path)
1082 static char buf[255]; /* should be enough for pathnames */
1088 #define DEV_NAME(x) \
1089 x != NULL && strlen(x) > 5 && strncmp(x, "/dev/", 5) == 0 ? x + 5 : x
1090 if ((buflen = readlink(path, buf, 254)) == -1)
1091 return DEV_NAME(path);
1093 return DEV_NAME(buf);
1097 static int parse_top_args(const char *s, const char *arg, struct text_object *obj)
1102 if (obj->data.top.was_parsed) {
1105 obj->data.top.was_parsed = 1;
1107 if (arg && !obj->data.top.s) {
1108 obj->data.top.s = strndup(arg, text_buffer_size);
1111 need_mask |= (1 << INFO_TOP);
1114 obj->type = OBJ_top;
1116 } else if (strcmp(&s[3], "_mem") == EQUAL) {
1117 obj->type = OBJ_top_mem;
1119 } else if (strcmp(&s[3], "_time") == EQUAL) {
1120 obj->type = OBJ_top_time;
1123 ERR("Must be top, top_mem or top_time");
1128 ERR("top needs arguments");
1132 if (sscanf(arg, "%63s %i", buf, &n) == 2) {
1133 if (strcmp(buf, "name") == EQUAL) {
1134 obj->data.top.type = TOP_NAME;
1135 } else if (strcmp(buf, "cpu") == EQUAL) {
1136 obj->data.top.type = TOP_CPU;
1137 } else if (strcmp(buf, "pid") == EQUAL) {
1138 obj->data.top.type = TOP_PID;
1139 } else if (strcmp(buf, "mem") == EQUAL) {
1140 obj->data.top.type = TOP_MEM;
1141 } else if (strcmp(buf, "time") == EQUAL) {
1142 obj->data.top.type = TOP_TIME;
1143 } else if (strcmp(buf, "mem_res") == EQUAL) {
1144 obj->data.top.type = TOP_MEM_RES;
1145 } else if (strcmp(buf, "mem_vsize") == EQUAL) {
1146 obj->data.top.type = TOP_MEM_VSIZE;
1148 ERR("invalid type arg for top");
1149 ERR("must be one of: name, cpu, pid, mem, time, mem_res, mem_vsize");
1152 if (n < 1 || n > 10) {
1153 ERR("invalid num arg for top. Must be between 1 and 10.");
1156 obj->data.top.num = n - 1;
1159 ERR("invalid argument count for top");
1165 /* construct_text_object() creates a new text_object */
1166 static struct text_object *construct_text_object(const char *s,
1167 const char *arg, long line, char allow_threaded, void **ifblock_opaque)
1169 // struct text_object *obj = new_text_object();
1170 struct text_object *obj = new_text_object_internal();
1174 #define OBJ(a, n) if (strcmp(s, #a) == 0) { \
1175 obj->type = OBJ_##a; need_mask |= (1ULL << n); {
1176 #define OBJ_IF(a, n) if (strcmp(s, #a) == 0) { \
1177 obj->type = OBJ_##a; need_mask |= (1ULL << n); \
1178 obj_be_ifblock_if(ifblock_opaque, obj); {
1179 #define OBJ_THREAD(a, n) if (strcmp(s, #a) == 0 && allow_threaded) { \
1180 obj->type = OBJ_##a; need_mask |= (1ULL << n); {
1181 #define END } } else
1183 #define SIZE_DEFAULTS(arg) { \
1184 obj->a = default_##arg##_width; \
1185 obj->b = default_##arg##_height; \
1190 obj->type = OBJ_color;
1191 obj->data.l = get_x11_color(s);
1195 OBJ(freq, INFO_FREQ)
1198 obj->data.i = open_acpi_temperature(arg);
1199 END OBJ(acpiacadapter, 0)
1200 END OBJ(freq, INFO_FREQ)
1201 #endif /* !__OpenBSD__ */
1203 if (!arg || !isdigit(arg[0]) || strlen(arg) >= 2 || atoi(&arg[0]) == 0
1204 || (unsigned int) atoi(&arg[0]) > info.cpu_count) {
1205 obj->data.cpu_index = 1;
1206 /* ERR("freq: Invalid CPU number or you don't have that many CPUs! "
1207 "Displaying the clock for CPU 1."); */
1209 obj->data.cpu_index = atoi(&arg[0]);
1212 END OBJ(freq_g, INFO_FREQ)
1214 if (!arg || !isdigit(arg[0]) || strlen(arg) >= 2 || atoi(&arg[0]) == 0
1215 || (unsigned int) atoi(&arg[0]) > info.cpu_count) {
1216 obj->data.cpu_index = 1;
1217 /* ERR("freq_g: Invalid CPU number or you don't have that many "
1218 "CPUs! Displaying the clock for CPU 1."); */
1220 obj->data.cpu_index = atoi(&arg[0]);
1223 #if defined(__linux__)
1224 END OBJ(voltage_mv, 0)
1226 if (!arg || !isdigit(arg[0]) || strlen(arg) >= 2 || atoi(&arg[0]) == 0
1227 || (unsigned int) atoi(&arg[0]) > info.cpu_count) {
1228 obj->data.cpu_index = 1;
1229 /* ERR("voltage_mv: Invalid CPU number or you don't have that many "
1230 "CPUs! Displaying voltage for CPU 1."); */
1232 obj->data.cpu_index = atoi(&arg[0]);
1235 END OBJ(voltage_v, 0)
1237 if (!arg || !isdigit(arg[0]) || strlen(arg) >= 2 || atoi(&arg[0]) == 0
1238 || (unsigned int) atoi(&arg[0]) > info.cpu_count) {
1239 obj->data.cpu_index = 1;
1240 /* ERR("voltage_v: Invalid CPU number or you don't have that many "
1241 "CPUs! Displaying voltage for CPU 1."); */
1243 obj->data.cpu_index = atoi(&arg[0]);
1248 END OBJ(wireless_essid, INFO_NET)
1250 obj->data.net = get_net_stat(arg);
1252 CRIT_ERR("wireless_essid: needs an argument");
1254 END OBJ(wireless_mode, INFO_NET)
1256 obj->data.net = get_net_stat(arg);
1258 CRIT_ERR("wireless_mode: needs an argument");
1260 END OBJ(wireless_bitrate, INFO_NET)
1262 obj->data.net = get_net_stat(arg);
1264 CRIT_ERR("wireless_bitrate: needs an argument");
1266 END OBJ(wireless_ap, INFO_NET)
1268 obj->data.net = get_net_stat(arg);
1270 CRIT_ERR("wireless_ap: needs an argument");
1272 END OBJ(wireless_link_qual, INFO_NET)
1274 obj->data.net = get_net_stat(arg);
1276 CRIT_ERR("wireless_link_qual: needs an argument");
1278 END OBJ(wireless_link_qual_max, INFO_NET)
1280 obj->data.net = get_net_stat(arg);
1282 CRIT_ERR("wireless_link_qual_max: needs an argument");
1284 END OBJ(wireless_link_qual_perc, INFO_NET)
1286 obj->data.net = get_net_stat(arg);
1288 CRIT_ERR("wireless_link_qual_perc: needs an argument");
1290 END OBJ(wireless_link_bar, INFO_NET)
1293 arg = scan_bar(arg, &obj->a, &obj->b);
1294 obj->data.net = get_net_stat(arg);
1296 CRIT_ERR("wireless_link_bar: needs an argument");
1298 #endif /* HAVE_IWLIB */
1300 #endif /* __linux__ */
1308 sscanf(arg, "%63s", bat);
1310 strcpy(bat, "BAT0");
1312 obj->data.s = strndup(bat, text_buffer_size);
1313 END OBJ(battery_short, 0)
1317 sscanf(arg, "%63s", bat);
1319 strcpy(bat, "BAT0");
1321 obj->data.s = strndup(bat, text_buffer_size);
1322 END OBJ(battery_time, 0)
1326 sscanf(arg, "%63s", bat);
1328 strcpy(bat, "BAT0");
1330 obj->data.s = strndup(bat, text_buffer_size);
1331 END OBJ(battery_percent, 0)
1335 sscanf(arg, "%63s", bat);
1337 strcpy(bat, "BAT0");
1339 obj->data.s = strndup(bat, text_buffer_size);
1341 END OBJ(battery_bar, 0)
1346 arg = scan_bar(arg, &obj->a, &obj->b);
1347 sscanf(arg, "%63s", bat);
1349 strcpy(bat, "BAT0");
1351 obj->data.s = strndup(bat, text_buffer_size);
1353 #endif /* !__OpenBSD__ */
1355 #if defined(__linux__)
1356 END OBJ(disk_protect, 0)
1358 obj->data.s = strndup(dev_name(arg), text_buffer_size);
1360 CRIT_ERR("disk_protect needs an argument");
1361 END OBJ(i8k_version, INFO_I8K)
1362 END OBJ(i8k_bios, INFO_I8K)
1363 END OBJ(i8k_serial, INFO_I8K)
1364 END OBJ(i8k_cpu_temp, INFO_I8K)
1365 END OBJ(i8k_left_fan_status, INFO_I8K)
1366 END OBJ(i8k_right_fan_status, INFO_I8K)
1367 END OBJ(i8k_left_fan_rpm, INFO_I8K)
1368 END OBJ(i8k_right_fan_rpm, INFO_I8K)
1369 END OBJ(i8k_ac_status, INFO_I8K)
1370 END OBJ(i8k_buttons_status, INFO_I8K)
1373 END OBJ(ibm_temps, 0)
1375 CRIT_ERR("ibm_temps: needs an argument");
1377 if (!isdigit(arg[0]) || strlen(arg) >= 2 || atoi(&arg[0]) >= 8) {
1378 obj->data.sensor = 0;
1379 ERR("Invalid temperature sensor! Sensor number must be 0 to 7. "
1380 "Using 0 (CPU temp sensor).");
1382 obj->data.sensor = atoi(&arg[0]);
1383 END OBJ(ibm_volume, 0)
1384 END OBJ(ibm_brightness, 0)
1386 /* information from sony_laptop kernel module
1387 * /sys/devices/platform/sony-laptop */
1388 END OBJ(sony_fanspeed, 0)
1389 END OBJ_IF(if_gw, INFO_GW)
1390 END OBJ(ioscheduler, 0)
1392 CRIT_ERR("get_ioscheduler needs an argument (e.g. hda)");
1395 obj->data.s = strndup(dev_name(arg), text_buffer_size);
1396 END OBJ(laptop_mode, 0)
1397 END OBJ(pb_battery, 0)
1398 if (arg && strcmp(arg, "status") == EQUAL) {
1399 obj->data.i = PB_BATT_STATUS;
1400 } else if (arg && strcmp(arg, "percent") == EQUAL) {
1401 obj->data.i = PB_BATT_PERCENT;
1402 } else if (arg && strcmp(arg, "time") == EQUAL) {
1403 obj->data.i = PB_BATT_TIME;
1405 ERR("pb_battery: needs one argument: status, percent or time");
1410 #endif /* __linux__ */
1411 #if (defined(__FreeBSD__) || defined(__linux__))
1412 END OBJ_IF(if_up, 0)
1414 ERR("if_up needs an argument");
1415 obj->data.ifblock.s = 0;
1417 obj->data.ifblock.s = strndup(arg, text_buffer_size);
1420 #if defined(__OpenBSD__)
1421 END OBJ(obsd_sensors_temp, 0)
1423 CRIT_ERR("obsd_sensors_temp: needs an argument");
1425 if (!isdigit(arg[0]) || atoi(&arg[0]) < 0
1426 || atoi(&arg[0]) > OBSD_MAX_SENSORS - 1) {
1427 obj->data.sensor = 0;
1428 ERR("Invalid temperature sensor number!");
1430 obj->data.sensor = atoi(&arg[0]);
1431 END OBJ(obsd_sensors_fan, 0)
1433 CRIT_ERR("obsd_sensors_fan: needs 2 arguments (device and sensor "
1436 if (!isdigit(arg[0]) || atoi(&arg[0]) < 0
1437 || atoi(&arg[0]) > OBSD_MAX_SENSORS - 1) {
1438 obj->data.sensor = 0;
1439 ERR("Invalid fan sensor number!");
1441 obj->data.sensor = atoi(&arg[0]);
1442 END OBJ(obsd_sensors_volt, 0)
1444 CRIT_ERR("obsd_sensors_volt: needs 2 arguments (device and sensor "
1447 if (!isdigit(arg[0]) || atoi(&arg[0]) < 0
1448 || atoi(&arg[0]) > OBSD_MAX_SENSORS - 1) {
1449 obj->data.sensor = 0;
1450 ERR("Invalid voltage sensor number!");
1452 obj->data.sensor = atoi(&arg[0]);
1453 END OBJ(obsd_vendor, 0)
1454 END OBJ(obsd_product, 0)
1455 #endif /* __OpenBSD__ */
1456 END OBJ(buffers, INFO_BUFFERS)
1457 END OBJ(cached, INFO_BUFFERS)
1458 #define SCAN_CPU(__arg, __var) { \
1460 if (__arg && sscanf(__arg, " cpu%u %n", &__var, &__offset) > 0) \
1461 __arg += __offset; \
1465 END OBJ(cpu, INFO_CPU)
1466 SCAN_CPU(arg, obj->data.cpu_index);
1467 DBGP2("Adding $cpu for CPU %d", obj->data.cpu_index);
1469 END OBJ(cpugauge, INFO_CPU)
1470 SIZE_DEFAULTS(gauge);
1471 SCAN_CPU(arg, obj->data.cpu_index);
1472 scan_gauge(arg, &obj->a, &obj->b);
1473 DBGP2("Adding $cpugauge for CPU %d", obj->data.cpu_index);
1474 END OBJ(cpubar, INFO_CPU)
1476 SCAN_CPU(arg, obj->data.cpu_index);
1477 scan_bar(arg, &obj->a, &obj->b);
1478 DBGP2("Adding $cpubar for CPU %d", obj->data.cpu_index);
1479 END OBJ(cpugraph, INFO_CPU)
1480 SIZE_DEFAULTS(graph);
1481 SCAN_CPU(arg, obj->data.cpu_index);
1482 scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
1483 &obj->e, &obj->char_a, &obj->char_b);
1484 DBGP2("Adding $cpugraph for CPU %d", obj->data.cpu_index);
1485 END OBJ(loadgraph, INFO_LOADAVG)
1487 SIZE_DEFAULTS(graph);
1488 buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
1489 &obj->e, &obj->char_a, &obj->char_b);
1493 r = sscanf(arg, "%d", &a);
1495 obj->data.loadavg[0] = (r >= 1) ? (unsigned char) a : 0;
1499 END OBJ(diskio, INFO_DISKIO)
1500 obj->data.diskio = prepare_diskio_stat(dev_name(arg));
1501 END OBJ(diskio_read, INFO_DISKIO)
1502 obj->data.diskio = prepare_diskio_stat(dev_name(arg));
1503 END OBJ(diskio_write, INFO_DISKIO)
1504 obj->data.diskio = prepare_diskio_stat(dev_name(arg));
1506 END OBJ(diskiograph, INFO_DISKIO)
1508 SIZE_DEFAULTS(graph);
1509 buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
1510 &obj->e, &obj->char_a, &obj->char_b);
1512 obj->data.diskio = prepare_diskio_stat(dev_name(buf));
1515 END OBJ(diskiograph_read, INFO_DISKIO)
1517 SIZE_DEFAULTS(graph);
1518 buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
1519 &obj->e, &obj->char_a, &obj->char_b);
1521 obj->data.diskio = prepare_diskio_stat(dev_name(buf));
1524 END OBJ(diskiograph_write, INFO_DISKIO)
1526 SIZE_DEFAULTS(graph);
1527 buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
1528 &obj->e, &obj->char_a, &obj->char_b);
1530 obj->data.diskio = prepare_diskio_stat(dev_name(buf));
1536 if (output_methods & TO_X) {
1537 obj->data.l = arg ? get_x11_color(arg) : default_fg_color;
1541 obj->data.l = color0;
1543 obj->data.l = color1;
1545 obj->data.l = color2;
1547 obj->data.l = color3;
1549 obj->data.l = color4;
1551 obj->data.l = color5;
1553 obj->data.l = color6;
1555 obj->data.l = color7;
1557 obj->data.l = color8;
1559 obj->data.l = color9;
1562 obj->data.s = scan_font(arg);
1564 END OBJ(conky_version, 0)
1565 END OBJ(conky_build_date, 0)
1566 END OBJ(conky_build_arch, 0)
1567 END OBJ(downspeed, INFO_NET)
1569 obj->data.net = get_net_stat(arg);
1571 CRIT_ERR("downspeed needs argument");
1573 END OBJ(downspeedf, INFO_NET)
1575 obj->data.net = get_net_stat(arg);
1577 CRIT_ERR("downspeedf needs argument");
1580 END OBJ(downspeedgraph, INFO_NET)
1582 SIZE_DEFAULTS(graph);
1583 buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
1584 &obj->e, &obj->char_a, &obj->char_b);
1586 // default to DEFAULTNETDEV
1587 buf = strndup(buf ? buf : "DEFAULTNETDEV", text_buffer_size);
1588 obj->data.net = get_net_stat(buf);
1592 obj_be_ifblock_else(ifblock_opaque, obj);
1594 obj_be_ifblock_endif(ifblock_opaque, obj);
1596 obj->data.s = strndup(arg ? arg : "", text_buffer_size);
1598 obj->data.s = strndup(arg ? arg : "", text_buffer_size);
1601 obj->data.s = strndup(arg ? arg : "", text_buffer_size);
1603 obj->data.s = strndup(arg ? arg : "", text_buffer_size);
1606 obj->data.s = strndup(arg ? arg : "", text_buffer_size);
1608 END OBJ(execgauge, 0)
1609 SIZE_DEFAULTS(gauge);
1610 obj->data.s = strndup(arg ? arg : "", text_buffer_size);
1611 END OBJ(execgraph, 0)
1612 SIZE_DEFAULTS(graph);
1613 obj->data.s = strndup(arg ? arg : "", text_buffer_size);
1614 END OBJ(execibar, 0)
1618 if (!arg || sscanf(arg, "%f %n", &obj->data.execi.interval, &n) <= 0) {
1621 ERR("${execibar <interval> command}");
1622 obj->type = OBJ_text;
1623 snprintf(buf, 256, "${%s}", s);
1624 obj->data.s = strndup(buf, text_buffer_size);
1626 obj->data.execi.cmd = strndup(arg + n, text_buffer_size);
1628 END OBJ(execigraph, 0)
1630 SIZE_DEFAULTS(graph);
1632 if (!arg || sscanf(arg, "%f %n", &obj->data.execi.interval, &n) <= 0) {
1635 ERR("${execigraph <interval> command}");
1636 obj->type = OBJ_text;
1637 snprintf(buf, 256, "${%s}", s);
1638 obj->data.s = strndup(buf, text_buffer_size);
1640 obj->data.execi.cmd = strndup(arg + n, text_buffer_size);
1642 END OBJ(execigauge, 0)
1644 SIZE_DEFAULTS(gauge);
1646 if (!arg || sscanf(arg, "%f %n", &obj->data.execi.interval, &n) <= 0) {
1649 ERR("${execigauge <interval> command}");
1650 obj->type = OBJ_text;
1651 snprintf(buf, 256, "${%s}", s);
1652 obj->data.s = strndup(buf, text_buffer_size);
1654 obj->data.execi.cmd = strndup(arg + n, text_buffer_size);
1660 if (!arg || sscanf(arg, "%f %n", &obj->data.execi.interval, &n) <= 0) {
1663 ERR("${execi <interval> command}");
1664 obj->type = OBJ_text;
1665 snprintf(buf, 256, "${%s}", s);
1666 obj->data.s = strndup(buf, text_buffer_size);
1668 obj->data.execi.cmd = strndup(arg + n, text_buffer_size);
1669 obj->data.execi.buffer = malloc(text_buffer_size);
1674 if (!arg || sscanf(arg, "%f %n", &obj->data.execi.interval, &n) <= 0) {
1677 ERR("${execi <interval> command}");
1678 obj->type = OBJ_text;
1679 snprintf(buf, 256, "${%s}", s);
1680 obj->data.s = strndup(buf, text_buffer_size);
1682 obj->data.execi.cmd = strndup(arg + n, text_buffer_size);
1683 obj->data.execi.buffer = malloc(text_buffer_size);
1685 END OBJ_THREAD(texeci, 0)
1688 if (!arg || sscanf(arg, "%f %n", &obj->data.texeci.interval, &n) <= 0) {
1691 ERR("${texeci <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.texeci.cmd = strndup(arg + n, text_buffer_size);
1697 obj->data.texeci.buffer = malloc(text_buffer_size);
1699 obj->data.texeci.p_timed_thread = NULL;
1700 END OBJ(pre_exec, 0)
1701 obj->type = OBJ_text;
1705 read_exec(arg, buf, sizeof(buf));
1706 obj->data.s = strndup(buf, text_buffer_size);
1708 obj->data.s = strndup("", text_buffer_size);
1712 END OBJ(fs_bar, INFO_FS)
1714 arg = scan_bar(arg, &obj->data.fsbar.w, &obj->data.fsbar.h);
1716 while (isspace(*arg)) {
1725 obj->data.fsbar.fs = prepare_fs_stat(arg);
1726 END OBJ(fs_bar_free, INFO_FS)
1728 arg = scan_bar(arg, &obj->data.fsbar.w, &obj->data.fsbar.h);
1730 while (isspace(*arg)) {
1740 obj->data.fsbar.fs = prepare_fs_stat(arg);
1742 END OBJ(fs_free, INFO_FS)
1746 obj->data.fs = prepare_fs_stat(arg);
1747 END OBJ(fs_used_perc, INFO_FS)
1751 obj->data.fs = prepare_fs_stat(arg);
1752 END OBJ(fs_free_perc, INFO_FS)
1756 obj->data.fs = prepare_fs_stat(arg);
1757 END OBJ(fs_size, INFO_FS)
1761 obj->data.fs = prepare_fs_stat(arg);
1762 END OBJ(fs_type, INFO_FS)
1766 obj->data.fs = prepare_fs_stat(arg);
1767 END OBJ(fs_used, INFO_FS)
1771 obj->data.fs = prepare_fs_stat(arg);
1773 obj->data.i = arg ? atoi(arg) : 1;
1774 END OBJ(nameserver, INFO_DNS)
1775 obj->data.i = arg ? atoi(arg) : 0;
1777 obj->data.i = arg ? atoi(arg) : 1;
1779 obj->data.i = arg ? atoi(arg) : 1;
1783 ERR("goto needs arguments");
1784 obj->type = OBJ_text;
1785 obj->data.s = strndup("${goto}", text_buffer_size);
1789 obj->data.i = atoi(arg);
1795 if (sscanf(arg, "%d %d", &a, &b) != 2) {
1796 sscanf(arg, "%d", &b);
1802 obj->data.pair.a = a;
1803 obj->data.pair.b = b;
1806 END OBJ(i2c, INFO_SYSFS)
1807 char buf1[64], buf2[64];
1808 float factor, offset;
1812 ERR("i2c needs arguments");
1813 obj->type = OBJ_text;
1814 // obj->data.s = strndup("${i2c}", text_buffer_size);
1818 #define HWMON_RESET() {\
1823 if (sscanf(arg, "%63s %d %f %f", buf2, &n, &factor, &offset) == 4) found = 1; else HWMON_RESET();
1824 if (!found && sscanf(arg, "%63s %63s %d %f %f", buf1, buf2, &n, &factor, &offset) == 5) found = 1; else if (!found) HWMON_RESET();
1825 if (!found && sscanf(arg, "%63s %63s %d", buf1, buf2, &n) == 3) found = 1; else if (!found) HWMON_RESET();
1826 if (!found && sscanf(arg, "%63s %d", buf2, &n) == 2) found = 1; else if (!found) HWMON_RESET();
1829 ERR("i2c failed to parse arguments");
1830 obj->type = OBJ_text;
1833 DBGP("parsed i2c args: '%s' '%s' %d %f %f\n", buf1, buf2, n, factor, offset);
1834 obj->data.sysfs.fd = open_i2c_sensor((*buf1) ? buf1 : 0, buf2, n,
1835 &obj->data.sysfs.arg, obj->data.sysfs.devtype);
1836 strncpy(obj->data.sysfs.type, buf2, 63);
1837 obj->data.sysfs.factor = factor;
1838 obj->data.sysfs.offset = offset;
1840 END OBJ(platform, INFO_SYSFS)
1841 char buf1[64], buf2[64];
1842 float factor, offset;
1846 ERR("platform needs arguments");
1847 obj->type = OBJ_text;
1851 if (sscanf(arg, "%63s %d %f %f", buf2, &n, &factor, &offset) == 4) found = 1; else HWMON_RESET();
1852 if (!found && sscanf(arg, "%63s %63s %d %f %f", buf1, buf2, &n, &factor, &offset) == 5) found = 1; else if (!found) HWMON_RESET();
1853 if (!found && sscanf(arg, "%63s %63s %d", buf1, buf2, &n) == 3) found = 1; else if (!found) HWMON_RESET();
1854 if (!found && sscanf(arg, "%63s %d", buf2, &n) == 2) found = 1; else if (!found) HWMON_RESET();
1857 ERR("platform failed to parse arguments");
1858 obj->type = OBJ_text;
1861 DBGP("parsed platform args: '%s' '%s' %d %f %f\n", buf1, buf2, n, factor, offset);
1862 obj->data.sysfs.fd = open_platform_sensor((*buf1) ? buf1 : 0, buf2, n,
1863 &obj->data.sysfs.arg, obj->data.sysfs.devtype);
1864 strncpy(obj->data.sysfs.type, buf2, 63);
1865 obj->data.sysfs.factor = factor;
1866 obj->data.sysfs.offset = offset;
1868 END OBJ(hwmon, INFO_SYSFS)
1869 char buf1[64], buf2[64];
1870 float factor, offset;
1874 ERR("hwmon needs argumanets");
1875 obj->type = OBJ_text;
1879 if (sscanf(arg, "%63s %d %f %f", buf2, &n, &factor, &offset) == 4) found = 1; else HWMON_RESET();
1880 if (!found && sscanf(arg, "%63s %63s %d %f %f", buf1, buf2, &n, &factor, &offset) == 5) found = 1; else if (!found) HWMON_RESET();
1881 if (!found && sscanf(arg, "%63s %63s %d", buf1, buf2, &n) == 3) found = 1; else if (!found) HWMON_RESET();
1882 if (!found && sscanf(arg, "%63s %d", buf2, &n) == 2) found = 1; else if (!found) HWMON_RESET();
1887 ERR("hwmon failed to parse arguments");
1888 obj->type = OBJ_text;
1891 DBGP("parsed hwmon args: '%s' '%s' %d %f %f\n", buf1, buf2, n, factor, offset);
1892 obj->data.sysfs.fd = open_hwmon_sensor((*buf1) ? buf1 : 0, buf2, n,
1893 &obj->data.sysfs.arg, obj->data.sysfs.devtype);
1894 strncpy(obj->data.sysfs.type, buf2, 63);
1895 obj->data.sysfs.factor = factor;
1896 obj->data.sysfs.offset = offset;
1898 #endif /* !__OpenBSD__ */
1901 /* we have three different types of top (top, top_mem and top_time). To
1902 * avoid having almost-same code three times, we have this special
1904 if (strncmp(s, "top", 3) == EQUAL) {
1905 if (!parse_top_args(s, arg, obj)) {
1908 } else OBJ(addr, INFO_NET)
1910 obj->data.net = get_net_stat(arg);
1912 CRIT_ERR("addr needs argument");
1914 #if defined(__linux__)
1915 END OBJ(addrs, INFO_NET)
1917 obj->data.net = get_net_stat(arg);
1919 CRIT_ERR("addrs needs argument");
1921 #endif /* __linux__ */
1923 if (init_tail_object(obj, arg)) {
1924 obj->type = OBJ_text;
1925 obj->data.s = strndup("${tail}", text_buffer_size);
1928 if (init_head_object(obj, arg)) {
1929 obj->type = OBJ_text;
1930 obj->data.s = strndup("${head}", text_buffer_size);
1934 obj->data.s = strndup(arg, text_buffer_size);
1936 CRIT_ERR("lines needs a argument");
1940 obj->data.s = strndup(arg, text_buffer_size);
1942 CRIT_ERR("words needs a argument");
1944 END OBJ(loadavg, INFO_LOADAVG)
1945 int a = 1, b = 2, c = 3, r = 3;
1948 r = sscanf(arg, "%d %d %d", &a, &b, &c);
1949 if (r >= 3 && (c < 1 || c > 3)) {
1952 if (r >= 2 && (b < 1 || b > 3)) {
1955 if (r >= 1 && (a < 1 || a > 3)) {
1959 obj->data.loadavg[0] = (r >= 1) ? (unsigned char) a : 0;
1960 obj->data.loadavg[1] = (r >= 2) ? (unsigned char) b : 0;
1961 obj->data.loadavg[2] = (r >= 3) ? (unsigned char) c : 0;
1962 END OBJ_IF(if_empty, 0)
1964 ERR("if_empty needs an argument");
1965 obj->data.ifblock.s = 0;
1967 obj->data.ifblock.s = strndup(arg, text_buffer_size);
1968 obj->sub = malloc(sizeof(struct text_object));
1969 extract_variable_text_internal(obj->sub,
1970 obj->data.ifblock.s, 0);
1972 END OBJ_IF(if_match, 0)
1974 ERR("if_match needs arguments");
1975 obj->data.ifblock.s = 0;
1977 obj->data.ifblock.s = strndup(arg, text_buffer_size);
1978 obj->sub = malloc(sizeof(struct text_object));
1979 extract_variable_text_internal(obj->sub,
1980 obj->data.ifblock.s, 0);
1982 END OBJ_IF(if_existing, 0)
1984 ERR("if_existing needs an argument or two");
1985 obj->data.ifblock.s = NULL;
1986 obj->data.ifblock.str = NULL;
1988 char buf1[256], buf2[256];
1989 int r = sscanf(arg, "%255s %255[^\n]", buf1, buf2);
1992 obj->data.ifblock.s = strndup(buf1, text_buffer_size);
1993 obj->data.ifblock.str = NULL;
1995 obj->data.ifblock.s = strndup(buf1, text_buffer_size);
1996 obj->data.ifblock.str = strndup(buf2, text_buffer_size);
1999 DBGP("if_existing: '%s' '%s'", obj->data.ifblock.s, obj->data.ifblock.str);
2000 END OBJ_IF(if_mounted, 0)
2002 ERR("if_mounted needs an argument");
2003 obj->data.ifblock.s = 0;
2005 obj->data.ifblock.s = strndup(arg, text_buffer_size);
2007 END OBJ_IF(if_running, 0)
2011 snprintf(buf, 256, "pidof %s >/dev/null", arg);
2012 obj->data.ifblock.s = strndup(buf, text_buffer_size);
2014 ERR("if_running needs an argument");
2015 obj->data.ifblock.s = 0;
2021 char box[256], dst[256];
2025 /* Kapil: Changed from MAIL_FILE to
2026 current_mail_spool since the latter
2027 is a copy of the former if undefined
2028 but the latter should take precedence
2030 strncpy(box, current_mail_spool, sizeof(box));
2032 if (sscanf(arg, "%s %f", box, &n1) != 2) {
2034 strncpy(box, arg, sizeof(box));
2038 variable_substitute(box, dst, sizeof(dst));
2039 obj->data.local_mail.box = strndup(dst, text_buffer_size);
2040 obj->data.local_mail.interval = n1;
2041 END OBJ(new_mails, 0)
2043 char box[256], dst[256];
2047 strncpy(box, current_mail_spool, sizeof(box));
2049 if (sscanf(arg, "%s %f", box, &n1) != 2) {
2051 strncpy(box, arg, sizeof(box));
2055 variable_substitute(box, dst, sizeof(dst));
2056 obj->data.local_mail.box = strndup(dst, text_buffer_size);
2057 obj->data.local_mail.interval = n1;
2058 END OBJ(seen_mails, 0)
2060 char box[256], dst[256];
2064 strncpy(box, current_mail_spool, sizeof(box));
2066 if (sscanf(arg, "%s %f", box, &n1) != 2) {
2068 strncpy(box, arg, sizeof(box));
2072 variable_substitute(box, dst, sizeof(dst));
2073 obj->data.local_mail.box = strndup(dst, text_buffer_size);
2074 obj->data.local_mail.interval = n1;
2075 END OBJ(unseen_mails, 0)
2077 char box[256], dst[256];
2081 strncpy(box, current_mail_spool, sizeof(box));
2083 if (sscanf(arg, "%s %f", box, &n1) != 2) {
2085 strncpy(box, arg, sizeof(box));
2089 variable_substitute(box, dst, sizeof(dst));
2090 obj->data.local_mail.box = strndup(dst, text_buffer_size);
2091 obj->data.local_mail.interval = n1;
2092 END OBJ(flagged_mails, 0)
2094 char box[256], dst[256];
2098 strncpy(box, current_mail_spool, sizeof(box));
2100 if (sscanf(arg, "%s %f", box, &n1) != 2) {
2102 strncpy(box, arg, sizeof(box));
2106 variable_substitute(box, dst, sizeof(dst));
2107 obj->data.local_mail.box = strndup(dst, text_buffer_size);
2108 obj->data.local_mail.interval = n1;
2109 END OBJ(unflagged_mails, 0)
2111 char box[256], dst[256];
2115 strncpy(box, current_mail_spool, sizeof(box));
2117 if (sscanf(arg, "%s %f", box, &n1) != 2) {
2119 strncpy(box, arg, sizeof(box));
2123 variable_substitute(box, dst, sizeof(dst));
2124 obj->data.local_mail.box = strndup(dst, text_buffer_size);
2125 obj->data.local_mail.interval = n1;
2126 END OBJ(forwarded_mails, 0)
2128 char box[256], dst[256];
2132 strncpy(box, current_mail_spool, sizeof(box));
2134 if (sscanf(arg, "%s %f", box, &n1) != 2) {
2136 strncpy(box, arg, sizeof(box));
2140 variable_substitute(box, dst, sizeof(dst));
2141 obj->data.local_mail.box = strndup(dst, text_buffer_size);
2142 obj->data.local_mail.interval = n1;
2143 END OBJ(unforwarded_mails, 0)
2145 char box[256], dst[256];
2149 strncpy(box, current_mail_spool, sizeof(box));
2151 if (sscanf(arg, "%s %f", box, &n1) != 2) {
2153 strncpy(box, arg, sizeof(box));
2157 variable_substitute(box, dst, sizeof(dst));
2158 obj->data.local_mail.box = strndup(dst, text_buffer_size);
2159 obj->data.local_mail.interval = n1;
2160 END OBJ(replied_mails, 0)
2162 char box[256], dst[256];
2166 strncpy(box, current_mail_spool, sizeof(box));
2168 if (sscanf(arg, "%s %f", box, &n1) != 2) {
2170 strncpy(box, arg, sizeof(box));
2174 variable_substitute(box, dst, sizeof(dst));
2175 obj->data.local_mail.box = strndup(dst, text_buffer_size);
2176 obj->data.local_mail.interval = n1;
2177 END OBJ(unreplied_mails, 0)
2179 char box[256], dst[256];
2183 strncpy(box, current_mail_spool, sizeof(box));
2185 if (sscanf(arg, "%s %f", box, &n1) != 2) {
2187 strncpy(box, arg, sizeof(box));
2191 variable_substitute(box, dst, sizeof(dst));
2192 obj->data.local_mail.box = strndup(dst, text_buffer_size);
2193 obj->data.local_mail.interval = n1;
2194 END OBJ(draft_mails, 0)
2196 char box[256], dst[256];
2200 strncpy(box, current_mail_spool, sizeof(box));
2202 if (sscanf(arg, "%s %f", box, &n1) != 2) {
2204 strncpy(box, arg, sizeof(box));
2208 variable_substitute(box, dst, sizeof(dst));
2209 obj->data.local_mail.box = strndup(dst, text_buffer_size);
2210 obj->data.local_mail.interval = n1;
2211 END OBJ(trashed_mails, 0)
2213 char box[256], dst[256];
2217 strncpy(box, current_mail_spool, sizeof(box));
2219 if (sscanf(arg, "%s %f", box, &n1) != 2) {
2221 strncpy(box, arg, sizeof(box));
2225 variable_substitute(box, dst, sizeof(dst));
2226 obj->data.local_mail.box = strndup(dst, text_buffer_size);
2227 obj->data.local_mail.interval = n1;
2228 END OBJ(mboxscan, 0)
2229 obj->data.mboxscan.args = (char *) malloc(text_buffer_size);
2230 obj->data.mboxscan.output = (char *) malloc(text_buffer_size);
2231 /* if '1' (in mboxscan.c) then there was SIGUSR1, hmm */
2232 obj->data.mboxscan.output[0] = 1;
2233 strncpy(obj->data.mboxscan.args, arg, text_buffer_size);
2234 END OBJ(mem, INFO_MEM)
2235 END OBJ(memeasyfree, INFO_MEM)
2236 END OBJ(memfree, INFO_MEM)
2237 END OBJ(memmax, INFO_MEM)
2238 END OBJ(memperc, INFO_MEM)
2240 END OBJ(memgauge, INFO_MEM)
2241 SIZE_DEFAULTS(gauge);
2242 scan_gauge(arg, &obj->data.pair.a, &obj->data.pair.b);
2243 END OBJ(membar, INFO_MEM)
2245 scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
2246 END OBJ(memgraph, INFO_MEM)
2248 SIZE_DEFAULTS(graph);
2249 buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
2250 &obj->e, &obj->char_a, &obj->char_b);
2256 END OBJ(mixer, INFO_MIXER)
2257 obj->data.l = mixer_init(arg);
2258 END OBJ(mixerl, INFO_MIXER)
2259 obj->data.l = mixer_init(arg);
2260 END OBJ(mixerr, INFO_MIXER)
2261 obj->data.l = mixer_init(arg);
2263 END OBJ(mixerbar, INFO_MIXER)
2265 scan_mixer_bar(arg, &obj->data.mixerbar.l, &obj->data.mixerbar.w,
2266 &obj->data.mixerbar.h);
2267 END OBJ(mixerlbar, INFO_MIXER)
2269 scan_mixer_bar(arg, &obj->data.mixerbar.l, &obj->data.mixerbar.w,
2270 &obj->data.mixerbar.h);
2271 END OBJ(mixerrbar, INFO_MIXER)
2273 scan_mixer_bar(arg, &obj->data.mixerbar.l, &obj->data.mixerbar.w,
2274 &obj->data.mixerbar.h);
2276 END OBJ_IF(if_mixer_mute, INFO_MIXER)
2277 obj->data.ifblock.i = mixer_init(arg);
2279 END OBJ(monitor, INFO_X11)
2280 END OBJ(monitor_number, INFO_X11)
2282 END OBJ(nodename, 0)
2283 END OBJ(processes, INFO_PROCS)
2284 END OBJ(running_processes, INFO_RUN_PROCS)
2285 END OBJ(shadecolor, 0)
2287 obj->data.l = arg ? get_x11_color(arg) : default_bg_color;
2289 END OBJ(outlinecolor, 0)
2291 obj->data.l = arg ? get_x11_color(arg) : default_out_color;
2293 END OBJ(stippled_hr, 0)
2295 int a = stippled_borders, b = 1;
2298 if (sscanf(arg, "%d %d", &a, &b) != 2) {
2299 sscanf(arg, "%d", &b);
2305 obj->data.pair.a = a;
2306 obj->data.pair.b = b;
2308 END OBJ(swap, INFO_MEM)
2309 END OBJ(swapmax, INFO_MEM)
2310 END OBJ(swapperc, INFO_MEM)
2312 END OBJ(swapbar, INFO_MEM)
2314 scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
2318 obj->data.s = strndup(arg ? arg : "%F %T", text_buffer_size);
2320 obj->data.s = strndup(arg ? arg : "%F %T", text_buffer_size);
2322 char buf1[256], buf2[256], *fmt, *tz;
2326 int nArgs = sscanf(arg, "%255s %255[^\n]", buf1, buf2);
2336 obj->data.tztime.fmt = strndup(fmt ? fmt : "%F %T", text_buffer_size);
2337 obj->data.tztime.tz = tz ? strndup(tz, text_buffer_size) : NULL;
2339 END OBJ(iconv_start, 0)
2340 if (iconv_converting) {
2341 CRIT_ERR("You must stop your last iconv conversion before "
2342 "starting another");
2345 char iconv_from[CODEPAGE_LENGTH];
2346 char iconv_to[CODEPAGE_LENGTH];
2348 if (sscanf(arg, "%s %s", iconv_from, iconv_to) != 2) {
2349 CRIT_ERR("Invalid arguments for iconv_start");
2353 new_iconv = iconv_open(iconv_to, iconv_from);
2354 if (new_iconv == (iconv_t) (-1)) {
2355 ERR("Can't convert from %s to %s.", iconv_from, iconv_to);
2357 obj->a = register_iconv(&new_iconv);
2358 iconv_converting = 1;
2362 CRIT_ERR("Iconv requires arguments");
2364 END OBJ(iconv_stop, 0)
2365 iconv_converting = 0;
2368 END OBJ(totaldown, INFO_NET)
2370 obj->data.net = get_net_stat(arg);
2372 CRIT_ERR("totaldown needs argument");
2374 END OBJ(totalup, INFO_NET)
2375 obj->data.net = get_net_stat(arg);
2377 obj->data.net = get_net_stat(arg);
2379 CRIT_ERR("totalup needs argument");
2382 END OBJ_IF(if_updatenr, 0)
2383 obj->data.ifblock.i = arg ? atoi(arg) : 0;
2384 if(obj->data.ifblock.i == 0) CRIT_ERR("if_updatenr needs a number above 0 as argument");
2385 updatereset = obj->data.ifblock.i > updatereset ? obj->data.ifblock.i : updatereset;
2387 obj->data.i = arg ? atoi(arg) : 0;
2389 obj->data.i = arg ? atoi(arg) : 0;
2390 END OBJ(upspeed, INFO_NET)
2392 obj->data.net = get_net_stat(arg);
2394 CRIT_ERR("upspeed needs argument");
2396 END OBJ(upspeedf, INFO_NET)
2398 obj->data.net = get_net_stat(arg);
2400 CRIT_ERR("upspeedf needs argument");
2404 END OBJ(upspeedgraph, INFO_NET)
2406 SIZE_DEFAULTS(graph);
2407 buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
2408 &obj->e, &obj->char_a, &obj->char_b);
2410 // default to DEFAULTNETDEV
2411 buf = strndup(buf ? buf : "DEFAULTNETDEV", text_buffer_size);
2412 obj->data.net = get_net_stat(buf);
2415 END OBJ(uptime_short, INFO_UPTIME)
2416 END OBJ(uptime, INFO_UPTIME)
2417 END OBJ(user_names, INFO_USERS)
2418 END OBJ(user_times, INFO_USERS)
2419 END OBJ(user_terms, INFO_USERS)
2420 END OBJ(user_number, INFO_USERS)
2421 #if defined(__linux__)
2422 END OBJ(gw_iface, INFO_GW)
2423 END OBJ(gw_ip, INFO_GW)
2424 #endif /* !__linux__ */
2426 END OBJ(adt746xcpu, 0)
2427 END OBJ(adt746xfan, 0)
2428 #endif /* !__OpenBSD__ */
2429 #if (defined(__FreeBSD__) || defined(__FreeBSD_kernel__) \
2430 || defined(__OpenBSD__)) && (defined(i386) || defined(__i386__))
2431 END OBJ(apm_adapter, 0)
2432 END OBJ(apm_battery_life, 0)
2433 END OBJ(apm_battery_time, 0)
2434 #endif /* __FreeBSD__ */
2435 END OBJ_THREAD(imap_unseen, 0)
2438 obj->data.mail = parse_mail_args(IMAP_TYPE, arg);
2443 END OBJ_THREAD(imap_messages, 0)
2446 obj->data.mail = parse_mail_args(IMAP_TYPE, arg);
2451 END OBJ_THREAD(pop3_unseen, 0)
2454 obj->data.mail = parse_mail_args(POP3_TYPE, arg);
2459 END OBJ_THREAD(pop3_used, 0)
2462 obj->data.mail = parse_mail_args(POP3_TYPE, arg);
2470 obj->data.s = strndup(arg, text_buffer_size);
2472 ERR("smapi needs an argument");
2473 END OBJ_IF(if_smapi_bat_installed, 0)
2475 ERR("if_smapi_bat_installed needs an argument");
2476 obj->data.ifblock.s = 0;
2478 obj->data.ifblock.s = strndup(arg, text_buffer_size);
2479 END OBJ(smapi_bat_perc, 0)
2481 obj->data.s = strndup(arg, text_buffer_size);
2483 ERR("smapi_bat_perc needs an argument");
2484 END OBJ(smapi_bat_temp, 0)
2486 obj->data.s = strndup(arg, text_buffer_size);
2488 ERR("smapi_bat_temp needs an argument");
2489 END OBJ(smapi_bat_power, 0)
2491 obj->data.s = strndup(arg, text_buffer_size);
2493 ERR("smapi_bat_power needs an argument");
2494 END OBJ(smapi_bat_bar, 0)
2498 if(sscanf(arg, "%i %n", &obj->data.i, &cnt) <= 0) {
2499 ERR("first argument to smapi_bat_bar must be an integer value");
2503 arg = scan_bar(arg + cnt, &obj->a, &obj->b);
2506 ERR("smapi_bat_bar needs an argument");
2509 #define mpd_set_maxlen(name) \
2512 sscanf(arg, "%d", &i); \
2514 obj->data.i = i + 1; \
2516 ERR(#name ": invalid length argument"); \
2518 END OBJ(mpd_artist, INFO_MPD)
2519 mpd_set_maxlen(mpd_artist);
2521 END OBJ(mpd_title, INFO_MPD)
2522 mpd_set_maxlen(mpd_title);
2524 END OBJ(mpd_random, INFO_MPD) init_mpd();
2525 END OBJ(mpd_repeat, INFO_MPD) init_mpd();
2526 END OBJ(mpd_elapsed, INFO_MPD) init_mpd();
2527 END OBJ(mpd_length, INFO_MPD) init_mpd();
2528 END OBJ(mpd_track, INFO_MPD)
2529 mpd_set_maxlen(mpd_track);
2531 END OBJ(mpd_name, INFO_MPD)
2532 mpd_set_maxlen(mpd_name);
2534 END OBJ(mpd_file, INFO_MPD)
2535 mpd_set_maxlen(mpd_file);
2537 END OBJ(mpd_percent, INFO_MPD) init_mpd();
2538 END OBJ(mpd_album, INFO_MPD)
2539 mpd_set_maxlen(mpd_album);
2541 END OBJ(mpd_vol, INFO_MPD) init_mpd();
2542 END OBJ(mpd_bitrate, INFO_MPD) init_mpd();
2543 END OBJ(mpd_status, INFO_MPD) init_mpd();
2545 END OBJ(mpd_bar, INFO_MPD)
2547 scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
2550 END OBJ(mpd_smart, INFO_MPD)
2551 mpd_set_maxlen(mpd_smart);
2553 END OBJ_IF(if_mpd_playing, INFO_MPD)
2555 #undef mpd_set_maxlen
2558 END OBJ(moc_state, INFO_MOC)
2559 END OBJ(moc_file, INFO_MOC)
2560 END OBJ(moc_title, INFO_MOC)
2561 END OBJ(moc_artist, INFO_MOC)
2562 END OBJ(moc_song, INFO_MOC)
2563 END OBJ(moc_album, INFO_MOC)
2564 END OBJ(moc_totaltime, INFO_MOC)
2565 END OBJ(moc_timeleft, INFO_MOC)
2566 END OBJ(moc_curtime, INFO_MOC)
2567 END OBJ(moc_bitrate, INFO_MOC)
2568 END OBJ(moc_rate, INFO_MOC)
2571 END OBJ(xmms2_artist, INFO_XMMS2)
2572 END OBJ(xmms2_album, INFO_XMMS2)
2573 END OBJ(xmms2_title, INFO_XMMS2)
2574 END OBJ(xmms2_genre, INFO_XMMS2)
2575 END OBJ(xmms2_comment, INFO_XMMS2)
2576 END OBJ(xmms2_url, INFO_XMMS2)
2577 END OBJ(xmms2_tracknr, INFO_XMMS2)
2578 END OBJ(xmms2_bitrate, INFO_XMMS2)
2579 END OBJ(xmms2_date, INFO_XMMS2)
2580 END OBJ(xmms2_id, INFO_XMMS2)
2581 END OBJ(xmms2_duration, INFO_XMMS2)
2582 END OBJ(xmms2_elapsed, INFO_XMMS2)
2583 END OBJ(xmms2_size, INFO_XMMS2)
2584 END OBJ(xmms2_status, INFO_XMMS2)
2585 END OBJ(xmms2_percent, INFO_XMMS2)
2586 END OBJ(xmms2_bar, INFO_XMMS2)
2588 scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
2589 END OBJ(xmms2_smart, INFO_XMMS2)
2590 END OBJ(xmms2_playlist, INFO_XMMS2)
2591 END OBJ(xmms2_timesplayed, INFO_XMMS2)
2592 END OBJ_IF(if_xmms2_connected, INFO_XMMS2)
2595 END OBJ(audacious_status, INFO_AUDACIOUS)
2596 END OBJ(audacious_title, INFO_AUDACIOUS)
2598 sscanf(arg, "%d", &info.audacious.max_title_len);
2599 if (info.audacious.max_title_len > 0) {
2600 info.audacious.max_title_len++;
2602 CRIT_ERR("audacious_title: invalid length argument");
2605 END OBJ(audacious_length, INFO_AUDACIOUS)
2606 END OBJ(audacious_length_seconds, INFO_AUDACIOUS)
2607 END OBJ(audacious_position, INFO_AUDACIOUS)
2608 END OBJ(audacious_position_seconds, INFO_AUDACIOUS)
2609 END OBJ(audacious_bitrate, INFO_AUDACIOUS)
2610 END OBJ(audacious_frequency, INFO_AUDACIOUS)
2611 END OBJ(audacious_channels, INFO_AUDACIOUS)
2612 END OBJ(audacious_filename, INFO_AUDACIOUS)
2613 END OBJ(audacious_playlist_length, INFO_AUDACIOUS)
2614 END OBJ(audacious_playlist_position, INFO_AUDACIOUS)
2615 END OBJ(audacious_main_volume, INFO_AUDACIOUS)
2616 END OBJ(audacious_bar, INFO_AUDACIOUS)
2618 scan_bar(arg, &obj->a, &obj->b);
2621 END OBJ(bmpx_title, INFO_BMPX)
2622 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
2623 END OBJ(bmpx_artist, INFO_BMPX)
2624 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
2625 END OBJ(bmpx_album, INFO_BMPX)
2626 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
2627 END OBJ(bmpx_track, INFO_BMPX)
2628 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
2629 END OBJ(bmpx_uri, INFO_BMPX)
2630 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
2631 END OBJ(bmpx_bitrate, INFO_BMPX)
2632 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
2638 char *userid = (char *) malloc(20 * sizeof(char));
2639 char *apikey = (char *) malloc(64 * sizeof(char));
2640 char *charid = (char *) malloc(20 * sizeof(char));
2642 argc = sscanf(arg, "%20s %64s %20s", userid, apikey, charid);
2643 obj->data.eve.charid = charid;
2644 obj->data.eve.userid = userid;
2645 obj->data.eve.apikey = apikey;
2649 CRIT_ERR("eve needs arguments: <userid> <apikey> <characterid>");
2655 int argc, delay, act_par;
2656 unsigned int nrspaces = 0;
2657 char *uri = (char *) malloc(128 * sizeof(char));
2658 char *action = (char *) malloc(64 * sizeof(char));
2660 argc = sscanf(arg, "%127s %d %63s %d %u", uri, &delay, action,
2661 &act_par, &nrspaces);
2662 obj->data.rss.uri = uri;
2663 obj->data.rss.delay = delay;
2664 obj->data.rss.action = action;
2665 obj->data.rss.act_par = act_par;
2666 obj->data.rss.nrspaces = nrspaces;
2670 CRIT_ERR("rss needs arguments: <uri> <delay in minutes> <action> "
2671 "[act_par] [spaces in front]");
2677 obj->data.s = strndup(arg, text_buffer_size);
2679 CRIT_ERR("lua needs arguments: <function name> [function parameters]");
2681 END OBJ(lua_parse, 0)
2683 obj->data.s = strndup(arg, text_buffer_size);
2685 CRIT_ERR("lua_parse needs arguments: <function name> [function parameters]");
2687 END OBJ(lua_read_parse, 0)
2689 obj->data.s = strndup(arg, text_buffer_size);
2691 CRIT_ERR("lua_read_parse needs arguments: <function name> <string to pass>");
2697 arg = scan_bar(arg, &obj->a, &obj->b);
2699 obj->data.s = strndup(arg, text_buffer_size);
2701 CRIT_ERR("lua_bar needs arguments: <height>,<width> <function name> [function parameters]");
2704 CRIT_ERR("lua_bar needs arguments: <height>,<width> <function name> [function parameters]");
2706 END OBJ(lua_graph, 0)
2707 SIZE_DEFAULTS(graph);
2709 arg = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
2710 &obj->e, &obj->char_a, &obj->char_b);
2712 obj->data.s = strndup(arg, text_buffer_size);
2714 CRIT_ERR("lua_graph needs arguments: <\"normal\"|\"log\"> <height>,<width> <gradient colour 1> <gradient colour 2> <scale> <function name> [function parameters]");
2717 CRIT_ERR("lua_graph needs arguments: <\"normal\"|\"log\"> <height>,<width> <gradient colour 1> <gradient colour 2> <scale> <function name> [function parameters]");
2719 END OBJ(lua_gauge, 0)
2720 SIZE_DEFAULTS(gauge);
2722 arg = scan_gauge(arg, &obj->a, &obj->b);
2724 obj->data.s = strndup(arg, text_buffer_size);
2726 CRIT_ERR("lua_gauge needs arguments: <height>,<width> <function name> [function parameters]");
2729 CRIT_ERR("lua_gauge needs arguments: <height>,<width> <function name> [function parameters]");
2732 #endif /* HAVE_LUA */
2735 if (scan_hddtemp(arg, &obj->data.hddtemp.dev,
2736 &obj->data.hddtemp.addr, &obj->data.hddtemp.port)) {
2737 ERR("hddtemp needs arguments");
2738 obj->type = OBJ_text;
2739 obj->data.s = strndup("${hddtemp}", text_buffer_size);
2740 obj->data.hddtemp.update_time = 0;
2742 obj->data.hddtemp.temp = NULL;
2744 #ifdef TCP_PORT_MONITOR
2745 END OBJ(tcp_portmon, INFO_TCP_PORT_MONITOR)
2746 tcp_portmon_init(arg, &obj->data.tcp_port_monitor);
2748 END OBJ(entropy_avail, INFO_ENTROPY)
2749 END OBJ(entropy_poolsize, INFO_ENTROPY)
2751 END OBJ(entropy_bar, INFO_ENTROPY)
2753 scan_bar(arg, &obj->a, &obj->b);
2758 obj->data.scroll.step = 1;
2759 if (arg && sscanf(arg, "%u %n", &obj->data.scroll.show, &n1) > 0) {
2760 if (sscanf(arg + n1, "%u %n", &obj->data.scroll.step, &n2) > 0)
2762 obj->data.scroll.text = strndup(arg + n1, text_buffer_size);
2763 obj->data.scroll.start = 0;
2764 obj->sub = malloc(sizeof(struct text_object));
2765 extract_variable_text_internal(obj->sub,
2766 obj->data.scroll.text, 0);
2768 CRIT_ERR("scroll needs arguments: <length> [<step>] <text>");
2773 unsigned int indenting = 0; //vars can be used as args for other vars
2776 startvar[0] = endvar[0] = startvar[1] = endvar[1] = -1;
2778 for(i=0; arg[i] != 0 && j < 2; i++) {
2779 if(startvar[j] == -1) {
2783 }else if(endvar[j] == -1) {
2786 }else if(arg[i] == '}') {
2789 if (indenting == 0 && arg[i+1] < 48) { //<48 has 0, $, and the most used chars not used in varnames but not { or }
2795 if(startvar[0] >= 0 && endvar[0] >= 0 && startvar[1] >= 0 && endvar[1] >= 0) {
2796 obj->data.combine.left=malloc(endvar[0]-startvar[0]+1);
2797 obj->data.combine.seperation=malloc(startvar[1]-endvar[0]+1);
2798 obj->data.combine.right=malloc(endvar[1]-startvar[1]+1);
2799 strncpy(obj->data.combine.left, arg+startvar[0], endvar[0]-startvar[0]); obj->data.combine.left[endvar[0]-startvar[0]]=0;
2800 strncpy(obj->data.combine.seperation, arg+endvar[0], startvar[1]-endvar[0]); obj->data.combine.seperation[startvar[1]-endvar[0]]=0;
2801 strncpy(obj->data.combine.right, arg+startvar[1], endvar[1]-startvar[1]); obj->data.combine.right[endvar[1]-startvar[1]]=0;
2802 obj->sub = malloc(sizeof(struct text_object));
2803 extract_variable_text_internal(obj->sub, obj->data.combine.left, 0);
2804 obj->sub->sub = malloc(sizeof(struct text_object));
2805 extract_variable_text_internal(obj->sub->sub, obj->data.combine.right, 0);
2807 CRIT_ERR("combine needs arguments: <text1> <text2>");
2810 CRIT_ERR("combine needs arguments: <text1> <text2>");
2815 CRIT_ERR("nvidia needs an argument\n");
2816 } else if (set_nvidia_type(&obj->data.nvidia, arg)) {
2817 CRIT_ERR("nvidia: invalid argument"
2818 " specified: '%s'\n", arg);
2823 END OBJ(apcupsd, INFO_APCUPSD)
2827 if (sscanf(arg, "%63s %d", host, &port) != 2) {
2828 CRIT_ERR("apcupsd needs arguments: <host> <port>");
2830 info.apcupsd.port = htons(port);
2831 strncpy(info.apcupsd.host, host, sizeof(info.apcupsd.host));
2834 CRIT_ERR("apcupsd needs arguments: <host> <port>");
2836 END OBJ(apcupsd_name, INFO_APCUPSD)
2837 END OBJ(apcupsd_model, INFO_APCUPSD)
2838 END OBJ(apcupsd_upsmode, INFO_APCUPSD)
2839 END OBJ(apcupsd_cable, INFO_APCUPSD)
2840 END OBJ(apcupsd_status, INFO_APCUPSD)
2841 END OBJ(apcupsd_linev, INFO_APCUPSD)
2842 END OBJ(apcupsd_load, INFO_APCUPSD)
2844 END OBJ(apcupsd_loadbar, INFO_APCUPSD)
2846 scan_bar(arg, &obj->a, &obj->b);
2847 END OBJ(apcupsd_loadgraph, INFO_APCUPSD)
2849 SIZE_DEFAULTS(graph);
2850 buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
2851 &obj->e, &obj->char_a, &obj->char_b);
2853 END OBJ(apcupsd_loadgauge, INFO_APCUPSD)
2854 SIZE_DEFAULTS(gauge);
2855 scan_gauge(arg, &obj->a, &obj->b);
2857 END OBJ(apcupsd_charge, INFO_APCUPSD)
2858 END OBJ(apcupsd_timeleft, INFO_APCUPSD)
2859 END OBJ(apcupsd_temp, INFO_APCUPSD)
2860 END OBJ(apcupsd_lastxfer, INFO_APCUPSD)
2861 #endif /* APCUPSD */
2865 ERR("unknown variable %s", s);
2866 obj->type = OBJ_text;
2867 snprintf(buf, 256, "${%s}", s);
2868 obj->data.s = strndup(buf, text_buffer_size);
2875 static struct text_object *create_plain_text(const char *s)
2877 struct text_object *obj;
2879 if (s == NULL || *s == '\0') {
2883 obj = new_text_object_internal();
2885 obj->type = OBJ_text;
2886 obj->data.s = strndup(s, text_buffer_size);
2890 /* backslash_escape - do the actual substitution task for template objects
2892 * The field templates is used for substituting the \N occurences. Set it to
2893 * NULL to leave them as they are.
2895 static char *backslash_escape(const char *src, char **templates, unsigned int template_count)
2899 unsigned int dup_idx = 0, dup_len;
2901 dup_len = strlen(src) + 1;
2902 src_dup = malloc(dup_len * sizeof(char));
2910 if (*(p + 1) == '\\') {
2911 src_dup[dup_idx++] = '\\';
2913 } else if (*(p + 1) == ' ') {
2914 src_dup[dup_idx++] = ' ';
2916 } else if (*(p + 1) == 'n') {
2917 src_dup[dup_idx++] = '\n';
2919 } else if (templates) {
2920 unsigned int tmpl_num;
2922 if ((sscanf(p + 1, "%u%n", &tmpl_num, &digits) <= 0) ||
2923 (tmpl_num > template_count))
2925 dup_len += strlen(templates[tmpl_num - 1]);
2926 src_dup = realloc(src_dup, dup_len * sizeof(char));
2927 sprintf(src_dup + dup_idx, "%s", templates[tmpl_num - 1]);
2928 dup_idx += strlen(templates[tmpl_num - 1]);
2933 src_dup[dup_idx++] = *p;
2938 src_dup[dup_idx] = '\0';
2939 src_dup = realloc(src_dup, (strlen(src_dup) + 1) * sizeof(char));
2943 /* handle_template_object - core logic of the template object
2945 * use config variables like this:
2946 * template1 = "$\1\2"
2947 * template2 = "\1: ${fs_bar 4,100 \2} ${fs_used \2} / ${fs_size \2}"
2949 * and use them like this:
2950 * ${template1 node name}
2951 * ${template2 root /}
2952 * ${template2 cdrom /mnt/cdrom}
2954 static char *handle_template(const char *tmpl, const char *args)
2956 char *args_dup, *p, *p_old;
2957 char **argsp = NULL;
2958 unsigned int argcnt = 0, template_idx, i;
2961 if ((sscanf(tmpl, "template%u", &template_idx) != 1) ||
2965 args_dup = strdup(args);
2968 while (*p && (*p == ' ' && *(p - 1) != '\\'))
2970 if (*(p - 1) == '\\')
2973 while (*p && (*p != ' ' || *(p - 1) == '\\'))
2979 argsp = realloc(argsp, ++argcnt * sizeof(char *));
2980 argsp[argcnt - 1] = p_old;
2982 for (i = 0; i < argcnt; i++) {
2984 tmp = backslash_escape(argsp[i], NULL, 0);
2985 DBGP2("%s: substituted arg '%s' to '%s'", tmpl, argsp[i], tmp);
2989 eval_text = backslash_escape(template[template_idx], argsp, argcnt);
2990 DBGP("substituted %s, output is '%s'", tmpl, eval_text);
2992 for (i = 0; i < argcnt; i++)
2998 static char *find_and_replace_templates(const char *inbuf)
3000 char *outbuf, *indup, *p, *o, *templ, *args, *tmpl_out;
3003 outlen = strlen(inbuf) + 1;
3004 o = outbuf = calloc(outlen, sizeof(char));
3005 memset(outbuf, 0, outlen * sizeof(char));
3007 p = indup = strdup(inbuf);
3009 while (*p && *p != '$')
3015 if (strncmp(p, "$template", 9) && strncmp(p, "${template", 10)) {
3020 if (*(p + 1) == '{') {
3042 tmpl_out = handle_template(templ, args);
3044 outlen += strlen(tmpl_out);
3045 outbuf = realloc(outbuf, outlen * sizeof(char));
3046 strcat (outbuf, tmpl_out);
3048 o = outbuf + strlen(outbuf);
3050 ERR("failed to handle template '%s' with args '%s'", templ, args);
3054 outbuf = realloc(outbuf, (strlen(outbuf) + 1) * sizeof(char));
3059 static int text_contains_templates(const char *text)
3061 if (strcasestr(text, "${template") != NULL)
3063 if (strcasestr(text, "$template") != NULL)
3068 static void strfold(char *start, int count)
3071 for (curplace = start + count; *curplace != 0; curplace++) {
3072 *(curplace - count) = *curplace;
3074 *(curplace - count - 1) = 0;
3077 static size_t remove_comments(char *string)
3079 char *curplace, *curplace2;
3081 for (curplace = string; *curplace != 0; curplace++) {
3082 if (*curplace == '\\' && *(curplace + 1) == '#') {
3083 // strcpy can't be used for overlapping strings
3084 strfold(curplace, 1);
3086 } else if (*curplace == '#') {
3087 // remove everything until we hit a '\n'
3088 curplace2 = curplace;
3089 while (*curplace2) {
3091 if (*curplace2 == '\n' &&
3092 *(curplace2 + 1) != '#') break;
3095 strfold(curplace, curplace2 - curplace);
3096 folded += curplace2 - curplace;
3105 static int extract_variable_text_internal(struct text_object *retval, const char *const_p, char allow_threaded)
3107 struct text_object *obj;
3108 char *p, *s, *orig_p;
3110 void *ifblock_opaque = NULL;
3115 p = strndup(const_p, max_user_text - 1);
3116 while (text_contains_templates(p)) {
3118 tmp = find_and_replace_templates(p);
3124 if (strcmp(p, const_p)) {
3125 DBGP("replaced all templates in text: input is\n'%s'\noutput is\n'%s'", const_p, p);
3127 DBGP("no templates to replace");
3130 memset(retval, 0, sizeof(struct text_object));
3132 line = global_text_lines;
3140 obj = create_plain_text(s);
3142 append_object(retval, obj);
3152 /* variable is either $foo or ${foo} */
3154 unsigned int brl = 1, brr = 0;
3158 while (*p && brl != brr) {
3173 while (*p && (isalnum((int) *p) || *p == '_')) {
3178 /* copy variable to buffer */
3179 len = (p - s > 255) ? 255 : (p - s);
3180 strncpy(buf, s, len);
3188 /* search for variable in environment */
3192 obj = create_plain_text(var);
3194 append_object(retval, obj);
3199 /* if variable wasn't found in environment, use some special */
3204 if (strchr(buf, ' ')) {
3205 arg = strchr(buf, ' ');
3208 while (isspace((int) *arg)) {
3216 /* lowercase variable name */
3219 *tmp_p = tolower(*tmp_p);
3223 obj = construct_text_object(buf, arg,
3224 line, allow_threaded,
3227 append_object(retval, obj);
3231 obj = create_plain_text("$");
3234 append_object(retval, obj);
3237 } else if (*p == '#') {
3243 obj = create_plain_text(s);
3245 append_object(retval, obj);
3248 if (!ifblock_stack_empty(&ifblock_opaque)) {
3249 ERR("one or more $endif's are missing");
3256 static void extract_variable_text(const char *p)
3258 free_text_objects(&global_root_object, 0);
3272 extract_variable_text_internal(&global_root_object, p, 1);
3275 int parse_conky_vars(struct text_object *root, char *txt, char *p, struct information *cur)
3277 extract_variable_text_internal(root, txt, 0);
3278 generate_text_internal(p, max_user_text, *root, cur);
3282 static inline struct mail_s *ensure_mail_thread(struct text_object *obj,
3283 void *thread(void *), const char *text)
3285 if (obj->char_b && info.mail) {
3286 // this means we use info
3287 if (!info.mail->p_timed_thread) {
3288 info.mail->p_timed_thread =
3289 timed_thread_create(thread,
3290 (void *) info.mail, info.mail->interval * 1000000);
3291 if (!info.mail->p_timed_thread) {
3292 ERR("Error creating %s timed thread", text);
3294 timed_thread_register(info.mail->p_timed_thread,
3295 &info.mail->p_timed_thread);
3296 if (timed_thread_run(info.mail->p_timed_thread)) {
3297 ERR("Error running %s timed thread", text);
3301 } else if (obj->data.mail) {
3302 // this means we use obj
3303 if (!obj->data.mail->p_timed_thread) {
3304 obj->data.mail->p_timed_thread =
3305 timed_thread_create(thread,
3306 (void *) obj->data.mail,
3307 obj->data.mail->interval * 1000000);
3308 if (!obj->data.mail->p_timed_thread) {
3309 ERR("Error creating %s timed thread", text);
3311 timed_thread_register(obj->data.mail->p_timed_thread,
3312 &obj->data.mail->p_timed_thread);
3313 if (timed_thread_run(obj->data.mail->p_timed_thread)) {
3314 ERR("Error running %s timed thread", text);
3317 return obj->data.mail;
3318 } else if (!obj->a) {
3319 // something is wrong, warn once then stop
3320 ERR("There's a problem with your mail settings. "
3321 "Check that the global mail settings are properly defined"
3322 " (line %li).", obj->line);
3328 char *format_time(unsigned long timeval, const int width)
3331 unsigned long nt; // narrow time, for speed on 32-bit
3332 unsigned cc; // centiseconds
3333 unsigned nn; // multi-purpose whatever
3336 cc = nt % 100; // centiseconds past second
3337 nt /= 100; // total seconds
3338 nn = nt % 60; // seconds past the minute
3339 nt /= 60; // total minutes
3340 if (width >= snprintf(buf, sizeof buf, "%lu:%02u.%02u",
3342 return strndup(buf, text_buffer_size);
3344 if (width >= snprintf(buf, sizeof buf, "%lu:%02u", nt, nn)) {
3345 return strndup(buf, text_buffer_size);
3347 nn = nt % 60; // minutes past the hour
3348 nt /= 60; // total hours
3349 if (width >= snprintf(buf, sizeof buf, "%lu,%02u", nt, nn)) {
3350 return strndup(buf, text_buffer_size);
3352 nn = nt; // now also hours
3353 if (width >= snprintf(buf, sizeof buf, "%uh", nn)) {
3354 return strndup(buf, text_buffer_size);
3356 nn /= 24; // now days
3357 if (width >= snprintf(buf, sizeof buf, "%ud", nn)) {
3358 return strndup(buf, text_buffer_size);
3360 nn /= 7; // now weeks
3361 if (width >= snprintf(buf, sizeof buf, "%uw", nn)) {
3362 return strndup(buf, text_buffer_size);
3364 // well shoot, this outta' fit...
3365 return strndup("<inf>", text_buffer_size);
3368 //remove backspaced chars, example: "dog^H^H^Hcat" becomes "cat"
3369 //string has to end with \0 and it's length should fit in a int
3371 void remove_deleted_chars(char *string){
3373 while(string[i] != 0){
3374 if(string[i] == BACKSPACE){
3376 strcpy( &(string[i-1]), &(string[i+1]) );
3378 }else strcpy( &(string[i]), &(string[i+1]) ); //necessary for ^H's at the start of a string
3383 static inline void format_media_player_time(char *buf, const int size,
3386 int days, hours, minutes;
3388 days = seconds / (24 * 60 * 60);
3389 seconds %= (24 * 60 * 60);
3390 hours = seconds / (60 * 60);
3391 seconds %= (60 * 60);
3392 minutes = seconds / 60;
3396 snprintf(buf, size, "%i days %i:%02i:%02i", days,
3397 hours, minutes, seconds);
3398 } else if (hours > 0) {
3399 snprintf(buf, size, "%i:%02i:%02i", hours, minutes,
3402 snprintf(buf, size, "%i:%02i", minutes, seconds);
3406 static inline double get_barnum(char *buf)
3418 if (sscanf(buf, "%lf", &barnum) == 0) {
3419 ERR("reading exec value failed (perhaps it's not the "
3420 "correct format?)");
3423 if (barnum > 100.0 || barnum < 0.0) {
3424 ERR("your exec value is not between 0 and 100, "
3425 "therefore it will be ignored");
3431 static void generate_text_internal(char *p, int p_max_size,
3432 struct text_object root, struct information *cur)
3434 struct text_object *obj;
3436 /* for the OBJ_top* handler */
3437 struct process **needed = 0;
3440 char buff_in[p_max_size];
3442 iconv_converting = 0;
3447 while (obj && p_max_size > 0) {
3448 needed = 0; // reset for top stuff
3450 /* IFBLOCK jumping algorithm
3452 * This is easier as it looks like:
3453 * - each IF checks it's condition
3454 * - on FALSE: call DO_JUMP
3455 * - on TRUE: don't care
3456 * - each ELSE calls DO_JUMP unconditionally
3457 * - each ENDIF is silently being ignored
3460 * DO_JUMP overwrites the "obj" variable of the loop and sets it to the target
3461 * (i.e. the corresponding ELSE or ENDIF). After that, processing for the given
3462 * object can continue, free()ing stuff e.g., then the for-loop does the rest: as
3463 * regularly, "obj" is being updated to point to obj->next, so object parsing
3464 * continues right after the corresponding ELSE or ENDIF. This means that if we
3465 * find an ELSE, it's corresponding IF must not have jumped, so we need to jump
3466 * always. If we encounter an ENDIF, it's corresponding IF or ELSE has not
3467 * jumped, and there is nothing to do.
3471 obj = obj->data.ifblock.next; \
3474 #define OBJ(a) break; case OBJ_##a:
3476 switch (obj->type) {
3478 ERR("not implemented obj type %d", obj->type);
3481 temp_print(p, p_max_size, get_acpi_temperature(obj->data.i), TEMP_CELSIUS);
3483 #endif /* !__OpenBSD__ */
3486 obj->a = get_freq(p, p_max_size, "%.0f", 1,
3487 obj->data.cpu_index);
3493 obj->a = get_freq(p, p_max_size, "%'.2f", 1000,
3494 obj->data.cpu_index);
3496 /* OpenBSD has no such flag (SUSv2) */
3497 obj->a = get_freq(p, p_max_size, "%.2f", 1000,
3498 obj->data.cpu_index);
3502 #if defined(__linux__)
3505 obj->a = get_voltage(p, p_max_size, "%.0f", 1,
3506 obj->data.cpu_index);
3511 obj->a = get_voltage(p, p_max_size, "%'.3f", 1000,
3512 obj->data.cpu_index);
3517 OBJ(wireless_essid) {
3518 snprintf(p, p_max_size, "%s", obj->data.net->essid);
3520 OBJ(wireless_mode) {
3521 snprintf(p, p_max_size, "%s", obj->data.net->mode);
3523 OBJ(wireless_bitrate) {
3524 snprintf(p, p_max_size, "%s", obj->data.net->bitrate);
3527 snprintf(p, p_max_size, "%s", obj->data.net->ap);
3529 OBJ(wireless_link_qual) {
3530 spaced_print(p, p_max_size, "%d", 4,
3531 obj->data.net->link_qual);
3533 OBJ(wireless_link_qual_max) {
3534 spaced_print(p, p_max_size, "%d", 4,
3535 obj->data.net->link_qual_max);
3537 OBJ(wireless_link_qual_perc) {
3538 if (obj->data.net->link_qual_max > 0) {
3539 spaced_print(p, p_max_size, "%.0f", 5,
3540 (double) obj->data.net->link_qual /
3541 obj->data.net->link_qual_max * 100);
3543 spaced_print(p, p_max_size, "unk", 5);
3546 OBJ(wireless_link_bar) {
3547 new_bar(p, obj->a, obj->b, ((double) obj->data.net->link_qual /
3548 obj->data.net->link_qual_max) * 255.0);
3550 #endif /* HAVE_IWLIB */
3552 #endif /* __linux__ */
3556 get_adt746x_cpu(p, p_max_size);
3559 get_adt746x_fan(p, p_max_size);
3562 get_acpi_fan(p, p_max_size);
3564 OBJ(acpiacadapter) {
3565 get_acpi_ac_adapter(p, p_max_size);
3568 get_battery_stuff(p, p_max_size, obj->data.s, BATTERY_STATUS);
3571 get_battery_stuff(p, p_max_size, obj->data.s, BATTERY_TIME);
3573 OBJ(battery_percent) {
3574 percent_print(p, p_max_size, get_battery_perct(obj->data.s));
3578 new_bar(p, obj->a, obj->b, get_battery_perct_bar(obj->data.s));
3581 OBJ(battery_short) {
3582 get_battery_short_status(p, p_max_size, obj->data.s);
3584 #endif /* __OpenBSD__ */
3587 human_readable(cur->buffers * 1024, p, 255);
3590 human_readable(cur->cached * 1024, p, 255);
3593 if (obj->data.cpu_index > info.cpu_count) {
3594 ERR("obj->data.cpu_index %i info.cpu_count %i",
3595 obj->data.cpu_index, info.cpu_count);
3596 CRIT_ERR("attempting to use more CPUs than you have!");
3598 percent_print(p, p_max_size,
3599 round_to_int(cur->cpu_usage[obj->data.cpu_index] * 100.0));
3603 new_gauge(p, obj->a, obj->b,
3604 round_to_int(cur->cpu_usage[obj->data.cpu_index] * 255.0));
3606 new_bar(p, obj->a, obj->b,
3607 round_to_int(cur->cpu_usage[obj->data.cpu_index] * 255.0));
3610 new_graph(p, obj->a, obj->b, obj->c, obj->d,
3611 round_to_int(cur->cpu_usage[obj->data.cpu_index] * 100),
3612 100, 1, obj->char_a, obj->char_b);
3615 new_graph(p, obj->a, obj->b, obj->c, obj->d, cur->loadavg[0],
3616 obj->e, 1, obj->char_a, obj->char_b);
3619 new_fg(p, obj->data.l);
3652 OBJ(conky_version) {
3653 snprintf(p, p_max_size, "%s", VERSION);
3655 OBJ(conky_build_date) {
3656 snprintf(p, p_max_size, "%s", BUILD_DATE);
3658 OBJ(conky_build_arch) {
3659 snprintf(p, p_max_size, "%s", BUILD_ARCH);
3661 #if defined(__linux__)
3663 snprintf(p, p_max_size, "%s",
3664 get_disk_protect_queue(obj->data.s));
3667 snprintf(p, p_max_size, "%s", i8k.version);
3670 snprintf(p, p_max_size, "%s", i8k.bios);
3673 snprintf(p, p_max_size, "%s", i8k.serial);
3678 sscanf(i8k.cpu_temp, "%d", &cpu_temp);
3679 temp_print(p, p_max_size, (double)cpu_temp, TEMP_CELSIUS);
3681 OBJ(i8k_left_fan_status) {
3682 int left_fan_status;
3684 sscanf(i8k.left_fan_status, "%d", &left_fan_status);
3685 if (left_fan_status == 0) {
3686 snprintf(p, p_max_size, "off");
3688 if (left_fan_status == 1) {
3689 snprintf(p, p_max_size, "low");
3691 if (left_fan_status == 2) {
3692 snprintf(p, p_max_size, "high");
3695 OBJ(i8k_right_fan_status) {
3696 int right_fan_status;
3698 sscanf(i8k.right_fan_status, "%d", &right_fan_status);
3699 if (right_fan_status == 0) {
3700 snprintf(p, p_max_size, "off");
3702 if (right_fan_status == 1) {
3703 snprintf(p, p_max_size, "low");
3705 if (right_fan_status == 2) {
3706 snprintf(p, p_max_size, "high");
3709 OBJ(i8k_left_fan_rpm) {
3710 snprintf(p, p_max_size, "%s", i8k.left_fan_rpm);
3712 OBJ(i8k_right_fan_rpm) {
3713 snprintf(p, p_max_size, "%s", i8k.right_fan_rpm);
3715 OBJ(i8k_ac_status) {
3718 sscanf(i8k.ac_status, "%d", &ac_status);
3719 if (ac_status == -1) {
3720 snprintf(p, p_max_size, "disabled (read i8k docs)");
3722 if (ac_status == 0) {
3723 snprintf(p, p_max_size, "off");
3725 if (ac_status == 1) {
3726 snprintf(p, p_max_size, "on");
3729 OBJ(i8k_buttons_status) {
3730 snprintf(p, p_max_size, "%s", i8k.buttons_status);
3734 get_ibm_acpi_fan(p, p_max_size);
3737 get_ibm_acpi_temps();
3738 temp_print(p, p_max_size,
3739 ibm_acpi.temps[obj->data.sensor], TEMP_CELSIUS);
3742 get_ibm_acpi_volume(p, p_max_size);
3744 OBJ(ibm_brightness) {
3745 get_ibm_acpi_brightness(p, p_max_size);
3748 /* information from sony_laptop kernel module
3749 * /sys/devices/platform/sony-laptop */
3750 OBJ(sony_fanspeed) {
3751 get_sony_fanspeed(p, p_max_size);
3754 if (!cur->gw_info.count) {
3759 snprintf(p, p_max_size, "%s", cur->gw_info.iface);
3762 snprintf(p, p_max_size, "%s", cur->gw_info.ip);
3765 snprintf(p, p_max_size, "%d", get_laptop_mode());
3768 get_powerbook_batt_info(p, p_max_size, obj->data.i);
3770 #endif /* __linux__ */
3771 #if (defined(__FreeBSD__) || defined(__linux__))
3773 if ((obj->data.ifblock.s)
3774 && (!interface_up(obj->data.ifblock.s))) {
3780 OBJ(obsd_sensors_temp) {
3781 obsd_sensors.device = sensor_device;
3782 update_obsd_sensors();
3783 temp_print(p, p_max_size,
3784 obsd_sensors.temp[obsd_sensors.device][obj->data.sensor],
3787 OBJ(obsd_sensors_fan) {
3788 obsd_sensors.device = sensor_device;
3789 update_obsd_sensors();
3790 snprintf(p, p_max_size, "%d",
3791 obsd_sensors.fan[obsd_sensors.device][obj->data.sensor]);
3793 OBJ(obsd_sensors_volt) {
3794 obsd_sensors.device = sensor_device;
3795 update_obsd_sensors();
3796 snprintf(p, p_max_size, "%.2f",
3797 obsd_sensors.volt[obsd_sensors.device][obj->data.sensor]);
3800 get_obsd_vendor(p, p_max_size);
3803 get_obsd_product(p, p_max_size);
3805 #endif /* __OpenBSD__ */
3808 new_font(p, obj->data.s);
3811 /* TODO: move this correction from kB to kB/s elsewhere
3812 * (or get rid of it??) */
3814 human_readable((obj->data.diskio->current / update_interval) * 1024LL,
3818 human_readable((obj->data.diskio->current_write / update_interval) * 1024LL,
3822 human_readable((obj->data.diskio->current_read / update_interval) * 1024LL,
3827 new_graph(p, obj->a, obj->b, obj->c, obj->d,
3828 obj->data.diskio->current, obj->e, 1, obj->char_a, obj->char_b);
3830 OBJ(diskiograph_read) {
3831 new_graph(p, obj->a, obj->b, obj->c, obj->d,
3832 obj->data.diskio->current_read, obj->e, 1, obj->char_a, obj->char_b);
3834 OBJ(diskiograph_write) {
3835 new_graph(p, obj->a, obj->b, obj->c, obj->d,
3836 obj->data.diskio->current_write, obj->e, 1, obj->char_a, obj->char_b);
3840 human_readable(obj->data.net->recv_speed, p, 255);
3843 spaced_print(p, p_max_size, "%.1f", 8,
3844 obj->data.net->recv_speed / 1024.0);
3847 OBJ(downspeedgraph) {
3848 new_graph(p, obj->a, obj->b, obj->c, obj->d,
3849 obj->data.net->recv_speed / 1024.0, obj->e, 1, obj->char_a, obj->char_b);
3853 /* Since we see you, you're if has not jumped.
3854 * Do Ninja jump here: without leaving traces.
3855 * This is to prevent us from stale jumped flags.
3857 obj = obj->data.ifblock.next;
3861 /* harmless object, just ignore */
3865 if ((obj->data.net->addr.sa_data[2] & 255) == 0
3866 && (obj->data.net->addr.sa_data[3] & 255) == 0
3867 && (obj->data.net->addr.sa_data[4] & 255) == 0
3868 && (obj->data.net->addr.sa_data[5] & 255) == 0) {
3869 snprintf(p, p_max_size, "No Address");
3871 snprintf(p, p_max_size, "%u.%u.%u.%u",
3872 obj->data.net->addr.sa_data[2] & 255,
3873 obj->data.net->addr.sa_data[3] & 255,
3874 obj->data.net->addr.sa_data[4] & 255,
3875 obj->data.net->addr.sa_data[5] & 255);
3878 #if defined(__linux__)
3880 if(NULL != obj->data.net->addrs && strlen(obj->data.net->addrs) > 2)
3882 obj->data.net->addrs[strlen(obj->data.net->addrs) - 2] = 0; /* remove ", " from end of string */
3883 strcpy(p, obj->data.net->addrs);
3886 strcpy(p, "0.0.0.0");
3888 #endif /* __linux__ */
3889 #if defined(IMLIB2) && defined(X11)
3891 /* doesn't actually draw anything, just queues it omp. the
3892 * image will get drawn after the X event loop */
3893 cimlib_add_image(obj->data.s);
3897 struct information *tmp_info;
3898 struct text_object subroot, subroot2;
3900 tmp_info = malloc(sizeof(struct information));
3901 memcpy(tmp_info, cur, sizeof(struct information));
3902 parse_conky_vars(&subroot, obj->data.s, p, tmp_info);
3903 DBGP("evaluated '%s' to '%s'", obj->data.s, p);
3904 parse_conky_vars(&subroot2, p, p, tmp_info);
3906 free_text_objects(&subroot, 1);
3907 free_text_objects(&subroot2, 1);
3911 read_exec(obj->data.s, p, text_buffer_size);
3912 remove_deleted_chars(p);
3915 struct information *tmp_info;
3916 struct text_object subroot;
3918 read_exec(obj->data.s, p, text_buffer_size);
3920 tmp_info = malloc(sizeof(struct information));
3921 memcpy(tmp_info, cur, sizeof(struct information));
3922 parse_conky_vars(&subroot, p, p, tmp_info);
3924 free_text_objects(&subroot, 1);
3931 read_exec(obj->data.s, p, text_buffer_size);
3932 barnum = get_barnum(p); /*using the same function*/
3934 if (barnum >= 0.0) {
3936 new_gauge(p, obj->a, obj->b, round_to_int(barnum * 255.0));
3944 read_exec(obj->data.s, p, text_buffer_size);
3945 barnum = get_barnum(p);
3947 if (barnum >= 0.0) {
3949 if(output_methods & TO_X) {
3951 new_bar(p, obj->a, obj->b, round_to_int(barnum * 255.0));
3954 if(!obj->a) obj->a = DEFAULT_BAR_WIDTH_NO_X;
3955 barnum = round_to_int( ( barnum * obj->a ) / 100);
3957 #pragma omp parallel for
3958 #endif /* HAVE_OPENMP */
3959 for(i=0; i<(int)barnum; i++) {
3962 /* gcc seems to think i is not initialized properly :/ */
3965 #pragma omp parallel for
3966 #endif /* HAVE_OPENMP */
3967 for(i = j/* cheats */; i < obj->a; i++) {
3978 char showaslog = FALSE;
3979 char tempgrad = FALSE;
3981 char *cmd = obj->data.s;
3983 if (strncasecmp(obj->data.execi.cmd, LOGGRAPH" ", strlen(LOGGRAPH" ")) == EQUAL) {
3985 cmd = cmd + strlen(LOGGRAPH" ") * sizeof(char);
3986 } else if(strncasecmp(obj->data.s, NORMGRAPH" ", strlen(NORMGRAPH" ")) == EQUAL) {
3987 cmd = cmd + strlen(NORMGRAPH" ") * sizeof(char);
3989 if (strstr(cmd, " "TEMPGRAD) && strlen(cmd) > strlen(" "TEMPGRAD)) {
3991 cmd += strlen(" "TEMPGRAD);
3993 read_exec(cmd, p, text_buffer_size);
3994 barnum = get_barnum(p);
3996 if (barnum >= 0.0) {
3997 new_graph(p, obj->a, obj->b, obj->c, obj->d, round_to_int(barnum),
3998 100, 1, showaslog, tempgrad);
4002 if (current_update_time - obj->data.execi.last_update
4003 >= obj->data.execi.interval) {
4006 read_exec(obj->data.execi.cmd, p, text_buffer_size);
4007 barnum = get_barnum(p);
4009 if (barnum >= 0.0) {
4010 obj->f = 255 * barnum / 100.0;
4012 obj->data.execi.last_update = current_update_time;
4014 new_bar(p, obj->a, obj->b, round_to_int(obj->f));
4017 if (current_update_time - obj->data.execi.last_update
4018 >= obj->data.execi.interval) {
4020 char showaslog = FALSE;
4021 char tempgrad = FALSE;
4022 char *cmd = obj->data.execi.cmd;
4024 if (strncasecmp(obj->data.execi.cmd, LOGGRAPH" ", strlen(LOGGRAPH" ")) == EQUAL) {
4026 cmd = cmd + strlen(LOGGRAPH" ") * sizeof(char);
4027 } else if(strncasecmp(obj->data.s, NORMGRAPH" ", strlen(NORMGRAPH" ")) == EQUAL) {
4028 cmd = cmd + strlen(NORMGRAPH" ") * sizeof(char);
4030 if (strstr(cmd, " "TEMPGRAD) && strlen(cmd) > strlen(" "TEMPGRAD)) {
4032 cmd += strlen(" "TEMPGRAD);
4034 obj->char_a = showaslog;
4035 obj->char_b = tempgrad;
4036 read_exec(cmd, p, text_buffer_size);
4037 barnum = get_barnum(p);
4039 if (barnum >= 0.0) {
4042 obj->data.execi.last_update = current_update_time;
4044 new_graph(p, obj->a, obj->b, obj->c, obj->d, (int) (obj->f), 100, 1, obj->char_a, obj->char_b);
4047 if (current_update_time - obj->data.execi.last_update
4048 >= obj->data.execi.interval) {
4051 read_exec(obj->data.execi.cmd, p, text_buffer_size);
4052 barnum = get_barnum(p);
4054 if (barnum >= 0.0) {
4055 obj->f = 255 * barnum / 100.0;
4057 obj->data.execi.last_update = current_update_time;
4059 new_gauge(p, obj->a, obj->b, round_to_int(obj->f));
4063 if (current_update_time - obj->data.execi.last_update
4064 >= obj->data.execi.interval
4065 && obj->data.execi.interval != 0) {
4066 read_exec(obj->data.execi.cmd, obj->data.execi.buffer,
4068 obj->data.execi.last_update = current_update_time;
4070 snprintf(p, text_buffer_size, "%s", obj->data.execi.buffer);
4073 struct text_object subroot;
4074 struct information *tmp_info =
4075 malloc(sizeof(struct information));
4076 memcpy(tmp_info, cur, sizeof(struct information));
4078 if (current_update_time - obj->data.execi.last_update
4079 < obj->data.execi.interval
4080 || obj->data.execi.interval == 0) {
4081 parse_conky_vars(&subroot, obj->data.execi.buffer, p, tmp_info);
4083 char *output = obj->data.execi.buffer;
4084 FILE *fp = popen(obj->data.execi.cmd, "r");
4085 int length = fread(output, 1, text_buffer_size, fp);
4089 output[length] = '\0';
4090 if (length > 0 && output[length - 1] == '\n') {
4091 output[length - 1] = '\0';
4094 parse_conky_vars(&subroot, obj->data.execi.buffer, p, tmp_info);
4095 obj->data.execi.last_update = current_update_time;
4097 free_text_objects(&subroot, 1);
4101 if (!obj->data.texeci.p_timed_thread) {
4102 obj->data.texeci.p_timed_thread =
4103 timed_thread_create(&threaded_exec,
4104 (void *) obj, obj->data.texeci.interval * 1000000);
4105 if (!obj->data.texeci.p_timed_thread) {
4106 ERR("Error creating texeci timed thread");
4108 timed_thread_register(obj->data.texeci.p_timed_thread,
4109 &obj->data.texeci.p_timed_thread);
4110 if (timed_thread_run(obj->data.texeci.p_timed_thread)) {
4111 ERR("Error running texeci timed thread");
4114 timed_thread_lock(obj->data.texeci.p_timed_thread);
4115 snprintf(p, text_buffer_size, "%s", obj->data.texeci.buffer);
4116 timed_thread_unlock(obj->data.texeci.p_timed_thread);
4119 #endif /* HAVE_POPEN */
4121 struct mail_s *mail = ensure_mail_thread(obj, imap_thread, "imap");
4123 if (mail && mail->p_timed_thread) {
4124 timed_thread_lock(mail->p_timed_thread);
4125 snprintf(p, p_max_size, "%lu", mail->unseen);
4126 timed_thread_unlock(mail->p_timed_thread);
4129 OBJ(imap_messages) {
4130 struct mail_s *mail = ensure_mail_thread(obj, imap_thread, "imap");
4132 if (mail && mail->p_timed_thread) {
4133 timed_thread_lock(mail->p_timed_thread);
4134 snprintf(p, p_max_size, "%lu", mail->messages);
4135 timed_thread_unlock(mail->p_timed_thread);
4139 struct mail_s *mail = ensure_mail_thread(obj, pop3_thread, "pop3");
4141 if (mail && mail->p_timed_thread) {
4142 timed_thread_lock(mail->p_timed_thread);
4143 snprintf(p, p_max_size, "%lu", mail->unseen);
4144 timed_thread_unlock(mail->p_timed_thread);
4148 struct mail_s *mail = ensure_mail_thread(obj, pop3_thread, "pop3");
4150 if (mail && mail->p_timed_thread) {
4151 timed_thread_lock(mail->p_timed_thread);
4152 snprintf(p, p_max_size, "%.1f",
4153 mail->used / 1024.0 / 1024.0);
4154 timed_thread_unlock(mail->p_timed_thread);
4159 if (obj->data.fs != NULL) {
4160 if (obj->data.fs->size == 0) {
4161 new_bar(p, obj->data.fsbar.w, obj->data.fsbar.h, 255);
4163 new_bar(p, obj->data.fsbar.w, obj->data.fsbar.h,
4164 (int) (255 - obj->data.fsbar.fs->avail * 255 /
4165 obj->data.fs->size));
4171 if (obj->data.fs != NULL) {
4172 human_readable( (obj->data.fs->free ? obj->data.fs->free :
4173 obj->data.fs->avail), p, 255);
4177 if (obj->data.fs != NULL) {
4180 if (obj->data.fs->size) {
4181 val = (obj->data.fs->free ? obj->data.fs->free :
4182 obj->data.fs->avail) * 100 /
4186 percent_print(p, p_max_size, val);
4190 if (obj->data.fs != NULL) {
4191 human_readable(obj->data.fs->size, p, 255);
4195 if (obj->data.fs != NULL)
4196 snprintf(p, p_max_size, "%s", obj->data.fs->type);
4199 if (obj->data.fs != NULL) {
4200 human_readable(obj->data.fs->size - (obj->data.fs->free
4201 ? obj->data.fs->free : obj->data.fs->avail), p, 255);
4206 if (obj->data.fs != NULL) {
4207 if (obj->data.fs->size == 0) {
4208 new_bar(p, obj->data.fsbar.w, obj->data.fsbar.h, 255);
4210 new_bar(p, obj->data.fsbar.w, obj->data.fsbar.h,
4211 (int) (obj->data.fsbar.fs->avail * 255 /
4212 obj->data.fs->size));
4218 if (obj->data.fs != NULL) {
4221 if (obj->data.fs->size) {
4222 val = (obj->data.fs->free ? obj->data.fs->free :
4223 obj->data.fs->avail) * 100 /
4227 percent_print(p, p_max_size, 100 - val);
4231 float *v = info.loadavg;
4233 if (obj->data.loadavg[2]) {
4234 snprintf(p, p_max_size, "%.2f %.2f %.2f",
4235 v[obj->data.loadavg[0] - 1],
4236 v[obj->data.loadavg[1] - 1],
4237 v[obj->data.loadavg[2] - 1]);
4238 } else if (obj->data.loadavg[1]) {
4239 snprintf(p, p_max_size, "%.2f %.2f",
4240 v[obj->data.loadavg[0] - 1],
4241 v[obj->data.loadavg[1] - 1]);
4242 } else if (obj->data.loadavg[0]) {
4243 snprintf(p, p_max_size, "%.2f",
4244 v[obj->data.loadavg[0] - 1]);
4248 new_goto(p, obj->data.i);
4251 new_tab(p, obj->data.pair.a, obj->data.pair.b);
4255 new_hr(p, obj->data.i);
4259 if (cur->nameserver_info.nscount > obj->data.i)
4260 snprintf(p, p_max_size, "%s",
4261 cur->nameserver_info.ns_list[obj->data.i]);
4265 char *skill = eve(obj->data.eve.userid, obj->data.eve.apikey, obj->data.eve.charid);
4266 snprintf(p, p_max_size, "%s", skill);
4271 PRSS *data = get_rss_info(obj->data.rss.uri,
4272 obj->data.rss.delay);
4276 snprintf(p, p_max_size, "prss: Error reading RSS data\n");
4278 if (strcmp(obj->data.rss.action, "feed_title") == EQUAL) {
4280 // remove trailing new line if one exists
4281 if (str[strlen(str) - 1] == '\n') {
4282 str[strlen(str) - 1] = 0;
4284 snprintf(p, p_max_size, "%s", str);
4285 } else if (strcmp(obj->data.rss.action, "item_title") == EQUAL) {
4286 if (obj->data.rss.act_par < data->item_count) {
4287 str = data->items[obj->data.rss.act_par].title;
4288 // remove trailing new line if one exists
4289 if (str[strlen(str) - 1] == '\n') {
4290 str[strlen(str) - 1] = 0;
4292 snprintf(p, p_max_size, "%s", str);
4294 } else if (strcmp(obj->data.rss.action, "item_desc") == EQUAL) {
4295 if (obj->data.rss.act_par < data->item_count) {
4297 data->items[obj->data.rss.act_par].description;
4298 // remove trailing new line if one exists
4299 if (str[strlen(str) - 1] == '\n') {
4300 str[strlen(str) - 1] = 0;
4302 snprintf(p, p_max_size, "%s", str);
4304 } else if (strcmp(obj->data.rss.action, "item_titles") == EQUAL) {
4305 if (data->item_count > 0) {
4308 //'tmpspaces' is a string with spaces too be placed in front of each title
4309 char *tmpspaces = malloc(obj->data.rss.nrspaces + 1);
4310 memset(tmpspaces, ' ', obj->data.rss.nrspaces);
4311 tmpspaces[obj->data.rss.nrspaces]=0;
4315 if (obj->data.rss.act_par > data->item_count) {
4316 show = data->item_count;
4318 show = obj->data.rss.act_par;
4320 for (itmp = 0; itmp < show; itmp++) {
4321 PRSS_Item *item = &data->items[itmp];
4325 // don't add new line before first item
4327 strncat(p, "\n", p_max_size);
4329 /* remove trailing new line if one exists,
4330 * we have our own */
4331 if (str[strlen(str) - 1] == '\n') {
4332 str[strlen(str) - 1] = 0;
4334 strncat(p, tmpspaces, p_max_size);
4335 strncat(p, str, p_max_size);
4346 char *str = llua_getstring(obj->data.s);
4348 snprintf(p, p_max_size, "%s", str);
4353 char *str = llua_getstring(obj->data.s);
4355 struct information *tmp_info;
4356 struct text_object subroot;
4358 tmp_info = malloc(sizeof(struct information));
4359 memcpy(tmp_info, cur, sizeof(struct information));
4360 parse_conky_vars(&subroot, str, p, tmp_info);
4362 free_text_objects(&subroot, 1);
4367 OBJ(lua_read_parse) {
4368 struct information *tmp_info;
4369 struct text_object subroot, subroot2;
4372 sscanf(obj->data.s, "%64s", func);
4373 text = obj->data.s + strlen(func) + 1;
4375 tmp_info = malloc(sizeof(struct information));
4376 memcpy(tmp_info, cur, sizeof(struct information));
4377 parse_conky_vars(&subroot, text, p, tmp_info);
4378 DBGP("evaluated '%s' to '%s'", text, p);
4380 str = llua_getstring_read(func, p);
4382 parse_conky_vars(&subroot2, str, p, tmp_info);
4383 DBGP("evaluated '%s' to '%s'", str, p);
4386 free_text_objects(&subroot2, 1);
4388 free_text_objects(&subroot, 1);
4394 if (llua_getinteger(obj->data.s, &per)) {
4395 new_bar(p, obj->a, obj->b, (per/100.0 * 255));
4400 if (llua_getinteger(obj->data.s, &per)) {
4401 new_graph(p, obj->a, obj->b, obj->c, obj->d,
4402 (per/100.0 * 255), 100, 1, obj->char_a, obj->char_b);
4407 if (llua_getinteger(obj->data.s, &per)) {
4408 new_gauge(p, obj->a, obj->b, (per/100.0 * 255));
4412 #endif /* HAVE_LUA */
4417 if (obj->data.hddtemp.update_time < current_update_time - 30) {
4418 if (obj->data.hddtemp.temp)
4419 free(obj->data.hddtemp.temp);
4420 obj->data.hddtemp.temp = get_hddtemp_info(obj->data.hddtemp.dev,
4421 obj->data.hddtemp.addr, obj->data.hddtemp.port);
4422 obj->data.hddtemp.update_time = current_update_time;
4424 if (!obj->data.hddtemp.temp) {
4425 snprintf(p, p_max_size, "N/A");
4427 val = strtol(obj->data.hddtemp.temp + 1, &endptr, 10);
4428 unit = obj->data.hddtemp.temp[0];
4430 if (*endptr != '\0')
4431 snprintf(p, p_max_size, "N/A");
4432 else if (unit == 'C')
4433 temp_print(p, p_max_size, (double)val, TEMP_CELSIUS);
4434 else if (unit == 'F')
4435 temp_print(p, p_max_size, (double)val, TEMP_FAHRENHEIT);
4437 snprintf(p, p_max_size, "N/A");
4442 new_offset(p, obj->data.i);
4445 new_voffset(p, obj->data.i);
4451 r = get_sysfs_info(&obj->data.sysfs.fd, obj->data.sysfs.arg,
4452 obj->data.sysfs.devtype, obj->data.sysfs.type);
4454 r = r * obj->data.sysfs.factor + obj->data.sysfs.offset;
4456 if (!strncmp(obj->data.sysfs.type, "temp", 4)) {
4457 temp_print(p, p_max_size, r, TEMP_CELSIUS);
4458 } else if (r >= 100.0 || r == 0) {
4459 snprintf(p, p_max_size, "%d", (int) r);
4461 snprintf(p, p_max_size, "%.1f", r);
4467 r = get_sysfs_info(&obj->data.sysfs.fd, obj->data.sysfs.arg,
4468 obj->data.sysfs.devtype, obj->data.sysfs.type);
4470 r = r * obj->data.sysfs.factor + obj->data.sysfs.offset;
4472 if (!strncmp(obj->data.sysfs.type, "temp", 4)) {
4473 temp_print(p, p_max_size, r, TEMP_CELSIUS);
4474 } else if (r >= 100.0 || r == 0) {
4475 snprintf(p, p_max_size, "%d", (int) r);
4477 snprintf(p, p_max_size, "%.1f", r);
4483 r = get_sysfs_info(&obj->data.sysfs.fd, obj->data.sysfs.arg,
4484 obj->data.sysfs.devtype, obj->data.sysfs.type);
4486 r = r * obj->data.sysfs.factor + obj->data.sysfs.offset;
4488 if (!strncmp(obj->data.sysfs.type, "temp", 4)) {
4489 temp_print(p, p_max_size, r, TEMP_CELSIUS);
4490 } else if (r >= 100.0 || r == 0) {
4491 snprintf(p, p_max_size, "%d", (int) r);
4493 snprintf(p, p_max_size, "%.1f", r);
4496 #endif /* __linux__ */
4498 new_alignr(p, obj->data.i);
4501 new_alignc(p, obj->data.i);
4504 char buf[max_user_text];
4505 struct information *tmp_info =
4506 malloc(sizeof(struct information));
4507 memcpy(tmp_info, cur, sizeof(struct information));
4508 generate_text_internal(buf, max_user_text,
4509 *obj->sub, tmp_info);
4511 if (strlen(buf) != 0) {
4517 char expression[max_user_text];
4519 struct information *tmp_info;
4521 tmp_info = malloc(sizeof(struct information));
4522 memcpy(tmp_info, cur, sizeof(struct information));
4523 generate_text_internal(expression, max_user_text,
4524 *obj->sub, tmp_info);
4525 DBGP("parsed arg into '%s'", expression);
4527 val = compare(expression);
4529 ERR("compare failed for expression '%s'",
4537 if (obj->data.ifblock.str
4538 && !check_contains(obj->data.ifblock.s,
4539 obj->data.ifblock.str)) {
4541 } else if (obj->data.ifblock.s
4542 && access(obj->data.ifblock.s, F_OK)) {
4547 if ((obj->data.ifblock.s)
4548 && (!check_mount(obj->data.ifblock.s))) {
4553 if ((obj->data.ifblock.s) && system(obj->data.ifblock.s)) {
4557 #if defined(__linux__)
4559 snprintf(p, p_max_size, "%s", get_ioscheduler(obj->data.s));
4563 snprintf(p, p_max_size, "%s", cur->uname_s.release);
4566 snprintf(p, p_max_size, "%s", cur->uname_s.machine);
4571 human_readable(cur->mem * 1024, p, 255);
4574 human_readable(cur->memeasyfree * 1024, p, 255);
4577 human_readable(cur->memfree * 1024, p, 255);
4580 human_readable(cur->memmax * 1024, p, 255);
4584 percent_print(p, p_max_size, cur->mem * 100 / cur->memmax);
4588 new_gauge(p, obj->data.pair.a, obj->data.pair.b,
4589 cur->memmax ? (cur->mem * 255) / (cur->memmax) : 0);
4592 new_bar(p, obj->data.pair.a, obj->data.pair.b,
4593 cur->memmax ? (cur->mem * 255) / (cur->memmax) : 0);
4596 new_graph(p, obj->a, obj->b, obj->c, obj->d,
4597 cur->memmax ? (cur->mem * 100.0) / (cur->memmax) : 0.0,
4598 100, 1, obj->char_a, obj->char_b);
4603 percent_print(p, p_max_size, mixer_get_avg(obj->data.l));
4606 percent_print(p, p_max_size, mixer_get_left(obj->data.l));
4609 percent_print(p, p_max_size, mixer_get_right(obj->data.l));
4613 new_bar(p, obj->data.mixerbar.w, obj->data.mixerbar.h,
4614 mixer_to_255(obj->data.mixerbar.l,mixer_get_avg(obj->data.mixerbar.l)));
4617 new_bar(p, obj->data.mixerbar.w, obj->data.mixerbar.h,
4618 mixer_to_255(obj->data.mixerbar.l,mixer_get_left(obj->data.mixerbar.l)));
4621 new_bar(p, obj->data.mixerbar.w, obj->data.mixerbar.h,
4622 mixer_to_255(obj->data.mixerbar.l,mixer_get_right(obj->data.mixerbar.l)));
4625 OBJ(if_mixer_mute) {
4626 if (!mixer_is_mute(obj->data.ifblock.i)) {
4632 snprintf(p, p_max_size, "%d", cur->x11.monitor.current);
4634 OBJ(monitor_number) {
4635 snprintf(p, p_max_size, "%d", cur->x11.monitor.number);
4641 update_mail_count(&obj->data.local_mail);
4642 snprintf(p, p_max_size, "%d", obj->data.local_mail.mail_count);
4645 update_mail_count(&obj->data.local_mail);
4646 snprintf(p, p_max_size, "%d",
4647 obj->data.local_mail.new_mail_count);
4650 update_mail_count(&obj->data.local_mail);
4651 snprintf(p, p_max_size, "%d",
4652 obj->data.local_mail.seen_mail_count);
4655 update_mail_count(&obj->data.local_mail);
4656 snprintf(p, p_max_size, "%d",
4657 obj->data.local_mail.unseen_mail_count);
4659 OBJ(flagged_mails) {
4660 update_mail_count(&obj->data.local_mail);
4661 snprintf(p, p_max_size, "%d",
4662 obj->data.local_mail.flagged_mail_count);
4664 OBJ(unflagged_mails) {
4665 update_mail_count(&obj->data.local_mail);
4666 snprintf(p, p_max_size, "%d",
4667 obj->data.local_mail.unflagged_mail_count);
4669 OBJ(forwarded_mails) {
4670 update_mail_count(&obj->data.local_mail);
4671 snprintf(p, p_max_size, "%d",
4672 obj->data.local_mail.forwarded_mail_count);
4674 OBJ(unforwarded_mails) {
4675 update_mail_count(&obj->data.local_mail);
4676 snprintf(p, p_max_size, "%d",
4677 obj->data.local_mail.unforwarded_mail_count);
4679 OBJ(replied_mails) {
4680 update_mail_count(&obj->data.local_mail);
4681 snprintf(p, p_max_size, "%d",
4682 obj->data.local_mail.replied_mail_count);
4684 OBJ(unreplied_mails) {
4685 update_mail_count(&obj->data.local_mail);
4686 snprintf(p, p_max_size, "%d",
4687 obj->data.local_mail.unreplied_mail_count);
4690 update_mail_count(&obj->data.local_mail);
4691 snprintf(p, p_max_size, "%d",
4692 obj->data.local_mail.draft_mail_count);
4694 OBJ(trashed_mails) {
4695 update_mail_count(&obj->data.local_mail);
4696 snprintf(p, p_max_size, "%d",
4697 obj->data.local_mail.trashed_mail_count);
4700 mbox_scan(obj->data.mboxscan.args, obj->data.mboxscan.output,
4702 snprintf(p, p_max_size, "%s", obj->data.mboxscan.output);
4705 snprintf(p, p_max_size, "%s", cur->uname_s.nodename);
4708 new_outline(p, obj->data.l);
4711 spaced_print(p, p_max_size, "%hu", 4, cur->procs);
4713 OBJ(running_processes) {
4714 spaced_print(p, p_max_size, "%hu", 4, cur->run_procs);
4717 snprintf(p, p_max_size, "%s", obj->data.s);
4721 new_bg(p, obj->data.l);
4724 new_stippled_hr(p, obj->data.pair.a, obj->data.pair.b);
4728 human_readable(cur->swap * 1024, p, 255);
4731 human_readable(cur->swapmax * 1024, p, 255);
4734 if (cur->swapmax == 0) {
4735 strncpy(p, "No swap", p_max_size);
4737 percent_print(p, p_max_size, cur->swap * 100 / cur->swapmax);
4742 new_bar(p, obj->data.pair.a, obj->data.pair.b,
4743 cur->swapmax ? (cur->swap * 255) / (cur->swapmax) : 0);
4747 snprintf(p, p_max_size, "%s", cur->uname_s.sysname);
4750 time_t t = time(NULL);
4751 struct tm *tm = localtime(&t);
4753 setlocale(LC_TIME, "");
4754 strftime(p, p_max_size, obj->data.s, tm);
4757 time_t t = time(NULL);
4758 struct tm *tm = gmtime(&t);
4760 strftime(p, p_max_size, obj->data.s, tm);
4767 if (obj->data.tztime.tz) {
4768 oldTZ = getenv("TZ");
4769 setenv("TZ", obj->data.tztime.tz, 1);
4775 setlocale(LC_TIME, "");
4776 strftime(p, p_max_size, obj->data.tztime.fmt, tm);
4778 setenv("TZ", oldTZ, 1);
4783 // Needless to free oldTZ since getenv gives ptr to static data
4786 human_readable(obj->data.net->recv, p, 255);
4789 human_readable(obj->data.net->trans, p, 255);
4792 snprintf(p, p_max_size, "%d", total_updates);
4795 if(total_updates % updatereset != obj->data.ifblock.i - 1) {
4800 human_readable(obj->data.net->trans_speed, p, 255);
4803 spaced_print(p, p_max_size, "%.1f", 8,
4804 obj->data.net->trans_speed / 1024.0);
4808 new_graph(p, obj->a, obj->b, obj->c, obj->d,
4809 obj->data.net->trans_speed / 1024.0, obj->e, 1, obj->char_a, obj->char_b);
4813 format_seconds_short(p, p_max_size, (int) cur->uptime);
4816 format_seconds(p, p_max_size, (int) cur->uptime);
4819 snprintf(p, p_max_size, "%s", cur->users.names);
4822 snprintf(p, p_max_size, "%s", cur->users.terms);
4825 snprintf(p, p_max_size, "%s", cur->users.times);
4828 snprintf(p, p_max_size, "%d", cur->users.number);
4830 #if (defined(__FreeBSD__) || defined(__FreeBSD_kernel__) \
4831 || defined(__OpenBSD__)) && (defined(i386) || defined(__i386__))
4835 msg = get_apm_adapter();
4836 snprintf(p, p_max_size, "%s", msg);
4839 OBJ(apm_battery_life) {
4842 msg = get_apm_battery_life();
4843 snprintf(p, p_max_size, "%s", msg);
4846 OBJ(apm_battery_time) {
4849 msg = get_apm_battery_time();
4850 snprintf(p, p_max_size, "%s", msg);
4853 #endif /* __FreeBSD__ __OpenBSD__ */
4856 #define mpd_printf(fmt, val) \
4857 snprintf(p, p_max_size, fmt, mpd_get_info()->val)
4858 #define mpd_sprintf(val) { \
4859 if (!obj->data.i || obj->data.i > p_max_size) \
4860 mpd_printf("%s", val); \
4862 snprintf(p, obj->data.i, "%s", mpd_get_info()->val); \
4867 mpd_sprintf(artist);
4871 mpd_printf("%s", random);
4873 mpd_printf("%s", repeat);
4881 mpd_printf("%d", volume);
4883 mpd_printf("%d", bitrate);
4885 mpd_printf("%s", status);
4887 format_media_player_time(p, p_max_size, mpd_get_info()->elapsed);
4890 format_media_player_time(p, p_max_size, mpd_get_info()->length);
4893 percent_print(p, p_max_size, (int)(mpd_get_info()->progress * 100));
4897 new_bar(p, obj->data.pair.a, obj->data.pair.b,
4898 (int) (mpd_get_info()->progress * 255.0f));
4902 struct mpd_s *mpd = mpd_get_info();
4903 int len = obj->data.i;
4904 if (len == 0 || len > p_max_size)
4907 memset(p, 0, p_max_size);
4908 if (mpd->artist && *mpd->artist &&
4909 mpd->title && *mpd->title) {
4910 snprintf(p, len, "%s - %s", mpd->artist,
4912 } else if (mpd->title && *mpd->title) {
4913 snprintf(p, len, "%s", mpd->title);
4914 } else if (mpd->artist && *mpd->artist) {
4915 snprintf(p, len, "%s", mpd->artist);
4916 } else if (mpd->file && *mpd->file) {
4917 snprintf(p, len, "%s", mpd->file);
4922 OBJ(if_mpd_playing) {
4923 if (!mpd_get_info()->is_playing) {
4936 #define MOC_PRINT(t, a) \
4937 snprintf(p, p_max_size, "%s", (moc.t ? moc.t : a))
4939 MOC_PRINT(state, "??");
4942 MOC_PRINT(file, "no file");
4945 MOC_PRINT(title, "no title");
4948 MOC_PRINT(artist, "no artist");
4951 MOC_PRINT(song, "no song");
4954 MOC_PRINT(album, "no album");
4956 OBJ(moc_totaltime) {
4957 MOC_PRINT(totaltime, "0:00");
4960 MOC_PRINT(timeleft, "0:00");
4963 MOC_PRINT(curtime, "0:00");
4966 MOC_PRINT(bitrate, "0Kbps");
4969 MOC_PRINT(rate, "0KHz");
4975 snprintf(p, p_max_size, "%s", cur->xmms2.artist);
4978 snprintf(p, p_max_size, "%s", cur->xmms2.album);
4981 snprintf(p, p_max_size, "%s", cur->xmms2.title);
4984 snprintf(p, p_max_size, "%s", cur->xmms2.genre);
4986 OBJ(xmms2_comment) {
4987 snprintf(p, p_max_size, "%s", cur->xmms2.comment);
4990 snprintf(p, p_max_size, "%s", cur->xmms2.url);
4993 snprintf(p, p_max_size, "%s", cur->xmms2.status);
4996 snprintf(p, p_max_size, "%s", cur->xmms2.date);
4998 OBJ(xmms2_tracknr) {
4999 if (cur->xmms2.tracknr != -1) {
5000 snprintf(p, p_max_size, "%i", cur->xmms2.tracknr);
5003 OBJ(xmms2_bitrate) {
5004 snprintf(p, p_max_size, "%i", cur->xmms2.bitrate);
5007 snprintf(p, p_max_size, "%u", cur->xmms2.id);
5010 snprintf(p, p_max_size, "%2.1f", cur->xmms2.size);
5012 OBJ(xmms2_elapsed) {
5013 snprintf(p, p_max_size, "%02d:%02d", cur->xmms2.elapsed / 60000,
5014 (cur->xmms2.elapsed / 1000) % 60);
5016 OBJ(xmms2_duration) {
5017 snprintf(p, p_max_size, "%02d:%02d",
5018 cur->xmms2.duration / 60000,
5019 (cur->xmms2.duration / 1000) % 60);
5021 OBJ(xmms2_percent) {
5022 snprintf(p, p_max_size, "%2.0f", cur->xmms2.progress * 100);
5025 new_bar(p, obj->data.pair.a, obj->data.pair.b,
5026 (int) (cur->xmms2.progress * 255.0f));
5028 OBJ(xmms2_playlist) {
5029 snprintf(p, p_max_size, "%s", cur->xmms2.playlist);
5031 OBJ(xmms2_timesplayed) {
5032 snprintf(p, p_max_size, "%i", cur->xmms2.timesplayed);
5035 if (strlen(cur->xmms2.title) < 2
5036 && strlen(cur->xmms2.title) < 2) {
5037 snprintf(p, p_max_size, "%s", cur->xmms2.url);
5039 snprintf(p, p_max_size, "%s - %s", cur->xmms2.artist,
5043 OBJ(if_xmms2_connected) {
5044 if (cur->xmms2.conn_state != 1) {
5050 OBJ(audacious_status) {
5051 snprintf(p, p_max_size, "%s",
5052 cur->audacious.items[AUDACIOUS_STATUS]);
5054 OBJ(audacious_title) {
5055 snprintf(p, cur->audacious.max_title_len > 0
5056 ? cur->audacious.max_title_len : p_max_size, "%s",
5057 cur->audacious.items[AUDACIOUS_TITLE]);
5059 OBJ(audacious_length) {
5060 snprintf(p, p_max_size, "%s",
5061 cur->audacious.items[AUDACIOUS_LENGTH]);
5063 OBJ(audacious_length_seconds) {
5064 snprintf(p, p_max_size, "%s",
5065 cur->audacious.items[AUDACIOUS_LENGTH_SECONDS]);
5067 OBJ(audacious_position) {
5068 snprintf(p, p_max_size, "%s",
5069 cur->audacious.items[AUDACIOUS_POSITION]);
5071 OBJ(audacious_position_seconds) {
5072 snprintf(p, p_max_size, "%s",
5073 cur->audacious.items[AUDACIOUS_POSITION_SECONDS]);
5075 OBJ(audacious_bitrate) {
5076 snprintf(p, p_max_size, "%s",
5077 cur->audacious.items[AUDACIOUS_BITRATE]);
5079 OBJ(audacious_frequency) {
5080 snprintf(p, p_max_size, "%s",
5081 cur->audacious.items[AUDACIOUS_FREQUENCY]);
5083 OBJ(audacious_channels) {
5084 snprintf(p, p_max_size, "%s",
5085 cur->audacious.items[AUDACIOUS_CHANNELS]);
5087 OBJ(audacious_filename) {
5088 snprintf(p, p_max_size, "%s",
5089 cur->audacious.items[AUDACIOUS_FILENAME]);
5091 OBJ(audacious_playlist_length) {
5092 snprintf(p, p_max_size, "%s",
5093 cur->audacious.items[AUDACIOUS_PLAYLIST_LENGTH]);
5095 OBJ(audacious_playlist_position) {
5096 snprintf(p, p_max_size, "%s",
5097 cur->audacious.items[AUDACIOUS_PLAYLIST_POSITION]);
5099 OBJ(audacious_main_volume) {
5100 snprintf(p, p_max_size, "%s",
5101 cur->audacious.items[AUDACIOUS_MAIN_VOLUME]);
5103 OBJ(audacious_bar) {
5107 atof(cur->audacious.items[AUDACIOUS_POSITION_SECONDS]) /
5108 atof(cur->audacious.items[AUDACIOUS_LENGTH_SECONDS]);
5109 new_bar(p, obj->a, obj->b, (int) (progress * 255.0f));
5115 snprintf(p, p_max_size, "%s", cur->bmpx.title);
5118 snprintf(p, p_max_size, "%s", cur->bmpx.artist);
5121 snprintf(p, p_max_size, "%s", cur->bmpx.album);
5124 snprintf(p, p_max_size, "%s", cur->bmpx.uri);
5127 snprintf(p, p_max_size, "%i", cur->bmpx.track);
5130 snprintf(p, p_max_size, "%i", cur->bmpx.bitrate);
5133 /* we have three different types of top (top, top_mem
5134 * and top_time). To avoid having almost-same code three
5135 * times, we have this special handler. */
5138 parse_top_args("top", obj->data.top.s, obj);
5139 if (!needed) needed = cur->cpu;
5141 parse_top_args("top_mem", obj->data.top.s, obj);
5142 if (!needed) needed = cur->memu;
5144 parse_top_args("top_time", obj->data.top.s, obj);
5145 if (!needed) needed = cur->time;
5147 if (needed[obj->data.top.num]) {
5150 switch (obj->data.top.type) {
5152 snprintf(p, top_name_width + 1, "%-*s", top_name_width,
5153 needed[obj->data.top.num]->name);
5156 snprintf(p, 7, "%6.2f",
5157 needed[obj->data.top.num]->amount);
5160 snprintf(p, 6, "%5i",
5161 needed[obj->data.top.num]->pid);
5164 snprintf(p, 7, "%6.2f",
5165 needed[obj->data.top.num]->totalmem);
5168 timeval = format_time(
5169 needed[obj->data.top.num]->total_cpu_time, 9);
5170 snprintf(p, 10, "%9s", timeval);
5174 human_readable(needed[obj->data.top.num]->rss,
5178 human_readable(needed[obj->data.top.num]->vsize,
5184 print_tail_object(obj, p, p_max_size);
5186 print_head_object(obj, p, p_max_size);
5188 FILE *fp = open_file(obj->data.s, &obj->a);
5191 /* FIXME: use something more general (see also tail.c, head.c */
5192 #define BUFSZ 0x1000
5197 while(fgets(buf, BUFSZ, fp) != NULL){
5198 for(j = 0; buf[j] != 0; j++) {
5199 if(buf[j] == '\n') {
5204 sprintf(p, "%d", lines);
5207 sprintf(p, "File Unreadable");
5212 FILE *fp = open_file(obj->data.s, &obj->a);
5217 char inword = FALSE;
5220 while(fgets(buf, BUFSZ, fp) != NULL){
5221 for(j = 0; buf[j] != 0; j++) {
5222 if(!isspace(buf[j])) {
5223 if(inword == FALSE) {
5232 sprintf(p, "%d", words);
5235 sprintf(p, "File Unreadable");
5238 #ifdef TCP_PORT_MONITOR
5240 tcp_portmon_action(p, p_max_size,
5241 &obj->data.tcp_port_monitor);
5247 iconv_converting = 1;
5248 iconv_selected = obj->a;
5251 iconv_converting = 0;
5256 OBJ(entropy_avail) {
5257 snprintf(p, p_max_size, "%d", cur->entropy.entropy_avail);
5259 OBJ(entropy_poolsize) {
5260 snprintf(p, p_max_size, "%d", cur->entropy.poolsize);
5264 double entropy_perc;
5266 entropy_perc = (double) cur->entropy.entropy_avail /
5267 (double) cur->entropy.poolsize;
5268 new_bar(p, obj->a, obj->b, (int) (entropy_perc * 255.0f));
5275 s = smapi_get_val(obj->data.s);
5276 snprintf(p, p_max_size, "%s", s);
5280 OBJ(if_smapi_bat_installed) {
5282 if(obj->data.ifblock.s && sscanf(obj->data.ifblock.s, "%i", &idx) == 1) {
5283 if(!smapi_bat_installed(idx)) {
5287 ERR("argument to if_smapi_bat_installed must be an integer");
5289 OBJ(smapi_bat_perc) {
5291 if(obj->data.s && sscanf(obj->data.s, "%i", &idx) == 1) {
5292 val = smapi_bat_installed(idx) ?
5293 smapi_get_bat_int(idx, "remaining_percent") : 0;
5294 percent_print(p, p_max_size, val);
5296 ERR("argument to smapi_bat_perc must be an integer");
5298 OBJ(smapi_bat_temp) {
5300 if(obj->data.s && sscanf(obj->data.s, "%i", &idx) == 1) {
5301 val = smapi_bat_installed(idx) ?
5302 smapi_get_bat_int(idx, "temperature") : 0;
5303 /* temperature is in milli degree celsius */
5304 temp_print(p, p_max_size, val / 1000, TEMP_CELSIUS);
5306 ERR("argument to smapi_bat_temp must be an integer");
5308 OBJ(smapi_bat_power) {
5310 if(obj->data.s && sscanf(obj->data.s, "%i", &idx) == 1) {
5311 val = smapi_bat_installed(idx) ?
5312 smapi_get_bat_int(idx, "power_now") : 0;
5313 /* power_now is in mW, set to W with one digit precision */
5314 snprintf(p, p_max_size, "%.1f", ((double)val / 1000));
5316 ERR("argument to smapi_bat_power must be an integer");
5318 OBJ(smapi_bat_bar) {
5319 if(obj->data.i >= 0 && smapi_bat_installed(obj->data.i))
5320 new_bar(p, obj->a, obj->b, (int)
5321 (255 * smapi_get_bat_int(obj->data.i, "remaining_percent") / 100));
5323 new_bar(p, obj->a, obj->b, 0);
5328 char *tmp, buf[max_user_text];
5329 generate_text_internal(buf, max_user_text,
5332 if (strlen(buf) <= obj->data.scroll.show) {
5333 snprintf(p, p_max_size, "%s", buf);
5336 #define LINESEPARATOR '|'
5337 //place all the lines behind each other with LINESEPARATOR between them
5338 for(j = 0; buf[j] != 0; j++) {
5340 buf[j]=LINESEPARATOR;
5343 //scroll the output obj->data.scroll.start places by copying that many chars from
5344 //the front of the string to tmp, scrolling the rest to the front and placing tmp
5345 //at the back of the string
5346 tmp = calloc(obj->data.scroll.start + 1, sizeof(char));
5347 strncpy(tmp, buf, obj->data.scroll.start); tmp[obj->data.scroll.start] = 0;
5348 for(j = obj->data.scroll.start; buf[j] != 0; j++){
5349 buf[j - obj->data.scroll.start] = buf[j];
5351 strcpy(&buf[j - obj->data.scroll.start], tmp);
5353 //only show the requested number of chars
5354 if(obj->data.scroll.show < j) {
5355 buf[obj->data.scroll.show] = 0;
5357 //next time, scroll a place more or reset scrolling if we are at the end
5358 obj->data.scroll.start += obj->data.scroll.step;
5359 if(obj->data.scroll.start >= j){
5360 obj->data.scroll.start = 0;
5362 snprintf(p, p_max_size, "%s", buf);
5365 char buf[2][max_user_text];
5372 struct llrows* next;
5374 struct llrows *ll_rows[2], *current[2];
5375 struct text_object * objsub = obj->sub;
5379 #pragma omp parallel for
5380 #endif /* HAVE_OPENMP */
5381 for(i=0; i<2; i++) {
5384 ll_rows[i] = malloc(sizeof(struct llrows));
5385 current[i] = ll_rows[i];
5387 #pragma omp parallel for
5388 #endif /* HAVE_OPENMP */
5389 for(j=0; j<i; j++) objsub = objsub->sub;
5390 generate_text_internal(buf[i], max_user_text, *objsub, cur);
5392 * #ifdef HAVE_OPENMP
5393 * #pragma omp parallel for reduction (+:nr_rows[i])
5394 * #endif HAVE_OPENMP */
5395 for(j=0; buf[i][j] != 0; j++) {
5396 if(buf[i][j] == '\t') buf[i][j] = ' ';
5397 if(buf[i][j] == '\n') {
5399 current[i]->row = strdup(buf[i]+nextstart);
5400 if(i==0 && (long)strlen(current[i]->row) > longest) longest = (long)strlen(current[i]->row);
5401 current[i]->next = malloc(sizeof(struct llrows));
5402 current[i] = current[i]->next;
5407 current[i]->row = strdup(buf[i]+nextstart);
5408 if(i==0 && (long)strlen(current[i]->row) > longest) longest = (long)strlen(current[i]->row);
5409 current[i]->next = NULL;
5410 current[i] = ll_rows[i];
5412 for(j=0; j < (nr_rows[0] > nr_rows[1] ? nr_rows[0] : nr_rows[1] ); j++) {
5414 strcat(p, current[0]->row);
5415 i=strlen(current[0]->row);
5417 while(i < longest) {
5422 strcat(p, obj->data.combine.seperation);
5423 strcat(p, current[1]->row);
5427 #pragma omp parallel for
5428 #endif /* HAVE_OPENMP */
5429 for(i=0; i<2; i++) if(current[i]) current[i]=current[i]->next;
5432 #pragma omp parallel for
5433 #endif /* HAVE_OPENMP */
5434 for(i=0; i<2; i++) {
5435 while(ll_rows[i] != NULL) {
5436 current[i]=ll_rows[i];
5437 free(current[i]->row);
5438 ll_rows[i]=current[i]->next;
5445 int value = get_nvidia_value(obj->data.nvidia.type, display);
5447 snprintf(p, p_max_size, "N/A");
5448 else if (obj->data.nvidia.type == NV_TEMP)
5449 temp_print(p, p_max_size, (double)value, TEMP_CELSIUS);
5450 else if (obj->data.nvidia.print_as_float &&
5451 value > 0 && value < 100)
5452 snprintf(p, p_max_size, "%.1f", (float)value);
5454 snprintf(p, p_max_size, "%d", value);
5459 /* This is just a meta-object to set host:port */
5462 snprintf(p, p_max_size, "%s",
5463 cur->apcupsd.items[APCUPSD_NAME]);
5465 OBJ(apcupsd_model) {
5466 snprintf(p, p_max_size, "%s",
5467 cur->apcupsd.items[APCUPSD_MODEL]);
5469 OBJ(apcupsd_upsmode) {
5470 snprintf(p, p_max_size, "%s",
5471 cur->apcupsd.items[APCUPSD_UPSMODE]);
5473 OBJ(apcupsd_cable) {
5474 snprintf(p, p_max_size, "%s",
5475 cur->apcupsd.items[APCUPSD_CABLE]);
5477 OBJ(apcupsd_status) {
5478 snprintf(p, p_max_size, "%s",
5479 cur->apcupsd.items[APCUPSD_STATUS]);
5481 OBJ(apcupsd_linev) {
5482 snprintf(p, p_max_size, "%s",
5483 cur->apcupsd.items[APCUPSD_LINEV]);
5486 snprintf(p, p_max_size, "%s",
5487 cur->apcupsd.items[APCUPSD_LOAD]);
5490 OBJ(apcupsd_loadbar) {
5492 progress = atof(cur->apcupsd.items[APCUPSD_LOAD]) / 100.0 * 255.0;
5493 new_bar(p, obj->a, obj->b, (int)progress);
5495 OBJ(apcupsd_loadgraph) {
5497 progress = atof(cur->apcupsd.items[APCUPSD_LOAD]);
5498 new_graph(p, obj->a, obj->b, obj->c, obj->d,
5499 (int)progress, 100, 1, obj->char_a, obj->char_b);
5501 OBJ(apcupsd_loadgauge) {
5503 progress = atof(cur->apcupsd.items[APCUPSD_LOAD]) / 100.0 * 255.0;
5504 new_gauge(p, obj->a, obj->b,
5508 OBJ(apcupsd_charge) {
5509 snprintf(p, p_max_size, "%s",
5510 cur->apcupsd.items[APCUPSD_CHARGE]);
5512 OBJ(apcupsd_timeleft) {
5513 snprintf(p, p_max_size, "%s",
5514 cur->apcupsd.items[APCUPSD_TIMELEFT]);
5517 snprintf(p, p_max_size, "%s",
5518 cur->apcupsd.items[APCUPSD_TEMP]);
5520 OBJ(apcupsd_lastxfer) {
5521 snprintf(p, p_max_size, "%s",
5522 cur->apcupsd.items[APCUPSD_LASTXFER]);
5524 #endif /* APCUPSD */
5531 unsigned int a = strlen(p);
5534 if (a > 0 && iconv_converting && iconv_selected > 0
5535 && (iconv_cd[iconv_selected - 1] != (iconv_t) (-1))) {
5537 size_t dummy1, dummy2;
5538 char *ptr = buff_in;
5541 dummy1 = dummy2 = a;
5543 strncpy(buff_in, p, p_max_size);
5545 iconv(*iconv_cd[iconv_selected - 1], NULL, NULL, NULL, NULL);
5546 while (dummy1 > 0) {
5547 bytes = iconv(*iconv_cd[iconv_selected - 1], &ptr, &dummy1,
5550 ERR("Iconv codeset conversion failed");
5555 /* It is nessecary when we are converting from multibyte to
5556 * singlebyte codepage */
5559 #endif /* HAVE_ICONV */
5567 double current_update_time, next_update_time, last_update_time;
5569 static void generate_text(void)
5571 struct information *cur = &info;
5578 current_update_time = get_time();
5582 /* add things to the buffer */
5588 generate_text_internal(p, max_user_text, global_root_object, cur);
5590 if (stuff_in_upper_case) {
5593 tmp_p = text_buffer;
5595 *tmp_p = toupper(*tmp_p);
5600 next_update_time += update_interval;
5601 if (next_update_time < get_time()) {
5602 next_update_time = get_time() + update_interval;
5603 } else if (next_update_time > get_time() + update_interval) {
5604 next_update_time = get_time() + update_interval;
5606 last_update_time = current_update_time;
5611 static inline int get_string_width(const char *s)
5614 if (output_methods & TO_X) {
5615 return *s ? calc_text_width(s, strlen(s)) : 0;
5621 static inline int get_string_width_special(char *s)
5629 if ((output_methods & TO_X) == 0) {
5631 return (s) ? strlen(s) : 0;
5639 p = strndup(s, text_buffer_size);
5643 if (*p == SPECIAL_CHAR) {
5644 /* shift everything over by 1 so that the special char
5645 * doesn't mess up the size calculation */
5646 for (i = 0; i < (long)strlen(p); i++) {
5647 *(p + i) = *(p + i + 1);
5649 if (specials[special_index + idx].type == GRAPH
5650 || specials[special_index + idx].type == GAUGE
5651 || specials[special_index + idx].type == BAR) {
5652 width += specials[special_index + idx].width;
5659 if (strlen(final) > 1) {
5660 width += calc_text_width(final, strlen(final));
5668 static void text_size_updater(char *s);
5670 int last_font_height;
5671 static void update_text_area(void)
5675 if ((output_methods & TO_X) == 0)
5677 /* update text size if it isn't fixed */
5682 text_width = minimum_width;
5685 last_font_height = font_height();
5686 for_each_line(text_buffer, text_size_updater);
5688 if (text_height < minimum_height) {
5689 text_height = minimum_height;
5691 if (text_width > maximum_width && maximum_width > 0) {
5692 text_width = maximum_width;
5696 /* get text position on workarea */
5697 switch (text_alignment) {
5704 x = workarea[2] - text_width - gap_x;
5709 x = workarea[2] / 2 - text_width / 2 - gap_x;
5716 y = workarea[3] - text_height - gap_y;
5720 x = workarea[2] - text_width - gap_x;
5721 y = workarea[3] - text_height - gap_y;
5725 x = workarea[2] / 2 - text_width / 2 - gap_x;
5726 y = workarea[3] - text_height - gap_y;
5731 y = workarea[3] / 2 - text_height / 2 - gap_y;
5735 x = workarea[2] - text_width - gap_x;
5736 y = workarea[3] / 2 - text_height / 2 - gap_y;
5740 case NONE: // Let the WM manage the window
5751 if (own_window && !fixed_pos) {
5754 text_start_x = border_margin + 1;
5755 text_start_y = border_margin + 1;
5756 window.x = x - border_margin - 1;
5757 window.y = y - border_margin - 1;
5761 /* If window size doesn't match to workarea's size,
5762 * then window probably includes panels (gnome).
5763 * Blah, doesn't work on KDE. */
5764 if (workarea[2] != window.width || workarea[3] != window.height) {
5776 static int cur_x, cur_y; /* current x and y for drawing */
5778 //draw_mode also without X11 because we only need to print to stdout with FG
5779 static int draw_mode; /* FG, BG or OUTLINE */
5781 static long current_color;
5783 static void text_size_updater(char *s)
5788 if ((output_methods & TO_X) == 0)
5790 /* get string widths and skip specials */
5793 if (*p == SPECIAL_CHAR) {
5795 w += get_string_width(s);
5798 if (specials[special_index].type == BAR
5799 || specials[special_index].type == GAUGE
5800 || specials[special_index].type == GRAPH) {
5801 w += specials[special_index].width;
5802 if (specials[special_index].height > last_font_height) {
5803 last_font_height = specials[special_index].height;
5804 last_font_height += font_height();
5806 } else if (specials[special_index].type == OFFSET) {
5807 if (specials[special_index].arg > 0) {
5808 w += specials[special_index].arg;
5810 } else if (specials[special_index].type == VOFFSET) {
5811 last_font_height += specials[special_index].arg;
5812 } else if (specials[special_index].type == GOTO) {
5813 if (specials[special_index].arg > cur_x) {
5814 w = (int) specials[special_index].arg;
5816 } else if (specials[special_index].type == TAB) {
5817 int start = specials[special_index].arg;
5818 int step = specials[special_index].width;
5820 if (!step || step < 0) {
5823 w += step - (cur_x - text_start_x - start) % step;
5824 } else if (specials[special_index].type == FONT) {
5825 selected_font = specials[special_index].font_added;
5826 if (font_height() > last_font_height) {
5827 last_font_height = font_height();
5836 w += get_string_width(s);
5837 if (w > text_width) {
5840 if (text_width > maximum_width && maximum_width) {
5841 text_width = maximum_width;
5844 text_height += last_font_height;
5845 last_font_height = font_height();
5848 static inline void set_foreground_color(long c)
5850 if ((output_methods & TO_X) == 0)
5853 XSetForeground(display, window.gc, c);
5857 static void draw_string(const char *s)
5859 int i, i2, pos, width_of_s;
5867 width_of_s = get_string_width(s);
5868 if ((output_methods & TO_STDOUT) && draw_mode == FG) {
5870 fflush(stdout); /* output immediately, don't buffer */
5872 if ((output_methods & TO_STDERR) && draw_mode == FG) {
5873 fprintf(stderr, "%s\n", s);
5874 fflush(stderr); /* output immediately, don't buffer */
5876 if ((output_methods & OVERWRITE_FILE) && draw_mode == FG && overwrite_fpointer) {
5877 fprintf(overwrite_fpointer, "%s\n", s);
5879 if ((output_methods & APPEND_FILE) && draw_mode == FG && append_fpointer) {
5880 fprintf(append_fpointer, "%s\n", s);
5882 memset(tmpstring1, 0, text_buffer_size);
5883 memset(tmpstring2, 0, text_buffer_size);
5884 strncpy(tmpstring1, s, text_buffer_size - 1);
5889 if (output_methods & TO_X) {
5890 max = ((text_width - width_of_s) / get_string_width(" "));
5893 /* This code looks for tabs in the text and coverts them to spaces.
5894 * The trick is getting the correct number of spaces, and not going
5895 * over the window's size without forcing the window larger. */
5896 for (i = 0; i < (int) text_buffer_size; i++) {
5897 if (tmpstring1[i] == '\t') {
5899 for (i2 = 0; i2 < (8 - (1 + pos) % 8) && added <= max; i2++) {
5900 /* guard against overrun */
5901 tmpstring2[MIN(pos + i2, (int)text_buffer_size - 1)] = ' ';
5906 /* guard against overrun */
5907 tmpstring2[MIN(pos, (int) text_buffer_size - 1)] = tmpstring1[i];
5912 if (output_methods & TO_X) {
5913 if (text_width == maximum_width) {
5914 /* this means the text is probably pushing the limit,
5915 * so we'll chop it */
5916 while (cur_x + get_string_width(tmpstring2) - text_start_x
5917 > maximum_width && strlen(tmpstring2) > 0) {
5918 tmpstring2[strlen(tmpstring2) - 1] = '\0';
5925 if (output_methods & TO_X) {
5931 c.pixel = current_color;
5932 XQueryColor(display, DefaultColormap(display, screen), &c);
5935 c2.color.red = c.red;
5936 c2.color.green = c.green;
5937 c2.color.blue = c.blue;
5938 c2.color.alpha = fonts[selected_font].font_alpha;
5940 XftDrawStringUtf8(window.xftdraw, &c2, fonts[selected_font].xftfont,
5941 cur_x, cur_y, (const XftChar8 *) s, strlen(s));
5943 XftDrawString8(window.xftdraw, &c2, fonts[selected_font].xftfont,
5944 cur_x, cur_y, (const XftChar8 *) s, strlen(s));
5949 XDrawString(display, window.drawable, window.gc, cur_x, cur_y, s,
5952 cur_x += width_of_s;
5955 memcpy(tmpstring1, s, text_buffer_size);
5958 static void draw_line(char *s)
5967 if ((output_methods & TO_X) == 0) {
5972 cur_x = text_start_x;
5973 cur_y += font_ascent();
5974 font_h = font_height();
5976 /* find specials and draw stuff */
5979 if (*p == SPECIAL_CHAR) {
5982 /* draw string before special */
5989 switch (specials[special_index].type) {
5990 case HORIZONTAL_LINE:
5992 int h = specials[special_index].height;
5993 int mid = font_ascent() / 2;
5995 w = text_start_x + text_width - cur_x;
5997 XSetLineAttributes(display, window.gc, h, LineSolid,
5998 CapButt, JoinMiter);
5999 XDrawLine(display, window.drawable, window.gc, cur_x,
6000 cur_y - mid / 2, cur_x + w, cur_y - mid / 2);
6006 int h = specials[special_index].height;
6007 int tmp_s = specials[special_index].arg;
6008 int mid = font_ascent() / 2;
6009 char ss[2] = { tmp_s, tmp_s };
6011 w = text_start_x + text_width - cur_x - 1;
6012 XSetLineAttributes(display, window.gc, h, LineOnOffDash,
6013 CapButt, JoinMiter);
6014 XSetDashes(display, window.gc, 0, ss, 2);
6015 XDrawLine(display, window.drawable, window.gc, cur_x,
6016 cur_y - mid / 2, cur_x + w, cur_y - mid / 2);
6022 int h, bar_usage, by;
6023 if (cur_x - text_start_x > maximum_width
6024 && maximum_width > 0) {
6027 h = specials[special_index].height;
6028 bar_usage = specials[special_index].arg;
6029 by = cur_y - (font_ascent() / 2) - 1;
6034 w = specials[special_index].width;
6036 w = text_start_x + text_width - cur_x - 1;
6042 XSetLineAttributes(display, window.gc, 1, LineSolid,
6043 CapButt, JoinMiter);
6045 XDrawRectangle(display, window.drawable, window.gc, cur_x,
6047 XFillRectangle(display, window.drawable, window.gc, cur_x,
6048 by, w * bar_usage / 255, h);
6056 case GAUGE: /* new GAUGE */
6059 unsigned long last_colour = current_color;
6060 float angle, px, py;
6063 if (cur_x - text_start_x > maximum_width
6064 && maximum_width > 0) {
6068 h = specials[special_index].height;
6069 by = cur_y - (font_ascent() / 2) - 1;
6074 w = specials[special_index].width;
6076 w = text_start_x + text_width - cur_x - 1;
6082 XSetLineAttributes(display, window.gc, 1, LineSolid,
6083 CapButt, JoinMiter);
6085 XDrawArc(display, window.drawable, window.gc,
6086 cur_x, by, w, h * 2, 0, 180*64);
6089 usage = specials[special_index].arg;
6090 angle = (M_PI)*(float)(usage)/255.;
6091 px = (float)(cur_x+(w/2.))-(float)(w/2.)*cos(angle);
6092 py = (float)(by+(h))-(float)(h)*sin(angle);
6094 XDrawLine(display, window.drawable, window.gc,
6095 cur_x + (w/2.), by+(h), (int)(px), (int)(py));
6103 set_foreground_color(last_colour);
6111 int h, by, i = 0, j = 0;
6113 unsigned long last_colour = current_color;
6114 unsigned long *tmpcolour = 0;
6115 if (cur_x - text_start_x > maximum_width
6116 && maximum_width > 0) {
6119 h = specials[special_index].height;
6120 by = cur_y - (font_ascent() / 2) - 1;
6125 w = specials[special_index].width;
6127 w = text_start_x + text_width - cur_x - 1;
6132 if (draw_graph_borders) {
6133 XSetLineAttributes(display, window.gc, 1, LineSolid,
6134 CapButt, JoinMiter);
6135 XDrawRectangle(display, window.drawable, window.gc,
6138 XSetLineAttributes(display, window.gc, 1, LineSolid,
6139 CapButt, JoinMiter);
6141 if (specials[special_index].last_colour != 0
6142 || specials[special_index].first_colour != 0) {
6143 tmpcolour = do_gradient(w - 1, specials[special_index].last_colour, specials[special_index].first_colour);
6146 for (i = w - 2; i > -1; i--) {
6147 if (specials[special_index].last_colour != 0
6148 || specials[special_index].first_colour != 0) {
6149 if (specials[special_index].tempgrad) {
6152 (int)((float)(w - 2) - specials[special_index].graph[j] *
6153 (w - 2) / (float)specials[special_index].graph_scale)
6157 (int)((float)(w - 2) - specials[special_index].graph[j] *
6158 (w - 2) / (float)specials[special_index].graph_scale)
6161 if (specials[special_index].graph[j] == specials[special_index].graph_scale) {
6163 (int)((float)(w - 2) - specials[special_index].graph[j] *
6164 (w - 2) / (float)specials[special_index].graph_scale)
6168 #endif /* DEBUG_lol */
6169 XSetForeground(display, window.gc, tmpcolour[
6170 (int)((float)(w - 2) - specials[special_index].graph[j] *
6171 (w - 2) / (float)specials[special_index].graph_scale)
6174 XSetForeground(display, window.gc, tmpcolour[colour_idx++]);
6177 /* this is mugfugly, but it works */
6178 XDrawLine(display, window.drawable, window.gc,
6179 cur_x + i + 1, by + h, cur_x + i + 1,
6180 round_to_int((double)by + h - specials[special_index].graph[j] *
6181 (h - 1) / specials[special_index].graph_scale));
6182 if ((w - i) / ((float) (w - 2) /
6183 (specials[special_index].graph_width)) > j
6184 && j < MAX_GRAPH_DEPTH - 3) {
6188 if (tmpcolour) free(tmpcolour);
6193 /* if (draw_mode == BG) {
6194 set_foreground_color(default_bg_color);
6195 } else if (draw_mode == OUTLINE) {
6196 set_foreground_color(default_out_color);
6198 set_foreground_color(default_fg_color);
6200 if (show_graph_range) {
6203 unsigned short int seconds = update_interval * w;
6208 unsigned short int timeunits;
6210 timeunits = seconds / 86400; seconds %= 86400;
6211 if (timeunits > 0) {
6212 asprintf(&tmp_day_str, "%dd", timeunits);
6214 tmp_day_str = strdup("");
6216 timeunits = seconds / 3600; seconds %= 3600;
6217 if (timeunits > 0) {
6218 asprintf(&tmp_hour_str, "%dh", timeunits);
6220 tmp_hour_str = strdup("");
6222 timeunits = seconds / 60; seconds %= 60;
6223 if (timeunits > 0) {
6224 asprintf(&tmp_min_str, "%dm", timeunits);
6226 tmp_min_str = strdup("");
6229 asprintf(&tmp_sec_str, "%ds", seconds);
6231 tmp_sec_str = strdup("");
6233 asprintf(&tmp_str, "%s%s%s%s", tmp_day_str, tmp_hour_str, tmp_min_str, tmp_sec_str);
6234 free(tmp_day_str); free(tmp_hour_str); free(tmp_min_str); free(tmp_sec_str);
6236 asprintf(&tmp_str, "Range not possible"); // should never happen, but better safe then sorry
6238 cur_x += (w / 2) - (font_ascent() * (strlen(tmp_str) / 2));
6239 cur_y += font_h / 2;
6240 draw_string(tmp_str);
6246 if (show_graph_scale && (specials[special_index].show_scale == 1)) {
6249 cur_x += font_ascent() / 2;
6250 cur_y += font_h / 2;
6252 calloc(log10(floor(specials[special_index].graph_scale)) + 4,
6254 sprintf(tmp_str, "%.1f", specials[special_index].graph_scale);
6255 draw_string(tmp_str);
6261 set_foreground_color(last_colour);
6267 int old = font_ascent();
6269 cur_y -= font_ascent();
6270 selected_font = specials[special_index].font_added;
6271 if (cur_y + font_ascent() < cur_y + old) {
6274 cur_y += font_ascent();
6277 font_h = font_height();
6281 if (draw_mode == FG) {
6282 set_foreground_color(specials[special_index].arg);
6287 if (draw_mode == BG) {
6288 set_foreground_color(specials[special_index].arg);
6293 if (draw_mode == OUTLINE) {
6294 set_foreground_color(specials[special_index].arg);
6299 w += specials[special_index].arg;
6303 cur_y += specials[special_index].arg;
6307 if (specials[special_index].arg >= 0) {
6308 cur_x = (int) specials[special_index].arg;
6314 int start = specials[special_index].arg;
6315 int step = specials[special_index].width;
6317 if (!step || step < 0) {
6320 w = step - (cur_x - text_start_x - start) % step;
6326 /* TODO: add back in "+ border_margin" to the end of
6328 int pos_x = text_start_x + text_width -
6329 get_string_width_special(s);
6331 /* printf("pos_x %i text_start_x %i text_width %i cur_x %i "
6332 "get_string_width(p) %i gap_x %i "
6333 "specials[special_index].arg %i border_margin %i "
6334 "border_width %i\n", pos_x, text_start_x, text_width,
6335 cur_x, get_string_width_special(s), gap_x,
6336 specials[special_index].arg, border_margin,
6338 if (pos_x > specials[special_index].arg && pos_x > cur_x) {
6339 cur_x = pos_x - specials[special_index].arg;
6346 int pos_x = (text_width) / 2 - get_string_width_special(s) /
6347 2 - (cur_x - text_start_x);
6348 /* int pos_x = text_start_x + text_width / 2 -
6349 get_string_width_special(s) / 2; */
6351 /* printf("pos_x %i text_start_x %i text_width %i cur_x %i "
6352 "get_string_width(p) %i gap_x %i "
6353 "specials[special_index].arg %i\n", pos_x, text_start_x,
6354 text_width, cur_x, get_string_width(s), gap_x,
6355 specials[special_index].arg); */
6356 if (pos_x > specials[special_index].arg) {
6357 w = pos_x - specials[special_index].arg;
6371 if (cur_y_add > 0) {
6375 cur_y += font_descent();
6380 static void draw_text(void)
6383 if (output_methods & TO_X) {
6384 cur_y = text_start_y;
6387 if (draw_borders && border_width > 0) {
6388 unsigned int b = (border_width + 1) / 2;
6390 if (stippled_borders) {
6391 char ss[2] = { stippled_borders, stippled_borders };
6392 XSetLineAttributes(display, window.gc, border_width, LineOnOffDash,
6393 CapButt, JoinMiter);
6394 XSetDashes(display, window.gc, 0, ss, 2);
6396 XSetLineAttributes(display, window.gc, border_width, LineSolid,
6397 CapButt, JoinMiter);
6400 XDrawRectangle(display, window.drawable, window.gc,
6401 text_start_x - border_margin + b, text_start_y - border_margin + b,
6402 text_width + border_margin * 2 - 1 - b * 2,
6403 text_height + border_margin * 2 - 1 - b * 2);
6410 for_each_line(text_buffer, draw_line);
6413 static void draw_stuff(void)
6415 if (overwrite_file) {
6416 overwrite_fpointer = fopen(overwrite_file, "w");
6417 if(!overwrite_fpointer)
6418 ERR("Can't overwrite '%s' anymore", overwrite_file);
6421 append_fpointer = fopen(append_file, "a");
6422 if(!append_fpointer)
6423 ERR("Can't append '%s' anymore", append_file);
6426 if (output_methods & TO_X) {
6428 if (draw_shades && !draw_outline) {
6431 set_foreground_color(default_bg_color);
6442 for (i = -1; i < 2; i++) {
6443 for (j = -1; j < 2; j++) {
6444 if (i == 0 && j == 0) {
6449 set_foreground_color(default_out_color);
6450 draw_mode = OUTLINE;
6458 set_foreground_color(default_fg_color);
6464 if (output_methods & TO_X) {
6469 swap.swap_window = window.window;
6470 swap.swap_action = XdbeBackground;
6471 XdbeSwapBuffers(display, &swap, 1);
6476 if(overwrite_fpointer) {
6477 fclose(overwrite_fpointer);
6478 overwrite_fpointer = 0;
6480 if(append_fpointer) {
6481 fclose(append_fpointer);
6482 append_fpointer = 0;
6487 static void clear_text(int exposures)
6491 /* The swap action is XdbeBackground, which clears */
6496 /* there is some extra space for borders and outlines */
6497 XClearArea(display, window.window, text_start_x - border_margin - 1,
6498 text_start_y - border_margin - 1,
6499 text_width + border_margin * 2 + 2,
6500 text_height + border_margin * 2 + 2, exposures ? True : 0);
6505 static int need_to_update;
6507 /* update_text() generates new text and clears old text area */
6508 static void update_text(void)
6515 if (output_methods & TO_X)
6521 #ifdef HAVE_SYS_INOTIFY_H
6525 static void main_loop(void)
6528 #ifdef SIGNAL_BLOCKING
6529 sigset_t newmask, oldmask;
6532 #ifdef HAVE_SYS_INOTIFY_H
6533 int inotify_config_wd = 0;
6534 #define INOTIFY_EVENT_SIZE (sizeof(struct inotify_event))
6535 #define INOTIFY_BUF_LEN (20 * (INOTIFY_EVENT_SIZE + 16))
6536 char inotify_buff[INOTIFY_BUF_LEN];
6537 #endif /* HAVE_SYS_INOTIFY_H */
6540 #ifdef SIGNAL_BLOCKING
6541 sigemptyset(&newmask);
6542 sigaddset(&newmask, SIGINT);
6543 sigaddset(&newmask, SIGTERM);
6544 sigaddset(&newmask, SIGUSR1);
6547 next_update_time = last_update_time = get_time();
6549 while (terminate == 0 && (total_run_times == 0 || info.looped < total_run_times)) {
6552 #ifdef SIGNAL_BLOCKING
6553 /* block signals. we will inspect for pending signals later */
6554 if (sigprocmask(SIG_BLOCK, &newmask, &oldmask) < 0) {
6555 CRIT_ERR("unable to sigprocmask()");
6560 if (output_methods & TO_X) {
6563 /* wait for X event or timeout */
6565 if (!XPending(display)) {
6569 t = next_update_time - get_time();
6573 } else if (t > update_interval) {
6574 t = update_interval;
6577 tv.tv_sec = (long) t;
6578 tv.tv_usec = (long) (t * 1000000) % 1000000;
6580 FD_SET(ConnectionNumber(display), &fdsr);
6582 s = select(ConnectionNumber(display) + 1, &fdsr, 0, 0, &tv);
6584 if (errno != EINTR) {
6585 ERR("can't select(): %s", strerror(errno));
6595 if (need_to_update) {
6597 int wx = window.x, wy = window.y;
6605 /* resize window if it isn't right size */
6607 && (text_width + border_margin * 2 + 1 != window.width
6608 || text_height + border_margin * 2 + 1 != window.height)) {
6609 window.width = text_width + border_margin * 2 + 1;
6610 window.height = text_height + border_margin * 2 + 1;
6611 XResizeWindow(display, window.window, window.width,
6614 set_transparent_background(window.window);
6618 /* move window if it isn't in right position */
6619 if (!fixed_pos && (window.x != wx || window.y != wy)) {
6620 XMoveWindow(display, window.window, window.x, window.y);
6631 r.x = text_start_x - border_margin;
6632 r.y = text_start_y - border_margin;
6633 r.width = text_width + border_margin * 2;
6634 r.height = text_height + border_margin * 2;
6635 XUnionRectWithRegion(&r, x11_stuff.region, x11_stuff.region);
6640 /* handle X events */
6641 while (XPending(display)) {
6644 XNextEvent(display, &ev);
6651 r.width = ev.xexpose.width;
6652 r.height = ev.xexpose.height;
6653 XUnionRectWithRegion(&r, x11_stuff.region, x11_stuff.region);
6658 case ReparentNotify:
6659 /* set background to ParentRelative for all parents */
6661 set_transparent_background(window.window);
6665 case ConfigureNotify:
6667 /* if window size isn't what expected, set fixed size */
6668 if (ev.xconfigure.width != window.width
6669 || ev.xconfigure.height != window.height) {
6670 if (window.width != 0 && window.height != 0) {
6674 /* clear old stuff before screwing up
6679 XWindowAttributes attrs;
6680 if (XGetWindowAttributes(display,
6681 window.window, &attrs)) {
6682 window.width = attrs.width;
6683 window.height = attrs.height;
6687 text_width = window.width - border_margin * 2 - 1;
6688 text_height = window.height - border_margin * 2 - 1;
6689 if (text_width > maximum_width
6690 && maximum_width > 0) {
6691 text_width = maximum_width;
6695 /* if position isn't what expected, set fixed pos
6696 * total_updates avoids setting fixed_pos when window
6697 * is set to weird locations when started */
6698 /* // this is broken
6699 if (total_updates >= 2 && !fixed_pos
6700 && (window.x != ev.xconfigure.x
6701 || window.y != ev.xconfigure.y)
6702 && (ev.xconfigure.x != 0
6703 || ev.xconfigure.y != 0)) {
6712 /* if an ordinary window with decorations */
6713 if ((window.type == TYPE_NORMAL)
6714 && (!TEST_HINT(window.hints,
6715 HINT_UNDECORATED))) {
6716 /* allow conky to hold input focus. */
6719 /* forward the click to the desktop window */
6720 XUngrabPointer(display, ev.xbutton.time);
6721 ev.xbutton.window = window.desktop;
6722 XSendEvent(display, ev.xbutton.window, False,
6723 ButtonPressMask, &ev);
6724 XSetInputFocus(display, ev.xbutton.window,
6725 RevertToParent, ev.xbutton.time);
6732 /* if an ordinary window with decorations */
6733 if ((window.type == TYPE_NORMAL)
6734 && (!TEST_HINT(window.hints,
6735 HINT_UNDECORATED))) {
6736 /* allow conky to hold input focus. */
6739 /* forward the release to the desktop window */
6740 ev.xbutton.window = window.desktop;
6741 XSendEvent(display, ev.xbutton.window, False,
6742 ButtonReleaseMask, &ev);
6751 if (ev.type == x11_stuff.event_base + XDamageNotify) {
6752 XDamageNotifyEvent *dev = (XDamageNotifyEvent *) &ev;
6754 XFixesSetRegion(display, x11_stuff.part, &dev->area, 1);
6755 XFixesUnionRegion(display, x11_stuff.region2, x11_stuff.region2, x11_stuff.part);
6757 #endif /* HAVE_XDAMAGE */
6763 XDamageSubtract(display, x11_stuff.damage, x11_stuff.region2, None);
6764 XFixesSetRegion(display, x11_stuff.region2, 0, 0);
6765 #endif /* HAVE_XDAMAGE */
6767 /* XDBE doesn't seem to provide a way to clear the back buffer without
6768 * interfering with the front buffer, other than passing XdbeBackground
6769 * to XdbeSwapBuffers. That means that if we're using XDBE, we need to
6770 * redraw the text even if it wasn't part of the exposed area. OTOH,
6771 * if we're not going to call draw_stuff at all, then no swap happens
6772 * and we can safely do nothing. */
6774 if (!XEmptyRegion(x11_stuff.region)) {
6779 r.x = text_start_x - border_margin;
6780 r.y = text_start_y - border_margin;
6781 r.width = text_width + border_margin * 2;
6782 r.height = text_height + border_margin * 2;
6783 XUnionRectWithRegion(&r, x11_stuff.region, x11_stuff.region);
6786 XSetRegion(display, window.gc, x11_stuff.region);
6789 XftDrawSetClip(window.xftdraw, x11_stuff.region);
6793 cimlib_render(text_start_x, text_start_y, window.width, window.height);
6796 XDestroyRegion(x11_stuff.region);
6797 x11_stuff.region = XCreateRegion();
6801 t = (next_update_time - get_time()) * 1000000;
6802 if(t > 0) usleep((useconds_t)t);
6809 #ifdef SIGNAL_BLOCKING
6810 /* unblock signals of interest and let handler fly */
6811 if (sigprocmask(SIG_SETMASK, &oldmask, NULL) < 0) {
6812 CRIT_ERR("unable to sigprocmask()");
6816 switch (g_signal_pending) {
6819 ERR("received SIGHUP or SIGUSR1. reloading the config file.");
6824 ERR("received SIGINT or SIGTERM to terminate. bye!");
6828 if (output_methods & TO_X) {
6829 XDestroyRegion(x11_stuff.region);
6830 x11_stuff.region = NULL;
6832 XDamageDestroy(display, x11_stuff.damage);
6833 XFixesDestroyRegion(display, x11_stuff.region2);
6834 XFixesDestroyRegion(display, x11_stuff.part);
6835 #endif /* HAVE_XDAMAGE */
6840 if(overwrite_file) {
6841 free(overwrite_file);
6850 /* Reaching here means someone set a signal
6851 * (SIGXXXX, signal_handler), but didn't write any code
6853 * If you don't want to handle a signal, don't set a handler on
6854 * it in the first place. */
6855 if (g_signal_pending) {
6856 ERR("ignoring signal (%d)", g_signal_pending);
6860 #ifdef HAVE_SYS_INOTIFY_H
6861 if (inotify_fd && !inotify_config_wd) {
6862 inotify_config_wd = inotify_add_watch(inotify_fd,
6866 if (inotify_fd && inotify_config_wd) {
6867 int len = 0, idx = 0;
6869 struct timeval time_to_wait;
6871 FD_ZERO (&descriptors);
6872 FD_SET(inotify_fd, &descriptors);
6874 time_to_wait.tv_sec = time_to_wait.tv_usec = 0;
6876 select(inotify_fd + 1, &descriptors, NULL, NULL, &time_to_wait);
6877 if (FD_ISSET(inotify_fd, &descriptors)) {
6878 /* process inotify events */
6879 len = read(inotify_fd, inotify_buff, INOTIFY_BUF_LEN);
6880 while (len > 0 && idx < len) {
6881 struct inotify_event *ev = (struct inotify_event *) &inotify_buff[idx];
6882 if (ev->wd == inotify_config_wd && (ev->mask & IN_MODIFY || ev->mask & IN_IGNORED)) {
6883 /* current_config should be reloaded */
6884 ERR("'%s' modified, reloading...", current_config);
6886 if (ev->mask & IN_IGNORED) {
6887 /* for some reason we get IN_IGNORED here
6888 * sometimes, so we need to re-add the watch */
6889 inotify_config_wd = inotify_add_watch(inotify_fd,
6896 llua_inotify_query(ev->wd, ev->mask);
6898 #endif /* HAVE_LUA */
6899 idx += INOTIFY_EVENT_SIZE + ev->len;
6903 #endif /* HAVE_SYS_INOTIFY_H */
6905 g_signal_pending = 0;
6908 #ifdef HAVE_SYS_INOTIFY_H
6910 inotify_rm_watch(inotify_fd, inotify_config_wd);
6912 inotify_fd = inotify_config_wd = 0;
6914 #endif /* HAVE_SYS_INOTIFY_H */
6916 #if defined(X11) && defined(HAVE_XDAMAGE)
6917 X11_destroy_window();
6918 #endif /* X11 && HAVE_XDAMAGE */
6921 static void load_config_file(const char *);
6922 static void load_config_file_x11(const char *);
6924 /* reload the config file */
6925 static void reload_config(void)
6927 timed_thread_destroy_registered_threads();
6929 if (info.cpu_usage) {
6930 free(info.cpu_usage);
6931 info.cpu_usage = NULL;
6942 #ifdef TCP_PORT_MONITOR
6943 tcp_portmon_clear();
6948 #endif /* HAVE_LUA */
6951 X11_destroy_window();
6954 if (current_config) {
6956 load_config_file(current_config);
6957 load_config_file_x11(current_config);
6959 /* re-init specials array */
6960 if ((specials = realloc((void *) specials,
6961 sizeof(struct special_t) * max_specials)) == 0) {
6962 ERR("failed to realloc specials array");
6968 extract_variable_text(global_text);
6974 tmpstring1 = malloc(text_buffer_size);
6975 memset(tmpstring1, 0, text_buffer_size);
6979 tmpstring2 = malloc(text_buffer_size);
6980 memset(tmpstring2, 0, text_buffer_size);
6984 text_buffer = malloc(max_user_text);
6985 memset(text_buffer, 0, max_user_text);
6988 X11_create_window();
6993 static void clean_up(void)
6996 timed_thread_destroy_registered_threads();
6998 if (info.cpu_usage) {
6999 free(info.cpu_usage);
7000 info.cpu_usage = NULL;
7003 if (output_methods & TO_X) {
7006 XdbeDeallocateBackBufferName(display, window.back_buffer);
7011 XDestroyWindow(display, window.window);
7012 XClearWindow(display, RootWindow(display, screen));
7017 XClearWindow(display, RootWindow(display, screen));
7022 XFreeGC(display, window.gc);
7024 for (i = 0; i < 10; i ++) {
7034 free_text_objects(&global_root_object, 0);
7053 free(current_config);
7055 #ifdef TCP_PORT_MONITOR
7056 tcp_portmon_clear();
7063 #endif /* HAVE_LUA */
7066 for (i = 0; i < special_count; i++) {
7067 if (specials[i].type == GRAPH) {
7068 free(specials[i].graph);
7075 clear_diskio_stats();
7078 static int string_to_bool(const char *s)
7081 // Assumes an option without a true/false means true
7083 } else if (strcasecmp(s, "yes") == EQUAL) {
7085 } else if (strcasecmp(s, "true") == EQUAL) {
7087 } else if (strcasecmp(s, "1") == EQUAL) {
7094 static enum alignment string_to_alignment(const char *s)
7096 if (strcasecmp(s, "top_left") == EQUAL) {
7098 } else if (strcasecmp(s, "top_right") == EQUAL) {
7100 } else if (strcasecmp(s, "top_middle") == EQUAL) {
7102 } else if (strcasecmp(s, "bottom_left") == EQUAL) {
7104 } else if (strcasecmp(s, "bottom_right") == EQUAL) {
7105 return BOTTOM_RIGHT;
7106 } else if (strcasecmp(s, "bottom_middle") == EQUAL) {
7107 return BOTTOM_MIDDLE;
7108 } else if (strcasecmp(s, "middle_left") == EQUAL) {
7110 } else if (strcasecmp(s, "middle_right") == EQUAL) {
7111 return MIDDLE_RIGHT;
7112 } else if (strcasecmp(s, "tl") == EQUAL) {
7114 } else if (strcasecmp(s, "tr") == EQUAL) {
7116 } else if (strcasecmp(s, "tm") == EQUAL) {
7118 } else if (strcasecmp(s, "bl") == EQUAL) {
7120 } else if (strcasecmp(s, "br") == EQUAL) {
7121 return BOTTOM_RIGHT;
7122 } else if (strcasecmp(s, "bm") == EQUAL) {
7123 return BOTTOM_MIDDLE;
7124 } else if (strcasecmp(s, "ml") == EQUAL) {
7126 } else if (strcasecmp(s, "mr") == EQUAL) {
7127 return MIDDLE_RIGHT;
7128 } else if (strcasecmp(s, "none") == EQUAL) {
7136 static void set_default_configurations_for_x(void)
7138 default_fg_color = WhitePixel(display, screen);
7139 default_bg_color = BlackPixel(display, screen);
7140 default_out_color = BlackPixel(display, screen);
7141 color0 = default_fg_color;
7142 color1 = default_fg_color;
7143 color2 = default_fg_color;
7144 color3 = default_fg_color;
7145 color4 = default_fg_color;
7146 color5 = default_fg_color;
7147 color6 = default_fg_color;
7148 color7 = default_fg_color;
7149 color8 = default_fg_color;
7150 color9 = default_fg_color;
7154 static void set_default_configurations(void)
7157 fork_to_background = 0;
7158 total_run_times = 0;
7159 info.cpu_avg_samples = 2;
7160 info.net_avg_samples = 2;
7161 info.diskio_avg_samples = 2;
7169 mpd_set_host("localhost");
7170 mpd_set_port("6600");
7173 info.xmms2.artist = NULL;
7174 info.xmms2.album = NULL;
7175 info.xmms2.title = NULL;
7176 info.xmms2.genre = NULL;
7177 info.xmms2.comment = NULL;
7178 info.xmms2.url = NULL;
7179 info.xmms2.status = NULL;
7180 info.xmms2.playlist = NULL;
7182 use_spacer = NO_SPACER;
7184 output_methods = TO_X;
7186 output_methods = TO_STDOUT;
7189 show_graph_scale = 0;
7190 show_graph_range = 0;
7191 template[0] = strdup("");
7192 template[1] = strdup("");
7193 template[2] = strdup("");
7194 template[3] = strdup("");
7195 template[4] = strdup("");
7196 template[5] = strdup("");
7197 template[6] = strdup("");
7198 template[7] = strdup("");
7199 template[8] = strdup("");
7200 template[9] = strdup("");
7203 draw_graph_borders = 1;
7205 set_first_font("6x10");
7213 window.type = TYPE_NORMAL;
7215 strcpy(window.class_name, PACKAGE_NAME);
7216 sprintf(window.title, PACKAGE_NAME" (%s)", info.uname_s.nodename);
7218 stippled_borders = 0;
7221 text_alignment = BOTTOM_LEFT;
7222 info.x11.monitor.number = 1;
7223 info.x11.monitor.current = 0;
7226 free(current_mail_spool);
7230 variable_substitute(MAIL_FILE, buf, 256);
7231 if (buf[0] != '\0') {
7232 current_mail_spool = strndup(buf, text_buffer_size);
7237 update_interval = 3.0;
7238 info.music_player_interval = 1.0;
7239 stuff_in_upper_case = 0;
7240 info.users.number = 1;
7242 #ifdef TCP_PORT_MONITOR
7243 /* set default connection limit */
7244 tcp_portmon_set_max_connections(0);
7248 /* returns 1 if you can overwrite or create the file at 'path' */
7249 static _Bool overwrite_works(const char *path)
7253 if (!(filepointer = fopen(path, "w")))
7255 fclose(filepointer);
7259 /* returns 1 if you can append or create the file at 'path' */
7260 static _Bool append_works(const char *path)
7264 if (!(filepointer = fopen(path, "a")))
7266 fclose(filepointer);
7271 static void X11_initialisation(void)
7273 if (x_initialised == YES) return;
7274 output_methods |= TO_X;
7276 set_default_configurations_for_x();
7277 x_initialised = YES;
7280 static void X11_destroy_window(void)
7282 /* this function only exists for the sake of consistency */
7283 if (output_methods & TO_X) {
7285 XDamageDestroy(display, x11_stuff.damage);
7286 XFixesDestroyRegion(display, x11_stuff.region2);
7287 XFixesDestroyRegion(display, x11_stuff.part);
7288 if (x11_stuff.region)
7289 XDestroyRegion(x11_stuff.region);
7290 x11_stuff.region = NULL;
7291 #endif /* HAVE_XDAMAGE */
7296 static char **xargv = 0;
7297 static int xargc = 0;
7299 static void X11_create_window(void)
7301 if (output_methods & TO_X) {
7303 init_window(own_window, text_width + border_margin * 2 + 1,
7304 text_height + border_margin * 2 + 1, set_transparent, background_colour,
7306 #else /* OWN_WINDOW */
7307 init_window(0, text_width + border_margin * 2 + 1,
7308 text_height + border_margin * 2 + 1, set_transparent, 0,
7310 #endif /* OWN_WINDOW */
7314 update_text_area(); /* to position text/window on screen */
7317 if (own_window && !fixed_pos) {
7318 XMoveWindow(display, window.window, window.x, window.y);
7321 set_transparent_background(window.window);
7330 x11_stuff.region = XCreateRegion();
7332 if (!XDamageQueryExtension(display, &x11_stuff.event_base, &x11_stuff.error_base)) {
7333 ERR("Xdamage extension unavailable");
7335 x11_stuff.damage = XDamageCreate(display, window.window, XDamageReportNonEmpty);
7336 x11_stuff.region2 = XFixesCreateRegionFromWindow(display, window.window, 0);
7337 x11_stuff.part = XFixesCreateRegionFromWindow(display, window.window, 0);
7338 #endif /* HAVE_XDAMAGE */
7341 update_text_area(); /* to get initial size of the window */
7346 #define CONF_ERR ERR("%s: %d: config file error", f, line)
7347 #define CONF_ERR2(a) ERR("%s: %d: config file error: %s", f, line, a)
7348 #define CONF2(a) if (strcasecmp(name, a) == 0)
7349 #define CONF(a) else CONF2(a)
7350 #define CONF3(a, b) else if (strcasecmp(name, a) == 0 \
7351 || strcasecmp(name, b) == 0)
7352 #define CONF_CONTINUE 1
7353 #define CONF_BREAK 2
7354 #define CONF_BUFF_SIZE 512
7356 static FILE *open_config_file(const char *f)
7358 #ifdef CONFIG_OUTPUT
7359 if (!strcmp(f, "==builtin==")) {
7360 #ifdef HAVE_FOPENCOOKIE
7361 return fopencookie(NULL, "r", conf_cookie);
7362 #endif /* HAVE_FOPENCOOKIE */
7364 #endif /* CONFIG_OUTPUT */
7365 return fopen(f, "r");
7368 static int do_config_step(int *line, FILE *fp, char *buf, char **name, char **value)
7372 if (fgets(buf, CONF_BUFF_SIZE, fp) == NULL) {
7375 remove_comments(buf);
7380 while (*p && isspace((int) *p)) {
7384 return CONF_CONTINUE; /* empty line */
7391 while (*p2 && !isspace((int) *p2)) {
7395 *p2 = '\0'; /* break at name's end */
7402 while (*p && isspace((int) *p)) {
7408 p2 = *value + strlen(*value);
7409 while (isspace((int) *(p2 - 1))) {
7418 static void load_config_file(const char *f)
7423 set_default_configurations();
7424 fp = open_config_file(f);
7428 DBGP("reading contents from config file '%s'", f);
7431 char buff[CONF_BUFF_SIZE], *name, *value;
7432 int ret = do_config_step(&line, fp, buff, &name, &value);
7433 if (ret == CONF_BREAK) {
7435 } else if (ret == CONF_CONTINUE) {
7441 /* don't listen if X is already initialised or
7442 * if we already know we don't want it */
7443 if(x_initialised == NO) {
7444 if (string_to_bool(value)) {
7445 output_methods &= TO_X;
7447 output_methods &= ~TO_X;
7448 x_initialised = NEVER;
7453 if (!value || x_initialised == YES) {
7458 disp = strdup(value);
7462 if (window.type == TYPE_DOCK)
7465 int a = string_to_alignment(value);
7476 CONF("background") {
7477 fork_to_background = string_to_bool(value);
7480 CONF2("background") {
7481 fork_to_background = string_to_bool(value);
7485 CONF("show_graph_scale") {
7486 show_graph_scale = string_to_bool(value);
7488 CONF("show_graph_range") {
7489 show_graph_range = string_to_bool(value);
7491 CONF("border_margin") {
7493 border_margin = strtol(value, 0, 0);
7498 CONF("border_width") {
7500 border_width = strtol(value, 0, 0);
7505 #define TEMPLATE_CONF(n) \
7506 CONF("template"#n) { \
7508 free(template[n]); \
7509 template[n] = strdup(value); \
7527 info.mail = parse_mail_args(IMAP_TYPE, value);
7534 info.mail = parse_mail_args(POP3_TYPE, value);
7539 CONF("default_bar_size") {
7542 if (sscanf(value, "%d %d", &default_bar_width, &default_bar_height) != 2) {
7549 CONF_ERR2("default_bar_size takes 2 integer arguments (ie. 'default_bar_size 0 6')")
7553 CONF("default_graph_size") {
7556 if (sscanf(value, "%d %d", &default_graph_width, &default_graph_height) != 2) {
7563 CONF_ERR2("default_graph_size takes 2 integer arguments (ie. 'default_graph_size 0 6')")
7566 CONF("default_gauge_size") {
7569 if (sscanf(value, "%d %d", &default_gauge_width, &default_gauge_height) != 2) {
7576 CONF_ERR2("default_gauge_size takes 2 integer arguments (ie. 'default_gauge_size 0 6')")
7583 mpd_set_host(value);
7589 if (value && mpd_set_port(value)) {
7593 CONF("mpd_password") {
7595 mpd_set_password(value);
7601 CONF("music_player_interval") {
7603 info.music_player_interval = strtod(value, 0);
7609 CONF("sensor_device") {
7611 sensor_device = strtol(value, 0, 0);
7617 CONF("cpu_avg_samples") {
7619 cpu_avg_samples = strtol(value, 0, 0);
7620 if (cpu_avg_samples < 1 || cpu_avg_samples > 14) {
7623 info.cpu_avg_samples = cpu_avg_samples;
7629 CONF("net_avg_samples") {
7631 net_avg_samples = strtol(value, 0, 0);
7632 if (net_avg_samples < 1 || net_avg_samples > 14) {
7635 info.net_avg_samples = net_avg_samples;
7641 CONF("diskio_avg_samples") {
7643 diskio_avg_samples = strtol(value, 0, 0);
7644 if (diskio_avg_samples < 1 || diskio_avg_samples > 14) {
7647 info.diskio_avg_samples = diskio_avg_samples;
7655 CONF("double_buffer") {
7656 use_xdbe = string_to_bool(value);
7660 CONF("override_utf8_locale") {
7661 utf8_mode = string_to_bool(value);
7663 CONF("draw_borders") {
7664 draw_borders = string_to_bool(value);
7666 CONF("draw_graph_borders") {
7667 draw_graph_borders = string_to_bool(value);
7669 CONF("draw_shades") {
7670 draw_shades = string_to_bool(value);
7672 CONF("draw_outline") {
7673 draw_outline = string_to_bool(value);
7676 CONF("out_to_console") {
7677 if(string_to_bool(value))
7678 output_methods |= TO_STDOUT;
7680 CONF("out_to_stderr") {
7681 if(string_to_bool(value))
7682 output_methods |= TO_STDERR;
7684 CONF("overwrite_file") {
7685 if(overwrite_file) {
7686 free(overwrite_file);
7689 if(overwrite_works(value)) {
7690 overwrite_file = strdup(value);
7691 output_methods |= OVERWRITE_FILE;
7693 ERR("overwrite_file won't be able to create/overwrite '%s'", value);
7695 CONF("append_file") {
7700 if(append_works(value)) {
7701 append_file = strdup(value);
7702 output_methods |= APPEND_FILE;
7704 ERR("append_file won't be able to create/append '%s'", value);
7706 CONF("use_spacer") {
7708 if (strcasecmp(value, "left") == EQUAL) {
7709 use_spacer = LEFT_SPACER;
7710 } else if (strcasecmp(value, "right") == EQUAL) {
7711 use_spacer = RIGHT_SPACER;
7712 } else if (strcasecmp(value, "none") == EQUAL) {
7713 use_spacer = NO_SPACER;
7715 use_spacer = string_to_bool(value);
7716 ERR("use_spacer should have an argument of left, right, or"
7717 " none. '%s' seems to be some form of '%s', so"
7718 " defaulting to %s.", value,
7719 use_spacer ? "true" : "false",
7720 use_spacer ? "right" : "none");
7722 use_spacer = RIGHT_SPACER;
7724 use_spacer = NO_SPACER;
7728 ERR("use_spacer should have an argument. Defaulting to right.");
7729 use_spacer = RIGHT_SPACER;
7735 use_xft = string_to_bool(value);
7739 set_first_font(value);
7743 if (value && font_count >= 0) {
7744 fonts[0].font_alpha = atof(value) * 65535.0;
7751 if (string_to_bool(value)) {
7752 ERR("Xft not enabled");
7756 /* xftfont silently ignored when no Xft */
7759 /* xftalpha is silently ignored when no Xft */
7764 set_first_font(value);
7772 gap_x = atoi(value);
7779 gap_y = atoi(value);
7785 CONF("mail_spool") {
7789 variable_substitute(value, buffer, 256);
7791 if (buffer[0] != '\0') {
7792 if (current_mail_spool) {
7793 free(current_mail_spool);
7795 current_mail_spool = strndup(buffer, text_buffer_size);
7802 CONF("minimum_size") {
7804 if (sscanf(value, "%d %d", &minimum_width, &minimum_height)
7806 if (sscanf(value, "%d", &minimum_width) != 1) {
7814 CONF("maximum_width") {
7816 if (sscanf(value, "%d", &maximum_width) != 1) {
7824 CONF("no_buffers") {
7825 no_buffers = string_to_bool(value);
7827 CONF("top_name_width") {
7829 if (sscanf(value, "%u", &top_name_width) != 1) {
7835 if (top_name_width >= max_user_text) {
7836 top_name_width = max_user_text - 1;
7839 CONF("top_cpu_separate") {
7840 cpu_separate = string_to_bool(value);
7842 CONF("short_units") {
7843 short_units = string_to_bool(value);
7845 CONF("pad_percents") {
7846 pad_percents = atoi(value);
7850 CONF("own_window") {
7852 own_window = string_to_bool(value);
7855 CONF("own_window_class") {
7857 memset(window.class_name, 0, sizeof(window.class_name));
7858 strncpy(window.class_name, value,
7859 sizeof(window.class_name) - 1);
7862 CONF("own_window_title") {
7864 memset(window.title, 0, sizeof(window.title));
7865 strncpy(window.title, value, sizeof(window.title) - 1);
7868 CONF("own_window_transparent") {
7870 set_transparent = string_to_bool(value);
7873 CONF("own_window_hints") {
7875 char *p_hint, *p_save;
7876 char delim[] = ", ";
7878 /* tokenize the value into individual hints */
7879 if ((p_hint = strtok_r(value, delim, &p_save)) != NULL) {
7881 /* fprintf(stderr, "hint [%s] parsed\n", p_hint); */
7882 if (strncmp(p_hint, "undecorate", 10) == EQUAL) {
7883 SET_HINT(window.hints, HINT_UNDECORATED);
7884 } else if (strncmp(p_hint, "below", 5) == EQUAL) {
7885 SET_HINT(window.hints, HINT_BELOW);
7886 } else if (strncmp(p_hint, "above", 5) == EQUAL) {
7887 SET_HINT(window.hints, HINT_ABOVE);
7888 } else if (strncmp(p_hint, "sticky", 6) == EQUAL) {
7889 SET_HINT(window.hints, HINT_STICKY);
7890 } else if (strncmp(p_hint, "skip_taskbar", 12) == EQUAL) {
7891 SET_HINT(window.hints, HINT_SKIP_TASKBAR);
7892 } else if (strncmp(p_hint, "skip_pager", 10) == EQUAL) {
7893 SET_HINT(window.hints, HINT_SKIP_PAGER);
7898 p_hint = strtok_r(NULL, delim, &p_save);
7899 } while (p_hint != NULL);
7905 CONF("own_window_type") {
7907 if (strncmp(value, "normal", 6) == EQUAL) {
7908 window.type = TYPE_NORMAL;
7909 } else if (strncmp(value, "desktop", 7) == EQUAL) {
7910 window.type = TYPE_DESKTOP;
7911 } else if (strncmp(value, "dock", 7) == EQUAL) {
7912 window.type = TYPE_DOCK;
7913 text_alignment = TOP_LEFT;
7914 } else if (strncmp(value, "override", 8) == EQUAL) {
7915 window.type = TYPE_OVERRIDE;
7924 CONF("stippled_borders") {
7926 stippled_borders = strtol(value, 0, 0);
7928 stippled_borders = 4;
7932 CONF("imlib_cache_size") {
7934 cimlib_set_cache_size(atoi(value));
7939 CONF("update_interval") {
7941 update_interval = strtod(value, 0);
7945 if (info.music_player_interval == 0) {
7946 // default to update_interval
7947 info.music_player_interval = update_interval;
7950 CONF("total_run_times") {
7952 total_run_times = strtod(value, 0);
7958 stuff_in_upper_case = string_to_bool(value);
7960 CONF("max_specials") {
7962 max_specials = atoi(value);
7967 CONF("max_user_text") {
7969 max_user_text = atoi(value);
7974 CONF("text_buffer_size") {
7976 text_buffer_size = atoi(value);
7977 if (text_buffer_size < DEFAULT_TEXT_BUFFER_SIZE) {
7978 ERR("text_buffer_size must be >=%i bytes", DEFAULT_TEXT_BUFFER_SIZE);
7979 text_buffer_size = DEFAULT_TEXT_BUFFER_SIZE;
7987 if(output_methods & TO_X) {
7988 X11_initialisation();
7997 global_text = (char *) malloc(1);
7998 global_text[0] = '\0';
8001 unsigned int l = strlen(global_text);
8003 char buf[CONF_BUFF_SIZE];
8005 if (fgets(buf, CONF_BUFF_SIZE, fp) == NULL) {
8011 if (bl >= 2 && buf[bl-2] == '\\' && buf[bl-1] == '\n') {
8019 /* Check for continuation of \\-\n. */
8020 if (l > 0 && buf[0] == '\n' && global_text[l-1] == '\\') {
8021 global_text[l-1] = '\0';
8025 global_text = (char *) realloc(global_text, l + bl + 1);
8026 strcat(global_text, buf);
8028 if (strlen(global_text) > max_user_text) {
8033 if (strlen(global_text) < 1) {
8034 CRIT_ERR("no text supplied in configuration; exiting");
8036 global_text_lines = line + 1;
8039 #ifdef TCP_PORT_MONITOR
8040 CONF("max_port_monitor_connections") {
8042 if (!value || (sscanf(value, "%d", &max) != 1)) {
8043 /* an error. use default, warn and continue. */
8044 tcp_portmon_set_max_connections(0);
8046 } else if (tcp_portmon_set_max_connections(max)) {
8047 /* max is < 0, default has been set*/
8052 CONF("if_up_strictness") {
8054 ERR("incorrect if_up_strictness value, defaulting to 'up'");
8055 ifup_strictness = IFUP_UP;
8056 } else if (strcasecmp(value, "up") == EQUAL) {
8057 ifup_strictness = IFUP_UP;
8058 } else if (strcasecmp(value, "link") == EQUAL) {
8059 ifup_strictness = IFUP_LINK;
8060 } else if (strcasecmp(value, "address") == EQUAL) {
8061 ifup_strictness = IFUP_ADDR;
8063 ERR("incorrect if_up_strictness value, defaulting to 'up'");
8064 ifup_strictness = IFUP_UP;
8068 CONF("temperature_unit") {
8070 ERR("config option 'temperature_unit' needs an argument, either 'celsius' or 'fahrenheit'");
8071 } else if (set_temp_output_unit(value)) {
8072 ERR("temperature_unit: incorrect argument");
8078 size_t maxlength = strlen(value); //+1 for terminating 0 not needed, 'cause of the space in the middle of value
8079 char *skey = malloc(maxlength);
8080 char *svalue = malloc(maxlength);
8082 if (sscanf(value, "%[0-9a-zA-Z_] %[^\n]", skey, svalue) == 2) {
8083 oldvalue = getenv(skey);
8084 if (oldvalue == NULL) {
8085 setenv(skey, svalue, 0);
8087 //PS: Don't free oldvalue, it's the real envvar, not a copy
8101 char *ptr = strtok(value, " ");
8104 ptr = strtok(NULL, " ");
8110 #endif /* HAVE_LUA */
8122 CONF("default_color"){}
8123 CONF3("default_shade_color", "default_shadecolor"){}
8124 CONF3("default_outline_color", "default_outlinecolor") {}
8125 CONF("own_window_colour") {}
8128 ERR("%s: %d: no such configuration: '%s'", f, line, name);
8134 if (info.music_player_interval == 0) {
8135 // default to update_interval
8136 info.music_player_interval = update_interval;
8138 if (!global_text) { // didn't supply any text
8139 CRIT_ERR("missing text block in configuration; exiting");
8143 static void load_config_file_x11(const char *f)
8148 fp = open_config_file(f);
8152 DBGP("reading contents from config file '%s'", f);
8155 char buff[CONF_BUFF_SIZE], *name, *value;
8156 int ret = do_config_step(&line, fp, buff, &name, &value);
8157 if (ret == CONF_BREAK) {
8159 } else if (ret == CONF_CONTINUE) {
8165 X11_initialisation();
8166 if (x_initialised == YES) {
8168 color0 = get_x11_color(value);
8175 X11_initialisation();
8176 if (x_initialised == YES) {
8178 color1 = get_x11_color(value);
8185 X11_initialisation();
8186 if (x_initialised == YES) {
8188 color2 = get_x11_color(value);
8195 X11_initialisation();
8196 if (x_initialised == YES) {
8198 color3 = get_x11_color(value);
8205 X11_initialisation();
8206 if (x_initialised == YES) {
8208 color4 = get_x11_color(value);
8215 X11_initialisation();
8216 if (x_initialised == YES) {
8218 color5 = get_x11_color(value);
8225 X11_initialisation();
8226 if (x_initialised == YES) {
8228 color6 = get_x11_color(value);
8235 X11_initialisation();
8236 if (x_initialised == YES) {
8238 color7 = get_x11_color(value);
8245 X11_initialisation();
8246 if (x_initialised == YES) {
8248 color8 = get_x11_color(value);
8255 X11_initialisation();
8256 if (x_initialised == YES) {
8258 color9 = get_x11_color(value);
8264 CONF("default_color") {
8265 X11_initialisation();
8266 if (x_initialised == YES) {
8268 default_fg_color = get_x11_color(value);
8274 CONF3("default_shade_color", "default_shadecolor") {
8275 X11_initialisation();
8276 if (x_initialised == YES) {
8278 default_bg_color = get_x11_color(value);
8284 CONF3("default_outline_color", "default_outlinecolor") {
8285 X11_initialisation();
8286 if (x_initialised == YES) {
8288 default_out_color = get_x11_color(value);
8295 CONF("own_window_colour") {
8296 X11_initialisation();
8297 if (x_initialised == YES) {
8299 background_colour = get_x11_color(value);
8301 ERR("Invalid colour for own_window_colour (try omitting the "
8302 "'#' for hex colours");
8308 //initialize X11 if nothing X11-related is mentioned before TEXT (and if X11 is the default outputmethod)
8309 if(output_methods & TO_X) {
8310 X11_initialisation();
8320 #undef CONF_CONTINUE
8321 #undef CONF_BUFF_SIZE
8328 static void print_help(const char *prog_name) {
8329 printf("Usage: %s [OPTION]...\n"
8330 PACKAGE_NAME" is a system monitor that renders text on desktop or to own transparent\n"
8331 "window. Command line options will override configurations defined in config\n"
8333 " -v, --version version\n"
8334 " -q, --quiet quiet mode\n"
8335 " -D, --debug increase debugging output\n"
8336 " -c, --config=FILE config file to load\n"
8337 #ifdef CONFIG_OUTPUT
8338 " -C, --print-config print the builtin default config to stdout\n"
8339 " e.g. 'conky -C > ~/.conkyrc' will create a new default config\n"
8341 " -d, --daemonize daemonize, fork to background\n"
8342 " -h, --help help\n"
8344 " -a, --alignment=ALIGNMENT text alignment on screen, {top,bottom,middle}_{left,right,middle}\n"
8345 " -f, --font=FONT font to use\n"
8346 " -X, --display=DISPLAY X11 display to use\n"
8348 " -o, --own-window create own window to draw\n"
8351 " -b, --double-buffer double buffer (prevents flickering)\n"
8353 " -w, --window-id=WIN_ID window id to draw\n"
8354 " -x X x position\n"
8355 " -y Y y position\n"
8357 " -t, --text=TEXT text to render, remember single quotes, like -t '$uptime'\n"
8358 " -u, --interval=SECS update interval\n"
8359 " -i COUNT number of times to update "PACKAGE_NAME" (and quit)\n",
8364 /* : means that character before that takes an argument */
8365 static const char *getopt_string = "vVqdDt:u:i:hc:"
8375 #ifdef CONFIG_OUTPUT
8380 static const struct option longopts[] = {
8381 { "help", 0, NULL, 'h' },
8382 { "version", 0, NULL, 'V' },
8383 { "debug", 0, NULL, 'D' },
8384 { "config", 1, NULL, 'c' },
8385 #ifdef CONFIG_OUTPUT
8386 { "print-config", 0, NULL, 'C' },
8388 { "daemonize", 0, NULL, 'd' },
8390 { "alignment", 1, NULL, 'a' },
8391 { "font", 1, NULL, 'f' },
8392 { "display", 1, NULL, 'X' },
8394 { "own-window", 0, NULL, 'o' },
8397 { "double-buffer", 0, NULL, 'b' },
8399 { "window-id", 1, NULL, 'w' },
8401 { "text", 1, NULL, 't' },
8402 { "interval", 0, NULL, 'u' },
8406 int main(int argc, char **argv)
8412 struct sigaction act, oact;
8414 g_signal_pending = 0;
8415 memset(&info, 0, sizeof(info));
8418 #ifdef TCP_PORT_MONITOR
8419 /* set default connection limit */
8420 tcp_portmon_set_max_connections(0);
8423 /* handle command line parameters that don't change configs */
8425 if (((s = getenv("LC_ALL")) && *s) || ((s = getenv("LC_CTYPE")) && *s)
8426 || ((s = getenv("LANG")) && *s)) {
8427 temp = (char *) malloc((strlen(s) + 1) * sizeof(char));
8429 ERR("malloc failed");
8431 for (x = 0; x < strlen(s); x++) {
8432 temp[x] = tolower(s[x]);
8435 if (strstr(temp, "utf-8") || strstr(temp, "utf8")) {
8441 if (!setlocale(LC_CTYPE, "")) {
8442 ERR("Can't set the specified locale!\nCheck LANG, LC_CTYPE, LC_ALL.");
8446 int c = getopt_long(argc, argv, getopt_string, longopts, NULL);
8457 if (current_config) {
8458 free(current_config);
8460 current_config = strndup(optarg, max_user_text);
8463 freopen("/dev/null", "w", stderr);
8466 print_help(argv[0]);
8468 #ifdef CONFIG_OUTPUT
8475 window.window = strtol(optarg, 0, 0);
8484 /* check if specified config file is valid */
8485 if (current_config) {
8487 if (stat(current_config, &sb) ||
8488 (!S_ISREG(sb.st_mode) && !S_ISLNK(sb.st_mode))) {
8489 ERR("invalid configuration file '%s'\n", current_config);
8490 free(current_config);
8495 /* load current_config, CONFIG_FILE or SYSTEM_CONFIG_FILE */
8497 if (!current_config) {
8498 /* load default config file */
8499 char buf[DEFAULT_TEXT_BUFFER_SIZE];
8502 /* Try to use personal config file first */
8503 to_real_path(buf, CONFIG_FILE);
8504 if (buf[0] && (fp = fopen(buf, "r"))) {
8505 current_config = strndup(buf, max_user_text);
8509 /* Try to use system config file if personal config not readable */
8510 if (!current_config && (fp = fopen(SYSTEM_CONFIG_FILE, "r"))) {
8511 current_config = strndup(SYSTEM_CONFIG_FILE, max_user_text);
8515 /* No readable config found */
8516 if (!current_config) {
8517 #ifdef CONFIG_OUTPUT
8518 current_config = strdup("==builtin==");
8519 ERR("no readable personal or system-wide config file found,"
8520 " using builtin default");
8522 CRIT_ERR("no readable personal or system-wide config file found");
8523 #endif /* ! CONF_OUTPUT */
8526 #ifdef HAVE_SYS_INOTIFY_H
8527 inotify_fd = inotify_init();
8528 #endif /* HAVE_SYS_INOTIFY_H */
8530 load_config_file(current_config);
8532 /* init specials array */
8533 if ((specials = calloc(sizeof(struct special_t), max_specials)) == 0) {
8534 ERR("failed to create specials array");
8538 if (current_mail_spool == NULL) {
8541 variable_substitute(MAIL_FILE, buf, 256);
8543 if (buf[0] != '\0') {
8544 current_mail_spool = strndup(buf, text_buffer_size);
8549 /* handle other command line arguments */
8551 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__OpenBSD__) \
8552 || defined(__NetBSD__)
8553 optind = optreset = 1;
8558 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
8559 if ((kd = kvm_open("/dev/null", "/dev/null", "/dev/null", O_RDONLY,
8560 "kvm_open")) == NULL) {
8561 CRIT_ERR("cannot read kvm");
8566 int c = getopt_long(argc, argv, getopt_string, longopts, NULL);
8574 fork_to_background = 1;
8577 global_debug_level++;
8581 set_first_font(optarg);
8584 text_alignment = string_to_alignment(optarg);
8589 disp = strdup(optarg);
8608 global_text = strndup(optarg, max_user_text);
8609 convert_escapes(global_text);
8613 update_interval = strtod(optarg, 0);
8614 if (info.music_player_interval == 0) {
8615 // default to update_interval
8616 info.music_player_interval = update_interval;
8621 total_run_times = strtod(optarg, 0);
8625 gap_x = atoi(optarg);
8629 gap_y = atoi(optarg);
8640 if (output_methods & TO_X) {
8641 load_config_file_x11(current_config);
8646 /* generate text and get initial size */
8647 extract_variable_text(global_text);
8654 if (fork_to_background) {
8659 ERR(PACKAGE_NAME": couldn't fork() to background: %s",
8666 fprintf(stderr, "\n");
8671 /* parent process */
8672 fprintf(stderr, PACKAGE_NAME": forked to background, pid is %d\n",
8679 text_buffer = malloc(max_user_text);
8680 memset(text_buffer, 0, max_user_text);
8681 tmpstring1 = malloc(text_buffer_size);
8682 memset(tmpstring1, 0, text_buffer_size);
8683 tmpstring2 = malloc(text_buffer_size);
8684 memset(tmpstring2, 0, text_buffer_size);
8689 X11_create_window();
8692 /* Set signal handlers */
8693 act.sa_handler = signal_handler;
8694 sigemptyset(&act.sa_mask);
8697 act.sa_flags |= SA_RESTART;
8700 if ( sigaction(SIGINT, &act, &oact) < 0
8701 || sigaction(SIGUSR1, &act, &oact) < 0
8702 || sigaction(SIGHUP, &act, &oact) < 0
8703 || sigaction(SIGTERM, &act, &oact) < 0) {
8704 ERR("error setting signal handler: %s", strerror(errno));
8709 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
8716 static void signal_handler(int sig)
8718 /* signal handler is light as a feather, as it should be.
8719 * we will poll g_signal_pending with each loop of conky
8720 * and do any signal processing there, NOT here. */
8721 g_signal_pending = sig;