103e00a72SGarrett Wollman /* 203e00a72SGarrett Wollman * Copyright 1997 Massachusetts Institute of Technology 303e00a72SGarrett Wollman * 403e00a72SGarrett Wollman * Permission to use, copy, modify, and distribute this software and 503e00a72SGarrett Wollman * its documentation for any purpose and without fee is hereby 603e00a72SGarrett Wollman * granted, provided that both the above copyright notice and this 703e00a72SGarrett Wollman * permission notice appear in all copies, that both the above 803e00a72SGarrett Wollman * copyright notice and this permission notice appear in all 903e00a72SGarrett Wollman * supporting documentation, and that the name of M.I.T. not be used 1003e00a72SGarrett Wollman * in advertising or publicity pertaining to distribution of the 1103e00a72SGarrett Wollman * software without specific, written prior permission. M.I.T. makes 1203e00a72SGarrett Wollman * no representations about the suitability of this software for any 1303e00a72SGarrett Wollman * purpose. It is provided "as is" without express or implied 1403e00a72SGarrett Wollman * warranty. 1503e00a72SGarrett Wollman * 1603e00a72SGarrett Wollman * THIS SOFTWARE IS PROVIDED BY M.I.T. ``AS IS''. M.I.T. DISCLAIMS 1703e00a72SGarrett Wollman * ALL EXPRESS OR IMPLIED WARRANTIES WITH REGARD TO THIS SOFTWARE, 1803e00a72SGarrett Wollman * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 1903e00a72SGarrett Wollman * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT 2003e00a72SGarrett Wollman * SHALL M.I.T. BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 2103e00a72SGarrett Wollman * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 2203e00a72SGarrett Wollman * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 2303e00a72SGarrett Wollman * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 2403e00a72SGarrett Wollman * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 2503e00a72SGarrett Wollman * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 2603e00a72SGarrett Wollman * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2703e00a72SGarrett Wollman * SUCH DAMAGE. 2803e00a72SGarrett Wollman */ 2903e00a72SGarrett Wollman 3003e00a72SGarrett Wollman /* 3103e00a72SGarrett Wollman * mode.c - mechanisms for dealing with SGI-style modal displays. 3203e00a72SGarrett Wollman * 3303e00a72SGarrett Wollman * There are four generally-understood useful modes for status displays 3403e00a72SGarrett Wollman * of the sort exemplified by the IRIX ``netstat -C'' and ``osview'' 3503e00a72SGarrett Wollman * programs. We try to follow their example, although the user interface 3603e00a72SGarrett Wollman * and terminology slightly differ. 3703e00a72SGarrett Wollman * 3803e00a72SGarrett Wollman * RATE - the default mode - displays the precise rate of change in 3903e00a72SGarrett Wollman * each statistic in units per second, regardless of the actual display 4003e00a72SGarrett Wollman * update interval. 4103e00a72SGarrett Wollman * 4203e00a72SGarrett Wollman * DELTA - displays the change in each statistic over the entire 4303e00a72SGarrett Wollman * display update interval (i.e., RATE * interval). 4403e00a72SGarrett Wollman * 4503e00a72SGarrett Wollman * SINCE - displays the total change in each statistic since the module 4603e00a72SGarrett Wollman * was last initialized or reset. 4703e00a72SGarrett Wollman * 4803e00a72SGarrett Wollman * ABSOLUTE - displays the current value of each statistic. 4903e00a72SGarrett Wollman * 5003e00a72SGarrett Wollman * In the SGI programs, these modes are selected by the single-character 5103e00a72SGarrett Wollman * commands D, W, N, and A. In systat, they are the slightly-harder-to-type 5203e00a72SGarrett Wollman * ``mode delta'', etc. The initial value for SINCE mode is initialized 5303e00a72SGarrett Wollman * when the module is first started and can be reset using the ``reset'' 5403e00a72SGarrett Wollman * command (as opposed to the SGI way where changing modes implicitly 5503e00a72SGarrett Wollman * resets). A ``mode'' command with no arguments displays the current 5603e00a72SGarrett Wollman * mode in the command line. 5703e00a72SGarrett Wollman */ 5803e00a72SGarrett Wollman 599ff712b0SMark Murray #include <sys/cdefs.h> 609ff712b0SMark Murray 619ff712b0SMark Murray __FBSDID("$FreeBSD$"); 629ff712b0SMark Murray 6303e00a72SGarrett Wollman #include <sys/types.h> 6403e00a72SGarrett Wollman 6503e00a72SGarrett Wollman #include "systat.h" 6603e00a72SGarrett Wollman #include "extern.h" 6703e00a72SGarrett Wollman #include "mode.h" 6803e00a72SGarrett Wollman 6903e00a72SGarrett Wollman enum mode currentmode = display_RATE; 7003e00a72SGarrett Wollman 7103e00a72SGarrett Wollman static const char *const modes[] = { "rate", "delta", "since", "absolute" }; 7203e00a72SGarrett Wollman 7303e00a72SGarrett Wollman int 749ff712b0SMark Murray cmdmode(const char *cmd, const char *args) 7503e00a72SGarrett Wollman { 7603e00a72SGarrett Wollman if (prefix(cmd, "mode")) { 7703e00a72SGarrett Wollman if (args[0] == '\0') { 7803e00a72SGarrett Wollman move(CMDLINE, 0); 7903e00a72SGarrett Wollman clrtoeol(); 8003e00a72SGarrett Wollman printw("%s", modes[currentmode]); 8103e00a72SGarrett Wollman } else if (prefix(args, "rate")) { 8203e00a72SGarrett Wollman currentmode = display_RATE; 8303e00a72SGarrett Wollman } else if (prefix(args, "delta")) { 8403e00a72SGarrett Wollman currentmode = display_DELTA; 8503e00a72SGarrett Wollman } else if (prefix(args, "since")) { 8603e00a72SGarrett Wollman currentmode = display_SINCE; 8703e00a72SGarrett Wollman } else if (prefix(args, "absolute")) { 8803e00a72SGarrett Wollman currentmode = display_ABS; 8903e00a72SGarrett Wollman } else { 9003e00a72SGarrett Wollman printw("unknown mode `%s'", args); 9103e00a72SGarrett Wollman } 9203e00a72SGarrett Wollman return 1; 9303e00a72SGarrett Wollman } 9403e00a72SGarrett Wollman if(prefix(cmd, "reset")) { 9503e00a72SGarrett Wollman curcmd->c_reset(); 9603e00a72SGarrett Wollman return 1; 9703e00a72SGarrett Wollman } 9803e00a72SGarrett Wollman return 0; 9903e00a72SGarrett Wollman } 100