libdap
Updated for version 3.21.1
libdap4 is an implementation of OPeNDAP's DAP protocol.
GetOpt.h
Go to the documentation of this file.
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 51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA.
16
*/
17
18
/* This version of `getopt' appears to the caller like standard Unix `getopt'
19
but it behaves differently for the user, since it allows the user
20
to intersperse the options with the other arguments.
21
22
As `getopt' works, it permutes the elements of `argv' so that,
23
when it is done, all the options precede everything else. Thus
24
all application programs are extended to handle flexible argument order.
25
26
Setting the environment variable _POSIX_OPTION_ORDER disables permutation.
27
Then the behavior is completely standard.
28
29
GNU application programs can use a third alternative mode in which
30
they can distinguish the relative order of options and other arguments. */
31
32
#ifndef GetOpt_h
33
#define GetOpt_h 1
34
35
// #include <stdio.h>
36
37
class
GetOpt
{
38
private
:
39
/* The next char to be scanned in the option-element
40
in which the last option character we returned was found.
41
This allows us to pick up the scan where we left off.
42
43
If this is zero, or a null string, it means resume the scan
44
by advancing to the next ARGV-element. */
45
46
static
char
*nextchar;
47
48
/* Describe how to deal with options that follow non-option ARGV-elements.
49
50
UNSPECIFIED means the caller did not specify anything;
51
the default is then REQUIRE_ORDER if the environment variable
52
_OPTIONS_FIRST is defined, PERMUTE otherwise.
53
54
REQUIRE_ORDER means don't recognize them as options.
55
Stop option processing when the first non-option is seen.
56
This is what Unix does.
57
58
PERMUTE is the default. We permute the contents of `argv' as we scan,
59
so that eventually all the options are at the end. This allows options
60
to be given in any order, even with programs that were not written to
61
expect this.
62
63
RETURN_IN_ORDER is an option available to programs that were written
64
to expect options and other ARGV-elements in any order and that care about
65
the ordering of the two. We describe each non-option ARGV-element
66
as if it were the argument of an option with character code zero.
67
Using `-' as the first character of the list of option characters
68
requests this mode of operation.
69
70
The special argument `--' forces an end of option-scanning regardless
71
of the value of `ordering'. In the case of RETURN_IN_ORDER, only
72
`--' can cause `getopt' to return EOF with `optind' != ARGC. */
73
74
enum
OrderingEnum { REQUIRE_ORDER, PERMUTE, RETURN_IN_ORDER };
75
OrderingEnum ordering;
76
77
/* Handle permutation of arguments. */
78
79
/* Describe the part of ARGV that contains non-options that have
80
been skipped. `first_nonopt' is the index in ARGV of the first of them;
81
`last_nonopt' is the index after the last of them. */
82
83
static
int
first_nonopt;
84
static
int
last_nonopt;
85
86
void
exchange(
char
**argv);
87
88
public
:
89
/* For communication from `getopt' to the caller.
90
When `getopt' finds an option that takes an argument,
91
the argument value is returned here.
92
Also, when `ordering' is RETURN_IN_ORDER,
93
each non-option ARGV-element is returned here. */
94
95
char
*
optarg
;
96
97
/* Index in ARGV of the next element to be scanned.
98
This is used for communication to and from the caller
99
and for communication between successive calls to `getopt'.
100
On entry to `getopt', zero means this is the first call; initialize.
101
102
When `getopt' returns EOF, this is the index of the first of the
103
non-option elements that the caller should itself scan.
104
105
Otherwise, `optind' communicates from one call to the next
106
how much of ARGV has been scanned so far. */
107
108
int
optind
;
109
110
/* Callers store zero here to inhibit the error message
111
for unrecognized options. */
112
113
int
opterr
;
114
115
int
nargc
;
116
char
**
nargv
;
117
const
char
*
noptstring
;
118
119
GetOpt
(
int
argc,
char
**argv,
const
char
*optstring);
120
int
operator()
(
void
);
121
};
122
123
#endif
GetOpt::nargc
int nargc
Definition
GetOpt.h:115
GetOpt::opterr
int opterr
Definition
GetOpt.h:113
GetOpt::GetOpt
GetOpt(int argc, char **argv, const char *optstring)
Definition
GetOpt.cc:51
GetOpt::noptstring
const char * noptstring
Definition
GetOpt.h:117
GetOpt::operator()
int operator()(void)
Definition
GetOpt.cc:137
GetOpt::optarg
char * optarg
Definition
GetOpt.h:95
GetOpt::optind
int optind
Definition
GetOpt.h:108
GetOpt::nargv
char ** nargv
Definition
GetOpt.h:116
GNU
GetOpt.h
Generated by
1.13.2