diff options
| author | Toby Goodwin <toby@paganbooks.eu> | 2018-04-28 07:46:54 +0100 |
|---|---|---|
| committer | Toby Goodwin <toby@paganbooks.eu> | 2018-04-28 07:53:50 +0100 |
| commit | cb99a1b11a2f0d39cd92a27351a4920422bcd7a1 (patch) | |
| tree | 36796cea42374e45b9fdd1eef9b0a435062ac865 | |
| parent | f26b1b7d1311c34b1ed4ec29b5d26e3ae421873b (diff) | |
eliminate goto... clearer?
| -rw-r--r-- | edit-readline.c | 26 |
1 files changed, 11 insertions, 15 deletions
diff --git a/edit-readline.c b/edit-readline.c index 58b686e..4a80044 100644 --- 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[] = { |