1251875Speter/* 2251875Speter * Copyright 1997 Massachusetts Institute of Technology 3251875Speter * 4251875Speter * Permission to use, copy, modify, and distribute this software and 5251875Speter * its documentation for any purpose and without fee is hereby 6251875Speter * granted, provided that both the above copyright notice and this 7251875Speter * permission notice appear in all copies, that both the above 8251875Speter * copyright notice and this permission notice appear in all 9251875Speter * supporting documentation, and that the name of M.I.T. not be used 10251875Speter * in advertising or publicity pertaining to distribution of the 11251875Speter * software without specific, written prior permission. M.I.T. makes 12251875Speter * no representations about the suitability of this software for any 13251875Speter * purpose. It is provided "as is" without express or implied 14251875Speter * warranty. 15251875Speter * 16251875Speter * THIS SOFTWARE IS PROVIDED BY M.I.T. ``AS IS''. M.I.T. DISCLAIMS 17251875Speter * ALL EXPRESS OR IMPLIED WARRANTIES WITH REGARD TO THIS SOFTWARE, 18251875Speter * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 19251875Speter * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT 20251875Speter * SHALL M.I.T. BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 21251875Speter * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22251875Speter * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 23251875Speter * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24251875Speter * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 25251875Speter * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 26251875Speter * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27251875Speter * SUCH DAMAGE. 28251875Speter */ 29251875Speter 30251875Speter/* 31251875Speter * mode.c - mechanisms for dealing with SGI-style modal displays. 32251875Speter * 33251875Speter * There are four generally-understood useful modes for status displays 34251875Speter * of the sort exemplified by the IRIX ``netstat -C'' and ``osview'' 35251875Speter * programs. We try to follow their example, although the user interface 36251875Speter * and terminology slightly differ. 37251875Speter * 38251875Speter * RATE - the default mode - displays the precise rate of change in 39251875Speter * each statistic in units per second, regardless of the actual display 40251875Speter * update interval. 41251875Speter * 42251875Speter * DELTA - displays the change in each statistic over the entire 43251875Speter * display update interval (i.e., RATE * interval). 44251875Speter * 45251875Speter * SINCE - displays the total change in each statistic since the module 46251875Speter * was last initialized or reset. 47251875Speter * 48251875Speter * ABSOLUTE - displays the current value of each statistic. 49251875Speter * 50251875Speter * In the SGI programs, these modes are selected by the single-character 51251875Speter * commands D, W, N, and A. In systat, they are the slightly-harder-to-type 52251875Speter * ``mode delta'', etc. The initial value for SINCE mode is initialized 53251875Speter * when the module is first started and can be reset using the ``reset'' 54251875Speter * command (as opposed to the SGI way where changing modes implicitly 55251875Speter * resets). A ``mode'' command with no arguments displays the current 56251875Speter * mode in the command line. 57251875Speter */ 58251875Speter 59251875Speter#include <sys/cdefs.h> 60251875Speter 61251875Speter__FBSDID("$FreeBSD$"); 62251875Speter 63251875Speter#include <sys/types.h> 64251875Speter 65251875Speter#include "systat.h" 66251875Speter#include "extern.h" 67251875Speter#include "mode.h" 68251875Speter 69251875Speterenum mode currentmode = display_RATE; 70251875Speter 71251875Speterstatic const char *const modes[] = { "rate", "delta", "since", "absolute" }; 72251875Speter 73251875Speterint 74251875Spetercmdmode(const char *cmd, const char *args) 75251875Speter{ 76251875Speter if (prefix(cmd, "mode")) { 77251875Speter if (args[0] == '\0') { 78251875Speter move(CMDLINE, 0); 79251875Speter clrtoeol(); 80251875Speter printw("%s", modes[currentmode]); 81251875Speter } else if (prefix(args, "rate")) { 82 currentmode = display_RATE; 83 } else if (prefix(args, "delta")) { 84 currentmode = display_DELTA; 85 } else if (prefix(args, "since")) { 86 currentmode = display_SINCE; 87 } else if (prefix(args, "absolute")) { 88 currentmode = display_ABS; 89 } else { 90 printw("unknown mode `%s'", args); 91 } 92 return 1; 93 } 94 if(prefix(cmd, "reset")) { 95 curcmd->c_reset(); 96 return 1; 97 } 98 return 0; 99} 100