rc-list - mailing list for the rc(1) shell
 help / color / mirror / Atom feed
From: malte@techfak.uni-bielefeld.de
To: rc@archone.tamu.edu
Subject: new version of getopts and a question
Date: Thu, 17 Oct 1991 09:52:52 -0500	[thread overview]
Message-ID: <9110171452.AA05117@dahlie.techfak.uni-bielefeld.de> (raw)

I recently posted my rc version of bourne sh getopts. I'm sorry to say
that this one was in an intermediate state. It did not handle '-n'
correctly. Another error was that error messages were put on stdout.

Now, here is a new enhanced(?) version which regards options like '-xy'
as an error if -x does not expect arguments. If you want getopts to
silently ignore the 'y', comment out

	} else if( ~ $^3 -??* ){
		echo 'too many arguments to -'$$2 >[1=2].

This will result in full compatibility with the last version.


fn getopts {
	if( ~ $#* 0 1 2 ){ return 1 }	# no arguments to process

	OPTSTRING=`` ($ifs ':') { echo $^1 | sed '1s|.|& |g' };
	OPTSTRING='-'^$OPTSTRING;

	switch($^3){
		case --   ; return 1
		case -?   ; OPTARG=($^3 $^4)
			    OPTIND=2
		case -??* ; OPTARG=`{echo $^3 | sed '1s|\(..\)\(.*\)|\1 \2|'}
			    OPTIND=1
		case *    ; return 1
	}
	if( ~ $OPTARG(1) $OPTSTRING ){
		$2=`` ($ifs '-') { echo -- $OPTARG(1) }
		if( ~ $^1 *$$^2:* ){
			OPTARG=$OPTARG(2)
			if( ~ $#OPTARG 0 ){
				echo 'too few arguments to -'$$2 >[1=2]
				exit 1
			}
		} else if( ~ $^3 -??* ){
			echo 'too many arguments to -'$$2 >[1=2]
		} else {
			OPTARG=() OPTIND=1
		}
	} else {
		echo invalid argument $OPTARG(1) >[1=2]
		OPTARG='-?'
		return 1
	}
	return 0
}

Now the question: As I understand it,
	case -??* ; OPTARG=`{echo $^3 | sed '1s|\(..\)\(.*\)|\1 \2|'}
and
	case -??* ; OPTARG=`{sed '1s|\(..\)\(.*\)|\1 \2|' <<< $^3}
should be identical. Am I wrong, or have I discovered a bug?


_______________________________________________________________________________
malte@techfak.uni-bielefeld.de

send mail reply to:	Universitaet Bielefeld, Technische Fakultaet
		z. Hd. Malte Uhl
		Postfach 8640
		4800 Bielefeld 1



                 reply	other threads:[~1991-10-17 14:53 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=9110171452.AA05117@dahlie.techfak.uni-bielefeld.de \
    --to=malte@techfak.uni-bielefeld.de \
    --cc=rc@archone.tamu.edu \
    /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;
as well as URLs for NNTP newsgroup(s).