X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=common%2Fenv_common.c;h=19149b513dc0eb1a68f3b120c2e11ea23a754dff;hb=98e99e5a48e8eb3987c89f5316929313601ed7d6;hp=a276efc634717eb4740b4ce5351402eb3c6ee483;hpb=d75c2a3d7f34ff1eb9920ad72483cff7cb6d358f;p=u-boot diff --git a/common/env_common.c b/common/env_common.c index a276efc634..19149b513d 100644 --- a/common/env_common.c +++ b/common/env_common.c @@ -47,7 +47,7 @@ static uchar env_get_char_init (int index); #define XMK_STR(x) #x #define MK_STR(x) XMK_STR(x) -uchar default_environment[] = { +const uchar default_environment[] = { #ifdef CONFIG_BOOTARGS "bootargs=" CONFIG_BOOTARGS "\0" #endif @@ -129,6 +129,8 @@ uchar default_environment[] = { "\0" }; +struct hsearch_data env_htab; + static uchar env_get_char_init (int index) { uchar c; @@ -160,7 +162,7 @@ uchar env_get_char (int index) return (c); } -uchar *env_get_addr (int index) +const uchar *env_get_addr (int index) { if (gd->env_valid) return (uchar *)(gd->env_addr + index); @@ -187,7 +189,7 @@ void set_default_env(const char *s) puts("Using default environment\n\n"); } - if (himport((char *)default_environment, + if (himport_r(&env_htab, (char *)default_environment, sizeof(default_environment), '\0', 0) == 0) { error("Environment import failed: errno = %d\n", errno); } @@ -213,7 +215,7 @@ int env_import(const char *buf, int check) } } - if (himport((char *)ep->data, ENV_SIZE, '\0', 0)) { + if (himport_r(&env_htab, (char *)ep->data, ENV_SIZE, '\0', 0)) { gd->flags |= GD_FLG_ENV_READY; return 1; } @@ -244,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) { - - 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; + while ((idx = hmatch_r(var, idx, &match, &env_htab))) { + int vallen = strlen(match->key) + 1; - 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; }