diff --git a/main.c b/main.c index da11003..73968fa 100644 --- a/main.c +++ b/main.c @@ -13,6 +13,8 @@ static CFMutableDictionaryRef liveConnections; static int debug; static CFStringRef requiredDeviceId; static char requiredProcessName[256]; +static char includeOccurrences[256]; +static char excludeOccurrences[256]; static void (*printMessage)(int fd, const char *, size_t); static void (*printSeparator)(int fd); @@ -67,6 +69,15 @@ static unsigned char should_print_message(const char *buffer, size_t length) // More filtering options can be added here and return 0 when they won't meed filter criteria + if (strlen(includeOccurrences) && !strstr(buffer, includeOccurrences)) + { + return 0; + } + + if (strlen(excludeOccurrences) && strstr(buffer, excludeOccurrences)) + { + return 0; + } return 1; } @@ -277,14 +288,14 @@ static void color_separator(int fd) int main (int argc, char * const argv[]) { if ((argc == 2) && (strcmp(argv[1], "--help") == 0)) { - fprintf(stderr, "Usage: %s [options]\nOptions:\n -d\t\t\tInclude connect/disconnect messages in standard out\n -u \t\tShow only logs from a specific device\n -p \tShow only logs from a specific process\n\nControl-C to disconnect\nMail bug reports and suggestions to \n", argv[0]); + fprintf(stderr, "Usage: %s [options]\nOptions:\n -d\t\t\tInclude connect/disconnect messages in standard out\n -u \t\tShow only logs from a specific device\n -p \tShow only logs from a specific process\n -f \tFilter output that contain occurrences of (include)\n -x \tFilter output that doesn't contain occurrences of (exclude)\n\nControl-C to disconnect\nMail bug reports and suggestions to \n", argv[0]); return 1; } int c; bool use_separators = false; bool force_color = false; memset(requiredProcessName, '\0', 256); - while ((c = getopt(argc, argv, "dcsu:p:")) != -1) + while ((c = getopt(argc, argv, "dcsu:p:f:x:")) != -1) switch (c) { case 'd': @@ -304,6 +315,12 @@ int main (int argc, char * const argv[]) case 'p': strcpy(requiredProcessName, optarg); break; + case 'f': + strcpy(includeOccurrences, optarg); + break; + case 'x': + strcpy(excludeOccurrences, optarg); + break; case '?': if (optopt == 'u') fprintf(stderr, "Option -%c requires an argument.\n", optopt);