summaryrefslogtreecommitdiff
path: root/common/cmd_nvedit.c
diff options
context:
space:
mode:
Diffstat (limited to 'common/cmd_nvedit.c')
-rw-r--r--common/cmd_nvedit.c104
1 files changed, 60 insertions, 44 deletions
diff --git a/common/cmd_nvedit.c b/common/cmd_nvedit.c
index 3ee971a..2186205 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;
-
- 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<nxt; ++k)
- putc(env_get_char(k));
- putc ('\n');
-
- if (ctrlc()) {
- puts ("\n ** Abort\n");
- return 1;
+ int i, j;
+ char c, buf[17];
+
+ i = 0;
+ buf[16] = '\0';
+
+ while (state && env_get_char(i) != '\0') {
+ if (state == 2 && envmatch((uchar *)name, i) >= 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');
- printf("\nEnvironment size: %d/%ld bytes\n",
- i, (ulong)ENV_SIZE);
+ if (state <= 1) {
+ if (j)
+ puts(buf);
+ putc('\n');
+ }
- return 0;
+ if (ctrlc())
+ return -1;
}
- for (i=1; i<argc; ++i) { /* print single env variables */
- char *name = argv[i];
+ if (state == 0)
+ i = 0;
+ return i;
+}
- k = -1;
+int do_printenv (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
+{
+ int i;
+ int rcode = 0;
- for (j=0; env_get_char(j) != '\0'; j=nxt+1) {
+ 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 (nxt=j; env_get_char(nxt) != '\0'; ++nxt)
- ;
- k = envmatch((uchar *)name, j);
- if (k < 0) {
- continue;
- }
- puts (name);
- putc ('=');
- while (k < nxt)
- putc(env_get_char(k++));
- putc ('\n');
- break;
- }
- if (k < 0) {
- printf ("## Error: \"%s\" not defined\n", name);
- rcode ++;
+ /* print selected env vars */
+ for (i = 1; i < argc; ++i) {
+ char *name = argv[i];
+ if (printenv(name, 2)) {
+ printf("## Error: \"%s\" not defined\n", name);
+ ++rcode;
}
}
+
return rcode;
}
@@ -553,7 +569,7 @@ int do_saveenv (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
U_BOOT_CMD(
saveenv, 1, 0, do_saveenv,
"save environment variables to persistent storage",
- NULL
+ ""
);
#endif
@@ -586,7 +602,7 @@ U_BOOT_CMD(
"print environment variables",
"\n - print values of all environment variables\n"
"printenv name ...\n"
- " - print value of environment variable 'name'\n"
+ " - print value of environment variable 'name'"
);
U_BOOT_CMD(
@@ -595,7 +611,7 @@ U_BOOT_CMD(
"name value ...\n"
" - set environment variable 'name' to 'value ...'\n"
"setenv name\n"
- " - delete environment variable 'name'\n"
+ " - delete environment variable 'name'"
);
#if defined(CONFIG_CMD_ASKENV)
@@ -611,7 +627,7 @@ U_BOOT_CMD(
" - get environment variable 'name' from stdin (max 'size' chars)\n"
"askenv name [message] size\n"
" - display 'message' string and get environment variable 'name'"
- "from stdin (max 'size' chars)\n"
+ "from stdin (max 'size' chars)"
);
#endif
@@ -621,6 +637,6 @@ U_BOOT_CMD(
run, CONFIG_SYS_MAXARGS, 1, do_run,
"run commands in an environment variable",
"var [...]\n"
- " - run the commands in the environment variable(s) 'var'\n"
+ " - run the commands in the environment variable(s) 'var'"
);
#endif