commit 4b6abcd3fc0b22e07992f2a381fe4017251cb3d0
parent fc884748369383f5cb2ba026c2988c53c55e3f58
Author: Jacob R. Edwards <jacobouno@protonmail.com>
Date: Wed, 25 Aug 2021 17:00:25 -0700
Use regular expressions for patterns
Currently there is no caching, I hope to implement it soon.
Diffstat:
2 files changed, 16 insertions(+), 5 deletions(-)
diff --git a/aps/TODO b/aps/TODO
@@ -2,5 +2,3 @@
- Allow 'ok' and 'error: *' items
- Consider separating commands with whitespace, this would require
quoting and escaping
-- Use regular expressions instead of fnmatch(1) (maybe limiting
- find to a single pattern for simplicity)
diff --git a/aps/match.c b/aps/match.c
@@ -16,16 +16,29 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
-#include <fnmatch.h>
+#include <regex.h>
+
+int
+regmatch(char *s, char *pattern)
+{
+ int code;
+ regex_t reg;
+
+ if (regcomp(®, pattern, REG_EXTENDED))
+ return 0;
+ code = regexec(®, s, 0, (void *)0, 0);
+ regfree(®);
+ return code == 0;
+}
int
match(char *s, char *pattern)
{
if (pattern[0] == '!')
- return fnmatch(pattern + 1, s, 0) != 0;
+ return !regmatch(s, pattern + 1);
if (pattern[0] == '\\' && pattern[1] != '\\')
++pattern;
- return fnmatch(pattern, s, 0) == 0;
+ return regmatch(s, pattern);
}
int