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
|
2008-03-31 04:56:39 +00:00
|
|
|
* Copyright (c) 2005-2008 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-02-20 20:30:45 +00:00
|
|
|
* $Id$ */
|
2005-07-20 00:30:40 +00:00
|
|
|
|
|
|
|
#include "conky.h"
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.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 <unistd.h>
|
|
|
|
#include <errno.h>
|
2006-05-08 22:34:38 +00:00
|
|
|
#include <termios.h>
|
2005-07-20 00:30:40 +00:00
|
|
|
#include <string.h>
|
|
|
|
#include <limits.h>
|
|
|
|
#if HAVE_DIRENT_H
|
|
|
|
#include <dirent.h>
|
|
|
|
#endif
|
|
|
|
#include <sys/time.h>
|
2005-08-08 01:18:52 +00:00
|
|
|
#ifdef X11
|
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
|
|
|
|
2006-05-13 20:14:26 +00:00
|
|
|
#ifdef HAVE_ICONV
|
2006-05-13 19:51:26 +00:00
|
|
|
#include <iconv.h>
|
|
|
|
#endif
|
|
|
|
|
2006-08-12 06:10:18 +00:00
|
|
|
#include "build.h"
|
|
|
|
|
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 CONFIG_FILE "$HOME/.conkyrc"
|
|
|
|
#define MAIL_FILE "$MAIL"
|
|
|
|
#define MAX_IF_BLOCK_DEPTH 5
|
2008-03-30 07:04:25 +00:00
|
|
|
#define MAX_TAIL_LINES 100
|
2005-07-20 00:30:40 +00:00
|
|
|
|
2005-11-24 02:18:42 +00:00
|
|
|
/* #define SIGNAL_BLOCKING */
|
|
|
|
#undef SIGNAL_BLOCKING
|
|
|
|
|
2008-03-29 11:35:02 +00:00
|
|
|
static void print_version(void) __attribute__((noreturn));
|
|
|
|
|
2008-03-29 02:01:03 +00:00
|
|
|
static void print_version(void)
|
2006-08-12 06:10:18 +00:00
|
|
|
{
|
2008-02-20 20:30:45 +00:00
|
|
|
printf("Conky %s compiled %s for %s\n", VERSION, BUILD_DATE, BUILD_ARCH);
|
2006-08-12 06:36:58 +00:00
|
|
|
|
2008-02-20 20:30:45 +00:00
|
|
|
printf("\nCompiled in features:\n\n"
|
2008-03-22 06:10:54 +00:00
|
|
|
"System config file: %s\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
|
2008-02-20 20:30:45 +00:00
|
|
|
" * Xdbe extension (double buffer)\n"
|
2006-08-12 06:36:58 +00:00
|
|
|
# endif /* HAVE_XDBE */
|
2006-11-07 01:19:32 +00:00
|
|
|
# ifdef XFT
|
2008-02-20 20:30:45 +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
|
2008-02-20 20:30:45 +00:00
|
|
|
" * audacious\n"
|
2006-08-12 06:36:58 +00:00
|
|
|
#endif /* AUDACIOUS */
|
|
|
|
#ifdef BMPX
|
2008-02-20 20:30:45 +00:00
|
|
|
" * bmpx\n"
|
2006-08-12 06:36:58 +00:00
|
|
|
#endif /* BMPX */
|
|
|
|
#ifdef MPD
|
2008-02-20 20:30:45 +00:00
|
|
|
" * mpd\n"
|
2006-08-12 06:36:58 +00:00
|
|
|
#endif /* MPD */
|
2006-11-05 00:23:18 +00:00
|
|
|
#ifdef XMMS2
|
2008-02-20 20:30:45 +00:00
|
|
|
" * xmms2\n"
|
2006-11-05 00:23:18 +00:00
|
|
|
#endif /* XMMS2 */
|
2008-02-20 20:30:45 +00:00
|
|
|
"\n General features:\n"
|
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
|
2008-02-20 20:30:45 +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 */
|
|
|
|
#ifdef SMAPI
|
|
|
|
" * smapi\n"
|
|
|
|
#endif /* SMAPI */
|
2008-06-03 20:46:15 +00:00
|
|
|
#ifdef NVIDIA
|
|
|
|
" * nvidia\n"
|
|
|
|
#endif
|
2008-03-18 00:23:16 +00:00
|
|
|
"", SYSTEM_CONFIG_FILE
|
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-03-29 03:45:36 +00:00
|
|
|
static const char *suffixes[] = { "B", "kiB", "MiB", "GiB", "TiB", "PiB", "" };
|
2008-03-23 17:26:41 +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
|
|
|
|
};
|
|
|
|
|
|
|
|
/* for fonts */
|
|
|
|
struct font_list {
|
|
|
|
|
2008-03-19 22:28:23 +00:00
|
|
|
char name[DEFAULT_TEXT_BUFFER_SIZE];
|
2006-08-24 18:01:22 +00:00
|
|
|
int num;
|
|
|
|
XFontStruct *font;
|
|
|
|
|
|
|
|
#ifdef XFT
|
|
|
|
XftFont *xftfont;
|
|
|
|
int font_alpha;
|
2008-02-20 20:30:45 +00:00
|
|
|
#endif
|
2006-08-24 18:01:22 +00:00
|
|
|
};
|
2008-02-20 20:30:45 +00:00
|
|
|
|
2006-08-24 18:01:22 +00:00
|
|
|
static int selected_font = 0;
|
|
|
|
static int font_count = -1;
|
|
|
|
struct font_list *fonts = NULL;
|
|
|
|
|
|
|
|
#ifdef XFT
|
|
|
|
|
2008-02-20 20:30:45 +00:00
|
|
|
#define font_height() (use_xft ? (fonts[selected_font].xftfont->ascent + \
|
|
|
|
fonts[selected_font].xftfont->descent) \
|
|
|
|
: (fonts[selected_font].font->max_bounds.ascent + \
|
|
|
|
fonts[selected_font].font->max_bounds.descent))
|
|
|
|
#define font_ascent() (use_xft ? fonts[selected_font].xftfont->ascent \
|
|
|
|
: fonts[selected_font].font->max_bounds.ascent)
|
|
|
|
#define font_descent() (use_xft ? fonts[selected_font].xftfont->descent \
|
|
|
|
: fonts[selected_font].font->max_bounds.descent)
|
2006-08-24 18:01:22 +00:00
|
|
|
|
|
|
|
#else
|
|
|
|
|
2008-02-20 20:30:45 +00:00
|
|
|
#define font_height() (fonts[selected_font].font->max_bounds.ascent + \
|
|
|
|
fonts[selected_font].font->max_bounds.descent)
|
2006-08-24 18:01:22 +00:00
|
|
|
#define font_ascent() fonts[selected_font].font->max_bounds.ascent
|
|
|
|
#define font_descent() fonts[selected_font].font->max_bounds.descent
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define MAX_FONTS 64 // hmm, no particular reason, just makes sense.
|
|
|
|
|
2008-03-29 02:01:03 +00:00
|
|
|
static void set_font(void);
|
2006-08-24 18:01:22 +00:00
|
|
|
|
2005-08-03 07:01:32 +00:00
|
|
|
int addfont(const char *data_in)
|
|
|
|
{
|
|
|
|
if (font_count > MAX_FONTS) {
|
|
|
|
CRIT_ERR("you don't need that many fonts, sorry.");
|
|
|
|
}
|
|
|
|
font_count++;
|
|
|
|
if (font_count == 0) {
|
2005-08-05 06:40:19 +00:00
|
|
|
if (fonts != NULL) {
|
|
|
|
free(fonts);
|
|
|
|
}
|
2008-02-20 20:30:45 +00:00
|
|
|
if ((fonts = (struct font_list *) malloc(sizeof(struct font_list)))
|
|
|
|
== NULL) {
|
2005-08-03 07:01:32 +00:00
|
|
|
CRIT_ERR("malloc");
|
|
|
|
}
|
2008-03-20 05:28:23 +00:00
|
|
|
memset(fonts, 0, sizeof(struct font_list));
|
2005-08-03 07:01:32 +00:00
|
|
|
}
|
2008-02-20 20:30:45 +00:00
|
|
|
fonts = realloc(fonts, (sizeof(struct font_list) * (font_count + 1)));
|
2008-03-20 19:22:29 +00:00
|
|
|
memset(&fonts[font_count], 0, sizeof(struct font_list));
|
2005-08-03 07:01:32 +00:00
|
|
|
if (fonts == NULL) {
|
|
|
|
CRIT_ERR("realloc in addfont");
|
|
|
|
}
|
2008-02-20 20:30:45 +00:00
|
|
|
// must account for null terminator
|
2008-03-19 22:28:23 +00:00
|
|
|
if (strlen(data_in) < DEFAULT_TEXT_BUFFER_SIZE) {
|
2008-04-22 21:54:49 +00:00
|
|
|
strncpy(fonts[font_count].name, data_in, DEFAULT_TEXT_BUFFER_SIZE);
|
2005-08-03 17:04:35 +00:00
|
|
|
#ifdef XFT
|
2005-08-03 07:01:32 +00:00
|
|
|
fonts[font_count].font_alpha = 0xffff;
|
2005-08-03 17:04:35 +00:00
|
|
|
#endif
|
2005-08-03 07:01:32 +00:00
|
|
|
} else {
|
|
|
|
CRIT_ERR("Oops...looks like something overflowed in addfont().");
|
|
|
|
}
|
|
|
|
return font_count;
|
|
|
|
}
|
|
|
|
|
|
|
|
void set_first_font(const char *data_in)
|
|
|
|
{
|
|
|
|
if (font_count < 0) {
|
2008-02-20 20:30:45 +00:00
|
|
|
if ((fonts = (struct font_list *) malloc(sizeof(struct font_list)))
|
|
|
|
== NULL) {
|
2005-08-03 07:01:32 +00:00
|
|
|
CRIT_ERR("malloc");
|
|
|
|
}
|
2008-03-19 22:28:23 +00:00
|
|
|
memset(fonts, 0, sizeof(struct font_list));
|
2005-08-03 07:01:32 +00:00
|
|
|
font_count++;
|
|
|
|
}
|
|
|
|
if (strlen(data_in) > 1) {
|
2008-04-22 22:54:22 +00:00
|
|
|
strncpy(fonts[0].name, data_in, DEFAULT_TEXT_BUFFER_SIZE);
|
2005-08-03 17:04:35 +00:00
|
|
|
#ifdef XFT
|
2005-08-03 07:01:32 +00:00
|
|
|
fonts[0].font_alpha = 0xffff;
|
2005-08-03 17:04:35 +00:00
|
|
|
#endif
|
2005-08-03 07:01:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-03-29 02:01:03 +00:00
|
|
|
void free_fonts(void)
|
2005-08-03 07:01:32 +00:00
|
|
|
{
|
2005-08-06 04:46:16 +00:00
|
|
|
int i;
|
2008-02-20 20:30:45 +00:00
|
|
|
|
2007-09-02 03:58:22 +00:00
|
|
|
for (i = 0; i <= font_count; i++) {
|
2005-08-05 06:40:19 +00:00
|
|
|
#ifdef XFT
|
|
|
|
if (use_xft) {
|
|
|
|
XftFontClose(display, fonts[i].xftfont);
|
2008-03-20 05:28:23 +00:00
|
|
|
fonts[i].xftfont = 0;
|
2005-08-05 06:40:19 +00:00
|
|
|
} else
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
XFreeFont(display, fonts[i].font);
|
2008-03-20 05:28:23 +00:00
|
|
|
fonts[i].font = 0;
|
2005-08-05 06:40:19 +00:00
|
|
|
}
|
2007-09-02 03:58:22 +00:00
|
|
|
}
|
2005-08-03 07:01:32 +00:00
|
|
|
free(fonts);
|
2007-09-02 03:58:22 +00:00
|
|
|
fonts = 0;
|
2005-08-05 06:40:19 +00:00
|
|
|
font_count = -1;
|
|
|
|
selected_font = 0;
|
2005-08-06 04:46:16 +00:00
|
|
|
}
|
2005-08-03 07:01:32 +00:00
|
|
|
|
2008-03-29 02:01:03 +00:00
|
|
|
static void load_fonts(void)
|
2005-08-03 07:01:32 +00:00
|
|
|
{
|
|
|
|
int i;
|
2008-02-20 20:30:45 +00:00
|
|
|
|
|
|
|
for (i = 0; i <= font_count; i++) {
|
2005-08-03 07:01:32 +00:00
|
|
|
#ifdef XFT
|
2008-02-20 20:30:45 +00:00
|
|
|
/* load Xft font */
|
2008-03-20 19:22:29 +00:00
|
|
|
if (use_xft && fonts[i].xftfont) {
|
2008-03-20 05:28:23 +00:00
|
|
|
continue;
|
2008-03-20 19:22:29 +00:00
|
|
|
} else if (use_xft) {
|
2008-02-20 20:30:45 +00:00
|
|
|
/* if (fonts[i].xftfont != NULL && selected_font == 0) {
|
|
|
|
XftFontClose(display, fonts[i].xftfont);
|
|
|
|
} */
|
2008-03-19 22:28:23 +00:00
|
|
|
fonts[i].xftfont = XftFontOpenName(display, screen,
|
|
|
|
fonts[i].name);
|
|
|
|
if (fonts[i].xftfont != NULL) {
|
2008-02-20 20:30:45 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
ERR("can't load Xft font '%s'", fonts[i].name);
|
|
|
|
if ((fonts[i].xftfont = XftFontOpenName(display, screen,
|
|
|
|
"courier-12")) != NULL) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
ERR("can't load Xft font '%s'", "courier-12");
|
|
|
|
|
|
|
|
if ((fonts[i].font = XLoadQueryFont(display, "fixed")) == NULL) {
|
|
|
|
CRIT_ERR("can't load font '%s'", "fixed");
|
|
|
|
}
|
|
|
|
use_xft = 0;
|
|
|
|
|
2005-08-03 07:01:32 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
#endif
|
2008-02-20 20:30:45 +00:00
|
|
|
/* load normal font */
|
|
|
|
/* if (fonts[i].font != NULL) {
|
|
|
|
XFreeFont(display, fonts[i].font);
|
|
|
|
} */
|
|
|
|
|
2008-03-21 23:39:38 +00:00
|
|
|
if (fonts[i].font || (fonts[i].font = XLoadQueryFont(display, fonts[i].name)) == NULL) {
|
2008-02-20 20:30:45 +00:00
|
|
|
ERR("can't load font '%s'", fonts[i].name);
|
|
|
|
if ((fonts[i].font = XLoadQueryFont(display, "fixed")) == NULL) {
|
|
|
|
CRIT_ERR("can't load font '%s'", "fixed");
|
|
|
|
printf("loaded fixed?\n");
|
|
|
|
}
|
2005-08-03 07:01:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-08-08 01:18:52 +00:00
|
|
|
#endif /* X11 */
|
|
|
|
|
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;
|
|
|
|
|
2005-08-08 01:18:52 +00:00
|
|
|
static int cpu_avg_samples, net_avg_samples;
|
|
|
|
|
|
|
|
#ifdef X11
|
|
|
|
|
2008-04-13 04:10:35 +00:00
|
|
|
static int show_graph_scale;
|
|
|
|
|
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
|
|
|
|
2006-11-22 21:53:54 +00:00
|
|
|
/* maximum number of special things, e.g. fonts, offsets, aligns, etc. */
|
|
|
|
static unsigned int max_specials = MAX_SPECIALS_DEFAULT;
|
|
|
|
|
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;
|
|
|
|
|
2005-11-11 03:28:24 +00:00
|
|
|
#ifdef TCP_PORT_MONITOR
|
2008-02-20 20:30:45 +00:00
|
|
|
tcp_port_monitor_args_t tcp_port_monitor_args;
|
2005-11-11 03:28:24 +00:00
|
|
|
#endif
|
|
|
|
|
2007-10-23 21:52:11 +00:00
|
|
|
static char *text = 0;
|
2006-05-14 07:05:05 +00:00
|
|
|
long text_lines;
|
2005-07-20 00:30:40 +00:00
|
|
|
|
|
|
|
static int total_updates;
|
|
|
|
|
|
|
|
/* if-blocks */
|
2005-07-28 04:48:27 +00:00
|
|
|
static int blockdepth = 0;
|
|
|
|
static int if_jumped = 0;
|
|
|
|
static int blockstart[MAX_IF_BLOCK_DEPTH];
|
|
|
|
|
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
|
|
|
{
|
|
|
|
#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
|
|
|
|
|
|
|
/* special stuff in text_buffer */
|
|
|
|
|
|
|
|
#define SPECIAL_CHAR '\x01'
|
|
|
|
|
2008-02-20 10:01:23 +00:00
|
|
|
enum special_types {
|
2005-07-20 00:30:40 +00:00
|
|
|
HORIZONTAL_LINE,
|
|
|
|
STIPPLED_HR,
|
|
|
|
BAR,
|
|
|
|
FG,
|
|
|
|
BG,
|
|
|
|
OUTLINE,
|
|
|
|
ALIGNR,
|
|
|
|
ALIGNC,
|
2005-07-28 04:48:27 +00:00
|
|
|
GRAPH,
|
2005-07-31 19:49:39 +00:00
|
|
|
OFFSET,
|
2005-08-21 05:04:22 +00:00
|
|
|
VOFFSET,
|
2005-08-02 05:06:53 +00:00
|
|
|
FONT,
|
2006-08-10 16:56:13 +00:00
|
|
|
GOTO,
|
|
|
|
TAB,
|
2005-07-20 00:30:40 +00:00
|
|
|
};
|
|
|
|
|
2006-11-22 21:53:54 +00:00
|
|
|
struct special_t {
|
2005-07-20 00:30:40 +00:00
|
|
|
int type;
|
|
|
|
short height;
|
|
|
|
short width;
|
|
|
|
long arg;
|
2005-07-29 04:32:56 +00:00
|
|
|
double *graph;
|
|
|
|
double graph_scale;
|
2008-04-13 04:10:35 +00:00
|
|
|
short show_scale;
|
2005-07-28 06:56:55 +00:00
|
|
|
int graph_width;
|
2005-07-29 04:32:56 +00:00
|
|
|
int scaled;
|
2008-02-20 20:30:45 +00:00
|
|
|
unsigned long first_colour; // for graph gradient
|
2005-08-01 09:15:02 +00:00
|
|
|
unsigned long last_colour;
|
2007-10-17 20:31:27 +00:00
|
|
|
short font_added;
|
2006-11-22 21:53:54 +00:00
|
|
|
};
|
2005-07-20 00:30:40 +00:00
|
|
|
|
2008-02-20 20:30:45 +00:00
|
|
|
/* create specials array on heap instead of stack with introduction of
|
|
|
|
* max_specials */
|
2006-11-22 21:53:54 +00:00
|
|
|
static struct special_t *specials = NULL;
|
|
|
|
|
|
|
|
static unsigned int special_count;
|
2008-02-20 20:30:45 +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
|
|
|
|
2008-02-20 20:30:45 +00:00
|
|
|
/* why 256? cause an array of more then 256 doubles seems excessive,
|
|
|
|
* and who needs that kind of precision anyway? */
|
|
|
|
#define MAX_GRAPH_DEPTH 256
|
2005-07-28 06:56:55 +00:00
|
|
|
|
2008-02-20 10:01:23 +00:00
|
|
|
static struct special_t *new_special(char *buf, enum special_types t)
|
2005-07-20 00:30:40 +00:00
|
|
|
{
|
2008-02-20 20:30:45 +00:00
|
|
|
if (special_count >= max_specials) {
|
2005-07-28 04:48:27 +00:00
|
|
|
CRIT_ERR("too many special things in text");
|
2008-02-20 20:30:45 +00:00
|
|
|
}
|
2005-07-20 00:30:40 +00:00
|
|
|
|
|
|
|
buf[0] = SPECIAL_CHAR;
|
|
|
|
buf[1] = '\0';
|
|
|
|
specials[special_count].type = t;
|
|
|
|
return &specials[special_count++];
|
|
|
|
}
|
|
|
|
|
2008-02-20 20:30:45 +00:00
|
|
|
long fwd_fcharfind(FILE *fp, char val, unsigned int step)
|
|
|
|
{
|
2006-12-29 23:14:31 +00:00
|
|
|
#define BUFSZ 0x1000
|
|
|
|
long ret = -1;
|
2006-12-29 23:38:57 +00:00
|
|
|
unsigned int count = 0;
|
2006-12-29 23:14:31 +00:00
|
|
|
static char buf[BUFSZ];
|
|
|
|
long orig_pos = ftell(fp);
|
|
|
|
long buf_pos = -1;
|
|
|
|
long buf_size = BUFSZ;
|
2008-02-20 20:30:45 +00:00
|
|
|
char *cur_found = NULL;
|
|
|
|
|
|
|
|
while (count < step) {
|
|
|
|
if (cur_found == NULL) {
|
2006-12-29 23:14:31 +00:00
|
|
|
buf_size = fread(buf, 1, buf_size, fp);
|
|
|
|
buf_pos = 0;
|
|
|
|
}
|
2008-02-20 20:30:45 +00:00
|
|
|
cur_found = memchr(buf + buf_pos, val, buf_size - buf_pos);
|
|
|
|
if (cur_found != NULL) {
|
|
|
|
buf_pos = cur_found - buf + 1;
|
2006-12-29 23:14:31 +00:00
|
|
|
count++;
|
2008-02-20 20:30:45 +00:00
|
|
|
} else {
|
|
|
|
if (feof(fp)) {
|
2006-12-29 23:14:31 +00:00
|
|
|
break;
|
2008-02-20 20:30:45 +00:00
|
|
|
}
|
2006-12-29 23:14:31 +00:00
|
|
|
}
|
2005-07-28 04:48:27 +00:00
|
|
|
}
|
2008-02-20 20:30:45 +00:00
|
|
|
if (count == step) {
|
2006-12-29 23:14:31 +00:00
|
|
|
ret = ftell(fp) - buf_size + buf_pos - 1;
|
2008-02-20 20:30:45 +00:00
|
|
|
}
|
2006-12-29 23:14:31 +00:00
|
|
|
fseek(fp, orig_pos, SEEK_SET);
|
|
|
|
return ret;
|
|
|
|
#undef BUFSZ
|
2005-07-28 04:48:27 +00:00
|
|
|
}
|
2005-07-20 00:30:40 +00:00
|
|
|
|
2007-03-28 17:53:40 +00:00
|
|
|
#ifndef HAVE_MEMRCHR
|
2008-02-20 10:01:23 +00:00
|
|
|
void *memrchr(const void *buffer, char c, size_t n)
|
2007-03-01 01:43:43 +00:00
|
|
|
{
|
|
|
|
const unsigned char *p = buffer;
|
|
|
|
|
2008-02-20 20:30:45 +00:00
|
|
|
for (p += n; n; n--) {
|
|
|
|
if (*--p == c) {
|
|
|
|
return (void *) p;
|
|
|
|
}
|
|
|
|
}
|
2007-03-01 01:43:43 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
#endif
|
2008-02-20 20:30:45 +00:00
|
|
|
|
|
|
|
long rev_fcharfind(FILE *fp, char val, unsigned int step)
|
|
|
|
{
|
2006-12-29 23:14:31 +00:00
|
|
|
#define BUFSZ 0x1000
|
|
|
|
long ret = -1;
|
2006-12-29 23:38:57 +00:00
|
|
|
unsigned int count = 0;
|
2006-12-29 23:14:31 +00:00
|
|
|
static char buf[BUFSZ];
|
|
|
|
long orig_pos = ftell(fp);
|
|
|
|
long buf_pos = -1;
|
|
|
|
long file_pos = orig_pos;
|
|
|
|
long buf_size = BUFSZ;
|
2008-02-20 20:30:45 +00:00
|
|
|
char *cur_found;
|
|
|
|
|
|
|
|
while (count < step) {
|
|
|
|
if (buf_pos <= 0) {
|
|
|
|
if (file_pos > BUFSZ) {
|
|
|
|
fseek(fp, file_pos - BUFSZ, SEEK_SET);
|
|
|
|
} else {
|
2006-12-29 23:14:31 +00:00
|
|
|
buf_size = file_pos;
|
|
|
|
fseek(fp, 0, SEEK_SET);
|
|
|
|
}
|
|
|
|
file_pos = ftell(fp);
|
|
|
|
buf_pos = fread(buf, 1, buf_size, fp);
|
|
|
|
}
|
2008-02-20 10:01:23 +00:00
|
|
|
cur_found = memrchr(buf, val, (size_t) buf_pos);
|
2008-02-20 20:30:45 +00:00
|
|
|
if (cur_found != NULL) {
|
|
|
|
buf_pos = cur_found - buf;
|
2006-12-29 23:14:31 +00:00
|
|
|
count++;
|
|
|
|
} else {
|
|
|
|
buf_pos = -1;
|
2008-02-20 20:30:45 +00:00
|
|
|
if (file_pos == 0) {
|
2006-12-29 23:14:31 +00:00
|
|
|
break;
|
|
|
|
}
|
2005-08-21 08:23:04 +00:00
|
|
|
}
|
|
|
|
}
|
2006-12-29 23:14:31 +00:00
|
|
|
fseek(fp, orig_pos, SEEK_SET);
|
2008-02-20 20:30:45 +00:00
|
|
|
if (count == step) {
|
2006-12-29 23:14:31 +00:00
|
|
|
ret = file_pos + buf_pos;
|
2008-02-20 20:30:45 +00:00
|
|
|
}
|
2006-12-29 23:14:31 +00:00
|
|
|
return ret;
|
|
|
|
#undef BUFSZ
|
2005-08-21 08:23:04 +00:00
|
|
|
}
|
2005-07-20 00:30:40 +00:00
|
|
|
|
|
|
|
static void new_bar(char *buf, int w, int h, int usage)
|
|
|
|
{
|
|
|
|
struct special_t *s = new_special(buf, BAR);
|
2008-02-20 20:30:45 +00:00
|
|
|
|
2005-07-20 00:30:40 +00:00
|
|
|
s->arg = (usage > 255) ? 255 : ((usage < 0) ? 0 : usage);
|
|
|
|
s->width = w;
|
|
|
|
s->height = h;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char *scan_bar(const char *args, int *w, int *h)
|
|
|
|
{
|
2008-02-20 20:30:45 +00:00
|
|
|
/* zero width means all space that is available */
|
|
|
|
*w = 0;
|
2005-07-24 23:08:51 +00:00
|
|
|
*h = 6;
|
2005-07-20 00:30:40 +00:00
|
|
|
/* bar's argument is either height or height,width */
|
|
|
|
if (args) {
|
|
|
|
int n = 0;
|
2008-02-20 20:30:45 +00:00
|
|
|
|
|
|
|
if (sscanf(args, "%d,%d %n", h, w, &n) <= 1) {
|
2005-07-20 00:30:40 +00:00
|
|
|
sscanf(args, "%d %n", h, &n);
|
2008-02-20 20:30:45 +00:00
|
|
|
}
|
2005-07-20 00:30:40 +00:00
|
|
|
args += n;
|
|
|
|
}
|
|
|
|
|
|
|
|
return args;
|
|
|
|
}
|
2005-08-11 05:21:56 +00:00
|
|
|
|
2005-08-02 05:06:53 +00:00
|
|
|
static char *scan_font(const char *args)
|
|
|
|
{
|
2008-02-20 20:30:45 +00:00
|
|
|
if (args && *args) {
|
2008-04-22 22:54:22 +00:00
|
|
|
return strndup(args, DEFAULT_TEXT_BUFFER_SIZE);
|
2008-02-20 20:30:45 +00:00
|
|
|
}
|
|
|
|
|
2005-08-03 07:01:32 +00:00
|
|
|
return NULL;
|
2005-08-02 05:06:53 +00:00
|
|
|
}
|
|
|
|
|
2005-08-11 05:21:56 +00:00
|
|
|
#ifdef X11
|
2008-02-20 20:30:45 +00:00
|
|
|
static void new_font(char *buf, char *args)
|
|
|
|
{
|
2006-05-09 23:08:23 +00:00
|
|
|
if (args) {
|
|
|
|
struct special_t *s = new_special(buf, FONT);
|
2008-02-20 20:30:45 +00:00
|
|
|
|
2008-03-19 22:28:23 +00:00
|
|
|
if (s->font_added > font_count || !s->font_added || strncmp(args, fonts[s->font_added].name, DEFAULT_TEXT_BUFFER_SIZE)) {
|
2006-05-09 23:08:23 +00:00
|
|
|
int tmp = selected_font;
|
2008-02-20 20:30:45 +00:00
|
|
|
|
2006-05-09 23:08:23 +00:00
|
|
|
selected_font = s->font_added = addfont(args);
|
|
|
|
load_fonts();
|
|
|
|
selected_font = tmp;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
struct special_t *s = new_special(buf, FONT);
|
2005-08-06 04:46:16 +00:00
|
|
|
int tmp = selected_font;
|
2008-02-20 20:30:45 +00:00
|
|
|
|
2006-05-09 23:08:23 +00:00
|
|
|
selected_font = s->font_added = 0;
|
2005-08-06 04:46:16 +00:00
|
|
|
selected_font = tmp;
|
2005-08-03 07:01:32 +00:00
|
|
|
}
|
2005-08-02 05:06:53 +00:00
|
|
|
}
|
2005-08-11 05:21:56 +00:00
|
|
|
#endif
|
2005-07-30 22:59:01 +00:00
|
|
|
inline void graph_append(struct special_t *graph, double f)
|
|
|
|
{
|
2008-03-29 06:24:04 +00:00
|
|
|
int i;
|
|
|
|
|
2005-08-25 04:00:55 +00:00
|
|
|
if (!graph->scaled && f > graph->graph_scale) {
|
|
|
|
f = graph->graph_scale;
|
|
|
|
}
|
2008-02-20 20:30:45 +00:00
|
|
|
|
2005-07-29 04:32:56 +00:00
|
|
|
if (graph->scaled) {
|
2005-08-26 02:16:35 +00:00
|
|
|
graph->graph_scale = 1;
|
2005-07-28 06:56:55 +00:00
|
|
|
}
|
2008-02-20 20:30:45 +00:00
|
|
|
graph->graph[0] = f; /* add new data */
|
|
|
|
/* shift all the data by 1 */
|
|
|
|
for (i = graph->graph_width - 1; i > 0; i--) {
|
2006-01-26 04:44:19 +00:00
|
|
|
graph->graph[i] = graph->graph[i - 1];
|
2005-07-29 04:32:56 +00:00
|
|
|
if (graph->scaled && graph->graph[i] > graph->graph_scale) {
|
2008-02-20 20:30:45 +00:00
|
|
|
/* check if we need to update the scale */
|
|
|
|
graph->graph_scale = graph->graph[i];
|
2005-07-29 04:32:56 +00:00
|
|
|
}
|
|
|
|
}
|
2005-07-28 06:56:55 +00:00
|
|
|
}
|
|
|
|
|
2005-08-30 14:59:37 +00:00
|
|
|
short colour_depth = 0;
|
2008-03-29 02:01:03 +00:00
|
|
|
void set_up_gradient(void);
|
2005-08-30 14:59:37 +00:00
|
|
|
|
2005-08-30 19:13:01 +00:00
|
|
|
/* precalculated: 31/255, and 63/255 */
|
|
|
|
#define CONST_8_TO_5_BITS 0.12156862745098
|
|
|
|
#define CONST_8_TO_6_BITS 0.247058823529412
|
|
|
|
|
2008-02-20 20:30:45 +00:00
|
|
|
/* adjust color values depending on color depth */
|
2005-08-30 14:59:37 +00:00
|
|
|
static unsigned int adjust_colors(unsigned int color)
|
|
|
|
{
|
|
|
|
double r, g, b;
|
2008-02-20 20:30:45 +00:00
|
|
|
|
2005-08-30 14:59:37 +00:00
|
|
|
if (colour_depth == 0) {
|
|
|
|
set_up_gradient();
|
|
|
|
}
|
|
|
|
if (colour_depth == 16) {
|
|
|
|
r = (color & 0xff0000) >> 16;
|
|
|
|
g = (color & 0xff00) >> 8;
|
|
|
|
b = color & 0xff;
|
2008-02-20 20:30:45 +00:00
|
|
|
color = (int) (r * CONST_8_TO_5_BITS) << 11;
|
|
|
|
color |= (int) (g * CONST_8_TO_6_BITS) << 5;
|
|
|
|
color |= (int) (b * CONST_8_TO_5_BITS);
|
2005-08-30 14:59:37 +00:00
|
|
|
}
|
|
|
|
return color;
|
|
|
|
}
|
|
|
|
|
2008-02-20 20:30:45 +00:00
|
|
|
static void new_graph(char *buf, int w, int h, unsigned int first_colour,
|
|
|
|
unsigned int second_colour, double i, int scale, int append)
|
2005-07-28 04:48:27 +00:00
|
|
|
{
|
|
|
|
struct special_t *s = new_special(buf, GRAPH);
|
2008-02-20 20:30:45 +00:00
|
|
|
|
2005-09-04 03:43:18 +00:00
|
|
|
s->width = w;
|
|
|
|
if (s->graph == NULL) {
|
|
|
|
if (s->width > 0 && s->width < MAX_GRAPH_DEPTH) {
|
2008-02-20 20:30:45 +00:00
|
|
|
// subtract 2 for the box
|
|
|
|
s->graph_width = s->width /* - 2 */;
|
2005-09-04 03:43:18 +00:00
|
|
|
} else {
|
2006-05-19 01:37:45 +00:00
|
|
|
s->graph_width = MAX_GRAPH_DEPTH - 2;
|
2005-09-04 03:43:18 +00:00
|
|
|
}
|
|
|
|
s->graph = malloc(s->graph_width * sizeof(double));
|
2005-09-16 01:55:36 +00:00
|
|
|
memset(s->graph, 0, s->graph_width * sizeof(double));
|
2005-09-04 03:43:18 +00:00
|
|
|
s->graph_scale = 100;
|
|
|
|
}
|
2005-07-28 04:48:27 +00:00
|
|
|
s->height = h;
|
2005-08-30 14:59:37 +00:00
|
|
|
s->first_colour = adjust_colors(first_colour);
|
|
|
|
s->last_colour = adjust_colors(second_colour);
|
2005-08-25 04:00:55 +00:00
|
|
|
if (scale != 0) {
|
|
|
|
s->scaled = 0;
|
|
|
|
} else {
|
|
|
|
s->scaled = 1;
|
|
|
|
}
|
2008-02-20 20:30:45 +00:00
|
|
|
/* if (s->width) {
|
2006-05-19 01:37:45 +00:00
|
|
|
s->graph_width = s->width - 2; // subtract 2 for rectangle around
|
2008-02-20 20:30:45 +00:00
|
|
|
} */
|
2005-08-25 04:00:55 +00:00
|
|
|
if (s->scaled) {
|
2005-07-30 11:23:26 +00:00
|
|
|
s->graph_scale = 1;
|
2008-04-13 04:10:35 +00:00
|
|
|
s->show_scale = 1;
|
2005-07-30 22:59:01 +00:00
|
|
|
} else {
|
2005-08-25 04:00:55 +00:00
|
|
|
s->graph_scale = scale;
|
2008-04-13 04:10:35 +00:00
|
|
|
s->show_scale = 0;
|
2005-07-29 04:32:56 +00:00
|
|
|
}
|
2005-08-23 03:00:50 +00:00
|
|
|
if (append) {
|
|
|
|
graph_append(s, i);
|
|
|
|
}
|
2005-07-28 04:48:27 +00:00
|
|
|
}
|
|
|
|
|
2008-02-09 02:21:06 +00:00
|
|
|
static char *scan_graph(const char *args, int *w, int *h,
|
|
|
|
unsigned int *first_colour, unsigned int *last_colour,
|
|
|
|
unsigned int *scale)
|
2005-07-28 04:48:27 +00:00
|
|
|
{
|
2008-02-09 02:21:06 +00:00
|
|
|
char buf[64];
|
2008-04-22 22:54:22 +00:00
|
|
|
buf[0] = 0;
|
2008-02-09 02:21:06 +00:00
|
|
|
|
2008-02-10 11:14:19 +00:00
|
|
|
/* zero width means all space that is available */
|
|
|
|
*w = 0;
|
|
|
|
*h = 25;
|
|
|
|
*first_colour = 0;
|
|
|
|
*last_colour = 0;
|
2008-02-20 10:00:45 +00:00
|
|
|
*scale = 0;
|
2005-07-28 04:48:27 +00:00
|
|
|
/* graph's argument is either height or height,width */
|
|
|
|
if (args) {
|
2008-03-29 03:01:48 +00:00
|
|
|
if (sscanf(args, "%d,%d %x %x %u", h, w, first_colour, last_colour,
|
2008-02-09 02:21:06 +00:00
|
|
|
scale) == 5) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
*scale = 0;
|
|
|
|
if (sscanf(args, "%d,%d %x %x", h, w, first_colour, last_colour) == 4) {
|
|
|
|
return NULL;
|
|
|
|
}
|
2008-03-29 03:01:48 +00:00
|
|
|
if (sscanf(args, "%63s %d,%d %x %x %u", buf, h, w, first_colour,
|
2008-02-09 02:21:06 +00:00
|
|
|
last_colour, scale) == 6) {
|
2008-04-02 18:44:49 +00:00
|
|
|
return strndup(buf, text_buffer_size);
|
2008-02-09 02:21:06 +00:00
|
|
|
}
|
|
|
|
*scale = 0;
|
|
|
|
if (sscanf(args, "%63s %d,%d %x %x", buf, h, w, first_colour,
|
|
|
|
last_colour) == 5) {
|
2008-04-02 18:44:49 +00:00
|
|
|
return strndup(buf, text_buffer_size);
|
2008-02-09 02:21:06 +00:00
|
|
|
}
|
|
|
|
buf[0] = '\0';
|
|
|
|
*h = 25;
|
|
|
|
*w = 0;
|
2008-03-29 03:01:48 +00:00
|
|
|
if (sscanf(args, "%x %x %u", first_colour, last_colour, scale) == 3) {
|
2008-02-09 02:21:06 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
*scale = 0;
|
|
|
|
if (sscanf(args, "%x %x", first_colour, last_colour) == 2) {
|
|
|
|
return NULL;
|
|
|
|
}
|
2008-03-29 03:01:48 +00:00
|
|
|
if (sscanf(args, "%63s %x %x %u", buf, first_colour, last_colour,
|
2008-02-09 02:21:06 +00:00
|
|
|
scale) == 4) {
|
2008-04-02 18:44:49 +00:00
|
|
|
return strndup(buf, text_buffer_size);
|
2008-02-09 02:21:06 +00:00
|
|
|
}
|
|
|
|
*scale = 0;
|
|
|
|
if (sscanf(args, "%63s %x %x", buf, first_colour, last_colour) == 3) {
|
2008-04-02 18:44:49 +00:00
|
|
|
return strndup(buf, text_buffer_size);
|
2008-02-09 02:21:06 +00:00
|
|
|
}
|
|
|
|
buf[0] = '\0';
|
|
|
|
*first_colour = 0;
|
|
|
|
*last_colour = 0;
|
2008-03-29 03:01:48 +00:00
|
|
|
if (sscanf(args, "%d,%d %u", h, w, scale) == 3) {
|
2008-02-09 02:21:06 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
*scale = 0;
|
|
|
|
if (sscanf(args, "%d,%d", h, w) == 2) {
|
|
|
|
return NULL;
|
|
|
|
}
|
2008-03-29 03:01:48 +00:00
|
|
|
if (sscanf(args, "%63s %d,%d %u", buf, h, w, scale) < 4) {
|
2008-02-09 02:21:06 +00:00
|
|
|
*scale = 0;
|
|
|
|
//TODO: check the return value and throw an error?
|
|
|
|
sscanf(args, "%63s %d,%d", buf, h, w);
|
|
|
|
}
|
|
|
|
|
2008-04-02 18:44:49 +00:00
|
|
|
return strndup(buf, text_buffer_size);
|
2008-02-09 02:21:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (buf[0] == '\0') {
|
|
|
|
return NULL;
|
|
|
|
} else {
|
2008-04-02 18:44:49 +00:00
|
|
|
return strndup(buf, text_buffer_size);
|
2008-02-09 02:21:06 +00:00
|
|
|
}
|
2005-07-28 04:48:27 +00:00
|
|
|
}
|
|
|
|
|
2005-07-20 00:30:40 +00:00
|
|
|
static inline void new_hr(char *buf, int a)
|
|
|
|
{
|
|
|
|
new_special(buf, HORIZONTAL_LINE)->height = a;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void new_stippled_hr(char *buf, int a, int b)
|
|
|
|
{
|
|
|
|
struct special_t *s = new_special(buf, STIPPLED_HR);
|
2008-02-20 20:30:45 +00:00
|
|
|
|
2005-07-20 00:30:40 +00:00
|
|
|
s->height = b;
|
|
|
|
s->arg = a;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void new_fg(char *buf, long c)
|
|
|
|
{
|
|
|
|
new_special(buf, FG)->arg = c;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void new_bg(char *buf, long c)
|
|
|
|
{
|
|
|
|
new_special(buf, BG)->arg = c;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void new_outline(char *buf, long c)
|
|
|
|
{
|
|
|
|
new_special(buf, OUTLINE)->arg = c;
|
|
|
|
}
|
|
|
|
|
2005-07-31 19:49:39 +00:00
|
|
|
static inline void new_offset(char *buf, long c)
|
2005-07-31 08:27:03 +00:00
|
|
|
{
|
2005-08-21 05:04:22 +00:00
|
|
|
new_special(buf, OFFSET)->arg = c;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void new_voffset(char *buf, long c)
|
|
|
|
{
|
|
|
|
new_special(buf, VOFFSET)->arg = c;
|
2005-07-31 08:27:03 +00:00
|
|
|
}
|
|
|
|
|
2005-07-28 04:48:27 +00:00
|
|
|
static inline void new_alignr(char *buf, long c)
|
|
|
|
{
|
2005-07-20 00:30:40 +00:00
|
|
|
new_special(buf, ALIGNR)->arg = c;
|
|
|
|
}
|
|
|
|
|
2005-07-28 04:48:27 +00:00
|
|
|
static inline void new_alignc(char *buf, long c)
|
|
|
|
{
|
2005-07-20 00:30:40 +00:00
|
|
|
new_special(buf, ALIGNC)->arg = c;
|
|
|
|
}
|
|
|
|
|
2006-08-10 16:56:13 +00:00
|
|
|
static inline void new_goto(char *buf, long c)
|
|
|
|
{
|
|
|
|
new_special(buf, GOTO)->arg = c;
|
|
|
|
}
|
|
|
|
|
2008-02-20 20:30:45 +00:00
|
|
|
static inline void new_tab(char *buf, int a, int b)
|
|
|
|
{
|
2006-08-10 16:56:13 +00:00
|
|
|
struct special_t *s = new_special(buf, TAB);
|
2008-02-20 20:30:45 +00:00
|
|
|
|
2006-08-10 16:56:13 +00:00
|
|
|
s->width = a;
|
|
|
|
s->arg = b;
|
|
|
|
}
|
|
|
|
|
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. */
|
2008-03-29 11:35:02 +00:00
|
|
|
static int spaced_print(char *, int, const char *, int, const char *, ...)
|
|
|
|
__attribute__((format(printf, 3, 6)));
|
|
|
|
|
2008-03-29 03:45:36 +00:00
|
|
|
static int spaced_print(char *buf, int size, const char *format, int width,
|
|
|
|
const char *func_name, ...) {
|
2008-02-09 02:21:06 +00:00
|
|
|
int len;
|
|
|
|
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
|
|
|
|
va_start(argp, func_name);
|
|
|
|
vsnprintf(tempbuf, size, format, argp);
|
|
|
|
va_end(argp);
|
|
|
|
|
|
|
|
switch (use_spacer) {
|
|
|
|
case NO_SPACER:
|
|
|
|
len = snprintf(buf, size, "%s", tempbuf);
|
|
|
|
break;
|
|
|
|
case LEFT_SPACER:
|
2008-03-22 18:18:25 +00:00
|
|
|
len = snprintf(buf, size, "%*s", width - 1, tempbuf);
|
2008-02-09 02:21:06 +00:00
|
|
|
break;
|
|
|
|
case RIGHT_SPACER:
|
2008-03-22 18:18:25 +00:00
|
|
|
len = snprintf(buf, size, "%-*s", width - 1, tempbuf);
|
2008-02-09 02:21:06 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
CRIT_ERR("%s encountered invalid use_spacer value (%d)", func_name,
|
|
|
|
use_spacer);
|
|
|
|
}
|
|
|
|
|
|
|
|
free(tempbuf);
|
|
|
|
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
2005-08-11 18:13:57 +00:00
|
|
|
/* converts from bytes to human readable format (k, M, G, T) */
|
2008-03-29 03:45:36 +00:00
|
|
|
static void human_readable(long long num, char *buf, int size, const char *func_name)
|
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;
|
|
|
|
int precision, len;
|
|
|
|
static const int WIDTH = 10, SHORT_WIDTH = 8;
|
|
|
|
|
|
|
|
if (num < 1024LL) {
|
|
|
|
if (short_units) {
|
|
|
|
spaced_print(buf, size, "%lld%c", SHORT_WIDTH, func_name, num,
|
|
|
|
**suffix);
|
|
|
|
} else {
|
|
|
|
spaced_print(buf, size, "%lld%s", WIDTH, func_name, num, *suffix);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (num / 1024 >= 1000LL && **(suffix + 2)) {
|
|
|
|
num /= 1024;
|
|
|
|
suffix++;
|
|
|
|
}
|
|
|
|
|
|
|
|
suffix++;
|
|
|
|
fnum = num / 1024.0;
|
2008-03-30 07:04:25 +00:00
|
|
|
|
2008-02-09 02:21:06 +00:00
|
|
|
precision = 3;
|
|
|
|
do {
|
|
|
|
precision--;
|
|
|
|
if (precision < 0) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (short_units) {
|
|
|
|
len = spaced_print(buf, size, "%.*f%c", SHORT_WIDTH, func_name,
|
|
|
|
precision, fnum, **suffix);
|
|
|
|
} else {
|
|
|
|
len = spaced_print(buf, size, "%.*f%s", WIDTH, func_name, precision,
|
|
|
|
fnum, *suffix);
|
|
|
|
}
|
|
|
|
} while (len >= (short_units ? SHORT_WIDTH : WIDTH) || len >= size);
|
2005-07-20 00:30:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* text handling */
|
|
|
|
|
|
|
|
enum text_object_type {
|
2007-08-10 21:14:06 +00:00
|
|
|
OBJ_addr,
|
2008-03-18 00:23:16 +00:00
|
|
|
#if defined(__linux__)
|
|
|
|
OBJ_addrs,
|
|
|
|
#endif /* __linux__ */
|
2007-08-10 21:14:06 +00:00
|
|
|
#ifndef __OpenBSD__
|
2005-07-20 00:30:40 +00:00
|
|
|
OBJ_acpiacadapter,
|
|
|
|
OBJ_adt746xcpu,
|
|
|
|
OBJ_adt746xfan,
|
|
|
|
OBJ_acpifan,
|
|
|
|
OBJ_acpitemp,
|
2005-08-21 06:36:13 +00:00
|
|
|
OBJ_acpitempf,
|
2005-07-20 00:30:40 +00:00
|
|
|
OBJ_battery,
|
2006-12-12 23:21:14 +00:00
|
|
|
OBJ_battery_time,
|
2007-04-06 06:11:53 +00:00
|
|
|
OBJ_battery_percent,
|
|
|
|
OBJ_battery_bar,
|
2007-08-10 21:06:30 +00:00
|
|
|
#endif /* !__OpenBSD__ */
|
2005-07-20 00:30:40 +00:00
|
|
|
OBJ_buffers,
|
|
|
|
OBJ_cached,
|
|
|
|
OBJ_color,
|
2007-04-25 17:22:06 +00:00
|
|
|
OBJ_color0,
|
|
|
|
OBJ_color1,
|
|
|
|
OBJ_color2,
|
|
|
|
OBJ_color3,
|
|
|
|
OBJ_color4,
|
|
|
|
OBJ_color5,
|
|
|
|
OBJ_color6,
|
|
|
|
OBJ_color7,
|
|
|
|
OBJ_color8,
|
|
|
|
OBJ_color9,
|
2008-03-18 00:23:16 +00:00
|
|
|
OBJ_conky_version,
|
|
|
|
OBJ_conky_build_date,
|
|
|
|
OBJ_conky_build_arch,
|
2005-08-02 05:06:53 +00:00
|
|
|
OBJ_font,
|
2005-07-20 00:30:40 +00:00
|
|
|
OBJ_cpu,
|
|
|
|
OBJ_cpubar,
|
2005-07-28 06:56:55 +00:00
|
|
|
OBJ_cpugraph,
|
2008-04-13 04:10:35 +00:00
|
|
|
OBJ_loadgraph,
|
2005-08-26 02:16:35 +00:00
|
|
|
OBJ_diskio,
|
2006-12-29 23:14:31 +00:00
|
|
|
OBJ_diskio_read,
|
|
|
|
OBJ_diskio_write,
|
2005-08-26 02:16:35 +00:00
|
|
|
OBJ_diskiograph,
|
2006-12-29 23:14:31 +00:00
|
|
|
OBJ_diskiograph_read,
|
|
|
|
OBJ_diskiograph_write,
|
2005-07-20 00:30:40 +00:00
|
|
|
OBJ_downspeed,
|
|
|
|
OBJ_downspeedf,
|
2005-07-28 06:56:55 +00:00
|
|
|
OBJ_downspeedgraph,
|
2005-07-20 00:30:40 +00:00
|
|
|
OBJ_else,
|
|
|
|
OBJ_endif,
|
2006-05-25 07:00:12 +00:00
|
|
|
OBJ_image,
|
2005-07-20 00:30:40 +00:00
|
|
|
OBJ_exec,
|
|
|
|
OBJ_execi,
|
2005-08-29 17:06:31 +00:00
|
|
|
OBJ_texeci,
|
2005-07-20 00:30:40 +00:00
|
|
|
OBJ_execbar,
|
2005-07-28 06:56:55 +00:00
|
|
|
OBJ_execgraph,
|
2005-08-23 03:00:50 +00:00
|
|
|
OBJ_execibar,
|
|
|
|
OBJ_execigraph,
|
2008-03-22 06:10:54 +00:00
|
|
|
OBJ_execp,
|
|
|
|
OBJ_execpi,
|
2005-07-20 00:30:40 +00:00
|
|
|
OBJ_freq,
|
2005-08-11 16:20:35 +00:00
|
|
|
OBJ_freq_g,
|
2005-08-26 02:16:35 +00:00
|
|
|
OBJ_freq_dyn,
|
|
|
|
OBJ_freq_dyn_g,
|
2005-07-20 00:30:40 +00:00
|
|
|
OBJ_fs_bar,
|
|
|
|
OBJ_fs_bar_free,
|
|
|
|
OBJ_fs_free,
|
|
|
|
OBJ_fs_free_perc,
|
2005-08-11 18:13:57 +00:00
|
|
|
OBJ_fs_size,
|
2008-03-18 00:23:16 +00:00
|
|
|
OBJ_fs_type,
|
2005-07-20 00:30:40 +00:00
|
|
|
OBJ_fs_used,
|
|
|
|
OBJ_fs_used_perc,
|
2006-08-10 16:56:13 +00:00
|
|
|
OBJ_goto,
|
|
|
|
OBJ_tab,
|
2005-07-20 00:30:40 +00:00
|
|
|
OBJ_hr,
|
2005-07-31 19:49:39 +00:00
|
|
|
OBJ_offset,
|
2005-08-21 05:04:22 +00:00
|
|
|
OBJ_voffset,
|
2005-07-20 00:30:40 +00:00
|
|
|
OBJ_alignr,
|
|
|
|
OBJ_alignc,
|
|
|
|
OBJ_i2c,
|
2007-08-27 20:26:58 +00:00
|
|
|
OBJ_platform,
|
|
|
|
OBJ_hwmon,
|
2005-08-27 12:59:46 +00:00
|
|
|
#if defined(__linux__)
|
2008-03-24 20:08:16 +00:00
|
|
|
OBJ_disk_protect,
|
2005-08-27 07:15:44 +00:00
|
|
|
OBJ_i8k_version,
|
|
|
|
OBJ_i8k_bios,
|
|
|
|
OBJ_i8k_serial,
|
|
|
|
OBJ_i8k_cpu_temp,
|
|
|
|
OBJ_i8k_cpu_tempf,
|
|
|
|
OBJ_i8k_left_fan_status,
|
|
|
|
OBJ_i8k_right_fan_status,
|
|
|
|
OBJ_i8k_left_fan_rpm,
|
|
|
|
OBJ_i8k_right_fan_rpm,
|
2008-02-20 20:30:45 +00:00
|
|
|
OBJ_i8k_ac_status,
|
2005-08-27 07:15:44 +00:00
|
|
|
OBJ_i8k_buttons_status,
|
2006-04-15 18:00:39 +00:00
|
|
|
OBJ_ibm_fan,
|
|
|
|
OBJ_ibm_temps,
|
|
|
|
OBJ_ibm_volume,
|
|
|
|
OBJ_ibm_brightness,
|
2008-03-18 00:23:16 +00:00
|
|
|
OBJ_if_up,
|
2008-03-22 19:06:09 +00:00
|
|
|
OBJ_if_gw,
|
2008-03-22 21:10:43 +00:00
|
|
|
OBJ_ioscheduler,
|
2008-03-22 19:06:09 +00:00
|
|
|
OBJ_gw_iface,
|
|
|
|
OBJ_gw_ip,
|
2008-03-22 20:13:51 +00:00
|
|
|
OBJ_laptop_mode,
|
2008-02-20 20:30:45 +00:00
|
|
|
OBJ_pb_battery,
|
2006-05-24 00:23:47 +00:00
|
|
|
OBJ_voltage_mv,
|
|
|
|
OBJ_voltage_v,
|
2007-08-07 12:51:08 +00:00
|
|
|
OBJ_wireless_essid,
|
|
|
|
OBJ_wireless_mode,
|
|
|
|
OBJ_wireless_bitrate,
|
2007-08-07 22:05:06 +00:00
|
|
|
OBJ_wireless_ap,
|
2007-08-07 12:51:08 +00:00
|
|
|
OBJ_wireless_link_qual,
|
|
|
|
OBJ_wireless_link_qual_max,
|
2007-08-07 22:05:06 +00:00
|
|
|
OBJ_wireless_link_qual_perc,
|
2007-08-07 12:51:08 +00:00
|
|
|
OBJ_wireless_link_bar,
|
2005-08-27 12:59:46 +00:00
|
|
|
#endif /* __linux__ */
|
2007-04-06 05:01:48 +00:00
|
|
|
OBJ_if_empty,
|
2005-07-20 00:30:40 +00:00
|
|
|
OBJ_if_existing,
|
|
|
|
OBJ_if_mounted,
|
|
|
|
OBJ_if_running,
|
|
|
|
OBJ_top,
|
2005-07-25 00:22:16 +00:00
|
|
|
OBJ_top_mem,
|
2005-07-20 00:30:40 +00:00
|
|
|
OBJ_tail,
|
2005-08-26 05:52:43 +00:00
|
|
|
OBJ_head,
|
2005-07-20 00:30:40 +00:00
|
|
|
OBJ_kernel,
|
|
|
|
OBJ_loadavg,
|
|
|
|
OBJ_machine,
|
|
|
|
OBJ_mails,
|
2007-02-12 01:03:10 +00:00
|
|
|
OBJ_mboxscan,
|
2005-07-20 00:30:40 +00:00
|
|
|
OBJ_mem,
|
|
|
|
OBJ_membar,
|
2005-07-28 06:56:55 +00:00
|
|
|
OBJ_memgraph,
|
2005-07-20 00:30:40 +00:00
|
|
|
OBJ_memmax,
|
|
|
|
OBJ_memperc,
|
2008-03-30 07:04:25 +00:00
|
|
|
OBJ_mem_res,
|
|
|
|
OBJ_mem_vsize,
|
2005-07-20 00:30:40 +00:00
|
|
|
OBJ_mixer,
|
|
|
|
OBJ_mixerl,
|
|
|
|
OBJ_mixerr,
|
|
|
|
OBJ_mixerbar,
|
|
|
|
OBJ_mixerlbar,
|
|
|
|
OBJ_mixerrbar,
|
2008-03-22 22:58:26 +00:00
|
|
|
OBJ_nameserver,
|
2005-07-20 00:30:40 +00:00
|
|
|
OBJ_new_mails,
|
|
|
|
OBJ_nodename,
|
2008-06-03 20:46:15 +00:00
|
|
|
OBJ_nvidia,
|
2005-07-20 00:30:40 +00:00
|
|
|
OBJ_pre_exec,
|
|
|
|
OBJ_processes,
|
|
|
|
OBJ_running_processes,
|
|
|
|
OBJ_shadecolor,
|
|
|
|
OBJ_outlinecolor,
|
|
|
|
OBJ_stippled_hr,
|
|
|
|
OBJ_swap,
|
|
|
|
OBJ_swapbar,
|
|
|
|
OBJ_swapmax,
|
|
|
|
OBJ_swapperc,
|
|
|
|
OBJ_sysname,
|
2008-02-20 20:30:45 +00:00
|
|
|
OBJ_temp1, /* i2c is used instead in these */
|
2005-07-20 00:30:40 +00:00
|
|
|
OBJ_temp2,
|
|
|
|
OBJ_text,
|
|
|
|
OBJ_time,
|
|
|
|
OBJ_utime,
|
2006-07-15 02:18:06 +00:00
|
|
|
OBJ_tztime,
|
2005-07-20 00:30:40 +00:00
|
|
|
OBJ_totaldown,
|
|
|
|
OBJ_totalup,
|
|
|
|
OBJ_updates,
|
|
|
|
OBJ_upspeed,
|
|
|
|
OBJ_upspeedf,
|
2005-07-28 06:56:55 +00:00
|
|
|
OBJ_upspeedgraph,
|
2005-07-20 00:30:40 +00:00
|
|
|
OBJ_uptime,
|
|
|
|
OBJ_uptime_short,
|
2008-03-18 00:23:16 +00:00
|
|
|
OBJ_user_names,
|
|
|
|
OBJ_user_terms,
|
|
|
|
OBJ_user_times,
|
|
|
|
OBJ_user_number,
|
2006-05-08 22:34:38 +00:00
|
|
|
OBJ_imap,
|
|
|
|
OBJ_imap_messages,
|
|
|
|
OBJ_imap_unseen,
|
|
|
|
OBJ_pop3,
|
|
|
|
OBJ_pop3_unseen,
|
|
|
|
OBJ_pop3_used,
|
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,
|
|
|
|
OBJ_apm_battery_time,
|
|
|
|
OBJ_apm_battery_life,
|
2007-05-06 09:32:21 +00:00
|
|
|
#endif /* __FreeBSD__ __OpenBSD__ */
|
2007-03-01 01:43:43 +00:00
|
|
|
#ifdef __OpenBSD__
|
|
|
|
OBJ_obsd_sensors_temp,
|
|
|
|
OBJ_obsd_sensors_fan,
|
|
|
|
OBJ_obsd_sensors_volt,
|
|
|
|
OBJ_obsd_vendor,
|
|
|
|
OBJ_obsd_product,
|
|
|
|
#endif /* __OpenBSD__ */
|
2005-07-20 00:30:40 +00:00
|
|
|
#ifdef MPD
|
|
|
|
OBJ_mpd_title,
|
|
|
|
OBJ_mpd_artist,
|
|
|
|
OBJ_mpd_album,
|
2005-10-11 01:37:46 +00:00
|
|
|
OBJ_mpd_random,
|
|
|
|
OBJ_mpd_repeat,
|
2005-07-20 00:30:40 +00:00
|
|
|
OBJ_mpd_vol,
|
|
|
|
OBJ_mpd_bitrate,
|
|
|
|
OBJ_mpd_status,
|
|
|
|
OBJ_mpd_host,
|
|
|
|
OBJ_mpd_port,
|
2006-01-31 03:32:26 +00:00
|
|
|
OBJ_mpd_password,
|
2005-07-20 00:30:40 +00:00
|
|
|
OBJ_mpd_bar,
|
2005-07-28 04:48:27 +00:00
|
|
|
OBJ_mpd_elapsed,
|
|
|
|
OBJ_mpd_length,
|
2005-10-11 01:37:46 +00:00
|
|
|
OBJ_mpd_track,
|
2006-01-31 03:32:26 +00:00
|
|
|
OBJ_mpd_name,
|
|
|
|
OBJ_mpd_file,
|
2005-07-28 04:48:27 +00:00
|
|
|
OBJ_mpd_percent,
|
2006-03-07 04:23:55 +00:00
|
|
|
OBJ_mpd_smart,
|
2005-07-20 00:30:40 +00:00
|
|
|
#endif
|
2008-02-20 20:30:45 +00:00
|
|
|
OBJ_music_player_interval,
|
2006-03-25 21:21:07 +00:00
|
|
|
#ifdef XMMS2
|
2008-02-20 20:30:45 +00:00
|
|
|
OBJ_xmms2_artist,
|
|
|
|
OBJ_xmms2_album,
|
|
|
|
OBJ_xmms2_title,
|
|
|
|
OBJ_xmms2_genre,
|
|
|
|
OBJ_xmms2_comment,
|
|
|
|
OBJ_xmms2_url,
|
|
|
|
OBJ_xmms2_date,
|
|
|
|
OBJ_xmms2_tracknr,
|
|
|
|
OBJ_xmms2_bitrate,
|
|
|
|
OBJ_xmms2_id,
|
|
|
|
OBJ_xmms2_duration,
|
|
|
|
OBJ_xmms2_elapsed,
|
|
|
|
OBJ_xmms2_size,
|
2006-04-16 03:49:49 +00:00
|
|
|
OBJ_xmms2_percent,
|
2006-03-25 21:21:07 +00:00
|
|
|
OBJ_xmms2_status,
|
|
|
|
OBJ_xmms2_bar,
|
2006-04-16 03:49:49 +00:00
|
|
|
OBJ_xmms2_smart,
|
2008-03-18 00:23:16 +00:00
|
|
|
OBJ_xmms2_playlist,
|
|
|
|
OBJ_xmms2_timesplayed,
|
2006-03-25 21:21:07 +00:00
|
|
|
#endif
|
2006-11-03 20:54:52 +00:00
|
|
|
#ifdef AUDACIOUS
|
|
|
|
OBJ_audacious_status,
|
|
|
|
OBJ_audacious_title,
|
|
|
|
OBJ_audacious_length,
|
|
|
|
OBJ_audacious_length_seconds,
|
|
|
|
OBJ_audacious_position,
|
|
|
|
OBJ_audacious_position_seconds,
|
|
|
|
OBJ_audacious_bitrate,
|
|
|
|
OBJ_audacious_frequency,
|
|
|
|
OBJ_audacious_channels,
|
|
|
|
OBJ_audacious_filename,
|
|
|
|
OBJ_audacious_playlist_length,
|
|
|
|
OBJ_audacious_playlist_position,
|
|
|
|
OBJ_audacious_bar,
|
|
|
|
#endif
|
2005-12-30 09:44:40 +00:00
|
|
|
#ifdef BMPX
|
|
|
|
OBJ_bmpx_title,
|
|
|
|
OBJ_bmpx_artist,
|
|
|
|
OBJ_bmpx_album,
|
|
|
|
OBJ_bmpx_track,
|
|
|
|
OBJ_bmpx_uri,
|
|
|
|
OBJ_bmpx_bitrate,
|
|
|
|
#endif
|
2007-05-06 12:17:13 +00:00
|
|
|
#ifdef RSS
|
|
|
|
OBJ_rss,
|
|
|
|
#endif
|
2005-10-31 05:17:06 +00:00
|
|
|
#ifdef TCP_PORT_MONITOR
|
|
|
|
OBJ_tcp_portmon,
|
|
|
|
#endif
|
2006-05-13 20:14:26 +00:00
|
|
|
#ifdef HAVE_ICONV
|
2006-05-13 19:51:26 +00:00
|
|
|
OBJ_iconv_start,
|
|
|
|
OBJ_iconv_stop,
|
|
|
|
#endif
|
2006-08-10 16:56:13 +00:00
|
|
|
#ifdef HDDTEMP
|
|
|
|
OBJ_hddtemp,
|
2008-03-18 00:23:16 +00:00
|
|
|
#endif
|
|
|
|
#ifdef SMAPI
|
|
|
|
OBJ_smapi,
|
|
|
|
OBJ_smapi_bat_bar,
|
|
|
|
OBJ_smapi_bat_perc,
|
|
|
|
OBJ_if_smapi_bat_installed,
|
2006-08-10 16:56:13 +00:00
|
|
|
#endif
|
2006-11-30 20:46:34 +00:00
|
|
|
OBJ_entropy_avail,
|
|
|
|
OBJ_entropy_poolsize,
|
|
|
|
OBJ_entropy_bar
|
2005-07-20 00:30:40 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct text_object {
|
|
|
|
union {
|
2008-02-20 20:30:45 +00:00
|
|
|
char *s; /* some string */
|
|
|
|
int i; /* some integer */
|
|
|
|
long l; /* some other integer */
|
2006-05-08 22:34:38 +00:00
|
|
|
unsigned int sensor;
|
2008-02-20 20:30:45 +00:00
|
|
|
struct net_stat *net;
|
2005-07-20 00:30:40 +00:00
|
|
|
struct fs_stat *fs;
|
2008-02-09 02:21:06 +00:00
|
|
|
struct diskio_stat *diskio;
|
2005-07-20 00:30:40 +00:00
|
|
|
unsigned char loadavg[3];
|
2005-08-27 09:34:00 +00:00
|
|
|
unsigned int cpu_index;
|
2006-05-08 22:34:38 +00:00
|
|
|
struct mail_s *mail;
|
2006-07-15 02:18:06 +00:00
|
|
|
|
2007-02-12 01:03:10 +00:00
|
|
|
struct {
|
|
|
|
char *args;
|
|
|
|
char *output;
|
|
|
|
} mboxscan;
|
|
|
|
|
2006-07-15 02:18:06 +00:00
|
|
|
struct {
|
2008-02-20 20:30:45 +00:00
|
|
|
char *tz; /* timezone variable */
|
|
|
|
char *fmt; /* time display formatting */
|
2006-07-15 02:18:06 +00:00
|
|
|
} tztime;
|
|
|
|
|
2005-07-20 00:30:40 +00:00
|
|
|
struct {
|
|
|
|
struct fs_stat *fs;
|
|
|
|
int w, h;
|
2008-02-20 20:30:45 +00:00
|
|
|
} fsbar; /* 3 */
|
2005-07-20 00:30:40 +00:00
|
|
|
|
|
|
|
struct {
|
|
|
|
int l;
|
|
|
|
int w, h;
|
2008-02-20 20:30:45 +00:00
|
|
|
} mixerbar; /* 3 */
|
2005-07-20 00:30:40 +00:00
|
|
|
|
|
|
|
struct {
|
|
|
|
int fd;
|
|
|
|
int arg;
|
|
|
|
char devtype[256];
|
|
|
|
char type[64];
|
2007-08-13 23:14:01 +00:00
|
|
|
} sysfs; /* 2 */
|
2007-04-06 06:11:53 +00:00
|
|
|
|
2005-07-20 00:30:40 +00:00
|
|
|
struct {
|
2005-07-28 04:48:27 +00:00
|
|
|
int pos;
|
|
|
|
char *s;
|
2007-04-06 06:11:53 +00:00
|
|
|
char *str;
|
2005-07-20 00:30:40 +00:00
|
|
|
} ifblock;
|
2007-04-06 06:11:53 +00:00
|
|
|
|
2005-07-20 00:30:40 +00:00
|
|
|
struct {
|
|
|
|
int num;
|
|
|
|
int type;
|
|
|
|
} top;
|
|
|
|
|
2005-07-28 04:48:27 +00:00
|
|
|
struct {
|
2005-07-20 00:30:40 +00:00
|
|
|
int wantedlines;
|
|
|
|
int readlines;
|
|
|
|
char *logfile;
|
|
|
|
double last_update;
|
|
|
|
float interval;
|
2005-08-10 05:52:52 +00:00
|
|
|
char *buffer;
|
2007-09-28 20:16:16 +00:00
|
|
|
/* If not -1, a file descriptor to read from when
|
|
|
|
* logfile is a FIFO. */
|
|
|
|
int fd;
|
2005-07-28 04:48:27 +00:00
|
|
|
} tail;
|
2005-07-20 00:30:40 +00:00
|
|
|
|
|
|
|
struct {
|
|
|
|
double last_update;
|
|
|
|
float interval;
|
|
|
|
char *cmd;
|
|
|
|
char *buffer;
|
2005-08-23 03:00:50 +00:00
|
|
|
double data;
|
2008-02-20 20:30:45 +00:00
|
|
|
} execi; /* 5 */
|
2005-07-20 00:30:40 +00:00
|
|
|
|
2006-11-15 01:20:49 +00:00
|
|
|
struct {
|
|
|
|
float interval;
|
|
|
|
char *cmd;
|
|
|
|
char *buffer;
|
|
|
|
double data;
|
|
|
|
timed_thread *p_timed_thread;
|
|
|
|
} texeci;
|
|
|
|
|
2005-07-20 00:30:40 +00:00
|
|
|
struct {
|
|
|
|
int a, b;
|
2008-02-20 20:30:45 +00:00
|
|
|
} pair; /* 2 */
|
2005-10-31 05:17:06 +00:00
|
|
|
#ifdef TCP_PORT_MONITOR
|
|
|
|
struct {
|
2008-02-20 20:30:45 +00:00
|
|
|
/* starting port to monitor */
|
|
|
|
in_port_t port_range_begin;
|
|
|
|
/* ending port to monitor */
|
|
|
|
in_port_t port_range_end;
|
|
|
|
/* enum from libtcp-portmon.h, e.g. COUNT, etc. */
|
|
|
|
int item;
|
|
|
|
/* 0 to n-1 connections. */
|
|
|
|
int connection_index;
|
2006-01-28 01:28:23 +00:00
|
|
|
} tcp_port_monitor;
|
2005-10-31 05:17:06 +00:00
|
|
|
#endif
|
2006-11-04 17:55:00 +00:00
|
|
|
#ifdef HDDTEMP
|
2006-08-10 16:56:13 +00:00
|
|
|
struct {
|
|
|
|
char *addr;
|
|
|
|
int port;
|
|
|
|
char *dev;
|
2008-04-13 04:10:35 +00:00
|
|
|
double update_time;
|
|
|
|
char *temp;
|
|
|
|
char unit;
|
2008-02-20 20:30:45 +00:00
|
|
|
} hddtemp; /* 2 */
|
2007-05-06 12:17:13 +00:00
|
|
|
#endif
|
|
|
|
#ifdef RSS
|
|
|
|
struct {
|
|
|
|
char *uri;
|
2007-06-02 08:17:33 +00:00
|
|
|
char *action;
|
|
|
|
int act_par;
|
2007-06-01 10:42:57 +00:00
|
|
|
int delay;
|
2007-05-06 12:17:13 +00:00
|
|
|
} rss;
|
2006-11-04 17:55:00 +00:00
|
|
|
#endif
|
2007-10-02 23:57:41 +00:00
|
|
|
struct local_mail_s local_mail;
|
2008-06-03 20:46:15 +00:00
|
|
|
#ifdef NVIDIA
|
|
|
|
struct nvidia_s nvidia;
|
|
|
|
#endif /* NVIDIA */
|
|
|
|
|
2005-07-20 00:30:40 +00:00
|
|
|
} data;
|
2007-10-17 20:31:27 +00:00
|
|
|
int type;
|
|
|
|
int a, b;
|
|
|
|
long line;
|
|
|
|
unsigned int c, d, e;
|
|
|
|
float f;
|
|
|
|
char global_mode;
|
2005-07-20 00:30:40 +00:00
|
|
|
};
|
|
|
|
|
2005-12-10 14:15:38 +00:00
|
|
|
struct text_object_list {
|
2006-01-28 01:28:23 +00:00
|
|
|
unsigned int text_object_count;
|
|
|
|
struct text_object *text_objects;
|
2005-12-10 14:15:38 +00:00
|
|
|
};
|
|
|
|
|
2008-03-29 05:23:45 +00:00
|
|
|
static unsigned int global_text_object_count;
|
|
|
|
static struct text_object *global_text_objects;
|
2008-02-20 20:30:45 +00:00
|
|
|
static void generate_text_internal(char *p, int p_max_size,
|
|
|
|
struct text_object *objs, unsigned int object_count,
|
|
|
|
struct information *cur);
|
2005-07-20 00:30:40 +00:00
|
|
|
|
2006-05-08 22:34:38 +00:00
|
|
|
#define MAXDATASIZE 1000
|
2006-05-14 06:42:35 +00:00
|
|
|
#define POP3 1
|
|
|
|
#define IMAP 2
|
2006-05-09 22:39:39 +00:00
|
|
|
|
2008-02-20 20:30:45 +00:00
|
|
|
struct mail_s *parse_mail_args(char type, const char *arg)
|
|
|
|
{
|
2006-05-09 22:39:39 +00:00
|
|
|
struct mail_s *mail;
|
2008-03-29 06:24:04 +00:00
|
|
|
char *tmp;
|
|
|
|
|
2006-05-09 22:39:39 +00:00
|
|
|
mail = malloc(sizeof(struct mail_s));
|
2006-05-12 18:06:12 +00:00
|
|
|
memset(mail, 0, sizeof(struct mail_s));
|
2008-02-20 20:30:45 +00:00
|
|
|
|
|
|
|
if (sscanf(arg, "%128s %128s %128s", mail->host, mail->user, mail->pass)
|
|
|
|
!= 3) {
|
2006-05-09 22:39:39 +00:00
|
|
|
if (type == POP3) {
|
|
|
|
ERR("Scanning IMAP args failed");
|
2008-02-20 20:30:45 +00:00
|
|
|
} else if (type == IMAP) {
|
2006-05-09 22:39:39 +00:00
|
|
|
ERR("Scanning POP3 args failed");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// see if password needs prompting
|
|
|
|
if (mail->pass[0] == '*' && mail->pass[1] == '\0') {
|
|
|
|
int fp = fileno(stdin);
|
|
|
|
struct termios term;
|
2008-02-20 20:30:45 +00:00
|
|
|
|
2006-05-09 22:39:39 +00:00
|
|
|
tcgetattr(fp, &term);
|
|
|
|
term.c_lflag &= ~ECHO;
|
|
|
|
tcsetattr(fp, TCSANOW, &term);
|
|
|
|
printf("Enter mailbox password (%s@%s): ", mail->user, mail->host);
|
|
|
|
scanf("%128s", mail->pass);
|
|
|
|
printf("\n");
|
|
|
|
term.c_lflag |= ECHO;
|
|
|
|
tcsetattr(fp, TCSANOW, &term);
|
|
|
|
}
|
|
|
|
// now we check for optional args
|
|
|
|
tmp = strstr(arg, "-i ");
|
|
|
|
if (tmp) {
|
|
|
|
tmp += 3;
|
|
|
|
sscanf(tmp, "%f", &mail->interval);
|
|
|
|
} else {
|
|
|
|
mail->interval = 300; // 5 minutes
|
|
|
|
}
|
|
|
|
tmp = strstr(arg, "-p ");
|
|
|
|
if (tmp) {
|
|
|
|
tmp += 3;
|
2006-05-13 19:51:26 +00:00
|
|
|
sscanf(tmp, "%lu", &mail->port);
|
2006-05-09 22:39:39 +00:00
|
|
|
} else {
|
|
|
|
if (type == POP3) {
|
2006-05-14 06:15:23 +00:00
|
|
|
mail->port = 110; // default pop3 port
|
2006-05-09 22:39:39 +00:00
|
|
|
} else if (type == IMAP) {
|
|
|
|
mail->port = 143; // default imap port
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (type == IMAP) {
|
|
|
|
tmp = strstr(arg, "-f ");
|
|
|
|
if (tmp) {
|
|
|
|
tmp += 3;
|
|
|
|
sscanf(tmp, "%s", mail->folder);
|
|
|
|
} else {
|
|
|
|
strncpy(mail->folder, "INBOX", 128); // default imap inbox
|
|
|
|
}
|
|
|
|
}
|
|
|
|
tmp = strstr(arg, "-e ");
|
|
|
|
if (tmp) {
|
|
|
|
int len = 1024;
|
2008-03-29 06:24:04 +00:00
|
|
|
tmp += 3;
|
2008-02-20 20:30:45 +00:00
|
|
|
|
2006-05-09 22:39:39 +00:00
|
|
|
if (tmp[0] == '\'') {
|
2008-02-20 20:30:45 +00:00
|
|
|
len = strstr(tmp + 1, "'") - tmp - 1;
|
2006-05-09 22:39:39 +00:00
|
|
|
if (len > 1024) {
|
|
|
|
len = 1024;
|
|
|
|
}
|
|
|
|
}
|
2008-02-20 20:30:45 +00:00
|
|
|
strncpy(mail->command, tmp + 1, len);
|
2006-05-09 22:39:39 +00:00
|
|
|
} else {
|
|
|
|
mail->command[0] = '\0';
|
|
|
|
}
|
2006-11-15 01:20:49 +00:00
|
|
|
mail->p_timed_thread = NULL;
|
2006-05-09 22:39:39 +00:00
|
|
|
return mail;
|
|
|
|
}
|
2006-05-08 22:34:38 +00:00
|
|
|
|
2008-03-29 05:14:35 +00:00
|
|
|
void *imap_thread(void *arg)
|
2006-11-15 01:20:49 +00:00
|
|
|
{
|
2006-05-08 22:34:38 +00:00
|
|
|
int sockfd, numbytes;
|
|
|
|
char recvbuf[MAXDATASIZE];
|
|
|
|
char sendbuf[MAXDATASIZE];
|
|
|
|
char *reply;
|
|
|
|
int fail = 0;
|
|
|
|
unsigned int old_unseen = UINT_MAX;
|
2006-05-14 07:13:55 +00:00
|
|
|
unsigned int old_messages = UINT_MAX;
|
2006-12-11 19:04:58 +00:00
|
|
|
struct stat stat_buf;
|
2008-04-10 22:45:45 +00:00
|
|
|
struct hostent he, *he_res = 0;
|
|
|
|
int he_errno;
|
|
|
|
char hostbuff[2048];
|
2006-05-08 22:34:38 +00:00
|
|
|
struct sockaddr_in their_addr; // connector's address information
|
2008-03-29 05:14:35 +00:00
|
|
|
struct mail_s *mail = (struct mail_s *)arg;
|
2008-02-20 20:30:45 +00:00
|
|
|
|
2008-04-10 22:45:45 +00:00
|
|
|
#ifdef HAVE_GETHOSTBYNAME_R
|
|
|
|
if (gethostbyname_r(mail->host, &he, hostbuff, sizeof(hostbuff), &he_res, &he_errno)) { // get the host info
|
|
|
|
ERR("IMAP gethostbyname_r: %s", hstrerror(h_errno));
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
#else /* HAVE_GETHOSTBYNAME_R */
|
|
|
|
if ((he_res = gethostbyname(mail->host)) == NULL) { // get the host info
|
2006-05-08 22:34:38 +00:00
|
|
|
herror("gethostbyname");
|
|
|
|
exit(1);
|
|
|
|
}
|
2008-04-10 22:45:45 +00:00
|
|
|
#endif /* HAVE_GETHOSTBYNAME_R */
|
2006-11-15 01:20:49 +00:00
|
|
|
while (fail < 5) {
|
2008-03-29 06:24:04 +00:00
|
|
|
struct timeval timeout;
|
|
|
|
int res;
|
|
|
|
fd_set fdset;
|
|
|
|
|
2006-05-14 05:43:16 +00:00
|
|
|
if (fail > 0) {
|
2008-02-20 20:30:45 +00:00
|
|
|
ERR("Trying IMAP connection again for %s@%s (try %i/5)",
|
2008-04-10 22:45:45 +00:00
|
|
|
mail->user, mail->host, fail + 1);
|
|
|
|
}
|
|
|
|
do {
|
|
|
|
if ((sockfd = socket(PF_INET, SOCK_STREAM, 0)) == -1) {
|
|
|
|
perror("socket");
|
2006-05-08 22:34:38 +00:00
|
|
|
fail++;
|
2008-04-10 22:45:45 +00:00
|
|
|
break;
|
2006-05-08 22:34:38 +00:00
|
|
|
}
|
2008-04-10 22:45:45 +00:00
|
|
|
|
|
|
|
// host byte order
|
|
|
|
their_addr.sin_family = AF_INET;
|
|
|
|
// short, network byte order
|
|
|
|
their_addr.sin_port = htons(mail->port);
|
|
|
|
their_addr.sin_addr = *((struct in_addr *) he_res->h_addr);
|
|
|
|
// zero the rest of the struct
|
|
|
|
memset(&(their_addr.sin_zero), '\0', 8);
|
|
|
|
|
|
|
|
if (connect(sockfd, (struct sockaddr *) &their_addr,
|
|
|
|
sizeof(struct sockaddr)) == -1) {
|
|
|
|
perror("connect");
|
2006-05-08 22:34:38 +00:00
|
|
|
fail++;
|
2008-04-10 22:45:45 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
timeout.tv_sec = 60; // 60 second timeout i guess
|
|
|
|
timeout.tv_usec = 0;
|
|
|
|
FD_ZERO(&fdset);
|
|
|
|
FD_SET(sockfd, &fdset);
|
|
|
|
res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
|
|
|
|
if (res > 0) {
|
|
|
|
if ((numbytes = recv(sockfd, recvbuf, MAXDATASIZE - 1, 0)) == -1) {
|
|
|
|
perror("recv");
|
|
|
|
fail++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
ERR("IMAP connection failed: timeout");
|
2006-05-08 22:34:38 +00:00
|
|
|
fail++;
|
2008-04-10 22:45:45 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
recvbuf[numbytes] = '\0';
|
|
|
|
if (strstr(recvbuf, "* OK") != recvbuf) {
|
|
|
|
ERR("IMAP connection failed, probably not an IMAP server");
|
2006-05-08 22:34:38 +00:00
|
|
|
fail++;
|
2008-04-10 22:45:45 +00:00
|
|
|
break;
|
2006-05-08 22:34:38 +00:00
|
|
|
}
|
2008-04-10 22:45:45 +00:00
|
|
|
strncpy(sendbuf, "a1 login ", MAXDATASIZE);
|
|
|
|
strncat(sendbuf, mail->user, MAXDATASIZE - strlen(sendbuf) - 1);
|
|
|
|
strncat(sendbuf, " ", MAXDATASIZE - strlen(sendbuf) - 1);
|
|
|
|
strncat(sendbuf, mail->pass, MAXDATASIZE - strlen(sendbuf) - 1);
|
|
|
|
strncat(sendbuf, "\r\n", MAXDATASIZE - strlen(sendbuf) - 1);
|
|
|
|
if (send(sockfd, sendbuf, strlen(sendbuf), 0) == -1) {
|
|
|
|
perror("send a1");
|
|
|
|
fail++;
|
|
|
|
break;
|
2006-05-08 22:34:38 +00:00
|
|
|
}
|
2008-04-10 22:45:45 +00:00
|
|
|
timeout.tv_sec = 60; // 60 second timeout i guess
|
|
|
|
timeout.tv_usec = 0;
|
|
|
|
FD_ZERO(&fdset);
|
|
|
|
FD_SET(sockfd, &fdset);
|
|
|
|
res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
|
|
|
|
if (res > 0) {
|
|
|
|
if ((numbytes = recv(sockfd, recvbuf, MAXDATASIZE - 1, 0)) == -1) {
|
|
|
|
perror("recv a1");
|
|
|
|
fail++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
recvbuf[numbytes] = '\0';
|
|
|
|
if (strstr(recvbuf, "a1 OK") == NULL) {
|
|
|
|
ERR("IMAP server login failed: %s", recvbuf);
|
|
|
|
fail++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
strncpy(sendbuf, "a2 STATUS ", MAXDATASIZE);
|
|
|
|
strncat(sendbuf, mail->folder, MAXDATASIZE - strlen(sendbuf) - 1);
|
|
|
|
strncat(sendbuf, " (MESSAGES UNSEEN)\r\n",
|
|
|
|
MAXDATASIZE - strlen(sendbuf) - 1);
|
|
|
|
if (send(sockfd, sendbuf, strlen(sendbuf), 0) == -1) {
|
|
|
|
perror("send a2");
|
|
|
|
fail++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
timeout.tv_sec = 60; // 60 second timeout i guess
|
|
|
|
timeout.tv_usec = 0;
|
|
|
|
FD_ZERO(&fdset);
|
|
|
|
FD_SET(sockfd, &fdset);
|
|
|
|
res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
|
|
|
|
if (res > 0) {
|
|
|
|
if ((numbytes = recv(sockfd, recvbuf, MAXDATASIZE - 1, 0)) == -1) {
|
|
|
|
perror("recv a2");
|
|
|
|
fail++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
recvbuf[numbytes] = '\0';
|
|
|
|
if (strstr(recvbuf, "a2 OK") == NULL) {
|
|
|
|
ERR("IMAP status failed: %s", recvbuf);
|
|
|
|
fail++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
// now we get the data
|
|
|
|
reply = strstr(recvbuf, " (MESSAGES ");
|
|
|
|
reply += 2;
|
|
|
|
*strchr(reply, ')') = '\0';
|
|
|
|
if (reply == NULL) {
|
|
|
|
ERR("Error parsing IMAP response: %s", recvbuf);
|
|
|
|
fail++;
|
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
timed_thread_lock(mail->p_timed_thread);
|
|
|
|
sscanf(reply, "MESSAGES %lu UNSEEN %lu", &mail->messages,
|
|
|
|
&mail->unseen);
|
|
|
|
timed_thread_unlock(mail->p_timed_thread);
|
|
|
|
}
|
|
|
|
strncpy(sendbuf, "a3 logout\r\n", MAXDATASIZE);
|
|
|
|
if (send(sockfd, sendbuf, strlen(sendbuf), 0) == -1) {
|
|
|
|
perror("send a3");
|
|
|
|
fail++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
timeout.tv_sec = 60; // 60 second timeout i guess
|
|
|
|
timeout.tv_usec = 0;
|
|
|
|
FD_ZERO(&fdset);
|
|
|
|
FD_SET(sockfd, &fdset);
|
|
|
|
res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
|
|
|
|
if (res > 0) {
|
|
|
|
if ((numbytes = recv(sockfd, recvbuf, MAXDATASIZE - 1, 0)) == -1) {
|
|
|
|
perror("recv a3");
|
|
|
|
fail++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
recvbuf[numbytes] = '\0';
|
|
|
|
if (strstr(recvbuf, "a3 OK") == NULL) {
|
|
|
|
ERR("IMAP logout failed: %s", recvbuf);
|
|
|
|
fail++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (strlen(mail->command) > 1 && (mail->unseen > old_unseen
|
|
|
|
|| (mail->messages > old_messages && mail->unseen > 0))) {
|
|
|
|
// new mail goodie
|
|
|
|
if (system(mail->command) == -1) {
|
|
|
|
perror("system()");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fail = 0;
|
|
|
|
old_unseen = mail->unseen;
|
|
|
|
old_messages = mail->messages;
|
|
|
|
} while (0);
|
2008-02-20 20:30:45 +00:00
|
|
|
if ((fstat(sockfd, &stat_buf) == 0) && S_ISSOCK(stat_buf.st_mode)) {
|
|
|
|
/* if a valid socket, close it */
|
|
|
|
close(sockfd);
|
|
|
|
}
|
|
|
|
if (timed_thread_test(mail->p_timed_thread)) {
|
|
|
|
timed_thread_exit(mail->p_timed_thread);
|
|
|
|
}
|
2006-05-08 22:34:38 +00:00
|
|
|
}
|
2007-09-02 04:36:09 +00:00
|
|
|
mail->unseen = 0;
|
|
|
|
mail->messages = 0;
|
2006-05-08 22:34:38 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-03-29 05:14:35 +00:00
|
|
|
void *pop3_thread(void *arg)
|
2006-11-15 01:20:49 +00:00
|
|
|
{
|
2006-05-08 22:34:38 +00:00
|
|
|
int sockfd, numbytes;
|
|
|
|
char recvbuf[MAXDATASIZE];
|
|
|
|
char sendbuf[MAXDATASIZE];
|
|
|
|
char *reply;
|
|
|
|
int fail = 0;
|
|
|
|
unsigned int old_unseen = UINT_MAX;
|
2006-12-11 19:04:58 +00:00
|
|
|
struct stat stat_buf;
|
2008-04-10 22:45:45 +00:00
|
|
|
struct hostent he, *he_res = 0;
|
|
|
|
int he_errno;
|
|
|
|
char hostbuff[2048];
|
2006-05-08 22:34:38 +00:00
|
|
|
struct sockaddr_in their_addr; // connector's address information
|
2008-03-29 05:14:35 +00:00
|
|
|
struct mail_s *mail = (struct mail_s *)arg;
|
2008-02-20 20:30:45 +00:00
|
|
|
|
2008-04-10 22:45:45 +00:00
|
|
|
#ifdef HAVE_GETHOSTBYNAME_R
|
|
|
|
if (gethostbyname_r(mail->host, &he, hostbuff, sizeof(hostbuff), &he_res, &he_errno)) { // get the host info
|
|
|
|
ERR("POP3 gethostbyname_r: %s", hstrerror(h_errno));
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
#else /* HAVE_GETHOSTBYNAME_R */
|
|
|
|
if ((he_res = gethostbyname(mail->host)) == NULL) { // get the host info
|
2006-05-08 22:34:38 +00:00
|
|
|
herror("gethostbyname");
|
|
|
|
exit(1);
|
|
|
|
}
|
2008-04-10 22:45:45 +00:00
|
|
|
#endif /* HAVE_GETHOSTBYNAME_R */
|
2006-11-15 01:20:49 +00:00
|
|
|
while (fail < 5) {
|
2008-03-29 06:24:04 +00:00
|
|
|
struct timeval timeout;
|
|
|
|
int res;
|
|
|
|
fd_set fdset;
|
|
|
|
|
2006-05-14 05:43:16 +00:00
|
|
|
if (fail > 0) {
|
2008-02-20 20:30:45 +00:00
|
|
|
ERR("Trying POP3 connection again for %s@%s (try %i/5)",
|
2008-04-10 22:45:45 +00:00
|
|
|
mail->user, mail->host, fail + 1);
|
|
|
|
}
|
|
|
|
do {
|
|
|
|
if ((sockfd = socket(PF_INET, SOCK_STREAM, 0)) == -1) {
|
|
|
|
perror("socket");
|
2006-05-08 22:34:38 +00:00
|
|
|
fail++;
|
2008-04-10 22:45:45 +00:00
|
|
|
break;
|
2006-05-08 22:34:38 +00:00
|
|
|
}
|
2008-04-10 22:45:45 +00:00
|
|
|
|
|
|
|
// host byte order
|
|
|
|
their_addr.sin_family = AF_INET;
|
|
|
|
// short, network byte order
|
|
|
|
their_addr.sin_port = htons(mail->port);
|
|
|
|
their_addr.sin_addr = *((struct in_addr *) he_res->h_addr);
|
|
|
|
// zero the rest of the struct
|
|
|
|
memset(&(their_addr.sin_zero), '\0', 8);
|
|
|
|
|
|
|
|
if (connect(sockfd, (struct sockaddr *) &their_addr,
|
|
|
|
sizeof(struct sockaddr)) == -1) {
|
|
|
|
perror("connect");
|
2006-05-08 22:34:38 +00:00
|
|
|
fail++;
|
2008-04-10 22:45:45 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
timeout.tv_sec = 60; // 60 second timeout i guess
|
|
|
|
timeout.tv_usec = 0;
|
|
|
|
FD_ZERO(&fdset);
|
|
|
|
FD_SET(sockfd, &fdset);
|
|
|
|
res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
|
|
|
|
if (res > 0) {
|
|
|
|
if ((numbytes = recv(sockfd, recvbuf, MAXDATASIZE - 1, 0)) == -1) {
|
|
|
|
perror("recv");
|
|
|
|
fail++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
ERR("POP3 connection failed: timeout\n");
|
2006-05-08 22:34:38 +00:00
|
|
|
fail++;
|
2008-04-10 22:45:45 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
recvbuf[numbytes] = '\0';
|
|
|
|
if (strstr(recvbuf, "+OK ") != recvbuf) {
|
|
|
|
ERR("POP3 connection failed, probably not a POP3 server");
|
2006-05-08 22:34:38 +00:00
|
|
|
fail++;
|
2008-04-10 22:45:45 +00:00
|
|
|
break;
|
2006-05-08 22:34:38 +00:00
|
|
|
}
|
2008-04-10 22:45:45 +00:00
|
|
|
strncpy(sendbuf, "USER ", MAXDATASIZE);
|
|
|
|
strncat(sendbuf, mail->user, MAXDATASIZE - strlen(sendbuf) - 1);
|
|
|
|
strncat(sendbuf, "\r\n", MAXDATASIZE - strlen(sendbuf) - 1);
|
|
|
|
if (send(sockfd, sendbuf, strlen(sendbuf), 0) == -1) {
|
|
|
|
perror("send USER");
|
|
|
|
fail++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
timeout.tv_sec = 60; // 60 second timeout i guess
|
|
|
|
timeout.tv_usec = 0;
|
|
|
|
FD_ZERO(&fdset);
|
|
|
|
FD_SET(sockfd, &fdset);
|
|
|
|
res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
|
|
|
|
if (res > 0) {
|
|
|
|
if ((numbytes = recv(sockfd, recvbuf, MAXDATASIZE - 1, 0)) == -1) {
|
|
|
|
perror("recv USER");
|
|
|
|
fail++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
recvbuf[numbytes] = '\0';
|
|
|
|
if (strstr(recvbuf, "+OK ") == NULL) {
|
|
|
|
ERR("POP3 server login failed: %s", recvbuf);
|
2006-05-08 22:34:38 +00:00
|
|
|
fail++;
|
2008-04-10 22:45:45 +00:00
|
|
|
break;
|
2006-05-08 22:34:38 +00:00
|
|
|
}
|
2008-04-10 22:45:45 +00:00
|
|
|
strncpy(sendbuf, "PASS ", MAXDATASIZE);
|
|
|
|
strncat(sendbuf, mail->pass, MAXDATASIZE - strlen(sendbuf) - 1);
|
|
|
|
strncat(sendbuf, "\r\n", MAXDATASIZE - strlen(sendbuf) - 1);
|
|
|
|
if (send(sockfd, sendbuf, strlen(sendbuf), 0) == -1) {
|
|
|
|
perror("send PASS");
|
|
|
|
fail++;
|
|
|
|
break;
|
2006-05-08 22:34:38 +00:00
|
|
|
}
|
2008-04-10 22:45:45 +00:00
|
|
|
timeout.tv_sec = 60; // 60 second timeout i guess
|
|
|
|
timeout.tv_usec = 0;
|
|
|
|
FD_ZERO(&fdset);
|
|
|
|
FD_SET(sockfd, &fdset);
|
|
|
|
res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
|
|
|
|
if (res > 0) {
|
|
|
|
if ((numbytes = recv(sockfd, recvbuf, MAXDATASIZE - 1, 0)) == -1) {
|
|
|
|
perror("recv PASS");
|
|
|
|
fail++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
recvbuf[numbytes] = '\0';
|
|
|
|
if (strstr(recvbuf, "+OK ") == NULL) {
|
|
|
|
ERR("POP3 server login failed: %s", recvbuf);
|
|
|
|
fail++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
strncpy(sendbuf, "STAT\r\n", MAXDATASIZE);
|
|
|
|
if (send(sockfd, sendbuf, strlen(sendbuf), 0) == -1) {
|
|
|
|
perror("send STAT");
|
|
|
|
fail++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
timeout.tv_sec = 60; // 60 second timeout i guess
|
|
|
|
timeout.tv_usec = 0;
|
|
|
|
FD_ZERO(&fdset);
|
|
|
|
FD_SET(sockfd, &fdset);
|
|
|
|
res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
|
|
|
|
if (res > 0) {
|
|
|
|
if ((numbytes = recv(sockfd, recvbuf, MAXDATASIZE - 1, 0)) == -1) {
|
|
|
|
perror("recv STAT");
|
|
|
|
fail++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
recvbuf[numbytes] = '\0';
|
|
|
|
if (strstr(recvbuf, "+OK ") == NULL) {
|
|
|
|
ERR("POP3 status failed: %s", recvbuf);
|
|
|
|
fail++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
// now we get the data
|
|
|
|
reply = recvbuf + 4;
|
|
|
|
if (reply == NULL) {
|
|
|
|
ERR("Error parsing POP3 response: %s", recvbuf);
|
|
|
|
fail++;
|
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
timed_thread_lock(mail->p_timed_thread);
|
|
|
|
sscanf(reply, "%lu %lu", &mail->unseen, &mail->used);
|
|
|
|
timed_thread_unlock(mail->p_timed_thread);
|
|
|
|
}
|
|
|
|
strncpy(sendbuf, "QUIT\r\n", MAXDATASIZE);
|
|
|
|
if (send(sockfd, sendbuf, strlen(sendbuf), 0) == -1) {
|
|
|
|
perror("send QUIT");
|
|
|
|
fail++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
timeout.tv_sec = 60; // 60 second timeout i guess
|
|
|
|
timeout.tv_usec = 0;
|
|
|
|
FD_ZERO(&fdset);
|
|
|
|
FD_SET(sockfd, &fdset);
|
|
|
|
res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
|
|
|
|
if (res > 0) {
|
|
|
|
if ((numbytes = recv(sockfd, recvbuf, MAXDATASIZE - 1, 0)) == -1) {
|
|
|
|
perror("recv QUIT");
|
|
|
|
fail++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
recvbuf[numbytes] = '\0';
|
|
|
|
if (strstr(recvbuf, "+OK") == NULL) {
|
|
|
|
ERR("POP3 logout failed: %s", recvbuf);
|
|
|
|
fail++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (strlen(mail->command) > 1 && mail->unseen > old_unseen) {
|
|
|
|
// new mail goodie
|
|
|
|
if (system(mail->command) == -1) {
|
|
|
|
perror("system()");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fail = 0;
|
|
|
|
old_unseen = mail->unseen;
|
|
|
|
} while (0);
|
2008-02-20 20:30:45 +00:00
|
|
|
if ((fstat(sockfd, &stat_buf) == 0) && S_ISSOCK(stat_buf.st_mode)) {
|
|
|
|
/* if a valid socket, close it */
|
|
|
|
close(sockfd);
|
|
|
|
}
|
|
|
|
if (timed_thread_test(mail->p_timed_thread)) {
|
|
|
|
timed_thread_exit(mail->p_timed_thread);
|
|
|
|
}
|
2006-05-08 22:34:38 +00:00
|
|
|
}
|
2007-09-02 04:36:09 +00:00
|
|
|
mail->unseen = 0;
|
|
|
|
mail->used = 0;
|
2006-05-08 22:34:38 +00:00
|
|
|
return 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
|
|
|
{
|
2008-03-29 06:24:04 +00:00
|
|
|
FILE *fp;
|
|
|
|
char *p2;
|
|
|
|
int n2;
|
|
|
|
struct text_object *obj = (struct text_object *)arg;
|
2006-11-15 01:20:49 +00:00
|
|
|
while (1) {
|
2008-03-29 06:24:04 +00:00
|
|
|
p2 = obj->data.texeci.buffer;
|
|
|
|
fp = popen(obj->data.texeci.cmd, "r");
|
2008-02-20 20:30:45 +00:00
|
|
|
|
|
|
|
timed_thread_lock(obj->data.texeci.p_timed_thread);
|
2008-03-29 06:24:04 +00:00
|
|
|
n2 = fread(p2, 1, text_buffer_size, fp);
|
2008-02-20 20:30:45 +00:00
|
|
|
|
|
|
|
pclose(fp);
|
2006-02-01 14:39:23 +00:00
|
|
|
p2[n2] = '\0';
|
2006-02-13 02:28:46 +00:00
|
|
|
if (n2 && p2[n2 - 1] == '\n') {
|
2006-02-01 14:39:23 +00:00
|
|
|
p2[n2 - 1] = '\0';
|
2006-02-13 02:28:46 +00:00
|
|
|
}
|
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++;
|
|
|
|
}
|
2008-02-20 20:30:45 +00:00
|
|
|
timed_thread_unlock(obj->data.texeci.p_timed_thread);
|
|
|
|
if (timed_thread_test(obj->data.texeci.p_timed_thread)) {
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
static void free_text_objects(unsigned int count, struct text_object *objs)
|
2005-07-20 00:30:40 +00:00
|
|
|
{
|
|
|
|
unsigned int i;
|
2008-02-20 20:30:45 +00:00
|
|
|
|
2005-12-10 14:15:38 +00:00
|
|
|
for (i = 0; i < count; i++) {
|
2006-01-28 01:28:23 +00:00
|
|
|
switch (objs[i].type) {
|
2007-08-10 21:14:06 +00:00
|
|
|
#ifndef __OpenBSD__
|
2006-01-28 01:28:23 +00:00
|
|
|
case OBJ_acpitemp:
|
|
|
|
case OBJ_acpitempf:
|
|
|
|
close(objs[i].data.i);
|
|
|
|
break;
|
|
|
|
case OBJ_i2c:
|
2008-02-20 20:30:45 +00:00
|
|
|
case OBJ_platform:
|
|
|
|
case OBJ_hwmon:
|
|
|
|
close(objs[i].data.sysfs.fd);
|
|
|
|
break;
|
2007-08-10 21:14:06 +00:00
|
|
|
#endif /* !__OpenBSD__ */
|
2006-01-28 01:28:23 +00:00
|
|
|
case OBJ_time:
|
|
|
|
case OBJ_utime:
|
2006-07-15 02:18:06 +00:00
|
|
|
free(objs[i].data.s);
|
|
|
|
break;
|
|
|
|
case OBJ_tztime:
|
|
|
|
free(objs[i].data.tztime.tz);
|
|
|
|
free(objs[i].data.tztime.fmt);
|
|
|
|
break;
|
2007-02-12 01:03:10 +00:00
|
|
|
case OBJ_mboxscan:
|
|
|
|
free(objs[i].data.mboxscan.args);
|
|
|
|
free(objs[i].data.mboxscan.output);
|
|
|
|
break;
|
2007-10-02 23:57:41 +00:00
|
|
|
case OBJ_mails:
|
|
|
|
case OBJ_new_mails:
|
|
|
|
free(objs[i].data.local_mail.box);
|
|
|
|
break;
|
2006-05-08 22:34:38 +00:00
|
|
|
case OBJ_imap:
|
|
|
|
free(info.mail);
|
|
|
|
break;
|
|
|
|
case OBJ_imap_unseen:
|
|
|
|
if (!objs[i].global_mode) {
|
|
|
|
free(objs[i].data.mail);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case OBJ_imap_messages:
|
|
|
|
if (!objs[i].global_mode) {
|
|
|
|
free(objs[i].data.mail);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case OBJ_pop3:
|
|
|
|
free(info.mail);
|
|
|
|
break;
|
|
|
|
case OBJ_pop3_unseen:
|
|
|
|
if (!objs[i].global_mode) {
|
|
|
|
free(objs[i].data.mail);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case OBJ_pop3_used:
|
|
|
|
if (!objs[i].global_mode) {
|
|
|
|
free(objs[i].data.mail);
|
|
|
|
}
|
|
|
|
break;
|
2007-04-06 05:01:48 +00:00
|
|
|
case OBJ_if_empty:
|
2006-01-28 01:28:23 +00:00
|
|
|
case OBJ_if_existing:
|
|
|
|
case OBJ_if_mounted:
|
|
|
|
case OBJ_if_running:
|
|
|
|
free(objs[i].data.ifblock.s);
|
2007-04-06 06:11:53 +00:00
|
|
|
free(objs[i].data.ifblock.str);
|
2006-01-28 01:28:23 +00:00
|
|
|
break;
|
|
|
|
case OBJ_tail:
|
|
|
|
free(objs[i].data.tail.logfile);
|
|
|
|
free(objs[i].data.tail.buffer);
|
|
|
|
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:
|
2006-01-28 01:28:23 +00:00
|
|
|
case OBJ_exec:
|
|
|
|
case OBJ_execbar:
|
|
|
|
case OBJ_execgraph:
|
2008-03-22 06:10:54 +00:00
|
|
|
case OBJ_execp:
|
2006-01-28 01:28:23 +00:00
|
|
|
free(objs[i].data.s);
|
|
|
|
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
|
2008-03-18 00:23:16 +00:00
|
|
|
#ifdef __LINUX__
|
2008-03-24 20:08:16 +00:00
|
|
|
case OBJ_disk_protect:
|
|
|
|
free(objs[i].data.s);
|
|
|
|
break;
|
2008-03-18 00:23:16 +00:00
|
|
|
case OBJ_if_up:
|
|
|
|
free(objs[i].data.ifblock.s);
|
|
|
|
free(objs[i].data.ifblock.str);
|
|
|
|
break;
|
2008-03-22 19:06:09 +00:00
|
|
|
case OBJ_if_gw:
|
|
|
|
free(objs[i].data.ifblock.s);
|
|
|
|
free(objs[i].data.ifblock.str);
|
|
|
|
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:
|
|
|
|
if(objs[i].data.s)
|
|
|
|
free(objs[i].data.s);
|
|
|
|
break;
|
2008-03-18 00:23:16 +00:00
|
|
|
#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
|
|
|
|
#ifdef RSS
|
|
|
|
case OBJ_rss:
|
|
|
|
free(objs[i].data.rss.uri);
|
2007-06-02 08:17:33 +00:00
|
|
|
free(objs[i].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:
|
|
|
|
free(objs[i].data.s);
|
|
|
|
break;
|
2006-12-12 23:21:14 +00:00
|
|
|
case OBJ_battery_time:
|
|
|
|
free(objs[i].data.s);
|
|
|
|
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:
|
2006-01-28 01:28:23 +00:00
|
|
|
free(objs[i].data.execi.cmd);
|
|
|
|
free(objs[i].data.execi.buffer);
|
|
|
|
break;
|
|
|
|
case OBJ_texeci:
|
2006-11-15 01:20:49 +00:00
|
|
|
free(objs[i].data.texeci.cmd);
|
|
|
|
free(objs[i].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:
|
|
|
|
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:
|
|
|
|
free(objs[i].data.hddtemp.dev);
|
|
|
|
free(objs[i].data.hddtemp.addr);
|
2008-04-22 22:54:22 +00:00
|
|
|
free(objs[i].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;
|
2008-03-22 18:08:47 +00:00
|
|
|
#ifdef SMAPI
|
|
|
|
case OBJ_smapi:
|
|
|
|
case OBJ_smapi_bat_perc:
|
|
|
|
free(objs[i].data.s);
|
|
|
|
break;
|
|
|
|
case OBJ_if_smapi_bat_installed:
|
|
|
|
free(objs[i].data.ifblock.s);
|
|
|
|
free(objs[i].data.ifblock.str);
|
|
|
|
break;
|
|
|
|
#endif
|
2008-06-03 20:46:15 +00:00
|
|
|
#ifdef NVIDIA
|
|
|
|
case OBJ_nvidia:
|
|
|
|
break;
|
|
|
|
#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_host:
|
|
|
|
case OBJ_mpd_port:
|
|
|
|
case OBJ_mpd_password:
|
|
|
|
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:
|
|
|
|
free_mpd_vars(&info);
|
|
|
|
break;
|
|
|
|
#endif
|
2005-07-20 00:30:40 +00:00
|
|
|
}
|
|
|
|
}
|
2005-12-10 14:15:38 +00:00
|
|
|
free(objs);
|
2008-02-20 20:30:45 +00:00
|
|
|
/* text_objects = NULL;
|
2008-03-18 00:23:16 +00:00
|
|
|
text_object_count = 0; */
|
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-03-31 15:33:54 +00:00
|
|
|
/* strip a leading /dev/ if any */
|
|
|
|
#define DEV_NAME(x) strncmp(x, "/dev/", 5) ? x : x + 5
|
|
|
|
|
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,
|
|
|
|
const char *arg, unsigned int object_count,
|
|
|
|
struct text_object *text_objects, long line)
|
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); {
|
|
|
|
#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(acpitempf, 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-10 11:14:19 +00:00
|
|
|
END OBJ(freq_dyn, 0)
|
|
|
|
END OBJ(freq_dyn_g, 0)
|
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];
|
|
|
|
|
|
|
|
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-04-02 18:44:49 +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_cpu_tempf, 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)
|
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)
|
2008-03-18 00:23:16 +00:00
|
|
|
END OBJ(if_up, 0)
|
|
|
|
if (blockdepth >= MAX_IF_BLOCK_DEPTH) {
|
|
|
|
CRIT_ERR("MAX_IF_BLOCK_DEPTH exceeded");
|
|
|
|
}
|
|
|
|
if (!arg) {
|
|
|
|
ERR("if_up 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-03-18 00:23:16 +00:00
|
|
|
blockstart[blockdepth] = object_count;
|
|
|
|
obj->data.ifblock.pos = object_count + 2;
|
|
|
|
blockdepth++;
|
2008-03-22 19:06:09 +00:00
|
|
|
END OBJ(if_gw, 0)
|
|
|
|
if (blockdepth >= MAX_IF_BLOCK_DEPTH) {
|
|
|
|
CRIT_ERR("MAX_IF_BLOCK_DEPTH exceeded");
|
|
|
|
}
|
|
|
|
blockstart[blockdepth] = object_count;
|
|
|
|
obj->data.ifblock.pos = object_count + 2;
|
|
|
|
blockdepth++;
|
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-04-02 18:44:49 +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-02-20 20:30:45 +00:00
|
|
|
if (arg && strcmp(arg, "status") == 0) {
|
|
|
|
obj->data.i = PB_BATT_STATUS;
|
|
|
|
} else if (arg && strcmp(arg, "percent") == 0) {
|
|
|
|
obj->data.i = PB_BATT_PERCENT;
|
|
|
|
} else if (arg && strcmp(arg, "time") == 0) {
|
|
|
|
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__ */
|
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)
|
|
|
|
END OBJ(cpu, INFO_CPU)
|
2005-08-27 10:10:31 +00:00
|
|
|
if (arg) {
|
2006-01-28 01:28:23 +00:00
|
|
|
if (strncmp(arg, "cpu", 3) == 0 && isdigit(arg[3])) {
|
|
|
|
obj->data.cpu_index = atoi(&arg[3]);
|
|
|
|
arg += 4;
|
2008-02-20 20:30:45 +00:00
|
|
|
} else {
|
|
|
|
obj->data.cpu_index = 0;
|
|
|
|
}
|
2005-08-27 10:36:28 +00:00
|
|
|
} else {
|
2006-01-28 01:28:23 +00:00
|
|
|
obj->data.cpu_index = 0;
|
|
|
|
}
|
2005-08-27 10:10:31 +00:00
|
|
|
END OBJ(cpubar, INFO_CPU)
|
|
|
|
if (arg) {
|
2006-01-28 01:28:23 +00:00
|
|
|
if (strncmp(arg, "cpu", 3) == 0 && isdigit(arg[3])) {
|
|
|
|
obj->data.cpu_index = atoi(&arg[3]);
|
|
|
|
arg += 4;
|
2008-02-20 20:30:45 +00:00
|
|
|
} else {
|
|
|
|
obj->data.cpu_index = 0;
|
2005-08-27 10:10:31 +00:00
|
|
|
}
|
2008-02-20 20:30:45 +00:00
|
|
|
scan_bar(arg, &obj->a, &obj->b);
|
2006-01-28 01:28:23 +00:00
|
|
|
} else {
|
2008-02-20 20:30:45 +00:00
|
|
|
scan_bar(arg, &obj->a, &obj->b);
|
2006-01-28 01:28:23 +00:00
|
|
|
obj->data.cpu_index = 0;
|
2005-08-27 10:10:31 +00:00
|
|
|
}
|
2006-01-28 01:28:23 +00:00
|
|
|
END OBJ(cpugraph, INFO_CPU)
|
2008-02-09 02:21:06 +00:00
|
|
|
char *buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
|
|
|
|
&obj->e);
|
|
|
|
|
|
|
|
if (buf) {
|
|
|
|
if (strncmp(buf, "cpu", 3) == 0 && isdigit(buf[3])) {
|
|
|
|
obj->data.cpu_index = atoi(&buf[3]);
|
|
|
|
} else {
|
|
|
|
obj->data.cpu_index = 0;
|
2005-08-27 09:29:24 +00:00
|
|
|
}
|
2008-02-09 02:21:06 +00:00
|
|
|
free(buf);
|
2006-01-28 01:28:23 +00:00
|
|
|
}
|
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,
|
|
|
|
&obj->e);
|
|
|
|
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-02-09 02:21:06 +00:00
|
|
|
if (arg) {
|
2008-03-31 15:33:54 +00:00
|
|
|
obj->data.diskio = prepare_diskio_stat(DEV_NAME(arg));
|
2008-02-09 02:21:06 +00:00
|
|
|
} else {
|
|
|
|
obj->data.diskio = NULL;
|
|
|
|
}
|
2006-12-29 23:14:31 +00:00
|
|
|
END OBJ(diskio_read, INFO_DISKIO)
|
2008-02-09 02:21:06 +00:00
|
|
|
if (arg) {
|
2008-03-31 15:33:54 +00:00
|
|
|
obj->data.diskio = prepare_diskio_stat(DEV_NAME(arg));
|
2008-02-09 02:21:06 +00:00
|
|
|
} else {
|
|
|
|
obj->data.diskio = NULL;
|
|
|
|
}
|
2006-12-29 23:14:31 +00:00
|
|
|
END OBJ(diskio_write, INFO_DISKIO)
|
2008-02-09 02:21:06 +00:00
|
|
|
if (arg) {
|
2008-03-31 15:33:54 +00:00
|
|
|
obj->data.diskio = prepare_diskio_stat(DEV_NAME(arg));
|
2008-02-09 02:21:06 +00:00
|
|
|
} else {
|
|
|
|
obj->data.diskio = NULL;
|
|
|
|
}
|
|
|
|
END OBJ(diskiograph, INFO_DISKIO)
|
2008-03-31 15:33:54 +00:00
|
|
|
char *buf = scan_graph(DEV_NAME(arg), &obj->a, &obj->b, &obj->c, &obj->d,
|
2008-02-09 02:21:06 +00:00
|
|
|
&obj->e);
|
|
|
|
|
|
|
|
if (buf) {
|
|
|
|
obj->data.diskio = prepare_diskio_stat(buf);
|
|
|
|
free(buf);
|
|
|
|
} else {
|
|
|
|
obj->data.diskio = NULL;
|
|
|
|
}
|
|
|
|
END OBJ(diskiograph_read, INFO_DISKIO)
|
2008-03-31 15:33:54 +00:00
|
|
|
char *buf = scan_graph(DEV_NAME(arg), &obj->a, &obj->b, &obj->c, &obj->d,
|
2008-02-09 02:21:06 +00:00
|
|
|
&obj->e);
|
|
|
|
|
|
|
|
if (buf) {
|
|
|
|
obj->data.diskio = prepare_diskio_stat(buf);
|
|
|
|
free(buf);
|
|
|
|
} else {
|
|
|
|
obj->data.diskio = NULL;
|
|
|
|
}
|
|
|
|
END OBJ(diskiograph_write, INFO_DISKIO)
|
2008-03-31 15:33:54 +00:00
|
|
|
char *buf = scan_graph(DEV_NAME(arg), &obj->a, &obj->b, &obj->c, &obj->d,
|
2008-02-09 02:21:06 +00:00
|
|
|
&obj->e);
|
|
|
|
|
|
|
|
if (buf) {
|
|
|
|
obj->data.diskio = prepare_diskio_stat(buf);
|
|
|
|
free(buf);
|
|
|
|
} else {
|
|
|
|
obj->data.diskio = NULL;
|
|
|
|
}
|
2008-02-20 20:30:45 +00:00
|
|
|
END OBJ(color, 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_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,
|
|
|
|
&obj->e);
|
|
|
|
|
|
|
|
if (buf) {
|
|
|
|
obj->data.net = get_net_stat(buf);
|
|
|
|
free(buf);
|
2005-07-30 22:59:01 +00:00
|
|
|
}
|
2006-01-25 04:31:00 +00:00
|
|
|
END OBJ(else, 0)
|
2006-01-28 01:28:23 +00:00
|
|
|
if (blockdepth) {
|
2008-02-20 20:30:45 +00:00
|
|
|
(text_objects[blockstart[blockdepth - 1]]).data.ifblock.pos =
|
|
|
|
object_count;
|
2006-01-28 01:28:23 +00:00
|
|
|
blockstart[blockdepth - 1] = object_count;
|
|
|
|
obj->data.ifblock.pos = object_count + 2;
|
|
|
|
} else {
|
|
|
|
ERR("$else: no matching $if_*");
|
|
|
|
}
|
2005-07-28 04:48:27 +00:00
|
|
|
END OBJ(endif, 0)
|
2006-01-28 01:28:23 +00:00
|
|
|
if (blockdepth) {
|
|
|
|
blockdepth--;
|
2008-02-20 20:30:45 +00:00
|
|
|
text_objects[blockstart[blockdepth]].data.ifblock.pos =
|
|
|
|
object_count;
|
2006-01-28 01:28:23 +00:00
|
|
|
} else {
|
|
|
|
ERR("$endif: no matching $if_*");
|
|
|
|
}
|
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);
|
2008-02-20 20:30:45 +00:00
|
|
|
END OBJ(execbar, 0)
|
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)
|
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;
|
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;
|
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
|
|
|
}
|
|
|
|
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
|
|
|
}
|
|
|
|
END OBJ(texeci, 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.texeci.interval, &n) <= 0) {
|
|
|
|
char buf[256];
|
|
|
|
|
|
|
|
ERR("${texeci <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.texeci.cmd = strndup(arg + n, text_buffer_size);
|
2008-03-22 06:10:54 +00:00
|
|
|
obj->data.texeci.buffer = malloc(text_buffer_size);
|
2008-02-20 20:30:45 +00:00
|
|
|
}
|
|
|
|
obj->data.texeci.p_timed_thread = NULL;
|
|
|
|
END OBJ(pre_exec, 0)
|
|
|
|
obj->type = OBJ_text;
|
|
|
|
if (arg) {
|
|
|
|
FILE *fp = popen(arg, "r");
|
|
|
|
unsigned int n;
|
|
|
|
char buf[2048];
|
|
|
|
|
|
|
|
n = fread(buf, 1, 2048, fp);
|
|
|
|
buf[n] = '\0';
|
|
|
|
|
|
|
|
if (n && buf[n - 1] == '\n') {
|
|
|
|
buf[n - 1] = '\0';
|
|
|
|
}
|
|
|
|
|
|
|
|
pclose(fp);
|
|
|
|
|
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.s = strndup("", text_buffer_size);
|
2008-02-20 20:30:45 +00:00
|
|
|
}
|
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);
|
|
|
|
if (arg) {
|
|
|
|
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
|
|
|
|
2007-08-10 21:14:06 +00:00
|
|
|
#ifndef __OpenBSD__
|
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
|
|
|
|
2005-07-20 00:30:40 +00:00
|
|
|
END OBJ(top, INFO_TOP)
|
2006-01-28 01:28:23 +00:00
|
|
|
char buf[64];
|
2008-02-20 20:30:45 +00:00
|
|
|
int n;
|
|
|
|
|
|
|
|
if (!arg) {
|
|
|
|
ERR("top needs arguments");
|
|
|
|
obj->type = OBJ_text;
|
2008-04-02 18:44:49 +00:00
|
|
|
// obj->data.s = strndup("${top}", text_buffer_size);
|
2005-12-10 14:15:38 +00:00
|
|
|
return NULL;
|
2005-07-20 00:30:40 +00:00
|
|
|
}
|
2008-02-20 20:30:45 +00:00
|
|
|
if (sscanf(arg, "%63s %i", buf, &n) == 2) {
|
|
|
|
if (strcmp(buf, "name") == 0) {
|
|
|
|
obj->data.top.type = TOP_NAME;
|
|
|
|
} else if (strcmp(buf, "cpu") == 0) {
|
|
|
|
obj->data.top.type = TOP_CPU;
|
|
|
|
} else if (strcmp(buf, "pid") == 0) {
|
|
|
|
obj->data.top.type = TOP_PID;
|
|
|
|
} else if (strcmp(buf, "mem") == 0) {
|
|
|
|
obj->data.top.type = TOP_MEM;
|
|
|
|
} else if (strcmp(buf, "time") == 0) {
|
|
|
|
obj->data.top.type = TOP_TIME;
|
2008-03-30 07:04:25 +00:00
|
|
|
} else if (strcmp(buf, "mem_res") == 0) {
|
|
|
|
obj->data.top.type = TOP_MEM_RES;
|
|
|
|
} else if (strcmp(buf, "mem_vsize") == 0) {
|
|
|
|
obj->data.top.type = TOP_MEM_VSIZE;
|
2008-02-20 20:30:45 +00:00
|
|
|
} else {
|
|
|
|
ERR("invalid arg for top");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
if (n < 1 || n > 10) {
|
|
|
|
CRIT_ERR("invalid arg for top");
|
|
|
|
return NULL;
|
|
|
|
} else {
|
|
|
|
obj->data.top.num = n - 1;
|
|
|
|
top_cpu = 1;
|
|
|
|
}
|
2005-07-28 04:48:27 +00:00
|
|
|
} else {
|
2008-02-20 20:30:45 +00:00
|
|
|
ERR("invalid args given for top");
|
|
|
|
return NULL;
|
2005-07-20 00:30:40 +00:00
|
|
|
}
|
2008-03-30 07:04:25 +00:00
|
|
|
END OBJ(top_mem, INFO_TOP)
|
|
|
|
char buf[64];
|
2008-02-20 20:30:45 +00:00
|
|
|
int n;
|
|
|
|
|
|
|
|
if (!arg) {
|
|
|
|
ERR("top_mem needs arguments");
|
|
|
|
obj->type = OBJ_text;
|
2008-04-02 18:44:49 +00:00
|
|
|
obj->data.s = strndup("${top_mem}", text_buffer_size);
|
2005-12-10 14:15:38 +00:00
|
|
|
return NULL;
|
2005-07-25 00:22:16 +00:00
|
|
|
}
|
2008-02-20 20:30:45 +00:00
|
|
|
if (sscanf(arg, "%63s %i", buf, &n) == 2) {
|
|
|
|
if (strcmp(buf, "name") == 0) {
|
|
|
|
obj->data.top.type = TOP_NAME;
|
|
|
|
} else if (strcmp(buf, "cpu") == 0) {
|
|
|
|
obj->data.top.type = TOP_CPU;
|
|
|
|
} else if (strcmp(buf, "pid") == 0) {
|
|
|
|
obj->data.top.type = TOP_PID;
|
|
|
|
} else if (strcmp(buf, "mem") == 0) {
|
|
|
|
obj->data.top.type = TOP_MEM;
|
|
|
|
} else if (strcmp(buf, "time") == 0) {
|
|
|
|
obj->data.top.type = TOP_TIME;
|
2008-03-30 07:04:25 +00:00
|
|
|
} else if (strcmp(buf, "mem_res") == 0) {
|
|
|
|
obj->data.top.type = TOP_MEM_RES;
|
|
|
|
} else if (strcmp(buf, "mem_vsize") == 0) {
|
|
|
|
obj->data.top.type = TOP_MEM_VSIZE;
|
2008-02-20 20:30:45 +00:00
|
|
|
} else {
|
|
|
|
ERR("invalid arg for top");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
if (n < 1 || n > 10) {
|
2008-03-30 07:04:25 +00:00
|
|
|
CRIT_ERR("invalid arg for top");
|
2008-02-20 20:30:45 +00:00
|
|
|
return NULL;
|
|
|
|
} else {
|
|
|
|
obj->data.top.num = n - 1;
|
|
|
|
top_mem = 1;
|
|
|
|
}
|
2005-07-28 04:48:27 +00:00
|
|
|
} else {
|
2008-02-20 20:30:45 +00:00
|
|
|
ERR("invalid args given for top");
|
|
|
|
return NULL;
|
2005-07-25 00:22:16 +00:00
|
|
|
}
|
2008-03-30 07:04:25 +00:00
|
|
|
END OBJ(addr, INFO_NET)
|
|
|
|
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-03-30 07:04:25 +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-03-30 07:04:25 +00:00
|
|
|
END OBJ(tail, 0)
|
|
|
|
char buf[64];
|
2008-02-20 20:30:45 +00:00
|
|
|
int n1, n2;
|
|
|
|
struct stat st;
|
2007-09-28 20:16:16 +00:00
|
|
|
|
2008-02-20 20:30:45 +00:00
|
|
|
if (!arg) {
|
|
|
|
ERR("tail needs arguments");
|
|
|
|
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
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
if (sscanf(arg, "%63s %i %i", buf, &n1, &n2) == 2) {
|
2008-03-30 07:04:25 +00:00
|
|
|
if (n1 < 1 || n1 > MAX_TAIL_LINES) {
|
2008-02-20 20:30:45 +00:00
|
|
|
CRIT_ERR("invalid arg for tail, number of lines must be "
|
2008-03-30 07:04:25 +00:00
|
|
|
"between 1 and %i", MAX_TAIL_LINES);
|
2008-02-20 20:30:45 +00:00
|
|
|
return NULL;
|
|
|
|
} else {
|
|
|
|
FILE *fp = NULL;
|
|
|
|
int fd;
|
2007-09-28 20:16:16 +00:00
|
|
|
|
2008-02-20 20:30:45 +00:00
|
|
|
obj->data.tail.fd = -1;
|
2007-09-28 20:16:16 +00:00
|
|
|
|
2008-02-20 20:30:45 +00:00
|
|
|
if (stat(buf, &st) == 0) {
|
|
|
|
if (S_ISFIFO(st.st_mode)) {
|
|
|
|
fd = open(buf, O_RDONLY | O_NONBLOCK);
|
2007-09-28 20:16:16 +00:00
|
|
|
|
2008-02-20 20:30:45 +00:00
|
|
|
if (fd == -1) {
|
|
|
|
CRIT_ERR("tail logfile does not exist, or you do "
|
|
|
|
"not have correct permissions");
|
|
|
|
}
|
2007-09-28 20:16:16 +00:00
|
|
|
|
2008-02-20 20:30:45 +00:00
|
|
|
obj->data.tail.fd = fd;
|
|
|
|
} else {
|
|
|
|
fp = fopen(buf, "r");
|
|
|
|
}
|
2007-09-28 20:16:16 +00:00
|
|
|
}
|
|
|
|
|
2008-02-20 20:30:45 +00:00
|
|
|
if (fp || obj->data.tail.fd != -1) {
|
2008-03-20 21:28:19 +00:00
|
|
|
obj->data.tail.logfile = malloc(text_buffer_size);
|
2008-02-20 20:30:45 +00:00
|
|
|
strcpy(obj->data.tail.logfile, buf);
|
|
|
|
obj->data.tail.wantedlines = n1;
|
|
|
|
obj->data.tail.interval = update_interval * 2;
|
2007-09-28 20:16:16 +00:00
|
|
|
|
2008-02-20 20:30:45 +00:00
|
|
|
if (obj->data.tail.fd == -1) {
|
|
|
|
fclose(fp);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// fclose(fp);
|
|
|
|
CRIT_ERR("tail logfile does not exist, or you do not have "
|
|
|
|
"correct permissions");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (sscanf(arg, "%63s %i %i", buf, &n1, &n2) == 3) {
|
2008-03-30 07:04:25 +00:00
|
|
|
if (n1 < 1 || n1 > MAX_TAIL_LINES) {
|
2008-02-20 20:30:45 +00:00
|
|
|
CRIT_ERR("invalid arg for tail, number of lines must be "
|
2008-03-30 07:04:25 +00:00
|
|
|
"between 1 and %i", MAX_TAIL_LINES);
|
2008-02-20 20:30:45 +00:00
|
|
|
return NULL;
|
|
|
|
} else if (n2 < 1 || n2 < update_interval) {
|
|
|
|
CRIT_ERR("invalid arg for tail, interval must be greater than "
|
|
|
|
"0 and Conky's interval");
|
|
|
|
return NULL;
|
2005-07-28 04:48:27 +00:00
|
|
|
} else {
|
2008-02-20 20:30:45 +00:00
|
|
|
FILE *fp = 0;
|
|
|
|
int fd;
|
2007-09-28 20:16:16 +00:00
|
|
|
|
2008-02-20 20:30:45 +00:00
|
|
|
obj->data.tail.fd = -1;
|
2007-09-28 20:16:16 +00:00
|
|
|
|
2008-02-20 20:30:45 +00:00
|
|
|
if (stat(buf, &st) == 0) {
|
|
|
|
if (S_ISFIFO(st.st_mode)) {
|
|
|
|
fd = open(buf, O_RDONLY | O_NONBLOCK);
|
2007-09-28 20:16:16 +00:00
|
|
|
|
2008-02-20 20:30:45 +00:00
|
|
|
if (fd == -1) {
|
|
|
|
CRIT_ERR("tail logfile does not exist, or you do "
|
|
|
|
"not have correct permissions");
|
|
|
|
}
|
2007-09-28 20:16:16 +00:00
|
|
|
|
2008-02-20 20:30:45 +00:00
|
|
|
obj->data.tail.fd = fd;
|
|
|
|
} else {
|
|
|
|
fp = fopen(buf, "r");
|
|
|
|
}
|
2007-09-28 20:16:16 +00:00
|
|
|
}
|
|
|
|
|
2008-02-20 20:30:45 +00:00
|
|
|
if (fp || obj->data.tail.fd != -1) {
|
2008-03-20 21:28:19 +00:00
|
|
|
obj->data.tail.logfile = malloc(text_buffer_size);
|
2008-02-20 20:30:45 +00:00
|
|
|
strcpy(obj->data.tail.logfile, buf);
|
|
|
|
obj->data.tail.wantedlines = n1;
|
|
|
|
obj->data.tail.interval = n2;
|
2007-09-28 20:16:16 +00:00
|
|
|
|
2008-02-20 20:30:45 +00:00
|
|
|
if (obj->data.tail.fd == -1) {
|
|
|
|
fclose(fp);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// fclose(fp);
|
|
|
|
CRIT_ERR("tail logfile does not exist, or you do not have "
|
|
|
|
"correct permissions");
|
|
|
|
}
|
2005-07-20 00:30:40 +00:00
|
|
|
}
|
2008-02-20 20:30:45 +00:00
|
|
|
} else {
|
|
|
|
ERR("invalid args given for tail");
|
|
|
|
return NULL;
|
2005-07-20 00:30:40 +00:00
|
|
|
}
|
2008-02-20 20:30:45 +00:00
|
|
|
/* asumming all else worked */
|
2008-03-20 21:28:19 +00:00
|
|
|
obj->data.tail.buffer = malloc(text_buffer_size * 20);
|
2005-08-26 05:52:43 +00:00
|
|
|
END OBJ(head, 0)
|
2006-01-28 01:28:23 +00:00
|
|
|
char buf[64];
|
2008-02-20 20:30:45 +00:00
|
|
|
int n1, n2;
|
|
|
|
|
|
|
|
if (!arg) {
|
|
|
|
ERR("head needs arguments");
|
|
|
|
obj->type = OBJ_text;
|
2008-04-02 18:44:49 +00:00
|
|
|
obj->data.s = strndup("${head}", text_buffer_size);
|
2005-12-10 14:15:38 +00:00
|
|
|
return NULL;
|
2005-08-26 05:52:43 +00:00
|
|
|
}
|
2008-02-20 20:30:45 +00:00
|
|
|
if (sscanf(arg, "%63s %i %i", buf, &n1, &n2) == 2) {
|
2008-03-30 07:04:25 +00:00
|
|
|
if (n1 < 1 || n1 > MAX_TAIL_LINES) {
|
2008-02-20 20:30:45 +00:00
|
|
|
CRIT_ERR("invalid arg for head, number of lines must be "
|
2008-03-30 07:04:25 +00:00
|
|
|
"between 1 and %i", MAX_TAIL_LINES);
|
2008-02-20 20:30:45 +00:00
|
|
|
return NULL;
|
2005-08-26 05:52:43 +00:00
|
|
|
} else {
|
2008-02-20 20:30:45 +00:00
|
|
|
FILE *fp;
|
|
|
|
|
|
|
|
fp = fopen(buf, "r");
|
|
|
|
if (fp != NULL) {
|
2008-03-20 21:28:19 +00:00
|
|
|
obj->data.tail.logfile = malloc(text_buffer_size);
|
2008-02-20 20:30:45 +00:00
|
|
|
strcpy(obj->data.tail.logfile, buf);
|
|
|
|
obj->data.tail.wantedlines = n1;
|
|
|
|
obj->data.tail.interval = update_interval * 2;
|
|
|
|
fclose(fp);
|
|
|
|
} else {
|
|
|
|
// fclose(fp);
|
|
|
|
CRIT_ERR("head logfile does not exist, or you do not have "
|
|
|
|
"correct permissions");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (sscanf(arg, "%63s %i %i", buf, &n1, &n2) == 3) {
|
2008-03-30 07:04:25 +00:00
|
|
|
if (n1 < 1 || n1 > MAX_TAIL_LINES) {
|
2008-02-20 20:30:45 +00:00
|
|
|
CRIT_ERR("invalid arg for head, number of lines must be "
|
2008-03-30 07:04:25 +00:00
|
|
|
"between 1 and %i", MAX_TAIL_LINES);
|
2008-02-20 20:30:45 +00:00
|
|
|
return NULL;
|
|
|
|
} else if (n2 < 1 || n2 < update_interval) {
|
|
|
|
CRIT_ERR("invalid arg for head, interval must be greater than "
|
|
|
|
"0 and Conky's interval");
|
|
|
|
return NULL;
|
|
|
|
} else {
|
|
|
|
FILE *fp;
|
|
|
|
|
|
|
|
fp = fopen(buf, "r");
|
|
|
|
if (fp != NULL) {
|
2008-03-20 21:28:19 +00:00
|
|
|
obj->data.tail.logfile = malloc(text_buffer_size);
|
2008-02-20 20:30:45 +00:00
|
|
|
strcpy(obj->data.tail.logfile, buf);
|
|
|
|
obj->data.tail.wantedlines = n1;
|
|
|
|
obj->data.tail.interval = n2;
|
|
|
|
fclose(fp);
|
|
|
|
} else {
|
|
|
|
// fclose(fp);
|
|
|
|
CRIT_ERR("head logfile does not exist, or you do not have "
|
|
|
|
"correct permissions");
|
|
|
|
}
|
2005-08-26 05:52:43 +00:00
|
|
|
}
|
2008-02-20 20:30:45 +00:00
|
|
|
} else {
|
|
|
|
ERR("invalid args given for head");
|
|
|
|
return NULL;
|
2005-08-26 05:52:43 +00:00
|
|
|
}
|
2008-02-20 20:30:45 +00:00
|
|
|
/* asumming all else worked */
|
2008-03-20 21:28:19 +00:00
|
|
|
obj->data.tail.buffer = malloc(text_buffer_size * 20);
|
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;
|
2007-04-06 05:01:48 +00:00
|
|
|
END OBJ(if_empty, 0)
|
|
|
|
if (blockdepth >= MAX_IF_BLOCK_DEPTH) {
|
|
|
|
CRIT_ERR("MAX_IF_BLOCK_DEPTH exceeded");
|
|
|
|
}
|
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-02-20 20:30:45 +00:00
|
|
|
}
|
|
|
|
blockstart[blockdepth] = object_count;
|
|
|
|
obj->data.ifblock.pos = object_count + 2;
|
|
|
|
blockdepth++;
|
2005-07-28 04:48:27 +00:00
|
|
|
END OBJ(if_existing, 0)
|
2006-01-28 01:28:23 +00:00
|
|
|
if (blockdepth >= MAX_IF_BLOCK_DEPTH) {
|
|
|
|
CRIT_ERR("MAX_IF_BLOCK_DEPTH exceeded");
|
|
|
|
}
|
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-02-20 20:30:45 +00:00
|
|
|
blockstart[blockdepth] = object_count;
|
|
|
|
obj->data.ifblock.pos = object_count + 2;
|
|
|
|
blockdepth++;
|
2005-07-28 04:48:27 +00:00
|
|
|
END OBJ(if_mounted, 0)
|
2006-01-28 01:28:23 +00:00
|
|
|
if (blockdepth >= MAX_IF_BLOCK_DEPTH) {
|
|
|
|
CRIT_ERR("MAX_IF_BLOCK_DEPTH exceeded");
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
blockstart[blockdepth] = object_count;
|
|
|
|
obj->data.ifblock.pos = object_count + 2;
|
|
|
|
blockdepth++;
|
2005-07-28 04:48:27 +00:00
|
|
|
END OBJ(if_running, 0)
|
2006-01-28 01:28:23 +00:00
|
|
|
if (blockdepth >= MAX_IF_BLOCK_DEPTH) {
|
|
|
|
CRIT_ERR("MAX_IF_BLOCK_DEPTH exceeded");
|
|
|
|
}
|
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;
|
|
|
|
}
|
|
|
|
blockstart[blockdepth] = object_count;
|
|
|
|
obj->data.ifblock.pos = object_count + 2;
|
|
|
|
blockdepth++;
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
END OBJ(memmax, INFO_MEM)
|
|
|
|
END OBJ(memperc, INFO_MEM)
|
|
|
|
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,
|
|
|
|
&obj->e);
|
|
|
|
|
|
|
|
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);
|
|
|
|
END OBJ(new_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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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(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)
|
|
|
|
#ifndef __OpenBSD__
|
2008-02-20 20:30:45 +00:00
|
|
|
END OBJ(temp1, INFO_SYSFS)
|
|
|
|
obj->type = OBJ_i2c;
|
|
|
|
obj->data.sysfs.fd = open_i2c_sensor(0, "temp", 1,
|
|
|
|
&obj->data.sysfs.arg, obj->data.sysfs.devtype);
|
|
|
|
END OBJ(temp2, INFO_SYSFS)
|
|
|
|
obj->type = OBJ_i2c;
|
|
|
|
obj->data.sysfs.fd = open_i2c_sensor(0, "temp", 2,
|
|
|
|
&obj->data.sysfs.arg, obj->data.sysfs.devtype);
|
2007-08-10 21:14:06 +00:00
|
|
|
#endif
|
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)
|
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,
|
|
|
|
&obj->e);
|
|
|
|
|
|
|
|
if (buf) {
|
|
|
|
obj->data.net = get_net_stat(buf);
|
|
|
|
free(buf);
|
2005-07-30 22:59:01 +00:00
|
|
|
}
|
2008-02-20 20:30:45 +00:00
|
|
|
END OBJ(uptime_short, INFO_UPTIME)
|
|
|
|
END OBJ(uptime, INFO_UPTIME)
|
2008-03-18 00:23:16 +00:00
|
|
|
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-03-22 19:06:09 +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-02-20 20:30:45 +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__))
|
|
|
|
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-02-20 20:30:45 +00:00
|
|
|
END OBJ(imap_unseen, 0)
|
2006-05-08 22:34:38 +00:00
|
|
|
if (arg) {
|
|
|
|
// proccss
|
2006-05-09 22:39:39 +00:00
|
|
|
obj->data.mail = parse_mail_args(IMAP, arg);
|
2006-05-08 22:34:38 +00:00
|
|
|
obj->global_mode = 0;
|
|
|
|
} else {
|
|
|
|
obj->global_mode = 1;
|
|
|
|
}
|
2008-02-20 20:30:45 +00:00
|
|
|
END OBJ(imap_messages, 0)
|
2006-05-08 22:34:38 +00:00
|
|
|
if (arg) {
|
|
|
|
// proccss
|
2006-05-09 22:39:39 +00:00
|
|
|
obj->data.mail = parse_mail_args(IMAP, arg);
|
2006-05-08 22:34:38 +00:00
|
|
|
obj->global_mode = 0;
|
|
|
|
} else {
|
|
|
|
obj->global_mode = 1;
|
|
|
|
}
|
2008-02-20 20:30:45 +00:00
|
|
|
END OBJ(pop3_unseen, 0)
|
2006-05-08 22:34:38 +00:00
|
|
|
if (arg) {
|
|
|
|
// proccss
|
2006-05-09 22:39:39 +00:00
|
|
|
obj->data.mail = parse_mail_args(POP3, arg);
|
2006-05-08 22:34:38 +00:00
|
|
|
obj->global_mode = 0;
|
|
|
|
} else {
|
|
|
|
obj->global_mode = 1;
|
|
|
|
}
|
2008-02-20 20:30:45 +00:00
|
|
|
END OBJ(pop3_used, 0)
|
2006-05-08 22:34:38 +00:00
|
|
|
if (arg) {
|
|
|
|
// proccss
|
2006-05-09 22:39:39 +00:00
|
|
|
obj->data.mail = parse_mail_args(POP3, arg);
|
2006-05-08 22:34:38 +00:00
|
|
|
obj->global_mode = 0;
|
|
|
|
} else {
|
|
|
|
obj->global_mode = 1;
|
|
|
|
}
|
2008-03-18 00:23:16 +00:00
|
|
|
#ifdef SMAPI
|
|
|
|
END OBJ(smapi, 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 needs an argument");
|
|
|
|
END OBJ(if_smapi_bat_installed, 0)
|
|
|
|
if (blockdepth >= MAX_IF_BLOCK_DEPTH) {
|
|
|
|
CRIT_ERR("MAX_IF_BLOCK_DEPTH exceeded");
|
|
|
|
}
|
2008-03-22 18:08:47 +00:00
|
|
|
if (!arg) {
|
|
|
|
ERR("if_smapi_bat_installed 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-03-22 18:08:47 +00:00
|
|
|
blockstart[blockdepth] = object_count;
|
|
|
|
obj->data.ifblock.pos = object_count + 2;
|
|
|
|
blockdepth++;
|
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");
|
|
|
|
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
|
|
|
|
ERR("if_smapi_bat_bar needs an argument");
|
|
|
|
#endif /* SMAPI */
|
|
|
|
#ifdef MPD
|
|
|
|
END OBJ(mpd_artist, INFO_MPD)
|
|
|
|
END OBJ(mpd_title, INFO_MPD)
|
|
|
|
if (arg) {
|
|
|
|
sscanf(arg, "%d", &info.mpd.max_title_len);
|
|
|
|
if (info.mpd.max_title_len > 0) {
|
|
|
|
info.mpd.max_title_len++;
|
|
|
|
} else {
|
|
|
|
CRIT_ERR("mpd_title: invalid length argument");
|
|
|
|
}
|
2008-02-20 20:30:45 +00:00
|
|
|
} else {
|
|
|
|
info.mpd.max_title_len = 0;
|
|
|
|
}
|
|
|
|
END OBJ(mpd_random, INFO_MPD)
|
|
|
|
END OBJ(mpd_repeat, INFO_MPD)
|
|
|
|
END OBJ(mpd_elapsed, INFO_MPD)
|
|
|
|
END OBJ(mpd_length, INFO_MPD)
|
|
|
|
END OBJ(mpd_track, INFO_MPD)
|
|
|
|
END OBJ(mpd_name, INFO_MPD)
|
|
|
|
END OBJ(mpd_file, INFO_MPD)
|
|
|
|
END OBJ(mpd_percent, INFO_MPD)
|
|
|
|
END OBJ(mpd_album, INFO_MPD)
|
|
|
|
END OBJ(mpd_vol, INFO_MPD)
|
|
|
|
END OBJ(mpd_bitrate, INFO_MPD)
|
|
|
|
END OBJ(mpd_status, INFO_MPD)
|
|
|
|
END OBJ(mpd_bar, INFO_MPD)
|
|
|
|
scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
|
|
|
|
END OBJ(mpd_smart, INFO_MPD)
|
2005-10-31 05:17:06 +00:00
|
|
|
#endif
|
2006-03-25 21:21:07 +00:00
|
|
|
#ifdef XMMS2
|
2008-02-20 20:30:45 +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)
|
2008-03-18 00:23:16 +00:00
|
|
|
END OBJ(xmms2_playlist, INFO_XMMS2)
|
|
|
|
END OBJ(xmms2_timesplayed, INFO_XMMS2)
|
2006-03-25 21:21:07 +00:00
|
|
|
#endif
|
2006-11-03 20:54:52 +00:00
|
|
|
#ifdef AUDACIOUS
|
2008-02-20 20:30:45 +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)
|
|
|
|
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-02-20 20:30:45 +00:00
|
|
|
END OBJ(bmpx_title, INFO_BMPX)
|
2006-01-06 23:56:12 +00:00
|
|
|
memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
|
2008-02-20 20:30:45 +00:00
|
|
|
END OBJ(bmpx_artist, INFO_BMPX)
|
2006-01-06 23:56:12 +00:00
|
|
|
memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
|
2008-02-20 20:30:45 +00:00
|
|
|
END OBJ(bmpx_album, INFO_BMPX)
|
2006-01-06 23:56:12 +00:00
|
|
|
memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
|
2008-02-20 20:30:45 +00:00
|
|
|
END OBJ(bmpx_track, INFO_BMPX)
|
2006-01-06 23:56:12 +00:00
|
|
|
memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
|
2008-02-20 20:30:45 +00:00
|
|
|
END OBJ(bmpx_uri, INFO_BMPX)
|
2006-01-06 23:56:12 +00:00
|
|
|
memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
|
2008-02-20 20:30:45 +00:00
|
|
|
END OBJ(bmpx_bitrate, INFO_BMPX)
|
2006-01-06 23:56:12 +00:00
|
|
|
memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
|
2005-12-30 09:44:40 +00:00
|
|
|
#endif
|
2007-05-06 12:17:13 +00:00
|
|
|
#ifdef RSS
|
2008-02-20 20:30:45 +00:00
|
|
|
END OBJ(rss, 0)
|
2007-05-06 12:17:13 +00:00
|
|
|
if (arg) {
|
2007-06-02 08:17:33 +00:00
|
|
|
int argc, delay, act_par;
|
2008-02-20 20:30:45 +00:00
|
|
|
char *uri = (char *) malloc(128 * sizeof(char));
|
|
|
|
char *action = (char *) malloc(64 * sizeof(char));
|
2007-05-06 12:17:13 +00:00
|
|
|
|
2008-02-20 20:30:45 +00:00
|
|
|
argc = sscanf(arg, "%127s %d %63s %d", uri, &delay, action,
|
|
|
|
&act_par);
|
2007-05-06 12:17:13 +00:00
|
|
|
obj->data.rss.uri = uri;
|
2007-06-01 10:42:57 +00:00
|
|
|
obj->data.rss.delay = delay;
|
2007-06-02 08:17:33 +00:00
|
|
|
obj->data.rss.action = action;
|
|
|
|
obj->data.rss.act_par = act_par;
|
2007-06-03 11:20:47 +00:00
|
|
|
|
|
|
|
init_rss_info();
|
2008-02-20 20:30:45 +00:00
|
|
|
} else {
|
|
|
|
CRIT_ERR("rss needs arguments: <uri> <delay in minutes> <action> "
|
|
|
|
"[act_par]");
|
|
|
|
}
|
2007-05-06 12:17:13 +00:00
|
|
|
#endif
|
2006-08-10 16:56:13 +00:00
|
|
|
#ifdef HDDTEMP
|
2008-02-20 20:30:45 +00:00
|
|
|
END OBJ(hddtemp, 0)
|
|
|
|
if (!arg || scan_hddtemp(arg, &obj->data.hddtemp.dev,
|
2008-04-22 22:54:22 +00:00
|
|
|
&obj->data.hddtemp.addr, &obj->data.hddtemp.port, &obj->data.hddtemp.temp)) {
|
2006-08-10 16:56:13 +00:00
|
|
|
ERR("hddtemp needs arguments");
|
|
|
|
obj->type = OBJ_text;
|
2008-04-02 18:44:49 +00:00
|
|
|
obj->data.s = strndup("${hddtemp}", text_buffer_size);
|
2008-04-13 04:10:35 +00:00
|
|
|
obj->data.hddtemp.update_time = 0;
|
2006-08-10 16:56:13 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
#endif
|
2005-10-31 05:17:06 +00:00
|
|
|
#ifdef TCP_PORT_MONITOR
|
2008-02-20 20:30:45 +00:00
|
|
|
END OBJ(tcp_portmon, INFO_TCP_PORT_MONITOR)
|
2005-10-31 05:17:06 +00:00
|
|
|
int argc, port_begin, port_end, item, connection_index;
|
2008-02-20 20:30:45 +00:00
|
|
|
char itembuf[32];
|
|
|
|
|
|
|
|
memset(itembuf, 0, sizeof(itembuf));
|
|
|
|
connection_index = 0;
|
|
|
|
/* massive argument checking */
|
|
|
|
if (!arg) {
|
|
|
|
CRIT_ERR("tcp_portmon: needs arguments");
|
|
|
|
}
|
|
|
|
argc = sscanf(arg, "%d %d %31s %d", &port_begin, &port_end, itembuf,
|
|
|
|
&connection_index);
|
|
|
|
if ((argc != 3) && (argc != 4)) {
|
|
|
|
CRIT_ERR("tcp_portmon: requires 3 or 4 arguments");
|
|
|
|
}
|
|
|
|
if ((port_begin < 1) || (port_begin > 65535) || (port_end < 1)
|
|
|
|
|| (port_end > 65535)) {
|
|
|
|
CRIT_ERR("tcp_portmon: port values must be from 1 to 65535");
|
|
|
|
}
|
|
|
|
if (port_begin > port_end) {
|
|
|
|
CRIT_ERR("tcp_portmon: starting port must be <= ending port");
|
|
|
|
}
|
|
|
|
if (strncmp(itembuf, "count", 31) == 0) {
|
|
|
|
item = COUNT;
|
|
|
|
} else if (strncmp(itembuf, "rip", 31) == 0) {
|
|
|
|
item = REMOTEIP;
|
|
|
|
} else if (strncmp(itembuf, "rhost", 31) == 0) {
|
|
|
|
item = REMOTEHOST;
|
|
|
|
} else if (strncmp(itembuf, "rport", 31) == 0) {
|
|
|
|
item = REMOTEPORT;
|
|
|
|
} else if (strncmp(itembuf, "rservice", 31) == 0) {
|
|
|
|
item = REMOTESERVICE;
|
|
|
|
} else if (strncmp(itembuf, "lip", 31) == 0) {
|
|
|
|
item = LOCALIP;
|
|
|
|
} else if (strncmp(itembuf, "lhost", 31) == 0) {
|
|
|
|
item = LOCALHOST;
|
|
|
|
} else if (strncmp(itembuf, "lport", 31) == 0) {
|
|
|
|
item = LOCALPORT;
|
|
|
|
} else if (strncmp(itembuf, "lservice", 31) == 0) {
|
|
|
|
item = LOCALSERVICE;
|
|
|
|
} else {
|
|
|
|
CRIT_ERR("tcp_portmon: invalid item specified");
|
2005-10-31 05:17:06 +00:00
|
|
|
}
|
2008-02-20 20:30:45 +00:00
|
|
|
if ((argc == 3) && (item != COUNT)) {
|
|
|
|
CRIT_ERR("tcp_portmon: 3 argument form valid only for \"count\" "
|
|
|
|
"item");
|
|
|
|
}
|
|
|
|
if ((argc == 4) && (connection_index < 0)) {
|
|
|
|
CRIT_ERR("tcp_portmon: connection index must be non-negative");
|
|
|
|
}
|
|
|
|
/* ok, args looks good. save the text object data */
|
|
|
|
obj->data.tcp_port_monitor.port_range_begin = (in_port_t) port_begin;
|
|
|
|
obj->data.tcp_port_monitor.port_range_end = (in_port_t) port_end;
|
|
|
|
obj->data.tcp_port_monitor.item = item;
|
|
|
|
obj->data.tcp_port_monitor.connection_index = connection_index;
|
2006-01-28 01:28:23 +00:00
|
|
|
|
2008-02-20 20:30:45 +00:00
|
|
|
/* if the port monitor collection hasn't been created,
|
|
|
|
* we must create it */
|
|
|
|
if (!info.p_tcp_port_monitor_collection) {
|
|
|
|
info.p_tcp_port_monitor_collection =
|
|
|
|
create_tcp_port_monitor_collection();
|
|
|
|
if (!info.p_tcp_port_monitor_collection) {
|
|
|
|
CRIT_ERR("tcp_portmon: unable to create port monitor "
|
|
|
|
"collection");
|
|
|
|
}
|
2005-10-31 05:17:06 +00:00
|
|
|
}
|
2008-02-20 20:30:45 +00:00
|
|
|
|
|
|
|
/* if a port monitor for this port does not exist,
|
|
|
|
* create one and add it to the collection */
|
|
|
|
if (find_tcp_port_monitor(info.p_tcp_port_monitor_collection,
|
|
|
|
port_begin, port_end) == NULL) {
|
|
|
|
tcp_port_monitor_t *p_monitor = create_tcp_port_monitor(port_begin,
|
|
|
|
port_end, &tcp_port_monitor_args);
|
|
|
|
|
|
|
|
if (!p_monitor) {
|
|
|
|
CRIT_ERR("tcp_portmon: unable to create port monitor");
|
|
|
|
}
|
|
|
|
/* add the newly created monitor to the collection */
|
|
|
|
if (insert_tcp_port_monitor_into_collection(
|
|
|
|
info.p_tcp_port_monitor_collection, p_monitor) != 0) {
|
|
|
|
CRIT_ERR("tcp_portmon: unable to add port monitor to "
|
|
|
|
"collection");
|
|
|
|
}
|
2005-10-31 05:17:06 +00:00
|
|
|
}
|
2005-07-20 00:30:40 +00:00
|
|
|
#endif
|
2008-02-20 20:30:45 +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);
|
2008-06-03 20:46:15 +00:00
|
|
|
#ifdef NVIDIA
|
|
|
|
END OBJ(nvidia, 0)
|
|
|
|
if (!arg){
|
|
|
|
CRIT_ERR("nvidia needs one argument "
|
|
|
|
"[temp,threshold,gpufreq,memfreq,imagequality]");
|
|
|
|
} else {
|
|
|
|
if (strcmp(arg, "temp") == 0)
|
|
|
|
obj->data.nvidia.type = NV_TEMP;
|
|
|
|
else if (strcmp(arg, "threshold") == 0)
|
|
|
|
obj->data.nvidia.type = NV_TEMP_THRESHOLD;
|
|
|
|
else if (strcmp(arg, "gpufreq") == 0)
|
|
|
|
obj->data.nvidia.type = NV_GPU_FREQ;
|
|
|
|
else if (strcmp(arg, "memfreq") == 0)
|
|
|
|
obj->data.nvidia.type = NV_MEM_FREQ;
|
|
|
|
else if (strcmp(arg, "imagequality") == 0)
|
|
|
|
obj->data.nvidia.type = NV_IMAGE_QUALITY;
|
|
|
|
else
|
|
|
|
CRIT_ERR("you have to give one of these arguments "
|
|
|
|
"[temp,threshold,gpufreq,memfreq,imagequality");
|
|
|
|
strncpy((char*)&obj->data.nvidia.arg, arg, 20);
|
|
|
|
}
|
|
|
|
#endif /* NVIDIA */
|
2008-02-20 20:30:45 +00:00
|
|
|
END {
|
2005-07-20 00:30:40 +00:00
|
|
|
char buf[256];
|
2008-02-20 20:30:45 +00:00
|
|
|
|
2005-07-20 00:30:40 +00:00
|
|
|
ERR("unknown variable %s", s);
|
|
|
|
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);
|
2005-07-28 04:48:27 +00:00
|
|
|
}
|
2005-07-20 00:30:40 +00:00
|
|
|
#undef OBJ
|
2005-12-10 14:15:38 +00:00
|
|
|
|
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
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-03-29 03:45:36 +00:00
|
|
|
static struct text_object_list *extract_variable_text_internal(const char *const_p)
|
2005-12-10 14:15:38 +00:00
|
|
|
{
|
2006-01-28 01:28:23 +00:00
|
|
|
struct text_object_list *retval;
|
|
|
|
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-03-29 03:45:36 +00:00
|
|
|
|
2008-04-02 18:44:49 +00:00
|
|
|
p = strndup(const_p, max_user_text);
|
2008-03-29 04:41:37 +00:00
|
|
|
s = orig_p = p;
|
2006-01-28 01:28:23 +00:00
|
|
|
|
|
|
|
retval = malloc(sizeof(struct text_object_list));
|
|
|
|
memset(retval, 0, sizeof(struct text_object_list));
|
|
|
|
retval->text_object_count = 0;
|
|
|
|
|
2008-03-29 06:24:04 +00:00
|
|
|
line = 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++;
|
|
|
|
}
|
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) {
|
2006-01-28 01:28:23 +00:00
|
|
|
// allocate memory for the object
|
2008-02-20 20:30:45 +00:00
|
|
|
retval->text_objects = realloc(retval->text_objects,
|
|
|
|
sizeof(struct text_object) *
|
|
|
|
(retval->text_object_count + 1));
|
2006-01-28 01:28:23 +00:00
|
|
|
// assign the new object to the end of the list.
|
2008-02-20 20:30:45 +00:00
|
|
|
memcpy(&retval->text_objects[retval->text_object_count++], obj,
|
|
|
|
sizeof(struct text_object));
|
2006-01-28 01:28:23 +00:00
|
|
|
free(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;
|
|
|
|
|
|
|
|
var = getenv(buf);
|
|
|
|
|
2008-02-20 20:30:45 +00:00
|
|
|
/* if variable wasn't found in environment, use some special */
|
2005-07-20 00:30:40 +00:00
|
|
|
if (!var) {
|
2008-03-29 03:45:36 +00:00
|
|
|
char *tmp_p;
|
2005-07-20 00:30:40 +00:00
|
|
|
char *arg = 0;
|
|
|
|
|
|
|
|
/* split arg */
|
|
|
|
if (strchr(buf, ' ')) {
|
|
|
|
arg = strchr(buf, ' ');
|
|
|
|
*arg = '\0';
|
|
|
|
arg++;
|
2008-02-20 20:30:45 +00:00
|
|
|
while (isspace((int) *arg)) {
|
2005-07-20 00:30:40 +00:00
|
|
|
arg++;
|
2008-02-20 20:30:45 +00:00
|
|
|
}
|
|
|
|
if (!*arg) {
|
2005-07-20 00:30:40 +00:00
|
|
|
arg = 0;
|
2008-02-20 20:30:45 +00:00
|
|
|
}
|
2005-07-20 00:30:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* lowercase variable name */
|
2008-03-29 03:45:36 +00:00
|
|
|
tmp_p = buf;
|
|
|
|
while (*tmp_p) {
|
|
|
|
*tmp_p = tolower(*tmp_p);
|
|
|
|
tmp_p++;
|
2005-07-20 00:30:40 +00:00
|
|
|
}
|
|
|
|
|
2005-12-10 14:15:38 +00:00
|
|
|
// create new object
|
2008-02-20 20:30:45 +00:00
|
|
|
obj = construct_text_object(buf, arg,
|
|
|
|
retval->text_object_count, retval->text_objects, line);
|
|
|
|
if (obj != NULL) {
|
2006-01-28 01:28:23 +00:00
|
|
|
// allocate memory for the object
|
2008-02-20 20:30:45 +00:00
|
|
|
retval->text_objects = realloc(retval->text_objects,
|
|
|
|
sizeof(struct text_object) *
|
|
|
|
(retval->text_object_count + 1));
|
2006-01-28 01:28:23 +00:00
|
|
|
// assign the new object to the end of the list.
|
2008-02-20 20:30:45 +00:00
|
|
|
memcpy(
|
|
|
|
&retval->text_objects[retval->text_object_count++],
|
|
|
|
obj, sizeof(struct text_object));
|
2006-01-28 01:28:23 +00:00
|
|
|
free(obj);
|
2005-12-10 14:15:38 +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("$");
|
2008-02-20 20:30:45 +00:00
|
|
|
if (obj != NULL) {
|
2006-01-28 01:28:23 +00:00
|
|
|
// allocate memory for the object
|
2008-02-20 20:30:45 +00:00
|
|
|
retval->text_objects = realloc(retval->text_objects,
|
|
|
|
sizeof(struct text_object) *
|
|
|
|
(retval->text_object_count + 1));
|
2006-01-28 01:28:23 +00:00
|
|
|
// assign the new object to the end of the list.
|
|
|
|
memcpy(&retval->text_objects[retval->text_object_count++],
|
2008-02-20 20:30:45 +00:00
|
|
|
obj, sizeof(struct text_object));
|
2006-01-28 01:28:23 +00:00
|
|
|
free(obj);
|
|
|
|
}
|
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) {
|
2006-01-28 01:28:23 +00:00
|
|
|
// allocate memory for the object
|
|
|
|
retval->text_objects = realloc(retval->text_objects,
|
2008-02-20 20:30:45 +00:00
|
|
|
sizeof(struct text_object) * (retval->text_object_count + 1));
|
2006-01-28 01:28:23 +00:00
|
|
|
// assign the new object to the end of the list.
|
2008-02-20 20:30:45 +00:00
|
|
|
memcpy(&retval->text_objects[retval->text_object_count++], obj,
|
|
|
|
sizeof(struct text_object));
|
2006-01-28 01:28:23 +00:00
|
|
|
free(obj);
|
2005-12-10 14:15:38 +00:00
|
|
|
}
|
|
|
|
|
2005-08-06 04:46:16 +00:00
|
|
|
if (blockdepth) {
|
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);
|
2005-12-10 14:15:38 +00:00
|
|
|
return retval;
|
|
|
|
}
|
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
|
|
|
{
|
2006-01-28 01:28:23 +00:00
|
|
|
struct text_object_list *list;
|
2005-07-20 00:30:40 +00:00
|
|
|
|
2008-03-29 05:23:45 +00:00
|
|
|
free_text_objects(global_text_object_count, global_text_objects);
|
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;
|
|
|
|
}
|
2008-03-29 05:23:45 +00:00
|
|
|
global_text_object_count = 0;
|
|
|
|
global_text_objects = NULL;
|
2005-07-20 00:30:40 +00:00
|
|
|
|
2006-01-28 01:28:23 +00:00
|
|
|
list = extract_variable_text_internal(p);
|
2008-03-29 05:23:45 +00:00
|
|
|
global_text_objects = list->text_objects;
|
|
|
|
global_text_object_count = list->text_object_count;
|
2006-01-28 01:28:23 +00:00
|
|
|
|
|
|
|
free(list);
|
2005-12-10 14:15:38 +00:00
|
|
|
}
|
2005-07-20 00:30:40 +00:00
|
|
|
|
2008-03-29 09:58:09 +00:00
|
|
|
struct text_object_list *parse_conky_vars(char *txt, char *p, struct information *cur)
|
2008-02-20 20:30:45 +00:00
|
|
|
{
|
|
|
|
struct text_object_list *object_list =
|
2008-03-29 09:58:09 +00:00
|
|
|
extract_variable_text_internal(txt);
|
2008-02-20 20:30:45 +00:00
|
|
|
|
2008-03-20 21:28:19 +00:00
|
|
|
generate_text_internal(p, max_user_text, object_list->text_objects,
|
2008-02-20 20:30:45 +00:00
|
|
|
object_list->text_object_count, cur);
|
2008-03-20 20:33:31 +00:00
|
|
|
return object_list;
|
2005-12-10 21:07:24 +00:00
|
|
|
}
|
2005-07-20 00:30:40 +00:00
|
|
|
|
2008-02-20 20:30:45 +00:00
|
|
|
/* Allows reading from a FIFO (i.e., /dev/xconsole).
|
|
|
|
* The file descriptor is set to non-blocking which makes this possible.
|
2007-09-28 20:16:16 +00:00
|
|
|
*
|
2008-02-20 20:30:45 +00:00
|
|
|
* FIXME: Since lseek cannot seek a file descriptor long lines will break. */
|
2007-09-28 20:16:16 +00:00
|
|
|
static void tail_pipe(struct text_object *obj, char *dst, size_t dst_size)
|
|
|
|
{
|
|
|
|
#define TAIL_PIPE_BUFSIZE 4096
|
2008-02-20 20:30:45 +00:00
|
|
|
int lines = 0;
|
|
|
|
int line_len = 0;
|
|
|
|
int last_line = 0;
|
|
|
|
int fd = obj->data.tail.fd;
|
2007-09-28 20:16:16 +00:00
|
|
|
|
2008-02-20 20:30:45 +00:00
|
|
|
while (1) {
|
|
|
|
char buf[TAIL_PIPE_BUFSIZE];
|
|
|
|
ssize_t len = read(fd, buf, sizeof(buf));
|
|
|
|
int i;
|
2007-09-28 20:16:16 +00:00
|
|
|
|
2008-02-20 20:30:45 +00:00
|
|
|
if (len == -1) {
|
|
|
|
if (errno != EAGAIN) {
|
|
|
|
strcpy(obj->data.tail.buffer, "Logfile Read Error");
|
|
|
|
snprintf(dst, dst_size, "Logfile Read Error");
|
|
|
|
}
|
2007-09-28 20:16:16 +00:00
|
|
|
|
2008-02-20 20:30:45 +00:00
|
|
|
break;
|
|
|
|
} else if (len == 0) {
|
|
|
|
strcpy(obj->data.tail.buffer, "Logfile Empty");
|
|
|
|
snprintf(dst, dst_size, "Logfile Empty");
|
|
|
|
break;
|
|
|
|
}
|
2007-09-28 20:16:16 +00:00
|
|
|
|
2008-02-20 20:30:45 +00:00
|
|
|
for (line_len = 0, i = 0; i < len; i++) {
|
|
|
|
int pos = 0;
|
|
|
|
char *p;
|
2007-09-28 20:16:16 +00:00
|
|
|
|
2008-02-20 20:30:45 +00:00
|
|
|
if (buf[i] == '\n') {
|
|
|
|
lines++;
|
2007-09-28 20:16:16 +00:00
|
|
|
|
2008-02-20 20:30:45 +00:00
|
|
|
if (obj->data.tail.readlines > 0) {
|
|
|
|
int n;
|
|
|
|
int olines = 0;
|
|
|
|
int first_line = 0;
|
2007-09-28 20:16:16 +00:00
|
|
|
|
2008-02-20 20:30:45 +00:00
|
|
|
for (n = 0; obj->data.tail.buffer[n]; n++) {
|
|
|
|
if (obj->data.tail.buffer[n] == '\n') {
|
|
|
|
if (!first_line) {
|
|
|
|
first_line = n + 1;
|
|
|
|
}
|
2007-09-28 20:16:16 +00:00
|
|
|
|
2008-02-20 20:30:45 +00:00
|
|
|
if (++olines < obj->data.tail.wantedlines) {
|
|
|
|
pos = n + 1;
|
|
|
|
continue;
|
|
|
|
}
|
2007-09-28 20:16:16 +00:00
|
|
|
|
2008-02-20 20:30:45 +00:00
|
|
|
n++;
|
|
|
|
p = obj->data.tail.buffer + first_line;
|
|
|
|
pos = n - first_line;
|
|
|
|
memmove(obj->data.tail.buffer,
|
|
|
|
obj->data.tail.buffer + first_line, strlen(p));
|
|
|
|
obj->data.tail.buffer[pos] = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-09-28 20:16:16 +00:00
|
|
|
|
2008-02-20 20:30:45 +00:00
|
|
|
p = buf + last_line;
|
|
|
|
line_len++;
|
|
|
|
memcpy(&(obj->data.tail.buffer[pos]), p, line_len);
|
|
|
|
obj->data.tail.buffer[pos + line_len] = 0;
|
|
|
|
last_line = i + 1;
|
|
|
|
line_len = 0;
|
|
|
|
obj->data.tail.readlines = lines;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
line_len++;
|
|
|
|
}
|
2007-09-28 20:16:16 +00:00
|
|
|
}
|
|
|
|
|
2008-02-20 20:30:45 +00:00
|
|
|
snprintf(dst, dst_size, "%s", obj->data.tail.buffer);
|
2007-09-28 20:16:16 +00:00
|
|
|
}
|
|
|
|
|
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-02-20 20:30:45 +00:00
|
|
|
static void generate_text_internal(char *p, int p_max_size,
|
|
|
|
struct text_object *objs, unsigned int object_count,
|
|
|
|
struct information *cur)
|
2005-12-10 14:15:38 +00:00
|
|
|
{
|
2006-01-28 01:28:23 +00:00
|
|
|
unsigned int i;
|
2006-05-13 19:51:26 +00:00
|
|
|
|
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
|
|
|
|
|
2005-12-10 14:15:38 +00:00
|
|
|
for (i = 0; i < object_count; i++) {
|
|
|
|
struct text_object *obj = &objs[i];
|
2005-07-20 00:30:40 +00:00
|
|
|
|
2008-03-20 20:56:13 +00:00
|
|
|
if (p_max_size < 1) {
|
|
|
|
break;
|
|
|
|
};
|
|
|
|
|
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-02-20 20:30:45 +00:00
|
|
|
OBJ(acpitemp) {
|
|
|
|
/* does anyone have decimals in acpi temperature? */
|
|
|
|
spaced_print(p, p_max_size, "%d", 5, "acpitemp",
|
|
|
|
round_to_int(get_acpi_temperature(obj->data.i)));
|
|
|
|
}
|
|
|
|
OBJ(acpitempf) {
|
|
|
|
/* does anyone have decimals in acpi temperature? */
|
|
|
|
spaced_print(p, p_max_size, "%d", 5, "acpitemp",
|
|
|
|
round_to_int((get_acpi_temperature(obj->data.i) + 40) *
|
|
|
|
9.0 / 5 - 40));
|
|
|
|
}
|
2007-08-10 21:14:06 +00:00
|
|
|
#endif /* !__OpenBSD__ */
|
2008-02-20 20:30:45 +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-02-20 20:30:45 +00:00
|
|
|
}
|
|
|
|
OBJ(freq_g) {
|
|
|
|
if (obj->a) {
|
2007-09-17 04:40:13 +00:00
|
|
|
#ifndef __OpenBSD__
|
2008-02-20 20:30:45 +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-02-20 20:30:45 +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-02-20 20:30:45 +00:00
|
|
|
}
|
2006-08-01 21:24:15 +00:00
|
|
|
#if defined(__linux__)
|
2008-02-20 20:30:45 +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-02-20 20:30:45 +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-02-20 20:30:45 +00:00
|
|
|
}
|
|
|
|
|
2007-08-07 12:51:08 +00:00
|
|
|
#ifdef HAVE_IWLIB
|
2008-02-20 20:30:45 +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) {
|
|
|
|
spaced_print(p, p_max_size, "%d", 4, "wireless_link_qual",
|
|
|
|
obj->data.net->link_qual);
|
|
|
|
}
|
|
|
|
OBJ(wireless_link_qual_max) {
|
|
|
|
spaced_print(p, p_max_size, "%d", 4,
|
|
|
|
"wireless_link_qual_max", obj->data.net->link_qual_max);
|
|
|
|
}
|
|
|
|
OBJ(wireless_link_qual_perc) {
|
|
|
|
if (obj->data.net->link_qual_max > 0) {
|
2008-03-18 00:23:16 +00:00
|
|
|
spaced_print(p, p_max_size, "%.0f", 5,
|
2008-02-20 20:30:45 +00:00
|
|
|
"wireless_link_qual_perc",
|
|
|
|
(double) obj->data.net->link_qual /
|
|
|
|
obj->data.net->link_qual_max * 100);
|
|
|
|
} else {
|
|
|
|
spaced_print(p, p_max_size, "unk", 5,
|
|
|
|
"wireless_link_qual_perc");
|
2007-08-07 12:51:08 +00:00
|
|
|
}
|
2008-02-20 20:30:45 +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
|
|
|
|
2008-02-20 20:30:45 +00:00
|
|
|
OBJ(freq_dyn) {
|
|
|
|
get_freq_dynamic(p, p_max_size, "%.0f", 1);
|
|
|
|
spaced_print(p, p_max_size, "%s", 6, "freq_dyn", p);
|
|
|
|
}
|
|
|
|
OBJ(freq_dyn_g) {
|
2007-09-17 04:40:13 +00:00
|
|
|
#ifndef __OpenBSD__
|
2008-02-20 20:30:45 +00:00
|
|
|
get_freq_dynamic(p, p_max_size, "%'.2f", 1000);
|
2007-09-17 04:40:13 +00:00
|
|
|
#else
|
2008-02-20 20:30:45 +00:00
|
|
|
get_freq_dynamic(p, p_max_size, "%.2f", 1000);
|
2007-09-17 04:40:13 +00:00
|
|
|
#endif
|
2008-02-20 20:30:45 +00:00
|
|
|
spaced_print(p, p_max_size, "%s", 6, "freq_dyn", p);
|
|
|
|
}
|
|
|
|
|
2007-08-10 21:14:06 +00:00
|
|
|
#ifndef __OpenBSD__
|
2008-02-20 20:30:45 +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) {
|
2008-03-28 23:23:21 +00:00
|
|
|
spaced_print(p, p_max_size, "%*d", 4, "battery_percent",
|
|
|
|
pad_percents, get_battery_perct(obj->data.s));
|
2008-02-20 20:30:45 +00:00
|
|
|
}
|
|
|
|
OBJ(battery_bar) {
|
|
|
|
new_bar(p, obj->a, obj->b, get_battery_perct_bar(obj->data.s));
|
|
|
|
}
|
2007-08-10 21:06:30 +00:00
|
|
|
#endif /* __OpenBSD__ */
|
2008-02-20 20:30:45 +00:00
|
|
|
|
|
|
|
OBJ(buffers) {
|
|
|
|
human_readable(cur->buffers * 1024, p, 255, "buffers");
|
|
|
|
}
|
|
|
|
OBJ(cached) {
|
|
|
|
human_readable(cur->cached * 1024, p, 255, "buffers");
|
|
|
|
}
|
|
|
|
OBJ(cpu) {
|
|
|
|
if (obj->data.cpu_index > info.cpu_count) {
|
|
|
|
printf("obj->data.cpu_index %i info.cpu_count %i",
|
|
|
|
obj->data.cpu_index, info.cpu_count);
|
2008-04-13 04:10:35 +00:00
|
|
|
CRIT_ERR("attempting to use more CPUs than you have!");
|
2007-04-25 17:22:06 +00:00
|
|
|
}
|
2008-02-20 20:30:45 +00:00
|
|
|
spaced_print(p, p_max_size, "%*d", 4, "cpu", pad_percents,
|
|
|
|
round_to_int(cur->cpu_usage[obj->data.cpu_index] * 100.0));
|
|
|
|
}
|
|
|
|
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);
|
|
|
|
}
|
2008-04-13 04:10:35 +00:00
|
|
|
OBJ(loadgraph) {
|
|
|
|
new_graph(p, obj->a, obj->b, obj->c, obj->d, cur->loadavg[0],
|
|
|
|
obj->e, 1);
|
|
|
|
}
|
2008-02-20 20:30:45 +00:00
|
|
|
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);
|
|
|
|
}
|
2008-03-18 00:23:16 +00:00
|
|
|
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-03-24 20:08:16 +00:00
|
|
|
OBJ(disk_protect) {
|
|
|
|
snprintf(p, p_max_size, "%s",
|
|
|
|
get_disk_protect_queue(obj->data.s));
|
|
|
|
}
|
2008-02-20 20:30:45 +00:00
|
|
|
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) {
|
|
|
|
snprintf(p, p_max_size, "%s", i8k.cpu_temp);
|
|
|
|
}
|
|
|
|
OBJ(i8k_cpu_tempf) {
|
|
|
|
int cpu_temp;
|
|
|
|
|
|
|
|
sscanf(i8k.cpu_temp, "%d", &cpu_temp);
|
|
|
|
snprintf(p, p_max_size, "%.1f", cpu_temp * (9.0 / 5.0) + 32.0);
|
|
|
|
}
|
|
|
|
OBJ(i8k_left_fan_status) {
|
|
|
|
int left_fan_status;
|
2005-08-27 07:15:44 +00:00
|
|
|
|
2008-02-20 20:30:45 +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-02-20 20:30:45 +00:00
|
|
|
if (left_fan_status == 1) {
|
|
|
|
snprintf(p, p_max_size, "low");
|
2005-08-27 07:15:44 +00:00
|
|
|
}
|
2008-02-20 20:30:45 +00:00
|
|
|
if (left_fan_status == 2) {
|
|
|
|
snprintf(p, p_max_size, "high");
|
2006-01-28 01:28:23 +00:00
|
|
|
}
|
2008-02-20 20:30:45 +00:00
|
|
|
}
|
|
|
|
OBJ(i8k_right_fan_status) {
|
|
|
|
int right_fan_status;
|
2005-08-27 07:15:44 +00:00
|
|
|
|
2008-02-20 20:30:45 +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-02-20 20:30:45 +00:00
|
|
|
if (right_fan_status == 1) {
|
|
|
|
snprintf(p, p_max_size, "low");
|
2007-03-01 01:43:43 +00:00
|
|
|
}
|
2008-02-20 20:30:45 +00:00
|
|
|
if (right_fan_status == 2) {
|
|
|
|
snprintf(p, p_max_size, "high");
|
2007-03-01 01:43:43 +00:00
|
|
|
}
|
2008-02-20 20:30:45 +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;
|
2007-03-01 01:43:43 +00:00
|
|
|
|
2008-02-20 20:30:45 +00:00
|
|
|
sscanf(i8k.ac_status, "%d", &ac_status);
|
|
|
|
if (ac_status == -1) {
|
|
|
|
snprintf(p, p_max_size, "disabled (read i8k docs)");
|
2007-03-01 01:43:43 +00:00
|
|
|
}
|
2008-02-20 20:30:45 +00:00
|
|
|
if (ac_status == 0) {
|
|
|
|
snprintf(p, p_max_size, "off");
|
2007-03-01 01:43:43 +00:00
|
|
|
}
|
2008-02-20 20:30:45 +00:00
|
|
|
if (ac_status == 1) {
|
|
|
|
snprintf(p, p_max_size, "on");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
OBJ(i8k_buttons_status) {
|
|
|
|
snprintf(p, p_max_size, "%s", i8k.buttons_status);
|
|
|
|
}
|
|
|
|
OBJ(ibm_fan) {
|
|
|
|
get_ibm_acpi_fan(p, p_max_size);
|
|
|
|
}
|
|
|
|
OBJ(ibm_temps) {
|
|
|
|
get_ibm_acpi_temps();
|
|
|
|
snprintf(p, p_max_size, "%d", ibm_acpi.temps[obj->data.sensor]);
|
|
|
|
}
|
|
|
|
OBJ(ibm_volume) {
|
|
|
|
get_ibm_acpi_volume(p, p_max_size);
|
|
|
|
}
|
|
|
|
OBJ(ibm_brightness) {
|
|
|
|
get_ibm_acpi_brightness(p, p_max_size);
|
|
|
|
}
|
2008-03-18 00:23:16 +00:00
|
|
|
OBJ(if_up) {
|
|
|
|
if ((obj->data.ifblock.s)
|
|
|
|
&& (!interface_up(obj->data.ifblock.s))) {
|
|
|
|
i = obj->data.ifblock.pos;
|
|
|
|
if_jumped = 1;
|
|
|
|
} else {
|
|
|
|
if_jumped = 0;
|
|
|
|
}
|
|
|
|
}
|
2008-03-22 19:06:09 +00:00
|
|
|
OBJ(if_gw) {
|
|
|
|
if (!cur->gw_info.count) {
|
|
|
|
i = obj->data.ifblock.pos;
|
|
|
|
if_jumped = 1;
|
|
|
|
} else {
|
|
|
|
if_jumped = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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);
|
|
|
|
}
|
2008-03-22 20:13:51 +00:00
|
|
|
OBJ(laptop_mode) {
|
|
|
|
snprintf(p, p_max_size, "%d", get_laptop_mode());
|
|
|
|
}
|
2008-02-20 20:30:45 +00:00
|
|
|
OBJ(pb_battery) {
|
|
|
|
get_powerbook_batt_info(p, p_max_size, obj->data.i);
|
|
|
|
}
|
|
|
|
#endif /* __linux__ */
|
|
|
|
|
|
|
|
#ifdef __OpenBSD__
|
|
|
|
OBJ(obsd_sensors_temp) {
|
|
|
|
obsd_sensors.device = sensor_device;
|
|
|
|
update_obsd_sensors();
|
|
|
|
snprintf(p, p_max_size, "%.1f",
|
|
|
|
obsd_sensors.temp[obsd_sensors.device][obj->data.sensor]);
|
|
|
|
}
|
|
|
|
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__ */
|
|
|
|
|
2007-11-14 21:41:08 +00:00
|
|
|
#ifdef X11
|
2008-02-20 20:30:45 +00:00
|
|
|
OBJ(font) {
|
|
|
|
new_font(p, obj->data.s);
|
|
|
|
}
|
2007-11-14 21:41:08 +00:00
|
|
|
#endif
|
2008-02-20 20:30:45 +00:00
|
|
|
/* TODO: move this correction from kB to kB/s elsewhere
|
|
|
|
* (or get rid of it??) */
|
|
|
|
OBJ(diskio) {
|
|
|
|
if (obj->data.diskio) {
|
|
|
|
human_readable(
|
|
|
|
(obj->data.diskio->current / update_interval) * 1024LL,
|
|
|
|
p, p_max_size, "diskio");
|
|
|
|
} else {
|
|
|
|
human_readable(diskio_value * 1024LL, p, p_max_size,
|
|
|
|
"diskio");
|
2008-02-09 02:21:06 +00:00
|
|
|
}
|
2008-02-20 20:30:45 +00:00
|
|
|
}
|
|
|
|
OBJ(diskio_write) {
|
|
|
|
if (obj->data.diskio) {
|
|
|
|
human_readable((obj->data.diskio->current_write / update_interval) * 1024LL, p, p_max_size,
|
|
|
|
"diskio_write");
|
|
|
|
} else {
|
|
|
|
human_readable(diskio_write_value * 1024LL, p, p_max_size,
|
|
|
|
"diskio_write");
|
2008-02-09 02:21:06 +00:00
|
|
|
}
|
2008-02-20 20:30:45 +00:00
|
|
|
}
|
|
|
|
OBJ(diskio_read) {
|
|
|
|
if (obj->data.diskio) {
|
|
|
|
human_readable((obj->data.diskio->current_read / update_interval) * 1024LL, p, p_max_size,
|
|
|
|
"diskio_read");
|
|
|
|
} else {
|
|
|
|
human_readable(diskio_read_value * 1024LL, p, p_max_size,
|
|
|
|
"diskio_read");
|
2006-01-28 01:28:23 +00:00
|
|
|
}
|
2008-02-20 20:30:45 +00:00
|
|
|
}
|
|
|
|
OBJ(diskiograph) {
|
|
|
|
if (obj->data.diskio) {
|
|
|
|
new_graph(p, obj->a, obj->b, obj->c, obj->d,
|
|
|
|
obj->data.diskio->current, obj->e, 1);
|
|
|
|
} else {
|
|
|
|
new_graph(p, obj->a, obj->b, obj->c, obj->d, diskio_value,
|
|
|
|
obj->e, 1);
|
2006-01-28 01:28:23 +00:00
|
|
|
}
|
2008-02-20 20:30:45 +00:00
|
|
|
}
|
|
|
|
OBJ(diskiograph_read) {
|
|
|
|
if (obj->data.diskio) {
|
|
|
|
new_graph(p, obj->a, obj->b, obj->c, obj->d,
|
|
|
|
obj->data.diskio->current_read, obj->e, 1);
|
|
|
|
} else {
|
2006-01-28 01:28:23 +00:00
|
|
|
new_graph(p, obj->a, obj->b, obj->c, obj->d,
|
2008-02-20 20:30:45 +00:00
|
|
|
diskio_read_value, obj->e, 1);
|
2006-01-28 01:28:23 +00:00
|
|
|
}
|
2008-02-20 20:30:45 +00:00
|
|
|
}
|
|
|
|
OBJ(diskiograph_write) {
|
|
|
|
if (obj->data.diskio) {
|
|
|
|
new_graph(p, obj->a, obj->b, obj->c, obj->d,
|
|
|
|
obj->data.diskio->current_write, obj->e, 1);
|
|
|
|
} else {
|
|
|
|
new_graph(p, obj->a, obj->b, obj->c, obj->d,
|
|
|
|
diskio_write_value, obj->e, 1);
|
2005-08-26 02:16:35 +00:00
|
|
|
}
|
2008-02-20 20:30:45 +00:00
|
|
|
}
|
|
|
|
OBJ(downspeed) {
|
|
|
|
spaced_print(p, p_max_size, "%d", 6, "downspeed",
|
|
|
|
round_to_int(obj->data.net->recv_speed / 1024));
|
|
|
|
}
|
|
|
|
OBJ(downspeedf) {
|
|
|
|
spaced_print(p, p_max_size, "%.1f", 8, "downspeedf",
|
|
|
|
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(else) {
|
|
|
|
if (!if_jumped) {
|
|
|
|
i = obj->data.ifblock.pos - 1;
|
|
|
|
} else {
|
2005-07-28 04:48:27 +00:00
|
|
|
if_jumped = 0;
|
|
|
|
}
|
2008-02-20 20:30:45 +00:00
|
|
|
}
|
|
|
|
OBJ(endif) {
|
|
|
|
if_jumped = 0;
|
|
|
|
}
|
2005-07-20 00:30:40 +00:00
|
|
|
#ifdef HAVE_POPEN
|
2008-02-20 20:30:45 +00:00
|
|
|
OBJ(addr) {
|
|
|
|
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-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
|
|
|
|
|
|
|
OBJ(exec) {
|
|
|
|
FILE *fp = popen(obj->data.s, "r");
|
|
|
|
int length = fread(p, 1, p_max_size, fp);
|
|
|
|
|
|
|
|
pclose(fp);
|
2008-03-22 22:58:26 +00:00
|
|
|
|
2008-02-20 20:30:45 +00:00
|
|
|
p[length] = '\0';
|
2008-06-04 08:51:15 +00:00
|
|
|
remove_deleted_chars(p);
|
2008-02-20 20:30:45 +00:00
|
|
|
if (length > 0 && p[length - 1] == '\n') {
|
|
|
|
p[length - 1] = '\0';
|
|
|
|
}
|
2008-03-20 20:33:31 +00:00
|
|
|
}
|
|
|
|
OBJ(execp) {
|
2008-03-29 06:24:04 +00:00
|
|
|
FILE *fp;
|
|
|
|
struct information *my_info;
|
|
|
|
struct text_object_list *text_objects;
|
|
|
|
int length;
|
2008-03-20 20:33:31 +00:00
|
|
|
|
2008-03-29 06:24:04 +00:00
|
|
|
fp = popen(obj->data.s, "r");
|
|
|
|
fread(p, 1, p_max_size, fp);
|
2008-03-20 20:33:31 +00:00
|
|
|
pclose(fp);
|
2008-03-22 22:58:26 +00:00
|
|
|
|
2008-03-29 06:24:04 +00:00
|
|
|
my_info = malloc(sizeof(struct information));
|
2008-03-20 20:33:31 +00:00
|
|
|
memcpy(my_info, cur, sizeof(struct information));
|
2008-03-29 06:24:04 +00:00
|
|
|
text_objects = parse_conky_vars(p, p, my_info);
|
2008-03-20 20:33:31 +00:00
|
|
|
|
2008-03-29 06:24:04 +00:00
|
|
|
length = strlen(p);
|
2008-03-22 22:58:26 +00:00
|
|
|
|
2008-03-20 20:33:31 +00:00
|
|
|
p[length] = '\0';
|
|
|
|
if (length > 0 && p[length - 1] == '\n') {
|
|
|
|
p[length - 1] = '\0';
|
|
|
|
}
|
2008-03-22 22:58:26 +00:00
|
|
|
|
2008-03-20 20:33:31 +00:00
|
|
|
free_text_objects(text_objects->text_object_count, text_objects->text_objects);
|
|
|
|
free(text_objects);
|
|
|
|
free(my_info);
|
2008-02-20 20:30:45 +00:00
|
|
|
}
|
|
|
|
OBJ(execbar) {
|
|
|
|
char *p2 = p;
|
|
|
|
FILE *fp = popen(obj->data.s, "r");
|
|
|
|
int n2 = fread(p, 1, p_max_size, fp);
|
2008-03-29 06:24:04 +00:00
|
|
|
double barnum;
|
2008-02-20 20:30:45 +00:00
|
|
|
|
|
|
|
pclose(fp);
|
|
|
|
p[n2] = '\0';
|
|
|
|
if (n2 && p[n2 - 1] == '\n') {
|
|
|
|
p[n2 - 1] = '\0';
|
|
|
|
}
|
|
|
|
|
|
|
|
while (*p2) {
|
|
|
|
if (*p2 == '\001') {
|
|
|
|
*p2 = ' ';
|
|
|
|
}
|
|
|
|
p2++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sscanf(p, "%lf", &barnum) == 0) {
|
|
|
|
ERR("reading execbar value failed (perhaps it's not the "
|
|
|
|
"correct format?)");
|
|
|
|
}
|
|
|
|
if (barnum > 100 || barnum < 0) {
|
|
|
|
ERR("your execbar value is not between 0 and 100, "
|
|
|
|
"therefore it will be ignored");
|
|
|
|
} else {
|
|
|
|
barnum = barnum / 100.0;
|
|
|
|
new_bar(p, 0, 4, (int) (barnum * 255.0));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
OBJ(execgraph) {
|
|
|
|
char *p2 = p;
|
|
|
|
FILE *fp = popen(obj->data.s, "r");
|
|
|
|
int n2 = fread(p, 1, p_max_size, fp);
|
2008-03-29 06:24:04 +00:00
|
|
|
double barnum;
|
2008-02-20 20:30:45 +00:00
|
|
|
|
|
|
|
pclose(fp);
|
|
|
|
p[n2] = '\0';
|
|
|
|
if (n2 && p[n2 - 1] == '\n') {
|
|
|
|
p[n2 - 1] = '\0';
|
|
|
|
}
|
|
|
|
while (*p2) {
|
|
|
|
if (*p2 == '\001') {
|
|
|
|
*p2 = ' ';
|
2005-12-15 04:13:32 +00:00
|
|
|
}
|
2008-02-20 20:30:45 +00:00
|
|
|
p2++;
|
|
|
|
}
|
2005-07-28 06:56:55 +00:00
|
|
|
|
2008-02-20 20:30:45 +00:00
|
|
|
if (sscanf(p, "%lf", &barnum) == 0) {
|
|
|
|
ERR("reading execgraph value failed (perhaps it's not the "
|
|
|
|
"correct format?)");
|
|
|
|
}
|
|
|
|
if (barnum > 100 || barnum < 0) {
|
|
|
|
ERR("your execgraph value is not between 0 and 100, "
|
|
|
|
"therefore it will be ignored");
|
|
|
|
} else {
|
|
|
|
new_graph(p, 0, 25, obj->c, obj->d, (int) (barnum),
|
|
|
|
obj->e, 1);
|
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
|
|
|
|
< obj->data.execi.interval) {
|
|
|
|
new_bar(p, 0, 4, (int) obj->f);
|
|
|
|
} else {
|
2005-08-23 03:00:50 +00:00
|
|
|
char *p2 = p;
|
2008-02-20 20:30:45 +00:00
|
|
|
FILE *fp = popen(obj->data.execi.cmd, "r");
|
2005-12-10 14:15:38 +00:00
|
|
|
int n2 = fread(p, 1, p_max_size, fp);
|
2008-03-29 06:24:04 +00:00
|
|
|
float barnum;
|
2006-01-28 01:28:23 +00:00
|
|
|
|
2008-02-20 20:30:45 +00:00
|
|
|
pclose(fp);
|
2005-08-23 03:00:50 +00:00
|
|
|
p[n2] = '\0';
|
2008-02-20 20:30:45 +00:00
|
|
|
if (n2 && p[n2 - 1] == '\n') {
|
2005-08-23 03:00:50 +00:00
|
|
|
p[n2 - 1] = '\0';
|
2008-02-20 20:30:45 +00:00
|
|
|
}
|
2005-08-23 03:00:50 +00:00
|
|
|
|
|
|
|
while (*p2) {
|
2008-02-20 20:30:45 +00:00
|
|
|
if (*p2 == '\001') {
|
2005-08-23 03:00:50 +00:00
|
|
|
*p2 = ' ';
|
2008-02-20 20:30:45 +00:00
|
|
|
}
|
2005-08-23 03:00:50 +00:00
|
|
|
p2++;
|
|
|
|
}
|
2008-02-20 20:30:45 +00:00
|
|
|
|
|
|
|
if (sscanf(p, "%f", &barnum) == 0) {
|
|
|
|
ERR("reading execibar value failed (perhaps it's not "
|
|
|
|
"the correct format?)");
|
2005-08-23 03:00:50 +00:00
|
|
|
}
|
|
|
|
if (barnum > 100 || barnum < 0) {
|
2008-02-20 20:30:45 +00:00
|
|
|
ERR("your execibar value is not between 0 and 100, "
|
|
|
|
"therefore it will be ignored");
|
2005-08-23 03:00:50 +00:00
|
|
|
} else {
|
2008-02-20 20:30:45 +00:00
|
|
|
obj->f = 255 * barnum / 100.0;
|
|
|
|
new_bar(p, 0, 4, (int) obj->f);
|
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
|
|
|
}
|
2008-02-20 20:30:45 +00:00
|
|
|
}
|
|
|
|
OBJ(execigraph) {
|
|
|
|
if (current_update_time - obj->data.execi.last_update
|
|
|
|
< obj->data.execi.interval) {
|
|
|
|
new_graph(p, 0, 25, obj->c, obj->d, (int) (obj->f), 100, 0);
|
|
|
|
} else {
|
2005-08-23 03:00:50 +00:00
|
|
|
char *p2 = p;
|
2008-02-20 20:30:45 +00:00
|
|
|
FILE *fp = popen(obj->data.execi.cmd, "r");
|
2005-12-10 14:15:38 +00:00
|
|
|
int n2 = fread(p, 1, p_max_size, fp);
|
2008-03-29 06:24:04 +00:00
|
|
|
float barnum;
|
2006-01-28 01:28:23 +00:00
|
|
|
|
2008-02-20 20:30:45 +00:00
|
|
|
pclose(fp);
|
2005-08-23 03:00:50 +00:00
|
|
|
p[n2] = '\0';
|
2008-02-20 20:30:45 +00:00
|
|
|
if (n2 && p[n2 - 1] == '\n') {
|
2005-08-23 03:00:50 +00:00
|
|
|
p[n2 - 1] = '\0';
|
2008-02-20 20:30:45 +00:00
|
|
|
}
|
2005-08-23 03:00:50 +00:00
|
|
|
|
|
|
|
while (*p2) {
|
2008-02-20 20:30:45 +00:00
|
|
|
if (*p2 == '\001') {
|
2005-08-23 03:00:50 +00:00
|
|
|
*p2 = ' ';
|
2008-02-20 20:30:45 +00:00
|
|
|
}
|
2005-08-23 03:00:50 +00:00
|
|
|
p2++;
|
|
|
|
}
|
2008-02-20 20:30:45 +00:00
|
|
|
|
|
|
|
if (sscanf(p, "%f", &barnum) == 0) {
|
|
|
|
ERR("reading execigraph value failed (perhaps it's not "
|
|
|
|
"the correct format?)");
|
2005-08-23 03:00:50 +00:00
|
|
|
}
|
|
|
|
if (barnum > 100 || barnum < 0) {
|
2008-02-20 20:30:45 +00:00
|
|
|
ERR("your execigraph value is not between 0 and 100, "
|
|
|
|
"therefore it will be ignored");
|
2005-08-23 03:00:50 +00:00
|
|
|
} else {
|
2008-02-20 20:30:45 +00:00
|
|
|
obj->f = barnum;
|
|
|
|
new_graph(p, 0, 25, obj->c, obj->d, (int) (obj->f),
|
|
|
|
100, 1);
|
2006-01-28 01:28:23 +00:00
|
|
|
}
|
2008-02-20 20:30:45 +00:00
|
|
|
obj->data.execi.last_update = current_update_time;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
OBJ(execi) {
|
|
|
|
if (current_update_time - obj->data.execi.last_update
|
|
|
|
< obj->data.execi.interval
|
|
|
|
|| obj->data.execi.interval == 0) {
|
|
|
|
snprintf(p, p_max_size, "%s", obj->data.execi.buffer);
|
|
|
|
} else {
|
|
|
|
char *output = obj->data.execi.buffer;
|
|
|
|
FILE *fp = popen(obj->data.execi.cmd, "r");
|
2006-01-28 01:28:23 +00:00
|
|
|
|
2008-03-20 21:28:19 +00:00
|
|
|
int length = fread(output, 1, text_buffer_size, fp);
|
2008-02-20 20:30:45 +00:00
|
|
|
|
|
|
|
pclose(fp);
|
|
|
|
output[length] = '\0';
|
|
|
|
if (length > 0 && output[length - 1] == '\n') {
|
|
|
|
output[length - 1] = '\0';
|
|
|
|
}
|
|
|
|
obj->data.execi.last_update = current_update_time;
|
|
|
|
snprintf(p, p_max_size, "%s", output);
|
|
|
|
}
|
|
|
|
// parse_conky_vars(output, p, cur);
|
|
|
|
}
|
2008-03-22 06:10:54 +00:00
|
|
|
OBJ(execpi) {
|
2008-03-29 06:24:04 +00:00
|
|
|
struct text_object_list *text_objects = 0;
|
2008-03-22 06:10:54 +00:00
|
|
|
struct information *my_info =
|
|
|
|
malloc(sizeof(struct information));
|
|
|
|
memcpy(my_info, cur, sizeof(struct information));
|
|
|
|
|
|
|
|
if (current_update_time - obj->data.execi.last_update
|
|
|
|
< obj->data.execi.interval
|
|
|
|
|| obj->data.execi.interval == 0) {
|
|
|
|
text_objects = parse_conky_vars(obj->data.execi.buffer, p, my_info);
|
|
|
|
} 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';
|
|
|
|
}
|
|
|
|
|
|
|
|
text_objects = parse_conky_vars(obj->data.execi.buffer, p, my_info);
|
|
|
|
obj->data.execi.last_update = current_update_time;
|
|
|
|
}
|
|
|
|
free_text_objects(text_objects->text_object_count, text_objects->text_objects);
|
|
|
|
free(text_objects);
|
|
|
|
free(my_info);
|
|
|
|
}
|
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");
|
|
|
|
}
|
2006-01-28 01:28:23 +00:00
|
|
|
}
|
2008-02-20 20:30:45 +00:00
|
|
|
timed_thread_lock(obj->data.texeci.p_timed_thread);
|
|
|
|
snprintf(p, p_max_size, "%s", obj->data.texeci.buffer);
|
|
|
|
timed_thread_unlock(obj->data.texeci.p_timed_thread);
|
|
|
|
}
|
|
|
|
#endif /* HAVE_POPEN */
|
|
|
|
OBJ(imap_unseen) {
|
|
|
|
if (obj->global_mode && info.mail) {
|
|
|
|
// this means we use info
|
|
|
|
if (!info.mail->p_timed_thread) {
|
|
|
|
info.mail->p_timed_thread =
|
2008-03-29 05:14:35 +00:00
|
|
|
timed_thread_create(&imap_thread,
|
2008-02-20 20:30:45 +00:00
|
|
|
(void *) info.mail, info.mail->interval * 1000000);
|
|
|
|
if (!info.mail->p_timed_thread) {
|
|
|
|
ERR("Error creating imap timed thread");
|
2006-01-28 01:28:23 +00:00
|
|
|
}
|
2008-02-20 20:30:45 +00:00
|
|
|
timed_thread_register(info.mail->p_timed_thread,
|
|
|
|
&info.mail->p_timed_thread);
|
|
|
|
if (timed_thread_run(info.mail->p_timed_thread)) {
|
|
|
|
ERR("Error running imap timed thread");
|
2006-01-28 01:28:23 +00:00
|
|
|
}
|
2005-08-23 03:00:50 +00:00
|
|
|
}
|
2008-02-20 20:30:45 +00:00
|
|
|
timed_thread_lock(info.mail->p_timed_thread);
|
|
|
|
snprintf(p, p_max_size, "%lu", info.mail->unseen);
|
|
|
|
timed_thread_unlock(info.mail->p_timed_thread);
|
|
|
|
} else if (obj->data.mail) {
|
|
|
|
// this means we use obj
|
|
|
|
if (!obj->data.mail->p_timed_thread) {
|
|
|
|
obj->data.mail->p_timed_thread =
|
2008-03-29 05:14:35 +00:00
|
|
|
timed_thread_create(&imap_thread,
|
2008-02-20 20:30:45 +00:00
|
|
|
(void *) obj->data.mail,
|
|
|
|
obj->data.mail->interval * 1000000);
|
|
|
|
if (!obj->data.mail->p_timed_thread) {
|
|
|
|
ERR("Error creating imap timed thread");
|
2006-01-28 01:28:23 +00:00
|
|
|
}
|
2008-02-20 20:30:45 +00:00
|
|
|
timed_thread_register(obj->data.mail->p_timed_thread,
|
|
|
|
&obj->data.mail->p_timed_thread);
|
|
|
|
if (timed_thread_run(obj->data.mail->p_timed_thread)) {
|
|
|
|
ERR("Error running imap timed thread");
|
2006-01-28 01:28:23 +00:00
|
|
|
}
|
2005-07-20 00:30:40 +00:00
|
|
|
}
|
2008-02-20 20:30:45 +00:00
|
|
|
timed_thread_lock(obj->data.mail->p_timed_thread);
|
|
|
|
snprintf(p, p_max_size, "%lu", obj->data.mail->unseen);
|
|
|
|
timed_thread_unlock(obj->data.mail->p_timed_thread);
|
|
|
|
} else if (!obj->a) {
|
|
|
|
// something is wrong, warn once then stop
|
|
|
|
ERR("Theres a problem with your imap_unseen settings. "
|
|
|
|
"Check that the global IMAP settings are defined "
|
|
|
|
"properly (line %li).", obj->line);
|
|
|
|
obj->a++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
OBJ(imap_messages) {
|
|
|
|
if (obj->global_mode && info.mail) {
|
|
|
|
// this means we use info
|
|
|
|
if (!info.mail->p_timed_thread) {
|
|
|
|
info.mail->p_timed_thread =
|
2008-03-29 05:14:35 +00:00
|
|
|
timed_thread_create(&imap_thread,
|
2008-02-20 20:30:45 +00:00
|
|
|
(void *) info.mail, info.mail->interval * 1000000);
|
|
|
|
if (!info.mail->p_timed_thread) {
|
|
|
|
ERR("Error creating imap timed thread");
|
|
|
|
}
|
|
|
|
timed_thread_register(info.mail->p_timed_thread,
|
|
|
|
&info.mail->p_timed_thread);
|
|
|
|
if (timed_thread_run(info.mail->p_timed_thread)) {
|
|
|
|
ERR("Error running imap timed thread");
|
2006-01-28 01:28:23 +00:00
|
|
|
}
|
|
|
|
}
|
2008-02-20 20:30:45 +00:00
|
|
|
timed_thread_lock(info.mail->p_timed_thread);
|
|
|
|
snprintf(p, p_max_size, "%lu", info.mail->messages);
|
|
|
|
timed_thread_unlock(info.mail->p_timed_thread);
|
|
|
|
} else if (obj->data.mail) {
|
|
|
|
// this means we use obj
|
|
|
|
if (!obj->data.mail->p_timed_thread) {
|
|
|
|
obj->data.mail->p_timed_thread =
|
2008-03-29 05:14:35 +00:00
|
|
|
timed_thread_create(&imap_thread,
|
2008-02-20 20:30:45 +00:00
|
|
|
(void *) obj->data.mail,
|
|
|
|
obj->data.mail->interval * 1000000);
|
|
|
|
if (!obj->data.mail->p_timed_thread) {
|
|
|
|
ERR("Error creating imap timed thread");
|
|
|
|
}
|
|
|
|
timed_thread_register(obj->data.mail->p_timed_thread,
|
|
|
|
&obj->data.mail->p_timed_thread);
|
|
|
|
if (timed_thread_run(obj->data.mail->p_timed_thread)) {
|
|
|
|
ERR("Error runninging imap timed thread");
|
|
|
|
}
|
2005-08-29 17:06:31 +00:00
|
|
|
}
|
2008-02-20 20:30:45 +00:00
|
|
|
timed_thread_lock(obj->data.mail->p_timed_thread);
|
|
|
|
snprintf(p, p_max_size, "%lu", obj->data.mail->messages);
|
|
|
|
timed_thread_lock(obj->data.mail->p_timed_thread);
|
|
|
|
} else if (!obj->a) {
|
|
|
|
// something is wrong, warn once then stop
|
|
|
|
ERR("Theres a problem with your imap_messages settings. "
|
|
|
|
"Check that the global IMAP settings are defined "
|
|
|
|
"properly (line %li).", obj->line);
|
|
|
|
obj->a++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
OBJ(pop3_unseen) {
|
|
|
|
if (obj->global_mode && info.mail) {
|
|
|
|
// this means we use info
|
|
|
|
if (!info.mail->p_timed_thread) {
|
|
|
|
info.mail->p_timed_thread =
|
2008-03-29 05:14:35 +00:00
|
|
|
timed_thread_create(&pop3_thread,
|
2008-02-20 20:30:45 +00:00
|
|
|
(void *) info.mail, info.mail->interval * 1000000);
|
|
|
|
if (!info.mail->p_timed_thread) {
|
|
|
|
ERR("Error creating pop3 timed thread");
|
2006-05-08 22:34:38 +00:00
|
|
|
}
|
2008-02-20 20:30:45 +00:00
|
|
|
timed_thread_register(info.mail->p_timed_thread,
|
|
|
|
&info.mail->p_timed_thread);
|
|
|
|
if (timed_thread_run(info.mail->p_timed_thread)) {
|
|
|
|
ERR("Error running pop3 timed thread");
|
2006-05-08 22:34:38 +00:00
|
|
|
}
|
|
|
|
}
|
2008-02-20 20:30:45 +00:00
|
|
|
timed_thread_lock(info.mail->p_timed_thread);
|
|
|
|
snprintf(p, p_max_size, "%lu", info.mail->unseen);
|
|
|
|
timed_thread_unlock(info.mail->p_timed_thread);
|
|
|
|
} else if (obj->data.mail) {
|
|
|
|
// this means we use obj
|
|
|
|
if (!obj->data.mail->p_timed_thread) {
|
|
|
|
obj->data.mail->p_timed_thread =
|
2008-03-29 05:14:35 +00:00
|
|
|
timed_thread_create(&pop3_thread,
|
2008-02-20 20:30:45 +00:00
|
|
|
(void *) obj->data.mail,
|
|
|
|
obj->data.mail->interval * 1000000);
|
|
|
|
if (!obj->data.mail->p_timed_thread) {
|
|
|
|
ERR("Error creating pop3 timed thread");
|
|
|
|
}
|
|
|
|
timed_thread_register(obj->data.mail->p_timed_thread,
|
|
|
|
&obj->data.mail->p_timed_thread);
|
|
|
|
if (timed_thread_run(obj->data.mail->p_timed_thread)) {
|
|
|
|
ERR("Error running pop3 timed thread");
|
2006-05-08 22:34:38 +00:00
|
|
|
}
|
|
|
|
}
|
2008-02-20 20:30:45 +00:00
|
|
|
timed_thread_lock(obj->data.mail->p_timed_thread);
|
|
|
|
snprintf(p, p_max_size, "%lu", obj->data.mail->unseen);
|
|
|
|
timed_thread_unlock(obj->data.mail->p_timed_thread);
|
|
|
|
} else if (!obj->a) {
|
|
|
|
// something is wrong, warn once then stop
|
|
|
|
ERR("Theres a problem with your pop3_unseen settings. "
|
|
|
|
"Check that the global POP3 settings are defined "
|
|
|
|
"properly (line %li).", obj->line);
|
|
|
|
obj->a++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
OBJ(pop3_used) {
|
|
|
|
if (obj->global_mode && info.mail) {
|
|
|
|
// this means we use info
|
|
|
|
if (!info.mail->p_timed_thread) {
|
|
|
|
info.mail->p_timed_thread =
|
2008-03-29 05:14:35 +00:00
|
|
|
timed_thread_create(&pop3_thread,
|
2008-02-20 20:30:45 +00:00
|
|
|
(void *) info.mail, info.mail->interval * 1000000);
|
|
|
|
if (!info.mail->p_timed_thread) {
|
|
|
|
ERR("Error creating pop3 timed thread");
|
2006-05-08 22:34:38 +00:00
|
|
|
}
|
2008-02-20 20:30:45 +00:00
|
|
|
timed_thread_register(info.mail->p_timed_thread,
|
|
|
|
&info.mail->p_timed_thread);
|
|
|
|
if (timed_thread_run(info.mail->p_timed_thread)) {
|
|
|
|
ERR("Error running pop3 timed thread");
|
2006-05-08 22:34:38 +00:00
|
|
|
}
|
|
|
|
}
|
2008-02-20 20:30:45 +00:00
|
|
|
timed_thread_lock(info.mail->p_timed_thread);
|
|
|
|
snprintf(p, p_max_size, "%.1f",
|
|
|
|
info.mail->used / 1024.0 / 1024.0);
|
|
|
|
timed_thread_unlock(info.mail->p_timed_thread);
|
|
|
|
} else if (obj->data.mail) {
|
|
|
|
// this means we use obj
|
|
|
|
if (!obj->data.mail->p_timed_thread) {
|
|
|
|
obj->data.mail->p_timed_thread =
|
2008-03-29 05:14:35 +00:00
|
|
|
timed_thread_create(&pop3_thread,
|
2008-02-20 20:30:45 +00:00
|
|
|
(void *) obj->data.mail,
|
|
|
|
obj->data.mail->interval * 1000000);
|
|
|
|
if (!obj->data.mail->p_timed_thread) {
|
|
|
|
ERR("Error creating pop3 timed thread");
|
2006-05-08 22:34:38 +00:00
|
|
|
}
|
2008-02-20 20:30:45 +00:00
|
|
|
timed_thread_register(obj->data.mail->p_timed_thread,
|
|
|
|
&obj->data.mail->p_timed_thread);
|
|
|
|
if (timed_thread_run(obj->data.mail->p_timed_thread)) {
|
|
|
|
ERR("Error running pop3 timed thread");
|
2006-05-08 22:34:38 +00:00
|
|
|
}
|
|
|
|
}
|
2008-02-20 20:30:45 +00:00
|
|
|
timed_thread_lock(obj->data.mail->p_timed_thread);
|
|
|
|
snprintf(p, p_max_size, "%.1f",
|
|
|
|
obj->data.mail->used / 1024.0 / 1024.0);
|
|
|
|
timed_thread_unlock(obj->data.mail->p_timed_thread);
|
|
|
|
} else if (!obj->a) {
|
|
|
|
// something is wrong, warn once then stop
|
|
|
|
ERR("Theres a problem with your pop3_used settings. "
|
|
|
|
"Check that the global POP3 settings are defined "
|
|
|
|
"properly (line %li).", obj->line);
|
|
|
|
obj->a++;
|
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) {
|
|
|
|
human_readable(obj->data.fs->avail, p, 255, "fs_free");
|
|
|
|
}
|
2005-07-20 00:30:40 +00:00
|
|
|
}
|
|
|
|
OBJ(fs_free_perc) {
|
|
|
|
if (obj->data.fs != NULL) {
|
2008-02-20 20:30:45 +00:00
|
|
|
if (obj->data.fs->size) {
|
2008-03-28 23:17:01 +00:00
|
|
|
spaced_print(p, p_max_size, "%*d", 4, "fs_free_perc",
|
|
|
|
pad_percents, (int) ((obj->data.fs->avail * 100) /
|
|
|
|
obj->data.fs->size));
|
2008-02-20 20:30:45 +00:00
|
|
|
} else {
|
2005-12-10 14:15:38 +00:00
|
|
|
snprintf(p, p_max_size, "0");
|
2008-02-20 20:30:45 +00:00
|
|
|
}
|
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) {
|
|
|
|
human_readable(obj->data.fs->size, p, 255, "fs_size");
|
|
|
|
}
|
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
|
|
|
|
? obj->data.fs->free : obj->data.fs->avail), p, 255,
|
|
|
|
"fs_used");
|
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) {
|
2008-02-20 20:30:45 +00:00
|
|
|
if (obj->data.fs->size) {
|
2008-03-28 23:17:01 +00:00
|
|
|
spaced_print(p, 4, "%*d", 4, "fs_used_perc",
|
|
|
|
pad_percents, 100 - ((int) ((obj->data.fs->avail * 100) /
|
|
|
|
obj->data.fs->size)));
|
2008-02-20 20:30:45 +00:00
|
|
|
} else {
|
2005-12-10 14:15:38 +00:00
|
|
|
snprintf(p, p_max_size, "0");
|
2008-02-20 20:30:45 +00:00
|
|
|
}
|
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]);
|
|
|
|
}
|
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 {
|
|
|
|
if (!strcmp(obj->data.rss.action, "feed_title")) {
|
|
|
|
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);
|
|
|
|
} else if (!strcmp(obj->data.rss.action, "item_title")) {
|
|
|
|
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-02-20 20:30:45 +00:00
|
|
|
} else if (!strcmp(obj->data.rss.action, "item_desc")) {
|
|
|
|
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-02-20 20:30:45 +00:00
|
|
|
} else if (!strcmp(obj->data.rss.action, "item_titles")) {
|
|
|
|
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;
|
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;
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
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-04-13 04:10:35 +00:00
|
|
|
if (obj->data.hddtemp.update_time < current_update_time - 30) {
|
2008-04-22 22:54:22 +00:00
|
|
|
char *str = get_hddtemp_info(obj->data.hddtemp.dev,
|
2008-04-13 04:10:35 +00:00
|
|
|
obj->data.hddtemp.addr, obj->data.hddtemp.port, &obj->data.hddtemp.unit);
|
2008-04-22 22:54:22 +00:00
|
|
|
if (str) {
|
|
|
|
strncpy(obj->data.hddtemp.temp, str, text_buffer_size);
|
|
|
|
} else {
|
|
|
|
obj->data.hddtemp.temp[0] = 0;
|
|
|
|
}
|
2008-04-13 04:10:35 +00:00
|
|
|
obj->data.hddtemp.update_time = current_update_time;
|
|
|
|
}
|
|
|
|
if (!obj->data.hddtemp.temp) {
|
2006-08-10 16:56:13 +00:00
|
|
|
snprintf(p, p_max_size, "N/A");
|
2008-04-13 04:10:35 +00:00
|
|
|
} else if (obj->data.hddtemp.unit == '*') {
|
|
|
|
snprintf(p, p_max_size, "%s", obj->data.hddtemp.temp);
|
2006-08-10 16:56:13 +00:00
|
|
|
} else {
|
2008-04-13 04:10:35 +00:00
|
|
|
snprintf(p, p_max_size, "%s%c", obj->data.hddtemp.temp, obj->data.hddtemp.unit);
|
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);
|
|
|
|
}
|
2007-08-10 21:14:06 +00:00
|
|
|
#ifndef __OpenBSD__
|
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);
|
|
|
|
|
|
|
|
if (r >= 100.0 || r == 0) {
|
|
|
|
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);
|
|
|
|
|
|
|
|
if (r >= 100.0 || r == 0) {
|
|
|
|
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-02-20 20:30:45 +00:00
|
|
|
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
|
|
|
}
|
2007-08-10 21:14:06 +00:00
|
|
|
#endif /* !__OpenBSD__ */
|
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-03-29 06:24:04 +00:00
|
|
|
struct text_object_list *text_objects;
|
2007-04-06 05:01:48 +00:00
|
|
|
struct information *my_info =
|
2008-02-20 20:30:45 +00:00
|
|
|
malloc(sizeof(struct information));
|
2007-04-06 05:01:48 +00:00
|
|
|
memcpy(my_info, cur, sizeof(struct information));
|
2008-03-29 06:24:04 +00:00
|
|
|
text_objects = parse_conky_vars(obj->data.ifblock.s, p, my_info);
|
|
|
|
|
2007-04-06 05:01:48 +00:00
|
|
|
if (strlen(p) != 0) {
|
|
|
|
i = obj->data.ifblock.pos;
|
|
|
|
if_jumped = 1;
|
|
|
|
} else {
|
|
|
|
if_jumped = 0;
|
|
|
|
}
|
|
|
|
p[0] = '\0';
|
2008-03-20 20:33:31 +00:00
|
|
|
free_text_objects(text_objects->text_object_count, text_objects->text_objects);
|
|
|
|
free(text_objects);
|
2007-04-06 05:01:48 +00:00
|
|
|
free(my_info);
|
|
|
|
}
|
2005-07-28 04:48:27 +00:00
|
|
|
OBJ(if_existing) {
|
|
|
|
struct stat tmp;
|
2008-02-20 20:30:45 +00:00
|
|
|
|
2005-07-28 04:48:27 +00:00
|
|
|
if ((obj->data.ifblock.s)
|
2008-02-20 20:30:45 +00:00
|
|
|
&& (stat(obj->data.ifblock.s, &tmp) == -1)) {
|
2006-01-26 03:05:12 +00:00
|
|
|
i = obj->data.ifblock.pos;
|
2005-07-28 04:48:27 +00:00
|
|
|
if_jumped = 1;
|
2006-01-26 03:05:12 +00:00
|
|
|
} else {
|
2008-02-20 20:30:45 +00:00
|
|
|
if (obj->data.ifblock.str) {
|
|
|
|
if (!check_contains(obj->data.ifblock.s,
|
|
|
|
obj->data.ifblock.str)) {
|
2007-04-06 06:11:53 +00:00
|
|
|
i = obj->data.ifblock.pos;
|
|
|
|
if_jumped = 1;
|
2008-02-20 20:30:45 +00:00
|
|
|
} else {
|
|
|
|
if_jumped = 0;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if_jumped = 0;
|
|
|
|
}
|
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))) {
|
2006-01-26 03:05:12 +00:00
|
|
|
i = obj->data.ifblock.pos;
|
2005-07-28 04:48:27 +00:00
|
|
|
if_jumped = 1;
|
2006-01-26 03:05:12 +00:00
|
|
|
} else {
|
2005-07-28 04:48:27 +00:00
|
|
|
if_jumped = 0;
|
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)) {
|
2006-01-26 03:05:12 +00:00
|
|
|
i = obj->data.ifblock.pos;
|
2005-07-28 04:48:27 +00:00
|
|
|
if_jumped = 1;
|
2006-01-26 03:05:12 +00:00
|
|
|
} else {
|
2005-07-28 04:48:27 +00:00
|
|
|
if_jumped = 0;
|
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-02-09 02:21:06 +00:00
|
|
|
human_readable(cur->mem * 1024, p, 255, "mem");
|
2005-07-20 00:30:40 +00:00
|
|
|
}
|
|
|
|
OBJ(memmax) {
|
2008-02-09 02:21:06 +00:00
|
|
|
human_readable(cur->memmax * 1024, p, 255, "memmax");
|
2005-07-20 00:30:40 +00:00
|
|
|
}
|
|
|
|
OBJ(memperc) {
|
2005-07-28 04:48:27 +00:00
|
|
|
if (cur->memmax) {
|
2008-03-29 05:28:33 +00:00
|
|
|
spaced_print(p, p_max_size, "%*llu", 4, "memperc",
|
2008-02-09 02:21:06 +00:00
|
|
|
pad_percents, cur->mem * 100 / cur->memmax);
|
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-04-13 04:10:35 +00:00
|
|
|
100, 0);
|
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) {
|
2008-02-20 20:30:45 +00:00
|
|
|
snprintf(p, p_max_size, "%d", mixer_get_avg(obj->data.l));
|
2005-07-20 00:30:40 +00:00
|
|
|
}
|
|
|
|
OBJ(mixerl) {
|
2008-02-20 20:30:45 +00:00
|
|
|
snprintf(p, p_max_size, "%d", mixer_get_left(obj->data.l));
|
2005-07-20 00:30:40 +00:00
|
|
|
}
|
|
|
|
OBJ(mixerr) {
|
2008-02-20 20:30:45 +00:00
|
|
|
snprintf(p, p_max_size, "%d", 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,
|
|
|
|
mixer_get_avg(obj->data.mixerbar.l) * 255 / 100);
|
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,
|
|
|
|
mixer_get_left(obj->data.mixerbar.l) * 255 / 100);
|
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,
|
|
|
|
mixer_get_right(obj->data.mixerbar.l) * 255 / 100);
|
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
|
|
|
}
|
2007-02-12 01:03:10 +00:00
|
|
|
OBJ(mboxscan) {
|
2008-02-20 20:30:45 +00:00
|
|
|
mbox_scan(obj->data.mboxscan.args, obj->data.mboxscan.output,
|
2008-03-20 21:28:19 +00:00
|
|
|
text_buffer_size);
|
2007-02-12 01:03:10 +00:00
|
|
|
snprintf(p, p_max_size, "%s", obj->data.mboxscan.output);
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
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) {
|
2008-02-09 02:21:06 +00:00
|
|
|
spaced_print(p, p_max_size, "%hu", 5, "processes", cur->procs);
|
2005-07-20 00:30:40 +00:00
|
|
|
}
|
|
|
|
OBJ(running_processes) {
|
2008-02-20 20:30:45 +00:00
|
|
|
spaced_print(p, p_max_size, "%hu", 3, "running_processes", 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-02-09 02:21:06 +00:00
|
|
|
human_readable(cur->swap * 1024, p, 255, "swap");
|
2005-07-20 00:30:40 +00:00
|
|
|
}
|
|
|
|
OBJ(swapmax) {
|
2008-02-09 02:21:06 +00:00
|
|
|
human_readable(cur->swapmax * 1024, p, 255, "swapmax");
|
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 {
|
2008-03-29 05:28:33 +00:00
|
|
|
spaced_print(p, p_max_size, "%*llu", 4, "swapperc",
|
2008-02-09 02:21:06 +00:00
|
|
|
pad_percents, 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-02-09 02:21:06 +00:00
|
|
|
human_readable(obj->data.net->recv, p, 255, "totaldown");
|
2005-07-20 00:30:40 +00:00
|
|
|
}
|
|
|
|
OBJ(totalup) {
|
2008-02-09 02:21:06 +00:00
|
|
|
human_readable(obj->data.net->trans, p, 255, "totalup");
|
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
|
|
|
}
|
|
|
|
OBJ(upspeed) {
|
2008-02-09 02:21:06 +00:00
|
|
|
spaced_print(p, p_max_size, "%d", 6, "upspeed",
|
|
|
|
round_to_int(obj->data.net->trans_speed / 1024));
|
2005-07-20 00:30:40 +00:00
|
|
|
}
|
|
|
|
OBJ(upspeedf) {
|
2008-02-09 02:21:06 +00:00
|
|
|
spaced_print(p, p_max_size, "%.1f", 8, "upspeedf",
|
|
|
|
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-02-20 20:30:45 +00:00
|
|
|
obj->data.net->trans_speed / 1024.0, obj->e, 1);
|
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
|
|
|
|
OBJ(mpd_title) {
|
2008-02-20 20:30:45 +00:00
|
|
|
snprintf(p, cur->mpd.max_title_len > 0
|
|
|
|
? cur->mpd.max_title_len : p_max_size, "%s",
|
|
|
|
cur->mpd.title);
|
2005-07-20 00:30:40 +00:00
|
|
|
}
|
|
|
|
OBJ(mpd_artist) {
|
2005-12-10 14:15:38 +00:00
|
|
|
snprintf(p, p_max_size, "%s", cur->mpd.artist);
|
2005-07-20 00:30:40 +00:00
|
|
|
}
|
|
|
|
OBJ(mpd_album) {
|
2005-12-10 14:15:38 +00:00
|
|
|
snprintf(p, p_max_size, "%s", cur->mpd.album);
|
2005-07-20 00:30:40 +00:00
|
|
|
}
|
2005-10-11 01:37:46 +00:00
|
|
|
OBJ(mpd_random) {
|
2005-12-10 14:15:38 +00:00
|
|
|
snprintf(p, p_max_size, "%s", cur->mpd.random);
|
2005-10-11 01:37:46 +00:00
|
|
|
}
|
|
|
|
OBJ(mpd_repeat) {
|
2005-12-10 14:15:38 +00:00
|
|
|
snprintf(p, p_max_size, "%s", cur->mpd.repeat);
|
2005-10-11 01:37:46 +00:00
|
|
|
}
|
|
|
|
OBJ(mpd_track) {
|
2005-12-10 14:15:38 +00:00
|
|
|
snprintf(p, p_max_size, "%s", cur->mpd.track);
|
2005-10-11 01:37:46 +00:00
|
|
|
}
|
2006-01-31 03:32:26 +00:00
|
|
|
OBJ(mpd_name) {
|
|
|
|
snprintf(p, p_max_size, "%s", cur->mpd.name);
|
|
|
|
}
|
|
|
|
OBJ(mpd_file) {
|
|
|
|
snprintf(p, p_max_size, "%s", cur->mpd.file);
|
|
|
|
}
|
2005-07-20 00:30:40 +00:00
|
|
|
OBJ(mpd_vol) {
|
2005-12-10 14:15:38 +00:00
|
|
|
snprintf(p, p_max_size, "%i", cur->mpd.volume);
|
2005-07-20 00:30:40 +00:00
|
|
|
}
|
|
|
|
OBJ(mpd_bitrate) {
|
2005-12-10 14:15:38 +00:00
|
|
|
snprintf(p, p_max_size, "%i", cur->mpd.bitrate);
|
2005-07-20 00:30:40 +00:00
|
|
|
}
|
|
|
|
OBJ(mpd_status) {
|
2005-12-10 14:15:38 +00:00
|
|
|
snprintf(p, p_max_size, "%s", cur->mpd.status);
|
2005-07-20 00:30:40 +00:00
|
|
|
}
|
2005-07-28 04:48:27 +00:00
|
|
|
OBJ(mpd_elapsed) {
|
2008-02-20 20:30:45 +00:00
|
|
|
int days = 0, hours = 0, minutes = 0, seconds = 0;
|
2005-07-28 04:48:27 +00:00
|
|
|
int tmp = cur->mpd.elapsed;
|
2008-02-20 20:30:45 +00:00
|
|
|
|
2005-07-28 04:48:27 +00:00
|
|
|
while (tmp >= 86400) {
|
|
|
|
tmp -= 86400;
|
|
|
|
days++;
|
|
|
|
}
|
|
|
|
while (tmp >= 3600) {
|
|
|
|
tmp -= 3600;
|
|
|
|
hours++;
|
|
|
|
}
|
|
|
|
while (tmp >= 60) {
|
|
|
|
tmp -= 60;
|
|
|
|
minutes++;
|
|
|
|
}
|
|
|
|
seconds = tmp;
|
2008-02-20 20:30:45 +00:00
|
|
|
if (days > 0) {
|
|
|
|
snprintf(p, p_max_size, "%i days %i:%02i:%02i", days,
|
|
|
|
hours, minutes, seconds);
|
|
|
|
} else if (hours > 0) {
|
|
|
|
snprintf(p, p_max_size, "%i:%02i:%02i", hours, minutes,
|
|
|
|
seconds);
|
|
|
|
} else {
|
|
|
|
snprintf(p, p_max_size, "%i:%02i", minutes, seconds);
|
|
|
|
}
|
2005-07-28 04:48:27 +00:00
|
|
|
}
|
|
|
|
OBJ(mpd_length) {
|
2008-02-20 20:30:45 +00:00
|
|
|
int days = 0, hours = 0, minutes = 0, seconds = 0;
|
2005-07-28 04:48:27 +00:00
|
|
|
int tmp = cur->mpd.length;
|
2008-02-20 20:30:45 +00:00
|
|
|
|
2005-07-28 04:48:27 +00:00
|
|
|
while (tmp >= 86400) {
|
|
|
|
tmp -= 86400;
|
|
|
|
days++;
|
|
|
|
}
|
|
|
|
while (tmp >= 3600) {
|
|
|
|
tmp -= 3600;
|
|
|
|
hours++;
|
|
|
|
}
|
|
|
|
while (tmp >= 60) {
|
|
|
|
tmp -= 60;
|
|
|
|
minutes++;
|
|
|
|
}
|
|
|
|
seconds = tmp;
|
2008-02-20 20:30:45 +00:00
|
|
|
if (days > 0) {
|
|
|
|
snprintf(p, p_max_size, "%i days %i:%02i:%02i", days,
|
|
|
|
hours, minutes, seconds);
|
|
|
|
} else if (hours > 0) {
|
|
|
|
snprintf(p, p_max_size, "%i:%02i:%02i", hours, minutes,
|
|
|
|
seconds);
|
|
|
|
} else {
|
|
|
|
snprintf(p, p_max_size, "%i:%02i", minutes, seconds);
|
|
|
|
}
|
2005-07-28 04:48:27 +00:00
|
|
|
}
|
|
|
|
OBJ(mpd_percent) {
|
2008-03-28 23:17:01 +00:00
|
|
|
spaced_print(p, p_max_size, "%*d", 4, "mpd_percent",
|
|
|
|
pad_percents, (int) (cur->mpd.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,
|
|
|
|
(int) (cur->mpd.progress * 255.0f));
|
2005-07-20 00:30:40 +00:00
|
|
|
}
|
2006-03-07 04:23:55 +00:00
|
|
|
OBJ(mpd_smart) {
|
2008-02-20 20:30:45 +00:00
|
|
|
memset(p, 0, p_max_size);
|
|
|
|
if (cur->mpd.artist && *cur->mpd.artist && cur->mpd.title
|
|
|
|
&& *cur->mpd.title) {
|
|
|
|
snprintf(p, p_max_size, "%s - %s", cur->mpd.artist,
|
|
|
|
cur->mpd.title);
|
|
|
|
} else if (cur->mpd.title && *cur->mpd.title) {
|
|
|
|
snprintf(p, p_max_size, "%s", cur->mpd.title);
|
|
|
|
} else if (cur->mpd.artist && *cur->mpd.artist) {
|
|
|
|
snprintf(p, p_max_size, "%s", cur->mpd.artist);
|
|
|
|
} else if (cur->mpd.file && *cur->mpd.file) {
|
|
|
|
snprintf(p, p_max_size, "%s", cur->mpd.file);
|
|
|
|
} else {
|
|
|
|
*p = 0;
|
|
|
|
}
|
2006-03-07 04:23:55 +00:00
|
|
|
}
|
2005-12-30 09:44:40 +00:00
|
|
|
#endif
|
2008-02-20 20:30:45 +00:00
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
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-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
|
|
|
|
OBJ(top) {
|
2008-02-20 10:01:31 +00:00
|
|
|
if (obj->data.top.num >= 0 && obj->data.top.num < 10) {
|
2008-03-29 09:58:09 +00:00
|
|
|
char *timeval;
|
2008-02-20 10:01:31 +00:00
|
|
|
|
|
|
|
switch (obj->data.top.type) {
|
|
|
|
case TOP_NAME:
|
|
|
|
snprintf(p, 16, "%-15s",
|
|
|
|
cur->cpu[obj->data.top.num]->name);
|
|
|
|
break;
|
|
|
|
case TOP_CPU:
|
|
|
|
snprintf(p, 7, "%6.2f",
|
|
|
|
cur->cpu[obj->data.top.num]->amount);
|
|
|
|
break;
|
|
|
|
case TOP_PID:
|
|
|
|
snprintf(p, 6, "%5i",
|
|
|
|
cur->cpu[obj->data.top.num]->pid);
|
|
|
|
break;
|
|
|
|
case TOP_MEM:
|
|
|
|
snprintf(p, 7, "%6.2f",
|
|
|
|
cur->cpu[obj->data.top.num]->totalmem);
|
|
|
|
break;
|
|
|
|
case TOP_TIME:
|
2008-03-29 09:58:09 +00:00
|
|
|
timeval = format_time(
|
2008-02-20 20:30:45 +00:00
|
|
|
cur->cpu[obj->data.top.num]->total_cpu_time, 9);
|
2008-03-29 09:58:09 +00:00
|
|
|
snprintf(p, 10, "%9s", timeval);
|
|
|
|
free(timeval);
|
2008-02-20 10:01:31 +00:00
|
|
|
break;
|
2008-03-30 07:04:25 +00:00
|
|
|
case TOP_MEM_RES:
|
|
|
|
human_readable(cur->cpu[obj->data.top.num]->rss,
|
|
|
|
p, 255, "top_rss");
|
|
|
|
break;
|
|
|
|
case TOP_MEM_VSIZE:
|
|
|
|
human_readable(cur->cpu[obj->data.top.num]->vsize,
|
|
|
|
p, 255, "top_rss");
|
|
|
|
break;
|
2008-02-20 10:01:31 +00:00
|
|
|
default:
|
2008-02-20 20:30:45 +00:00
|
|
|
ERR("Unhandled top data type: %d\n",
|
|
|
|
obj->data.top.type);
|
2008-02-20 10:01:31 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
ERR("Top index < 0 or > 10: %d\n", obj->data.top.num);
|
2005-07-28 04:48:27 +00:00
|
|
|
}
|
2005-07-20 00:30:40 +00:00
|
|
|
}
|
2005-07-25 00:22:16 +00:00
|
|
|
OBJ(top_mem) {
|
2008-02-20 10:01:31 +00:00
|
|
|
if (obj->data.top.num >= 0 && obj->data.top.num < 10) {
|
2008-03-29 09:58:09 +00:00
|
|
|
char *timeval;
|
2008-02-20 10:01:31 +00:00
|
|
|
|
|
|
|
switch (obj->data.top.type) {
|
|
|
|
case TOP_NAME:
|
|
|
|
snprintf(p, 16, "%-15s",
|
2008-02-20 20:30:45 +00:00
|
|
|
cur->memu[obj->data.top.num]->name);
|
2008-02-20 10:01:31 +00:00
|
|
|
break;
|
|
|
|
case TOP_CPU:
|
|
|
|
snprintf(p, 7, "%6.2f",
|
2008-02-24 16:35:18 +00:00
|
|
|
cur->memu[obj->data.top.num]->amount);
|
2008-02-20 10:01:31 +00:00
|
|
|
break;
|
|
|
|
case TOP_PID:
|
|
|
|
snprintf(p, 6, "%5i",
|
|
|
|
cur->memu[obj->data.top.num]->pid);
|
|
|
|
break;
|
|
|
|
case TOP_MEM:
|
|
|
|
snprintf(p, 7, "%6.2f",
|
2008-02-20 20:30:45 +00:00
|
|
|
cur->memu[obj->data.top.num]->totalmem);
|
2008-02-20 10:01:31 +00:00
|
|
|
break;
|
|
|
|
case TOP_TIME:
|
2008-03-29 09:58:09 +00:00
|
|
|
timeval = format_time(
|
2008-02-20 10:01:31 +00:00
|
|
|
cur->memu[obj->data.top.num]->total_cpu_time,
|
|
|
|
9);
|
2008-03-29 09:58:09 +00:00
|
|
|
snprintf(p, 10, "%9s", timeval);
|
|
|
|
free(timeval);
|
2008-02-20 10:01:31 +00:00
|
|
|
break;
|
2008-03-30 07:04:25 +00:00
|
|
|
case TOP_MEM_RES:
|
|
|
|
human_readable(cur->cpu[obj->data.top.num]->rss,
|
|
|
|
p, 255, "top_rss");
|
|
|
|
break;
|
|
|
|
case TOP_MEM_VSIZE:
|
|
|
|
human_readable(cur->cpu[obj->data.top.num]->vsize,
|
|
|
|
p, 255, "top_rss");
|
|
|
|
break;
|
2008-02-20 10:01:31 +00:00
|
|
|
default:
|
2008-02-20 20:30:45 +00:00
|
|
|
ERR("Unhandled top data type: %d\n",
|
|
|
|
obj->data.top.type);
|
2008-02-20 10:01:31 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
ERR("Top index < 0 or > 10: %d\n", obj->data.top.num);
|
2005-07-25 00:22:16 +00:00
|
|
|
}
|
|
|
|
}
|
2005-07-20 00:30:40 +00:00
|
|
|
OBJ(tail) {
|
2008-02-20 20:30:45 +00:00
|
|
|
if (current_update_time - obj->data.tail.last_update
|
|
|
|
< obj->data.tail.interval) {
|
|
|
|
snprintf(p, p_max_size, "%s", obj->data.tail.buffer);
|
2006-01-06 05:11:28 +00:00
|
|
|
} else {
|
2005-07-28 04:48:27 +00:00
|
|
|
FILE *fp;
|
2008-02-20 20:30:45 +00:00
|
|
|
long nl = 0, bsize;
|
2006-12-29 23:14:31 +00:00
|
|
|
int iter;
|
2007-09-28 20:16:16 +00:00
|
|
|
|
2008-03-29 06:24:04 +00:00
|
|
|
obj->data.tail.last_update = current_update_time;
|
|
|
|
|
2007-09-28 20:16:16 +00:00
|
|
|
if (obj->data.tail.fd != -1) {
|
2008-02-20 20:30:45 +00:00
|
|
|
tail_pipe(obj, p, p_max_size);
|
|
|
|
goto head;
|
2007-09-28 20:16:16 +00:00
|
|
|
}
|
|
|
|
|
2005-08-01 02:52:17 +00:00
|
|
|
fp = fopen(obj->data.tail.logfile, "rt");
|
2007-09-28 20:16:16 +00:00
|
|
|
|
2005-08-10 05:52:52 +00:00
|
|
|
if (fp == NULL) {
|
2008-02-20 20:30:45 +00:00
|
|
|
/* Send one message, but do not consistently spam
|
|
|
|
* on missing logfiles. */
|
|
|
|
if (obj->data.tail.readlines != 0) {
|
2006-12-29 23:14:31 +00:00
|
|
|
ERR("tail logfile failed to open");
|
|
|
|
strcpy(obj->data.tail.buffer, "Logfile Missing");
|
|
|
|
}
|
|
|
|
obj->data.tail.readlines = 0;
|
|
|
|
snprintf(p, p_max_size, "Logfile Missing");
|
2008-02-20 20:30:45 +00:00
|
|
|
} else {
|
2005-08-01 02:52:17 +00:00
|
|
|
obj->data.tail.readlines = 0;
|
2008-02-20 20:30:45 +00:00
|
|
|
/* -1 instead of 0 to avoid counting a trailing
|
|
|
|
* newline */
|
|
|
|
fseek(fp, -1, SEEK_END);
|
2006-12-29 23:14:31 +00:00
|
|
|
bsize = ftell(fp) + 1;
|
2008-02-20 20:30:45 +00:00
|
|
|
for (iter = obj->data.tail.wantedlines; iter > 0;
|
|
|
|
iter--) {
|
2006-12-29 23:14:31 +00:00
|
|
|
nl = rev_fcharfind(fp, '\n', iter);
|
2008-02-20 20:30:45 +00:00
|
|
|
if (nl >= 0) {
|
2006-12-29 23:14:31 +00:00
|
|
|
break;
|
2008-02-20 20:30:45 +00:00
|
|
|
}
|
2005-07-20 00:30:40 +00:00
|
|
|
}
|
2006-12-29 23:14:31 +00:00
|
|
|
obj->data.tail.readlines = iter;
|
2008-02-20 20:30:45 +00:00
|
|
|
if (obj->data.tail.readlines
|
|
|
|
< obj->data.tail.wantedlines) {
|
2006-12-29 23:14:31 +00:00
|
|
|
fseek(fp, 0, SEEK_SET);
|
2008-02-20 20:30:45 +00:00
|
|
|
} else {
|
|
|
|
fseek(fp, nl + 1, SEEK_SET);
|
2006-12-29 23:14:31 +00:00
|
|
|
bsize -= ftell(fp);
|
|
|
|
}
|
2008-02-20 20:30:45 +00:00
|
|
|
/* Make sure bsize is at least 1 byte smaller than the
|
|
|
|
* buffer max size. */
|
2008-03-20 21:28:19 +00:00
|
|
|
if (bsize > (long) ((text_buffer_size * 20) - 1)) {
|
|
|
|
fseek(fp, bsize - text_buffer_size * 20 - 1,
|
2008-02-20 20:30:45 +00:00
|
|
|
SEEK_CUR);
|
2008-03-20 21:28:19 +00:00
|
|
|
bsize = text_buffer_size * 20 - 1;
|
2006-12-29 23:14:31 +00:00
|
|
|
}
|
|
|
|
bsize = fread(obj->data.tail.buffer, 1, bsize, fp);
|
2005-07-28 04:48:27 +00:00
|
|
|
fclose(fp);
|
2008-02-20 20:30:45 +00:00
|
|
|
if (bsize > 0) {
|
|
|
|
/* Clean up trailing newline, make sure the
|
|
|
|
* buffer is null terminated. */
|
|
|
|
if (obj->data.tail.buffer[bsize - 1] == '\n') {
|
|
|
|
obj->data.tail.buffer[bsize - 1] = '\0';
|
|
|
|
} else {
|
2006-12-29 23:14:31 +00:00
|
|
|
obj->data.tail.buffer[bsize] = '\0';
|
2008-02-20 20:30:45 +00:00
|
|
|
}
|
|
|
|
snprintf(p, p_max_size, "%s",
|
|
|
|
obj->data.tail.buffer);
|
|
|
|
} else {
|
2005-08-26 05:52:43 +00:00
|
|
|
strcpy(obj->data.tail.buffer, "Logfile Empty");
|
2006-01-06 05:11:28 +00:00
|
|
|
snprintf(p, p_max_size, "Logfile Empty");
|
2008-02-20 20:30:45 +00:00
|
|
|
} /* bsize > 0 */
|
|
|
|
} /* fp == NULL */
|
|
|
|
} /* if cur_upd_time >= */
|
|
|
|
// parse_conky_vars(obj->data.tail.buffer, p, cur);
|
2005-08-26 05:52:43 +00:00
|
|
|
}
|
2007-09-28 20:16:16 +00:00
|
|
|
head:
|
2005-08-26 05:52:43 +00:00
|
|
|
OBJ(head) {
|
2008-02-20 20:30:45 +00:00
|
|
|
if (current_update_time - obj->data.tail.last_update
|
|
|
|
< obj->data.tail.interval) {
|
2006-12-29 23:14:31 +00:00
|
|
|
snprintf(p, p_max_size, "%s", obj->data.tail.buffer);
|
2006-01-06 05:11:28 +00:00
|
|
|
} else {
|
2005-08-26 05:52:43 +00:00
|
|
|
FILE *fp;
|
2008-02-20 20:30:45 +00:00
|
|
|
long nl = 0;
|
2006-12-29 23:14:31 +00:00
|
|
|
int iter;
|
2008-02-20 20:30:45 +00:00
|
|
|
|
2008-03-29 06:24:04 +00:00
|
|
|
obj->data.tail.last_update = current_update_time;
|
|
|
|
|
2005-08-26 05:52:43 +00:00
|
|
|
fp = fopen(obj->data.tail.logfile, "rt");
|
|
|
|
if (fp == NULL) {
|
2008-02-20 20:30:45 +00:00
|
|
|
/* Send one message, but do not consistently spam
|
|
|
|
* on missing logfiles. */
|
|
|
|
if (obj->data.tail.readlines != 0) {
|
2006-12-29 23:14:31 +00:00
|
|
|
ERR("head logfile failed to open");
|
|
|
|
strcpy(obj->data.tail.buffer, "Logfile Missing");
|
|
|
|
}
|
|
|
|
obj->data.tail.readlines = 0;
|
|
|
|
snprintf(p, p_max_size, "Logfile Missing");
|
2005-12-10 21:07:24 +00:00
|
|
|
} else {
|
2005-08-26 05:52:43 +00:00
|
|
|
obj->data.tail.readlines = 0;
|
2008-02-20 20:30:45 +00:00
|
|
|
for (iter = obj->data.tail.wantedlines; iter > 0;
|
|
|
|
iter--) {
|
2006-12-29 23:14:31 +00:00
|
|
|
nl = fwd_fcharfind(fp, '\n', iter);
|
2008-02-20 20:30:45 +00:00
|
|
|
if (nl >= 0) {
|
2006-12-29 23:14:31 +00:00
|
|
|
break;
|
2008-02-20 20:30:45 +00:00
|
|
|
}
|
2005-08-26 05:52:43 +00:00
|
|
|
}
|
2006-12-29 23:14:31 +00:00
|
|
|
obj->data.tail.readlines = iter;
|
2008-02-20 20:30:45 +00:00
|
|
|
/* Make sure nl is at least 1 byte smaller than the
|
|
|
|
* buffer max size. */
|
2008-03-20 21:28:19 +00:00
|
|
|
if (nl > (long) ((text_buffer_size * 20) - 1)) {
|
|
|
|
nl = text_buffer_size * 20 - 1;
|
2006-12-29 23:14:31 +00:00
|
|
|
}
|
|
|
|
nl = fread(obj->data.tail.buffer, 1, nl, fp);
|
2005-08-26 05:52:43 +00:00
|
|
|
fclose(fp);
|
2008-02-20 20:30:45 +00:00
|
|
|
if (nl > 0) {
|
2006-12-29 23:14:31 +00:00
|
|
|
/* Clean up trailing newline, make sure the buffer
|
|
|
|
* is null terminated. */
|
2008-02-20 20:30:45 +00:00
|
|
|
if (obj->data.tail.buffer[nl - 1] == '\n') {
|
|
|
|
obj->data.tail.buffer[nl - 1] = '\0';
|
|
|
|
} else {
|
2006-12-29 23:14:31 +00:00
|
|
|
obj->data.tail.buffer[nl] = '\0';
|
2005-08-26 05:52:43 +00:00
|
|
|
}
|
2008-02-20 20:30:45 +00:00
|
|
|
snprintf(p, p_max_size, "%s",
|
|
|
|
obj->data.tail.buffer);
|
|
|
|
} else {
|
2005-08-01 02:52:17 +00:00
|
|
|
strcpy(obj->data.tail.buffer, "Logfile Empty");
|
2006-01-06 05:11:28 +00:00
|
|
|
snprintf(p, p_max_size, "Logfile Empty");
|
2008-02-20 20:30:45 +00:00
|
|
|
} /* nl > 0 */
|
|
|
|
} /* if fp == null */
|
|
|
|
} /* cur_upd_time >= */
|
|
|
|
// parse_conky_vars(obj->data.tail.buffer, p, cur);
|
2005-07-20 00:30:40 +00:00
|
|
|
}
|
2008-02-20 20:30:45 +00:00
|
|
|
|
2005-10-31 05:17:06 +00:00
|
|
|
#ifdef TCP_PORT_MONITOR
|
2008-02-20 20:30:45 +00:00
|
|
|
OBJ(tcp_portmon) {
|
2005-10-31 05:17:06 +00:00
|
|
|
/* grab a pointer to this port monitor */
|
2008-02-20 20:30:45 +00:00
|
|
|
tcp_port_monitor_t *p_monitor =
|
|
|
|
find_tcp_port_monitor(info.p_tcp_port_monitor_collection,
|
|
|
|
obj->data.tcp_port_monitor.port_range_begin,
|
|
|
|
obj->data.tcp_port_monitor.port_range_end);
|
|
|
|
|
|
|
|
if (!p_monitor) {
|
2005-12-10 14:15:38 +00:00
|
|
|
snprintf(p, p_max_size, "monitor not found");
|
2005-10-31 05:17:06 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* now grab the text of interest */
|
2008-02-20 20:30:45 +00:00
|
|
|
if (peek_tcp_port_monitor(p_monitor,
|
|
|
|
obj->data.tcp_port_monitor.item,
|
|
|
|
obj->data.tcp_port_monitor.connection_index, p,
|
|
|
|
p_max_size) != 0) {
|
2005-12-10 14:15:38 +00:00
|
|
|
snprintf(p, p_max_size, "monitor peek error");
|
2005-10-31 05:17:06 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#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));
|
|
|
|
}
|
2008-03-18 00:23:16 +00:00
|
|
|
#ifdef SMAPI
|
|
|
|
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)) {
|
|
|
|
i = obj->data.ifblock.pos;
|
|
|
|
if_jumped = 1;
|
|
|
|
} else
|
|
|
|
if_jumped = 0;
|
|
|
|
} 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;
|
2008-03-22 18:08:47 +00:00
|
|
|
spaced_print(p, p_max_size, "%*d", 4, "smapi_bat_perc", pad_percents, val);
|
2008-03-18 00:23:16 +00:00
|
|
|
} else
|
|
|
|
ERR("argument to smapi_bat_perc must be an integer");
|
|
|
|
}
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
#endif /* SMAPI */
|
2008-06-03 20:46:15 +00:00
|
|
|
#ifdef NVIDIA
|
|
|
|
OBJ(nvidia) {
|
|
|
|
int hol = (strcmp((char*)&obj->data.nvidia.arg, "gpufreq")) ? 1 : 0;
|
|
|
|
if(!(obj->data.nvidia.value = get_nvidia_value(obj->data.nvidia.type, display, hol)))
|
|
|
|
snprintf(p, p_max_size, "value unavailible");
|
|
|
|
else
|
|
|
|
spaced_print(p, p_max_size, "%*d", 4, "nvidia",
|
|
|
|
4, obj->data.nvidia.value);
|
|
|
|
|
|
|
|
}
|
|
|
|
#endif /* NVIDIA */
|
2006-05-13 19:51:26 +00:00
|
|
|
|
2005-07-20 00:30:40 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
double current_update_time, last_update_time;
|
|
|
|
|
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();
|
2006-12-29 23:14:31 +00:00
|
|
|
/* fix diskio rates to b/s (use update_interval */
|
|
|
|
diskio_read_value = diskio_read_value / update_interval;
|
|
|
|
diskio_write_value = diskio_write_value / update_interval;
|
|
|
|
diskio_value = diskio_value / update_interval;
|
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-03-29 05:23:45 +00:00
|
|
|
generate_text_internal(p, max_user_text, global_text_objects,
|
|
|
|
global_text_object_count, 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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2005-08-08 01:18:52 +00:00
|
|
|
#ifdef X11
|
2008-03-29 02:01:03 +00:00
|
|
|
static void set_font(void)
|
2005-08-03 07:01:32 +00:00
|
|
|
{
|
|
|
|
#ifdef XFT
|
|
|
|
if (use_xft) {
|
2008-02-20 20:30:45 +00:00
|
|
|
if (window.xftdraw != NULL) {
|
|
|
|
XftDrawDestroy(window.xftdraw);
|
|
|
|
}
|
|
|
|
window.xftdraw = XftDrawCreate(display, window.drawable,
|
|
|
|
DefaultVisual(display, screen), DefaultColormap(display, screen));
|
|
|
|
} else
|
2005-08-03 07:01:32 +00:00
|
|
|
#endif
|
2008-02-20 20:30:45 +00:00
|
|
|
{
|
|
|
|
XSetFont(display, window.gc, fonts[selected_font].font->fid);
|
|
|
|
}
|
2005-08-03 07:01:32 +00:00
|
|
|
}
|
|
|
|
|
2005-08-08 01:18:52 +00:00
|
|
|
#endif /* X11 */
|
|
|
|
|
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
|
2005-07-20 00:30:40 +00:00
|
|
|
return *s ? calc_text_width(s, strlen(s)) : 0;
|
2005-08-08 01:18:52 +00:00
|
|
|
#else
|
|
|
|
return strlen(s);
|
|
|
|
#endif /* X11 */
|
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)
|
|
|
|
{
|
2008-03-29 06:24:04 +00:00
|
|
|
#ifdef X11
|
|
|
|
char *p, *final;
|
2008-03-29 09:58:09 +00:00
|
|
|
int idx = 1;
|
2008-03-29 06:24:04 +00:00
|
|
|
int width = 0;
|
|
|
|
unsigned int i;
|
|
|
|
|
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 */
|
2005-08-27 04:55:48 +00:00
|
|
|
for (i = 0; i < strlen(p); i++) {
|
|
|
|
*(p + i) = *(p + i + 1);
|
|
|
|
}
|
2008-03-29 09:58:09 +00:00
|
|
|
if (specials[special_index + idx].type == GRAPH
|
|
|
|
|| 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;
|
|
|
|
#else
|
2008-03-29 06:24:04 +00:00
|
|
|
return (s) ? strlen(s) : 0;
|
2005-08-27 04:55:48 +00:00
|
|
|
#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;
|
|
|
|
|
|
|
|
/* 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
|
|
|
#ifdef X11
|
|
|
|
static void text_size_updater(char *s)
|
|
|
|
{
|
|
|
|
int w = 0;
|
|
|
|
char *p;
|
2008-02-20 20:30:45 +00:00
|
|
|
|
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
|
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;
|
|
|
|
last_font_height += font_ascent();
|
|
|
|
}
|
|
|
|
} 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();
|
|
|
|
}
|
|
|
|
#endif /* X11 */
|
|
|
|
|
2005-07-20 00:30:40 +00:00
|
|
|
static inline void set_foreground_color(long c)
|
|
|
|
{
|
|
|
|
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-04 22:35:02 +00:00
|
|
|
if (out_to_console && 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
|
|
|
}
|
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
|
2008-05-06 22:41:28 +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-03-20 21:28:19 +00:00
|
|
|
for (i = 0; i < (int)text_buffer_size; i++) {
|
2008-02-20 20:30:45 +00:00
|
|
|
if (tmpstring1[i] == '\t') { // 9 is ascii tab
|
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 {
|
2005-07-20 00:30:40 +00:00
|
|
|
if (tmpstring1[i] != 9) {
|
2008-02-20 20:30:45 +00:00
|
|
|
/* guard against overrun */
|
2008-03-20 21:28:19 +00:00
|
|
|
tmpstring2[MIN(pos, (int)text_buffer_size - 1)] = tmpstring1[i];
|
2005-07-20 00:30:40 +00:00
|
|
|
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
|
2005-08-24 06:21:50 +00:00
|
|
|
if (text_width == maximum_width) {
|
2008-02-20 20:30:45 +00:00
|
|
|
/* 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
|
2005-07-20 00:30:40 +00:00
|
|
|
#ifdef XFT
|
|
|
|
if (use_xft) {
|
|
|
|
XColor c;
|
|
|
|
XftColor c2;
|
2008-02-20 20:30:45 +00:00
|
|
|
|
2005-07-20 00:30:40 +00:00
|
|
|
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;
|
2005-08-03 07:01:32 +00:00
|
|
|
c2.color.alpha = fonts[selected_font].font_alpha;
|
2005-07-28 04:48:27 +00:00
|
|
|
if (utf8_mode) {
|
2005-08-03 07:01:32 +00:00
|
|
|
XftDrawStringUtf8(window.xftdraw, &c2, fonts[selected_font].xftfont,
|
2008-03-29 03:45:36 +00:00
|
|
|
cur_x, cur_y, (const XftChar8 *) s, strlen(s));
|
2005-07-28 04:48:27 +00:00
|
|
|
} else {
|
2005-08-03 07:01:32 +00:00
|
|
|
XftDrawString8(window.xftdraw, &c2, fonts[selected_font].xftfont,
|
2008-03-29 03:45:36 +00:00
|
|
|
cur_x, cur_y, (const XftChar8 *) s, strlen(s));
|
2005-07-25 01:13:26 +00:00
|
|
|
}
|
2005-07-20 00:30:40 +00:00
|
|
|
} else
|
|
|
|
#endif
|
|
|
|
{
|
2008-02-20 20:30:45 +00:00
|
|
|
XDrawString(display, window.drawable, window.gc, cur_x, cur_y, s,
|
|
|
|
strlen(s));
|
2005-07-20 00:30:40 +00:00
|
|
|
}
|
|
|
|
cur_x += width_of_s;
|
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
|
|
|
}
|
|
|
|
|
2005-08-21 03:29:05 +00:00
|
|
|
long redmask, greenmask, bluemask;
|
|
|
|
|
2008-03-29 02:01:03 +00:00
|
|
|
void set_up_gradient(void)
|
2005-08-21 03:29:05 +00:00
|
|
|
{
|
2008-03-29 06:24:04 +00:00
|
|
|
int i;
|
2005-08-22 01:22:34 +00:00
|
|
|
#ifdef X11
|
2005-08-21 03:29:05 +00:00
|
|
|
colour_depth = DisplayPlanes(display, screen);
|
2005-08-22 01:22:34 +00:00
|
|
|
#else
|
|
|
|
colour_depth = 16;
|
|
|
|
#endif /* X11 */
|
2005-08-21 03:29:05 +00:00
|
|
|
if (colour_depth != 24 && colour_depth != 16) {
|
2008-02-20 20:30:45 +00:00
|
|
|
ERR("using non-standard colour depth, gradients may look like a "
|
|
|
|
"lolly-pop");
|
2005-08-21 03:29:05 +00:00
|
|
|
}
|
2008-02-20 20:30:45 +00:00
|
|
|
|
2005-08-21 03:29:05 +00:00
|
|
|
redmask = 0;
|
|
|
|
greenmask = 0;
|
|
|
|
bluemask = 0;
|
2008-02-20 20:30:45 +00:00
|
|
|
for (i = (colour_depth / 3) - 1; i >= 0; i--) {
|
2005-08-21 03:29:05 +00:00
|
|
|
redmask |= 1 << i;
|
|
|
|
greenmask |= 1 << i;
|
|
|
|
bluemask |= 1 << i;
|
|
|
|
}
|
2008-02-20 20:30:45 +00:00
|
|
|
if (colour_depth % 3 == 1) {
|
2005-08-21 03:29:05 +00:00
|
|
|
greenmask |= 1 << (colour_depth / 3);
|
|
|
|
}
|
2008-02-20 20:30:45 +00:00
|
|
|
redmask = redmask << (2 * colour_depth / 3 + colour_depth % 3);
|
2005-08-21 03:29:05 +00:00
|
|
|
greenmask = greenmask << (colour_depth / 3);
|
|
|
|
}
|
|
|
|
|
2008-02-20 20:30:45 +00:00
|
|
|
/* this function returns the next colour between two colours for a gradient */
|
|
|
|
inline unsigned long do_gradient(unsigned long first_colour,
|
|
|
|
unsigned long last_colour)
|
|
|
|
{
|
2005-08-01 09:15:02 +00:00
|
|
|
int tmp_color = 0;
|
2008-02-20 20:30:45 +00:00
|
|
|
int red1, green1, blue1; // first colour
|
|
|
|
int red2, green2, blue2; // second colour
|
|
|
|
int red3 = 0, green3 = 0, blue3 = 0; // difference
|
|
|
|
short redshift = (2 * colour_depth / 3 + colour_depth % 3);
|
2005-08-21 03:29:05 +00:00
|
|
|
short greenshift = (colour_depth / 3);
|
2008-02-20 20:30:45 +00:00
|
|
|
|
2005-08-21 03:29:05 +00:00
|
|
|
red1 = (first_colour & redmask) >> redshift;
|
|
|
|
green1 = (first_colour & greenmask) >> greenshift;
|
|
|
|
blue1 = first_colour & bluemask;
|
|
|
|
red2 = (last_colour & redmask) >> redshift;
|
|
|
|
green2 = (last_colour & greenmask) >> greenshift;
|
|
|
|
blue2 = last_colour & bluemask;
|
2005-08-01 09:15:02 +00:00
|
|
|
if (red1 > red2) {
|
|
|
|
red3 = -1;
|
|
|
|
}
|
|
|
|
if (red1 < red2) {
|
|
|
|
red3 = 1;
|
|
|
|
}
|
|
|
|
if (green1 > green2) {
|
|
|
|
green3 = -1;
|
|
|
|
}
|
|
|
|
if (green1 < green2) {
|
|
|
|
green3 = 1;
|
|
|
|
}
|
|
|
|
if (blue1 > blue2) {
|
|
|
|
blue3 = -1;
|
|
|
|
}
|
|
|
|
if (blue1 < blue2) {
|
|
|
|
blue3 = 1;
|
|
|
|
}
|
|
|
|
red1 += red3;
|
|
|
|
green1 += green3;
|
|
|
|
blue1 += blue3;
|
|
|
|
if (red1 < 0) {
|
|
|
|
red1 = 0;
|
|
|
|
}
|
|
|
|
if (green1 < 0) {
|
|
|
|
green1 = 0;
|
|
|
|
}
|
|
|
|
if (blue1 < 0) {
|
|
|
|
blue1 = 0;
|
|
|
|
}
|
2005-08-21 03:29:05 +00:00
|
|
|
if (red1 > bluemask) {
|
|
|
|
red1 = bluemask;
|
2005-08-01 09:15:02 +00:00
|
|
|
}
|
2005-08-21 03:29:05 +00:00
|
|
|
if (green1 > bluemask) {
|
|
|
|
green1 = bluemask;
|
2005-08-01 09:15:02 +00:00
|
|
|
}
|
2005-08-21 03:29:05 +00:00
|
|
|
if (blue1 > bluemask) {
|
|
|
|
blue1 = bluemask;
|
2005-08-01 09:15:02 +00:00
|
|
|
}
|
2005-08-21 03:29:05 +00:00
|
|
|
tmp_color = (red1 << redshift) | (green1 << greenshift) | blue1;
|
2005-08-01 09:15:02 +00:00
|
|
|
return tmp_color;
|
|
|
|
}
|
|
|
|
|
2008-02-20 20:30:45 +00:00
|
|
|
/* this function returns the max diff for a gradient */
|
|
|
|
inline unsigned long gradient_max(unsigned long first_colour,
|
|
|
|
unsigned long last_colour)
|
|
|
|
{
|
2008-03-29 06:24:04 +00:00
|
|
|
int red1, green1, blue1; // first colour
|
|
|
|
int red2, green2, blue2; // second colour
|
|
|
|
int red3 = 0, green3 = 0, blue3 = 0; // difference
|
|
|
|
long redshift, greenshift;
|
|
|
|
int max;
|
|
|
|
|
2005-08-21 03:29:05 +00:00
|
|
|
if (colour_depth == 0) {
|
|
|
|
set_up_gradient();
|
|
|
|
}
|
2008-03-29 06:24:04 +00:00
|
|
|
redshift = (2 * colour_depth / 3 + colour_depth % 3);
|
|
|
|
greenshift = (colour_depth / 3);
|
2008-02-20 20:30:45 +00:00
|
|
|
|
2005-08-21 03:29:05 +00:00
|
|
|
red1 = (first_colour & redmask) >> redshift;
|
|
|
|
green1 = (first_colour & greenmask) >> greenshift;
|
|
|
|
blue1 = first_colour & bluemask;
|
|
|
|
red2 = (last_colour & redmask) >> redshift;
|
|
|
|
green2 = (last_colour & greenmask) >> greenshift;
|
|
|
|
blue2 = last_colour & bluemask;
|
2005-08-01 09:15:02 +00:00
|
|
|
red3 = abs(red1 - red2);
|
|
|
|
green3 = abs(green1 - green2);
|
|
|
|
blue3 = abs(blue1 - blue2);
|
2008-03-29 06:24:04 +00:00
|
|
|
max = red3;
|
2008-02-20 20:30:45 +00:00
|
|
|
|
|
|
|
if (green3 > max) {
|
2005-08-01 09:15:02 +00:00
|
|
|
max = green3;
|
2008-02-20 20:30:45 +00:00
|
|
|
}
|
|
|
|
if (blue3 > max) {
|
2005-08-01 09:15:02 +00:00
|
|
|
max = blue3;
|
2008-02-20 20:30:45 +00:00
|
|
|
}
|
2005-08-01 09:15:02 +00:00
|
|
|
return max;
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
short font_h;
|
2008-04-13 04:10:35 +00:00
|
|
|
char *tmp_str;
|
2008-02-20 20:30:45 +00:00
|
|
|
|
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
|
|
|
|
2006-05-28 07:25:30 +00:00
|
|
|
if (h < font_height()) {
|
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);
|
|
|
|
if (specials[special_index].height > cur_y_add
|
|
|
|
&& specials[special_index].height > font_h) {
|
|
|
|
cur_y_add = specials[special_index].height;
|
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
|
|
|
}
|
|
|
|
|
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-04-13 04:10:35 +00:00
|
|
|
int show_scale_x = cur_x + font_ascent() / 2;
|
|
|
|
int show_scale_y = cur_y + font_height() / 2;
|
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
|
|
|
|
2006-05-28 07:25:30 +00:00
|
|
|
if (h < font_height()) {
|
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
|
|
|
}
|
2008-02-20 20:30:45 +00:00
|
|
|
if (specials[special_index].height > cur_y_add
|
|
|
|
&& specials[special_index].height > font_h) {
|
|
|
|
cur_y_add = specials[special_index].height;
|
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-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;
|
|
|
|
cur_x = show_scale_x;
|
|
|
|
cur_y = show_scale_y;
|
|
|
|
tmp_str = (char *)
|
|
|
|
calloc(log10(floor(specials[special_index].graph_scale)) + 4,
|
|
|
|
sizeof(char));
|
|
|
|
sprintf(tmp_str, "%.1f", specials[special_index].graph_scale);
|
|
|
|
draw_string(tmp_str);
|
|
|
|
free(tmp_str);
|
|
|
|
cur_x = tmp_x;
|
|
|
|
cur_y = tmp_y;
|
|
|
|
}
|
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();
|
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,
|
|
|
|
text_width, cur_x, get_string_width(s), gap_x,
|
|
|
|
specials[special_index].arg); */
|
|
|
|
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++;
|
|
|
|
}
|
2005-08-08 01:18:52 +00:00
|
|
|
#else
|
|
|
|
draw_string(s);
|
|
|
|
#endif
|
|
|
|
#ifdef X11
|
2005-07-30 12:02:48 +00:00
|
|
|
if (cur_y_add > 0) {
|
|
|
|
cur_y += cur_y_add;
|
2005-07-30 12:45:06 +00:00
|
|
|
cur_y -= font_descent();
|
2005-07-30 12:02:48 +00:00
|
|
|
}
|
2005-07-20 00:30:40 +00:00
|
|
|
|
|
|
|
draw_string(s);
|
2005-08-04 02:17:25 +00:00
|
|
|
|
|
|
|
cur_y += font_descent();
|
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
|
2005-07-20 00:30:40 +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) {
|
2008-02-20 20:30:45 +00:00
|
|
|
char ss[2] = { stippled_borders, stippled_borders };
|
|
|
|
XSetLineAttributes(display, window.gc, border_width, LineOnOffDash,
|
|
|
|
CapButt, JoinMiter);
|
2005-07-20 00:30:40 +00:00
|
|
|
XSetDashes(display, window.gc, 0, ss, 2);
|
|
|
|
} else {
|
2008-02-20 20:30:45 +00:00
|
|
|
XSetLineAttributes(display, window.gc, border_width, LineSolid,
|
|
|
|
CapButt, JoinMiter);
|
2005-07-20 00:30:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
XDrawRectangle(display, window.drawable, window.gc,
|
2008-02-20 20:30:45 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
/* draw text */
|
|
|
|
special_index = 0;
|
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
|
|
|
{
|
2005-08-08 01:18:52 +00:00
|
|
|
#ifdef X11
|
2006-05-28 07:25:30 +00:00
|
|
|
selected_font = 0;
|
2005-07-20 00:30:40 +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;
|
2008-03-29 06:24:04 +00:00
|
|
|
selected_font = 0;
|
2008-02-20 20:30:45 +00:00
|
|
|
|
|
|
|
for (i = -1; i < 2; i++) {
|
2005-07-20 00:30:40 +00:00
|
|
|
for (j = -1; j < 2; j++) {
|
2008-02-20 20:30:45 +00:00
|
|
|
if (i == 0 && j == 0) {
|
2005-07-20 00:30:40 +00:00
|
|
|
continue;
|
2008-02-20 20:30:45 +00:00
|
|
|
}
|
2005-07-20 00:30:40 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
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
|
2006-11-07 02:19:58 +00:00
|
|
|
#ifdef HAVE_XDBE
|
2005-07-20 00:30:40 +00:00
|
|
|
if (use_xdbe) {
|
|
|
|
XdbeSwapInfo swap;
|
2008-02-20 20:30:45 +00:00
|
|
|
|
2005-07-20 00:30:40 +00:00
|
|
|
swap.swap_window = window.window;
|
|
|
|
swap.swap_action = XdbeBackground;
|
|
|
|
XdbeSwapBuffers(display, &swap, 1);
|
|
|
|
}
|
|
|
|
#endif
|
2005-08-08 01:18:52 +00:00
|
|
|
#endif /* X11 */
|
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
|
2005-07-20 00:30:40 +00:00
|
|
|
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-02-20 20:30:45 +00:00
|
|
|
sigset_t newmask, oldmask;
|
2005-11-24 02:18:42 +00:00
|
|
|
#endif
|
2005-08-08 01:18:52 +00:00
|
|
|
#ifdef X11
|
2005-07-20 00:30:40 +00:00
|
|
|
Region region = XCreateRegion();
|
2008-02-20 20:30:45 +00:00
|
|
|
|
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;
|
2008-02-20 20:30:45 +00:00
|
|
|
|
|
|
|
if (!XDamageQueryExtension(display, &event_base, &error_base)) {
|
2006-05-24 06:34:37 +00:00
|
|
|
ERR("Xdamage extension unavailable");
|
|
|
|
}
|
2008-03-29 06:24:04 +00:00
|
|
|
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 */
|
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
|
|
|
|
|
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
|
2005-07-20 00:30:40 +00:00
|
|
|
XFlush(display);
|
|
|
|
|
|
|
|
/* wait for X event or timeout */
|
|
|
|
|
|
|
|
if (!XPending(display)) {
|
|
|
|
fd_set fdsr;
|
|
|
|
struct timeval tv;
|
|
|
|
int s;
|
2008-02-20 20:30:45 +00:00
|
|
|
double t = update_interval - (get_time() - last_update_time);
|
2005-07-20 00:30:40 +00:00
|
|
|
|
2008-02-20 20:30:45 +00:00
|
|
|
if (t < 0) {
|
2005-07-20 00:30:40 +00:00
|
|
|
t = 0;
|
2008-02-20 20:30:45 +00:00
|
|
|
}
|
2005-07-20 00:30:40 +00:00
|
|
|
|
|
|
|
tv.tv_sec = (long) t;
|
|
|
|
tv.tv_usec = (long) (t * 1000000) % 1000000;
|
|
|
|
FD_ZERO(&fdsr);
|
|
|
|
FD_SET(ConnectionNumber(display), &fdsr);
|
|
|
|
|
2008-02-20 20:30:45 +00:00
|
|
|
s = select(ConnectionNumber(display) + 1, &fdsr, 0, 0, &tv);
|
2005-07-20 00:30:40 +00:00
|
|
|
if (s == -1) {
|
2008-02-20 20:30:45 +00:00
|
|
|
if (errno != EINTR) {
|
|
|
|
ERR("can't select(): %s", strerror(errno));
|
|
|
|
}
|
2005-07-20 00:30:40 +00:00
|
|
|
} else {
|
|
|
|
/* timeout */
|
2008-02-20 20:30:45 +00:00
|
|
|
if (s == 0) {
|
|
|
|
#else
|
|
|
|
/* FIXME just sleep for the interval time if no X11 */
|
|
|
|
usleep(update_interval * 1000000);
|
2005-08-08 01:18:52 +00:00
|
|
|
#endif /* X11 */
|
2005-07-20 00:30:40 +00:00
|
|
|
update_text();
|
2005-08-08 01:18:52 +00:00
|
|
|
#ifdef X11
|
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
|
|
|
if (need_to_update) {
|
|
|
|
#ifdef OWN_WINDOW
|
|
|
|
int wx = window.x, wy = window.y;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
need_to_update = 0;
|
2006-05-28 07:25:30 +00:00
|
|
|
selected_font = 0;
|
2005-07-20 00:30:40 +00:00
|
|
|
update_text_area();
|
|
|
|
#ifdef OWN_WINDOW
|
|
|
|
if (own_window) {
|
|
|
|
/* resize window if it isn't right size */
|
2008-02-20 20:30:45 +00:00
|
|
|
if (!fixed_size
|
|
|
|
&& (text_width + border_margin * 2 + 1 != window.width
|
|
|
|
|| text_height + border_margin * 2 + 1 != window.height)) {
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
2005-07-20 00:30:40 +00:00
|
|
|
|
|
|
|
/* move window if it isn't in right position */
|
2008-02-20 20:30:45 +00:00
|
|
|
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
|
|
|
|
|
|
|
|
clear_text(1);
|
|
|
|
|
2006-11-07 02:19:58 +00:00
|
|
|
#ifdef HAVE_XDBE
|
2005-07-20 00:30:40 +00:00
|
|
|
if (use_xdbe) {
|
|
|
|
XRectangle r;
|
2008-02-20 20:30:45 +00:00
|
|
|
|
2005-07-20 00:30:40 +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);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/* handle X events */
|
|
|
|
while (XPending(display)) {
|
|
|
|
XEvent ev;
|
2008-02-20 20:30:45 +00:00
|
|
|
|
2005-07-20 00:30:40 +00:00
|
|
|
XNextEvent(display, &ev);
|
|
|
|
switch (ev.type) {
|
2008-02-20 20:30:45 +00:00
|
|
|
case Expose:
|
2005-07-20 00:30:40 +00:00
|
|
|
{
|
|
|
|
XRectangle r;
|
2008-02-20 20:30:45 +00:00
|
|
|
|
2005-07-20 00:30:40 +00:00
|
|
|
r.x = ev.xexpose.x;
|
|
|
|
r.y = ev.xexpose.y;
|
|
|
|
r.width = ev.xexpose.width;
|
|
|
|
r.height = ev.xexpose.height;
|
2008-02-20 20:30:45 +00:00
|
|
|
XUnionRectWithRegion(&r, region, region);
|
|
|
|
break;
|
2005-07-20 00:30:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef OWN_WINDOW
|
2008-02-20 20:30:45 +00:00
|
|
|
case ReparentNotify:
|
|
|
|
/* set background to ParentRelative for all parents */
|
|
|
|
if (own_window) {
|
|
|
|
set_transparent_background(window.window);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
{
|
|
|
|
XWindowAttributes attrs;
|
|
|
|
|
|
|
|
if (XGetWindowAttributes(display,
|
|
|
|
window.window, &attrs)) {
|
|
|
|
window.width = attrs.width;
|
|
|
|
window.height = attrs.height;
|
|
|
|
}
|
|
|
|
}
|
2005-07-20 00:30:40 +00:00
|
|
|
|
2008-02-20 20:30:45 +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;
|
2005-07-20 00:30:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-02-20 20:30:45 +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
|
|
|
}
|
2008-02-20 20:30:45 +00:00
|
|
|
break;
|
2005-07-20 00:30:40 +00:00
|
|
|
|
2008-02-20 20:30:45 +00:00
|
|
|
case ButtonPress:
|
|
|
|
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 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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2006-03-08 23:02:28 +00:00
|
|
|
|
2008-02-20 20:30:45 +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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2006-03-08 23:02:28 +00:00
|
|
|
|
2005-07-20 00:30:40 +00:00
|
|
|
#endif
|
|
|
|
|
2008-02-20 20:30:45 +00:00
|
|
|
default:
|
2006-08-01 21:24:15 +00:00
|
|
|
#ifdef HAVE_XDAMAGE
|
2008-02-20 20:30:45 +00:00
|
|
|
if (ev.type == event_base + XDamageNotify) {
|
|
|
|
XDamageNotifyEvent *dev = (XDamageNotifyEvent *) &ev;
|
|
|
|
|
|
|
|
XFixesSetRegion(display, part, &dev->area, 1);
|
|
|
|
XFixesUnionRegion(display, region2, region2, part);
|
|
|
|
}
|
2006-08-01 21:24:15 +00:00
|
|
|
#endif /* HAVE_XDAMAGE */
|
2008-02-20 20:30:45 +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
|
|
|
|
XDamageSubtract(display, damage, region2, None);
|
|
|
|
XFixesSetRegion(display, region2, 0, 0);
|
|
|
|
#endif /* HAVE_XDAMAGE */
|
2005-07-20 00:30:40 +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
|
2008-02-20 20:30:45 +00:00
|
|
|
* and we can safely do nothing. */
|
2005-07-20 00:30:40 +00:00
|
|
|
|
|
|
|
if (!XEmptyRegion(region)) {
|
2006-11-07 02:19:58 +00:00
|
|
|
#ifdef HAVE_XDBE
|
2005-07-20 00:30:40 +00:00
|
|
|
if (use_xdbe) {
|
|
|
|
XRectangle r;
|
2008-02-20 20:30:45 +00:00
|
|
|
|
2005-07-20 00:30:40 +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);
|
2008-02-20 20:30:45 +00:00
|
|
|
}
|
2005-07-20 00:30:40 +00:00
|
|
|
#endif
|
|
|
|
XSetRegion(display, window.gc, region);
|
|
|
|
#ifdef XFT
|
2005-08-29 17:06:31 +00:00
|
|
|
if (use_xft) {
|
2005-07-20 00:30:40 +00:00
|
|
|
XftDrawSetClip(window.xftdraw, region);
|
2005-08-29 17:06:31 +00:00
|
|
|
}
|
2005-07-20 00:30:40 +00:00
|
|
|
#endif
|
2005-08-08 01:18:52 +00:00
|
|
|
#endif /* X11 */
|
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
|
|
|
XDestroyRegion(region);
|
|
|
|
region = XCreateRegion();
|
|
|
|
}
|
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
|
2008-02-20 20:30:45 +00:00
|
|
|
XDestroyRegion(region);
|
|
|
|
region = NULL;
|
2008-03-20 05:28:23 +00:00
|
|
|
#ifdef HAVE_XDAMAGE
|
2008-03-24 21:44:50 +00:00
|
|
|
XDamageDestroy(display, damage);
|
|
|
|
XFixesDestroyRegion(display, region2);
|
|
|
|
XFixesDestroyRegion(display, part);
|
2008-03-20 05:28:23 +00:00
|
|
|
#endif /* HAVE_XDAMAGE */
|
2005-11-10 04:19:43 +00:00
|
|
|
#endif /* X11 */
|
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)
|
2006-05-25 01:00:29 +00:00
|
|
|
XDamageDestroy(display, damage);
|
|
|
|
XFixesDestroyRegion(display, region2);
|
|
|
|
XFixesDestroyRegion(display, part);
|
2005-11-10 04:19:43 +00:00
|
|
|
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 *);
|
|
|
|
|
2005-11-01 06:51:48 +00:00
|
|
|
/* reload the config file */
|
|
|
|
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 MPD
|
2008-02-20 20:30:45 +00:00
|
|
|
if (info.mpd.title) {
|
|
|
|
free(info.mpd.title);
|
|
|
|
info.mpd.title = NULL;
|
|
|
|
}
|
|
|
|
if (info.mpd.artist) {
|
|
|
|
free(info.mpd.artist);
|
|
|
|
info.mpd.artist = NULL;
|
|
|
|
}
|
|
|
|
if (info.mpd.album) {
|
|
|
|
free(info.mpd.album);
|
|
|
|
info.mpd.album = NULL;
|
|
|
|
}
|
|
|
|
if (info.mpd.random) {
|
|
|
|
free(info.mpd.random);
|
|
|
|
info.mpd.random = NULL;
|
|
|
|
}
|
|
|
|
if (info.mpd.repeat) {
|
|
|
|
free(info.mpd.repeat);
|
|
|
|
info.mpd.repeat = NULL;
|
|
|
|
}
|
|
|
|
if (info.mpd.track) {
|
|
|
|
free(info.mpd.track);
|
|
|
|
info.mpd.track = NULL;
|
|
|
|
}
|
|
|
|
if (info.mpd.name) {
|
|
|
|
free(info.mpd.name);
|
|
|
|
info.mpd.name = NULL;
|
|
|
|
}
|
|
|
|
if (info.mpd.file) {
|
|
|
|
free(info.mpd.file);
|
|
|
|
info.mpd.file = NULL;
|
|
|
|
}
|
|
|
|
if (info.mpd.status) {
|
|
|
|
free(info.mpd.status);
|
|
|
|
info.mpd.status = NULL;
|
2007-09-02 03:58:22 +00:00
|
|
|
}
|
|
|
|
#endif
|
2008-02-20 20:30:45 +00:00
|
|
|
|
2007-09-02 03:58:22 +00:00
|
|
|
#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-02-20 20:30:45 +00:00
|
|
|
destroy_tcp_port_monitor_collection(info.p_tcp_port_monitor_collection);
|
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);
|
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));
|
2005-10-22 01:37:44 +00:00
|
|
|
|
2005-08-08 01:18:52 +00:00
|
|
|
#endif /* X11 */
|
2005-10-31 05:17:06 +00:00
|
|
|
#ifdef TCP_PORT_MONITOR
|
2008-02-20 20:30:45 +00:00
|
|
|
info.p_tcp_port_monitor_collection = NULL;
|
2005-10-31 05:17:06 +00:00
|
|
|
#endif
|
2005-07-20 00:30:40 +00:00
|
|
|
extract_variable_text(text);
|
|
|
|
free(text);
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-11-01 06:51:48 +00:00
|
|
|
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
|
2006-11-07 02:19:58 +00:00
|
|
|
#ifdef HAVE_XDBE
|
2005-08-29 17:06:31 +00:00
|
|
|
if (use_xdbe) {
|
2005-07-20 00:30:40 +00:00
|
|
|
XdbeDeallocateBackBufferName(display, window.back_buffer);
|
2005-08-29 17:06:31 +00:00
|
|
|
}
|
2005-07-20 00:30:40 +00:00
|
|
|
#endif
|
|
|
|
#ifdef OWN_WINDOW
|
2008-02-20 20:30:45 +00:00
|
|
|
if (own_window) {
|
2005-07-20 00:30:40 +00:00
|
|
|
XDestroyWindow(display, window.window);
|
2006-02-14 06:15:38 +00:00
|
|
|
XClearWindow(display, RootWindow(display, screen));
|
|
|
|
XFlush(display);
|
2008-02-20 20:30:45 +00:00
|
|
|
} else
|
2005-07-20 00:30:40 +00:00
|
|
|
#endif
|
|
|
|
{
|
2005-08-21 08:23:04 +00:00
|
|
|
XClearWindow(display, RootWindow(display, screen));
|
2005-07-20 00:30:40 +00:00
|
|
|
clear_text(1);
|
|
|
|
XFlush(display);
|
|
|
|
}
|
|
|
|
|
|
|
|
XFreeGC(display, window.gc);
|
2007-09-02 03:58:22 +00:00
|
|
|
free_fonts();
|
2005-08-08 01:18:52 +00:00
|
|
|
#endif /* X11 */
|
|
|
|
|
2008-03-29 05:23:45 +00:00
|
|
|
free_text_objects(global_text_object_count, global_text_objects);
|
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;
|
|
|
|
}
|
2008-03-29 05:23:45 +00:00
|
|
|
global_text_object_count = 0;
|
|
|
|
global_text_objects = NULL;
|
2005-12-10 14:15:38 +00:00
|
|
|
|
2008-03-19 22:28:23 +00:00
|
|
|
if (text) {
|
2005-07-20 00:30:40 +00:00
|
|
|
free(text);
|
2008-03-19 22:28:23 +00:00
|
|
|
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-02-20 20:30:45 +00:00
|
|
|
destroy_tcp_port_monitor_collection(info.p_tcp_port_monitor_collection);
|
2005-10-31 05:17:06 +00:00
|
|
|
info.p_tcp_port_monitor_collection = NULL;
|
|
|
|
#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-02-24 16:35:18 +00:00
|
|
|
return 1;
|
2008-02-20 20:30:45 +00:00
|
|
|
} else if (strcasecmp(s, "yes") == 0) {
|
2008-02-24 16:35:18 +00:00
|
|
|
return 1;
|
2008-02-20 20:30:45 +00:00
|
|
|
} else if (strcasecmp(s, "true") == 0) {
|
2008-02-24 16:35:18 +00:00
|
|
|
return 1;
|
2008-02-20 20:30:45 +00:00
|
|
|
} else if (strcasecmp(s, "1") == 0) {
|
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-02-20 20:30:45 +00:00
|
|
|
if (strcasecmp(s, "top_left") == 0) {
|
2005-07-20 00:30:40 +00:00
|
|
|
return TOP_LEFT;
|
2008-02-20 20:30:45 +00:00
|
|
|
} else if (strcasecmp(s, "top_right") == 0) {
|
2005-07-20 00:30:40 +00:00
|
|
|
return TOP_RIGHT;
|
2008-03-18 00:23:16 +00:00
|
|
|
} else if (strcasecmp(s, "top_middle") == 0) {
|
|
|
|
return TOP_MIDDLE;
|
2008-02-20 20:30:45 +00:00
|
|
|
} else if (strcasecmp(s, "bottom_left") == 0) {
|
2005-07-20 00:30:40 +00:00
|
|
|
return BOTTOM_LEFT;
|
2008-02-20 20:30:45 +00:00
|
|
|
} else if (strcasecmp(s, "bottom_right") == 0) {
|
2005-07-20 00:30:40 +00:00
|
|
|
return BOTTOM_RIGHT;
|
2008-03-18 00:23:16 +00:00
|
|
|
} else if (strcasecmp(s, "bottom_middle") == 0) {
|
|
|
|
return BOTTOM_MIDDLE;
|
|
|
|
} else if (strcasecmp(s, "middle_left") == 0) {
|
|
|
|
return MIDDLE_LEFT;
|
|
|
|
} else if (strcasecmp(s, "middle_right") == 0) {
|
|
|
|
return MIDDLE_RIGHT;
|
2008-02-20 20:30:45 +00:00
|
|
|
} else if (strcasecmp(s, "tl") == 0) {
|
2005-07-20 00:30:40 +00:00
|
|
|
return TOP_LEFT;
|
2008-02-20 20:30:45 +00:00
|
|
|
} else if (strcasecmp(s, "tr") == 0) {
|
2005-07-20 00:30:40 +00:00
|
|
|
return TOP_RIGHT;
|
2008-03-18 00:23:16 +00:00
|
|
|
} else if (strcasecmp(s, "tm") == 0) {
|
|
|
|
return TOP_MIDDLE;
|
2008-02-20 20:30:45 +00:00
|
|
|
} else if (strcasecmp(s, "bl") == 0) {
|
2005-07-20 00:30:40 +00:00
|
|
|
return BOTTOM_LEFT;
|
2008-02-20 20:30:45 +00:00
|
|
|
} else if (strcasecmp(s, "br") == 0) {
|
2005-07-20 00:30:40 +00:00
|
|
|
return BOTTOM_RIGHT;
|
2008-03-18 00:23:16 +00:00
|
|
|
} else if (strcasecmp(s, "bm") == 0) {
|
|
|
|
return BOTTOM_MIDDLE;
|
|
|
|
} else if (strcasecmp(s, "ml") == 0) {
|
|
|
|
return MIDDLE_LEFT;
|
|
|
|
} else if (strcasecmp(s, "mr") == 0) {
|
|
|
|
return MIDDLE_RIGHT;
|
2008-02-20 20:30:45 +00:00
|
|
|
} else if (strcasecmp(s, "none") == 0) {
|
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 */
|
|
|
|
|
2005-07-20 00:30:40 +00:00
|
|
|
static void set_default_configurations(void)
|
|
|
|
{
|
|
|
|
fork_to_background = 0;
|
|
|
|
total_run_times = 0;
|
|
|
|
info.cpu_avg_samples = 2;
|
|
|
|
info.net_avg_samples = 2;
|
|
|
|
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;
|
2005-07-20 00:30:40 +00:00
|
|
|
#ifdef MPD
|
2005-07-24 23:08:51 +00:00
|
|
|
strcpy(info.mpd.host, "localhost");
|
2005-07-20 00:30:40 +00:00
|
|
|
info.mpd.port = 6600;
|
2006-01-31 03:32:26 +00:00
|
|
|
info.mpd.status = NULL;
|
|
|
|
info.mpd.artist = NULL;
|
|
|
|
info.mpd.album = NULL;
|
|
|
|
info.mpd.title = NULL;
|
|
|
|
info.mpd.random = NULL;
|
|
|
|
info.mpd.track = NULL;
|
|
|
|
info.mpd.name = NULL;
|
|
|
|
info.mpd.file = NULL;
|
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
|
|
|
|
out_to_console = 0;
|
|
|
|
#else
|
|
|
|
out_to_console = 1;
|
|
|
|
#endif
|
|
|
|
#ifdef X11
|
2008-04-13 04:10:35 +00:00
|
|
|
show_graph_scale = 0;
|
2005-07-20 00:30:40 +00:00
|
|
|
default_fg_color = WhitePixel(display, screen);
|
|
|
|
default_bg_color = BlackPixel(display, screen);
|
|
|
|
default_out_color = BlackPixel(display, screen);
|
2007-04-25 17:22:06 +00:00
|
|
|
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;
|
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;
|
|
|
|
strcpy(window.class_name, "Conky");
|
2007-09-02 03:02:33 +00:00
|
|
|
update_uname();
|
2008-02-20 20:30:45 +00:00
|
|
|
sprintf(window.title, "Conky (%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;
|
|
|
|
#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-02-20 20:30:45 +00:00
|
|
|
tcp_port_monitor_args.max_port_monitor_connections =
|
|
|
|
MAX_PORT_MONITOR_CONNECTIONS_DEFAULT;
|
2005-11-11 03:28:24 +00:00
|
|
|
#endif
|
2005-07-20 00:30:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void load_config_file(const char *f)
|
|
|
|
{
|
2005-07-30 22:59:01 +00:00
|
|
|
#define CONF_ERR ERR("%s: %d: config file error", f, line)
|
2005-07-20 00:30:40 +00:00
|
|
|
int line = 0;
|
|
|
|
FILE *fp;
|
|
|
|
|
|
|
|
set_default_configurations();
|
2005-11-12 04:26:00 +00:00
|
|
|
fp = fopen(f, "r");
|
2008-02-20 20:30:45 +00:00
|
|
|
if (!fp) {
|
2005-07-20 00:30:40 +00:00
|
|
|
return;
|
2008-02-20 20:30:45 +00:00
|
|
|
}
|
2005-07-20 00:30:40 +00:00
|
|
|
|
|
|
|
while (!feof(fp)) {
|
|
|
|
char buf[256], *p, *p2, *name, *value;
|
2008-02-20 20:30:45 +00:00
|
|
|
|
2005-07-20 00:30:40 +00:00
|
|
|
line++;
|
2008-02-20 20:30:45 +00:00
|
|
|
if (fgets(buf, 256, fp) == NULL) {
|
2005-07-20 00:30:40 +00:00
|
|
|
break;
|
2008-02-20 20:30:45 +00:00
|
|
|
}
|
2005-07-20 00:30:40 +00:00
|
|
|
|
|
|
|
p = buf;
|
|
|
|
|
|
|
|
/* break at comment */
|
|
|
|
p2 = strchr(p, '#');
|
2008-02-20 20:30:45 +00:00
|
|
|
if (p2) {
|
2005-07-20 00:30:40 +00:00
|
|
|
*p2 = '\0';
|
2008-02-20 20:30:45 +00:00
|
|
|
}
|
2005-07-20 00:30:40 +00:00
|
|
|
|
|
|
|
/* skip spaces */
|
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
|
|
|
}
|
|
|
|
if (*p == '\0') {
|
2005-07-20 00:30:40 +00:00
|
|
|
continue; /* empty line */
|
2008-02-20 20:30:45 +00:00
|
|
|
}
|
2005-07-20 00:30:40 +00:00
|
|
|
|
|
|
|
name = p;
|
|
|
|
|
|
|
|
/* skip name */
|
|
|
|
p2 = p;
|
2008-02-20 20:30:45 +00:00
|
|
|
while (*p2 && !isspace((int) *p2)) {
|
2005-07-20 00:30:40 +00:00
|
|
|
p2++;
|
2008-02-20 20:30:45 +00:00
|
|
|
}
|
2005-07-20 00:30:40 +00:00
|
|
|
if (*p2 != '\0') {
|
|
|
|
*p2 = '\0'; /* break at name's end */
|
|
|
|
p2++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 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
|
|
|
|
|
|
|
value = p;
|
|
|
|
|
|
|
|
p2 = value + strlen(value);
|
2008-02-20 20:30:45 +00:00
|
|
|
while (isspace((int) *(p2 - 1))) {
|
2005-07-20 00:30:40 +00:00
|
|
|
*--p2 = '\0';
|
2008-02-20 20:30:45 +00:00
|
|
|
}
|
2005-07-20 00:30:40 +00:00
|
|
|
} else {
|
|
|
|
value = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define CONF2(a) if (strcasecmp(name, a) == 0)
|
|
|
|
#define CONF(a) else CONF2(a)
|
2008-02-20 20:30:45 +00:00
|
|
|
#define CONF3(a, b) else if (strcasecmp(name, a) == 0 \
|
|
|
|
|| strcasecmp(name, b) == 0)
|
2005-07-20 00:30:40 +00:00
|
|
|
|
2005-08-08 01:18:52 +00:00
|
|
|
#ifdef X11
|
2005-07-20 00:30:40 +00:00
|
|
|
CONF2("alignment") {
|
2008-02-20 20:30:45 +00:00
|
|
|
if (value) {
|
|
|
|
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);
|
|
|
|
}
|
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
|
|
|
}
|
2007-04-25 17:22:06 +00:00
|
|
|
CONF("color0") {
|
2008-02-20 20:30:45 +00:00
|
|
|
if (value) {
|
2007-04-25 17:22:06 +00:00
|
|
|
color0 = get_x11_color(value);
|
2008-02-20 20:30:45 +00:00
|
|
|
} else {
|
2007-04-25 17:22:06 +00:00
|
|
|
CONF_ERR;
|
2008-02-20 20:30:45 +00:00
|
|
|
}
|
2007-04-25 17:22:06 +00:00
|
|
|
}
|
|
|
|
CONF("color1") {
|
2008-02-20 20:30:45 +00:00
|
|
|
if (value) {
|
2007-04-25 17:22:06 +00:00
|
|
|
color1 = get_x11_color(value);
|
2008-02-20 20:30:45 +00:00
|
|
|
} else {
|
2007-04-25 17:22:06 +00:00
|
|
|
CONF_ERR;
|
2008-02-20 20:30:45 +00:00
|
|
|
}
|
2007-04-25 17:22:06 +00:00
|
|
|
}
|
|
|
|
CONF("color2") {
|
2008-02-20 20:30:45 +00:00
|
|
|
if (value) {
|
2007-04-25 17:22:06 +00:00
|
|
|
color2 = get_x11_color(value);
|
2008-02-20 20:30:45 +00:00
|
|
|
} else {
|
2007-04-25 17:22:06 +00:00
|
|
|
CONF_ERR;
|
2008-02-20 20:30:45 +00:00
|
|
|
}
|
2007-04-25 17:22:06 +00:00
|
|
|
}
|
|
|
|
CONF("color3") {
|
2008-02-20 20:30:45 +00:00
|
|
|
if (value) {
|
2007-04-25 17:22:06 +00:00
|
|
|
color3 = get_x11_color(value);
|
2008-02-20 20:30:45 +00:00
|
|
|
} else {
|
2007-04-25 17:22:06 +00:00
|
|
|
CONF_ERR;
|
2008-02-20 20:30:45 +00:00
|
|
|
}
|
2007-04-25 17:22:06 +00:00
|
|
|
}
|
|
|
|
CONF("color4") {
|
2008-02-20 20:30:45 +00:00
|
|
|
if (value) {
|
2007-04-25 17:22:06 +00:00
|
|
|
color4 = get_x11_color(value);
|
2008-02-20 20:30:45 +00:00
|
|
|
} else {
|
2007-04-25 17:22:06 +00:00
|
|
|
CONF_ERR;
|
2008-02-20 20:30:45 +00:00
|
|
|
}
|
2007-04-25 17:22:06 +00:00
|
|
|
}
|
|
|
|
CONF("color5") {
|
2008-02-20 20:30:45 +00:00
|
|
|
if (value) {
|
2007-04-25 17:22:06 +00:00
|
|
|
color5 = get_x11_color(value);
|
2008-02-20 20:30:45 +00:00
|
|
|
} else {
|
2007-04-25 17:22:06 +00:00
|
|
|
CONF_ERR;
|
2008-02-20 20:30:45 +00:00
|
|
|
}
|
2007-04-25 17:22:06 +00:00
|
|
|
}
|
|
|
|
CONF("color6") {
|
2008-02-20 20:30:45 +00:00
|
|
|
if (value) {
|
2007-04-25 17:22:06 +00:00
|
|
|
color6 = get_x11_color(value);
|
2008-02-20 20:30:45 +00:00
|
|
|
} else {
|
2007-04-25 17:22:06 +00:00
|
|
|
CONF_ERR;
|
2008-02-20 20:30:45 +00:00
|
|
|
}
|
2007-04-25 17:22:06 +00:00
|
|
|
}
|
|
|
|
CONF("color7") {
|
2008-02-20 20:30:45 +00:00
|
|
|
if (value) {
|
2007-04-25 17:22:06 +00:00
|
|
|
color7 = get_x11_color(value);
|
2008-02-20 20:30:45 +00:00
|
|
|
} else {
|
2007-04-25 17:22:06 +00:00
|
|
|
CONF_ERR;
|
2008-02-20 20:30:45 +00:00
|
|
|
}
|
2007-04-25 17:22:06 +00:00
|
|
|
}
|
|
|
|
CONF("color8") {
|
2008-02-20 20:30:45 +00:00
|
|
|
if (value) {
|
2007-04-25 17:22:06 +00:00
|
|
|
color8 = get_x11_color(value);
|
2008-02-20 20:30:45 +00:00
|
|
|
} else {
|
2007-04-25 17:22:06 +00:00
|
|
|
CONF_ERR;
|
2008-02-20 20:30:45 +00:00
|
|
|
}
|
2007-04-25 17:22:06 +00:00
|
|
|
}
|
|
|
|
CONF("color9") {
|
2008-02-20 20:30:45 +00:00
|
|
|
if (value) {
|
2007-04-25 17:22:06 +00:00
|
|
|
color9 = get_x11_color(value);
|
2008-02-20 20:30:45 +00:00
|
|
|
} else {
|
2007-04-25 17:22:06 +00:00
|
|
|
CONF_ERR;
|
2008-02-20 20:30:45 +00:00
|
|
|
}
|
2007-04-25 17:22:06 +00:00
|
|
|
}
|
2005-07-30 22:59:01 +00:00
|
|
|
CONF("default_color") {
|
2008-02-20 20:30:45 +00:00
|
|
|
if (value) {
|
2005-07-30 22:59:01 +00:00
|
|
|
default_fg_color = get_x11_color(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
|
|
|
}
|
|
|
|
CONF3("default_shade_color", "default_shadecolor") {
|
2008-02-20 20:30:45 +00:00
|
|
|
if (value) {
|
2005-07-30 22:59:01 +00:00
|
|
|
default_bg_color = get_x11_color(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
|
|
|
}
|
|
|
|
CONF3("default_outline_color", "default_outlinecolor") {
|
2008-02-20 20:30:45 +00:00
|
|
|
if (value) {
|
2005-07-30 22:59:01 +00:00
|
|
|
default_out_color = get_x11_color(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 */
|
2006-05-08 22:34:38 +00:00
|
|
|
CONF("imap") {
|
|
|
|
if (value) {
|
2006-05-09 22:39:39 +00:00
|
|
|
info.mail = parse_mail_args(IMAP, value);
|
2006-05-08 22:34:38 +00:00
|
|
|
} else {
|
|
|
|
CONF_ERR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
CONF("pop3") {
|
|
|
|
if (value) {
|
2006-05-14 06:15:23 +00:00
|
|
|
info.mail = parse_mail_args(POP3, value);
|
2006-05-08 22:34:38 +00:00
|
|
|
} else {
|
|
|
|
CONF_ERR;
|
|
|
|
}
|
|
|
|
}
|
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) {
|
2006-01-31 03:32:26 +00:00
|
|
|
strncpy(info.mpd.host, value, 127);
|
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") {
|
|
|
|
if (value) {
|
|
|
|
info.mpd.port = strtol(value, 0, 0);
|
2008-02-20 20:30:45 +00:00
|
|
|
if (info.mpd.port < 1 || info.mpd.port > 0xffff) {
|
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
|
|
|
}
|
|
|
|
}
|
2006-01-31 03:32:26 +00:00
|
|
|
CONF("mpd_password") {
|
2008-02-20 20:30:45 +00:00
|
|
|
if (value) {
|
2006-01-31 03:32:26 +00:00
|
|
|
strncpy(info.mpd.password, value, 127);
|
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
|
|
|
}
|
|
|
|
|
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") {
|
|
|
|
out_to_console = string_to_bool(value);
|
|
|
|
}
|
|
|
|
CONF("use_spacer") {
|
2008-02-09 02:21:06 +00:00
|
|
|
if (value) {
|
|
|
|
if (strcasecmp(value, "left") == 0) {
|
|
|
|
use_spacer = LEFT_SPACER;
|
|
|
|
} else if (strcasecmp(value, "right") == 0) {
|
|
|
|
use_spacer = RIGHT_SPACER;
|
|
|
|
} else if (strcasecmp(value, "none") == 0) {
|
|
|
|
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") {
|
2005-12-31 17:36:16 +00:00
|
|
|
if (value) {
|
|
|
|
set_first_font(value);
|
2008-02-20 20:30:45 +00:00
|
|
|
} else {
|
2005-12-31 17:36:16 +00:00
|
|
|
CONF_ERR;
|
2008-02-20 20:30:45 +00:00
|
|
|
}
|
2005-07-30 22:59:01 +00:00
|
|
|
}
|
|
|
|
CONF("xftalpha") {
|
2008-02-20 20:30:45 +00:00
|
|
|
if (value && font_count >= 0) {
|
|
|
|
fonts[0].font_alpha = atof(value) * 65535.0;
|
|
|
|
} 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("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
|
2005-12-31 17:36:16 +00:00
|
|
|
if (value) {
|
|
|
|
set_first_font(value);
|
2008-02-20 20:30:45 +00:00
|
|
|
} else {
|
2005-12-31 17:36:16 +00:00
|
|
|
CONF_ERR;
|
2008-02-20 20:30:45 +00:00
|
|
|
}
|
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);
|
|
|
|
}
|
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") {
|
2008-02-20 20:30:45 +00:00
|
|
|
if (value) {
|
|
|
|
own_window = string_to_bool(value);
|
|
|
|
} else {
|
|
|
|
CONF_ERR;
|
|
|
|
}
|
2006-12-23 06:01:16 +00:00
|
|
|
}
|
|
|
|
CONF("own_window_class") {
|
2008-02-20 20:30:45 +00:00
|
|
|
if (value) {
|
|
|
|
memset(window.class_name, 0, sizeof(window.class_name));
|
|
|
|
strncpy(window.class_name, value,
|
|
|
|
sizeof(window.class_name) - 1);
|
|
|
|
} else {
|
|
|
|
CONF_ERR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
CONF("own_window_title") {
|
|
|
|
if (value) {
|
|
|
|
memset(window.title, 0, sizeof(window.title));
|
|
|
|
strncpy(window.title, value, sizeof(window.title) - 1);
|
|
|
|
} else {
|
|
|
|
CONF_ERR;
|
|
|
|
}
|
|
|
|
}
|
2005-08-25 09:24:26 +00:00
|
|
|
CONF("own_window_transparent") {
|
2008-02-20 20:30:45 +00:00
|
|
|
if (value) {
|
|
|
|
set_transparent = string_to_bool(value);
|
|
|
|
} else {
|
|
|
|
CONF_ERR;
|
|
|
|
}
|
2005-08-25 09:24:26 +00:00
|
|
|
}
|
|
|
|
CONF("own_window_colour") {
|
2006-02-13 02:28:46 +00:00
|
|
|
if (value) {
|
|
|
|
background_colour = get_x11_color(value);
|
|
|
|
} else {
|
2008-02-20 20:30:45 +00:00
|
|
|
ERR("Invalid colour for own_window_colour (try omitting the "
|
|
|
|
"'#' for hex colours");
|
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") {
|
|
|
|
if (value) {
|
|
|
|
char *p_hint, *p_save;
|
|
|
|
char delim[] = ", ";
|
|
|
|
|
|
|
|
/* tokenize the value into individual hints */
|
2008-02-20 20:30:45 +00:00
|
|
|
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) == 0) {
|
|
|
|
SET_HINT(window.hints, HINT_UNDECORATED);
|
|
|
|
} else if (strncmp(p_hint, "below", 5) == 0) {
|
|
|
|
SET_HINT(window.hints, HINT_BELOW);
|
|
|
|
} else if (strncmp(p_hint, "above", 5) == 0) {
|
|
|
|
SET_HINT(window.hints, HINT_ABOVE);
|
|
|
|
} else if (strncmp(p_hint, "sticky", 6) == 0) {
|
|
|
|
SET_HINT(window.hints, HINT_STICKY);
|
|
|
|
} else if (strncmp(p_hint, "skip_taskbar", 12) == 0) {
|
|
|
|
SET_HINT(window.hints, HINT_SKIP_TASKBAR);
|
|
|
|
} else if (strncmp(p_hint, "skip_pager", 10) == 0) {
|
|
|
|
SET_HINT(window.hints, HINT_SKIP_PAGER);
|
|
|
|
} else {
|
|
|
|
CONF_ERR;
|
|
|
|
}
|
|
|
|
|
|
|
|
p_hint = strtok_r(NULL, delim, &p_save);
|
|
|
|
} while (p_hint != NULL);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
CONF_ERR;
|
|
|
|
}
|
2006-03-06 23:35:41 +00:00
|
|
|
}
|
2006-03-08 22:17:27 +00:00
|
|
|
CONF("own_window_type") {
|
|
|
|
if (value) {
|
2008-02-20 20:30:45 +00:00
|
|
|
if (strncmp(value, "normal", 6) == 0) {
|
2006-03-08 22:17:27 +00:00
|
|
|
window.type = TYPE_NORMAL;
|
2008-02-20 20:30:45 +00:00
|
|
|
} else if (strncmp(value, "desktop", 7) == 0) {
|
2006-03-08 22:17:27 +00:00
|
|
|
window.type = TYPE_DESKTOP;
|
2008-04-29 21:31:04 +00:00
|
|
|
} else if (strncmp(value, "dock", 7) == 0) {
|
|
|
|
window.type = TYPE_DOCK;
|
2008-02-20 20:30:45 +00:00
|
|
|
} else if (strncmp(value, "override", 8) == 0) {
|
2006-03-09 02:28:38 +00:00
|
|
|
window.type = TYPE_OVERRIDE;
|
2008-02-20 20:30:45 +00:00
|
|
|
} else {
|
|
|
|
CONF_ERR;
|
|
|
|
}
|
|
|
|
} 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-03-19 22:28:23 +00:00
|
|
|
if (text) {
|
2005-07-30 22:59:01 +00:00
|
|
|
free(text);
|
2008-03-19 22:28:23 +00:00
|
|
|
text = 0;
|
2008-02-20 20:30:45 +00:00
|
|
|
}
|
2005-07-30 22:59:01 +00:00
|
|
|
|
2008-02-20 20:30:45 +00:00
|
|
|
text = (char *) malloc(1);
|
|
|
|
text[0] = '\0';
|
2005-07-30 22:59:01 +00:00
|
|
|
|
|
|
|
while (!feof(fp)) {
|
2008-02-20 20:30:45 +00:00
|
|
|
unsigned int l = strlen(text);
|
|
|
|
|
|
|
|
if (fgets(buf, 256, fp) == NULL) {
|
2005-07-30 22:59:01 +00:00
|
|
|
break;
|
2008-02-20 20:30:45 +00:00
|
|
|
}
|
|
|
|
text = (char *) realloc(text, l + strlen(buf) + 1);
|
2005-07-30 22:59:01 +00:00
|
|
|
strcat(text, buf);
|
|
|
|
|
2008-02-20 20:30:45 +00:00
|
|
|
if (strlen(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-04-02 02:12:57 +00:00
|
|
|
if (strlen(text) < 1) {
|
|
|
|
CRIT_ERR("no text supplied in configuration; exiting");
|
|
|
|
}
|
2006-05-14 07:05:05 +00:00
|
|
|
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") {
|
|
|
|
if (!value || (sscanf(value, "%d",
|
|
|
|
&tcp_port_monitor_args.max_port_monitor_connections) != 1)
|
|
|
|
|| tcp_port_monitor_args.max_port_monitor_connections < 0) {
|
2005-11-11 22:21:34 +00:00
|
|
|
/* an error. use default, warn and continue. */
|
2008-02-20 20:30:45 +00:00
|
|
|
tcp_port_monitor_args.max_port_monitor_connections =
|
2006-12-09 05:40:08 +00:00
|
|
|
MAX_PORT_MONITOR_CONNECTIONS_DEFAULT;
|
2005-11-11 03:28:24 +00:00
|
|
|
CONF_ERR;
|
2008-02-20 20:30:45 +00:00
|
|
|
} else if (tcp_port_monitor_args.max_port_monitor_connections
|
|
|
|
== 0) {
|
2005-11-11 22:21:34 +00:00
|
|
|
/* no error, just use default */
|
2008-02-20 20:30:45 +00:00
|
|
|
tcp_port_monitor_args.max_port_monitor_connections =
|
2006-12-09 05:40:08 +00:00
|
|
|
MAX_PORT_MONITOR_CONNECTIONS_DEFAULT;
|
2005-11-11 22:21:34 +00:00
|
|
|
}
|
2008-02-20 20:30:45 +00:00
|
|
|
/* else tcp_port_monitor_args.max_port_monitor_connections > 0
|
|
|
|
* as per config */
|
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;
|
|
|
|
} else if (!strcmp(value, "up")) {
|
|
|
|
ifup_strictness = IFUP_UP;
|
|
|
|
} else if (!strcmp(value, "link")) {
|
|
|
|
ifup_strictness = IFUP_LINK;
|
|
|
|
} else if (!strcmp(value, "address")) {
|
|
|
|
ifup_strictness = IFUP_ADDR;
|
|
|
|
} else {
|
|
|
|
ERR("incorrect if_up_strictness value, defaulting to 'up'");
|
|
|
|
ifup_strictness = IFUP_UP;
|
|
|
|
}
|
|
|
|
}
|
2008-02-20 20:30:45 +00:00
|
|
|
else {
|
|
|
|
ERR("%s: %d: no such configuration: '%s'", f, line, name);
|
|
|
|
}
|
2005-07-20 00:30:40 +00:00
|
|
|
|
|
|
|
#undef CONF
|
|
|
|
#undef CONF2
|
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
|
|
|
|
2005-07-20 00:30:40 +00:00
|
|
|
#undef CONF_ERR
|
2006-05-13 19:51:26 +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-04-02 02:12:57 +00:00
|
|
|
if (!text) { // didn't supply any text
|
|
|
|
CRIT_ERR("missing text block in configuration; exiting");
|
|
|
|
}
|
2005-07-30 22:59:01 +00:00
|
|
|
}
|
2005-07-28 04:48:27 +00:00
|
|
|
|
2008-02-20 10:01:13 +00:00
|
|
|
/* : means that character before that takes an argument */
|
2008-06-03 21:01:40 +00:00
|
|
|
static const char *getopt_string = "vVqdt:u:i:hc:"
|
2005-08-08 01:18:52 +00:00
|
|
|
#ifdef X11
|
2008-02-20 20:30:45 +00:00
|
|
|
"x:y:w:a:f:"
|
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
|
2005-08-08 01:18:52 +00:00
|
|
|
#endif /* X11 */
|
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' },
|
|
|
|
{ "config", 1, NULL, 'c' },
|
|
|
|
{ "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' },
|
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));
|
2005-10-31 05:17:06 +00:00
|
|
|
|
2005-11-11 22:21:34 +00:00
|
|
|
#ifdef TCP_PORT_MONITOR
|
2008-02-20 20:30:45 +00:00
|
|
|
tcp_port_monitor_args.max_port_monitor_connections =
|
|
|
|
MAX_PORT_MONITOR_CONNECTIONS_DEFAULT;
|
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-02-20 20:30:45 +00:00
|
|
|
printf("Usage: %s [OPTION]...\n"
|
2008-06-03 21:01:40 +00:00
|
|
|
"Conky is a system monitor that renders text on desktop or to own transparent\n"
|
|
|
|
"window. Command line options will override configurations defined in config\n"
|
2008-02-20 20:30:45 +00:00
|
|
|
"file.\n"
|
2008-04-01 04:59:00 +00:00
|
|
|
" -v, --version version\n"
|
2008-06-03 21:01:40 +00:00
|
|
|
" -q, --quiet quiet mode\n"
|
2008-02-20 20:30:45 +00:00
|
|
|
" -c, --config=FILE config file to load\n"
|
|
|
|
" -d, --daemonize daemonize, fork to background\n"
|
|
|
|
" -h, --help help\n"
|
2005-08-08 01:18:52 +00:00
|
|
|
#ifdef X11
|
2008-04-01 04:59:00 +00:00
|
|
|
" -a, --alignment=ALIGNMENT text alignment on screen, {top,bottom,middle}_{left,right,middle}\n"
|
2008-02-20 20:30:45 +00:00
|
|
|
" -f, --font=FONT font to use\n"
|
2005-07-20 00:30:40 +00:00
|
|
|
#ifdef OWN_WINDOW
|
2008-02-20 20:30:45 +00:00
|
|
|
" -o, --own-window create own window to draw\n"
|
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, --double-buffer double buffer (prevents flickering)\n"
|
2005-07-20 00:30:40 +00:00
|
|
|
#endif
|
2008-02-20 20:30:45 +00:00
|
|
|
" -w, --window-id=WIN_ID window id to draw\n"
|
|
|
|
" -x X x position\n"
|
|
|
|
" -y Y y position\n"
|
2005-08-08 01:18:52 +00:00
|
|
|
#endif /* X11 */
|
2008-02-20 20:30:45 +00:00
|
|
|
" -t, --text=TEXT text to render, remember single quotes, like -t '$uptime'\n"
|
|
|
|
" -u, --interval=SECS update interval\n"
|
2008-04-01 04:59:00 +00:00
|
|
|
" -i COUNT number of times to update Conky (and quit)\n",
|
2008-02-20 20:30:45 +00:00
|
|
|
argv[0]
|
2008-01-06 01:35:14 +00:00
|
|
|
);
|
|
|
|
return 0;
|
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
|
|
|
}
|
|
|
|
}
|
2005-08-08 01:18:52 +00:00
|
|
|
#ifdef X11
|
2008-02-20 20:30:45 +00:00
|
|
|
/* initalize X BEFORE we load config.
|
|
|
|
* (we need to so that 'screen' is set) */
|
2005-07-30 22:59:01 +00:00
|
|
|
init_X11();
|
2005-08-08 01:18:52 +00:00
|
|
|
#endif /* X11 */
|
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) {
|
|
|
|
CRIT_ERR("no readable personal or system-wide config file found");
|
|
|
|
}
|
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;
|
2005-07-30 22:59:01 +00:00
|
|
|
|
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;
|
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-03-19 22:28:23 +00:00
|
|
|
if (text) {
|
2008-02-20 20:30:45 +00:00
|
|
|
free(text);
|
2008-03-19 22:28:23 +00:00
|
|
|
text = 0;
|
2008-02-20 20:30:45 +00:00
|
|
|
}
|
2008-04-02 18:44:49 +00:00
|
|
|
text = strndup(optarg, max_user_text);
|
2008-02-20 20:30:45 +00:00
|
|
|
convert_escapes(text);
|
|
|
|
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 */
|
2005-08-03 07:01:32 +00:00
|
|
|
load_fonts();
|
2005-08-08 01:18:52 +00:00
|
|
|
#endif /* X11 */
|
2005-07-30 22:59:01 +00:00
|
|
|
|
|
|
|
/* generate text and get initial size */
|
|
|
|
extract_variable_text(text);
|
2008-03-19 22:28:23 +00:00
|
|
|
if (text) {
|
2005-07-30 22:59:01 +00:00
|
|
|
free(text);
|
2008-03-19 22:28:23 +00:00
|
|
|
text = 0;
|
2005-08-06 00:26:14 +00:00
|
|
|
}
|
2005-07-30 22:59:01 +00:00
|
|
|
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:
|
|
|
|
ERR("Conky: couldn't fork() to background: %s",
|
|
|
|
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 */
|
|
|
|
fprintf(stderr, "Conky: forked to background, pid is %d\n",
|
|
|
|
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
|
2006-05-28 07:25:30 +00:00
|
|
|
selected_font = 0;
|
2005-07-30 22:59:01 +00:00
|
|
|
update_text_area(); /* to get initial size of the window */
|
|
|
|
|
2008-03-18 00:23:16 +00:00
|
|
|
#ifdef OWN_WINDOW
|
2008-02-20 20:30:45 +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 */
|
|
|
|
init_window(0, text_width + border_margin * 2 + 1,
|
|
|
|
text_height + border_margin * 2 + 1, set_transparent, 0,
|
|
|
|
argv, argc);
|
|
|
|
#endif /* OWN_WINDOW */
|
2008-02-20 20:30:45 +00:00
|
|
|
|
2006-05-28 07:25:30 +00:00
|
|
|
selected_font = 0;
|
2005-07-30 22:59:01 +00:00
|
|
|
update_text_area(); /* to position text/window on screen */
|
2005-08-08 01:18:52 +00:00
|
|
|
#endif /* X11 */
|
2005-07-20 00:30:40 +00:00
|
|
|
|
2005-08-08 01:18:52 +00:00
|
|
|
#ifdef X11
|
2005-07-20 00:30:40 +00:00
|
|
|
#ifdef OWN_WINDOW
|
2005-08-26 02:16:35 +00:00
|
|
|
if (own_window && !fixed_pos) {
|
2005-07-30 22:59:01 +00:00
|
|
|
XMoveWindow(display, window.window, window.x, window.y);
|
2005-08-26 02:16:35 +00:00
|
|
|
}
|
|
|
|
if (own_window) {
|
|
|
|
set_transparent_background(window.window);
|
|
|
|
}
|
2005-07-20 00:30:40 +00:00
|
|
|
#endif
|
|
|
|
|
2005-07-30 22:59:01 +00:00
|
|
|
create_gc();
|
|
|
|
|
|
|
|
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-02-20 20:30:45 +00:00
|
|
|
if (sigaction(SIGINT, &act, &oact) < 0
|
|
|
|
|| sigaction(SIGUSR1, &act, &oact) < 0
|
2008-03-18 00:23:16 +00:00
|
|
|
|| sigaction(SIGHUP,&act,&oact) < 0
|
2008-02-20 20:30:45 +00:00
|
|
|
|| sigaction(SIGTERM, &act, &oact) < 0) {
|
|
|
|
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 CONKY LOOP *
|
|
|
|
* *************** */
|
|
|
|
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
|
|
|
|
|
|
|
void signal_handler(int sig)
|
|
|
|
{
|
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
|
|
|
}
|