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