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);
248 static void X11_initialisation(void);
250 struct _x11_stuff_s {
254 XserverRegion region2, part;
255 int event_base, error_base;
261 static int text_start_x, text_start_y; /* text start position in window */
262 static int text_width, text_height;
277 /* display to connect to */
278 static char *disp = NULL;
282 /* struct that has all info to be shared between
283 * instances of the same text object */
284 struct information info;
286 /* default config file */
287 static char *current_config;
289 /* set to 1 if you want all text to be in uppercase */
290 static unsigned int stuff_in_upper_case;
292 /* Run how many times? */
293 static unsigned long total_run_times;
296 static int fork_to_background;
298 static int cpu_avg_samples, net_avg_samples, diskio_avg_samples;
300 /* filenames for output */
301 char *overwrite_file = NULL; FILE *overwrite_fpointer = NULL;
302 char *append_file = NULL; FILE *append_fpointer = NULL;
306 static int show_graph_scale;
307 static int show_graph_range;
309 /* Position on the screen */
310 static int text_alignment;
311 static int gap_x, gap_y;
314 static int draw_borders;
315 static int draw_graph_borders;
316 static int stippled_borders;
318 static int draw_shades, draw_outline;
320 static int border_margin, border_width;
322 static long default_fg_color, default_bg_color, default_out_color;
324 /* create own window or draw stuff to root? */
325 static int set_transparent = 0;
328 static int own_window = 0;
329 static int background_colour = 0;
331 /* fixed size/pos is set if wm/user changes them */
332 static int fixed_size = 0, fixed_pos = 0;
335 static int minimum_width, minimum_height;
336 static int maximum_width;
341 static int sensor_device;
344 static long color0, color1, color2, color3, color4, color5, color6, color7,
347 #define MAX_TEMPLATES 10
348 static char *template[MAX_TEMPLATES];
350 /* maximum size of config TEXT buffer, i.e. below TEXT line. */
351 static unsigned int max_user_text = MAX_USER_TEXT_DEFAULT;
353 /* maximum size of individual text buffers, ie $exec buffer size */
354 unsigned int text_buffer_size = DEFAULT_TEXT_BUFFER_SIZE;
357 #define CODEPAGE_LENGTH 20
359 long iconv_count = 0;
360 char iconv_converting;
361 static iconv_t **iconv_cd = 0;
363 int register_iconv(iconv_t *new_iconv)
365 iconv_cd = realloc(iconv_cd, sizeof(iconv_t *) * (iconv_count + 1));
367 CRIT_ERR("Out of memory");
369 iconv_cd[iconv_count] = malloc(sizeof(iconv_t));
370 if (!iconv_cd[iconv_count]) {
371 CRIT_ERR("Out of memory");
373 memcpy(iconv_cd[iconv_count], new_iconv, sizeof(iconv_t));
378 void free_iconv(void)
383 for (i = 0; i < iconv_count; i++) {
385 iconv_close(*iconv_cd[i]);
399 /* no buffers in used memory? */
402 /* pad percentages to decimals? */
403 static int pad_percents = 0;
405 static char *global_text = 0;
406 long global_text_lines;
408 static int total_updates;
409 static int updatereset;
411 int check_contains(char *f, char *s)
414 FILE *where = open_file(f, 0);
419 while (fgets(buf1, 256, where)) {
420 if (strstr(buf1, s)) {
427 ERR("Could not open the file");
433 static inline int calc_text_width(const char *s, int l)
435 if ((output_methods & TO_X) == 0)
442 XftTextExtentsUtf8(display, fonts[selected_font].xftfont,
443 (const FcChar8 *) s, l, &gi);
445 XftTextExtents8(display, fonts[selected_font].xftfont,
446 (const FcChar8 *) s, l, &gi);
452 return XTextWidth(fonts[selected_font].font, s, l);
457 /* formatted text to render on screen, generated in generate_text(),
458 * drawn in draw_stuff() */
460 static char *text_buffer;
463 static unsigned int special_index; /* used when drawing */
466 /* quite boring functions */
468 static inline void for_each_line(char *b, void f(char *))
472 for (ps = b, pe = b; *pe; pe++) {
486 static void convert_escapes(char *buf)
488 char *p = buf, *s = buf;
495 } else if (*s == '\\') {
506 /* Prints anything normally printed with snprintf according to the current value
507 * of use_spacer. Actually slightly more flexible than snprintf, as you can
508 * safely specify the destination buffer as one of your inputs. */
509 int spaced_print(char *buf, int size, const char *format, int width, ...)
518 tempbuf = malloc(size * sizeof(char));
520 // Passes the varargs along to vsnprintf
521 va_start(argp, width);
522 vsnprintf(tempbuf, size, format, argp);
525 switch (use_spacer) {
527 len = snprintf(buf, size, "%s", tempbuf);
530 len = snprintf(buf, size, "%*s", width, tempbuf);
533 len = snprintf(buf, size, "%-*s", width, tempbuf);
540 /* print percentage values
542 * - i.e., unsigned values between 0 and 100
543 * - respect the value of pad_percents */
544 static int percent_print(char *buf, int size, unsigned value)
546 return spaced_print(buf, size, "%u", pad_percents, value);
549 /* converts from bytes to human readable format (K, M, G, T)
551 * The algorithm always divides by 1024, as unit-conversion of byte
552 * counts suggests. But for output length determination we need to
553 * compare with 1000 here, as we print in decimal form. */
554 static void human_readable(long long num, char *buf, int size)
556 const char **suffix = suffixes;
570 if (llabs(num) < 1000LL) {
571 spaced_print(buf, size, format, width, 0, (float)num, *suffix);
575 while (llabs(num / 1024) >= 1000LL && **(suffix + 2)) {
583 /* fnum should now be < 1000, so looks like 'AAA.BBBBB'
585 * The goal is to always have a significance of 3, by
586 * adjusting the decimal part of the number. Sample output:
590 * so the point of alignment resides between number and unit. The
591 * upside of this is that there is minimal padding necessary, though
592 * there should be a way to make alignment take place at the decimal
593 * dot (then with fixed width decimal part).
595 * Note the repdigits below: when given a precision value, printf()
596 * rounds the float to it, not just cuts off the remaining digits. So
597 * e.g. 99.95 with a precision of 1 gets 100.0, which again should be
598 * printed with a precision of 0. Yay. */
600 precision = 0; /* print 100-999 without decimal part */
602 precision = 1; /* print 10-99 with one decimal place */
604 precision = 2; /* print 0-9 with two decimal places */
606 spaced_print(buf, size, format, width, precision, fnum, *suffix);
609 /* global object list root element */
610 static struct text_object global_root_object;
612 static inline void read_exec(const char *data, char *buf, const int size)
614 FILE *fp = popen(data, "r");
615 int length = fread(buf, 1, size, fp);
619 if (length > 0 && buf[length - 1] == '\n') {
620 buf[length - 1] = '\0';
624 void *threaded_exec(void *) __attribute__((noreturn));
626 void *threaded_exec(void *arg)
629 struct text_object *obj = (struct text_object *)arg;
632 buff = malloc(text_buffer_size);
633 read_exec(obj->data.texeci.cmd, buff,
642 timed_thread_lock(obj->data.texeci.p_timed_thread);
643 strncpy(obj->data.texeci.buffer, buff, text_buffer_size);
644 timed_thread_unlock(obj->data.texeci.p_timed_thread);
646 if (timed_thread_test(obj->data.texeci.p_timed_thread, 0)) {
647 timed_thread_exit(obj->data.texeci.p_timed_thread);
653 static struct text_object *new_text_object_internal(void)
655 struct text_object *obj = malloc(sizeof(struct text_object));
656 memset(obj, 0, sizeof(struct text_object));
661 * Frees the list of text objects root points to. When internal = 1, it won't
662 * free global objects.
664 static void free_text_objects(struct text_object *root, int internal)
666 struct text_object *obj;
672 #define data obj->data
673 for (obj = root->prev; obj; obj = root->prev) {
674 root->prev = obj->prev;
680 #endif /* !__OpenBSD__ */
685 close(data.sysfs.fd);
687 #endif /* __linux__ */
689 free(data.read_tcp.host);
696 free(data.tztime.tz);
697 free(data.tztime.fmt);
700 free(data.mboxscan.args);
701 free(data.mboxscan.output);
706 case OBJ_unseen_mails:
707 case OBJ_flagged_mails:
708 case OBJ_unflagged_mails:
709 case OBJ_forwarded_mails:
710 case OBJ_unforwarded_mails:
711 case OBJ_replied_mails:
712 case OBJ_unreplied_mails:
713 case OBJ_draft_mails:
714 case OBJ_trashed_mails:
715 free(data.local_mail.box);
717 case OBJ_imap_unseen:
722 case OBJ_imap_messages:
727 case OBJ_pop3_unseen:
739 free_text_objects(obj->sub, 1);
742 case OBJ_if_existing:
745 free(data.ifblock.s);
746 free(data.ifblock.str);
749 free(data.tail.logfile);
750 free(data.tail.buffer);
766 case OBJ_iconv_start:
771 case OBJ_disk_protect:
775 free(data.ifblock.s);
776 free(data.ifblock.str);
779 if (info.gw_info.iface) {
780 free(info.gw_info.iface);
781 info.gw_info.iface = 0;
783 if (info.gw_info.ip) {
784 free(info.gw_info.ip);
788 case OBJ_ioscheduler:
793 #if (defined(__FreeBSD__) || defined(__linux__))
795 free(data.ifblock.s);
796 free(data.ifblock.str);
800 case OBJ_xmms2_artist:
801 if (info.xmms2.artist) {
802 free(info.xmms2.artist);
803 info.xmms2.artist = 0;
806 case OBJ_xmms2_album:
807 if (info.xmms2.album) {
808 free(info.xmms2.album);
809 info.xmms2.album = 0;
812 case OBJ_xmms2_title:
813 if (info.xmms2.title) {
814 free(info.xmms2.title);
815 info.xmms2.title = 0;
818 case OBJ_xmms2_genre:
819 if (info.xmms2.genre) {
820 free(info.xmms2.genre);
821 info.xmms2.genre = 0;
824 case OBJ_xmms2_comment:
825 if (info.xmms2.comment) {
826 free(info.xmms2.comment);
827 info.xmms2.comment = 0;
831 if (info.xmms2.url) {
832 free(info.xmms2.url);
837 if (info.xmms2.date) {
838 free(info.xmms2.date);
842 case OBJ_xmms2_status:
843 if (info.xmms2.status) {
844 free(info.xmms2.status);
845 info.xmms2.status = 0;
848 case OBJ_xmms2_playlist:
849 if (info.xmms2.playlist) {
850 free(info.xmms2.playlist);
851 info.xmms2.playlist = 0;
854 case OBJ_xmms2_smart:
855 if (info.xmms2.artist) {
856 free(info.xmms2.artist);
857 info.xmms2.artist = 0;
859 if (info.xmms2.title) {
860 free(info.xmms2.title);
861 info.xmms2.title = 0;
863 if (info.xmms2.url) {
864 free(info.xmms2.url);
871 case OBJ_bmpx_artist:
875 case OBJ_bmpx_bitrate:
885 free(data.rss.action);
891 case OBJ_lua_read_parse:
899 #endif /* HAVE_LUA */
906 case OBJ_battery_short:
909 case OBJ_battery_time:
912 #endif /* !__OpenBSD__ */
920 free(data.execi.cmd);
921 free(data.execi.buffer);
924 free(data.texeci.cmd);
925 free(data.texeci.buffer);
933 if (info.first_process && !internal) {
934 free_all_processes();
935 info.first_process = NULL;
937 if (data.top.s) free(data.top.s);
941 free(data.hddtemp.dev);
942 free(data.hddtemp.addr);
943 if (data.hddtemp.temp)
944 free(data.hddtemp.temp);
947 case OBJ_entropy_avail:
948 case OBJ_entropy_perc:
949 case OBJ_entropy_poolsize:
950 case OBJ_entropy_bar:
953 if (info.users.names) {
954 free(info.users.names);
955 info.users.names = 0;
959 if (info.users.terms) {
960 free(info.users.terms);
961 info.users.terms = 0;
965 if (info.users.times) {
966 free(info.users.times);
967 info.users.times = 0;
972 case OBJ_smapi_bat_perc:
973 case OBJ_smapi_bat_temp:
974 case OBJ_smapi_bat_power:
977 case OBJ_if_smapi_bat_installed:
978 free(data.ifblock.s);
979 free(data.ifblock.str);
993 case OBJ_mpd_bitrate:
996 case OBJ_mpd_elapsed:
1001 case OBJ_mpd_percent:
1003 case OBJ_if_mpd_playing:
1011 case OBJ_moc_artist:
1014 case OBJ_moc_totaltime:
1015 case OBJ_moc_timeleft:
1016 case OBJ_moc_curtime:
1017 case OBJ_moc_bitrate:
1023 free(data.scroll.text);
1024 free_text_objects(obj->sub, 1);
1028 free(data.combine.left);
1029 free(data.combine.seperation);
1030 free(data.combine.right);
1031 free_text_objects(obj->sub, 1);
1036 case OBJ_apcupsd_name:
1037 case OBJ_apcupsd_model:
1038 case OBJ_apcupsd_upsmode:
1039 case OBJ_apcupsd_cable:
1040 case OBJ_apcupsd_status:
1041 case OBJ_apcupsd_linev:
1042 case OBJ_apcupsd_load:
1043 case OBJ_apcupsd_loadbar:
1045 case OBJ_apcupsd_loadgraph:
1046 case OBJ_apcupsd_loadgauge:
1048 case OBJ_apcupsd_charge:
1049 case OBJ_apcupsd_timeleft:
1050 case OBJ_apcupsd_temp:
1051 case OBJ_apcupsd_lastxfer:
1053 #endif /* APCUPSD */
1061 void scan_mixer_bar(const char *arg, int *a, int *w, int *h)
1066 if (arg && sscanf(arg, "%63s %n", buf1, &n) >= 1) {
1067 *a = mixer_init(buf1);
1068 scan_bar(arg + n, w, h);
1070 *a = mixer_init(NULL);
1071 scan_bar(arg, w, h);
1076 /* strip a leading /dev/ if any, following symlinks first
1078 * BEWARE: this function returns a pointer to static content
1079 * which gets overwritten in consecutive calls. I.e.:
1080 * this function is NOT reentrant.
1082 static const char *dev_name(const char *path)
1084 static char buf[255]; /* should be enough for pathnames */
1090 #define DEV_NAME(x) \
1091 x != NULL && strlen(x) > 5 && strncmp(x, "/dev/", 5) == 0 ? x + 5 : x
1092 if ((buflen = readlink(path, buf, 254)) == -1)
1093 return DEV_NAME(path);
1095 return DEV_NAME(buf);
1099 static int parse_top_args(const char *s, const char *arg, struct text_object *obj)
1104 if (obj->data.top.was_parsed) {
1107 obj->data.top.was_parsed = 1;
1109 if (arg && !obj->data.top.s) {
1110 obj->data.top.s = strndup(arg, text_buffer_size);
1113 need_mask |= (1 << INFO_TOP);
1116 obj->type = OBJ_top;
1118 } else if (strcmp(&s[3], "_mem") == EQUAL) {
1119 obj->type = OBJ_top_mem;
1121 } else if (strcmp(&s[3], "_time") == EQUAL) {
1122 obj->type = OBJ_top_time;
1125 ERR("Must be top, top_mem or top_time");
1130 ERR("top needs arguments");
1134 if (sscanf(arg, "%63s %i", buf, &n) == 2) {
1135 if (strcmp(buf, "name") == EQUAL) {
1136 obj->data.top.type = TOP_NAME;
1137 } else if (strcmp(buf, "cpu") == EQUAL) {
1138 obj->data.top.type = TOP_CPU;
1139 } else if (strcmp(buf, "pid") == EQUAL) {
1140 obj->data.top.type = TOP_PID;
1141 } else if (strcmp(buf, "mem") == EQUAL) {
1142 obj->data.top.type = TOP_MEM;
1143 } else if (strcmp(buf, "time") == EQUAL) {
1144 obj->data.top.type = TOP_TIME;
1145 } else if (strcmp(buf, "mem_res") == EQUAL) {
1146 obj->data.top.type = TOP_MEM_RES;
1147 } else if (strcmp(buf, "mem_vsize") == EQUAL) {
1148 obj->data.top.type = TOP_MEM_VSIZE;
1150 ERR("invalid type arg for top");
1151 ERR("must be one of: name, cpu, pid, mem, time, mem_res, mem_vsize");
1154 if (n < 1 || n > 10) {
1155 ERR("invalid num arg for top. Must be between 1 and 10.");
1158 obj->data.top.num = n - 1;
1161 ERR("invalid argument count for top");
1167 /* construct_text_object() creates a new text_object */
1168 static struct text_object *construct_text_object(const char *s,
1169 const char *arg, long line, char allow_threaded, void **ifblock_opaque)
1171 // struct text_object *obj = new_text_object();
1172 struct text_object *obj = new_text_object_internal();
1176 #define OBJ(a, n) if (strcmp(s, #a) == 0) { \
1177 obj->type = OBJ_##a; need_mask |= (1ULL << n); {
1178 #define OBJ_IF(a, n) if (strcmp(s, #a) == 0) { \
1179 obj->type = OBJ_##a; need_mask |= (1ULL << n); \
1180 obj_be_ifblock_if(ifblock_opaque, obj); {
1181 #define OBJ_THREAD(a, n) if (strcmp(s, #a) == 0 && allow_threaded) { \
1182 obj->type = OBJ_##a; need_mask |= (1ULL << n); {
1183 #define END } } else
1185 #define SIZE_DEFAULTS(arg) { \
1186 obj->a = default_##arg##_width; \
1187 obj->b = default_##arg##_height; \
1192 obj->type = OBJ_color;
1193 obj->data.l = get_x11_color(s);
1197 OBJ(freq, INFO_FREQ)
1200 obj->data.i = open_acpi_temperature(arg);
1201 END OBJ(acpiacadapter, 0)
1202 END OBJ(freq, INFO_FREQ)
1203 #endif /* !__OpenBSD__ */
1205 if (!arg || !isdigit(arg[0]) || strlen(arg) >= 2 || atoi(&arg[0]) == 0
1206 || (unsigned int) atoi(&arg[0]) > info.cpu_count) {
1207 obj->data.cpu_index = 1;
1208 /* ERR("freq: Invalid CPU number or you don't have that many CPUs! "
1209 "Displaying the clock for CPU 1."); */
1211 obj->data.cpu_index = atoi(&arg[0]);
1214 END OBJ(freq_g, INFO_FREQ)
1216 if (!arg || !isdigit(arg[0]) || strlen(arg) >= 2 || atoi(&arg[0]) == 0
1217 || (unsigned int) atoi(&arg[0]) > info.cpu_count) {
1218 obj->data.cpu_index = 1;
1219 /* ERR("freq_g: Invalid CPU number or you don't have that many "
1220 "CPUs! Displaying the clock for CPU 1."); */
1222 obj->data.cpu_index = atoi(&arg[0]);
1225 END OBJ(read_tcp, 0)
1227 obj->data.read_tcp.host = malloc(text_buffer_size);
1228 sscanf(arg, "%s", obj->data.read_tcp.host);
1229 sscanf(arg+strlen(obj->data.read_tcp.host), "%u", &(obj->data.read_tcp.port));
1230 if(obj->data.read_tcp.port == 0) {
1231 obj->data.read_tcp.port = atoi(obj->data.read_tcp.host);
1232 strcpy(obj->data.read_tcp.host,"localhost");
1234 obj->data.read_tcp.port = htons(obj->data.read_tcp.port);
1235 if(obj->data.read_tcp.port < 1 || obj->data.read_tcp.port > 65535) {
1236 CRIT_ERR("read_tcp: Needs \"(host) port\" as argument(s)");
1239 CRIT_ERR("read_tcp: Needs \"(host) port\" as argument(s)");
1241 #if defined(__linux__)
1242 END OBJ(voltage_mv, 0)
1244 if (!arg || !isdigit(arg[0]) || strlen(arg) >= 2 || atoi(&arg[0]) == 0
1245 || (unsigned int) atoi(&arg[0]) > info.cpu_count) {
1246 obj->data.cpu_index = 1;
1247 /* ERR("voltage_mv: Invalid CPU number or you don't have that many "
1248 "CPUs! Displaying voltage for CPU 1."); */
1250 obj->data.cpu_index = atoi(&arg[0]);
1253 END OBJ(voltage_v, 0)
1255 if (!arg || !isdigit(arg[0]) || strlen(arg) >= 2 || atoi(&arg[0]) == 0
1256 || (unsigned int) atoi(&arg[0]) > info.cpu_count) {
1257 obj->data.cpu_index = 1;
1258 /* ERR("voltage_v: Invalid CPU number or you don't have that many "
1259 "CPUs! Displaying voltage for CPU 1."); */
1261 obj->data.cpu_index = atoi(&arg[0]);
1266 END OBJ(wireless_essid, INFO_NET)
1268 obj->data.net = get_net_stat(arg);
1270 CRIT_ERR("wireless_essid: needs an argument");
1272 END OBJ(wireless_mode, INFO_NET)
1274 obj->data.net = get_net_stat(arg);
1276 CRIT_ERR("wireless_mode: needs an argument");
1278 END OBJ(wireless_bitrate, INFO_NET)
1280 obj->data.net = get_net_stat(arg);
1282 CRIT_ERR("wireless_bitrate: needs an argument");
1284 END OBJ(wireless_ap, INFO_NET)
1286 obj->data.net = get_net_stat(arg);
1288 CRIT_ERR("wireless_ap: needs an argument");
1290 END OBJ(wireless_link_qual, INFO_NET)
1292 obj->data.net = get_net_stat(arg);
1294 CRIT_ERR("wireless_link_qual: needs an argument");
1296 END OBJ(wireless_link_qual_max, INFO_NET)
1298 obj->data.net = get_net_stat(arg);
1300 CRIT_ERR("wireless_link_qual_max: needs an argument");
1302 END OBJ(wireless_link_qual_perc, INFO_NET)
1304 obj->data.net = get_net_stat(arg);
1306 CRIT_ERR("wireless_link_qual_perc: needs an argument");
1308 END OBJ(wireless_link_bar, INFO_NET)
1311 arg = scan_bar(arg, &obj->a, &obj->b);
1312 obj->data.net = get_net_stat(arg);
1314 CRIT_ERR("wireless_link_bar: needs an argument");
1316 #endif /* HAVE_IWLIB */
1318 #endif /* __linux__ */
1326 sscanf(arg, "%63s", bat);
1328 strcpy(bat, "BAT0");
1330 obj->data.s = strndup(bat, text_buffer_size);
1331 END OBJ(battery_short, 0)
1335 sscanf(arg, "%63s", bat);
1337 strcpy(bat, "BAT0");
1339 obj->data.s = strndup(bat, text_buffer_size);
1340 END OBJ(battery_time, 0)
1344 sscanf(arg, "%63s", bat);
1346 strcpy(bat, "BAT0");
1348 obj->data.s = strndup(bat, text_buffer_size);
1349 END OBJ(battery_percent, 0)
1353 sscanf(arg, "%63s", bat);
1355 strcpy(bat, "BAT0");
1357 obj->data.s = strndup(bat, text_buffer_size);
1358 END OBJ(battery_bar, 0)
1363 arg = scan_bar(arg, &obj->a, &obj->b);
1364 sscanf(arg, "%63s", bat);
1366 strcpy(bat, "BAT0");
1368 obj->data.s = strndup(bat, text_buffer_size);
1369 #endif /* !__OpenBSD__ */
1371 #if defined(__linux__)
1372 END OBJ(disk_protect, 0)
1374 obj->data.s = strndup(dev_name(arg), text_buffer_size);
1376 CRIT_ERR("disk_protect needs an argument");
1377 END OBJ(i8k_version, INFO_I8K)
1378 END OBJ(i8k_bios, INFO_I8K)
1379 END OBJ(i8k_serial, INFO_I8K)
1380 END OBJ(i8k_cpu_temp, INFO_I8K)
1381 END OBJ(i8k_left_fan_status, INFO_I8K)
1382 END OBJ(i8k_right_fan_status, INFO_I8K)
1383 END OBJ(i8k_left_fan_rpm, INFO_I8K)
1384 END OBJ(i8k_right_fan_rpm, INFO_I8K)
1385 END OBJ(i8k_ac_status, INFO_I8K)
1386 END OBJ(i8k_buttons_status, INFO_I8K)
1389 END OBJ(ibm_temps, 0)
1391 CRIT_ERR("ibm_temps: needs an argument");
1393 if (!isdigit(arg[0]) || strlen(arg) >= 2 || atoi(&arg[0]) >= 8) {
1394 obj->data.sensor = 0;
1395 ERR("Invalid temperature sensor! Sensor number must be 0 to 7. "
1396 "Using 0 (CPU temp sensor).");
1398 obj->data.sensor = atoi(&arg[0]);
1399 END OBJ(ibm_volume, 0)
1400 END OBJ(ibm_brightness, 0)
1402 /* information from sony_laptop kernel module
1403 * /sys/devices/platform/sony-laptop */
1404 END OBJ(sony_fanspeed, 0)
1405 END OBJ_IF(if_gw, INFO_GW)
1406 END OBJ(ioscheduler, 0)
1408 CRIT_ERR("get_ioscheduler needs an argument (e.g. hda)");
1411 obj->data.s = strndup(dev_name(arg), text_buffer_size);
1412 END OBJ(laptop_mode, 0)
1413 END OBJ(pb_battery, 0)
1414 if (arg && strcmp(arg, "status") == EQUAL) {
1415 obj->data.i = PB_BATT_STATUS;
1416 } else if (arg && strcmp(arg, "percent") == EQUAL) {
1417 obj->data.i = PB_BATT_PERCENT;
1418 } else if (arg && strcmp(arg, "time") == EQUAL) {
1419 obj->data.i = PB_BATT_TIME;
1421 ERR("pb_battery: needs one argument: status, percent or time");
1426 #endif /* __linux__ */
1427 #if (defined(__FreeBSD__) || defined(__linux__))
1428 END OBJ_IF(if_up, 0)
1430 ERR("if_up needs an argument");
1431 obj->data.ifblock.s = 0;
1433 obj->data.ifblock.s = strndup(arg, text_buffer_size);
1436 #if defined(__OpenBSD__)
1437 END OBJ(obsd_sensors_temp, 0)
1439 CRIT_ERR("obsd_sensors_temp: needs an argument");
1441 if (!isdigit(arg[0]) || atoi(&arg[0]) < 0
1442 || atoi(&arg[0]) > OBSD_MAX_SENSORS - 1) {
1443 obj->data.sensor = 0;
1444 ERR("Invalid temperature sensor number!");
1446 obj->data.sensor = atoi(&arg[0]);
1447 END OBJ(obsd_sensors_fan, 0)
1449 CRIT_ERR("obsd_sensors_fan: needs 2 arguments (device and sensor "
1452 if (!isdigit(arg[0]) || atoi(&arg[0]) < 0
1453 || atoi(&arg[0]) > OBSD_MAX_SENSORS - 1) {
1454 obj->data.sensor = 0;
1455 ERR("Invalid fan sensor number!");
1457 obj->data.sensor = atoi(&arg[0]);
1458 END OBJ(obsd_sensors_volt, 0)
1460 CRIT_ERR("obsd_sensors_volt: needs 2 arguments (device and sensor "
1463 if (!isdigit(arg[0]) || atoi(&arg[0]) < 0
1464 || atoi(&arg[0]) > OBSD_MAX_SENSORS - 1) {
1465 obj->data.sensor = 0;
1466 ERR("Invalid voltage sensor number!");
1468 obj->data.sensor = atoi(&arg[0]);
1469 END OBJ(obsd_vendor, 0)
1470 END OBJ(obsd_product, 0)
1471 #endif /* __OpenBSD__ */
1472 END OBJ(buffers, INFO_BUFFERS)
1473 END OBJ(cached, INFO_BUFFERS)
1474 #define SCAN_CPU(__arg, __var) { \
1476 if (__arg && sscanf(__arg, " cpu%u %n", &__var, &__offset) > 0) \
1477 __arg += __offset; \
1481 END OBJ(cpu, INFO_CPU)
1482 SCAN_CPU(arg, obj->data.cpu_index);
1483 DBGP2("Adding $cpu for CPU %d", obj->data.cpu_index);
1485 END OBJ(cpugauge, INFO_CPU)
1486 SIZE_DEFAULTS(gauge);
1487 SCAN_CPU(arg, obj->data.cpu_index);
1488 scan_gauge(arg, &obj->a, &obj->b);
1489 DBGP2("Adding $cpugauge for CPU %d", obj->data.cpu_index);
1491 END OBJ(cpubar, INFO_CPU)
1493 SCAN_CPU(arg, obj->data.cpu_index);
1494 scan_bar(arg, &obj->a, &obj->b);
1495 DBGP2("Adding $cpubar for CPU %d", obj->data.cpu_index);
1497 END OBJ(cpugraph, INFO_CPU)
1498 SIZE_DEFAULTS(graph);
1499 SCAN_CPU(arg, obj->data.cpu_index);
1500 scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
1501 &obj->e, &obj->char_a, &obj->char_b);
1502 DBGP2("Adding $cpugraph for CPU %d", obj->data.cpu_index);
1503 END OBJ(loadgraph, INFO_LOADAVG)
1505 SIZE_DEFAULTS(graph);
1506 buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
1507 &obj->e, &obj->char_a, &obj->char_b);
1511 r = sscanf(arg, "%d", &a);
1513 obj->data.loadavg[0] = (r >= 1) ? (unsigned char) a : 0;
1517 END OBJ(diskio, INFO_DISKIO)
1518 obj->data.diskio = prepare_diskio_stat(dev_name(arg));
1519 END OBJ(diskio_read, INFO_DISKIO)
1520 obj->data.diskio = prepare_diskio_stat(dev_name(arg));
1521 END OBJ(diskio_write, INFO_DISKIO)
1522 obj->data.diskio = prepare_diskio_stat(dev_name(arg));
1524 END OBJ(diskiograph, 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));
1533 END OBJ(diskiograph_read, INFO_DISKIO)
1535 SIZE_DEFAULTS(graph);
1536 buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
1537 &obj->e, &obj->char_a, &obj->char_b);
1539 obj->data.diskio = prepare_diskio_stat(dev_name(buf));
1542 END OBJ(diskiograph_write, INFO_DISKIO)
1544 SIZE_DEFAULTS(graph);
1545 buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
1546 &obj->e, &obj->char_a, &obj->char_b);
1548 obj->data.diskio = prepare_diskio_stat(dev_name(buf));
1554 if (output_methods & TO_X) {
1555 obj->data.l = arg ? get_x11_color(arg) : default_fg_color;
1559 obj->data.l = color0;
1561 obj->data.l = color1;
1563 obj->data.l = color2;
1565 obj->data.l = color3;
1567 obj->data.l = color4;
1569 obj->data.l = color5;
1571 obj->data.l = color6;
1573 obj->data.l = color7;
1575 obj->data.l = color8;
1577 obj->data.l = color9;
1580 obj->data.s = scan_font(arg);
1582 END OBJ(conky_version, 0)
1583 END OBJ(conky_build_date, 0)
1584 END OBJ(conky_build_arch, 0)
1585 END OBJ(downspeed, INFO_NET)
1587 obj->data.net = get_net_stat(arg);
1589 CRIT_ERR("downspeed needs argument");
1591 END OBJ(downspeedf, INFO_NET)
1593 obj->data.net = get_net_stat(arg);
1595 CRIT_ERR("downspeedf needs argument");
1598 END OBJ(downspeedgraph, INFO_NET)
1600 SIZE_DEFAULTS(graph);
1601 buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
1602 &obj->e, &obj->char_a, &obj->char_b);
1604 // default to DEFAULTNETDEV
1605 buf = strndup(buf ? buf : "DEFAULTNETDEV", text_buffer_size);
1606 obj->data.net = get_net_stat(buf);
1610 obj_be_ifblock_else(ifblock_opaque, obj);
1612 obj_be_ifblock_endif(ifblock_opaque, obj);
1614 obj->data.s = strndup(arg ? arg : "", text_buffer_size);
1616 obj->data.s = strndup(arg ? arg : "", text_buffer_size);
1619 obj->data.s = strndup(arg ? arg : "", text_buffer_size);
1621 obj->data.s = strndup(arg ? arg : "", text_buffer_size);
1624 obj->data.s = strndup(arg ? arg : "", text_buffer_size);
1626 END OBJ(execgauge, 0)
1627 SIZE_DEFAULTS(gauge);
1628 obj->data.s = strndup(arg ? arg : "", text_buffer_size);
1629 END OBJ(execgraph, 0)
1630 SIZE_DEFAULTS(graph);
1631 obj->data.s = strndup(arg ? arg : "", text_buffer_size);
1633 END OBJ(execibar, 0)
1637 if (!arg || sscanf(arg, "%f %n", &obj->data.execi.interval, &n) <= 0) {
1640 ERR("${execibar <interval> command}");
1641 obj->type = OBJ_text;
1642 snprintf(buf, 256, "${%s}", s);
1643 obj->data.s = strndup(buf, text_buffer_size);
1645 obj->data.execi.cmd = strndup(arg + n, text_buffer_size);
1648 END OBJ(execigraph, 0)
1650 SIZE_DEFAULTS(graph);
1652 if (!arg || sscanf(arg, "%f %n", &obj->data.execi.interval, &n) <= 0) {
1655 ERR("${execigraph <interval> command}");
1656 obj->type = OBJ_text;
1657 snprintf(buf, 256, "${%s}", s);
1658 obj->data.s = strndup(buf, text_buffer_size);
1660 obj->data.execi.cmd = strndup(arg + n, text_buffer_size);
1662 END OBJ(execigauge, 0)
1664 SIZE_DEFAULTS(gauge);
1666 if (!arg || sscanf(arg, "%f %n", &obj->data.execi.interval, &n) <= 0) {
1669 ERR("${execigauge <interval> command}");
1670 obj->type = OBJ_text;
1671 snprintf(buf, 256, "${%s}", s);
1672 obj->data.s = strndup(buf, text_buffer_size);
1674 obj->data.execi.cmd = strndup(arg + n, text_buffer_size);
1680 if (!arg || sscanf(arg, "%f %n", &obj->data.execi.interval, &n) <= 0) {
1683 ERR("${execi <interval> command}");
1684 obj->type = OBJ_text;
1685 snprintf(buf, 256, "${%s}", s);
1686 obj->data.s = strndup(buf, text_buffer_size);
1688 obj->data.execi.cmd = strndup(arg + n, text_buffer_size);
1689 obj->data.execi.buffer = malloc(text_buffer_size);
1694 if (!arg || sscanf(arg, "%f %n", &obj->data.execi.interval, &n) <= 0) {
1697 ERR("${execi <interval> command}");
1698 obj->type = OBJ_text;
1699 snprintf(buf, 256, "${%s}", s);
1700 obj->data.s = strndup(buf, text_buffer_size);
1702 obj->data.execi.cmd = strndup(arg + n, text_buffer_size);
1703 obj->data.execi.buffer = malloc(text_buffer_size);
1705 END OBJ_THREAD(texeci, 0)
1708 if (!arg || sscanf(arg, "%f %n", &obj->data.texeci.interval, &n) <= 0) {
1711 ERR("${texeci <interval> command}");
1712 obj->type = OBJ_text;
1713 snprintf(buf, 256, "${%s}", s);
1714 obj->data.s = strndup(buf, text_buffer_size);
1716 obj->data.texeci.cmd = strndup(arg + n, text_buffer_size);
1717 obj->data.texeci.buffer = malloc(text_buffer_size);
1719 obj->data.texeci.p_timed_thread = NULL;
1720 END OBJ(pre_exec, 0)
1721 obj->type = OBJ_text;
1725 read_exec(arg, buf, sizeof(buf));
1726 obj->data.s = strndup(buf, text_buffer_size);
1728 obj->data.s = strndup("", text_buffer_size);
1731 END OBJ(fs_bar, INFO_FS)
1733 arg = scan_bar(arg, &obj->data.fsbar.w, &obj->data.fsbar.h);
1735 while (isspace(*arg)) {
1744 obj->data.fsbar.fs = prepare_fs_stat(arg);
1745 END OBJ(fs_bar_free, INFO_FS)
1747 arg = scan_bar(arg, &obj->data.fsbar.w, &obj->data.fsbar.h);
1749 while (isspace(*arg)) {
1759 obj->data.fsbar.fs = prepare_fs_stat(arg);
1760 END OBJ(fs_free, INFO_FS)
1764 obj->data.fs = prepare_fs_stat(arg);
1765 END OBJ(fs_used_perc, INFO_FS)
1769 obj->data.fs = prepare_fs_stat(arg);
1770 END OBJ(fs_free_perc, INFO_FS)
1774 obj->data.fs = prepare_fs_stat(arg);
1775 END OBJ(fs_size, INFO_FS)
1779 obj->data.fs = prepare_fs_stat(arg);
1780 END OBJ(fs_type, INFO_FS)
1784 obj->data.fs = prepare_fs_stat(arg);
1785 END OBJ(fs_used, INFO_FS)
1789 obj->data.fs = prepare_fs_stat(arg);
1791 obj->data.i = arg ? atoi(arg) : 1;
1792 END OBJ(nameserver, INFO_DNS)
1793 obj->data.i = arg ? atoi(arg) : 0;
1795 obj->data.i = arg ? atoi(arg) : 1;
1797 obj->data.i = arg ? atoi(arg) : 1;
1801 ERR("goto needs arguments");
1802 obj->type = OBJ_text;
1803 obj->data.s = strndup("${goto}", text_buffer_size);
1807 obj->data.i = atoi(arg);
1813 if (sscanf(arg, "%d %d", &a, &b) != 2) {
1814 sscanf(arg, "%d", &b);
1820 obj->data.pair.a = a;
1821 obj->data.pair.b = b;
1824 END OBJ(i2c, INFO_SYSFS)
1825 char buf1[64], buf2[64];
1826 float factor, offset;
1830 ERR("i2c needs arguments");
1831 obj->type = OBJ_text;
1832 // obj->data.s = strndup("${i2c}", text_buffer_size);
1836 #define HWMON_RESET() {\
1841 if (sscanf(arg, "%63s %d %f %f", buf2, &n, &factor, &offset) == 4) found = 1; else HWMON_RESET();
1842 if (!found && sscanf(arg, "%63s %63s %d %f %f", buf1, buf2, &n, &factor, &offset) == 5) found = 1; else if (!found) HWMON_RESET();
1843 if (!found && sscanf(arg, "%63s %63s %d", buf1, buf2, &n) == 3) found = 1; else if (!found) HWMON_RESET();
1844 if (!found && sscanf(arg, "%63s %d", buf2, &n) == 2) found = 1; else if (!found) HWMON_RESET();
1847 ERR("i2c failed to parse arguments");
1848 obj->type = OBJ_text;
1851 DBGP("parsed i2c args: '%s' '%s' %d %f %f\n", buf1, buf2, n, factor, offset);
1852 obj->data.sysfs.fd = open_i2c_sensor((*buf1) ? buf1 : 0, buf2, n,
1853 &obj->data.sysfs.arg, obj->data.sysfs.devtype);
1854 strncpy(obj->data.sysfs.type, buf2, 63);
1855 obj->data.sysfs.factor = factor;
1856 obj->data.sysfs.offset = offset;
1858 END OBJ(platform, INFO_SYSFS)
1859 char buf1[64], buf2[64];
1860 float factor, offset;
1864 ERR("platform needs arguments");
1865 obj->type = OBJ_text;
1869 if (sscanf(arg, "%63s %d %f %f", buf2, &n, &factor, &offset) == 4) found = 1; else HWMON_RESET();
1870 if (!found && sscanf(arg, "%63s %63s %d %f %f", buf1, buf2, &n, &factor, &offset) == 5) found = 1; else if (!found) HWMON_RESET();
1871 if (!found && sscanf(arg, "%63s %63s %d", buf1, buf2, &n) == 3) found = 1; else if (!found) HWMON_RESET();
1872 if (!found && sscanf(arg, "%63s %d", buf2, &n) == 2) found = 1; else if (!found) HWMON_RESET();
1875 ERR("platform failed to parse arguments");
1876 obj->type = OBJ_text;
1879 DBGP("parsed platform args: '%s' '%s' %d %f %f\n", buf1, buf2, n, factor, offset);
1880 obj->data.sysfs.fd = open_platform_sensor((*buf1) ? buf1 : 0, buf2, n,
1881 &obj->data.sysfs.arg, obj->data.sysfs.devtype);
1882 strncpy(obj->data.sysfs.type, buf2, 63);
1883 obj->data.sysfs.factor = factor;
1884 obj->data.sysfs.offset = offset;
1886 END OBJ(hwmon, INFO_SYSFS)
1887 char buf1[64], buf2[64];
1888 float factor, offset;
1892 ERR("hwmon needs argumanets");
1893 obj->type = OBJ_text;
1897 if (sscanf(arg, "%63s %d %f %f", buf2, &n, &factor, &offset) == 4) found = 1; else HWMON_RESET();
1898 if (!found && sscanf(arg, "%63s %63s %d %f %f", buf1, buf2, &n, &factor, &offset) == 5) found = 1; else if (!found) HWMON_RESET();
1899 if (!found && sscanf(arg, "%63s %63s %d", buf1, buf2, &n) == 3) found = 1; else if (!found) HWMON_RESET();
1900 if (!found && sscanf(arg, "%63s %d", buf2, &n) == 2) found = 1; else if (!found) HWMON_RESET();
1905 ERR("hwmon failed to parse arguments");
1906 obj->type = OBJ_text;
1909 DBGP("parsed hwmon args: '%s' '%s' %d %f %f\n", buf1, buf2, n, factor, offset);
1910 obj->data.sysfs.fd = open_hwmon_sensor((*buf1) ? buf1 : 0, buf2, n,
1911 &obj->data.sysfs.arg, obj->data.sysfs.devtype);
1912 strncpy(obj->data.sysfs.type, buf2, 63);
1913 obj->data.sysfs.factor = factor;
1914 obj->data.sysfs.offset = offset;
1916 #endif /* !__OpenBSD__ */
1919 /* we have three different types of top (top, top_mem and top_time). To
1920 * avoid having almost-same code three times, we have this special
1922 if (strncmp(s, "top", 3) == EQUAL) {
1923 if (!parse_top_args(s, arg, obj)) {
1926 } else OBJ(addr, INFO_NET)
1928 obj->data.net = get_net_stat(arg);
1930 CRIT_ERR("addr needs argument");
1932 #if defined(__linux__)
1933 END OBJ(addrs, INFO_NET)
1935 obj->data.net = get_net_stat(arg);
1937 CRIT_ERR("addrs needs argument");
1939 #endif /* __linux__ */
1941 if (init_tail_object(obj, arg)) {
1942 obj->type = OBJ_text;
1943 obj->data.s = strndup("${tail}", text_buffer_size);
1946 if (init_head_object(obj, arg)) {
1947 obj->type = OBJ_text;
1948 obj->data.s = strndup("${head}", text_buffer_size);
1952 obj->data.s = strndup(arg, text_buffer_size);
1954 CRIT_ERR("lines needs a argument");
1958 obj->data.s = strndup(arg, text_buffer_size);
1960 CRIT_ERR("words needs a argument");
1962 END OBJ(loadavg, INFO_LOADAVG)
1963 int a = 1, b = 2, c = 3, r = 3;
1966 r = sscanf(arg, "%d %d %d", &a, &b, &c);
1967 if (r >= 3 && (c < 1 || c > 3)) {
1970 if (r >= 2 && (b < 1 || b > 3)) {
1973 if (r >= 1 && (a < 1 || a > 3)) {
1977 obj->data.loadavg[0] = (r >= 1) ? (unsigned char) a : 0;
1978 obj->data.loadavg[1] = (r >= 2) ? (unsigned char) b : 0;
1979 obj->data.loadavg[2] = (r >= 3) ? (unsigned char) c : 0;
1980 END OBJ_IF(if_empty, 0)
1982 ERR("if_empty needs an argument");
1983 obj->data.ifblock.s = 0;
1985 obj->data.ifblock.s = strndup(arg, text_buffer_size);
1986 obj->sub = malloc(sizeof(struct text_object));
1987 extract_variable_text_internal(obj->sub,
1988 obj->data.ifblock.s, 0);
1990 END OBJ_IF(if_match, 0)
1992 ERR("if_match needs arguments");
1993 obj->data.ifblock.s = 0;
1995 obj->data.ifblock.s = strndup(arg, text_buffer_size);
1996 obj->sub = malloc(sizeof(struct text_object));
1997 extract_variable_text_internal(obj->sub,
1998 obj->data.ifblock.s, 0);
2000 END OBJ_IF(if_existing, 0)
2002 ERR("if_existing needs an argument or two");
2003 obj->data.ifblock.s = NULL;
2004 obj->data.ifblock.str = NULL;
2006 char buf1[256], buf2[256];
2007 int r = sscanf(arg, "%255s %255[^\n]", buf1, buf2);
2010 obj->data.ifblock.s = strndup(buf1, text_buffer_size);
2011 obj->data.ifblock.str = NULL;
2013 obj->data.ifblock.s = strndup(buf1, text_buffer_size);
2014 obj->data.ifblock.str = strndup(buf2, text_buffer_size);
2017 DBGP("if_existing: '%s' '%s'", obj->data.ifblock.s, obj->data.ifblock.str);
2018 END OBJ_IF(if_mounted, 0)
2020 ERR("if_mounted needs an argument");
2021 obj->data.ifblock.s = 0;
2023 obj->data.ifblock.s = strndup(arg, text_buffer_size);
2025 END OBJ_IF(if_running, 0)
2029 snprintf(buf, 256, "pidof %s >/dev/null", arg);
2030 obj->data.ifblock.s = strndup(buf, text_buffer_size);
2032 ERR("if_running needs an argument");
2033 obj->data.ifblock.s = 0;
2039 char box[256], dst[256];
2043 /* Kapil: Changed from MAIL_FILE to
2044 current_mail_spool since the latter
2045 is a copy of the former if undefined
2046 but the latter should take precedence
2048 strncpy(box, current_mail_spool, sizeof(box));
2050 if (sscanf(arg, "%s %f", box, &n1) != 2) {
2052 strncpy(box, arg, sizeof(box));
2056 variable_substitute(box, dst, sizeof(dst));
2057 obj->data.local_mail.box = strndup(dst, text_buffer_size);
2058 obj->data.local_mail.interval = n1;
2059 END OBJ(new_mails, 0)
2061 char box[256], dst[256];
2065 strncpy(box, current_mail_spool, sizeof(box));
2067 if (sscanf(arg, "%s %f", box, &n1) != 2) {
2069 strncpy(box, arg, sizeof(box));
2073 variable_substitute(box, dst, sizeof(dst));
2074 obj->data.local_mail.box = strndup(dst, text_buffer_size);
2075 obj->data.local_mail.interval = n1;
2076 END OBJ(seen_mails, 0)
2078 char box[256], dst[256];
2082 strncpy(box, current_mail_spool, sizeof(box));
2084 if (sscanf(arg, "%s %f", box, &n1) != 2) {
2086 strncpy(box, arg, sizeof(box));
2090 variable_substitute(box, dst, sizeof(dst));
2091 obj->data.local_mail.box = strndup(dst, text_buffer_size);
2092 obj->data.local_mail.interval = n1;
2093 END OBJ(unseen_mails, 0)
2095 char box[256], dst[256];
2099 strncpy(box, current_mail_spool, sizeof(box));
2101 if (sscanf(arg, "%s %f", box, &n1) != 2) {
2103 strncpy(box, arg, sizeof(box));
2107 variable_substitute(box, dst, sizeof(dst));
2108 obj->data.local_mail.box = strndup(dst, text_buffer_size);
2109 obj->data.local_mail.interval = n1;
2110 END OBJ(flagged_mails, 0)
2112 char box[256], dst[256];
2116 strncpy(box, current_mail_spool, sizeof(box));
2118 if (sscanf(arg, "%s %f", box, &n1) != 2) {
2120 strncpy(box, arg, sizeof(box));
2124 variable_substitute(box, dst, sizeof(dst));
2125 obj->data.local_mail.box = strndup(dst, text_buffer_size);
2126 obj->data.local_mail.interval = n1;
2127 END OBJ(unflagged_mails, 0)
2129 char box[256], dst[256];
2133 strncpy(box, current_mail_spool, sizeof(box));
2135 if (sscanf(arg, "%s %f", box, &n1) != 2) {
2137 strncpy(box, arg, sizeof(box));
2141 variable_substitute(box, dst, sizeof(dst));
2142 obj->data.local_mail.box = strndup(dst, text_buffer_size);
2143 obj->data.local_mail.interval = n1;
2144 END OBJ(forwarded_mails, 0)
2146 char box[256], dst[256];
2150 strncpy(box, current_mail_spool, sizeof(box));
2152 if (sscanf(arg, "%s %f", box, &n1) != 2) {
2154 strncpy(box, arg, sizeof(box));
2158 variable_substitute(box, dst, sizeof(dst));
2159 obj->data.local_mail.box = strndup(dst, text_buffer_size);
2160 obj->data.local_mail.interval = n1;
2161 END OBJ(unforwarded_mails, 0)
2163 char box[256], dst[256];
2167 strncpy(box, current_mail_spool, sizeof(box));
2169 if (sscanf(arg, "%s %f", box, &n1) != 2) {
2171 strncpy(box, arg, sizeof(box));
2175 variable_substitute(box, dst, sizeof(dst));
2176 obj->data.local_mail.box = strndup(dst, text_buffer_size);
2177 obj->data.local_mail.interval = n1;
2178 END OBJ(replied_mails, 0)
2180 char box[256], dst[256];
2184 strncpy(box, current_mail_spool, sizeof(box));
2186 if (sscanf(arg, "%s %f", box, &n1) != 2) {
2188 strncpy(box, arg, sizeof(box));
2192 variable_substitute(box, dst, sizeof(dst));
2193 obj->data.local_mail.box = strndup(dst, text_buffer_size);
2194 obj->data.local_mail.interval = n1;
2195 END OBJ(unreplied_mails, 0)
2197 char box[256], dst[256];
2201 strncpy(box, current_mail_spool, sizeof(box));
2203 if (sscanf(arg, "%s %f", box, &n1) != 2) {
2205 strncpy(box, arg, sizeof(box));
2209 variable_substitute(box, dst, sizeof(dst));
2210 obj->data.local_mail.box = strndup(dst, text_buffer_size);
2211 obj->data.local_mail.interval = n1;
2212 END OBJ(draft_mails, 0)
2214 char box[256], dst[256];
2218 strncpy(box, current_mail_spool, sizeof(box));
2220 if (sscanf(arg, "%s %f", box, &n1) != 2) {
2222 strncpy(box, arg, sizeof(box));
2226 variable_substitute(box, dst, sizeof(dst));
2227 obj->data.local_mail.box = strndup(dst, text_buffer_size);
2228 obj->data.local_mail.interval = n1;
2229 END OBJ(trashed_mails, 0)
2231 char box[256], dst[256];
2235 strncpy(box, current_mail_spool, sizeof(box));
2237 if (sscanf(arg, "%s %f", box, &n1) != 2) {
2239 strncpy(box, arg, sizeof(box));
2243 variable_substitute(box, dst, sizeof(dst));
2244 obj->data.local_mail.box = strndup(dst, text_buffer_size);
2245 obj->data.local_mail.interval = n1;
2246 END OBJ(mboxscan, 0)
2247 obj->data.mboxscan.args = (char *) malloc(text_buffer_size);
2248 obj->data.mboxscan.output = (char *) malloc(text_buffer_size);
2249 /* if '1' (in mboxscan.c) then there was SIGUSR1, hmm */
2250 obj->data.mboxscan.output[0] = 1;
2251 strncpy(obj->data.mboxscan.args, arg, text_buffer_size);
2252 END OBJ(mem, INFO_MEM)
2253 END OBJ(memeasyfree, INFO_MEM)
2254 END OBJ(memfree, INFO_MEM)
2255 END OBJ(memmax, INFO_MEM)
2256 END OBJ(memperc, INFO_MEM)
2258 END OBJ(memgauge, INFO_MEM)
2259 SIZE_DEFAULTS(gauge);
2260 scan_gauge(arg, &obj->data.pair.a, &obj->data.pair.b);
2262 END OBJ(membar, INFO_MEM)
2264 scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
2266 END OBJ(memgraph, INFO_MEM)
2268 SIZE_DEFAULTS(graph);
2269 buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
2270 &obj->e, &obj->char_a, &obj->char_b);
2276 END OBJ(mixer, INFO_MIXER)
2277 obj->data.l = mixer_init(arg);
2278 END OBJ(mixerl, INFO_MIXER)
2279 obj->data.l = mixer_init(arg);
2280 END OBJ(mixerr, INFO_MIXER)
2281 obj->data.l = mixer_init(arg);
2283 END OBJ(mixerbar, INFO_MIXER)
2285 scan_mixer_bar(arg, &obj->data.mixerbar.l, &obj->data.mixerbar.w,
2286 &obj->data.mixerbar.h);
2287 END OBJ(mixerlbar, INFO_MIXER)
2289 scan_mixer_bar(arg, &obj->data.mixerbar.l, &obj->data.mixerbar.w,
2290 &obj->data.mixerbar.h);
2291 END OBJ(mixerrbar, INFO_MIXER)
2293 scan_mixer_bar(arg, &obj->data.mixerbar.l, &obj->data.mixerbar.w,
2294 &obj->data.mixerbar.h);
2296 END OBJ_IF(if_mixer_mute, INFO_MIXER)
2297 obj->data.ifblock.i = mixer_init(arg);
2299 END OBJ(monitor, INFO_X11)
2300 END OBJ(monitor_number, INFO_X11)
2302 END OBJ(nodename, 0)
2303 END OBJ(processes, INFO_PROCS)
2304 END OBJ(running_processes, INFO_RUN_PROCS)
2305 END OBJ(shadecolor, 0)
2307 obj->data.l = arg ? get_x11_color(arg) : default_bg_color;
2309 END OBJ(outlinecolor, 0)
2311 obj->data.l = arg ? get_x11_color(arg) : default_out_color;
2313 END OBJ(stippled_hr, 0)
2315 int a = stippled_borders, b = 1;
2318 if (sscanf(arg, "%d %d", &a, &b) != 2) {
2319 sscanf(arg, "%d", &b);
2325 obj->data.pair.a = a;
2326 obj->data.pair.b = b;
2328 END OBJ(swap, INFO_MEM)
2329 END OBJ(swapmax, INFO_MEM)
2330 END OBJ(swapperc, INFO_MEM)
2331 END OBJ(swapbar, INFO_MEM)
2333 scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
2336 obj->data.s = strndup(arg ? arg : "%F %T", text_buffer_size);
2338 obj->data.s = strndup(arg ? arg : "%F %T", text_buffer_size);
2340 char buf1[256], buf2[256], *fmt, *tz;
2344 int nArgs = sscanf(arg, "%255s %255[^\n]", buf1, buf2);
2354 obj->data.tztime.fmt = strndup(fmt ? fmt : "%F %T", text_buffer_size);
2355 obj->data.tztime.tz = tz ? strndup(tz, text_buffer_size) : NULL;
2357 END OBJ(iconv_start, 0)
2358 if (iconv_converting) {
2359 CRIT_ERR("You must stop your last iconv conversion before "
2360 "starting another");
2363 char iconv_from[CODEPAGE_LENGTH];
2364 char iconv_to[CODEPAGE_LENGTH];
2366 if (sscanf(arg, "%s %s", iconv_from, iconv_to) != 2) {
2367 CRIT_ERR("Invalid arguments for iconv_start");
2371 new_iconv = iconv_open(iconv_to, iconv_from);
2372 if (new_iconv == (iconv_t) (-1)) {
2373 ERR("Can't convert from %s to %s.", iconv_from, iconv_to);
2375 obj->a = register_iconv(&new_iconv);
2376 iconv_converting = 1;
2380 CRIT_ERR("Iconv requires arguments");
2382 END OBJ(iconv_stop, 0)
2383 iconv_converting = 0;
2386 END OBJ(totaldown, INFO_NET)
2388 obj->data.net = get_net_stat(arg);
2390 CRIT_ERR("totaldown needs argument");
2392 END OBJ(totalup, INFO_NET)
2393 obj->data.net = get_net_stat(arg);
2395 obj->data.net = get_net_stat(arg);
2397 CRIT_ERR("totalup needs argument");
2400 END OBJ_IF(if_updatenr, 0)
2401 obj->data.ifblock.i = arg ? atoi(arg) : 0;
2402 if(obj->data.ifblock.i == 0) CRIT_ERR("if_updatenr needs a number above 0 as argument");
2403 updatereset = obj->data.ifblock.i > updatereset ? obj->data.ifblock.i : updatereset;
2405 obj->data.i = arg ? atoi(arg) : 0;
2407 obj->data.i = arg ? atoi(arg) : 0;
2408 END OBJ(upspeed, INFO_NET)
2410 obj->data.net = get_net_stat(arg);
2412 CRIT_ERR("upspeed needs argument");
2414 END OBJ(upspeedf, INFO_NET)
2416 obj->data.net = get_net_stat(arg);
2418 CRIT_ERR("upspeedf needs argument");
2422 END OBJ(upspeedgraph, INFO_NET)
2424 SIZE_DEFAULTS(graph);
2425 buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
2426 &obj->e, &obj->char_a, &obj->char_b);
2428 // default to DEFAULTNETDEV
2429 buf = strndup(buf ? buf : "DEFAULTNETDEV", text_buffer_size);
2430 obj->data.net = get_net_stat(buf);
2433 END OBJ(uptime_short, INFO_UPTIME)
2434 END OBJ(uptime, INFO_UPTIME)
2435 END OBJ(user_names, INFO_USERS)
2436 END OBJ(user_times, INFO_USERS)
2437 END OBJ(user_terms, INFO_USERS)
2438 END OBJ(user_number, INFO_USERS)
2439 #if defined(__linux__)
2440 END OBJ(gw_iface, INFO_GW)
2441 END OBJ(gw_ip, INFO_GW)
2442 #endif /* !__linux__ */
2444 END OBJ(adt746xcpu, 0)
2445 END OBJ(adt746xfan, 0)
2446 #endif /* !__OpenBSD__ */
2447 #if (defined(__FreeBSD__) || defined(__FreeBSD_kernel__) \
2448 || defined(__OpenBSD__)) && (defined(i386) || defined(__i386__))
2449 END OBJ(apm_adapter, 0)
2450 END OBJ(apm_battery_life, 0)
2451 END OBJ(apm_battery_time, 0)
2452 #endif /* __FreeBSD__ */
2453 END OBJ_THREAD(imap_unseen, 0)
2456 obj->data.mail = parse_mail_args(IMAP_TYPE, arg);
2461 END OBJ_THREAD(imap_messages, 0)
2464 obj->data.mail = parse_mail_args(IMAP_TYPE, arg);
2469 END OBJ_THREAD(pop3_unseen, 0)
2472 obj->data.mail = parse_mail_args(POP3_TYPE, arg);
2477 END OBJ_THREAD(pop3_used, 0)
2480 obj->data.mail = parse_mail_args(POP3_TYPE, arg);
2488 obj->data.s = strndup(arg, text_buffer_size);
2490 ERR("smapi needs an argument");
2491 END OBJ_IF(if_smapi_bat_installed, 0)
2493 ERR("if_smapi_bat_installed needs an argument");
2494 obj->data.ifblock.s = 0;
2496 obj->data.ifblock.s = strndup(arg, text_buffer_size);
2497 END OBJ(smapi_bat_perc, 0)
2499 obj->data.s = strndup(arg, text_buffer_size);
2501 ERR("smapi_bat_perc needs an argument");
2502 END OBJ(smapi_bat_temp, 0)
2504 obj->data.s = strndup(arg, text_buffer_size);
2506 ERR("smapi_bat_temp needs an argument");
2507 END OBJ(smapi_bat_power, 0)
2509 obj->data.s = strndup(arg, text_buffer_size);
2511 ERR("smapi_bat_power needs an argument");
2512 END OBJ(smapi_bat_bar, 0)
2516 if(sscanf(arg, "%i %n", &obj->data.i, &cnt) <= 0) {
2517 ERR("first argument to smapi_bat_bar must be an integer value");
2521 arg = scan_bar(arg + cnt, &obj->a, &obj->b);
2524 ERR("smapi_bat_bar needs an argument");
2527 #define mpd_set_maxlen(name) \
2530 sscanf(arg, "%d", &i); \
2532 obj->data.i = i + 1; \
2534 ERR(#name ": invalid length argument"); \
2536 END OBJ(mpd_artist, INFO_MPD)
2537 mpd_set_maxlen(mpd_artist);
2539 END OBJ(mpd_title, INFO_MPD)
2540 mpd_set_maxlen(mpd_title);
2542 END OBJ(mpd_random, INFO_MPD) init_mpd();
2543 END OBJ(mpd_repeat, INFO_MPD) init_mpd();
2544 END OBJ(mpd_elapsed, INFO_MPD) init_mpd();
2545 END OBJ(mpd_length, INFO_MPD) init_mpd();
2546 END OBJ(mpd_track, INFO_MPD)
2547 mpd_set_maxlen(mpd_track);
2549 END OBJ(mpd_name, INFO_MPD)
2550 mpd_set_maxlen(mpd_name);
2552 END OBJ(mpd_file, INFO_MPD)
2553 mpd_set_maxlen(mpd_file);
2555 END OBJ(mpd_percent, INFO_MPD) init_mpd();
2556 END OBJ(mpd_album, INFO_MPD)
2557 mpd_set_maxlen(mpd_album);
2559 END OBJ(mpd_vol, INFO_MPD) init_mpd();
2560 END OBJ(mpd_bitrate, INFO_MPD) init_mpd();
2561 END OBJ(mpd_status, INFO_MPD) init_mpd();
2562 END OBJ(mpd_bar, INFO_MPD)
2564 scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
2566 END OBJ(mpd_smart, INFO_MPD)
2567 mpd_set_maxlen(mpd_smart);
2569 END OBJ_IF(if_mpd_playing, INFO_MPD)
2571 #undef mpd_set_maxlen
2574 END OBJ(moc_state, INFO_MOC)
2575 END OBJ(moc_file, INFO_MOC)
2576 END OBJ(moc_title, INFO_MOC)
2577 END OBJ(moc_artist, INFO_MOC)
2578 END OBJ(moc_song, INFO_MOC)
2579 END OBJ(moc_album, INFO_MOC)
2580 END OBJ(moc_totaltime, INFO_MOC)
2581 END OBJ(moc_timeleft, INFO_MOC)
2582 END OBJ(moc_curtime, INFO_MOC)
2583 END OBJ(moc_bitrate, INFO_MOC)
2584 END OBJ(moc_rate, INFO_MOC)
2587 END OBJ(xmms2_artist, INFO_XMMS2)
2588 END OBJ(xmms2_album, INFO_XMMS2)
2589 END OBJ(xmms2_title, INFO_XMMS2)
2590 END OBJ(xmms2_genre, INFO_XMMS2)
2591 END OBJ(xmms2_comment, INFO_XMMS2)
2592 END OBJ(xmms2_url, INFO_XMMS2)
2593 END OBJ(xmms2_tracknr, INFO_XMMS2)
2594 END OBJ(xmms2_bitrate, INFO_XMMS2)
2595 END OBJ(xmms2_date, INFO_XMMS2)
2596 END OBJ(xmms2_id, INFO_XMMS2)
2597 END OBJ(xmms2_duration, INFO_XMMS2)
2598 END OBJ(xmms2_elapsed, INFO_XMMS2)
2599 END OBJ(xmms2_size, INFO_XMMS2)
2600 END OBJ(xmms2_status, INFO_XMMS2)
2601 END OBJ(xmms2_percent, INFO_XMMS2)
2602 END OBJ(xmms2_bar, INFO_XMMS2)
2604 scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
2605 END OBJ(xmms2_smart, INFO_XMMS2)
2606 END OBJ(xmms2_playlist, INFO_XMMS2)
2607 END OBJ(xmms2_timesplayed, INFO_XMMS2)
2608 END OBJ_IF(if_xmms2_connected, INFO_XMMS2)
2611 END OBJ(audacious_status, INFO_AUDACIOUS)
2612 END OBJ(audacious_title, INFO_AUDACIOUS)
2614 sscanf(arg, "%d", &info.audacious.max_title_len);
2615 if (info.audacious.max_title_len > 0) {
2616 info.audacious.max_title_len++;
2618 CRIT_ERR("audacious_title: invalid length argument");
2621 END OBJ(audacious_length, INFO_AUDACIOUS)
2622 END OBJ(audacious_length_seconds, INFO_AUDACIOUS)
2623 END OBJ(audacious_position, INFO_AUDACIOUS)
2624 END OBJ(audacious_position_seconds, INFO_AUDACIOUS)
2625 END OBJ(audacious_bitrate, INFO_AUDACIOUS)
2626 END OBJ(audacious_frequency, INFO_AUDACIOUS)
2627 END OBJ(audacious_channels, INFO_AUDACIOUS)
2628 END OBJ(audacious_filename, INFO_AUDACIOUS)
2629 END OBJ(audacious_playlist_length, INFO_AUDACIOUS)
2630 END OBJ(audacious_playlist_position, INFO_AUDACIOUS)
2631 END OBJ(audacious_main_volume, INFO_AUDACIOUS)
2632 END OBJ(audacious_bar, INFO_AUDACIOUS)
2634 scan_bar(arg, &obj->a, &obj->b);
2637 END OBJ(bmpx_title, INFO_BMPX)
2638 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
2639 END OBJ(bmpx_artist, INFO_BMPX)
2640 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
2641 END OBJ(bmpx_album, INFO_BMPX)
2642 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
2643 END OBJ(bmpx_track, INFO_BMPX)
2644 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
2645 END OBJ(bmpx_uri, INFO_BMPX)
2646 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
2647 END OBJ(bmpx_bitrate, INFO_BMPX)
2648 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
2654 char *userid = (char *) malloc(20 * sizeof(char));
2655 char *apikey = (char *) malloc(64 * sizeof(char));
2656 char *charid = (char *) malloc(20 * sizeof(char));
2658 argc = sscanf(arg, "%20s %64s %20s", userid, apikey, charid);
2659 obj->data.eve.charid = charid;
2660 obj->data.eve.userid = userid;
2661 obj->data.eve.apikey = apikey;
2665 CRIT_ERR("eve needs arguments: <userid> <apikey> <characterid>");
2671 int argc, delay, act_par;
2672 unsigned int nrspaces = 0;
2673 char *uri = (char *) malloc(128 * sizeof(char));
2674 char *action = (char *) malloc(64 * sizeof(char));
2676 argc = sscanf(arg, "%127s %d %63s %d %u", uri, &delay, action,
2677 &act_par, &nrspaces);
2678 obj->data.rss.uri = uri;
2679 obj->data.rss.delay = delay;
2680 obj->data.rss.action = action;
2681 obj->data.rss.act_par = act_par;
2682 obj->data.rss.nrspaces = nrspaces;
2686 CRIT_ERR("rss needs arguments: <uri> <delay in minutes> <action> "
2687 "[act_par] [spaces in front]");
2693 obj->data.s = strndup(arg, text_buffer_size);
2695 CRIT_ERR("lua needs arguments: <function name> [function parameters]");
2697 END OBJ(lua_parse, 0)
2699 obj->data.s = strndup(arg, text_buffer_size);
2701 CRIT_ERR("lua_parse needs arguments: <function name> [function parameters]");
2703 END OBJ(lua_read_parse, 0)
2705 obj->data.s = strndup(arg, text_buffer_size);
2707 CRIT_ERR("lua_read_parse needs arguments: <function name> <string to pass>");
2712 arg = scan_bar(arg, &obj->a, &obj->b);
2714 obj->data.s = strndup(arg, text_buffer_size);
2716 CRIT_ERR("lua_bar needs arguments: <height>,<width> <function name> [function parameters]");
2719 CRIT_ERR("lua_bar needs arguments: <height>,<width> <function name> [function parameters]");
2722 END OBJ(lua_graph, 0)
2723 SIZE_DEFAULTS(graph);
2725 arg = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
2726 &obj->e, &obj->char_a, &obj->char_b);
2728 obj->data.s = strndup(arg, text_buffer_size);
2730 CRIT_ERR("lua_graph needs arguments: <\"normal\"|\"log\"> <height>,<width> <gradient colour 1> <gradient colour 2> <scale> <function name> [function parameters]");
2733 CRIT_ERR("lua_graph needs arguments: <\"normal\"|\"log\"> <height>,<width> <gradient colour 1> <gradient colour 2> <scale> <function name> [function parameters]");
2735 END OBJ(lua_gauge, 0)
2736 SIZE_DEFAULTS(gauge);
2738 arg = scan_gauge(arg, &obj->a, &obj->b);
2740 obj->data.s = strndup(arg, text_buffer_size);
2742 CRIT_ERR("lua_gauge needs arguments: <height>,<width> <function name> [function parameters]");
2745 CRIT_ERR("lua_gauge needs arguments: <height>,<width> <function name> [function parameters]");
2748 #endif /* HAVE_LUA */
2751 if (scan_hddtemp(arg, &obj->data.hddtemp.dev,
2752 &obj->data.hddtemp.addr, &obj->data.hddtemp.port)) {
2753 ERR("hddtemp needs arguments");
2754 obj->type = OBJ_text;
2755 obj->data.s = strndup("${hddtemp}", text_buffer_size);
2756 obj->data.hddtemp.update_time = 0;
2758 obj->data.hddtemp.temp = NULL;
2759 #endif /* HDDTEMP */
2760 #ifdef TCP_PORT_MONITOR
2761 END OBJ(tcp_portmon, INFO_TCP_PORT_MONITOR)
2762 tcp_portmon_init(arg, &obj->data.tcp_port_monitor);
2763 #endif /* TCP_PORT_MONITOR */
2764 END OBJ(entropy_avail, INFO_ENTROPY)
2765 END OBJ(entropy_perc, INFO_ENTROPY)
2766 END OBJ(entropy_poolsize, INFO_ENTROPY)
2767 END OBJ(entropy_bar, INFO_ENTROPY)
2769 scan_bar(arg, &obj->a, &obj->b);
2773 obj->data.scroll.step = 1;
2774 if (arg && sscanf(arg, "%u %n", &obj->data.scroll.show, &n1) > 0) {
2775 if (sscanf(arg + n1, "%u %n", &obj->data.scroll.step, &n2) > 0)
2777 obj->data.scroll.text = strndup(arg + n1, text_buffer_size);
2778 obj->data.scroll.start = 0;
2779 obj->sub = malloc(sizeof(struct text_object));
2780 extract_variable_text_internal(obj->sub,
2781 obj->data.scroll.text, 0);
2783 CRIT_ERR("scroll needs arguments: <length> [<step>] <text>");
2788 unsigned int indenting = 0; //vars can be used as args for other vars
2791 startvar[0] = endvar[0] = startvar[1] = endvar[1] = -1;
2793 for (i=0; arg[i] != 0 && j < 2; i++) {
2794 if(startvar[j] == -1) {
2798 }else if(endvar[j] == -1) {
2801 }else if(arg[i] == '}') {
2804 if (indenting == 0 && arg[i+1] < 48) { //<48 has 0, $, and the most used chars not used in varnames but not { or }
2810 if(startvar[0] >= 0 && endvar[0] >= 0 && startvar[1] >= 0 && endvar[1] >= 0) {
2811 obj->data.combine.left = malloc(endvar[0]-startvar[0] + 1);
2812 obj->data.combine.seperation = malloc(startvar[1] - endvar[0] + 1);
2813 obj->data.combine.right= malloc(endvar[1]-startvar[1] + 1);
2815 strncpy(obj->data.combine.left, arg + startvar[0], endvar[0] - startvar[0]);
2816 obj->data.combine.left[endvar[0] - startvar[0]] = 0;
2818 strncpy(obj->data.combine.seperation, arg + endvar[0], startvar[1] - endvar[0]);
2819 obj->data.combine.seperation[startvar[1] - endvar[0]] = 0;
2821 strncpy(obj->data.combine.right, arg + startvar[1], endvar[1] - startvar[1]);
2822 obj->data.combine.right[endvar[1] - startvar[1]] = 0;
2824 obj->sub = malloc(sizeof(struct text_object));
2825 extract_variable_text_internal(obj->sub, obj->data.combine.left, 0);
2826 obj->sub->sub = malloc(sizeof(struct text_object));
2827 extract_variable_text_internal(obj->sub->sub, obj->data.combine.right, 0);
2829 CRIT_ERR("combine needs arguments: <text1> <text2>");
2832 CRIT_ERR("combine needs arguments: <text1> <text2>");
2837 CRIT_ERR("nvidia needs an argument\n");
2838 } else if (set_nvidia_type(&obj->data.nvidia, arg)) {
2839 CRIT_ERR("nvidia: invalid argument"
2840 " specified: '%s'\n", arg);
2845 END OBJ(apcupsd, INFO_APCUPSD)
2849 if (sscanf(arg, "%63s %d", host, &port) != 2) {
2850 CRIT_ERR("apcupsd needs arguments: <host> <port>");
2852 info.apcupsd.port = htons(port);
2853 strncpy(info.apcupsd.host, host, sizeof(info.apcupsd.host));
2856 CRIT_ERR("apcupsd needs arguments: <host> <port>");
2858 END OBJ(apcupsd_name, INFO_APCUPSD)
2859 END OBJ(apcupsd_model, INFO_APCUPSD)
2860 END OBJ(apcupsd_upsmode, INFO_APCUPSD)
2861 END OBJ(apcupsd_cable, INFO_APCUPSD)
2862 END OBJ(apcupsd_status, INFO_APCUPSD)
2863 END OBJ(apcupsd_linev, INFO_APCUPSD)
2864 END OBJ(apcupsd_load, INFO_APCUPSD)
2865 END OBJ(apcupsd_loadbar, INFO_APCUPSD)
2867 scan_bar(arg, &obj->a, &obj->b);
2869 END OBJ(apcupsd_loadgraph, INFO_APCUPSD)
2871 SIZE_DEFAULTS(graph);
2872 buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
2873 &obj->e, &obj->char_a, &obj->char_b);
2875 END OBJ(apcupsd_loadgauge, INFO_APCUPSD)
2876 SIZE_DEFAULTS(gauge);
2877 scan_gauge(arg, &obj->a, &obj->b);
2879 END OBJ(apcupsd_charge, INFO_APCUPSD)
2880 END OBJ(apcupsd_timeleft, INFO_APCUPSD)
2881 END OBJ(apcupsd_temp, INFO_APCUPSD)
2882 END OBJ(apcupsd_lastxfer, INFO_APCUPSD)
2883 #endif /* APCUPSD */
2887 ERR("unknown variable %s", s);
2888 obj->type = OBJ_text;
2889 snprintf(buf, 256, "${%s}", s);
2890 obj->data.s = strndup(buf, text_buffer_size);
2897 static struct text_object *create_plain_text(const char *s)
2899 struct text_object *obj;
2901 if (s == NULL || *s == '\0') {
2905 obj = new_text_object_internal();
2907 obj->type = OBJ_text;
2908 obj->data.s = strndup(s, text_buffer_size);
2912 /* backslash_escape - do the actual substitution task for template objects
2914 * The field templates is used for substituting the \N occurences. Set it to
2915 * NULL to leave them as they are.
2917 static char *backslash_escape(const char *src, char **templates, unsigned int template_count)
2921 unsigned int dup_idx = 0, dup_len;
2923 dup_len = strlen(src) + 1;
2924 src_dup = malloc(dup_len * sizeof(char));
2932 if (*(p + 1) == '\\') {
2933 src_dup[dup_idx++] = '\\';
2935 } else if (*(p + 1) == ' ') {
2936 src_dup[dup_idx++] = ' ';
2938 } else if (*(p + 1) == 'n') {
2939 src_dup[dup_idx++] = '\n';
2941 } else if (templates) {
2942 unsigned int tmpl_num;
2944 if ((sscanf(p + 1, "%u%n", &tmpl_num, &digits) <= 0) ||
2945 (tmpl_num > template_count))
2947 dup_len += strlen(templates[tmpl_num - 1]);
2948 src_dup = realloc(src_dup, dup_len * sizeof(char));
2949 sprintf(src_dup + dup_idx, "%s", templates[tmpl_num - 1]);
2950 dup_idx += strlen(templates[tmpl_num - 1]);
2955 src_dup[dup_idx++] = *p;
2960 src_dup[dup_idx] = '\0';
2961 src_dup = realloc(src_dup, (strlen(src_dup) + 1) * sizeof(char));
2965 /* handle_template_object - core logic of the template object
2967 * use config variables like this:
2968 * template1 = "$\1\2"
2969 * template2 = "\1: ${fs_bar 4,100 \2} ${fs_used \2} / ${fs_size \2}"
2971 * and use them like this:
2972 * ${template1 node name}
2973 * ${template2 root /}
2974 * ${template2 cdrom /mnt/cdrom}
2976 static char *handle_template(const char *tmpl, const char *args)
2978 char *args_dup = NULL;
2980 char **argsp = NULL;
2981 unsigned int argcnt = 0, template_idx, i;
2984 if ((sscanf(tmpl, "template%u", &template_idx) != 1) ||
2985 (template_idx >= MAX_TEMPLATES))
2989 args_dup = strdup(args);
2992 while (*p && (*p == ' ' && (p == args_dup || *(p - 1) != '\\')))
2994 if (p > args_dup && *(p - 1) == '\\')
2997 while (*p && (*p != ' ' || (p > args_dup && *(p - 1) == '\\')))
3003 argsp = realloc(argsp, ++argcnt * sizeof(char *));
3004 argsp[argcnt - 1] = p_old;
3006 for (i = 0; i < argcnt; i++) {
3008 tmp = backslash_escape(argsp[i], NULL, 0);
3009 DBGP2("%s: substituted arg '%s' to '%s'", tmpl, argsp[i], tmp);
3014 eval_text = backslash_escape(template[template_idx], argsp, argcnt);
3015 DBGP("substituted %s, output is '%s'", tmpl, eval_text);
3017 for (i = 0; i < argcnt; i++)
3023 static char *find_and_replace_templates(const char *inbuf)
3025 char *outbuf, *indup, *p, *o, *templ, *args, *tmpl_out;
3028 outlen = strlen(inbuf) + 1;
3029 o = outbuf = calloc(outlen, sizeof(char));
3030 memset(outbuf, 0, outlen * sizeof(char));
3032 p = indup = strdup(inbuf);
3034 while (*p && *p != '$')
3040 if (strncmp(p, "$template", 9) && strncmp(p, "${template", 10)) {
3045 if (*(p + 1) == '{') {
3048 while (*p && !isspace(*p) && *p != '{' && *p != '}')
3056 while (*p && stack > 0) {
3064 // stack is empty. that means the previous char was }, so we zero it
3067 // we ran into the end of string without finding a closing }, bark
3068 CRIT_ERR("cannot find a closing '}' in template expansion");
3072 while (*p && !isspace(*p))
3076 tmpl_out = handle_template(templ, args);
3078 outlen += strlen(tmpl_out);
3080 outbuf = realloc(outbuf, outlen * sizeof(char));
3081 strcat (outbuf, tmpl_out);
3083 o = outbuf + strlen(outbuf);
3085 ERR("failed to handle template '%s' with args '%s'", templ, args);
3089 outbuf = realloc(outbuf, (strlen(outbuf) + 1) * sizeof(char));
3094 static int text_contains_templates(const char *text)
3096 if (strcasestr(text, "${template") != NULL)
3098 if (strcasestr(text, "$template") != NULL)
3103 static void strfold(char *start, int count)
3106 for (curplace = start + count; *curplace != 0; curplace++) {
3107 *(curplace - count) = *curplace;
3109 *(curplace - count - 1) = 0;
3112 static size_t remove_comments(char *string)
3114 char *curplace, *curplace2;
3116 for (curplace = string; *curplace != 0; curplace++) {
3117 if (*curplace == '\\' && *(curplace + 1) == '#') {
3118 // strcpy can't be used for overlapping strings
3119 strfold(curplace, 1);
3121 } else if (*curplace == '#') {
3122 // remove everything until we hit a '\n'
3123 curplace2 = curplace;
3124 while (*curplace2) {
3126 if (*curplace2 == '\n' &&
3127 *(curplace2 + 1) != '#') break;
3130 strfold(curplace, curplace2 - curplace);
3131 folded += curplace2 - curplace;
3140 static int extract_variable_text_internal(struct text_object *retval, const char *const_p, char allow_threaded)
3142 struct text_object *obj;
3143 char *p, *s, *orig_p;
3145 void *ifblock_opaque = NULL;
3150 p = strndup(const_p, max_user_text - 1);
3151 while (text_contains_templates(p)) {
3153 tmp = find_and_replace_templates(p);
3159 if (strcmp(p, const_p)) {
3160 DBGP("replaced all templates in text: input is\n'%s'\noutput is\n'%s'", const_p, p);
3162 DBGP("no templates to replace");
3165 memset(retval, 0, sizeof(struct text_object));
3167 line = global_text_lines;
3175 obj = create_plain_text(s);
3177 append_object(retval, obj);
3187 /* variable is either $foo or ${foo} */
3189 unsigned int brl = 1, brr = 0;
3193 while (*p && brl != brr) {
3208 while (*p && (isalnum((int) *p) || *p == '_')) {
3213 /* copy variable to buffer */
3214 len = (p - s > 255) ? 255 : (p - s);
3215 strncpy(buf, s, len);
3223 /* search for variable in environment */
3227 obj = create_plain_text(var);
3229 append_object(retval, obj);
3234 /* if variable wasn't found in environment, use some special */
3239 if (strchr(buf, ' ')) {
3240 arg = strchr(buf, ' ');
3243 while (isspace((int) *arg)) {
3251 /* lowercase variable name */
3254 *tmp_p = tolower(*tmp_p);
3258 obj = construct_text_object(buf, arg,
3259 line, allow_threaded,
3262 append_object(retval, obj);
3266 obj = create_plain_text("$");
3269 append_object(retval, obj);
3272 } else if (*p == '#') {
3278 obj = create_plain_text(s);
3280 append_object(retval, obj);
3283 if (!ifblock_stack_empty(&ifblock_opaque)) {
3284 ERR("one or more $endif's are missing");
3291 static void extract_variable_text(const char *p)
3293 free_text_objects(&global_root_object, 0);
3307 extract_variable_text_internal(&global_root_object, p, 1);
3310 int parse_conky_vars(struct text_object *root, char *txt, char *p, struct information *cur)
3312 extract_variable_text_internal(root, txt, 0);
3313 generate_text_internal(p, max_user_text, *root, cur);
3317 static inline struct mail_s *ensure_mail_thread(struct text_object *obj,
3318 void *thread(void *), const char *text)
3320 if (obj->char_b && info.mail) {
3321 // this means we use info
3322 if (!info.mail->p_timed_thread) {
3323 info.mail->p_timed_thread =
3324 timed_thread_create(thread,
3325 (void *) info.mail, info.mail->interval * 1000000);
3326 if (!info.mail->p_timed_thread) {
3327 ERR("Error creating %s timed thread", text);
3329 timed_thread_register(info.mail->p_timed_thread,
3330 &info.mail->p_timed_thread);
3331 if (timed_thread_run(info.mail->p_timed_thread)) {
3332 ERR("Error running %s timed thread", text);
3336 } else if (obj->data.mail) {
3337 // this means we use obj
3338 if (!obj->data.mail->p_timed_thread) {
3339 obj->data.mail->p_timed_thread =
3340 timed_thread_create(thread,
3341 (void *) obj->data.mail,
3342 obj->data.mail->interval * 1000000);
3343 if (!obj->data.mail->p_timed_thread) {
3344 ERR("Error creating %s timed thread", text);
3346 timed_thread_register(obj->data.mail->p_timed_thread,
3347 &obj->data.mail->p_timed_thread);
3348 if (timed_thread_run(obj->data.mail->p_timed_thread)) {
3349 ERR("Error running %s timed thread", text);
3352 return obj->data.mail;
3353 } else if (!obj->a) {
3354 // something is wrong, warn once then stop
3355 ERR("There's a problem with your mail settings. "
3356 "Check that the global mail settings are properly defined"
3357 " (line %li).", obj->line);
3363 char *format_time(unsigned long timeval, const int width)
3366 unsigned long nt; // narrow time, for speed on 32-bit
3367 unsigned cc; // centiseconds
3368 unsigned nn; // multi-purpose whatever
3371 cc = nt % 100; // centiseconds past second
3372 nt /= 100; // total seconds
3373 nn = nt % 60; // seconds past the minute
3374 nt /= 60; // total minutes
3375 if (width >= snprintf(buf, sizeof buf, "%lu:%02u.%02u",
3377 return strndup(buf, text_buffer_size);
3379 if (width >= snprintf(buf, sizeof buf, "%lu:%02u", nt, nn)) {
3380 return strndup(buf, text_buffer_size);
3382 nn = nt % 60; // minutes past the hour
3383 nt /= 60; // total hours
3384 if (width >= snprintf(buf, sizeof buf, "%lu,%02u", nt, nn)) {
3385 return strndup(buf, text_buffer_size);
3387 nn = nt; // now also hours
3388 if (width >= snprintf(buf, sizeof buf, "%uh", nn)) {
3389 return strndup(buf, text_buffer_size);
3391 nn /= 24; // now days
3392 if (width >= snprintf(buf, sizeof buf, "%ud", nn)) {
3393 return strndup(buf, text_buffer_size);
3395 nn /= 7; // now weeks
3396 if (width >= snprintf(buf, sizeof buf, "%uw", nn)) {
3397 return strndup(buf, text_buffer_size);
3399 // well shoot, this outta' fit...
3400 return strndup("<inf>", text_buffer_size);
3403 //remove backspaced chars, example: "dog^H^H^Hcat" becomes "cat"
3404 //string has to end with \0 and it's length should fit in a int
3406 void remove_deleted_chars(char *string){
3408 while(string[i] != 0){
3409 if(string[i] == BACKSPACE){
3411 strcpy( &(string[i-1]), &(string[i+1]) );
3413 }else strcpy( &(string[i]), &(string[i+1]) ); //necessary for ^H's at the start of a string
3418 static inline void format_media_player_time(char *buf, const int size,
3421 int days, hours, minutes;
3423 days = seconds / (24 * 60 * 60);
3424 seconds %= (24 * 60 * 60);
3425 hours = seconds / (60 * 60);
3426 seconds %= (60 * 60);
3427 minutes = seconds / 60;
3431 snprintf(buf, size, "%i days %i:%02i:%02i", days,
3432 hours, minutes, seconds);
3433 } else if (hours > 0) {
3434 snprintf(buf, size, "%i:%02i:%02i", hours, minutes,
3437 snprintf(buf, size, "%i:%02i", minutes, seconds);
3441 static inline double get_barnum(char *buf)
3453 if (sscanf(buf, "%lf", &barnum) == 0) {
3454 ERR("reading exec value failed (perhaps it's not the "
3455 "correct format?)");
3458 if (barnum > 100.0 || barnum < 0.0) {
3459 ERR("your exec value is not between 0 and 100, "
3460 "therefore it will be ignored");
3466 static void generate_text_internal(char *p, int p_max_size,
3467 struct text_object root, struct information *cur)
3469 struct text_object *obj;
3471 /* for the OBJ_top* handler */
3472 struct process **needed = 0;
3475 char buff_in[p_max_size];
3477 iconv_converting = 0;
3482 while (obj && p_max_size > 0) {
3483 needed = 0; // reset for top stuff
3485 /* IFBLOCK jumping algorithm
3487 * This is easier as it looks like:
3488 * - each IF checks it's condition
3489 * - on FALSE: call DO_JUMP
3490 * - on TRUE: don't care
3491 * - each ELSE calls DO_JUMP unconditionally
3492 * - each ENDIF is silently being ignored
3495 * DO_JUMP overwrites the "obj" variable of the loop and sets it to the target
3496 * (i.e. the corresponding ELSE or ENDIF). After that, processing for the given
3497 * object can continue, free()ing stuff e.g., then the for-loop does the rest: as
3498 * regularly, "obj" is being updated to point to obj->next, so object parsing
3499 * continues right after the corresponding ELSE or ENDIF. This means that if we
3500 * find an ELSE, it's corresponding IF must not have jumped, so we need to jump
3501 * always. If we encounter an ENDIF, it's corresponding IF or ELSE has not
3502 * jumped, and there is nothing to do.
3506 obj = obj->data.ifblock.next; \
3509 #define OBJ(a) break; case OBJ_##a:
3511 switch (obj->type) {
3513 ERR("not implemented obj type %d", obj->type);
3516 struct sockaddr_in addr;
3517 struct hostent* he = gethostbyname(obj->data.read_tcp.host);
3519 sock = socket(he->h_addrtype, SOCK_STREAM, 0);
3521 memset(&addr, 0, sizeof(addr));
3522 addr.sin_family = AF_INET;
3523 addr.sin_port = obj->data.read_tcp.port;
3524 memcpy(&addr.sin_addr, he->h_addr, he->h_length);
3525 if (connect(sock, (struct sockaddr*)&addr, sizeof(struct sockaddr)) == 0) {
3529 FD_SET(sock, &readfds);
3532 if(select(sock + 1, &readfds, NULL, NULL, &tv) > 0){
3533 received = recv(sock, p, p_max_size, 0);
3538 ERR("read_tcp: Couldn't create a connection");
3541 ERR("read_tcp: Couldn't create a socket");
3544 ERR("read_tcp: Problem with resolving the hostname");
3549 temp_print(p, p_max_size, get_acpi_temperature(obj->data.i), TEMP_CELSIUS);
3551 #endif /* !__OpenBSD__ */
3554 obj->a = get_freq(p, p_max_size, "%.0f", 1,
3555 obj->data.cpu_index);
3561 obj->a = get_freq(p, p_max_size, "%'.2f", 1000,
3562 obj->data.cpu_index);
3564 /* OpenBSD has no such flag (SUSv2) */
3565 obj->a = get_freq(p, p_max_size, "%.2f", 1000,
3566 obj->data.cpu_index);
3570 #if defined(__linux__)
3573 obj->a = get_voltage(p, p_max_size, "%.0f", 1,
3574 obj->data.cpu_index);
3579 obj->a = get_voltage(p, p_max_size, "%'.3f", 1000,
3580 obj->data.cpu_index);
3585 OBJ(wireless_essid) {
3586 snprintf(p, p_max_size, "%s", obj->data.net->essid);
3588 OBJ(wireless_mode) {
3589 snprintf(p, p_max_size, "%s", obj->data.net->mode);
3591 OBJ(wireless_bitrate) {
3592 snprintf(p, p_max_size, "%s", obj->data.net->bitrate);
3595 snprintf(p, p_max_size, "%s", obj->data.net->ap);
3597 OBJ(wireless_link_qual) {
3598 spaced_print(p, p_max_size, "%d", 4,
3599 obj->data.net->link_qual);
3601 OBJ(wireless_link_qual_max) {
3602 spaced_print(p, p_max_size, "%d", 4,
3603 obj->data.net->link_qual_max);
3605 OBJ(wireless_link_qual_perc) {
3606 if (obj->data.net->link_qual_max > 0) {
3607 spaced_print(p, p_max_size, "%.0f", 5,
3608 (double) obj->data.net->link_qual /
3609 obj->data.net->link_qual_max * 100);
3611 spaced_print(p, p_max_size, "unk", 5);
3614 OBJ(wireless_link_bar) {
3615 new_bar(p, obj->a, obj->b, ((double) obj->data.net->link_qual /
3616 obj->data.net->link_qual_max) * 255.0);
3618 #endif /* HAVE_IWLIB */
3620 #endif /* __linux__ */
3624 get_adt746x_cpu(p, p_max_size);
3627 get_adt746x_fan(p, p_max_size);
3630 get_acpi_fan(p, p_max_size);
3632 OBJ(acpiacadapter) {
3633 get_acpi_ac_adapter(p, p_max_size);
3636 get_battery_stuff(p, p_max_size, obj->data.s, BATTERY_STATUS);
3639 get_battery_stuff(p, p_max_size, obj->data.s, BATTERY_TIME);
3641 OBJ(battery_percent) {
3642 percent_print(p, p_max_size, get_battery_perct(obj->data.s));
3646 if(output_methods & TO_X) {
3647 new_bar(p, obj->a, obj->b, get_battery_perct_bar(obj->data.s));
3650 if(!obj->a) obj->a = DEFAULT_BAR_WIDTH_NO_X;
3651 new_bar_in_shell(p, p_max_size, get_battery_perct_bar(obj->data.s) / 2.55, obj->a);
3656 OBJ(battery_short) {
3657 get_battery_short_status(p, p_max_size, obj->data.s);
3659 #endif /* __OpenBSD__ */
3662 human_readable(cur->buffers * 1024, p, 255);
3665 human_readable(cur->cached * 1024, p, 255);
3668 if (obj->data.cpu_index > info.cpu_count) {
3669 ERR("obj->data.cpu_index %i info.cpu_count %i",
3670 obj->data.cpu_index, info.cpu_count);
3671 CRIT_ERR("attempting to use more CPUs than you have!");
3673 percent_print(p, p_max_size,
3674 round_to_int(cur->cpu_usage[obj->data.cpu_index] * 100.0));
3678 new_gauge(p, obj->a, obj->b,
3679 round_to_int(cur->cpu_usage[obj->data.cpu_index] * 255.0));
3683 if(output_methods & TO_X) {
3684 new_bar(p, obj->a, obj->b,
3685 round_to_int(cur->cpu_usage[obj->data.cpu_index] * 255.0));
3688 if(!obj->a) obj->a = DEFAULT_BAR_WIDTH_NO_X;
3689 new_bar_in_shell(p, p_max_size, round_to_int(cur->cpu_usage[obj->data.cpu_index] * 100), obj->a);
3696 new_graph(p, obj->a, obj->b, obj->c, obj->d,
3697 round_to_int(cur->cpu_usage[obj->data.cpu_index] * 100),
3698 100, 1, obj->char_a, obj->char_b);
3701 new_graph(p, obj->a, obj->b, obj->c, obj->d, cur->loadavg[0],
3702 obj->e, 1, obj->char_a, obj->char_b);
3705 new_fg(p, obj->data.l);
3738 OBJ(conky_version) {
3739 snprintf(p, p_max_size, "%s", VERSION);
3741 OBJ(conky_build_date) {
3742 snprintf(p, p_max_size, "%s", BUILD_DATE);
3744 OBJ(conky_build_arch) {
3745 snprintf(p, p_max_size, "%s", BUILD_ARCH);
3747 #if defined(__linux__)
3749 snprintf(p, p_max_size, "%s",
3750 get_disk_protect_queue(obj->data.s));
3753 snprintf(p, p_max_size, "%s", i8k.version);
3756 snprintf(p, p_max_size, "%s", i8k.bios);
3759 snprintf(p, p_max_size, "%s", i8k.serial);
3764 sscanf(i8k.cpu_temp, "%d", &cpu_temp);
3765 temp_print(p, p_max_size, (double)cpu_temp, TEMP_CELSIUS);
3767 OBJ(i8k_left_fan_status) {
3768 int left_fan_status;
3770 sscanf(i8k.left_fan_status, "%d", &left_fan_status);
3771 if (left_fan_status == 0) {
3772 snprintf(p, p_max_size, "off");
3774 if (left_fan_status == 1) {
3775 snprintf(p, p_max_size, "low");
3777 if (left_fan_status == 2) {
3778 snprintf(p, p_max_size, "high");
3781 OBJ(i8k_right_fan_status) {
3782 int right_fan_status;
3784 sscanf(i8k.right_fan_status, "%d", &right_fan_status);
3785 if (right_fan_status == 0) {
3786 snprintf(p, p_max_size, "off");
3788 if (right_fan_status == 1) {
3789 snprintf(p, p_max_size, "low");
3791 if (right_fan_status == 2) {
3792 snprintf(p, p_max_size, "high");
3795 OBJ(i8k_left_fan_rpm) {
3796 snprintf(p, p_max_size, "%s", i8k.left_fan_rpm);
3798 OBJ(i8k_right_fan_rpm) {
3799 snprintf(p, p_max_size, "%s", i8k.right_fan_rpm);
3801 OBJ(i8k_ac_status) {
3804 sscanf(i8k.ac_status, "%d", &ac_status);
3805 if (ac_status == -1) {
3806 snprintf(p, p_max_size, "disabled (read i8k docs)");
3808 if (ac_status == 0) {
3809 snprintf(p, p_max_size, "off");
3811 if (ac_status == 1) {
3812 snprintf(p, p_max_size, "on");
3815 OBJ(i8k_buttons_status) {
3816 snprintf(p, p_max_size, "%s", i8k.buttons_status);
3820 get_ibm_acpi_fan(p, p_max_size);
3823 get_ibm_acpi_temps();
3824 temp_print(p, p_max_size,
3825 ibm_acpi.temps[obj->data.sensor], TEMP_CELSIUS);
3828 get_ibm_acpi_volume(p, p_max_size);
3830 OBJ(ibm_brightness) {
3831 get_ibm_acpi_brightness(p, p_max_size);
3834 /* information from sony_laptop kernel module
3835 * /sys/devices/platform/sony-laptop */
3836 OBJ(sony_fanspeed) {
3837 get_sony_fanspeed(p, p_max_size);
3840 if (!cur->gw_info.count) {
3845 snprintf(p, p_max_size, "%s", cur->gw_info.iface);
3848 snprintf(p, p_max_size, "%s", cur->gw_info.ip);
3851 snprintf(p, p_max_size, "%d", get_laptop_mode());
3854 get_powerbook_batt_info(p, p_max_size, obj->data.i);
3856 #endif /* __linux__ */
3857 #if (defined(__FreeBSD__) || defined(__linux__))
3859 if ((obj->data.ifblock.s)
3860 && (!interface_up(obj->data.ifblock.s))) {
3866 OBJ(obsd_sensors_temp) {
3867 obsd_sensors.device = sensor_device;
3868 update_obsd_sensors();
3869 temp_print(p, p_max_size,
3870 obsd_sensors.temp[obsd_sensors.device][obj->data.sensor],
3873 OBJ(obsd_sensors_fan) {
3874 obsd_sensors.device = sensor_device;
3875 update_obsd_sensors();
3876 snprintf(p, p_max_size, "%d",
3877 obsd_sensors.fan[obsd_sensors.device][obj->data.sensor]);
3879 OBJ(obsd_sensors_volt) {
3880 obsd_sensors.device = sensor_device;
3881 update_obsd_sensors();
3882 snprintf(p, p_max_size, "%.2f",
3883 obsd_sensors.volt[obsd_sensors.device][obj->data.sensor]);
3886 get_obsd_vendor(p, p_max_size);
3889 get_obsd_product(p, p_max_size);
3891 #endif /* __OpenBSD__ */
3894 new_font(p, obj->data.s);
3897 /* TODO: move this correction from kB to kB/s elsewhere
3898 * (or get rid of it??) */
3900 human_readable((obj->data.diskio->current / update_interval) * 1024LL,
3904 human_readable((obj->data.diskio->current_write / update_interval) * 1024LL,
3908 human_readable((obj->data.diskio->current_read / update_interval) * 1024LL,
3913 new_graph(p, obj->a, obj->b, obj->c, obj->d,
3914 obj->data.diskio->current, obj->e, 1, obj->char_a, obj->char_b);
3916 OBJ(diskiograph_read) {
3917 new_graph(p, obj->a, obj->b, obj->c, obj->d,
3918 obj->data.diskio->current_read, obj->e, 1, obj->char_a, obj->char_b);
3920 OBJ(diskiograph_write) {
3921 new_graph(p, obj->a, obj->b, obj->c, obj->d,
3922 obj->data.diskio->current_write, obj->e, 1, obj->char_a, obj->char_b);
3926 human_readable(obj->data.net->recv_speed, p, 255);
3929 spaced_print(p, p_max_size, "%.1f", 8,
3930 obj->data.net->recv_speed / 1024.0);
3933 OBJ(downspeedgraph) {
3934 new_graph(p, obj->a, obj->b, obj->c, obj->d,
3935 obj->data.net->recv_speed / 1024.0, obj->e, 1, obj->char_a, obj->char_b);
3939 /* Since we see you, you're if has not jumped.
3940 * Do Ninja jump here: without leaving traces.
3941 * This is to prevent us from stale jumped flags.
3943 obj = obj->data.ifblock.next;
3947 /* harmless object, just ignore */
3951 if ((obj->data.net->addr.sa_data[2] & 255) == 0
3952 && (obj->data.net->addr.sa_data[3] & 255) == 0
3953 && (obj->data.net->addr.sa_data[4] & 255) == 0
3954 && (obj->data.net->addr.sa_data[5] & 255) == 0) {
3955 snprintf(p, p_max_size, "No Address");
3957 snprintf(p, p_max_size, "%u.%u.%u.%u",
3958 obj->data.net->addr.sa_data[2] & 255,
3959 obj->data.net->addr.sa_data[3] & 255,
3960 obj->data.net->addr.sa_data[4] & 255,
3961 obj->data.net->addr.sa_data[5] & 255);
3964 #if defined(__linux__)
3966 if(NULL != obj->data.net->addrs && strlen(obj->data.net->addrs) > 2)
3968 obj->data.net->addrs[strlen(obj->data.net->addrs) - 2] = 0; /* remove ", " from end of string */
3969 strcpy(p, obj->data.net->addrs);
3972 strcpy(p, "0.0.0.0");
3974 #endif /* __linux__ */
3975 #if defined(IMLIB2) && defined(X11)
3977 /* doesn't actually draw anything, just queues it omp. the
3978 * image will get drawn after the X event loop */
3979 cimlib_add_image(obj->data.s);
3983 struct information *tmp_info;
3984 struct text_object subroot, subroot2;
3986 tmp_info = malloc(sizeof(struct information));
3987 memcpy(tmp_info, cur, sizeof(struct information));
3988 parse_conky_vars(&subroot, obj->data.s, p, tmp_info);
3989 DBGP("evaluated '%s' to '%s'", obj->data.s, p);
3990 parse_conky_vars(&subroot2, p, p, tmp_info);
3992 free_text_objects(&subroot, 1);
3993 free_text_objects(&subroot2, 1);
3997 read_exec(obj->data.s, p, text_buffer_size);
3998 remove_deleted_chars(p);
4001 struct information *tmp_info;
4002 struct text_object subroot;
4004 read_exec(obj->data.s, p, text_buffer_size);
4006 tmp_info = malloc(sizeof(struct information));
4007 memcpy(tmp_info, cur, sizeof(struct information));
4008 parse_conky_vars(&subroot, p, p, tmp_info);
4010 free_text_objects(&subroot, 1);
4017 read_exec(obj->data.s, p, text_buffer_size);
4018 barnum = get_barnum(p); /*using the same function*/
4020 if (barnum >= 0.0) {
4022 new_gauge(p, obj->a, obj->b, round_to_int(barnum * 255.0));
4029 read_exec(obj->data.s, p, text_buffer_size);
4030 barnum = get_barnum(p);
4032 if (barnum >= 0.0) {
4034 if(output_methods & TO_X) {
4036 new_bar(p, obj->a, obj->b, round_to_int(barnum * 255.0));
4039 if(!obj->a) obj->a = DEFAULT_BAR_WIDTH_NO_X;
4040 new_bar_in_shell(p, p_max_size, barnum, obj->a);
4048 char showaslog = FALSE;
4049 char tempgrad = FALSE;
4051 char *cmd = obj->data.s;
4053 if (strncasecmp(obj->data.execi.cmd, LOGGRAPH" ", strlen(LOGGRAPH" ")) == EQUAL) {
4055 cmd = cmd + strlen(LOGGRAPH" ") * sizeof(char);
4056 } else if(strncasecmp(obj->data.s, NORMGRAPH" ", strlen(NORMGRAPH" ")) == EQUAL) {
4057 cmd = cmd + strlen(NORMGRAPH" ") * sizeof(char);
4059 if (strstr(cmd, " "TEMPGRAD) && strlen(cmd) > strlen(" "TEMPGRAD)) {
4061 cmd += strlen(" "TEMPGRAD);
4063 read_exec(cmd, p, text_buffer_size);
4064 barnum = get_barnum(p);
4066 if (barnum >= 0.0) {
4067 new_graph(p, obj->a, obj->b, obj->c, obj->d, round_to_int(barnum),
4068 100, 1, showaslog, tempgrad);
4073 if (current_update_time - obj->data.execi.last_update
4074 >= obj->data.execi.interval) {
4077 read_exec(obj->data.execi.cmd, p, text_buffer_size);
4078 barnum = get_barnum(p);
4080 if (barnum >= 0.0) {
4083 obj->data.execi.last_update = current_update_time;
4086 if(output_methods & TO_X) {
4087 new_bar(p, obj->a, obj->b, round_to_int(obj->f * 2.55));
4090 if(!obj->a) obj->a = DEFAULT_BAR_WIDTH_NO_X;
4091 new_bar_in_shell(p, p_max_size, round_to_int(obj->f), obj->a);
4098 if (current_update_time - obj->data.execi.last_update
4099 >= obj->data.execi.interval) {
4101 char showaslog = FALSE;
4102 char tempgrad = FALSE;
4103 char *cmd = obj->data.execi.cmd;
4105 if (strncasecmp(obj->data.execi.cmd, LOGGRAPH" ", strlen(LOGGRAPH" ")) == EQUAL) {
4107 cmd = cmd + strlen(LOGGRAPH" ") * sizeof(char);
4108 } else if(strncasecmp(obj->data.s, NORMGRAPH" ", strlen(NORMGRAPH" ")) == EQUAL) {
4109 cmd = cmd + strlen(NORMGRAPH" ") * sizeof(char);
4111 if (strstr(cmd, " "TEMPGRAD) && strlen(cmd) > strlen(" "TEMPGRAD)) {
4113 cmd += strlen(" "TEMPGRAD);
4115 obj->char_a = showaslog;
4116 obj->char_b = tempgrad;
4117 read_exec(cmd, p, text_buffer_size);
4118 barnum = get_barnum(p);
4120 if (barnum >= 0.0) {
4123 obj->data.execi.last_update = current_update_time;
4125 new_graph(p, obj->a, obj->b, obj->c, obj->d, (int) (obj->f), 100, 1, obj->char_a, obj->char_b);
4128 if (current_update_time - obj->data.execi.last_update
4129 >= obj->data.execi.interval) {
4132 read_exec(obj->data.execi.cmd, p, text_buffer_size);
4133 barnum = get_barnum(p);
4135 if (barnum >= 0.0) {
4136 obj->f = 255 * barnum / 100.0;
4138 obj->data.execi.last_update = current_update_time;
4140 new_gauge(p, obj->a, obj->b, round_to_int(obj->f));
4144 if (current_update_time - obj->data.execi.last_update
4145 >= obj->data.execi.interval
4146 && obj->data.execi.interval != 0) {
4147 read_exec(obj->data.execi.cmd, obj->data.execi.buffer,
4149 obj->data.execi.last_update = current_update_time;
4151 snprintf(p, text_buffer_size, "%s", obj->data.execi.buffer);
4154 struct text_object subroot;
4155 struct information *tmp_info =
4156 malloc(sizeof(struct information));
4157 memcpy(tmp_info, cur, sizeof(struct information));
4159 if (current_update_time - obj->data.execi.last_update
4160 < obj->data.execi.interval
4161 || obj->data.execi.interval == 0) {
4162 parse_conky_vars(&subroot, obj->data.execi.buffer, p, tmp_info);
4164 char *output = obj->data.execi.buffer;
4165 FILE *fp = popen(obj->data.execi.cmd, "r");
4166 int length = fread(output, 1, text_buffer_size, fp);
4170 output[length] = '\0';
4171 if (length > 0 && output[length - 1] == '\n') {
4172 output[length - 1] = '\0';
4175 parse_conky_vars(&subroot, obj->data.execi.buffer, p, tmp_info);
4176 obj->data.execi.last_update = current_update_time;
4178 free_text_objects(&subroot, 1);
4182 if (!obj->data.texeci.p_timed_thread) {
4183 obj->data.texeci.p_timed_thread =
4184 timed_thread_create(&threaded_exec,
4185 (void *) obj, obj->data.texeci.interval * 1000000);
4186 if (!obj->data.texeci.p_timed_thread) {
4187 ERR("Error creating texeci timed thread");
4189 timed_thread_register(obj->data.texeci.p_timed_thread,
4190 &obj->data.texeci.p_timed_thread);
4191 if (timed_thread_run(obj->data.texeci.p_timed_thread)) {
4192 ERR("Error running texeci timed thread");
4195 timed_thread_lock(obj->data.texeci.p_timed_thread);
4196 snprintf(p, text_buffer_size, "%s", obj->data.texeci.buffer);
4197 timed_thread_unlock(obj->data.texeci.p_timed_thread);
4200 #endif /* HAVE_POPEN */
4202 struct mail_s *mail = ensure_mail_thread(obj, imap_thread, "imap");
4204 if (mail && mail->p_timed_thread) {
4205 timed_thread_lock(mail->p_timed_thread);
4206 snprintf(p, p_max_size, "%lu", mail->unseen);
4207 timed_thread_unlock(mail->p_timed_thread);
4210 OBJ(imap_messages) {
4211 struct mail_s *mail = ensure_mail_thread(obj, imap_thread, "imap");
4213 if (mail && mail->p_timed_thread) {
4214 timed_thread_lock(mail->p_timed_thread);
4215 snprintf(p, p_max_size, "%lu", mail->messages);
4216 timed_thread_unlock(mail->p_timed_thread);
4220 struct mail_s *mail = ensure_mail_thread(obj, pop3_thread, "pop3");
4222 if (mail && mail->p_timed_thread) {
4223 timed_thread_lock(mail->p_timed_thread);
4224 snprintf(p, p_max_size, "%lu", mail->unseen);
4225 timed_thread_unlock(mail->p_timed_thread);
4229 struct mail_s *mail = ensure_mail_thread(obj, pop3_thread, "pop3");
4231 if (mail && mail->p_timed_thread) {
4232 timed_thread_lock(mail->p_timed_thread);
4233 snprintf(p, p_max_size, "%.1f",
4234 mail->used / 1024.0 / 1024.0);
4235 timed_thread_unlock(mail->p_timed_thread);
4239 if (obj->data.fs != NULL) {
4240 if (obj->data.fs->size == 0) {
4242 if(output_methods & TO_X) {
4243 new_bar(p, obj->data.fsbar.w, obj->data.fsbar.h, 255);
4246 if(!obj->data.fsbar.w) obj->data.fsbar.w = DEFAULT_BAR_WIDTH_NO_X;
4247 new_bar_in_shell(p, p_max_size, 100, obj->data.fsbar.w);
4253 if(output_methods & TO_X) {
4254 new_bar(p, obj->data.fsbar.w, obj->data.fsbar.h,
4255 (int) (255 - obj->data.fsbar.fs->avail * 255 /
4256 obj->data.fs->size));
4259 if(!obj->data.fsbar.w) obj->data.fsbar.w = DEFAULT_BAR_WIDTH_NO_X;
4260 new_bar_in_shell(p, p_max_size,
4261 (int) (100 - obj->data.fsbar.fs->avail * 100 / obj->data.fs->size), obj->data.fsbar.w);
4269 if (obj->data.fs != NULL) {
4270 human_readable( (obj->data.fs->free ? obj->data.fs->free :
4271 obj->data.fs->avail), p, 255);
4275 if (obj->data.fs != NULL) {
4278 if (obj->data.fs->size) {
4279 val = (obj->data.fs->free ? obj->data.fs->free :
4280 obj->data.fs->avail) * 100 /
4284 percent_print(p, p_max_size, val);
4288 if (obj->data.fs != NULL) {
4289 human_readable(obj->data.fs->size, p, 255);
4293 if (obj->data.fs != NULL)
4294 snprintf(p, p_max_size, "%s", obj->data.fs->type);
4297 if (obj->data.fs != NULL) {
4298 human_readable(obj->data.fs->size - (obj->data.fs->free
4299 ? obj->data.fs->free : obj->data.fs->avail), p, 255);
4303 if (obj->data.fs != NULL) {
4304 if (obj->data.fs->size == 0) {
4306 if(output_methods & TO_X) {
4307 new_bar(p, obj->data.fsbar.w, obj->data.fsbar.h, 255);
4310 if(!obj->data.fsbar.w) obj->data.fsbar.w = DEFAULT_BAR_WIDTH_NO_X;
4311 new_bar_in_shell(p, p_max_size, 100, obj->data.fsbar.w);
4317 if(output_methods & TO_X) {
4318 new_bar(p, obj->data.fsbar.w, obj->data.fsbar.h,
4319 (int) (obj->data.fsbar.fs->avail * 255 /
4320 obj->data.fs->size));
4323 if(!obj->data.fsbar.w) obj->data.fsbar.w = DEFAULT_BAR_WIDTH_NO_X;
4324 new_bar_in_shell(p, p_max_size,
4325 (int) (obj->data.fsbar.fs->avail * 100 / obj->data.fs->size), obj->data.fsbar.w);
4333 if (obj->data.fs != NULL) {
4336 if (obj->data.fs->size) {
4337 val = (obj->data.fs->free ? obj->data.fs->free :
4338 obj->data.fs->avail) * 100 /
4342 percent_print(p, p_max_size, 100 - val);
4346 float *v = info.loadavg;
4348 if (obj->data.loadavg[2]) {
4349 snprintf(p, p_max_size, "%.2f %.2f %.2f",
4350 v[obj->data.loadavg[0] - 1],
4351 v[obj->data.loadavg[1] - 1],
4352 v[obj->data.loadavg[2] - 1]);
4353 } else if (obj->data.loadavg[1]) {
4354 snprintf(p, p_max_size, "%.2f %.2f",
4355 v[obj->data.loadavg[0] - 1],
4356 v[obj->data.loadavg[1] - 1]);
4357 } else if (obj->data.loadavg[0]) {
4358 snprintf(p, p_max_size, "%.2f",
4359 v[obj->data.loadavg[0] - 1]);
4363 new_goto(p, obj->data.i);
4366 new_tab(p, obj->data.pair.a, obj->data.pair.b);
4370 new_hr(p, obj->data.i);
4374 if (cur->nameserver_info.nscount > obj->data.i)
4375 snprintf(p, p_max_size, "%s",
4376 cur->nameserver_info.ns_list[obj->data.i]);
4380 char *skill = eve(obj->data.eve.userid, obj->data.eve.apikey, obj->data.eve.charid);
4381 snprintf(p, p_max_size, "%s", skill);
4386 PRSS *data = get_rss_info(obj->data.rss.uri,
4387 obj->data.rss.delay);
4391 snprintf(p, p_max_size, "prss: Error reading RSS data\n");
4393 if (strcmp(obj->data.rss.action, "feed_title") == EQUAL) {
4395 // remove trailing new line if one exists
4396 if (str[strlen(str) - 1] == '\n') {
4397 str[strlen(str) - 1] = 0;
4399 snprintf(p, p_max_size, "%s", str);
4400 } else if (strcmp(obj->data.rss.action, "item_title") == EQUAL) {
4401 if (obj->data.rss.act_par < data->item_count) {
4402 str = data->items[obj->data.rss.act_par].title;
4403 // remove trailing new line if one exists
4404 if (str[strlen(str) - 1] == '\n') {
4405 str[strlen(str) - 1] = 0;
4407 snprintf(p, p_max_size, "%s", str);
4409 } else if (strcmp(obj->data.rss.action, "item_desc") == EQUAL) {
4410 if (obj->data.rss.act_par < data->item_count) {
4412 data->items[obj->data.rss.act_par].description;
4413 // remove trailing new line if one exists
4414 if (str[strlen(str) - 1] == '\n') {
4415 str[strlen(str) - 1] = 0;
4417 snprintf(p, p_max_size, "%s", str);
4419 } else if (strcmp(obj->data.rss.action, "item_titles") == EQUAL) {
4420 if (data->item_count > 0) {
4423 //'tmpspaces' is a string with spaces too be placed in front of each title
4424 char *tmpspaces = malloc(obj->data.rss.nrspaces + 1);
4425 memset(tmpspaces, ' ', obj->data.rss.nrspaces);
4426 tmpspaces[obj->data.rss.nrspaces]=0;
4430 if (obj->data.rss.act_par > data->item_count) {
4431 show = data->item_count;
4433 show = obj->data.rss.act_par;
4435 for (itmp = 0; itmp < show; itmp++) {
4436 PRSS_Item *item = &data->items[itmp];
4440 // don't add new line before first item
4442 strncat(p, "\n", p_max_size);
4444 /* remove trailing new line if one exists,
4445 * we have our own */
4446 if (str[strlen(str) - 1] == '\n') {
4447 str[strlen(str) - 1] = 0;
4449 strncat(p, tmpspaces, p_max_size);
4450 strncat(p, str, p_max_size);
4461 char *str = llua_getstring(obj->data.s);
4463 snprintf(p, p_max_size, "%s", str);
4468 char *str = llua_getstring(obj->data.s);
4470 struct information *tmp_info;
4471 struct text_object subroot;
4473 tmp_info = malloc(sizeof(struct information));
4474 memcpy(tmp_info, cur, sizeof(struct information));
4475 parse_conky_vars(&subroot, str, p, tmp_info);
4477 free_text_objects(&subroot, 1);
4482 OBJ(lua_read_parse) {
4483 struct information *tmp_info;
4484 struct text_object subroot, subroot2;
4487 sscanf(obj->data.s, "%64s", func);
4488 text = obj->data.s + strlen(func) + 1;
4490 tmp_info = malloc(sizeof(struct information));
4491 memcpy(tmp_info, cur, sizeof(struct information));
4492 parse_conky_vars(&subroot, text, p, tmp_info);
4493 DBGP("evaluated '%s' to '%s'", text, p);
4495 str = llua_getstring_read(func, p);
4497 parse_conky_vars(&subroot2, str, p, tmp_info);
4498 DBGP("evaluated '%s' to '%s'", str, p);
4501 free_text_objects(&subroot2, 1);
4503 free_text_objects(&subroot, 1);
4508 if (llua_getinteger(obj->data.s, &per)) {
4510 if(output_methods & TO_X) {
4511 new_bar(p, obj->a, obj->b, (per/100.0 * 255));
4514 if(!obj->a) obj->a = DEFAULT_BAR_WIDTH_NO_X;
4515 new_bar_in_shell(p, p_max_size, per, obj->a);
4524 if (llua_getinteger(obj->data.s, &per)) {
4525 new_graph(p, obj->a, obj->b, obj->c, obj->d,
4526 (per/100.0 * 255), 100, 1, obj->char_a, obj->char_b);
4531 if (llua_getinteger(obj->data.s, &per)) {
4532 new_gauge(p, obj->a, obj->b, (per/100.0 * 255));
4536 #endif /* HAVE_LUA */
4541 if (obj->data.hddtemp.update_time < current_update_time - 30) {
4542 if (obj->data.hddtemp.temp)
4543 free(obj->data.hddtemp.temp);
4544 obj->data.hddtemp.temp = get_hddtemp_info(obj->data.hddtemp.dev,
4545 obj->data.hddtemp.addr, obj->data.hddtemp.port);
4546 obj->data.hddtemp.update_time = current_update_time;
4548 if (!obj->data.hddtemp.temp) {
4549 snprintf(p, p_max_size, "N/A");
4551 val = strtol(obj->data.hddtemp.temp + 1, &endptr, 10);
4552 unit = obj->data.hddtemp.temp[0];
4554 if (*endptr != '\0')
4555 snprintf(p, p_max_size, "N/A");
4556 else if (unit == 'C')
4557 temp_print(p, p_max_size, (double)val, TEMP_CELSIUS);
4558 else if (unit == 'F')
4559 temp_print(p, p_max_size, (double)val, TEMP_FAHRENHEIT);
4561 snprintf(p, p_max_size, "N/A");
4566 new_offset(p, obj->data.i);
4569 new_voffset(p, obj->data.i);
4575 r = get_sysfs_info(&obj->data.sysfs.fd, obj->data.sysfs.arg,
4576 obj->data.sysfs.devtype, obj->data.sysfs.type);
4578 r = r * obj->data.sysfs.factor + obj->data.sysfs.offset;
4580 if (!strncmp(obj->data.sysfs.type, "temp", 4)) {
4581 temp_print(p, p_max_size, r, TEMP_CELSIUS);
4582 } else if (r >= 100.0 || r == 0) {
4583 snprintf(p, p_max_size, "%d", (int) r);
4585 snprintf(p, p_max_size, "%.1f", r);
4591 r = get_sysfs_info(&obj->data.sysfs.fd, obj->data.sysfs.arg,
4592 obj->data.sysfs.devtype, obj->data.sysfs.type);
4594 r = r * obj->data.sysfs.factor + obj->data.sysfs.offset;
4596 if (!strncmp(obj->data.sysfs.type, "temp", 4)) {
4597 temp_print(p, p_max_size, r, TEMP_CELSIUS);
4598 } else if (r >= 100.0 || r == 0) {
4599 snprintf(p, p_max_size, "%d", (int) r);
4601 snprintf(p, p_max_size, "%.1f", r);
4607 r = get_sysfs_info(&obj->data.sysfs.fd, obj->data.sysfs.arg,
4608 obj->data.sysfs.devtype, obj->data.sysfs.type);
4610 r = r * obj->data.sysfs.factor + obj->data.sysfs.offset;
4612 if (!strncmp(obj->data.sysfs.type, "temp", 4)) {
4613 temp_print(p, p_max_size, r, TEMP_CELSIUS);
4614 } else if (r >= 100.0 || r == 0) {
4615 snprintf(p, p_max_size, "%d", (int) r);
4617 snprintf(p, p_max_size, "%.1f", r);
4620 #endif /* __linux__ */
4622 new_alignr(p, obj->data.i);
4625 new_alignc(p, obj->data.i);
4628 char buf[max_user_text];
4629 struct information *tmp_info =
4630 malloc(sizeof(struct information));
4631 memcpy(tmp_info, cur, sizeof(struct information));
4632 generate_text_internal(buf, max_user_text,
4633 *obj->sub, tmp_info);
4635 if (strlen(buf) != 0) {
4641 char expression[max_user_text];
4643 struct information *tmp_info;
4645 tmp_info = malloc(sizeof(struct information));
4646 memcpy(tmp_info, cur, sizeof(struct information));
4647 generate_text_internal(expression, max_user_text,
4648 *obj->sub, tmp_info);
4649 DBGP("parsed arg into '%s'", expression);
4651 val = compare(expression);
4653 ERR("compare failed for expression '%s'",
4661 if (obj->data.ifblock.str
4662 && !check_contains(obj->data.ifblock.s,
4663 obj->data.ifblock.str)) {
4665 } else if (obj->data.ifblock.s
4666 && access(obj->data.ifblock.s, F_OK)) {
4671 if ((obj->data.ifblock.s)
4672 && (!check_mount(obj->data.ifblock.s))) {
4677 if ((obj->data.ifblock.s) && system(obj->data.ifblock.s)) {
4681 #if defined(__linux__)
4683 snprintf(p, p_max_size, "%s", get_ioscheduler(obj->data.s));
4687 snprintf(p, p_max_size, "%s", cur->uname_s.release);
4690 snprintf(p, p_max_size, "%s", cur->uname_s.machine);
4695 human_readable(cur->mem * 1024, p, 255);
4698 human_readable(cur->memeasyfree * 1024, p, 255);
4701 human_readable(cur->memfree * 1024, p, 255);
4704 human_readable(cur->memmax * 1024, p, 255);
4708 percent_print(p, p_max_size, cur->mem * 100 / cur->memmax);
4712 new_gauge(p, obj->data.pair.a, obj->data.pair.b,
4713 cur->memmax ? (cur->mem * 255) / (cur->memmax) : 0);
4718 if(output_methods & TO_X) {
4719 new_bar(p, obj->data.pair.a, obj->data.pair.b,
4720 cur->memmax ? (cur->mem * 255) / (cur->memmax) : 0);
4723 if(!obj->data.pair.a) obj->data.pair.a = DEFAULT_BAR_WIDTH_NO_X;
4724 new_bar_in_shell(p, p_max_size, cur->memmax ? (cur->mem * 100) / (cur->memmax) : 0, obj->data.pair.a);
4731 new_graph(p, obj->a, obj->b, obj->c, obj->d,
4732 cur->memmax ? (cur->mem * 100.0) / (cur->memmax) : 0.0,
4733 100, 1, obj->char_a, obj->char_b);
4738 percent_print(p, p_max_size, mixer_get_avg(obj->data.l));
4741 percent_print(p, p_max_size, mixer_get_left(obj->data.l));
4744 percent_print(p, p_max_size, mixer_get_right(obj->data.l));
4748 new_bar(p, obj->data.mixerbar.w, obj->data.mixerbar.h,
4749 mixer_to_255(obj->data.mixerbar.l,mixer_get_avg(obj->data.mixerbar.l)));
4752 new_bar(p, obj->data.mixerbar.w, obj->data.mixerbar.h,
4753 mixer_to_255(obj->data.mixerbar.l,mixer_get_left(obj->data.mixerbar.l)));
4756 new_bar(p, obj->data.mixerbar.w, obj->data.mixerbar.h,
4757 mixer_to_255(obj->data.mixerbar.l,mixer_get_right(obj->data.mixerbar.l)));
4760 OBJ(if_mixer_mute) {
4761 if (!mixer_is_mute(obj->data.ifblock.i)) {
4767 snprintf(p, p_max_size, "%d", cur->x11.monitor.current);
4769 OBJ(monitor_number) {
4770 snprintf(p, p_max_size, "%d", cur->x11.monitor.number);
4776 update_mail_count(&obj->data.local_mail);
4777 snprintf(p, p_max_size, "%d", obj->data.local_mail.mail_count);
4780 update_mail_count(&obj->data.local_mail);
4781 snprintf(p, p_max_size, "%d",
4782 obj->data.local_mail.new_mail_count);
4785 update_mail_count(&obj->data.local_mail);
4786 snprintf(p, p_max_size, "%d",
4787 obj->data.local_mail.seen_mail_count);
4790 update_mail_count(&obj->data.local_mail);
4791 snprintf(p, p_max_size, "%d",
4792 obj->data.local_mail.unseen_mail_count);
4794 OBJ(flagged_mails) {
4795 update_mail_count(&obj->data.local_mail);
4796 snprintf(p, p_max_size, "%d",
4797 obj->data.local_mail.flagged_mail_count);
4799 OBJ(unflagged_mails) {
4800 update_mail_count(&obj->data.local_mail);
4801 snprintf(p, p_max_size, "%d",
4802 obj->data.local_mail.unflagged_mail_count);
4804 OBJ(forwarded_mails) {
4805 update_mail_count(&obj->data.local_mail);
4806 snprintf(p, p_max_size, "%d",
4807 obj->data.local_mail.forwarded_mail_count);
4809 OBJ(unforwarded_mails) {
4810 update_mail_count(&obj->data.local_mail);
4811 snprintf(p, p_max_size, "%d",
4812 obj->data.local_mail.unforwarded_mail_count);
4814 OBJ(replied_mails) {
4815 update_mail_count(&obj->data.local_mail);
4816 snprintf(p, p_max_size, "%d",
4817 obj->data.local_mail.replied_mail_count);
4819 OBJ(unreplied_mails) {
4820 update_mail_count(&obj->data.local_mail);
4821 snprintf(p, p_max_size, "%d",
4822 obj->data.local_mail.unreplied_mail_count);
4825 update_mail_count(&obj->data.local_mail);
4826 snprintf(p, p_max_size, "%d",
4827 obj->data.local_mail.draft_mail_count);
4829 OBJ(trashed_mails) {
4830 update_mail_count(&obj->data.local_mail);
4831 snprintf(p, p_max_size, "%d",
4832 obj->data.local_mail.trashed_mail_count);
4835 mbox_scan(obj->data.mboxscan.args, obj->data.mboxscan.output,
4837 snprintf(p, p_max_size, "%s", obj->data.mboxscan.output);
4840 snprintf(p, p_max_size, "%s", cur->uname_s.nodename);
4843 new_outline(p, obj->data.l);
4846 spaced_print(p, p_max_size, "%hu", 4, cur->procs);
4848 OBJ(running_processes) {
4849 spaced_print(p, p_max_size, "%hu", 4, cur->run_procs);
4852 snprintf(p, p_max_size, "%s", obj->data.s);
4856 new_bg(p, obj->data.l);
4859 new_stippled_hr(p, obj->data.pair.a, obj->data.pair.b);
4863 human_readable(cur->swap * 1024, p, 255);
4866 human_readable(cur->swapmax * 1024, p, 255);
4869 if (cur->swapmax == 0) {
4870 strncpy(p, "No swap", p_max_size);
4872 percent_print(p, p_max_size, cur->swap * 100 / cur->swapmax);
4877 if(output_methods & TO_X) {
4878 new_bar(p, obj->data.pair.a, obj->data.pair.b,
4879 cur->swapmax ? (cur->swap * 255) / (cur->swapmax) : 0);
4882 if(!obj->data.pair.a) obj->data.pair.a = DEFAULT_BAR_WIDTH_NO_X;
4883 new_bar_in_shell(p, p_max_size, cur->swapmax ? (cur->swap * 100) / (cur->swapmax) : 0, obj->data.pair.a);
4889 snprintf(p, p_max_size, "%s", cur->uname_s.sysname);
4892 time_t t = time(NULL);
4893 struct tm *tm = localtime(&t);
4895 setlocale(LC_TIME, "");
4896 strftime(p, p_max_size, obj->data.s, tm);
4899 time_t t = time(NULL);
4900 struct tm *tm = gmtime(&t);
4902 strftime(p, p_max_size, obj->data.s, tm);
4909 if (obj->data.tztime.tz) {
4910 oldTZ = getenv("TZ");
4911 setenv("TZ", obj->data.tztime.tz, 1);
4917 setlocale(LC_TIME, "");
4918 strftime(p, p_max_size, obj->data.tztime.fmt, tm);
4920 setenv("TZ", oldTZ, 1);
4925 // Needless to free oldTZ since getenv gives ptr to static data
4928 human_readable(obj->data.net->recv, p, 255);
4931 human_readable(obj->data.net->trans, p, 255);
4934 snprintf(p, p_max_size, "%d", total_updates);
4937 if(total_updates % updatereset != obj->data.ifblock.i - 1) {
4942 human_readable(obj->data.net->trans_speed, p, 255);
4945 spaced_print(p, p_max_size, "%.1f", 8,
4946 obj->data.net->trans_speed / 1024.0);
4950 new_graph(p, obj->a, obj->b, obj->c, obj->d,
4951 obj->data.net->trans_speed / 1024.0, obj->e, 1, obj->char_a, obj->char_b);
4955 format_seconds_short(p, p_max_size, (int) cur->uptime);
4958 format_seconds(p, p_max_size, (int) cur->uptime);
4961 snprintf(p, p_max_size, "%s", cur->users.names);
4964 snprintf(p, p_max_size, "%s", cur->users.terms);
4967 snprintf(p, p_max_size, "%s", cur->users.times);
4970 snprintf(p, p_max_size, "%d", cur->users.number);
4972 #if (defined(__FreeBSD__) || defined(__FreeBSD_kernel__) \
4973 || defined(__OpenBSD__)) && (defined(i386) || defined(__i386__))
4977 msg = get_apm_adapter();
4978 snprintf(p, p_max_size, "%s", msg);
4981 OBJ(apm_battery_life) {
4984 msg = get_apm_battery_life();
4985 snprintf(p, p_max_size, "%s", msg);
4988 OBJ(apm_battery_time) {
4991 msg = get_apm_battery_time();
4992 snprintf(p, p_max_size, "%s", msg);
4995 #endif /* __FreeBSD__ __OpenBSD__ */
4998 #define mpd_printf(fmt, val) \
4999 snprintf(p, p_max_size, fmt, mpd_get_info()->val)
5000 #define mpd_sprintf(val) { \
5001 if (!obj->data.i || obj->data.i > p_max_size) \
5002 mpd_printf("%s", val); \
5004 snprintf(p, obj->data.i, "%s", mpd_get_info()->val); \
5009 mpd_sprintf(artist);
5013 mpd_printf("%s", random);
5015 mpd_printf("%s", repeat);
5023 mpd_printf("%d", volume);
5025 mpd_printf("%d", bitrate);
5027 mpd_printf("%s", status);
5029 format_media_player_time(p, p_max_size, mpd_get_info()->elapsed);
5032 format_media_player_time(p, p_max_size, mpd_get_info()->length);
5035 percent_print(p, p_max_size, (int)(mpd_get_info()->progress * 100));
5039 if(output_methods & TO_X) {
5040 new_bar(p, obj->data.pair.a, obj->data.pair.b,
5041 (int) (mpd_get_info()->progress * 255.0f));
5044 if(!obj->data.pair.a) obj->data.pair.a = DEFAULT_BAR_WIDTH_NO_X;
5045 new_bar_in_shell(p, p_max_size, (int) (mpd_get_info()->progress * 100.0f), obj->data.pair.a);
5051 struct mpd_s *mpd = mpd_get_info();
5052 int len = obj->data.i;
5053 if (len == 0 || len > p_max_size)
5056 memset(p, 0, p_max_size);
5057 if (mpd->artist && *mpd->artist &&
5058 mpd->title && *mpd->title) {
5059 snprintf(p, len, "%s - %s", mpd->artist,
5061 } else if (mpd->title && *mpd->title) {
5062 snprintf(p, len, "%s", mpd->title);
5063 } else if (mpd->artist && *mpd->artist) {
5064 snprintf(p, len, "%s", mpd->artist);
5065 } else if (mpd->file && *mpd->file) {
5066 snprintf(p, len, "%s", mpd->file);
5071 OBJ(if_mpd_playing) {
5072 if (!mpd_get_info()->is_playing) {
5085 #define MOC_PRINT(t, a) \
5086 snprintf(p, p_max_size, "%s", (moc.t ? moc.t : a))
5088 MOC_PRINT(state, "??");
5091 MOC_PRINT(file, "no file");
5094 MOC_PRINT(title, "no title");
5097 MOC_PRINT(artist, "no artist");
5100 MOC_PRINT(song, "no song");
5103 MOC_PRINT(album, "no album");
5105 OBJ(moc_totaltime) {
5106 MOC_PRINT(totaltime, "0:00");
5109 MOC_PRINT(timeleft, "0:00");
5112 MOC_PRINT(curtime, "0:00");
5115 MOC_PRINT(bitrate, "0Kbps");
5118 MOC_PRINT(rate, "0KHz");
5124 snprintf(p, p_max_size, "%s", cur->xmms2.artist);
5127 snprintf(p, p_max_size, "%s", cur->xmms2.album);
5130 snprintf(p, p_max_size, "%s", cur->xmms2.title);
5133 snprintf(p, p_max_size, "%s", cur->xmms2.genre);
5135 OBJ(xmms2_comment) {
5136 snprintf(p, p_max_size, "%s", cur->xmms2.comment);
5139 snprintf(p, p_max_size, "%s", cur->xmms2.url);
5142 snprintf(p, p_max_size, "%s", cur->xmms2.status);
5145 snprintf(p, p_max_size, "%s", cur->xmms2.date);
5147 OBJ(xmms2_tracknr) {
5148 if (cur->xmms2.tracknr != -1) {
5149 snprintf(p, p_max_size, "%i", cur->xmms2.tracknr);
5152 OBJ(xmms2_bitrate) {
5153 snprintf(p, p_max_size, "%i", cur->xmms2.bitrate);
5156 snprintf(p, p_max_size, "%u", cur->xmms2.id);
5159 snprintf(p, p_max_size, "%2.1f", cur->xmms2.size);
5161 OBJ(xmms2_elapsed) {
5162 snprintf(p, p_max_size, "%02d:%02d", cur->xmms2.elapsed / 60000,
5163 (cur->xmms2.elapsed / 1000) % 60);
5165 OBJ(xmms2_duration) {
5166 snprintf(p, p_max_size, "%02d:%02d",
5167 cur->xmms2.duration / 60000,
5168 (cur->xmms2.duration / 1000) % 60);
5170 OBJ(xmms2_percent) {
5171 snprintf(p, p_max_size, "%2.0f", cur->xmms2.progress * 100);
5174 new_bar(p, obj->data.pair.a, obj->data.pair.b,
5175 (int) (cur->xmms2.progress * 255.0f));
5177 OBJ(xmms2_playlist) {
5178 snprintf(p, p_max_size, "%s", cur->xmms2.playlist);
5180 OBJ(xmms2_timesplayed) {
5181 snprintf(p, p_max_size, "%i", cur->xmms2.timesplayed);
5184 if (strlen(cur->xmms2.title) < 2
5185 && strlen(cur->xmms2.title) < 2) {
5186 snprintf(p, p_max_size, "%s", cur->xmms2.url);
5188 snprintf(p, p_max_size, "%s - %s", cur->xmms2.artist,
5192 OBJ(if_xmms2_connected) {
5193 if (cur->xmms2.conn_state != 1) {
5199 OBJ(audacious_status) {
5200 snprintf(p, p_max_size, "%s",
5201 cur->audacious.items[AUDACIOUS_STATUS]);
5203 OBJ(audacious_title) {
5204 snprintf(p, cur->audacious.max_title_len > 0
5205 ? cur->audacious.max_title_len : p_max_size, "%s",
5206 cur->audacious.items[AUDACIOUS_TITLE]);
5208 OBJ(audacious_length) {
5209 snprintf(p, p_max_size, "%s",
5210 cur->audacious.items[AUDACIOUS_LENGTH]);
5212 OBJ(audacious_length_seconds) {
5213 snprintf(p, p_max_size, "%s",
5214 cur->audacious.items[AUDACIOUS_LENGTH_SECONDS]);
5216 OBJ(audacious_position) {
5217 snprintf(p, p_max_size, "%s",
5218 cur->audacious.items[AUDACIOUS_POSITION]);
5220 OBJ(audacious_position_seconds) {
5221 snprintf(p, p_max_size, "%s",
5222 cur->audacious.items[AUDACIOUS_POSITION_SECONDS]);
5224 OBJ(audacious_bitrate) {
5225 snprintf(p, p_max_size, "%s",
5226 cur->audacious.items[AUDACIOUS_BITRATE]);
5228 OBJ(audacious_frequency) {
5229 snprintf(p, p_max_size, "%s",
5230 cur->audacious.items[AUDACIOUS_FREQUENCY]);
5232 OBJ(audacious_channels) {
5233 snprintf(p, p_max_size, "%s",
5234 cur->audacious.items[AUDACIOUS_CHANNELS]);
5236 OBJ(audacious_filename) {
5237 snprintf(p, p_max_size, "%s",
5238 cur->audacious.items[AUDACIOUS_FILENAME]);
5240 OBJ(audacious_playlist_length) {
5241 snprintf(p, p_max_size, "%s",
5242 cur->audacious.items[AUDACIOUS_PLAYLIST_LENGTH]);
5244 OBJ(audacious_playlist_position) {
5245 snprintf(p, p_max_size, "%s",
5246 cur->audacious.items[AUDACIOUS_PLAYLIST_POSITION]);
5248 OBJ(audacious_main_volume) {
5249 snprintf(p, p_max_size, "%s",
5250 cur->audacious.items[AUDACIOUS_MAIN_VOLUME]);
5252 OBJ(audacious_bar) {
5256 atof(cur->audacious.items[AUDACIOUS_POSITION_SECONDS]) /
5257 atof(cur->audacious.items[AUDACIOUS_LENGTH_SECONDS]);
5258 new_bar(p, obj->a, obj->b, (int) (progress * 255.0f));
5260 #endif /* AUDACIOUS */
5264 snprintf(p, p_max_size, "%s", cur->bmpx.title);
5267 snprintf(p, p_max_size, "%s", cur->bmpx.artist);
5270 snprintf(p, p_max_size, "%s", cur->bmpx.album);
5273 snprintf(p, p_max_size, "%s", cur->bmpx.uri);
5276 snprintf(p, p_max_size, "%i", cur->bmpx.track);
5279 snprintf(p, p_max_size, "%i", cur->bmpx.bitrate);
5282 /* we have three different types of top (top, top_mem
5283 * and top_time). To avoid having almost-same code three
5284 * times, we have this special handler. */
5287 parse_top_args("top", obj->data.top.s, obj);
5288 if (!needed) needed = cur->cpu;
5290 parse_top_args("top_mem", obj->data.top.s, obj);
5291 if (!needed) needed = cur->memu;
5293 parse_top_args("top_time", obj->data.top.s, obj);
5294 if (!needed) needed = cur->time;
5296 if (needed[obj->data.top.num]) {
5299 switch (obj->data.top.type) {
5301 snprintf(p, top_name_width + 1, "%-*s", top_name_width,
5302 needed[obj->data.top.num]->name);
5305 snprintf(p, 7, "%6.2f",
5306 needed[obj->data.top.num]->amount);
5309 snprintf(p, 6, "%5i",
5310 needed[obj->data.top.num]->pid);
5313 snprintf(p, 7, "%6.2f",
5314 needed[obj->data.top.num]->totalmem);
5317 timeval = format_time(
5318 needed[obj->data.top.num]->total_cpu_time, 9);
5319 snprintf(p, 10, "%9s", timeval);
5323 human_readable(needed[obj->data.top.num]->rss,
5327 human_readable(needed[obj->data.top.num]->vsize,
5333 print_tail_object(obj, p, p_max_size);
5335 print_head_object(obj, p, p_max_size);
5337 FILE *fp = open_file(obj->data.s, &obj->a);
5340 /* FIXME: use something more general (see also tail.c, head.c */
5341 #define BUFSZ 0x1000
5346 while(fgets(buf, BUFSZ, fp) != NULL){
5347 for(j = 0; buf[j] != 0; j++) {
5348 if(buf[j] == '\n') {
5353 sprintf(p, "%d", lines);
5356 sprintf(p, "File Unreadable");
5361 FILE *fp = open_file(obj->data.s, &obj->a);
5366 char inword = FALSE;
5369 while(fgets(buf, BUFSZ, fp) != NULL){
5370 for(j = 0; buf[j] != 0; j++) {
5371 if(!isspace(buf[j])) {
5372 if(inword == FALSE) {
5381 sprintf(p, "%d", words);
5384 sprintf(p, "File Unreadable");
5387 #ifdef TCP_PORT_MONITOR
5389 tcp_portmon_action(p, p_max_size,
5390 &obj->data.tcp_port_monitor);
5392 #endif /* TCP_PORT_MONITOR */
5396 iconv_converting = 1;
5397 iconv_selected = obj->a;
5400 iconv_converting = 0;
5403 #endif /* HAVE_ICONV */
5405 OBJ(entropy_avail) {
5406 snprintf(p, p_max_size, "%d", cur->entropy.entropy_avail);
5409 percent_print(p, p_max_size,
5410 cur->entropy.entropy_avail *
5411 100 / cur->entropy.poolsize);
5413 OBJ(entropy_poolsize) {
5414 snprintf(p, p_max_size, "%d", cur->entropy.poolsize);
5417 double entropy_perc;
5419 entropy_perc = (double) cur->entropy.entropy_avail /
5420 (double) cur->entropy.poolsize;
5422 if(output_methods & TO_X) {
5423 new_bar(p, obj->a, obj->b, (int) (entropy_perc * 255.0f));
5426 if(!obj->a) obj->a = DEFAULT_BAR_WIDTH_NO_X;
5427 new_bar_in_shell(p, p_max_size, (int) (entropy_perc * 100.0f), obj->a);
5436 s = smapi_get_val(obj->data.s);
5437 snprintf(p, p_max_size, "%s", s);
5441 OBJ(if_smapi_bat_installed) {
5443 if(obj->data.ifblock.s && sscanf(obj->data.ifblock.s, "%i", &idx) == 1) {
5444 if(!smapi_bat_installed(idx)) {
5448 ERR("argument to if_smapi_bat_installed must be an integer");
5450 OBJ(smapi_bat_perc) {
5452 if(obj->data.s && sscanf(obj->data.s, "%i", &idx) == 1) {
5453 val = smapi_bat_installed(idx) ?
5454 smapi_get_bat_int(idx, "remaining_percent") : 0;
5455 percent_print(p, p_max_size, val);
5457 ERR("argument to smapi_bat_perc must be an integer");
5459 OBJ(smapi_bat_temp) {
5461 if(obj->data.s && sscanf(obj->data.s, "%i", &idx) == 1) {
5462 val = smapi_bat_installed(idx) ?
5463 smapi_get_bat_int(idx, "temperature") : 0;
5464 /* temperature is in milli degree celsius */
5465 temp_print(p, p_max_size, val / 1000, TEMP_CELSIUS);
5467 ERR("argument to smapi_bat_temp must be an integer");
5469 OBJ(smapi_bat_power) {
5471 if(obj->data.s && sscanf(obj->data.s, "%i", &idx) == 1) {
5472 val = smapi_bat_installed(idx) ?
5473 smapi_get_bat_int(idx, "power_now") : 0;
5474 /* power_now is in mW, set to W with one digit precision */
5475 snprintf(p, p_max_size, "%.1f", ((double)val / 1000));
5477 ERR("argument to smapi_bat_power must be an integer");
5479 OBJ(smapi_bat_bar) {
5480 if(obj->data.i >= 0 && smapi_bat_installed(obj->data.i))
5481 new_bar(p, obj->a, obj->b, (int)
5482 (255 * smapi_get_bat_int(obj->data.i, "remaining_percent") / 100));
5484 new_bar(p, obj->a, obj->b, 0);
5489 char *tmp, buf[max_user_text];
5490 generate_text_internal(buf, max_user_text,
5493 if (strlen(buf) <= obj->data.scroll.show) {
5494 snprintf(p, p_max_size, "%s", buf);
5497 #define LINESEPARATOR '|'
5498 //place all the lines behind each other with LINESEPARATOR between them
5499 for(j = 0; buf[j] != 0; j++) {
5501 buf[j]=LINESEPARATOR;
5504 //scroll the output obj->data.scroll.start places by copying that many chars from
5505 //the front of the string to tmp, scrolling the rest to the front and placing tmp
5506 //at the back of the string
5507 tmp = calloc(obj->data.scroll.start + 1, sizeof(char));
5508 strncpy(tmp, buf, obj->data.scroll.start); tmp[obj->data.scroll.start] = 0;
5509 for(j = obj->data.scroll.start; buf[j] != 0; j++){
5510 buf[j - obj->data.scroll.start] = buf[j];
5512 strcpy(&buf[j - obj->data.scroll.start], tmp);
5514 //only show the requested number of chars
5515 if(obj->data.scroll.show < j) {
5516 buf[obj->data.scroll.show] = 0;
5518 //next time, scroll a place more or reset scrolling if we are at the end
5519 obj->data.scroll.start += obj->data.scroll.step;
5520 if(obj->data.scroll.start >= j){
5521 obj->data.scroll.start = 0;
5523 snprintf(p, p_max_size, "%s", buf);
5526 char buf[2][max_user_text];
5533 struct llrows* next;
5535 struct llrows *ll_rows[2], *current[2];
5536 struct text_object * objsub = obj->sub;
5539 for(i=0; i<2; i++) {
5542 ll_rows[i] = malloc(sizeof(struct llrows));
5543 current[i] = ll_rows[i];
5544 for(j=0; j<i; j++) objsub = objsub->sub;
5545 generate_text_internal(buf[i], max_user_text, *objsub, cur);
5546 for(j=0; buf[i][j] != 0; j++) {
5547 if(buf[i][j] == '\t') buf[i][j] = ' ';
5548 if(buf[i][j] == '\n') {
5550 current[i]->row = strdup(buf[i]+nextstart);
5551 if(i==0 && (long)strlen(current[i]->row) > longest) longest = (long)strlen(current[i]->row);
5552 current[i]->next = malloc(sizeof(struct llrows));
5553 current[i] = current[i]->next;
5558 current[i]->row = strdup(buf[i]+nextstart);
5559 if(i==0 && (long)strlen(current[i]->row) > longest) longest = (long)strlen(current[i]->row);
5560 current[i]->next = NULL;
5561 current[i] = ll_rows[i];
5563 for(j=0; j < (nr_rows[0] > nr_rows[1] ? nr_rows[0] : nr_rows[1] ); j++) {
5565 strcat(p, current[0]->row);
5566 i=strlen(current[0]->row);
5568 while(i < longest) {
5573 strcat(p, obj->data.combine.seperation);
5574 strcat(p, current[1]->row);
5578 #pragma omp parallel for
5579 #endif /* HAVE_OPENMP */
5580 for(i=0; i<2; i++) if(current[i]) current[i]=current[i]->next;
5583 #pragma omp parallel for
5584 #endif /* HAVE_OPENMP */
5585 for(i=0; i<2; i++) {
5586 while(ll_rows[i] != NULL) {
5587 current[i]=ll_rows[i];
5588 free(current[i]->row);
5589 ll_rows[i]=current[i]->next;
5596 int value = get_nvidia_value(obj->data.nvidia.type, display);
5598 snprintf(p, p_max_size, "N/A");
5599 else if (obj->data.nvidia.type == NV_TEMP)
5600 temp_print(p, p_max_size, (double)value, TEMP_CELSIUS);
5601 else if (obj->data.nvidia.print_as_float &&
5602 value > 0 && value < 100)
5603 snprintf(p, p_max_size, "%.1f", (float)value);
5605 snprintf(p, p_max_size, "%d", value);
5610 /* This is just a meta-object to set host:port */
5613 snprintf(p, p_max_size, "%s",
5614 cur->apcupsd.items[APCUPSD_NAME]);
5616 OBJ(apcupsd_model) {
5617 snprintf(p, p_max_size, "%s",
5618 cur->apcupsd.items[APCUPSD_MODEL]);
5620 OBJ(apcupsd_upsmode) {
5621 snprintf(p, p_max_size, "%s",
5622 cur->apcupsd.items[APCUPSD_UPSMODE]);
5624 OBJ(apcupsd_cable) {
5625 snprintf(p, p_max_size, "%s",
5626 cur->apcupsd.items[APCUPSD_CABLE]);
5628 OBJ(apcupsd_status) {
5629 snprintf(p, p_max_size, "%s",
5630 cur->apcupsd.items[APCUPSD_STATUS]);
5632 OBJ(apcupsd_linev) {
5633 snprintf(p, p_max_size, "%s",
5634 cur->apcupsd.items[APCUPSD_LINEV]);
5637 snprintf(p, p_max_size, "%s",
5638 cur->apcupsd.items[APCUPSD_LOAD]);
5640 OBJ(apcupsd_loadbar) {
5643 if(output_methods & TO_X) {
5644 progress = atof(cur->apcupsd.items[APCUPSD_LOAD]) / 100.0 * 255.0;
5645 new_bar(p, obj->a, obj->b, (int) progress);
5648 progress = atof(cur->apcupsd.items[APCUPSD_LOAD]);
5649 if(!obj->a) obj->a = DEFAULT_BAR_WIDTH_NO_X;
5650 new_bar_in_shell(p, p_max_size, (int) progress, obj->a);
5656 OBJ(apcupsd_loadgraph) {
5658 progress = atof(cur->apcupsd.items[APCUPSD_LOAD]);
5659 new_graph(p, obj->a, obj->b, obj->c, obj->d,
5660 (int)progress, 100, 1, obj->char_a, obj->char_b);
5662 OBJ(apcupsd_loadgauge) {
5664 progress = atof(cur->apcupsd.items[APCUPSD_LOAD]) / 100.0 * 255.0;
5665 new_gauge(p, obj->a, obj->b,
5669 OBJ(apcupsd_charge) {
5670 snprintf(p, p_max_size, "%s",
5671 cur->apcupsd.items[APCUPSD_CHARGE]);
5673 OBJ(apcupsd_timeleft) {
5674 snprintf(p, p_max_size, "%s",
5675 cur->apcupsd.items[APCUPSD_TIMELEFT]);
5678 snprintf(p, p_max_size, "%s",
5679 cur->apcupsd.items[APCUPSD_TEMP]);
5681 OBJ(apcupsd_lastxfer) {
5682 snprintf(p, p_max_size, "%s",
5683 cur->apcupsd.items[APCUPSD_LASTXFER]);
5685 #endif /* APCUPSD */
5692 unsigned int a = strlen(p);
5695 if (a > 0 && iconv_converting && iconv_selected > 0
5696 && (iconv_cd[iconv_selected - 1] != (iconv_t) (-1))) {
5698 size_t dummy1, dummy2;
5699 char *ptr = buff_in;
5702 dummy1 = dummy2 = a;
5704 strncpy(buff_in, p, p_max_size);
5706 iconv(*iconv_cd[iconv_selected - 1], NULL, NULL, NULL, NULL);
5707 while (dummy1 > 0) {
5708 bytes = iconv(*iconv_cd[iconv_selected - 1], &ptr, &dummy1,
5711 ERR("Iconv codeset conversion failed");
5716 /* It is nessecary when we are converting from multibyte to
5717 * singlebyte codepage */
5720 #endif /* HAVE_ICONV */
5728 double current_update_time, next_update_time, last_update_time;
5730 static void generate_text(void)
5732 struct information *cur = &info;
5739 current_update_time = get_time();
5743 /* add things to the buffer */
5749 generate_text_internal(p, max_user_text, global_root_object, cur);
5751 if (stuff_in_upper_case) {
5754 tmp_p = text_buffer;
5756 *tmp_p = toupper(*tmp_p);
5761 next_update_time += update_interval;
5762 if (next_update_time < get_time()) {
5763 next_update_time = get_time() + update_interval;
5764 } else if (next_update_time > get_time() + update_interval) {
5765 next_update_time = get_time() + update_interval;
5767 last_update_time = current_update_time;
5772 static inline int get_string_width(const char *s)
5775 if (output_methods & TO_X) {
5776 return *s ? calc_text_width(s, strlen(s)) : 0;
5782 static inline int get_string_width_special(char *s)
5790 if ((output_methods & TO_X) == 0) {
5792 return (s) ? strlen(s) : 0;
5800 p = strndup(s, text_buffer_size);
5804 if (*p == SPECIAL_CHAR) {
5805 /* shift everything over by 1 so that the special char
5806 * doesn't mess up the size calculation */
5807 for (i = 0; i < (long)strlen(p); i++) {
5808 *(p + i) = *(p + i + 1);
5810 if (specials[special_index + idx].type == GRAPH
5811 || specials[special_index + idx].type == GAUGE
5812 || specials[special_index + idx].type == BAR) {
5813 width += specials[special_index + idx].width;
5820 if (strlen(final) > 1) {
5821 width += calc_text_width(final, strlen(final));
5829 static void text_size_updater(char *s);
5831 int last_font_height;
5832 static void update_text_area(void)
5836 if ((output_methods & TO_X) == 0)
5838 /* update text size if it isn't fixed */
5843 text_width = minimum_width;
5846 last_font_height = font_height();
5847 for_each_line(text_buffer, text_size_updater);
5849 if (text_height < minimum_height) {
5850 text_height = minimum_height;
5852 if (text_width > maximum_width && maximum_width > 0) {
5853 text_width = maximum_width;
5857 /* get text position on workarea */
5858 switch (text_alignment) {
5865 x = workarea[2] - text_width - gap_x;
5870 x = workarea[2] / 2 - text_width / 2 - gap_x;
5877 y = workarea[3] - text_height - gap_y;
5881 x = workarea[2] - text_width - gap_x;
5882 y = workarea[3] - text_height - gap_y;
5886 x = workarea[2] / 2 - text_width / 2 - gap_x;
5887 y = workarea[3] - text_height - gap_y;
5892 y = workarea[3] / 2 - text_height / 2 - gap_y;
5896 x = workarea[2] - text_width - gap_x;
5897 y = workarea[3] / 2 - text_height / 2 - gap_y;
5901 case NONE: // Let the WM manage the window
5912 if (own_window && !fixed_pos) {
5915 text_start_x = border_margin + 1;
5916 text_start_y = border_margin + 1;
5917 window.x = x - border_margin - 1;
5918 window.y = y - border_margin - 1;
5922 /* If window size doesn't match to workarea's size,
5923 * then window probably includes panels (gnome).
5924 * Blah, doesn't work on KDE. */
5925 if (workarea[2] != window.width || workarea[3] != window.height) {
5937 static int cur_x, cur_y; /* current x and y for drawing */
5939 //draw_mode also without X11 because we only need to print to stdout with FG
5940 static int draw_mode; /* FG, BG or OUTLINE */
5942 static long current_color;
5944 static void text_size_updater(char *s)
5949 if ((output_methods & TO_X) == 0)
5951 /* get string widths and skip specials */
5954 if (*p == SPECIAL_CHAR) {
5956 w += get_string_width(s);
5959 if (specials[special_index].type == BAR
5960 || specials[special_index].type == GAUGE
5961 || specials[special_index].type == GRAPH) {
5962 w += specials[special_index].width;
5963 if (specials[special_index].height > last_font_height) {
5964 last_font_height = specials[special_index].height;
5965 last_font_height += font_height();
5967 } else if (specials[special_index].type == OFFSET) {
5968 if (specials[special_index].arg > 0) {
5969 w += specials[special_index].arg;
5971 } else if (specials[special_index].type == VOFFSET) {
5972 last_font_height += specials[special_index].arg;
5973 } else if (specials[special_index].type == GOTO) {
5974 if (specials[special_index].arg > cur_x) {
5975 w = (int) specials[special_index].arg;
5977 } else if (specials[special_index].type == TAB) {
5978 int start = specials[special_index].arg;
5979 int step = specials[special_index].width;
5981 if (!step || step < 0) {
5984 w += step - (cur_x - text_start_x - start) % step;
5985 } else if (specials[special_index].type == FONT) {
5986 selected_font = specials[special_index].font_added;
5987 if (font_height() > last_font_height) {
5988 last_font_height = font_height();
5997 w += get_string_width(s);
5998 if (w > text_width) {
6001 if (text_width > maximum_width && maximum_width) {
6002 text_width = maximum_width;
6005 text_height += last_font_height;
6006 last_font_height = font_height();
6009 static inline void set_foreground_color(long c)
6011 if ((output_methods & TO_X) == 0)
6014 XSetForeground(display, window.gc, c);
6018 static void draw_string(const char *s)
6020 int i, i2, pos, width_of_s;
6028 width_of_s = get_string_width(s);
6029 if ((output_methods & TO_STDOUT) && draw_mode == FG) {
6031 fflush(stdout); /* output immediately, don't buffer */
6033 if ((output_methods & TO_STDERR) && draw_mode == FG) {
6034 fprintf(stderr, "%s\n", s);
6035 fflush(stderr); /* output immediately, don't buffer */
6037 if ((output_methods & OVERWRITE_FILE) && draw_mode == FG && overwrite_fpointer) {
6038 fprintf(overwrite_fpointer, "%s\n", s);
6040 if ((output_methods & APPEND_FILE) && draw_mode == FG && append_fpointer) {
6041 fprintf(append_fpointer, "%s\n", s);
6043 memset(tmpstring1, 0, text_buffer_size);
6044 memset(tmpstring2, 0, text_buffer_size);
6045 strncpy(tmpstring1, s, text_buffer_size - 1);
6050 if (output_methods & TO_X) {
6051 max = ((text_width - width_of_s) / get_string_width(" "));
6054 /* This code looks for tabs in the text and coverts them to spaces.
6055 * The trick is getting the correct number of spaces, and not going
6056 * over the window's size without forcing the window larger. */
6057 for (i = 0; i < (int) text_buffer_size; i++) {
6058 if (tmpstring1[i] == '\t') {
6060 for (i2 = 0; i2 < (8 - (1 + pos) % 8) && added <= max; i2++) {
6061 /* guard against overrun */
6062 tmpstring2[MIN(pos + i2, (int)text_buffer_size - 1)] = ' ';
6067 /* guard against overrun */
6068 tmpstring2[MIN(pos, (int) text_buffer_size - 1)] = tmpstring1[i];
6073 if (output_methods & TO_X) {
6074 if (text_width == maximum_width) {
6075 /* this means the text is probably pushing the limit,
6076 * so we'll chop it */
6077 while (cur_x + get_string_width(tmpstring2) - text_start_x
6078 > maximum_width && strlen(tmpstring2) > 0) {
6079 tmpstring2[strlen(tmpstring2) - 1] = '\0';
6086 if (output_methods & TO_X) {
6092 c.pixel = current_color;
6093 XQueryColor(display, DefaultColormap(display, screen), &c);
6096 c2.color.red = c.red;
6097 c2.color.green = c.green;
6098 c2.color.blue = c.blue;
6099 c2.color.alpha = fonts[selected_font].font_alpha;
6101 XftDrawStringUtf8(window.xftdraw, &c2, fonts[selected_font].xftfont,
6102 cur_x, cur_y, (const XftChar8 *) s, strlen(s));
6104 XftDrawString8(window.xftdraw, &c2, fonts[selected_font].xftfont,
6105 cur_x, cur_y, (const XftChar8 *) s, strlen(s));
6110 XDrawString(display, window.drawable, window.gc, cur_x, cur_y, s,
6113 cur_x += width_of_s;
6116 memcpy(tmpstring1, s, text_buffer_size);
6119 static void draw_line(char *s)
6127 if ((output_methods & TO_X) == 0) {
6133 cur_x = text_start_x;
6134 cur_y += font_ascent();
6135 font_h = font_height();
6137 /* find specials and draw stuff */
6140 if (*p == SPECIAL_CHAR) {
6143 /* draw string before special */
6150 switch (specials[special_index].type) {
6151 case HORIZONTAL_LINE:
6153 int h = specials[special_index].height;
6154 int mid = font_ascent() / 2;
6156 w = text_start_x + text_width - cur_x;
6158 XSetLineAttributes(display, window.gc, h, LineSolid,
6159 CapButt, JoinMiter);
6160 XDrawLine(display, window.drawable, window.gc, cur_x,
6161 cur_y - mid / 2, cur_x + w, cur_y - mid / 2);
6167 int h = specials[special_index].height;
6168 int tmp_s = specials[special_index].arg;
6169 int mid = font_ascent() / 2;
6170 char ss[2] = { tmp_s, tmp_s };
6172 w = text_start_x + text_width - cur_x - 1;
6173 XSetLineAttributes(display, window.gc, h, LineOnOffDash,
6174 CapButt, JoinMiter);
6175 XSetDashes(display, window.gc, 0, ss, 2);
6176 XDrawLine(display, window.drawable, window.gc, cur_x,
6177 cur_y - mid / 2, cur_x + w, cur_y - mid / 2);
6183 int h, bar_usage, by;
6184 if (cur_x - text_start_x > maximum_width
6185 && maximum_width > 0) {
6188 h = specials[special_index].height;
6189 bar_usage = specials[special_index].arg;
6190 by = cur_y - (font_ascent() / 2) - 1;
6195 w = specials[special_index].width;
6197 w = text_start_x + text_width - cur_x - 1;
6203 XSetLineAttributes(display, window.gc, 1, LineSolid,
6204 CapButt, JoinMiter);
6206 XDrawRectangle(display, window.drawable, window.gc, cur_x,
6208 XFillRectangle(display, window.drawable, window.gc, cur_x,
6209 by, w * bar_usage / 255, h);
6217 case GAUGE: /* new GAUGE */
6220 unsigned long last_colour = current_color;
6221 float angle, px, py;
6224 if (cur_x - text_start_x > maximum_width
6225 && maximum_width > 0) {
6229 h = specials[special_index].height;
6230 by = cur_y - (font_ascent() / 2) - 1;
6235 w = specials[special_index].width;
6237 w = text_start_x + text_width - cur_x - 1;
6243 XSetLineAttributes(display, window.gc, 1, LineSolid,
6244 CapButt, JoinMiter);
6246 XDrawArc(display, window.drawable, window.gc,
6247 cur_x, by, w, h * 2, 0, 180*64);
6250 usage = specials[special_index].arg;
6251 angle = (M_PI)*(float)(usage)/255.;
6252 px = (float)(cur_x+(w/2.))-(float)(w/2.)*cos(angle);
6253 py = (float)(by+(h))-(float)(h)*sin(angle);
6255 XDrawLine(display, window.drawable, window.gc,
6256 cur_x + (w/2.), by+(h), (int)(px), (int)(py));
6264 set_foreground_color(last_colour);
6272 int h, by, i = 0, j = 0;
6274 unsigned long last_colour = current_color;
6275 unsigned long *tmpcolour = 0;
6276 if (cur_x - text_start_x > maximum_width
6277 && maximum_width > 0) {
6280 h = specials[special_index].height;
6281 by = cur_y - (font_ascent() / 2) - 1;
6286 w = specials[special_index].width;
6288 w = text_start_x + text_width - cur_x - 1;
6293 if (draw_graph_borders) {
6294 XSetLineAttributes(display, window.gc, 1, LineSolid,
6295 CapButt, JoinMiter);
6296 XDrawRectangle(display, window.drawable, window.gc,
6299 XSetLineAttributes(display, window.gc, 1, LineSolid,
6300 CapButt, JoinMiter);
6302 if (specials[special_index].last_colour != 0
6303 || specials[special_index].first_colour != 0) {
6304 tmpcolour = do_gradient(w - 1, specials[special_index].last_colour, specials[special_index].first_colour);
6307 for (i = w - 2; i > -1; i--) {
6308 if (specials[special_index].last_colour != 0
6309 || specials[special_index].first_colour != 0) {
6310 if (specials[special_index].tempgrad) {
6313 (int)((float)(w - 2) - specials[special_index].graph[j] *
6314 (w - 2) / (float)specials[special_index].graph_scale)
6318 (int)((float)(w - 2) - specials[special_index].graph[j] *
6319 (w - 2) / (float)specials[special_index].graph_scale)
6322 if (specials[special_index].graph[j] == specials[special_index].graph_scale) {
6324 (int)((float)(w - 2) - specials[special_index].graph[j] *
6325 (w - 2) / (float)specials[special_index].graph_scale)
6329 #endif /* DEBUG_lol */
6330 XSetForeground(display, window.gc, tmpcolour[
6331 (int)((float)(w - 2) - specials[special_index].graph[j] *
6332 (w - 2) / (float)specials[special_index].graph_scale)
6335 XSetForeground(display, window.gc, tmpcolour[colour_idx++]);
6338 /* this is mugfugly, but it works */
6339 XDrawLine(display, window.drawable, window.gc,
6340 cur_x + i + 1, by + h, cur_x + i + 1,
6341 round_to_int((double)by + h - specials[special_index].graph[j] *
6342 (h - 1) / specials[special_index].graph_scale));
6343 if ((w - i) / ((float) (w - 2) /
6344 (specials[special_index].graph_width)) > j
6345 && j < MAX_GRAPH_DEPTH - 3) {
6349 if (tmpcolour) free(tmpcolour);
6354 /* if (draw_mode == BG) {
6355 set_foreground_color(default_bg_color);
6356 } else if (draw_mode == OUTLINE) {
6357 set_foreground_color(default_out_color);
6359 set_foreground_color(default_fg_color);
6361 if (show_graph_range) {
6364 unsigned short int seconds = update_interval * w;
6369 unsigned short int timeunits;
6371 timeunits = seconds / 86400; seconds %= 86400;
6372 if (timeunits > 0) {
6373 asprintf(&tmp_day_str, "%dd", timeunits);
6375 tmp_day_str = strdup("");
6377 timeunits = seconds / 3600; seconds %= 3600;
6378 if (timeunits > 0) {
6379 asprintf(&tmp_hour_str, "%dh", timeunits);
6381 tmp_hour_str = strdup("");
6383 timeunits = seconds / 60; seconds %= 60;
6384 if (timeunits > 0) {
6385 asprintf(&tmp_min_str, "%dm", timeunits);
6387 tmp_min_str = strdup("");
6390 asprintf(&tmp_sec_str, "%ds", seconds);
6392 tmp_sec_str = strdup("");
6394 asprintf(&tmp_str, "%s%s%s%s", tmp_day_str, tmp_hour_str, tmp_min_str, tmp_sec_str);
6395 free(tmp_day_str); free(tmp_hour_str); free(tmp_min_str); free(tmp_sec_str);
6397 asprintf(&tmp_str, "Range not possible"); // should never happen, but better safe then sorry
6399 cur_x += (w / 2) - (font_ascent() * (strlen(tmp_str) / 2));
6400 cur_y += font_h / 2;
6401 draw_string(tmp_str);
6407 if (show_graph_scale && (specials[special_index].show_scale == 1)) {
6410 cur_x += font_ascent() / 2;
6411 cur_y += font_h / 2;
6413 calloc(log10(floor(specials[special_index].graph_scale)) + 4,
6415 sprintf(tmp_str, "%.1f", specials[special_index].graph_scale);
6416 draw_string(tmp_str);
6422 set_foreground_color(last_colour);
6428 int old = font_ascent();
6430 cur_y -= font_ascent();
6431 selected_font = specials[special_index].font_added;
6432 if (cur_y + font_ascent() < cur_y + old) {
6435 cur_y += font_ascent();
6438 font_h = font_height();
6442 if (draw_mode == FG) {
6443 set_foreground_color(specials[special_index].arg);
6448 if (draw_mode == BG) {
6449 set_foreground_color(specials[special_index].arg);
6454 if (draw_mode == OUTLINE) {
6455 set_foreground_color(specials[special_index].arg);
6460 w += specials[special_index].arg;
6464 cur_y += specials[special_index].arg;
6468 if (specials[special_index].arg >= 0) {
6469 cur_x = (int) specials[special_index].arg;
6475 int start = specials[special_index].arg;
6476 int step = specials[special_index].width;
6478 if (!step || step < 0) {
6481 w = step - (cur_x - text_start_x - start) % step;
6487 /* TODO: add back in "+ border_margin" to the end of
6489 int pos_x = text_start_x + text_width -
6490 get_string_width_special(s);
6492 /* printf("pos_x %i text_start_x %i text_width %i cur_x %i "
6493 "get_string_width(p) %i gap_x %i "
6494 "specials[special_index].arg %i border_margin %i "
6495 "border_width %i\n", pos_x, text_start_x, text_width,
6496 cur_x, get_string_width_special(s), gap_x,
6497 specials[special_index].arg, border_margin,
6499 if (pos_x > specials[special_index].arg && pos_x > cur_x) {
6500 cur_x = pos_x - specials[special_index].arg;
6507 int pos_x = (text_width) / 2 - get_string_width_special(s) /
6508 2 - (cur_x - text_start_x);
6509 /* int pos_x = text_start_x + text_width / 2 -
6510 get_string_width_special(s) / 2; */
6512 /* printf("pos_x %i text_start_x %i text_width %i cur_x %i "
6513 "get_string_width(p) %i gap_x %i "
6514 "specials[special_index].arg %i\n", pos_x, text_start_x,
6515 text_width, cur_x, get_string_width(s), gap_x,
6516 specials[special_index].arg); */
6517 if (pos_x > specials[special_index].arg) {
6518 w = pos_x - specials[special_index].arg;
6532 if (cur_y_add > 0) {
6536 cur_y += font_descent();
6541 static void draw_text(void)
6544 if (output_methods & TO_X) {
6545 cur_y = text_start_y;
6548 if (draw_borders && border_width > 0) {
6549 unsigned int b = (border_width + 1) / 2;
6551 if (stippled_borders) {
6552 char ss[2] = { stippled_borders, stippled_borders };
6553 XSetLineAttributes(display, window.gc, border_width, LineOnOffDash,
6554 CapButt, JoinMiter);
6555 XSetDashes(display, window.gc, 0, ss, 2);
6557 XSetLineAttributes(display, window.gc, border_width, LineSolid,
6558 CapButt, JoinMiter);
6561 XDrawRectangle(display, window.drawable, window.gc,
6562 text_start_x - border_margin + b, text_start_y - border_margin + b,
6563 text_width + border_margin * 2 - 1 - b * 2,
6564 text_height + border_margin * 2 - 1 - b * 2);
6571 for_each_line(text_buffer, draw_line);
6574 static void draw_stuff(void)
6576 if (overwrite_file) {
6577 overwrite_fpointer = fopen(overwrite_file, "w");
6578 if(!overwrite_fpointer)
6579 ERR("Can't overwrite '%s' anymore", overwrite_file);
6582 append_fpointer = fopen(append_file, "a");
6583 if(!append_fpointer)
6584 ERR("Can't append '%s' anymore", append_file);
6587 if (output_methods & TO_X) {
6589 if (draw_shades && !draw_outline) {
6592 set_foreground_color(default_bg_color);
6603 for (i = -1; i < 2; i++) {
6604 for (j = -1; j < 2; j++) {
6605 if (i == 0 && j == 0) {
6610 set_foreground_color(default_out_color);
6611 draw_mode = OUTLINE;
6619 set_foreground_color(default_fg_color);
6625 if (output_methods & TO_X) {
6630 swap.swap_window = window.window;
6631 swap.swap_action = XdbeBackground;
6632 XdbeSwapBuffers(display, &swap, 1);
6637 if(overwrite_fpointer) {
6638 fclose(overwrite_fpointer);
6639 overwrite_fpointer = 0;
6641 if(append_fpointer) {
6642 fclose(append_fpointer);
6643 append_fpointer = 0;
6648 static void clear_text(int exposures)
6652 /* The swap action is XdbeBackground, which clears */
6656 if (display && window.window) { // make sure these are !null
6657 /* there is some extra space for borders and outlines */
6658 XClearArea(display, window.window, text_start_x - border_margin - 1,
6659 text_start_y - border_margin - 1,
6660 text_width + border_margin * 2 + 2,
6661 text_height + border_margin * 2 + 2, exposures ? True : 0);
6666 static int need_to_update;
6668 /* update_text() generates new text and clears old text area */
6669 static void update_text(void)
6676 if (output_methods & TO_X)
6682 #ifdef HAVE_SYS_INOTIFY_H
6686 static void main_loop(void)
6689 #ifdef SIGNAL_BLOCKING
6690 sigset_t newmask, oldmask;
6693 #ifdef HAVE_SYS_INOTIFY_H
6694 int inotify_config_wd = 0;
6695 #define INOTIFY_EVENT_SIZE (sizeof(struct inotify_event))
6696 #define INOTIFY_BUF_LEN (20 * (INOTIFY_EVENT_SIZE + 16))
6697 char inotify_buff[INOTIFY_BUF_LEN];
6698 #endif /* HAVE_SYS_INOTIFY_H */
6701 #ifdef SIGNAL_BLOCKING
6702 sigemptyset(&newmask);
6703 sigaddset(&newmask, SIGINT);
6704 sigaddset(&newmask, SIGTERM);
6705 sigaddset(&newmask, SIGUSR1);
6708 last_update_time = 0.0;
6709 next_update_time = get_time();
6711 while (terminate == 0 && (total_run_times == 0 || info.looped < total_run_times)) {
6714 #ifdef SIGNAL_BLOCKING
6715 /* block signals. we will inspect for pending signals later */
6716 if (sigprocmask(SIG_BLOCK, &newmask, &oldmask) < 0) {
6717 CRIT_ERR("unable to sigprocmask()");
6722 if (output_methods & TO_X) {
6725 /* wait for X event or timeout */
6727 if (!XPending(display)) {
6731 t = next_update_time - get_time();
6735 } else if (t > update_interval) {
6736 t = update_interval;
6739 tv.tv_sec = (long) t;
6740 tv.tv_usec = (long) (t * 1000000) % 1000000;
6742 FD_SET(ConnectionNumber(display), &fdsr);
6744 s = select(ConnectionNumber(display) + 1, &fdsr, 0, 0, &tv);
6746 if (errno != EINTR) {
6747 ERR("can't select(): %s", strerror(errno));
6757 if (need_to_update) {
6759 int wx = window.x, wy = window.y;
6767 /* resize window if it isn't right size */
6769 && (text_width + border_margin * 2 + 1 != window.width
6770 || text_height + border_margin * 2 + 1 != window.height)) {
6771 window.width = text_width + border_margin * 2 + 1;
6772 window.height = text_height + border_margin * 2 + 1;
6773 XResizeWindow(display, window.window, window.width,
6776 set_transparent_background(window.window);
6780 /* move window if it isn't in right position */
6781 if (!fixed_pos && (window.x != wx || window.y != wy)) {
6782 XMoveWindow(display, window.window, window.x, window.y);
6793 r.x = text_start_x - border_margin;
6794 r.y = text_start_y - border_margin;
6795 r.width = text_width + border_margin * 2;
6796 r.height = text_height + border_margin * 2;
6797 XUnionRectWithRegion(&r, x11_stuff.region, x11_stuff.region);
6802 /* handle X events */
6803 while (XPending(display)) {
6806 XNextEvent(display, &ev);
6813 r.width = ev.xexpose.width;
6814 r.height = ev.xexpose.height;
6815 XUnionRectWithRegion(&r, x11_stuff.region, x11_stuff.region);
6820 case ReparentNotify:
6821 /* set background to ParentRelative for all parents */
6823 set_transparent_background(window.window);
6827 case ConfigureNotify:
6829 /* if window size isn't what expected, set fixed size */
6830 if (ev.xconfigure.width != window.width
6831 || ev.xconfigure.height != window.height) {
6832 if (window.width != 0 && window.height != 0) {
6836 /* clear old stuff before screwing up
6841 XWindowAttributes attrs;
6842 if (XGetWindowAttributes(display,
6843 window.window, &attrs)) {
6844 window.width = attrs.width;
6845 window.height = attrs.height;
6849 text_width = window.width - border_margin * 2 - 1;
6850 text_height = window.height - border_margin * 2 - 1;
6851 if (text_width > maximum_width
6852 && maximum_width > 0) {
6853 text_width = maximum_width;
6857 /* if position isn't what expected, set fixed pos
6858 * total_updates avoids setting fixed_pos when window
6859 * is set to weird locations when started */
6860 /* // this is broken
6861 if (total_updates >= 2 && !fixed_pos
6862 && (window.x != ev.xconfigure.x
6863 || window.y != ev.xconfigure.y)
6864 && (ev.xconfigure.x != 0
6865 || ev.xconfigure.y != 0)) {
6874 /* if an ordinary window with decorations */
6875 if ((window.type == TYPE_NORMAL)
6876 && (!TEST_HINT(window.hints,
6877 HINT_UNDECORATED))) {
6878 /* allow conky to hold input focus. */
6881 /* forward the click to the desktop window */
6882 XUngrabPointer(display, ev.xbutton.time);
6883 ev.xbutton.window = window.desktop;
6884 ev.xbutton.x = ev.xbutton.x_root;
6885 ev.xbutton.y = ev.xbutton.y_root;
6886 XSendEvent(display, ev.xbutton.window, False,
6887 ButtonPressMask, &ev);
6888 XSetInputFocus(display, ev.xbutton.window,
6889 RevertToParent, ev.xbutton.time);
6896 /* if an ordinary window with decorations */
6897 if ((window.type == TYPE_NORMAL)
6898 && (!TEST_HINT(window.hints,
6899 HINT_UNDECORATED))) {
6900 /* allow conky to hold input focus. */
6903 /* forward the release to the desktop window */
6904 ev.xbutton.window = window.desktop;
6905 ev.xbutton.x = ev.xbutton.x_root;
6906 ev.xbutton.y = ev.xbutton.y_root;
6907 XSendEvent(display, ev.xbutton.window, False,
6908 ButtonReleaseMask, &ev);
6917 if (ev.type == x11_stuff.event_base + XDamageNotify) {
6918 XDamageNotifyEvent *dev = (XDamageNotifyEvent *) &ev;
6920 XFixesSetRegion(display, x11_stuff.part, &dev->area, 1);
6921 XFixesUnionRegion(display, x11_stuff.region2, x11_stuff.region2, x11_stuff.part);
6923 #endif /* HAVE_XDAMAGE */
6929 XDamageSubtract(display, x11_stuff.damage, x11_stuff.region2, None);
6930 XFixesSetRegion(display, x11_stuff.region2, 0, 0);
6931 #endif /* HAVE_XDAMAGE */
6933 /* XDBE doesn't seem to provide a way to clear the back buffer without
6934 * interfering with the front buffer, other than passing XdbeBackground
6935 * to XdbeSwapBuffers. That means that if we're using XDBE, we need to
6936 * redraw the text even if it wasn't part of the exposed area. OTOH,
6937 * if we're not going to call draw_stuff at all, then no swap happens
6938 * and we can safely do nothing. */
6940 if (!XEmptyRegion(x11_stuff.region)) {
6945 r.x = text_start_x - border_margin;
6946 r.y = text_start_y - border_margin;
6947 r.width = text_width + border_margin * 2;
6948 r.height = text_height + border_margin * 2;
6949 XUnionRectWithRegion(&r, x11_stuff.region, x11_stuff.region);
6952 XSetRegion(display, window.gc, x11_stuff.region);
6955 XftDrawSetClip(window.xftdraw, x11_stuff.region);
6959 cimlib_render(text_start_x, text_start_y, window.width, window.height);
6962 XDestroyRegion(x11_stuff.region);
6963 x11_stuff.region = XCreateRegion();
6967 t = (next_update_time - get_time()) * 1000000;
6968 if(t > 0) usleep((useconds_t)t);
6975 #ifdef SIGNAL_BLOCKING
6976 /* unblock signals of interest and let handler fly */
6977 if (sigprocmask(SIG_SETMASK, &oldmask, NULL) < 0) {
6978 CRIT_ERR("unable to sigprocmask()");
6982 switch (g_signal_pending) {
6985 ERR("received SIGHUP or SIGUSR1. reloading the config file.");
6990 ERR("received SIGINT or SIGTERM to terminate. bye!");
6994 if (output_methods & TO_X) {
6995 XDestroyRegion(x11_stuff.region);
6996 x11_stuff.region = NULL;
6998 XDamageDestroy(display, x11_stuff.damage);
6999 XFixesDestroyRegion(display, x11_stuff.region2);
7000 XFixesDestroyRegion(display, x11_stuff.part);
7001 #endif /* HAVE_XDAMAGE */
7007 if(overwrite_file) {
7008 free(overwrite_file);
7017 /* Reaching here means someone set a signal
7018 * (SIGXXXX, signal_handler), but didn't write any code
7020 * If you don't want to handle a signal, don't set a handler on
7021 * it in the first place. */
7022 if (g_signal_pending) {
7023 ERR("ignoring signal (%d)", g_signal_pending);
7027 #ifdef HAVE_SYS_INOTIFY_H
7028 if (inotify_fd && !inotify_config_wd) {
7029 inotify_config_wd = inotify_add_watch(inotify_fd,
7033 if (inotify_fd && inotify_config_wd) {
7034 int len = 0, idx = 0;
7036 struct timeval time_to_wait;
7038 FD_ZERO (&descriptors);
7039 FD_SET(inotify_fd, &descriptors);
7041 time_to_wait.tv_sec = time_to_wait.tv_usec = 0;
7043 select(inotify_fd + 1, &descriptors, NULL, NULL, &time_to_wait);
7044 if (FD_ISSET(inotify_fd, &descriptors)) {
7045 /* process inotify events */
7046 len = read(inotify_fd, inotify_buff, INOTIFY_BUF_LEN);
7047 while (len > 0 && idx < len) {
7048 struct inotify_event *ev = (struct inotify_event *) &inotify_buff[idx];
7049 if (ev->wd == inotify_config_wd && (ev->mask & IN_MODIFY || ev->mask & IN_IGNORED)) {
7050 /* current_config should be reloaded */
7051 ERR("'%s' modified, reloading...", current_config);
7053 if (ev->mask & IN_IGNORED) {
7054 /* for some reason we get IN_IGNORED here
7055 * sometimes, so we need to re-add the watch */
7056 inotify_config_wd = inotify_add_watch(inotify_fd,
7063 llua_inotify_query(ev->wd, ev->mask);
7065 #endif /* HAVE_LUA */
7066 idx += INOTIFY_EVENT_SIZE + ev->len;
7070 #endif /* HAVE_SYS_INOTIFY_H */
7072 g_signal_pending = 0;
7075 #ifdef HAVE_SYS_INOTIFY_H
7077 inotify_rm_watch(inotify_fd, inotify_config_wd);
7079 inotify_fd = inotify_config_wd = 0;
7081 #endif /* HAVE_SYS_INOTIFY_H */
7084 X11_destroy_window();
7088 static void load_config_file(const char *);
7089 static void load_config_file_x11(const char *);
7091 /* reload the config file */
7092 static void reload_config(void)
7094 timed_thread_destroy_registered_threads();
7096 if (info.cpu_usage) {
7097 free(info.cpu_usage);
7098 info.cpu_usage = NULL;
7109 #ifdef TCP_PORT_MONITOR
7110 tcp_portmon_clear();
7115 #endif /* HAVE_LUA */
7118 X11_destroy_window();
7121 if (current_config) {
7123 load_config_file(current_config);
7124 load_config_file_x11(current_config);
7126 /* re-init specials array */
7127 if ((specials = realloc((void *) specials,
7128 sizeof(struct special_t) * max_specials)) == 0) {
7129 ERR("failed to realloc specials array");
7134 if (output_methods & TO_X) {
7135 X11_initialisation();
7138 extract_variable_text(global_text);
7144 tmpstring1 = malloc(text_buffer_size);
7145 memset(tmpstring1, 0, text_buffer_size);
7149 tmpstring2 = malloc(text_buffer_size);
7150 memset(tmpstring2, 0, text_buffer_size);
7154 text_buffer = malloc(max_user_text);
7155 memset(text_buffer, 0, max_user_text);
7158 X11_create_window();
7163 static void clean_up(void)
7166 timed_thread_destroy_registered_threads();
7168 if (info.cpu_usage) {
7169 free(info.cpu_usage);
7170 info.cpu_usage = NULL;
7173 if (output_methods & TO_X) {
7176 XdbeDeallocateBackBufferName(display, window.back_buffer);
7181 XDestroyWindow(display, window.window);
7182 XClearWindow(display, RootWindow(display, screen));
7187 XClearWindow(display, RootWindow(display, screen));
7192 XFreeGC(display, window.gc);
7198 for (i = 0; i < MAX_TEMPLATES; i++) {
7205 free_text_objects(&global_root_object, 0);
7224 free(current_config);
7226 #ifdef TCP_PORT_MONITOR
7227 tcp_portmon_clear();
7234 #endif /* HAVE_LUA */
7237 for (i = 0; i < special_count; i++) {
7238 if (specials[i].type == GRAPH) {
7239 free(specials[i].graph);
7246 clear_diskio_stats();
7249 static int string_to_bool(const char *s)
7252 // Assumes an option without a true/false means true
7254 } else if (strcasecmp(s, "yes") == EQUAL) {
7256 } else if (strcasecmp(s, "true") == EQUAL) {
7258 } else if (strcasecmp(s, "1") == EQUAL) {
7265 static enum alignment string_to_alignment(const char *s)
7267 if (strcasecmp(s, "top_left") == EQUAL) {
7269 } else if (strcasecmp(s, "top_right") == EQUAL) {
7271 } else if (strcasecmp(s, "top_middle") == EQUAL) {
7273 } else if (strcasecmp(s, "bottom_left") == EQUAL) {
7275 } else if (strcasecmp(s, "bottom_right") == EQUAL) {
7276 return BOTTOM_RIGHT;
7277 } else if (strcasecmp(s, "bottom_middle") == EQUAL) {
7278 return BOTTOM_MIDDLE;
7279 } else if (strcasecmp(s, "middle_left") == EQUAL) {
7281 } else if (strcasecmp(s, "middle_right") == EQUAL) {
7282 return MIDDLE_RIGHT;
7283 } else if (strcasecmp(s, "tl") == EQUAL) {
7285 } else if (strcasecmp(s, "tr") == EQUAL) {
7287 } else if (strcasecmp(s, "tm") == EQUAL) {
7289 } else if (strcasecmp(s, "bl") == EQUAL) {
7291 } else if (strcasecmp(s, "br") == EQUAL) {
7292 return BOTTOM_RIGHT;
7293 } else if (strcasecmp(s, "bm") == EQUAL) {
7294 return BOTTOM_MIDDLE;
7295 } else if (strcasecmp(s, "ml") == EQUAL) {
7297 } else if (strcasecmp(s, "mr") == EQUAL) {
7298 return MIDDLE_RIGHT;
7299 } else if (strcasecmp(s, "none") == EQUAL) {
7307 static void set_default_configurations_for_x(void)
7309 default_fg_color = WhitePixel(display, screen);
7310 default_bg_color = BlackPixel(display, screen);
7311 default_out_color = BlackPixel(display, screen);
7312 color0 = default_fg_color;
7313 color1 = default_fg_color;
7314 color2 = default_fg_color;
7315 color3 = default_fg_color;
7316 color4 = default_fg_color;
7317 color5 = default_fg_color;
7318 color6 = default_fg_color;
7319 color7 = default_fg_color;
7320 color8 = default_fg_color;
7321 color9 = default_fg_color;
7325 static void set_default_configurations(void)
7329 fork_to_background = 0;
7330 total_run_times = 0;
7331 info.cpu_avg_samples = 2;
7332 info.net_avg_samples = 2;
7333 info.diskio_avg_samples = 2;
7341 mpd_set_host("localhost");
7342 mpd_set_port("6600");
7345 info.xmms2.artist = NULL;
7346 info.xmms2.album = NULL;
7347 info.xmms2.title = NULL;
7348 info.xmms2.genre = NULL;
7349 info.xmms2.comment = NULL;
7350 info.xmms2.url = NULL;
7351 info.xmms2.status = NULL;
7352 info.xmms2.playlist = NULL;
7354 use_spacer = NO_SPACER;
7356 output_methods = TO_X;
7358 output_methods = TO_STDOUT;
7361 show_graph_scale = 0;
7362 show_graph_range = 0;
7365 draw_graph_borders = 1;
7367 set_first_font("6x10");
7375 window.type = TYPE_NORMAL;
7377 strcpy(window.class_name, PACKAGE_NAME);
7378 sprintf(window.title, PACKAGE_NAME" (%s)", info.uname_s.nodename);
7380 stippled_borders = 0;
7383 text_alignment = BOTTOM_LEFT;
7384 info.x11.monitor.number = 1;
7385 info.x11.monitor.current = 0;
7388 for (i = 0; i < MAX_TEMPLATES; i++) {
7389 template[i] = strdup("");
7392 free(current_mail_spool);
7396 variable_substitute(MAIL_FILE, buf, 256);
7397 if (buf[0] != '\0') {
7398 current_mail_spool = strndup(buf, text_buffer_size);
7403 update_interval = 3.0;
7404 info.music_player_interval = 1.0;
7405 stuff_in_upper_case = 0;
7406 info.users.number = 1;
7408 #ifdef TCP_PORT_MONITOR
7409 /* set default connection limit */
7410 tcp_portmon_set_max_connections(0);
7414 /* returns 1 if you can overwrite or create the file at 'path' */
7415 static _Bool overwrite_works(const char *path)
7419 if (!(filepointer = fopen(path, "w")))
7421 fclose(filepointer);
7425 /* returns 1 if you can append or create the file at 'path' */
7426 static _Bool append_works(const char *path)
7430 if (!(filepointer = fopen(path, "a")))
7432 fclose(filepointer);
7437 static void X11_initialisation(void)
7439 if (x_initialised == YES) return;
7440 output_methods |= TO_X;
7442 set_default_configurations_for_x();
7443 x_initialised = YES;
7446 static void X11_destroy_window(void)
7448 /* this function only exists for the sake of consistency */
7449 if (output_methods & TO_X) {
7451 XDamageDestroy(display, x11_stuff.damage);
7452 XFixesDestroyRegion(display, x11_stuff.region2);
7453 XFixesDestroyRegion(display, x11_stuff.part);
7454 if (x11_stuff.region) {
7455 XDestroyRegion(x11_stuff.region);
7457 x11_stuff.region = NULL;
7458 #endif /* HAVE_XDAMAGE */
7463 static char **xargv = 0;
7464 static int xargc = 0;
7466 static void X11_create_window(void)
7468 if (output_methods & TO_X) {
7470 init_window(own_window, text_width + border_margin * 2 + 1,
7471 text_height + border_margin * 2 + 1, set_transparent, background_colour,
7473 #else /* OWN_WINDOW */
7474 init_window(0, text_width + border_margin * 2 + 1,
7475 text_height + border_margin * 2 + 1, set_transparent, 0,
7477 #endif /* OWN_WINDOW */
7481 update_text_area(); /* to position text/window on screen */
7484 if (own_window && !fixed_pos) {
7485 XMoveWindow(display, window.window, window.x, window.y);
7488 set_transparent_background(window.window);
7497 x11_stuff.region = XCreateRegion();
7499 if (!XDamageQueryExtension(display, &x11_stuff.event_base, &x11_stuff.error_base)) {
7500 ERR("Xdamage extension unavailable");
7502 x11_stuff.damage = XDamageCreate(display, window.window, XDamageReportNonEmpty);
7503 x11_stuff.region2 = XFixesCreateRegionFromWindow(display, window.window, 0);
7504 x11_stuff.part = XFixesCreateRegionFromWindow(display, window.window, 0);
7505 #endif /* HAVE_XDAMAGE */
7508 update_text_area(); /* to get initial size of the window */
7513 #define CONF_ERR ERR("%s: %d: config file error", f, line)
7514 #define CONF_ERR2(a) ERR("%s: %d: config file error: %s", f, line, a)
7515 #define CONF2(a) if (strcasecmp(name, a) == 0)
7516 #define CONF(a) else CONF2(a)
7517 #define CONF3(a, b) else if (strcasecmp(name, a) == 0 \
7518 || strcasecmp(name, b) == 0)
7519 #define CONF_CONTINUE 1
7520 #define CONF_BREAK 2
7521 #define CONF_BUFF_SIZE 512
7523 static FILE *open_config_file(const char *f)
7525 #ifdef CONFIG_OUTPUT
7526 if (!strcmp(f, "==builtin==")) {
7527 #ifdef HAVE_FOPENCOOKIE
7528 return fopencookie(NULL, "r", conf_cookie);
7529 #endif /* HAVE_FOPENCOOKIE */
7531 #endif /* CONFIG_OUTPUT */
7532 return fopen(f, "r");
7535 static int do_config_step(int *line, FILE *fp, char *buf, char **name, char **value)
7539 if (fgets(buf, CONF_BUFF_SIZE, fp) == NULL) {
7542 remove_comments(buf);
7547 while (*p && isspace((int) *p)) {
7551 return CONF_CONTINUE; /* empty line */
7558 while (*p2 && !isspace((int) *p2)) {
7562 *p2 = '\0'; /* break at name's end */
7569 while (*p && isspace((int) *p)) {
7575 p2 = *value + strlen(*value);
7576 while (isspace((int) *(p2 - 1))) {
7585 static void load_config_file(const char *f)
7590 set_default_configurations();
7591 fp = open_config_file(f);
7595 DBGP("reading contents from config file '%s'", f);
7598 char buff[CONF_BUFF_SIZE], *name, *value;
7599 int ret = do_config_step(&line, fp, buff, &name, &value);
7600 if (ret == CONF_BREAK) {
7602 } else if (ret == CONF_CONTINUE) {
7608 /* don't listen if X is already initialised or
7609 * if we already know we don't want it */
7610 if(x_initialised == NO) {
7611 if (string_to_bool(value)) {
7612 output_methods &= TO_X;
7614 output_methods &= ~TO_X;
7615 x_initialised = NEVER;
7620 if (!value || x_initialised == YES) {
7625 disp = strdup(value);
7629 if (window.type == TYPE_DOCK)
7632 int a = string_to_alignment(value);
7643 CONF("background") {
7644 fork_to_background = string_to_bool(value);
7647 CONF2("background") {
7648 fork_to_background = string_to_bool(value);
7652 CONF("show_graph_scale") {
7653 show_graph_scale = string_to_bool(value);
7655 CONF("show_graph_range") {
7656 show_graph_range = string_to_bool(value);
7658 CONF("border_margin") {
7660 border_margin = strtol(value, 0, 0);
7665 CONF("border_width") {
7667 border_width = strtol(value, 0, 0);
7673 #define TEMPLATE_CONF(n) \
7674 CONF("template"#n) { \
7676 free(template[n]); \
7677 template[n] = strdup(value); \
7694 info.mail = parse_mail_args(IMAP_TYPE, value);
7701 info.mail = parse_mail_args(POP3_TYPE, value);
7706 CONF("default_bar_size") {
7709 if (sscanf(value, "%d %d", &default_bar_width, &default_bar_height) != 2) {
7716 CONF_ERR2("default_bar_size takes 2 integer arguments (ie. 'default_bar_size 0 6')")
7720 CONF("default_graph_size") {
7723 if (sscanf(value, "%d %d", &default_graph_width, &default_graph_height) != 2) {
7730 CONF_ERR2("default_graph_size takes 2 integer arguments (ie. 'default_graph_size 0 6')")
7733 CONF("default_gauge_size") {
7736 if (sscanf(value, "%d %d", &default_gauge_width, &default_gauge_height) != 2) {
7743 CONF_ERR2("default_gauge_size takes 2 integer arguments (ie. 'default_gauge_size 0 6')")
7750 mpd_set_host(value);
7756 if (value && mpd_set_port(value)) {
7760 CONF("mpd_password") {
7762 mpd_set_password(value);
7768 CONF("music_player_interval") {
7770 info.music_player_interval = strtod(value, 0);
7776 CONF("sensor_device") {
7778 sensor_device = strtol(value, 0, 0);
7784 CONF("cpu_avg_samples") {
7786 cpu_avg_samples = strtol(value, 0, 0);
7787 if (cpu_avg_samples < 1 || cpu_avg_samples > 14) {
7790 info.cpu_avg_samples = cpu_avg_samples;
7796 CONF("net_avg_samples") {
7798 net_avg_samples = strtol(value, 0, 0);
7799 if (net_avg_samples < 1 || net_avg_samples > 14) {
7802 info.net_avg_samples = net_avg_samples;
7808 CONF("diskio_avg_samples") {
7810 diskio_avg_samples = strtol(value, 0, 0);
7811 if (diskio_avg_samples < 1 || diskio_avg_samples > 14) {
7814 info.diskio_avg_samples = diskio_avg_samples;
7822 CONF("double_buffer") {
7823 use_xdbe = string_to_bool(value);
7827 CONF("override_utf8_locale") {
7828 utf8_mode = string_to_bool(value);
7830 CONF("draw_borders") {
7831 draw_borders = string_to_bool(value);
7833 CONF("draw_graph_borders") {
7834 draw_graph_borders = string_to_bool(value);
7836 CONF("draw_shades") {
7837 draw_shades = string_to_bool(value);
7839 CONF("draw_outline") {
7840 draw_outline = string_to_bool(value);
7843 CONF("out_to_console") {
7844 if(string_to_bool(value))
7845 output_methods |= TO_STDOUT;
7847 CONF("out_to_stderr") {
7848 if(string_to_bool(value))
7849 output_methods |= TO_STDERR;
7851 CONF("overwrite_file") {
7852 if(overwrite_file) {
7853 free(overwrite_file);
7856 if(overwrite_works(value)) {
7857 overwrite_file = strdup(value);
7858 output_methods |= OVERWRITE_FILE;
7860 ERR("overwrite_file won't be able to create/overwrite '%s'", value);
7862 CONF("append_file") {
7867 if(append_works(value)) {
7868 append_file = strdup(value);
7869 output_methods |= APPEND_FILE;
7871 ERR("append_file won't be able to create/append '%s'", value);
7873 CONF("use_spacer") {
7875 if (strcasecmp(value, "left") == EQUAL) {
7876 use_spacer = LEFT_SPACER;
7877 } else if (strcasecmp(value, "right") == EQUAL) {
7878 use_spacer = RIGHT_SPACER;
7879 } else if (strcasecmp(value, "none") == EQUAL) {
7880 use_spacer = NO_SPACER;
7882 use_spacer = string_to_bool(value);
7883 ERR("use_spacer should have an argument of left, right, or"
7884 " none. '%s' seems to be some form of '%s', so"
7885 " defaulting to %s.", value,
7886 use_spacer ? "true" : "false",
7887 use_spacer ? "right" : "none");
7889 use_spacer = RIGHT_SPACER;
7891 use_spacer = NO_SPACER;
7895 ERR("use_spacer should have an argument. Defaulting to right.");
7896 use_spacer = RIGHT_SPACER;
7902 use_xft = string_to_bool(value);
7906 set_first_font(value);
7910 if (value && font_count >= 0) {
7911 fonts[0].font_alpha = atof(value) * 65535.0;
7918 if (string_to_bool(value)) {
7919 ERR("Xft not enabled");
7923 /* xftfont silently ignored when no Xft */
7926 /* xftalpha is silently ignored when no Xft */
7931 set_first_font(value);
7939 gap_x = atoi(value);
7946 gap_y = atoi(value);
7952 CONF("mail_spool") {
7956 variable_substitute(value, buffer, 256);
7958 if (buffer[0] != '\0') {
7959 if (current_mail_spool) {
7960 free(current_mail_spool);
7962 current_mail_spool = strndup(buffer, text_buffer_size);
7969 CONF("minimum_size") {
7971 if (sscanf(value, "%d %d", &minimum_width, &minimum_height)
7973 if (sscanf(value, "%d", &minimum_width) != 1) {
7981 CONF("maximum_width") {
7983 if (sscanf(value, "%d", &maximum_width) != 1) {
7991 CONF("no_buffers") {
7992 no_buffers = string_to_bool(value);
7994 CONF("top_name_width") {
7996 if (sscanf(value, "%u", &top_name_width) != 1) {
8002 if (top_name_width >= max_user_text) {
8003 top_name_width = max_user_text - 1;
8006 CONF("top_cpu_separate") {
8007 cpu_separate = string_to_bool(value);
8009 CONF("short_units") {
8010 short_units = string_to_bool(value);
8012 CONF("pad_percents") {
8013 pad_percents = atoi(value);
8017 CONF("own_window") {
8019 own_window = string_to_bool(value);
8022 CONF("own_window_class") {
8024 memset(window.class_name, 0, sizeof(window.class_name));
8025 strncpy(window.class_name, value,
8026 sizeof(window.class_name) - 1);
8029 CONF("own_window_title") {
8031 memset(window.title, 0, sizeof(window.title));
8032 strncpy(window.title, value, sizeof(window.title) - 1);
8035 CONF("own_window_transparent") {
8037 set_transparent = string_to_bool(value);
8040 CONF("own_window_hints") {
8042 char *p_hint, *p_save;
8043 char delim[] = ", ";
8045 /* tokenize the value into individual hints */
8046 if ((p_hint = strtok_r(value, delim, &p_save)) != NULL) {
8048 /* fprintf(stderr, "hint [%s] parsed\n", p_hint); */
8049 if (strncmp(p_hint, "undecorate", 10) == EQUAL) {
8050 SET_HINT(window.hints, HINT_UNDECORATED);
8051 } else if (strncmp(p_hint, "below", 5) == EQUAL) {
8052 SET_HINT(window.hints, HINT_BELOW);
8053 } else if (strncmp(p_hint, "above", 5) == EQUAL) {
8054 SET_HINT(window.hints, HINT_ABOVE);
8055 } else if (strncmp(p_hint, "sticky", 6) == EQUAL) {
8056 SET_HINT(window.hints, HINT_STICKY);
8057 } else if (strncmp(p_hint, "skip_taskbar", 12) == EQUAL) {
8058 SET_HINT(window.hints, HINT_SKIP_TASKBAR);
8059 } else if (strncmp(p_hint, "skip_pager", 10) == EQUAL) {
8060 SET_HINT(window.hints, HINT_SKIP_PAGER);
8065 p_hint = strtok_r(NULL, delim, &p_save);
8066 } while (p_hint != NULL);
8072 CONF("own_window_type") {
8074 if (strncmp(value, "normal", 6) == EQUAL) {
8075 window.type = TYPE_NORMAL;
8076 } else if (strncmp(value, "desktop", 7) == EQUAL) {
8077 window.type = TYPE_DESKTOP;
8078 } else if (strncmp(value, "dock", 7) == EQUAL) {
8079 window.type = TYPE_DOCK;
8080 text_alignment = TOP_LEFT;
8081 } else if (strncmp(value, "override", 8) == EQUAL) {
8082 window.type = TYPE_OVERRIDE;
8091 CONF("stippled_borders") {
8093 stippled_borders = strtol(value, 0, 0);
8095 stippled_borders = 4;
8099 CONF("imlib_cache_size") {
8101 cimlib_set_cache_size(atoi(value));
8104 CONF("imlib_cache_flush_interval") {
8106 cimlib_set_cache_flush_interval(atoi(value));
8111 CONF("update_interval") {
8113 update_interval = strtod(value, 0);
8117 if (info.music_player_interval == 0) {
8118 // default to update_interval
8119 info.music_player_interval = update_interval;
8122 CONF("total_run_times") {
8124 total_run_times = strtod(value, 0);
8130 stuff_in_upper_case = string_to_bool(value);
8132 CONF("max_specials") {
8134 max_specials = atoi(value);
8139 CONF("max_user_text") {
8141 max_user_text = atoi(value);
8146 CONF("text_buffer_size") {
8148 text_buffer_size = atoi(value);
8149 if (text_buffer_size < DEFAULT_TEXT_BUFFER_SIZE) {
8150 ERR("text_buffer_size must be >=%i bytes", DEFAULT_TEXT_BUFFER_SIZE);
8151 text_buffer_size = DEFAULT_TEXT_BUFFER_SIZE;
8159 if (output_methods & TO_X) {
8160 X11_initialisation();
8169 global_text = (char *) malloc(1);
8170 global_text[0] = '\0';
8173 unsigned int l = strlen(global_text);
8175 char buf[CONF_BUFF_SIZE];
8177 if (fgets(buf, CONF_BUFF_SIZE, fp) == NULL) {
8183 if (bl >= 2 && buf[bl-2] == '\\' && buf[bl-1] == '\n') {
8191 /* Check for continuation of \\-\n. */
8192 if (l > 0 && buf[0] == '\n' && global_text[l-1] == '\\') {
8193 global_text[l-1] = '\0';
8197 global_text = (char *) realloc(global_text, l + bl + 1);
8198 strcat(global_text, buf);
8200 if (strlen(global_text) > max_user_text) {
8205 if (strlen(global_text) < 1) {
8206 CRIT_ERR("no text supplied in configuration; exiting");
8208 global_text_lines = line + 1;
8211 #ifdef TCP_PORT_MONITOR
8212 CONF("max_port_monitor_connections") {
8214 if (!value || (sscanf(value, "%d", &max) != 1)) {
8215 /* an error. use default, warn and continue. */
8216 tcp_portmon_set_max_connections(0);
8218 } else if (tcp_portmon_set_max_connections(max)) {
8219 /* max is < 0, default has been set*/
8224 CONF("if_up_strictness") {
8226 ERR("incorrect if_up_strictness value, defaulting to 'up'");
8227 ifup_strictness = IFUP_UP;
8228 } else if (strcasecmp(value, "up") == EQUAL) {
8229 ifup_strictness = IFUP_UP;
8230 } else if (strcasecmp(value, "link") == EQUAL) {
8231 ifup_strictness = IFUP_LINK;
8232 } else if (strcasecmp(value, "address") == EQUAL) {
8233 ifup_strictness = IFUP_ADDR;
8235 ERR("incorrect if_up_strictness value, defaulting to 'up'");
8236 ifup_strictness = IFUP_UP;
8240 CONF("temperature_unit") {
8242 ERR("config option 'temperature_unit' needs an argument, either 'celsius' or 'fahrenheit'");
8243 } else if (set_temp_output_unit(value)) {
8244 ERR("temperature_unit: incorrect argument");
8250 size_t maxlength = strlen(value); //+1 for terminating 0 not needed, 'cause of the space in the middle of value
8251 char *skey = malloc(maxlength);
8252 char *svalue = malloc(maxlength);
8254 if (sscanf(value, "%[0-9a-zA-Z_] %[^\n]", skey, svalue) == 2) {
8255 oldvalue = getenv(skey);
8256 if (oldvalue == NULL) {
8257 setenv(skey, svalue, 0);
8259 //PS: Don't free oldvalue, it's the real envvar, not a copy
8273 char *ptr = strtok(value, " ");
8276 ptr = strtok(NULL, " ");
8282 #endif /* HAVE_LUA */
8294 CONF("default_color"){}
8295 CONF3("default_shade_color", "default_shadecolor"){}
8296 CONF3("default_outline_color", "default_outlinecolor") {}
8297 CONF("own_window_colour") {}
8300 ERR("%s: %d: no such configuration: '%s'", f, line, name);
8306 if (info.music_player_interval == 0) {
8307 // default to update_interval
8308 info.music_player_interval = update_interval;
8310 if (!global_text) { // didn't supply any text
8311 CRIT_ERR("missing text block in configuration; exiting");
8315 static void load_config_file_x11(const char *f)
8320 fp = open_config_file(f);
8324 DBGP("reading contents from config file '%s'", f);
8327 char buff[CONF_BUFF_SIZE], *name, *value;
8328 int ret = do_config_step(&line, fp, buff, &name, &value);
8329 if (ret == CONF_BREAK) {
8331 } else if (ret == CONF_CONTINUE) {
8337 X11_initialisation();
8338 if (x_initialised == YES) {
8340 color0 = get_x11_color(value);
8347 X11_initialisation();
8348 if (x_initialised == YES) {
8350 color1 = get_x11_color(value);
8357 X11_initialisation();
8358 if (x_initialised == YES) {
8360 color2 = get_x11_color(value);
8367 X11_initialisation();
8368 if (x_initialised == YES) {
8370 color3 = get_x11_color(value);
8377 X11_initialisation();
8378 if (x_initialised == YES) {
8380 color4 = get_x11_color(value);
8387 X11_initialisation();
8388 if (x_initialised == YES) {
8390 color5 = get_x11_color(value);
8397 X11_initialisation();
8398 if (x_initialised == YES) {
8400 color6 = get_x11_color(value);
8407 X11_initialisation();
8408 if (x_initialised == YES) {
8410 color7 = get_x11_color(value);
8417 X11_initialisation();
8418 if (x_initialised == YES) {
8420 color8 = get_x11_color(value);
8427 X11_initialisation();
8428 if (x_initialised == YES) {
8430 color9 = get_x11_color(value);
8436 CONF("default_color") {
8437 X11_initialisation();
8438 if (x_initialised == YES) {
8440 default_fg_color = get_x11_color(value);
8446 CONF3("default_shade_color", "default_shadecolor") {
8447 X11_initialisation();
8448 if (x_initialised == YES) {
8450 default_bg_color = get_x11_color(value);
8456 CONF3("default_outline_color", "default_outlinecolor") {
8457 X11_initialisation();
8458 if (x_initialised == YES) {
8460 default_out_color = get_x11_color(value);
8467 CONF("own_window_colour") {
8468 X11_initialisation();
8469 if (x_initialised == YES) {
8471 background_colour = get_x11_color(value);
8473 ERR("Invalid colour for own_window_colour (try omitting the "
8474 "'#' for hex colours");
8480 //initialize X11 if nothing X11-related is mentioned before TEXT (and if X11 is the default outputmethod)
8481 if(output_methods & TO_X) {
8482 X11_initialisation();
8492 #undef CONF_CONTINUE
8493 #undef CONF_BUFF_SIZE
8500 static void print_help(const char *prog_name) {
8501 printf("Usage: %s [OPTION]...\n"
8502 PACKAGE_NAME" is a system monitor that renders text on desktop or to own transparent\n"
8503 "window. Command line options will override configurations defined in config\n"
8505 " -v, --version version\n"
8506 " -q, --quiet quiet mode\n"
8507 " -D, --debug increase debugging output\n"
8508 " -c, --config=FILE config file to load\n"
8509 #ifdef CONFIG_OUTPUT
8510 " -C, --print-config print the builtin default config to stdout\n"
8511 " e.g. 'conky -C > ~/.conkyrc' will create a new default config\n"
8513 " -d, --daemonize daemonize, fork to background\n"
8514 " -h, --help help\n"
8516 " -a, --alignment=ALIGNMENT text alignment on screen, {top,bottom,middle}_{left,right,middle}\n"
8517 " -f, --font=FONT font to use\n"
8518 " -X, --display=DISPLAY X11 display to use\n"
8520 " -o, --own-window create own window to draw\n"
8523 " -b, --double-buffer double buffer (prevents flickering)\n"
8525 " -w, --window-id=WIN_ID window id to draw\n"
8526 " -x X x position\n"
8527 " -y Y y position\n"
8529 " -t, --text=TEXT text to render, remember single quotes, like -t '$uptime'\n"
8530 " -u, --interval=SECS update interval\n"
8531 " -i COUNT number of times to update "PACKAGE_NAME" (and quit)\n",
8536 /* : means that character before that takes an argument */
8537 static const char *getopt_string = "vVqdDt:u:i:hc:"
8547 #ifdef CONFIG_OUTPUT
8552 static const struct option longopts[] = {
8553 { "help", 0, NULL, 'h' },
8554 { "version", 0, NULL, 'V' },
8555 { "debug", 0, NULL, 'D' },
8556 { "config", 1, NULL, 'c' },
8557 #ifdef CONFIG_OUTPUT
8558 { "print-config", 0, NULL, 'C' },
8560 { "daemonize", 0, NULL, 'd' },
8562 { "alignment", 1, NULL, 'a' },
8563 { "font", 1, NULL, 'f' },
8564 { "display", 1, NULL, 'X' },
8566 { "own-window", 0, NULL, 'o' },
8569 { "double-buffer", 0, NULL, 'b' },
8571 { "window-id", 1, NULL, 'w' },
8573 { "text", 1, NULL, 't' },
8574 { "interval", 0, NULL, 'u' },
8578 int main(int argc, char **argv)
8584 struct sigaction act, oact;
8586 g_signal_pending = 0;
8587 memset(&info, 0, sizeof(info));
8590 #ifdef TCP_PORT_MONITOR
8591 /* set default connection limit */
8592 tcp_portmon_set_max_connections(0);
8595 /* handle command line parameters that don't change configs */
8597 if (((s = getenv("LC_ALL")) && *s) || ((s = getenv("LC_CTYPE")) && *s)
8598 || ((s = getenv("LANG")) && *s)) {
8599 temp = (char *) malloc((strlen(s) + 1) * sizeof(char));
8601 ERR("malloc failed");
8603 for (x = 0; x < strlen(s); x++) {
8604 temp[x] = tolower(s[x]);
8607 if (strstr(temp, "utf-8") || strstr(temp, "utf8")) {
8613 if (!setlocale(LC_CTYPE, "")) {
8614 ERR("Can't set the specified locale!\nCheck LANG, LC_CTYPE, LC_ALL.");
8618 int c = getopt_long(argc, argv, getopt_string, longopts, NULL);
8629 if (current_config) {
8630 free(current_config);
8632 current_config = strndup(optarg, max_user_text);
8635 freopen("/dev/null", "w", stderr);
8638 print_help(argv[0]);
8640 #ifdef CONFIG_OUTPUT
8647 window.window = strtol(optarg, 0, 0);
8656 /* check if specified config file is valid */
8657 if (current_config) {
8659 if (stat(current_config, &sb) ||
8660 (!S_ISREG(sb.st_mode) && !S_ISLNK(sb.st_mode))) {
8661 ERR("invalid configuration file '%s'\n", current_config);
8662 free(current_config);
8667 /* load current_config, CONFIG_FILE or SYSTEM_CONFIG_FILE */
8669 if (!current_config) {
8670 /* load default config file */
8671 char buf[DEFAULT_TEXT_BUFFER_SIZE];
8674 /* Try to use personal config file first */
8675 to_real_path(buf, CONFIG_FILE);
8676 if (buf[0] && (fp = fopen(buf, "r"))) {
8677 current_config = strndup(buf, max_user_text);
8681 /* Try to use system config file if personal config not readable */
8682 if (!current_config && (fp = fopen(SYSTEM_CONFIG_FILE, "r"))) {
8683 current_config = strndup(SYSTEM_CONFIG_FILE, max_user_text);
8687 /* No readable config found */
8688 if (!current_config) {
8689 #ifdef CONFIG_OUTPUT
8690 current_config = strdup("==builtin==");
8691 ERR("no readable personal or system-wide config file found,"
8692 " using builtin default");
8694 CRIT_ERR("no readable personal or system-wide config file found");
8695 #endif /* ! CONF_OUTPUT */
8698 #ifdef HAVE_SYS_INOTIFY_H
8699 inotify_fd = inotify_init();
8700 #endif /* HAVE_SYS_INOTIFY_H */
8702 load_config_file(current_config);
8704 /* init specials array */
8705 if ((specials = calloc(sizeof(struct special_t), max_specials)) == 0) {
8706 ERR("failed to create specials array");
8710 if (current_mail_spool == NULL) {
8713 variable_substitute(MAIL_FILE, buf, 256);
8715 if (buf[0] != '\0') {
8716 current_mail_spool = strndup(buf, text_buffer_size);
8721 /* handle other command line arguments */
8723 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__OpenBSD__) \
8724 || defined(__NetBSD__)
8725 optind = optreset = 1;
8730 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
8731 if ((kd = kvm_open("/dev/null", "/dev/null", "/dev/null", O_RDONLY,
8732 "kvm_open")) == NULL) {
8733 CRIT_ERR("cannot read kvm");
8738 int c = getopt_long(argc, argv, getopt_string, longopts, NULL);
8746 fork_to_background = 1;
8749 global_debug_level++;
8753 set_first_font(optarg);
8756 text_alignment = string_to_alignment(optarg);
8761 disp = strdup(optarg);
8780 global_text = strndup(optarg, max_user_text);
8781 convert_escapes(global_text);
8785 update_interval = strtod(optarg, 0);
8786 if (info.music_player_interval == 0) {
8787 // default to update_interval
8788 info.music_player_interval = update_interval;
8793 total_run_times = strtod(optarg, 0);
8797 gap_x = atoi(optarg);
8801 gap_y = atoi(optarg);
8812 if (output_methods & TO_X) {
8813 load_config_file_x11(current_config);
8817 /* generate text and get initial size */
8818 extract_variable_text(global_text);
8825 if (fork_to_background) {
8830 ERR(PACKAGE_NAME": couldn't fork() to background: %s",
8837 fprintf(stderr, "\n");
8842 /* parent process */
8843 fprintf(stderr, PACKAGE_NAME": forked to background, pid is %d\n",
8850 text_buffer = malloc(max_user_text);
8851 memset(text_buffer, 0, max_user_text);
8852 tmpstring1 = malloc(text_buffer_size);
8853 memset(tmpstring1, 0, text_buffer_size);
8854 tmpstring2 = malloc(text_buffer_size);
8855 memset(tmpstring2, 0, text_buffer_size);
8860 X11_create_window();
8863 /* Set signal handlers */
8864 act.sa_handler = signal_handler;
8865 sigemptyset(&act.sa_mask);
8868 act.sa_flags |= SA_RESTART;
8871 if ( sigaction(SIGINT, &act, &oact) < 0
8872 || sigaction(SIGUSR1, &act, &oact) < 0
8873 || sigaction(SIGHUP, &act, &oact) < 0
8874 || sigaction(SIGTERM, &act, &oact) < 0) {
8875 ERR("error setting signal handler: %s", strerror(errno));
8880 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
8887 static void signal_handler(int sig)
8889 /* signal handler is light as a feather, as it should be.
8890 * we will poll g_signal_pending with each loop of conky
8891 * and do any signal processing there, NOT here. */
8892 g_signal_pending = sig;