Do not use a global variable for passing the information about which elements to extract to functions.

This commit is contained in:
Moritz Bunkus 2005-02-05 19:07:25 +00:00
parent ed9d1df852
commit 01005098ca
4 changed files with 21 additions and 15 deletions

View File

@ -73,7 +73,8 @@ using namespace libmatroska;
using namespace std; using namespace std;
static void static void
handle_attachments(KaxAttachments *atts) { handle_attachments(KaxAttachments *atts,
vector<track_spec_t> &tracks) {
KaxAttached *att; KaxAttached *att;
KaxFileData *fdata; KaxFileData *fdata;
EbmlElement *e; EbmlElement *e;
@ -146,6 +147,7 @@ handle_attachments(KaxAttachments *atts) {
void void
extract_attachments(const char *file_name, extract_attachments(const char *file_name,
vector<track_spec_t> &tracks,
bool parse_fully) { bool parse_fully) {
mm_io_c *in; mm_io_c *in;
mm_stdio_c out; mm_stdio_c out;
@ -169,7 +171,7 @@ extract_attachments(const char *file_name,
if (verbose > 0) if (verbose > 0)
debug_dump_elements(attachments, 0); debug_dump_elements(attachments, 0);
handle_attachments(attachments); handle_attachments(attachments, tracks);
delete attachments; delete attachments;
} }

View File

@ -76,7 +76,6 @@ using namespace std;
#define MODE_CHAPTERS 3 #define MODE_CHAPTERS 3
#define MODE_CUESHEET 4 #define MODE_CUESHEET 4
vector<track_spec_t> tracks;
bool no_variable_data = false; bool no_variable_data = false;
void void
@ -150,7 +149,8 @@ static bool parse_fully = false;
void void
parse_args(vector<string> args, parse_args(vector<string> args,
string &file_name, string &file_name,
int &mode) { int &mode,
vector<track_spec_t> &tracks) {
int i; int i;
char *colon, *copy; char *colon, *copy;
const char *sub_charset; const char *sub_charset;
@ -365,6 +365,7 @@ main(int argc,
char **argv) { char **argv) {
string input_file; string input_file;
int mode; int mode;
vector<track_spec_t> tracks;
#if defined(SYS_UNIX) #if defined(SYS_UNIX)
nice(2); nice(2);
@ -383,9 +384,9 @@ main(int argc,
xml_element_map_init(); xml_element_map_init();
parse_args(command_line_utf8(argc, argv), input_file, mode); parse_args(command_line_utf8(argc, argv), input_file, mode, tracks);
if (mode == MODE_TRACKS) { if (mode == MODE_TRACKS) {
extract_tracks(input_file.c_str()); extract_tracks(input_file.c_str(), tracks);
if (verbose == 0) if (verbose == 0)
mxinfo(_("progress: 100%%\n")); mxinfo(_("progress: 100%%\n"));
@ -394,7 +395,7 @@ main(int argc,
extract_tags(input_file.c_str(), parse_fully); extract_tags(input_file.c_str(), parse_fully);
else if (mode == MODE_ATTACHMENTS) else if (mode == MODE_ATTACHMENTS)
extract_attachments(input_file.c_str(), parse_fully); extract_attachments(input_file.c_str(), tracks, parse_fully);
else if (mode == MODE_CHAPTERS) else if (mode == MODE_CHAPTERS)
extract_chapters(input_file.c_str(), chapter_format_simple, parse_fully); extract_chapters(input_file.c_str(), chapter_format_simple, parse_fully);

View File

@ -46,7 +46,6 @@ struct track_spec_t {
bool done; bool done;
}; };
extern vector<track_spec_t> tracks;
extern bool no_variable_data; extern bool no_variable_data;
#define fits_parent(l, p) (l->GetElementPosition() < \ #define fits_parent(l, p) (l->GetElementPosition() < \
@ -59,11 +58,12 @@ extern bool no_variable_data;
void show_element(EbmlElement *l, int level, const char *fmt, ...); void show_element(EbmlElement *l, int level, const char *fmt, ...);
void show_error(const char *fmt, ...); void show_error(const char *fmt, ...);
bool extract_tracks(const char *file_name); bool extract_tracks(const char *file_name, vector<track_spec_t> &tracks);
void extract_tags(const char *file_name, bool parse_fully); void extract_tags(const char *file_name, bool parse_fully);
void extract_chapters(const char *file_name, bool chapter_format_simple, void extract_chapters(const char *file_name, bool chapter_format_simple,
bool parse_fully); bool parse_fully);
void extract_attachments(const char *file_name, bool parse_fully); void extract_attachments(const char *file_name,
vector<track_spec_t> &tracks, bool parse_fully);
void extract_cuesheet(const char *file_name, bool parse_fully); void extract_cuesheet(const char *file_name, bool parse_fully);
void write_cuesheet(const char *file_name, KaxChapters &chapters, void write_cuesheet(const char *file_name, KaxChapters &chapters,
KaxTags &tags, int64_t tuid, mm_io_c &out); KaxTags &tags, int64_t tuid, mm_io_c &out);

View File

@ -66,7 +66,8 @@ static vector<xtr_base_c *> extractors;
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
static void static void
create_extractors(KaxTracks &kax_tracks) { create_extractors(KaxTracks &kax_tracks,
vector<track_spec_t> &tracks) {
int i; int i;
for (i = 0; i < kax_tracks.ListSize(); i++) { for (i = 0; i < kax_tracks.ListSize(); i++) {
@ -219,7 +220,8 @@ close_extractors() {
static void static void
write_all_cuesheets(KaxChapters &chapters, write_all_cuesheets(KaxChapters &chapters,
KaxTags &tags) { KaxTags &tags,
vector<track_spec_t> &tracks) {
int i; int i;
mm_io_c *out; mm_io_c *out;
@ -261,7 +263,8 @@ write_all_cuesheets(KaxChapters &chapters,
} }
bool bool
extract_tracks(const char *file_name) { extract_tracks(const char *file_name,
vector<track_spec_t> &tracks) {
int upper_lvl_el; int upper_lvl_el;
// Elements for different levels // Elements for different levels
EbmlElement *l0 = NULL, *l1 = NULL, *l2 = NULL, *l3 = NULL; EbmlElement *l0 = NULL, *l1 = NULL, *l2 = NULL, *l3 = NULL;
@ -373,7 +376,7 @@ extract_tracks(const char *file_name) {
tracks_found = true; tracks_found = true;
l1->Read(*es, KaxTracks::ClassInfos.Context, upper_lvl_el, l2, true); l1->Read(*es, KaxTracks::ClassInfos.Context, upper_lvl_el, l2, true);
create_extractors(*dynamic_cast<KaxTracks *>(l1)); create_extractors(*dynamic_cast<KaxTracks *>(l1), tracks);
} else if (EbmlId(*l1) == KaxCluster::ClassInfos.GlobalId) { } else if (EbmlId(*l1) == KaxCluster::ClassInfos.GlobalId) {
show_element(l1, 1, _("Cluster")); show_element(l1, 1, _("Cluster"));
@ -494,7 +497,7 @@ extract_tracks(const char *file_name) {
delete es; delete es;
delete in; delete in;
write_all_cuesheets(all_chapters, all_tags); write_all_cuesheets(all_chapters, all_tags, tracks);
// Now just close the files and go to sleep. Mummy will sing you a // Now just close the files and go to sleep. Mummy will sing you a
// lullaby. Just close your eyes, listen to her sweet voice, singing, // lullaby. Just close your eyes, listen to her sweet voice, singing,