| 1 | /* Declarations for getopt. |
| 2 | Copyright (C) 1989,90,91,92,93,94,96,97 Free Software Foundation, Inc. |
| 3 | |
| 4 | This file is part of the GNU C Library. Its master source is NOT part of |
| 5 | the C library, however. The master source lives in /gd/gnu/lib. |
| 6 | |
| 7 | The GNU C Library is free software; you can redistribute it and/or |
| 8 | modify it under the terms of the GNU Library General Public License as |
| 9 | published by the Free Software Foundation; either version 2 of the |
| 10 | License, or (at your option) any later version. |
| 11 | |
| 12 | The GNU C Library is distributed in the hope that it will be useful, |
| 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15 | Library General Public License for more details. |
| 16 | |
| 17 | You should have received a copy of the GNU Library General Public |
| 18 | License along with the GNU C Library; see the file COPYING.LIB. If not, |
| 19 | write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
| 20 | Boston, MA 02111-1307, USA. */ |
| 21 | |
| 22 | #ifndef _PVPGN_GETOPT_H_ |
| 23 | #define _PVPGN_GETOPT_H_ 1 |
| 24 | |
| 25 | #include "common/setup_before.h" |
| 26 | |
| 27 | #ifdef HAVE_UNISTD_H |
| 28 | # include <unistd.h> |
| 29 | #endif |
| 30 | |
| 31 | #ifndef HAVE_GETOPT |
| 32 | |
| 33 | namespace pvpgn |
| 34 | { |
| 35 | |
| 36 | /* For communication from `getopt' to the caller. |
| 37 | When `getopt' finds an option that takes an argument, |
| 38 | the argument value is returned here. |
| 39 | Also, when `ordering' is RETURN_IN_ORDER, |
| 40 | each non-option ARGV-element is returned here. */ |
| 41 | |
| 42 | extern char *optarg; |
| 43 | |
| 44 | /* Index in ARGV of the next element to be scanned. |
| 45 | This is used for communication to and from the caller |
| 46 | and for communication between successive calls to `getopt'. |
| 47 | |
| 48 | On entry to `getopt', zero means this is the first call; initialize. |
| 49 | |
| 50 | When `getopt' returns -1, this is the index of the first of the |
| 51 | non-option elements that the caller should itself scan. |
| 52 | |
| 53 | Otherwise, `optind' communicates from one call to the next |
| 54 | how much of ARGV has been scanned so far. */ |
| 55 | |
| 56 | extern int optind; |
| 57 | |
| 58 | /* Callers store zero here to inhibit the error message `getopt' prints |
| 59 | for unrecognized options. */ |
| 60 | |
| 61 | extern int opterr; |
| 62 | |
| 63 | /* Set to an option character which was unrecognized. */ |
| 64 | |
| 65 | extern int optopt; |
| 66 | |
| 67 | /* Describe the long-named options requested by the application. |
| 68 | The LONG_OPTIONS argument to getopt_long or getopt_long_only is a vector |
| 69 | of `struct option' terminated by an element containing a name which is |
| 70 | zero. |
| 71 | |
| 72 | The field `has_arg' is: |
| 73 | no_argument (or 0) if the option does not take an argument, |
| 74 | required_argument (or 1) if the option requires an argument, |
| 75 | optional_argument (or 2) if the option takes an optional argument. |
| 76 | |
| 77 | If the field `flag' is not NULL, it points to a variable that is set |
| 78 | to the value given in the field `val' when the option is found, but |
| 79 | left unchanged if the option is not found. |
| 80 | |
| 81 | To have a long-named option do something other than set an `int' to |
| 82 | a compiled-in constant, such as set a value from `optarg', set the |
| 83 | option's `flag' field to zero and its `val' field to a nonzero |
| 84 | value (the equivalent single-letter option character, if there is |
| 85 | one). For long options that have a zero `flag' field, `getopt' |
| 86 | returns the contents of the `val' field. */ |
| 87 | |
| 88 | struct option |
| 89 | { |
| 90 | const char *name; |
| 91 | |
| 92 | /* has_arg can't be an enum because some compilers complain about |
| 93 | type mismatches in all the code that assumes it is an int. */ |
| 94 | int has_arg; |
| 95 | int *flag; |
| 96 | int val; |
| 97 | }; |
| 98 | |
| 99 | /* Names for the values of the `has_arg' field of `struct option'. */ |
| 100 | |
| 101 | #define no_argument 0 |
| 102 | #define required_argument 1 |
| 103 | #define optional_argument 2 |
| 104 | |
| 105 | extern int getopt(int argc, char *const *argv, const char *shortopts); |
| 106 | |
| 107 | } |
| 108 | |
| 109 | #endif /* !HAVE_GETOPT */ |
| 110 | |
| 111 | #endif /* _PVPGN_GETOPT_H_ */ |