annotate liboctave/getopt.h @ 1229:7d7c3eaa1d3b

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