1 cli/wavpack.c | 57 ++++++++++++++++++++++++++++++++++++++-------------------
2 cli/wvunpack.c | 46 +++++++++++++++++++++++++++++++++-------------
3 2 files changed, 71 insertions(+), 32 deletions(-)
5 diff --git a/cli/wavpack.c b/cli/wavpack.c
6 index da60e0b..d81d092 100644
10 #define stricmp strcasecmp
14 +static __forceinline void flush_stderr(void)
16 + static int stderr_mode = -1;
17 + if (stderr_mode < 0)
20 + if (!_fstat(_fileno(stderr), &stat))
22 + stderr_mode = stat.st_mode & _S_IFMT;
25 + if (stderr_mode == _S_IFIFO)
27 + fflush(stderr); /*flush iff it's a pipe*/
32 ///////////////////////////// local variable storage //////////////////////////
34 static const char *sign_on = "\n"
35 @@ -777,11 +796,11 @@ int main (int argc, char **argv)
37 if (strcmp (WavpackGetLibraryVersionString (), PACKAGE_VERSION)) {
38 fprintf (stderr, version_warning, WavpackGetLibraryVersionString (), PACKAGE_VERSION);
42 else if (!quiet_mode && !error_count) {
43 fprintf (stderr, sign_on, VERSION_OS, WavpackGetLibraryVersionString ());
48 // Loop through any tag specification strings and check for file access, convert text
49 @@ -891,7 +910,7 @@ int main (int argc, char **argv)
52 fprintf (stderr, "\ntype 'wavpack' for short help or 'wavpack --help' for full help\n");
58 @@ -1189,7 +1208,7 @@ int main (int argc, char **argv)
60 if (num_files > 1 && !quiet_mode) {
61 fprintf (stderr, "\n%s:\n", matches [file_index]);
66 if (filespec_ext (matches [file_index]) && !stricmp (filespec_ext (matches [file_index]), ".wv"))
67 @@ -1223,11 +1242,11 @@ int main (int argc, char **argv)
70 fprintf (stderr, "\n **** warning: errors occurred in %d of %d files! ****\n", error_count, num_files);
74 else if (!quiet_mode) {
75 fprintf (stderr, "\n **** %d files successfully processed ****\n", num_files);
81 @@ -1278,7 +1297,7 @@ int main(int argc, char **argv)
84 fprintf (stderr, "\nPress any key to continue . . . ");
89 fprintf (stderr, "\n");
90 @@ -1507,7 +1526,7 @@ static int pack_file (char *infilename, char *outfilename, char *out2filename, c
93 fprintf (stderr, "overwrite %s (yes/no/all)? ", FN_FIT (outfilename));
97 if (set_console_title)
98 DoSetConsoleTitle ("overwrite?");
99 @@ -1532,7 +1551,7 @@ static int pack_file (char *infilename, char *outfilename, char *out2filename, c
102 fprintf (stderr, "overwrite %s (yes/no/all)? ", FN_FIT (out2filename));
106 if (set_console_title)
107 DoSetConsoleTitle ("overwrite?");
108 @@ -1643,7 +1662,7 @@ static int pack_file (char *infilename, char *outfilename, char *out2filename, c
110 fprintf (stderr, "creating %s,", FN_FIT (outfilename));
117 @@ -2396,7 +2415,7 @@ static int pack_audio (WavpackContext *wpc, FILE *infile, unsigned char *new_ord
119 fprintf (stderr, "\n");
123 free (sample_buffer);
125 return WAVPACK_SOFT_ERROR;
126 @@ -2412,7 +2431,7 @@ static int pack_audio (WavpackContext *wpc, FILE *infile, unsigned char *new_ord
128 fprintf (stderr, "%s%3d%% done...",
129 nobs ? " " : "\b\b\b\b\b\b\b\b\b\b\b\b", (int) progress);
135 @@ -2506,7 +2525,7 @@ static int repack_file (char *infilename, char *outfilename, char *out2filename,
137 fprintf (stderr, "overwrite %s with lossy transcode (yes/no/all)? ", FN_FIT (outfilename));
142 if (set_console_title)
143 DoSetConsoleTitle ("overwrite?");
144 @@ -2526,7 +2545,7 @@ static int repack_file (char *infilename, char *outfilename, char *out2filename,
145 if (out2filename && !overwrite_all && (wvc_file.file = fopen (out2filename, "rb")) != NULL) {
146 DoCloseHandle (wvc_file.file);
147 fprintf (stderr, "overwrite %s (yes/no/all)? ", FN_FIT (out2filename));
151 if (set_console_title)
152 DoSetConsoleTitle ("overwrite?");
153 @@ -2628,7 +2647,7 @@ static int repack_file (char *infilename, char *outfilename, char *out2filename,
155 fprintf (stderr, "creating %s,", FN_FIT (outfilename));
162 @@ -3076,7 +3095,7 @@ static int repack_audio (WavpackContext *outfile, WavpackContext *infile, unsign
164 fprintf (stderr, "\n");
168 free (sample_buffer);
169 return WAVPACK_SOFT_ERROR;
171 @@ -3091,7 +3110,7 @@ static int repack_audio (WavpackContext *outfile, WavpackContext *infile, unsign
173 fprintf (stderr, "%s%3d%% done...",
174 nobs ? " " : "\b\b\b\b\b\b\b\b\b\b\b\b", (int) progress);
180 @@ -3194,7 +3213,7 @@ static int verify_audio (char *infilename, unsigned char *md5_digest_source)
182 fprintf (stderr, "\n");
186 result = WAVPACK_SOFT_ERROR;
189 @@ -3208,7 +3227,7 @@ static int verify_audio (char *infilename, unsigned char *md5_digest_source)
191 fprintf (stderr, "%s%3d%% done...",
192 "\b\b\b\b\b\b\b\b\b\b\b\b", (int) progress);
198 diff --git a/cli/wvunpack.c b/cli/wvunpack.c
199 index 05c9fda..07dbd99 100644
203 #define strdup(x) _strdup(x)
207 +static __forceinline void flush_stderr(void)
209 + static int stderr_mode = -1;
210 + if (stderr_mode < 0)
213 + if (!_fstat(_fileno(stderr), &stat))
215 + stderr_mode = stat.st_mode & _S_IFMT;
218 + if (stderr_mode == _S_IFIFO)
220 + fflush(stderr); /*flush iff it's a pipe*/
225 ///////////////////////////// local variable storage //////////////////////////
227 static const char *sign_on = "\n"
228 @@ -460,11 +479,11 @@ int main(int argc, char **argv)
230 if (strcmp (WavpackGetLibraryVersionString (), PACKAGE_VERSION)) {
231 fprintf (stderr, version_warning, WavpackGetLibraryVersionString (), PACKAGE_VERSION);
235 else if (!quiet_mode && !error_count) {
236 fprintf (stderr, sign_on, VERSION_OS, WavpackGetLibraryVersionString ());
242 @@ -677,7 +696,7 @@ int main(int argc, char **argv)
244 if (num_files > 1 && !quiet_mode) {
245 fprintf (stderr, "\n%s:\n", matches [file_index]);
250 result = unpack_file (matches [file_index], verify_only ? NULL : outfilename);
251 @@ -703,11 +722,11 @@ int main(int argc, char **argv)
254 fprintf (stderr, "\n **** warning: errors occurred in %d of %d files! ****\n", error_count, num_files);
258 else if (!quiet_mode) {
259 fprintf (stderr, "\n **** %d files successfully processed ****\n", num_files);
265 @@ -758,10 +777,11 @@ int main(int argc, char **argv)
268 fprintf (stderr, "\nPress any key to continue . . . ");
273 fprintf (stderr, "\n");
278 @@ -845,7 +865,7 @@ static FILE *open_output_file (char *filename, char **tempfilename)
280 if (!overwrite_all) {
281 fprintf (stderr, "overwrite %s (yes/no/all)? ", FN_FIT (filename));
285 if (set_console_title)
286 DoSetConsoleTitle ("overwrite?");
287 @@ -1060,12 +1080,12 @@ static int unpack_file (char *infilename, char *outfilename)
289 fprintf (stderr, "unpacking %s%s to stdout,", *infilename == '-' ?
290 "stdin" : FN_FIT (infilename), wvc_mode ? " (+.wvc)" : "");
295 else if (!quiet_mode) {
296 fprintf (stderr, "restoring %s,", FN_FIT (outfilename));
302 @@ -1087,7 +1107,7 @@ static int unpack_file (char *infilename, char *outfilename)
304 fprintf (stderr, "verifying %s%s,", *infilename == '-' ? "stdin" :
305 FN_FIT (infilename), wvc_mode ? " (+.wvc)" : "");
311 @@ -1175,7 +1195,7 @@ static int unpack_file (char *infilename, char *outfilename)
313 fprintf (stderr, "\n");
317 DoTruncateFile (outfile);
318 result = WAVPACK_SOFT_ERROR;
320 @@ -1192,7 +1212,7 @@ static int unpack_file (char *infilename, char *outfilename)
322 fprintf (stderr, "%s%3d%% done...",
323 nobs ? " " : "\b\b\b\b\b\b\b\b\b\b\b\b", (int) progress);
329 @@ -1474,7 +1494,7 @@ static int do_tag_extractions (WavpackContext *wpc, char *outfilename)
330 if (!overwrite_all && (outfile = fopen (full_filename, "r")) != NULL) {
331 DoCloseHandle (outfile);
332 fprintf (stderr, "overwrite %s (yes/no/all)? ", FN_FIT (full_filename));
336 if (set_console_title)
337 DoSetConsoleTitle ("overwrite?");