From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from pearl.eecs.unsw.oz.au ([129.94.128.185]) by archone.tamu.edu with SMTP id <22534>; Fri, 6 Sep 1991 08:29:03 -0500 Received: from chiton.eecs.unsw.OZ.AU by pearl.eecs.unsw.oz.au (5.65/SMI-4.1) id AA25353; Fri, 6 Sep 91 23:28:33 +1000 Received: by chiton (4.1/4.7) id AA04737; Fri, 6 Sep 91 23:27:22 EST (from mackin) From: John Mackin Date: Fri, 6 Sep 1991 08:01:10 -0500 To: The rc Mailing List Subject: Re: how to 'getopts' in rc In-Reply-To: <9109051902.AA00517@dahlie.techfak.uni-bielefeld.de> Message-Id: <9109062301.4705.rc.babad@vast.eecs.unsw.oz> X-Face: 39seV7n\`#asqOFdx#oj/Uz*lseO_1n9n7rQS;~ve\e`&Z},nU1+>0X^>mg&M.^X$[ez>{F k5[Ah<7xBWF-@-ru?& @4K4-b`ydd^`(n%Z{ Could anyone on the list who wants to send me mail privately please note my new address. The address I was at previously is no longer valid (and I mean that -- it will not forward). Malte asks: How would you do it in rc or should getopts be a rc builtin? Well, I think no one on the list would seriously campaign to have a getopts builtin (at least, I _sincerely hope_ no one would). It would be easy, if a little tedious, to code up a getopts rough-equivalent; one could either take an approach of doing most of the work in rc, or of making it a function that wrapped around getopt(1) (which is easily available in the public domain) and got that to do most of the work. But hey! This is rc! Why hamstring ourselves with old-style interfaces, when we can do much cuter things -- things that were only _theoretically_ possible in sh, since in any attempt to implement them in practice, the quoting would have gotten totally out of control. I have in mind a function along the following rough lines: * = ` { getopts opt1 'code1' opt2 'code2' ... - $* } where each fragment of rc code gets executed if the corresponding option is present. The assignment to * is necessary, since a function can't affect the $* of the enclosing level. So, for example, if you have options x and q, and option f that takes an option argument, you might write: * = ` { getopts x 'dashx = true' q 'dashq = true' \ f: 'dashf = $optarg' - $* } I think that's a much nicer interface than the getopt(1) style supported by the getopts builtin, mainly because the option letter and the code for the option are right next to each other. I haven't coded this up in rc (I'm unemployed right now, and I don't have much computer access), but I don't see any reason why it should be at all difficult. The only thing that's not perfectly nice, in my view, about this is the fact you have to explicitly pass $*, and explicitly assign to it; that, however, is the price that must be paid for getopts not being a builtin, and I am sure we are all quite willing to pay it. OK, John.