diff mbox series

expand: Add support for caret

Message ID ZkmBivbgyEeKclKS@gondor.apana.org.au (mailing list archive)
State Accepted
Delegated to: Herbert Xu
Headers show
Series expand: Add support for caret | expand

Commit Message

Herbert Xu May 19, 2024, 4:35 a.m. UTC
Rather than making dash bigger by actively excluding carets when
fnmatch is enabled, add caret support when fnmatch is disabled.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
---
 src/expand.c   | 5 +----
 src/mksyntax.c | 4 ++--
 src/mystring.c | 3 ---
 src/mystring.h | 2 +-
 4 files changed, 4 insertions(+), 10 deletions(-)
diff mbox series

Patch

diff --git a/src/expand.c b/src/expand.c
index 399a9e6..d8b354c 100644
--- a/src/expand.c
+++ b/src/expand.c
@@ -1580,7 +1580,7 @@  pmatch(const char *pattern, const char *string)
 
 			startp = p;
 			invert = 0;
-			if (*p == '!') {
+			if (*p == '!' || *p == '^') {
 				invert++;
 				p++;
 			}
@@ -1694,11 +1694,8 @@  _rmescapes(char *str, int flag)
 			notescaped ^= globbing;
 			goto copy;
 		}
-		if (FNMATCH_IS_ENABLED && *p == '^')
-			goto add_escape;
 		if (*p == (char)CTLESC) {
 			p++;
-add_escape:
 			if (notescaped)
 				*q++ = '\\';
 			else if (inquotes) {
diff --git a/src/mksyntax.c b/src/mksyntax.c
index da18f5d..4d7280b 100644
--- a/src/mksyntax.c
+++ b/src/mksyntax.c
@@ -178,14 +178,14 @@  main(int argc, char **argv)
 	add("$", "CVAR");
 	add("}", "CENDVAR");
 	/* ':/' for tilde expansion, '-' for [a\-x] pattern ranges */
-	add("!*?[=~:/-]", "CCTL");
+	add("^!*?[=~:/-]", "CCTL");
 	print("dqsyntax");
 	init();
 	fputs("\n/* syntax table used when in single quotes */\n", cfile);
 	add("\n", "CNL");
 	add("'", "CENDQUOTE");
 	/* ':/' for tilde expansion, '-' for [a\-x] pattern ranges */
-	add("!*?[=~:/-]\\", "CCTL");
+	add("^!*?[=~:/-]\\", "CCTL");
 	print("sqsyntax");
 	init();
 	fputs("\n/* syntax table used when in arithmetic */\n", cfile);
diff --git a/src/mystring.c b/src/mystring.c
index 5eace6c..978bbb5 100644
--- a/src/mystring.c
+++ b/src/mystring.c
@@ -64,9 +64,6 @@  const char dolatstr[] = { CTLQUOTEMARK, CTLVAR, VSNORMAL | VSBIT, '@', '=',
 			  CTLQUOTEMARK, '\0' };
 const char cqchars[] = {
 	'\\',
-#ifdef HAVE_FNMATCH
-	'^',
-#endif
 	CTLESC, CTLQUOTEMARK, 0
 };
 const char illnum[] = "Illegal number: %s";
diff --git a/src/mystring.h b/src/mystring.h
index 07d0c73..d178990 100644
--- a/src/mystring.h
+++ b/src/mystring.h
@@ -54,7 +54,7 @@  extern const char spcstr[];
 extern const char dolatstr[];
 #define DOLATSTRLEN 6
 extern const char cqchars[];
-#define qchars (cqchars + FNMATCH_IS_ENABLED + 1)
+#define qchars (cqchars + 1)
 extern const char illnum[];
 extern const char homestr[];