4778009409ad23f13d769c3ab3e5ba4dd67eb860
[libcext.git] / getopt_long.h
1 /*
2 * Copyright (c) 2002 Todd C. Miller <Todd.Miller@courtesan.com>
3 *
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 *
16 * Sponsored in part by the Defense Advanced Research Projects
17 * Agency (DARPA) and Air Force Research Laboratory, Air Force
18 * Materiel Command, USAF, under agreement number F39502-99-1-0512.
19 */
20
21 /*
22 * Copyright (c) 1990, 1993
23 * The Regents of the University of California. All rights reserved.
24 *
25 * Redistribution and use in source and binary forms, with or without
26 * modification, are permitted provided that the following conditions
27 * are met:
28 * 1. Redistributions of source code must retain the above copyright
29 * notice, this list of conditions and the following disclaimer.
30 * 2. Redistributions in binary form must reproduce the above copyright
31 * notice, this list of conditions and the following disclaimer in the
32 * documentation and/or other materials provided with the distribution.
33 * 3. Neither the name of the University nor the names of its contributors
34 * may be used to endorse or promote products derived from this software
35 * without specific prior written permission.
36 *
37 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
38 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
39 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
40 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
41 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
42 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
43 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
45 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
46 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
47 * SUCH DAMAGE.
48 */
49
50 /*
51 * Copyright (c) 2000 The NetBSD Foundation, Inc.
52 * All rights reserved.
53 *
54 * This code is derived from software contributed to The NetBSD Foundation
55 * by Dieter Baron and Thomas Klausner.
56 *
57 * Redistribution and use in source and binary forms, with or without
58 * modification, are permitted provided that the following conditions
59 * are met:
60 * 1. Redistributions of source code must retain the above copyright
61 * notice, this list of conditions and the following disclaimer.
62 * 2. Redistributions in binary form must reproduce the above copyright
63 * notice, this list of conditions and the following disclaimer in the
64 * documentation and/or other materials provided with the distribution.
65 *
66 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
67 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
68 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
69 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
70 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
71 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
72 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
73 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
74 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
75 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
76 * POSSIBILITY OF SUCH DAMAGE.
77 */
78
79 /* https://git.datadissipation.net */
80 #ifndef GETOPT_LONG_H_
81 #define GETOPT_LONG_H_ 1
82
83 #ifdef GETOPT_LONG_INCLUDE_LIBC
84 #include <stdarg.h>
85 #include <stdio.h>
86 #include <stdlib.h>
87 #include <string.h>
88 #endif /* GETOPT_LONG_INCLUDE_LIBC */
89
90 #ifndef HAVE_GETOPT_LONG
91 #define HAVE_GETOPT_LONG 1
92
93 #define no_argument 0
94 #define required_argument 1
95 #define optional_argument 2
96
97 /*
98 * structs are in their own namespace, so this should be OK
99 * the worst it can do is make compiler messages worse
100 */
101 #define option i_option_
102
103 #define optarg i_optarg_
104 #define suboptarg i_suboptarg_
105 #define optind i_optind_
106 #define opterr i_opterr_
107 #define optopt i_optopt_
108 #define optreset i_optreset_
109
110 #define getopt i_getopt_
111 #define getsubopt i_getsubopt_
112 #define getopt_long i_getopt_long_
113 #define getopt_long_only i_getopt_long_only_
114
115 #ifndef GETOPT_LONG_IMPLEMENTATION
116 extern char *i_optarg_;
117 extern char *i_suboptarg_;
118 extern int i_optind_, i_opterr_, i_optopt_, i_optreset_;
119 #endif /* !GETOPT_LONG_IMPLEMENTATION */
120
121 struct i_option_ {
122 const char *name;
123 /*
124 * one of no_argument, required_argument, and optional_argument:
125 * whether option takes an argument
126 */
127 int has_arg;
128 /* if not NULL, set *flag to val when option found */
129 int *flag;
130 /* if flag not NULL, value to set *flag to; else return value */
131 int val;
132 };
133
134 int i_getopt_(int argc, char * const *argv, const char *optstring);
135 int i_getsubopt_(char **optionp, char * const *tokens, char **valuep);
136 int i_getopt_long_(int argc, char * const *argv, const char *optstring,
137 const struct option *longopts, int *longindex);
138 int i_getopt_long_only_(int argc, char * const *argv, const char *optstring,
139 const struct option *longopts, int *longindex);
140
141 #endif /* !HAVE_GETOPT_LONG */
142
143 #ifdef GETOPT_LONG_IMPLEMENTATION
144 #define I_PRINT_ERROR_ ((i_opterr_) && (*options != ':'))
145
146 #define I_FLAG_PERMUTE_ 0x01 /* permute non-options to the end of argv */
147 #define I_FLAG_ALLARGS_ 0x02 /* treat non-options as args to option "-1" */
148 #define I_FLAG_LONGONLY_ 0x04 /* operate as getopt_long_only */
149
150 /* return values */
151 #define I_BADCH_ (int) '?'
152 #define I_BADARG_ ((*options == ':') ? (int) ':' : (int) '?')
153 #define I_INORDER_ (int) 1
154
155 #define I_EMSG_ ""
156
157 int i_opterr_ = 1; /* if error message should be printed */
158 int i_optind_ = 1; /* index into parent argv vector */
159 int i_optopt_ = '?'; /* character checked for validity */
160 int i_optreset_; /* reset getopt */
161 char *i_optarg_; /* argument associated with option */
162 char *i_suboptarg_; /* argument associated with suboption */
163
164 /* XXX: set optreset to 1 rather than these two */
165 static int i_nonopt_start_ = -1; /* first non option argument (for permute) */
166 static int i_nonopt_end_ = -1; /* first option after non options (for permute) */
167 static char *i_place_ = I_EMSG_; /* option letter processing */
168 static char *i_progname_; /* program name == argv[0] */
169
170 /* Error messages */
171 static const char i_recargchar_[] = "option requires an argument -- %c";
172 static const char i_recargstring_[] = "option requires an argument -- %s";
173 static const char i_ambig_[] = "i_ambig_uous option -- %.*s";
174 static const char i_noarg_[] = "option doesn't take an argument -- %.*s";
175 static const char i_illoptchar_[] = "unknown option -- %c";
176 static const char i_illoptstring_[] = "unknown option -- %s";
177
178 static void i_warnx_(const char *, ...);
179 static int i_getopt_internal_(int, char * const *, const char *,
180 const struct option *, int *, int);
181 static int i_parse_long_options__(char * const *, const char *,
182 const struct option *, int *, int);
183 static int i_gcd_(int, int);
184 static void i_permute_args_(int, int, int, char * const *);
185
186 /*
187 * Own warnx() for portability
188 */
189 void
190 i_warnx_(const char *fmt, ...)
191 {
192 va_list args;
193
194 va_start(args, fmt);
195 fprintf(stderr, "%s: ", i_progname_);
196 vfprintf(stderr, fmt, args);
197 fputc('\n', stderr);
198 va_end(args);
199 }
200
201 /*
202 * Compute the greatest common divisor of a and b.
203 */
204 static int
205 i_gcd_(int a, int b)
206 {
207 int c;
208
209 c = a % b;
210 while (c != 0) {
211 a = b;
212 b = c;
213 c = a % b;
214 }
215
216 return (b);
217 }
218
219 /*
220 * Exchange the block from nonopt_start to nonopt_end with the block
221 * from nonopt_end to opt_end (keeping the same order of arguments
222 * in each block).
223 */
224 static void
225 i_permute_args_(int panonopt_start, int panonopt_end, int opt_end,
226 char * const *nargv)
227 {
228 int cstart, cyclelen, i, j, ncycle, nnonopts, nopts, pos;
229 char *swap;
230
231 /*
232 * compute lengths of blocks and number and size of cycles
233 */
234 nnonopts = panonopt_end - panonopt_start;
235 nopts = opt_end - panonopt_end;
236 ncycle = i_gcd_(nnonopts, nopts);
237 cyclelen = (opt_end - panonopt_start) / ncycle;
238
239 for (i = 0; i < ncycle; i++) {
240 cstart = panonopt_end+i;
241 pos = cstart;
242 for (j = 0; j < cyclelen; j++) {
243 if (pos >= panonopt_end)
244 pos -= nnonopts;
245 else
246 pos += nopts;
247 swap = nargv[pos];
248 /* LINTED const cast */
249 ((char **) nargv)[pos] = nargv[cstart];
250 /* LINTED const cast */
251 ((char **) nargv)[cstart] = swap;
252 }
253 }
254 }
255
256 /*
257 * i_parse_long_options__ --
258 * Parse long options in argc/argv argument vector.
259 * Returns -1 if short_too is set and the option does not match long_options.
260 */
261 static int
262 i_parse_long_options__(char * const *nargv, const char *options,
263 const struct option *long_options, int *idx, int
264 short_too)
265 {
266 char *current_argv, *has_equal;
267 size_t current_argv_len;
268 int i, match;
269
270 current_argv = i_place_;
271 match = -1;
272
273 i_optind_++;
274
275 if ((has_equal = strchr(current_argv, '=')) != NULL) {
276 /* argument found (--option=arg) */
277 current_argv_len = has_equal - current_argv;
278 has_equal++;
279 } else {
280 current_argv_len = strlen(current_argv);
281 }
282 for (i = 0; long_options[i].name; i++) {
283 /* find matching long option */
284 if (strncmp(current_argv, long_options[i].name,
285 current_argv_len))
286 continue;
287
288 if (strlen(long_options[i].name) == current_argv_len) {
289 /* exact match */
290 match = i;
291 break;
292 }
293 /*
294 * If this is a known short option, don't allow
295 * a partial match of a single character.
296 */
297 if (short_too && current_argv_len == 1)
298 continue;
299
300 if (match == -1) { /* partial match */
301 match = i;
302 } else {
303 /* ambiguous abbreviation */
304 if (I_PRINT_ERROR_)
305 i_warnx_(i_ambig_, (int) current_argv_len,
306 current_argv);
307 i_optopt_ = 0;
308 return (I_BADCH_);
309 }
310 }
311 if (match != -1) { /* option found */
312 if (long_options[match].has_arg == no_argument
313 && has_equal) {
314 if (I_PRINT_ERROR_)
315 i_warnx_(i_noarg_, (int) current_argv_len,
316 current_argv);
317 /*
318 * XXX: GNU sets optopt to val regardless of flag
319 */
320 if (long_options[match].flag == NULL)
321 i_optopt_ = long_options[match].val;
322 else
323 i_optopt_ = 0;
324 return (I_BADARG_);
325 }
326 if (long_options[match].has_arg == required_argument ||
327 long_options[match].has_arg == optional_argument) {
328 if (has_equal){
329 i_optarg_ = has_equal;
330 } else if (long_options[match].has_arg ==
331 required_argument) {
332 /*
333 * optional argument doesn't use next nargv
334 */
335 i_optarg_ = nargv[i_optind_++];
336 }
337 }
338 if ((long_options[match].has_arg == required_argument)
339 && (i_optarg_ == NULL)) {
340 /*
341 * Missing argument; leading ':' indicates no error
342 * should be generated.
343 */
344 if (I_PRINT_ERROR_)
345 i_warnx_(i_recargstring_,
346 current_argv);
347 /*
348 * XXX: GNU sets optopt to val regardless of flag
349 */
350 if (long_options[match].flag == NULL)
351 i_optopt_ = long_options[match].val;
352 else
353 i_optopt_ = 0;
354 --i_optind_;
355 return (I_BADARG_);
356 }
357 } else { /* unknown option */
358 if (short_too) {
359 --i_optind_;
360 return (-1);
361 }
362 if (I_PRINT_ERROR_)
363 i_warnx_(i_illoptstring_, current_argv);
364 i_optopt_ = 0;
365 return (I_BADCH_);
366 }
367 if (idx)
368 *idx = match;
369 if (long_options[match].flag) {
370 *long_options[match].flag = long_options[match].val;
371 return (0);
372 } else {
373 return (long_options[match].val);
374 }
375 }
376
377 /*
378 * i_getopt_internal_ --
379 * Parse argc/argv argument vector. Called by user level routines.
380 */
381 static int
382 i_getopt_internal_(int nargc, char *const *nargv, const char *options,
383 const struct option *long_options, int *idx, int flags)
384 {
385 char *oli; /* option letter list index */
386 int optchar, short_too;
387 static int posix_me_harder = -1;
388
389 i_progname_ = nargv[0];
390
391 if (options == NULL)
392 return (-1);
393
394 /*
395 * XXX Some GNU programs (like cvs) set optind to 0 instead of
396 * XXX using optreset. Work around this braindamage.
397 */
398 if (i_optind_ == 0)
399 i_optind_ = i_optreset_ = 1;
400
401 /*
402 * Disable GNU extensions if POSIXLY_CORRECT is set or options
403 * string begins with a '+'.
404 */
405 if (posix_me_harder == -1 || i_optreset_)
406 posix_me_harder = (getenv("POSIXLY_CORRECT") != NULL);
407 if (*options == '-')
408 flags |= I_FLAG_ALLARGS_;
409 else if (posix_me_harder || *options == '+')
410 flags &= ~I_FLAG_PERMUTE_;
411 if (*options == '+' || *options == '-')
412 options++;
413
414 i_optarg_ = NULL;
415 if (i_optreset_)
416 i_nonopt_start_ = i_nonopt_end_ = -1;
417 start:
418 if (i_optreset_ || !*i_place_) { /* update scanning pointer */
419 i_optreset_ = 0;
420 if (i_optind_ >= nargc) { /* end of argument vector */
421 i_place_ = I_EMSG_;
422 if (i_nonopt_end_ != -1) {
423 /* do permutation, if we have to */
424 i_permute_args_(i_nonopt_start_, i_nonopt_end_,
425 i_optind_, nargv);
426 i_optind_ -= i_nonopt_end_ - i_nonopt_start_;
427 } else if (i_nonopt_start_ != -1) {
428 /*
429 * If we skipped non-options, set optind
430 * to the first of them.
431 */
432 i_optind_ = i_nonopt_start_;
433 }
434 i_nonopt_start_ = i_nonopt_end_ = -1;
435 return (-1);
436 }
437 if (*(i_place_ = nargv[i_optind_]) != '-' ||
438 (i_place_[1] == '\0' && strchr(options, '-') == NULL)) {
439 i_place_ = I_EMSG_; /* found non-option */
440 if (flags & I_FLAG_ALLARGS_) {
441 /*
442 * GNU extension:
443 * return non-option as argument to option 1
444 */
445 i_optarg_ = nargv[i_optind_++];
446 return (I_INORDER_);
447 }
448 if (!(flags & I_FLAG_PERMUTE_)) {
449 /*
450 * If no permutation wanted, stop parsing
451 * at first non-option.
452 */
453 return (-1);
454 }
455 /* do permutation */
456 if (i_nonopt_start_ == -1) {
457 i_nonopt_start_ = i_optind_;
458 } else if (i_nonopt_end_ != -1) {
459 i_permute_args_(i_nonopt_start_, i_nonopt_end_,
460 i_optind_, nargv);
461 i_nonopt_start_ = i_optind_ -
462 (i_nonopt_end_ -
463 i_nonopt_start_);
464 i_nonopt_end_ = -1;
465 }
466 i_optind_++;
467 /* process next argument */
468 goto start;
469 }
470 if (i_nonopt_start_ != -1 && i_nonopt_end_ == -1)
471 i_nonopt_end_ = i_optind_;
472
473 /*
474 * If we have "-" do nothing, if "--" we are done.
475 */
476 if (i_place_[1] != '\0' && *++i_place_ == '-' && i_place_[1] ==
477 '\0') {
478 i_optind_++;
479 i_place_ = I_EMSG_;
480 /*
481 * We found an option (--), so if we skipped
482 * non-options, we have to permute.
483 */
484 if (i_nonopt_end_ != -1) {
485 i_permute_args_(i_nonopt_start_, i_nonopt_end_,
486 i_optind_, nargv);
487 i_optind_ -= i_nonopt_end_ - i_nonopt_start_;
488 }
489 i_nonopt_start_ = i_nonopt_end_ = -1;
490 return (-1);
491 }
492 }
493
494 /*
495 * Check long options if:
496 * 1) we were passed some
497 * 2) the arg is not just "-"
498 * 3) either the arg starts with -- we are i_getopt_long_only()
499 */
500 if (long_options != NULL && i_place_ != nargv[i_optind_] &&
501 (*i_place_ == '-' || (flags & I_FLAG_LONGONLY_))) {
502 short_too = 0;
503 if (*i_place_ == '-')
504 i_place_++; /* --foo long option */
505 else if (*i_place_ != ':'
506 && strchr(options, *i_place_) != NULL)
507 short_too = 1; /* could be short option too */
508
509 optchar = i_parse_long_options__(nargv, options, long_options,
510 idx, short_too);
511 if (optchar != -1) {
512 i_place_ = I_EMSG_;
513 return (optchar);
514 }
515 }
516
517 if ((optchar = (int) *i_place_++) == (int) ':' ||
518 (optchar == (int) '-' && *i_place_ != '\0') ||
519 (oli = strchr(options, optchar)) == NULL) {
520 /*
521 * If the user specified "-" and '-' isn't listed in
522 * options, return -1 (non-option) as per POSIX.
523 * Otherwise, it is an unknown option character (or ':').
524 */
525 if (optchar == (int) '-' && *i_place_ == '\0')
526 return (-1);
527 if (!*i_place_)
528 ++i_optind_;
529 if (I_PRINT_ERROR_)
530 i_warnx_(i_illoptchar_, optchar);
531 i_optopt_ = optchar;
532 return (I_BADCH_);
533 }
534 if (long_options != NULL && optchar == 'W' && oli[1] == ';') {
535 /* -W long-option */
536 if (*i_place_) { /* no space */
537 /* NOTHING */
538 ;
539 } else if (++i_optind_ >= nargc) { /* no arg */
540 i_place_ = I_EMSG_;
541 if (I_PRINT_ERROR_)
542 i_warnx_(i_recargchar_, optchar);
543 i_optopt_ = optchar;
544 return (I_BADARG_);
545 } else { /* white space */
546 i_place_ = nargv[i_optind_];
547 }
548 optchar = i_parse_long_options__(nargv, options, long_options,
549 idx, 0);
550 i_place_ = I_EMSG_;
551 return (optchar);
552 }
553 if (*++oli != ':') { /* doesn't take argument */
554 if (!*i_place_)
555 ++i_optind_;
556 } else { /* takes (optional) argument */
557 i_optarg_ = NULL;
558 if (*i_place_){ /* no white space */
559 i_optarg_ = i_place_;
560 } else if (oli[1] != ':'){ /* arg not optional */
561 if (++i_optind_ >= nargc) { /* no arg */
562 i_place_ = I_EMSG_;
563 if (I_PRINT_ERROR_)
564 i_warnx_(i_recargchar_, optchar);
565 i_optopt_ = optchar;
566 return (I_BADARG_);
567 } else {
568 i_optarg_ = nargv[i_optind_];
569 }
570 }
571 i_place_ = I_EMSG_;
572 ++i_optind_;
573 }
574 /* dump back option letter */
575 return (optchar);
576 }
577
578 int
579 i_getsubopt_(char **optionp, char * const *tokens, char **valuep)
580 {
581 int cnt;
582 char *p;
583
584 i_suboptarg_ = *valuep = NULL;
585
586 if (!optionp || !*optionp)
587 return (-1);
588
589 /* skip leading white-space, commas */
590 for (p = *optionp; *p && (*p == ',' || *p == ' ' || *p == '\t'); ++p) ;
591
592 if (!*p) {
593 *optionp = p;
594 return (-1);
595 }
596
597 /* save the start of the token, and skip the rest of the token. */
598 for (i_suboptarg_ = p;
599 *++p && *p != ',' && *p != '=' && *p != ' ' && *p != '\t';) ;
600
601 if (*p) {
602 /*
603 * If there's an equals sign, set the value pointer, and
604 * skip over the value part of the token. Terminate the
605 * token.
606 */
607 if (*p == '=') {
608 *p = '\0';
609 for (*valuep = ++p;
610 *p && *p != ',' && *p != ' ' && *p != '\t'; ++p) ;
611 if (*p)
612 *p++ = '\0';
613 } else {
614 *p++ = '\0';
615 }
616 /* Skip any whitespace or commas after this token. */
617 for (; *p && (*p == ',' || *p == ' ' || *p == '\t'); ++p) ;
618 }
619
620 /* set optionp for next round. */
621 *optionp = p;
622
623 for (cnt = 0; *tokens; ++tokens, ++cnt)
624 if (!strcmp(i_suboptarg_, *tokens))
625 return (cnt);
626 return (-1);
627 }
628
629 int
630 i_getopt_(int argc, char * const *argv, const char *optstring)
631 {
632 #ifdef GETOPT_PERMUTE_ARGS
633 return (i_getopt_internal_(argc, argv, optstring, NULL, NULL,
634 I_FLAG_PERMUTE_));
635 #else
636 return (i_getopt_internal_(argc, argv, optstring, NULL, NULL, 0));
637 #endif
638 }
639
640 int
641 i_getopt_long_(int argc, char * const *argv, const char *optstring,
642 const struct option *longopts, int *longindex)
643 {
644 #ifdef GETOPT_LONG_PERMUTE_ARGS
645 return (i_getopt_internal_(argc, argv, optstring, longopts, longindex,
646 I_FLAG_PERMUTE_));
647 #else
648 return (i_getopt_internal_(argc, argv, optstring, longopts, longindex, 0
649 ));
650 #endif
651 }
652
653 int
654 i_getopt_long_only_(int argc, char * const *argv, const char *optstring,
655 const struct option *longopts, int *longindex)
656 {
657 #ifdef GETOPT_LONG_ONLY_PERMUTE_ARGS
658 return (i_getopt_internal_(argc, argv, optstring, longopts, longindex,
659 I_FLAG_PERMUTE_ | I_FLAG_LONGONLY_));
660 #else
661 return (i_getopt_internal_(argc, argv, optstring, longopts, longindex,
662 I_FLAG_LONGONLY_));
663 #endif
664 }
665 #endif /* GETOPT_LONG_IMPLEMENTATION */
666 #endif /* !GETOPT_LONG_H_ */