1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186
|
/*
* Copyright (c) 1998-2000 Albert Dorofeev <albert@tigr.net>
* For the updates see http://www.tigr.net/afterstep/
*
* This software is distributed under GPL. For details see LICENSE file.
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include "safecopy.h"
#include "asmem_x.h"
#include "state.h"
extern struct asmem_state state;
/*
* default check and update intervals in microseconds
* x11 events - every 1/100 th of a second (in mks)
* Memory status - every second (in sec)
*/
#define X11_INTERVAL 10000L
#define CHK_INTERVAL 1
int withdrawn = 0;
int iconic = 0;
int pushed_in = 1;
char display_name[50];
char mainGeometry[50];
void defaults()
{
state.update_interval = CHK_INTERVAL;
state.standard_free = 0;
state.mb = 0;
state.show_used = 0;
safecopy(state.proc_mem_filename, PROC_MEM, 256);
withdrawn = 0;
iconic = 0;
pushed_in = 1;
safecopy(display_name, "", 50);
safecopy(mainGeometry, "", 50);
safecopy(state.bgcolor, "#303030", 50);
safecopy(state.fgcolor, "#20b2aa", 50);
safecopy(state.memory_color, "#4141d7", 50);
safecopy(state.buffer_color, "#aa80aa", 50);
safecopy(state.cache_color, "#bebebe", 50);
safecopy(state.swap_color, "#ffa649", 50);
}
/* print the usage for the tool */
void usage()
{
printf("Usage : asmem [options ...]\n\n");
printf("-V print version and exit\n");
printf("-h -H -help print this message\n");
printf("-u <secs> the update interval in seconds\n");
printf("-mb the display is in MBytes\n");
printf("-used display used memory instead of free\n");
printf("-display <name> the name of the display to use\n");
printf("-position <xy> position on the screen (geometry)\n");
printf("-withdrawn start in withdrawn shape (for WindowMaker)\n");
printf("-iconic start iconized\n");
printf("-standout standing out rather than being pushed in\n");
printf("-asis use free memory amount as read from device\n");
printf("-dev <device> use the specified file as stat device\n\n");
printf("-bg <color> background color\n");
printf("-fg <color> base foreground color\n");
printf("-memory <color> used memory bar color\n");
printf("-buffer <color> buffer memory bar color\n");
printf("-cache <color> cache memory bar color\n");
printf("-swap <color> used swap space bar color\n");
printf("\n");
exit(0);
}
/* print the version of the tool */
void version()
{
printf("asmem : AfterStep memory utilization monitor version 1.9\n");
}
void parsecmdline(int argc, char *argv[])
{
char *argument;
int i;
/* parse the command line */
for (i=1; i<argc; i++) {
argument=argv[i];
if (argument[0]=='-') {
if (!strncmp(argument,"-withdrawn",10)) {
withdrawn=1;
} else if (!strncmp(argument,"-iconic",7)) {
iconic=1;
} else if (!strncmp(argument,"-standout",9)) {
pushed_in=0;
} else if (!strncmp(argument,"-asis",5)) {
state.standard_free=1;
} else if (!strncmp(argument,"-free",5)) {
state.standard_free=1;
} else if (!strncmp(argument,"-mb",3)) {
state.mb=1;
} else if (!strncmp(argument,"-used",5)) {
state.show_used=1;
} else if (!strncmp(argument,"-u",2)) {
if (++i >= argc)
usage();
state.update_interval = atoi(argv[i]);
if ( state.update_interval < 1 )
state.update_interval = CHK_INTERVAL;
} else if (!strncmp(argument,"-position",9)) {
if (++i >= argc)
usage();
safecopy(mainGeometry, argv[i], 50);
} else if (!strncmp(argument,"-display",8)) {
if (++i >= argc)
usage();
safecopy(display_name, argv[i], 50);
} else if (!strncmp(argument,"-dev",4)) {
if (++i >= argc)
usage();
safecopy(state.proc_mem_filename,argv[i],256);
} else if (!strncmp(argument,"-bg",3)) {
if (++i >= argc)
usage();
safecopy(state.bgcolor, argv[i], 50);
} else if (!strncmp(argument,"-fg",3)) {
if (++i >= argc)
usage();
safecopy(state.fgcolor, argv[i], 50);
} else if (!strncmp(argument,"-memory",7)) {
if (++i >= argc)
usage();
safecopy(state.memory_color, argv[i], 50);
} else if (!strncmp(argument,"-buffer",7)) {
if (++i >= argc)
usage();
safecopy(state.buffer_color, argv[i], 50);
} else if (!strncmp(argument,"-cache",6)) {
if (++i >= argc)
usage();
safecopy(state.cache_color, argv[i], 50);
} else if (!strncmp(argument,"-swap",5)) {
if (++i >= argc)
usage();
safecopy(state.swap_color, argv[i], 50);
} else if (!strncmp(argument,"-V",2)) {
version();
exit(0);
} else if (!strncmp(argument,"-H",2)) {
version();
usage();
} else if (!strncmp(argument,"-h",2)) {
version();
usage();
} else {
version();
usage();
}
} else {
version();
usage();
}
}
}
void main(int argc, char** argv)
{
defaults();
parsecmdline(argc, argv);
asmem_initialize(argc, argv,
display_name,
mainGeometry,
withdrawn,
iconic,
pushed_in);
while (1) {
asmem_update();
usleep(X11_INTERVAL);
}
}
|