X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/22b636aa1523c68f1fa87f4b24770c773dbc8b58..4871d34290873072ca2783074d4779ba5ecb2052:/utils/tex2rtf/src/tex2rtf.cpp diff --git a/utils/tex2rtf/src/tex2rtf.cpp b/utils/tex2rtf/src/tex2rtf.cpp index 6e157386e3..55e7af99d8 100644 --- a/utils/tex2rtf/src/tex2rtf.cpp +++ b/utils/tex2rtf/src/tex2rtf.cpp @@ -10,10 +10,6 @@ // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// -#ifdef __GNUG__ -#pragma implementation -#endif - // For compilers that support precompilation, includes "wx.h". #include "wx/wxprec.h" @@ -21,15 +17,22 @@ #pragma hdrstop #endif +#if defined(__WXMSW__) + #include "wx/msw/wrapwin.h" +#endif + #ifndef WX_PRECOMP #ifndef NO_GUI #include "wx/menu.h" #include "wx/textctrl.h" #include "wx/filedlg.h" #include "wx/msgdlg.h" + #include "wx/icon.h" #endif #endif +#include "wx/log.h" + #ifndef NO_GUI #include "wx/timer.h" #include "wx/help.h" @@ -42,6 +45,8 @@ #endif #endif // !NO_GUI +#include "wx/utils.h" + #if wxUSE_IOSTREAMH #include #include @@ -57,16 +62,14 @@ #include "rtfutils.h" #include "symbols.h" -#if (defined(__WXGTK__) || defined(__WXMOTIF__) || defined(__WXMAC__) || defined(__WXX11__)) && !defined(NO_GUI) +#if (defined(__WXGTK__) || defined(__WXMOTIF__) || defined(__WXMAC__) || defined(__WXX11__) || defined(__WXMGL__)) && !defined(NO_GUI) #include "tex2rtf.xpm" #endif -#if !WXWIN_COMPATIBILITY_2_4 static inline wxChar* copystring(const wxChar* s) { return wxStrcpy(new wxChar[wxStrlen(s) + 1], s); } -#endif -const float versionNo = (float)TEX2RTF_VERSION_NUMBER; +const float versionNo = float(TEX2RTF_VERSION_NUMBER); TexChunk *currentMember = NULL; bool startedSections = false; @@ -107,8 +110,8 @@ FILE *Subsubsections = NULL; FILE *Popups = NULL; FILE *WinHelpContentsFile = NULL; -wxChar *InputFile = NULL; -wxChar *OutputFile = NULL; +wxString InputFile; +wxString OutputFile; wxChar *MacroFile = copystring(_T("tex2rtf.ini")); wxChar *FileRoot = NULL; @@ -128,6 +131,7 @@ int BufSize = 500; bool Go(void); void ShowOptions(void); +void ShowVersion(void); wxChar wxTex2RTFBuffer[1500]; @@ -161,37 +165,23 @@ bool MyApp::OnInit() // Read input/output files if (argc > 1) { - if (argv[1][0] != '-') - { - InputFile = argv[1]; - n ++; - - if (argc > 2) + if (argv[1][0] != _T('-')) { - if (argv[2][0] != '-') - { - OutputFile = argv[2]; + InputFile = argv[1]; n ++; - } - } - } - } -#ifdef NO_GUI - if (!InputFile || !OutputFile) - { - wxSTD cout << "Tex2RTF: input or output file is missing.\n"; - ShowOptions(); - exit(1); + if (argc > 2) + { + if (argv[2][0] != _T('-')) + { + OutputFile = argv[2]; + n ++; + } + } + } } -#endif - if (InputFile) - { - TexPathList.EnsureFileAccessible(InputFile); - } - if (!InputFile || !OutputFile) - isInteractive = true; + TexPathList.Add(::wxGetCwd()); int i; for (i = n; i < argc;) @@ -269,21 +259,38 @@ bool MyApp::OnInit() } } } + else if (wxStrcmp(argv[i], _T("-checkcurlybraces")) == 0) + { + i ++; + checkCurlyBraces = true; + } else if (wxStrcmp(argv[i], _T("-checkcurleybraces")) == 0) { + // Support the old, incorrectly spelled version of -checkcurlybraces + // so that old scripts which run tex2rtf -checkcurleybraces still work. i ++; - checkCurleyBraces = true; + checkCurlyBraces = true; } else if (wxStrcmp(argv[i], _T("-checksyntax")) == 0) { i ++; checkSyntax = true; } + else if (wxStrcmp(argv[i], _T("-version")) == 0) + { + i ++; + ShowVersion(); +#ifdef NO_GUI + exit(1); +#else + return false; +#endif + } else { wxString buf; buf.Printf(_T("Invalid switch %s.\n"), argv[i]); - OnError((wxChar *)buf.c_str()); + OnError(buf); #ifdef NO_GUI ShowOptions(); exit(1); @@ -293,6 +300,22 @@ bool MyApp::OnInit() } } +#ifdef NO_GUI + if (InputFile.empty() || OutputFile.empty()) + { + wxSTD cout << "Tex2RTF: input or output file is missing.\n"; + ShowOptions(); + exit(1); + } +#endif + + if (!InputFile.empty()) + { + TexPathList.EnsureFileAccessible(InputFile); + } + if (InputFile.empty() || OutputFile.empty()) + isInteractive = true; + #if defined(__WXMSW__) && !defined(NO_GUI) wxDDEInitialize(); Tex2RTFLastStatus[0] = 0; // DDE connection return value @@ -307,8 +330,6 @@ bool MyApp::OnInit() if (isInteractive) { - wxChar buf[100]; - // Create the main frame window frame = new MyFrame(NULL, wxID_ANY, _T("Tex2RTF"), wxDefaultPosition, wxSize(400, 300)); #if wxUSE_STATUSBAR @@ -319,10 +340,11 @@ bool MyApp::OnInit() // TODO: uncomment this when we have tex2rtf.xpm frame->SetIcon(wxICON(tex2rtf)); - if (InputFile) + if (!InputFile.empty()) { - wxSnprintf(buf, sizeof(buf), _T("Tex2RTF [%s]"), wxFileNameFromPath(InputFile)); - frame->SetTitle(buf); + wxString title; + title.Printf( _T("Tex2RTF [%s]"), wxFileNameFromPath(InputFile).c_str()); + frame->SetTitle(title); } // Make a menubar @@ -351,10 +373,10 @@ bool MyApp::OnInit() wxMenu *options_menu = new wxMenu; - options_menu->Append(TEX_OPTIONS_CURLEY_BRACE, _T("Curley brace matching"), _T("Checks for mismatched curley braces"),true); + options_menu->Append(TEX_OPTIONS_CURLY_BRACE, _T("Curly brace matching"), _T("Checks for mismatched curly braces"),true); options_menu->Append(TEX_OPTIONS_SYNTAX_CHECKING, _T("Syntax checking"), _T("Syntax checking for common errors"),true); - options_menu->Check(TEX_OPTIONS_CURLEY_BRACE, checkCurleyBraces); + options_menu->Check(TEX_OPTIONS_CURLY_BRACE, checkCurlyBraces); options_menu->Check(TEX_OPTIONS_SYNTAX_CHECKING, checkSyntax); wxMenu *help_menu = new wxMenu; @@ -370,7 +392,7 @@ bool MyApp::OnInit() menuBar->Append(help_menu, _T("&Help")); frame->SetMenuBar(menuBar); - frame->textWindow = new wxTextCtrl(frame, wxID_ANY, _T(""), wxDefaultPosition, wxDefaultSize, wxTE_READONLY|wxTE_MULTILINE); + frame->textWindow = new wxTextCtrl(frame, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_READONLY|wxTE_MULTILINE); (*frame->textWindow) << _T("Welcome to Tex2RTF.\n"); // ShowOptions(); @@ -379,7 +401,7 @@ bool MyApp::OnInit() #if wxUSE_MS_HTML_HELP && !defined(__WXUNIVERSAL__) HelpInstance = new wxCHMHelpController; #else - HelpInstance = new wxHtmlHelpController; + HelpInstance = new wxHelpController; #endif HelpInstance->Initialize(_T("tex2rtf")); #endif // wxUSE_HELP @@ -390,28 +412,34 @@ bool MyApp::OnInit() */ wxString path = TexPathList.FindValidPath(MacroFile); - if (path != _T("")) - ReadCustomMacros((wxChar *)path.c_str()); + if (!path.empty()) + ReadCustomMacros(path); #if wxUSE_STATUSBAR - wxStrcpy(buf, _T("In ")); + wxString inStr(_T("In ")); switch (convertMode) { - case TEX_RTF: - wxStrcat(buf, (winHelp) ? _T("WinHelp RTF") : _T("linear RTF")); - break; - case TEX_HTML: - wxStrcat(buf, _T("HTML")); - break; - case TEX_XLP: - wxStrcat(buf, _T("XLP")); - break; - default: - wxStrcat(buf, _T("unknown")); - break; + case TEX_RTF: + if(winHelp) + inStr += _T("WinHelp RTF"); + else + inStr += _T("linear RTF"); + break; + + case TEX_HTML: + inStr += _T("HTML"); + break; + + case TEX_XLP: + inStr += _T("XLP"); + break; + + default: + inStr += _T("unknown"); + break; } - wxStrcat(buf, _T(" mode.")); - frame->SetStatusText(buf, 1); + inStr += _T(" mode."); + frame->SetStatusText(inStr, 1); #endif // wxUSE_STATUSBAR frame->Show(true); @@ -426,16 +454,16 @@ bool MyApp::OnInit() */ wxString path = TexPathList.FindValidPath(MacroFile); - if (path != _T("")) - ReadCustomMacros((wxChar*)path.c_str()); + if (!path.empty()) + ReadCustomMacros(path); - Go(); - if (runTwice) + bool rc = Go(); + if ( rc && runTwice ) { - Go(); + rc = Go(); } #ifdef NO_GUI - return true; + return rc; #else OnExit(); // Do cleanup since OnExit won't be called now return false; @@ -576,11 +604,17 @@ int MyApp::OnExit() return 0; } #endif -void ShowOptions(void) + +void ShowVersion(void) { wxChar buf[100]; wxSnprintf(buf, sizeof(buf), _T("Tex2RTF version %.2f"), versionNo); OnInform(buf); +} + +void ShowOptions(void) +{ + ShowVersion(); OnInform(_T("Usage: tex2rtf [input] [output] [switches]\n")); OnInform(_T("where valid switches are")); #ifndef NO_GUI @@ -590,8 +624,9 @@ void ShowOptions(void) OnInform(_T(" -charset (default ansi)")); OnInform(_T(" -twice")); OnInform(_T(" -sync")); - OnInform(_T(" -checkcurleybraces")); + OnInform(_T(" -checkcurlybraces")); OnInform(_T(" -checksyntax")); + OnInform(_T(" -version")); OnInform(_T(" -macros ")); OnInform(_T(" -winhelp")); OnInform(_T(" -rtf")); @@ -616,7 +651,7 @@ BEGIN_EVENT_TABLE(MyFrame, wxFrame) EVT_MENU(TEX_MODE_WINHELP, MyFrame::OnModeWinHelp) EVT_MENU(TEX_MODE_HTML, MyFrame::OnModeHTML) EVT_MENU(TEX_MODE_XLP, MyFrame::OnModeXLP) - EVT_MENU(TEX_OPTIONS_CURLEY_BRACE, MyFrame::OnOptionsCurleyBrace) + EVT_MENU(TEX_OPTIONS_CURLY_BRACE, MyFrame::OnOptionsCurlyBrace) EVT_MENU(TEX_OPTIONS_SYNTAX_CHECKING, MyFrame::OnOptionsSyntaxChecking) EVT_MENU(TEX_HELP, MyFrame::OnHelp) EVT_MENU(TEX_ABOUT, MyFrame::OnAbout) @@ -666,7 +701,7 @@ void MyFrame::OnGo(wxCommandEvent& WXUNUSED(event)) #endif // wxUSE_STATUSBAR wxString errBuf; errBuf.Printf(_T("\nErrors encountered during this pass: %lu\n"), errorCount); - OnInform((wxChar *)errBuf.c_str()); + OnInform(errBuf); } @@ -693,117 +728,121 @@ void MyFrame::OnSetOutput(wxCommandEvent& WXUNUSED(event)) void MyFrame::OnSaveFile(wxCommandEvent& WXUNUSED(event)) { - wxString s = wxFileSelector(_T("Save text to file"), _T(""), _T(""), _T("txt"), _T("*.txt")); - if (s != _T("")) - { +#if wxUSE_FILEDLG + wxString s = wxFileSelector(_T("Save text to file"), wxEmptyString, wxEmptyString, _T("txt"), _T("*.txt")); + if (!s.empty()) + { textWindow->SaveFile(s); #if wxUSE_STATUSBAR wxChar buf[350]; wxSnprintf(buf, sizeof(buf), _T("Saved text to %s"), (const wxChar*) s.c_str()); frame->SetStatusText(buf, 0); #endif // wxUSE_STATUSBAR - } + } +#endif // wxUSE_FILEDLG } void MyFrame::OnViewOutput(wxCommandEvent& WXUNUSED(event)) { - ChooseOutputFile(); - if (OutputFile && wxFileExists(OutputFile)) - { + ChooseOutputFile(); + if (!OutputFile.empty() && wxFileExists(OutputFile)) + { textWindow->LoadFile(OutputFile); wxChar buf[300]; wxString str(wxFileNameFromPath(OutputFile)); wxSnprintf(buf, sizeof(buf), _T("Tex2RTF [%s]"), (const wxChar*) str.c_str()); frame->SetTitle(buf); - } + } } void MyFrame::OnViewLatex(wxCommandEvent& WXUNUSED(event)) { - ChooseInputFile(); - if (InputFile && wxFileExists(InputFile)) - { + ChooseInputFile(); + if (!InputFile.empty() && wxFileExists(InputFile)) + { textWindow->LoadFile(InputFile); wxChar buf[300]; wxString str(wxFileNameFromPath(OutputFile)); wxSnprintf(buf, sizeof(buf), _T("Tex2RTF [%s]"), (const wxChar*) str.c_str()); frame->SetTitle(buf); - } + } } void MyFrame::OnLoadMacros(wxCommandEvent& WXUNUSED(event)) { - textWindow->Clear(); - wxString s = wxFileSelector(_T("Choose custom macro file"), wxPathOnly(MacroFile), wxFileNameFromPath(MacroFile), _T("ini"), _T("*.ini")); - if (s != _T("") && wxFileExists(s)) - { + textWindow->Clear(); +#if wxUSE_FILEDLG + wxString s = wxFileSelector(_T("Choose custom macro file"), wxPathOnly(MacroFile), wxFileNameFromPath(MacroFile), _T("ini"), _T("*.ini")); + if (!s.empty() && wxFileExists(s)) + { MacroFile = copystring(s); - ReadCustomMacros((wxChar *)s.c_str()); + ReadCustomMacros(s); ShowCustomMacros(); - } + } +#endif // wxUSE_FILEDLG } void MyFrame::OnShowMacros(wxCommandEvent& WXUNUSED(event)) { - textWindow->Clear(); - Tex2RTFYield(true); - ShowCustomMacros(); + textWindow->Clear(); + Tex2RTFYield(true); + ShowCustomMacros(); } void MyFrame::OnModeRTF(wxCommandEvent& WXUNUSED(event)) { - convertMode = TEX_RTF; - winHelp = false; - InputFile = NULL; - OutputFile = NULL; + convertMode = TEX_RTF; + winHelp = false; + InputFile = wxEmptyString; + OutputFile = wxEmptyString; #if wxUSE_STATUSBAR - SetStatusText(_T("In linear RTF mode."), 1); + SetStatusText(_T("In linear RTF mode."), 1); #endif // wxUSE_STATUSBAR } void MyFrame::OnModeWinHelp(wxCommandEvent& WXUNUSED(event)) { - convertMode = TEX_RTF; - winHelp = true; - InputFile = NULL; - OutputFile = NULL; + convertMode = TEX_RTF; + winHelp = true; + InputFile = wxEmptyString; + OutputFile = wxEmptyString; #if wxUSE_STATUSBAR - SetStatusText(_T("In WinHelp RTF mode."), 1); + SetStatusText(_T("In WinHelp RTF mode."), 1); #endif // wxUSE_STATUSBAR } void MyFrame::OnModeHTML(wxCommandEvent& WXUNUSED(event)) { - convertMode = TEX_HTML; - winHelp = false; - InputFile = NULL; - OutputFile = NULL; + convertMode = TEX_HTML; + winHelp = false; + InputFile = wxEmptyString; + OutputFile = wxEmptyString; #if wxUSE_STATUSBAR - SetStatusText(_T("In HTML mode."), 1); + SetStatusText(_T("In HTML mode."), 1); #endif // wxUSE_STATUSBAR } void MyFrame::OnModeXLP(wxCommandEvent& WXUNUSED(event)) { - convertMode = TEX_XLP; - InputFile = NULL; - OutputFile = NULL; + convertMode = TEX_XLP; + InputFile = wxEmptyString; + OutputFile = wxEmptyString; #if wxUSE_STATUSBAR - SetStatusText(_T("In XLP mode."), 1); + SetStatusText(_T("In XLP mode."), 1); #endif // wxUSE_STATUSBAR } -void MyFrame::OnOptionsCurleyBrace(wxCommandEvent& WXUNUSED(event)) +void MyFrame::OnOptionsCurlyBrace(wxCommandEvent& WXUNUSED(event)) { - checkCurleyBraces = !checkCurleyBraces; + checkCurlyBraces = !checkCurlyBraces; #if wxUSE_STATUSBAR - if (checkCurleyBraces) + if (checkCurlyBraces) { - SetStatusText(_T("Checking curley braces: YES"), 1); + SetStatusText(_T("Checking curly braces: YES"), 1); } else { - SetStatusText(_T("Checking curley braces: NO"), 1); + SetStatusText(_T("Checking curly braces: NO"), 1); } #endif // wxUSE_STATUSBAR } @@ -836,81 +875,81 @@ void MyFrame::OnHelp(wxCommandEvent& WXUNUSED(event)) void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event)) { wxChar buf[300]; -#ifdef __WIN32__ - wxChar *platform = _T(" (32-bit)"); -#else -#ifdef __WXMSW__ - wxChar *platform = _T(" (16-bit)"); -#else - wxChar *platform = _T(""); -#endif -#endif - wxSnprintf(buf, sizeof(buf), _T("Tex2RTF Version %.2f%s\nLaTeX to RTF, WinHelp, and HTML Conversion\n\n(c) Julian Smart, George Tasker and others, 1999-2002"), versionNo, platform); + wxString platform = wxGetOsDescription(); + wxSnprintf(buf, sizeof(buf), _T("Tex2RTF Version %.2f %s\nLaTeX to RTF, WinHelp, and HTML Conversion\n\n(c) Julian Smart, George Tasker and others, 1999-2005"), versionNo, platform.c_str()); wxMessageBox(buf, _T("About Tex2RTF")); } void ChooseInputFile(bool force) { - if (force || !InputFile) - { - wxString s = wxFileSelector(_T("Choose LaTeX input file"), wxPathOnly(InputFile), wxFileNameFromPath(InputFile), _T("tex"), _T("*.tex")); - if (s != _T("")) +#if wxUSE_FILEDLG + if (force || InputFile.empty()) { - // Different file, so clear index entries. - ClearKeyWordTable(); - ResetContentsLevels(0); - passNumber = 1; - errorCount = 0; - - InputFile = copystring(s); - wxString str = wxFileNameFromPath(InputFile); - wxString buf; - buf.Printf(_T("Tex2RTF [%s]"), str.c_str()); - frame->SetTitle((wxChar *)buf.c_str()); - OutputFile = NULL; + wxString s = wxFileSelector(_T("Choose LaTeX input file"), wxPathOnly(InputFile), wxFileNameFromPath(InputFile), _T("tex"), _T("*.tex")); + if (!s.empty()) + { + // Different file, so clear index entries. + ClearKeyWordTable(); + ResetContentsLevels(0); + passNumber = 1; + errorCount = 0; + + InputFile = s; + wxString str = wxFileNameFromPath(InputFile); + wxString buf; + buf.Printf(_T("Tex2RTF [%s]"), str.c_str()); + frame->SetTitle(buf); + OutputFile = wxEmptyString; + } } - } +#else + wxUnusedVar(force); +#endif // wxUSE_FILEDLG } void ChooseOutputFile(bool force) { - wxChar extensionBuf[10]; - wxChar wildBuf[10]; - wxStrcpy(wildBuf, _T("*.")); - wxString path; - if (OutputFile) - path = wxPathOnly(OutputFile); - else if (InputFile) - path = wxPathOnly(InputFile); + wxChar extensionBuf[10]; + wxChar wildBuf[10]; + wxStrcpy(wildBuf, _T("*.")); + wxString path; + if (!OutputFile.empty()) + path = wxPathOnly(OutputFile); + else if (!InputFile.empty()) + path = wxPathOnly(InputFile); - switch (convertMode) - { - case TEX_RTF: - { - wxStrcpy(extensionBuf, _T("rtf")); - wxStrcat(wildBuf, _T("rtf")); - break; - } - case TEX_XLP: + switch (convertMode) { - wxStrcpy(extensionBuf, _T("xlp")); - wxStrcat(wildBuf, _T("xlp")); - break; + case TEX_RTF: + { + wxStrcpy(extensionBuf, _T("rtf")); + wxStrcat(wildBuf, _T("rtf")); + break; + } + case TEX_XLP: + { + wxStrcpy(extensionBuf, _T("xlp")); + wxStrcat(wildBuf, _T("xlp")); + break; + } + case TEX_HTML: + { + wxStrcpy(extensionBuf, _T("html")); + wxStrcat(wildBuf, _T("html")); + break; + } } - case TEX_HTML: +#if wxUSE_FILEDLG + if (force || OutputFile.empty()) { - wxStrcpy(extensionBuf, _T("html")); - wxStrcat(wildBuf, _T("html")); - break; + wxString s = wxFileSelector(_T("Choose output file"), path, wxFileNameFromPath(OutputFile), + extensionBuf, wildBuf); + if (!s.empty()) + OutputFile = s; } - } - if (force || !OutputFile) - { - wxString s = wxFileSelector(_T("Choose output file"), path, wxFileNameFromPath(OutputFile), - extensionBuf, wildBuf); - if (s != _T("")) - OutputFile = copystring(s); - } +#else + wxUnusedVar(force); +#endif // wxUSE_FILEDLG } #endif @@ -921,7 +960,7 @@ bool Go(void) ChooseOutputFile(); #endif - if (!InputFile || !OutputFile || stopRunning) + if (InputFile.empty() || OutputFile.empty() || stopRunning) return false; #ifndef NO_GUI @@ -934,11 +973,11 @@ bool Go(void) frame->SetTitle(buf); } - wxStartTimer(); + wxLongLong localTime = wxGetLocalTimeMillis(); #endif // Find extension-less filename - wxStrcpy(FileRoot, OutputFile); + wxStrcpy(FileRoot, OutputFile.c_str()); StripExtension(FileRoot); if (truncateFilenames && convertMode == TEX_HTML) @@ -963,7 +1002,7 @@ bool Go(void) if (!bulletFile) { wxString s = TexPathList.FindValidPath(_T("bullet.bmp")); - if (s != _T("")) + if (!s.empty()) { wxString str = wxFileNameFromPath(s); bulletFile = copystring(str); @@ -975,7 +1014,7 @@ bool Go(void) bool success = false; - if (InputFile && OutputFile) + if (!InputFile.empty() && !OutputFile.empty()) { if (!wxFileExists(InputFile)) { @@ -988,7 +1027,7 @@ bool Go(void) { wxString buf; buf.Printf(_T("Working, pass %d...Click CLOSE to abort"), passNumber); - frame->SetStatusText((wxChar *)buf.c_str()); + frame->SetStatusText(buf); } #endif OkToClose = false; @@ -1036,30 +1075,30 @@ bool Go(void) wxString buf; #ifndef NO_GUI - long tim = wxGetElapsedTime(); - buf.Printf(_T("Finished PASS #%d in %ld seconds.\n"), passNumber, (long)(tim/1000.0)); - OnInform((wxChar *)buf.c_str()); + wxLongLong elapsed = wxGetLocalTimeMillis() - localTime; + buf.Printf(_T("Finished PASS #%d in %ld seconds.\n"), passNumber, (long)(elapsed.GetLo()/1000.0)); + OnInform(buf); if (errorCount) { buf.Printf(_T("Errors encountered during this pass: %lu\n"), errorCount); - OnInform((wxChar *)buf.c_str()); + OnInform(buf); } #if wxUSE_STATUSBAR if (isInteractive) { buf.Printf(_T("Done, %d %s."), passNumber, (passNumber > 1) ? _T("passes") : _T("pass")); - frame->SetStatusText((wxChar *)buf.c_str()); + frame->SetStatusText(buf); } #endif // wxUSE_STATUSBAR #else buf.Printf(_T("Done, %d %s."), passNumber, (passNumber > 1) ? _T("passes") : _T("pass")); - OnInform((wxChar *)buf.c_str()); + OnInform(buf); if (errorCount) { buf.Printf(_T("Errors encountered during this pass: %lu\n"), errorCount); - OnInform((wxChar *)buf.c_str()); + OnInform(buf.c_str()); } #endif passNumber ++; @@ -1080,61 +1119,56 @@ bool Go(void) return false; } -void OnError(const wxChar *msg) +void OnError(const wxString& msg) { - wxString msg_string = msg; - errorCount++; + errorCount++; #ifdef NO_GUI - wxSTD cerr << "Error: " << msg_string.mb_str() << "\n"; - wxSTD cerr.flush(); -#else - if (isInteractive && frame) - (*frame->textWindow) << _T("Error: ") << msg << _T("\n"); - else -#ifdef __UNIX__ - { - wxSTD cerr << "Error: " << msg_string.mb_str() << "\n"; + wxSTD cerr << "Error: " << msg.mb_str() << "\n"; wxSTD cerr.flush(); - } +#else + if (isInteractive && frame) + { + (*frame->textWindow) << _T("Error: ") << msg << _T("\n"); + } + else + { +#if defined(__UNIX__) + wxSTD cerr << "Error: " << msg.mb_str() << "\n"; + wxSTD cerr.flush(); +#elif defined(__WXMSW__) + wxLogError(msg); #endif + } -#ifdef __WXMSW__ - wxLogError(msg); -#endif - Tex2RTFYield(true); + Tex2RTFYield(true); #endif // NO_GUI } -void OnInform(const wxChar *msg) +void OnInform(const wxString& msg) { - wxString msg_string = msg; #ifdef NO_GUI - wxSTD cout << msg_string.mb_str() << "\n"; - wxSTD cout.flush(); -#else - if (isInteractive && frame) - (*frame->textWindow) << msg << _T("\n"); -/* This whole block of code is just wrong I think. It would behave - completely wrong under anything other than MSW due to the ELSE - with no statement, and the cout calls would fail under MSW, as - the code in this block is compiled if !NO_GUI This code has been - here since v1.1 of this file too. - gt - else -#ifdef __WXMSW__ - { - wxSTD cout << msg_string.mb_str() << "\n"; + wxSTD cout << msg.mb_str() << "\n"; wxSTD cout.flush(); - } -#endif -#ifdef __WXMSW__ - {} +#else + if (isInteractive && frame) + { + (*frame->textWindow) << msg << _T("\n"); + } + else + { +#if defined(__UNIX__) + wxSTD cout << msg.mb_str() << "\n"; + wxSTD cout.flush(); +#elif defined(__WXMSW__) + wxLogInfo(msg); #endif -*/ - if (isInteractive) - { - Tex2RTFYield(true); - } + } + + if (isInteractive) + { + Tex2RTFYield(true); + } #endif // NO_GUI } @@ -1213,10 +1247,6 @@ Tex2RTFConnection::Tex2RTFConnection(wxChar *buf, int size):wxDDEConnection(buf, { } -Tex2RTFConnection::~Tex2RTFConnection(void) -{ -} - bool SplitCommand(wxChar *data, wxChar *firstArg, wxChar *secondArg) { firstArg[0] = 0; @@ -1262,20 +1292,18 @@ bool Tex2RTFConnection::OnExecute(const wxString& WXUNUSED(topic), wxChar *data, bool hasArg = (wxStrlen(secondArg) > 0); if (wxStrcmp(firstArg, _T("INPUT")) == 0 && hasArg) { - if (InputFile) delete[] InputFile; - InputFile = copystring(secondArg); - if (frame) - { - wxChar buf[100]; - wxString str = wxFileNameFromPath(InputFile); - wxSnprintf(buf, sizeof(buf), _T("Tex2RTF [%s]"), (const wxChar*) str); - frame->SetTitle(buf); - } + InputFile = secondArg; + if (frame) + { + wxChar buf[100]; + wxString str = wxFileNameFromPath(InputFile); + wxSnprintf(buf, sizeof(buf), _T("Tex2RTF [%s]"), (const wxChar*) str); + frame->SetTitle(buf); + } } else if (wxStrcmp(firstArg, _T("OUTPUT")) == 0 && hasArg) { - if (OutputFile) delete[] OutputFile; - OutputFile = copystring(secondArg); + OutputFile = secondArg; } else if (wxStrcmp(firstArg, _T("GO")) == 0) {