libflashprog: Allow optional sub-patterns when matching names

When a sub-pattern contains only one alternative (i.e. there is no
'/' at all), or the first alternative is explicitly empty (i.e. we
have something like "(/...)", treat the sub-pattern as optional.

Change-Id: Ib55d43d7198b7e0a3f866721126d81475e78eae8
Signed-off-by: Nico Huber <nico.h@gmx.de>
Reviewed-on: https://review.sourcearcade.org/c/flashprog/+/569
Reviewed-by: Jakob Haufe <sur5r@sur5r.net>
diff --git a/libflashprog.c b/libflashprog.c
index c8b9c5e..24885a3 100644
--- a/libflashprog.c
+++ b/libflashprog.c
@@ -286,8 +286,11 @@
 		if (*pattern == '(') {				/* potential sub-pattern */
 			const char *const sub_end = strlvlchr(pattern + 1, 0, ')');
 			if (sub_end) {
+				const char *delim = strlvlchr(pattern + 1, 0, '/');
 				const char *sub_match = match_chip_name(pattern + 1, cur_match);
-				if (sub_match > cur_match) {
+				/* if there is only one pattern in the parentheses (i.e. no '/')
+				   or the first sub-pattern is empty, consider the match optional */
+				if (sub_match > cur_match || !delim || delim == pattern + 1) {
 					cur_match = sub_match - 1;
 					pattern = sub_end;
 					continue;