ref: 6257b1b873d24ff2192d86f6efa4817eb433480c
parent: bbee99ba6f099a9efb64384a482a39b1fb8aae9a
author: Ulrich Klauer <ulrich@chirlu.de>
date: Wed Jan 11 17:01:35 EST 2012
Allow an empty effects chain with --effects-file Enable the user to specify an empty last effects chain even when reading the effects from a file, by putting ":" by itself into the last line of the effects file. This commit also should solve the remaining memory management issues with --effects-file.
--- a/sox.1
+++ b/sox.1
@@ -825,9 +825,12 @@
\fB\-\-effects\-file \fIFILENAME\fR
Use FILENAME to obtain all effects and their arguments.
The file is parsed as if the values were specified on the
-command line. A new line can be used in place of the special ":" marker
-to separate effect chains. This option causes any effects specified on
-the command line to be discarded.
+command line. A new line can be used in place of the special \fB:\fR
+marker to separate effect chains. For convenience, such markers at the
+end of the file are normally ignored; if you want to specify an empty
+last effects chain, use an explicit \fB:\fR by itself on the last line
+of the file. This option causes any effects specified on the command
+line to be discarded.
.TP
\fB\-G\fR, \fB\-\-guard\fR
Automatically invoke the
--- a/src/sox.c
+++ b/src/sox.c
@@ -895,6 +895,7 @@
int pos = 0;
int argc;
char * * argv;
+ sox_bool last_was_colon = sox_false; /* last line read consisted of ":" only */
/* Free any command line options and then re-initialize to
* starter user_effargs.
@@ -901,6 +902,7 @@
*/
delete_eff_chains();
current_eff_chain = 0;
+ add_eff_chain();
if (!file) {
lsx_fail("Cannot open effects file `%s': %s", filename, strerror(errno));
@@ -929,8 +931,13 @@
exit(1);
}
+ last_was_colon = sox_false;
+
argv = strtoargv(s, &argc);
+ if (argv && argc == 1 && strcmp(argv[0], ":") == 0)
+ last_was_colon = sox_true;
+
if (argv) {
/* Make sure first option is an effect name. */
if (!sox_find_effect(argv[0]) && !is_pseudo_effect(argv[0]))
@@ -939,8 +946,6 @@
exit(1);
}
- add_eff_chain();
-
/* parse_effects normally parses options from command line.
* Reset opt index so it thinks its back at beginning of
* main()'s argv[].
@@ -951,8 +956,10 @@
/* Advance to next effect but only if current chain has been
* filled in. This recovers from side affects of pseudo-effects.
*/
- if (nuser_effects[eff_chain_count] > 0)
+ if (nuser_effects[eff_chain_count] > 0) {
eff_chain_count++;
+ add_eff_chain();
+ }
free(argv);
}
@@ -963,6 +970,15 @@
}
fclose(file);
free(s);
+
+ if (last_was_colon || eff_chain_count == 0) {
+ /* user explicitly wanted an empty last effects chain,
+ or didn't specify any chains at all */
+ eff_chain_count++;
+ } else {
+ /* there's one unneeded effects chain */
+ free_eff_chain();
+ }
} /* read_user_effects */
/* Creates users effects and passes in user specified options.