]> git.saurik.com Git - wxWidgets.git/blobdiff - utils/tex2rtf/src/rtfutils.cpp
Set CHRBITS to the "correct" amount.
[wxWidgets.git] / utils / tex2rtf / src / rtfutils.cpp
index 735745b2c4f3579a61cdf8002be9a907682a28d6..676d2f561395bf5f6a58ed0ef6f424a3bc902b33 100644 (file)
@@ -21,7 +21,6 @@
 #endif
 
 #ifndef WX_PRECOMP
-#include "wx/wx.h"
 #endif
 
 #include "tex2any.h"
 #include "bmputils.h"
 #include "table.h"
 
+#if !WXWIN_COMPATIBILITY_2_4
+static inline wxChar* copystring(const wxChar* s)
+    { return wxStrcpy(new wxChar[wxStrlen(s) + 1], s); }
+#endif
+
 wxList itemizeStack;
 static int indentLevel = 0;
 static int forbidParindent = 0; // if > 0, no parindent (e.g. in center environment)
@@ -58,6 +62,9 @@ extern FILE *WinHelpContentsFile;
 extern char *RTFCharset;
 // This is defined in the Tex2Any library and isn't in use after parsing
 extern char *BigBuffer;
+
+extern wxHashTable TexReferences;
+
 // Are we in verbatim mode? If so, format differently.
 static bool inVerbatim = FALSE;
 
@@ -90,6 +97,8 @@ static int TwoColWidthB = 3000;
 
 const int PageWidth = 12242; // 8.25 inches wide for A4
 
+// Remember the anchor in a helpref
+static TexChunk *helpRefText = NULL;
 
 /*
  * Flag to say we've just issued a \par\pard command, so don't
@@ -208,18 +217,18 @@ void ResetContentsLevels(int l)
 // : for space.
 void OutputSectionKeyword(FILE *fd)
 {
-  OutputCurrentSectionToString(wxBuffer);
+  OutputCurrentSectionToString(wxTex2RTFBuffer);
   
   unsigned int i;
-  for (i = 0; i < strlen(wxBuffer); i++)
-    if (wxBuffer[i] == ':')
-      wxBuffer[i] = ' ';
+  for (i = 0; i < strlen(wxTex2RTFBuffer); i++)
+    if (wxTex2RTFBuffer[i] == ':')
+      wxTex2RTFBuffer[i] = ' ';
     // Don't write to index if there's some RTF in the string
-    else if ( wxBuffer[i] == '{' )
+    else if ( wxTex2RTFBuffer[i] == '{' )
         return;
 
   fprintf(fd, "K{\\footnote {K} ");
-  fprintf(fd, "%s", wxBuffer);
+  fprintf(fd, "%s", wxTex2RTFBuffer);
   
   fprintf(fd, "}\n");
 }
@@ -238,7 +247,6 @@ void WriteWinHelpContentsFileLine(char *topicName, char *xitle, int level)
                  char ch1=xitle[s+1]&0xff;
                  char ch2=xitle[s+2]&0xff;
                  char ch3=xitle[s+3]&0xff;
-                 char ch4=xitle[s+4]&0xff;
                  s+=4; // next character                 
                  char a=0;
                  if ((ch1==0x27)&&(ch2==0x66)&&(ch3==0x36)) { title[d++]='รถ';  a=1; }
@@ -339,10 +347,10 @@ void GenerateKeywordsForTopic(char *topic)
   wxStringList *list = texTopic->keywords;
   if (list)
   {
-    wxNode *node = list->First();
+    wxStringListNode *node = list->GetFirst();
     while (node)
     {
-      char *s = (char *)node->Data();
+      char *s = (char *)node->GetData();
 
       // Must separate out main entry form subentry (only 1 subentry allowed)
       char buf1[100]; char buf2[100];
@@ -368,7 +376,7 @@ void GenerateKeywordsForTopic(char *topic)
         TexOutput(buf2);
       }
       TexOutput("}\n");
-      node = node->Next();
+      node = node->GetNext();
     }
   }
 }
@@ -404,12 +412,12 @@ void GenerateIndexEntry(char *entry)
 void WriteColourTable(FILE *fd)
 {
   fprintf(fd, "{\\colortbl");
-  wxNode *node = ColourTable.First();
+  wxNode *node = ColourTable.GetFirst();
   while (node)
   {
-    ColourTableEntry *entry = (ColourTableEntry *)node->Data();
+    ColourTableEntry *entry = (ColourTableEntry *)node->GetData();
     fprintf(fd, "\\red%d\\green%d\\blue%d;\n", entry->red, entry->green, entry->blue);
-    node = node->Next();
+    node = node->GetNext();
   }
   fprintf(fd, "}");
 }
@@ -522,7 +530,7 @@ bool WriteHPJ(char *filename)
   StripExtension(hpjFilename);
   strcat(hpjFilename, ".hpj");
 
-  strcpy(helpFile, FileNameFromPath(filename));
+  strcpy(helpFile, wxFileNameFromPath(filename));
   StripExtension(helpFile);
   strcpy(rtfFile, helpFile);
   strcat(helpFile, ".hlp");
@@ -662,7 +670,7 @@ void ProcessText2RTF(TexChunk *chunk)
       i += 1;
       changed = TRUE;
     }
-    else if (inVerbatim && (ch == '{' || ch == '}')) // Escape the curly bracket
+    else if (inVerbatim && (ch == '{' || ch == '}')) // Escape the curley bracket
     {
       BigBuffer[ptr] = '\\'; ptr ++;
       BigBuffer[ptr] = ch; ptr ++;
@@ -709,12 +717,12 @@ void Text2RTF(TexChunk *chunk)
       if (def && (def->macroId == ltVERBATIM || def->macroId == ltVERB))
         inVerbatim = TRUE;
 
-      wxNode *node = chunk->children.First();
+      wxNode *node = chunk->children.GetFirst();
       while (node)
       {
-        TexChunk *child_chunk = (TexChunk *)node->Data();
+        TexChunk *child_chunk = (TexChunk *)node->GetData();
         Text2RTF(child_chunk);
-        node = node->Next();
+        node = node->GetNext();
       }
 
       if (def && (def->macroId == ltVERBATIM || def->macroId == ltVERB))
@@ -724,12 +732,12 @@ void Text2RTF(TexChunk *chunk)
     }
     case CHUNK_TYPE_ARG:
     {
-      wxNode *node = chunk->children.First();
+      wxNode *node = chunk->children.GetFirst();
       while (node)
       {
-        TexChunk *child_chunk = (TexChunk *)node->Data();
+        TexChunk *child_chunk = (TexChunk *)node->GetData();
         Text2RTF(child_chunk);
-        node = node->Next();
+        node = node->GetNext();
       }
 
       break;
@@ -776,10 +784,10 @@ void PushEnvironmentStyle(char *style)
 
 void PopEnvironmentStyle(void)
 {
-  wxNode *node = environmentStack.Last();
+  wxStringListNode *node = environmentStack.GetLast();
   if (node)
   {
-    char *val = (char *)node->Data();
+    char *val = (char *)node->GetData();
     delete[] val;
     delete node;
   }
@@ -788,12 +796,12 @@ void PopEnvironmentStyle(void)
 // Write out the styles, most recent first.
 void WriteEnvironmentStyles(void)
 {
-  wxNode *node = environmentStack.Last();
+  wxStringListNode *node = environmentStack.GetLast();
   while (node)
   {
-    char *val = (char *)node->Data();
+    char *val = (char *)node->GetData();
     TexOutput(val);
-    node = node->Next();
+    node = node->GetNext();
   }
   if (!inTabular && (ParIndent > 0) && (forbidParindent == 0))
   {
@@ -801,7 +809,7 @@ void WriteEnvironmentStyles(void)
     sprintf(buf, "\\fi%d", ParIndent*20); // Convert points to TWIPS
     TexOutput(buf);
   }
-  if (environmentStack.Number() > 0 || (ParIndent > 0))
+  if (environmentStack.GetCount() > 0 || (ParIndent > 0))
     TexOutput("\n");
 }
 
@@ -1108,8 +1116,8 @@ void RTFOnMacro(int macroId, int no_args, bool start)
 
       if (winHelpContents && winHelp && !InPopups())
       {
-        OutputCurrentSectionToString(wxBuffer);
-        WriteWinHelpContentsFileLine(topicName, wxBuffer, 1);
+        OutputCurrentSectionToString(wxTex2RTFBuffer);
+        WriteWinHelpContentsFileLine(topicName, wxTex2RTFBuffer, 1);
       }
       AddTexRef(topicName, NULL, ChapterNameString, chapterNo);
 
@@ -1190,7 +1198,7 @@ void RTFOnMacro(int macroId, int no_args, bool start)
             fprintf(Chapters, "!{\\footnote DisableButton(\"Up\")}\n");
           else
             fprintf(Chapters, "!{\\footnote EnableButton(\"Up\");ChangeButtonBinding(\"Up\", \"JumpId(`%s.hlp', `%s')\")}\n",
-               FileNameFromPath(FileRoot), "Contents");
+               wxFileNameFromPath(FileRoot), "Contents");
         }
       }
 
@@ -1250,8 +1258,8 @@ void RTFOnMacro(int macroId, int no_args, bool start)
       NotifyParentHasChildren(1);
       if (winHelpContents && winHelp && !InPopups())
       {
-        OutputCurrentSectionToString(wxBuffer);
-        WriteWinHelpContentsFileLine(topicName, wxBuffer, 2);
+        OutputCurrentSectionToString(wxTex2RTFBuffer);
+        WriteWinHelpContentsFileLine(topicName, wxTex2RTFBuffer, 2);
       }
       AddTexRef(topicName, NULL, SectionNameString, chapterNo, sectionNo);
 
@@ -1345,12 +1353,12 @@ void RTFOnMacro(int macroId, int no_args, bool start)
           if (DocumentStyle == LATEX_ARTICLE)
           {
             fprintf(Sections, "!{\\footnote EnableButton(\"Up\");ChangeButtonBinding(\"Up\", \"JumpId(`%s.hlp', `%s')\")}\n",
-               FileNameFromPath(FileRoot), "Contents");
+               wxFileNameFromPath(FileRoot), "Contents");
           }
           else if (CurrentChapterName)
           {
             fprintf(Sections, "!{\\footnote EnableButton(\"Up\");ChangeButtonBinding(\"Up\", \"JumpId(`%s.hlp', `%s')\")}\n",
-               FileNameFromPath(FileRoot), CurrentChapterName);
+               wxFileNameFromPath(FileRoot), CurrentChapterName);
           }
         }
       }
@@ -1434,8 +1442,8 @@ void RTFOnMacro(int macroId, int no_args, bool start)
       NotifyParentHasChildren(2);
       if (winHelpContents && winHelp && !InPopups())
       {
-        OutputCurrentSectionToString(wxBuffer);
-        WriteWinHelpContentsFileLine(topicName, wxBuffer, 3);
+        OutputCurrentSectionToString(wxTex2RTFBuffer);
+        WriteWinHelpContentsFileLine(topicName, wxTex2RTFBuffer, 3);
       }
       AddTexRef(topicName, NULL, SectionNameString, chapterNo, sectionNo, subsectionNo);
 
@@ -1496,7 +1504,7 @@ void RTFOnMacro(int macroId, int no_args, bool start)
         if (useUpButton && CurrentSectionName)
         {
           fprintf(Subsections, "!{\\footnote EnableButton(\"Up\");ChangeButtonBinding(\"Up\", \"JumpId(`%s.hlp', `%s')\")}\n",
-             FileNameFromPath(FileRoot), CurrentSectionName);
+             wxFileNameFromPath(FileRoot), CurrentSectionName);
         }
       }
       if (!winHelp && indexSubsections && useWord)
@@ -1584,8 +1592,8 @@ void RTFOnMacro(int macroId, int no_args, bool start)
       NotifyParentHasChildren(3);
       if (winHelpContents && winHelp)
       {
-        OutputCurrentSectionToString(wxBuffer);
-        WriteWinHelpContentsFileLine(topicName, wxBuffer, 4);
+        OutputCurrentSectionToString(wxTex2RTFBuffer);
+        WriteWinHelpContentsFileLine(topicName, wxTex2RTFBuffer, 4);
       }
       AddTexRef(topicName, NULL, SectionNameString, chapterNo, sectionNo, subsectionNo, subsubsectionNo);
 
@@ -1642,7 +1650,7 @@ void RTFOnMacro(int macroId, int no_args, bool start)
         if (useUpButton && CurrentSubsectionName)
         {
           fprintf(Subsubsections, "!{\\footnote EnableButton(\"Up\");ChangeButtonBinding(\"Up\", \"JumpId(`%s.hlp', `%s')\")}\n",
-             FileNameFromPath(FileRoot), CurrentSubsectionName);
+             wxFileNameFromPath(FileRoot), CurrentSubsectionName);
         }
       }
       if (!winHelp && indexSubsections && useWord)
@@ -2020,9 +2028,9 @@ void RTFOnMacro(int macroId, int no_args, bool start)
         listType = LATEX_DESCRIPTION;
 
       int oldIndent = 0;
-      wxNode *node = itemizeStack.First();
+      wxNode *node = itemizeStack.GetFirst();
       if (node)
-        oldIndent = ((ItemizeStruc *)node->Data())->indentation;
+        oldIndent = ((ItemizeStruc *)node->GetData())->indentation;
 
       int indentSize1 = oldIndent + 20*labelIndentTab;
       int indentSize2 = oldIndent + 20*itemIndentTab;
@@ -2039,11 +2047,11 @@ void RTFOnMacro(int macroId, int no_args, bool start)
       indentLevel --;
       PopEnvironmentStyle();
 
-      if (itemizeStack.First())
+      if (itemizeStack.GetFirst())
       {
-        ItemizeStruc *struc = (ItemizeStruc *)itemizeStack.First()->Data();
+        ItemizeStruc *struc = (ItemizeStruc *)itemizeStack.GetFirst()->GetData();
         delete struc;
-        delete itemizeStack.First();
+        delete itemizeStack.GetFirst();
       }
 /* Change 18/7/97 - don't know why we wish to do this
       if (itemizeStack.Number() == 0)
@@ -2062,9 +2070,9 @@ void RTFOnMacro(int macroId, int no_args, bool start)
     {
       indentLevel ++;
       int oldIndent = 0;
-      wxNode *node = itemizeStack.First();
+      wxNode *node = itemizeStack.GetFirst();
       if (node)
-        oldIndent = ((ItemizeStruc *)node->Data())->indentation;
+        oldIndent = ((ItemizeStruc *)node->GetData())->indentation;
 
       int indentSize = oldIndent + TwoColWidthA;
 
@@ -2079,11 +2087,11 @@ void RTFOnMacro(int macroId, int no_args, bool start)
     {
       indentLevel --;
       PopEnvironmentStyle();
-      if (itemizeStack.First())
+      if (itemizeStack.GetFirst())
       {
-        ItemizeStruc *struc = (ItemizeStruc *)itemizeStack.First()->Data();
+        ItemizeStruc *struc = (ItemizeStruc *)itemizeStack.GetFirst()->GetData();
         delete struc;
-        delete itemizeStack.First();
+        delete itemizeStack.GetFirst();
       }
 /*
       // JACS June 1997
@@ -2091,7 +2099,7 @@ void RTFOnMacro(int macroId, int no_args, bool start)
       WriteEnvironmentStyles();
 */
 /* why do we need this? */
-      if (itemizeStack.Number() == 0)
+      if (itemizeStack.GetCount() == 0)
       {
         issuedNewParagraph = 0;
         OnMacro(ltPAR, 0, TRUE);
@@ -2102,10 +2110,10 @@ void RTFOnMacro(int macroId, int no_args, bool start)
   }
   case ltITEM:
   {
-    wxNode *node = itemizeStack.First();
+    wxNode *node = itemizeStack.GetFirst();
     if (node)
     {
-      ItemizeStruc *struc = (ItemizeStruc *)node->Data();
+      ItemizeStruc *struc = (ItemizeStruc *)node->GetData();
       if (!start)
       {
         struc->currentItem += 1;
@@ -2192,21 +2200,20 @@ void RTFOnMacro(int macroId, int no_args, bool start)
   case ltTWOCOLITEM:
   case ltTWOCOLITEMRULED:
   {
-    wxNode *node = itemizeStack.First();
+    wxNode *node = itemizeStack.GetFirst();
     if (node)
     {
-      ItemizeStruc *struc = (ItemizeStruc *)node->Data();
+      ItemizeStruc *struc = (ItemizeStruc *)node->GetData();
       if (start)
       {
         struc->currentItem += 1;
 
-        int indentSize = struc->indentation;
         int oldIndent = 0;
         wxNode *node2 = NULL;
-        if (itemizeStack.Number() > 1) // TODO: do I actually mean Nth(0) here??
-            node2 = itemizeStack.Nth(1);
+        if (itemizeStack.GetCount() > 1) // TODO: do I actually mean Nth(0) here??
+            node2 = itemizeStack.Item(1);
         if (node2)
-          oldIndent = ((ItemizeStruc *)node2->Data())->indentation;
+          oldIndent = ((ItemizeStruc *)node2->GetData())->indentation;
 
         TexOutput("\n");
         if (struc->currentItem > 1)
@@ -3338,46 +3345,60 @@ bool RTFOnArgument(int macroId, int arg_no, bool start)
           TexOutput("{\\i ");
         else
           TexOutput("}");
+
+        if (start)
+          helpRefText = GetArgChunk();
+
         return TRUE;
       }
       else if ((GetNoArgs() - arg_no) == 0) // Arg = 2, or 3 if first is optional
       {
         if (macroId != ltHELPREFN)
         {
+          char *refName = GetArgData();
+          TexRef *texRef = NULL;
+          if (refName)
+            texRef = FindReference(refName);
           if (start)
           {
-            TexOutput(" (");
-            char *refName = GetArgData();
+            if (texRef || !ignoreBadRefs)
+              TexOutput(" (");
             if (refName)
             {
-                if (useWord)
-                {
-                    char *s = GetArgData();
-                    TexOutput("p. ");
-                    TexOutput("{\\field{\\*\\fldinst  PAGEREF ");
-                    TexOutput(refName);
-                    TexOutput(" \\\\* MERGEFORMAT }{\\fldrslt ??}}");
-                }
-                else
+                if (texRef || !ignoreBadRefs)
                 {
-                  // Only print section name if we're not in Word mode,
-                  // so can't do page references
-                  TexRef *texRef = FindReference(refName);
-                  if (texRef)
+                  if (useWord)
                   {
-                    TexOutput(texRef->sectionName) ; TexOutput(" "); TexOutput(texRef->sectionNumber);
+                      TexOutput("p. ");
+                      TexOutput("{\\field{\\*\\fldinst  PAGEREF ");
+                      TexOutput(refName);
+                      TexOutput(" \\\\* MERGEFORMAT }{\\fldrslt ??}}");
                   }
                   else
                   {
-                    TexOutput("??");
-                    sprintf(buf, "Warning: unresolved reference %s.", refName);
-                    OnInform(buf);
+                    // Only print section name if we're not in Word mode,
+                    // so can't do page references
+                    if (texRef)
+                    {
+                      TexOutput(texRef->sectionName) ; TexOutput(" "); TexOutput(texRef->sectionNumber);
+                    }
+                    else
+                    {
+                      if (!ignoreBadRefs)
+                        TexOutput("??");
+                      sprintf(buf, "Warning: unresolved reference '%s'", refName);
+                      OnInform(buf);
+                    }
                   }
                 }
             }
             else TexOutput("??");
           }
-          else TexOutput(")");
+          else
+          {
+            if (texRef || !ignoreBadRefs)
+              TexOutput(")");
+          }
         }
         return FALSE;
       }
@@ -3482,6 +3503,8 @@ bool RTFOnArgument(int macroId, int arg_no, bool start)
       // Convert points to TWIPS (1 twip = 1/20th of point)
       imageWidth = (int)(20*(tok1 ? ParseUnitArgument(tok1) : 0));
       imageHeight = (int)(20*(tok2 ? ParseUnitArgument(tok2) : 0));
+      if (imageDimensions)  // glt
+          delete [] imageDimensions;
       return FALSE;
     }  
     else if (start && (arg_no == 2 ))
@@ -3556,6 +3579,8 @@ bool RTFOnArgument(int macroId, int arg_no, bool start)
           sprintf(buf, "Warning: could not find a BMP or WMF equivalent for %s.", filename);
           OnInform(buf);
         }
+        if (filename)  // glt
+            delete [] filename;
       }
       else // linear RTF
       {
@@ -3595,7 +3620,7 @@ bool RTFOnArgument(int macroId, int arg_no, bool start)
               }
               else
               {
-                sprintf(buf, "Could not read metafile %s. Perhaps it's not a placeable metafile?", f);
+                sprintf(buf, "Could not read metafile %s. Perhaps it's not a placeable metafile?", (const char*)f);
                 OnError(buf);
               }
               fclose(fd);
@@ -4662,9 +4687,9 @@ bool RTFOnArgument(int macroId, int arg_no, bool start)
 //      indentLevel ++;
 //      TexOutput("\\fi0\n");
       int oldIndent = 0;
-      wxNode *node = itemizeStack.First();
+      wxNode *node = itemizeStack.GetFirst();
       if (node)
-        oldIndent = ((ItemizeStruc *)node->Data())->indentation;
+        oldIndent = ((ItemizeStruc *)node->GetData())->indentation;
 
       int indentValue = 20*ParseUnitArgument(GetArgData());
       int indentSize = indentValue + oldIndent;
@@ -4680,13 +4705,13 @@ bool RTFOnArgument(int macroId, int arg_no, bool start)
     if (!start && (arg_no == 2))
     {
       PopEnvironmentStyle();
-      if (itemizeStack.First())
+      if (itemizeStack.GetFirst())
       {
-        ItemizeStruc *struc = (ItemizeStruc *)itemizeStack.First()->Data();
+        ItemizeStruc *struc = (ItemizeStruc *)itemizeStack.GetFirst()->GetData();
         delete struc;
-        delete itemizeStack.First();
+        delete itemizeStack.GetFirst();
       }
-      if (itemizeStack.Number() == 0)
+      if (itemizeStack.GetCount() == 0)
       {
         TexOutput("\\par\\pard\n");
         issuedNewParagraph = 1;
@@ -4703,9 +4728,9 @@ bool RTFOnArgument(int macroId, int arg_no, bool start)
     if (start && (arg_no == 1))
     {
       int oldIndent = 0;
-      wxNode *node = itemizeStack.First();
+      wxNode *node = itemizeStack.GetFirst();
       if (node)
-        oldIndent = ((ItemizeStruc *)node->Data())->indentation;
+        oldIndent = ((ItemizeStruc *)node->GetData())->indentation;
 
       int boxWidth = 20*ParseUnitArgument(GetArgData());
 
@@ -4725,11 +4750,11 @@ bool RTFOnArgument(int macroId, int arg_no, bool start)
     if (!start && (arg_no == 2))
     {
       PopEnvironmentStyle();
-      if (itemizeStack.First())
+      if (itemizeStack.GetFirst())
       {
-        ItemizeStruc *struc = (ItemizeStruc *)itemizeStack.First()->Data();
+        ItemizeStruc *struc = (ItemizeStruc *)itemizeStack.GetFirst()->GetData();
         delete struc;
-        delete itemizeStack.First();
+        delete itemizeStack.GetFirst();
       }
       if (itemizeStack.Number() == 0)
       {
@@ -4874,7 +4899,7 @@ bool RTFOnArgument(int macroId, int arg_no, bool start)
         if (useUpButton)
         {
           fprintf(Chapters, "!{\\footnote EnableButton(\"Up\");ChangeButtonBinding(\"Up\", \"JumpId(`%s.hlp', `%s')\")}\n",
-               FileNameFromPath(FileRoot), "Contents");
+               wxFileNameFromPath(FileRoot), "Contents");
         }
       }
       
@@ -5081,6 +5106,9 @@ bool RTFOnArgument(int macroId, int arg_no, bool start)
 
 bool RTFGo(void)
 {
+  if (stopRunning)
+      return FALSE;
+
   // Reset variables
   indentLevel = 0;
   forbidParindent = 0;
@@ -5155,6 +5183,9 @@ bool RTFGo(void)
 
     SetCurrentOutput(Chapters);
 
+    if (stopRunning)
+        return FALSE;
+
     OnInform("Converting...");
 
     TraverseDocument();
@@ -5218,15 +5249,20 @@ bool RTFGo(void)
     {
       wxConcatFiles("header.rtf", "chapters.rtf", "tmp1.rtf");
       Tex2RTFYield(TRUE);
-      if (FileExists(OutputFile)) wxRemoveFile(OutputFile);
-      wxString cwdStr, outputDirStr;
+      if (wxFileExists(OutputFile))
+          wxRemoveFile(OutputFile);
+
+      char *cwdStr;
       cwdStr = wxGetWorkingDirectory();
+
+      wxString outputDirStr;
       outputDirStr = wxPathOnly(OutputFile);
+
       // Determine if the temp file and the output file are in the same directory,
       // and if they are, then just rename the temp file rather than copying
       // it, as this is much faster when working with large (multi-megabyte files)
-      if ((wxStrcmp(wxPathOnly(OutputFile),"") == 0) ||  // no path specified on output file
-          (wxStrcmp(wxGetWorkingDirectory(),wxPathOnly(OutputFile)) == 0)) // paths do not match
+      if ((wxStrcmp(outputDirStr.c_str(),"") == 0) ||  // no path specified on output file
+          (wxStrcmp(cwdStr,outputDirStr.c_str()) == 0)) // paths do not match
       {
         wxRenameFile("tmp1.rtf", OutputFile);
       }
@@ -5234,11 +5270,12 @@ bool RTFGo(void)
       {
         wxCopyFile("tmp1.rtf", OutputFile);
       }
+      delete [] cwdStr;
       Tex2RTFYield(TRUE);
       wxRemoveFile("tmp1.rtf");
     }
     
-    if (FileExists(ContentsName)) wxRemoveFile(ContentsName);
+    if (wxFileExists(ContentsName)) wxRemoveFile(ContentsName);
 
     if (!wxRenameFile(TmpContentsName, ContentsName))
     {