From 434d686ee4c2d46ac08425d1809afffb9548849c Mon Sep 17 00:00:00 2001 From: Chris Allegretta Date: Mon, 3 Feb 2003 04:55:17 +0000 Subject: [PATCH] files.c:do_insertfile() - Add some more checks and fix recursion when toggling multibuffer (David Benbennick) git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@1416 35c25a1d-7b9e-4130-9fde-d3aeb78583b8 --- ChangeLog | 3 +++ TODO | 3 +++ files.c | 75 +++++++++++++++++++++++++++---------------------------- 3 files changed, 43 insertions(+), 38 deletions(-) diff --git a/ChangeLog b/ChangeLog index 0d27b9d6..b4e3ef12 100644 --- a/ChangeLog +++ b/ChangeLog @@ -48,6 +48,9 @@ CVS Code - - Fix goto directory operating dir check and tilde expansion (David Benbennick). - Even more checks and operating dir fixes (David Benbennick). + do_insertfile() + - Add some more checks and fix recursion when toggling + multibuffer (David Benbennick). open_file() - Fix FD leak with file load error (David Benbennick). add_open_file() diff --git a/TODO b/TODO index 2b7ae855..63ba5c1d 100644 --- a/TODO +++ b/TODO @@ -22,6 +22,9 @@ For version 1.4: - Remindable keys? - Keystroke to implement "Add next sequence as raw" like vi's ^V. - Spell check selected text only. +- Make "To line" (^W^T) and "Read from Command" (^R^X) re-enter their + parent menu when their keystroke is entered a second time (^W^T^T and + (^R^X^X)(requires figuring out when to keep cursor pos and when not to). Old requests: diff --git a/files.c b/files.c index d7a8cd6b..b2d14ea7 100644 --- a/files.c +++ b/files.c @@ -427,6 +427,10 @@ int do_insertfile(int loading_file) wrap_reset(); +#if !defined(DISABLE_BROWSER) || !defined(NANO_SMALL) && defined(ENABLE_MULTIBUFFER) + start_again: /* Goto here when the user cancels the file browser. */ +#endif + #if !defined(DISABLE_BROWSER) || (!defined(DISABLE_MOUSE) && defined(NCURSES_MOUSE_VERSION)) currshortcut = insertfile_list; #endif @@ -473,55 +477,46 @@ int do_insertfile(int loading_file) fprintf(stderr, _("filename is %s\n"), answer); #endif - realname = real_dir_from_tilde(answer); - -#ifndef DISABLE_BROWSER - if (i == NANO_TOFILES_KEY) { - char *tmp = do_browse_from(realname); - -#if !defined(DISABLE_HELP) || (!defined(DISABLE_MOUSE) && defined(NCURSES_MOUSE_VERSION)) - currshortcut = insertfile_list; -#endif -#ifdef DISABLE_TABCOMP - realname = NULL; -#endif - if (tmp != NULL) { - free(realname); - realname = tmp; - } else - return do_insertfile(loading_file); - } -#endif - -#ifndef DISABLE_OPERATINGDIR - if (operating_dir != NULL && check_operating_dir(realname, 0)) { - statusbar(_("Can't insert file from outside of %s"), - operating_dir); - return 0; - } -#endif - #ifndef NANO_SMALL #ifdef ENABLE_MULTIBUFFER if (i == TOGGLE_LOAD_KEY) { - /* don't allow toggling if we're in both view mode and - multibuffer mode now */ - if (!ISSET(VIEW_MODE) || !ISSET(MULTIBUFFER)) + /* Don't allow toggling if we're in view mode. */ + if (!ISSET(VIEW_MODE)) TOGGLE(MULTIBUFFER); - return do_insertfile(ISSET(MULTIBUFFER)); + loading_file = ISSET(MULTIBUFFER); + goto start_again; } #endif /* ENABLE_MULTIBUFFER */ + if (i == NANO_EXTCMD_KEY) { - int ts; - ts = statusq(1, extcmd_list, "", 0, _("Command to execute ")); - if (ts == -1 || answer == NULL || answer[0] == '\0') { - statusbar(_("Cancelled")); + int ts = statusq(TRUE, extcmd_list, "", NULL, + _("Command to execute")); + if (ts == -1 || answer == NULL || answer[0] == '\0') { + statusbar("Cancelled"); UNSET(KEEP_CUTBUFFER); display_main_list(); return 0; } } #endif /* !NANO_SMALL */ +#ifndef DISABLE_BROWSER + if (i == NANO_TOFILES_KEY) { + char *tmp = do_browse_from(answer); + + if (tmp != NULL) + answer = tmp; + else + goto start_again; + } +#endif + +#ifndef DISABLE_OPERATINGDIR + if (i != NANO_EXTCMD_KEY && check_operating_dir(answer, FALSE)) { + statusbar(_("Can't insert file from outside of %s"), + operating_dir); + return 0; + } +#endif #ifdef ENABLE_MULTIBUFFER if (loading_file) { @@ -536,11 +531,15 @@ int do_insertfile(int loading_file) #endif #ifndef NANO_SMALL - if (i == NANO_EXTCMD_KEY) + if (i == NANO_EXTCMD_KEY) { + realname = mallocstrcpy(realname, ""); i = open_pipe(answer); - else + } else #endif /* NANO_SMALL */ + { + realname = real_dir_from_tilde(answer); i = open_file(realname, 1, loading_file); + } #ifdef ENABLE_MULTIBUFFER if (loading_file) {