}
#ifdef CONFIG_CMD_GREPENV
-static int do_env_grep (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+static int do_env_grep(cmd_tbl_t *cmdtp, int flag,
+ int argc, char * const argv[])
{
ENTRY *match;
unsigned char matched[env_htab.size / 8];
while (arg <= argc) {
idx = 0;
- while ((idx = hstrstr_r(argv[arg], idx, &match, &env_htab))) {
+ while (idx = hstrstr_r(argv[arg], idx, &match, &env_htab)) {
if (!(matched[idx / 8] & (1 << (idx & 7)))) {
puts(match->key);
puts("=");
* Set a new environment variable,
* or replace or delete an existing one.
*/
-
-int _do_env_set (int flag, int argc, char * const argv[])
+int _do_env_set(int flag, int argc, char * const argv[])
{
bd_t *bd = gd->bd;
int i, len;
name = argv[1];
if (strchr(name, '=')) {
- printf("## Error: illegal character '=' in variable name \"%s\"\n", name);
+ printf("## Error: illegal character '=' in variable name"
+ "\"%s\"\n", name);
return 1;
}
*/
if (ep) { /* variable exists */
#ifndef CONFIG_ENV_OVERWRITE
- if ((strcmp(name, "serial#") == 0) ||
- ((strcmp(name, "ethaddr") == 0)
+ if (strcmp(name, "serial#") == 0 ||
+ (strcmp(name, "ethaddr") == 0
#if defined(CONFIG_OVERWRITE_ETHADDR_ONCE) && defined(CONFIG_ETHADDR)
- && (strcmp(ep->data, MK_STR(CONFIG_ETHADDR)) != 0)
+ && strcmp(ep->data, MK_STR(CONFIG_ETHADDR)) != 0
#endif /* CONFIG_OVERWRITE_ETHADDR_ONCE && CONFIG_ETHADDR */
- ) ) {
+ )) {
printf("Can't overwrite \"%s\"\n", name);
return 1;
}
baudrate);
return 1;
}
- printf ("## Switch baudrate to %d bps and press ENTER ...\n",
- baudrate);
+ printf("## Switch baudrate to %d bps and"
+ "press ENTER ...\n", baudrate);
udelay(50000);
gd->baudrate = baudrate;
#if defined(CONFIG_PPC) || defined(CONFIG_MCF52x2)
serial_setbrg();
udelay(50000);
- for (;;) {
- if (getc() == '\r')
- break;
- }
+ while (getc() != '\r')
+ ;
}
}
/* Delete only ? */
- if ((argc < 3) || argv[2] == NULL) {
+ if (argc < 3 || argv[2] == NULL) {
int rc = hdelete_r(name, &env_htab);
return !rc;
}
while ((*s++ = *v++) != '\0')
;
- *(s-1) = ' ';
+ *(s - 1) = ' ';
}
if (s != value)
*--s = '\0';
- e.key = name;
- e.data = value;
+ e.key = name;
+ e.data = value;
hsearch_r(e, ENTER, &ep, &env_htab);
free(value);
if (!ep) {
* Some variables should be updated when the corresponding
* entry in the environment is changed
*/
-
if (strcmp(name, "ipaddr") == 0) {
char *s = argv[2]; /* always use only one arg */
char *e;
for (addr = 0, i = 0; i < 4; ++i) {
ulong val = s ? simple_strtoul(s, &e, 10) : 0;
addr <<= 8;
- addr |= (val & 0xFF);
- if (s) s = (*e) ? e+1 : e;
+ addr |= val & 0xFF;
+ if (s)
+ s = *e ? e + 1 : e;
}
bd->bi_ip_addr = htonl(addr);
return 0;
{
const char * const argv[4] = { "setenv", varname, varvalue, NULL };
- if ((varvalue == NULL) || (varvalue[0] == '\0'))
+ if (varvalue == NULL || varvalue[0] == '\0')
return _do_env_set(0, 2, (char * const *)argv);
else
return _do_env_set(0, 3, (char * const *)argv);
if (pos)
message[pos++] = ' ';
- strcpy(message+pos, argv[i]);
+ strcpy(message + pos, argv[i]);
pos += strlen(argv[i]);
}
+
message[pos] = '\0';
size = simple_strtoul(argv[argc - 1], NULL, 10);
break;
*/
char *getenv(const char *name)
{
- if (gd->flags & GD_FLG_ENV_READY) { /* after import into hashtable */
+ if (gd->flags & GD_FLG_ENV_READY) { /* after import into hashtable */
ENTRY e, *ep;
WATCHDOG_RESET();
- e.key = name;
- e.data = NULL;
+ e.key = name;
+ e.data = NULL;
hsearch_r(e, FIND, &ep, &env_htab);
return ep ? ep->data : NULL;
}
/* restricted capabilities before import */
-
if (getenv_f(name, (char *)(gd->env_buf), sizeof(gd->env_buf)) > 0)
return (char *)(gd->env_buf);
{
int i, nxt;
- for (i = 0; env_get_char(i) != '\0'; i = nxt+1) {
+ for (i = 0; env_get_char(i) != '\0'; i = nxt + 1) {
int val, n;
for (nxt = i; env_get_char(nxt) != '\0'; ++nxt) {
/* found; copy out */
for (n = 0; n < len; ++n, ++buf) {
- if ((*buf = env_get_char(val++)) == '\0')
+ *buf = env_get_char(val++);
+ if (*buf == '\0')
return n;
}
return n;
}
+
return -1;
}
}
#if defined(CONFIG_CMD_SAVEENV) && !defined(CONFIG_ENV_IS_NOWHERE)
-
int do_env_save(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
{
- extern char *env_name_spec;
-
printf("Saving Environment to %s...\n", env_name_spec);
return saveenv() ? 1 : 0;
"save environment variables to persistent storage",
""
);
-
#endif
*
* s1 is either a simple 'name', or a 'name=value' pair.
* i2 is the environment index for a 'name2=value2' pair.
- * If the names match, return the index for the value2, else NULL.
+ * If the names match, return the index for the value2, else -1.
*/
-
int envmatch(uchar *s1, int i2)
{
while (*s1 == env_get_char(i2++))
if (*s1++ == '=')
return i2;
+
if (*s1 == '\0' && env_get_char(i2-1) == '=')
return i2;
+
return -1;
}
-static int do_env_default(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+static int do_env_default(cmd_tbl_t *cmdtp, int flag,
+ int argc, char * const argv[])
{
- if ((argc != 2) || (strcmp(argv[1], "-f") != 0))
+ if (argc != 2 || strcmp(argv[1], "-f") != 0)
return cmd_usage(cmdtp);
set_default_env("## Resetting to default environment\n");
return 0;
}
-static int do_env_delete(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+static int do_env_delete(cmd_tbl_t *cmdtp, int flag,
+ int argc, char * const argv[])
{
printf("Not implemented yet\n");
return 0;
*
* => env import -d -t ${backup_addr}
*/
-static int do_env_export(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+static int do_env_export(cmd_tbl_t *cmdtp, int flag,
+ int argc, char * const argv[])
{
char buf[32];
char *addr, *cmd, *res;
if (sep) { /* export as text file */
len = hexport_r(&env_htab, sep, &addr, size, argc, argv);
if (len < 0) {
- error("Cannot export environment: errno = %d\n",
- errno);
+ error("Cannot export environment: errno = %d\n", errno);
return 1;
}
sprintf(buf, "%zX", (size_t)len);
len = hexport_r(&env_htab, '\0', &res, ENV_SIZE, argc, argv);
if (len < 0) {
- error("Cannot export environment: errno = %d\n",
- errno);
+ error("Cannot export environment: errno = %d\n", errno);
return 1;
}
if (chk) {
- envp->crc = crc32(0, envp->data, ENV_SIZE);
+ envp->crc = crc32(0, envp->data, ENV_SIZE);
#ifdef CONFIG_ENV_ADDR_REDUND
envp->flags = ACTIVE_FLAG;
#endif
return 0;
sep_err:
- printf("## %s: only one of \"-b\", \"-c\" or \"-t\" allowed\n",
- cmd);
+ printf("## %s: only one of \"-b\", \"-c\" or \"-t\" allowed\n", cmd);
return 1;
}
#endif
* size: length of input data; if missing, proper '\0'
* termination is mandatory
*/
-static int do_env_import(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+static int do_env_import(cmd_tbl_t *cmdtp, int flag,
+ int argc, char * const argv[])
{
char *cmd, *addr;
char sep = '\n';
}
#endif
-#if defined(CONFIG_CMD_RUN)
-extern int do_run(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
-#endif
-
/*
* New command line interface: "env" command with subcommands
*/