Newsgroups: alt.sources
Path: qiclab!psgrain!charnel!rat!usc!zaphod.mps.ohio-state.edu!darwin.sura.net!Sirius.dfn.de!dct.zrz.tu-berlin.de!news.netmbx.de!Germany.EU.net!isaak.isa.de!omega!av
From: av@omega.ssw.de (Andreas Vogel)
Subject: u386mon for SVR4
Message-ID: <1992Oct2.181241.4030@omega.ssw.de>
Date: Fri, 2 Oct 1992 18:12:41 GMT
Organization: Omega Softlab
Lines: 3081

Submitted-by: av@ssw.de
Archive-name: av386mon/part03

#!/bin/sh
# this is av386mon.shar.03 (part 3 of av386mon)
# do not concatenate these parts, unpack them in order with /bin/sh
# file u386mon.c continued
#
if test ! -r _shar_seq_.tmp; then
	echo 'Please unpack part 1 first!'
	exit 1
fi
(read Scheck
 if test "$Scheck" != 3; then
	echo Please unpack part "$Scheck" next!
	exit 1
 else
	exit 0
 fi
) < _shar_seq_.tmp || exit 1
if test ! -f _shar_wnt_.tmp; then
	echo 'x - still skipping u386mon.c'
else
echo 'x - continuing file u386mon.c'
sed 's/^X//' << 'SHAR_EOF' >> 'u386mon.c' &&
X			ltmp = 0;
X		disp_info_long(wscr,"lread    ","%7ld",ltmp);
X		myreadcnt = 0;	/* reset /dev/{mem,kmem,swap} read count */
X		wmove(wscr,y++,PER_SEC1_TLX);
X		disp_info_long(wscr,"lwrite   ","%7ld",sysidelta(lwrite));
X		wmove(wscr,y++,PER_SEC1_TLX);
X		disp_info_long(wscr,"phread   ","%7ld",sysidelta(phread));
X		wmove(wscr,y++,PER_SEC1_TLX);
X		disp_info_long(wscr,"phwrite  ","%7ld",sysidelta(phwrite));
X		wmove(wscr,y++,PER_SEC1_TLX);
X		disp_info_long(wscr,"swapin   ","%7ld",sysidelta(swapin));
X		wmove(wscr,y++,PER_SEC1_TLX);
X		disp_info_long(wscr,"swapout  ","%7ld",sysidelta(swapout));
X		wmove(wscr,y++,PER_SEC1_TLX);
X		disp_info_long(wscr,"bswapin  ","%7ld",sysidelta(bswapin));
X		wmove(wscr,y++,PER_SEC1_TLX);
X		disp_info_long(wscr,"bswapout ","%7ld",sysidelta(bswapout));
X		wmove(wscr,y++,PER_SEC1_TLX);
X		disp_info_long(wscr,"iget     ","%7ld",sysidelta(iget));
X		wmove(wscr,y++,PER_SEC1_TLX);
X		disp_info_long(wscr,"namei    ","%7ld",sysidelta(namei));
X		wmove(wscr,y++,PER_SEC1_TLX);
X		disp_info_long(wscr,"dirblk   ","%7ld",sysidelta(dirblk));
X
X		y = PER_SEC_TLY + 1;
X		wmove(wscr,y++,PER_SEC2_TLX);
X		if((ltmp = sysidelta(readch) - myreadlen) < 0)
X			ltmp = 0;
X		disp_info_long(wscr,"readch  ","%7ld",ltmp);
X		myreadlen = 0;	/* reset /dev/{mem,kmem,swap} read count */
X
X		wmove(wscr,y++,PER_SEC2_TLX);
X		disp_info_long(wscr,"writch  ","%7ld",sysidelta(writech));
X
X		wmove(wscr,y++,PER_SEC2_TLX);
X		disp_info_long(wscr,"rawch   ","%7ld",sysidelta(rawch));
X		wmove(wscr,y++,PER_SEC2_TLX);
X		disp_info_long(wscr,"canch   ","%7ld",sysidelta(canch));
X		wmove(wscr,y++,PER_SEC2_TLX);
X		disp_info_long(wscr,"outch   ","%7ld",sysidelta(outch));
X
X		wmove(wscr,y++,PER_SEC2_TLX);
X		disp_info_long(wscr,"msg     ","%7ld",sysidelta(msg));
X		wmove(wscr,y++,PER_SEC2_TLX);
X		disp_info_long(wscr,"sema    ","%7ld",sysidelta(sema));
X
X		wmove(wscr,y++,PER_SEC2_TLX);
#ifdef SVR4
X		disp_static_long(wscr, "maxmem  ","%6ldk",x_maxmem);
#else
X		disp_static_long(wscr, "maxmem  ","%6ldk",(long)maxmem * NBPP / 1024);
#endif
X		wmove(wscr,y++,PER_SEC2_TLX);
#ifdef SVR4
X		disp_info_long(wscr,   "frmem   ","%6ldk",x_freemem);
X		wmove(wscr,y++,PER_SEC2_TLX);
X		disp_info_int (wscr,   "mem used","%6d%%",
X			100 - (int)((x_freemem * 100) / x_maxmem));
#else
X		disp_info_long(wscr,   "frmem   ","%6ldk",(long)freemem * NBPP / 1024);
X		wmove(wscr,y++,PER_SEC2_TLX);
X		disp_info_int (wscr,   "mem used","%6d%%",
X			100 - (int)((freemem * 100) / maxmem));
#endif
X
X		wmove(wscr,y++,PER_SEC2_TLX);
#ifdef SVR4
X		disp_static_int(wscr, "nswap   ","%6ldk",nswap);
#else
X		disp_static_int(wscr, "nswap   ","%6ldk",nswap * NBPSCTR / 1024);
#endif
X		wmove(wscr,y++,PER_SEC2_TLX);
#ifdef SVR4
X		disp_info_long(wscr,  "frswp   ","%6ldk",freeswap);
#else
X		disp_info_long(wscr,  "frswp   ","%6ldk",minfo.freeswap* NBPSCTR/1024);
#endif
X		wmove(wscr,y++,PER_SEC2_TLX);
#ifdef SVR4
X		disp_info_int(wscr,   "swp used","%6d%%", 100 - (int)((freeswap * 100) / nswap));
#else
X		disp_info_int(wscr,   "swp used","%6d%%",
X			100 - (int)((minfo.freeswap * 100) / nswap));
#endif
X
X		y = PER_SEC_TLY + 1;
X		wmove(wscr,y++,PER_SEC3_TLX);
X		disp_info_long(wscr,"pswitch ","%5ld",sysidelta(pswitch));
X		wmove(wscr,y++,PER_SEC3_TLX);
X		disp_info_long(wscr,"syscall ","%5ld",sysidelta(syscall));
X		wmove(wscr,y++,PER_SEC3_TLX);
X		disp_info_long(wscr,"sysread ","%5ld",sysidelta(sysread));
X		wmove(wscr,y++,PER_SEC3_TLX);
X		disp_info_long(wscr,"syswrit ","%5ld",sysidelta(syswrite));
X		wmove(wscr,y++,PER_SEC3_TLX);
X		disp_info_long(wscr,"sysfork ","%5ld",sysidelta(sysfork));
X		wmove(wscr,y++,PER_SEC3_TLX);
X		disp_info_long(wscr,"sysexec ","%5ld",sysidelta(sysexec));
X
X		y++;
X		wmove(wscr,y++,PER_SEC3_TLX);
X		disp_info_long(wscr,"runque  ","%5ld",sysidelta(runque));
X		wmove(wscr,y++,PER_SEC3_TLX);
X		disp_info_long(wscr,"runocc  ","%5ld",sysidelta(runocc));
X		wmove(wscr,y++,PER_SEC3_TLX);
X		disp_info_long(wscr,"swpque  ","%5ld",sysidelta(swpque));
X		wmove(wscr,y++,PER_SEC3_TLX);
X		disp_info_long(wscr,"swpocc  ","%5ld",sysidelta(swpocc));
X
X		y = PER_SEC_TLY + 1;
X		wmove(wscr,y++,PER_SEC4_TLX);
X		disp_info_long(wscr,"vfault  ","%4ld",midelta(vfault));
X		wmove(wscr,y++,PER_SEC4_TLX);
X		disp_info_long(wscr,"demand  ","%4ld",midelta(demand));
X		wmove(wscr,y++,PER_SEC4_TLX);
X		disp_info_long(wscr,"pfault  ","%4ld",midelta(pfault));
X		wmove(wscr,y++,PER_SEC4_TLX);
X		disp_info_long(wscr,"cw      ","%4ld",midelta(cw));
X		wmove(wscr,y++,PER_SEC4_TLX);
X		disp_info_long(wscr,"steal   ","%4ld",midelta(steal));
X		wmove(wscr,y++,PER_SEC4_TLX);
X		disp_info_long(wscr,"frdpgs  ","%4ld",midelta(freedpgs));
#if defined(SVR32) || defined (SVR4)
X		wmove(wscr,y++,PER_SEC4_TLX);
X		disp_info_long(wscr,"vfpg    ","%4ld",midelta(vfpg));
X		wmove(wscr,y++,PER_SEC4_TLX);
X		disp_info_long(wscr,"sfpg    ","%4ld",midelta(sfpg));
X		wmove(wscr,y++,PER_SEC4_TLX);
X		disp_info_long(wscr,"vspg    ","%4ld",midelta(vspg));
X		wmove(wscr,y++,PER_SEC4_TLX);
X		disp_info_long(wscr,"sspg    ","%4ld",midelta(sspg));
X		wmove(wscr,y++,PER_SEC4_TLX);
X		disp_info_long(wscr,"pnpfault","%4ld",sysidelta(pnpfault));
X		wmove(wscr,y++,PER_SEC4_TLX);
X		disp_info_long(wscr,"wrtfault","%4ld",sysidelta(wrtfault));
#endif
X
X		y = PER_SEC_TLY + 1;
X		wmove(wscr,y++,PER_SEC5_TLX);
X		disp_info_long(wscr,"unmodsw ","%3ld",midelta(unmodsw));
X		wmove(wscr,y++,PER_SEC5_TLX);
X		disp_info_long(wscr,"unmodfl ","%3ld",midelta(unmodfl));
#if defined(SVR32) || defined (SVR4)
X		wmove(wscr,y++,PER_SEC5_TLX);
X		disp_info_long(wscr,"psoutok ","%3ld",midelta(psoutok));
X		wmove(wscr,y++,PER_SEC5_TLX);
X		disp_info_long(wscr,"psinfai ","%3ld",midelta(psinfail));
X		wmove(wscr,y++,PER_SEC5_TLX);
X		disp_info_long(wscr,"psinok  ","%3ld",midelta(psinok));
X		wmove(wscr,y++,PER_SEC5_TLX);
X		disp_info_long(wscr,"rsout   ","%3ld",midelta(rsout));
X		wmove(wscr,y++,PER_SEC5_TLX);
X		disp_info_long(wscr,"rsin    ","%3ld",midelta(rsin));
#endif
X
X		y++;
X		wmove(wscr,y++,PER_SEC5_TLX);
X		use_cp(wscr,cpLIT);
X		waddstr(wscr,"pages on   ");
X		wmove(wscr,y++,PER_SEC5_TLX);
X		disp_info_long(wscr,"swap  ","%5ld",midelta(swap));
X		wmove(wscr,y++,PER_SEC5_TLX);
X		disp_info_long(wscr,"cache ","%5ld",midelta(cache));
X		wmove(wscr,y++,PER_SEC5_TLX);
X		disp_info_long(wscr,"file  ","%5ld",midelta(file));
X
X		if(LINES >= 43)
X			extra_info_stuff();
X
X		detail_panel_update();
X
X		if(initial_cmd)
X		{
X			detail_panel_cmd(initial_cmd);
X			initial_cmd = 0;
X		}
X
X		pflush();
X
X		cmd = 0;
#if defined(HAS_RDCHK)
X		while(rdchk(0))
#endif
X		{
X			switch(cmd = wgetch(wscr))
X			{
X				case 'L' & 0x1F:		/* ^L */
X				case 'R' & 0x1F:		/* ^R */
X					clearok (wscr, TRUE);
X					touchwin(wscr);
X					wrefresh(wscr);
X					if(wdet)
X					{
X						touchwin(wdet);
X						wrefresh(wscr);
X					}
X					break;
X
X				case 'q':
X				case A_ESC:
X					goto GOOD_BYE;
#if defined(M_UNIX)
X				case 'b':
X					if(bootinfo.bootstrlen > 79)
X						itmp = 79;
X					else
X						itmp = bootinfo.bootstrlen;
X					kread(s80,bootinfoaddr +
X						(bootinfo.bootstr - (caddr_t)&bootinfo),itmp);
X					s80[itmp] = 0;
X					disp_msg(cpMED,s80);
X					break;
#endif
X				case 'e':
X				case 'P':
X				case 'p':
X				case 'm':
#if defined(M_UNIX) || defined(SVR31) || defined(ISC22)
X				case 'n':
X				case 't':
#endif
#if defined(M_UNIX)
X				case 's':
#if defined(SCO322)
X				case 'w':
#endif
#endif
X					detail_panel_cmd(cmd);
X					break;
X				case 'l':
X					if(!plock_indicator)
X					{
X						if(!plock(PROCLOCK))
X						{
X							plock_indicator = 1;
X							wmove(wscr,0,banner_free_x);
X							use_cp(wscr,cpMED);
X							waddstr(wscr," PLOCK ");
X							nice(-5);
X						}
X					}
X					break;
X				case 'u':
X					if(plock_indicator)
X					{
X						if(!plock(UNLOCK))
X						{
X							plock_indicator = 0;
X							wmove(wscr,0,banner_free_x);
X							use_cp(wscr,cpBANNER);
X							waddstr(wscr,"       ");
X							nice(5);
X						}
X					}
X					break;
X				case '+':
X					if(CYCLEmsec < CYCLEmsecMax)
X					{
X						invalidity += (INEXACT_STATE * (CYCLEmsec + 1000L)) /
X											CYCLEmsec;
X						CYCLEmsec += 1000L;
X						draw_cpuscale_literals(wscr,CPUSCALE_TLY,0);
X						draw_waitscale_literals(wscr,WAITSCALE_TLY,0);
X					}
X					else beep();
X					break;
X				case '-':
X					if(CYCLEmsec > 1000L)
X					{
X						CYCLEmsec -= 1000L;
X						draw_cpuscale_literals(wscr,CPUSCALE_TLY,0);
X						draw_waitscale_literals(wscr,WAITSCALE_TLY,0);
X					}
X					else beep();
X					break;
X				case 0:
X				case -1:
X					break;
X				default:
X					beep();
X					break;
X			}
X		}
X
X		/* remember previous statistics for next delta */
X		sysinfo_last = sysinfo;
X		minfo_last = minfo;
X
X		/* ex-lax: all in the name of regularity */
#if defined(HAS_TIMEB)
X		ftime(&timeb_cycle_end);
X		nap_msec = CYCLEmsec - delta_msec(timeb_cycle_end,timeb_cycle_start);
X		if(nap_msec < (CYCLEmsec - 300L))
X			nap_msec = (CYCLEmsec - 300L);
#else
X		nap_msec = (CYCLEmsec - 300L);
#endif
#ifdef HAS_NAP
X		(void)nap(nap_msec);
#else
X		napms(nap_msec);	/* curses call: most round UP to nearest second */
#endif
X	}
X
GOOD_BYE:
X	leave_text("",0);
X	/*NOTREACHED*/
}	/* end of main */
X
/* vi: set tabstop=4 shiftwidth=4: */
/* end of u386mon.c */
SHAR_EOF
echo 'File u386mon.c is complete' &&
chmod 0644 u386mon.c ||
echo 'restore of u386mon.c failed'
Wc_c="`wc -c < 'u386mon.c'`"
test 41336 -eq "$Wc_c" ||
	echo 'u386mon.c: original size 41336, current size' "$Wc_c"
rm -f _shar_wnt_.tmp
fi
# ============= bootinfo.c ==============
if test -f 'bootinfo.c' -a X"$1" != X"-c"; then
	echo 'x - skipping bootinfo.c (File already exists)'
	rm -f _shar_wnt_.tmp
else
> _shar_wnt_.tmp
echo 'x - extracting bootinfo.c (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'bootinfo.c' &&
/*+-------------------------------------------------------------------------
X	bootinfo.c - u386mon bootinfo struct display
X
X  Defined functions:
X	bmemf_text(flags)
X	display_bootinfo(win,y,x)
X
We try to be dynamic with memory block counts, but if the sum of
memavailcnt and memusedcnt ever exceeds 7, we will lose in 24 line
sessions (8 in 25 line, 9 in 43 line)
X
X
--------------------------------------------------------------------------*/
/*+:EDITS:*/
/*:08-01-1991-23:34-wht@n4hgf-release 2.40 source control point */
/*:08-10-1990-14:12-jmd@p1so/wht@n4hgf-2.20-add Tandem Integrity S2 */
/*:08-07-1990-14:24-wht@n4hgf-nba@sysware.dk SVR31 updates */
/*:08-02-1990-15:35-wht@n4hgf-2.12-old curses hacks+minor 3.2 formalizations */
/*:07-28-1990-18:06-wht@n4hgf-2.10 release */
/*:07-11-1990-17:19-root@n4hgf-more input from trb@ima.ima.isc.com */
/*:07-04-1990-01:28-root@n4hgf-alan@cms2.lonestar.org reported missing M_ */
/*:06-27-1990-01:57-wht@n4hgf-1.10-incorporate suggestions from alpha testers */
/*:06-25-1990-04:14-wht@n4hgf-1.02-better error handling */
/*:06-25-1990-03:18-wht@n4hgf-ODT/3.2.1 has B_MEM_CANTDMA not B_MEM_NODMA */
/*:06-24-1990-20:53-wht@n4hgf-v1.01-add ISC support thanks to peter@radig.de */
/*:06-21-1990-14:26-r@n4hgf-version x0.12 seems bug free */
/*:06-17-1990-14:59-wht-creation */
X
#include "config.h"
#if defined(HAS_BOOTINFO)
#define M_TERMINFO
#include <curses.h>
#undef timeout /* conflict in curses.h and bootinfo.h per trb@ima.ima.isc.com */
#undef reg     /* per nba@sysware.dk */
#ifdef NATIVE_PANELS
# include <panel.h>
#else
# include "libpanel.h"
#endif
#include <sys/types.h>
#include <sys/bootinfo.h>
#include "u386mon.h"
X
/*+-------------------------------------------------------------------------
X	bmemf_text(flags)
--------------------------------------------------------------------------*/
char *
bmemf_text(flags)
ulong flags;
{
static char hex_errant[16];
ulong orig_flags = flags;
X
#if defined(B_MEM_DOWN)		/* SCO only */
X	flags &= ~B_MEM_DOWN;
#endif
#if defined(B_MEM_BASE)		/* ISC only (or is it SVR3.2.2?) */
X	flags &= ~B_MEM_BASE;
#endif
#if defined(B_MEM_EXPANS)	/* ISC */
X	flags &= ~B_MEM_EXPANS;
#endif
#if defined(B_MEM_SHADOW)	/* ISC */
X	flags &= ~B_MEM_SHADOW;
#endif
#if defined(B_MEM_TREV)		/* ISC */
X	flags &= ~B_MEM_TREV;
#endif
X
X	if(!flags)
X		return("    ");
X	switch(flags)
X	{
#if defined(B_MEM_RSRVD)
X		case B_MEM_RSRVD: return("RSVD");
#endif
#if defined(B_MEM_KBSS)
X		case B_MEM_KBSS:  return("KBSS");
#endif
#if defined(B_MEM_KTEXT)
X		case B_MEM_KTEXT: return("KTXT");
#endif
#if defined(B_MEM_KDATA)
X		case B_MEM_KDATA: return("KDTA");
#endif
#if defined(B_MEM_NODMA)
X		case B_MEM_NODMA: return("NODM");
#endif
#if defined(B_MEM_CANTDMA)
X		case B_MEM_CANTDMA: return("NODM");
#endif
X	}
X	sprintf(hex_errant,"%04x",(ushort)orig_flags);
X	return(hex_errant);
}	/* end of bmemf_text */
X
/*+-------------------------------------------------------------------------
X	ISC_machinetype_text(machine)
--------------------------------------------------------------------------*/
#if defined(ME_COMPAQVGA)	/* ISC machdep.h */
char *
ISC_machinetype_text(machine)
unsigned char machine;
{
X	switch(machine)
X	{
#if defined(M_UNKNOWN)	/* some ISC bootinfo.h do not have these */
X		case M_UNKNOWN:
X			return("");
X			break;
#endif
#if defined(M_COMPAQ)
X		case M_COMPAQ:
X			return("Compaq");
X			break;
#endif
#if defined(M_PS2)
X		case M_PS2:
X			return("PS/2");
X			break;
#endif
#if defined(M_AT)
X		case M_AT:
X			return("Generic 386");
X			break;
#endif
#if defined(M_ATT)
X		case M_ATT:
X			return("AT&T 6386");
X			break;
#endif
#if defined(M_ATT5)
X		case M_ATT5:
X			return("AT&T 6386");
X			break;
#endif
#if defined(M_M380)
X		case M_M380:
X			return("Olivetti M380");
X			break;
#endif
#if defined(M_DELL)
X		case M_DELL:
X			return("Dell 386");
X			break;
#endif
#if defined(M_D325)
X		case M_D325:
X			return("Dell 325");
X			break;
#endif
#if defined(M_ALR)
X		case M_ALR:
X			return("Adv Logic Res");
X			break;
#endif
#if defined(M_ZDS)
X		case M_ZDS:
X			return("Zenith Data");
X			break;
#endif
X	}
X	return("i386");
}	/* end of ISC_machinetype_text */
#endif
X
/*+-------------------------------------------------------------------------
X	ISC_displaytype_text(adapter)
--------------------------------------------------------------------------*/
#if defined(ME_COMPAQVGA)	/* ISC machdep.h */
char *
ISC_displaytype_text(adapter)
unsigned char adapter;
{
X
X	switch(adapter)
X	{
X		case ME_UNKNOWN:
X			return("unknown to sys");
X			break;
X		case ME_EGA:
X			return("EGA");
X			break;
X		case ME_CGA80:
X			return("CGA");
X			break;
X		case ME_MONO:
X			return("MONO");
X			break;
X		case ME_COMPAQHR:
X			return("Compaq mono");
X			break;
X		case ME_Z449:
X			return("Zenith Z449");
X			break;
X		case ME_T5100:
X			return("Toshiba T5100");
X			break;
X		case ME_COMPAQVGA:
X			return("Compaq VGA");
X			break;
X		case ME_OTHERVGA:
X			return("VGA");
X			break;
#if defined(ME_PVGA1)
X		case ME_PVGA1:
X			return("Paradise VGA1");
X			break;
#endif /*ME_PVGA1*/
#if defined(ME_V7VGA)
X		case ME_V7VGA:
X			return("Video 7 VGA");
X			break;
#endif /*ME_V7VGA*/
X	}
X	return("???");
}	/* end of ISC_displaytype_text */
#endif
X
/*+-------------------------------------------------------------------------
X	display_bootinfo(win,y,x)
--------------------------------------------------------------------------*/
void
display_bootinfo(win,y,x)
WINDOW *win;
int y;
int x;
{
register itmp;
register struct bootmem *bmem;
X
X	use_cp(win,cpBANNER);
X	wmove(win,y++,x);
X	waddstr(win,"-- Bootinfo ----------");
#if defined(M_UNIX)	/* ISC doesn't have this in struct */
X	wmove(win,y++,x);
X	disp_static_long(win,"basemem  ","%7ldk     ",bootinfo.basemem / 1024);
X	wmove(win,y++,x);
X	disp_static_long(win,"extmem   ","%7ldk     ",bootinfo.extmem / 1024);
#endif
#if defined(ME_COMPAQVGA)	/* ISC machdep.h */
X	wmove(win,y++,x);
X	wprintw(win,"machine %14.14s",
X		ISC_machinetype_text(bootinfo.machenv.machine));
X	wmove(win,y++,x);
X	wprintw(win,"disp %17.17s",
X		ISC_displaytype_text(bootinfo.machenv.adapter));
#endif
X	wmove(win,y++,x);
X	disp_static_long(win,"bflags   ","%08lx     ",bootinfo.bootflags);
X
X	wmove(win,y++,x); waddstr(win,"memory available      ");
X	for(itmp = 0; itmp < bootinfo.memavailcnt; itmp++)
X	{
X		bmem = &bootinfo.memavail[itmp];
#if defined(B_MEM_DOWN)
X		if(bmem->flags & B_MEM_DOWN)
X		{
X			bmem->base -= bmem->extent;
X			bmem->flags &= ~B_MEM_DOWN;
X		}
#endif
X		wmove(win,y++,x);
X		wprintw(win,"%08lx %08lx %s",bmem->base,bmem->extent,
X			bmemf_text(bmem->flags));
X	}
X
X	wmove(win,y++,x); waddstr(win,"memory used           ");
X	for(itmp = 0; itmp < bootinfo.memusedcnt; itmp++)
X	{
X		bmem = &bootinfo.memused[itmp];
#if defined(B_MEM_DOWN)
X		if(bmem->flags & B_MEM_DOWN)
X		{
X			bmem->base -= bmem->extent;
X			bmem->flags &= ~B_MEM_DOWN;
X		}
#endif
X		wmove(win,y++,x);
X		wprintw(win,"%08lx %08lx %s",bmem->base,bmem->extent,
X			bmemf_text(bmem->flags));
X	}
X
}	/* end of display_bootinfo */
X
#endif /* HAS_BOOTINFO */
/* vi: set tabstop=4 shiftwidth=4: */
/* end of bootinfo.c */
SHAR_EOF
chmod 0644 bootinfo.c ||
echo 'restore of bootinfo.c failed'
Wc_c="`wc -c < 'bootinfo.c'`"
test 6997 -eq "$Wc_c" ||
	echo 'bootinfo.c: original size 6997, current size' "$Wc_c"
rm -f _shar_wnt_.tmp
fi
# ============= detail.c ==============
if test -f 'detail.c' -a X"$1" != X"-c"; then
	echo 'x - skipping detail.c (File already exists)'
	rm -f _shar_wnt_.tmp
else
> _shar_wnt_.tmp
echo 'x - extracting detail.c (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'detail.c' &&
/*+-------------------------------------------------------------------------
X	detail.c - UNIX 386 system monitor detail window
X
X  Defined functions:
X	detail_init()
X	detail_panel_cmd(cmd)
X	detail_panel_update()
X	detpanel_destroy()
X	detpanel_extra_init()
X	detpanel_extra_update()
X	detpanel_ps_init(full43)
X	detpanel_ps_update()
X	detpanel_sio_init()
X	detpanel_sio_update()
X	detpanel_streams_init()
X	detpanel_streams_update()
X	detpanel_table_init()
X	detpanel_table_update()
X
--------------------------------------------------------------------------*/
/*+:EDITS:*/
/*:08-14-1991-13:04-wht@n4hgf-STREAMS and table works for ISC 2.2 */
/*:08-01-1991-23:34-wht@n4hgf-release 2.40 source control point */
/*:05-15-1991-17:22-wht@n4hgf-2.3 patches for SVR31 from nba@sysware.dk */
/*:04-16-1991-16:51-martin@hppcmart-Fix display problems */
/*:04-16-1991-02:24-martin@hppcmart-additions for SCO 3.2.2 */
/*:08-10-1990-14:12-jmd@p1so/wht@n4hgf-2.20-add Tandem Integrity S2 */
/*:08-07-1990-14:24-wht@n4hgf-nba@sysware.dk SVR31 updates */
/*:08-02-1990-15:36-wht@n4hgf-2.12-old curses hacks+minor 3.2 formalizations */
/*:07-28-1990-18:06-wht@n4hgf-2.10 release */
/*:07-10-1990-14:53-root@n4hgf-clear msg line on detail cmd - fix 24-line bug */
/*:06-27-1990-01:57-wht@n4hgf-1.10-incorporate suggestions from alpha testers */
/*:06-25-1990-17:34-wht@n4hgf-add detail extra for 25 line tubes */
/*:06-25-1990-04:14-wht@n4hgf-1.02-better error handling */
/*:06-24-1990-20:53-wht@n4hgf-v1.01-add ISC support thanks to peter@radig.de */
/*:06-21-1990-14:26-r@n4hgf-version x0.12 seems bug free */
/*:06-15-1990-18:32-wht@n4hgf-creation */
X
#include "config.h"
#define M_TERMINFO
#include <curses.h>
#undef timeout /* conflict in curses.h and bootinfo.h per trb@ima.ima.isc.com */
#undef reg     /* per nba@sysware.dk */
#ifdef NATIVE_PANELS
# include <panel.h>
#else
# include "libpanel.h"
#endif
#include <signal.h>
#include <string.h>
#include <fcntl.h>
#include <nlist.h>
#include <errno.h>
#include <time.h>
#include <pwd.h>
#include <sys/types.h>
#include <utmp.h>
#include <sys/utsname.h>
#include <sys/stat.h>
#undef NGROUPS_MAX
#undef NULL
#include <sys/param.h>
#include <sys/tuneable.h>
#include <sys/sysinfo.h>
#include <sys/sysmacros.h>
#include <sys/immu.h>
#include <sys/region.h>
#if defined(mips)
#include <sys/sbd.h>
#endif
#include <sys/proc.h>
#include <sys/var.h>
X
#include "nlsym.h"
#include "libkmem.h"
#include "libnlsym.h"
#include "u386mon.h"
X
#define DPT_NONE		0
#define DPT_PS			1
#define DPT_PS_LONG		2
#define DPT_EXTRA		3
#define DPT_SIO			4
#define DPT_STREAMS		5
#define DPT_TABLE		6
#define DPT_WD			7
X
PANEL *mkpanel();
X
extern PANEL *pscr;
extern WINDOW *wscr;
X
PANEL *pdet;
WINDOW *wdet = (WINDOW *)0;
u_char detpanel_type = DPT_NONE;
int detpanel_length;
int detpanel_cols;
X
/*+-------------------------------------------------------------------------
X	detpanel_ps_init(full43)
--------------------------------------------------------------------------*/
void
detpanel_ps_init(full43)
int full43;
{
/*
#define DETAIL_PS_COLS ((LINES >= 43) ? EXTRA4_TLX - 1 : PER_SEC4_TLX)
detpanel_cols = DETAIL_PS_COLS;
*/
X
#define DETAIL_PS_TLY ((LINES >= 43) ? ((full43)?PER_SEC_TLY:PER_SEC_TLY+14)\
X                                     : PER_SEC_TLY)
X
#define DETAIL_PS_LENGTH		(MSG_TLY - DETAIL_PS_TLY)
X
X	detpanel_length = DETAIL_PS_LENGTH;
X	detpanel_cols = COLS;
X	if(!(pdet = mkpanel(detpanel_length,detpanel_cols,DETAIL_PS_TLY,0,"ps")))
X	{
X		leave_text("cannot make detail panel",1);
X	}
X	show_panel(pdet);
X	top_panel(pdet);
X	wdet = panel_window(pdet);
X	display_proc_stats(wdet,1);
X
}	/* end of detpanel_ps_init */
X
/*+-------------------------------------------------------------------------
X	detpanel_ps_update()
--------------------------------------------------------------------------*/
void
detpanel_ps_update()
{
X	display_proc_stats(wdet,0);
}	/* end of detpanel_ps_update */
X
/*+-------------------------------------------------------------------------
X	detpanel_extra_init()
--------------------------------------------------------------------------*/
void
detpanel_extra_init()
{
#define DETAIL_EXTRA_TLY		PER_SEC_TLY
#define DETAIL_EXTRA_LENGTH		(CMD_TLY - DETAIL_EXTRA_TLY)
X
X	detpanel_length = DETAIL_EXTRA_LENGTH;
X	detpanel_cols = COLS;
X	if(!(pdet = mkpanel(detpanel_length,detpanel_cols,DETAIL_EXTRA_TLY,0,"ex")))
X	{
X		leave_text("cannot make detail panel",1);
X	}
X	show_panel(pdet);
X	top_panel(pdet);
X	wdet = panel_window(pdet);
X	display_var(wdet,0,EXTRA1_TLX);
#if defined(HAS_BOOTINFO)
X	display_bootinfo(wdet,0,EXTRA2_TLX);
#endif
X	display_tune(wdet,0,EXTRA3_TLX);
X	display_proc(wdet,0,EXTRA4_TLX);
X
}	/* end of detpanel_extra_init */
X
/*+-------------------------------------------------------------------------
X	detpanel_extra_update()
--------------------------------------------------------------------------*/
void
detpanel_extra_update()
{
X	display_proc(wdet,0,EXTRA4_TLX);
}	/* end of detpanel_extra_update */
X
/*+-------------------------------------------------------------------------
X	detpanel_streams_init() - streams stats
--------------------------------------------------------------------------*/
#if defined(M_UNIX) || defined(SVR31) || defined(ISC22)
void
detpanel_streams_init()
{
#define DETAIL_STREAMS_TLY ((LINES >= 43) ? (PER_SEC_TLY+14) : PER_SEC_TLY)
#define DETAIL_STREAMS_LENGTH		(CMD_TLY - DETAIL_STREAMS_TLY)
X
X	detpanel_length = DETAIL_STREAMS_LENGTH;
X	detpanel_cols = COLS;
X	if(!(pdet = mkpanel(detpanel_length,detpanel_cols,
X		DETAIL_STREAMS_TLY,0,"str")))
X	{
X		leave_text("cannot make detail panel",1);
X	}
X	show_panel(pdet);
X	top_panel(pdet);
X	wdet = panel_window(pdet);
X	draw_streamscale_literals(wdet, 0, 0);
X	update_streamscale(wdet, 1, 21, 79-39);
}	/* end of detpanel_streams_init */
X
/*+-------------------------------------------------------------------------
X	detpanel_streams_update()
--------------------------------------------------------------------------*/
X
void
detpanel_streams_update()
{
X	update_streamscale(wdet, 1, 21, 79-39);
}	/* end of detpanel_streams_update */
#endif
X
/*+-------------------------------------------------------------------------
X	detpanel_wd_init()
X	SCO 3.2.2 only WD Disk stats
--------------------------------------------------------------------------*/
#if defined(M_UNIX) && defined(SCO322)
void
detpanel_wd_init()
{
#define DETAIL_WD_TLY ((LINES >= 43) ? (PER_SEC_TLY + 14) : PER_SEC_TLY)
#define DETAIL_WD_LENGTH		(CMD_TLY - DETAIL_WD_TLY)
X
X	detpanel_length = DETAIL_WD_LENGTH;
X	detpanel_cols = COLS;
X	if(!(pdet = mkpanel(detpanel_length,detpanel_cols,DETAIL_WD_TLY,0,"str")))
X	{
X		leave_text("cannot make detail panel",1);
X	}
X	show_panel(pdet);
X	top_panel(pdet);
X	wdet = panel_window(pdet);
X	draw_wd_literals(wdet, 0, 0);
X	update_wd(wdet, 1, 9, 79-28);
}	/* end of detpanel_wd_init */
#endif
/*+-------------------------------------------------------------------------
X	detpanel_wd_update()
--------------------------------------------------------------------------*/
#if defined(M_UNIX) && defined(SCO322)
void
detpanel_wd_update()
{
X	update_wd(wdet, 1, 9, 79-28);
}	/* end of detpanel_wd_update */
#endif
X
/*+-------------------------------------------------------------------------
X	detpanel_table_init()
X	SCO only table stats
--------------------------------------------------------------------------*/
#if defined(M_UNIX) || defined(SVR31) || defined(ISC22)
void
detpanel_table_init()
{
#define DETAIL_TABLE_TLY ((LINES >= 43) ? (PER_SEC_TLY+14) : PER_SEC_TLY)
#define DETAIL_TABLE_LENGTH		(CMD_TLY - DETAIL_TABLE_TLY)
X
X	detpanel_length = DETAIL_TABLE_LENGTH;
X	detpanel_cols = COLS;
X	if(!(pdet = mkpanel(detpanel_length,detpanel_cols,DETAIL_TABLE_TLY,0,"tab")))
X	{
X		leave_text("cannot make detail panel",1);
X	}
X	show_panel(pdet);
X	top_panel(pdet);
X	wdet = panel_window(pdet);
X	draw_table_literals(wdet, 0, 0);
X	update_table(wdet, 1, 15, 79-32);
}	/* end of detpanel_table_init */
X
/*+-------------------------------------------------------------------------
X	detpanel_table_update()
--------------------------------------------------------------------------*/
X
void
detpanel_table_update()
{
X	update_table(wdet, 1, 15, 79-32);
}	/* end of detpanel_table_update */
#endif
X
X
/*+-------------------------------------------------------------------------
X	detpanel_sio_init() - SCO only serial I/O display
--------------------------------------------------------------------------*/
#if defined(M_UNIX)
void
detpanel_sio_init()
{
#define DETAIL_SIO_TLY ((LINES >= 43) ? (PER_SEC_TLY+14) : PER_SEC_TLY)
#define DETAIL_SIO_LENGTH		(CMD_TLY - DETAIL_SIO_TLY)
X
X	detpanel_length = DETAIL_SIO_LENGTH;
X	detpanel_cols = COLS;
X	if(!(pdet = mkpanel(detpanel_length,detpanel_cols,DETAIL_SIO_TLY,0,"sio")))
X	{
X		leave_text("cannot make detail panel",1);
X	}
X	show_panel(pdet);
X	top_panel(pdet);
X	wdet = panel_window(pdet);
X	display_sio_summary(wdet,1);
}	/* end of detpanel_sio_init */
#endif
X
/*+-------------------------------------------------------------------------
X	detpanel_sio_update()
--------------------------------------------------------------------------*/
#if defined(M_UNIX)
void
detpanel_sio_update()
{
X	display_sio_summary(wdet,0);
}	/* end of detpanel_sio_update */
#endif
X
/*+-------------------------------------------------------------------------
X	detpanel_destroy()
--------------------------------------------------------------------------*/
void
detpanel_destroy()
{
X	hide_panel(pdet);
X	delwin(wdet);
X	wdet = (WINDOW *)0;
X	del_panel(pdet);
X	top_panel(pscr);
X	disp_msg(cpINFO,"");
X	detpanel_type = DPT_NONE;
}	/* end of detpanel_destroy */
X
/*+-------------------------------------------------------------------------
X	detail_panel_cmd(cmd)
X
X  command: m main screen
X           p proc status
--------------------------------------------------------------------------*/
void
detail_panel_cmd(cmd)
chtype cmd;
{
X	disp_msg(cpINFO,"");
X	switch(cmd)
X	{
X		case 'm':
X			if(detpanel_type != DPT_NONE)
X				detpanel_destroy();
X			break;
X
X		case 'P':
X			if(detpanel_type == DPT_PS_LONG)
X				break;
X			if(detpanel_type != DPT_NONE)
X				detpanel_destroy();
X			detpanel_ps_init(1);
X			detpanel_type = DPT_PS_LONG;
X			break;
X
X		case 'p':
X			if(detpanel_type == DPT_PS)
X				break;
X			if(detpanel_type != DPT_NONE)
X				detpanel_destroy();
X			detpanel_ps_init(0);
X			detpanel_type = DPT_PS;
X			break;
X
X		case 'e':
X			if(LINES >= 43)
X				break;
X			if(detpanel_type == DPT_EXTRA)
X				break;
X			if(detpanel_type != DPT_NONE)
X				detpanel_destroy();
X			detpanel_extra_init();
X			detpanel_type = DPT_EXTRA;
X			break;
X
#if defined(M_UNIX) || defined(SVR31) || defined(ISC22)
X		case 'n':
X			if(detpanel_type == DPT_STREAMS)
X				break;
X			if(detpanel_type != DPT_NONE)
X				detpanel_destroy();
X			detpanel_streams_init();
X			detpanel_type = DPT_STREAMS;
X			break;
X		case 't':
X			if(detpanel_type == DPT_TABLE)
X				break;
X			if(detpanel_type != DPT_NONE)
X				detpanel_destroy();
X			detpanel_table_init();
X			detpanel_type = DPT_TABLE;
X			break;
#endif
#if defined(M_UNIX)
X		case 's':
X			if(detpanel_type == DPT_SIO)
X				break;
X			if(detpanel_type != DPT_NONE)
X				detpanel_destroy();
X			detpanel_sio_init();
X			detpanel_type = DPT_SIO;
X			break;
#if defined(SCO322)
X		case 'w':
X			if(detpanel_type == DPT_WD)
X				break;
X			if(detpanel_type != DPT_NONE)
X				detpanel_destroy();
X			detpanel_wd_init();
X			detpanel_type = DPT_WD;
X			break;
#endif
#endif
X
X	}
}	/* end of detail_panel_cmd */
X
/*+-------------------------------------------------------------------------
X	detail_panel_update()
--------------------------------------------------------------------------*/
void
detail_panel_update()
{
X	switch(detpanel_type)
X	{
X		case DPT_PS:
X		case DPT_PS_LONG:
X			detpanel_ps_update();
X			break;
X		case DPT_EXTRA:
X			detpanel_extra_update();
X			break;
#if defined(M_UNIX)
X		case DPT_SIO:
X			detpanel_sio_update();
X			break;
#endif
#if defined(M_UNIX) || defined(SVR31) || defined(ISC22)
X		case DPT_STREAMS:
X			detpanel_streams_update();
X			break;
X		case DPT_TABLE:
X			detpanel_table_update();
X			break;
#if defined(SCO322)
X		case DPT_WD:
X			detpanel_wd_update();
X			break;
#endif
#endif
X	}
}	/* end of detail_panel_update */
X
/*+-------------------------------------------------------------------------
X	detail_init()
--------------------------------------------------------------------------*/
void
detail_init()
{
X	det_proc_init();	/* see det_proc.c */
#if defined(M_UNIX) || defined(SVR31) || defined(ISC22)
X	init_stream();
X	init_table();
#ifdef SCO322
X	init_wd();
#endif
#endif
}	/* end of detail_init */
X
/* vi: set tabstop=4 shiftwidth=4: */
/* end of detail.c */
SHAR_EOF
chmod 0644 detail.c ||
echo 'restore of detail.c failed'
Wc_c="`wc -c < 'detail.c'`"
test 12559 -eq "$Wc_c" ||
	echo 'detail.c: original size 12559, current size' "$Wc_c"
rm -f _shar_wnt_.tmp
fi
# ============= det_proc.c ==============
if test -f 'det_proc.c' -a X"$1" != X"-c"; then
	echo 'x - skipping det_proc.c (File already exists)'
	rm -f _shar_wnt_.tmp
else
> _shar_wnt_.tmp
echo 'x - extracting det_proc.c (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'det_proc.c' &&
/*+-------------------------------------------------------------------------
X	det_proc.c - UNIX V/386 system monitor proc status detail
X	...!{gatech,emory}!n4hgf!wht
X
X  Defined functions:
X	det_proc_init()
X	display_proc_stat(win,iproc,initial)
X	display_proc_stats(win,initial)
X	find_utmp_for_pgrp(pgrp)
X	get_cpu_time_str(ticks)
X	get_user(tproc,tuser)
X	getpwent_and_enter(uid)
X	init_uid_name_hash()
X	pgrp_to_ttyname(pgrp)
X	ppproc_pid_compare(ppp1,ppp2)
X	read_and_sort_procs(initial)
X	read_utmp()
X	uid_name_enter(uid,name)
X	uid_to_name(uid)
X
--------------------------------------------------------------------------*/
/*+:EDITS:*/
/*:08-11-1991-13:58-root@n4hgf-keep bogus numbers from polluting display */
/*:08-01-1991-23:34-wht@n4hgf-release 2.40 source control point */
/*:02-14-1991-11:26-martin@hppcmart-Whittle procs with no cpu time*/
/*:08-10-1990-14:12-jmd@p1so/wht@n4hgf-2.20-add Tandem Integrity S2 */
/*:08-07-1990-14:24-wht@n4hgf-nba@sysware.dk SVR31 updates */
/*:08-02-1990-15:36-wht@n4hgf-2.12-old curses hacks+minor 3.2 formalizations */
/*:08-01-1990-12:26-wht@n4hgf-2.11-try to support ISC 1.x.x */
/*:07-28-1990-18:06-wht@n4hgf-2.10 release */
/*:07-11-1990-03:45-root@n4hgf-faster proc table manipulation */
/*:06-27-1990-01:57-wht@n4hgf-1.10-incorporate suggestions from alpha testers */
/*:06-25-1990-04:14-wht@n4hgf-1.02-better error handling */
/*:06-24-1990-20:53-wht@n4hgf-v1.01-add ISC support thanks to peter@radig.de */
/*:06-21-1990-14:26-r@n4hgf-version x0.12 seems bug free */
/*:01-05-1989-13:27-wht-creation */
X
#include "config.h"
#define M_TERMINFO
#include <curses.h>
#undef timeout /* conflict in curses.h and bootinfo.h per trb@ima.ima.isc.com */
#undef reg     /* per nba@sysware.dk */
#ifdef NATIVE_PANELS
# include <panel.h>
#else
# include "libpanel.h"
#endif
#include <signal.h>
#include <string.h>
#include <fcntl.h>
#include <nlist.h>
#include <errno.h>
#include <time.h>
#include <pwd.h>
#include <sys/types.h>
#include <utmp.h>
#include <sys/stat.h>
#undef NGROUPS_MAX
#undef NULL
#include <sys/param.h>
#include <sys/tuneable.h>
#include <sys/sysinfo.h>
#include <sys/sysmacros.h>
#include <sys/immu.h>
#include <sys/region.h>
#if defined(mips)
#define pg_pres pg_sv /* alias: MIPS pg_sv==page valid */
#include <sys/sbd.h>
#include <sys/pcb.h>
#endif
#include <sys/proc.h>
#include <sys/fs/s5dir.h>
#include <sys/user.h>
#include <sys/var.h>
#ifdef SVR4
#   include <sys/sysi86.h>
#else
#   if defined(M_UNIX) && (defined(i386) || defined(i486)) && SYSI86_RDUBLK_WANTED
X	/* maybe someday, but not now */
#       include <sys/sysi86.h>
#   endif
#endif
X
#ifdef SVR4
#   include <sys/cred.h>
#   include <sys/vnode.h>
#   include <sys/session.h>
#endif
X
#include "nlsym.h"
#include "libkmem.h"
#include "libmem.h"
#include "libswap.h"
#include "libnlsym.h"
#include "u386mon.h"
X
extern int errno;
X
extern int nprocs;
extern struct var v;
extern struct proc *procs;
extern struct proc *oldprocs;
extern struct proc **pprocs;
extern struct proc **poldprocs;
X
int mypid;
int noldprocs = 0;
int nprocs = 0;
int max_procs_to_display;
X
struct user user;
X
#define min(a,b) (((a) > (b)) ? (b) : (a))
X
#define MAX_UTMP 64
int nutmps = 0;
struct utmp utmps[MAX_UTMP];
X
/*+-------------------------------------------------------------------------
X	ppproc_pid_compare(ppp1,ppp2)
--------------------------------------------------------------------------*/
ppproc_pid_compare(ppp1,ppp2)
register struct proc **ppp1;
register struct proc **ppp2;
{
#ifdef SVR4
X	return((*ppp1)->p_pidp->pid_id - (*ppp2)->p_pidp->pid_id);
#else
X	return((*ppp1)->p_pid - (*ppp2)->p_pid);
#endif
}       /* end of ppproc_pid_compare */
X
/*+-------------------------------------------------------------------------
X	read_and_sort_procs(initial)
--------------------------------------------------------------------------*/
void
read_and_sort_procs(initial)
int initial;
{
int iproc;
register char *cptr;
register struct proc *tproc;
int omitted_one;
char omitted[80];
X
X	omitted[0] = 0;
X	disp_msg(cpINFO,"");
X	if(!initial)
X	{
X		(void)memcpy((char *)oldprocs,(char *)procs,
X			v.v_proc * sizeof(struct proc));
X		noldprocs = nprocs;
X		(void)memcpy((char *)poldprocs,(char *)pprocs,
X			noldprocs * sizeof(struct proc *));
X	}
X
/* read current procs */
X	grok_proc();
X
/* if slot not in use, force to end when sorting */
X	nprocs = 0;
X	for(iproc = 0; iproc < v.v_proc; iproc++)
X	{
X		tproc = pprocs[iproc];
X		if(     (tproc->p_stat == 0) ||         /* if slot not in use, ... */
#ifdef SVR4
X			(tproc->p_pidp->pid_id == 1)  ||         /* ... or proc is init, ... */
#else
X			(tproc->p_pid == 1)  ||         /* ... or proc is init, ... */
#endif
X			(tproc->p_flag & SSYS))         /* ... or proc is system process */
X		{                                                       /* eliminate from consideration */
#ifdef SVR4
X			tproc->p_pidp->pid_id = MAXPID;   /* force below selected procs in qsort */
#else
X			tproc->p_pid = 32767;   /* force below selected procs in qsort */
#endif
X			continue;
X		}
X		nprocs++;
X	}
X
/* if too many procs, whittle zombies */
X	if(nprocs > max_procs_to_display)
X	{
X		nprocs = 0;
X		omitted_one = 0;
X		for(iproc = 0; iproc < v.v_proc; iproc++)
X		{
X			tproc = pprocs[iproc];
#ifdef SVR4
X			if(tproc->p_pidp->pid_id == MAXPID)       /* previously eliminated? */
#else
X			if(tproc->p_pid == 32767)       /* previously eliminated? */
#endif
X				continue;
X			else if(tproc->p_stat == SZOMB)
X			{
#ifdef SVR4
X				tproc->p_pidp->pid_id = MAXPID;
#else
X				tproc->p_pid = 32767;
#endif
X				omitted_one = 1;
X				continue;
X			}
X			nprocs++;
X		}
X		if(omitted_one)
X		{
X			if(omitted[0])
X				strcat(omitted,"/");
X			strcat(omitted,"zombie");
X		}
X	}
X
/* if still too many procs, whittle shells and gettys */
X	if(nprocs > max_procs_to_display)
X	{
X		nprocs = 0;
X		omitted_one = 0;
X		for(iproc = 0; iproc < v.v_proc; iproc++)
X		{
X			tproc = pprocs[iproc];
#ifdef SVR4
X			if(tproc->p_pidp->pid_id == MAXPID)       /* previously eliminated? */
#else
X			if(tproc->p_pid == 32767)       /* previously eliminated? */
#endif
X				continue;
X			else if(get_user(tproc,&user))
X			{
X				if( !strcmp(cptr = user.u_comm,"csh") ||
X					!strcmp(cptr,"sh")              ||
X					!strcmp(cptr,"ksh")             ||
X					!strcmp(cptr,"bash")    ||
X					!strcmp(cptr,"cron")    ||
X					!strcmp(cptr,"errdemon")||
X					!strcmp(cptr,"lpsched") ||
X					!strcmp(cptr,"logger")  ||
X					!strcmp(cptr,"getty")   ||
X					!strcmp(cptr,"uugetty")         )
X				{
#ifdef SVR4
X					tproc->p_pidp->pid_id = MAXPID;
#else
X					tproc->p_pid = 32767;
#endif
X					omitted_one = 1;
X					continue;
X				}
X			}
X			nprocs++;
X		}
X		if(omitted_one)
X		{
X			if(omitted[0])
X				strcat(omitted,"/");
X			strcat(omitted,"shell/getty");
X		}
X	}
X
/* if still too many procs, whittle swapped */
X	if(nprocs > max_procs_to_display)
X	{
X		nprocs = 0;
X		omitted_one = 0;
X		for(iproc = 0; iproc < v.v_proc; iproc++)
X		{
X			tproc = pprocs[iproc];
#ifdef SVR4
X			if(tproc->p_pidp->pid_id == MAXPID)       /* previously eliminated? */
#else
X			if(tproc->p_pid == 32767)       /* previously eliminated? */
#endif
X				continue;
X			else if(!(tproc->p_flag & SLOAD) && (tproc->p_stat != SRUN))
X			{
#ifdef SVR4
X				tproc->p_pidp->pid_id = MAXPID;
#else
X				tproc->p_pid = 32767;
#endif
X				omitted_one = 1;
X				continue;
X			}
X			nprocs++;
X		}
X		if(omitted_one)
X		{
X			if(omitted[0])
X				strcat(omitted,"/");
X			strcat(omitted,"swapped");
X		}
X	}
X
/* If still too many procs, get rid of processes not using the CPU
X   This hilites the processes that are actually doing something
X   if you have a lot */
X
X	if(nprocs > max_procs_to_display)
X	{
X		nprocs = 0;
X		omitted_one = 0;
X		for(iproc = 0; iproc < v.v_proc; iproc++)
X		{
X			tproc = pprocs[iproc];
#ifdef SVR4
X			if(tproc->p_pidp->pid_id == MAXPID)       /* previously eliminated? */
#else
X			if(tproc->p_pid == 32767)       /* previously eliminated? */
#endif
X				continue;
X			else if(!tproc->p_cpu)
X			{
#ifdef SVR4
X				tproc->p_pidp->pid_id = MAXPID;
#else
X				tproc->p_pid = 32767;
#endif
X				omitted_one = 1;
X				continue;
X			}
X			nprocs++;
X		}
X		if(omitted_one)
X		{
X			if(omitted[0])
X				strcat(omitted,"/");
X			strcat(omitted,"no cpu");
X		}
X	}
X
X
/* if still too many procs, whittle hard */
X	if(nprocs > max_procs_to_display)
X	{
X		nprocs = 0;
X		omitted_one = 0;
X		for(iproc = 0; iproc < v.v_proc; iproc++)
X		{
X			tproc = pprocs[iproc];
#ifdef SVR4
X			if(tproc->p_pidp->pid_id == MAXPID)       /* previously eliminated? */
#else
X			if(tproc->p_pid == 32767)       /* previously eliminated? */
#endif
X				continue;
X			else if(tproc->p_stat == SSLEEP)
X			{
#ifdef SVR4
X				tproc->p_pidp->pid_id = MAXPID;
#else
X				tproc->p_pid = 32767;
#endif
X				omitted_one = 1;
X				continue;
X			}
X			nprocs++;
X		}
X		if(omitted_one)
X		{
X			if(omitted[0])
X				strcat(omitted,"/");
X			strcat(omitted,"sleeping");
X		}
X	}
X
/* if still too many procs, truncate */
X	if(nprocs > max_procs_to_display)
X	{
X		nprocs = max_procs_to_display;
X		disp_msg(cpMED,"display size too small for all processes");
X		omitted[0] = 0;
X	}
X	if(omitted[0])
X	{
X		strcat(omitted," procs omitted");
X		disp_msg(cpLIT,omitted);
X	}
X
/* sort new procs array */
X	(void)qsort((char *)pprocs,(unsigned)v.v_proc,
X		sizeof(struct proc *),ppproc_pid_compare);
X
X	if(initial)
X	{
X		(void)memcpy((char *)oldprocs,(char *)procs,
X			v.v_proc * sizeof(struct proc));
X		noldprocs = nprocs;
X		(void)memcpy((char *)poldprocs,(char *)pprocs,
X			noldprocs * sizeof(struct proc *));
X	}
X
}       /* end of read_and_sort_procs */
X
/*+-------------------------------------------------------------------------
X	read_utmp()
--------------------------------------------------------------------------*/
void
read_utmp()
{
#ifdef SVR4
X    register struct utmp *tutmp = utmps;
X    register struct utmp *ptr;
X
X    nutmps = 0;
X
X    while ((ptr = getutent ()) != (struct utmp *) 0)
X    {
X	*tutmp++ = *ptr;
X	tutmp->ut_id[sizeof(tutmp->ut_id)] = 0;
X	if (++nutmps == MAX_UTMP)
X	    leave_text ("too many utmp entries for me to handle", 1);
X    }
X
X    endutent ();
#else
int utmpfd;
register struct utmp *tutmp = utmps;
X
X	nutmps = 0;
X	if((utmpfd = open("/etc/utmp",O_RDONLY,755)) < 0)
X		leave_text("/etc/utmp open error",255);
X
X	while(read(utmpfd,(char *)(tutmp++),sizeof(struct utmp)) > 0)
X	{
X		/* ensure null termination
X		 * (clobbers 1st byte of ut_line, but we don't use it)
X		 */
X		tutmp->ut_id[sizeof(tutmp->ut_id)] = 0;
X		if(++nutmps == MAX_UTMP)
X			leave_text("too many utmp entries for me to handle",1);
X	}
X	(void)close(utmpfd);
#endif
}       /* end of read_utmp */
X
/*+-------------------------------------------------------------------------
X	find_utmp_for_pgrp(pgrp)
--------------------------------------------------------------------------*/
struct utmp *
find_utmp_for_pgrp(pgrp)
#ifdef SVR4
pid_t pgrp;
#else
int pgrp;
#endif
{
struct utmp *tutmp = utmps;
register int count = nutmps;
X
X	while(count--)
X	{
X		if(tutmp->ut_pid == pgrp)
X			return(tutmp);
X		tutmp++;
X	}
X	return((struct utmp *)0);
}       /* end of find_utmp_for_pgrp */
X
/*+-------------------------------------------------------------------------
X	pgrp_to_ttyname(pgrp)
--------------------------------------------------------------------------*/
char *
pgrp_to_ttyname(pgrp)
int pgrp;
{
register itmp;
struct utmp *tutmp;
X
X	if(!(tutmp = find_utmp_for_pgrp(pgrp)))
X	{
X		read_utmp();
X		tutmp = find_utmp_for_pgrp(pgrp);
X	}
X	if(!tutmp)
X		return("??");
X	else
X	{
X		itmp = strlen(tutmp->ut_id);
X		return(&tutmp->ut_id[(itmp >= 2) ? (itmp - 2) : 0]);
X	}
}       /* end of pgrp_to_ttyname */
X
/*+-------------------------------------------------------------------------
X	get_user(tproc,tuser) - read user struct for pid
return 1 if successful, else 0 if not available
--------------------------------------------------------------------------*/
int
get_user(tproc,tuser)
struct proc *tproc;
struct user *tuser;
{
#if defined(RDUBLK)     /* see sysi86.h #include above */
X	/* this system call is not returning 0 on success ?!? */
#ifdef SVR4
X	return (!!sysi86 (RDUBLK, tproc->p_pidp->pid_id, (char *) tuser, sizeof (*tuser)));
#else
X	return(!!sysi86(RDUBLK,tproc->p_pid,(char *)tuser,sizeof(*tuser)));
#endif
#else /* RDUBLK */
X	register caddr_t uptr = (caddr_t)tuser;
X	register int ubrdcount = sizeof(struct user);
X	int ipde;
X	paddr_t mptr;
X
#if !defined(ISC_1) && !defined(mips)
X	if(tproc->p_flag & SULOAD)
X	{
X		for(ipde = 0;
#if defined(SVR31)
X			ipde < USIZE;
#else
X			ipde < tproc->p_usize;
#endif
X			ipde++)
X		{
X			if(!tproc->p_ubptbl[ipde].pgm.pg_pres)  /* if not resident */
X				return(0);
X			mptr = tproc->p_ubptbl[ipde].pgm.pg_pfn * NBPP;
X			mread(uptr,(daddr_t)mptr,min(ubrdcount,NBPP));
X			uptr += NBPP;
X			if((ubrdcount -= NBPP) <= 0)
X				break;
X		}
X	}
X	else
X	{
#if defined(SVR31)
X		mptr = tproc->p_ubdbd [0].dbd_blkno * NBPSCTR;
#else
X		mptr = tproc->p_ubdbd.dbd_blkno * NBPSCTR;
#endif
X		sread(uptr,mptr,ubrdcount);
X	}
#else /* ISC_1: a compromise first-attempt */
X	for(ipde = 0; ipde < USIZE; ipde++)
X	{
X		if(!tproc->p_ubptbl[ipde].pgm.pg_pres)  /* if not resident */
X			return(0);
X		mptr = tproc->p_ubptbl[ipde].pgm.pg_pfn * NBPP;
X		mread(uptr,(daddr_t)mptr,min(ubrdcount,NBPP));
X		uptr += NBPP;
X		if((ubrdcount -= NBPP) <= 0)
X			break;
X	}
#endif /* ISC_1 */
X
X	/*
X	 * we can get crap from swap if things change after we get
X	 * an address to read from, so validate user as best we can
X	 */
X	return( (tuser->u_ruid == tproc->p_uid) ||
X			(tuser->u_ruid == tproc->p_suid));
#endif /* RDUBLK */
}       /* end of get_user */
X
/*+-------------------------------------------------------------------------
uid to username conversion; thanks for the idea to William LeFebvre
--------------------------------------------------------------------------*/
#define UID_NAME_HASH_SIZE      127     /* prime */
#define HASH_EMPTY                      32767
#define HASHIT(i)                       ((i) % UID_NAME_HASH_SIZE)
X
struct uid_name_hash_entry {
X	ushort uid;
X	char name[10];
};
X
struct uid_name_hash_entry uid_name_table[UID_NAME_HASH_SIZE];
int uid_count = 0;
X
/*+-------------------------------------------------------------------------
X	init_uid_name_hash()
--------------------------------------------------------------------------*/
void
init_uid_name_hash()
{
register int ihash = 0;
register struct uid_name_hash_entry *hashent = uid_name_table;
X
X	while(ihash++ < UID_NAME_HASH_SIZE)
X	{
X		hashent->uid = HASH_EMPTY;
X		hashent++;
X	}
}       /* end of init_uid_name_hash */
X
/*+-------------------------------------------------------------------------
X	uid_name_enter(uid,name)
--------------------------------------------------------------------------*/
int
uid_name_enter(uid,name)
register ushort uid;
register char *name;
{
register ushort table_uid;
register int hashval;
X
X	if(++uid_count >= UID_NAME_HASH_SIZE - 1)
X		leave_text("too many user names for me to handle",1);
X
X	hashval = HASHIT(uid);
X	while((table_uid = uid_name_table[hashval].uid) != HASH_EMPTY)
X	{
X		if(table_uid == uid)
X			return(hashval);
X		hashval = (hashval + 1) % UID_NAME_HASH_SIZE;
X	}
X
X	uid_name_table[hashval].uid = uid;
X	(void)strncpy(uid_name_table[hashval].name,name,
X		sizeof(uid_name_table[0].name));
X
X	return(hashval);
X
}       /* end of uid_name_enter */
X
/*+-------------------------------------------------------------------------
X	getpwent_and_enter(uid)
--------------------------------------------------------------------------*/
getpwent_and_enter(uid)
register ushort uid;
{
register int hashval;
register struct passwd *pwd;
char errant[10];
struct passwd *getpwuid();
X
X	pwd = getpwuid(uid);
X	endpwent();
X	if(pwd)
X	{
X		hashval = uid_name_enter(pwd->pw_uid,pwd->pw_name);
X		return(hashval);
X	}
X	(void)sprintf(errant,"%u",uid);
X	return(uid_name_enter(uid,errant));
}       /* end of getpwent_and_enter */
X
/*+-------------------------------------------------------------------------
X	uid_to_name(uid)
--------------------------------------------------------------------------*/
char *
uid_to_name(uid)
register ushort uid;
{
register int uid_hash;
register ushort table_uid;
X
X	uid_hash = HASHIT(uid);
X	while((table_uid = uid_name_table[uid_hash].uid) != uid)
X	{
X		if(table_uid == HASH_EMPTY)
X		{
X			/* not in hash table */
X			uid_hash = getpwent_and_enter(uid);
X			break;          /* out of while */
X		}
X		uid_hash = (uid_hash + 1) % UID_NAME_HASH_SIZE;
X	}
X	return(uid_name_table[uid_hash].name);
}       /* end of uid_to_name */
X
/*+-----------------------------------------------------------------------
X	char *get_cpu_time_str(ticks)
X  6-char static string address is returned
------------------------------------------------------------------------*/
char *
get_cpu_time_str(ticks)
time_t ticks;
{
static char timestr[10];
time_t mm,ss;
extern int hz;
X
X	if(ticks < 0)           /* keep bogus numbers from polluting display */
X		return("------");
X
X	ticks /= hz;
X	mm = ticks / 60L;
X	ticks -= mm * 60L;
X	ss = ticks;
X
X	if(mm > 9999)
X		(void)strcpy(timestr,">9999m");
X	else if(mm > 999)
X		(void)sprintf(timestr,"%5ldm",mm);
X	else
X		(void)sprintf(timestr,"%3lu:%02lu",mm,ss);
X
X	return(timestr);
X
}       /* end of get_cpu_time_str */
X
#define PROC_Y          1
#define PROC_X          0
#define UID_X           2
#define PID_X           12
#define CPU_X           18
#define PRI_X           22
#define NICE_X          26
#define UTIME_X         29
#define STIME_X         36
#define SIZE_X          43
#define TTY_X           48
#define CMD_X           52
X
/*+-------------------------------------------------------------------------
X	display_proc_stat(win,iproc,initial)
00000000001111111111222222222233333333334444444444555555555566666666667777777777
01234567890123456789012345678901234567890123456789012345678901234567890123456789
S     USER   PID  CPU PRI NI  UCPU   SCPU  SIZE TTY CMD
#!########X ##### ### ### ## ###### ###### #### ### ########
--------------------------------------------------------------------------*/
void
display_proc_stat(win,iproc,initial)
WINDOW *win;
register int iproc;
register int initial;
{
register int positioned = 0;
register struct proc *tproc = pprocs[iproc];
struct proc          *oproc = poldprocs[iproc];
int got_user;
static char *p_stat_str = " sRzdipx";   /* dependent on values of SSLEEP etc */
char buf[20];
X
X	use_cp(win,cpINFO);
X	if((tproc->p_stat == SRUN) && !(tproc->p_flag & SLOAD))
X		use_cp(win,cpHIGH);
X	else if(tproc->p_stat == SRUN)
X		use_cp(win,cpMED);
#ifdef SVR4
X	if(tproc->p_pidp->pid_id != oproc->p_pidp->pid_id)
#else
X	if(tproc->p_pid != tproc->p_pid)
#endif
X		initial = 1;
X
X	wmove(win,PROC_Y + iproc,PROC_X);
X	waddch(win,(chtype)p_stat_str[tproc->p_stat]);
X	waddch(win,(tproc->p_flag & SLOAD) ? (chtype)' ' : (chtype)'S');
X	positioned = 1;
X
X	if(initial)
X	{
X		if(!positioned)
X			wmove(win,PROC_Y + iproc,PROC_X + UID_X);
X		(void)sprintf(buf,"%8s",uid_to_name(tproc->p_uid));
X		waddstr(win,buf);
#ifdef SVR4
X		waddch(win,(tproc->p_cred->cr_uid != tproc->p_cred->cr_suid) ? '#' : ' ');
#else
X		waddch(win,(tproc->p_uid != tproc->p_suid) ? '#' : ' ');
#endif
X		waddch(win,' ');
X		positioned = 1;
X	}
X	else
X		positioned = 0;
X
X	if(initial)
X	{
X		if(!positioned)
X			wmove(win,PROC_Y + iproc,PROC_X + PID_X);
#ifdef SVR4
X		(void)sprintf(buf,"%5d ",tproc->p_pidp->pid_id);
#else
X		(void)sprintf(buf,"%5d ",tproc->p_pid);
#endif
X		waddstr(win,buf);
X		positioned = 1;
X	}
X	else
X		positioned = 0;
X
X	if(initial || (tproc->p_cpu != oproc->p_cpu))
X	{
X		if(!positioned)
X			wmove(win,PROC_Y + iproc,PROC_X + CPU_X);
X		(void)sprintf(buf,"%3u ",tproc->p_cpu);
X		waddstr(win,buf);
X		positioned = 1;
X	}
X	else
X		positioned = 0;
X
X	if(initial || (tproc->p_pri != oproc->p_pri))
X	{
X		if(!positioned)
X			wmove(win,PROC_Y + iproc,PROC_X + PRI_X);
X		(void)sprintf(buf,"%3u ",tproc->p_pri);
X		waddstr(win,buf);
X		positioned = 1;
X	}
X	else
X		positioned = 0;
X
#ifdef SVR4
X	if(initial)
#else
X	if(initial || (tproc->p_nice != oproc->p_nice))
#endif
X	{
X		if(!positioned)
X			wmove(win,PROC_Y + iproc,PROC_X + NICE_X);
#ifdef SVR4
X		(void)sprintf(buf,"?? ");
#else
X		(void)sprintf(buf,"%2d ",tproc->p_nice);
#endif
X		waddstr(win,buf);
X		positioned = 1;
X	}
X	else
X		positioned = 0;
X
/* since not saving user area, always update fields from it */
X	if(!positioned)
X		wmove(win,PROC_Y + iproc,PROC_X + UTIME_X);
X	if(got_user = get_user(tproc,&user))
X	{
#ifdef SVR4
X		waddstr(win,get_cpu_time_str(tproc->p_utime));
#else
X		waddstr(win,get_cpu_time_str(user.u_utime));
#endif
X		waddch(win,' ');
#ifdef SVR4
X		waddstr(win,get_cpu_time_str(tproc->p_stime));
#else
X		waddstr(win,get_cpu_time_str(user.u_stime));
#endif
X		waddch(win,' ');
/*
X * process size:
X *
X * There are ways that seem right to a man, but the end of them is death.
X * u_tsize and friends are not clicks, but in bytes.
X * I thought this would have been:
X *              (ctob((u_long)user.u_tsize + user.u_dsize + user.u_ssize)) / 1024);
X * At least this makes numbers agree with /bin/ps, although I cannot
X * figure out why there is one extra page charged by ps (user is 2 pages).
X *
X *
X * This was evidentally wrong in SCO UNIX 3.2.0 and fixed in 3.2.1.
X * If you get lots of processes who size is reported as 4, define
X * USIZE_FIXED
X */
#ifdef SVR4
X		(void) sprintf (buf, "%4lu ",
X		    ctob ((u_long) user.u_tsize + user.u_dsize + user.u_ssize)
X			/ 1024
X		);
#else
X		(void)sprintf(buf,"%4lu ",
#if !defined(M_UNIX) /* !SCO */
X	/*
X    ** For ISC:
X	** Reports exactly the same value as ps.  The values in the user
X	** area seem totally bogus (u_tsize is always 0, from observation)
X	** so this size, the program swap size, seems the best measure.
X	** Without USIZE_FIXED, on ISC2.02/Dell UNIX 1.1 I get zeroes.
X	** With USIZE_FIXED I get values, but they're way out (e.g. vpix
X	** and cron shown as the same size....).
X	*/
X			(u_long)tproc->p_size
#else /* SCO */
#if defined(USIZE_FIXED)        /* SCO UNIX 3.2.1 (and later?) */
X			(ctob((u_long)user.u_tsize + user.u_dsize + user.u_ssize)) / 1024
#else                           /* SCO UNIX 3.2.0 */
X			(((u_long)user.u_tsize + 511) / 1024) +
X			(((u_long)user.u_dsize + 511) / 1024) +
X			(((u_long)user.u_ssize + 511) / 1024) +
X			(((u_long)((user.u_tsize)?1:0) * NBPP) / 1024)
#endif
#endif /* SCO */
X		);
#endif /* SVR4 */
X		waddstr(win,buf);
X	}
X	else
X		waddstr(win,"------ ------ ---- ");
X
/*
X	positioned = 1;
X	if(!positioned)
X		wmove(win,PROC_Y + iproc,PROC_X + TTY_X);
*/
#ifdef SVR4
X	(void)sprintf(buf,"%3.3s ",pgrp_to_ttyname(tproc->p_sessp->s_sidp->pid_id));
#else
X	(void)sprintf(buf,"%3.3s ",pgrp_to_ttyname(tproc->p_pgrp));
#endif
X	waddstr(win,buf);
X	positioned = 1;
X
/*
X	if(!positioned)
X		wmove(win,PROC_Y + iproc,PROC_X + CMD_X);
*/
X	if(got_user)
X	{
X	register char *cptr = user.u_psargs;
X	int y,x,maxx = getmaxx(win);
X		getyx(win,y,x);
X		while(*cptr && (x < maxx))
X		{
X			*cptr &= 0x7F;
X			if(*cptr < 0x20)
X				*cptr = 0x20;
X			waddch(win,*cptr);
X			cptr++,x++;
X		}
X	}
X	else
X	{
X		switch(tproc->p_stat)
X		{
X			case SZOMB:
X				waddstr(win,"<zombie>");
X				break;
X			case SXBRK:
X				waddstr(win,"<xbreak>");
X				break;
X			case SIDL:
X				waddstr(win,"<in creation>");
X				break;
X			default:
X				waddstr(win,"<swapping>");
X		}
X	}
X
X	wclrtoeol(win);
X
}       /* end of display_proc_stat */
X
/*+-------------------------------------------------------------------------
X	display_proc_stats(win,initial)
--------------------------------------------------------------------------*/
void
display_proc_stats(win,initial)
WINDOW *win;
int initial;
{
register int iproc;
int y,x;
X
X	touchwin (win);
X	if(initial)
X	{
X		use_cp(win,cpBANNER);
X		wmove(win,0,0);
X		waddstr(win,
X			"S     USER   PID  CPU PRI NI  UCPU   SCPU  SIZE TTY CMD");
X		getyx(win,y,x);
X		while(x < getmaxx(win))
X			waddch(win,(chtype)' '),x++;
X	}
X	mypid = getpid();
X	max_procs_to_display = getmaxy(win) - PROC_Y;
X	read_and_sort_procs(initial);
X	max_procs_to_display = min(nprocs,max_procs_to_display);
X	for(iproc = 0; iproc < max_procs_to_display; iproc++)
X		display_proc_stat(win,iproc,1);
X	wclrtobot(win);
}       /* end of display_proc_stats */
X
/*+-------------------------------------------------------------------------
X	det_proc_init()
--------------------------------------------------------------------------*/
det_proc_init()
{
X	init_uid_name_hash();   /* see det_proc.c */
}       /* end of det_proc_init */
/* vi: set tabstop=4 shiftwidth=4: */
/* end of det_proc.c */
SHAR_EOF
chmod 0644 det_proc.c ||
echo 'restore of det_proc.c failed'
Wc_c="`wc -c < 'det_proc.c'`"
test 24177 -eq "$Wc_c" ||
	echo 'det_proc.c: original size 24177, current size' "$Wc_c"
rm -f _shar_wnt_.tmp
fi
# ============= det_sio.c ==============
if test -f 'det_sio.c' -a X"$1" != X"-c"; then
	echo 'x - skipping det_sio.c (File already exists)'
	rm -f _shar_wnt_.tmp
else
> _shar_wnt_.tmp
echo 'x - extracting det_sio.c (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'det_sio.c' &&
/*+-------------------------------------------------------------------------
X	det_sio.c - UNIX V/386 system monitor serial I/O detail
X	...!{gatech,emory}!n4hgf!wht
X
X  Defined functions:
X	B_to_baud_rate(code)
X	cflag_to_baud_d_p_s(cflag)
X	grok_sio_tty()
X	display_siofull_init(win,tly,tlx,show_flag)
X	display_siofull_update(win,tly,tlx,tsio)
X	display_siosum_update(win,y,tsio)
X	tty_slot_compare(sio1,sio2)
X
--------------------------------------------------------------------------*/
/*+:EDITS:*/
/*:08-01-1991-23:34-wht@n4hgf-release 2.40 source control point */
/*:05-09-1991-03:35-wht@n4hgf-gcc gives good warning */
/*:08-10-1990-14:12-jmd@p1so/wht@n4hgf-2.20-add Tandem Integrity S2 */
/*:08-07-1990-14:24-wht@n4hgf-nba@sysware.dk SVR31 updates */
/*:08-02-1990-15:36-wht@n4hgf-2.12-old curses hacks+minor 3.2 formalizations */
/*:07-28-1990-18:06-wht@n4hgf-2.10 release */
/*:06-27-1990-17:33-wht@n4hgf-fix bug during 24-line display */
/*:06-27-1990-01:57-wht@n4hgf-1.10-incorporate suggestions from alpha testers */
/*:06-26-1990-03:17-wht@n4hgf-creation */
X
#include "config.h"
#if defined(M_UNIX) /* SCO */
#define M_TERMINFO
#include <curses.h>
#undef reg     /* per nba@sysware.dk */
#ifdef NATIVE_PANELS
# include <panel.h>
#else
# include "libpanel.h"
#endif
#include <string.h>
#include <nlist.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/ascii.h>
#undef NGROUPS_MAX
#undef NULL
#include <sys/param.h>
#include <sys/tty.h>
X
#include "nlsym.h"
#include "libkmem.h"
#include "libmem.h"
#include "libswap.h"
#include "libnlsym.h"
#include "u386mon.h"
X
extern int errno;
extern int sys_nerr;
extern char *sys_errlist[];
X
#define SIO_NTTY 16	/* for now */
struct tty sio[SIO_NTTY];
X
#define t_slot	t_delct
X
int nsio;	/* number of sios open */
X
typedef struct slabel
{
X	int y,x;
X	char *label;
} SLABEL;
X
SLABEL tty_slabels[] =
{
X    {  0,  0, "iflag:" },
X    {  2,  0, "oflag:" },
X    {  3,  0, "cflag:" },
X    {  4,  0, "lflag:" },
X    {  5,  7, "INTR QUIT ERASE KILL EOF/VMIN  EOL/VTIME EOL2 SWTCH" },
X    {  6,  0, "cc:" },
X    {  7,  0, "state:" },
X    {  -1,-1, (char *)0}
};
X
typedef struct bitfld
{
X	int y,x;
X	char *label;
X	int flag_num;
X	int mask;
} BITFLD;
X
#define IFLAG 1
#define OFLAG 2
#define LFLAG 3
#define CFLAG 4
#define STATE 5
X
BITFLD ttybitflds[] =
{
X    {  0,  7, "IGNBRK", IFLAG, IGNBRK },
X    {  0, 15, "BRKINT", IFLAG, BRKINT },
X    {  0, 23, "IGNPAR", IFLAG, IGNPAR },
X    {  0, 31, "PARMRK", IFLAG, PARMRK },
X    {  0, 39, "INPCK",  IFLAG, INPCK },
X    {  0, 46, "ISTRIP", IFLAG, ISTRIP },
X    {  0, 53, "INLCR",  IFLAG, INLCR },
X    {  0, 60, "IGNCR",  IFLAG, IGNCR },
X    {  0, 68, "ICRNL",  IFLAG, ICRNL },
X    {  1,  7, "IUCLC",  IFLAG, IUCLC },
X    {  1, 15, "IXON",   IFLAG, IXON },
X    {  1, 23, "IXOFF",  IFLAG, IXOFF },
X    {  1, 31, "IXANY",  IFLAG, IXANY },
X    {  2,  7, "OPOST",  OFLAG, OPOST },
X    {  2, 15, "OLCUC",  OFLAG, OLCUC },
X    {  2, 23, "ONLCR",  OFLAG, ONLCR },
X    {  2, 31, "OCRNL",  OFLAG, OCRNL },
X    {  2, 39, "ONOCR",  OFLAG, ONOCR },
X    {  2, 46, "ONLRET", OFLAG, ONLRET },
X    {  2, 53, "OFDEL",  OFLAG, OFDEL },
X    {  3, 23, "CREAD",  CFLAG, CREAD },
X    {  3, 31, "HUPCL",  CFLAG, HUPCL },
X    {  3, 39, "CLOCAL", CFLAG, CLOCAL },
#ifdef RTSFLOW
X    {  3, 46, "RTSFLO", CFLAG, RTSFLOW },
#endif
#ifdef CTSFLOW
X    {  3, 53, "CTSFLO", CFLAG, CTSFLOW },
#endif
X    {  4,  7, "ISIG",   LFLAG, ISIG },
X    {  4, 15, "ICANON", LFLAG, ICANON },
X    {  4, 23, "XCASE",  LFLAG, XCASE },
X    {  4, 31, "ECHO",   LFLAG, ECHO },
X    {  4, 39, "ECHOE",  LFLAG, ECHOE },
X    {  4, 46, "ECHOK",  LFLAG, ECHOK },
X    {  4, 53, "ECHONL", LFLAG, ECHONL },
X    {  4, 60, "NOFLSH", LFLAG, NOFLSH },
X    {  4, 68, "XCLUDE", LFLAG, XCLUDE },
X	{  7,  7, "TO",     STATE, TIMEOUT },
X	{  7, 10, "WO",     STATE, WOPEN },
X	{  7, 13, "O",      STATE, ISOPEN },
X	{  7, 15, "TB",     STATE, TBLOCK },
X	{  7, 18, "CD",     STATE, CARR_ON },
X	{  7, 21, "BY",     STATE, BUSY },
X	{  7, 24, "OSLP",   STATE, OASLP },
X	{  7, 29, "ISLP",   STATE, IASLP },
X	{  7, 34, "STOP",   STATE, TTSTOP },
X	{  7, 39, "EXT",    STATE, EXTPROC },
X	{  7, 43, "TACT",   STATE, TACT },
X	{  7, 48, "ESC",    STATE, CLESC },
X	{  7, 52, "RTO",    STATE, RTO },
X	{  7, 56, "IOW",    STATE, TTIOW },
X	{  7, 60, "XON",    STATE, TTXON },
X	{  7, 64, "XOFF",   STATE, TTXOFF },
X    {  -1,-1, (char *)0,    -1,    -1 }
};
X
typedef struct valyx
{
X	int y,x;
} VALYX;
X
VALYX ttyvalyx[] =
{
#define Fc_intr       0
X	{  6,  8 },
#define Fcc_quit      1
X	{  6, 13 },
#define Fcc_erase     2
X	{  6, 18 },
#define Fcc_kill      3
X	{  6, 24 },
#define Fcc_eof       4
X	{  6, 30 },
#define Fcc_eol       5
X	{  6, 40 },
#define Fcc_eol2      6
X	{  6, 49 },
#define Fcc_swtch     7
X	{  6, 54 },
#define Fbaud_b_p_s   8
X	{  3,  7 }
};
X
typedef struct b_to_br
{
X	char *baud_rate;
X	int B_code;
} B_TO_BR;
X
B_TO_BR speeds[] = 	/* ordered to put less common rates later in table */
{					/* and the vagaries of baud rates above 9600 "handled" */
X	" 2400",	B2400,
X	" 1200",	B1200,
X	" 9600",	B9600,
#if defined(B19200)
X	"19200",	B19200,
#endif
#if defined(B38400)
X	"38400",	B38400,
#endif
X	" 4800",	B4800,
X	"  300",	B300,
#ifdef SVR4
X	"  200",        B200,
X	"  150",        B150,
X	"  134",        B134,
#endif
X	"  110",	B110,
X	"  600",	B600,
X	"   75",	B75,
X	"   50",	B50,
X	"  HUP",	B0,
X	" EXTA",	EXTA,
X	" EXTB",	EXTB,
X
X	(char *)0,0
};
X
/*+-------------------------------------------------------------------------
X	tty_slot_compare(sio1,sio2)
--------------------------------------------------------------------------*/
int
tty_slot_compare(sio1,sio2)
struct tty *sio1;
struct tty *sio2;
{
X	return(sio1->t_slot - sio2->t_slot);
}	/* end of tty_slot_compare */
X
/*+-------------------------------------------------------------------------
X	grok_sio_tty()
--------------------------------------------------------------------------*/
void
grok_sio_tty()
{
register isio;
register struct tty *tsio;
X
X	nsio = 0;
X	kread((caddr_t)sio,sio_ttyaddr,sizeof(struct tty) * SIO_NTTY);
X	for(isio = 0; isio < SIO_NTTY; isio++)
X	{
X		tsio = &sio[isio];
X		if(tsio->t_state & (WOPEN | ISOPEN))
X		{
X			tsio->t_slot = (ushort)isio;
X			nsio++;
X			continue;
X		}
X		tsio->t_slot = 127;
X	}
X	(void)qsort((char *)sio,(unsigned)SIO_NTTY,
X		sizeof(struct tty),tty_slot_compare);
X
}	/* end of grok_sio_tty */
X
/*+-------------------------------------------------------------------------
X	B_to_baud_rate(code) - convert CBAUD B_ code to baud rate string
--------------------------------------------------------------------------*/
char *
B_to_baud_rate(code)
{
register int n;
X
X	for(n=0; speeds[n].baud_rate; n++)
X		if(speeds[n].B_code == code)
X			return(speeds[n].baud_rate);
X	return("-----");
}	/* end of B_to_baud_rate */
X
/*+-------------------------------------------------------------------------
X	cflag_to_baud_d_p_s(cflag)
--------------------------------------------------------------------------*/
char *
cflag_to_baud_d_p_s(cflag)
int cflag;
{
register char *cptr;
static char rtnstr[16];
X
X	strcpy(rtnstr,B_to_baud_rate(cflag & CBAUD));
X	cptr = rtnstr + strlen(rtnstr);
X	*cptr++ = '-';
X	switch(cflag & CSIZE)
X	{
X		case CS5: *cptr++ = '5'; break;
X		case CS6: *cptr++ = '6'; break;
X		case CS7: *cptr++ = '7'; break;
X		case CS8: *cptr++ = '8'; break;
X	}
X	*cptr++ = '-';
X	*cptr++ = (cflag & PARENB) ? ((cflag & PARODD) ? 'O' : 'E') : 'N';
X	*cptr++ = '-';
X	*cptr++ = (cflag & CSTOPB) ? '2' : '1';
X	*cptr = 0;
X	return(rtnstr);
X
}	/* end of cflag_to_baud_d_p_s */
X
/*+-----------------------------------------------------------------------
X	display_siofull_update(win,tly,tlx,tsio)
X
000000000011111111112222222222333333333344444444445555555555666666666677777
012345678901234567890123456789012345678901234567890123456789012345678901234
iflag: IGNBRK  BRKINT  IGNPAR  PARMRK  INPCK  ISTRIP INLCR  IGNCR   ICRNL
X       IUCLC   IXON    IXOFF   IXANY
oflag: OPOST   OLCUC   ONLCR   OCRNL   ONOCR  ONLRET OFDEL
cflag: 09600-8-N-1     CREAD   HUPCL   CLOCAL
lflag: ISIG    ICANON  XCASE   ECHO    ECHOE  ECHOK  ECHONL NOFLSH  XCLUDE
X       INTR QUIT ERASE KILL EOF/VMIN  EOL/VTIME EOL2 SWTCH 
cc:     03   1c   08    15    01        00       00   00   
X
------------------------------------------------------------------------*/
void
display_siofull_update(win,tly,tlx,tsio)
WINDOW *win;
int tly;
int tlx;
struct tty *tsio;
{
register flag;
register i_cc;
BITFLD *bfptr = ttybitflds;
VALYX *vptr = ttyvalyx;
X
X	use_cp(win,cpLOW);
X	while(bfptr->y >= 0)
X	{
X		switch(bfptr->flag_num)
X		{
X			case IFLAG: flag = tsio->t_iflag; break;
X			case OFLAG: flag = tsio->t_oflag; break;
X			case LFLAG: flag = tsio->t_lflag; break;
X			case CFLAG: flag = tsio->t_cflag; break;
X			case STATE: flag = tsio->t_state; break;
X		}
X		flag &= bfptr->mask;
X		wmove(win,bfptr->y + tly,bfptr->x + tlx);
X		if(flag)
X			use_cp(win,cpREVERSE);
X		waddstr(win,bfptr->label);
X		if(flag)
X			use_cp(win,cpLOW);
X		bfptr++;
X	}
X	for(i_cc = 0; i_cc < NCC; i_cc++)
X	{
X		wmove(win,vptr->y + tly,vptr->x + tlx);
X		wprintw(win,"%02x",tsio->t_cc[i_cc]);
X		vptr++;
X	}
X
X	vptr = &ttyvalyx[Fbaud_b_p_s];
X	clear_area(win,vptr->y + tly,vptr->x + tlx,12);
X	waddstr(win,cflag_to_baud_d_p_s(tsio->t_cflag));
X
}	/* end of display_siofull_update */
X
/*+-------------------------------------------------------------------------
X	display_siofull_init(win,tly,tlx,show_flag)
--------------------------------------------------------------------------*/
void
display_siofull_init(win,tly,tlx,show_flag)
WINDOW *win;
int tly;
int tlx;
int show_flag;
{
register y;
SLABEL *sptr = tty_slabels;
X
X	use_cp(win,cpLIT);
X	for(y = 0; y < 7; y++)
X		clear_area(win,y,0,getmaxy(win));
X	if(show_flag)
X	{
X		while(sptr->y >= 0)
X		{
X			wmove(win,sptr->y + tly,sptr->x + tlx);
X			waddstr(win,sptr->label);
X			sptr++;
X		}
X	}
X
}	/* end of display_siofull_init */
X
/*+-------------------------------------------------------------------------
X	display_siosum_update(win,y,tsio)
--------------------------------------------------------------------------*/
void
display_siosum_update(win,y,tsio)
register WINDOW *win;
int y;
register struct tty *tsio;
{
register unsigned int itmp;
register opened = tsio->t_state & (ISOPEN | WOPEN);
char s8[8];
X
#define TX 1
#define RX 6
#define CX 11
#define OX 16
#define SX 23
#define FX 30
X
X	wmove(win,y,TX);
#ifdef M_UNIX
X	waddch(win,(tsio->t_slot < 8) ? '1' : '2');
X	waddch(win,(tsio->t_slot % 8) + 'a');
#else
X	wprintw(win,"%02d",tsio->slot);
#endif
X
X	if(!opened)
X	{
X		use_cp(win,cpINFO);
X		clear_area(win,y,TX,COLS - TX);
X		waddstr(win,"closed");
X		return;
X	}
X
X	wmove(win,y,RX);
X	if((itmp = (unsigned)tsio->t_rawq.c_cc) > 999)
X		itmp = 999;
X	if(itmp > 10)
X		use_cp(win,cpHIGH);
X	else if(itmp > 3)
X		use_cp(win,cpMED);
X	else
X		use_cp(win,cpLOW);
X	wprintw(win,"%3d",itmp);
X
X	if((itmp = (unsigned)tsio->t_canq.c_cc) > 999)
X		itmp = 999;
X	if(itmp > 20)
X		use_cp(win,cpHIGH);
X	else if(itmp > 10)
X		use_cp(win,cpMED);
X	else
X		use_cp(win,cpLOW);
X	wmove(win,y,CX);
X	wprintw(win,"%3d",itmp);
X
X	if((itmp = (unsigned)tsio->t_outq.c_cc + tsio->t_tbuf.c_count) > 99999)
X		itmp = 99999;
X	if(itmp > 75)
X		use_cp(win,cpHIGH);
X	else if(itmp > 20)
X		use_cp(win,cpMED);
X	else
X		use_cp(win,cpLOW);
X	wmove(win,y,OX);
X	wprintw(win,"%5d",itmp);
X
X	use_cp(win,cpINFO);
X	wmove(win,y,SX);
X	waddstr(win,B_to_baud_rate(tsio->t_cflag & CBAUD));
X
X	strcpy(s8,".....");
X	if(tsio->t_state & WOPEN)
X		s8[0] = 'W';
X	else if(tsio->t_state & ISOPEN)
X		s8[0] = 'O';
X	if(tsio->t_state & CARR_ON)
X		s8[1] = 'C';
X	if(tsio->t_state & BUSY)
X		s8[2] = 'B';
X	if(tsio->t_state & TTSTOP)
X		s8[3] = 'S';
X	if(tsio->t_state & TIMEOUT)
X		s8[4] = 'D';
X	wmove(win,y,FX);
X	waddstr(win,s8);
X
X	wprintw(win,"%7o",tsio->t_iflag);
X	wprintw(win,"%7o",tsio->t_oflag);
X	wprintw(win,"%7o",tsio->t_cflag);
X	wprintw(win,"%7o",tsio->t_lflag);
X	if(tsio->t_pgrp)
X		wprintw(win,"%6d",tsio->t_pgrp);
X	else
X		waddstr(win,"      ");
X
}	/* end of display_siosum_update */
X
/*+-------------------------------------------------------------------------
X	display_sio_summary(win,initial)
--------------------------------------------------------------------------*/
display_sio_summary(win,initial)
register WINDOW *win;
int initial;
{
register int isio;
int max_displayable_sios = getmaxy(win) - 2;
static char *header  = 
" tty  raw  can    out  speed  state  iflag  oflag  cflag  lflag  pgrp";
static char *legend =
"W=wait for open  O=open C=carrier on  B=output busy  S=stopped  T=timeout";
static couldnt_display_all = 0;
X
X	if(initial)
X	{
X		use_cp(win,cpBANNER);
X		clear_area(win,0,0,getmaxx(win));
X		waddstr(win,header);
X		use_cp(win,cpLIT);
X		clear_area(win,getmaxy(win)-1,0,getmaxx(win));
X		waddstr(win,legend);
X		couldnt_display_all = 1;
X	}
X	grok_sio_tty();
X	for(isio = 0; (isio < nsio); isio++)
X	{
X		if(isio > max_displayable_sios)
X		{
X			wmove(win,getmaxy(win)-2);
X			use_cp(win,cpMED);
X			waddstr(win,"cannot display all active serial ports");
X			couldnt_display_all = 1;
X			return;
X		}
X		display_siosum_update(win,isio + 1,&sio[isio]);
X	}
X
X	for(; isio < getmaxy(win)-2; isio++);
X		clear_area(win,isio + 1,0,getmaxx(win));
X
X	if(couldnt_display_all)
X	{
X		use_cp(win,cpINFO);
X		clear_area(win,getmaxy(win)-2,0,getmaxx(win));
X		couldnt_display_all = 0;
X	}
X
}	/* end of display_sio_summary */
X
#endif /* M_UNIX / SCO */
/* vi: set tabstop=4 shiftwidth=4: */
/* end of det_sio.c */
SHAR_EOF
chmod 0644 det_sio.c ||
echo 'restore of det_sio.c failed'
Wc_c="`wc -c < 'det_sio.c'`"
test 13242 -eq "$Wc_c" ||
	echo 'det_sio.c: original size 13242, current size' "$Wc_c"
rm -f _shar_wnt_.tmp
fi
# ============= det_stream.c ==============
if test -f 'det_stream.c' -a X"$1" != X"-c"; then
	echo 'x - skipping det_stream.c (File already exists)'
	rm -f _shar_wnt_.tmp
else
> _shar_wnt_.tmp
echo 'x - extracting det_stream.c (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'det_stream.c' &&
/*+-------------------------------------------------------------------------
X	det_stream.c - UNIX V/386 system monitor stream usage detail
X	martin@hppcmart.grenoble.hp.com
X
00000000001111111111222222222233333333334444444444555555555566666666667777777777
01234567890123456789012345678901234567890123456789012345678901234567890123456789
Resource             Config Alloc Fail -- (% of resource used) -----------------
#################### ###### ##### #### ######################################### 
X  Defined functions:
X
--------------------------------------------------------------------------*/
/*+:EDITS:*/
/*:08-01-1991-23:34-wht@n4hgf-release 2.40 source control point */
/*:05-15-1991-17:22-wht@n4hgf-2.3 patches for SVR31 from nba@sysware.dk */
/*:02-07-1991-13:30-martin@hppcmart-creation */
X
#define M_TERMINFO
X
#include <curses.h>
#ifdef NATIVE_PANELS
# include <panel.h>
#else
# include "libpanel.h"
#endif
#include <string.h>
#include <nlist.h>
#include <sys/types.h>
#include <sys/stat.h>
/*
#include <sys/ascii.h>
*/
#include <sys/var.h>
#undef NGROUPS_MAX
#undef NULL
#include <sys/param.h>
#include <sys/stream.h>
#include <sys/strstat.h>
X
#include "nlsym.h"
#include "libkmem.h"
#include "libmem.h"
#include "libswap.h"
#include "libnlsym.h"
#include "u386mon.h"
X
#ifdef SVR4
#else
extern struct var v;
unsigned stream_size[NCLASS+4];
ushort rbsize[NCLASS];
struct strstat strst;
#endif
X
#define _NDX_STREAMS	0
#define _NDX_QUEUES		1
#define _NDX_MESSAGES	2
#define	_NDX_NBLK		3
#define _NDX_NBLK4		4
#define _NDX_NBLK16		5
#define _NDX_NBLK64		6
#define _NDX_NBLK128	7
#define _NDX_NBLK256	8
#define _NDX_NBLK512	9
#define _NDX_NBLK1024	10
#define _NDX_NBLK2048	11
#define _NDX_NBLK4096	12
X
/*+----------------------------------------------------------------------------
X	init_stream()
-----------------------------------------------------------------------------*/
void
init_stream()
{
#ifdef SVR4
#else
X	int nmblock, i;
X
X	kread((caddr_t) rbsize, rbsizeaddr, sizeof(ushort) * NCLASS);
X	stream_size[_NDX_STREAMS]=v.v_nstream;
X	stream_size[_NDX_QUEUES]=v.v_nqueue;
X	kread((caddr_t) &nmblock, nmblockaddr, sizeof(int));
X	stream_size[_NDX_MESSAGES]=nmblock;
X	stream_size[_NDX_NBLK4]=v.v_nblk4;	
X	stream_size[_NDX_NBLK16]=v.v_nblk16;	
X	stream_size[_NDX_NBLK64]=v.v_nblk64;	
X	stream_size[_NDX_NBLK128]=v.v_nblk128;	
X	stream_size[_NDX_NBLK256]=v.v_nblk256;	
X	stream_size[_NDX_NBLK512]=v.v_nblk512;	
X	stream_size[_NDX_NBLK1024]=v.v_nblk1024;	
X	stream_size[_NDX_NBLK2048]=v.v_nblk2048;	
X	stream_size[_NDX_NBLK4096]=v.v_nblk4096;	
X	stream_size[_NDX_NBLK]=0;
X    for(i=_NDX_NBLK4; i<=_NDX_NBLK4096; i++)
X		stream_size[_NDX_NBLK]+=stream_size[i];
#endif
}
X
/*+----------------------------------------------------------------------------
X	draw_streamscale_literals(win, y, x);
X
00000000001111111111222222222233333333334444444444555555555566666666667777777777
01234567890123456789012345678901234567890123456789012345678901234567890123456789
Resource             Config Alloc Fail -- (% of resource used) -----------------
Streams              ###### ##### #### #########################################
Queues
Message blocks
Data blocks
Data block size ####
-----------------------------------------------------------------------------*/
X
void
draw_streamscale_literals(win, y, x)
WINDOW *win;
int y, x;
X
{
#ifdef SVR4
#else
X	static char *header = 
"Resource            Config Alloc  Fail -- (% of resource used) ";
X	int x2, i;
X
X	wmove(win, y, x);
X	use_cp(win, cpBANNER);
X	waddstr(win, header);
X	getyx(win,y,x2);
X	while (x2++ <= COLS)
X		waddch(win, (chtype)'-');
X	use_cp(win,cpLIT);
X	clear_area(win,getmaxy(win)-1,0,getmaxx(win));
X	mvwaddstr(win, y + 1, x, "Streams");
X	mvwaddstr(win, y + 2, x, "Queues");
X	mvwaddstr(win, y + 3, x, "Message blocks");
X	mvwaddstr(win, y + 4, x, "Data blocks");
X	for (i=0; i<NCLASS; i++)
X		mvwprintw(win, (y+i+5), x, "Data block size %4lu", rbsize[i]);
#endif
} 
X
/*+----------------------------------------------------------------------------
X	update_streamscale(win, y, x, width);
X
00000000001111111111222222222233333333334444444444555555555566666666667777777777
01234567890123456789012345678901234567890123456789012345678901234567890123456789
Conf  Alloc Fail  -- (% of resource used) -----------------
##### ##### ##### #########################################
-----------------------------------------------------------------------------*/
#define _STREAM_CO	0
#define _STREAM_AL	6
#define _STREAM_FA	12
#define _STREAM_SX	18
X
void
update_streamscale(win, y, x, width)
WINDOW *win;
int y, x;
int width;
X
{
#ifdef SVR4
#else
X	int percent_used, percent_max;
X	int i, itmp, max;
X	alcdat	*strdat;
X
X	kread((caddr_t)&strst, strstaddr, sizeof(struct strstat));
X	strdat=(alcdat *)&strst;
X	for (i=0; i<NCLASS+4; i++) {
X		percent_used=stream_size[i] ? (strdat->use*100/stream_size[i]) : 0;
X		percent_max=stream_size[i] ? (strdat->max*100/stream_size[i]) : 0;
X		use_cp(win, cpINFO);
X		mvwprintw(win, y+i, _STREAM_CO+x, "%5i", stream_size[i]);
X		mvwprintw(win, y+i, _STREAM_AL+x, "%5i", strdat->use);
X		if (strdat->fail)
X			use_cp(win, cpHIGH);
X		else
X			use_cp(win, cpINFO);
X		mvwprintw(win, y+i, _STREAM_FA+x, "%5i", strdat->fail);
X		wmove(win, y+i, _STREAM_SX+x);
X
X		if (percent_used < 70)
X			use_cp(win, cpLOW);
X		else if (percent_used < 90)
X			use_cp(win, cpMED);
X		else
X			use_cp(win, cpHIGH);
X
X		itmp=(width * percent_used) / 100;
X		max=(width * percent_max) / 100;
X		while (-1) {
X			itmp--;max--;
X			if (max<1) {
X				use_cp(win, cpHIGH);
X				waddch(win, (chtype)'M');
X				break;
X			}
X			if (itmp>-1)
X				waddch(win, (chtype)'-');
X			else
X				waddch(win, (chtype)' ');
X		}
X
X		wclrtoeol(win);
X		strdat++;
X	}
#endif
}
X
/* vi: set tabstop=4 shiftwidth=4: */
/* end of det_stream.c */
SHAR_EOF
chmod 0644 det_stream.c ||
echo 'restore of det_stream.c failed'
Wc_c="`wc -c < 'det_stream.c'`"
test 5717 -eq "$Wc_c" ||
	echo 'det_stream.c: original size 5717, current size' "$Wc_c"
rm -f _shar_wnt_.tmp
fi
# ============= det_table.c ==============
if test -f 'det_table.c' -a X"$1" != X"-c"; then
	echo 'x - skipping det_table.c (File already exists)'
	rm -f _shar_wnt_.tmp
else
> _shar_wnt_.tmp
echo 'x - extracting det_table.c (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'det_table.c' &&
/*+-------------------------------------------------------------------------
X	det_table.c - UNIX V/386 system monitor table usage detail
X	martin@hppcmart.grenoble.hp.com
X
00000000001111111111222222222233333333334444444444555555555566666666667777777777
01234567890123456789012345678901234567890123456789012345678901234567890123456789
Resource             Config Alloc Fail -- (% of resource used) -----------------
#################### ###### ##### #### ######################################### 
X  Defined functions:
files_in_use()
inodes_in_use()
update_table_line(win, y, x, width, num_item, max_item, conf_item, percent_item)
init_table()
draw_table_literals(win,y,x)
X
--------------------------------------------------------------------------*/
/*+:EDITS:*/
/*:08-01-1991-23:34-wht@n4hgf-release 2.40 source control point */
/*:05-15-1991-17:22-wht@n4hgf-2.3 patches for SVR31 from nba@sysware.dk */
/*:02-07-1991-13:30-martin@hppcmart-creation */
X
#define M_TERMINFO
X
#include <curses.h>
#ifdef NATIVE_PANELS
# include <panel.h>
#else
# include "libpanel.h"
#endif
#include <string.h>
#include <nlist.h>
#include <sys/types.h>
#include <sys/stat.h>
/*
#include <sys/ascii.h>
*/
#include <sys/var.h>
#undef NGROUPS_MAX
#undef NULL
#include <sys/param.h>
#include <sys/inode.h>
#include <sys/file.h>
#include <sys/fcntl.h>
#include <sys/flock.h>
#include <sys/immu.h>
#include <sys/region.h>
#include <sys/callo.h>
X
#include "nlsym.h"
#include "libkmem.h"
#include "libmem.h"
#include "libswap.h"
#include "libnlsym.h"
#include "u386mon.h"
X
extern struct var v;
struct file *fpbase;
struct inode *ipbase;
struct flckinfo flckinfo;
struct region *rgbase;
struct callo *callbase;
int max_files=0;
int max_inodes=0;
int max_locks=0;
int max_regions=0;
int max_callouts=0;
X
/*+-------------------------------------------------------------------------
X	files_in_use()
X
X	Returns the number of files in use or -1 if the free list
X	pointers were munged when read which happens every now and then.
--------------------------------------------------------------------------*/
static int
files_in_use()
{
X	struct file *fp, *fflist;
X	register int cnt=0;
X	unsigned int ndx;
X
#ifdef SVR4
X	return (-1);
#else
X	kread((caddr_t) fpbase, fileaddr, sizeof(struct file)*v.v_file);
X	kread((caddr_t) &fflist, ffreelistaddr, sizeof(struct file *));
X	fp=fpbase + (fflist - (struct file *)fileaddr);
X	while (1) {
X		cnt++;
X		if (fp->f_next == 0) break;
X		ndx=fp->f_next - (struct file *)fileaddr;
X		if ((ndx >= v.v_file) || (ndx < 0) || (cnt > v.v_file)) return(-1);
X		fp=fpbase + ndx;
X			
X	}
X	return(v.v_file-cnt);
#endif
}
X
/*+-------------------------------------------------------------------------
X	inodes_in_use()
X
X	Returns the number of inodes used or -1 if the free list
X	pointers were munged when read which happens every now and then.
--------------------------------------------------------------------------*/
X
static int
inodes_in_use()
{
X	struct inode *ip, *iflistend;
X	struct ifreelist iflist;
X	register int cnt=0;
X	int ndx;
X
#ifdef SVR4
X	return (-1);
#else
X	kread((caddr_t) ipbase, inodeaddr, sizeof(struct inode)*v.v_inode);
X	kread((caddr_t) &iflist, ifreelistaddr, sizeof(struct ifreelist));
X	ip=ipbase + (iflist.av_forw - (struct inode *)inodeaddr);
X	iflistend=ipbase + (iflist.av_back - (struct inode *)inodeaddr);
X	while (1) {
X		cnt++;
X		if (ip==iflistend) break;
X		ndx=ip->av_forw - (struct inode *)inodeaddr;
X		if ((ndx >= v.v_inode) || (ndx < 0) || (cnt > v.v_inode)) return(-1);
X		ip=ipbase + ndx;
X	}
X	return(v.v_inode-cnt);
#endif
}
X
/*+-------------------------------------------------------------------------
X	regions_in_use()
X
X	Returns the number of regions used or -1 if the free list
X	pointers were munged when read which happens every now and then.
--------------------------------------------------------------------------*/
X
static int
regions_in_use()
{
#ifdef SVR4
X	return (-1);
#else
X	struct region *rg, ractive;
X	register int cnt=0;
X	int ndx;
X
X	kread((caddr_t) rgbase, regionaddr, sizeof(struct region)*v.v_region);
X	kread((caddr_t) &ractive, ractiveaddr, sizeof(struct region));
X	rg=rgbase + (ractive.r_forw - (struct region *)regionaddr);
SHAR_EOF
true || echo 'restore of det_table.c failed'
fi
echo 'End of av386mon part 3'
echo 'File det_table.c is continued in part 4'
echo 4 > _shar_seq_.tmp
exit 0
-- 
Andreas Vogel                   Bahnhofstr. 13 / D-7300 Esslingen / Germany
				Voice:  +49-711/357613
				E-Mail: av@ssw.de
