Merged 2394:2396, 2399

This commit is contained in:
Moritz Bunkus 2004-10-28 16:39:22 +00:00
parent 4796bb8ea0
commit a95f1f182f
26 changed files with 840 additions and 890 deletions

View File

@ -59,7 +59,7 @@ probe_cue_chapters(mm_text_io_c *in) {
return false; return false;
} }
char *cue_to_chapter_name_format = NULL; string cue_to_chapter_name_format;
static void static void
cue_entries_to_chapter_name(string &performer, cue_entries_to_chapter_name(string &performer,
@ -76,10 +76,10 @@ cue_entries_to_chapter_name(string &performer,
if (performer.length() == 0) if (performer.length() == 0)
performer = global_performer; performer = global_performer;
if (cue_to_chapter_name_format == NULL) if (cue_to_chapter_name_format == "")
this_char = "%p - %t"; this_char = "%p - %t";
else else
this_char = cue_to_chapter_name_format; this_char = cue_to_chapter_name_format.c_str();
next_char = this_char + 1; next_char = this_char + 1;
while (*this_char != 0) { while (*this_char != 0) {
if (*this_char == '%') { if (*this_char == '%') {
@ -134,7 +134,7 @@ typedef struct {
vector<string> global_rem; vector<string> global_rem;
vector<string> global_comment; vector<string> global_comment;
vector<string> comment; vector<string> comment;
const char *language; string language;
int line_num; int line_num;
int cc_utf8; int cc_utf8;
} cue_parser_args_t; } cue_parser_args_t;
@ -142,17 +142,10 @@ typedef struct {
static UTFstring static UTFstring
cue_str_internal_to_utf(cue_parser_args_t &a, cue_str_internal_to_utf(cue_parser_args_t &a,
const string &s) { const string &s) {
if (a.do_convert) { if (a.do_convert)
UTFstring wchar_string; return cstrutf8_to_UTFstring(to_utf8(a.cc_utf8, s));
char *recoded_string; else
return cstrutf8_to_UTFstring(s);
recoded_string = to_utf8(a.cc_utf8, s.c_str());
wchar_string = cstrutf8_to_UTFstring(recoded_string);
safefree(recoded_string);
return wchar_string;
} else
return cstrutf8_to_UTFstring(s.c_str());
} }
static KaxTagSimple * static KaxTagSimple *
@ -369,8 +362,8 @@ parse_cue_chapters(mm_text_io_c *in,
int64_t min_tc, int64_t min_tc,
int64_t max_tc, int64_t max_tc,
int64_t offset, int64_t offset,
const char *language, const string &language,
const char *charset, const string &charset,
bool exception_on_error, bool exception_on_error,
KaxTags **tags) { KaxTags **tags) {
cue_parser_args_t a; cue_parser_args_t a;
@ -381,14 +374,14 @@ parse_cue_chapters(mm_text_io_c *in,
if (in->get_byte_order() == BO_NONE) { if (in->get_byte_order() == BO_NONE) {
a.do_convert = true; a.do_convert = true;
a.cc_utf8 = utf8_init(charset); a.cc_utf8 = utf8_init(charset.c_str());
} else { } else {
a.do_convert = false; a.do_convert = false;
a.cc_utf8 = 0; a.cc_utf8 = 0;
} }
if (language == NULL) if (language == "")
a.language = "eng"; a.language = "eng";
else else
a.language = language; a.language = language;

View File

@ -126,18 +126,17 @@ parse_simple_chapters(mm_text_io_c *in,
int64_t min_tc, int64_t min_tc,
int64_t max_tc, int64_t max_tc,
int64_t offset, int64_t offset,
const char *language, const string &language,
const char *charset, const string &charset,
bool exception_on_error) { bool exception_on_error) {
KaxChapters *chaps; KaxChapters *chaps;
KaxEditionEntry *edition; KaxEditionEntry *edition;
KaxChapterAtom *atom; KaxChapterAtom *atom;
KaxChapterDisplay *display; KaxChapterDisplay *display;
int64_t start, hour, minute, second, msecs; int64_t start, hour, minute, second, msecs;
string name, line; string name, line, use_language;
int mode, num, cc_utf8; int mode, num, cc_utf8;
bool do_convert; bool do_convert;
char *recoded_string;
UTFstring wchar_string; UTFstring wchar_string;
in->setFilePointer(0); in->setFilePointer(0);
@ -160,17 +159,18 @@ parse_simple_chapters(mm_text_io_c *in,
if (in->get_byte_order() == BO_NONE) { if (in->get_byte_order() == BO_NONE) {
do_convert = true; do_convert = true;
cc_utf8 = utf8_init(charset); cc_utf8 = utf8_init(charset.c_str());
} else } else
do_convert = false; do_convert = false;
if (language == NULL) { if (language == "") {
if (default_chapter_language.length() > 0) if (default_chapter_language.length() > 0)
language = default_chapter_language.c_str(); use_language = default_chapter_language;
else else
language = "eng"; use_language = "eng";
} } else
use_language = language;
try { try {
while (in->getline2(line)) { while (in->getline2(line)) {
@ -181,10 +181,10 @@ parse_simple_chapters(mm_text_io_c *in,
if (mode == 0) { if (mode == 0) {
if (!ischapterline(line.c_str())) if (!ischapterline(line.c_str()))
chapter_error("'%s' is not a CHAPTERxx=... line.", line.c_str()); chapter_error("'%s' is not a CHAPTERxx=... line.", line.c_str());
parse_int(line.substr(10, 2).c_str(), hour); parse_int(line.substr(10, 2), hour);
parse_int(line.substr(13, 2).c_str(), minute); parse_int(line.substr(13, 2), minute);
parse_int(line.substr(16, 2).c_str(), second); parse_int(line.substr(16, 2), second);
parse_int(line.substr(19, 3).c_str(), msecs); parse_int(line.substr(19, 3), msecs);
if (hour > 23) if (hour > 23)
chapter_error("Invalid hour: %d", hour); chapter_error("Invalid hour: %d", hour);
if (minute > 59) if (minute > 59)
@ -217,17 +217,15 @@ parse_simple_chapters(mm_text_io_c *in,
display = &GetChild<KaxChapterDisplay>(*atom); display = &GetChild<KaxChapterDisplay>(*atom);
if (do_convert) { if (do_convert)
recoded_string = to_utf8(cc_utf8, name.c_str()); wchar_string = cstrutf8_to_UTFstring(to_utf8(cc_utf8, name));
wchar_string = cstrutf8_to_UTFstring(recoded_string); else
safefree(recoded_string); wchar_string = cstrutf8_to_UTFstring(name);
} else
wchar_string = cstrutf8_to_UTFstring(name.c_str());
*static_cast<EbmlUnicodeString *> *static_cast<EbmlUnicodeString *>
(&GetChild<KaxChapterString>(*display)) = wchar_string; (&GetChild<KaxChapterString>(*display)) = wchar_string;
*static_cast<EbmlString *>(&GetChild<KaxChapterLanguage>(*display)) = *static_cast<EbmlString *>(&GetChild<KaxChapterLanguage>(*display)) =
language; use_language;
if (default_chapter_country.length() > 0) if (default_chapter_country.length() > 0)
*static_cast<EbmlString *> *static_cast<EbmlString *>
@ -257,12 +255,12 @@ parse_simple_chapters(mm_text_io_c *in,
// }}} // }}}
KaxChapters * KaxChapters *
parse_chapters(const char *file_name, parse_chapters(const string &file_name,
int64_t min_tc, int64_t min_tc,
int64_t max_tc, int64_t max_tc,
int64_t offset, int64_t offset,
const char *language, const string &language,
const char *charset, const string &charset,
bool exception_on_error, bool exception_on_error,
bool *is_simple_format, bool *is_simple_format,
KaxTags **tags) { KaxTags **tags) {
@ -273,10 +271,10 @@ parse_chapters(const char *file_name,
in = new mm_text_io_c(file_name); in = new mm_text_io_c(file_name);
} catch (...) { } catch (...) {
if (exception_on_error) if (exception_on_error)
throw error_c(string("Could not open '") + string(file_name) + throw error_c(mxsprintf("Could not open '%s' for reading.\n",
string("' for reading.\n")); file_name.c_str()));
else else
mxerror("Could not open '%s' for reading.\n", file_name); mxerror("Could not open '%s' for reading.\n", file_name.c_str());
} }
try { try {
@ -299,9 +297,9 @@ parse_chapters(const char *file_name,
delete in; delete in;
throw error_c(string("Unknown file format for '") + string(file_name) + throw error_c(mxsprintf("Unknown file format for '%s'. It does not "
string("'. It does not contain a supported chapter " "contain a support chapter format.\n",
"format.\n")); file_name.c_str()));
} catch (error_c e) { } catch (error_c e) {
if (exception_on_error) if (exception_on_error)
throw e; throw e;

View File

@ -34,10 +34,10 @@ using namespace libebml;
using namespace libmatroska; using namespace libmatroska;
KaxChapters *MTX_DLL_API KaxChapters *MTX_DLL_API
parse_chapters(const char *file_name, int64_t min_tc = 0, parse_chapters(const string &file_name, int64_t min_tc = 0,
int64_t max_tc = -1, int64_t offset = 0, int64_t max_tc = -1, int64_t offset = 0,
const char *language = NULL, const string &language = "",
const char *charset = NULL, const string &charset = "",
bool exception_on_error = false, bool exception_on_error = false,
bool *is_simple_format = NULL, bool *is_simple_format = NULL,
KaxTags **tags = NULL); KaxTags **tags = NULL);
@ -51,15 +51,15 @@ bool MTX_DLL_API probe_simple_chapters(mm_text_io_c *in);
KaxChapters *MTX_DLL_API KaxChapters *MTX_DLL_API
parse_simple_chapters(mm_text_io_c *in, int64_t min_tc, parse_simple_chapters(mm_text_io_c *in, int64_t min_tc,
int64_t max_tc, int64_t offset, int64_t max_tc, int64_t offset,
const char *language, const char *charset, const string &language, const string &charset,
bool exception_on_error = false); bool exception_on_error = false);
extern char *MTX_DLL_API cue_to_chapter_name_format; extern string MTX_DLL_API cue_to_chapter_name_format;
bool MTX_DLL_API probe_cue_chapters(mm_text_io_c *in); bool MTX_DLL_API probe_cue_chapters(mm_text_io_c *in);
KaxChapters *MTX_DLL_API parse_cue_chapters(mm_text_io_c *in, int64_t min_tc, KaxChapters *MTX_DLL_API parse_cue_chapters(mm_text_io_c *in, int64_t min_tc,
int64_t max_tc, int64_t offset, int64_t max_tc, int64_t offset,
const char *language, const string &language,
const char *charset, const string &charset,
bool exception_on_error = false, bool exception_on_error = false,
KaxTags **tags = NULL); KaxTags **tags = NULL);

View File

@ -69,12 +69,12 @@ bitvalue_c::bitvalue_c(const bitvalue_c &src) {
#define upperchar(c) (((c) >= 'a') ? ((c) - 'a' + 'A') : (c)) #define upperchar(c) (((c) >= 'a') ? ((c) - 'a' + 'A') : (c))
#define hextodec(c) (isdigit(c) ? ((c) - '0') : ((c) - 'A' + 10)) #define hextodec(c) (isdigit(c) ? ((c) - '0') : ((c) - 'A' + 10))
bitvalue_c::bitvalue_c(const char *s, bitvalue_c::bitvalue_c(string s,
int allowed_bitlength) { int allowed_bitlength) {
int len, i; int len, i;
string s2; string s2;
len = strlen(s); len = s.size();
if (len < 2) if (len < 2)
throw exception(); throw exception();
@ -94,8 +94,8 @@ bitvalue_c::bitvalue_c(const char *s,
i++; i++;
} }
} }
s = s2.c_str(); s = s2;
len = strlen(s); len = s.size();
} }
if ((len % 2) == 1) if ((len % 2) == 1)
@ -552,7 +552,7 @@ utf8_init(const char *charset) {
lc_charset = "CP" + to_string(GetACP()); lc_charset = "CP" + to_string(GetACP());
#elif defined(SYS_SOLARIS) #elif defined(SYS_SOLARIS)
lc_charset = nl_langinfo(CODESET); lc_charset = nl_langinfo(CODESET);
if (parse_int(lc_charset.c_str(), i)) if (parse_int(lc_charset, i))
lc_charset = string("ISO") + lc_charset + string("-US"); lc_charset = string("ISO") + lc_charset + string("-US");
#else #else
lc_charset = nl_langinfo(CODESET); lc_charset = nl_langinfo(CODESET);
@ -627,8 +627,8 @@ convert_charset(iconv_t ict,
} }
char * char *
to_utf8(int handle, to_utf8_c(int handle,
const char *local) { const char *local) {
char *copy; char *copy;
if (handle == -1) { if (handle == -1) {
@ -643,21 +643,22 @@ to_utf8(int handle,
return convert_charset(kax_convs[handle].ict_to_utf8, local); return convert_charset(kax_convs[handle].ict_to_utf8, local);
} }
string & string
to_utf8(int handle, to_utf8(int handle,
string &local) { const string &local) {
string s;
char *cutf8; char *cutf8;
cutf8 = to_utf8(handle, local.c_str()); cutf8 = to_utf8_c(handle, local.c_str());
local = cutf8; s = cutf8;
safefree(cutf8); safefree(cutf8);
return local; return s;
} }
char * char *
from_utf8(int handle, from_utf8_c(int handle,
const char *utf8) { const char *utf8) {
char *copy; char *copy;
if (handle == -1) { if (handle == -1) {
@ -672,16 +673,17 @@ from_utf8(int handle,
return convert_charset(kax_convs[handle].ict_from_utf8, utf8); return convert_charset(kax_convs[handle].ict_from_utf8, utf8);
} }
string & string
from_utf8(int handle, from_utf8(int handle,
string &utf8) { const string &utf8) {
string s;
char *clocal; char *clocal;
clocal = from_utf8(handle, utf8.c_str()); clocal = from_utf8_c(handle, utf8.c_str());
utf8 = clocal; s = clocal;
safefree(clocal); safefree(clocal);
return utf8; return s;
} }
/* /*
@ -1043,6 +1045,30 @@ starts_with_case(const string &s,
return strncasecmp(s.c_str(), start.c_str(), start.length()) == 0; return strncasecmp(s.c_str(), start.c_str(), start.length()) == 0;
} }
string
upcase(const string &s) {
string dst;
int i;
dst.reserve(s.size());
for (i = 0; i < s.size(); i++)
dst += toupper(s[i]);
return dst;
}
string
downcase(const string &s) {
string dst;
int i;
dst.reserve(s.size());
for (i = 0; i < s.size(); i++)
dst += tolower(s[i]);
return dst;
}
/* /*
* Integer parsing * Integer parsing
*/ */

View File

@ -184,10 +184,20 @@ extern int MTX_DLL_API cc_local_utf8;
int MTX_DLL_API utf8_init(const char *charset); int MTX_DLL_API utf8_init(const char *charset);
void MTX_DLL_API utf8_done(); void MTX_DLL_API utf8_done();
char *MTX_DLL_API to_utf8(int handle, const char *local); char *MTX_DLL_API to_utf8_c(int handle, const char *local);
char *MTX_DLL_API from_utf8(int handle, const char *utf8); inline char *
string &MTX_DLL_API to_utf8(int handle, string &local); to_utf8_c(int handle,
string &MTX_DLL_API from_utf8(int handle, string &utf8); const string &local) {
return to_utf8_c(handle, local.c_str());
}
char *MTX_DLL_API from_utf8_c(int handle, const char *utf8);
inline char *
from_utf8_c(int handle,
const string &utf8) {
return from_utf8_c(handle, utf8.c_str());
}
string MTX_DLL_API to_utf8(int handle, const string &local);
string MTX_DLL_API from_utf8(int handle, const string &utf8);
#define UNIQUE_ALL_IDS -1 #define UNIQUE_ALL_IDS -1
#define UNIQUE_TRACK_IDS 0 #define UNIQUE_TRACK_IDS 0
@ -206,6 +216,12 @@ uint32_t MTX_DLL_API create_unique_uint32(int category);
void *MTX_DLL_API _safemalloc(size_t size, const char *file, int line); void *MTX_DLL_API _safemalloc(size_t size, const char *file, int line);
#define safestrdup(s) _safestrdup(s, __FILE__, __LINE__) #define safestrdup(s) _safestrdup(s, __FILE__, __LINE__)
char *MTX_DLL_API _safestrdup(const char *s, const char *file, int line); char *MTX_DLL_API _safestrdup(const char *s, const char *file, int line);
inline char *
_safestrdup(const string &s,
const char *file,
int line) {
return _safestrdup(s.c_str(), file, line);
}
unsigned char *_safestrdup(const unsigned char *s, const char *file, int line); unsigned char *_safestrdup(const unsigned char *s, const char *file, int line);
#define safememdup(src, size) _safememdup(src, size, __FILE__, __LINE__) #define safememdup(src, size) _safememdup(src, size, __FILE__, __LINE__)
void *MTX_DLL_API _safememdup(const void *src, size_t size, const char *file, void *MTX_DLL_API _safememdup(const void *src, size_t size, const char *file,
@ -216,6 +232,12 @@ void *MTX_DLL_API _saferealloc(void *mem, size_t size, const char *file,
vector<string> MTX_DLL_API split(const char *src, const char *pattern = ",", vector<string> MTX_DLL_API split(const char *src, const char *pattern = ",",
int max_num = -1); int max_num = -1);
inline vector<string>
split(const string &src,
const string &pattern = string(","),
int max_num = -1) {
return split(src.c_str(), pattern.c_str(), max_num);
}
string MTX_DLL_API join(const char *pattern, vector<string> &strings); string MTX_DLL_API join(const char *pattern, vector<string> &strings);
void MTX_DLL_API strip(string &s, bool newlines = false); void MTX_DLL_API strip(string &s, bool newlines = false);
void MTX_DLL_API strip(vector<string> &v, bool newlines = false); void MTX_DLL_API strip(vector<string> &v, bool newlines = false);
@ -226,6 +248,8 @@ bool MTX_DLL_API starts_with(const string &s, const char *start);
bool MTX_DLL_API starts_with(const string &s, const string &start); bool MTX_DLL_API starts_with(const string &s, const string &start);
bool MTX_DLL_API starts_with_case(const string &s, const char *start); bool MTX_DLL_API starts_with_case(const string &s, const char *start);
bool MTX_DLL_API starts_with_case(const string &s, const string &start); bool MTX_DLL_API starts_with_case(const string &s, const string &start);
string MTX_DLL_API upcase(const string &s);
string MTX_DLL_API downcase(const string &s);
#define irnd(a) ((int64_t)((double)(a) + 0.5)) #define irnd(a) ((int64_t)((double)(a) + 0.5))
#define iabs(a) ((a) < 0 ? (a) * -1 : (a)) #define iabs(a) ((a) < 0 ? (a) * -1 : (a))
@ -233,6 +257,16 @@ bool MTX_DLL_API starts_with_case(const string &s, const string &start);
uint32_t MTX_DLL_API round_to_nearest_pow2(uint32_t value); uint32_t MTX_DLL_API round_to_nearest_pow2(uint32_t value);
bool MTX_DLL_API parse_int(const char *s, int64_t &value); bool MTX_DLL_API parse_int(const char *s, int64_t &value);
bool MTX_DLL_API parse_int(const char *s, int &value); bool MTX_DLL_API parse_int(const char *s, int &value);
inline bool
parse_int(const string &s,
int64_t &value) {
return parse_int(s.c_str(), value);
}
inline bool
parse_int(const string &s,
int &value) {
return parse_int(s.c_str(), value);
}
string MTX_DLL_API to_string(int64_t i); string MTX_DLL_API to_string(int64_t i);
bool MTX_DLL_API parse_double(const char *s, double &value); bool MTX_DLL_API parse_double(const char *s, double &value);
@ -434,7 +468,7 @@ private:
public: public:
bitvalue_c(int nsize); bitvalue_c(int nsize);
bitvalue_c(const bitvalue_c &src); bitvalue_c(const bitvalue_c &src);
bitvalue_c(const char *s, int allowed_bitlength = -1); bitvalue_c(string s, int allowed_bitlength = -1);
virtual ~bitvalue_c(); virtual ~bitvalue_c();
bitvalue_c &operator =(const bitvalue_c &src); bitvalue_c &operator =(const bitvalue_c &src);

View File

@ -38,23 +38,21 @@ static const char *mosu_hacks[] = {
ENGAGE_FORCE_PASSTHROUGH_PACKETIZER, ENGAGE_FORCE_PASSTHROUGH_PACKETIZER,
NULL NULL
}; };
static vector<const char *> engaged_hacks; static vector<string> engaged_hacks;
bool bool
hack_engaged(const char *hack) { hack_engaged(const string &hack) {
uint32_t i; vector<string>::const_iterator hit;
if (hack == NULL) foreach(hit, engaged_hacks)
return false; if (*hit == hack)
for (i = 0; i < engaged_hacks.size(); i++)
if (!strcmp(engaged_hacks[i], hack))
return true; return true;
return false; return false;
} }
void void
engage_hacks(const char *hacks) { engage_hacks(const string &hacks) {
vector<string> engage_args; vector<string> engage_args;
int aidx, hidx; int aidx, hidx;
bool valid_hack; bool valid_hack;

View File

@ -18,6 +18,10 @@
#include "os.h" #include "os.h"
#include <string>
using namespace std;
// Some hacks that are configurable via command line but which should ONLY! // Some hacks that are configurable via command line but which should ONLY!
// be used by the author. // be used by the author.
#define ENGAGE_SPACE_AFTER_CHAPTERS "space_after_chapters" #define ENGAGE_SPACE_AFTER_CHAPTERS "space_after_chapters"
@ -30,7 +34,7 @@
#define ENGAGE_NO_DEFAULT_HEADER_VALUES "no_default_header_values" #define ENGAGE_NO_DEFAULT_HEADER_VALUES "no_default_header_values"
#define ENGAGE_FORCE_PASSTHROUGH_PACKETIZER "force_passthrough_packetizer" #define ENGAGE_FORCE_PASSTHROUGH_PACKETIZER "force_passthrough_packetizer"
void MTX_DLL_API engage_hacks(const char *hacks); void MTX_DLL_API engage_hacks(const string &hacks);
bool MTX_DLL_API hack_engaged(const char *hack); bool MTX_DLL_API hack_engaged(const string &hack);
#endif // __HACKS_H #endif // __HACKS_H

View File

@ -34,7 +34,7 @@
using namespace std; using namespace std;
#if !defined(SYS_WINDOWS) #if !defined(SYS_WINDOWS)
mm_io_c::mm_io_c(const char *path, mm_io_c::mm_io_c(const string &path,
const open_mode mode) { const open_mode mode) {
char *cmode; char *cmode;
@ -55,24 +55,24 @@ mm_io_c::mm_io_c(const char *path,
throw 0; throw 0;
} }
file = (FILE *)fopen(path, cmode); file = (FILE *)fopen(path.c_str(), cmode);
if (file == NULL) if (file == NULL)
throw exception(); throw exception();
file_name = safestrdup(path); file_name = path;
dos_style_newlines = false; dos_style_newlines = false;
} }
mm_io_c::mm_io_c() { mm_io_c::mm_io_c() {
file_name = NULL; file_name = "";
file = NULL; file = NULL;
dos_style_newlines = false; dos_style_newlines = false;
} }
mm_io_c::~mm_io_c() { mm_io_c::~mm_io_c() {
close(); close();
safefree(file_name); file_name = "";
} }
uint64 uint64
@ -133,7 +133,7 @@ mm_io_c::truncate(int64_t pos) {
#else // SYS_UNIX #else // SYS_UNIX
mm_io_c::mm_io_c(const char *path, mm_io_c::mm_io_c(const string &path,
const open_mode mode) { const open_mode mode) {
DWORD access_mode, share_mode, disposition; DWORD access_mode, share_mode, disposition;
@ -162,18 +162,18 @@ mm_io_c::mm_io_c(const char *path,
throw exception(); throw exception();
} }
file = (void *)CreateFile(path, access_mode, share_mode, NULL, disposition, file = (void *)CreateFile(path.c_str(), access_mode, share_mode, NULL,
0, NULL); disposition, 0, NULL);
_eof = false; _eof = false;
if ((HANDLE)file == (HANDLE)0xFFFFFFFF) if ((HANDLE)file == (HANDLE)0xFFFFFFFF)
throw exception(); throw exception();
file_name = safestrdup(path); file_name = path;
dos_style_newlines = true; dos_style_newlines = true;
} }
mm_io_c::mm_io_c() { mm_io_c::mm_io_c() {
file_name = NULL; file_name = "";
file = NULL; file = NULL;
dos_style_newlines = true; dos_style_newlines = true;
} }
@ -186,6 +186,7 @@ void
mm_io_c::close() { mm_io_c::close() {
if (file != NULL) if (file != NULL)
CloseHandle((HANDLE)file); CloseHandle((HANDLE)file);
file_name = "";
} }
uint64 uint64
@ -300,11 +301,6 @@ mm_io_c::truncate(int64_t pos) {
#endif #endif
const char *
mm_io_c::get_file_name() {
return file_name;
}
string string
mm_io_c::getline() { mm_io_c::getline() {
char c; char c;
@ -346,14 +342,16 @@ mm_io_c::setFilePointer2(int64 offset, seek_mode mode) {
} }
size_t size_t
mm_io_c::puts_unl(const char *s) { mm_io_c::puts_unl(const string &s) {
int i; int i;
size_t bytes_written; size_t bytes_written;
const char *cs;
cs = s.c_str();
bytes_written = 0; bytes_written = 0;
for (i = 0; i < strlen(s); i++) for (i = 0; cs[i] != 0; i++)
if (s[i] != '\r') if (cs[i] != '\r')
bytes_written += write(&s[i], 1); bytes_written += write(&cs[i], 1);
return bytes_written; return bytes_written;
} }
@ -549,7 +547,7 @@ mm_io_c::restore_pos() {
} }
bool bool
mm_io_c::write_bom(const char *charset) { mm_io_c::write_bom(const string &charset) {
const unsigned char utf8_bom[3] = {0xef, 0xbb, 0xbf}; const unsigned char utf8_bom[3] = {0xef, 0xbb, 0xbf};
const unsigned char utf16le_bom[2] = {0xff, 0xfe}; const unsigned char utf16le_bom[2] = {0xff, 0xfe};
const unsigned char utf16be_bom[2] = {0xfe, 0xff}; const unsigned char utf16be_bom[2] = {0xfe, 0xff};
@ -558,24 +556,24 @@ mm_io_c::write_bom(const char *charset) {
const unsigned char *bom; const unsigned char *bom;
int bom_len; int bom_len;
if (charset == NULL) if (charset == "")
return false; return false;
if (!strcmp(charset, "UTF-8") || !strcmp(charset, "UTF8")) { if ((charset =="UTF-8") || (charset =="UTF8")) {
bom_len = 3; bom_len = 3;
bom = utf8_bom; bom = utf8_bom;
} else if (!strcmp(charset, "UTF-16") || !strcmp(charset, "UTF-16LE") || } else if ((charset =="UTF-16") || (charset =="UTF-16LE") ||
!strcmp(charset, "UTF16") || !strcmp(charset, "UTF16LE")) { (charset =="UTF16") || (charset =="UTF16LE")) {
bom_len = 2; bom_len = 2;
bom = utf16le_bom; bom = utf16le_bom;
} else if (!strcmp(charset, "UTF-16BE") || !strcmp(charset, "UTF16BE")) { } else if ((charset =="UTF-16BE") || (charset =="UTF16BE")) {
bom_len = 2; bom_len = 2;
bom = utf16be_bom; bom = utf16be_bom;
} else if (!strcmp(charset, "UTF-32") || !strcmp(charset, "UTF-32LE") || } else if ((charset =="UTF-32") || (charset =="UTF-32LE") ||
!strcmp(charset, "UTF32") || !strcmp(charset, "UTF32LE")) { (charset =="UTF32") || (charset =="UTF32LE")) {
bom_len = 4; bom_len = 4;
bom = utf32le_bom; bom = utf32le_bom;
} else if (!strcmp(charset, "UTF-32BE") || !strcmp(charset, "UTF32BE")) { } else if ((charset =="UTF-32BE") || (charset =="UTF32BE")) {
bom_len = 4; bom_len = 4;
bom = utf32be_bom; bom = utf32be_bom;
} else } else
@ -756,7 +754,7 @@ mm_mem_io_c::eof() {
* Class for handling UTF-8/UTF-16/UTF-32 text files. * Class for handling UTF-8/UTF-16/UTF-32 text files.
*/ */
mm_text_io_c::mm_text_io_c(const char *path): mm_text_io_c::mm_text_io_c(const string &path):
mm_io_c(path, MODE_READ) { mm_io_c(path, MODE_READ) {
unsigned char buffer[4]; unsigned char buffer[4];

View File

@ -31,14 +31,14 @@ protected:
#if defined(SYS_WINDOWS) #if defined(SYS_WINDOWS)
bool _eof; bool _eof;
#endif #endif
char *file_name; string file_name;
void *file; void *file;
stack<int64_t> positions; stack<int64_t> positions;
bool dos_style_newlines; bool dos_style_newlines;
public: public:
mm_io_c(); mm_io_c();
mm_io_c(const char *path, const open_mode mode); mm_io_c(const string &path, const open_mode mode);
virtual ~mm_io_c(); virtual ~mm_io_c();
virtual uint64 getFilePointer(); virtual uint64 getFilePointer();
@ -68,8 +68,8 @@ public:
virtual bool eof(); virtual bool eof();
virtual string getline(); virtual string getline();
virtual bool getline2(string &s); virtual bool getline2(string &s);
virtual size_t puts_unl(const char *s); virtual size_t puts_unl(const string &s);
virtual bool write_bom(const char *charset); virtual bool write_bom(const string &charset);
virtual int getch(); virtual int getch();
virtual void save_pos(int64_t new_pos = -1); virtual void save_pos(int64_t new_pos = -1);
@ -77,7 +77,9 @@ public:
virtual int64_t get_size(); virtual int64_t get_size();
virtual const char *get_file_name(); virtual const string &get_file_name() {
return file_name;
}
virtual int truncate(int64_t pos); virtual int truncate(int64_t pos);
@ -126,7 +128,7 @@ protected:
int bom_len; int bom_len;
public: public:
mm_text_io_c(const char *path); mm_text_io_c(const string &path);
virtual void setFilePointer(int64 offset, seek_mode mode=seek_beginning); virtual void setFilePointer(int64 offset, seek_mode mode=seek_beginning);
virtual string getline(); virtual string getline();

View File

@ -395,7 +395,7 @@ parse_xml_elements(const char *parser_name,
pdata = (parser_data_t *)safemalloc(sizeof(parser_data_t)); pdata = (parser_data_t *)safemalloc(sizeof(parser_data_t));
memset(pdata, 0, sizeof(parser_data_t)); memset(pdata, 0, sizeof(parser_data_t));
pdata->parser = parser; pdata->parser = parser;
pdata->file_name = in->get_file_name(); pdata->file_name = in->get_file_name().c_str();
pdata->parser_name = parser_name; pdata->parser_name = parser_name;
pdata->mapping = mapping; pdata->mapping = mapping;
pdata->parents = new vector<EbmlElement *>; pdata->parents = new vector<EbmlElement *>;

View File

@ -581,8 +581,8 @@ create_output_files() {
(sconv[sconv.length()- 1] != '\n')) (sconv[sconv.length()- 1] != '\n'))
sconv += "\n"; sconv += "\n";
from_utf8(tracks[i].conv_handle, sconv); sconv = from_utf8(tracks[i].conv_handle, sconv);
tracks[i].out->puts_unl(sconv.c_str()); tracks[i].out->puts_unl(sconv);
} else if (tracks[i].type == TYPEFLAC) { } else if (tracks[i].type == TYPEFLAC) {
if (!tracks[i].embed_in_ogg) if (!tracks[i].embed_in_ogg)
@ -711,7 +711,7 @@ handle_data(KaxBlock *block,
s = (char *)safemalloc(data.Size() + 1); s = (char *)safemalloc(data.Size() + 1);
memcpy(s, data.Buffer(), data.Size()); memcpy(s, data.Buffer(), data.Size());
s[data.Size()] = 0; s[data.Size()] = 0;
s2 = from_utf8(track->conv_handle, s); s2 = from_utf8_c(track->conv_handle, s);
safefree(s); safefree(s);
len = strlen(s2); len = strlen(s2);
s = (char *)safemalloc(len + 3); s = (char *)safemalloc(len + 3);
@ -766,7 +766,7 @@ handle_data(KaxBlock *block,
// Convert the ReadOrder entry so that we can re-order the entries // Convert the ReadOrder entry so that we can re-order the entries
// later. // later.
if (!parse_int(fields[0].c_str(), num)) { if (!parse_int(fields[0], num)) {
mxwarn(_("Invalid format for a SSA line ('%s'). " mxwarn(_("Invalid format for a SSA line ('%s'). "
"This entry will be skipped.\n"), s); "This entry will be skipped.\n"), s);
continue; continue;
@ -815,7 +815,7 @@ handle_data(KaxBlock *block,
fields[8] + string("\n"); // Text fields[8] + string("\n"); // Text
// Do the charset conversion. // Do the charset conversion.
from_utf8(track->conv_handle, line); line = from_utf8(track->conv_handle, line);
// Now store that entry. // Now store that entry.
ssa_line.num = num; ssa_line.num = num;

View File

@ -953,7 +953,7 @@ kax_reader_c::read_headers() {
for (idx = 0; idx < 4; idx++) { for (idx = 0; idx < 4; idx++) {
int num; int num;
if (!parse_int(ver_parts[idx].c_str(), num) || (num < 0) || if (!parse_int(ver_parts[idx], num) || (num < 0) ||
(num > 255)) { (num > 255)) {
failed = true; failed = true;
break; break;

View File

@ -1120,13 +1120,8 @@ ogm_reader_c::handle_stream_comments() {
if (comment.size() != 2) if (comment.size() != 2)
continue; continue;
if (!comments_in_utf8) { if (!comments_in_utf8)
char *utf8_comment; comment[1] = to_utf8(cc_local_utf8, comment[1]);
utf8_comment = to_utf8(cc_local_utf8, comment[1].c_str());
comment[1] = utf8_comment;
safefree(utf8_comment);
}
if (comment[0] == "LANGUAGE") { if (comment[0] == "LANGUAGE") {
iso639_2 = map_english_name_to_iso639_2(comment[1].c_str()); iso639_2 = map_english_name_to_iso639_2(comment[1].c_str());
@ -1177,7 +1172,7 @@ ogm_reader_c::handle_stream_comments() {
if (comments_in_utf8) if (comments_in_utf8)
chapters.push_back(safestrdup(comments[j])); chapters.push_back(safestrdup(comments[j]));
else else
chapters.push_back(to_utf8(cc_local_utf8, comments[j])); chapters.push_back(to_utf8_c(cc_local_utf8, comments[j]));
} }
} }
if ((chapters.size() > 0) && !ti->no_chapters && (kax_chapters == NULL)) { if ((chapters.size() > 0) && !ti->no_chapters && (kax_chapters == NULL)) {

View File

@ -50,7 +50,7 @@ srt_reader_c::probe_file(mm_text_io_c *mm_io,
mm_io->setFilePointer(0, seek_beginning); mm_io->setFilePointer(0, seek_beginning);
s = mm_io->getline(); s = mm_io->getline();
strip(s); strip(s);
if (!parse_int(s.c_str(), dummy)) if (!parse_int(s, dummy))
return 0; return 0;
s = mm_io->getline(); s = mm_io->getline();
if ((s.length() < 29) || !issrttimecode(s.c_str())) if ((s.length() < 29) || !issrttimecode(s.c_str()))

View File

@ -175,7 +175,7 @@ ssa_reader_c::parse_time(string &stime) {
return -1; return -1;
s = stime.substr(0, pos); s = stime.substr(0, pos);
if (!parse_int(s.c_str(), th)) if (!parse_int(s, th))
return -1; return -1;
stime.erase(0, pos + 1); stime.erase(0, pos + 1);
@ -184,7 +184,7 @@ ssa_reader_c::parse_time(string &stime) {
return -1; return -1;
s = stime.substr(0, pos); s = stime.substr(0, pos);
if (!parse_int(s.c_str(), tm)) if (!parse_int(s, tm))
return -1; return -1;
stime.erase(0, pos + 1); stime.erase(0, pos + 1);
@ -193,11 +193,11 @@ ssa_reader_c::parse_time(string &stime) {
return -1; return -1;
s = stime.substr(0, pos); s = stime.substr(0, pos);
if (!parse_int(s.c_str(), ts)) if (!parse_int(s, ts))
return -1; return -1;
stime.erase(0, pos + 1); stime.erase(0, pos + 1);
if (!parse_int(stime.c_str(), tds)) if (!parse_int(stime, tds))
return -1; return -1;
return (tds * 10 + ts * 1000 + tm * 60 * 1000 + th * 60 * 60 * 1000) * return (tds * 10 + ts * 1000 + tm * 60 * 1000 + th * 60 * 60 * 1000) *
@ -206,16 +206,8 @@ ssa_reader_c::parse_time(string &stime) {
string string
ssa_reader_c::recode_text(vector<string> &fields) { ssa_reader_c::recode_text(vector<string> &fields) {
char *s;
string res;
// TODO: Handle \fe encoding changes. // TODO: Handle \fe encoding changes.
res = get_element("Text", fields); return to_utf8(cc_utf8, get_element("Text", fields));
s = to_utf8(cc_utf8, res.c_str());
res = s;
safefree(s);
return res;
} }
int int

File diff suppressed because it is too large Load Diff

View File

@ -51,8 +51,6 @@ extern bool no_lacing, no_linking, use_durations;
extern bool identifying, identify_verbose; extern bool identifying, identify_verbose;
extern char *dump_packets;
int64_t create_track_number(generic_reader_c *reader, int64_t tid); int64_t create_track_number(generic_reader_c *reader, int64_t tid);
void add_packetizer_globally(generic_packetizer_c *packetizer); void add_packetizer_globally(generic_packetizer_c *packetizer);

View File

@ -441,7 +441,7 @@ to_utf8(const wxString &src) {
utf8 = (char *)safemalloc(len + 1); utf8 = (char *)safemalloc(len + 1);
wxConvUTF8.WC2MB(utf8, src.c_str(), len + 1); wxConvUTF8.WC2MB(utf8, src.c_str(), len + 1);
#else #else
utf8 = to_utf8(cc_local_utf8, src.c_str()); utf8 = to_utf8_c(cc_local_utf8, src);
#endif #endif
retval = utf8; retval = utf8;
safefree(utf8); safefree(utf8);

View File

@ -1945,7 +1945,7 @@ tab_chapters::parse_time(wxString s) {
} }
c++; c++;
} }
if (!parse_int(utf8s.c_str(), nsecs)) if (!parse_int(utf8s, nsecs))
return -1; return -1;
return nsecs * 1000000000; return nsecs * 1000000000;
} }

View File

@ -469,7 +469,7 @@ tab_global::validate_settings() {
wxOK | wxCENTER | wxICON_ERROR); wxOK | wxCENTER | wxICON_ERROR);
return false; return false;
} }
if ((s.length() == 0) || !parse_int(s.c_str(), dummy_i)) { if ((s.length() == 0) || !parse_int(s, dummy_i)) {
wxMessageBox(wxT("The format of the split size is invalid."), wxMessageBox(wxT("The format of the split size is invalid."),
wxT("mkvmerge GUI error"), wxT("mkvmerge GUI error"),
wxOK | wxCENTER | wxICON_ERROR); wxOK | wxCENTER | wxICON_ERROR);
@ -494,7 +494,7 @@ tab_global::validate_settings() {
c = s[s.length() - 1]; c = s[s.length() - 1];
if (tolower(c) == 's') { if (tolower(c) == 's') {
s.erase(s.length() - 1); s.erase(s.length() - 1);
if ((s.length() == 0) || !parse_int(s.c_str(), dummy_i) || if ((s.length() == 0) || !parse_int(s, dummy_i) ||
(dummy_i <= 0)) { (dummy_i <= 0)) {
wxMessageBox(wxT("The format of the split time is invalid."), wxMessageBox(wxT("The format of the split time is invalid."),
wxT("mkvmerge GUI error"), wxOK | wxCENTER | wxT("mkvmerge GUI error"), wxOK | wxCENTER |
@ -523,7 +523,7 @@ tab_global::validate_settings() {
s = wxMB(tc_split_max_files->GetValue()); s = wxMB(tc_split_max_files->GetValue());
strip(s); strip(s);
if ((s.length() > 0) && (!parse_int(s.c_str(), dummy_i) || if ((s.length() > 0) && (!parse_int(s, dummy_i) ||
(dummy_i <= 1))) { (dummy_i <= 1))) {
wxMessageBox(wxT("Invalid number of max. split files given."), wxMessageBox(wxT("Invalid number of max. split files given."),
wxT("mkvmerge GUI error"), wxOK | wxCENTER | wxICON_ERROR); wxT("mkvmerge GUI error"), wxOK | wxCENTER | wxICON_ERROR);

View File

@ -623,7 +623,7 @@ from_utf8(const wxString &src) {
wxString retval; wxString retval;
char *local; char *local;
local = from_utf8(cc_local_utf8, src.c_str()); local = from_utf8_c(cc_local_utf8, src.c_str());
retval = local; retval = local;
safefree(local); safefree(local);
return retval; return retval;
@ -1591,7 +1591,7 @@ tab_input::validate_settings() {
s = wxMB(*t->delay); s = wxMB(*t->delay);
strip(s); strip(s);
if ((s.length() > 0) && !parse_int(s.c_str(), dummy_i)) { if ((s.length() > 0) && !parse_int(s, dummy_i)) {
wxMessageBox(wxT("The delay setting for track nr. ") + sid + wxMessageBox(wxT("The delay setting for track nr. ") + sid +
wxT(" in file '") + *f->file_name + wxT("' is invalid."), wxT(" in file '") + *f->file_name + wxT("' is invalid."),
wxT("mkvmerge GUI: error"), wxT("mkvmerge GUI: error"),

View File

@ -203,10 +203,6 @@ mp3_packetizer_c::process(memory_c &mem,
byte_buffer.add(mem.data, mem.size); byte_buffer.add(mem.data, mem.size);
while ((packet = get_mp3_packet(&mp3header)) != NULL) { while ((packet = get_mp3_packet(&mp3header)) != NULL) {
#ifdef DEBUG
dump_packet(packet, mp3header.framesize);
#endif
if (timecode == -1) if (timecode == -1)
my_timecode = (int64_t)(1000000000.0 * packetno * spf / samples_per_sec); my_timecode = (int64_t)(1000000000.0 * packetno * spf / samples_per_sec);
else else

View File

@ -129,7 +129,7 @@ textsubs_packetizer_c::process(memory_c &mem,
*idx2 = 0; *idx2 = 0;
if (recode) { if (recode) {
utf8_subs = to_utf8(cc_utf8, subs); utf8_subs = to_utf8_c(cc_utf8, subs);
safefree(subs); safefree(subs);
memory_c mem((unsigned char *)utf8_subs, strlen(utf8_subs), true); memory_c mem((unsigned char *)utf8_subs, strlen(utf8_subs), true);
add_packet(mem, start, length, true); add_packet(mem, start, length, true);

View File

@ -243,8 +243,6 @@ generic_packetizer_c::generic_packetizer_c(generic_reader_c *nreader,
hcompression = COMPRESSION_UNSPECIFIED; hcompression = COMPRESSION_UNSPECIFIED;
compressor = NULL; compressor = NULL;
dumped_packet_number = 0;
timecode_factory = timecode_factory_c::create(ti->ext_timecodes, timecode_factory = timecode_factory_c::create(ti->ext_timecodes,
ti->fname, ti->id); ti->fname, ti->id);
} }
@ -881,28 +879,6 @@ generic_packetizer_c::get_packet() {
return pack; return pack;
} }
void
generic_packetizer_c::dump_packet(const void *buffer,
int size) {
char *path;
mm_io_c *out;
if (dump_packets == NULL)
return;
path = (char *)safemalloc(strlen(dump_packets) + 1 + 30);
mxprints(path, "%s/%u-%010lld", dump_packets, hserialno,
dumped_packet_number);
dumped_packet_number++;
try {
out = new mm_io_c(path, MODE_CREATE);
out->write(buffer, size);
delete out;
} catch(...) {
}
safefree(path);
}
void void
generic_packetizer_c::displace(float by_ns) { generic_packetizer_c::displace(float by_ns) {
ti->async.displacement += (int64_t)by_ns; ti->async.displacement += (int64_t)by_ns;

View File

@ -319,8 +319,6 @@ protected:
int hvideo_pixel_width, hvideo_pixel_height; int hvideo_pixel_width, hvideo_pixel_height;
int hvideo_display_width, hvideo_display_height; int hvideo_display_width, hvideo_display_height;
int64_t dumped_packet_number;
int hcompression; int hcompression;
compression_c *compressor; compression_c *compressor;
@ -475,9 +473,6 @@ public:
if (ti->avi_block_sizes != NULL) if (ti->avi_block_sizes != NULL)
ti->avi_block_sizes->push_back(block_size); ti->avi_block_sizes->push_back(block_size);
} }
protected:
virtual void dump_packet(const void *buffer, int size);
}; };
extern vector<generic_packetizer_c *> ptzrs_in_header_order; extern vector<generic_packetizer_c *> ptzrs_in_header_order;

View File

@ -43,7 +43,7 @@ timecode_factory_c::create(const char *_file_name,
} }
if (!in->getline2(line) || !starts_with_case(line, "# timecode format v") || if (!in->getline2(line) || !starts_with_case(line, "# timecode format v") ||
!parse_int(&line.c_str()[strlen("# timecode format v")], version)) !parse_int(&line[strlen("# timecode format v")], version))
mxerror(_("The timecode file '%s' contains an unsupported/unrecognized " mxerror(_("The timecode file '%s' contains an unsupported/unrecognized "
"format line. The very first line must look like " "format line. The very first line must look like "
"'# timecode format v1'.\n"), _file_name); "'# timecode format v1'.\n"), _file_name);