asmon: Add version 0.71 to repository.

From
http://ftp.riken.jp/X11/AfterStep/stable/rpms/misc-tarballs/asmon-0.71.tar.bz2
This commit is contained in:
Doug Torrance 2018-07-10 22:14:59 -04:00 committed by Carlos R. Mafra
parent 3132e13337
commit 2fdb26a3bd
20 changed files with 2741 additions and 0 deletions

339
asmon/COPYING Normal file
View file

@ -0,0 +1,339 @@
GNU GENERAL PUBLIC LICENSE
Version 2, June 1991
Copyright (C) 1989, 1991 Free Software Foundation, Inc.
675 Mass Ave, Cambridge, MA 02139, USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The licenses for most software are designed to take away your
freedom to share and change it. By contrast, the GNU General Public
License is intended to guarantee your freedom to share and change free
software--to make sure the software is free for all its users. This
General Public License applies to most of the Free Software
Foundation's software and to any other program whose authors commit to
using it. (Some other Free Software Foundation software is covered by
the GNU Library General Public License instead.) You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
this service if you wish), that you receive source code or can get it
if you want it, that you can change the software or use pieces of it
in new free programs; and that you know you can do these things.
To protect your rights, we need to make restrictions that forbid
anyone to deny you these rights or to ask you to surrender the rights.
These restrictions translate to certain responsibilities for you if you
distribute copies of the software, or if you modify it.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must give the recipients all the rights that
you have. You must make sure that they, too, receive or can get the
source code. And you must show them these terms so they know their
rights.
We protect your rights with two steps: (1) copyright the software, and
(2) offer you this license which gives you legal permission to copy,
distribute and/or modify the software.
Also, for each author's protection and ours, we want to make certain
that everyone understands that there is no warranty for this free
software. If the software is modified by someone else and passed on, we
want its recipients to know that what they have is not the original, so
that any problems introduced by others will not reflect on the original
authors' reputations.
Finally, any free program is threatened constantly by software
patents. We wish to avoid the danger that redistributors of a free
program will individually obtain patent licenses, in effect making the
program proprietary. To prevent this, we have made it clear that any
patent must be licensed for everyone's free use or not licensed at all.
The precise terms and conditions for copying, distribution and
modification follow.
GNU GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. This License applies to any program or other work which contains
a notice placed by the copyright holder saying it may be distributed
under the terms of this General Public License. The "Program", below,
refers to any such program or work, and a "work based on the Program"
means either the Program or any derivative work under copyright law:
that is to say, a work containing the Program or a portion of it,
either verbatim or with modifications and/or translated into another
language. (Hereinafter, translation is included without limitation in
the term "modification".) Each licensee is addressed as "you".
Activities other than copying, distribution and modification are not
covered by this License; they are outside its scope. The act of
running the Program is not restricted, and the output from the Program
is covered only if its contents constitute a work based on the
Program (independent of having been made by running the Program).
Whether that is true depends on what the Program does.
1. You may copy and distribute verbatim copies of the Program's
source code as you receive it, in any medium, provided that you
conspicuously and appropriately publish on each copy an appropriate
copyright notice and disclaimer of warranty; keep intact all the
notices that refer to this License and to the absence of any warranty;
and give any other recipients of the Program a copy of this License
along with the Program.
You may charge a fee for the physical act of transferring a copy, and
you may at your option offer warranty protection in exchange for a fee.
2. You may modify your copy or copies of the Program or any portion
of it, thus forming a work based on the Program, and copy and
distribute such modifications or work under the terms of Section 1
above, provided that you also meet all of these conditions:
a) You must cause the modified files to carry prominent notices
stating that you changed the files and the date of any change.
b) You must cause any work that you distribute or publish, that in
whole or in part contains or is derived from the Program or any
part thereof, to be licensed as a whole at no charge to all third
parties under the terms of this License.
c) If the modified program normally reads commands interactively
when run, you must cause it, when started running for such
interactive use in the most ordinary way, to print or display an
announcement including an appropriate copyright notice and a
notice that there is no warranty (or else, saying that you provide
a warranty) and that users may redistribute the program under
these conditions, and telling the user how to view a copy of this
License. (Exception: if the Program itself is interactive but
does not normally print such an announcement, your work based on
the Program is not required to print an announcement.)
These requirements apply to the modified work as a whole. If
identifiable sections of that work are not derived from the Program,
and can be reasonably considered independent and separate works in
themselves, then this License, and its terms, do not apply to those
sections when you distribute them as separate works. But when you
distribute the same sections as part of a whole which is a work based
on the Program, the distribution of the whole must be on the terms of
this License, whose permissions for other licensees extend to the
entire whole, and thus to each and every part regardless of who wrote it.
Thus, it is not the intent of this section to claim rights or contest
your rights to work written entirely by you; rather, the intent is to
exercise the right to control the distribution of derivative or
collective works based on the Program.
In addition, mere aggregation of another work not based on the Program
with the Program (or with a work based on the Program) on a volume of
a storage or distribution medium does not bring the other work under
the scope of this License.
3. You may copy and distribute the Program (or a work based on it,
under Section 2) in object code or executable form under the terms of
Sections 1 and 2 above provided that you also do one of the following:
a) Accompany it with the complete corresponding machine-readable
source code, which must be distributed under the terms of Sections
1 and 2 above on a medium customarily used for software interchange; or,
b) Accompany it with a written offer, valid for at least three
years, to give any third party, for a charge no more than your
cost of physically performing source distribution, a complete
machine-readable copy of the corresponding source code, to be
distributed under the terms of Sections 1 and 2 above on a medium
customarily used for software interchange; or,
c) Accompany it with the information you received as to the offer
to distribute corresponding source code. (This alternative is
allowed only for noncommercial distribution and only if you
received the program in object code or executable form with such
an offer, in accord with Subsection b above.)
The source code for a work means the preferred form of the work for
making modifications to it. For an executable work, complete source
code means all the source code for all modules it contains, plus any
associated interface definition files, plus the scripts used to
control compilation and installation of the executable. However, as a
special exception, the source code distributed need not include
anything that is normally distributed (in either source or binary
form) with the major components (compiler, kernel, and so on) of the
operating system on which the executable runs, unless that component
itself accompanies the executable.
If distribution of executable or object code is made by offering
access to copy from a designated place, then offering equivalent
access to copy the source code from the same place counts as
distribution of the source code, even though third parties are not
compelled to copy the source along with the object code.
4. You may not copy, modify, sublicense, or distribute the Program
except as expressly provided under this License. Any attempt
otherwise to copy, modify, sublicense or distribute the Program is
void, and will automatically terminate your rights under this License.
However, parties who have received copies, or rights, from you under
this License will not have their licenses terminated so long as such
parties remain in full compliance.
5. You are not required to accept this License, since you have not
signed it. However, nothing else grants you permission to modify or
distribute the Program or its derivative works. These actions are
prohibited by law if you do not accept this License. Therefore, by
modifying or distributing the Program (or any work based on the
Program), you indicate your acceptance of this License to do so, and
all its terms and conditions for copying, distributing or modifying
the Program or works based on it.
6. Each time you redistribute the Program (or any work based on the
Program), the recipient automatically receives a license from the
original licensor to copy, distribute or modify the Program subject to
these terms and conditions. You may not impose any further
restrictions on the recipients' exercise of the rights granted herein.
You are not responsible for enforcing compliance by third parties to
this License.
7. If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues),
conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot
distribute so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you
may not distribute the Program at all. For example, if a patent
license would not permit royalty-free redistribution of the Program by
all those who receive copies directly or indirectly through you, then
the only way you could satisfy both it and this License would be to
refrain entirely from distribution of the Program.
If any portion of this section is held invalid or unenforceable under
any particular circumstance, the balance of the section is intended to
apply and the section as a whole is intended to apply in other
circumstances.
It is not the purpose of this section to induce you to infringe any
patents or other property right claims or to contest validity of any
such claims; this section has the sole purpose of protecting the
integrity of the free software distribution system, which is
implemented by public license practices. Many people have made
generous contributions to the wide range of software distributed
through that system in reliance on consistent application of that
system; it is up to the author/donor to decide if he or she is willing
to distribute software through any other system and a licensee cannot
impose that choice.
This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License.
8. If the distribution and/or use of the Program is restricted in
certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Program under this License
may add an explicit geographical distribution limitation excluding
those countries, so that distribution is permitted only in or among
countries not thus excluded. In such case, this License incorporates
the limitation as if written in the body of this License.
9. The Free Software Foundation may publish revised and/or new versions
of the General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the Program
specifies a version number of this License which applies to it and "any
later version", you have the option of following the terms and conditions
either of that version or of any later version published by the Free
Software Foundation. If the Program does not specify a version number of
this License, you may choose any version ever published by the Free Software
Foundation.
10. If you wish to incorporate parts of the Program into other free
programs whose distribution conditions are different, write to the author
to ask for permission. For software which is copyrighted by the Free
Software Foundation, write to the Free Software Foundation; we sometimes
make exceptions for this. Our decision will be guided by the two goals
of preserving the free status of all derivatives of our free software and
of promoting the sharing and reuse of software generally.
NO WARRANTY
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
REPAIR OR CORRECTION.
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGES.
END OF TERMS AND CONDITIONS
Appendix: How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
convey the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) 19yy <name of author>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
Also add information on how to contact you by electronic and paper mail.
If the program is interactive, make it output a short notice like this
when it starts in an interactive mode:
Gnomovision version 69, Copyright (C) 19yy name of author
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, the commands you use may
be called something other than `show w' and `show c'; they could even be
mouse-clicks or menu items--whatever suits your program.
You should also get your employer (if you work as a programmer) or your
school, if any, to sign a "copyright disclaimer" for the program, if
necessary. Here is a sample; alter the names:
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
`Gnomovision' (which makes passes at compilers) written by James Hacker.
<signature of Ty Coon>, 1 April 1989
Ty Coon, President of Vice
This General Public License does not permit incorporating your program into
proprietary programs. If your program is a subroutine library, you may
consider it more useful to permit linking proprietary applications with the
library. If this is what you want to do, use the GNU Library General
Public License instead of this License.

104
asmon/Changelog Normal file
View file

@ -0,0 +1,104 @@
asmon-0.71
- Patch from Eric Evans <eevans@sym-link.com> to fix problems
with the Uptime not rolling over after more than 10 days.
asmon-0.7
- Fixed a graphics bug when X mem is over 100 mb
- Fixed a bug in regards to throttling cpus
- Eric Evans
- added support for Linux Kernel 2.6
- apollock@debian.org
- fixed problem with more powerful cpus
- fixed problem with very large memory systems
asmon-0.60
- fixed glitch when only shared mem shown
- Eric Davis <ead@pobox.com>
- ported to Solaris
- added code to refresh the area of the memory and swap bars
- fixed a few math bugs
asmon-0.51
- added support for more than 9 days uptime
- added support for load average higher than 9.99
- fixed the mem bar for >99 megs of ram
- added "Kitchen Sink" for WavePoet
- fixed a couple graphics glitches
asmon-0.50
- fixed yet another bug in the X mem bar, it should behave now
- integrated patch from Dmytro Sudak <ii1@grant.kharkov.ua>, allowing
execution of a program when you click on asmon, with "-e <prog>"
asmon-0.49
- fixed bug in X mem usage bar
asmon-0.48
- tweaked a few things
asmon-0.47
- more CPU optimization
- cleaned up the code alot
asmon-0.46
- it now checks both /tmp/.X0-lock and /var/run/server.0.pid for X's pid
asmon-0.45
- cleaned up the code a bunch
- some optimization
asmon-0.44
- added -m option to show only Shared mem like other mem meters
asmon-0.43
- increased the time interval between mem updates to lower cpu usage
- fixed the >100 megs bug
- added "-u" option to force uptime display
- fixed a few other minor things that I don't remember
asmon-0.42
- fixed some math errors
- put a limiter on the X mem bar
- fixed problem of crashing when no Swap exists
asmon-0.4
- made X mem meter only appear if X pid can be found
otherwise diverting to uptime
asmon-0.3
- put in X mem meter
asmon-0.2
- stomped a few bugs
- first official release
asmon-0.15
- tweaked the graphs
- changed the name
- fixed -h docs
asmem-0.1e
- put brackets on the graphs
asmem-0.1d
- fixed overzealous bra graphs
asmem-0.1c
- moved the cpu meter over one pixel
asmem-0.1b
- re-integrated CPU monitor
- removed ladavg bar
asmem-0.1a
- added page/swap LED's
asmem-0.1
- changed from wmcpu
- Removed CPU Usage Meter
- Added Swap Usage Meter
- Added Number of megs next to mem meters
- Added Load avg number
- Changed mem splits to tick marks rather than colors
- Put in better colors taken from wmsysmon

14
asmon/INSTALL Normal file
View file

@ -0,0 +1,14 @@
Installation instructions for asmon
Installation
--------------------------------------------------------------
1) % tar -zxvf asmon-0.7.tar.gz
2) % cd amon-0.7/asmon
3) % make
4) % make install
5) % asmon & (or asmon -h for help)
Solaris
--------------------------------------------------------------
Uncomment the appropriate lines in the Makefile before
compiling.

62
asmon/asmon.icon.xpm Normal file
View file

@ -0,0 +1,62 @@
/* XPM */
static char * xemacs_xpm[] = {
/* XEmacs pixmap
* width height ncolors chars_per_pixel */
"50 50 5 1",
/**/
" s None c None",
". m black c darkslategrey",
"X m white c orange",
"o m black c slate blue",
"O m white c white",
/* pixels */
" ",
" ",
" ...... ... ",
" .. ... ",
" ............. ",
" .XXXXXXXXXX... ",
" .XX............ ",
" .X. ... ",
" ..... ... ",
" ... ",
" o ... ",
" o ... ",
" ... ",
" o o o ... ",
" oo oo ... ",
" ooo ... ",
" .......................................... ",
" o ......................................... ",
" o ....................................... ",
" o ..................................... ",
" o ..................................... ",
" ..................................... ",
" ..................................... ",
" o ..................................... ",
" oo ......OOO...OOOO..................... ",
" o .....OO.OO.O......................... ",
" .....O...O.O.....OO.OO..OO...OOO..... ",
" .....OOOOO..OOO..O.O.O.O..O..O..O.... ",
" .....O...O.....O.O.O.O.O..O..O..O.... ",
" o .....O...O.....O.O...O.O..O..O..O.... ",
" oo .....O...O.OOOO..O...O..OO...O..O.... ",
" o ..................................... ",
" ..................................... ",
" ..................................... ",
" ..................................... ",
" ..................................... ",
" o ................................... ",
" o ................................. ",
" oo ..X.. ",
" .X. .... ",
" .X. .XXXX. ",
" .X. .XX..XX. ",
" .X. .X. .X. ",
" o .XX..XX. .X. ",
" o .XXXX. .X. ",
" o o .... .X. ",
" .X. ",
" ",
" ",
" "};

27
asmon/asmon/Makefile Normal file
View file

@ -0,0 +1,27 @@
# uncomment the following lines if your using Solaris
#SOLARIS = -D__solaris__
#SOLARIS_LIBS = -lsocket -lkstat
#SOLARIS_OBJS = solaris26.o
LIBDIR = -L/usr/X11R6/lib
LIBS = -lXpm -lXext -lX11 $(SOLARIS_LIBS)
OBJS = asmon.o $(SOLARIS_OBJS) \
../wmgeneral/wmgeneral.o \
../wmgeneral/misc.o \
../wmgeneral/list.o
.c.o:
gcc -c -Wall $(SOLARIS) $< -o $*.o
asmon: $(OBJS)
gcc -o asmon $(OBJS) $(LIBDIR) $(LIBS)
clean::
for i in $(OBJS) ; do \
rm $$i;\
done
rm asmon
install::
cp -f asmon /usr/local/bin

BIN
asmon/asmon/asmon Executable file

Binary file not shown.

View file

@ -0,0 +1,38 @@
#define asmon_mask_width 64
#define asmon_mask_height 64
static char asmon_mask_bits[] = {
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0xf0,0xff,0xff,0xff,0xff,0xff,0xff,0x0f,0xf0,0xff,0xff,0xff,0xff,
0xff,0xff,0x0f,0xf0,0xff,0xff,0xff,0xff,0xff,0xff,0x0f,0xf0,0xff,0xff,0xff,
0xff,0xff,0xff,0x0f,0xf0,0xff,0xff,0xff,0xff,0xff,0xff,0x0f,0xf0,0xff,0xff,
0xff,0xff,0xff,0xff,0x0f,0xf0,0xff,0xff,0xff,0xff,0xff,0xff,0x0f,0xf0,0xff,
0xff,0xff,0xff,0xff,0xff,0x0f,0xf0,0xff,0xff,0xff,0xff,0xff,0xff,0x0f,0xf0,
0xff,0xff,0xff,0xff,0xff,0xff,0x0f,0xf0,0xff,0xff,0xff,0xff,0xff,0xff,0x0f,
0xf0,0xff,0xff,0xff,0xff,0xff,0xff,0x0f,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xf0,0xff,0xff,0xff,0xff,0xff,
0xff,0x0f,0xf0,0xff,0xff,0xff,0xff,0xff,0xff,0x0f,0xf0,0xff,0xff,0xff,0xff,
0xff,0xff,0x0f,0xf0,0xff,0xff,0xff,0xff,0xff,0xff,0x0f,0xf0,0xff,0xff,0xff,
0xff,0xff,0xff,0x0f,0xf0,0xff,0xff,0xff,0xff,0xff,0xff,0x0f,0xf0,0xff,0xff,
0xff,0xff,0xff,0xff,0x0f,0xf0,0xff,0xff,0xff,0xff,0xff,0xff,0x0f,0xf0,0xff,
0xff,0xff,0xff,0xff,0xff,0x0f,0xf0,0xff,0xff,0xff,0xff,0xff,0xff,0x0f,0xf0,
0xff,0xff,0xff,0xff,0xff,0xff,0x0f,0xf0,0xff,0xff,0xff,0xff,0xff,0xff,0x0f,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0xf0,0xff,0xff,0xff,0xff,0xff,0xff,0x0f,0xf0,0xff,0xff,0xff,0xff,0xff,
0xff,0x0f,0xf0,0xff,0xff,0xff,0xff,0xff,0xff,0x0f,0xf0,0xff,0xff,0xff,0xff,
0xff,0xff,0x0f,0xf0,0xff,0xff,0xff,0xff,0xff,0xff,0x0f,0xf0,0xff,0xff,0xff,
0xff,0xff,0xff,0x0f,0xf0,0xff,0xff,0xff,0xff,0xff,0xff,0x0f,0xf0,0xff,0xff,
0xff,0xff,0xff,0xff,0x0f,0xf0,0xff,0xff,0xff,0xff,0xff,0xff,0x0f,0xf0,0xff,
0xff,0xff,0xff,0xff,0xff,0x0f,0xf0,0xff,0xff,0xff,0xff,0xff,0xff,0x0f,0xf0,
0xff,0xff,0xff,0xff,0xff,0xff,0x0f,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xf0,0xff,0xff,0xff,0xff,0xff,0xff,
0x0f,0xf0,0xff,0xff,0xff,0xff,0xff,0xff,0x0f,0xf0,0xff,0xff,0xff,0xff,0xff,
0xff,0x0f,0xf0,0xff,0xff,0xff,0xff,0xff,0xff,0x0f,0xf0,0xff,0xff,0xff,0xff,
0xff,0xff,0x0f,0xf0,0xff,0xff,0xff,0xff,0xff,0xff,0x0f,0xf0,0xff,0xff,0xff,
0xff,0xff,0xff,0x0f,0xf0,0xff,0xff,0xff,0xff,0xff,0xff,0x0f,0xf0,0xff,0xff,
0xff,0xff,0xff,0xff,0x0f,0xf0,0xff,0xff,0xff,0xff,0xff,0xff,0x0f,0xf0,0xff,
0xff,0xff,0xff,0xff,0xff,0x0f,0xf0,0xff,0xff,0xff,0xff,0xff,0xff,0x0f,0xf0,
0xff,0xff,0xff,0xff,0xff,0xff,0x0f,0xf0,0xff,0xff,0xff,0xff,0xff,0xff,0x0f,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00};

View file

@ -0,0 +1,205 @@
/* XPM */
static char * asmon_master_xpm[] = {
"75 126 76 1",
" c None",
". c #000000",
"+ c #202020",
"@ c #C7C7C7",
"# c #20B2AE",
"$ c #004941",
"% c #188A86",
"& c #107D79",
"* c #24DA0D",
"= c #28D60D",
"- c #2DD10D",
"; c #32CC0C",
"> c #36C80C",
", c #3BC30C",
"' c #3FBF0B",
") c #44BA0B",
"! c #48B60B",
"~ c #4DB10B",
"{ c #51AD0A",
"] c #56A80A",
"^ c #5BA30A",
"/ c #5F9F09",
"( c #649A09",
"_ c #689609",
": c #6D9109",
"< c #718D08",
"[ c #768808",
"} c #7A8408",
"| c #7F7F07",
"1 c #847A07",
"2 c #887607",
"3 c #8D7107",
"4 c #916D06",
"5 c #966806",
"6 c #9A6406",
"7 c #9F5F05",
"8 c #A35B05",
"9 c #A85605",
"0 c #AD5105",
"a c #B14D04",
"b c #B64804",
"c c #BA4404",
"d c #BF3F03",
"e c #C33B03",
"f c #C83603",
"g c #CC3203",
"h c #D12D02",
"i c #D62802",
"j c #DA2402",
"k c #DF1F01",
"l c #E31B01",
"m c #E81601",
"n c #EC1201",
"o c #F10D00",
"p c #F50900",
"q c #FA0400",
"r c #30CB00",
"s c #38BE00",
"t c #41B600",
"u c #49AA00",
"v c #59A200",
"w c #619600",
"x c #698E00",
"y c #718200",
"z c #867900",
"A c #8E6D00",
"B c #966500",
"C c #9E5900",
"D c #AE5100",
"E c #B64500",
"F c #BE3C00",
"G c #C73000",
"H c #BF2020",
"I c #B60418",
"J c #283C38",
"K c #F7F3FF",
" ",
" ",
" ",
" ",
" ........................................................ ",
" .++++++++++++++++++++++++++++++++++++++++++++++++++++++@ ",
" .++++++++++++++++++++++++++++++++++++++++++++++++++++++@ ",
" .++++++++++++++++++++++++++++++++++++++++++++++++++++++@ ",
" .++++++++++++++++++++++++++++++++++++++++++++++++++++++@ ",
" .++++++++++++++++++++++++++++++++++++++++++++++++++++++@ ",
" .++++++++++++++++++++++++++++++++++++++++++++++++++++++@ ",
" .++++++++++++++++++++++++++++++++++++++++++++++++++++++@ ",
" .++++++++++++++++++++++++++++++++++++++++++++++++++++++@ ",
" .++++++++++++++++++++++++++++++++++++++++++++++++++++++@ ",
" .++++++++++++++++++++++++++++++++++++++++++++++++++++++@ ",
" @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ ",
" ",
" ",
" ........................................................ ",
" .++++++++++++++++++++++++++++++++++++++++++++++++++++++@ ",
" .++++++++++++++++++++++++++++++++++++++++++++++++++++++@ ",
" .++++++++++++++++++++++++++++++++++++++++++++++++++++++@ ",
" .++++++++++++++++++++++++++++++++++++++++++++++++++++++@ ",
" .++++++++++++++++++++++++++++++++++++++++++++++++++++++@ ",
" .++++++++++++++++++++++++++++++++++++++++++++++++++++++@ ",
" .++++++++++++++++++++++++++++++++++++++++++++++++++++++@ ",
" .++++++++++++++++++++++++++++++++++++++++++++++++++++++@ ",
" .++++++++++++++++++++++++++++++++++++++++++++++++++++++@ ",
" .++++++++++++++++++++++++++++++++++++++++++++++++++++++@ ",
" @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ ",
" ",
" ",
" ........................................................ ",
" .++++++++++++++++++++++++++++++++++++++++++++++++++++++@ ",
" .++++++++++++++++++++++++++++++++++++++++++++++++++++++@ ",
" .++++++++++++++++++++++++++++++++++++++++++++++++++++++@ ",
" .++++++++++++++++++++++++++++++++++++++++++++++++++++++@ ",
" .++++++++++++++++++++++++++++++++++++++++++++++++++++++@ ",
" .++++++++++++++++++++++++++++++++++++++++++++++++++++++@ ",
" .++++++++++++++++++++++++++++++++++++++++++++++++++++++@ ",
" .++++++++++++++++++++++++++++++++++++++++++++++++++++++@ ",
" .++++++++++++++++++++++++++++++++++++++++++++++++++++++@ ",
" .++++++++++++++++++++++++++++++++++++++++++++++++++++++@ ",
" @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ ",
" ",
" ",
" ........................................................ ",
" .+++++++++++@.+++++++++++++++++++++++++++++++++++++++++@ ",
" .+++++++++++@.+++++++++++++++++++++++++++++++++++++++++@ ",
" .+++++++++++@.+++++++++++++++++++++++++++++++++++++++++@ ",
" .+++++++++++@.+++++++++++++++++++++++++++++++++++++++++@ ",
" .+++++++++++@.+++++++++++++++++++++++++++++++++++++++++@ ",
" .+++++++++++@.+++++++++++++++++++++++++++++++++++++++++@ ",
" .+++++++++++@.+++++++++++++++++++++++++++++++++++++++++@ ",
" .+++++++++++@.+++++++++++++++++++++++++++++++++++++++++@ ",
" .+++++++++++@.+++++++++++++++++++++++++++++++++++++++++@ ",
" .+++++++++++@.+++++++++++++++++++++++++++++++++++++++++@ ",
" .+++++++++++@.+++++++++++++++++++++++++++++++++++++++++@ ",
" .+++++++++++@.+++++++++++++++++++++++++++++++++++++++++@ ",
" @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ ",
" ",
" ",
" ",
" ",
" ",
" ",
" ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ",
" ++###+++$$$%+%###%+%###%+#$$$#+%###%+%###%+%###%+%###%+%###%++++++ ",
" +#+++#+$+++#+$+++#+$+++#+#+++#+#+++$+#+++$+$+++#+#+++#+#+++#+#++++ ",
" +#+++#+$+++#+$+++#+$+++#+#+++#+#+++$+#+++$+$+++#+#+++#+#+++#+#++++ ",
" +%$$$%++$$$%+%###%++###%+%###%+####%+%###%++$$$%+%###%+&###%++++++ ",
" +#+++#+$+++#+#+++$+$+++#+$+++#+$+++#+#+++#+$+++#+#+++#+$+++#+#++++ ",
" +#+++#+$+++#+#+++$+$+++#+$+++#+$+++#+#+++#+$+++#+#+++#+$+++#+#++++ ",
" ++###+++$$$#+%###%+%###%++$$$%+%###%+%###%++$$$#+%###%+%###%+++#++ ",
" ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ",
" *=-;>,')!~{]^/(_:<[}|1234567890abcdefghijklmnopq ",
" *=-;>,')!~{]^/(_:<[}|1234567890abcdefghijklmnopq ",
" *=-;>,')!~{]^/(_:<[}|1234567890abcdefghijklmnopq ",
" *=-;>,')!~{]^/(_:<[}|1234567890abcdefghijklmnopq ",
" *=-;>,')!~{]^/(_:<[}|1234567890abcdefghijklmnopq ",
" *=-;>,')!~{]^/(_:<[}|1234567890abcdefghijklmnopq ",
" *=-;>,')!~{]^/(_:<[}|1234567890abcdefghijklmnopq ",
" *=-;>,')!~{]^/(_:<[}|1234567890abcdefghijklmnopq ",
" *=-;>,')!~{]^/(_:<[}|1234567890abcdefghijklmnopq ",
" rsstuuvvwwxxyzzAABBCCDEEFFGHHHHHHHHHHHHHHHHHHHHHHHHHH ",
" rsstuuvvwwxxyzzAABBCCDEEFFGHHHHHHHHHHHHHHHHHHHHHHHHHH ",
" rsstuuvvwwxxyzzAABBCCDEEFFGHHHHHHHHHHHHHHHHHHHHHHHHHH ",
" rsstuuvvwwxxyzzAABBCCDEEFFGHHHHHHHHHHHHHHHHHHHHHHHHHH ",
" rsstuuvvwwxxyzzAABBCCDEEFFGHHHHHHHHHHHHHHHHHHHHHHHHHH ",
" rsstuuvvwwxxyzzAABBCCDEEFFGHHHHHHHHHHHHHHHHHHHHHHHHHH ",
" rsstuuvvwwxxyzzAABBCCDEEFFGHHHHHHHHHHHHHHHHHHHHHHHHHH ",
" rsstuuvvwwxxyzzAABBCCDEEFFGHHHHHHHHHHHHHHHHHHHHHHHHHH ",
" rsstuuvvwwxxyzzAABBCCDEEFFGHHHHHHHHHHHHHHHHHHHHHHHHHH ",
" rsstuuvvwwxxyzzAABBCCDEEFFGHHHHHHHHHHHHHHHHHHHHHHHHHH ",
" rsstuuvvwwxxyzzAABBCCDEEFFGHHHHHHHHHHHHHHHHHHHHHHHHHH ",
" +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++,' ",
" +$###$+%###+++###%+%###++%###%+%###%+%###%+%$$$%++$$$%++$$$%+,' ",
" +#+++#+#+++#+#+++$+#+++#+#+++$+#+++$+#+++$+#+++#+$+++#+$+++#+,' ",
" +#+++#+#+++#+#+++$+#+++#+#+++$+#+++$+#+++$+#+++#+$+++#+$+++#+,' ",
" +%###%+%###++%$$$++%$$$%+%###++%###++%$%#%+%###%++$$$%++$$$%+,' ",
" +#+++#+#+++#+#+++$+#+++#+#+++$+#+++$+#+++#+#+++#+$+++#+$+++#+,' ",
" +#+++#+#+++#+#+++$+#+++#+#+++$+#+++$+#+++#+#+++#+$+++#+$+++#+,' ",
" +%$$$%+%###+++###%+%###++%###%+%$$$++%###%+%$$$%++$$$%+%###%+ ",
" +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ",
" ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++",
" ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++",
" ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++",
" ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++",
" ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++",
" ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++",
" ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++",
" +II+ +JJ+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++",
" IKII JJJJ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++",
" IIII JJJJ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++",
" +II+ +JJ+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++",
" ....................................................... ",
" .++++++++++++++++++++++++++++++++++++++++++++++++++++++ ",
" .++++++++++++++++++++++++++++++++++++++++++++++++++++++ ",
" .++++++++++++++++++++++++++++++++++++++++++++++++++++++ ",
" .++++++++++++++++++++++++++++++++++++++++++++++++++++++ ",
" .++++++++++++++++++++++++++++++++++++++++++++++++++++++ ",
" .++++++++++++++++++++++++++++++++++++++++++++++++++++++ ",
" .++++++++++++++++++++++++++++++++++++++++++++++++++++++ ",
" .++++++++++++++++++++++++++++++++++++++++++++++++++++++ ",
" .++++++++++++++++++++++++++++++++++++++++++++++++++++++ ",
" .++++++++++++++++++++++++++++++++++++++++++++++++++++++ "};

873
asmon/asmon/asmon.c Normal file
View file

@ -0,0 +1,873 @@
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <string.h>
#include <fcntl.h>
#include <unistd.h>
#include <ctype.h>
#include <sys/utsname.h>
#include <sys/wait.h>
#include <sys/param.h>
#include <sys/types.h>
#include <X11/Xlib.h>
#include <X11/xpm.h>
#include <X11/extensions/shape.h>
#include "../wmgeneral/wmgeneral.h"
#include "../wmgeneral/misc.h"
#include "asmon-master.xpm"
#include "asmon-mask.xbm"
#ifdef __solaris__
#include <utmp.h>
#endif
#define EXEC_ON_CLICK 1
#define ASMON_VERSION "0.71"
#define CHAR_WIDTH 5
#define CHAR_HEIGHT 7
#define BCHAR_WIDTH 6
#define BCHAR_HEIGHT 9
#define BOFFX (9)
#define BOFFY (111)
#define BREDX (3)
#define BREDY (111)
#define BGREENX (87)
#define BGREENY (66)
#define LITEW (4)
#define LITEH (4)
#define B_OFF (0)
#define B_RED (1)
#define B_GREEN (2)
/* Evil globals I haven't removed yet */
long last_pageins=0, last_pageouts=0;
long last_swapins=0, last_swapouts=0;
//double old;
static int has_kern26 = 0;
#ifdef EXEC_ON_CLICK
char Command[256]="";
#endif
/* functions */
void DrawUptime(void);
void usage(void);
void printversion(void);
void asmon_routine(int Xpid, int allmem);
void DrawLite(int state, int dx, int dy);
void DrawCPU(void);
void DrawLoad(void);
#ifdef __solaris__
float DrawMemSwap(void);
extern int getLoad(float *);
extern int getSwap(unsigned long *, unsigned long *);
extern int getMem(unsigned long *, unsigned long *);
extern int getCPU(unsigned long *, unsigned long *,
unsigned long *, unsigned long *,
unsigned long *, unsigned long *,
unsigned long *, unsigned long *);
#else
void DrawXmem(int Xpid, float total);
float DrawMemSwap(float total, int allmem);
#endif
int main(int argc, char *argv[])
{
FILE *fp;
int i;
int allmem=1;
int Xpid=1;
char *ProgName;
struct utsname name;
int kernMajor, kernMinor, kernRev;
ProgName = argv[0];
if (strlen(ProgName) >= 5)
ProgName += (strlen(ProgName) - 5);
for (i=1; i<argc; i++) {
char *arg = argv[i];
if (*arg=='-') {
switch (arg[1]) {
case 'd' :
if (strcmp(arg+1, "display")) {
usage();
exit(1);
}
break;
#ifdef EXEC_ON_CLICK
case 'e' :
if ( argv[++i] ) {
strncpy( Command, argv[i], 253);
strcat( Command, " &");
} else {
usage();
exit(0);
}
break;
#endif
case 'v' :
printversion();
exit(0);
break;
case 'u' :
#ifdef __solaris__
fprintf(stderr, "X Server memory stats unavailable for Solaris.\n");
exit(0);
#endif
Xpid=0;
break;
default:
usage();
exit(0);
break;
}
}
}
#ifndef __solaris__
if ( Xpid != 0) {
if ( (fp = fopen("/var/run/server.0.pid", "r")) != NULL)
{
fscanf(fp, " %d", &Xpid);
fclose(fp);
} else {
if ( (fp = fopen("/tmp/.X0-lock", "r")) != NULL)
{
fscanf(fp, " %d", &Xpid);
fclose(fp);
} else {
Xpid=0;
}
}
}
#endif
/* Open 64x64 window */
openXwindow(argc, argv, asmon_master_xpm, asmon_mask_bits, asmon_mask_width, asmon_mask_height);
if( uname( &name ) != -1 )
{
if( strcmp( name.sysname, "Linux" ) == 0 )
{
sscanf(name.release, "%d.%d.%d", &kernMajor, &kernMinor,
&kernRev);
if(( kernMajor == 2 ) && ( kernMinor == 6 ))
has_kern26 = 1;
}
}
else
{
fprintf(stderr, "Can't find system name\n");
exit(1);
}
asmon_routine(Xpid, allmem);
return(0);
}
/**************************************************************************/
void usage(void) {
fprintf(stderr, "\nasmon %s - by Brad Hall (bkh@rio.vg)\n\t\toriginally based on Timecop's wmcpu\n\n", ASMON_VERSION);
fprintf(stderr, "The top bar: left is the CPU usage, right is the load average\n");
fprintf(stderr, "The middle bar: left memory usage devided by ticks into shared, buffers, and\n\t\t cached, respectively, and the number of megs used\n");
fprintf(stderr, "The lower bar: the left swap usage and the number of megs swappedd avg\n");
fprintf(stderr, "The bottom: the left is a set of LED's marking page's and swap's, the right is\n\t\t a bar representing the amount of memory that the X server \n\t\t is taking up, and the exact megs\n\n usage:\n");
fprintf(stderr, "\t-display <display name>\n");
fprintf(stderr, "\t-h\tthis screen\n");
fprintf(stderr, "\t-v\tprint the version number\n");
#ifndef __solaris__
fprintf(stderr, "\t-u\tforce asmon to show uptime, rather than X mem use\n");
#endif
#ifdef EXEC_ON_CLICK
fprintf(stderr, "\t-e cmd\texecute 'cmd' on mouse click\n");
#endif
fprintf(stderr, "\n");
}
/**************************************************************************/
void printversion(void)
{
fprintf(stderr, "asmon %s\n", ASMON_VERSION);
}
/**************************************************************************/
void asmon_routine(int Xpid, int allmem)
{
int xpm_X=0, xpm_Y=0, count=0;
XEvent Event;
float total=0.0;
while(1)
{
DrawCPU();
DrawLoad();
/* Only run every 15 iterations */
if ( count == 0 || count == 15)
#ifdef __solaris__
total=DrawMemSwap();
#else
total=DrawMemSwap(total, allmem);
#endif
#ifdef __solaris__
DrawUptime();
#else
/* X mem or Uptime? */
if (Xpid == 0)
{
DrawUptime();
} else {
if (count == 5)
DrawXmem(Xpid, total);
}
#endif
/* Redraw Windows */
RedrawWindowXY(xpm_X, xpm_Y);
while (XPending(display))
{
XNextEvent(display, &Event);
switch (Event.type)
{
#ifdef EXEC_ON_CLICK
case ButtonPress:
#if 0
fprintf(stderr,"system(%s)\n",Command);
#endif
if (Command[ 0 ]) system(Command);
break;
#endif
case Expose:
RedrawWindowXY(xpm_X, xpm_Y);
break;
case DestroyNotify:
XCloseDisplay(display);
exit(0);
break;
}
}
count++;
if (count > 30)
count = 0;
usleep(150000);
}
}
/**************************************************************************/
#ifdef __solaris__
/* CPU Usage Meter */
void DrawCPU
(
void
)
{
unsigned long cpuIdle, cpuUser, cpuKern, cpuWait;
unsigned long pageIn, pageOut, swapIn, swapOut;
/* remember the statistics read last time */
static float cpustat[4] = {0.0, 0.0, 0.0, 0.0};
float fields[4] = {0.0, 0.0, 0.0, 0.0};
float cputotal = 0.0;
getCPU(&cpuIdle, &cpuUser, &cpuKern, &cpuWait,
&pageIn, &pageOut, &swapIn, &swapOut);
// Calculate CPU stuff
fields[0] = ((float)cpuIdle - cpustat[0]);
cpustat[0] = (float)cpuIdle;
cputotal += fields[0];
fields[1] = ((float)cpuUser - cpustat[1]);
cpustat[1] = (float)cpuUser;
cputotal += fields[1];
fields[2] = ((float)cpuKern - cpustat[2]);
cpustat[2] = (float)cpuKern;
cputotal += fields[2];
fields[3] = ((float)cpuWait - cpustat[3]);
cpustat[3] = (float)cpuWait;
cputotal += fields[3];
// CPU Bar
if(cputotal > 0)
{
cputotal = ((cputotal - (fields[0] + fields[2])) * 1.55);
if (cputotal > 26) cputotal = 26;
copyXPMArea(3, 84, cputotal, 9, 5, 5);
copyXPMArea(15, 105, (27 - cputotal), 9, (5 + cputotal), 5);
copyXPMArea(16, 46, 2, 14, 32, 2);
}
// Page In/Out
if (pageIn > last_pageins) DrawLite(B_RED, 5, 48);
else DrawLite(B_OFF, 5, 48);
if (pageOut > last_pageouts) DrawLite(B_RED, 10, 48);
else DrawLite(B_OFF, 10, 48);
last_pageins = pageIn;
last_pageouts = pageOut;
// Swap In/Out
if (swapIn > last_swapins) DrawLite(B_RED, 5, 53);
else DrawLite(B_OFF, 5, 53);
if (swapOut > last_swapouts) DrawLite(B_RED, 10, 53);
else DrawLite(B_OFF, 10, 53);
last_swapins = swapIn;
last_swapouts = swapOut;
}
#else
/* CPU Usage Meter */
void DrawCPU(void)
{
FILE *fp;
static double cpustat[7]; /* remember the statistics read last time */
//double fields[7], info[7], cputotal=0.0,idlee=0.0;
double fields[7], info[7], cputotal=0.0;
long pageins=0, pageouts=0, swapins=0, swapouts=0 ;
char buf[128];
int i;
if( (fp = fopen("/proc/stat", "r")) != NULL)
{
if( has_kern26 > 0 )
{
// CPU data
fscanf(fp, "cpu %lf %lf %lf %lf %lf %lf %lf", info, info+1,
info+2, info+3, info+4, info+5, info+6);
fclose(fp);
if( (fp = fopen("/proc/vmstat", "r")) != NULL)
{
// gather data for LED's
while( fgets(buf, 127, fp) )
{
if (strstr(buf, "pgpgin"))
sscanf(buf, "pgpgin %ld", &pageins);
if (strstr(buf, "pgpgout"))
sscanf(buf, "pgpgout %ld", &pageouts);
if (strstr(buf, "pswpin"))
sscanf(buf, "pswpin %ld", &swapins);
if (strstr(buf, "pswpout"))
sscanf(buf, "pswpout %ld", &swapouts);
}
fclose(fp);
}
} else {
// CPU data
fscanf(fp, "cpu %lf %lf %lf %lf", info, info+1, info+2,
info+3);
// gather data for LED's
while( fgets(buf, 127, fp) )
{
if (strstr(buf, "page"))
sscanf(buf, "page %ld %ld", &pageins, &pageouts);
if (strstr(buf, "swap"))
sscanf(buf, "swap %ld %ld", &swapins, &swapouts);
}
fclose(fp);
}
// Calculate CPU stuff
if( has_kern26 > 0 )
{
for(i = 0; i < 7; i++)
{
fields[i] = info[i] - cpustat[i];
cputotal += fields[i];
cpustat[i] = info[i];
}
} else {
for(i = 0; i < 4; i++)
{
fields[i] = info[i] - cpustat[i];
cputotal += fields[i];
cpustat[i] = info[i];
}
}
//idlee=info[3]-old;
//old=info[3];
// CPU Bar
//cputotal = 100 * l1 ;
//cputotal=(100-(idlee*100/16))*26/100;
if(cputotal > 0)
{
cputotal = (cputotal-(fields[3]+fields[4]))*1.55;
if ( cputotal > 26 ) cputotal = 26;
copyXPMArea(3,84,cputotal,9,5,5);
copyXPMArea(15,105,(27-cputotal),9,(5+cputotal),5);
copyXPMArea(16,46,2,14,32,2);
}
// Page In/Out
if (pageins > last_pageins)
{
DrawLite(B_RED, 5, 48);
} else {
DrawLite(B_OFF, 5, 48);
}
if (pageouts > last_pageouts)
{
DrawLite(B_RED, 10, 48);
} else {
DrawLite(B_OFF, 10, 48);
}
last_pageins = pageins;
last_pageouts = pageouts;
// Swap In/Out
if (swapins > last_swapins)
{
DrawLite(B_RED, 5, 53);
} else {
DrawLite(B_OFF, 5, 53);
}
if (swapouts > last_swapouts)
{
DrawLite(B_RED, 10, 53);
} else {
DrawLite(B_OFF, 10, 53);
}
last_swapins = swapins;
last_swapouts = swapouts;
}
}
#endif
/**************************************************************************/
/* Load Average */
void DrawLoad(void)
{
int tempy, tempa, i;
static float oldv = -1.0;
float ftmp;
#ifdef __solaris__
if (getLoad(&ftmp) != -1)
{
#else
FILE *fp;
if( (fp = fopen("/proc/loadavg", "r")) != NULL)
{
fscanf(fp, "%f", &ftmp);
fclose(fp);
#endif
if(oldv != ftmp)
{
oldv = ftmp;
i=ftmp*26;
tempa=(ftmp+0.005)*100;
tempy=tempa%10;
copyXPMArea(3+(tempy*6),66,6,9,50,5);
tempy=tempa/10;
tempy=tempy%10;
copyXPMArea(3+(tempy*6),66,6,9,44,5);
copyXPMArea(65,66,3,9,41,5);
tempy=tempa/100;
if ( tempy > 9 )
{
tempy=(tempy-10);
copyXPMArea(3+(tempy*6),95,6,9,34,5);
} else {
copyXPMArea(3+(tempy*6),66,6,9,34,5);
}
}
}
}
/**************************************************************************/
#ifdef __solaris__
/* Mem/Swap Meter */
float DrawMemSwap
(
void
)
{
unsigned long memMax, memFree, swapMax, swapFree;
unsigned long MEMmem, MEMswap;
float memUsed, swapUsed;
int tempy, tempa;
getMem(&memMax, &memFree);
memUsed = (float)(memMax - memFree);
getSwap(&swapMax, &swapFree);
swapUsed = (float)(swapMax - swapFree);
/* MEM Meter */
if (memMax == 0)
MEMmem = 0;
else
{
if (((float)memMax / 1048576) >= 1)
MEMmem = ((memUsed * 31) / (float)memMax);
else
MEMmem = ((memUsed * 36) / (float)memMax);
}
// refresh
copyXPMArea(4, 115, 55, 11, 4, 18);
// Bar
copyXPMArea(3, 75, MEMmem, 9, 5, 19);
copyXPMArea(15, 105, (36 - MEMmem), 9, (5 + MEMmem), 19);
// Numbers
tempa = (memUsed / 1048576);
tempy = (tempa % 10);
copyXPMArea((3 + (tempy * 6)), 66, 6, 9, 50, 19);
tempy = ((tempa / 10) % 10);
copyXPMArea((3 + (tempy * 6)), 66, 6, 9, 44, 19);
tempy = ((tempa / 100) % 10);
if (tempy != 0)
{
copyXPMArea((3 + (tempy * 6)), 66, 6, 9, 38, 19);
copyXPMArea(16, 46, 2, 14, 35, 16);
}
else
{
copyXPMArea(16, 46, 2, 14, 41, 16);
}
// refresh
copyXPMArea(4, 115, 55, 11, 4, 32);
/* SWAP Meter */
if (swapMax == 0)
MEMswap = 0;
else
{
if (((float)swapMax / 1048576) >= 1)
MEMswap = ((swapUsed * 31) / (float)swapMax);
else
MEMswap = ((swapUsed * 36) / (float)swapMax);
}
// Bar
copyXPMArea(3, 75, MEMswap, 9, 5, 33);
copyXPMArea(15, 105, (36 - MEMswap), 9, (5 + MEMswap), 33);
// Numbers
tempa = (swapUsed / 1048576);
tempy = (tempa % 10);
copyXPMArea((3 + (tempy * 6)), 66, 6, 9, 50, 33);
tempy = ((tempa / 10) % 10);
copyXPMArea((3 + (tempy * 6)), 66, 6, 9, 44, 33);
tempy = ((tempa / 100) % 10);
if (tempy != 0)
{
copyXPMArea((3 + (tempy * 6)), 66, 6, 9, 38, 33);
copyXPMArea(16, 46, 2, 14, 42, 16);
}
else
{
copyXPMArea(16, 46, 2, 14, 41, 30);
}
return (float)memMax;
}
#else
/* Mem/Swap Meter */
float DrawMemSwap(float total, int allmem)
{
FILE *fp;
if( (fp = fopen("/proc/meminfo", "r")) != NULL)
{
static float stotal=0.0, sshared=0.0, sbuffers=0.0, scached=0.0;
char junk[128];
float used, freeM, shared, buffers, cached, swaptotal,
swapused, swapfreeM;
unsigned long MEMshar,MEMbuff,MEMcach, MEMswap;
int tempy, tempa;
if( has_kern26 > 0 )
{
float scratch;
while(!feof(fp))
{
fgets(junk, 120, fp);
if (strstr(junk, "MemTotal"))
{
sscanf(junk, "MemTotal: %f kB", &scratch);
total = scratch * 1024;
}
if (strstr(junk, "MemFree"))
{
sscanf(junk, "MemFree: %f kB", &scratch);
freeM = scratch * 1024;
used = total - freeM;
}
if (strstr(junk, "Buffers"))
{
sscanf(junk, "Buffers: %f kB", &scratch);
buffers = scratch * 1024;
}
if (strstr(junk, "Cached"))
{
sscanf(junk, "Cached: %f kB", &scratch);
cached = scratch * 1024;
}
if (strstr(junk, "SwapTotal"))
{
sscanf(junk, "SwapTotal: %f kB", &scratch);
swaptotal = scratch * 1024;
}
if (strstr(junk, "SwapFree"))
{
sscanf(junk, "SwapFree: %f kB", &scratch);
swapfreeM = scratch * 1024;
swapused = swaptotal - swapfreeM;
}
}
} else {
fgets(junk, 80, fp);
fscanf(fp, "Mem: %f %f %f %f %f %f\nSwap: %f %f %f", &total,
&used, &freeM, &shared, &buffers, &cached,
&swaptotal, &swapused, &swapfreeM);
}
fclose(fp);
/* All mem areas */
if(stotal != total || sshared != shared || sbuffers != buffers || scached != cached)
{
stotal = total; sshared = shared; sbuffers = buffers; scached = cached;
if ( (total/101048576) >= 1)
{
MEMshar=((used-buffers-cached)/total)*27;
MEMbuff=(buffers/total)*27;
MEMcach=(cached/total)*27;
} else {
MEMshar=((used-buffers-cached)/total)*33;
MEMbuff=(buffers/total)*33;
MEMcach=(cached/total)*33;
}
// refresh
copyXPMArea(4, 115, 55, 11, 4, 18);
// Bar
if ( (total/101048576) >= 1)
{
copyXPMArea(3,75,((used/total)*28),9,5,19);
} else {
copyXPMArea(3,75,((used/total)*34),9,5,19);
}
// Separators
copyXPMArea(15,105,1,9,5+MEMshar,19);
copyXPMArea(15,105,1,9,7+MEMshar+MEMbuff,19);
copyXPMArea(15,105,(36-(used/total)*34),9,(5+(used/total)*34),19);
// Numbers
tempa=used/1048576;
tempy=tempa%10;
copyXPMArea(3+(tempy*6),66,6,9,50,19);
tempy=(tempa/10)%10;
copyXPMArea(3+(tempy*6),66,6,9,44,19);
tempy=(tempa/100)%10;
if ( (total/101048576) >= 1) {
copyXPMArea(3+(tempy*6),66,6,9,38,19);
copyXPMArea(16,46,2,14,35,16);
} else {
copyXPMArea(16,46,2,14,41,16);
}
}
/* SWAP Meter */
if ( swaptotal == 0 ) MEMswap = 0;
else {
if ( (total/101048576) >= 1)
MEMswap=(swapused*31)/swaptotal;
else MEMswap=(swapused*36)/swaptotal;
}
// refresh
copyXPMArea(4, 115, 55, 11, 4, 32);
// Bar
copyXPMArea(3,75,MEMswap,9,5,33);
copyXPMArea(15,105,(36-(MEMswap)),9,5+MEMswap,33);
// Numbers
tempa=swapused/1048576;
tempy=tempa%10;
copyXPMArea(3+(tempy*6),66,6,9,50,33);
tempy=(tempa/10)%10;
copyXPMArea(3+(tempy*6),66,6,9,44,33);
tempy=tempa/100;
if ( tempy != 0 ) {
copyXPMArea(3+(tempy*6),66,6,9,38,33);
copyXPMArea(16,46,2,14,35,30);
} else {
copyXPMArea(16,46,2,14,41,30);
}
}
return(total);
}
#endif
/**************************************************************************/
#ifndef __solaris__
/* X Mem Usage */
void DrawXmem(int Xpid, float total)
{
FILE *fp;
char buf[128], XFileName[256];
float ratio;
long old_Xsize=-1, Xsize=0;
sprintf(XFileName, "/proc/%d/status", Xpid);
if ((fp = fopen(XFileName, "r")) != NULL)
{
while( fgets(buf, 127, fp) )
{
if (strstr(buf, "VmSize"))
sscanf(buf, "VmSize: %ld", &Xsize);
}
if(old_Xsize!=Xsize)
{
int tempy, tempa, tempb;
old_Xsize=Xsize;
ratio=Xsize/(total/1024);
if ( Xsize > (total/1024) ) Xsize=total/1024;
Xsize=Xsize/1024;
tempy=Xsize%10;
copyXPMArea(3+(tempy*6),66,6,9,50,48);
tempa=Xsize/10;
tempy=tempa%10;
tempb=Xsize/100;
if ( Xsize > 100 )
{
copyXPMArea(3,84,((ratio)*17),11,18,47);
copyXPMArea(15,105,(23-((ratio)*17)),11,(18+(ratio*22)),47);
copyXPMArea(3+(tempy*6),66,6,9,44,48);
copyXPMArea(3+(tempb*6),66,6,9,38,48);
copyXPMArea(16,46,2,14,36,46);
} else {
copyXPMArea(3,84,((ratio)*22),11,18,47);
copyXPMArea(15,105,(23-((ratio)*22)),11,(18+(ratio*22)),47);
copyXPMArea(3+(tempy*6),66,6,9,44,48);
copyXPMArea(16,46,2,14,41,46);
}
}
fclose(fp);
}
}
#endif
/**************************************************************************/
/* Uptime */
void DrawUptime(void)
{
int upt, days=0,hours=0,mins=0, old_mins=-1,old_hours=-1;
#ifdef __solaris__
struct utmp * pUtmp;
struct utmp idUtmp;
idUtmp.ut_type = BOOT_TIME;
setutent();
pUtmp = getutid(&idUtmp);
upt = (time(0) - pUtmp->ut_time);
#else
FILE *fp;
if( (fp = fopen("/proc/uptime", "r")) != NULL)
fscanf(fp, "%d",&upt);
fclose(fp);
#endif
mins=(upt/60)%60;
hours=(upt/3600)%24;
days=(upt/86400);
if(old_hours!=hours)
old_hours=hours;
if(old_mins!=mins)
{
int tempy;
old_mins=mins;
if ( days > 9 )
{
copyXPMArea(20,105,36,9,18,48);
tempy=hours%10;
copyXPMArea(3+(tempy*6),66,6,9,50,48);
tempy=hours/10;
copyXPMArea(3+(tempy*6),66,6,9,44,48);
copyXPMArea(63,66,3,9,41,48);
tempy=days%10;
copyXPMArea(3+(tempy*6),66,6,9,34,48);
tempy=(days/10)%10;
copyXPMArea(3+(tempy*6),66,6,9,28,48);
tempy=days/100;
copyXPMArea(3+(tempy*6),66,6,9,22,48);
} else {
tempy=mins%10;
copyXPMArea(3+(tempy*6),66,6,9,50,48);
tempy=mins/10;
copyXPMArea(3+(tempy*6),66,6,9,44,48);
copyXPMArea(63,66,3,9,41,48);
tempy=hours%10;
copyXPMArea(3+(tempy*6),66,6,9,34,48);
tempy=hours/10;
copyXPMArea(3+(tempy*6),66,6,9,28,48);
copyXPMArea(63,66,3,9,25,48);
tempy=days%10;
copyXPMArea(3+(tempy*6),66,6,9,18,48);
}
}
}
/**************************************************************************/
/* Drawing LED's */
void DrawLite(int state, int dx, int dy)
{
switch(state)
{
case B_RED:
copyXPMArea(BREDX, BREDY, LITEW, LITEH, dx, dy);
break;
case B_GREEN:
copyXPMArea(BGREENX, BGREENY, LITEW, LITEH, dx, dy);
break;
default:
case B_OFF:
copyXPMArea(BOFFX, BOFFY, LITEW, LITEH, dx, dy);
break;
}
}
/* EOF */

BIN
asmon/asmon/asmon.o Normal file

Binary file not shown.

262
asmon/asmon/solaris26.c Normal file
View file

@ -0,0 +1,262 @@
/*
* Routines for Solaris.
*
* Note that this might not work on differnet versions of Solaris. The
* reason being is that the kstat variables can change from version to
* version. Read the kvm and kstat man pages to see what Sun says
* about it. Also there is no 'real' way to find out the implemented
* kernel variables! There is an undocumented feature to netstat which
* walks the kstat chain. The output sort of makes sense for kernel
* hackers. Anyways use 'netstat -k'.
*
* The code is GPL'ed. See the asmon COPYING file that comes with the
* distribution. The only thing I add is that if you use this code
* and we meet sometime, then you can buy me a beer. Happy monitoring.
*
* Eric Davis <ead@pobox.com>
*/
#include <kstat.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <sys/cpuvar.h>
#include <sys/swap.h>
#include <sys/param.h>
typedef struct swapent SWAP_ENT_T;
typedef struct swaptable SWAP_TABLE_T;
typedef unsigned long ULONG;
static int err
(
char * msg
)
{
perror(msg);
return -1;
}
int getLoad
(
float * load
)
{
kstat_t * ks;
kstat_ctl_t * kc;
kstat_named_t * kn;
if ((kc = kstat_open()) == NULL)
return err("kstat_open");
if ((ks = kstat_lookup(kc, "unix", 0, "system_misc")) == NULL)
return err("kstat_lookup");
if (kstat_read(kc, ks, NULL) == -1)
return err("kstat_read");
if ((kn = kstat_data_lookup(ks, "avenrun_1min")) == NULL)
return err("kstat_data_lookup");
if (kstat_close(kc) == -1)
return err("kstat_close");
*load = ((float)kn->value.ul / FSCALE);
/* printf("load: %2.2f\n\n", *load); */
return 0;
}
int getSwap
(
ULONG * swapMax,
ULONG * swapFree
)
{
static char buf[256];
int i;
int totalSwapEntries;
SWAP_TABLE_T * swapTable;
SWAP_ENT_T * swapEntries;
TRY_AGAIN:
totalSwapEntries = swapctl(SC_GETNSWP, 0);
swapTable = (SWAP_TABLE_T *)malloc(sizeof(int) +
(totalSwapEntries *
sizeof(SWAP_ENT_T)));
swapTable->swt_n = totalSwapEntries;
for (swapEntries = &(swapTable->swt_ent[0]),
i = 0; i < totalSwapEntries; i++, swapEntries++)
{
swapEntries->ste_path = buf;
}
if (swapctl(SC_LIST, swapTable) == -1)
{
/* Retry if our swap table was too small else bail */
free(swapTable);
perror("swapctl");
if (errno == ENOMEM) goto TRY_AGAIN;
else return -1;
}
for (swapEntries = &(swapTable->swt_ent[0]), *swapMax = *swapFree = 0,
i = 0; i < totalSwapEntries; i++, swapEntries++)
{
if (!(swapEntries->ste_flags & ST_INDEL) &&
!(swapEntries->ste_flags & ST_DOINGDEL))
{
*swapMax += swapEntries->ste_pages;
*swapFree += swapEntries->ste_free;
}
}
*swapMax *= sysconf(_SC_PAGESIZE);
*swapFree *= sysconf(_SC_PAGESIZE);
/*
printf("swap max: %ld\nswap free: %ld\nswap used: %ld\n\n",
*swapMax, *swapFree, (*swapMax - *swapFree));
*/
free(swapTable);
return 0;
}
int getMem
(
ULONG * memMax,
ULONG * memFree
)
{
kstat_t * ks;
kstat_ctl_t * kc;
kstat_named_t * kn;
if ((kc = kstat_open()) == NULL)
return err("kstat_open");
if ((ks = kstat_lookup(kc, "unix", 0, "system_pages")) == NULL)
return err("kstat_lookup");
if (kstat_read(kc, ks, NULL) == -1)
return err("kstat_read");
if ((kn = kstat_data_lookup(ks, "physmem")) == NULL)
return err("kstat_data_lookup");
*memMax = (kn->value.ul * sysconf(_SC_PAGESIZE));
if ((kn = kstat_data_lookup(ks, "freemem")) == NULL)
return err("kstat_data_lookup");
*memFree = (kn->value.ul * sysconf(_SC_PAGESIZE));
if (kstat_close(kc) == -1)
return err("kstat_close");
/*
printf("mem max: %ld\nmem free: %ld\nmem used: %ld\n\n",
*memMax, *memFree, (*memMax - *memFree));
*/
return 0;
}
int getCPU
(
ULONG * cpuIdle,
ULONG * cpuUser,
ULONG * cpuKern,
ULONG * cpuWait,
ULONG * pageIn,
ULONG * pageOut,
ULONG * swapIn,
ULONG * swapOut
)
{
cpu_stat_t * cpu_stat;
ULONG numCPUs;
int i;
kstat_t * ks;
kstat_ctl_t * kc;
kstat_named_t * kn;
if ((kc = kstat_open()) == NULL)
return err("kstat_open");
if ((ks = kstat_lookup(kc, "unix", 0, "system_misc")) == NULL)
return err("kstat_lookup");
if (kstat_read(kc, ks, NULL) == -1)
return err("kstat_read");
if ((kn = kstat_data_lookup(ks, "ncpus")) == NULL)
return err("kstat_data_lookup");
numCPUs = kn->value.ul;
cpu_stat = (cpu_stat_t *)malloc(numCPUs * sizeof(cpu_stat_t));
for (i = 0, ks = kc->kc_chain; ks != NULL; ks = ks->ks_next)
{
if (strncmp(ks->ks_name, "cpu_stat", 8) == 0)
{
if (kstat_read(kc, ks, &cpu_stat[i++]) == -1)
{
free(cpu_stat);
return err("kstat_read");
}
if (i > numCPUs)
{
fprintf(stderr,
"getCPU: invalid number of cpus in kstat chain\n");
free(cpu_stat);
return -1;
}
}
}
if (i != numCPUs)
{
fprintf(stderr,
"getCPU: invalid number of cpus in kstat chain\n");
free(cpu_stat);
return -1;
}
for (*cpuIdle = *cpuUser = *cpuKern = *cpuWait = 0,
*pageIn = *pageOut = *swapIn = *swapOut = 0,
i = 0; i < numCPUs; ++i)
{
*cpuIdle += cpu_stat[i].cpu_sysinfo.cpu[CPU_IDLE];
*cpuUser += cpu_stat[i].cpu_sysinfo.cpu[CPU_USER];
*cpuKern += cpu_stat[i].cpu_sysinfo.cpu[CPU_KERNEL];
*cpuWait += cpu_stat[i].cpu_sysinfo.cpu[CPU_WAIT];
*pageIn += cpu_stat[i].cpu_vminfo.pgpgin;
*pageOut += cpu_stat[i].cpu_vminfo.pgpgout;
*swapIn += cpu_stat[i].cpu_vminfo.pgswapin;
*swapOut += cpu_stat[i].cpu_vminfo.pgswapout;
}
if (kstat_close(kc) == -1)
{
free(cpu_stat);
return err("kstat_close");
}
/*
printf("num cpus: %ld\ncpu idle: %ld\ncpu user: %ld\ncpu kern: %ld\ncpu wait: %ld\npage in: %ld\npage out: %ld\nswap in: %ld\nswap out: %ld\n\n",
numCPUs, *cpuIdle, *cpuUser, *cpuKern, *cpuWait,
*pageIn, *pageOut, *swapIn, *swapOut);
*/
free(cpu_stat);
return 0;
}

169
asmon/wmgeneral/list.c Normal file
View file

@ -0,0 +1,169 @@
/* Generic single linked list to keep various information
Copyright (C) 1993, 1994 Free Software Foundation, Inc.
Author: Kresten Krab Thorup
Many modifications by Alfredo K. Kojima
This file is part of GNU CC.
GNU CC is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU CC is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU CC; see the file COPYING. If not, write to
the Free Software Foundation, 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
/* As a special exception, if you link this library with files compiled with
GCC to produce an executable, this does not cause the resulting executable
to be covered by the GNU General Public License. This exception does not
however invalidate any other reasons why the executable file might be
covered by the GNU General Public License. */
#include "list.h"
#ifdef HAVE_SYS_TYPES_H
# include <sys/types.h>
#endif
#include <stdlib.h>
/* Return a cons cell produced from (head . tail) */
INLINE LinkedList*
list_cons(void* head, LinkedList* tail)
{
LinkedList* cell;
cell = (LinkedList*)malloc(sizeof(LinkedList));
cell->head = head;
cell->tail = tail;
return cell;
}
/* Return the length of a list, list_length(NULL) returns zero */
INLINE int
list_length(LinkedList* list)
{
int i = 0;
while(list)
{
i += 1;
list = list->tail;
}
return i;
}
/* Return the Nth element of LIST, where N count from zero. If N
larger than the list length, NULL is returned */
INLINE void*
list_nth(int index, LinkedList* list)
{
while(index-- != 0)
{
if(list->tail)
list = list->tail;
else
return 0;
}
return list->head;
}
/* Remove the element at the head by replacing it by its successor */
INLINE void
list_remove_head(LinkedList** list)
{
if (!*list) return;
if ((*list)->tail)
{
LinkedList* tail = (*list)->tail; /* fetch next */
*(*list) = *tail; /* copy next to list head */
free(tail); /* free next */
}
else /* only one element in list */
{
free(*list);
(*list) = 0;
}
}
/* Remove the element with `car' set to ELEMENT */
/*
INLINE void
list_remove_elem(LinkedList** list, void* elem)
{
while (*list)
{
if ((*list)->head == elem)
list_remove_head(list);
*list = (*list ? (*list)->tail : NULL);
}
}*/
INLINE LinkedList *
list_remove_elem(LinkedList* list, void* elem)
{
LinkedList *tmp;
if (list) {
if (list->head == elem) {
tmp = list->tail;
free(list);
return tmp;
}
list->tail = list_remove_elem(list->tail, elem);
return list;
}
return NULL;
}
/* Return element that has ELEM as car */
INLINE LinkedList*
list_find(LinkedList* list, void* elem)
{
while(list)
{
if (list->head == elem)
return list;
list = list->tail;
}
return NULL;
}
/* Free list (backwards recursive) */
INLINE void
list_free(LinkedList* list)
{
if(list)
{
list_free(list->tail);
free(list);
}
}
/* Map FUNCTION over all elements in LIST */
INLINE void
list_mapcar(LinkedList* list, void(*function)(void*))
{
while(list)
{
(*function)(list->head);
list = list->tail;
}
}

59
asmon/wmgeneral/list.h Normal file
View file

@ -0,0 +1,59 @@
/* Generic single linked list to keep various information
Copyright (C) 1993, 1994 Free Software Foundation, Inc.
Author: Kresten Krab Thorup
This file is part of GNU CC.
GNU CC is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU CC is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU CC; see the file COPYING. If not, write to
the Free Software Foundation, 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
/* As a special exception, if you link this library with files compiled with
GCC to produce an executable, this does not cause the resulting executable
to be covered by the GNU General Public License. This exception does not
however invalidate any other reasons why the executable file might be
covered by the GNU General Public License. */
#ifndef __LIST_H_
#define __LIST_H_
#if defined(__GNUC__) && !defined(__STRICT_ANSI__)
# define INLINE inline
#else
# define INLINE
#endif
typedef struct LinkedList {
void *head;
struct LinkedList *tail;
} LinkedList;
INLINE LinkedList* list_cons(void* head, LinkedList* tail);
INLINE int list_length(LinkedList* list);
INLINE void* list_nth(int index, LinkedList* list);
INLINE void list_remove_head(LinkedList** list);
INLINE LinkedList *list_remove_elem(LinkedList* list, void* elem);
INLINE void list_mapcar(LinkedList* list, void(*function)(void*));
INLINE LinkedList*list_find(LinkedList* list, void* elem);
INLINE void list_free(LinkedList* list);
#endif

BIN
asmon/wmgeneral/list.o Normal file

Binary file not shown.

164
asmon/wmgeneral/misc.c Normal file
View file

@ -0,0 +1,164 @@
/* dock.c- built-in Dock module for WindowMaker
*
* WindowMaker window manager
*
* Copyright (c) 1997 Alfredo K. Kojima
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <stdlib.h>
#include <string.h>
#include "list.h"
#include "misc.h"
/*
*----------------------------------------------------------------------
* parse_command--
* Divides a command line into a argv/argc pair.
*----------------------------------------------------------------------
*/
#define PRC_ALPHA 0
#define PRC_BLANK 1
#define PRC_ESCAPE 2
#define PRC_DQUOTE 3
#define PRC_EOS 4
#define PRC_SQUOTE 5
typedef struct {
short nstate;
short output;
} DFA;
static DFA mtable[9][6] = {
{{3,1},{0,0},{4,0},{1,0},{8,0},{6,0}},
{{1,1},{1,1},{2,0},{3,0},{5,0},{1,1}},
{{1,1},{1,1},{1,1},{1,1},{5,0},{1,1}},
{{3,1},{5,0},{4,0},{1,0},{5,0},{6,0}},
{{3,1},{3,1},{3,1},{3,1},{5,0},{3,1}},
{{-1,-1},{0,0},{0,0},{0,0},{0,0},{0,0}}, /* final state */
{{6,1},{6,1},{7,0},{6,1},{5,0},{3,0}},
{{6,1},{6,1},{6,1},{6,1},{5,0},{6,1}},
{{-1,-1},{0,0},{0,0},{0,0},{0,0},{0,0}}, /* final state */
};
char*
next_token(char *word, char **next)
{
char *ptr;
char *ret, *t;
int state, ctype;
t = ret = malloc(strlen(word)+1);
ptr = word;
state = 0;
*t = 0;
while (1) {
if (*ptr==0)
ctype = PRC_EOS;
else if (*ptr=='\\')
ctype = PRC_ESCAPE;
else if (*ptr=='"')
ctype = PRC_DQUOTE;
else if (*ptr=='\'')
ctype = PRC_SQUOTE;
else if (*ptr==' ' || *ptr=='\t')
ctype = PRC_BLANK;
else
ctype = PRC_ALPHA;
if (mtable[state][ctype].output) {
*t = *ptr; t++;
*t = 0;
}
state = mtable[state][ctype].nstate;
ptr++;
if (mtable[state][0].output<0) {
break;
}
}
if (*ret==0)
t = NULL;
else
t = strdup(ret);
free(ret);
if (ctype==PRC_EOS)
*next = NULL;
else
*next = ptr;
return t;
}
extern void
parse_command(char *command, char ***argv, int *argc)
{
LinkedList *list = NULL;
char *token, *line;
int count, i;
line = command;
do {
token = next_token(line, &line);
if (token) {
list = list_cons(token, list);
}
} while (token!=NULL && line!=NULL);
count = list_length(list);
*argv = malloc(sizeof(char*)*count);
i = count;
while (list!=NULL) {
(*argv)[--i] = list->head;
list_remove_head(&list);
}
*argc = count;
}
extern pid_t
execCommand(char *command)
{
pid_t pid;
char **argv;
int argc;
parse_command(command, &argv, &argc);
if (argv==NULL) {
return 0;
}
if ((pid=fork())==0) {
char **args;
int i;
args = malloc(sizeof(char*)*(argc+1));
if (!args)
exit(10);
for (i=0; i<argc; i++) {
args[i] = argv[i];
}
args[argc] = NULL;
execvp(argv[0], args);
exit(10);
}
return pid;
}

9
asmon/wmgeneral/misc.h Normal file
View file

@ -0,0 +1,9 @@
#ifndef __MISC_H
#define __MISC_H
#include <unistd.h>
extern void parse_command(char *, char ***, int *);
extern pid_t execCommand(char *);
#endif /* __MISC_H */

BIN
asmon/wmgeneral/misc.o Normal file

Binary file not shown.

366
asmon/wmgeneral/wmgeneral.c Normal file
View file

@ -0,0 +1,366 @@
/*
Best viewed with vim5, using ts=4
wmgeneral was taken from wmppp.
It has a lot of routines which most of the wm* programs use.
------------------------------------------------------------
Author: Martijn Pieterse (pieterse@xs4all.nl)
---
CHANGES:
---
02/05/1998 (Martijn Pieterse, pieterse@xs4all.nl)
* changed the read_rc_file to parse_rcfile, as suggester by Marcelo E. Magallon
* debugged the parse_rc file.
30/04/1998 (Martijn Pieterse, pieterse@xs4all.nl)
* Ripped similar code from all the wm* programs,
and put them in a single file.
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <ctype.h>
#include <stdarg.h>
#include <X11/Xlib.h>
#include <X11/xpm.h>
#include <X11/extensions/shape.h>
#include "wmgeneral.h"
/*****************/
/* X11 Variables */
/*****************/
Window Root;
int screen;
int x_fd;
int d_depth;
XSizeHints mysizehints;
XWMHints mywmhints;
Pixel back_pix, fore_pix;
char *Geometry = "";
Window iconwin, win;
GC NormalGC;
XpmIcon wmgen;
Pixmap pixmask;
/*****************/
/* Mouse Regions */
/*****************/
typedef struct {
int enable;
int top;
int bottom;
int left;
int right;
} MOUSE_REGION;
#define MAX_MOUSE_REGION (8)
MOUSE_REGION mouse_region[MAX_MOUSE_REGION];
/***********************/
/* Function Prototypes */
/***********************/
static void GetXPM(XpmIcon *, char **);
static Pixel GetColor(char *);
void RedrawWindow(void);
void AddMouseRegion(int, int, int, int, int);
int CheckMouseRegion(int, int);
/*******************************************************************************\
|* read_rc_file *|
\*******************************************************************************/
void parse_rcfile(const char *filename, rckeys *keys) {
char *p;
char temp[128];
char *tokens = " :\t\n";
FILE *fp;
int i,key;
fp = fopen(filename, "r");
if (fp) {
while (fgets(temp, 128, fp)) {
key = 0;
while (key >= 0 && keys[key].label) {
if ((p = strstr(temp, keys[key].label))) {
p += strlen(keys[key].label);
p += strspn(p, tokens);
if ((i = strcspn(p, "#\n"))) p[i] = 0;
free(*keys[key].var);
*keys[key].var = strdup(p);
key = -1;
} else key++;
}
}
fclose(fp);
}
}
/*******************************************************************************\
|* GetXPM *|
\*******************************************************************************/
static void GetXPM(XpmIcon *wmgen, char *pixmap_bytes[]) {
XWindowAttributes attributes;
int err;
/* For the colormap */
XGetWindowAttributes(display, Root, &attributes);
wmgen->attributes.valuemask |= (XpmReturnPixels | XpmReturnExtensions);
err = XpmCreatePixmapFromData(display, Root, pixmap_bytes, &(wmgen->pixmap),
&(wmgen->mask), &(wmgen->attributes));
if (err != XpmSuccess) {
fprintf(stderr, "Not enough free colorcells.\n");
exit(1);
}
}
/*******************************************************************************\
|* GetColor *|
\*******************************************************************************/
static Pixel GetColor(char *name) {
XColor color;
XWindowAttributes attributes;
XGetWindowAttributes(display, Root, &attributes);
color.pixel = 0;
if (!XParseColor(display, attributes.colormap, name, &color)) {
fprintf(stderr, "wm.app: can't parse %s.\n", name);
} else if (!XAllocColor(display, attributes.colormap, &color)) {
fprintf(stderr, "wm.app: can't allocate %s.\n", name);
}
return color.pixel;
}
/*******************************************************************************\
|* flush_expose *|
\*******************************************************************************/
static int flush_expose(Window w) {
XEvent dummy;
int i=0;
while (XCheckTypedWindowEvent(display, w, Expose, &dummy))
i++;
return i;
}
/*******************************************************************************\
|* RedrawWindow *|
\*******************************************************************************/
void RedrawWindow(void) {
flush_expose(iconwin);
XCopyArea(display, wmgen.pixmap, iconwin, NormalGC,
0,0, wmgen.attributes.width, wmgen.attributes.height, 0,0);
flush_expose(win);
XCopyArea(display, wmgen.pixmap, win, NormalGC,
0,0, wmgen.attributes.width, wmgen.attributes.height, 0,0);
}
/*******************************************************************************\
|* RedrawWindowXY *|
\*******************************************************************************/
void RedrawWindowXY(int x, int y) {
flush_expose(iconwin);
XCopyArea(display, wmgen.pixmap, iconwin, NormalGC,
x,y, wmgen.attributes.width, wmgen.attributes.height, 0,0);
flush_expose(win);
XCopyArea(display, wmgen.pixmap, win, NormalGC,
x,y, wmgen.attributes.width, wmgen.attributes.height, 0,0);
}
/*******************************************************************************\
|* AddMouseRegion *|
\*******************************************************************************/
void AddMouseRegion(int index, int left, int top, int right, int bottom) {
if (index < MAX_MOUSE_REGION) {
mouse_region[index].enable = 1;
mouse_region[index].top = top;
mouse_region[index].left = left;
mouse_region[index].bottom = bottom;
mouse_region[index].right = right;
}
}
/*******************************************************************************\
|* CheckMouseRegion *|
\*******************************************************************************/
int CheckMouseRegion(int x, int y) {
int i;
int found;
found = 0;
for (i=0; i<MAX_MOUSE_REGION && !found; i++) {
if (mouse_region[i].enable &&
x <= mouse_region[i].right &&
x >= mouse_region[i].left &&
y <= mouse_region[i].bottom &&
y >= mouse_region[i].top)
found = 1;
}
if (!found) return -1;
return (i-1);
}
/*******************************************************************************\
|* copyXPMArea *|
\*******************************************************************************/
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);
}
/*******************************************************************************\
|* copyXBMArea *|
\*******************************************************************************/
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);
}
/*******************************************************************************\
|* setMaskXY *|
\*******************************************************************************/
void setMaskXY(int x, int y) {
XShapeCombineMask(display, win, ShapeBounding, x, y, pixmask, ShapeSet);
XShapeCombineMask(display, iconwin, ShapeBounding, x, y, pixmask, ShapeSet);
}
/*******************************************************************************\
|* openXwindow *|
\*******************************************************************************/
void openXwindow(int argc, char *argv[], char *pixmap_bytes[], char *pixmask_bits, int pixmask_width, int pixmask_height) {
unsigned int borderwidth = 1;
XClassHint classHint;
char *display_name = NULL;
char *wname = argv[0];
XTextProperty name;
XGCValues gcv;
unsigned long gcm;
int dummy=0;
int i;
for (i=1; argv[i]; i++) {
if (!strcmp(argv[i], "-display"))
display_name = argv[i+1];
}
if (!(display = XOpenDisplay(display_name))) {
fprintf(stderr, "%s: can't open display %s\n",
wname, XDisplayName(display_name));
exit(1);
}
screen = DefaultScreen(display);
Root = RootWindow(display, screen);
d_depth = DefaultDepth(display, screen);
x_fd = XConnectionNumber(display);
/* Convert XPM to XImage */
GetXPM(&wmgen, pixmap_bytes);
/* Create a window to hold the stuff */
mysizehints.flags = USSize | USPosition;
mysizehints.x = 0;
mysizehints.y = 0;
back_pix = GetColor("white");
fore_pix = GetColor("black");
XWMGeometry(display, screen, Geometry, NULL, borderwidth, &mysizehints,
&mysizehints.x, &mysizehints.y,&mysizehints.width,&mysizehints.height, &dummy);
mysizehints.width = 64;
mysizehints.height = 64;
win = XCreateSimpleWindow(display, Root, mysizehints.x, mysizehints.y,
mysizehints.width, mysizehints.height, borderwidth, fore_pix, back_pix);
iconwin = XCreateSimpleWindow(display, win, mysizehints.x, mysizehints.y,
mysizehints.width, mysizehints.height, borderwidth, fore_pix, back_pix);
/* Activate hints */
XSetWMNormalHints(display, win, &mysizehints);
classHint.res_name = wname;
classHint.res_class = wname;
XSetClassHint(display, win, &classHint);
XSelectInput(display, win, ButtonPressMask | ExposureMask | ButtonReleaseMask | PointerMotionMask | StructureNotifyMask);
XSelectInput(display, iconwin, ButtonPressMask | ExposureMask | ButtonReleaseMask | PointerMotionMask | StructureNotifyMask);
if (XStringListToTextProperty(&wname, 1, &name) == 0) {
fprintf(stderr, "%s: can't allocate window name\n", wname);
exit(1);
}
XSetWMName(display, win, &name);
/* Create GC for drawing */
gcm = GCForeground | GCBackground | GCGraphicsExposures;
gcv.foreground = fore_pix;
gcv.background = back_pix;
gcv.graphics_exposures = 0;
NormalGC = XCreateGC(display, Root, gcm, &gcv);
/* ONLYSHAPE ON */
pixmask = XCreateBitmapFromData(display, win, pixmask_bits, pixmask_width, pixmask_height);
XShapeCombineMask(display, win, ShapeBounding, 0, 0, pixmask, ShapeSet);
XShapeCombineMask(display, iconwin, ShapeBounding, 0, 0, pixmask, ShapeSet);
/* ONLYSHAPE OFF */
mywmhints.initial_state = WithdrawnState;
mywmhints.icon_window = iconwin;
mywmhints.icon_x = mysizehints.x;
mywmhints.icon_y = mysizehints.y;
mywmhints.window_group = win;
mywmhints.flags = StateHint | IconWindowHint | IconPositionHint | WindowGroupHint;
XSetWMHints(display, win, &mywmhints);
XSetCommand(display, win, argv, argc);
XMapWindow(display, win);
}

View file

@ -0,0 +1,50 @@
#ifndef WMGENERAL_H_INCLUDED
#define WMGENERAL_H_INCLUDED
/***********/
/* Defines */
/***********/
#define MAX_MOUSE_REGION (8)
/************/
/* Typedefs */
/************/
typedef struct _rckeys rckeys;
struct _rckeys {
const char *label;
char **var;
};
typedef struct {
Pixmap pixmap;
Pixmap mask;
XpmAttributes attributes;
} XpmIcon;
/*******************/
/* Global variable */
/*******************/
Display *display;
/***********************/
/* Function Prototypes */
/***********************/
void AddMouseRegion(int index, int left, int top, int right, int bottom);
int CheckMouseRegion(int x, int y);
void openXwindow(int argc, char *argv[], char **, char *, int, int);
void RedrawWindow(void);
void RedrawWindowXY(int x, int y);
void copyXPMArea(int, int, int, int, int, int);
void copyXBMArea(int, int, int, int, int, int);
void setMaskXY(int, int);
void parse_rcfile(const char *, rckeys *);
#endif

BIN
asmon/wmgeneral/wmgeneral.o Normal file

Binary file not shown.