ref: de3efbf70d870d9b34d126d3c437eeb7f75db33f
parent: 2512ec55a1df28fc324b0678816605f07411d6a0
author: cbagwell <cbagwell>
date: Wed Oct 13 21:58:41 EDT 1999
Made sox delete files by default again.
--- a/Changelog
+++ b/Changelog
@@ -7,6 +7,9 @@
sox-12.17
---------
o Added AVR handler from Jan Paul Schmidt.
+ o SoX now waits until the last possible moment before opening
+ the output file. This will allow all input and effect options
+ to be parsed for errors and abort before overwriting any file.
o SoX will no longer write to files that exists. This will keep
it from deleting files when a user mistakenly types "sox *.wav".
o Added new compander effect from Nick Bailey. Nice general purpose
--- a/TODO
+++ b/TODO
@@ -15,9 +15,6 @@
o Add GSM support to WAV format. Goes with the above but used
most often.
- o Add option that allows one to force overwriting to an output
- file (now that it defaults to not allowing this).
-
o highpass and lowpass filters don't let you specify the cut
of freq. Need some improvements to these filters.
--- a/src/sox.c
+++ b/src/sox.c
@@ -127,6 +127,12 @@
fail("Can't open input file '%s': %s",
ifile, strerror(errno));
ft->filename = ifile;
+#if defined(DUMB_FILESYSTEM)
+ ft->seekable = 0;
+#else
+ ft->seekable = (filetype(fileno(informat.fp)) == S_IFREG);
+#endif
+
optind++;
/* If more arguments are left then look for -e to see if */
@@ -144,6 +150,7 @@
ft = &outformat;
doopts(argc, argv);
+ /* Find and save output filename, if writing to file */
if (writing) {
/* Get output file */
if (optind >= argc)
@@ -150,45 +157,19 @@
usage("No output file?");
ofile = argv[optind];
ft->filename = ofile;
- /*
- * There are two choices here:
- * 1) stomp the old file - normal shell "> file" behavior
- * 2) fail if the old file already exists - csh mode
- */
- if (! strcmp(ofile, "-"))
- {
- ft->fp = stdout;
- /* stdout tends to be line-buffered. Override this */
- /* to be Full Buffering. */
- if (setvbuf (ft->fp,NULL,_IOFBF,sizeof(char)*BUFSIZ))
- fail("Can't set write buffer");
- }
- else {
-
- if ((ft->fp = fopen(ofile, READBINARY)) != NULL)
- {
- fclose(ft->fp);
- fail("File '%s' already exists.", ofile);
- }
-
- ft->fp = fopen(ofile, WRITEBINARY);
-
- if (ft->fp == NULL)
- fail("Can't open output file '%s': %s",
- ofile, strerror(errno));
-
- /* stdout tends to be line-buffered. Override this */
- /* to be Full Buffering. */
- if (setvbuf (ft->fp,NULL,_IOFBF,sizeof(char)*BUFSIZ))
- fail("Can't set write buffer");
-
- } /* end of else != stdout */
-
/* Move passed filename */
optind++;
- } /* end if writing */
+ /* Hold off on opening file until the very last minute.
+ * This allows us to verify header in input files are
+ * what they should be and parse effect command lines.
+ * That way if anything is found invalid, we will abort
+ * without truncating any existing file that has the same
+ * output filename.
+ */
+ }
+
/* Get effect name */
if (optind < argc) {
eff.name = argv[optind];
@@ -204,14 +185,6 @@
if (volume <= 0.0)
fail("Volume must be greater than 0.0");
-#if defined(DUMB_FILESYSETM)
- informat.seekable = 0;
- outformat.seekable = 0;
-#else
- informat.seekable = (filetype(fileno(informat.fp)) == S_IFREG);
- outformat.seekable = (filetype(fileno(outformat.fp)) == S_IFREG);
-#endif
-
/* If file types have not been set with -t, set from file names. */
if (! informat.filetype) {
if ((informat.filetype = strrchr(ifile, LASTCHAR)) != NULL)
@@ -407,6 +380,44 @@
/* need to check EFF_REPORT */
if (writing) {
+ /*
+ * There are two choices here:
+ * 1) stomp the old file - normal shell "> file" behavior
+ * 2) fail if the old file already exists - csh mode
+ */
+ if (! strcmp(ofile, "-"))
+ {
+ ft->fp = stdout;
+
+ /* stdout tends to be line-buffered. Override this */
+ /* to be Full Buffering. */
+ if (setvbuf (ft->fp,NULL,_IOFBF,sizeof(char)*BUFSIZ))
+ {
+ fail("Can't set write buffer");
+ }
+ }
+ else {
+
+ ft->fp = fopen(ofile, WRITEBINARY);
+
+ if (ft->fp == NULL)
+ fail("Can't open output file '%s': %s",
+ ofile, strerror(errno));
+
+ /* stdout tends to be line-buffered. Override this */
+ /* to be Full Buffering. */
+ if (setvbuf (ft->fp,NULL,_IOFBF,sizeof(char)*BUFSIZ))
+ {
+ fail("Can't set write buffer");
+ }
+
+ } /* end of else != stdout */
+#if defined(DUMB_FILESYSTEM)
+ outformat.seekable = 0;
+#else
+ outformat.seekable = (filetype(fileno(informat.fp)) == S_IFREG);
+#endif
+
copyformat(&informat, &outformat);
(* outformat.h->startwrite)(&outformat);
checkformat(&outformat);
--- a/src/testall.bat
+++ b/src/testall.bat
@@ -10,9 +10,7 @@
echo cls >>t.bat
echo echo Format: %%format%% Options: %%opts%% >>t.bat
echo echo on >>t.bat
-echo del %%tmp%%\monkey.%%format%%
echo .\sox monkey.voc %%opts%% %%tmp%%\monkey.%%format%% %%effect%% >>t.bat
-echo del %%tmp%%\monkey1.voc
echo .\sox %%opts%% %%tmp%%\monkey.%%format%% %%tmp%%\monkey1.voc %%effect%% >>t.bat
echo @echo off >>t.bat
echo echo. >>t.bat
--- a/src/testall.sh
+++ b/src/testall.sh
@@ -5,9 +5,7 @@
opts="$*"
echo "Format: $format Options: $opts"
- rm /tmp/monkey.$format
./sox monkey.voc $opts /tmp/monkey.$format $effect
- rm /tmp/monkey1.voc
./sox $opts /tmp/monkey.$format /tmp/monkey1.voc $effect
}
t 8svx
--
⑨