libdap Updated for version 3.20.11
libdap4 is an implementation of OPeNDAP's DAP protocol.
GetOpt.h
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
5This file is part of the GNU C++ Library. This library is free
6software; you can redistribute it and/or modify it under the terms of
7the GNU Library General Public License as published by the Free
8Software Foundation; either version 2 of the License, or (at your
9option) any later version. This library is distributed in the hope
10that it will be useful, but WITHOUT ANY WARRANTY; without even the
11implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12PURPOSE. See the GNU Library General Public License for more details.
13You should have received a copy of the GNU Library General Public
14License along with this library; if not, write to the Free Software
15Foundation 51 Franklin Street, Suite 500, Boston, MA 02110-1335 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#define GetOpt_h 1
35
36// #include <stdio.h>
37
38class GetOpt
39{
40private:
41 /* The next char to be scanned in the option-element
42 in which the last option character we returned was found.
43 This allows us to pick up the scan where we left off.
44
45 If this is zero, or a null string, it means resume the scan
46 by advancing to the next ARGV-element. */
47
48 static char *nextchar;
49
50
51 /* Describe how to deal with options that follow non-option ARGV-elements.
52
53 UNSPECIFIED means the caller did not specify anything;
54 the default is then REQUIRE_ORDER if the environment variable
55 _OPTIONS_FIRST is defined, PERMUTE otherwise.
56
57 REQUIRE_ORDER means don't recognize them as options.
58 Stop option processing when the first non-option is seen.
59 This is what Unix does.
60
61 PERMUTE is the default. We permute the contents of `argv' as we scan,
62 so that eventually all the options are at the end. This allows options
63 to be given in any order, even with programs that were not written to
64 expect this.
65
66 RETURN_IN_ORDER is an option available to programs that were written
67 to expect options and other ARGV-elements in any order and that care about
68 the ordering of the two. We describe each non-option ARGV-element
69 as if it were the argument of an option with character code zero.
70 Using `-' as the first character of the list of option characters
71 requests this mode of operation.
72
73 The special argument `--' forces an end of option-scanning regardless
74 of the value of `ordering'. In the case of RETURN_IN_ORDER, only
75 `--' can cause `getopt' to return EOF with `optind' != ARGC. */
76
77 enum OrderingEnum { REQUIRE_ORDER, PERMUTE, RETURN_IN_ORDER };
78 OrderingEnum ordering;
79
80 /* Handle permutation of arguments. */
81
82 /* Describe the part of ARGV that contains non-options that have
83 been skipped. `first_nonopt' is the index in ARGV of the first of them;
84 `last_nonopt' is the index after the last of them. */
85
86 static int first_nonopt;
87 static int last_nonopt;
88
89 void exchange (char **argv);
90public:
91 /* For communication from `getopt' to the caller.
92 When `getopt' finds an option that takes an argument,
93 the argument value is returned here.
94 Also, when `ordering' is RETURN_IN_ORDER,
95 each non-option ARGV-element is returned here. */
96
97 char *optarg;
98
99 /* Index in ARGV of the next element to be scanned.
100 This is used for communication to and from the caller
101 and for communication between successive calls to `getopt'.
102 On entry to `getopt', zero means this is the first call; initialize.
103
104 When `getopt' returns EOF, this is the index of the first of the
105 non-option elements that the caller should itself scan.
106
107 Otherwise, `optind' communicates from one call to the next
108 how much of ARGV has been scanned so far. */
109
110 int optind;
111
112 /* Callers store zero here to inhibit the error message
113 for unrecognized options. */
114
115 int opterr;
116
117 int nargc;
118 char **nargv;
119 const char *noptstring;
120
121 GetOpt (int argc, char **argv, const char *optstring);
122 int operator () (void);
123};
124
125#endif
Definition: GetOpt.h:39