ref: c7c73fe5c313242e4ec4ff26c63af39ab9af276d
parent: 2081ac9dac4f4830ffb5cbce1024ba270478a77d
author: lordmulder <[email protected]>
date: Sun Jul 22 12:23:59 EDT 2012
More Win32 unicode support and display fixes.
--- a/src/opusdec.c
+++ b/src/opusdec.c
@@ -878,8 +878,13 @@
if(!quiet){
static const char spinner[]="|/-\\";
- if(!(last_spin % 100)) {
- fprintf(stderr,"[%c]\b\b\b", spinner[(last_spin/100) % 3]);
+ if(!(last_spin % 128)) {
+ unsigned int sec, min, hrs;
+ unsigned int total_secs = (unsigned int)(audio_size / (((ogg_int64_t) channels) * ((ogg_int64_t) rate) * ((ogg_int64_t) 2)));
+ hrs = total_secs / 3600;
+ min = (total_secs % 3600) / 60;
+ sec = (total_secs % 3600) % 60;
+ fprintf(stderr,"[%c] %02u:%02u:%02u\r", spinner[(last_spin/128) % 4], hrs, min, sec);
fflush(stderr);
}
last_spin++;
@@ -952,7 +957,7 @@
}
if (feof(fin)) {
if(!quiet) {
- fprintf(stderr, "Complete.\n");
+ fprintf(stderr, "Decoding complete.\n");
fflush(stderr);
}
break;
--- a/src/opusinfo.c
+++ b/src/opusinfo.c
@@ -31,6 +31,12 @@
#include "opus_header.h"
#include "info_opus.h"
+#if defined WIN32 || defined _WIN32 || defined WIN64 || defined _WIN64
+# include "unicode_support.h"
+#else
+# define fopen_utf8(_x,_y) fopen((_x),(_y))
+#endif
+
#define CHUNK 4500
static int printlots = 0;
@@ -465,7 +471,7 @@
}
static void process_file(char *filename) {
- FILE *file = fopen(filename, "rb");
+ FILE *file = fopen_utf8(filename, "rb");
ogg_sync_state ogsync;
ogg_page page;
stream_set *processors = create_stream_set();
@@ -583,7 +589,12 @@
printf (_("\t-V Output version information and exit.\n"));
}
-int main(int argc, char **argv) {
+#ifdef WIN_UNICODE
+static int opusinfo_main(int argc, char **argv)
+#else
+int main(int argc, char **argv)
+#endif
+{
int f, ret;
if(argc < 2) {
@@ -637,3 +648,18 @@
return ret;
}
+
+#ifdef WIN_UNICODE
+int main( int argc, char **argv )
+{
+ int my_argc;
+ char **my_argv;
+ int exit_code;
+
+ init_commandline_arguments_utf8(&my_argc, &my_argv);
+ exit_code = opusinfo_main(my_argc, my_argv);
+ free_commandline_arguments_utf8(&my_argc, &my_argv);
+
+ return exit_code;
+}
+#endif
\ No newline at end of file
--- a/src/opusinfo.vcxproj
+++ b/src/opusinfo.vcxproj
@@ -30,6 +30,7 @@
<ClCompile Include="resample.c" />
<ClCompile Include="wave_out.c" />
<ClCompile Include="wav_io.c" />
+ <ClCompile Include="..\win32\unicode_support.c" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\win32\config.h" />
@@ -46,6 +47,7 @@
<ClInclude Include="stack_alloc.h" />
<ClInclude Include="wave_out.h" />
<ClInclude Include="wav_io.h" />
+ <ClInclude Include="..\win32\unicode_support.h" />
</ItemGroup>
<PropertyGroup Label="Globals">
<Keyword>Win32Proj</Keyword>
--- a/win32/unicode_support.c
+++ b/win32/unicode_support.c
@@ -34,6 +34,8 @@
#include <windows.h>
#include <io.h>
+static UINT g_old_output_cp = ((UINT)-1);
+
char *utf16_to_utf8(const wchar_t *input)
{
char *Buffer;
@@ -176,6 +178,20 @@
}
return ret;
+}
+
+void init_console_utf8(void)
+{
+ g_old_output_cp = GetConsoleOutputCP();
+ SetConsoleOutputCP(CP_UTF8);
+}
+
+void uninit_console_utf8(void)
+{
+ if(g_old_output_cp != ((UINT)-1))
+ {
+ SetConsoleOutputCP(g_old_output_cp);
+ }
}
#endif
\ No newline at end of file
--- a/win32/unicode_support.h
+++ b/win32/unicode_support.h
@@ -43,5 +43,7 @@
FILE *fopen_utf8(const char *filename_utf8, const char *mode_utf8);
int stat_utf8(const char *path_utf8, struct _stat *buf);
int unlink_utf8(const char *path_utf8);
+void init_console_utf8(void);
+void uninit_console_utf8(void);
#endif
\ No newline at end of file