diff options
author | pdw <> | 2002-10-25 09:59:02 +0000 |
---|---|---|
committer | pdw <> | 2002-10-25 09:59:02 +0000 |
commit | 36700cef9252382d139a96bfda9a9e0f8e1b5ef1 (patch) | |
tree | 44e7df222d8823b73d7f18eb2b0b4936931d132d /screenfilter.c | |
parent | 5624d5f6866ea35ceac1a4d6447c9571cd40bcc2 (diff) | |
download | iftop-36700cef9252382d139a96bfda9a9e0f8e1b5ef1.zip |
Added regexp based screen filtering.
Diffstat (limited to 'screenfilter.c')
-rw-r--r-- | screenfilter.c | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/screenfilter.c b/screenfilter.c new file mode 100644 index 0000000..93b0465 --- /dev/null +++ b/screenfilter.c @@ -0,0 +1,56 @@ +/* + * screenfilter.c: + * + * Copyright (c) 2002 DecisionSoft Ltd. + * Paul Warren (pdw) Fri Oct 25 10:21:00 2002 + * + */ + +#include <sys/types.h> +#include <regex.h> +#include <stdio.h> +#include "iftop.h" +#include "options.h" + +static const char rcsid[] = "$Id$"; + +extern options_t options ; + +regex_t preg; + +int screen_filter_set(char* s) { + int r; + + if(options.screenfilter != NULL) { + xfree(options.screenfilter); + options.screenfilter = NULL; + regfree(&preg); + } + + r = regcomp(&preg, s, 0); + + if(r == 0) { + options.screenfilter = s; + return 1; + } + else { + xfree(s); + return 0; + } +} + +int screen_filter_match(char *s) { + int r; + if(options.screenfilter == NULL) { + return 1; + } + + r = regexec(&preg, s, 0, NULL, 0); + if(r == 0) { + return 1; + } + else { + return 0; + } +} + |