rc

[fork] interactive rc shell
Log | Files | Refs | README | LICENSE

commit cb99a1b11a2f0d39cd92a27351a4920422bcd7a1
parent f26b1b7d1311c34b1ed4ec29b5d26e3ae421873b
Author: Toby Goodwin <toby@paganbooks.eu>
Date:   Sat, 28 Apr 2018 07:46:54 +0100

eliminate goto... clearer?

Diffstat:
Medit-readline.c | 26+++++++++++---------------
1 file changed, 11 insertions(+), 15 deletions(-)

diff --git a/edit-readline.c b/edit-readline.c @@ -20,31 +20,27 @@ static char *compl_extcmd(const char *text, int state) { static DIR *d; static List *path; static size_t len; - char *name = NULL; if (!state) { d = NULL; path = varlookup("path"); len = strlen(text); } -nextdir: - while (d == NULL) { - if (path == NULL) - return NULL; - d = opendir(path->w); - path = path->n; - } - while (name == NULL) { - struct dirent *e = readdir(d); - if (e == NULL) { + while (d || path) { + if (!d) + d = opendir(path->w); + else { + struct dirent *e; + while ((e = readdir(d))) { + if (strncmp(e->d_name, text, len) == 0) + return strdup(e->d_name); + } closedir(d); d = NULL; - goto nextdir; + path = path->n; } - if (strncmp(e->d_name, text, len) == 0) - name = strdup(e->d_name); } - return name; + return NULL; } static rl_compentry_func_t *const compl_cmd_funcs[] = {