xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Alex Xu <alex_y_xu@yahoo.ca>
To: xen-devel@lists.xen.org
Cc: keir@xen.org, ian.jackson@eu.citrix.com, ian.campbell@citrix.com,
	jbeulich@suse.com, tim@xen.org
Subject: Re: [PATCH] xen/tools/get-fields.sh: Use printf for POSIX compat
Date: Mon, 14 Dec 2015 13:25:55 -0500	[thread overview]
Message-ID: <20151214132555.16914efb.alex_y_xu@yahoo.ca> (raw)
In-Reply-To: <20151214132228.3dda030a.alex_y_xu@yahoo.ca>

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.

  reply	other threads:[~2015-12-14 18:25 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-12-12 18:18 [PATCH] xen/tools/get-fields.sh: Use printf for POSIX compat 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 [this message]
2016-01-04 16:28     ` Ian Jackson
2016-01-04 16:42       ` Ian Campbell
2016-01-04 16:28   ` Ian Jackson
  -- strict thread matches above, loose matches on Subject: below --
2015-12-20 16:41 Alex Xu
2015-12-21 11:35 ` Jan Beulich
2015-12-21 15:29 Alex Xu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20151214132555.16914efb.alex_y_xu@yahoo.ca \
    --to=alex_y_xu@yahoo.ca \
    --cc=ian.campbell@citrix.com \
    --cc=ian.jackson@eu.citrix.com \
    --cc=jbeulich@suse.com \
    --cc=keir@xen.org \
    --cc=tim@xen.org \
    --cc=xen-devel@lists.xen.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).