Re: XForms: Xforms & command line parameters

Steve Lamont (spl@szechuan.ucsd.edu)
Fri, 11 Jul 97 06:55:58 PDT

To subscribers of the xforms list from spl@szechuan.ucsd.edu (Steve Lamont) :

> > Perhaps the solution is to use the built in argument parsing provided
> > by XForms. ...
> > ... I've even
> > hacked it to be "self-documenting," so that all the parameter
> > definitions, defaults, and explanations of the parameters are
> > effectively in one place.
>
> Could you provide a sketch of how you do that ?

I'm not sure which part you're asking about.

The standard form option handling is discussed in the manual, so I
won't bother to spend much time unless there's something unclear.
Refer to the discussion of resources in Appendix B, "Resources for
Forms Library," for much detail.

My "self-documentation" consists of adding fake definitions to the
FL_CMD_OPT structures. For instance, here's an elided excerpt from
the command options in one of my programs:

static FL_CMD_OPT command_options[] = {
OPTION( "-help",
".help",
XrmoptionNoArg,
"False",
"Prints this helpful message and quits" ),

/*
* -start, and -first are synonyms.
*/

OPTION( "-start",
".start",
XrmoptionSepArg,
NULL,
"Starting tilt (default %s degrees)" ),
OPTION( "-first",
".start",
XrmoptionSepArg,
NULL,
SYNONYM ),

OPTION( "-backlash",
".backlash",
XrmoptionNoArg,
"True",
"Turn on backlash correction." ),
OPTION( "-nobacklash",
".backlash",
XrmoptionNoArg,
"False",
MUTUALLY_EXCLUSIVE DEFAULT ),

OPTION( "-logfile",
".logfile",
XrmoptionSepArg,
NULL,
"Name of log file to be created (default '%s')" ),

[...]

The OPTION macro is defined as follows:

#define OPTION(flag,resource,xrmoption,default,help_stuff) \
{ \
flag, \
resource, \
xrmoption, \
default \
}, \
{ \
"-DeFiNiTiOn", \
".DeFiNiTiOn", \
XrmoptionNoArg, \
help_stuff \
}

The first part of the OPTION macro defines the standard FL_CMD_OPT
(really XrmOptionDescRec) structure members.

The second part declares a bogus resource that is never used
anywhere.

The `help_stuff' member is a string telling my help processor what to
print.

In its simplest form, it is just a string to be printed.

It may also include the `%s' formatting conversion symbol. In this
case, the default value for the option is inserted in the standard
fprintf() manner.

Finally, there are some special macro symbols, MUTUALLY_EXCLUSIVE,
DEFAULT, SYNONYM, and UNDOCUMENTED_OPTION, which tell the help
processor function to treat the option in some special manner.

The result is to print something like

pitstop:spl> xptomo -help
usage: xptomo [options]

where [options] are one or more of

-help Prints this helpful message and quits

[...]

-start Starting tilt (default -60.0 degrees)
-begin Synonym for -start

[...]

-backlash Turn on backlash correction.
-nobacklash Mutually exclusive with -backlash (Default)
-logfile Name of log file to be created (default 'xptomo.log')

[...]

For more information, type

man xptomo

or use xptomo's online "Help?" button.

The support code is relatively straightforward, complicated only by
the special option and default string printing handler, but still a
bit longer than I'd care to post in this already too long posting. If
anyone is interested, I'll be happy to arrange to share the code.

spl

_________________________________________________
To unsubscribe, send the message "unsubscribe" to
xforms-request@bob.usuf2.usuhs.mil or see
http://bob.usuf2.usuhs.mil/mailserv/xforms.html
Xforms Home Page: http://bragg.phys.uwm.edu/xforms
List Archive: http://bob.usuf2.usuhs.mil/mailserv/list-archives/