From: sources@anomaly.sbs.risc.net
Subject: v01i125 - u386mon v3.40, SCO UNIX Performance Monitor - Part 05/06
Reply-To: sources@anomaly.sbs.risc.net
Organization: The Rhode Island Internet Systems Cooperative Network
Date: Mon, 14 Sep 1992 14:19:11 GMT
Followup-To: biz.sco.general


#!/bin/sh
# this is part.05 (part 5 of a multipart archive)
# do not concatenate these parts, unpack them in order with /bin/sh
# file nlsym.h continued
#
if test ! -r shar3_seq_.tmp; then
	echo "Please unpack part 1 first!"
	exit 1
fi
(read Scheck
 if test "$Scheck" != 5; then
	echo "Please unpack part $Scheck next!"
	exit 1
 else
	exit 0
 fi
) < shar3_seq_.tmp || exit 1
echo "x - Continuing file nlsym.h"
sed 's/^X//' << 'SHAR_EOF' >> nlsym.h &&
X/*:06-27-1990-01:55-wht@n4hgf-use 64 bits of unique check */
X/*:06-25-1990-04:14-wht@n4hgf-1.02-better error handling */
X/*:06-24-1990-20:53-wht@n4hgf-v1.01-add ISC support thanks to peter@radig.de */
X/*:06-21-1990-14:26-r@n4hgf-version x0.12 seems bug free */
X/*:10-27-1988-11:07-wht-creation */
X
X#define UNIX_KERNEL		"/unix"
X#define UNIX_NLSYM		"/unix.nlsym"
X#define NLSYM_UNIQUE1	0x1BADD00DL
X#define NLSYM_UNIQUE2	0xDEADB1FFL
X
X#define Nindex_AVAILRMEM            0
X#define Nindex_AVAILSMEM            1
X#define Nindex_BDEVCNT              2
X#define Nindex_BDEVSW               3
X#if defined(HAS_BOOTINFO)
X#define Nindex_BOOTINFO             4
X#else
X#endif
X#define Nindex_CDEVCNT              5
X#define Nindex_CDEVSW               6
X#define Nindex_CFREE                7
X#define Nindex_CFREECNT             8
X#define Nindex_CFREELIST            9
X#define Nindex_CONSSW              10
X#define Nindex_CURPROC             11
X#define Nindex_DINFO               12
X#define Nindex_DSTFLAG             13
X#define Nindex_DUMPDEV             14
X#define Nindex_EMAP                15
X#define Nindex_FFREELIST           16
X#define Nindex_FILE                17
X#define Nindex_FMODCNT             18
X#define Nindex_FMODSW              19
X#define Nindex_FREEMEM             20
X#define Nindex_FSINFO              21
X#define Nindex_FSTYPSW             22
X#define Nindex_HZ                  23
X#define Nindex_IDLESERVER          24
X#define Nindex_IFREELIST           25
X#define Nindex_INODE               26
X#define Nindex_KPTBL               27
X#define Nindex_LBOLT               28
X#define Nindex_LINECNT             29
X#define Nindex_LINESW              30
X#define Nindex_MAXCLICK            31
X#define Nindex_MAXMEM              32
X#define Nindex_MINFO               33
X#define Nindex_MOUNT               34
X#define Nindex_MSGLISTCNT          35
X#define Nindex_NFSTYP              36
X#define Nindex_NPTALLOCED          37
X#define Nindex_NPTFREE             38
X#define Nindex_NSERVERS            39
X#define Nindex_NSWAP               40
X#define Nindex_NSYSENT             41
X#define Nindex_OLDPROC             42
X#define Nindex_OLD_CURPROC         43
X#define Nindex_PANICSTR            44
X#define Nindex_PHYSMEM             45
X#define Nindex_PIPEDEV             46
X#define Nindex_PROC                47
X#define Nindex_RCINFO              48
X#define Nindex_ROOTDEV             49
X#define Nindex_RUNQ                50
X#define Nindex_SHLBINFO            51
X#define Nindex_SWAPDEV             52
X#define Nindex_SWPLO               53
X#define Nindex_SYSERR              54
X#define Nindex_SYSINFO             55
X#define Nindex_SYSSEGS             56
X#define Nindex_SYSWAIT             57
X#define Nindex_TIME                58
X#define Nindex_TIMEZONE            59
X#define Nindex_TTHIWAT             60
X#define Nindex_TTLOWAT             61
X#define Nindex_TUNE                62
X#define Nindex_U                   63
X#define Nindex_USERTABLE           64
X#define Nindex_V                   65
X#define Nindex_WIN_UBLK            66
X#define Nindex_REGION              67
X#if defined(M_UNIX)
X#define Nindex_SIO_TTY             68
X#endif
X#if defined(M_UNIX) || defined(SVR31)
X#define Nindex_STRST		   69
X#define Nindex_RBSIZE		   70
X#define Nindex_NMBLOCK		   71
X#define Nindex_FLCKINFO		   72
X#define Nindex_RACTIVE		   73
X#define Nindex_CALLOUT		   74
X#ifdef SCO322
X#define Nindex_FLSTATS		   75
X#define Nindex_WD1010STATS	   76
X#endif
X#endif
X
X#if defined(HAS_BOOTINFO)
X#define bootinfoaddr (nlsym[Nindex_BOOTINFO].n_value)
X#endif
X#define freememaddr (nlsym[Nindex_FREEMEM].n_value)
X#define lboltaddr (nlsym[Nindex_LBOLT].n_value)
X#define maxmemaddr (nlsym[Nindex_MAXMEM].n_value)
X#define minfoaddr (nlsym[Nindex_MINFO].n_value)
X#define nswapaddr (nlsym[Nindex_NSWAP].n_value)
X#define physmemaddr (nlsym[Nindex_PHYSMEM].n_value)
X#define procaddr (nlsym[Nindex_PROC].n_value)
X#define regionaddr (nlsym[Nindex_REGION].n_value)
X#define sysinfoaddr (nlsym[Nindex_SYSINFO].n_value)
X#define tuneaddr (nlsym[Nindex_TUNE].n_value)
X#define vaddr (nlsym[Nindex_V].n_value)
X#if defined(M_UNIX)
X#define sio_ttyaddr (nlsym[Nindex_SIO_TTY].n_value)
X#endif
X#if defined(M_UNIX) || defined(SVR31)
X#define strstaddr (nlsym[Nindex_STRST].n_value)
X#define rbsizeaddr (nlsym[Nindex_RBSIZE].n_value)
X#define nmblockaddr (nlsym[Nindex_NMBLOCK].n_value)
X#define flckinfoaddr (nlsym[Nindex_FLCKINFO].n_value)
X#define fileaddr (nlsym[Nindex_FILE].n_value)
X#define ifreelistaddr (nlsym[Nindex_IFREELIST].n_value)
X#define inodeaddr (nlsym[Nindex_INODE].n_value)
X#define ffreelistaddr (nlsym[Nindex_FFREELIST].n_value)
X#define ractiveaddr (nlsym[Nindex_RACTIVE].n_value)
X#define cfreecntaddr (nlsym[Nindex_CFREECNT].n_value)
X#define calloutaddr (nlsym[Nindex_CALLOUT].n_value)
X#endif /* defined(M_UNIX) || defined(SVR31) */
X#ifdef SCO322
X#define flstatsaddr (nlsym[Nindex_FLSTATS].n_value)
X#define wd1010statsaddr (nlsym[Nindex_WD1010STATS].n_value)
X#endif /* SCO322 */
X
X#ifdef DEFINE_NLSYM
Xstruct nlist nlsym[] =
X{
X	{ "availrmem" },
X	{ "availsmem" },
X	{ "bdevcnt" },
X	{ "bdevsw" },
X#if defined(HAS_BOOTINFO)
X	{ "bootinfo" },
X#else
X	{ "spl" },	/*
X				 * dummy argument: unique text symbol present in all
X				 * implimenations (function name helps ensure uniqueness
X				 * since we don't "do" text)
X				 */
X#endif
X	{ "cdevcnt" },
X	{ "cdevsw" },
X	{ "cfree" },
X	{ "cfreecnt" },
X	{ "cfreelist" },
X	{ "conssw" },
X	{ "curproc" },
X	{ "dinfo" },
X	{ "Dstflag" },
X	{ "dumpdev" },
X	{ "emap" },
X	{ "ffreelist" },
X	{ "file" },
X	{ "fmodcnt" },
X	{ "fmodsw" },
X	{ "freemem" },
X	{ "fsinfo" },
X	{ "fstypsw" },
X	{ "Hz" },
X	{ "idleserver" },
X	{ "ifreelist" },
X	{ "inode" },
X	{ "kptbl" },
X	{ "lbolt" },
X	{ "linecnt" },
X	{ "linesw" },
X	{ "maxclick" },
X	{ "maxmem" },
X	{ "minfo" },
X	{ "mount" },
X	{ "msglistcnt" },
X	{ "nfstyp" },
X	{ "nptalloced" },
X	{ "nptfree" },
X	{ "nservers" },
X	{ "nswap" },
X	{ "nsysent" },
X	{ "oldproc" },
X	{ "old_curproc" },
X	{ "panicstr" },
X	{ "physmem" },
X	{ "pipedev" },
X	{ "proc" },
X	{ "rcinfo" },
X	{ "rootdev" },
X	{ "runq" },
X	{ "shlbinfo" },
X	{ "swapdev" },
X	{ "swplo" },
X	{ "syserr" },
X	{ "sysinfo" },
X	{ "syssegs" },
X	{ "syswait" },
X	{ "time" },
X	{ "Timezone" },
X	{ "tthiwat" },
X	{ "ttlowat" },
X	{ "tune" },
X	{ "u" },
X	{ "usertable" },
X	{ "v" },
X	{ "win_ublk" },
X	{ "region" },
X#if defined(M_UNIX)
X	{ "sio_tty" },
X#else
X	{ "spl" },
X#endif
X#if defined(M_UNIX) || defined(SVR31)
X	{ "strst" },
X	{ "rbsize" },
X	{ "nmblock" },
X	{ "flckinfo" },
X	{ "ractive" },
X	{ "callout" },
X#ifdef SCO322
X	{ "flstats" },
X	{ "wd1010stats" },
X#endif
X#endif
X	{ (char *)0 }
X};
X#else
Xextern struct nlist nlsym[];
X#endif
X
X/* vi: set tabstop=4 shiftwidth=4: */
SHAR_EOF
echo "File nlsym.h is complete" &&
# ============= panel/README ==============
if test ! -d 'panel'; then
    echo "x - creating directory panel"
    mkdir 'panel'
fi
echo "x - extracting panel/README (Text)"
sed 's/^X//' << 'SHAR_EOF' > panel/README &&
XLIBPANEL 1.2 README - last revised Wed Jul 25 01:07:33 EDT 1990
X
XThis is a public domain implementation of the S5R3 terminfo
Xcurses panels layer.  It was written primarily to assist in
Xporting u386mon 2.0 (comp.sources.misc v14i001-4) to systems
Xlacking panels support.  It meets those needs and may be
Xuseful in other applications.  u386mon 2.10 and beyond use
Xthe package.
X
XFUNCTIONALITY
X-------------
X
XPanels are terminfo curses(3) windows with the added feature of depth.
XPanel functions allow the use of stacked windows and ensure the proper
Xportions of each window and the curses stdscr window are hidden or
Xdisplayed when panels are added, moved, modified or removed.  The set
Xof currently visible panels is the stack of panels.  Stdscr beneath
Xall panels, and is not considered part of the stack.
X
XA window is associated with every panel.  The panel routines enable
Xyou to create, move, hides, and show panels, as well as position a
Xpanel at an appropriate position in the stack.
X
XPanel routines are a functional layer added to terminfo curses(3),
Xmake only high-level curses calls, and work anywhere terminfo curses
Xdoes.
X
XCOMPATIBILITY
X-------------
X
XReasonable care has been taken to ensure compatibility with the native
Xpanel facility introducted with S5R3.2.  The PANEL data structures are
Xmerely similar.  The programmer is cautioned not to directly use
X'PANEL' fields.
X
XThe functions show_panel() and top_panel() are identical in thes
Ximplementation, and work equally well with displayed or hidden panels.
XIn the native implementation, show_panel() is intended for making a
Xhidden panel visible (at the top of the stack) and top_panel() is
Xintended for making an already-visible panel move to the top of the
Xstack.  You are cautioned to use the correct function to ensure
Xcompatibility with native panel libraries.
X
XUSE
X---
X
XTo make this panels implementation work for you, install
Xpanel.h in /usr/include or modify each of your panel-using
Xsources in a fashion similar to:
X
Xold:
X#include <curses.h>
X#include <panel.h>
X
Xnew:
X#include <curses.h>
X#ifdef NATIVE_PANELS
X#include <panel.h>
X#else
X#include "panel.h"
X#endif
X
XInclude libpanel.o in your link line and panel away.
X
XCOMPILE TIME SWITCHES
X---------------------
X__STDC__ is used to detect nouveau compilers.  Depending on who/where
Xyou are, on what day of the week, The Great Programmer help you.
XI only use it to satisfy lint that malloc is a good function to use.
X
XLINT_ARGS causes a Microsoft 5.1 flavor of function prototypes to
Xbe used.
X
XNATIVE_PANELS is detected by panel.h.  If NATIVE_PANELS *is* defined,
Xthen an error is emited to keep you from using the wrong panel.h.
X
XTESTING
X-------
X
XA rudimentary test program, PTEST, is supplied.  It requires
Xthe nap() system call.  If You do not have nap, add -DNONAP
Xto your CFLAGS line.
X
X
XComments are appreciated, especially bug fixes and information
Xhelping to port the module to another system.
X
XNO FSF, LPF, FOO or LSD -- just free.
X
XWarren Tucker N4HGF
X{gatech,emory}!n4hgf!wht -or- wht@n4hgf.Mt-Park.GA.US
SHAR_EOF
# ============= panel/panel.3 ==============
echo "x - extracting panel/panel.3 (Text)"
sed 's/^X//' << 'SHAR_EOF' > panel/panel.3 &&
X.\" @(#)panel.3	1.1 7/23/90
X.TH PANEL 3 "23 July 1990" "wht@n4hgf"
X.SH NAME
Xpanel - surrogate PANEL library routines
X.SH SYNTAX
X.B "include "panel.h"
X
X.B "cc [flags] sourcefiles libpanel.[co] -lcurses -[otherlibs]
X
X.B "PANEL *new_panel(win);"
X.br
XWINDOW *win;
X
X.B "int bottom_panel(pan);"
X.br
XPANEL *pan;
X
X.B "int top_panel(pan);"
X.br
XPANEL *pan;
X
X.B "int show_panel(pan);"
X.br
XPANEL *pan;
X
X.B "void update_panels();"
X
X.B "int hide_panel(pan);"
X.br
XPANEL *pan;
X
X.B "WINDOW *panel_window(pan);"
X.br
XPANEL *pan;
X
X.B "int replace_panel(pan,window);"
X.br
XPANEL *pan;
X.br
XWINDOW *window;
X
X.B "int move_panel(pan,starty,startx);"
X.br
XPANEL *pan;
X.br
Xint starty;
X.br
Xint startx;
X
X.B "int panel_hidden(pan);"
X.br
XPANEL *pan;
X
X.B "PANEL *panel_above(pan);"
X.br
XPANEL *pan;
X
X.B "PANEL *panel_below(pan);"
X.br
XPANEL *pan;
X
X.B "int set_panel_userptr(pan,ptr);"
X.br
XPANEL *pan;
X.br
Xchar *ptr;
X
X.B "char *panel_userptr(pan);"
X.br
XPANEL *pan;
X
X.B "int del_panel(pan);"
X.br
XPANEL *pan;
X
X.SH DESCRIPTION
XPanels are terminfo curses(3) windows with the added feature of
Xdepth.  Panel functions allow the use of stacked windows and
Xensure the proper portions of each window and the curses stdscr
Xwindow are hidden or displayed when panels are added, moved,
Xmodified or removed.  The set of currently visible panels is the
Xstack of panels.  Stdscr beneath all panels, and is not
Xconsidered part of the stack.
X
XA window is associated with every panel.  The panel routines
Xenable you to create, move, hides, and show panels, as well as
Xposition a panel at an appropriate position in the stack.
X
XPanel routines are a functional layer added to terminfo curses(3), make
Xonly high-level curses calls, and work anywhere terminfo curses does.
X
X.SH FUNCTIONS
X.B "new_panel(win)"
Xallocates a 'PANEL',
Xassovciates it with win,
Xplaces the panel on the top of the stack (causes it to be dispalyed
Xabove any other panel) and
Xreturns a pointer to the new panel.
X
X.B "void update_panels()"
Xrefreshes the virtual screen to reflect the relations between the
Xpanels in the stack, but does not call doupdate() to refresh the
Xphysical screen.  Use this function and not wrefresh or wnoutrefresh.
Xupdate_panels() may be called more than once before a call to
Xdoupdate(), but doupdate() is the function responsible for
Xupdating the physical screen.
X.br
Xe.g.,
X.br
Xupdate_panels();   /* panel(3) call */
X.br
Xdoupdate();        /* curses(3) call */
X
X.B "del_panel(pan)"
Xremoves pan from the stack,
Xdeletes the 'PANEL', but not its associated window.
X
X.B "hide_panel(pan)"
Xremoves the panel from the panel stack and thus hides it
Xfrom view.  The 'PANEL' is not lost, merely removed
Xfrom the stack.
X
X.B "show_panel(pan)"
Xmakes a hidden panel visible by placing it on top of
Xthe panels in the panel stack.
XSee COMPATIBILITY below.
X
X.B "top_panel(pan)"
Xputs the given visible panel on top of all panels in the stack.
XSee COMPATIBILITY below.
X
X.B "bottom_panel(pan)"
Xputs panel at the bottom of all panels.
X
X.B "move_panel(pan,starty,startx)"
Xmoves the given panel window so that
Xits upper-left corner is at starty, startx.  
XIt does not change the position of the panel in the stack.
XBe sure to use this function, not mvwin(), to move a panel window.
X
X.B "replace_panel(pan,window)"
Xreplaces the current window of panel with window.
XIt does not change the position of the panel in the stack.
X
X.B "panel_above(pan)"
Xreturns a pointer to the panel above pan.  If
Xthe panel argument is (PANEL *)0, it returns a pointer to the
Xbottom panel in the stack.
X
X.B "panel_below(pan)"
Xreturns a pointer to the panel just below pan.
XIf the panel argument is (PANEL *)0,
Xit returns a pointer to the top panel in the stack.
X
X.B "set_panel_userptr(pan,ptr)"
Xsets the panel's user pointer.
X
X.B "panel_userptr(pan)"
Xreturns the user pointer for a given panel.
X
X.B "panel_window(pan)"
Xreturns a pointer to the window of panel.
X
X.SH DIAGNOSTICS
XEach routine that returns a pointer returns NULL if an error
Xoccurs.  Each routine that returns an int value returns OK if it
Xexecutes successfully and ERR if not.
X
X.SH COMPATIBILITY
XReasonable care has been taken to ensure compatibility with
Xthe native panel facility introducted with S5R3.2.  The PANEL
Xdata structures are merely  similar.  The programmer
Xis cautioned not to directly use 'PANEL' fields.
X
XThe functions show_panel() and top_panel() are identical
Xin thes implementation, and work equally well with
Xdisplayed or hidden panels.
XIn the native implementation,
Xshow_panel() is intended for making a hidden panel visible
X(at the top of the stack) and top_panel() is intended for
Xmaking an already-visible panel move to the top of the stack.
XYou are cautioned to use the correct function to ensure
Xcompatibility with native panel libraries.
X
X.SH FILES
Xpanel.h
X.br
Xlibpanel.c
X
X.SH "SEE ALSO"
Xcurses(3)
X
X.SH "AUTHOR"
Xwht@n4hgf.Mt-Park.GA.US ({emory,gatech}!n4hgf!wht), primarily
Xto assist in porting u386mon to systems without a native
Xpanels library.
SHAR_EOF
# ============= panel/ptest.c ==============
echo "x - extracting panel/ptest.c (Text)"
sed 's/^X//' << 'SHAR_EOF' > panel/ptest.c &&
X/*+-------------------------------------------------------------------------
X	ptest.c
X--------------------------------------------------------------------------*/
X/*+:EDITS:*/
X/*:07-24-1990-23:20-wht@n4hgf-move debug code to libpanel.c */
X/*:07-20-1990-18:28-wht-creation */
X
X#define M_TERMINFO
X#include <curses.h>
X#include "libpanel.h"
X
XPANEL *p1;
XPANEL *p2;
XPANEL *p3;
XPANEL *p4;
XPANEL *p5;
XWINDOW *w1;
XWINDOW *w2;
XWINDOW *w3;
XWINDOW *w4;
XWINDOW *w5;
X
Xlong nap_msec = 500L;
X
Xchar *mod[] = 
X{
X	"test ",
X	"TEST ",
X	"(**) ",
X	"*()* ",
X	"<--> ",
X	"LAST "
X};
X
X/*+-------------------------------------------------------------------------
X	wait_a_while(msec)
X--------------------------------------------------------------------------*/
Xvoid
Xwait_a_while(msec)
Xlong msec;
X{
X#ifdef NONAP
X	if(nap_msec == 1)
X		getchar();
X	else if(msec > 1000L)
X		sleep((int)msec/1000L);
X	else
X		sleep(1);
X#else
X	if(nap_msec == 1)
X		getchar();
X	else
X		nap(nap_msec);
X#endif
X}	/* end of wait_a_while */
X
X/*+-------------------------------------------------------------------------
X	saywhat(text)
X--------------------------------------------------------------------------*/
Xvoid
Xsaywhat(text)
Xchar *text;
X{
Xint y,x;
X
X#ifdef PANEL_DEBUG
X	if(!dfp)
X	{
X		dfp = fopen("p.log","w");
X		fputs("-------\n",dfp);
X	}
X	fprintf(dfp,"\n--> %s\n",text);
X#endif
X
X	wmove(stdscr,LINES - 1,0);
X	wprintw(stdscr,"%-20.20s",text);
X
X}	/* end of saywhat */
X
X/*+-------------------------------------------------------------------------
X	mkpanel(rows,cols,tly,tlx) - alloc a win and panel and associate them
X--------------------------------------------------------------------------*/
XPANEL *
Xmkpanel(rows,cols,tly,tlx)
Xint rows;
Xint cols;
Xint tly;
Xint tlx;
X{
XWINDOW *win = newwin(rows,cols,tly,tlx);
XPANEL *pan;
X
X	if(!win)
X		return((PANEL *)0);
X	if(pan = new_panel(win))
X		return(pan);
X	delwin(win);
X	return((PANEL *)0);
X}	/* end of mkpanel */
X
X/*+-------------------------------------------------------------------------
X	rmpanel(pan)
X--------------------------------------------------------------------------*/
Xvoid
Xrmpanel(pan)
XPANEL *pan;
X{
XWINDOW *win = pan->win;
X	del_panel(pan);
X	delwin(win);
X}	/* end of rmpanel */
X
X/*+-------------------------------------------------------------------------
X	pflush()
X--------------------------------------------------------------------------*/
Xvoid
Xpflush()
X{
X	update_panels();
X	doupdate();
X}	/* end of pflush */
X
X/*+-------------------------------------------------------------------------
X	fill_panel(win)
X--------------------------------------------------------------------------*/
Xfill_panel(pan)
XPANEL *pan;
X{
XWINDOW *win = pan->win;
Xchar num = *(pan->user + 1);
Xint y,x;
X
X	box(win,'|','-');
X	wmove(win,1,1);
X	wprintw(win,"-pan%c-",num);
X	for(y = 2; y < getmaxy(win) - 1; y++)
X	{
X		for(x = 1; x < getmaxx(win) - 1; x++)
X		{
X			wmove(win,y,x);
X			waddch(win,num);
X		}
X	}
X}	/* end of fill_panel */
X
X/*+-------------------------------------------------------------------------
X	main(argc,argv)
X--------------------------------------------------------------------------*/
Xmain(argc,argv)
Xint argc;
Xchar **argv;
X{
Xint itmp;
Xregister y,x;
Xlong atol();
X
X	if((argc > 1) && atol(argv[1]))
X		nap_msec = atol(argv[1]);
X
X	initscr();
X
X	for(y = 0; y < LINES - 1; y++)
X	{
X		for(x = 0; x < COLS; x++)
X			wprintw(stdscr,"%d",(y + x) % 10);
X	}
X	for(y = 0; y < 5; y++)
X	{
X		p1 = mkpanel(10,10,0,0);
X		w1 = panel_window(p1);
X		set_panel_userptr(p1,"p1");
X
X		p2 = mkpanel(14,14,5,5);
X		w2 = panel_window(p2);
X		set_panel_userptr(p2,"p2");
X
X		p3 = mkpanel(6,8,12,12);
X		w3 = panel_window(p3);
X		set_panel_userptr(p3,"p3");
X
X		p4 = mkpanel(10,10,10,30);
X		w4 = panel_window(p4);
X		set_panel_userptr(p4,"p4");
X
X		p5 = mkpanel(10,10,13,37);
X		w5 = panel_window(p5);
X		set_panel_userptr(p5,"p5");
X
X		fill_panel(p1);
X		fill_panel(p2);
X		fill_panel(p3);
X		fill_panel(p4);
X		fill_panel(p5);
X		hide_panel(p4);
X		hide_panel(p5);
X		pflush();
X		wait_a_while(nap_msec);
X
X		saywhat("h3 s1 s2 s4 s5;");
X		move_panel(p1,0,0);
X		hide_panel(p3);
X		show_panel(p1);
X		show_panel(p2);
X		show_panel(p4);
X		show_panel(p5);
X		pflush();
X		wait_a_while(nap_msec);
X
X		saywhat("s1;");
X		show_panel(p1);
X		pflush();
X		wait_a_while(nap_msec);
X
X		saywhat("s2;");
X		show_panel(p2);
X		pflush();
X		wait_a_while(nap_msec);
X
X		saywhat("m2;");
X		move_panel(p2,10,10);
X		pflush();
X		wait_a_while(nap_msec);
X
X		saywhat("s3;");
X		show_panel(p3);
X		pflush();
X		wait_a_while(nap_msec);
X
X		saywhat("m3;");
X		move_panel(p3,5,5);
X		pflush();
X		wait_a_while(nap_msec);
X
X		saywhat("b3;");
X		bottom_panel(p3);
X		pflush();
X		wait_a_while(nap_msec);
X
X		saywhat("s4;");
X		show_panel(p4);
X		pflush();
X		wait_a_while(nap_msec);
X
X		saywhat("s5;");
X		show_panel(p5);
X		pflush();
X		wait_a_while(nap_msec);
X
X		saywhat("t3;");
X		top_panel(p3);
X		pflush();
X		wait_a_while(nap_msec);
X
X		saywhat("t1;");
X		top_panel(p1);
X		pflush();
X		wait_a_while(nap_msec);
X
X		saywhat("t2;");
X		top_panel(p2);
X		pflush();
X		wait_a_while(nap_msec);
X
X		saywhat("t3;");
X		top_panel(p3);
X		pflush();
X		wait_a_while(nap_msec);
X
X		saywhat("t4;");
X		top_panel(p4);
X		pflush();
X		wait_a_while(nap_msec);
X
X		for(itmp = 0; itmp < 6; itmp++)
X		{
X			saywhat("m4;");
X			wmove(w4,3,1);
X			waddstr(w4,mod[itmp]);
X			move_panel(p4,4,itmp*10);
X			wmove(w5,4,1);
X			waddstr(w5,mod[itmp]);
X			pflush();
X			wait_a_while(nap_msec);
X			saywhat("m5;");
X			wmove(w4,4,1);
X			waddstr(w4,mod[itmp]);
X			move_panel(p5,7,(itmp*10) + 6);
X			wmove(w5,3,1);
X			waddstr(w5,mod[itmp]);
X			pflush();
X			wait_a_while(nap_msec);
X		}
X
X		saywhat("m4;");
X		move_panel(p4,4,itmp*10);
X		pflush();
X		wait_a_while(nap_msec);
X
X		saywhat("t5;");
X		top_panel(p5);
X		pflush();
X		wait_a_while(nap_msec);
X
X		saywhat("t2;");
X		top_panel(p2);
X		pflush();
X		wait_a_while(nap_msec);
X
X		saywhat("t1;");
X		top_panel(p1);
X		pflush();
X		wait_a_while(nap_msec);
X
X		saywhat("d2;");
X		rmpanel(p2);
X		pflush();
X		wait_a_while(nap_msec);
X
X		saywhat("h3;");
X		hide_panel(p3);
X		pflush();
X		wait_a_while(nap_msec);
X
X		saywhat("d1;");
X		rmpanel(p1);
X		pflush();
X		wait_a_while(nap_msec);
X
X		saywhat("d4; ");
X		rmpanel(p4);
X		pflush();
X		wait_a_while(nap_msec);
X
X		saywhat("d5; ");
X		rmpanel(p5);
X		pflush();
X		wait_a_while(nap_msec);
X		if(nap_msec == 1)
X			break;
X		nap_msec = 100L;
X	}
X	endwin();
X	exit(0);
X}	/* end of main */
X
X/* vi: set tabstop=4 shiftwidth=4: */
X/* end of ptest.c */
SHAR_EOF
# ============= panel/Makefile ==============
echo "x - extracting panel/Makefile (Text)"
sed 's/^X//' << 'SHAR_EOF' > panel/Makefile &&
XCFLAGS = -O
X#CFLAGS = -O -DLINT_ARGS
X
XSHARFLS = \
X	README\
X	Makefile\
X	panel.3\
X	config.h\
X	libpanel.h\
X	libpanel.c
X
XOBJ = ptest.o libpanel.o
X
Xptest: $(OBJ)
X	cc -o $@ $(OBJ) -lcurses -lx
X
X$(OBJ): Makefile libpanel.h
X
Xshar:
X	shar -n libpanel -a $(SHARFLS) > libpanel.sh
X
Xclean:
X	rm -rf $(OBJ) core a.out cscope.out tags
X
Xclobber: clean
X	rm -rf ptest
SHAR_EOF
# ============= patchlevel.h ==============
echo "x - extracting patchlevel.h (Text)"
sed 's/^X//' << 'SHAR_EOF' > patchlevel.h &&
X#define PATCHLEVEL 1 /* scheme good for 9 patches */
SHAR_EOF
# ============= proc.c ==============
echo "x - extracting proc.c (Text)"
sed 's/^X//' << 'SHAR_EOF' > proc.c &&
X/*+-------------------------------------------------------------------------
X	proc.c - u386mon proc table functions
X
X  Defined functions:
X	display_proc(win,y,x)
X	grok_proc()
X	pstat_text(pstat)
X
X--------------------------------------------------------------------------*/
X/*+:EDITS:*/
X/*:08-01-1991-23:35-wht@n4hgf-release 3.40 source control point */
X/*:08-10-1990-14:12-jmd@p1so/wht@n4hgf-2.20-add Tandem Integrity S2 */
X/*:08-07-1990-14:24-wht@n4hgf-nba@sysware.dk SVR31 updates */
X/*:08-02-1990-15:36-wht@n4hgf-2.12-old curses hacks+minor 3.2 formalizations */
X/*:07-28-1990-18:06-wht@n4hgf-2.10 release */
X/*:07-11-1990-03:45-root@n4hgf-faster proc table manipulation */
X/*:06-27-1990-01:57-wht@n4hgf-1.10-incorporate suggestions from alpha testers */
X/*:06-25-1990-04:14-wht@n4hgf-1.02-better error handling */
X/*:06-24-1990-20:53-wht@n4hgf-v1.01-add ISC support thanks to peter@radig.de */
X/*:06-21-1990-14:26-r@n4hgf-version x0.12 seems bug free */
X/*:06-17-1990-16:46-wht-creation */
X
X#include "config.h"
X#define M_TERMINFO
X#include <curses.h>
X#undef reg     /* per nba@sysware.dk */
X#ifdef NATIVE_PANELS
X# include <panel.h>
X#else
X# include "libpanel.h"
X#endif
X#include <sys/types.h>
X#undef NGROUPS_MAX
X#undef NULL
X#include <sys/param.h>
X#include <sys/immu.h>
X#include <sys/region.h>
X#if defined(mips)
X#include <sys/sbd.h>
X#endif
X#include <sys/proc.h>
X#include <sys/var.h>
X#include <nlist.h>
X#include "nlsym.h"
X#include "libkmem.h"
X#include "libnlsym.h"
X#include "u386mon.h"
X
Xextern struct var v;
X
Xstruct proc *procs = (struct proc *)0;
Xstruct proc *oldprocs = (struct proc *)0;
Xstruct proc **pprocs = (struct proc **)0;
Xstruct proc **poldprocs = (struct proc **)0;
X
Xint procs_per_pstat[SXBRK + 1];
Xint procs_in_core;
Xint procs_alive;
X
X/*+-------------------------------------------------------------------------
X	pstat_text(pstat)
X--------------------------------------------------------------------------*/
Xchar *
Xpstat_text(pstat)
Xchar pstat;
X{
Xstatic char errant[10];
X
X	switch(pstat)
X	{
X		case SSLEEP:   return("sleep ");
X		case SRUN:     return("run   ");
X		case SZOMB:    return("zombie");
X		case SSTOP:    return("stop  ");
X		case SIDL:     return("idle  ");
X		case SONPROC:  return("onproc");
X		case SXBRK:    return("xbrk  ");
X	}
X	(void)sprintf(errant,"%06u?",(unsigned char)pstat);
X	return(errant);
X
X}	/* end of pstat_text */
X
X/*+-------------------------------------------------------------------------
X	grok_proc() - read and examine kernel process table
X--------------------------------------------------------------------------*/
Xvoid
Xgrok_proc()
X{
Xregister iproc;
Xregister struct proc *tproc;
Xstatic char *memfail = "cannot alloc memory for proc table";
X
X	if(!procs)
X	{
X		if(!(procs = (struct proc *)malloc(sizeof(struct proc) * v.v_proc)))
X			leave_text(memfail,1);
X		if(!(oldprocs = (struct proc *)malloc(sizeof(struct proc) * v.v_proc)))
X			leave_text(memfail,1);
X		if(!(pprocs = (struct proc **)malloc(sizeof(struct proc *) * v.v_proc)))
X			leave_text(memfail,1);
X		if(!(poldprocs=(struct proc **)malloc(sizeof(struct proc *)*v.v_proc)))
X			leave_text(memfail,1);
X	}
X	kread((caddr_t)procs,procaddr,sizeof(struct proc) * v.v_proc);
X	for(iproc = 0; iproc < SXBRK + 1; iproc++)
X		procs_per_pstat[iproc] = 0;
X	procs_in_core = 0;
X	procs_alive = 0;
X
X	for(iproc = 0; iproc < v.v_proc; iproc++)
X	{
X		tproc = pprocs[iproc] = (procs + iproc);
X
X		if(tproc->p_stat)
X			procs_alive++;
X
X		procs_per_pstat[tproc->p_stat]++;	/* count # procs in each state */
X
X		if(tproc->p_flag & SLOAD)			/* count # procs in memory */
X			procs_in_core++;
X	}
X
X}	/* end of grok_proc */
X
X/*+-------------------------------------------------------------------------
X	display_proc(win,y,x)
X--------------------------------------------------------------------------*/
Xvoid
Xdisplay_proc(win,y,x)
XWINDOW *win;
Xint y;
Xint x;
X{
Xregister istat;
X
X	grok_proc();
X
X	use_cp(win,cpBANNER);
X	wmove(win,y++,x);
X	waddstr(win,"-- Proc ---");
X	for(istat = SSLEEP; istat <= SXBRK; istat++)
X	{
X		wmove(win,y++,x);
X		disp_info_int(win,pstat_text(istat),"  %3d",procs_per_pstat[istat]);
X	}
X	wmove(win,y++,x);
X	disp_info_int(win,"total ","  %3d",procs_alive);
X	wmove(win,y++,x);
X	disp_info_int(win,"in mem","  %3d",procs_in_core);
X}	/* end of display_proc */
X
X/* vi: set tabstop=4 shiftwidth=4: */
X/* end of proc.c */
SHAR_EOF
# ============= renice/Makefile ==============
if test ! -d 'renice'; then
    echo "x - creating directory renice"
    mkdir 'renice'
fi
echo "x - extracting renice/Makefile (Text)"
sed 's/^X//' << 'SHAR_EOF' > renice/Makefile &&
X#  CHK=0xD897
X#+-------------------------------------------------------------------
X#  Makefile for renice for SCO UNIX V/386
X#  ...!emory!n4hgf!wht
X#--------------------------------------------------------------------
X#+:EDITS:*/
X#:06-25-1990-04:14-wht@n4hgf-1.03-better error handling
X#:06-21-1990-14:27-r@n4hgf-version x0.12 seems bug free
X#:06-19-1990-21:37-wht@n4hgf-get ready for 0.08 release
X
X#------------> CFLAGS 
XCFLAGS = -c -Octl -DLINT_ARGS
X#CFLAGS = -c -O
X
X#------------> BINDIR
XBINDIR = /usr/local/bin
X
X#LDFLAGS = -s
X
X
X#handle Sys V make "feature" of using SHELL
XSHELL = /bin/sh
X
X#FCRC = fcrc -u $*.c ;
X.c.o:;	$(FCRC) $(CC) $(CFLAGS) $*.c 
X
XSRC = \
X	renice.c
X
XRENICE_OBJ =\
X	renice.o\
X	../libnlsym.o\
X	libkmem-w.o
X
Xall: renice
X
X#must run as root
Xinstall: all
X	mv renice $(BINDIR)
X	chmod 4711 $(BINDIR)/renice
X	chown root $(BINDIR)/renice
X	@echo ' ';echo 'csh users rehash before executing'
X
Xrenice: $(RENICE_OBJ)
X	$(CC) $(LDFLAGS) -o $@ $(RENICE_OBJ) $(LIB)
X
Xlibkmem-w.o: ../libkmem.c
X	cc $(CFLAGS) -I .. -DKWRITE_NEEDED ../libkmem.c; mv libkmem.o libkmem-w.o
X
X../libnlsym.o: ../libnlsym.c
X	cd ..;make libnlsym.o
X
Xclean:
X	rm -f renice.o libkmem-w.o core 
X
Xclobber: clean
X	rm -f renice
X
SHAR_EOF
# ============= renice/renice.c ==============
echo "x - extracting renice/renice.c (Text)"
sed 's/^X//' << 'SHAR_EOF' > renice/renice.c &&
X/* CHK=0xE998 */
X/*+-------------------------------------------------------------------------
X	renice.c - UNIX 386 renice
X
X * This program was written by me, Mike "Ford" Ditto, and
X * I hereby release it into the public domain in the interest
X * of promoting the development of free, quality software
X * for the hackers and users of the world.
X *
X * Feel free to use, copy, modify, improve, and redistribute
X * this program, but keep in mind the spirit of this
X * contribution; always provide source, and always allow
X * free redistribution (shareware is fine with me).  If
X * you use a significant part of this code in a program of
X * yours, I would appreciate being given the appropriate
X * amount of credit.
X *				-=] Ford [=-
X *
X--------------------------------------------------------------------------*/
X/*+:EDITS:*/
X/*:06-26-1990-15:09-wht@n4hgf-adapt Ford's work to UNIX 386 */
X
X#include <stdio.h>
X#include <errno.h>
X#include <sys/types.h>
X#undef NGROUPS_MAX
X#undef NULL
X#include <sys/param.h>
X#include <sys/immu.h>
X#include <sys/region.h>
X#include <sys/proc.h>
X#include <sys/var.h>
X#include <nlist.h>
X#include "../nlsym.h"
X#include "../libkmem.h"
X#include "../libnlsym.h"
X
Xstruct var v;
Xstruct proc tproc;
Xint myuid;
Xchar *progname;
Xchar s128[128];
Xint myreadcnt = 0;			/* see libkmem.c, libmem.c, libswap.c */
Xdaddr_t myreadlen = 0;
X
X/*+-------------------------------------------------------------------------
X	leave_text(text,exit_code)
XIf exit_code == 255, do perror
X--------------------------------------------------------------------------*/
Xvoid
Xleave_text(text,exit_code)
Xchar *text;
Xint exit_code;
X{
X	if(exit_code == 255)
X		perror(text);
X	else
X	{
X		fputs(text,stderr);
X		fputs("\n",stderr);
X	}
X	exit(exit_code);
X}	/* end of leave_text */
X
X/*+-------------------------------------------------------------------------
X	renice(pid,value,relative) - change nice of process `pid'
Xbased on 'value' and 'relative'
X--------------------------------------------------------------------------*/
Xrenice(pid,value,relative)
Xint pid;
Xint value;
Xint relative;
X{
X	register i;
X	int tmpnice;
X
X	for(i = 0; i < v.v_proc; i++)
X	{
X		kread((caddr_t)&tproc,(daddr_t)((struct proc *)procaddr + i),
X		    sizeof(struct proc));
X		if(tproc.p_pid == pid)
X		{
X#ifdef DEBUG
X			fprintf(stderr,"Found it!  proc[%d], p_uid is %d\n",
X			    i,tproc.p_uid);
X
X			fprintf(stderr,"Old p_nice was %d\n",tproc.p_nice);
X#endif /* DEBUG */
X
X			tmpnice = tproc.p_nice;
X
X			if(relative)
X				tmpnice += value;
X			else
X				tmpnice = value;
X
X			if(tmpnice >= 40)
X				tmpnice = 40;
X			if(tmpnice < 0)
X				tmpnice = 0;
X
X#ifdef DEBUG
X			fprintf(stderr,"New p_nice is %d\n",tmpnice);
X#endif /* DEBUG */
X
X			if( 
X#ifdef WHT
X				(myuid && (myuid != 201))
X#else
X				myuid
X#endif
X			 	&& ((myuid != tproc.p_uid) || (tmpnice < tproc.p_nice)))
X			{
X				errno = EACCES;
X				sprintf(s128,"%s: can't renice process %d",progname,pid);
X				perror(s128);
X				return 1;
X			}
X
X			tproc.p_nice = tmpnice;
X
X			kwrite((daddr_t)&((struct proc *)procaddr)[i]
X			    + ( ((caddr_t)&tproc.p_nice) - (caddr_t)&tproc ),
X			    (caddr_t)&tproc.p_nice,sizeof(tproc.p_nice));
X			return(0);
X		}
X	}
X	fprintf(stderr,"%s: process %d not found.\n",progname,pid);
X
X	return(1);
X}	/* end of renice */
X
X/*+-------------------------------------------------------------------------
X	usage()
X--------------------------------------------------------------------------*/
Xvoid
Xusage()
X{
X    fprintf(stderr,"usage: %s [{+-}inc] [=prio] pid ...\n",progname);
X    exit(-1);
X}	/* end of usage */
X
X/*+-------------------------------------------------------------------------
X	main(argc,argv)
X--------------------------------------------------------------------------*/
Xmain(argc,argv)
Xint argc;
Xchar **argv;
X{
X	int status=0;
X	int pid;
X	int relative = 1;
X	int value = 0;
X
X	progname = *argv;
X	if(argc < 2)
X		usage();
X
X	myuid = getuid();
X	nlsym_read();
X	kinit(1);
X	kread((caddr_t)&v,vaddr,sizeof(v));
X
X	while(++argv,--argc)
X	{
X		switch(**argv)
X		{
X		case '-':
X			if(sscanf(*argv+1,"%d",&value) != 1)
X				usage();
X			relative = 1;
X			break;
X		case '+':
X			if(sscanf(*argv+1,"%d",&value) != 1)
X				usage();
X			value = -value;
X			relative = 1;
X			break;
X		case '=':
X			if(sscanf(*argv+1,"%d",&value) != 1)
X				usage();
X			relative = 0;
X			break;
X		default:
X			if(sscanf(*argv,"%d",&pid) != 1)
X				usage();
X			status += renice(pid,value,relative);
X		}
X	}
X
X	exit(status);
X}	/* end of main */
X
X/* vi: set tabstop=4 shiftwidth=4: */
X/* end of renice.c */
SHAR_EOF
# ============= tune.c ==============
echo "x - extracting tune.c (Text)"
sed 's/^X//' << 'SHAR_EOF' > tune.c &&
X/*+-------------------------------------------------------------------------
X	tune.c - u386mon tune struct display
X
X  Defined functions:
X	display_tune(win,y,x)
X
X--------------------------------------------------------------------------*/
X/*+:EDITS:*/
X/*:08-01-1991-23:35-wht@n4hgf-release 3.40 source control point */
X/*:08-10-1990-14:12-jmd@p1so/wht@n4hgf-2.20-add Tandem Integrity S2 */
X/*:08-07-1990-14:24-wht@n4hgf-nba@sysware.dk SVR31 updates */
X/*:08-02-1990-15:36-wht@n4hgf-2.12-old curses hacks+minor 3.2 formalizations */
X/*:07-28-1990-18:06-wht@n4hgf-2.10 release */
X/*:06-27-1990-01:57-wht@n4hgf-1.10-incorporate suggestions from alpha testers */
X/*:06-25-1990-17:33-wht@n4hgf-alpha sort identifiers */
X/*:06-25-1990-04:14-wht@n4hgf-1.02-better error handling */
X/*:06-24-1990-20:53-wht@n4hgf-v1.01-add ISC support thanks to peter@radig.de */
X/*:06-21-1990-14:26-r@n4hgf-version x0.12 seems bug free */
X/*:06-17-1990-14:59-wht-creation */
X
X#include "config.h"
X#define M_TERMINFO
X#include <curses.h>
X#undef reg     /* per nba@sysware.dk */
X#ifdef NATIVE_PANELS
X# include <panel.h>
X#else
X# include "libpanel.h"
X#endif
X#include <sys/types.h>
X#include <sys/tuneable.h>
X#if defined(mips)
X#define t_gpgsmsk  t_gpgslmsk
X#endif
X#include "u386mon.h"
X
X/*+-------------------------------------------------------------------------
X	display_tune(win,y,x)
X--------------------------------------------------------------------------*/
Xvoid
Xdisplay_tune(win,y,x)
XWINDOW *win;
Xint y;
Xint x;
X{
X
X	use_cp(win,cpBANNER);
X	wmove(win,y++,x);
X	waddstr(win,"-- Tune ---------");
X#ifdef	SVR32
X	wmove(win,y++,x);
X	disp_static_int(win,"t_ageintvl  ","%5d",tune.t_ageinterval);
X#endif
X	wmove(win,y++,x);
X	disp_static_int(win,"t_bdflushr  ","%5d",tune.t_bdflushr);
X	wmove(win,y++,x);
X	disp_static_int(win,"t_gpgshi    ","%5d",tune.t_gpgshi);
X	wmove(win,y++,x);
X	disp_static_int(win,"t_gpgslo    ","%5d",tune.t_gpgslo);
X	wmove(win,y++,x);
X	disp_static_int(win,"t_gpgsmsk   ","0x%03lx",tune.t_gpgsmsk);
X	wmove(win,y++,x);
X	disp_static_int(win,"t_maxfc     ","%5d",tune.t_maxfc);
X	wmove(win,y++,x);
X	disp_static_int(win,"t_maxsc     ","%5d",tune.t_maxsc);
X	wmove(win,y++,x);
X	disp_static_int(win,"t_maxumem   ","%5d",tune.t_maxumem);
X	wmove(win,y++,x);
X	disp_static_int(win,"t_minarmem  ","%5d",tune.t_minarmem);
X	wmove(win,y++,x);
X	disp_static_int(win,"t_minasmem  ","%5d",tune.t_minasmem);
X
X}	/* end of display_tune */
X
X/* vi: set tabstop=4 shiftwidth=4: */
X/* end of tune.c */
SHAR_EOF
# ============= u386mon.c ==============
echo "x - extracting u386mon.c (Text)"
sed 's/^X//' << 'SHAR_EOF' > u386mon.c &&
Xchar *revision = "3.40";
X/*+-------------------------------------------------------------------------
X	u386mon.c - UNIX 386 (and other) system monitor
X	wht@n4hgf.Mt-Park.GA.US and many others
X
X  Defined functions:
X	adb_trap()
X	calc_cpu_avg(per_state)
X	calc_wait_avg(per_state)
X	caught_signal(sig)
X	draw_cpuscale_literals(win,y,x)
X	draw_per_sec_literals(win,y,x)
X	draw_waitscale_literals(win,y,x)
X	extra_info_stuff()
X	extra_static_stuff()
X	get_cpu_avg(cpu_ticks,period)
X	get_elapsed_time(elapsed_seconds)
X	get_wait_avg(wait_ticks,period)
X	leave(exit_code)
X	leave_text(text,exit_code)
X	leaving(exit_code)
X	main(argc,argv,envp)
X	update_cpuscale(win,y,x,width,per_state)
X	update_waitscale(win,y,x,width,per_state,total_ticks)
X
X00000000001111111111222222222233333333334444444444555555555566666666667777777777
X01234567890123456789012345678901234567890123456789012345678901234567890123456789
X u386mon xxx.xxx                       PLOCK     INVALID      hh:mm:ss wht@n4hgf
X
X---- CPU --- tot usr ker brk ---------------------------------------------------
X Instant %   ### ### ### ### xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
X 5 Sec Avg % ### ### ### ### xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
X10 Sec Avg % ### ### ### ### xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
X---- Wait -- tot  io pio swp ---------------------------------------------------
X Instant %   ### ### ### ### xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
X 5 Sec Avg % ### ### ### ### xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
X10 Sec Avg % ### ### ### ### xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
X
X--------------------------------------------------------------------------*/
X/*+:EDITS:*/
X/*:08-01-1991-23:35-wht@n4hgf-release 3.40 source control point */
X/*:05-15-1991-17:22-wht@n4hgf-2.3 patches for SVR31 from nba@sysware.dk */
X/*:05-14-1991-06:11-root@n4hgf-evidently a fast cpu gets 0 cpu sometimes :-) */
X/*:05-09-1991-03:57-wht@n4hgf-fix HZ problem reported by ir@crosfield.co.uk */
X/*:05-09-1991-03:35-wht@n4hgf-gcc gives good warning */
X/*:05-09-1991-02:24-wht@n4hgf-HZ environment variable might be non-zero */
X/*:04-16-1991-02:25-martin@hppcmart additions for SCO 3.2.2 */
X/*:03-16-1991-14:22-wht@n4hgf-widen sysinfo column 4 */
X/*:08-14-1990-19:08-root@n4hgf-fix **argv bug */
X/*:08-10-1990-14:12-jmd@p1so/wht@n4hgf-2.20-add Tandem Integrity S2 */
X/*:08-07-1990-14:24-wht@n4hgf-nba@sysware.dk SVR31 updates */
X/*:08-02-1990-15:36-wht@n4hgf-2.12-old curses hacks+minor 3.2 formalizations */
X/*:08-01-1990-19:24-jdc@dell.com-add DELL config */
X/*:08-01-1990-17:25-wht@n4hgf-fix sysi86 swap calculations */
X/*:07-28-1990-18:06-wht@n4hgf-2.10 release */
X/*:07-28-1990-15:05-wht@n4hgf-make CYCLEmsec variable */
X/*:07-11-1990-03:45-root@n4hgf-faster proc table manipulation */
X/*:07-10-1990-19:06-root@n4hgf-redesign attributes/color pairs */
X/*:07-10-1990-18:33-root@n4hgf-move pio wait to medium alert */
X/*:07-10-1990-18:01-root@n4hgf-"improvement" didnt do much, but leave for now */
X/*:07-10-1990-13:54-root@n4hgf-improve nap heuristics and catch signals */
X/*:07-08-1990-20:31-root@n4hgf-make room for phread/phwrite */
X/*:07-03-1990-02:48-root@n4hgf-more accurate timing using ftime calculations */
X/*:06-27-1990-01:57-wht@n4hgf-1.10-incorporate suggestions from alpha testers */
X/*:06-27-1990-01:07-wht@n4hgf-add ^R and ^L refresh */
X/*:06-25-1990-17:34-wht@n4hgf-add detail extra for 25 line tubes */
X/*:06-25-1990-04:14-wht@n4hgf-1.02-better error handling */
X/*:06-24-1990-20:53-wht@n4hgf-v1.01-add ISC support thanks to peter@radig.de */
X/*:06-21-1990-14:26-r@n4hgf-version x0.12 seems bug free */
X/*:06-15-1990-18:32-wht@n4hgf-creation */
X
X#include "config.h"
X#define M_TERMINFO
X#include <curses.h>
X#undef timeout /* conflict in curses.h and bootinfo.h per trb@ima.ima.isc.com */
X#undef reg     /* per nba@sysware.dk */
X#include "libpanel.h"
X#include <signal.h>
X#include <string.h>
X#include <fcntl.h>
X#include <nlist.h>
X#include <errno.h>
X#include <time.h>
X#include <sys/types.h>
X#if defined(HAS_TIMEB)
X# include <sys/timeb.h>
X#endif
X#include <sys/lock.h>
X#include <sys/utsname.h>
X#include <sys/stat.h>
X#if defined(HAS_ASCII)
X# include <sys/ascii.h>
X#else
X#define A_ESC	'\033'
X#endif
X#undef NGROUPS_MAX
X#undef NULL
X#include <sys/param.h>
X#if defined(HAS_BOOTINFO)
X# include <sys/bootinfo.h>
X#endif
X#include <sys/tuneable.h>
X#include <sys/sysinfo.h>
X#include <sys/sysmacros.h>
X#include <sys/immu.h>
X#include <sys/region.h>
X#if defined(mips)
X#include <sys/sbd.h>
X#endif
X#include <sys/proc.h>
X#include <sys/var.h>
X#if defined(i386) || defined(i486)
X# include <sys/sysi86.h>
X#endif
X#if defined(mips)
X# include <sys/sysmips.h>
X#endif
X#include <sys/swap.h>
X#if !defined(mips)
X# include <sys/trap.h>
X#endif
X#include "nlsym.h"
X#include "libkmem.h"
X#include "libmem.h"
X#include "libswap.h"
X#include "libnlsym.h"
X#include "u386mon.h"
X
Xlong nap();
XPANEL *mkpanel();
X
X#if defined(HAS_TIMEB)
X#define delta_msec(t,t0) ((( t.time * 1000L) +  t.millitm) - \
X                          ((t0.time * 1000L) + t0.millitm))
X#endif
X
X#define INEXACT_STATE	2
X#define INVALID_STATE	5
X
X#if defined(mips)
X#define CYCLEmsecDef 5000L
X#define CYCLEmsecMax 9000L
X#else
X#define CYCLEmsecDef 2000L
X#define CYCLEmsecMax 4000L
X#endif
X
Xlong CYCLEmsec = CYCLEmsecDef;
X
Xstruct sysinfo sysinfo;
Xstruct sysinfo sysinfo_last;
X#define sysidelta(x) (sysinfo.x - sysinfo_last.x)
X
Xstruct minfo minfo;
Xstruct minfo minfo_last;
X#define midelta(x) (minfo.x - minfo_last.x)
X
X#if defined(HAS_BOOTINFO)
Xstruct bootinfo bootinfo;
X#endif
X
Xswpt_t swaptab [MSFILES];
Xswpi_t swapint = {SI_LIST, (char *)swaptab};
Xstruct tune tune;
Xstruct utsname utsname;
Xstruct var v;
X
X#if defined(HAS_TIMEB)
Xstruct timeb timeb_cycle_start;
Xstruct timeb timeb_cycle_end;
Xstruct timeb timeb_info_read;
Xstruct timeb timeb_last_info_read;
X#endif
X
Xint hz;
Xint nswap;	/* seems to be in units of NBPSCTR bytes */
Xint maxmem;
Xint freemem;
Xdaddr_t myreadlen = 0L;
Xint myreadcnt = 0;
Xint stat_period_msec_y = -1;
Xint stat_period_msec_x = -1;
Xint color_avail = 0;
Xint invalidity = 0;
X
XPANEL *pscr;
XWINDOW *wscr;
Xextern WINDOW *wdet;
X
X#define CPU_AVG_MAX		10
Xint cpu_avg_init = 0;
Xtime_t *cpu_avg[CPU_AVG_MAX];
Xtime_t cpu_ticks[5];
X
X#define WAIT_AVG_MAX	10
Xint wait_avg_init = 0;
Xtime_t *wait_avg[WAIT_AVG_MAX];
Xtime_t wait_ticks[5];
X
X/*+-------------------------------------------------------------------------
X	basename(fullname) - strip directory name from filename
X
Xreturns address of static string
X--------------------------------------------------------------------------*/
Xchar *
Xbasename(fullname)
Xchar *fullname;
X{
Xregister char *start;
Xstatic char outstr[256];
Xchar *strrchr();
X
X	start = strrchr(fullname,'/'); /* find last slash */
X	if(!start)
X		return(fullname);
X	start++;
X	strcpy(outstr,start);
X	return(outstr);
X}	/* end of basename */
X
X/*+-------------------------------------------------------------------------
X	leaving() - perform leave() basic processing and return
X--------------------------------------------------------------------------*/
Xvoid
Xleaving()
X{
X	wmove(wscr,CMD_TLY,0);
X	use_cp(wscr,cpLIT);
X	wclrtoeol(wscr);
X	pflush();
X	endwin();
X}	/* end of leaving */
X
X/*+-------------------------------------------------------------------------
X	leave(exit_code) - leave program with exit code
X--------------------------------------------------------------------------*/
Xvoid
Xleave(exit_code)
Xint exit_code;
X{
X	leaving();
X	exit(exit_code);
X}	/* end of leave */
X
X/*+-------------------------------------------------------------------------
X	leave_text(text,exit_code) - leave program with message and exit code
XIf exit_code == 255, do wperror
X--------------------------------------------------------------------------*/
Xvoid
Xleave_text(text,exit_code)
Xchar *text;
Xint exit_code;
X{
X	if(exit_code == 255)
X	{
X	int y;
X	register x;
X	extern int errno;
X	extern int sys_nerr;
X	extern char *sys_errlist[];
X
X		top_panel(pscr);
X		wmove(wscr,MSG_TLY - 2,0);
X		use_cp(wscr,cpHIGH);
X		x = 0;
X		while(x++ < COLS)
X			waddch(wscr,(chtype)' ');
X		wmove(wscr,MSG_TLY - 1,0);
X		wprintw(wscr,"errno %d",errno);
X		if(errno < sys_nerr)
X			wprintw(wscr,": %s",sys_errlist[errno]);
X		getyx(wscr,y,x);
X		while(x++ < COLS)
X			waddch(wscr,(chtype)' ');
X	}
X	if (text && *text) disp_msg(cpHIGH,text);
X	leave(exit_code);
X}	/* end of leave_text */
X
X/*+-------------------------------------------------------------------------
X	adb_trap() - convenient trap for catching abort
X
X  Get a look at stack before abort() botches it
X--------------------------------------------------------------------------*/
X#if defined(ADB_DEBUG)
Xvoid
Xadb_trap()
X{
X	printf("too bad .... goodbye\n");
X}	/* end of adb_trap */
X#endif
X
X/*+-------------------------------------------------------------------------
X	caught_signal(sig) - SIGHUP thru SIGSYS: leave with possible abort
X--------------------------------------------------------------------------*/
Xvoid
Xcaught_signal(sig)
Xint sig;
X{
X	leaving();
X	switch(sig)
X	{
X		case SIGQUIT:
X		case SIGILL:
X		case SIGTRAP:
X		case SIGIOT:
X		case SIGEMT:
X		case SIGFPE:
X		case SIGBUS:
X		case SIGSEGV:
X		case SIGSYS:
X#if defined(ADB_DEBUG)
X			adb_trap();	/* if debugging, stop at convenient breakpoint */
X#endif
X			abort();
X	}
X	exit(200);
X}	/* end of caught_signal */
X
X/*+-----------------------------------------------------------------------
X	char *get_elapsed_time(elapsed_seconds) - "ddd+hh:mm:ss" returned
X  static string address is returned
X------------------------------------------------------------------------*/
Xchar *
Xget_elapsed_time(elapsed_seconds)
Xtime_t elapsed_seconds;
X{
Xstatic char elapsed_time_str[32];
Xtime_t dd,hh,mm,ss;
X
X	dd = 0;
X	hh = elapsed_seconds / 3600;
X	if(hh > 24)
X	{
X		dd = hh / 24;
X		elapsed_seconds -= dd * 3600 * 24;
X		hh %= 24;
X	}
X	elapsed_seconds -= hh * 3600;
X	mm = elapsed_seconds / 60L;
X	elapsed_seconds -= mm * 60L;
X	ss = elapsed_seconds;
X
X	if(dd)
X		(void)sprintf(elapsed_time_str,"%3ld+%02ld:%02ld:%02ld",dd,hh,mm,ss);
X	else
X		(void)sprintf(elapsed_time_str,"    %2ld:%02ld:%02ld",hh,mm,ss);
X	return(elapsed_time_str);
X}	/* end of get_elapsed_time */
X
X/*+-------------------------------------------------------------------------
X	draw_cpuscale_literals(win)
X--------------------------------------------------------------------------*/
Xvoid
Xdraw_cpuscale_literals(win,y,x)
XWINDOW *win;
Xint y;
Xint x;
X{
Xint x2 = x;
X
X	wmove(win,y,x);
X	use_cp(wscr,cpBANNER);
X	waddstr(win,"---- CPU --- tot usr ker brk ");
X	getyx(win,y,x2);
X	while(x2 < COLS)
X		waddch(win,(chtype)'-'),x2++;
X	use_cp(wscr,cpLIT);
X	wmove(win,y + 1,x);
X	if(CYCLEmsec == 1000L)
X		waddstr(win," Instant %  ");
X	else
X		wprintw(win,"%2d Sec Avg %%",(int)(CYCLEmsec / 1000L));
X	wmove(win,y + 2,x);
X  	wprintw(win,"%2d Sec Avg %%",(int)(CYCLEmsec * 5 / 1000L));
X	wmove(win,y + 3,x);
X  	wprintw(win,"%2d Sec Avg %%",(int)(CYCLEmsec * 10 / 1000L));
X
X}	/* end of draw_cpuscale_literals */
X
X/*+-------------------------------------------------------------------------
X	update_cpuscale(win,y,width,per_state)
X
X000000000011111111112222222222333333333344444444445555555555666666
X012345678901234567890123456789012345678901234567890123456789012345
Xtot usr ker misc 
X### ### ### ### xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
X--------------------------------------------------------------------------*/
X#define _CPUSCALE_TX	0
X#define _CPUSCALE_UX	4
X#define _CPUSCALE_KX	8
X#define _CPUSCALE_BX	12
X#define _CPUSCALE_SX	16
X
Xtime_t
Xupdate_cpuscale(win,y,x,width,per_state)
XWINDOW *win;
Xint y;
Xint x;
Xregister width;
Xtime_t *per_state;
X{
Xregister itmp;
Xint accum = 0;
Xtime_t idle = per_state[CPU_IDLE] + per_state[CPU_WAIT];
Xtime_t cpu_ticks_total = idle + per_state[CPU_SXBRK] + 
X                         per_state[CPU_KERNEL] + per_state[CPU_USER];
Xtime_t percent_user    = 0;
Xtime_t percent_kernel  = 0;
Xtime_t percent_break   = 0;
Xtime_t percent_busy    = 0;
X
X	if(cpu_ticks_total)
X	{
X		percent_user    = (per_state[CPU_USER]   * 100) / cpu_ticks_total;
X		percent_kernel  = (per_state[CPU_KERNEL] * 100) / cpu_ticks_total;
X		percent_break   = (per_state[CPU_SXBRK]  * 100) / cpu_ticks_total;
X		percent_busy    = percent_user + percent_kernel + percent_break;
X	}
X
X	if(!idle)			/* take care of integer div truncation */
X		percent_busy = 100;
X
X	wmove(win,y, x + _CPUSCALE_TX);
X	if(percent_busy < 70)
X		use_cp(wscr,cpLOW);
X	else if(percent_busy < 90)
X		use_cp(wscr,cpMED);
X	else
X		use_cp(wscr,cpHIGH);
X	wprintw(win,"%3ld",percent_busy);
X
X	wmove(win,y, x + _CPUSCALE_UX);
X	use_cp(wscr,cpINFO);
X	wprintw(win,"%3ld",percent_user);
X	
X	wmove(win,y, x + _CPUSCALE_KX);
X	wprintw(win,"%3ld",percent_kernel);
X	
X	wmove(win,y, x + _CPUSCALE_BX);
X	wprintw(win,"%3ld",percent_break);
X	
X	wmove(win,y, x + _CPUSCALE_SX);
X	use_cp(wscr,cpLOW);
X	itmp = (width * percent_user) / 100;
X	accum += itmp;
X	while(itmp--)
X		waddch(win,(chtype)'u');
X
X	use_cp(wscr,cpMED);
X	itmp = (width * percent_kernel) / 100;
X	accum += itmp;
X	while(itmp--)
X		waddch(win,(chtype)'k');
X
X	use_cp(wscr,cpHIGH);
X	itmp = (width * percent_break) / 100;
X	accum += itmp;
X	while(itmp--)
X		waddch(win,(chtype)'b');
X
X	if((percent_busy > 98) && ((width - accum) > 0))
X	{
X		waddch(win,(chtype)'*');
X		accum++;
X	}
X
X	if((itmp = (width - accum)) > 0)
X	{
X		use_cp(wscr,cpLIT);
X		while(itmp--)
X			waddch(win,(chtype)' ');
X	}
X	return(cpu_ticks_total);
X}	/* end of update_cpuscale */
X
X/*+-------------------------------------------------------------------------
X	calc_cpu_avg(per_state) - add per_state array to avg array
X--------------------------------------------------------------------------*/
Xvoid
Xcalc_cpu_avg(per_state)
Xtime_t per_state[];
X{
Xregister itmp;
X
X	if(!cpu_avg_init)
X	{
X		for(itmp = 0; itmp < CPU_AVG_MAX; itmp++)
X			(void)memcpy(cpu_avg[itmp],per_state,sizeof(time_t) * 5);
X		cpu_avg_init = 1;
X	}
X	else
X	{
X		for(itmp = 0; itmp < CPU_AVG_MAX - 1; itmp++)
X			(void)memcpy(cpu_avg[itmp],cpu_avg[itmp + 1],sizeof(time_t) * 5);
X		(void)memcpy(cpu_avg[itmp],per_state,sizeof(time_t) * 5);
X	}
X
X}	/* end of calc_cpu_avg */
X
X/*+-------------------------------------------------------------------------
X	get_cpu_avg(cpu_ticks,period)
X--------------------------------------------------------------------------*/
Xget_cpu_avg(cpu_ticks,period)
Xtime_t cpu_ticks[];
Xint period;
X{
Xregister iperiod = CPU_AVG_MAX;
Xregister istate;
Xregister count = period;
X
X	for(istate = 0; istate < 5; istate++)
X		cpu_ticks[istate] = 0;
X
X	while(count--)
X	{
X		iperiod--;
X		for(istate = 0; istate < 5; istate++)
X		{
X			cpu_ticks[istate] += (cpu_avg[iperiod])[istate];
X		}
X	}
X
X	for(istate = 0; istate < 5; istate++)
X		cpu_ticks[istate] /= period;
X
X}	/* end of get_cpu_avg */
X
X/*+-------------------------------------------------------------------------
X	draw_waitscale_literals(win)
X--------------------------------------------------------------------------*/
Xvoid
Xdraw_waitscale_literals(win,y,x)
XWINDOW *win;
Xint y;
Xint x;
X{
Xint x2 = x;
X
X	wmove(win,y,x);
X	use_cp(wscr,cpBANNER);
X	waddstr(win,"---- Wait -- tot  io pio swp -- (% of real time) ");
X	getyx(win,y,x2);
X	while(x2 < COLS)
X		waddch(win,(chtype)'-'),x2++;
X	use_cp(wscr,cpLIT);
X	wmove(win,y + 1,x);
X	if(CYCLEmsec == 1000L)
X		waddstr(win," Instant %  ");
X	else
X		wprintw(win,"%2d Sec Avg %%",(int)(CYCLEmsec / 1000L));
X	wmove(win,y + 2,x);
X  	wprintw(win,"%2d Sec Avg %%",(int)(CYCLEmsec * 5 / 1000L));
X	wmove(win,y + 3,x);
X  	wprintw(win,"%2d Sec Avg %%",(int)(CYCLEmsec * 10 / 1000L));
X
X}	/* end of draw_waitscale_literals */
X
X/*+-------------------------------------------------------------------------
X	draw_per_sec_literals(win)
X--------------------------------------------------------------------------*/
Xvoid
Xdraw_per_sec_literals(win,y,x)
XWINDOW *win;
Xint y;
Xint x;
X{
X
X	wmove(win,y,x);
X	use_cp(wscr,cpBANNER);
X	waddstr(win,"---- Sysinfo/Minfo --- (last ");
X	getyx(win,stat_period_msec_y,stat_period_msec_x);
X 	wprintw(win," %4ld msec activity) ",CYCLEmsec);
X	getyx(win,y,x);
X	while(x < getmaxx(win))
X		waddch(win,(chtype)'-'),x++;
X
X}	/* end of draw_per_sec_literals */
X
X/*+-------------------------------------------------------------------------
X	update_waitscale(win,y,width,per_state)
X
X000000000011111111112222222222333333333344444444445555555555666666
X012345678901234567890123456789012345678901234567890123456789012345
Xtot  io pio swp  
X### ### ### ### xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
X--------------------------------------------------------------------------*/
X#define _WAITSCALE_TX	0
X#define _WAITSCALE_IX	4
X#define _WAITSCALE_PX	8
X#define _WAITSCALE_WX	12
X#define _WAITSCALE_SX	16
X
Xtime_t
Xupdate_waitscale(win,y,x,width,per_state,total_ticks)
XWINDOW *win;
Xint y;
Xint x;
Xregister width;
Xtime_t *per_state;
Xtime_t total_ticks;
X{
Xregister itmp;
Xint accum = 0;
Xtime_t percent_io = 0L;
Xtime_t percent_swap = 0L;
Xtime_t percent_pio = 0L;
Xtime_t percent_total_wait;
Xtime_t total_wait;
X
X/* crock: because of latency, total_ticks < all wait ticks sometimes */
X	total_wait = per_state[W_IO] + per_state[W_SWAP] + per_state[W_PIO];
X	if(total_ticks < total_wait)
X		total_ticks = total_wait;
X
X	if(total_ticks)
X	{
X		percent_io    = (per_state[W_IO]   * 100) / total_ticks;
X		percent_pio   = (per_state[W_PIO]  * 100) / total_ticks;
X		percent_swap  = (per_state[W_SWAP] * 100) / total_ticks;
X	}
X
X	wmove(win,y, x + _WAITSCALE_TX);
X	percent_total_wait = percent_io + percent_swap + percent_pio;
X	if(percent_total_wait < 30)
X		use_cp(wscr,cpLOW);
X	else if(percent_total_wait < 50)
X		use_cp(wscr,cpMED);
X	else
X		use_cp(wscr,cpHIGH);
X	wprintw(win,"%3ld",percent_total_wait);
X
X	use_cp(wscr,cpINFO);
X	wmove(win,y, x + _WAITSCALE_IX);
X	wprintw(win,"%3ld",percent_io);
X	
X	wmove(win,y, x + _WAITSCALE_PX);
X	wprintw(win,"%3ld",percent_pio);
X	
X	wmove(win,y, x + _WAITSCALE_WX);
X	wprintw(win,"%3ld",percent_swap);
X	
X	wmove(win,y, x + _WAITSCALE_SX);
X	use_cp(wscr,cpLOW);
X	itmp = (width * percent_io) / 100;
X	accum += itmp;
X	while(itmp--)
X		waddch(win,(chtype)'i');
X
X	use_cp(wscr,cpMED);
X	itmp = (width * percent_pio) / 100;
X	accum += itmp;
X	while(itmp--)
X		waddch(win,(chtype)'p');
X
X	use_cp(wscr,cpHIGH);
X	itmp = (width * percent_swap) / 100;
X	accum += itmp;
X	while(itmp--)
X		waddch(win,(chtype)'s');
X
X	if((itmp = (width - accum)) > 0)
X	{
X		use_cp(wscr,cpLIT);
X		while(itmp--)
X			waddch(win,(chtype)' ');
X	}
X
X}	/* end of update_waitscale */
X
X/*+-------------------------------------------------------------------------
X	calc_wait_avg(per_state) - add per_state array to avg array
X--------------------------------------------------------------------------*/
Xvoid
Xcalc_wait_avg(per_state)
Xtime_t per_state[];
X{
Xregister itmp;
X
X	if(!wait_avg_init)
X	{
X		for(itmp = 0; itmp < WAIT_AVG_MAX; itmp++)
X			(void)memcpy(wait_avg[itmp],per_state,sizeof(time_t) * 3);
X		wait_avg_init = 1;
X	}
X	else
X	{
X		for(itmp = 0; itmp < WAIT_AVG_MAX - 1; itmp++)
X			(void)memcpy(wait_avg[itmp],wait_avg[itmp + 1],sizeof(time_t) * 3);
X		(void)memcpy(wait_avg[itmp],per_state,sizeof(time_t) * 3);
X	}
X
X}	/* end of calc_wait_avg */
X
X/*+-------------------------------------------------------------------------
X	get_wait_avg(wait_ticks,period)
X--------------------------------------------------------------------------*/
Xget_wait_avg(wait_ticks,period)
Xtime_t wait_ticks[];
Xint period;
X{
Xregister iperiod = WAIT_AVG_MAX;
Xregister istate;
Xregister count = period;
X
X	for(istate = 0; istate < 3; istate++)
X		wait_ticks[istate] = 0;
X
X	while(count--)
X	{
X		iperiod--;
X		for(istate = 0; istate < 3; istate++)
X		{
X			wait_ticks[istate] += (wait_avg[iperiod])[istate];
X		}
X	}
X
X	for(istate = 0; istate < 3; istate++)
X		wait_ticks[istate] /= period;
X
X}	/* end of get_wait_avg */
X
X/*+-------------------------------------------------------------------------
X	extra_static_stuff()/extra_info_stuff() - for 43 line display
X--------------------------------------------------------------------------*/
Xvoid
Xextra_static_stuff()
X{
X	display_var(wscr,EXTRA_TLY,EXTRA1_TLX);
X#if defined(HAS_BOOTINFO)
X	display_bootinfo(wscr,EXTRA_TLY,EXTRA2_TLX);
X#endif
X	display_tune(wscr,EXTRA_TLY,EXTRA3_TLX);
X}	/* end of extra_static_stuff */
X
Xvoid
Xextra_info_stuff()
X{
X	display_proc(wscr,EXTRA_TLY,EXTRA4_TLX);
X}	/* end of extra_info_stuff */
X
X/*+-------------------------------------------------------------------------
X	read_sysinfo_and_minfo()
X--------------------------------------------------------------------------*/
Xvoid
Xread_sysinfo_and_minfo()
X{
X#if defined(HAS_TIMEB)
X	timeb_last_info_read = timeb_info_read;
X	(void)ftime(&timeb_info_read);
X#endif
X	kread((caddr_t)&sysinfo,sysinfoaddr,sizeof(sysinfo));
X	kread((caddr_t)&minfo,minfoaddr,sizeof(minfo));
X}	/* end of read_sysinfo_and_minfo */
X
X/*+-------------------------------------------------------------------------
X	main(argc,argv,envp)
X--------------------------------------------------------------------------*/
X/*ARGSUSED*/
Xmain(argc,argv,envp)
Xint argc;
Xchar **argv;
Xchar **envp;
X{
Xregister itmp;
Xregister char *cptr;
Xregister chtype cmd;
Xregister chtype initial_cmd = 0;
Xint errflg = 0;
Xint plock_indicator = 0;
Xtime_t total_ticks;
Xlong stat_period_msec;
Xlong nap_msec;
Xint y,x;
Xint banner_free_x;
Xlong ltmp, now;
X#if !defined(HAS_TIMEB)
Xlong then;
X#endif /* HAS_TIMEB */
Xstruct tm *lt;
Xstatic char stdoutbuf[2048];
Xchar s80[80];
Xextern int optind;
X
X/*
X * curses works better if standard output is fully buffered
X */
X	(void)setvbuf(stdout,stdoutbuf,_IOFBF,sizeof(stdoutbuf));
X
X/*
X * check out command line
X */
X	while((itmp = getopt(argc,argv,"lPnpstw")) != -1)
X	{
X		switch(itmp)
X		{
X			case 'P':
X			case 'p':
X#if defined(M_UNIX) || defined(SVR31)
X			case 'n':
X			case 't':
X#endif
X#if defined(M_UNIX)
X			case 's':
X#if defined(SCO322)
X			case 'w':
X#endif
X#endif
X				initial_cmd = (chtype) itmp;
X				break;
X			case 'l':
X				plock_indicator = 1;
X				break;
X			case '?':
X				errflg++;
X		}
X	}
X	if(errflg || (optind != argc))
X	{
X		static char *usage_str[]=
X		{
X			"-l lock process into memory (if root)",
X			"-p begin with short ps display",
X			"-P begin with long ps display (if 43 line screen)",
X			(char *)0
X		};
X		char **cpptr = usage_str;
X		fprintf(stderr,"usage: %s [-l] [-p | -P]\n",basename(*argv));
X		while(*cpptr)
X			(void)fprintf(stderr,"%s\n",*(cpptr++));
X		exit(1);
X	}
X
X/*
X * if man wants to plock() try it; fail silently if non-root
X */
X	if(plock_indicator && plock(PROCLOCK))
X	{
X		nice(-5);
X		plock_indicator = 0;
X	}
X
X/*
X * Real(tm) performance monitor users will have done a kernel link
X * and won't need to rely on /etc/systemid
X */
X	if(uname(&utsname))
X	{
X		leave_text("uname failed",255);
X		exit(1);
X	}
X
X/*
X * allocate memory for cpu time array averaging buckets
X */
X	for(itmp = 0; itmp < CPU_AVG_MAX; itmp++)
X	{
X		if(!(cpu_avg[itmp] = (time_t *)malloc(sizeof(time_t) * 5)))
X			leave_text("cannot alloc memory for cpu avg arrays",1);
X	}
X
X/*
X * allocate memory for wait time array averaging buckets
X */
X	for(itmp = 0; itmp < WAIT_AVG_MAX; itmp++)
X	{
X		if(!(wait_avg[itmp] = (time_t *)malloc(sizeof(time_t) * 3)))
X			leave_text("cannot alloc memory for wait avg arrays",1);
X	}
X
X/*
X * initialize curses environment
X */
X	if(!initscr())
X	{
X		(void)printf("curses init failed\n");
X		exit(1);
X	}
X#if defined(COLOR_PAIR)
X	has_colors_kludge();
X#endif
X	clear();
X	refresh();
X
X	if((LINES < 24) || (COLS < 80))
X	{
X		waddstr(stdscr,"\n\n\nNeed at least 80x24 screen\n\n");
X		refresh();
X		endwin();
X		exit(1);
X	}
X
X	noecho();
X	keypad(stdscr,TRUE);
X	typeahead(-1);
X#if !defined(HAS_RDCHK)
X	cbreak ();
X#endif
X
X/*
X * see u386mon.h cXXX definitons for A_BOLD requirements for bright colors
X */
X#if defined(COLOR_PAIR)
X	if(color_avail)
X	{
X		start_color();
X		init_pair(cpLIT,cBLU,cBLK);
X		init_pair(cpINFO,cGRN,cBLK);
X		init_pair(cpLOW,cLTG,cBLK);
X		init_pair(cpMED,cYEL,cBLK);
X		init_pair(cpHIGH,cRED,cBLK);
X		init_pair(cpBANNER,cBLK,cWHT);
X		init_pair(cpREVERSE,cRED,cWHT);
X		init_pair(cpBANWARN,cBLU,cWHT);
X	}
X#endif
X
X#if (defined(i386) || defined(i486)) && defined(HI_BIT_CAN_BE_SET)
X	/* a hack for now -- assuming AT char set */
X	/* This does NOT work with SCO ... rumours are it does work somewhere */
X	acs_map['l'] = A_ALTCHARSET | sTL;	
X	acs_map['m'] = A_ALTCHARSET | sTR;	
X	acs_map['j'] = A_ALTCHARSET | sBL;	
X	acs_map['k'] = A_ALTCHARSET | sBR;	
X	acs_map['x'] = A_ALTCHARSET | sVR;		/* vertical rule */
X	acs_map['q'] = A_ALTCHARSET | sHR;		/* horizontal rule */
X	acs_map['t'] = A_ALTCHARSET | sLT;		/* left hand T */
X	acs_map['u'] = A_ALTCHARSET | sRT;		/* right hand T */
X#endif
X
X	if(!(pscr = mkpanel(LINES,COLS,0,0,"main")))
X	{
X		addstr("cannot make screen panel");
X		refresh();
X		endwin();
X		exit(1);
X	}
X	wscr = panel_window(pscr);
X	top_panel(pscr);
X#if !defined(HAS_RDCHK)
X	nodelay (wscr, TRUE);
X#endif
X
X/*
X * catch signals that can leave our tty in disarray
X */
X	for(itmp = SIGHUP; itmp < SIGSYS; itmp++)
X		signal(itmp,caught_signal);
X
X/*
X * read nlist symbols, open /dev/kmem, /dev/mem, /dev/swap,
X * initialize detail environment
X * (all of these must occur after curses init)
X * drop euid and egid (after opening privileged mem/devices)
X * initialize process status uid->name hasher
X */
X	nlsym_read();
X	kinit(0);	/* /dev/kmem, read access only */
X	minit(0);	/* /dev/mem,  read access only */
X	sinit();	/* /dev/swap, only read access available */
X	(void)setuid(getuid());	/* some people run us setuid, so clen that up */
X	(void)setgid(getgid());	/* now that we have the fds open, drop egid */
X	kread((caddr_t)&v,vaddr,sizeof(v));
X	detail_init();
X
X/*
X * start fireworks
X */
X	wmove(wscr,0,0);
X	use_cp(wscr,cpBANNER);
X	waddch(wscr,(chtype)' ');
X	waddstr(wscr,basename(*argv));
X	waddch(wscr,(chtype)' ');
X	waddstr(wscr,revision);
X
X#if defined(mips)
X	waddstr(wscr,"/Tandem");
X#else
X#if defined(M_UNIX)
X	waddstr(wscr,"/SCO");
X#else
X#if defined(ISC)
X#if defined(DELL)
X	waddstr(wscr,"/Dell");
X#else
X	waddstr(wscr,"/ISC");
SHAR_EOF
echo "End of  part 5"
echo "File u386mon.c is continued in part 6"
echo "6" > shar3_seq_.tmp
exit 0