diff options
author | Mike Frysinger <vapier@gentoo.org> | 2010-12-17 16:51:59 -0500 |
---|---|---|
committer | Wolfgang Denk <wd@denx.de> | 2011-01-09 17:57:37 +0100 |
commit | 560d424b6d7cd4205b062ad95f1b104bd4f8bcc3 (patch) | |
tree | 5a429e36ad18a8fa2e0b026d143c38d7f3d493af /common/env_common.c | |
parent | 42df1e1618f2bcae308ad193a136b72b82103bea (diff) | |
download | u-boot-imx-560d424b6d7cd4205b062ad95f1b104bd4f8bcc3.zip u-boot-imx-560d424b6d7cd4205b062ad95f1b104bd4f8bcc3.tar.gz u-boot-imx-560d424b6d7cd4205b062ad95f1b104bd4f8bcc3.tar.bz2 |
env: re-add support for auto-completion
Currently, only basic completion is supported (no globs), but this is
what we had previously.
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Diffstat (limited to 'common/env_common.c')
-rw-r--r-- | common/env_common.c | 40 |
1 files changed, 15 insertions, 25 deletions
diff --git a/common/env_common.c b/common/env_common.c index ae710e5..c3e6388 100644 --- a/common/env_common.c +++ b/common/env_common.c @@ -246,42 +246,32 @@ void env_relocate (void) } } -#if 0 /* need to reimplement - def CONFIG_AUTO_COMPLETE */ +#ifdef CONFIG_AUTO_COMPLETE int env_complete(char *var, int maxv, char *cmdv[], int bufsz, char *buf) { - int i, nxt, len, vallen, found; - const char *lval, *rval; + ENTRY *match; + int found, idx; + idx = 0; found = 0; cmdv[0] = NULL; - len = strlen(var); - /* now iterate over the variables and select those that match */ - for (i=0; env_get_char(i) != '\0'; i=nxt+1) { + while ((idx = hmatch_r(var, idx, &match, &env_htab))) { + int vallen = strlen(match->key) + 1; - for (nxt=i; env_get_char(nxt) != '\0'; ++nxt) - ; - - lval = (char *)env_get_addr(i); - rval = strchr(lval, '='); - if (rval != NULL) { - vallen = rval - lval; - rval++; - } else - vallen = strlen(lval); - - if (len > 0 && (vallen < len || memcmp(lval, var, len) != 0)) - continue; - - if (found >= maxv - 2 || bufsz < vallen + 1) { - cmdv[found++] = "..."; + if (found >= maxv - 2 || bufsz < vallen) break; - } + cmdv[found++] = buf; - memcpy(buf, lval, vallen); buf += vallen; bufsz -= vallen; - *buf++ = '\0'; bufsz--; + memcpy(buf, match->key, vallen); + buf += vallen; + bufsz -= vallen; } + qsort(cmdv, found, sizeof(cmdv[0]), strcmp_compar); + + if (idx) + cmdv[found++] = "..."; cmdv[found] = NULL; return found; } |