From fb3b7fd8b27dc930bfbcb6faf4ac5fe0a1de48b7 Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Wed, 3 Aug 2005 10:26:08 +0000 Subject: [PATCH] Made the mx* output routines write to an instance of mm_io_c and added an option for mkvinfo ("-o") for redirecting its output to a file. --- ChangeLog | 4 ++++ src/base64tool.cpp | 2 ++ src/common/common.cpp | 23 +++++++++++++++++------ src/common/common.h | 5 +++++ src/common/mm_io.cpp | 5 +++++ src/common/mm_io.h | 3 +++ src/extract/mkvextract.cpp | 2 ++ src/info/mkvinfo.cpp | 17 +++++++++++++++++ src/merge/output_control.cpp | 1 + 9 files changed, 56 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index 48479904c..1f1a1b2da 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,9 @@ 2005-08-03 Moritz Bunkus + * mkvinfo: new feature: Added a command line switch "-o" for + redirecting the output to a file (for systems which re-interpret + stdout). + * mkvmerge: bug fix: The combination of using external timecode files and video tracks with B frames was not working as intended. The user had to order the timecodes in the timecode file diff --git a/src/base64tool.cpp b/src/base64tool.cpp index 70c4f9f26..ea5aacd11 100644 --- a/src/base64tool.cpp +++ b/src/base64tool.cpp @@ -49,6 +49,8 @@ main(int argc, mm_io_c *in, *out; mm_text_io_c *intext; + init_mm_stdio(); + if (argc < 4) usage(0); diff --git a/src/common/common.cpp b/src/common/common.cpp index 787769804..fe7733269 100644 --- a/src/common/common.cpp +++ b/src/common/common.cpp @@ -61,6 +61,7 @@ using namespace libebml; #include "hacks.h" #include "mm_io.h" #include "random.h" +#include "smart_pointers.h" int verbose = 1; bool suppress_warnings = false; @@ -1270,13 +1271,24 @@ mxprints(char *dst, va_end(ap); } +counted_ptr mm_stdio; + +void +init_mm_stdio() { + set_mm_stdio(new mm_stdio_c()); +} + +void +set_mm_stdio(mm_io_c *stdio) { + mm_stdio = counted_ptr(stdio); +} + static void mxmsg(int level, const char *fmt, va_list ap) { string new_fmt, output; bool nl; - FILE *stream; char *prefix; fix_format(fmt, new_fmt); @@ -1287,7 +1299,6 @@ mxmsg(int level, } else nl = false; - stream = stdout; prefix = NULL; if (level == MXMSG_ERROR) @@ -1298,14 +1309,14 @@ mxmsg(int level, prefix = "DBG> "; if (nl) - fprintf(stream, "\n"); + mm_stdio->puts("\n"); if (prefix != NULL) - fprintf(stream, prefix); + mm_stdio->puts(prefix); output = from_utf8(cc_stdio, mxvsprintf(new_fmt.c_str(), ap)); - fputs(output.c_str(), stream); - fflush(stream); + mm_stdio->puts(output); + mm_stdio->flush(); } void diff --git a/src/common/common.h b/src/common/common.h index 57758e969..25292bedc 100644 --- a/src/common/common.h +++ b/src/common/common.h @@ -139,6 +139,11 @@ void MTX_DLL_API _trace(const char *func, const char *file, int line); void MTX_DLL_API mxhexdump(int level, const unsigned char *buffer, int lenth); +class mm_io_c; + +void MTX_DLL_API init_mm_stdio(); +void MTX_DLL_API set_mm_stdio(mm_io_c *); + #define get_fourcc(b) get_uint32_be(b) uint16_t MTX_DLL_API get_uint16_le(const void *buf); uint32_t MTX_DLL_API get_uint24_le(const void *buf); diff --git a/src/common/mm_io.cpp b/src/common/mm_io.cpp index 561f4a093..2af84a3cd 100644 --- a/src/common/mm_io.cpp +++ b/src/common/mm_io.cpp @@ -1166,3 +1166,8 @@ mm_stdio_c::write(const void *buffer, void mm_stdio_c::close() { } + +void +mm_stdio_c::flush() { + fflush(stdout); +} diff --git a/src/common/mm_io.h b/src/common/mm_io.h index 32fe74cee..1a582ff8b 100644 --- a/src/common/mm_io.h +++ b/src/common/mm_io.h @@ -86,6 +86,8 @@ public: virtual void skip(int64 numbytes); virtual size_t write(const void *buffer, size_t size) = 0; virtual bool eof() = 0; + virtual void flush() { + } virtual string get_file_name() const = 0; @@ -255,6 +257,7 @@ public: virtual string get_file_name() const { return ""; } + virtual void flush(); }; #endif // __MM_IO_H diff --git a/src/extract/mkvextract.cpp b/src/extract/mkvextract.cpp index c830a0752..1b1a6b13e 100644 --- a/src/extract/mkvextract.cpp +++ b/src/extract/mkvextract.cpp @@ -384,6 +384,8 @@ main(int argc, int mode; vector tracks; + init_mm_stdio(); + #if defined(SYS_UNIX) nice(2); #endif diff --git a/src/info/mkvinfo.cpp b/src/info/mkvinfo.cpp index b161dceb5..11fd84f1e 100644 --- a/src/info/mkvinfo.cpp +++ b/src/info/mkvinfo.cpp @@ -142,6 +142,8 @@ usage() { " description of what mkvinfo outputs.\n" " -c, --checksum Calculate and display checksums of frame contents.\n" " -s, --summary Only show summaries of the contents, not each element.\n" + " -o, --output file.ext\n" + " Redirect the output to a file named 'file.ext'.\n" " -h, --help Show this help.\n" " -V, --version Show version information.\n")); #else @@ -153,6 +155,8 @@ usage() { " description of what mkvinfo outputs.\n" " -c, --checksum Calculate and display checksums of frame contents.\n" " -s, --summary Only show summaries of the contents, not each element.\n" + " -o, --output file.ext\n" + " Redirect the output to a file named 'file.ext'.\n" " -h, --help Show this help.\n" " -V, --version Show version information.\n")); #endif @@ -282,6 +286,16 @@ parse_args(vector args, } else if ((args[i] == "-s") || (args[i] == "--summary")) { calc_checksums = true; show_summary = true; + } else if ((args[i] == "-o") || (args[i] == "--output")) { + if ((i + 1) == args.size()) + mxerror("'%s' is missing the file name.\n", args[i].c_str()); + try { + set_mm_stdio(new mm_file_io_c(args[i + 1], MODE_CREATE)); + ++i; + } catch(...) { + mxerror("Could not open the file '%s' for directing the output.\n", + args[i + 1].c_str()); + } } else if (file_name != "") mxerror("Only one input file is allowed.\n"); else @@ -1959,6 +1973,8 @@ process_file(const string &file_name) { void setup() { + init_mm_stdio(); + #if defined(HAVE_LIBINTL_H) if (setlocale(LC_MESSAGES, "") == NULL) mxerror("Could not set the locale properly. Check the " @@ -2006,6 +2022,7 @@ console_main(vector args) { int main(int argc, char **argv) { + init_mm_stdio(); return console_main(command_line_utf8(argc, argv)); } diff --git a/src/merge/output_control.cpp b/src/merge/output_control.cpp index fcad67933..165587732 100644 --- a/src/merge/output_control.cpp +++ b/src/merge/output_control.cpp @@ -1953,6 +1953,7 @@ main_loop() { */ void setup() { + init_mm_stdio(); #if ! defined(SYS_WINDOWS) && defined(HAVE_LIBINTL_H) if (setlocale(LC_MESSAGES, "") == NULL) mxerror("The locale could not be set properly. Check the "