All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] xen/tools/get-fields.sh: Use printf for POSIX compat
@ 2015-12-20 16:41 Alex Xu
  2015-12-21 11:35 ` Jan Beulich
  0 siblings, 1 reply; 12+ messages in thread
From: Alex Xu @ 2015-12-20 16:41 UTC (permalink / raw)
  To: xen-devel; +Cc: keir, ian.campbell, tim, ian.jackson, Alex Xu, jbeulich

xen/tools/get-fields.sh used echo -n which is not POSIX compatible and
breaks building with dash (shell). Change it to use printf '%s' which
is usable everywhere.

Signed-off-by: Alex Xu <alex_y_xu@yahoo.ca>
---
 xen/tools/get-fields.sh | 30 +++++++++++++++---------------
 1 file changed, 15 insertions(+), 15 deletions(-)

diff --git a/xen/tools/get-fields.sh b/xen/tools/get-fields.sh
index 4547dc2..9c0b286 100644
--- a/xen/tools/get-fields.sh
+++ b/xen/tools/get-fields.sh
@@ -130,9 +130,9 @@ handle_field ()
 		echo " \\"
 		if [ -z "$4" ]
 		then
-			echo -n "$1(_d_)->$3 = (_s_)->$3;"
+			printf "%s" "$1(_d_)->$3 = (_s_)->$3;"
 		else
-			echo -n "$1XLAT_${2}_HNDL_$(echo $3 | $SED 's,\.,_,g')(_d_, _s_);"
+			printf "%s" "$1XLAT_${2}_HNDL_$(echo $3 | $SED 's,\.,_,g')(_d_, _s_);"
 		fi
 	elif [ -z "$(echo "$5" | $SED 's,[^{}],,g')" ]
 	then
@@ -142,7 +142,7 @@ for line in sys.stdin.readlines():
     print re.subn(r"\s*(struct|union)\s+(compat_)?(\w+)\s.*", r"\3", line)[0].rstrip()
 ')
 		echo " \\"
-		echo -n "${1}XLAT_$tag(&(_d_)->$3, &(_s_)->$3);"
+		printf "%s" "${1}XLAT_$tag(&(_d_)->$3, &(_s_)->$3);"
 	else
 		local level=1 kind= fields= id= array= arrlvl=1 array_type= type= token
 		for token in $5
@@ -156,7 +156,7 @@ for line in sys.stdin.readlines():
 					if [ $kind = union ]
 					then
 						echo " \\"
-						echo -n "${1}switch ($(echo $3 | $SED 's,\.,_,g')) {"
+						printf "%s" "${1}switch ($(echo $3 | $SED 's,\.,_,g')) {"
 					fi
 				fi
 				;;
@@ -168,7 +168,7 @@ for line in sys.stdin.readlines():
 				if [ $level = 1 -a $kind = union ]
 				then
 					echo " \\"
-					echo -n "$1}"
+					printf "%s" "$1}"
 				fi
 				;;
 			"[")
@@ -223,7 +223,7 @@ for line in sys.stdin.readlines():
 					if [ $kind = union ]
 					then
 						echo " \\"
-						echo -n "${1}case XLAT_${2}_$(echo $3.$id | $SED 's,\.,_,g'):"
+						printf "%s" "${1}case XLAT_${2}_$(echo $3.$id | $SED 's,\.,_,g'):"
 						handle_field "$1    " $2 $3.$id "$type" "$fields"
 					elif [ -z "$array" -a -z "$array_type" ]
 					then
@@ -239,7 +239,7 @@ for line in sys.stdin.readlines():
 					if [ $kind = union ]
 					then
 						echo " \\"
-						echo -n "$1    break;"
+						printf "%s" "$1    break;"
 					fi
 				fi
 				;;
@@ -259,7 +259,7 @@ copy_array ()
 {
 	echo " \\"
 	echo "${1}if ((_d_)->$2 != (_s_)->$2) \\"
-	echo -n "$1    memcpy((_d_)->$2, (_s_)->$2, sizeof((_d_)->$2));"
+	printf "%s" "$1    memcpy((_d_)->$2, (_s_)->$2, sizeof((_d_)->$2));"
 }
 
 handle_array ()
@@ -268,7 +268,7 @@ handle_array ()
 	echo " \\"
 	echo "$1{ \\"
 	echo "$1    unsigned int $i; \\"
-	echo -n "$1    for ($i = 0; $i < "${4%%;*}"; ++$i) {"
+	printf "%s" "$1    for ($i = 0; $i < "${4%%;*}"; ++$i) {"
 	if [ "$4" = "${4#*;}" ]
 	then
 		handle_field "$1        " $2 $3[$i] "$5" "$6"
@@ -277,13 +277,13 @@ handle_array ()
 	fi
 	echo " \\"
 	echo "$1    } \\"
-	echo -n "$1}"
+	printf "%s" "$1}"
 }
 
 build_body ()
 {
 	echo
-	echo -n "#define XLAT_$1(_d_, _s_) do {"
+	printf "%s" "#define XLAT_$1(_d_, _s_) do {"
 	local level=1 fields= id= array= arrlvl=1 array_type= type= token
 	for token in $2
 	do
@@ -389,7 +389,7 @@ check_field ()
 				struct|union)
 					;;
 				[a-zA-Z_]*)
-					echo -n "    CHECK_${n#xen_}"
+					printf "%s" "    CHECK_${n#xen_}"
 					break
 					;;
 				*)
@@ -400,9 +400,9 @@ check_field ()
 			done
 		elif [ $n = 0 ]
 		then
-			echo -n "    CHECK_FIELD_($1, $2, $3)"
+			printf "%s" "    CHECK_FIELD_($1, $2, $3)"
 		else
-			echo -n "    CHECK_SUBFIELD_${n}_($1, $2, $(echo $3 | $SED 's!\.!, !g'))"
+			printf "%s" "    CHECK_SUBFIELD_${n}_($1, $2, $(echo $3 | $SED 's!\.!, !g'))"
 		fi
 	else
 		local level=1 fields= id= token
@@ -446,7 +446,7 @@ build_check ()
 			if [ $level = 1 ]
 			then
 				kind=$token
-				echo -n "    CHECK_SIZE_($kind, $1)"
+				printf "%s" "    CHECK_SIZE_($kind, $1)"
 			elif [ $level = 2 ]
 			then
 				fields=" "
-- 
2.6.4

^ permalink raw reply related	[flat|nested] 12+ messages in thread

* Re: [PATCH] xen/tools/get-fields.sh: Use printf for POSIX compat
  2015-12-20 16:41 [PATCH] xen/tools/get-fields.sh: Use printf for POSIX compat Alex Xu
@ 2015-12-21 11:35 ` Jan Beulich
  0 siblings, 0 replies; 12+ messages in thread
From: Jan Beulich @ 2015-12-21 11:35 UTC (permalink / raw)
  To: Alex Xu; +Cc: keir, tim, ian.jackson, ian.campbell, xen-devel

>>> On 20.12.15 at 17:41, <alex_y_xu@yahoo.ca> wrote:
> xen/tools/get-fields.sh used echo -n which is not POSIX compatible and
> breaks building with dash (shell). Change it to use printf '%s' which
> is usable everywhere.
> 
> Signed-off-by: Alex Xu <alex_y_xu@yahoo.ca>

My remarks on v1 regarding quotation still apply.

Jan

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH] xen/tools/get-fields.sh: Use printf for POSIX compat
  2016-01-04 16:28     ` Ian Jackson
@ 2016-01-04 16:42       ` Ian Campbell
  0 siblings, 0 replies; 12+ messages in thread
From: Ian Campbell @ 2016-01-04 16:42 UTC (permalink / raw)
  To: Ian Jackson, Alex Xu; +Cc: tim, keir, jbeulich, xen-devel

On Mon, 2016-01-04 at 16:28 +0000, Ian Jackson wrote:
> Alex Xu writes ("Re: [PATCH] xen/tools/get-fields.sh: Use printf for
> POSIX compat"):
> > Argh, claws mangled the formatting. Please ignore.
> 
> Indeed.  But, your code is good.  When you repost please add my ack.

Jan already committed it.



_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH] xen/tools/get-fields.sh: Use printf for POSIX compat
  2015-12-14 18:25   ` Alex Xu
@ 2016-01-04 16:28     ` Ian Jackson
  2016-01-04 16:42       ` Ian Campbell
  0 siblings, 1 reply; 12+ messages in thread
From: Ian Jackson @ 2016-01-04 16:28 UTC (permalink / raw)
  To: Alex Xu; +Cc: tim, keir, ian.campbell, jbeulich, xen-devel

Alex Xu writes ("Re: [PATCH] xen/tools/get-fields.sh: Use printf for POSIX compat"):
> Argh, claws mangled the formatting. Please ignore.

Indeed.  But, your code is good.  When you repost please add my ack.

Ian.

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH] xen/tools/get-fields.sh: Use printf for POSIX compat
  2015-12-14 18:22 ` Alex Xu
  2015-12-14 18:25   ` Alex Xu
@ 2016-01-04 16:28   ` Ian Jackson
  1 sibling, 0 replies; 12+ messages in thread
From: Ian Jackson @ 2016-01-04 16:28 UTC (permalink / raw)
  To: Alex Xu; +Cc: tim, keir, ian.campbell, jbeulich, xen-devel

Alex Xu writes ("[PATCH] xen/tools/get-fields.sh: Use printf for POSIX compat"):
> xen/tools/get-fields.sh used echo -n which is not POSIX compatible and
> breaks building with dash (shell). Change it to use printf "%s" which
> is usable everywhere.

Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>

^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH] xen/tools/get-fields.sh: Use printf for POSIX compat
@ 2015-12-21 15:29 Alex Xu
  0 siblings, 0 replies; 12+ messages in thread
From: Alex Xu @ 2015-12-21 15:29 UTC (permalink / raw)
  To: xen-devel; +Cc: keir, ian.campbell, tim, ian.jackson, Alex Xu, jbeulich

xen/tools/get-fields.sh used echo -n which is not POSIX compatible and
breaks building with dash (shell). Change it to use printf %s which is
usable everywhere.

Signed-off-by: Alex Xu <alex_y_xu@yahoo.ca>
---
 xen/tools/get-fields.sh | 30 +++++++++++++++---------------
 1 file changed, 15 insertions(+), 15 deletions(-)

diff --git a/xen/tools/get-fields.sh b/xen/tools/get-fields.sh
index 4547dc2..887feec 100644
--- a/xen/tools/get-fields.sh
+++ b/xen/tools/get-fields.sh
@@ -130,9 +130,9 @@ handle_field ()
 		echo " \\"
 		if [ -z "$4" ]
 		then
-			echo -n "$1(_d_)->$3 = (_s_)->$3;"
+			printf %s "$1(_d_)->$3 = (_s_)->$3;"
 		else
-			echo -n "$1XLAT_${2}_HNDL_$(echo $3 | $SED 's,\.,_,g')(_d_, _s_);"
+			printf %s "$1XLAT_${2}_HNDL_$(echo $3 | $SED 's,\.,_,g')(_d_, _s_);"
 		fi
 	elif [ -z "$(echo "$5" | $SED 's,[^{}],,g')" ]
 	then
@@ -142,7 +142,7 @@ for line in sys.stdin.readlines():
     print re.subn(r"\s*(struct|union)\s+(compat_)?(\w+)\s.*", r"\3", line)[0].rstrip()
 ')
 		echo " \\"
-		echo -n "${1}XLAT_$tag(&(_d_)->$3, &(_s_)->$3);"
+		printf %s "${1}XLAT_$tag(&(_d_)->$3, &(_s_)->$3);"
 	else
 		local level=1 kind= fields= id= array= arrlvl=1 array_type= type= token
 		for token in $5
@@ -156,7 +156,7 @@ for line in sys.stdin.readlines():
 					if [ $kind = union ]
 					then
 						echo " \\"
-						echo -n "${1}switch ($(echo $3 | $SED 's,\.,_,g')) {"
+						printf %s "${1}switch ($(echo $3 | $SED 's,\.,_,g')) {"
 					fi
 				fi
 				;;
@@ -168,7 +168,7 @@ for line in sys.stdin.readlines():
 				if [ $level = 1 -a $kind = union ]
 				then
 					echo " \\"
-					echo -n "$1}"
+					printf %s "$1}"
 				fi
 				;;
 			"[")
@@ -223,7 +223,7 @@ for line in sys.stdin.readlines():
 					if [ $kind = union ]
 					then
 						echo " \\"
-						echo -n "${1}case XLAT_${2}_$(echo $3.$id | $SED 's,\.,_,g'):"
+						printf %s "${1}case XLAT_${2}_$(echo $3.$id | $SED 's,\.,_,g'):"
 						handle_field "$1    " $2 $3.$id "$type" "$fields"
 					elif [ -z "$array" -a -z "$array_type" ]
 					then
@@ -239,7 +239,7 @@ for line in sys.stdin.readlines():
 					if [ $kind = union ]
 					then
 						echo " \\"
-						echo -n "$1    break;"
+						printf %s "$1    break;"
 					fi
 				fi
 				;;
@@ -259,7 +259,7 @@ copy_array ()
 {
 	echo " \\"
 	echo "${1}if ((_d_)->$2 != (_s_)->$2) \\"
-	echo -n "$1    memcpy((_d_)->$2, (_s_)->$2, sizeof((_d_)->$2));"
+	printf %s "$1    memcpy((_d_)->$2, (_s_)->$2, sizeof((_d_)->$2));"
 }
 
 handle_array ()
@@ -268,7 +268,7 @@ handle_array ()
 	echo " \\"
 	echo "$1{ \\"
 	echo "$1    unsigned int $i; \\"
-	echo -n "$1    for ($i = 0; $i < "${4%%;*}"; ++$i) {"
+	printf %s "$1    for ($i = 0; $i < "${4%%;*}"; ++$i) {"
 	if [ "$4" = "${4#*;}" ]
 	then
 		handle_field "$1        " $2 $3[$i] "$5" "$6"
@@ -277,13 +277,13 @@ handle_array ()
 	fi
 	echo " \\"
 	echo "$1    } \\"
-	echo -n "$1}"
+	printf %s "$1}"
 }
 
 build_body ()
 {
 	echo
-	echo -n "#define XLAT_$1(_d_, _s_) do {"
+	printf %s "#define XLAT_$1(_d_, _s_) do {"
 	local level=1 fields= id= array= arrlvl=1 array_type= type= token
 	for token in $2
 	do
@@ -389,7 +389,7 @@ check_field ()
 				struct|union)
 					;;
 				[a-zA-Z_]*)
-					echo -n "    CHECK_${n#xen_}"
+					printf %s "    CHECK_${n#xen_}"
 					break
 					;;
 				*)
@@ -400,9 +400,9 @@ check_field ()
 			done
 		elif [ $n = 0 ]
 		then
-			echo -n "    CHECK_FIELD_($1, $2, $3)"
+			printf %s "    CHECK_FIELD_($1, $2, $3)"
 		else
-			echo -n "    CHECK_SUBFIELD_${n}_($1, $2, $(echo $3 | $SED 's!\.!, !g'))"
+			printf %s "    CHECK_SUBFIELD_${n}_($1, $2, $(echo $3 | $SED 's!\.!, !g'))"
 		fi
 	else
 		local level=1 fields= id= token
@@ -446,7 +446,7 @@ build_check ()
 			if [ $level = 1 ]
 			then
 				kind=$token
-				echo -n "    CHECK_SIZE_($kind, $1)"
+				printf %s "    CHECK_SIZE_($kind, $1)"
 			elif [ $level = 2 ]
 			then
 				fields=" "
-- 
2.6.4

^ permalink raw reply related	[flat|nested] 12+ messages in thread

* Re: [PATCH] xen/tools/get-fields.sh: Use printf for POSIX compat
  2015-12-14 18:22 ` Alex Xu
@ 2015-12-14 18:25   ` Alex Xu
  2016-01-04 16:28     ` Ian Jackson
  2016-01-04 16:28   ` Ian Jackson
  1 sibling, 1 reply; 12+ messages in thread
From: Alex Xu @ 2015-12-14 18:25 UTC (permalink / raw)
  To: xen-devel; +Cc: keir, ian.jackson, ian.campbell, jbeulich, tim

On Mon, 14 Dec 2015 13:22:28 -0500
Alex Xu <alex_y_xu@yahoo.ca> wrote:

> xen/tools/get-fields.sh used echo -n which is not POSIX compatible and
> breaks building with dash (shell). Change it to use printf "%s" which
> is usable everywhere.
> 
> Signed-off-by: Alex Xu <alex_y_xu@yahoo.ca>
> ---
>  xen/tools/get-fields.sh | 30 +++++++++++++++---------------
>  1 file changed, 15 insertions(+), 15 deletions(-)
> 
> diff --git a/xen/tools/get-fields.sh b/xen/tools/get-fields.sh
> index 4547dc2..9c0b286 100644
> --- a/xen/tools/get-fields.sh
> +++ b/xen/tools/get-fields.sh
> @@ -130,9 +130,9 @@ handle_field ()
>  		echo " \\"
>  		if [ -z "$4" ]
>  		then
> -			echo -n "$1(_d_)->$3 = (_s_)->$3;"
> +			printf "%s" "$1(_d_)->$3 = (_s_)->$3;"
>  		else
> -			echo -n "$1XLAT_${2}_HNDL_$(echo $3 | $SED
> 's,\.,_,g')(_d_, _s_);"
> +			printf "%s" "$1XLAT_${2}_HNDL_$(echo $3 |
> $SED 's,\.,_,g')(_d_, _s_);" fi
>  	elif [ -z "$(echo "$5" | $SED 's,[^{}],,g')" ]
>  	then
> @@ -142,7 +142,7 @@ for line in sys.stdin.readlines():
>      print re.subn(r"\s*(struct|union)\s+(compat_)?(\w+)\s.*", r"\3",
> line)[0].rstrip() ')
>  		echo " \\"
> -		echo -n "${1}XLAT_$tag(&(_d_)->$3, &(_s_)->$3);"
> +		printf "%s" "${1}XLAT_$tag(&(_d_)->$3, &(_s_)->$3);"
>  	else
>  		local level=1 kind= fields= id= array= arrlvl=1
> array_type= type= token for token in $5
> @@ -156,7 +156,7 @@ for line in sys.stdin.readlines():
>  					if [ $kind = union ]
>  					then
>  						echo " \\"
> -						echo -n "${1}switch
> ($(echo $3 | $SED 's,\.,_,g')) {"
> +						printf "%s"
> "${1}switch ($(echo $3 | $SED 's,\.,_,g')) {" fi
>  				fi
>  				;;
> @@ -168,7 +168,7 @@ for line in sys.stdin.readlines():
>  				if [ $level = 1 -a $kind = union ]
>  				then
>  					echo " \\"
> -					echo -n "$1}"
> +					printf "%s" "$1}"
>  				fi
>  				;;
>  			"[")
> @@ -223,7 +223,7 @@ for line in sys.stdin.readlines():
>  					if [ $kind = union ]
>  					then
>  						echo " \\"
> -						echo -n "${1}case
> XLAT_${2}_$(echo $3.$id | $SED 's,\.,_,g'):"
> +						printf "%s" "${1}case
> XLAT_${2}_$(echo $3.$id | $SED 's,\.,_,g'):" handle_field "$1    " $2
> $3.$id "$type" "$fields" elif [ -z "$array" -a -z "$array_type" ]
>  					then
> @@ -239,7 +239,7 @@ for line in sys.stdin.readlines():
>  					if [ $kind = union ]
>  					then
>  						echo " \\"
> -						echo -n "$1
> break;"
> +						printf "%s" "$1
> break;" fi
>  				fi
>  				;;
> @@ -259,7 +259,7 @@ copy_array ()
>  {
>  	echo " \\"
>  	echo "${1}if ((_d_)->$2 != (_s_)->$2) \\"
> -	echo -n "$1    memcpy((_d_)->$2, (_s_)->$2,
> sizeof((_d_)->$2));"
> +	printf "%s" "$1    memcpy((_d_)->$2, (_s_)->$2,
> sizeof((_d_)->$2));" }
>  
>  handle_array ()
> @@ -268,7 +268,7 @@ handle_array ()
>  	echo " \\"
>  	echo "$1{ \\"
>  	echo "$1    unsigned int $i; \\"
> -	echo -n "$1    for ($i = 0; $i < "${4%%;*}"; ++$i) {"
> +	printf "%s" "$1    for ($i = 0; $i < "${4%%;*}"; ++$i) {"
>  	if [ "$4" = "${4#*;}" ]
>  	then
>  		handle_field "$1        " $2 $3[$i] "$5" "$6"
> @@ -277,13 +277,13 @@ handle_array ()
>  	fi
>  	echo " \\"
>  	echo "$1    } \\"
> -	echo -n "$1}"
> +	printf "%s" "$1}"
>  }
>  
>  build_body ()
>  {
>  	echo
> -	echo -n "#define XLAT_$1(_d_, _s_) do {"
> +	printf "%s" "#define XLAT_$1(_d_, _s_) do {"
>  	local level=1 fields= id= array= arrlvl=1 array_type= type=
> token for token in $2
>  	do
> @@ -389,7 +389,7 @@ check_field ()
>  				struct|union)
>  					;;
>  				[a-zA-Z_]*)
> -					echo -n "    CHECK_${n#xen_}"
> +					printf "%s" "
> CHECK_${n#xen_}" break
>  					;;
>  				*)
> @@ -400,9 +400,9 @@ check_field ()
>  			done
>  		elif [ $n = 0 ]
>  		then
> -			echo -n "    CHECK_FIELD_($1, $2, $3)"
> +			printf "%s" "    CHECK_FIELD_($1, $2, $3)"
>  		else
> -			echo -n "    CHECK_SUBFIELD_${n}_($1, $2,
> $(echo $3 | $SED 's!\.!, !g'))"
> +			printf "%s" "    CHECK_SUBFIELD_${n}_($1, $2,
> $(echo $3 | $SED 's!\.!, !g'))" fi
>  	else
>  		local level=1 fields= id= token
> @@ -446,7 +446,7 @@ build_check ()
>  			if [ $level = 1 ]
>  			then
>  				kind=$token
> -				echo -n "    CHECK_SIZE_($kind, $1)"
> +				printf "%s" "    CHECK_SIZE_($kind,
> $1)" elif [ $level = 2 ]
>  			then
>  				fields=" "

Argh, claws mangled the formatting. Please ignore.

^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH] xen/tools/get-fields.sh: Use printf for POSIX compat
  2015-12-12 18:18 Alex Xu
  2015-12-14  9:12 ` Jan Beulich
@ 2015-12-14 18:22 ` Alex Xu
  2015-12-14 18:25   ` Alex Xu
  2016-01-04 16:28   ` Ian Jackson
  1 sibling, 2 replies; 12+ messages in thread
From: Alex Xu @ 2015-12-14 18:22 UTC (permalink / raw)
  To: xen-devel; +Cc: keir, ian.jackson, ian.campbell, jbeulich, tim

xen/tools/get-fields.sh used echo -n which is not POSIX compatible and
breaks building with dash (shell). Change it to use printf "%s" which
is usable everywhere.

Signed-off-by: Alex Xu <alex_y_xu@yahoo.ca>
---
 xen/tools/get-fields.sh | 30 +++++++++++++++---------------
 1 file changed, 15 insertions(+), 15 deletions(-)

diff --git a/xen/tools/get-fields.sh b/xen/tools/get-fields.sh
index 4547dc2..9c0b286 100644
--- a/xen/tools/get-fields.sh
+++ b/xen/tools/get-fields.sh
@@ -130,9 +130,9 @@ handle_field ()
 		echo " \\"
 		if [ -z "$4" ]
 		then
-			echo -n "$1(_d_)->$3 = (_s_)->$3;"
+			printf "%s" "$1(_d_)->$3 = (_s_)->$3;"
 		else
-			echo -n "$1XLAT_${2}_HNDL_$(echo $3 | $SED
's,\.,_,g')(_d_, _s_);"
+			printf "%s" "$1XLAT_${2}_HNDL_$(echo $3 | $SED
's,\.,_,g')(_d_, _s_);" fi
 	elif [ -z "$(echo "$5" | $SED 's,[^{}],,g')" ]
 	then
@@ -142,7 +142,7 @@ for line in sys.stdin.readlines():
     print re.subn(r"\s*(struct|union)\s+(compat_)?(\w+)\s.*", r"\3",
line)[0].rstrip() ')
 		echo " \\"
-		echo -n "${1}XLAT_$tag(&(_d_)->$3, &(_s_)->$3);"
+		printf "%s" "${1}XLAT_$tag(&(_d_)->$3, &(_s_)->$3);"
 	else
 		local level=1 kind= fields= id= array= arrlvl=1
array_type= type= token for token in $5
@@ -156,7 +156,7 @@ for line in sys.stdin.readlines():
 					if [ $kind = union ]
 					then
 						echo " \\"
-						echo -n "${1}switch
($(echo $3 | $SED 's,\.,_,g')) {"
+						printf "%s"
"${1}switch ($(echo $3 | $SED 's,\.,_,g')) {" fi
 				fi
 				;;
@@ -168,7 +168,7 @@ for line in sys.stdin.readlines():
 				if [ $level = 1 -a $kind = union ]
 				then
 					echo " \\"
-					echo -n "$1}"
+					printf "%s" "$1}"
 				fi
 				;;
 			"[")
@@ -223,7 +223,7 @@ for line in sys.stdin.readlines():
 					if [ $kind = union ]
 					then
 						echo " \\"
-						echo -n "${1}case
XLAT_${2}_$(echo $3.$id | $SED 's,\.,_,g'):"
+						printf "%s" "${1}case
XLAT_${2}_$(echo $3.$id | $SED 's,\.,_,g'):" handle_field "$1    " $2
$3.$id "$type" "$fields" elif [ -z "$array" -a -z "$array_type" ]
 					then
@@ -239,7 +239,7 @@ for line in sys.stdin.readlines():
 					if [ $kind = union ]
 					then
 						echo " \\"
-						echo -n "$1    break;"
+						printf "%s" "$1
break;" fi
 				fi
 				;;
@@ -259,7 +259,7 @@ copy_array ()
 {
 	echo " \\"
 	echo "${1}if ((_d_)->$2 != (_s_)->$2) \\"
-	echo -n "$1    memcpy((_d_)->$2, (_s_)->$2,
sizeof((_d_)->$2));"
+	printf "%s" "$1    memcpy((_d_)->$2, (_s_)->$2,
sizeof((_d_)->$2));" }
 
 handle_array ()
@@ -268,7 +268,7 @@ handle_array ()
 	echo " \\"
 	echo "$1{ \\"
 	echo "$1    unsigned int $i; \\"
-	echo -n "$1    for ($i = 0; $i < "${4%%;*}"; ++$i) {"
+	printf "%s" "$1    for ($i = 0; $i < "${4%%;*}"; ++$i) {"
 	if [ "$4" = "${4#*;}" ]
 	then
 		handle_field "$1        " $2 $3[$i] "$5" "$6"
@@ -277,13 +277,13 @@ handle_array ()
 	fi
 	echo " \\"
 	echo "$1    } \\"
-	echo -n "$1}"
+	printf "%s" "$1}"
 }
 
 build_body ()
 {
 	echo
-	echo -n "#define XLAT_$1(_d_, _s_) do {"
+	printf "%s" "#define XLAT_$1(_d_, _s_) do {"
 	local level=1 fields= id= array= arrlvl=1 array_type= type=
token for token in $2
 	do
@@ -389,7 +389,7 @@ check_field ()
 				struct|union)
 					;;
 				[a-zA-Z_]*)
-					echo -n "    CHECK_${n#xen_}"
+					printf "%s" "
CHECK_${n#xen_}" break
 					;;
 				*)
@@ -400,9 +400,9 @@ check_field ()
 			done
 		elif [ $n = 0 ]
 		then
-			echo -n "    CHECK_FIELD_($1, $2, $3)"
+			printf "%s" "    CHECK_FIELD_($1, $2, $3)"
 		else
-			echo -n "    CHECK_SUBFIELD_${n}_($1, $2,
$(echo $3 | $SED 's!\.!, !g'))"
+			printf "%s" "    CHECK_SUBFIELD_${n}_($1, $2,
$(echo $3 | $SED 's!\.!, !g'))" fi
 	else
 		local level=1 fields= id= token
@@ -446,7 +446,7 @@ build_check ()
 			if [ $level = 1 ]
 			then
 				kind=$token
-				echo -n "    CHECK_SIZE_($kind, $1)"
+				printf "%s" "    CHECK_SIZE_($kind,
$1)" elif [ $level = 2 ]
 			then
 				fields=" "
-- 
2.6.3

^ permalink raw reply related	[flat|nested] 12+ messages in thread

* Re: [PATCH] xen/tools/get-fields.sh: Use printf for POSIX compat
  2015-12-14 15:56   ` Alex Xu
@ 2015-12-14 16:13     ` Jan Beulich
  0 siblings, 0 replies; 12+ messages in thread
From: Jan Beulich @ 2015-12-14 16:13 UTC (permalink / raw)
  To: Alex Xu; +Cc: xen-devel

>>> On 14.12.15 at 16:56, <alex_y_xu@yahoo.ca> wrote:
> On Mon, 14 Dec 2015 02:12:16 -0700
> "Jan Beulich" <JBeulich@suse.com> wrote:
> 
>> >>> On 12.12.15 at 19:18, <alex_y_xu@yahoo.ca> wrote:  
>> > xen/tools/get-fields.sh used echo -n which is not POSIX compatible
>> > and breaks with dash. Change it to use printf "%s" which is usable
>> > everywhere.  
>> 
>> Looks okay, but a couple of remarks:
>> - For the unaware as well as to know why to take care going forward,
>>   it would be nice if the commit message mentioned where actually you
>>   saw this to be an issue.
> 
> I already said that it doesn't work with dash. I can insert the word
> "building" if you want.

Oh, I'm sorry, I didn't take "dash" as a shell name (and have been
wondering what you mean with that sentence (taking the word as
just what ir normally means).

>> - There appears to be quite a bit of unnecessary quoting (namely on
>>   all the "%s" instances), making lines longer than they need to be
>>   (and hence possible harder to read).
> 
> Habit from C.
> 
>> In fact, since field names
>> can't contain %, \, or other characters with special meaning to
>> printf it looks as if the use of %s is superfluous altogether.
> 
> Again, habit from C, but here I think it is useful to use %s for
> several reasons.
> 
> 1. works exactly the same way as before
> 1a. no need to exhaustively check every case to see if % or \ ever gets
>     in
> 2. less likely to cause issues if someone copies and pastes the code or
>    the calls change later on

Well, in general I would agree, but in this particular case I wonder
whether the shorter resulting lines aren't outweighing the benefits
you name.

>> - Please Cc all relevant maintainers, not just Keir.
> 
> OK, I looked at MAINTAINERS but I only found "THE REST" and Keir was
> the only one who had touched get-fields.sh semi-recently.

But THE REST is it in this case.

Jan

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH] xen/tools/get-fields.sh: Use printf for POSIX compat
  2015-12-14  9:12 ` Jan Beulich
@ 2015-12-14 15:56   ` Alex Xu
  2015-12-14 16:13     ` Jan Beulich
  0 siblings, 1 reply; 12+ messages in thread
From: Alex Xu @ 2015-12-14 15:56 UTC (permalink / raw)
  To: Jan Beulich; +Cc: xen-devel

On Mon, 14 Dec 2015 02:12:16 -0700
"Jan Beulich" <JBeulich@suse.com> wrote:

> >>> On 12.12.15 at 19:18, <alex_y_xu@yahoo.ca> wrote:  
> > xen/tools/get-fields.sh used echo -n which is not POSIX compatible
> > and breaks with dash. Change it to use printf "%s" which is usable
> > everywhere.  
> 
> Looks okay, but a couple of remarks:
> - For the unaware as well as to know why to take care going forward,
>   it would be nice if the commit message mentioned where actually you
>   saw this to be an issue.

I already said that it doesn't work with dash. I can insert the word
"building" if you want.

> - There appears to be quite a bit of unnecessary quoting (namely on
>   all the "%s" instances), making lines longer than they need to be
>   (and hence possible harder to read).

Habit from C.

> In fact, since field names
> can't contain %, \, or other characters with special meaning to
> printf it looks as if the use of %s is superfluous altogether.

Again, habit from C, but here I think it is useful to use %s for
several reasons.

1. works exactly the same way as before
1a. no need to exhaustively check every case to see if % or \ ever gets
    in
2. less likely to cause issues if someone copies and pastes the code or
   the calls change later on

> - Please Cc all relevant maintainers, not just Keir.

OK, I looked at MAINTAINERS but I only found "THE REST" and Keir was
the only one who had touched get-fields.sh semi-recently.

> 
> Jan
> 

Thank you for the feedback. I will rewrite the commit message and send
again to everyone.

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH] xen/tools/get-fields.sh: Use printf for POSIX compat
  2015-12-12 18:18 Alex Xu
@ 2015-12-14  9:12 ` Jan Beulich
  2015-12-14 15:56   ` Alex Xu
  2015-12-14 18:22 ` Alex Xu
  1 sibling, 1 reply; 12+ messages in thread
From: Jan Beulich @ 2015-12-14  9:12 UTC (permalink / raw)
  To: Alex Xu; +Cc: keir, xen-devel

>>> On 12.12.15 at 19:18, <alex_y_xu@yahoo.ca> wrote:
> xen/tools/get-fields.sh used echo -n which is not POSIX compatible and
> breaks with dash. Change it to use printf "%s" which is usable
> everywhere.

Looks okay, but a couple of remarks:
- For the unaware as well as to know why to take care going forward,
  it would be nice if the commit message mentioned where actually you
  saw this to be an issue.
- There appears to be quite a bit of unnecessary quoting (namely on
  all the "%s" instances), making lines longer than they need to be
  (and hence possible harder to read). In fact, since field names can't
  contain %, \, or other characters with special meaning to printf it
  looks as if the use of %s is superfluous altogether.
- Please Cc all relevant maintainers, not just Keir.

Jan

^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH] xen/tools/get-fields.sh: Use printf for POSIX compat
@ 2015-12-12 18:18 Alex Xu
  2015-12-14  9:12 ` Jan Beulich
  2015-12-14 18:22 ` Alex Xu
  0 siblings, 2 replies; 12+ messages in thread
From: Alex Xu @ 2015-12-12 18:18 UTC (permalink / raw)
  To: xen-devel; +Cc: keir, Alex Xu

xen/tools/get-fields.sh used echo -n which is not POSIX compatible and
breaks with dash. Change it to use printf "%s" which is usable
everywhere.

Signed-off-by: Alex Xu <alex_y_xu@yahoo.ca>
---
 xen/tools/get-fields.sh | 30 +++++++++++++++---------------
 1 file changed, 15 insertions(+), 15 deletions(-)

diff --git a/xen/tools/get-fields.sh b/xen/tools/get-fields.sh
index 4547dc2..9c0b286 100644
--- a/xen/tools/get-fields.sh
+++ b/xen/tools/get-fields.sh
@@ -130,9 +130,9 @@ handle_field ()
 		echo " \\"
 		if [ -z "$4" ]
 		then
-			echo -n "$1(_d_)->$3 = (_s_)->$3;"
+			printf "%s" "$1(_d_)->$3 = (_s_)->$3;"
 		else
-			echo -n "$1XLAT_${2}_HNDL_$(echo $3 | $SED 's,\.,_,g')(_d_, _s_);"
+			printf "%s" "$1XLAT_${2}_HNDL_$(echo $3 | $SED 's,\.,_,g')(_d_, _s_);"
 		fi
 	elif [ -z "$(echo "$5" | $SED 's,[^{}],,g')" ]
 	then
@@ -142,7 +142,7 @@ for line in sys.stdin.readlines():
     print re.subn(r"\s*(struct|union)\s+(compat_)?(\w+)\s.*", r"\3", line)[0].rstrip()
 ')
 		echo " \\"
-		echo -n "${1}XLAT_$tag(&(_d_)->$3, &(_s_)->$3);"
+		printf "%s" "${1}XLAT_$tag(&(_d_)->$3, &(_s_)->$3);"
 	else
 		local level=1 kind= fields= id= array= arrlvl=1 array_type= type= token
 		for token in $5
@@ -156,7 +156,7 @@ for line in sys.stdin.readlines():
 					if [ $kind = union ]
 					then
 						echo " \\"
-						echo -n "${1}switch ($(echo $3 | $SED 's,\.,_,g')) {"
+						printf "%s" "${1}switch ($(echo $3 | $SED 's,\.,_,g')) {"
 					fi
 				fi
 				;;
@@ -168,7 +168,7 @@ for line in sys.stdin.readlines():
 				if [ $level = 1 -a $kind = union ]
 				then
 					echo " \\"
-					echo -n "$1}"
+					printf "%s" "$1}"
 				fi
 				;;
 			"[")
@@ -223,7 +223,7 @@ for line in sys.stdin.readlines():
 					if [ $kind = union ]
 					then
 						echo " \\"
-						echo -n "${1}case XLAT_${2}_$(echo $3.$id | $SED 's,\.,_,g'):"
+						printf "%s" "${1}case XLAT_${2}_$(echo $3.$id | $SED 's,\.,_,g'):"
 						handle_field "$1    " $2 $3.$id "$type" "$fields"
 					elif [ -z "$array" -a -z "$array_type" ]
 					then
@@ -239,7 +239,7 @@ for line in sys.stdin.readlines():
 					if [ $kind = union ]
 					then
 						echo " \\"
-						echo -n "$1    break;"
+						printf "%s" "$1    break;"
 					fi
 				fi
 				;;
@@ -259,7 +259,7 @@ copy_array ()
 {
 	echo " \\"
 	echo "${1}if ((_d_)->$2 != (_s_)->$2) \\"
-	echo -n "$1    memcpy((_d_)->$2, (_s_)->$2, sizeof((_d_)->$2));"
+	printf "%s" "$1    memcpy((_d_)->$2, (_s_)->$2, sizeof((_d_)->$2));"
 }
 
 handle_array ()
@@ -268,7 +268,7 @@ handle_array ()
 	echo " \\"
 	echo "$1{ \\"
 	echo "$1    unsigned int $i; \\"
-	echo -n "$1    for ($i = 0; $i < "${4%%;*}"; ++$i) {"
+	printf "%s" "$1    for ($i = 0; $i < "${4%%;*}"; ++$i) {"
 	if [ "$4" = "${4#*;}" ]
 	then
 		handle_field "$1        " $2 $3[$i] "$5" "$6"
@@ -277,13 +277,13 @@ handle_array ()
 	fi
 	echo " \\"
 	echo "$1    } \\"
-	echo -n "$1}"
+	printf "%s" "$1}"
 }
 
 build_body ()
 {
 	echo
-	echo -n "#define XLAT_$1(_d_, _s_) do {"
+	printf "%s" "#define XLAT_$1(_d_, _s_) do {"
 	local level=1 fields= id= array= arrlvl=1 array_type= type= token
 	for token in $2
 	do
@@ -389,7 +389,7 @@ check_field ()
 				struct|union)
 					;;
 				[a-zA-Z_]*)
-					echo -n "    CHECK_${n#xen_}"
+					printf "%s" "    CHECK_${n#xen_}"
 					break
 					;;
 				*)
@@ -400,9 +400,9 @@ check_field ()
 			done
 		elif [ $n = 0 ]
 		then
-			echo -n "    CHECK_FIELD_($1, $2, $3)"
+			printf "%s" "    CHECK_FIELD_($1, $2, $3)"
 		else
-			echo -n "    CHECK_SUBFIELD_${n}_($1, $2, $(echo $3 | $SED 's!\.!, !g'))"
+			printf "%s" "    CHECK_SUBFIELD_${n}_($1, $2, $(echo $3 | $SED 's!\.!, !g'))"
 		fi
 	else
 		local level=1 fields= id= token
@@ -446,7 +446,7 @@ build_check ()
 			if [ $level = 1 ]
 			then
 				kind=$token
-				echo -n "    CHECK_SIZE_($kind, $1)"
+				printf "%s" "    CHECK_SIZE_($kind, $1)"
 			elif [ $level = 2 ]
 			then
 				fields=" "
-- 
2.6.3

^ permalink raw reply related	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2016-01-04 16:42 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-12-20 16:41 [PATCH] xen/tools/get-fields.sh: Use printf for POSIX compat Alex Xu
2015-12-21 11:35 ` Jan Beulich
  -- strict thread matches above, loose matches on Subject: below --
2015-12-21 15:29 Alex Xu
2015-12-12 18:18 Alex Xu
2015-12-14  9:12 ` Jan Beulich
2015-12-14 15:56   ` Alex Xu
2015-12-14 16:13     ` Jan Beulich
2015-12-14 18:22 ` Alex Xu
2015-12-14 18:25   ` Alex Xu
2016-01-04 16:28     ` Ian Jackson
2016-01-04 16:42       ` Ian Campbell
2016-01-04 16:28   ` Ian Jackson

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.