Cygwin: mmap: allow remapping part of an existing anonymous mapping
[newlib-cygwin.git] / newlib / libc / include / getopt.h
blobac88524ead76a5ae013c33be906037f4b86fc970
1 /****************************************************************************
3 getopt.h - Read command line options
5 AUTHOR: Gregory Pietsch
6 CREATED Thu Jan 09 22:37:00 1997
8 DESCRIPTION:
10 The getopt() function parses the command line arguments. Its arguments argc
11 and argv are the argument count and array as passed to the main() function
12 on program invocation. The argument optstring is a list of available option
13 characters. If such a character is followed by a colon (`:'), the option
14 takes an argument, which is placed in optarg. If such a character is
15 followed by two colons, the option takes an optional argument, which is
16 placed in optarg. If the option does not take an argument, optarg is NULL.
18 The external variable optind is the index of the next array element of argv
19 to be processed; it communicates from one call to the next which element to
20 process.
22 The getopt_long() function works like getopt() except that it also accepts
23 long options started by two dashes `--'. If these take values, it is either
24 in the form
26 --arg=value
30 --arg value
32 It takes the additional arguments longopts which is a pointer to the first
33 element of an array of type GETOPT_LONG_OPTION_T, defined below. The last
34 element of the array has to be filled with NULL for the name field.
36 The longind pointer points to the index of the current long option relative
37 to longopts if it is non-NULL.
39 The getopt() function returns the option character if the option was found
40 successfully, `:' if there was a missing parameter for one of the options,
41 `?' for an unknown option character, and EOF for the end of the option list.
43 The getopt_long() function's return value is described below.
45 The function getopt_long_only() is identical to getopt_long(), except that a
46 plus sign `+' can introduce long options as well as `--'.
48 Describe how to deal with options that follow non-option ARGV-elements.
50 If the caller did not specify anything, the default is REQUIRE_ORDER if the
51 environment variable POSIXLY_CORRECT is defined, PERMUTE otherwise.
53 REQUIRE_ORDER means don't recognize them as options; stop option processing
54 when the first non-option is seen. This is what Unix does. This mode of
55 operation is selected by either setting the environment variable
56 POSIXLY_CORRECT, or using `+' as the first character of the optstring
57 parameter.
59 PERMUTE is the default. We permute the contents of ARGV as we scan, so that
60 eventually all the non-options are at the end. This allows options to be
61 given in any order, even with programs that were not written to expect this.
63 RETURN_IN_ORDER is an option available to programs that were written to
64 expect options and other ARGV-elements in any order and that care about the
65 ordering of the two. We describe each non-option ARGV-element as if it were
66 the argument of an option with character code 1. Using `-' as the first
67 character of the optstring parameter selects this mode of operation.
69 The special argument `--' forces an end of option-scanning regardless of the
70 value of `ordering'. In the case of RETURN_IN_ORDER, only `--' can cause
71 getopt() and friends to return EOF with optind != argc.
73 COPYRIGHT NOTICE AND DISCLAIMER:
75 Copyright (C) 1997 Gregory Pietsch
77 This file and the accompanying getopt.c implementation file are hereby
78 placed in the public domain without restrictions. Just give the author
79 credit, don't claim you wrote it or prevent anyone else from using it.
81 Gregory Pietsch's current e-mail address:
82 gpietsch@comcast.net
83 ****************************************************************************/
85 /* This is a glibc-extension header file. */
87 #ifndef GETOPT_H
88 #define GETOPT_H
90 #include <_ansi.h>
92 /* include files needed by this include file */
94 #define no_argument 0
95 #define required_argument 1
96 #define optional_argument 2
98 #ifdef __cplusplus
99 extern "C"
102 #endif /* __cplusplus */
104 /* types defined by this include file */
105 struct option
107 const char *name; /* the name of the long option */
108 int has_arg; /* one of the above macros */
109 int *flag; /* determines if getopt_long() returns a
110 * value for a long option; if it is
111 * non-NULL, 0 is returned as a function
112 * value and the value of val is stored in
113 * the area pointed to by flag. Otherwise,
114 * val is returned. */
115 int val; /* determines the value to return if flag is
116 * NULL. */
120 /* While getopt.h is a glibc extension, the following are newlib extensions.
121 * They are optionally included via the __need_getopt_newlib flag. */
123 #ifdef __need_getopt_newlib
125 /* macros defined by this include file */
126 #define NO_ARG no_argument
127 #define REQUIRED_ARG required_argument
128 #define OPTIONAL_ARG optional_argument
130 /* The GETOPT_DATA_INITIALIZER macro is used to initialize a statically-
131 allocated variable of type struct getopt_data. */
132 #define GETOPT_DATA_INITIALIZER {0,0,0,0,0,0,0}
134 /* These #defines are to make accessing the reentrant functions easier. */
135 #define getopt_r __getopt_r
136 #define getopt_long_r __getopt_long_r
137 #define getopt_long_only_r __getopt_long_only_r
139 /* The getopt_data structure is for reentrancy. Its members are similar to
140 the externally-defined variables. */
141 typedef struct getopt_data
143 char *optarg;
144 int optind, opterr, optopt, optwhere;
145 int permute_from, num_nonopts;
146 } getopt_data;
148 #endif /* __need_getopt_newlib */
150 /* externally-defined variables */
151 extern char *optarg;
152 extern int optind;
153 extern int opterr;
154 extern int optopt;
156 /* function prototypes */
157 int getopt (int __argc, char *const __argv[], const char *__optstring);
159 int getopt_long (int __argc, char *const __argv[], const char *__shortopts,
160 const struct option * __longopts, int *__longind);
162 int getopt_long_only (int __argc, char *const __argv[], const char *__shortopts,
163 const struct option * __longopts, int *__longind);
165 #ifdef __need_getopt_newlib
166 int __getopt_r (int __argc, char *const __argv[], const char *__optstring,
167 struct getopt_data * __data);
169 int __getopt_long_r (int __argc, char *const __argv[], const char *__shortopts,
170 const struct option * __longopts, int *__longind,
171 struct getopt_data * __data);
173 int __getopt_long_only_r (int __argc, char *const __argv[], const char *__shortopts,
174 const struct option * __longopts, int *__longind,
175 struct getopt_data * __data);
176 #endif /* __need_getopt_newlib */
178 #ifdef __cplusplus
181 #endif /* __cplusplus */
183 #endif /* GETOPT_H */
185 /* END OF FILE getopt.h */