tools: env: split fw_string_blank into skip_chars / skip_blanks

Signed-off-by: Andreas Fenkart <andreas.fenkart@digitalstrom.com>
This commit is contained in:
Andreas Fenkart 2016-03-11 09:39:37 +01:00 committed by Tom Rini
parent 9583efcc74
commit 938c29ff41

23
tools/env/fw_env.c vendored
View file

@ -133,14 +133,19 @@ static inline ulong getenvsize (void)
return rc; return rc;
} }
static char *fw_string_blank(char *s, int noblank) static char *skip_chars(char *s)
{ {
int i; for (; *s != '\0'; s++) {
int len = strlen(s); if (isblank(*s))
return s;
}
return NULL;
}
for (i = 0; i < len; i++, s++) { static char *skip_blanks(char *s)
if ((noblank && !isblank(*s)) || {
(!noblank && isblank(*s))) for (; *s != '\0'; s++) {
if (!isblank(*s))
return s; return s;
} }
return NULL; return NULL;
@ -575,17 +580,17 @@ int fw_parse_script(char *fname)
* Search for variable's name, * Search for variable's name,
* remove leading whitespaces * remove leading whitespaces
*/ */
name = fw_string_blank(dump, 1); name = skip_blanks(dump);
if (!name) if (!name)
continue; continue;
/* The first white space is the end of variable name */ /* The first white space is the end of variable name */
val = fw_string_blank(name, 0); val = skip_chars(name);
len = strlen(name); len = strlen(name);
if (val) { if (val) {
*val++ = '\0'; *val++ = '\0';
if ((val - name) < len) if ((val - name) < len)
val = fw_string_blank(val, 1); val = skip_blanks(val);
else else
val = NULL; val = NULL;
} }