From fbc60f908905b720ff14b3a6fd8cdb98ffb1adcb Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Wed, 21 May 2003 21:05:47 +0000 Subject: [PATCH] UTFstring / C string conversion. Proper version numbers are written to the KaxInfos. --- ChangeLog | 5 +++++ common.cpp | 46 +++++++++++++++++++++++++++++++++++++++++++++- common.h | 7 ++++++- mkvmerge.cpp | 7 ++++--- 4 files changed, 60 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index c634ddccc..5ff3769fa 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2003-05-21 Moritz Bunkus + + * Some internal changes and enhancements. Code requires libebml + and libmatroska 0.4.3 now. + 2003-05-19 Moritz Bunkus * ADTS headers are stripped from the AAC streams. This is what I'd diff --git a/common.cpp b/common.cpp index bff590be8..37e45b372 100644 --- a/common.cpp +++ b/common.cpp @@ -13,7 +13,7 @@ /*! \file - \version \$Id: common.cpp,v 1.23 2003/05/19 18:24:52 mosu Exp $ + \version \$Id: common.cpp,v 1.24 2003/05/21 21:05:47 mosu Exp $ \brief helper functions, common variables \author Moritz Bunkus */ @@ -343,3 +343,47 @@ void *_saferealloc(void *mem, size_t size, const char *file, int line) { return mem; } + +/* + * UTFstring <-> C string conversion + */ + +UTFstring cstr_to_UTFstring(const char *c) { +#ifdef NO_WSTRING + return UTFstring(c); +#else + wchar_t *new_string; + const char *sptr; + UTFstring u; + int len; + + len = strlen(c); + new_string = (wchar_t *)safemalloc((len + 1) * sizeof(wchar_t)); + memset(new_string, 0, (len + 1) * sizeof(wchar_t)); + new_string[len] = L'\0'; + sptr = c; + mbsrtowcs(new_string, &sptr, len, NULL); + u = UTFstring(new_string); + safefree(new_string); + + return u; +#endif +} + +char *UTFstring_to_cstr(const UTFstring &u) { +#ifdef NO_WSTRING + return safestrdup(u.c_str()); +#else + const wchar_t *sptr; + char *new_string; + int len; + + len = u.size(); + new_string = (char *)safemalloc(len * 4 + 1); + memset(new_string, 0, len * 4 + 1); + sptr = u.c_str(); + wcsrtombs(new_string, &sptr, len, NULL); + + return new_string; +#endif +} diff --git a/common.h b/common.h index 9494524ae..eae2dab65 100644 --- a/common.h +++ b/common.h @@ -13,7 +13,7 @@ /*! \file - \version \$Id: common.h,v 1.27 2003/05/20 06:30:24 mosu Exp $ + \version \$Id: common.h,v 1.28 2003/05/21 21:05:47 mosu Exp $ \brief definitions used in all programs, helper functions \author Moritz Bunkus */ @@ -36,6 +36,8 @@ #define nice(a) #endif +#include "EbmlUnicodeString.h" + #include "config.h" #define VERSIONINFO "mkvmerge v" VERSION @@ -105,6 +107,9 @@ void *_safememdup(const void *src, size_t size, const char *file, int line); #define saferealloc(mem, size) _saferealloc(mem, size, __FILE__, __LINE__) void *_saferealloc(void *mem, size_t size, const char *file, int line); +UTFstring cstr_to_UTFstring(const char *c); +char *UTFstring_to_cstr(const UTFstring &u); + extern int verbose; class bit_cursor_c { diff --git a/mkvmerge.cpp b/mkvmerge.cpp index f9f8bea7b..3a27073c6 100644 --- a/mkvmerge.cpp +++ b/mkvmerge.cpp @@ -13,7 +13,7 @@ /*! \file - \version \$Id: mkvmerge.cpp,v 1.70 2003/05/21 19:55:49 mosu Exp $ + \version \$Id: mkvmerge.cpp,v 1.71 2003/05/21 21:05:47 mosu Exp $ \brief command line parameter parsing, looping, output handling \author Moritz Bunkus */ @@ -583,10 +583,11 @@ static void render_headers(mm_io_callback *out) { kax_duration = &GetChild(*kax_infos); *(static_cast(kax_duration)) = 0.0; + string version = string("libmatroska ") + KaxCodeVersion; *((EbmlUnicodeString *)&GetChild(*kax_infos)) = - L"libmatroska 0.4.3"; + cstr_to_UTFstring(version.c_str()); *((EbmlUnicodeString *)&GetChild(*kax_infos)) = - L"mkvmerge 0.3.4"; + cstr_to_UTFstring(VERSIONINFO); #if LIBEBML_VERSION >= 000403 kax_segment->WriteHead(*out, 5);