diff mbox series

Make mktokens accept a random TMPDIR, replace `...` with $(...).

Message ID CAEtFKss1twXBC_w0LZMmpD+cAhzpZrAda3HcrEP_yEGLAp+WMA@mail.gmail.com (mailing list archive)
State Changes Requested
Delegated to: Herbert Xu
Headers show
Series Make mktokens accept a random TMPDIR, replace `...` with $(...). | expand

Commit Message

Devin Hussey Nov. 15, 2018, 3:32 p.m. UTC
From b9724fc82eda2b0d164c33ad3e871d38b298d1ad Mon Sep 17 00:00:00 2001
From: Devin Hussey <husseydevin@gmail.com>
Date: Thu, 15 Nov 2018 10:30:05 -0500
Subject: [PATCH] Make mktokens accept a random TMPDIR, replace `...` with
 $(...).

Sorry about the multiple commits at once.

Signed-off-by: Devin Hussey <husseydevin@gmail.com>
---
 src/mktokens | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)

Comments

Eric Blake Nov. 15, 2018, 3:43 p.m. UTC | #1
On 11/15/18 9:32 AM, Devin Hussey wrote:
>>From b9724fc82eda2b0d164c33ad3e871d38b298d1ad Mon Sep 17 00:00:00 2001
> From: Devin Hussey <husseydevin@gmail.com>
> Date: Thu, 15 Nov 2018 10:30:05 -0500
> Subject: [PATCH] Make mktokens accept a random TMPDIR, replace `...` with
>   $(...).
> 
> Sorry about the multiple commits at once.
> 
> Signed-off-by: Devin Hussey <husseydevin@gmail.com>
> ---
>   src/mktokens | 17 ++++++++++-------
>   1 file changed, 10 insertions(+), 7 deletions(-)
> 
> diff --git a/src/mktokens b/src/mktokens
> index cd52241..ec801cc 100644
> --- a/src/mktokens
> +++ b/src/mktokens
> @@ -37,7 +37,10 @@
>   # token marks the end of a list.  The third column is the name to print in
>   # error messages.
> 
> -cat > /tmp/ka$$ <<\!
> +# set TMPDIR if it isn't already
> +[ -z "${TMPDIR}" ] && TMPDIR="/tmp"

Shorter as:

: "${TMPDIR:=/tmp}"
Devin Hussey Nov. 15, 2018, 4:35 p.m. UTC | #2
From 31afca233f67dde67181efd7ed594cd2c25fefa6 Mon Sep 17 00:00:00 2001
From: Devin Hussey <husseydevin@gmail.com>
Date: Thu, 15 Nov 2018 10:30:05 -0500
Subject: [PATCH] Make mktokens accept a random TMPDIR, replace `...` with
 $(...).

Sorry about the multiple commits at once.

Signed-off-by: Devin Hussey <husseydevin@gmail.com>
---
 src/mktokens | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)

diff --git a/src/mktokens b/src/mktokens
index cd52241..9e56c10 100644
--- a/src/mktokens
+++ b/src/mktokens
@@ -37,7 +37,10 @@
 # token marks the end of a list.  The third column is the name to print in
 # error messages.

-cat > /tmp/ka$$ <<\!
+# set TMPDIR if it isn't already
+: "${TMPDIR:=/tmp}"
+
+cat > "${TMPDIR}/ka$$" <<\!
 TEOF    1    end of file
 TNL    0    newline
 TSEMI    0    ";"
@@ -68,28 +71,28 @@ TWHILE    0    "while"
 TBEGIN    0    "{"
 TEND    1    "}"
 !
-nl=`wc -l /tmp/ka$$`
+nl=$(wc -l "${TMPDIR}/ka$$")
 exec > token.h
-awk '{print "#define " $1 " " NR-1}' /tmp/ka$$
+awk '{print "#define " $1 " " NR-1}' "${TMPDIR}/ka$$"

 exec > token_vars.h

 echo '
 /* Array indicating which tokens mark the end of a list */
 static const char tokendlist[] = {'
-awk '{print "\t" $2 ","}' /tmp/ka$$
+awk '{print "\t" $2 ","}' "${TMPDIR}/ka$$"
 echo '};

 static const char *const tokname[] = {'
 sed -e 's/"/\\"/g' \
     -e 's/[^     ]*[     ][     ]*[^     ]*[     ][     ]*\(.*\)/    "\1",/' \
-    /tmp/ka$$
+    "${TMPDIR}/ka$$"
 echo '};
 '
-sed 's/"//g' /tmp/ka$$ | awk '
+sed 's/"//g' "${TMPDIR}/ka$$" | awk '
 /TNOT/{print "#define KWDOFFSET " NR-1; print "";
       print "static const char *const parsekwd[] = {"}
 /TNOT/,/neverfound/{if (last) print "    \"" last "\","; last = $3}
 END{print "    \"" last "\"\n};"}'

-rm /tmp/ka$$
+rm "${TMPDIR}/ka$$"
Herbert Xu Dec. 14, 2018, 4:58 a.m. UTC | #3
Devin Hussey <husseydevin@gmail.com> wrote:
> From 31afca233f67dde67181efd7ed594cd2c25fefa6 Mon Sep 17 00:00:00 2001
> From: Devin Hussey <husseydevin@gmail.com>
> Date: Thu, 15 Nov 2018 10:30:05 -0500
> Subject: [PATCH] Make mktokens accept a random TMPDIR, replace `...` with
> $(...).
> 
> Sorry about the multiple commits at once.
> 
> Signed-off-by: Devin Hussey <husseydevin@gmail.com>
> ---
> src/mktokens | 17 ++++++++++-------
> 1 file changed, 10 insertions(+), 7 deletions(-)

Thanks for the patch.

For whatever the current patchwork no longer accepts patches sent
as replies to an existing patch.

So please resubmit this patch under its own Subject.

Cheers,
diff mbox series

Patch

diff --git a/src/mktokens b/src/mktokens
index cd52241..ec801cc 100644
--- a/src/mktokens
+++ b/src/mktokens
@@ -37,7 +37,10 @@ 
 # token marks the end of a list.  The third column is the name to print in
 # error messages.

-cat > /tmp/ka$$ <<\!
+# set TMPDIR if it isn't already
+[ -z "${TMPDIR}" ] && TMPDIR="/tmp"
+
+cat > "${TMPDIR}/ka$$" <<\!
 TEOF    1    end of file
 TNL    0    newline
 TSEMI    0    ";"
@@ -68,28 +71,28 @@  TWHILE    0    "while"
 TBEGIN    0    "{"
 TEND    1    "}"
 !
-nl=`wc -l /tmp/ka$$`
+nl=$(wc -l "${TMPDIR}/ka$$")
 exec > token.h
-awk '{print "#define " $1 " " NR-1}' /tmp/ka$$
+awk '{print "#define " $1 " " NR-1}' "${TMPDIR}/ka$$"

 exec > token_vars.h

 echo '
 /* Array indicating which tokens mark the end of a list */
 static const char tokendlist[] = {'
-awk '{print "\t" $2 ","}' /tmp/ka$$
+awk '{print "\t" $2 ","}' "${TMPDIR}/ka$$"
 echo '};

 static const char *const tokname[] = {'
 sed -e 's/"/\\"/g' \
     -e 's/[^     ]*[     ][     ]*[^     ]*[     ][     ]*\(.*\)/    "\1",/' \
-    /tmp/ka$$
+    "${TMPDIR}/ka$$"
 echo '};
 '
-sed 's/"//g' /tmp/ka$$ | awk '
+sed 's/"//g' "${TMPDIR}/ka$$" | awk '
 /TNOT/{print "#define KWDOFFSET " NR-1; print "";
       print "static const char *const parsekwd[] = {"}
 /TNOT/,/neverfound/{if (last) print "    \"" last "\","; last = $3}
 END{print "    \"" last "\"\n};"}'

-rm /tmp/ka$$
+rm "${TMPDIR}/ka$$"