Sync usage with man page.
[netbsd-mini2440.git] / gnu / lib / libg++ / g++-include / GetOpt.h
blob413c52d64c12cb2e958f4bd305bc4dff5767e262
1 /* Getopt for GNU.
2 Copyright (C) 1987, 1989 Free Software Foundation, Inc.
3 (Modified by Douglas C. Schmidt for use with GNU G++.)
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 1, or (at your option)
8 any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
21 /* This version of `getopt' appears to the caller like standard Unix `getopt'
22 but it behaves differently for the user, since it allows the user
23 to intersperse the options with the other arguments.
25 As `getopt' works, it permutes the elements of `argv' so that,
26 when it is done, all the options precede everything else. Thus
27 all application programs are extended to handle flexible argument order.
29 Setting the environment variable _POSIX_OPTION_ORDER disables permutation.
30 Then the behavior is completely standard.
32 GNU application programs can use a third alternative mode in which
33 they can distinguish the relative order of options and other arguments. */
35 #ifndef GetOpt_h
36 #ifdef __GNUG__
37 #pragma once
38 #pragma interface
39 #endif
40 #define GetOpt_h 1
42 #include <std.h>
43 #include <stdio.h>
45 class GetOpt
47 private:
48 /* The next char to be scanned in the option-element
49 in which the last option character we returned was found.
50 This allows us to pick up the scan where we left off.
52 If this is zero, or a null string, it means resume the scan
53 by advancing to the next ARGV-element. */
55 static char *nextchar;
58 /* Describe how to deal with options that follow non-option ARGV-elements.
60 UNSPECIFIED means the caller did not specify anything;
61 the default is then REQUIRE_ORDER if the environment variable
62 _OPTIONS_FIRST is defined, PERMUTE otherwise.
64 REQUIRE_ORDER means don't recognize them as options.
65 Stop option processing when the first non-option is seen.
66 This is what Unix does.
68 PERMUTE is the default. We permute the contents of `argv' as we scan,
69 so that eventually all the options are at the end. This allows options
70 to be given in any order, even with programs that were not written to
71 expect this.
73 RETURN_IN_ORDER is an option available to programs that were written
74 to expect options and other ARGV-elements in any order and that care about
75 the ordering of the two. We describe each non-option ARGV-element
76 as if it were the argument of an option with character code zero.
77 Using `-' as the first character of the list of option characters
78 requests this mode of operation.
80 The special argument `--' forces an end of option-scanning regardless
81 of the value of `ordering'. In the case of RETURN_IN_ORDER, only
82 `--' can cause `getopt' to return EOF with `optind' != ARGC. */
84 static enum { REQUIRE_ORDER, PERMUTE, RETURN_IN_ORDER } ordering;
86 /* Handle permutation of arguments. */
88 /* Describe the part of ARGV that contains non-options that have
89 been skipped. `first_nonopt' is the index in ARGV of the first of them;
90 `last_nonopt' is the index after the last of them. */
92 static int first_nonopt;
93 static int last_nonopt;
95 void exchange (char **argv);
96 public:
97 /* For communication from `getopt' to the caller.
98 When `getopt' finds an option that takes an argument,
99 the argument value is returned here.
100 Also, when `ordering' is RETURN_IN_ORDER,
101 each non-option ARGV-element is returned here. */
103 char *optarg;
105 /* Index in ARGV of the next element to be scanned.
106 This is used for communication to and from the caller
107 and for communication between successive calls to `getopt'.
108 On entry to `getopt', zero means this is the first call; initialize.
110 When `getopt' returns EOF, this is the index of the first of the
111 non-option elements that the caller should itself scan.
113 Otherwise, `optind' communicates from one call to the next
114 how much of ARGV has been scanned so far. */
116 int optind;
118 /* Callers store zero here to inhibit the error message
119 for unrecognized options. */
121 int opterr;
123 int nargc;
124 char **nargv;
125 char *noptstring;
127 GetOpt (int argc, char **argv, char *optstring);
128 int operator () (void);
131 #endif