tools: env: trivial cleanups in script parsing
cover tools: env: trivial cleanups in script parsing
Andreas Fenkart (6):
tools: env: replace WHITESPACE macro by isblank
tools: env: fw_string_blank: return from loop when item found
tools: env: split fw_string_blank into skip_chars / skip_blanks
tools: env: fw_parse_script: simplify removal of newline/carriage
return
tools: env: fw_parse_script: simplify value parsing
tools: env: fw_parse_script: align arguments with opening brace
tools/env/fw_env.c | 49 ++++++++++++++++++++++--------------------------- 1 file changed, 22 insertions(+), 27 deletions(-)
Signature · 1 line
2.7.0
PATCH 1/6 tools: env: replace WHITESPACE macro by isblank
--- tools/env/fw_env.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
tools/env/fw_env.c +3 -4
@@ -15,6 +15,7 @@#include <env_flags.h> #include <fcntl.h> #include <linux/stringify.h> +#include <ctype.h> #include <stdio.h> #include <stdlib.h> #include <stddef.h>
@@ -36,8 +37,6 @@#define DIV_ROUND_UP (n, d) (((n) + (d) - 1) / (d)) -#define WHITESPACE (c) ((c == '\t') || (c == ' ')) -#define min (x, y) ({ \ typeof(x) _min1 = (x); \ typeof(y) _min2 = (y); \
@@ -140,8 +139,8 @@ static char *fw_string_blank(char *s, int noblank)int len =strlen (s);for (i =0 ; i < len; i++, s++) { -if ((noblank && !WHITESPACE (*s)) || - (!noblank &&WHITESPACE (*s))) +if ((noblank && !isblank (*s)) || + (!noblank &&isblank (*s)))break ; }if (i == len)
Signature · 1 line
2.7.0
PATCH 1/6 tools: env: replace WHITESPACE macro by isblank
Quoted 1 line · Andreas Fenkart
Signed-off-by Andreas Fenkart <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 836 bytes Desc: Digital signature URL: <http://lists.denx.de/pipermail/u-boot/attachments/20160327/fab0de3d/attachment.sig>
PATCH 2/6 tools: env: fw_string_blank: return from loop when item found
In reply to Andreas Fenkart--- tools/env/fw_env.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)
tools/env/fw_env.c +2 -5
@@ -141,12 +141,9 @@ static char *fw_string_blank(char *s, int noblank)for (i =0 ; i < len; i++, s++) {if ((noblank && !isblank (*s)) || (!noblank &&isblank (*s))) -break ; +return s; } -if (i == len) -return NULL ; - -return s; +return NULL ; }/*
Signature · 1 line
2.7.0
PATCH 2/6 tools: env: fw_string_blank: return from loop when item found
Quoted 1 line · Andreas Fenkart
Signed-off-by Andreas Fenkart <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 836 bytes Desc: Digital signature URL: <http://lists.denx.de/pipermail/u-boot/attachments/20160327/af130dd8/attachment.sig>
PATCH 3/6 tools: env: split fw_string_blank into skip_chars / skip_blanks
In reply to Andreas Fenkart--- tools/env/fw_env.c | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-)
tools/env/fw_env.c +14 -9
@@ -133,14 +133,19 @@ static inline ulong getenvsize (void)return rc; } -static char *fw_string_blank (char *s,int noblank) +static char *skip_chars (char *s) { -int i; -int len =strlen (s); +for (; *s !='\0' ; s++) { +if (isblank (*s)) +return s; + } +return NULL ; +} -for (i =0 ; i < len; i++, s++) { -if ((noblank && !isblank (*s)) || - (!noblank &&isblank (*s))) +static char *skip_blanks (char *s) +{ +for (; *s !='\0' ; s++) { +if (!isblank (*s))return s; }return NULL ;
@@ -575,17 +580,17 @@ int fw_parse_script(char *fname)* Search for variable's name, * remove leading whitespaces */ - name =fw_string_blank (dump,1 ); + name =skip_blanks (dump);if (!name)continue ;/* The first white space is the end of variable name */ - val =fw_string_blank (name,0 ); + val =skip_chars (name); len =strlen (name);if (val) { *val++ ='\0' ;if ((val - name) < len) - val =fw_string_blank (val,1 ); + val =skip_blanks (val);else val =NULL ; }
Signature · 1 line
2.7.0
PATCH 3/6 tools: env: split fw_string_blank into skip_chars / skip_blanks
Quoted 1 line · Andreas Fenkart
Signed-off-by Andreas Fenkart <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 836 bytes Desc: Digital signature URL: <http://lists.denx.de/pipermail/u-boot/attachments/20160327/f7988166/attachment.sig>
PATCH 4/6 tools: env: fw_parse_script: simplify removal of newline/carriage return
In reply to Andreas Fenkartfgets returns when the first '\n' is found
--- tools/env/fw_env.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-)
tools/env/fw_env.c +4 -6
@@ -566,14 +566,12 @@ int fw_parse_script(char *fname) }/* Drop ending line feed / carriage return */ -while (len >0 && (dump[len -1 ] =='\n' || - dump[len -1 ] =='\r' )) { - dump[len -1 ] ='\0' ; - len--; - } + dump[--len] ='\0' ; +if (len && dump[len -1 ] =='\r' ) + dump[--len] ='\0' ;/* Skip comment or empty lines */ -if ((len ==0 ) || dump[0 ] =='#' ) +if (len ==0 || dump[0 ] =='#' )continue ;/*
Signature · 1 line
2.7.0
PATCH 4/6 tools: env: fw_parse_script: simplify removal of newline/carriage return
Quoted 3 lines · Andreas Fenkart
fgets returns when the first '\n' is found
Signed-off-by Andreas Fenkart <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 836 bytes Desc: Digital signature URL: <http://lists.denx.de/pipermail/u-boot/attachments/20160327/a05d23d0/attachment.sig>