tweaks: rename and shorten a small helper function
parent
6d873d3760
commit
f48e15f2a3
|
@ -297,7 +297,7 @@ char *do_browser(char *path)
|
|||
/* If we are moving up one level, remember where we came from, so
|
||||
* this directory can be highlighted and easily reentered. */
|
||||
if (strcmp(tail(filelist[selected]), "..") == 0)
|
||||
present_name = striponedir(filelist[selected]);
|
||||
present_name = strip_last_component(filelist[selected]);
|
||||
|
||||
/* Try opening and reading the selected directory. */
|
||||
path = mallocstrcpy(path, filelist[selected]);
|
||||
|
@ -353,7 +353,7 @@ char *do_browse_from(const char *inpath)
|
|||
* at all. If so, we'll just pass the current directory to
|
||||
* do_browser(). */
|
||||
if (stat(path, &st) == -1 || !S_ISDIR(st.st_mode)) {
|
||||
path = free_and_assign(path, striponedir(path));
|
||||
path = free_and_assign(path, strip_last_component(path));
|
||||
|
||||
if (stat(path, &st) == -1 || !S_ISDIR(st.st_mode)) {
|
||||
char * currentdir = charalloc(PATH_MAX + 1);
|
||||
|
@ -781,21 +781,17 @@ void do_last_file(void)
|
|||
selected = filelist_len - 1;
|
||||
}
|
||||
|
||||
/* Strip one directory from the end of path, and return the stripped
|
||||
* path. The returned string is dynamically allocated, and should be
|
||||
* freed. */
|
||||
char *striponedir(const char *path)
|
||||
/* Strip one element from the end of path, and return the stripped path.
|
||||
* The returned string is dynamically allocated, and should be freed. */
|
||||
char *strip_last_component(const char *path)
|
||||
{
|
||||
char *retval, *tmp;
|
||||
char *copy = mallocstrcpy(NULL, path);
|
||||
char *last_slash = strrchr(copy, '/');
|
||||
|
||||
retval = mallocstrcpy(NULL, path);
|
||||
if (last_slash != NULL)
|
||||
*last_slash = '\0';
|
||||
|
||||
tmp = strrchr(retval, '/');
|
||||
|
||||
if (tmp != NULL)
|
||||
null_at(&retval, tmp - retval);
|
||||
|
||||
return retval;
|
||||
return copy;
|
||||
}
|
||||
|
||||
#endif /* !DISABLE_BROWSER */
|
||||
|
|
|
@ -178,7 +178,7 @@ void do_filesearch(void);
|
|||
void do_fileresearch(void);
|
||||
void do_first_file(void);
|
||||
void do_last_file(void);
|
||||
char *striponedir(const char *path);
|
||||
char *strip_last_component(const char *path);
|
||||
#endif
|
||||
|
||||
/* Most functions in chars.c. */
|
||||
|
|
Loading…
Reference in New Issue