summaryrefslogtreecommitdiff
path: root/manual/getopt.texi
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>2001-02-11 19:54:38 +0000
committerUlrich Drepper <drepper@redhat.com>2001-02-11 19:54:38 +0000
commit6062f8d97f629cbf8b53f35adf6840c6c5ee702b (patch)
tree7c6490c2d61909359795a27c36e1ed10e8de2610 /manual/getopt.texi
parent416539648101f2dff10c9b3d6abcee4f6612871a (diff)
(Getopt Long Options): Document getopt_long_only.
Diffstat (limited to 'manual/getopt.texi')
-rw-r--r--manual/getopt.texi32
1 files changed, 31 insertions, 1 deletions
diff --git a/manual/getopt.texi b/manual/getopt.texi
index f388c99394..a0c7ede907 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}