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