xref: /dflybsd-src/usr.bin/systat/mode.c (revision 86d7f5d305c6adaa56ff4582ece9859d73106103)
1*86d7f5d3SJohn Marino /*
2*86d7f5d3SJohn Marino  * Copyright 1997 Massachusetts Institute of Technology
3*86d7f5d3SJohn Marino  *
4*86d7f5d3SJohn Marino  * Permission to use, copy, modify, and distribute this software and
5*86d7f5d3SJohn Marino  * its documentation for any purpose and without fee is hereby
6*86d7f5d3SJohn Marino  * granted, provided that both the above copyright notice and this
7*86d7f5d3SJohn Marino  * permission notice appear in all copies, that both the above
8*86d7f5d3SJohn Marino  * copyright notice and this permission notice appear in all
9*86d7f5d3SJohn Marino  * supporting documentation, and that the name of M.I.T. not be used
10*86d7f5d3SJohn Marino  * in advertising or publicity pertaining to distribution of the
11*86d7f5d3SJohn Marino  * software without specific, written prior permission.  M.I.T. makes
12*86d7f5d3SJohn Marino  * no representations about the suitability of this software for any
13*86d7f5d3SJohn Marino  * purpose.  It is provided "as is" without express or implied
14*86d7f5d3SJohn Marino  * warranty.
15*86d7f5d3SJohn Marino  *
16*86d7f5d3SJohn Marino  * THIS SOFTWARE IS PROVIDED BY M.I.T. ``AS IS''.  M.I.T. DISCLAIMS
17*86d7f5d3SJohn Marino  * ALL EXPRESS OR IMPLIED WARRANTIES WITH REGARD TO THIS SOFTWARE,
18*86d7f5d3SJohn Marino  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19*86d7f5d3SJohn Marino  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT
20*86d7f5d3SJohn Marino  * SHALL M.I.T. BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21*86d7f5d3SJohn Marino  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22*86d7f5d3SJohn Marino  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
23*86d7f5d3SJohn Marino  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24*86d7f5d3SJohn Marino  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
25*86d7f5d3SJohn Marino  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
26*86d7f5d3SJohn Marino  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27*86d7f5d3SJohn Marino  * SUCH DAMAGE.
28*86d7f5d3SJohn Marino  *
29*86d7f5d3SJohn Marino  * $FreeBSD: src/usr.bin/systat/mode.c,v 1.2 1999/08/28 01:06:03 peter Exp $
30*86d7f5d3SJohn Marino  * $DragonFly: src/usr.bin/systat/mode.c,v 1.3 2008/11/10 04:59:45 swildner Exp $
31*86d7f5d3SJohn Marino  */
32*86d7f5d3SJohn Marino 
33*86d7f5d3SJohn Marino /*
34*86d7f5d3SJohn Marino  * mode.c - mechanisms for dealing with SGI-style modal displays.
35*86d7f5d3SJohn Marino  *
36*86d7f5d3SJohn Marino  * There are four generally-understood useful modes for status displays
37*86d7f5d3SJohn Marino  * of the sort exemplified by the IRIX ``netstat -C'' and ``osview''
38*86d7f5d3SJohn Marino  * programs.  We try to follow their example, although the user interface
39*86d7f5d3SJohn Marino  * and terminology slightly differ.
40*86d7f5d3SJohn Marino  *
41*86d7f5d3SJohn Marino  * RATE - the default mode - displays the precise rate of change in
42*86d7f5d3SJohn Marino  * each statistic in units per second, regardless of the actual display
43*86d7f5d3SJohn Marino  * update interval.
44*86d7f5d3SJohn Marino  *
45*86d7f5d3SJohn Marino  * DELTA - displays the change in each statistic over the entire
46*86d7f5d3SJohn Marino  * display update interval (i.e., RATE * interval).
47*86d7f5d3SJohn Marino  *
48*86d7f5d3SJohn Marino  * SINCE - displays the total change in each statistic since the module
49*86d7f5d3SJohn Marino  * was last initialized or reset.
50*86d7f5d3SJohn Marino  *
51*86d7f5d3SJohn Marino  * ABSOLUTE - displays the current value of each statistic.
52*86d7f5d3SJohn Marino  *
53*86d7f5d3SJohn Marino  * In the SGI programs, these modes are selected by the single-character
54*86d7f5d3SJohn Marino  * commands D, W, N, and A.  In systat, they are the slightly-harder-to-type
55*86d7f5d3SJohn Marino  * ``mode delta'', etc.  The initial value for SINCE mode is initialized
56*86d7f5d3SJohn Marino  * when the module is first started and can be reset using the ``reset''
57*86d7f5d3SJohn Marino  * command (as opposed to the SGI way where changing modes implicitly
58*86d7f5d3SJohn Marino  * resets).  A ``mode'' command with no arguments displays the current
59*86d7f5d3SJohn Marino  * mode in the command line.
60*86d7f5d3SJohn Marino  */
61*86d7f5d3SJohn Marino 
62*86d7f5d3SJohn Marino #include <sys/types.h>
63*86d7f5d3SJohn Marino 
64*86d7f5d3SJohn Marino #include "systat.h"
65*86d7f5d3SJohn Marino #include "extern.h"
66*86d7f5d3SJohn Marino #include "mode.h"
67*86d7f5d3SJohn Marino 
68*86d7f5d3SJohn Marino enum mode currentmode = display_RATE;
69*86d7f5d3SJohn Marino 
70*86d7f5d3SJohn Marino static const char *const modes[] = { "rate", "delta", "since", "absolute" };
71*86d7f5d3SJohn Marino 
72*86d7f5d3SJohn Marino int
cmdmode(const char * cmd,char * args)73*86d7f5d3SJohn Marino cmdmode(const char *cmd, char *args)
74*86d7f5d3SJohn Marino {
75*86d7f5d3SJohn Marino 	if (prefix(cmd, "mode")) {
76*86d7f5d3SJohn Marino 		if (args[0] == '\0') {
77*86d7f5d3SJohn Marino 			move(CMDLINE, 0);
78*86d7f5d3SJohn Marino 			clrtoeol();
79*86d7f5d3SJohn Marino 			printw("%s", modes[currentmode]);
80*86d7f5d3SJohn Marino 		} else if (prefix(args, "rate")) {
81*86d7f5d3SJohn Marino 			currentmode = display_RATE;
82*86d7f5d3SJohn Marino 		} else if (prefix(args, "delta")) {
83*86d7f5d3SJohn Marino 			currentmode = display_DELTA;
84*86d7f5d3SJohn Marino 		} else if (prefix(args, "since")) {
85*86d7f5d3SJohn Marino 			currentmode = display_SINCE;
86*86d7f5d3SJohn Marino 		} else if (prefix(args, "absolute")) {
87*86d7f5d3SJohn Marino 			currentmode = display_ABS;
88*86d7f5d3SJohn Marino 		} else {
89*86d7f5d3SJohn Marino 			printw("unknown mode `%s'", args);
90*86d7f5d3SJohn Marino 		}
91*86d7f5d3SJohn Marino 		return 1;
92*86d7f5d3SJohn Marino 	}
93*86d7f5d3SJohn Marino 	if(prefix(cmd, "reset")) {
94*86d7f5d3SJohn Marino 		curcmd->c_reset();
95*86d7f5d3SJohn Marino 		return 1;
96*86d7f5d3SJohn Marino 	}
97*86d7f5d3SJohn Marino 	return 0;
98*86d7f5d3SJohn Marino }
99