mirror of
https://gitlab.com/mbunkus/mkvtoolnix.git
synced 2024-12-24 11:54:01 +00:00
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.
This commit is contained in:
parent
934de763c7
commit
fb3b7fd8b2
@ -1,5 +1,9 @@
|
||||
2005-08-03 Moritz Bunkus <moritz@bunkus.org>
|
||||
|
||||
* 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
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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_io_c> 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<mm_io_c>(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
|
||||
|
@ -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);
|
||||
|
@ -1166,3 +1166,8 @@ mm_stdio_c::write(const void *buffer,
|
||||
void
|
||||
mm_stdio_c::close() {
|
||||
}
|
||||
|
||||
void
|
||||
mm_stdio_c::flush() {
|
||||
fflush(stdout);
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -384,6 +384,8 @@ main(int argc,
|
||||
int mode;
|
||||
vector<track_spec_t> tracks;
|
||||
|
||||
init_mm_stdio();
|
||||
|
||||
#if defined(SYS_UNIX)
|
||||
nice(2);
|
||||
#endif
|
||||
|
@ -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<string> 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<string> args) {
|
||||
int
|
||||
main(int argc,
|
||||
char **argv) {
|
||||
init_mm_stdio();
|
||||
return console_main(command_line_utf8(argc, argv));
|
||||
}
|
||||
|
||||
|
@ -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 "
|
||||
|
Loading…
Reference in New Issue
Block a user