ref: 8025dd7861959189fc0abaade8d5be47244034da
parent: 38208dba602264f95f378eafe304a0d6bfd7c640
author: cbagwell <cbagwell>
date: Fri May 22 15:41:17 EDT 2009
Revert back to always compiling internal getopt but now manually rename all referenced symbols instead of using unsafe #defines to do that same job.
--- a/configure.ac
+++ b/configure.ac
@@ -153,14 +153,10 @@
dnl Checks for header files.
AC_HEADER_STDC
-AC_CHECK_HEADERS(fcntl.h unistd.h byteswap.h sys/time.h sys/timeb.h sys/types.h sys/utsname.h termios.h getopt.h)
+AC_CHECK_HEADERS(fcntl.h unistd.h byteswap.h sys/time.h sys/timeb.h sys/types.h sys/utsname.h termios.h)
dnl Checks for library functions.
AC_CHECK_FUNCS(strcasecmp strdup popen vsnprintf gettimeofday glob mkstemp)
-
-if test "x$ac_cv_header_getopt_h" = "xyes"; then
- AC_CHECK_FUNCS(getopt_long)
-fi
dnl Check if math library is needed.
AC_CHECK_FUNC(pow)
--- a/src/bend.c
+++ b/src/bend.c
@@ -101,12 +101,12 @@
p->frame_rate = 25;
p->ovsamp = 16;
- while ((c = getopt(argc, argv, opts)) != -1) switch (c) {
+ while ((c = lsx_getopt(argc, argv, opts)) != -1) switch (c) {
GETOPT_NUMERIC('f', frame_rate, 10 , 80)
GETOPT_NUMERIC('o', ovsamp, 4 , 32)
default: lsx_fail("unknown option `-%c'", optopt); return lsx_usage(effp);
}
- argc -= optind, argv += optind;
+ argc -= lsx_optind, argv += lsx_optind;
p->bends = lsx_calloc(p->nbends = argc, sizeof(*p->bends));
return parse(effp, argv, 0.); /* No rate yet; parse with dummy */
--- a/src/dither.c
+++ b/src/dither.c
@@ -210,7 +210,7 @@
priv_t * p = (priv_t *)effp->priv;
int c;
- while ((c = getopt(argc, argv, "+aSsf:""rt")) != -1) switch (c) {
+ while ((c = lsx_getopt(argc, argv, "+aSsf:""rt")) != -1) switch (c) {
case 'a': p->auto_detect = sox_true; break;
case 'S': p->alt_tpdf = sox_true; break;
case 'r': case 't': break; /* No longer in use */
@@ -222,7 +222,7 @@
break;
default: lsx_fail("invalid option `-%c'", optopt); return lsx_usage(effp);
}
- argc -= optind, argv += optind;
+ argc -= lsx_optind, argv += lsx_optind;
do {NUMERIC_PARAMETER(dummy, 0.5, 1)} while (0); /* No longer in use */
return argc? lsx_usage(effp) : SOX_SUCCESS;
}
--- a/src/effects.c
+++ b/src/effects.c
@@ -81,14 +81,14 @@
int sox_effect_options(sox_effect_t *effp, int argc, char * const argv[])
{
- int result, callers_optind = optind, callers_opterr = opterr;
+ int result, callers_optind = lsx_optind, callers_opterr = opterr;
char * * argv2 = lsx_malloc((argc + 1) * sizeof(*argv2));
argv2[0] = (char *)effp->handler.name;
memcpy(argv2 + 1, argv, argc * sizeof(*argv2));
- optind = 1, opterr = 0;
+ lsx_optind = 1, opterr = 0;
result = effp->handler.getopts(effp, argc + 1, argv2);
- optind = callers_optind, opterr = callers_opterr;
+ lsx_optind = callers_optind, opterr = callers_opterr;
free(argv2);
return result;
} /* sox_effect_options */
--- a/src/getopt.c
+++ b/src/getopt.c
@@ -1,5 +1,4 @@
#include "soxconfig.h"
-#if !defined(HAVE_GETOPT_H) || !defined(HAVE_GETOPT_LONG)
/* Getopt for GNU.
NOTE: getopt is now part of the C library, so if you don't know what
"Keep this file name-space clean" means, talk to drepper@gnu.org
@@ -61,6 +60,9 @@
# endif
#endif
+/* Always compile for SoX. */
+#undef ELIDE_CODE
+
#ifndef ELIDE_CODE
@@ -113,11 +115,14 @@
GNU application programs can use a third alternative mode in which
they can distinguish the relative order of options and other arguments. */
+#if 0
#ifdef _LIBC
# include <getopt.h>
#else
# include "getopt.h"
#endif
+#endif
+#include "sgetopt.h"
/* For communication from `getopt' to the caller.
When `getopt' finds an option that takes an argument,
@@ -125,7 +130,7 @@
Also, when `ordering' is RETURN_IN_ORDER,
each non-option ARGV-element is returned here. */
-char *optarg = NULL;
+char *lsx_optarg = NULL;
/* Index in ARGV of the next element to be scanned.
This is used for communication to and from the caller
@@ -140,7 +145,7 @@
how much of ARGV has been scanned so far. */
/* 1003.2 says this must be 1 before any call. */
-int optind = 1;
+int lsx_optind = 1;
/* Formerly, initialization of getopt depended on optind==0, which
causes problems with re-calling getopt as programs generally don't
@@ -314,7 +319,7 @@
{
int bottom = first_nonopt;
int middle = last_nonopt;
- int top = optind;
+ int top = lsx_optind;
char *tem;
/* Exchange the shorter segment with the far end of the longer segment.
@@ -384,8 +389,8 @@
/* Update records for the slots the non-options now occupy. */
- first_nonopt += (optind - last_nonopt);
- last_nonopt = optind;
+ first_nonopt += (lsx_optind - last_nonopt);
+ last_nonopt = lsx_optind;
}
/* Initialize the internal data when the first call is made. */
@@ -403,7 +408,7 @@
is the program name); the sequence of previously skipped
non-option ARGV-elements is empty. */
- first_nonopt = last_nonopt = optind;
+ first_nonopt = last_nonopt = lsx_optind;
nextchar = NULL;
@@ -541,12 +546,12 @@
if (argc < 1)
return -1;
- optarg = NULL;
+ lsx_optarg = NULL;
- if (optind == 0 || !__getopt_initialized)
+ if (lsx_optind == 0 || !__getopt_initialized)
{
- if (optind == 0)
- optind = 1; /* Don't scan ARGV[0], the program name. */
+ if (lsx_optind == 0)
+ lsx_optind = 1; /* Don't scan ARGV[0], the program name. */
optstring = _getopt_initialize (argc, argv, optstring);
__getopt_initialized = 1;
}
@@ -556,11 +561,11 @@
from the shell indicating it is not an option. The later information
is only used when the used in the GNU libc. */
#if defined _LIBC && defined USE_NONOPTION_FLAGS
-# define NONOPTION_P (argv[optind][0] != '-' || argv[optind][1] == '\0' \
- || (optind < nonoption_flags_len \
- && __getopt_nonoption_flags[optind] == '1'))
+# define NONOPTION_P (argv[lsx_optind][0] != '-' || argv[lsx_optind][1] == '\0' \
+ || (lsx_optind < nonoption_flags_len \
+ && __getopt_nonoption_flags[lsx_optind] == '1'))
#else
-# define NONOPTION_P (argv[optind][0] != '-' || argv[optind][1] == '\0')
+# define NONOPTION_P (argv[lsx_optind][0] != '-' || argv[lsx_optind][1] == '\0')
#endif
if (nextchar == NULL || *nextchar == '\0')
@@ -569,10 +574,10 @@
/* Give FIRST_NONOPT & LAST_NONOPT rational values if OPTIND has been
moved back by the user (who may also have changed the arguments). */
- if (last_nonopt > optind)
- last_nonopt = optind;
- if (first_nonopt > optind)
- first_nonopt = optind;
+ if (last_nonopt > lsx_optind)
+ last_nonopt = lsx_optind;
+ if (first_nonopt > lsx_optind)
+ first_nonopt = lsx_optind;
if (ordering == PERMUTE)
{
@@ -579,17 +584,17 @@
/* If we have just processed some options following some non-options,
exchange them so that the options come first. */
- if (first_nonopt != last_nonopt && last_nonopt != optind)
+ if (first_nonopt != last_nonopt && last_nonopt != lsx_optind)
exchange ((char **) argv);
- else if (last_nonopt != optind)
- first_nonopt = optind;
+ else if (last_nonopt != lsx_optind)
+ first_nonopt = lsx_optind;
/* Skip any additional non-options
and extend the range of non-options previously skipped. */
- while (optind < argc && NONOPTION_P)
- optind++;
- last_nonopt = optind;
+ while (lsx_optind < argc && NONOPTION_P)
+ lsx_optind++;
+ last_nonopt = lsx_optind;
}
/* The special ARGV-element `--' means premature end of options.
@@ -597,28 +602,28 @@
then exchange with previous non-options as if it were an option,
then skip everything else like a non-option. */
- if (optind != argc && !strcmp (argv[optind], "--"))
+ if (lsx_optind != argc && !strcmp (argv[lsx_optind], "--"))
{
- optind++;
+ lsx_optind++;
- if (first_nonopt != last_nonopt && last_nonopt != optind)
+ if (first_nonopt != last_nonopt && last_nonopt != lsx_optind)
exchange ((char **) argv);
else if (first_nonopt == last_nonopt)
- first_nonopt = optind;
+ first_nonopt = lsx_optind;
last_nonopt = argc;
- optind = argc;
+ lsx_optind = argc;
}
/* If we have done all the ARGV-elements, stop the scan
and back over any non-options that we skipped and permuted. */
- if (optind == argc)
+ if (lsx_optind == argc)
{
/* Set the next-arg-index to point at the non-options
that we previously skipped, so the caller will digest them. */
if (first_nonopt != last_nonopt)
- optind = first_nonopt;
+ lsx_optind = first_nonopt;
nextchar = NULL; /* SoX */
return -1;
}
@@ -630,7 +635,7 @@
{
if (ordering == REQUIRE_ORDER)
return -1;
- optarg = argv[optind++];
+ lsx_optarg = argv[lsx_optind++];
return 1;
}
@@ -637,8 +642,8 @@
/* We have found another option-ARGV-element.
Skip the initial punctuation. */
- nextchar = (argv[optind] + 1
- + (longopts != NULL && argv[optind][1] == '-'));
+ nextchar = (argv[lsx_optind] + 1
+ + (longopts != NULL && argv[lsx_optind][1] == '-'));
}
/* Decode the current option-ARGV-element. */
@@ -657,8 +662,8 @@
This distinction seems to be the most useful approach. */
if (longopts != NULL
- && (argv[optind][1] == '-'
- || (long_only && (argv[optind][2] || !my_index (optstring, argv[optind][1])))))
+ && (argv[lsx_optind][1] == '-'
+ || (long_only && (argv[lsx_optind][2] || !my_index (optstring, argv[lsx_optind][1])))))
{
char *nameend;
const struct option *p;
@@ -707,7 +712,7 @@
char *buf;
if (__asprintf (&buf, _("%s: option `%s' is ambiguous\n"),
- argv[0], argv[optind]) >= 0)
+ argv[0], argv[lsx_optind]) >= 0)
{
if (_IO_fwide (stderr, 0) > 0)
@@ -719,11 +724,11 @@
}
#else
fprintf (stderr, _("%s: option `%s' is ambiguous\n"),
- argv[0], argv[optind]);
+ argv[0], argv[lsx_optind]);
#endif
}
nextchar += strlen (nextchar);
- optind++;
+ lsx_optind++;
optopt = 0;
return '?';
}
@@ -731,13 +736,13 @@
if (pfound != NULL)
{
option_index = indfound;
- optind++;
+ lsx_optind++;
if (*nameend)
{
/* Don't test has_arg with >, because some C compilers don't
allow it to be used on enums. */
if (pfound->has_arg)
- optarg = nameend + 1;
+ lsx_optarg = nameend + 1;
else
{
if (print_errors)
@@ -747,7 +752,7 @@
int n;
#endif
- if (argv[optind - 1][1] == '-')
+ if (argv[lsx_optind - 1][1] == '-')
{
/* --option */
#if defined _LIBC && defined USE_IN_LIBIO
@@ -766,12 +771,12 @@
#if defined _LIBC && defined USE_IN_LIBIO
n = __asprintf (&buf, _("\
%s: option `%c%s' doesn't allow an argument\n"),
- argv[0], argv[optind - 1][0],
+ argv[0], argv[lsx_optind - 1][0],
pfound->name);
#else
fprintf (stderr, _("\
%s: option `%c%s' doesn't allow an argument\n"),
- argv[0], argv[optind - 1][0], pfound->name);
+ argv[0], argv[lsx_optind - 1][0], pfound->name);
#endif
}
@@ -796,8 +801,8 @@
}
else if (pfound->has_arg == 1)
{
- if (optind < argc)
- optarg = argv[optind++];
+ if (lsx_optind < argc)
+ lsx_optarg = argv[lsx_optind++];
else
{
if (print_errors)
@@ -807,7 +812,7 @@
if (__asprintf (&buf, _("\
%s: option `%s' requires an argument\n"),
- argv[0], argv[optind - 1]) >= 0)
+ argv[0], argv[lsx_optind - 1]) >= 0)
{
if (_IO_fwide (stderr, 0) > 0)
__fwprintf (stderr, L"%s", buf);
@@ -819,7 +824,7 @@
#else
fprintf (stderr,
_("%s: option `%s' requires an argument\n"),
- argv[0], argv[optind - 1]);
+ argv[0], argv[lsx_optind - 1]);
#endif
}
nextchar += strlen (nextchar);
@@ -842,7 +847,7 @@
or the option starts with '--' or is not a valid short
option, then it's an error.
Otherwise interpret it as a short option. */
- if (!long_only || argv[optind][1] == '-'
+ if (!long_only || argv[lsx_optind][1] == '-'
|| my_index (optstring, *nextchar) == NULL)
{
if (print_errors)
@@ -852,7 +857,7 @@
int n;
#endif
- if (argv[optind][1] == '-')
+ if (argv[lsx_optind][1] == '-')
{
/* --option */
#if defined _LIBC && defined USE_IN_LIBIO
@@ -868,10 +873,10 @@
/* +option or -option */
#if defined _LIBC && defined USE_IN_LIBIO
n = __asprintf (&buf, _("%s: unrecognized option `%c%s'\n"),
- argv[0], argv[optind][0], nextchar);
+ argv[0], argv[lsx_optind][0], nextchar);
#else
fprintf (stderr, _("%s: unrecognized option `%c%s'\n"),
- argv[0], argv[optind][0], nextchar);
+ argv[0], argv[lsx_optind][0], nextchar);
#endif
}
@@ -888,7 +893,7 @@
#endif
}
nextchar = (char *) "";
- optind++;
+ lsx_optind++;
optopt = 0;
return '?';
}
@@ -902,7 +907,7 @@
/* Increment `optind' when we start to process its last character. */
if (temp && *nextchar == '\0') /* SoX */
- ++optind;
+ ++lsx_optind;
if (temp == NULL || c == ':')
{
@@ -963,12 +968,12 @@
/* This is an option that requires an argument. */
if (*nextchar != '\0')
{
- optarg = nextchar;
+ lsx_optarg = nextchar;
/* If we end this ARGV-element by taking the rest as an arg,
we must advance to the next element now. */
- optind++;
+ lsx_optind++;
}
- else if (optind == argc)
+ else if (lsx_optind == argc)
{
if (print_errors)
{
@@ -1002,12 +1007,12 @@
else
/* We already incremented `optind' once;
increment it again when taking next ARGV-elt as argument. */
- optarg = argv[optind++];
+ lsx_optarg = argv[lsx_optind++];
/* optarg is now the argument, see if it's in the
table of longopts. */
- for (nextchar = nameend = optarg; *nameend && *nameend != '='; nameend++)
+ for (nextchar = nameend = lsx_optarg; *nameend && *nameend != '='; nameend++)
/* Do nothing. */ ;
/* Test all long options for either exact match
@@ -1041,7 +1046,7 @@
char *buf;
if (__asprintf (&buf, _("%s: option `-W %s' is ambiguous\n"),
- argv[0], argv[optind]) >= 0)
+ argv[0], argv[lsx_optind]) >= 0)
{
if (_IO_fwide (stderr, 0) > 0)
__fwprintf (stderr, L"%s", buf);
@@ -1052,11 +1057,11 @@
}
#else
fprintf (stderr, _("%s: option `-W %s' is ambiguous\n"),
- argv[0], argv[optind]);
+ argv[0], argv[lsx_optind]);
#endif
}
nextchar += strlen (nextchar);
- optind++;
+ lsx_optind++;
return '?';
}
if (pfound != NULL)
@@ -1067,7 +1072,7 @@
/* Don't test has_arg with >, because some C compilers don't
allow it to be used on enums. */
if (pfound->has_arg)
- optarg = nameend + 1;
+ lsx_optarg = nameend + 1;
else
{
if (print_errors)
@@ -1099,8 +1104,8 @@
}
else if (pfound->has_arg == 1)
{
- if (optind < argc)
- optarg = argv[optind++];
+ if (lsx_optind < argc)
+ lsx_optarg = argv[lsx_optind++];
else
{
if (print_errors)
@@ -1110,7 +1115,7 @@
if (__asprintf (&buf, _("\
%s: option `%s' requires an argument\n"),
- argv[0], argv[optind - 1]) >= 0)
+ argv[0], argv[lsx_optind - 1]) >= 0)
{
if (_IO_fwide (stderr, 0) > 0)
__fwprintf (stderr, L"%s", buf);
@@ -1122,7 +1127,7 @@
#else
fprintf (stderr,
_("%s: option `%s' requires an argument\n"),
- argv[0], argv[optind - 1]);
+ argv[0], argv[lsx_optind - 1]);
#endif
}
nextchar += strlen (nextchar);
@@ -1149,11 +1154,11 @@
/* This is an option that accepts an argument optionally. */
if (*nextchar != '\0')
{
- optarg = nextchar;
- optind++;
+ lsx_optarg = nextchar;
+ lsx_optind++;
}
else
- optarg = NULL;
+ lsx_optarg = NULL;
nextchar = NULL;
}
else
@@ -1161,12 +1166,12 @@
/* This is an option that requires an argument. */
if (*nextchar != '\0')
{
- optarg = nextchar;
+ lsx_optarg = nextchar;
/* If we end this ARGV-element by taking the rest as an arg,
we must advance to the next element now. */
- optind++;
+ lsx_optind++;
}
- else if (optind == argc)
+ else if (lsx_optind == argc)
{
if (print_errors)
{
@@ -1200,7 +1205,7 @@
else
/* We already incremented `optind' once;
increment it again when taking next ARGV-elt as argument. */
- optarg = argv[optind++];
+ lsx_optarg = argv[lsx_optind++];
nextchar = NULL;
}
}
@@ -1209,7 +1214,7 @@
}
int
-getopt (int argc, char * const * argv, char const * optstring)
+lsx_getopt (int argc, char * const * argv, char const * optstring)
{
return _getopt_internal (argc, argv, optstring,
(const struct option *) 0,
@@ -1234,7 +1239,7 @@
while (1)
{
- int this_option_optind = optind ? optind : 1;
+ int this_option_optind = lsx_optind ? lsx_optind : 1;
c = getopt (argc, argv, "abc:d:0123456789");
if (c == -1)
@@ -1267,7 +1272,7 @@
break;
case 'c':
- printf ("option c with value `%s'\n", optarg);
+ printf ("option c with value `%s'\n", lsx_optarg);
break;
case '?':
@@ -1278,11 +1283,11 @@
}
}
- if (optind < argc)
+ if (lsx_optind < argc)
{
printf ("non-option ARGV-elements: ");
- while (optind < argc)
- printf ("%s ", argv[optind++]);
+ while (lsx_optind < argc)
+ printf ("%s ", argv[lsx_optind++]);
printf ("\n");
}
@@ -1290,4 +1295,3 @@
}
#endif /* TEST */
-#endif
--- a/src/getopt1.c
+++ b/src/getopt1.c
@@ -1,5 +1,4 @@
#include "soxconfig.h"
-#if !defined(HAVE_GETOPT_H) || !defined(HAVE_GETOPT_LONG)
/* getopt_long and getopt_long_only entry points for GNU getopt.
Copyright (C) 1987,88,89,90,91,92,93,94,96,97,98
Free Software Foundation, Inc.
@@ -26,11 +25,14 @@
#endif
#endif
+#if 0
#ifdef _LIBC
# include <getopt.h>
#else
# include "getopt.h"
#endif
+#endif
+#include "sgetopt.h"
#if !defined __STDC__ || !__STDC__
/* This is a separate conditional since some stdc systems
@@ -58,6 +60,9 @@
#endif
#endif
+/* Always compile for SoX. */
+#undef ELIDE_CODE
+
#ifndef ELIDE_CODE
@@ -73,7 +78,7 @@
int
-getopt_long (
+lsx_getopt_long (
int argc,
char *const *argv,
const char *options,
@@ -80,7 +85,7 @@
const struct option *long_options,
int *opt_index);
int
-getopt_long (
+lsx_getopt_long (
int argc,
char *const *argv,
const char *options,
@@ -114,7 +119,7 @@
}
# ifdef _LIBC
-libc_hidden_def (getopt_long)
+libc_hidden_def (lsx_getopt_long)
libc_hidden_def (getopt_long_only)
# endif
@@ -148,7 +153,7 @@
{0, 0, 0, 0}
};
- c = getopt_long (argc, argv, "abc:d:0123456789",
+ c = lsx_getopt_long (argc, argv, "abc:d:0123456789",
long_options, &option_index);
if (c == -1)
break;
@@ -214,4 +219,3 @@
}
#endif /* TEST */
-#endif
--- a/src/rate.c
+++ b/src/rate.c
@@ -445,7 +445,7 @@
p->phase = 50;
p->shared_ptr = &p->shared;
- while ((c = getopt(argc, argv, opts)) != -1) switch (c) {
+ while ((c = lsx_getopt(argc, argv, opts)) != -1) switch (c) {
GETOPT_NUMERIC('i', coef_interp, 1 , 3)
GETOPT_NUMERIC('p', phase, 0 , 100)
GETOPT_NUMERIC('b', bandwidth, 100 - LSX_MAX_TBW3, 99.7)
@@ -457,7 +457,7 @@
default: if ((found_at = strchr(qopts, c))) p->quality = found_at - qopts;
else {lsx_fail("unknown option `-%c'", optopt); return lsx_usage(effp);}
}
- argc -= optind, argv += optind;
+ argc -= lsx_optind, argv += lsx_optind;
if ((unsigned)p->quality < 2 && (p->bandwidth || p->phase != 50 || p->allow_aliasing)) {
lsx_fail("override options not allowed with this quality level");
--- a/src/sgetopt.h
+++ b/src/sgetopt.h
@@ -17,12 +17,6 @@
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
-#if defined(HAVE_GETOPT_H) && defined(HAVE_GETOPT_LONG)
-
-#include <getopt.h>
-
-#else
-
#ifndef _GETOPT_H
#if defined __GNUC__
#pragma GCC system_header
@@ -57,7 +51,7 @@
Also, when `ordering' is RETURN_IN_ORDER,
each non-option ARGV-element is returned here. */
-extern char *optarg;
+extern char *lsx_optarg;
/* Index in ARGV of the next element to be scanned.
This is used for communication to and from the caller
@@ -71,7 +65,7 @@
Otherwise, `optind' communicates from one call to the next
how much of ARGV has been scanned so far. */
-extern int optind;
+extern int lsx_optind;
/* Callers store zero here to inhibit the error message `getopt' prints
for unrecognized options. */
@@ -155,13 +149,13 @@
/* Many other libraries have conflicting prototypes for getopt, with
differences in the consts, in stdlib.h. To avoid compilation
errors, only prototype getopt for the GNU C library. */
-extern int getopt (int ___argc, char *const *___argv, const char *__shortopts);
+extern int lsx_getopt (int ___argc, char *const *___argv, const char *__shortopts);
# else /* not __GNU_LIBRARY__ */
-extern int getopt ();
+extern int lsx_getopt ();
# endif /* __GNU_LIBRARY__ */
# ifndef __need_getopt
-extern int getopt_long (int ___argc, char *const *___argv,
+extern int lsx_getopt_long (int ___argc, char *const *___argv,
const char *__shortopts,
const struct option *__longopts, int *__longind);
extern int getopt_long_only (int ___argc, char *const *___argv,
@@ -175,9 +169,9 @@
int __long_only);
# endif
#else /* not __STDC__ */
-extern int getopt ();
+extern int lsx_getopt ();
# ifndef __need_getopt
-extern int getopt_long ();
+extern int lsx_getopt_long ();
extern int getopt_long_only ();
extern int _getopt_internal ();
@@ -199,4 +193,3 @@
#pragma warning(pop)
#endif
-#endif
--- a/src/sinc.c
+++ b/src/sinc.c
@@ -39,7 +39,7 @@
p->beta = -1;
while (i < 2) {
int c = 1;
- while (c && (c = getopt(argc, argv, "+ra:b:p:MILt:n:")) != -1) switch (c) {
+ while (c && (c = lsx_getopt(argc, argv, "+ra:b:p:MILt:n:")) != -1) switch (c) {
char * parse_ptr;
case 'r': p->round = sox_true; break;
GETOPT_NUMERIC('a', att, 40 , 180)
@@ -49,7 +49,7 @@
case 'I': p->phase = 25; break;
case 'L': p->phase = 50; break;
GETOPT_NUMERIC('n', num_taps[1], 11, 32767)
- case 't': p->tbw1 = lsx_parse_frequency(optarg, &parse_ptr);
+ case 't': p->tbw1 = lsx_parse_frequency(lsx_optarg, &parse_ptr);
if (p->tbw1 < 1 || *parse_ptr) return lsx_usage(effp);
break;
default: c = 0;
@@ -58,14 +58,14 @@
return lsx_usage(effp);
if (!i || !p->Fc1)
p->tbw0 = p->tbw1, p->num_taps[0] = p->num_taps[1];
- if (!i++ && optind < argc) {
- if (*(parse_ptr = argv[optind++]) != '-')
+ if (!i++ && lsx_optind < argc) {
+ if (*(parse_ptr = argv[lsx_optind++]) != '-')
p->Fc0 = lsx_parse_frequency(parse_ptr, &parse_ptr);
if (*parse_ptr == '-')
p->Fc1 = lsx_parse_frequency(parse_ptr + 1, &parse_ptr);
}
}
- return optind != argc || p->Fc0 < 0 || p->Fc1 < 0 || *parse_ptr ?
+ return lsx_optind != argc || p->Fc0 < 0 || p->Fc1 < 0 || *parse_ptr ?
lsx_usage(effp) : SOX_SUCCESS;
}
--- a/src/sox.c
+++ b/src/sox.c
@@ -736,7 +736,7 @@
static void parse_effects(int argc, char **argv)
{
- while (optind < argc) {
+ while (lsx_optind < argc) {
unsigned eff_offset;
int j;
int newline_mode = 0;
@@ -748,7 +748,7 @@
}
/* psuedo-effect ":" is used to create a new effects chain */
- if (strcmp(argv[optind], ":") == 0)
+ if (strcmp(argv[lsx_optind], ":") == 0)
{
/* Only create a new chain if current one has effects.
* Error checking will be done when loop is restarted.
@@ -758,11 +758,11 @@
eff_chain_count++;
add_eff_chain();
}
- optind++;
+ lsx_optind++;
continue;
}
- if (strcmp(argv[optind], "newfile") == 0)
+ if (strcmp(argv[lsx_optind], "newfile") == 0)
{
/* Start a new effect chain for newfile if user doesn't
* manually do it. Restart loop without advancing
@@ -776,7 +776,7 @@
}
newline_mode = 1;
}
- else if (strcmp(argv[optind], "restart") == 0)
+ else if (strcmp(argv[lsx_optind], "restart") == 0)
{
/* Start a new effect chain for restart if user doesn't
* manually do it. Restart loop without advancing
@@ -792,13 +792,13 @@
}
/* Name should always be correct! */
- user_effargs[eff_chain_count][eff_offset].name = strdup(argv[optind++]);
- for (j = 0; j < argc - optind && !sox_find_effect(argv[optind + j]) &&
- !is_pseudo_effect(argv[optind + j]); ++j)
- user_effargs[eff_chain_count][eff_offset].argv[j] = strdup(argv[optind + j]);
+ user_effargs[eff_chain_count][eff_offset].name = strdup(argv[lsx_optind++]);
+ for (j = 0; j < argc - lsx_optind && !sox_find_effect(argv[lsx_optind + j]) &&
+ !is_pseudo_effect(argv[lsx_optind + j]); ++j)
+ user_effargs[eff_chain_count][eff_offset].argv[j] = strdup(argv[lsx_optind + j]);
user_effargs[eff_chain_count][eff_offset].argc = j;
- optind += j; /* Skip past the effect arguments */
+ lsx_optind += j; /* Skip past the effect arguments */
nuser_effects[eff_chain_count]++;
if (newline_mode)
{
@@ -880,7 +880,7 @@
* Reset opt index so it thinks its back at beginning of
* main()'s argv[].
*/
- optind = 0;
+ lsx_optind = 0;
parse_effects(argc, argv);
/* Advance to next effect but only if current chain has been
@@ -2091,7 +2091,7 @@
static int enum_option(int option_index, lsx_enum_item const * items)
{
- lsx_enum_item const * p = lsx_find_enum_text(optarg, items);
+ lsx_enum_item const * p = lsx_find_enum_text(lsx_optarg, items);
if (p == NULL) {
size_t len = 1;
char * set = lsx_malloc(len);
@@ -2101,7 +2101,7 @@
strcat(set, ", "); strcat(set, p->text);
}
lsx_fail("--%s: `%s' is not one of: %s.",
- long_options[option_index].name, optarg, set + 2);
+ long_options[option_index].name, lsx_optarg, set + 2);
free(set);
exit(1);
}
@@ -2115,7 +2115,7 @@
int i; /* sscanf silently accepts negative numbers for %u :( */
char dummy; /* To check for extraneous chars in optarg. */
- switch (c=getopt_long(argc, argv, getoptstr, long_options, &option_index)) {
+ switch (c=lsx_getopt_long(argc, argv, getoptstr, long_options, &option_index)) {
case -1: /* @ one of: file-name, effect name, end of arg-list. */
return '\0'; /* i.e. not device. */
@@ -2122,14 +2122,14 @@
case 0: /* Long options with no short equivalent. */
switch (option_index) {
case 0:
- if (optarg)
- sox_append_comment(&f->oob.comments, optarg);
+ if (lsx_optarg)
+ sox_append_comment(&f->oob.comments, lsx_optarg);
break;
case 1:
#define SOX_BUFMIN 16
- if (sscanf(optarg, "%i %c", &i, &dummy) != 1 || i <= SOX_BUFMIN) {
- lsx_fail("Buffer size `%s' must be > %d", optarg, SOX_BUFMIN);
+ if (sscanf(lsx_optarg, "%i %c", &i, &dummy) != 1 || i <= SOX_BUFMIN) {
+ lsx_fail("Buffer size `%s' must be > %d", lsx_optarg, SOX_BUFMIN);
exit(1);
}
sox_globals.bufsiz = i;
@@ -2141,13 +2141,13 @@
case 3:
sox_append_comment(&f->oob.comments, "");
- read_comment_file(&f->oob.comments, optarg);
+ read_comment_file(&f->oob.comments, lsx_optarg);
break;
case 4:
sox_append_comment(&f->oob.comments, "");
- if (*optarg)
- sox_append_comment(&f->oob.comments, optarg);
+ if (*lsx_optarg)
+ sox_append_comment(&f->oob.comments, lsx_optarg);
break;
case 5:
@@ -2161,8 +2161,8 @@
break;
case 6:
- if (sscanf(optarg, "%i %c", &i, &dummy) != 1 || i <= SOX_BUFMIN) {
- lsx_fail("Buffer size `%s' must be > %d", optarg, SOX_BUFMIN);
+ if (sscanf(lsx_optarg, "%i %c", &i, &dummy) != 1 || i <= SOX_BUFMIN) {
+ lsx_fail("Buffer size `%s' must be > %d", lsx_optarg, SOX_BUFMIN);
exit(1);
}
sox_globals.input_bufsiz = i;
@@ -2169,8 +2169,8 @@
break;
case 7: no_clobber = sox_true; break;
- case 8: usage_effect(optarg); break;
- case 9: usage_format(optarg); break;
+ case 8: usage_effect(lsx_optarg); break;
+ case 9: usage_format(lsx_optarg); break;
case 10: f->no_glob = sox_true; break;
case 11:
sox_effects_globals.plot = enum_option(option_index, plot_methods);
@@ -2178,8 +2178,8 @@
case 12: replay_gain_mode = enum_option(option_index, rg_modes); break;
case 13: display_SoX_version(stdout); exit(0); break;
case 14: break;
- case 15: effects_filename = strdup(optarg); break;
- case 16: sox_globals.tmp_path = strdup(optarg); break;
+ case 15: effects_filename = strdup(lsx_optarg); break;
+ case 16: sox_globals.tmp_path = strdup(lsx_optarg); break;
case 17: single_threaded = sox_true; break;
case 18: f->signal.length = SOX_IGNORE_LENGTH; break;
case 19: do_guarded_norm = is_guarded = sox_true; break;
@@ -2188,7 +2188,7 @@
#else
case 20: lsx_warn("this build of SoX does not include `magic'"); break;
#endif
- case 21: play_rate_arg = strdup(optarg); break;
+ case 21: play_rate_arg = strdup(lsx_optarg); break;
case 22: no_clobber = sox_false; break;
case 23: no_clobber = sox_true; break;
}
@@ -2216,7 +2216,7 @@
break;
case 't':
- f->filetype = optarg;
+ f->filetype = lsx_optarg;
if (f->filetype[0] == '.')
f->filetype++;
break;
@@ -2223,9 +2223,9 @@
case 'r': {
char k = 0;
- size_t n = sscanf(optarg, "%lf %c %c", &f->signal.rate, &k, &dummy);
+ size_t n = sscanf(lsx_optarg, "%lf %c %c", &f->signal.rate, &k, &dummy);
if (n < 1 || f->signal.rate <= 0 || (n > 1 && k != 'k') || n > 2) {
- lsx_fail("Rate value `%s' is not a positive number", optarg);
+ lsx_fail("Rate value `%s' is not a positive number", lsx_optarg);
exit(1);
}
f->signal.rate *= k == 'k'? 1000. : 1.;
@@ -2233,8 +2233,8 @@
}
case 'v':
- if (sscanf(optarg, "%lf %c", &f->volume, &dummy) != 1) {
- lsx_fail("Volume value `%s' is not a number", optarg);
+ if (sscanf(lsx_optarg, "%lf %c", &f->volume, &dummy) != 1) {
+ lsx_fail("Volume value `%s' is not a number", lsx_optarg);
exit(1);
}
uservolume = sox_true;
@@ -2244,8 +2244,8 @@
break;
case 'c':
- if (sscanf(optarg, "%d %c", &i, &dummy) != 1 || i <= 0) {
- lsx_fail("Channels value `%s' is not a positive integer", optarg);
+ if (sscanf(lsx_optarg, "%d %c", &i, &dummy) != 1 || i <= 0) {
+ lsx_fail("Channels value `%s' is not a positive integer", lsx_optarg);
exit(1);
}
f->signal.channels = i;
@@ -2252,15 +2252,15 @@
break;
case 'C':
- if (sscanf(optarg, "%lf %c", &f->encoding.compression, &dummy) != 1) {
- lsx_fail("Compression value `%s' is not a number", optarg);
+ if (sscanf(lsx_optarg, "%lf %c", &f->encoding.compression, &dummy) != 1) {
+ lsx_fail("Compression value `%s' is not a number", lsx_optarg);
exit(1);
}
break;
case 'b':
- if (sscanf(optarg, "%d %c", &i, &dummy) != 1 || i <= 0) {
- lsx_fail("Bits value `%s' is not a positive integer", optarg);
+ if (sscanf(lsx_optarg, "%d %c", &i, &dummy) != 1 || i <= 0) {
+ lsx_fail("Bits value `%s' is not a positive integer", lsx_optarg);
exit(1);
}
f->encoding.bits_per_sample = i;
@@ -2326,12 +2326,12 @@
case 'D': no_dither = sox_true; break;
case 'V':
- if (optarg == NULL)
+ if (lsx_optarg == NULL)
++sox_globals.verbosity;
else {
- if (sscanf(optarg, "%d %c", &i, &dummy) != 1 || i < 0) {
+ if (sscanf(lsx_optarg, "%d %c", &i, &dummy) != 1 || i < 0) {
sox_globals.verbosity = 2;
- lsx_fail("Verbosity value `%s' is not a non-negative integer", optarg);
+ lsx_fail("Verbosity value `%s' is not a non-negative integer", lsx_optarg);
exit(1);
}
sox_globals.verbosity = (unsigned)i;
@@ -2448,12 +2448,12 @@
lsx_fail("invalid option for "SOX_OPTS);
exit(1);
}
- optind = 1, opterr = 0;
+ lsx_optind = 1, opterr = 0;
free(str);
free(argv2);
}
- for (; optind < argc && !sox_find_effect(argv[optind]); init_file(&opts)) {
+ for (; lsx_optind < argc && !sox_find_effect(argv[lsx_optind]); init_file(&opts)) {
char c = parse_gopts_and_fopts(&opts, argc, argv);
if (c == 'n') { /* is null file? */
if (opts.filetype != NULL && strcmp(opts.filetype, "null") != 0)
@@ -2469,11 +2469,11 @@
opts.filetype = "sox";
add_file(&opts, "-");
}
- else if (optind >= argc || sox_find_effect(argv[optind]))
+ else if (lsx_optind >= argc || sox_find_effect(argv[lsx_optind]))
break;
- else if (!sox_is_playlist(argv[optind]))
- add_glob_file(&opts, argv[optind++]);
- else if (sox_parse_playlist((sox_playlist_callback_t)add_file, &opts, argv[optind++]) != SOX_SUCCESS)
+ else if (!sox_is_playlist(argv[lsx_optind]))
+ add_glob_file(&opts, argv[lsx_optind++]);
+ else if (sox_parse_playlist((sox_playlist_callback_t)add_file, &opts, argv[lsx_optind++]) != SOX_SUCCESS)
exit(1);
}
if (env_opts && *env_opts) {
@@ -2535,16 +2535,16 @@
int opt, num_errors = 0;
sox_bool do_total = sox_false;
- while ((opt = getopt(argc, argv, opts)) > 0) /* act only on last option */
+ while ((opt = lsx_getopt(argc, argv, opts)) > 0) /* act only on last option */
if (opt == 'V') {
int i; /* sscanf silently accepts negative numbers for %u :( */
char dummy; /* To check for extraneous chars in optarg. */
- if (optarg == NULL)
+ if (lsx_optarg == NULL)
++sox_globals.verbosity;
else {
- if (sscanf(optarg, "%d %c", &i, &dummy) != 1 || i < 0) {
+ if (sscanf(lsx_optarg, "%d %c", &i, &dummy) != 1 || i < 0) {
sox_globals.verbosity = 2;
- lsx_fail("Verbosity value `%s' is not a non-negative integer", optarg);
+ lsx_fail("Verbosity value `%s' is not a non-negative integer", lsx_optarg);
exit(1);
}
sox_globals.verbosity = (unsigned)i;
@@ -2563,10 +2563,10 @@
do_total = sox_false;
}
soxi_total = -!do_total;
- for (; optind < argc; ++optind) {
- if (sox_is_playlist(argv[optind]))
- num_errors += (sox_parse_playlist((sox_playlist_callback_t)soxi1, &type, argv[optind]) != SOX_SUCCESS);
- else num_errors += soxi1(&type, argv[optind]);
+ for (; lsx_optind < argc; ++lsx_optind) {
+ if (sox_is_playlist(argv[lsx_optind]))
+ num_errors += (sox_parse_playlist((sox_playlist_callback_t)soxi1, &type, argv[lsx_optind]) != SOX_SUCCESS);
+ else num_errors += soxi1(&type, argv[lsx_optind]);
}
if (type == Full) {
if (soxi_file_count > 1 && soxi_total > 0)
--- a/src/sox_i.h
+++ b/src/sox_i.h
@@ -292,8 +292,8 @@
#define GETOPT_NUMERIC(ch, name, min, max) case ch:{ \
char * end_ptr; \
- double d = strtod(optarg, &end_ptr); \
- if (end_ptr == optarg || d < min || d > max || *end_ptr != '\0') {\
+ double d = strtod(lsx_optarg, &end_ptr); \
+ if (end_ptr == lsx_optarg || d < min || d > max || *end_ptr != '\0') {\
lsx_fail("parameter `%s' must be between %g and %g", #name, (double)min, (double)max); \
return lsx_usage(effp); \
} \
--- a/src/spectrogram.c
+++ b/src/spectrogram.c
@@ -26,15 +26,11 @@
#include "sox_i.h"
#include "fft4g.h"
+#include "sgetopt.h"
#include <assert.h>
#include <math.h>
#include <png.h>
-/* we are playing games with getopt aliases so this needs to be included
- * after system header files to prevent aliasing OS's version of getopt.
- */
-#include "getopt.h"
-
#define malloc lsx_malloc
#define calloc lsx_calloc
#define realloc lsx_realloc
@@ -89,7 +85,7 @@
p->spectrum_points = 249, p->perm = 1, p->max_cols = MAX_COLS;
p->out_name = "spectrogram.png", p->comment = "Created by SoX";
- while ((c = getopt(argc, argv, "+M:x:X:y:z:Z:q:p:w:st:c:amlho:")) != -1) switch (c) {
+ while ((c = lsx_getopt(argc, argv, "+M:x:X:y:z:Z:q:p:w:st:c:amlho:")) != -1) switch (c) {
GETOPT_NUMERIC('M', max_cols , 100, 2000)
GETOPT_NUMERIC('x', pixels_per_sec, 1 , 5000)
GETOPT_NUMERIC('y', y_size , 1 , 1 + MAX_DFT_SIZE_SHIFT)
@@ -100,25 +96,25 @@
case 'w': p->win_type = lsx_enum_option(c, window_options); break;
case 's': p->slack_overlap = sox_true; break;
case 'X':
- next = lsx_parsesamples(1e5, optarg, &duration_1e5, 't');
+ next = lsx_parsesamples(1e5, lsx_optarg, &duration_1e5, 't');
if (next == NULL || *next != '\0' || duration_1e5 > p->max_cols * 1e5
|| duration_1e5 < 1e5 / 5000 * p->max_cols)
return lsx_usage(effp);
p->pixels_per_sec = p->max_cols * 1e5 / duration_1e5;
break;
- case 't': p->title = optarg; break;
- case 'c': p->comment = optarg; break;
+ case 't': p->title = lsx_optarg; break;
+ case 'c': p->comment = lsx_optarg; break;
case 'a': p->no_axes = sox_true; break;
case 'm': p->monochrome = sox_true; break;
case 'l': p->light_background = sox_true; break;
case 'h': p->high_colour = sox_true; break;
- case 'o': p->out_name = optarg; break;
+ case 'o': p->out_name = lsx_optarg; break;
default: lsx_fail("invalid option `-%c'", optopt); return lsx_usage(effp);
}
p->gain = -p->gain;
--p->y_size, --p->perm;
p->spectrum_points += 2;
- return optind !=argc || p->win_type == INT_MAX? lsx_usage(effp) : SOX_SUCCESS;
+ return lsx_optind !=argc || p->win_type == INT_MAX? lsx_usage(effp) : SOX_SUCCESS;
}
static double make_window(priv_t * p, int end)
--- a/src/stats.c
+++ b/src/stats.c
@@ -37,7 +37,7 @@
p->time_constant = .05;
p->scale = 1;
- while ((c = getopt(argc, argv, "+x:b:t:s:")) != -1) switch (c) {
+ while ((c = lsx_getopt(argc, argv, "+x:b:t:s:")) != -1) switch (c) {
GETOPT_NUMERIC('x', hex_bits , 2 , 32)
GETOPT_NUMERIC('b', scale_bits , 2 , 32)
GETOPT_NUMERIC('w', time_constant , .01 , 10)
@@ -46,7 +46,7 @@
}
if (p->hex_bits)
p->scale_bits = p->hex_bits;
- return optind != argc? lsx_usage(effp) : SOX_SUCCESS;
+ return lsx_optind != argc? lsx_usage(effp) : SOX_SUCCESS;
}
static int start(sox_effect_t * effp)
--- a/src/tempo.c
+++ b/src/tempo.c
@@ -218,7 +218,7 @@
int c;
p->segment_ms = p->search_ms = p->overlap_ms = HUGE_VAL;
- while ((c = getopt(argc, argv, "+qmls")) != -1) switch (c) {
+ while ((c = lsx_getopt(argc, argv, "+qmls")) != -1) switch (c) {
case 'q': p->quick_search = sox_true; break;
case 'm': profile = Music; break;
case 's': profile = Speech; break;
@@ -225,7 +225,7 @@
case 'l': profile = Linear; p->search_ms = 0; break;
default: lsx_fail("unknown option `-%c'", optopt); return lsx_usage(effp);
}
- argc -= optind, argv += optind;
+ argc -= lsx_optind, argv += lsx_optind;
do { /* break-able block */
NUMERIC_PARAMETER(factor ,0.1 , 100 )
NUMERIC_PARAMETER(segment_ms , 10 , 120)
--- a/src/util.c
+++ b/src/util.c
@@ -85,7 +85,7 @@
int lsx_enum_option(int c, lsx_enum_item const * items)
{
- lsx_enum_item const * p = lsx_find_enum_text(optarg, items);
+ lsx_enum_item const * p = lsx_find_enum_text(lsx_optarg, items);
if (p == NULL) {
size_t len = 1;
char * set = lsx_malloc(len);
@@ -94,7 +94,7 @@
set = lsx_realloc(set, len += 2 + strlen(p->text));
strcat(set, ", "); strcat(set, p->text);
}
- lsx_fail("-%c: `%s' is not one of: %s.", c, optarg, set + 2);
+ lsx_fail("-%c: `%s' is not one of: %s.", c, lsx_optarg, set + 2);
free(set);
return INT_MAX;
}
--- a/src/vad.c
+++ b/src/vad.c
@@ -41,7 +41,7 @@
p->power_boot_len = 2; p->trigger_time = .01;
p->power_dt = .1; p->buffer_time = .05;
- while ((c = getopt(argc, argv, "+c:b:d:r:u:p:")) != -1) switch (c) {
+ while ((c = lsx_getopt(argc, argv, "+c:b:d:r:u:p:")) != -1) switch (c) {
GETOPT_NUMERIC('c', power_tc ,.001 , 10)
GETOPT_NUMERIC('b', power_boot_len , 0 , 10)
GETOPT_NUMERIC('d', power_dt ,.001 , 10)
@@ -51,7 +51,7 @@
default: lsx_fail("invalid option `-%c'", optopt); return lsx_usage(effp);
}
p->trigger_rise *= .1 * log(10.); /* Convert to natural log */
- return optind !=argc? lsx_usage(effp) : SOX_SUCCESS;
+ return lsx_optind !=argc? lsx_usage(effp) : SOX_SUCCESS;
}
static int start(sox_effect_t * effp)