diff --git a/common/cmd_nvedit.c b/common/cmd_nvedit.c index 3ee971ab0..ac9e5cfc3 100644 --- a/common/cmd_nvedit.c +++ b/common/cmd_nvedit.c @@ -94,56 +94,72 @@ int get_env_id (void) * Command interface: print one or all environment variables */ -int do_printenv (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) +/* + * state 0: finish printing this string and return (matched!) + * state 1: no matching to be done; print everything + * state 2: continue searching for matched name + */ +static int printenv(char *name, int state) { - int i, j, k, nxt; - int rcode = 0; + int i, j; + char c, buf[17]; - if (argc == 1) { /* Print all env variables */ - for (i=0; env_get_char(i) != '\0'; i=nxt+1) { - for (nxt=i; env_get_char(nxt) != '\0'; ++nxt) - ; - for (k=i; k= 0) + state = 0; + + j = 0; + do { + buf[j++] = c = env_get_char(i++); + if (j == sizeof(buf) - 1) { + if (state <= 1) + puts(buf); + j = 0; } + } while (c != '\0'); + + if (state <= 1) { + if (j) + puts(buf); + putc('\n'); } - printf("\nEnvironment size: %d/%ld bytes\n", - i, (ulong)ENV_SIZE); + if (ctrlc()) + return -1; + } + if (state == 0) + i = 0; + return i; +} + +int do_printenv (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) +{ + int i; + int rcode = 0; + + if (argc == 1) { + /* print all env vars */ + rcode = printenv(NULL, 1); + if (rcode < 0) + return 1; + printf("\nEnvironment size: %d/%ld bytes\n", + rcode, (ulong)ENV_SIZE); return 0; } - for (i=1; i