2005-08-05 01:06:17 +00:00
/*
* Conky , a system monitor , based on torsmo
2005-07-20 00:30:40 +00:00
*
* This program is licensed under BSD license , read COPYING
2005-08-05 01:06:17 +00:00
*
* $ Id $
2005-07-20 00:30:40 +00:00
*/
# include "conky.h"
# include <stdio.h>
# include <stdlib.h>
# include <string.h>
# include <ctype.h>
# include <time.h>
# include <locale.h>
# include <signal.h>
# include <unistd.h>
# include <string.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>
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>
2006-03-22 19:35:58 +00:00
2006-05-13 19:51:26 +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
2005-07-20 00:30:40 +00:00
# define CONFIG_FILE "$HOME / .conkyrc"
# define MAIL_FILE "$MAIL"
# define MAX_IF_BLOCK_DEPTH 5
2005-11-24 02:18:42 +00:00
/* #define SIGNAL_BLOCKING */
# undef SIGNAL_BLOCKING
2005-08-08 01:18:52 +00:00
# ifdef X11
2005-07-20 00:30:40 +00:00
/* alignments */
enum alignment {
TOP_LEFT = 1 ,
TOP_RIGHT ,
BOTTOM_LEFT ,
BOTTOM_RIGHT ,
2005-08-20 19:43:06 +00:00
NONE
2005-07-20 00:30:40 +00:00
} ;
2005-08-03 07:01:32 +00:00
/* for fonts */
struct font_list {
char name [ TEXT_BUFFER_SIZE ] ;
int num ;
XFontStruct * font ;
# ifdef XFT
XftFont * xftfont ;
int font_alpha ;
# endif
} ;
static int selected_font = 0 ;
static int font_count = - 1 ;
struct font_list * fonts = NULL ;
# ifdef XFT
# 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
# else
# define font_height() (fonts[selected_font].font->max_bounds.ascent + fonts[selected_font].font->max_bounds.descent)
# 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.
2005-08-06 04:46:16 +00:00
static void set_font ( ) ;
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 ) ;
}
2005-08-03 07:01:32 +00:00
if ( ( fonts = ( struct font_list * ) malloc ( sizeof ( struct font_list ) ) ) = = NULL ) {
CRIT_ERR ( " malloc " ) ;
}
}
fonts = realloc ( fonts , ( sizeof ( struct font_list ) * ( font_count + 1 ) ) ) ;
if ( fonts = = NULL ) {
CRIT_ERR ( " realloc in addfont " ) ;
}
if ( strlen ( data_in ) < TEXT_BUFFER_SIZE ) { // must account for null terminator
strncpy ( fonts [ font_count ] . name , data_in , 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 ) {
if ( ( fonts = ( struct font_list * ) malloc ( sizeof ( struct font_list ) ) ) = = NULL ) {
CRIT_ERR ( " malloc " ) ;
}
font_count + + ;
}
if ( strlen ( data_in ) > 1 ) {
strncpy ( fonts [ 0 ] . name , data_in , TEXT_BUFFER_SIZE - 1 ) ;
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
}
}
2005-08-06 04:46:16 +00:00
void free_fonts ( )
2005-08-03 07:01:32 +00:00
{
2005-08-06 04:46:16 +00:00
int i ;
2005-08-05 06:40:19 +00:00
for ( i = 0 ; i < = font_count ; i + + ) {
# ifdef XFT
if ( use_xft ) {
XftFontClose ( display , fonts [ i ] . xftfont ) ;
} else
# endif
{
XFreeFont ( display , fonts [ i ] . font ) ;
}
}
2005-08-03 07:01:32 +00:00
free ( fonts ) ;
2005-08-05 06:40:19 +00:00
fonts = NULL ;
font_count = - 1 ;
selected_font = 0 ;
2005-08-06 04:46:16 +00:00
set_first_font ( " 6x10 " ) ;
}
2005-08-03 07:01:32 +00:00
static void load_fonts ( )
{
int i ;
2006-05-09 23:08:23 +00:00
for ( i = 0 ; i < = font_count ; i + + ) {
2005-08-03 07:01:32 +00:00
# ifdef XFT
/* load Xft font */
if ( use_xft ) {
2005-08-05 06:40:19 +00:00
/*if (fonts[i].xftfont != NULL && selected_font == 0) {
XftFontClose ( display , fonts [ i ] . xftfont ) ;
} */
2005-08-03 07:01:32 +00:00
if ( ( fonts [ i ] . xftfont =
2005-08-05 06:40:19 +00:00
XftFontOpenName ( display , screen , fonts [ i ] . name ) ) ! = NULL )
2005-08-03 07:01:32 +00:00
continue ;
2005-08-05 06:40:19 +00:00
2005-08-03 07:01:32 +00:00
ERR ( " can't load Xft font '%s' " , fonts [ i ] . name ) ;
if ( ( fonts [ i ] . xftfont =
2005-08-05 06:40:19 +00:00
XftFontOpenName ( display , screen ,
" courier-12 " ) ) ! = NULL )
2005-08-03 07:01:32 +00:00
continue ;
2005-08-05 06:40:19 +00:00
2005-08-03 07:01:32 +00:00
ERR ( " can't load Xft font '%s' " , " courier-12 " ) ;
2005-08-05 06:40:19 +00:00
2005-08-03 07:01:32 +00:00
if ( ( fonts [ i ] . font = XLoadQueryFont ( display , " fixed " ) ) = = NULL ) {
CRIT_ERR ( " can't load font '%s' " , " fixed " ) ;
}
use_xft = 0 ;
2005-08-05 06:40:19 +00:00
2005-08-03 07:01:32 +00:00
continue ;
}
# endif
/* load normal font */
2005-08-05 06:40:19 +00:00
/* if (fonts[i].font != NULL)
XFreeFont ( display , fonts [ i ] . font ) ; */
2005-08-03 07:01:32 +00:00
if ( ( fonts [ i ] . font = XLoadQueryFont ( display , fonts [ i ] . name ) ) = = NULL ) {
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 " ) ;
2005-08-26 02:52:54 +00:00
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 ;
/* Update interval */
static double update_interval ;
/* 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
/* Always on bottom */
static int on_bottom ;
/* 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-07-20 00:30:40 +00:00
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 ;
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-05-13 19:51:26 +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 ;
long iconv_count ;
char iconv_converting ;
static iconv_t * * iconv_cd = 0 ;
int register_iconv ( iconv_t * new_iconv )
{
if ( iconv_cd ) {
iconv_cd = realloc ( iconv , sizeof ( iconv_t * ) * ( iconv_count + 1 ) ) ;
} else {
iconv_cd = malloc ( sizeof ( iconv_t * ) ) ;
}
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 ;
for ( i = iconv_count ; i < 0 ; i + + ) {
if ( iconv_cd [ i ] ) {
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 ;
# endif /* X11 */
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
2005-11-11 20:46:42 +00:00
tcp_port_monitor_collection_args_t tcp_port_monitor_collection_args ;
tcp_port_monitor_args_t tcp_port_monitor_args ;
2005-11-11 03:28:24 +00:00
# endif
2005-07-20 00:30:40 +00:00
/* Text that is shown */
static char original_text [ ] =
" $nodename - $sysname $kernel on $machine \n "
" $hr \n "
" ${color grey}Uptime:$color $uptime \n "
" ${color grey}Frequency (in MHz):$color $freq \n "
2005-08-26 02:16:35 +00:00
" ${color grey}Frequency (in GHz):$color $freq_g \n "
2005-07-20 00:30:40 +00:00
" ${color grey}RAM Usage:$color $mem/$memmax - $memperc% ${membar 4} \n "
" ${color grey}Swap Usage:$color $swap/$swapmax - $swapperc% ${swapbar 4} \n "
" ${color grey}CPU Usage:$color $cpu% ${cpubar 4} \n "
" ${color grey}Processes:$color $processes ${color grey}Running:$color $running_processes \n "
" $hr \n "
" ${color grey}File systems: \n "
" / $color${fs_free /}/${fs_size /} ${fs_bar 6 /} \n "
" ${color grey}Networking: \n "
" Up:$color ${upspeed eth0} k/s${color grey} - Down:$color ${downspeed eth0} k/s \n "
" $hr \n "
# ifdef SETI
" ${color grey}SETI@Home Statistics: \n "
" ${color grey}Seti Unit Number:$color $seti_credit \n "
" ${color grey}Seti Progress:$color $seti_prog% $seti_progbar \n "
# endif
# ifdef MPD
" ${color grey}MPD: $mpd_status $mpd_artist - $mpd_title from $mpd_album at $mpd_vol \n "
2005-07-28 04:48:27 +00:00
" Bitrate: $mpd_bitrate \n " " Progress: $mpd_bar \n "
2006-03-25 21:21:07 +00:00
# endif
# ifdef XMMS2
" ${color grey}XMMS2: $xmms2_status $xmms2_artist - $xmms2_title from $xmms2_album \n "
" Progress: $xmms2_bar \n "
2005-07-20 00:30:40 +00:00
# endif
" ${color grey}Name PID CPU% MEM% \n "
" ${color lightgrey} ${top name 1} ${top pid 1} ${top cpu 1} ${top mem 1} \n "
" ${color lightgrey} ${top name 2} ${top pid 2} ${top cpu 2} ${top mem 2} \n "
" ${color lightgrey} ${top name 3} ${top pid 3} ${top cpu 3} ${top mem 3} \n "
" ${color lightgrey} ${top name 4} ${top pid 4} ${top cpu 4} ${top mem 4} \n "
2005-07-28 04:48:27 +00:00
" ${tail /var/log/Xorg.0.log 3} " ;
2005-07-20 00:30:40 +00:00
static char * text = original_text ;
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 ] ;
int check_mount ( char * s )
{
2005-10-16 11:53:36 +00:00
# if defined(__linux__)
2005-07-28 04:48:27 +00:00
int ret = 0 ;
FILE * mtab = fopen ( " /etc/mtab " , " r " ) ;
if ( mtab ) {
char buf1 [ 256 ] , buf2 [ 128 ] ;
while ( fgets ( buf1 , 256 , mtab ) ) {
sscanf ( buf1 , " %*s %128s " , buf2 ) ;
if ( ! strcmp ( s , buf2 ) ) {
ret = 1 ;
break ;
}
}
fclose ( mtab ) ;
} else {
ERR ( " Could not open mtab " ) ;
}
return ret ;
2005-10-16 11:53:36 +00:00
# elif defined(__FreeBSD__)
struct statfs * mntbuf ;
int i , mntsize ;
mntsize = getmntinfo ( & mntbuf , MNT_NOWAIT ) ;
for ( i = mntsize - 1 ; i > = 0 ; i - - )
if ( strcmp ( mntbuf [ i ] . f_mntonname , s ) = = 0 )
return 1 ;
return 0 ;
# endif
2005-07-20 00:30:40 +00:00
}
2005-07-28 04:48:27 +00:00
2005-07-20 00:30:40 +00:00
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 ;
2005-07-28 04:48:27 +00:00
if ( utf8_mode ) {
2005-08-03 07:01:32 +00:00
XftTextExtentsUtf8 ( display , fonts [ selected_font ] . xftfont , s , l , & gi ) ;
2005-07-28 04:48:27 +00:00
} else {
2005-08-03 07:01:32 +00:00
XftTextExtents8 ( display , fonts [ selected_font ] . xftfont , 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 ( ) */
2005-07-28 04:48:27 +00:00
static char text_buffer [ TEXT_BUFFER_SIZE * 4 ] ;
2005-07-20 00:30:40 +00:00
/* special stuff in text_buffer */
# define SPECIAL_CHAR '\x01'
enum {
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 ,
2005-07-20 00:30:40 +00:00
} ;
static struct special_t {
int type ;
short height ;
short width ;
long arg ;
2005-07-29 04:32:56 +00:00
double * graph ;
double graph_scale ;
2005-07-28 06:56:55 +00:00
int graph_width ;
2005-07-29 04:32:56 +00:00
int scaled ;
2005-08-03 07:01:32 +00:00
short font_added ;
2005-08-01 09:15:02 +00:00
unsigned long first_colour ; // for graph gradient
unsigned long last_colour ;
2005-07-20 00:30:40 +00:00
} specials [ 128 ] ;
static int special_count ;
2005-08-11 05:21:56 +00:00
# ifdef X11
2005-07-20 00:30:40 +00:00
static int special_index ; /* used when drawing */
2005-08-11 05:21:56 +00:00
# endif /* X11 */
2005-07-20 00:30:40 +00:00
2005-09-04 03:43:18 +00:00
# define MAX_GRAPH_DEPTH 256 /* why 256? cause an array of more then 256 doubles seems excessive, and who needs that kind of precision anyway? */
2005-07-28 06:56:55 +00:00
2005-07-20 00:30:40 +00:00
static struct special_t * new_special ( char * buf , int t )
{
2006-02-13 02:28:46 +00:00
if ( special_count > = 512 )
2005-07-28 04:48:27 +00:00
CRIT_ERR ( " too many special things in text " ) ;
2005-07-20 00:30:40 +00:00
buf [ 0 ] = SPECIAL_CHAR ;
buf [ 1 ] = ' \0 ' ;
specials [ special_count ] . type = t ;
return & specials [ special_count + + ] ;
}
typedef struct tailstring_list {
char data [ TEXT_BUFFER_SIZE ] ;
struct tailstring_list * next ;
2005-08-21 08:23:04 +00:00
struct tailstring_list * first ;
2005-07-20 00:30:40 +00:00
} tailstring ;
2005-07-28 04:48:27 +00:00
void addtail ( tailstring * * head , char * data_in )
{
2005-07-20 00:30:40 +00:00
tailstring * tmp ;
if ( ( tmp = malloc ( sizeof ( * tmp ) ) ) = = NULL ) {
CRIT_ERR ( " malloc " ) ;
}
2005-08-21 08:23:04 +00:00
if ( * head = = NULL ) {
tmp - > first = tmp ;
} else {
tmp - > first = ( * head ) - > first ;
}
2005-07-20 00:30:40 +00:00
strncpy ( tmp - > data , data_in , TEXT_BUFFER_SIZE ) ;
tmp - > next = * head ;
* head = tmp ;
}
2005-07-28 04:48:27 +00:00
void freetail ( tailstring * head )
{
tailstring * tmp ;
while ( head ! = NULL ) {
tmp = head - > next ;
free ( head ) ;
head = tmp ;
}
}
2005-07-20 00:30:40 +00:00
2005-08-21 08:23:04 +00:00
void freelasttail ( tailstring * head )
{
tailstring * tmp = head ;
while ( tmp ! = NULL ) {
if ( tmp - > next = = head - > first ) {
tmp - > next = NULL ;
break ;
}
tmp = tmp - > next ;
}
free ( head - > first ) ;
while ( head ! = NULL & & tmp ! = NULL ) {
head - > first = tmp ;
head = head - > next ;
}
}
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 ) ;
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 )
{
* w = 0 ; /* zero width means all space that is available */
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 ;
if ( sscanf ( args , " %d,%d %n " , h , w , & n ) < = 1 )
sscanf ( args , " %d %n " , h , & n ) ;
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 )
{
if ( args & & sizeof ( args ) < 127 ) {
return strdup ( args ) ;
}
2006-05-09 23:08:23 +00:00
/* else {
2005-08-02 05:06:53 +00:00
ERR ( " font scan failed, lets hope it doesn't mess stuff up " ) ;
2006-05-09 23:08:23 +00:00
we ' ll assume this means to use the default font now , like $ color
} */
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
2005-08-02 05:06:53 +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 ) ;
if ( ! s - > font_added | | strcmp ( args , fonts [ s - > font_added ] . name ) ) {
int tmp = selected_font ;
selected_font = s - > font_added = addfont ( args ) ;
load_fonts ( ) ;
//set_font();
selected_font = tmp ;
}
} else {
struct special_t * s = new_special ( buf , FONT ) ;
2005-08-06 04:46:16 +00:00
int tmp = selected_font ;
2006-05-09 23:08:23 +00:00
selected_font = s - > font_added = 0 ;
2005-08-03 07:01:32 +00:00
load_fonts ( ) ;
2006-05-09 23:08:23 +00:00
//set_font();
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-08-02 05:06:53 +00:00
2005-07-30 22:59:01 +00:00
inline void graph_append ( struct special_t * graph , double f )
{
2005-08-25 04:00:55 +00:00
if ( ! graph - > scaled & & f > graph - > graph_scale ) {
f = graph - > graph_scale ;
}
2005-07-30 22:59:01 +00:00
int i ;
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
}
2006-01-26 04:44:19 +00:00
graph - > graph [ 0 ] = f ; /* add new data */
for ( i = graph - > graph_width - 1 ; i > 0 ; i - - ) { /* shift all the data by 1 */
graph - > graph [ i ] = graph - > graph [ i - 1 ] ;
2005-07-29 04:32:56 +00:00
if ( graph - > scaled & & graph - > graph [ i ] > graph - > graph_scale ) {
2005-07-30 23:05:03 +00:00
graph - > graph_scale = graph - > graph [ i ] ; /* check if we need to update the scale */
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 ;
void set_up_gradient ( ) ;
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
2005-08-30 14:59:37 +00:00
/* adjust color values depending on color depth*/
static unsigned int adjust_colors ( unsigned int color )
{
double r , g , b ;
if ( colour_depth = = 0 ) {
set_up_gradient ( ) ;
}
if ( colour_depth = = 16 ) {
r = ( color & 0xff0000 ) > > 16 ;
g = ( color & 0xff00 ) > > 8 ;
b = color & 0xff ;
2005-08-30 19:13:01 +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 ;
}
2005-08-25 04:00:55 +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 ) ;
2005-09-04 03:43:18 +00:00
s - > width = w ;
if ( s - > graph = = NULL ) {
if ( s - > width > 0 & & s - > width < MAX_GRAPH_DEPTH ) {
s - > graph_width = s - > width - 3 ; // subtract 3 for the box
} else {
s - > graph_width = MAX_GRAPH_DEPTH - 3 ;
}
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 ;
}
2005-09-04 03:43:18 +00:00
/*if (s->width) {
2005-07-30 22:59:01 +00:00
s - > graph_width = s - > width - 3 ; // subtract 3 for rectangle around
2005-09-04 03:43:18 +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 ;
2005-07-30 22:59:01 +00:00
} else {
2005-08-25 04:00:55 +00:00
s - > graph_scale = scale ;
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
}
2005-08-25 04:00:55 +00:00
static const 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
{
* w = 0 ; /* zero width means all space that is available */
2005-07-28 06:56:55 +00:00
* h = 25 ;
2005-08-01 09:15:02 +00:00
* first_colour = 0 ;
* last_colour = 0 ;
2005-07-28 04:48:27 +00:00
/* graph's argument is either height or height,width */
if ( args ) {
2005-08-25 04:00:55 +00:00
if ( sscanf ( args , " %*s %d,%d %x %x %i " , h , w , first_colour , last_colour , scale ) < 5 ) {
if ( sscanf ( args , " %*s %d,%d %x %x " , h , w , first_colour , last_colour ) < 4 ) {
* scale = 0 ;
if ( sscanf ( args , " %d,%d %x %x %i " , h , w , first_colour , last_colour , scale ) < 5 ) {
* scale = 0 ;
if ( sscanf ( args , " %d,%d %x %x " , h , w , first_colour , last_colour ) < 4 ) {
* w = 0 ;
2005-08-03 07:01:32 +00:00
* h = 25 ;
2005-08-26 02:16:35 +00:00
if ( sscanf ( args , " %*s %x %x %i " , first_colour , last_colour , scale ) < 3 ) {
2005-08-03 07:01:32 +00:00
* w = 0 ;
* h = 25 ;
2005-08-26 02:16:35 +00:00
* scale = 0 ;
if ( sscanf ( args , " %*s %x %x " , first_colour , last_colour ) < 2 ) {
* w = 0 ;
* h = 25 ;
if ( sscanf ( args , " %x %x %i " , first_colour , last_colour , scale ) < 3 ) {
* first_colour = 0 ;
* last_colour = 0 ;
* scale = 0 ;
if ( sscanf ( args , " %x %x " , first_colour , last_colour ) < 2 ) {
2005-08-03 07:01:32 +00:00
* first_colour = 0 ;
* last_colour = 0 ;
2005-08-26 02:16:35 +00:00
if ( sscanf ( args , " %d,%d %i " , h , w , scale ) < 3 ) {
2005-08-02 03:08:54 +00:00
* first_colour = 0 ;
* last_colour = 0 ;
2005-08-26 02:16:35 +00:00
* scale = 0 ;
if ( sscanf ( args , " %d,%d " , h , w ) < 2 ) {
* first_colour = 0 ;
* last_colour = 0 ;
sscanf ( args , " %*s %d,%d " , h , w ) ;
} } } } } } } } } } } // haha
2005-07-28 04:48:27 +00:00
return args ;
}
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 ) ;
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 ;
}
/* quite boring functions */
static inline void for_each_line ( char * b , void ( * f ) ( char * ) )
{
char * ps , * pe ;
for ( ps = b , pe = b ; * pe ; pe + + ) {
if ( * pe = = ' \n ' ) {
* pe = ' \0 ' ;
f ( ps ) ;
* pe = ' \n ' ;
ps = pe + 1 ;
}
}
if ( ps < pe )
f ( ps ) ;
}
static void convert_escapes ( char * buf )
{
char * p = buf , * s = buf ;
while ( * s ) {
if ( * s = = ' \\ ' ) {
s + + ;
if ( * s = = ' n ' )
* p + + = ' \n ' ;
else if ( * s = = ' \\ ' )
* p + + = ' \\ ' ;
s + + ;
} else
* p + + = * s + + ;
}
* p = ' \0 ' ;
}
2005-08-11 18:13:57 +00:00
/* converts from bytes to human readable format (k, M, G, T) */
2005-07-20 00:30:40 +00:00
static void human_readable ( long long a , char * buf , int size )
{
2005-08-26 05:52:43 +00:00
// Strange conditional due to possible overflows
2005-08-11 18:13:57 +00:00
if ( a / 1024 / 1024 / 1024.0 > 1024.0 ) {
2005-08-26 05:52:43 +00:00
snprintf ( buf , size , " %.2fT " , ( a / 1024 / 1024 / 1024 ) / 1024.0 ) ;
2005-08-11 18:13:57 +00:00
}
2005-08-12 04:34:06 +00:00
else if ( a > = 1024 * 1024 * 1024 ) {
2005-07-20 00:30:40 +00:00
snprintf ( buf , size , " %.2fG " , ( a / 1024 / 1024 ) / 1024.0 ) ;
2005-08-11 18:13:57 +00:00
}
2005-07-20 00:30:40 +00:00
else if ( a > = 1024 * 1024 ) {
double m = ( a / 1024 ) / 1024.0 ;
if ( m > = 100.0 )
snprintf ( buf , size , " %.0fM " , m ) ;
else
snprintf ( buf , size , " %.1fM " , m ) ;
} else if ( a > = 1024 )
snprintf ( buf , size , " %Ldk " , a / ( long long ) 1024 ) ;
else
snprintf ( buf , size , " %Ld " , a ) ;
}
/* text handling */
enum text_object_type {
OBJ_acpiacadapter ,
OBJ_adt746xcpu ,
OBJ_adt746xfan ,
OBJ_acpifan ,
2005-07-28 04:48:27 +00:00
OBJ_addr ,
OBJ_linkstatus ,
2005-07-20 00:30:40 +00:00
OBJ_acpitemp ,
2005-08-21 06:36:13 +00:00
OBJ_acpitempf ,
2005-07-20 00:30:40 +00:00
OBJ_battery ,
OBJ_buffers ,
OBJ_cached ,
OBJ_color ,
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 ,
2005-08-26 02:16:35 +00:00
OBJ_diskio ,
OBJ_diskiograph ,
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 ,
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 ,
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 ,
2005-07-20 00:30:40 +00:00
OBJ_fs_used ,
OBJ_fs_used_perc ,
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 ,
2005-08-27 12:59:46 +00:00
# if defined(__linux__)
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 ,
OBJ_i8k_ac_status ,
OBJ_i8k_buttons_status ,
2006-04-15 18:00:39 +00:00
OBJ_ibm_fan ,
OBJ_ibm_temps ,
OBJ_ibm_volume ,
OBJ_ibm_brightness ,
2006-04-23 21:35:31 +00:00
OBJ_pb_battery ,
2005-08-27 12:59:46 +00:00
# endif /* __linux__ */
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 ,
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 ,
OBJ_mixer ,
OBJ_mixerl ,
OBJ_mixerr ,
OBJ_mixerbar ,
OBJ_mixerlbar ,
OBJ_mixerrbar ,
OBJ_new_mails ,
OBJ_nodename ,
OBJ_pre_exec ,
# ifdef MLDONKEY
2005-07-28 04:48:27 +00:00
OBJ_ml_upload_counter ,
OBJ_ml_download_counter ,
OBJ_ml_nshared_files ,
OBJ_ml_shared_counter ,
OBJ_ml_tcp_upload_rate ,
OBJ_ml_tcp_download_rate ,
OBJ_ml_udp_upload_rate ,
OBJ_ml_udp_download_rate ,
OBJ_ml_ndownloaded_files ,
OBJ_ml_ndownloading_files ,
2005-07-20 00:30:40 +00:00
# endif
OBJ_processes ,
OBJ_running_processes ,
OBJ_shadecolor ,
OBJ_outlinecolor ,
OBJ_stippled_hr ,
OBJ_swap ,
OBJ_swapbar ,
OBJ_swapmax ,
OBJ_swapperc ,
OBJ_sysname ,
OBJ_temp1 , /* i2c is used instead in these */
OBJ_temp2 ,
OBJ_text ,
OBJ_time ,
OBJ_utime ,
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 ,
2006-05-08 22:34:38 +00:00
OBJ_imap ,
OBJ_imap_messages ,
OBJ_imap_unseen ,
OBJ_pop3 ,
OBJ_pop3_unseen ,
OBJ_pop3_used ,
2005-09-29 03:22:31 +00:00
# if defined(__FreeBSD__) && (defined(i386) || defined(__i386__))
2005-08-30 04:19:16 +00:00
OBJ_apm_adapter ,
OBJ_apm_battery_time ,
OBJ_apm_battery_life ,
# endif /* __FreeBSD__ */
2005-07-20 00:30:40 +00:00
# ifdef SETI
OBJ_seti_prog ,
OBJ_seti_progbar ,
OBJ_seti_credit ,
# endif
# 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
2006-03-25 21:21:07 +00:00
# ifdef XMMS2
2006-04-16 03:49:49 +00:00
OBJ_xmms2_artist ,
OBJ_xmms2_album ,
OBJ_xmms2_title ,
OBJ_xmms2_genre ,
OBJ_xmms2_comment ,
OBJ_xmms2_decoder ,
OBJ_xmms2_transport ,
OBJ_xmms2_url ,
OBJ_xmms2_date ,
OBJ_xmms2_tracknr ,
OBJ_xmms2_bitrate ,
OBJ_xmms2_id ,
OBJ_xmms2_duration ,
OBJ_xmms2_elapsed ,
OBJ_xmms2_size ,
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 ,
2006-03-25 21:21:07 +00:00
# endif
2006-01-08 14:51:47 +00:00
# if defined(XMMS) || defined(BMP) || defined(AUDACIOUS) || defined(INFOPIPE)
2006-01-08 08:02:37 +00:00
OBJ_xmms_status ,
OBJ_xmms_title ,
OBJ_xmms_length ,
OBJ_xmms_length_seconds ,
OBJ_xmms_position ,
OBJ_xmms_position_seconds ,
OBJ_xmms_bitrate ,
OBJ_xmms_frequency ,
OBJ_xmms_channels ,
OBJ_xmms_filename ,
OBJ_xmms_playlist_length ,
OBJ_xmms_playlist_position ,
2006-01-28 01:28:23 +00:00
OBJ_xmms_bar ,
2006-01-07 07:01:22 +00:00
# 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
2005-10-31 05:17:06 +00:00
# ifdef TCP_PORT_MONITOR
OBJ_tcp_portmon ,
# endif
2006-05-13 19:51:26 +00:00
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
2005-07-20 00:30:40 +00:00
} ;
struct text_object {
int type ;
2005-07-30 11:23:26 +00:00
int a , b ;
2006-05-14 07:05:05 +00:00
long line ;
2005-08-25 04:00:55 +00:00
unsigned int c , d , e ;
2005-08-26 03:26:23 +00:00
float f ;
2006-05-08 22:34:38 +00:00
char global_mode ;
2005-07-20 00:30:40 +00:00
union {
char * s ; /* some string */
int i ; /* some integer */
long l ; /* some other integer */
2006-05-08 22:34:38 +00:00
unsigned int sensor ;
2006-04-15 18:00:39 +00:00
struct net_stat * net ;
2005-07-20 00:30:40 +00:00
struct fs_stat * fs ;
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 ;
2005-07-20 00:30:40 +00:00
struct {
struct fs_stat * fs ;
int w , h ;
} fsbar ; /* 3 */
struct {
int l ;
int w , h ;
} mixerbar ; /* 3 */
struct {
int fd ;
int arg ;
char devtype [ 256 ] ;
char type [ 64 ] ;
} i2c ; /* 2 */
struct {
2005-07-28 04:48:27 +00:00
int pos ;
char * s ;
2005-07-20 00:30:40 +00:00
} ifblock ;
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 ;
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 ;
2006-01-28 22:13:23 +00:00
int pos ;
struct thread_info_s thread_info ;
2005-07-20 00:30:40 +00:00
} execi ; /* 5 */
struct {
int a , b ;
} pair ; /* 2 */
2005-10-31 05:17:06 +00:00
# ifdef TCP_PORT_MONITOR
struct {
in_port_t port_range_begin ; /* starting port to monitor */
in_port_t port_range_end ; /* ending port to monitor */
2005-11-01 00:58:34 +00:00
int item ; /* enum value from libtcp-portmon.h, e.g. COUNT, REMOTEIP, etc. */
2005-10-31 05:17:06 +00:00
int connection_index ; /* 0 to n-1 connections. */
2006-01-28 01:28:23 +00:00
} tcp_port_monitor ;
2005-10-31 05:17:06 +00:00
# endif
2005-07-20 00:30:40 +00:00
} data ;
} ;
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
} ;
2005-07-20 00:30:40 +00:00
static unsigned int text_object_count ;
static struct text_object * text_objects ;
2005-12-10 21:07:24 +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-01-28 22:13:23 +00:00
# define MAX_THREADS 512 // sure whatever
typedef struct thread_info_s * thread_info ;
2006-01-31 02:09:00 +00:00
static thread_info thread_list [ MAX_THREADS ] ;
static int thread_count = 0 ;
2006-02-13 02:28:46 +00:00
static int threads_runnable = 1 ;
2006-01-28 22:13:23 +00:00
int register_thread ( struct thread_info_s * new_thread )
{
if ( thread_count > = MAX_THREADS ) {
CRIT_ERR ( " Uh oh, tried to register too many threads " ) ;
} else {
thread_list [ thread_count ] = new_thread ;
thread_count + + ;
2006-05-14 04:49:55 +00:00
// may as well fix the mutex for them as well
pthread_mutex_init ( & ( new_thread - > mutex ) , NULL ) ;
2006-01-28 22:13:23 +00:00
}
return thread_count - 1 ;
}
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
struct mail_s * parse_mail_args ( char type , const char * arg ) {
struct mail_s * mail ;
mail = malloc ( sizeof ( struct mail_s ) ) ;
2006-05-12 18:06:12 +00:00
memset ( mail , 0 , sizeof ( struct mail_s ) ) ;
2006-05-09 22:39:39 +00:00
char * tmp ;
if ( sscanf ( arg , " %128s %128s %128s " , mail - > host , mail - > user , mail - > pass ) ! = 3 ) {
if ( type = = POP3 ) {
ERR ( " Scanning IMAP args failed " ) ;
} else if ( type = = IMAP ) {
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 ;
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 ) {
tmp + = 3 ;
int len = 1024 ;
if ( tmp [ 0 ] = = ' \' ' ) {
len = strstr ( tmp + 1 , " ' " ) - tmp - 1 ;
if ( len > 1024 ) {
len = 1024 ;
}
}
strncpy ( mail - > command , tmp + 1 , len ) ;
} else {
mail - > command [ 0 ] = ' \0 ' ;
}
mail - > pos = - 1 ;
return mail ;
}
2006-05-08 22:34:38 +00:00
void * imap_thread ( struct mail_s * mail )
{ // pthreads are really beginning to piss me off
double update_time ;
int run_code = threads_runnable ;
update_time = get_time ( ) ;
int sockfd , numbytes ;
char recvbuf [ MAXDATASIZE ] ;
char sendbuf [ MAXDATASIZE ] ;
char * reply ;
int fail = 0 ;
unsigned int old_unseen = UINT_MAX ;
struct hostent * he ;
struct sockaddr_in their_addr ; // connector's address information
if ( ( he = gethostbyname ( mail - > host ) ) = = NULL ) { // get the host info
herror ( " gethostbyname " ) ;
exit ( 1 ) ;
}
while ( threads_runnable = = run_code & & fail < 5 ) {
2006-05-14 05:43:16 +00:00
if ( fail > 0 ) {
ERR ( " Trying IMAP connection again for %s@%s (try %i/5) " , mail - > user , mail - > host , fail + 1 ) ;
}
2006-05-08 22:34:38 +00:00
update_time = get_time ( ) ;
if ( ( sockfd = socket ( PF_INET , SOCK_STREAM , 0 ) ) = = - 1 ) {
perror ( " socket " ) ;
fail + + ;
2006-05-14 05:43:16 +00:00
continue ;
2006-05-08 22:34:38 +00:00
}
their_addr . sin_family = AF_INET ; // host byte order
their_addr . sin_port = htons ( mail - > port ) ; // short, network byte order
their_addr . sin_addr = * ( ( struct in_addr * ) he - > h_addr ) ;
memset ( & ( their_addr . sin_zero ) , ' \0 ' , 8 ) ; // zero the rest of the struct
if ( connect
( sockfd , ( struct sockaddr * ) & their_addr ,
sizeof ( struct sockaddr ) ) = = - 1 ) {
perror ( " connect " ) ;
fail + + ;
2006-05-14 05:43:16 +00:00
continue ;
2006-05-08 22:34:38 +00:00
}
struct timeval timeout ;
int res ;
fd_set fdset ;
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 + + ;
2006-05-14 05:43:16 +00:00
continue ;
2006-05-08 22:34:38 +00:00
}
} else {
2006-05-14 06:15:23 +00:00
ERR ( " IMAP connection failed: timeout " ) ;
2006-05-08 22:34:38 +00:00
fail + + ;
2006-05-14 05:43:16 +00:00
continue ;
2006-05-08 22:34:38 +00:00
}
recvbuf [ numbytes ] = ' \0 ' ;
if ( strstr ( recvbuf , " * OK " ) ! = recvbuf ) {
2006-05-14 06:15:23 +00:00
ERR ( " IMAP connection failed, probably not an IMAP server " ) ;
2006-05-08 22:34:38 +00:00
fail + + ;
2006-05-14 05:43:16 +00:00
continue ;
2006-05-08 22:34:38 +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 , " \n " , MAXDATASIZE - strlen ( sendbuf ) - 1 ) ;
if ( send ( sockfd , sendbuf , strlen ( sendbuf ) , 0 ) = = - 1 ) {
perror ( " send a1 " ) ;
fail + + ;
2006-05-14 05:43:16 +00:00
continue ;
2006-05-08 22:34:38 +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 + + ;
2006-05-14 05:43:16 +00:00
continue ;
2006-05-08 22:34:38 +00:00
}
}
recvbuf [ numbytes ] = ' \0 ' ;
if ( strstr ( recvbuf , " a1 OK " ) = = NULL ) {
2006-05-14 06:15:23 +00:00
ERR ( " IMAP server login failed: %s " , recvbuf ) ;
2006-05-08 22:34:38 +00:00
fail + + ;
2006-05-14 05:43:16 +00:00
continue ;
2006-05-08 22:34:38 +00:00
}
strncpy ( sendbuf , " a2 STATUS " , MAXDATASIZE ) ;
strncat ( sendbuf , mail - > folder ,
MAXDATASIZE - strlen ( sendbuf ) - 1 ) ;
strncat ( sendbuf , " (MESSAGES UNSEEN) \n " ,
MAXDATASIZE - strlen ( sendbuf ) - 1 ) ;
if ( send ( sockfd , sendbuf , strlen ( sendbuf ) , 0 ) = = - 1 ) {
perror ( " send a2 " ) ;
fail + + ;
2006-05-14 05:43:16 +00:00
continue ;
2006-05-08 22:34:38 +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 a2 " ) ;
fail + + ;
2006-05-14 05:43:16 +00:00
continue ;
2006-05-08 22:34:38 +00:00
}
}
recvbuf [ numbytes ] = ' \0 ' ;
if ( strstr ( recvbuf , " a2 OK " ) = = NULL ) {
2006-05-14 06:15:23 +00:00
ERR ( " IMAP status failed: %s " , recvbuf ) ;
2006-05-08 22:34:38 +00:00
fail + + ;
2006-05-14 05:43:16 +00:00
continue ;
2006-05-08 22:34:38 +00:00
}
// 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 + + ;
2006-05-14 05:43:16 +00:00
continue ;
2006-05-08 22:34:38 +00:00
} else {
2006-05-14 04:49:55 +00:00
pthread_mutex_lock ( & ( mail - > thread_info . mutex ) ) ;
2006-05-13 19:51:26 +00:00
sscanf ( reply , " MESSAGES %lu UNSEEN %lu " ,
2006-05-08 22:34:38 +00:00
& mail - > messages ,
& mail - > unseen ) ;
2006-05-14 04:49:55 +00:00
pthread_mutex_unlock ( & ( mail - > thread_info . mutex ) ) ;
2006-05-08 22:34:38 +00:00
}
strncpy ( sendbuf , " a3 logout \n " , MAXDATASIZE ) ;
if ( send ( sockfd , sendbuf , strlen ( sendbuf ) , 0 ) = = - 1 ) {
perror ( " send a3 " ) ;
fail + + ;
2006-05-14 05:43:16 +00:00
continue ;
2006-05-08 22:34:38 +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 a3 " ) ;
fail + + ;
2006-05-14 05:43:16 +00:00
continue ;
2006-05-08 22:34:38 +00:00
}
}
recvbuf [ numbytes ] = ' \0 ' ;
if ( strstr ( recvbuf , " a3 OK " ) = = NULL ) {
2006-05-14 06:15:23 +00:00
ERR ( " IMAP logout failed: %s " , recvbuf ) ;
2006-05-08 22:34:38 +00:00
fail + + ;
2006-05-14 05:43:16 +00:00
continue ;
2006-05-08 22:34:38 +00:00
}
close ( sockfd ) ;
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 ;
mail - > last_update = update_time ;
usleep ( 100 ) ; // prevent race condition
if ( get_time ( ) - mail - > last_update >
mail - > interval ) {
continue ;
} else {
unsigned int delay =
1000000.0 * ( mail - > interval -
( get_time ( ) -
mail - > last_update ) ) ;
if ( delay < update_interval * 500000 ) {
delay = update_interval * 1000000 ;
}
usleep ( delay ) ;
}
}
ERR ( " exiting imap thread " ) ;
pthread_exit ( NULL ) ;
return 0 ;
}
void * pop3_thread ( struct mail_s * mail )
{ // pthreads are really beginning to piss me off
double update_time ;
int run_code = threads_runnable ;
update_time = get_time ( ) ;
int sockfd , numbytes ;
char recvbuf [ MAXDATASIZE ] ;
char sendbuf [ MAXDATASIZE ] ;
char * reply ;
int fail = 0 ;
unsigned int old_unseen = UINT_MAX ;
struct hostent * he ;
struct sockaddr_in their_addr ; // connector's address information
if ( ( he = gethostbyname ( mail - > host ) ) = = NULL ) { // get the host info
herror ( " gethostbyname " ) ;
exit ( 1 ) ;
}
while ( threads_runnable = = run_code & & fail < 5 ) {
2006-05-14 05:43:16 +00:00
if ( fail > 0 ) {
ERR ( " Trying POP3 connection again for %s@%s (try %i/5) " , mail - > user , mail - > host , fail + 1 ) ;
}
2006-05-08 22:34:38 +00:00
update_time = get_time ( ) ;
if ( ( sockfd = socket ( PF_INET , SOCK_STREAM , 0 ) ) = = - 1 ) {
perror ( " socket " ) ;
fail + + ;
2006-05-14 05:43:16 +00:00
continue ;
2006-05-08 22:34:38 +00:00
}
their_addr . sin_family = AF_INET ; // host byte order
their_addr . sin_port = htons ( mail - > port ) ; // short, network byte order
their_addr . sin_addr = * ( ( struct in_addr * ) he - > h_addr ) ;
memset ( & ( their_addr . sin_zero ) , ' \0 ' , 8 ) ; // zero the rest of the struct
if ( connect
( sockfd , ( struct sockaddr * ) & their_addr ,
sizeof ( struct sockaddr ) ) = = - 1 ) {
perror ( " connect " ) ;
fail + + ;
2006-05-14 05:43:16 +00:00
continue ;
2006-05-08 22:34:38 +00:00
}
struct timeval timeout ;
int res ;
fd_set fdset ;
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 + + ;
2006-05-14 05:43:16 +00:00
continue ;
2006-05-08 22:34:38 +00:00
}
} else {
ERR ( " POP3 connection failed: timeout \n " ) ;
fail + + ;
2006-05-14 05:43:16 +00:00
continue ;
2006-05-08 22:34:38 +00:00
}
recvbuf [ numbytes ] = ' \0 ' ;
if ( strstr ( recvbuf , " +OK " ) ! = recvbuf ) {
2006-05-14 06:15:23 +00:00
ERR ( " POP3 connection failed, probably not a POP3 server " ) ;
2006-05-08 22:34:38 +00:00
fail + + ;
2006-05-14 05:43:16 +00:00
continue ;
2006-05-08 22:34:38 +00:00
}
strncpy ( sendbuf , " USER " , MAXDATASIZE ) ;
strncat ( sendbuf , mail - > user ,
MAXDATASIZE - strlen ( sendbuf ) - 1 ) ;
strncat ( sendbuf , " \n " , MAXDATASIZE - strlen ( sendbuf ) - 1 ) ;
if ( send ( sockfd , sendbuf , strlen ( sendbuf ) , 0 ) = = - 1 ) {
perror ( " send USER " ) ;
fail + + ;
2006-05-14 05:43:16 +00:00
continue ;
2006-05-08 22:34:38 +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 USER " ) ;
fail + + ;
2006-05-14 05:43:16 +00:00
continue ;
2006-05-08 22:34:38 +00:00
}
}
recvbuf [ numbytes ] = ' \0 ' ;
if ( strstr ( recvbuf , " +OK " ) = = NULL ) {
2006-05-14 06:15:23 +00:00
ERR ( " POP3 server login failed: %s " , recvbuf ) ;
2006-05-08 22:34:38 +00:00
fail + + ;
2006-05-14 05:43:16 +00:00
continue ;
2006-05-08 22:34:38 +00:00
}
strncpy ( sendbuf , " PASS " , MAXDATASIZE ) ;
strncat ( sendbuf , mail - > pass ,
MAXDATASIZE - strlen ( sendbuf ) - 1 ) ;
strncat ( sendbuf , " \n " , MAXDATASIZE - strlen ( sendbuf ) - 1 ) ;
if ( send ( sockfd , sendbuf , strlen ( sendbuf ) , 0 ) = = - 1 ) {
perror ( " send PASS " ) ;
fail + + ;
2006-05-14 05:43:16 +00:00
continue ;
2006-05-08 22:34:38 +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 + + ;
2006-05-14 05:43:16 +00:00
continue ;
2006-05-08 22:34:38 +00:00
}
}
recvbuf [ numbytes ] = ' \0 ' ;
if ( strstr ( recvbuf , " +OK " ) = = NULL ) {
2006-05-14 06:15:23 +00:00
ERR ( " POP3 server login failed: %s " , recvbuf ) ;
2006-05-08 22:34:38 +00:00
fail + + ;
2006-05-14 05:43:16 +00:00
continue ;
2006-05-08 22:34:38 +00:00
}
strncpy ( sendbuf , " STAT \n " , MAXDATASIZE ) ;
if ( send ( sockfd , sendbuf , strlen ( sendbuf ) , 0 ) = = - 1 ) {
perror ( " send STAT " ) ;
fail + + ;
2006-05-14 05:43:16 +00:00
continue ;
2006-05-08 22:34:38 +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 STAT " ) ;
fail + + ;
2006-05-14 05:43:16 +00:00
continue ;
2006-05-08 22:34:38 +00:00
}
}
recvbuf [ numbytes ] = ' \0 ' ;
if ( strstr ( recvbuf , " +OK " ) = = NULL ) {
2006-05-14 06:15:23 +00:00
ERR ( " POP3 status failed: %s " , recvbuf ) ;
2006-05-08 22:34:38 +00:00
fail + + ;
2006-05-14 05:43:16 +00:00
continue ;
2006-05-08 22:34:38 +00:00
}
// now we get the data
reply = recvbuf + 4 ;
if ( reply = = NULL ) {
ERR ( " Error parsing POP3 response: %s " , recvbuf ) ;
fail + + ;
2006-05-14 05:43:16 +00:00
continue ;
2006-05-08 22:34:38 +00:00
} else {
2006-05-14 04:49:55 +00:00
pthread_mutex_lock ( & ( mail - > thread_info . mutex ) ) ;
2006-05-13 19:51:26 +00:00
sscanf ( reply , " %lu %lu " , & mail - > unseen ,
2006-05-08 22:34:38 +00:00
& mail - > used ) ;
2006-05-14 06:42:35 +00:00
// sleep(60);
2006-05-14 04:49:55 +00:00
pthread_mutex_unlock ( & ( mail - > thread_info . mutex ) ) ;
2006-05-08 22:34:38 +00:00
}
strncpy ( sendbuf , " QUIT \n " , MAXDATASIZE ) ;
if ( send ( sockfd , sendbuf , strlen ( sendbuf ) , 0 ) = = - 1 ) {
perror ( " send QUIT " ) ;
fail + + ;
2006-05-14 05:43:16 +00:00
continue ;
2006-05-08 22:34:38 +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 QUIT " ) ;
fail + + ;
2006-05-14 05:43:16 +00:00
continue ;
2006-05-08 22:34:38 +00:00
}
}
recvbuf [ numbytes ] = ' \0 ' ;
if ( strstr ( recvbuf , " +OK " ) = = NULL ) {
2006-05-14 06:15:23 +00:00
ERR ( " POP3 logout failed: %s " , recvbuf ) ;
2006-05-08 22:34:38 +00:00
fail + + ;
2006-05-14 05:43:16 +00:00
continue ;
2006-05-08 22:34:38 +00:00
}
close ( sockfd ) ;
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 ;
mail - > last_update = update_time ;
usleep ( 100 ) ; // prevent race condition
if ( get_time ( ) - mail - > last_update >
mail - > interval ) {
continue ;
} else {
unsigned int delay =
1000000.0 * ( mail - > interval -
( get_time ( ) -
mail - > last_update ) ) ;
if ( delay < update_interval * 500000 ) {
delay = update_interval * 1000000 ;
}
usleep ( delay ) ;
}
}
ERR ( " exiting pop3 thread " ) ;
pthread_exit ( NULL ) ;
return 0 ;
}
2006-02-01 14:39:23 +00:00
void * threaded_exec ( struct text_object * obj ) { // pthreads are really beginning to piss me off
double update_time ;
2006-02-13 02:28:46 +00:00
int run_code = threads_runnable ;
while ( threads_runnable = = run_code ) {
2006-02-01 14:39:23 +00:00
update_time = get_time ( ) ;
char * p2 = obj - > data . execi . buffer ;
FILE * fp = popen ( obj - > data . execi . cmd , " r " ) ;
2006-05-14 04:49:55 +00:00
pthread_mutex_lock ( & ( obj - > data . execi . thread_info . mutex ) ) ;
2006-02-01 14:39:23 +00:00
int n2 = fread ( p2 , 1 , TEXT_BUFFER_SIZE , fp ) ;
( void ) pclose ( fp ) ;
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 + + ;
}
2006-05-14 04:49:55 +00:00
pthread_mutex_unlock ( & ( obj - > data . execi . thread_info . mutex ) ) ;
2006-02-01 14:39:23 +00:00
obj - > data . execi . last_update = update_time ;
usleep ( 100 ) ; // prevent race condition
if ( get_time ( ) - obj - > data . execi . last_update > obj - > data . execi . interval ) {
continue ;
} else {
2006-02-02 02:23:18 +00:00
unsigned int delay = 1000000.0 * ( obj - > data . execi . interval - ( get_time ( ) - obj - > data . execi . last_update ) ) ;
2006-02-01 14:39:23 +00:00
if ( delay < update_interval * 500000 ) {
delay = update_interval * 1000000 ;
}
usleep ( delay ) ;
}
2006-01-31 01:31:29 +00:00
}
2006-02-13 02:28:46 +00:00
ERR ( " exiting thread " ) ;
2006-01-28 01:28:23 +00:00
pthread_exit ( NULL ) ;
2006-02-13 02:28:46 +00:00
return 0 ;
2005-08-29 17:06:31 +00:00
}
2005-12-10 14:15:38 +00:00
static struct text_object * new_text_object_internal ( )
{
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
}
2005-11-12 05:18:37 +00:00
# ifdef MLDONKEY
2005-11-12 04:26:00 +00:00
void ml_cleanup ( )
{
if ( mlconfig . mldonkey_hostname ) {
free ( mlconfig . mldonkey_hostname ) ;
mlconfig . mldonkey_hostname = NULL ;
}
}
2005-11-12 05:18:37 +00:00
# endif
2005-11-12 04:26:00 +00:00
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 ;
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 ) {
case OBJ_acpitemp :
close ( objs [ i ] . data . i ) ;
break ;
case OBJ_acpitempf :
close ( objs [ i ] . data . i ) ;
break ;
case OBJ_i2c :
close ( objs [ i ] . data . i2c . fd ) ;
break ;
case OBJ_time :
free ( objs [ i ] . data . s ) ;
break ;
case OBJ_utime :
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 ;
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 ) ;
break ;
case OBJ_tail :
free ( objs [ i ] . data . tail . logfile ) ;
free ( objs [ i ] . data . tail . buffer ) ;
break ;
case OBJ_text : case OBJ_font :
free ( objs [ i ] . data . s ) ;
break ;
case OBJ_exec :
free ( objs [ i ] . data . s ) ;
break ;
case OBJ_execbar :
free ( objs [ i ] . data . s ) ;
break ;
case OBJ_execgraph :
free ( objs [ i ] . data . s ) ;
break ;
/* case OBJ_execibar:
free ( objs [ i ] . data . s ) ;
break ;
case OBJ_execigraph :
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
2005-07-20 00:30:40 +00:00
# ifdef MPD
2006-01-28 01:28:23 +00:00
case OBJ_mpd_title :
2006-01-31 03:32:26 +00:00
if ( info . mpd . title ) {
free ( info . mpd . title ) ;
info . mpd . title = 0 ;
}
break ;
2006-01-28 01:28:23 +00:00
case OBJ_mpd_artist :
2006-01-31 03:32:26 +00:00
if ( info . mpd . artist ) {
free ( info . mpd . artist ) ;
info . mpd . artist = 0 ;
}
break ;
2006-01-28 01:28:23 +00:00
case OBJ_mpd_album :
2006-01-31 03:32:26 +00:00
if ( info . mpd . album ) {
free ( info . mpd . album ) ;
info . mpd . album = 0 ;
}
break ;
2006-01-28 01:28:23 +00:00
case OBJ_mpd_random :
2006-01-31 03:32:26 +00:00
if ( info . mpd . random ) {
free ( info . mpd . random ) ;
info . mpd . random = 0 ;
}
break ;
2006-01-28 01:28:23 +00:00
case OBJ_mpd_repeat :
2006-01-31 03:32:26 +00:00
if ( info . mpd . repeat ) {
free ( info . mpd . repeat ) ;
info . mpd . repeat = 0 ;
}
break ;
2006-01-28 01:28:23 +00:00
case OBJ_mpd_track :
2006-01-31 03:32:26 +00:00
if ( info . mpd . track ) {
free ( info . mpd . track ) ;
info . mpd . track = 0 ;
}
break ;
case OBJ_mpd_name :
if ( info . mpd . name ) {
free ( info . mpd . name ) ;
info . mpd . name = 0 ;
}
break ;
case OBJ_mpd_file :
if ( info . mpd . file ) {
free ( info . mpd . file ) ;
info . mpd . file = 0 ;
}
break ;
2006-01-28 01:28:23 +00:00
case OBJ_mpd_status :
2006-01-31 03:32:26 +00:00
if ( info . mpd . status ) {
free ( info . mpd . status ) ;
info . mpd . status = 0 ;
}
break ;
2006-03-07 04:23:55 +00:00
case OBJ_mpd_smart :
if ( info . mpd . artist ) {
free ( info . mpd . artist ) ;
info . mpd . artist = 0 ;
}
if ( info . mpd . title ) {
free ( info . mpd . title ) ;
info . mpd . title = 0 ;
}
if ( info . mpd . file ) {
free ( info . mpd . file ) ;
info . mpd . file = 0 ;
}
break ;
2006-01-28 01:28:23 +00:00
case OBJ_mpd_host :
2005-12-30 09:44:40 +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_decoder :
if ( info . xmms2 . decoder ) {
free ( info . xmms2 . decoder ) ;
info . xmms2 . url = 0 ;
}
break ;
case OBJ_xmms2_transport :
if ( info . xmms2 . transport ) {
free ( info . xmms2 . transport ) ;
info . xmms2 . url = 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 ;
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 :
2005-07-20 00:30:40 +00:00
# endif
2006-01-28 01:28:23 +00:00
case OBJ_pre_exec :
case OBJ_battery :
free ( objs [ i ] . data . s ) ;
break ;
2005-07-20 00:30:40 +00:00
2006-01-28 01:28:23 +00:00
case OBJ_execi :
free ( objs [ i ] . data . execi . cmd ) ;
free ( objs [ i ] . data . execi . buffer ) ;
break ;
case OBJ_texeci :
free ( objs [ i ] . data . execi . cmd ) ;
free ( objs [ i ] . data . execi . buffer ) ;
break ;
case OBJ_top :
if ( info . first_process ) {
free_all_processes ( ) ;
info . first_process = NULL ;
}
break ;
case OBJ_top_mem :
if ( info . first_process ) {
free_all_processes ( ) ;
info . first_process = NULL ;
}
break ;
2005-07-20 00:30:40 +00:00
}
}
2005-12-10 14:15:38 +00:00
free ( objs ) ;
//text_objects = NULL;
//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 ) ;
( void ) scan_bar ( arg + n , w , h ) ;
} else {
* a = mixer_init ( 0 ) ;
( void ) scan_bar ( arg , w , h ) ;
}
}
2005-12-10 21:07:24 +00:00
2005-07-20 00:30:40 +00:00
/* construct_text_object() creates a new text_object */
2006-05-14 07:05:05 +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
{
2006-01-28 01:28:23 +00:00
//struct text_object *obj = new_text_object();
struct text_object * obj = new_text_object_internal ( ) ;
2006-05-14 07:05:05 +00:00
obj - > line = line ;
2005-07-20 00:30:40 +00:00
# define OBJ(a, n) if (strcmp(s, #a) == 0) { obj->type = OBJ_##a; need_mask |= (1 << n); {
# define END ; } } else
2005-08-08 01:18:52 +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 */
2006-01-28 01:28:23 +00:00
OBJ ( acpitemp , 0 ) obj - > data . i = open_acpi_temperature ( arg ) ;
2005-08-21 06:36:13 +00:00
END OBJ ( acpitempf , 0 ) obj - > data . i = open_acpi_temperature ( arg ) ;
2005-07-20 00:30:40 +00:00
END OBJ ( acpiacadapter , 0 )
2006-01-28 01:28:23 +00:00
END OBJ ( freq , 0 ) ;
2005-08-11 16:20:35 +00:00
END OBJ ( freq_g , 0 ) ;
2005-08-26 02:16:35 +00:00
END OBJ ( freq_dyn , 0 ) ;
END OBJ ( freq_dyn_g , 0 ) ;
2005-08-11 16:05:44 +00:00
END OBJ ( acpifan , 0 ) ;
END OBJ ( battery , 0 ) ;
2005-08-27 07:15:44 +00:00
char bat [ 64 ] ;
if ( arg )
sscanf ( arg , " %63s " , bat ) ;
else
strcpy ( bat , " BAT0 " ) ;
obj - > data . s = strdup ( bat ) ;
2005-08-27 12:59:46 +00:00
# if defined(__linux__)
2005-08-27 07:15:44 +00:00
END OBJ ( i8k_version , INFO_I8K )
2006-01-28 01:28:23 +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 )
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). " ) ;
}
obj - > data . sensor = atoi ( & arg [ 0 ] ) ;
END OBJ ( ibm_volume , 0 )
END OBJ ( ibm_brightness , 0 )
2006-04-23 21:35:31 +00:00
END OBJ ( pb_battery , 0 )
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 ;
}
2005-08-27 12:59:46 +00:00
# endif /* __linux__ */
2006-01-28 01:28:23 +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 ;
} 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 ;
2005-08-27 10:10:31 +00:00
}
2006-01-28 01:28:23 +00:00
else { obj - > data . cpu_index = 0 ; }
( void ) scan_bar ( arg , & obj - > a , & obj - > b ) ;
} else {
( void ) scan_bar ( arg , & obj - > a , & obj - > b ) ;
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 )
if ( arg ) {
if ( strncmp ( arg , " cpu " , 3 ) = = 0 & & isdigit ( arg [ 3 ] ) ) {
obj - > data . cpu_index = atoi ( & arg [ 3 ] ) ;
arg + = 4 ;
2005-08-27 09:29:24 +00:00
}
2006-01-28 01:28:23 +00:00
( void ) scan_graph ( arg , & obj - > a , & obj - > b , & obj - > c , & obj - > d , & obj - > e ) ;
} else {
( void ) scan_graph ( arg , & obj - > a , & obj - > b , & obj - > c , & obj - > d , & obj - > e ) ;
obj - > data . cpu_index = 0 ;
}
2005-08-26 02:52:54 +00:00
END OBJ ( diskio , INFO_DISKIO )
2006-01-28 01:28:23 +00:00
END OBJ ( diskiograph , INFO_DISKIO ) ( void ) scan_graph ( arg , & obj - > a , & obj - > b , & obj - > c , & obj - > d , & obj - > e ) ;
2005-08-08 01:18:52 +00:00
END OBJ ( color , 0 )
# 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 */
2005-08-02 05:06:53 +00:00
END
2006-01-28 01:28:23 +00:00
OBJ ( font , 0 )
obj - > data . s = scan_font ( arg ) ;
2005-08-27 07:58:29 +00:00
END
2005-08-29 16:49:09 +00:00
OBJ ( downspeed , INFO_NET )
if ( arg ) {
obj - > data . net = get_net_stat ( arg ) ;
}
else {
CRIT_ERR ( " downspeed needs argument " ) ;
}
END OBJ ( downspeedf , INFO_NET )
if ( arg ) {
obj - > data . net = get_net_stat ( arg ) ;
}
else {
CRIT_ERR ( " downspeedf needs argument " ) ;
}
2005-07-29 04:32:56 +00:00
END OBJ ( downspeedgraph , INFO_NET )
2006-01-28 01:28:23 +00:00
( void ) scan_graph ( arg , & obj - > a , & obj - > b , & obj - > c , & obj - > d , & obj - > e ) ;
2005-07-30 22:59:01 +00:00
char buf [ 64 ] ;
sscanf ( arg , " %63s %*i,%*i %*i " , buf ) ;
obj - > data . net = get_net_stat ( buf ) ;
if ( sscanf ( arg , " %*s %d,%d %*d " , & obj - > b , & obj - > a ) < = 1 ) {
if ( sscanf ( arg , " %*s %d,%d " , & obj - > b , & obj - > a ) < = 1 ) {
obj - > a = 0 ;
obj - > b = 25 ;
}
}
2006-01-25 04:31:00 +00:00
END OBJ ( else , 0 )
2006-01-28 01:28:23 +00:00
if ( blockdepth ) {
( text_objects [ blockstart [ blockdepth - 1 ] ] ) . data . ifblock . pos = object_count ;
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 - - ;
text_objects [ blockstart [ blockdepth ] ] . data . ifblock . pos = object_count ;
} else {
ERR ( " $endif: no matching $if_* " ) ;
}
2005-07-20 00:30:40 +00:00
END
# ifdef HAVE_POPEN
2006-01-28 01:28:23 +00:00
OBJ ( exec , 0 ) obj - > data . s = strdup ( arg ? arg : " " ) ;
2005-07-30 22:59:01 +00:00
END OBJ ( execbar , 0 ) obj - > data . s = strdup ( arg ? arg : " " ) ;
END OBJ ( execgraph , 0 ) obj - > data . s = strdup ( arg ? arg : " " ) ;
2005-08-23 03:00:50 +00:00
END OBJ ( execibar , 0 ) unsigned int n ;
if ( ! arg | | sscanf ( arg , " %f %n " , & obj - > data . execi . interval , & n ) < = 0 ) {
char buf [ 256 ] ;
ERR ( " ${execibar <interval> command} " ) ;
obj - > type = OBJ_text ;
snprintf ( buf , 256 , " ${%s} " , s ) ;
obj - > data . s = strdup ( buf ) ;
2006-01-28 01:28:23 +00:00
} else {
obj - > data . execi . cmd = strdup ( arg + n ) ;
}
2005-08-23 03:00:50 +00:00
END OBJ ( execigraph , 0 ) unsigned int n ;
if ( ! arg | | sscanf ( arg , " %f %n " , & obj - > data . execi . interval , & n ) < = 0 ) {
char buf [ 256 ] ;
ERR ( " ${execigraph <interval> command} " ) ;
obj - > type = OBJ_text ;
snprintf ( buf , 256 , " ${%s} " , s ) ;
obj - > data . s = strdup ( buf ) ;
2005-12-13 03:36:28 +00:00
} else {
obj - > data . execi . cmd = strdup ( arg + n ) ;
}
2005-07-28 04:48:27 +00:00
END OBJ ( execi , 0 ) unsigned int n ;
2005-07-20 00:30:40 +00:00
if ( ! arg
2006-01-28 01:28:23 +00:00
| | sscanf ( arg , " %f %n " , & obj - > data . execi . interval , & n ) < = 0 ) {
2005-07-20 00:30:40 +00:00
char buf [ 256 ] ;
ERR ( " ${execi <interval> command} " ) ;
obj - > type = OBJ_text ;
snprintf ( buf , 256 , " ${%s} " , s ) ;
obj - > data . s = strdup ( buf ) ;
} else {
obj - > data . execi . cmd = strdup ( arg + n ) ;
obj - > data . execi . buffer =
2006-01-28 01:28:23 +00:00
( char * ) calloc ( 1 , TEXT_BUFFER_SIZE ) ;
2005-07-20 00:30:40 +00:00
}
2005-08-29 17:06:31 +00:00
END OBJ ( texeci , 0 ) unsigned int n ;
2006-01-28 22:13:23 +00:00
if ( ! arg | | sscanf ( arg , " %f %n " , & obj - > data . execi . interval , & n ) < = 0 ) {
2005-08-29 17:06:31 +00:00
char buf [ 256 ] ;
ERR ( " ${texeci <interval> command} " ) ;
obj - > type = OBJ_text ;
snprintf ( buf , 256 , " ${%s} " , s ) ;
obj - > data . s = strdup ( buf ) ;
2006-01-28 01:28:23 +00:00
} else {
obj - > data . execi . cmd = strdup ( arg + n ) ;
obj - > data . execi . buffer =
( char * ) calloc ( 1 , TEXT_BUFFER_SIZE ) ;
}
2006-02-01 14:39:23 +00:00
obj - > data . execi . pos = - 1 ;
2005-07-20 00:30:40 +00:00
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 ' ;
( void ) pclose ( fp ) ;
obj - > data . s = strdup ( buf ) ;
} else
obj - > data . s = strdup ( " " ) ;
END
# endif
2006-01-28 01:28:23 +00:00
OBJ ( fs_bar , INFO_FS ) obj - > data . fsbar . h = 4 ;
2005-07-20 00:30:40 +00:00
arg = scan_bar ( arg , & obj - > data . fsbar . w , & obj - > data . fsbar . h ) ;
if ( arg ) {
while ( isspace ( * arg ) )
arg + + ;
if ( * arg = = ' \0 ' )
arg = " / " ;
} else
arg = " / " ;
obj - > data . fsbar . fs = prepare_fs_stat ( arg ) ;
END OBJ ( fs_bar_free , INFO_FS ) obj - > data . fsbar . h = 4 ;
if ( arg ) {
unsigned int n ;
if ( sscanf ( arg , " %d %n " , & obj - > data . fsbar . h , & n ) > = 1 )
arg + = n ;
} else
arg = " / " ;
obj - > data . fsbar . fs = prepare_fs_stat ( arg ) ;
END OBJ ( fs_free , INFO_FS ) if ( ! arg )
2006-01-28 01:28:23 +00:00
arg = " / " ;
2005-07-20 00:30:40 +00:00
obj - > data . fs = prepare_fs_stat ( arg ) ;
END OBJ ( fs_used_perc , INFO_FS ) if ( ! arg )
2006-01-28 01:28:23 +00:00
arg = " / " ;
2005-07-20 00:30:40 +00:00
obj - > data . fs = prepare_fs_stat ( arg ) ;
END OBJ ( fs_free_perc , INFO_FS ) if ( ! arg )
2006-01-28 01:28:23 +00:00
arg = " / " ;
2005-07-20 00:30:40 +00:00
obj - > data . fs = prepare_fs_stat ( arg ) ;
END OBJ ( fs_size , INFO_FS ) if ( ! arg )
2006-01-28 01:28:23 +00:00
arg = " / " ;
2005-07-20 00:30:40 +00:00
obj - > data . fs = prepare_fs_stat ( arg ) ;
END OBJ ( fs_used , INFO_FS ) if ( ! arg )
2006-01-28 01:28:23 +00:00
arg = " / " ;
2005-07-20 00:30:40 +00:00
obj - > data . fs = prepare_fs_stat ( arg ) ;
END OBJ ( hr , 0 ) obj - > data . i = arg ? atoi ( arg ) : 1 ;
2005-07-31 19:49:39 +00:00
END OBJ ( offset , 0 ) obj - > data . i = arg ? atoi ( arg ) : 1 ;
2005-08-21 05:04:22 +00:00
END OBJ ( voffset , 0 ) obj - > data . i = arg ? atoi ( arg ) : 1 ;
2005-07-20 00:30:40 +00:00
END OBJ ( i2c , INFO_I2C ) char buf1 [ 64 ] , buf2 [ 64 ] ;
int n ;
if ( ! arg ) {
ERR ( " i2c needs arguments " ) ;
obj - > type = OBJ_text ;
2005-09-05 02:09:31 +00:00
//obj->data.s = strdup("${i2c}");
2005-12-10 14:15:38 +00:00
return NULL ;
2005-07-20 00:30:40 +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 . i2c . fd =
2006-01-28 01:28:23 +00:00
open_i2c_sensor ( 0 , buf2 , n , & obj - > data . i2c . arg ,
obj - > data . i2c . devtype ) ;
2005-09-05 02:09:31 +00:00
strncpy ( obj - > data . i2c . type , buf2 , 63 ) ;
2005-07-20 00:30:40 +00:00
} else {
obj - > data . i2c . fd =
2006-01-28 01:28:23 +00:00
open_i2c_sensor ( buf1 , buf2 , n , & obj - > data . i2c . arg ,
obj - > data . i2c . devtype ) ;
2005-09-05 02:09:31 +00:00
strncpy ( obj - > data . i2c . type , buf2 , 63 ) ;
2005-07-20 00:30:40 +00:00
}
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 ] ;
2005-07-20 00:30:40 +00:00
int n ;
2005-07-28 04:48:27 +00:00
if ( ! arg ) {
2005-07-20 00:30:40 +00:00
ERR ( " top needs arguments " ) ;
obj - > type = OBJ_text ;
2005-09-05 02:09:31 +00:00
//obj->data.s = strdup("${top}");
2005-12-10 14:15:38 +00:00
return NULL ;
2005-07-20 00:30:40 +00:00
}
2005-07-28 04:48:27 +00:00
if ( sscanf ( arg , " %63s %i " , buf , & n ) = = 2 ) {
if ( strcmp ( buf , " name " ) = = 0 ) {
2005-07-20 00:30:40 +00:00
obj - > data . top . type = TOP_NAME ;
2005-07-28 04:48:27 +00:00
} else if ( strcmp ( buf , " cpu " ) = = 0 ) {
2005-07-20 00:30:40 +00:00
obj - > data . top . type = TOP_CPU ;
2005-07-28 04:48:27 +00:00
} else if ( strcmp ( buf , " pid " ) = = 0 ) {
2005-07-20 00:30:40 +00:00
obj - > data . top . type = TOP_PID ;
2005-07-28 04:48:27 +00:00
} else if ( strcmp ( buf , " mem " ) = = 0 ) {
2005-07-20 00:30:40 +00:00
obj - > data . top . type = TOP_MEM ;
2005-07-28 04:48:27 +00:00
} else {
2005-07-20 00:30:40 +00:00
ERR ( " invalid arg for top " ) ;
2005-12-10 14:15:38 +00:00
return NULL ;
2005-07-20 00:30:40 +00:00
}
2005-07-28 04:48:27 +00:00
if ( n < 1 | | n > 10 ) {
2005-07-20 00:30:40 +00:00
CRIT_ERR ( " invalid arg for top " ) ;
2005-12-10 14:15:38 +00:00
return NULL ;
2005-07-28 04:48:27 +00:00
} else {
obj - > data . top . num = n - 1 ;
2005-07-25 00:22:16 +00:00
top_cpu = 1 ;
2005-07-20 00:30:40 +00:00
}
2005-07-28 04:48:27 +00:00
} else {
2005-07-20 00:30:40 +00:00
ERR ( " invalid args given for top " ) ;
2005-12-10 14:15:38 +00:00
return NULL ;
2005-07-20 00:30:40 +00:00
}
2005-07-28 04:48:27 +00:00
END OBJ ( top_mem , INFO_TOP )
2006-01-28 01:28:23 +00:00
char buf [ 64 ] ;
2005-07-25 00:22:16 +00:00
int n ;
2005-07-28 04:48:27 +00:00
if ( ! arg ) {
2005-07-25 00:22:16 +00:00
ERR ( " top_mem needs arguments " ) ;
obj - > type = OBJ_text ;
obj - > data . s = strdup ( " ${top_mem} " ) ;
2005-12-10 14:15:38 +00:00
return NULL ;
2005-07-25 00:22:16 +00:00
}
2005-07-28 04:48:27 +00:00
if ( sscanf ( arg , " %63s %i " , buf , & n ) = = 2 ) {
if ( strcmp ( buf , " name " ) = = 0 ) {
2005-07-25 00:22:16 +00:00
obj - > data . top . type = TOP_NAME ;
2005-07-28 04:48:27 +00:00
} else if ( strcmp ( buf , " cpu " ) = = 0 ) {
2005-07-25 00:22:16 +00:00
obj - > data . top . type = TOP_CPU ;
2005-07-28 04:48:27 +00:00
} else if ( strcmp ( buf , " pid " ) = = 0 ) {
2005-07-25 00:22:16 +00:00
obj - > data . top . type = TOP_PID ;
2005-07-28 04:48:27 +00:00
} else if ( strcmp ( buf , " mem " ) = = 0 ) {
2005-07-25 00:22:16 +00:00
obj - > data . top . type = TOP_MEM ;
2005-07-28 04:48:27 +00:00
} else {
2005-07-25 00:22:16 +00:00
ERR ( " invalid arg for top " ) ;
2005-12-10 14:15:38 +00:00
return NULL ;
2005-07-25 00:22:16 +00:00
}
2005-07-28 04:48:27 +00:00
if ( n < 1 | | n > 10 ) {
2005-07-25 00:22:16 +00:00
CRIT_ERR ( " invalid arg for top " ) ;
2005-12-10 14:15:38 +00:00
return NULL ;
2005-07-28 04:48:27 +00:00
} else {
obj - > data . top . num = n - 1 ;
2005-07-25 00:22:16 +00:00
top_mem = 1 ;
}
2005-07-28 04:48:27 +00:00
} else {
2005-07-25 00:22:16 +00:00
ERR ( " invalid args given for top " ) ;
2005-12-10 14:15:38 +00:00
return NULL ;
2005-07-25 00:22:16 +00:00
}
2005-08-29 16:49:09 +00:00
END OBJ ( addr , INFO_NET )
if ( arg ) {
obj - > data . net = get_net_stat ( arg ) ;
}
else {
CRIT_ERR ( " addr needs argument " ) ;
}
END OBJ ( linkstatus , INFO_WIFI )
if ( arg ) {
obj - > data . net = get_net_stat ( arg ) ;
}
else {
CRIT_ERR ( " linkstatus needs argument " ) ;
}
2005-07-28 04:48:27 +00:00
END OBJ ( tail , 0 )
2006-01-28 01:28:23 +00:00
char buf [ 64 ] ;
2005-07-20 00:30:40 +00:00
int n1 , n2 ;
2005-07-28 04:48:27 +00:00
if ( ! arg ) {
2005-07-20 00:30:40 +00:00
ERR ( " tail needs arguments " ) ;
obj - > type = OBJ_text ;
obj - > data . s = strdup ( " ${tail} " ) ;
2005-12-10 14:15:38 +00:00
return NULL ;
2005-07-20 00:30:40 +00:00
}
2005-07-28 04:48:27 +00:00
if ( sscanf ( arg , " %63s %i %i " , buf , & n1 , & n2 ) = = 2 ) {
if ( n1 < 1 | | n1 > 30 ) {
2005-08-10 05:52:52 +00:00
CRIT_ERR ( " invalid arg for tail, number of lines must be between 1 and 30 " ) ;
2005-12-10 14:15:38 +00:00
return NULL ;
2005-07-28 04:48:27 +00:00
} else {
2005-11-12 04:26:00 +00:00
FILE * fp = NULL ;
fp = fopen ( buf , " r " ) ;
if ( fp ) {
2005-07-28 04:48:27 +00:00
obj - > data . tail . logfile =
2006-01-28 01:28:23 +00:00
malloc ( TEXT_BUFFER_SIZE ) ;
2005-07-20 00:30:40 +00:00
strcpy ( obj - > data . tail . logfile , buf ) ;
2005-07-28 04:48:27 +00:00
obj - > data . tail . wantedlines = n1 - 1 ;
obj - > data . tail . interval =
2006-01-28 01:28:23 +00:00
update_interval * 2 ;
2005-07-28 04:48:27 +00:00
fclose ( fp ) ;
} else {
2005-07-20 00:30:40 +00:00
//fclose (fp);
2005-08-10 05:52:52 +00:00
CRIT_ERR ( " tail logfile does not exist, or you do not have correct permissions " ) ;
2005-07-20 00:30:40 +00:00
}
}
2005-07-28 04:48:27 +00:00
} else if ( sscanf ( arg , " %63s %i %i " , buf , & n1 , & n2 ) = = 3 ) {
if ( n1 < 1 | | n1 > 30 ) {
CRIT_ERR
2006-01-28 01:28:23 +00:00
( " invalid arg for tail, number of lines must be between 1 and 30 " ) ;
2005-12-10 14:15:38 +00:00
return NULL ;
2005-07-28 04:48:27 +00:00
} else if ( n2 < 1 | | n2 < update_interval ) {
CRIT_ERR
2006-01-28 01:28:23 +00:00
( " invalid arg for tail, interval must be greater than 0 and Conky's interval " ) ;
2005-12-10 14:15:38 +00:00
return NULL ;
2005-07-28 04:48:27 +00:00
} else {
FILE * fp ;
2005-11-12 04:26:00 +00:00
fp = fopen ( buf , " r " ) ;
2005-07-20 00:30:40 +00:00
if ( fp ! = NULL ) {
2005-07-28 04:48:27 +00:00
obj - > data . tail . logfile =
2006-01-28 01:28:23 +00:00
malloc ( TEXT_BUFFER_SIZE ) ;
2005-07-20 00:30:40 +00:00
strcpy ( obj - > data . tail . logfile , buf ) ;
2005-07-28 04:48:27 +00:00
obj - > data . tail . wantedlines = n1 - 1 ;
2005-07-20 00:30:40 +00:00
obj - > data . tail . interval = n2 ;
2005-07-28 04:48:27 +00:00
fclose ( fp ) ;
} else {
2005-07-20 00:30:40 +00:00
//fclose (fp);
2005-08-10 05:52:52 +00:00
CRIT_ERR ( " tail logfile does not exist, or you do not have correct permissions " ) ;
2005-07-20 00:30:40 +00:00
}
}
}
else {
ERR ( " invalid args given for tail " ) ;
2005-12-10 14:15:38 +00:00
return NULL ;
2005-07-20 00:30:40 +00:00
}
2005-08-26 05:52:43 +00:00
obj - > data . tail . buffer = malloc ( TEXT_BUFFER_SIZE * 20 ) ; /* asumming all else worked */
END OBJ ( head , 0 )
2006-01-28 01:28:23 +00:00
char buf [ 64 ] ;
2005-08-26 05:52:43 +00:00
int n1 , n2 ;
if ( ! arg ) {
ERR ( " head needs arguments " ) ;
obj - > type = OBJ_text ;
obj - > data . s = strdup ( " ${head} " ) ;
2005-12-10 14:15:38 +00:00
return NULL ;
2005-08-26 05:52:43 +00:00
}
if ( sscanf ( arg , " %63s %i %i " , buf , & n1 , & n2 ) = = 2 ) {
if ( n1 < 1 | | n1 > 30 ) {
CRIT_ERR ( " invalid arg for head, number of lines must be between 1 and 30 " ) ;
2005-12-10 14:15:38 +00:00
return NULL ;
2005-08-26 05:52:43 +00:00
} else {
FILE * fp ;
2005-11-12 04:26:00 +00:00
fp = fopen ( buf , " r " ) ;
2005-08-26 05:52:43 +00:00
if ( fp ! = NULL ) {
obj - > data . tail . logfile =
2006-01-28 01:28:23 +00:00
malloc ( TEXT_BUFFER_SIZE ) ;
2005-08-26 05:52:43 +00:00
strcpy ( obj - > data . tail . logfile , buf ) ;
obj - > data . tail . wantedlines = n1 - 1 ;
obj - > data . tail . interval =
2006-01-28 01:28:23 +00:00
update_interval * 2 ;
2005-08-26 05:52:43 +00:00
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 ) {
if ( n1 < 1 | | n1 > 30 ) {
CRIT_ERR
2006-01-28 01:28:23 +00:00
( " invalid arg for head, number of lines must be between 1 and 30 " ) ;
2005-12-10 14:15:38 +00:00
return NULL ;
2005-08-26 05:52:43 +00:00
} else if ( n2 < 1 | | n2 < update_interval ) {
CRIT_ERR
2006-01-28 01:28:23 +00:00
( " invalid arg for head, interval must be greater than 0 and Conky's interval " ) ;
2005-12-10 14:15:38 +00:00
return NULL ;
2005-08-26 05:52:43 +00:00
} else {
FILE * fp ;
2005-11-12 04:26:00 +00:00
fp = fopen ( buf , " r " ) ;
2005-08-26 05:52:43 +00:00
if ( fp ! = NULL ) {
obj - > data . tail . logfile =
2006-01-28 01:28:23 +00:00
malloc ( TEXT_BUFFER_SIZE ) ;
2005-08-26 05:52:43 +00:00
strcpy ( obj - > data . tail . logfile , buf ) ;
obj - > data . tail . wantedlines = n1 - 1 ;
obj - > data . tail . interval = n2 ;
fclose ( fp ) ;
} else {
//fclose (fp);
CRIT_ERR ( " head logfile does not exist, or you do not have correct permissions " ) ;
}
}
}
else {
ERR ( " invalid args given for head " ) ;
2005-12-10 14:15:38 +00:00
return NULL ;
2005-08-26 05:52:43 +00:00
}
obj - > data . tail . buffer = malloc ( TEXT_BUFFER_SIZE * 20 ) ; /* asumming all else worked */
2005-07-28 04:48:27 +00:00
END OBJ ( loadavg , INFO_LOADAVG ) int a = 1 , b = 2 , c = 3 , r = 3 ;
2005-07-20 00:30:40 +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 ;
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 " ) ;
}
2005-07-28 04:48:27 +00:00
if ( ! arg ) {
ERR ( " if_existing needs an argument " ) ;
obj - > data . ifblock . s = 0 ;
} else
obj - > data . ifblock . s = strdup ( arg ) ;
2006-01-25 04:31:00 +00:00
blockstart [ blockdepth ] = object_count ;
obj - > data . ifblock . pos = object_count + 2 ;
2005-07-28 04:48:27 +00:00
blockdepth + + ;
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 " ) ;
}
2005-07-28 04:48:27 +00:00
if ( ! arg ) {
ERR ( " if_mounted needs an argument " ) ;
obj - > data . ifblock . s = 0 ;
} else
obj - > data . ifblock . s = strdup ( arg ) ;
2006-01-25 04:31:00 +00:00
blockstart [ blockdepth ] = object_count ;
obj - > data . ifblock . pos = object_count + 2 ;
2005-07-28 04:48:27 +00:00
blockdepth + + ;
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 " ) ;
}
2005-07-28 04:48:27 +00:00
if ( arg ) {
char buf [ 256 ] ;
snprintf ( buf , 256 , " pidof %s >/dev/null " , arg ) ;
obj - > data . ifblock . s = strdup ( buf ) ;
} else {
ERR ( " if_running needs an argument " ) ;
obj - > data . ifblock . s = 0 ;
}
2006-01-25 04:31:00 +00:00
blockstart [ blockdepth ] = object_count ;
obj - > data . ifblock . pos = object_count + 2 ;
2005-07-28 04:48:27 +00:00
blockdepth + + ;
END OBJ ( kernel , 0 )
2006-01-28 01:28:23 +00:00
END OBJ ( machine , 0 )
END OBJ ( mails , INFO_MAIL )
END OBJ ( mem , INFO_MEM )
END OBJ ( memmax , INFO_MEM )
END OBJ ( memperc , INFO_MEM )
END OBJ ( membar , INFO_MEM )
( void ) scan_bar ( arg , & obj - > data . pair . a , & obj - > data . pair . b ) ;
2005-08-10 16:07:03 +00:00
END OBJ ( memgraph , INFO_MEM )
2006-01-28 01:28:23 +00:00
( void ) scan_graph ( arg , & obj - > a , & obj - > b , & obj - > c , & obj - > d , & obj - > e ) ;
2005-07-20 00:30:40 +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 ) ;
END OBJ ( mixerbar , INFO_MIXER )
2006-01-28 01:28:23 +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 )
2006-01-28 01:28:23 +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 )
2006-01-28 01:28:23 +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
2005-07-28 04:48:27 +00:00
# ifdef MLDONKEY
2006-01-28 01:28:23 +00:00
OBJ ( ml_upload_counter , INFO_MLDONKEY )
END OBJ ( ml_download_counter , INFO_MLDONKEY )
END OBJ ( ml_nshared_files , INFO_MLDONKEY )
END OBJ ( ml_shared_counter , INFO_MLDONKEY )
END OBJ ( ml_tcp_upload_rate , INFO_MLDONKEY )
END OBJ ( ml_tcp_download_rate , INFO_MLDONKEY )
END OBJ ( ml_udp_upload_rate , INFO_MLDONKEY )
END OBJ ( ml_udp_download_rate , INFO_MLDONKEY )
END OBJ ( ml_ndownloaded_files , INFO_MLDONKEY )
END OBJ ( ml_ndownloading_files , INFO_MLDONKEY ) END
2005-07-28 04:48:27 +00:00
# endif
2006-01-28 01:28:23 +00:00
OBJ ( new_mails , INFO_MAIL )
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 ;
2005-07-20 00:30:40 +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 )
2006-01-28 01:28:23 +00:00
END OBJ ( swapmax , INFO_MEM )
END OBJ ( swapperc , INFO_MEM )
END OBJ ( swapbar , INFO_MEM )
( void ) scan_bar ( arg , & obj - > data . pair . a , & obj - > data . pair . b ) ;
2005-07-20 00:30:40 +00:00
END OBJ ( sysname , 0 ) END OBJ ( temp1 , INFO_I2C ) obj - > type = OBJ_i2c ;
obj - > data . i2c . fd =
2006-01-28 01:28:23 +00:00
open_i2c_sensor ( 0 , " temp " , 1 , & obj - > data . i2c . arg ,
obj - > data . i2c . devtype ) ;
2005-07-20 00:30:40 +00:00
END OBJ ( temp2 , INFO_I2C ) obj - > type = OBJ_i2c ;
obj - > data . i2c . fd =
2006-01-28 01:28:23 +00:00
open_i2c_sensor ( 0 , " temp " , 2 , & obj - > data . i2c . arg ,
obj - > data . i2c . devtype ) ;
2005-07-20 00:30:40 +00:00
END OBJ ( time , 0 ) obj - > data . s = strdup ( arg ? arg : " %F %T " ) ;
END OBJ ( utime , 0 ) obj - > data . s = strdup ( arg ? arg : " %F %T " ) ;
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 ) {
CRIT_ERR ( " You must stop your last iconv conversion before starting another " ) ;
}
if ( arg ) {
char iconv_from [ CODEPAGE_LENGTH ] ;
char iconv_to [ CODEPAGE_LENGTH ] ;
if ( sscanf ( arg , " %s %s " , iconv_from , iconv_to ) ! = 2 ) {
CRIT_ERR ( " Invalid arguments for iconv_start " ) ;
} else {
iconv_t new_iconv ;
new_iconv = iconv_open ( iconv_to , iconv_from ) ;
if ( new_iconv = = ( iconv_t ) ( - 1 ) ) {
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 ;
# endif
2005-08-29 16:49:09 +00:00
END OBJ ( totaldown , INFO_NET )
if ( arg ) {
obj - > data . net = get_net_stat ( arg ) ;
}
else {
CRIT_ERR ( " totaldown needs argument " ) ;
}
2005-07-20 00:30:40 +00:00
END OBJ ( totalup , INFO_NET ) obj - > data . net = get_net_stat ( arg ) ;
2006-01-28 01:28:23 +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 )
2006-01-28 01:28:23 +00:00
END OBJ ( alignr , 0 ) obj - > data . i = arg ? atoi ( arg ) : 0 ;
2005-08-10 05:52:52 +00:00
END OBJ ( alignc , 0 ) obj - > data . i = arg ? atoi ( arg ) : 0 ;
2005-08-29 16:49:09 +00:00
END OBJ ( upspeed , INFO_NET )
if ( arg ) {
obj - > data . net = get_net_stat ( arg ) ;
}
else {
CRIT_ERR ( " upspeed needs argument " ) ;
}
END OBJ ( upspeedf , INFO_NET )
if ( arg ) {
obj - > data . net = get_net_stat ( arg ) ;
}
else {
CRIT_ERR ( " upspeedf needs argument " ) ;
}
2005-07-29 04:32:56 +00:00
END OBJ ( upspeedgraph , INFO_NET )
2006-01-28 01:28:23 +00:00
( void ) scan_graph ( arg , & obj - > a , & obj - > b , & obj - > c , & obj - > d , & obj - > e ) ;
2005-07-30 22:59:01 +00:00
char buf [ 64 ] ;
sscanf ( arg , " %63s %*i,%*i %*i " , buf ) ;
obj - > data . net = get_net_stat ( buf ) ;
if ( sscanf ( arg , " %*s %d,%d %*d " , & obj - > b , & obj - > a ) < = 1 ) {
if ( sscanf ( arg , " %*s %d,%d " , & obj - > a , & obj - > a ) < = 1 ) {
obj - > a = 0 ;
obj - > b = 25 ;
}
}
2005-07-20 00:30:40 +00:00
END OBJ ( uptime_short , INFO_UPTIME ) END OBJ ( uptime , INFO_UPTIME ) END
2006-01-28 01:28:23 +00:00
OBJ ( adt746xcpu , 0 ) END OBJ ( adt746xfan , 0 ) END
2005-09-29 03:22:31 +00:00
# if defined(__FreeBSD__) && (defined(i386) || defined(__i386__))
2006-01-28 01:28:23 +00:00
OBJ ( apm_adapter , 0 ) END
OBJ ( apm_battery_life , 0 ) END
OBJ ( apm_battery_time , 0 ) END
2005-08-30 04:19:16 +00:00
# endif /* __FreeBSD__ */
2005-07-20 00:30:40 +00:00
# ifdef SETI
2006-01-28 01:28:23 +00:00
OBJ ( seti_prog , INFO_SETI ) END OBJ ( seti_progbar , INFO_SETI )
( void ) scan_bar ( arg , & obj - > data . pair . a , & obj - > data . pair . b ) ;
2005-07-20 00:30:40 +00:00
END OBJ ( seti_credit , INFO_SETI ) END
# endif
2006-05-08 22:34:38 +00:00
OBJ ( imap_unseen , 0 )
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 ;
}
END
OBJ ( imap_messages , 0 )
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 ;
}
END
OBJ ( pop3_unseen , 0 )
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 ;
}
END
OBJ ( pop3_used , 0 )
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 ;
}
END
2005-07-20 00:30:40 +00:00
# ifdef MPD
2006-01-28 01:28:23 +00:00
OBJ ( mpd_artist , INFO_MPD )
END OBJ ( mpd_title , INFO_MPD )
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 )
2006-01-31 03:32:26 +00:00
END OBJ ( mpd_name , INFO_MPD )
END OBJ ( mpd_file , INFO_MPD )
2006-01-28 01:28:23 +00:00
END OBJ ( mpd_percent , INFO_MPD )
2006-03-07 04:23:55 +00:00
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 )
( void ) scan_bar ( arg , & obj - > data . pair . a , & obj - > data . pair . b ) ;
END OBJ ( mpd_smart , INFO_MPD ) END
2005-10-31 05:17:06 +00:00
# endif
2006-03-25 21:21:07 +00:00
# ifdef XMMS2
OBJ ( xmms2_artist , INFO_XMMS2 )
END OBJ ( xmms2_album , INFO_XMMS2 )
2006-04-16 03:49:49 +00:00
END OBJ ( xmms2_title , INFO_XMMS2 )
END OBJ ( xmms2_genre , INFO_XMMS2 )
END OBJ ( xmms2_comment , INFO_XMMS2 )
END OBJ ( xmms2_decoder , INFO_XMMS2 )
END OBJ ( xmms2_transport , 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 )
2006-03-25 21:21:07 +00:00
END OBJ ( xmms2_status , INFO_XMMS2 )
END OBJ ( xmms2_percent , INFO_XMMS2 )
END OBJ ( xmms2_bar , INFO_XMMS2 )
( void ) scan_bar ( arg , & obj - > data . pair . a , & obj - > data . pair . b ) ;
2006-04-16 03:49:49 +00:00
END OBJ ( xmms2_smart , INFO_XMMS2 )
2006-03-25 21:21:07 +00:00
END
# endif
2006-01-08 14:51:47 +00:00
# if defined(XMMS) || defined(BMP) || defined(AUDACIOUS) || defined(INFOPIPE)
2006-01-28 01:28:23 +00:00
OBJ ( xmms_status , INFO_XMMS ) END
OBJ ( xmms_title , INFO_XMMS ) END
OBJ ( xmms_length , INFO_XMMS ) END
OBJ ( xmms_length_seconds , INFO_XMMS ) END
OBJ ( xmms_position , INFO_XMMS ) END
OBJ ( xmms_position_seconds , INFO_XMMS ) END
OBJ ( xmms_bitrate , INFO_XMMS ) END
OBJ ( xmms_frequency , INFO_XMMS ) END
OBJ ( xmms_channels , INFO_XMMS ) END
OBJ ( xmms_filename , INFO_XMMS ) END
OBJ ( xmms_playlist_length , INFO_XMMS ) END
OBJ ( xmms_playlist_position , INFO_XMMS ) END
OBJ ( xmms_bar , INFO_XMMS )
( void ) scan_bar ( arg , & obj - > a , & obj - > b ) ;
END
2006-01-07 07:01:22 +00:00
# endif
2005-12-30 09:44:40 +00:00
# ifdef BMPX
2006-01-28 01:28:23 +00:00
OBJ ( bmpx_title , 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
END
2006-01-28 01:28:23 +00:00
OBJ ( bmpx_artist , 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
END
2006-01-28 01:28:23 +00:00
OBJ ( bmpx_album , 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
END
2006-01-28 01:28:23 +00:00
OBJ ( bmpx_track , 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
END
2006-01-28 01:28:23 +00:00
OBJ ( bmpx_uri , 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
END
2006-01-28 01:28:23 +00:00
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
END
# endif
2005-10-31 05:17:06 +00:00
# ifdef TCP_PORT_MONITOR
2006-01-28 01:28:23 +00:00
OBJ ( tcp_portmon , INFO_TCP_PORT_MONITOR )
2005-10-31 05:17:06 +00:00
int argc , port_begin , port_end , item , connection_index ;
2006-01-28 01:28:23 +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 ;
2006-03-30 18:14:18 +00:00
else if ( strncmp ( itembuf , " rservice " , 31 ) = = 0 )
item = REMOTESERVICE ;
2006-01-28 01:28:23 +00:00
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 " ) ;
}
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_addr_t ) port_begin ;
obj - > data . tcp_port_monitor . port_range_end = ( in_addr_t ) port_end ;
obj - > data . tcp_port_monitor . item = item ;
obj - > data . tcp_port_monitor . connection_index = connection_index ;
/* 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 ( & tcp_port_monitor_collection_args ) ;
if ( ! info . p_tcp_port_monitor_collection )
2005-10-31 05:17:06 +00:00
{
2006-01-28 01:28:23 +00:00
CRIT_ERR ( " tcp_portmon: unable to create port monitor collection " ) ;
2005-10-31 05:17:06 +00:00
}
2006-01-28 01:28:23 +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 )
2005-10-31 05:17:06 +00:00
{
2006-01-28 01:28:23 +00:00
CRIT_ERR ( " tcp_portmon: unable to create port monitor " ) ;
2005-10-31 05:17:06 +00:00
}
2006-01-28 01:28:23 +00:00
/* add the newly created monitor to the collection */
if ( insert_tcp_port_monitor_into_collection ( info . p_tcp_port_monitor_collection ,
p_monitor ) ! = 0 )
2005-10-31 05:17:06 +00:00
{
2006-01-28 01:28:23 +00:00
CRIT_ERR ( " tcp_portmon: unable to add port monitor to collection " ) ;
2005-10-31 05:17:06 +00:00
}
2006-01-28 01:28:23 +00:00
}
2005-10-31 05:17:06 +00:00
END
2005-07-20 00:30:40 +00:00
# endif
2005-07-28 04:48:27 +00:00
{
2005-07-20 00:30:40 +00:00
char buf [ 256 ] ;
ERR ( " unknown variable %s " , s ) ;
obj - > type = OBJ_text ;
snprintf ( buf , 256 , " ${%s} " , s ) ;
obj - > data . s = strdup ( buf ) ;
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 ;
obj - > data . s = strdup ( s ) ;
return obj ;
2005-07-20 00:30:40 +00:00
}
2005-12-10 14:15:38 +00:00
static struct text_object_list * extract_variable_text_internal ( const char * p )
{
2006-01-28 01:28:23 +00:00
struct text_object_list * retval ;
struct text_object * obj ;
const char * s = p ;
retval = malloc ( sizeof ( struct text_object_list ) ) ;
memset ( retval , 0 , sizeof ( struct text_object_list ) ) ;
retval - > text_object_count = 0 ;
2006-05-14 07:05:05 +00:00
long line = text_lines ;
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 = = ' $ ' ) {
* ( char * ) p = ' \0 ' ;
2005-12-10 14:15:38 +00:00
obj = create_plain_text ( s ) ;
if ( obj ! = NULL ) {
2006-01-28 01:28:23 +00:00
// allocate memory for the object
retval - > text_objects = realloc ( retval - > text_objects ,
sizeof ( struct text_object ) * ( retval - > text_object_count + 1 ) ) ;
// assign the new object to the end of the list.
memcpy ( & retval - > text_objects [ retval - > text_object_count + + ] ,
obj , sizeof ( struct text_object ) ) ;
free ( obj ) ;
2005-12-10 14:15:38 +00:00
}
2005-07-20 00:30:40 +00:00
* ( char * ) p = ' $ ' ;
p + + ;
s = p ;
if ( * p ! = ' $ ' ) {
char buf [ 256 ] ;
const char * var ;
unsigned int len ;
/* variable is either $foo or ${foo} */
if ( * p = = ' { ' ) {
p + + ;
s = p ;
while ( * p & & * p ! = ' } ' )
p + + ;
} else {
s = p ;
if ( * p = = ' # ' )
p + + ;
while ( * p & & ( isalnum ( ( int ) * p )
2006-01-28 01:28:23 +00:00
| | * p = = ' _ ' ) )
2005-07-20 00:30:40 +00:00
p + + ;
}
/* copy variable to buffer */
len = ( p - s > 255 ) ? 255 : ( p - s ) ;
strncpy ( buf , s , len ) ;
buf [ len ] = ' \0 ' ;
if ( * p = = ' } ' )
p + + ;
s = p ;
var = getenv ( buf ) ;
/* if variable wasn't found from environment, use some special */
if ( ! var ) {
char * p ;
char * arg = 0 ;
/* split arg */
if ( strchr ( buf , ' ' ) ) {
arg = strchr ( buf , ' ' ) ;
* arg = ' \0 ' ;
arg + + ;
while ( isspace ( ( int ) * arg ) )
arg + + ;
if ( ! * arg )
arg = 0 ;
}
/* lowercase variable name */
p = buf ;
while ( * p ) {
* p = tolower ( * p ) ;
p + + ;
}
2005-12-10 14:15:38 +00:00
// create new object
2006-05-14 07:05:05 +00:00
obj = construct_text_object ( buf , arg , retval - > text_object_count , retval - > text_objects , line ) ;
2005-12-10 14:15:38 +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 ,
sizeof ( struct text_object ) * ( retval - > text_object_count + 1 ) ) ;
// assign the new object to the end of the list.
memcpy ( & retval - > text_objects [ retval - > text_object_count + + ] ,
obj , sizeof ( struct text_object ) ) ;
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 ( " $ " ) ;
if ( obj ! = NULL ) {
// allocate memory for the object
retval - > text_objects = realloc ( retval - > text_objects ,
sizeof ( struct text_object ) * ( retval - > text_object_count + 1 ) ) ;
// assign the new object to the end of the list.
memcpy ( & retval - > text_objects [ retval - > text_object_count + + ] ,
obj , sizeof ( struct text_object ) ) ;
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 ) ;
if ( obj ! = NULL ) {
2006-01-28 01:28:23 +00:00
// allocate memory for the object
retval - > text_objects = realloc ( retval - > text_objects ,
sizeof ( struct text_object ) * ( retval - > text_object_count + 1 ) ) ;
// assign the new object to the end of the list.
memcpy ( & retval - > text_objects [ retval - > text_object_count + + ] ,
obj , sizeof ( struct text_object ) ) ;
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
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
2006-01-28 01:28:23 +00:00
free_text_objects ( text_object_count , text_objects ) ;
text_object_count = 0 ;
text_objects = NULL ;
2005-07-20 00:30:40 +00:00
2005-12-10 14:15:38 +00:00
# ifdef MLDONKEY
2006-01-28 01:28:23 +00:00
ml_cleanup ( ) ;
2005-12-10 14:15:38 +00:00
# endif /* MLDONKEY */
2005-07-20 00:30:40 +00:00
2006-05-13 19:51:26 +00:00
2006-01-28 01:28:23 +00:00
list = extract_variable_text_internal ( p ) ;
text_objects = list - > text_objects ;
text_object_count = list - > text_object_count ;
free ( list ) ;
2005-07-20 00:30:40 +00:00
2006-01-28 01:28:23 +00:00
return ;
2005-12-10 14:15:38 +00:00
}
2005-07-20 00:30:40 +00:00
2005-12-15 03:05:16 +00:00
void parse_conky_vars ( char * text , char * p , struct information * cur ) {
2005-12-10 21:07:24 +00:00
struct text_object_list * object_list = extract_variable_text_internal ( text ) ;
generate_text_internal ( p , P_MAX_SIZE , object_list - > text_objects , object_list - > text_object_count , cur ) ;
free ( object_list ) ;
}
2005-07-20 00:30:40 +00:00
2005-12-10 14:15:38 +00:00
static void generate_text_internal ( char * p , int p_max_size , struct text_object * objs , unsigned int object_count , struct information * cur )
{
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
2006-05-13 19:51:26 +00:00
char buff_in [ P_MAX_SIZE ] = { 0 } ;
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
# define OBJ(a) break; case OBJ_##a:
switch ( obj - > type ) {
2006-01-28 01:28:23 +00:00
default :
{
ERR ( " not implemented obj type %d " ,
obj - > type ) ;
}
OBJ ( acpitemp ) {
/* does anyone have decimals in acpi temperature? */
if ( ! use_spacer )
snprintf ( p , p_max_size , " %d " , ( int )
get_acpi_temperature ( obj - >
2005-08-21 06:36:13 +00:00
data .
i ) ) ;
2006-01-28 01:28:23 +00:00
else
snprintf ( p , 5 , " %d " , ( int )
get_acpi_temperature ( obj - >
2005-08-21 06:36:13 +00:00
data .
i ) ) ;
2005-12-06 03:33:59 +00:00
}
2006-01-28 01:28:23 +00:00
OBJ ( acpitempf ) {
/* does anyone have decimals in acpi temperature? */
if ( ! use_spacer )
snprintf ( p , p_max_size , " %d " , ( int )
( ( get_acpi_temperature ( obj - >
data .
i ) + 40 ) * 9.0 / 5 - 40 ) ) ;
else
snprintf ( p , 5 , " %d " , ( int )
( ( get_acpi_temperature ( obj - >
data .
i ) + 40 ) * 9.0 / 5 - 40 ) ) ;
2005-12-06 03:33:59 +00:00
}
2006-01-28 01:28:23 +00:00
OBJ ( freq ) {
get_freq ( p , p_max_size , " %.0f " , 1 ) ; /* pk */
}
OBJ ( freq_g ) {
get_freq ( p , p_max_size , " %'.2f " , 1000 ) ; /* pk */
}
OBJ ( freq_dyn ) {
if ( use_spacer ) {
get_freq_dynamic ( p , 6 , " %.0f " , 1 ) ; /* pk */
} else {
get_freq_dynamic ( p , p_max_size , " %.0f " , 1 ) ; /* pk */
}
}
OBJ ( freq_dyn_g ) {
if ( use_spacer ) {
get_freq_dynamic ( p , 6 , " %'.2f " , 1000 ) ; /* pk */
} else {
get_freq_dynamic ( p , p_max_size , " %'.2f " , 1000 ) ; /* pk */
}
}
OBJ ( adt746xcpu ) {
get_adt746x_cpu ( p , p_max_size ) ; /* pk */
}
OBJ ( adt746xfan ) {
get_adt746x_fan ( p , p_max_size ) ; /* pk */
}
OBJ ( acpifan ) {
get_acpi_fan ( p , p_max_size ) ; /* pk */
}
OBJ ( acpiacadapter ) {
get_acpi_ac_adapter ( p , p_max_size ) ; /* pk */
}
OBJ ( battery ) {
get_battery_stuff ( p , p_max_size , obj - > data . s ) ;
}
OBJ ( buffers ) {
human_readable ( cur - > buffers * 1024 , p , 255 ) ;
}
OBJ ( cached ) {
human_readable ( cur - > cached * 1024 , p , 255 ) ;
}
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 ) ;
CRIT_ERR ( " attempting to use more CPUs then you have! " ) ;
}
if ( ! use_spacer )
snprintf ( p , p_max_size , " %*d " , pad_percents ,
( int ) round_to_int ( cur - > cpu_usage [ obj - > data . cpu_index ] *
100.0 ) ) ;
else
snprintf ( p , 4 , " %*d " ,
pad_percents ,
( int ) round_to_int ( cur - > cpu_usage [ obj - > data . cpu_index ] *
100.0 ) ) ;
}
OBJ ( cpubar ) {
new_bar ( p , obj - > a ,
obj - > b ,
( int ) round_to_int ( cur - > cpu_usage [ obj - > data . cpu_index ] * 255.0 ) ) ;
}
OBJ ( cpugraph ) {
new_graph ( p , obj - > a ,
obj - > b , obj - > c , obj - > d ,
( unsigned int ) round_to_int ( cur - > cpu_usage [ obj - > data . cpu_index ] *
100 ) , 100 , 1 ) ;
}
OBJ ( color ) {
new_fg ( p , obj - > data . l ) ;
2005-08-27 09:34:00 +00:00
}
2005-08-27 12:59:46 +00:00
# if defined(__linux__)
2006-01-28 01:28:23 +00:00
OBJ ( i8k_version ) {
snprintf ( p , p_max_size , " %s " , i8k . version ) ;
}
OBJ ( i8k_bios ) {
snprintf ( p , p_max_size , " %s " , i8k . bios ) ;
2005-08-27 07:15:44 +00:00
}
2006-01-28 01:28:23 +00:00
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 ;
sscanf ( i8k . left_fan_status , " %d " , & left_fan_status ) ;
if ( left_fan_status = = 0 ) {
snprintf ( p , p_max_size , " off " ) ;
} if ( left_fan_status = = 1 ) {
snprintf ( p , p_max_size , " low " ) ;
} if ( left_fan_status = = 2 ) {
snprintf ( p , p_max_size , " high " ) ;
}
2005-08-27 07:15:44 +00:00
}
2006-01-28 01:28:23 +00:00
OBJ ( i8k_right_fan_status ) {
int right_fan_status ;
sscanf ( i8k . right_fan_status , " %d " , & right_fan_status ) ;
if ( right_fan_status = = 0 ) {
snprintf ( p , p_max_size , " off " ) ;
} if ( right_fan_status = = 1 ) {
snprintf ( p , p_max_size , " low " ) ;
} if ( right_fan_status = = 2 ) {
snprintf ( p , p_max_size , " high " ) ;
}
2005-08-27 07:15:44 +00:00
}
2006-01-28 01:28:23 +00:00
OBJ ( i8k_left_fan_rpm ) {
snprintf ( p , p_max_size , " %s " , i8k . left_fan_rpm ) ;
}
OBJ ( i8k_right_fan_rpm ) {
snprintf ( p , p_max_size , " %s " , i8k . right_fan_rpm ) ;
}
OBJ ( i8k_ac_status ) {
int ac_status ;
sscanf ( i8k . ac_status , " %d " , & ac_status ) ;
if ( ac_status = = - 1 ) {
snprintf ( p , p_max_size , " disabled (read i8k docs) " ) ;
} if ( ac_status = = 0 ) {
snprintf ( p , p_max_size , " off " ) ;
} if ( ac_status = = 1 ) {
snprintf ( p , p_max_size , " on " ) ;
}
}
OBJ ( i8k_buttons_status ) {
snprintf ( p , p_max_size , " %s " , i8k . buttons_status ) ;
2005-08-27 07:15:44 +00:00
2006-01-28 01:28:23 +00:00
}
2006-04-15 18:00:39 +00:00
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 ) ;
}
2006-04-23 21:35:31 +00:00
OBJ ( pb_battery ) {
get_powerbook_batt_info ( p , p_max_size , obj - > data . i ) ;
}
2005-08-27 12:59:46 +00:00
# endif /* __linux__ */
2005-08-27 07:15:44 +00:00
2005-08-11 05:21:56 +00:00
# ifdef X11
2006-01-28 01:28:23 +00:00
OBJ ( font ) {
new_font ( p , obj - > data . s ) ;
}
2005-08-11 05:21:56 +00:00
# endif /* X11 */
2006-01-28 01:28:23 +00:00
OBJ ( diskio ) {
if ( ! use_spacer ) {
if ( diskio_value > 1024 * 1024 ) {
snprintf ( p , p_max_size , " %.1fG " ,
( double ) diskio_value / 1024 / 1024 ) ;
} else if ( diskio_value > 1024 ) {
snprintf ( p , p_max_size , " %.1fM " ,
( double ) diskio_value / 1024 ) ;
} else if ( diskio_value > 0 ) {
snprintf ( p , p_max_size , " %dK " , diskio_value ) ;
} else {
snprintf ( p , p_max_size , " %d " , diskio_value ) ;
}
2005-08-26 05:52:43 +00:00
} else {
2006-01-28 01:28:23 +00:00
if ( diskio_value > 1024 * 1024 ) {
snprintf ( p , 6 , " %.1fG " ,
( double ) diskio_value / 1024 / 1024 ) ;
} else if ( diskio_value > 1024 ) {
snprintf ( p , 6 , " %.1fM " ,
( double ) diskio_value / 1024 ) ;
} else if ( diskio_value > 0 ) {
snprintf ( p , 6 , " %dK " , diskio_value ) ;
} else {
snprintf ( p , 6 , " %d " , diskio_value ) ;
}
2005-08-26 05:52:43 +00:00
}
2006-01-28 01:28:23 +00:00
}
OBJ ( diskiograph ) {
new_graph ( p , obj - > a ,
obj - > b , obj - > c , obj - > d ,
diskio_value , obj - > e , 1 ) ;
}
OBJ ( downspeed ) {
if ( ! use_spacer ) {
snprintf ( p , p_max_size , " %d " ,
( int ) ( obj - > data . net - >
recv_speed /
1024 ) ) ;
} else
snprintf ( p , 6 , " %d " ,
( int ) ( obj - > data . net - >
recv_speed /
1024 ) ) ;
}
OBJ ( downspeedf ) {
if ( ! use_spacer )
snprintf ( p , p_max_size , " %.1f " ,
obj - > data . net - >
recv_speed / 1024.0 ) ;
else
snprintf ( p , 8 , " %.1f " ,
obj - > data . net - >
recv_speed / 1024.0 ) ;
}
OBJ ( downspeedgraph ) {
if ( obj - > data . net - > recv_speed = = 0 ) // this is just to make the ugliness at start go away
obj - > data . net - > recv_speed = 0.01 ;
new_graph ( p , obj - > a , obj - > b , obj - > c , obj - > d ,
( obj - > data . net - > recv_speed /
1024.0 ) , obj - > e , 1 ) ;
}
2006-04-23 21:57:04 +00:00
OBJ ( else ) {
2006-01-28 01:28:23 +00:00
if ( ! if_jumped ) {
2006-04-23 21:57:04 +00:00
i = obj - > data . ifblock . pos - 1 ;
2005-08-26 05:52:43 +00:00
} else {
2006-01-28 01:28:23 +00:00
if_jumped = 0 ;
2005-08-26 05:52:43 +00:00
}
2005-08-26 02:16:35 +00:00
}
2006-01-28 01:28:23 +00:00
OBJ ( endif ) {
2005-07-28 04:48:27 +00:00
if_jumped = 0 ;
}
2005-07-20 00:30:40 +00:00
# ifdef HAVE_POPEN
2006-01-28 01:28:23 +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 ) ;
2005-07-28 06:56:55 +00:00
2006-01-28 01:28:23 +00:00
}
OBJ ( linkstatus ) {
snprintf ( p , p_max_size , " %d " ,
obj - > data . net - > linkstatus ) ;
}
2005-12-15 04:13:32 +00:00
2006-01-28 01:28:23 +00:00
OBJ ( exec ) {
FILE * fp = popen ( obj - > data . s , " r " ) ;
int length = fread ( p , 1 , p_max_size , fp ) ;
( void ) pclose ( fp ) ;
/*output[length] = '\0';
if ( length > 0 & & output [ length - 1 ] = = ' \n ' ) {
output [ length - 1 ] = ' \0 ' ;
} */
2005-12-15 04:13:32 +00:00
p [ length ] = ' \0 ' ;
if ( length > 0 & & p [ length - 1 ] = = ' \n ' ) {
p [ length - 1 ] = ' \0 ' ;
}
2005-07-28 06:56:55 +00:00
2006-01-28 01:28:23 +00:00
//parse_conky_vars(output, p, cur);
2005-07-28 06:56:55 +00:00
}
2006-01-28 01:28:23 +00:00
OBJ ( execbar ) {
2005-08-23 03:00:50 +00:00
char * p2 = p ;
2006-01-28 01:28:23 +00:00
FILE * fp = popen ( obj - > data . s , " r " ) ;
2005-12-10 14:15:38 +00:00
int n2 = fread ( p , 1 , p_max_size , fp ) ;
2005-08-23 03:00:50 +00:00
( void ) pclose ( fp ) ;
2006-01-28 01:28:23 +00:00
2005-08-23 03:00:50 +00:00
p [ n2 ] = ' \0 ' ;
if ( n2 & & p [ n2 - 1 ] = = ' \n ' )
p [ n2 - 1 ] = ' \0 ' ;
while ( * p2 ) {
if ( * p2 = = ' \001 ' )
* p2 = ' ' ;
p2 + + ;
}
2006-01-28 01:28:23 +00:00
double barnum ;
if ( sscanf ( p , " %lf " , & barnum ) = = 0 ) {
ERR ( " reading execbar value failed (perhaps it's not the correct format?) " ) ;
2005-08-23 03:00:50 +00:00
}
if ( barnum > 100 | | barnum < 0 ) {
2006-01-28 01:28:23 +00:00
ERR ( " your execbar value is not between 0 and 100, therefore it will be ignored " ) ;
2005-08-23 03:00:50 +00:00
} else {
2006-01-28 01:28:23 +00:00
barnum = barnum / 100.0 ;
new_bar ( p , 0 , 4 , ( int ) ( barnum * 255.0 ) ) ;
2005-08-23 03:00:50 +00:00
}
2006-01-28 01:28:23 +00:00
2005-08-23 03:00:50 +00:00
}
2006-01-28 01:28:23 +00:00
OBJ ( execgraph ) {
2005-08-23 03:00:50 +00:00
char * p2 = p ;
2006-01-28 01:28:23 +00:00
FILE * fp = popen ( obj - > data . s , " r " ) ;
2005-12-10 14:15:38 +00:00
int n2 = fread ( p , 1 , p_max_size , fp ) ;
2005-08-23 03:00:50 +00:00
( void ) pclose ( fp ) ;
2006-01-28 01:28:23 +00:00
2005-08-23 03:00:50 +00:00
p [ n2 ] = ' \0 ' ;
if ( n2 & & p [ n2 - 1 ] = = ' \n ' )
p [ n2 - 1 ] = ' \0 ' ;
while ( * p2 ) {
if ( * p2 = = ' \001 ' )
* p2 = ' ' ;
p2 + + ;
}
2006-01-28 01:28:23 +00:00
double barnum ;
if ( sscanf ( p , " %lf " , & barnum ) = = 0 ) {
ERR ( " reading execgraph value failed (perhaps it's not the correct format?) " ) ;
2005-08-23 03:00:50 +00:00
}
if ( barnum > 100 | | barnum < 0 ) {
2006-01-28 01:28:23 +00:00
ERR ( " your execgraph value is not between 0 and 100, therefore it will be ignored " ) ;
2005-08-23 03:00:50 +00:00
} else {
2006-01-28 01:28:23 +00:00
new_graph ( p , 0 , 25 , obj - > c , obj - > d , ( int ) ( barnum ) , obj - > e , 1 ) ;
}
}
OBJ ( execibar ) {
if ( current_update_time - obj - > data . execi . last_update < obj - > data . execi . interval ) {
new_bar ( p , 0 , 4 , ( int ) obj - > f ) ;
} else {
char * p2 = p ;
FILE * fp = popen ( obj - > data . execi . cmd , " r " ) ;
int n2 = fread ( p , 1 , p_max_size , fp ) ;
( void ) pclose ( fp ) ;
p [ n2 ] = ' \0 ' ;
if ( n2 & & p [ n2 - 1 ] = = ' \n ' )
p [ n2 - 1 ] = ' \0 ' ;
while ( * p2 ) {
if ( * p2 = = ' \001 ' )
* p2 = ' ' ;
p2 + + ;
}
float barnum ;
if ( sscanf ( p , " %f " , & barnum ) = = 0 ) {
ERR ( " reading execibar value failed (perhaps it's not the correct format?) " ) ;
}
if ( barnum > 100 | | barnum < 0 ) {
ERR ( " your execibar value is not between 0 and 100, therefore it will be ignored " ) ;
} else {
obj - > f = 255 * barnum / 100.0 ;
new_bar ( p , 0 , 4 , ( int ) obj - > f ) ;
}
obj - > data . execi . last_update =
current_update_time ;
2005-08-23 03:00:50 +00:00
}
2005-07-28 06:56:55 +00:00
}
2006-01-28 01:28:23 +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 {
char * p2 = p ;
FILE * fp = popen ( obj - > data . execi . cmd , " r " ) ;
int n2 = fread ( p , 1 , p_max_size , fp ) ;
( void ) pclose ( fp ) ;
p [ n2 ] = ' \0 ' ;
if ( n2 & & p [ n2 - 1 ] = = ' \n ' )
p [ n2 - 1 ] = ' \0 ' ;
while ( * p2 ) {
if ( * p2 = = ' \001 ' )
* p2 = ' ' ;
p2 + + ;
}
float barnum ;
if ( sscanf ( p , " %f " , & barnum ) = = 0 ) {
ERR ( " reading execigraph value failed (perhaps it's not the correct format?) " ) ;
}
if ( barnum > 100 | | barnum < 0 ) {
ERR ( " your execigraph value is not between 0 and 100, therefore it will be ignored " ) ;
} else {
obj - > f = barnum ;
new_graph ( p , 0 , 25 , obj - > c , obj - > d , ( int ) ( obj - > f ) , 100 , 1 ) ;
}
obj - > data . execi . last_update = current_update_time ;
2005-07-28 06:56:55 +00:00
2005-07-20 00:30:40 +00:00
}
2006-01-28 01:28:23 +00:00
2005-07-20 00:30:40 +00:00
}
2006-01-28 01:28:23 +00:00
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 " ) ;
//int length = fread(output, 1, TEXT_BUFFER_SIZE, fp);
int length = fread ( output , 1 , TEXT_BUFFER_SIZE , fp ) ;
( void ) 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);
}
OBJ ( texeci ) {
2006-02-01 14:39:23 +00:00
if ( obj - > data . execi . pos < 0 ) {
obj - > data . execi . last_update = current_update_time ;
2006-02-13 02:28:46 +00:00
if ( pthread_create ( & ( obj - > data . execi . thread_info . thread ) , NULL , ( void * ) threaded_exec , ( void * ) obj ) ) {
ERR ( " Error starting thread " ) ;
2006-01-28 01:28:23 +00:00
}
2006-02-13 02:28:46 +00:00
obj - > data . execi . pos = register_thread ( & ( obj - > data . execi . thread_info ) ) ;
2005-08-29 17:06:31 +00:00
}
2006-05-14 04:49:55 +00:00
pthread_mutex_lock ( & ( obj - > data . execi . thread_info . mutex ) ) ;
2005-12-15 04:13:32 +00:00
snprintf ( p , p_max_size , " %s " , obj - > data . execi . buffer ) ;
2006-05-14 04:49:55 +00:00
pthread_mutex_unlock ( & ( obj - > data . execi . thread_info . mutex ) ) ;
2005-08-29 17:06:31 +00:00
}
2006-05-08 22:34:38 +00:00
# endif /* HAVE_POPEN */
OBJ ( imap_unseen ) {
2006-05-14 06:42:35 +00:00
if ( obj - > global_mode & & info . mail ) { // this means we use info
2006-05-08 22:34:38 +00:00
if ( info . mail - > pos < 0 ) {
info . mail - > last_update = current_update_time ;
if ( pthread_create ( & ( info . mail - > thread_info . thread ) , NULL , ( void * ) imap_thread , ( void * ) info . mail ) ) {
ERR ( " Error starting thread " ) ;
}
info . mail - > pos = register_thread ( & ( info . mail - > thread_info ) ) ;
}
2006-05-14 04:49:55 +00:00
// get a lock before reading
pthread_mutex_lock ( & ( info . mail - > thread_info . mutex ) ) ;
2006-05-13 19:51:26 +00:00
snprintf ( p , p_max_size , " %lu " , info . mail - > unseen ) ;
2006-05-14 04:49:55 +00:00
pthread_mutex_unlock ( & ( info . mail - > thread_info . mutex ) ) ;
2006-05-14 06:42:35 +00:00
} else if ( obj - > data . mail ) { // this means we use obj
2006-05-08 22:34:38 +00:00
if ( obj - > data . mail - > pos < 0 ) {
obj - > data . mail - > last_update = current_update_time ;
if ( pthread_create ( & ( obj - > data . mail - > thread_info . thread ) , NULL , ( void * ) imap_thread , ( void * ) obj - > data . mail ) ) {
ERR ( " Error starting thread " ) ;
}
obj - > data . mail - > pos = register_thread ( & ( obj - > data . mail - > thread_info ) ) ;
}
2006-05-14 06:42:35 +00:00
pthread_mutex_lock ( & ( obj - > data . mail - > thread_info . mutex ) ) ;
2006-05-13 19:51:26 +00:00
snprintf ( p , p_max_size , " %lu " , obj - > data . mail - > unseen ) ;
2006-05-14 06:42:35 +00:00
pthread_mutex_unlock ( & ( obj - > data . mail - > thread_info . mutex ) ) ;
2006-05-14 07:05:05 +00:00
} 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 + + ;
2006-05-08 22:34:38 +00:00
}
}
OBJ ( imap_messages ) {
2006-05-14 06:42:35 +00:00
if ( obj - > global_mode & & info . mail ) { // this means we use info
2006-05-08 22:34:38 +00:00
if ( info . mail - > pos < 0 ) {
info . mail - > last_update = current_update_time ;
if ( pthread_create ( & ( info . mail - > thread_info . thread ) , NULL , ( void * ) imap_thread , ( void * ) info . mail ) ) {
ERR ( " Error starting thread " ) ;
}
info . mail - > pos = register_thread ( & ( info . mail - > thread_info ) ) ;
}
2006-05-14 04:49:55 +00:00
pthread_mutex_lock ( & ( info . mail - > thread_info . mutex ) ) ;
2006-05-13 19:51:26 +00:00
snprintf ( p , p_max_size , " %lu " , info . mail - > messages ) ;
2006-05-14 04:49:55 +00:00
pthread_mutex_unlock ( & ( info . mail - > thread_info . mutex ) ) ;
2006-05-14 06:42:35 +00:00
} else if ( obj - > data . mail ) { // this means we use obj
2006-05-08 22:34:38 +00:00
if ( obj - > data . mail - > pos < 0 ) {
obj - > data . mail - > last_update = current_update_time ;
if ( pthread_create ( & ( obj - > data . mail - > thread_info . thread ) , NULL , ( void * ) imap_thread , ( void * ) obj - > data . mail ) ) {
ERR ( " Error starting thread " ) ;
}
obj - > data . mail - > pos = register_thread ( & ( obj - > data . mail - > thread_info ) ) ;
}
2006-05-14 06:42:35 +00:00
pthread_mutex_lock ( & ( obj - > data . mail - > thread_info . mutex ) ) ;
2006-05-13 19:51:26 +00:00
snprintf ( p , p_max_size , " %lu " , obj - > data . mail - > messages ) ;
2006-05-14 06:42:35 +00:00
pthread_mutex_unlock ( & ( obj - > data . mail - > thread_info . mutex ) ) ;
2006-05-14 07:05:05 +00:00
} 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 + + ;
2006-05-08 22:34:38 +00:00
}
}
OBJ ( pop3_unseen ) {
2006-05-14 06:42:35 +00:00
if ( obj - > global_mode & & info . mail ) { // this means we use info
2006-05-08 22:34:38 +00:00
if ( info . mail - > pos < 0 ) {
info . mail - > last_update = current_update_time ;
if ( pthread_create ( & ( info . mail - > thread_info . thread ) , NULL , ( void * ) pop3_thread , ( void * ) info . mail ) ) {
ERR ( " Error starting thread " ) ;
}
info . mail - > pos = register_thread ( & ( info . mail - > thread_info ) ) ;
}
2006-05-14 04:49:55 +00:00
pthread_mutex_lock ( & ( info . mail - > thread_info . mutex ) ) ;
2006-05-13 19:51:26 +00:00
snprintf ( p , p_max_size , " %lu " , info . mail - > unseen ) ;
2006-05-14 04:49:55 +00:00
pthread_mutex_unlock ( & ( info . mail - > thread_info . mutex ) ) ;
2006-05-14 06:42:35 +00:00
} else if ( obj - > data . mail ) { // this means we use obj
2006-05-08 22:34:38 +00:00
if ( obj - > data . mail - > pos < 0 ) {
obj - > data . mail - > last_update = current_update_time ;
if ( pthread_create ( & ( obj - > data . mail - > thread_info . thread ) , NULL , ( void * ) pop3_thread , ( void * ) obj - > data . mail ) ) {
ERR ( " Error starting thread " ) ;
}
obj - > data . mail - > pos = register_thread ( & ( obj - > data . mail - > thread_info ) ) ;
}
2006-05-14 06:42:35 +00:00
pthread_mutex_lock ( & ( obj - > data . mail - > thread_info . mutex ) ) ;
2006-05-13 19:51:26 +00:00
snprintf ( p , p_max_size , " %lu " , obj - > data . mail - > unseen ) ;
2006-05-14 06:42:35 +00:00
pthread_mutex_unlock ( & ( obj - > data . mail - > thread_info . mutex ) ) ;
2006-05-14 07:05:05 +00:00
} 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 + + ;
2006-05-08 22:34:38 +00:00
}
}
OBJ ( pop3_used ) {
2006-05-14 06:42:35 +00:00
if ( obj - > global_mode & & info . mail ) { // this means we use info
2006-05-08 22:34:38 +00:00
if ( info . mail - > pos < 0 ) {
info . mail - > last_update = current_update_time ;
if ( pthread_create ( & ( info . mail - > thread_info . thread ) , NULL , ( void * ) pop3_thread , ( void * ) info . mail ) ) {
ERR ( " Error starting thread " ) ;
}
info . mail - > pos = register_thread ( & ( info . mail - > thread_info ) ) ;
}
2006-05-14 04:49:55 +00:00
pthread_mutex_lock ( & ( info . mail - > thread_info . mutex ) ) ;
2006-05-08 22:34:38 +00:00
snprintf ( p , p_max_size , " %.1f " , info . mail - > used / 1024.0 / 1024.0 ) ;
2006-05-14 04:49:55 +00:00
pthread_mutex_unlock ( & ( info . mail - > thread_info . mutex ) ) ;
2006-05-14 06:42:35 +00:00
} else if ( obj - > data . mail ) { // this means we use obj
2006-05-08 22:34:38 +00:00
if ( obj - > data . mail - > pos < 0 ) {
obj - > data . mail - > last_update = current_update_time ;
if ( pthread_create ( & ( obj - > data . mail - > thread_info . thread ) , NULL , ( void * ) pop3_thread , ( void * ) obj - > data . mail ) ) {
ERR ( " Error starting thread " ) ;
}
obj - > data . mail - > pos = register_thread ( & ( obj - > data . mail - > thread_info ) ) ;
}
2006-05-14 06:42:35 +00:00
pthread_mutex_lock ( & ( obj - > data . mail - > thread_info . mutex ) ) ;
2006-05-08 22:34:38 +00:00
snprintf ( p , p_max_size , " %.1f " , obj - > data . mail - > used / 1024.0 / 1024.0 ) ;
2006-05-14 06:42:35 +00:00
pthread_mutex_unlock ( & ( obj - > data . mail - > thread_info . mutex ) ) ;
2006-05-14 07:05:05 +00:00
} 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
}
}
2005-07-20 00:30:40 +00:00
OBJ ( fs_bar ) {
if ( obj - > data . fs ! = NULL ) {
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 ) ) ;
}
}
OBJ ( fs_free ) {
if ( obj - > data . fs ! = NULL )
human_readable ( obj - > data . fs - > avail ,
p , 255 ) ;
}
OBJ ( fs_free_perc ) {
if ( obj - > data . fs ! = NULL ) {
if ( obj - > data . fs - > size )
2005-12-10 14:15:38 +00:00
snprintf ( p , p_max_size , " %*d " ,
2005-07-28 04:48:27 +00:00
pad_percents ,
( int ) ( ( obj - > data .
fs - >
avail *
100 ) /
obj - > data .
fs - > size ) ) ;
2005-07-20 00:30:40 +00:00
else
2005-12-10 14:15:38 +00:00
snprintf ( p , p_max_size , " 0 " ) ;
2005-07-28 04:48:27 +00:00
}
2005-07-20 00:30:40 +00:00
}
OBJ ( fs_size ) {
if ( obj - > data . fs ! = NULL )
human_readable ( obj - > data . fs - > size ,
p , 255 ) ;
}
OBJ ( fs_used ) {
if ( obj - > data . fs ! = NULL )
human_readable ( obj - > data . fs - > size -
2005-12-01 06:32:14 +00:00
( obj - > data . fs - > free ? obj - > data . fs - > free : obj - > data . fs - > avail ) ,
2005-07-20 00:30:40 +00:00
p , 255 ) ;
}
OBJ ( fs_bar_free ) {
if ( obj - > data . fs ! = NULL ) {
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 ) ) ;
}
}
OBJ ( fs_used_perc ) {
if ( obj - > data . fs ! = NULL ) {
if ( obj - > data . fs - > size )
snprintf ( p , 4 , " %d " ,
100 - ( ( int )
( ( obj - >
data . fs - >
avail *
100 ) /
obj - > data .
fs - >
size ) ) ) ;
else
2005-12-10 14:15:38 +00:00
snprintf ( p , p_max_size , " 0 " ) ;
2005-07-20 00:30:40 +00:00
}
}
OBJ ( loadavg ) {
float * v = info . loadavg ;
if ( obj - > data . loadavg [ 2 ] )
2005-12-10 14:15:38 +00:00
snprintf ( p , p_max_size , " %.2f %.2f %.2f " ,
2005-07-20 00:30:40 +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 " ,
2005-07-20 00:30:40 +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 " ,
2005-07-20 00:30:40 +00:00
v [ obj - > data . loadavg [ 0 ] -
1 ] ) ;
}
OBJ ( hr ) {
new_hr ( p , obj - > data . i ) ;
}
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 ) ;
}
OBJ ( i2c ) {
2005-07-20 00:30:40 +00:00
double r ;
r = get_i2c_info ( & obj - > data . i2c . fd ,
obj - > data . i2c . arg ,
obj - > data . i2c . devtype ,
obj - > data . i2c . type ) ;
if ( r > = 100.0 | | r = = 0 )
2005-12-10 14:15:38 +00:00
snprintf ( p , p_max_size , " %d " , ( int ) r ) ;
2005-07-20 00:30:40 +00:00
else
2005-12-10 14:15:38 +00:00
snprintf ( p , p_max_size , " %.1f " , r ) ;
2005-07-20 00:30:40 +00:00
}
OBJ ( alignr ) {
new_alignr ( p , obj - > data . i ) ;
}
OBJ ( alignc ) {
new_alignc ( p , obj - > data . i ) ;
}
2005-07-28 04:48:27 +00:00
OBJ ( if_existing ) {
struct stat tmp ;
if ( ( obj - > data . ifblock . s )
& & ( 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 {
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_mounted ) {
if ( ( obj - > data . ifblock . s )
2005-07-30 22:59:01 +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 ) {
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
}
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 ) {
human_readable ( cur - > mem * 1024 , p , 6 ) ;
}
OBJ ( memmax ) {
human_readable ( cur - > memmax * 1024 , p , 255 ) ;
}
OBJ ( memperc ) {
2005-07-28 04:48:27 +00:00
if ( cur - > memmax ) {
if ( ! use_spacer )
2005-12-10 14:15:38 +00:00
snprintf ( p , p_max_size , " %*lu " ,
2005-07-28 04:48:27 +00:00
pad_percents ,
( cur - > mem * 100 ) /
( cur - > memmax ) ) ;
2005-07-20 00:30:40 +00:00
else
2005-10-18 00:54:51 +00:00
snprintf ( p , 4 , " %*lu " ,
2005-07-28 04:48:27 +00:00
pad_percents ,
( cur - > mem * 100 ) /
( cur - > memmax ) ) ;
2005-07-20 00:30:40 +00:00
}
}
OBJ ( membar ) {
new_bar ( p , obj - > data . pair . a ,
obj - > data . pair . b ,
cur - > memmax ? ( cur - > mem * 255 ) /
( cur - > memmax ) : 0 ) ;
}
2005-07-28 06:56:55 +00:00
OBJ ( memgraph ) {
2005-08-10 17:35:26 +00:00
new_graph ( p , obj - > a ,
obj - > b , obj - > c , obj - > d ,
cur - > memmax ? ( cur - > mem * 100.0 ) /
2005-08-25 04:00:55 +00:00
( cur - > memmax ) : 0.0 , 100 , 1 ) ;
2005-07-28 06:56:55 +00:00
}
2005-07-20 00:30:40 +00:00
/* mixer stuff */
OBJ ( mixer ) {
2005-12-10 14:15:38 +00:00
snprintf ( p , p_max_size , " %d " ,
2005-07-20 00:30:40 +00:00
mixer_get_avg ( obj - > data . l ) ) ;
}
OBJ ( mixerl ) {
2005-12-10 14:15:38 +00:00
snprintf ( p , p_max_size , " %d " ,
2005-07-20 00:30:40 +00:00
mixer_get_left ( obj - > data . l ) ) ;
}
OBJ ( mixerr ) {
2005-12-10 14:15:38 +00:00
snprintf ( p , p_max_size , " %d " ,
2005-07-20 00:30:40 +00:00
mixer_get_right ( obj - > data . l ) ) ;
}
OBJ ( mixerbar ) {
new_bar ( p , obj - > data . mixerbar . w ,
obj - > data . mixerbar . h ,
mixer_get_avg ( obj - > data . mixerbar .
l ) * 255 / 100 ) ;
}
OBJ ( mixerlbar ) {
new_bar ( p , obj - > data . mixerbar . w ,
obj - > data . mixerbar . h ,
mixer_get_left ( obj - > data . mixerbar .
l ) * 255 / 100 ) ;
}
OBJ ( mixerrbar ) {
new_bar ( p , obj - > data . mixerbar . w ,
obj - > data . mixerbar . h ,
mixer_get_right ( obj - > data . mixerbar .
l ) * 255 / 100 ) ;
}
/* mail stuff */
OBJ ( mails ) {
2005-12-10 14:15:38 +00:00
snprintf ( p , p_max_size , " %d " , cur - > mail_count ) ;
2005-07-20 00:30:40 +00:00
}
OBJ ( new_mails ) {
2005-12-10 14:15:38 +00:00
snprintf ( p , p_max_size , " %d " , cur - > new_mail_count ) ;
2005-07-20 00:30:40 +00:00
}
# ifdef MLDONKEY
2005-07-28 04:48:27 +00:00
OBJ ( ml_upload_counter ) {
2005-12-10 14:15:38 +00:00
snprintf ( p , p_max_size , " %lld " ,
2005-07-28 04:48:27 +00:00
mlinfo . upload_counter / 1048576 ) ;
}
OBJ ( ml_download_counter ) {
2005-12-10 14:15:38 +00:00
snprintf ( p , p_max_size , " %lld " ,
2005-07-28 04:48:27 +00:00
mlinfo . download_counter /
1048576 ) ;
}
OBJ ( ml_nshared_files ) {
2005-12-10 14:15:38 +00:00
snprintf ( p , p_max_size , " %i " , mlinfo . nshared_files ) ;
2005-07-28 04:48:27 +00:00
}
OBJ ( ml_shared_counter ) {
2005-12-10 14:15:38 +00:00
snprintf ( p , p_max_size , " %lld " ,
2005-07-28 04:48:27 +00:00
mlinfo . shared_counter / 1048576 ) ;
}
OBJ ( ml_tcp_upload_rate ) {
2005-12-10 14:15:38 +00:00
snprintf ( p , p_max_size , " %.2f " ,
2005-07-28 04:48:27 +00:00
( float ) mlinfo . tcp_upload_rate /
1024 ) ;
}
OBJ ( ml_tcp_download_rate ) {
2005-12-10 14:15:38 +00:00
snprintf ( p , p_max_size , " %.2f " ,
2005-07-28 04:48:27 +00:00
( float ) mlinfo . tcp_download_rate /
1024 ) ;
}
OBJ ( ml_udp_upload_rate ) {
2005-12-10 14:15:38 +00:00
snprintf ( p , p_max_size , " %.2f " ,
2005-07-28 04:48:27 +00:00
( float ) mlinfo . udp_upload_rate /
1024 ) ;
}
OBJ ( ml_udp_download_rate ) {
2005-12-10 14:15:38 +00:00
snprintf ( p , p_max_size , " %.2f " ,
2005-07-28 04:48:27 +00:00
( float ) mlinfo . udp_download_rate /
1024 ) ;
}
OBJ ( ml_ndownloaded_files ) {
2005-12-10 14:15:38 +00:00
snprintf ( p , p_max_size , " %i " ,
2005-07-28 04:48:27 +00:00
mlinfo . ndownloaded_files ) ;
}
OBJ ( ml_ndownloading_files ) {
2005-12-10 14:15:38 +00:00
snprintf ( p , p_max_size , " %i " ,
2005-07-28 04:48:27 +00:00
mlinfo . ndownloading_files ) ;
}
# endif
2005-07-20 00:30:40 +00:00
OBJ ( nodename ) {
2005-12-10 14:15:38 +00:00
snprintf ( p , p_max_size , " %s " ,
2005-07-20 00:30:40 +00:00
cur - > uname_s . nodename ) ;
}
OBJ ( outlinecolor ) {
new_outline ( p , obj - > data . l ) ;
}
OBJ ( processes ) {
2005-07-28 04:48:27 +00:00
if ( ! use_spacer )
2005-12-10 14:15:38 +00:00
snprintf ( p , p_max_size , " %hu " , cur - > procs ) ;
2005-07-20 00:30:40 +00:00
else
2005-11-27 06:56:35 +00:00
snprintf ( p , 5 , " %hu " ,
2005-07-28 04:48:27 +00:00
cur - > procs ) ;
2005-07-20 00:30:40 +00:00
}
OBJ ( running_processes ) {
2005-07-28 04:48:27 +00:00
if ( ! use_spacer )
2005-12-10 14:15:38 +00:00
snprintf ( p , p_max_size , " %hu " ,
2005-07-28 04:48:27 +00:00
cur - > run_procs ) ;
2005-07-20 00:30:40 +00:00
else
2005-11-27 06:56:35 +00:00
snprintf ( p , 3 , " %hu " ,
2005-07-28 04:48:27 +00:00
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 ) {
new_stippled_hr ( p , obj - > data . pair . a ,
obj - > data . pair . b ) ;
}
OBJ ( swap ) {
human_readable ( cur - > swap * 1024 , p , 255 ) ;
}
OBJ ( swapmax ) {
2005-07-28 04:48:27 +00:00
human_readable ( cur - > swapmax * 1024 , p ,
255 ) ;
2005-07-20 00:30:40 +00:00
}
OBJ ( swapperc ) {
if ( cur - > swapmax = = 0 ) {
strncpy ( p , " No swap " , 255 ) ;
} else {
2005-07-28 04:48:27 +00:00
if ( ! use_spacer )
2005-10-18 00:54:51 +00:00
snprintf ( p , 255 , " %*lu " ,
2005-07-28 04:48:27 +00:00
pad_percents ,
( cur - > swap *
100 ) /
cur - > swapmax ) ;
2005-07-20 00:30:40 +00:00
else
2005-10-18 00:54:51 +00:00
snprintf ( p , 4 , " %*lu " ,
2005-07-28 04:48:27 +00:00
pad_percents ,
( cur - > swap *
100 ) /
cur - > swapmax ) ;
2005-07-20 00:30:40 +00:00
}
}
OBJ ( swapbar ) {
new_bar ( p , obj - > data . pair . a ,
obj - > data . pair . b ,
cur - > swapmax ? ( cur - > swap * 255 ) /
( cur - > swapmax ) : 0 ) ;
}
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 ) ;
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 ) ;
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 ( totaldown ) {
2005-07-28 04:48:27 +00:00
human_readable ( obj - > data . net - > recv , p ,
255 ) ;
2005-07-20 00:30:40 +00:00
}
OBJ ( totalup ) {
2005-07-28 04:48:27 +00:00
human_readable ( obj - > data . net - > trans , p ,
255 ) ;
2005-07-20 00:30:40 +00:00
}
OBJ ( updates ) {
2005-12-10 14:15:38 +00:00
snprintf ( p , p_max_size , " %d " , total_updates ) ;
2005-07-20 00:30:40 +00:00
}
OBJ ( upspeed ) {
2005-07-28 04:48:27 +00:00
if ( ! use_spacer )
2005-12-10 14:15:38 +00:00
snprintf ( p , p_max_size , " %d " ,
2005-07-28 04:48:27 +00:00
( int ) ( obj - > data . net - >
trans_speed /
1024 ) ) ;
2005-07-20 00:30:40 +00:00
else
snprintf ( p , 5 , " %d " ,
2005-07-28 04:48:27 +00:00
( int ) ( obj - > data . net - >
trans_speed /
1024 ) ) ;
2005-07-20 00:30:40 +00:00
}
OBJ ( upspeedf ) {
2005-07-28 04:48:27 +00:00
if ( ! use_spacer )
2005-12-10 14:15:38 +00:00
snprintf ( p , p_max_size , " %.1f " ,
2005-07-28 04:48:27 +00:00
obj - > data . net - >
trans_speed / 1024.0 ) ;
2005-07-20 00:30:40 +00:00
else
snprintf ( p , 8 , " %.1f " ,
2005-07-28 04:48:27 +00:00
obj - > data . net - >
trans_speed / 1024.0 ) ;
2005-07-20 00:30:40 +00:00
}
2005-07-28 06:56:55 +00:00
OBJ ( upspeedgraph ) {
2005-07-30 22:59:01 +00:00
if ( obj - > data . net - > trans_speed = = 0 ) // this is just to make the ugliness at start go away
2005-07-30 12:02:48 +00:00
obj - > data . net - > trans_speed = 0.01 ;
2005-08-01 09:15:02 +00:00
new_graph ( p , obj - > a , obj - > b , obj - > c , obj - > d ,
2005-07-30 22:59:01 +00:00
( obj - > data . net - > trans_speed /
2005-08-25 04:00:55 +00:00
1024.0 ) , obj - > e , 1 ) ;
2005-07-30 11:23:26 +00:00
}
2005-07-20 00:30:40 +00:00
OBJ ( uptime_short ) {
2005-12-10 14:15:38 +00:00
format_seconds_short ( p , p_max_size ,
2005-07-20 00:30:40 +00:00
( int ) cur - > uptime ) ;
}
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
}
2005-09-29 03:22:31 +00:00
# if defined(__FreeBSD__) && (defined(i386) || defined(__i386__))
2005-08-30 04:19:16 +00:00
OBJ ( apm_adapter ) {
2005-12-10 14:15:38 +00:00
snprintf ( p , p_max_size , " %s " , get_apm_adapter ( ) ) ;
2005-08-30 04:19:16 +00:00
}
OBJ ( apm_battery_life ) {
char * msg ;
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 ) {
char * msg ;
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 ) ;
}
# endif /* __FreeBSD__ */
2005-07-20 00:30:40 +00:00
# ifdef SETI
OBJ ( seti_prog ) {
2005-12-10 14:15:38 +00:00
snprintf ( p , p_max_size , " %.2f " ,
2005-07-20 00:30:40 +00:00
cur - > seti_prog * 100.0f ) ;
}
OBJ ( seti_progbar ) {
new_bar ( p , obj - > data . pair . a ,
obj - > data . pair . b ,
( int ) ( cur - > seti_prog * 255.0f ) ) ;
}
OBJ ( seti_credit ) {
2005-12-10 14:15:38 +00:00
snprintf ( p , p_max_size , " %.0f " , cur - > seti_credit ) ;
2005-07-20 00:30:40 +00:00
}
# endif
# ifdef MPD
OBJ ( mpd_title ) {
2005-12-10 14:15:38 +00:00
snprintf ( p , 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 ) {
2005-07-30 22:59:01 +00:00
int days = 0 , hours = 0 , minutes =
0 , seconds = 0 ;
2005-07-28 04:48:27 +00:00
int tmp = cur - > mpd . elapsed ;
while ( tmp > = 86400 ) {
tmp - = 86400 ;
days + + ;
}
while ( tmp > = 3600 ) {
tmp - = 3600 ;
hours + + ;
}
while ( tmp > = 60 ) {
tmp - = 60 ;
minutes + + ;
}
seconds = tmp ;
if ( days > 0 )
2005-12-10 14:15:38 +00:00
snprintf ( p , p_max_size , " %i days %i:%02i:%02i " ,
2005-07-30 22:59:01 +00:00
days , hours , minutes ,
seconds ) ;
2005-09-04 03:43:18 +00:00
else if ( hours > 0 )
2005-12-10 14:15:38 +00:00
snprintf ( p , p_max_size , " %i:%02i:%02i " , hours ,
2005-07-30 22:59:01 +00:00
minutes , seconds ) ;
2005-07-28 04:48:27 +00:00
else
2005-12-10 14:15:38 +00:00
snprintf ( p , p_max_size , " %i:%02i " , minutes ,
2005-07-30 22:59:01 +00:00
seconds ) ;
2005-07-28 04:48:27 +00:00
}
OBJ ( mpd_length ) {
2005-07-30 22:59:01 +00:00
int days = 0 , hours = 0 , minutes =
0 , seconds = 0 ;
2005-07-28 04:48:27 +00:00
int tmp = cur - > mpd . length ;
while ( tmp > = 86400 ) {
tmp - = 86400 ;
days + + ;
}
while ( tmp > = 3600 ) {
tmp - = 3600 ;
hours + + ;
}
while ( tmp > = 60 ) {
tmp - = 60 ;
minutes + + ;
}
seconds = tmp ;
if ( days > 0 )
2005-12-10 14:15:38 +00:00
snprintf ( p , p_max_size ,
2005-09-04 03:43:18 +00:00
" %i days %i:%02i:%02i " ,
2005-07-30 22:59:01 +00:00
days , hours , minutes ,
seconds ) ;
2005-09-04 03:43:18 +00:00
else if ( hours > 0 )
2005-12-10 14:15:38 +00:00
snprintf ( p , p_max_size , " %i:%02i:%02i " , hours ,
2005-07-30 22:59:01 +00:00
minutes , seconds ) ;
2005-07-28 04:48:27 +00:00
else
2005-12-10 14:15:38 +00:00
snprintf ( p , p_max_size , " %i:%02i " , minutes ,
2005-07-30 22:59:01 +00:00
seconds ) ;
2005-07-28 04:48:27 +00:00
}
OBJ ( mpd_percent ) {
2005-12-10 14:15:38 +00:00
snprintf ( p , p_max_size , " %2.0f " ,
2005-07-30 22:59:01 +00:00
cur - > mpd . progress * 100 ) ;
2005-07-28 04:48:27 +00:00
}
2005-07-20 00:30:40 +00:00
OBJ ( mpd_bar ) {
new_bar ( p , obj - > data . pair . a ,
obj - > data . pair . b ,
2005-07-28 04:48:27 +00:00
( 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 ) {
if ( strlen ( cur - > mpd . title ) < 2 & & strlen ( cur - > mpd . title ) < 2 ) {
snprintf ( p , p_max_size , " %s " , cur - > mpd . file ) ;
} else {
snprintf ( p , p_max_size , " %s - %s " , cur - > mpd . artist , cur - > mpd . title ) ;
}
}
2005-12-30 09:44:40 +00:00
# endif
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_decoder ) {
snprintf ( p , p_max_size , " %s " , cur - > xmms2 . decoder ) ;
2006-03-25 21:21:07 +00:00
}
2006-04-16 03:49:49 +00:00
OBJ ( xmms2_transport ) {
snprintf ( p , p_max_size , " %s " , cur - > xmms2 . transport ) ;
2006-03-25 21:21:07 +00:00
}
2006-04-16 03:49:49 +00:00
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 ) ;
}
2006-04-16 03:49:49 +00:00
OBJ ( xmms2_date ) {
snprintf ( p , p_max_size , " %s " , cur - > xmms2 . date ) ;
}
OBJ ( xmms2_tracknr ) {
if ( cur - > xmms2 . tracknr ! = - 1 )
snprintf ( p , p_max_size , " %i " , cur - > xmms2 . tracknr ) ;
}
OBJ ( xmms2_bitrate ) {
snprintf ( p , p_max_size , " %i " , cur - > xmms2 . bitrate ) ;
}
OBJ ( xmms2_id ) {
snprintf ( p , p_max_size , " %u " , cur - > xmms2 . id ) ;
}
OBJ ( xmms2_size ) {
snprintf ( p , p_max_size , " %2.1f " , cur - > xmms2 . size ) ;
}
2006-03-25 21:21:07 +00:00
OBJ ( xmms2_elapsed ) {
int tmp = cur - > xmms2 . elapsed ;
2006-04-16 03:49:49 +00:00
snprintf ( p , p_max_size , " %02d:%02d " ,
2006-03-25 21:21:07 +00:00
tmp / 60000 , ( tmp / 1000 ) % 60 ) ;
}
2006-04-16 03:49:49 +00:00
OBJ ( xmms2_duration ) {
int tmp = cur - > xmms2 . duration ;
snprintf ( p , p_max_size , " %02d:%02d " ,
2006-03-25 21:21:07 +00:00
tmp / 60000 , ( tmp / 1000 ) % 60 ) ;
}
OBJ ( xmms2_percent ) {
snprintf ( p , p_max_size , " %2.0f " ,
cur - > xmms2 . progress * 100 ) ;
}
OBJ ( xmms2_bar ) {
new_bar ( p , obj - > data . pair . a ,
obj - > data . pair . b ,
( int ) ( cur - > xmms2 . progress *
255.0f ) ) ;
}
2006-04-16 03:49:49 +00:00
OBJ ( xmms2_smart ) {
if ( strlen ( cur - > xmms2 . title ) < 2 & & strlen ( cur - > xmms2 . title ) < 2 ) {
snprintf ( p , p_max_size , " %s " , cur - > xmms2 . url ) ;
} else {
snprintf ( p , p_max_size , " %s - %s " , cur - > xmms2 . artist , cur - > xmms2 . title ) ;
}
}
2006-03-25 21:21:07 +00:00
# endif
2006-01-08 14:51:47 +00:00
# if defined(XMMS) || defined(BMP) || defined(AUDACIOUS) || defined(INFOPIPE)
2006-01-08 08:02:37 +00:00
OBJ ( xmms_status ) {
snprintf ( p , p_max_size , " %s " , cur - > xmms . items [ XMMS_STATUS ] ) ;
}
OBJ ( xmms_title ) {
snprintf ( p , p_max_size , " %s " , cur - > xmms . items [ XMMS_TITLE ] ) ;
2006-01-07 07:01:22 +00:00
}
2006-01-08 08:02:37 +00:00
OBJ ( xmms_length ) {
snprintf ( p , p_max_size , " %s " , cur - > xmms . items [ XMMS_LENGTH ] ) ;
2006-01-07 07:01:22 +00:00
}
2006-01-08 08:02:37 +00:00
OBJ ( xmms_length_seconds ) {
snprintf ( p , p_max_size , " %s " , cur - > xmms . items [ XMMS_LENGTH_SECONDS ] ) ;
2006-01-07 07:01:22 +00:00
}
2006-01-08 08:02:37 +00:00
OBJ ( xmms_position ) {
snprintf ( p , p_max_size , " %s " , cur - > xmms . items [ XMMS_POSITION ] ) ;
2006-01-07 07:01:22 +00:00
}
2006-01-08 08:02:37 +00:00
OBJ ( xmms_position_seconds ) {
snprintf ( p , p_max_size , " %s " , cur - > xmms . items [ XMMS_POSITION_SECONDS ] ) ;
2006-01-07 07:01:22 +00:00
}
2006-01-08 08:02:37 +00:00
OBJ ( xmms_bitrate ) {
snprintf ( p , p_max_size , " %s " , cur - > xmms . items [ XMMS_BITRATE ] ) ;
2006-01-07 07:01:22 +00:00
}
2006-01-08 08:02:37 +00:00
OBJ ( xmms_frequency ) {
snprintf ( p , p_max_size , " %s " , cur - > xmms . items [ XMMS_FREQUENCY ] ) ;
2006-01-07 07:01:22 +00:00
}
2006-01-08 08:02:37 +00:00
OBJ ( xmms_channels ) {
snprintf ( p , p_max_size , " %s " , cur - > xmms . items [ XMMS_CHANNELS ] ) ;
2006-01-07 07:01:22 +00:00
}
2006-01-08 08:02:37 +00:00
OBJ ( xmms_filename ) {
snprintf ( p , p_max_size , " %s " , cur - > xmms . items [ XMMS_FILENAME ] ) ;
2006-01-07 07:01:22 +00:00
}
2006-01-08 08:02:37 +00:00
OBJ ( xmms_playlist_length ) {
snprintf ( p , p_max_size , " %s " , cur - > xmms . items [ XMMS_PLAYLIST_LENGTH ] ) ;
2006-01-07 07:01:22 +00:00
}
2006-01-08 08:02:37 +00:00
OBJ ( xmms_playlist_position ) {
snprintf ( p , p_max_size , " %s " , cur - > xmms . items [ XMMS_PLAYLIST_POSITION ] ) ;
}
OBJ ( xmms_bar ) {
2006-01-07 07:01:22 +00:00
double progress ;
2006-01-08 08:02:37 +00:00
progress = atof ( cur - > xmms . items [ XMMS_POSITION_SECONDS ] ) /
atof ( cur - > xmms . items [ XMMS_LENGTH_SECONDS ] ) ;
2006-01-07 07:01:22 +00:00
new_bar ( p , obj - > a , obj - > b , ( int ) ( progress * 255.0f ) ) ;
}
# endif
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 ) {
snprintf ( p , p_max_size , " %i " , cur - > bmpx . track ) ;
}
OBJ ( bmpx_bitrate ) {
snprintf ( p , p_max_size , " %i " , cur - > bmpx . bitrate ) ;
}
2005-07-20 00:30:40 +00:00
# endif
OBJ ( top ) {
2005-07-28 04:48:27 +00:00
if ( obj - > data . top . type = = TOP_NAME
& & obj - > data . top . num > = 0
& & obj - > data . top . num < 10 ) {
2005-07-20 00:30:40 +00:00
// if we limit the buffer and add a bunch of space after, it stops the thing from
// moving other shit around, which is really fucking annoying
2005-08-25 01:13:01 +00:00
snprintf ( p , 17 , " %s " , cur - > cpu [ obj - > data . top . num ] - > name ) ;
2005-07-28 04:48:27 +00:00
} else if ( obj - > data . top . type = = TOP_CPU
& & obj - > data . top . num > = 0
& & obj - > data . top . num < 10 ) {
snprintf ( p , 7 , " %3.2f " ,
cur - > cpu [ obj - > data . top .
num ] - > amount ) ;
} else if ( obj - > data . top . type = = TOP_PID
& & obj - > data . top . num > = 0
& & obj - > data . top . num < 10 ) {
snprintf ( p , 8 , " %i " ,
cur - > cpu [ obj - > data . top .
num ] - > pid ) ;
} else if ( obj - > data . top . type = = TOP_MEM
& & obj - > data . top . num > = 0
& & obj - > data . top . num < 10 ) {
snprintf ( p , 7 , " %3.2f " ,
cur - > cpu [ obj - > data . top .
num ] - > totalmem ) ;
}
2005-07-20 00:30:40 +00:00
}
2005-07-25 00:22:16 +00:00
OBJ ( top_mem ) {
2005-07-28 04:48:27 +00:00
if ( obj - > data . top . type = = TOP_NAME
& & obj - > data . top . num > = 0
& & obj - > data . top . num < 10 ) {
2005-07-25 00:22:16 +00:00
// if we limit the buffer and add a bunch of space after, it stops the thing from
// moving other shit around, which is really fucking annoying
2005-07-28 04:48:27 +00:00
snprintf ( p , 17 ,
" %s " ,
cur - > memu [ obj - > data . top .
num ] - > name ) ;
} else if ( obj - > data . top . type = = TOP_CPU
& & obj - > data . top . num > = 0
& & obj - > data . top . num < 10 ) {
snprintf ( p , 7 , " %3.2f " ,
cur - > memu [ obj - > data . top .
num ] - > amount ) ;
} else if ( obj - > data . top . type = = TOP_PID
& & obj - > data . top . num > = 0
& & obj - > data . top . num < 10 ) {
snprintf ( p , 8 , " %i " ,
cur - > memu [ obj - > data . top .
num ] - > pid ) ;
} else if ( obj - > data . top . type = = TOP_MEM
& & obj - > data . top . num > = 0
& & obj - > data . top . num < 10 ) {
snprintf ( p , 7 , " %3.2f " ,
cur - > memu [ obj - > data . top .
num ] - > totalmem ) ;
2005-07-25 00:22:16 +00:00
}
}
2005-07-28 04:48:27 +00:00
2005-07-20 00:30:40 +00:00
OBJ ( tail ) {
2006-01-06 05:11:28 +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 ) ;
} else {
2005-08-01 02:52:17 +00:00
obj - > data . tail . last_update = current_update_time ;
2005-07-28 04:48:27 +00:00
FILE * fp ;
int i ;
2005-08-21 08:23:04 +00:00
int added = 0 ;
2005-07-28 04:48:27 +00:00
tailstring * head = NULL ;
2005-08-01 02:52:17 +00:00
tailstring * headtmp = NULL ;
2005-08-26 05:52:43 +00:00
tailstring * freetmp = NULL ;
2005-08-01 02:52:17 +00:00
fp = fopen ( obj - > data . tail . logfile , " rt " ) ;
2005-08-10 05:52:52 +00:00
if ( fp = = NULL ) {
2005-07-28 04:48:27 +00:00
ERR ( " tail logfile failed to open " ) ;
2005-08-10 05:52:52 +00:00
}
2005-07-28 04:48:27 +00:00
else {
2005-08-01 02:52:17 +00:00
obj - > data . tail . readlines = 0 ;
2005-09-05 02:09:31 +00:00
while ( fgets ( obj - > data . tail . buffer , TEXT_BUFFER_SIZE * 20 , fp ) ! = NULL ) {
2005-08-21 08:23:04 +00:00
if ( added > = 30 ) {
freelasttail ( head ) ;
}
else {
added + + ;
}
2005-08-01 02:52:17 +00:00
addtail ( & head , obj - > data . tail . buffer ) ;
obj - > data . tail . readlines + + ;
2005-07-20 00:30:40 +00:00
}
2005-07-28 04:48:27 +00:00
fclose ( fp ) ;
2005-08-26 05:52:43 +00:00
freetmp = head ;
2005-07-28 04:48:27 +00:00
2005-08-01 02:52:17 +00:00
if ( obj - > data . tail . readlines > 0 ) {
for ( i = 0 ; i < obj - > data . tail . wantedlines + 1 & & i < obj - > data . tail . readlines ; i + + ) {
addtail ( & headtmp , head - > data ) ;
head = head - > next ;
2005-07-20 00:30:40 +00:00
}
2005-08-26 05:52:43 +00:00
freetail ( freetmp ) ;
freetmp = headtmp ;
2005-08-01 02:52:17 +00:00
strcpy ( obj - > data . tail . buffer , headtmp - > data ) ;
headtmp = headtmp - > next ;
for ( i = 1 ; i < obj - > data . tail . wantedlines + 1 & & i < obj - > data . tail . readlines ; i + + ) {
if ( headtmp ) {
2005-09-05 02:09:31 +00:00
strncat ( obj - > data . tail . buffer , headtmp - > data , ( TEXT_BUFFER_SIZE * 20 ) - strlen ( obj - > data . tail . buffer ) ) ; /* without strlen() at the end this becomes a possible */
2005-08-01 02:52:17 +00:00
headtmp = headtmp - > next ;
2005-07-28 04:48:27 +00:00
}
}
2005-08-01 02:52:17 +00:00
/* get rid of any ugly newlines at the end */
if ( obj - > data . tail . buffer [ strlen ( obj - > data . tail . buffer ) - 1 ] = = ' \n ' ) {
obj - > data . tail . buffer [ strlen ( obj - > data . tail . buffer ) - 1 ] = ' \0 ' ;
}
2006-01-06 05:11:28 +00:00
snprintf ( p , p_max_size , " %s " , obj - > data . tail . buffer ) ;
2005-07-28 04:48:27 +00:00
2005-08-26 05:52:43 +00:00
freetail ( freetmp ) ;
2005-12-10 21:07:24 +00:00
} 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 " ) ;
2005-12-10 21:07:24 +00:00
} /* if readlines */
} /* fp == NULL */
} /* if cur_upd_time >= */
2005-12-15 04:13:32 +00:00
//parse_conky_vars(obj->data.tail.buffer, p, cur);
2005-12-10 21:07:24 +00:00
2005-08-26 05:52:43 +00:00
}
OBJ ( head ) {
2006-01-06 05:11:28 +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 ) ;
} else {
2005-08-26 05:52:43 +00:00
obj - > data . tail . last_update = current_update_time ;
FILE * fp ;
tailstring * head = NULL ;
tailstring * headtmp = NULL ;
tailstring * freetmp = NULL ;
fp = fopen ( obj - > data . tail . logfile , " rt " ) ;
if ( fp = = NULL ) {
ERR ( " head logfile failed to open " ) ;
2005-12-10 21:07:24 +00:00
} else {
2005-08-26 05:52:43 +00:00
obj - > data . tail . readlines = 0 ;
2005-09-05 02:09:31 +00:00
while ( fgets ( obj - > data . tail . buffer , TEXT_BUFFER_SIZE * 20 , fp ) ! = NULL & & obj - > data . tail . readlines < = obj - > data . tail . wantedlines ) {
2005-08-26 05:52:43 +00:00
addtail ( & head , obj - > data . tail . buffer ) ;
obj - > data . tail . readlines + + ;
}
fclose ( fp ) ;
freetmp = head ;
if ( obj - > data . tail . readlines > 0 ) {
while ( head ) {
addtail ( & headtmp , head - > data ) ;
head = head - > next ;
}
freetail ( freetmp ) ;
freetmp = headtmp ;
strcpy ( obj - > data . tail . buffer , headtmp - > data ) ;
headtmp = headtmp - > next ;
while ( headtmp ) {
2005-09-05 02:09:31 +00:00
strncat ( obj - > data . tail . buffer , headtmp - > data , ( TEXT_BUFFER_SIZE * 20 ) - strlen ( obj - > data . tail . buffer ) ) ; /* without strlen() at the end this becomes a possible */
2005-08-26 05:52:43 +00:00
headtmp = headtmp - > next ;
}
freetail ( freetmp ) ;
/* get rid of any ugly newlines at the end */
if ( obj - > data . tail . buffer [ strlen ( obj - > data . tail . buffer ) - 1 ] = = ' \n ' ) {
obj - > data . tail . buffer [ strlen ( obj - > data . tail . buffer ) - 1 ] = ' \0 ' ;
}
2006-01-06 05:11:28 +00:00
snprintf ( p , p_max_size , " %s " , obj - > data . tail . buffer ) ;
2005-12-10 21:07:24 +00:00
} 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 " ) ;
2005-12-10 21:07:24 +00:00
} /* if readlines > 0 */
} /* if fp == null */
} /* cur_upd_time >= */
2005-12-15 04:13:32 +00:00
//parse_conky_vars(obj->data.tail.buffer, p, cur);
2005-12-10 21:07:24 +00:00
2005-07-20 00:30:40 +00:00
}
2005-10-31 05:17:06 +00:00
# ifdef TCP_PORT_MONITOR
OBJ ( tcp_portmon )
{
/* grab a pointer to this port monitor */
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 */
if ( peek_tcp_port_monitor ( p_monitor ,
obj - > data . tcp_port_monitor . item ,
obj - > data . tcp_port_monitor . connection_index ,
2005-12-10 14:15:38 +00:00
p , p_max_size ) ! = 0 )
2005-10-31 05:17:06 +00:00
{
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
2006-05-13 19:51:26 +00:00
OBJ ( iconv_start )
{
iconv_converting = 1 ;
iconv_selected = obj - > a ;
}
OBJ ( iconv_stop )
{
iconv_converting = 0 ;
iconv_selected = 0 ;
}
# endif
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
2006-05-13 19:51:26 +00:00
if ( a > 0 & & iconv_converting & & iconv_selected > 0 & & ( iconv_cd [ iconv_selected - 1 ] ! = ( iconv_t ) ( - 1 ) ) ) {
int bytes ;
size_t dummy1 , dummy2 ;
char * ptr = buff_in ;
char * outptr = p ;
dummy1 = dummy2 = a ;
strncpy ( buff_in , p , P_MAX_SIZE ) ;
iconv ( * iconv_cd [ iconv_selected - 1 ] , NULL , NULL , NULL , NULL ) ;
while ( dummy1 > 0 ) {
bytes = iconv ( * iconv_cd [ iconv_selected - 1 ] , & ptr , & dummy1 , & outptr , & dummy2 ) ;
if ( bytes = = - 1 ) {
ERR ( " Iconv codeset conversion failed " ) ;
break ;
}
}
/* It is nessecary when we are converting from multibyte to singlebyte codepage */
a = outptr - p ;
}
# endif
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 ;
static void generate_text ( )
{
struct information * cur = & info ;
char * p ;
2006-05-13 19:51:26 +00:00
2005-12-10 14:15:38 +00:00
special_count = 0 ;
/* update info */
current_update_time = get_time ( ) ;
update_stuff ( cur ) ;
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 ;
2005-12-10 21:07:24 +00:00
generate_text_internal ( p , P_MAX_SIZE , text_objects , text_object_count , cur ) ;
2005-07-20 00:30:40 +00:00
if ( stuff_in_upper_case ) {
char * p ;
p = text_buffer ;
while ( * p ) {
* p = toupper ( * p ) ;
p + + ;
}
}
2006-05-13 19:51:26 +00:00
2005-07-20 00:30:40 +00:00
last_update_time = current_update_time ;
total_updates + + ;
//free(p);
}
2005-12-10 14:15:38 +00:00
2005-08-08 01:18:52 +00:00
# ifdef X11
2005-08-03 07:01:32 +00:00
static void set_font ( )
{
# ifdef XFT
if ( use_xft ) {
2005-08-29 17:06:31 +00:00
if ( window . xftdraw ! = NULL ) {
2005-08-03 07:01:32 +00:00
XftDrawDestroy ( window . xftdraw ) ;
2005-08-29 17:06:31 +00:00
}
2005-08-03 07:01:32 +00:00
window . xftdraw = XftDrawCreate ( display , window . drawable ,
DefaultVisual ( display ,
screen ) ,
DefaultColormap ( display ,
screen ) ) ;
} else
# endif
{
XSetFont ( display , window . gc , fonts [ selected_font ] . font - > fid ) ;
}
}
2005-07-20 00:30:40 +00:00
/*
* text size
*/
static int text_start_x , text_start_y ; /* text start position in window */
static int text_width , text_height ;
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 )
{
if ( ! s ) {
return 0 ;
}
# ifdef X11
char * p , * final ;
p = strdup ( s ) ;
final = p ;
int index = 1 ;
int width = 0 ;
unsigned int i ;
while ( * p ) {
if ( * p = = SPECIAL_CHAR ) {
2005-08-27 07:58:29 +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 ) ;
}
if ( specials [ special_index + index ] . type = = GRAPH | | specials [ special_index + index ] . type = = BAR ) {
width + = specials [ special_index + index ] . width ;
}
index + + ;
} 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
return strlen ( s ) ;
# endif /* X11 */
}
2005-08-03 07:01:32 +00:00
int fontchange = 0 ;
2005-08-02 05:06:53 +00:00
2005-08-11 05:21:56 +00:00
# ifdef X11
2005-07-20 00:30:40 +00:00
static void text_size_updater ( char * s )
{
int w = 0 ;
char * p ;
2005-07-29 02:52:08 +00:00
int h = font_height ( ) ;
2005-07-20 00:30:40 +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 ;
2005-07-30 22:59:01 +00:00
if ( specials [ special_index ] . type = = BAR
| | specials [ special_index ] . type = = GRAPH ) {
2005-07-20 00:30:40 +00:00
w + = specials [ special_index ] . width ;
2005-07-30 22:59:01 +00:00
if ( specials [ special_index ] . height > h ) {
2005-07-29 02:52:08 +00:00
h = specials [ special_index ] . height ;
2005-07-30 12:45:06 +00:00
h + = font_ascent ( ) ;
2005-07-29 02:52:08 +00:00
}
2005-07-20 00:30:40 +00:00
}
2005-07-31 19:49:39 +00:00
2005-08-02 05:06:53 +00:00
else if ( specials [ special_index ] . type = = OFFSET ) {
2005-07-31 20:05:19 +00:00
w + = specials [ special_index ] . arg + get_string_width ( " a " ) ; /* filthy, but works */
}
2005-08-21 05:04:22 +00:00
else if ( specials [ special_index ] . type = = VOFFSET ) {
h + = specials [ special_index ] . arg ;
}
2005-08-02 05:06:53 +00:00
else if ( specials [ special_index ] . type = = FONT ) {
2005-08-03 07:01:32 +00:00
fontchange = specials [ special_index ] . font_added ;
selected_font = specials [ special_index ] . font_added ;
2005-08-02 05:06:53 +00:00
h = font_height ( ) ;
}
2005-07-20 00:30:40 +00:00
special_index + + ;
s = p + 1 ;
}
p + + ;
}
2005-08-03 07:01:32 +00:00
w + = get_string_width ( s ) ;
2005-07-20 00:30:40 +00:00
if ( w > text_width )
text_width = w ;
2005-08-24 06:21:50 +00:00
if ( text_width > maximum_width & & maximum_width )
text_width = maximum_width ;
2005-07-20 00:30:40 +00:00
2005-07-29 02:52:08 +00:00
text_height + = h ;
2006-05-09 23:08:23 +00:00
/* if (fontchange) {
2005-08-04 02:17:25 +00:00
selected_font = 0 ;
2006-05-09 23:08:23 +00:00
} */
2005-07-20 00:30:40 +00:00
}
2005-08-11 05:21:56 +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
static void update_text_area ( )
{
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 ;
for_each_line ( text_buffer , text_size_updater ) ;
text_width + = 1 ;
if ( text_height < minimum_height )
text_height = minimum_height ;
2005-08-24 06:21:50 +00:00
if ( text_width > maximum_width & & maximum_width > 0 )
text_width = maximum_width ;
2005-07-20 00:30:40 +00:00
}
/* get text position on workarea */
switch ( text_alignment ) {
case TOP_LEFT :
x = gap_x ;
y = gap_y ;
break ;
case TOP_RIGHT :
x = workarea [ 2 ] - text_width - gap_x ;
y = gap_y ;
break ;
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 ;
2005-08-20 19:43:06 +00:00
2005-08-21 17:32:43 +00:00
# ifdef OWN_WINDOW
2005-08-20 19:43:06 +00:00
case NONE : // Let the WM manage the window
x = window . x ;
y = window . y ;
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
{
/* If window size doesn't match to workarea's size, then window
* probably includes panels ( gnome ) .
* Blah , doesn ' t work on KDE . */
if ( workarea [ 2 ] ! = window . width
| | workarea [ 3 ] ! = window . height ) {
y + = workarea [ 1 ] ;
x + = workarea [ 0 ] ;
}
text_start_x = x ;
text_start_y = y ;
}
}
/*
* drawing stuff
*/
static int cur_x , cur_y ; /* current x and y for drawing */
static int draw_mode ; /* FG, BG or OUTLINE */
static long current_color ;
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 )
{
if ( s [ 0 ] = = ' \0 ' )
return ;
int i , i2 , pos , width_of_s ;
2005-08-11 05:21:56 +00:00
int max = 0 ;
int added ;
2005-07-20 00:30:40 +00:00
width_of_s = get_string_width ( s ) ;
2005-07-28 04:48:27 +00:00
if ( out_to_console ) {
2005-07-20 00:30:40 +00:00
printf ( " %s \n " , s ) ;
2005-12-16 00:08:42 +00:00
fflush ( stdout ) ; /* output immediately, don't buffer */
2005-07-20 00:30:40 +00:00
}
2005-08-15 00:35:51 +00:00
/* daemon_run(s); the daemon can be called here, but we need to have a buffer in daemon_run() and we need to tell it when everything is ready to be sent */
2005-11-29 17:35:21 +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 ;
char space [ 2 ] ;
snprintf ( space , 2 , " " ) ;
2005-08-08 01:18:52 +00:00
# ifdef X11
2005-07-28 04:48:27 +00:00
max = ( ( text_width - width_of_s ) / get_string_width ( space ) ) ;
2005-08-08 01:18:52 +00:00
# endif /* X11 */
2005-07-20 00:30:40 +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 .
*/
2005-07-28 04:48:27 +00:00
for ( i = 0 ; i < TEXT_BUFFER_SIZE ; i + + ) {
if ( tmpstring1 [ i ] = = ' \t ' ) // 9 is ascii tab
2005-07-20 00:30:40 +00:00
{
2005-07-28 04:48:27 +00:00
i2 = 0 ;
for ( i2 = 0 ;
i2 < ( 8 - ( 1 + pos ) % 8 ) & & added < = max ;
i2 + + ) {
2005-11-29 17:35:21 +00:00
/*
if ( pos + i2 > TEXT_BUFFER_SIZE - 1 )
fprintf ( stderr , " buffer overrun detected \n " ) ;
*/
tmpstring2 [ MIN ( pos + i2 , TEXT_BUFFER_SIZE - 1 ) ] = ' ' ; /* guard against overrun */
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 ) {
2005-11-29 17:35:21 +00:00
/*
if ( pos > TEXT_BUFFER_SIZE - 1 )
fprintf ( stderr , " buffer overrun detected \n " ) ;
*/
tmpstring2 [ MIN ( pos , TEXT_BUFFER_SIZE - 1 ) ] = tmpstring1 [ i ] ; /* guard against overrun */
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 ) {
/* 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-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 ;
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 ,
2005-07-28 04:48:27 +00:00
cur_x , cur_y , ( XftChar8 * ) s ,
strlen ( s ) ) ;
} else {
2005-08-03 07:01:32 +00:00
XftDrawString8 ( window . xftdraw , & c2 , fonts [ selected_font ] . xftfont ,
2005-07-28 04:48:27 +00:00
cur_x , cur_y , ( XftChar8 * ) s ,
strlen ( s ) ) ;
2005-07-25 01:13:26 +00:00
}
2005-07-20 00:30:40 +00:00
} else
# endif
{
XDrawString ( display , window . drawable , window . gc ,
cur_x , cur_y , s , strlen ( s ) ) ;
}
cur_x + = width_of_s ;
2005-08-08 01:18:52 +00:00
# endif /* X11 */
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 ;
void set_up_gradient ( )
{
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 ) {
ERR ( " using non-standard colour depth, gradients may look like a lolly-pop " ) ;
}
int i ;
redmask = 0 ;
greenmask = 0 ;
bluemask = 0 ;
for ( i = ( colour_depth / 3 ) - 1 ; i > = 0 ; i - - ) {
redmask | = 1 < < i ;
greenmask | = 1 < < i ;
bluemask | = 1 < < i ;
}
if ( colour_depth % 3 = = 1 ) {
greenmask | = 1 < < ( colour_depth / 3 ) ;
}
redmask = redmask < < ( 2 * colour_depth / 3 + colour_depth % 3 ) ;
greenmask = greenmask < < ( colour_depth / 3 ) ;
}
2005-08-17 02:48:08 +00:00
inline unsigned long do_gradient ( unsigned long first_colour , unsigned long last_colour ) { /* this function returns the next colour between two colours for a gradient */
2005-08-01 09:15:02 +00:00
int tmp_color = 0 ;
int red1 , green1 , blue1 ; // first colour
int red2 , green2 , blue2 ; // second colour
int red3 = 0 , green3 = 0 , blue3 = 0 ; // difference
2005-08-21 03:29:05 +00:00
short redshift = ( 2 * colour_depth / 3 + colour_depth % 3 ) ;
short greenshift = ( colour_depth / 3 ) ;
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 ;
}
2005-08-17 02:48:08 +00:00
inline unsigned long gradient_max ( unsigned long first_colour , unsigned long last_colour ) { /* this function returns the max diff for a gradient */
2005-08-21 03:29:05 +00:00
if ( colour_depth = = 0 ) {
set_up_gradient ( ) ;
}
2005-08-01 09:15:02 +00:00
int red1 , green1 , blue1 ; // first colour
int red2 , green2 , blue2 ; // second colour
2005-08-21 03:29:05 +00:00
long redshift = ( 2 * colour_depth / 3 + colour_depth % 3 ) ;
long greenshift = ( colour_depth / 3 ) ;
2005-08-01 09:15:02 +00:00
int red3 = 0 , green3 = 0 , blue3 = 0 ; // difference
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 ) ;
int max = red3 ;
if ( green3 > max )
max = green3 ;
if ( blue3 > max )
max = blue3 ;
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 ;
cur_x = text_start_x ;
cur_y + = font_ascent ( ) ;
2005-07-30 12:02:48 +00:00
int cur_y_add = 0 ;
short 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 ) {
case HORIZONTAL_LINE :
{
int h =
specials [ special_index ] . height ;
int mid = font_ascent ( ) / 2 ;
w = text_start_x + text_width -
cur_x ;
XSetLineAttributes ( display ,
window . gc , h ,
LineSolid ,
CapButt ,
JoinMiter ) ;
XDrawLine ( display , window . drawable ,
window . gc , cur_x ,
2005-07-28 04:48:27 +00:00
cur_y - mid / 2 ,
cur_x + w ,
cur_y - mid / 2 ) ;
2005-07-20 00:30:40 +00:00
}
break ;
case STIPPLED_HR :
{
int h =
specials [ special_index ] . height ;
int s =
specials [ special_index ] . arg ;
int mid = font_ascent ( ) / 2 ;
char ss [ 2 ] = { s , s } ;
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 ,
2005-07-28 04:48:27 +00:00
cur_y - mid / 2 ,
cur_x + w ,
cur_y - mid / 2 ) ;
2005-07-20 00:30:40 +00:00
}
break ;
case BAR :
{
2005-09-24 22:16:07 +00:00
if ( cur_x - text_start_x > maximum_width & & maximum_width > 0 ) {
2005-08-24 06:21:50 +00:00
break ;
}
2005-07-20 00:30:40 +00:00
int h =
specials [ special_index ] . height ;
int bar_usage =
specials [ special_index ] . arg ;
2005-08-26 16:29:56 +00:00
int by ;
# ifdef XFT
if ( use_xft ) {
by = cur_y - ( font_ascent ( ) + h ) / 2 - 1 ;
} else
# endif
{
by = cur_y - ( font_ascent ( ) / 2 ) - 1 ;
}
if ( h < ( font_height ( ) ) ) {
by - = h / 2 - 1 ;
}
2005-07-20 00:30:40 +00:00
w = specials [ special_index ] . width ;
if ( w = = 0 )
w = text_start_x +
text_width - cur_x - 1 ;
if ( w < 0 )
w = 0 ;
XSetLineAttributes ( display ,
window . gc , 1 ,
LineSolid ,
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 ) ;
2005-07-30 22:59:01 +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
}
2005-07-20 00:30:40 +00:00
}
break ;
2005-07-28 06:56:55 +00:00
case GRAPH :
2005-08-27 06:02:45 +00:00
{
2005-09-24 22:16:07 +00:00
if ( cur_x - text_start_x > maximum_width & & maximum_width > 0 ) {
2005-08-24 06:21:50 +00:00
break ;
}
2005-07-28 06:56:55 +00:00
int h =
2005-07-30 22:59:01 +00:00
specials [ special_index ] . height ;
2005-08-04 02:17:25 +00:00
int by ;
2006-03-08 05:48:34 +00:00
unsigned long last_colour = current_color ;
2005-08-04 02:17:25 +00:00
# ifdef XFT
if ( use_xft ) {
2005-08-26 16:29:56 +00:00
by = cur_y - ( font_ascent ( ) + h ) / 2 - 1 ;
2005-08-04 02:17:25 +00:00
} else
# endif
{
2005-08-26 16:29:56 +00:00
by = cur_y - ( font_ascent ( ) / 2 ) - 1 ;
}
if ( h < ( font_height ( ) ) ) {
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 ;
if ( w = = 0 )
2005-08-04 05:44:39 +00:00
w = text_start_x + text_width - cur_x - 1 ;
2005-07-28 06:56:55 +00:00
if ( w < 0 )
w = 0 ;
2006-01-05 23:23:51 +00:00
if ( draw_graph_borders ) {
XSetLineAttributes ( display , window . gc , 1 , LineSolid , CapButt , JoinMiter ) ;
XDrawRectangle ( display , window . drawable , window . gc , cur_x , by , w , h ) ;
}
2005-07-28 06:56:55 +00:00
XSetLineAttributes ( display ,
2005-07-30 22:59:01 +00:00
window . gc , 1 ,
LineSolid ,
CapButt ,
JoinMiter ) ;
2005-08-01 09:15:02 +00:00
int i ;
int j = 0 ;
int gradient_size = 0 ;
float gradient_factor = 0 ;
float gradient_update = 0 ;
2005-08-17 02:48:08 +00:00
unsigned long tmpcolour = current_color ;
2006-01-26 04:44:19 +00:00
if ( specials [ special_index ] . last_colour ! = specials [ special_index ] . first_colour ) {
tmpcolour = specials [ special_index ] . last_colour ;
gradient_size = gradient_max ( specials [ special_index ] . last_colour , specials [ special_index ] . first_colour ) ;
2005-08-01 09:15:02 +00:00
gradient_factor = ( float ) gradient_size / ( w - 3 ) ;
}
2006-01-26 04:44:19 +00:00
for ( i = w - 3 ; i > 0 ; i - - ) {
if ( specials [ special_index ] . last_colour ! = specials [ special_index ] . first_colour ) {
2005-08-03 07:01:32 +00:00
XSetForeground ( display , window . gc , tmpcolour ) ;
2005-08-02 05:06:53 +00:00
gradient_update + = gradient_factor ;
2005-08-01 09:15:02 +00:00
while ( gradient_update > 0 ) {
2006-01-26 04:44:19 +00:00
tmpcolour = do_gradient ( tmpcolour , specials [ special_index ] . first_colour ) ;
2005-08-01 09:15:02 +00:00
gradient_update - - ;
}
}
2006-01-26 04:44:19 +00:00
if ( ( w - 3 - i ) / ( ( float ) ( w - 3 ) / ( specials [ special_index ] . graph_width ) ) > j ) {
2005-08-01 09:15:02 +00:00
j + + ;
2006-01-26 04:44:19 +00:00
}
2005-08-01 09:15:02 +00:00
XDrawLine ( display , window . drawable , window . gc , cur_x + i + 2 , by + h , cur_x + i + 2 , by + h - specials [ special_index ] . graph [ j ] * ( h - 1 ) / specials [ special_index ] . graph_scale ) ; /* this is mugfugly, but it works */
2005-08-26 02:16:35 +00:00
}
2005-07-30 22:59:01 +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
}
2006-03-08 05:48:34 +00:00
/* if (draw_mode == BG) {
2005-08-03 07:49:06 +00:00
set_foreground_color ( default_bg_color ) ;
}
else if ( draw_mode = = OUTLINE ) {
set_foreground_color ( default_out_color ) ;
} else {
set_foreground_color ( default_fg_color ) ;
2006-03-08 05:48:34 +00:00
} */
set_foreground_color ( last_colour ) ;
}
2005-07-28 06:56:55 +00:00
break ;
2005-08-02 05:06:53 +00:00
case FONT :
2005-08-03 07:01:32 +00:00
if ( fontchange ) {
cur_y - = font_ascent ( ) ;
2005-08-03 07:26:37 +00:00
selected_font = specials [ special_index ] . font_added ;
2005-08-06 00:26:14 +00:00
cur_y + = font_ascent ( ) ;
# ifdef XFT
2005-08-29 17:06:31 +00:00
if ( ! use_xft | | use_xdbe )
2005-08-06 00:26:14 +00:00
# endif
{
set_font ( ) ;
}
2005-08-05 06:40:19 +00:00
}
2005-08-03 07:01:32 +00:00
break ;
2005-07-20 00:30:40 +00:00
case FG :
if ( draw_mode = = FG )
set_foreground_color ( specials
[ special_index ] .
arg ) ;
break ;
case BG :
if ( draw_mode = = BG )
set_foreground_color ( specials
[ special_index ] .
arg ) ;
break ;
2005-07-28 04:48:27 +00:00
case OUTLINE :
if ( draw_mode = = OUTLINE )
set_foreground_color ( specials
[ special_index ] .
arg ) ;
break ;
2005-07-20 00:30:40 +00:00
2005-08-21 05:04:22 +00:00
case OFFSET :
2005-07-31 08:27:03 +00:00
{
2005-08-20 20:33:19 +00:00
w + = specials [ special_index ] . arg ;
2005-07-31 08:27:03 +00:00
}
2005-08-21 05:04:22 +00:00
break ;
case VOFFSET :
{
cur_y + = specials [ special_index ] . arg ;
}
break ;
2005-07-31 08:27:03 +00:00
2005-07-28 04:48:27 +00:00
case ALIGNR :
2005-07-20 00:30:40 +00:00
{
2005-08-27 04:55:48 +00:00
int pos_x = text_start_x + text_width - get_string_width_special ( s ) /*+ border_margin*/ ;
/*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 ;
2005-08-21 03:29:05 +00:00
}
2005-07-20 00:30:40 +00:00
}
break ;
2005-07-28 04:48:27 +00:00
case ALIGNC :
2005-07-20 00:30:40 +00:00
{
2005-08-27 04:55:48 +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);*/
2005-07-28 04:48:27 +00:00
if ( pos_x >
specials [ special_index ] . arg )
w = pos_x -
specials
[ special_index ] . arg ;
2005-07-20 00:30:40 +00:00
}
break ;
}
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 ( ) ;
2006-05-09 23:08:23 +00:00
/* if (fontchange) {
2005-08-03 07:01:32 +00:00
selected_font = 0 ;
2006-05-09 23:08:23 +00:00
} */
2005-08-08 01:18:52 +00:00
# endif /* X11 */
2005-07-20 00:30:40 +00:00
}
static void draw_text ( )
{
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 ) {
char ss [ 2 ] =
{ stippled_borders , stippled_borders } ;
XSetLineAttributes ( display , window . gc ,
border_width , LineOnOffDash ,
CapButt , JoinMiter ) ;
XSetDashes ( display , window . gc , 0 , ss , 2 ) ;
} else {
XSetLineAttributes ( display , window . gc ,
border_width , LineSolid ,
CapButt , JoinMiter ) ;
}
XDrawRectangle ( display , window . drawable , window . gc ,
text_start_x - border_margin + b ,
text_start_y - border_margin + b ,
text_width + border_margin * 2 - 1 - b * 2 ,
text_height + border_margin * 2 - 1 -
b * 2 ) ;
}
/* 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 ) ;
}
static void draw_stuff ( )
{
2005-08-08 01:18:52 +00:00
# ifdef X11
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 ;
for ( i = - 1 ; i < 2 ; i + + )
for ( j = - 1 ; j < 2 ; j + + ) {
if ( i = = 0 & & j = = 0 )
continue ;
text_start_x + = i ;
text_start_y + = j ;
set_foreground_color ( default_out_color ) ;
draw_mode = OUTLINE ;
draw_text ( ) ;
text_start_x - = i ;
text_start_y - = j ;
}
}
set_foreground_color ( default_fg_color ) ;
draw_mode = FG ;
2005-08-08 01:18:52 +00:00
# endif /* X11 */
2005-07-20 00:30:40 +00:00
draw_text ( ) ;
2005-08-08 01:18:52 +00:00
# ifdef X11
2005-07-20 00:30:40 +00:00
# ifdef XDBE
if ( use_xdbe ) {
XdbeSwapInfo swap ;
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
}
2005-08-08 01:18:52 +00:00
# ifdef X11
2005-07-20 00:30:40 +00:00
static void clear_text ( int exposures )
{
# ifdef XDBE
2005-08-29 17:06:31 +00:00
if ( use_xdbe ) {
2005-07-20 00:30:40 +00:00
return ; /* The swap action is XdbeBackground, which clears */
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
{
2005-07-20 00:30:40 +00:00
/* there is some extra space for borders and outlines */
XClearArea ( display , window . drawable ,
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 */
static void update_text ( )
{
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 ;
}
static void main_loop ( )
{
2005-11-24 02:18:42 +00:00
# ifdef SIGNAL_BLOCKING
sigset_t newmask , oldmask ;
2005-11-23 19:05:23 +00:00
sigemptyset ( & newmask ) ;
sigaddset ( & newmask , SIGINT ) ;
sigaddset ( & newmask , SIGTERM ) ;
sigaddset ( & newmask , SIGUSR1 ) ;
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
Region region = XCreateRegion ( ) ;
2005-08-08 01:18:52 +00:00
# endif /* X11 */
2005-07-25 00:22:16 +00:00
info . looped = 0 ;
2005-07-28 04:48:27 +00:00
while ( total_run_times = = 0 | | info . looped < total_run_times - 1 ) {
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 */
if ( sigprocmask ( SIG_BLOCK , & newmask , & oldmask ) < 0 )
CRIT_ERR ( " unable to sigprocmask() " ) ;
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 ;
double t =
update_interval - ( get_time ( ) -
last_update_time ) ;
if ( t < 0 )
t = 0 ;
tv . tv_sec = ( long ) t ;
tv . tv_usec = ( long ) ( t * 1000000 ) % 1000000 ;
FD_ZERO ( & fdsr ) ;
FD_SET ( ConnectionNumber ( display ) , & fdsr ) ;
2005-08-08 01:18:52 +00:00
2005-07-20 00:30:40 +00:00
s = select ( ConnectionNumber ( display ) + 1 , & fdsr , 0 ,
0 , & tv ) ;
2005-08-08 01:18:52 +00:00
# else
usleep ( update_interval * 1000000 ) ; /* FIXME just sleep for the interval time if no X11 */
# endif /* X11 */
# ifdef X11
2005-07-20 00:30:40 +00:00
if ( s = = - 1 ) {
if ( errno ! = EINTR )
ERR ( " can't select(): %s " ,
strerror ( errno ) ) ;
} else {
/* timeout */
if ( s = = 0 )
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
2005-07-20 00:30:40 +00:00
}
}
2005-08-26 02:16:35 +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 ;
update_text_area ( ) ;
# ifdef OWN_WINDOW
if ( own_window ) {
/* resize window if it isn't right size */
if ( ! fixed_size & &
2006-03-07 06:24:58 +00:00
( text_width + border_margin * 2 + 1 ! =
2005-07-20 00:30:40 +00:00
window . width
2006-03-07 06:24:58 +00:00
| | text_height + border_margin * 2 + 1 ! =
2005-07-20 00:30:40 +00:00
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 ) ;
2006-03-07 06:24:58 +00:00
if ( own_window ) {
set_transparent_background ( window . window ) ;
}
2005-08-26 02:16:35 +00:00
}
2005-07-20 00:30:40 +00:00
/* move window if it isn't in right position */
if ( ! fixed_pos
& & ( window . x ! = wx
| | window . y ! = wy ) ) {
XMoveWindow ( display , window . window ,
window . x , window . y ) ;
}
}
# endif
clear_text ( 1 ) ;
# ifdef XDBE
if ( use_xdbe ) {
XRectangle r ;
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 ;
XNextEvent ( display , & ev ) ;
switch ( ev . type ) {
case Expose :
{
XRectangle r ;
r . x = ev . xexpose . x ;
r . y = ev . xexpose . y ;
r . width = ev . xexpose . width ;
r . height = ev . xexpose . height ;
XUnionRectWithRegion ( & r , region ,
region ) ;
}
break ;
# ifdef OWN_WINDOW
2005-08-29 17:06:31 +00:00
case ReparentNotify :
/* set background to ParentRelative for all parents */
2005-08-25 09:24:26 +00:00
if ( own_window ) {
2005-07-20 00:30:40 +00:00
set_transparent_background ( window .
2005-08-26 02:16:35 +00:00
window ) ;
2005-08-25 09:24:26 +00:00
}
2005-08-29 17:06:31 +00:00
break ;
2005-07-20 00:30:40 +00:00
case ConfigureNotify :
if ( own_window ) {
/* if window size isn't what expected, set fixed size */
if ( ev . xconfigure . width ! =
window . width
| | ev . xconfigure . height ! =
window . height ) {
if ( window . width ! = 0
& & window . height ! = 0 )
fixed_size = 1 ;
/* clear old stuff before screwing up size and pos */
clear_text ( 1 ) ;
{
XWindowAttributes
attrs ;
if ( XGetWindowAttributes ( display , window . window , & attrs ) ) {
window .
width =
attrs .
width ;
window .
height
=
attrs .
height ;
}
}
text_width =
window . width -
border_margin * 2 - 1 ;
text_height =
window . height -
border_margin * 2 - 1 ;
2005-08-24 06:21:50 +00:00
if ( text_width > maximum_width & & maximum_width > 0 )
text_width = maximum_width ;
2005-07-20 00:30:40 +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 */
2005-08-25 07:54:53 +00:00
/*if (total_updates >= 2 this is broken
2005-07-20 00:30:40 +00:00
& & ! fixed_pos
& & ( window . x ! = ev . xconfigure . x
| | window . y ! =
ev . xconfigure . y )
& & ( ev . xconfigure . x ! = 0
| | ev . xconfigure . y ! = 0 ) ) {
fixed_pos = 1 ;
2005-08-25 07:54:53 +00:00
} */
2005-09-11 23:07:28 +00:00
set_font ( ) ;
2005-07-20 00:30:40 +00:00
}
break ;
2006-03-06 05:58:58 +00:00
case ButtonPress :
if ( own_window )
{
2006-03-07 19:46:51 +00:00
/* forward the click to the desktop window */
2006-03-06 05:58:58 +00:00
XUngrabPointer ( display , ev . xbutton . time ) ;
2006-03-07 19:46:51 +00:00
ev . xbutton . window = window . desktop ;
2006-03-06 05:58:58 +00:00
XSendEvent ( display , ev . xbutton . window , False , ButtonPressMask , & ev ) ;
}
break ;
2006-03-08 23:02:28 +00:00
case ButtonRelease :
if ( own_window )
{
/* forward the release to the desktop window */
ev . xbutton . window = window . desktop ;
XSendEvent ( display , ev . xbutton . window , False , ButtonReleaseMask , & ev ) ;
}
break ;
2005-07-20 00:30:40 +00:00
# endif
default :
break ;
}
}
/* XDBE doesn't seem to provide a way to clear the back buffer without
* interfering with the front buffer , other than passing XdbeBackground
* to XdbeSwapBuffers . That means that if we ' re using XDBE , we need to
* redraw the text even if it wasn ' t part of the exposed area . OTOH ,
* if we ' re not going to call draw_stuff at all , then no swap happens
* and we can safely do nothing .
*/
if ( ! XEmptyRegion ( region ) ) {
# ifdef XDBE
if ( use_xdbe ) {
XRectangle r ;
r . x = text_start_x - border_margin ;
r . y = text_start_y - border_margin ;
r . width = text_width + border_margin * 2 ;
r . height = text_height + border_margin * 2 ;
XUnionRectWithRegion ( & r , region , region ) ;
2005-08-29 17:06:31 +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 */
if ( sigprocmask ( SIG_SETMASK , & oldmask , NULL ) < 0 )
CRIT_ERR ( " unable to sigprocmask() " ) ;
2005-11-24 02:18:42 +00:00
# endif
2005-11-23 19:05:23 +00:00
2005-11-01 06:51:48 +00:00
switch ( g_signal_pending ) {
case SIGUSR1 :
{
ERR ( " received SIGUSR1. reloading the config file. " ) ;
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
XDestroyRegion ( region ) ;
region = NULL ;
# endif /* X11 */
2005-11-10 00:37:22 +00:00
return ; /* return from main_loop */
2005-11-01 06:51:48 +00:00
/*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 ;
}
}
g_signal_pending = 0 ;
2005-07-20 00:30:40 +00:00
}
2005-11-10 04:19:43 +00:00
# ifdef X11
XDestroyRegion ( region ) ;
region = NULL ;
# endif /* X11 */
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
{
2006-02-13 02:28:46 +00:00
//lock_all_threads();
threads_runnable + + ;
2006-01-27 21:30:56 +00:00
# if defined(XMMS) || defined(BMP) || defined(AUDACIOUS) || defined(INFOPIPE)
if ( info . xmms . thread ) {
if ( destroy_xmms_thread ( ) ! = 0 )
{
ERR ( " error destroying xmms_player thread " ) ;
}
}
# endif
# ifdef TCP_PORT_MONITOR
destroy_tcp_port_monitor_collection ( info . p_tcp_port_monitor_collection ) ;
# endif
2005-07-20 00:30:40 +00:00
if ( current_config ) {
clear_fs_stats ( ) ;
load_config_file ( current_config ) ;
2005-08-08 01:18:52 +00:00
# ifdef X11
2005-08-03 07:01:32 +00:00
load_fonts ( ) ;
2005-07-20 00:30:40 +00:00
set_font ( ) ;
2005-10-22 01:37:44 +00:00
XClearWindow ( display , RootWindow ( display , screen ) ) ; // clear the window first
2005-08-08 01:18:52 +00:00
# endif /* X11 */
2005-10-31 05:17:06 +00:00
# ifdef TCP_PORT_MONITOR
info . p_tcp_port_monitor_collection = NULL ;
2006-01-11 17:03:45 +00:00
# endif
# if defined(XMMS) || defined(BMP) || defined(AUDACIOUS) || defined(INFOPIPE)
if ( ( ! info . xmms . thread ) & & ( info . xmms . current_project > PROJECT_NONE ) & &
( create_xmms_thread ( ) ! = 0 ) )
{
2006-01-12 00:10:40 +00:00
CRIT_ERR ( " unable to create xmms_player thread! " ) ;
2006-01-11 17:03:45 +00:00
}
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 ;
update_text ( ) ;
}
2006-01-28 22:13:23 +00:00
thread_count = 0 ;
2005-07-20 00:30:40 +00:00
}
2005-11-01 06:51:48 +00:00
void clean_up ( void )
2005-07-20 00:30:40 +00:00
{
2006-02-13 02:28:46 +00:00
//lock_all_threads();
threads_runnable + + ;
2005-08-08 01:18:52 +00:00
# ifdef X11
2005-07-20 00:30:40 +00:00
# ifdef 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
2006-02-14 06:15:38 +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 ) ;
}
2005-07-20 00:30:40 +00:00
else
# 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 ) ;
2005-08-08 01:18:52 +00:00
# endif /* X11 */
2005-07-20 00:30:40 +00:00
/* it is really pointless to free() memory at the end of program but ak|ra
* wants me to do this */
2005-12-10 14:15:38 +00:00
free_text_objects ( text_object_count , text_objects ) ;
text_object_count = 0 ;
text_objects = NULL ;
# ifdef MLDONKEY
ml_cleanup ( ) ;
# endif /* MLDONKEY */
2005-07-20 00:30:40 +00:00
if ( text ! = original_text )
free ( text ) ;
free ( current_config ) ;
free ( current_mail_spool ) ;
# ifdef SETI
free ( seti_dir ) ;
# endif
2005-10-31 05:17:06 +00:00
# ifdef TCP_PORT_MONITOR
destroy_tcp_port_monitor_collection ( info . p_tcp_port_monitor_collection ) ;
info . p_tcp_port_monitor_collection = NULL ;
# endif
2006-01-11 17:03:45 +00:00
# if defined(XMMS) || defined(BMP) || defined(AUDACIOUS) || defined(INFOPIPE)
if ( info . xmms . thread & & ( destroy_xmms_thread ( ) ! = 0 ) )
{
2006-01-12 00:10:40 +00:00
ERR ( " error destroying xmms_player thread " ) ;
2006-01-11 17:03:45 +00:00
}
# endif
2005-07-20 00:30:40 +00:00
}
static int string_to_bool ( const char * s )
{
if ( ! s )
return 1 ;
if ( strcasecmp ( s , " yes " ) = = 0 )
return 1 ;
if ( strcasecmp ( s , " true " ) = = 0 )
return 1 ;
if ( strcasecmp ( s , " 1 " ) = = 0 )
return 1 ;
return 0 ;
}
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 )
{
if ( strcasecmp ( s , " top_left " ) = = 0 )
return TOP_LEFT ;
else if ( strcasecmp ( s , " top_right " ) = = 0 )
return TOP_RIGHT ;
else if ( strcasecmp ( s , " bottom_left " ) = = 0 )
return BOTTOM_LEFT ;
else if ( strcasecmp ( s , " bottom_right " ) = = 0 )
return BOTTOM_RIGHT ;
else if ( strcasecmp ( s , " tl " ) = = 0 )
return TOP_LEFT ;
else if ( strcasecmp ( s , " tr " ) = = 0 )
return TOP_RIGHT ;
else if ( strcasecmp ( s , " bl " ) = = 0 )
return BOTTOM_LEFT ;
else if ( strcasecmp ( s , " br " ) = = 0 )
return BOTTOM_RIGHT ;
2005-08-20 19:43:06 +00:00
else if ( strcasecmp ( s , " none " ) = = 0 )
return NONE ;
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 ;
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
2006-04-16 03:49:49 +00:00
info . xmms2 . artist = NULL ;
info . xmms2 . album = NULL ;
info . xmms2 . title = NULL ;
info . xmms2 . genre = NULL ;
info . xmms2 . comment = NULL ;
info . xmms2 . decoder = NULL ;
info . xmms2 . transport = NULL ;
info . xmms2 . url = NULL ;
info . xmms2 . status = NULL ;
2005-07-20 00:30:40 +00:00
# endif
use_spacer = 0 ;
2005-08-08 01:18:52 +00:00
# ifdef X11
out_to_console = 0 ;
# else
out_to_console = 1 ;
# endif
# ifdef X11
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 ) ;
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 ;
gap_y = 5 ;
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 ;
2006-03-08 22:17:27 +00:00
window . type = TYPE_NORMAL ;
window . hints = 0 ;
2006-03-06 23:35:41 +00:00
strcpy ( window . wm_class_name , " conky " ) ;
2005-08-08 01:18:52 +00:00
# endif
stippled_borders = 0 ;
border_margin = 3 ;
border_width = 1 ;
text_alignment = BOTTOM_LEFT ;
on_bottom = 1 ;
# endif /* X11 */
2005-07-20 00:30:40 +00:00
free ( current_mail_spool ) ;
{
char buf [ 256 ] ;
variable_substitute ( MAIL_FILE , buf , 256 ) ;
if ( buf [ 0 ] ! = ' \0 ' )
current_mail_spool = strdup ( buf ) ;
}
no_buffers = 1 ;
update_interval = 10.0 ;
stuff_in_upper_case = 0 ;
2005-07-28 04:48:27 +00:00
# ifdef MLDONKEY
2005-10-08 02:48:21 +00:00
mlconfig . mldonkey_hostname = strdup ( " 127.0.0.1 " ) ;
2005-07-28 04:48:27 +00:00
mlconfig . mldonkey_port = 4001 ;
mlconfig . mldonkey_login = NULL ;
mlconfig . mldonkey_password = NULL ;
# endif
2005-11-11 03:28:24 +00:00
# ifdef TCP_PORT_MONITOR
2005-11-11 20:46:42 +00:00
tcp_port_monitor_collection_args . min_port_monitors = MIN_PORT_MONITORS_DEFAULT ;
tcp_port_monitor_args . min_port_monitor_connections = MIN_PORT_MONITOR_CONNECTIONS_DEFAULT ;
2005-11-11 03:28:24 +00:00
# endif
2006-01-11 17:03:45 +00:00
# if defined(XMMS) || defined(BMP) || defined(AUDACIOUS) || defined(INFOPIPE)
info . xmms . current_project = PROJECT_NONE ;
# 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 " ) ;
2005-07-20 00:30:40 +00:00
if ( ! fp )
return ;
while ( ! feof ( fp ) ) {
char buf [ 256 ] , * p , * p2 , * name , * value ;
line + + ;
if ( fgets ( buf , 256 , fp ) = = NULL )
break ;
p = buf ;
/* break at comment */
p2 = strchr ( p , ' # ' ) ;
if ( p2 )
* p2 = ' \0 ' ;
/* skip spaces */
while ( * p & & isspace ( ( int ) * p ) )
p + + ;
if ( * p = = ' \0 ' )
continue ; /* empty line */
name = p ;
/* skip name */
p2 = p ;
while ( * p2 & & ! isspace ( ( int ) * p2 ) )
p2 + + ;
if ( * p2 ! = ' \0 ' ) {
* p2 = ' \0 ' ; /* break at name's end */
p2 + + ;
}
/* get value */
if ( * p2 ) {
p = p2 ;
while ( * p & & isspace ( ( int ) * p ) )
p + + ;
value = p ;
p2 = value + strlen ( value ) ;
while ( isspace ( ( int ) * ( p2 - 1 ) ) )
* - - p2 = ' \0 ' ;
} else {
value = 0 ;
}
# define CONF2(a) if (strcasecmp(name, a) == 0)
# define CONF(a) else CONF2(a)
# define CONF3(a,b) \
2005-09-28 02:33:24 +00:00
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 " ) {
2005-08-08 01:18:52 +00:00
if ( value ) {
int a = string_to_alignment ( value ) ;
if ( a < = 0 )
CONF_ERR ;
else
text_alignment = a ;
} else
CONF_ERR ;
2005-07-30 22:59:01 +00:00
}
2005-08-08 00:54:29 +00:00
CONF ( " on_bottom " ) {
if ( value )
2006-03-06 23:35:41 +00:00
ERR ( " on_bottom is deprecated. use own_window_hints below " ) ;
2005-08-08 00:54:29 +00:00
on_bottom = string_to_bool ( value ) ;
2006-03-06 23:35:41 +00:00
if ( on_bottom )
SET_HINT ( window . hints , HINT_BELOW ) ;
2005-08-08 00:54:29 +00:00
else
CONF_ERR ;
}
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 " ) {
fork_to_background = string_to_bool ( value ) ;
}
# endif /* X11 */
# ifdef X11
2005-07-30 22:59:01 +00:00
CONF ( " border_margin " ) {
if ( value )
border_margin = strtol ( value , 0 , 0 ) ;
else
CONF_ERR ;
}
CONF ( " border_width " ) {
if ( value )
border_width = strtol ( value , 0 , 0 ) ;
else
CONF_ERR ;
}
CONF ( " default_color " ) {
if ( value )
default_fg_color = get_x11_color ( value ) ;
else
CONF_ERR ;
}
CONF3 ( " default_shade_color " , " default_shadecolor " ) {
if ( value )
default_bg_color = get_x11_color ( value ) ;
else
CONF_ERR ;
}
CONF3 ( " default_outline_color " , " default_outlinecolor " ) {
if ( value )
default_out_color = get_x11_color ( value ) ;
else
CONF_ERR ;
}
2005-08-08 01:18:52 +00:00
# endif /* X11 */
2006-01-11 17:03:45 +00:00
# if defined(XMMS) || defined(BMP) || defined(AUDACIOUS) || defined(INFOPIPE)
CONF ( " xmms_player " ) {
if ( value ) {
if ( strncmp ( value , " none " , 4 ) = = 0 )
info . xmms . current_project = PROJECT_NONE ;
else if ( strncmp ( value , " xmms " , 4 ) = = 0 )
info . xmms . current_project = PROJECT_XMMS ;
else if ( strncmp ( value , " bmp " , 3 ) = = 0 )
info . xmms . current_project = PROJECT_BMP ;
else if ( strncmp ( value , " audacious " , 9 ) = = 0 )
info . xmms . current_project = PROJECT_AUDACIOUS ;
else if ( strncmp ( value , " infopipe " , 8 ) = = 0 )
info . xmms . current_project = PROJECT_INFOPIPE ;
else
CONF_ERR ;
}
else
CONF_ERR ;
}
# endif
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 " ) {
if ( value )
2006-01-31 03:32:26 +00:00
strncpy ( info . mpd . host , value , 127 ) ;
2005-07-30 22:59:01 +00:00
else
CONF_ERR ;
}
CONF ( " mpd_port " ) {
if ( value ) {
info . mpd . port = strtol ( value , 0 , 0 ) ;
if ( info . mpd . port < 1
| | info . mpd . port > 0xffff )
CONF_ERR ;
}
}
2006-01-31 03:32:26 +00:00
CONF ( " mpd_password " ) {
if ( value )
strncpy ( info . mpd . password , value , 127 ) ;
else
CONF_ERR ;
}
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 ) ;
if ( cpu_avg_samples < 1
| | cpu_avg_samples > 14 )
CONF_ERR ;
else
info .
cpu_avg_samples
= cpu_avg_samples ;
} else
CONF_ERR ;
}
CONF ( " net_avg_samples " ) {
if ( value ) {
net_avg_samples = strtol ( value , 0 , 0 ) ;
if ( net_avg_samples < 1
| | net_avg_samples > 14 )
CONF_ERR ;
else
info .
net_avg_samples
= net_avg_samples ;
} else
CONF_ERR ;
}
2005-07-20 00:30:40 +00:00
# ifdef XDBE
2005-07-30 22:59:01 +00:00
CONF ( " double_buffer " ) {
2005-08-08 03:42:41 +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 " ) {
utf8_mode = string_to_bool ( value ) ;
}
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 " ) {
use_spacer = string_to_bool ( value ) ;
}
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 ) ;
} else
CONF_ERR ;
2005-07-30 22:59:01 +00:00
}
CONF ( " xftalpha " ) {
2005-08-03 07:01:32 +00:00
if ( value & & font_count > = 0 )
fonts [ 0 ] . font_alpha = atof ( value )
2005-07-30 22:59:01 +00:00
* 65535.0 ;
else
CONF_ERR ;
}
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 " ) {
if ( string_to_bool ( value ) )
ERR ( " Xft not enabled " ) ;
}
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 ) ;
} else
CONF_ERR ;
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 " ) {
if ( value )
gap_x = atoi ( value ) ;
else
CONF_ERR ;
}
CONF ( " gap_y " ) {
if ( value )
gap_y = atoi ( value ) ;
else
CONF_ERR ;
}
2005-08-08 01:18:52 +00:00
# endif /* X11 */
2005-07-30 22:59:01 +00:00
CONF ( " mail_spool " ) {
if ( value ) {
char buf [ 256 ] ;
variable_substitute ( value , buf , 256 ) ;
if ( buf [ 0 ]
! = ' \0 ' ) {
if ( current_mail_spool )
free ( current_mail_spool ) ;
current_mail_spool = strdup ( buf ) ;
}
} else
CONF_ERR ;
}
2005-08-08 01:18:52 +00:00
# ifdef X11
2005-07-30 22:59:01 +00:00
CONF ( " minimum_size " ) {
2005-08-24 06:21:50 +00:00
if ( value ) {
if ( sscanf
( value , " %d %d " , & minimum_width ,
& minimum_height ) ! = 2 )
if ( sscanf
( value , " %d " ,
& minimum_width ) ! = 1 )
CONF_ERR ;
} else
CONF_ERR ;
}
CONF ( " maximum_width " ) {
2005-07-30 22:59:01 +00:00
if ( value ) {
2005-08-24 06:21:50 +00:00
if ( sscanf ( value , " %d " , & maximum_width ) ! = 1 )
CONF_ERR ;
2005-07-30 22:59:01 +00:00
} else
CONF_ERR ;
}
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 ) ;
}
2005-07-20 00:30:40 +00:00
# ifdef MLDONKEY
2005-07-30 22:59:01 +00:00
CONF ( " mldonkey_hostname " ) {
2005-08-05 06:40:19 +00:00
if ( value ) {
if ( mlconfig . mldonkey_hostname ! = NULL ) {
free ( mlconfig . mldonkey_hostname ) ;
}
mlconfig . mldonkey_hostname = strdup ( value ) ;
}
2005-07-30 22:59:01 +00:00
else
CONF_ERR ;
}
CONF ( " mldonkey_port " ) {
if ( value )
mlconfig . mldonkey_port = atoi ( value ) ;
else
CONF_ERR ;
}
CONF ( " mldonkey_login " ) {
2005-08-05 06:40:19 +00:00
if ( value ) {
if ( mlconfig . mldonkey_login ! = NULL ) {
free ( mlconfig . mldonkey_login ) ;
}
2005-07-30 22:59:01 +00:00
mlconfig . mldonkey_login = strdup ( value ) ;
2005-08-05 06:40:19 +00:00
}
2005-07-30 22:59:01 +00:00
else
CONF_ERR ;
}
CONF ( " mldonkey_password " ) {
2005-08-05 06:40:19 +00:00
if ( value ) {
if ( mlconfig . mldonkey_password ! = NULL ) {
free ( mlconfig . mldonkey_password ) ;
}
2005-07-30 22:59:01 +00:00
mlconfig . mldonkey_password = strdup ( value ) ;
2005-08-05 06:40:19 +00:00
}
2005-07-30 22:59:01 +00:00
else
CONF_ERR ;
}
2005-07-20 00:30:40 +00:00
# endif
2005-08-08 01:18:52 +00:00
CONF ( " pad_percents " ) {
pad_percents = atoi ( value ) ;
}
# ifdef X11
2005-07-20 00:30:40 +00:00
# ifdef OWN_WINDOW
2005-07-30 22:59:01 +00:00
CONF ( " own_window " ) {
own_window = string_to_bool ( value ) ;
}
2005-10-31 05:17:06 +00:00
CONF ( " wm_class_name " ) {
2006-03-06 23:35:41 +00:00
memset ( window . wm_class_name , 0 , sizeof ( window . wm_class_name ) ) ;
strncpy ( window . wm_class_name , value , sizeof ( window . wm_class_name ) - 1 ) ;
2005-10-31 05:17:06 +00:00
}
2005-08-25 09:24:26 +00:00
CONF ( " own_window_transparent " ) {
set_transparent = string_to_bool ( value ) ;
}
CONF ( " own_window_colour " ) {
2006-02-13 02:28:46 +00:00
if ( value ) {
background_colour = get_x11_color ( value ) ;
} else {
ERR ( " Invalid colour for own_winder_colour (try omitting the '#' for hex colours " ) ;
}
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 */
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 ) ;
}
}
2006-03-08 22:17:27 +00:00
CONF ( " own_window_type " ) {
if ( value ) {
if ( strncmp ( value , " normal " , 6 ) = = 0 )
window . type = TYPE_NORMAL ;
else if ( strncmp ( value , " desktop " , 7 ) = = 0 )
window . type = TYPE_DESKTOP ;
2006-03-09 02:28:38 +00:00
else if ( strncmp ( value , " override " , 8 ) = = 0 )
window . type = TYPE_OVERRIDE ;
2006-03-08 22:17:27 +00:00
else
CONF_ERR ;
}
}
2005-07-20 00:30:40 +00:00
# endif
2005-07-30 22:59:01 +00:00
CONF ( " stippled_borders " ) {
if ( value )
stippled_borders = strtol ( value , 0 , 0 ) ;
else
stippled_borders = 4 ;
}
2005-08-08 01:18:52 +00:00
# endif /* X11 */
2005-07-30 22:59:01 +00:00
CONF ( " temp1 " ) {
ERR ( " temp1 configuration is obsolete, use ${i2c <i2c device here> temp 1} " ) ;
}
CONF ( " temp1 " ) {
ERR ( " temp2 configuration is obsolete, use ${i2c <i2c device here> temp 2} " ) ;
}
CONF ( " update_interval " ) {
if ( value )
update_interval = strtod ( value , 0 ) ;
else
CONF_ERR ;
}
CONF ( " total_run_times " ) {
if ( value )
total_run_times = strtod ( value , 0 ) ;
else
CONF_ERR ;
}
CONF ( " uppercase " ) {
stuff_in_upper_case = string_to_bool ( value ) ;
}
2005-07-20 00:30:40 +00:00
# ifdef SETI
2005-07-30 22:59:01 +00:00
CONF ( " seti_dir " ) {
seti_dir = ( char * )
malloc ( strlen ( value )
+ 1 ) ;
strcpy ( seti_dir , value ) ;
}
2005-07-28 04:48:27 +00:00
# endif
2005-07-30 22:59:01 +00:00
CONF ( " text " ) {
if ( text ! = original_text )
free ( text ) ;
text = ( char * )
malloc ( 1 ) ;
text [ 0 ]
= ' \0 ' ;
while ( ! feof ( fp ) ) {
unsigned
int l = strlen ( text ) ;
if ( fgets ( buf , 256 , fp ) = = NULL )
break ;
text = ( char * )
realloc ( text , l + strlen ( buf )
+ 1 ) ;
strcat ( text , buf ) ;
if ( strlen ( text ) > 1024 * 8 )
break ;
}
fclose ( fp ) ;
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
CONF ( " min_port_monitors " )
{
if ( ! value | |
2005-11-11 20:46:42 +00:00
( sscanf ( value , " %d " , & tcp_port_monitor_collection_args . min_port_monitors ) ! = 1 ) | |
2005-11-11 22:21:34 +00:00
tcp_port_monitor_collection_args . min_port_monitors < 0 )
2005-11-11 03:28:24 +00:00
{
2005-11-11 22:21:34 +00:00
/* an error. use default, warn and continue. */
2005-11-11 20:46:42 +00:00
tcp_port_monitor_collection_args . min_port_monitors = MIN_PORT_MONITORS_DEFAULT ;
2005-11-11 03:28:24 +00:00
CONF_ERR ;
}
2005-11-11 22:21:34 +00:00
else if ( tcp_port_monitor_collection_args . min_port_monitors = = 0 )
{
/* no error, just use default */
tcp_port_monitor_collection_args . min_port_monitors = MIN_PORT_MONITORS_DEFAULT ;
}
/* else tcp_port_monitor_collection_args.min_port_monitors > 0 as per config */
2005-11-11 03:28:24 +00:00
}
CONF ( " min_port_monitor_connections " )
{
if ( ! value | |
2005-11-11 20:46:42 +00:00
( sscanf ( value , " %d " , & tcp_port_monitor_args . min_port_monitor_connections ) ! = 1 )
2005-11-11 22:21:34 +00:00
| | tcp_port_monitor_args . min_port_monitor_connections < 0 )
2005-11-11 03:28:24 +00:00
{
2005-11-11 22:21:34 +00:00
/* an error. use default, warni and continue. */
2005-11-11 20:46:42 +00:00
tcp_port_monitor_args . min_port_monitor_connections = MIN_PORT_MONITOR_CONNECTIONS_DEFAULT ;
2005-11-11 03:28:24 +00:00
CONF_ERR ;
}
2005-11-11 22:21:34 +00:00
else if ( tcp_port_monitor_args . min_port_monitor_connections = = 0 )
{
/* no error, just use default */
tcp_port_monitor_args . min_port_monitor_connections = MIN_PORT_MONITOR_CONNECTIONS_DEFAULT ;
}
/* else tcp_port_monitor_args.min_port_monitor_connections > 0 as per config */
2005-11-11 03:28:24 +00:00
}
# endif
2005-07-30 22:59:01 +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 ) ;
2005-07-20 00:30:40 +00:00
# undef CONF_ERR
2006-05-13 19:51:26 +00:00
2005-07-30 22:59:01 +00:00
}
2005-07-28 04:48:27 +00:00
/* : means that character before that takes an argument */
2005-08-08 01:18:52 +00:00
static const char * getopt_string = " vVdt:f:u:i:hc:w:x:y:a: "
# ifdef X11
" x:y:w:a:f: "
2005-07-20 00:30:40 +00:00
# ifdef OWN_WINDOW
2005-07-30 22:59:01 +00:00
" o "
2005-07-20 00:30:40 +00:00
# endif
# ifdef XDBE
2005-07-30 22:59:01 +00:00
" b "
2005-07-20 00:30:40 +00:00
# endif
2005-08-08 01:18:52 +00:00
# endif /* X11 */
2005-07-30 22:59:01 +00:00
;
int main ( int argc , char * * argv )
{
2005-11-23 19:05:23 +00:00
struct sigaction act , oact ;
2005-11-01 06:51:48 +00:00
g_signal_pending = 0 ;
2005-10-31 05:17:06 +00:00
memset ( & info , 0 , sizeof ( info ) ) ;
2005-11-11 22:21:34 +00:00
# ifdef TCP_PORT_MONITOR
tcp_port_monitor_collection_args . min_port_monitors = MIN_PORT_MONITORS_DEFAULT ;
tcp_port_monitor_args . min_port_monitor_connections = MIN_PORT_MONITOR_CONNECTIONS_DEFAULT ;
# endif
2006-01-11 17:03:45 +00:00
# if defined(XMMS)
SET_XMMS_PROJECT_AVAILABLE ( info . xmms . project_mask , PROJECT_XMMS ) ;
# endif
# if defined(BMP)
SET_XMMS_PROJECT_AVAILABLE ( info . xmms . project_mask , PROJECT_BMP ) ;
# endif
# if defined(AUDACIOUS)
SET_XMMS_PROJECT_AVAILABLE ( info . xmms . project_mask , PROJECT_AUDACIOUS ) ;
# endif
# if defined(INFOPIPE)
SET_XMMS_PROJECT_AVAILABLE ( info . xmms . project_mask , PROJECT_INFOPIPE ) ;
# endif
2005-11-11 22:21:34 +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
2005-07-30 22:59:01 +00:00
char * s ;
2005-08-05 01:06:17 +00:00
char temp [ 10 ] ;
unsigned int x ;
2005-07-30 22:59:01 +00:00
2005-08-05 01:06:17 +00:00
if ( ( ( s = getenv ( " LC_ALL " ) ) & & * s ) | | ( ( s = getenv ( " LC_CTYPE " ) ) & &
* s ) | | ( ( s = getenv ( " LANG " ) ) & & * s ) ) {
strcpy ( temp , s ) ;
for ( x = 0 ; x < strlen ( s ) ; x + + ) {
temp [ x ] = tolower ( s [ x ] ) ;
}
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
}
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! \n Check 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 ) {
int c = getopt ( argc ,
argv ,
getopt_string ) ;
if ( c = = - 1 )
break ;
switch ( c ) {
case ' v ' :
case ' V ' :
printf
( " Conky " VERSION " compiled " __DATE__ " \n " ) ;
return 0 ;
case ' c ' :
/* if current_config is set to a strdup of CONFIG_FILE, free it (even
* though free ( ) does the NULL check itself ; ) , then load optarg value */
if ( current_config )
free ( current_config ) ;
current_config = strdup ( optarg ) ;
break ;
case ' h ' :
printf
2005-08-08 01:18:52 +00:00
( " Usage: %s [OPTION]... \n "
" 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 "
" file. \n "
" -V version \n "
" -c FILE config file to load instead of "
CONFIG_FILE
" \n "
" -d daemonize, fork to background \n "
" -h help \n "
# ifdef X11
" -a ALIGNMENT text alignment on screen, {top,bottom}_{left,right} \n "
" -f FONT font to use \n "
2005-07-20 00:30:40 +00:00
# ifdef OWN_WINDOW
2005-08-08 01:18:52 +00:00
" -o create own window to draw \n "
2005-07-20 00:30:40 +00:00
# endif
# ifdef XDBE
2005-08-08 01:18:52 +00:00
" -b double buffer (prevents flickering) \n "
2005-07-20 00:30:40 +00:00
# endif
2005-08-08 01:18:52 +00:00
" -w WIN_ID window id to draw \n "
" -x X x position \n "
" -y Y y position \n "
# endif /* X11 */
" -t TEXT text to render, remember single quotes, like -t '$uptime' \n "
" -u SECS update interval \n "
" -i NUM number of times to update Conky \n " , argv [ 0 ] ) ;
2005-07-30 22:59:01 +00:00
return 0 ;
2005-08-08 01:18:52 +00:00
# ifdef X11
2005-07-30 22:59:01 +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
case ' ? ' :
exit ( EXIT_FAILURE ) ;
}
}
2005-08-08 01:18:52 +00:00
# ifdef X11
2005-07-30 22:59:01 +00:00
/* initalize X BEFORE we load config. (we need to so that 'screen' is set) */
init_X11 ( ) ;
2005-08-08 01:18:52 +00:00
# endif /* X11 */
2005-07-30 22:59:01 +00:00
/* load current_config or CONFIG_FILE */
2005-07-20 00:30:40 +00:00
# ifdef CONFIG_FILE
2005-07-30 22:59:01 +00:00
if ( current_config = = NULL ) {
/* load default config file */
char buf [ 256 ] ;
variable_substitute ( CONFIG_FILE , buf , 256 ) ;
if ( buf [ 0 ] ! = ' \0 ' )
current_config = strdup ( buf ) ;
}
2005-07-20 00:30:40 +00:00
# endif
2005-08-26 01:55:33 +00:00
if ( current_config ! = NULL & & fopen ( ( const char * ) current_config , ( const char * ) " r " ) )
2005-07-30 22:59:01 +00:00
load_config_file ( current_config ) ;
2005-08-26 01:55:33 +00:00
else {
2005-07-30 22:59:01 +00:00
set_default_configurations ( ) ;
2005-08-26 01:55:33 +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 ] ;
variable_substitute ( MAIL_FILE , buf , 256 ) ;
if ( buf [ 0 ] ! = ' \0 ' )
current_mail_spool = strdup ( buf ) ;
}
2005-07-20 00:30:40 +00:00
# endif
2005-07-30 22:59:01 +00:00
/* handle other command line arguments */
2005-08-24 12:05:47 +00:00
# if defined(__FreeBSD__) || defined (__OpenBSD__) || defined(__NetBSD__)
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
# if defined(__FreeBSD__)
if ( ( kd = kvm_open ( " /dev/null " , " /dev/null " , " /dev/null " ,
O_RDONLY , " kvm_open " ) ) = = NULL )
CRIT_ERR ( " cannot read kvm " ) ;
# endif
2005-08-24 12:05:47 +00:00
2005-07-30 22:59:01 +00:00
while ( 1 ) {
int c = getopt ( argc ,
argv ,
getopt_string ) ;
if ( c = = - 1 )
break ;
switch ( c ) {
case ' d ' :
fork_to_background = 1 ;
break ;
2005-08-08 01:18:52 +00:00
# ifdef X11
case ' f ' :
2005-08-03 07:01:32 +00:00
set_first_font ( optarg ) ;
2005-07-30 22:59:01 +00:00
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
2005-07-30 22:59:01 +00:00
case ' o ' :
own_window = 1 ;
break ;
2005-07-20 00:30:40 +00:00
# endif
# ifdef XDBE
2005-07-30 22:59:01 +00:00
case ' b ' :
2005-08-26 02:16:35 +00:00
use_xdbe = 1 ;
2005-07-30 22:59:01 +00:00
break ;
2005-07-20 00:30:40 +00:00
# endif
2005-08-08 01:18:52 +00:00
# endif /* X11 */
2005-07-30 22:59:01 +00:00
case ' t ' :
if ( text ! = original_text )
free ( text ) ;
text = strdup ( optarg ) ;
convert_escapes ( text ) ;
break ;
case ' u ' :
update_interval = strtod ( optarg , 0 ) ;
break ;
case ' i ' :
total_run_times = strtod ( optarg , 0 ) ;
break ;
2005-08-08 01:18:52 +00:00
# ifdef X11
2005-07-30 22:59:01 +00:00
case ' x ' :
gap_x = atoi ( optarg ) ;
break ;
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
case ' ? ' :
exit ( EXIT_FAILURE ) ;
}
}
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 ) ;
2005-08-06 00:26:14 +00:00
if ( text ! = original_text ) {
2005-07-30 22:59:01 +00:00
free ( text ) ;
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 ( ) ;
switch ( pid ) {
2006-03-06 06:57:30 +00:00
case - 1 :
ERR ( " can't fork() to background: %s " ,
strerror ( errno ) ) ;
break ;
case 0 :
2006-03-07 20:35:11 +00:00
/* child process */
sleep ( 1 ) ;
fprintf ( stderr , " \n " ) ; fflush ( stderr ) ;
2006-03-06 06:57:30 +00:00
break ;
default :
2006-03-07 20:35:11 +00:00
/* parent process */
fprintf ( stderr , " Conky: forked to background, pid is %d \n " , pid ) ;
2006-03-06 23:35:41 +00:00
fflush ( stderr ) ;
2006-03-06 06:57:30 +00:00
return 0 ;
}
}
2005-07-30 22:59:01 +00:00
update_uname ( ) ;
generate_text ( ) ;
2005-08-08 01:18:52 +00:00
# ifdef X11
2005-07-30 22:59:01 +00:00
update_text_area ( ) ; /* to get initial size of the window */
2005-08-21 17:32:43 +00:00
init_window
2005-08-20 19:43:06 +00:00
( own_window ,
text_width + border_margin * 2 + 1 ,
text_height + border_margin * 2 + 1 ,
2006-03-06 05:58:58 +00:00
set_transparent , background_colour , info . uname_s . nodename , argv , argc ) ;
2005-08-20 19:43:06 +00:00
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 CAIRO
2005-07-20 00:30:40 +00:00
// why the fuck not?
//do_it();
2005-08-08 01:18:52 +00:00
# endif* /
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
if ( sigaction ( SIGINT , & act , & oact ) < 0 | |
sigaction ( SIGUSR1 , & act , & oact ) < 0 | |
sigaction ( SIGTERM , & act , & oact ) < 0 )
2005-07-30 22:59:01 +00:00
{
2005-11-01 06:51:48 +00:00
ERR ( " error setting signal handler: %s " , strerror ( errno ) ) ;
2005-07-30 22:59:01 +00:00
}
2005-11-01 06:51:48 +00:00
2006-01-08 14:51:47 +00:00
# if defined(XMMS) || defined(BMP) || defined(AUDACIOUS) || defined(INFOPIPE)
2006-01-11 17:03:45 +00:00
if ( ( info . xmms . current_project > PROJECT_NONE ) & & ( create_xmms_thread ( ) ! = 0 ) )
2006-01-07 07:01:22 +00:00
{
2006-01-12 00:10:40 +00:00
CRIT_ERR ( " unable to create xmms_player thread! " ) ;
2006-01-05 07:06:42 +00:00
}
# endif
2005-07-30 22:59:01 +00:00
main_loop ( ) ;
2006-01-07 07:01:22 +00:00
2006-01-08 14:51:47 +00:00
# if defined(XMMS) || defined(BMP) || defined(AUDACIOUS) || defined(INFOPIPE)
2006-01-11 17:03:45 +00:00
if ( info . xmms . thread & & ( destroy_xmms_thread ( ) ! = 0 ) )
2006-01-07 07:01:22 +00:00
{
2006-01-12 00:10:40 +00:00
ERR ( " error destroying xmms_player thread " ) ;
2006-01-07 07:01:22 +00:00
}
# endif
2005-11-25 04:17:54 +00:00
2006-03-22 19:27:31 +00:00
# if defined(__FreeBSD__)
kvm_close ( kd ) ;
# endif
2005-07-30 22:59:01 +00:00
return 0 ;
}
2005-11-01 06:51:48 +00:00
void signal_handler ( int sig )
{
/* signal handler is light as a feather, as it should be.
* we will poll g_signal_pending with each loop of conky
* and do any signal processing there , NOT here . pkovacs . */
g_signal_pending = sig ;
}