1 /* Declarations for getopt (GNU extensions). 2 Copyright (C) 1989-2019 Free Software Foundation, Inc. 3 This file is part of the GNU C Library and is also part of gnulib. 4 Patches to this file should be submitted to both projects. 5 6 The GNU C Library is free software; you can redistribute it and/or 7 modify it under the terms of the GNU Lesser General Public 8 License as published by the Free Software Foundation; either 9 version 2.1 of the License, or (at your option) any later version. 10 11 The GNU C Library is distributed in the hope that it will be useful, 12 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 Lesser General Public License for more details. 15 16 You should have received a copy of the GNU Lesser General Public 17 License along with the GNU C Library; if not, see 18 <http://www.gnu.org/licenses/>. */ 19 20 #ifndef _GETOPT_EXT_H 21 #define _GETOPT_EXT_H 1 22 23 /* This header should not be used directly; include getopt.h instead. 24 Unlike most bits headers, it does not have a protective #error, 25 because the guard macro for getopt.h in gnulib is not fixed. */ 26 27 /* Describe the long-named options requested by the application. 28 The LONG_OPTIONS argument to getopt_long or getopt_long_only is a vector 29 of 'struct option' terminated by an element containing a name which is 30 zero. 31 32 The field 'has_arg' is: 33 no_argument (or 0) if the option does not take an argument, 34 required_argument (or 1) if the option requires an argument, 35 optional_argument (or 2) if the option takes an optional argument. 36 37 If the field 'flag' is not NULL, it points to a variable that is set 38 to the value given in the field 'val' when the option is found, but 39 left unchanged if the option is not found. 40 41 To have a long-named option do something other than set an 'int' to 42 a compiled-in constant, such as set a value from 'optarg', set the 43 option's 'flag' field to zero and its 'val' field to a nonzero 44 value (the equivalent single-letter option character, if there is 45 one). For long options that have a zero 'flag' field, 'getopt' 46 returns the contents of the 'val' field. */ 47 48 struct option 49 { 50 const char *name; 51 /* has_arg can't be an enum because some compilers complain about 52 type mismatches in all the code that assumes it is an int. */ 53 int has_arg; 54 int *flag; 55 int val; 56 }; 57 58 /* Names for the values of the 'has_arg' field of 'struct option'. */ 59 60 #define no_argument 0 61 #define required_argument 1 62 #define optional_argument 2 63 64 extern int getopt_long (int ___argc, char *__getopt_argv_const *___argv, 65 const char *__shortopts, 66 const struct option *__longopts, int *__longind); 67 extern int getopt_long_only (int ___argc, char *__getopt_argv_const *___argv, 68 const char *__shortopts, 69 const struct option *__longopts, int *__longind); 70 71 #endif /* getopt_ext.h */ 72