⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 screen.c

📁 <B>Digital的Unix操作系统VAX 4.2源码</B>
💻 C
📖 第 1 页 / 共 2 页
字号:
#ifndef lintstatic char *sccsid = "@(#)screen.c	4.2	(ULTRIX)	1/25/91";#endif/* Based on: * RCSid = "$Header: /sparky/a/davy/system/nfswatch/RCS/screen.c,v 3.0 91/01/23 08:23:23 davy Exp $"; *//* * screen.c - routines for updating the screen. * * David A. Curry				Jeffrey C. Mogul * SRI International				Digital Equipment Corporation * 333 Ravenswood Avenue			Western Research Laboratory * Menlo Park, CA 94025				100 Hamilton Avenue * davy@erg.sri.com				Palo Alto, CA 94301 *						mogul@decwrl.dec.com * * $Log:	screen.c,v $ * Revision 3.0  91/01/23  08:23:23  davy * NFSWATCH Version 3.0. *  * Revision 1.4  91/01/17  10:13:30  davy * New features from Jeff Mogul. *  * Revision 1.7  91/01/16  15:49:41  mogul * Make sure snapshot captures up-to-date screen. *  * Revision 1.6  91/01/07  14:24:05  mogul * fixed a few little bugs *  * Revision 1.5  91/01/07  14:10:43  mogul * Added scrolling * Added help screen *  * Revision 1.4  91/01/04  14:13:29  mogul * Support for client counters * disable screen update during database upheaval * indicate how many files/file systems/procedures/clients not shown *  * Revision 1.3  91/01/03  17:42:16  mogul * Support for per-procedure counters *  * Revision 1.2  90/08/17  15:47:48  davy * NFSWATCH Version 2.0. *  * Revision 1.1  88/11/29  11:21:03  davy * NFSWATCH Release 1.0 *  */#include <sys/param.h>#include <sys/time.h>#include <curses.h>#include <stdio.h>#include <signal.h>#include "nfswatch.h"#include "externs.h"#include "screen.h"/* * Screen text items which are always displayed. */static struct scrtxt scrtxts[] = {	SCR_HOST_X,	SCR_HOST_Y,	dsthost,	SCR_ELAPS_X0,	SCR_ELAPS_Y,	"Elapsed time:",	SCR_ELAPS_X,	SCR_ELAPS_Y,	"00:00:00",	SCR_PKTINT_X0,	SCR_PKTINT_Y,	"Interval packets:",	SCR_PKTTOT_X0,	SCR_PKTTOT_Y,	"Total packets:",	SCR_PKTHDR_X,	SCR_PKTHDR_Y,	"int   pct   total",	SCR_PKTHDR_X+SCR_MIDDLE,	SCR_PKTHDR_Y,					"int   pct   total",	-1,		-1,		NULL};/* * Screen text items displayed when showing file systems * (showwhich == SHOWFILESYSTEM). */static struct scrtxt fstxts[] = {	SCR_NFSHDR_X,	SCR_NFSHDR_Y,	"File Sys        int   pct   total",	SCR_NFSHDR_X+SCR_MIDDLE,	SCR_NFSHDR_Y,					"File Sys        int   pct   total",	-1,		-1,		NULL};/* * Screen text items displayed when showing individual files * (showwhich == SHOWINDVFILES). */static struct scrtxt fitxts[] = {	SCR_NFSHDR_X,	SCR_NFSHDR_Y,	"File            int   pct   total",	SCR_NFSHDR_X+SCR_MIDDLE,	SCR_NFSHDR_Y,					"File            int   pct   total",	-1,		-1,		NULL};/* * Screen text items displayed when showing individual procedures * (showwhich == SHOWNFSPROCS). */static struct scrtxt prtxts[] = {	0,		SCR_NFSHDR_Y,		" Procedure           int   pct   total",	SCR_MIDDLE,	SCR_NFSHDR_Y,		" Procedure           int   pct   total",	-1,		-1,		NULL};/* * Screen text items displayed when showing individual clients * (showwhich == SHOWCLIENTS). */static struct scrtxt cltxts[] = {	0,		SCR_NFSHDR_Y,		"Client host          int   pct   total",	SCR_MIDDLE,	SCR_NFSHDR_Y,		"Client host          int   pct   total",	-1,		-1,		NULL};/* * Screen text items for help page (showwhich == SHOWHELP). */#define	SCR_HELPHDR_Y (SCR_NFSHDR_Y - 1)static struct scrtxt helptxts[] = {	2,		SCR_HELPHDR_Y+0, "^L\tRedraw screen",	3,		SCR_HELPHDR_Y+1, "c\tDisplay NFS client hosts",	3,		SCR_HELPHDR_Y+2, "f\tDisplay file systems",	3,		SCR_HELPHDR_Y+3, "l\tToggle logging",	3,		SCR_HELPHDR_Y+4, "p\tDisplay NFS procedures",	3,		SCR_HELPHDR_Y+5, "q\tQuit",	3,		SCR_HELPHDR_Y+6, "s\tWrite snapshot",	3,		SCR_HELPHDR_Y+7, "u\tToggle sort by % usage",	SCR_MIDDLE+3,	SCR_HELPHDR_Y+0, ">\tIncrease cycle time by one sec",	SCR_MIDDLE+3,	SCR_HELPHDR_Y+1, "<\tDecrease cycle time by one sec",	SCR_MIDDLE+3,	SCR_HELPHDR_Y+2, "+\tIncrease cycle time by 10 secs",	SCR_MIDDLE+3,	SCR_HELPHDR_Y+3, "-\tDecrease cycle time by 10 secs",	SCR_MIDDLE+3,	SCR_HELPHDR_Y+4, "=\tReset cycle time to 10 secs",	SCR_MIDDLE+3,	SCR_HELPHDR_Y+5, "]\tScroll forward",	SCR_MIDDLE+3,	SCR_HELPHDR_Y+6, "[\tScroll back",	SCR_MIDDLE,	SCR_HELPHDR_Y+7, "*space bar resumes display*",	SCR_MIDDLE - 6,	SCR_HELPHDR_Y+8, "--COMMANDS--",	-1,		-1,		NULL};static int prev_showwhich = 0;	/* used for resuming after help *//* * scrolling offsets, one for each display type, in terms of displayed * items (i.e., lines skipped * 2) */static int scroll_off[SHOW_MAXCODE+1];/* * This array tells the scrolling mechanism how far a display can be scrolled; *	NULL entries are not scrollable. */static int maxnfsproc = MAXNFSPROC;static int *scroll_limit[SHOW_MAXCODE+1] =	{NULL,	&nfilecounters, &nnfscounters, &maxnfsproc, &nclientcounters, NULL};/* * setup_screen - initialize the display screen. */voidsetup_screen(device)char *device;{	int len;	char *tstr;	char *ctime();	register int i;	char buf[BUFSIZ];	struct timeval tv;	register struct scrtxt *st;	/*	 * Initialize the screen.	 */	(void) initscr();	screen_inited = 1;	/*	 * Turn echo off, cbreak on.	 */	(void) noecho();#ifdef crmode	(void) crmode();#else	(void) cbreak();#endif /* crmode */	/*	 * Clear the screen.	 */	(void) clear();	/*	 * Get the time of day. 	 */	(void) gettimeofday(&tv, (struct timeval *) 0);	tstr = ctime(&tv.tv_sec);	(void) mvprintw(SCR_DATE_Y, SCR_DATE_X, "%.24s", tstr);	/*	 * Now draw the various strings on the screen.	 */	for (st = scrtxts; st->s_text != NULL; st++)		(void) mvprintw(st->s_y, st->s_x, "%s", st->s_text);	if (allintf)		(void) sprintf(buf, "Monitoring packets from all interfaces");	else		(void) sprintf(buf, "Monitoring packets from interface %s",			       device);	len = strlen(buf);	(void) mvprintw(SCR_IF_Y, SCR_MIDDLE - (len/2), buf);	(void) mvprintw(SCR_PROMPT_Y, SCR_PROMPT_X0, prompt);}/* * label_screen - put all packet counter labels on screen. */voidlabel_screen(){	register int i;	register struct scrtxt *st;	register int soff = scroll_off[showwhich];	/*	 * Display packet counter labels.	 */	for (i = 0; i < PKT_NCOUNTERS; i++) {		(void) mvprintw(pkt_counters[i].pc_namey,			pkt_counters[i].pc_namex, "%.*s",			SCR_PKTLEN, pkt_counters[i].pc_name);	}	/*	 * Clear NFS packet counter lines, since we may be	 * changing them.	 */	for (i = SCR_NFSHDR_Y; i < (LINES - 1); i++) {		(void) move(i, 0);		(void) clrtoeol();	}	/*	 * Display the labels for the NFS packet counter lines.	 */	if (showwhich == SHOWFILESYSTEM) {		for (st = fstxts; st->s_text != NULL; st++)			(void) mvprintw(st->s_y, st->s_x, "%s", st->s_text);		for (i = soff;			(i < nnfscounters) && ((i - soff) < NFSLINES); i++) {			(void) mvprintw(nfs_counters[i - soff].nc_namey,				nfs_counters[i - soff].nc_namex, "%.*s",				SCR_NFSLEN, nfs_counters[i].nc_name);		}	}	else if (showwhich == SHOWNFSPROCS) {		for (st = prtxts; st->s_text != NULL; st++)			(void) mvprintw(st->s_y, st->s_x, "%s", st->s_text);		for (i = soff;			(i < MAXNFSPROC) && ((i - soff) < NFSLINES); i++) {			(void) mvprintw(prc_counters[i - soff].pr_namey,					prc_counters[i - soff].pr_namex,					"%.*s", SCR_NFSLEN,					prc_counters[i].pr_name);		}	}	else if (showwhich == SHOWCLIENTS) {		for (st = cltxts; st->s_text != NULL; st++)			(void) mvprintw(st->s_y, st->s_x, "%s", st->s_text);		for (i = soff; 		      (i < nclientcounters) && ((i - soff) < NFSLINES); i++) {			(void) mvprintw(clnt_counters[i - soff].cl_namey,					clnt_counters[i - soff].cl_namex,					"%.*s", SCR_NFSLEN,					clnt_counters[i].cl_name);		}	}	else if (showwhich == SHOWHELP) {		/* We "stole" one line so we must clear it */		(void) move(SCR_HELPHDR_Y, 0);		(void) clrtoeol();		for (st = helptxts; st->s_text != NULL; st++)			(void) mvprintw(st->s_y, st->s_x, "%s", st->s_text);	}	else {		for (st = fitxts; st->s_text != NULL; st++)			(void) mvprintw(st->s_y, st->s_x, "%s", st->s_text);		for (i = soff;			(i < nfilecounters) && ((i - soff) < NFSLINES); i++) {			(void) mvprintw(fil_counters[i - soff].fc_namey,				fil_counters[i - soff].fc_namex, "%.*s",				SCR_NFSLEN, fil_counters[i].fc_name);		}	}}/* * update_screen - update the screen with new information. */voidupdate_screen(){	char *tstr;	char *ctime();	float percent;	struct timeval tv;	register int i, nfstotal;	register int soff = scroll_off[showwhich];	(void) gettimeofday(&tv, (struct timezone *) 0);	(void) mvprintw(SCR_DATE_Y, SCR_DATE_X, "%.24s", ctime(&tv.tv_sec));	tv.tv_sec -= starttime.tv_sec;	tstr = prtime(tv.tv_sec);	/*	 * Print the headers.	 */	(void) mvprintw(SCR_ELAPS_Y, SCR_ELAPS_X, "%.8s", tstr);	(void) mvprintw(SCR_PKTINT_Y, SCR_PKTINT_X,		"%8d (network)   %8d (to host)   %8d (dropped)",		int_pkt_total, int_dst_pkt_total, int_pkt_drops);	(void) mvprintw(SCR_PKTTOT_Y, SCR_PKTTOT_X,		"%8d (network)   %8d (to host)   %8d (dropped)",		pkt_total, dst_pkt_total, pkt_drops);	/*	 * Print the packet counters.  Percentage is calculated as	 * this interval counter over total packets this interval.	 */	for (i = 0; i < PKT_NCOUNTERS; i++) {		if (int_dst_pkt_total) {			percent = ((float) pkt_counters[i].pc_interval /				  (float) int_dst_pkt_total) * 100.0;		}		else {			percent = 0.0;		}		(void) mvprintw(pkt_counters[i].pc_inty,			pkt_counters[i].pc_intx, "%5d",			pkt_counters[i].pc_interval);		(void) mvprintw(pkt_counters[i].pc_pcty,			pkt_counters[i].pc_pctx, "%3.0f%%",			percent);		(void) mvprintw(pkt_counters[i].pc_toty,			pkt_counters[i].pc_totx, "%8d",			pkt_counters[i].pc_total);	}	/*	 * Calculate the total number of NFS packets this	 * interval.	 */	nfstotal = pkt_counters[PKT_NFSWRITE].pc_interval +		   pkt_counters[PKT_NFSREAD].pc_interval;	if (showwhich == SHOWFILESYSTEM) {		/*		 * Print the NFS counters.  Percentage is calculated as		 * packets this interval over total NFS packets this		 * interval.		 */		HowMany("file systems", nnfscounters);		for (i = soff;			(i < nnfscounters) && ((i - soff) < NFSLINES); i++) {			if (nfstotal) {			    percent = ((float) nfs_counters[i].nc_interval /					  (float) nfstotal) * 100.0;			}			else {				percent = 0.0;			}			(void) mvprintw(nfs_counters[i - soff].nc_inty,				nfs_counters[i - soff].nc_intx, "%5d",				nfs_counters[i].nc_interval);			(void) mvprintw(nfs_counters[i - soff].nc_pcty,				nfs_counters[i - soff].nc_pctx, "%3.0f%%",				percent);			(void) mvprintw(nfs_counters[i - soff].nc_toty,				nfs_counters[i - soff].nc_totx, "%8d",				nfs_counters[i].nc_total);		}	}	else if (showwhich == SHOWNFSPROCS) {		long tot_count;		tot_count = 0;		/* Sum up all over all the procedures  */		for (i = 0; i < MAXNFSPROC; i++) {			tot_count += prc_counters[i].pr_interval;		}		HowMany("NFS Procedures", MAXNFSPROC);		for (i = soff;			(i < MAXNFSPROC) && ((i - soff) < NFSLINES); i++) {		    if (tot_count)			percent = (((float) prc_counters[i].pr_interval)					 / ((float)tot_count)) * 100.0;		    else			percent = 0.0;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -