From: Clement Chauplannaz <chauplac@gmail.com>
To: linux-kbuild@vger.kernel.org
Cc: mmarek@suse.cz, ak@linux.intel.com, yann.morin.1998@free.fr
Subject: [PATCH] scripts/config: use sed's POSIX interface
Date: Wed, 10 Jul 2013 21:58:08 +0200 [thread overview]
Message-ID: <1373486288-715-1-git-send-email-chauplac@gmail.com> (raw)
Script `config' relies on extensions of `GNU sed', and is thus not
working on all Unixes:
- in-place edition of files (-i), which can be replaced with
a temporary file;
- extended-regexps (-r), which can be split into basic regexps;
- single-line calls to `a' command, while some implementations
require a leading newline before the parameter.
Rewrite calls to `sed' program to comply with POSIX interface.
Signed-off-by: Clement Chauplannaz <chauplac@gmail.com>
---
scripts/config | 12 +++++++++---
1 file changed, 9 insertions(+), 3 deletions(-)
diff --git a/scripts/config b/scripts/config
index a65ecbb..3fd95eb 100755
--- a/scripts/config
+++ b/scripts/config
@@ -66,9 +66,14 @@ set_var() {
name_re="^($name=|# $name is not set)"
before_re="^($before=|# $before is not set)"
if test -n "$before" && grep -Eq "$before_re" "$FN"; then
- sed -ri "/$before_re/a $new" "$FN"
+ lf=$'\n'
+ sed -e "/^$before=/a\\$lf$new$lf" \
+ -e "/^# $before is not set/a\\$lf$new$lf" "$FN" >"$FN.swp"
+ mv "$FN.swp" "$FN"
elif grep -Eq "$name_re" "$FN"; then
- sed -ri "s:$name_re.*:$new:" "$FN"
+ sed -e "s:^$name=.*:$new:" \
+ -e "s:^# $name is not set:$new:" "$FN" >"$FN.swp"
+ mv "$FN.swp" "$FN"
else
echo "$new" >>"$FN"
fi
@@ -77,7 +82,8 @@ set_var() {
undef_var() {
local name=$1
- sed -ri "/^($name=|# $name is not set)/d" "$FN"
+ sed -e "/^$name=/d" -e "/^# $name is not set/d" "$FN" >"$FN.swp"
+ mv "$FN.swp" "$FN"
}
if [ "$1" = "--file" ]; then
--
1.8.3.rc1.44.gb387c77.dirty
next reply other threads:[~2013-07-10 19:58 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-07-10 19:58 Clement Chauplannaz [this message]
2013-07-10 20:38 ` [PATCH] scripts/config: use sed's POSIX interface Yann E. MORIN
2013-07-10 22:20 ` Clément Chauplannaz
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=1373486288-715-1-git-send-email-chauplac@gmail.com \
--to=chauplac@gmail.com \
--cc=ak@linux.intel.com \
--cc=linux-kbuild@vger.kernel.org \
--cc=mmarek@suse.cz \
--cc=yann.morin.1998@free.fr \
/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