]> git.saurik.com Git - wxWidgets.git/blobdiff - utils/tex2rtf/src/tex2rtf.cpp
added QueryRawValue() to wxRegKey and test code for it in the sample
[wxWidgets.git] / utils / tex2rtf / src / tex2rtf.cpp
index d99f91343994965869c7d2351d82525d4d8b8c4f..e5ac8969cee815f094443f20cde637dc6fbcb711 100644 (file)
@@ -29,7 +29,7 @@
 #include <wx/timer.h>
 #endif
 
-#ifdef NO_GUI
+#if defined(NO_GUI) || defined(__UNIX__)
 #if wxUSE_IOSTREAMH
 #include <iostream.h>
 #include <fstream.h>
@@ -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();
@@ -401,7 +431,81 @@ 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;
+    }
 
   // TODO: this simulates zero-memory leaks!
   // Otherwise there are just too many...
@@ -411,7 +515,7 @@ int MyApp::OnExit()
 
   return 0;
 }
-
+#endif
 void ShowOptions(void)
 {
     char buf[100];
@@ -473,11 +577,13 @@ void MyFrame::OnCloseWindow(wxCloseEvent& event)
 
 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);
@@ -601,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)
@@ -647,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:
@@ -727,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);
@@ -747,7 +855,7 @@ bool Go(void)
 
   if (wxFileExists(RefName))
     ReadTexReferences(RefName);
-    
+
   bool success = FALSE;
 
   if (InputFile && OutputFile)
@@ -805,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)
     {
@@ -835,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__
@@ -857,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__
@@ -936,7 +1044,7 @@ wxConnectionBase *Tex2RTFServer::OnAcceptConnection(const wxString& topic)
   {
     if (!ipc_buffer)
       ipc_buffer = new char[1000];
-      
+
     return new Tex2RTFConnection(ipc_buffer, 4000);
   }
   else
@@ -946,7 +1054,7 @@ wxConnectionBase *Tex2RTFServer::OnAcceptConnection(const wxString& topic)
  /*
   * Connection
   */
-  
+
 Tex2RTFConnection::Tex2RTFConnection(char *buf, int size):wxDDEConnection(buf, size)
 {
 }
@@ -1026,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)
     {
@@ -1074,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