win_getopt.h 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674
  1. /**
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. /**
  19. * DISCLAIMER
  20. * This file is part of the mingw-w64 runtime package.
  21. *
  22. * The mingw-w64 runtime package and its code is distributed in the hope that it
  23. * will be useful but WITHOUT ANY WARRANTY. ALL WARRANTIES, EXPRESSED OR
  24. * IMPLIED ARE HEREBY DISCLAIMED. This includes but is not limited to
  25. * warranties of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  26. */
  27. /*
  28. * Copyright (c) 2002 Todd C. Miller <Todd.Miller@courtesan.com>
  29. *
  30. * Permission to use, copy, modify, and distribute this software for any
  31. * purpose with or without fee is hereby granted, provided that the above
  32. * copyright notice and this permission notice appear in all copies.
  33. *
  34. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  35. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  36. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  37. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  38. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  39. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  40. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  41. *
  42. * Sponsored in part by the Defense Advanced Research Projects
  43. * Agency (DARPA) and Air Force Research Laboratory, Air Force
  44. * Materiel Command, USAF, under agreement number F39502-99-1-0512.
  45. */
  46. /*-
  47. * Copyright (c) 2000 The NetBSD Foundation, Inc.
  48. * All rights reserved.
  49. *
  50. * This code is derived from software contributed to The NetBSD Foundation
  51. * by Dieter Baron and Thomas Klausner.
  52. *
  53. * Redistribution and use in source and binary forms, with or without
  54. * modification, are permitted provided that the following conditions
  55. * are met:
  56. * 1. Redistributions of source code must retain the above copyright
  57. * notice, this list of conditions and the following disclaimer.
  58. * 2. Redistributions in binary form must reproduce the above copyright
  59. * notice, this list of conditions and the following disclaimer in the
  60. * documentation and/or other materials provided with the distribution.
  61. *
  62. * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
  63. * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
  64. * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  65. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
  66. * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  67. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  68. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  69. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  70. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  71. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  72. * POSSIBILITY OF SUCH DAMAGE.
  73. */
  74. #ifndef __GETOPT_H__
  75. #pragma warning(disable:4996);
  76. #define __GETOPT_H__
  77. /* All the headers include this file. */
  78. #include <crtdefs.h>
  79. #include <errno.h>
  80. #include <stdlib.h>
  81. #include <string.h>
  82. #include <stdarg.h>
  83. #include <stdio.h>
  84. #include <windows.h>
  85. #ifdef __cplusplus
  86. extern "C" {
  87. #endif
  88. #define REPLACE_GETOPT /* use this getopt as the system getopt(3) */
  89. #ifdef REPLACE_GETOPT
  90. int opterr = 1; /* if error message should be printed */
  91. int optind = 1; /* index into parent argv vector */
  92. int optopt = '?'; /* character checked for validity */
  93. #undef optreset /* see getopt.h */
  94. #define optreset __mingw_optreset
  95. int optreset; /* reset getopt */
  96. char *optarg; /* argument associated with option */
  97. #endif
  98. //extern int optind; /* index of first non-option in argv */
  99. //extern int optopt; /* single option character, as parsed */
  100. //extern int opterr; /* flag to enable built-in diagnostics... */
  101. // /* (user may set to zero, to suppress) */
  102. //
  103. //extern char *optarg; /* pointer to argument of current option */
  104. #define PRINT_ERROR ((opterr) && (*options != ':'))
  105. #define FLAG_PERMUTE 0x01 /* permute non-options to the end of argv */
  106. #define FLAG_ALLARGS 0x02 /* treat non-options as args to option "-1" */
  107. #define FLAG_LONGONLY 0x04 /* operate as getopt_long_only */
  108. /* return values */
  109. #define BADCH (int)'?'
  110. #define BADARG ((*options == ':') ? (int)':' : (int)'?')
  111. #define INORDER (int)1
  112. #ifndef __CYGWIN__
  113. #define __progname __argv[0]
  114. #else
  115. extern char __declspec(dllimport) *__progname;
  116. #endif
  117. #ifdef __CYGWIN__
  118. static char EMSG[] = "";
  119. #else
  120. #define EMSG ""
  121. #endif
  122. static int getopt_internal(int, char * const *, const char *,
  123. const struct option *, int *, int);
  124. static int parse_long_options(char * const *, const char *,
  125. const struct option *, int *, int);
  126. static int gcd(int, int);
  127. static void permute_args(int, int, int, char * const *);
  128. static char *place = EMSG; /* option letter processing */
  129. /* XXX: set optreset to 1 rather than these two */
  130. static int nonopt_start = -1; /* first non option argument (for permute) */
  131. static int nonopt_end = -1; /* first option after non options (for permute) */
  132. /* Error messages */
  133. static const char recargchar[] = "option requires an argument -- %c";
  134. static const char recargstring[] = "option requires an argument -- %s";
  135. static const char ambig[] = "ambiguous option -- %.*s";
  136. static const char noarg[] = "option doesn't take an argument -- %.*s";
  137. static const char illoptchar[] = "unknown option -- %c";
  138. static const char illoptstring[] = "unknown option -- %s";
  139. static void
  140. _vwarnx(const char *fmt,va_list ap)
  141. {
  142. (void)fprintf(stderr,"%s: ",__progname);
  143. if (fmt != NULL)
  144. (void)vfprintf(stderr,fmt,ap);
  145. (void)fprintf(stderr,"\n");
  146. }
  147. static void
  148. warnx(const char *fmt,...)
  149. {
  150. va_list ap;
  151. va_start(ap,fmt);
  152. _vwarnx(fmt,ap);
  153. va_end(ap);
  154. }
  155. /*
  156. * Compute the greatest common divisor of a and b.
  157. */
  158. static int
  159. gcd(int a, int b)
  160. {
  161. int c;
  162. c = a % b;
  163. while (c != 0) {
  164. a = b;
  165. b = c;
  166. c = a % b;
  167. }
  168. return (b);
  169. }
  170. /*
  171. * Exchange the block from nonopt_start to nonopt_end with the block
  172. * from nonopt_end to opt_end (keeping the same order of arguments
  173. * in each block).
  174. */
  175. static void
  176. permute_args(int panonopt_start, int panonopt_end, int opt_end,
  177. char * const *nargv)
  178. {
  179. int cstart, cyclelen, i, j, ncycle, nnonopts, nopts, pos;
  180. char *swap;
  181. /*
  182. * compute lengths of blocks and number and size of cycles
  183. */
  184. nnonopts = panonopt_end - panonopt_start;
  185. nopts = opt_end - panonopt_end;
  186. ncycle = gcd(nnonopts, nopts);
  187. cyclelen = (opt_end - panonopt_start) / ncycle;
  188. for (i = 0; i < ncycle; i++) {
  189. cstart = panonopt_end+i;
  190. pos = cstart;
  191. for (j = 0; j < cyclelen; j++) {
  192. if (pos >= panonopt_end)
  193. pos -= nnonopts;
  194. else
  195. pos += nopts;
  196. swap = nargv[pos];
  197. /* LINTED const cast */
  198. ((char **) nargv)[pos] = nargv[cstart];
  199. /* LINTED const cast */
  200. ((char **)nargv)[cstart] = swap;
  201. }
  202. }
  203. }
  204. #ifdef REPLACE_GETOPT
  205. /*
  206. * getopt --
  207. * Parse argc/argv argument vector.
  208. *
  209. * [eventually this will replace the BSD getopt]
  210. */
  211. int
  212. getopt(int nargc, char * const *nargv, const char *options)
  213. {
  214. /*
  215. * We don't pass FLAG_PERMUTE to getopt_internal() since
  216. * the BSD getopt(3) (unlike GNU) has never done this.
  217. *
  218. * Furthermore, since many privileged programs call getopt()
  219. * before dropping privileges it makes sense to keep things
  220. * as simple (and bug-free) as possible.
  221. */
  222. return (getopt_internal(nargc, nargv, options, NULL, NULL, 0));
  223. }
  224. #endif /* REPLACE_GETOPT */
  225. //extern int getopt(int nargc, char * const *nargv, const char *options);
  226. #ifdef _BSD_SOURCE
  227. /*
  228. * BSD adds the non-standard `optreset' feature, for reinitialisation
  229. * of `getopt' parsing. We support this feature, for applications which
  230. * proclaim their BSD heritage, before including this header; however,
  231. * to maintain portability, developers are advised to avoid it.
  232. */
  233. # define optreset __mingw_optreset
  234. extern int optreset;
  235. #endif
  236. #ifdef __cplusplus
  237. }
  238. #endif
  239. /*
  240. * POSIX requires the `getopt' API to be specified in `unistd.h';
  241. * thus, `unistd.h' includes this header. However, we do not want
  242. * to expose the `getopt_long' or `getopt_long_only' APIs, when
  243. * included in this manner. Thus, close the standard __GETOPT_H__
  244. * declarations block, and open an additional __GETOPT_LONG_H__
  245. * specific block, only when *not* __UNISTD_H_SOURCED__, in which
  246. * to declare the extended API.
  247. */
  248. #endif /* !defined(__GETOPT_H__) */
  249. #if !defined(__UNISTD_H_SOURCED__) && !defined(__GETOPT_LONG_H__)
  250. #define __GETOPT_LONG_H__
  251. #ifdef __cplusplus
  252. extern "C" {
  253. #endif
  254. struct option /* specification for a long form option... */
  255. {
  256. const char *name; /* option name, without leading hyphens */
  257. int has_arg; /* does it take an argument? */
  258. int *flag; /* where to save its status, or NULL */
  259. int val; /* its associated status value */
  260. };
  261. enum /* permitted values for its `has_arg' field... */
  262. {
  263. no_argument = 0, /* option never takes an argument */
  264. required_argument, /* option always requires an argument */
  265. optional_argument /* option may take an argument */
  266. };
  267. /*
  268. * parse_long_options --
  269. * Parse long options in argc/argv argument vector.
  270. * Returns -1 if short_too is set and the option does not match long_options.
  271. */
  272. static int
  273. parse_long_options(char * const *nargv, const char *options,
  274. const struct option *long_options, int *idx, int short_too)
  275. {
  276. char *current_argv, *has_equal;
  277. size_t current_argv_len;
  278. int i, ambiguous, match;
  279. #define IDENTICAL_INTERPRETATION(_x, _y) \
  280. (long_options[(_x)].has_arg == long_options[(_y)].has_arg && \
  281. long_options[(_x)].flag == long_options[(_y)].flag && \
  282. long_options[(_x)].val == long_options[(_y)].val)
  283. current_argv = place;
  284. match = -1;
  285. ambiguous = 0;
  286. optind++;
  287. if ((has_equal = strchr(current_argv, '=')) != NULL) {
  288. /* argument found (--option=arg) */
  289. current_argv_len = has_equal - current_argv;
  290. has_equal++;
  291. } else
  292. current_argv_len = strlen(current_argv);
  293. for (i = 0; long_options[i].name; i++) {
  294. /* find matching long option */
  295. if (strncmp(current_argv, long_options[i].name,
  296. current_argv_len))
  297. continue;
  298. if (strlen(long_options[i].name) == current_argv_len) {
  299. /* exact match */
  300. match = i;
  301. ambiguous = 0;
  302. break;
  303. }
  304. /*
  305. * If this is a known short option, don't allow
  306. * a partial match of a single character.
  307. */
  308. if (short_too && current_argv_len == 1)
  309. continue;
  310. if (match == -1) /* partial match */
  311. match = i;
  312. else if (!IDENTICAL_INTERPRETATION(i, match))
  313. ambiguous = 1;
  314. }
  315. if (ambiguous) {
  316. /* ambiguous abbreviation */
  317. if (PRINT_ERROR)
  318. warnx(ambig, (int)current_argv_len,
  319. current_argv);
  320. optopt = 0;
  321. return (BADCH);
  322. }
  323. if (match != -1) { /* option found */
  324. if (long_options[match].has_arg == no_argument
  325. && has_equal) {
  326. if (PRINT_ERROR)
  327. warnx(noarg, (int)current_argv_len,
  328. current_argv);
  329. /*
  330. * XXX: GNU sets optopt to val regardless of flag
  331. */
  332. if (long_options[match].flag == NULL)
  333. optopt = long_options[match].val;
  334. else
  335. optopt = 0;
  336. return (BADARG);
  337. }
  338. if (long_options[match].has_arg == required_argument ||
  339. long_options[match].has_arg == optional_argument) {
  340. if (has_equal)
  341. optarg = has_equal;
  342. else if (long_options[match].has_arg ==
  343. required_argument) {
  344. /*
  345. * optional argument doesn't use next nargv
  346. */
  347. optarg = nargv[optind++];
  348. }
  349. }
  350. if ((long_options[match].has_arg == required_argument)
  351. && (optarg == NULL)) {
  352. /*
  353. * Missing argument; leading ':' indicates no error
  354. * should be generated.
  355. */
  356. if (PRINT_ERROR)
  357. warnx(recargstring,
  358. current_argv);
  359. /*
  360. * XXX: GNU sets optopt to val regardless of flag
  361. */
  362. if (long_options[match].flag == NULL)
  363. optopt = long_options[match].val;
  364. else
  365. optopt = 0;
  366. --optind;
  367. return (BADARG);
  368. }
  369. } else { /* unknown option */
  370. if (short_too) {
  371. --optind;
  372. return (-1);
  373. }
  374. if (PRINT_ERROR)
  375. warnx(illoptstring, current_argv);
  376. optopt = 0;
  377. return (BADCH);
  378. }
  379. if (idx)
  380. *idx = match;
  381. if (long_options[match].flag) {
  382. *long_options[match].flag = long_options[match].val;
  383. return (0);
  384. } else
  385. return (long_options[match].val);
  386. #undef IDENTICAL_INTERPRETATION
  387. }
  388. /*
  389. * getopt_internal --
  390. * Parse argc/argv argument vector. Called by user level routines.
  391. */
  392. static int
  393. getopt_internal(int nargc, char * const *nargv, const char *options,
  394. const struct option *long_options, int *idx, int flags)
  395. {
  396. char *oli; /* option letter list index */
  397. int optchar, short_too;
  398. static int posixly_correct = -1;
  399. if (options == NULL)
  400. return (-1);
  401. /*
  402. * XXX Some GNU programs (like cvs) set optind to 0 instead of
  403. * XXX using optreset. Work around this braindamage.
  404. */
  405. if (optind == 0)
  406. optind = optreset = 1;
  407. /*
  408. * Disable GNU extensions if POSIXLY_CORRECT is set or options
  409. * string begins with a '+'.
  410. *
  411. * CV, 2009-12-14: Check POSIXLY_CORRECT anew if optind == 0 or
  412. * optreset != 0 for GNU compatibility.
  413. */
  414. if (posixly_correct == -1 || optreset != 0)
  415. posixly_correct = (getenv("POSIXLY_CORRECT") != NULL);
  416. if (*options == '-')
  417. flags |= FLAG_ALLARGS;
  418. else if (posixly_correct || *options == '+')
  419. flags &= ~FLAG_PERMUTE;
  420. if (*options == '+' || *options == '-')
  421. options++;
  422. optarg = NULL;
  423. if (optreset)
  424. nonopt_start = nonopt_end = -1;
  425. start:
  426. if (optreset || !*place) { /* update scanning pointer */
  427. optreset = 0;
  428. if (optind >= nargc) { /* end of argument vector */
  429. place = EMSG;
  430. if (nonopt_end != -1) {
  431. /* do permutation, if we have to */
  432. permute_args(nonopt_start, nonopt_end,
  433. optind, nargv);
  434. optind -= nonopt_end - nonopt_start;
  435. }
  436. else if (nonopt_start != -1) {
  437. /*
  438. * If we skipped non-options, set optind
  439. * to the first of them.
  440. */
  441. optind = nonopt_start;
  442. }
  443. nonopt_start = nonopt_end = -1;
  444. return (-1);
  445. }
  446. if (*(place = nargv[optind]) != '-' ||
  447. (place[1] == '\0' && strchr(options, '-') == NULL)) {
  448. place = EMSG; /* found non-option */
  449. if (flags & FLAG_ALLARGS) {
  450. /*
  451. * GNU extension:
  452. * return non-option as argument to option 1
  453. */
  454. optarg = nargv[optind++];
  455. return (INORDER);
  456. }
  457. if (!(flags & FLAG_PERMUTE)) {
  458. /*
  459. * If no permutation wanted, stop parsing
  460. * at first non-option.
  461. */
  462. return (-1);
  463. }
  464. /* do permutation */
  465. if (nonopt_start == -1)
  466. nonopt_start = optind;
  467. else if (nonopt_end != -1) {
  468. permute_args(nonopt_start, nonopt_end,
  469. optind, nargv);
  470. nonopt_start = optind -
  471. (nonopt_end - nonopt_start);
  472. nonopt_end = -1;
  473. }
  474. optind++;
  475. /* process next argument */
  476. goto start;
  477. }
  478. if (nonopt_start != -1 && nonopt_end == -1)
  479. nonopt_end = optind;
  480. /*
  481. * If we have "-" do nothing, if "--" we are done.
  482. */
  483. if (place[1] != '\0' && *++place == '-' && place[1] == '\0') {
  484. optind++;
  485. place = EMSG;
  486. /*
  487. * We found an option (--), so if we skipped
  488. * non-options, we have to permute.
  489. */
  490. if (nonopt_end != -1) {
  491. permute_args(nonopt_start, nonopt_end,
  492. optind, nargv);
  493. optind -= nonopt_end - nonopt_start;
  494. }
  495. nonopt_start = nonopt_end = -1;
  496. return (-1);
  497. }
  498. }
  499. /*
  500. * Check long options if:
  501. * 1) we were passed some
  502. * 2) the arg is not just "-"
  503. * 3) either the arg starts with -- we are getopt_long_only()
  504. */
  505. if (long_options != NULL && place != nargv[optind] &&
  506. (*place == '-' || (flags & FLAG_LONGONLY))) {
  507. short_too = 0;
  508. if (*place == '-')
  509. place++; /* --foo long option */
  510. else if (*place != ':' && strchr(options, *place) != NULL)
  511. short_too = 1; /* could be short option too */
  512. optchar = parse_long_options(nargv, options, long_options,
  513. idx, short_too);
  514. if (optchar != -1) {
  515. place = EMSG;
  516. return (optchar);
  517. }
  518. }
  519. if ((optchar = (int)*place++) == (int)':' ||
  520. (optchar == (int)'-' && *place != '\0') ||
  521. (oli = (char*)strchr(options, optchar)) == NULL) {
  522. /*
  523. * If the user specified "-" and '-' isn't listed in
  524. * options, return -1 (non-option) as per POSIX.
  525. * Otherwise, it is an unknown option character (or ':').
  526. */
  527. if (optchar == (int)'-' && *place == '\0')
  528. return (-1);
  529. if (!*place)
  530. ++optind;
  531. if (PRINT_ERROR)
  532. warnx(illoptchar, optchar);
  533. optopt = optchar;
  534. return (BADCH);
  535. }
  536. if (long_options != NULL && optchar == 'W' && oli[1] == ';') {
  537. /* -W long-option */
  538. if (*place) /* no space */
  539. /* NOTHING */;
  540. else if (++optind >= nargc) { /* no arg */
  541. place = EMSG;
  542. if (PRINT_ERROR)
  543. warnx(recargchar, optchar);
  544. optopt = optchar;
  545. return (BADARG);
  546. } else /* white space */
  547. place = nargv[optind];
  548. optchar = parse_long_options(nargv, options, long_options,
  549. idx, 0);
  550. place = EMSG;
  551. return (optchar);
  552. }
  553. if (*++oli != ':') { /* doesn't take argument */
  554. if (!*place)
  555. ++optind;
  556. } else { /* takes (optional) argument */
  557. optarg = NULL;
  558. if (*place) /* no white space */
  559. optarg = place;
  560. else if (oli[1] != ':') { /* arg not optional */
  561. if (++optind >= nargc) { /* no arg */
  562. place = EMSG;
  563. if (PRINT_ERROR)
  564. warnx(recargchar, optchar);
  565. optopt = optchar;
  566. return (BADARG);
  567. } else
  568. optarg = nargv[optind];
  569. }
  570. place = EMSG;
  571. ++optind;
  572. }
  573. /* dump back option letter */
  574. return (optchar);
  575. }
  576. /*
  577. * getopt_long --
  578. * Parse argc/argv argument vector.
  579. */
  580. int
  581. getopt_long(int nargc, char * const *nargv, const char *options,
  582. const struct option *long_options, int *idx)
  583. {
  584. return (getopt_internal(nargc, nargv, options, long_options, idx,
  585. FLAG_PERMUTE));
  586. }
  587. /*
  588. * getopt_long_only --
  589. * Parse argc/argv argument vector.
  590. */
  591. int
  592. getopt_long_only(int nargc, char * const *nargv, const char *options,
  593. const struct option *long_options, int *idx)
  594. {
  595. return (getopt_internal(nargc, nargv, options, long_options, idx,
  596. FLAG_PERMUTE|FLAG_LONGONLY));
  597. }
  598. //extern int getopt_long(int nargc, char * const *nargv, const char *options,
  599. // const struct option *long_options, int *idx);
  600. //extern int getopt_long_only(int nargc, char * const *nargv, const char *options,
  601. // const struct option *long_options, int *idx);
  602. /*
  603. * Previous MinGW implementation had...
  604. */
  605. #ifndef HAVE_DECL_GETOPT
  606. /*
  607. * ...for the long form API only; keep this for compatibility.
  608. */
  609. # define HAVE_DECL_GETOPT 1
  610. #endif
  611. #ifdef __cplusplus
  612. }
  613. #endif
  614. #endif /* !defined(__UNISTD_H_SOURCED__) && !defined(__GETOPT_LONG_H__) */