X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/12a44087e448071f9f108208a0a88e908d543d44..6dfec4b8d901b13f11745a1371083a0b8c1c6980:/utils/tex2rtf/src/tex2rtf.cpp diff --git a/utils/tex2rtf/src/tex2rtf.cpp b/utils/tex2rtf/src/tex2rtf.cpp index 42ca52a529..e5ac8969ce 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 @@ -59,7 +59,17 @@ bool OkToClose = TRUE; int passNumber = 1; #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; + +#if wxUSE_HELP wxHelpController *HelpInstance = NULL; +#endif // wxUSE_HELP #ifdef __WXMSW__ static char *ipc_buffer = NULL; @@ -101,6 +111,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 +141,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 +165,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 +183,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,6 +255,7 @@ bool MyApp::OnInit() else { OnError("Incorrect argument for -charset"); + return FALSE; } } } @@ -244,6 +269,7 @@ bool MyApp::OnInit() ShowOptions(); exit(1); #endif + return FALSE; } } @@ -321,16 +347,18 @@ bool MyApp::OnInit() 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 +373,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,7 +384,7 @@ bool MyApp::OnInit() * Read macro/initialisation file * */ - + wxString path; if ((path = TexPathList.FindValidPath(MacroFile)) != "") ReadCustomMacros((char*) (const char*) path); @@ -374,10 +402,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(); @@ -399,8 +429,83 @@ int MyApp::OnExit() MacroDefs.Clear(); #ifdef __WXMSW__ 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; + } // TODO: this simulates zero-memory leaks! // Otherwise there are just too many... @@ -410,7 +515,7 @@ int MyApp::OnExit() return 0; } - +#endif void ShowOptions(void) { char buf[100]; @@ -466,21 +571,19 @@ void MyFrame::OnCloseWindow(wxCloseEvent& event) } else if (OkToClose) { -#ifdef __WXMSW__ - delete TheTex2RTFServer; - wxDDECleanUp(); -#endif this->Destroy(); } } void MyFrame::OnExit(wxCommandEvent& event) { - this->Destroy(); + Close(); +// this->Destroy(); } void MyFrame::OnGo(wxCommandEvent& event) { + passNumber = 1; menuBar->EnableTop(0, FALSE); menuBar->EnableTop(1, FALSE); menuBar->EnableTop(2, FALSE); @@ -604,8 +707,10 @@ void MyFrame::OnModeXLP(wxCommandEvent& event) void MyFrame::OnHelp(wxCommandEvent& event) { +#if wxUSE_HELP HelpInstance->LoadFile(); HelpInstance->DisplayContents(); +#endif // wxUSE_HELP } void MyFrame::OnAbout(wxCommandEvent& event) @@ -650,12 +755,12 @@ void ChooseOutputFile(bool force) char extensionBuf[10]; char wildBuf[10]; strcpy(wildBuf, "*."); - char *path = NULL; + wxString path; if (OutputFile) path = wxPathOnly(OutputFile); else if (InputFile) path = wxPathOnly(InputFile); - + switch (convertMode) { case TEX_RTF: @@ -730,7 +835,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); @@ -750,7 +855,7 @@ bool Go(void) if (wxFileExists(RefName)) ReadTexReferences(RefName); - + bool success = FALSE; if (InputFile && OutputFile) @@ -808,7 +913,7 @@ bool Go(void) char buf[100]; #ifndef NO_GUI long tim = wxGetElapsedTime(); - sprintf(buf, "Finished in %ld seconds.", (long)(tim/1000.0)); + sprintf(buf, "Finished PASS #%d in %ld seconds.\n", passNumber, (long)(tim/1000.0)); OnInform(buf); if (isInteractive) { @@ -838,7 +943,7 @@ void OnError(char *msg) cerr << "Error: " << msg << "\n"; cerr.flush(); #else - if (isInteractive) + if (isInteractive && frame) (*frame->textWindow) << "Error: " << msg << "\n"; else #ifdef __UNIX__ @@ -860,7 +965,7 @@ void OnInform(char *msg) cout << msg << "\n"; cout.flush(); #else - if (isInteractive) + if (isInteractive && frame) (*frame->textWindow) << msg << "\n"; else #ifdef __WXMSW__ @@ -939,7 +1044,7 @@ wxConnectionBase *Tex2RTFServer::OnAcceptConnection(const wxString& topic) { if (!ipc_buffer) ipc_buffer = new char[1000]; - + return new Tex2RTFConnection(ipc_buffer, 4000); } else @@ -949,7 +1054,7 @@ wxConnectionBase *Tex2RTFServer::OnAcceptConnection(const wxString& topic) /* * Connection */ - + Tex2RTFConnection::Tex2RTFConnection(char *buf, int size):wxDDEConnection(buf, size) { } @@ -1029,8 +1134,7 @@ bool Tex2RTFConnection::OnExecute(const wxString& topic, char *data, int size, i } else if (strcmp(firstArg, "EXIT") == 0) { - if (frame && frame->OnClose()) - delete frame; + if (frame) frame->Close(); } else if (strcmp(firstArg, "MINIMIZE") == 0 || strcmp(firstArg, "ICONIZE") == 0) { @@ -1077,3 +1181,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