From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from pigeon.gentoo.org ([208.92.234.80] helo=lists.gentoo.org) by finch.gentoo.org with esmtp (Exim 4.60) (envelope-from ) id 1QO6GJ-0005kG-FW for garchives@archives.gentoo.org; Sun, 22 May 2011 10:51:55 +0000 Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 62BFB1C01E; Sun, 22 May 2011 10:51:44 +0000 (UTC) Received: from amun.cheops.ods.org (amun.cheops.ods.org [83.161.135.166]) by pigeon.gentoo.org (Postfix) with ESMTP id E8A7D1C007 for ; Sun, 22 May 2011 10:51:09 +0000 (UTC) Received: from tefnut.cheops.ods.org ([2001:980:57a5:1:211:24ff:fe37:e46e] helo=gentoo.org) by amun.cheops.ods.org with esmtps (TLSv1:AES256-SHA:256) (Exim 4.76) (envelope-from ) id 1QO6FY-0006q8-E6 for gentoo-dev@lists.gentoo.org; Sun, 22 May 2011 12:51:09 +0200 Date: Sun, 22 May 2011 12:50:43 +0200 From: Fabian Groffen To: gentoo-dev@lists.gentoo.org Subject: Re: [gentoo-dev] RFC: sed script redundancy Message-ID: <20110522105043.GO24801@gentoo.org> Mail-Followup-To: gentoo-dev@lists.gentoo.org References: <20110520173922.391ea292@epia.jer-c2.orkz.net> <20110520155600.GB24801@gentoo.org> <20110521193434.3f623fa6@epia.jer-c2.orkz.net> Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-dev@lists.gentoo.org Reply-to: gentoo-dev@lists.gentoo.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20110521193434.3f623fa6@epia.jer-c2.orkz.net> User-Agent: Mutt/1.5.21 (Darwin 8.11.0, VIM - Vi IMproved 7.3) Organization: Gentoo Foundation, Inc. X-Content-Scanned: by amun.cheops.ods.org (Exim Exiscan) using SpamAssassin and ClamAV X-Archives-Salt: X-Archives-Hash: e865a3c5bf182a0d713de47c8e5f38c2 On 21-05-2011 19:34:34 +0200, Jeroen Roovers wrote: > On Fri, 20 May 2011 17:56:00 +0200 > Fabian Groffen wrote: > > > sed -e "" "${file}" | diff "${file}" - > > > > followed by the actual sed -i -e ... > > > > This way I didn't need to write an intermediate file. > > The problem there is that sed might be called just once on any one file, > but in the tree it is often invoked with multiple scripts, so this > simple implementation lacks a way to evaluate which sed scripts are > useful. > > Also, how do I ensure the sed replacement works only on invocations > inside the ebuild, and not, say, in portage's internals? (not tested, but as proof of concept) alias sed my_sed my_sed() { local oargs="${@}" local arg local nargs=() local hadi= local hade= while [[ -n $1 ]] ; do case "$1" in -i) # ignore this flag hadi=yes ;; -e|-f) shift nargs+=( "-e$1" ) hade=yes ;; -*) nargs+=( "$1" ) hade=yes ;; *) if [[ -z ${hade} ]] ; then nargs+=( "$1" ) elif [[ -z ${hadi} ]] ; then # there is no inline replacing, not much we can do break else sed "${nargs[@]}" "$1" | diff -q "$1" - > /dev/null \ && ewarn "sed ${oargs} has no effect on $1" fi ;; esac shift done \sed "${oargs}" } -- Fabian Groffen Gentoo on a different level