1 cli/utils.c | 34 +++++++++++++++++++++++++---------
2 cli/wavpack.c | 58 +++++++++++++++++++++++++++++++++++++---------------------
3 cli/wvgain.c | 34 +++++++++++++++++++++++++---------
4 cli/wvtag.c | 30 +++++++++++++++++++++++-------
5 cli/wvunpack.c | 46 +++++++++++++++++++++++++++++++---------------
6 5 files changed, 141 insertions(+), 61 deletions(-)
8 diff --git a/cli/utils.c b/cli/utils.c
9 index d59bad0..8840032 100644
13 #define remove(f) unlink_utf8(f)
17 +static __inline void flush_pipe(FILE *const stream)
20 + if (!_fstat(_fileno(stream), &stat))
22 + if ((stat.st_mode & _S_IFMT) == _S_IFIFO)
24 + fflush(stream); /*flush iff it is a pipe*/
29 +#define flush_pipe(X) ((void)0)
34 int copy_timestamp (const char *src_filename, const char *dst_filename)
35 @@ -325,38 +341,38 @@ char yna (void)
36 else if (key == '\r' || key == '\n') {
38 fprintf (stderr, "\r\n");
40 + flush_pipe (stderr);
44 fprintf (stderr, "%c", 7);
46 + flush_pipe (stderr);
49 else if (key == 'Y' || key == 'y') {
51 fprintf (stderr, "%c\b", key);
53 + flush_pipe (stderr);
57 else if (key == 'N' || key == 'n') {
59 fprintf (stderr, "%c\b", key);
61 + flush_pipe (stderr);
65 else if (key == 'A' || key == 'a') {
67 fprintf (stderr, "%c\b", key);
69 + flush_pipe (stderr);
74 fprintf (stderr, "%c", 7);
76 + flush_pipe (stderr);
80 @@ -557,7 +573,7 @@ void finish_line (void)
82 fprintf (stderr, " \n");
85 + flush_pipe (stderr);
88 //////////////////////////////////////////////////////////////////////////////
89 @@ -568,7 +584,7 @@ void finish_line (void)
90 void finish_line (void)
92 fprintf (stderr, " \n");
94 + flush_pipe (stderr);
97 //////////////////////////////////////////////////////////////////////////////
98 @@ -763,7 +779,7 @@ void DoSetConsoleTitle (char *text)
99 void DoSetConsoleTitle (char *text)
101 fprintf (stderr, "\033]0;%s\007", text);
103 + flush_pipe (stderr);
107 diff --git a/cli/wavpack.c b/cli/wavpack.c
108 index 4d46aba..f33086f 100644
112 #define stricmp strcasecmp
116 +static __inline void flush_pipe(FILE *const stream)
119 + if (!_fstat(_fileno(stream), &stat))
121 + if ((stat.st_mode & _S_IFMT) == _S_IFIFO)
123 + fflush(stream); /*flush iff it is a pipe*/
128 +#define flush_pipe(X) ((void)0)
131 ///////////////////////////// local variable storage //////////////////////////
133 static const char *sign_on = "\n"
134 @@ -882,11 +898,11 @@ int main (int argc, char **argv)
136 if (strcmp (WavpackGetLibraryVersionString (), PACKAGE_VERSION)) {
137 fprintf (stderr, version_warning, WavpackGetLibraryVersionString (), PACKAGE_VERSION);
139 + flush_pipe (stderr);
141 else if (!quiet_mode && !error_count) {
142 fprintf (stderr, sign_on, VERSION_OS, WavpackGetLibraryVersionString ());
144 + flush_pipe (stderr);
147 // Loop through any tag specification strings and check for file access, convert text
148 @@ -1004,7 +1020,7 @@ int main (int argc, char **argv)
151 fprintf (stderr, "\ntype 'wavpack' for short help or 'wavpack --help' for full help\n");
153 + flush_pipe (stderr);
157 @@ -1261,7 +1277,7 @@ int main (int argc, char **argv)
159 if (num_files > 1 && !quiet_mode) {
160 fprintf (stderr, "\n%s:\n", matches [file_index]);
162 + flush_pipe (stderr);
165 if (filespec_ext (matches [file_index]) && !stricmp (filespec_ext (matches [file_index]), ".wv"))
166 @@ -1295,11 +1311,11 @@ int main (int argc, char **argv)
169 fprintf (stderr, "\n **** warning: errors occurred in %d of %d files! ****\n", error_count, num_files);
171 + flush_pipe (stderr);
173 else if (!quiet_mode) {
174 fprintf (stderr, "\n **** %d files successfully processed ****\n", num_files);
176 + flush_pipe (stderr);
180 @@ -1350,7 +1366,7 @@ int main(int argc, char **argv)
183 fprintf (stderr, "\nPress any key to continue . . . ");
185 + flush_pipe (stderr);
188 fprintf (stderr, "\n");
189 @@ -1604,7 +1620,7 @@ static int pack_file (char *infilename, char *outfilename, char *out2filename, c
191 if (!overwrite_all) {
192 fprintf (stderr, "overwrite %s (yes/no/all)? ", FN_FIT (outfilename));
194 + flush_pipe (stderr);
196 if (set_console_title)
197 DoSetConsoleTitle ("overwrite?");
198 @@ -1629,7 +1645,7 @@ static int pack_file (char *infilename, char *outfilename, char *out2filename, c
201 fprintf (stderr, "overwrite %s (yes/no/all)? ", FN_FIT (out2filename));
203 + flush_pipe (stderr);
205 if (set_console_title)
206 DoSetConsoleTitle ("overwrite?");
207 @@ -1740,7 +1756,7 @@ static int pack_file (char *infilename, char *outfilename, char *out2filename, c
209 fprintf (stderr, "creating %s,", FN_FIT (outfilename));
212 + flush_pipe (stderr);
215 // for now, raw 1-bit PCM is only DSDIFF format
216 @@ -2364,7 +2380,7 @@ static int pack_audio (WavpackContext *wpc, FILE *infile, int qmode, unsigned ch
218 fprintf (stderr, "\n");
221 + flush_pipe (stderr);
222 free (sample_buffer);
224 return WAVPACK_SOFT_ERROR;
225 @@ -2380,7 +2396,7 @@ static int pack_audio (WavpackContext *wpc, FILE *infile, int qmode, unsigned ch
227 fprintf (stderr, "%s%3d%% done...",
228 nobs ? " " : "\b\b\b\b\b\b\b\b\b\b\b\b", (int) progress);
230 + flush_pipe (stderr);
234 @@ -2522,7 +2538,7 @@ static int pack_dsd_audio (WavpackContext *wpc, FILE *infile, int qmode, unsigne
236 fprintf (stderr, "\n");
239 + flush_pipe (stderr);
240 free (sample_buffer);
242 return WAVPACK_SOFT_ERROR;
243 @@ -2538,7 +2554,7 @@ static int pack_dsd_audio (WavpackContext *wpc, FILE *infile, int qmode, unsigne
245 fprintf (stderr, "%s%3d%% done...",
246 nobs ? " " : "\b\b\b\b\b\b\b\b\b\b\b\b", (int) progress);
248 + flush_pipe (stderr);
252 @@ -2637,7 +2653,7 @@ static int repack_file (char *infilename, char *outfilename, char *out2filename,
254 fprintf (stderr, "overwrite %s with lossy transcode (yes/no/all)? ", FN_FIT (outfilename));
257 + flush_pipe (stderr);
259 if (set_console_title)
260 DoSetConsoleTitle ("overwrite?");
261 @@ -2657,7 +2673,7 @@ static int repack_file (char *infilename, char *outfilename, char *out2filename,
262 if (out2filename && !overwrite_all && (wvc_file.file = fopen (out2filename, "rb")) != NULL) {
263 DoCloseHandle (wvc_file.file);
264 fprintf (stderr, "overwrite %s (yes/no/all)? ", FN_FIT (out2filename));
266 + flush_pipe (stderr);
268 if (set_console_title)
269 DoSetConsoleTitle ("overwrite?");
270 @@ -2759,7 +2775,7 @@ static int repack_file (char *infilename, char *outfilename, char *out2filename,
272 fprintf (stderr, "creating %s,", FN_FIT (outfilename));
275 + flush_pipe (stderr);
278 WavpackSetFileInformation (outfile, WavpackGetFileExtension (infile), WavpackGetFileFormat (infile));
279 @@ -3324,7 +3340,7 @@ static int repack_audio (WavpackContext *outfile, WavpackContext *infile, unsign
281 fprintf (stderr, "\n");
284 + flush_pipe (stderr);
285 free (sample_buffer);
286 return WAVPACK_SOFT_ERROR;
288 @@ -3339,7 +3355,7 @@ static int repack_audio (WavpackContext *outfile, WavpackContext *infile, unsign
290 fprintf (stderr, "%s%3d%% done...",
291 nobs ? " " : "\b\b\b\b\b\b\b\b\b\b\b\b", (int) progress);
293 + flush_pipe (stderr);
297 @@ -3525,7 +3541,7 @@ static int verify_audio (char *infilename, unsigned char *md5_digest_source)
299 fprintf (stderr, "\n");
302 + flush_pipe (stderr);
303 result = WAVPACK_SOFT_ERROR;
306 @@ -3539,7 +3555,7 @@ static int verify_audio (char *infilename, unsigned char *md5_digest_source)
308 fprintf (stderr, "%s%3d%% done...",
309 "\b\b\b\b\b\b\b\b\b\b\b\b", (int) progress);
311 + flush_pipe (stderr);
315 diff --git a/cli/wvgain.c b/cli/wvgain.c
316 index 4e789ea..2603824 100644
320 #define fopen(f,m) fopen_utf8(f,m)
324 +static __inline void flush_pipe(FILE *const stream)
327 + if (!_fstat(_fileno(stream), &stat))
329 + if ((stat.st_mode & _S_IFMT) == _S_IFIFO)
331 + fflush(stream); /*flush iff it is a pipe*/
336 +#define flush_pipe(X) ((void)0)
339 ///////////////////////////// local variable storage //////////////////////////
341 static const char *sign_on = "\n"
342 @@ -258,11 +274,11 @@ int main(int argc, char **argv)
344 if (strcmp (WavpackGetLibraryVersionString (), PACKAGE_VERSION)) {
345 fprintf (stderr, version_warning, WavpackGetLibraryVersionString (), PACKAGE_VERSION);
347 + flush_pipe (stderr);
349 else if (!quiet_mode && !error_count) {
350 fprintf (stderr, sign_on, VERSION_OS, WavpackGetLibraryVersionString ());
352 + flush_pipe (stderr);
356 @@ -407,7 +423,7 @@ int main(int argc, char **argv)
358 if (num_files > 1 && !quiet_mode) {
359 fprintf (stderr, "\n%s:\n", matches [file_index]);
361 + flush_pipe (stderr);
365 @@ -496,7 +512,7 @@ int main(int argc, char **argv)
367 if (num_files > 1 && !quiet_mode) {
368 fprintf (stderr, "\n%s:\n", matches [file_index]);
370 + flush_pipe (stderr);
374 @@ -517,11 +533,11 @@ int main(int argc, char **argv)
377 fprintf (stderr, "\n **** warning: errors occurred in %d of %d files! ****\n", error_count, num_files);
379 + flush_pipe (stderr);
381 else if (!quiet_mode) {
382 fprintf (stderr, "\n **** %d files successfully processed ****\n", num_files);
384 + flush_pipe (stderr);
388 @@ -624,7 +640,7 @@ static int analyze_file (char *infilename, uint32_t *histogram, float *peak)
390 fprintf (stderr, "analyzing %s%s,", *infilename == '-' ? "stdin" :
391 FN_FIT (infilename), wvc_mode ? " (+.wvc)" : "");
393 + flush_pipe (stderr);
396 sample_rate = WavpackGetSampleRate (wpc);
397 @@ -711,7 +727,7 @@ static int analyze_file (char *infilename, uint32_t *histogram, float *peak)
399 fprintf (stderr, "\n");
402 + flush_pipe (stderr);
403 result = WAVPACK_HARD_ERROR;
406 @@ -727,7 +743,7 @@ static int analyze_file (char *infilename, uint32_t *histogram, float *peak)
408 fprintf (stderr, "%s%3d%% done...",
409 nobs ? " " : "\b\b\b\b\b\b\b\b\b\b\b\b", (int) progress);
411 + flush_pipe (stderr);
415 diff --git a/cli/wvtag.c b/cli/wvtag.c
416 index 6e6512a..33f3526 100644
420 #define stricmp strcasecmp
424 +static __inline void flush_pipe(FILE *const stream)
427 + if (!_fstat(_fileno(stream), &stat))
429 + if ((stat.st_mode & _S_IFMT) == _S_IFIFO)
431 + fflush(stream); /*flush iff it is a pipe*/
436 +#define flush_pipe(X) ((void)0)
439 ///////////////////////////// local variable storage //////////////////////////
441 static const char *sign_on = "\n"
442 @@ -408,11 +424,11 @@ int main (int argc, char **argv)
444 if (strcmp (WavpackGetLibraryVersionString (), PACKAGE_VERSION)) {
445 fprintf (stderr, version_warning, WavpackGetLibraryVersionString (), PACKAGE_VERSION);
447 + flush_pipe (stderr);
449 else if (!quiet_mode && !error_count) {
450 fprintf (stderr, sign_on, VERSION_OS, WavpackGetLibraryVersionString ());
452 + flush_pipe (stderr);
455 // Loop through any tag specification strings and check for file access, convert text
456 @@ -653,7 +669,7 @@ int main (int argc, char **argv)
458 if (num_files > 1 && !quiet_mode) {
459 fprintf (stderr, "\n%s:\n", matches [file_index]);
461 + flush_pipe (stderr);
464 result = process_file (matches [file_index]);
465 @@ -672,11 +688,11 @@ int main (int argc, char **argv)
468 fprintf (stderr, "\n **** warning: errors occurred in %d of %d files! ****\n", error_count, num_files);
470 + flush_pipe (stderr);
472 else if (!quiet_mode) {
473 fprintf (stderr, "\n **** %d files successfully processed ****\n", num_files);
475 + flush_pipe (stderr);
479 @@ -721,7 +737,7 @@ int main(int argc, char **argv)
482 fprintf (stderr, "\nPress any key to continue . . . ");
484 + flush_pipe (stderr);
487 fprintf (stderr, "\n");
488 @@ -995,7 +1011,7 @@ static int do_tag_extractions (WavpackContext *wpc, char *outfilename)
489 if (!overwrite_all && (outfile = fopen (full_filename, "r")) != NULL) {
490 DoCloseHandle (outfile);
491 fprintf (stderr, "overwrite %s (yes/no/all)? ", FN_FIT (full_filename));
493 + flush_pipe (stderr);
497 diff --git a/cli/wvunpack.c b/cli/wvunpack.c
498 index 2db1cb3..c0a3c87 100644
502 #define strdup(x) _strdup(x)
506 +static __inline void flush_pipe(FILE *const stream)
509 + if (!_fstat(_fileno(stream), &stat))
511 + if ((stat.st_mode & _S_IFMT) == _S_IFIFO)
513 + fflush(stream); /*flush iff it is a pipe*/
518 +#define flush_pipe(X) ((void)0)
521 ///////////////////////////// local variable storage //////////////////////////
523 static const char *sign_on = "\n"
524 @@ -549,11 +565,11 @@ int main(int argc, char **argv)
526 if (strcmp (WavpackGetLibraryVersionString (), PACKAGE_VERSION)) {
527 fprintf (stderr, version_warning, WavpackGetLibraryVersionString (), PACKAGE_VERSION);
529 + flush_pipe (stderr);
531 else if (!quiet_mode && !error_count) {
532 fprintf (stderr, sign_on, VERSION_OS, WavpackGetLibraryVersionString ());
534 + flush_pipe (stderr);
538 @@ -763,7 +779,7 @@ int main(int argc, char **argv)
540 if (num_files > 1 && !quiet_mode) {
541 fprintf (stderr, "\n%s:\n", matches [file_index]);
543 + flush_pipe (stderr);
546 result = unpack_file (matches [file_index], verify_only ? NULL : outfilename, add_extension);
547 @@ -789,11 +805,11 @@ int main(int argc, char **argv)
550 fprintf (stderr, "\n **** warning: errors occurred in %d of %d files! ****\n", error_count, num_files);
552 + flush_pipe (stderr);
554 else if (!quiet_mode) {
555 fprintf (stderr, "\n **** %d files successfully processed ****\n", num_files);
557 + flush_pipe (stderr);
561 @@ -844,7 +860,7 @@ int main(int argc, char **argv)
564 fprintf (stderr, "\nPress any key to continue . . . ");
566 + flush_pipe (stderr);
569 fprintf (stderr, "\n");
570 @@ -931,7 +947,7 @@ static FILE *open_output_file (char *filename, char **tempfilename)
572 if (!overwrite_all) {
573 fprintf (stderr, "overwrite %s (yes/no/all)? ", FN_FIT (filename));
575 + flush_pipe (stderr);
577 if (set_console_title)
578 DoSetConsoleTitle ("overwrite?");
579 @@ -1235,12 +1251,12 @@ static int unpack_file (char *infilename, char *outfilename, int add_extension)
581 fprintf (stderr, "unpacking %s%s to stdout,", *infilename == '-' ?
582 "stdin" : FN_FIT (infilename), wvc_mode ? " (+.wvc)" : "");
584 + flush_pipe (stderr);
587 else if (!quiet_mode) {
588 fprintf (stderr, "restoring %s,", FN_FIT (outfilename));
590 + flush_pipe (stderr);
593 else { // in verify only mode we don't worry about headers
594 @@ -1249,7 +1265,7 @@ static int unpack_file (char *infilename, char *outfilename, int add_extension)
596 fprintf (stderr, "verifying %s%s,", *infilename == '-' ? "stdin" :
597 FN_FIT (infilename), wvc_mode ? " (+.wvc)" : "");
599 + flush_pipe (stderr);
603 @@ -1607,7 +1623,7 @@ static int unpack_audio (WavpackContext *wpc, FILE *outfile, int qmode, unsigned
605 fprintf (stderr, "\n");
608 + flush_pipe (stderr);
609 DoTruncateFile (outfile);
610 result = WAVPACK_SOFT_ERROR;
612 @@ -1624,7 +1640,7 @@ static int unpack_audio (WavpackContext *wpc, FILE *outfile, int qmode, unsigned
614 fprintf (stderr, "%s%3d%% done...",
615 nobs ? " " : "\b\b\b\b\b\b\b\b\b\b\b\b", (int) progress);
617 + flush_pipe (stderr);
621 @@ -1762,7 +1778,7 @@ static int unpack_dsd_audio (WavpackContext *wpc, FILE *outfile, int qmode, unsi
623 fprintf (stderr, "\n");
626 + flush_pipe (stderr);
627 DoTruncateFile (outfile);
628 result = WAVPACK_SOFT_ERROR;
630 @@ -1779,7 +1795,7 @@ static int unpack_dsd_audio (WavpackContext *wpc, FILE *outfile, int qmode, unsi
632 fprintf (stderr, "%s%3d%% done...",
633 nobs ? " " : "\b\b\b\b\b\b\b\b\b\b\b\b", (int) progress);
635 + flush_pipe (stderr);
639 @@ -1883,7 +1899,7 @@ static int do_tag_extractions (WavpackContext *wpc, char *outfilename)
640 if (!overwrite_all && (outfile = fopen (full_filename, "r")) != NULL) {
641 DoCloseHandle (outfile);
642 fprintf (stderr, "overwrite %s (yes/no/all)? ", FN_FIT (full_filename));
644 + flush_pipe (stderr);
646 if (set_console_title)
647 DoSetConsoleTitle ("overwrite?");