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