getopt: remove dependency on err.h/warnx()

pull/36/head
Fabian Groffen 2012-08-08 10:34:48 -05:00 committed by William Pitcock
parent 953fb66ff3
commit 80ad957788
1 changed files with 41 additions and 18 deletions

View File

@ -62,7 +62,6 @@
#include "stdinc.h" #include "stdinc.h"
#include <err.h>
#include <errno.h> #include <errno.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
@ -259,26 +258,32 @@ parse_long_options(char * const *nargv, const char *options,
} }
if (!exact_match && second_partial_match) { if (!exact_match && second_partial_match) {
/* ambiguous abbreviation */ /* ambiguous abbreviation */
if (PRINT_ERROR) if (PRINT_ERROR) {
warnx(ambig, fprintf(stderr, "pkgconf: ");
fprintf(stderr, ambig,
#ifdef GNU_COMPATIBLE #ifdef GNU_COMPATIBLE
current_dash, current_dash,
#endif #endif
(int)current_argv_len, (int)current_argv_len,
current_argv); current_argv);
fprintf(stderr, "\n");
}
pkg_optopt = 0; pkg_optopt = 0;
return (BADCH); return (BADCH);
} }
if (match != -1) { /* option found */ if (match != -1) { /* option found */
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, fprintf(stderr, "pkgconf: ");
fprintf(stderr, noarg,
#ifdef GNU_COMPATIBLE #ifdef GNU_COMPATIBLE
current_dash, current_dash,
#endif #endif
(int)current_argv_len, (int)current_argv_len,
current_argv); current_argv);
fprintf(stderr, "\n");
}
/* /*
* XXX: GNU sets pkg_optopt to val regardless of flag * XXX: GNU sets pkg_optopt to val regardless of flag
*/ */
@ -310,12 +315,15 @@ parse_long_options(char * const *nargv, const char *options,
* Missing argument; leading ':' indicates no error * Missing argument; leading ':' indicates no error
* should be generated. * should be generated.
*/ */
if (PRINT_ERROR) if (PRINT_ERROR) {
warnx(recargstring, fprintf(stderr, "pkgconf: ");
fprintf(stderr, recargstring,
#ifdef GNU_COMPATIBLE #ifdef GNU_COMPATIBLE
current_dash, current_dash,
#endif #endif
current_argv); current_argv);
fprintf(stderr, "\n");
}
/* /*
* XXX: GNU sets pkg_optopt to val regardless of flag * XXX: GNU sets pkg_optopt to val regardless of flag
*/ */
@ -331,12 +339,15 @@ parse_long_options(char * const *nargv, const char *options,
--pkg_optind; --pkg_optind;
return (-1); return (-1);
} }
if (PRINT_ERROR) if (PRINT_ERROR) {
warnx(illoptstring, fprintf(stderr, "pkgconf: ");
fprintf(stderr, illoptstring,
#ifdef GNU_COMPATIBLE #ifdef GNU_COMPATIBLE
current_dash, current_dash,
#endif #endif
current_argv); current_argv);
fprintf(stderr, "\n");
}
pkg_optopt = 0; pkg_optopt = 0;
return (BADCH); return (BADCH);
} }
@ -517,12 +528,18 @@ start:
if (!*place) if (!*place)
++pkg_optind; ++pkg_optind;
#ifdef GNU_COMPATIBLE #ifdef GNU_COMPATIBLE
if (PRINT_ERROR) if (PRINT_ERROR) {
warnx(posixly_correct ? illoptchar : gnuoptchar, fprintf(stderr, "pkgconf: ");
fprintf(stderr, posixly_correct ? illoptchar : gnuoptchar,
optchar); optchar);
fprintf(stderr, "\n");
}
#else #else
if (PRINT_ERROR) if (PRINT_ERROR) {
warnx(illoptchar, optchar); fprintf(stderr, "pkgconf: ");
fprintf(stderr, illoptchar, optchar);
fprintf(stderr, "\n");
}
#endif #endif
pkg_optopt = optchar; pkg_optopt = optchar;
return (BADCH); return (BADCH);
@ -533,8 +550,11 @@ start:
/* NOTHING */; /* NOTHING */;
else if (++pkg_optind >= nargc) { /* no arg */ else if (++pkg_optind >= nargc) { /* no arg */
place = EMSG; place = EMSG;
if (PRINT_ERROR) if (PRINT_ERROR) {
warnx(recargchar, optchar); fprintf(stderr, "pkgconf: ");
fprintf(stderr, recargchar, optchar);
fprintf(stderr, "\n");
}
pkg_optopt = optchar; pkg_optopt = optchar;
return (BADARG); return (BADARG);
} else /* white space */ } else /* white space */
@ -557,8 +577,11 @@ start:
else if (oli[1] != ':') { /* arg not optional */ else if (oli[1] != ':') { /* arg not optional */
if (++pkg_optind >= nargc) { /* no arg */ if (++pkg_optind >= nargc) { /* no arg */
place = EMSG; place = EMSG;
if (PRINT_ERROR) if (PRINT_ERROR) {
warnx(recargchar, optchar); fprintf(stderr, "pkgconf: ");
fprintf(stderr, recargchar, optchar);
fprintf(stderr, "\n");
}
pkg_optopt = optchar; pkg_optopt = optchar;
return (BADARG); return (BADARG);
} else } else