libdap
Updated for version 3.17.0
|
00001 /* Getopt for GNU. 00002 Copyright (C) 1987, 1989, 1992 Free Software Foundation, Inc. 00003 (Modified by Douglas C. Schmidt for use with GNU G++.) 00004 00005 This file is part of the GNU C++ Library. This library is free 00006 software; you can redistribute it and/or modify it under the terms of 00007 the GNU Library General Public License as published by the Free 00008 Software Foundation; either version 2 of the License, or (at your 00009 option) any later version. This library is distributed in the hope 00010 that it will be useful, but WITHOUT ANY WARRANTY; without even the 00011 implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 00012 PURPOSE. See the GNU Library General Public License for more details. 00013 You should have received a copy of the GNU Library General Public 00014 License along with this library; if not, write to the Free Software 00015 Foundation 51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA. 00016 */ 00017 00018 00019 /* This version of `getopt' appears to the caller like standard Unix `getopt' 00020 but it behaves differently for the user, since it allows the user 00021 to intersperse the options with the other arguments. 00022 00023 As `getopt' works, it permutes the elements of `argv' so that, 00024 when it is done, all the options precede everything else. Thus 00025 all application programs are extended to handle flexible argument order. 00026 00027 Setting the environment variable _POSIX_OPTION_ORDER disables permutation. 00028 Then the behavior is completely standard. 00029 00030 GNU application programs can use a third alternative mode in which 00031 they can distinguish the relative order of options and other arguments. */ 00032 00033 #ifndef GetOpt_h 00034 #define GetOpt_h 1 00035 00036 // #include <stdio.h> 00037 00038 class GetOpt 00039 { 00040 private: 00041 /* The next char to be scanned in the option-element 00042 in which the last option character we returned was found. 00043 This allows us to pick up the scan where we left off. 00044 00045 If this is zero, or a null string, it means resume the scan 00046 by advancing to the next ARGV-element. */ 00047 00048 static char *nextchar; 00049 00050 00051 /* Describe how to deal with options that follow non-option ARGV-elements. 00052 00053 UNSPECIFIED means the caller did not specify anything; 00054 the default is then REQUIRE_ORDER if the environment variable 00055 _OPTIONS_FIRST is defined, PERMUTE otherwise. 00056 00057 REQUIRE_ORDER means don't recognize them as options. 00058 Stop option processing when the first non-option is seen. 00059 This is what Unix does. 00060 00061 PERMUTE is the default. We permute the contents of `argv' as we scan, 00062 so that eventually all the options are at the end. This allows options 00063 to be given in any order, even with programs that were not written to 00064 expect this. 00065 00066 RETURN_IN_ORDER is an option available to programs that were written 00067 to expect options and other ARGV-elements in any order and that care about 00068 the ordering of the two. We describe each non-option ARGV-element 00069 as if it were the argument of an option with character code zero. 00070 Using `-' as the first character of the list of option characters 00071 requests this mode of operation. 00072 00073 The special argument `--' forces an end of option-scanning regardless 00074 of the value of `ordering'. In the case of RETURN_IN_ORDER, only 00075 `--' can cause `getopt' to return EOF with `optind' != ARGC. */ 00076 00077 enum OrderingEnum { REQUIRE_ORDER, PERMUTE, RETURN_IN_ORDER }; 00078 OrderingEnum ordering; 00079 00080 /* Handle permutation of arguments. */ 00081 00082 /* Describe the part of ARGV that contains non-options that have 00083 been skipped. `first_nonopt' is the index in ARGV of the first of them; 00084 `last_nonopt' is the index after the last of them. */ 00085 00086 static int first_nonopt; 00087 static int last_nonopt; 00088 00089 void exchange (char **argv); 00090 public: 00091 /* For communication from `getopt' to the caller. 00092 When `getopt' finds an option that takes an argument, 00093 the argument value is returned here. 00094 Also, when `ordering' is RETURN_IN_ORDER, 00095 each non-option ARGV-element is returned here. */ 00096 00097 char *optarg; 00098 00099 /* Index in ARGV of the next element to be scanned. 00100 This is used for communication to and from the caller 00101 and for communication between successive calls to `getopt'. 00102 On entry to `getopt', zero means this is the first call; initialize. 00103 00104 When `getopt' returns EOF, this is the index of the first of the 00105 non-option elements that the caller should itself scan. 00106 00107 Otherwise, `optind' communicates from one call to the next 00108 how much of ARGV has been scanned so far. */ 00109 00110 int optind; 00111 00112 /* Callers store zero here to inhibit the error message 00113 for unrecognized options. */ 00114 00115 int opterr; 00116 00117 int nargc; 00118 char **nargv; 00119 const char *noptstring; 00120 00121 GetOpt (int argc, char **argv, const char *optstring); 00122 int operator () (void); 00123 }; 00124 00125 #endif