(argc, argv, optstring, longopts, longind, long_only)
| 298 | long-named options. */ |
| 299 | |
| 300 | int |
| 301 | _getopt_internal(argc, argv, optstring, longopts, longind, long_only) |
| 302 | int argc; |
| 303 | char *const *argv; |
| 304 | const char *optstring; |
| 305 | const struct option *longopts; |
| 306 | int *longind; |
| 307 | int 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; |
no test coverage detected