Enable extended pattern matching

So that the exclude options can also work as include using special
pattern syntax.

For example, to only include /dev/ttyUSB* devices simply do:

$ tio --exclude-devices=!(/dev/ttyUSB*) --list

See the man page of fnmatch() for all available extended pattern
options.
This commit is contained in:
Martin Lund 2024-04-29 19:27:45 +02:00
parent d8fb141bc4
commit 8ead9337d1

View file

@ -19,6 +19,7 @@
* 02110-1301, USA.
*/
#define _GNU_SOURCE // For FNM_EXTMATCH
#include "config.h"
#include <ctype.h>
#include <dirent.h>
@ -197,7 +198,7 @@ bool match_patterns(const char *string, const char *patterns)
while (pattern != NULL)
{
// Check if the string matches the current pattern
if (fnmatch(pattern, string, 0) == 0)
if (fnmatch(pattern, string, FNM_EXTMATCH) == 0)
{
free(patterns_copy);
return true;