[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Groff] Re: getopt() as gtroff macro ?
From: |
Werner LEMBERG |
Subject: |
Re: [Groff] Re: getopt() as gtroff macro ? |
Date: |
Thu, 23 Sep 2004 13:20:47 +0200 (CEST) |
> >> I think this is important and, while I admire what Keith has
> >> done, I wonder if there's any way to get a getopt built into
> >> gtroff?
> >
> > Nice idea. What exactly do you have in mind? Can you make syntax
> > suggestions?
>
> I agree, this would be a nice feature to have. Perhaps something
> along the lines of the shell's built-in 'getopts' command?
>
> The main problem I foresee is, how do you implement the call backs
> needed, to allow getopt's caller to handle the optional arguments as
> they are parsed? This could end up being no simpler than the
> technique I suggested earlier, but it would be great if we can
> identify a viable solution.
What about the following (inspired by Python's getopt module):
.getopt <prefix> <options> <long options>
Example:
.de foo
. getopt "foox" "ac:" "--all --check="
. ...
..
The .getopt command would call the functions `<prefix>-<option>', passing
the corresponding values as arguments. `<prefix>-?' (with <option> as
the argument) is called if <option> is invalid. Finally, all
non-option arguments are passed to a macro called `<prefix>'.
Calling the above function like this
.foo -a -c bar --all --check=urgh --xxx arg1 arg2
would consequently call the functions
.foox-a
.foox-c bar
.foox--all
.foox--check urgh
.foox-? --xxx
.foox arg1 arg2
It probably makes sense to provide a .gnu-getopt request also to
reorder the arguments.
Comments, please.
Werner
[Groff] Re: getopt() as gtroff macro ?, Steve Izma, 2004/09/23
Re: [Groff] Re: getopt() as gtroff macro ?, Keith MARSHALL, 2004/09/24