OSDN Git Service

Update Chinese and Taiwanese translations. Thanks to 456Vv <123@456vv.com>.
[lamexp/LameXP.git] / etc / Patches / deprecated / SoX-v14.4.0rc3-MSVC10-UTF8.V1.diff
1  src/8svx.c            |    3 +-
2  src/adpcm.c           |    1 +
3  src/effects_i.c       |    3 +-
4  src/formats.c         |    9 ++-
5  src/libsox.c          |    2 +
6  src/libsox_i.c        |    7 +-
7  src/noiseprof.c       |    3 +-
8  src/sox.c             |   33 ++++++++---
9  src/unicode_support.c |  148 +++++++++++++++++++++++++++++++++++++++++++++++++
10  src/unicode_support.h |   16 +++++
11  src/util.h            |    5 ++
12  11 files changed, 211 insertions(+), 19 deletions(-)
13
14 diff --git a/src/8svx.c b/src/8svx.c
15 index 63c30e6..fd712f4 100644
16 --- a/src/8svx.c
17 +++ b/src/8svx.c
18 @@ -1,6 +1,7 @@
19  /* Amiga 8SVX format handler: W V Neisius, February 1992 */
20  
21  #include "sox_i.h"
22 +#include "unicode_support.h"
23  
24  #include <errno.h>
25  #include <string.h>
26 @@ -161,7 +162,7 @@ static int startread(sox_format_t * ft)
27          chan1_pos = lsx_tell(ft);
28  
29          for (i = 1; i < channels; i++) {
30 -                if ((p->ch[i] = fopen(ft->filename, "rb")) == NULL)
31 +                if ((p->ch[i] = fopen_utf8(ft->filename, "rb")) == NULL)
32                  {
33                          lsx_fail_errno(ft,errno,"Can't open channel file '%s'",
34                                  ft->filename);
35 diff --git a/src/adpcm.c b/src/adpcm.c
36 index 2e13867..15c27c2 100644
37 --- a/src/adpcm.c
38 +++ b/src/adpcm.c
39 @@ -33,6 +33,7 @@
40  
41  #include "sox_i.h"
42  #include "adpcm.h"
43 +#include "unicode_support.h"
44  
45  #include <sys/types.h>
46  #include <stdio.h>
47 diff --git a/src/effects_i.c b/src/effects_i.c
48 index 7d72166..65d6a0b 100644
49 --- a/src/effects_i.c
50 +++ b/src/effects_i.c
51 @@ -20,6 +20,7 @@
52  
53  #define LSX_EFF_ALIAS
54  #include "sox_i.h"
55 +#include "unicode_support.h"
56  #include <string.h>
57  #include <ctype.h>
58  
59 @@ -355,7 +356,7 @@ FILE * lsx_open_input_file(sox_effect_t * effp, char const * filename)
60      effp->global_info->global_info->stdin_in_use_by = effp->handler.name;
61      file = stdin;
62    }
63 -  else if (!(file = fopen(filename, "r"))) {
64 +  else if (!(file = fopen_utf8(filename, "r"))) {
65      lsx_fail("couldn't open file %s: %s", filename, strerror(errno));
66      return NULL;
67    }
68 diff --git a/src/formats.c b/src/formats.c
69 index cac686c..1baa213 100644
70 --- a/src/formats.c
71 +++ b/src/formats.c
72 @@ -19,6 +19,7 @@
73   */
74  
75  #include "sox_i.h"
76 +#include "unicode_support.h"
77  
78  #include <assert.h>
79  #include <ctype.h>
80 @@ -396,7 +397,7 @@ static FILE * xfopen(char const * identifier, char const * mode, lsx_io_type * i
81  #endif
82      return f;
83    }
84 -  return fopen(identifier, mode);
85 +  return fopen_utf8(identifier, mode);
86  }
87  
88  /* Hack to rewind pipes (a small amount).
89 @@ -847,8 +848,8 @@ static sox_format_t * open_write(
90        ft->fp = stdout;
91      }
92      else {
93 -      struct stat st;
94 -      if (!stat(path, &st) && (st.st_mode & S_IFMT) == S_IFREG &&
95 +      struct _stat st;
96 +      if (!stat_utf8(path, &st) && (st.st_mode & S_IFMT) == S_IFREG &&
97            (overwrite_permitted && !overwrite_permitted(path))) {
98          lsx_fail("permission to overwrite `%s' denied", path);
99          goto error;
100 @@ -858,7 +859,7 @@ static sox_format_t * open_write(
101          buffer? fmemopen(buffer, buffer_size, "w+b") :
102          buffer_ptr? open_memstream(buffer_ptr, buffer_size_ptr) :
103  #endif
104 -        fopen(path, "w+b");
105 +        fopen_utf8(path, "w+b");
106        if (ft->fp == NULL) {
107          lsx_fail("can't open output file `%s': %s", path, strerror(errno));
108          goto error;
109 diff --git a/src/libsox.c b/src/libsox.c
110 index 75354e4..a766aa9 100644
111 --- a/src/libsox.c
112 +++ b/src/libsox.c
113 @@ -19,6 +19,8 @@
114   */
115  
116  #include "sox_i.h"
117 +#include "unicode_support.h"
118 +
119  #include <string.h>
120  
121  const char *sox_version(void)
122 diff --git a/src/libsox_i.c b/src/libsox_i.c
123 index 8a7074a..b498cc0 100644
124 --- a/src/libsox_i.c
125 +++ b/src/libsox_i.c
126 @@ -20,6 +20,7 @@
127  
128  
129  #include "sox_i.h"
130 +#include "unicode_support.h"
131  
132  #ifdef HAVE_IO_H
133    #include <io.h>
134 @@ -48,8 +49,8 @@
135  #ifdef WIN32
136  static int check_dir(char * buf, size_t buflen, char const * name)
137  {
138 -  struct stat st;
139 -  if (!name || stat(name, &st) || (st.st_mode & S_IFMT) != S_IFDIR)
140 +  struct _stat st;
141 +  if (!name || stat_utf8(name, &st) || (st.st_mode & S_IFMT) != S_IFDIR)
142    {
143      return 0;
144    }
145 @@ -102,7 +103,7 @@ FILE * lsx_tmpfile(void)
146      fildes = mkstemp(name);
147  #ifdef HAVE_UNISTD_H
148      lsx_debug(FAKE_MKSTEMP "mkstemp, name=%s (unlinked)", name);
149 -    unlink(name);
150 +    unlink_utf8(name);
151  #else
152      lsx_debug(FAKE_MKSTEMP "mkstemp, name=%s (O_TEMPORARY)", name);
153  #endif
154 diff --git a/src/noiseprof.c b/src/noiseprof.c
155 index 603402f..d46c280 100644
156 --- a/src/noiseprof.c
157 +++ b/src/noiseprof.c
158 @@ -19,6 +19,7 @@
159   */
160  
161  #include "noisered.h"
162 +#include "unicode_support.h"
163  
164  #include <assert.h>
165  #include <string.h>
166 @@ -75,7 +76,7 @@ static int sox_noiseprof_start(sox_effect_t * effp)
167      effp->global_info->global_info->stdout_in_use_by = effp->handler.name;
168      data->output_file = stdout;
169    }
170 -  else if ((data->output_file = fopen(data->output_filename, "w")) == NULL) {
171 +  else if ((data->output_file = fopen_utf8(data->output_filename, "w")) == NULL) {
172      lsx_fail("Couldn't open profile file %s: %s", data->output_filename, strerror(errno));
173      return SOX_EOF;
174    }
175 diff --git a/src/sox.c b/src/sox.c
176 index 665149b..da43424 100644
177 --- a/src/sox.c
178 +++ b/src/sox.c
179 @@ -24,6 +24,7 @@
180  #include "soxconfig.h"
181  #include "sox.h"
182  #include "util.h"
183 +#include "unicode_support.h"
184  
185  #include <ctype.h>
186  #include <errno.h>
187 @@ -236,12 +237,12 @@ static void cleanup(void)
188    if (file_count) {
189      if (ofile->ft) {
190        if (!success && ofile->ft->fp) {   /* If we failed part way through */
191 -        struct stat st;                  /* writing a normal file, remove it. */
192 -        if (!stat(ofile->ft->filename, &st) &&
193 +        struct _stat st;                  /* writing a normal file, remove it. */
194 +        if (!stat_utf8(ofile->ft->filename, &st) &&
195              (st.st_mode & S_IFMT) == S_IFREG)
196 -          unlink(ofile->ft->filename);
197 +          unlink_utf8(ofile->ft->filename);
198        }
199 -      sox_close(ofile->ft); /* Assume we can unlink a file before closing it. */
200 +      sox_close(ofile->ft); /* Assume we can unlink_utf8 a file before closing it. */
201      }
202      free(ofile->filename);
203      free(ofile);
204 @@ -293,8 +294,8 @@ static char const * str_time(double seconds)
205  
206  static char const * size_and_bitrate(sox_format_t * ft, char const * * text)
207  {
208 -  struct stat st;    /* ft->fp may validly be NULL, so stat not fstat */
209 -  if (stat(ft->filename, &st) || (st.st_mode & S_IFMT) != S_IFREG)
210 +  struct _stat st;    /* ft->fp may validly be NULL, so stat not fstat */
211 +  if (stat_utf8(ft->filename, &st) || (st.st_mode & S_IFMT) != S_IFREG)
212      return NULL;
213    if (ft->signal.length && ft->signal.channels && ft->signal.rate && text) {
214      double secs = ft->signal.length / ft->signal.channels / ft->signal.rate;
215 @@ -906,7 +907,7 @@ static char * * strtoargv(char * s, int * argc)
216  
217  static void read_user_effects(char const *filename)
218  {
219 -    FILE *file = fopen(filename, "rt");
220 +    FILE *file = fopen_utf8(filename, "rt");
221      const size_t buffer_size_step = 1024;
222      size_t buffer_size = buffer_size_step;
223      char *s = lsx_malloc(buffer_size); /* buffer for one input line */
224 @@ -1269,6 +1270,7 @@ static void display_status(sox_bool all_done)
225        lsx_sigfigs3((double)output_samples),
226        vu(0), vu(1), headroom(), lsx_sigfigs3((double)total_clips()));
227    }
228 +  fflush(stderr);
229    if (all_done)
230      fputc('\n', stderr);
231  }
232 @@ -2123,7 +2125,7 @@ static void read_comment_file(sox_comments_t * comments, char const * const file
233    int c;
234    size_t text_length = 100;
235    char * text = lsx_malloc(text_length + 1);
236 -  FILE * file = fopen(filename, "rt");
237 +  FILE * file = fopen_utf8(filename, "rt");
238  
239    if (file == NULL) {
240      lsx_fail("Cannot open comment file `%s'", filename);
241 @@ -2830,7 +2832,7 @@ static sox_bool cmp_comment_text(char const * c1, char const * c2)
242    return c1 && c2 && !strcasecmp(c1, c2);
243  }
244  
245 -int main(int argc, char **argv)
246 +static int sox_main(int argc, char **argv)
247  {
248    size_t i;
249    char mybase[6];
250 @@ -3032,3 +3034,16 @@ int main(int argc, char **argv)
251  
252    return 0;
253  }
254 +
255 +int main( int argc, char **argv )
256 +{
257 +  int sox_argc;
258 +  char **sox_argv;
259 +  int exit_code;
260 +
261 +  init_commandline_arguments_utf8(&sox_argc, &sox_argv);
262 +  exit_code = sox_main(sox_argc, sox_argv);
263 +  free_commandline_arguments_utf8(&sox_argc, &sox_argv);
264 +
265 +  return exit_code;
266 +}
267 diff --git a/src/unicode_support.c b/src/unicode_support.c
268 new file mode 100644
269 index 0000000..e0cbbc9
270 --- /dev/null
271 +++ b/src/unicode_support.c
272 @@ -0,0 +1,148 @@
273 +#include "unicode_support.h"
274 +
275 +#include <windows.h>
276 +#include <io.h>
277 +
278 +char *utf16_to_utf8(const wchar_t *input)
279 +{
280 +       char *Buffer;
281 +       int BuffSize = 0, Result = 0;
282 +
283 +       BuffSize = WideCharToMultiByte(CP_UTF8, 0, input, -1, NULL, 0, NULL, NULL);
284 +       Buffer = (char*) malloc(sizeof(char) * BuffSize);
285 +       if(Buffer)
286 +       {
287 +               Result = WideCharToMultiByte(CP_UTF8, 0, input, -1, Buffer, BuffSize, NULL, NULL);
288 +       }
289 +
290 +       return ((Result > 0) && (Result <= BuffSize)) ? Buffer : NULL;
291 +}
292 +
293 +char *utf16_to_ansi(const wchar_t *input)
294 +{
295 +       char *Buffer;
296 +       int BuffSize = 0, Result = 0;
297 +
298 +       BuffSize = WideCharToMultiByte(CP_ACP, 0, input, -1, NULL, 0, NULL, NULL);
299 +       Buffer = (char*) malloc(sizeof(char) * BuffSize);
300 +       if(Buffer)
301 +       {
302 +               Result = WideCharToMultiByte(CP_ACP, 0, input, -1, Buffer, BuffSize, NULL, NULL);
303 +       }
304 +
305 +       return ((Result > 0) && (Result <= BuffSize)) ? Buffer : NULL;
306 +}
307 +
308 +wchar_t *utf8_to_utf16(const char *input)
309 +{
310 +       wchar_t *Buffer;
311 +       int BuffSize = 0, Result = 0;
312 +
313 +       BuffSize = MultiByteToWideChar(CP_UTF8, 0, input, -1, NULL, 0);
314 +       Buffer = (wchar_t*) malloc(sizeof(wchar_t) * BuffSize);
315 +       if(Buffer)
316 +       {
317 +               Result = MultiByteToWideChar(CP_UTF8, 0, input, -1, Buffer, BuffSize);
318 +       }
319 +
320 +       return ((Result > 0) && (Result <= BuffSize)) ? Buffer : NULL;
321 +}
322 +
323 +void init_commandline_arguments_utf8(int *argc, char ***argv)
324 +{
325 +       int i, nArgs;
326 +       LPWSTR *szArglist;
327 +
328 +       szArglist = CommandLineToArgvW(GetCommandLineW(), &nArgs);
329 +
330 +       if(NULL == szArglist)
331 +       {
332 +               fprintf(stderr, "\nFATAL: CommandLineToArgvW failed\n\n");
333 +               exit(-1);
334 +       }
335 +
336 +       *argv = (char**) malloc(sizeof(char*) * nArgs);
337 +       *argc = nArgs;
338 +
339 +       if(NULL == *argv)
340 +       {
341 +               fprintf(stderr, "\nFATAL: Malloc failed\n\n");
342 +               exit(-1);
343 +       }
344 +       
345 +       for(i = 0; i < nArgs; i++)
346 +       {
347 +               (*argv)[i] = utf16_to_utf8(szArglist[i]);
348 +               if(NULL == (*argv)[i])
349 +               {
350 +                       fprintf(stderr, "\nFATAL: utf16_to_utf8 failed\n\n");
351 +                       exit(-1);
352 +               }
353 +       }
354 +
355 +       LocalFree(szArglist);
356 +}
357 +
358 +void free_commandline_arguments_utf8(int *argc, char ***argv)
359 +{
360 +       int i = 0;
361 +       
362 +       if(*argv != NULL)
363 +       {
364 +               for(i = 0; i < *argc; i++)
365 +               {
366 +                       if((*argv)[i] != NULL)
367 +                       {
368 +                               free((*argv)[i]);
369 +                               (*argv)[i] = NULL;
370 +                       }
371 +               }
372 +               free(*argv);
373 +               *argv = NULL;
374 +       }
375 +}
376 +
377 +FILE *fopen_utf8(const char *filename_utf8, const char *mode_utf8)
378 +{
379 +       FILE *ret = NULL;
380 +       wchar_t *filename_utf16 = utf8_to_utf16(filename_utf8);
381 +       wchar_t *mode_utf16 = utf8_to_utf16(mode_utf8);
382 +       
383 +       if(filename_utf16 && mode_utf16)
384 +       {
385 +               ret = _wfopen(filename_utf16, mode_utf16);
386 +       }
387 +
388 +       if(filename_utf16) free(filename_utf16);
389 +       if(mode_utf16) free(mode_utf16);
390 +
391 +       return ret;
392 +}
393 +
394 +int stat_utf8(const char *path_utf8, struct _stat *buf)
395 +{
396 +       int ret = -1;
397 +       
398 +       wchar_t *path_utf16 = utf8_to_utf16(path_utf8);
399 +       if(path_utf16)
400 +       {
401 +               ret = _wstat(path_utf16, buf);
402 +               free(path_utf16);
403 +       }
404 +       
405 +       return ret;
406 +}
407 +
408 +int unlink_utf8(const char *path_utf8)
409 +{
410 +       int ret = -1;
411 +       
412 +       wchar_t *path_utf16 = utf8_to_utf16(path_utf8);
413 +       if(path_utf16)
414 +       {
415 +               ret = _wunlink(path_utf16);
416 +               free(path_utf16);
417 +       }
418 +       
419 +       return ret;
420 +}
421 diff --git a/src/unicode_support.h b/src/unicode_support.h
422 new file mode 100644
423 index 0000000..6775e00
424 --- /dev/null
425 +++ b/src/unicode_support.h
426 @@ -0,0 +1,16 @@
427 +#ifndef UNICODE_SUPPORT_H_INCLUDED
428 +#define UNICODE_SUPPORT_H_INCLUDED
429 +
430 +#include <stdio.h>
431 +#include <sys/stat.h>
432 +
433 +char *utf16_to_utf8(const wchar_t *input);
434 +char *utf16_to_ansi(const wchar_t *input);
435 +wchar_t *utf8_to_utf16(const char *input);
436 +void init_commandline_arguments_utf8(int *argc, char ***argv);
437 +void free_commandline_arguments_utf8(int *argc, char ***argv);
438 +FILE *fopen_utf8(const char *filename_utf8, const char *mode_utf8);
439 +int stat_utf8(const char *path_utf8, struct _stat *buf);
440 +int unlink_utf8(const char *path_utf8);
441 +
442 +#endif
443 \ No newline at end of file
444 diff --git a/src/util.h b/src/util.h
445 index f10b676..4a835f0 100644
446 --- a/src/util.h
447 +++ b/src/util.h
448 @@ -91,6 +91,10 @@
449  
450  #ifdef _MSC_VER
451  
452 +#define inline __inline
453 +#define snprintf _snprintf
454 +
455 +/*
456  #define __STDC__ 1
457  #define O_BINARY _O_BINARY
458  #define O_CREAT _O_CREAT
459 @@ -141,6 +145,7 @@
460  #define off_t __int64
461  #define HAVE_FSEEKO 1
462  #endif
463 +*/
464  
465  #elif defined(__MINGW32__)
466