1 frontend/audio.c | 7 +-
2 frontend/main.c | 34 ++++++---
3 frontend/mp4read.c | 7 +-
4 frontend/unicode_support.c | 172 +++++++++++++++++++++++++++++++++++++++++++++
5 frontend/unicode_support.h | 50 +++++++++++++
6 5 files changed, 258 insertions(+), 12 deletions(-)
8 diff --git a/frontend/audio.c b/frontend/audio.c
9 index 9ab7a2a..0d94c18 100644
10 --- a/frontend/audio.c
11 +++ b/frontend/audio.c
17 +#include "unicode_support.h"
22 @@ -74,13 +77,13 @@ audio_file *open_audio_file(char *infile, int samplerate, int channels,
26 - setmode(fileno(stdout), O_BINARY);
27 + _setmode(_fileno(stdout), O_BINARY);
29 aufile->sndfile = stdout;
33 - aufile->sndfile = fopen(infile, "wb");
34 + aufile->sndfile = faad_fopen(infile, "wb");
37 if (aufile->sndfile == NULL)
38 diff --git a/frontend/main.c b/frontend/main.c
39 index deaa039..d433253 100644
44 #define WIN32_LEAN_AND_MEAN
50 +#include "unicode_support.h"
54 @@ -479,7 +481,7 @@ static int decodeAACfile(char *aacfile, char *sndfile, char *adts_fn, int to_std
58 - adtsFile = fopen(adts_fn, "wb");
59 + adtsFile = faad_fopen(adts_fn, "wb");
62 faad_fprintf(stderr, "Error opening file: %s\n", adts_fn);
63 @@ -491,12 +493,12 @@ static int decodeAACfile(char *aacfile, char *sndfile, char *adts_fn, int to_std
67 - setmode(fileno(stdin), O_BINARY);
68 + _setmode(_fileno(stdin), O_BINARY);
73 - b.infile = fopen(aacfile, "rb");
74 + b.infile = faad_fopen(aacfile, "rb");
77 /* unable to open file */
78 @@ -833,7 +835,7 @@ static int decodeMP4file(char *mp4file, char *sndfile, char *adts_fn, int to_std
82 - adtsFile = fopen(adts_fn, "wb");
83 + adtsFile = faad_fopen(adts_fn, "wb");
86 faad_fprintf(stderr, "Error opening file: %s\n", adts_fn);
87 @@ -953,7 +955,7 @@ static int decodeMP4file(char *mp4file, char *sndfile, char *adts_fn, int to_std
88 outputFormat, fileType, aacChannelConfig2wavexChannelMask(&frameInfo));
91 - setmode(fileno(stdout), O_BINARY);
92 + _setmode(_fileno(stdout), O_BINARY);
94 aufile = open_audio_file("-", frameInfo.samplerate, frameInfo.channels,
95 outputFormat, fileType, aacChannelConfig2wavexChannelMask(&frameInfo));
96 @@ -1007,7 +1009,7 @@ static int decodeMP4file(char *mp4file, char *sndfile, char *adts_fn, int to_std
97 return frameInfo.error;
100 -int main(int argc, char *argv[])
101 +static int faad_main(int argc, char *argv[])
105 @@ -1265,13 +1267,13 @@ int main(int argc, char *argv[])
109 - setmode(fileno(stdin), O_BINARY);
110 + _setmode(_fileno(stdin), O_BINARY);
116 - hMP4File = fopen(aacFileName, "rb");
117 + hMP4File = faad_fopen(aacFileName, "rb");
120 faad_fprintf(stderr, "Error opening file: %s\n", aacFileName);
121 @@ -1338,3 +1340,19 @@ int main(int argc, char *argv[])
126 +int main(int argc, char *argv[])
129 + int argc_utf8, exit_code;
131 + init_console_utf8(stderr);
132 + init_commandline_arguments_utf8(&argc_utf8, &argv_utf8);
133 + exit_code = faad_main(argc_utf8, argv_utf8);
134 + free_commandline_arguments_utf8(&argc_utf8, &argv_utf8);
135 + uninit_console_utf8();
138 + return faad_main(argc, argv);
141 \ No newline at end of file
142 diff --git a/frontend/mp4read.c b/frontend/mp4read.c
143 index c8ca530..be8d591 100644
144 --- a/frontend/mp4read.c
145 +++ b/frontend/mp4read.c
151 +#include "unicode_support.h"
156 @@ -939,7 +942,7 @@ int mp4read_seek(int framenum)
158 static void mp4info(void)
160 - fprintf(stderr, "Modification Time:\t\%s", mp4time(mp4config.mtime));
161 + fprintf(stderr, "Modification Time:\t\t%s", mp4time(mp4config.mtime));
162 fprintf(stderr, "Samplerate:\t\t%d\n", mp4config.samplerate);
163 fprintf(stderr, "Total samples:\t\t%d\n", mp4config.samples);
164 fprintf(stderr, "Total channels:\t\t%d\n", mp4config.channels);
165 @@ -970,7 +973,7 @@ int mp4read_open(char *name)
169 - g_fin = fopen(name, "rb");
170 + g_fin = faad_fopen(name, "rb");
174 diff --git a/frontend/unicode_support.c b/frontend/unicode_support.c
176 index 0000000..96ea5a4
178 +++ b/frontend/unicode_support.c
180 +/* Copyright (c) 2004-2012 LoRd_MuldeR <mulder2@gmx.de>
181 + File: unicode_support.c
183 + This file was originally part of a patch included with LameXP,
184 + released under the same license as the original audio tools.
186 + Redistribution and use in source and binary forms, with or without
187 + modification, are permitted provided that the following conditions
190 + - Redistributions of source code must retain the above copyright
191 + notice, this list of conditions and the following disclaimer.
193 + - Redistributions in binary form must reproduce the above copyright
194 + notice, this list of conditions and the following disclaimer in the
195 + documentation and/or other materials provided with the distribution.
197 + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
198 + ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
199 + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
200 + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR
201 + CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
202 + EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
203 + PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
204 + PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
205 + LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
206 + NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
207 + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
209 +#if defined WIN32 || defined _WIN32 || defined WIN64 || defined _WIN64
211 +#include "unicode_support.h"
213 +#include <windows.h>
216 +static UINT g_old_output_cp = ((UINT)-1);
218 +char *utf16_to_utf8(const wchar_t *input)
221 + int BuffSize = 0, Result = 0;
223 + BuffSize = WideCharToMultiByte(CP_UTF8, 0, input, -1, NULL, 0, NULL, NULL);
224 + Buffer = (char*) malloc(sizeof(char) * BuffSize);
227 + Result = WideCharToMultiByte(CP_UTF8, 0, input, -1, Buffer, BuffSize, NULL, NULL);
230 + return ((Result > 0) && (Result <= BuffSize)) ? Buffer : NULL;
233 +char *utf16_to_ansi(const wchar_t *input)
236 + int BuffSize = 0, Result = 0;
238 + BuffSize = WideCharToMultiByte(CP_ACP, 0, input, -1, NULL, 0, NULL, NULL);
239 + Buffer = (char*) malloc(sizeof(char) * BuffSize);
242 + Result = WideCharToMultiByte(CP_ACP, 0, input, -1, Buffer, BuffSize, NULL, NULL);
245 + return ((Result > 0) && (Result <= BuffSize)) ? Buffer : NULL;
248 +wchar_t *utf8_to_utf16(const char *input)
251 + int BuffSize = 0, Result = 0;
253 + BuffSize = MultiByteToWideChar(CP_UTF8, 0, input, -1, NULL, 0);
254 + Buffer = (wchar_t*) malloc(sizeof(wchar_t) * BuffSize);
257 + Result = MultiByteToWideChar(CP_UTF8, 0, input, -1, Buffer, BuffSize);
260 + return ((Result > 0) && (Result <= BuffSize)) ? Buffer : NULL;
263 +void init_commandline_arguments_utf8(int *argc, char ***argv)
268 + szArglist = CommandLineToArgvW(GetCommandLineW(), &nArgs);
270 + if(NULL == szArglist)
272 + fprintf(stderr, "\nFATAL: CommandLineToArgvW failed\n\n");
276 + *argv = (char**) malloc(sizeof(char*) * nArgs);
281 + fprintf(stderr, "\nFATAL: Malloc failed\n\n");
285 + for(i = 0; i < nArgs; i++)
287 + (*argv)[i] = utf16_to_utf8(szArglist[i]);
288 + if(NULL == (*argv)[i])
290 + fprintf(stderr, "\nFATAL: utf16_to_utf8 failed\n\n");
295 + LocalFree(szArglist);
298 +void free_commandline_arguments_utf8(int *argc, char ***argv)
304 + for(i = 0; i < *argc; i++)
306 + if((*argv)[i] != NULL)
317 +FILE *fopen_utf8(const char *filename_utf8, const char *mode_utf8)
320 + wchar_t *filename_utf16 = utf8_to_utf16(filename_utf8);
321 + wchar_t *mode_utf16 = utf8_to_utf16(mode_utf8);
323 + if(filename_utf16 && mode_utf16)
325 + ret = _wfopen(filename_utf16, mode_utf16);
328 + if(filename_utf16) free(filename_utf16);
329 + if(mode_utf16) free(mode_utf16);
334 +void init_console_utf8(FILE *const stream)
336 + if (_isatty(_fileno(stream)))
338 + g_old_output_cp = GetConsoleOutputCP();
339 + SetConsoleOutputCP(CP_UTF8);
343 +void uninit_console_utf8(void)
345 + if(g_old_output_cp != ((UINT)-1))
347 + SetConsoleOutputCP(g_old_output_cp);
352 \ No newline at end of file
353 diff --git a/frontend/unicode_support.h b/frontend/unicode_support.h
355 index 0000000..eb21877
357 +++ b/frontend/unicode_support.h
359 +/* Copyright (c) 2004-2012 LoRd_MuldeR <mulder2@gmx.de>
360 + File: unicode_support.h
362 + This file was originally part of a patch included with LameXP,
363 + released under the same license as the original audio tools.
365 + Redistribution and use in source and binary forms, with or without
366 + modification, are permitted provided that the following conditions
369 + - Redistributions of source code must retain the above copyright
370 + notice, this list of conditions and the following disclaimer.
372 + - Redistributions in binary form must reproduce the above copyright
373 + notice, this list of conditions and the following disclaimer in the
374 + documentation and/or other materials provided with the distribution.
376 + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
377 + ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
378 + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
379 + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR
380 + CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
381 + EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
382 + PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
383 + PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
384 + LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
385 + NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
386 + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
388 +#ifndef UNICODE_SUPPORT_H_INCLUDED
389 +#define UNICODE_SUPPORT_H_INCLUDED
393 +char *utf16_to_utf8(const wchar_t *input);
394 +char *utf16_to_ansi(const wchar_t *input);
395 +wchar_t *utf8_to_utf16(const char *input);
396 +void init_commandline_arguments_utf8(int *argc, char ***argv);
397 +void free_commandline_arguments_utf8(int *argc, char ***argv);
398 +FILE *fopen_utf8(const char *filename_utf8, const char *mode_utf8);
399 +void init_console_utf8(FILE *const stream);
400 +void uninit_console_utf8(void);
403 +#define faad_fopen(X,Y) fopen_utf8((X),(Y))
405 +#define faad_fopen(X,Y) fopen((X),(Y))
408 +#endif //UNICODE_SUPPORT_H_INCLUDED