X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/aed0ed3c420d6821e81ca6243482e620c4aeeffd..a763ac036b30921d5c76a393c03dc19bf36fd0b7:/utils/tex2rtf/src/tex2rtf.cpp?ds=sidebyside diff --git a/utils/tex2rtf/src/tex2rtf.cpp b/utils/tex2rtf/src/tex2rtf.cpp index a61db85708..55f736ae0d 100644 --- a/utils/tex2rtf/src/tex2rtf.cpp +++ b/utils/tex2rtf/src/tex2rtf.cpp @@ -29,7 +29,7 @@ #include #endif -#ifdef NO_GUI +#if defined(NO_GUI) || defined(__UNIX__) #if wxUSE_IOSTREAMH #include #include @@ -57,9 +57,41 @@ char *contentsString = NULL; bool suppressNameDecoration = FALSE; bool OkToClose = TRUE; int passNumber = 1; +int errorCount = 0; #ifndef NO_GUI + +extern char *BigBuffer; +extern char *TexFileRoot; +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; +#endif // wxUSE_HELP #ifdef __WXMSW__ static char *ipc_buffer = NULL; @@ -101,6 +133,13 @@ bool Go(void); void ShowOptions(void); #ifdef NO_GUI + +#if wxUSE_GUI || !defined(__UNIX__) +// wxBase for Unix does not have wxBuffer +extern +#endif +char *wxBuffer; // we must init it, otherwise tex2rtf will crash + int main(int argc, char **argv) #else wxMenuBar *menuBar = NULL; @@ -124,8 +163,10 @@ bool MyApp::OnInit() WinHelpContentsFileName = new char[300]; RefName = new char[300]; + ColourTable.DeleteContents(TRUE); + int n = 1; - + // Read input/output files if (argc > 1) { @@ -146,12 +187,16 @@ bool MyApp::OnInit() } #ifdef NO_GUI + wxBuffer = new char[1500]; + // this is done in wxApp, but NO_GUI version doesn't call it :-( + if (!InputFile || !OutputFile) { cout << "Tex2RTF: input or output file is missing.\n"; ShowOptions(); exit(1); } + #endif if (InputFile) { @@ -160,7 +205,8 @@ bool MyApp::OnInit() if (!InputFile || !OutputFile) isInteractive = TRUE; - for (int i = n; i < argc;) + int i; + for (i = n; i < argc;) { if (strcmp(argv[i], "-winhelp") == 0) { @@ -231,19 +277,31 @@ bool MyApp::OnInit() else { OnError("Incorrect argument for -charset"); + return FALSE; } } } + 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(); exit(1); #endif + return FALSE; } } @@ -306,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"); @@ -315,22 +381,25 @@ 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); frame->textWindow = new wxTextCtrl(frame, -1, "", wxPoint(-1, -1), wxSize(-1, -1), wxTE_READONLY|wxTE_MULTILINE); (*frame->textWindow) << "Welcome to Julian Smart's LaTeX to RTF converter.\n"; -// ShowOptions(); +// ShowOptions(); +#if wxUSE_HELP HelpInstance = new wxHelpController(); HelpInstance->Initialize("tex2rtf"); +#endif // wxUSE_HELP /* * Read macro/initialisation file * */ - + wxString path; if ((path = TexPathList.FindValidPath(MacroFile)) != "") ReadCustomMacros((char*) (const char*) path); @@ -345,7 +414,7 @@ bool MyApp::OnInit() else if (convertMode == TEX_XLP) strcat(buf, "XLP"); strcat(buf, " mode."); frame->SetStatusText(buf, 1); - + frame->Show(TRUE); return TRUE; } @@ -356,13 +425,16 @@ bool MyApp::OnInit() * Read macro/initialisation file * */ - + wxString path; if ((path = TexPathList.FindValidPath(MacroFile)) != "") ReadCustomMacros((char*) (const char*) path); Go(); - if (runTwice) Go(); + if (runTwice) + { + Go(); + } #ifdef NO_GUI return 0; #else @@ -374,10 +446,12 @@ bool MyApp::OnInit() // Return the main frame window return TRUE; #else + delete[] wxBuffer; return FALSE; #endif } +#ifndef NO_GUI int MyApp::OnExit() { wxNode *node = CustomMacroList.First(); @@ -401,17 +475,115 @@ int MyApp::OnExit() delete TheTex2RTFServer; wxDDECleanUp(); #endif + +#if wxUSE_HELP delete HelpInstance; +#endif // wxUSE_HELP + + if (BigBuffer) + { + delete BigBuffer; + BigBuffer = NULL; + } + if (currentArgData) + { + delete currentArgData; + currentArgData = NULL; + } + if (TexFileRoot) + { + delete TexFileRoot; + TexFileRoot = NULL; + } + if (TexBibName) + { + delete TexBibName; + TexBibName = NULL; + } + if (TexTmpBibName) + { + delete TexTmpBibName; + TexTmpBibName = NULL; + } + if (FileRoot) + { + delete FileRoot; + FileRoot = NULL; + } + if (ContentsName) + { + delete ContentsName; + ContentsName = NULL; + } + if (TmpContentsName) + { + delete TmpContentsName; + TmpContentsName = NULL; + } + if (TmpFrameContentsName) + { + delete TmpFrameContentsName; + TmpFrameContentsName = NULL; + } + if (WinHelpContentsFileName) + { + delete WinHelpContentsFileName; + WinHelpContentsFileName = NULL; + } + if (RefName) + { + delete RefName; + RefName = NULL; + } + if (TopLevel) + { + delete TopLevel; + TopLevel = NULL; + } + if (MacroFile) + { + delete MacroFile; + MacroFile = NULL; + } + if (RTFCharset) + { + delete RTFCharset; + 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; } - +#endif void ShowOptions(void) { char buf[100]; @@ -424,6 +596,8 @@ void ShowOptions(void) OnInform(" -charset (default ansi)"); OnInform(" -twice"); OnInform(" -sync"); + OnInform(" -checkcurleybraces"); + OnInform(" -checksyntax"); OnInform(" -macros "); OnInform(" -winhelp"); OnInform(" -rtf"); @@ -448,6 +622,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() @@ -473,11 +649,14 @@ void MyFrame::OnCloseWindow(wxCloseEvent& event) void MyFrame::OnExit(wxCommandEvent& event) { - this->Destroy(); + Close(); +// this->Destroy(); } void MyFrame::OnGo(wxCommandEvent& event) { + passNumber = 1; + errorCount = 0; menuBar->EnableTop(0, FALSE); menuBar->EnableTop(1, FALSE); menuBar->EnableTop(2, FALSE); @@ -599,10 +778,40 @@ 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 HelpInstance->LoadFile(); HelpInstance->DisplayContents(); +#endif // wxUSE_HELP } void MyFrame::OnAbout(wxCommandEvent& event) @@ -632,11 +841,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; } } @@ -652,7 +863,7 @@ void ChooseOutputFile(bool force) path = wxPathOnly(OutputFile); else if (InputFile) path = wxPathOnly(InputFile); - + switch (convertMode) { case TEX_RTF: @@ -727,7 +938,7 @@ bool Go(void) if(strlen( sName) > 5) sName[5] = '\0'; // that should do! } - + sprintf(ContentsName, "%s.con", FileRoot); sprintf(TmpContentsName, "%s.cn1", FileRoot); sprintf(TmpFrameContentsName, "%s.frc", FileRoot); @@ -747,7 +958,7 @@ bool Go(void) if (wxFileExists(RefName)) ReadTexReferences(RefName); - + bool success = FALSE; if (InputFile && OutputFile) @@ -761,9 +972,9 @@ 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; @@ -802,21 +1013,34 @@ bool Go(void) TexCleanUp(); startedSections = FALSE; - char buf[100]; + wxString buf; #ifndef NO_GUI long tim = wxGetElapsedTime(); - sprintf(buf, "Finished in %ld seconds.", (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; } @@ -824,6 +1048,10 @@ bool Go(void) TexCleanUp(); startedSections = FALSE; +#ifndef NO_GUI + frame->SetStatusText("Aborted by user."); +#endif // GUI + OnInform("Sorry, unsuccessful."); OkToClose = TRUE; return FALSE; @@ -831,11 +1059,13 @@ bool Go(void) void OnError(char *msg) { + errorCount++; + #ifdef NO_GUI cerr << "Error: " << msg << "\n"; cerr.flush(); #else - if (isInteractive) + if (isInteractive && frame) (*frame->textWindow) << "Error: " << msg << "\n"; else #ifdef __UNIX__ @@ -844,6 +1074,7 @@ void OnError(char *msg) cerr.flush(); } #endif + #ifdef __WXMSW__ wxError(msg); #endif @@ -857,8 +1088,13 @@ void OnInform(char *msg) cout << msg << "\n"; cout.flush(); #else - if (isInteractive) + 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__ { @@ -869,6 +1105,7 @@ void OnInform(char *msg) #ifdef __WXMSW__ {} #endif +*/ if (isInteractive) { Tex2RTFYield(TRUE); @@ -936,7 +1173,7 @@ wxConnectionBase *Tex2RTFServer::OnAcceptConnection(const wxString& topic) { if (!ipc_buffer) ipc_buffer = new char[1000]; - + return new Tex2RTFConnection(ipc_buffer, 4000); } else @@ -946,7 +1183,7 @@ wxConnectionBase *Tex2RTFServer::OnAcceptConnection(const wxString& topic) /* * Connection */ - + Tex2RTFConnection::Tex2RTFConnection(char *buf, int size):wxDDEConnection(buf, size) { } @@ -1073,3 +1310,14 @@ char *Tex2RTFConnection::OnRequest(const wxString& topic, const wxString& item, #endif +#ifndef NO_GUI +#ifndef __WXGTK__ +//void wxObject::Dump(ostream& str) +//{ +// if (GetClassInfo() && GetClassInfo()->GetClassName()) +// str << GetClassInfo()->GetClassName(); +// else +// str << "unknown object class"; +//} +#endif +#endif