if (eap->cmdidx == CMD_sfind || eap->cmdidx == CMD_tabfind)
{
+ char_u *file_to_find = NULL;
+ char *search_ctx = NULL;
fname = find_file_in_path(eap->arg, (int)STRLEN(eap->arg),
- FNAME_MESS, TRUE, curbuf->b_ffname);
+ FNAME_MESS, TRUE, curbuf->b_ffname,
+ &file_to_find, &search_ctx);
+ vim_free(file_to_find);
+ vim_findfile_cleanup(search_ctx);
if (fname == NULL)
goto theend;
eap->arg = fname;
{
char_u *fname;
int count;
+ char_u *file_to_find = NULL;
+ char *search_ctx = NULL;
fname = find_file_in_path(eap->arg, (int)STRLEN(eap->arg), FNAME_MESS,
- TRUE, curbuf->b_ffname);
+ TRUE, curbuf->b_ffname, &file_to_find, &search_ctx);
if (eap->addr_count > 0)
{
- // Repeat finding the file "count" times. This matters when it
- // appears several times in the path.
+ // Repeat finding the file "count" times. This matters when it appears
+ // several times in the path.
count = eap->line2;
while (fname != NULL && --count > 0)
{
vim_free(fname);
fname = find_file_in_path(NULL, 0, FNAME_MESS,
- FALSE, curbuf->b_ffname);
+ FALSE, curbuf->b_ffname, &file_to_find, &search_ctx);
}
}
+ VIM_CLEAR(file_to_find);
+ vim_findfile_cleanup(search_ctx);
if (fname == NULL)
return;
}
/*
- * ":open" simulation: for now just work like ":visual".
+ * ":open" simulation: for now works just like ":visual".
*/
static void
ex_open(exarg_T *eap)
// Special case: ":global/pat/visual\NLvi-commands"
if (global_busy)
{
- int rd = RedrawingDisabled;
- int nwr = no_wait_return;
- int ms = msg_scroll;
-#ifdef FEAT_GUI
- int he = hold_gui_events;
-#endif
-
if (eap->nextcmd != NULL)
{
stuffReadbuff(eap->nextcmd);
if (exmode_was != EXMODE_VIM)
settmode(TMODE_RAW);
+ int save_rd = RedrawingDisabled;
RedrawingDisabled = 0;
+ int save_nwr = no_wait_return;
no_wait_return = 0;
need_wait_return = FALSE;
+ int save_ms = msg_scroll;
msg_scroll = 0;
#ifdef FEAT_GUI
+ int save_he = hold_gui_events;
hold_gui_events = 0;
#endif
set_must_redraw(UPD_CLEAR);
main_loop(FALSE, TRUE);
pending_exmode_active = FALSE;
- RedrawingDisabled = rd;
- no_wait_return = nwr;
- msg_scroll = ms;
+ RedrawingDisabled = save_rd;
+ no_wait_return = save_nwr;
+ msg_scroll = save_ms;
#ifdef FEAT_GUI
- hold_gui_events = he;
+ hold_gui_events = save_he;
#endif
}
return;
int len, // length of file name
int options,
int first, // use count'th matching file name
- char_u *rel_fname) // file name searching relative to
+ char_u *rel_fname, // file name searching relative to
+ char_u **file_to_find, // in/out: modified copy of file name
+ char **search_ctx) // in/out: state of the search
{
return find_file_in_path_option(ptr, len, options, first,
*curbuf->b_p_path == NUL ? p_path : curbuf->b_p_path,
- FINDFILE_BOTH, rel_fname, curbuf->b_p_sua);
+ FINDFILE_BOTH, rel_fname, curbuf->b_p_sua,
+ file_to_find, search_ctx);
}
-static char_u *ff_file_to_find = NULL;
-static void *fdip_search_ctx = NULL;
-
# if defined(EXITFREE) || defined(PROTO)
void
free_findfile(void)
{
- vim_free(ff_file_to_find);
- vim_findfile_cleanup(fdip_search_ctx);
- vim_free(ff_expand_buffer);
+ VIM_CLEAR(ff_expand_buffer);
}
# endif
char_u *ptr, // file name
int len, // length of file name
int options,
- char_u *rel_fname) // file name searching relative to
+ char_u *rel_fname, // file name searching relative to
+ char_u **file_to_find, // in/out: modified copy of file name
+ char **search_ctx) // in/out: state of the search
{
return find_file_in_path_option(ptr, len, options, TRUE, p_cdpath,
- FINDFILE_DIR, rel_fname, (char_u *)"");
+ FINDFILE_DIR, rel_fname, (char_u *)"",
+ file_to_find, search_ctx);
}
char_u *
char_u *path_option, // p_path or p_cdpath
int find_what, // FINDFILE_FILE, _DIR or _BOTH
char_u *rel_fname, // file name we are looking relative to.
- char_u *suffixes) // list of suffixes, 'suffixesadd' option
+ char_u *suffixes, // list of suffixes, 'suffixesadd' option
+ char_u **file_to_find, // in/out: modified copy of file name
+ char **search_ctx_arg) // in/out: state of the search
{
+ ff_search_ctx_T **search_ctx = (ff_search_ctx_T **)search_ctx_arg;
static char_u *dir;
static int did_findfile_init = FALSE;
char_u save_char;
expand_env_esc(ptr, NameBuff, MAXPATHL, FALSE, TRUE, NULL);
ptr[len] = save_char;
- vim_free(ff_file_to_find);
- ff_file_to_find = vim_strsave(NameBuff);
- if (ff_file_to_find == NULL) // out of memory
+ vim_free(*file_to_find);
+ *file_to_find = vim_strsave(NameBuff);
+ if (*file_to_find == NULL) // out of memory
{
file_name = NULL;
goto theend;
if (options & FNAME_UNESC)
{
// Change all "\ " to " ".
- for (ptr = ff_file_to_find; *ptr != NUL; ++ptr)
+ for (ptr = *file_to_find; *ptr != NUL; ++ptr)
if (ptr[0] == '\\' && ptr[1] == ' ')
mch_memmove(ptr, ptr + 1, STRLEN(ptr));
}
}
- rel_to_curdir = (ff_file_to_find[0] == '.'
- && (ff_file_to_find[1] == NUL
- || vim_ispathsep(ff_file_to_find[1])
- || (ff_file_to_find[1] == '.'
- && (ff_file_to_find[2] == NUL
- || vim_ispathsep(ff_file_to_find[2])))));
- if (vim_isAbsName(ff_file_to_find)
+ rel_to_curdir = ((*file_to_find)[0] == '.'
+ && ((*file_to_find)[1] == NUL
+ || vim_ispathsep((*file_to_find)[1])
+ || ((*file_to_find)[1] == '.'
+ && ((*file_to_find)[2] == NUL
+ || vim_ispathsep((*file_to_find)[2])))));
+ if (vim_isAbsName(*file_to_find)
// "..", "../path", "." and "./path": don't use the path_option
|| rel_to_curdir
# if defined(MSWIN)
// handle "\tmp" as absolute path
- || vim_ispathsep(ff_file_to_find[0])
+ || vim_ispathsep((*file_to_find)[0])
// handle "c:name" as absolute path
- || (ff_file_to_find[0] != NUL && ff_file_to_find[1] == ':')
+ || ((*file_to_find)[0] != NUL && (*file_to_find)[1] == ':')
# endif
# ifdef AMIGA
// handle ":tmp" as absolute path
- || ff_file_to_find[0] == ':'
+ || (*file_to_find)[0] == ':'
# endif
)
{
int l;
int run;
- if (path_with_url(ff_file_to_find))
+ if (path_with_url(*file_to_find))
{
- file_name = vim_strsave(ff_file_to_find);
+ file_name = vim_strsave(*file_to_find);
goto theend;
}
// Otherwise or when this fails use the current directory.
for (run = 1; run <= 2; ++run)
{
- l = (int)STRLEN(ff_file_to_find);
+ l = (int)STRLEN(*file_to_find);
if (run == 1
&& rel_to_curdir
&& (options & FNAME_REL)
&& STRLEN(rel_fname) + l < MAXPATHL)
{
STRCPY(NameBuff, rel_fname);
- STRCPY(gettail(NameBuff), ff_file_to_find);
+ STRCPY(gettail(NameBuff), *file_to_find);
l = (int)STRLEN(NameBuff);
}
else
{
- STRCPY(NameBuff, ff_file_to_find);
+ STRCPY(NameBuff, *file_to_find);
run = 2;
}
if (first == TRUE)
{
// vim_findfile_free_visited can handle a possible NULL pointer
- vim_findfile_free_visited(fdip_search_ctx);
+ vim_findfile_free_visited(*search_ctx);
dir = path_option;
did_findfile_init = FALSE;
}
{
if (did_findfile_init)
{
- file_name = vim_findfile(fdip_search_ctx);
+ file_name = vim_findfile(*search_ctx);
if (file_name != NULL)
break;
{
// We searched all paths of the option, now we can
// free the search context.
- vim_findfile_cleanup(fdip_search_ctx);
- fdip_search_ctx = NULL;
+ vim_findfile_cleanup(*search_ctx);
+ *search_ctx = NULL;
break;
}
// get the stopdir string
r_ptr = vim_findfile_stopdir(buf);
- fdip_search_ctx = vim_findfile_init(buf, ff_file_to_find,
+ *search_ctx = vim_findfile_init(buf, *file_to_find,
r_ptr, 100, FALSE, find_what,
- fdip_search_ctx, FALSE, rel_fname);
- if (fdip_search_ctx != NULL)
+ *search_ctx, FALSE, rel_fname);
+ if (*search_ctx != NULL)
did_findfile_init = TRUE;
vim_free(buf);
}
if (first == TRUE)
{
if (find_what == FINDFILE_DIR)
- semsg(_(e_cant_find_directory_str_in_cdpath),
- ff_file_to_find);
+ semsg(_(e_cant_find_directory_str_in_cdpath), *file_to_find);
else
- semsg(_(e_cant_find_file_str_in_path),
- ff_file_to_find);
+ semsg(_(e_cant_find_file_str_in_path), *file_to_find);
}
else
{
if (find_what == FINDFILE_DIR)
semsg(_(e_no_more_directory_str_found_in_cdpath),
- ff_file_to_find);
+ *file_to_find);
else
- semsg(_(e_no_more_file_str_found_in_path),
- ff_file_to_find);
+ semsg(_(e_no_more_file_str_found_in_path), *file_to_find);
}
}
if (options & FNAME_EXP)
{
+ char_u *file_to_find = NULL;
+ char *search_ctx = NULL;
+
file_name = find_file_in_path(ptr, len, options & ~FNAME_MESS,
- TRUE, rel_fname);
+ TRUE, rel_fname, &file_to_find, &search_ctx);
# if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
/*
ptr = tofree;
len = (int)STRLEN(ptr);
file_name = find_file_in_path(ptr, len, options & ~FNAME_MESS,
- TRUE, rel_fname);
+ TRUE, rel_fname, &file_to_find, &search_ctx);
}
}
# endif
while (file_name != NULL && --count > 0)
{
vim_free(file_name);
- file_name = find_file_in_path(ptr, len, options, FALSE, rel_fname);
+ file_name = find_file_in_path(ptr, len, options, FALSE, rel_fname,
+ &file_to_find, &search_ctx);
}
+
+ vim_free(file_to_find);
+ vim_findfile_cleanup(search_ctx);
}
else
file_name = vim_strnsave(ptr, len);