idevicecrashreport: Allow filtering crash reports by filename

Allows to filter crash reports by filename and copy only matching crash reports.

$ idevicecrashreport -u 00008020-001234 --filter MyApplication crash_reports
Move: /MyApplication-2019-07-29-164320.ips

This allows significantly improve speed of collecting only required crash reports.
diff --git a/docs/idevicecrashreport.1 b/docs/idevicecrashreport.1
index aba806a..6acd6e9 100644
--- a/docs/idevicecrashreport.1
+++ b/docs/idevicecrashreport.1
@@ -30,6 +30,9 @@
 .B \-d, \-\-debug
 enable communication debugging.
 .TP
+.B \-f, \-\-filter NAME
+filter crash reports by NAME (case sensitive)
+.TP
 .B \-h, \-\-help
 prints usage information.
 .TP
diff --git a/tools/idevicecrashreport.c b/tools/idevicecrashreport.c
index 7df8dd9..ba54ebc 100644
--- a/tools/idevicecrashreport.c
+++ b/tools/idevicecrashreport.c
@@ -103,7 +103,7 @@
 	return res;
 }
 
-static int afc_client_copy_and_remove_crash_reports(afc_client_t afc, const char* device_directory, const char* host_directory)
+static int afc_client_copy_and_remove_crash_reports(afc_client_t afc, const char* device_directory, const char* host_directory, const char* filename_filter)
 {
 	afc_error_t afc_error;
 	int k;
@@ -242,12 +242,16 @@
 #else
 			mkdir(target_filename, 0755);
 #endif
-			res = afc_client_copy_and_remove_crash_reports(afc, source_filename, target_filename);
+			res = afc_client_copy_and_remove_crash_reports(afc, source_filename, target_filename, filename_filter);
 
 			/* remove directory from device */
 			if (!keep_crash_reports)
 				afc_remove_path(afc, source_filename);
 		} else if (S_ISREG(stbuf.st_mode)) {
+			if (filename_filter != NULL && strstr(source_filename, filename_filter) == NULL) {
+				continue;
+			}
+
 			/* copy file to host */
 			afc_error = afc_file_open(afc, source_filename, AFC_FOPEN_RDONLY, &handle);
 			if(afc_error != AFC_E_SUCCESS) {
@@ -324,6 +328,7 @@
 	printf("  -e, --extract\t\textract raw crash report into separate '.crash' file\n");
 	printf("  -k, --keep\t\tcopy but do not remove crash reports from device\n");
 	printf("  -d, --debug\t\tenable communication debugging\n");
+	printf("  -f, --filter NAME\tfilter crash reports by NAME (case sensitive)\n");
 	printf("  -h, --help\t\tprints usage information\n");
 	printf("  -v, --version\t\tprints version information\n");
 	printf("\n");
@@ -344,6 +349,7 @@
 	int i;
 	const char* udid = NULL;
 	int use_network = 0;
+	const char* filename_filter = NULL;
 
 #ifndef WIN32
 	signal(SIGPIPE, SIG_IGN);
@@ -367,6 +373,15 @@
 			use_network = 1;
 			continue;
 		}
+		else if (!strcmp(argv[i], "-f") || !strcmp(argv[i], "--filter")) {
+			i++;
+			if (!argv[i] || !*argv[i]) {
+				print_usage(argc, argv);
+				return 0;
+			}
+			filename_filter = argv[i];
+			continue;
+		}
 		else if (!strcmp(argv[i], "-h") || !strcmp(argv[i], "--help")) {
 			print_usage(argc, argv);
 			return 0;
@@ -492,7 +507,7 @@
 	}
 
 	/* recursively copy crash reports from the device to a local directory */
-	if (afc_client_copy_and_remove_crash_reports(afc, ".", target_directory) < 0) {
+	if (afc_client_copy_and_remove_crash_reports(afc, ".", target_directory, filename_filter) < 0) {
 		fprintf(stderr, "ERROR: Failed to get crash reports from device.\n");
 		afc_client_free(afc);
 		idevice_free(device);