129759Swollman/*
229759Swollman * Copyright 1997 Massachusetts Institute of Technology
329759Swollman *
429759Swollman * Permission to use, copy, modify, and distribute this software and
529759Swollman * its documentation for any purpose and without fee is hereby
629759Swollman * granted, provided that both the above copyright notice and this
729759Swollman * permission notice appear in all copies, that both the above
829759Swollman * copyright notice and this permission notice appear in all
929759Swollman * supporting documentation, and that the name of M.I.T. not be used
1029759Swollman * in advertising or publicity pertaining to distribution of the
1129759Swollman * software without specific, written prior permission.  M.I.T. makes
1229759Swollman * no representations about the suitability of this software for any
1329759Swollman * purpose.  It is provided "as is" without express or implied
1429759Swollman * warranty.
15231279Sed *
1629759Swollman * THIS SOFTWARE IS PROVIDED BY M.I.T. ``AS IS''.  M.I.T. DISCLAIMS
1729759Swollman * ALL EXPRESS OR IMPLIED WARRANTIES WITH REGARD TO THIS SOFTWARE,
1829759Swollman * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
1929759Swollman * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT
2029759Swollman * SHALL M.I.T. BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
2129759Swollman * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
2229759Swollman * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
2329759Swollman * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
2429759Swollman * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
2529759Swollman * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
2629759Swollman * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2729759Swollman * SUCH DAMAGE.
2829759Swollman */
2929759Swollman
3029759Swollman/*
3129759Swollman * mode.c - mechanisms for dealing with SGI-style modal displays.
3229759Swollman *
3329759Swollman * There are four generally-understood useful modes for status displays
3429759Swollman * of the sort exemplified by the IRIX ``netstat -C'' and ``osview''
3529759Swollman * programs.  We try to follow their example, although the user interface
3629759Swollman * and terminology slightly differ.
3729759Swollman *
3829759Swollman * RATE - the default mode - displays the precise rate of change in
3929759Swollman * each statistic in units per second, regardless of the actual display
4029759Swollman * update interval.
4129759Swollman *
4229759Swollman * DELTA - displays the change in each statistic over the entire
4329759Swollman * display update interval (i.e., RATE * interval).
4429759Swollman *
4529759Swollman * SINCE - displays the total change in each statistic since the module
4629759Swollman * was last initialized or reset.
4729759Swollman *
4829759Swollman * ABSOLUTE - displays the current value of each statistic.
4929759Swollman *
5029759Swollman * In the SGI programs, these modes are selected by the single-character
5129759Swollman * commands D, W, N, and A.  In systat, they are the slightly-harder-to-type
5229759Swollman * ``mode delta'', etc.  The initial value for SINCE mode is initialized
5329759Swollman * when the module is first started and can be reset using the ``reset''
5429759Swollman * command (as opposed to the SGI way where changing modes implicitly
5529759Swollman * resets).  A ``mode'' command with no arguments displays the current
5629759Swollman * mode in the command line.
5729759Swollman */
5829759Swollman
5987715Smarkm#include <sys/cdefs.h>
6087715Smarkm
6187715Smarkm__FBSDID("$FreeBSD$");
6287715Smarkm
63200462Sdelphij#include <sys/types.h>
64200462Sdelphij
6529759Swollman#include "systat.h"
6629759Swollman#include "extern.h"
6729759Swollman#include "mode.h"
6829759Swollman
6929759Swollmanenum mode currentmode = display_RATE;
7029759Swollman
7129759Swollmanstatic const char *const modes[] = { "rate", "delta", "since", "absolute" };
7229759Swollman
7329759Swollmanint
7487715Smarkmcmdmode(const char *cmd, const char *args)
7529759Swollman{
7629759Swollman	if (prefix(cmd, "mode")) {
7729759Swollman		if (args[0] == '\0') {
7829759Swollman			move(CMDLINE, 0);
7929759Swollman			clrtoeol();
8029759Swollman			printw("%s", modes[currentmode]);
8129759Swollman		} else if (prefix(args, "rate")) {
8229759Swollman			currentmode = display_RATE;
8329759Swollman		} else if (prefix(args, "delta")) {
8429759Swollman			currentmode = display_DELTA;
8529759Swollman		} else if (prefix(args, "since")) {
8629759Swollman			currentmode = display_SINCE;
8729759Swollman		} else if (prefix(args, "absolute")) {
8829759Swollman			currentmode = display_ABS;
8929759Swollman		} else {
9029759Swollman			printw("unknown mode `%s'", args);
9129759Swollman		}
9229759Swollman		return 1;
9329759Swollman	}
9429759Swollman	if(prefix(cmd, "reset")) {
9529759Swollman		curcmd->c_reset();
9629759Swollman		return 1;
9729759Swollman	}
9829759Swollman	return 0;
9929759Swollman}
100