1
0
mirror of https://github.com/Llewellynvdm/conky.git synced 2024-11-17 10:35:10 +00:00

cleaned code; adding initial graph stuff, I will probably finish this later, but I wanted to get started

git-svn-id: https://conky.svn.sourceforge.net/svnroot/conky/trunk/conky@22 7f574dfc-610e-0410-a909-a81674777703
This commit is contained in:
Brenden Matthews 2005-07-28 04:48:27 +00:00
parent d898d143ef
commit b6632fd510
14 changed files with 3178 additions and 2673 deletions

231
cairo.c
View File

@ -23,69 +23,65 @@
/* Fill the given area with checks in the standard style
* for showing compositing effects.
*/
static void
fill_checks (cairo_t *cr,
int x, int y,
int width, int height)
static void fill_checks(cairo_t * cr, int x, int y, int width, int height)
{
cairo_surface_t *check;
cairo_pattern_t *check_pattern;
cairo_save (cr);
cairo_save(cr);
#define CHECK_SIZE 32
check = cairo_surface_create_similar (cairo_current_target_surface (cr),
CAIRO_FORMAT_RGB24,
2 * CHECK_SIZE, 2 * CHECK_SIZE);
cairo_surface_set_repeat (check, 1);
check =
cairo_surface_create_similar(cairo_current_target_surface(cr),
CAIRO_FORMAT_RGB24,
2 * CHECK_SIZE, 2 * CHECK_SIZE);
cairo_surface_set_repeat(check, 1);
/* Draw the check */
{
cairo_save (cr);
/* Draw the check */
{
cairo_save(cr);
cairo_set_target_surface (cr, check);
cairo_set_target_surface(cr, check);
cairo_set_operator (cr, CAIRO_OPERATOR_SRC);
cairo_set_operator(cr, CAIRO_OPERATOR_SRC);
cairo_set_rgb_color (cr, 0.4, 0.4, 0.4);
cairo_set_rgb_color(cr, 0.4, 0.4, 0.4);
cairo_rectangle (cr, 0, 0, 2 * CHECK_SIZE, 2 * CHECK_SIZE);
cairo_fill (cr);
cairo_rectangle(cr, 0, 0, 2 * CHECK_SIZE, 2 * CHECK_SIZE);
cairo_fill(cr);
cairo_set_rgb_color (cr, 0.7, 0.7, 0.7);
cairo_set_rgb_color(cr, 0.7, 0.7, 0.7);
cairo_rectangle (cr, x, y, CHECK_SIZE, CHECK_SIZE);
cairo_fill (cr);
cairo_rectangle (cr, x + CHECK_SIZE, y + CHECK_SIZE, CHECK_SIZE, CHECK_SIZE);
cairo_fill (cr);
cairo_rectangle(cr, x, y, CHECK_SIZE, CHECK_SIZE);
cairo_fill(cr);
cairo_rectangle(cr, x + CHECK_SIZE, y + CHECK_SIZE,
CHECK_SIZE, CHECK_SIZE);
cairo_fill(cr);
cairo_restore (cr);
}
cairo_restore(cr);
}
/* Fill the whole surface with the check */
/* Fill the whole surface with the check */
check_pattern = cairo_pattern_create_for_surface (check);
cairo_set_pattern (cr, check_pattern);
cairo_rectangle (cr, 0, 0, width, height);
cairo_fill (cr);
check_pattern = cairo_pattern_create_for_surface(check);
cairo_set_pattern(cr, check_pattern);
cairo_rectangle(cr, 0, 0, width, height);
cairo_fill(cr);
cairo_pattern_destroy (check_pattern);
cairo_surface_destroy (check);
cairo_pattern_destroy(check_pattern);
cairo_surface_destroy(check);
cairo_restore (cr);
cairo_restore(cr);
}
static void draw_pee (cairo_t *cr, double xc, double yc)
static void draw_pee(cairo_t * cr, double xc, double yc)
{
cairo_set_rgb_color (cr, 0, 0, 0);
cairo_show_text (cr, "Conky");
cairo_set_rgb_color(cr, 0, 0, 0);
cairo_show_text(cr, "Conky");
}
static void
draw (cairo_t *cr,
int width,
int height)
static void draw(cairo_t * cr, int width, int height)
{
cairo_surface_t *overlay;
@ -93,30 +89,30 @@ static void
double xc = width / 2.;
double yc = height / 2.;
overlay = cairo_surface_create_similar (cairo_current_target_surface (cr),
CAIRO_FORMAT_ARGB32,
width, height);
overlay =
cairo_surface_create_similar(cairo_current_target_surface(cr),
CAIRO_FORMAT_ARGB32, width,
height);
if (overlay == NULL)
return;
fill_checks (cr, 0, 0, width, height);
fill_checks(cr, 0, 0, width, height);
cairo_save (cr);
cairo_set_target_surface (cr, overlay);
cairo_save(cr);
cairo_set_target_surface(cr, overlay);
cairo_set_alpha (cr, 0.5);
cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
draw_pee (cr, xc, yc);
cairo_set_alpha(cr, 0.5);
cairo_set_operator(cr, CAIRO_OPERATOR_OVER);
draw_pee(cr, xc, yc);
cairo_restore (cr);
cairo_restore(cr);
cairo_show_surface (cr, overlay, width, height);
cairo_show_surface(cr, overlay, width, height);
cairo_surface_destroy (overlay);
cairo_surface_destroy(overlay);
}
int
do_it (void)
int do_it(void)
{
Display *dpy;
int screen;
@ -129,102 +125,107 @@ int
XWMHints *wmhints;
XSizeHints *normalhints;
XClassHint *classhint;
int width = 400;
int height = 400;
dpy = XOpenDisplay (NULL);
screen = DefaultScreen (dpy);
w = XCreateSimpleWindow (dpy, RootWindow (dpy, screen),
0, 0, width, height, 0,
BlackPixel (dpy, screen), WhitePixel (dpy, screen));
dpy = XOpenDisplay(NULL);
screen = DefaultScreen(dpy);
normalhints = XAllocSizeHints ();
w = XCreateSimpleWindow(dpy, RootWindow(dpy, screen),
0, 0, width, height, 0,
BlackPixel(dpy, screen), WhitePixel(dpy,
screen));
normalhints = XAllocSizeHints();
normalhints->flags = 0;
normalhints->x = 0;
normalhints->y = 0;
normalhints->width = width;
normalhints->height = height;
classhint = XAllocClassHint ();
classhint = XAllocClassHint();
classhint->res_name = "cairo-knockout";
classhint->res_class = "Cairo-knockout";
wmhints = XAllocWMHints ();
wmhints = XAllocWMHints();
wmhints->flags = InputHint;
wmhints->input = True;
XmbSetWMProperties (dpy, w, title, "cairo-knockout", 0, 0,
normalhints, wmhints, classhint);
XFree (wmhints);
XFree (classhint);
XFree (normalhints);
pixmap = XCreatePixmap (dpy, w, width, height, DefaultDepth (dpy, screen));
gc = XCreateGC (dpy, pixmap, 0, NULL);
XmbSetWMProperties(dpy, w, title, "cairo-knockout", 0, 0,
normalhints, wmhints, classhint);
XFree(wmhints);
XFree(classhint);
XFree(normalhints);
pixmap =
XCreatePixmap(dpy, w, width, height,
DefaultDepth(dpy, screen));
gc = XCreateGC(dpy, pixmap, 0, NULL);
quit_keycode = XKeysymToKeycode(dpy, XStringToKeysym("Q"));
XSelectInput (dpy, w, ExposureMask | StructureNotifyMask | ButtonPressMask | KeyPressMask);
XMapWindow (dpy, w);
XSelectInput(dpy, w,
ExposureMask | StructureNotifyMask | ButtonPressMask |
KeyPressMask);
XMapWindow(dpy, w);
needs_redraw = 1;
while (1) {
XEvent xev;
/* Only do the redraw if there are no events pending. This
* avoids us getting behind doing several redraws for several
* consecutive resize events for example.
*/
if (!XPending (dpy) && needs_redraw) {
cairo_t *cr = cairo_create ();
/* Only do the redraw if there are no events pending. This
* avoids us getting behind doing several redraws for several
* consecutive resize events for example.
*/
if (!XPending(dpy) && needs_redraw) {
cairo_t *cr = cairo_create();
cairo_set_target_drawable (cr, dpy, pixmap);
cairo_set_target_drawable(cr, dpy, pixmap);
draw (cr, width, height);
draw(cr, width, height);
cairo_destroy (cr);
cairo_destroy(cr);
XCopyArea (dpy, pixmap, w, gc,
0, 0,
width, height,
0, 0);
XCopyArea(dpy, pixmap, w, gc,
0, 0, width, height, 0, 0);
needs_redraw = 0;
}
XNextEvent (dpy, &xev);
XNextEvent(dpy, &xev);
switch (xev.xany.type) {
case ButtonPress:
/* A click on the canvas ends the program */
case ButtonPress:
/* A click on the canvas ends the program */
goto DONE;
case KeyPress:
if (xev.xkey.keycode == quit_keycode)
goto DONE;
case KeyPress:
if (xev.xkey.keycode == quit_keycode)
goto DONE;
break;
case ConfigureNotify:
/* Note new size and create new pixmap. */
width = xev.xconfigure.width;
height = xev.xconfigure.height;
XFreePixmap (dpy, pixmap);
pixmap = XCreatePixmap (dpy, w, width, height, DefaultDepth (dpy, screen));
needs_redraw = 1;
break;
case Expose:
XCopyArea (dpy, pixmap, w, gc,
xev.xexpose.x, xev.xexpose.y,
xev.xexpose.width, xev.xexpose.height,
xev.xexpose.x, xev.xexpose.y);
break;
break;
case ConfigureNotify:
/* Note new size and create new pixmap. */
width = xev.xconfigure.width;
height = xev.xconfigure.height;
XFreePixmap(dpy, pixmap);
pixmap =
XCreatePixmap(dpy, w, width, height,
DefaultDepth(dpy, screen));
needs_redraw = 1;
break;
case Expose:
XCopyArea(dpy, pixmap, w, gc,
xev.xexpose.x, xev.xexpose.y,
xev.xexpose.width, xev.xexpose.height,
xev.xexpose.x, xev.xexpose.y);
break;
}
}
DONE:
DONE:
XFreeGC (dpy, gc);
XCloseDisplay (dpy);
XFreeGC(dpy, gc);
XCloseDisplay(dpy);
return 0;
return 0;
}

View File

@ -53,9 +53,8 @@ void variable_substitute(const char *s, char *dest, unsigned int n)
s++;
} else {
a = s;
while (*s
&& (isalnum((int) *s)
|| *s == '_'))
while (*s && (isalnum((int) *s)
|| *s == '_'))
s++;
}
@ -197,9 +196,10 @@ void update_stuff()
update_top();
#ifdef MLDONKEY
if (NEED(INFO_MLDONKEY)) get_mldonkey_status(&mlconfig, &mlinfo);
if (NEED(INFO_MLDONKEY))
get_mldonkey_status(&mlconfig, &mlinfo);
#endif
#ifdef SETI
if (NEED(INFO_SETI))
update_seti();
@ -214,10 +214,12 @@ void update_stuff()
update_load_average();
#ifdef METAR
if (NEED(INFO_METAR) && current_update_time - last_metar_update > 1200.9 && info.looped) {
update_metar();
last_metar_update = current_update_time;
}
if (NEED(INFO_METAR)
&& current_update_time - last_metar_update > 1200.9
&& info.looped) {
update_metar();
last_metar_update = current_update_time;
}
#endif

2995
conky.c

File diff suppressed because it is too large Load Diff

30
conky.h
View File

@ -72,6 +72,8 @@ struct mpd_s {
char host[128];
float progress;
int bitrate;
int length;
int elapsed;
};
#endif
@ -98,12 +100,12 @@ enum {
#endif
INFO_TOP = 16,
#ifdef METAR
INFO_METAR = 17,
INFO_METAR = 17,
#endif
#ifdef MLDONKEY
INFO_MLDONKEY = 18,
#endif
INFO_WIFI = 19,
INFO_WIFI = 19,
};
@ -355,24 +357,24 @@ typedef struct mldonkey_config {
/* The MLDonkey status returned */
typedef struct mldonkey_info {
int64 upload_counter;
int64 upload_counter;
int64 download_counter;
int nshared_files;
int64 shared_counter;
int tcp_upload_rate;
int tcp_download_rate;
int udp_upload_rate;
int udp_download_rate;
int ndownloaded_files;
int tcp_upload_rate;
int tcp_download_rate;
int udp_upload_rate;
int udp_download_rate;
int ndownloaded_files;
int ndownloading_files;
int nconnected_networks;
int connected_networks[1];
} mldonkey_info;
extern mldonkey_info mlinfo;
extern mldonkey_config mlconfig;
int get_mldonkey_status(mldonkey_config *config, mldonkey_info *info);
int get_mldonkey_status(mldonkey_config * config, mldonkey_info * info);
#endif
@ -385,4 +387,10 @@ extern int show_nice_processes;
extern int do_it(void);
/* struct for graphs */
typedef struct graph {
unsigned int *value;
} graph;
#endif

View File

@ -26,38 +26,39 @@
#if defined(i386) || defined(__i386__)
static unsigned int get_timer();
static unsigned int get_cpu_speed(void);
static inline unsigned long long int rdtsc( void );
static inline unsigned long long int rdtsc(void);
/* cpu frequency detection code based on mplayer's one */
static unsigned int get_timer() {
static unsigned int get_timer()
{
struct timeval tv;
struct timezone tz;
gettimeofday(&tv,&tz);
return (tv.tv_sec*1000000+tv.tv_usec);
gettimeofday(&tv, &tz);
return (tv.tv_sec * 1000000 + tv.tv_usec);
}
static inline unsigned long long int rdtsc( void )
static inline unsigned long long int rdtsc(void)
{
unsigned long long int retval;
__asm __volatile ("rdtsc":"=A"(retval)::"memory");
__asm __volatile("rdtsc":"=A"(retval)::"memory");
return retval;
}
static unsigned int get_cpu_speed(void)
{
unsigned long long int tscstart, tscstop;
unsigned int start, stop;
tscstart = rdtsc();
start = get_timer();
usleep(50000);
stop = get_timer();
tscstop = rdtsc();
return((tscstop-tscstart)/((stop-start)/1000.0));
}
return ((tscstop - tscstart) / ((stop - start) / 1000.0));
}
#endif
@ -410,29 +411,33 @@ char *get_acpi_fan()
return "";
}
char* get_adt746x_cpu() {
char *get_adt746x_cpu()
{
return "";
}
char* get_adt746x_fan() {
char *get_adt746x_fan()
{
return "";
}
char* get_freq() {
char *get_freq()
{
#if defined(i386) || defined(__i386__)
int i;
char *cpuspeed;
if ((cpuspeed = (char *)malloc(16)) == NULL)
if ((cpuspeed = (char *) malloc(16)) == NULL)
exit(1);
i = 0;
if ((i = get_cpu_speed()) > 0) {
if (i < 1000000) {
i += 50; /* for rounding */
snprintf(cpuspeed, 15, "%d.%d MHz", i/1000, (i/100)%10);
if (i < 1000000) {
i += 50; /* for rounding */
snprintf(cpuspeed, 15, "%d.%d MHz", i / 1000,
(i / 100) % 10);
} else {
snprintf(cpuspeed, 15, "%d MHz", i/1000);
snprintf(cpuspeed, 15, "%d MHz", i / 1000);
}
} else {
cpuspeed = "";

1429
ftp.c

File diff suppressed because it is too large Load Diff

12
ftp.h
View File

@ -8,13 +8,13 @@
#ifndef __MIRRORS_FTP_H__
#define __MIRRORS_FTP_H__
typedef void (*ftpListCallback) (void *userData,
const char *filename, const char* attrib,
const char *owner, const char *group,
unsigned long size, int links, int year,
const char *month, int day, int minute);
const char *filename, const char *attrib,
const char *owner, const char *group,
unsigned long size, int links, int year,
const char *month, int day, int minute);
typedef void (*ftpDataCallback) (void *userData,
const char *data, int len);
const char *data, int len);
extern void initFtp(void);
@ -23,4 +23,4 @@ extern int changeFtpDirectory(char *directory);
extern int disconnectFtp(void);
int getFtp(ftpDataCallback, void *, const char *);
#endif /* __MIRRORS_FTP_H__ */
#endif /* __MIRRORS_FTP_H__ */

174
linux.c
View File

@ -41,7 +41,7 @@ static void update_sysinfo()
/* there was some problem with these */
#if 0
// info.loadavg[0] = s_info.loads[0] / 100000.0f;
// info.loadavg[0] = s_info.loads[0] / 100000.0f;
info.loadavg[1] = s_info.loads[1] / 100000.0f;
info.loadavg[2] = s_info.loads[2] / 100000.0f;
gkrelltop_process_find_top_three info.mask |= 1 << INFO_LOADAVG;
@ -64,7 +64,7 @@ static void update_sysinfo()
void update_uptime()
{
/* prefers sysinfo() for uptime, I don't really know which one is better
* (=faster?) */
* (=faster?) */
#ifdef USE_PROC_UPTIME
static int rep;
FILE *fp = open_file("/proc/uptime", &rep);
@ -91,7 +91,7 @@ void update_meminfo()
char buf[256];
info.mem = info.memmax = info.swap = info.swapmax = info.bufmem =
info.buffers = info.cached = 0;
info.buffers = info.cached = 0;
if (meminfo_fp == NULL)
meminfo_fp = open_file("/proc/meminfo", &rep);
@ -194,37 +194,40 @@ inline void update_net_stats()
if (r < ns->last_read_recv)
ns->recv +=
((long long) 4294967295U -
ns->last_read_recv) + r;
((long long) 4294967295U -
ns->last_read_recv) + r;
else
ns->recv += (r - ns->last_read_recv);
ns->last_read_recv = r;
if (t < ns->last_read_trans)
ns->trans +=
((long long) 4294967295U -
ns->last_read_trans) + t;
((long long) 4294967295U -
ns->last_read_trans) + t;
else
ns->trans += (t - ns->last_read_trans);
ns->last_read_trans = t;
/*** ip addr patch ***/
i = socket(PF_INET, SOCK_DGRAM, IPPROTO_IP);
conf.ifc_buf = malloc(sizeof(struct ifreq) * 16);
conf.ifc_len = sizeof(struct ifreq) * 16;
ioctl((long)i, SIOCGIFCONF, &conf);
ioctl((long) i, SIOCGIFCONF, &conf);
for (k=0; k < conf.ifc_len / sizeof(struct ifreq); k++) {
struct net_stat *ns;
ns = get_net_stat(((struct ifreq*)conf.ifc_buf)[k].ifr_ifrn.ifrn_name);
ns->addr = ((struct ifreq*)conf.ifc_buf)[k].ifr_ifru.ifru_addr;
for (k = 0; k < conf.ifc_len / sizeof(struct ifreq); k++) {
struct net_stat *ns;
ns = get_net_stat(((struct ifreq *) conf.
ifc_buf)[k].ifr_ifrn.ifrn_name);
ns->addr =
((struct ifreq *) conf.ifc_buf)[k].ifr_ifru.
ifru_addr;
}
close((long)i);
close((long) i);
free(conf.ifc_buf);
@ -247,7 +250,7 @@ inline void update_net_stats()
for (i = info.net_avg_samples; i > 1; i--) {
ns->net_rec[i - 1] = ns->net_rec[i - 2];
ns->net_trans[i - 1] =
ns->net_trans[i - 2];
ns->net_trans[i - 2];
}
}
@ -258,45 +261,49 @@ inline void update_net_stats()
/* fclose(net_dev_fp); net_dev_fp = NULL; */
}
inline void update_wifi_stats() {
inline void update_wifi_stats()
{
/** wireless stats patch by Bobby Beckmann **/
static int rep;
int i;
char buf[256];
/*open file and ignore first two lines sorry, this code sucks ass right now, i'll clean it up later*/
/*open file and ignore first two lines sorry, this code sucks ass right now, i'll clean it up later */
if (net_wireless_fp == NULL)
net_wireless_fp = open_file("/proc/net/wireless", &rep);
else
fseek(net_wireless_fp, 0, SEEK_SET);
if (!net_wireless_fp) return;
if (!net_wireless_fp)
return;
fgets(buf, 255, net_wireless_fp); /* garbage */
fgets(buf, 255, net_wireless_fp); /* garbage (field names) */
fgets(buf, 255, net_wireless_fp); /* garbage */
fgets(buf, 255, net_wireless_fp); /* garbage (field names) */
/* read each interface */
for (i=0; i<16; i++) {
for (i = 0; i < 16; i++) {
struct net_stat *ns;
char *s, *p;
int l, m, n;
if (fgets(buf, 255, net_wireless_fp) == NULL) break;
if (fgets(buf, 255, net_wireless_fp) == NULL)
break;
p = buf;
while (isspace((int) *p)) p++;
while (isspace((int) *p))
p++;
s = p;
while (*p && *p != ':') p++;
if (*p == '\0') continue;
while (*p && *p != ':')
p++;
if (*p == '\0')
continue;
*p = '\0';
p++;
ns = get_net_stat(s);
sscanf(p,
"%*d %d. %d. %d",
&l, &m, &n);
sscanf(p, "%*d %d. %d. %d", &l, &m, &n);
ns->linkstatus = (int)(log(l) / log(92) * 100);
ns->linkstatus = (int) (log(l) / log(92) * 100);
}
/*** end wireless patch ***/
@ -359,9 +366,9 @@ inline static void update_stat()
clock_ticks = sysconf(_SC_CLK_TCK);
curtmp = 0;
cpu_val[0] =
(cpu_user + cpu_nice + cpu_system -
last_cpu_sum) / delta / (double) clock_ticks /
info.cpu_count;
(cpu_user + cpu_nice + cpu_system -
last_cpu_sum) / delta / (double) clock_ticks /
info.cpu_count;
for (i = 0; i < info.cpu_avg_samples; i++)
curtmp += cpu_val[i];
info.cpu_usage = curtmp / info.cpu_avg_samples;
@ -428,7 +435,7 @@ static int no_dots(const struct dirent *d)
}
static int
get_first_file_in_a_directory(const char *dir, char *s, int *rep)
get_first_file_in_a_directory(const char *dir, char *s, int *rep)
{
struct dirent **namelist;
int i, n;
@ -480,9 +487,9 @@ open_i2c_sensor(const char *dev, const char *type, int n, int *div,
type = "in";
if (strcmp(type, "tempf") == 0) {
snprintf(path, 255, I2C_DIR "%s/%s%d_input", dev, "temp", n);
}
else {
snprintf(path, 255, I2C_DIR "%s/%s%d_input", dev, "temp",
n);
} else {
snprintf(path, 255, I2C_DIR "%s/%s%d_input", dev, type, n);
}
strcpy(devtype, path);
@ -492,7 +499,8 @@ open_i2c_sensor(const char *dev, const char *type, int n, int *div,
if (fd < 0)
ERR("can't open '%s': %s", path, strerror(errno));
if (strcmp(type, "in") == 0 || strcmp(type, "temp") == 0 || strcmp(type, "tempf") == 0)
if (strcmp(type, "in") == 0 || strcmp(type, "temp") == 0
|| strcmp(type, "tempf") == 0)
*div = 1;
else
*div = 0;
@ -502,9 +510,9 @@ open_i2c_sensor(const char *dev, const char *type, int n, int *div,
/* test if *_div file exist, open it and use it as divisor */
if (strcmp(type, "tempf") == 0) {
snprintf(path, 255, I2C_DIR "%s/%s%d_div", "one", "two", n);
}
else {
snprintf(path, 255, I2C_DIR "%s/%s%d_div", "one", "two",
n);
} else {
snprintf(path, 255, I2C_DIR "%s/%s%d_div", dev, type, n);
}
@ -515,7 +523,7 @@ open_i2c_sensor(const char *dev, const char *type, int n, int *div,
unsigned int divn;
divn = read(divfd, divbuf, 63);
/* should read until n == 0 but I doubt that kernel will give these
* in multiple pieces. :) */
* in multiple pieces. :) */
divbuf[divn] = '\0';
*div = atoi(divbuf);
}
@ -540,7 +548,7 @@ double get_i2c_info(int *fd, int div, char *devtype, char *type)
unsigned int n;
n = read(*fd, buf, 63);
/* should read until n == 0 but I doubt that kernel will give these
* in multiple pieces. :) */
* in multiple pieces. :) */
buf[n] = '\0';
val = atoi(buf);
}
@ -549,26 +557,25 @@ double get_i2c_info(int *fd, int div, char *devtype, char *type)
/* open file */
*fd = open(devtype, O_RDONLY);
if (*fd < 0)
ERR("can't open '%s': %s", devtype, strerror(errno));
ERR("can't open '%s': %s", devtype, strerror(errno));
/* My dirty hack for computing CPU value
* Filedil, from forums.gentoo.org
*/
* Filedil, from forums.gentoo.org
*/
/* if (strstr(devtype, "temp1_input") != NULL)
return -15.096+1.4893*(val / 1000.0); */
/* divide voltage and temperature by 1000 */
/* or if any other divisor is given, use that */
if (strcmp(type, "tempf") == 0) {
if (div > 1)
return ((val / div + 40)*9.0/5)-40;
return ((val / div + 40) * 9.0 / 5) - 40;
else if (div)
return ((val / 1000.0 + 40)*9.0/5)-40;
return ((val / 1000.0 + 40) * 9.0 / 5) - 40;
else
return ((val + 40)*9.0/5)-40;
}
else {
return ((val + 40) * 9.0 / 5) - 40;
} else {
if (div > 1)
return val / div;
else if (div)
@ -643,7 +650,7 @@ char *get_adt746x_cpu()
__inline__ unsigned long long int rdtsc()
{
unsigned long long int x;
__asm__ volatile (".byte 0x0f, 0x31" : "=A" (x));
__asm__ volatile (".byte 0x0f, 0x31":"=A" (x));
return x;
}
@ -655,9 +662,9 @@ char *get_freq()
buffer = malloc(64);
struct timezone tz;
struct timeval tvstart, tvstop;
unsigned long long cycles[2]; /* gotta be 64 bit */
unsigned int microseconds; /* total time taken */
unsigned long long cycles[2]; /* gotta be 64 bit */
unsigned int microseconds; /* total time taken */
memset(&tz, 0, sizeof(tz));
/* get this function in cached memory */
@ -667,14 +674,13 @@ char *get_freq()
/* we don't trust that this is any specific length of time */
usleep(100);
cycles[1] = rdtsc();
gettimeofday(&tvstop, &tz);
microseconds = ((tvstop.tv_sec-tvstart.tv_sec)*1000000) +
(tvstop.tv_usec-tvstart.tv_usec);
microseconds = ((tvstop.tv_sec - tvstart.tv_sec) * 1000000) +
(tvstop.tv_usec - tvstart.tv_usec);
sprintf(buffer, "%lldMHz",
(cycles[1]-cycles[0])/microseconds);
sprintf(buffer, "%lldMHz", (cycles[1] - cycles[0]) / microseconds);
return buffer;
}
@ -772,7 +778,7 @@ int open_acpi_temperature(const char *name)
if (name == NULL || strcmp(name, "*") == 0) {
static int rep;
if (!get_first_file_in_a_directory
(ACPI_THERMAL_DIR, buf, &rep))
(ACPI_THERMAL_DIR, buf, &rep))
return -1;
name = buf;
}
@ -910,8 +916,8 @@ void get_battery_stuff(char *buf, unsigned int n, const char *bat)
break;
if (sscanf
(b, "last full capacity: %d",
&acpi_last_full) != 0)
(b, "last full capacity: %d",
&acpi_last_full) != 0)
break;
}
@ -947,45 +953,47 @@ void get_battery_stuff(char *buf, unsigned int n, const char *bat)
format_seconds(last_battery_str + 9,
63 - 9,
(acpi_last_full -
remaining_capacity) * 60 *
60 / present_rate);
remaining_capacity) * 60 *
60 / present_rate);
} else if (acpi_last_full != 0
&& present_rate <= 0) {
sprintf(last_battery_str, "charging %d%%",
remaining_capacity * 100 /
acpi_last_full);
} else {
strcpy(last_battery_str, "charging");
}
&& present_rate <= 0) {
sprintf(last_battery_str, "charging %d%%",
remaining_capacity * 100 /
acpi_last_full);
} else {
strcpy(last_battery_str, "charging");
}
}
/* discharging */
else if (strcmp(charging_state, "discharging") == 0) {
if (present_rate > 0)
format_seconds(last_battery_str, 63,
(remaining_capacity * 60 *
60) / present_rate);
60) / present_rate);
else
sprintf(last_battery_str,
"discharging %d%%",
remaining_capacity * 100 /
acpi_last_full);
acpi_last_full);
}
/* charged */
/* thanks to Lukas Zapletal <lzap@seznam.cz> */
else if (strcmp(charging_state, "charged") == 0) {
if (acpi_last_full != 0 && remaining_capacity != acpi_last_full)
if (acpi_last_full != 0
&& remaining_capacity != acpi_last_full)
sprintf(last_battery_str, "charged %d%%",
remaining_capacity * 100 / acpi_last_full);
remaining_capacity * 100 /
acpi_last_full);
else
strcpy(last_battery_str, "charged");
}
/* unknown, probably full / AC */
else {
if (acpi_last_full != 0
&& remaining_capacity != acpi_last_full)
&& remaining_capacity != acpi_last_full)
sprintf(last_battery_str, "unknown %d%%",
remaining_capacity * 100 /
acpi_last_full);
acpi_last_full);
else
strcpy(last_battery_str, "AC");
}
@ -1013,7 +1021,7 @@ void get_battery_stuff(char *buf, unsigned int n, const char *bat)
}
/* it seemed to buffer it so file must be closed (or could use syscalls
* directly but I don't feel like coding it now) */
* directly but I don't feel like coding it now) */
fclose(apm_bat_fp);
apm_bat_fp = NULL;
}

View File

@ -10,58 +10,67 @@
static int status = 0;
int calculateRelativeHumidity(int temp, int dew) {
int calculateRelativeHumidity(int temp, int dew)
{
float rh = 0.0;
rh = 100.0 * powf ((112 - (0.1 * temp)+dew ) / (112 + (0.9 * temp)), 8);
return (int)rh;
rh = 100.0 * powf((112 - (0.1 * temp) + dew) /
(112 + (0.9 * temp)), 8);
return (int) rh;
}
int calculateWindChill(int temperatureC, int windKn) {
int calculateWindChill(int temperatureC, int windKn)
{
double windKmh = knTokph(windKn);
return (int)(13.112+0.6215*temperatureC - 11.37*powf(windKmh,.16) + 0.3965*temperatureC*powf(windKmh,.16) );
return (int) (13.112 + 0.6215 * temperatureC -
11.37 * powf(windKmh,
.16) +
0.3965 * temperatureC * powf(windKmh, .16));
}
int knTokph(int knSpeed ){
int knTokph(int knSpeed)
{
return (knSpeed * 1.852);
}
const char *calculateWindDirectionString(int degree) {
const char *calculateWindDirectionString(int degree)
{
if (degree < 22.5) {
return "North";
} else if (degree < 67.5){
} else if (degree < 67.5) {
return "Northeast";
} else if (degree < 112.5) {
return "East";
} else if (degree < 157.5) {
return "Southeast";
} else if (degree < 202.5){
} else if (degree < 202.5) {
return "South";
} else if (degree < 247.5) {
return "Southwest";
} else if (degree < 292.5) {
return "West";
} else if (degree < 337.5){
} else if (degree < 337.5) {
return "Northwest";
} else {
return "North";
}
}
const char*calculateShortWindDirectionString(int degree){
const char *calculateShortWindDirectionString(int degree)
{
if (degree < 22.5) {
return "N";
} else if (degree < 67.5){
} else if (degree < 67.5) {
return "NE";
} else if (degree < 112.5) {
return "E";
} else if (degree < 157.5) {
return "SE";
} else if (degree < 202.5){
} else if (degree < 202.5) {
return "S";
} else if (degree < 247.5) {
return "SW";
} else if (degree < 292.5) {
return "W";
} else if (degree < 337.5){
} else if (degree < 337.5) {
return "NW";
} else {
return "N";
@ -70,36 +79,39 @@ const char*calculateShortWindDirectionString(int degree){
void ftpData(void *userData, const char *data, int len)
{
if(userData) {} // do nothing to make stupid warning go away
if (userData) {
} // do nothing to make stupid warning go away
if (len <= 0)
return;
if ( data != NULL ){
if (data != NULL) {
line = strdup(data);
}
}
extern unsigned int sleep(unsigned int);
void *fetch_ftp( ) {
// try three times if it fails
void *fetch_ftp()
{
// try three times if it fails
int tries = 0;
do {
if (tries > 0) {
/* this happens too often, so i'll leave it commented fprintf(stderr, "METAR update failed for some reason, retry %i\n", tries); */
sleep(15); /* give it some time in case the server is busy or down */
sleep(15); /* give it some time in case the server is busy or down */
}
tries++;
if ( strlen(metar_station) != 8 ){
if (strlen(metar_station) != 8) {
ERR("You didn't supply a valid METAR station code\n");
return NULL;
}
if (metar_server == NULL)
metar_server = strdup("weather.noaa.gov");
if (metar_path == NULL)
metar_path = strdup("/data/observations/metar/stations");
metar_path =
strdup("/data/observations/metar/stations");
int res;
initFtp();
res = connectFtp(metar_server, 0);
@ -110,7 +122,8 @@ void *fetch_ftp( ) {
}
res = changeFtpDirectory(metar_path);
if (res < 0) {
ERR("Metar update failed (couldn't CWD to %s)\n", metar_path);
ERR("Metar update failed (couldn't CWD to %s)\n",
metar_path);
disconnectFtp();
status = 1;
return NULL;
@ -123,16 +136,15 @@ void *fetch_ftp( ) {
if (getFtp(ftpData, NULL, metar_station) < 0) {
ERR("Failed to get file %s\n", metar_station);
}
disconnectFtp();
if ( line != NULL ){
if (line != NULL) {
dcdNetMETAR(line, &data);
free(line);
line = NULL;
ftp_ok = 1;
metar_worked = 1;
}
else {
} else {
ftp_ok = 0;
}
@ -143,19 +155,18 @@ void *fetch_ftp( ) {
static pthread_t thread1;
void update_metar() {
int iret1;
void update_metar()
{
int iret1;
if (!status) {
status = 2;
iret1 = pthread_create( &thread1, NULL, fetch_ftp, NULL);
}
else if (status == 2) { /* thread is still running. what else can we do? */
iret1 = pthread_create(&thread1, NULL, fetch_ftp, NULL);
} else if (status == 2) { /* thread is still running. what else can we do? */
return;
}
else {
pthread_join( thread1, NULL);
} else {
pthread_join(thread1, NULL);
status = 2;
iret1 = pthread_create( &thread1, NULL, fetch_ftp, NULL);
iret1 = pthread_create(&thread1, NULL, fetch_ftp, NULL);
}
}

View File

@ -8,11 +8,11 @@ int knTokph(int);
const char *calculateWindDirectionString(int);
const char *calculateShortWindDirectionString(int);
char *line = NULL;
char *line = NULL;
char *metar_station = NULL;
char *metar_server = NULL;
char *metar_path = NULL;
char ftp_ok = 0;
char metar_worked = 0;
char *metar_server = NULL;
char *metar_path = NULL;
char ftp_ok = 0;
char metar_worked = 0;
Decoded_METAR data;

View File

@ -1,10 +1,11 @@
#include "conky.h"
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include <netdb.h>
#include <fcntl.h>
#include <arpa/inet.h>
#include "conky.h"
int64 buf_to_int(char *buf, int pos, int size);
void int_to_buf(int64 i, char *buf, int pos, int size);
@ -28,56 +29,56 @@ mldonkey_config mlconfig;
* -1 otherwise. */
enum to_gui {
CoreProtocol, /* 0 */
Options_info,
RESERVED2,
DefineSearches,
Result_info,
Search_result,
Search_waiting,
File_info,
File_downloaded,
File_availability,
File_source, /* 10 */
Server_busy,
Server_user,
Server_state,
Server_info,
Client_info,
Client_state,
Client_friend,
Client_file,
Console,
Network_info, /* 20 */
User_info,
Room_info,
Room_message,
Room_add_user,
Client_stats,
Server_info_v2,
MessageFromClient,
ConnectedServers,
DownloadFiles,
DownloadedFiles, /* 30 */
Room_info_v2,
Room_remove_user,
Shared_file_info,
Shared_file_upload,
Shared_file_unshared,
Add_section_option,
Client_stats_v2,
Add_plugin_option,
Client_stats_v3,
File_info_v2, /* 40 */
DownloadFiles_v2,
DownloadedFiles_v2,
File_info_v3,
DownloadFiles_v3,
DownloadedFiles_v3,
File_downloaded_v2,
BadPassword,
Shared_file_info_v2,
Client_stats_v4, /* 49 */
CoreProtocol, /* 0 */
Options_info,
RESERVED2,
DefineSearches,
Result_info,
Search_result,
Search_waiting,
File_info,
File_downloaded,
File_availability,
File_source, /* 10 */
Server_busy,
Server_user,
Server_state,
Server_info,
Client_info,
Client_state,
Client_friend,
Client_file,
Console,
Network_info, /* 20 */
User_info,
Room_info,
Room_message,
Room_add_user,
Client_stats,
Server_info_v2,
MessageFromClient,
ConnectedServers,
DownloadFiles,
DownloadedFiles, /* 30 */
Room_info_v2,
Room_remove_user,
Shared_file_info,
Shared_file_upload,
Shared_file_unshared,
Add_section_option,
Client_stats_v2,
Add_plugin_option,
Client_stats_v3,
File_info_v2, /* 40 */
DownloadFiles_v2,
DownloadedFiles_v2,
File_info_v3,
DownloadFiles_v3,
DownloadedFiles_v3,
File_downloaded_v2,
BadPassword,
Shared_file_info_v2,
Client_stats_v4, /* 49 */
};
#define MLDONKEY_DISCONNECTED 0
@ -98,89 +99,93 @@ static mldonkey_config *old_config = NULL;
int64 buf_to_int(char *buf, int pos, int size)
{
int i;
int64 res = 0;
int i;
int64 res = 0;
for(i = 0; i < size; i++){
res += (buf[pos + i] & 0xFF) << (8 * i);
}
return res;
for (i = 0; i < size; i++) {
res += (buf[pos + i] & 0xFF) << (8 * i);
}
return res;
}
void int_to_buf(int64 i, char *buf, int pos, int size)
{
int j;
int j;
for(j = 0; j < size; j++){
buf[pos + j] = (i & (-1)) >> (8 * j);
}
for (j = 0; j < size; j++) {
buf[pos + j] = (i & (-1)) >> (8 * j);
}
}
/* Write operations --------------------- */
void init_message()
{ write_pos = 0; }
{
write_pos = 0;
}
void write_int8(int code)
{
write_buf[write_pos++] = code;
write_buf[write_pos++] = code;
}
void write_opcode(int code)
{
write_buf[write_pos++] = code;
write_buf[write_pos++] = code;
}
void write_int16(int code)
{
INT_TO_BUF16(code, write_buf, write_pos);
write_pos += 2;
INT_TO_BUF16(code, write_buf, write_pos);
write_pos += 2;
}
void write_int32(int code)
{
INT_TO_BUF32(code, write_buf, write_pos);
write_pos += 4;
INT_TO_BUF32(code, write_buf, write_pos);
write_pos += 4;
}
void write_int64(int64 code)
{
INT_TO_BUF64(code, write_buf, write_pos);
write_pos += 8;
INT_TO_BUF64(code, write_buf, write_pos);
write_pos += 8;
}
void write_string(char *str)
{
if(str == NULL){
write_int16(0);
} else {
int len = strlen(str);
write_int16(len);
memcpy((void *) (write_buf + write_pos), (void *) str, (size_t) len);
write_pos += len;
}
if (str == NULL) {
write_int16(0);
} else {
int len = strlen(str);
write_int16(len);
memcpy((void *) (write_buf + write_pos), (void *) str,
(size_t) len);
write_pos += len;
}
}
int write_message(char *mtype)
{
char header[4];
char header[4];
INT_TO_BUF32(write_pos, header, 0);
if(4 != write(mldonkey_sock, header, 4) ||
write_pos != write(mldonkey_sock,(void *)write_buf,(size_t)write_pos)){
ERR("Error in transmitting %s\n",mtype);
write_pos = 0;
INT_TO_BUF32(write_pos, header, 0);
if (4 != write(mldonkey_sock, header, 4) ||
write_pos != write(mldonkey_sock, (void *) write_buf,
(size_t) write_pos)) {
ERR("Error in transmitting %s\n", mtype);
write_pos = 0;
/* Immediatly close the connection */
close(mldonkey_sock);
mldonkey_state = MLDONKEY_DISCONNECTED;
mldonkey_sock = -1;
return -1;
} else {
write_pos = 0;
return 0;
}
/* Immediatly close the connection */
close(mldonkey_sock);
mldonkey_state = MLDONKEY_DISCONNECTED;
mldonkey_sock = -1;
return -1;
} else {
write_pos = 0;
return 0;
}
}
@ -188,44 +193,44 @@ int write_message(char *mtype)
int read_int8()
{
return read_buf[read_pos++];
return read_buf[read_pos++];
}
int read_int16()
{
int i = BUF16_TO_INT(read_buf, read_pos);
read_pos += 2;
return i;
int i = BUF16_TO_INT(read_buf, read_pos);
read_pos += 2;
return i;
}
int read_int32()
{
int i = BUF32_TO_INT(read_buf, read_pos);
read_pos += 4;
return i;
int i = BUF32_TO_INT(read_buf, read_pos);
read_pos += 4;
return i;
}
int64 read_int64()
{
int64 i = BUF64_TO_INT(read_buf, read_pos);
read_pos += 8;
return i;
int64 i = BUF64_TO_INT(read_buf, read_pos);
read_pos += 8;
return i;
}
char* read_string()
char *read_string()
{
char *buf;
int len;
char *buf;
int len;
len = BUF16_TO_INT(read_buf, read_pos);
read_pos += 2;
len = BUF16_TO_INT(read_buf, read_pos);
read_pos += 2;
buf = (char *) malloc((size_t) len+1);
memmove(read_buf + read_pos, buf, len);
buf[len] = 0;
read_pos += len;
buf = (char *) malloc((size_t) len + 1);
memmove(read_buf + read_pos, buf, len);
buf[len] = 0;
read_pos += len;
return buf;
return buf;
}
/* protocol impl. ----------------------------- */
@ -236,197 +241,216 @@ void close_sock();
-1 on error. */
int cut_messages(int reinit)
{
int nread;
static int toread = 0;
static int pos = 0;
int nread;
static int toread = 0;
static int pos = 0;
if(reinit){
toread = 0;
pos = 0;
read_pos = 0;
return 0;
}
if (reinit) {
toread = 0;
pos = 0;
read_pos = 0;
return 0;
}
while(1){
if(toread == 0){
nread = read(mldonkey_sock, read_buf+pos,4-pos);
if(nread <= 0){
if(errno == EAGAIN) {
return 0;
} else {
close_sock();
pos = 0; toread = 0; return -1; }
}
pos += nread;
if(pos == 4){
toread = BUF32_TO_INT(read_buf,0);
pos = 0;
}
} else {
nread = read(mldonkey_sock, read_buf+pos, toread - pos);
if(nread <= 0){
if(errno == EAGAIN) return 0; else {
pos = 0; toread = 0;
close_sock();
return -1; }
}
pos += nread;
if(pos == toread){
/* We have one message !!! */
int old_pos = pos;
read_pos = 0;
pos = 0;
toread = 0;
while (1) {
if (toread == 0) {
nread =
read(mldonkey_sock, read_buf + pos, 4 - pos);
if (nread <= 0) {
if (errno == EAGAIN) {
return 0;
} else {
close_sock();
pos = 0;
toread = 0;
return -1;
}
}
pos += nread;
if (pos == 4) {
toread = BUF32_TO_INT(read_buf, 0);
pos = 0;
}
} else {
nread =
read(mldonkey_sock, read_buf + pos,
toread - pos);
if (nread <= 0) {
if (errno == EAGAIN)
return 0;
else {
pos = 0;
toread = 0;
close_sock();
return -1;
}
}
pos += nread;
if (pos == toread) {
/* We have one message !!! */
int old_pos = pos;
read_pos = 0;
pos = 0;
toread = 0;
return old_pos;
}
}
}
return old_pos;
}
}
}
}
void close_sock()
{
old_config = NULL;
if(mldonkey_sock >= 0) close(mldonkey_sock);
mldonkey_sock = -1;
mldonkey_state = MLDONKEY_DISCONNECTED;
cut_messages(1);
old_config = NULL;
if (mldonkey_sock >= 0)
close(mldonkey_sock);
mldonkey_sock = -1;
mldonkey_state = MLDONKEY_DISCONNECTED;
cut_messages(1);
}
int mldonkey_connect(mldonkey_config *config)
{
if(config != old_config){
struct sockaddr_in sa;
int retcode;
close_sock();
int mldonkey_connect(mldonkey_config * config)
{
if (config != old_config) {
struct sockaddr_in sa;
int retcode;
close_sock();
old_config=config;
/* resolve hostname */
memset(&sa, 0, sizeof(sa));
old_config = config;
/* resolve hostname */
memset(&sa, 0, sizeof(sa));
if(config->mldonkey_hostname == NULL)
config->mldonkey_hostname = "127.0.0.1";
if(config->mldonkey_hostname[0] >= '0' &&
config->mldonkey_hostname[0] <= '9'){
#ifdef HAS_INET_ATON
if (inet_aton(config->mldonkey_hostname, &sa.sin_addr) == 0) return -1;
#else
if (config->mldonkey_hostname == NULL)
config->mldonkey_hostname = "127.0.0.1";
if (config->mldonkey_hostname[0] >= '0' &&
config->mldonkey_hostname[0] <= '9') {
#ifdef HAS_INET_ATON
if (inet_aton
(config->mldonkey_hostname, &sa.sin_addr) == 0)
return -1;
#else
sa.sin_addr.s_addr = inet_addr(config->mldonkey_hostname);
if (sa.sin_addr.s_addr == (unsigned int) -1) return -1;
#endif
sa.sin_addr.s_addr =
inet_addr(config->mldonkey_hostname);
if (sa.sin_addr.s_addr == (unsigned int) -1)
return -1;
#endif
} else {
struct hostent * hp;
hp = gethostbyname(config->mldonkey_hostname);
if (hp == (struct hostent *) NULL) return -1;
sa.sin_addr.s_addr = (unsigned long)hp->h_addr_list[0];
}
} else {
struct hostent *hp;
hp = gethostbyname(config->mldonkey_hostname);
if (hp == (struct hostent *) NULL)
return -1;
sa.sin_addr.s_addr =
(unsigned long) hp->h_addr_list[0];
}
sa.sin_port = htons(config->mldonkey_port);
sa.sin_family = AF_INET;
sa.sin_port = htons(config->mldonkey_port);
sa.sin_family = AF_INET;
if ((mldonkey_sock = socket(PF_INET, SOCK_STREAM, 0)) < 0) {
ERR("Opening socket");
close_sock();
return -1;
}
if ((mldonkey_sock = socket(PF_INET, SOCK_STREAM, 0)) < 0) {
ERR("Opening socket");
close_sock();
return -1;
}
if( connect(mldonkey_sock, (struct sockaddr *) &sa, sizeof(sa)) < 0) {
if (errno != EAGAIN &&
errno != EINTR &&
errno != EINPROGRESS &&
errno != EWOULDBLOCK) {
if (connect
(mldonkey_sock, (struct sockaddr *) &sa,
sizeof(sa)) < 0) {
if (errno != EAGAIN && errno != EINTR
&& errno != EINPROGRESS
&& errno != EWOULDBLOCK) {
// ERR("Connection failed");
close_sock();
return -1;
}
}
close_sock();
return -1;
}
}
retcode = fcntl(mldonkey_sock, F_GETFL, 0);
if (retcode == -1 ||
fcntl(mldonkey_sock, F_SETFL, retcode | O_NONBLOCK) == -1){
return -1;
}
retcode = fcntl(mldonkey_sock, F_GETFL, 0);
if (retcode == -1 ||
fcntl(mldonkey_sock, F_SETFL,
retcode | O_NONBLOCK) == -1) {
return -1;
}
mldonkey_state = MLDONKEY_CONNECTING;
return 0;
}
mldonkey_state = MLDONKEY_CONNECTING;
return 0;
}
return 0;
return 0;
}
int mldonkey_can_read()
{
return cut_messages(0);
return cut_messages(0);
}
int mldonkey_info_message(mldonkey_info *info)
int mldonkey_info_message(mldonkey_info * info)
{
int opcode = read_int16();
int opcode = read_int16();
switch(opcode){
switch (opcode) {
case CoreProtocol :
init_message();
case CoreProtocol:
init_message();
write_int16(0); /* GUI protocol */
write_int32(10); /* Version 10 ! */
write_message("GuiProtocol");
write_int16(0); /* GUI protocol */
write_int32(10); /* Version 10 ! */
write_message("GuiProtocol");
write_int16(47); /* GUI protocol */
write_int16(47); /* GUI protocol */
write_int16(1);
write_int32(1);
write_int8(1);
write_message("GuiExtensions");
write_int16(1);
write_int32(1);
write_int8(1);
write_message("GuiExtensions");
init_message();
write_int16(5); /* Password */
write_string(old_config->mldonkey_password);
write_message("Password");
init_message();
write_int16(5); /* Password */
write_string(old_config->mldonkey_password);
write_message("Password");
break;
break;
case BadPassword :
ERR("Bad Password\n");
close_sock();
break;
case BadPassword:
ERR("Bad Password\n");
close_sock();
break;
case Client_stats:
case Client_stats_v2:
case Client_stats_v3:
ERR("Client stats format too old...\n");
break;
case Client_stats:
case Client_stats_v2:
case Client_stats_v3:
ERR("Client stats format too old...\n");
break;
case Client_stats_v4:
mldonkey_state = MLDONKEY_CONNECTED;
case Client_stats_v4:
mldonkey_state = MLDONKEY_CONNECTED;
info->upload_counter = read_int64();
info->download_counter = read_int64();
info->shared_counter = read_int64();
info->nshared_files = read_int32();
info->tcp_upload_rate = read_int32();
info->tcp_download_rate = read_int32();
info->udp_upload_rate = read_int32();
info->udp_download_rate = read_int32();
info->ndownloading_files = read_int32();
info->ndownloaded_files = read_int32();
info->upload_counter = read_int64();
info->download_counter = read_int64();
info->shared_counter = read_int64();
info->nshared_files = read_int32();
info->tcp_upload_rate = read_int32();
info->tcp_download_rate = read_int32();
info->udp_upload_rate = read_int32();
info->udp_download_rate = read_int32();
info->ndownloading_files = read_int32();
info->ndownloaded_files = read_int32();
break;
}
break;
}
return 0;
return 0;
}
int get_mldonkey_status(mldonkey_config *config, mldonkey_info *info)
int get_mldonkey_status(mldonkey_config * config, mldonkey_info * info)
{
if( mldonkey_connect(config) >= 0){
while(mldonkey_can_read() > 0){
mldonkey_info_message(info);
}
}
return mldonkey_state;
if (mldonkey_connect(config) >= 0) {
while (mldonkey_can_read() > 0) {
mldonkey_info_message(info);
}
}
return mldonkey_state;
}

77
mpd.c
View File

@ -14,65 +14,74 @@ void update_mpd()
if (current_info->conn->error) {
//fprintf(stderr, "%s\n", current_info->conn->errorStr);
mpd_closeConnection(current_info->conn);
if(current_info->mpd.artist == NULL)
current_info->mpd.artist = malloc(TEXT_BUFFER_SIZE);
if(current_info->mpd.album == NULL)
if (current_info->mpd.artist == NULL)
current_info->mpd.artist =
malloc(TEXT_BUFFER_SIZE);
if (current_info->mpd.album == NULL)
current_info->mpd.album = malloc(TEXT_BUFFER_SIZE);
if(current_info->mpd.title == NULL)
if (current_info->mpd.title == NULL)
current_info->mpd.title = malloc(TEXT_BUFFER_SIZE);
strcpy(current_info->mpd.artist, "Unknown");
strcpy(current_info->mpd.album, "Unknown");
strcpy(current_info->mpd.title, "Unknown");
current_info->mpd.status = "MPD not responding";
current_info->mpd.bitrate = 0;
current_info->mpd.progress = 0;
current_info->mpd.elapsed = 0;
current_info->mpd.length = 0;
return;
}
mpd_Status * status;
mpd_Status *status;
mpd_InfoEntity *entity;
mpd_sendCommandListOkBegin(current_info->conn);
mpd_sendStatusCommand(current_info->conn);
mpd_sendCurrentSongCommand(current_info->conn);
mpd_sendCommandListEnd(current_info->conn);
if ((status = mpd_getStatus(current_info->conn)) == NULL) {
if ((status = mpd_getStatus(current_info->conn)) == NULL) {
//fprintf(stderr, "%s\n", current_info->conn->errorStr);
mpd_closeConnection(current_info->conn);
if(current_info->mpd.artist == NULL)
current_info->mpd.artist = malloc(TEXT_BUFFER_SIZE);
if(current_info->mpd.album == NULL)
if (current_info->mpd.artist == NULL)
current_info->mpd.artist =
malloc(TEXT_BUFFER_SIZE);
if (current_info->mpd.album == NULL)
current_info->mpd.album = malloc(TEXT_BUFFER_SIZE);
if(current_info->mpd.title == NULL)
if (current_info->mpd.title == NULL)
current_info->mpd.title = malloc(TEXT_BUFFER_SIZE);
strcpy(current_info->mpd.artist, "Unknown");
strcpy(current_info->mpd.album, "Unknown");
strcpy(current_info->mpd.title, "Unknown");
current_info->mpd.status = "MPD not responding";
current_info->mpd.bitrate = 0;
current_info->mpd.progress = 0;
current_info->mpd.elapsed = 0;
current_info->mpd.length = 0;
return;
}
current_info->mpd.volume = status->volume;
//if (status->error)
//printf("error: %s\n", status->error);
//printf("error: %s\n", status->error);
if(status->state == MPD_STATUS_STATE_PLAY)
{
if (status->state == MPD_STATUS_STATE_PLAY) {
current_info->mpd.status = "Playing";
}
if(status->state == MPD_STATUS_STATE_STOP)
{
if (status->state == MPD_STATUS_STATE_STOP) {
current_info->mpd.status = "Stopped";
}
if(status->state == MPD_STATUS_STATE_PAUSE)
{
if (status->state == MPD_STATUS_STATE_PAUSE) {
current_info->mpd.status = "Paused";
}
if(status->state == MPD_STATUS_STATE_UNKNOWN)
{
if (status->state == MPD_STATUS_STATE_UNKNOWN) {
current_info->mpd.status = "Unknown";
}
if(status->state == MPD_STATUS_STATE_PLAY ||
status->state == MPD_STATUS_STATE_PAUSE) {
if (status->state == MPD_STATUS_STATE_PLAY ||
status->state == MPD_STATUS_STATE_PAUSE) {
current_info->mpd.bitrate = status->bitRate;
current_info->mpd.progress = (float)status->elapsedTime/status->totalTime;
}
current_info->mpd.progress =
(float) status->elapsedTime / status->totalTime;
current_info->mpd.elapsed = status->elapsedTime;
current_info->mpd.length = status->totalTime;
}
if (current_info->conn->error) {
@ -84,34 +93,32 @@ void update_mpd()
mpd_nextListOkCommand(current_info->conn);
while ((entity = mpd_getNextInfoEntity(current_info->conn))) {
mpd_Song * song = entity->info.song;
mpd_Song *song = entity->info.song;
if (entity->type != MPD_INFO_ENTITY_TYPE_SONG) {
mpd_freeInfoEntity(entity);
continue;
}
if(current_info->mpd.artist == NULL)
current_info->mpd.artist = malloc(TEXT_BUFFER_SIZE);
if(current_info->mpd.album == NULL)
if (current_info->mpd.artist == NULL)
current_info->mpd.artist =
malloc(TEXT_BUFFER_SIZE);
if (current_info->mpd.album == NULL)
current_info->mpd.album = malloc(TEXT_BUFFER_SIZE);
if(current_info->mpd.title == NULL)
if (current_info->mpd.title == NULL)
current_info->mpd.title = malloc(TEXT_BUFFER_SIZE);
if (song->artist) {
strcpy(current_info->mpd.artist, song->artist);
}
else {
} else {
strcpy(current_info->mpd.artist, "Unknown");
}
if (song->album) {
strcpy(current_info->mpd.album, song->album);
}
else {
} else {
strcpy(current_info->mpd.album, "Unknown");
}
if (song->title) {
strcpy(current_info->mpd.title, song->title);
}
else {
} else {
strcpy(current_info->mpd.title, "Unknown");
}
if (entity != NULL) {
@ -121,7 +128,7 @@ void update_mpd()
if (entity != NULL) {
mpd_freeInfoEntity(entity);
}
if (current_info->conn->error) {
//fprintf(stderr, "%s\n", current_info->conn->errorStr);
mpd_closeConnection(current_info->conn);

188
top.c
View File

@ -25,8 +25,8 @@ static struct process *new_process(int p)
process = malloc(sizeof(struct process));
/*
* Do stitching necessary for doubly linked list
*/
* Do stitching necessary for doubly linked list
*/
process->name = 0;
process->previous = 0;
process->next = first_process;
@ -40,7 +40,7 @@ static struct process *new_process(int p)
process->previous_kernel_time = INT_MAX;
process->counted = 1;
/* process_find_name(process);*/
/* process_find_name(process); */
return process;
}
@ -86,13 +86,13 @@ static int process_parse_stat(struct process *process)
ps = open(filename, O_RDONLY);
if (ps < 0)
/*
* The process must have finished in the last few jiffies!
*/
* The process must have finished in the last few jiffies!
*/
return 1;
/*
* Mark process as up-to-date.
*/
* Mark process as up-to-date.
*/
process->time_stamp = g_time;
rc = read(ps, line, sizeof(line));
@ -101,8 +101,8 @@ static int process_parse_stat(struct process *process)
return 1;
/*
* Extract cpu times from data in /proc filesystem
*/
* Extract cpu times from data in /proc filesystem
*/
rc = sscanf(line,
"%*s %s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %d %d %*s %*s %*s %d %*s %*s %*s %d %d",
procname, &process->user_time, &process->kernel_time,
@ -110,8 +110,8 @@ static int process_parse_stat(struct process *process)
if (rc < 5)
return 1;
/*
* Remove parentheses from the process name stored in /proc/ under Linux...
*/
* Remove parentheses from the process name stored in /proc/ under Linux...
*/
r = procname + 1;
/* remove any "kdeinit: " */
if (r == strstr(r, "kdeinit")) {
@ -121,8 +121,8 @@ static int process_parse_stat(struct process *process)
ps = open(filename, O_RDONLY);
if (ps < 0)
/*
* The process must have finished in the last few jiffies!
*/
* The process must have finished in the last few jiffies!
*/
return 1;
endl = read(ps, line, sizeof(line));
@ -147,16 +147,16 @@ static int process_parse_stat(struct process *process)
*q++ = *r++;
*q = 0;
}
if (process->name)
free(process->name);
process->name = strdup(deparenthesised_name);
process->rss *= getpagesize();
if(!cur->memmax)
if (!cur->memmax)
update_total_processes();
process->totalmem = ( (float) process->rss / cur->memmax ) / 10;
process->totalmem = ((float) process->rss / cur->memmax) / 10;
if (process->previous_user_time == INT_MAX)
process->previous_user_time = process->user_time;
@ -194,15 +194,15 @@ static int update_process_table()
++g_time;
/*
* Get list of processes from /proc directory
*/
* Get list of processes from /proc directory
*/
while ((entry = readdir(dir))) {
pid_t pid;
if (!entry) {
/*
* Problem reading list of processes
*/
* Problem reading list of processes
*/
closedir(dir);
return 1;
}
@ -240,14 +240,14 @@ static int calculate_cpu(struct process *process)
if (rc)
return 1;
/*rc = process_parse_statm(process);
if (rc)
return 1;*/
if (rc)
return 1; */
/*
* Check name against the exclusion list
*/
* Check name against the exclusion list
*/
if (process->counted && exclusion_expression
&& !regexec(exclusion_expression, process->name, 0, 0, 0))
&& !regexec(exclusion_expression, process->name, 0, 0, 0))
process->counted = 0;
return 0;
@ -270,8 +270,8 @@ static void process_cleanup()
p = p->next;
/*
* Delete processes that have died
*/
* Delete processes that have died
*/
if (current->time_stamp != g_time)
delete_process(current);
}
@ -287,14 +287,14 @@ static void delete_process(struct process *p)
assert(p->id == 0x0badfeed);
/*
* Ensure that deleted processes aren't reused.
*/
* Ensure that deleted processes aren't reused.
*/
p->id = 0x007babe;
#endif /* defined(PARANOID) */
/*
* Maintain doubly linked list.
*/
* Maintain doubly linked list.
*/
if (p->next)
p->next->previous = p->previous;
if (p->previous)
@ -345,9 +345,10 @@ inline static void calc_cpu_each(int total)
struct process *p = first_process;
while (p) {
/*p->amount = total ?
(100.0 * (float) (p->user_time + p->kernel_time) /
total) : 0;*/
p->amount = (100.0 * (p->user_time + p->kernel_time) / total);
(100.0 * (float) (p->user_time + p->kernel_time) /
total) : 0; */
p->amount =
(100.0 * (p->user_time + p->kernel_time) / total);
/* if (p->amount > 100)
p->amount = 0;*/
@ -370,7 +371,7 @@ inline void process_find_top(struct process **cpu, struct process **mem)
{
struct process *pr;
if (sorttmp == NULL) {
sorttmp = malloc(sizeof(struct process)*sorttmp_size);
sorttmp = malloc(sizeof(struct process) * sorttmp_size);
assert(sorttmp != NULL);
}
int total;
@ -383,64 +384,64 @@ inline void process_find_top(struct process **cpu, struct process **mem)
process_cleanup(); /* cleanup list from exited processes */
/*
* this is really ugly,
* not to mention probably not too efficient.
* the main problem is that there could be any number of processes,
* however we have to use a fixed size for the "best" array.
* right now i can't think of a better way to do this,
* although i'm sure there is one.
* Perhaps just using a linked list would be more effecient?
* I'm too fucking lazy to do that right now.
*/
if(top_cpu) {
* this is really ugly,
* not to mention probably not too efficient.
* the main problem is that there could be any number of processes,
* however we have to use a fixed size for the "best" array.
* right now i can't think of a better way to do this,
* although i'm sure there is one.
* Perhaps just using a linked list would be more effecient?
* I'm too fucking lazy to do that right now.
*/
if (top_cpu) {
pr = first_process;
i = 0;
while(pr) {
if(i<sorttmp_size && pr->counted) {
while (pr) {
if (i < sorttmp_size && pr->counted) {
sorttmp[i] = pr;
i++;
}
else if (i == sorttmp_size && pr->counted) {
} else if (i == sorttmp_size && pr->counted) {
sorttmp_size++;
sorttmp = realloc(sorttmp, sizeof(struct process)*sorttmp_size);
sorttmp =
realloc(sorttmp,
sizeof(struct process) *
sorttmp_size);
sorttmp[i] = pr;
i++;
}
pr = pr->next;
}
if (i+1 < sorttmp_size) {
sorttmp = realloc(sorttmp, sizeof(struct process)*sorttmp_size);
if (i + 1 < sorttmp_size) {
sorttmp =
realloc(sorttmp,
sizeof(struct process) * sorttmp_size);
}
max = i;
for(i=0;i<max-1;i++)
{
while (sorttmp[i+1]->amount > sorttmp[i]->amount)
{
for (i = 0; i < max - 1; i++) {
while (sorttmp[i + 1]->amount > sorttmp[i]->amount) {
pr = sorttmp[i];
sorttmp[i] = sorttmp[i+1];
sorttmp[i+1] = pr;
if (i>0)
sorttmp[i] = sorttmp[i + 1];
sorttmp[i + 1] = pr;
if (i > 0)
i--;
else
break;
}
}
for(i=max;i>1;i--);
for (i = max; i > 1; i--);
{
while (sorttmp[i]->amount > sorttmp[i-1]->amount)
{
while (sorttmp[i]->amount > sorttmp[i - 1]->amount) {
pr = sorttmp[i];
sorttmp[i] = sorttmp[i-1];
sorttmp[i-1] = pr;
if (i<max)
sorttmp[i] = sorttmp[i - 1];
sorttmp[i - 1] = pr;
if (i < max)
i++;
else
break;
}
}
for(i=0;i<10;i++)
{
for (i = 0; i < 10; i++) {
cpu[i] = sorttmp[i];
}
@ -448,51 +449,54 @@ inline void process_find_top(struct process **cpu, struct process **mem)
if (top_mem) {
pr = first_process;
i = 0;
while(pr) {
if(i<sorttmp_size && pr->counted) {
while (pr) {
if (i < sorttmp_size && pr->counted) {
sorttmp[i] = pr;
i++;
}
else if (i == sorttmp_size && pr->counted) {
} else if (i == sorttmp_size && pr->counted) {
sorttmp_size++;
sorttmp = realloc(sorttmp, sizeof(struct process)*sorttmp_size);
sorttmp =
realloc(sorttmp,
sizeof(struct process) *
sorttmp_size);
sorttmp[i] = pr;
i++;
}
pr = pr->next;
}
if (i+1 < sorttmp_size) {
sorttmp = realloc(sorttmp, sizeof(struct process)*sorttmp_size);
} max = i;
for(i=0;i<max-1;i++)
{
while (sorttmp[i+1]->totalmem > sorttmp[i]->totalmem)
{
if (i + 1 < sorttmp_size) {
sorttmp =
realloc(sorttmp,
sizeof(struct process) * sorttmp_size);
}
max = i;
for (i = 0; i < max - 1; i++) {
while (sorttmp[i + 1]->totalmem >
sorttmp[i]->totalmem) {
pr = sorttmp[i];
sorttmp[i] = sorttmp[i+1];
sorttmp[i+1] = pr;
if (i>0)
sorttmp[i] = sorttmp[i + 1];
sorttmp[i + 1] = pr;
if (i > 0)
i--;
else
break;
}
}
for(i=max;i>1;i--);
for (i = max; i > 1; i--);
{
while (sorttmp[i]->totalmem > sorttmp[i-1]->totalmem)
{
while (sorttmp[i]->totalmem >
sorttmp[i - 1]->totalmem) {
pr = sorttmp[i];
sorttmp[i] = sorttmp[i-1];
sorttmp[i-1] = pr;
if (i<max)
sorttmp[i] = sorttmp[i - 1];
sorttmp[i - 1] = pr;
if (i < max)
i++;
else
break;
}
}
for(i=0;i<10;i++)
{
for (i = 0; i < 10; i++) {
mem[i] = sorttmp[i];
}

9
x11.c
View File

@ -311,11 +311,12 @@ static Window find_subwindow(Window win, int w, int h)
long get_x11_color(const char *name)
{
XColor color;
XColor color;
color.pixel = 0;
if (!XParseColor(display, DefaultColormap(display, screen), name, &color)) {
ERR("can't parse X color '%s'", name);
return 0xFF00FF;
if (!XParseColor
(display, DefaultColormap(display, screen), name, &color)) {
ERR("can't parse X color '%s'", name);
return 0xFF00FF;
}
if (!XAllocColor
(display, DefaultColormap(display, screen), &color))