summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2010-08-04 17:07:20 +0200
committerBram Moolenaar <Bram@vim.org>2010-08-04 17:07:20 +0200
commit80a7dcf8b5af473af674fb47769accc40e67cac0 (patch)
tree50884d2f3ea7aa2bd6ad9fa5c6e0180178666ddd
parent150a1321b230ce1cfd661c7da89c3684d0f2d478 (diff)
downloadvim-80a7dcf8b5af473af674fb47769accc40e67cac0.zip
Make :find completion consistent between Unix and MS-Windows. Add a test.
(Nazri Ramliy)
-rw-r--r--src/misc1.c55
-rw-r--r--src/misc2.c30
-rw-r--r--src/proto/misc2.pro1
-rw-r--r--src/testdir/Make_amiga.mak3
-rw-r--r--src/testdir/Make_dos.mak2
-rw-r--r--src/testdir/Make_ming.mak2
-rw-r--r--src/testdir/Make_os2.mak2
-rw-r--r--src/testdir/Make_vms.mms4
-rw-r--r--src/testdir/Makefile2
-rw-r--r--src/testdir/test73.in21
-rw-r--r--src/testdir/test73.ok3
11 files changed, 75 insertions, 50 deletions
diff --git a/src/misc1.c b/src/misc1.c
index 6f197f22b..c8fb8eb3f 100644
--- a/src/misc1.c
+++ b/src/misc1.c
@@ -9321,7 +9321,7 @@ expand_path_option(curdir, gap)
ga_init2(gap, (int)sizeof(char_u *), 1);
- if ((buf = alloc((int)(MAXPATHL))) == NULL)
+ if ((buf = alloc((int)MAXPATHL)) == NULL)
return;
while (*path_option != NUL)
@@ -9564,8 +9564,8 @@ theend:
}
/*
- * Calls globpath() or mch_expandpath() with 'path' values for the given
- * pattern and stores the result in gap.
+ * Calls globpath() with 'path' values for the given pattern and stores the
+ * result in "gap".
* Returns the total number of matches.
*/
static int
@@ -9574,18 +9574,12 @@ expand_in_path(gap, pattern, flags)
char_u *pattern;
int flags; /* EW_* flags */
{
- char_u **path_list;
char_u *curdir;
garray_T path_ga;
- int i;
-# ifdef WIN3264
- char_u *file_pattern;
-# else
char_u *files = NULL;
char_u *s; /* start */
char_u *e; /* end */
char_u *paths = NULL;
-# endif
if ((curdir = alloc((unsigned)MAXPATHL)) == NULL)
return 0;
@@ -9595,42 +9589,14 @@ expand_in_path(gap, pattern, flags)
vim_free(curdir);
if (path_ga.ga_len == 0)
return 0;
- path_list = (char_u **)(path_ga.ga_data);
-# ifdef WIN3264
- if ((file_pattern = alloc((unsigned)MAXPATHL)) == NULL)
+
+ paths = ga_concat_strings(&path_ga);
+ ga_clear_strings(&path_ga);
+ if (paths == NULL)
return 0;
- for (i = 0; i < path_ga.ga_len; i++)
- {
- if (STRLEN(path_list[i]) + STRLEN(pattern) + 2 > MAXPATHL)
- continue;
- STRCPY(file_pattern, path_list[i]);
- STRCAT(file_pattern, "/");
- STRCAT(file_pattern, pattern);
- mch_expandpath(gap, file_pattern, EW_DIR|EW_ADDSLASH|EW_FILE);
- }
- vim_free(file_pattern);
-# else
- for (i = 0; i < path_ga.ga_len; i++)
- {
- if (paths == NULL)
- {
- if ((paths = alloc((unsigned)(STRLEN(path_list[i]) + 1))) == NULL)
- return 0;
- STRCPY(paths, path_list[i]);
- }
- else
- {
- if ((paths = realloc(paths, (int)(STRLEN(paths)
- + STRLEN(path_list[i]) + 2))) == NULL)
- return 0;
- STRCAT(paths, ",");
- STRCAT(paths, path_list[i]);
- }
- }
files = globpath(paths, pattern, 0);
vim_free(paths);
-
if (files == NULL)
return 0;
@@ -9654,9 +9620,7 @@ expand_in_path(gap, pattern, flags)
s = e;
}
}
-
vim_free(files);
-# endif
return gap->ga_len;
}
@@ -9797,7 +9761,12 @@ gen_expand_wildcards(num_pat, pat, num_file, file, flags)
{
#if defined(FEAT_SEARCHPATH)
if (*p != '.' && !vim_ispathsep(*p) && (flags & EW_PATH))
+ {
+ /* recursiveness is OK here */
+ recursive = FALSE;
add_pat = expand_in_path(&ga, p, flags);
+ recursive = TRUE;
+ }
else
#endif
add_pat = mch_expandpath(&ga, p, flags);
diff --git a/src/misc2.c b/src/misc2.c
index 96813a484..3c25a1f08 100644
--- a/src/misc2.c
+++ b/src/misc2.c
@@ -2068,6 +2068,36 @@ ga_grow(gap, n)
}
/*
+ * For a growing array that contains a list of strings: concatenate all the
+ * strings with a separating comma.
+ * Returns NULL when out of memory.
+ */
+ char_u *
+ga_concat_strings(gap)
+ garray_T *gap;
+{
+ int i;
+ int len = 0;
+ char_u *s;
+
+ for (i = 0; i < gap->ga_len; ++i)
+ len += (int)STRLEN(((char_u **)(gap->ga_data))[i]) + 1;
+
+ s = alloc(len + 1);
+ if (s != NULL)
+ {
+ *s = NUL;
+ for (i = 0; i < gap->ga_len; ++i)
+ {
+ if (*s != NUL)
+ STRCAT(s, ",");
+ STRCAT(s, ((char_u **)(gap->ga_data))[i]);
+ }
+ }
+ return s;
+}
+
+/*
* Concatenate a string to a growarray which contains characters.
* Note: Does NOT copy the NUL at the end!
*/
diff --git a/src/proto/misc2.pro b/src/proto/misc2.pro
index 3fa0c9b3b..671bd9fdf 100644
--- a/src/proto/misc2.pro
+++ b/src/proto/misc2.pro
@@ -53,6 +53,7 @@ void ga_clear_strings __ARGS((garray_T *gap));
void ga_init __ARGS((garray_T *gap));
void ga_init2 __ARGS((garray_T *gap, int itemsize, int growsize));
int ga_grow __ARGS((garray_T *gap, int n));
+char_u *ga_concat_strings __ARGS((garray_T *gap));
void ga_concat __ARGS((garray_T *gap, char_u *s));
void ga_append __ARGS((garray_T *gap, int c));
int name_to_mod_mask __ARGS((int c));
diff --git a/src/testdir/Make_amiga.mak b/src/testdir/Make_amiga.mak
index 59c616de3..a2644cd95 100644
--- a/src/testdir/Make_amiga.mak
+++ b/src/testdir/Make_amiga.mak
@@ -27,7 +27,7 @@ SCRIPTS = test1.out test3.out test4.out test5.out test6.out \
test56.out test57.out test58.out test59.out test60.out \
test61.out test62.out test63.out test64.out test65.out \
test66.out test67.out test68.out test69.out test70.out \
- test71.out test72.out
+ test71.out test72.out test73.out
.SUFFIXES: .in .out
@@ -119,3 +119,4 @@ test69.out: test69.in
test70.out: test70.in
test71.out: test71.in
test72.out: test72.in
+test73.out: test73.in
diff --git a/src/testdir/Make_dos.mak b/src/testdir/Make_dos.mak
index 063fd8564..94b44c242 100644
--- a/src/testdir/Make_dos.mak
+++ b/src/testdir/Make_dos.mak
@@ -27,7 +27,7 @@ SCRIPTS = test3.out test4.out test5.out test6.out test7.out \
test30.out test31.out test32.out test33.out test34.out \
test37.out test38.out test39.out test40.out test41.out \
test42.out test52.out test65.out test66.out test67.out \
- test68.out test69.out test71.out test72.out
+ test68.out test69.out test71.out test72.out test73.out
SCRIPTS32 = test50.out test70.out
diff --git a/src/testdir/Make_ming.mak b/src/testdir/Make_ming.mak
index 9029d98c9..2d40ab5c7 100644
--- a/src/testdir/Make_ming.mak
+++ b/src/testdir/Make_ming.mak
@@ -47,7 +47,7 @@ SCRIPTS = test3.out test4.out test5.out test6.out test7.out \
test30.out test31.out test32.out test33.out test34.out \
test37.out test38.out test39.out test40.out test41.out \
test42.out test52.out test65.out test66.out test67.out \
- test68.out test69.out test71.out test72.out
+ test68.out test69.out test71.out test72.out test72.out
SCRIPTS32 = test50.out test70.out
diff --git a/src/testdir/Make_os2.mak b/src/testdir/Make_os2.mak
index f5262e21e..46e9b6c16 100644
--- a/src/testdir/Make_os2.mak
+++ b/src/testdir/Make_os2.mak
@@ -27,7 +27,7 @@ SCRIPTS = test1.out test3.out test4.out test5.out test6.out \
test56.out test57.out test58.out test59.out test60.out \
test61.out test62.out test63.out test64.out test65.out \
test66.out test67.out test68.out test69.out test70.out \
- test71.out test72.out
+ test71.out test72.out test73.out
.SUFFIXES: .in .out
diff --git a/src/testdir/Make_vms.mms b/src/testdir/Make_vms.mms
index 6ea02de1e..4e2c096e0 100644
--- a/src/testdir/Make_vms.mms
+++ b/src/testdir/Make_vms.mms
@@ -4,7 +4,7 @@
# Authors: Zoltan Arpadffy, <arpadffy@polarhome.com>
# Sandor Kopanyi, <sandor.kopanyi@mailbox.hu>
#
-# Last change: 2010 Jul 30
+# Last change: 2010 Aug 04
#
# This has been tested on VMS 6.2 to 8.3 on DEC Alpha, VAX and IA64.
# Edit the lines in the Configuration section below to select.
@@ -94,7 +94,7 @@ GUI_OPTION = -g
.ENDIF
.IFDEF WANT_UNIX
-SCRIPT_UNIX = test10.out test12.out test25.out test27.out test49.out
+SCRIPT_UNIX = test10.out test12.out test25.out test27.out test49.out test73.out
.ENDIF
.IFDEF WANT_WIN
diff --git a/src/testdir/Makefile b/src/testdir/Makefile
index f970b26b8..4951dc2fa 100644
--- a/src/testdir/Makefile
+++ b/src/testdir/Makefile
@@ -23,7 +23,7 @@ SCRIPTS = test1.out test2.out test3.out test4.out test5.out test6.out \
test54.out test55.out test56.out test57.out test58.out \
test59.out test60.out test61.out test62.out test63.out \
test64.out test65.out test66.out test67.out test68.out \
- test69.out test70.out test71.out test72.out
+ test69.out test70.out test71.out test72.out test73.out
SCRIPTS_GUI = test16.out
diff --git a/src/testdir/test73.in b/src/testdir/test73.in
new file mode 100644
index 000000000..822dde3f5
--- /dev/null
+++ b/src/testdir/test73.in
@@ -0,0 +1,21 @@
+Tests for find completion.
+
+STARTTEST
+:!mkdir -p Xfind/in/path
+:e Xfind/file.txt
+aHoly Grail:w
+:e Xfind/in/file.txt
+aJimmy Hoffa:w
+:e Xfind/in/path/file.txt
+aE.T.:w
+:set path=Xfind/**
+:set nocp
+:find file
+:w! test.out
+:find file
+:w >>test.out
+:find file
+:w >>test.out
+:qa!
+ENDTEST
+
diff --git a/src/testdir/test73.ok b/src/testdir/test73.ok
new file mode 100644
index 000000000..bf1d43359
--- /dev/null
+++ b/src/testdir/test73.ok
@@ -0,0 +1,3 @@
+Holy Grail
+Jimmy Hoffa
+E.T.