From: Ulrich Drepper Date: Sun, 11 Feb 2001 19:54:38 +0000 (+0000) Subject: (Getopt Long Options): Document getopt_long_only. X-Git-Tag: cvs/glibc-2_2_2~31 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=6062f8d97f629cbf8b53f35adf6840c6c5ee702b;p=thirdparty%2Fglibc.git (Getopt Long Options): Document getopt_long_only. --- diff --git a/manual/getopt.texi b/manual/getopt.texi index f388c993945..a0c7ede9074 100644 --- a/manual/getopt.texi +++ b/manual/getopt.texi @@ -224,7 +224,7 @@ was seen. @comment getopt.h @comment GNU -@deftypefun int getopt_long (int @var{argc}, char **@var{argv}, const char *@var{shortopts}, struct option *@var{longopts}, int *@var{indexptr}) +@deftypefun int getopt_long (int @var{argc}, char *const *@var{argv}, const char *@var{shortopts}, struct option *@var{longopts}, int *@var{indexptr}) Decode options from the vector @var{argv} (whose length is @var{argc}). The argument @var{shortopts} describes the short options to accept, just as it does in @code{getopt}. The argument @var{longopts} describes the long @@ -269,6 +269,36 @@ When @code{getopt_long} has no more options to handle, it returns @var{argv} of the next remaining argument. @end deftypefun +Since long option names were used before before the @code{getopt_long} +options was invented there are program interfaces which require programs +to recognize options like @w{@samp{-option value}} instead of +@w{@samp{--option value}}. To enable these programs to use the GNU +getopt functionality there is one more function available. + +@comment getopt.h +@comment GNU +@deftypefun int getopt_long_only (int @var{argc}, char *const *@var{argv}, const char *@var{shortopts}, struct option *@var{longopts}, int *@var{indexptr}) + +The @code{getopt_long_only} function is equivalent to the +@code{getopt_long} function but it allows to specify the user of the +application to pass long options with only @samp{-} instead of +@samp{--}. The @samp{--} prefix is still recognized but instead of +looking through the short options if a @samp{-} is seen it is first +tried whether this parameter names a long option. If not, it is parsed +as a short option. + +Assuming @code{getopt_long_only} is used starting an application with + +@smallexample + app -foo +@end smallexample + +@noindent +the @code{getopt_long_only} will first look for a long option named +@samp{foo}. If this is not found, the short options @samp{f}, @samp{o}, +and again @samp{o} are recognized. +@end deftypefun + @node Getopt Long Option Example @subsection Example of Parsing Long Options with @code{getopt_long}