Commit d3bd855c authored by Benno Schulenberg's avatar Benno Schulenberg
Browse files

tweaks: rename a function, and move the sorting there too

parent bd3f1560
Showing with 11 additions and 12 deletions
+11 -12
......@@ -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. */
......
......@@ -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);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment