Blame manual/argp.texi

Packit Service 82fcde
@node Argp, Suboptions, Getopt, Parsing Program Arguments
Packit Service 82fcde
@need 5000
Packit Service 82fcde
@section Parsing Program Options with Argp
Packit Service 82fcde
@cindex argp (program argument parser)
Packit Service 82fcde
@cindex argument parsing with argp
Packit Service 82fcde
@cindex option parsing with argp
Packit Service 82fcde
Packit Service 82fcde
@dfn{Argp} is an interface for parsing unix-style argument vectors.
Packit Service 82fcde
@xref{Program Arguments}.
Packit Service 82fcde
Packit Service 82fcde
Argp provides features unavailable in the more commonly used
Packit Service 82fcde
@code{getopt} interface.  These features include automatically producing
Packit Service 82fcde
output in response to the @samp{--help} and @samp{--version} options, as
Packit Service 82fcde
described in the GNU coding standards.  Using argp makes it less likely
Packit Service 82fcde
that programmers will neglect to implement these additional options or
Packit Service 82fcde
keep them up to date.
Packit Service 82fcde
Packit Service 82fcde
Argp also provides the ability to merge several independently defined
Packit Service 82fcde
option parsers into one, mediating conflicts between them and making the
Packit Service 82fcde
result appear seamless.  A library can export an argp option parser that
Packit Service 82fcde
user programs might employ in conjunction with their own option parsers,
Packit Service 82fcde
resulting in less work for the user programs.  Some programs may use only
Packit Service 82fcde
argument parsers exported by libraries, thereby achieving consistent and
Packit Service 82fcde
efficient option-parsing for abstractions implemented by the libraries.
Packit Service 82fcde
Packit Service 82fcde
@pindex argp.h
Packit Service 82fcde
The header file @file{<argp.h>} should be included to use argp.
Packit Service 82fcde
Packit Service 82fcde
@subsection The @code{argp_parse} Function
Packit Service 82fcde
Packit Service 82fcde
The main interface to argp is the @code{argp_parse} function.  In many
Packit Service 82fcde
cases, calling @code{argp_parse} is the only argument-parsing code
Packit Service 82fcde
needed in @code{main}.
Packit Service 82fcde
@xref{Program Arguments}.
Packit Service 82fcde
Packit Service 82fcde
@deftypefun {error_t} argp_parse (const struct argp *@var{argp}, int @var{argc}, char **@var{argv}, unsigned @var{flags}, int *@var{arg_index}, void *@var{input})
Packit Service 82fcde
@standards{GNU, argp.h}
Packit Service 82fcde
@safety{@prelim{}@mtunsafe{@mtasurace{:argpbuf} @mtslocale{} @mtsenv{}}@asunsafe{@ascuheap{} @ascuintl{} @asulock{} @asucorrupt{}}@acunsafe{@acsmem{} @aculock{} @acucorrupt{}}}
Packit Service 82fcde
@c Optionally alloca()tes standard help options, initializes the parser,
Packit Service 82fcde
@c then parses individual args in a loop, and then finalizes.
Packit Service 82fcde
@c  parser_init
Packit Service 82fcde
@c   calc_sizes ok
Packit Service 82fcde
@c    option_is_end ok
Packit Service 82fcde
@c   malloc @ascuheap @acsmem
Packit Service 82fcde
@c   parser_convert @mtslocale
Packit Service 82fcde
@c    convert_options @mtslocale
Packit Service 82fcde
@c     option_is_end ok
Packit Service 82fcde
@c     option_is_short ok
Packit Service 82fcde
@c      isprint, but locale may change within the loop
Packit Service 82fcde
@c     find_long_option ok
Packit Service 82fcde
@c   group_parse
Packit Service 82fcde
@c    group->parser (from argp->parser)
Packit Service 82fcde
@c  parser_parse_next
Packit Service 82fcde
@c   getopt_long(_only)_r many issues, same as non_r minus @mtasurace
Packit Service 82fcde
@c   parser_parse_arg
Packit Service 82fcde
@c    group_parse dup
Packit Service 82fcde
@c   parser_parse_opt
Packit Service 82fcde
@c    group_parse dup
Packit Service 82fcde
@c    argp_error dup @mtasurace:argpbuf @mtsenv @mtslocale @ascuheap @ascuintl @asucorrupt @acsmem @acucorrupt @aculock
Packit Service 82fcde
@c    dgettext (bad key error) dup @mtsenv @asucorrupt @ascuheap @asulock @ascudlopen @acucorrupt @aculock @acsfd @acsmem
Packit Service 82fcde
@c  parser_finalize
Packit Service 82fcde
@c   group_parse
Packit Service 82fcde
@c   fprintf dup @mtslocale @asucorrupt @aculock @acucorrupt [no @ascuheap @acsmem]
Packit Service 82fcde
@c   dgettext dup @mtsenv @asucorrupt @ascuheap @asulock @ascudlopen @acucorrupt @aculock @acsfd @acsmem
Packit Service 82fcde
@c   arg_state_help
Packit Service 82fcde
@c   free dup @ascuhelp @acsmem
Packit Service 82fcde
The @code{argp_parse} function parses the arguments in @var{argv}, of
Packit Service 82fcde
length @var{argc}, using the argp parser @var{argp}.  @xref{Argp
Packit Service 82fcde
Parsers}.  Passing a null pointer for @var{argp} is the same as using
Packit Service 82fcde
a @code{struct argp} containing all zeros.
Packit Service 82fcde
Packit Service 82fcde
@var{flags} is a set of flag bits that modify the parsing behavior.
Packit Service 82fcde
@xref{Argp Flags}.  @var{input} is passed through to the argp parser
Packit Service 82fcde
@var{argp}, and has meaning defined by @var{argp}.  A typical usage is
Packit Service 82fcde
to pass a pointer to a structure which is used for specifying
Packit Service 82fcde
parameters to the parser and passing back the results.
Packit Service 82fcde
Packit Service 82fcde
Unless the @code{ARGP_NO_EXIT} or @code{ARGP_NO_HELP} flags are included
Packit Service 82fcde
in @var{flags}, calling @code{argp_parse} may result in the program
Packit Service 82fcde
exiting.  This behavior is true if an error is detected, or when an
Packit Service 82fcde
unknown option is encountered.  @xref{Program Termination}.
Packit Service 82fcde
Packit Service 82fcde
If @var{arg_index} is non-null, the index of the first unparsed option
Packit Service 82fcde
in @var{argv} is returned as a value.
Packit Service 82fcde
Packit Service 82fcde
The return value is zero for successful parsing, or an error code
Packit Service 82fcde
(@pxref{Error Codes}) if an error is detected.  Different argp parsers
Packit Service 82fcde
may return arbitrary error codes, but the standard error codes are:
Packit Service 82fcde
@code{ENOMEM} if a memory allocation error occurred, or @code{EINVAL} if
Packit Service 82fcde
an unknown option or option argument is encountered.
Packit Service 82fcde
@end deftypefun
Packit Service 82fcde
Packit Service 82fcde
@menu
Packit Service 82fcde
* Globals: Argp Global Variables.  Global argp parameters.
Packit Service 82fcde
* Parsers: Argp Parsers.        Defining parsers for use with @code{argp_parse}.
Packit Service 82fcde
* Flags: Argp Flags.            Flags that modify the behavior of @code{argp_parse}.
Packit Service 82fcde
* Help: Argp Help.              Printing help messages when not parsing.
Packit Service 82fcde
* Examples: Argp Examples.      Simple examples of programs using argp.
Packit Service 82fcde
* Customization: Argp User Customization.
Packit Service 82fcde
                                Users may control the @samp{--help} output format.
Packit Service 82fcde
@end menu
Packit Service 82fcde
Packit Service 82fcde
@node Argp Global Variables, Argp Parsers, , Argp
Packit Service 82fcde
@subsection Argp Global Variables
Packit Service 82fcde
Packit Service 82fcde
These variables make it easy for user programs to implement the
Packit Service 82fcde
@samp{--version} option and provide a bug-reporting address in the
Packit Service 82fcde
@samp{--help} output.  These are implemented in argp by default.
Packit Service 82fcde
Packit Service 82fcde
@deftypevar {const char *} argp_program_version
Packit Service 82fcde
@standards{GNU, argp.h}
Packit Service 82fcde
If defined or set by the user program to a non-zero value, then a
Packit Service 82fcde
@samp{--version} option is added when parsing with @code{argp_parse},
Packit Service 82fcde
which will print the @samp{--version} string followed by a newline and
Packit Service 82fcde
exit.  The exception to this is if the @code{ARGP_NO_EXIT} flag is used.
Packit Service 82fcde
@end deftypevar
Packit Service 82fcde
Packit Service 82fcde
@deftypevar {const char *} argp_program_bug_address
Packit Service 82fcde
@standards{GNU, argp.h}
Packit Service 82fcde
If defined or set by the user program to a non-zero value,
Packit Service 82fcde
@code{argp_program_bug_address} should point to a string that will be
Packit Service 82fcde
printed at the end of the standard output for the @samp{--help} option,
Packit Service 82fcde
embedded in a sentence that says @samp{Report bugs to @var{address}.}.
Packit Service 82fcde
@end deftypevar
Packit Service 82fcde
Packit Service 82fcde
@need 1500
Packit Service 82fcde
@defvar argp_program_version_hook
Packit Service 82fcde
@standards{GNU, argp.h}
Packit Service 82fcde
If defined or set by the user program to a non-zero value, a
Packit Service 82fcde
@samp{--version} option is added when parsing with @code{arg_parse},
Packit Service 82fcde
which prints the program version and exits with a status of zero.  This
Packit Service 82fcde
is not the case if the @code{ARGP_NO_HELP} flag is used.  If the
Packit Service 82fcde
@code{ARGP_NO_EXIT} flag is set, the exit behavior of the program is
Packit Service 82fcde
suppressed or modified, as when the argp parser is going to be used by
Packit Service 82fcde
other programs.
Packit Service 82fcde
Packit Service 82fcde
It should point to a function with this type of signature:
Packit Service 82fcde
Packit Service 82fcde
@smallexample
Packit Service 82fcde
void @var{print-version} (FILE *@var{stream}, struct argp_state *@var{state})
Packit Service 82fcde
@end smallexample
Packit Service 82fcde
Packit Service 82fcde
@noindent
Packit Service 82fcde
@xref{Argp Parsing State}, for an explanation of @var{state}.
Packit Service 82fcde
Packit Service 82fcde
This variable takes precedence over @code{argp_program_version}, and is
Packit Service 82fcde
useful if a program has version information not easily expressed in a
Packit Service 82fcde
simple string.
Packit Service 82fcde
@end defvar
Packit Service 82fcde
Packit Service 82fcde
@deftypevar error_t argp_err_exit_status
Packit Service 82fcde
@standards{GNU, argp.h}
Packit Service 82fcde
This is the exit status used when argp exits due to a parsing error.  If
Packit Service 82fcde
not defined or set by the user program, this defaults to:
Packit Service 82fcde
@code{EX_USAGE} from @file{<sysexits.h>}.
Packit Service 82fcde
@end deftypevar
Packit Service 82fcde
Packit Service 82fcde
@node Argp Parsers, Argp Flags, Argp Global Variables, Argp
Packit Service 82fcde
@subsection Specifying Argp Parsers
Packit Service 82fcde
Packit Service 82fcde
The first argument to the @code{argp_parse} function is a pointer to a
Packit Service 82fcde
@code{struct argp}, which is known as an @dfn{argp parser}:
Packit Service 82fcde
Packit Service 82fcde
@deftp {Data Type} {struct argp}
Packit Service 82fcde
@standards{GNU, argp.h}
Packit Service 82fcde
This structure specifies how to parse a given set of options and
Packit Service 82fcde
arguments, perhaps in conjunction with other argp parsers.  It has the
Packit Service 82fcde
following fields:
Packit Service 82fcde
Packit Service 82fcde
@table @code
Packit Service 82fcde
@item const struct argp_option *options
Packit Service 82fcde
A pointer to a vector of @code{argp_option} structures specifying which
Packit Service 82fcde
options this argp parser understands; it may be zero if there are no
Packit Service 82fcde
options at all.  @xref{Argp Option Vectors}.
Packit Service 82fcde
Packit Service 82fcde
@item argp_parser_t parser
Packit Service 82fcde
A pointer to a function that defines actions for this parser; it is
Packit Service 82fcde
called for each option parsed, and at other well-defined points in the
Packit Service 82fcde
parsing process.  A value of zero is the same as a pointer to a function
Packit Service 82fcde
that always returns @code{ARGP_ERR_UNKNOWN}.  @xref{Argp Parser
Packit Service 82fcde
Functions}.
Packit Service 82fcde
Packit Service 82fcde
@item const char *args_doc
Packit Service 82fcde
If non-zero, a string describing what non-option arguments are called by
Packit Service 82fcde
this parser.  This is only used to print the @samp{Usage:} message.  If
Packit Service 82fcde
it contains newlines, the strings separated by them are considered
Packit Service 82fcde
alternative usage patterns and printed on separate lines.  Lines after
Packit Service 82fcde
the first are prefixed by @samp{ or: } instead of @samp{Usage:}.
Packit Service 82fcde
Packit Service 82fcde
@item const char *doc
Packit Service 82fcde
If non-zero, a string containing extra text to be printed before and
Packit Service 82fcde
after the options in a long help message, with the two sections
Packit Service 82fcde
separated by a vertical tab (@code{'\v'}, @code{'\013'}) character.  By
Packit Service 82fcde
convention, the documentation before the options is just a short string
Packit Service 82fcde
explaining what the program does.  Documentation printed after the
Packit Service 82fcde
options describe behavior in more detail.
Packit Service 82fcde
Packit Service 82fcde
@item const struct argp_child *children
Packit Service 82fcde
A pointer to a vector of @code{argp_child} structures.  This pointer
Packit Service 82fcde
specifies which additional argp parsers should be combined with this
Packit Service 82fcde
one.  @xref{Argp Children}.
Packit Service 82fcde
Packit Service 82fcde
@item char *(*help_filter)(int @var{key}, const char *@var{text}, void *@var{input})
Packit Service 82fcde
If non-zero, a pointer to a function that filters the output of help
Packit Service 82fcde
messages.  @xref{Argp Help Filtering}.
Packit Service 82fcde
Packit Service 82fcde
@item const char *argp_domain
Packit Service 82fcde
If non-zero, the strings used in the argp library are translated using
Packit Service 82fcde
the domain described by this string.  If zero, the current default domain
Packit Service 82fcde
is used.
Packit Service 82fcde
Packit Service 82fcde
@end table
Packit Service 82fcde
@end deftp
Packit Service 82fcde
Packit Service 82fcde
Of the above group, @code{options}, @code{parser}, @code{args_doc}, and
Packit Service 82fcde
the @code{doc} fields are usually all that are needed.  If an argp
Packit Service 82fcde
parser is defined as an initialized C variable, only the fields used
Packit Service 82fcde
need be specified in the initializer.  The rest will default to zero due
Packit Service 82fcde
to the way C structure initialization works.  This design is exploited in
Packit Service 82fcde
most argp structures; the most-used fields are grouped near the
Packit Service 82fcde
beginning, the unused fields left unspecified.
Packit Service 82fcde
Packit Service 82fcde
@menu
Packit Service 82fcde
* Options: Argp Option Vectors.   Specifying options in an argp parser.
Packit Service 82fcde
* Argp Parser Functions::         Defining actions for an argp parser.
Packit Service 82fcde
* Children: Argp Children.        Combining multiple argp parsers.
Packit Service 82fcde
* Help Filtering: Argp Help Filtering.  Customizing help output for an argp parser.
Packit Service 82fcde
@end menu
Packit Service 82fcde
Packit Service 82fcde
@node Argp Option Vectors, Argp Parser Functions, Argp Parsers, Argp Parsers
Packit Service 82fcde
@subsection Specifying Options in an Argp Parser
Packit Service 82fcde
Packit Service 82fcde
The @code{options} field in a @code{struct argp} points to a vector of
Packit Service 82fcde
@code{struct argp_option} structures, each of which specifies an option
Packit Service 82fcde
that the argp parser supports.  Multiple entries may be used for a single
Packit Service 82fcde
option provided it has multiple names.  This should be terminated by an
Packit Service 82fcde
entry with zero in all fields.  Note that when using an initialized C
Packit Service 82fcde
array for options, writing @code{@{ 0 @}} is enough to achieve this.
Packit Service 82fcde
Packit Service 82fcde
@deftp {Data Type} {struct argp_option}
Packit Service 82fcde
@standards{GNU, argp.h}
Packit Service 82fcde
This structure specifies a single option that an argp parser
Packit Service 82fcde
understands, as well as how to parse and document that option.  It has
Packit Service 82fcde
the following fields:
Packit Service 82fcde
Packit Service 82fcde
@table @code
Packit Service 82fcde
@item const char *name
Packit Service 82fcde
The long name for this option, corresponding to the long option
Packit Service 82fcde
@samp{--@var{name}}; this field may be zero if this option @emph{only}
Packit Service 82fcde
has a short name.  To specify multiple names for an option, additional
Packit Service 82fcde
entries may follow this one, with the @code{OPTION_ALIAS} flag
Packit Service 82fcde
set.  @xref{Argp Option Flags}.
Packit Service 82fcde
Packit Service 82fcde
@item int key
Packit Service 82fcde
The integer key provided by the current option to the option parser.  If
Packit Service 82fcde
@var{key} has a value that is a printable @sc{ascii} character (i.e.,
Packit Service 82fcde
@code{isascii (@var{key})} is true), it @emph{also} specifies a short
Packit Service 82fcde
option @samp{-@var{char}}, where @var{char} is the @sc{ascii} character
Packit Service 82fcde
with the code @var{key}.
Packit Service 82fcde
Packit Service 82fcde
@item const char *arg
Packit Service 82fcde
If non-zero, this is the name of an argument associated with this
Packit Service 82fcde
option, which must be provided (e.g., with the
Packit Service 82fcde
@samp{--@var{name}=@var{value}} or @samp{-@var{char} @var{value}}
Packit Service 82fcde
syntaxes), unless the @code{OPTION_ARG_OPTIONAL} flag (@pxref{Argp
Packit Service 82fcde
Option Flags}) is set, in which case it @emph{may} be provided.
Packit Service 82fcde
Packit Service 82fcde
@item int flags
Packit Service 82fcde
Flags associated with this option, some of which are referred to above.
Packit Service 82fcde
@xref{Argp Option Flags}.
Packit Service 82fcde
Packit Service 82fcde
@item const char *doc
Packit Service 82fcde
A documentation string for this option, for printing in help messages.
Packit Service 82fcde
Packit Service 82fcde
If both the @code{name} and @code{key} fields are zero, this string
Packit Service 82fcde
will be printed tabbed left from the normal option column, making it
Packit Service 82fcde
useful as a group header.  This will be the first thing printed in its
Packit Service 82fcde
group.  In this usage, it's conventional to end the string with a
Packit Service 82fcde
@samp{:} character.
Packit Service 82fcde
Packit Service 82fcde
@item int group
Packit Service 82fcde
Group identity for this option.
Packit Service 82fcde
Packit Service 82fcde
In a long help message, options are sorted alphabetically within each
Packit Service 82fcde
group, and the groups presented in the order 0, 1, 2, @dots{}, @var{n},
Packit Service 82fcde
@minus{}@var{m}, @dots{}, @minus{}2, @minus{}1.
Packit Service 82fcde
Packit Service 82fcde
Every entry in an options array with this field 0 will inherit the group
Packit Service 82fcde
number of the previous entry, or zero if it's the first one.  If it's a
Packit Service 82fcde
group header with @code{name} and @code{key} fields both zero, the
Packit Service 82fcde
previous entry + 1 is the default.  Automagic options such as
Packit Service 82fcde
@samp{--help} are put into group @minus{}1.
Packit Service 82fcde
Packit Service 82fcde
Note that because of C structure initialization rules, this field often
Packit Service 82fcde
need not be specified, because 0 is the correct value.
Packit Service 82fcde
@end table
Packit Service 82fcde
@end deftp
Packit Service 82fcde
Packit Service 82fcde
Packit Service 82fcde
@menu
Packit Service 82fcde
* Flags: Argp Option Flags.     Flags for options.
Packit Service 82fcde
@end menu
Packit Service 82fcde
Packit Service 82fcde
@node Argp Option Flags, , , Argp Option Vectors
Packit Service 82fcde
@subsubsection Flags for Argp Options
Packit Service 82fcde
Packit Service 82fcde
The following flags may be or'd together in the @code{flags} field of a
Packit Service 82fcde
@code{struct argp_option}.  These flags control various aspects of how
Packit Service 82fcde
that option is parsed or displayed in help messages:
Packit Service 82fcde
Packit Service 82fcde
Packit Service 82fcde
@vtable @code
Packit Service 82fcde
@item OPTION_ARG_OPTIONAL
Packit Service 82fcde
@standards{GNU, argp.h}
Packit Service 82fcde
The argument associated with this option is optional.
Packit Service 82fcde
Packit Service 82fcde
@item OPTION_HIDDEN
Packit Service 82fcde
@standards{GNU, argp.h}
Packit Service 82fcde
This option isn't displayed in any help messages.
Packit Service 82fcde
Packit Service 82fcde
@item OPTION_ALIAS
Packit Service 82fcde
@standards{GNU, argp.h}
Packit Service 82fcde
This option is an alias for the closest previous non-alias option.  This
Packit Service 82fcde
means that it will be displayed in the same help entry, and will inherit
Packit Service 82fcde
fields other than @code{name} and @code{key} from the option being
Packit Service 82fcde
aliased.
Packit Service 82fcde
Packit Service 82fcde
Packit Service 82fcde
@item OPTION_DOC
Packit Service 82fcde
@standards{GNU, argp.h}
Packit Service 82fcde
This option isn't actually an option and should be ignored by the actual
Packit Service 82fcde
option parser.  It is an arbitrary section of documentation that should
Packit Service 82fcde
be displayed in much the same manner as the options.  This is known as a
Packit Service 82fcde
@dfn{documentation option}.
Packit Service 82fcde
Packit Service 82fcde
If this flag is set, then the option @code{name} field is displayed
Packit Service 82fcde
unmodified (e.g., no @samp{--} prefix is added) at the left-margin where
Packit Service 82fcde
a @emph{short} option would normally be displayed, and this
Packit Service 82fcde
documentation string is left in its usual place.  For purposes of
Packit Service 82fcde
sorting, any leading whitespace and punctuation is ignored, unless the
Packit Service 82fcde
first non-whitespace character is @samp{-}.  This entry is displayed
Packit Service 82fcde
after all options, after @code{OPTION_DOC} entries with a leading
Packit Service 82fcde
@samp{-}, in the same group.
Packit Service 82fcde
Packit Service 82fcde
@item OPTION_NO_USAGE
Packit Service 82fcde
@standards{GNU, argp.h}
Packit Service 82fcde
This option shouldn't be included in `long' usage messages, but should
Packit Service 82fcde
still be included in other help messages.  This is intended for options
Packit Service 82fcde
that are completely documented in an argp's @code{args_doc}
Packit Service 82fcde
field.  @xref{Argp Parsers}.  Including this option in the generic usage
Packit Service 82fcde
list would be redundant, and should be avoided.
Packit Service 82fcde
Packit Service 82fcde
For instance, if @code{args_doc} is @code{"FOO BAR\n-x BLAH"}, and the
Packit Service 82fcde
@samp{-x} option's purpose is to distinguish these two cases, @samp{-x}
Packit Service 82fcde
should probably be marked @code{OPTION_NO_USAGE}.
Packit Service 82fcde
@end vtable
Packit Service 82fcde
Packit Service 82fcde
@node Argp Parser Functions, Argp Children, Argp Option Vectors, Argp Parsers
Packit Service 82fcde
@subsection Argp Parser Functions
Packit Service 82fcde
Packit Service 82fcde
The function pointed to by the @code{parser} field in a @code{struct
Packit Service 82fcde
argp} (@pxref{Argp Parsers}) defines what actions take place in response
Packit Service 82fcde
to each option or argument parsed.  It is also used as a hook, allowing a
Packit Service 82fcde
parser to perform tasks at certain other points during parsing.
Packit Service 82fcde
Packit Service 82fcde
@need 2000
Packit Service 82fcde
Argp parser functions have the following type signature:
Packit Service 82fcde
Packit Service 82fcde
@cindex argp parser functions
Packit Service 82fcde
@smallexample
Packit Service 82fcde
error_t @var{parser} (int @var{key}, char *@var{arg}, struct argp_state *@var{state})
Packit Service 82fcde
@end smallexample
Packit Service 82fcde
Packit Service 82fcde
@noindent
Packit Service 82fcde
where the arguments are as follows:
Packit Service 82fcde
Packit Service 82fcde
@table @var
Packit Service 82fcde
@item key
Packit Service 82fcde
For each option that is parsed, @var{parser} is called with a value of
Packit Service 82fcde
@var{key} from that option's @code{key} field in the option
Packit Service 82fcde
vector.  @xref{Argp Option Vectors}.  @var{parser} is also called at
Packit Service 82fcde
other times with special reserved keys, such as @code{ARGP_KEY_ARG} for
Packit Service 82fcde
non-option arguments.  @xref{Argp Special Keys}.
Packit Service 82fcde
Packit Service 82fcde
@item arg
Packit Service 82fcde
If @var{key} is an option, @var{arg} is its given value.  This defaults
Packit Service 82fcde
to zero if no value is specified.  Only options that have a non-zero
Packit Service 82fcde
@code{arg} field can ever have a value.  These must @emph{always} have a
Packit Service 82fcde
value unless the @code{OPTION_ARG_OPTIONAL} flag is specified.  If the
Packit Service 82fcde
input being parsed specifies a value for an option that doesn't allow
Packit Service 82fcde
one, an error results before @var{parser} ever gets called.
Packit Service 82fcde
Packit Service 82fcde
If @var{key} is @code{ARGP_KEY_ARG}, @var{arg} is a non-option
Packit Service 82fcde
argument.  Other special keys always have a zero @var{arg}.
Packit Service 82fcde
Packit Service 82fcde
@item state
Packit Service 82fcde
@var{state} points to a @code{struct argp_state}, containing useful
Packit Service 82fcde
information about the current parsing state for use by
Packit Service 82fcde
@var{parser}.  @xref{Argp Parsing State}.
Packit Service 82fcde
@end table
Packit Service 82fcde
Packit Service 82fcde
When @var{parser} is called, it should perform whatever action is
Packit Service 82fcde
appropriate for @var{key}, and return @code{0} for success,
Packit Service 82fcde
@code{ARGP_ERR_UNKNOWN} if the value of @var{key} is not handled by this
Packit Service 82fcde
parser function, or a unix error code if a real error
Packit Service 82fcde
occurred.  @xref{Error Codes}.
Packit Service 82fcde
Packit Service 82fcde
@deftypevr Macro int ARGP_ERR_UNKNOWN
Packit Service 82fcde
@standards{GNU, argp.h}
Packit Service 82fcde
Argp parser functions should return @code{ARGP_ERR_UNKNOWN} for any
Packit Service 82fcde
@var{key} value they do not recognize, or for non-option arguments
Packit Service 82fcde
(@code{@var{key} == ARGP_KEY_ARG}) that they are not equipped to handle.
Packit Service 82fcde
@end deftypevr
Packit Service 82fcde
Packit Service 82fcde
@need 3000
Packit Service 82fcde
A typical parser function uses a switch statement on @var{key}:
Packit Service 82fcde
Packit Service 82fcde
@smallexample
Packit Service 82fcde
error_t
Packit Service 82fcde
parse_opt (int key, char *arg, struct argp_state *state)
Packit Service 82fcde
@{
Packit Service 82fcde
  switch (key)
Packit Service 82fcde
    @{
Packit Service 82fcde
    case @var{option_key}:
Packit Service 82fcde
      @var{action}
Packit Service 82fcde
      break;
Packit Service 82fcde
    @dots{}
Packit Service 82fcde
    default:
Packit Service 82fcde
      return ARGP_ERR_UNKNOWN;
Packit Service 82fcde
    @}
Packit Service 82fcde
  return 0;
Packit Service 82fcde
@}
Packit Service 82fcde
@end smallexample
Packit Service 82fcde
Packit Service 82fcde
@menu
Packit Service 82fcde
* Keys: Argp Special Keys.           Special values for the @var{key} argument.
Packit Service 82fcde
* State: Argp Parsing State.         What the @var{state} argument refers to.
Packit Service 82fcde
* Functions: Argp Helper Functions.  Functions to help during argp parsing.
Packit Service 82fcde
@end menu
Packit Service 82fcde
Packit Service 82fcde
@node Argp Special Keys, Argp Parsing State, , Argp Parser Functions
Packit Service 82fcde
@subsubsection Special Keys for Argp Parser Functions
Packit Service 82fcde
Packit Service 82fcde
In addition to key values corresponding to user options, the @var{key}
Packit Service 82fcde
argument to argp parser functions may have a number of other special
Packit Service 82fcde
values.  In the following example @var{arg} and @var{state} refer to
Packit Service 82fcde
parser function arguments.  @xref{Argp Parser Functions}.
Packit Service 82fcde
Packit Service 82fcde
@vtable @code
Packit Service 82fcde
@item ARGP_KEY_ARG
Packit Service 82fcde
@standards{GNU, argp.h}
Packit Service 82fcde
This is not an option at all, but rather a command line argument, whose
Packit Service 82fcde
value is pointed to by @var{arg}.
Packit Service 82fcde
Packit Service 82fcde
When there are multiple parser functions in play due to argp parsers
Packit Service 82fcde
being combined, it's impossible to know which one will handle a specific
Packit Service 82fcde
argument.  Each is called until one returns 0 or an error other than
Packit Service 82fcde
@code{ARGP_ERR_UNKNOWN}; if an argument is not handled,
Packit Service 82fcde
@code{argp_parse} immediately returns success, without parsing any more
Packit Service 82fcde
arguments.
Packit Service 82fcde
Packit Service 82fcde
Once a parser function returns success for this key, that fact is
Packit Service 82fcde
recorded, and the @code{ARGP_KEY_NO_ARGS} case won't be
Packit Service 82fcde
used.  @emph{However}, if while processing the argument a parser function
Packit Service 82fcde
decrements the @code{next} field of its @var{state} argument, the option
Packit Service 82fcde
won't be considered processed; this is to allow you to actually modify
Packit Service 82fcde
the argument, perhaps into an option, and have it processed again.
Packit Service 82fcde
Packit Service 82fcde
@item ARGP_KEY_ARGS
Packit Service 82fcde
@standards{GNU, argp.h}
Packit Service 82fcde
If a parser function returns @code{ARGP_ERR_UNKNOWN} for
Packit Service 82fcde
@code{ARGP_KEY_ARG}, it is immediately called again with the key
Packit Service 82fcde
@code{ARGP_KEY_ARGS}, which has a similar meaning, but is slightly more
Packit Service 82fcde
convenient for consuming all remaining arguments.  @var{arg} is 0, and
Packit Service 82fcde
the tail of the argument vector may be found at @code{@var{state}->argv
Packit Service 82fcde
+ @var{state}->next}.  If success is returned for this key, and
Packit Service 82fcde
@code{@var{state}->next} is unchanged, all remaining arguments are
Packit Service 82fcde
considered to have been consumed.  Otherwise, the amount by which
Packit Service 82fcde
@code{@var{state}->next} has been adjusted indicates how many were used.
Packit Service 82fcde
Here's an example that uses both, for different args:
Packit Service 82fcde
Packit Service 82fcde
Packit Service 82fcde
@smallexample
Packit Service 82fcde
@dots{}
Packit Service 82fcde
case ARGP_KEY_ARG:
Packit Service 82fcde
  if (@var{state}->arg_num == 0)
Packit Service 82fcde
    /* First argument */
Packit Service 82fcde
    first_arg = @var{arg};
Packit Service 82fcde
  else
Packit Service 82fcde
    /* Let the next case parse it.  */
Packit Service 82fcde
    return ARGP_KEY_UNKNOWN;
Packit Service 82fcde
  break;
Packit Service 82fcde
case ARGP_KEY_ARGS:
Packit Service 82fcde
  remaining_args = @var{state}->argv + @var{state}->next;
Packit Service 82fcde
  num_remaining_args = @var{state}->argc - @var{state}->next;
Packit Service 82fcde
  break;
Packit Service 82fcde
@end smallexample
Packit Service 82fcde
Packit Service 82fcde
@item ARGP_KEY_END
Packit Service 82fcde
@standards{GNU, argp.h}
Packit Service 82fcde
This indicates that there are no more command line arguments.  Parser
Packit Service 82fcde
functions are called in a different order, children first.  This allows
Packit Service 82fcde
each parser to clean up its state for the parent.
Packit Service 82fcde
Packit Service 82fcde
@item ARGP_KEY_NO_ARGS
Packit Service 82fcde
@standards{GNU, argp.h}
Packit Service 82fcde
Because it's common to do some special processing if there aren't any
Packit Service 82fcde
non-option args, parser functions are called with this key if they
Packit Service 82fcde
didn't successfully process any non-option arguments.  This is called
Packit Service 82fcde
just before @code{ARGP_KEY_END}, where more general validity checks on
Packit Service 82fcde
previously parsed arguments take place.
Packit Service 82fcde
Packit Service 82fcde
@item ARGP_KEY_INIT
Packit Service 82fcde
@standards{GNU, argp.h}
Packit Service 82fcde
This is passed in before any parsing is done.  Afterwards, the values of
Packit Service 82fcde
each element of the @code{child_input} field of @var{state}, if any, are
Packit Service 82fcde
copied to each child's state to be the initial value of the @code{input}
Packit Service 82fcde
when @emph{their} parsers are called.
Packit Service 82fcde
Packit Service 82fcde
@item ARGP_KEY_SUCCESS
Packit Service 82fcde
@standards{GNU, argp.h}
Packit Service 82fcde
Passed in when parsing has successfully been completed, even if
Packit Service 82fcde
arguments remain.
Packit Service 82fcde
Packit Service 82fcde
@item ARGP_KEY_ERROR
Packit Service 82fcde
@standards{GNU, argp.h}
Packit Service 82fcde
Passed in if an error has occurred and parsing is terminated.  In this
Packit Service 82fcde
case a call with a key of @code{ARGP_KEY_SUCCESS} is never made.
Packit Service 82fcde
Packit Service 82fcde
@item ARGP_KEY_FINI
Packit Service 82fcde
@standards{GNU, argp.h}
Packit Service 82fcde
The final key ever seen by any parser, even after
Packit Service 82fcde
@code{ARGP_KEY_SUCCESS} and @code{ARGP_KEY_ERROR}.  Any resources
Packit Service 82fcde
allocated by @code{ARGP_KEY_INIT} may be freed here.  At times, certain
Packit Service 82fcde
resources allocated are to be returned to the caller after a successful
Packit Service 82fcde
parse.  In that case, those particular resources can be freed in the
Packit Service 82fcde
@code{ARGP_KEY_ERROR} case.
Packit Service 82fcde
@end vtable
Packit Service 82fcde
Packit Service 82fcde
In all cases, @code{ARGP_KEY_INIT} is the first key seen by parser
Packit Service 82fcde
functions, and @code{ARGP_KEY_FINI} the last, unless an error was
Packit Service 82fcde
returned by the parser for @code{ARGP_KEY_INIT}.  Other keys can occur
Packit Service 82fcde
in one the following orders.  @var{opt} refers to an arbitrary option
Packit Service 82fcde
key:
Packit Service 82fcde
Packit Service 82fcde
@table @asis
Packit Service 82fcde
@item @var{opt}@dots{} @code{ARGP_KEY_NO_ARGS} @code{ARGP_KEY_END} @code{ARGP_KEY_SUCCESS}
Packit Service 82fcde
The arguments being parsed did not contain any non-option arguments.
Packit Service 82fcde
Packit Service 82fcde
@item ( @var{opt} | @code{ARGP_KEY_ARG} )@dots{} @code{ARGP_KEY_END} @code{ARGP_KEY_SUCCESS}
Packit Service 82fcde
All non-option arguments were successfully handled by a parser
Packit Service 82fcde
function.  There may be multiple parser functions if multiple argp
Packit Service 82fcde
parsers were combined.
Packit Service 82fcde
Packit Service 82fcde
@item ( @var{opt} | @code{ARGP_KEY_ARG} )@dots{} @code{ARGP_KEY_SUCCESS}
Packit Service 82fcde
Some non-option argument went unrecognized.
Packit Service 82fcde
Packit Service 82fcde
This occurs when every parser function returns @code{ARGP_KEY_UNKNOWN}
Packit Service 82fcde
for an argument, in which case parsing stops at that argument if
Packit Service 82fcde
@var{arg_index} is a null pointer.  Otherwise an error occurs.
Packit Service 82fcde
@end table
Packit Service 82fcde
Packit Service 82fcde
In all cases, if a non-null value for @var{arg_index} gets passed to
Packit Service 82fcde
@code{argp_parse}, the index of the first unparsed command-line argument
Packit Service 82fcde
is passed back in that value.
Packit Service 82fcde
Packit Service 82fcde
If an error occurs and is either detected by argp or because a parser
Packit Service 82fcde
function returned an error value, each parser is called with
Packit Service 82fcde
@code{ARGP_KEY_ERROR}.  No further calls are made, except the final call
Packit Service 82fcde
with @code{ARGP_KEY_FINI}.
Packit Service 82fcde
Packit Service 82fcde
@node Argp Parsing State, Argp Helper Functions, Argp Special Keys, Argp Parser Functions
Packit Service 82fcde
@subsubsection Argp Parsing State
Packit Service 82fcde
Packit Service 82fcde
The third argument to argp parser functions (@pxref{Argp Parser
Packit Service 82fcde
Functions}) is a pointer to a @code{struct argp_state}, which contains
Packit Service 82fcde
information about the state of the option parsing.
Packit Service 82fcde
Packit Service 82fcde
@deftp {Data Type} {struct argp_state}
Packit Service 82fcde
@standards{GNU, argp.h}
Packit Service 82fcde
This structure has the following fields, which may be modified as noted:
Packit Service 82fcde
Packit Service 82fcde
@table @code
Packit Service 82fcde
@item const struct argp *const root_argp
Packit Service 82fcde
The top level argp parser being parsed.  Note that this is often
Packit Service 82fcde
@emph{not} the same @code{struct argp} passed into @code{argp_parse} by
Packit Service 82fcde
the invoking program.  @xref{Argp}.  It is an internal argp parser that
Packit Service 82fcde
contains options implemented by @code{argp_parse} itself, such as
Packit Service 82fcde
@samp{--help}.
Packit Service 82fcde
Packit Service 82fcde
@item int argc
Packit Service 82fcde
@itemx char **argv
Packit Service 82fcde
The argument vector being parsed.  This may be modified.
Packit Service 82fcde
Packit Service 82fcde
@item int next
Packit Service 82fcde
The index in @code{argv} of the next argument to be parsed.  This may be
Packit Service 82fcde
modified.
Packit Service 82fcde
Packit Service 82fcde
One way to consume all remaining arguments in the input is to set
Packit Service 82fcde
@code{@var{state}->next = @var{state}->argc}, perhaps after recording
Packit Service 82fcde
the value of the @code{next} field to find the consumed arguments.  The
Packit Service 82fcde
current option can be re-parsed immediately by decrementing this field,
Packit Service 82fcde
then modifying @code{@var{state}->argv[@var{state}->next]} to reflect
Packit Service 82fcde
the option that should be reexamined.
Packit Service 82fcde
Packit Service 82fcde
@item unsigned flags
Packit Service 82fcde
The flags supplied to @code{argp_parse}.  These may be modified, although
Packit Service 82fcde
some flags may only take effect when @code{argp_parse} is first
Packit Service 82fcde
invoked.  @xref{Argp Flags}.
Packit Service 82fcde
Packit Service 82fcde
@item unsigned arg_num
Packit Service 82fcde
While calling a parsing function with the @var{key} argument
Packit Service 82fcde
@code{ARGP_KEY_ARG}, this represents the number of the current arg,
Packit Service 82fcde
starting at 0.  It is incremented after each @code{ARGP_KEY_ARG} call
Packit Service 82fcde
returns.  At all other times, this is the number of @code{ARGP_KEY_ARG}
Packit Service 82fcde
arguments that have been processed.
Packit Service 82fcde
Packit Service 82fcde
@item int quoted
Packit Service 82fcde
If non-zero, the index in @code{argv} of the first argument following a
Packit Service 82fcde
special @samp{--} argument.  This prevents anything that follows from
Packit Service 82fcde
being interpreted as an option.  It is only set after argument parsing
Packit Service 82fcde
has proceeded past this point.
Packit Service 82fcde
Packit Service 82fcde
@item void *input
Packit Service 82fcde
An arbitrary pointer passed in from the caller of @code{argp_parse}, in
Packit Service 82fcde
the @var{input} argument.
Packit Service 82fcde
Packit Service 82fcde
@item void **child_inputs
Packit Service 82fcde
These are values that will be passed to child parsers.  This vector will
Packit Service 82fcde
be the same length as the number of children in the current parser.  Each
Packit Service 82fcde
child parser will be given the value of
Packit Service 82fcde
@code{@var{state}->child_inputs[@var{i}]} as @emph{its}
Packit Service 82fcde
@code{@var{state}->input} field, where @var{i} is the index of the child
Packit Service 82fcde
in the this parser's @code{children} field.  @xref{Argp Children}.
Packit Service 82fcde
Packit Service 82fcde
@item void *hook
Packit Service 82fcde
For the parser function's use.  Initialized to 0, but otherwise ignored
Packit Service 82fcde
by argp.
Packit Service 82fcde
Packit Service 82fcde
@item char *name
Packit Service 82fcde
The name used when printing messages.  This is initialized to
Packit Service 82fcde
@code{argv[0]}, or @code{program_invocation_name} if @code{argv[0]} is
Packit Service 82fcde
unavailable.
Packit Service 82fcde
Packit Service 82fcde
@item FILE *err_stream
Packit Service 82fcde
@itemx FILE *out_stream
Packit Service 82fcde
The stdio streams used when argp prints.  Error messages are printed to
Packit Service 82fcde
@code{err_stream}, all other output, such as @samp{--help} output) to
Packit Service 82fcde
@code{out_stream}.  These are initialized to @code{stderr} and
Packit Service 82fcde
@code{stdout} respectively.  @xref{Standard Streams}.
Packit Service 82fcde
Packit Service 82fcde
@item void *pstate
Packit Service 82fcde
Private, for use by the argp implementation.
Packit Service 82fcde
@end table
Packit Service 82fcde
@end deftp
Packit Service 82fcde
Packit Service 82fcde
@node Argp Helper Functions, , Argp Parsing State, Argp Parser Functions
Packit Service 82fcde
@subsubsection Functions For Use in Argp Parsers
Packit Service 82fcde
Packit Service 82fcde
Argp provides a number of functions available to the user of argp
Packit Service 82fcde
(@pxref{Argp Parser Functions}), mostly for producing error messages.
Packit Service 82fcde
These take as their first argument the @var{state} argument to the
Packit Service 82fcde
parser function.  @xref{Argp Parsing State}.
Packit Service 82fcde
Packit Service 82fcde
Packit Service 82fcde
@cindex usage messages, in argp
Packit Service 82fcde
@deftypefun void argp_usage (const struct argp_state *@var{state})
Packit Service 82fcde
@standards{GNU, argp.h}
Packit Service 82fcde
@safety{@prelim{}@mtunsafe{@mtasurace{:argpbuf} @mtsenv{} @mtslocale{}}@asunsafe{@ascuheap{} @ascuintl{} @asucorrupt{}}@acunsafe{@acsmem{} @acucorrupt{} @aculock{}}}
Packit Service 82fcde
@c Just calls argp_state_help with stderr and ARGP_HELP_STD_USAGE.
Packit Service 82fcde
Outputs the standard usage message for the argp parser referred to by
Packit Service 82fcde
@var{state} to @code{@var{state}->err_stream} and terminates the program
Packit Service 82fcde
with @code{exit (argp_err_exit_status)}.  @xref{Argp Global Variables}.
Packit Service 82fcde
@end deftypefun
Packit Service 82fcde
Packit Service 82fcde
@cindex syntax error messages, in argp
Packit Service 82fcde
@deftypefun void argp_error (const struct argp_state *@var{state}, const char *@var{fmt}, @dots{})
Packit Service 82fcde
@standards{GNU, argp.h}
Packit Service 82fcde
@safety{@prelim{}@mtunsafe{@mtasurace{:argpbuf} @mtsenv{} @mtslocale{}}@asunsafe{@ascuheap{} @ascuintl{} @asucorrupt{}}@acunsafe{@acsmem{} @acucorrupt{} @aculock{}}}
Packit Service 82fcde
@c Lock stream, vasprintf the formatted message into a buffer, print the
Packit Service 82fcde
@c buffer prefixed by the short program name (in libc,
Packit Service 82fcde
@c argp_short_program_name is a macro that expands to
Packit Service 82fcde
@c program_invocation_short_name), releases the buffer, then call
Packit Service 82fcde
@c argp_state_help with stream and ARGP_HELP_STD_ERR, unlocking the
Packit Service 82fcde
@c stream at the end.
Packit Service 82fcde
Prints the printf format string @var{fmt} and following args, preceded
Packit Service 82fcde
by the program name and @samp{:}, and followed by a @w{@samp{Try @dots{}
Packit Service 82fcde
--help}} message, and terminates the program with an exit status of
Packit Service 82fcde
@code{argp_err_exit_status}.  @xref{Argp Global Variables}.
Packit Service 82fcde
@end deftypefun
Packit Service 82fcde
Packit Service 82fcde
@cindex error messages, in argp
Packit Service 82fcde
@deftypefun void argp_failure (const struct argp_state *@var{state}, int @var{status}, int @var{errnum}, const char *@var{fmt}, @dots{})
Packit Service 82fcde
@standards{GNU, argp.h}
Packit Service 82fcde
@safety{@prelim{}@mtsafe{}@asunsafe{@asucorrupt{} @ascuheap{}}@acunsafe{@aculock{} @acucorrupt{} @acsmem{}}}
Packit Service 82fcde
@c Lock stream, write out the short program name, vasprintf the optional
Packit Service 82fcde
@c formatted message to a buffer, print the buffer prefixed by colon and
Packit Service 82fcde
@c blank, release the buffer, call strerror_r with an automatic buffer,
Packit Service 82fcde
@c print it out after colon and blank, put[w]c a line break, unlock the
Packit Service 82fcde
@c stream, then exit unless ARGP_NO_EXIT.
Packit Service 82fcde
Similar to the standard GNU error-reporting function @code{error}, this
Packit Service 82fcde
prints the program name and @samp{:}, the printf format string
Packit Service 82fcde
@var{fmt}, and the appropriate following args.  If it is non-zero, the
Packit Service 82fcde
standard unix error text for @var{errnum} is printed.  If @var{status} is
Packit Service 82fcde
non-zero, it terminates the program with that value as its exit status.
Packit Service 82fcde
Packit Service 82fcde
The difference between @code{argp_failure} and @code{argp_error} is that
Packit Service 82fcde
@code{argp_error} is for @emph{parsing errors}, whereas
Packit Service 82fcde
@code{argp_failure} is for other problems that occur during parsing but
Packit Service 82fcde
don't reflect a syntactic problem with the input, such as illegal values
Packit Service 82fcde
for options, bad phase of the moon, etc.
Packit Service 82fcde
@end deftypefun
Packit Service 82fcde
Packit Service 82fcde
@deftypefun void argp_state_help (const struct argp_state *@var{state}, FILE *@var{stream}, unsigned @var{flags})
Packit Service 82fcde
@standards{GNU, argp.h}
Packit Service 82fcde
@safety{@prelim{}@mtunsafe{@mtasurace{:argpbuf} @mtsenv{} @mtslocale{}}@asunsafe{@ascuheap{} @ascuintl{} @asucorrupt{}}@acunsafe{@acsmem{} @acucorrupt{} @aculock{}}}
Packit Service 82fcde
@c Just calls _help with the short program name and optionally exit.
Packit Service 82fcde
@c The main problems in _help, besides the usual issues with stream I/O
Packit Service 82fcde
@c and translation, are the use of a static buffer (uparams, thus
Packit Service 82fcde
@c @mtasurace:argpbuf) that makes the whole thing thread-unsafe, reading
Packit Service 82fcde
@c from the environment for ARGP_HELP_FMT, accessing the locale object
Packit Service 82fcde
@c multiple times.
Packit Service 82fcde
Packit Service 82fcde
@c _help @mtsenv @mtasurace:argpbuf @mtslocale @ascuheap @ascuintl @asucorrupt @acsmem @acucorrupt @aculock
Packit Service 82fcde
@c  dgettext @ascuintl
Packit Service 82fcde
@c  flockfile @aculock
Packit Service 82fcde
@c  funlockfile @aculock
Packit Service 82fcde
@c  fill_in_uparams @mtsenv @mtasurace:argpbuf @mtslocale @asucorrupt @ascuheap @aculock @acucorrupt @acsmem
Packit Service 82fcde
@c   argp_failure dup (status = errnum = 0)
Packit Service 82fcde
@c   atoi dup @mtslocale
Packit Service 82fcde
@c  argp_hol @ascuheap @acsmem
Packit Service 82fcde
@c   make_hol @ascuheap @acsmem
Packit Service 82fcde
@c   hol_add_cluster @ascuheap @acsmem
Packit Service 82fcde
@c   hol_append @ascuheap @acsmem
Packit Service 82fcde
@c  hol_set_group ok
Packit Service 82fcde
@c   hol_find_entry ok
Packit Service 82fcde
@c  hol_sort @mtslocale @acucorrupt
Packit Service 82fcde
@c   qsort dup @acucorrupt
Packit Service 82fcde
@c    hol_entry_qcmp @mtslocale
Packit Service 82fcde
@c     hol_entry_cmp @mtslocale
Packit Service 82fcde
@c      group_cmp ok
Packit Service 82fcde
@c      hol_cluster_cmp ok
Packit Service 82fcde
@c       group_cmp ok
Packit Service 82fcde
@c      hol_entry_first_short @mtslocale
Packit Service 82fcde
@c       hol_entry_short_iterate [@mtslocale]
Packit Service 82fcde
@c        until_short ok
Packit Service 82fcde
@c         oshort ok
Packit Service 82fcde
@c          isprint ok
Packit Service 82fcde
@c      odoc ok
Packit Service 82fcde
@c      hol_entry_first_long ok
Packit Service 82fcde
@c      canon_doc_option @mtslocale
Packit Service 82fcde
@c      tolower dup
Packit Service 82fcde
@c  hol_usage @mtslocale @ascuintl @ascuheap @acsmem
Packit Service 82fcde
@c   hol_entry_short_iterate ok
Packit Service 82fcde
@c    add_argless_short_opt ok
Packit Service 82fcde
@c   argp_fmtstream_printf dup
Packit Service 82fcde
@c   hol_entry_short_iterate @mtslocale @ascuintl @ascuheap @acsmem
Packit Service 82fcde
@c    usage_argful_short_opt @mtslocale @ascuintl @ascuheap @acsmem
Packit Service 82fcde
@c     dgettext dup
Packit Service 82fcde
@c     argp_fmtstream_printf dup
Packit Service 82fcde
@c   hol_entry_long_iterate @mtslocale @ascuintl @ascuheap @acsmem
Packit Service 82fcde
@c    usage_long_opt @mtslocale @ascuintl @ascuheap @acsmem
Packit Service 82fcde
@c     dgettext dup
Packit Service 82fcde
@c     argp_fmtstream_printf dup
Packit Service 82fcde
@c  hol_help @mtslocale @mtasurace:argpbuf @ascuheap @ascuintl @asucorrupt @acsmem @acucorrupt @aculock
Packit Service 82fcde
@c   hol_entry_help @mtslocale @mtasurace:argpbuf @ascuheap @ascuintl @asucorrupt @acsmem @acucorrupt @aculock
Packit Service 82fcde
@c    argp_fmtstream_set_lmargin dup
Packit Service 82fcde
@c    argp_fmtstream_wmargin dup
Packit Service 82fcde
@c    argp_fmtstream_set_wmargin dup
Packit Service 82fcde
@c    comma @mtslocale @ascuheap @ascuintl @asucorrupt @acsmem @acucorrupt @aculock
Packit Service 82fcde
@c     argp_fmtstream_putc dup
Packit Service 82fcde
@c     hol_cluster_is_child ok
Packit Service 82fcde
@c     argp_fmtstream_wmargin dup
Packit Service 82fcde
@c     print_header dup
Packit Service 82fcde
@c     argp_fmtstream_set_wmargin dup
Packit Service 82fcde
@c     argp_fmtstream_puts dup
Packit Service 82fcde
@c     indent_to dup
Packit Service 82fcde
@c    argp_fmtstream_putc dup
Packit Service 82fcde
@c    arg @mtslocale @ascuheap @acsmem
Packit Service 82fcde
@c     argp_fmtstream_printf dup
Packit Service 82fcde
@c    odoc dup
Packit Service 82fcde
@c    argp_fmtstream_puts dup
Packit Service 82fcde
@c    argp_fmtstream_printf dup
Packit Service 82fcde
@c    print_header @mtslocale @mtasurace:argpbuf @ascuheap @ascuintl @asucorrupt @acsmem @acucorrupt @aculock
Packit Service 82fcde
@c     dgettext dup
Packit Service 82fcde
@c     filter_doc dup
Packit Service 82fcde
@c     argp_fmtstream_putc dup
Packit Service 82fcde
@c     indent_to dup
Packit Service 82fcde
@c     argp_fmtstream_set_lmargin dup
Packit Service 82fcde
@c     argp_fmtstream_set_wmargin dup
Packit Service 82fcde
@c     argp_fmtstream_puts dup
Packit Service 82fcde
@c     free dup
Packit Service 82fcde
@c    filter_doc dup
Packit Service 82fcde
@c    argp_fmtstream_point dup
Packit Service 82fcde
@c    indent_to @mtslocale @ascuheap @asucorrupt @acsmem @acucorrupt @aculock
Packit Service 82fcde
@c     argp_fmtstream_point dup
Packit Service 82fcde
@c     argp_fmtstream_putc dup
Packit Service 82fcde
@c   dgettext dup
Packit Service 82fcde
@c   filter_doc dup
Packit Service 82fcde
@c   argp_fmtstream_putc dup
Packit Service 82fcde
@c   argp_fmtstream_puts dup
Packit Service 82fcde
@c   free dup
Packit Service 82fcde
@c  hol_free @ascuheap @acsmem
Packit Service 82fcde
@c   free dup
Packit Service 82fcde
@c  argp_args_levels ok
Packit Service 82fcde
@c  argp_args_usage @mtslocale @ascuintl @ascuheap @asucorrupt @acsmem @acucorrupt @aculock
Packit Service 82fcde
@c   dgettext dup
Packit Service 82fcde
@c   filter_doc ok
Packit Service 82fcde
@c    argp_input ok
Packit Service 82fcde
@c    argp->help_filter
Packit Service 82fcde
@c   space @mtslocale @ascuheap @asucorrupt @acsmem @acucorrupt @aculock
Packit Service 82fcde
@c    argp_fmtstream_point dup
Packit Service 82fcde
@c    argp_fmtstream_rmargin @mtslocale @asucorrupt @acucorrupt @aculock
Packit Service 82fcde
@c     argp_fmtstream_update dup
Packit Service 82fcde
@c    argp_fmtstream_putc dup
Packit Service 82fcde
@c   argp_fmtstream_write dup
Packit Service 82fcde
@c   free dup
Packit Service 82fcde
@c  argp_doc @mtslocale @ascuheap @ascuintl @asucorrupt @acsmem @acucorrupt @aculock
Packit Service 82fcde
@c   dgettext @ascuintl
Packit Service 82fcde
@c   strndup @ascuheap @acsmem
Packit Service 82fcde
@c   argp_input dup
Packit Service 82fcde
@c   argp->help_filter
Packit Service 82fcde
@c   argp_fmtstream_putc @mtslocale @ascuheap @asucorrupt @acsmem @acucorrupt @aculock
Packit Service 82fcde
@c    argp_fmtstream_ensure dup
Packit Service 82fcde
@c   argp_fmtstream_write dup
Packit Service 82fcde
@c   argp_fmtstream_puts dup
Packit Service 82fcde
@c   argp_fmtstream_point @mtslocale @asucorrupt @acucorrupt @aculock
Packit Service 82fcde
@c    argp_fmtstream_update dup
Packit Service 82fcde
@c   argp_fmtstream_lmargin dup
Packit Service 82fcde
@c   free dup
Packit Service 82fcde
@c  argp_make_fmtstream @ascuheap @acsmem
Packit Service 82fcde
@c  argp_fmtstream_free @mtslocale @ascuheap @asucorrupt @acsmem @acucorrupt @aculock
Packit Service 82fcde
@c   argp_fmtstream_update @mtslocale @asucorrupt @acucorrupt @aculock
Packit Service 82fcde
@c    put[w]c_unlocked dup
Packit Service 82fcde
@c    isblank in loop @mtslocale
Packit Service 82fcde
@c    fxprintf @aculock
Packit Service 82fcde
@c   fxprintf @aculock
Packit Service 82fcde
@c   free dup
Packit Service 82fcde
@c  argp_fmtstream_set_wmargin @mtslocale @asucorrupt @acucorrupt @aculock
Packit Service 82fcde
@c   argp_fmtstream_update dup
Packit Service 82fcde
@c  argp_fmtstream_printf @mtslocale @ascuheap @acsmem
Packit Service 82fcde
@c   argp_fmtstream_ensure dup
Packit Service 82fcde
@c   vsnprintf dup
Packit Service 82fcde
@c  argp_fmtstream_set_lmargin @mtslocale @asucorrupt @acucorrupt @aculock
Packit Service 82fcde
@c   argp_fmtstream_update dup
Packit Service 82fcde
@c  argp_fmtstream_puts @mtslocale @ascuheap @asucorrupt @acsmem @acucorrupt @aculock
Packit Service 82fcde
@c   argp_fmtstream_write @mtslocale @ascuheap @asucorrupt @acsmem @acucorrupt @aculock
Packit Service 82fcde
@c    argp_fmtstream_ensure @mtslocale @ascuheap @asucorrupt @acsmem @acucorrupt @aculock
Packit Service 82fcde
@c     argp_fmtstream_update dup
Packit Service 82fcde
@c     fxprintf @aculock
Packit Service 82fcde
@c     realloc @ascuheap @acsmem
Packit Service 82fcde
Outputs a help message for the argp parser referred to by @var{state},
Packit Service 82fcde
to @var{stream}.  The @var{flags} argument determines what sort of help
Packit Service 82fcde
message is produced.  @xref{Argp Help Flags}.
Packit Service 82fcde
@end deftypefun
Packit Service 82fcde
Packit Service 82fcde
Error output is sent to @code{@var{state}->err_stream}, and the program
Packit Service 82fcde
name printed is @code{@var{state}->name}.
Packit Service 82fcde
Packit Service 82fcde
The output or program termination behavior of these functions may be
Packit Service 82fcde
suppressed if the @code{ARGP_NO_EXIT} or @code{ARGP_NO_ERRS} flags are
Packit Service 82fcde
passed to @code{argp_parse}.  @xref{Argp Flags}.
Packit Service 82fcde
Packit Service 82fcde
This behavior is useful if an argp parser is exported for use by other
Packit Service 82fcde
programs (e.g., by a library), and may be used in a context where it is
Packit Service 82fcde
not desirable to terminate the program in response to parsing errors.  In
Packit Service 82fcde
argp parsers intended for such general use, and for the case where the
Packit Service 82fcde
program @emph{doesn't} terminate, calls to any of these functions should
Packit Service 82fcde
be followed by code that returns the appropriate error code:
Packit Service 82fcde
Packit Service 82fcde
@smallexample
Packit Service 82fcde
if (@var{bad argument syntax})
Packit Service 82fcde
  @{
Packit Service 82fcde
     argp_usage (@var{state});
Packit Service 82fcde
     return EINVAL;
Packit Service 82fcde
  @}
Packit Service 82fcde
@end smallexample
Packit Service 82fcde
Packit Service 82fcde
@noindent
Packit Service 82fcde
If a parser function will @emph{only} be used when @code{ARGP_NO_EXIT}
Packit Service 82fcde
is not set, the return may be omitted.
Packit Service 82fcde
Packit Service 82fcde
@node Argp Children, Argp Help Filtering, Argp Parser Functions, Argp Parsers
Packit Service 82fcde
@subsection Combining Multiple Argp Parsers
Packit Service 82fcde
Packit Service 82fcde
The @code{children} field in a @code{struct argp} enables other argp
Packit Service 82fcde
parsers to be combined with the referencing one for the parsing of a
Packit Service 82fcde
single set of arguments.  This field should point to a vector of
Packit Service 82fcde
@code{struct argp_child}, which is terminated by an entry having a value
Packit Service 82fcde
of zero in the @code{argp} field.
Packit Service 82fcde
Packit Service 82fcde
Where conflicts between combined parsers arise, as when two specify an
Packit Service 82fcde
option with the same name, the parser conflicts are resolved in favor of
Packit Service 82fcde
the parent argp parser(s), or the earlier of the argp parsers in the
Packit Service 82fcde
list of children.
Packit Service 82fcde
Packit Service 82fcde
@deftp {Data Type} {struct argp_child}
Packit Service 82fcde
@standards{GNU, argp.h}
Packit Service 82fcde
An entry in the list of subsidiary argp parsers pointed to by the
Packit Service 82fcde
@code{children} field in a @code{struct argp}.  The fields are as
Packit Service 82fcde
follows:
Packit Service 82fcde
Packit Service 82fcde
@table @code
Packit Service 82fcde
@item const struct argp *argp
Packit Service 82fcde
The child argp parser, or zero to end of the list.
Packit Service 82fcde
Packit Service 82fcde
@item int flags
Packit Service 82fcde
Flags for this child.
Packit Service 82fcde
Packit Service 82fcde
@item const char *header
Packit Service 82fcde
If non-zero, this is an optional header to be printed within help output
Packit Service 82fcde
before the child options.  As a side-effect, a non-zero value forces the
Packit Service 82fcde
child options to be grouped together.  To achieve this effect without
Packit Service 82fcde
actually printing a header string, use a value of @code{""}.  As with
Packit Service 82fcde
header strings specified in an option entry, the conventional value of
Packit Service 82fcde
the last character is @samp{:}.  @xref{Argp Option Vectors}.
Packit Service 82fcde
Packit Service 82fcde
@item int group
Packit Service 82fcde
This is where the child options are grouped relative to the other
Packit Service 82fcde
`consolidated' options in the parent argp parser.  The values are the
Packit Service 82fcde
same as the @code{group} field in @code{struct argp_option}.  @xref{Argp
Packit Service 82fcde
Option Vectors}.  All child-groupings follow parent options at a
Packit Service 82fcde
particular group level.  If both this field and @code{header} are zero,
Packit Service 82fcde
then the child's options aren't grouped together, they are merged with
Packit Service 82fcde
parent options at the parent option group level.
Packit Service 82fcde
Packit Service 82fcde
@end table
Packit Service 82fcde
@end deftp
Packit Service 82fcde
Packit Service 82fcde
@node Argp Flags, Argp Help, Argp Parsers, Argp
Packit Service 82fcde
@subsection Flags for @code{argp_parse}
Packit Service 82fcde
Packit Service 82fcde
The default behavior of @code{argp_parse} is designed to be convenient
Packit Service 82fcde
for the most common case of parsing program command line argument.  To
Packit Service 82fcde
modify these defaults, the following flags may be or'd together in the
Packit Service 82fcde
@var{flags} argument to @code{argp_parse}:
Packit Service 82fcde
Packit Service 82fcde
@vtable @code
Packit Service 82fcde
@item ARGP_PARSE_ARGV0
Packit Service 82fcde
@standards{GNU, argp.h}
Packit Service 82fcde
Don't ignore the first element of the @var{argv} argument to
Packit Service 82fcde
@code{argp_parse}.  Unless @code{ARGP_NO_ERRS} is set, the first element
Packit Service 82fcde
of the argument vector is skipped for option parsing purposes, as it
Packit Service 82fcde
corresponds to the program name in a command line.
Packit Service 82fcde
Packit Service 82fcde
@item ARGP_NO_ERRS
Packit Service 82fcde
@standards{GNU, argp.h}
Packit Service 82fcde
Don't print error messages for unknown options to @code{stderr}; unless
Packit Service 82fcde
this flag is set, @code{ARGP_PARSE_ARGV0} is ignored, as @code{argv[0]}
Packit Service 82fcde
is used as the program name in the error messages.  This flag implies
Packit Service 82fcde
@code{ARGP_NO_EXIT}.  This is based on the assumption that silent exiting
Packit Service 82fcde
upon errors is bad behavior.
Packit Service 82fcde
Packit Service 82fcde
@item ARGP_NO_ARGS
Packit Service 82fcde
@standards{GNU, argp.h}
Packit Service 82fcde
Don't parse any non-option args.  Normally these are parsed by calling
Packit Service 82fcde
the parse functions with a key of @code{ARGP_KEY_ARG}, the actual
Packit Service 82fcde
argument being the value.  This flag needn't normally be set, as the
Packit Service 82fcde
default behavior is to stop parsing as soon as an argument fails to be
Packit Service 82fcde
parsed.  @xref{Argp Parser Functions}.
Packit Service 82fcde
Packit Service 82fcde
@item ARGP_IN_ORDER
Packit Service 82fcde
@standards{GNU, argp.h}
Packit Service 82fcde
Parse options and arguments in the same order they occur on the command
Packit Service 82fcde
line.  Normally they're rearranged so that all options come first.
Packit Service 82fcde
Packit Service 82fcde
@item ARGP_NO_HELP
Packit Service 82fcde
@standards{GNU, argp.h}
Packit Service 82fcde
Don't provide the standard long option @samp{--help}, which ordinarily
Packit Service 82fcde
causes usage and option help information to be output to @code{stdout}
Packit Service 82fcde
and @code{exit (0)}.
Packit Service 82fcde
Packit Service 82fcde
@item ARGP_NO_EXIT
Packit Service 82fcde
@standards{GNU, argp.h}
Packit Service 82fcde
Don't exit on errors, although they may still result in error messages.
Packit Service 82fcde
Packit Service 82fcde
@item ARGP_LONG_ONLY
Packit Service 82fcde
@standards{GNU, argp.h}
Packit Service 82fcde
Use the GNU getopt `long-only' rules for parsing arguments.  This allows
Packit Service 82fcde
long-options to be recognized with only a single @samp{-}
Packit Service 82fcde
(i.e., @samp{-help}).  This results in a less useful interface, and its
Packit Service 82fcde
use is discouraged as it conflicts with the way most GNU programs work
Packit Service 82fcde
as well as the GNU coding standards.
Packit Service 82fcde
Packit Service 82fcde
@item ARGP_SILENT
Packit Service 82fcde
@standards{GNU, argp.h}
Packit Service 82fcde
Turns off any message-printing/exiting options, specifically
Packit Service 82fcde
@code{ARGP_NO_EXIT}, @code{ARGP_NO_ERRS}, and @code{ARGP_NO_HELP}.
Packit Service 82fcde
@end vtable
Packit Service 82fcde
Packit Service 82fcde
@node Argp Help Filtering, , Argp Children, Argp Parsers
Packit Service 82fcde
@need 2000
Packit Service 82fcde
@subsection Customizing Argp Help Output
Packit Service 82fcde
Packit Service 82fcde
The @code{help_filter} field in a @code{struct argp} is a pointer to a
Packit Service 82fcde
function that filters the text of help messages before displaying
Packit Service 82fcde
them.  They have a function signature like:
Packit Service 82fcde
Packit Service 82fcde
@smallexample
Packit Service 82fcde
char *@var{help-filter} (int @var{key}, const char *@var{text}, void *@var{input})
Packit Service 82fcde
@end smallexample
Packit Service 82fcde
Packit Service 82fcde
Packit Service 82fcde
@noindent
Packit Service 82fcde
Where @var{key} is either a key from an option, in which case @var{text}
Packit Service 82fcde
is that option's help text.  @xref{Argp Option Vectors}.  Alternately, one
Packit Service 82fcde
of the special keys with names beginning with @samp{ARGP_KEY_HELP_}
Packit Service 82fcde
might be used, describing which other help text @var{text} will contain.
Packit Service 82fcde
@xref{Argp Help Filter Keys}.
Packit Service 82fcde
Packit Service 82fcde
The function should return either @var{text} if it remains as-is, or a
Packit Service 82fcde
replacement string allocated using @code{malloc}.  This will be either be
Packit Service 82fcde
freed by argp or zero, which prints nothing.  The value of @var{text} is
Packit Service 82fcde
supplied @emph{after} any translation has been done, so if any of the
Packit Service 82fcde
replacement text needs translation, it will be done by the filter
Packit Service 82fcde
function.  @var{input} is either the input supplied to @code{argp_parse}
Packit Service 82fcde
or it is zero, if @code{argp_help} was called directly by the user.
Packit Service 82fcde
Packit Service 82fcde
@menu
Packit Service 82fcde
* Keys: Argp Help Filter Keys.  Special @var{key} values for help filter functions.
Packit Service 82fcde
@end menu
Packit Service 82fcde
Packit Service 82fcde
@node Argp Help Filter Keys, , , Argp Help Filtering
Packit Service 82fcde
@subsubsection Special Keys for Argp Help Filter Functions
Packit Service 82fcde
Packit Service 82fcde
The following special values may be passed to an argp help filter
Packit Service 82fcde
function as the first argument in addition to key values for user
Packit Service 82fcde
options.  They specify which help text the @var{text} argument contains:
Packit Service 82fcde
Packit Service 82fcde
@vtable @code
Packit Service 82fcde
@item ARGP_KEY_HELP_PRE_DOC
Packit Service 82fcde
@standards{GNU, argp.h}
Packit Service 82fcde
The help text preceding options.
Packit Service 82fcde
Packit Service 82fcde
@item ARGP_KEY_HELP_POST_DOC
Packit Service 82fcde
@standards{GNU, argp.h}
Packit Service 82fcde
The help text following options.
Packit Service 82fcde
Packit Service 82fcde
@item ARGP_KEY_HELP_HEADER
Packit Service 82fcde
@standards{GNU, argp.h}
Packit Service 82fcde
The option header string.
Packit Service 82fcde
Packit Service 82fcde
@item ARGP_KEY_HELP_EXTRA
Packit Service 82fcde
@standards{GNU, argp.h}
Packit Service 82fcde
This is used after all other documentation; @var{text} is zero for this key.
Packit Service 82fcde
Packit Service 82fcde
@item ARGP_KEY_HELP_DUP_ARGS_NOTE
Packit Service 82fcde
@standards{GNU, argp.h}
Packit Service 82fcde
The explanatory note printed when duplicate option arguments have been suppressed.
Packit Service 82fcde
Packit Service 82fcde
@item ARGP_KEY_HELP_ARGS_DOC
Packit Service 82fcde
@standards{GNU, argp.h}
Packit Service 82fcde
The argument doc string; formally the @code{args_doc} field from the argp parser.  @xref{Argp Parsers}.
Packit Service 82fcde
@end vtable
Packit Service 82fcde
Packit Service 82fcde
@node Argp Help, Argp Examples, Argp Flags, Argp
Packit Service 82fcde
@subsection The @code{argp_help} Function
Packit Service 82fcde
Packit Service 82fcde
Normally programs using argp need not be written with particular
Packit Service 82fcde
printing argument-usage-type help messages in mind as the standard
Packit Service 82fcde
@samp{--help} option is handled automatically by argp.  Typical error
Packit Service 82fcde
cases can be handled using @code{argp_usage} and
Packit Service 82fcde
@code{argp_error}.  @xref{Argp Helper Functions}.  However, if it's
Packit Service 82fcde
desirable to print a help message in some context other than parsing the
Packit Service 82fcde
program options, argp offers the @code{argp_help} interface.
Packit Service 82fcde
Packit Service 82fcde
@deftypefun void argp_help (const struct argp *@var{argp}, FILE *@var{stream}, unsigned @var{flags}, char *@var{name})
Packit Service 82fcde
@standards{GNU, argp.h}
Packit Service 82fcde
@safety{@prelim{}@mtunsafe{@mtasurace{:argpbuf} @mtsenv{} @mtslocale{}}@asunsafe{@ascuheap{} @ascuintl{} @asucorrupt{}}@acunsafe{@acsmem{} @acucorrupt{} @aculock{}}}
Packit Service 82fcde
@c Just calls _help.
Packit Service 82fcde
This outputs a help message for the argp parser @var{argp} to
Packit Service 82fcde
@var{stream}.  The type of messages printed will be determined by
Packit Service 82fcde
@var{flags}.
Packit Service 82fcde
Packit Service 82fcde
Any options such as @samp{--help} that are implemented automatically by
Packit Service 82fcde
argp itself will @emph{not} be present in the help output; for this
Packit Service 82fcde
reason it is best to use @code{argp_state_help} if calling from within
Packit Service 82fcde
an argp parser function.  @xref{Argp Helper Functions}.
Packit Service 82fcde
@end deftypefun
Packit Service 82fcde
Packit Service 82fcde
@menu
Packit Service 82fcde
* Flags: Argp Help Flags.       Specifying what sort of help message to print.
Packit Service 82fcde
@end menu
Packit Service 82fcde
Packit Service 82fcde
@node Argp Help Flags, , , Argp Help
Packit Service 82fcde
@subsection Flags for the @code{argp_help} Function
Packit Service 82fcde
Packit Service 82fcde
When calling @code{argp_help} (@pxref{Argp Help}) or
Packit Service 82fcde
@code{argp_state_help} (@pxref{Argp Helper Functions}) the exact output
Packit Service 82fcde
is determined by the @var{flags} argument.  This should consist of any of
Packit Service 82fcde
the following flags, or'd together:
Packit Service 82fcde
Packit Service 82fcde
@vtable @code
Packit Service 82fcde
@item ARGP_HELP_USAGE
Packit Service 82fcde
@standards{GNU, argp.h}
Packit Service 82fcde
A unix @samp{Usage:} message that explicitly lists all options.
Packit Service 82fcde
Packit Service 82fcde
@item ARGP_HELP_SHORT_USAGE
Packit Service 82fcde
@standards{GNU, argp.h}
Packit Service 82fcde
A unix @samp{Usage:} message that displays an appropriate placeholder to
Packit Service 82fcde
indicate where the options go; useful for showing the non-option
Packit Service 82fcde
argument syntax.
Packit Service 82fcde
Packit Service 82fcde
@item ARGP_HELP_SEE
Packit Service 82fcde
@standards{GNU, argp.h}
Packit Service 82fcde
A @samp{Try @dots{} for more help} message; @samp{@dots{}} contains the
Packit Service 82fcde
program name and @samp{--help}.
Packit Service 82fcde
Packit Service 82fcde
@item ARGP_HELP_LONG
Packit Service 82fcde
@standards{GNU, argp.h}
Packit Service 82fcde
A verbose option help message that gives each option available along
Packit Service 82fcde
with its documentation string.
Packit Service 82fcde
Packit Service 82fcde
@item ARGP_HELP_PRE_DOC
Packit Service 82fcde
@standards{GNU, argp.h}
Packit Service 82fcde
The part of the argp parser doc string preceding the verbose option help.
Packit Service 82fcde
Packit Service 82fcde
@item ARGP_HELP_POST_DOC
Packit Service 82fcde
@standards{GNU, argp.h}
Packit Service 82fcde
The part of the argp parser doc string that following the verbose option help.
Packit Service 82fcde
Packit Service 82fcde
@item ARGP_HELP_DOC
Packit Service 82fcde
@standards{GNU, argp.h}
Packit Service 82fcde
@code{(ARGP_HELP_PRE_DOC | ARGP_HELP_POST_DOC)}
Packit Service 82fcde
Packit Service 82fcde
@item ARGP_HELP_BUG_ADDR
Packit Service 82fcde
@standards{GNU, argp.h}
Packit Service 82fcde
A message that prints where to report bugs for this program, if the
Packit Service 82fcde
@code{argp_program_bug_address} variable contains this information.
Packit Service 82fcde
Packit Service 82fcde
@item ARGP_HELP_LONG_ONLY
Packit Service 82fcde
@standards{GNU, argp.h}
Packit Service 82fcde
This will modify any output to reflect the @code{ARGP_LONG_ONLY} mode.
Packit Service 82fcde
@end vtable
Packit Service 82fcde
Packit Service 82fcde
The following flags are only understood when used with
Packit Service 82fcde
@code{argp_state_help}.  They control whether the function returns after
Packit Service 82fcde
printing its output, or terminates the program:
Packit Service 82fcde
Packit Service 82fcde
@vtable @code
Packit Service 82fcde
@item ARGP_HELP_EXIT_ERR
Packit Service 82fcde
@standards{GNU, argp.h}
Packit Service 82fcde
This will terminate the program with @code{exit (argp_err_exit_status)}.
Packit Service 82fcde
Packit Service 82fcde
@item ARGP_HELP_EXIT_OK
Packit Service 82fcde
@standards{GNU, argp.h}
Packit Service 82fcde
This will terminate the program with @code{exit (0)}.
Packit Service 82fcde
@end vtable
Packit Service 82fcde
Packit Service 82fcde
The following flags are combinations of the basic flags for printing
Packit Service 82fcde
standard messages:
Packit Service 82fcde
Packit Service 82fcde
@vtable @code
Packit Service 82fcde
@item ARGP_HELP_STD_ERR
Packit Service 82fcde
@standards{GNU, argp.h}
Packit Service 82fcde
Assuming that an error message for a parsing error has printed, this
Packit Service 82fcde
prints a message on how to get help, and terminates the program with an
Packit Service 82fcde
error.
Packit Service 82fcde
Packit Service 82fcde
@item ARGP_HELP_STD_USAGE
Packit Service 82fcde
@standards{GNU, argp.h}
Packit Service 82fcde
This prints a standard usage message and terminates the program with an
Packit Service 82fcde
error.  This is used when no other specific error messages are
Packit Service 82fcde
appropriate or available.
Packit Service 82fcde
Packit Service 82fcde
@item ARGP_HELP_STD_HELP
Packit Service 82fcde
@standards{GNU, argp.h}
Packit Service 82fcde
This prints the standard response for a @samp{--help} option, and
Packit Service 82fcde
terminates the program successfully.
Packit Service 82fcde
@end vtable
Packit Service 82fcde
Packit Service 82fcde
@node Argp Examples, Argp User Customization, Argp Help, Argp
Packit Service 82fcde
@subsection Argp Examples
Packit Service 82fcde
Packit Service 82fcde
These example programs demonstrate the basic usage of argp.
Packit Service 82fcde
Packit Service 82fcde
@menu
Packit Service 82fcde
* 1: Argp Example 1.            A minimal program using argp.
Packit Service 82fcde
* 2: Argp Example 2.            A program using only default options.
Packit Service 82fcde
* 3: Argp Example 3.            A simple program with user options.
Packit Service 82fcde
* 4: Argp Example 4.            Combining multiple argp parsers.
Packit Service 82fcde
@end menu
Packit Service 82fcde
Packit Service 82fcde
@node Argp Example 1, Argp Example 2, , Argp Examples
Packit Service 82fcde
@subsubsection A Minimal Program Using Argp
Packit Service 82fcde
Packit Service 82fcde
This is perhaps the smallest program possible that uses argp.  It won't
Packit Service 82fcde
do much except give an error message and exit when there are any
Packit Service 82fcde
arguments, and prints a rather pointless message for @samp{--help}.
Packit Service 82fcde
Packit Service 82fcde
@smallexample
Packit Service 82fcde
@include argp-ex1.c.texi
Packit Service 82fcde
@end smallexample
Packit Service 82fcde
Packit Service 82fcde
@node Argp Example 2, Argp Example 3, Argp Example 1, Argp Examples
Packit Service 82fcde
@subsubsection A Program Using Argp with Only Default Options
Packit Service 82fcde
Packit Service 82fcde
This program doesn't use any options or arguments, it uses argp to be
Packit Service 82fcde
compliant with the GNU standard command line format.
Packit Service 82fcde
Packit Service 82fcde
In addition to giving no arguments and implementing a @samp{--help}
Packit Service 82fcde
option, this example has a @samp{--version} option, which will put the
Packit Service 82fcde
given documentation string and bug address in the @samp{--help} output,
Packit Service 82fcde
as per GNU standards.
Packit Service 82fcde
Packit Service 82fcde
The variable @code{argp} contains the argument parser
Packit Service 82fcde
specification.  Adding fields to this structure is the way most
Packit Service 82fcde
parameters are passed to @code{argp_parse}.  The first three fields are
Packit Service 82fcde
normally used, but they are not in this small program.  There are also
Packit Service 82fcde
two global variables that argp can use defined here,
Packit Service 82fcde
@code{argp_program_version} and @code{argp_program_bug_address}.  They
Packit Service 82fcde
are considered global variables because they will almost always be
Packit Service 82fcde
constant for a given program, even if they use different argument
Packit Service 82fcde
parsers for various tasks.
Packit Service 82fcde
Packit Service 82fcde
@smallexample
Packit Service 82fcde
@include argp-ex2.c.texi
Packit Service 82fcde
@end smallexample
Packit Service 82fcde
Packit Service 82fcde
@node Argp Example 3, Argp Example 4, Argp Example 2, Argp Examples
Packit Service 82fcde
@subsubsection A Program Using Argp with User Options
Packit Service 82fcde
Packit Service 82fcde
This program uses the same features as example 2, adding user options
Packit Service 82fcde
and arguments.
Packit Service 82fcde
Packit Service 82fcde
We now use the first four fields in @code{argp} (@pxref{Argp Parsers})
Packit Service 82fcde
and specify @code{parse_opt} as the parser function.  @xref{Argp Parser
Packit Service 82fcde
Functions}.
Packit Service 82fcde
Packit Service 82fcde
Note that in this example, @code{main} uses a structure to communicate
Packit Service 82fcde
with the @code{parse_opt} function, a pointer to which it passes in the
Packit Service 82fcde
@code{input} argument to @code{argp_parse}.  @xref{Argp}.  It is retrieved
Packit Service 82fcde
by @code{parse_opt} through the @code{input} field in its @code{state}
Packit Service 82fcde
argument.  @xref{Argp Parsing State}.  Of course, it's also possible to
Packit Service 82fcde
use global variables instead, but using a structure like this is
Packit Service 82fcde
somewhat more flexible and clean.
Packit Service 82fcde
Packit Service 82fcde
@smallexample
Packit Service 82fcde
@include argp-ex3.c.texi
Packit Service 82fcde
@end smallexample
Packit Service 82fcde
Packit Service 82fcde
@node Argp Example 4, , Argp Example 3, Argp Examples
Packit Service 82fcde
@subsubsection A Program Using Multiple Combined Argp Parsers
Packit Service 82fcde
Packit Service 82fcde
This program uses the same features as example 3, but has more options,
Packit Service 82fcde
and presents more structure in the @samp{--help} output.  It also
Packit Service 82fcde
illustrates how you can `steal' the remainder of the input arguments
Packit Service 82fcde
past a certain point for programs that accept a list of items.  It also
Packit Service 82fcde
illustrates the @var{key} value @code{ARGP_KEY_NO_ARGS}, which is only
Packit Service 82fcde
given if no non-option arguments were supplied to the
Packit Service 82fcde
program.  @xref{Argp Special Keys}.
Packit Service 82fcde
Packit Service 82fcde
For structuring help output, two features are used: @emph{headers} and a
Packit Service 82fcde
two part option string.  The @emph{headers} are entries in the options
Packit Service 82fcde
vector.  @xref{Argp Option Vectors}.  The first four fields are zero.  The
Packit Service 82fcde
two part documentation string are in the variable @code{doc}, which
Packit Service 82fcde
allows documentation both before and after the options.  @xref{Argp
Packit Service 82fcde
Parsers}, the two parts of @code{doc} are separated by a vertical-tab
Packit Service 82fcde
character (@code{'\v'}, or @code{'\013'}).  By convention, the
Packit Service 82fcde
documentation before the options is a short string stating what the
Packit Service 82fcde
program does, and after any options it is longer, describing the
Packit Service 82fcde
behavior in more detail.  All documentation strings are automatically
Packit Service 82fcde
filled for output, although newlines may be included to force a line
Packit Service 82fcde
break at a particular point.  In addition, documentation strings are
Packit Service 82fcde
passed to the @code{gettext} function, for possible translation into the
Packit Service 82fcde
current locale.
Packit Service 82fcde
Packit Service 82fcde
@smallexample
Packit Service 82fcde
@include argp-ex4.c.texi
Packit Service 82fcde
@end smallexample
Packit Service 82fcde
Packit Service 82fcde
@node Argp User Customization, , Argp Examples, Argp
Packit Service 82fcde
@subsection Argp User Customization
Packit Service 82fcde
Packit Service 82fcde
@cindex ARGP_HELP_FMT environment variable
Packit Service 82fcde
The formatting of argp @samp{--help} output may be controlled to some
Packit Service 82fcde
extent by a program's users, by setting the @code{ARGP_HELP_FMT}
Packit Service 82fcde
environment variable to a comma-separated list of tokens.  Whitespace is
Packit Service 82fcde
ignored:
Packit Service 82fcde
Packit Service 82fcde
@table @samp
Packit Service 82fcde
@item dup-args
Packit Service 82fcde
@itemx no-dup-args
Packit Service 82fcde
These turn @dfn{duplicate-argument-mode} on or off.  In duplicate
Packit Service 82fcde
argument mode, if an option that accepts an argument has multiple names,
Packit Service 82fcde
the argument is shown for each name.  Otherwise, it is only shown for the
Packit Service 82fcde
first long option.  A note is subsequently printed so the user knows that
Packit Service 82fcde
it applies to other names as well.  The default is @samp{no-dup-args},
Packit Service 82fcde
which is less consistent, but prettier.
Packit Service 82fcde
Packit Service 82fcde
@item dup-args-note
Packit Service 82fcde
@item no-dup-args-note
Packit Service 82fcde
These will enable or disable the note informing the user of suppressed
Packit Service 82fcde
option argument duplication.  The default is @samp{dup-args-note}.
Packit Service 82fcde
Packit Service 82fcde
@item short-opt-col=@var{n}
Packit Service 82fcde
This prints the first short option in column @var{n}.  The default is 2.
Packit Service 82fcde
Packit Service 82fcde
@item long-opt-col=@var{n}
Packit Service 82fcde
This prints the first long option in column @var{n}.  The default is 6.
Packit Service 82fcde
Packit Service 82fcde
@item doc-opt-col=@var{n}
Packit Service 82fcde
This prints `documentation options' (@pxref{Argp Option Flags}) in
Packit Service 82fcde
column @var{n}.  The default is 2.
Packit Service 82fcde
Packit Service 82fcde
@item opt-doc-col=@var{n}
Packit Service 82fcde
This prints the documentation for options starting in column
Packit Service 82fcde
@var{n}.  The default is 29.
Packit Service 82fcde
Packit Service 82fcde
@item header-col=@var{n}
Packit Service 82fcde
This will indent the group headers that document groups of options to
Packit Service 82fcde
column @var{n}.  The default is 1.
Packit Service 82fcde
Packit Service 82fcde
@item usage-indent=@var{n}
Packit Service 82fcde
This will indent continuation lines in @samp{Usage:} messages to column
Packit Service 82fcde
@var{n}.  The default is 12.
Packit Service 82fcde
Packit Service 82fcde
@item rmargin=@var{n}
Packit Service 82fcde
This will word wrap help output at or before column @var{n}.  The default
Packit Service 82fcde
is 79.
Packit Service 82fcde
@end table