X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/63ad540d400df0e9e2a064367dd03ed84bd80710..c74d8df09d0c0e182cb2063cc4cc546de3a00fae:/utils/tex2rtf/src/tex2rtf.cpp diff --git a/utils/tex2rtf/src/tex2rtf.cpp b/utils/tex2rtf/src/tex2rtf.cpp index 3c121934fa..50b4466234 100644 --- a/utils/tex2rtf/src/tex2rtf.cpp +++ b/utils/tex2rtf/src/tex2rtf.cpp @@ -25,8 +25,8 @@ #endif #ifndef NO_GUI -#include -#include +#include "wx/help.h" +#include "wx/timer.h" #endif #if defined(NO_GUI) || defined(__UNIX__) @@ -45,7 +45,7 @@ #include "tex2rtf.h" #include "rtfutils.h" -#if (defined(__WXGTK__) || defined(__WXMOTIF__)) && !defined(NO_GUI) +#if (defined(__WXGTK__) || defined(__WXMOTIF__) || defined(__WXMAC__)) && !defined(NO_GUI) #include "tex2rtf.xpm" #endif @@ -119,7 +119,7 @@ char *ContentsName = NULL; // Contents page from last time around char *TmpContentsName = NULL; // Current contents page char *TmpFrameContentsName = NULL; // Current frame contents page char *WinHelpContentsFileName = NULL; // WinHelp .cnt file -char *RefName = NULL; // Reference file name +char *RefFileName = NULL; // Reference file name char *RTFCharset = copystring("ansi"); @@ -161,7 +161,7 @@ bool MyApp::OnInit() TmpContentsName = new char[300]; TmpFrameContentsName = new char[300]; WinHelpContentsFileName = new char[300]; - RefName = new char[300]; + RefFileName = new char[300]; ColourTable.DeleteContents(TRUE); @@ -192,7 +192,7 @@ bool MyApp::OnInit() if (!InputFile || !OutputFile) { - cout << "Tex2RTF: input or output file is missing.\n"; + wxSTD cout << "Tex2RTF: input or output file is missing.\n"; ShowOptions(); exit(1); } @@ -281,6 +281,16 @@ bool MyApp::OnInit() } } } + else if (strcmp(argv[i], "-checkcurleybraces") == 0) + { + i ++; + checkCurleyBraces = TRUE; + } + else if (strcmp(argv[i], "-checksyntax") == 0) + { + i ++; + checkSyntax = TRUE; + } else { wxString buf; @@ -354,6 +364,14 @@ bool MyApp::OnInit() mode_menu->Append(TEX_MODE_HTML, "Output &HTML", "HTML World Wide Web hypertext file"); mode_menu->Append(TEX_MODE_XLP, "Output &XLP", "wxHelp hypertext help file"); + wxMenu *options_menu = new wxMenu; + + options_menu->Append(TEX_OPTIONS_CURELY_BRACE, "Curley brace matching", "Checks for mismatched curley braces",TRUE); + options_menu->Append(TEX_OPTIONS_SYNTAX_CHECKING, "Syntax checking", "Syntax checking for common errors",TRUE); + + options_menu->Check(TEX_OPTIONS_CURELY_BRACE, checkCurleyBraces); + options_menu->Check(TEX_OPTIONS_SYNTAX_CHECKING, checkSyntax); + wxMenu *help_menu = new wxMenu; help_menu->Append(TEX_HELP, "&Help", "Tex2RTF Contents Page"); @@ -363,6 +381,7 @@ bool MyApp::OnInit() menuBar->Append(file_menu, "&File"); menuBar->Append(macro_menu, "&Macros"); menuBar->Append(mode_menu, "&Conversion Mode"); + menuBar->Append(options_menu, "&Options"); menuBar->Append(help_menu, "&Help"); frame->SetMenuBar(menuBar); @@ -511,10 +530,10 @@ int MyApp::OnExit() delete WinHelpContentsFileName; WinHelpContentsFileName = NULL; } - if (RefName) + if (RefFileName) { - delete RefName; - RefName = NULL; + delete RefFileName; + RefFileName = NULL; } if (TopLevel) { @@ -557,7 +576,9 @@ int MyApp::OnExit() // TODO: this simulates zero-memory leaks! // Otherwise there are just too many... #ifndef __WXGTK__ +#if (defined(__WXDEBUG__) && wxUSE_MEMORY_TRACING) || wxUSE_DEBUG_CONTEXT wxDebugContext::SetCheckpoint(); +#endif #endif return 0; @@ -570,11 +591,15 @@ void ShowOptions(void) OnInform(buf); OnInform("Usage: tex2rtf [input] [output] [switches]\n"); OnInform("where valid switches are"); +#ifndef NO_GUI OnInform(" -interactive"); +#endif OnInform(" -bufsize "); OnInform(" -charset (default ansi)"); OnInform(" -twice"); OnInform(" -sync"); + OnInform(" -checkcurleybraces"); + OnInform(" -checksyntax"); OnInform(" -macros "); OnInform(" -winhelp"); OnInform(" -rtf"); @@ -599,6 +624,8 @@ 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_SYNTAX_CHECKING, MyFrame::OnOptionsSyntaxChecking) EVT_MENU(TEX_HELP, MyFrame::OnHelp) EVT_MENU(TEX_ABOUT, MyFrame::OnAbout) END_EVENT_TABLE() @@ -640,7 +667,16 @@ void MyFrame::OnGo(wxCommandEvent& event) Tex2RTFYield(TRUE); Go(); - if (runTwice) + if (stopRunning) + { + SetStatusText("Build aborted!"); + wxString errBuf; + errBuf.Printf("\nErrors encountered during this pass: %lu\n", errorCount); + OnInform((char *)errBuf.c_str()); + } + + + if (runTwice && !stopRunning) { Tex2RTFYield(TRUE); Go(); @@ -753,6 +789,34 @@ void MyFrame::OnModeXLP(wxCommandEvent& event) SetStatusText("In XLP mode.", 1); } +void MyFrame::OnOptionsCurleyBrace(wxCommandEvent& event) +{ + checkCurleyBraces = !checkCurleyBraces; + if (checkCurleyBraces) + { + SetStatusText("Checking curley braces: YES", 1); + } + else + { + SetStatusText("Checking curley braces: NO", 1); + } +} + + +void MyFrame::OnOptionsSyntaxChecking(wxCommandEvent& event) +{ + checkSyntax = !checkSyntax; + if (checkSyntax) + { + SetStatusText("Checking syntax: YES", 1); + } + else + { + SetStatusText("Checking syntax: NO", 1); + } +} + + void MyFrame::OnHelp(wxCommandEvent& event) { #if wxUSE_HELP @@ -854,7 +918,7 @@ bool Go(void) ChooseOutputFile(); #endif - if (!InputFile || !OutputFile) + if (!InputFile || !OutputFile || stopRunning) return FALSE; #ifndef NO_GUI @@ -890,7 +954,7 @@ bool Go(void) sprintf(TmpContentsName, "%s.cn1", FileRoot); sprintf(TmpFrameContentsName, "%s.frc", FileRoot); sprintf(WinHelpContentsFileName, "%s.cnt", FileRoot); - sprintf(RefName, "%s.ref", FileRoot); + sprintf(RefFileName, "%s.ref", FileRoot); TexPathList.EnsureFileAccessible(InputFile); if (!bulletFile) @@ -903,8 +967,8 @@ bool Go(void) } } - if (wxFileExists(RefName)) - ReadTexReferences(RefName); + if (wxFileExists(RefFileName)) + ReadTexReferences(RefFileName); bool success = FALSE; @@ -920,7 +984,7 @@ bool Go(void) if (isInteractive) { wxString buf; - buf.Printf("Working, pass %d...", passNumber); + buf.Printf("Working, pass %d...Click CLOSE to abort", passNumber); frame->SetStatusText((char *)buf.c_str()); } #endif @@ -928,6 +992,12 @@ bool Go(void) OnInform("Reading LaTeX file..."); TexLoadFile(InputFile); + if (stopRunning) + { + OkToClose = TRUE; + return FALSE; + } + switch (convertMode) { case TEX_RTF: @@ -952,11 +1022,12 @@ bool Go(void) OnInform("*** Aborted by user."); success = FALSE; stopRunning = FALSE; + OkToClose = TRUE; } if (success) { - WriteTexReferences(RefName); + WriteTexReferences(RefFileName); TexCleanUp(); startedSections = FALSE; @@ -995,26 +1066,30 @@ bool Go(void) TexCleanUp(); startedSections = FALSE; +#ifndef NO_GUI + frame->SetStatusText("Aborted by user."); +#endif // GUI + OnInform("Sorry, unsuccessful."); OkToClose = TRUE; return FALSE; } -void OnError(char *msg) +void OnError(const char *msg) { errorCount++; #ifdef NO_GUI - cerr << "Error: " << msg << "\n"; - cerr.flush(); + wxSTD cerr << "Error: " << msg << "\n"; + wxSTD cerr.flush(); #else if (isInteractive && frame) (*frame->textWindow) << "Error: " << msg << "\n"; else #ifdef __UNIX__ { - cerr << "Error: " << msg << "\n"; - cerr.flush(); + wxSTD cerr << "Error: " << msg << "\n"; + wxSTD cerr.flush(); } #endif @@ -1025,24 +1100,30 @@ void OnError(char *msg) #endif // NO_GUI } -void OnInform(char *msg) +void OnInform(const char *msg) { #ifdef NO_GUI - cout << msg << "\n"; - cout.flush(); + wxSTD cout << msg << "\n"; + wxSTD cout.flush(); #else if (isInteractive && frame) (*frame->textWindow) << msg << "\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__ { - cout << msg << "\n"; - cout.flush(); + wxSTD cout << msg << "\n"; + wxSTD cout.flush(); } #endif #ifdef __WXMSW__ {} #endif +*/ if (isInteractive) { Tex2RTFYield(TRUE); @@ -1249,7 +1330,7 @@ char *Tex2RTFConnection::OnRequest(const wxString& topic, const wxString& item, #ifndef NO_GUI #ifndef __WXGTK__ -//void wxObject::Dump(ostream& str) +//void wxObject::Dump(wxSTD ostream& str) //{ // if (GetClassInfo() && GetClassInfo()->GetClassName()) // str << GetClassInfo()->GetClassName();