Import ezmlm 0.53
[ezmlm] / getopt.3
CommitLineData
5b62e993
MW
1.TH getopt 3
2.SH NAME
3getopt \- get option character from command line
4.SH SYNTAX
5.B #include <getopt.h>
6
7char *\fBoptarg\fP;
8.br
9int \fBoptind\fP;
10.br
11int \fBoptpos\fP;
12.br
13int \fBopteof\fP;
14.br
15int \fBoptproblem\fP;
16.br
17char *\fBoptprogname\fP;
18.br
19int \fBopterr\fP;
20
21int \fBgetopt(\fP\fIargc,argv,opts\fR\fB)\fP;
22
23int \fIargc\fR;
24.br
25char **\fIargv\fR;
26.br
27char *\fIopts\fR;
28.SH DESCRIPTION
29This is a clone version of
30the standard
31.B getopt
32library,
33built on top of
34.BR subgetopt(3) .
35
36See
37.B subgetopt(3)
38for a detailed description of
39.B getopt
40processing.
41The main difference between
42.B getopt
43and
44.B subgetopt
45is that
46.B getopt
47prints error messages
48in case of problems.
49To turn off these error messages, set
50.B opterr
51(default nonzero)
52to zero.
53
54This clone version of
55.B getopt
56also provides an
57.B optprogname
58variable.
59There are two uses for this variable:
60
61(1)
62By default
63.B optprogname
64is null.
65When
66.B getopt
67sees this,
68it
69attempts to initialize
70.B optprogname
71from
72.IR argv\fB[0] ,
73stripping the directory name.
74The calling program can use
75.B optprogname
76after calling
77.B getopt
78at least once.
79This is appropriate if the name of the program should be
80determined from its command line.
81
82(2)
83.B getopt
84prints
85.B optprogname
86at the beginning
87of any error messages.
88So the calling program can,
89before calling
90.BR getopt ,
91initialize
92.B optprogname
93as desired.
94This is appropriate if the name of the program should not be
95determined from its command line.
96.SH "COMPATIBILITY"
97Old versions of
98.B getopt
99do not include
100.BR opterr .
101.BR optpos ,
102.BR opteof ,
103.BR optproblem ,
104and
105.B optprogname
106are specific to this clone version of
107.BR getopt .
108
109Many features of this clone version of
110.B getopt
111are poorly defined, if available at all,
112in most versions of
113.BR getopt .
114For example, the standard
115.B getopt
116interface does not define
117.B optind
118until the end of the option list.
119And
120.B optarg
121is not defined
122unless
123.B getopt
124has just returned
125an option which takes an argument.
126In this clone version,
127.B optind
128and
129.B optpos
130always indicate the next character to be read,
131and
132.B optarg
133is null whenever
134the current option does not take an argument.
135See
136.B subgetopt(3)
137for precise definitions of the parsing procedure.
138
139When it reaches the end of the option list,
140this version of
141.B getopt
142always returns
143.BR opteof ,
144which is the same as
145.BR subgetoptdone ,
146which is initialized to
147.BR SUBGETOPTDONE ,
148which is defined as \-1.
149The standard behavior is to return
150EOF
151from
152.B stdio(3).
153This is incompatible
154on any weird machine where
155EOF is different from \-1.
156The calling program could set
157.B opteof
158to EOF to imitate the standard behavior.
159
160Like most versions of
161.BR getopt ,
162this clone version allows, but does not demand, that
163option arguments be
164separated from the option by whitespace, i.e., be
165in the next command-line argument.
166
167Some versions of
168.B getopt
169provide an
170.B optopt
171variable.
172.B optopt
173is incompatible across systems:
174for example,
175GNU
176.B getopt
177uses it the same way that this clone version uses
178.BR optproblem ,
179while
180BSD
181.B getopt
182uses it to
183indicate the last option character returned by
184.BR getopt .
185This clone version does not provide
186.BR optopt .
187The use of
188.B optopt
189is strongly discouraged.
190
191Some versions of
192.B getopt
193do not recognize a double hyphen as the end of arguments.
194This version allows a double hyphen, or in fact any argument beginning
195with two hyphens.
196
197A lone hyphen is always recognized as the end of arguments.
198Some versions of
199.B getopt
200allow lone hyphens as options.
201This practice is wrong and is strongly discouraged.
202.SH "SYNTAX NOTE"
203.B getopt
204is actually a macro abbreviation for
205.BR getoptmine .
206The external
207.B opterr
208and
209.B optprogname
210variables
211are macros for
212.B getopterr
213and
214.BR getoptprogname .
215All the other
216.B opt
217variables are macros
218for
219.BR subgetopt .
220These macros are defined in
221.BR <getopt.h> ,
222unless
223.B GETOPTNOSHORT
224is defined.
225Further macros are defined in
226.BR <subgetopt.h> ,
227which is included by
228.BR <getopt.h> ,
229unless
230.B SUBGETOPTNOSHORT
231is defined.
232.SH VERSION
233getopt version 1.9, 931129.
234.SH AUTHOR
235Placed into the public domain by Daniel J. Bernstein.