Browse Source

* filter-test : optional logfile parameter

master
Alex 'AdUser' Z 9 years ago
parent
commit
30fac00acb
  1. 12
      src/filter-test.c

12
src/filter-test.c

@ -11,7 +11,7 @@
#include "filter.h" #include "filter.h"
void usage() { void usage() {
fprintf(stderr, "Usage: filter-test <library.so> <regexps-file.txt>\n"); fprintf(stderr, "Usage: filter-test <library.so> <regexps-file.txt> [<file.log>]\n");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
@ -23,6 +23,7 @@ int main(int argc, char *argv[]) {
char line[LOGLINE_MAX] = ""; char line[LOGLINE_MAX] = "";
size_t read = 0, matched = 0; size_t read = 0, matched = 0;
const char *error; const char *error;
FILE *file = NULL;
if (argc < 3) if (argc < 3)
usage(); usage();
@ -33,7 +34,14 @@ int main(int argc, char *argv[]) {
if ((filter = f2b_filter_create(&config, argv[2])) == false) if ((filter = f2b_filter_create(&config, argv[2])) == false)
usage(); usage();
while (fgets(line, sizeof(line), stdin) != NULL) { if (argc > 3) {
if ((file = fopen(argv[3], "r")) == NULL)
usage();
} else {
file = stdin;
}
while (fgets(line, sizeof(line), file) != NULL) {
read++; read++;
if (f2b_filter_match(filter, line, match, sizeof(match))) { if (f2b_filter_match(filter, line, match, sizeof(match))) {
matched++; matched++;

Loading…
Cancel
Save