source: trunk/src/emx/include/Attic/cpp/GetOpt.h@ 18

Last change on this file since 18 was 18, checked in by bird, 23 years ago

Initial revision

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