summaryrefslogtreecommitdiffstats
path: root/src/buffer.c
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2005-02-26 23:04:13 +0000
committerBram Moolenaar <Bram@vim.org>2005-02-26 23:04:13 +0000
commit05159a0c6a27a030c8497c5cf836977090f9e75d (patch)
tree9ccc167cf3e830e5d01aff4555f99d854cbb623b /src/buffer.c
parent5313dcb75ac76501f23d21ac94efdbeeabc860bc (diff)
updated for version 7.0052v7.0052
Diffstat (limited to 'src/buffer.c')
-rw-r--r--src/buffer.c38
1 files changed, 28 insertions, 10 deletions
diff --git a/src/buffer.c b/src/buffer.c
index a634062cf6..1eb23a3246 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -2082,25 +2082,38 @@ ExpandBufnames(pat, num_file, file, options)
char_u *p;
int attempt;
regprog_T *prog;
+ char_u *patc;
*num_file = 0; /* return values in case of FAIL */
*file = NULL;
+ /* Make a copy of "pat" and change "^" to "\(^\|[\/]\)". */
+ if (*pat == '^')
+ {
+ patc = alloc((unsigned)STRLEN(pat) + 11);
+ if (patc == NULL)
+ return FAIL;
+ STRCPY(patc, "\\(^\\|[\\/]\\)");
+ STRCPY(patc + 11, pat + 1);
+ }
+ else
+ patc = pat;
+
/*
- * attempt == 1: try match with '^', match at start
- * attempt == 2: try match without '^', match anywhere
+ * attempt == 0: try match with '\<', match at start of word
+ * attempt == 2: try match without '\<', match anywhere
*/
- for (attempt = 1; attempt <= 2; ++attempt)
+ for (attempt = 0; attempt <= 2; attempt += 2)
{
- if (attempt == 2)
- {
- if (*pat != '^') /* there's no '^', no need to try again */
- break;
- ++pat; /* skip the '^' */
- }
- prog = vim_regcomp(pat, p_magic ? RE_MAGIC : 0);
+ if (attempt == 2 && patc == pat)
+ break; /* there was no anchor, no need to try again */
+ prog = vim_regcomp(patc + attempt, RE_MAGIC);
if (prog == NULL)
+ {
+ if (patc != pat)
+ vim_free(patc);
return FAIL;
+ }
/*
* round == 1: Count the matches.
@@ -2136,6 +2149,8 @@ ExpandBufnames(pat, num_file, file, options)
if (*file == NULL)
{
vim_free(prog);
+ if (patc != pat)
+ vim_free(patc);
return FAIL;
}
}
@@ -2145,6 +2160,9 @@ ExpandBufnames(pat, num_file, file, options)
break;
}
+ if (patc != pat)
+ vim_free(patc);
+
*num_file = count;
return (count == 0 ? FAIL : OK);
}