X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/6c155d33875eb3641bf845fbac186c1b5470708e..ae200bfcb537c475708959cb034be66eb0f5dcd4:/utils/tex2rtf/src/tex2rtf.cpp diff --git a/utils/tex2rtf/src/tex2rtf.cpp b/utils/tex2rtf/src/tex2rtf.cpp index f3f655fb19..2e9840aefc 100644 --- a/utils/tex2rtf/src/tex2rtf.cpp +++ b/utils/tex2rtf/src/tex2rtf.cpp @@ -2,17 +2,14 @@ // Name: tex2rtf.cpp // Purpose: Converts Latex to linear/WinHelp RTF, HTML, wxHelp. // Author: Julian Smart -// Modified by: +// Modified by: Wlodzimiez ABX Skiba 2003/2004 Unicode support +// Ron Lee // Created: 7.9.93 // RCS-ID: $Id$ // Copyright: (c) Julian Smart // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// -#ifdef __GNUG__ -#pragma implementation -#endif - // For compilers that support precompilation, includes "wx.h". #include "wx/wxprec.h" @@ -20,21 +17,36 @@ #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/help.h" -#include "wx/timer.h" -#endif + #include "wx/timer.h" + #include "wx/help.h" + #include "wx/cshelp.h" + #include "wx/helphtml.h" + #ifdef __WXMSW__ + #include "wx/msw/helpchm.h" + #else + #include "wx/html/helpctrl.h" + #endif +#endif // !NO_GUI + +#include "wx/utils.h" -#if defined(NO_GUI) || defined(__UNIX__) #if wxUSE_IOSTREAMH #include #include @@ -42,7 +54,6 @@ #include #include #endif -#endif #include #include @@ -51,7 +62,7 @@ #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 @@ -60,13 +71,13 @@ static inline wxChar* copystring(const wxChar* s) { return wxStrcpy(new wxChar[wxStrlen(s) + 1], s); } #endif -const float versionNo = TEX2RTF_VERSION_NUMBER; +const float versionNo = float(TEX2RTF_VERSION_NUMBER); TexChunk *currentMember = NULL; -bool startedSections = FALSE; +bool startedSections = false; wxChar *contentsString = NULL; -bool suppressNameDecoration = FALSE; -bool OkToClose = TRUE; +bool suppressNameDecoration = false; +bool OkToClose = true; int passNumber = 1; unsigned long errorCount = 0; @@ -79,18 +90,17 @@ extern wxChar *TexTmpBibName; // Temporary bibliography output file name extern wxList ColourTable; extern TexChunk *TopLevel; - - #if wxUSE_HELP -wxHelpController *HelpInstance = NULL; +wxHelpControllerBase *HelpInstance = NULL; #endif // wxUSE_HELP #ifdef __WXMSW__ static wxChar *ipc_buffer = NULL; static wxChar Tex2RTFLastStatus[100]; Tex2RTFServer *TheTex2RTFServer = NULL; -#endif -#endif +#endif // __WXMSW__ + +#endif // !NO_GUI wxChar *bulletFile = NULL; @@ -102,8 +112,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; @@ -127,18 +137,16 @@ void ShowOptions(void); wxChar wxTex2RTFBuffer[1500]; #ifdef NO_GUI - -int main(int argc, char **argv) + IMPLEMENT_APP_CONSOLE(MyApp) #else -wxMenuBar *menuBar = NULL; -MyFrame *frame = NULL; - -// DECLARE_APP(MyApp) -IMPLEMENT_APP(MyApp) + wxMenuBar *menuBar = NULL; + MyFrame *frame = NULL; + // DECLARE_APP(MyApp) + IMPLEMENT_APP(MyApp) +#endif // `Main program' equivalent, creating windows and returning main app frame bool MyApp::OnInit() -#endif { // Use default list of macros defined in tex2any.cc DefineDefaultMacros(); @@ -151,44 +159,46 @@ bool MyApp::OnInit() WinHelpContentsFileName = new wxChar[300]; RefFileName = new wxChar[300]; - ColourTable.DeleteContents(TRUE); + WX_CLEAR_LIST(wxList,ColourTable); int n = 1; // 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 ++; - } + + if (argc > 2) + { + if (argv[2][0] != _T('-')) + { + OutputFile = argv[2]; + n ++; + } + } } - } } + TexPathList.Add(::wxGetCwd()); + #ifdef NO_GUI - if (!InputFile || !OutputFile) + if (InputFile.empty() || OutputFile.empty()) { - wxSTD cout << "Tex2RTF: input or output file is missing.\n"; - ShowOptions(); - exit(1); + wxSTD cout << "Tex2RTF: input or output file is missing.\n"; + ShowOptions(); + exit(1); } - #endif - if (InputFile) + + if (!InputFile.empty()) { - TexPathList.EnsureFileAccessible(InputFile); + TexPathList.EnsureFileAccessible(InputFile); } - if (!InputFile || !OutputFile) - isInteractive = TRUE; + if (InputFile.empty() || OutputFile.empty()) + isInteractive = true; int i; for (i = n; i < argc;) @@ -197,19 +207,19 @@ bool MyApp::OnInit() { i ++; convertMode = TEX_RTF; - winHelp = TRUE; + winHelp = true; } #ifndef NO_GUI else if (wxStrcmp(argv[i], _T("-interactive")) == 0) { i ++; - isInteractive = TRUE; + isInteractive = true; } #endif else if (wxStrcmp(argv[i], _T("-sync")) == 0) // Don't yield { i ++; - isSync = TRUE; + isSync = true; } else if (wxStrcmp(argv[i], _T("-rtf")) == 0) { @@ -229,7 +239,7 @@ bool MyApp::OnInit() else if (wxStrcmp(argv[i], _T("-twice")) == 0) { i ++; - runTwice = TRUE; + runTwice = true; } else if (wxStrcmp(argv[i], _T("-macros")) == 0) { @@ -262,19 +272,26 @@ bool MyApp::OnInit() else { OnError(_T("Incorrect argument for -charset")); - return FALSE; + return false; } } } + 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; + checkSyntax = true; } else { @@ -284,8 +301,9 @@ bool MyApp::OnInit() #ifdef NO_GUI ShowOptions(); exit(1); +#else + return false; #endif - return FALSE; } } @@ -296,11 +314,6 @@ bool MyApp::OnInit() TheTex2RTFServer->Create(_T("TEX2RTF")); #endif -#if defined(__WXMSW__) && defined(__WIN16__) - // Limit to max Windows array size - if (BufSize > 64) BufSize = 64; -#endif - TexInitialize(BufSize); ResetContentsLevels(0); @@ -308,20 +321,21 @@ bool MyApp::OnInit() if (isInteractive) { - wxChar buf[100]; - // Create the main frame window - frame = new MyFrame(NULL, -1, _T("Tex2RTF"), wxPoint(-1, -1), wxSize(400, 300)); + frame = new MyFrame(NULL, wxID_ANY, _T("Tex2RTF"), wxDefaultPosition, wxSize(400, 300)); +#if wxUSE_STATUSBAR frame->CreateStatusBar(2); +#endif // wxUSE_STATUSBAR // Give it an icon // TODO: uncomment this when we have tex2rtf.xpm frame->SetIcon(wxICON(tex2rtf)); - if (InputFile) + if (!InputFile.empty()) { - wxSprintf(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 @@ -350,10 +364,10 @@ bool MyApp::OnInit() wxMenu *options_menu = new wxMenu; - options_menu->Append(TEX_OPTIONS_CURELY_BRACE, _T("Curley brace matching"), _T("Checks for mismatched curley braces"),TRUE); - options_menu->Append(TEX_OPTIONS_SYNTAX_CHECKING, _T("Syntax checking"), _T("Syntax checking for common errors"),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_CURELY_BRACE, checkCurleyBraces); + options_menu->Check(TEX_OPTIONS_CURLY_BRACE, checkCurlyBraces); options_menu->Check(TEX_OPTIONS_SYNTAX_CHECKING, checkSyntax); wxMenu *help_menu = new wxMenu; @@ -369,13 +383,17 @@ bool MyApp::OnInit() menuBar->Append(help_menu, _T("&Help")); frame->SetMenuBar(menuBar); - frame->textWindow = new wxTextCtrl(frame, -1, _T(""), wxPoint(-1, -1), wxSize(-1, -1), 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(); #if wxUSE_HELP - HelpInstance = new wxHelpController(); +#if wxUSE_MS_HTML_HELP && !defined(__WXUNIVERSAL__) + HelpInstance = new wxCHMHelpController; +#else + HelpInstance = new wxHelpController; +#endif HelpInstance->Initialize(_T("tex2rtf")); #endif // wxUSE_HELP @@ -385,22 +403,38 @@ bool MyApp::OnInit() */ wxString path = TexPathList.FindValidPath(MacroFile); - if (path != _T("")) - ReadCustomMacros((wxChar *)path.c_str()); - - wxStrcpy(buf, _T("In ")); - - if (winHelp && (convertMode == TEX_RTF)) - wxStrcat(buf, _T("WinHelp RTF")); - else if (!winHelp && (convertMode == TEX_RTF)) - wxStrcat(buf, _T("linear RTF")); - else if (convertMode == TEX_HTML) wxStrcat(buf, _T("HTML")); - else if (convertMode == TEX_XLP) wxStrcat(buf, _T("XLP")); - wxStrcat(buf, _T(" mode.")); - frame->SetStatusText(buf, 1); - - frame->Show(TRUE); - return TRUE; + if (!path.empty()) + ReadCustomMacros(path); + +#if wxUSE_STATUSBAR + wxString inStr(_T("In ")); + switch (convertMode) + { + 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; + } + inStr += _T(" mode."); + frame->SetStatusText(inStr, 1); +#endif // wxUSE_STATUSBAR + + frame->Show(true); + return true; } else #endif // NO_GUI @@ -411,30 +445,21 @@ bool MyApp::OnInit() */ wxString path = TexPathList.FindValidPath(MacroFile); - if (path != _T("")) - ReadCustomMacros((wxChar*)path.c_str()); + if (!path.empty()) + ReadCustomMacros(path); Go(); - if (runTwice) + if (runTwice) { Go(); } #ifdef NO_GUI - return 0; + return true; #else - return FALSE; + OnExit(); // Do cleanup since OnExit won't be called now + return false; #endif } - -#if 0 - // it already returned something, no need to cause warning -#ifndef NO_GUI - // Return the main frame window - return TRUE; -#else - return 0; -#endif -#endif } #ifndef NO_GUI @@ -449,12 +474,12 @@ int MyApp::OnExit() node = CustomMacroList.GetFirst(); } MacroDefs.BeginFind(); - node = MacroDefs.Next(); - while (node) + wxHashTable::Node* mNode = MacroDefs.Next(); + while (mNode) { - TexMacroDef* def = (TexMacroDef*) node->GetData(); + TexMacroDef* def = (TexMacroDef*) mNode->GetData(); delete def; - node = MacroDefs.Next(); + mNode = MacroDefs.Next(); } MacroDefs.Clear(); #ifdef __WXMSW__ @@ -573,7 +598,7 @@ int MyApp::OnExit() void ShowOptions(void) { wxChar buf[100]; - wxSprintf(buf, _T("Tex2RTF version %.2f"), versionNo); + wxSnprintf(buf, sizeof(buf), _T("Tex2RTF version %.2f"), versionNo); OnInform(buf); OnInform(_T("Usage: tex2rtf [input] [output] [switches]\n")); OnInform(_T("where valid switches are")); @@ -584,7 +609,7 @@ 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(" -macros ")); OnInform(_T(" -winhelp")); @@ -610,7 +635,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_CURELY_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) @@ -625,8 +650,8 @@ void MyFrame::OnCloseWindow(wxCloseEvent& WXUNUSED(event)) { if (!stopRunning && !OkToClose) { - stopRunning = TRUE; - runTwice = FALSE; + stopRunning = true; + runTwice = false; return; } else if (OkToClose) @@ -645,17 +670,19 @@ void MyFrame::OnGo(wxCommandEvent& WXUNUSED(event)) { passNumber = 1; errorCount = 0; - menuBar->EnableTop(0, FALSE); - menuBar->EnableTop(1, FALSE); - menuBar->EnableTop(2, FALSE); - menuBar->EnableTop(3, FALSE); + menuBar->EnableTop(0, false); + menuBar->EnableTop(1, false); + menuBar->EnableTop(2, false); + menuBar->EnableTop(3, false); textWindow->Clear(); - Tex2RTFYield(TRUE); + Tex2RTFYield(true); Go(); if (stopRunning) { +#if wxUSE_STATUSBAR SetStatusText(_T("Build aborted!")); +#endif // wxUSE_STATUSBAR wxString errBuf; errBuf.Printf(_T("\nErrors encountered during this pass: %lu\n"), errorCount); OnInform((wxChar *)errBuf.c_str()); @@ -664,134 +691,151 @@ void MyFrame::OnGo(wxCommandEvent& WXUNUSED(event)) if (runTwice && !stopRunning) { - Tex2RTFYield(TRUE); + Tex2RTFYield(true); Go(); } - menuBar->EnableTop(0, TRUE); - menuBar->EnableTop(1, TRUE); - menuBar->EnableTop(2, TRUE); - menuBar->EnableTop(3, TRUE); + menuBar->EnableTop(0, true); + menuBar->EnableTop(1, true); + menuBar->EnableTop(2, true); + menuBar->EnableTop(3, true); } void MyFrame::OnSetInput(wxCommandEvent& WXUNUSED(event)) { - ChooseInputFile(TRUE); + ChooseInputFile(true); } void MyFrame::OnSetOutput(wxCommandEvent& WXUNUSED(event)) { - ChooseOutputFile(TRUE); + ChooseOutputFile(true); } 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]; - wxSprintf(buf, _T("Saved text to %s"), (const wxChar*) s.c_str()); + 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)); - wxSprintf(buf, _T("Tex2RTF [%s]"), (const wxChar*) str.c_str()); + 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)); - wxSprintf(buf, _T("Tex2RTF [%s]"), (const wxChar*) str.c_str()); + 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; - SetStatusText(_T("In linear RTF mode."), 1); + convertMode = TEX_RTF; + winHelp = false; + InputFile = wxEmptyString; + OutputFile = wxEmptyString; +#if wxUSE_STATUSBAR + 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; - SetStatusText(_T("In WinHelp RTF mode."), 1); + convertMode = TEX_RTF; + winHelp = true; + InputFile = wxEmptyString; + OutputFile = wxEmptyString; +#if wxUSE_STATUSBAR + 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; - SetStatusText(_T("In HTML mode."), 1); + convertMode = TEX_HTML; + winHelp = false; + InputFile = wxEmptyString; + OutputFile = wxEmptyString; +#if wxUSE_STATUSBAR + SetStatusText(_T("In HTML mode."), 1); +#endif // wxUSE_STATUSBAR } void MyFrame::OnModeXLP(wxCommandEvent& WXUNUSED(event)) { - convertMode = TEX_XLP; - InputFile = NULL; - OutputFile = NULL; - SetStatusText(_T("In XLP mode."), 1); + convertMode = TEX_XLP; + InputFile = wxEmptyString; + OutputFile = wxEmptyString; +#if wxUSE_STATUSBAR + SetStatusText(_T("In XLP mode."), 1); +#endif // wxUSE_STATUSBAR } -void MyFrame::OnOptionsCurleyBrace(wxCommandEvent& WXUNUSED(event)) +void MyFrame::OnOptionsCurlyBrace(wxCommandEvent& WXUNUSED(event)) { - checkCurleyBraces = !checkCurleyBraces; - if (checkCurleyBraces) + checkCurlyBraces = !checkCurlyBraces; +#if wxUSE_STATUSBAR + 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 } void MyFrame::OnOptionsSyntaxChecking(wxCommandEvent& WXUNUSED(event)) { checkSyntax = !checkSyntax; +#if wxUSE_STATUSBAR if (checkSyntax) { SetStatusText(_T("Checking syntax: YES"), 1); @@ -800,6 +844,7 @@ void MyFrame::OnOptionsSyntaxChecking(wxCommandEvent& WXUNUSED(event)) { SetStatusText(_T("Checking syntax: NO"), 1); } +#endif // wxUSE_STATUSBAR } @@ -814,86 +859,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 - wxSprintf(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((wxChar *)buf.c_str()); + 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: + switch (convertMode) { - wxStrcpy(extensionBuf, _T("rtf")); - wxStrcat(wildBuf, _T("rtf")); - 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_XLP: +#if wxUSE_FILEDLG + if (force || OutputFile.empty()) { - wxStrcpy(extensionBuf, _T("xlp")); - wxStrcat(wildBuf, _T("xlp")); - break; + wxString s = wxFileSelector(_T("Choose output file"), path, wxFileNameFromPath(OutputFile), + extensionBuf, wildBuf); + if (!s.empty()) + OutputFile = s; } - case TEX_HTML: - { -#if defined(__WXMSW__) && defined(__WIN16__) - wxStrcpy(extensionBuf, _T("htm")); - wxStrcat(wildBuf, _T("htm")); #else - wxStrcpy(extensionBuf, _T("html")); - wxStrcat(wildBuf, _T("html")); -#endif - break; - } - } - if (force || !OutputFile) - { - wxString s = wxFileSelector(_T("Choose output file"), path, wxFileNameFromPath(OutputFile), - extensionBuf, wildBuf); - if (s != _T("")) - OutputFile = copystring(s); - } + wxUnusedVar(force); +#endif // wxUSE_FILEDLG } #endif @@ -904,8 +944,8 @@ bool Go(void) ChooseOutputFile(); #endif - if (!InputFile || !OutputFile || stopRunning) - return FALSE; + if (InputFile.empty() || OutputFile.empty() || stopRunning) + return false; #ifndef NO_GUI if (isInteractive) @@ -913,15 +953,15 @@ bool Go(void) wxChar buf[300]; wxString str = wxFileNameFromPath(InputFile); - wxSprintf(buf, _T("Tex2RTF [%s]"), (const wxChar*) str); + wxSnprintf(buf, sizeof(buf), _T("Tex2RTF [%s]"), (const wxChar*) str); 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) @@ -936,17 +976,17 @@ bool Go(void) sName[5] = '\0'; // that should do! } - wxSprintf(ContentsName, _T("%s.con"), FileRoot); - wxSprintf(TmpContentsName, _T("%s.cn1"), FileRoot); - wxSprintf(TmpFrameContentsName, _T("%s.frc"), FileRoot); - wxSprintf(WinHelpContentsFileName, _T("%s.cnt"), FileRoot); - wxSprintf(RefFileName, _T("%s.ref"), FileRoot); + wxSnprintf(ContentsName, 300, _T("%s.con"), FileRoot); + wxSnprintf(TmpContentsName, 300, _T("%s.cn1"), FileRoot); + wxSnprintf(TmpFrameContentsName, 300, _T("%s.frc"), FileRoot); + wxSnprintf(WinHelpContentsFileName, 300, _T("%s.cnt"), FileRoot); + wxSnprintf(RefFileName, 300, _T("%s.ref"), FileRoot); TexPathList.EnsureFileAccessible(InputFile); if (!bulletFile) { wxString s = TexPathList.FindValidPath(_T("bullet.bmp")); - if (s != _T("")) + if (!s.empty()) { wxString str = wxFileNameFromPath(s); bulletFile = copystring(str); @@ -956,17 +996,17 @@ bool Go(void) if (wxFileExists(RefFileName)) ReadTexReferences(RefFileName); - bool success = FALSE; + bool success = false; - if (InputFile && OutputFile) + if (!InputFile.empty() && !OutputFile.empty()) { if (!wxFileExists(InputFile)) { OnError(_T("Cannot open input file!")); TexCleanUp(); - return FALSE; + return false; } -#ifndef NO_GUI +#if !defined(NO_GUI) && wxUSE_STATUSBAR if (isInteractive) { wxString buf; @@ -974,14 +1014,14 @@ bool Go(void) frame->SetStatusText((wxChar *)buf.c_str()); } #endif - OkToClose = FALSE; + OkToClose = false; OnInform(_T("Reading LaTeX file...")); TexLoadFile(InputFile); if (stopRunning) { - OkToClose = TRUE; - return FALSE; + OkToClose = true; + return false; } switch (convertMode) @@ -1006,21 +1046,21 @@ bool Go(void) if (stopRunning) { OnInform(_T("*** Aborted by user.")); - success = FALSE; - stopRunning = FALSE; - OkToClose = TRUE; + success = false; + stopRunning = false; + OkToClose = true; } if (success) { WriteTexReferences(RefFileName); TexCleanUp(); - startedSections = FALSE; + startedSections = false; wxString buf; #ifndef NO_GUI - long tim = wxGetElapsedTime(); - buf.Printf(_T("Finished PASS #%d in %ld seconds.\n"), passNumber, (long)(tim/1000.0)); + wxLongLong elapsed = wxGetLocalTimeMillis() - localTime; + buf.Printf(_T("Finished PASS #%d in %ld seconds.\n"), passNumber, (long)(elapsed.GetLo()/1000.0)); OnInform((wxChar *)buf.c_str()); if (errorCount) @@ -1029,11 +1069,13 @@ bool Go(void) OnInform((wxChar *)buf.c_str()); } +#if wxUSE_STATUSBAR if (isInteractive) { buf.Printf(_T("Done, %d %s."), passNumber, (passNumber > 1) ? _T("passes") : _T("pass")); frame->SetStatusText((wxChar *)buf.c_str()); } +#endif // wxUSE_STATUSBAR #else buf.Printf(_T("Done, %d %s."), passNumber, (passNumber > 1) ? _T("passes") : _T("pass")); OnInform((wxChar *)buf.c_str()); @@ -1045,75 +1087,74 @@ bool Go(void) #endif passNumber ++; errorCount = 0; - OkToClose = TRUE; - return TRUE; + OkToClose = true; + return true; } TexCleanUp(); - startedSections = FALSE; + startedSections = false; -#ifndef NO_GUI +#if !defined(NO_GUI) && wxUSE_STATUSBAR frame->SetStatusText(_T("Aborted by user.")); #endif // GUI OnInform(_T("Sorry, unsuccessful.")); - OkToClose = TRUE; - return FALSE; + OkToClose = true; + return false; } void OnError(const wxChar *msg) { - errorCount++; + wxString msg_string = msg; + errorCount++; #ifdef NO_GUI - wxSTD cerr << "Error: " << msg << "\n"; - wxSTD cerr.flush(); -#else - if (isInteractive && frame) - (*frame->textWindow) << _T("Error: ") << msg << _T("\n"); - else -#ifdef __UNIX__ - { - wxSTD cerr << "Error: " << msg << "\n"; + wxSTD cerr << "Error: " << msg_string.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_string.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) { + wxString msg_string = msg; #ifdef NO_GUI - wxSTD cout << msg << "\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 << "\n"; + wxSTD cout << msg_string.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_string.mb_str() << "\n"; + wxSTD cout.flush(); +#elif defined(__WXMSW__) + wxLogInfo(msg); #endif -*/ - if (isInteractive) - { - Tex2RTFYield(TRUE); - } + } + + if (isInteractive) + { + Tex2RTFYield(true); + } #endif // NO_GUI } @@ -1159,7 +1200,7 @@ bool OnArgument(int macroId, int arg_no, bool start) // break; } } - return TRUE; + return true; } /* @@ -1192,21 +1233,17 @@ Tex2RTFConnection::Tex2RTFConnection(wxChar *buf, int size):wxDDEConnection(buf, { } -Tex2RTFConnection::~Tex2RTFConnection(void) -{ -} - bool SplitCommand(wxChar *data, wxChar *firstArg, wxChar *secondArg) { firstArg[0] = 0; secondArg[0] = 0; int i = 0; - bool stop = FALSE; + bool stop = false; // Find first argument (command name) while (!stop) { if (data[i] == ' ' || data[i] == 0) - stop = TRUE; + stop = true; else { firstArg[i] = data[i]; @@ -1227,7 +1264,7 @@ bool SplitCommand(wxChar *data, wxChar *firstArg, wxChar *secondArg) } secondArg[j] = 0; } - return TRUE; + return true; } bool Tex2RTFConnection::OnExecute(const wxString& WXUNUSED(topic), wxChar *data, int WXUNUSED(size), wxIPCFormat WXUNUSED(format)) @@ -1241,20 +1278,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); - wxSprintf(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) { @@ -1271,21 +1306,21 @@ bool Tex2RTFConnection::OnExecute(const wxString& WXUNUSED(topic), wxChar *data, else if (wxStrcmp(firstArg, _T("MINIMIZE")) == 0 || wxStrcmp(firstArg, _T("ICONIZE")) == 0) { if (frame) - frame->Iconize(TRUE); + frame->Iconize(true); } else if (wxStrcmp(firstArg, _T("SHOW")) == 0 || wxStrcmp(firstArg, _T("RESTORE")) == 0) { if (frame) { - frame->Iconize(FALSE); - frame->Show(TRUE); + frame->Iconize(false); + frame->Show(true); } } else { // Try for a setting - wxStrcpy(Tex2RTFLastStatus, RegisterSetting(firstArg, secondArg, FALSE)); -#ifndef NO_GUI + wxStrcpy(Tex2RTFLastStatus, RegisterSetting(firstArg, secondArg, false)); +#if !defined(NO_GUI) && wxUSE_STATUSBAR if (frame && wxStrcmp(firstArg, _T("conversionMode")) == 0) { wxChar buf[100]; @@ -1303,7 +1338,7 @@ bool Tex2RTFConnection::OnExecute(const wxString& WXUNUSED(topic), wxChar *data, #endif } } - return TRUE; + return true; } wxChar *Tex2RTFConnection::OnRequest(const wxString& WXUNUSED(topic), const wxString& WXUNUSED(item), int *WXUNUSED(size), wxIPCFormat WXUNUSED(format))