wmmemload: Consistent formatting.
Format the source so as to minimize warnings from checkpatch.pl in the Window Maker source tree.
This commit is contained in:
parent
917d454f0d
commit
ea2cf286ef
|
@ -36,8 +36,8 @@ Bool dockapp_isbrokenwm = False;
|
||||||
/* private */
|
/* private */
|
||||||
static Window window = None;
|
static Window window = None;
|
||||||
static Window icon_window = None;
|
static Window icon_window = None;
|
||||||
static GC gc = NULL;
|
static GC gc;
|
||||||
static int depth = 0;
|
static int depth;
|
||||||
static Atom delete_win;
|
static Atom delete_win;
|
||||||
static int width, height;
|
static int width, height;
|
||||||
static int offset_w, offset_h;
|
static int offset_w, offset_h;
|
||||||
|
@ -78,11 +78,10 @@ dockapp_open_window(char *display_specified, char *appname,
|
||||||
|
|
||||||
/* Create Windows */
|
/* Create Windows */
|
||||||
icon_window = XCreateSimpleWindow(display, root, 0, 0, ww, wh, 0, 0, 0);
|
icon_window = XCreateSimpleWindow(display, root, 0, 0, ww, wh, 0, 0, 0);
|
||||||
if (dockapp_isbrokenwm) {
|
if (dockapp_isbrokenwm)
|
||||||
window = XCreateSimpleWindow(display, root, 0, 0, ww, wh, 0, 0, 0);
|
window = XCreateSimpleWindow(display, root, 0, 0, ww, wh, 0, 0, 0);
|
||||||
} else {
|
else
|
||||||
window = XCreateSimpleWindow(display, root, 0, 0, 1, 1, 0, 0, 0);
|
window = XCreateSimpleWindow(display, root, 0, 0, 1, 1, 0, 0, 0);
|
||||||
}
|
|
||||||
|
|
||||||
/* Set ClassHint */
|
/* Set ClassHint */
|
||||||
classhint = XAllocClassHint();
|
classhint = XAllocClassHint();
|
||||||
|
@ -232,7 +231,7 @@ dockapp_xpm2pixmap(char **data, Pixmap *pixmap, Pixmap *mask,
|
||||||
Pixmap
|
Pixmap
|
||||||
dockapp_XCreatePixmap(int w, int h)
|
dockapp_XCreatePixmap(int w, int h)
|
||||||
{
|
{
|
||||||
return (XCreatePixmap(display, icon_window, w, h, depth));
|
return XCreatePixmap(display, icon_window, w, h, depth);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -352,31 +351,28 @@ dockapp_blendedcolor(char *color_name, int r, int g, int b, float fac)
|
||||||
return color.pixel;
|
return color.pixel;
|
||||||
|
|
||||||
/* red */
|
/* red */
|
||||||
if (color.red + r > 0xffff) {
|
if (color.red + r > 0xffff)
|
||||||
color.red = 0xffff;
|
color.red = 0xffff;
|
||||||
} else if (color.red + r < 0) {
|
else if (color.red + r < 0)
|
||||||
color.red = 0;
|
color.red = 0;
|
||||||
} else {
|
else
|
||||||
color.red = (unsigned short)(fac * color.red + r);
|
color.red = (unsigned short)(fac * color.red + r);
|
||||||
}
|
|
||||||
|
|
||||||
/* green */
|
/* green */
|
||||||
if (color.green + g > 0xffff) {
|
if (color.green + g > 0xffff)
|
||||||
color.green = 0xffff;
|
color.green = 0xffff;
|
||||||
} else if (color.green + g < 0) {
|
else if (color.green + g < 0)
|
||||||
color.green = 0;
|
color.green = 0;
|
||||||
} else {
|
else
|
||||||
color.green = (unsigned short)(fac * color.green + g);
|
color.green = (unsigned short)(fac * color.green + g);
|
||||||
}
|
|
||||||
|
|
||||||
/* blue */
|
/* blue */
|
||||||
if (color.blue + b > 0xffff) {
|
if (color.blue + b > 0xffff)
|
||||||
color.blue = 0xffff;
|
color.blue = 0xffff;
|
||||||
} else if (color.blue + b < 0) {
|
else if (color.blue + b < 0)
|
||||||
color.blue = 0;
|
color.blue = 0;
|
||||||
} else {
|
else
|
||||||
color.blue = (unsigned short)(fac * color.blue + b);
|
color.blue = (unsigned short)(fac * color.blue + b);
|
||||||
}
|
|
||||||
|
|
||||||
color.flags = DoRed | DoGreen | DoBlue;
|
color.flags = DoRed | DoGreen | DoBlue;
|
||||||
|
|
||||||
|
|
|
@ -44,13 +44,13 @@ Pixmap backdrop_off;
|
||||||
Pixmap parts;
|
Pixmap parts;
|
||||||
Pixmap mask;
|
Pixmap mask;
|
||||||
static char *display_name = "";
|
static char *display_name = "";
|
||||||
static char *light_color = NULL; /* back-light color */
|
static char *light_color; /* back-light color */
|
||||||
static unsigned update_interval = 1;
|
static unsigned update_interval = 1;
|
||||||
static light backlight = LIGHTOFF;
|
static light backlight = LIGHTOFF;
|
||||||
|
|
||||||
static struct mem_options mem_opts;
|
static struct mem_options mem_opts;
|
||||||
static int mem_usage = 0;
|
static int mem_usage;
|
||||||
static int swap_usage = 0;
|
static int swap_usage;
|
||||||
static unsigned alarm_mem = 101;
|
static unsigned alarm_mem = 101;
|
||||||
static unsigned alarm_swap = 101;
|
static unsigned alarm_swap = 101;
|
||||||
|
|
||||||
|
@ -78,8 +78,7 @@ int main(int argc, char **argv)
|
||||||
dockapp_open_window(display_name, PACKAGE, SIZE, SIZE, argc, argv);
|
dockapp_open_window(display_name, PACKAGE, SIZE, SIZE, argc, argv);
|
||||||
dockapp_set_eventmask(ButtonPressMask);
|
dockapp_set_eventmask(ButtonPressMask);
|
||||||
|
|
||||||
if(light_color)
|
if (light_color) {
|
||||||
{
|
|
||||||
colors[0].pixel = dockapp_getcolor(light_color);
|
colors[0].pixel = dockapp_getcolor(light_color);
|
||||||
colors[1].pixel = dockapp_blendedcolor(light_color, -24, -24, -24, 1.0);
|
colors[1].pixel = dockapp_blendedcolor(light_color, -24, -24, -24, 1.0);
|
||||||
ncolor = 2;
|
ncolor = 2;
|
||||||
|
@ -89,18 +88,15 @@ int main(int argc, char **argv)
|
||||||
if (dockapp_iswindowed)
|
if (dockapp_iswindowed)
|
||||||
backlight_on_xpm[1] = backlight_off_xpm[1] = WINDOWED_BG;
|
backlight_on_xpm[1] = backlight_off_xpm[1] = WINDOWED_BG;
|
||||||
|
|
||||||
if(!dockapp_xpm2pixmap(backlight_on_xpm, &backdrop_on, &mask, colors, ncolor))
|
if (!dockapp_xpm2pixmap(backlight_on_xpm, &backdrop_on, &mask, colors, ncolor)) {
|
||||||
{
|
|
||||||
fprintf(stderr, "Error initializing backlit background image.\n");
|
fprintf(stderr, "Error initializing backlit background image.\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
if(!dockapp_xpm2pixmap(backlight_off_xpm, &backdrop_off, NULL, NULL, 0))
|
if (!dockapp_xpm2pixmap(backlight_off_xpm, &backdrop_off, NULL, NULL, 0)) {
|
||||||
{
|
|
||||||
fprintf(stderr, "Error initializing background image.\n");
|
fprintf(stderr, "Error initializing background image.\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
if(!dockapp_xpm2pixmap(parts_xpm, &parts, NULL, colors, ncolor))
|
if (!dockapp_xpm2pixmap(parts_xpm, &parts, NULL, colors, ncolor)) {
|
||||||
{
|
|
||||||
fprintf(stderr, "Error initializing parts image.\n");
|
fprintf(stderr, "Error initializing parts image.\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
@ -108,7 +104,8 @@ int main(int argc, char **argv)
|
||||||
/* shape window */
|
/* shape window */
|
||||||
if (!dockapp_iswindowed)
|
if (!dockapp_iswindowed)
|
||||||
dockapp_setshape(mask, 0, 0);
|
dockapp_setshape(mask, 0, 0);
|
||||||
if(mask) XFreePixmap(display, mask);
|
if (mask)
|
||||||
|
XFreePixmap(display, mask);
|
||||||
|
|
||||||
/* pixmap : draw area */
|
/* pixmap : draw area */
|
||||||
pixmap = dockapp_XCreatePixmap(SIZE, SIZE);
|
pixmap = dockapp_XCreatePixmap(SIZE, SIZE);
|
||||||
|
@ -123,22 +120,17 @@ int main(int argc, char **argv)
|
||||||
dockapp_show();
|
dockapp_show();
|
||||||
|
|
||||||
/* Main loop */
|
/* Main loop */
|
||||||
while(1)
|
while (1) {
|
||||||
{
|
if (dockapp_nextevent_or_timeout(&event, update_interval * 1000)) {
|
||||||
if (dockapp_nextevent_or_timeout(&event, update_interval * 1000))
|
|
||||||
{
|
|
||||||
/* Next Event */
|
/* Next Event */
|
||||||
switch(event.type)
|
switch (event.type) {
|
||||||
{
|
|
||||||
case ButtonPress:
|
case ButtonPress:
|
||||||
switch_light();
|
switch_light();
|
||||||
break;
|
break;
|
||||||
default: /* make gcc happy */
|
default: /* make gcc happy */
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
/* Time Out */
|
/* Time Out */
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
@ -157,26 +149,19 @@ static void update(void)
|
||||||
mem_getusage(&mem_usage, &swap_usage, &mem_opts);
|
mem_getusage(&mem_usage, &swap_usage, &mem_opts);
|
||||||
|
|
||||||
/* alarm mode */
|
/* alarm mode */
|
||||||
if(mem_usage >= alarm_mem || swap_usage >= alarm_swap)
|
if (mem_usage >= alarm_mem || swap_usage >= alarm_swap) {
|
||||||
{
|
if (!in_alarm_mode) {
|
||||||
if(!in_alarm_mode)
|
|
||||||
{
|
|
||||||
in_alarm_mode = True;
|
in_alarm_mode = True;
|
||||||
pre_backlight = backlight;
|
pre_backlight = backlight;
|
||||||
}
|
}
|
||||||
if(backlight == LIGHTOFF)
|
if (backlight == LIGHTOFF) {
|
||||||
{
|
|
||||||
switch_light();
|
switch_light();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else
|
if (in_alarm_mode) {
|
||||||
{
|
|
||||||
if(in_alarm_mode)
|
|
||||||
{
|
|
||||||
in_alarm_mode = False;
|
in_alarm_mode = False;
|
||||||
if (backlight != pre_backlight)
|
if (backlight != pre_backlight) {
|
||||||
{
|
|
||||||
switch_light();
|
switch_light();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -200,8 +185,7 @@ static void update(void)
|
||||||
/* called when mouse button pressed */
|
/* called when mouse button pressed */
|
||||||
static void switch_light(void)
|
static void switch_light(void)
|
||||||
{
|
{
|
||||||
switch (backlight)
|
switch (backlight) {
|
||||||
{
|
|
||||||
case LIGHTOFF:
|
case LIGHTOFF:
|
||||||
backlight = LIGHTON;
|
backlight = LIGHTON;
|
||||||
dockapp_copyarea(backdrop_on, pixmap, 0, 0, 58, 58, 0, 0);
|
dockapp_copyarea(backdrop_on, pixmap, 0, 0, 58, 58, 0, 0);
|
||||||
|
@ -226,21 +210,23 @@ static void draw_memdigit(int per)
|
||||||
int v100, v10, v1;
|
int v100, v10, v1;
|
||||||
int y = 0;
|
int y = 0;
|
||||||
|
|
||||||
if (per < 0) per = 0;
|
if (per < 0)
|
||||||
if (per > 100) per = 100;
|
per = 0;
|
||||||
|
if (per > 100)
|
||||||
|
per = 100;
|
||||||
|
|
||||||
v100 = per / 100;
|
v100 = per / 100;
|
||||||
v10 = (per - v100 * 100) / 10;
|
v10 = (per - v100 * 100) / 10;
|
||||||
v1 = (per - v100 * 100 - v10 * 10);
|
v1 = (per - v100 * 100 - v10 * 10);
|
||||||
|
|
||||||
if (backlight == LIGHTON) y = 20;
|
if (backlight == LIGHTON)
|
||||||
|
y = 20;
|
||||||
|
|
||||||
/* draw digit */
|
/* draw digit */
|
||||||
dockapp_copyarea(parts, pixmap, v1 * 10, y, 10, 20, 29, 7);
|
dockapp_copyarea(parts, pixmap, v1 * 10, y, 10, 20, 29, 7);
|
||||||
if (v10 != 0)
|
if (v10 != 0)
|
||||||
dockapp_copyarea(parts, pixmap, v10 * 10, y, 10, 20, 17, 7);
|
dockapp_copyarea(parts, pixmap, v10 * 10, y, 10, 20, 17, 7);
|
||||||
if (v100 == 1)
|
if (v100 == 1) {
|
||||||
{
|
|
||||||
dockapp_copyarea(parts, pixmap, 10, y, 10, 20, 5, 7);
|
dockapp_copyarea(parts, pixmap, 10, y, 10, 20, 5, 7);
|
||||||
dockapp_copyarea(parts, pixmap, 0, y, 10, 20, 17, 7);
|
dockapp_copyarea(parts, pixmap, 0, y, 10, 20, 17, 7);
|
||||||
}
|
}
|
||||||
|
@ -252,21 +238,23 @@ static void draw_swapdigit(int per)
|
||||||
int v100, v10, v1;
|
int v100, v10, v1;
|
||||||
int y = 0;
|
int y = 0;
|
||||||
|
|
||||||
if (per < 0) per = 0;
|
if (per < 0)
|
||||||
if (per > 100) per = 100;
|
per = 0;
|
||||||
|
if (per > 100)
|
||||||
|
per = 100;
|
||||||
|
|
||||||
v100 = per / 100;
|
v100 = per / 100;
|
||||||
v10 = (per - v100 * 100) / 10;
|
v10 = (per - v100 * 100) / 10;
|
||||||
v1 = (per - v100 * 100 - v10 * 10);
|
v1 = (per - v100 * 100 - v10 * 10);
|
||||||
|
|
||||||
if (backlight == LIGHTON) y = 20;
|
if (backlight == LIGHTON)
|
||||||
|
y = 20;
|
||||||
|
|
||||||
/* draw digit */
|
/* draw digit */
|
||||||
dockapp_copyarea(parts, pixmap, v1 * 10, y, 10, 20, 29, 34);
|
dockapp_copyarea(parts, pixmap, v1 * 10, y, 10, 20, 29, 34);
|
||||||
if (v10 != 0)
|
if (v10 != 0)
|
||||||
dockapp_copyarea(parts, pixmap, v10 * 10, y, 10, 20, 17, 34);
|
dockapp_copyarea(parts, pixmap, v10 * 10, y, 10, 20, 17, 34);
|
||||||
if (v100 == 1)
|
if (v100 == 1) {
|
||||||
{
|
|
||||||
dockapp_copyarea(parts, pixmap, 10, y, 10, 20, 5, 34);
|
dockapp_copyarea(parts, pixmap, 10, y, 10, 20, 5, 34);
|
||||||
dockapp_copyarea(parts, pixmap, 0, y, 10, 20, 17, 34);
|
dockapp_copyarea(parts, pixmap, 0, y, 10, 20, 17, 34);
|
||||||
}
|
}
|
||||||
|
@ -276,19 +264,15 @@ static void parse_arguments(int argc, char **argv)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
int integer;
|
int integer;
|
||||||
for (i = 1; i < argc; i++)
|
for (i = 1; i < argc; i++) {
|
||||||
{
|
|
||||||
if (!strcmp(argv[i], "--help") || !strcmp(argv[i], "-h"))
|
if (!strcmp(argv[i], "--help") || !strcmp(argv[i], "-h"))
|
||||||
print_help(argv[0]), exit(0);
|
print_help(argv[0]), exit(0);
|
||||||
else if (!strcmp(argv[i], "--version") || !strcmp(argv[i], "-v"))
|
else if (!strcmp(argv[i], "--version") || !strcmp(argv[i], "-v"))
|
||||||
printf("%s version %s\n", PACKAGE, VERSION), exit(0);
|
printf("%s version %s\n", PACKAGE, VERSION), exit(0);
|
||||||
else if (!strcmp(argv[i], "--display") || !strcmp(argv[i], "-d"))
|
else if (!strcmp(argv[i], "--display") || !strcmp(argv[i], "-d")) {
|
||||||
{
|
|
||||||
display_name = argv[i + 1];
|
display_name = argv[i + 1];
|
||||||
i++;
|
i++;
|
||||||
}
|
} else if (!strcmp(argv[i], "--alarm-mem") || !strcmp(argv[i], "-am")) {
|
||||||
else if (!strcmp(argv[i], "--alarm-mem") || !strcmp(argv[i], "-am"))
|
|
||||||
{
|
|
||||||
if (argc == i + 1)
|
if (argc == i + 1)
|
||||||
alarm_mem = 90;
|
alarm_mem = 90;
|
||||||
else if (sscanf(argv[i + 1], "%i", &integer) != 1)
|
else if (sscanf(argv[i + 1], "%i", &integer) != 1)
|
||||||
|
@ -298,9 +282,7 @@ static void parse_arguments(int argc, char **argv)
|
||||||
argv[0], argv[i]), exit(1);
|
argv[0], argv[i]), exit(1);
|
||||||
else
|
else
|
||||||
alarm_mem = integer, i++;
|
alarm_mem = integer, i++;
|
||||||
}
|
} else if (!strcmp(argv[i], "--alarm-swap") || !strcmp(argv[i], "-as")) {
|
||||||
else if (!strcmp(argv[i], "--alarm-swap") || !strcmp(argv[i], "-as"))
|
|
||||||
{
|
|
||||||
if (argc == i + 1)
|
if (argc == i + 1)
|
||||||
alarm_swap = 50;
|
alarm_swap = 50;
|
||||||
else if (sscanf(argv[i + 1], "%i", &integer) != 1)
|
else if (sscanf(argv[i + 1], "%i", &integer) != 1)
|
||||||
|
@ -310,16 +292,12 @@ static void parse_arguments(int argc, char **argv)
|
||||||
argv[0], argv[i]), exit(1);
|
argv[0], argv[i]), exit(1);
|
||||||
else
|
else
|
||||||
alarm_swap = integer, i++;
|
alarm_swap = integer, i++;
|
||||||
}
|
} else if (!strcmp(argv[i], "--backlight") || !strcmp(argv[i], "-bl"))
|
||||||
else if (!strcmp(argv[i], "--backlight") || !strcmp(argv[i], "-bl"))
|
|
||||||
backlight = LIGHTON;
|
backlight = LIGHTON;
|
||||||
else if (!strcmp(argv[i], "--light-color") || !strcmp(argv[i], "-lc"))
|
else if (!strcmp(argv[i], "--light-color") || !strcmp(argv[i], "-lc")) {
|
||||||
{
|
|
||||||
light_color = argv[i + 1];
|
light_color = argv[i + 1];
|
||||||
i++;
|
i++;
|
||||||
}
|
} else if (!strcmp(argv[i], "--interval") || !strcmp(argv[i], "-i")) {
|
||||||
else if (!strcmp(argv[i], "--interval") || !strcmp(argv[i], "-i"))
|
|
||||||
{
|
|
||||||
if (argc == i + 1)
|
if (argc == i + 1)
|
||||||
fprintf(stderr, "%s: error parsing argument for option %s\n",
|
fprintf(stderr, "%s: error parsing argument for option %s\n",
|
||||||
argv[0], argv[i]), exit(1);
|
argv[0], argv[i]), exit(1);
|
||||||
|
@ -331,8 +309,7 @@ static void parse_arguments(int argc, char **argv)
|
||||||
argv[0], argv[i]), exit(1);
|
argv[0], argv[i]), exit(1);
|
||||||
update_interval = integer;
|
update_interval = integer;
|
||||||
i++;
|
i++;
|
||||||
}
|
} else if (!strcmp(argv[i], "--windowed") || !strcmp(argv[i], "-w"))
|
||||||
else if (!strcmp(argv[i], "--windowed") || !strcmp(argv[i], "-w"))
|
|
||||||
dockapp_iswindowed = True;
|
dockapp_iswindowed = True;
|
||||||
else if (!strcmp(argv[i], "--broken-wm") || !strcmp(argv[i], "-bw"))
|
else if (!strcmp(argv[i], "--broken-wm") || !strcmp(argv[i], "-bw"))
|
||||||
dockapp_isbrokenwm = True;
|
dockapp_isbrokenwm = True;
|
||||||
|
@ -348,14 +325,12 @@ static void parse_arguments(int argc, char **argv)
|
||||||
else if (!strcmp(argv[i], "--ignore-wired") || !strcmp(argv[i], "-wr"))
|
else if (!strcmp(argv[i], "--ignore-wired") || !strcmp(argv[i], "-wr"))
|
||||||
mem_opts.ignore_wired = True;
|
mem_opts.ignore_wired = True;
|
||||||
#endif
|
#endif
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
fprintf(stderr, "%s: unrecognized option '%s'\n", argv[0], argv[i]);
|
fprintf(stderr, "%s: unrecognized option '%s'\n", argv[0], argv[i]);
|
||||||
print_help(argv[0]), exit(1);
|
print_help(argv[0]), exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (alarm_mem != 101 && alarm_swap != 101)
|
if (alarm_mem != 101 && alarm_swap != 101) {
|
||||||
{
|
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"%s: select either '-am, --alarm-mem' or '-as, --alarm-swap'\n",
|
"%s: select either '-am, --alarm-mem' or '-as, --alarm-swap'\n",
|
||||||
argv[0]);
|
argv[0]);
|
||||||
|
|
|
@ -32,7 +32,7 @@
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
# define INLINE_STATIC static
|
# define INLINE_STATIC static
|
||||||
#else
|
#else
|
||||||
# define INLINE_STATIC inline static
|
# define INLINE_STATIC static inline
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* initialize function */
|
/* initialize function */
|
||||||
|
@ -50,21 +50,25 @@ void mem_init(void)
|
||||||
|
|
||||||
INLINE_STATIC char *skip_line(const char *p)
|
INLINE_STATIC char *skip_line(const char *p)
|
||||||
{
|
{
|
||||||
while (*p != '\n') p++;
|
while (*p != '\n')
|
||||||
|
p++;
|
||||||
return (char *) ++p;
|
return (char *) ++p;
|
||||||
}
|
}
|
||||||
|
|
||||||
INLINE_STATIC char *skip_token(const char *p)
|
INLINE_STATIC char *skip_token(const char *p)
|
||||||
{
|
{
|
||||||
while (isspace(*p)) p++;
|
while (isspace(*p))
|
||||||
while (*p && !isspace(*p)) p++;
|
p++;
|
||||||
|
while (*p && !isspace(*p))
|
||||||
|
p++;
|
||||||
return (char *)p;
|
return (char *)p;
|
||||||
}
|
}
|
||||||
|
|
||||||
INLINE_STATIC char *skip_multiple_token(const char *p, int count)
|
INLINE_STATIC char *skip_multiple_token(const char *p, int count)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
for (i = 0; i < count; i++) p = skip_token (p);
|
for (i = 0; i < count; i++)
|
||||||
|
p = skip_token(p);
|
||||||
return (char *)p;
|
return (char *)p;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -103,7 +107,8 @@ void mem_getusage(int *per_mem, int *per_swap, const struct mem_options *opts)
|
||||||
/* skip N lines and examine info about swap */
|
/* skip N lines and examine info about swap */
|
||||||
while (isprint(p[0])) {
|
while (isprint(p[0])) {
|
||||||
p = skip_line(p);
|
p = skip_line(p);
|
||||||
if (strncmp(p, "SwapTotal", 9) == 0) break;
|
if (strncmp(p, "SwapTotal", 9) == 0)
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
p = skip_token(p);
|
p = skip_token(p);
|
||||||
|
@ -122,11 +127,10 @@ void mem_getusage(int *per_mem, int *per_swap, const struct mem_options *opts)
|
||||||
sused = stotal - sfree;
|
sused = stotal - sfree;
|
||||||
if (opts->ignore_cached)
|
if (opts->ignore_cached)
|
||||||
sused -= scached;
|
sused -= scached;
|
||||||
if (!stotal) {
|
if (!stotal)
|
||||||
*per_swap = 0;
|
*per_swap = 0;
|
||||||
} else {
|
else
|
||||||
*per_swap = 100 * (double) sused / (double) stotal;
|
*per_swap = 100 * (double) sused / (double) stotal;
|
||||||
}
|
|
||||||
|
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
printf("-----------------------\n");
|
printf("-----------------------\n");
|
||||||
|
|
|
@ -28,12 +28,12 @@
|
||||||
#include <sys/utsname.h>
|
#include <sys/utsname.h>
|
||||||
#include "mem.h"
|
#include "mem.h"
|
||||||
|
|
||||||
static int isnewformat = 0; /* for kernel 2.5.1 or later */
|
static int isnewformat; /* for kernel 2.5.1 or later */
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
# define INLINE_STATIC static
|
# define INLINE_STATIC static
|
||||||
#else
|
#else
|
||||||
# define INLINE_STATIC inline static
|
# define INLINE_STATIC static inline
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* initialize function */
|
/* initialize function */
|
||||||
|
@ -49,8 +49,8 @@ void mem_init(void)
|
||||||
|
|
||||||
/* new format ? (kernel >= 2.5.1pre?) */
|
/* new format ? (kernel >= 2.5.1pre?) */
|
||||||
/* see linux/fs/proc/proc_misc.c */
|
/* see linux/fs/proc/proc_misc.c */
|
||||||
if ((version == 2 && patchlevel >= 5 && sublevel >= 1) || \
|
if ((version == 2 && patchlevel >= 5 && sublevel >= 1) ||
|
||||||
(version == 2 && patchlevel >= 6 && sublevel >= 0) || \
|
(version == 2 && patchlevel >= 6 && sublevel >= 0) ||
|
||||||
version > 2)
|
version > 2)
|
||||||
isnewformat = 1;
|
isnewformat = 1;
|
||||||
}
|
}
|
||||||
|
@ -58,21 +58,25 @@ void mem_init(void)
|
||||||
|
|
||||||
INLINE_STATIC char *skip_line(const char *p)
|
INLINE_STATIC char *skip_line(const char *p)
|
||||||
{
|
{
|
||||||
while (*p != '\n') p++;
|
while (*p != '\n')
|
||||||
|
p++;
|
||||||
return (char *) ++p;
|
return (char *) ++p;
|
||||||
}
|
}
|
||||||
|
|
||||||
INLINE_STATIC char *skip_token(const char *p)
|
INLINE_STATIC char *skip_token(const char *p)
|
||||||
{
|
{
|
||||||
while (isspace(*p)) p++;
|
while (isspace(*p))
|
||||||
while (*p && !isspace(*p)) p++;
|
p++;
|
||||||
|
while (*p && !isspace(*p))
|
||||||
|
p++;
|
||||||
return (char *)p;
|
return (char *)p;
|
||||||
}
|
}
|
||||||
|
|
||||||
INLINE_STATIC char *skip_multiple_token(const char *p, int count)
|
INLINE_STATIC char *skip_multiple_token(const char *p, int count)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
for (i = 0; i < count; i++) p = skip_token (p);
|
for (i = 0; i < count; i++)
|
||||||
|
p = skip_token(p);
|
||||||
return (char *)p;
|
return (char *)p;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -111,8 +115,7 @@ void mem_getusage(int *per_mem, int *per_swap, const struct mem_options *opts)
|
||||||
mbuffer = strtoul(p, &p, 0); p = skip_multiple_token(p, 2);
|
mbuffer = strtoul(p, &p, 0); p = skip_multiple_token(p, 2);
|
||||||
mcached = strtoul(p, &p, 0); p = skip_multiple_token(p, 2);
|
mcached = strtoul(p, &p, 0); p = skip_multiple_token(p, 2);
|
||||||
scached = strtoul(p, &p, 0);
|
scached = strtoul(p, &p, 0);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
p = skip_token(p);
|
p = skip_token(p);
|
||||||
/* examine each line of file */
|
/* examine each line of file */
|
||||||
mtotal = strtoul(p, &p, 0); p = skip_multiple_token(p, 2);
|
mtotal = strtoul(p, &p, 0); p = skip_multiple_token(p, 2);
|
||||||
|
@ -127,7 +130,8 @@ void mem_getusage(int *per_mem, int *per_swap, const struct mem_options *opts)
|
||||||
/* kernel-2.4.2:N=8 2.4.16:N=7 */
|
/* kernel-2.4.2:N=8 2.4.16:N=7 */
|
||||||
while (isprint(p[0])) {
|
while (isprint(p[0])) {
|
||||||
p = skip_line(p);
|
p = skip_line(p);
|
||||||
if (strncmp(p, "SwapTotal", 9) == 0) break;
|
if (strncmp(p, "SwapTotal", 9) == 0)
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
p = skip_token(p);
|
p = skip_token(p);
|
||||||
|
@ -146,11 +150,10 @@ void mem_getusage(int *per_mem, int *per_swap, const struct mem_options *opts)
|
||||||
sused = stotal - sfree;
|
sused = stotal - sfree;
|
||||||
if (opts->ignore_cached)
|
if (opts->ignore_cached)
|
||||||
sused -= scached;
|
sused -= scached;
|
||||||
if (!stotal) {
|
if (!stotal)
|
||||||
*per_swap = 0;
|
*per_swap = 0;
|
||||||
} else {
|
else
|
||||||
*per_swap = 100 * (double) sused / (double) stotal;
|
*per_swap = 100 * (double) sused / (double) stotal;
|
||||||
}
|
|
||||||
|
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
printf("-----------------------\n");
|
printf("-----------------------\n");
|
||||||
|
|
|
@ -37,10 +37,12 @@ get_swap_usage(void)
|
||||||
|
|
||||||
stotal = sused = 0;
|
stotal = sused = 0;
|
||||||
|
|
||||||
if ((num_swap = swapctl(SWAP_NSWAP, 0, 0)) == 0)
|
num_swap = swapctl(SWAP_NSWAP, 0, 0);
|
||||||
|
if (num_swap == 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if ((swap_dev = malloc(num_swap * sizeof(*swap_dev))) == NULL)
|
swap_dev = malloc(num_swap * sizeof(*swap_dev));
|
||||||
|
if (swap_dev == NULL)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if (swapctl(SWAP_STATS, swap_dev, num_swap) == -1)
|
if (swapctl(SWAP_STATS, swap_dev, num_swap) == -1)
|
||||||
|
@ -79,7 +81,8 @@ mem_getusage(int *per_mem, int *per_swap, const struct mem_options *opts)
|
||||||
if (vm.t_rm > 0)
|
if (vm.t_rm > 0)
|
||||||
*per_mem = 100 * (double) vm.t_rm / (double) (vm.t_rm + vm.t_free);
|
*per_mem = 100 * (double) vm.t_rm / (double) (vm.t_rm + vm.t_free);
|
||||||
|
|
||||||
if (*per_mem > 97) *per_mem = 100;
|
if (*per_mem > 97)
|
||||||
|
*per_mem = 100;
|
||||||
|
|
||||||
/* swap */
|
/* swap */
|
||||||
*per_swap = get_swap_usage();
|
*per_swap = get_swap_usage();
|
||||||
|
|
Loading…
Reference in a new issue