Skip to contentSkip to conversation

update_unicode.sh: simplify output capture

PATCH Superseded [email protected] 3 participants 9 messages Jun 15, 2016

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/5 update_unicode.sh: simplify output capture

From: Beat Bolli <[email protected]>

Instead of capturing the output of each echo and uniset invocation, wrap the whole section in a group command and redirect its output all at once.

---
 update_unicode.sh | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)
update_unicode.sh +9 -8
index 000b937..c1c876c 100755
@@ -26,12 +26,13 @@ fi &&
 			./configure --enable-warnings=-Werror CFLAGS='-O0 -ggdb'
 		fi &&
 		make
-	) &&
-	echo "static const struct interval zero_width[] = {" >$UNICODEWIDTH_H &&
-	UNICODE_DIR=. ./uniset/uniset --32 cat:Me,Mn,Cf + U+1160..U+11FF - U+00AD |
-	grep -v plane >>$UNICODEWIDTH_H &&
-	echo "};" >>$UNICODEWIDTH_H &&
-	echo "static const struct interval double_width[] = {" >>$UNICODEWIDTH_H &&
-	UNICODE_DIR=. ./uniset/uniset --32 eaw:F,W >>$UNICODEWIDTH_H &&
-	echo "};" >>$UNICODEWIDTH_H
+	) && {
+		echo "static const struct interval zero_width[] = {" &&
+		UNICODE_DIR=. ./uniset/uniset --32 cat:Me,Mn,Cf + U+1160..U+11FF - U+00AD |
+		grep -v plane &&
+		echo "};" &&
+		echo "static const struct interval double_width[] = {" &&
+		UNICODE_DIR=. ./uniset/uniset --32 eaw:F,W &&
+		echo "};"
+	} >$UNICODEWIDTH_H
 )
Signature · 1 line
2.1.3
#2 lore raw

PATCH 3/5 update_unicode.sh: shorten uniset invocation path

From: Beat Bolli <[email protected]>

"uniset/uniset" is a relative path; there's no need to prefix it with "./".

---
 update_unicode.sh | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
update_unicode.sh +2 -2
index bed8916..f5cc14b 100755
@@ -29,11 +29,11 @@ fi &&
 	) && {
 		UNICODE_DIR=. && export UNICODE_DIR &&
 		echo "static const struct interval zero_width[] = {" &&
-		./uniset/uniset --32 cat:Me,Mn,Cf + U+1160..U+11FF - U+00AD |
+		uniset/uniset --32 cat:Me,Mn,Cf + U+1160..U+11FF - U+00AD |
 		grep -v plane &&
 		echo "};" &&
 		echo "static const struct interval double_width[] = {" &&
-		./uniset/uniset --32 eaw:F,W &&
+		uniset/uniset --32 eaw:F,W &&
 		echo "};"
 	} >$UNICODEWIDTH_H
 )
Signature · 1 line
2.1.3
#1 lore raw

PATCH 2/5 update_unicode.sh: set UNICODE_DIR only once

In reply to [email protected]

From: Beat Bolli <[email protected]>

The value is the same on both uniset invocations, so "Don't Repeat Yourself" applies.

Since we're in a subshell already, there's no need to unset UNICODE_DIR at the end.

---
 update_unicode.sh | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
update_unicode.sh +3 -2
index c1c876c..bed8916 100755
@@ -27,12 +27,13 @@ fi &&
 		fi &&
 		make
 	) && {
+		UNICODE_DIR=. && export UNICODE_DIR &&
 		echo "static const struct interval zero_width[] = {" &&
-		UNICODE_DIR=. ./uniset/uniset --32 cat:Me,Mn,Cf + U+1160..U+11FF - U+00AD |
+		./uniset/uniset --32 cat:Me,Mn,Cf + U+1160..U+11FF - U+00AD |
 		grep -v plane &&
 		echo "};" &&
 		echo "static const struct interval double_width[] = {" &&
-		UNICODE_DIR=. ./uniset/uniset --32 eaw:F,W &&
+		./uniset/uniset --32 eaw:F,W &&
 		echo "};"
 	} >$UNICODEWIDTH_H
 )
Signature · 1 line
2.1.3
#3 lore raw

PATCH 4/5 update_unicode.sh: Make the output structure visible

In reply to [email protected]

From: Beat Bolli <[email protected]>

By using printf instead of the echo/uniset sequence, the final structure of the generated file becomes obvious.

---
 update_unicode.sh | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)
update_unicode.sh +11 -7
index f5cc14b..61968d9 100755
@@ -28,12 +28,16 @@ fi &&
 		make
 	) && {
 		UNICODE_DIR=. && export UNICODE_DIR &&
-		echo "static const struct interval zero_width[] = {" &&
-		uniset/uniset --32 cat:Me,Mn,Cf + U+1160..U+11FF - U+00AD |
-		grep -v plane &&
-		echo "};" &&
-		echo "static const struct interval double_width[] = {" &&
-		uniset/uniset --32 eaw:F,W &&
-		echo "};"
+		printf "\
+static const struct interval zero_width[] = {
+%s
+};
+static const struct interval double_width[] = {
+%s
+};
+" \
+		"$(uniset/uniset --32 cat:Me,Mn,Cf + U+1160..U+11FF - U+00AD |
+		grep -v plane)" \
+		"$(uniset/uniset --32 eaw:F,W)"
 	} >$UNICODEWIDTH_H
 )
Signature · 1 line
2.1.3
#4 lore raw

Re: [PATCH 4/5] update_unicode.sh: Make the output structure visible

Quoted 2 lines · On Fri, Dec 19, 2014 at 03:39:30PM +0100, [email protected] wrote:

By using printf instead of the echo/uniset sequence, the final structure of the generated file becomes obvious.

This whole series looks pretty sane to me, and the result is easier to read.

I did wonder if a here-doc would be even easier than a PDF, like:

  cat >$UNICODEWIDTH_H <<-EOF
  static const struct interval zero_width[] = {
    $(uniset/uniset --32 cat:Me,Mn,Cf + U+1160..U+11FF - U+00AD | grep -v plane)
  };
  static const struct interval double_width[] = {
    $(uniset/uniset --32 eaw:F,W)
  };
  EOF

The nice thing is that <<- will strip leading tabs, which means you can indent properly to match the surrounding code. I don't know if you find the in-line $() more readable or not, though.

I think either way it is an improvement over the current state.

-Peff

#5 lore raw

Re: [PATCH 4/5] update_unicode.sh: Make the output structure visible

Quoted 19 lines · Jeff King
Quoted 2 lines · On Fri, Dec 19, 2014 at 03:39:30PM +0100, [email protected] wrote:

By using printf instead of the echo/uniset sequence, the final structure of the generated file becomes obvious.

This whole series looks pretty sane to me, and the result is easier to read.

I did wonder if a here-doc would be even easier than a PDF, like:

  cat >$UNICODEWIDTH_H <<-EOF
  static const struct interval zero_width[] = {
    $(uniset/uniset --32 cat:Me,Mn,Cf + U+1160..U+11FF - U+00AD | grep -v plane)
  };
  static const struct interval double_width[] = {
    $(uniset/uniset --32 eaw:F,W)
  };
  EOF
Quoted 3 lines

The nice thing is that <<- will strip leading tabs, which means you can indent properly to match the surrounding code. I don't know if you find the in-line $() more readable or not, though.

I think the code looks much nicer with a here doc.

Checking in t/, it looks that there's no consensus about whether to indent the content relative to the cat statement or not. What do you suggest?

Quoted 1 line

I think either way it is an improvement over the current state.

Thanks!

Beat

#6 lore raw

Re: [PATCH 4/5] update_unicode.sh: Make the output structure visible

Quoted 5 lines · Beat Bolli

I think the code looks much nicer with a here doc.

Checking in t/, it looks that there's no consensus about whether to indent the content relative to the cat statement or not. What do you suggest?

I think we typically do it at the same level as the cat. Checking "git grep -A1 '<<-'" does show a mix, but skimming over it I think what I suggested is more common.

-Peff

#7 lore raw

PATCH 5/5 update_unicode.sh: Delete the command group

In reply to [email protected]

From: Beat Bolli <[email protected]>

Now that the whole file is generated by one single command, the command group is no longer needed.

---
 update_unicode.sh | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)
update_unicode.sh +6 -7
index 61968d9..45bd12a 100755
@@ -26,9 +26,9 @@ fi &&
 			./configure --enable-warnings=-Werror CFLAGS='-O0 -ggdb'
 		fi &&
 		make
-	) && {
-		UNICODE_DIR=. && export UNICODE_DIR &&
-		printf "\
+	) &&
+	UNICODE_DIR=. && export UNICODE_DIR &&
+	printf "\
 static const struct interval zero_width[] = {
 %s
 };
@@ -36,8 +36,7 @@ static const struct interval double_width[] = {
 %s
 };
 " \
-		"$(uniset/uniset --32 cat:Me,Mn,Cf + U+1160..U+11FF - U+00AD |
-		grep -v plane)" \
-		"$(uniset/uniset --32 eaw:F,W)"
-	} >$UNICODEWIDTH_H
+	"$(uniset/uniset --32 cat:Me,Mn,Cf + U+1160..U+11FF - U+00AD |
+	grep -v plane)" \
+	"$(uniset/uniset --32 eaw:F,W)" >$UNICODEWIDTH_H
 )
Signature · 1 line
2.1.3
#8 lore raw
In reply to [email protected]
Quoted 1 line · On 19.12.14 15:39, [email protected] wrote:

From: Beat Bolli <[email protected]>

Sorry, it looks like git send-email borked these messages. This line should be part of the mail headers.

Regards,
Beat Bolli

Signature · 6 lines
https://drbeat.li
pgp: 0x506A903A; 49D5 794A EA77 F907 764F  D89E 304B 93CF 506A 903A
gsm: 4.7.7.6.0.7.7.9.7.1.4.e164.arpa
icbm: 47.0452 N, 7.2715 E

"It takes love over gold, and mind over matter" -- Dire Straits