Using getopt to parse multi-argument options

Henry Spencer henry at utzoo.uucp
Mon Jan 16 12:37:12 AEST 1989


In article <3652 at phri.UUCP> roy at phri.UUCP (Roy Smith) writes:
>	I'm writing a program which will take an optional range, in the
>style of graph(1)'s "-x xmin xmax".  How do I tell getopt to parse
>something like that? ...

You can't.  The only getopt-compatible way is to require the user to
say "-x 'xmin xmax'" instead, and have your code pull the single argument
apart.  This is what the AT&T syntax standard mandates (with the further
flourish that tabs and commas must work as separators, not just spaces,
as I recall).

Nobody has ever pretended that getopt or the syntax standard could handle
all the old weird programs that hack their arguments in their own strange
ways.  From personal experience, I can testify that life is a lot better
when everything uses getopt, even if this means some aggravation over
backward compatibility.  Just having things consistent is a huge win.
-- 
"God willing, we will return." |     Henry Spencer at U of Toronto Zoology
-Eugene Cernan, the Moon, 1972 | uunet!attcan!utzoo!henry henry at zoo.toronto.edu



More information about the Comp.lang.c mailing list