1*6f3aa0fcSscole /* $NetBSD: ifcmds.c,v 1.2 2016/08/02 17:53:46 scole Exp $ */
2*6f3aa0fcSscole
3bd7662dcSscole /*
4bd7662dcSscole * Copyright (c) 2003, Trent Nelson, <trent@arpa.com>.
5bd7662dcSscole * All rights reserved.
6bd7662dcSscole *
7bd7662dcSscole * Redistribution and use in source and binary forms, with or without
8bd7662dcSscole * modification, are permitted provided that the following conditions
9bd7662dcSscole * are met:
10bd7662dcSscole * 1. Redistributions of source code must retain the above copyright
11bd7662dcSscole * notice, this list of conditions and the following disclaimer.
12bd7662dcSscole * 2. Redistributions in binary form must reproduce the above copyright
13bd7662dcSscole * notice, this list of conditions and the following disclaimer in the
14bd7662dcSscole * documentation and/or other materials provided with the distribution.
15bd7662dcSscole * 3. The name of the author may not be used to endorse or promote products
16bd7662dcSscole * derived from this software without specific prior written permission.
17bd7662dcSscole *
18bd7662dcSscole * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19bd7662dcSscole * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20bd7662dcSscole * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21bd7662dcSscole * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
22bd7662dcSscole * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23bd7662dcSscole * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24bd7662dcSscole * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25bd7662dcSscole * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26bd7662dcSscole * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27bd7662dcSscole * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28bd7662dcSscole * SUCH DAMAGE.
29bd7662dcSscole *
30bd7662dcSscole * $FreeBSD: releng/10.1/usr.bin/systat/ifcmds.c 247037 2013-02-20 14:19:09Z melifaro $
31bd7662dcSscole */
32bd7662dcSscole
33bd7662dcSscole #include <sys/cdefs.h>
34bd7662dcSscole #ifndef lint
35*6f3aa0fcSscole __RCSID("$NetBSD: ifcmds.c,v 1.2 2016/08/02 17:53:46 scole Exp $");
36bd7662dcSscole #endif /* not lint */
37bd7662dcSscole
38bd7662dcSscole #include <sys/types.h>
39bd7662dcSscole
40bd7662dcSscole #include <stdlib.h>
41bd7662dcSscole #include <string.h>
42bd7662dcSscole
43bd7662dcSscole #include "systat.h"
44bd7662dcSscole #include "extern.h"
45bd7662dcSscole #include "convtbl.h"
46bd7662dcSscole
47bd7662dcSscole
48bd7662dcSscole int curscale = SC_AUTO;
49bd7662dcSscole char *matchline = NULL;
50bd7662dcSscole int showpps = 0;
51bd7662dcSscole int needsort = 0;
52bd7662dcSscole
53bd7662dcSscole int
ifcmd(const char * cmd,const char * args)54bd7662dcSscole ifcmd(const char *cmd, const char *args)
55bd7662dcSscole {
56bd7662dcSscole int scale;
57bd7662dcSscole
58bd7662dcSscole if (prefix(cmd, "scale")) {
59bd7662dcSscole if ((scale = get_scale(args)) != -1)
60bd7662dcSscole curscale = scale;
61bd7662dcSscole else {
62bd7662dcSscole move(CMDLINE, 0);
63bd7662dcSscole clrtoeol();
64bd7662dcSscole addstr("what scale? ");
65bd7662dcSscole addstr(get_helplist());
66bd7662dcSscole }
67bd7662dcSscole } else if (prefix(cmd, "match")) {
68bd7662dcSscole if (args != NULL && *args != '\0' && memcmp(args, "*", 2) != 0) {
69bd7662dcSscole /* We got a valid match line */
70bd7662dcSscole if (matchline != NULL)
71bd7662dcSscole free(matchline);
72bd7662dcSscole needsort = 1;
73bd7662dcSscole matchline = strdup(args);
74bd7662dcSscole } else {
75bd7662dcSscole /* Empty or * pattern, turn filtering off */
76bd7662dcSscole if (matchline != NULL)
77bd7662dcSscole free(matchline);
78bd7662dcSscole needsort = 1;
79bd7662dcSscole matchline = NULL;
80bd7662dcSscole }
81bd7662dcSscole } else if (prefix(cmd, "pps"))
82bd7662dcSscole showpps = !showpps;
83bd7662dcSscole
84bd7662dcSscole return (1);
85bd7662dcSscole }
86