Improve the code by static code analysis [1/3]: Bug fixes
[amule.git] / src / ExternalConnector.cpp
blob2e06c91363a41f9eb84194ec811bd0b30fd1cbf9
1 //
2 // This file is part of the aMule Project.
3 //
4 // Copyright (c) 2004-2011 aMule Team ( admin@amule.org / http://www.amule.org )
5 //
6 // Any parts of this program derived from the xMule, lMule or eMule project,
7 // or contributed by third-party developers are copyrighted by their
8 // respective authors.
9 //
10 // This program is free software; you can redistribute it and/or modify
11 // it under the terms of the GNU General Public License as published by
12 // the Free Software Foundation; either version 2 of the License, or
13 // (at your option) any later version.
15 // This program is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU General Public License for more details.
20 // You should have received a copy of the GNU General Public License
21 // along with this program; if not, write to the Free Software
22 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
25 #include "ExternalConnector.h"
27 #ifdef HAVE_CONFIG_H
28 #include "config.h" // Needed for VERSION and readline detection
29 #endif
31 #include <common/ClientVersion.h>
32 #include <common/Format.h> // Needed for CFormat
33 #include <wx/tokenzr.h> // For wxStringTokenizer
35 // For readline
36 #ifdef HAVE_LIBREADLINE
37 #if defined(HAVE_READLINE_READLINE_H)
38 #include <readline/readline.h> // Do_not_auto_remove
39 #elif defined(HAVE_READLINE_H)
40 #include <readline.h> // Do_not_auto_remove
41 #else /* !defined(HAVE_READLINE_H) */
42 extern "C" char *readline (const char*);
43 #endif /* !defined(HAVE_READLINE_H) */
44 #else /* !defined(HAVE_READLINE_READLINE_H) */
45 /* no readline */
46 #endif /* HAVE_LIBREADLINE */
48 // For history
49 #ifdef HAVE_READLINE_HISTORY
50 #if defined(HAVE_READLINE_HISTORY_H)
51 #include <readline/history.h> // Do_not_auto_remove
52 #elif defined(HAVE_HISTORY_H)
53 #include <history.h> // Do_not_auto_remove
54 #else /* !defined(HAVE_HISTORY_H) */
55 extern "C" void add_history (const char*);
56 #endif /* defined(HAVE_READLINE_HISTORY_H) */
57 #else
58 /* no history */
59 #endif /* HAVE_READLINE_HISTORY */
62 #include <ec/cpp/ECFileConfig.h> // Needed for CECFileConfig
63 #include <common/MD5Sum.h>
64 #include "OtherFunctions.h" // Needed for GetPassword()
66 #ifdef _MSC_VER // silly warnings about deprecated functions
67 #pragma warning(disable:4996)
68 #endif
70 //-------------------------------------------------------------------
72 CCommandTree::~CCommandTree()
74 DeleteContents(m_subcommands);
78 CCommandTree* CCommandTree::AddCommand(CCommandTree* command)
80 command->m_parent = this;
81 const wxString& cmd = command->m_command;
82 CmdPos_t it;
83 for (it = m_subcommands.begin(); it != m_subcommands.end(); ++it) {
84 if ((*it)->m_command > cmd) {
85 break;
88 m_subcommands.insert(it, command);
89 return command;
93 int CCommandTree::FindCommandId(const wxString& command, wxString& args, wxString& cmdstr) const
95 wxString cmd = command.BeforeFirst(wxT(' ')).Lower();
96 for (CmdPosConst_t it = m_subcommands.begin(); it != m_subcommands.end(); ++it) {
97 if ((*it)->m_command.Lower() == cmd) {
98 args = command.AfterFirst(wxT(' ')).Trim(false);
99 return (*it)->FindCommandId(args, args, cmdstr);
102 cmdstr = GetFullCommand().Lower();
103 if (m_params == CMD_PARAM_ALWAYS && args.IsEmpty()) {
104 return CMD_ERR_MUST_HAVE_PARAM;
105 } else if (m_params == CMD_PARAM_NEVER && !args.IsEmpty()) {
106 return CMD_ERR_NO_PARAM;
107 } else {
108 if ((m_cmd_id >= 0) && (m_cmd_id & CMD_DEPRECATED)) {
109 m_app.Show(wxT('\n') + m_verbose + wxT('\n'));
110 return m_cmd_id & ~CMD_DEPRECATED;
111 } else {
112 return m_cmd_id;
118 wxString CCommandTree::GetFullCommand() const
120 wxString cmd = m_command;
122 const CCommandTree *parent = m_parent;
123 while (parent && parent->m_parent) {
124 cmd = parent->m_command + wxT(" ") + cmd;
125 parent = parent->m_parent;
128 return cmd;
132 void CCommandTree::PrintHelpFor(const wxString& command) const
134 wxString cmd = command.BeforeFirst(wxT(' ')).Lower();
135 if (!cmd.IsEmpty()) {
136 for (CmdPosConst_t it = m_subcommands.begin(); it != m_subcommands.end(); ++it) {
137 if ((*it)->m_command.Lower() == cmd) {
138 (*it)->PrintHelpFor(command.AfterFirst(wxT(' ')).Trim(false));
139 return;
142 if (m_parent) {
143 m_app.Show(CFormat(_("Unknown extension '%s' for the '%s' command.\n")) % command % GetFullCommand());
144 } else {
145 m_app.Show(CFormat(_("Unknown command '%s'.\n")) % command);
147 } else {
148 wxString fullcmd = GetFullCommand();
149 if (!fullcmd.IsEmpty()) {
150 m_app.Show(fullcmd.Upper() + wxT(": ") + wxGetTranslation(m_short) + wxT("\n"));
151 if (!m_verbose.IsEmpty()) {
152 m_app.Show(wxT("\n"));
153 m_app.Show(wxGetTranslation(m_verbose));
156 if (m_params == CMD_PARAM_NEVER) {
157 m_app.Show(_("\nThis command cannot have an argument.\n"));
158 } else if (m_params == CMD_PARAM_ALWAYS) {
159 m_app.Show(_("\nThis command must have an argument.\n"));
161 if (m_cmd_id == CMD_ERR_INCOMPLETE) {
162 m_app.Show(_("\nThis command is incomplete, you must use one of the extensions below.\n"));
164 if (!m_subcommands.empty()) {
165 CmdPosConst_t it;
166 int maxlen = 0;
167 if (m_parent) {
168 m_app.Show(_("\nAvailable extensions:\n"));
169 } else {
170 m_app.Show(_("Available commands:\n"));
172 for (it = m_subcommands.begin(); it != m_subcommands.end(); ++it) {
173 if (!((*it)->m_cmd_id >= 0 && (*it)->m_cmd_id & CMD_DEPRECATED) || m_parent) {
174 int len = (*it)->m_command.Length();
175 if (len > maxlen) {
176 maxlen = len;
180 maxlen += 4;
181 for (it = m_subcommands.begin(); it != m_subcommands.end(); ++it) {
182 if (!((*it)->m_cmd_id >= 0 && (*it)->m_cmd_id & CMD_DEPRECATED) || m_parent) {
183 m_app.Show((*it)->m_command + wxString(wxT(' '), maxlen - (*it)->m_command.Length()) + wxGetTranslation((*it)->m_short) + wxT("\n"));
186 if (!m_parent) {
187 m_app.Show(CFormat(_("\nAll commands are case insensitive.\nType '%s <command>' to get detailed info on <command>.\n")) % wxT("help"));
191 m_app.Show(wxT("\n"));
194 //-------------------------------------------------------------------
196 CaMuleExternalConnector::CaMuleExternalConnector()
197 : m_configFile(NULL),
198 m_port(-1),
199 m_KeepQuiet(false),
200 m_Verbose(false),
201 m_interactive(false),
202 m_commands(*this),
203 m_ECClient(NULL),
204 m_InputLine(NULL),
205 m_NeedsConfigSave(false),
206 m_locale(NULL),
207 m_strFullVersion(NULL),
208 m_strOSDescription(NULL)
210 SetAppName(wxT("aMule")); // Do not change!
213 CaMuleExternalConnector::~CaMuleExternalConnector()
215 delete m_configFile;
216 delete m_locale;
217 free(m_strFullVersion);
218 free(m_strOSDescription);
221 void CaMuleExternalConnector::OnInitCommandSet()
223 m_commands.AddCommand(wxT("Quit"), CMD_ID_QUIT, wxTRANSLATE("Exits from the application."), wxEmptyString);
224 m_commands.AddCommand(wxT("Exit"), CMD_ID_QUIT, wxTRANSLATE("Exits from the application."), wxEmptyString);
225 m_commands.AddCommand(wxT("Help"), CMD_ID_HELP, wxTRANSLATE("Show help."),
226 /* TRANSLATORS:
227 Do not translate the word 'help', it is a command to the program! */
228 wxTRANSLATE("To get help on a command, type 'help <command>'.\nTo get the full command list type 'help'.\n"));
231 void CaMuleExternalConnector::Show(const wxString &s)
233 if( !m_KeepQuiet ) {
234 printf("%s", (const char *)unicode2char(s));
235 #ifdef __WXMSW__
236 fflush(stdout);
237 #endif
241 void CaMuleExternalConnector::ShowGreet()
243 wxString text = GetGreetingTitle();
244 int len = text.Length();
245 Show(wxT('\n') + wxString(wxT('-'), 22 + len) + wxT('\n'));
246 Show(wxT('|') + wxString(wxT(' '), 10) + text + wxString(wxT(' '), 10) + wxT('|') + wxT('\n'));
247 Show(wxString(wxT('-'), 22 + len) + wxT('\n'));
248 // Do not merge the line below, or translators could translate "Help"
249 Show(CFormat(_("\nUse '%s' for command list\n\n")) % wxT("Help"));
252 void CaMuleExternalConnector::Process_Answer(const wxString& answer)
254 wxStringTokenizer tokens(answer, wxT("\n"));
255 while ( tokens.HasMoreTokens() ) {
256 Show(wxT(" > ") + tokens.GetNextToken() + wxT("\n"));
260 bool CaMuleExternalConnector::Parse_Command(const wxString& buffer)
262 wxString cmd;
263 wxStringTokenizer tokens(buffer);
264 while (tokens.HasMoreTokens()) {
265 cmd += tokens.GetNextToken() + wxT(' ');
267 cmd.Trim(false);
268 cmd.Trim(true);
269 int cmd_ID = GetIDFromString(cmd);
270 if ( cmd_ID >= 0 ) {
271 cmd_ID = ProcessCommand(cmd_ID);
273 wxString error;
274 switch (cmd_ID) {
275 case CMD_ID_HELP:
276 m_commands.PrintHelpFor(GetCmdArgs());
277 break;
278 case CMD_ERR_SYNTAX:
279 error = _("Syntax error!");
280 break;
281 case CMD_ERR_PROCESS_CMD:
282 Show(_("Error processing command - should never happen! Report bug, please\n"));
283 break;
284 case CMD_ERR_NO_PARAM:
285 error = _("This command should not have any parameters.");
286 break;
287 case CMD_ERR_MUST_HAVE_PARAM:
288 error = _("This command must have a parameter.");
289 break;
290 case CMD_ERR_INVALID_ARG:
291 error = _("Invalid argument.");
292 break;
293 case CMD_ERR_INCOMPLETE:
294 error = _("This is an incomplete command.");
295 break;
297 if (!error.IsEmpty()) {
298 Show(error + wxT('\n'));
299 wxString helpStr(wxT("help"));
300 if (!GetLastCmdStr().IsEmpty()) {
301 helpStr << wxT(' ') << GetLastCmdStr();
303 Show(CFormat(_("Type '%s' to get more help.\n")) % helpStr);
305 return cmd_ID == CMD_ID_QUIT;
308 void CaMuleExternalConnector::GetCommand(const wxString &prompt, char* buffer, size_t buffer_size)
310 #ifdef HAVE_LIBREADLINE
311 char *text = readline(unicode2char(prompt + wxT("$ ")));
312 if (text && *text &&
313 (m_InputLine == 0 || strcmp(text,m_InputLine) != 0)) {
314 add_history (text);
316 if (m_InputLine)
317 free(m_InputLine);
318 m_InputLine = text;
319 #else
320 Show(prompt + wxT("$ "));
321 const char *text = fgets(buffer, buffer_size, stdin); // == buffer if ok, NULL if eof
322 #endif /* HAVE_LIBREADLINE */
323 if ( text ) {
324 size_t len = strlen(text);
325 if (len > buffer_size - 1) {
326 len = buffer_size - 1;
328 if (buffer != text) {
329 strncpy(buffer, text, len);
331 buffer[len] = 0;
332 } else {
333 strncpy(buffer, "quit", buffer_size);
337 void CaMuleExternalConnector::TextShell(const wxString &prompt)
339 char buffer[2048];
340 wxString buf;
342 bool The_End = false;
343 do {
344 GetCommand(prompt, buffer, sizeof buffer);
345 buf = char2unicode(buffer);
346 The_End = Parse_Command(buf);
347 } while ((!The_End) && (m_ECClient->IsSocketConnected()));
350 void CaMuleExternalConnector::ConnectAndRun(const wxString &ProgName, const wxString& ProgVersion)
352 if (m_NeedsConfigSave) {
353 SaveConfigFile();
354 return;
357 #ifdef SVNDATE
358 Show(CFormat(_("This is %s %s %s\n")) % wxString::FromAscii(m_appname) % wxT(VERSION) % wxT(SVNDATE));
359 #else
360 Show(CFormat(_("This is %s %s\n")) % wxString::FromAscii(m_appname) % wxT(VERSION));
361 #endif
363 // HostName, Port and Password
364 if ( m_password.IsEmpty() ) {
365 m_password = GetPassword(true);
366 // MD5 hash for an empty string, according to rfc1321.
367 if (m_password.Encode() == wxT("D41D8CD98F00B204E9800998ECF8427E")) {
368 m_password.Clear();
372 if (!m_password.IsEmpty()) {
374 // Create the socket
375 Show(_("\nCreating client...\n"));
376 m_ECClient = new CRemoteConnect(NULL);
377 m_ECClient->SetCapabilities(m_ZLIB, true, false); // ZLIB, UTF8 numbers, notification
379 // ConnectToCore is blocking since m_ECClient was initialized with NULL
380 if (!m_ECClient->ConnectToCore(m_host, m_port, wxT("foobar"), m_password.Encode(), ProgName, ProgVersion)) {
381 // no connection => close gracefully
382 if (!m_ECClient->GetServerReply().IsEmpty()) {
383 Show(CFormat(wxT("%s\n")) % m_ECClient->GetServerReply());
385 Show(CFormat(_("Connection Failed. Unable to connect to %s:%d\n")) % m_host % m_port);
386 } else {
387 // Authenticate ourselves
388 // ConnectToCore() already authenticated for us.
389 //m_ECClient->ConnectionEstablished();
390 Show(m_ECClient->GetServerReply()+wxT("\n"));
391 if (m_ECClient->IsSocketConnected()) {
392 if (m_interactive) {
393 ShowGreet();
395 Pre_Shell();
396 TextShell(ProgName);
397 Post_Shell();
398 if (m_interactive) {
399 Show(CFormat(_("\nOk, exiting %s...\n")) % ProgName);
403 m_ECClient->DestroySocket();
404 } else {
405 Show(_("Cannot connect with an empty password.\nYou must specify a password either in config file\nor on command-line, or enter one when asked.\n\nExiting...\n"));
409 void CaMuleExternalConnector::OnInitCmdLine(wxCmdLineParser& parser, const char* appname)
411 m_appname = appname;
413 parser.AddSwitch(wxEmptyString, wxT("help"),
414 _("Show this help text."),
415 wxCMD_LINE_PARAM_OPTIONAL);
416 parser.AddOption(wxT("h"), wxT("host"),
417 _("Host where aMule is running. (default: localhost)"),
418 wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL);
419 parser.AddOption(wxT("p"), wxT("port"),
420 _("aMule's port for External Connection. (default: 4712)"),
421 wxCMD_LINE_VAL_NUMBER, wxCMD_LINE_PARAM_OPTIONAL);
422 parser.AddOption(wxT("P"), wxT("password"),
423 _("External Connection password."),
424 wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL);
425 parser.AddOption(wxT("f"), wxT("config-file"),
426 _("Read configuration from file."),
427 wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL);
428 parser.AddSwitch(wxT("q"), wxT("quiet"),
429 _("Do not print any output to stdout."),
430 wxCMD_LINE_PARAM_OPTIONAL);
431 parser.AddSwitch(wxT("v"), wxT("verbose"),
432 _("Be verbose - show also debug messages."),
433 wxCMD_LINE_PARAM_OPTIONAL);
434 parser.AddOption(wxT("l"), wxT("locale"),
435 _("Sets program locale (language)."),
436 wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL);
437 parser.AddSwitch(wxT("w"), wxT("write-config"),
438 _("Write command line options to config file."),
439 wxCMD_LINE_PARAM_OPTIONAL);
440 parser.AddOption(wxEmptyString, wxT("create-config-from"),
441 _("Creates config file based on aMule's config file."),
442 wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL);
443 parser.AddSwitch(wxEmptyString, wxT("version"),
444 _("Print program version."),
445 wxCMD_LINE_PARAM_OPTIONAL);
448 bool CaMuleExternalConnector::OnCmdLineParsed(wxCmdLineParser& parser)
450 if (parser.Found(wxT("version"))) {
451 printf("%s %s\n", m_appname, (const char *)unicode2char(GetMuleVersion()));
452 return false;
455 if (!parser.Found(wxT("config-file"), &m_configFileName)) {
456 m_configFileName = GetConfigDir() + wxT("remote.conf");
459 wxString aMuleConfigFile;
460 if (parser.Found(wxT("create-config-from"), &aMuleConfigFile)) {
461 aMuleConfigFile = FinalizeFilename(aMuleConfigFile);
462 if (!::wxFileExists(aMuleConfigFile)) {
463 fprintf(stderr, "%s\n", (const char *)unicode2char(wxT("FATAL ERROR: File does not exist: ") + aMuleConfigFile));
464 exit(1);
466 CECFileConfig aMuleConfig(aMuleConfigFile);
467 LoadAmuleConfig(aMuleConfig);
468 SaveConfigFile();
469 m_configFile->Flush();
470 exit(0);
473 LoadConfigFile();
475 if ( !parser.Found(wxT("host"), &m_host) ) {
476 if ( m_host.IsEmpty() ) {
477 m_host = wxT("localhost");
481 long port;
482 if (parser.Found(wxT("port"), &port)) {
483 m_port = port;
486 wxString pass_plain;
487 if (parser.Found(wxT("password"), &pass_plain)) {
488 if (!pass_plain.IsEmpty()) {
489 m_password.Decode(MD5Sum(pass_plain).GetHash());
490 } else {
491 m_password.Clear();
495 if (parser.Found(wxT("write-config"))) {
496 m_NeedsConfigSave = true;
499 parser.Found(wxT("locale"), &m_language);
501 if (parser.Found(wxT("help"))) {
502 parser.Usage();
503 return false;
506 m_KeepQuiet = parser.Found(wxT("quiet"));
507 m_Verbose = parser.Found(wxT("verbose"));
509 return true;
512 void CaMuleExternalConnector::LoadAmuleConfig(CECFileConfig& cfg)
514 m_host = wxT("localhost");
515 m_port = cfg.Read(wxT("/ExternalConnect/ECPort"), 4712l);
516 cfg.ReadHash(wxT("/ExternalConnect/ECPassword"), &m_password);
517 m_language = cfg.Read(wxT("/eMule/Language"), wxEmptyString);
521 void CaMuleExternalConnector::LoadConfigFile()
523 if (!m_configFile) {
524 m_configFile = new CECFileConfig(m_configFileName);
526 if (m_configFile) {
527 m_language = m_configFile->Read(wxT("/Locale"), wxEmptyString);
528 m_host = m_configFile->Read(wxT("/EC/Host"), wxEmptyString);
529 m_port = m_configFile->Read(wxT("/EC/Port"), 4712l);
530 m_configFile->ReadHash(wxT("/EC/Password"), &m_password);
531 m_ZLIB = m_configFile->Read(wxT("/EC/ZLIB"), 1l) != 0;
535 void CaMuleExternalConnector::SaveConfigFile()
537 if (!wxFileName::DirExists(GetConfigDir())) {
538 wxFileName::Mkdir(GetConfigDir());
540 if (!m_configFile) {
541 m_configFile = new CECFileConfig(m_configFileName);
543 if (m_configFile) {
544 m_configFile->Write(wxT("/Locale"), m_language);
545 m_configFile->Write(wxT("/EC/Host"), m_host);
546 m_configFile->Write(wxT("/EC/Port"), m_port);
547 m_configFile->WriteHash(wxT("/EC/Password"), m_password);
551 bool CaMuleExternalConnector::OnInit()
553 #ifndef __WXMSW__
554 #if wxUSE_ON_FATAL_EXCEPTION
555 // catch fatal exceptions
556 wxHandleFatalExceptions(true);
557 #endif
558 #endif
560 // If we didn't know that OnInit is called only once when creating the
561 // object, it could cause a memory leak. The two pointers below should
562 // be free()'d before assigning the new value.
563 // cppcheck-suppress publicAllocationError
564 m_strFullVersion = strdup((const char *)unicode2char(GetMuleVersion()));
565 m_strOSDescription = strdup((const char *)unicode2char(wxGetOsDescription()));
567 // Handle uncaught exceptions
568 InstallMuleExceptionHandler();
570 bool retval = wxApp::OnInit();
571 OnInitCommandSet();
572 InitCustomLanguages();
573 SetLocale(m_language);
574 return retval;
577 wxString CaMuleExternalConnector::SetLocale(const wxString& language)
579 if (!language.IsEmpty()) {
580 m_language = language;
581 if (m_locale) {
582 delete m_locale;
584 m_locale = new wxLocale;
585 InitLocale(*m_locale, StrLang2wx(language));
588 return m_locale == NULL ? wxString() : m_locale->GetCanonicalName();
591 #if !wxUSE_GUI && defined(__WXMAC__) && !wxCHECK_VERSION(2, 9, 0)
593 #include <wx/apptrait.h> // Do_not_auto_remove
594 #include <wx/stdpaths.h> // Do_not_auto_remove
596 class CaMuleExternalConnectorTraits : public wxConsoleAppTraits
598 public:
599 virtual wxStandardPathsBase& GetStandardPaths()
601 return s_stdPaths;
604 private:
605 static wxStandardPathsCF s_stdPaths;
608 wxStandardPathsCF CaMuleExternalConnectorTraits::s_stdPaths;
610 wxAppTraits* CaMuleExternalConnector::CreateTraits()
612 return new CaMuleExternalConnectorTraits;
615 #endif
617 #if wxUSE_ON_FATAL_EXCEPTION
618 // Gracefully handle fatal exceptions and print backtrace if possible
619 void CaMuleExternalConnector::OnFatalException()
621 /* Print the backtrace */
622 fprintf(stderr, "\n--------------------------------------------------------------------------------\n");
623 fprintf(stderr, "A fatal error has occurred and %s has crashed.\n", m_appname);
624 fprintf(stderr, "Please assist us in fixing this problem by posting the backtrace below in our\n");
625 fprintf(stderr, "'aMule Crashes' forum and include as much information as possible regarding the\n");
626 fprintf(stderr, "circumstances of this crash. The forum is located here:\n");
627 fprintf(stderr, " http://forum.amule.org/index.php?board=67.0\n");
628 fprintf(stderr, "If possible, please try to generate a real backtrace of this crash:\n");
629 fprintf(stderr, " http://wiki.amule.org/index.php/Backtraces\n\n");
630 fprintf(stderr, "----------------------------=| BACKTRACE FOLLOWS: |=----------------------------\n");
631 fprintf(stderr, "Current version is: %s %s\n", m_appname, m_strFullVersion);
632 fprintf(stderr, "Running on: %s\n\n", m_strOSDescription);
634 print_backtrace(1); // 1 == skip this function.
636 fprintf(stderr, "\n--------------------------------------------------------------------------------\n");
638 #endif
640 #ifdef __WXDEBUG__
641 void CaMuleExternalConnector::OnAssertFailure(const wxChar *file, int line, const wxChar *func, const wxChar *cond, const wxChar *msg)
643 #if !defined wxUSE_STACKWALKER || !wxUSE_STACKWALKER
644 wxString errmsg = CFormat( wxT("%s:%s:%d: Assertion '%s' failed. %s") ) % file % func % line % cond % ( msg ? msg : wxT("") );
646 fprintf(stderr, "Assertion failed: %s\n", (const char*)unicode2char(errmsg));
648 // Skip the function-calls directly related to the assert call.
649 fprintf(stderr, "\nBacktrace follows:\n");
650 print_backtrace(3);
651 fprintf(stderr, "\n");
652 #else
653 wxApp::OnAssertFailure(file, line, func, cond, msg);
654 #endif
656 #endif
657 // File_checked_for_headers