MCPcopy Create free account
hub / github.com/Hamlib/Hamlib / _getopt_internal

Function _getopt_internal

lib/getopt.c:300–694  ·  view source on GitHub ↗
(argc, argv, optstring, longopts, longind, long_only)

Source from the content-addressed store, hash-verified

298 long-named options. */
299
300int
301_getopt_internal(argc, argv, optstring, longopts, longind, long_only)
302int argc;
303char *const *argv;
304const char *optstring;
305const struct option *longopts;
306int *longind;
307int long_only;
308{
309 optarg = 0;
310
311 /* Initialize the internal data when the first call is made.
312 Start processing options with ARGV-element 1 (since ARGV-element 0
313 is the program name); the sequence of previously skipped
314 non-option ARGV-elements is empty. */
315
316 if (optind == 0)
317 {
318 first_nonopt = last_nonopt = optind = 1;
319
320 nextchar = NULL;
321
322 /* Determine how to handle the ordering of options and nonoptions. */
323
324 if (optstring[0] == '-')
325 {
326 ordering = RETURN_IN_ORDER;
327 ++optstring;
328 }
329 else if (optstring[0] == '+')
330 {
331 ordering = REQUIRE_ORDER;
332 ++optstring;
333 }
334 else if (getenv("POSIXLY_CORRECT") != NULL)
335 {
336 ordering = REQUIRE_ORDER;
337 }
338 else
339 {
340 ordering = PERMUTE;
341 }
342 }
343
344 if (nextchar == NULL || *nextchar == '\0')
345 {
346 if (ordering == PERMUTE)
347 {
348 /* If we have just processed some options following some non-options,
349 exchange them so that the options come first. */
350
351 if (first_nonopt != last_nonopt && last_nonopt != optind)
352 {
353 exchange((char **) argv);
354 }
355 else if (last_nonopt != optind)
356 {
357 first_nonopt = optind;

Callers 3

getopt_longFunction · 0.85
getopt_long_onlyFunction · 0.85
getoptFunction · 0.85

Calls 1

exchangeFunction · 0.85

Tested by

no test coverage detected