annotate lib-src/getopt.h @ 129:e292c9648bb9 xemacs-20-1p3

Import from CVS: tag xemacs-20-1p3
author cvs
date Mon, 13 Aug 2007 09:28:38 +0200
parents 376386a54a3c
children 43dd3413c7c7
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1 /* Declarations for getopt.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2 Copyright (C) 1989, 90, 91, 92, 93, 94 Free Software Foundation, Inc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4 This program is free software; you can redistribute it and/or modify it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5 under the terms of the GNU General Public License as published by the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6 Free Software Foundation; either version 2, or (at your option) any
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7 later version.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9 This program is distributed in the hope that it will be useful,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12 GNU General Public License for more details.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14 You should have received a copy of the GNU General Public License
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15 along with this program; see the file COPYING. If not, write to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17 Boston, MA 02111-1307, USA. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19 /* Synched up with: FSF 19.29. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21 #ifndef _GETOPT_H
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22 #define _GETOPT_H 1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24 #ifdef __cplusplus
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25 extern "C" {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28 /* For communication from `getopt' to the caller.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29 When `getopt' finds an option that takes an argument,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30 the argument value is returned here.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31 Also, when `ordering' is RETURN_IN_ORDER,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32 each non-option ARGV-element is returned here. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34 extern char *optarg;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 /* Index in ARGV of the next element to be scanned.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37 This is used for communication to and from the caller
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 and for communication between successive calls to `getopt'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 On entry to `getopt', zero means this is the first call; initialize.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 When `getopt' returns EOF, this is the index of the first of the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43 non-option elements that the caller should itself scan.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 Otherwise, `optind' communicates from one call to the next
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 how much of ARGV has been scanned so far. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 extern int optind;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 /* Callers store zero here to inhibit the error message `getopt' prints
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 for unrecognized options. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 extern int opterr;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 /* Set to an option character which was unrecognized. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 extern int optopt;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 /* Describe the long-named options requested by the application.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 The LONG_OPTIONS argument to getopt_long or getopt_long_only is a vector
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 of `struct option' terminated by an element containing a name which is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 zero.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64 The field `has_arg' is:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 no_argument (or 0) if the option does not take an argument,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 required_argument (or 1) if the option requires an argument,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 optional_argument (or 2) if the option takes an optional argument.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 If the field `flag' is not NULL, it points to a variable that is set
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 to the value given in the field `val' when the option is found, but
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 left unchanged if the option is not found.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 To have a long-named option do something other than set an `int' to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 a compiled-in constant, such as set a value from `optarg', set the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 option's `flag' field to zero and its `val' field to a nonzero
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 value (the equivalent single-letter option character, if there is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 one). For long options that have a zero `flag' field, `getopt'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 returns the contents of the `val' field. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 struct option
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 #if defined (__STDC__) && __STDC__ || defined (STDC_HEADERS)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 const char *name;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 char *name;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 /* has_arg can't be an enum because some compilers complain about
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 type mismatches in all the code that assumes it is an int. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 int has_arg;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 int *flag;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 int val;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 };
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 /* Names for the values of the `has_arg' field of `struct option'. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 #define no_argument 0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 #define required_argument 1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 #define optional_argument 2
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 #if defined (__STDC__) && __STDC__ || defined (STDC_HEADERS)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 #ifdef __GNU_LIBRARY__
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 /* Many other libraries have conflicting prototypes for getopt, with
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 differences in the consts, in stdlib.h. To avoid compilation
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 errors, only prototype getopt for the GNU C library. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 extern int getopt (int argc, char *const *argv, const char *shortopts);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 #else /* not __GNU_LIBRARY__ */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 extern int getopt ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 #endif /* __GNU_LIBRARY__ */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 extern int getopt_long (int argc, char *const *argv, const char *shortopts,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 const struct option *longopts, int *longind);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 extern int getopt_long_only (int argc, char *const *argv,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 const char *shortopts,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 const struct option *longopts, int *longind);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 /* Internal only. Users should not call this directly. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 extern int _getopt_internal (int argc, char *const *argv,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117 const char *shortopts,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 const struct option *longopts, int *longind,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 int long_only);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 #else /* not __STDC__ */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 extern int getopt ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 extern int getopt_long ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 extern int getopt_long_only ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 extern int _getopt_internal ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 #endif /* __STDC__ */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 #ifdef __cplusplus
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 #endif /* _GETOPT_H */