mirror of
https://code.videolan.org/videolan/dav1d
synced 2026-06-11 04:03:05 +00:00
Replace platform-specific APIs for getting the program name in getopt fallback
This commit is contained in:
committed by
Ronald S. Bultje
co-authored by
Ronald S. Bultje
parent
46e9017355
commit
6d681d5144
@@ -12,11 +12,6 @@
|
|||||||
|
|
||||||
#define __GETOPT_H__
|
#define __GETOPT_H__
|
||||||
|
|
||||||
/* All the headers include this file. */
|
|
||||||
#ifdef _WIN32
|
|
||||||
#include <crtdefs.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
+19
-31
@@ -55,11 +55,6 @@
|
|||||||
#include <getopt.h>
|
#include <getopt.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#ifdef _WIN32
|
|
||||||
#include <windows.h>
|
|
||||||
#else
|
|
||||||
#include <err.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define REPLACE_GETOPT /* use this getopt as the system getopt(3) */
|
#define REPLACE_GETOPT /* use this getopt as the system getopt(3) */
|
||||||
|
|
||||||
@@ -92,7 +87,7 @@ static char EMSG[] = "";
|
|||||||
|
|
||||||
static int getopt_internal(int, char * const *, const char *,
|
static int getopt_internal(int, char * const *, const char *,
|
||||||
const struct option *, int *, int);
|
const struct option *, int *, int);
|
||||||
static int parse_long_options(char * const *, const char *,
|
static int parse_long_options(const char *, char * const *, const char *,
|
||||||
const struct option *, int *, int);
|
const struct option *, int *, int);
|
||||||
static int gcd(int, int);
|
static int gcd(int, int);
|
||||||
static void permute_args(int, int, int, char * const *);
|
static void permute_args(int, int, int, char * const *);
|
||||||
@@ -111,31 +106,23 @@ static const char noarg[] = "option doesn't take an argument -- %.*s";
|
|||||||
static const char illoptchar[] = "unknown option -- %c";
|
static const char illoptchar[] = "unknown option -- %c";
|
||||||
static const char illoptstring[] = "unknown option -- %s";
|
static const char illoptstring[] = "unknown option -- %s";
|
||||||
|
|
||||||
#ifdef _WIN32
|
|
||||||
#ifndef __CYGWIN__
|
|
||||||
#define __progname __argv[0]
|
|
||||||
#else
|
|
||||||
extern char __declspec(dllimport) *__progname;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
_vwarnx(const char *fmt,va_list ap)
|
my_vwarnx(const char *progname,const char *fmt,va_list ap)
|
||||||
{
|
{
|
||||||
(void)fprintf(stderr,"%s: ",__progname);
|
(void)fprintf(stderr,"%s: ",progname);
|
||||||
if (fmt != NULL)
|
if (fmt != NULL)
|
||||||
(void)vfprintf(stderr,fmt,ap);
|
(void)vfprintf(stderr,fmt,ap);
|
||||||
(void)fprintf(stderr,"\n");
|
(void)fprintf(stderr,"\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
warnx(const char *fmt,...)
|
my_warnx(const char *progname,const char *fmt,...)
|
||||||
{
|
{
|
||||||
va_list ap;
|
va_list ap;
|
||||||
va_start(ap,fmt);
|
va_start(ap,fmt);
|
||||||
_vwarnx(fmt,ap);
|
my_vwarnx(progname,fmt,ap);
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Compute the greatest common divisor of a and b.
|
* Compute the greatest common divisor of a and b.
|
||||||
@@ -198,7 +185,7 @@ permute_args(int panonopt_start, int panonopt_end, int opt_end,
|
|||||||
* Returns -1 if short_too is set and the option does not match long_options.
|
* Returns -1 if short_too is set and the option does not match long_options.
|
||||||
*/
|
*/
|
||||||
static int
|
static int
|
||||||
parse_long_options(char * const *nargv, const char *options,
|
parse_long_options(const char *progname, char * const *nargv, const char *options,
|
||||||
const struct option *long_options, int *idx, int short_too)
|
const struct option *long_options, int *idx, int short_too)
|
||||||
{
|
{
|
||||||
char *current_argv, *has_equal;
|
char *current_argv, *has_equal;
|
||||||
@@ -250,8 +237,8 @@ parse_long_options(char * const *nargv, const char *options,
|
|||||||
if (ambiguous) {
|
if (ambiguous) {
|
||||||
/* ambiguous abbreviation */
|
/* ambiguous abbreviation */
|
||||||
if (PRINT_ERROR)
|
if (PRINT_ERROR)
|
||||||
warnx(ambig, (int)current_argv_len,
|
my_warnx(progname, ambig, (int)current_argv_len,
|
||||||
current_argv);
|
current_argv);
|
||||||
optopt = 0;
|
optopt = 0;
|
||||||
return (BADCH);
|
return (BADCH);
|
||||||
}
|
}
|
||||||
@@ -259,8 +246,8 @@ parse_long_options(char * const *nargv, const char *options,
|
|||||||
if (long_options[match].has_arg == no_argument
|
if (long_options[match].has_arg == no_argument
|
||||||
&& has_equal) {
|
&& has_equal) {
|
||||||
if (PRINT_ERROR)
|
if (PRINT_ERROR)
|
||||||
warnx(noarg, (int)current_argv_len,
|
my_warnx(progname, noarg, (int)current_argv_len,
|
||||||
current_argv);
|
current_argv);
|
||||||
/*
|
/*
|
||||||
* XXX: GNU sets optopt to val regardless of flag
|
* XXX: GNU sets optopt to val regardless of flag
|
||||||
*/
|
*/
|
||||||
@@ -289,8 +276,8 @@ parse_long_options(char * const *nargv, const char *options,
|
|||||||
* should be generated.
|
* should be generated.
|
||||||
*/
|
*/
|
||||||
if (PRINT_ERROR)
|
if (PRINT_ERROR)
|
||||||
warnx(recargstring,
|
my_warnx(progname, recargstring,
|
||||||
current_argv);
|
current_argv);
|
||||||
/*
|
/*
|
||||||
* XXX: GNU sets optopt to val regardless of flag
|
* XXX: GNU sets optopt to val regardless of flag
|
||||||
*/
|
*/
|
||||||
@@ -307,7 +294,7 @@ parse_long_options(char * const *nargv, const char *options,
|
|||||||
return (-1);
|
return (-1);
|
||||||
}
|
}
|
||||||
if (PRINT_ERROR)
|
if (PRINT_ERROR)
|
||||||
warnx(illoptstring, current_argv);
|
my_warnx(progname, illoptstring, current_argv);
|
||||||
optopt = 0;
|
optopt = 0;
|
||||||
return (BADCH);
|
return (BADCH);
|
||||||
}
|
}
|
||||||
@@ -329,6 +316,7 @@ static int
|
|||||||
getopt_internal(int nargc, char * const *nargv, const char *options,
|
getopt_internal(int nargc, char * const *nargv, const char *options,
|
||||||
const struct option *long_options, int *idx, int flags)
|
const struct option *long_options, int *idx, int flags)
|
||||||
{
|
{
|
||||||
|
const char *progname = nargv[0];
|
||||||
char *oli; /* option letter list index */
|
char *oli; /* option letter list index */
|
||||||
int optchar, short_too;
|
int optchar, short_too;
|
||||||
static int posixly_correct = -1;
|
static int posixly_correct = -1;
|
||||||
@@ -452,7 +440,7 @@ start:
|
|||||||
else if (*place != ':' && strchr(options, *place) != NULL)
|
else if (*place != ':' && strchr(options, *place) != NULL)
|
||||||
short_too = 1; /* could be short option too */
|
short_too = 1; /* could be short option too */
|
||||||
|
|
||||||
optchar = parse_long_options(nargv, options, long_options,
|
optchar = parse_long_options(progname, nargv, options, long_options,
|
||||||
idx, short_too);
|
idx, short_too);
|
||||||
if (optchar != -1) {
|
if (optchar != -1) {
|
||||||
place = EMSG;
|
place = EMSG;
|
||||||
@@ -473,7 +461,7 @@ start:
|
|||||||
if (!*place)
|
if (!*place)
|
||||||
++optind;
|
++optind;
|
||||||
if (PRINT_ERROR)
|
if (PRINT_ERROR)
|
||||||
warnx(illoptchar, optchar);
|
my_warnx(progname, illoptchar, optchar);
|
||||||
optopt = optchar;
|
optopt = optchar;
|
||||||
return (BADCH);
|
return (BADCH);
|
||||||
}
|
}
|
||||||
@@ -484,12 +472,12 @@ start:
|
|||||||
else if (++optind >= nargc) { /* no arg */
|
else if (++optind >= nargc) { /* no arg */
|
||||||
place = EMSG;
|
place = EMSG;
|
||||||
if (PRINT_ERROR)
|
if (PRINT_ERROR)
|
||||||
warnx(recargchar, optchar);
|
my_warnx(progname, recargchar, optchar);
|
||||||
optopt = optchar;
|
optopt = optchar;
|
||||||
return (BADARG);
|
return (BADARG);
|
||||||
} else /* white space */
|
} else /* white space */
|
||||||
place = nargv[optind];
|
place = nargv[optind];
|
||||||
optchar = parse_long_options(nargv, options, long_options,
|
optchar = parse_long_options(progname, nargv, options, long_options,
|
||||||
idx, 0);
|
idx, 0);
|
||||||
place = EMSG;
|
place = EMSG;
|
||||||
return (optchar);
|
return (optchar);
|
||||||
@@ -505,7 +493,7 @@ start:
|
|||||||
if (++optind >= nargc) { /* no arg */
|
if (++optind >= nargc) { /* no arg */
|
||||||
place = EMSG;
|
place = EMSG;
|
||||||
if (PRINT_ERROR)
|
if (PRINT_ERROR)
|
||||||
warnx(recargchar, optchar);
|
my_warnx(progname, recargchar, optchar);
|
||||||
optopt = optchar;
|
optopt = optchar;
|
||||||
return (BADARG);
|
return (BADARG);
|
||||||
} else
|
} else
|
||||||
|
|||||||
Reference in New Issue
Block a user