screenfilter.c 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /*
  2. * screenfilter.c:
  3. *
  4. * Copyright (c) 2002 DecisionSoft Ltd.
  5. * Paul Warren (pdw) Fri Oct 25 10:21:00 2002
  6. *
  7. */
  8. #include "config.h"
  9. #ifdef HAVE_REGCOMP
  10. #include <sys/types.h>
  11. #include <regex.h>
  12. #include <stdio.h>
  13. #include "iftop.h"
  14. #include "options.h"
  15. static const char rcsid[] = "$Id: screenfilter.c,v 1.3 2002/11/04 12:27:35 chris Exp $";
  16. extern options_t options ;
  17. regex_t preg;
  18. int screen_filter_set(char* s) {
  19. int r;
  20. if(options.screenfilter != NULL) {
  21. xfree(options.screenfilter);
  22. options.screenfilter = NULL;
  23. regfree(&preg);
  24. }
  25. r = regcomp(&preg, s, REG_ICASE|REG_EXTENDED);
  26. if(r == 0) {
  27. options.screenfilter = s;
  28. return 1;
  29. }
  30. else {
  31. xfree(s);
  32. return 0;
  33. }
  34. }
  35. int screen_filter_match(char *s) {
  36. int r;
  37. if(options.screenfilter == NULL) {
  38. return 1;
  39. }
  40. r = regexec(&preg, s, 0, NULL, 0);
  41. if(r == 0) {
  42. return 1;
  43. }
  44. else {
  45. return 0;
  46. }
  47. }
  48. #endif /* HAVE_REGCOMP */