+ PopEnvironmentStyle();
+
+ Tex2RTFYield(true);
+ if (winHelp)
+ {
+// wxFprintf(Contents, _T("\\page\n"));
+ wxFprintf(Chapters, _T("\\page\n"));
+ wxFprintf(Sections, _T("\\page\n"));
+ wxFprintf(Subsections, _T("\\page\n"));
+ wxFprintf(Subsubsections, _T("\\page\n\n"));
+ wxFprintf(Popups, _T("\\page\n}\n"));
+ }
+
+// TexOutput(_T("\n\\info{\\doccomm Document created by Julian Smart's Tex2RTF.}\n"));
+ if (!winHelp)
+ TexOutput(_T("}\n"));
+ fclose(Contents); Contents = NULL;
+ fclose(Chapters); Chapters = NULL;
+ if (winHelp)
+ {
+ fclose(Sections); Sections = NULL;
+ fclose(Subsections); Subsections = NULL;
+ fclose(Subsubsections); Subsubsections = NULL;
+ fclose(Popups); Popups = NULL;
+ if (winHelpContents)
+ {
+ fclose(WinHelpContentsFile); WinHelpContentsFile = NULL;
+ }
+ }
+
+ if (winHelp)
+ {
+ wxConcatFiles(_T("header.rtf"), _T("chapters.rtf"), _T("tmp1.rtf"));
+ Tex2RTFYield(true);
+ wxConcatFiles(_T("tmp1.rtf"), _T("sections.rtf"), _T("tmp2.rtf"));
+ Tex2RTFYield(true);
+ wxConcatFiles(_T("tmp2.rtf"), _T("subsections.rtf"), _T("tmp3.rtf"));
+ Tex2RTFYield(true);
+ wxConcatFiles(_T("tmp3.rtf"), _T("subsubsections.rtf"), _T("tmp4.rtf"));
+ Tex2RTFYield(true);
+ wxConcatFiles(_T("tmp4.rtf"), _T("popups.rtf"), OutputFile);
+ Tex2RTFYield(true);
+
+ wxRemoveFile(_T("tmp1.rtf"));
+ wxRemoveFile(_T("tmp2.rtf"));
+ wxRemoveFile(_T("tmp3.rtf"));
+ wxRemoveFile(_T("tmp4.rtf"));
+ }
+ else
+ {
+ wxConcatFiles(_T("header.rtf"), _T("chapters.rtf"), _T("tmp1.rtf"));
+ Tex2RTFYield(true);
+ if (wxFileExists(OutputFile))
+ wxRemoveFile(OutputFile);
+
+ wxString cwdStr = wxGetCwd();
+
+ wxString 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 ((outputDirStr.empty()) || // no path specified on output file
+ (cwdStr != outputDirStr)) // paths do not match
+ {
+ wxRenameFile(_T("tmp1.rtf"), OutputFile);
+ }
+ else
+ {
+ wxCopyFile(_T("tmp1.rtf"), OutputFile);
+ }
+ Tex2RTFYield(true);
+ wxRemoveFile(_T("tmp1.rtf"));
+ }
+
+ if (wxFileExists(ContentsName)) wxRemoveFile(ContentsName);
+
+ if (!wxRenameFile(TmpContentsName, ContentsName))
+ {
+ wxCopyFile(TmpContentsName, ContentsName);
+ wxRemoveFile(TmpContentsName);
+ }
+
+ wxRemoveFile(_T("chapters.rtf"));
+ wxRemoveFile(_T("header.rtf"));
+
+ if (winHelp)
+ {
+ wxRemoveFile(_T("sections.rtf"));
+ wxRemoveFile(_T("subsections.rtf"));
+ wxRemoveFile(_T("subsubsections.rtf"));
+ wxRemoveFile(_T("popups.rtf"));
+ }
+ if (winHelp && generateHPJ)
+ WriteHPJ(OutputFile);
+ return true;