Next: , Previous: , Up: Genparse File Syntax   [Contents][Index]

4.3 Usage Function

Genparse also generates a usage () function which prints a help text to stdout about the usage of the program for which Genparse is generating the parser. It is automatically executed when

This usage function can be customized by specifying a usage section at the bottom of the Genparse file. If no such section is specified it defaults to

#usage_begin
usage: __PROGRAM_NAME__ __OPTIONS_SHORT__ __MANDATORIES__
__GLOSSARY__
#usage_end

The usage section starts with #usage_begin and ends with #usage_end. Any text between is printed verbatim except for the following keywords, which will be replaced as listed below:

long options can be followed by an = sign and an optional designation opt_name in the genparse file (See Parameter Definitions.) which can be referred to in the following description (See parameter-description.). It will be used in the usage () function only. For example the following genparse line

s / block-size=SIZE		int	"use SIZE-byte blocks"

will lead to the following line in the help screen

   [ -s ] [ --block-size=SIZE ] (type=INTEGER)
          use SIZE-byte blocks

in genparse style (See __GLOSSARY__.) or

   -s, --block-size=SIZE   use SIZE-byte blocks

in GNU style (See __GLOSSARY_GNU__.).

It is also possible to put square braces around the optional name in order to indicate that the argument is optional. This has no meaning for the generated parser however. Use * postfixes in order to make an argument optional (See optional_arguments.).

s* / block*[=SIZE]	int	"use blocks."
                                "If SIZE is not given then they will get a size of 1kB."

will lead to the following line in the help screen

   -s, --block[=SIZE]   use blocks.
                        If SIZE is not given then they will get a size of 1kB.

For an example of the generated default usage () function in C See Parser Files.


Next: , Previous: , Up: Genparse File Syntax   [Contents][Index]