OSDN Git Service

Updated OggEnc2 binaries to v2.87 using libvorbis v1.3.5 and aoTuV v6.03_2015 (2014...
[lamexp/LameXP.git] / etc / Patches / Aften-v0.0.8-UTF8.diff
1  aften/aften.c           |   23 ++++++++++-
2  aften/unicode_support.c |   98 +++++++++++++++++++++++++++++++++++++++++++++++
3  aften/unicode_support.h |   21 ++++++++++
4  libaften/a52.h          |    2 +-
5  4 files changed, 140 insertions(+), 4 deletions(-)
6
7 diff --git a/aften/aften.c b/aften/aften.c
8 index 143bb1c..a93da2f 100644
9 --- a/aften/aften.c
10 +++ b/aften/aften.c
11 @@ -38,6 +38,7 @@
12  #include "pcm.h"
13  #include "helptext.h"
14  #include "opts.h"
15 +#include "unicode_support.h"
16  
17  static const int acmod_to_ch[8] = { 2, 1, 2, 3, 3, 4, 4, 5 };
18  
19 @@ -82,7 +83,7 @@ print_simd_in_use(FILE *out, AftenSimdInstructions *simd_instructions)
20  }
21  
22  int
23 -main(int argc, char **argv)
24 +aften_main(int argc, char **argv)
25  {
26      void (*aften_remap)(void *samples, int n, int ch,
27                          A52SampleFormat fmt, int acmod) = NULL;
28 @@ -137,7 +138,7 @@ main(int argc, char **argv)
29  #endif
30              ifp[i] = stdin;
31          } else {
32 -            ifp[i] = fopen(opts.infile[i], "rb");
33 +            ifp[i] = fopen_utf8(opts.infile[i], "rb");
34              if (!ifp[i]) {
35                  fprintf(stderr, "error opening input file: %s\n", opts.infile[i]);
36                  goto error_end;
37 @@ -235,7 +236,7 @@ main(int argc, char **argv)
38  #endif
39          ofp = stdout;
40      } else {
41 -        ofp = fopen(opts.outfile, "wb");
42 +        ofp = fopen_utf8(opts.outfile, "wb");
43          if (!ofp) {
44              fprintf(stderr, "error opening output file: %s\n", opts.outfile);
45              goto error_end;
46 @@ -327,6 +328,7 @@ main(int argc, char **argv)
47                                      "bw: %2.1f | bitrate: %4.1f kbps ",
48                                      percent, (qual / (frame_cnt+1)),
49                                      (bw / (frame_cnt+1)), kbps);
50 +                            fflush(stderr);
51                          }
52                          t0 = t1;
53                          last_update_clock = current_clock;
54 @@ -335,6 +337,7 @@ main(int argc, char **argv)
55                      fprintf(stderr, "frame: %7d | q: %4d | bw: %2d | bitrate: %3d kbps\n",
56                              frame_cnt, s.status.quality, s.status.bwcode,
57                              s.status.bit_rate);
58 +                    fflush(stderr);
59                  }
60              }
61              fwrite(frame, 1, fs, ofp);
62 @@ -352,11 +355,13 @@ main(int argc, char **argv)
63          if (s.verbose == 1) {
64              fprintf(stderr, "\rprogress: 100%% | q: %4.1f | bw: %2.1f | bitrate: %4.1f kbps\n\n",
65                      (qual / frame_cnt), (bw / frame_cnt), kbps);
66 +            fflush(stderr);
67          } else if (s.verbose == 2) {
68              fprintf(stderr, "\n");
69              fprintf(stderr, "average quality:   %4.1f\n", (qual / frame_cnt));
70              fprintf(stderr, "average bandwidth: %2.1f\n", (bw / frame_cnt));
71              fprintf(stderr, "average bitrate:   %4.1f kbps\n\n", kbps);
72 +            fflush(stderr);
73          }
74      }
75      goto end;
76 @@ -382,3 +387,15 @@ end:
77  
78      return ret_val;
79  }
80 +
81 +int wmain(int argc, wchar_t **argv_utf16)
82 +{
83 +  int result = 0;
84 +  char **argv_utf8 = NULL;
85 +
86 +  init_commandline_arguments_utf8(argc, &argv_utf8, argv_utf16);
87 +  result = aften_main(argc, argv_utf8);
88 +  free_commandline_arguments_utf8(argc, &argv_utf8);
89 +  
90 +  return result;
91 +}
92 diff --git a/aften/unicode_support.c b/aften/unicode_support.c
93 new file mode 100644
94 index 0000000..21ecd5c
95 --- /dev/null
96 +++ b/aften/unicode_support.c
97 @@ -0,0 +1,98 @@
98 +#include "unicode_support.h"
99 +
100 +#include <stdio.h>
101 +#include <windows.h>
102 +
103 +char *utf16_to_utf8(const wchar_t *input)
104 +{
105 +       char *Buffer;
106 +       int BuffSize, Result;
107 +
108 +       BuffSize = WideCharToMultiByte(CP_UTF8, 0, input, -1, NULL, 0, NULL, NULL);
109 +       Buffer = (char*) malloc(sizeof(char) * BuffSize);
110 +       
111 +       if(!Buffer)
112 +       {
113 +               fprintf(stderr, "Error in utf16_to_utf8: Memory allocation failed!\n");
114 +               return NULL;
115 +       }
116 +
117 +       Result = WideCharToMultiByte(CP_UTF8, 0, input, -1, Buffer, BuffSize, NULL, NULL);
118 +       return ((Result > 0) && (Result <= BuffSize)) ? Buffer : NULL;
119 +}
120 +
121 +wchar_t *utf8_to_utf16(const char *input)
122 +{
123 +       wchar_t *Buffer;
124 +       int BuffSize, Result;
125 +
126 +       BuffSize = MultiByteToWideChar(CP_UTF8, 0, input, -1, NULL, 0);
127 +       Buffer = (wchar_t*) malloc(sizeof(wchar_t) * BuffSize);
128 +
129 +       if(!Buffer)
130 +       {
131 +               fprintf(stderr, "Error in utf8_to_utf16: Memory allocation failed!\n");
132 +               return NULL;
133 +       }
134 +
135 +       Result = MultiByteToWideChar(CP_UTF8, 0, input, -1, Buffer, BuffSize);
136 +       return ((Result > 0) && (Result <= BuffSize)) ? Buffer : NULL;
137 +}
138 +
139 +void init_commandline_arguments_utf8(int argc, char ***argv_utf8, wchar_t **argv_utf16)
140 +{
141 +       int i = 0;
142 +       
143 +       *argv_utf8 = (char**) malloc(argc * sizeof(char*));
144 +       if(!(*argv_utf8))
145 +       {
146 +               fprintf(stderr, "Error in init_commandline_arguments_utf8: Memory allocation failed!\n");
147 +               exit(-1);
148 +       }
149 +       
150 +       for(i = 0; i < argc; i++)
151 +       {
152 +               (*argv_utf8)[i] = utf16_to_utf8(argv_utf16[i]);
153 +               if(!(*argv_utf8)[i])
154 +               {
155 +                       fprintf(stderr, "Error in init_commandline_arguments_utf8: Memory allocation failed!\n");
156 +                       exit(-1);
157 +               }
158 +       }
159 +}
160 +
161 +void free_commandline_arguments_utf8(int argc, char ***argv_utf8)
162 +{
163 +       int i = 0;
164 +       
165 +       if(*argv_utf8 != NULL)
166 +       {
167 +               for(i = 0; i < argc; i++)
168 +               {
169 +                       if((*argv_utf8)[i] != NULL)
170 +                       {
171 +                               free((*argv_utf8)[i]);
172 +                               (*argv_utf8)[i] = NULL;
173 +                       }
174 +               }
175 +               free(*argv_utf8);
176 +               *argv_utf8 = NULL;
177 +       }
178 +}
179 +
180 +FILE *fopen_utf8(const char *filename_utf8, const char *mode_utf8)
181 +{
182 +       FILE *ret = NULL;
183 +       wchar_t *filename_utf16 = utf8_to_utf16(filename_utf8);
184 +       wchar_t *mode_utf16 = utf8_to_utf16(mode_utf8);
185 +       
186 +       if(filename_utf16 && mode_utf16)
187 +       {
188 +               ret = _wfopen(filename_utf16, mode_utf16);
189 +       }
190 +
191 +       if(filename_utf16) free(filename_utf16);
192 +       if(mode_utf16) free(mode_utf16);
193 +
194 +       return ret;
195 +}
196 diff --git a/aften/unicode_support.h b/aften/unicode_support.h
197 new file mode 100644
198 index 0000000..cc13fd9
199 --- /dev/null
200 +++ b/aften/unicode_support.h
201 @@ -0,0 +1,21 @@
202 +#ifndef UNICODE_SUPPORT_H_INCLUDED
203 +#define UNICODE_SUPPORT_H_INCLUDED
204 +
205 +#include <ctype.h>
206 +#include <stdio.h>
207 +#include <stdlib.h>
208 +
209 +#ifdef __cplusplus
210 +extern "C" {
211 +#endif
212 +
213 +char *utf16_to_utf8(const wchar_t *input);
214 +wchar_t *utf8_to_utf16(const char *input);
215 +void init_commandline_arguments_utf8(int argc, char ***argv_utf8, wchar_t **argv_utf16);
216 +void free_commandline_arguments_utf8(int argc, char ***argv_utf8);
217 +FILE *fopen_utf8(const char *filename_utf8, const char *mode_utf8);
218 +
219 +#ifdef __cplusplus
220 +}
221 +#endif
222 +#endif
223 \ No newline at end of file
224 diff --git a/libaften/a52.h b/libaften/a52.h
225 index 9a6812b..85c6fa5 100644
226 --- a/libaften/a52.h
227 +++ b/libaften/a52.h
228 @@ -32,7 +32,7 @@
229  #include "a52tab.h"
230  #include "aften-types.h"
231  
232 -#define AFTEN_VERSION "git"
233 +#define AFTEN_VERSION "0.0.8+"
234  
235  #define A52_MAX_CHANNELS 6
236