Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.1 6/24/83; site ttrdc.UUCP Path: utzoo!watmath!clyde!burl!ulysses!mhuxr!mhuxn!ihnp4!mgnetp!ltuxa!ttrdc!levy From: levy@ttrdc.UUCP (Daniel R. Levy) Newsgroups: net.sources.bugs Subject: Re: getopt(3) posting Message-ID: <515@ttrdc.UUCP> Date: Wed, 23-Oct-85 20:24:46 EDT Article-I.D.: ttrdc.515 Posted: Wed Oct 23 20:24:46 1985 Date-Received: Fri, 25-Oct-85 02:01:29 EDT References: <910@utcs.uucp> <306@graffiti.UUCP> <444@seismo.CSS.GOV> <324@graffiti.UUCP> Organization: AT&T, Computer Systems Division, Skokie, IL Lines: 37 In article <324@graffiti.UUCP>, peter@graffiti.UUCP (Peter da Silva) writes: > connect: a UNIX modem program that I wrote. It allows a series of >phone numbers on the command line & keeps trying them until it gets one that >works. Handy for calling bbs-es: > usage: connect -s -l number... > Note: direct is considered a number for compatibility with cu. > > connect -s 1200 4445555 4446666 -s300 5556666 6667777 -l tty1 direct > >How would you deal with that using getopt, which seems to require that all >options be before all arguments? > >Peter da Silva Maybe with a bit of change in the command line syntax, it would be amenable to getopt. Remember, that there is nothing keeping the same flag from being used more than once: connect -s 1200 -n 4445555,4446666 -s300 -n 5556666,6667777 -l tty1 direct If you MUST keep the original syntax (mixing flags with nonflag arguments) you can still use getopt with a little bit of shimming. Just increment optind (presuming it is still smaller than argc) after getopt has returned EOF, check that the first character of the corresponding argument is a '-' (i.e., another flag, else handle the argument specially) then jump back into the loop calling getopt. It's still cleaner looking inside the program than a brute force parse. Of course someone is going to ask what if the argument was supposed to begin with '-' and it is not a flag. Oh well, life ain't easy.... -- ------------------------------- Disclaimer: The views contained herein are | dan levy | yvel nad | my own and are not at all those of my em- | an engihacker @ | ployer or the administrator of any computer | at&t computer systems division | upon which I may hack. | skokie, illinois | -------------------------------- Path: ..!ihnp4!ttrdc!levy