Commit ccd96bb4 authored by twanvl's avatar twanvl

Added --export command line flag for using export templates, --export-image now export images

parent 57ea6d26
......@@ -34,7 +34,7 @@ CLISetInterface::CLISetInterface(const SetP& set, bool quiet)
setSet(set);
// show welcome logo
if (!quiet) showWelcome();
print_pending_errors();
cli.print_pending_errors();
}
CLISetInterface::~CLISetInterface() {
......@@ -90,7 +90,7 @@ void CLISetInterface::run_interactive() {
String command = cli.getLine();
if (command.empty() && !cli.canGetLine()) break;
handleCommand(command);
print_pending_errors();
cli.print_pending_errors();
cli.flush();
cli.flushRaw();
}
......@@ -272,11 +272,3 @@ void CLISetInterface::handleCommand(const String& command) {
}
}
#endif
void CLISetInterface::print_pending_errors() {
MessageType type;
String msg;
while (get_queued_message(type,msg)) {
cli.show_message(type,msg);
}
}
......@@ -40,7 +40,6 @@ class CLISetInterface : public SetView {
#if USE_SCRIPT_PROFILING
void showProfilingStats(const FunctionProfile& parent, int level = 0);
#endif
void print_pending_errors();
/// our own context, when no set is loaded
Context& getContext();
......
......@@ -55,7 +55,7 @@ void TextIOHandler::init() {
have_console = false;
have_stderr = false;
// Use console mode if one of the cli flags is passed
static const Char* redirect_flags[] = {_("-?"),_("--help"),_("-v"),_("--version"),_("--cli"),_("-c"),_("--export"),_("--create-installer")};
static const Char* redirect_flags[] = {_("-?"),_("--help"),_("-v"),_("--version"),_("--cli"),_("-c"),_("--export"),_("--export-images"),_("--create-installer")};
for (int i = 1 ; i < wxTheApp->argc ; ++i) {
for (int j = 0 ; j < sizeof(redirect_flags)/sizeof(redirect_flags[0]) ; ++j) {
if (String(wxTheApp->argv[i]) == redirect_flags[j]) {
......@@ -152,12 +152,12 @@ void TextIOHandler::flushRaw() {
if (!buffer.empty()) {
#ifdef UNICODE
wxCharBuffer buf = buffer.mb_str(wxConvUTF8);
fputs(buf,stdout);
fputs(buf,stream);
#else
fputs(buffer.c_str(),stdout);
fputs(buffer.c_str(),stream);
#endif
}
fflush(stdout);
fflush(stream);
// clear
buffer.clear();
raw_mode_status = 0;
......@@ -166,7 +166,8 @@ void TextIOHandler::flushRaw() {
// ----------------------------------------------------------------------------- : Errors
void TextIOHandler::show_message(MessageType type, String const& message) {
stream = stdout;
flush();
stream = stderr;
if (type == MESSAGE_WARNING) {
*this << YELLOW << _("WARNING: ") << NORMAL << replace_all(message,_("\n"),_("\n ")) << ENDL;
} else {
......@@ -176,3 +177,17 @@ void TextIOHandler::show_message(MessageType type, String const& message) {
stream = stdout;
if (raw_mode) raw_mode_status = max(raw_mode_status, type == MESSAGE_WARNING ? 1 : 2);
}
void TextIOHandler::print_pending_errors() {
MessageType type;
String msg;
while (get_queued_message(type,msg)) {
if (haveConsole()) {
cli.show_message(type,msg);
cli.flush();
} else {
// no console, use a messagebox instead
wxMessageBox(msg, wxMessageBoxCaptionStr, type == MESSAGE_INFO ? wxICON_INFORMATION : type == MESSAGE_WARNING ? wxICON_WARNING : wxICON_ERROR);
}
}
}
......@@ -38,6 +38,7 @@ class TextIOHandler {
/// Show an error or warning message
void show_message(MessageType type, String const& message);
void print_pending_errors();
/// Enable raw mode
void enableRaw();
......
......@@ -45,6 +45,7 @@ DWORD WINAPI TransferThread(Transfer*);
BOOL WINAPI HandleCtrlEvent(DWORD type);
void CopyFileBuffer(HANDLE output, char* buffer, DWORD size);
void InitEscapeTranslation(HANDLE console);
void FinishEscapeTranslation(HANDLE console);
void PerformEscapeCode(HANDLE console, char command, int argc, int argv[]);
/// The child process
......@@ -54,14 +55,15 @@ PROCESS_INFORMATION child_process_info;
HANDLE in_mine, in_theirs, in_real;
HANDLE out_mine, out_theirs, out_real;
HANDLE err_mine, err_theirs, err_real;
bool need_redirection;
// ----------------------------------------------------------------------------- : Main function
const char* redirect_flags[] = {"-?","--help","-v","--version","--cli","-c","--export","--create-installer"};
const char* redirect_flags[] = {"-?","/?","--help","-v","--version","--cli","-c","--export","--export-images","--create-installer"};
int main(int argc, char** argv) {
// determine whether we need to wrap console i/o
bool need_redirection = false;
need_redirection = false;
for (int i = 1 ; i < argc ; ++i) {
for (int j = 0 ; j < sizeof(redirect_flags)/sizeof(redirect_flags[0]) ; ++j) {
if (strcmp(argv[i],redirect_flags[j]) == 0) {
......@@ -115,6 +117,7 @@ int main(int argc, char** argv) {
out_real = GetStdHandle(STD_OUTPUT_HANDLE);
err_real = GetStdHandle(STD_ERROR_HANDLE);
InitEscapeTranslation(out_real);
InitEscapeTranslation(err_real);
// start threads
Transfer tranfer_in = {in_real, in_mine, false};
......@@ -134,6 +137,7 @@ int main(int argc, char** argv) {
// start the child program
if (!CreateProcess(app_path,command_line,NULL,NULL,TRUE,0,NULL,NULL,&child_startup_info,&child_process_info)) {
fprintf(stderr, "Unable to start child process.\n");
ExitProcess(1);
}
......@@ -146,6 +150,10 @@ int main(int argc, char** argv) {
}
// That's all folks!
if (need_redirection) {
FinishEscapeTranslation(out_real);
FinishEscapeTranslation(err_real);
}
return exit_code;
}
......@@ -168,6 +176,10 @@ BOOL WINAPI HandleCtrlEvent(DWORD type) {
TerminateProcess(child_process_info.hProcess,1);
}
// exit this process
if (need_redirection) {
FinishEscapeTranslation(out_real);
FinishEscapeTranslation(err_real);
}
ExitProcess(exit_code);
return TRUE;
}
......@@ -251,6 +263,12 @@ void InitEscapeTranslation(HANDLE console) {
original_attributes = screen_buffer.wAttributes;
}
/// Cleanup for escape translation: put things back to normal
void FinishEscapeTranslation(HANDLE console) {
CONSOLE_SCREEN_BUFFER_INFO screen_buffer;
SetConsoleTextAttribute(console, original_attributes);
}
/// Perform an escape code
void PerformEscapeCode(HANDLE console, char command, int argc, int argv[]) {
switch (command) {
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment