groff
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Groff] Re: getopt() as gtroff macro ?


From: Werner LEMBERG
Subject: [Groff] Re: getopt() as gtroff macro ?
Date: Fri, 24 Sep 2004 16:44:19 +0200 (CEST)

> >   Introduce a request `local' to tag local variables:
> > 
> >     .de foo
> >     .  local nr bar 12345
> >     ..

Actually, it would be

  .local .nr bar 12345

in analogy to the .do request.

> Somewhere I recall a description of calling a macro (or perhaps a
> string?) with an argument this way: \[macroname arg1], so that
> you could do:
> 
> .sp \[calcspace \\n[sizeof_subhead]]u

This works for strings only.

> I like python's facility for this, but one reason, I think, that it
> works so well is because of how easy it is in python to step through
> a list, so that you can set up a "while" loop and step through each
> option and write the appropriate code for each one, if it's present.
> I would prefer to avoid calling outside macros to process the
> options and instead just be able to set flags and variables.

See below.

> How about having getopt set local variables based on the option
> names,

That would be

  .local .getopt ...

> both the long or the short ones (one could choose between
> readability and conciseness).  Flags would always be numeric
> (essentially boolean) and options with values would always return a
> string, which if numeric would require a unit designator (as above).
> If the string is used in a numeric context, it would be converted to
> that first:

Maybe a synthesis of a function call for error handling and register
assignments is the way to go.  Here another try, incorporating your
ideas:

  .getopt <prefix> <options> <long options> <arguments>

Example:

  .de foo
  .  getopt "foox" "ac:" "--all --check=" \\$@
  .  ...
  ..

The .getopt command would do

  .ds <prefix><option> <argument>    \" option with argument
  .nr <prefix><option> 1             \" option without argument

It will call the function `<prefix>-?' (with <option> as the argument)
if <option> is invalid.  Finally, it will apply a proper `.shift' call
so that after .getopt parameter \$1 is the first non-option argument.

Calling the above function like this

  .foo -a -c bar --all --check=urgh --xxx arg1 arg2

would consequently do the following assignments

  .nr foox-a 1
  .ds foox-c bar
  .nr foox--all 1
  .ds foox--check urgh

and this macro call:

  .foox-? --xxx


     Werner




reply via email to

[Prev in Thread] Current Thread [Next in Thread]