add miscellaneous minor cleanups to do_browser(), do_browse_from(), and
browser_init() git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@3775 35c25a1d-7b9e-4130-9fde-d3aeb78583b8master
parent
35c9fa6da3
commit
87b37bde9b
|
@ -34,6 +34,8 @@ CVS code -
|
||||||
- After entering "..", select the directory we were in before
|
- After entering "..", select the directory we were in before
|
||||||
instead of the first filename in the list, as Pico does. (DLR)
|
instead of the first filename in the list, as Pico does. (DLR)
|
||||||
- Simplify screen update handling and exiting. (DLR)
|
- Simplify screen update handling and exiting. (DLR)
|
||||||
|
- Move the opening of path here from do_browse_from(), so that
|
||||||
|
we no longer need a DIR* parameter. (DLR)
|
||||||
do_browse_from()
|
do_browse_from()
|
||||||
- During the operating directory check, if path isn't NULL,
|
- During the operating directory check, if path isn't NULL,
|
||||||
don't bother freeing it before mallocstrcpy()ing operating_dir
|
don't bother freeing it before mallocstrcpy()ing operating_dir
|
||||||
|
@ -43,6 +45,8 @@ CVS code -
|
||||||
rightmost column of the screen from being used. (DLR)
|
rightmost column of the screen from being used. (DLR)
|
||||||
- Calculate width here instead of in browser_refresh(), as it's
|
- Calculate width here instead of in browser_refresh(), as it's
|
||||||
more consistent. (DLR)
|
more consistent. (DLR)
|
||||||
|
- If filelist is initialized, free it here instead of in several
|
||||||
|
places in do_browser(). (DLR)
|
||||||
browser_refresh()
|
browser_refresh()
|
||||||
- Simplify. (DLR)
|
- Simplify. (DLR)
|
||||||
- Fix problems where translated versions of "(dir)" could be
|
- Fix problems where translated versions of "(dir)" could be
|
||||||
|
|
|
@ -46,7 +46,7 @@ static bool search_last_file = FALSE;
|
||||||
|
|
||||||
/* Our main file browser function. path is the tilde-expanded path to
|
/* Our main file browser function. path is the tilde-expanded path to
|
||||||
* start browsing from. */
|
* start browsing from. */
|
||||||
char *do_browser(char *path, DIR *dir)
|
char *do_browser(char *path)
|
||||||
{
|
{
|
||||||
char *retval = NULL;
|
char *retval = NULL;
|
||||||
int kbinput;
|
int kbinput;
|
||||||
|
@ -56,10 +56,17 @@ char *do_browser(char *path, DIR *dir)
|
||||||
char *prev_dir = NULL;
|
char *prev_dir = NULL;
|
||||||
/* The directory we were in, if any, before backing up via
|
/* The directory we were in, if any, before backing up via
|
||||||
* browsing to "..". */
|
* browsing to "..". */
|
||||||
char *ans = mallocstrcpy(NULL, "");
|
char *ans = NULL;
|
||||||
/* The last answer the user typed on the statusbar. */
|
/* The last answer the user typed on the statusbar. */
|
||||||
size_t old_selected;
|
size_t old_selected;
|
||||||
/* The selected file we had before the current selected file. */
|
/* The selected file we had before the current selected file. */
|
||||||
|
DIR *dir;
|
||||||
|
|
||||||
|
/* If we have no path, or we can't open it, get out. */
|
||||||
|
if (path == NULL || (dir = opendir(path)) == NULL) {
|
||||||
|
beep();
|
||||||
|
goto cleanup_browser;
|
||||||
|
}
|
||||||
|
|
||||||
curs_set(0);
|
curs_set(0);
|
||||||
blank_statusbar();
|
blank_statusbar();
|
||||||
|
@ -71,6 +78,8 @@ char *do_browser(char *path, DIR *dir)
|
||||||
|
|
||||||
UNSET(CONST_UPDATE);
|
UNSET(CONST_UPDATE);
|
||||||
|
|
||||||
|
ans = mallocstrcpy(NULL, "");
|
||||||
|
|
||||||
change_browser_directory:
|
change_browser_directory:
|
||||||
/* We go here after we select a new directory. */
|
/* We go here after we select a new directory. */
|
||||||
|
|
||||||
|
@ -281,7 +290,6 @@ char *do_browser(char *path, DIR *dir)
|
||||||
/* Start over again with the new path value. */
|
/* Start over again with the new path value. */
|
||||||
free(path);
|
free(path);
|
||||||
path = new_path;
|
path = new_path;
|
||||||
free_chararray(filelist, filelist_len);
|
|
||||||
goto change_browser_directory;
|
goto change_browser_directory;
|
||||||
case NANO_PREVLINE_KEY:
|
case NANO_PREVLINE_KEY:
|
||||||
if (selected >= width)
|
if (selected >= width)
|
||||||
|
@ -355,7 +363,6 @@ char *do_browser(char *path, DIR *dir)
|
||||||
path = mallocstrcpy(path, filelist[selected]);
|
path = mallocstrcpy(path, filelist[selected]);
|
||||||
|
|
||||||
/* Start over again with the new path value. */
|
/* Start over again with the new path value. */
|
||||||
free_chararray(filelist, filelist_len);
|
|
||||||
goto change_browser_directory;
|
goto change_browser_directory;
|
||||||
/* Abort the file browser. */
|
/* Abort the file browser. */
|
||||||
case NANO_EXIT_KEY:
|
case NANO_EXIT_KEY:
|
||||||
|
@ -370,10 +377,16 @@ char *do_browser(char *path, DIR *dir)
|
||||||
if (old_const_update)
|
if (old_const_update)
|
||||||
SET(CONST_UPDATE);
|
SET(CONST_UPDATE);
|
||||||
|
|
||||||
/* Clean up. */
|
cleanup_browser:
|
||||||
free(path);
|
if (path != NULL)
|
||||||
free(ans);
|
free(path);
|
||||||
free_chararray(filelist, filelist_len);
|
if (ans != NULL)
|
||||||
|
free(ans);
|
||||||
|
if (filelist != NULL) {
|
||||||
|
free_chararray(filelist, filelist_len);
|
||||||
|
filelist = NULL;
|
||||||
|
filelist_len = 0;
|
||||||
|
}
|
||||||
|
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
@ -386,7 +399,6 @@ char *do_browse_from(const char *inpath)
|
||||||
struct stat st;
|
struct stat st;
|
||||||
char *path;
|
char *path;
|
||||||
/* This holds the tilde-expanded version of inpath. */
|
/* This holds the tilde-expanded version of inpath. */
|
||||||
DIR *dir = NULL;
|
|
||||||
|
|
||||||
assert(inpath != NULL);
|
assert(inpath != NULL);
|
||||||
|
|
||||||
|
@ -419,16 +431,7 @@ char *do_browse_from(const char *inpath)
|
||||||
path = mallocstrcpy(path, operating_dir);
|
path = mallocstrcpy(path, operating_dir);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (path != NULL)
|
return do_browser(path);
|
||||||
dir = opendir(path);
|
|
||||||
|
|
||||||
if (dir == NULL) {
|
|
||||||
beep();
|
|
||||||
free(path);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
return do_browser(path, dir);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Set filelist to the list of files contained in the directory path,
|
/* Set filelist to the list of files contained in the directory path,
|
||||||
|
@ -470,14 +473,17 @@ void browser_init(const char *path, DIR *dir)
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
filelist_len = i;
|
|
||||||
|
|
||||||
rewinddir(dir);
|
rewinddir(dir);
|
||||||
|
|
||||||
/* Put 10 columns' worth of blank space between columns of filenames
|
/* Put 10 columns' worth of blank space between columns of filenames
|
||||||
* in the list whenever possible, as Pico does. */
|
* in the list whenever possible, as Pico does. */
|
||||||
longest += 10;
|
longest += 10;
|
||||||
|
|
||||||
|
if (filelist != NULL)
|
||||||
|
free_chararray(filelist, filelist_len);
|
||||||
|
|
||||||
|
filelist_len = i;
|
||||||
|
|
||||||
filelist = (char **)nmalloc(filelist_len * sizeof(char *));
|
filelist = (char **)nmalloc(filelist_len * sizeof(char *));
|
||||||
|
|
||||||
i = 0;
|
i = 0;
|
||||||
|
|
|
@ -143,7 +143,7 @@ extern char *homedir;
|
||||||
|
|
||||||
/* Public functions in browser.c. */
|
/* Public functions in browser.c. */
|
||||||
#ifndef DISABLE_BROWSER
|
#ifndef DISABLE_BROWSER
|
||||||
char *do_browser(char *path, DIR *dir);
|
char *do_browser(char *path);
|
||||||
char *do_browse_from(const char *inpath);
|
char *do_browse_from(const char *inpath);
|
||||||
void browser_init(const char *path, DIR *dir);
|
void browser_init(const char *path, DIR *dir);
|
||||||
void parse_browser_input(int *kbinput, bool *meta_key, bool *func_key);
|
void parse_browser_input(int *kbinput, bool *meta_key, bool *func_key);
|
||||||
|
|
Loading…
Reference in New Issue