[illumos-Developer] sed -i behavior - question

Joerg Schilling Joerg.Schilling at fokus.fraunhofer.de
Wed Dec 22 02:02:35 PST 2010


"Garrett D'Amore" <garrett at damore.org> wrote:

> > then just punt and do it Jorge's way.  It is at least reasonable.
>
>
> I think I'm coming to that conclusion.   It looks like there will be 
> some effort to make that happen, since the existing getopt() can't cope 
> with that.  Any volunteers, or need I make this change myself? :-)

It can be easily done with the getargs() function from libschily. getargs()
supports flags characters (similar to printf) to control the behavior for each 
option.

As getargs() is much older than getopt(), it however has a different interface.
See the od(1) implementation in hdump/hdump.c for a template on how to switch 
it into POSIX mode and on how to deal with options that depend on the order in 
the command line and see mkisofs/mkisofs.c for a template on how to deal with 
really many options and how to combine options with usage strings in a similar 
way as it is done in GNU ld(1).

The format string "i*" is for an option -i with a string arg and allows both
-i arg and -iarg.

	"i* " enforces a space between option and arg (this is e.g. used by 
		mkisofs	to deal with the long options introduced by Eric 
		Youngdale that only differ after a common substring at the 
		beginning.

	"i*_" forbids -i arg and only allows -iarg

getargs() returns "" as argument string in case -i is called without arg and the 
format string is "i*_".

Jörg

-- 
 EMail:joerg at schily.isdn.cs.tu-berlin.de (home) Jörg Schilling D-13353 Berlin
       js at cs.tu-berlin.de                (uni)  
       joerg.schilling at fokus.fraunhofer.de (work) Blog: http://schily.blogspot.com/
 URL:  http://cdrecord.berlios.de/private/ ftp://ftp.berlios.de/pub/schily



More information about the Developer mailing list