tweaks: rename a function, and move the sorting there too
parent
bd3f156044
commit
d3bd855c9d
|
@ -83,15 +83,10 @@ char *do_browser(char *path)
|
||||||
assert(path != NULL && path[strlen(path) - 1] == '/');
|
assert(path != NULL && path[strlen(path) - 1] == '/');
|
||||||
|
|
||||||
/* Get the file list, and set longest and width in the process. */
|
/* Get the file list, and set longest and width in the process. */
|
||||||
browser_init(path, dir);
|
read_the_list(path, dir);
|
||||||
|
|
||||||
closedir(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 given, reselect the present_name and then discard it. */
|
||||||
if (present_name != NULL) {
|
if (present_name != NULL) {
|
||||||
browser_select_dirname(present_name);
|
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
|
* 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
|
* 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
|
* 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
|
* per line. And sort the list too. */
|
||||||
* display ".. (parent dir)", as Pico does. Assume path exists and is a
|
void read_the_list(const char *path, DIR *dir)
|
||||||
* directory. */
|
|
||||||
void browser_init(const char *path, DIR *dir)
|
|
||||||
{
|
{
|
||||||
const struct dirent *nextdir;
|
const struct dirent *nextdir;
|
||||||
size_t i = 0, path_len = strlen(path);
|
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. */
|
* in the list whenever possible, as Pico does. */
|
||||||
longest += 10;
|
longest += 10;
|
||||||
|
|
||||||
/* Make sure longest is between 15 and COLS. */
|
/* If needed, make room for ".. (parent dir)". */
|
||||||
if (longest < 15)
|
if (longest < 15)
|
||||||
longest = 15;
|
longest = 15;
|
||||||
|
/* Make sure we're not wider than the window. */
|
||||||
if (longest > COLS)
|
if (longest > COLS)
|
||||||
longest = COLS;
|
longest = COLS;
|
||||||
|
|
||||||
|
@ -477,6 +471,11 @@ void browser_init(const char *path, DIR *dir)
|
||||||
* filelist, so record it. */
|
* filelist, so record it. */
|
||||||
filelist_len = i;
|
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
|
/* Calculate how many files fit on a line -- feigning room for two
|
||||||
* spaces beyond the right edge, and adding two spaces of padding
|
* spaces beyond the right edge, and adding two spaces of padding
|
||||||
* between columns. */
|
* between columns. */
|
||||||
|
|
|
@ -152,7 +152,7 @@ typedef void (*functionptrtype)(void);
|
||||||
#ifndef DISABLE_BROWSER
|
#ifndef DISABLE_BROWSER
|
||||||
char *do_browser(char *path);
|
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 read_the_list(const char *path, DIR *dir);
|
||||||
functionptrtype parse_browser_input(int *kbinput);
|
functionptrtype parse_browser_input(int *kbinput);
|
||||||
void browser_refresh(void);
|
void browser_refresh(void);
|
||||||
void browser_select_dirname(const char *needle);
|
void browser_select_dirname(const char *needle);
|
||||||
|
|
Loading…
Reference in New Issue