1 /** 2 * @file getopt.h 3 * @copy 2012 MinGW.org project 4 * 5 * Permission is hereby granted, free of charge, to any person obtaining a 6 * copy of this software and associated documentation files (the "Software"), 7 * to deal in the Software without restriction, including without limitation 8 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 9 * and/or sell copies of the Software, and to permit persons to whom the 10 * Software is furnished to do so, subject to the following conditions: 11 * 12 * The above copyright notice and this permission notice (including the next 13 * paragraph) shall be included in all copies or substantial portions of the 14 * Software. 15 * 16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 22 * DEALINGS IN THE SOFTWARE. 23 */ 24 #ifndef _GETOPT_H 25 #define _GETOPT_H 26 27 /* 28 * Defines constants and function prototypes required to implement 29 * the `getopt', `getopt_long' and `getopt_long_only' APIs. 30 */ 31 32 #ifdef __cplusplus 33 extern "C" { 34 #endif 35 36 extern int optind; /* index of first non-option in argv */ 37 extern int optopt; /* single option character, as parsed */ 38 extern int opterr; /* flag to enable built-in diagnostics... */ 39 /* (user may set to zero, to suppress) */ 40 41 extern char *optarg; /* pointer to argument of current option */ 42 43 extern int getopt( int, char * const [], const char * ); 44 45 #ifdef _BSD_SOURCE 46 /* 47 * BSD adds the non-standard `optreset' feature, for reinitialisation 48 * of `getopt' parsing. We support this feature, for applications which 49 * proclaim their BSD heritage, before including this header; however, 50 * to maintain portability, developers are advised to avoid it. 51 */ 52 # define optreset __mingw_optreset 53 54 extern int optreset; 55 #endif 56 #ifdef __cplusplus 57 } 58 #endif 59 /* 60 * POSIX requires the `getopt' API to be specified in `unistd.h'; 61 * thus, `unistd.h' includes this header. However, we do not want 62 * to expose the `getopt_long' or `getopt_long_only' APIs, when 63 * included in this manner. Thus, close the standard __GETOPT_H__ 64 * declarations block, and open an additional __GETOPT_LONG_H__ 65 * specific block, only when *not* __UNISTD_H_SOURCED__, in which 66 * to declare the extended API. 67 */ 68 #endif /* !defined(__GETOPT_H__) */ 69 #if !defined(__UNISTD_H_SOURCED__) && !defined(__GETOPT_LONG_H__) 70 #define __GETOPT_LONG_H__ 71 72 #ifdef __cplusplus 73 extern "C" { 74 #endif 75 76 struct option /* specification for a long form option... */ 77 { 78 const char *name; /* option name, without leading hyphens */ 79 int has_arg; /* does it take an argument? */ 80 int *flag; /* where to save its status, or NULL */ 81 int val; /* its associated status value */ 82 }; 83 84 enum /* permitted values for its `has_arg' field... */ 85 { 86 no_argument = 0, /* option never takes an argument */ 87 required_argument, /* option always requires an argument */ 88 optional_argument /* option may take an argument */ 89 }; 90 91 extern int getopt_long( int, char * const [], const char *, const struct option *, int * ); 92 extern int getopt_long_only( int, char * const [], const char *, const struct option *, int * ); 93 /* 94 * Previous MinGW implementation had... 95 */ 96 #ifndef HAVE_DECL_GETOPT 97 /* 98 * ...for the long form API only; keep this for compatibility. 99 */ 100 # define HAVE_DECL_GETOPT 1 101 #endif 102 103 #ifdef __cplusplus 104 } 105 #endif 106 107 #endif /* !defined(__UNISTD_H_SOURCED__) && !defined(__GETOPT_LONG_H__) */ 108