commit d3bd855c9dba0ffaf6f8d19c22832515006435d3
parent bd3f15604471261f0a7f8abac560a3b75c50be5b
Author: Benno Schulenberg <bensberg@justemail.net>
Date: Wed, 25 May 2016 12:09:22 +0200
tweaks: rename a function, and move the sorting there too
Diffstat:
2 files changed, 11 insertions(+), 12 deletions(-)
diff --git a/src/browser.c b/src/browser.c
@@ -83,15 +83,10 @@ char *do_browser(char *path)
assert(path != NULL && path[strlen(path) - 1] == '/');
/* Get the file list, and set longest and width in the process. */
- browser_init(path, dir);
+ read_the_list(path, dir);
closedir(dir);
- assert(filelist != NULL);
-
- /* Sort the file list. */
- qsort(filelist, filelist_len, sizeof(char *), diralphasort);
-
/* If given, reselect the present_name and then discard it. */
if (present_name != NULL) {
browser_select_dirname(present_name);
@@ -419,10 +414,8 @@ char *do_browse_from(const char *inpath)
* set filelist_len to the number of files in that list, set longest to
* the width in columns of the longest filename in that list (between 15
* and COLS), and set width to the number of files that we can display
- * per line. longest needs to be at least 15 columns in order to
- * display ".. (parent dir)", as Pico does. Assume path exists and is a
- * directory. */
-void browser_init(const char *path, DIR *dir)
+ * per line. And sort the list too. */
+void read_the_list(const char *path, DIR *dir)
{
const struct dirent *nextdir;
size_t i = 0, path_len = strlen(path);
@@ -445,9 +438,10 @@ void browser_init(const char *path, DIR *dir)
* in the list whenever possible, as Pico does. */
longest += 10;
- /* Make sure longest is between 15 and COLS. */
+ /* If needed, make room for ".. (parent dir)". */
if (longest < 15)
longest = 15;
+ /* Make sure we're not wider than the window. */
if (longest > COLS)
longest = COLS;
@@ -477,6 +471,11 @@ void browser_init(const char *path, DIR *dir)
* filelist, so record it. */
filelist_len = i;
+ assert(filelist != NULL);
+
+ /* Sort the list of names. */
+ qsort(filelist, filelist_len, sizeof(char *), diralphasort);
+
/* Calculate how many files fit on a line -- feigning room for two
* spaces beyond the right edge, and adding two spaces of padding
* between columns. */
diff --git a/src/proto.h b/src/proto.h
@@ -152,7 +152,7 @@ typedef void (*functionptrtype)(void);
#ifndef DISABLE_BROWSER
char *do_browser(char *path);
char *do_browse_from(const char *inpath);
-void browser_init(const char *path, DIR *dir);
+void read_the_list(const char *path, DIR *dir);
functionptrtype parse_browser_input(int *kbinput);
void browser_refresh(void);
void browser_select_dirname(const char *needle);