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) ...@@ -34,7 +34,7 @@ CLISetInterface::CLISetInterface(const SetP& set, bool quiet)
setSet(set); setSet(set);
// show welcome logo // show welcome logo
if (!quiet) showWelcome(); if (!quiet) showWelcome();
print_pending_errors(); cli.print_pending_errors();
} }
CLISetInterface::~CLISetInterface() { CLISetInterface::~CLISetInterface() {
...@@ -90,7 +90,7 @@ void CLISetInterface::run_interactive() { ...@@ -90,7 +90,7 @@ void CLISetInterface::run_interactive() {
String command = cli.getLine(); String command = cli.getLine();
if (command.empty() && !cli.canGetLine()) break; if (command.empty() && !cli.canGetLine()) break;
handleCommand(command); handleCommand(command);
print_pending_errors(); cli.print_pending_errors();
cli.flush(); cli.flush();
cli.flushRaw(); cli.flushRaw();
} }
...@@ -272,11 +272,3 @@ void CLISetInterface::handleCommand(const String& command) { ...@@ -272,11 +272,3 @@ void CLISetInterface::handleCommand(const String& command) {
} }
} }
#endif #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 { ...@@ -40,7 +40,6 @@ class CLISetInterface : public SetView {
#if USE_SCRIPT_PROFILING #if USE_SCRIPT_PROFILING
void showProfilingStats(const FunctionProfile& parent, int level = 0); void showProfilingStats(const FunctionProfile& parent, int level = 0);
#endif #endif
void print_pending_errors();
/// our own context, when no set is loaded /// our own context, when no set is loaded
Context& getContext(); Context& getContext();
......
...@@ -55,7 +55,7 @@ void TextIOHandler::init() { ...@@ -55,7 +55,7 @@ void TextIOHandler::init() {
have_console = false; have_console = false;
have_stderr = false; have_stderr = false;
// Use console mode if one of the cli flags is passed // 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 i = 1 ; i < wxTheApp->argc ; ++i) {
for (int j = 0 ; j < sizeof(redirect_flags)/sizeof(redirect_flags[0]) ; ++j) { for (int j = 0 ; j < sizeof(redirect_flags)/sizeof(redirect_flags[0]) ; ++j) {
if (String(wxTheApp->argv[i]) == redirect_flags[j]) { if (String(wxTheApp->argv[i]) == redirect_flags[j]) {
...@@ -152,12 +152,12 @@ void TextIOHandler::flushRaw() { ...@@ -152,12 +152,12 @@ void TextIOHandler::flushRaw() {
if (!buffer.empty()) { if (!buffer.empty()) {
#ifdef UNICODE #ifdef UNICODE
wxCharBuffer buf = buffer.mb_str(wxConvUTF8); wxCharBuffer buf = buffer.mb_str(wxConvUTF8);
fputs(buf,stdout); fputs(buf,stream);
#else #else
fputs(buffer.c_str(),stdout); fputs(buffer.c_str(),stream);
#endif #endif
} }
fflush(stdout); fflush(stream);
// clear // clear
buffer.clear(); buffer.clear();
raw_mode_status = 0; raw_mode_status = 0;
...@@ -166,7 +166,8 @@ void TextIOHandler::flushRaw() { ...@@ -166,7 +166,8 @@ void TextIOHandler::flushRaw() {
// ----------------------------------------------------------------------------- : Errors // ----------------------------------------------------------------------------- : Errors
void TextIOHandler::show_message(MessageType type, String const& message) { void TextIOHandler::show_message(MessageType type, String const& message) {
stream = stdout; flush();
stream = stderr;
if (type == MESSAGE_WARNING) { if (type == MESSAGE_WARNING) {
*this << YELLOW << _("WARNING: ") << NORMAL << replace_all(message,_("\n"),_("\n ")) << ENDL; *this << YELLOW << _("WARNING: ") << NORMAL << replace_all(message,_("\n"),_("\n ")) << ENDL;
} else { } else {
...@@ -176,3 +177,17 @@ void TextIOHandler::show_message(MessageType type, String const& message) { ...@@ -176,3 +177,17 @@ void TextIOHandler::show_message(MessageType type, String const& message) {
stream = stdout; stream = stdout;
if (raw_mode) raw_mode_status = max(raw_mode_status, type == MESSAGE_WARNING ? 1 : 2); 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 { ...@@ -38,6 +38,7 @@ class TextIOHandler {
/// Show an error or warning message /// Show an error or warning message
void show_message(MessageType type, String const& message); void show_message(MessageType type, String const& message);
void print_pending_errors();
/// Enable raw mode /// Enable raw mode
void enableRaw(); void enableRaw();
......
...@@ -45,6 +45,7 @@ DWORD WINAPI TransferThread(Transfer*); ...@@ -45,6 +45,7 @@ DWORD WINAPI TransferThread(Transfer*);
BOOL WINAPI HandleCtrlEvent(DWORD type); BOOL WINAPI HandleCtrlEvent(DWORD type);
void CopyFileBuffer(HANDLE output, char* buffer, DWORD size); void CopyFileBuffer(HANDLE output, char* buffer, DWORD size);
void InitEscapeTranslation(HANDLE console); void InitEscapeTranslation(HANDLE console);
void FinishEscapeTranslation(HANDLE console);
void PerformEscapeCode(HANDLE console, char command, int argc, int argv[]); void PerformEscapeCode(HANDLE console, char command, int argc, int argv[]);
/// The child process /// The child process
...@@ -54,14 +55,15 @@ PROCESS_INFORMATION child_process_info; ...@@ -54,14 +55,15 @@ PROCESS_INFORMATION child_process_info;
HANDLE in_mine, in_theirs, in_real; HANDLE in_mine, in_theirs, in_real;
HANDLE out_mine, out_theirs, out_real; HANDLE out_mine, out_theirs, out_real;
HANDLE err_mine, err_theirs, err_real; HANDLE err_mine, err_theirs, err_real;
bool need_redirection;
// ----------------------------------------------------------------------------- : Main function // ----------------------------------------------------------------------------- : 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) { int main(int argc, char** argv) {
// determine whether we need to wrap console i/o // 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 i = 1 ; i < argc ; ++i) {
for (int j = 0 ; j < sizeof(redirect_flags)/sizeof(redirect_flags[0]) ; ++j) { for (int j = 0 ; j < sizeof(redirect_flags)/sizeof(redirect_flags[0]) ; ++j) {
if (strcmp(argv[i],redirect_flags[j]) == 0) { if (strcmp(argv[i],redirect_flags[j]) == 0) {
...@@ -115,6 +117,7 @@ int main(int argc, char** argv) { ...@@ -115,6 +117,7 @@ int main(int argc, char** argv) {
out_real = GetStdHandle(STD_OUTPUT_HANDLE); out_real = GetStdHandle(STD_OUTPUT_HANDLE);
err_real = GetStdHandle(STD_ERROR_HANDLE); err_real = GetStdHandle(STD_ERROR_HANDLE);
InitEscapeTranslation(out_real); InitEscapeTranslation(out_real);
InitEscapeTranslation(err_real);
// start threads // start threads
Transfer tranfer_in = {in_real, in_mine, false}; Transfer tranfer_in = {in_real, in_mine, false};
...@@ -134,6 +137,7 @@ int main(int argc, char** argv) { ...@@ -134,6 +137,7 @@ int main(int argc, char** argv) {
// start the child program // start the child program
if (!CreateProcess(app_path,command_line,NULL,NULL,TRUE,0,NULL,NULL,&child_startup_info,&child_process_info)) { 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); ExitProcess(1);
} }
...@@ -146,6 +150,10 @@ int main(int argc, char** argv) { ...@@ -146,6 +150,10 @@ int main(int argc, char** argv) {
} }
// That's all folks! // That's all folks!
if (need_redirection) {
FinishEscapeTranslation(out_real);
FinishEscapeTranslation(err_real);
}
return exit_code; return exit_code;
} }
...@@ -168,6 +176,10 @@ BOOL WINAPI HandleCtrlEvent(DWORD type) { ...@@ -168,6 +176,10 @@ BOOL WINAPI HandleCtrlEvent(DWORD type) {
TerminateProcess(child_process_info.hProcess,1); TerminateProcess(child_process_info.hProcess,1);
} }
// exit this process // exit this process
if (need_redirection) {
FinishEscapeTranslation(out_real);
FinishEscapeTranslation(err_real);
}
ExitProcess(exit_code); ExitProcess(exit_code);
return TRUE; return TRUE;
} }
...@@ -251,6 +263,12 @@ void InitEscapeTranslation(HANDLE console) { ...@@ -251,6 +263,12 @@ void InitEscapeTranslation(HANDLE console) {
original_attributes = screen_buffer.wAttributes; 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 /// Perform an escape code
void PerformEscapeCode(HANDLE console, char command, int argc, int argv[]) { void PerformEscapeCode(HANDLE console, char command, int argc, int argv[]) {
switch (command) { 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