Gentoo Archives: gentoo-dev

From: Fabian Groffen <grobian@g.o>
To: gentoo-dev@l.g.o
Subject: Re: [gentoo-dev] RFC: sed script redundancy
Date: Sun, 29 May 2011 11:01:42
Message-Id: 20110529110032.GW24801@gentoo.org
In Reply to: Re: [gentoo-dev] RFC: sed script redundancy by Christopher Schwan
1 On 29-05-2011 12:44:46 +0200, Christopher Schwan wrote:
2 > Thank you for that script. I experimented a bit with it and have a number of
3 > corrections and suggestions:
4 >
5 > - alias does not work because my_sed is not declared at this stage. I removed
6 > the whole alias line because I want to selectively enable my_sed
7 > - oargs must be an array in order to make quoting work:
8 >
9 > local oargs=( "${@}" )
10 >
11 > - In the ewarn line ${oargs} should be changed to ${nargs[@]} (!?)
12 > - is it correct to treat -e and -f alike ? I am not sure about that, because
13 > the latter expects a file
14
15 Yes, because (also in your function) you always shift, and assume the
16 next argument is there. Hence, you have two identical cases in your
17 script now. I only distinguised between 1) being able to do something
18 (-i) and 2) having a pattern to work with (-e/-f or first non-option
19 argument as string pattern).
20
21 > - If no "-e" is given, the first non-option argument is treated as the sed-
22 > script-expression, therefore I added hade=yes in the if-branch
23
24 That one was missing indeed. I just quickly wrote the proof of concept
25 :)
26
27 > The new function now reads:
28 >
29 [snip improved function]
30 >
31 > As you can see, I added support for long-options. However, testing the
32 > individual sed commands remains to be done. This could be especially difficult
33 > if input is taken from stdin (e.g. in cat foo | sed "s:a:b:g").
34
35 You might be able to detect input is a pipe, and temporarily
36 write the input to some file, then perform the sed without the -i
37 requirement and remove the temp file after the real sed.
38
39 > I tested my_sed within our sage ebuild[1]. This ebuild contains 39 sed
40 > commands and I was able to spot one useless sed.
41
42 Cool, nice to see you've made it into something useful!
43
44 > [1] https://github.com/cschwan/sage-on-gentoo/blob/master/sci-
45 > mathematics/sage/sage-4.7.ebuild
46
47
48 --
49 Fabian Groffen
50 Gentoo on a different level

Replies

Subject Author
Re: [gentoo-dev] RFC: sed script redundancy Christopher Schwan <cschwan@××××××××××××××××××.de>