[prev in list] [next in list] [prev in thread] [next in thread] 

List:       gentoo-dev
Subject:    Re: [gentoo-dev] RFC: sed script redundancy
From:       Christopher Schwan <cschwan () students ! uni-mainz ! de>
Date:       2011-05-29 11:49:50
Message-ID: 201105291349.50497.cschwan () students ! uni-mainz ! de
[Download RAW message or body]

On Sunday 29 May 2011 13:00:32 Fabian Groffen wrote:
> On 29-05-2011 12:44:46 +0200, Christopher Schwan wrote:
> > Thank you for that script. I experimented a bit with it and have a number
> > of corrections and suggestions:
> > 
> > - alias does not work because my_sed is not declared at this stage. I
> > removed the whole alias line because I want to selectively enable my_sed
> > 
> > - oargs must be an array in order to make quoting work:
> >    local oargs=( "${@}" )
> > 
> > - In the ewarn line ${oargs} should be changed to ${nargs[@]} (!?)
> > - is it correct to treat -e and -f alike ? I am not sure about that,
> > because the latter expects a file
> 
> Yes, because (also in your function) you always shift, and assume the
> next argument is there.  Hence, you have two identical cases in your
> script now.  I only distinguised between 1) being able to do something
> (-i) and 2) having a pattern to work with (-e/-f or first non-option
> argument as string pattern).

Ok sorry - I did not express myself clearly. Your script is replacing "-f" 
with "-e" and I wasnt sure if this is correct. Buf of course, they can be 
treated alike:

-e|--expression|-f|--file)
	arg="$1"
	shift
	nargs+=( "${arg}" "$1" )
	hade=yes
	;;

> 
> > - If no "-e" is given, the first non-option argument is treated as the
> > sed- script-expression, therefore I added hade=yes in the if-branch
> 
> That one was missing indeed.  I just quickly wrote the proof of concept
> 
> :)
> :
> > The new function now reads:
> [snip improved function]
> 
> > As you can see, I added support for long-options. However, testing the
> > individual sed commands remains to be done. This could be especially
> > difficult if input is taken from stdin (e.g. in cat foo | sed
> > "s:a:b:g").
> 
> You might be able to detect input is a pipe, and temporarily
> write the input to some file, then perform the sed without the -i
> requirement and remove the temp file after the real sed.

Good idea, thanks!

> 
> > I tested my_sed within our sage ebuild[1]. This ebuild contains 39 sed
> > commands and I was able to spot one useless sed.
> 
> Cool, nice to see you've made it into something useful!
> 
> > [1] https://github.com/cschwan/sage-on-gentoo/blob/master/sci-
> > mathematics/sage/sage-4.7.ebuild

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic