332{
333 int option_index;
334
336
337
338
339
340
341
343 {
345
347
348
349
350 if (optstring[0] == '-')
351 {
353 ++optstring;
354 }
355 else if (optstring[0] == '+')
356 {
358 ++optstring;
359 }
362 else
364 }
365
367 {
369 {
370
371
372
377
378
379
380
383#ifdef GETOPT_COMPAT
386#endif
387 )
390 }
391
392
393
394
395
396
398 {
400
406
408 }
409
410
411
412
414 {
415
416
419 return EOF;
420 }
421
422
423
424
426#ifdef GETOPT_COMPAT
429#endif
430 )
431 {
433 return EOF;
435 return 1;
436 }
437
438
439
440
443 }
444
447 && (argv[
fe_optind][1] ==
'-' || long_only))
448#ifdef GETOPT_COMPAT
450#endif
451 ))
452 {
455 int exact = 0;
456 int ambig = 0;
458 int indfound = 0;
459
460 while (*
s && *
s !=
'=')
462
463
464 for (
p = longopts, option_index = 0;
p->name;
467 {
469 {
470
472 indfound = option_index;
473 exact = 1;
474 break;
475 }
476 else if (pfound ==
NULL)
477 {
478
480 indfound = option_index;
481 }
482 else
483
484 ambig = 1;
485 }
486
487 if (ambig && !exact)
488 {
490 fprintf (stderr, "%s: option `%s' is ambiguous\n",
495 }
496
498 {
499 option_index = indfound;
502 {
503
504
507 else
508 {
510 {
512
513 fprintf (stderr,
514 "%s: option `--%s' doesn't allow an argument\n",
515 argv[0], pfound->
name);
516 else
517
518 fprintf (stderr,
519 "%s: option `%c%s' doesn't allow an argument\n",
521 }
524 }
525 }
527 {
530 else
531 {
533 fprintf (stderr, "%s: option `%s' requires an argument\n",
536 return optstring[0] ==
':' ?
':' :
BAD_OPTION;
537 }
538 }
541 *longind = option_index;
543 }
544
545
546
547
548 if (!long_only || argv[
fe_optind][1] ==
'-'
549#ifdef GETOPT_COMPAT
551#endif
553 {
555 {
557
558 fprintf (stderr, "%s: unrecognized option `--%s'\n",
560 else
561
562 fprintf (stderr, "%s: unrecognized option `%c%s'\n",
564 }
568 }
569 }
570
571
572
573 {
575 const char *temp =
my_index (optstring, c);
576
577
580
581 if (temp ==
NULL || c ==
':')
582 {
584 {
585#if 0
586 if (c < 040 || c >= 0177)
587 fprintf (stderr, "%s: unrecognized option, character code 0%o\n",
588 argv[0], c);
589 else
590 fprintf (stderr, "%s: unrecognized option `-%c'\n", argv[0], c);
591#else
592
593 fprintf (stderr, "%s: illegal option -- %c\n", argv[0], c);
594#endif
595 }
598 }
599 if (temp[1] == ':')
600 {
601 if (temp[2] == ':')
602 {
603
605 {
608 }
609 else
612 }
613 else
614 {
615
617 {
619
620
622 }
624 {
626 {
627#if 0
628 fprintf (stderr, "%s: option `-%c' requires an argument\n",
629 argv[0], c);
630#else
631
632 fprintf (stderr, "%s: option requires an argument -- %c\n",
633 argv[0], c);
634#endif
635 }
637 if (optstring[0] == ':')
638 c = ':';
639 else
641 }
642 else
643
644
647 }
648 }
649 return c;
650 }
651}
const CanonicalForm int s
static void exchange(char **argv)
static size_t my_strlen(const char *str)
static const char * my_index(const char *str, int chr)