tweaks: rename two functions, and rename and reshuffle a parameter
Also, drop an unneeded nulling: the function copy_of() already NUL-terminates the copied string.master
parent
26d7a7494e
commit
9faa95450b
21
src/files.c
21
src/files.c
|
@ -2363,8 +2363,7 @@ bool is_dir(const char *path)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Try to complete the given fragment in 'buf' to a username. */
|
/* Try to complete the given fragment in 'buf' to a username. */
|
||||||
char **username_tab_completion(const char *buf, size_t *num_matches,
|
char **username_completion(const char *buf, size_t length, size_t *num_matches)
|
||||||
size_t buf_len)
|
|
||||||
{
|
{
|
||||||
char **matches = NULL;
|
char **matches = NULL;
|
||||||
#ifdef HAVE_PWD_H
|
#ifdef HAVE_PWD_H
|
||||||
|
@ -2373,7 +2372,7 @@ char **username_tab_completion(const char *buf, size_t *num_matches,
|
||||||
/* Iterate through the entries in the passwd file, and
|
/* Iterate through the entries in the passwd file, and
|
||||||
* add each fitting username to the list of matches. */
|
* add each fitting username to the list of matches. */
|
||||||
while ((userdata = getpwent()) != NULL) {
|
while ((userdata = getpwent()) != NULL) {
|
||||||
if (strncmp(userdata->pw_name, buf + 1, buf_len - 1) == 0) {
|
if (strncmp(userdata->pw_name, buf + 1, length - 1) == 0) {
|
||||||
#ifdef ENABLE_OPERATINGDIR
|
#ifdef ENABLE_OPERATINGDIR
|
||||||
/* Skip directories that are outside of the allowed area. */
|
/* Skip directories that are outside of the allowed area. */
|
||||||
if (outside_of_confinement(userdata->pw_dir, TRUE))
|
if (outside_of_confinement(userdata->pw_dir, TRUE))
|
||||||
|
@ -2407,8 +2406,8 @@ char **username_tab_completion(const char *buf, size_t *num_matches,
|
||||||
* This code may safely be consumed by a BSD or GPL license. */
|
* This code may safely be consumed by a BSD or GPL license. */
|
||||||
|
|
||||||
/* Try to complete the given fragment in 'buf' to a filename. */
|
/* Try to complete the given fragment in 'buf' to a filename. */
|
||||||
char **cwd_tab_completion(const char *buf, bool allow_files,
|
char **filename_completion(const char *buf, size_t length,
|
||||||
size_t *num_matches, size_t buf_len)
|
bool allow_files, size_t *num_matches)
|
||||||
{
|
{
|
||||||
char *dirname = copy_of(buf);
|
char *dirname = copy_of(buf);
|
||||||
char *slash, *filename;
|
char *slash, *filename;
|
||||||
|
@ -2417,8 +2416,6 @@ char **cwd_tab_completion(const char *buf, bool allow_files,
|
||||||
DIR *dir;
|
DIR *dir;
|
||||||
const struct dirent *nextdir;
|
const struct dirent *nextdir;
|
||||||
|
|
||||||
dirname[buf_len] = '\0';
|
|
||||||
|
|
||||||
/* If there's a / in the name, split out filename and directory parts. */
|
/* If there's a / in the name, split out filename and directory parts. */
|
||||||
slash = strrchr(dirname, '/');
|
slash = strrchr(dirname, '/');
|
||||||
if (slash != NULL) {
|
if (slash != NULL) {
|
||||||
|
@ -2430,8 +2427,7 @@ char **cwd_tab_completion(const char *buf, bool allow_files,
|
||||||
dirname = real_dir_from_tilde(dirname);
|
dirname = real_dir_from_tilde(dirname);
|
||||||
/* A non-absolute path is relative to the current browser directory. */
|
/* A non-absolute path is relative to the current browser directory. */
|
||||||
if (dirname[0] != '/') {
|
if (dirname[0] != '/') {
|
||||||
dirname = charealloc(dirname, strlen(present_path) +
|
dirname = charealloc(dirname, strlen(present_path) + strlen(wasdirname) + 1);
|
||||||
strlen(wasdirname) + 1);
|
|
||||||
sprintf(dirname, "%s%s", present_path, wasdirname);
|
sprintf(dirname, "%s%s", present_path, wasdirname);
|
||||||
}
|
}
|
||||||
free(wasdirname);
|
free(wasdirname);
|
||||||
|
@ -2443,7 +2439,6 @@ char **cwd_tab_completion(const char *buf, bool allow_files,
|
||||||
dir = opendir(dirname);
|
dir = opendir(dirname);
|
||||||
|
|
||||||
if (dir == NULL) {
|
if (dir == NULL) {
|
||||||
/* Don't print an error, just shut up and return. */
|
|
||||||
beep();
|
beep();
|
||||||
free(filename);
|
free(filename);
|
||||||
free(dirname);
|
free(dirname);
|
||||||
|
@ -2489,7 +2484,7 @@ char **cwd_tab_completion(const char *buf, bool allow_files,
|
||||||
|
|
||||||
/* Do tab completion. 'place' is the position of the status-bar cursor, and
|
/* Do tab completion. 'place' is the position of the status-bar cursor, and
|
||||||
* 'refresh_func' is the function to be called to refresh the edit window. */
|
* 'refresh_func' is the function to be called to refresh the edit window. */
|
||||||
char *input_tab(char *buf, bool allow_files, size_t *place,
|
char *input_tab(char *buf, size_t *place, bool allow_files,
|
||||||
bool *lastwastab, void (*refresh_func)(void), bool *listed)
|
bool *lastwastab, void (*refresh_func)(void), bool *listed)
|
||||||
{
|
{
|
||||||
size_t num_matches = 0;
|
size_t num_matches = 0;
|
||||||
|
@ -2506,12 +2501,12 @@ char *input_tab(char *buf, bool allow_files, size_t *place,
|
||||||
/* If the fragment starts with a tilde and contains no slash,
|
/* If the fragment starts with a tilde and contains no slash,
|
||||||
* then try completing it as a username. */
|
* then try completing it as a username. */
|
||||||
if (buf[0] == '~' && strchr(buf, '/') == NULL)
|
if (buf[0] == '~' && strchr(buf, '/') == NULL)
|
||||||
matches = username_tab_completion(buf, &num_matches, *place);
|
matches = username_completion(buf, *place, &num_matches);
|
||||||
|
|
||||||
/* If there are no matches yet, try matching against filenames
|
/* If there are no matches yet, try matching against filenames
|
||||||
* in the current directory. */
|
* in the current directory. */
|
||||||
if (matches == NULL)
|
if (matches == NULL)
|
||||||
matches = cwd_tab_completion(buf, allow_files, &num_matches, *place);
|
matches = filename_completion(buf, *place, allow_files, &num_matches);
|
||||||
|
|
||||||
if (num_matches == 0)
|
if (num_matches == 0)
|
||||||
beep();
|
beep();
|
||||||
|
|
|
@ -471,7 +471,7 @@ functionptrtype acquire_an_answer(int *actual, bool allow_tabs,
|
||||||
} else
|
} else
|
||||||
#endif
|
#endif
|
||||||
if (allow_tabs)
|
if (allow_tabs)
|
||||||
answer = input_tab(answer, allow_files, &typing_x,
|
answer = input_tab(answer, &typing_x, allow_files,
|
||||||
&tabbed, refresh_func, listed);
|
&tabbed, refresh_func, listed);
|
||||||
} else
|
} else
|
||||||
#endif /* ENABLE_TABCOMP */
|
#endif /* ENABLE_TABCOMP */
|
||||||
|
|
|
@ -323,7 +323,7 @@ char *real_dir_from_tilde(const char *buf);
|
||||||
int diralphasort(const void *va, const void *vb);
|
int diralphasort(const void *va, const void *vb);
|
||||||
#endif
|
#endif
|
||||||
#ifdef ENABLE_TABCOMP
|
#ifdef ENABLE_TABCOMP
|
||||||
char *input_tab(char *buf, bool allow_files, size_t *place,
|
char *input_tab(char *buf, size_t *place, bool allow_files,
|
||||||
bool *lastwastab, void (*refresh_func)(void), bool *listed);
|
bool *lastwastab, void (*refresh_func)(void), bool *listed);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue