diff options
-rw-r--r-- | getopt/getopt.c | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/getopt/getopt.c b/getopt/getopt.c index ceb9d3ded..b857aac83 100644 --- a/getopt/getopt.c +++ b/getopt/getopt.c @@ -76,7 +76,10 @@ static shell_t shell=BASH; /* The shell we generate output for. */ static int quiet_errors=0; /* 0 is not quiet. */ static int quiet_output=0; /* 0 is not quiet. */ static int quote=1; /* 1 is do quote. */ -static int alternative=0; /* 0 is getopt_long, 1 is getopt_long_only */ + +/* Allow changing which getopt is in use with function pointer */ +int (*getopt_long_fp) (int argc, char *const *argv, const char *optstr, + const struct option * longopts, int *longindex); /* Function prototypes */ static const char *normalize(const char *arg); @@ -172,9 +175,7 @@ static int generate_output(char * argv[],int argc,const char *optstr, opterr=0; optind=0; /* Reset getopt(3) */ - while ((opt = (alternative? - getopt_long_only(argc,argv,optstr,longopts,&longindex): - getopt_long(argc,argv,optstr,longopts,&longindex))) + while ((opt = (getopt_long_fp(argc,argv,optstr,longopts,&longindex))) != EOF) if (opt == '?' || opt == ':' ) exit_code = GETOPT_EXIT_CODE; @@ -352,6 +353,7 @@ int main(int argc, char *argv[]) textdomain(PACKAGE); init_longopt(); + getopt_long_fp = getopt_long; if (getenv("GETOPT_COMPATIBLE")) compatible=1; @@ -379,7 +381,7 @@ int main(int argc, char *argv[]) while ((opt=getopt_long(argc,argv,shortopts,longopts,NULL)) != EOF) switch (opt) { case 'a': - alternative=1; + getopt_long_fp = getopt_long_only; break; case 'h': print_help(); |