ReactOS 0.4.15-dev-7842-g558ab78
getopt_int.h File Reference
#include "getopt.h"
Include dependency graph for getopt_int.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  _getopt_data
 

Macros

#define _GETOPT_DATA_INITIALIZER   { 1, 1 }
 

Enumerations

enum  __ord { REQUIRE_ORDER , PERMUTE , RETURN_IN_ORDER }
 

Functions

int _getopt_internal (int ___argc, char **___argv, const char *__shortopts, const struct option *__longopts, int *__longind, int __long_only, int __posixly_correct)
 
int _getopt_internal_r (int ___argc, char **___argv, const char *__shortopts, const struct option *__longopts, int *__longind, int __long_only, struct _getopt_data *__data, int __posixly_correct)
 
int _getopt_long_r (int ___argc, char **___argv, const char *__shortopts, const struct option *__longopts, int *__longind, struct _getopt_data *__data)
 
int _getopt_long_only_r (int ___argc, char **___argv, const char *__shortopts, const struct option *__longopts, int *__longind, struct _getopt_data *__data)
 

Macro Definition Documentation

◆ _GETOPT_DATA_INITIALIZER

#define _GETOPT_DATA_INITIALIZER   { 1, 1 }

Definition at line 99 of file getopt_int.h.

Enumeration Type Documentation

◆ __ord

Enumerator
REQUIRE_ORDER 
PERMUTE 
RETURN_IN_ORDER 

Definition at line 55 of file getopt_int.h.

56 {
58 };
@ REQUIRE_ORDER
Definition: getopt_int.h:57
@ RETURN_IN_ORDER
Definition: getopt_int.h:57
@ PERMUTE
Definition: getopt_int.h:57

Function Documentation

◆ _getopt_internal()

int _getopt_internal ( int  ___argc,
char **  ___argv,
const char __shortopts,
const struct option __longopts,
int __longind,
int  __long_only,
int  __posixly_correct 
)

Definition at line 700 of file getopt.c.

703{
704 int result;
705
706 getopt_data.optind = optind;
707 getopt_data.opterr = opterr;
708
709 result = _getopt_internal_r (argc, argv, optstring, longopts,
710 longind, long_only, &getopt_data,
711 posixly_correct);
712
713 optind = getopt_data.optind;
714 optarg = getopt_data.optarg;
715 optopt = getopt_data.optopt;
716
717 return result;
718}
static int argc
Definition: ServiceArgs.c:12
int optopt
Definition: getopt.c:48
const char * optarg
Definition: getopt.c:49
int optind
Definition: getopt.c:47
int opterr
Definition: getopt.c:46
GLuint64EXT * result
Definition: glext.h:11304
#define argv
Definition: mplay32.c:18
static struct _getopt_data getopt_data
Definition: getopt.c:116
int _getopt_internal_r(int argc, char **argv, const char *optstring, const struct option *longopts, int *longind, int long_only, struct _getopt_data *d, int posixly_correct)
Definition: getopt.c:468

◆ _getopt_internal_r()

int _getopt_internal_r ( int  ___argc,
char **  ___argv,
const char __shortopts,
const struct option __longopts,
int __longind,
int  __long_only,
struct _getopt_data __data,
int  __posixly_correct 
)

Definition at line 468 of file getopt.c.

471{
472 int print_errors = d->opterr;
473
474 if (argc < 1)
475 return -1;
476
477 d->optarg = NULL;
478
479 if (d->optind == 0 || !d->__initialized)
480 optstring = _getopt_initialize (argc, argv, optstring, d, posixly_correct);
481 else if (optstring[0] == '-' || optstring[0] == '+')
482 optstring++;
483
484 if (optstring[0] == ':')
485 print_errors = 0;
486
487 /* Test whether ARGV[optind] points to a non-option argument. */
488#define NONOPTION_P (argv[d->optind][0] != '-' || argv[d->optind][1] == '\0')
489
490 if (d->__nextchar == NULL || *d->__nextchar == '\0')
491 {
492 /* Advance to the next ARGV-element. */
493
494 /* Give FIRST_NONOPT & LAST_NONOPT rational values if OPTIND has been
495 moved back by the user (who may also have changed the arguments). */
496 if (d->__last_nonopt > d->optind)
497 d->__last_nonopt = d->optind;
498 if (d->__first_nonopt > d->optind)
499 d->__first_nonopt = d->optind;
500
501 if (d->__ordering == PERMUTE)
502 {
503 /* If we have just processed some options following some non-options,
504 exchange them so that the options come first. */
505
506 if (d->__first_nonopt != d->__last_nonopt
507 && d->__last_nonopt != d->optind)
508 exchange (argv, d);
509 else if (d->__last_nonopt != d->optind)
510 d->__first_nonopt = d->optind;
511
512 /* Skip any additional non-options
513 and extend the range of non-options previously skipped. */
514
515 while (d->optind < argc && NONOPTION_P)
516 d->optind++;
517 d->__last_nonopt = d->optind;
518 }
519
520 /* The special ARGV-element '--' means premature end of options.
521 Skip it like a null option,
522 then exchange with previous non-options as if it were an option,
523 then skip everything else like a non-option. */
524
525 if (d->optind != argc && !strcmp (argv[d->optind], "--"))
526 {
527 d->optind++;
528
529 if (d->__first_nonopt != d->__last_nonopt
530 && d->__last_nonopt != d->optind)
531 exchange (argv, d);
532 else if (d->__first_nonopt == d->__last_nonopt)
533 d->__first_nonopt = d->optind;
534 d->__last_nonopt = argc;
535
536 d->optind = argc;
537 }
538
539 /* If we have done all the ARGV-elements, stop the scan
540 and back over any non-options that we skipped and permuted. */
541
542 if (d->optind == argc)
543 {
544 /* Set the next-arg-index to point at the non-options
545 that we previously skipped, so the caller will digest them. */
546 if (d->__first_nonopt != d->__last_nonopt)
547 d->optind = d->__first_nonopt;
548 return -1;
549 }
550
551 /* If we have come to a non-option and did not permute it,
552 either stop the scan or describe it to the caller and pass it by. */
553
554 if (NONOPTION_P)
555 {
556 if (d->__ordering == REQUIRE_ORDER)
557 return -1;
558 d->optarg = argv[d->optind++];
559 return 1;
560 }
561
562 /* We have found another option-ARGV-element.
563 Check whether it might be a long option. */
564 if (longopts)
565 {
566 if (argv[d->optind][1] == '-')
567 {
568 /* "--foo" is always a long option. The special option
569 "--" was handled above. */
570 d->__nextchar = argv[d->optind] + 2;
571 return process_long_option (argc, argv, optstring, longopts,
572 longind, long_only, d,
573 print_errors, "--");
574 }
575
576 /* If long_only and the ARGV-element has the form "-f",
577 where f is a valid short option, don't consider it an
578 abbreviated form of a long option that starts with f.
579 Otherwise there would be no way to give the -f short
580 option.
581
582 On the other hand, if there's a long option "fubar" and
583 the ARGV-element is "-fu", do consider that an
584 abbreviation of the long option, just like "--fu", and
585 not "-f" with arg "u".
586
587 This distinction seems to be the most useful approach. */
588 if (long_only && (argv[d->optind][2]
589 || !strchr (optstring, argv[d->optind][1])))
590 {
591 int code;
592 d->__nextchar = argv[d->optind] + 1;
593 code = process_long_option (argc, argv, optstring, longopts,
594 longind, long_only, d,
595 print_errors, "-");
596 if (code != -1)
597 return code;
598 }
599 }
600
601 /* It is not a long option. Skip the initial punctuation. */
602 d->__nextchar = argv[d->optind] + 1;
603 }
604
605 /* Look at and handle the next short option-character. */
606
607 {
608 char c = *d->__nextchar++;
609 const char *temp = strchr (optstring, c);
610
611 /* Increment 'optind' when we start to process its last character. */
612 if (*d->__nextchar == '\0')
613 ++d->optind;
614
615 if (temp == NULL || c == ':' || c == ';')
616 {
617 if (print_errors)
618 fprintf (stderr, _("%s: invalid option -- '%c'\n"), argv[0], c);
619 d->optopt = c;
620 return '?';
621 }
622
623 /* Convenience. Treat POSIX -W foo same as long option --foo */
624 if (temp[0] == 'W' && temp[1] == ';' && longopts != NULL)
625 {
626 /* This is an option that requires an argument. */
627 if (*d->__nextchar != '\0')
628 d->optarg = d->__nextchar;
629 else if (d->optind == argc)
630 {
631 if (print_errors)
633 _("%s: option requires an argument -- '%c'\n"),
634 argv[0], c);
635
636 d->optopt = c;
637 if (optstring[0] == ':')
638 c = ':';
639 else
640 c = '?';
641 return c;
642 }
643 else
644 d->optarg = argv[d->optind];
645
646 d->__nextchar = d->optarg;
647 d->optarg = NULL;
648 return process_long_option (argc, argv, optstring, longopts, longind,
649 0 /* long_only */, d, print_errors, "-W ");
650 }
651 if (temp[1] == ':')
652 {
653 if (temp[2] == ':')
654 {
655 /* This is an option that accepts an argument optionally. */
656 if (*d->__nextchar != '\0')
657 {
658 d->optarg = d->__nextchar;
659 d->optind++;
660 }
661 else
662 d->optarg = NULL;
663 d->__nextchar = NULL;
664 }
665 else
666 {
667 /* This is an option that requires an argument. */
668 if (*d->__nextchar != '\0')
669 {
670 d->optarg = d->__nextchar;
671 /* If we end this ARGV-element by taking the rest as an arg,
672 we must advance to the next element now. */
673 d->optind++;
674 }
675 else if (d->optind == argc)
676 {
677 if (print_errors)
679 _("%s: option requires an argument -- '%c'\n"),
680 argv[0], c);
681
682 d->optopt = c;
683 if (optstring[0] == ':')
684 c = ':';
685 else
686 c = '?';
687 }
688 else
689 /* We already incremented 'optind' once;
690 increment it again when taking next ARGV-elt as argument. */
691 d->optarg = argv[d->optind++];
692 d->__nextchar = NULL;
693 }
694 }
695 return c;
696 }
697}
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
char * strchr(const char *String, int ch)
Definition: utclib.c:501
#define NULL
Definition: types.h:112
@ REQUIRE_ORDER
Definition: getopt.cpp:45
const GLubyte * c
Definition: glext.h:8905
#define stderr
Definition: stdio.h:100
_Check_return_opt_ _CRTIMP int __cdecl fprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const char *_Format,...)
#define d
Definition: ke_i.h:81
#define c
Definition: ke_i.h:80
static calc_node_t temp
Definition: rpn_ieee.c:38
#define PERMUTE
Definition: getopt.c:41
#define NONOPTION_P
static int process_long_option(int argc, char **argv, const char *optstring, const struct option *longopts, int *longind, int long_only, struct _getopt_data *d, int print_errors, const char *prefix)
Definition: getopt.c:191
#define _(msgid)
Definition: getopt.c:43
static const char * _getopt_initialize(int argc, char **argv, const char *optstring, struct _getopt_data *d, int posixly_correct)
Definition: getopt.c:378
static void exchange(char **argv, struct _getopt_data *d)
Definition: getopt.c:128
Definition: inflate.c:139

Referenced by _getopt_internal(), _getopt_long_only_r(), and _getopt_long_r().

◆ _getopt_long_only_r()

int _getopt_long_only_r ( int  ___argc,
char **  ___argv,
const char __shortopts,
const struct option __longopts,
int __longind,
struct _getopt_data __data 
)

Definition at line 55 of file getopt1.c.

58{
59 return _getopt_internal_r (argc, argv, options, long_options, opt_index,
60 1, d, 0);
61}
static const struct option long_options[]
Definition: widl.c:185

◆ _getopt_long_r()

int _getopt_long_r ( int  ___argc,
char **  ___argv,
const char __shortopts,
const struct option __longopts,
int __longind,
struct _getopt_data __data 
)

Definition at line 32 of file getopt1.c.

35{
36 return _getopt_internal_r (argc, argv, options, long_options, opt_index,
37 0, d, 0);
38}