334{
335 int option_index;
336
338
339
340
341
342
343
345 {
347
349
350
351
352 if (optstring[0] == '-')
353 {
355 ++optstring;
356 }
357 else if (optstring[0] == '+')
358 {
360 ++optstring;
361 }
364 else
366 }
367
369 {
371 {
372
373
374
379
380
381
382
385#ifdef GETOPT_COMPAT
388#endif
389 )
392 }
393
394
395
396
397
398
400 {
402
408
410 }
411
412
413
414
416 {
417
418
421 return EOF;
422 }
423
424
425
426
428#ifdef GETOPT_COMPAT
431#endif
432 )
433 {
435 return EOF;
437 return 1;
438 }
439
440
441
442
445 }
446
449 && (argv[
fe_optind][1] ==
'-' || long_only))
450#ifdef GETOPT_COMPAT
452#endif
453 ))
454 {
457 int exact = 0;
458 int ambig = 0;
460 int indfound = 0;
461
462 while (*
s && *
s !=
'=')
464
465
466 for (
p = longopts, option_index = 0;
p->name;
469 {
471 {
472
474 indfound = option_index;
475 exact = 1;
476 break;
477 }
478 else if (pfound ==
NULL)
479 {
480
482 indfound = option_index;
483 }
484 else
485
486 ambig = 1;
487 }
488
489 if (ambig && !exact)
490 {
492 fprintf (stderr, "%s: option `%s' is ambiguous\n",
497 }
498
500 {
501 option_index = indfound;
504 {
505
506
509 else
510 {
512 {
514
515 fprintf (stderr,
516 "%s: option `--%s' doesn't allow an argument\n",
517 argv[0], pfound->
name);
518 else
519
520 fprintf (stderr,
521 "%s: option `%c%s' doesn't allow an argument\n",
523 }
526 }
527 }
529 {
532 else
533 {
535 fprintf (stderr, "%s: option `%s' requires an argument\n",
538 return optstring[0] ==
':' ?
':' :
BAD_OPTION;
539 }
540 }
543 *longind = option_index;
545 }
546
547
548
549
550 if (!long_only || argv[
fe_optind][1] ==
'-'
551#ifdef GETOPT_COMPAT
553#endif
555 {
557 {
559
560 fprintf (stderr, "%s: unrecognized option `--%s'\n",
562 else
563
564 fprintf (stderr, "%s: unrecognized option `%c%s'\n",
566 }
570 }
571 }
572
573
574
575 {
577 const char *temp =
my_index (optstring, c);
578
579
582
583 if (temp ==
NULL || c ==
':')
584 {
586 {
587#if 0
588 if (c < 040 || c >= 0177)
589 fprintf (stderr, "%s: unrecognized option, character code 0%o\n",
590 argv[0], c);
591 else
592 fprintf (stderr, "%s: unrecognized option `-%c'\n", argv[0], c);
593#else
594
595 fprintf (stderr, "%s: illegal option -- %c\n", argv[0], c);
596#endif
597 }
600 }
601 if (temp[1] == ':')
602 {
603 if (temp[2] == ':')
604 {
605
607 {
610 }
611 else
614 }
615 else
616 {
617
619 {
621
622
624 }
626 {
628 {
629#if 0
630 fprintf (stderr, "%s: option `-%c' requires an argument\n",
631 argv[0], c);
632#else
633
634 fprintf (stderr, "%s: option requires an argument -- %c\n",
635 argv[0], c);
636#endif
637 }
639 if (optstring[0] == ':')
640 c = ':';
641 else
643 }
644 else
645
646
649 }
650 }
651 return c;
652 }
653}
const CanonicalForm int s
STATIC_VAR int first_nonopt
static void exchange(char **argv)
static size_t my_strlen(const char *str)
static const char * my_index(const char *str, int chr)
STATIC_VAR char * nextchar
STATIC_VAR int last_nonopt