Bump version.
[LameXP.git] / etc / Patches / deprecated / WavPack-4.70.0-UTF8+FlushProgress.diff
blobfcd6dee3aca5779a6fea79266051101fc79e5114
1 diff --git a/cli/wvunpack.c b/cli/wvunpack.c
2 index 424514f..110d0b6 100644
3 --- a/cli/wvunpack.c
4 +++ b/cli/wvunpack.c
5 @@ -50,6 +50,7 @@
6 #ifdef WIN32
7 #define strdup(x) _strdup(x)
8 #define fileno _fileno
9 +#include "../src/unicode_support.h"
10 #endif
12 #ifdef DEBUG_ALLOC
13 @@ -152,7 +153,7 @@ static void display_progress (double file_progress);
14 // The "main" function for the command-line WavPack decompressor. //
15 //////////////////////////////////////////////////////////////////////////////
17 -int main (argc, argv) int argc; char **argv;
18 +static int wvunpack_main (argc, argv) int argc; char **argv;
20 #ifdef __EMX__ /* OS/2 */
21 _wildcard (&argc, &argv);
22 @@ -162,7 +163,7 @@ int main (argc, argv) int argc; char **argv;
23 int result;
25 #if defined(WIN32)
26 - struct _finddata_t _finddata_t;
27 + //struct _finddata_t _finddata_t;
28 char selfname [MAX_PATH];
30 if (GetModuleFileName (NULL, selfname, sizeof (selfname)) && filespec_name (selfname) &&
31 @@ -437,8 +438,10 @@ int main (argc, argv) int argc; char **argv;
32 ++error_count;
35 - if (!quiet_mode && !error_count)
36 - fprintf (stderr, sign_on, VERSION_OS, WavpackGetLibraryVersionString ());
37 + if (!quiet_mode && !error_count) {
38 + fprintf(stderr, sign_on, VERSION_OS, WavpackGetLibraryVersionString());
39 + fflush(stderr);
40 + }
42 if (!num_files) {
43 printf ("%s", usage);
44 @@ -459,7 +462,7 @@ int main (argc, argv) int argc; char **argv;
45 // frontends, but could be used for other purposes.
47 if (*infilename == '@') {
48 - FILE *list = fopen (infilename+1, "rt");
49 + FILE *list = fopen_utf8 (infilename+1, "rt");
50 int di, c;
52 for (di = file_index; di < num_files - 1; di++)
53 @@ -501,9 +504,9 @@ int main (argc, argv) int argc; char **argv;
54 fclose (list);
55 free (infilename);
57 -#if defined (WIN32)
58 +#if defined (WIN66)
59 else if (filespec_wild (infilename)) {
60 - FILE *list = fopen (infilename+1, "rt");
61 + FILE *list = fopen_utf8 (infilename+1, "rt");
62 intptr_t file;
63 int di;
65 @@ -542,7 +545,7 @@ int main (argc, argv) int argc; char **argv;
66 // be passed on the command-line, but could be used for other purposes.
68 if (outfilename && outfilename [0] == '@') {
69 - FILE *list = fopen (outfilename+1, "rt");
70 + FILE *list = fopen_utf8 (outfilename+1, "rt");
71 int c;
73 if (list == NULL) {
74 @@ -614,8 +617,10 @@ int main (argc, argv) int argc; char **argv;
75 if (outfilename && *outfilename != '-' && add_extension)
76 strcat (outfilename, raw_decode ? ".raw" : ".wav");
78 - if (num_files > 1 && !quiet_mode)
79 - fprintf (stderr, "\n%s:\n", matches [file_index]);
80 + if (num_files > 1 && !quiet_mode) {
81 + fprintf(stderr, "\n%s:\n", matches[file_index]);
82 + fflush(stderr);
83 + }
85 result = unpack_file (matches [file_index], verify_only ? NULL : outfilename);
87 @@ -642,6 +647,7 @@ int main (argc, argv) int argc; char **argv;
88 fprintf (stderr, "\n **** warning: errors occurred in %d of %d files! ****\n", error_count, num_files);
89 else if (!quiet_mode)
90 fprintf (stderr, "\n **** %d files successfully processed ****\n", num_files);
91 + fflush(stderr);
94 free (matches);
95 @@ -728,7 +734,7 @@ static FILE *open_output_file (char *filename, char **tempfilename)
96 return stdout;
99 - testfile = fopen (filename, "rb");
100 + testfile = fopen_utf8 (filename, "rb");
102 if (testfile) {
103 size_t res = fread (&dummy, 1, 1, testfile);
104 @@ -773,7 +779,7 @@ static FILE *open_output_file (char *filename, char **tempfilename)
105 strcat (*tempfilename, ".tmp");
108 - testfile = fopen (*tempfilename, "rb");
109 + testfile = fopen_utf8 (*tempfilename, "rb");
111 if (!testfile)
112 break;
113 @@ -787,7 +793,7 @@ static FILE *open_output_file (char *filename, char **tempfilename)
117 - retval = fopen (*tempfilename ? *tempfilename : filename, "w+b");
118 + retval = fopen_utf8 (*tempfilename ? *tempfilename : filename, "w+b");
120 if (retval == NULL)
121 error_line ("can't create file %s!", *tempfilename ? *tempfilename : filename);
122 @@ -945,12 +951,15 @@ static int unpack_file (char *infilename, char *outfilename)
123 return SOFT_ERROR;
125 else if (*outfilename == '-') {
126 - if (!quiet_mode)
127 - fprintf (stderr, "unpacking %s%s to stdout,", *infilename == '-' ?
128 - "stdin" : FN_FIT (infilename), wvc_mode ? " (+.wvc)" : "");
129 + if (!quiet_mode) {
130 + fprintf(stderr, "unpacking %s%s to stdout,", *infilename == '-' ? "stdin" : FN_FIT(infilename), wvc_mode ? " (+.wvc)" : "");
131 + fflush(stderr);
134 - else if (!quiet_mode)
135 - fprintf (stderr, "restoring %s,", FN_FIT (outfilename));
136 + else if (!quiet_mode) {
137 + fprintf(stderr, "restoring %s,", FN_FIT(outfilename));
138 + fflush(stderr);
141 if (outbuf_k)
142 output_buffer_size = outbuf_k * 1024;
143 @@ -968,9 +977,10 @@ static int unpack_file (char *infilename, char *outfilename)
144 else { // in verify only mode we don't worry about headers
145 outfile = NULL;
147 - if (!quiet_mode)
148 - fprintf (stderr, "verifying %s%s,", *infilename == '-' ? "stdin" :
149 - FN_FIT (infilename), wvc_mode ? " (+.wvc)" : "");
150 + if (!quiet_mode) {
151 + fprintf(stderr, "verifying %s%s,", *infilename == '-' ? "stdin" : FN_FIT(infilename), wvc_mode ? " (+.wvc)" : "");
152 + fflush(stderr);
156 #if defined(WIN32)
157 @@ -1070,9 +1080,10 @@ static int unpack_file (char *infilename, char *outfilename)
158 display_progress (progress);
159 progress = floor (progress * 100.0 + 0.5);
161 - if (!quiet_mode)
162 - fprintf (stderr, "%s%3d%% done...",
163 - nobs ? " " : "\b\b\b\b\b\b\b\b\b\b\b\b", (int) progress);
164 + if (!quiet_mode) {
165 + fprintf(stderr, "%s%3d%% done...", nobs ? " " : "\b\b\b\b\b\b\b\b\b\b\b\b", (int)progress);
166 + fflush(stderr);
171 @@ -1242,6 +1253,7 @@ static int unpack_file (char *infilename, char *outfilename)
174 error_line ("%s %s%s in %.2f secs (%s%s)", oper, file, fext, dtime, cmode, cratio);
175 + fflush(stderr);
178 WavpackCloseFile (wpc);
179 @@ -1249,9 +1261,10 @@ static int unpack_file (char *infilename, char *outfilename)
180 if (result == NO_ERROR && delete_source) {
181 int res = DoDeleteFile (infilename);
183 - if (!quiet_mode || !res)
184 - error_line ("%s source file %s", res ?
185 - "deleted" : "can't delete", infilename);
186 + if (!quiet_mode || !res) {
187 + error_line("%s source file %s", res ? "deleted" : "can't delete", infilename);
188 + fflush(stderr);
191 if (wvc_mode) {
192 char in2filename [PATH_MAX];
193 @@ -1260,9 +1273,10 @@ static int unpack_file (char *infilename, char *outfilename)
194 strcat (in2filename, "c");
195 res = DoDeleteFile (in2filename);
197 - if (!quiet_mode || !res)
198 - error_line ("%s source file %s", res ?
199 - "deleted" : "can't delete", in2filename);
200 + if (!quiet_mode || !res) {
201 + error_line("%s source file %s", res ? "deleted" : "can't delete", in2filename);
202 + fflush(stderr);
207 @@ -1350,7 +1364,7 @@ static int do_tag_extractions (WavpackContext *wpc, char *outfilename)
208 else
209 strcpy (filespec_name (full_filename), tag_filename);
211 - if (!overwrite_all && (outfile = fopen (full_filename, "r")) != NULL) {
212 + if (!overwrite_all && (outfile = fopen_utf8 (full_filename, "r")) != NULL) {
213 DoCloseHandle (outfile);
214 fprintf (stderr, "overwrite %s (yes/no/all)? ", FN_FIT (full_filename));
216 @@ -1371,7 +1385,7 @@ static int do_tag_extractions (WavpackContext *wpc, char *outfilename)
217 // open output file for writing
219 if (*full_filename) {
220 - if ((outfile = fopen (full_filename, "w")) == NULL) {
221 + if ((outfile = fopen_utf8 (full_filename, "w")) == NULL) {
222 error_line ("can't create file %s!", FN_FIT (full_filename));
223 result = SOFT_ERROR;
225 @@ -1382,8 +1396,10 @@ static int do_tag_extractions (WavpackContext *wpc, char *outfilename)
226 error_line ("can't close file %s!", FN_FIT (full_filename));
227 result = SOFT_ERROR;
229 - else if (!quiet_mode)
230 - error_line ("extracted tag \"%s\" to file %s", extraction_spec, FN_FIT (full_filename));
231 + else if (!quiet_mode) {
232 + error_line("extracted tag \"%s\" to file %s", extraction_spec, FN_FIT(full_filename));
233 + fflush(stderr);
238 @@ -2060,3 +2076,30 @@ void display_progress (double file_progress)
239 DoSetConsoleTitle (title);
244 +//////////////////////////////////////////////////////////////////////////////
245 +// Entry Point
246 +//////////////////////////////////////////////////////////////////////////////
248 +int main(int argc, char **argv)
250 + int iResult = -1;
252 +#if defined (WIN32)
253 + int argc_utf8;
254 + char **argv_utf8;
256 + init_console_utf8();
257 + init_commandline_arguments_utf8(&argc_utf8, &argv_utf8);
259 + iResult = wvunpack_main(argc_utf8, argv_utf8);
261 + free_commandline_arguments_utf8(&argc_utf8, &argv_utf8);
262 + uninit_console_utf8();
263 +#else
264 + iResult = wvunpack_main(argc, argv);
265 +#endif
267 + return iResult;
269 diff --git a/src/unicode_support.c b/src/unicode_support.c
270 new file mode 100644
271 index 0000000..f057ac0
272 --- /dev/null
273 +++ b/src/unicode_support.c
274 @@ -0,0 +1,197 @@
275 +/* Copyright (c) 2004-2012 LoRd_MuldeR <mulder2@gmx.de>
276 + File: unicode_support.c
278 + This file was originally part of a patch included with LameXP,
279 + released under the same license as the original audio tools.
281 + Redistribution and use in source and binary forms, with or without
282 + modification, are permitted provided that the following conditions
283 + are met:
285 + - Redistributions of source code must retain the above copyright
286 + notice, this list of conditions and the following disclaimer.
288 + - Redistributions in binary form must reproduce the above copyright
289 + notice, this list of conditions and the following disclaimer in the
290 + documentation and/or other materials provided with the distribution.
292 + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
293 + ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
294 + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
295 + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR
296 + CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
297 + EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
298 + PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
299 + PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
300 + LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
301 + NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
302 + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
304 +#if defined WIN32 || defined _WIN32 || defined WIN64 || defined _WIN64
306 +#include "unicode_support.h"
308 +#include <windows.h>
309 +#include <io.h>
311 +static UINT g_old_output_cp = ((UINT)-1);
313 +char *utf16_to_utf8(const wchar_t *input)
315 + char *Buffer;
316 + int BuffSize = 0, Result = 0;
318 + BuffSize = WideCharToMultiByte(CP_UTF8, 0, input, -1, NULL, 0, NULL, NULL);
319 + Buffer = (char*) malloc(sizeof(char) * BuffSize);
320 + if(Buffer)
322 + Result = WideCharToMultiByte(CP_UTF8, 0, input, -1, Buffer, BuffSize, NULL, NULL);
325 + return ((Result > 0) && (Result <= BuffSize)) ? Buffer : NULL;
328 +char *utf16_to_ansi(const wchar_t *input)
330 + char *Buffer;
331 + int BuffSize = 0, Result = 0;
333 + BuffSize = WideCharToMultiByte(CP_ACP, 0, input, -1, NULL, 0, NULL, NULL);
334 + Buffer = (char*) malloc(sizeof(char) * BuffSize);
335 + if(Buffer)
337 + Result = WideCharToMultiByte(CP_ACP, 0, input, -1, Buffer, BuffSize, NULL, NULL);
340 + return ((Result > 0) && (Result <= BuffSize)) ? Buffer : NULL;
343 +wchar_t *utf8_to_utf16(const char *input)
345 + wchar_t *Buffer;
346 + int BuffSize = 0, Result = 0;
348 + BuffSize = MultiByteToWideChar(CP_UTF8, 0, input, -1, NULL, 0);
349 + Buffer = (wchar_t*) malloc(sizeof(wchar_t) * BuffSize);
350 + if(Buffer)
352 + Result = MultiByteToWideChar(CP_UTF8, 0, input, -1, Buffer, BuffSize);
355 + return ((Result > 0) && (Result <= BuffSize)) ? Buffer : NULL;
358 +void init_commandline_arguments_utf8(int *argc, char ***argv)
360 + int i, nArgs;
361 + LPWSTR *szArglist;
363 + szArglist = CommandLineToArgvW(GetCommandLineW(), &nArgs);
365 + if(NULL == szArglist)
367 + fprintf(stderr, "\nFATAL: CommandLineToArgvW failed\n\n");
368 + exit(-1);
371 + *argv = (char**) malloc(sizeof(char*) * nArgs);
372 + *argc = nArgs;
374 + if(NULL == *argv)
376 + fprintf(stderr, "\nFATAL: Malloc failed\n\n");
377 + exit(-1);
380 + for(i = 0; i < nArgs; i++)
382 + (*argv)[i] = utf16_to_utf8(szArglist[i]);
383 + if(NULL == (*argv)[i])
385 + fprintf(stderr, "\nFATAL: utf16_to_utf8 failed\n\n");
386 + exit(-1);
390 + LocalFree(szArglist);
393 +void free_commandline_arguments_utf8(int *argc, char ***argv)
395 + int i = 0;
397 + if(*argv != NULL)
399 + for(i = 0; i < *argc; i++)
401 + if((*argv)[i] != NULL)
403 + free((*argv)[i]);
404 + (*argv)[i] = NULL;
407 + free(*argv);
408 + *argv = NULL;
412 +FILE *fopen_utf8(const char *filename_utf8, const char *mode_utf8)
414 + FILE *ret = NULL;
415 + wchar_t *filename_utf16 = utf8_to_utf16(filename_utf8);
416 + wchar_t *mode_utf16 = utf8_to_utf16(mode_utf8);
418 + if(filename_utf16 && mode_utf16)
420 + ret = _wfopen(filename_utf16, mode_utf16);
423 + if(filename_utf16) free(filename_utf16);
424 + if(mode_utf16) free(mode_utf16);
426 + return ret;
429 +int stat_utf8(const char *path_utf8, struct _stat *buf)
431 + int ret = -1;
433 + wchar_t *path_utf16 = utf8_to_utf16(path_utf8);
434 + if(path_utf16)
436 + ret = _wstat(path_utf16, buf);
437 + free(path_utf16);
440 + return ret;
443 +int unlink_utf8(const char *path_utf8)
445 + int ret = -1;
447 + wchar_t *path_utf16 = utf8_to_utf16(path_utf8);
448 + if(path_utf16)
450 + ret = _wunlink(path_utf16);
451 + free(path_utf16);
454 + return ret;
457 +void init_console_utf8(void)
459 + g_old_output_cp = GetConsoleOutputCP();
460 + SetConsoleOutputCP(CP_UTF8);
463 +void uninit_console_utf8(void)
465 + if(g_old_output_cp != ((UINT)-1))
467 + SetConsoleOutputCP(g_old_output_cp);
471 +#endif
472 \ No newline at end of file
473 diff --git a/src/unicode_support.h b/src/unicode_support.h
474 new file mode 100644
475 index 0000000..cf55719
476 --- /dev/null
477 +++ b/src/unicode_support.h
478 @@ -0,0 +1,49 @@
479 +/* Copyright (c) 2004-2012 LoRd_MuldeR <mulder2@gmx.de>
480 + File: unicode_support.h
482 + This file was originally part of a patch included with LameXP,
483 + released under the same license as the original audio tools.
485 + Redistribution and use in source and binary forms, with or without
486 + modification, are permitted provided that the following conditions
487 + are met:
489 + - Redistributions of source code must retain the above copyright
490 + notice, this list of conditions and the following disclaimer.
492 + - Redistributions in binary form must reproduce the above copyright
493 + notice, this list of conditions and the following disclaimer in the
494 + documentation and/or other materials provided with the distribution.
496 + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
497 + ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
498 + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
499 + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR
500 + CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
501 + EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
502 + PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
503 + PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
504 + LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
505 + NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
506 + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
508 +#ifndef UNICODE_SUPPORT_H_INCLUDED
509 +#define UNICODE_SUPPORT_H_INCLUDED
511 +#include <stdio.h>
512 +#include <sys/stat.h>
514 +#define WIN_UNICODE 1
516 +char *utf16_to_utf8(const wchar_t *input);
517 +char *utf16_to_ansi(const wchar_t *input);
518 +wchar_t *utf8_to_utf16(const char *input);
519 +void init_commandline_arguments_utf8(int *argc, char ***argv);
520 +void free_commandline_arguments_utf8(int *argc, char ***argv);
521 +FILE *fopen_utf8(const char *filename_utf8, const char *mode_utf8);
522 +int stat_utf8(const char *path_utf8, struct _stat *buf);
523 +int unlink_utf8(const char *path_utf8);
524 +void init_console_utf8(void);
525 +void uninit_console_utf8(void);
527 +#endif
528 \ No newline at end of file
529 diff --git a/src/wputils.c b/src/wputils.c
530 index 5d30f1e..1aebbce 100644
531 --- a/src/wputils.c
532 +++ b/src/wputils.c
533 @@ -26,6 +26,7 @@
535 #if defined (WIN32) || defined (__OS2__)
536 #include <io.h>
537 +#include "unicode_support.h"
538 #endif
540 #ifndef LIBWAVPACK_VERSION_STRING
541 @@ -169,7 +170,7 @@ WavpackContext *WavpackOpenFileInput (const char *infilename, char *error, int f
542 setmode (fileno (stdin), O_BINARY);
543 #endif
545 - else if ((wv_id = fopen (infilename, file_mode)) == NULL) {
546 + else if ((wv_id = fopen_utf8 (infilename, file_mode)) == NULL) {
547 if (error) strcpy (error, (flags & OPEN_EDIT_TAGS) ? "can't open file for editing" : "can't open file");
548 return NULL;
550 @@ -179,7 +180,7 @@ WavpackContext *WavpackOpenFileInput (const char *infilename, char *error, int f
552 strcpy (in2filename, infilename);
553 strcat (in2filename, "c");
554 - wvc_id = fopen (in2filename, "rb");
555 + wvc_id = fopen_utf8 (in2filename, "rb");
556 free (in2filename);
558 else
560 \ No newline at end of file