X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/71599f0a0ad3084f7c366d91db9384b56c82614a..34a1d7328f198b5ad31c33a07a6078f089feb45f:/utils/tex2rtf/src/tex2rtf.cpp diff --git a/utils/tex2rtf/src/tex2rtf.cpp b/utils/tex2rtf/src/tex2rtf.cpp index e5ac8969ce..425b828075 100644 --- a/utils/tex2rtf/src/tex2rtf.cpp +++ b/utils/tex2rtf/src/tex2rtf.cpp @@ -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 @@ -57,6 +57,7 @@ char *contentsString = NULL; bool suppressNameDecoration = FALSE; bool OkToClose = TRUE; int passNumber = 1; +int errorCount = 0; #ifndef NO_GUI @@ -66,6 +67,27 @@ extern char *TexBibName; // Bibliography output file name extern char *TexTmpBibName; // Temporary bibliography output file name extern wxList ColourTable; extern TexChunk *TopLevel; +extern char *PageStyle; +extern char *BibliographyStyleString; +extern char *DocumentStyleString; +extern char *bitmapMethod; +extern char *backgroundColourString; +extern char *ContentsNameString; +extern char *AbstractNameString; +extern char *GlossaryNameString; +extern char *ReferencesNameString; +extern char *FiguresNameString; +extern char *TablesNameString; +extern char *FigureNameString; +extern char *TableNameString; +extern char *IndexNameString; +extern char *ChapterNameString; +extern char *SectionNameString; +extern char *SubsectionNameString; +extern char *SubsubsectionNameString; +extern char *UpNameString; + + #if wxUSE_HELP wxHelpController *HelpInstance = NULL; @@ -259,11 +281,21 @@ bool MyApp::OnInit() } } } + else if (strcmp(argv[i], "-checkcurleybraces") == 0) + { + i ++; + checkCurleyBraces = TRUE; + } + else if (strcmp(argv[i], "-checksyntax") == 0) + { + i ++; + checkSyntax = TRUE; + } else { - char buf[100]; - sprintf(buf, "Invalid switch %s.\n", argv[i]); - OnError(buf); + wxString buf; + buf.Printf("Invalid switch %s.\n", argv[i]); + OnError((char *)buf.c_str()); i++; #ifdef NO_GUI ShowOptions(); @@ -332,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"); @@ -341,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); @@ -390,7 +431,10 @@ bool MyApp::OnInit() ReadCustomMacros((char*) (const char*) path); Go(); - if (runTwice) Go(); + if (runTwice) + { + Go(); + } #ifdef NO_GUI return 0; #else @@ -507,10 +551,34 @@ int MyApp::OnExit() RTFCharset = NULL; } + delete [] PageStyle; + delete [] BibliographyStyleString; + delete [] DocumentStyleString; + delete [] bitmapMethod; + delete [] backgroundColourString; + delete [] ContentsNameString; + delete [] AbstractNameString; + delete [] GlossaryNameString; + delete [] ReferencesNameString; + delete [] FiguresNameString; + delete [] TablesNameString; + delete [] FigureNameString; + delete [] TableNameString; + delete [] IndexNameString; + delete [] ChapterNameString; + delete [] SectionNameString; + delete [] SubsectionNameString; + delete [] SubsubsectionNameString; + delete [] UpNameString; + if (winHelpTitle) + delete[] winHelpTitle; + // 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; @@ -523,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"); @@ -552,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() @@ -584,6 +658,7 @@ void MyFrame::OnExit(wxCommandEvent& event) void MyFrame::OnGo(wxCommandEvent& event) { passNumber = 1; + errorCount = 0; menuBar->EnableTop(0, FALSE); menuBar->EnableTop(1, FALSE); menuBar->EnableTop(2, FALSE); @@ -592,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(); @@ -705,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 @@ -740,11 +852,13 @@ void ChooseInputFile(bool force) ClearKeyWordTable(); ResetContentsLevels(0); passNumber = 1; - char buf[300]; + errorCount = 0; + InputFile = copystring(s); wxString str = wxFileNameFromPath(InputFile); - sprintf(buf, "Tex2RTF [%s]", (const char*) str); - frame->SetTitle(buf); + wxString buf; + buf.Printf("Tex2RTF [%s]", str.c_str()); + frame->SetTitle((char *)buf.c_str()); OutputFile = NULL; } } @@ -804,7 +918,7 @@ bool Go(void) ChooseOutputFile(); #endif - if (!InputFile || !OutputFile) + if (!InputFile || !OutputFile || stopRunning) return FALSE; #ifndef NO_GUI @@ -869,15 +983,21 @@ bool Go(void) #ifndef NO_GUI if (isInteractive) { - char buf[50]; - sprintf(buf, "Working, pass %d...", passNumber); - frame->SetStatusText(buf); + wxString buf; + buf.Printf("Working, pass %d...Click CLOSE to abort", passNumber); + frame->SetStatusText((char *)buf.c_str()); } #endif OkToClose = FALSE; OnInform("Reading LaTeX file..."); TexLoadFile(InputFile); + if (stopRunning) + { + OkToClose = TRUE; + return FALSE; + } + switch (convertMode) { case TEX_RTF: @@ -902,6 +1022,7 @@ bool Go(void) OnInform("*** Aborted by user."); success = FALSE; stopRunning = FALSE; + OkToClose = TRUE; } if (success) @@ -910,21 +1031,34 @@ bool Go(void) TexCleanUp(); startedSections = FALSE; - char buf[100]; + wxString buf; #ifndef NO_GUI long tim = wxGetElapsedTime(); - sprintf(buf, "Finished PASS #%d in %ld seconds.\n", passNumber, (long)(tim/1000.0)); - OnInform(buf); + buf.Printf("Finished PASS #%d in %ld seconds.\n", passNumber, (long)(tim/1000.0)); + OnInform((char *)buf.c_str()); + + if (errorCount) + { + buf.Printf("Errors encountered during this pass: %lu\n", errorCount); + OnInform((char *)buf.c_str()); + } + if (isInteractive) { - sprintf(buf, "Done, %d %s.", passNumber, (passNumber > 1) ? "passes" : "pass"); - frame->SetStatusText(buf); + buf.Printf("Done, %d %s.", passNumber, (passNumber > 1) ? "passes" : "pass"); + frame->SetStatusText((char *)buf.c_str()); } #else - sprintf(buf, "Done, %d %s.", passNumber, (passNumber > 1) ? "passes" : "pass"); - OnInform(buf); + buf.Printf("Done, %d %s.", passNumber, (passNumber > 1) ? "passes" : "pass"); + OnInform((char *)buf.c_str()); + if (errorCount) + { + buf.Printf("Errors encountered during this pass: %lu\n", errorCount); + OnInform((char *)buf.c_str()); + } #endif passNumber ++; + errorCount = 0; OkToClose = TRUE; return TRUE; } @@ -932,6 +1066,10 @@ bool Go(void) TexCleanUp(); startedSections = FALSE; +#ifndef NO_GUI + frame->SetStatusText("Aborted by user."); +#endif // GUI + OnInform("Sorry, unsuccessful."); OkToClose = TRUE; return FALSE; @@ -939,6 +1077,8 @@ bool Go(void) void OnError(char *msg) { + errorCount++; + #ifdef NO_GUI cerr << "Error: " << msg << "\n"; cerr.flush(); @@ -952,6 +1092,7 @@ void OnError(char *msg) cerr.flush(); } #endif + #ifdef __WXMSW__ wxError(msg); #endif @@ -967,6 +1108,11 @@ void OnInform(char *msg) #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__ { @@ -977,6 +1123,7 @@ void OnInform(char *msg) #ifdef __WXMSW__ {} #endif +*/ if (isInteractive) { Tex2RTFYield(TRUE); @@ -1183,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();