wmSMPmon: Code formating cleanup

This commit is contained in:
Milan Čermák 2013-01-19 10:17:30 +01:00 committed by Carlos R. Mafra
parent cb8524e80a
commit d914561f0c
5 changed files with 601 additions and 615 deletions

View file

@ -23,7 +23,8 @@ void bye_bye (int eno, const char *str)
{ {
fflush(stdout); fflush(stdout);
if (str) { if (str) {
if (eno) perror(str); if (eno)
perror(str);
else { else {
fputs(str, stderr); fputs(str, stderr);
eno = 1; eno = 1;
@ -43,10 +44,9 @@ const char *fmtmk (const char *fmts, ...)
va_start(va, fmts); va_start(va, fmts);
vsnprintf(buf, sizeof(buf), fmts, va); vsnprintf(buf, sizeof(buf), fmts, va);
va_end(va); va_end(va);
return (const char *)buf; return ((const char *)buf);
} }
/* /*
* Standard error handler to normalize the look of all err o/p */ * Standard error handler to normalize the look of all err o/p */
void std_err(const char *str) void std_err(const char *str)
@ -71,8 +71,9 @@ void *alloc_c (unsigned numb)
{ {
void * p; void * p;
if (!numb) ++numb; if (!numb)
++numb;
if (!(p = calloc(1, numb))) if (!(p = calloc(1, numb)))
std_err("failed memory allocate"); std_err("failed memory allocate");
return p; return (p);
} }

View file

@ -83,18 +83,17 @@ unsigned int NumCpus_DoInit(void)
if (linux_version_code > LINUX_VERSION(2, 5, 41)) if (linux_version_code > LINUX_VERSION(2, 5, 41))
States_fmts = STATES_line2x5; States_fmts = STATES_line2x5;
if (linux_version_code >= LINUX_VERSION(2, 6, 0)) // grrr... only if (linux_version_code >= LINUX_VERSION(2, 6, 0)) {
// some 2.6.0-testX :-( // grrr... only some 2.6.0-testX :-(
States_fmts = STATES_line2x6; States_fmts = STATES_line2x6;
}
smp_num_cpus = sysconf(_SC_NPROCESSORS_CONF); // or _SC_NPROCESSORS_ONLN smp_num_cpus = sysconf(_SC_NPROCESSORS_CONF); // or _SC_NPROCESSORS_ONLN
if (smp_num_cpus < 1) if (smp_num_cpus < 1) {
{
smp_num_cpus = 1; /* SPARC glibc is buggy */ smp_num_cpus = 1; /* SPARC glibc is buggy */
} }
if (smp_num_cpus > 255) if (smp_num_cpus > 255) {
{
/* we don't support more than 255 CPUs (well, in fact no more /* we don't support more than 255 CPUs (well, in fact no more
than two ate the moment... */ than two ate the moment... */
smp_num_cpus = 255; smp_num_cpus = 255;
@ -119,8 +118,10 @@ typedef struct mem_table_struct {
unsigned long *slot; /* slot in return struct */ unsigned long *slot; /* slot in return struct */
} mem_table_struct; } mem_table_struct;
static int compare_mem_table_structs(const void *a, const void *b){ static int compare_mem_table_structs(const void *a, const void *b)
return strcmp(((const mem_table_struct*)a)->name,((const mem_table_struct*)b)->name); {
return strcmp(((const mem_table_struct *) a)->name,
((const mem_table_struct *) b)->name);
} }
/* example data, following junk, with comments added: /* example data, following junk, with comments added:
@ -189,7 +190,8 @@ unsigned long kb_inactive;
unsigned long kb_mapped; unsigned long kb_mapped;
unsigned long kb_pagetables; unsigned long kb_pagetables;
static void meminfo(void){ static void meminfo(void)
{
char namebuf[16]; /* big enough to hold any row name */ char namebuf[16]; /* big enough to hold any row name */
mem_table_struct findme = { namebuf, NULL}; mem_table_struct findme = { namebuf, NULL};
mem_table_struct *found; mem_table_struct *found;
@ -225,7 +227,8 @@ static void meminfo(void){
{"Writeback", &kb_writeback}, // kB version of vmstat {"Writeback", &kb_writeback}, // kB version of vmstat
// nr_writeback // nr_writeback
}; };
const int mem_table_count = sizeof(mem_table)/sizeof(mem_table_struct); const int mem_table_count =
sizeof(mem_table) / sizeof(mem_table_struct);
FILE_TO_BUF(MEMINFO_FILE,meminfo_fd); FILE_TO_BUF(MEMINFO_FILE,meminfo_fd);
@ -234,7 +237,8 @@ static void meminfo(void){
head = buf; head = buf;
for(;;) { for(;;) {
tail = strchr(head, ':'); tail = strchr(head, ':');
if(!tail) break; if (!tail)
break;
*tail = '\0'; *tail = '\0';
if (strlen(head) >= sizeof(namebuf)) { if (strlen(head) >= sizeof(namebuf)) {
head = tail + 1; head = tail + 1;
@ -242,14 +246,15 @@ static void meminfo(void){
} }
strcpy(namebuf, head); strcpy(namebuf, head);
found = bsearch(&findme, mem_table, mem_table_count, found = bsearch(&findme, mem_table, mem_table_count,
sizeof(mem_table_struct), compare_mem_table_structs sizeof(mem_table_struct), compare_mem_table_structs);
);
head = tail + 1; head = tail + 1;
if(!found) goto nextline; if (!found)
goto nextline;
*(found->slot) = strtoul(head, &tail, 10); *(found->slot) = strtoul(head, &tail, 10);
nextline: nextline:
tail = strchr(head, '\n'); tail = strchr(head, '\n');
if(!tail) break; if (!tail)
break;
head = tail + 1; head = tail + 1;
} }
if (!kb_low_total) { /* low==main except with large-memory support */ if (!kb_low_total) { /* low==main except with large-memory support */
@ -263,7 +268,6 @@ static void meminfo(void){
kb_main_used = kb_main_total - kb_main_free; kb_main_used = kb_main_total - kb_main_free;
} }
/*************************************************************************/ /*************************************************************************/
/* /*
* This guy's modeled on libproc's 'five_cpu_numbers' function except * This guy's modeled on libproc's 'five_cpu_numbers' function except
@ -275,6 +279,7 @@ static CPU_t *cpus_refresh (CPU_t *cpus, unsigned int Cpu_tot)
{ {
static FILE *fp = NULL; static FILE *fp = NULL;
int i; int i;
// enough for a /proc/stat CPU line (not the intr line) // enough for a /proc/stat CPU line (not the intr line)
char buf[SMLBUFSIZ]; char buf[SMLBUFSIZ];
@ -282,7 +287,8 @@ static CPU_t *cpus_refresh (CPU_t *cpus, unsigned int Cpu_tot)
(sorry Linux, but you'll have to close it for us) */ (sorry Linux, but you'll have to close it for us) */
if (!fp) { if (!fp) {
if (!(fp = fopen("/proc/stat", "r"))) if (!(fp = fopen("/proc/stat", "r")))
std_err(fmtmk("Failed /proc/stat open: %s", strerror(errno))); std_err(fmtmk("Failed /proc/stat open: %s",
strerror(errno)));
/* note: we allocate one more CPU_t than Cpu_tot so that the /* note: we allocate one more CPU_t than Cpu_tot so that the
last slot can hold tics representing the /proc/stat cpu last slot can hold tics representing the /proc/stat cpu
summary (the first line read) -- that slot supports our summary (the first line read) -- that slot supports our
@ -293,15 +299,17 @@ static CPU_t *cpus_refresh (CPU_t *cpus, unsigned int Cpu_tot)
fflush(fp); fflush(fp);
// first value the last slot with the cpu summary line // first value the last slot with the cpu summary line
if (!fgets(buf, sizeof(buf), fp)) std_err("failed /proc/stat read"); if (!fgets(buf, sizeof(buf), fp))
std_err("failed /proc/stat read");
cpus[Cpu_tot].x = 0; // FIXME: can't tell by kernel version number cpus[Cpu_tot].x = 0; // FIXME: can't tell by kernel version number
cpus[Cpu_tot].y = 0; // FIXME: can't tell by kernel version number cpus[Cpu_tot].y = 0; // FIXME: can't tell by kernel version number
if (4 > sscanf(buf, CPU_FMTS_JUST1, &cpus[Cpu_tot].u, &cpus[Cpu_tot].n, &cpus[Cpu_tot].s, &cpus[Cpu_tot].i, &cpus[Cpu_tot].w, &cpus[Cpu_tot].x, &cpus[Cpu_tot].y)) if (4 > sscanf(buf, CPU_FMTS_JUST1, &cpus[Cpu_tot].u, &cpus[Cpu_tot].n,
&cpus[Cpu_tot].s, &cpus[Cpu_tot].i, &cpus[Cpu_tot].w,
&cpus[Cpu_tot].x, &cpus[Cpu_tot].y))
std_err("failed /proc/stat read"); std_err("failed /proc/stat read");
// and just in case we're 2.2.xx compiled without SMP support... // and just in case we're 2.2.xx compiled without SMP support...
if (1 == Cpu_tot) if (1 == Cpu_tot) {
{
/* do it "manually", otherwise we overwrite charge and total */ /* do it "manually", otherwise we overwrite charge and total */
cpus[0].u = cpus[1].u; cpus[0].u = cpus[1].u;
cpus[0].n = cpus[1].n; cpus[0].n = cpus[1].n;
@ -312,14 +320,15 @@ static CPU_t *cpus_refresh (CPU_t *cpus, unsigned int Cpu_tot)
cpus[0].y = cpus[1].y; cpus[0].y = cpus[1].y;
} }
// now value each separate cpu's tics // now value each separate cpu's tics
for (i = 0; 1 < Cpu_tot && i < Cpu_tot; i++) { for (i = 0; 1 < Cpu_tot && i < Cpu_tot; i++) {
if (!fgets(buf, sizeof(buf), fp))
if (!fgets(buf, sizeof(buf), fp)) std_err("failed /proc/stat read"); std_err("failed /proc/stat read");
cpus[i].x = 0; // FIXME: can't tell by kernel version number cpus[i].x = 0; // FIXME: can't tell by kernel version number
cpus[i].y = 0; // FIXME: can't tell by kernel version number cpus[i].y = 0; // FIXME: can't tell by kernel version number
if (4 > sscanf(buf, CPU_FMTS_MULTI, &cpus[i].u, &cpus[i].n, &cpus[i].s, &cpus[i].i, &cpus[i].w, &cpus[i].x, &cpus[i].y)) if (4 > sscanf(buf, CPU_FMTS_MULTI, &cpus[i].u,
&cpus[i].n, &cpus[i].s, &cpus[i].i, &cpus[i].w,
&cpus[i].x, &cpus[i].y))
std_err("failed /proc/stat read"); std_err("failed /proc/stat read");
} }
return cpus; return cpus;
@ -333,13 +342,13 @@ unsigned int *Get_CPU_Load(unsigned int *load, unsigned int Cpu_tot)
smpcpu = cpus_refresh(smpcpu, Cpu_tot); smpcpu = cpus_refresh(smpcpu, Cpu_tot);
for(j = 0 ; j < Cpu_tot ; j ++) for (j = 0; j < Cpu_tot; j ++) {
{
charge = smpcpu[j].u + smpcpu[j].s + smpcpu[j].n; charge = smpcpu[j].u + smpcpu[j].s + smpcpu[j].n;
total = charge + smpcpu[j].i; total = charge + smpcpu[j].i;
/* scale cpu to a maximum of HAUTEUR */ /* scale cpu to a maximum of HAUTEUR */
load[j] = ((HAUTEUR * (charge - smpcpu[j].charge)) / (total - smpcpu[j].total + 0.001)) + 1 ; load[j] = ((HAUTEUR * (charge - smpcpu[j].charge)) /
(total - smpcpu[j].total + 0.001)) + 1 ;
smpcpu[j].total = total ; smpcpu[j].total = total ;
smpcpu[j].charge = charge ; smpcpu[j].charge = charge ;
} }
@ -351,14 +360,14 @@ unsigned int Get_Memory(void)
{ {
meminfo(); meminfo();
return (kb_main_used - kb_main_cached) / (kb_main_total / 100) ; return ((kb_main_used - kb_main_cached) / (kb_main_total / 100));
/* should be between 0 and 100 now */ /* should be between 0 and 100 now */
} }
unsigned int Get_Swap(void) unsigned int Get_Swap(void)
{ {
/* returns swap usage as value between 0 and 100 OR 999 if no swap /* returns swap usage as value between 0 and 100
* present */ * OR 999 if no swap present */
meminfo(); meminfo();
return (kb_swap_total == 0 ? 999 : kb_swap_used / (kb_swap_total / 100)); return (kb_swap_total == 0 ? 999 : kb_swap_used / (kb_swap_total / 100));

View file

@ -11,7 +11,8 @@
#define CPU_FMTS_JUST1 "cpu %Lu %Lu %Lu %Lu %Lu %Lu %Lu" #define CPU_FMTS_JUST1 "cpu %Lu %Lu %Lu %Lu %Lu %Lu %Lu"
#define CPU_FMTS_MULTI "cpu%*d %Lu %Lu %Lu %Lu %Lu %Lu %Lu" #define CPU_FMTS_MULTI "cpu%*d %Lu %Lu %Lu %Lu %Lu %Lu %Lu"
/* Summary Lines specially formatted string(s) -- see 'show_special' for syntax details + other cautions. */ /* Summary Lines specially formatted string(s) --
see 'show_special' for syntax details + other cautions. */
#define STATES_line2x4 "%s\03" \ #define STATES_line2x4 "%s\03" \
" %#5.1f%% \02user,\03 %#5.1f%% \02system,\03 %#5.1f%% \02nice,\03 %#5.1f%% \02idle\03\n" " %#5.1f%% \02user,\03 %#5.1f%% \02system,\03 %#5.1f%% \02nice,\03 %#5.1f%% \02idle\03\n"
#define STATES_line2x5 "%s\03" \ #define STATES_line2x5 "%s\03" \
@ -30,4 +31,4 @@ typedef struct CPU_t {
TIC_t charge, total; TIC_t charge, total;
} CPU_t; } CPU_t;
#endif /* SYSINFO_H */ #endif /* LINUX_SYSINFO_H */

View file

@ -1,6 +1,6 @@
/*************************************************************************** /***************************************************************************
wmSMPmon III - Window Maker system monitor wmSMPmon III - Window Maker system monitor
VERSION : 3.1 VERSION : 3.2
DATE : 2005-11-06 DATE : 2005-11-06
ORIGINAL AUTHORS : redseb <redseb@goupilfr.org> and ORIGINAL AUTHORS : redseb <redseb@goupilfr.org> and
PhiR <phir@gcu-squad.org> PhiR <phir@gcu-squad.org>
@ -21,7 +21,6 @@ CURRENT MAINTAINER: Thomas Ribbrock <emgaron@gmx.net>
#include "wmSMPmon_mask.xbm" #include "wmSMPmon_mask.xbm"
#include "general.h" #include "general.h"
#include "standards.h" #include "standards.h"
#include "sysinfo-linux.h"
#define VERSION "3.2" #define VERSION "3.2"
@ -71,52 +70,44 @@ int main(int argc, char **argv)
NumCPUs = NumCpus_DoInit(); NumCPUs = NumCpus_DoInit();
CPU_Load = alloc_c((NumCPUs) * sizeof(int)); CPU_Load = alloc_c((NumCPUs) * sizeof(int));
if(NumCPUs == 1) if(NumCPUs == 1) {
{
load_width = 8; load_width = 8;
} } else {
else
{
load_width = 3; load_width = 3;
} }
Myname = strrchr(argv[0], '/'); Myname = strrchr(argv[0], '/');
if (Myname) ++Myname; else Myname = argv[0]; if (Myname)
++Myname;
else
Myname = argv[0];
/* process command line args */ /* process command line args */
i = 1; /* skip program name (i=0) */ i = 1; /* skip program name (i=0) */
while(argc > i) while (argc > i) {
{ if (!strncmp(argv[i], "-r", 2)) {
if(!strncmp(argv[i], "-r", 2))
{
i++; i++;
if(i == argc) if (i == argc) {
{
/* parameter missing! */ /* parameter missing! */
usage(NumCPUs, "no refresh rate given when using -r!"); usage(NumCPUs,
} "no refresh rate given when using -r!");
else } else {
{
delay = atol(argv[i]) ; delay = atol(argv[i]) ;
} }
i++; i++;
continue; continue;
} }
if(!strncmp(argv[i], "-h", 2)) if (!strncmp(argv[i], "-h", 2)) {
{
usage(NumCPUs, NULL); usage(NumCPUs, NULL);
} }
if(!strncmp(argv[i], "-g", 2) && NumCPUs > 1) if (!strncmp(argv[i], "-g", 2) && NumCPUs > 1) {
{
/* we only support this on SMP systems */ /* we only support this on SMP systems */
i++; i++;
if(i == argc) if (i == argc) {
{
/* parameter missing! */ /* parameter missing! */
usage(NumCPUs, "no graph style given when using -g!"); usage(NumCPUs,
} "no graph style given when using -g!");
else } else {
{
etat = atoi(argv[i]); etat = atoi(argv[i]);
} }
@ -125,8 +116,7 @@ int main(int argc, char **argv)
i++; i++;
continue; continue;
} }
if(!strncmp(argv[i], "-no-swap", 8)) if (!strncmp(argv[i], "-no-swap", 8)) {
{
puts(MSG_NO_SWAP); puts(MSG_NO_SWAP);
no_swap = VRAI; no_swap = VRAI;
i++; i++;
@ -138,23 +128,22 @@ int main(int argc, char **argv)
} }
/* open initial window */ /* open initial window */
if(NumCPUs == 1) if (NumCPUs == 1) {
{
/* we only have a single CPU - change the mask accordingly /* we only have a single CPU - change the mask accordingly
NOTE: The for loop was derived from the differences between * NOTE: The for loop was derived from the differences between
wmSMPmon_mask.xbm and wmSMPmon_mask-single.xbm. * wmSMPmon_mask.xbm and wmSMPmon_mask-single.xbm.
wmSMPmon_mask-single.xbm as such is NOT used in this * wmSMPmon_mask-single.xbm as such is NOT used in this
program! */ * program!
for (i = 33; i <= 289; i = i+8) */
{ for (i = 33; i <= 289; i = i+8) {
wmSMPmon_mask_bits[i] = 0xDF; wmSMPmon_mask_bits[i] = 0xDF;
} }
} }
openXwindow(argc,argv,wmSMPmon_master_xpm,wmSMPmon_mask_bits,wmSMPmon_mask_width,wmSMPmon_mask_height) ; openXwindow(argc, argv, wmSMPmon_master_xpm, wmSMPmon_mask_bits,
wmSMPmon_mask_width, wmSMPmon_mask_height);
if(NumCPUs >= 2) if(NumCPUs >= 2) {
{
/* we have two CPUs -> draw separator between CPU load bars */ /* we have two CPUs -> draw separator between CPU load bars */
copyXPMArea(12, 4, 2, HAUTEUR + 2, 7, 4); copyXPMArea(12, 4, 2, HAUTEUR + 2, 7, 4);
} }
@ -172,10 +161,8 @@ int main(int argc, char **argv)
copyXPMArea(60, 63, 60, 10, 6, 50); copyXPMArea(60, 63, 60, 10, 6, 50);
/* MAIN LOOP */ /* MAIN LOOP */
while(VRAI) while (VRAI) {
{ if (lecture) {
if(lecture)
{
CPU_Load = Get_CPU_Load(CPU_Load, NumCPUs); CPU_Load = Get_CPU_Load(CPU_Load, NumCPUs);
load = CPU_Load[0]; load = CPU_Load[0];
@ -184,17 +171,16 @@ int main(int argc, char **argv)
} }
load = load / i; load = load / i;
load0t = load0t + load; load0t = load0t + load;
if(load != load0o) if (load != load0o) {
{
/* redraw only if cpu load changed */ /* redraw only if cpu load changed */
delta = HAUTEUR - load; delta = HAUTEUR - load;
copyXPMArea(108, 0, load_width, HAUTEUR, 4, 5); copyXPMArea(108, 0, load_width, HAUTEUR, 4, 5);
copyXPMArea(108, delta + 32, load_width, load, 4, 5 + delta) ; copyXPMArea(108, delta + 32, load_width, load,
4, 5 + delta);
load0o = load; load0o = load;
} }
if(NumCPUs >= 2) if (NumCPUs >= 2) {
{
/* we have two CPUs -> do CPU 1 */ /* we have two CPUs -> do CPU 1 */
load = 0; load = 0;
for (; i < NumCPUs; i++) { for (; i < NumCPUs; i++) {
@ -202,47 +188,42 @@ int main(int argc, char **argv)
} }
load = load / (NumCPUs >> 1); load = load / (NumCPUs >> 1);
if(load != load1o) if (load != load1o) {
{
/* redraw only if cpu load changed */ /* redraw only if cpu load changed */
delta = HAUTEUR - load; delta = HAUTEUR - load;
copyXPMArea(108, 0, 3, HAUTEUR, 9, 5); copyXPMArea(108, 0, 3, HAUTEUR, 9, 5);
copyXPMArea(108, delta + 32, 3, load, 9, 5 + delta) ; copyXPMArea(108, delta + 32, 3, load,
9, 5 + delta);
load1o = load; load1o = load;
} }
} }
/* we have to set load1t in any case to get the correct /* we have to set load1t in any case to get the correct
graph below. With only one CPU, 'load' will still be * graph below. With only one CPU, 'load' will still be
CPU_Load[0], on a SMP system, it will be CPU_Load[1]. */ * CPU_Load[0], on a SMP system, it will be CPU_Load[1].
*/
load1t = load1t + load; load1t = load1t + load;
if(c1 > DIV1) if (c1 > DIV1) {
{
mem = Get_Memory(); mem = Get_Memory();
if(mem != prec_mem) if (mem != prec_mem) {
{
/* redraw only if mem changed */ /* redraw only if mem changed */
copyXPMArea(30, 63, 30, 8, 29, 39); copyXPMArea(30, 63, 30, 8, 29, 39);
copyXPMArea(0, 63, (mem * 30 / 100), 8, 29, 39) ; copyXPMArea(0, 63, (mem * 30 / 100), 8,
29, 39);
prec_mem = mem; prec_mem = mem;
} }
if(!no_swap) if (!no_swap) {
{
mem = Get_Swap(); mem = Get_Swap();
if(mem != prec_swap) if (mem != prec_swap) {
{
/* redraw if there was a change */ /* redraw if there was a change */
if(mem == 999) if (mem == 999) {
{
/* swap is disabled => show "none" */ /* swap is disabled => show "none" */
copyXPMArea(60, 63, 60, 10, 6, 50); copyXPMArea(60, 63, 60, 10, 6, 50);
} } else {
else
{
/* draw swap usage */ /* draw swap usage */
copyXPMArea(30, 63, 30, 8, 29, 50); copyXPMArea(30, 63, 30, 8, 29, 50);
copyXPMArea(0, 63, (mem * 30 / 100), 8, 29, 50); copyXPMArea(0, 63, (mem * 30 / 100), 8, 29, 50);
@ -268,11 +249,10 @@ int main(int argc, char **argv)
draw_graph = VRAI; draw_graph = VRAI;
c2 = 0; c2 = 0;
} }
if(draw_graph)
{ if (draw_graph) {
/* draw graph */ /* draw graph */
switch(etat) switch (etat) {
{
case 1 : case 1 :
copyXPMArea(64, 32, TAILLE_T, HAUTEUR, 15, 5); copyXPMArea(64, 32, TAILLE_T, HAUTEUR, 15, 5);
for (i = 0, load = t_idx; i < TAILLE_T; i ++, load++) for (i = 0, load = t_idx; i < TAILLE_T; i ++, load++)
@ -300,11 +280,10 @@ int main(int argc, char **argv)
} }
lecture = 1 - lecture ; lecture = 1 - lecture ;
RedrawWindow(); RedrawWindow();
if(NumCPUs >= 2 && XCheckMaskEvent(display, ButtonPressMask, &Event)) if (NumCPUs >= 2 &&
{ XCheckMaskEvent(display, ButtonPressMask, &Event)) {
/* changing graph style not supported on single CPU systems */ /* changing graph style not supported on single CPU systems */
if(Event.type == ButtonPress) if (Event.type == ButtonPress) {
{
if ((etat++) >= 3) if ((etat++) >= 3)
etat = 1; etat = 1;
draw_graph = VRAI; draw_graph = VRAI;
@ -314,32 +293,28 @@ int main(int argc, char **argv)
} }
} }
/*###### Usage Message ##################################################*/ /*###### Usage Message ##################################################*/
void usage(int cpus, const char *str) void usage(int cpus, const char *str)
{ {
fflush(stdout); fflush(stdout);
if (str) if (str) {
{
fprintf(stderr, "\nERROR: %s\n", str); fprintf(stderr, "\nERROR: %s\n", str);
} }
fputs("\nwmSMPmon "VERSION" - display system load (", stderr); fputs("\nwmSMPmon "VERSION" - display system load (", stderr);
if(cpus == 1) if(cpus == 1) {
{
fputs("uniprocessor system)\n\n", stderr); fputs("uniprocessor system)\n\n", stderr);
} } else {
else fputs("multiprocessor system)\n\n", stderr);
{
fputs("(multiprocessor system)\n\n", stderr);
} }
fputs("Options : -h this help screen.\n" fputs("Options : -h this help screen.\n"
" -r RATE refresh rate (in microseconds, default 250000).\n", stderr); " -r RATE refresh rate (in microseconds, default 250000).\n",
stderr);
if(cpus > 1) if(cpus > 1) {
{ fputs(" -g STYLE graph style (try 2 or 3, default is 1).\n",
fputs(" -g STYLE graph style (try 2 or 3, default is 1).\n", stderr); stderr);
} }
fputs(" -no-swap don't monitore swap size.\n\n" fputs(" -no-swap don't monitore swap size.\n\n"
@ -347,7 +322,6 @@ void usage(int cpus, const char *str)
"<phir@gcu-squad.org> http://gcu-squad.org\n" "<phir@gcu-squad.org> http://gcu-squad.org\n"
"<emgaron@gmx.net> http://www.ribbrock.org\n", "<emgaron@gmx.net> http://www.ribbrock.org\n",
stderr); stderr);
exit(OK); exit(OK);
} }

View file

@ -299,9 +299,7 @@ void createXBMfromXPM(char *xbm, char **xpm, int sx, int sy) {
sscanf(*xpm, "%d %d %d %d", &width, &height, &numcol, &depth); sscanf(*xpm, "%d %d %d %d", &width, &height, &numcol, &depth);
for (k = 0; k != depth; k++) {
for (k=0; k!=depth; k++)
{
zero <<=8; zero <<=8;
zero |= xpm[1][k]; zero |= xpm[1][k];
} }
@ -313,8 +311,7 @@ void createXBMfromXPM(char *xbm, char **xpm, int sx, int sy) {
bwrite >>= 1; bwrite >>= 1;
curpixel=0; curpixel=0;
for (k=0; k!=depth; k++) for (k = 0; k != depth; k++) {
{
curpixel <<=8; curpixel <<=8;
curpixel |= xpm[i][j+k]; curpixel |= xpm[i][j+k];
} }
@ -343,10 +340,10 @@ void createXBMfromXPM(char *xbm, char **xpm, int sx, int sy) {
|* dx,dy: first corner of target area *| |* dx,dy: first corner of target area *|
\***************************************************************************/ \***************************************************************************/
void copyXPMArea(int x, int y, int sx, int sy, int dx, int dy) { void copyXPMArea(int x, int y, int sx, int sy, int dx, int dy)
{
XCopyArea(display, wmgen.pixmap, wmgen.pixmap, NormalGC, x, y, sx, sy, dx, dy); XCopyArea(display, wmgen.pixmap, wmgen.pixmap, NormalGC,
x, y, sx, sy, dx, dy);
} }
/***************************************************************************\ /***************************************************************************\
@ -359,9 +356,10 @@ void copyXPMArea(int x, int y, int sx, int sy, int dx, int dy) {
|* dx,dy: first corner of target area *| |* dx,dy: first corner of target area *|
\***************************************************************************/ \***************************************************************************/
void copyXBMArea(int x, int y, int sx, int sy, int dx, int dy) { void copyXBMArea(int x, int y, int sx, int sy, int dx, int dy)
{
XCopyArea(display, wmgen.mask, wmgen.pixmap, NormalGC, x, y, sx, sy, dx, dy); XCopyArea(display, wmgen.mask, wmgen.pixmap, NormalGC,
x, y, sx, sy, dx, dy);
} }
@ -369,8 +367,8 @@ void copyXBMArea(int x, int y, int sx, int sy, int dx, int dy) {
|* setMaskXY *| |* setMaskXY *|
\***************************************************************************/ \***************************************************************************/
void setMaskXY(int x, int y) { void setMaskXY(int x, int y)
{
XShapeCombineMask(display, win, ShapeBounding, x, y, pixmask, ShapeSet); XShapeCombineMask(display, win, ShapeBounding, x, y, pixmask, ShapeSet);
XShapeCombineMask(display, iconwin, ShapeBounding, x, y, pixmask, ShapeSet); XShapeCombineMask(display, iconwin, ShapeBounding, x, y, pixmask, ShapeSet);
} }
@ -427,16 +425,19 @@ void openXwindow(int argc, char *argv[], char *pixmap_bytes[], char *pixmask_bit
fore_pix = GetColor("black"); fore_pix = GetColor("black");
XWMGeometry(display, screen, Geometry, NULL, borderwidth, &mysizehints, XWMGeometry(display, screen, Geometry, NULL, borderwidth, &mysizehints,
&mysizehints.x, &mysizehints.y,&mysizehints.width,&mysizehints.height, &dummy); &mysizehints.x, &mysizehints.y, &mysizehints.width,
&mysizehints.height, &dummy);
mysizehints.width = 64; mysizehints.width = 64;
mysizehints.height = 64; mysizehints.height = 64;
win = XCreateSimpleWindow(display, Root, mysizehints.x, mysizehints.y, win = XCreateSimpleWindow(display, Root, mysizehints.x, mysizehints.y,
mysizehints.width, mysizehints.height, borderwidth, fore_pix, back_pix); mysizehints.width, mysizehints.height, borderwidth,
fore_pix, back_pix);
iconwin = XCreateSimpleWindow(display, win, mysizehints.x, mysizehints.y, iconwin = XCreateSimpleWindow(display, win,
mysizehints.width, mysizehints.height, borderwidth, fore_pix, back_pix); mysizehints.x, mysizehints.y, mysizehints.width, mysizehints.height,
borderwidth, fore_pix, back_pix);
/* Activate hints */ /* Activate hints */
XSetWMNormalHints(display, win, &mysizehints); XSetWMNormalHints(display, win, &mysizehints);