diff --git a/src/common/chapter_parser_cue.cpp b/src/common/chapter_parser_cue.cpp index 2f2a3674c..6fefb7479 100644 --- a/src/common/chapter_parser_cue.cpp +++ b/src/common/chapter_parser_cue.cpp @@ -374,7 +374,7 @@ parse_cue_chapters(mm_text_io_c *in, if (in->get_byte_order() == BO_NONE) { a.do_convert = true; - a.cc_utf8 = utf8_init(charset.c_str()); + a.cc_utf8 = utf8_init(charset); } else { a.do_convert = false; diff --git a/src/common/chapters.cpp b/src/common/chapters.cpp index 1ba52859e..0d6a1bae8 100644 --- a/src/common/chapters.cpp +++ b/src/common/chapters.cpp @@ -214,7 +214,7 @@ parse_simple_chapters(mm_text_io_c *in, if (in->get_byte_order() == BO_NONE) { do_convert = true; - cc_utf8 = utf8_init(charset.c_str()); + cc_utf8 = utf8_init(charset); } else do_convert = false; diff --git a/src/common/common.cpp b/src/common/common.cpp index f94c44fe8..5a1ac76be 100644 --- a/src/common/common.cpp +++ b/src/common/common.cpp @@ -541,12 +541,12 @@ add_kax_conv(const char *charset, } int -utf8_init(const char *charset) { +utf8_init(const string &charset) { string lc_charset; iconv_t ict_from_utf8, ict_to_utf8; int i; - if ((charset == NULL) || (*charset == 0)) { + if (charset == "") { setlocale(LC_CTYPE, ""); #if defined(COMP_MINGW) || defined(COMP_MSC) lc_charset = "CP" + to_string(GetACP()); diff --git a/src/common/common.h b/src/common/common.h index 15139b72f..2f02d869b 100644 --- a/src/common/common.h +++ b/src/common/common.h @@ -152,7 +152,7 @@ void MTX_DLL_API put_uint64_be(void *buf, uint64_t value); extern int MTX_DLL_API cc_local_utf8; -int MTX_DLL_API utf8_init(const char *charset); +int MTX_DLL_API utf8_init(const string &charset); void MTX_DLL_API utf8_done(); char *MTX_DLL_API to_utf8_c(int handle, const char *local); inline char * diff --git a/src/extract/mkvextract.cpp b/src/extract/mkvextract.cpp index 3bb15f9a0..f0102a1af 100644 --- a/src/extract/mkvextract.cpp +++ b/src/extract/mkvextract.cpp @@ -252,7 +252,7 @@ parse_args(int argc, if ((i + 1) >= argc) mxerror(_("'-c' lacks a charset.\n")); - conv_handle = utf8_init(argv[i + 1]); + conv_handle = utf8_init(argv[i + 1] == NULL ? "" : argv[i + 1]); sub_charset = argv[i + 1]; i++; @@ -405,7 +405,7 @@ main(int argc, #endif srand(time(NULL)); - utf8_init(NULL); + utf8_init(""); conv_utf8 = utf8_init("UTF-8"); xml_element_map_init(); diff --git a/src/info/mkvinfo.cpp b/src/info/mkvinfo.cpp index 30af9fbe7..baff652e7 100644 --- a/src/info/mkvinfo.cpp +++ b/src/info/mkvinfo.cpp @@ -1891,7 +1891,7 @@ setup() { textdomain("mkvtoolnix"); #endif - cc_local_utf8 = utf8_init(NULL); + cc_local_utf8 = utf8_init(""); xml_element_map_init(); } diff --git a/src/input/r_ssa.cpp b/src/input/r_ssa.cpp index 41717753b..b32f4d25d 100644 --- a/src/input/r_ssa.cpp +++ b/src/input/r_ssa.cpp @@ -82,7 +82,8 @@ ssa_reader_c::ssa_reader_c(track_info_c *nti) for (i = 0; i < ti->sub_charsets->size(); i++) if ((*ti->sub_charsets)[i].id == 0) { sub_charset_found = true; - cc_utf8 = utf8_init((*ti->sub_charsets)[i].language); + cc_utf8 = utf8_init((*ti->sub_charsets)[i].language == NULL ? "" : + (*ti->sub_charsets)[i].language); break; } @@ -90,7 +91,7 @@ ssa_reader_c::ssa_reader_c(track_info_c *nti) if (mm_io->get_byte_order() != BO_NONE) cc_utf8 = utf8_init("UTF-8"); else - cc_utf8 = utf8_init(ti->sub_charset); + cc_utf8 = utf8_init(ti->sub_charset == NULL ? "" : ti->sub_charset); } ti->id = 0; // ID for this track. diff --git a/src/merge/mkvmerge.cpp b/src/merge/mkvmerge.cpp index bfc7c361a..dfa33b5b3 100644 --- a/src/merge/mkvmerge.cpp +++ b/src/merge/mkvmerge.cpp @@ -1417,6 +1417,7 @@ parse_args(vector &args) { "'--chapter-charset %s'.\n"), next_arg.c_str()); chapter_charset = next_arg; + ti->chapter_charset = next_arg; sit++; } else if ((this_arg == "--cue-chapter-name-format")) { @@ -1829,7 +1830,7 @@ handle_args(int argc, if (!strcmp(argv[i], "--command-line-charset")) { if ((i + 1) == argc) mxerror(_("'--command-line-charset' is missing its argument.\n")); - cc_command_line = utf8_init(argv[i + 1]); + cc_command_line = utf8_init(argv[i + 1] == NULL ? "" : argv[i + 1]); i++; } else args.push_back(to_utf8(cc_command_line, argv[i])); diff --git a/src/merge/output_control.cpp b/src/merge/output_control.cpp index ed859a71b..8b9c68534 100644 --- a/src/merge/output_control.cpp +++ b/src/merge/output_control.cpp @@ -1766,7 +1766,7 @@ setup() { #endif srand(time(NULL)); - cc_local_utf8 = utf8_init(NULL); + cc_local_utf8 = utf8_init(""); cluster_helper = new cluster_helper_c(); diff --git a/src/merge/pr_generic.cpp b/src/merge/pr_generic.cpp index 0c644fc07..15cd0cf32 100644 --- a/src/merge/pr_generic.cpp +++ b/src/merge/pr_generic.cpp @@ -1378,6 +1378,8 @@ track_info_c::operator =(const track_info_c &src) { no_attachments = src.no_attachments; no_tags = src.no_tags; + chapter_charset = src.chapter_charset; + avi_block_align = src.avi_block_align; avi_samples_per_sec = src.avi_samples_per_sec; avi_avg_bytes_per_sec = src.avi_avg_bytes_per_sec; diff --git a/src/merge/pr_generic.h b/src/merge/pr_generic.h index 3e8391b14..1207a7a29 100644 --- a/src/merge/pr_generic.h +++ b/src/merge/pr_generic.h @@ -223,6 +223,10 @@ public: bool no_chapters, no_attachments, no_tags; + // Some file formats can contain chapters, but for some the charset + // cannot be identified unambiguously (*cough* OGM *cough*). + string chapter_charset; + // The following variables are needed for the broken way of // syncing audio in AVIs: by prepending it with trash. Thanks to // the nandub author for this really, really sucky implementation. diff --git a/src/mmg/mmg.cpp b/src/mmg/mmg.cpp index 86b7f659d..f05b5caf8 100644 --- a/src/mmg/mmg.cpp +++ b/src/mmg/mmg.cpp @@ -1743,7 +1743,7 @@ mmg_app::OnInit() { uint32_t i; wxString k, v; - cc_local_utf8 = utf8_init(NULL); + cc_local_utf8 = utf8_init(""); xml_element_map_init(); cfg = new wxConfig(wxT("mkvmergeGUI")); diff --git a/src/output/p_textsubs.cpp b/src/output/p_textsubs.cpp index aa2eb6eae..df0add451 100644 --- a/src/output/p_textsubs.cpp +++ b/src/output/p_textsubs.cpp @@ -38,7 +38,7 @@ textsubs_packetizer_c::textsubs_packetizer_c(generic_reader_c *nreader, recode = nrecode; if (recode) { if ((ti->sub_charset != NULL) || !is_utf8) - cc_utf8 = utf8_init(ti->sub_charset); + cc_utf8 = utf8_init(ti->sub_charset == NULL ? "" : ti->sub_charset); else cc_utf8 = utf8_init("UTF-8"); }