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