2008-02-20 20:30:45 +00:00
|
|
|
/* Conky, a system monitor, based on torsmo
|
2005-07-20 00:30:40 +00:00
|
|
|
*
|
2007-08-10 19:53:44 +00:00
|
|
|
* Any original torsmo code is licensed under the BSD license
|
|
|
|
*
|
|
|
|
* All code written since the fork of torsmo is licensed under the GPL
|
|
|
|
*
|
|
|
|
* Please see COPYING for details
|
|
|
|
*
|
|
|
|
* Copyright (c) 2004, Hannu Saransaari and Lauri Hakkarainen
|
2009-03-30 04:55:30 +00:00
|
|
|
* Copyright (c) 2005-2009 Brenden Matthews, Philip Kovacs, et. al.
|
2008-02-20 20:30:45 +00:00
|
|
|
* (see AUTHORS)
|
2007-08-10 19:53:44 +00:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2008-02-20 20:30:45 +00:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2005-08-05 01:06:17 +00:00
|
|
|
*
|
2008-12-09 23:35:49 +00:00
|
|
|
*/
|
2005-07-20 00:30:40 +00:00
|
|
|
|
2008-12-15 21:40:24 +00:00
|
|
|
#include "config.h"
|
2008-12-15 17:31:23 +00:00
|
|
|
#include "text_object.h"
|
2005-07-20 00:30:40 +00:00
|
|
|
#include "conky.h"
|
2008-12-15 21:40:24 +00:00
|
|
|
#include "common.h"
|
2008-04-17 20:40:53 +00:00
|
|
|
#include <stdarg.h>
|
2008-04-17 20:46:29 +00:00
|
|
|
#include <math.h>
|
2005-07-20 00:30:40 +00:00
|
|
|
#include <ctype.h>
|
|
|
|
#include <time.h>
|
|
|
|
#include <locale.h>
|
|
|
|
#include <signal.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <limits.h>
|
|
|
|
#if HAVE_DIRENT_H
|
|
|
|
#include <dirent.h>
|
|
|
|
#endif
|
|
|
|
#include <sys/time.h>
|
2008-12-23 03:59:42 +00:00
|
|
|
#include <sys/param.h>
|
2005-08-08 01:18:52 +00:00
|
|
|
#ifdef X11
|
2008-12-15 21:40:24 +00:00
|
|
|
#include "x11.h"
|
2005-07-20 00:30:40 +00:00
|
|
|
#include <X11/Xutil.h>
|
2006-11-20 20:17:46 +00:00
|
|
|
#ifdef HAVE_XDAMAGE
|
2006-05-24 06:34:37 +00:00
|
|
|
#include <X11/extensions/Xdamage.h>
|
2006-11-20 20:17:46 +00:00
|
|
|
#endif
|
2006-05-25 07:00:12 +00:00
|
|
|
#ifdef IMLIB2
|
|
|
|
#include <Imlib2.h>
|
|
|
|
#endif /* IMLIB2 */
|
2005-08-08 01:18:52 +00:00
|
|
|
#endif /* X11 */
|
2005-07-20 00:30:40 +00:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
2006-05-12 12:41:18 +00:00
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <netdb.h>
|
2007-09-28 20:16:16 +00:00
|
|
|
#include <fcntl.h>
|
2008-01-06 01:35:14 +00:00
|
|
|
#include <getopt.h>
|
2006-03-22 19:35:58 +00:00
|
|
|
|
2008-12-15 21:40:24 +00:00
|
|
|
/* local headers */
|
2008-12-20 01:31:00 +00:00
|
|
|
#include "algebra.h"
|
2008-12-15 21:40:24 +00:00
|
|
|
#include "build.h"
|
2009-02-22 16:53:30 +00:00
|
|
|
#include "colours.h"
|
2008-12-15 21:40:24 +00:00
|
|
|
#include "diskio.h"
|
2009-03-17 17:36:46 +00:00
|
|
|
#ifdef X11
|
2009-02-22 16:53:30 +00:00
|
|
|
#include "fonts.h"
|
2009-03-17 17:36:46 +00:00
|
|
|
#endif
|
2008-12-15 21:40:24 +00:00
|
|
|
#include "fs.h"
|
|
|
|
#include "logging.h"
|
|
|
|
#include "mixer.h"
|
|
|
|
#include "mail.h"
|
|
|
|
#include "mboxscan.h"
|
2009-02-22 16:53:30 +00:00
|
|
|
#include "specials.h"
|
2008-12-15 21:40:24 +00:00
|
|
|
#include "temphelper.h"
|
2009-01-05 12:11:13 +00:00
|
|
|
#include "tailhead.h"
|
2008-12-15 21:40:24 +00:00
|
|
|
#include "top.h"
|
|
|
|
|
|
|
|
/* check for OS and include appropriate headers */
|
|
|
|
#if defined(__linux__)
|
|
|
|
#include "linux.h"
|
|
|
|
#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
|
|
|
|
#include "freebsd.h"
|
|
|
|
#elif defined(__OpenBSD__)
|
|
|
|
#include "openbsd.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* FIXME: apm_getinfo is unused here. maybe it's meant for common.c */
|
|
|
|
#if (defined(__FreeBSD__) || defined(__FreeBSD_kernel__) \
|
|
|
|
|| defined(__OpenBSD__)) && (defined(i386) || defined(__i386__))
|
|
|
|
int apm_getinfo(int fd, apm_info_t aip);
|
|
|
|
char *get_apm_adapter(void);
|
|
|
|
char *get_apm_battery_life(void);
|
|
|
|
char *get_apm_battery_time(void);
|
|
|
|
#endif
|
|
|
|
|
2006-05-13 20:14:26 +00:00
|
|
|
#ifdef HAVE_ICONV
|
2006-05-13 19:51:26 +00:00
|
|
|
#include <iconv.h>
|
|
|
|
#endif
|
|
|
|
|
2008-12-12 14:33:25 +00:00
|
|
|
#ifdef CONFIG_OUTPUT
|
|
|
|
#include "defconfig.h"
|
2008-12-14 13:36:44 +00:00
|
|
|
#ifdef HAVE_FOPENCOOKIE
|
|
|
|
#include "conf_cookie.h"
|
|
|
|
#endif
|
2008-12-12 14:33:25 +00:00
|
|
|
#endif
|
|
|
|
|
2006-12-11 19:04:58 +00:00
|
|
|
#ifndef S_ISSOCK
|
|
|
|
#define S_ISSOCK(x) ((x & S_IFMT) == S_IFSOCK)
|
|
|
|
#endif
|
|
|
|
|
2005-07-20 00:30:40 +00:00
|
|
|
#define MAIL_FILE "$MAIL"
|
|
|
|
#define MAX_IF_BLOCK_DEPTH 5
|
|
|
|
|
2008-09-26 21:09:48 +00:00
|
|
|
//#define SIGNAL_BLOCKING
|
|
|
|
#undef SIGNAL_BLOCKING
|
2005-11-24 02:18:42 +00:00
|
|
|
|
2008-12-15 21:40:24 +00:00
|
|
|
/* debugging level, used by logging.h */
|
2008-11-30 20:53:20 +00:00
|
|
|
int global_debug_level = 0;
|
|
|
|
|
2008-12-15 21:40:24 +00:00
|
|
|
/* two strings for internal use */
|
|
|
|
static char *tmpstring1, *tmpstring2;
|
|
|
|
|
|
|
|
/* variables holding various config settings */
|
|
|
|
int short_units;
|
|
|
|
int cpu_separate;
|
2008-12-16 01:56:26 +00:00
|
|
|
enum {
|
|
|
|
NO_SPACER = 0,
|
|
|
|
LEFT_SPACER,
|
|
|
|
RIGHT_SPACER
|
|
|
|
} use_spacer;
|
2009-02-07 14:01:50 +00:00
|
|
|
int top_cpu, top_mem, top_time;
|
2009-05-07 23:49:32 +00:00
|
|
|
static unsigned int top_name_width = 15;
|
2009-02-22 16:53:30 +00:00
|
|
|
int output_methods;
|
|
|
|
enum x_initialiser_state x_initialised = NO;
|
2008-12-15 21:40:24 +00:00
|
|
|
static volatile int g_signal_pending;
|
|
|
|
/* Update interval */
|
2009-01-05 00:27:07 +00:00
|
|
|
double update_interval;
|
2008-12-15 21:40:24 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* prototypes for internally used functions */
|
|
|
|
static void signal_handler(int);
|
2008-03-29 11:35:02 +00:00
|
|
|
static void print_version(void) __attribute__((noreturn));
|
2008-12-15 21:40:24 +00:00
|
|
|
static void reload_config(void);
|
|
|
|
static void clean_up(void);
|
2008-12-22 16:55:21 +00:00
|
|
|
static void generate_text_internal(char *, int, struct text_object,
|
|
|
|
struct information *);
|
|
|
|
static int extract_variable_text_internal(struct text_object *,
|
|
|
|
const char *, char);
|
2008-03-29 11:35:02 +00:00
|
|
|
|
2008-03-29 02:01:03 +00:00
|
|
|
static void print_version(void)
|
2006-08-12 06:10:18 +00:00
|
|
|
{
|
2008-07-12 10:25:05 +00:00
|
|
|
printf(PACKAGE_NAME" "VERSION" compiled "BUILD_DATE" for "BUILD_ARCH"\n");
|
2006-08-12 06:36:58 +00:00
|
|
|
|
2008-02-20 20:30:45 +00:00
|
|
|
printf("\nCompiled in features:\n\n"
|
2008-07-12 10:25:05 +00:00
|
|
|
"System config file: "SYSTEM_CONFIG_FILE"\n\n"
|
2006-08-12 06:36:58 +00:00
|
|
|
#ifdef X11
|
2008-02-20 20:30:45 +00:00
|
|
|
" X11:\n"
|
2006-08-12 06:36:58 +00:00
|
|
|
# ifdef HAVE_XDAMAGE
|
2008-02-20 20:30:45 +00:00
|
|
|
" * Xdamage extension\n"
|
2006-08-12 06:36:58 +00:00
|
|
|
# endif /* HAVE_XDAMAGE */
|
|
|
|
# ifdef HAVE_XDBE
|
2009-03-18 06:29:01 +00:00
|
|
|
" * XDBE (double buffer extension)\n"
|
2006-08-12 06:36:58 +00:00
|
|
|
# endif /* HAVE_XDBE */
|
2006-11-07 01:19:32 +00:00
|
|
|
# ifdef XFT
|
2009-03-18 06:29:01 +00:00
|
|
|
" * Xft\n"
|
2006-11-07 01:19:32 +00:00
|
|
|
# endif /* XFT */
|
2006-08-12 06:36:58 +00:00
|
|
|
#endif /* X11 */
|
2008-02-20 20:30:45 +00:00
|
|
|
"\n Music detection:\n"
|
2006-08-12 06:36:58 +00:00
|
|
|
#ifdef AUDACIOUS
|
2009-03-18 06:29:01 +00:00
|
|
|
" * Audacious\n"
|
2006-08-12 06:36:58 +00:00
|
|
|
#endif /* AUDACIOUS */
|
|
|
|
#ifdef BMPX
|
2009-03-18 06:29:01 +00:00
|
|
|
" * BMPx\n"
|
2006-08-12 06:36:58 +00:00
|
|
|
#endif /* BMPX */
|
|
|
|
#ifdef MPD
|
2009-03-18 06:29:01 +00:00
|
|
|
" * MPD\n"
|
2006-08-12 06:36:58 +00:00
|
|
|
#endif /* MPD */
|
2008-09-24 06:59:45 +00:00
|
|
|
#ifdef MOC
|
2009-03-18 06:29:01 +00:00
|
|
|
" * MOC\n"
|
2008-09-24 06:59:45 +00:00
|
|
|
#endif /* MOC */
|
2006-11-05 00:23:18 +00:00
|
|
|
#ifdef XMMS2
|
2009-03-18 06:29:01 +00:00
|
|
|
" * XMMS2\n"
|
2006-11-05 00:23:18 +00:00
|
|
|
#endif /* XMMS2 */
|
2009-03-18 06:29:01 +00:00
|
|
|
"\n General:\n"
|
2008-07-01 11:13:40 +00:00
|
|
|
#ifdef MATH
|
|
|
|
" * math\n"
|
|
|
|
#endif /* Math */
|
2006-11-05 00:23:18 +00:00
|
|
|
#ifdef HDDTEMP
|
2008-02-20 20:30:45 +00:00
|
|
|
" * hddtemp\n"
|
2006-11-05 00:23:18 +00:00
|
|
|
#endif /* HDDTEMP */
|
2006-08-12 06:36:58 +00:00
|
|
|
#ifdef TCP_PORT_MONITOR
|
2008-02-20 20:30:45 +00:00
|
|
|
" * portmon\n"
|
2006-08-12 06:36:58 +00:00
|
|
|
#endif /* TCP_PORT_MONITOR */
|
2007-05-06 12:17:13 +00:00
|
|
|
#ifdef RSS
|
2009-03-18 06:29:01 +00:00
|
|
|
" * RSS\n"
|
2007-06-02 08:17:33 +00:00
|
|
|
#endif /* RSS */
|
2007-08-07 22:05:06 +00:00
|
|
|
#ifdef HAVE_IWLIB
|
2008-02-20 20:30:45 +00:00
|
|
|
" * wireless\n"
|
2008-03-18 00:23:16 +00:00
|
|
|
#endif /* HAVE_IWLIB */
|
2009-01-03 23:25:15 +00:00
|
|
|
#ifdef IBM
|
2009-03-18 06:29:01 +00:00
|
|
|
" * support for IBM/Lenovo notebooks\n"
|
2009-01-03 23:25:15 +00:00
|
|
|
#endif /* IBM */
|
2008-06-03 20:46:15 +00:00
|
|
|
#ifdef NVIDIA
|
2009-03-18 06:29:01 +00:00
|
|
|
" * nvidia\n"
|
2008-06-03 20:46:15 +00:00
|
|
|
#endif
|
2009-03-18 06:29:01 +00:00
|
|
|
#ifdef EVE
|
|
|
|
" * eve-online\n"
|
|
|
|
#endif /* EVE */
|
|
|
|
#ifdef CONFIG_OUTPUT
|
|
|
|
" * config-output\n"
|
|
|
|
#endif /* CONFIG_OUTPUT */
|
2009-04-28 16:56:49 +00:00
|
|
|
#ifdef MIXER_IS_ALSA
|
|
|
|
" * ALSA mixer support\n"
|
|
|
|
#endif /* MIXER_IS_ALSA */
|
2008-02-20 20:30:45 +00:00
|
|
|
);
|
2006-08-12 06:36:58 +00:00
|
|
|
|
2006-08-12 06:10:18 +00:00
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
|
2008-07-20 02:05:11 +00:00
|
|
|
static const char *suffixes[] = { "B", "KiB", "MiB", "GiB", "TiB", "PiB", "" };
|
2008-03-23 17:26:41 +00:00
|
|
|
|
2008-09-24 06:59:45 +00:00
|
|
|
|
2006-08-24 18:01:22 +00:00
|
|
|
#ifdef X11
|
|
|
|
|
2008-02-20 20:30:45 +00:00
|
|
|
/* text size */
|
2006-08-24 18:01:22 +00:00
|
|
|
|
|
|
|
static int text_start_x, text_start_y; /* text start position in window */
|
|
|
|
static int text_width, text_height;
|
|
|
|
|
|
|
|
/* alignments */
|
|
|
|
enum alignment {
|
|
|
|
TOP_LEFT = 1,
|
|
|
|
TOP_RIGHT,
|
2008-03-18 00:23:16 +00:00
|
|
|
TOP_MIDDLE,
|
2006-08-24 18:01:22 +00:00
|
|
|
BOTTOM_LEFT,
|
|
|
|
BOTTOM_RIGHT,
|
2008-03-18 00:23:16 +00:00
|
|
|
BOTTOM_MIDDLE,
|
|
|
|
MIDDLE_LEFT,
|
|
|
|
MIDDLE_RIGHT,
|
2006-08-24 18:01:22 +00:00
|
|
|
NONE
|
|
|
|
};
|
|
|
|
|
2009-05-08 14:04:16 +00:00
|
|
|
/* display to connect to */
|
|
|
|
static char *disp = NULL;
|
|
|
|
|
2005-08-08 01:18:52 +00:00
|
|
|
#endif /* X11 */
|
|
|
|
|
2008-12-15 21:40:24 +00:00
|
|
|
/* struct that has all info to be shared between
|
|
|
|
* instances of the same text object */
|
|
|
|
struct information info;
|
|
|
|
|
2005-07-20 00:30:40 +00:00
|
|
|
/* default config file */
|
|
|
|
static char *current_config;
|
|
|
|
|
|
|
|
/* set to 1 if you want all text to be in uppercase */
|
|
|
|
static unsigned int stuff_in_upper_case;
|
|
|
|
|
|
|
|
/* Run how many times? */
|
|
|
|
static unsigned long total_run_times;
|
|
|
|
|
|
|
|
/* fork? */
|
|
|
|
static int fork_to_background;
|
|
|
|
|
2009-05-01 23:03:59 +00:00
|
|
|
static int cpu_avg_samples, net_avg_samples, diskio_avg_samples;
|
2005-08-08 01:18:52 +00:00
|
|
|
|
2009-02-12 21:35:00 +00:00
|
|
|
/* filenames for output */
|
|
|
|
char *overwrite_file = NULL; FILE *overwrite_fpointer = NULL;
|
2009-02-12 21:45:18 +00:00
|
|
|
char *append_file = NULL; FILE *append_fpointer = NULL;
|
2009-02-12 21:35:00 +00:00
|
|
|
|
2005-08-08 01:18:52 +00:00
|
|
|
#ifdef X11
|
|
|
|
|
2008-04-13 04:10:35 +00:00
|
|
|
static int show_graph_scale;
|
2008-06-21 20:37:58 +00:00
|
|
|
static int show_graph_range;
|
2008-04-13 04:10:35 +00:00
|
|
|
|
2005-08-08 01:18:52 +00:00
|
|
|
/* Position on the screen */
|
|
|
|
static int text_alignment;
|
|
|
|
static int gap_x, gap_y;
|
|
|
|
|
2005-07-20 00:30:40 +00:00
|
|
|
/* border */
|
|
|
|
static int draw_borders;
|
2006-01-05 23:23:51 +00:00
|
|
|
static int draw_graph_borders;
|
2005-07-20 00:30:40 +00:00
|
|
|
static int stippled_borders;
|
|
|
|
|
|
|
|
static int draw_shades, draw_outline;
|
|
|
|
|
|
|
|
static int border_margin, border_width;
|
|
|
|
|
|
|
|
static long default_fg_color, default_bg_color, default_out_color;
|
|
|
|
|
|
|
|
/* create own window or draw stuff to root? */
|
2005-08-25 09:24:26 +00:00
|
|
|
static int set_transparent = 0;
|
|
|
|
|
2005-08-06 00:26:14 +00:00
|
|
|
#ifdef OWN_WINDOW
|
2005-08-26 02:16:35 +00:00
|
|
|
static int own_window = 0;
|
|
|
|
static int background_colour = 0;
|
2008-02-20 20:30:45 +00:00
|
|
|
|
2005-07-20 00:30:40 +00:00
|
|
|
/* fixed size/pos is set if wm/user changes them */
|
|
|
|
static int fixed_size = 0, fixed_pos = 0;
|
2005-08-06 00:26:14 +00:00
|
|
|
#endif
|
2005-07-20 00:30:40 +00:00
|
|
|
|
|
|
|
static int minimum_width, minimum_height;
|
2005-08-24 06:21:50 +00:00
|
|
|
static int maximum_width;
|
2005-07-20 00:30:40 +00:00
|
|
|
|
2006-08-27 19:03:52 +00:00
|
|
|
#endif /* X11 */
|
2006-05-13 19:51:26 +00:00
|
|
|
|
2007-03-01 01:43:43 +00:00
|
|
|
#ifdef __OpenBSD__
|
|
|
|
static int sensor_device;
|
|
|
|
#endif
|
|
|
|
|
2008-02-20 20:30:45 +00:00
|
|
|
static long color0, color1, color2, color3, color4, color5, color6, color7,
|
|
|
|
color8, color9;
|
2007-08-05 04:47:21 +00:00
|
|
|
|
2008-11-29 01:34:54 +00:00
|
|
|
static char *template[10];
|
|
|
|
|
2006-11-14 22:10:28 +00:00
|
|
|
/* maximum size of config TEXT buffer, i.e. below TEXT line. */
|
|
|
|
static unsigned int max_user_text = MAX_USER_TEXT_DEFAULT;
|
|
|
|
|
2007-02-12 01:03:10 +00:00
|
|
|
/* maximum size of individual text buffers, ie $exec buffer size */
|
2008-03-20 21:28:19 +00:00
|
|
|
unsigned int text_buffer_size = DEFAULT_TEXT_BUFFER_SIZE;
|
2007-02-12 01:03:10 +00:00
|
|
|
|
2006-05-13 20:14:26 +00:00
|
|
|
#ifdef HAVE_ICONV
|
2006-05-13 19:51:26 +00:00
|
|
|
#define CODEPAGE_LENGTH 20
|
|
|
|
long iconv_selected;
|
2007-06-03 11:20:47 +00:00
|
|
|
long iconv_count = 0;
|
2006-05-13 19:51:26 +00:00
|
|
|
char iconv_converting;
|
|
|
|
static iconv_t **iconv_cd = 0;
|
|
|
|
|
|
|
|
int register_iconv(iconv_t *new_iconv)
|
|
|
|
{
|
2008-03-29 07:24:25 +00:00
|
|
|
iconv_cd = realloc(iconv_cd, sizeof(iconv_t *) * (iconv_count + 1));
|
2006-05-13 19:51:26 +00:00
|
|
|
if (!iconv_cd) {
|
|
|
|
CRIT_ERR("Out of memory");
|
|
|
|
}
|
|
|
|
iconv_cd[iconv_count] = malloc(sizeof(iconv_t));
|
|
|
|
if (!iconv_cd[iconv_count]) {
|
|
|
|
CRIT_ERR("Out of memory");
|
|
|
|
}
|
|
|
|
memcpy(iconv_cd[iconv_count], new_iconv, sizeof(iconv_t));
|
|
|
|
iconv_count++;
|
|
|
|
return iconv_count;
|
|
|
|
}
|
|
|
|
|
|
|
|
void free_iconv(void)
|
|
|
|
{
|
|
|
|
if (iconv_cd) {
|
|
|
|
long i;
|
2008-02-20 20:30:45 +00:00
|
|
|
|
2007-06-03 11:20:47 +00:00
|
|
|
for (i = 0; i < iconv_count; i++) {
|
2006-05-13 19:51:26 +00:00
|
|
|
if (iconv_cd[i]) {
|
2007-06-03 11:20:47 +00:00
|
|
|
iconv_close(*iconv_cd[i]);
|
2006-05-13 19:51:26 +00:00
|
|
|
free(iconv_cd[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
free(iconv_cd);
|
|
|
|
}
|
|
|
|
iconv_cd = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2005-08-08 01:18:52 +00:00
|
|
|
/* UTF-8 */
|
|
|
|
int utf8_mode = 0;
|
|
|
|
|
2005-07-20 00:30:40 +00:00
|
|
|
/* no buffers in used memory? */
|
|
|
|
int no_buffers;
|
|
|
|
|
|
|
|
/* pad percentages to decimals? */
|
|
|
|
static int pad_percents = 0;
|
|
|
|
|
2008-06-21 09:24:56 +00:00
|
|
|
static char *global_text = 0;
|
|
|
|
long global_text_lines;
|
2005-07-20 00:30:40 +00:00
|
|
|
|
|
|
|
static int total_updates;
|
2009-03-01 14:10:01 +00:00
|
|
|
static int updatereset;
|
2005-07-20 00:30:40 +00:00
|
|
|
|
2007-04-06 06:11:53 +00:00
|
|
|
int check_contains(char *f, char *s)
|
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
FILE *where = fopen(f, "r");
|
2008-02-20 20:30:45 +00:00
|
|
|
|
2007-04-06 06:11:53 +00:00
|
|
|
if (where) {
|
|
|
|
char buf1[256], buf2[256];
|
2008-02-20 20:30:45 +00:00
|
|
|
|
2007-04-06 06:11:53 +00:00
|
|
|
while (fgets(buf1, 256, where)) {
|
|
|
|
sscanf(buf1, "%255s", buf2);
|
|
|
|
if (strstr(buf2, s)) {
|
|
|
|
ret = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fclose(where);
|
|
|
|
} else {
|
|
|
|
ERR("Could not open the file");
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2005-08-08 01:18:52 +00:00
|
|
|
#ifdef X11
|
2005-11-17 00:32:39 +00:00
|
|
|
static inline int calc_text_width(const char *s, int l)
|
2005-07-20 00:30:40 +00:00
|
|
|
{
|
2009-02-21 23:37:15 +00:00
|
|
|
if ((output_methods & TO_X) == 0)
|
|
|
|
return 0;
|
2005-07-20 00:30:40 +00:00
|
|
|
#ifdef XFT
|
|
|
|
if (use_xft) {
|
|
|
|
XGlyphInfo gi;
|
2008-02-20 20:30:45 +00:00
|
|
|
|
2005-07-28 04:48:27 +00:00
|
|
|
if (utf8_mode) {
|
2008-02-20 20:30:45 +00:00
|
|
|
XftTextExtentsUtf8(display, fonts[selected_font].xftfont,
|
2008-03-29 03:45:36 +00:00
|
|
|
(const FcChar8 *) s, l, &gi);
|
2005-07-28 04:48:27 +00:00
|
|
|
} else {
|
2008-02-20 20:30:45 +00:00
|
|
|
XftTextExtents8(display, fonts[selected_font].xftfont,
|
2008-03-29 03:45:36 +00:00
|
|
|
(const FcChar8 *) s, l, &gi);
|
2005-07-25 01:13:26 +00:00
|
|
|
}
|
2005-07-20 00:30:40 +00:00
|
|
|
return gi.xOff;
|
|
|
|
} else
|
|
|
|
#endif
|
|
|
|
{
|
2005-08-03 07:01:32 +00:00
|
|
|
return XTextWidth(fonts[selected_font].font, s, l);
|
2005-07-20 00:30:40 +00:00
|
|
|
}
|
|
|
|
}
|
2005-08-08 01:18:52 +00:00
|
|
|
#endif /* X11 */
|
2005-07-20 00:30:40 +00:00
|
|
|
|
|
|
|
/* formatted text to render on screen, generated in generate_text(),
|
|
|
|
* drawn in draw_stuff() */
|
|
|
|
|
2008-03-19 22:28:23 +00:00
|
|
|
static char *text_buffer;
|
2005-07-20 00:30:40 +00:00
|
|
|
|
2005-08-11 05:21:56 +00:00
|
|
|
#ifdef X11
|
2006-11-22 21:53:54 +00:00
|
|
|
static unsigned int special_index; /* used when drawing */
|
2005-08-11 05:21:56 +00:00
|
|
|
#endif /* X11 */
|
2005-07-20 00:30:40 +00:00
|
|
|
|
|
|
|
/* quite boring functions */
|
|
|
|
|
2008-02-20 20:30:45 +00:00
|
|
|
static inline void for_each_line(char *b, void f(char *))
|
2005-07-20 00:30:40 +00:00
|
|
|
{
|
|
|
|
char *ps, *pe;
|
|
|
|
|
|
|
|
for (ps = b, pe = b; *pe; pe++) {
|
|
|
|
if (*pe == '\n') {
|
|
|
|
*pe = '\0';
|
|
|
|
f(ps);
|
|
|
|
*pe = '\n';
|
|
|
|
ps = pe + 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-02-20 20:30:45 +00:00
|
|
|
if (ps < pe) {
|
2005-07-20 00:30:40 +00:00
|
|
|
f(ps);
|
2008-02-20 20:30:45 +00:00
|
|
|
}
|
2005-07-20 00:30:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void convert_escapes(char *buf)
|
|
|
|
{
|
|
|
|
char *p = buf, *s = buf;
|
|
|
|
|
|
|
|
while (*s) {
|
|
|
|
if (*s == '\\') {
|
|
|
|
s++;
|
2008-02-20 20:30:45 +00:00
|
|
|
if (*s == 'n') {
|
2005-07-20 00:30:40 +00:00
|
|
|
*p++ = '\n';
|
2008-02-20 20:30:45 +00:00
|
|
|
} else if (*s == '\\') {
|
2005-07-20 00:30:40 +00:00
|
|
|
*p++ = '\\';
|
2008-02-20 20:30:45 +00:00
|
|
|
}
|
2005-07-20 00:30:40 +00:00
|
|
|
s++;
|
2008-02-20 20:30:45 +00:00
|
|
|
} else {
|
2005-07-20 00:30:40 +00:00
|
|
|
*p++ = *s++;
|
2008-02-20 20:30:45 +00:00
|
|
|
}
|
2005-07-20 00:30:40 +00:00
|
|
|
}
|
|
|
|
*p = '\0';
|
|
|
|
}
|
|
|
|
|
2008-02-09 02:21:06 +00:00
|
|
|
/* Prints anything normally printed with snprintf according to the current value
|
|
|
|
* of use_spacer. Actually slightly more flexible than snprintf, as you can
|
|
|
|
* safely specify the destination buffer as one of your inputs. */
|
2009-02-18 05:00:23 +00:00
|
|
|
int spaced_print(char *buf, int size, const char *format, int width, ...)
|
|
|
|
{
|
2009-02-08 17:29:49 +00:00
|
|
|
int len = 0;
|
2008-02-09 02:21:06 +00:00
|
|
|
va_list argp;
|
2008-03-29 06:24:04 +00:00
|
|
|
char *tempbuf;
|
|
|
|
|
2008-03-20 20:56:13 +00:00
|
|
|
if (size < 1) {
|
|
|
|
return 0;
|
|
|
|
}
|
2008-03-29 06:24:04 +00:00
|
|
|
tempbuf = malloc(size * sizeof(char));
|
2008-02-09 02:21:06 +00:00
|
|
|
|
|
|
|
// Passes the varargs along to vsnprintf
|
2008-12-16 01:56:26 +00:00
|
|
|
va_start(argp, width);
|
2008-02-09 02:21:06 +00:00
|
|
|
vsnprintf(tempbuf, size, format, argp);
|
|
|
|
va_end(argp);
|
|
|
|
|
|
|
|
switch (use_spacer) {
|
|
|
|
case NO_SPACER:
|
|
|
|
len = snprintf(buf, size, "%s", tempbuf);
|
|
|
|
break;
|
|
|
|
case LEFT_SPACER:
|
2009-03-01 19:24:22 +00:00
|
|
|
len = snprintf(buf, size, "%*s", width, tempbuf);
|
2008-02-09 02:21:06 +00:00
|
|
|
break;
|
|
|
|
case RIGHT_SPACER:
|
2009-03-01 19:24:22 +00:00
|
|
|
len = snprintf(buf, size, "%-*s", width, tempbuf);
|
2008-02-09 02:21:06 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
free(tempbuf);
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
2009-03-01 19:53:47 +00:00
|
|
|
/* print percentage values
|
|
|
|
*
|
|
|
|
* - i.e., unsigned values between 0 and 100
|
|
|
|
* - respect the value of pad_percents */
|
|
|
|
static int percent_print(char *buf, int size, unsigned value)
|
|
|
|
{
|
|
|
|
return spaced_print(buf, size, "%u", pad_percents, value);
|
|
|
|
}
|
|
|
|
|
2009-03-01 19:24:22 +00:00
|
|
|
/* converts from bytes to human readable format (K, M, G, T)
|
|
|
|
*
|
|
|
|
* The algorithm always divides by 1024, as unit-conversion of byte
|
|
|
|
* counts suggests. But for output length determination we need to
|
|
|
|
* compare with 1000 here, as we print in decimal form. */
|
2008-12-16 01:56:26 +00:00
|
|
|
static void human_readable(long long num, char *buf, int size)
|
2005-07-20 00:30:40 +00:00
|
|
|
{
|
2008-03-29 03:45:36 +00:00
|
|
|
const char **suffix = suffixes;
|
2008-02-09 02:21:06 +00:00
|
|
|
float fnum;
|
2009-03-01 19:24:22 +00:00
|
|
|
int precision;
|
2008-12-16 02:18:35 +00:00
|
|
|
int width;
|
2009-03-01 19:24:22 +00:00
|
|
|
const char *format;
|
2008-02-09 02:21:06 +00:00
|
|
|
|
2008-12-16 02:18:35 +00:00
|
|
|
if (short_units) {
|
2009-03-01 19:24:22 +00:00
|
|
|
width = 5;
|
|
|
|
format = "%.*f%.1s";
|
2008-12-16 02:18:35 +00:00
|
|
|
} else {
|
2009-03-01 19:24:22 +00:00
|
|
|
width = 7;
|
|
|
|
format = "%.*f%-3s";
|
2008-12-16 02:18:35 +00:00
|
|
|
}
|
|
|
|
|
2009-03-01 19:24:22 +00:00
|
|
|
if (llabs(num) < 1000LL) {
|
|
|
|
spaced_print(buf, size, format, width, 0, (float)num, *suffix);
|
2008-02-09 02:21:06 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-03-01 19:24:22 +00:00
|
|
|
while (llabs(num / 1024) >= 1000LL && **(suffix + 2)) {
|
2008-02-09 02:21:06 +00:00
|
|
|
num /= 1024;
|
|
|
|
suffix++;
|
|
|
|
}
|
|
|
|
|
|
|
|
suffix++;
|
|
|
|
fnum = num / 1024.0;
|
2008-06-15 18:38:33 +00:00
|
|
|
|
2009-03-01 19:24:22 +00:00
|
|
|
/* fnum should now be < 1000, so looks like 'AAA.BBBBB'
|
|
|
|
*
|
|
|
|
* The goal is to always have a significance of 3, by
|
|
|
|
* adjusting the decimal part of the number. Sample output:
|
|
|
|
* 123MiB
|
|
|
|
* 23.4GiB
|
|
|
|
* 5.12B
|
|
|
|
* so the point of alignment resides between number and unit. The
|
|
|
|
* upside of this is that there is minimal padding necessary, though
|
|
|
|
* there should be a way to make alignment take place at the decimal
|
|
|
|
* dot (then with fixed width decimal part). * */
|
|
|
|
|
|
|
|
precision = 0; /* print 100-999 without decimal part */
|
|
|
|
if (fnum < 100)
|
|
|
|
precision = 1; /* print 10-99 with one decimal place */
|
|
|
|
if (fnum < 10)
|
|
|
|
precision = 2; /* print 0-9 with two decimal place */
|
|
|
|
|
|
|
|
spaced_print(buf, size, format, width, precision, fnum, *suffix);
|
2005-07-20 00:30:40 +00:00
|
|
|
}
|
|
|
|
|
2008-12-15 18:09:57 +00:00
|
|
|
/* global object list root element */
|
2008-12-15 01:44:21 +00:00
|
|
|
static struct text_object global_root_object;
|
|
|
|
|
2008-06-21 09:25:22 +00:00
|
|
|
static inline void read_exec(const char *data, char *buf, const int size)
|
|
|
|
{
|
|
|
|
FILE *fp = popen(data, "r");
|
|
|
|
int length = fread(buf, 1, size, fp);
|
|
|
|
|
|
|
|
pclose(fp);
|
|
|
|
buf[length] = '\0';
|
|
|
|
if (length > 0 && buf[length - 1] == '\n') {
|
|
|
|
buf[length - 1] = '\0';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-03-29 11:35:02 +00:00
|
|
|
void *threaded_exec(void *) __attribute__((noreturn));
|
|
|
|
|
2008-03-29 05:14:35 +00:00
|
|
|
void *threaded_exec(void *arg)
|
2008-02-20 20:30:45 +00:00
|
|
|
{
|
2009-05-02 05:05:06 +00:00
|
|
|
char *buff, *p2;
|
2008-03-29 06:24:04 +00:00
|
|
|
struct text_object *obj = (struct text_object *)arg;
|
2008-06-21 09:25:22 +00:00
|
|
|
|
2006-11-15 01:20:49 +00:00
|
|
|
while (1) {
|
2009-05-02 05:05:06 +00:00
|
|
|
buff = malloc(text_buffer_size);
|
|
|
|
read_exec(obj->data.texeci.cmd, buff,
|
2008-06-21 09:25:22 +00:00
|
|
|
text_buffer_size);
|
2009-05-02 05:05:06 +00:00
|
|
|
p2 = buff;
|
2006-02-01 14:39:23 +00:00
|
|
|
while (*p2) {
|
2006-02-13 02:28:46 +00:00
|
|
|
if (*p2 == '\001') {
|
2006-02-01 14:39:23 +00:00
|
|
|
*p2 = ' ';
|
2006-02-13 02:28:46 +00:00
|
|
|
}
|
2006-02-01 14:39:23 +00:00
|
|
|
p2++;
|
|
|
|
}
|
2009-05-02 05:05:06 +00:00
|
|
|
timed_thread_lock(obj->data.texeci.p_timed_thread);
|
|
|
|
strncpy(obj->data.texeci.buffer, buff, text_buffer_size);
|
2008-02-20 20:30:45 +00:00
|
|
|
timed_thread_unlock(obj->data.texeci.p_timed_thread);
|
2009-05-02 05:05:06 +00:00
|
|
|
free(buff);
|
2008-12-09 08:37:59 +00:00
|
|
|
if (timed_thread_test(obj->data.texeci.p_timed_thread, 0)) {
|
2008-02-20 20:30:45 +00:00
|
|
|
timed_thread_exit(obj->data.texeci.p_timed_thread);
|
|
|
|
}
|
2006-01-31 01:31:29 +00:00
|
|
|
}
|
2008-03-29 11:35:02 +00:00
|
|
|
/* never reached */
|
2005-08-29 17:06:31 +00:00
|
|
|
}
|
|
|
|
|
2008-03-29 02:01:03 +00:00
|
|
|
static struct text_object *new_text_object_internal(void)
|
2005-12-10 14:15:38 +00:00
|
|
|
{
|
2006-01-28 01:28:23 +00:00
|
|
|
struct text_object *obj = malloc(sizeof(struct text_object));
|
2006-02-01 14:39:23 +00:00
|
|
|
memset(obj, 0, sizeof(struct text_object));
|
2006-01-28 01:28:23 +00:00
|
|
|
return obj;
|
2005-12-10 14:15:38 +00:00
|
|
|
}
|
|
|
|
|
2008-12-18 12:37:53 +00:00
|
|
|
/* free the list of text objects root points to */
|
|
|
|
static void free_text_objects(struct text_object *root)
|
2005-07-20 00:30:40 +00:00
|
|
|
{
|
2008-06-21 09:24:51 +00:00
|
|
|
struct text_object *obj;
|
|
|
|
|
2008-12-15 01:44:21 +00:00
|
|
|
if (!root->prev) {
|
2008-06-21 09:24:51 +00:00
|
|
|
return;
|
|
|
|
}
|
2008-02-20 20:30:45 +00:00
|
|
|
|
2008-12-15 15:54:57 +00:00
|
|
|
#define data obj->data
|
2008-12-15 01:44:21 +00:00
|
|
|
for (obj = root->prev; obj; obj = root->prev) {
|
|
|
|
root->prev = obj->prev;
|
2008-06-21 09:24:51 +00:00
|
|
|
switch (obj->type) {
|
2007-08-10 21:14:06 +00:00
|
|
|
#ifndef __OpenBSD__
|
2006-01-28 01:28:23 +00:00
|
|
|
case OBJ_acpitemp:
|
2008-12-15 15:54:57 +00:00
|
|
|
close(data.i);
|
2006-01-28 01:28:23 +00:00
|
|
|
break;
|
2009-03-28 19:46:20 +00:00
|
|
|
#endif /* !__OpenBSD__ */
|
|
|
|
#ifdef __linux__
|
2006-01-28 01:28:23 +00:00
|
|
|
case OBJ_i2c:
|
2008-02-20 20:30:45 +00:00
|
|
|
case OBJ_platform:
|
|
|
|
case OBJ_hwmon:
|
2008-12-15 15:54:57 +00:00
|
|
|
close(data.sysfs.fd);
|
2008-02-20 20:30:45 +00:00
|
|
|
break;
|
2009-03-28 19:46:20 +00:00
|
|
|
#endif /* __linux__ */
|
2006-01-28 01:28:23 +00:00
|
|
|
case OBJ_time:
|
|
|
|
case OBJ_utime:
|
2008-12-15 15:54:57 +00:00
|
|
|
free(data.s);
|
2006-07-15 02:18:06 +00:00
|
|
|
break;
|
|
|
|
case OBJ_tztime:
|
2008-12-15 15:54:57 +00:00
|
|
|
free(data.tztime.tz);
|
|
|
|
free(data.tztime.fmt);
|
2006-07-15 02:18:06 +00:00
|
|
|
break;
|
2007-02-12 01:03:10 +00:00
|
|
|
case OBJ_mboxscan:
|
2008-12-15 15:54:57 +00:00
|
|
|
free(data.mboxscan.args);
|
|
|
|
free(data.mboxscan.output);
|
2007-02-12 01:03:10 +00:00
|
|
|
break;
|
2007-10-02 23:57:41 +00:00
|
|
|
case OBJ_mails:
|
|
|
|
case OBJ_new_mails:
|
2009-02-18 05:26:15 +00:00
|
|
|
case OBJ_seen_mails:
|
|
|
|
case OBJ_unseen_mails:
|
|
|
|
case OBJ_flagged_mails:
|
|
|
|
case OBJ_unflagged_mails:
|
|
|
|
case OBJ_forwarded_mails:
|
|
|
|
case OBJ_unforwarded_mails:
|
|
|
|
case OBJ_replied_mails:
|
|
|
|
case OBJ_unreplied_mails:
|
|
|
|
case OBJ_draft_mails:
|
|
|
|
case OBJ_trashed_mails:
|
2008-12-15 15:54:57 +00:00
|
|
|
free(data.local_mail.box);
|
2007-10-02 23:57:41 +00:00
|
|
|
break;
|
2006-05-08 22:34:38 +00:00
|
|
|
case OBJ_imap_unseen:
|
2008-06-21 09:24:51 +00:00
|
|
|
if (!obj->global_mode) {
|
2008-12-15 15:54:57 +00:00
|
|
|
free(data.mail);
|
2006-05-08 22:34:38 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case OBJ_imap_messages:
|
2008-06-21 09:24:51 +00:00
|
|
|
if (!obj->global_mode) {
|
2008-12-15 15:54:57 +00:00
|
|
|
free(data.mail);
|
2006-05-08 22:34:38 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case OBJ_pop3_unseen:
|
2008-06-21 09:24:51 +00:00
|
|
|
if (!obj->global_mode) {
|
2008-12-15 15:54:57 +00:00
|
|
|
free(data.mail);
|
2006-05-08 22:34:38 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case OBJ_pop3_used:
|
2008-06-21 09:24:51 +00:00
|
|
|
if (!obj->global_mode) {
|
2008-12-15 15:54:57 +00:00
|
|
|
free(data.mail);
|
2006-05-08 22:34:38 +00:00
|
|
|
}
|
|
|
|
break;
|
2007-04-06 05:01:48 +00:00
|
|
|
case OBJ_if_empty:
|
2008-12-20 01:31:00 +00:00
|
|
|
case OBJ_if_match:
|
2008-12-22 17:36:44 +00:00
|
|
|
free_text_objects(obj->sub);
|
|
|
|
free(obj->sub);
|
|
|
|
/* fall through */
|
2006-01-28 01:28:23 +00:00
|
|
|
case OBJ_if_existing:
|
|
|
|
case OBJ_if_mounted:
|
|
|
|
case OBJ_if_running:
|
2008-12-15 15:54:57 +00:00
|
|
|
free(data.ifblock.s);
|
|
|
|
free(data.ifblock.str);
|
2006-01-28 01:28:23 +00:00
|
|
|
break;
|
|
|
|
case OBJ_tail:
|
2008-12-15 15:54:57 +00:00
|
|
|
free(data.tail.logfile);
|
|
|
|
free(data.tail.buffer);
|
2006-01-28 01:28:23 +00:00
|
|
|
break;
|
2007-08-05 04:47:21 +00:00
|
|
|
case OBJ_text:
|
|
|
|
case OBJ_font:
|
2006-05-25 07:00:12 +00:00
|
|
|
case OBJ_image:
|
2009-03-23 23:27:51 +00:00
|
|
|
case OBJ_eval:
|
2006-01-28 01:28:23 +00:00
|
|
|
case OBJ_exec:
|
2009-03-11 00:37:24 +00:00
|
|
|
case OBJ_execgauge:
|
2006-01-28 01:28:23 +00:00
|
|
|
case OBJ_execbar:
|
|
|
|
case OBJ_execgraph:
|
2008-03-22 06:10:54 +00:00
|
|
|
case OBJ_execp:
|
2008-12-15 15:54:57 +00:00
|
|
|
free(data.s);
|
2006-01-28 01:28:23 +00:00
|
|
|
break;
|
2006-05-13 20:14:26 +00:00
|
|
|
#ifdef HAVE_ICONV
|
2006-05-13 19:51:26 +00:00
|
|
|
case OBJ_iconv_start:
|
|
|
|
free_iconv();
|
|
|
|
break;
|
|
|
|
#endif
|
2009-03-28 17:47:53 +00:00
|
|
|
#ifdef __linux__
|
2008-03-24 20:08:16 +00:00
|
|
|
case OBJ_disk_protect:
|
2009-03-28 17:47:53 +00:00
|
|
|
free(data.s);
|
2008-03-24 20:08:16 +00:00
|
|
|
break;
|
2008-03-22 19:06:09 +00:00
|
|
|
case OBJ_if_gw:
|
2009-03-28 17:47:53 +00:00
|
|
|
free(data.ifblock.s);
|
|
|
|
free(data.ifblock.str);
|
2008-03-22 19:06:09 +00:00
|
|
|
case OBJ_gw_iface:
|
|
|
|
case OBJ_gw_ip:
|
|
|
|
if (info.gw_info.iface) {
|
|
|
|
free(info.gw_info.iface);
|
|
|
|
info.gw_info.iface = 0;
|
|
|
|
}
|
|
|
|
if (info.gw_info.ip) {
|
|
|
|
free(info.gw_info.ip);
|
|
|
|
info.gw_info.ip = 0;
|
|
|
|
}
|
|
|
|
break;
|
2008-03-22 21:10:43 +00:00
|
|
|
case OBJ_ioscheduler:
|
2009-03-28 17:47:53 +00:00
|
|
|
if(data.s)
|
|
|
|
free(data.s);
|
2008-03-22 21:10:43 +00:00
|
|
|
break;
|
2008-03-18 00:23:16 +00:00
|
|
|
#endif
|
2009-03-28 23:15:20 +00:00
|
|
|
#if (defined(__FreeBSD__) || defined(__linux__))
|
|
|
|
case OBJ_if_up:
|
|
|
|
free(data.ifblock.s);
|
|
|
|
free(data.ifblock.str);
|
|
|
|
#endif
|
2006-03-25 21:21:07 +00:00
|
|
|
#ifdef XMMS2
|
|
|
|
case OBJ_xmms2_artist:
|
|
|
|
if (info.xmms2.artist) {
|
|
|
|
free(info.xmms2.artist);
|
|
|
|
info.xmms2.artist = 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case OBJ_xmms2_album:
|
|
|
|
if (info.xmms2.album) {
|
|
|
|
free(info.xmms2.album);
|
|
|
|
info.xmms2.album = 0;
|
|
|
|
}
|
|
|
|
break;
|
2006-04-16 03:49:49 +00:00
|
|
|
case OBJ_xmms2_title:
|
|
|
|
if (info.xmms2.title) {
|
|
|
|
free(info.xmms2.title);
|
|
|
|
info.xmms2.title = 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case OBJ_xmms2_genre:
|
|
|
|
if (info.xmms2.genre) {
|
|
|
|
free(info.xmms2.genre);
|
|
|
|
info.xmms2.genre = 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case OBJ_xmms2_comment:
|
|
|
|
if (info.xmms2.comment) {
|
|
|
|
free(info.xmms2.comment);
|
|
|
|
info.xmms2.comment = 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case OBJ_xmms2_url:
|
|
|
|
if (info.xmms2.url) {
|
|
|
|
free(info.xmms2.url);
|
|
|
|
info.xmms2.url = 0;
|
2006-03-25 21:21:07 +00:00
|
|
|
}
|
|
|
|
break;
|
2006-04-16 03:49:49 +00:00
|
|
|
case OBJ_xmms2_date:
|
|
|
|
if (info.xmms2.date) {
|
|
|
|
free(info.xmms2.date);
|
|
|
|
info.xmms2.date = 0;
|
2006-03-25 21:21:07 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case OBJ_xmms2_status:
|
|
|
|
if (info.xmms2.status) {
|
|
|
|
free(info.xmms2.status);
|
|
|
|
info.xmms2.status = 0;
|
|
|
|
}
|
|
|
|
break;
|
2008-03-18 00:23:16 +00:00
|
|
|
case OBJ_xmms2_playlist:
|
|
|
|
if (info.xmms2.playlist) {
|
|
|
|
free(info.xmms2.playlist);
|
|
|
|
info.xmms2.playlist = 0;
|
|
|
|
}
|
|
|
|
break;
|
2006-04-16 03:49:49 +00:00
|
|
|
case OBJ_xmms2_smart:
|
2006-03-25 21:21:07 +00:00
|
|
|
if (info.xmms2.artist) {
|
|
|
|
free(info.xmms2.artist);
|
|
|
|
info.xmms2.artist = 0;
|
|
|
|
}
|
|
|
|
if (info.xmms2.title) {
|
|
|
|
free(info.xmms2.title);
|
|
|
|
info.xmms2.title = 0;
|
|
|
|
}
|
2006-04-16 03:49:49 +00:00
|
|
|
if (info.xmms2.url) {
|
|
|
|
free(info.xmms2.url);
|
|
|
|
info.xmms2.url = 0;
|
2006-03-25 21:21:07 +00:00
|
|
|
}
|
2006-04-16 03:49:49 +00:00
|
|
|
break;
|
2006-03-25 21:21:07 +00:00
|
|
|
#endif
|
2005-12-30 09:44:40 +00:00
|
|
|
#ifdef BMPX
|
2006-01-28 01:28:23 +00:00
|
|
|
case OBJ_bmpx_title:
|
|
|
|
case OBJ_bmpx_artist:
|
|
|
|
case OBJ_bmpx_album:
|
|
|
|
case OBJ_bmpx_track:
|
|
|
|
case OBJ_bmpx_uri:
|
|
|
|
case OBJ_bmpx_bitrate:
|
2008-02-20 10:01:00 +00:00
|
|
|
break;
|
2007-05-06 12:17:13 +00:00
|
|
|
#endif
|
2008-06-28 20:14:04 +00:00
|
|
|
#ifdef EVE
|
2008-07-12 01:22:40 +00:00
|
|
|
case OBJ_eve:
|
|
|
|
break;
|
2008-06-28 20:14:04 +00:00
|
|
|
#endif
|
2007-05-06 12:17:13 +00:00
|
|
|
#ifdef RSS
|
|
|
|
case OBJ_rss:
|
2008-12-15 15:54:57 +00:00
|
|
|
free(data.rss.uri);
|
|
|
|
free(data.rss.action);
|
2007-06-03 11:20:47 +00:00
|
|
|
break;
|
2005-07-20 00:30:40 +00:00
|
|
|
#endif
|
2006-01-28 01:28:23 +00:00
|
|
|
case OBJ_pre_exec:
|
2008-02-20 10:01:00 +00:00
|
|
|
break;
|
2007-08-10 21:06:30 +00:00
|
|
|
#ifndef __OpenBSD__
|
2006-01-28 01:28:23 +00:00
|
|
|
case OBJ_battery:
|
2008-12-15 15:54:57 +00:00
|
|
|
free(data.s);
|
2006-01-28 01:28:23 +00:00
|
|
|
break;
|
2009-02-22 17:35:47 +00:00
|
|
|
case OBJ_battery_short:
|
2009-02-18 04:49:45 +00:00
|
|
|
free(data.s);
|
|
|
|
break;
|
2006-12-12 23:21:14 +00:00
|
|
|
case OBJ_battery_time:
|
2008-12-15 15:54:57 +00:00
|
|
|
free(data.s);
|
2006-12-12 23:21:14 +00:00
|
|
|
break;
|
2007-08-10 21:06:30 +00:00
|
|
|
#endif /* !__OpenBSD__ */
|
2008-03-22 06:10:54 +00:00
|
|
|
case OBJ_execpi:
|
2006-01-28 01:28:23 +00:00
|
|
|
case OBJ_execi:
|
2008-03-22 06:10:54 +00:00
|
|
|
case OBJ_execibar:
|
|
|
|
case OBJ_execigraph:
|
2009-04-10 02:10:08 +00:00
|
|
|
case OBJ_execigauge:
|
2008-12-15 15:54:57 +00:00
|
|
|
free(data.execi.cmd);
|
|
|
|
free(data.execi.buffer);
|
2006-01-28 01:28:23 +00:00
|
|
|
break;
|
|
|
|
case OBJ_texeci:
|
2008-12-15 15:54:57 +00:00
|
|
|
free(data.texeci.cmd);
|
|
|
|
free(data.texeci.buffer);
|
2006-01-28 01:28:23 +00:00
|
|
|
break;
|
2008-03-22 22:58:26 +00:00
|
|
|
case OBJ_nameserver:
|
|
|
|
free_dns_data();
|
|
|
|
break;
|
2006-01-28 01:28:23 +00:00
|
|
|
case OBJ_top:
|
|
|
|
case OBJ_top_mem:
|
2009-02-08 15:16:12 +00:00
|
|
|
case OBJ_top_time:
|
2006-01-28 01:28:23 +00:00
|
|
|
if (info.first_process) {
|
|
|
|
free_all_processes();
|
|
|
|
info.first_process = NULL;
|
|
|
|
}
|
|
|
|
break;
|
2006-08-10 16:56:13 +00:00
|
|
|
#ifdef HDDTEMP
|
|
|
|
case OBJ_hddtemp:
|
2008-12-15 15:54:57 +00:00
|
|
|
free(data.hddtemp.dev);
|
|
|
|
free(data.hddtemp.addr);
|
|
|
|
if (data.hddtemp.temp)
|
|
|
|
free(data.hddtemp.temp);
|
2006-08-10 16:56:13 +00:00
|
|
|
break;
|
|
|
|
#endif
|
2006-11-30 20:46:34 +00:00
|
|
|
case OBJ_entropy_avail:
|
|
|
|
case OBJ_entropy_poolsize:
|
|
|
|
case OBJ_entropy_bar:
|
|
|
|
break;
|
2008-03-18 00:23:16 +00:00
|
|
|
case OBJ_user_names:
|
|
|
|
if (info.users.names) {
|
|
|
|
free(info.users.names);
|
|
|
|
info.users.names = 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case OBJ_user_terms:
|
|
|
|
if (info.users.terms) {
|
|
|
|
free(info.users.terms);
|
|
|
|
info.users.terms = 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case OBJ_user_times:
|
|
|
|
if (info.users.times) {
|
|
|
|
free(info.users.times);
|
|
|
|
info.users.times = 0;
|
|
|
|
}
|
|
|
|
break;
|
2009-01-03 23:25:15 +00:00
|
|
|
#ifdef IBM
|
2008-03-22 18:08:47 +00:00
|
|
|
case OBJ_smapi:
|
|
|
|
case OBJ_smapi_bat_perc:
|
2008-06-25 10:08:27 +00:00
|
|
|
case OBJ_smapi_bat_temp:
|
|
|
|
case OBJ_smapi_bat_power:
|
2008-12-15 15:54:57 +00:00
|
|
|
free(data.s);
|
2008-03-22 18:08:47 +00:00
|
|
|
break;
|
|
|
|
case OBJ_if_smapi_bat_installed:
|
2008-12-15 15:54:57 +00:00
|
|
|
free(data.ifblock.s);
|
|
|
|
free(data.ifblock.str);
|
2008-03-22 18:08:47 +00:00
|
|
|
break;
|
|
|
|
#endif
|
2008-06-03 20:46:15 +00:00
|
|
|
#ifdef NVIDIA
|
|
|
|
case OBJ_nvidia:
|
2008-06-15 18:38:33 +00:00
|
|
|
break;
|
2008-06-03 20:46:15 +00:00
|
|
|
#endif
|
2008-03-20 20:33:31 +00:00
|
|
|
#ifdef MPD
|
|
|
|
case OBJ_mpd_title:
|
|
|
|
case OBJ_mpd_artist:
|
|
|
|
case OBJ_mpd_album:
|
|
|
|
case OBJ_mpd_random:
|
|
|
|
case OBJ_mpd_repeat:
|
|
|
|
case OBJ_mpd_vol:
|
|
|
|
case OBJ_mpd_bitrate:
|
|
|
|
case OBJ_mpd_status:
|
|
|
|
case OBJ_mpd_bar:
|
|
|
|
case OBJ_mpd_elapsed:
|
|
|
|
case OBJ_mpd_length:
|
|
|
|
case OBJ_mpd_track:
|
|
|
|
case OBJ_mpd_name:
|
|
|
|
case OBJ_mpd_file:
|
|
|
|
case OBJ_mpd_percent:
|
|
|
|
case OBJ_mpd_smart:
|
2008-10-08 11:44:27 +00:00
|
|
|
case OBJ_if_mpd_playing:
|
2008-12-18 12:37:53 +00:00
|
|
|
free_mpd();
|
2008-03-20 20:33:31 +00:00
|
|
|
break;
|
2008-09-24 06:59:45 +00:00
|
|
|
#endif
|
|
|
|
#ifdef MOC
|
2008-12-22 18:31:48 +00:00
|
|
|
case OBJ_moc_state:
|
|
|
|
case OBJ_moc_file:
|
|
|
|
case OBJ_moc_title:
|
|
|
|
case OBJ_moc_artist:
|
|
|
|
case OBJ_moc_song:
|
|
|
|
case OBJ_moc_album:
|
|
|
|
case OBJ_moc_totaltime:
|
|
|
|
case OBJ_moc_timeleft:
|
|
|
|
case OBJ_moc_curtime:
|
|
|
|
case OBJ_moc_bitrate:
|
|
|
|
case OBJ_moc_rate:
|
|
|
|
free_moc();
|
|
|
|
break;
|
2008-03-20 20:33:31 +00:00
|
|
|
#endif
|
2008-06-21 20:37:58 +00:00
|
|
|
case OBJ_scroll:
|
2008-12-15 15:54:57 +00:00
|
|
|
free(data.scroll.text);
|
2008-12-22 17:36:44 +00:00
|
|
|
free_text_objects(obj->sub);
|
|
|
|
free(obj->sub);
|
2008-06-21 20:37:58 +00:00
|
|
|
break;
|
2009-04-30 19:05:59 +00:00
|
|
|
case OBJ_combine:
|
|
|
|
free(data.combine.left);
|
|
|
|
free(data.combine.seperation);
|
|
|
|
free(data.combine.right);
|
|
|
|
free_text_objects(obj->sub);
|
|
|
|
free(obj->sub);
|
|
|
|
break;
|
2005-07-20 00:30:40 +00:00
|
|
|
}
|
2008-12-15 01:44:21 +00:00
|
|
|
free(obj);
|
2005-07-20 00:30:40 +00:00
|
|
|
}
|
2008-12-15 15:54:57 +00:00
|
|
|
#undef data
|
2005-07-20 00:30:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void scan_mixer_bar(const char *arg, int *a, int *w, int *h)
|
|
|
|
{
|
|
|
|
char buf1[64];
|
|
|
|
int n;
|
|
|
|
|
|
|
|
if (arg && sscanf(arg, "%63s %n", buf1, &n) >= 1) {
|
|
|
|
*a = mixer_init(buf1);
|
2008-02-20 20:30:45 +00:00
|
|
|
scan_bar(arg + n, w, h);
|
2005-07-20 00:30:40 +00:00
|
|
|
} else {
|
2008-02-20 20:30:45 +00:00
|
|
|
*a = mixer_init(NULL);
|
|
|
|
scan_bar(arg, w, h);
|
2005-07-20 00:30:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-12-14 16:53:31 +00:00
|
|
|
/* strip a leading /dev/ if any, following symlinks first
|
|
|
|
*
|
|
|
|
* BEWARE: this function returns a pointer to static content
|
|
|
|
* which gets overwritten in consecutive calls. I.e.:
|
|
|
|
* this function is NOT reentrant.
|
|
|
|
*/
|
2008-12-16 01:32:30 +00:00
|
|
|
static const char *dev_name(const char *path)
|
2008-12-14 16:53:31 +00:00
|
|
|
{
|
|
|
|
static char buf[255]; /* should be enough for pathnames */
|
|
|
|
ssize_t buflen;
|
|
|
|
|
2008-12-16 01:32:30 +00:00
|
|
|
if (!path)
|
|
|
|
return NULL;
|
|
|
|
|
2008-12-14 16:53:31 +00:00
|
|
|
#define DEV_NAME(x) \
|
|
|
|
x != NULL && strlen(x) > 5 && strncmp(x, "/dev/", 5) == 0 ? x + 5 : x
|
|
|
|
if ((buflen = readlink(path, buf, 254)) == -1)
|
|
|
|
return DEV_NAME(path);
|
|
|
|
buf[buflen] = '\0';
|
|
|
|
return DEV_NAME(buf);
|
|
|
|
#undef DEV_NAME
|
|
|
|
}
|
2008-03-31 15:33:54 +00:00
|
|
|
|
2005-07-20 00:30:40 +00:00
|
|
|
/* construct_text_object() creates a new text_object */
|
2008-02-20 20:30:45 +00:00
|
|
|
static struct text_object *construct_text_object(const char *s,
|
2008-12-22 16:45:08 +00:00
|
|
|
const char *arg, long line, char allow_threaded, void **ifblock_opaque)
|
2005-07-20 00:30:40 +00:00
|
|
|
{
|
2008-02-20 20:30:45 +00:00
|
|
|
// struct text_object *obj = new_text_object();
|
2006-01-28 01:28:23 +00:00
|
|
|
struct text_object *obj = new_text_object_internal();
|
2008-02-20 20:30:45 +00:00
|
|
|
|
2006-05-14 07:05:05 +00:00
|
|
|
obj->line = line;
|
2005-07-20 00:30:40 +00:00
|
|
|
|
2008-02-20 20:30:45 +00:00
|
|
|
#define OBJ(a, n) if (strcmp(s, #a) == 0) { \
|
|
|
|
obj->type = OBJ_##a; need_mask |= (1 << n); {
|
2008-12-22 18:43:12 +00:00
|
|
|
#define OBJ_IF(a, n) if (strcmp(s, #a) == 0) { \
|
|
|
|
obj->type = OBJ_##a; need_mask |= (1 << n); \
|
|
|
|
obj_be_ifblock_if(ifblock_opaque, obj); {
|
2008-07-17 03:14:37 +00:00
|
|
|
#define OBJ_THREAD(a, n) if (strcmp(s, #a) == 0 && allow_threaded) { \
|
|
|
|
obj->type = OBJ_##a; need_mask |= (1 << n); {
|
2008-02-20 20:30:45 +00:00
|
|
|
#define END } } else
|
2005-07-20 00:30:40 +00:00
|
|
|
|
2008-02-20 20:30:45 +00:00
|
|
|
#ifdef X11
|
2006-01-28 01:28:23 +00:00
|
|
|
if (s[0] == '#') {
|
2005-07-20 00:30:40 +00:00
|
|
|
obj->type = OBJ_color;
|
|
|
|
obj->data.l = get_x11_color(s);
|
|
|
|
} else
|
2005-08-08 01:18:52 +00:00
|
|
|
#endif /* X11 */
|
2007-08-10 21:16:44 +00:00
|
|
|
#ifdef __OpenBSD__
|
|
|
|
OBJ(freq, INFO_FREQ)
|
|
|
|
#else
|
2008-02-20 20:30:45 +00:00
|
|
|
OBJ(acpitemp, 0)
|
|
|
|
obj->data.i = open_acpi_temperature(arg);
|
|
|
|
END OBJ(acpiacadapter, 0)
|
2006-12-23 06:01:16 +00:00
|
|
|
END OBJ(freq, INFO_FREQ)
|
2008-02-20 20:30:45 +00:00
|
|
|
#endif /* !__OpenBSD__ */
|
|
|
|
get_cpu_count();
|
|
|
|
if (!arg || !isdigit(arg[0]) || strlen(arg) >= 2 || atoi(&arg[0]) == 0
|
|
|
|
|| (unsigned int) atoi(&arg[0]) > info.cpu_count) {
|
|
|
|
obj->data.cpu_index = 1;
|
|
|
|
/* ERR("freq: Invalid CPU number or you don't have that many CPUs! "
|
|
|
|
"Displaying the clock for CPU 1."); */
|
|
|
|
} else {
|
|
|
|
obj->data.cpu_index = atoi(&arg[0]);
|
|
|
|
}
|
|
|
|
obj->a = 1;
|
2006-12-23 06:01:16 +00:00
|
|
|
END OBJ(freq_g, INFO_FREQ)
|
2008-02-20 20:30:45 +00:00
|
|
|
get_cpu_count();
|
|
|
|
if (!arg || !isdigit(arg[0]) || strlen(arg) >= 2 || atoi(&arg[0]) == 0
|
|
|
|
|| (unsigned int) atoi(&arg[0]) > info.cpu_count) {
|
|
|
|
obj->data.cpu_index = 1;
|
|
|
|
/* ERR("freq_g: Invalid CPU number or you don't have that many "
|
|
|
|
"CPUs! Displaying the clock for CPU 1."); */
|
|
|
|
} else {
|
|
|
|
obj->data.cpu_index = atoi(&arg[0]);
|
|
|
|
}
|
|
|
|
obj->a = 1;
|
2006-12-03 18:10:21 +00:00
|
|
|
#if defined(__linux__)
|
2006-05-24 00:23:47 +00:00
|
|
|
END OBJ(voltage_mv, 0)
|
2008-02-20 20:30:45 +00:00
|
|
|
get_cpu_count();
|
|
|
|
if (!arg || !isdigit(arg[0]) || strlen(arg) >= 2 || atoi(&arg[0]) == 0
|
|
|
|
|| (unsigned int) atoi(&arg[0]) > info.cpu_count) {
|
|
|
|
obj->data.cpu_index = 1;
|
|
|
|
/* ERR("voltage_mv: Invalid CPU number or you don't have that many "
|
|
|
|
"CPUs! Displaying voltage for CPU 1."); */
|
|
|
|
} else {
|
|
|
|
obj->data.cpu_index = atoi(&arg[0]);
|
|
|
|
}
|
|
|
|
obj->a = 1;
|
2006-05-24 00:23:47 +00:00
|
|
|
END OBJ(voltage_v, 0)
|
2008-02-20 20:30:45 +00:00
|
|
|
get_cpu_count();
|
|
|
|
if (!arg || !isdigit(arg[0]) || strlen(arg) >= 2 || atoi(&arg[0]) == 0
|
|
|
|
|| (unsigned int) atoi(&arg[0]) > info.cpu_count) {
|
|
|
|
obj->data.cpu_index = 1;
|
|
|
|
/* ERR("voltage_v: Invalid CPU number or you don't have that many "
|
|
|
|
"CPUs! Displaying voltage for CPU 1."); */
|
|
|
|
} else {
|
|
|
|
obj->data.cpu_index = atoi(&arg[0]);
|
|
|
|
}
|
|
|
|
obj->a = 1;
|
2007-08-07 12:51:08 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_IWLIB
|
|
|
|
END OBJ(wireless_essid, INFO_NET)
|
2008-02-20 20:30:45 +00:00
|
|
|
if (arg) {
|
|
|
|
obj->data.net = get_net_stat(arg);
|
|
|
|
} else {
|
|
|
|
CRIT_ERR("wireless_essid: needs an argument");
|
|
|
|
}
|
2007-08-07 12:51:08 +00:00
|
|
|
END OBJ(wireless_mode, INFO_NET)
|
2008-02-20 20:30:45 +00:00
|
|
|
if (arg) {
|
|
|
|
obj->data.net = get_net_stat(arg);
|
|
|
|
} else {
|
|
|
|
CRIT_ERR("wireless_mode: needs an argument");
|
|
|
|
}
|
2007-08-07 22:05:06 +00:00
|
|
|
END OBJ(wireless_bitrate, INFO_NET)
|
2008-02-20 20:30:45 +00:00
|
|
|
if (arg) {
|
|
|
|
obj->data.net = get_net_stat(arg);
|
|
|
|
} else {
|
|
|
|
CRIT_ERR("wireless_bitrate: needs an argument");
|
|
|
|
}
|
2007-08-07 22:05:06 +00:00
|
|
|
END OBJ(wireless_ap, INFO_NET)
|
2008-02-20 20:30:45 +00:00
|
|
|
if (arg) {
|
|
|
|
obj->data.net = get_net_stat(arg);
|
|
|
|
} else {
|
|
|
|
CRIT_ERR("wireless_ap: needs an argument");
|
|
|
|
}
|
2007-08-07 12:51:08 +00:00
|
|
|
END OBJ(wireless_link_qual, INFO_NET)
|
2008-02-20 20:30:45 +00:00
|
|
|
if (arg) {
|
|
|
|
obj->data.net = get_net_stat(arg);
|
|
|
|
} else {
|
|
|
|
CRIT_ERR("wireless_link_qual: needs an argument");
|
|
|
|
}
|
2007-08-07 12:51:08 +00:00
|
|
|
END OBJ(wireless_link_qual_max, INFO_NET)
|
2008-02-20 20:30:45 +00:00
|
|
|
if (arg) {
|
|
|
|
obj->data.net = get_net_stat(arg);
|
|
|
|
} else {
|
|
|
|
CRIT_ERR("wireless_link_qual_max: needs an argument");
|
|
|
|
}
|
2007-08-07 22:05:06 +00:00
|
|
|
END OBJ(wireless_link_qual_perc, INFO_NET)
|
2008-02-20 20:30:45 +00:00
|
|
|
if (arg) {
|
|
|
|
obj->data.net = get_net_stat(arg);
|
|
|
|
} else {
|
|
|
|
CRIT_ERR("wireless_link_qual_perc: needs an argument");
|
|
|
|
}
|
2007-08-07 12:51:08 +00:00
|
|
|
END OBJ(wireless_link_bar, INFO_NET)
|
2008-02-20 20:30:45 +00:00
|
|
|
if (arg) {
|
|
|
|
arg = scan_bar(arg, &obj->a, &obj->b);
|
|
|
|
obj->data.net = get_net_stat(arg);
|
|
|
|
} else {
|
|
|
|
CRIT_ERR("wireless_link_bar: needs an argument");
|
|
|
|
}
|
2007-08-07 12:51:08 +00:00
|
|
|
#endif /* HAVE_IWLIB */
|
|
|
|
|
2006-05-22 02:49:22 +00:00
|
|
|
#endif /* __linux__ */
|
2008-02-20 20:30:45 +00:00
|
|
|
|
2007-08-10 21:06:30 +00:00
|
|
|
#ifndef __OpenBSD__
|
2008-02-10 11:14:19 +00:00
|
|
|
END OBJ(acpifan, 0)
|
|
|
|
END OBJ(battery, 0)
|
2008-02-20 20:30:45 +00:00
|
|
|
char bat[64];
|
|
|
|
|
2009-02-18 04:49:45 +00:00
|
|
|
if (arg) {
|
|
|
|
sscanf(arg, "%63s", bat);
|
|
|
|
} else {
|
|
|
|
strcpy(bat, "BAT0");
|
|
|
|
}
|
|
|
|
obj->data.s = strndup(bat, text_buffer_size);
|
|
|
|
END OBJ(battery_short, 0)
|
|
|
|
char bat[64];
|
|
|
|
|
2008-02-20 20:30:45 +00:00
|
|
|
if (arg) {
|
|
|
|
sscanf(arg, "%63s", bat);
|
|
|
|
} else {
|
|
|
|
strcpy(bat, "BAT0");
|
|
|
|
}
|
2008-04-02 18:44:49 +00:00
|
|
|
obj->data.s = strndup(bat, text_buffer_size);
|
2008-02-10 11:14:19 +00:00
|
|
|
END OBJ(battery_time, 0)
|
2008-02-20 20:30:45 +00:00
|
|
|
char bat[64];
|
|
|
|
|
|
|
|
if (arg) {
|
|
|
|
sscanf(arg, "%63s", bat);
|
|
|
|
} else {
|
|
|
|
strcpy(bat, "BAT0");
|
|
|
|
}
|
2008-04-02 18:44:49 +00:00
|
|
|
obj->data.s = strndup(bat, text_buffer_size);
|
2008-02-10 11:14:19 +00:00
|
|
|
END OBJ(battery_percent, 0)
|
2008-02-20 20:30:45 +00:00
|
|
|
char bat[64];
|
|
|
|
|
|
|
|
if (arg) {
|
|
|
|
sscanf(arg, "%63s", bat);
|
|
|
|
} else {
|
|
|
|
strcpy(bat, "BAT0");
|
|
|
|
}
|
2008-04-02 18:44:49 +00:00
|
|
|
obj->data.s = strndup(bat, text_buffer_size);
|
2008-02-10 11:14:19 +00:00
|
|
|
END OBJ(battery_bar, 0)
|
2008-02-20 20:30:45 +00:00
|
|
|
char bat[64];
|
2008-03-24 21:44:50 +00:00
|
|
|
obj->b = 6;
|
2008-02-20 20:30:45 +00:00
|
|
|
if (arg) {
|
|
|
|
arg = scan_bar(arg, &obj->a, &obj->b);
|
|
|
|
sscanf(arg, "%63s", bat);
|
|
|
|
} else {
|
|
|
|
strcpy(bat, "BAT0");
|
|
|
|
}
|
2008-04-02 18:44:49 +00:00
|
|
|
obj->data.s = strndup(bat, text_buffer_size);
|
2007-08-10 21:06:30 +00:00
|
|
|
#endif /* !__OpenBSD__ */
|
2008-02-20 20:30:45 +00:00
|
|
|
|
2005-08-27 12:59:46 +00:00
|
|
|
#if defined(__linux__)
|
2008-03-24 20:08:16 +00:00
|
|
|
END OBJ(disk_protect, 0)
|
|
|
|
if (arg)
|
2008-12-14 16:53:31 +00:00
|
|
|
obj->data.s = strndup(dev_name(arg), text_buffer_size);
|
2008-03-24 20:08:16 +00:00
|
|
|
else
|
|
|
|
CRIT_ERR("disk_protect needs an argument");
|
2005-08-27 07:15:44 +00:00
|
|
|
END OBJ(i8k_version, INFO_I8K)
|
2008-02-20 20:30:45 +00:00
|
|
|
END OBJ(i8k_bios, INFO_I8K)
|
|
|
|
END OBJ(i8k_serial, INFO_I8K)
|
|
|
|
END OBJ(i8k_cpu_temp, INFO_I8K)
|
|
|
|
END OBJ(i8k_left_fan_status, INFO_I8K)
|
|
|
|
END OBJ(i8k_right_fan_status, INFO_I8K)
|
|
|
|
END OBJ(i8k_left_fan_rpm, INFO_I8K)
|
|
|
|
END OBJ(i8k_right_fan_rpm, INFO_I8K)
|
|
|
|
END OBJ(i8k_ac_status, INFO_I8K)
|
|
|
|
END OBJ(i8k_buttons_status, INFO_I8K)
|
2009-01-03 23:00:52 +00:00
|
|
|
#if defined(IBM)
|
2006-04-15 18:00:39 +00:00
|
|
|
END OBJ(ibm_fan, 0)
|
|
|
|
END OBJ(ibm_temps, 0)
|
2008-02-20 20:30:45 +00:00
|
|
|
if (!arg) {
|
|
|
|
CRIT_ERR("ibm_temps: needs an argument");
|
|
|
|
}
|
|
|
|
if (!isdigit(arg[0]) || strlen(arg) >= 2 || atoi(&arg[0]) >= 8) {
|
|
|
|
obj->data.sensor = 0;
|
|
|
|
ERR("Invalid temperature sensor! Sensor number must be 0 to 7. "
|
|
|
|
"Using 0 (CPU temp sensor).");
|
|
|
|
}
|
2006-04-15 18:00:39 +00:00
|
|
|
obj->data.sensor = atoi(&arg[0]);
|
|
|
|
END OBJ(ibm_volume, 0)
|
|
|
|
END OBJ(ibm_brightness, 0)
|
2009-01-03 23:00:52 +00:00
|
|
|
#endif
|
2009-05-04 19:13:51 +00:00
|
|
|
/* information from sony_laptop kernel module
|
|
|
|
* /sys/devices/platform/sony-laptop */
|
|
|
|
END OBJ(sony_fanspeed, 0)
|
2008-12-22 18:43:12 +00:00
|
|
|
END OBJ_IF(if_gw, 0)
|
2008-03-22 21:10:43 +00:00
|
|
|
END OBJ(ioscheduler, 0)
|
|
|
|
if (!arg) {
|
|
|
|
CRIT_ERR("get_ioscheduler needs an argument (e.g. hda)");
|
|
|
|
obj->data.s = 0;
|
|
|
|
} else
|
2008-12-14 16:53:31 +00:00
|
|
|
obj->data.s = strndup(dev_name(arg), text_buffer_size);
|
2008-03-22 20:13:51 +00:00
|
|
|
END OBJ(laptop_mode, 0)
|
2006-04-23 21:35:31 +00:00
|
|
|
END OBJ(pb_battery, 0)
|
2008-06-21 20:37:58 +00:00
|
|
|
if (arg && strcmp(arg, "status") == EQUAL) {
|
2008-02-20 20:30:45 +00:00
|
|
|
obj->data.i = PB_BATT_STATUS;
|
2008-06-21 20:37:58 +00:00
|
|
|
} else if (arg && strcmp(arg, "percent") == EQUAL) {
|
2008-02-20 20:30:45 +00:00
|
|
|
obj->data.i = PB_BATT_PERCENT;
|
2008-06-21 20:37:58 +00:00
|
|
|
} else if (arg && strcmp(arg, "time") == EQUAL) {
|
2008-02-20 20:30:45 +00:00
|
|
|
obj->data.i = PB_BATT_TIME;
|
|
|
|
} else {
|
|
|
|
ERR("pb_battery: needs one argument: status, percent or time");
|
|
|
|
free(obj);
|
|
|
|
return NULL;
|
|
|
|
}
|
2006-04-23 21:35:31 +00:00
|
|
|
|
2005-08-27 12:59:46 +00:00
|
|
|
#endif /* __linux__ */
|
2009-03-28 23:15:20 +00:00
|
|
|
#if (defined(__FreeBSD__) || defined(__linux__))
|
|
|
|
END OBJ_IF(if_up, 0)
|
|
|
|
if (!arg) {
|
|
|
|
ERR("if_up needs an argument");
|
|
|
|
obj->data.ifblock.s = 0;
|
|
|
|
} else
|
|
|
|
obj->data.ifblock.s = strndup(arg, text_buffer_size);
|
|
|
|
#endif
|
2007-03-01 01:43:43 +00:00
|
|
|
#if defined(__OpenBSD__)
|
2008-02-10 11:14:19 +00:00
|
|
|
END OBJ(obsd_sensors_temp, 0)
|
2008-02-20 20:30:45 +00:00
|
|
|
if (!arg) {
|
2007-03-01 01:43:43 +00:00
|
|
|
CRIT_ERR("obsd_sensors_temp: needs an argument");
|
|
|
|
}
|
2008-02-20 20:30:45 +00:00
|
|
|
if (!isdigit(arg[0]) || atoi(&arg[0]) < 0
|
|
|
|
|| atoi(&arg[0]) > OBSD_MAX_SENSORS - 1) {
|
|
|
|
obj->data.sensor = 0;
|
2007-03-01 01:43:43 +00:00
|
|
|
ERR("Invalid temperature sensor number!");
|
|
|
|
}
|
2008-02-20 20:30:45 +00:00
|
|
|
obj->data.sensor = atoi(&arg[0]);
|
2008-02-10 11:14:19 +00:00
|
|
|
END OBJ(obsd_sensors_fan, 0)
|
2008-02-20 20:30:45 +00:00
|
|
|
if (!arg) {
|
|
|
|
CRIT_ERR("obsd_sensors_fan: needs 2 arguments (device and sensor "
|
|
|
|
"number)");
|
2007-03-01 01:43:43 +00:00
|
|
|
}
|
2008-02-20 20:30:45 +00:00
|
|
|
if (!isdigit(arg[0]) || atoi(&arg[0]) < 0
|
|
|
|
|| atoi(&arg[0]) > OBSD_MAX_SENSORS - 1) {
|
|
|
|
obj->data.sensor = 0;
|
2007-03-01 01:43:43 +00:00
|
|
|
ERR("Invalid fan sensor number!");
|
|
|
|
}
|
2008-02-20 20:30:45 +00:00
|
|
|
obj->data.sensor = atoi(&arg[0]);
|
2008-02-10 11:14:19 +00:00
|
|
|
END OBJ(obsd_sensors_volt, 0)
|
2008-02-20 20:30:45 +00:00
|
|
|
if (!arg) {
|
|
|
|
CRIT_ERR("obsd_sensors_volt: needs 2 arguments (device and sensor "
|
|
|
|
"number)");
|
2007-03-01 01:43:43 +00:00
|
|
|
}
|
2008-02-20 20:30:45 +00:00
|
|
|
if (!isdigit(arg[0]) || atoi(&arg[0]) < 0
|
|
|
|
|| atoi(&arg[0]) > OBSD_MAX_SENSORS - 1) {
|
|
|
|
obj->data.sensor = 0;
|
2007-03-01 01:43:43 +00:00
|
|
|
ERR("Invalid voltage sensor number!");
|
|
|
|
}
|
2008-02-20 20:30:45 +00:00
|
|
|
obj->data.sensor = atoi(&arg[0]);
|
2008-02-10 11:14:19 +00:00
|
|
|
END OBJ(obsd_vendor, 0)
|
|
|
|
END OBJ(obsd_product, 0)
|
2007-03-01 01:43:43 +00:00
|
|
|
#endif /* __OpenBSD__ */
|
2008-02-20 20:30:45 +00:00
|
|
|
END OBJ(buffers, INFO_BUFFERS)
|
|
|
|
END OBJ(cached, INFO_BUFFERS)
|
2009-04-03 23:19:49 +00:00
|
|
|
#define SCAN_CPU(__arg, __var) { \
|
|
|
|
int __offset; \
|
2009-05-07 16:44:45 +00:00
|
|
|
if (__arg && sscanf(__arg, " cpu%u %n", &__var, &__offset) == 2) \
|
2009-04-03 23:19:49 +00:00
|
|
|
__arg += __offset; \
|
|
|
|
else \
|
|
|
|
__var = 0; \
|
|
|
|
}
|
2008-02-20 20:30:45 +00:00
|
|
|
END OBJ(cpu, INFO_CPU)
|
2009-04-03 23:19:49 +00:00
|
|
|
SCAN_CPU(arg, obj->data.cpu_index);
|
|
|
|
DBGP2("Adding $cpu for CPU %d", obj->data.cpu_index);
|
2009-03-11 00:37:24 +00:00
|
|
|
END OBJ(cpugauge, INFO_CPU)
|
2009-04-03 23:19:49 +00:00
|
|
|
SCAN_CPU(arg, obj->data.cpu_index);
|
2009-03-11 00:37:24 +00:00
|
|
|
scan_gauge(arg, &obj->a, &obj->b);
|
|
|
|
DBGP2("Adding $cpugauge for CPU %d", obj->data.cpu_index);
|
2005-08-27 10:10:31 +00:00
|
|
|
END OBJ(cpubar, INFO_CPU)
|
2009-04-03 23:19:49 +00:00
|
|
|
SCAN_CPU(arg, obj->data.cpu_index);
|
|
|
|
scan_bar(arg, &obj->a, &obj->b);
|
2008-12-09 23:15:06 +00:00
|
|
|
DBGP2("Adding $cpubar for CPU %d", obj->data.cpu_index);
|
2006-01-28 01:28:23 +00:00
|
|
|
END OBJ(cpugraph, INFO_CPU)
|
2009-04-03 23:19:49 +00:00
|
|
|
SCAN_CPU(arg, obj->data.cpu_index);
|
|
|
|
scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
|
2008-06-21 20:37:58 +00:00
|
|
|
&obj->e, &obj->showaslog);
|
2008-12-09 23:15:06 +00:00
|
|
|
DBGP2("Adding $cpugraph for CPU %d", obj->data.cpu_index);
|
2008-04-13 04:10:35 +00:00
|
|
|
END OBJ(loadgraph, INFO_LOADAVG)
|
|
|
|
char *buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
|
2008-06-21 20:37:58 +00:00
|
|
|
&obj->e, &obj->showaslog);
|
2008-04-13 04:10:35 +00:00
|
|
|
if (buf) {
|
|
|
|
int a = 1, r = 3;
|
|
|
|
if (arg) {
|
|
|
|
r = sscanf(arg, "%d", &a);
|
|
|
|
}
|
|
|
|
obj->data.loadavg[0] = (r >= 1) ? (unsigned char) a : 0;
|
|
|
|
free(buf);
|
|
|
|
}
|
2005-08-26 02:52:54 +00:00
|
|
|
END OBJ(diskio, INFO_DISKIO)
|
2008-12-16 01:32:30 +00:00
|
|
|
obj->data.diskio = prepare_diskio_stat(dev_name(arg));
|
2006-12-29 23:14:31 +00:00
|
|
|
END OBJ(diskio_read, INFO_DISKIO)
|
2008-12-16 01:32:30 +00:00
|
|
|
obj->data.diskio = prepare_diskio_stat(dev_name(arg));
|
2006-12-29 23:14:31 +00:00
|
|
|
END OBJ(diskio_write, INFO_DISKIO)
|
2008-12-16 01:32:30 +00:00
|
|
|
obj->data.diskio = prepare_diskio_stat(dev_name(arg));
|
2008-02-09 02:21:06 +00:00
|
|
|
END OBJ(diskiograph, INFO_DISKIO)
|
2008-12-18 14:03:02 +00:00
|
|
|
char *buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
|
2008-06-21 20:37:58 +00:00
|
|
|
&obj->e, &obj->showaslog);
|
2008-02-09 02:21:06 +00:00
|
|
|
|
2008-12-18 14:03:02 +00:00
|
|
|
obj->data.diskio = prepare_diskio_stat(dev_name(buf));
|
2008-12-16 01:32:30 +00:00
|
|
|
if (buf)
|
2008-02-09 02:21:06 +00:00
|
|
|
free(buf);
|
|
|
|
END OBJ(diskiograph_read, INFO_DISKIO)
|
2008-12-18 14:03:02 +00:00
|
|
|
char *buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
|
2008-06-21 20:37:58 +00:00
|
|
|
&obj->e, &obj->showaslog);
|
2008-02-09 02:21:06 +00:00
|
|
|
|
2008-12-18 14:03:02 +00:00
|
|
|
obj->data.diskio = prepare_diskio_stat(dev_name(buf));
|
2008-12-16 01:32:30 +00:00
|
|
|
if (buf)
|
2008-02-09 02:21:06 +00:00
|
|
|
free(buf);
|
|
|
|
END OBJ(diskiograph_write, INFO_DISKIO)
|
2008-12-18 14:03:02 +00:00
|
|
|
char *buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
|
2008-06-21 20:37:58 +00:00
|
|
|
&obj->e, &obj->showaslog);
|
2008-02-09 02:21:06 +00:00
|
|
|
|
2008-12-18 14:03:02 +00:00
|
|
|
obj->data.diskio = prepare_diskio_stat(dev_name(buf));
|
2008-12-16 01:32:30 +00:00
|
|
|
if (buf)
|
2008-02-09 02:21:06 +00:00
|
|
|
free(buf);
|
2008-02-20 20:30:45 +00:00
|
|
|
END OBJ(color, 0)
|
2005-08-08 01:18:52 +00:00
|
|
|
#ifdef X11
|
2009-02-21 23:37:15 +00:00
|
|
|
if (output_methods & TO_X) {
|
2009-02-14 12:03:11 +00:00
|
|
|
obj->data.l = arg ? get_x11_color(arg) : default_fg_color;
|
|
|
|
}
|
2005-08-08 01:18:52 +00:00
|
|
|
#endif /* X11 */
|
2007-04-25 17:22:06 +00:00
|
|
|
END OBJ(color0, 0)
|
|
|
|
obj->data.l = color0;
|
|
|
|
END OBJ(color1, 0)
|
|
|
|
obj->data.l = color1;
|
|
|
|
END OBJ(color2, 0)
|
|
|
|
obj->data.l = color2;
|
|
|
|
END OBJ(color3, 0)
|
|
|
|
obj->data.l = color3;
|
|
|
|
END OBJ(color4, 0)
|
|
|
|
obj->data.l = color4;
|
|
|
|
END OBJ(color5, 0)
|
|
|
|
obj->data.l = color5;
|
|
|
|
END OBJ(color6, 0)
|
|
|
|
obj->data.l = color6;
|
|
|
|
END OBJ(color7, 0)
|
|
|
|
obj->data.l = color7;
|
|
|
|
END OBJ(color8, 0)
|
|
|
|
obj->data.l = color8;
|
|
|
|
END OBJ(color9, 0)
|
|
|
|
obj->data.l = color9;
|
|
|
|
END OBJ(font, 0)
|
2006-01-28 01:28:23 +00:00
|
|
|
obj->data.s = scan_font(arg);
|
2008-03-18 00:23:16 +00:00
|
|
|
END OBJ(conky_version, 0)
|
|
|
|
END OBJ(conky_build_date, 0)
|
|
|
|
END OBJ(conky_build_arch, 0)
|
2008-02-20 20:30:45 +00:00
|
|
|
END OBJ(downspeed, INFO_NET)
|
|
|
|
if (arg) {
|
2005-08-29 16:49:09 +00:00
|
|
|
obj->data.net = get_net_stat(arg);
|
2008-02-20 20:30:45 +00:00
|
|
|
} else {
|
2005-08-29 16:49:09 +00:00
|
|
|
CRIT_ERR("downspeed needs argument");
|
|
|
|
}
|
|
|
|
END OBJ(downspeedf, INFO_NET)
|
2008-02-20 20:30:45 +00:00
|
|
|
if (arg) {
|
2005-08-29 16:49:09 +00:00
|
|
|
obj->data.net = get_net_stat(arg);
|
2008-02-20 20:30:45 +00:00
|
|
|
} else {
|
2005-08-29 16:49:09 +00:00
|
|
|
CRIT_ERR("downspeedf needs argument");
|
|
|
|
}
|
2005-07-29 04:32:56 +00:00
|
|
|
END OBJ(downspeedgraph, INFO_NET)
|
2008-02-09 02:21:06 +00:00
|
|
|
char *buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
|
2008-06-21 20:37:58 +00:00
|
|
|
&obj->e, &obj->showaslog);
|
2008-02-09 02:21:06 +00:00
|
|
|
|
2008-07-12 01:22:40 +00:00
|
|
|
// default to DEFAULTNETDEV
|
|
|
|
buf = strndup(buf ? buf : "DEFAULTNETDEV", text_buffer_size);
|
2008-06-28 20:14:04 +00:00
|
|
|
obj->data.net = get_net_stat(buf);
|
|
|
|
free(buf);
|
2006-01-25 04:31:00 +00:00
|
|
|
END OBJ(else, 0)
|
2008-12-22 16:45:08 +00:00
|
|
|
obj_be_ifblock_else(ifblock_opaque, obj);
|
2005-07-28 04:48:27 +00:00
|
|
|
END OBJ(endif, 0)
|
2008-12-22 16:45:08 +00:00
|
|
|
obj_be_ifblock_endif(ifblock_opaque, obj);
|
2009-03-23 23:27:51 +00:00
|
|
|
END OBJ(eval, 0)
|
|
|
|
obj->data.s = strndup(arg ? arg : "", text_buffer_size);
|
2008-02-20 20:30:45 +00:00
|
|
|
END OBJ(image, 0)
|
2008-04-02 18:44:49 +00:00
|
|
|
obj->data.s = strndup(arg ? arg : "", text_buffer_size);
|
2005-07-20 00:30:40 +00:00
|
|
|
#ifdef HAVE_POPEN
|
2008-02-20 20:30:45 +00:00
|
|
|
END OBJ(exec, 0)
|
2008-04-02 18:44:49 +00:00
|
|
|
obj->data.s = strndup(arg ? arg : "", text_buffer_size);
|
2008-03-20 20:33:31 +00:00
|
|
|
END OBJ(execp, 0)
|
2008-04-02 18:44:49 +00:00
|
|
|
obj->data.s = strndup(arg ? arg : "", text_buffer_size);
|
2009-04-10 02:10:08 +00:00
|
|
|
#define SIZE_DEFAULTS(arg) { \
|
|
|
|
obj->a = default_##arg##_width; \
|
|
|
|
obj->b = default_##arg##_height; \
|
|
|
|
}
|
2009-03-11 00:37:24 +00:00
|
|
|
END OBJ(execgauge, 0)
|
2009-04-10 02:10:08 +00:00
|
|
|
SIZE_DEFAULTS(gauge);
|
2009-03-11 00:37:24 +00:00
|
|
|
obj->data.s = strndup(arg ? arg : "", text_buffer_size);
|
2008-02-20 20:30:45 +00:00
|
|
|
END OBJ(execbar, 0)
|
2009-04-10 02:10:08 +00:00
|
|
|
SIZE_DEFAULTS(bar);
|
2008-04-02 18:44:49 +00:00
|
|
|
obj->data.s = strndup(arg ? arg : "", text_buffer_size);
|
2008-02-20 20:30:45 +00:00
|
|
|
END OBJ(execgraph, 0)
|
2009-04-10 02:10:08 +00:00
|
|
|
SIZE_DEFAULTS(graph);
|
2008-04-02 18:44:49 +00:00
|
|
|
obj->data.s = strndup(arg ? arg : "", text_buffer_size);
|
2008-02-20 20:30:45 +00:00
|
|
|
END OBJ(execibar, 0)
|
2008-03-29 03:01:48 +00:00
|
|
|
int n;
|
2009-04-10 02:10:08 +00:00
|
|
|
SIZE_DEFAULTS(bar);
|
2005-07-20 00:30:40 +00:00
|
|
|
|
2008-02-20 20:30:45 +00:00
|
|
|
if (!arg || sscanf(arg, "%f %n", &obj->data.execi.interval, &n) <= 0) {
|
|
|
|
char buf[256];
|
2005-07-20 00:30:40 +00:00
|
|
|
|
2008-02-20 20:30:45 +00:00
|
|
|
ERR("${execibar <interval> command}");
|
|
|
|
obj->type = OBJ_text;
|
|
|
|
snprintf(buf, 256, "${%s}", s);
|
2008-04-02 18:44:49 +00:00
|
|
|
obj->data.s = strndup(buf, text_buffer_size);
|
2008-02-20 20:30:45 +00:00
|
|
|
} else {
|
2008-04-02 18:44:49 +00:00
|
|
|
obj->data.execi.cmd = strndup(arg + n, text_buffer_size);
|
2008-02-20 20:30:45 +00:00
|
|
|
}
|
|
|
|
END OBJ(execigraph, 0)
|
2008-03-29 03:01:48 +00:00
|
|
|
int n;
|
2009-04-10 02:10:08 +00:00
|
|
|
SIZE_DEFAULTS(graph);
|
2005-07-20 00:30:40 +00:00
|
|
|
|
2008-02-20 20:30:45 +00:00
|
|
|
if (!arg || sscanf(arg, "%f %n", &obj->data.execi.interval, &n) <= 0) {
|
|
|
|
char buf[256];
|
2005-07-20 00:30:40 +00:00
|
|
|
|
2008-02-20 20:30:45 +00:00
|
|
|
ERR("${execigraph <interval> command}");
|
|
|
|
obj->type = OBJ_text;
|
|
|
|
snprintf(buf, 256, "${%s}", s);
|
2008-04-02 18:44:49 +00:00
|
|
|
obj->data.s = strndup(buf, text_buffer_size);
|
2008-02-20 20:30:45 +00:00
|
|
|
} else {
|
2008-04-02 18:44:49 +00:00
|
|
|
obj->data.execi.cmd = strndup(arg + n, text_buffer_size);
|
2008-02-20 20:30:45 +00:00
|
|
|
}
|
2009-04-10 02:10:08 +00:00
|
|
|
END OBJ(execigauge, 0)
|
|
|
|
int n;
|
|
|
|
SIZE_DEFAULTS(gauge);
|
|
|
|
|
|
|
|
if (!arg || sscanf(arg, "%f %n", &obj->data.execi.interval, &n) <= 0) {
|
|
|
|
char buf[256];
|
|
|
|
|
|
|
|
ERR("${execigauge <interval> command}");
|
|
|
|
obj->type = OBJ_text;
|
|
|
|
snprintf(buf, 256, "${%s}", s);
|
|
|
|
obj->data.s = strndup(buf, text_buffer_size);
|
|
|
|
} else {
|
|
|
|
obj->data.execi.cmd = strndup(arg + n, text_buffer_size);
|
|
|
|
}
|
2008-02-20 20:30:45 +00:00
|
|
|
END OBJ(execi, 0)
|
2008-03-29 03:01:48 +00:00
|
|
|
int n;
|
2008-02-20 20:30:45 +00:00
|
|
|
|
|
|
|
if (!arg || sscanf(arg, "%f %n", &obj->data.execi.interval, &n) <= 0) {
|
|
|
|
char buf[256];
|
|
|
|
|
|
|
|
ERR("${execi <interval> command}");
|
|
|
|
obj->type = OBJ_text;
|
|
|
|
snprintf(buf, 256, "${%s}", s);
|
2008-04-02 18:44:49 +00:00
|
|
|
obj->data.s = strndup(buf, text_buffer_size);
|
2008-02-20 20:30:45 +00:00
|
|
|
} else {
|
2008-04-02 18:44:49 +00:00
|
|
|
obj->data.execi.cmd = strndup(arg + n, text_buffer_size);
|
2008-03-22 06:10:54 +00:00
|
|
|
obj->data.execi.buffer = malloc(text_buffer_size);
|
|
|
|
}
|
|
|
|
END OBJ(execpi, 0)
|
2008-03-29 03:01:48 +00:00
|
|
|
int n;
|
2008-03-22 06:10:54 +00:00
|
|
|
|
|
|
|
if (!arg || sscanf(arg, "%f %n", &obj->data.execi.interval, &n) <= 0) {
|
|
|
|
char buf[256];
|
|
|
|
|
|
|
|
ERR("${execi <interval> command}");
|
|
|
|
obj->type = OBJ_text;
|
|
|
|
snprintf(buf, 256, "${%s}", s);
|
2008-04-02 18:44:49 +00:00
|
|
|
obj->data.s = strndup(buf, text_buffer_size);
|
2008-03-22 06:10:54 +00:00
|
|
|
} else {
|
2008-04-02 18:44:49 +00:00
|
|
|
obj->data.execi.cmd = strndup(arg + n, text_buffer_size);
|
2008-03-22 06:10:54 +00:00
|
|
|
obj->data.execi.buffer = malloc(text_buffer_size);
|
2008-02-20 20:30:45 +00:00
|
|
|
}
|
2008-07-17 03:14:37 +00:00
|
|
|
END OBJ_THREAD(texeci, 0)
|
|
|
|
int n;
|
2008-02-20 20:30:45 +00:00
|
|
|
|
2008-07-17 03:14:37 +00:00
|
|
|
if (!arg || sscanf(arg, "%f %n", &obj->data.texeci.interval, &n) <= 0) {
|
|
|
|
char buf[256];
|
2008-02-20 20:30:45 +00:00
|
|
|
|
2008-07-17 03:14:37 +00:00
|
|
|
ERR("${texeci <interval> command}");
|
|
|
|
obj->type = OBJ_text;
|
|
|
|
snprintf(buf, 256, "${%s}", s);
|
|
|
|
obj->data.s = strndup(buf, text_buffer_size);
|
|
|
|
} else {
|
|
|
|
obj->data.texeci.cmd = strndup(arg + n, text_buffer_size);
|
|
|
|
obj->data.texeci.buffer = malloc(text_buffer_size);
|
|
|
|
}
|
|
|
|
obj->data.texeci.p_timed_thread = NULL;
|
|
|
|
END OBJ(pre_exec, 0)
|
2008-02-20 20:30:45 +00:00
|
|
|
obj->type = OBJ_text;
|
2008-07-17 03:14:37 +00:00
|
|
|
if (arg) {
|
|
|
|
char buf[2048];
|
2008-02-20 20:30:45 +00:00
|
|
|
|
2008-07-17 03:14:37 +00:00
|
|
|
read_exec(arg, buf, sizeof(buf));
|
|
|
|
obj->data.s = strndup(buf, text_buffer_size);
|
|
|
|
} else {
|
|
|
|
obj->data.s = strndup("", text_buffer_size);
|
|
|
|
}
|
2005-07-20 00:30:40 +00:00
|
|
|
#endif
|
2008-02-20 20:30:45 +00:00
|
|
|
END OBJ(fs_bar, INFO_FS)
|
|
|
|
arg = scan_bar(arg, &obj->data.fsbar.w, &obj->data.fsbar.h);
|
2008-07-17 03:14:37 +00:00
|
|
|
if (arg) {
|
2008-02-20 20:30:45 +00:00
|
|
|
while (isspace(*arg)) {
|
|
|
|
arg++;
|
|
|
|
}
|
|
|
|
if (*arg == '\0') {
|
|
|
|
arg = "/";
|
|
|
|
}
|
|
|
|
} else {
|
2005-07-20 00:30:40 +00:00
|
|
|
arg = "/";
|
2008-02-20 20:30:45 +00:00
|
|
|
}
|
|
|
|
obj->data.fsbar.fs = prepare_fs_stat(arg);
|
|
|
|
END OBJ(fs_bar_free, INFO_FS)
|
2008-03-24 21:44:50 +00:00
|
|
|
arg = scan_bar(arg, &obj->data.fsbar.w, &obj->data.fsbar.h);
|
2008-02-20 20:30:45 +00:00
|
|
|
if (arg) {
|
2008-03-24 21:44:50 +00:00
|
|
|
while (isspace(*arg)) {
|
|
|
|
arg++;
|
|
|
|
}
|
|
|
|
if (*arg == '\0') {
|
|
|
|
arg = "/";
|
2008-02-20 20:30:45 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
arg = "/";
|
|
|
|
}
|
2008-03-24 21:44:50 +00:00
|
|
|
|
2008-02-20 20:30:45 +00:00
|
|
|
obj->data.fsbar.fs = prepare_fs_stat(arg);
|
|
|
|
END OBJ(fs_free, INFO_FS)
|
|
|
|
if (!arg) {
|
|
|
|
arg = "/";
|
|
|
|
}
|
|
|
|
obj->data.fs = prepare_fs_stat(arg);
|
|
|
|
END OBJ(fs_used_perc, INFO_FS)
|
|
|
|
if (!arg) {
|
|
|
|
arg = "/";
|
|
|
|
}
|
|
|
|
obj->data.fs = prepare_fs_stat(arg);
|
|
|
|
END OBJ(fs_free_perc, INFO_FS)
|
|
|
|
if (!arg) {
|
|
|
|
arg = "/";
|
|
|
|
}
|
|
|
|
obj->data.fs = prepare_fs_stat(arg);
|
|
|
|
END OBJ(fs_size, INFO_FS)
|
|
|
|
if (!arg) {
|
|
|
|
arg = "/";
|
|
|
|
}
|
|
|
|
obj->data.fs = prepare_fs_stat(arg);
|
2008-03-18 00:23:16 +00:00
|
|
|
END OBJ(fs_type, INFO_FS)
|
|
|
|
if (!arg) {
|
|
|
|
arg = "/";
|
|
|
|
}
|
|
|
|
obj->data.fs = prepare_fs_stat(arg);
|
2008-02-20 20:30:45 +00:00
|
|
|
END OBJ(fs_used, INFO_FS)
|
|
|
|
if (!arg) {
|
|
|
|
arg = "/";
|
|
|
|
}
|
|
|
|
obj->data.fs = prepare_fs_stat(arg);
|
|
|
|
END OBJ(hr, 0)
|
|
|
|
obj->data.i = arg ? atoi(arg) : 1;
|
2008-03-22 22:58:26 +00:00
|
|
|
END OBJ(nameserver, INFO_DNS)
|
|
|
|
obj->data.i = arg ? atoi(arg) : 0;
|
2008-02-20 20:30:45 +00:00
|
|
|
END OBJ(offset, 0)
|
|
|
|
obj->data.i = arg ? atoi(arg) : 1;
|
|
|
|
END OBJ(voffset, 0)
|
|
|
|
obj->data.i = arg ? atoi(arg) : 1;
|
2006-08-10 16:56:13 +00:00
|
|
|
END OBJ(goto, 0)
|
|
|
|
|
2008-02-20 20:30:45 +00:00
|
|
|
if (!arg) {
|
|
|
|
ERR("goto needs arguments");
|
|
|
|
obj->type = OBJ_text;
|
2008-04-02 18:44:49 +00:00
|
|
|
obj->data.s = strndup("${goto}", text_buffer_size);
|
2008-02-20 20:30:45 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
obj->data.i = atoi(arg);
|
|
|
|
|
2006-08-10 16:56:13 +00:00
|
|
|
END OBJ(tab, 0)
|
2008-02-20 20:30:45 +00:00
|
|
|
int a = 10, b = 0;
|
|
|
|
|
|
|
|
if (arg) {
|
|
|
|
if (sscanf(arg, "%d %d", &a, &b) != 2) {
|
|
|
|
sscanf(arg, "%d", &b);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (a <= 0) {
|
|
|
|
a = 1;
|
|
|
|
}
|
|
|
|
obj->data.pair.a = a;
|
|
|
|
obj->data.pair.b = b;
|
2006-08-10 16:56:13 +00:00
|
|
|
|
2009-03-28 19:46:20 +00:00
|
|
|
#ifdef __linux__
|
2007-08-13 23:14:01 +00:00
|
|
|
END OBJ(i2c, INFO_SYSFS)
|
2008-02-20 20:30:45 +00:00
|
|
|
char buf1[64], buf2[64];
|
|
|
|
int n;
|
2005-07-20 00:30:40 +00:00
|
|
|
|
2008-02-20 20:30:45 +00:00
|
|
|
if (!arg) {
|
|
|
|
ERR("i2c needs arguments");
|
|
|
|
obj->type = OBJ_text;
|
2008-04-02 18:44:49 +00:00
|
|
|
// obj->data.s = strndup("${i2c}", text_buffer_size);
|
2008-02-20 20:30:45 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
2005-07-20 00:30:40 +00:00
|
|
|
|
2008-02-20 20:30:45 +00:00
|
|
|
if (sscanf(arg, "%63s %63s %d", buf1, buf2, &n) != 3) {
|
|
|
|
/* if scanf couldn't read three values, read type and num and use
|
|
|
|
* default device */
|
|
|
|
sscanf(arg, "%63s %d", buf2, &n);
|
|
|
|
obj->data.sysfs.fd = open_i2c_sensor(0, buf2, n,
|
|
|
|
&obj->data.sysfs.arg, obj->data.sysfs.devtype);
|
|
|
|
strncpy(obj->data.sysfs.type, buf2, 63);
|
|
|
|
} else {
|
|
|
|
obj->data.sysfs.fd = open_i2c_sensor(buf1, buf2, n,
|
|
|
|
&obj->data.sysfs.arg, obj->data.sysfs.devtype);
|
|
|
|
strncpy(obj->data.sysfs.type, buf2, 63);
|
|
|
|
}
|
|
|
|
|
|
|
|
END OBJ(platform, INFO_SYSFS)
|
|
|
|
char buf1[64], buf2[64];
|
|
|
|
int n;
|
|
|
|
|
|
|
|
if (!arg) {
|
|
|
|
ERR("platform needs arguments");
|
|
|
|
obj->type = OBJ_text;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sscanf(arg, "%63s %63s %d", buf1, buf2, &n) != 3) {
|
|
|
|
/* if scanf couldn't read three values, read type and num and use
|
|
|
|
* default device */
|
|
|
|
sscanf(arg, "%63s %d", buf2, &n);
|
|
|
|
obj->data.sysfs.fd = open_platform_sensor(0, buf2, n,
|
|
|
|
&obj->data.sysfs.arg, obj->data.sysfs.devtype);
|
|
|
|
strncpy(obj->data.sysfs.type, buf2, 63);
|
|
|
|
} else {
|
|
|
|
obj->data.sysfs.fd = open_platform_sensor(buf1, buf2, n,
|
|
|
|
&obj->data.sysfs.arg, obj->data.sysfs.devtype);
|
|
|
|
strncpy(obj->data.sysfs.type, buf2, 63);
|
|
|
|
}
|
|
|
|
|
|
|
|
END OBJ(hwmon, INFO_SYSFS)
|
|
|
|
char buf1[64], buf2[64];
|
|
|
|
int n;
|
|
|
|
|
|
|
|
if (!arg) {
|
|
|
|
ERR("hwmon needs argumanets");
|
|
|
|
obj->type = OBJ_text;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sscanf(arg, "%63s %63s %d", buf1, buf2, &n) != 3) {
|
|
|
|
/* if scanf couldn't read three values, read type and num and use
|
|
|
|
* default device */
|
|
|
|
sscanf(arg, "%63s %d", buf2, &n);
|
|
|
|
obj->data.sysfs.fd = open_hwmon_sensor(0, buf2, n,
|
|
|
|
&obj->data.sysfs.arg, obj->data.sysfs.devtype);
|
|
|
|
strncpy(obj->data.sysfs.type, buf2, 63);
|
|
|
|
} else {
|
|
|
|
obj->data.sysfs.fd = open_hwmon_sensor(buf1, buf2, n,
|
|
|
|
&obj->data.sysfs.arg, obj->data.sysfs.devtype);
|
|
|
|
strncpy(obj->data.sysfs.type, buf2, 63);
|
|
|
|
}
|
2007-08-10 21:14:06 +00:00
|
|
|
#endif /* !__OpenBSD__ */
|
2005-07-28 04:48:27 +00:00
|
|
|
|
2009-02-08 16:19:10 +00:00
|
|
|
END
|
|
|
|
/* we have three different types of top (top, top_mem and top_time). To
|
|
|
|
* avoid having almost-same code three times, we have this special
|
|
|
|
* handler. */
|
|
|
|
if (strncmp(s, "top", 3) == EQUAL) {
|
2006-01-28 01:28:23 +00:00
|
|
|
char buf[64];
|
2008-02-20 20:30:45 +00:00
|
|
|
int n;
|
|
|
|
|
2009-02-08 16:19:10 +00:00
|
|
|
need_mask |= (1 << INFO_TOP);
|
|
|
|
|
|
|
|
if (s[3] == 0) {
|
|
|
|
obj->type = OBJ_top;
|
|
|
|
top_cpu = 1;
|
|
|
|
} else if (strcmp(&s[3], "_mem") == EQUAL) {
|
|
|
|
obj->type = OBJ_top_mem;
|
|
|
|
top_mem = 1;
|
|
|
|
} else if (strcmp(&s[3], "_time") == EQUAL) {
|
|
|
|
obj->type = OBJ_top_time;
|
|
|
|
top_time = 1;
|
2005-07-28 04:48:27 +00:00
|
|
|
} else {
|
2009-02-08 16:19:10 +00:00
|
|
|
ERR("Must be top, top_mem or top_time");
|
2008-02-20 20:30:45 +00:00
|
|
|
return NULL;
|
2005-07-20 00:30:40 +00:00
|
|
|
}
|
2008-02-20 20:30:45 +00:00
|
|
|
|
|
|
|
if (!arg) {
|
2009-02-08 16:19:10 +00:00
|
|
|
ERR("top needs arguments");
|
2008-02-20 20:30:45 +00:00
|
|
|
return NULL;
|
2005-07-25 00:22:16 +00:00
|
|
|
}
|
2009-02-07 14:01:50 +00:00
|
|
|
|
|
|
|
if (sscanf(arg, "%63s %i", buf, &n) == 2) {
|
|
|
|
if (strcmp(buf, "name") == EQUAL) {
|
|
|
|
obj->data.top.type = TOP_NAME;
|
|
|
|
} else if (strcmp(buf, "cpu") == EQUAL) {
|
|
|
|
obj->data.top.type = TOP_CPU;
|
|
|
|
} else if (strcmp(buf, "pid") == EQUAL) {
|
|
|
|
obj->data.top.type = TOP_PID;
|
|
|
|
} else if (strcmp(buf, "mem") == EQUAL) {
|
|
|
|
obj->data.top.type = TOP_MEM;
|
|
|
|
} else if (strcmp(buf, "time") == EQUAL) {
|
|
|
|
obj->data.top.type = TOP_TIME;
|
|
|
|
} else if (strcmp(buf, "mem_res") == EQUAL) {
|
|
|
|
obj->data.top.type = TOP_MEM_RES;
|
|
|
|
} else if (strcmp(buf, "mem_vsize") == EQUAL) {
|
|
|
|
obj->data.top.type = TOP_MEM_VSIZE;
|
|
|
|
} else {
|
2009-02-08 16:19:10 +00:00
|
|
|
ERR("invalid type arg for top");
|
|
|
|
ERR("must be one of: name, cpu, pid, mem, time, mem_res, mem_vsize");
|
2009-02-07 14:01:50 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
if (n < 1 || n > 10) {
|
2009-02-08 16:19:10 +00:00
|
|
|
ERR("invalid num arg for top. Must be between 1 and 10.");
|
2009-02-07 14:01:50 +00:00
|
|
|
return NULL;
|
|
|
|
} else {
|
|
|
|
obj->data.top.num = n - 1;
|
|
|
|
}
|
|
|
|
} else {
|
2009-02-08 16:19:10 +00:00
|
|
|
ERR("invalid argument count for top");
|
2009-02-07 14:01:50 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
2009-02-08 16:19:10 +00:00
|
|
|
} else OBJ(addr, INFO_NET)
|
2008-09-01 22:05:24 +00:00
|
|
|
if (arg) {
|
|
|
|
obj->data.net = get_net_stat(arg);
|
|
|
|
} else {
|
|
|
|
CRIT_ERR("addr needs argument");
|
|
|
|
}
|
2008-03-18 00:23:16 +00:00
|
|
|
#if defined(__linux__)
|
2008-09-01 22:05:24 +00:00
|
|
|
END OBJ(addrs, INFO_NET)
|
|
|
|
if (arg) {
|
|
|
|
obj->data.net = get_net_stat(arg);
|
|
|
|
} else {
|
|
|
|
CRIT_ERR("addrs needs argument");
|
|
|
|
}
|
2008-03-18 00:23:16 +00:00
|
|
|
#endif /* __linux__ */
|
2008-09-01 22:05:24 +00:00
|
|
|
END OBJ(tail, 0)
|
2009-01-05 00:27:07 +00:00
|
|
|
if (init_tail_object(obj, arg)) {
|
2008-02-20 20:30:45 +00:00
|
|
|
obj->type = OBJ_text;
|
2008-04-02 18:44:49 +00:00
|
|
|
obj->data.s = strndup("${tail}", text_buffer_size);
|
2008-02-20 20:30:45 +00:00
|
|
|
}
|
2005-08-26 05:52:43 +00:00
|
|
|
END OBJ(head, 0)
|
2009-01-05 00:27:07 +00:00
|
|
|
if (init_head_object(obj, arg)) {
|
2008-02-20 20:30:45 +00:00
|
|
|
obj->type = OBJ_text;
|
2008-04-02 18:44:49 +00:00
|
|
|
obj->data.s = strndup("${head}", text_buffer_size);
|
2005-08-26 05:52:43 +00:00
|
|
|
}
|
2008-06-21 20:37:58 +00:00
|
|
|
END OBJ(lines, 0)
|
|
|
|
if (arg) {
|
|
|
|
obj->data.s = strdup(arg);
|
|
|
|
}else{
|
|
|
|
CRIT_ERR("lines needs a argument");
|
|
|
|
}
|
|
|
|
END OBJ(words, 0)
|
|
|
|
if (arg) {
|
|
|
|
obj->data.s = strdup(arg);
|
|
|
|
}else{
|
|
|
|
CRIT_ERR("words needs a argument");
|
|
|
|
}
|
2008-02-20 20:30:45 +00:00
|
|
|
END OBJ(loadavg, INFO_LOADAVG)
|
|
|
|
int a = 1, b = 2, c = 3, r = 3;
|
2005-08-26 05:52:43 +00:00
|
|
|
|
2008-02-20 20:30:45 +00:00
|
|
|
if (arg) {
|
|
|
|
r = sscanf(arg, "%d %d %d", &a, &b, &c);
|
|
|
|
if (r >= 3 && (c < 1 || c > 3)) {
|
|
|
|
r--;
|
|
|
|
}
|
|
|
|
if (r >= 2 && (b < 1 || b > 3)) {
|
|
|
|
r--, b = c;
|
|
|
|
}
|
|
|
|
if (r >= 1 && (a < 1 || a > 3)) {
|
|
|
|
r--, a = b, b = c;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
obj->data.loadavg[0] = (r >= 1) ? (unsigned char) a : 0;
|
|
|
|
obj->data.loadavg[1] = (r >= 2) ? (unsigned char) b : 0;
|
|
|
|
obj->data.loadavg[2] = (r >= 3) ? (unsigned char) c : 0;
|
2008-12-22 18:43:12 +00:00
|
|
|
END OBJ_IF(if_empty, 0)
|
2008-02-20 20:30:45 +00:00
|
|
|
if (!arg) {
|
|
|
|
ERR("if_empty needs an argument");
|
|
|
|
obj->data.ifblock.s = 0;
|
|
|
|
} else {
|
2008-04-02 18:44:49 +00:00
|
|
|
obj->data.ifblock.s = strndup(arg, text_buffer_size);
|
2008-12-22 17:36:44 +00:00
|
|
|
obj->sub = malloc(sizeof(struct text_object));
|
|
|
|
extract_variable_text_internal(obj->sub,
|
|
|
|
obj->data.ifblock.s, 0);
|
2008-02-20 20:30:45 +00:00
|
|
|
}
|
2008-12-22 18:43:12 +00:00
|
|
|
END OBJ_IF(if_match, 0)
|
2008-12-20 01:31:00 +00:00
|
|
|
if (!arg) {
|
|
|
|
ERR("if_match needs arguments");
|
|
|
|
obj->data.ifblock.s = 0;
|
|
|
|
} else {
|
|
|
|
obj->data.ifblock.s = strndup(arg, text_buffer_size);
|
2008-12-22 17:36:44 +00:00
|
|
|
obj->sub = malloc(sizeof(struct text_object));
|
|
|
|
extract_variable_text_internal(obj->sub,
|
|
|
|
obj->data.ifblock.s, 0);
|
2008-12-20 01:31:00 +00:00
|
|
|
}
|
2008-12-22 18:43:12 +00:00
|
|
|
END OBJ_IF(if_existing, 0)
|
2008-02-20 20:30:45 +00:00
|
|
|
if (!arg) {
|
|
|
|
ERR("if_existing needs an argument or two");
|
|
|
|
obj->data.ifblock.s = NULL;
|
|
|
|
obj->data.ifblock.str = NULL;
|
2007-04-06 06:11:53 +00:00
|
|
|
} else {
|
2008-02-20 20:30:45 +00:00
|
|
|
char buf1[256], buf2[256];
|
|
|
|
int r = sscanf(arg, "%255s %255[^\n]", buf1, buf2);
|
|
|
|
|
|
|
|
if (r == 1) {
|
2008-04-02 18:44:49 +00:00
|
|
|
obj->data.ifblock.s = strndup(buf1, text_buffer_size);
|
2008-02-20 20:30:45 +00:00
|
|
|
obj->data.ifblock.str = NULL;
|
|
|
|
} else {
|
2008-04-02 18:44:49 +00:00
|
|
|
obj->data.ifblock.s = strndup(buf1, text_buffer_size);
|
|
|
|
obj->data.ifblock.str = strndup(buf2, text_buffer_size);
|
2008-02-20 20:30:45 +00:00
|
|
|
}
|
2007-04-06 06:11:53 +00:00
|
|
|
}
|
2008-12-15 01:44:21 +00:00
|
|
|
DBGP("if_existing: '%s' '%s'", obj->data.ifblock.s, obj->data.ifblock.str);
|
2008-12-22 18:43:12 +00:00
|
|
|
END OBJ_IF(if_mounted, 0)
|
2008-02-20 20:30:45 +00:00
|
|
|
if (!arg) {
|
|
|
|
ERR("if_mounted needs an argument");
|
|
|
|
obj->data.ifblock.s = 0;
|
|
|
|
} else {
|
2008-04-02 18:44:49 +00:00
|
|
|
obj->data.ifblock.s = strndup(arg, text_buffer_size);
|
2008-02-20 20:30:45 +00:00
|
|
|
}
|
2008-12-22 18:43:12 +00:00
|
|
|
END OBJ_IF(if_running, 0)
|
2008-02-20 20:30:45 +00:00
|
|
|
if (arg) {
|
|
|
|
char buf[256];
|
2007-10-02 23:57:41 +00:00
|
|
|
|
2008-02-20 20:30:45 +00:00
|
|
|
snprintf(buf, 256, "pidof %s >/dev/null", arg);
|
2008-04-02 18:44:49 +00:00
|
|
|
obj->data.ifblock.s = strndup(buf, text_buffer_size);
|
2008-02-20 20:30:45 +00:00
|
|
|
} else {
|
|
|
|
ERR("if_running needs an argument");
|
|
|
|
obj->data.ifblock.s = 0;
|
|
|
|
}
|
|
|
|
END OBJ(kernel, 0)
|
|
|
|
END OBJ(machine, 0)
|
|
|
|
END OBJ(mails, 0)
|
|
|
|
float n1;
|
|
|
|
char box[256], dst[256];
|
|
|
|
|
|
|
|
if (!arg) {
|
|
|
|
n1 = 9.5;
|
2008-04-02 18:29:08 +00:00
|
|
|
/* Kapil: Changed from MAIL_FILE to
|
|
|
|
current_mail_spool since the latter
|
|
|
|
is a copy of the former if undefined
|
|
|
|
but the latter should take precedence
|
|
|
|
if defined */
|
|
|
|
strncpy(box, current_mail_spool, sizeof(box));
|
2008-02-20 20:30:45 +00:00
|
|
|
} else {
|
|
|
|
if (sscanf(arg, "%s %f", box, &n1) != 2) {
|
2007-10-02 23:57:41 +00:00
|
|
|
n1 = 9.5;
|
2008-02-20 20:30:45 +00:00
|
|
|
strncpy(box, arg, sizeof(box));
|
2007-10-02 23:57:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-02-18 05:26:15 +00:00
|
|
|
variable_substitute(box, dst, sizeof(dst));
|
|
|
|
obj->data.local_mail.box = strndup(dst, text_buffer_size);
|
|
|
|
obj->data.local_mail.interval = n1;
|
|
|
|
END OBJ(new_mails, 0)
|
|
|
|
float n1;
|
|
|
|
char box[256], dst[256];
|
|
|
|
|
|
|
|
if (!arg) {
|
|
|
|
n1 = 9.5;
|
|
|
|
strncpy(box, current_mail_spool, sizeof(box));
|
|
|
|
} else {
|
|
|
|
if (sscanf(arg, "%s %f", box, &n1) != 2) {
|
|
|
|
n1 = 9.5;
|
|
|
|
strncpy(box, arg, sizeof(box));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
variable_substitute(box, dst, sizeof(dst));
|
|
|
|
obj->data.local_mail.box = strndup(dst, text_buffer_size);
|
|
|
|
obj->data.local_mail.interval = n1;
|
|
|
|
END OBJ(seen_mails, 0)
|
|
|
|
float n1;
|
|
|
|
char box[256], dst[256];
|
|
|
|
|
|
|
|
if (!arg) {
|
|
|
|
n1 = 9.5;
|
|
|
|
strncpy(box, current_mail_spool, sizeof(box));
|
|
|
|
} else {
|
|
|
|
if (sscanf(arg, "%s %f", box, &n1) != 2) {
|
|
|
|
n1 = 9.5;
|
|
|
|
strncpy(box, arg, sizeof(box));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
variable_substitute(box, dst, sizeof(dst));
|
|
|
|
obj->data.local_mail.box = strndup(dst, text_buffer_size);
|
|
|
|
obj->data.local_mail.interval = n1;
|
|
|
|
END OBJ(unseen_mails, 0)
|
|
|
|
float n1;
|
|
|
|
char box[256], dst[256];
|
|
|
|
|
|
|
|
if (!arg) {
|
|
|
|
n1 = 9.5;
|
|
|
|
strncpy(box, current_mail_spool, sizeof(box));
|
|
|
|
} else {
|
|
|
|
if (sscanf(arg, "%s %f", box, &n1) != 2) {
|
|
|
|
n1 = 9.5;
|
|
|
|
strncpy(box, arg, sizeof(box));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
variable_substitute(box, dst, sizeof(dst));
|
|
|
|
obj->data.local_mail.box = strndup(dst, text_buffer_size);
|
|
|
|
obj->data.local_mail.interval = n1;
|
|
|
|
END OBJ(flagged_mails, 0)
|
|
|
|
float n1;
|
|
|
|
char box[256], dst[256];
|
|
|
|
|
|
|
|
if (!arg) {
|
|
|
|
n1 = 9.5;
|
|
|
|
strncpy(box, current_mail_spool, sizeof(box));
|
|
|
|
} else {
|
|
|
|
if (sscanf(arg, "%s %f", box, &n1) != 2) {
|
|
|
|
n1 = 9.5;
|
|
|
|
strncpy(box, arg, sizeof(box));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
variable_substitute(box, dst, sizeof(dst));
|
|
|
|
obj->data.local_mail.box = strndup(dst, text_buffer_size);
|
|
|
|
obj->data.local_mail.interval = n1;
|
|
|
|
END OBJ(unflagged_mails, 0)
|
|
|
|
float n1;
|
|
|
|
char box[256], dst[256];
|
|
|
|
|
|
|
|
if (!arg) {
|
|
|
|
n1 = 9.5;
|
|
|
|
strncpy(box, current_mail_spool, sizeof(box));
|
|
|
|
} else {
|
|
|
|
if (sscanf(arg, "%s %f", box, &n1) != 2) {
|
|
|
|
n1 = 9.5;
|
|
|
|
strncpy(box, arg, sizeof(box));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
variable_substitute(box, dst, sizeof(dst));
|
|
|
|
obj->data.local_mail.box = strndup(dst, text_buffer_size);
|
|
|
|
obj->data.local_mail.interval = n1;
|
|
|
|
END OBJ(forwarded_mails, 0)
|
|
|
|
float n1;
|
|
|
|
char box[256], dst[256];
|
|
|
|
|
|
|
|
if (!arg) {
|
|
|
|
n1 = 9.5;
|
|
|
|
strncpy(box, current_mail_spool, sizeof(box));
|
|
|
|
} else {
|
|
|
|
if (sscanf(arg, "%s %f", box, &n1) != 2) {
|
|
|
|
n1 = 9.5;
|
|
|
|
strncpy(box, arg, sizeof(box));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
variable_substitute(box, dst, sizeof(dst));
|
|
|
|
obj->data.local_mail.box = strndup(dst, text_buffer_size);
|
|
|
|
obj->data.local_mail.interval = n1;
|
|
|
|
END OBJ(unforwarded_mails, 0)
|
|
|
|
float n1;
|
|
|
|
char box[256], dst[256];
|
|
|
|
|
|
|
|
if (!arg) {
|
|
|
|
n1 = 9.5;
|
|
|
|
strncpy(box, current_mail_spool, sizeof(box));
|
|
|
|
} else {
|
|
|
|
if (sscanf(arg, "%s %f", box, &n1) != 2) {
|
|
|
|
n1 = 9.5;
|
|
|
|
strncpy(box, arg, sizeof(box));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
variable_substitute(box, dst, sizeof(dst));
|
|
|
|
obj->data.local_mail.box = strndup(dst, text_buffer_size);
|
|
|
|
obj->data.local_mail.interval = n1;
|
|
|
|
END OBJ(replied_mails, 0)
|
|
|
|
float n1;
|
|
|
|
char box[256], dst[256];
|
|
|
|
|
|
|
|
if (!arg) {
|
|
|
|
n1 = 9.5;
|
|
|
|
strncpy(box, current_mail_spool, sizeof(box));
|
|
|
|
} else {
|
|
|
|
if (sscanf(arg, "%s %f", box, &n1) != 2) {
|
|
|
|
n1 = 9.5;
|
|
|
|
strncpy(box, arg, sizeof(box));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
variable_substitute(box, dst, sizeof(dst));
|
|
|
|
obj->data.local_mail.box = strndup(dst, text_buffer_size);
|
|
|
|
obj->data.local_mail.interval = n1;
|
|
|
|
END OBJ(unreplied_mails, 0)
|
|
|
|
float n1;
|
|
|
|
char box[256], dst[256];
|
|
|
|
|
|
|
|
if (!arg) {
|
|
|
|
n1 = 9.5;
|
|
|
|
strncpy(box, current_mail_spool, sizeof(box));
|
|
|
|
} else {
|
|
|
|
if (sscanf(arg, "%s %f", box, &n1) != 2) {
|
|
|
|
n1 = 9.5;
|
|
|
|
strncpy(box, arg, sizeof(box));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
variable_substitute(box, dst, sizeof(dst));
|
|
|
|
obj->data.local_mail.box = strndup(dst, text_buffer_size);
|
|
|
|
obj->data.local_mail.interval = n1;
|
|
|
|
END OBJ(draft_mails, 0)
|
|
|
|
float n1;
|
|
|
|
char box[256], dst[256];
|
|
|
|
|
|
|
|
if (!arg) {
|
|
|
|
n1 = 9.5;
|
|
|
|
strncpy(box, current_mail_spool, sizeof(box));
|
|
|
|
} else {
|
|
|
|
if (sscanf(arg, "%s %f", box, &n1) != 2) {
|
|
|
|
n1 = 9.5;
|
|
|
|
strncpy(box, arg, sizeof(box));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
variable_substitute(box, dst, sizeof(dst));
|
|
|
|
obj->data.local_mail.box = strndup(dst, text_buffer_size);
|
|
|
|
obj->data.local_mail.interval = n1;
|
|
|
|
END OBJ(trashed_mails, 0)
|
|
|
|
float n1;
|
|
|
|
char box[256], dst[256];
|
|
|
|
|
|
|
|
if (!arg) {
|
|
|
|
n1 = 9.5;
|
|
|
|
strncpy(box, current_mail_spool, sizeof(box));
|
|
|
|
} else {
|
|
|
|
if (sscanf(arg, "%s %f", box, &n1) != 2) {
|
|
|
|
n1 = 9.5;
|
|
|
|
strncpy(box, arg, sizeof(box));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-02-20 20:30:45 +00:00
|
|
|
variable_substitute(box, dst, sizeof(dst));
|
2008-04-02 18:44:49 +00:00
|
|
|
obj->data.local_mail.box = strndup(dst, text_buffer_size);
|
2008-02-20 20:30:45 +00:00
|
|
|
obj->data.local_mail.interval = n1;
|
|
|
|
END OBJ(mboxscan, 0)
|
2008-03-20 21:28:19 +00:00
|
|
|
obj->data.mboxscan.args = (char *) malloc(text_buffer_size);
|
|
|
|
obj->data.mboxscan.output = (char *) malloc(text_buffer_size);
|
2007-03-01 01:43:43 +00:00
|
|
|
/* if '1' (in mboxscan.c) then there was SIGUSR1, hmm */
|
|
|
|
obj->data.mboxscan.output[0] = 1;
|
2008-03-20 21:28:19 +00:00
|
|
|
strncpy(obj->data.mboxscan.args, arg, text_buffer_size);
|
2008-02-20 20:30:45 +00:00
|
|
|
END OBJ(mem, INFO_MEM)
|
2008-06-21 20:37:58 +00:00
|
|
|
END OBJ(memeasyfree, INFO_MEM)
|
|
|
|
END OBJ(memfree, INFO_MEM)
|
2008-02-20 20:30:45 +00:00
|
|
|
END OBJ(memmax, INFO_MEM)
|
|
|
|
END OBJ(memperc, INFO_MEM)
|
2009-03-11 00:37:24 +00:00
|
|
|
END OBJ(memgauge, INFO_MEM)
|
|
|
|
scan_gauge(arg, &obj->data.pair.a, &obj->data.pair.b);
|
2008-02-20 20:30:45 +00:00
|
|
|
END OBJ(membar, INFO_MEM)
|
|
|
|
scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
|
2005-08-10 16:07:03 +00:00
|
|
|
END OBJ(memgraph, INFO_MEM)
|
2008-02-09 02:21:06 +00:00
|
|
|
char *buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
|
2008-06-21 20:37:58 +00:00
|
|
|
&obj->e, &obj->showaslog);
|
2008-02-09 02:21:06 +00:00
|
|
|
|
|
|
|
if (buf) {
|
|
|
|
free(buf);
|
|
|
|
}
|
2008-02-20 20:30:45 +00:00
|
|
|
END OBJ(mixer, INFO_MIXER)
|
|
|
|
obj->data.l = mixer_init(arg);
|
|
|
|
END OBJ(mixerl, INFO_MIXER)
|
|
|
|
obj->data.l = mixer_init(arg);
|
|
|
|
END OBJ(mixerr, INFO_MIXER)
|
|
|
|
obj->data.l = mixer_init(arg);
|
2005-07-20 00:30:40 +00:00
|
|
|
END OBJ(mixerbar, INFO_MIXER)
|
2008-02-20 20:30:45 +00:00
|
|
|
scan_mixer_bar(arg, &obj->data.mixerbar.l, &obj->data.mixerbar.w,
|
|
|
|
&obj->data.mixerbar.h);
|
2005-07-20 00:30:40 +00:00
|
|
|
END OBJ(mixerlbar, INFO_MIXER)
|
2008-02-20 20:30:45 +00:00
|
|
|
scan_mixer_bar(arg, &obj->data.mixerbar.l, &obj->data.mixerbar.w,
|
|
|
|
&obj->data.mixerbar.h);
|
2005-07-20 00:30:40 +00:00
|
|
|
END OBJ(mixerrbar, INFO_MIXER)
|
2008-02-20 20:30:45 +00:00
|
|
|
scan_mixer_bar(arg, &obj->data.mixerbar.l, &obj->data.mixerbar.w,
|
|
|
|
&obj->data.mixerbar.h);
|
2009-04-28 16:56:49 +00:00
|
|
|
END OBJ_IF(if_mixer_mute, INFO_MIXER)
|
|
|
|
obj->data.ifblock.i = mixer_init(arg);
|
2008-06-21 20:37:58 +00:00
|
|
|
#ifdef X11
|
|
|
|
END OBJ(monitor, INFO_X11)
|
|
|
|
END OBJ(monitor_number, INFO_X11)
|
|
|
|
#endif
|
2008-02-20 20:30:45 +00:00
|
|
|
END OBJ(nodename, 0)
|
|
|
|
END OBJ(processes, INFO_PROCS)
|
|
|
|
END OBJ(running_processes, INFO_RUN_PROCS)
|
|
|
|
END OBJ(shadecolor, 0)
|
2005-08-08 01:18:52 +00:00
|
|
|
#ifdef X11
|
2006-01-28 01:28:23 +00:00
|
|
|
obj->data.l = arg ? get_x11_color(arg) : default_bg_color;
|
2005-08-08 01:18:52 +00:00
|
|
|
#endif /* X11 */
|
2005-07-20 00:30:40 +00:00
|
|
|
END OBJ(outlinecolor, 0)
|
2005-08-08 01:18:52 +00:00
|
|
|
#ifdef X11
|
2006-01-28 01:28:23 +00:00
|
|
|
obj->data.l = arg ? get_x11_color(arg) : default_out_color;
|
2005-08-08 01:18:52 +00:00
|
|
|
#endif /* X11 */
|
|
|
|
END OBJ(stippled_hr, 0)
|
|
|
|
#ifdef X11
|
2006-01-28 01:28:23 +00:00
|
|
|
int a = stippled_borders, b = 1;
|
2008-02-20 20:30:45 +00:00
|
|
|
|
|
|
|
if (arg) {
|
|
|
|
if (sscanf(arg, "%d %d", &a, &b) != 2) {
|
|
|
|
sscanf(arg, "%d", &b);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (a <= 0) {
|
|
|
|
a = 1;
|
|
|
|
}
|
|
|
|
obj->data.pair.a = a;
|
|
|
|
obj->data.pair.b = b;
|
2005-08-08 01:18:52 +00:00
|
|
|
#endif /* X11 */
|
2005-07-20 00:30:40 +00:00
|
|
|
END OBJ(swap, INFO_MEM)
|
2008-02-20 20:30:45 +00:00
|
|
|
END OBJ(swapmax, INFO_MEM)
|
|
|
|
END OBJ(swapperc, INFO_MEM)
|
|
|
|
END OBJ(swapbar, INFO_MEM)
|
|
|
|
scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
|
2007-08-10 21:14:06 +00:00
|
|
|
END OBJ(sysname, 0)
|
2008-02-20 20:30:45 +00:00
|
|
|
END OBJ(time, 0)
|
2008-04-02 18:44:49 +00:00
|
|
|
obj->data.s = strndup(arg ? arg : "%F %T", text_buffer_size);
|
2008-02-20 20:30:45 +00:00
|
|
|
END OBJ(utime, 0)
|
2008-04-02 18:44:49 +00:00
|
|
|
obj->data.s = strndup(arg ? arg : "%F %T", text_buffer_size);
|
2006-07-15 02:18:06 +00:00
|
|
|
END OBJ(tztime, 0)
|
|
|
|
char buf1[256], buf2[256], *fmt, *tz;
|
2008-02-20 20:30:45 +00:00
|
|
|
|
2006-07-15 02:18:06 +00:00
|
|
|
fmt = tz = NULL;
|
|
|
|
if (arg) {
|
|
|
|
int nArgs = sscanf(arg, "%255s %255[^\n]", buf1, buf2);
|
2008-02-20 20:30:45 +00:00
|
|
|
|
2006-07-15 02:18:06 +00:00
|
|
|
switch (nArgs) {
|
|
|
|
case 2:
|
|
|
|
tz = buf1;
|
|
|
|
case 1:
|
|
|
|
fmt = buf2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-04-02 18:44:49 +00:00
|
|
|
obj->data.tztime.fmt = strndup(fmt ? fmt : "%F %T", text_buffer_size);
|
|
|
|
obj->data.tztime.tz = tz ? strndup(tz, text_buffer_size) : NULL;
|
2006-05-13 20:14:26 +00:00
|
|
|
#ifdef HAVE_ICONV
|
2006-05-13 19:51:26 +00:00
|
|
|
END OBJ(iconv_start, 0)
|
|
|
|
if (iconv_converting) {
|
2008-02-20 20:30:45 +00:00
|
|
|
CRIT_ERR("You must stop your last iconv conversion before "
|
|
|
|
"starting another");
|
2006-05-13 19:51:26 +00:00
|
|
|
}
|
|
|
|
if (arg) {
|
|
|
|
char iconv_from[CODEPAGE_LENGTH];
|
|
|
|
char iconv_to[CODEPAGE_LENGTH];
|
2008-02-20 20:30:45 +00:00
|
|
|
|
2006-05-13 19:51:26 +00:00
|
|
|
if (sscanf(arg, "%s %s", iconv_from, iconv_to) != 2) {
|
|
|
|
CRIT_ERR("Invalid arguments for iconv_start");
|
|
|
|
} else {
|
|
|
|
iconv_t new_iconv;
|
2008-02-20 20:30:45 +00:00
|
|
|
|
2006-05-13 19:51:26 +00:00
|
|
|
new_iconv = iconv_open(iconv_to, iconv_from);
|
2008-02-20 20:30:45 +00:00
|
|
|
if (new_iconv == (iconv_t) (-1)) {
|
2006-05-13 19:51:26 +00:00
|
|
|
ERR("Can't convert from %s to %s.", iconv_from, iconv_to);
|
|
|
|
} else {
|
|
|
|
obj->a = register_iconv(&new_iconv);
|
|
|
|
iconv_converting = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
CRIT_ERR("Iconv requires arguments");
|
|
|
|
}
|
|
|
|
END OBJ(iconv_stop, 0)
|
|
|
|
iconv_converting = 0;
|
2008-02-20 20:30:45 +00:00
|
|
|
|
2006-05-13 19:51:26 +00:00
|
|
|
#endif
|
2005-08-29 16:49:09 +00:00
|
|
|
END OBJ(totaldown, INFO_NET)
|
2008-02-20 20:30:45 +00:00
|
|
|
if (arg) {
|
2005-08-29 16:49:09 +00:00
|
|
|
obj->data.net = get_net_stat(arg);
|
2008-02-20 20:30:45 +00:00
|
|
|
} else {
|
2005-08-29 16:49:09 +00:00
|
|
|
CRIT_ERR("totaldown needs argument");
|
|
|
|
}
|
2008-02-20 20:30:45 +00:00
|
|
|
END OBJ(totalup, INFO_NET)
|
2006-01-28 01:28:23 +00:00
|
|
|
obj->data.net = get_net_stat(arg);
|
2008-02-20 20:30:45 +00:00
|
|
|
if (arg) {
|
|
|
|
obj->data.net = get_net_stat(arg);
|
|
|
|
} else {
|
|
|
|
CRIT_ERR("totalup needs argument");
|
|
|
|
}
|
2005-07-20 00:30:40 +00:00
|
|
|
END OBJ(updates, 0)
|
2009-03-01 14:10:01 +00:00
|
|
|
END OBJ_IF(if_updatenr, 0)
|
|
|
|
obj->data.ifblock.i = arg ? atoi(arg) : 0;
|
|
|
|
if(obj->data.ifblock.i == 0) CRIT_ERR("if_updatenr needs a number above 0 as argument");
|
|
|
|
updatereset = obj->data.ifblock.i > updatereset ? obj->data.ifblock.i : updatereset;
|
2008-02-20 20:30:45 +00:00
|
|
|
END OBJ(alignr, 0)
|
|
|
|
obj->data.i = arg ? atoi(arg) : 0;
|
|
|
|
END OBJ(alignc, 0)
|
|
|
|
obj->data.i = arg ? atoi(arg) : 0;
|
2005-08-29 16:49:09 +00:00
|
|
|
END OBJ(upspeed, INFO_NET)
|
2008-02-20 20:30:45 +00:00
|
|
|
if (arg) {
|
2005-08-29 16:49:09 +00:00
|
|
|
obj->data.net = get_net_stat(arg);
|
2008-02-20 20:30:45 +00:00
|
|
|
} else {
|
2005-08-29 16:49:09 +00:00
|
|
|
CRIT_ERR("upspeed needs argument");
|
|
|
|
}
|
2008-02-20 20:30:45 +00:00
|
|
|
END OBJ(upspeedf, INFO_NET)
|
|
|
|
if (arg) {
|
2005-08-29 16:49:09 +00:00
|
|
|
obj->data.net = get_net_stat(arg);
|
2008-02-20 20:30:45 +00:00
|
|
|
} else {
|
2005-08-29 16:49:09 +00:00
|
|
|
CRIT_ERR("upspeedf needs argument");
|
|
|
|
}
|
|
|
|
|
2005-07-29 04:32:56 +00:00
|
|
|
END OBJ(upspeedgraph, INFO_NET)
|
2008-02-09 02:21:06 +00:00
|
|
|
char *buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
|
2008-06-21 20:37:58 +00:00
|
|
|
&obj->e, &obj->showaslog);
|
2008-02-09 02:21:06 +00:00
|
|
|
|
2008-09-01 22:05:24 +00:00
|
|
|
// default to DEFAULTNETDEV
|
|
|
|
buf = strndup(buf ? buf : "DEFAULTNETDEV", text_buffer_size);
|
|
|
|
obj->data.net = get_net_stat(buf);
|
|
|
|
free(buf);
|
2008-02-20 20:30:45 +00:00
|
|
|
END OBJ(uptime_short, INFO_UPTIME)
|
2008-09-01 22:05:24 +00:00
|
|
|
END OBJ(uptime, INFO_UPTIME)
|
|
|
|
END OBJ(user_names, INFO_USERS)
|
|
|
|
END OBJ(user_times, INFO_USERS)
|
|
|
|
END OBJ(user_terms, INFO_USERS)
|
|
|
|
END OBJ(user_number, INFO_USERS)
|
2008-05-03 12:30:05 +00:00
|
|
|
#if defined(__linux__)
|
2008-09-01 22:05:24 +00:00
|
|
|
END OBJ(gw_iface, INFO_GW)
|
|
|
|
END OBJ(gw_ip, INFO_GW)
|
|
|
|
END OBJ(if_gw, INFO_GW)
|
2008-05-03 12:30:05 +00:00
|
|
|
#endif /* !__linux__ */
|
2007-08-10 21:14:06 +00:00
|
|
|
#ifndef __OpenBSD__
|
2008-09-01 22:05:24 +00:00
|
|
|
END OBJ(adt746xcpu, 0)
|
|
|
|
END OBJ(adt746xfan, 0)
|
2007-08-10 21:14:06 +00:00
|
|
|
#endif /* !__OpenBSD__ */
|
2008-02-20 20:30:45 +00:00
|
|
|
#if (defined(__FreeBSD__) || defined(__FreeBSD_kernel__) \
|
|
|
|
|| defined(__OpenBSD__)) && (defined(i386) || defined(__i386__))
|
2008-09-01 22:05:24 +00:00
|
|
|
END OBJ(apm_adapter, 0)
|
|
|
|
END OBJ(apm_battery_life, 0)
|
|
|
|
END OBJ(apm_battery_time, 0)
|
2005-08-30 04:19:16 +00:00
|
|
|
#endif /* __FreeBSD__ */
|
2008-09-01 22:05:24 +00:00
|
|
|
END OBJ_THREAD(imap_unseen, 0)
|
2006-05-08 22:34:38 +00:00
|
|
|
if (arg) {
|
|
|
|
// proccss
|
2008-12-14 02:53:05 +00:00
|
|
|
obj->data.mail = parse_mail_args(IMAP_TYPE, arg);
|
2006-05-08 22:34:38 +00:00
|
|
|
obj->global_mode = 0;
|
|
|
|
} else {
|
|
|
|
obj->global_mode = 1;
|
|
|
|
}
|
2008-07-17 03:14:37 +00:00
|
|
|
END OBJ_THREAD(imap_messages, 0)
|
2006-05-08 22:34:38 +00:00
|
|
|
if (arg) {
|
|
|
|
// proccss
|
2008-12-14 02:53:05 +00:00
|
|
|
obj->data.mail = parse_mail_args(IMAP_TYPE, arg);
|
2006-05-08 22:34:38 +00:00
|
|
|
obj->global_mode = 0;
|
|
|
|
} else {
|
|
|
|
obj->global_mode = 1;
|
|
|
|
}
|
2008-07-17 03:14:37 +00:00
|
|
|
END OBJ_THREAD(pop3_unseen, 0)
|
2006-05-08 22:34:38 +00:00
|
|
|
if (arg) {
|
|
|
|
// proccss
|
2008-12-14 02:53:05 +00:00
|
|
|
obj->data.mail = parse_mail_args(POP3_TYPE, arg);
|
2006-05-08 22:34:38 +00:00
|
|
|
obj->global_mode = 0;
|
|
|
|
} else {
|
|
|
|
obj->global_mode = 1;
|
|
|
|
}
|
2008-07-17 03:14:37 +00:00
|
|
|
END OBJ_THREAD(pop3_used, 0)
|
2006-05-08 22:34:38 +00:00
|
|
|
if (arg) {
|
|
|
|
// proccss
|
2008-12-14 02:53:05 +00:00
|
|
|
obj->data.mail = parse_mail_args(POP3_TYPE, arg);
|
2006-05-08 22:34:38 +00:00
|
|
|
obj->global_mode = 0;
|
|
|
|
} else {
|
|
|
|
obj->global_mode = 1;
|
|
|
|
}
|
2009-01-03 23:25:15 +00:00
|
|
|
#ifdef IBM
|
2008-08-14 17:10:41 +00:00
|
|
|
END OBJ(smapi, 0)
|
2008-03-18 00:23:16 +00:00
|
|
|
if (arg)
|
2008-04-02 18:44:49 +00:00
|
|
|
obj->data.s = strndup(arg, text_buffer_size);
|
2008-03-18 00:23:16 +00:00
|
|
|
else
|
|
|
|
ERR("smapi needs an argument");
|
2008-12-22 18:43:12 +00:00
|
|
|
END OBJ_IF(if_smapi_bat_installed, 0)
|
2008-09-01 22:05:24 +00:00
|
|
|
if (!arg) {
|
|
|
|
ERR("if_smapi_bat_installed needs an argument");
|
|
|
|
obj->data.ifblock.s = 0;
|
|
|
|
} else
|
|
|
|
obj->data.ifblock.s = strndup(arg, text_buffer_size);
|
2008-03-18 00:23:16 +00:00
|
|
|
END OBJ(smapi_bat_perc, 0)
|
|
|
|
if (arg)
|
2008-04-02 18:44:49 +00:00
|
|
|
obj->data.s = strndup(arg, text_buffer_size);
|
2008-03-18 00:23:16 +00:00
|
|
|
else
|
|
|
|
ERR("smapi_bat_perc needs an argument");
|
2008-06-25 10:08:27 +00:00
|
|
|
END OBJ(smapi_bat_temp, 0)
|
|
|
|
if (arg)
|
|
|
|
obj->data.s = strndup(arg, text_buffer_size);
|
|
|
|
else
|
|
|
|
ERR("smapi_bat_temp needs an argument");
|
|
|
|
END OBJ(smapi_bat_power, 0)
|
|
|
|
if (arg)
|
|
|
|
obj->data.s = strndup(arg, text_buffer_size);
|
|
|
|
else
|
|
|
|
ERR("smapi_bat_power needs an argument");
|
2008-03-18 00:23:16 +00:00
|
|
|
END OBJ(smapi_bat_bar, 0)
|
|
|
|
if(arg) {
|
|
|
|
int cnt;
|
|
|
|
if(sscanf(arg, "%i %n", &obj->data.i, &cnt) <= 0) {
|
|
|
|
ERR("first argument to smapi_bat_bar must be an integer value");
|
|
|
|
obj->data.i = -1;
|
2007-08-31 02:05:02 +00:00
|
|
|
} else {
|
2008-03-18 00:23:16 +00:00
|
|
|
obj->b = 4;
|
|
|
|
arg = scan_bar(arg + cnt, &obj->a, &obj->b);
|
2008-02-20 20:30:45 +00:00
|
|
|
}
|
2008-03-18 00:23:16 +00:00
|
|
|
} else
|
2008-12-15 01:44:21 +00:00
|
|
|
ERR("smapi_bat_bar needs an argument");
|
2009-01-03 23:25:15 +00:00
|
|
|
#endif /* IBM */
|
2008-03-18 00:23:16 +00:00
|
|
|
#ifdef MPD
|
2008-12-18 12:37:53 +00:00
|
|
|
#define mpd_set_maxlen(name) \
|
|
|
|
if (arg) { \
|
|
|
|
int i; \
|
|
|
|
sscanf(arg, "%d", &i); \
|
|
|
|
if (i > 0) \
|
|
|
|
obj->data.i = i + 1; \
|
|
|
|
else \
|
|
|
|
ERR(#name ": invalid length argument"); \
|
2008-12-15 15:59:07 +00:00
|
|
|
}
|
2008-12-20 01:32:45 +00:00
|
|
|
END OBJ(mpd_artist, INFO_MPD)
|
2008-12-18 12:37:53 +00:00
|
|
|
mpd_set_maxlen(mpd_artist);
|
|
|
|
init_mpd();
|
2008-12-20 01:32:45 +00:00
|
|
|
END OBJ(mpd_title, INFO_MPD)
|
2008-12-18 12:37:53 +00:00
|
|
|
mpd_set_maxlen(mpd_title);
|
|
|
|
init_mpd();
|
2008-12-20 01:32:45 +00:00
|
|
|
END OBJ(mpd_random, INFO_MPD) init_mpd();
|
|
|
|
END OBJ(mpd_repeat, INFO_MPD) init_mpd();
|
|
|
|
END OBJ(mpd_elapsed, INFO_MPD) init_mpd();
|
|
|
|
END OBJ(mpd_length, INFO_MPD) init_mpd();
|
|
|
|
END OBJ(mpd_track, INFO_MPD)
|
2008-12-18 12:37:53 +00:00
|
|
|
mpd_set_maxlen(mpd_track);
|
|
|
|
init_mpd();
|
2008-12-20 01:32:45 +00:00
|
|
|
END OBJ(mpd_name, INFO_MPD)
|
2008-12-18 12:37:53 +00:00
|
|
|
mpd_set_maxlen(mpd_name);
|
|
|
|
init_mpd();
|
2008-12-20 01:32:45 +00:00
|
|
|
END OBJ(mpd_file, INFO_MPD)
|
2008-12-18 12:37:53 +00:00
|
|
|
mpd_set_maxlen(mpd_file);
|
|
|
|
init_mpd();
|
2008-12-20 01:32:45 +00:00
|
|
|
END OBJ(mpd_percent, INFO_MPD) init_mpd();
|
|
|
|
END OBJ(mpd_album, INFO_MPD)
|
2008-12-18 12:37:53 +00:00
|
|
|
mpd_set_maxlen(mpd_album);
|
|
|
|
init_mpd();
|
2008-12-20 01:32:45 +00:00
|
|
|
END OBJ(mpd_vol, INFO_MPD) init_mpd();
|
|
|
|
END OBJ(mpd_bitrate, INFO_MPD) init_mpd();
|
|
|
|
END OBJ(mpd_status, INFO_MPD) init_mpd();
|
|
|
|
END OBJ(mpd_bar, INFO_MPD)
|
2008-09-01 22:05:24 +00:00
|
|
|
scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
|
2008-12-18 12:37:53 +00:00
|
|
|
init_mpd();
|
2008-12-20 01:32:45 +00:00
|
|
|
END OBJ(mpd_smart, INFO_MPD)
|
2008-12-18 12:37:53 +00:00
|
|
|
mpd_set_maxlen(mpd_smart);
|
|
|
|
init_mpd();
|
2008-12-22 18:43:12 +00:00
|
|
|
END OBJ_IF(if_mpd_playing, INFO_MPD)
|
2008-12-18 12:37:53 +00:00
|
|
|
init_mpd();
|
|
|
|
#undef mpd_set_maxlen
|
2008-08-14 17:10:41 +00:00
|
|
|
#endif /* MPD */
|
2008-09-24 06:59:45 +00:00
|
|
|
#ifdef MOC
|
2008-12-22 18:31:48 +00:00
|
|
|
END OBJ(moc_state, INFO_MOC)
|
|
|
|
END OBJ(moc_file, INFO_MOC)
|
|
|
|
END OBJ(moc_title, INFO_MOC)
|
|
|
|
END OBJ(moc_artist, INFO_MOC)
|
|
|
|
END OBJ(moc_song, INFO_MOC)
|
|
|
|
END OBJ(moc_album, INFO_MOC)
|
|
|
|
END OBJ(moc_totaltime, INFO_MOC)
|
|
|
|
END OBJ(moc_timeleft, INFO_MOC)
|
|
|
|
END OBJ(moc_curtime, INFO_MOC)
|
|
|
|
END OBJ(moc_bitrate, INFO_MOC)
|
|
|
|
END OBJ(moc_rate, INFO_MOC)
|
2008-09-24 06:59:45 +00:00
|
|
|
#endif /* MOC */
|
2006-03-25 21:21:07 +00:00
|
|
|
#ifdef XMMS2
|
2008-09-01 22:05:24 +00:00
|
|
|
END OBJ(xmms2_artist, INFO_XMMS2)
|
|
|
|
END OBJ(xmms2_album, INFO_XMMS2)
|
|
|
|
END OBJ(xmms2_title, INFO_XMMS2)
|
|
|
|
END OBJ(xmms2_genre, INFO_XMMS2)
|
|
|
|
END OBJ(xmms2_comment, INFO_XMMS2)
|
|
|
|
END OBJ(xmms2_url, INFO_XMMS2)
|
|
|
|
END OBJ(xmms2_tracknr, INFO_XMMS2)
|
|
|
|
END OBJ(xmms2_bitrate, INFO_XMMS2)
|
|
|
|
END OBJ(xmms2_date, INFO_XMMS2)
|
|
|
|
END OBJ(xmms2_id, INFO_XMMS2)
|
|
|
|
END OBJ(xmms2_duration, INFO_XMMS2)
|
|
|
|
END OBJ(xmms2_elapsed, INFO_XMMS2)
|
|
|
|
END OBJ(xmms2_size, INFO_XMMS2)
|
|
|
|
END OBJ(xmms2_status, INFO_XMMS2)
|
|
|
|
END OBJ(xmms2_percent, INFO_XMMS2)
|
|
|
|
END OBJ(xmms2_bar, INFO_XMMS2)
|
|
|
|
scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
|
|
|
|
END OBJ(xmms2_smart, INFO_XMMS2)
|
|
|
|
END OBJ(xmms2_playlist, INFO_XMMS2)
|
|
|
|
END OBJ(xmms2_timesplayed, INFO_XMMS2)
|
2008-12-22 18:43:12 +00:00
|
|
|
END OBJ_IF(if_xmms2_connected, INFO_XMMS2)
|
2006-03-25 21:21:07 +00:00
|
|
|
#endif
|
2006-11-03 20:54:52 +00:00
|
|
|
#ifdef AUDACIOUS
|
2008-09-01 22:05:24 +00:00
|
|
|
END OBJ(audacious_status, INFO_AUDACIOUS)
|
|
|
|
END OBJ(audacious_title, INFO_AUDACIOUS)
|
|
|
|
if (arg) {
|
|
|
|
sscanf(arg, "%d", &info.audacious.max_title_len);
|
|
|
|
if (info.audacious.max_title_len > 0) {
|
|
|
|
info.audacious.max_title_len++;
|
|
|
|
} else {
|
|
|
|
CRIT_ERR("audacious_title: invalid length argument");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
END OBJ(audacious_length, INFO_AUDACIOUS)
|
|
|
|
END OBJ(audacious_length_seconds, INFO_AUDACIOUS)
|
|
|
|
END OBJ(audacious_position, INFO_AUDACIOUS)
|
|
|
|
END OBJ(audacious_position_seconds, INFO_AUDACIOUS)
|
|
|
|
END OBJ(audacious_bitrate, INFO_AUDACIOUS)
|
|
|
|
END OBJ(audacious_frequency, INFO_AUDACIOUS)
|
|
|
|
END OBJ(audacious_channels, INFO_AUDACIOUS)
|
|
|
|
END OBJ(audacious_filename, INFO_AUDACIOUS)
|
|
|
|
END OBJ(audacious_playlist_length, INFO_AUDACIOUS)
|
|
|
|
END OBJ(audacious_playlist_position, INFO_AUDACIOUS)
|
2008-12-07 07:38:06 +00:00
|
|
|
END OBJ(audacious_main_volume, INFO_AUDACIOUS)
|
2008-09-01 22:05:24 +00:00
|
|
|
END OBJ(audacious_bar, INFO_AUDACIOUS)
|
|
|
|
scan_bar(arg, &obj->a, &obj->b);
|
2006-01-07 07:01:22 +00:00
|
|
|
#endif
|
2005-12-30 09:44:40 +00:00
|
|
|
#ifdef BMPX
|
2008-09-01 22:05:24 +00:00
|
|
|
END OBJ(bmpx_title, INFO_BMPX)
|
|
|
|
memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
|
|
|
|
END OBJ(bmpx_artist, INFO_BMPX)
|
|
|
|
memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
|
|
|
|
END OBJ(bmpx_album, INFO_BMPX)
|
|
|
|
memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
|
|
|
|
END OBJ(bmpx_track, INFO_BMPX)
|
|
|
|
memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
|
|
|
|
END OBJ(bmpx_uri, INFO_BMPX)
|
|
|
|
memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
|
|
|
|
END OBJ(bmpx_bitrate, INFO_BMPX)
|
|
|
|
memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
|
2008-06-28 20:14:04 +00:00
|
|
|
#endif
|
|
|
|
#ifdef EVE
|
2008-09-01 22:05:24 +00:00
|
|
|
END OBJ(eve, 0)
|
|
|
|
if(arg) {
|
|
|
|
int argc;
|
|
|
|
char *userid = (char *) malloc(20 * sizeof(char));
|
|
|
|
char *apikey = (char *) malloc(64 * sizeof(char));
|
|
|
|
char *charid = (char *) malloc(20 * sizeof(char));
|
|
|
|
|
|
|
|
argc = sscanf(arg, "%20s %64s %20s", userid, apikey, charid);
|
|
|
|
obj->data.eve.charid = charid;
|
|
|
|
obj->data.eve.userid = userid;
|
|
|
|
obj->data.eve.apikey = apikey;
|
|
|
|
|
|
|
|
init_eve();
|
|
|
|
} else {
|
|
|
|
CRIT_ERR("eve needs arguments: <userid> <apikey> <characterid>");
|
|
|
|
}
|
2005-12-30 09:44:40 +00:00
|
|
|
#endif
|
2007-05-06 12:17:13 +00:00
|
|
|
#ifdef RSS
|
2008-09-01 22:05:24 +00:00
|
|
|
END OBJ(rss, 0)
|
|
|
|
if (arg) {
|
|
|
|
int argc, delay, act_par;
|
2009-04-18 22:42:01 +00:00
|
|
|
unsigned int nrspaces = 0;
|
2008-09-01 22:05:24 +00:00
|
|
|
char *uri = (char *) malloc(128 * sizeof(char));
|
|
|
|
char *action = (char *) malloc(64 * sizeof(char));
|
|
|
|
|
2009-04-18 22:42:01 +00:00
|
|
|
argc = sscanf(arg, "%127s %d %63s %d %u", uri, &delay, action,
|
|
|
|
&act_par, &nrspaces);
|
2008-09-01 22:05:24 +00:00
|
|
|
obj->data.rss.uri = uri;
|
|
|
|
obj->data.rss.delay = delay;
|
|
|
|
obj->data.rss.action = action;
|
|
|
|
obj->data.rss.act_par = act_par;
|
2009-04-18 22:42:01 +00:00
|
|
|
obj->data.rss.nrspaces = nrspaces;
|
2008-09-01 22:05:24 +00:00
|
|
|
|
|
|
|
init_rss_info();
|
|
|
|
} else {
|
|
|
|
CRIT_ERR("rss needs arguments: <uri> <delay in minutes> <action> "
|
2009-04-18 22:42:01 +00:00
|
|
|
"[act_par] [spaces in front]");
|
2008-09-01 22:05:24 +00:00
|
|
|
}
|
2007-05-06 12:17:13 +00:00
|
|
|
#endif
|
2006-08-10 16:56:13 +00:00
|
|
|
#ifdef HDDTEMP
|
2008-09-01 22:05:24 +00:00
|
|
|
END OBJ(hddtemp, 0)
|
2008-12-08 15:01:15 +00:00
|
|
|
if (scan_hddtemp(arg, &obj->data.hddtemp.dev,
|
|
|
|
&obj->data.hddtemp.addr, &obj->data.hddtemp.port)) {
|
2008-09-01 22:05:24 +00:00
|
|
|
ERR("hddtemp needs arguments");
|
|
|
|
obj->type = OBJ_text;
|
|
|
|
obj->data.s = strndup("${hddtemp}", text_buffer_size);
|
|
|
|
obj->data.hddtemp.update_time = 0;
|
2008-12-08 15:01:15 +00:00
|
|
|
} else
|
|
|
|
obj->data.hddtemp.temp = NULL;
|
2006-08-10 16:56:13 +00:00
|
|
|
#endif
|
2005-10-31 05:17:06 +00:00
|
|
|
#ifdef TCP_PORT_MONITOR
|
2008-09-01 22:05:24 +00:00
|
|
|
END OBJ(tcp_portmon, INFO_TCP_PORT_MONITOR)
|
2008-12-09 13:44:14 +00:00
|
|
|
tcp_portmon_init(arg, &obj->data.tcp_port_monitor);
|
2005-07-20 00:30:40 +00:00
|
|
|
#endif
|
2008-09-01 22:05:24 +00:00
|
|
|
END OBJ(entropy_avail, INFO_ENTROPY)
|
|
|
|
END OBJ(entropy_poolsize, INFO_ENTROPY)
|
|
|
|
END OBJ(entropy_bar, INFO_ENTROPY)
|
|
|
|
scan_bar(arg, &obj->a, &obj->b);
|
|
|
|
END OBJ(scroll, 0)
|
2008-11-04 23:25:28 +00:00
|
|
|
int n1, n2;
|
2008-07-12 01:22:40 +00:00
|
|
|
|
2008-09-24 06:59:45 +00:00
|
|
|
obj->data.scroll.step = 1;
|
2008-11-04 23:25:28 +00:00
|
|
|
if (arg && sscanf(arg, "%u %n", &obj->data.scroll.show, &n1) > 0) {
|
|
|
|
if (sscanf(arg + n1, "%u %n", &obj->data.scroll.step, &n2) > 0)
|
|
|
|
n1 += n2;
|
|
|
|
obj->data.scroll.text = strndup(arg + n1, text_buffer_size);
|
2008-09-01 22:05:24 +00:00
|
|
|
obj->data.scroll.start = 0;
|
2008-12-22 17:36:44 +00:00
|
|
|
obj->sub = malloc(sizeof(struct text_object));
|
|
|
|
extract_variable_text_internal(obj->sub,
|
|
|
|
obj->data.scroll.text, 0);
|
2008-09-01 22:05:24 +00:00
|
|
|
} else {
|
2008-09-24 06:59:45 +00:00
|
|
|
CRIT_ERR("scroll needs arguments: <length> [<step>] <text>");
|
2008-09-01 22:05:24 +00:00
|
|
|
}
|
2009-04-30 19:05:59 +00:00
|
|
|
END OBJ(combine, 0)
|
|
|
|
if(arg) {
|
|
|
|
unsigned int i,j;
|
|
|
|
unsigned int indenting = 0; //vars can be used as args for other vars
|
|
|
|
int startvar[2];
|
|
|
|
int endvar[2];
|
|
|
|
startvar[0] = endvar[0] = startvar[1] = endvar[1] = -1;
|
|
|
|
j=0;
|
|
|
|
for(i=0; arg[i] != 0 && j < 2; i++) {
|
|
|
|
if(startvar[j] == -1) {
|
|
|
|
if(arg[i] == '$') {
|
|
|
|
startvar[j] = i;
|
|
|
|
}
|
|
|
|
}else if(endvar[j] == -1) {
|
|
|
|
if(arg[i] == '{') {
|
|
|
|
indenting++;
|
|
|
|
}else if(arg[i] == '}') {
|
|
|
|
indenting--;
|
|
|
|
}
|
2009-05-04 19:15:46 +00:00
|
|
|
if (indenting == 0 && arg[i+1] < 48) { //<48 has 0, $, and the most used chars not used in varnames but not { or }
|
2009-04-30 19:05:59 +00:00
|
|
|
endvar[j]=i+1;
|
|
|
|
j++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(startvar[0] >= 0 && endvar[0] >= 0 && startvar[1] >= 0 && endvar[1] >= 0) {
|
|
|
|
obj->data.combine.left=malloc(endvar[0]-startvar[0]+1);
|
|
|
|
obj->data.combine.seperation=malloc(startvar[1]-endvar[0]+1);
|
|
|
|
obj->data.combine.right=malloc(endvar[1]-startvar[1]+1);
|
|
|
|
strncpy(obj->data.combine.left, arg+startvar[0], endvar[0]-startvar[0]); obj->data.combine.left[endvar[0]-startvar[0]]=0;
|
|
|
|
strncpy(obj->data.combine.seperation, arg+endvar[0], startvar[1]-endvar[0]); obj->data.combine.seperation[startvar[1]-endvar[0]]=0;
|
|
|
|
strncpy(obj->data.combine.right, arg+startvar[1], endvar[1]-startvar[1]); obj->data.combine.right[endvar[1]-startvar[1]]=0;
|
|
|
|
obj->sub = malloc(sizeof(struct text_object));
|
|
|
|
extract_variable_text_internal(obj->sub, obj->data.combine.left, 0);
|
|
|
|
obj->sub->sub = malloc(sizeof(struct text_object));
|
|
|
|
extract_variable_text_internal(obj->sub->sub, obj->data.combine.right, 0);
|
|
|
|
} else {
|
|
|
|
CRIT_ERR("combine needs arguments: <text1> <text2>");
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
CRIT_ERR("combine needs arguments: <text1> <text2>");
|
|
|
|
}
|
2008-06-15 18:38:33 +00:00
|
|
|
#ifdef NVIDIA
|
2008-09-01 22:05:24 +00:00
|
|
|
END OBJ(nvidia, 0)
|
|
|
|
if (!arg) {
|
|
|
|
CRIT_ERR("nvidia needs an argument\n");
|
|
|
|
} else if (set_nvidia_type(&obj->data.nvidia, arg)) {
|
|
|
|
CRIT_ERR("nvidia: invalid argument"
|
|
|
|
" specified: '%s'\n", arg);
|
|
|
|
}
|
2008-06-03 20:46:15 +00:00
|
|
|
#endif /* NVIDIA */
|
2008-09-01 22:05:24 +00:00
|
|
|
END {
|
|
|
|
char buf[256];
|
2008-02-20 20:30:45 +00:00
|
|
|
|
2008-09-01 22:05:24 +00:00
|
|
|
ERR("unknown variable %s", s);
|
|
|
|
obj->type = OBJ_text;
|
|
|
|
snprintf(buf, 256, "${%s}", s);
|
|
|
|
obj->data.s = strndup(buf, text_buffer_size);
|
|
|
|
}
|
2005-07-20 00:30:40 +00:00
|
|
|
#undef OBJ
|
2005-12-10 14:15:38 +00:00
|
|
|
|
2008-09-01 22:05:24 +00:00
|
|
|
return obj;
|
2005-12-10 14:15:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static struct text_object *create_plain_text(const char *s)
|
|
|
|
{
|
2006-01-28 01:28:23 +00:00
|
|
|
struct text_object *obj;
|
2005-12-10 14:15:38 +00:00
|
|
|
|
2009-05-10 02:10:55 +00:00
|
|
|
char *esc = strstr(s, "\\#");
|
|
|
|
if (esc) {
|
|
|
|
/* remove extra '\' */
|
|
|
|
strcpy(esc, esc + 1);
|
|
|
|
}
|
|
|
|
|
2006-01-28 01:28:23 +00:00
|
|
|
if (s == NULL || *s == '\0') {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
obj = new_text_object_internal();
|
2005-12-10 14:15:38 +00:00
|
|
|
|
2006-01-28 01:28:23 +00:00
|
|
|
obj->type = OBJ_text;
|
2008-04-02 18:44:49 +00:00
|
|
|
obj->data.s = strndup(s, text_buffer_size);
|
2006-01-28 01:28:23 +00:00
|
|
|
return obj;
|
2005-07-20 00:30:40 +00:00
|
|
|
}
|
|
|
|
|
2008-11-29 13:02:42 +00:00
|
|
|
/* backslash_escape - do the actual substitution task for template objects
|
|
|
|
*
|
|
|
|
* The field templates is used for substituting the \N occurences. Set it to
|
|
|
|
* NULL to leave them as they are.
|
|
|
|
*/
|
|
|
|
static char *backslash_escape(const char *src, char **templates, unsigned int template_count)
|
|
|
|
{
|
|
|
|
char *src_dup;
|
|
|
|
const char *p;
|
2008-12-08 23:07:32 +00:00
|
|
|
unsigned int dup_idx = 0, dup_len;
|
2008-11-29 13:02:42 +00:00
|
|
|
|
2009-03-30 02:26:16 +00:00
|
|
|
dup_len = strlen(src) + 1;
|
2008-11-29 13:02:42 +00:00
|
|
|
src_dup = malloc(dup_len * sizeof(char));
|
2008-12-08 23:07:32 +00:00
|
|
|
|
2008-11-29 13:02:42 +00:00
|
|
|
p = src;
|
|
|
|
while (*p) {
|
|
|
|
switch (*p) {
|
|
|
|
case '\\':
|
|
|
|
if (!*(p + 1))
|
|
|
|
break;
|
|
|
|
if (*(p + 1) == '\\') {
|
|
|
|
src_dup[dup_idx++] = '\\';
|
|
|
|
p++;
|
|
|
|
} else if (*(p + 1) == ' ') {
|
|
|
|
src_dup[dup_idx++] = ' ';
|
|
|
|
p++;
|
|
|
|
} else if (*(p + 1) == 'n') {
|
|
|
|
src_dup[dup_idx++] = '\n';
|
|
|
|
p++;
|
|
|
|
} else if (templates) {
|
|
|
|
unsigned int tmpl_num;
|
|
|
|
int digits;
|
|
|
|
if ((sscanf(p + 1, "%u%n", &tmpl_num, &digits) <= 0) ||
|
|
|
|
(tmpl_num > template_count))
|
|
|
|
break;
|
2008-12-08 23:07:32 +00:00
|
|
|
dup_len += strlen(templates[tmpl_num - 1]);
|
|
|
|
src_dup = realloc(src_dup, dup_len * sizeof(char));
|
2008-11-29 13:02:42 +00:00
|
|
|
sprintf(src_dup + dup_idx, "%s", templates[tmpl_num - 1]);
|
|
|
|
dup_idx += strlen(templates[tmpl_num - 1]);
|
|
|
|
p += digits;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
src_dup[dup_idx++] = *p;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
p++;
|
|
|
|
}
|
|
|
|
src_dup[dup_idx] = '\0';
|
|
|
|
src_dup = realloc(src_dup, (strlen(src_dup) + 1) * sizeof(char));
|
|
|
|
return src_dup;
|
|
|
|
}
|
2008-11-29 01:34:54 +00:00
|
|
|
|
|
|
|
/* handle_template_object - core logic of the template object
|
|
|
|
*
|
|
|
|
* use config variables like this:
|
|
|
|
* template1 = "$\1\2"
|
|
|
|
* template2 = "\1: ${fs_bar 4,100 \2} ${fs_used \2} / ${fs_size \2}"
|
|
|
|
*
|
|
|
|
* and use them like this:
|
|
|
|
* ${template1 node name}
|
|
|
|
* ${template2 root /}
|
|
|
|
* ${template2 cdrom /mnt/cdrom}
|
|
|
|
*/
|
2008-12-08 23:07:32 +00:00
|
|
|
static char *handle_template(const char *tmpl, const char *args)
|
2008-11-29 01:34:54 +00:00
|
|
|
{
|
2008-12-08 23:07:32 +00:00
|
|
|
char *args_dup, *p, *p_old;
|
2008-11-29 01:34:54 +00:00
|
|
|
char **argsp = NULL;
|
2008-11-29 13:02:42 +00:00
|
|
|
unsigned int argcnt = 0, template_idx, i;
|
2008-11-29 01:34:54 +00:00
|
|
|
char *eval_text;
|
|
|
|
|
|
|
|
if ((sscanf(tmpl, "template%u", &template_idx) != 1) ||
|
|
|
|
(template_idx > 9))
|
2008-12-08 23:07:32 +00:00
|
|
|
return NULL;
|
2008-11-29 01:34:54 +00:00
|
|
|
|
|
|
|
args_dup = strdup(args);
|
|
|
|
p = args_dup;
|
|
|
|
while (*p) {
|
2008-11-29 13:02:42 +00:00
|
|
|
while (*p && (*p == ' ' && *(p - 1) != '\\'))
|
2008-11-29 01:34:54 +00:00
|
|
|
p++;
|
2008-11-29 13:02:42 +00:00
|
|
|
if (*(p - 1) == '\\')
|
|
|
|
p--;
|
2008-11-29 01:34:54 +00:00
|
|
|
p_old = p;
|
2008-11-29 13:02:42 +00:00
|
|
|
while (*p && (*p != ' ' || *(p - 1) == '\\'))
|
2008-11-29 01:34:54 +00:00
|
|
|
p++;
|
|
|
|
if (*p) {
|
|
|
|
(*p) = '\0';
|
|
|
|
p++;
|
|
|
|
}
|
|
|
|
argsp = realloc(argsp, ++argcnt * sizeof(char *));
|
|
|
|
argsp[argcnt - 1] = p_old;
|
|
|
|
}
|
2008-11-29 13:02:42 +00:00
|
|
|
for (i = 0; i < argcnt; i++) {
|
|
|
|
char *tmp;
|
|
|
|
tmp = backslash_escape(argsp[i], NULL, 0);
|
2008-12-07 18:47:57 +00:00
|
|
|
DBGP2("%s: substituted arg '%s' to '%s'", tmpl, argsp[i], tmp);
|
2008-12-08 23:07:32 +00:00
|
|
|
argsp[i] = tmp;
|
2008-11-29 13:02:42 +00:00
|
|
|
}
|
2008-11-29 01:34:54 +00:00
|
|
|
|
2008-11-29 13:02:42 +00:00
|
|
|
eval_text = backslash_escape(template[template_idx], argsp, argcnt);
|
2008-12-07 18:47:57 +00:00
|
|
|
DBGP("substituted %s, output is '%s'", tmpl, eval_text);
|
2008-11-29 01:34:54 +00:00
|
|
|
free(args_dup);
|
2008-12-08 23:07:32 +00:00
|
|
|
for (i = 0; i < argcnt; i++)
|
|
|
|
free(argsp[i]);
|
2008-11-29 01:34:54 +00:00
|
|
|
free(argsp);
|
2008-12-08 23:07:32 +00:00
|
|
|
return eval_text;
|
|
|
|
}
|
|
|
|
|
|
|
|
static char *find_and_replace_templates(const char *inbuf)
|
|
|
|
{
|
|
|
|
char *outbuf, *indup, *p, *o, *templ, *args, *tmpl_out;
|
|
|
|
int stack, outlen;
|
|
|
|
|
|
|
|
outlen = strlen(inbuf) + 1;
|
|
|
|
o = outbuf = calloc(outlen, sizeof(char));
|
|
|
|
memset(outbuf, 0, outlen * sizeof(char));
|
|
|
|
|
|
|
|
p = indup = strdup(inbuf);
|
|
|
|
while (*p) {
|
|
|
|
while (*p && *p != '$')
|
|
|
|
*(o++) = *(p++);
|
|
|
|
|
|
|
|
if (!(*p))
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (strncmp(p, "$template", 9) && strncmp(p, "${template", 10)) {
|
|
|
|
*(o++) = *(p++);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (*(p + 1) == '{') {
|
|
|
|
templ = p + 2;
|
|
|
|
while (*p != ' ')
|
|
|
|
p++;
|
|
|
|
*(p++) = '\0';
|
|
|
|
args = p;
|
|
|
|
stack = 1;
|
|
|
|
while (stack > 0) {
|
|
|
|
p++;
|
|
|
|
if (*p == '{')
|
|
|
|
stack++;
|
|
|
|
else if (*p == '}')
|
|
|
|
stack--;
|
|
|
|
}
|
|
|
|
*(p++) = '\0';
|
|
|
|
} else {
|
|
|
|
templ = p + 1;
|
|
|
|
while (*p != ' ')
|
|
|
|
p++;
|
|
|
|
*(p++) = '\0';
|
|
|
|
args = NULL;
|
|
|
|
}
|
|
|
|
tmpl_out = handle_template(templ, args);
|
|
|
|
if (tmpl_out) {
|
|
|
|
outlen += strlen(tmpl_out);
|
|
|
|
outbuf = realloc(outbuf, outlen * sizeof(char));
|
|
|
|
strcat (outbuf, tmpl_out);
|
|
|
|
free(tmpl_out);
|
|
|
|
o = outbuf + strlen(outbuf);
|
|
|
|
} else {
|
|
|
|
ERR("failed to handle template '%s' with args '%s'", templ, args);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*o = '\0';
|
|
|
|
outbuf = realloc(outbuf, (strlen(outbuf) + 1) * sizeof(char));
|
|
|
|
free(indup);
|
|
|
|
return outbuf;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int text_contains_templates(const char *text)
|
|
|
|
{
|
|
|
|
if (strcasestr(text, "${template") != NULL)
|
|
|
|
return 1;
|
|
|
|
if (strcasestr(text, "$template") != NULL)
|
|
|
|
return 1;
|
2008-11-29 01:34:54 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-12-15 01:44:21 +00:00
|
|
|
static int extract_variable_text_internal(struct text_object *retval, const char *const_p, char allow_threaded)
|
2005-12-10 14:15:38 +00:00
|
|
|
{
|
2006-01-28 01:28:23 +00:00
|
|
|
struct text_object *obj;
|
2008-03-29 04:41:37 +00:00
|
|
|
char *p, *s, *orig_p;
|
2008-03-29 06:24:04 +00:00
|
|
|
long line;
|
2008-12-22 16:45:08 +00:00
|
|
|
void *ifblock_opaque = NULL;
|
2009-03-16 00:34:40 +00:00
|
|
|
char *tmp_p;
|
|
|
|
char *arg = 0;
|
2008-03-29 03:45:36 +00:00
|
|
|
|
2008-12-08 23:07:32 +00:00
|
|
|
p = strndup(const_p, max_user_text - 1);
|
|
|
|
while (text_contains_templates(p)) {
|
|
|
|
char *tmp;
|
|
|
|
tmp = find_and_replace_templates(p);
|
|
|
|
free(p);
|
|
|
|
p = tmp;
|
|
|
|
}
|
2008-03-29 04:41:37 +00:00
|
|
|
s = orig_p = p;
|
2006-01-28 01:28:23 +00:00
|
|
|
|
2008-12-08 23:07:32 +00:00
|
|
|
if (strcmp(p, const_p)) {
|
|
|
|
DBGP("replaced all templates in text: input is\n'%s'\noutput is\n'%s'", const_p, p);
|
|
|
|
} else {
|
|
|
|
DBGP("no templates to replace");
|
|
|
|
}
|
|
|
|
|
2008-12-15 01:44:21 +00:00
|
|
|
memset(retval, 0, sizeof(struct text_object));
|
2006-01-28 01:28:23 +00:00
|
|
|
|
2008-06-21 09:24:56 +00:00
|
|
|
line = global_text_lines;
|
2006-05-14 07:05:05 +00:00
|
|
|
|
2005-07-20 00:30:40 +00:00
|
|
|
while (*p) {
|
2006-05-14 07:05:05 +00:00
|
|
|
if (*p == '\n') {
|
|
|
|
line++;
|
|
|
|
}
|
2009-05-10 02:10:55 +00:00
|
|
|
/* handle comments within the TEXT area */
|
|
|
|
if (*p == '#' && (p == orig_p || *(p - 1) != '\\')) {
|
|
|
|
while (*p && *p != '\n') p++;
|
|
|
|
s = p;
|
|
|
|
line++;
|
|
|
|
}
|
2005-07-20 00:30:40 +00:00
|
|
|
if (*p == '$') {
|
2008-03-29 03:45:36 +00:00
|
|
|
*p = '\0';
|
2005-12-10 14:15:38 +00:00
|
|
|
obj = create_plain_text(s);
|
2008-02-20 20:30:45 +00:00
|
|
|
if (obj != NULL) {
|
2008-12-15 01:44:21 +00:00
|
|
|
append_object(retval, obj);
|
2005-12-10 14:15:38 +00:00
|
|
|
}
|
2008-03-29 03:45:36 +00:00
|
|
|
*p = '$';
|
2005-07-20 00:30:40 +00:00
|
|
|
p++;
|
|
|
|
s = p;
|
|
|
|
|
|
|
|
if (*p != '$') {
|
|
|
|
char buf[256];
|
|
|
|
const char *var;
|
|
|
|
unsigned int len;
|
|
|
|
|
|
|
|
/* variable is either $foo or ${foo} */
|
|
|
|
if (*p == '{') {
|
2007-04-06 05:01:48 +00:00
|
|
|
unsigned int brl = 1, brr = 0;
|
2008-02-20 20:30:45 +00:00
|
|
|
|
2005-07-20 00:30:40 +00:00
|
|
|
p++;
|
|
|
|
s = p;
|
2007-04-06 05:01:48 +00:00
|
|
|
while (*p && brl != brr) {
|
2008-02-20 20:30:45 +00:00
|
|
|
if (*p == '{') {
|
|
|
|
brl++;
|
|
|
|
}
|
|
|
|
if (*p == '}') {
|
|
|
|
brr++;
|
|
|
|
}
|
2005-07-20 00:30:40 +00:00
|
|
|
p++;
|
2007-04-06 05:01:48 +00:00
|
|
|
}
|
|
|
|
p--;
|
2005-07-20 00:30:40 +00:00
|
|
|
} else {
|
|
|
|
s = p;
|
2008-02-20 20:30:45 +00:00
|
|
|
if (*p == '#') {
|
2005-07-20 00:30:40 +00:00
|
|
|
p++;
|
2008-02-20 20:30:45 +00:00
|
|
|
}
|
|
|
|
while (*p && (isalnum((int) *p) || *p == '_')) {
|
2005-07-20 00:30:40 +00:00
|
|
|
p++;
|
2008-02-20 20:30:45 +00:00
|
|
|
}
|
2005-07-20 00:30:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* copy variable to buffer */
|
|
|
|
len = (p - s > 255) ? 255 : (p - s);
|
|
|
|
strncpy(buf, s, len);
|
|
|
|
buf[len] = '\0';
|
|
|
|
|
2008-02-20 20:30:45 +00:00
|
|
|
if (*p == '}') {
|
2005-07-20 00:30:40 +00:00
|
|
|
p++;
|
2008-02-20 20:30:45 +00:00
|
|
|
}
|
2005-07-20 00:30:40 +00:00
|
|
|
s = p;
|
|
|
|
|
2009-04-26 20:38:03 +00:00
|
|
|
/* search for variable in environment */
|
2005-07-20 00:30:40 +00:00
|
|
|
|
2009-04-26 20:38:03 +00:00
|
|
|
var = getenv(buf);
|
2009-03-16 19:21:09 +00:00
|
|
|
if (var) {
|
2009-04-26 20:38:03 +00:00
|
|
|
obj = create_plain_text(var);
|
2009-04-28 16:54:43 +00:00
|
|
|
if (obj) {
|
2009-04-26 20:38:03 +00:00
|
|
|
append_object(retval, obj);
|
2009-04-28 16:54:43 +00:00
|
|
|
}
|
2009-04-26 20:38:03 +00:00
|
|
|
continue;
|
2009-03-16 19:21:09 +00:00
|
|
|
}
|
2009-04-26 20:38:03 +00:00
|
|
|
|
|
|
|
/* if variable wasn't found in environment, use some special */
|
2005-07-20 00:30:40 +00:00
|
|
|
|
2009-04-28 16:54:43 +00:00
|
|
|
arg = 0;
|
|
|
|
|
2009-03-16 19:21:09 +00:00
|
|
|
/* split arg */
|
|
|
|
if (strchr(buf, ' ')) {
|
|
|
|
arg = strchr(buf, ' ');
|
|
|
|
*arg = '\0';
|
|
|
|
arg++;
|
|
|
|
while (isspace((int) *arg)) {
|
2005-07-20 00:30:40 +00:00
|
|
|
arg++;
|
|
|
|
}
|
2009-03-16 19:21:09 +00:00
|
|
|
if (!*arg) {
|
|
|
|
arg = 0;
|
2009-03-11 00:37:24 +00:00
|
|
|
}
|
2009-03-16 19:21:09 +00:00
|
|
|
}
|
2009-03-07 14:12:09 +00:00
|
|
|
|
2009-03-16 19:21:09 +00:00
|
|
|
/* lowercase variable name */
|
|
|
|
tmp_p = buf;
|
|
|
|
while (*tmp_p) {
|
|
|
|
*tmp_p = tolower(*tmp_p);
|
|
|
|
tmp_p++;
|
|
|
|
}
|
|
|
|
|
|
|
|
obj = construct_text_object(buf, arg,
|
|
|
|
line, allow_threaded,
|
|
|
|
&ifblock_opaque);
|
|
|
|
if (obj != NULL) {
|
|
|
|
append_object(retval, obj);
|
2009-03-07 14:12:09 +00:00
|
|
|
}
|
2005-07-20 00:30:40 +00:00
|
|
|
continue;
|
2005-12-10 14:15:38 +00:00
|
|
|
} else {
|
2006-01-28 01:28:23 +00:00
|
|
|
obj = create_plain_text("$");
|
2009-03-23 23:29:07 +00:00
|
|
|
s = p + 1;
|
2008-02-20 20:30:45 +00:00
|
|
|
if (obj != NULL) {
|
2008-12-15 01:44:21 +00:00
|
|
|
append_object(retval, obj);
|
2006-01-28 01:28:23 +00:00
|
|
|
}
|
2005-12-10 14:15:38 +00:00
|
|
|
}
|
2005-07-20 00:30:40 +00:00
|
|
|
}
|
|
|
|
p++;
|
|
|
|
}
|
2005-12-10 14:15:38 +00:00
|
|
|
obj = create_plain_text(s);
|
2008-02-20 20:30:45 +00:00
|
|
|
if (obj != NULL) {
|
2008-12-15 01:44:21 +00:00
|
|
|
append_object(retval, obj);
|
2005-12-10 14:15:38 +00:00
|
|
|
}
|
|
|
|
|
2008-12-22 16:45:08 +00:00
|
|
|
if (!ifblock_stack_empty(&ifblock_opaque)) {
|
2005-07-28 04:48:27 +00:00
|
|
|
ERR("one or more $endif's are missing");
|
2005-08-06 04:46:16 +00:00
|
|
|
}
|
2005-07-20 00:30:40 +00:00
|
|
|
|
2008-03-29 04:41:37 +00:00
|
|
|
free(orig_p);
|
2008-12-15 01:44:21 +00:00
|
|
|
return 0;
|
2005-12-10 14:15:38 +00:00
|
|
|
}
|
2005-07-20 00:30:40 +00:00
|
|
|
|
2005-12-10 14:15:38 +00:00
|
|
|
static void extract_variable_text(const char *p)
|
2005-07-20 00:30:40 +00:00
|
|
|
{
|
2008-12-18 12:37:53 +00:00
|
|
|
free_text_objects(&global_root_object);
|
2008-03-20 20:33:31 +00:00
|
|
|
if (tmpstring1) {
|
|
|
|
free(tmpstring1);
|
|
|
|
tmpstring1 = 0;
|
|
|
|
}
|
|
|
|
if (tmpstring2) {
|
|
|
|
free(tmpstring2);
|
|
|
|
tmpstring2 = 0;
|
|
|
|
}
|
|
|
|
if (text_buffer) {
|
|
|
|
free(text_buffer);
|
|
|
|
text_buffer = 0;
|
|
|
|
}
|
2006-01-28 01:28:23 +00:00
|
|
|
|
2008-12-15 01:44:21 +00:00
|
|
|
extract_variable_text_internal(&global_root_object, p, 1);
|
2005-12-10 14:15:38 +00:00
|
|
|
}
|
2005-07-20 00:30:40 +00:00
|
|
|
|
2008-12-15 01:44:21 +00:00
|
|
|
int parse_conky_vars(struct text_object *root, char *txt, char *p, struct information *cur)
|
2008-02-20 20:30:45 +00:00
|
|
|
{
|
2008-12-15 01:44:21 +00:00
|
|
|
extract_variable_text_internal(root, txt, 0);
|
|
|
|
generate_text_internal(p, max_user_text, *root, cur);
|
|
|
|
return 0;
|
2005-12-10 21:07:24 +00:00
|
|
|
}
|
2005-07-20 00:30:40 +00:00
|
|
|
|
2008-06-21 09:25:16 +00:00
|
|
|
static inline struct mail_s *ensure_mail_thread(struct text_object *obj,
|
|
|
|
void *thread(void *), const char *text)
|
|
|
|
{
|
|
|
|
if (obj->global_mode && info.mail) {
|
|
|
|
// this means we use info
|
|
|
|
if (!info.mail->p_timed_thread) {
|
|
|
|
info.mail->p_timed_thread =
|
|
|
|
timed_thread_create(thread,
|
2008-06-28 20:14:04 +00:00
|
|
|
(void *) info.mail, info.mail->interval * 1000000);
|
2008-06-21 09:25:16 +00:00
|
|
|
if (!info.mail->p_timed_thread) {
|
|
|
|
ERR("Error creating %s timed thread", text);
|
|
|
|
}
|
|
|
|
timed_thread_register(info.mail->p_timed_thread,
|
2008-06-28 20:14:04 +00:00
|
|
|
&info.mail->p_timed_thread);
|
2008-06-21 09:25:16 +00:00
|
|
|
if (timed_thread_run(info.mail->p_timed_thread)) {
|
|
|
|
ERR("Error running %s timed thread", text);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return info.mail;
|
|
|
|
} else if (obj->data.mail) {
|
|
|
|
// this means we use obj
|
|
|
|
if (!obj->data.mail->p_timed_thread) {
|
|
|
|
obj->data.mail->p_timed_thread =
|
|
|
|
timed_thread_create(thread,
|
2008-06-28 20:14:04 +00:00
|
|
|
(void *) obj->data.mail,
|
|
|
|
obj->data.mail->interval * 1000000);
|
2008-06-21 09:25:16 +00:00
|
|
|
if (!obj->data.mail->p_timed_thread) {
|
|
|
|
ERR("Error creating %s timed thread", text);
|
|
|
|
}
|
|
|
|
timed_thread_register(obj->data.mail->p_timed_thread,
|
2008-06-28 20:14:04 +00:00
|
|
|
&obj->data.mail->p_timed_thread);
|
2008-06-21 09:25:16 +00:00
|
|
|
if (timed_thread_run(obj->data.mail->p_timed_thread)) {
|
|
|
|
ERR("Error running %s timed thread", text);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return obj->data.mail;
|
|
|
|
} else if (!obj->a) {
|
|
|
|
// something is wrong, warn once then stop
|
2009-04-28 16:19:28 +00:00
|
|
|
ERR("There's a problem with your mail settings. "
|
|
|
|
"Check that the global mail settings are properly defined"
|
2009-04-28 16:54:43 +00:00
|
|
|
" (line %li).", obj->line);
|
2008-06-21 09:25:16 +00:00
|
|
|
obj->a++;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2008-03-29 09:58:09 +00:00
|
|
|
char *format_time(unsigned long timeval, const int width)
|
2008-03-19 22:28:23 +00:00
|
|
|
{
|
|
|
|
char buf[10];
|
|
|
|
unsigned long nt; // narrow time, for speed on 32-bit
|
|
|
|
unsigned cc; // centiseconds
|
|
|
|
unsigned nn; // multi-purpose whatever
|
|
|
|
|
2008-03-29 09:58:09 +00:00
|
|
|
nt = timeval;
|
2008-03-19 22:28:23 +00:00
|
|
|
cc = nt % 100; // centiseconds past second
|
|
|
|
nt /= 100; // total seconds
|
|
|
|
nn = nt % 60; // seconds past the minute
|
|
|
|
nt /= 60; // total minutes
|
|
|
|
if (width >= snprintf(buf, sizeof buf, "%lu:%02u.%02u",
|
|
|
|
nt, nn, cc)) {
|
2008-04-02 18:44:49 +00:00
|
|
|
return strndup(buf, text_buffer_size);
|
2008-03-19 22:28:23 +00:00
|
|
|
}
|
|
|
|
if (width >= snprintf(buf, sizeof buf, "%lu:%02u", nt, nn)) {
|
2008-04-02 18:44:49 +00:00
|
|
|
return strndup(buf, text_buffer_size);
|
2008-03-19 22:28:23 +00:00
|
|
|
}
|
|
|
|
nn = nt % 60; // minutes past the hour
|
|
|
|
nt /= 60; // total hours
|
|
|
|
if (width >= snprintf(buf, sizeof buf, "%lu,%02u", nt, nn)) {
|
2008-04-02 18:44:49 +00:00
|
|
|
return strndup(buf, text_buffer_size);
|
2008-03-19 22:28:23 +00:00
|
|
|
}
|
|
|
|
nn = nt; // now also hours
|
|
|
|
if (width >= snprintf(buf, sizeof buf, "%uh", nn)) {
|
2008-04-02 18:44:49 +00:00
|
|
|
return strndup(buf, text_buffer_size);
|
2008-03-19 22:28:23 +00:00
|
|
|
}
|
|
|
|
nn /= 24; // now days
|
|
|
|
if (width >= snprintf(buf, sizeof buf, "%ud", nn)) {
|
2008-04-02 18:44:49 +00:00
|
|
|
return strndup(buf, text_buffer_size);
|
2008-03-19 22:28:23 +00:00
|
|
|
}
|
|
|
|
nn /= 7; // now weeks
|
|
|
|
if (width >= snprintf(buf, sizeof buf, "%uw", nn)) {
|
2008-04-02 18:44:49 +00:00
|
|
|
return strndup(buf, text_buffer_size);
|
2008-03-19 22:28:23 +00:00
|
|
|
}
|
|
|
|
// well shoot, this outta' fit...
|
2008-04-02 18:44:49 +00:00
|
|
|
return strndup("<inf>", text_buffer_size);
|
2008-03-19 22:28:23 +00:00
|
|
|
}
|
|
|
|
|
2008-06-04 08:51:15 +00:00
|
|
|
//remove backspaced chars, example: "dog^H^H^Hcat" becomes "cat"
|
|
|
|
//string has to end with \0 and it's length should fit in a int
|
|
|
|
#define BACKSPACE 8
|
|
|
|
void remove_deleted_chars(char *string){
|
|
|
|
int i = 0;
|
|
|
|
while(string[i] != 0){
|
|
|
|
if(string[i] == BACKSPACE){
|
|
|
|
if(i != 0){
|
|
|
|
strcpy( &(string[i-1]), &(string[i+1]) );
|
|
|
|
i--;
|
|
|
|
}else strcpy( &(string[i]), &(string[i+1]) ); //necessary for ^H's at the start of a string
|
|
|
|
}else i++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-06-19 19:56:30 +00:00
|
|
|
static inline void format_media_player_time(char *buf, const int size,
|
|
|
|
int seconds)
|
|
|
|
{
|
|
|
|
int days, hours, minutes;
|
|
|
|
|
|
|
|
days = seconds / (24 * 60 * 60);
|
|
|
|
seconds %= (24 * 60 * 60);
|
|
|
|
hours = seconds / (60 * 60);
|
|
|
|
seconds %= (60 * 60);
|
|
|
|
minutes = seconds / 60;
|
|
|
|
seconds %= 60;
|
|
|
|
|
|
|
|
if (days > 0) {
|
|
|
|
snprintf(buf, size, "%i days %i:%02i:%02i", days,
|
2008-06-28 20:14:04 +00:00
|
|
|
hours, minutes, seconds);
|
2008-06-19 19:56:30 +00:00
|
|
|
} else if (hours > 0) {
|
|
|
|
snprintf(buf, size, "%i:%02i:%02i", hours, minutes,
|
2008-06-28 20:14:04 +00:00
|
|
|
seconds);
|
2008-06-19 19:56:30 +00:00
|
|
|
} else {
|
|
|
|
snprintf(buf, size, "%i:%02i", minutes, seconds);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-06-21 09:25:29 +00:00
|
|
|
static inline double get_barnum(char *buf)
|
|
|
|
{
|
|
|
|
char *c = buf;
|
|
|
|
double barnum;
|
|
|
|
|
|
|
|
while (*c) {
|
|
|
|
if (*c == '\001') {
|
|
|
|
*c = ' ';
|
|
|
|
}
|
|
|
|
c++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sscanf(buf, "%lf", &barnum) == 0) {
|
2009-04-10 02:10:08 +00:00
|
|
|
ERR("reading exec value failed (perhaps it's not the "
|
2008-06-28 20:14:04 +00:00
|
|
|
"correct format?)");
|
2008-06-21 09:25:29 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (barnum > 100.0 || barnum < 0.0) {
|
2009-04-10 02:10:08 +00:00
|
|
|
ERR("your exec value is not between 0 and 100, "
|
2008-06-28 20:14:04 +00:00
|
|
|
"therefore it will be ignored");
|
2008-06-21 09:25:29 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return barnum;
|
|
|
|
}
|
|
|
|
|
2008-02-20 20:30:45 +00:00
|
|
|
static void generate_text_internal(char *p, int p_max_size,
|
2008-12-15 01:44:21 +00:00
|
|
|
struct text_object root, struct information *cur)
|
2005-12-10 14:15:38 +00:00
|
|
|
{
|
2008-12-15 01:44:21 +00:00
|
|
|
struct text_object *obj;
|
2006-05-13 19:51:26 +00:00
|
|
|
|
2009-02-08 17:13:54 +00:00
|
|
|
/* for the OBJ_top* handler */
|
|
|
|
struct process **needed = 0;
|
|
|
|
|
2006-05-13 20:14:26 +00:00
|
|
|
#ifdef HAVE_ICONV
|
2008-03-19 22:28:23 +00:00
|
|
|
char buff_in[p_max_size];
|
|
|
|
buff_in[0] = 0;
|
2006-05-13 19:51:26 +00:00
|
|
|
iconv_converting = 0;
|
|
|
|
#endif
|
|
|
|
|
2008-06-07 19:11:29 +00:00
|
|
|
p[0] = 0;
|
2008-12-15 01:44:21 +00:00
|
|
|
for (obj = root.next; obj && p_max_size > 0; obj = obj->next) {
|
2009-02-09 19:36:10 +00:00
|
|
|
needed = 0; // reset for top stuff
|
2005-07-20 00:30:40 +00:00
|
|
|
|
2008-12-15 01:44:21 +00:00
|
|
|
/* IFBLOCK jumping algorithm
|
|
|
|
*
|
|
|
|
* This is easier as it looks like:
|
|
|
|
* - each IF checks it's condition
|
|
|
|
* - on FALSE: call DO_JUMP
|
|
|
|
* - on TRUE: don't care
|
|
|
|
* - each ELSE calls DO_JUMP unconditionally
|
|
|
|
* - each ENDIF is silently being ignored
|
|
|
|
*
|
|
|
|
* Why this works:
|
|
|
|
* DO_JUMP overwrites the "obj" variable of the loop and sets it to the target
|
|
|
|
* (i.e. the corresponding ELSE or ENDIF). After that, processing for the given
|
|
|
|
* object can continue, free()ing stuff e.g., then the for-loop does the rest: as
|
|
|
|
* regularly, "obj" is being updated to point to obj->next, so object parsing
|
|
|
|
* continues right after the corresponding ELSE or ENDIF. This means that if we
|
|
|
|
* find an ELSE, it's corresponding IF must not have jumped, so we need to jump
|
|
|
|
* always. If we encounter an ENDIF, it's corresponding IF or ELSE has not
|
|
|
|
* jumped, and there is nothing to do.
|
|
|
|
*/
|
|
|
|
#define DO_JUMP { \
|
|
|
|
DBGP2("jumping"); \
|
|
|
|
obj = obj->data.ifblock.next; \
|
|
|
|
}
|
2008-03-20 20:56:13 +00:00
|
|
|
|
2005-07-20 00:30:40 +00:00
|
|
|
#define OBJ(a) break; case OBJ_##a:
|
|
|
|
|
|
|
|
switch (obj->type) {
|
2006-01-28 01:28:23 +00:00
|
|
|
default:
|
2008-02-20 20:30:45 +00:00
|
|
|
ERR("not implemented obj type %d", obj->type);
|
2007-08-10 21:14:06 +00:00
|
|
|
#ifndef __OpenBSD__
|
2008-09-01 23:08:09 +00:00
|
|
|
OBJ(acpitemp) {
|
2008-12-07 19:08:29 +00:00
|
|
|
temp_print(p, p_max_size, get_acpi_temperature(obj->data.i), TEMP_CELSIUS);
|
2008-09-01 23:08:09 +00:00
|
|
|
}
|
2007-08-10 21:14:06 +00:00
|
|
|
#endif /* !__OpenBSD__ */
|
2008-09-01 23:08:09 +00:00
|
|
|
OBJ(freq) {
|
|
|
|
if (obj->a) {
|
|
|
|
obj->a = get_freq(p, p_max_size, "%.0f", 1,
|
|
|
|
obj->data.cpu_index);
|
2006-01-28 01:28:23 +00:00
|
|
|
}
|
2008-09-01 23:08:09 +00:00
|
|
|
}
|
|
|
|
OBJ(freq_g) {
|
|
|
|
if (obj->a) {
|
2007-09-17 04:40:13 +00:00
|
|
|
#ifndef __OpenBSD__
|
2008-09-01 23:08:09 +00:00
|
|
|
obj->a = get_freq(p, p_max_size, "%'.2f", 1000,
|
|
|
|
obj->data.cpu_index);
|
2007-09-17 04:40:13 +00:00
|
|
|
#else
|
2008-09-01 23:08:09 +00:00
|
|
|
/* OpenBSD has no such flag (SUSv2) */
|
|
|
|
obj->a = get_freq(p, p_max_size, "%.2f", 1000,
|
|
|
|
obj->data.cpu_index);
|
2007-09-17 04:40:13 +00:00
|
|
|
#endif
|
2006-01-28 01:28:23 +00:00
|
|
|
}
|
2008-09-01 23:08:09 +00:00
|
|
|
}
|
2006-08-01 21:24:15 +00:00
|
|
|
#if defined(__linux__)
|
2008-09-01 23:08:09 +00:00
|
|
|
OBJ(voltage_mv) {
|
|
|
|
if (obj->a) {
|
|
|
|
obj->a = get_voltage(p, p_max_size, "%.0f", 1,
|
|
|
|
obj->data.cpu_index);
|
2006-05-24 00:23:47 +00:00
|
|
|
}
|
2008-09-01 23:08:09 +00:00
|
|
|
}
|
|
|
|
OBJ(voltage_v) {
|
|
|
|
if (obj->a) {
|
|
|
|
obj->a = get_voltage(p, p_max_size, "%'.3f", 1000,
|
|
|
|
obj->data.cpu_index);
|
2006-05-24 00:23:47 +00:00
|
|
|
}
|
2008-09-01 23:08:09 +00:00
|
|
|
}
|
2008-02-20 20:30:45 +00:00
|
|
|
|
2007-08-07 12:51:08 +00:00
|
|
|
#ifdef HAVE_IWLIB
|
2008-09-01 23:08:09 +00:00
|
|
|
OBJ(wireless_essid) {
|
|
|
|
snprintf(p, p_max_size, "%s", obj->data.net->essid);
|
|
|
|
}
|
|
|
|
OBJ(wireless_mode) {
|
|
|
|
snprintf(p, p_max_size, "%s", obj->data.net->mode);
|
|
|
|
}
|
|
|
|
OBJ(wireless_bitrate) {
|
|
|
|
snprintf(p, p_max_size, "%s", obj->data.net->bitrate);
|
|
|
|
}
|
|
|
|
OBJ(wireless_ap) {
|
|
|
|
snprintf(p, p_max_size, "%s", obj->data.net->ap);
|
|
|
|
}
|
|
|
|
OBJ(wireless_link_qual) {
|
2008-12-16 01:56:26 +00:00
|
|
|
spaced_print(p, p_max_size, "%d", 4,
|
2008-09-01 23:08:09 +00:00
|
|
|
obj->data.net->link_qual);
|
|
|
|
}
|
|
|
|
OBJ(wireless_link_qual_max) {
|
|
|
|
spaced_print(p, p_max_size, "%d", 4,
|
2008-12-16 01:56:26 +00:00
|
|
|
obj->data.net->link_qual_max);
|
2008-09-01 23:08:09 +00:00
|
|
|
}
|
|
|
|
OBJ(wireless_link_qual_perc) {
|
|
|
|
if (obj->data.net->link_qual_max > 0) {
|
|
|
|
spaced_print(p, p_max_size, "%.0f", 5,
|
|
|
|
(double) obj->data.net->link_qual /
|
|
|
|
obj->data.net->link_qual_max * 100);
|
|
|
|
} else {
|
2008-12-16 01:56:26 +00:00
|
|
|
spaced_print(p, p_max_size, "unk", 5);
|
2007-08-07 12:51:08 +00:00
|
|
|
}
|
2008-09-01 23:08:09 +00:00
|
|
|
}
|
|
|
|
OBJ(wireless_link_bar) {
|
|
|
|
new_bar(p, obj->a, obj->b, ((double) obj->data.net->link_qual /
|
|
|
|
obj->data.net->link_qual_max) * 255.0);
|
|
|
|
}
|
2007-08-07 12:51:08 +00:00
|
|
|
#endif /* HAVE_IWLIB */
|
|
|
|
|
2006-08-01 21:24:15 +00:00
|
|
|
#endif /* __linux__ */
|
2006-05-24 00:23:47 +00:00
|
|
|
|
2007-08-10 21:14:06 +00:00
|
|
|
#ifndef __OpenBSD__
|
2008-09-01 23:08:09 +00:00
|
|
|
OBJ(adt746xcpu) {
|
|
|
|
get_adt746x_cpu(p, p_max_size);
|
|
|
|
}
|
|
|
|
OBJ(adt746xfan) {
|
|
|
|
get_adt746x_fan(p, p_max_size);
|
|
|
|
}
|
|
|
|
OBJ(acpifan) {
|
|
|
|
get_acpi_fan(p, p_max_size);
|
|
|
|
}
|
|
|
|
OBJ(acpiacadapter) {
|
|
|
|
get_acpi_ac_adapter(p, p_max_size);
|
|
|
|
}
|
|
|
|
OBJ(battery) {
|
|
|
|
get_battery_stuff(p, p_max_size, obj->data.s, BATTERY_STATUS);
|
|
|
|
}
|
|
|
|
OBJ(battery_time) {
|
|
|
|
get_battery_stuff(p, p_max_size, obj->data.s, BATTERY_TIME);
|
|
|
|
}
|
|
|
|
OBJ(battery_percent) {
|
2009-03-01 19:53:47 +00:00
|
|
|
percent_print(p, p_max_size, get_battery_perct(obj->data.s));
|
2008-09-01 23:08:09 +00:00
|
|
|
}
|
|
|
|
OBJ(battery_bar) {
|
|
|
|
new_bar(p, obj->a, obj->b, get_battery_perct_bar(obj->data.s));
|
|
|
|
}
|
2009-02-18 04:49:45 +00:00
|
|
|
OBJ(battery_short) {
|
|
|
|
get_battery_short_status(p, p_max_size, obj->data.s);
|
|
|
|
}
|
2007-08-10 21:06:30 +00:00
|
|
|
#endif /* __OpenBSD__ */
|
2008-02-20 20:30:45 +00:00
|
|
|
|
2008-09-01 23:08:09 +00:00
|
|
|
OBJ(buffers) {
|
2008-12-16 01:56:26 +00:00
|
|
|
human_readable(cur->buffers * 1024, p, 255);
|
2008-09-01 23:08:09 +00:00
|
|
|
}
|
|
|
|
OBJ(cached) {
|
2008-12-16 01:56:26 +00:00
|
|
|
human_readable(cur->cached * 1024, p, 255);
|
2008-09-01 23:08:09 +00:00
|
|
|
}
|
|
|
|
OBJ(cpu) {
|
|
|
|
if (obj->data.cpu_index > info.cpu_count) {
|
2009-04-10 02:10:08 +00:00
|
|
|
ERR("obj->data.cpu_index %i info.cpu_count %i",
|
2008-09-01 23:08:09 +00:00
|
|
|
obj->data.cpu_index, info.cpu_count);
|
|
|
|
CRIT_ERR("attempting to use more CPUs than you have!");
|
2008-06-28 20:14:04 +00:00
|
|
|
}
|
2009-03-01 19:53:47 +00:00
|
|
|
percent_print(p, p_max_size,
|
|
|
|
round_to_int(cur->cpu_usage[obj->data.cpu_index] * 100.0));
|
2008-09-01 23:08:09 +00:00
|
|
|
}
|
2009-03-11 00:37:24 +00:00
|
|
|
OBJ(cpugauge)
|
|
|
|
new_gauge(p, obj->a, obj->b,
|
|
|
|
round_to_int(cur->cpu_usage[obj->data.cpu_index] * 255.0));
|
2008-09-01 23:08:09 +00:00
|
|
|
OBJ(cpubar) {
|
|
|
|
new_bar(p, obj->a, obj->b,
|
|
|
|
round_to_int(cur->cpu_usage[obj->data.cpu_index] * 255.0));
|
|
|
|
}
|
|
|
|
OBJ(cpugraph) {
|
|
|
|
new_graph(p, obj->a, obj->b, obj->c, obj->d, (unsigned int)
|
|
|
|
round_to_int(cur->cpu_usage[obj->data.cpu_index] * 100),
|
|
|
|
100, 1, obj->showaslog);
|
|
|
|
}
|
|
|
|
OBJ(loadgraph) {
|
|
|
|
new_graph(p, obj->a, obj->b, obj->c, obj->d, cur->loadavg[0],
|
|
|
|
obj->e, 1, obj->showaslog);
|
|
|
|
}
|
|
|
|
OBJ(color) {
|
|
|
|
new_fg(p, obj->data.l);
|
|
|
|
}
|
|
|
|
OBJ(color0) {
|
|
|
|
new_fg(p, color0);
|
|
|
|
}
|
|
|
|
OBJ(color1) {
|
|
|
|
new_fg(p, color1);
|
|
|
|
}
|
|
|
|
OBJ(color2) {
|
|
|
|
new_fg(p, color2);
|
|
|
|
}
|
|
|
|
OBJ(color3) {
|
|
|
|
new_fg(p, color3);
|
|
|
|
}
|
|
|
|
OBJ(color4) {
|
|
|
|
new_fg(p, color4);
|
|
|
|
}
|
|
|
|
OBJ(color5) {
|
|
|
|
new_fg(p, color5);
|
|
|
|
}
|
|
|
|
OBJ(color6) {
|
|
|
|
new_fg(p, color6);
|
|
|
|
}
|
|
|
|
OBJ(color7) {
|
|
|
|
new_fg(p, color7);
|
|
|
|
}
|
|
|
|
OBJ(color8) {
|
|
|
|
new_fg(p, color8);
|
|
|
|
}
|
|
|
|
OBJ(color9) {
|
|
|
|
new_fg(p, color9);
|
|
|
|
}
|
|
|
|
OBJ(conky_version) {
|
|
|
|
snprintf(p, p_max_size, "%s", VERSION);
|
|
|
|
}
|
|
|
|
OBJ(conky_build_date) {
|
|
|
|
snprintf(p, p_max_size, "%s", BUILD_DATE);
|
|
|
|
}
|
|
|
|
OBJ(conky_build_arch) {
|
|
|
|
snprintf(p, p_max_size, "%s", BUILD_ARCH);
|
|
|
|
}
|
2005-08-27 12:59:46 +00:00
|
|
|
#if defined(__linux__)
|
2008-09-01 23:08:09 +00:00
|
|
|
OBJ(disk_protect) {
|
|
|
|
snprintf(p, p_max_size, "%s",
|
|
|
|
get_disk_protect_queue(obj->data.s));
|
|
|
|
}
|
|
|
|
OBJ(i8k_version) {
|
|
|
|
snprintf(p, p_max_size, "%s", i8k.version);
|
|
|
|
}
|
|
|
|
OBJ(i8k_bios) {
|
|
|
|
snprintf(p, p_max_size, "%s", i8k.bios);
|
|
|
|
}
|
|
|
|
OBJ(i8k_serial) {
|
|
|
|
snprintf(p, p_max_size, "%s", i8k.serial);
|
|
|
|
}
|
|
|
|
OBJ(i8k_cpu_temp) {
|
|
|
|
int cpu_temp;
|
2008-06-28 20:14:04 +00:00
|
|
|
|
2008-09-01 23:08:09 +00:00
|
|
|
sscanf(i8k.cpu_temp, "%d", &cpu_temp);
|
2008-12-07 19:08:29 +00:00
|
|
|
temp_print(p, p_max_size, (double)cpu_temp, TEMP_CELSIUS);
|
2008-09-01 23:08:09 +00:00
|
|
|
}
|
|
|
|
OBJ(i8k_left_fan_status) {
|
|
|
|
int left_fan_status;
|
2005-08-27 07:15:44 +00:00
|
|
|
|
2008-09-01 23:08:09 +00:00
|
|
|
sscanf(i8k.left_fan_status, "%d", &left_fan_status);
|
|
|
|
if (left_fan_status == 0) {
|
|
|
|
snprintf(p, p_max_size, "off");
|
2005-08-27 07:15:44 +00:00
|
|
|
}
|
2008-09-01 23:08:09 +00:00
|
|
|
if (left_fan_status == 1) {
|
|
|
|
snprintf(p, p_max_size, "low");
|
2005-08-27 07:15:44 +00:00
|
|
|
}
|
2008-09-01 23:08:09 +00:00
|
|
|
if (left_fan_status == 2) {
|
|
|
|
snprintf(p, p_max_size, "high");
|
2006-01-28 01:28:23 +00:00
|
|
|
}
|
2008-09-01 23:08:09 +00:00
|
|
|
}
|
|
|
|
OBJ(i8k_right_fan_status) {
|
|
|
|
int right_fan_status;
|
2005-08-27 07:15:44 +00:00
|
|
|
|
2008-09-01 23:08:09 +00:00
|
|
|
sscanf(i8k.right_fan_status, "%d", &right_fan_status);
|
|
|
|
if (right_fan_status == 0) {
|
|
|
|
snprintf(p, p_max_size, "off");
|
2007-03-01 01:43:43 +00:00
|
|
|
}
|
2008-09-01 23:08:09 +00:00
|
|
|
if (right_fan_status == 1) {
|
|
|
|
snprintf(p, p_max_size, "low");
|
2007-03-01 01:43:43 +00:00
|
|
|
}
|
2008-09-01 23:08:09 +00:00
|
|
|
if (right_fan_status == 2) {
|
|
|
|
snprintf(p, p_max_size, "high");
|
2007-03-01 01:43:43 +00:00
|
|
|
}
|
2008-09-01 23:08:09 +00:00
|
|
|
}
|
|
|
|
OBJ(i8k_left_fan_rpm) {
|
|
|
|
snprintf(p, p_max_size, "%s", i8k.left_fan_rpm);
|
|
|
|
}
|
|
|
|
OBJ(i8k_right_fan_rpm) {
|
|
|
|
snprintf(p, p_max_size, "%s", i8k.right_fan_rpm);
|
|
|
|
}
|
|
|
|
OBJ(i8k_ac_status) {
|
|
|
|
int ac_status;
|
|
|
|
|
|
|
|
sscanf(i8k.ac_status, "%d", &ac_status);
|
|
|
|
if (ac_status == -1) {
|
|
|
|
snprintf(p, p_max_size, "disabled (read i8k docs)");
|
2008-06-28 20:14:04 +00:00
|
|
|
}
|
2008-09-01 23:08:09 +00:00
|
|
|
if (ac_status == 0) {
|
|
|
|
snprintf(p, p_max_size, "off");
|
2008-06-28 20:14:04 +00:00
|
|
|
}
|
2008-09-01 23:08:09 +00:00
|
|
|
if (ac_status == 1) {
|
|
|
|
snprintf(p, p_max_size, "on");
|
2008-06-28 20:14:04 +00:00
|
|
|
}
|
2008-09-01 23:08:09 +00:00
|
|
|
}
|
|
|
|
OBJ(i8k_buttons_status) {
|
|
|
|
snprintf(p, p_max_size, "%s", i8k.buttons_status);
|
|
|
|
}
|
2009-01-03 23:00:52 +00:00
|
|
|
#if defined(IBM)
|
2008-09-01 23:08:09 +00:00
|
|
|
OBJ(ibm_fan) {
|
|
|
|
get_ibm_acpi_fan(p, p_max_size);
|
|
|
|
}
|
|
|
|
OBJ(ibm_temps) {
|
|
|
|
get_ibm_acpi_temps();
|
2008-12-07 19:08:29 +00:00
|
|
|
temp_print(p, p_max_size,
|
|
|
|
ibm_acpi.temps[obj->data.sensor], TEMP_CELSIUS);
|
2008-09-01 23:08:09 +00:00
|
|
|
}
|
|
|
|
OBJ(ibm_volume) {
|
|
|
|
get_ibm_acpi_volume(p, p_max_size);
|
|
|
|
}
|
|
|
|
OBJ(ibm_brightness) {
|
|
|
|
get_ibm_acpi_brightness(p, p_max_size);
|
|
|
|
}
|
2009-01-03 23:00:52 +00:00
|
|
|
#endif /* IBM */
|
2009-05-04 19:13:51 +00:00
|
|
|
/* information from sony_laptop kernel module
|
|
|
|
* /sys/devices/platform/sony-laptop */
|
|
|
|
OBJ(sony_fanspeed) {
|
|
|
|
get_sony_fanspeed(p, p_max_size);
|
|
|
|
}
|
2008-09-01 23:08:09 +00:00
|
|
|
OBJ(if_gw) {
|
|
|
|
if (!cur->gw_info.count) {
|
2008-12-15 01:44:21 +00:00
|
|
|
DO_JUMP;
|
2008-03-22 19:06:09 +00:00
|
|
|
}
|
2008-09-01 23:08:09 +00:00
|
|
|
}
|
|
|
|
OBJ(gw_iface) {
|
|
|
|
snprintf(p, p_max_size, "%s", cur->gw_info.iface);
|
|
|
|
}
|
|
|
|
OBJ(gw_ip) {
|
|
|
|
snprintf(p, p_max_size, "%s", cur->gw_info.ip);
|
|
|
|
}
|
|
|
|
OBJ(laptop_mode) {
|
|
|
|
snprintf(p, p_max_size, "%d", get_laptop_mode());
|
|
|
|
}
|
|
|
|
OBJ(pb_battery) {
|
|
|
|
get_powerbook_batt_info(p, p_max_size, obj->data.i);
|
|
|
|
}
|
2008-02-20 20:30:45 +00:00
|
|
|
#endif /* __linux__ */
|
2009-03-28 23:15:20 +00:00
|
|
|
#if (defined(__FreeBSD__) || defined(__linux__))
|
|
|
|
OBJ(if_up) {
|
|
|
|
if ((obj->data.ifblock.s)
|
|
|
|
&& (!interface_up(obj->data.ifblock.s))) {
|
|
|
|
DO_JUMP;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2008-02-20 20:30:45 +00:00
|
|
|
#ifdef __OpenBSD__
|
2008-09-01 23:08:09 +00:00
|
|
|
OBJ(obsd_sensors_temp) {
|
|
|
|
obsd_sensors.device = sensor_device;
|
|
|
|
update_obsd_sensors();
|
2008-12-07 19:08:29 +00:00
|
|
|
temp_print(p, p_max_size,
|
|
|
|
obsd_sensors.temp[obsd_sensors.device][obj->data.sensor],
|
|
|
|
TEMP_CELSIUS);
|
2008-09-01 23:08:09 +00:00
|
|
|
}
|
|
|
|
OBJ(obsd_sensors_fan) {
|
|
|
|
obsd_sensors.device = sensor_device;
|
|
|
|
update_obsd_sensors();
|
|
|
|
snprintf(p, p_max_size, "%d",
|
|
|
|
obsd_sensors.fan[obsd_sensors.device][obj->data.sensor]);
|
|
|
|
}
|
|
|
|
OBJ(obsd_sensors_volt) {
|
|
|
|
obsd_sensors.device = sensor_device;
|
|
|
|
update_obsd_sensors();
|
|
|
|
snprintf(p, p_max_size, "%.2f",
|
|
|
|
obsd_sensors.volt[obsd_sensors.device][obj->data.sensor]);
|
|
|
|
}
|
|
|
|
OBJ(obsd_vendor) {
|
|
|
|
get_obsd_vendor(p, p_max_size);
|
|
|
|
}
|
|
|
|
OBJ(obsd_product) {
|
|
|
|
get_obsd_product(p, p_max_size);
|
|
|
|
}
|
2007-03-01 01:43:43 +00:00
|
|
|
#endif /* __OpenBSD__ */
|
|
|
|
|
2008-09-01 23:08:09 +00:00
|
|
|
OBJ(font) {
|
|
|
|
new_font(p, obj->data.s);
|
|
|
|
}
|
|
|
|
/* TODO: move this correction from kB to kB/s elsewhere
|
|
|
|
* (or get rid of it??) */
|
|
|
|
OBJ(diskio) {
|
2008-12-16 01:32:30 +00:00
|
|
|
human_readable((obj->data.diskio->current / update_interval) * 1024LL,
|
2008-12-16 01:56:26 +00:00
|
|
|
p, p_max_size);
|
2008-09-01 23:08:09 +00:00
|
|
|
}
|
|
|
|
OBJ(diskio_write) {
|
2009-02-23 22:28:12 +00:00
|
|
|
human_readable((obj->data.diskio->current_write / update_interval) * 1024LL,
|
2008-12-16 01:56:26 +00:00
|
|
|
p, p_max_size);
|
2008-09-01 23:08:09 +00:00
|
|
|
}
|
|
|
|
OBJ(diskio_read) {
|
2009-02-23 22:28:12 +00:00
|
|
|
human_readable((obj->data.diskio->current_read / update_interval) * 1024LL,
|
2008-12-16 01:56:26 +00:00
|
|
|
p, p_max_size);
|
2008-09-01 23:08:09 +00:00
|
|
|
}
|
|
|
|
OBJ(diskiograph) {
|
2008-12-16 01:32:30 +00:00
|
|
|
new_graph(p, obj->a, obj->b, obj->c, obj->d,
|
|
|
|
obj->data.diskio->current, obj->e, 1, obj->showaslog);
|
2008-09-01 23:08:09 +00:00
|
|
|
}
|
|
|
|
OBJ(diskiograph_read) {
|
2008-12-16 01:32:30 +00:00
|
|
|
new_graph(p, obj->a, obj->b, obj->c, obj->d,
|
|
|
|
obj->data.diskio->current_read, obj->e, 1, obj->showaslog);
|
2008-09-01 23:08:09 +00:00
|
|
|
}
|
|
|
|
OBJ(diskiograph_write) {
|
2008-12-16 01:32:30 +00:00
|
|
|
new_graph(p, obj->a, obj->b, obj->c, obj->d,
|
|
|
|
obj->data.diskio->current_write, obj->e, 1, obj->showaslog);
|
2008-09-01 23:08:09 +00:00
|
|
|
}
|
|
|
|
OBJ(downspeed) {
|
2009-02-18 05:00:23 +00:00
|
|
|
human_readable(obj->data.net->recv_speed, p, 255);
|
2008-09-01 23:08:09 +00:00
|
|
|
}
|
|
|
|
OBJ(downspeedf) {
|
2008-12-16 01:56:26 +00:00
|
|
|
spaced_print(p, p_max_size, "%.1f", 8,
|
2008-09-01 23:08:09 +00:00
|
|
|
obj->data.net->recv_speed / 1024.0);
|
|
|
|
}
|
|
|
|
OBJ(downspeedgraph) {
|
|
|
|
new_graph(p, obj->a, obj->b, obj->c, obj->d,
|
|
|
|
obj->data.net->recv_speed / 1024.0, obj->e, 1, obj->showaslog);
|
2008-02-20 20:30:45 +00:00
|
|
|
}
|
|
|
|
OBJ(else) {
|
2008-12-15 01:44:21 +00:00
|
|
|
/* Since we see you, you're if has not jumped.
|
|
|
|
* Do Ninja jump here: without leaving traces.
|
|
|
|
* This is to prevent us from stale jumped flags.
|
|
|
|
*/
|
|
|
|
obj = obj->data.ifblock.next;
|
|
|
|
continue;
|
2008-02-20 20:30:45 +00:00
|
|
|
}
|
|
|
|
OBJ(endif) {
|
2008-12-15 01:44:21 +00:00
|
|
|
/* harmless object, just ignore */
|
2008-02-20 20:30:45 +00:00
|
|
|
}
|
2005-07-20 00:30:40 +00:00
|
|
|
#ifdef HAVE_POPEN
|
2008-02-20 20:30:45 +00:00
|
|
|
OBJ(addr) {
|
2008-06-19 19:54:31 +00:00
|
|
|
if ((obj->data.net->addr.sa_data[2] & 255) == 0
|
|
|
|
&& (obj->data.net->addr.sa_data[3] & 255) == 0
|
|
|
|
&& (obj->data.net->addr.sa_data[4] & 255) == 0
|
|
|
|
&& (obj->data.net->addr.sa_data[5] & 255) == 0) {
|
|
|
|
snprintf(p, p_max_size, "No Address");
|
|
|
|
} else {
|
|
|
|
snprintf(p, p_max_size, "%u.%u.%u.%u",
|
|
|
|
obj->data.net->addr.sa_data[2] & 255,
|
|
|
|
obj->data.net->addr.sa_data[3] & 255,
|
|
|
|
obj->data.net->addr.sa_data[4] & 255,
|
|
|
|
obj->data.net->addr.sa_data[5] & 255);
|
|
|
|
}
|
2008-02-20 20:30:45 +00:00
|
|
|
}
|
2008-03-18 00:23:16 +00:00
|
|
|
#if defined(__linux__)
|
2008-05-06 21:44:23 +00:00
|
|
|
OBJ(addrs) {
|
|
|
|
if(NULL != obj->data.net->addrs && strlen(obj->data.net->addrs) > 2)
|
|
|
|
{
|
|
|
|
obj->data.net->addrs[strlen(obj->data.net->addrs) - 2] = 0; /* remove ", " from end of string */
|
|
|
|
strcpy(p, obj->data.net->addrs);
|
|
|
|
}
|
|
|
|
else
|
2008-03-18 00:23:16 +00:00
|
|
|
strcpy(p, "0.0.0.0");
|
|
|
|
}
|
|
|
|
#endif /* __linux__ */
|
|
|
|
|
2006-05-25 07:00:12 +00:00
|
|
|
#if defined(IMLIB2) && defined(X11)
|
2008-02-20 20:30:45 +00:00
|
|
|
OBJ(image) {
|
|
|
|
if (obj->a < 1) {
|
|
|
|
obj->a++;
|
|
|
|
} else {
|
|
|
|
Imlib_Image image, buffer;
|
|
|
|
|
|
|
|
image = imlib_load_image(obj->data.s);
|
|
|
|
imlib_context_set_image(image);
|
|
|
|
if (image) {
|
|
|
|
int w, h;
|
|
|
|
|
|
|
|
w = imlib_image_get_width();
|
|
|
|
h = imlib_image_get_height();
|
|
|
|
buffer = imlib_create_image(w, h);
|
|
|
|
imlib_context_set_display(display);
|
|
|
|
imlib_context_set_drawable(window.drawable);
|
|
|
|
imlib_context_set_colormap(DefaultColormap(display,
|
|
|
|
screen));
|
|
|
|
imlib_context_set_visual(DefaultVisual(display,
|
|
|
|
screen));
|
|
|
|
imlib_context_set_image(buffer);
|
|
|
|
imlib_blend_image_onto_image(image, 0, 0, 0, w, h,
|
|
|
|
text_start_x, text_start_y, w, h);
|
|
|
|
imlib_render_image_on_drawable(text_start_x,
|
|
|
|
text_start_y);
|
|
|
|
imlib_free_image();
|
2006-05-25 07:00:12 +00:00
|
|
|
imlib_context_set_image(image);
|
2008-02-20 20:30:45 +00:00
|
|
|
imlib_free_image();
|
2006-05-25 07:00:12 +00:00
|
|
|
}
|
|
|
|
}
|
2008-02-20 20:30:45 +00:00
|
|
|
}
|
2006-05-25 07:00:12 +00:00
|
|
|
#endif /* IMLIB2 */
|
2008-02-20 20:30:45 +00:00
|
|
|
|
2009-03-23 23:27:51 +00:00
|
|
|
OBJ(eval) {
|
|
|
|
struct information *tmp_info;
|
|
|
|
struct text_object subroot, subroot2;
|
|
|
|
|
|
|
|
tmp_info = malloc(sizeof(struct information));
|
|
|
|
memcpy(tmp_info, cur, sizeof(struct information));
|
|
|
|
parse_conky_vars(&subroot, obj->data.s, p, tmp_info);
|
|
|
|
DBGP("evaluated '%s' to '%s'", obj->data.s, p);
|
|
|
|
parse_conky_vars(&subroot2, p, p, tmp_info);
|
|
|
|
|
|
|
|
free_text_objects(&subroot);
|
|
|
|
free_text_objects(&subroot2);
|
|
|
|
free(tmp_info);
|
|
|
|
}
|
2008-02-20 20:30:45 +00:00
|
|
|
OBJ(exec) {
|
2008-12-07 07:31:53 +00:00
|
|
|
read_exec(obj->data.s, p, text_buffer_size);
|
2008-06-04 08:51:15 +00:00
|
|
|
remove_deleted_chars(p);
|
2008-03-20 20:33:31 +00:00
|
|
|
}
|
|
|
|
OBJ(execp) {
|
2008-06-21 09:25:03 +00:00
|
|
|
struct information *tmp_info;
|
2008-12-15 01:44:21 +00:00
|
|
|
struct text_object subroot;
|
2008-03-20 20:33:31 +00:00
|
|
|
|
2008-12-07 07:31:53 +00:00
|
|
|
read_exec(obj->data.s, p, text_buffer_size);
|
2008-03-22 22:58:26 +00:00
|
|
|
|
2008-06-21 09:25:03 +00:00
|
|
|
tmp_info = malloc(sizeof(struct information));
|
|
|
|
memcpy(tmp_info, cur, sizeof(struct information));
|
2008-12-15 01:44:21 +00:00
|
|
|
parse_conky_vars(&subroot, p, p, tmp_info);
|
2008-03-20 20:33:31 +00:00
|
|
|
|
2008-12-18 12:37:53 +00:00
|
|
|
free_text_objects(&subroot);
|
2008-06-21 09:25:03 +00:00
|
|
|
free(tmp_info);
|
2008-02-20 20:30:45 +00:00
|
|
|
}
|
2009-03-11 00:37:24 +00:00
|
|
|
OBJ(execgauge) {
|
|
|
|
double barnum;
|
|
|
|
|
|
|
|
read_exec(obj->data.s, p, text_buffer_size);
|
|
|
|
barnum = get_barnum(p); /*using the same function*/
|
|
|
|
|
|
|
|
if (barnum >= 0.0) {
|
|
|
|
barnum /= 100;
|
2009-04-10 02:10:08 +00:00
|
|
|
new_gauge(p, obj->a, obj->b, round_to_int(barnum * 255.0));
|
2009-03-11 00:37:24 +00:00
|
|
|
}
|
|
|
|
}
|
2008-02-20 20:30:45 +00:00
|
|
|
OBJ(execbar) {
|
2008-03-29 06:24:04 +00:00
|
|
|
double barnum;
|
2008-02-20 20:30:45 +00:00
|
|
|
|
2008-12-07 07:31:53 +00:00
|
|
|
read_exec(obj->data.s, p, text_buffer_size);
|
2008-06-21 09:25:29 +00:00
|
|
|
barnum = get_barnum(p);
|
2008-02-20 20:30:45 +00:00
|
|
|
|
2008-06-21 09:25:29 +00:00
|
|
|
if (barnum >= 0.0) {
|
2008-12-07 22:49:04 +00:00
|
|
|
barnum /= 100;
|
2009-04-10 02:10:08 +00:00
|
|
|
new_bar(p, obj->a, obj->b, round_to_int(barnum * 255.0));
|
2008-02-20 20:30:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
OBJ(execgraph) {
|
2008-06-21 20:37:58 +00:00
|
|
|
char showaslog = FALSE;
|
2008-03-29 06:24:04 +00:00
|
|
|
double barnum;
|
2008-02-20 20:30:45 +00:00
|
|
|
|
2008-06-21 20:37:58 +00:00
|
|
|
if(strncasecmp(obj->data.s, LOGGRAPH" ", strlen(LOGGRAPH" ")) == EQUAL) {
|
|
|
|
showaslog = TRUE;
|
2008-12-07 07:31:53 +00:00
|
|
|
read_exec(obj->data.s + strlen(LOGGRAPH" ") * sizeof(char), p, text_buffer_size);
|
2008-06-21 20:37:58 +00:00
|
|
|
} else if(strncasecmp(obj->data.s, NORMGRAPH" ", strlen(NORMGRAPH" ")) == EQUAL) {
|
2008-12-07 07:31:53 +00:00
|
|
|
read_exec(obj->data.s + strlen(NORMGRAPH" ") * sizeof(char), p, text_buffer_size);
|
2008-06-21 20:37:58 +00:00
|
|
|
} else {
|
2008-12-07 07:31:53 +00:00
|
|
|
read_exec(obj->data.s, p, text_buffer_size);
|
2008-06-21 20:37:58 +00:00
|
|
|
}
|
2008-06-21 09:25:29 +00:00
|
|
|
barnum = get_barnum(p);
|
2005-07-28 06:56:55 +00:00
|
|
|
|
2008-06-21 09:25:29 +00:00
|
|
|
if (barnum >= 0.0) {
|
2009-04-10 02:10:08 +00:00
|
|
|
new_graph(p, obj->a, obj->b, obj->c, obj->d, round_to_int(barnum),
|
2008-06-21 20:37:58 +00:00
|
|
|
100, 1, showaslog);
|
2005-07-28 06:56:55 +00:00
|
|
|
}
|
2008-02-20 20:30:45 +00:00
|
|
|
}
|
|
|
|
OBJ(execibar) {
|
|
|
|
if (current_update_time - obj->data.execi.last_update
|
2008-06-21 09:25:37 +00:00
|
|
|
>= obj->data.execi.interval) {
|
2008-06-21 09:25:29 +00:00
|
|
|
double barnum;
|
2006-01-28 01:28:23 +00:00
|
|
|
|
2008-12-07 07:31:53 +00:00
|
|
|
read_exec(obj->data.execi.cmd, p, text_buffer_size);
|
2008-06-21 09:25:29 +00:00
|
|
|
barnum = get_barnum(p);
|
2008-02-20 20:30:45 +00:00
|
|
|
|
2008-06-21 09:25:29 +00:00
|
|
|
if (barnum >= 0.0) {
|
2008-02-20 20:30:45 +00:00
|
|
|
obj->f = 255 * barnum / 100.0;
|
2005-08-23 03:00:50 +00:00
|
|
|
}
|
2008-02-20 20:30:45 +00:00
|
|
|
obj->data.execi.last_update = current_update_time;
|
2005-08-23 03:00:50 +00:00
|
|
|
}
|
2009-04-10 02:10:08 +00:00
|
|
|
new_bar(p, obj->a, obj->b, round_to_int(obj->f));
|
2008-02-20 20:30:45 +00:00
|
|
|
}
|
|
|
|
OBJ(execigraph) {
|
|
|
|
if (current_update_time - obj->data.execi.last_update
|
2008-06-21 09:25:37 +00:00
|
|
|
>= obj->data.execi.interval) {
|
2008-06-21 09:25:29 +00:00
|
|
|
double barnum;
|
2006-01-28 01:28:23 +00:00
|
|
|
|
2008-12-07 07:31:53 +00:00
|
|
|
read_exec(obj->data.execi.cmd, p, text_buffer_size);
|
2008-06-21 09:25:29 +00:00
|
|
|
barnum = get_barnum(p);
|
2008-02-20 20:30:45 +00:00
|
|
|
|
2008-06-21 09:25:29 +00:00
|
|
|
if (barnum >= 0.0) {
|
2008-02-20 20:30:45 +00:00
|
|
|
obj->f = barnum;
|
2006-01-28 01:28:23 +00:00
|
|
|
}
|
2008-02-20 20:30:45 +00:00
|
|
|
obj->data.execi.last_update = current_update_time;
|
|
|
|
}
|
2009-04-10 02:10:08 +00:00
|
|
|
new_graph(p, obj->a, obj->b, obj->c, obj->d, (int) (obj->f), 100, 1, FALSE);
|
|
|
|
}
|
|
|
|
OBJ(execigauge) {
|
|
|
|
if (current_update_time - obj->data.execi.last_update
|
|
|
|
>= obj->data.execi.interval) {
|
|
|
|
double barnum;
|
|
|
|
|
|
|
|
read_exec(obj->data.execi.cmd, p, text_buffer_size);
|
|
|
|
barnum = get_barnum(p);
|
|
|
|
|
|
|
|
if (barnum >= 0.0) {
|
|
|
|
obj->f = 255 * barnum / 100.0;
|
|
|
|
}
|
|
|
|
obj->data.execi.last_update = current_update_time;
|
|
|
|
}
|
|
|
|
new_gauge(p, obj->a, obj->b, round_to_int(obj->f));
|
2008-02-20 20:30:45 +00:00
|
|
|
}
|
|
|
|
OBJ(execi) {
|
|
|
|
if (current_update_time - obj->data.execi.last_update
|
2008-06-21 09:25:37 +00:00
|
|
|
>= obj->data.execi.interval
|
|
|
|
&& obj->data.execi.interval != 0) {
|
2008-06-21 09:25:22 +00:00
|
|
|
read_exec(obj->data.execi.cmd, obj->data.execi.buffer,
|
2008-12-07 07:31:53 +00:00
|
|
|
text_buffer_size);
|
2008-02-20 20:30:45 +00:00
|
|
|
obj->data.execi.last_update = current_update_time;
|
|
|
|
}
|
2008-12-07 07:31:53 +00:00
|
|
|
snprintf(p, text_buffer_size, "%s", obj->data.execi.buffer);
|
2008-02-20 20:30:45 +00:00
|
|
|
}
|
2008-03-22 06:10:54 +00:00
|
|
|
OBJ(execpi) {
|
2008-12-15 01:44:21 +00:00
|
|
|
struct text_object subroot;
|
2008-06-21 09:25:03 +00:00
|
|
|
struct information *tmp_info =
|
2008-03-22 06:10:54 +00:00
|
|
|
malloc(sizeof(struct information));
|
2008-06-21 09:25:03 +00:00
|
|
|
memcpy(tmp_info, cur, sizeof(struct information));
|
2008-03-22 06:10:54 +00:00
|
|
|
|
|
|
|
if (current_update_time - obj->data.execi.last_update
|
|
|
|
< obj->data.execi.interval
|
|
|
|
|| obj->data.execi.interval == 0) {
|
2008-12-15 01:44:21 +00:00
|
|
|
parse_conky_vars(&subroot, obj->data.execi.buffer, p, tmp_info);
|
2008-03-22 06:10:54 +00:00
|
|
|
} else {
|
|
|
|
char *output = obj->data.execi.buffer;
|
|
|
|
FILE *fp = popen(obj->data.execi.cmd, "r");
|
|
|
|
int length = fread(output, 1, text_buffer_size, fp);
|
|
|
|
|
|
|
|
pclose(fp);
|
|
|
|
|
|
|
|
output[length] = '\0';
|
|
|
|
if (length > 0 && output[length - 1] == '\n') {
|
|
|
|
output[length - 1] = '\0';
|
|
|
|
}
|
2008-06-15 18:38:33 +00:00
|
|
|
|
2008-12-15 01:44:21 +00:00
|
|
|
parse_conky_vars(&subroot, obj->data.execi.buffer, p, tmp_info);
|
2008-03-22 06:10:54 +00:00
|
|
|
obj->data.execi.last_update = current_update_time;
|
|
|
|
}
|
2008-12-18 12:37:53 +00:00
|
|
|
free_text_objects(&subroot);
|
2008-06-21 09:25:03 +00:00
|
|
|
free(tmp_info);
|
2008-03-22 06:10:54 +00:00
|
|
|
}
|
2008-02-20 20:30:45 +00:00
|
|
|
OBJ(texeci) {
|
|
|
|
if (!obj->data.texeci.p_timed_thread) {
|
|
|
|
obj->data.texeci.p_timed_thread =
|
2008-03-29 05:14:35 +00:00
|
|
|
timed_thread_create(&threaded_exec,
|
2008-02-20 20:30:45 +00:00
|
|
|
(void *) obj, obj->data.texeci.interval * 1000000);
|
|
|
|
if (!obj->data.texeci.p_timed_thread) {
|
|
|
|
ERR("Error creating texeci timed thread");
|
|
|
|
}
|
|
|
|
timed_thread_register(obj->data.texeci.p_timed_thread,
|
|
|
|
&obj->data.texeci.p_timed_thread);
|
|
|
|
if (timed_thread_run(obj->data.texeci.p_timed_thread)) {
|
|
|
|
ERR("Error running texeci timed thread");
|
|
|
|
}
|
2009-05-02 05:05:06 +00:00
|
|
|
} else {
|
|
|
|
timed_thread_lock(obj->data.texeci.p_timed_thread);
|
|
|
|
snprintf(p, text_buffer_size, "%s", obj->data.texeci.buffer);
|
|
|
|
timed_thread_unlock(obj->data.texeci.p_timed_thread);
|
2006-01-28 01:28:23 +00:00
|
|
|
}
|
2008-02-20 20:30:45 +00:00
|
|
|
}
|
|
|
|
#endif /* HAVE_POPEN */
|
|
|
|
OBJ(imap_unseen) {
|
2008-06-21 09:25:16 +00:00
|
|
|
struct mail_s *mail = ensure_mail_thread(obj, imap_thread, "imap");
|
|
|
|
|
|
|
|
if (mail && mail->p_timed_thread) {
|
|
|
|
timed_thread_lock(mail->p_timed_thread);
|
|
|
|
snprintf(p, p_max_size, "%lu", mail->unseen);
|
|
|
|
timed_thread_unlock(mail->p_timed_thread);
|
2008-02-20 20:30:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
OBJ(imap_messages) {
|
2008-06-21 09:25:16 +00:00
|
|
|
struct mail_s *mail = ensure_mail_thread(obj, imap_thread, "imap");
|
|
|
|
|
|
|
|
if (mail && mail->p_timed_thread) {
|
|
|
|
timed_thread_lock(mail->p_timed_thread);
|
|
|
|
snprintf(p, p_max_size, "%lu", mail->messages);
|
|
|
|
timed_thread_unlock(mail->p_timed_thread);
|
2008-02-20 20:30:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
OBJ(pop3_unseen) {
|
2008-06-21 09:25:16 +00:00
|
|
|
struct mail_s *mail = ensure_mail_thread(obj, pop3_thread, "pop3");
|
|
|
|
|
|
|
|
if (mail && mail->p_timed_thread) {
|
|
|
|
timed_thread_lock(mail->p_timed_thread);
|
|
|
|
snprintf(p, p_max_size, "%lu", mail->unseen);
|
|
|
|
timed_thread_unlock(mail->p_timed_thread);
|
2008-02-20 20:30:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
OBJ(pop3_used) {
|
2008-06-21 09:25:16 +00:00
|
|
|
struct mail_s *mail = ensure_mail_thread(obj, pop3_thread, "pop3");
|
|
|
|
|
|
|
|
if (mail && mail->p_timed_thread) {
|
|
|
|
timed_thread_lock(mail->p_timed_thread);
|
2008-02-20 20:30:45 +00:00
|
|
|
snprintf(p, p_max_size, "%.1f",
|
2008-06-21 09:25:16 +00:00
|
|
|
mail->used / 1024.0 / 1024.0);
|
|
|
|
timed_thread_unlock(mail->p_timed_thread);
|
2006-05-08 22:34:38 +00:00
|
|
|
}
|
2008-02-20 20:30:45 +00:00
|
|
|
}
|
2005-07-20 00:30:40 +00:00
|
|
|
OBJ(fs_bar) {
|
|
|
|
if (obj->data.fs != NULL) {
|
2008-02-20 20:30:45 +00:00
|
|
|
if (obj->data.fs->size == 0) {
|
|
|
|
new_bar(p, obj->data.fsbar.w, obj->data.fsbar.h, 255);
|
|
|
|
} else {
|
|
|
|
new_bar(p, obj->data.fsbar.w, obj->data.fsbar.h,
|
|
|
|
(int) (255 - obj->data.fsbar.fs->avail * 255 /
|
|
|
|
obj->data.fs->size));
|
|
|
|
}
|
2005-07-20 00:30:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
OBJ(fs_free) {
|
2008-02-09 02:21:06 +00:00
|
|
|
if (obj->data.fs != NULL) {
|
2009-04-09 21:28:45 +00:00
|
|
|
human_readable( (obj->data.fs->free ? obj->data.fs->free :
|
|
|
|
obj->data.fs->avail), p, 255);
|
2008-02-09 02:21:06 +00:00
|
|
|
}
|
2005-07-20 00:30:40 +00:00
|
|
|
}
|
|
|
|
OBJ(fs_free_perc) {
|
|
|
|
if (obj->data.fs != NULL) {
|
2009-03-01 19:53:47 +00:00
|
|
|
int val = 0;
|
|
|
|
|
2009-04-09 21:28:45 +00:00
|
|
|
if (obj->data.fs->size) {
|
|
|
|
val = (obj->data.fs->free ? obj->data.fs->free :
|
|
|
|
obj->data.fs->avail) * 100 /
|
|
|
|
obj->data.fs->size;
|
|
|
|
}
|
2009-03-01 19:53:47 +00:00
|
|
|
|
|
|
|
percent_print(p, p_max_size, val);
|
2005-07-28 04:48:27 +00:00
|
|
|
}
|
2005-07-20 00:30:40 +00:00
|
|
|
}
|
|
|
|
OBJ(fs_size) {
|
2008-02-09 02:21:06 +00:00
|
|
|
if (obj->data.fs != NULL) {
|
2008-12-16 01:56:26 +00:00
|
|
|
human_readable(obj->data.fs->size, p, 255);
|
2008-02-09 02:21:06 +00:00
|
|
|
}
|
2005-07-20 00:30:40 +00:00
|
|
|
}
|
2008-03-18 00:23:16 +00:00
|
|
|
OBJ(fs_type) {
|
|
|
|
if (obj->data.fs != NULL)
|
|
|
|
snprintf(p, p_max_size, "%s", obj->data.fs->type);
|
|
|
|
}
|
2005-07-20 00:30:40 +00:00
|
|
|
OBJ(fs_used) {
|
2008-02-09 02:21:06 +00:00
|
|
|
if (obj->data.fs != NULL) {
|
2008-02-20 20:30:45 +00:00
|
|
|
human_readable(obj->data.fs->size - (obj->data.fs->free
|
2008-12-16 01:56:26 +00:00
|
|
|
? obj->data.fs->free : obj->data.fs->avail), p, 255);
|
2008-02-09 02:21:06 +00:00
|
|
|
}
|
2005-07-20 00:30:40 +00:00
|
|
|
}
|
|
|
|
OBJ(fs_bar_free) {
|
|
|
|
if (obj->data.fs != NULL) {
|
2008-02-20 20:30:45 +00:00
|
|
|
if (obj->data.fs->size == 0) {
|
|
|
|
new_bar(p, obj->data.fsbar.w, obj->data.fsbar.h, 255);
|
|
|
|
} else {
|
|
|
|
new_bar(p, obj->data.fsbar.w, obj->data.fsbar.h,
|
|
|
|
(int) (obj->data.fsbar.fs->avail * 255 /
|
|
|
|
obj->data.fs->size));
|
|
|
|
}
|
2005-07-20 00:30:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
OBJ(fs_used_perc) {
|
|
|
|
if (obj->data.fs != NULL) {
|
2009-03-01 19:53:47 +00:00
|
|
|
int val = 0;
|
|
|
|
|
2009-04-09 21:28:45 +00:00
|
|
|
if (obj->data.fs->size) {
|
|
|
|
val = (obj->data.fs->free ? obj->data.fs->free :
|
|
|
|
obj->data.fs->avail) * 100 /
|
|
|
|
obj->data.fs->size;
|
|
|
|
}
|
2009-03-01 19:53:47 +00:00
|
|
|
|
|
|
|
percent_print(p, p_max_size, 100 - val);
|
2005-07-20 00:30:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
OBJ(loadavg) {
|
|
|
|
float *v = info.loadavg;
|
|
|
|
|
2008-02-20 20:30:45 +00:00
|
|
|
if (obj->data.loadavg[2]) {
|
2005-12-10 14:15:38 +00:00
|
|
|
snprintf(p, p_max_size, "%.2f %.2f %.2f",
|
2008-02-20 20:30:45 +00:00
|
|
|
v[obj->data.loadavg[0] - 1],
|
|
|
|
v[obj->data.loadavg[1] - 1],
|
|
|
|
v[obj->data.loadavg[2] - 1]);
|
|
|
|
} else if (obj->data.loadavg[1]) {
|
2005-12-10 14:15:38 +00:00
|
|
|
snprintf(p, p_max_size, "%.2f %.2f",
|
2008-02-20 20:30:45 +00:00
|
|
|
v[obj->data.loadavg[0] - 1],
|
|
|
|
v[obj->data.loadavg[1] - 1]);
|
|
|
|
} else if (obj->data.loadavg[0]) {
|
2005-12-10 14:15:38 +00:00
|
|
|
snprintf(p, p_max_size, "%.2f",
|
2008-02-20 20:30:45 +00:00
|
|
|
v[obj->data.loadavg[0] - 1]);
|
|
|
|
}
|
2005-07-20 00:30:40 +00:00
|
|
|
}
|
2006-08-10 16:56:13 +00:00
|
|
|
OBJ(goto) {
|
|
|
|
new_goto(p, obj->data.i);
|
|
|
|
}
|
|
|
|
OBJ(tab) {
|
|
|
|
new_tab(p, obj->data.pair.a, obj->data.pair.b);
|
|
|
|
}
|
2005-07-20 00:30:40 +00:00
|
|
|
OBJ(hr) {
|
|
|
|
new_hr(p, obj->data.i);
|
|
|
|
}
|
2008-03-22 22:58:26 +00:00
|
|
|
OBJ(nameserver) {
|
|
|
|
if (cur->nameserver_info.nscount > obj->data.i)
|
|
|
|
snprintf(p, p_max_size, "%s",
|
|
|
|
cur->nameserver_info.ns_list[obj->data.i]);
|
|
|
|
}
|
2008-06-28 20:14:04 +00:00
|
|
|
#ifdef EVE
|
2008-07-12 01:22:40 +00:00
|
|
|
OBJ(eve) {
|
|
|
|
char *skill = eve(obj->data.eve.userid, obj->data.eve.apikey, obj->data.eve.charid);
|
|
|
|
snprintf(p, p_max_size, "%s", skill);
|
|
|
|
}
|
2008-06-28 20:14:04 +00:00
|
|
|
#endif
|
2007-05-06 12:17:13 +00:00
|
|
|
#ifdef RSS
|
|
|
|
OBJ(rss) {
|
2008-02-20 20:30:45 +00:00
|
|
|
PRSS *data = get_rss_info(obj->data.rss.uri,
|
|
|
|
obj->data.rss.delay);
|
2007-06-03 11:20:47 +00:00
|
|
|
char *str;
|
2008-02-20 20:30:45 +00:00
|
|
|
|
|
|
|
if (data == NULL) {
|
2007-06-01 10:42:57 +00:00
|
|
|
snprintf(p, p_max_size, "prss: Error reading RSS data\n");
|
2008-02-20 20:30:45 +00:00
|
|
|
} else {
|
2008-06-21 20:37:58 +00:00
|
|
|
if (strcmp(obj->data.rss.action, "feed_title") == EQUAL) {
|
2008-02-20 20:30:45 +00:00
|
|
|
str = data->title;
|
|
|
|
// remove trailing new line if one exists
|
|
|
|
if (str[strlen(str) - 1] == '\n') {
|
|
|
|
str[strlen(str) - 1] = 0;
|
|
|
|
}
|
|
|
|
snprintf(p, p_max_size, "%s", str);
|
2008-06-21 20:37:58 +00:00
|
|
|
} else if (strcmp(obj->data.rss.action, "item_title") == EQUAL) {
|
2008-02-20 20:30:45 +00:00
|
|
|
if (obj->data.rss.act_par < data->item_count) {
|
2007-06-03 11:20:47 +00:00
|
|
|
str = data->items[obj->data.rss.act_par].title;
|
2008-02-20 20:30:45 +00:00
|
|
|
// remove trailing new line if one exists
|
|
|
|
if (str[strlen(str) - 1] == '\n') {
|
|
|
|
str[strlen(str) - 1] = 0;
|
|
|
|
}
|
2007-06-03 11:20:47 +00:00
|
|
|
snprintf(p, p_max_size, "%s", str);
|
2007-06-01 10:42:57 +00:00
|
|
|
}
|
2008-06-21 20:37:58 +00:00
|
|
|
} else if (strcmp(obj->data.rss.action, "item_desc") == EQUAL) {
|
2008-02-20 20:30:45 +00:00
|
|
|
if (obj->data.rss.act_par < data->item_count) {
|
|
|
|
str =
|
|
|
|
data->items[obj->data.rss.act_par].description;
|
|
|
|
// remove trailing new line if one exists
|
|
|
|
if (str[strlen(str) - 1] == '\n') {
|
|
|
|
str[strlen(str) - 1] = 0;
|
|
|
|
}
|
2007-06-03 11:20:47 +00:00
|
|
|
snprintf(p, p_max_size, "%s", str);
|
2007-06-02 08:17:33 +00:00
|
|
|
}
|
2008-06-21 20:37:58 +00:00
|
|
|
} else if (strcmp(obj->data.rss.action, "item_titles") == EQUAL) {
|
2008-02-20 20:30:45 +00:00
|
|
|
if (data->item_count > 0) {
|
2007-06-02 08:17:33 +00:00
|
|
|
int itmp;
|
2008-03-29 06:24:04 +00:00
|
|
|
int show;
|
2009-04-18 22:42:01 +00:00
|
|
|
//'tmpspaces' is a string with spaces too be placed in front of each title
|
|
|
|
char *tmpspaces = malloc(obj->data.rss.nrspaces + 1);
|
|
|
|
memset(tmpspaces, ' ', obj->data.rss.nrspaces);
|
|
|
|
tmpspaces[obj->data.rss.nrspaces]=0;
|
2008-02-20 20:30:45 +00:00
|
|
|
|
2007-06-02 08:17:33 +00:00
|
|
|
p[0] = 0;
|
2008-02-20 20:30:45 +00:00
|
|
|
|
|
|
|
if (obj->data.rss.act_par > data->item_count) {
|
2007-06-02 08:17:33 +00:00
|
|
|
show = data->item_count;
|
2008-02-20 20:30:45 +00:00
|
|
|
} else {
|
|
|
|
show = obj->data.rss.act_par;
|
|
|
|
}
|
|
|
|
for (itmp = 0; itmp < show; itmp++) {
|
2007-06-02 08:17:33 +00:00
|
|
|
PRSS_Item *item = &data->items[itmp];
|
2008-02-20 20:30:45 +00:00
|
|
|
|
2007-06-03 11:20:47 +00:00
|
|
|
str = item->title;
|
2008-02-20 20:30:45 +00:00
|
|
|
if (str) {
|
|
|
|
// don't add new line before first item
|
|
|
|
if (itmp > 0) {
|
2007-06-06 14:19:09 +00:00
|
|
|
strncat(p, "\n", p_max_size);
|
2008-02-20 20:30:45 +00:00
|
|
|
}
|
|
|
|
/* remove trailing new line if one exists,
|
|
|
|
* we have our own */
|
|
|
|
if (str[strlen(str) - 1] == '\n') {
|
|
|
|
str[strlen(str) - 1] = 0;
|
|
|
|
}
|
2009-04-18 22:42:01 +00:00
|
|
|
strncat(p, tmpspaces, p_max_size);
|
2007-07-19 16:32:00 +00:00
|
|
|
strncat(p, str, p_max_size);
|
2007-06-06 14:19:09 +00:00
|
|
|
}
|
2007-06-02 08:17:33 +00:00
|
|
|
}
|
2009-04-18 22:42:01 +00:00
|
|
|
free(tmpspaces);
|
2007-06-02 08:17:33 +00:00
|
|
|
}
|
|
|
|
}
|
2007-05-06 12:17:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2006-11-04 17:55:00 +00:00
|
|
|
#ifdef HDDTEMP
|
2006-08-10 16:56:13 +00:00
|
|
|
OBJ(hddtemp) {
|
2008-12-08 15:01:15 +00:00
|
|
|
char *endptr, unit;
|
|
|
|
long val;
|
2008-09-11 03:22:37 +00:00
|
|
|
if (obj->data.hddtemp.update_time < current_update_time - 30) {
|
2008-12-08 15:01:15 +00:00
|
|
|
if (obj->data.hddtemp.temp)
|
|
|
|
free(obj->data.hddtemp.temp);
|
|
|
|
obj->data.hddtemp.temp = get_hddtemp_info(obj->data.hddtemp.dev,
|
|
|
|
obj->data.hddtemp.addr, obj->data.hddtemp.port);
|
2008-04-13 04:10:35 +00:00
|
|
|
obj->data.hddtemp.update_time = current_update_time;
|
2008-09-11 03:22:37 +00:00
|
|
|
}
|
2008-04-13 04:10:35 +00:00
|
|
|
if (!obj->data.hddtemp.temp) {
|
2006-08-10 16:56:13 +00:00
|
|
|
snprintf(p, p_max_size, "N/A");
|
2008-12-07 19:08:29 +00:00
|
|
|
} else {
|
2008-12-08 15:01:15 +00:00
|
|
|
val = strtol(obj->data.hddtemp.temp + 1, &endptr, 10);
|
|
|
|
unit = obj->data.hddtemp.temp[0];
|
|
|
|
|
|
|
|
if (*endptr != '\0')
|
|
|
|
snprintf(p, p_max_size, "N/A");
|
|
|
|
else if (unit == 'C')
|
|
|
|
temp_print(p, p_max_size, (double)val, TEMP_CELSIUS);
|
|
|
|
else if (unit == 'F')
|
|
|
|
temp_print(p, p_max_size, (double)val, TEMP_FAHRENHEIT);
|
2008-12-07 19:08:29 +00:00
|
|
|
else
|
2008-12-08 15:01:15 +00:00
|
|
|
snprintf(p, p_max_size, "N/A");
|
2006-08-10 16:56:13 +00:00
|
|
|
}
|
|
|
|
}
|
2006-11-04 17:55:00 +00:00
|
|
|
#endif
|
2005-08-21 05:04:22 +00:00
|
|
|
OBJ(offset) {
|
2005-07-31 19:49:39 +00:00
|
|
|
new_offset(p, obj->data.i);
|
2005-07-31 08:27:03 +00:00
|
|
|
}
|
2005-08-21 05:04:22 +00:00
|
|
|
OBJ(voffset) {
|
|
|
|
new_voffset(p, obj->data.i);
|
|
|
|
}
|
2009-03-28 19:46:20 +00:00
|
|
|
#ifdef __linux__
|
2005-08-21 05:04:22 +00:00
|
|
|
OBJ(i2c) {
|
2005-07-20 00:30:40 +00:00
|
|
|
double r;
|
|
|
|
|
2008-02-20 20:30:45 +00:00
|
|
|
r = get_sysfs_info(&obj->data.sysfs.fd, obj->data.sysfs.arg,
|
|
|
|
obj->data.sysfs.devtype, obj->data.sysfs.type);
|
|
|
|
|
2008-12-07 19:08:29 +00:00
|
|
|
if (!strncmp(obj->data.sysfs.type, "temp", 4)) {
|
|
|
|
temp_print(p, p_max_size, r, TEMP_CELSIUS);
|
|
|
|
} else if (r >= 100.0 || r == 0) {
|
2008-02-20 20:30:45 +00:00
|
|
|
snprintf(p, p_max_size, "%d", (int) r);
|
|
|
|
} else {
|
|
|
|
snprintf(p, p_max_size, "%.1f", r);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
OBJ(platform) {
|
|
|
|
double r;
|
|
|
|
|
|
|
|
r = get_sysfs_info(&obj->data.sysfs.fd, obj->data.sysfs.arg,
|
|
|
|
obj->data.sysfs.devtype, obj->data.sysfs.type);
|
|
|
|
|
2008-12-07 19:08:29 +00:00
|
|
|
if (!strncmp(obj->data.sysfs.type, "temp", 4)) {
|
|
|
|
temp_print(p, p_max_size, r, TEMP_CELSIUS);
|
|
|
|
} else if (r >= 100.0 || r == 0) {
|
2008-02-20 20:30:45 +00:00
|
|
|
snprintf(p, p_max_size, "%d", (int) r);
|
|
|
|
} else {
|
|
|
|
snprintf(p, p_max_size, "%.1f", r);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
OBJ(hwmon) {
|
|
|
|
double r;
|
|
|
|
|
|
|
|
r = get_sysfs_info(&obj->data.sysfs.fd, obj->data.sysfs.arg,
|
|
|
|
obj->data.sysfs.devtype, obj->data.sysfs.type);
|
2005-07-20 00:30:40 +00:00
|
|
|
|
2008-12-07 19:08:29 +00:00
|
|
|
if (!strncmp(obj->data.sysfs.type, "temp", 4)) {
|
|
|
|
temp_print(p, p_max_size, r, TEMP_CELSIUS);
|
|
|
|
} else if (r >= 100.0 || r == 0) {
|
2005-12-10 14:15:38 +00:00
|
|
|
snprintf(p, p_max_size, "%d", (int) r);
|
2008-02-20 20:30:45 +00:00
|
|
|
} else {
|
2005-12-10 14:15:38 +00:00
|
|
|
snprintf(p, p_max_size, "%.1f", r);
|
2008-02-20 20:30:45 +00:00
|
|
|
}
|
2005-07-20 00:30:40 +00:00
|
|
|
}
|
2009-03-28 19:46:20 +00:00
|
|
|
#endif /* __linux__ */
|
2005-07-20 00:30:40 +00:00
|
|
|
OBJ(alignr) {
|
|
|
|
new_alignr(p, obj->data.i);
|
|
|
|
}
|
|
|
|
OBJ(alignc) {
|
|
|
|
new_alignc(p, obj->data.i);
|
|
|
|
}
|
2007-04-06 05:01:48 +00:00
|
|
|
OBJ(if_empty) {
|
2008-12-22 17:36:44 +00:00
|
|
|
char buf[max_user_text];
|
2008-06-21 09:25:03 +00:00
|
|
|
struct information *tmp_info =
|
2008-02-20 20:30:45 +00:00
|
|
|
malloc(sizeof(struct information));
|
2008-06-21 09:25:03 +00:00
|
|
|
memcpy(tmp_info, cur, sizeof(struct information));
|
2008-12-22 17:36:44 +00:00
|
|
|
generate_text_internal(buf, max_user_text,
|
|
|
|
*obj->sub, tmp_info);
|
2008-03-29 06:24:04 +00:00
|
|
|
|
2008-12-22 17:36:44 +00:00
|
|
|
if (strlen(buf) != 0) {
|
2008-12-15 01:44:21 +00:00
|
|
|
DO_JUMP;
|
2007-04-06 05:01:48 +00:00
|
|
|
}
|
2008-06-21 09:25:03 +00:00
|
|
|
free(tmp_info);
|
2007-04-06 05:01:48 +00:00
|
|
|
}
|
2008-12-20 01:31:00 +00:00
|
|
|
OBJ(if_match) {
|
|
|
|
char expression[max_user_text];
|
|
|
|
int val;
|
|
|
|
struct information *tmp_info;
|
|
|
|
|
|
|
|
tmp_info = malloc(sizeof(struct information));
|
|
|
|
memcpy(tmp_info, cur, sizeof(struct information));
|
2008-12-22 17:36:44 +00:00
|
|
|
generate_text_internal(expression, max_user_text,
|
|
|
|
*obj->sub, tmp_info);
|
2008-12-20 01:31:00 +00:00
|
|
|
DBGP("parsed arg into '%s'", expression);
|
|
|
|
|
|
|
|
val = compare(expression);
|
|
|
|
if (val == -2) {
|
|
|
|
ERR("compare failed for expression '%s'",
|
|
|
|
expression);
|
|
|
|
} else if (!val) {
|
|
|
|
DO_JUMP;
|
|
|
|
}
|
|
|
|
free(tmp_info);
|
|
|
|
}
|
2005-07-28 04:48:27 +00:00
|
|
|
OBJ(if_existing) {
|
2008-12-15 15:39:48 +00:00
|
|
|
if (obj->data.ifblock.str
|
|
|
|
&& !check_contains(obj->data.ifblock.s,
|
|
|
|
obj->data.ifblock.str)) {
|
2008-12-15 01:44:21 +00:00
|
|
|
DO_JUMP;
|
2008-12-15 15:39:48 +00:00
|
|
|
} else if (obj->data.ifblock.s
|
|
|
|
&& access(obj->data.ifblock.s, F_OK)) {
|
2008-12-15 01:44:21 +00:00
|
|
|
DO_JUMP;
|
2006-01-26 03:05:12 +00:00
|
|
|
}
|
2005-07-28 04:48:27 +00:00
|
|
|
}
|
|
|
|
OBJ(if_mounted) {
|
|
|
|
if ((obj->data.ifblock.s)
|
2008-02-20 20:30:45 +00:00
|
|
|
&& (!check_mount(obj->data.ifblock.s))) {
|
2008-12-15 01:44:21 +00:00
|
|
|
DO_JUMP;
|
2006-01-26 03:05:12 +00:00
|
|
|
}
|
2005-07-28 04:48:27 +00:00
|
|
|
}
|
|
|
|
OBJ(if_running) {
|
2008-02-20 20:30:45 +00:00
|
|
|
if ((obj->data.ifblock.s) && system(obj->data.ifblock.s)) {
|
2008-12-15 01:44:21 +00:00
|
|
|
DO_JUMP;
|
2006-01-26 03:05:12 +00:00
|
|
|
}
|
2005-07-28 04:48:27 +00:00
|
|
|
}
|
2008-05-03 12:30:05 +00:00
|
|
|
#if defined(__linux__)
|
2008-03-22 21:10:43 +00:00
|
|
|
OBJ(ioscheduler) {
|
|
|
|
snprintf(p, p_max_size, "%s", get_ioscheduler(obj->data.s));
|
|
|
|
}
|
2008-05-03 12:30:05 +00:00
|
|
|
#endif
|
2005-07-20 00:30:40 +00:00
|
|
|
OBJ(kernel) {
|
2005-12-10 14:15:38 +00:00
|
|
|
snprintf(p, p_max_size, "%s", cur->uname_s.release);
|
2005-07-20 00:30:40 +00:00
|
|
|
}
|
|
|
|
OBJ(machine) {
|
2005-12-10 14:15:38 +00:00
|
|
|
snprintf(p, p_max_size, "%s", cur->uname_s.machine);
|
2005-07-20 00:30:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* memory stuff */
|
|
|
|
OBJ(mem) {
|
2008-12-16 01:56:26 +00:00
|
|
|
human_readable(cur->mem * 1024, p, 255);
|
2005-07-20 00:30:40 +00:00
|
|
|
}
|
2008-06-21 20:37:58 +00:00
|
|
|
OBJ(memeasyfree) {
|
2008-12-16 01:56:26 +00:00
|
|
|
human_readable(cur->memeasyfree * 1024, p, 255);
|
2008-06-21 20:37:58 +00:00
|
|
|
}
|
|
|
|
OBJ(memfree) {
|
2008-12-16 01:56:26 +00:00
|
|
|
human_readable(cur->memfree * 1024, p, 255);
|
2008-06-21 20:37:58 +00:00
|
|
|
}
|
2005-07-20 00:30:40 +00:00
|
|
|
OBJ(memmax) {
|
2008-12-16 01:56:26 +00:00
|
|
|
human_readable(cur->memmax * 1024, p, 255);
|
2005-07-20 00:30:40 +00:00
|
|
|
}
|
|
|
|
OBJ(memperc) {
|
2009-03-01 19:53:47 +00:00
|
|
|
if (cur->memmax)
|
|
|
|
percent_print(p, p_max_size, cur->mem * 100 / cur->memmax);
|
2005-07-20 00:30:40 +00:00
|
|
|
}
|
2009-03-11 00:37:24 +00:00
|
|
|
OBJ(memgauge){
|
|
|
|
new_gauge(p, obj->data.pair.a, obj->data.pair.b,
|
|
|
|
cur->memmax ? (cur->mem * 255) / (cur->memmax) : 0);
|
|
|
|
}
|
2005-07-20 00:30:40 +00:00
|
|
|
OBJ(membar) {
|
2008-02-20 20:30:45 +00:00
|
|
|
new_bar(p, obj->data.pair.a, obj->data.pair.b,
|
|
|
|
cur->memmax ? (cur->mem * 255) / (cur->memmax) : 0);
|
2005-07-20 00:30:40 +00:00
|
|
|
}
|
2005-07-28 06:56:55 +00:00
|
|
|
OBJ(memgraph) {
|
2008-02-20 20:30:45 +00:00
|
|
|
new_graph(p, obj->a, obj->b, obj->c, obj->d,
|
|
|
|
cur->memmax ? (cur->mem * 100.0) / (cur->memmax) : 0.0,
|
2008-06-21 20:37:58 +00:00
|
|
|
100, 1, obj->showaslog);
|
2005-07-28 06:56:55 +00:00
|
|
|
}
|
2008-02-20 20:30:45 +00:00
|
|
|
|
2005-07-20 00:30:40 +00:00
|
|
|
/* mixer stuff */
|
|
|
|
OBJ(mixer) {
|
2009-03-01 19:53:47 +00:00
|
|
|
percent_print(p, p_max_size, mixer_get_avg(obj->data.l));
|
2005-07-20 00:30:40 +00:00
|
|
|
}
|
|
|
|
OBJ(mixerl) {
|
2009-03-01 19:53:47 +00:00
|
|
|
percent_print(p, p_max_size, mixer_get_left(obj->data.l));
|
2005-07-20 00:30:40 +00:00
|
|
|
}
|
|
|
|
OBJ(mixerr) {
|
2009-03-01 19:53:47 +00:00
|
|
|
percent_print(p, p_max_size, mixer_get_right(obj->data.l));
|
2005-07-20 00:30:40 +00:00
|
|
|
}
|
|
|
|
OBJ(mixerbar) {
|
2008-02-20 20:30:45 +00:00
|
|
|
new_bar(p, obj->data.mixerbar.w, obj->data.mixerbar.h,
|
2009-04-28 16:56:49 +00:00
|
|
|
mixer_to_255(obj->data.mixerbar.l,mixer_get_avg(obj->data.mixerbar.l)));
|
2005-07-20 00:30:40 +00:00
|
|
|
}
|
|
|
|
OBJ(mixerlbar) {
|
2008-02-20 20:30:45 +00:00
|
|
|
new_bar(p, obj->data.mixerbar.w, obj->data.mixerbar.h,
|
2009-04-28 16:56:49 +00:00
|
|
|
mixer_to_255(obj->data.mixerbar.l,mixer_get_left(obj->data.mixerbar.l)));
|
2005-07-20 00:30:40 +00:00
|
|
|
}
|
|
|
|
OBJ(mixerrbar) {
|
2008-02-20 20:30:45 +00:00
|
|
|
new_bar(p, obj->data.mixerbar.w, obj->data.mixerbar.h,
|
2009-04-28 16:56:49 +00:00
|
|
|
mixer_to_255(obj->data.mixerbar.l,mixer_get_right(obj->data.mixerbar.l)));
|
|
|
|
}
|
|
|
|
OBJ(if_mixer_mute) {
|
|
|
|
if (!mixer_is_mute(obj->data.ifblock.i)) {
|
|
|
|
DO_JUMP;
|
|
|
|
}
|
2005-07-20 00:30:40 +00:00
|
|
|
}
|
2008-06-21 20:37:58 +00:00
|
|
|
#ifdef X11
|
|
|
|
OBJ(monitor) {
|
|
|
|
snprintf(p, p_max_size, "%d", cur->x11.monitor.current);
|
|
|
|
}
|
|
|
|
OBJ(monitor_number) {
|
|
|
|
snprintf(p, p_max_size, "%d", cur->x11.monitor.number);
|
|
|
|
}
|
|
|
|
#endif
|
2005-07-20 00:30:40 +00:00
|
|
|
|
|
|
|
/* mail stuff */
|
|
|
|
OBJ(mails) {
|
2007-10-02 23:57:41 +00:00
|
|
|
update_mail_count(&obj->data.local_mail);
|
|
|
|
snprintf(p, p_max_size, "%d", obj->data.local_mail.mail_count);
|
2005-07-20 00:30:40 +00:00
|
|
|
}
|
|
|
|
OBJ(new_mails) {
|
2007-10-02 23:57:41 +00:00
|
|
|
update_mail_count(&obj->data.local_mail);
|
2008-02-20 20:30:45 +00:00
|
|
|
snprintf(p, p_max_size, "%d",
|
|
|
|
obj->data.local_mail.new_mail_count);
|
2005-07-20 00:30:40 +00:00
|
|
|
}
|
2009-02-18 05:26:15 +00:00
|
|
|
OBJ(seen_mails) {
|
|
|
|
update_mail_count(&obj->data.local_mail);
|
|
|
|
snprintf(p, p_max_size, "%d",
|
|
|
|
obj->data.local_mail.seen_mail_count);
|
|
|
|
}
|
|
|
|
OBJ(unseen_mails) {
|
|
|
|
update_mail_count(&obj->data.local_mail);
|
|
|
|
snprintf(p, p_max_size, "%d",
|
|
|
|
obj->data.local_mail.unseen_mail_count);
|
|
|
|
}
|
|
|
|
OBJ(flagged_mails) {
|
|
|
|
update_mail_count(&obj->data.local_mail);
|
|
|
|
snprintf(p, p_max_size, "%d",
|
|
|
|
obj->data.local_mail.flagged_mail_count);
|
|
|
|
}
|
|
|
|
OBJ(unflagged_mails) {
|
|
|
|
update_mail_count(&obj->data.local_mail);
|
|
|
|
snprintf(p, p_max_size, "%d",
|
|
|
|
obj->data.local_mail.unflagged_mail_count);
|
|
|
|
}
|
|
|
|
OBJ(forwarded_mails) {
|
|
|
|
update_mail_count(&obj->data.local_mail);
|
|
|
|
snprintf(p, p_max_size, "%d",
|
|
|
|
obj->data.local_mail.forwarded_mail_count);
|
|
|
|
}
|
|
|
|
OBJ(unforwarded_mails) {
|
|
|
|
update_mail_count(&obj->data.local_mail);
|
|
|
|
snprintf(p, p_max_size, "%d",
|
|
|
|
obj->data.local_mail.unforwarded_mail_count);
|
|
|
|
}
|
|
|
|
OBJ(replied_mails) {
|
|
|
|
update_mail_count(&obj->data.local_mail);
|
|
|
|
snprintf(p, p_max_size, "%d",
|
|
|
|
obj->data.local_mail.replied_mail_count);
|
|
|
|
}
|
|
|
|
OBJ(unreplied_mails) {
|
|
|
|
update_mail_count(&obj->data.local_mail);
|
|
|
|
snprintf(p, p_max_size, "%d",
|
|
|
|
obj->data.local_mail.unreplied_mail_count);
|
|
|
|
}
|
|
|
|
OBJ(draft_mails) {
|
|
|
|
update_mail_count(&obj->data.local_mail);
|
|
|
|
snprintf(p, p_max_size, "%d",
|
|
|
|
obj->data.local_mail.draft_mail_count);
|
|
|
|
}
|
|
|
|
OBJ(trashed_mails) {
|
|
|
|
update_mail_count(&obj->data.local_mail);
|
|
|
|
snprintf(p, p_max_size, "%d",
|
|
|
|
obj->data.local_mail.trashed_mail_count);
|
|
|
|
}
|
|
|
|
OBJ(mboxscan) {
|
|
|
|
mbox_scan(obj->data.mboxscan.args, obj->data.mboxscan.output,
|
|
|
|
text_buffer_size);
|
|
|
|
snprintf(p, p_max_size, "%s", obj->data.mboxscan.output);
|
|
|
|
}
|
2005-07-20 00:30:40 +00:00
|
|
|
OBJ(nodename) {
|
2008-02-20 20:30:45 +00:00
|
|
|
snprintf(p, p_max_size, "%s", cur->uname_s.nodename);
|
2005-07-20 00:30:40 +00:00
|
|
|
}
|
|
|
|
OBJ(outlinecolor) {
|
|
|
|
new_outline(p, obj->data.l);
|
|
|
|
}
|
|
|
|
OBJ(processes) {
|
2009-03-01 20:06:23 +00:00
|
|
|
spaced_print(p, p_max_size, "%hu", 4, cur->procs);
|
2005-07-20 00:30:40 +00:00
|
|
|
}
|
|
|
|
OBJ(running_processes) {
|
2009-03-01 20:06:23 +00:00
|
|
|
spaced_print(p, p_max_size, "%hu", 4, cur->run_procs);
|
2005-07-20 00:30:40 +00:00
|
|
|
}
|
|
|
|
OBJ(text) {
|
2005-12-10 14:15:38 +00:00
|
|
|
snprintf(p, p_max_size, "%s", obj->data.s);
|
2005-07-20 00:30:40 +00:00
|
|
|
}
|
|
|
|
OBJ(shadecolor) {
|
|
|
|
new_bg(p, obj->data.l);
|
|
|
|
}
|
|
|
|
OBJ(stippled_hr) {
|
2008-02-20 20:30:45 +00:00
|
|
|
new_stippled_hr(p, obj->data.pair.a, obj->data.pair.b);
|
2005-07-20 00:30:40 +00:00
|
|
|
}
|
|
|
|
OBJ(swap) {
|
2008-12-16 01:56:26 +00:00
|
|
|
human_readable(cur->swap * 1024, p, 255);
|
2005-07-20 00:30:40 +00:00
|
|
|
}
|
|
|
|
OBJ(swapmax) {
|
2008-12-16 01:56:26 +00:00
|
|
|
human_readable(cur->swapmax * 1024, p, 255);
|
2005-07-20 00:30:40 +00:00
|
|
|
}
|
|
|
|
OBJ(swapperc) {
|
|
|
|
if (cur->swapmax == 0) {
|
2008-02-09 02:21:06 +00:00
|
|
|
strncpy(p, "No swap", p_max_size);
|
2005-07-20 00:30:40 +00:00
|
|
|
} else {
|
2009-03-01 19:53:47 +00:00
|
|
|
percent_print(p, p_max_size, cur->swap * 100 / cur->swapmax);
|
2005-07-20 00:30:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
OBJ(swapbar) {
|
2008-02-20 20:30:45 +00:00
|
|
|
new_bar(p, obj->data.pair.a, obj->data.pair.b,
|
|
|
|
cur->swapmax ? (cur->swap * 255) / (cur->swapmax) : 0);
|
2005-07-20 00:30:40 +00:00
|
|
|
}
|
|
|
|
OBJ(sysname) {
|
2005-12-10 14:15:38 +00:00
|
|
|
snprintf(p, p_max_size, "%s", cur->uname_s.sysname);
|
2005-07-20 00:30:40 +00:00
|
|
|
}
|
|
|
|
OBJ(time) {
|
|
|
|
time_t t = time(NULL);
|
|
|
|
struct tm *tm = localtime(&t);
|
2008-02-20 20:30:45 +00:00
|
|
|
|
2005-07-20 00:30:40 +00:00
|
|
|
setlocale(LC_TIME, "");
|
2005-12-10 14:15:38 +00:00
|
|
|
strftime(p, p_max_size, obj->data.s, tm);
|
2005-07-20 00:30:40 +00:00
|
|
|
}
|
|
|
|
OBJ(utime) {
|
|
|
|
time_t t = time(NULL);
|
|
|
|
struct tm *tm = gmtime(&t);
|
2008-02-20 20:30:45 +00:00
|
|
|
|
2005-12-10 14:15:38 +00:00
|
|
|
strftime(p, p_max_size, obj->data.s, tm);
|
2005-07-20 00:30:40 +00:00
|
|
|
}
|
2006-07-15 02:18:06 +00:00
|
|
|
OBJ(tztime) {
|
2008-02-20 20:30:45 +00:00
|
|
|
char *oldTZ = NULL;
|
2008-03-29 06:24:04 +00:00
|
|
|
time_t t;
|
|
|
|
struct tm *tm;
|
2008-02-20 20:30:45 +00:00
|
|
|
|
2006-07-15 02:18:06 +00:00
|
|
|
if (obj->data.tztime.tz) {
|
|
|
|
oldTZ = getenv("TZ");
|
|
|
|
setenv("TZ", obj->data.tztime.tz, 1);
|
|
|
|
tzset();
|
|
|
|
}
|
2008-03-29 06:24:04 +00:00
|
|
|
t = time(NULL);
|
|
|
|
tm = localtime(&t);
|
2008-02-20 20:30:45 +00:00
|
|
|
|
2006-07-15 02:18:06 +00:00
|
|
|
setlocale(LC_TIME, "");
|
|
|
|
strftime(p, p_max_size, obj->data.tztime.fmt, tm);
|
|
|
|
if (oldTZ) {
|
|
|
|
setenv("TZ", oldTZ, 1);
|
|
|
|
tzset();
|
|
|
|
} else {
|
|
|
|
unsetenv("TZ");
|
|
|
|
}
|
2008-02-20 20:30:45 +00:00
|
|
|
// Needless to free oldTZ since getenv gives ptr to static data
|
2006-07-15 02:18:06 +00:00
|
|
|
}
|
2005-07-20 00:30:40 +00:00
|
|
|
OBJ(totaldown) {
|
2008-12-16 01:56:26 +00:00
|
|
|
human_readable(obj->data.net->recv, p, 255);
|
2005-07-20 00:30:40 +00:00
|
|
|
}
|
|
|
|
OBJ(totalup) {
|
2008-12-16 01:56:26 +00:00
|
|
|
human_readable(obj->data.net->trans, p, 255);
|
2005-07-20 00:30:40 +00:00
|
|
|
}
|
|
|
|
OBJ(updates) {
|
2005-12-10 14:15:38 +00:00
|
|
|
snprintf(p, p_max_size, "%d", total_updates);
|
2005-07-20 00:30:40 +00:00
|
|
|
}
|
2009-03-01 14:10:01 +00:00
|
|
|
OBJ(if_updatenr) {
|
|
|
|
if(total_updates % updatereset != obj->data.ifblock.i - 1) {
|
|
|
|
DO_JUMP;
|
|
|
|
}
|
|
|
|
}
|
2005-07-20 00:30:40 +00:00
|
|
|
OBJ(upspeed) {
|
2009-02-18 05:00:23 +00:00
|
|
|
human_readable(obj->data.net->trans_speed, p, 255);
|
2005-07-20 00:30:40 +00:00
|
|
|
}
|
|
|
|
OBJ(upspeedf) {
|
2008-12-16 01:56:26 +00:00
|
|
|
spaced_print(p, p_max_size, "%.1f", 8,
|
2008-02-09 02:21:06 +00:00
|
|
|
obj->data.net->trans_speed / 1024.0);
|
2005-07-20 00:30:40 +00:00
|
|
|
}
|
2005-07-28 06:56:55 +00:00
|
|
|
OBJ(upspeedgraph) {
|
2005-08-01 09:15:02 +00:00
|
|
|
new_graph(p, obj->a, obj->b, obj->c, obj->d,
|
2008-06-21 20:37:58 +00:00
|
|
|
obj->data.net->trans_speed / 1024.0, obj->e, 1, obj->showaslog);
|
2005-07-30 11:23:26 +00:00
|
|
|
}
|
2005-07-20 00:30:40 +00:00
|
|
|
OBJ(uptime_short) {
|
2008-02-20 20:30:45 +00:00
|
|
|
format_seconds_short(p, p_max_size, (int) cur->uptime);
|
2005-07-20 00:30:40 +00:00
|
|
|
}
|
|
|
|
OBJ(uptime) {
|
2005-12-10 14:15:38 +00:00
|
|
|
format_seconds(p, p_max_size, (int) cur->uptime);
|
2005-07-20 00:30:40 +00:00
|
|
|
}
|
2008-03-18 00:23:16 +00:00
|
|
|
OBJ(user_names) {
|
|
|
|
snprintf(p, p_max_size, "%s", cur->users.names);
|
|
|
|
}
|
|
|
|
OBJ(user_terms) {
|
|
|
|
snprintf(p, p_max_size, "%s", cur->users.terms);
|
|
|
|
}
|
|
|
|
OBJ(user_times) {
|
|
|
|
snprintf(p, p_max_size, "%s", cur->users.times);
|
|
|
|
}
|
|
|
|
OBJ(user_number) {
|
|
|
|
snprintf(p, p_max_size, "%d", cur->users.number);
|
|
|
|
}
|
2008-02-20 20:30:45 +00:00
|
|
|
#if (defined(__FreeBSD__) || defined(__FreeBSD_kernel__) \
|
|
|
|
|| defined(__OpenBSD__)) && (defined(i386) || defined(__i386__))
|
2005-08-30 04:19:16 +00:00
|
|
|
OBJ(apm_adapter) {
|
2008-02-20 20:30:45 +00:00
|
|
|
char *msg;
|
|
|
|
|
2007-05-06 09:32:21 +00:00
|
|
|
msg = get_apm_adapter();
|
|
|
|
snprintf(p, p_max_size, "%s", msg);
|
|
|
|
free(msg);
|
2005-08-30 04:19:16 +00:00
|
|
|
}
|
|
|
|
OBJ(apm_battery_life) {
|
2008-02-20 20:30:45 +00:00
|
|
|
char *msg;
|
|
|
|
|
2005-08-30 04:19:16 +00:00
|
|
|
msg = get_apm_battery_life();
|
2005-12-10 14:15:38 +00:00
|
|
|
snprintf(p, p_max_size, "%s", msg);
|
2005-08-30 04:19:16 +00:00
|
|
|
free(msg);
|
|
|
|
}
|
|
|
|
OBJ(apm_battery_time) {
|
2008-02-20 20:30:45 +00:00
|
|
|
char *msg;
|
|
|
|
|
2005-08-30 04:19:16 +00:00
|
|
|
msg = get_apm_battery_time();
|
2005-12-10 14:15:38 +00:00
|
|
|
snprintf(p, p_max_size, "%s", msg);
|
2005-08-30 04:19:16 +00:00
|
|
|
free(msg);
|
|
|
|
}
|
2007-05-06 09:32:21 +00:00
|
|
|
#endif /* __FreeBSD__ __OpenBSD__ */
|
2005-07-20 00:30:40 +00:00
|
|
|
|
|
|
|
#ifdef MPD
|
2008-12-18 12:37:53 +00:00
|
|
|
#define mpd_printf(fmt, val) \
|
|
|
|
snprintf(p, p_max_size, fmt, mpd_get_info()->val)
|
|
|
|
#define mpd_sprintf(val) { \
|
|
|
|
if (!obj->data.i || obj->data.i > p_max_size) \
|
|
|
|
mpd_printf("%s", val); \
|
|
|
|
else \
|
|
|
|
snprintf(p, obj->data.i, "%s", mpd_get_info()->val); \
|
|
|
|
}
|
|
|
|
OBJ(mpd_title)
|
|
|
|
mpd_sprintf(title);
|
|
|
|
OBJ(mpd_artist)
|
|
|
|
mpd_sprintf(artist);
|
|
|
|
OBJ(mpd_album)
|
|
|
|
mpd_sprintf(album);
|
|
|
|
OBJ(mpd_random)
|
|
|
|
mpd_printf("%s", random);
|
|
|
|
OBJ(mpd_repeat)
|
|
|
|
mpd_printf("%s", repeat);
|
|
|
|
OBJ(mpd_track)
|
|
|
|
mpd_sprintf(track);
|
|
|
|
OBJ(mpd_name)
|
|
|
|
mpd_sprintf(name);
|
|
|
|
OBJ(mpd_file)
|
|
|
|
mpd_sprintf(file);
|
|
|
|
OBJ(mpd_vol)
|
|
|
|
mpd_printf("%d", volume);
|
|
|
|
OBJ(mpd_bitrate)
|
|
|
|
mpd_printf("%d", bitrate);
|
|
|
|
OBJ(mpd_status)
|
|
|
|
mpd_printf("%s", status);
|
2005-07-28 04:48:27 +00:00
|
|
|
OBJ(mpd_elapsed) {
|
2008-12-18 12:37:53 +00:00
|
|
|
format_media_player_time(p, p_max_size, mpd_get_info()->elapsed);
|
2005-07-28 04:48:27 +00:00
|
|
|
}
|
|
|
|
OBJ(mpd_length) {
|
2008-12-18 12:37:53 +00:00
|
|
|
format_media_player_time(p, p_max_size, mpd_get_info()->length);
|
2005-07-28 04:48:27 +00:00
|
|
|
}
|
|
|
|
OBJ(mpd_percent) {
|
2009-03-01 19:53:47 +00:00
|
|
|
percent_print(p, p_max_size, (int)(mpd_get_info()->progress * 100));
|
2005-07-28 04:48:27 +00:00
|
|
|
}
|
2005-07-20 00:30:40 +00:00
|
|
|
OBJ(mpd_bar) {
|
2008-02-20 20:30:45 +00:00
|
|
|
new_bar(p, obj->data.pair.a, obj->data.pair.b,
|
2008-12-18 12:37:53 +00:00
|
|
|
(int) (mpd_get_info()->progress * 255.0f));
|
2005-07-20 00:30:40 +00:00
|
|
|
}
|
2006-03-07 04:23:55 +00:00
|
|
|
OBJ(mpd_smart) {
|
2008-12-18 12:37:53 +00:00
|
|
|
struct mpd_s *mpd = mpd_get_info();
|
2008-09-01 22:30:54 +00:00
|
|
|
int len = obj->data.i;
|
|
|
|
if (len == 0 || len > p_max_size)
|
|
|
|
len = p_max_size;
|
|
|
|
|
2008-02-20 20:30:45 +00:00
|
|
|
memset(p, 0, p_max_size);
|
2008-12-18 12:37:53 +00:00
|
|
|
if (mpd->artist && *mpd->artist &&
|
|
|
|
mpd->title && *mpd->title) {
|
|
|
|
snprintf(p, len, "%s - %s", mpd->artist,
|
|
|
|
mpd->title);
|
|
|
|
} else if (mpd->title && *mpd->title) {
|
|
|
|
snprintf(p, len, "%s", mpd->title);
|
|
|
|
} else if (mpd->artist && *mpd->artist) {
|
|
|
|
snprintf(p, len, "%s", mpd->artist);
|
|
|
|
} else if (mpd->file && *mpd->file) {
|
|
|
|
snprintf(p, len, "%s", mpd->file);
|
2008-02-20 20:30:45 +00:00
|
|
|
} else {
|
|
|
|
*p = 0;
|
|
|
|
}
|
2006-03-07 04:23:55 +00:00
|
|
|
}
|
2008-10-08 11:44:27 +00:00
|
|
|
OBJ(if_mpd_playing) {
|
2008-12-18 12:37:53 +00:00
|
|
|
if (!mpd_get_info()->is_playing) {
|
2008-12-15 01:44:21 +00:00
|
|
|
DO_JUMP;
|
2008-10-08 11:44:27 +00:00
|
|
|
}
|
|
|
|
}
|
2008-12-18 12:37:53 +00:00
|
|
|
#undef mpd_sprintf
|
|
|
|
#undef mpd_printf
|
2005-12-30 09:44:40 +00:00
|
|
|
#endif
|
2008-02-20 20:30:45 +00:00
|
|
|
|
2009-04-28 16:02:24 +00:00
|
|
|
#ifdef XMMS2
|
|
|
|
free_xmms2();
|
|
|
|
#endif
|
|
|
|
|
2008-09-24 06:59:45 +00:00
|
|
|
#ifdef MOC
|
2008-12-22 18:31:48 +00:00
|
|
|
#define MOC_PRINT(t, a) \
|
|
|
|
snprintf(p, p_max_size, "%s", (moc.t ? moc.t : a))
|
2008-09-24 06:59:45 +00:00
|
|
|
OBJ(moc_state) {
|
2008-12-22 18:31:48 +00:00
|
|
|
MOC_PRINT(state, "??");
|
2008-09-24 06:59:45 +00:00
|
|
|
}
|
|
|
|
OBJ(moc_file) {
|
2008-12-22 18:31:48 +00:00
|
|
|
MOC_PRINT(file, "no file");
|
2008-09-24 06:59:45 +00:00
|
|
|
}
|
|
|
|
OBJ(moc_title) {
|
2008-12-22 18:31:48 +00:00
|
|
|
MOC_PRINT(title, "no title");
|
2008-09-24 06:59:45 +00:00
|
|
|
}
|
|
|
|
OBJ(moc_artist) {
|
2008-12-22 18:31:48 +00:00
|
|
|
MOC_PRINT(artist, "no artist");
|
2008-09-24 06:59:45 +00:00
|
|
|
}
|
|
|
|
OBJ(moc_song) {
|
2008-12-22 18:31:48 +00:00
|
|
|
MOC_PRINT(song, "no song");
|
2008-09-24 06:59:45 +00:00
|
|
|
}
|
|
|
|
OBJ(moc_album) {
|
2008-12-22 18:31:48 +00:00
|
|
|
MOC_PRINT(album, "no album");
|
2008-09-24 06:59:45 +00:00
|
|
|
}
|
|
|
|
OBJ(moc_totaltime) {
|
2008-12-22 18:31:48 +00:00
|
|
|
MOC_PRINT(totaltime, "0:00");
|
2008-09-24 06:59:45 +00:00
|
|
|
}
|
|
|
|
OBJ(moc_timeleft) {
|
2008-12-22 18:31:48 +00:00
|
|
|
MOC_PRINT(timeleft, "0:00");
|
2008-09-24 06:59:45 +00:00
|
|
|
}
|
|
|
|
OBJ(moc_curtime) {
|
2008-12-22 18:31:48 +00:00
|
|
|
MOC_PRINT(curtime, "0:00");
|
2008-09-24 06:59:45 +00:00
|
|
|
}
|
|
|
|
OBJ(moc_bitrate) {
|
2008-12-22 18:31:48 +00:00
|
|
|
MOC_PRINT(bitrate, "0Kbps");
|
2008-09-24 06:59:45 +00:00
|
|
|
}
|
|
|
|
OBJ(moc_rate) {
|
2008-12-22 18:31:48 +00:00
|
|
|
MOC_PRINT(rate, "0KHz");
|
2008-09-24 06:59:45 +00:00
|
|
|
}
|
2008-12-22 18:31:48 +00:00
|
|
|
#undef MOC_PRINT
|
2008-09-24 06:59:45 +00:00
|
|
|
#endif /* MOC */
|
2006-03-25 21:21:07 +00:00
|
|
|
#ifdef XMMS2
|
|
|
|
OBJ(xmms2_artist) {
|
|
|
|
snprintf(p, p_max_size, "%s", cur->xmms2.artist);
|
|
|
|
}
|
|
|
|
OBJ(xmms2_album) {
|
|
|
|
snprintf(p, p_max_size, "%s", cur->xmms2.album);
|
|
|
|
}
|
2006-04-16 03:49:49 +00:00
|
|
|
OBJ(xmms2_title) {
|
|
|
|
snprintf(p, p_max_size, "%s", cur->xmms2.title);
|
|
|
|
}
|
|
|
|
OBJ(xmms2_genre) {
|
|
|
|
snprintf(p, p_max_size, "%s", cur->xmms2.genre);
|
|
|
|
}
|
|
|
|
OBJ(xmms2_comment) {
|
|
|
|
snprintf(p, p_max_size, "%s", cur->xmms2.comment);
|
|
|
|
}
|
|
|
|
OBJ(xmms2_url) {
|
|
|
|
snprintf(p, p_max_size, "%s", cur->xmms2.url);
|
|
|
|
}
|
|
|
|
OBJ(xmms2_status) {
|
2006-03-25 21:21:07 +00:00
|
|
|
snprintf(p, p_max_size, "%s", cur->xmms2.status);
|
|
|
|
}
|
2008-02-20 20:30:45 +00:00
|
|
|
OBJ(xmms2_date) {
|
|
|
|
snprintf(p, p_max_size, "%s", cur->xmms2.date);
|
2006-04-16 03:49:49 +00:00
|
|
|
}
|
|
|
|
OBJ(xmms2_tracknr) {
|
2008-02-20 20:30:45 +00:00
|
|
|
if (cur->xmms2.tracknr != -1) {
|
|
|
|
snprintf(p, p_max_size, "%i", cur->xmms2.tracknr);
|
|
|
|
}
|
2006-04-16 03:49:49 +00:00
|
|
|
}
|
|
|
|
OBJ(xmms2_bitrate) {
|
|
|
|
snprintf(p, p_max_size, "%i", cur->xmms2.bitrate);
|
|
|
|
}
|
2008-02-20 20:30:45 +00:00
|
|
|
OBJ(xmms2_id) {
|
2006-04-16 03:49:49 +00:00
|
|
|
snprintf(p, p_max_size, "%u", cur->xmms2.id);
|
|
|
|
}
|
2008-02-20 20:30:45 +00:00
|
|
|
OBJ(xmms2_size) {
|
2006-04-16 03:49:49 +00:00
|
|
|
snprintf(p, p_max_size, "%2.1f", cur->xmms2.size);
|
|
|
|
}
|
2006-03-25 21:21:07 +00:00
|
|
|
OBJ(xmms2_elapsed) {
|
2008-02-20 20:30:45 +00:00
|
|
|
snprintf(p, p_max_size, "%02d:%02d", cur->xmms2.elapsed / 60000,
|
|
|
|
(cur->xmms2.elapsed / 1000) % 60);
|
2006-03-25 21:21:07 +00:00
|
|
|
}
|
2006-04-16 03:49:49 +00:00
|
|
|
OBJ(xmms2_duration) {
|
|
|
|
snprintf(p, p_max_size, "%02d:%02d",
|
2008-02-20 20:30:45 +00:00
|
|
|
cur->xmms2.duration / 60000,
|
|
|
|
(cur->xmms2.duration / 1000) % 60);
|
2006-03-25 21:21:07 +00:00
|
|
|
}
|
|
|
|
OBJ(xmms2_percent) {
|
2008-02-20 20:30:45 +00:00
|
|
|
snprintf(p, p_max_size, "%2.0f", cur->xmms2.progress * 100);
|
2006-03-25 21:21:07 +00:00
|
|
|
}
|
|
|
|
OBJ(xmms2_bar) {
|
2008-02-20 20:30:45 +00:00
|
|
|
new_bar(p, obj->data.pair.a, obj->data.pair.b,
|
|
|
|
(int) (cur->xmms2.progress * 255.0f));
|
2006-03-25 21:21:07 +00:00
|
|
|
}
|
2008-03-18 00:23:16 +00:00
|
|
|
OBJ(xmms2_playlist) {
|
|
|
|
snprintf(p, p_max_size, "%s", cur->xmms2.playlist);
|
|
|
|
}
|
|
|
|
OBJ(xmms2_timesplayed) {
|
|
|
|
snprintf(p, p_max_size, "%i", cur->xmms2.timesplayed);
|
|
|
|
}
|
2006-04-16 03:49:49 +00:00
|
|
|
OBJ(xmms2_smart) {
|
2008-02-20 20:30:45 +00:00
|
|
|
if (strlen(cur->xmms2.title) < 2
|
|
|
|
&& strlen(cur->xmms2.title) < 2) {
|
2006-04-16 03:49:49 +00:00
|
|
|
snprintf(p, p_max_size, "%s", cur->xmms2.url);
|
|
|
|
} else {
|
2008-02-20 20:30:45 +00:00
|
|
|
snprintf(p, p_max_size, "%s - %s", cur->xmms2.artist,
|
|
|
|
cur->xmms2.title);
|
2006-04-16 03:49:49 +00:00
|
|
|
}
|
|
|
|
}
|
2008-12-07 07:22:05 +00:00
|
|
|
OBJ(if_xmms2_connected) {
|
2009-04-28 16:02:24 +00:00
|
|
|
if (cur->xmms2.conn_state != 1) {
|
2008-12-15 01:44:21 +00:00
|
|
|
DO_JUMP;
|
2008-12-07 07:22:05 +00:00
|
|
|
}
|
|
|
|
}
|
2006-03-25 21:21:07 +00:00
|
|
|
#endif
|
2006-11-03 20:54:52 +00:00
|
|
|
#ifdef AUDACIOUS
|
|
|
|
OBJ(audacious_status) {
|
2008-02-20 20:30:45 +00:00
|
|
|
snprintf(p, p_max_size, "%s",
|
|
|
|
cur->audacious.items[AUDACIOUS_STATUS]);
|
2006-01-08 08:02:37 +00:00
|
|
|
}
|
2008-02-20 20:30:45 +00:00
|
|
|
OBJ(audacious_title) {
|
|
|
|
snprintf(p, cur->audacious.max_title_len > 0
|
|
|
|
? cur->audacious.max_title_len : p_max_size, "%s",
|
|
|
|
cur->audacious.items[AUDACIOUS_TITLE]);
|
2006-01-07 07:01:22 +00:00
|
|
|
}
|
2008-02-20 20:30:45 +00:00
|
|
|
OBJ(audacious_length) {
|
|
|
|
snprintf(p, p_max_size, "%s",
|
|
|
|
cur->audacious.items[AUDACIOUS_LENGTH]);
|
2006-01-07 07:01:22 +00:00
|
|
|
}
|
2008-02-20 20:30:45 +00:00
|
|
|
OBJ(audacious_length_seconds) {
|
|
|
|
snprintf(p, p_max_size, "%s",
|
|
|
|
cur->audacious.items[AUDACIOUS_LENGTH_SECONDS]);
|
2006-01-07 07:01:22 +00:00
|
|
|
}
|
2008-02-20 20:30:45 +00:00
|
|
|
OBJ(audacious_position) {
|
|
|
|
snprintf(p, p_max_size, "%s",
|
|
|
|
cur->audacious.items[AUDACIOUS_POSITION]);
|
2006-01-07 07:01:22 +00:00
|
|
|
}
|
2008-02-20 20:30:45 +00:00
|
|
|
OBJ(audacious_position_seconds) {
|
|
|
|
snprintf(p, p_max_size, "%s",
|
|
|
|
cur->audacious.items[AUDACIOUS_POSITION_SECONDS]);
|
2006-01-07 07:01:22 +00:00
|
|
|
}
|
2008-02-20 20:30:45 +00:00
|
|
|
OBJ(audacious_bitrate) {
|
|
|
|
snprintf(p, p_max_size, "%s",
|
|
|
|
cur->audacious.items[AUDACIOUS_BITRATE]);
|
2006-01-07 07:01:22 +00:00
|
|
|
}
|
2008-02-20 20:30:45 +00:00
|
|
|
OBJ(audacious_frequency) {
|
|
|
|
snprintf(p, p_max_size, "%s",
|
|
|
|
cur->audacious.items[AUDACIOUS_FREQUENCY]);
|
2006-01-07 07:01:22 +00:00
|
|
|
}
|
2008-02-20 20:30:45 +00:00
|
|
|
OBJ(audacious_channels) {
|
|
|
|
snprintf(p, p_max_size, "%s",
|
|
|
|
cur->audacious.items[AUDACIOUS_CHANNELS]);
|
2006-01-07 07:01:22 +00:00
|
|
|
}
|
2008-02-20 20:30:45 +00:00
|
|
|
OBJ(audacious_filename) {
|
|
|
|
snprintf(p, p_max_size, "%s",
|
|
|
|
cur->audacious.items[AUDACIOUS_FILENAME]);
|
2006-01-07 07:01:22 +00:00
|
|
|
}
|
2008-02-20 20:30:45 +00:00
|
|
|
OBJ(audacious_playlist_length) {
|
|
|
|
snprintf(p, p_max_size, "%s",
|
|
|
|
cur->audacious.items[AUDACIOUS_PLAYLIST_LENGTH]);
|
2006-01-07 07:01:22 +00:00
|
|
|
}
|
2008-02-20 20:30:45 +00:00
|
|
|
OBJ(audacious_playlist_position) {
|
|
|
|
snprintf(p, p_max_size, "%s",
|
|
|
|
cur->audacious.items[AUDACIOUS_PLAYLIST_POSITION]);
|
2006-01-08 08:02:37 +00:00
|
|
|
}
|
2008-12-07 07:38:06 +00:00
|
|
|
OBJ(audacious_main_volume) {
|
|
|
|
snprintf(p, p_max_size, "%s",
|
|
|
|
cur->audacious.items[AUDACIOUS_MAIN_VOLUME]);
|
|
|
|
}
|
2008-02-20 20:30:45 +00:00
|
|
|
OBJ(audacious_bar) {
|
|
|
|
double progress;
|
|
|
|
|
|
|
|
progress =
|
|
|
|
atof(cur->audacious.items[AUDACIOUS_POSITION_SECONDS]) /
|
|
|
|
atof(cur->audacious.items[AUDACIOUS_LENGTH_SECONDS]);
|
|
|
|
new_bar(p, obj->a, obj->b, (int) (progress * 255.0f));
|
2006-11-03 20:54:52 +00:00
|
|
|
}
|
|
|
|
#endif
|
2008-02-20 20:30:45 +00:00
|
|
|
|
2005-12-30 09:44:40 +00:00
|
|
|
#ifdef BMPX
|
|
|
|
OBJ(bmpx_title) {
|
|
|
|
snprintf(p, p_max_size, "%s", cur->bmpx.title);
|
|
|
|
}
|
|
|
|
OBJ(bmpx_artist) {
|
|
|
|
snprintf(p, p_max_size, "%s", cur->bmpx.artist);
|
|
|
|
}
|
|
|
|
OBJ(bmpx_album) {
|
|
|
|
snprintf(p, p_max_size, "%s", cur->bmpx.album);
|
|
|
|
}
|
|
|
|
OBJ(bmpx_uri) {
|
|
|
|
snprintf(p, p_max_size, "%s", cur->bmpx.uri);
|
|
|
|
}
|
|
|
|
OBJ(bmpx_track) {
|
2008-02-20 20:30:45 +00:00
|
|
|
snprintf(p, p_max_size, "%i", cur->bmpx.track);
|
2005-12-30 09:44:40 +00:00
|
|
|
}
|
|
|
|
OBJ(bmpx_bitrate) {
|
|
|
|
snprintf(p, p_max_size, "%i", cur->bmpx.bitrate);
|
|
|
|
}
|
2005-07-20 00:30:40 +00:00
|
|
|
#endif
|
2009-02-08 16:19:10 +00:00
|
|
|
/* we have three different types of top (top, top_mem
|
|
|
|
* and top_time). To avoid having almost-same code three
|
|
|
|
* times, we have this special handler. */
|
|
|
|
break;
|
|
|
|
case OBJ_top:
|
2009-02-08 17:13:54 +00:00
|
|
|
if (!needed) needed = cur->cpu;
|
2009-02-08 16:19:10 +00:00
|
|
|
case OBJ_top_mem:
|
2009-02-08 17:13:54 +00:00
|
|
|
if (!needed) needed = cur->memu;
|
2009-02-08 16:19:10 +00:00
|
|
|
case OBJ_top_time:
|
2009-02-08 17:13:54 +00:00
|
|
|
if (!needed) needed = cur->time;
|
2008-02-20 10:01:31 +00:00
|
|
|
|
2009-02-08 16:19:10 +00:00
|
|
|
{
|
2009-02-07 14:01:50 +00:00
|
|
|
char *timeval;
|
|
|
|
|
|
|
|
switch (obj->data.top.type) {
|
|
|
|
case TOP_NAME:
|
2009-05-07 23:49:32 +00:00
|
|
|
snprintf(p, top_name_width + 1, "%-*s", top_name_width,
|
2009-02-08 16:19:10 +00:00
|
|
|
needed[obj->data.top.num]->name);
|
2009-02-07 14:01:50 +00:00
|
|
|
break;
|
|
|
|
case TOP_CPU:
|
|
|
|
snprintf(p, 7, "%6.2f",
|
2009-02-08 16:19:10 +00:00
|
|
|
needed[obj->data.top.num]->amount);
|
2009-02-07 14:01:50 +00:00
|
|
|
break;
|
|
|
|
case TOP_PID:
|
|
|
|
snprintf(p, 6, "%5i",
|
2009-02-08 16:19:10 +00:00
|
|
|
needed[obj->data.top.num]->pid);
|
2009-02-07 14:01:50 +00:00
|
|
|
break;
|
|
|
|
case TOP_MEM:
|
|
|
|
snprintf(p, 7, "%6.2f",
|
2009-02-08 16:19:10 +00:00
|
|
|
needed[obj->data.top.num]->totalmem);
|
2009-02-07 14:01:50 +00:00
|
|
|
break;
|
|
|
|
case TOP_TIME:
|
|
|
|
timeval = format_time(
|
2009-02-08 16:19:10 +00:00
|
|
|
needed[obj->data.top.num]->total_cpu_time, 9);
|
2009-02-07 14:01:50 +00:00
|
|
|
snprintf(p, 10, "%9s", timeval);
|
|
|
|
free(timeval);
|
|
|
|
break;
|
|
|
|
case TOP_MEM_RES:
|
2009-02-08 16:19:10 +00:00
|
|
|
human_readable(needed[obj->data.top.num]->rss,
|
2009-02-07 14:01:50 +00:00
|
|
|
p, 255);
|
|
|
|
break;
|
|
|
|
case TOP_MEM_VSIZE:
|
2009-02-08 16:19:10 +00:00
|
|
|
human_readable(needed[obj->data.top.num]->vsize,
|
2009-02-07 14:01:50 +00:00
|
|
|
p, 255);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2009-01-05 00:27:07 +00:00
|
|
|
OBJ(tail)
|
|
|
|
print_tail_object(obj, p, p_max_size);
|
|
|
|
OBJ(head)
|
|
|
|
print_head_object(obj, p, p_max_size);
|
2008-06-21 20:37:58 +00:00
|
|
|
OBJ(lines) {
|
|
|
|
FILE *fp = fopen(obj->data.s,"r");
|
2008-09-01 23:08:09 +00:00
|
|
|
|
2008-06-21 20:37:58 +00:00
|
|
|
if(fp != NULL) {
|
2009-01-05 00:27:07 +00:00
|
|
|
/* FIXME: use something more general (see also tail.c, head.c */
|
|
|
|
#define BUFSZ 0x1000
|
2008-06-21 20:37:58 +00:00
|
|
|
char buf[BUFSZ];
|
|
|
|
int j, lines;
|
2008-09-01 23:08:09 +00:00
|
|
|
|
2008-06-21 20:37:58 +00:00
|
|
|
lines = 0;
|
|
|
|
while(fgets(buf, BUFSZ, fp) != NULL){
|
|
|
|
for(j = 0; buf[j] != 0; j++) {
|
|
|
|
if(buf[j] == '\n') {
|
|
|
|
lines++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
sprintf(p, "%d", lines);
|
|
|
|
fclose(fp);
|
|
|
|
} else {
|
|
|
|
sprintf(p, "File Unreadable");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
OBJ(words) {
|
|
|
|
FILE *fp = fopen(obj->data.s,"r");
|
2008-09-01 23:08:09 +00:00
|
|
|
|
2008-06-21 20:37:58 +00:00
|
|
|
if(fp != NULL) {
|
|
|
|
char buf[BUFSZ];
|
|
|
|
int j, words;
|
|
|
|
char inword = FALSE;
|
2008-09-01 23:08:09 +00:00
|
|
|
|
2008-06-21 20:37:58 +00:00
|
|
|
words = 0;
|
|
|
|
while(fgets(buf, BUFSZ, fp) != NULL){
|
|
|
|
for(j = 0; buf[j] != 0; j++) {
|
|
|
|
if(!isspace(buf[j])) {
|
|
|
|
if(inword == FALSE) {
|
|
|
|
words++;
|
|
|
|
inword = TRUE;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
inword = FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
sprintf(p, "%d", words);
|
|
|
|
fclose(fp);
|
|
|
|
} else {
|
|
|
|
sprintf(p, "File Unreadable");
|
|
|
|
}
|
|
|
|
}
|
2005-10-31 05:17:06 +00:00
|
|
|
#ifdef TCP_PORT_MONITOR
|
2008-02-20 20:30:45 +00:00
|
|
|
OBJ(tcp_portmon) {
|
2008-12-09 13:44:14 +00:00
|
|
|
tcp_portmon_action(p, p_max_size,
|
|
|
|
&obj->data.tcp_port_monitor);
|
2005-10-31 05:17:06 +00:00
|
|
|
}
|
|
|
|
#endif
|
2005-07-20 00:30:40 +00:00
|
|
|
|
2006-05-13 20:14:26 +00:00
|
|
|
#ifdef HAVE_ICONV
|
2008-02-20 20:30:45 +00:00
|
|
|
OBJ(iconv_start) {
|
2006-05-13 19:51:26 +00:00
|
|
|
iconv_converting = 1;
|
|
|
|
iconv_selected = obj->a;
|
|
|
|
}
|
2008-02-20 20:30:45 +00:00
|
|
|
OBJ(iconv_stop) {
|
2006-05-13 19:51:26 +00:00
|
|
|
iconv_converting = 0;
|
|
|
|
iconv_selected = 0;
|
|
|
|
}
|
|
|
|
#endif
|
2008-02-20 20:30:45 +00:00
|
|
|
|
|
|
|
OBJ(entropy_avail) {
|
|
|
|
snprintf(p, p_max_size, "%d", cur->entropy.entropy_avail);
|
2006-11-30 20:46:34 +00:00
|
|
|
}
|
2008-02-20 20:30:45 +00:00
|
|
|
OBJ(entropy_poolsize) {
|
2006-11-30 20:46:34 +00:00
|
|
|
snprintf(p, p_max_size, "%d", cur->entropy.poolsize);
|
|
|
|
}
|
2008-02-20 20:30:45 +00:00
|
|
|
OBJ(entropy_bar) {
|
2006-11-30 20:46:34 +00:00
|
|
|
double entropy_perc;
|
|
|
|
|
2008-02-20 20:30:45 +00:00
|
|
|
entropy_perc = (double) cur->entropy.entropy_avail /
|
|
|
|
(double) cur->entropy.poolsize;
|
|
|
|
new_bar(p, obj->a, obj->b, (int) (entropy_perc * 255.0f));
|
|
|
|
}
|
2009-01-03 23:25:15 +00:00
|
|
|
#ifdef IBM
|
2008-03-18 00:23:16 +00:00
|
|
|
OBJ(smapi) {
|
|
|
|
char *s;
|
|
|
|
if(obj->data.s) {
|
|
|
|
s = smapi_get_val(obj->data.s);
|
|
|
|
snprintf(p, p_max_size, "%s", s);
|
|
|
|
free(s);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
OBJ(if_smapi_bat_installed) {
|
|
|
|
int idx;
|
|
|
|
if(obj->data.ifblock.s && sscanf(obj->data.ifblock.s, "%i", &idx) == 1) {
|
|
|
|
if(!smapi_bat_installed(idx)) {
|
2008-12-15 01:44:21 +00:00
|
|
|
DO_JUMP;
|
|
|
|
}
|
2008-03-18 00:23:16 +00:00
|
|
|
} else
|
|
|
|
ERR("argument to if_smapi_bat_installed must be an integer");
|
|
|
|
}
|
|
|
|
OBJ(smapi_bat_perc) {
|
|
|
|
int idx, val;
|
|
|
|
if(obj->data.s && sscanf(obj->data.s, "%i", &idx) == 1) {
|
|
|
|
val = smapi_bat_installed(idx) ?
|
|
|
|
smapi_get_bat_int(idx, "remaining_percent") : 0;
|
2009-03-01 19:53:47 +00:00
|
|
|
percent_print(p, p_max_size, val);
|
2008-03-18 00:23:16 +00:00
|
|
|
} else
|
|
|
|
ERR("argument to smapi_bat_perc must be an integer");
|
|
|
|
}
|
2008-06-25 10:08:27 +00:00
|
|
|
OBJ(smapi_bat_temp) {
|
|
|
|
int idx, val;
|
|
|
|
if(obj->data.s && sscanf(obj->data.s, "%i", &idx) == 1) {
|
|
|
|
val = smapi_bat_installed(idx) ?
|
|
|
|
smapi_get_bat_int(idx, "temperature") : 0;
|
2008-12-07 19:08:29 +00:00
|
|
|
/* temperature is in milli degree celsius */
|
|
|
|
temp_print(p, p_max_size, val / 1000, TEMP_CELSIUS);
|
2008-06-25 10:08:27 +00:00
|
|
|
} else
|
|
|
|
ERR("argument to smapi_bat_temp must be an integer");
|
|
|
|
}
|
|
|
|
OBJ(smapi_bat_power) {
|
|
|
|
int idx, val;
|
|
|
|
if(obj->data.s && sscanf(obj->data.s, "%i", &idx) == 1) {
|
|
|
|
val = smapi_bat_installed(idx) ?
|
|
|
|
smapi_get_bat_int(idx, "power_now") : 0;
|
|
|
|
/* power_now is in mW, set to W with one digit precision */
|
|
|
|
snprintf(p, p_max_size, "%.1f", ((double)val / 1000));
|
|
|
|
} else
|
|
|
|
ERR("argument to smapi_bat_power must be an integer");
|
|
|
|
}
|
2008-03-18 00:23:16 +00:00
|
|
|
OBJ(smapi_bat_bar) {
|
|
|
|
if(obj->data.i >= 0 && smapi_bat_installed(obj->data.i))
|
|
|
|
new_bar(p, obj->a, obj->b, (int)
|
|
|
|
(255 * smapi_get_bat_int(obj->data.i, "remaining_percent") / 100));
|
|
|
|
else
|
|
|
|
new_bar(p, obj->a, obj->b, 0);
|
|
|
|
}
|
2009-01-03 23:25:15 +00:00
|
|
|
#endif /* IBM */
|
2008-06-21 20:37:58 +00:00
|
|
|
OBJ(scroll) {
|
|
|
|
unsigned int j;
|
2008-12-22 17:36:44 +00:00
|
|
|
char *tmp, buf[max_user_text];
|
|
|
|
generate_text_internal(buf, max_user_text,
|
|
|
|
*obj->sub, cur);
|
2008-12-15 01:44:21 +00:00
|
|
|
|
2008-12-22 17:36:44 +00:00
|
|
|
if (strlen(buf) <= obj->data.scroll.show) {
|
|
|
|
snprintf(p, p_max_size, "%s", buf);
|
2008-09-24 06:59:45 +00:00
|
|
|
break;
|
|
|
|
}
|
2008-06-21 20:37:58 +00:00
|
|
|
#define LINESEPARATOR '|'
|
|
|
|
//place all the lines behind each other with LINESEPARATOR between them
|
2008-12-22 17:36:44 +00:00
|
|
|
for(j = 0; buf[j] != 0; j++) {
|
|
|
|
if(buf[j]=='\n') {
|
|
|
|
buf[j]=LINESEPARATOR;
|
2008-06-21 20:37:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
//scroll the output obj->data.scroll.start places by copying that many chars from
|
|
|
|
//the front of the string to tmp, scrolling the rest to the front and placing tmp
|
|
|
|
//at the back of the string
|
|
|
|
tmp = calloc(obj->data.scroll.start + 1, sizeof(char));
|
2008-12-22 17:36:44 +00:00
|
|
|
strncpy(tmp, buf, obj->data.scroll.start); tmp[obj->data.scroll.start] = 0;
|
|
|
|
for(j = obj->data.scroll.start; buf[j] != 0; j++){
|
|
|
|
buf[j - obj->data.scroll.start] = buf[j];
|
2008-06-21 20:37:58 +00:00
|
|
|
}
|
2008-12-22 17:36:44 +00:00
|
|
|
strcpy(&buf[j - obj->data.scroll.start], tmp);
|
2008-06-21 20:37:58 +00:00
|
|
|
free(tmp);
|
|
|
|
//only show the requested number of chars
|
|
|
|
if(obj->data.scroll.show < j) {
|
2008-12-22 17:36:44 +00:00
|
|
|
buf[obj->data.scroll.show] = 0;
|
2008-06-21 20:37:58 +00:00
|
|
|
}
|
|
|
|
//next time, scroll a place more or reset scrolling if we are at the end
|
2008-09-24 06:59:45 +00:00
|
|
|
obj->data.scroll.start += obj->data.scroll.step;
|
|
|
|
if(obj->data.scroll.start >= j){
|
2008-06-21 20:37:58 +00:00
|
|
|
obj->data.scroll.start = 0;
|
|
|
|
}
|
2008-12-22 17:36:44 +00:00
|
|
|
snprintf(p, p_max_size, "%s", buf);
|
2008-06-21 20:37:58 +00:00
|
|
|
}
|
2009-04-30 19:05:59 +00:00
|
|
|
OBJ(combine) {
|
|
|
|
char buf[2][max_user_text];
|
|
|
|
unsigned int i, j;
|
|
|
|
unsigned int longest=0;
|
|
|
|
unsigned int nextstart;
|
|
|
|
unsigned int nr_rows[2];
|
|
|
|
struct llrows {
|
|
|
|
char* row;
|
|
|
|
struct llrows* next;
|
|
|
|
};
|
|
|
|
struct llrows *ll_rows[2], *current[2];
|
|
|
|
struct text_object * objsub = obj->sub;
|
|
|
|
|
|
|
|
p[0]=0;
|
|
|
|
for(i=0; i<2; i++) {
|
|
|
|
nr_rows[i] = 1;
|
|
|
|
nextstart = 0;
|
|
|
|
ll_rows[i] = malloc(sizeof(struct llrows));
|
|
|
|
current[i] = ll_rows[i];
|
|
|
|
for(j=0; j<i; j++) objsub = objsub->sub;
|
|
|
|
generate_text_internal(buf[i], max_user_text, *objsub, cur);
|
|
|
|
for(j=0; buf[i][j] != 0; j++) {
|
|
|
|
if(buf[i][j] == '\t') buf[i][j] = ' ';
|
|
|
|
if(buf[i][j] == '\n') {
|
|
|
|
buf[i][j] = 0;
|
|
|
|
current[i]->row = strdup(buf[i]+nextstart);
|
|
|
|
if(i==0 && strlen(current[i]->row) > longest) longest = strlen(current[i]->row);
|
|
|
|
current[i]->next = malloc(sizeof(struct llrows));
|
|
|
|
current[i] = current[i]->next;
|
|
|
|
nextstart = j + 1;
|
|
|
|
nr_rows[i]++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
current[i]->row = strdup(buf[i]+nextstart);
|
|
|
|
if(i==0 && strlen(current[i]->row) > longest) longest = strlen(current[i]->row);
|
|
|
|
current[i]->next = NULL;
|
|
|
|
current[i] = ll_rows[i];
|
|
|
|
}
|
|
|
|
for(j=0; j < (nr_rows[0] > nr_rows[1] ? nr_rows[0] : nr_rows[1] ); j++) {
|
|
|
|
if(current[0]) {
|
|
|
|
strcat(p, current[0]->row);
|
|
|
|
i=strlen(current[0]->row);
|
|
|
|
}else i = 0;
|
|
|
|
while(i < longest) {
|
|
|
|
strcat(p, " ");
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
if(current[1]) {
|
|
|
|
strcat(p, obj->data.combine.seperation);
|
|
|
|
strcat(p, current[1]->row);
|
|
|
|
}
|
|
|
|
strcat(p, "\n");
|
|
|
|
for(i=0; i<2; i++) if(current[i]) current[i]=current[i]->next;
|
|
|
|
}
|
|
|
|
for(i=0; i<2; i++) {
|
|
|
|
while(ll_rows[i] != NULL) {
|
|
|
|
current[i]=ll_rows[i];
|
|
|
|
free(current[i]->row);
|
|
|
|
ll_rows[i]=current[i]->next;
|
|
|
|
free(current[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-06-03 20:46:15 +00:00
|
|
|
#ifdef NVIDIA
|
|
|
|
OBJ(nvidia) {
|
2008-08-03 13:27:00 +00:00
|
|
|
int value = get_nvidia_value(obj->data.nvidia.type, display);
|
|
|
|
if(value == -1)
|
|
|
|
snprintf(p, p_max_size, "N/A");
|
2008-12-07 19:08:29 +00:00
|
|
|
else if (obj->data.nvidia.type == NV_TEMP)
|
|
|
|
temp_print(p, p_max_size, (double)value, TEMP_CELSIUS);
|
2008-08-03 13:27:00 +00:00
|
|
|
else if (obj->data.nvidia.print_as_float &&
|
|
|
|
value > 0 && value < 100)
|
|
|
|
snprintf(p, p_max_size, "%.1f", (float)value);
|
2008-06-15 18:38:33 +00:00
|
|
|
else
|
2008-08-03 13:27:00 +00:00
|
|
|
snprintf(p, p_max_size, "%d", value);
|
2008-06-03 20:46:15 +00:00
|
|
|
}
|
|
|
|
#endif /* NVIDIA */
|
2006-05-13 19:51:26 +00:00
|
|
|
|
2005-07-20 00:30:40 +00:00
|
|
|
break;
|
|
|
|
}
|
2008-12-15 01:44:21 +00:00
|
|
|
#undef DO_JUMP
|
|
|
|
|
2005-07-20 00:30:40 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
unsigned int a = strlen(p);
|
2006-05-13 19:51:26 +00:00
|
|
|
|
2006-05-13 20:14:26 +00:00
|
|
|
#ifdef HAVE_ICONV
|
2008-02-20 20:30:45 +00:00
|
|
|
if (a > 0 && iconv_converting && iconv_selected > 0
|
|
|
|
&& (iconv_cd[iconv_selected - 1] != (iconv_t) (-1))) {
|
2006-05-13 19:51:26 +00:00
|
|
|
int bytes;
|
|
|
|
size_t dummy1, dummy2;
|
|
|
|
char *ptr = buff_in;
|
|
|
|
char *outptr = p;
|
|
|
|
|
|
|
|
dummy1 = dummy2 = a;
|
2008-02-20 20:30:45 +00:00
|
|
|
|
2008-03-19 22:28:23 +00:00
|
|
|
strncpy(buff_in, p, p_max_size);
|
2006-05-13 19:51:26 +00:00
|
|
|
|
|
|
|
iconv(*iconv_cd[iconv_selected - 1], NULL, NULL, NULL, NULL);
|
|
|
|
while (dummy1 > 0) {
|
2008-02-20 20:30:45 +00:00
|
|
|
bytes = iconv(*iconv_cd[iconv_selected - 1], &ptr, &dummy1,
|
2008-03-18 00:23:16 +00:00
|
|
|
&outptr, &dummy2);
|
2006-05-13 19:51:26 +00:00
|
|
|
if (bytes == -1) {
|
|
|
|
ERR("Iconv codeset conversion failed");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-02-20 20:30:45 +00:00
|
|
|
/* It is nessecary when we are converting from multibyte to
|
|
|
|
* singlebyte codepage */
|
2006-05-13 19:51:26 +00:00
|
|
|
a = outptr - p;
|
|
|
|
}
|
2008-03-19 22:28:23 +00:00
|
|
|
#endif /* HAVE_ICONV */
|
2005-07-20 00:30:40 +00:00
|
|
|
p += a;
|
2005-12-10 14:15:38 +00:00
|
|
|
p_max_size -= a;
|
2005-07-20 00:30:40 +00:00
|
|
|
}
|
|
|
|
}
|
2005-12-10 14:15:38 +00:00
|
|
|
}
|
|
|
|
|
2008-09-12 03:01:33 +00:00
|
|
|
double current_update_time, next_update_time, last_update_time;
|
2005-12-10 14:15:38 +00:00
|
|
|
|
2008-03-29 02:01:03 +00:00
|
|
|
static void generate_text(void)
|
2005-12-10 14:15:38 +00:00
|
|
|
{
|
|
|
|
struct information *cur = &info;
|
|
|
|
char *p;
|
|
|
|
|
|
|
|
special_count = 0;
|
|
|
|
|
|
|
|
/* update info */
|
|
|
|
|
|
|
|
current_update_time = get_time();
|
|
|
|
|
2008-03-29 02:01:03 +00:00
|
|
|
update_stuff();
|
2005-12-10 14:15:38 +00:00
|
|
|
|
2005-12-15 03:05:16 +00:00
|
|
|
/* add things to the buffer */
|
|
|
|
|
2005-12-10 14:15:38 +00:00
|
|
|
/* generate text */
|
|
|
|
|
|
|
|
p = text_buffer;
|
|
|
|
|
2008-12-15 01:44:21 +00:00
|
|
|
generate_text_internal(p, max_user_text, global_root_object, cur);
|
2005-07-20 00:30:40 +00:00
|
|
|
|
|
|
|
if (stuff_in_upper_case) {
|
2008-03-29 09:58:09 +00:00
|
|
|
char *tmp_p;
|
2005-07-20 00:30:40 +00:00
|
|
|
|
2008-03-29 09:58:09 +00:00
|
|
|
tmp_p = text_buffer;
|
|
|
|
while (*tmp_p) {
|
|
|
|
*tmp_p = toupper(*tmp_p);
|
|
|
|
tmp_p++;
|
2005-07-20 00:30:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-09-12 03:01:33 +00:00
|
|
|
next_update_time += update_interval;
|
|
|
|
if (next_update_time < get_time()) {
|
|
|
|
next_update_time = get_time() + update_interval;
|
|
|
|
} else if (next_update_time > get_time() + update_interval) {
|
|
|
|
next_update_time = get_time() + update_interval;
|
|
|
|
}
|
2005-07-20 00:30:40 +00:00
|
|
|
last_update_time = current_update_time;
|
|
|
|
total_updates++;
|
2008-02-20 20:30:45 +00:00
|
|
|
// free(p);
|
2005-07-20 00:30:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline int get_string_width(const char *s)
|
|
|
|
{
|
2005-08-08 01:18:52 +00:00
|
|
|
#ifdef X11
|
2009-02-21 23:37:15 +00:00
|
|
|
if (output_methods & TO_X) {
|
2009-02-14 12:03:11 +00:00
|
|
|
return *s ? calc_text_width(s, strlen(s)) : 0;
|
|
|
|
}
|
2005-08-08 01:18:52 +00:00
|
|
|
#endif /* X11 */
|
2009-02-14 12:03:11 +00:00
|
|
|
return strlen(s);
|
2005-07-20 00:30:40 +00:00
|
|
|
}
|
|
|
|
|
2005-08-27 04:55:48 +00:00
|
|
|
static inline int get_string_width_special(char *s)
|
|
|
|
{
|
2009-02-21 23:37:15 +00:00
|
|
|
#ifdef X11
|
2009-02-18 04:45:06 +00:00
|
|
|
char *p, *final;
|
|
|
|
int idx = 1;
|
|
|
|
int width = 0;
|
2009-05-05 23:36:12 +00:00
|
|
|
long i;
|
2009-02-21 23:37:15 +00:00
|
|
|
|
|
|
|
if ((output_methods & TO_X) == 0) {
|
2009-02-14 12:03:11 +00:00
|
|
|
#endif
|
|
|
|
return (s) ? strlen(s) : 0;
|
|
|
|
#ifdef X11
|
|
|
|
}
|
2008-03-29 06:24:04 +00:00
|
|
|
|
2005-08-27 04:55:48 +00:00
|
|
|
if (!s) {
|
|
|
|
return 0;
|
|
|
|
}
|
2008-02-20 20:30:45 +00:00
|
|
|
|
2008-04-02 18:44:49 +00:00
|
|
|
p = strndup(s, text_buffer_size);
|
2005-08-27 04:55:48 +00:00
|
|
|
final = p;
|
2008-02-20 20:30:45 +00:00
|
|
|
|
2005-08-27 04:55:48 +00:00
|
|
|
while (*p) {
|
|
|
|
if (*p == SPECIAL_CHAR) {
|
2008-02-20 20:30:45 +00:00
|
|
|
/* shift everything over by 1 so that the special char
|
|
|
|
* doesn't mess up the size calculation */
|
2009-05-05 23:36:12 +00:00
|
|
|
for (i = 0; i < (long)strlen(p); i++) {
|
2005-08-27 04:55:48 +00:00
|
|
|
*(p + i) = *(p + i + 1);
|
|
|
|
}
|
2008-03-29 09:58:09 +00:00
|
|
|
if (specials[special_index + idx].type == GRAPH
|
2009-04-10 02:10:08 +00:00
|
|
|
|| specials[special_index + idx].type == GAUGE
|
2008-03-29 09:58:09 +00:00
|
|
|
|| specials[special_index + idx].type == BAR) {
|
|
|
|
width += specials[special_index + idx].width;
|
2005-08-27 04:55:48 +00:00
|
|
|
}
|
2008-03-29 09:58:09 +00:00
|
|
|
idx++;
|
2005-08-27 04:55:48 +00:00
|
|
|
} else {
|
|
|
|
p++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (strlen(final) > 1) {
|
|
|
|
width += calc_text_width(final, strlen(final));
|
|
|
|
}
|
2005-08-27 06:02:45 +00:00
|
|
|
free(final);
|
2005-08-27 04:55:48 +00:00
|
|
|
return width;
|
|
|
|
#endif /* X11 */
|
|
|
|
}
|
|
|
|
|
2005-08-11 05:21:56 +00:00
|
|
|
#ifdef X11
|
2006-08-10 16:56:13 +00:00
|
|
|
static void text_size_updater(char *s);
|
2005-07-20 00:30:40 +00:00
|
|
|
|
2006-08-10 16:56:13 +00:00
|
|
|
int last_font_height;
|
2008-03-29 02:01:03 +00:00
|
|
|
static void update_text_area(void)
|
2005-07-20 00:30:40 +00:00
|
|
|
{
|
|
|
|
int x, y;
|
|
|
|
|
2009-02-21 23:37:15 +00:00
|
|
|
if ((output_methods & TO_X) == 0)
|
|
|
|
return;
|
2005-07-20 00:30:40 +00:00
|
|
|
/* update text size if it isn't fixed */
|
|
|
|
#ifdef OWN_WINDOW
|
|
|
|
if (!fixed_size)
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
text_width = minimum_width;
|
|
|
|
text_height = 0;
|
|
|
|
special_index = 0;
|
2006-09-28 04:54:46 +00:00
|
|
|
last_font_height = font_height();
|
2005-07-20 00:30:40 +00:00
|
|
|
for_each_line(text_buffer, text_size_updater);
|
|
|
|
text_width += 1;
|
2008-02-20 20:30:45 +00:00
|
|
|
if (text_height < minimum_height) {
|
2005-07-20 00:30:40 +00:00
|
|
|
text_height = minimum_height;
|
2008-02-20 20:30:45 +00:00
|
|
|
}
|
|
|
|
if (text_width > maximum_width && maximum_width > 0) {
|
2005-08-24 06:21:50 +00:00
|
|
|
text_width = maximum_width;
|
2008-02-20 20:30:45 +00:00
|
|
|
}
|
2005-07-20 00:30:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* get text position on workarea */
|
|
|
|
switch (text_alignment) {
|
2008-02-20 20:30:45 +00:00
|
|
|
case TOP_LEFT:
|
|
|
|
x = gap_x;
|
|
|
|
y = gap_y;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TOP_RIGHT:
|
|
|
|
x = workarea[2] - text_width - gap_x;
|
|
|
|
y = gap_y;
|
|
|
|
break;
|
|
|
|
|
2008-03-18 00:23:16 +00:00
|
|
|
case TOP_MIDDLE:
|
|
|
|
x = workarea[2] / 2 - text_width / 2 - gap_x;
|
|
|
|
y = gap_y;
|
|
|
|
break;
|
|
|
|
|
2008-02-20 20:30:45 +00:00
|
|
|
default:
|
|
|
|
case BOTTOM_LEFT:
|
|
|
|
x = gap_x;
|
|
|
|
y = workarea[3] - text_height - gap_y;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BOTTOM_RIGHT:
|
|
|
|
x = workarea[2] - text_width - gap_x;
|
|
|
|
y = workarea[3] - text_height - gap_y;
|
|
|
|
break;
|
|
|
|
|
2008-03-18 00:23:16 +00:00
|
|
|
case BOTTOM_MIDDLE:
|
|
|
|
x = workarea[2] / 2 - text_width / 2 - gap_x;
|
|
|
|
y = workarea[3] - text_height - gap_y;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MIDDLE_LEFT:
|
|
|
|
x = gap_x;
|
|
|
|
y = workarea[3] / 2 - text_height / 2 - gap_y;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MIDDLE_RIGHT:
|
|
|
|
x = workarea[2] - text_width - gap_x;
|
|
|
|
y = workarea[3] / 2 - text_height / 2 - gap_y;
|
|
|
|
break;
|
|
|
|
|
2005-08-21 17:32:43 +00:00
|
|
|
#ifdef OWN_WINDOW
|
2008-02-20 20:30:45 +00:00
|
|
|
case NONE: // Let the WM manage the window
|
|
|
|
x = window.x;
|
|
|
|
y = window.y;
|
2005-08-20 19:43:06 +00:00
|
|
|
|
2008-02-20 20:30:45 +00:00
|
|
|
fixed_pos = 1;
|
|
|
|
fixed_size = 1;
|
|
|
|
break;
|
2005-08-21 17:32:43 +00:00
|
|
|
#endif
|
2005-07-20 00:30:40 +00:00
|
|
|
}
|
|
|
|
#ifdef OWN_WINDOW
|
2005-08-21 17:32:43 +00:00
|
|
|
|
2005-08-20 19:43:06 +00:00
|
|
|
if (own_window && !fixed_pos) {
|
2005-07-20 00:30:40 +00:00
|
|
|
x += workarea[0];
|
|
|
|
y += workarea[1];
|
|
|
|
text_start_x = border_margin + 1;
|
|
|
|
text_start_y = border_margin + 1;
|
|
|
|
window.x = x - border_margin - 1;
|
|
|
|
window.y = y - border_margin - 1;
|
|
|
|
} else
|
|
|
|
#endif
|
|
|
|
{
|
2008-02-20 20:30:45 +00:00
|
|
|
/* If window size doesn't match to workarea's size,
|
|
|
|
* then window probably includes panels (gnome).
|
2005-07-20 00:30:40 +00:00
|
|
|
* Blah, doesn't work on KDE. */
|
2008-02-20 20:30:45 +00:00
|
|
|
if (workarea[2] != window.width || workarea[3] != window.height) {
|
2005-07-20 00:30:40 +00:00
|
|
|
y += workarea[1];
|
|
|
|
x += workarea[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
text_start_x = x;
|
|
|
|
text_start_y = y;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-02-20 20:30:45 +00:00
|
|
|
/* drawing stuff */
|
2005-07-20 00:30:40 +00:00
|
|
|
|
|
|
|
static int cur_x, cur_y; /* current x and y for drawing */
|
2008-06-04 22:35:02 +00:00
|
|
|
#endif
|
|
|
|
//draw_mode also without X11 because we only need to print to stdout with FG
|
2005-07-20 00:30:40 +00:00
|
|
|
static int draw_mode; /* FG, BG or OUTLINE */
|
2008-06-04 22:35:02 +00:00
|
|
|
#ifdef X11
|
2005-07-20 00:30:40 +00:00
|
|
|
static long current_color;
|
|
|
|
|
2006-08-10 16:56:13 +00:00
|
|
|
static void text_size_updater(char *s)
|
|
|
|
{
|
|
|
|
int w = 0;
|
|
|
|
char *p;
|
2008-02-20 20:30:45 +00:00
|
|
|
|
2009-02-21 23:37:15 +00:00
|
|
|
if ((output_methods & TO_X) == 0)
|
|
|
|
return;
|
2006-08-10 16:56:13 +00:00
|
|
|
/* get string widths and skip specials */
|
|
|
|
p = s;
|
|
|
|
while (*p) {
|
|
|
|
if (*p == SPECIAL_CHAR) {
|
|
|
|
*p = '\0';
|
|
|
|
w += get_string_width(s);
|
|
|
|
*p = SPECIAL_CHAR;
|
|
|
|
|
|
|
|
if (specials[special_index].type == BAR
|
2009-04-10 02:10:08 +00:00
|
|
|
|| specials[special_index].type == GAUGE
|
2008-02-20 20:30:45 +00:00
|
|
|
|| specials[special_index].type == GRAPH) {
|
2006-08-10 16:56:13 +00:00
|
|
|
w += specials[special_index].width;
|
|
|
|
if (specials[special_index].height > last_font_height) {
|
|
|
|
last_font_height = specials[special_index].height;
|
2009-04-10 02:10:08 +00:00
|
|
|
last_font_height += font_height();
|
2006-08-10 16:56:13 +00:00
|
|
|
}
|
|
|
|
} else if (specials[special_index].type == OFFSET) {
|
2008-01-06 01:35:14 +00:00
|
|
|
if (specials[special_index].arg > 0) {
|
|
|
|
w += specials[special_index].arg;
|
|
|
|
}
|
2006-08-10 16:56:13 +00:00
|
|
|
} else if (specials[special_index].type == VOFFSET) {
|
|
|
|
last_font_height += specials[special_index].arg;
|
|
|
|
} else if (specials[special_index].type == GOTO) {
|
2008-01-06 01:35:14 +00:00
|
|
|
if (specials[special_index].arg > cur_x) {
|
2008-02-20 20:30:45 +00:00
|
|
|
w = (int) specials[special_index].arg;
|
2008-01-06 01:35:14 +00:00
|
|
|
}
|
2008-02-20 20:30:45 +00:00
|
|
|
} else if (specials[special_index].type == TAB) {
|
|
|
|
int start = specials[special_index].arg;
|
2006-08-10 16:56:13 +00:00
|
|
|
int step = specials[special_index].width;
|
2008-02-20 20:30:45 +00:00
|
|
|
|
|
|
|
if (!step || step < 0) {
|
2006-08-10 16:56:13 +00:00
|
|
|
step = 10;
|
2008-02-20 20:30:45 +00:00
|
|
|
}
|
2006-08-10 16:56:13 +00:00
|
|
|
w += step - (cur_x - text_start_x - start) % step;
|
|
|
|
} else if (specials[special_index].type == FONT) {
|
|
|
|
selected_font = specials[special_index].font_added;
|
|
|
|
if (font_height() > last_font_height) {
|
|
|
|
last_font_height = font_height();
|
|
|
|
}
|
|
|
|
}
|
2008-02-20 20:30:45 +00:00
|
|
|
|
2006-08-10 16:56:13 +00:00
|
|
|
special_index++;
|
|
|
|
s = p + 1;
|
|
|
|
}
|
|
|
|
p++;
|
|
|
|
}
|
|
|
|
w += get_string_width(s);
|
|
|
|
if (w > text_width) {
|
|
|
|
text_width = w;
|
|
|
|
}
|
|
|
|
if (text_width > maximum_width && maximum_width) {
|
|
|
|
text_width = maximum_width;
|
|
|
|
}
|
|
|
|
|
|
|
|
text_height += last_font_height;
|
|
|
|
last_font_height = font_height();
|
|
|
|
}
|
|
|
|
|
2005-07-20 00:30:40 +00:00
|
|
|
static inline void set_foreground_color(long c)
|
|
|
|
{
|
2009-02-21 23:37:15 +00:00
|
|
|
if ((output_methods & TO_X) == 0)
|
|
|
|
return;
|
2005-07-20 00:30:40 +00:00
|
|
|
current_color = c;
|
|
|
|
XSetForeground(display, window.gc, c);
|
|
|
|
}
|
2005-08-08 01:18:52 +00:00
|
|
|
#endif /* X11 */
|
2005-07-20 00:30:40 +00:00
|
|
|
|
|
|
|
static void draw_string(const char *s)
|
|
|
|
{
|
|
|
|
int i, i2, pos, width_of_s;
|
2008-02-20 20:30:45 +00:00
|
|
|
int max = 0;
|
2005-08-11 05:21:56 +00:00
|
|
|
int added;
|
2008-03-29 06:24:04 +00:00
|
|
|
|
|
|
|
if (s[0] == '\0') {
|
|
|
|
return;
|
|
|
|
}
|
2008-02-20 20:30:45 +00:00
|
|
|
|
2005-07-20 00:30:40 +00:00
|
|
|
width_of_s = get_string_width(s);
|
2008-06-21 20:37:58 +00:00
|
|
|
if ((output_methods & TO_STDOUT) && draw_mode == FG) {
|
2005-07-20 00:30:40 +00:00
|
|
|
printf("%s\n", s);
|
2008-02-20 20:30:45 +00:00
|
|
|
fflush(stdout); /* output immediately, don't buffer */
|
2005-07-20 00:30:40 +00:00
|
|
|
}
|
2009-02-10 08:43:20 +00:00
|
|
|
if ((output_methods & TO_STDERR) && draw_mode == FG) {
|
|
|
|
fprintf(stderr, "%s\n", s);
|
|
|
|
fflush(stderr); /* output immediately, don't buffer */
|
|
|
|
}
|
2009-02-21 23:37:15 +00:00
|
|
|
if ((output_methods & OVERWRITE_FILE) && draw_mode == FG && overwrite_fpointer) {
|
2009-02-12 21:35:00 +00:00
|
|
|
fprintf(overwrite_fpointer, "%s\n", s);
|
|
|
|
}
|
2009-02-21 23:37:15 +00:00
|
|
|
if ((output_methods & APPEND_FILE) && draw_mode == FG && append_fpointer) {
|
2009-02-12 21:45:18 +00:00
|
|
|
fprintf(append_fpointer, "%s\n", s);
|
|
|
|
}
|
2008-03-20 21:28:19 +00:00
|
|
|
memset(tmpstring1, 0, text_buffer_size);
|
|
|
|
memset(tmpstring2, 0, text_buffer_size);
|
|
|
|
strncpy(tmpstring1, s, text_buffer_size - 1);
|
2005-07-20 00:30:40 +00:00
|
|
|
pos = 0;
|
|
|
|
added = 0;
|
2008-02-20 20:30:45 +00:00
|
|
|
|
2005-08-08 01:18:52 +00:00
|
|
|
#ifdef X11
|
2009-02-21 23:37:15 +00:00
|
|
|
if (output_methods & TO_X) {
|
2009-02-14 12:03:11 +00:00
|
|
|
max = ((text_width - width_of_s) / get_string_width(" "));
|
|
|
|
}
|
2005-08-08 01:18:52 +00:00
|
|
|
#endif /* X11 */
|
2008-02-20 20:30:45 +00:00
|
|
|
/* This code looks for tabs in the text and coverts them to spaces.
|
|
|
|
* The trick is getting the correct number of spaces, and not going
|
|
|
|
* over the window's size without forcing the window larger. */
|
2008-06-19 19:57:12 +00:00
|
|
|
for (i = 0; i < (int) text_buffer_size; i++) {
|
|
|
|
if (tmpstring1[i] == '\t') {
|
2005-07-28 04:48:27 +00:00
|
|
|
i2 = 0;
|
2008-02-20 20:30:45 +00:00
|
|
|
for (i2 = 0; i2 < (8 - (1 + pos) % 8) && added <= max; i2++) {
|
|
|
|
/* guard against overrun */
|
2008-03-20 21:28:19 +00:00
|
|
|
tmpstring2[MIN(pos + i2, (int)text_buffer_size - 1)] = ' ';
|
2005-07-20 00:30:40 +00:00
|
|
|
added++;
|
|
|
|
}
|
|
|
|
pos += i2;
|
2005-07-28 04:48:27 +00:00
|
|
|
} else {
|
2008-06-19 19:57:12 +00:00
|
|
|
/* guard against overrun */
|
|
|
|
tmpstring2[MIN(pos, (int) text_buffer_size - 1)] = tmpstring1[i];
|
|
|
|
pos++;
|
2005-07-28 04:48:27 +00:00
|
|
|
}
|
2005-07-20 00:30:40 +00:00
|
|
|
}
|
2005-08-29 17:06:31 +00:00
|
|
|
#ifdef X11
|
2009-02-21 23:37:15 +00:00
|
|
|
if (output_methods & TO_X) {
|
2009-02-14 12:03:11 +00:00
|
|
|
if (text_width == maximum_width) {
|
|
|
|
/* this means the text is probably pushing the limit,
|
|
|
|
* so we'll chop it */
|
|
|
|
while (cur_x + get_string_width(tmpstring2) - text_start_x
|
|
|
|
> maximum_width && strlen(tmpstring2) > 0) {
|
|
|
|
tmpstring2[strlen(tmpstring2) - 1] = '\0';
|
|
|
|
}
|
2005-08-24 06:21:50 +00:00
|
|
|
}
|
|
|
|
}
|
2005-08-29 17:06:31 +00:00
|
|
|
#endif /* X11 */
|
2005-07-20 00:30:40 +00:00
|
|
|
s = tmpstring2;
|
2005-08-08 01:18:52 +00:00
|
|
|
#ifdef X11
|
2009-02-21 23:37:15 +00:00
|
|
|
if (output_methods & TO_X) {
|
2005-07-20 00:30:40 +00:00
|
|
|
#ifdef XFT
|
2009-02-14 12:03:11 +00:00
|
|
|
if (use_xft) {
|
|
|
|
XColor c;
|
|
|
|
XftColor c2;
|
|
|
|
|
|
|
|
c.pixel = current_color;
|
|
|
|
XQueryColor(display, DefaultColormap(display, screen), &c);
|
|
|
|
|
|
|
|
c2.pixel = c.pixel;
|
|
|
|
c2.color.red = c.red;
|
|
|
|
c2.color.green = c.green;
|
|
|
|
c2.color.blue = c.blue;
|
|
|
|
c2.color.alpha = fonts[selected_font].font_alpha;
|
|
|
|
if (utf8_mode) {
|
|
|
|
XftDrawStringUtf8(window.xftdraw, &c2, fonts[selected_font].xftfont,
|
|
|
|
cur_x, cur_y, (const XftChar8 *) s, strlen(s));
|
|
|
|
} else {
|
|
|
|
XftDrawString8(window.xftdraw, &c2, fonts[selected_font].xftfont,
|
|
|
|
cur_x, cur_y, (const XftChar8 *) s, strlen(s));
|
|
|
|
}
|
|
|
|
} else
|
2005-07-20 00:30:40 +00:00
|
|
|
#endif
|
2009-02-14 12:03:11 +00:00
|
|
|
{
|
|
|
|
XDrawString(display, window.drawable, window.gc, cur_x, cur_y, s,
|
|
|
|
strlen(s));
|
|
|
|
}
|
|
|
|
cur_x += width_of_s;
|
2005-07-20 00:30:40 +00:00
|
|
|
}
|
2005-08-08 01:18:52 +00:00
|
|
|
#endif /* X11 */
|
2008-03-20 21:28:19 +00:00
|
|
|
memcpy(tmpstring1, s, text_buffer_size);
|
2005-07-20 00:30:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void draw_line(char *s)
|
|
|
|
{
|
2005-08-08 01:18:52 +00:00
|
|
|
#ifdef X11
|
2005-07-20 00:30:40 +00:00
|
|
|
char *p;
|
2008-03-29 06:24:04 +00:00
|
|
|
int cur_y_add = 0;
|
2009-04-10 02:10:08 +00:00
|
|
|
int font_h;
|
2008-04-13 04:10:35 +00:00
|
|
|
char *tmp_str;
|
2009-02-18 04:45:06 +00:00
|
|
|
#endif /* X11 */
|
2009-02-21 23:37:15 +00:00
|
|
|
|
|
|
|
if ((output_methods & TO_X) == 0) {
|
2009-02-18 04:45:06 +00:00
|
|
|
draw_string(s);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#ifdef X11
|
2005-07-20 00:30:40 +00:00
|
|
|
cur_x = text_start_x;
|
|
|
|
cur_y += font_ascent();
|
2008-03-29 06:24:04 +00:00
|
|
|
font_h = font_height();
|
2005-07-20 00:30:40 +00:00
|
|
|
|
|
|
|
/* find specials and draw stuff */
|
|
|
|
p = s;
|
|
|
|
while (*p) {
|
|
|
|
if (*p == SPECIAL_CHAR) {
|
|
|
|
int w = 0;
|
|
|
|
|
|
|
|
/* draw string before special */
|
|
|
|
*p = '\0';
|
|
|
|
draw_string(s);
|
|
|
|
*p = SPECIAL_CHAR;
|
|
|
|
s = p + 1;
|
|
|
|
|
|
|
|
/* draw special */
|
|
|
|
switch (specials[special_index].type) {
|
2008-02-20 20:30:45 +00:00
|
|
|
case HORIZONTAL_LINE:
|
2005-07-20 00:30:40 +00:00
|
|
|
{
|
2008-02-20 20:30:45 +00:00
|
|
|
int h = specials[special_index].height;
|
2005-07-20 00:30:40 +00:00
|
|
|
int mid = font_ascent() / 2;
|
2008-02-20 20:30:45 +00:00
|
|
|
|
|
|
|
w = text_start_x + text_width - cur_x;
|
|
|
|
|
|
|
|
XSetLineAttributes(display, window.gc, h, LineSolid,
|
|
|
|
CapButt, JoinMiter);
|
|
|
|
XDrawLine(display, window.drawable, window.gc, cur_x,
|
|
|
|
cur_y - mid / 2, cur_x + w, cur_y - mid / 2);
|
|
|
|
break;
|
2005-07-20 00:30:40 +00:00
|
|
|
}
|
|
|
|
|
2008-02-20 20:30:45 +00:00
|
|
|
case STIPPLED_HR:
|
2005-07-20 00:30:40 +00:00
|
|
|
{
|
2008-02-20 20:30:45 +00:00
|
|
|
int h = specials[special_index].height;
|
2008-03-29 09:58:09 +00:00
|
|
|
int tmp_s = specials[special_index].arg;
|
2005-07-20 00:30:40 +00:00
|
|
|
int mid = font_ascent() / 2;
|
2008-03-29 09:58:09 +00:00
|
|
|
char ss[2] = { tmp_s, tmp_s };
|
2008-02-20 20:30:45 +00:00
|
|
|
|
|
|
|
w = text_start_x + text_width - cur_x - 1;
|
|
|
|
XSetLineAttributes(display, window.gc, h, LineOnOffDash,
|
|
|
|
CapButt, JoinMiter);
|
|
|
|
XSetDashes(display, window.gc, 0, ss, 2);
|
|
|
|
XDrawLine(display, window.drawable, window.gc, cur_x,
|
|
|
|
cur_y - mid / 2, cur_x + w, cur_y - mid / 2);
|
|
|
|
break;
|
2005-07-20 00:30:40 +00:00
|
|
|
}
|
|
|
|
|
2008-02-20 20:30:45 +00:00
|
|
|
case BAR:
|
2005-07-20 00:30:40 +00:00
|
|
|
{
|
2008-03-29 06:24:04 +00:00
|
|
|
int h, bar_usage, by;
|
2008-02-20 20:30:45 +00:00
|
|
|
if (cur_x - text_start_x > maximum_width
|
|
|
|
&& maximum_width > 0) {
|
2005-08-24 06:21:50 +00:00
|
|
|
break;
|
|
|
|
}
|
2008-03-29 06:24:04 +00:00
|
|
|
h = specials[special_index].height;
|
|
|
|
bar_usage = specials[special_index].arg;
|
|
|
|
by = cur_y - (font_ascent() / 2) - 1;
|
2008-02-20 20:30:45 +00:00
|
|
|
|
2009-04-10 02:10:08 +00:00
|
|
|
if (h < font_h) {
|
2005-08-26 16:29:56 +00:00
|
|
|
by -= h / 2 - 1;
|
|
|
|
}
|
2005-07-20 00:30:40 +00:00
|
|
|
w = specials[special_index].width;
|
2008-02-20 20:30:45 +00:00
|
|
|
if (w == 0) {
|
|
|
|
w = text_start_x + text_width - cur_x - 1;
|
|
|
|
}
|
|
|
|
if (w < 0) {
|
2005-07-20 00:30:40 +00:00
|
|
|
w = 0;
|
2008-02-20 20:30:45 +00:00
|
|
|
}
|
2005-07-20 00:30:40 +00:00
|
|
|
|
2008-02-20 20:30:45 +00:00
|
|
|
XSetLineAttributes(display, window.gc, 1, LineSolid,
|
|
|
|
CapButt, JoinMiter);
|
|
|
|
|
|
|
|
XDrawRectangle(display, window.drawable, window.gc, cur_x,
|
|
|
|
by, w, h);
|
|
|
|
XFillRectangle(display, window.drawable, window.gc, cur_x,
|
|
|
|
by, w * bar_usage / 255, h);
|
2009-04-10 02:10:08 +00:00
|
|
|
if (h > cur_y_add
|
|
|
|
&& h > font_h) {
|
|
|
|
cur_y_add = h;
|
2005-07-29 02:52:08 +00:00
|
|
|
}
|
2008-02-20 20:30:45 +00:00
|
|
|
break;
|
2005-07-20 00:30:40 +00:00
|
|
|
}
|
|
|
|
|
2009-03-11 00:37:24 +00:00
|
|
|
case GAUGE: /* new GAUGE */
|
|
|
|
{
|
2009-04-10 02:10:08 +00:00
|
|
|
int h, by = 0;
|
2009-03-11 00:37:24 +00:00
|
|
|
unsigned long last_colour = current_color;
|
2009-04-10 02:10:08 +00:00
|
|
|
float angle, px, py;
|
2009-03-11 00:37:24 +00:00
|
|
|
int usage;
|
|
|
|
|
|
|
|
if (cur_x - text_start_x > maximum_width
|
|
|
|
&& maximum_width > 0) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
h = specials[special_index].height;
|
|
|
|
by = cur_y - (font_ascent() / 2) - 1;
|
|
|
|
|
2009-04-10 02:10:08 +00:00
|
|
|
if (h < font_h) {
|
2009-03-11 00:37:24 +00:00
|
|
|
by -= h / 2 - 1;
|
|
|
|
}
|
|
|
|
w = specials[special_index].width;
|
|
|
|
if (w == 0) {
|
|
|
|
w = text_start_x + text_width - cur_x - 1;
|
|
|
|
}
|
|
|
|
if (w < 0) {
|
|
|
|
w = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
XSetLineAttributes(display, window.gc, 1, LineSolid,
|
2009-04-10 02:10:08 +00:00
|
|
|
CapButt, JoinMiter);
|
2009-03-11 00:37:24 +00:00
|
|
|
|
|
|
|
XDrawArc(display, window.drawable, window.gc,
|
2009-04-10 02:10:08 +00:00
|
|
|
cur_x, by, w, h * 2, 0, 180*64);
|
2009-03-11 00:37:24 +00:00
|
|
|
|
|
|
|
#ifdef MATH
|
2009-04-10 02:10:08 +00:00
|
|
|
usage = specials[special_index].arg;
|
|
|
|
angle = (M_PI)*(float)(usage)/255.;
|
|
|
|
px = (float)(cur_x+(w/2.))-(float)(w/2.)*cos(angle);
|
|
|
|
py = (float)(by+(h))-(float)(h)*sin(angle);
|
2009-03-11 00:37:24 +00:00
|
|
|
|
|
|
|
XDrawLine(display, window.drawable, window.gc,
|
2009-04-10 02:10:08 +00:00
|
|
|
cur_x + (w/2.), by+(h), (int)(px), (int)(py));
|
2009-03-11 00:37:24 +00:00
|
|
|
#endif
|
|
|
|
|
2009-04-10 02:10:08 +00:00
|
|
|
if (h > cur_y_add
|
|
|
|
&& h > font_h) {
|
|
|
|
cur_y_add = h;
|
2009-03-11 00:37:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
set_foreground_color(last_colour);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2008-02-20 20:30:45 +00:00
|
|
|
case GRAPH:
|
|
|
|
{
|
2008-03-29 06:24:04 +00:00
|
|
|
int h, by, i, j = 0;
|
|
|
|
int gradient_size = 0;
|
|
|
|
float gradient_factor = 0;
|
|
|
|
float gradient_update = 0;
|
|
|
|
unsigned long last_colour = current_color;
|
|
|
|
unsigned long tmpcolour = current_color;
|
2008-02-20 20:30:45 +00:00
|
|
|
if (cur_x - text_start_x > maximum_width
|
|
|
|
&& maximum_width > 0) {
|
2005-08-24 06:21:50 +00:00
|
|
|
break;
|
|
|
|
}
|
2008-03-29 06:24:04 +00:00
|
|
|
h = specials[special_index].height;
|
|
|
|
by = cur_y - (font_ascent() / 2) - 1;
|
2008-02-20 20:30:45 +00:00
|
|
|
|
2009-04-10 02:10:08 +00:00
|
|
|
if (h < font_h) {
|
2005-08-26 16:29:56 +00:00
|
|
|
by -= h / 2 - 1;
|
2005-08-04 02:17:25 +00:00
|
|
|
}
|
2005-07-28 06:56:55 +00:00
|
|
|
w = specials[special_index].width;
|
2008-02-20 20:30:45 +00:00
|
|
|
if (w == 0) {
|
2005-08-04 05:44:39 +00:00
|
|
|
w = text_start_x + text_width - cur_x - 1;
|
2008-02-20 20:30:45 +00:00
|
|
|
}
|
|
|
|
if (w < 0) {
|
2005-07-28 06:56:55 +00:00
|
|
|
w = 0;
|
2008-02-20 20:30:45 +00:00
|
|
|
}
|
2006-01-05 23:23:51 +00:00
|
|
|
if (draw_graph_borders) {
|
2008-02-20 20:30:45 +00:00
|
|
|
XSetLineAttributes(display, window.gc, 1, LineSolid,
|
|
|
|
CapButt, JoinMiter);
|
|
|
|
XDrawRectangle(display, window.drawable, window.gc,
|
|
|
|
cur_x, by, w, h);
|
2006-01-05 23:23:51 +00:00
|
|
|
}
|
2008-02-20 20:30:45 +00:00
|
|
|
XSetLineAttributes(display, window.gc, 1, LineSolid,
|
|
|
|
CapButt, JoinMiter);
|
|
|
|
|
|
|
|
if (specials[special_index].last_colour != 0
|
|
|
|
|| specials[special_index].first_colour != 0) {
|
|
|
|
tmpcolour = specials[special_index].last_colour;
|
|
|
|
gradient_size =
|
|
|
|
gradient_max(specials[special_index].last_colour,
|
|
|
|
specials[special_index].first_colour);
|
|
|
|
gradient_factor = (float) gradient_size / (w - 2);
|
|
|
|
}
|
|
|
|
for (i = w - 2; i > -1; i--) {
|
|
|
|
if (specials[special_index].last_colour != 0
|
|
|
|
|| specials[special_index].first_colour != 0) {
|
|
|
|
XSetForeground(display, window.gc, tmpcolour);
|
|
|
|
gradient_update += gradient_factor;
|
|
|
|
while (gradient_update > 0) {
|
|
|
|
tmpcolour = do_gradient(tmpcolour,
|
|
|
|
specials[special_index].first_colour);
|
|
|
|
gradient_update--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ((w - i) / ((float) (w - 2) /
|
|
|
|
(specials[special_index].graph_width)) > j
|
|
|
|
&& j < MAX_GRAPH_DEPTH - 3) {
|
|
|
|
j++;
|
|
|
|
}
|
|
|
|
/* this is mugfugly, but it works */
|
|
|
|
XDrawLine(display, window.drawable, window.gc,
|
|
|
|
cur_x + i + 1, by + h, cur_x + i + 1,
|
|
|
|
by + h - specials[special_index].graph[j] *
|
|
|
|
(h - 1) / specials[special_index].graph_scale);
|
2005-08-26 02:16:35 +00:00
|
|
|
}
|
2009-04-10 02:10:08 +00:00
|
|
|
if (h > cur_y_add
|
|
|
|
&& h > font_h) {
|
|
|
|
cur_y_add = h;
|
2005-07-29 02:52:08 +00:00
|
|
|
}
|
2008-02-20 20:30:45 +00:00
|
|
|
/* if (draw_mode == BG) {
|
|
|
|
set_foreground_color(default_bg_color);
|
|
|
|
} else if (draw_mode == OUTLINE) {
|
|
|
|
set_foreground_color(default_out_color);
|
|
|
|
} else {
|
|
|
|
set_foreground_color(default_fg_color);
|
|
|
|
} */
|
2008-06-21 20:37:58 +00:00
|
|
|
if (show_graph_range) {
|
|
|
|
int tmp_x = cur_x;
|
|
|
|
int tmp_y = cur_y;
|
|
|
|
unsigned short int seconds = update_interval * w;
|
|
|
|
char *tmp_day_str;
|
|
|
|
char *tmp_hour_str;
|
|
|
|
char *tmp_min_str;
|
|
|
|
char *tmp_sec_str;
|
|
|
|
unsigned short int timeunits;
|
2009-04-10 02:10:08 +00:00
|
|
|
if (seconds != 0) {
|
2008-06-21 20:37:58 +00:00
|
|
|
timeunits = seconds / 86400; seconds %= 86400;
|
2009-04-10 02:10:08 +00:00
|
|
|
if (timeunits > 0) {
|
2008-06-21 20:37:58 +00:00
|
|
|
asprintf(&tmp_day_str, "%dd", timeunits);
|
2009-04-10 02:10:08 +00:00
|
|
|
} else {
|
2008-06-21 20:37:58 +00:00
|
|
|
tmp_day_str = strdup("");
|
|
|
|
}
|
|
|
|
timeunits = seconds / 3600; seconds %= 3600;
|
2009-04-10 02:10:08 +00:00
|
|
|
if (timeunits > 0) {
|
2008-06-21 20:37:58 +00:00
|
|
|
asprintf(&tmp_hour_str, "%dh", timeunits);
|
2009-04-10 02:10:08 +00:00
|
|
|
} else {
|
2008-06-21 20:37:58 +00:00
|
|
|
tmp_hour_str = strdup("");
|
|
|
|
}
|
|
|
|
timeunits = seconds / 60; seconds %= 60;
|
2009-04-10 02:10:08 +00:00
|
|
|
if (timeunits > 0) {
|
2008-06-21 20:37:58 +00:00
|
|
|
asprintf(&tmp_min_str, "%dm", timeunits);
|
2009-04-10 02:10:08 +00:00
|
|
|
} else {
|
2008-06-21 20:37:58 +00:00
|
|
|
tmp_min_str = strdup("");
|
|
|
|
}
|
2009-04-10 02:10:08 +00:00
|
|
|
if (seconds > 0) {
|
2008-06-21 20:37:58 +00:00
|
|
|
asprintf(&tmp_sec_str, "%ds", seconds);
|
2009-04-10 02:10:08 +00:00
|
|
|
} else {
|
2008-06-21 20:37:58 +00:00
|
|
|
tmp_sec_str = strdup("");
|
|
|
|
}
|
|
|
|
asprintf(&tmp_str, "%s%s%s%s", tmp_day_str, tmp_hour_str, tmp_min_str, tmp_sec_str);
|
|
|
|
free(tmp_day_str); free(tmp_hour_str); free(tmp_min_str); free(tmp_sec_str);
|
2009-04-10 02:10:08 +00:00
|
|
|
} else {
|
|
|
|
asprintf(&tmp_str, "Range not possible"); // should never happen, but better safe then sorry
|
2008-06-21 20:37:58 +00:00
|
|
|
}
|
|
|
|
cur_x += (w / 2) - (font_ascent() * (strlen(tmp_str) / 2));
|
2009-04-10 02:10:08 +00:00
|
|
|
cur_y += font_h / 2;
|
2008-06-21 20:37:58 +00:00
|
|
|
draw_string(tmp_str);
|
|
|
|
free(tmp_str);
|
|
|
|
cur_x = tmp_x;
|
|
|
|
cur_y = tmp_y;
|
|
|
|
}
|
2008-07-01 11:13:40 +00:00
|
|
|
#ifdef MATH
|
2008-04-13 04:10:35 +00:00
|
|
|
if (show_graph_scale && (specials[special_index].show_scale == 1)) {
|
|
|
|
int tmp_x = cur_x;
|
|
|
|
int tmp_y = cur_y;
|
2008-06-21 20:37:58 +00:00
|
|
|
cur_x += font_ascent() / 2;
|
2009-04-10 02:10:08 +00:00
|
|
|
cur_y += font_h / 2;
|
2008-04-13 04:10:35 +00:00
|
|
|
tmp_str = (char *)
|
|
|
|
calloc(log10(floor(specials[special_index].graph_scale)) + 4,
|
|
|
|
sizeof(char));
|
2009-02-21 23:37:15 +00:00
|
|
|
sprintf(tmp_str, "%.1f", specials[special_index].graph_scale);
|
2008-04-13 04:10:35 +00:00
|
|
|
draw_string(tmp_str);
|
|
|
|
free(tmp_str);
|
|
|
|
cur_x = tmp_x;
|
|
|
|
cur_y = tmp_y;
|
|
|
|
}
|
2008-07-01 11:13:40 +00:00
|
|
|
#endif
|
2008-02-20 20:30:45 +00:00
|
|
|
set_foreground_color(last_colour);
|
|
|
|
break;
|
2005-08-03 07:49:06 +00:00
|
|
|
}
|
2008-02-20 20:30:45 +00:00
|
|
|
|
2005-08-02 05:06:53 +00:00
|
|
|
case FONT:
|
2006-05-28 07:25:30 +00:00
|
|
|
{
|
2006-05-28 04:25:34 +00:00
|
|
|
int old = font_ascent();
|
2008-02-20 20:30:45 +00:00
|
|
|
|
2005-08-03 07:01:32 +00:00
|
|
|
cur_y -= font_ascent();
|
2005-08-03 07:26:37 +00:00
|
|
|
selected_font = specials[special_index].font_added;
|
2006-05-28 07:25:30 +00:00
|
|
|
if (cur_y + font_ascent() < cur_y + old) {
|
|
|
|
cur_y += old;
|
2006-05-28 04:25:34 +00:00
|
|
|
} else {
|
|
|
|
cur_y += font_ascent();
|
2005-08-06 00:26:14 +00:00
|
|
|
}
|
2006-05-28 04:25:34 +00:00
|
|
|
set_font();
|
2009-04-10 02:10:08 +00:00
|
|
|
font_h = font_height();
|
2008-02-20 20:30:45 +00:00
|
|
|
break;
|
2005-08-05 06:40:19 +00:00
|
|
|
}
|
2008-02-20 20:30:45 +00:00
|
|
|
case FG:
|
|
|
|
if (draw_mode == FG) {
|
|
|
|
set_foreground_color(specials[special_index].arg);
|
|
|
|
}
|
|
|
|
break;
|
2005-07-20 00:30:40 +00:00
|
|
|
|
2008-02-20 20:30:45 +00:00
|
|
|
case BG:
|
|
|
|
if (draw_mode == BG) {
|
|
|
|
set_foreground_color(specials[special_index].arg);
|
|
|
|
}
|
|
|
|
break;
|
2005-07-20 00:30:40 +00:00
|
|
|
|
2008-02-20 20:30:45 +00:00
|
|
|
case OUTLINE:
|
|
|
|
if (draw_mode == OUTLINE) {
|
|
|
|
set_foreground_color(specials[special_index].arg);
|
|
|
|
}
|
|
|
|
break;
|
2005-07-20 00:30:40 +00:00
|
|
|
|
2008-02-20 20:30:45 +00:00
|
|
|
case OFFSET:
|
|
|
|
w += specials[special_index].arg;
|
|
|
|
break;
|
2006-08-10 16:56:13 +00:00
|
|
|
|
2008-02-20 20:30:45 +00:00
|
|
|
case VOFFSET:
|
|
|
|
cur_y += specials[special_index].arg;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GOTO:
|
|
|
|
if (specials[special_index].arg >= 0) {
|
|
|
|
cur_x = (int) specials[special_index].arg;
|
|
|
|
}
|
|
|
|
break;
|
2006-08-10 16:56:13 +00:00
|
|
|
|
2008-02-20 20:30:45 +00:00
|
|
|
case TAB:
|
2005-08-21 05:04:22 +00:00
|
|
|
{
|
2006-08-10 16:56:13 +00:00
|
|
|
int start = specials[special_index].arg;
|
|
|
|
int step = specials[special_index].width;
|
2008-02-20 20:30:45 +00:00
|
|
|
|
|
|
|
if (!step || step < 0) {
|
2006-08-10 16:56:13 +00:00
|
|
|
step = 10;
|
2008-02-20 20:30:45 +00:00
|
|
|
}
|
2006-08-10 16:56:13 +00:00
|
|
|
w = step - (cur_x - text_start_x - start) % step;
|
2008-02-20 20:30:45 +00:00
|
|
|
break;
|
2005-08-21 05:04:22 +00:00
|
|
|
}
|
2005-07-31 08:27:03 +00:00
|
|
|
|
2008-02-20 20:30:45 +00:00
|
|
|
case ALIGNR:
|
2005-07-20 00:30:40 +00:00
|
|
|
{
|
2008-02-20 20:30:45 +00:00
|
|
|
/* TODO: add back in "+ border_margin" to the end of
|
|
|
|
* this line? */
|
|
|
|
int pos_x = text_start_x + text_width -
|
|
|
|
get_string_width_special(s);
|
|
|
|
|
|
|
|
/* printf("pos_x %i text_start_x %i text_width %i cur_x %i "
|
|
|
|
"get_string_width(p) %i gap_x %i "
|
|
|
|
"specials[special_index].arg %i border_margin %i "
|
|
|
|
"border_width %i\n", pos_x, text_start_x, text_width,
|
|
|
|
cur_x, get_string_width_special(s), gap_x,
|
|
|
|
specials[special_index].arg, border_margin,
|
|
|
|
border_width); */
|
2005-08-21 03:29:05 +00:00
|
|
|
if (pos_x > specials[special_index].arg && pos_x > cur_x) {
|
2005-08-27 04:55:48 +00:00
|
|
|
cur_x = pos_x - specials[special_index].arg;
|
2008-02-20 20:30:45 +00:00
|
|
|
}
|
|
|
|
break;
|
2005-08-21 03:29:05 +00:00
|
|
|
}
|
2005-07-20 00:30:40 +00:00
|
|
|
|
2008-02-20 20:30:45 +00:00
|
|
|
case ALIGNC:
|
2005-07-20 00:30:40 +00:00
|
|
|
{
|
2008-02-20 20:30:45 +00:00
|
|
|
int pos_x = (text_width) / 2 - get_string_width_special(s) /
|
|
|
|
2 - (cur_x - text_start_x);
|
|
|
|
/* int pos_x = text_start_x + text_width / 2 -
|
|
|
|
get_string_width_special(s) / 2; */
|
|
|
|
|
|
|
|
/* printf("pos_x %i text_start_x %i text_width %i cur_x %i "
|
|
|
|
"get_string_width(p) %i gap_x %i "
|
|
|
|
"specials[special_index].arg %i\n", pos_x, text_start_x,
|
2009-02-21 23:37:15 +00:00
|
|
|
text_width, cur_x, get_string_width(s), gap_x,
|
|
|
|
specials[special_index].arg); */
|
2008-02-20 20:30:45 +00:00
|
|
|
if (pos_x > specials[special_index].arg) {
|
|
|
|
w = pos_x - specials[special_index].arg;
|
|
|
|
}
|
|
|
|
break;
|
2005-07-20 00:30:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
cur_x += w;
|
|
|
|
|
|
|
|
special_index++;
|
|
|
|
}
|
|
|
|
|
|
|
|
p++;
|
|
|
|
}
|
2009-04-10 02:10:08 +00:00
|
|
|
|
2005-07-30 12:02:48 +00:00
|
|
|
if (cur_y_add > 0) {
|
|
|
|
cur_y += cur_y_add;
|
|
|
|
}
|
2005-07-20 00:30:40 +00:00
|
|
|
draw_string(s);
|
2005-08-04 02:17:25 +00:00
|
|
|
cur_y += font_descent();
|
2009-04-10 02:10:08 +00:00
|
|
|
|
2005-08-08 01:18:52 +00:00
|
|
|
#endif /* X11 */
|
2005-07-20 00:30:40 +00:00
|
|
|
}
|
|
|
|
|
2008-03-29 02:01:03 +00:00
|
|
|
static void draw_text(void)
|
2005-07-20 00:30:40 +00:00
|
|
|
{
|
2005-08-08 01:18:52 +00:00
|
|
|
#ifdef X11
|
2009-02-21 23:37:15 +00:00
|
|
|
if (output_methods & TO_X) {
|
2009-02-14 12:03:11 +00:00
|
|
|
cur_y = text_start_y;
|
|
|
|
|
|
|
|
/* draw borders */
|
|
|
|
if (draw_borders && border_width > 0) {
|
|
|
|
unsigned int b = (border_width + 1) / 2;
|
|
|
|
|
|
|
|
if (stippled_borders) {
|
|
|
|
char ss[2] = { stippled_borders, stippled_borders };
|
|
|
|
XSetLineAttributes(display, window.gc, border_width, LineOnOffDash,
|
|
|
|
CapButt, JoinMiter);
|
|
|
|
XSetDashes(display, window.gc, 0, ss, 2);
|
|
|
|
} else {
|
|
|
|
XSetLineAttributes(display, window.gc, border_width, LineSolid,
|
|
|
|
CapButt, JoinMiter);
|
|
|
|
}
|
2005-07-20 00:30:40 +00:00
|
|
|
|
2009-02-14 12:03:11 +00:00
|
|
|
XDrawRectangle(display, window.drawable, window.gc,
|
|
|
|
text_start_x - border_margin + b, text_start_y - border_margin + b,
|
|
|
|
text_width + border_margin * 2 - 1 - b * 2,
|
|
|
|
text_height + border_margin * 2 - 1 - b * 2);
|
2005-07-20 00:30:40 +00:00
|
|
|
}
|
|
|
|
|
2009-02-14 12:03:11 +00:00
|
|
|
/* draw text */
|
|
|
|
special_index = 0;
|
2005-07-20 00:30:40 +00:00
|
|
|
}
|
2005-08-08 01:18:52 +00:00
|
|
|
#endif /* X11 */
|
2005-07-20 00:30:40 +00:00
|
|
|
for_each_line(text_buffer, draw_line);
|
|
|
|
}
|
|
|
|
|
2008-03-29 02:01:03 +00:00
|
|
|
static void draw_stuff(void)
|
2005-07-20 00:30:40 +00:00
|
|
|
{
|
2009-02-21 23:37:15 +00:00
|
|
|
if(overwrite_file) {
|
2009-02-12 21:35:00 +00:00
|
|
|
overwrite_fpointer = fopen(overwrite_file, "w");
|
2009-02-21 23:37:15 +00:00
|
|
|
if(!overwrite_fpointer)
|
|
|
|
ERR("Can't overwrite '%s' anymore", overwrite_file);
|
2009-02-12 21:35:00 +00:00
|
|
|
}
|
2009-02-21 23:37:15 +00:00
|
|
|
if(append_file) {
|
2009-02-12 21:45:18 +00:00
|
|
|
append_fpointer = fopen(append_file, "a");
|
2009-02-21 23:37:15 +00:00
|
|
|
if(!append_fpointer)
|
|
|
|
ERR("Can't append '%s' anymore", append_file);
|
2009-02-12 21:45:18 +00:00
|
|
|
}
|
2005-08-08 01:18:52 +00:00
|
|
|
#ifdef X11
|
2009-02-21 23:37:15 +00:00
|
|
|
if (output_methods & TO_X) {
|
2008-03-29 06:24:04 +00:00
|
|
|
selected_font = 0;
|
2009-02-14 12:03:11 +00:00
|
|
|
if (draw_shades && !draw_outline) {
|
|
|
|
text_start_x++;
|
|
|
|
text_start_y++;
|
|
|
|
set_foreground_color(default_bg_color);
|
|
|
|
draw_mode = BG;
|
|
|
|
draw_text();
|
|
|
|
text_start_x--;
|
|
|
|
text_start_y--;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (draw_outline) {
|
|
|
|
int i, j;
|
|
|
|
selected_font = 0;
|
2008-02-20 20:30:45 +00:00
|
|
|
|
2009-02-14 12:03:11 +00:00
|
|
|
for (i = -1; i < 2; i++) {
|
|
|
|
for (j = -1; j < 2; j++) {
|
|
|
|
if (i == 0 && j == 0) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
text_start_x += i;
|
|
|
|
text_start_y += j;
|
|
|
|
set_foreground_color(default_out_color);
|
|
|
|
draw_mode = OUTLINE;
|
|
|
|
draw_text();
|
|
|
|
text_start_x -= i;
|
|
|
|
text_start_y -= j;
|
2008-02-20 20:30:45 +00:00
|
|
|
}
|
2005-07-20 00:30:40 +00:00
|
|
|
}
|
2008-02-20 20:30:45 +00:00
|
|
|
}
|
2005-07-20 00:30:40 +00:00
|
|
|
|
2009-02-14 12:03:11 +00:00
|
|
|
set_foreground_color(default_fg_color);
|
|
|
|
}
|
2005-08-08 01:18:52 +00:00
|
|
|
#endif /* X11 */
|
2008-06-04 22:35:02 +00:00
|
|
|
draw_mode = FG;
|
2005-07-20 00:30:40 +00:00
|
|
|
draw_text();
|
2005-08-08 01:18:52 +00:00
|
|
|
#ifdef X11
|
2009-02-21 23:37:15 +00:00
|
|
|
if (output_methods & TO_X) {
|
2006-11-07 02:19:58 +00:00
|
|
|
#ifdef HAVE_XDBE
|
2009-02-14 12:03:11 +00:00
|
|
|
if (use_xdbe) {
|
|
|
|
XdbeSwapInfo swap;
|
2008-02-20 20:30:45 +00:00
|
|
|
|
2009-02-14 12:03:11 +00:00
|
|
|
swap.swap_window = window.window;
|
|
|
|
swap.swap_action = XdbeBackground;
|
|
|
|
XdbeSwapBuffers(display, &swap, 1);
|
|
|
|
}
|
2005-07-20 00:30:40 +00:00
|
|
|
#endif
|
2009-02-14 12:03:11 +00:00
|
|
|
}
|
2005-08-08 01:18:52 +00:00
|
|
|
#endif /* X11 */
|
2009-02-21 23:37:15 +00:00
|
|
|
if(overwrite_fpointer) {
|
|
|
|
fclose(overwrite_fpointer);
|
|
|
|
overwrite_fpointer = 0;
|
|
|
|
}
|
|
|
|
if(append_fpointer) {
|
|
|
|
fclose(append_fpointer);
|
|
|
|
append_fpointer = 0;
|
|
|
|
}
|
2005-07-20 00:30:40 +00:00
|
|
|
}
|
2008-02-20 20:30:45 +00:00
|
|
|
|
2005-08-08 01:18:52 +00:00
|
|
|
#ifdef X11
|
2005-07-20 00:30:40 +00:00
|
|
|
static void clear_text(int exposures)
|
|
|
|
{
|
2006-11-07 02:19:58 +00:00
|
|
|
#ifdef HAVE_XDBE
|
2005-08-29 17:06:31 +00:00
|
|
|
if (use_xdbe) {
|
2008-02-20 20:30:45 +00:00
|
|
|
/* The swap action is XdbeBackground, which clears */
|
|
|
|
return;
|
2005-09-11 23:07:28 +00:00
|
|
|
} else
|
2005-07-20 00:30:40 +00:00
|
|
|
#endif
|
2005-09-11 23:07:28 +00:00
|
|
|
{
|
2008-02-20 20:30:45 +00:00
|
|
|
/* there is some extra space for borders and outlines */
|
|
|
|
XClearArea(display, window.window, text_start_x - border_margin - 1,
|
|
|
|
text_start_y - border_margin - 1,
|
|
|
|
text_width + border_margin * 2 + 2,
|
|
|
|
text_height + border_margin * 2 + 2, exposures ? True : 0);
|
2005-09-11 23:07:28 +00:00
|
|
|
}
|
2005-07-20 00:30:40 +00:00
|
|
|
}
|
2005-08-08 01:18:52 +00:00
|
|
|
#endif /* X11 */
|
2005-07-20 00:30:40 +00:00
|
|
|
|
|
|
|
static int need_to_update;
|
|
|
|
|
|
|
|
/* update_text() generates new text and clears old text area */
|
2008-03-29 02:01:03 +00:00
|
|
|
static void update_text(void)
|
2005-07-20 00:30:40 +00:00
|
|
|
{
|
|
|
|
generate_text();
|
2005-08-08 01:18:52 +00:00
|
|
|
#ifdef X11
|
2009-02-21 23:37:15 +00:00
|
|
|
if (output_methods & TO_X)
|
|
|
|
clear_text(1);
|
2005-08-08 01:18:52 +00:00
|
|
|
#endif /* X11 */
|
2005-07-20 00:30:40 +00:00
|
|
|
need_to_update = 1;
|
|
|
|
}
|
|
|
|
|
2008-03-29 02:01:03 +00:00
|
|
|
static void main_loop(void)
|
2005-07-20 00:30:40 +00:00
|
|
|
{
|
2005-11-24 02:18:42 +00:00
|
|
|
#ifdef SIGNAL_BLOCKING
|
2008-09-26 21:09:48 +00:00
|
|
|
sigset_t newmask, oldmask;
|
2005-11-24 02:18:42 +00:00
|
|
|
#endif
|
2008-09-12 03:01:33 +00:00
|
|
|
double t;
|
2005-08-08 01:18:52 +00:00
|
|
|
#ifdef X11
|
2009-02-14 12:03:11 +00:00
|
|
|
Region region;
|
2006-08-01 21:24:15 +00:00
|
|
|
#ifdef HAVE_XDAMAGE
|
2008-03-29 06:24:04 +00:00
|
|
|
Damage damage;
|
|
|
|
XserverRegion region2, part;
|
2006-11-07 01:19:32 +00:00
|
|
|
int event_base, error_base;
|
2009-02-14 12:03:11 +00:00
|
|
|
#endif
|
2009-02-21 23:37:15 +00:00
|
|
|
if (output_methods & TO_X) {
|
2009-02-14 12:03:11 +00:00
|
|
|
region = XCreateRegion();
|
|
|
|
#ifdef HAVE_XDAMAGE
|
|
|
|
if (!XDamageQueryExtension(display, &event_base, &error_base)) {
|
|
|
|
ERR("Xdamage extension unavailable");
|
|
|
|
}
|
|
|
|
damage = XDamageCreate(display, window.window, XDamageReportNonEmpty);
|
|
|
|
region2 = XFixesCreateRegionFromWindow(display, window.window, 0);
|
|
|
|
part = XFixesCreateRegionFromWindow(display, window.window, 0);
|
2006-08-01 21:24:15 +00:00
|
|
|
#endif /* HAVE_XDAMAGE */
|
2009-02-14 12:03:11 +00:00
|
|
|
}
|
2005-08-08 01:18:52 +00:00
|
|
|
#endif /* X11 */
|
|
|
|
|
2008-03-29 06:24:04 +00:00
|
|
|
#ifdef SIGNAL_BLOCKING
|
|
|
|
sigemptyset(&newmask);
|
|
|
|
sigaddset(&newmask, SIGINT);
|
|
|
|
sigaddset(&newmask, SIGTERM);
|
|
|
|
sigaddset(&newmask, SIGUSR1);
|
|
|
|
#endif
|
|
|
|
|
2008-09-12 03:01:33 +00:00
|
|
|
next_update_time = last_update_time = get_time();
|
2005-07-25 00:22:16 +00:00
|
|
|
info.looped = 0;
|
2006-08-24 18:14:22 +00:00
|
|
|
while (total_run_times == 0 || info.looped < total_run_times) {
|
2005-07-20 00:30:40 +00:00
|
|
|
info.looped++;
|
2005-11-23 19:05:23 +00:00
|
|
|
|
2005-11-24 02:18:42 +00:00
|
|
|
#ifdef SIGNAL_BLOCKING
|
2005-11-23 19:05:23 +00:00
|
|
|
/* block signals. we will inspect for pending signals later */
|
2008-02-20 20:30:45 +00:00
|
|
|
if (sigprocmask(SIG_BLOCK, &newmask, &oldmask) < 0) {
|
2005-11-23 19:05:23 +00:00
|
|
|
CRIT_ERR("unable to sigprocmask()");
|
2008-02-20 20:30:45 +00:00
|
|
|
}
|
2005-11-24 02:18:42 +00:00
|
|
|
#endif
|
2005-11-23 19:05:23 +00:00
|
|
|
|
2005-08-08 01:18:52 +00:00
|
|
|
#ifdef X11
|
2009-02-21 23:37:15 +00:00
|
|
|
if (output_methods & TO_X) {
|
2009-02-14 12:03:11 +00:00
|
|
|
XFlush(display);
|
2005-07-20 00:30:40 +00:00
|
|
|
|
2009-02-14 12:03:11 +00:00
|
|
|
/* wait for X event or timeout */
|
2005-07-20 00:30:40 +00:00
|
|
|
|
2009-02-14 12:03:11 +00:00
|
|
|
if (!XPending(display)) {
|
|
|
|
fd_set fdsr;
|
|
|
|
struct timeval tv;
|
|
|
|
int s;
|
|
|
|
t = next_update_time - get_time();
|
2005-07-20 00:30:40 +00:00
|
|
|
|
2009-02-14 12:03:11 +00:00
|
|
|
if (t < 0) {
|
|
|
|
t = 0;
|
|
|
|
} else if (t > update_interval) {
|
|
|
|
t = update_interval;
|
|
|
|
}
|
2005-07-20 00:30:40 +00:00
|
|
|
|
2009-02-14 12:03:11 +00:00
|
|
|
tv.tv_sec = (long) t;
|
|
|
|
tv.tv_usec = (long) (t * 1000000) % 1000000;
|
|
|
|
FD_ZERO(&fdsr);
|
|
|
|
FD_SET(ConnectionNumber(display), &fdsr);
|
2005-07-20 00:30:40 +00:00
|
|
|
|
2009-02-14 12:03:11 +00:00
|
|
|
s = select(ConnectionNumber(display) + 1, &fdsr, 0, 0, &tv);
|
|
|
|
if (s == -1) {
|
|
|
|
if (errno != EINTR) {
|
|
|
|
ERR("can't select(): %s", strerror(errno));
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* timeout */
|
|
|
|
if (s == 0) {
|
|
|
|
update_text();
|
|
|
|
}
|
2008-02-20 20:30:45 +00:00
|
|
|
}
|
2005-07-20 00:30:40 +00:00
|
|
|
}
|
2008-02-20 20:30:45 +00:00
|
|
|
|
2009-02-14 12:03:11 +00:00
|
|
|
if (need_to_update) {
|
2005-07-20 00:30:40 +00:00
|
|
|
#ifdef OWN_WINDOW
|
2009-02-14 12:03:11 +00:00
|
|
|
int wx = window.x, wy = window.y;
|
2005-07-20 00:30:40 +00:00
|
|
|
#endif
|
|
|
|
|
2009-02-14 12:03:11 +00:00
|
|
|
need_to_update = 0;
|
|
|
|
selected_font = 0;
|
|
|
|
update_text_area();
|
2005-07-20 00:30:40 +00:00
|
|
|
#ifdef OWN_WINDOW
|
2009-02-14 12:03:11 +00:00
|
|
|
if (own_window) {
|
|
|
|
/* resize window if it isn't right size */
|
|
|
|
if (!fixed_size
|
2008-02-20 20:30:45 +00:00
|
|
|
&& (text_width + border_margin * 2 + 1 != window.width
|
|
|
|
|| text_height + border_margin * 2 + 1 != window.height)) {
|
2009-02-14 12:03:11 +00:00
|
|
|
window.width = text_width + border_margin * 2 + 1;
|
|
|
|
window.height = text_height + border_margin * 2 + 1;
|
|
|
|
XResizeWindow(display, window.window, window.width,
|
|
|
|
window.height);
|
|
|
|
if (own_window) {
|
|
|
|
set_transparent_background(window.window);
|
|
|
|
}
|
2008-02-20 20:30:45 +00:00
|
|
|
}
|
2005-07-20 00:30:40 +00:00
|
|
|
|
2009-02-14 12:03:11 +00:00
|
|
|
/* move window if it isn't in right position */
|
|
|
|
if (!fixed_pos && (window.x != wx || window.y != wy)) {
|
|
|
|
XMoveWindow(display, window.window, window.x, window.y);
|
|
|
|
}
|
2005-07-20 00:30:40 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2009-02-14 12:03:11 +00:00
|
|
|
clear_text(1);
|
2005-07-20 00:30:40 +00:00
|
|
|
|
2006-11-07 02:19:58 +00:00
|
|
|
#ifdef HAVE_XDBE
|
2009-02-14 12:03:11 +00:00
|
|
|
if (use_xdbe) {
|
|
|
|
XRectangle r;
|
2008-02-20 20:30:45 +00:00
|
|
|
|
2009-02-14 12:03:11 +00:00
|
|
|
r.x = text_start_x - border_margin;
|
|
|
|
r.y = text_start_y - border_margin;
|
|
|
|
r.width = text_width + border_margin * 2;
|
|
|
|
r.height = text_height + border_margin * 2;
|
|
|
|
XUnionRectWithRegion(&r, region, region);
|
|
|
|
}
|
2005-07-20 00:30:40 +00:00
|
|
|
#endif
|
2009-02-14 12:03:11 +00:00
|
|
|
}
|
2005-07-20 00:30:40 +00:00
|
|
|
|
2009-02-14 12:03:11 +00:00
|
|
|
/* handle X events */
|
|
|
|
while (XPending(display)) {
|
|
|
|
XEvent ev;
|
2008-02-20 20:30:45 +00:00
|
|
|
|
2009-02-14 12:03:11 +00:00
|
|
|
XNextEvent(display, &ev);
|
|
|
|
switch (ev.type) {
|
|
|
|
case Expose:
|
|
|
|
{
|
|
|
|
XRectangle r;
|
2008-02-20 20:30:45 +00:00
|
|
|
|
2009-02-14 12:03:11 +00:00
|
|
|
r.x = ev.xexpose.x;
|
|
|
|
r.y = ev.xexpose.y;
|
|
|
|
r.width = ev.xexpose.width;
|
|
|
|
r.height = ev.xexpose.height;
|
|
|
|
XUnionRectWithRegion(&r, region, region);
|
|
|
|
break;
|
|
|
|
}
|
2005-07-20 00:30:40 +00:00
|
|
|
|
|
|
|
#ifdef OWN_WINDOW
|
2009-02-14 12:03:11 +00:00
|
|
|
case ReparentNotify:
|
|
|
|
/* set background to ParentRelative for all parents */
|
|
|
|
if (own_window) {
|
|
|
|
set_transparent_background(window.window);
|
|
|
|
}
|
|
|
|
break;
|
2008-02-20 20:30:45 +00:00
|
|
|
|
2009-02-14 12:03:11 +00:00
|
|
|
case ConfigureNotify:
|
|
|
|
if (own_window) {
|
|
|
|
/* if window size isn't what expected, set fixed size */
|
|
|
|
if (ev.xconfigure.width != window.width
|
|
|
|
|| ev.xconfigure.height != window.height) {
|
|
|
|
if (window.width != 0 && window.height != 0) {
|
|
|
|
fixed_size = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* clear old stuff before screwing up
|
|
|
|
* size and pos */
|
|
|
|
clear_text(1);
|
2008-02-20 20:30:45 +00:00
|
|
|
|
2009-02-14 12:03:11 +00:00
|
|
|
{
|
|
|
|
XWindowAttributes attrs;
|
2008-02-20 20:30:45 +00:00
|
|
|
|
2009-02-14 12:03:11 +00:00
|
|
|
if (XGetWindowAttributes(display,
|
|
|
|
window.window, &attrs)) {
|
|
|
|
window.width = attrs.width;
|
|
|
|
window.height = attrs.height;
|
|
|
|
}
|
|
|
|
}
|
2008-02-20 20:30:45 +00:00
|
|
|
|
2009-02-14 12:03:11 +00:00
|
|
|
text_width = window.width - border_margin * 2 - 1;
|
|
|
|
text_height = window.height - border_margin * 2 - 1;
|
|
|
|
if (text_width > maximum_width
|
|
|
|
&& maximum_width > 0) {
|
|
|
|
text_width = maximum_width;
|
2008-02-20 20:30:45 +00:00
|
|
|
}
|
|
|
|
}
|
2005-07-20 00:30:40 +00:00
|
|
|
|
2009-02-14 12:03:11 +00:00
|
|
|
/* if position isn't what expected, set fixed pos
|
|
|
|
* total_updates avoids setting fixed_pos when window
|
|
|
|
* is set to weird locations when started */
|
|
|
|
/* // this is broken
|
|
|
|
if (total_updates >= 2 && !fixed_pos
|
|
|
|
&& (window.x != ev.xconfigure.x
|
|
|
|
|| window.y != ev.xconfigure.y)
|
|
|
|
&& (ev.xconfigure.x != 0
|
|
|
|
|| ev.xconfigure.y != 0)) {
|
|
|
|
fixed_pos = 1;
|
|
|
|
} */
|
|
|
|
set_font();
|
2005-07-20 00:30:40 +00:00
|
|
|
}
|
2009-02-14 12:03:11 +00:00
|
|
|
break;
|
2005-07-20 00:30:40 +00:00
|
|
|
|
2009-02-14 12:03:11 +00:00
|
|
|
case ButtonPress:
|
|
|
|
if (own_window) {
|
|
|
|
/* if an ordinary window with decorations */
|
|
|
|
if ((window.type == TYPE_NORMAL)
|
2008-02-20 20:30:45 +00:00
|
|
|
&& (!TEST_HINT(window.hints,
|
|
|
|
HINT_UNDECORATED))) {
|
2009-02-14 12:03:11 +00:00
|
|
|
/* allow conky to hold input focus. */
|
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
/* forward the click to the desktop window */
|
|
|
|
XUngrabPointer(display, ev.xbutton.time);
|
|
|
|
ev.xbutton.window = window.desktop;
|
|
|
|
XSendEvent(display, ev.xbutton.window, False,
|
|
|
|
ButtonPressMask, &ev);
|
|
|
|
XSetInputFocus(display, ev.xbutton.window,
|
|
|
|
RevertToParent, ev.xbutton.time);
|
|
|
|
}
|
2008-02-20 20:30:45 +00:00
|
|
|
}
|
2009-02-14 12:03:11 +00:00
|
|
|
break;
|
2006-03-08 23:02:28 +00:00
|
|
|
|
2009-02-14 12:03:11 +00:00
|
|
|
case ButtonRelease:
|
|
|
|
if (own_window) {
|
|
|
|
/* if an ordinary window with decorations */
|
|
|
|
if ((window.type == TYPE_NORMAL)
|
|
|
|
&& (!TEST_HINT(window.hints,
|
|
|
|
HINT_UNDECORATED))) {
|
|
|
|
/* allow conky to hold input focus. */
|
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
/* forward the release to the desktop window */
|
|
|
|
ev.xbutton.window = window.desktop;
|
|
|
|
XSendEvent(display, ev.xbutton.window, False,
|
|
|
|
ButtonReleaseMask, &ev);
|
|
|
|
}
|
2008-02-20 20:30:45 +00:00
|
|
|
}
|
2009-02-14 12:03:11 +00:00
|
|
|
break;
|
2006-03-08 23:02:28 +00:00
|
|
|
|
2005-07-20 00:30:40 +00:00
|
|
|
#endif
|
|
|
|
|
2009-02-14 12:03:11 +00:00
|
|
|
default:
|
2006-08-01 21:24:15 +00:00
|
|
|
#ifdef HAVE_XDAMAGE
|
2009-02-14 12:03:11 +00:00
|
|
|
if (ev.type == event_base + XDamageNotify) {
|
|
|
|
XDamageNotifyEvent *dev = (XDamageNotifyEvent *) &ev;
|
2008-02-20 20:30:45 +00:00
|
|
|
|
2009-02-14 12:03:11 +00:00
|
|
|
XFixesSetRegion(display, part, &dev->area, 1);
|
|
|
|
XFixesUnionRegion(display, region2, region2, part);
|
|
|
|
}
|
2006-08-01 21:24:15 +00:00
|
|
|
#endif /* HAVE_XDAMAGE */
|
2009-02-14 12:03:11 +00:00
|
|
|
break;
|
|
|
|
}
|
2005-07-20 00:30:40 +00:00
|
|
|
}
|
2008-02-20 20:30:45 +00:00
|
|
|
|
2006-10-02 08:33:08 +00:00
|
|
|
#ifdef HAVE_XDAMAGE
|
2009-02-14 12:03:11 +00:00
|
|
|
XDamageSubtract(display, damage, region2, None);
|
|
|
|
XFixesSetRegion(display, region2, 0, 0);
|
2006-10-02 08:33:08 +00:00
|
|
|
#endif /* HAVE_XDAMAGE */
|
2005-07-20 00:30:40 +00:00
|
|
|
|
2009-02-14 12:03:11 +00:00
|
|
|
/* XDBE doesn't seem to provide a way to clear the back buffer without
|
|
|
|
* interfering with the front buffer, other than passing XdbeBackground
|
|
|
|
* to XdbeSwapBuffers. That means that if we're using XDBE, we need to
|
|
|
|
* redraw the text even if it wasn't part of the exposed area. OTOH,
|
|
|
|
* if we're not going to call draw_stuff at all, then no swap happens
|
|
|
|
* and we can safely do nothing. */
|
2005-07-20 00:30:40 +00:00
|
|
|
|
2009-02-14 12:03:11 +00:00
|
|
|
if (!XEmptyRegion(region)) {
|
2006-11-07 02:19:58 +00:00
|
|
|
#ifdef HAVE_XDBE
|
2009-02-14 12:03:11 +00:00
|
|
|
if (use_xdbe) {
|
|
|
|
XRectangle r;
|
2008-02-20 20:30:45 +00:00
|
|
|
|
2009-02-14 12:03:11 +00:00
|
|
|
r.x = text_start_x - border_margin;
|
|
|
|
r.y = text_start_y - border_margin;
|
|
|
|
r.width = text_width + border_margin * 2;
|
|
|
|
r.height = text_height + border_margin * 2;
|
|
|
|
XUnionRectWithRegion(&r, region, region);
|
|
|
|
}
|
2005-07-20 00:30:40 +00:00
|
|
|
#endif
|
2009-02-14 12:03:11 +00:00
|
|
|
XSetRegion(display, window.gc, region);
|
2005-07-20 00:30:40 +00:00
|
|
|
#ifdef XFT
|
2009-02-14 12:03:11 +00:00
|
|
|
if (use_xft) {
|
|
|
|
XftDrawSetClip(window.xftdraw, region);
|
|
|
|
}
|
2005-07-20 00:30:40 +00:00
|
|
|
#endif
|
2009-02-14 12:03:11 +00:00
|
|
|
draw_stuff();
|
|
|
|
XDestroyRegion(region);
|
|
|
|
region = XCreateRegion();
|
|
|
|
}
|
2009-02-21 23:37:15 +00:00
|
|
|
} else {
|
2005-08-08 01:18:52 +00:00
|
|
|
#endif /* X11 */
|
2009-02-14 12:03:11 +00:00
|
|
|
t = (next_update_time - get_time()) * 1000000;
|
|
|
|
if(t > 0) usleep((useconds_t)t);
|
|
|
|
update_text();
|
2005-07-20 00:30:40 +00:00
|
|
|
draw_stuff();
|
2005-08-08 01:18:52 +00:00
|
|
|
#ifdef X11
|
2005-07-20 00:30:40 +00:00
|
|
|
}
|
2005-08-08 01:18:52 +00:00
|
|
|
#endif /* X11 */
|
|
|
|
|
2005-11-24 02:18:42 +00:00
|
|
|
#ifdef SIGNAL_BLOCKING
|
2005-11-23 19:05:23 +00:00
|
|
|
/* unblock signals of interest and let handler fly */
|
2008-02-20 20:30:45 +00:00
|
|
|
if (sigprocmask(SIG_SETMASK, &oldmask, NULL) < 0) {
|
2005-11-23 19:05:23 +00:00
|
|
|
CRIT_ERR("unable to sigprocmask()");
|
2008-02-20 20:30:45 +00:00
|
|
|
}
|
2005-11-24 02:18:42 +00:00
|
|
|
#endif
|
2005-11-23 19:05:23 +00:00
|
|
|
|
2008-02-20 20:30:45 +00:00
|
|
|
switch (g_signal_pending) {
|
2008-03-18 00:23:16 +00:00
|
|
|
case SIGHUP:
|
2008-02-20 20:30:45 +00:00
|
|
|
case SIGUSR1:
|
2008-03-18 00:23:16 +00:00
|
|
|
ERR("received SIGHUP or SIGUSR1. reloading the config file.");
|
2008-02-20 20:30:45 +00:00
|
|
|
reload_config();
|
|
|
|
break;
|
|
|
|
case SIGINT:
|
|
|
|
case SIGTERM:
|
|
|
|
ERR("received SIGINT or SIGTERM to terminate. bye!");
|
|
|
|
clean_up();
|
2005-11-10 04:19:43 +00:00
|
|
|
#ifdef X11
|
2009-02-21 23:37:15 +00:00
|
|
|
if (output_methods & TO_X) {
|
2009-02-14 12:03:11 +00:00
|
|
|
XDestroyRegion(region);
|
|
|
|
region = NULL;
|
2008-03-20 05:28:23 +00:00
|
|
|
#ifdef HAVE_XDAMAGE
|
2009-02-14 12:03:11 +00:00
|
|
|
XDamageDestroy(display, damage);
|
|
|
|
XFixesDestroyRegion(display, region2);
|
|
|
|
XFixesDestroyRegion(display, part);
|
2008-03-20 05:28:23 +00:00
|
|
|
#endif /* HAVE_XDAMAGE */
|
2009-02-14 12:03:11 +00:00
|
|
|
}
|
2005-11-10 04:19:43 +00:00
|
|
|
#endif /* X11 */
|
2009-02-21 23:37:15 +00:00
|
|
|
if(overwrite_file) {
|
|
|
|
free(overwrite_file);
|
|
|
|
overwrite_file = 0;
|
|
|
|
}
|
|
|
|
if(append_file) {
|
|
|
|
free(append_file);
|
|
|
|
append_file = 0;
|
|
|
|
}
|
2008-02-20 20:30:45 +00:00
|
|
|
return; /* return from main_loop */
|
|
|
|
/* break; */
|
|
|
|
default:
|
|
|
|
/* Reaching here means someone set a signal
|
|
|
|
* (SIGXXXX, signal_handler), but didn't write any code
|
|
|
|
* to deal with it.
|
|
|
|
* If you don't want to handle a signal, don't set a handler on
|
|
|
|
* it in the first place. */
|
|
|
|
if (g_signal_pending) {
|
|
|
|
ERR("ignoring signal (%d)", g_signal_pending);
|
|
|
|
}
|
|
|
|
break;
|
2005-11-01 06:51:48 +00:00
|
|
|
}
|
2008-02-20 20:30:45 +00:00
|
|
|
g_signal_pending = 0;
|
2005-07-20 00:30:40 +00:00
|
|
|
}
|
2008-02-20 20:30:45 +00:00
|
|
|
|
2006-08-01 21:24:15 +00:00
|
|
|
#if defined(X11) && defined(HAVE_XDAMAGE)
|
2009-02-21 23:37:15 +00:00
|
|
|
if (output_methods & TO_X) {
|
2009-02-14 12:03:11 +00:00
|
|
|
XDamageDestroy(display, damage);
|
|
|
|
XFixesDestroyRegion(display, region2);
|
|
|
|
XFixesDestroyRegion(display, part);
|
|
|
|
XDestroyRegion(region);
|
|
|
|
region = NULL;
|
|
|
|
}
|
2006-08-01 21:24:15 +00:00
|
|
|
#endif /* X11 && HAVE_XDAMAGE */
|
2005-07-20 00:30:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void load_config_file(const char *);
|
2009-04-01 17:06:31 +00:00
|
|
|
static void load_config_file_x11(const char *);
|
2005-07-20 00:30:40 +00:00
|
|
|
|
2005-11-01 06:51:48 +00:00
|
|
|
/* reload the config file */
|
2008-12-15 21:40:24 +00:00
|
|
|
static void reload_config(void)
|
2005-07-20 00:30:40 +00:00
|
|
|
{
|
2008-02-20 20:30:45 +00:00
|
|
|
timed_thread_destroy_registered_threads();
|
2006-11-15 01:20:49 +00:00
|
|
|
|
2006-05-22 03:29:19 +00:00
|
|
|
if (info.cpu_usage) {
|
|
|
|
free(info.cpu_usage);
|
|
|
|
info.cpu_usage = NULL;
|
|
|
|
}
|
2008-02-20 20:30:45 +00:00
|
|
|
|
2007-09-02 03:58:22 +00:00
|
|
|
if (info.mail) {
|
|
|
|
free(info.mail);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef X11
|
|
|
|
free_fonts();
|
|
|
|
#endif /* X11 */
|
2006-11-15 01:20:49 +00:00
|
|
|
|
2006-01-27 21:30:56 +00:00
|
|
|
#ifdef TCP_PORT_MONITOR
|
2008-12-09 13:44:14 +00:00
|
|
|
tcp_portmon_clear();
|
2006-01-27 21:30:56 +00:00
|
|
|
#endif
|
|
|
|
|
2005-07-20 00:30:40 +00:00
|
|
|
if (current_config) {
|
|
|
|
clear_fs_stats();
|
|
|
|
load_config_file(current_config);
|
2009-04-01 17:06:31 +00:00
|
|
|
load_config_file_x11(current_config);
|
2006-11-22 21:53:54 +00:00
|
|
|
|
|
|
|
/* re-init specials array */
|
2008-02-20 20:30:45 +00:00
|
|
|
if ((specials = realloc((void *) specials,
|
|
|
|
sizeof(struct special_t) * max_specials)) == 0) {
|
|
|
|
ERR("failed to realloc specials array");
|
|
|
|
}
|
2006-11-22 21:53:54 +00:00
|
|
|
|
2005-08-08 01:18:52 +00:00
|
|
|
#ifdef X11
|
2008-04-10 22:45:45 +00:00
|
|
|
load_fonts();
|
|
|
|
set_font();
|
2008-02-20 20:30:45 +00:00
|
|
|
// clear the window first
|
|
|
|
XClearWindow(display, RootWindow(display, screen));
|
2009-03-19 19:40:49 +00:00
|
|
|
x_initialised = NO;
|
2005-10-22 01:37:44 +00:00
|
|
|
|
2005-08-08 01:18:52 +00:00
|
|
|
#endif /* X11 */
|
2008-06-21 09:24:56 +00:00
|
|
|
extract_variable_text(global_text);
|
|
|
|
free(global_text);
|
|
|
|
global_text = NULL;
|
2008-03-20 05:28:23 +00:00
|
|
|
if (tmpstring1) {
|
|
|
|
free(tmpstring1);
|
|
|
|
}
|
2008-03-20 21:28:19 +00:00
|
|
|
tmpstring1 = malloc(text_buffer_size);
|
|
|
|
memset(tmpstring1, 0, text_buffer_size);
|
2008-03-20 05:28:23 +00:00
|
|
|
if (tmpstring2) {
|
|
|
|
free(tmpstring2);
|
|
|
|
}
|
2008-03-20 21:28:19 +00:00
|
|
|
tmpstring2 = malloc(text_buffer_size);
|
|
|
|
memset(tmpstring2, 0, text_buffer_size);
|
2008-03-20 05:28:23 +00:00
|
|
|
if (text_buffer) {
|
|
|
|
free(text_buffer);
|
|
|
|
}
|
2008-03-20 21:28:19 +00:00
|
|
|
text_buffer = malloc(max_user_text);
|
|
|
|
memset(text_buffer, 0, max_user_text);
|
2005-07-20 00:30:40 +00:00
|
|
|
update_text();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-12-15 21:40:24 +00:00
|
|
|
static void clean_up(void)
|
2005-07-20 00:30:40 +00:00
|
|
|
{
|
2008-02-20 20:30:45 +00:00
|
|
|
timed_thread_destroy_registered_threads();
|
2006-11-15 01:20:49 +00:00
|
|
|
|
2006-05-22 03:29:19 +00:00
|
|
|
if (info.cpu_usage) {
|
|
|
|
free(info.cpu_usage);
|
|
|
|
info.cpu_usage = NULL;
|
|
|
|
}
|
2005-08-08 01:18:52 +00:00
|
|
|
#ifdef X11
|
2009-02-21 23:37:15 +00:00
|
|
|
if (output_methods & TO_X) {
|
2006-11-07 02:19:58 +00:00
|
|
|
#ifdef HAVE_XDBE
|
2009-02-14 12:03:11 +00:00
|
|
|
if (use_xdbe) {
|
|
|
|
XdbeDeallocateBackBufferName(display, window.back_buffer);
|
|
|
|
}
|
2005-07-20 00:30:40 +00:00
|
|
|
#endif
|
|
|
|
#ifdef OWN_WINDOW
|
2009-02-14 12:03:11 +00:00
|
|
|
if (own_window) {
|
|
|
|
XDestroyWindow(display, window.window);
|
|
|
|
XClearWindow(display, RootWindow(display, screen));
|
|
|
|
XFlush(display);
|
|
|
|
} else
|
2005-07-20 00:30:40 +00:00
|
|
|
#endif
|
2009-02-14 12:03:11 +00:00
|
|
|
{
|
|
|
|
XClearWindow(display, RootWindow(display, screen));
|
|
|
|
clear_text(1);
|
|
|
|
XFlush(display);
|
|
|
|
}
|
2005-07-20 00:30:40 +00:00
|
|
|
|
2009-02-14 12:03:11 +00:00
|
|
|
XFreeGC(display, window.gc);
|
|
|
|
free_fonts();
|
|
|
|
}
|
2005-08-08 01:18:52 +00:00
|
|
|
#endif /* X11 */
|
|
|
|
|
2008-12-18 12:37:53 +00:00
|
|
|
free_text_objects(&global_root_object);
|
2008-03-20 20:33:31 +00:00
|
|
|
if (tmpstring1) {
|
|
|
|
free(tmpstring1);
|
|
|
|
tmpstring1 = 0;
|
|
|
|
}
|
|
|
|
if (tmpstring2) {
|
|
|
|
free(tmpstring2);
|
|
|
|
tmpstring2 = 0;
|
|
|
|
}
|
|
|
|
if (text_buffer) {
|
|
|
|
free(text_buffer);
|
|
|
|
text_buffer = 0;
|
|
|
|
}
|
2005-12-10 14:15:38 +00:00
|
|
|
|
2008-06-21 09:24:56 +00:00
|
|
|
if (global_text) {
|
|
|
|
free(global_text);
|
|
|
|
global_text = 0;
|
2008-02-20 20:30:45 +00:00
|
|
|
}
|
2005-07-20 00:30:40 +00:00
|
|
|
|
|
|
|
free(current_config);
|
2006-11-22 21:53:54 +00:00
|
|
|
|
2005-10-31 05:17:06 +00:00
|
|
|
#ifdef TCP_PORT_MONITOR
|
2008-12-09 13:44:14 +00:00
|
|
|
tcp_portmon_clear();
|
2005-10-31 05:17:06 +00:00
|
|
|
#endif
|
2007-06-03 11:20:47 +00:00
|
|
|
#ifdef RSS
|
|
|
|
free_rss_info();
|
|
|
|
#endif
|
2006-11-22 21:53:54 +00:00
|
|
|
|
|
|
|
if (specials) {
|
2007-06-03 11:20:47 +00:00
|
|
|
unsigned int i;
|
2008-02-20 20:30:45 +00:00
|
|
|
|
|
|
|
for (i = 0; i < special_count; i++) {
|
|
|
|
if (specials[i].type == GRAPH) {
|
2007-06-03 11:20:47 +00:00
|
|
|
free(specials[i].graph);
|
2008-02-20 20:30:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
free(specials);
|
|
|
|
specials = NULL;
|
2006-11-22 21:53:54 +00:00
|
|
|
}
|
2008-02-09 02:21:06 +00:00
|
|
|
|
|
|
|
clear_diskio_stats();
|
2005-07-20 00:30:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int string_to_bool(const char *s)
|
|
|
|
{
|
2008-02-20 20:30:45 +00:00
|
|
|
if (!s) {
|
2008-06-21 09:24:39 +00:00
|
|
|
// Assumes an option without a true/false means true
|
2008-02-24 16:35:18 +00:00
|
|
|
return 1;
|
2008-06-21 20:37:58 +00:00
|
|
|
} else if (strcasecmp(s, "yes") == EQUAL) {
|
2008-02-24 16:35:18 +00:00
|
|
|
return 1;
|
2008-06-21 20:37:58 +00:00
|
|
|
} else if (strcasecmp(s, "true") == EQUAL) {
|
2008-02-24 16:35:18 +00:00
|
|
|
return 1;
|
2008-06-21 20:37:58 +00:00
|
|
|
} else if (strcasecmp(s, "1") == EQUAL) {
|
2008-02-24 16:35:18 +00:00
|
|
|
return 1;
|
2008-02-20 20:30:45 +00:00
|
|
|
}
|
2008-02-24 16:35:18 +00:00
|
|
|
return 0;
|
2005-07-20 00:30:40 +00:00
|
|
|
}
|
2008-02-20 20:30:45 +00:00
|
|
|
|
2005-08-08 01:18:52 +00:00
|
|
|
#ifdef X11
|
2005-07-20 00:30:40 +00:00
|
|
|
static enum alignment string_to_alignment(const char *s)
|
|
|
|
{
|
2008-06-21 20:37:58 +00:00
|
|
|
if (strcasecmp(s, "top_left") == EQUAL) {
|
2005-07-20 00:30:40 +00:00
|
|
|
return TOP_LEFT;
|
2008-06-21 20:37:58 +00:00
|
|
|
} else if (strcasecmp(s, "top_right") == EQUAL) {
|
2005-07-20 00:30:40 +00:00
|
|
|
return TOP_RIGHT;
|
2008-06-21 20:37:58 +00:00
|
|
|
} else if (strcasecmp(s, "top_middle") == EQUAL) {
|
2008-03-18 00:23:16 +00:00
|
|
|
return TOP_MIDDLE;
|
2008-06-21 20:37:58 +00:00
|
|
|
} else if (strcasecmp(s, "bottom_left") == EQUAL) {
|
2005-07-20 00:30:40 +00:00
|
|
|
return BOTTOM_LEFT;
|
2008-06-21 20:37:58 +00:00
|
|
|
} else if (strcasecmp(s, "bottom_right") == EQUAL) {
|
2005-07-20 00:30:40 +00:00
|
|
|
return BOTTOM_RIGHT;
|
2008-06-21 20:37:58 +00:00
|
|
|
} else if (strcasecmp(s, "bottom_middle") == EQUAL) {
|
2008-03-18 00:23:16 +00:00
|
|
|
return BOTTOM_MIDDLE;
|
2008-06-21 20:37:58 +00:00
|
|
|
} else if (strcasecmp(s, "middle_left") == EQUAL) {
|
2008-03-18 00:23:16 +00:00
|
|
|
return MIDDLE_LEFT;
|
2008-06-21 20:37:58 +00:00
|
|
|
} else if (strcasecmp(s, "middle_right") == EQUAL) {
|
2008-03-18 00:23:16 +00:00
|
|
|
return MIDDLE_RIGHT;
|
2008-06-21 20:37:58 +00:00
|
|
|
} else if (strcasecmp(s, "tl") == EQUAL) {
|
2005-07-20 00:30:40 +00:00
|
|
|
return TOP_LEFT;
|
2008-06-21 20:37:58 +00:00
|
|
|
} else if (strcasecmp(s, "tr") == EQUAL) {
|
2005-07-20 00:30:40 +00:00
|
|
|
return TOP_RIGHT;
|
2008-06-21 20:37:58 +00:00
|
|
|
} else if (strcasecmp(s, "tm") == EQUAL) {
|
2008-03-18 00:23:16 +00:00
|
|
|
return TOP_MIDDLE;
|
2008-06-21 20:37:58 +00:00
|
|
|
} else if (strcasecmp(s, "bl") == EQUAL) {
|
2005-07-20 00:30:40 +00:00
|
|
|
return BOTTOM_LEFT;
|
2008-06-21 20:37:58 +00:00
|
|
|
} else if (strcasecmp(s, "br") == EQUAL) {
|
2005-07-20 00:30:40 +00:00
|
|
|
return BOTTOM_RIGHT;
|
2008-06-21 20:37:58 +00:00
|
|
|
} else if (strcasecmp(s, "bm") == EQUAL) {
|
2008-03-18 00:23:16 +00:00
|
|
|
return BOTTOM_MIDDLE;
|
2008-06-21 20:37:58 +00:00
|
|
|
} else if (strcasecmp(s, "ml") == EQUAL) {
|
2008-03-18 00:23:16 +00:00
|
|
|
return MIDDLE_LEFT;
|
2008-06-21 20:37:58 +00:00
|
|
|
} else if (strcasecmp(s, "mr") == EQUAL) {
|
2008-03-18 00:23:16 +00:00
|
|
|
return MIDDLE_RIGHT;
|
2008-06-21 20:37:58 +00:00
|
|
|
} else if (strcasecmp(s, "none") == EQUAL) {
|
2005-08-20 19:43:06 +00:00
|
|
|
return NONE;
|
2008-02-20 20:30:45 +00:00
|
|
|
}
|
2005-07-20 00:30:40 +00:00
|
|
|
return TOP_LEFT;
|
|
|
|
}
|
2005-08-08 01:18:52 +00:00
|
|
|
#endif /* X11 */
|
|
|
|
|
2009-02-14 12:03:11 +00:00
|
|
|
#ifdef X11
|
|
|
|
static void set_default_configurations_for_x(void)
|
|
|
|
{
|
|
|
|
default_fg_color = WhitePixel(display, screen);
|
|
|
|
default_bg_color = BlackPixel(display, screen);
|
|
|
|
default_out_color = BlackPixel(display, screen);
|
|
|
|
color0 = default_fg_color;
|
|
|
|
color1 = default_fg_color;
|
|
|
|
color2 = default_fg_color;
|
|
|
|
color3 = default_fg_color;
|
|
|
|
color4 = default_fg_color;
|
|
|
|
color5 = default_fg_color;
|
|
|
|
color6 = default_fg_color;
|
|
|
|
color7 = default_fg_color;
|
|
|
|
color8 = default_fg_color;
|
|
|
|
color9 = default_fg_color;
|
|
|
|
}
|
|
|
|
#endif /* X11 */
|
|
|
|
|
2005-07-20 00:30:40 +00:00
|
|
|
static void set_default_configurations(void)
|
|
|
|
{
|
2009-05-08 12:57:19 +00:00
|
|
|
update_uname();
|
2005-07-20 00:30:40 +00:00
|
|
|
fork_to_background = 0;
|
|
|
|
total_run_times = 0;
|
|
|
|
info.cpu_avg_samples = 2;
|
|
|
|
info.net_avg_samples = 2;
|
2009-05-01 23:03:59 +00:00
|
|
|
info.diskio_avg_samples = 2;
|
2005-07-20 00:30:40 +00:00
|
|
|
info.memmax = 0;
|
2005-07-25 00:22:16 +00:00
|
|
|
top_cpu = 0;
|
2008-01-06 01:35:14 +00:00
|
|
|
cpu_separate = 0;
|
2008-02-09 02:21:06 +00:00
|
|
|
short_units = 0;
|
2005-07-25 00:22:16 +00:00
|
|
|
top_mem = 0;
|
2009-02-07 14:01:50 +00:00
|
|
|
top_time = 0;
|
2005-07-20 00:30:40 +00:00
|
|
|
#ifdef MPD
|
2008-12-18 12:37:53 +00:00
|
|
|
mpd_set_host("localhost");
|
|
|
|
mpd_set_port("6600");
|
2006-03-25 21:21:07 +00:00
|
|
|
#endif
|
|
|
|
#ifdef XMMS2
|
2008-02-20 20:30:45 +00:00
|
|
|
info.xmms2.artist = NULL;
|
|
|
|
info.xmms2.album = NULL;
|
|
|
|
info.xmms2.title = NULL;
|
|
|
|
info.xmms2.genre = NULL;
|
|
|
|
info.xmms2.comment = NULL;
|
|
|
|
info.xmms2.url = NULL;
|
|
|
|
info.xmms2.status = NULL;
|
2008-03-18 00:23:16 +00:00
|
|
|
info.xmms2.playlist = NULL;
|
2005-07-20 00:30:40 +00:00
|
|
|
#endif
|
2008-02-09 02:21:06 +00:00
|
|
|
use_spacer = NO_SPACER;
|
2005-08-08 01:18:52 +00:00
|
|
|
#ifdef X11
|
2008-06-21 20:37:58 +00:00
|
|
|
output_methods = TO_X;
|
2005-08-08 01:18:52 +00:00
|
|
|
#else
|
2008-06-21 20:37:58 +00:00
|
|
|
output_methods = TO_STDOUT;
|
2005-08-08 01:18:52 +00:00
|
|
|
#endif
|
|
|
|
#ifdef X11
|
2008-04-13 04:10:35 +00:00
|
|
|
show_graph_scale = 0;
|
2008-06-21 20:37:58 +00:00
|
|
|
show_graph_range = 0;
|
2008-11-29 01:34:54 +00:00
|
|
|
template[0] = strdup("");
|
|
|
|
template[1] = strdup("");
|
|
|
|
template[2] = strdup("");
|
|
|
|
template[3] = strdup("");
|
|
|
|
template[4] = strdup("");
|
|
|
|
template[5] = strdup("");
|
|
|
|
template[6] = strdup("");
|
|
|
|
template[7] = strdup("");
|
|
|
|
template[8] = strdup("");
|
|
|
|
template[9] = strdup("");
|
2005-07-20 00:30:40 +00:00
|
|
|
draw_shades = 1;
|
2006-01-05 23:23:51 +00:00
|
|
|
draw_borders = 0;
|
|
|
|
draw_graph_borders = 1;
|
2005-07-20 00:30:40 +00:00
|
|
|
draw_outline = 0;
|
2005-08-06 04:46:16 +00:00
|
|
|
set_first_font("6x10");
|
2005-07-20 00:30:40 +00:00
|
|
|
gap_x = 5;
|
2007-10-23 21:52:11 +00:00
|
|
|
gap_y = 60;
|
2005-08-08 01:18:52 +00:00
|
|
|
minimum_width = 5;
|
|
|
|
minimum_height = 5;
|
2005-08-24 06:21:50 +00:00
|
|
|
maximum_width = 0;
|
2005-08-08 01:18:52 +00:00
|
|
|
#ifdef OWN_WINDOW
|
|
|
|
own_window = 0;
|
2008-02-20 20:30:45 +00:00
|
|
|
window.type = TYPE_NORMAL;
|
|
|
|
window.hints = 0;
|
2008-07-12 10:25:05 +00:00
|
|
|
strcpy(window.class_name, PACKAGE_NAME);
|
|
|
|
sprintf(window.title, PACKAGE_NAME" (%s)", info.uname_s.nodename);
|
2005-08-08 01:18:52 +00:00
|
|
|
#endif
|
|
|
|
stippled_borders = 0;
|
|
|
|
border_margin = 3;
|
|
|
|
border_width = 1;
|
|
|
|
text_alignment = BOTTOM_LEFT;
|
2008-06-21 20:37:58 +00:00
|
|
|
info.x11.monitor.number = 1;
|
|
|
|
info.x11.monitor.current = 0;
|
2005-08-08 01:18:52 +00:00
|
|
|
#endif /* X11 */
|
2005-07-20 00:30:40 +00:00
|
|
|
|
|
|
|
free(current_mail_spool);
|
|
|
|
{
|
|
|
|
char buf[256];
|
2008-02-20 20:30:45 +00:00
|
|
|
|
2005-07-20 00:30:40 +00:00
|
|
|
variable_substitute(MAIL_FILE, buf, 256);
|
2008-02-20 20:30:45 +00:00
|
|
|
if (buf[0] != '\0') {
|
2008-04-02 18:44:49 +00:00
|
|
|
current_mail_spool = strndup(buf, text_buffer_size);
|
2008-02-20 20:30:45 +00:00
|
|
|
}
|
2005-07-20 00:30:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
no_buffers = 1;
|
2007-10-21 23:36:53 +00:00
|
|
|
update_interval = 3.0;
|
2008-02-20 20:30:45 +00:00
|
|
|
info.music_player_interval = 1.0;
|
2005-07-20 00:30:40 +00:00
|
|
|
stuff_in_upper_case = 0;
|
2008-03-18 00:23:16 +00:00
|
|
|
info.users.number = 1;
|
2005-11-11 03:28:24 +00:00
|
|
|
|
|
|
|
#ifdef TCP_PORT_MONITOR
|
2008-12-09 13:44:14 +00:00
|
|
|
/* set default connection limit */
|
|
|
|
tcp_portmon_set_max_connections(0);
|
2005-11-11 03:28:24 +00:00
|
|
|
#endif
|
2005-07-20 00:30:40 +00:00
|
|
|
}
|
|
|
|
|
2009-02-21 23:37:15 +00:00
|
|
|
/* returns 1 if you can overwrite or create the file at 'path' */
|
2009-02-12 21:35:00 +00:00
|
|
|
static _Bool overwrite_works(const char *path)
|
|
|
|
{
|
2009-02-21 23:37:15 +00:00
|
|
|
FILE *filepointer;
|
|
|
|
|
|
|
|
if (!(filepointer = fopen(path, "w")))
|
|
|
|
return 0;
|
2009-02-12 21:35:00 +00:00
|
|
|
fclose(filepointer);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2009-02-21 23:37:15 +00:00
|
|
|
/* returns 1 if you can append or create the file at 'path' */
|
2009-02-12 21:45:18 +00:00
|
|
|
static _Bool append_works(const char *path)
|
|
|
|
{
|
2009-02-21 23:37:15 +00:00
|
|
|
FILE *filepointer;
|
|
|
|
|
|
|
|
if (!(filepointer = fopen(path, "a")))
|
|
|
|
return 0;
|
2009-02-12 21:45:18 +00:00
|
|
|
fclose(filepointer);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2009-02-22 02:07:14 +00:00
|
|
|
#ifdef X11
|
2009-02-18 04:45:06 +00:00
|
|
|
static void X11_initialisation(void)
|
|
|
|
{
|
2009-03-19 19:40:49 +00:00
|
|
|
if (x_initialised == YES) return;
|
2009-02-14 12:03:11 +00:00
|
|
|
output_methods |= TO_X;
|
2009-04-01 17:06:31 +00:00
|
|
|
init_X11(disp);
|
2009-02-14 12:03:11 +00:00
|
|
|
set_default_configurations_for_x();
|
|
|
|
x_initialised = YES;
|
|
|
|
}
|
2009-02-22 02:07:14 +00:00
|
|
|
#endif /* X11 */
|
2009-02-14 12:03:11 +00:00
|
|
|
|
2005-07-30 22:59:01 +00:00
|
|
|
#define CONF_ERR ERR("%s: %d: config file error", f, line)
|
2009-04-09 22:00:40 +00:00
|
|
|
#define CONF_ERR2(a) ERR("%s: %d: config file error: %s", f, line, a)
|
2009-05-10 02:10:55 +00:00
|
|
|
#define CONF2(a) if (strcasecmp(name, a) == 0)
|
|
|
|
#define CONF(a) else CONF2(a)
|
|
|
|
#define CONF3(a, b) else if (strcasecmp(name, a) == 0 \
|
|
|
|
|| strcasecmp(name, b) == 0)
|
|
|
|
#define CONF_CONTINUE 1
|
|
|
|
#define CONF_BREAK 2
|
|
|
|
#define CONF_BUFF_SIZE 512
|
2005-07-20 00:30:40 +00:00
|
|
|
|
2009-05-10 02:10:55 +00:00
|
|
|
static FILE *open_config_file(const char *f)
|
|
|
|
{
|
2008-12-14 13:36:44 +00:00
|
|
|
#ifdef CONFIG_OUTPUT
|
|
|
|
if (!strcmp(f, "==builtin==")) {
|
|
|
|
#ifdef HAVE_FOPENCOOKIE
|
2009-05-10 02:10:55 +00:00
|
|
|
return fopencookie(NULL, "r", conf_cookie);
|
|
|
|
#endif /* HAVE_FOPENCOOKIE */
|
2008-12-14 13:36:44 +00:00
|
|
|
} else
|
|
|
|
#endif /* CONFIG_OUTPUT */
|
2009-05-10 02:10:55 +00:00
|
|
|
return fopen(f, "r");
|
|
|
|
}
|
2008-12-14 13:36:44 +00:00
|
|
|
|
2009-05-10 02:10:55 +00:00
|
|
|
static int do_config_step(int *line, FILE *fp, char *buf, char **name, char **value)
|
|
|
|
{
|
|
|
|
char *p, *p2;
|
|
|
|
(*line)++;
|
|
|
|
if (fgets(buf, CONF_BUFF_SIZE, fp) == NULL) {
|
|
|
|
return CONF_BREAK;
|
2008-02-20 20:30:45 +00:00
|
|
|
}
|
2005-07-20 00:30:40 +00:00
|
|
|
|
2009-05-10 02:10:55 +00:00
|
|
|
p = buf;
|
2008-02-20 20:30:45 +00:00
|
|
|
|
2009-05-10 02:10:55 +00:00
|
|
|
/* break at comment, unless preceeded by \ */
|
|
|
|
p2 = strchr(p, '#');
|
|
|
|
if (p2 && (p2 == p || *(p2 - 1) != '\\')) {
|
|
|
|
*p2 = '\0';
|
|
|
|
}
|
|
|
|
|
|
|
|
/* skip spaces */
|
|
|
|
while (*p && isspace((int) *p)) {
|
|
|
|
p++;
|
|
|
|
}
|
|
|
|
if (*p == '\0') {
|
|
|
|
return CONF_CONTINUE; /* empty line */
|
|
|
|
}
|
2005-07-20 00:30:40 +00:00
|
|
|
|
2009-05-10 02:10:55 +00:00
|
|
|
*name = p;
|
2005-07-20 00:30:40 +00:00
|
|
|
|
2009-05-10 02:10:55 +00:00
|
|
|
/* skip name */
|
|
|
|
p2 = p;
|
|
|
|
while (*p2 && !isspace((int) *p2)) {
|
|
|
|
p2++;
|
|
|
|
}
|
|
|
|
if (*p2 != '\0') {
|
|
|
|
*p2 = '\0'; /* break at name's end */
|
|
|
|
p2++;
|
|
|
|
}
|
2005-07-20 00:30:40 +00:00
|
|
|
|
2009-05-10 02:10:55 +00:00
|
|
|
/* get value */
|
|
|
|
if (*p2) {
|
|
|
|
p = p2;
|
2008-02-20 20:30:45 +00:00
|
|
|
while (*p && isspace((int) *p)) {
|
2005-07-20 00:30:40 +00:00
|
|
|
p++;
|
2008-02-20 20:30:45 +00:00
|
|
|
}
|
2005-07-20 00:30:40 +00:00
|
|
|
|
2009-05-10 02:10:55 +00:00
|
|
|
*value = p;
|
2005-07-20 00:30:40 +00:00
|
|
|
|
2009-05-10 02:10:55 +00:00
|
|
|
p2 = *value + strlen(*value);
|
|
|
|
while (isspace((int) *(p2 - 1))) {
|
|
|
|
*--p2 = '\0';
|
2005-07-20 00:30:40 +00:00
|
|
|
}
|
2009-05-10 02:10:55 +00:00
|
|
|
} else {
|
|
|
|
*value = 0;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2005-07-20 00:30:40 +00:00
|
|
|
|
2009-05-10 02:10:55 +00:00
|
|
|
static void load_config_file(const char *f)
|
|
|
|
{
|
|
|
|
int line = 0;
|
|
|
|
FILE *fp;
|
2005-07-20 00:30:40 +00:00
|
|
|
|
2009-05-10 02:10:55 +00:00
|
|
|
set_default_configurations();
|
|
|
|
fp = open_config_file(f);
|
|
|
|
if (!fp) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
DBGP("reading contents from config file '%s'", f);
|
2005-07-20 00:30:40 +00:00
|
|
|
|
2009-05-10 02:10:55 +00:00
|
|
|
while (!feof(fp)) {
|
|
|
|
char buff[CONF_BUFF_SIZE], *name, *value;
|
|
|
|
int ret = do_config_step(&line, fp, buff, &name, &value);
|
|
|
|
if (ret == CONF_BREAK) {
|
|
|
|
break;
|
|
|
|
} else if (ret == CONF_CONTINUE) {
|
|
|
|
continue;
|
2005-07-20 00:30:40 +00:00
|
|
|
}
|
|
|
|
|
2005-08-08 01:18:52 +00:00
|
|
|
#ifdef X11
|
2009-02-14 12:03:11 +00:00
|
|
|
CONF2("out_to_x") {
|
2009-02-21 23:37:15 +00:00
|
|
|
/* don't listen if X is already initialised or
|
|
|
|
* if we already know we don't want it */
|
|
|
|
if(x_initialised == NO) {
|
|
|
|
if (string_to_bool(value)) {
|
2009-03-15 00:17:32 +00:00
|
|
|
output_methods &= TO_X;
|
2009-02-21 23:37:15 +00:00
|
|
|
} else {
|
2009-03-15 00:17:32 +00:00
|
|
|
output_methods &= ~TO_X;
|
2009-02-14 12:03:11 +00:00
|
|
|
x_initialised = NEVER;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-04-01 17:06:31 +00:00
|
|
|
CONF("display") {
|
|
|
|
if (!value || x_initialised == YES) {
|
|
|
|
CONF_ERR;
|
|
|
|
} else {
|
|
|
|
if (disp)
|
|
|
|
free(disp);
|
|
|
|
disp = strdup(value);
|
|
|
|
}
|
|
|
|
}
|
2009-02-14 12:03:11 +00:00
|
|
|
CONF("alignment") {
|
2008-12-07 20:44:56 +00:00
|
|
|
if (window.type == TYPE_DOCK)
|
|
|
|
;
|
|
|
|
else if (value) {
|
2008-02-20 20:30:45 +00:00
|
|
|
int a = string_to_alignment(value);
|
|
|
|
|
|
|
|
if (a <= 0) {
|
|
|
|
CONF_ERR;
|
|
|
|
} else {
|
|
|
|
text_alignment = a;
|
|
|
|
}
|
|
|
|
} else {
|
2005-08-08 00:54:29 +00:00
|
|
|
CONF_ERR;
|
2008-02-20 20:30:45 +00:00
|
|
|
}
|
2005-08-08 00:54:29 +00:00
|
|
|
}
|
2005-07-30 22:59:01 +00:00
|
|
|
CONF("background") {
|
|
|
|
fork_to_background = string_to_bool(value);
|
|
|
|
}
|
2005-08-08 01:18:52 +00:00
|
|
|
#else
|
|
|
|
CONF2("background") {
|
2006-11-11 01:15:28 +00:00
|
|
|
fork_to_background = string_to_bool(value);
|
2005-08-08 01:18:52 +00:00
|
|
|
}
|
|
|
|
#endif /* X11 */
|
|
|
|
#ifdef X11
|
2008-04-13 04:10:35 +00:00
|
|
|
CONF("show_graph_scale") {
|
|
|
|
show_graph_scale = string_to_bool(value);
|
|
|
|
}
|
2008-06-21 20:37:58 +00:00
|
|
|
CONF("show_graph_range") {
|
|
|
|
show_graph_range = string_to_bool(value);
|
|
|
|
}
|
2005-07-30 22:59:01 +00:00
|
|
|
CONF("border_margin") {
|
2008-02-20 20:30:45 +00:00
|
|
|
if (value) {
|
2005-07-30 22:59:01 +00:00
|
|
|
border_margin = strtol(value, 0, 0);
|
2008-02-20 20:30:45 +00:00
|
|
|
} else {
|
2005-07-30 22:59:01 +00:00
|
|
|
CONF_ERR;
|
2008-02-20 20:30:45 +00:00
|
|
|
}
|
2005-07-30 22:59:01 +00:00
|
|
|
}
|
|
|
|
CONF("border_width") {
|
2008-02-20 20:30:45 +00:00
|
|
|
if (value) {
|
2005-07-30 22:59:01 +00:00
|
|
|
border_width = strtol(value, 0, 0);
|
2008-02-20 20:30:45 +00:00
|
|
|
} else {
|
2005-07-30 22:59:01 +00:00
|
|
|
CONF_ERR;
|
2008-02-20 20:30:45 +00:00
|
|
|
}
|
2005-07-30 22:59:01 +00:00
|
|
|
}
|
2008-11-29 01:34:54 +00:00
|
|
|
#define TEMPLATE_CONF(n) \
|
|
|
|
CONF("template"#n) { \
|
|
|
|
if (value) { \
|
|
|
|
free(template[n]); \
|
|
|
|
template[n] = strdup(value); \
|
|
|
|
} else { \
|
|
|
|
CONF_ERR; \
|
|
|
|
} \
|
|
|
|
}
|
|
|
|
TEMPLATE_CONF(0)
|
|
|
|
TEMPLATE_CONF(1)
|
|
|
|
TEMPLATE_CONF(2)
|
|
|
|
TEMPLATE_CONF(3)
|
|
|
|
TEMPLATE_CONF(4)
|
|
|
|
TEMPLATE_CONF(5)
|
|
|
|
TEMPLATE_CONF(6)
|
|
|
|
TEMPLATE_CONF(7)
|
|
|
|
TEMPLATE_CONF(8)
|
|
|
|
TEMPLATE_CONF(9)
|
2005-08-08 01:18:52 +00:00
|
|
|
#endif /* X11 */
|
2006-05-08 22:34:38 +00:00
|
|
|
CONF("imap") {
|
|
|
|
if (value) {
|
2008-12-14 02:53:05 +00:00
|
|
|
info.mail = parse_mail_args(IMAP_TYPE, value);
|
2006-05-08 22:34:38 +00:00
|
|
|
} else {
|
|
|
|
CONF_ERR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
CONF("pop3") {
|
|
|
|
if (value) {
|
2008-12-14 02:53:05 +00:00
|
|
|
info.mail = parse_mail_args(POP3_TYPE, value);
|
2006-05-08 22:34:38 +00:00
|
|
|
} else {
|
|
|
|
CONF_ERR;
|
|
|
|
}
|
|
|
|
}
|
2009-04-09 22:00:40 +00:00
|
|
|
CONF("default_bar_size") {
|
|
|
|
char err = 0;
|
|
|
|
if (value) {
|
|
|
|
if (sscanf(value, "%d %d", &default_bar_width, &default_bar_height) != 2) {
|
|
|
|
err = 1;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
err = 1;
|
|
|
|
}
|
|
|
|
if (err) {
|
|
|
|
CONF_ERR2("default_bar_size takes 2 integer arguments (ie. 'default_bar_size 0 6')")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
CONF("default_graph_size") {
|
|
|
|
char err = 0;
|
|
|
|
if (value) {
|
|
|
|
if (sscanf(value, "%d %d", &default_graph_width, &default_graph_height) != 2) {
|
|
|
|
err = 1;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
err = 1;
|
|
|
|
}
|
|
|
|
if (err) {
|
|
|
|
CONF_ERR2("default_graph_size takes 2 integer arguments (ie. 'default_graph_size 0 6')")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
CONF("default_gauge_size") {
|
|
|
|
char err = 0;
|
|
|
|
if (value) {
|
|
|
|
if (sscanf(value, "%d %d", &default_gauge_width, &default_gauge_height) != 2) {
|
|
|
|
err = 1;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
err = 1;
|
|
|
|
}
|
|
|
|
if (err) {
|
|
|
|
CONF_ERR2("default_gauge_size takes 2 integer arguments (ie. 'default_gauge_size 0 6')")
|
|
|
|
}
|
|
|
|
}
|
2005-07-20 00:30:40 +00:00
|
|
|
#ifdef MPD
|
2005-07-30 22:59:01 +00:00
|
|
|
CONF("mpd_host") {
|
2008-02-20 20:30:45 +00:00
|
|
|
if (value) {
|
2008-12-18 12:37:53 +00:00
|
|
|
mpd_set_host(value);
|
2008-02-20 20:30:45 +00:00
|
|
|
} else {
|
2005-07-30 22:59:01 +00:00
|
|
|
CONF_ERR;
|
2008-02-20 20:30:45 +00:00
|
|
|
}
|
2005-07-30 22:59:01 +00:00
|
|
|
}
|
|
|
|
CONF("mpd_port") {
|
2008-12-18 12:37:53 +00:00
|
|
|
if (value && mpd_set_port(value)) {
|
|
|
|
CONF_ERR;
|
2005-07-30 22:59:01 +00:00
|
|
|
}
|
|
|
|
}
|
2006-01-31 03:32:26 +00:00
|
|
|
CONF("mpd_password") {
|
2008-02-20 20:30:45 +00:00
|
|
|
if (value) {
|
2008-12-18 12:37:53 +00:00
|
|
|
mpd_set_password(value);
|
2008-02-20 20:30:45 +00:00
|
|
|
} else {
|
2006-01-31 03:32:26 +00:00
|
|
|
CONF_ERR;
|
2008-02-20 20:30:45 +00:00
|
|
|
}
|
2007-03-01 01:43:43 +00:00
|
|
|
}
|
|
|
|
#endif
|
2008-02-20 20:30:45 +00:00
|
|
|
CONF("music_player_interval") {
|
|
|
|
if (value) {
|
|
|
|
info.music_player_interval = strtod(value, 0);
|
|
|
|
} else {
|
|
|
|
CONF_ERR;
|
|
|
|
}
|
|
|
|
}
|
2007-03-01 01:43:43 +00:00
|
|
|
#ifdef __OpenBSD__
|
|
|
|
CONF("sensor_device") {
|
2008-02-20 20:30:45 +00:00
|
|
|
if (value) {
|
2007-03-01 01:43:43 +00:00
|
|
|
sensor_device = strtol(value, 0, 0);
|
2008-02-20 20:30:45 +00:00
|
|
|
} else {
|
2007-03-01 01:43:43 +00:00
|
|
|
CONF_ERR;
|
2008-02-20 20:30:45 +00:00
|
|
|
}
|
2006-01-31 03:32:26 +00:00
|
|
|
}
|
2005-07-20 00:30:40 +00:00
|
|
|
#endif
|
2005-07-30 22:59:01 +00:00
|
|
|
CONF("cpu_avg_samples") {
|
|
|
|
if (value) {
|
|
|
|
cpu_avg_samples = strtol(value, 0, 0);
|
2008-02-20 20:30:45 +00:00
|
|
|
if (cpu_avg_samples < 1 || cpu_avg_samples > 14) {
|
2005-07-30 22:59:01 +00:00
|
|
|
CONF_ERR;
|
2008-02-20 20:30:45 +00:00
|
|
|
} else {
|
|
|
|
info.cpu_avg_samples = cpu_avg_samples;
|
|
|
|
}
|
|
|
|
} else {
|
2005-07-30 22:59:01 +00:00
|
|
|
CONF_ERR;
|
2008-02-20 20:30:45 +00:00
|
|
|
}
|
2005-07-30 22:59:01 +00:00
|
|
|
}
|
|
|
|
CONF("net_avg_samples") {
|
|
|
|
if (value) {
|
|
|
|
net_avg_samples = strtol(value, 0, 0);
|
2008-02-20 20:30:45 +00:00
|
|
|
if (net_avg_samples < 1 || net_avg_samples > 14) {
|
2005-07-30 22:59:01 +00:00
|
|
|
CONF_ERR;
|
2008-02-20 20:30:45 +00:00
|
|
|
} else {
|
|
|
|
info.net_avg_samples = net_avg_samples;
|
|
|
|
}
|
|
|
|
} else {
|
2005-07-30 22:59:01 +00:00
|
|
|
CONF_ERR;
|
2008-02-20 20:30:45 +00:00
|
|
|
}
|
2005-07-30 22:59:01 +00:00
|
|
|
}
|
2009-05-01 23:03:59 +00:00
|
|
|
CONF("diskio_avg_samples") {
|
|
|
|
if (value) {
|
|
|
|
diskio_avg_samples = strtol(value, 0, 0);
|
|
|
|
if (diskio_avg_samples < 1 || diskio_avg_samples > 14) {
|
|
|
|
CONF_ERR;
|
|
|
|
} else {
|
|
|
|
info.diskio_avg_samples = diskio_avg_samples;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
CONF_ERR;
|
|
|
|
}
|
|
|
|
}
|
2005-07-30 22:59:01 +00:00
|
|
|
|
2006-11-07 02:19:58 +00:00
|
|
|
#ifdef HAVE_XDBE
|
2005-07-30 22:59:01 +00:00
|
|
|
CONF("double_buffer") {
|
2008-02-20 20:30:45 +00:00
|
|
|
use_xdbe = string_to_bool(value);
|
2005-07-30 22:59:01 +00:00
|
|
|
}
|
2005-07-20 00:30:40 +00:00
|
|
|
#endif
|
2005-08-08 01:18:52 +00:00
|
|
|
#ifdef X11
|
|
|
|
CONF("override_utf8_locale") {
|
2008-02-20 20:30:45 +00:00
|
|
|
utf8_mode = string_to_bool(value);
|
2005-08-08 01:18:52 +00:00
|
|
|
}
|
2005-07-30 22:59:01 +00:00
|
|
|
CONF("draw_borders") {
|
|
|
|
draw_borders = string_to_bool(value);
|
|
|
|
}
|
2006-01-05 23:23:51 +00:00
|
|
|
CONF("draw_graph_borders") {
|
|
|
|
draw_graph_borders = string_to_bool(value);
|
|
|
|
}
|
2005-07-30 22:59:01 +00:00
|
|
|
CONF("draw_shades") {
|
|
|
|
draw_shades = string_to_bool(value);
|
|
|
|
}
|
|
|
|
CONF("draw_outline") {
|
|
|
|
draw_outline = string_to_bool(value);
|
|
|
|
}
|
2005-08-08 01:18:52 +00:00
|
|
|
#endif /* X11 */
|
2005-07-30 22:59:01 +00:00
|
|
|
CONF("out_to_console") {
|
2009-02-21 23:37:15 +00:00
|
|
|
if(string_to_bool(value))
|
|
|
|
output_methods |= TO_STDOUT;
|
2005-07-30 22:59:01 +00:00
|
|
|
}
|
2009-02-10 08:43:20 +00:00
|
|
|
CONF("out_to_stderr") {
|
2009-02-21 23:37:15 +00:00
|
|
|
if(string_to_bool(value))
|
|
|
|
output_methods |= TO_STDERR;
|
2009-02-10 08:43:20 +00:00
|
|
|
}
|
2009-02-12 21:35:00 +00:00
|
|
|
CONF("overwrite_file") {
|
2009-02-21 23:37:15 +00:00
|
|
|
if(overwrite_file) {
|
|
|
|
free(overwrite_file);
|
|
|
|
overwrite_file = 0;
|
|
|
|
}
|
|
|
|
if(overwrite_works(value)) {
|
2009-02-12 21:35:00 +00:00
|
|
|
overwrite_file = strdup(value);
|
|
|
|
output_methods |= OVERWRITE_FILE;
|
2009-02-21 23:37:15 +00:00
|
|
|
} else
|
|
|
|
ERR("overwrite_file won't be able to create/overwrite '%s'", value);
|
2009-02-12 21:35:00 +00:00
|
|
|
}
|
2009-02-12 21:45:18 +00:00
|
|
|
CONF("append_file") {
|
2009-02-21 23:37:15 +00:00
|
|
|
if(append_file) {
|
|
|
|
free(append_file);
|
|
|
|
append_file = 0;
|
|
|
|
}
|
|
|
|
if(append_works(value)) {
|
2009-02-12 21:45:18 +00:00
|
|
|
append_file = strdup(value);
|
|
|
|
output_methods |= APPEND_FILE;
|
2009-02-21 23:37:15 +00:00
|
|
|
} else
|
|
|
|
ERR("append_file won't be able to create/append '%s'", value);
|
2009-02-12 21:45:18 +00:00
|
|
|
}
|
2005-07-30 22:59:01 +00:00
|
|
|
CONF("use_spacer") {
|
2008-02-09 02:21:06 +00:00
|
|
|
if (value) {
|
2008-06-21 20:37:58 +00:00
|
|
|
if (strcasecmp(value, "left") == EQUAL) {
|
2008-02-09 02:21:06 +00:00
|
|
|
use_spacer = LEFT_SPACER;
|
2008-06-21 20:37:58 +00:00
|
|
|
} else if (strcasecmp(value, "right") == EQUAL) {
|
2008-02-09 02:21:06 +00:00
|
|
|
use_spacer = RIGHT_SPACER;
|
2008-06-21 20:37:58 +00:00
|
|
|
} else if (strcasecmp(value, "none") == EQUAL) {
|
2008-02-09 02:21:06 +00:00
|
|
|
use_spacer = NO_SPACER;
|
|
|
|
} else {
|
|
|
|
use_spacer = string_to_bool(value);
|
|
|
|
ERR("use_spacer should have an argument of left, right, or"
|
|
|
|
" none. '%s' seems to be some form of '%s', so"
|
|
|
|
" defaulting to %s.", value,
|
|
|
|
use_spacer ? "true" : "false",
|
|
|
|
use_spacer ? "right" : "none");
|
|
|
|
if (use_spacer) {
|
|
|
|
use_spacer = RIGHT_SPACER;
|
|
|
|
} else {
|
|
|
|
use_spacer = NO_SPACER;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
ERR("use_spacer should have an argument. Defaulting to right.");
|
|
|
|
use_spacer = RIGHT_SPACER;
|
|
|
|
}
|
2005-07-30 22:59:01 +00:00
|
|
|
}
|
2005-08-08 01:18:52 +00:00
|
|
|
#ifdef X11
|
2005-07-20 00:30:40 +00:00
|
|
|
#ifdef XFT
|
2005-07-30 22:59:01 +00:00
|
|
|
CONF("use_xft") {
|
|
|
|
use_xft = string_to_bool(value);
|
|
|
|
}
|
|
|
|
CONF("font") {
|
2009-04-01 17:06:31 +00:00
|
|
|
if (value) {
|
|
|
|
set_first_font(value);
|
2008-02-20 20:30:45 +00:00
|
|
|
}
|
2005-07-30 22:59:01 +00:00
|
|
|
}
|
|
|
|
CONF("xftalpha") {
|
2009-04-01 17:06:31 +00:00
|
|
|
if (value && font_count >= 0) {
|
|
|
|
fonts[0].font_alpha = atof(value) * 65535.0;
|
2008-02-20 20:30:45 +00:00
|
|
|
}
|
2005-07-30 22:59:01 +00:00
|
|
|
}
|
|
|
|
CONF("xftfont") {
|
2006-01-07 11:26:33 +00:00
|
|
|
if (use_xft) {
|
2005-07-20 00:30:40 +00:00
|
|
|
#else
|
2005-07-30 22:59:01 +00:00
|
|
|
CONF("use_xft") {
|
2008-02-20 20:30:45 +00:00
|
|
|
if (string_to_bool(value)) {
|
2005-07-30 22:59:01 +00:00
|
|
|
ERR("Xft not enabled");
|
2008-02-20 20:30:45 +00:00
|
|
|
}
|
2005-07-30 22:59:01 +00:00
|
|
|
}
|
|
|
|
CONF("xftfont") {
|
|
|
|
/* xftfont silently ignored when no Xft */
|
|
|
|
}
|
|
|
|
CONF("xftalpha") {
|
|
|
|
/* xftalpha is silently ignored when no Xft */
|
|
|
|
}
|
|
|
|
CONF("font") {
|
2005-07-20 00:30:40 +00:00
|
|
|
#endif
|
2009-04-01 17:06:31 +00:00
|
|
|
if (value) {
|
|
|
|
set_first_font(value);
|
|
|
|
}
|
2006-01-07 11:26:33 +00:00
|
|
|
#ifdef XFT
|
2005-12-31 17:36:16 +00:00
|
|
|
}
|
2006-01-07 11:26:33 +00:00
|
|
|
#endif
|
2005-07-30 22:59:01 +00:00
|
|
|
}
|
|
|
|
CONF("gap_x") {
|
2008-02-20 20:30:45 +00:00
|
|
|
if (value) {
|
2005-07-30 22:59:01 +00:00
|
|
|
gap_x = atoi(value);
|
2008-02-20 20:30:45 +00:00
|
|
|
} else {
|
2005-07-30 22:59:01 +00:00
|
|
|
CONF_ERR;
|
2008-02-20 20:30:45 +00:00
|
|
|
}
|
2005-07-30 22:59:01 +00:00
|
|
|
}
|
|
|
|
CONF("gap_y") {
|
2008-02-20 20:30:45 +00:00
|
|
|
if (value) {
|
2005-07-30 22:59:01 +00:00
|
|
|
gap_y = atoi(value);
|
2008-02-20 20:30:45 +00:00
|
|
|
} else {
|
2005-07-30 22:59:01 +00:00
|
|
|
CONF_ERR;
|
2008-02-20 20:30:45 +00:00
|
|
|
}
|
2005-07-30 22:59:01 +00:00
|
|
|
}
|
2005-08-08 01:18:52 +00:00
|
|
|
#endif /* X11 */
|
2005-07-30 22:59:01 +00:00
|
|
|
CONF("mail_spool") {
|
|
|
|
if (value) {
|
2008-03-29 09:58:09 +00:00
|
|
|
char buffer[256];
|
2008-02-20 20:30:45 +00:00
|
|
|
|
2008-03-29 09:58:09 +00:00
|
|
|
variable_substitute(value, buffer, 256);
|
2005-07-30 22:59:01 +00:00
|
|
|
|
2008-03-29 09:58:09 +00:00
|
|
|
if (buffer[0] != '\0') {
|
2008-02-20 20:30:45 +00:00
|
|
|
if (current_mail_spool) {
|
2005-07-30 22:59:01 +00:00
|
|
|
free(current_mail_spool);
|
2008-02-20 20:30:45 +00:00
|
|
|
}
|
2008-04-02 18:44:49 +00:00
|
|
|
current_mail_spool = strndup(buffer, text_buffer_size);
|
2005-07-30 22:59:01 +00:00
|
|
|
}
|
2008-02-20 20:30:45 +00:00
|
|
|
} else {
|
2005-07-30 22:59:01 +00:00
|
|
|
CONF_ERR;
|
2008-02-20 20:30:45 +00:00
|
|
|
}
|
2005-07-30 22:59:01 +00:00
|
|
|
}
|
2005-08-08 01:18:52 +00:00
|
|
|
#ifdef X11
|
2005-07-30 22:59:01 +00:00
|
|
|
CONF("minimum_size") {
|
2008-02-20 20:30:45 +00:00
|
|
|
if (value) {
|
|
|
|
if (sscanf(value, "%d %d", &minimum_width, &minimum_height)
|
|
|
|
!= 2) {
|
|
|
|
if (sscanf(value, "%d", &minimum_width) != 1) {
|
|
|
|
CONF_ERR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2005-08-24 06:21:50 +00:00
|
|
|
CONF_ERR;
|
2008-02-20 20:30:45 +00:00
|
|
|
}
|
2005-08-24 06:21:50 +00:00
|
|
|
}
|
|
|
|
CONF("maximum_width") {
|
2005-07-30 22:59:01 +00:00
|
|
|
if (value) {
|
2008-02-20 20:30:45 +00:00
|
|
|
if (sscanf(value, "%d", &maximum_width) != 1) {
|
2005-08-24 06:21:50 +00:00
|
|
|
CONF_ERR;
|
2008-02-20 20:30:45 +00:00
|
|
|
}
|
|
|
|
} else {
|
2005-07-30 22:59:01 +00:00
|
|
|
CONF_ERR;
|
2008-02-20 20:30:45 +00:00
|
|
|
}
|
2005-07-30 22:59:01 +00:00
|
|
|
}
|
2005-08-08 01:18:52 +00:00
|
|
|
#endif /* X11 */
|
2005-07-30 22:59:01 +00:00
|
|
|
CONF("no_buffers") {
|
|
|
|
no_buffers = string_to_bool(value);
|
|
|
|
}
|
2009-05-07 23:49:32 +00:00
|
|
|
CONF("top_name_width") {
|
|
|
|
if (value) {
|
|
|
|
if (sscanf(value, "%u", &top_name_width) != 1) {
|
|
|
|
CONF_ERR;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
CONF_ERR;
|
|
|
|
}
|
|
|
|
if (top_name_width >= max_user_text) {
|
|
|
|
top_name_width = max_user_text - 1;
|
|
|
|
}
|
|
|
|
}
|
2008-01-06 01:35:14 +00:00
|
|
|
CONF("top_cpu_separate") {
|
|
|
|
cpu_separate = string_to_bool(value);
|
|
|
|
}
|
2008-02-09 02:21:06 +00:00
|
|
|
CONF("short_units") {
|
|
|
|
short_units = string_to_bool(value);
|
|
|
|
}
|
2005-08-08 01:18:52 +00:00
|
|
|
CONF("pad_percents") {
|
2008-02-20 20:30:45 +00:00
|
|
|
pad_percents = atoi(value);
|
2005-08-08 01:18:52 +00:00
|
|
|
}
|
|
|
|
#ifdef X11
|
2005-07-20 00:30:40 +00:00
|
|
|
#ifdef OWN_WINDOW
|
2005-07-30 22:59:01 +00:00
|
|
|
CONF("own_window") {
|
2009-04-01 17:06:31 +00:00
|
|
|
if (value) {
|
|
|
|
own_window = string_to_bool(value);
|
2008-02-20 20:30:45 +00:00
|
|
|
}
|
2006-12-23 06:01:16 +00:00
|
|
|
}
|
|
|
|
CONF("own_window_class") {
|
2009-04-01 17:06:31 +00:00
|
|
|
if (value) {
|
|
|
|
memset(window.class_name, 0, sizeof(window.class_name));
|
|
|
|
strncpy(window.class_name, value,
|
2009-02-14 12:03:11 +00:00
|
|
|
sizeof(window.class_name) - 1);
|
2008-02-20 20:30:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
CONF("own_window_title") {
|
2009-04-01 17:06:31 +00:00
|
|
|
if (value) {
|
|
|
|
memset(window.title, 0, sizeof(window.title));
|
|
|
|
strncpy(window.title, value, sizeof(window.title) - 1);
|
2008-02-20 20:30:45 +00:00
|
|
|
}
|
|
|
|
}
|
2005-08-25 09:24:26 +00:00
|
|
|
CONF("own_window_transparent") {
|
2009-04-01 17:06:31 +00:00
|
|
|
if (value) {
|
|
|
|
set_transparent = string_to_bool(value);
|
2006-02-13 02:28:46 +00:00
|
|
|
}
|
2005-08-25 09:24:26 +00:00
|
|
|
}
|
2006-03-06 23:35:41 +00:00
|
|
|
CONF("own_window_hints") {
|
2009-04-01 17:06:31 +00:00
|
|
|
if (value) {
|
|
|
|
char *p_hint, *p_save;
|
|
|
|
char delim[] = ", ";
|
|
|
|
|
|
|
|
/* tokenize the value into individual hints */
|
|
|
|
if ((p_hint = strtok_r(value, delim, &p_save)) != NULL) {
|
|
|
|
do {
|
|
|
|
/* fprintf(stderr, "hint [%s] parsed\n", p_hint); */
|
|
|
|
if (strncmp(p_hint, "undecorate", 10) == EQUAL) {
|
|
|
|
SET_HINT(window.hints, HINT_UNDECORATED);
|
|
|
|
} else if (strncmp(p_hint, "below", 5) == EQUAL) {
|
|
|
|
SET_HINT(window.hints, HINT_BELOW);
|
|
|
|
} else if (strncmp(p_hint, "above", 5) == EQUAL) {
|
|
|
|
SET_HINT(window.hints, HINT_ABOVE);
|
|
|
|
} else if (strncmp(p_hint, "sticky", 6) == EQUAL) {
|
|
|
|
SET_HINT(window.hints, HINT_STICKY);
|
|
|
|
} else if (strncmp(p_hint, "skip_taskbar", 12) == EQUAL) {
|
|
|
|
SET_HINT(window.hints, HINT_SKIP_TASKBAR);
|
|
|
|
} else if (strncmp(p_hint, "skip_pager", 10) == EQUAL) {
|
|
|
|
SET_HINT(window.hints, HINT_SKIP_PAGER);
|
|
|
|
} else {
|
|
|
|
CONF_ERR;
|
|
|
|
}
|
|
|
|
|
|
|
|
p_hint = strtok_r(NULL, delim, &p_save);
|
|
|
|
} while (p_hint != NULL);
|
2008-02-20 20:30:45 +00:00
|
|
|
}
|
2009-04-01 17:06:31 +00:00
|
|
|
} else {
|
|
|
|
CONF_ERR;
|
2008-02-20 20:30:45 +00:00
|
|
|
}
|
2006-03-06 23:35:41 +00:00
|
|
|
}
|
2006-03-08 22:17:27 +00:00
|
|
|
CONF("own_window_type") {
|
2009-04-01 17:06:31 +00:00
|
|
|
if (value) {
|
|
|
|
if (strncmp(value, "normal", 6) == EQUAL) {
|
|
|
|
window.type = TYPE_NORMAL;
|
|
|
|
} else if (strncmp(value, "desktop", 7) == EQUAL) {
|
|
|
|
window.type = TYPE_DESKTOP;
|
|
|
|
} else if (strncmp(value, "dock", 7) == EQUAL) {
|
|
|
|
window.type = TYPE_DOCK;
|
|
|
|
text_alignment = TOP_LEFT;
|
|
|
|
} else if (strncmp(value, "override", 8) == EQUAL) {
|
|
|
|
window.type = TYPE_OVERRIDE;
|
2008-02-20 20:30:45 +00:00
|
|
|
} else {
|
|
|
|
CONF_ERR;
|
|
|
|
}
|
2009-04-01 17:06:31 +00:00
|
|
|
} else {
|
|
|
|
CONF_ERR;
|
2006-03-08 22:17:27 +00:00
|
|
|
}
|
|
|
|
}
|
2005-07-20 00:30:40 +00:00
|
|
|
#endif
|
2005-07-30 22:59:01 +00:00
|
|
|
CONF("stippled_borders") {
|
2008-02-20 20:30:45 +00:00
|
|
|
if (value) {
|
2005-07-30 22:59:01 +00:00
|
|
|
stippled_borders = strtol(value, 0, 0);
|
2008-02-20 20:30:45 +00:00
|
|
|
} else {
|
2005-07-30 22:59:01 +00:00
|
|
|
stippled_borders = 4;
|
2008-02-20 20:30:45 +00:00
|
|
|
}
|
2005-07-30 22:59:01 +00:00
|
|
|
}
|
2005-08-08 01:18:52 +00:00
|
|
|
#endif /* X11 */
|
2005-07-30 22:59:01 +00:00
|
|
|
CONF("temp1") {
|
2008-02-20 20:30:45 +00:00
|
|
|
ERR("temp1 configuration is obsolete, use ${i2c <i2c device here> "
|
|
|
|
"temp 1}");
|
2005-07-30 22:59:01 +00:00
|
|
|
}
|
2008-02-10 11:14:19 +00:00
|
|
|
CONF("temp2") {
|
2008-02-20 20:30:45 +00:00
|
|
|
ERR("temp2 configuration is obsolete, use ${i2c <i2c device here> "
|
|
|
|
"temp 2}");
|
2005-07-30 22:59:01 +00:00
|
|
|
}
|
|
|
|
CONF("update_interval") {
|
2008-02-20 20:30:45 +00:00
|
|
|
if (value) {
|
2005-07-30 22:59:01 +00:00
|
|
|
update_interval = strtod(value, 0);
|
2008-02-20 20:30:45 +00:00
|
|
|
} else {
|
2005-07-30 22:59:01 +00:00
|
|
|
CONF_ERR;
|
2008-02-20 20:30:45 +00:00
|
|
|
}
|
2007-09-02 04:26:08 +00:00
|
|
|
if (info.music_player_interval == 0) {
|
2007-09-02 03:02:33 +00:00
|
|
|
// default to update_interval
|
2007-09-02 04:26:08 +00:00
|
|
|
info.music_player_interval = update_interval;
|
2007-09-02 03:02:33 +00:00
|
|
|
}
|
2005-07-30 22:59:01 +00:00
|
|
|
}
|
|
|
|
CONF("total_run_times") {
|
2008-02-20 20:30:45 +00:00
|
|
|
if (value) {
|
2005-07-30 22:59:01 +00:00
|
|
|
total_run_times = strtod(value, 0);
|
2008-02-20 20:30:45 +00:00
|
|
|
} else {
|
2005-07-30 22:59:01 +00:00
|
|
|
CONF_ERR;
|
2008-02-20 20:30:45 +00:00
|
|
|
}
|
2005-07-30 22:59:01 +00:00
|
|
|
}
|
|
|
|
CONF("uppercase") {
|
|
|
|
stuff_in_upper_case = string_to_bool(value);
|
|
|
|
}
|
2006-11-22 21:53:54 +00:00
|
|
|
CONF("max_specials") {
|
2008-02-20 20:30:45 +00:00
|
|
|
if (value) {
|
2006-11-22 21:53:54 +00:00
|
|
|
max_specials = atoi(value);
|
2008-02-20 20:30:45 +00:00
|
|
|
} else {
|
2006-11-22 21:53:54 +00:00
|
|
|
CONF_ERR;
|
2008-02-20 20:30:45 +00:00
|
|
|
}
|
2006-11-22 21:53:54 +00:00
|
|
|
}
|
2006-11-09 00:33:46 +00:00
|
|
|
CONF("max_user_text") {
|
2008-02-20 20:30:45 +00:00
|
|
|
if (value) {
|
2006-11-09 00:33:46 +00:00
|
|
|
max_user_text = atoi(value);
|
2008-02-20 20:30:45 +00:00
|
|
|
} else {
|
2006-11-09 00:33:46 +00:00
|
|
|
CONF_ERR;
|
2008-02-20 20:30:45 +00:00
|
|
|
}
|
2006-11-09 00:33:46 +00:00
|
|
|
}
|
2007-02-12 01:03:10 +00:00
|
|
|
CONF("text_buffer_size") {
|
2008-02-20 20:30:45 +00:00
|
|
|
if (value) {
|
2008-03-20 21:28:19 +00:00
|
|
|
text_buffer_size = atoi(value);
|
|
|
|
if (text_buffer_size < DEFAULT_TEXT_BUFFER_SIZE) {
|
|
|
|
ERR("text_buffer_size must be >=%i bytes", DEFAULT_TEXT_BUFFER_SIZE);
|
|
|
|
text_buffer_size = DEFAULT_TEXT_BUFFER_SIZE;
|
2008-03-19 22:28:23 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
CONF_ERR;
|
|
|
|
}
|
|
|
|
}
|
2005-07-30 22:59:01 +00:00
|
|
|
CONF("text") {
|
2008-06-21 09:24:56 +00:00
|
|
|
if (global_text) {
|
|
|
|
free(global_text);
|
|
|
|
global_text = 0;
|
2008-02-20 20:30:45 +00:00
|
|
|
}
|
2005-07-30 22:59:01 +00:00
|
|
|
|
2008-06-21 09:24:56 +00:00
|
|
|
global_text = (char *) malloc(1);
|
|
|
|
global_text[0] = '\0';
|
2005-07-30 22:59:01 +00:00
|
|
|
|
|
|
|
while (!feof(fp)) {
|
2008-06-21 09:24:56 +00:00
|
|
|
unsigned int l = strlen(global_text);
|
2008-12-16 04:17:56 +00:00
|
|
|
unsigned int bl;
|
2009-05-10 02:10:55 +00:00
|
|
|
char buf[CONF_BUFF_SIZE];
|
2008-02-20 20:30:45 +00:00
|
|
|
|
2009-05-10 02:10:55 +00:00
|
|
|
if (fgets(buf, CONF_BUFF_SIZE, fp) == NULL) {
|
2005-07-30 22:59:01 +00:00
|
|
|
break;
|
2008-02-20 20:30:45 +00:00
|
|
|
}
|
2008-12-16 04:17:56 +00:00
|
|
|
|
|
|
|
/* Remove \\-\n. */
|
|
|
|
bl = strlen(buf);
|
|
|
|
if (bl >= 2 && buf[bl-2] == '\\' && buf[bl-1] == '\n') {
|
|
|
|
buf[bl-2] = '\0';
|
|
|
|
bl -= 2;
|
|
|
|
if (bl == 0) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check for continuation of \\-\n. */
|
|
|
|
if (l > 0 && buf[0] == '\n' && global_text[l-1] == '\\') {
|
|
|
|
global_text[l-1] = '\0';
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
global_text = (char *) realloc(global_text, l + bl + 1);
|
2008-06-21 09:24:56 +00:00
|
|
|
strcat(global_text, buf);
|
2005-07-30 22:59:01 +00:00
|
|
|
|
2008-06-21 09:24:56 +00:00
|
|
|
if (strlen(global_text) > max_user_text) {
|
2005-07-30 22:59:01 +00:00
|
|
|
break;
|
2008-02-20 20:30:45 +00:00
|
|
|
}
|
2005-07-30 22:59:01 +00:00
|
|
|
}
|
|
|
|
fclose(fp);
|
2008-06-21 09:24:56 +00:00
|
|
|
if (strlen(global_text) < 1) {
|
2008-04-02 02:12:57 +00:00
|
|
|
CRIT_ERR("no text supplied in configuration; exiting");
|
|
|
|
}
|
2008-06-21 09:24:56 +00:00
|
|
|
global_text_lines = line + 1;
|
2005-07-30 22:59:01 +00:00
|
|
|
return;
|
|
|
|
}
|
2005-11-11 03:28:24 +00:00
|
|
|
#ifdef TCP_PORT_MONITOR
|
2008-02-20 20:30:45 +00:00
|
|
|
CONF("max_port_monitor_connections") {
|
2008-12-09 13:44:14 +00:00
|
|
|
int max;
|
|
|
|
if (!value || (sscanf(value, "%d", &max) != 1)) {
|
2005-11-11 22:21:34 +00:00
|
|
|
/* an error. use default, warn and continue. */
|
2008-12-09 13:44:14 +00:00
|
|
|
tcp_portmon_set_max_connections(0);
|
|
|
|
CONF_ERR;
|
|
|
|
} else if (tcp_portmon_set_max_connections(max)) {
|
|
|
|
/* max is < 0, default has been set*/
|
2005-11-11 03:28:24 +00:00
|
|
|
CONF_ERR;
|
2005-11-11 22:21:34 +00:00
|
|
|
}
|
2005-11-11 03:28:24 +00:00
|
|
|
}
|
|
|
|
#endif
|
2008-05-30 11:30:58 +00:00
|
|
|
CONF("if_up_strictness") {
|
|
|
|
if (!value) {
|
|
|
|
ERR("incorrect if_up_strictness value, defaulting to 'up'");
|
|
|
|
ifup_strictness = IFUP_UP;
|
2008-06-21 20:37:58 +00:00
|
|
|
} else if (strcasecmp(value, "up") == EQUAL) {
|
2008-05-30 11:30:58 +00:00
|
|
|
ifup_strictness = IFUP_UP;
|
2008-06-21 20:37:58 +00:00
|
|
|
} else if (strcasecmp(value, "link") == EQUAL) {
|
2008-05-30 11:30:58 +00:00
|
|
|
ifup_strictness = IFUP_LINK;
|
2008-06-21 20:37:58 +00:00
|
|
|
} else if (strcasecmp(value, "address") == EQUAL) {
|
2008-05-30 11:30:58 +00:00
|
|
|
ifup_strictness = IFUP_ADDR;
|
|
|
|
} else {
|
|
|
|
ERR("incorrect if_up_strictness value, defaulting to 'up'");
|
|
|
|
ifup_strictness = IFUP_UP;
|
|
|
|
}
|
|
|
|
}
|
2008-12-07 19:08:29 +00:00
|
|
|
|
|
|
|
CONF("temperature_unit") {
|
|
|
|
if (!value) {
|
2009-03-16 00:34:40 +00:00
|
|
|
ERR("config option 'temperature_unit' needs an argument, either 'celsius' or 'fahrenheit'");
|
2008-12-07 19:08:29 +00:00
|
|
|
} else if (set_temp_output_unit(value)) {
|
|
|
|
ERR("temperature_unit: incorrect argument");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-03-07 14:12:09 +00:00
|
|
|
CONF("alias") {
|
|
|
|
if (value) {
|
2009-03-16 20:14:22 +00:00
|
|
|
size_t maxlength = strlen(value); //+1 for terminating 0 not needed, 'cause of the space in the middle of value
|
|
|
|
char *skey = malloc(maxlength);
|
|
|
|
char *svalue = malloc(maxlength);
|
2009-03-16 00:34:40 +00:00
|
|
|
char *oldvalue;
|
2009-03-16 20:14:22 +00:00
|
|
|
if (sscanf(value, "%[0-9a-zA-Z_] %[^\n]", skey, svalue) == 2) {
|
2009-03-07 14:12:09 +00:00
|
|
|
oldvalue = getenv(skey);
|
2009-03-16 00:34:40 +00:00
|
|
|
if (oldvalue == NULL) {
|
2009-03-07 14:12:09 +00:00
|
|
|
setenv(skey, svalue, 0);
|
|
|
|
}
|
|
|
|
//PS: Don't free oldvalue, it's the real envvar, not a copy
|
|
|
|
} else {
|
|
|
|
CONF_ERR;
|
|
|
|
}
|
2009-03-16 20:14:22 +00:00
|
|
|
free(skey);
|
|
|
|
free(svalue);
|
2009-03-07 14:12:09 +00:00
|
|
|
} else {
|
|
|
|
CONF_ERR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-04-01 17:06:31 +00:00
|
|
|
CONF("color0"){}
|
|
|
|
CONF("color1"){}
|
|
|
|
CONF("color2"){}
|
|
|
|
CONF("color3"){}
|
|
|
|
CONF("color4"){}
|
|
|
|
CONF("color5"){}
|
|
|
|
CONF("color6"){}
|
|
|
|
CONF("color7"){}
|
|
|
|
CONF("color8"){}
|
|
|
|
CONF("color9"){}
|
|
|
|
CONF("default_color"){}
|
|
|
|
CONF3("default_shade_color", "default_shadecolor"){}
|
|
|
|
CONF3("default_outline_color", "default_outlinecolor") {}
|
|
|
|
CONF("own_window_colour") {}
|
|
|
|
|
2008-02-20 20:30:45 +00:00
|
|
|
else {
|
|
|
|
ERR("%s: %d: no such configuration: '%s'", f, line, name);
|
|
|
|
}
|
2005-07-30 22:59:01 +00:00
|
|
|
}
|
2005-07-20 00:30:40 +00:00
|
|
|
|
2005-07-30 22:59:01 +00:00
|
|
|
fclose(fp);
|
2008-02-20 20:30:45 +00:00
|
|
|
|
2007-09-02 04:26:08 +00:00
|
|
|
if (info.music_player_interval == 0) {
|
2007-09-02 03:02:33 +00:00
|
|
|
// default to update_interval
|
2007-09-02 04:26:08 +00:00
|
|
|
info.music_player_interval = update_interval;
|
2007-09-02 03:02:33 +00:00
|
|
|
}
|
2008-06-21 09:24:56 +00:00
|
|
|
if (!global_text) { // didn't supply any text
|
2008-04-02 02:12:57 +00:00
|
|
|
CRIT_ERR("missing text block in configuration; exiting");
|
|
|
|
}
|
2005-07-30 22:59:01 +00:00
|
|
|
}
|
2005-07-28 04:48:27 +00:00
|
|
|
|
2009-04-01 17:06:31 +00:00
|
|
|
static void load_config_file_x11(const char *f)
|
|
|
|
{
|
|
|
|
int line = 0;
|
|
|
|
FILE *fp;
|
|
|
|
|
2009-05-10 02:10:55 +00:00
|
|
|
fp = open_config_file(f);
|
2009-04-01 17:06:31 +00:00
|
|
|
if (!fp) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
DBGP("reading contents from config file '%s'", f);
|
|
|
|
|
|
|
|
while (!feof(fp)) {
|
2009-05-10 02:10:55 +00:00
|
|
|
char buff[CONF_BUFF_SIZE], *name, *value;
|
|
|
|
int ret = do_config_step(&line, fp, buff, &name, &value);
|
|
|
|
if (ret == CONF_BREAK) {
|
2009-04-01 17:06:31 +00:00
|
|
|
break;
|
2009-05-10 02:10:55 +00:00
|
|
|
} else if (ret == CONF_CONTINUE) {
|
|
|
|
continue;
|
2009-04-01 17:06:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef X11
|
|
|
|
CONF2("color0") {
|
|
|
|
X11_initialisation();
|
|
|
|
if (x_initialised == YES) {
|
|
|
|
if (value) {
|
|
|
|
color0 = get_x11_color(value);
|
|
|
|
} else {
|
|
|
|
CONF_ERR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
CONF("color1") {
|
|
|
|
X11_initialisation();
|
|
|
|
if (x_initialised == YES) {
|
|
|
|
if (value) {
|
|
|
|
color1 = get_x11_color(value);
|
|
|
|
} else {
|
|
|
|
CONF_ERR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
CONF("color2") {
|
|
|
|
X11_initialisation();
|
|
|
|
if (x_initialised == YES) {
|
|
|
|
if (value) {
|
|
|
|
color2 = get_x11_color(value);
|
|
|
|
} else {
|
|
|
|
CONF_ERR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
CONF("color3") {
|
|
|
|
X11_initialisation();
|
|
|
|
if (x_initialised == YES) {
|
|
|
|
if (value) {
|
|
|
|
color3 = get_x11_color(value);
|
|
|
|
} else {
|
|
|
|
CONF_ERR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
CONF("color4") {
|
|
|
|
X11_initialisation();
|
|
|
|
if (x_initialised == YES) {
|
|
|
|
if (value) {
|
|
|
|
color4 = get_x11_color(value);
|
|
|
|
} else {
|
|
|
|
CONF_ERR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
CONF("color5") {
|
|
|
|
X11_initialisation();
|
|
|
|
if (x_initialised == YES) {
|
|
|
|
if (value) {
|
|
|
|
color5 = get_x11_color(value);
|
|
|
|
} else {
|
|
|
|
CONF_ERR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
CONF("color6") {
|
|
|
|
X11_initialisation();
|
|
|
|
if (x_initialised == YES) {
|
|
|
|
if (value) {
|
|
|
|
color6 = get_x11_color(value);
|
|
|
|
} else {
|
|
|
|
CONF_ERR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
CONF("color7") {
|
|
|
|
X11_initialisation();
|
|
|
|
if (x_initialised == YES) {
|
|
|
|
if (value) {
|
|
|
|
color7 = get_x11_color(value);
|
|
|
|
} else {
|
|
|
|
CONF_ERR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
CONF("color8") {
|
|
|
|
X11_initialisation();
|
|
|
|
if (x_initialised == YES) {
|
|
|
|
if (value) {
|
|
|
|
color8 = get_x11_color(value);
|
|
|
|
} else {
|
|
|
|
CONF_ERR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
CONF("color9") {
|
|
|
|
X11_initialisation();
|
|
|
|
if (x_initialised == YES) {
|
|
|
|
if (value) {
|
|
|
|
color9 = get_x11_color(value);
|
|
|
|
} else {
|
|
|
|
CONF_ERR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
CONF("default_color") {
|
|
|
|
X11_initialisation();
|
|
|
|
if (x_initialised == YES) {
|
|
|
|
if (value) {
|
|
|
|
default_fg_color = get_x11_color(value);
|
|
|
|
} else {
|
|
|
|
CONF_ERR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
CONF3("default_shade_color", "default_shadecolor") {
|
|
|
|
X11_initialisation();
|
|
|
|
if (x_initialised == YES) {
|
|
|
|
if (value) {
|
|
|
|
default_bg_color = get_x11_color(value);
|
|
|
|
} else {
|
|
|
|
CONF_ERR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
CONF3("default_outline_color", "default_outlinecolor") {
|
|
|
|
X11_initialisation();
|
|
|
|
if (x_initialised == YES) {
|
|
|
|
if (value) {
|
|
|
|
default_out_color = get_x11_color(value);
|
|
|
|
} else {
|
|
|
|
CONF_ERR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#ifdef OWN_WINDOW
|
|
|
|
CONF("own_window_colour") {
|
|
|
|
X11_initialisation();
|
|
|
|
if (x_initialised == YES) {
|
|
|
|
if (value) {
|
|
|
|
background_colour = get_x11_color(value);
|
|
|
|
} else {
|
|
|
|
ERR("Invalid colour for own_window_colour (try omitting the "
|
|
|
|
"'#' for hex colours");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
CONF("text") {
|
|
|
|
//initialize X11 if nothing X11-related is mentioned before TEXT (and if X11 is the default outputmethod)
|
|
|
|
if(output_methods & TO_X) {
|
|
|
|
X11_initialisation();
|
|
|
|
}
|
|
|
|
}
|
2009-04-13 12:42:31 +00:00
|
|
|
#endif /* X11 */
|
2009-04-01 17:06:31 +00:00
|
|
|
#undef CONF
|
|
|
|
#undef CONF2
|
2009-05-10 02:10:55 +00:00
|
|
|
#undef CONF3
|
|
|
|
#undef CONF_ERR
|
|
|
|
#undef CONF_ERR2
|
|
|
|
#undef CONF_BREAK
|
|
|
|
#undef CONF_CONTINUE
|
|
|
|
#undef CONF_BUFF_SIZE
|
2009-04-01 17:06:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fclose(fp);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2008-06-19 19:59:30 +00:00
|
|
|
static void print_help(const char *prog_name) {
|
|
|
|
printf("Usage: %s [OPTION]...\n"
|
2008-07-12 10:25:05 +00:00
|
|
|
PACKAGE_NAME" is a system monitor that renders text on desktop or to own transparent\n"
|
2008-06-19 19:59:30 +00:00
|
|
|
"window. Command line options will override configurations defined in config\n"
|
|
|
|
"file.\n"
|
|
|
|
" -v, --version version\n"
|
|
|
|
" -q, --quiet quiet mode\n"
|
2008-11-30 20:53:20 +00:00
|
|
|
" -D, --debug increase debugging output\n"
|
2008-06-19 19:59:30 +00:00
|
|
|
" -c, --config=FILE config file to load\n"
|
2009-02-22 17:55:39 +00:00
|
|
|
#ifdef CONFIG_OUTPUT
|
|
|
|
" -C, --print-config print the builtin default config to stdout\n"
|
|
|
|
" e.g. 'conky -C > ~/.conkyrc' will create a new default config\n"
|
|
|
|
#endif
|
2008-06-19 19:59:30 +00:00
|
|
|
" -d, --daemonize daemonize, fork to background\n"
|
|
|
|
" -h, --help help\n"
|
|
|
|
#ifdef X11
|
|
|
|
" -a, --alignment=ALIGNMENT text alignment on screen, {top,bottom,middle}_{left,right,middle}\n"
|
|
|
|
" -f, --font=FONT font to use\n"
|
|
|
|
#ifdef OWN_WINDOW
|
|
|
|
" -o, --own-window create own window to draw\n"
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_XDBE
|
|
|
|
" -b, --double-buffer double buffer (prevents flickering)\n"
|
|
|
|
#endif
|
|
|
|
" -w, --window-id=WIN_ID window id to draw\n"
|
|
|
|
" -x X x position\n"
|
|
|
|
" -y Y y position\n"
|
|
|
|
#endif /* X11 */
|
|
|
|
" -t, --text=TEXT text to render, remember single quotes, like -t '$uptime'\n"
|
|
|
|
" -u, --interval=SECS update interval\n"
|
2008-07-12 10:25:05 +00:00
|
|
|
" -i COUNT number of times to update "PACKAGE_NAME" (and quit)\n",
|
2008-06-19 19:59:30 +00:00
|
|
|
prog_name
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2008-02-20 10:01:13 +00:00
|
|
|
/* : means that character before that takes an argument */
|
2008-11-30 20:53:20 +00:00
|
|
|
static const char *getopt_string = "vVqdDt:u:i:hc:"
|
2005-08-08 01:18:52 +00:00
|
|
|
#ifdef X11
|
2009-04-01 17:06:31 +00:00
|
|
|
"x:y:w:a:f:X:"
|
2005-07-20 00:30:40 +00:00
|
|
|
#ifdef OWN_WINDOW
|
2008-02-20 20:30:45 +00:00
|
|
|
"o"
|
2005-07-20 00:30:40 +00:00
|
|
|
#endif
|
2006-11-07 02:19:58 +00:00
|
|
|
#ifdef HAVE_XDBE
|
2008-02-20 20:30:45 +00:00
|
|
|
"b"
|
2005-07-20 00:30:40 +00:00
|
|
|
#endif
|
2009-02-22 17:55:39 +00:00
|
|
|
#endif /* X11 */
|
2008-12-12 14:33:25 +00:00
|
|
|
#ifdef CONFIG_OUTPUT
|
|
|
|
"C"
|
|
|
|
#endif
|
2008-01-06 01:35:14 +00:00
|
|
|
;
|
|
|
|
|
2008-02-20 20:30:45 +00:00
|
|
|
static const struct option longopts[] = {
|
|
|
|
{ "help", 0, NULL, 'h' },
|
|
|
|
{ "version", 0, NULL, 'V' },
|
2008-11-30 20:53:20 +00:00
|
|
|
{ "debug", 0, NULL, 'D' },
|
2008-02-20 20:30:45 +00:00
|
|
|
{ "config", 1, NULL, 'c' },
|
2008-12-12 14:33:25 +00:00
|
|
|
#ifdef CONFIG_OUTPUT
|
|
|
|
{ "print-config", 0, NULL, 'C' },
|
|
|
|
#endif
|
2008-02-20 20:30:45 +00:00
|
|
|
{ "daemonize", 0, NULL, 'd' },
|
2008-01-06 01:35:14 +00:00
|
|
|
#ifdef X11
|
2008-02-20 20:30:45 +00:00
|
|
|
{ "alignment", 1, NULL, 'a' },
|
|
|
|
{ "font", 1, NULL, 'f' },
|
2009-04-01 17:06:31 +00:00
|
|
|
{ "display", 1, NULL, 'X' },
|
2008-01-06 01:35:14 +00:00
|
|
|
#ifdef OWN_WINDOW
|
2008-02-20 20:30:45 +00:00
|
|
|
{ "own-window", 0, NULL, 'o' },
|
2008-01-06 01:35:14 +00:00
|
|
|
#endif
|
|
|
|
#ifdef HAVE_XDBE
|
2008-02-20 20:30:45 +00:00
|
|
|
{ "double-buffer", 0, NULL, 'b' },
|
2008-01-06 01:35:14 +00:00
|
|
|
#endif
|
2008-02-20 20:30:45 +00:00
|
|
|
{ "window-id", 1, NULL, 'w' },
|
2008-01-06 01:35:14 +00:00
|
|
|
#endif /* X11 */
|
2008-02-20 20:30:45 +00:00
|
|
|
{ "text", 1, NULL, 't' },
|
|
|
|
{ "interval", 0, NULL, 'u' },
|
|
|
|
{ 0, 0, 0, 0 }
|
|
|
|
};
|
2005-07-30 22:59:01 +00:00
|
|
|
|
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
2008-03-29 06:24:04 +00:00
|
|
|
#ifdef X11
|
|
|
|
char *s, *temp;
|
|
|
|
unsigned int x;
|
|
|
|
#endif
|
2005-11-23 19:05:23 +00:00
|
|
|
struct sigaction act, oact;
|
|
|
|
|
2008-02-20 20:30:45 +00:00
|
|
|
g_signal_pending = 0;
|
2007-08-31 02:05:02 +00:00
|
|
|
memset(&info, 0, sizeof(info));
|
2008-09-24 06:59:45 +00:00
|
|
|
clear_net_stats();
|
2005-10-31 05:17:06 +00:00
|
|
|
|
2005-11-11 22:21:34 +00:00
|
|
|
#ifdef TCP_PORT_MONITOR
|
2008-12-09 13:44:14 +00:00
|
|
|
/* set default connection limit */
|
|
|
|
tcp_portmon_set_max_connections(0);
|
2005-11-11 22:21:34 +00:00
|
|
|
#endif
|
2006-01-11 17:03:45 +00:00
|
|
|
|
2005-07-30 22:59:01 +00:00
|
|
|
/* handle command line parameters that don't change configs */
|
2005-08-08 01:18:52 +00:00
|
|
|
#ifdef X11
|
2008-02-20 20:30:45 +00:00
|
|
|
if (((s = getenv("LC_ALL")) && *s) || ((s = getenv("LC_CTYPE")) && *s)
|
|
|
|
|| ((s = getenv("LANG")) && *s)) {
|
|
|
|
temp = (char *) malloc((strlen(s) + 1) * sizeof(char));
|
2006-10-05 17:25:23 +00:00
|
|
|
if (temp == NULL) {
|
|
|
|
ERR("malloc failed");
|
|
|
|
}
|
|
|
|
for (x = 0; x < strlen(s); x++) {
|
2005-08-05 01:06:17 +00:00
|
|
|
temp[x] = tolower(s[x]);
|
|
|
|
}
|
2007-06-03 09:18:54 +00:00
|
|
|
temp[x] = 0;
|
2005-08-05 01:06:17 +00:00
|
|
|
if (strstr(temp, "utf-8") || strstr(temp, "utf8")) {
|
2005-07-30 22:59:01 +00:00
|
|
|
utf8_mode = 1;
|
2005-08-05 01:06:17 +00:00
|
|
|
}
|
2008-02-20 20:30:45 +00:00
|
|
|
|
2006-10-05 17:25:23 +00:00
|
|
|
free(temp);
|
2005-07-30 22:59:01 +00:00
|
|
|
}
|
|
|
|
if (!setlocale(LC_CTYPE, "")) {
|
2005-08-05 01:06:17 +00:00
|
|
|
ERR("Can't set the specified locale!\nCheck LANG, LC_CTYPE, LC_ALL.");
|
2005-07-30 22:59:01 +00:00
|
|
|
}
|
2005-08-08 01:18:52 +00:00
|
|
|
#endif /* X11 */
|
2005-07-30 22:59:01 +00:00
|
|
|
while (1) {
|
2008-01-06 01:35:14 +00:00
|
|
|
int c = getopt_long(argc, argv, getopt_string, longopts, NULL);
|
|
|
|
|
2008-02-20 20:30:45 +00:00
|
|
|
if (c == -1) {
|
2005-07-30 22:59:01 +00:00
|
|
|
break;
|
2008-01-06 01:35:14 +00:00
|
|
|
}
|
2005-07-30 22:59:01 +00:00
|
|
|
|
|
|
|
switch (c) {
|
2008-02-20 20:30:45 +00:00
|
|
|
case 'v':
|
|
|
|
case 'V':
|
|
|
|
print_version();
|
|
|
|
case 'c':
|
|
|
|
if (current_config) {
|
|
|
|
free(current_config);
|
|
|
|
}
|
2008-04-02 18:44:49 +00:00
|
|
|
current_config = strndup(optarg, max_user_text);
|
2008-02-20 20:30:45 +00:00
|
|
|
break;
|
2008-06-03 21:01:40 +00:00
|
|
|
case 'q':
|
|
|
|
freopen("/dev/null", "w", stderr);
|
|
|
|
break;
|
2008-01-06 01:35:14 +00:00
|
|
|
case 'h':
|
2008-06-19 19:59:30 +00:00
|
|
|
print_help(argv[0]);
|
2008-01-06 01:35:14 +00:00
|
|
|
return 0;
|
2008-12-12 14:33:25 +00:00
|
|
|
#ifdef CONFIG_OUTPUT
|
|
|
|
case 'C':
|
|
|
|
print_defconfig();
|
|
|
|
return 0;
|
|
|
|
#endif
|
2005-08-08 01:18:52 +00:00
|
|
|
#ifdef X11
|
2008-02-20 20:30:45 +00:00
|
|
|
case 'w':
|
|
|
|
window.window = strtol(optarg, 0, 0);
|
|
|
|
break;
|
2005-08-08 01:18:52 +00:00
|
|
|
#endif /* X11 */
|
2005-07-30 22:59:01 +00:00
|
|
|
|
2008-02-20 20:30:45 +00:00
|
|
|
case '?':
|
|
|
|
exit(EXIT_FAILURE);
|
2005-07-30 22:59:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-03-24 19:24:55 +00:00
|
|
|
/* check if specified config file is valid */
|
|
|
|
if (current_config) {
|
|
|
|
struct stat sb;
|
|
|
|
if (stat(current_config, &sb) ||
|
|
|
|
(!S_ISREG(sb.st_mode) && !S_ISLNK(sb.st_mode))) {
|
|
|
|
ERR("invalid configuration file '%s'\n", current_config);
|
|
|
|
free(current_config);
|
|
|
|
current_config = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-10-23 21:52:11 +00:00
|
|
|
/* load current_config, CONFIG_FILE or SYSTEM_CONFIG_FILE */
|
2005-07-20 00:30:40 +00:00
|
|
|
|
2007-10-23 21:52:11 +00:00
|
|
|
if (!current_config) {
|
2005-07-30 22:59:01 +00:00
|
|
|
/* load default config file */
|
|
|
|
char buf[256];
|
2008-02-20 20:30:45 +00:00
|
|
|
FILE *fp;
|
2005-07-30 22:59:01 +00:00
|
|
|
|
2008-02-20 20:30:45 +00:00
|
|
|
/* Try to use personal config file first */
|
2007-10-23 21:52:11 +00:00
|
|
|
variable_substitute(CONFIG_FILE, buf, sizeof(buf));
|
2008-02-20 20:30:45 +00:00
|
|
|
if (buf[0] && (fp = fopen(buf, "r"))) {
|
2008-04-02 18:44:49 +00:00
|
|
|
current_config = strndup(buf, max_user_text);
|
2008-02-20 20:30:45 +00:00
|
|
|
fclose(fp);
|
|
|
|
}
|
2005-07-30 22:59:01 +00:00
|
|
|
|
2008-02-20 20:30:45 +00:00
|
|
|
/* Try to use system config file if personal config not readable */
|
|
|
|
if (!current_config && (fp = fopen(SYSTEM_CONFIG_FILE, "r"))) {
|
2008-04-02 18:44:49 +00:00
|
|
|
current_config = strndup(SYSTEM_CONFIG_FILE, max_user_text);
|
2008-02-20 20:30:45 +00:00
|
|
|
fclose(fp);
|
|
|
|
}
|
2005-07-20 00:30:40 +00:00
|
|
|
|
2008-02-20 20:30:45 +00:00
|
|
|
/* No readable config found */
|
|
|
|
if (!current_config) {
|
2008-12-14 13:36:44 +00:00
|
|
|
#ifdef CONFIG_OUTPUT
|
|
|
|
current_config = strdup("==builtin==");
|
|
|
|
ERR("no readable personal or system-wide config file found,"
|
|
|
|
" using builtin default");
|
|
|
|
#else
|
2008-02-20 20:30:45 +00:00
|
|
|
CRIT_ERR("no readable personal or system-wide config file found");
|
2008-12-14 13:36:44 +00:00
|
|
|
#endif /* ! CONF_OUTPUT */
|
2008-02-20 20:30:45 +00:00
|
|
|
}
|
2005-08-26 01:55:33 +00:00
|
|
|
}
|
2005-07-20 00:30:40 +00:00
|
|
|
|
2007-10-23 21:52:11 +00:00
|
|
|
load_config_file(current_config);
|
|
|
|
|
2006-11-22 21:53:54 +00:00
|
|
|
/* init specials array */
|
2008-02-20 20:30:45 +00:00
|
|
|
if ((specials = calloc(sizeof(struct special_t), max_specials)) == 0) {
|
|
|
|
ERR("failed to create specials array");
|
|
|
|
}
|
2006-11-22 21:53:54 +00:00
|
|
|
|
2005-07-20 00:30:40 +00:00
|
|
|
#ifdef MAIL_FILE
|
2005-07-30 22:59:01 +00:00
|
|
|
if (current_mail_spool == NULL) {
|
|
|
|
char buf[256];
|
2008-02-20 20:30:45 +00:00
|
|
|
|
2005-07-30 22:59:01 +00:00
|
|
|
variable_substitute(MAIL_FILE, buf, 256);
|
|
|
|
|
2008-02-20 20:30:45 +00:00
|
|
|
if (buf[0] != '\0') {
|
2008-04-02 18:44:49 +00:00
|
|
|
current_mail_spool = strndup(buf, text_buffer_size);
|
2008-02-20 20:30:45 +00:00
|
|
|
}
|
2005-07-30 22:59:01 +00:00
|
|
|
}
|
2005-07-20 00:30:40 +00:00
|
|
|
#endif
|
|
|
|
|
2005-07-30 22:59:01 +00:00
|
|
|
/* handle other command line arguments */
|
|
|
|
|
2008-02-24 16:35:18 +00:00
|
|
|
#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__OpenBSD__) \
|
2008-02-20 10:01:00 +00:00
|
|
|
|| defined(__NetBSD__)
|
2005-08-24 12:05:47 +00:00
|
|
|
optind = optreset = 1;
|
|
|
|
#else
|
2005-07-30 22:59:01 +00:00
|
|
|
optind = 0;
|
2005-08-24 12:05:47 +00:00
|
|
|
#endif
|
2006-03-22 19:27:31 +00:00
|
|
|
|
2007-12-31 00:00:35 +00:00
|
|
|
#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
|
2008-02-20 20:30:45 +00:00
|
|
|
if ((kd = kvm_open("/dev/null", "/dev/null", "/dev/null", O_RDONLY,
|
|
|
|
"kvm_open")) == NULL) {
|
|
|
|
CRIT_ERR("cannot read kvm");
|
|
|
|
}
|
2006-03-22 19:27:31 +00:00
|
|
|
#endif
|
2008-02-20 20:30:45 +00:00
|
|
|
|
2005-07-30 22:59:01 +00:00
|
|
|
while (1) {
|
2008-01-06 01:35:14 +00:00
|
|
|
int c = getopt_long(argc, argv, getopt_string, longopts, NULL);
|
|
|
|
|
2008-02-20 20:30:45 +00:00
|
|
|
if (c == -1) {
|
2005-07-30 22:59:01 +00:00
|
|
|
break;
|
2008-01-06 01:35:14 +00:00
|
|
|
}
|
2005-07-30 22:59:01 +00:00
|
|
|
|
|
|
|
switch (c) {
|
2008-02-20 20:30:45 +00:00
|
|
|
case 'd':
|
|
|
|
fork_to_background = 1;
|
|
|
|
break;
|
2008-11-30 20:53:20 +00:00
|
|
|
case 'D':
|
|
|
|
global_debug_level++;
|
|
|
|
break;
|
2005-08-08 01:18:52 +00:00
|
|
|
#ifdef X11
|
|
|
|
case 'f':
|
2008-02-20 20:30:45 +00:00
|
|
|
set_first_font(optarg);
|
|
|
|
break;
|
2005-08-08 01:18:52 +00:00
|
|
|
case 'a':
|
|
|
|
text_alignment = string_to_alignment(optarg);
|
|
|
|
break;
|
2009-04-01 17:06:31 +00:00
|
|
|
case 'X':
|
|
|
|
if (disp)
|
|
|
|
free(disp);
|
|
|
|
disp = strdup(optarg);
|
|
|
|
break;
|
2005-07-20 00:30:40 +00:00
|
|
|
|
|
|
|
#ifdef OWN_WINDOW
|
2008-02-20 20:30:45 +00:00
|
|
|
case 'o':
|
|
|
|
own_window = 1;
|
|
|
|
break;
|
2005-07-20 00:30:40 +00:00
|
|
|
#endif
|
2006-11-07 02:19:58 +00:00
|
|
|
#ifdef HAVE_XDBE
|
2008-02-20 20:30:45 +00:00
|
|
|
case 'b':
|
2005-08-26 02:16:35 +00:00
|
|
|
use_xdbe = 1;
|
2008-02-20 20:30:45 +00:00
|
|
|
break;
|
2005-07-20 00:30:40 +00:00
|
|
|
#endif
|
2005-08-08 01:18:52 +00:00
|
|
|
#endif /* X11 */
|
2008-02-20 20:30:45 +00:00
|
|
|
case 't':
|
2008-06-21 09:24:56 +00:00
|
|
|
if (global_text) {
|
|
|
|
free(global_text);
|
|
|
|
global_text = 0;
|
2008-02-20 20:30:45 +00:00
|
|
|
}
|
2008-06-21 09:24:56 +00:00
|
|
|
global_text = strndup(optarg, max_user_text);
|
|
|
|
convert_escapes(global_text);
|
2008-02-20 20:30:45 +00:00
|
|
|
break;
|
2005-07-30 22:59:01 +00:00
|
|
|
|
2008-02-20 20:30:45 +00:00
|
|
|
case 'u':
|
|
|
|
update_interval = strtod(optarg, 0);
|
|
|
|
if (info.music_player_interval == 0) {
|
|
|
|
// default to update_interval
|
|
|
|
info.music_player_interval = update_interval;
|
|
|
|
}
|
|
|
|
break;
|
2005-07-30 22:59:01 +00:00
|
|
|
|
2008-02-20 20:30:45 +00:00
|
|
|
case 'i':
|
|
|
|
total_run_times = strtod(optarg, 0);
|
|
|
|
break;
|
2005-08-08 01:18:52 +00:00
|
|
|
#ifdef X11
|
2008-02-20 20:30:45 +00:00
|
|
|
case 'x':
|
|
|
|
gap_x = atoi(optarg);
|
|
|
|
break;
|
2005-07-30 22:59:01 +00:00
|
|
|
|
2008-02-20 20:30:45 +00:00
|
|
|
case 'y':
|
|
|
|
gap_y = atoi(optarg);
|
|
|
|
break;
|
2005-08-08 01:18:52 +00:00
|
|
|
#endif /* X11 */
|
2005-07-30 22:59:01 +00:00
|
|
|
|
2008-02-20 20:30:45 +00:00
|
|
|
case '?':
|
|
|
|
exit(EXIT_FAILURE);
|
2005-07-30 22:59:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-08-08 01:18:52 +00:00
|
|
|
#ifdef X11
|
2005-07-30 22:59:01 +00:00
|
|
|
/* load font */
|
2009-04-01 17:06:31 +00:00
|
|
|
if (output_methods & TO_X) {
|
|
|
|
load_config_file_x11(current_config);
|
2009-02-21 23:37:15 +00:00
|
|
|
load_fonts();
|
2009-04-01 17:06:31 +00:00
|
|
|
}
|
2005-08-08 01:18:52 +00:00
|
|
|
#endif /* X11 */
|
2005-07-30 22:59:01 +00:00
|
|
|
|
|
|
|
/* generate text and get initial size */
|
2008-06-21 09:24:56 +00:00
|
|
|
extract_variable_text(global_text);
|
|
|
|
if (global_text) {
|
|
|
|
free(global_text);
|
|
|
|
global_text = 0;
|
2005-08-06 00:26:14 +00:00
|
|
|
}
|
2008-06-21 09:24:56 +00:00
|
|
|
global_text = NULL;
|
2006-03-06 06:57:30 +00:00
|
|
|
/* fork */
|
|
|
|
if (fork_to_background) {
|
2006-03-07 20:35:11 +00:00
|
|
|
int pid = fork();
|
2008-02-20 20:30:45 +00:00
|
|
|
|
2006-03-07 20:35:11 +00:00
|
|
|
switch (pid) {
|
2008-02-20 20:30:45 +00:00
|
|
|
case -1:
|
2008-07-12 10:25:05 +00:00
|
|
|
ERR(PACKAGE_NAME": couldn't fork() to background: %s",
|
2008-02-20 20:30:45 +00:00
|
|
|
strerror(errno));
|
|
|
|
break;
|
2006-03-06 06:57:30 +00:00
|
|
|
|
2008-02-20 20:30:45 +00:00
|
|
|
case 0:
|
|
|
|
/* child process */
|
|
|
|
usleep(25000);
|
|
|
|
fprintf(stderr, "\n");
|
|
|
|
fflush(stderr);
|
|
|
|
break;
|
2006-03-06 06:57:30 +00:00
|
|
|
|
2008-02-20 20:30:45 +00:00
|
|
|
default:
|
|
|
|
/* parent process */
|
2008-07-12 10:25:05 +00:00
|
|
|
fprintf(stderr, PACKAGE_NAME": forked to background, pid is %d\n",
|
2008-02-20 20:30:45 +00:00
|
|
|
pid);
|
|
|
|
fflush(stderr);
|
|
|
|
return 0;
|
2006-03-06 06:57:30 +00:00
|
|
|
}
|
|
|
|
}
|
2005-07-30 22:59:01 +00:00
|
|
|
|
2008-03-20 21:28:19 +00:00
|
|
|
text_buffer = malloc(max_user_text);
|
|
|
|
memset(text_buffer, 0, max_user_text);
|
|
|
|
tmpstring1 = malloc(text_buffer_size);
|
|
|
|
memset(tmpstring1, 0, text_buffer_size);
|
|
|
|
tmpstring2 = malloc(text_buffer_size);
|
|
|
|
memset(tmpstring2, 0, text_buffer_size);
|
2008-03-19 22:28:23 +00:00
|
|
|
|
2005-08-08 01:18:52 +00:00
|
|
|
#ifdef X11
|
2009-02-21 23:37:15 +00:00
|
|
|
if (output_methods & TO_X) {
|
2009-02-14 12:03:11 +00:00
|
|
|
selected_font = 0;
|
|
|
|
update_text_area(); /* to get initial size of the window */
|
2005-07-30 22:59:01 +00:00
|
|
|
|
2008-03-18 00:23:16 +00:00
|
|
|
#ifdef OWN_WINDOW
|
2009-02-14 12:03:11 +00:00
|
|
|
init_window(own_window, text_width + border_margin * 2 + 1,
|
|
|
|
text_height + border_margin * 2 + 1, set_transparent, background_colour,
|
|
|
|
argv, argc);
|
2008-03-18 00:23:16 +00:00
|
|
|
#else /* OWN_WINDOW */
|
2009-02-14 12:03:11 +00:00
|
|
|
init_window(0, text_width + border_margin * 2 + 1,
|
|
|
|
text_height + border_margin * 2 + 1, set_transparent, 0,
|
|
|
|
argv, argc);
|
2008-03-18 00:23:16 +00:00
|
|
|
#endif /* OWN_WINDOW */
|
2008-02-20 20:30:45 +00:00
|
|
|
|
2009-02-14 12:03:11 +00:00
|
|
|
selected_font = 0;
|
|
|
|
update_text_area(); /* to position text/window on screen */
|
2005-07-20 00:30:40 +00:00
|
|
|
|
|
|
|
#ifdef OWN_WINDOW
|
2009-02-14 12:03:11 +00:00
|
|
|
if (own_window && !fixed_pos) {
|
|
|
|
XMoveWindow(display, window.window, window.x, window.y);
|
|
|
|
}
|
|
|
|
if (own_window) {
|
|
|
|
set_transparent_background(window.window);
|
|
|
|
}
|
2005-07-20 00:30:40 +00:00
|
|
|
#endif
|
|
|
|
|
2009-02-14 12:03:11 +00:00
|
|
|
create_gc();
|
2005-07-30 22:59:01 +00:00
|
|
|
|
2009-02-14 12:03:11 +00:00
|
|
|
set_font();
|
|
|
|
draw_stuff();
|
|
|
|
}
|
2005-08-08 01:18:52 +00:00
|
|
|
#endif /* X11 */
|
2005-07-30 22:59:01 +00:00
|
|
|
|
2005-11-01 06:51:48 +00:00
|
|
|
/* Set signal handlers */
|
2005-11-23 19:05:23 +00:00
|
|
|
act.sa_handler = signal_handler;
|
|
|
|
sigemptyset(&act.sa_mask);
|
|
|
|
act.sa_flags = 0;
|
2005-11-24 02:18:42 +00:00
|
|
|
#ifdef SA_RESTART
|
2005-11-23 19:05:23 +00:00
|
|
|
act.sa_flags |= SA_RESTART;
|
2005-11-24 02:18:42 +00:00
|
|
|
#endif
|
2005-11-23 19:05:23 +00:00
|
|
|
|
2008-09-24 06:59:45 +00:00
|
|
|
if ( sigaction(SIGINT, &act, &oact) < 0
|
|
|
|
|| sigaction(SIGUSR1, &act, &oact) < 0
|
|
|
|
|| sigaction(SIGHUP, &act, &oact) < 0
|
|
|
|
|| sigaction(SIGTERM, &act, &oact) < 0) {
|
2008-02-20 20:30:45 +00:00
|
|
|
ERR("error setting signal handler: %s", strerror(errno));
|
2005-07-30 22:59:01 +00:00
|
|
|
}
|
2005-11-01 06:51:48 +00:00
|
|
|
|
2008-02-20 20:30:45 +00:00
|
|
|
main_loop();
|
2006-01-07 07:01:22 +00:00
|
|
|
|
2007-12-31 00:00:35 +00:00
|
|
|
#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
|
2006-03-22 19:27:31 +00:00
|
|
|
kvm_close(kd);
|
|
|
|
#endif
|
2008-02-20 20:30:45 +00:00
|
|
|
|
2005-07-30 22:59:01 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2005-11-01 06:51:48 +00:00
|
|
|
|
2008-12-15 21:40:24 +00:00
|
|
|
static void signal_handler(int sig)
|
2005-11-01 06:51:48 +00:00
|
|
|
{
|
2008-02-20 20:30:45 +00:00
|
|
|
/* signal handler is light as a feather, as it should be.
|
2005-11-01 06:51:48 +00:00
|
|
|
* we will poll g_signal_pending with each loop of conky
|
2006-10-07 01:42:37 +00:00
|
|
|
* and do any signal processing there, NOT here. */
|
2008-02-20 20:30:45 +00:00
|
|
|
g_signal_pending = sig;
|
2005-11-01 06:51:48 +00:00
|
|
|
}
|