1695b41eeSopenharmony_ci/****************************************************************************
2695b41eeSopenharmony_ci
3695b41eeSopenharmony_cigetopt.c - Read command line options
4695b41eeSopenharmony_ci
5695b41eeSopenharmony_ciAUTHOR: Gregory Pietsch
6695b41eeSopenharmony_ciCREATED Fri Jan 10 21:13:05 1997
7695b41eeSopenharmony_ci
8695b41eeSopenharmony_ciDESCRIPTION:
9695b41eeSopenharmony_ci
10695b41eeSopenharmony_ciThe getopt() function parses the command line arguments.  Its arguments argc
11695b41eeSopenharmony_ciand argv are the argument count and array as passed to the main() function
12695b41eeSopenharmony_cion program invocation.  The argument optstring is a list of available option
13695b41eeSopenharmony_cicharacters.  If such a character is followed by a colon (`:'), the option
14695b41eeSopenharmony_citakes an argument, which is placed in optarg.  If such a character is
15695b41eeSopenharmony_cifollowed by two colons, the option takes an optional argument, which is
16695b41eeSopenharmony_ciplaced in optarg.  If the option does not take an argument, optarg is NULL.
17695b41eeSopenharmony_ci
18695b41eeSopenharmony_ciThe external variable optind is the index of the next array element of argv
19695b41eeSopenharmony_cito be processed; it communicates from one call to the next which element to
20695b41eeSopenharmony_ciprocess.
21695b41eeSopenharmony_ci
22695b41eeSopenharmony_ciThe getopt_long() function works like getopt() except that it also accepts
23695b41eeSopenharmony_cilong options started by two dashes `--'.  If these take values, it is either
24695b41eeSopenharmony_ciin the form
25695b41eeSopenharmony_ci
26695b41eeSopenharmony_ci--arg=value
27695b41eeSopenharmony_ci
28695b41eeSopenharmony_ci or
29695b41eeSopenharmony_ci
30695b41eeSopenharmony_ci--arg value
31695b41eeSopenharmony_ci
32695b41eeSopenharmony_ciIt takes the additional arguments longopts which is a pointer to the first
33695b41eeSopenharmony_cielement of an array of type GETOPT_LONG_OPTION_T.  The last element of the
34695b41eeSopenharmony_ciarray has to be filled with NULL for the name field.
35695b41eeSopenharmony_ci
36695b41eeSopenharmony_ciThe longind pointer points to the index of the current long option relative
37695b41eeSopenharmony_cito longopts if it is non-NULL.
38695b41eeSopenharmony_ci
39695b41eeSopenharmony_ciThe getopt() function returns the option character if the option was found
40695b41eeSopenharmony_cisuccessfully, `:' if there was a missing parameter for one of the options,
41695b41eeSopenharmony_ci`?' for an unknown option character, and EOF for the end of the option list.
42695b41eeSopenharmony_ci
43695b41eeSopenharmony_ciThe getopt_long() function's return value is described in the header file.
44695b41eeSopenharmony_ci
45695b41eeSopenharmony_ciThe function getopt_long_only() is identical to getopt_long(), except that a
46695b41eeSopenharmony_ciplus sign `+' can introduce long options as well as `--'.
47695b41eeSopenharmony_ci
48695b41eeSopenharmony_ciThe following describes how to deal with options that follow non-option
49695b41eeSopenharmony_ciargv-elements.
50695b41eeSopenharmony_ci
51695b41eeSopenharmony_ciIf the caller did not specify anything, the default is REQUIRE_ORDER if the
52695b41eeSopenharmony_cienvironment variable POSIXLY_CORRECT is defined, PERMUTE otherwise.
53695b41eeSopenharmony_ci
54695b41eeSopenharmony_ciREQUIRE_ORDER means don't recognize them as options; stop option processing
55695b41eeSopenharmony_ciwhen the first non-option is seen.  This is what Unix does.  This mode of
56695b41eeSopenharmony_cioperation is selected by either setting the environment variable
57695b41eeSopenharmony_ciPOSIXLY_CORRECT, or using `+' as the first character of the optstring
58695b41eeSopenharmony_ciparameter.
59695b41eeSopenharmony_ci
60695b41eeSopenharmony_ciPERMUTE is the default.  We permute the contents of ARGV as we scan, so that
61695b41eeSopenharmony_cieventually all the non-options are at the end.  This allows options to be
62695b41eeSopenharmony_cigiven in any order, even with programs that were not written to expect this.
63695b41eeSopenharmony_ci
64695b41eeSopenharmony_ciRETURN_IN_ORDER is an option available to programs that were written to
65695b41eeSopenharmony_ciexpect options and other argv-elements in any order and that care about the
66695b41eeSopenharmony_ciordering of the two.  We describe each non-option argv-element as if it were
67695b41eeSopenharmony_cithe argument of an option with character code 1.  Using `-' as the first
68695b41eeSopenharmony_cicharacter of the optstring parameter selects this mode of operation.
69695b41eeSopenharmony_ci
70695b41eeSopenharmony_ciThe special argument `--' forces an end of option-scanning regardless of the
71695b41eeSopenharmony_civalue of ordering.  In the case of RETURN_IN_ORDER, only `--' can cause
72695b41eeSopenharmony_cigetopt() and friends to return EOF with optind != argc.
73695b41eeSopenharmony_ci
74695b41eeSopenharmony_ciCOPYRIGHT NOTICE AND DISCLAIMER:
75695b41eeSopenharmony_ci
76695b41eeSopenharmony_ciCopyright (C) 1997 Gregory Pietsch
77695b41eeSopenharmony_ci
78695b41eeSopenharmony_ciThis file and the accompanying getopt.h header file are hereby placed in the
79695b41eeSopenharmony_cipublic domain without restrictions.  Just give the author credit, don't
80695b41eeSopenharmony_ciclaim you wrote it or prevent anyone else from using it.
81695b41eeSopenharmony_ci
82695b41eeSopenharmony_ciGregory Pietsch's current e-mail address:
83695b41eeSopenharmony_cigpietsch@comcast.net
84695b41eeSopenharmony_ci****************************************************************************/
85695b41eeSopenharmony_ci
86695b41eeSopenharmony_ci/* include files */
87695b41eeSopenharmony_ci#include <stdio.h>
88695b41eeSopenharmony_ci#include <stdlib.h>
89695b41eeSopenharmony_ci#include <string.h>
90695b41eeSopenharmony_ci#ifndef GETOPT_H
91695b41eeSopenharmony_ci#include "getopt.h"
92695b41eeSopenharmony_ci#endif
93695b41eeSopenharmony_ci
94695b41eeSopenharmony_ci/* macros */
95695b41eeSopenharmony_ci
96695b41eeSopenharmony_ci/* types */
97695b41eeSopenharmony_citypedef enum GETOPT_ORDERING_T
98695b41eeSopenharmony_ci{
99695b41eeSopenharmony_ci  PERMUTE,
100695b41eeSopenharmony_ci  RETURN_IN_ORDER,
101695b41eeSopenharmony_ci  REQUIRE_ORDER
102695b41eeSopenharmony_ci} GETOPT_ORDERING_T;
103695b41eeSopenharmony_ci
104695b41eeSopenharmony_ci/* globally-defined variables */
105695b41eeSopenharmony_cichar *optarg = NULL;
106695b41eeSopenharmony_ciint optind = 0;
107695b41eeSopenharmony_ciint opterr = 1;
108695b41eeSopenharmony_ciint optopt = '?';
109695b41eeSopenharmony_ci
110695b41eeSopenharmony_ci/* functions */
111695b41eeSopenharmony_ci
112695b41eeSopenharmony_ci/* reverse_argv_elements:  reverses num elements starting at argv */
113695b41eeSopenharmony_cistatic void
114695b41eeSopenharmony_cireverse_argv_elements (char **argv, int num)
115695b41eeSopenharmony_ci{
116695b41eeSopenharmony_ci  int i;
117695b41eeSopenharmony_ci  char *tmp;
118695b41eeSopenharmony_ci
119695b41eeSopenharmony_ci  for (i = 0; i < (num >> 1); i++)
120695b41eeSopenharmony_ci    {
121695b41eeSopenharmony_ci      tmp = argv[i];
122695b41eeSopenharmony_ci      argv[i] = argv[num - i - 1];
123695b41eeSopenharmony_ci      argv[num - i - 1] = tmp;
124695b41eeSopenharmony_ci    }
125695b41eeSopenharmony_ci}
126695b41eeSopenharmony_ci
127695b41eeSopenharmony_ci/* permute: swap two blocks of argv-elements given their lengths */
128695b41eeSopenharmony_cistatic void
129695b41eeSopenharmony_cipermute (char **argv, int len1, int len2)
130695b41eeSopenharmony_ci{
131695b41eeSopenharmony_ci  reverse_argv_elements (argv, len1);
132695b41eeSopenharmony_ci  reverse_argv_elements (argv, len1 + len2);
133695b41eeSopenharmony_ci  reverse_argv_elements (argv, len2);
134695b41eeSopenharmony_ci}
135695b41eeSopenharmony_ci
136695b41eeSopenharmony_ci/* is_option: is this argv-element an option or the end of the option list? */
137695b41eeSopenharmony_cistatic int
138695b41eeSopenharmony_ciis_option (char *argv_element, int only)
139695b41eeSopenharmony_ci{
140695b41eeSopenharmony_ci  return ((argv_element == NULL)
141695b41eeSopenharmony_ci          || (argv_element[0] == '-') || (only && argv_element[0] == '+'));
142695b41eeSopenharmony_ci}
143695b41eeSopenharmony_ci
144695b41eeSopenharmony_ci/* getopt_internal:  the function that does all the dirty work */
145695b41eeSopenharmony_cistatic int
146695b41eeSopenharmony_cigetopt_internal (int argc, char **argv, char *shortopts,
147695b41eeSopenharmony_ci                 GETOPT_LONG_OPTION_T * longopts, int *longind, int only)
148695b41eeSopenharmony_ci{
149695b41eeSopenharmony_ci  GETOPT_ORDERING_T ordering = PERMUTE;
150695b41eeSopenharmony_ci  static size_t optwhere = 0;
151695b41eeSopenharmony_ci  size_t permute_from = 0;
152695b41eeSopenharmony_ci  int num_nonopts = 0;
153695b41eeSopenharmony_ci  int optindex = 0;
154695b41eeSopenharmony_ci  size_t match_chars = 0;
155695b41eeSopenharmony_ci  char *possible_arg = NULL;
156695b41eeSopenharmony_ci  int longopt_match = -1;
157695b41eeSopenharmony_ci  int has_arg = -1;
158695b41eeSopenharmony_ci  char *cp = NULL;
159695b41eeSopenharmony_ci  int arg_next = 0;
160695b41eeSopenharmony_ci
161695b41eeSopenharmony_ci  /* first, deal with silly parameters and easy stuff */
162695b41eeSopenharmony_ci  if (argc == 0 || argv == NULL || (shortopts == NULL && longopts == NULL))
163695b41eeSopenharmony_ci    return (optopt = '?');
164695b41eeSopenharmony_ci  if (optind >= argc || argv[optind] == NULL)
165695b41eeSopenharmony_ci    return EOF;
166695b41eeSopenharmony_ci  if (strcmp (argv[optind], "--") == 0)
167695b41eeSopenharmony_ci    {
168695b41eeSopenharmony_ci      optind++;
169695b41eeSopenharmony_ci      return EOF;
170695b41eeSopenharmony_ci    }
171695b41eeSopenharmony_ci  /* if this is our first time through */
172695b41eeSopenharmony_ci  if (optind == 0)
173695b41eeSopenharmony_ci    optind = optwhere = 1;
174695b41eeSopenharmony_ci
175695b41eeSopenharmony_ci  /* define ordering */
176695b41eeSopenharmony_ci  if (shortopts != NULL && (*shortopts == '-' || *shortopts == '+'))
177695b41eeSopenharmony_ci    {
178695b41eeSopenharmony_ci      ordering = (*shortopts == '-') ? RETURN_IN_ORDER : REQUIRE_ORDER;
179695b41eeSopenharmony_ci      shortopts++;
180695b41eeSopenharmony_ci    }
181695b41eeSopenharmony_ci  else
182695b41eeSopenharmony_ci    ordering = (getenv ("POSIXLY_CORRECT") != NULL) ? REQUIRE_ORDER : PERMUTE;
183695b41eeSopenharmony_ci
184695b41eeSopenharmony_ci  /*
185695b41eeSopenharmony_ci   * based on ordering, find our next option, if we're at the beginning of
186695b41eeSopenharmony_ci   * one
187695b41eeSopenharmony_ci   */
188695b41eeSopenharmony_ci  if (optwhere == 1)
189695b41eeSopenharmony_ci    {
190695b41eeSopenharmony_ci      switch (ordering)
191695b41eeSopenharmony_ci        {
192695b41eeSopenharmony_ci        case PERMUTE:
193695b41eeSopenharmony_ci          permute_from = optind;
194695b41eeSopenharmony_ci          num_nonopts = 0;
195695b41eeSopenharmony_ci          while (!is_option (argv[optind], only))
196695b41eeSopenharmony_ci            {
197695b41eeSopenharmony_ci              optind++;
198695b41eeSopenharmony_ci              num_nonopts++;
199695b41eeSopenharmony_ci            }
200695b41eeSopenharmony_ci          if (argv[optind] == NULL)
201695b41eeSopenharmony_ci            {
202695b41eeSopenharmony_ci              /* no more options */
203695b41eeSopenharmony_ci              optind = permute_from;
204695b41eeSopenharmony_ci              return EOF;
205695b41eeSopenharmony_ci            }
206695b41eeSopenharmony_ci          else if (strcmp (argv[optind], "--") == 0)
207695b41eeSopenharmony_ci            {
208695b41eeSopenharmony_ci              /* no more options, but have to get `--' out of the way */
209695b41eeSopenharmony_ci              permute (argv + permute_from, num_nonopts, 1);
210695b41eeSopenharmony_ci              optind = permute_from + 1;
211695b41eeSopenharmony_ci              return EOF;
212695b41eeSopenharmony_ci            }
213695b41eeSopenharmony_ci          break;
214695b41eeSopenharmony_ci        case RETURN_IN_ORDER:
215695b41eeSopenharmony_ci          if (!is_option (argv[optind], only))
216695b41eeSopenharmony_ci            {
217695b41eeSopenharmony_ci              optarg = argv[optind++];
218695b41eeSopenharmony_ci              return (optopt = 1);
219695b41eeSopenharmony_ci            }
220695b41eeSopenharmony_ci          break;
221695b41eeSopenharmony_ci        case REQUIRE_ORDER:
222695b41eeSopenharmony_ci          if (!is_option (argv[optind], only))
223695b41eeSopenharmony_ci            return EOF;
224695b41eeSopenharmony_ci          break;
225695b41eeSopenharmony_ci        }
226695b41eeSopenharmony_ci    }
227695b41eeSopenharmony_ci  /* we've got an option, so parse it */
228695b41eeSopenharmony_ci
229695b41eeSopenharmony_ci  /* first, is it a long option? */
230695b41eeSopenharmony_ci  if (longopts != NULL
231695b41eeSopenharmony_ci      && (memcmp (argv[optind], "--", 2) == 0
232695b41eeSopenharmony_ci          || (only && argv[optind][0] == '+')) && optwhere == 1)
233695b41eeSopenharmony_ci    {
234695b41eeSopenharmony_ci      /* handle long options */
235695b41eeSopenharmony_ci      if (memcmp (argv[optind], "--", 2) == 0)
236695b41eeSopenharmony_ci        optwhere = 2;
237695b41eeSopenharmony_ci      longopt_match = -1;
238695b41eeSopenharmony_ci      possible_arg = strchr (argv[optind] + optwhere, '=');
239695b41eeSopenharmony_ci      if (possible_arg == NULL)
240695b41eeSopenharmony_ci        {
241695b41eeSopenharmony_ci          /* no =, so next argv might be arg */
242695b41eeSopenharmony_ci          match_chars = strlen (argv[optind]);
243695b41eeSopenharmony_ci          possible_arg = argv[optind] + match_chars;
244695b41eeSopenharmony_ci          match_chars = match_chars - optwhere;
245695b41eeSopenharmony_ci        }
246695b41eeSopenharmony_ci      else
247695b41eeSopenharmony_ci        match_chars = (possible_arg - argv[optind]) - optwhere;
248695b41eeSopenharmony_ci      for (optindex = 0; longopts[optindex].name != NULL; optindex++)
249695b41eeSopenharmony_ci        {
250695b41eeSopenharmony_ci          if (memcmp (argv[optind] + optwhere,
251695b41eeSopenharmony_ci                      longopts[optindex].name, match_chars) == 0)
252695b41eeSopenharmony_ci            {
253695b41eeSopenharmony_ci              /* do we have an exact match? */
254695b41eeSopenharmony_ci              if (match_chars == strlen (longopts[optindex].name))
255695b41eeSopenharmony_ci                {
256695b41eeSopenharmony_ci                  longopt_match = optindex;
257695b41eeSopenharmony_ci                  break;
258695b41eeSopenharmony_ci                }
259695b41eeSopenharmony_ci              /* do any characters match? */
260695b41eeSopenharmony_ci              else
261695b41eeSopenharmony_ci                {
262695b41eeSopenharmony_ci                  if (longopt_match < 0)
263695b41eeSopenharmony_ci                    longopt_match = optindex;
264695b41eeSopenharmony_ci                  else
265695b41eeSopenharmony_ci                    {
266695b41eeSopenharmony_ci                      /* we have ambiguous options */
267695b41eeSopenharmony_ci                      if (opterr)
268695b41eeSopenharmony_ci                        fprintf (stderr, "%s: option `%s' is ambiguous "
269695b41eeSopenharmony_ci                                 "(could be `--%s' or `--%s')\n",
270695b41eeSopenharmony_ci                                 argv[0],
271695b41eeSopenharmony_ci                                 argv[optind],
272695b41eeSopenharmony_ci                                 longopts[longopt_match].name,
273695b41eeSopenharmony_ci                                 longopts[optindex].name);
274695b41eeSopenharmony_ci                      return (optopt = '?');
275695b41eeSopenharmony_ci                    }
276695b41eeSopenharmony_ci                }
277695b41eeSopenharmony_ci            }
278695b41eeSopenharmony_ci        }
279695b41eeSopenharmony_ci      if (longopt_match >= 0)
280695b41eeSopenharmony_ci        has_arg = longopts[longopt_match].has_arg;
281695b41eeSopenharmony_ci    }
282695b41eeSopenharmony_ci  /* if we didn't find a long option, is it a short option? */
283695b41eeSopenharmony_ci  if (longopt_match < 0 && shortopts != NULL)
284695b41eeSopenharmony_ci    {
285695b41eeSopenharmony_ci      cp = strchr (shortopts, argv[optind][optwhere]);
286695b41eeSopenharmony_ci      if (cp == NULL)
287695b41eeSopenharmony_ci        {
288695b41eeSopenharmony_ci          /* couldn't find option in shortopts */
289695b41eeSopenharmony_ci          if (opterr)
290695b41eeSopenharmony_ci            fprintf (stderr,
291695b41eeSopenharmony_ci                     "%s: invalid option -- `-%c'\n",
292695b41eeSopenharmony_ci                     argv[0], argv[optind][optwhere]);
293695b41eeSopenharmony_ci          optwhere++;
294695b41eeSopenharmony_ci          if (argv[optind][optwhere] == '\0')
295695b41eeSopenharmony_ci            {
296695b41eeSopenharmony_ci              optind++;
297695b41eeSopenharmony_ci              optwhere = 1;
298695b41eeSopenharmony_ci            }
299695b41eeSopenharmony_ci          return (optopt = '?');
300695b41eeSopenharmony_ci        }
301695b41eeSopenharmony_ci      has_arg = ((cp[1] == ':')
302695b41eeSopenharmony_ci                 ? ((cp[2] == ':') ? OPTIONAL_ARG : required_argument) : no_argument);
303695b41eeSopenharmony_ci      possible_arg = argv[optind] + optwhere + 1;
304695b41eeSopenharmony_ci      optopt = *cp;
305695b41eeSopenharmony_ci    }
306695b41eeSopenharmony_ci  /* get argument and reset optwhere */
307695b41eeSopenharmony_ci  arg_next = 0;
308695b41eeSopenharmony_ci  switch (has_arg)
309695b41eeSopenharmony_ci    {
310695b41eeSopenharmony_ci    case OPTIONAL_ARG:
311695b41eeSopenharmony_ci      if (*possible_arg == '=')
312695b41eeSopenharmony_ci        possible_arg++;
313695b41eeSopenharmony_ci      if (*possible_arg != '\0')
314695b41eeSopenharmony_ci        {
315695b41eeSopenharmony_ci          optarg = possible_arg;
316695b41eeSopenharmony_ci          optwhere = 1;
317695b41eeSopenharmony_ci        }
318695b41eeSopenharmony_ci      else
319695b41eeSopenharmony_ci        optarg = NULL;
320695b41eeSopenharmony_ci      break;
321695b41eeSopenharmony_ci    case required_argument:
322695b41eeSopenharmony_ci      if (*possible_arg == '=')
323695b41eeSopenharmony_ci        possible_arg++;
324695b41eeSopenharmony_ci      if (*possible_arg != '\0')
325695b41eeSopenharmony_ci        {
326695b41eeSopenharmony_ci          optarg = possible_arg;
327695b41eeSopenharmony_ci          optwhere = 1;
328695b41eeSopenharmony_ci        }
329695b41eeSopenharmony_ci      else if (optind + 1 >= argc)
330695b41eeSopenharmony_ci        {
331695b41eeSopenharmony_ci          if (opterr)
332695b41eeSopenharmony_ci            {
333695b41eeSopenharmony_ci              fprintf (stderr, "%s: argument required for option `", argv[0]);
334695b41eeSopenharmony_ci              if (longopt_match >= 0)
335695b41eeSopenharmony_ci                fprintf (stderr, "--%s'\n", longopts[longopt_match].name);
336695b41eeSopenharmony_ci              else
337695b41eeSopenharmony_ci                fprintf (stderr, "-%c'\n", *cp);
338695b41eeSopenharmony_ci            }
339695b41eeSopenharmony_ci          optind++;
340695b41eeSopenharmony_ci          return (optopt = ':');
341695b41eeSopenharmony_ci        }
342695b41eeSopenharmony_ci      else
343695b41eeSopenharmony_ci        {
344695b41eeSopenharmony_ci          optarg = argv[optind + 1];
345695b41eeSopenharmony_ci          arg_next = 1;
346695b41eeSopenharmony_ci          optwhere = 1;
347695b41eeSopenharmony_ci        }
348695b41eeSopenharmony_ci      break;
349695b41eeSopenharmony_ci    case no_argument:
350695b41eeSopenharmony_ci      if (longopt_match < 0)
351695b41eeSopenharmony_ci        {
352695b41eeSopenharmony_ci          optwhere++;
353695b41eeSopenharmony_ci          if (argv[optind][optwhere] == '\0')
354695b41eeSopenharmony_ci            optwhere = 1;
355695b41eeSopenharmony_ci        }
356695b41eeSopenharmony_ci      else
357695b41eeSopenharmony_ci        optwhere = 1;
358695b41eeSopenharmony_ci      optarg = NULL;
359695b41eeSopenharmony_ci      break;
360695b41eeSopenharmony_ci    }
361695b41eeSopenharmony_ci
362695b41eeSopenharmony_ci  /* do we have to permute or otherwise modify optind? */
363695b41eeSopenharmony_ci  if (ordering == PERMUTE && optwhere == 1 && num_nonopts != 0)
364695b41eeSopenharmony_ci    {
365695b41eeSopenharmony_ci      permute (argv + permute_from, num_nonopts, 1 + arg_next);
366695b41eeSopenharmony_ci      optind = permute_from + 1 + arg_next;
367695b41eeSopenharmony_ci    }
368695b41eeSopenharmony_ci  else if (optwhere == 1)
369695b41eeSopenharmony_ci    optind = optind + 1 + arg_next;
370695b41eeSopenharmony_ci
371695b41eeSopenharmony_ci  /* finally return */
372695b41eeSopenharmony_ci  if (longopt_match >= 0)
373695b41eeSopenharmony_ci    {
374695b41eeSopenharmony_ci      if (longind != NULL)
375695b41eeSopenharmony_ci        *longind = longopt_match;
376695b41eeSopenharmony_ci      if (longopts[longopt_match].flag != NULL)
377695b41eeSopenharmony_ci        {
378695b41eeSopenharmony_ci          *(longopts[longopt_match].flag) = longopts[longopt_match].val;
379695b41eeSopenharmony_ci          return 0;
380695b41eeSopenharmony_ci        }
381695b41eeSopenharmony_ci      else
382695b41eeSopenharmony_ci        return longopts[longopt_match].val;
383695b41eeSopenharmony_ci    }
384695b41eeSopenharmony_ci  else
385695b41eeSopenharmony_ci    return optopt;
386695b41eeSopenharmony_ci}
387695b41eeSopenharmony_ci
388695b41eeSopenharmony_ci#ifndef _AIX
389695b41eeSopenharmony_ciint
390695b41eeSopenharmony_cigetopt (int argc, char **argv, char *optstring)
391695b41eeSopenharmony_ci{
392695b41eeSopenharmony_ci  return getopt_internal (argc, argv, optstring, NULL, NULL, 0);
393695b41eeSopenharmony_ci}
394695b41eeSopenharmony_ci#endif
395695b41eeSopenharmony_ci
396695b41eeSopenharmony_ciint
397695b41eeSopenharmony_cigetopt_long (int argc, char **argv, const char *shortopts,
398695b41eeSopenharmony_ci             const GETOPT_LONG_OPTION_T * longopts, int *longind)
399695b41eeSopenharmony_ci{
400695b41eeSopenharmony_ci  return getopt_internal (argc, argv, (char*)shortopts, (GETOPT_LONG_OPTION_T*)longopts, longind, 0);
401695b41eeSopenharmony_ci}
402695b41eeSopenharmony_ci
403695b41eeSopenharmony_ciint
404695b41eeSopenharmony_cigetopt_long_only (int argc, char **argv, const char *shortopts,
405695b41eeSopenharmony_ci                  const GETOPT_LONG_OPTION_T * longopts, int *longind)
406695b41eeSopenharmony_ci{
407695b41eeSopenharmony_ci  return getopt_internal (argc, argv, (char*)shortopts, (GETOPT_LONG_OPTION_T*)longopts, longind, 1);
408695b41eeSopenharmony_ci}
409695b41eeSopenharmony_ci
410695b41eeSopenharmony_ci/* end of file GETOPT.C */
411