ifcmds.c revision 247036
1135446Strhodes/* 2254897Serwin * Copyright (c) 2003, Trent Nelson, <trent@arpa.com>. 3153816Sdougb * All rights reserved. 4153816Sdougb * 5204619Sdougb * Redistribution and use in source and binary forms, with or without 6135446Strhodes * modification, are permitted provided that the following conditions 7135446Strhodes * are met: 8153816Sdougb * 1. Redistributions of source code must retain the above copyright 9135446Strhodes * notice, this list of conditions and the following disclaimer. 10135446Strhodes * 2. Redistributions in binary form must reproduce the above copyright 11153816Sdougb * notice, this list of conditions and the following disclaimer in the 12135446Strhodes * documentation and/or other materials provided with the distribution. 13135446Strhodes * 3. The name of the author may not be used to endorse or promote products 14135446Strhodes * derived from this software without specific prior written permission. 15135446Strhodes * 16135446Strhodes * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 17234010Sdougb * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18153816Sdougb * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19153816Sdougb * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 20153816Sdougb * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21153816Sdougb * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22170222Sdougb * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23153816Sdougb * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24153816Sdougb * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25225361Sdougb * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26153816Sdougb * SUCH DAMAGE. 27153816Sdougb * 28170222Sdougb * $FreeBSD: head/usr.bin/systat/ifcmds.c 247036 2013-02-20 13:47:05Z melifaro $ 29153816Sdougb */ 30153816Sdougb 31153816Sdougb#include <sys/types.h> 32153816Sdougb 33153816Sdougb#include "systat.h" 34170222Sdougb#include "extern.h" 35170222Sdougb#include "convtbl.h" 36153816Sdougb 37170222Sdougb#include <stdlib.h> 38170222Sdougb#include <string.h> 39170222Sdougb 40170222Sdougbint curscale = SC_AUTO; 41170222Sdougbchar *matchline = NULL; 42153816Sdougbint showpps = 0; 43153816Sdougbint needsort = 0; 44153816Sdougb 45254897Serwinint 46170222Sdougbifcmd(const char *cmd, const char *args) 47170222Sdougb{ 48170222Sdougb int scale; 49170222Sdougb 50170222Sdougb if (prefix(cmd, "scale")) { 51170222Sdougb if ((scale = get_scale(args)) != -1) 52153816Sdougb curscale = scale; 53153816Sdougb else { 54153816Sdougb move(CMDLINE, 0); 55170222Sdougb clrtoeol(); 56170222Sdougb addstr("what scale? "); 57153816Sdougb addstr(get_helplist()); 58153816Sdougb } 59170222Sdougb } else if (prefix(cmd, "match")) { 60170222Sdougb if (args != NULL && *args != '\0' && memcmp(args, "*", 2) != 0) { 61153816Sdougb /* We got a valid match line */ 62153816Sdougb if (matchline != NULL) { 63170222Sdougb free(matchline); 64170222Sdougb } 65170222Sdougb needsort = 1; 66153816Sdougb matchline = strdup(args); 67153816Sdougb } else { 68170222Sdougb /* Empty or * pattern, turn filtering off */ 69170222Sdougb if (matchline != NULL) { 70153816Sdougb free(matchline); 71170222Sdougb } 72170222Sdougb needsort = 1; 73153816Sdougb matchline = NULL; 74153816Sdougb } 75170222Sdougb } else if (prefix(cmd, "pps")) 76170222Sdougb showpps = !showpps; 77153816Sdougb 78153816Sdougb return (1); 79170222Sdougb} 80170222Sdougb