X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/6c155d33875eb3641bf845fbac186c1b5470708e..173f3c03a059a269a237aab72c6b067020a41b8c:/utils/tex2rtf/src/rtfutils.cpp diff --git a/utils/tex2rtf/src/rtfutils.cpp b/utils/tex2rtf/src/rtfutils.cpp index 974e5d5d86..5f59fea4e3 100644 --- a/utils/tex2rtf/src/rtfutils.cpp +++ b/utils/tex2rtf/src/rtfutils.cpp @@ -2,17 +2,14 @@ // Name: rtfutils.cpp // Purpose: Converts Latex to Word RTF/WinHelp RTF // Author: Julian Smart -// Modified by: +// Modified by: Wlodzimiez ABX Skiba 2003/2004 Unicode support +// Ron Lee // Created: 7.9.93 // RCS-ID: $Id$ // Copyright: (c) Julian Smart // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// -#ifdef __GNUG__ -#pragma implementation -#endif - // For compilers that support precompilation, includes "wx.h". #include "wx/wxprec.h" @@ -36,10 +33,8 @@ #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; @@ -65,17 +60,17 @@ extern wxChar *BigBuffer; extern wxHashTable TexReferences; // Are we in verbatim mode? If so, format differently. -static bool inVerbatim = FALSE; +static bool inVerbatim = false; // We're in a series of PopRef topics, so don't output section headings -bool inPopRefSection = FALSE; +bool inPopRefSection = false; // Green colour? -static bool hotSpotColour = TRUE; -static bool hotSpotUnderline = TRUE; +static bool hotSpotColour = true; +static bool hotSpotUnderline = true; // Transparency (WHITE = transparent) -static bool bitmapTransparency = TRUE; +static bool bitmapTransparency = true; // Linear RTF requires us to set the style per section. static wxChar *currentNumberStyle = NULL; @@ -109,8 +104,8 @@ int issuedNewParagraph = 0; // Need to know whether we're in a table or figure for benefit // of listoffigures/listoftables -static bool inFigure = FALSE; -static bool inTable = FALSE; +static bool inFigure = false; +static bool inTable = false; /* * Current topics @@ -124,10 +119,10 @@ static wxChar *CurrentTopic = NULL; static bool InPopups() { if (CurrentChapterName && (wxStrcmp(CurrentChapterName, _T("popups")) == 0)) - return TRUE; + return true; if (CurrentSectionName && (wxStrcmp(CurrentSectionName, _T("popups")) == 0)) - return TRUE; - return FALSE; + return true; + return false; } static void SetCurrentTopic(wxChar *s) @@ -190,7 +185,7 @@ void NotifyParentHasChildren(int parentLevel) texTopic = new TexTopic; TopicTable.Put(parentTopic, texTopic); } - texTopic->hasChildren = TRUE; + texTopic->hasChildren = true; } } @@ -206,10 +201,10 @@ void ResetContentsLevels(int l) { int i; for (i = l; i < 5; i++) - ContentsLevels[i] = FALSE; - + ContentsLevels[i] = false; + // There are always books on the top level - ContentsLevels[0] = TRUE; + ContentsLevels[0] = true; } // Output a WinHelp section as a keyword, substituting @@ -217,7 +212,7 @@ void ResetContentsLevels(int l) void OutputSectionKeyword(FILE *fd) { OutputCurrentSectionToString(wxTex2RTFBuffer); - + unsigned int i; for (i = 0; i < wxStrlen(wxTex2RTFBuffer); i++) if (wxTex2RTFBuffer[i] == ':') @@ -228,7 +223,7 @@ void OutputSectionKeyword(FILE *fd) wxFprintf(fd, _T("K{\\footnote {K} ")); wxFprintf(fd, _T("%s"), wxTex2RTFBuffer); - + wxFprintf(fd, _T("}\n")); } @@ -239,24 +234,25 @@ void WriteWinHelpContentsFileLine(wxChar *topicName, wxChar *xitle, int level) wxChar title[255]; int s=0; int d=0; + // assuming iso-8859-1 here even in Unicode build (FIXME?) while ( (xitle[s]!=0)&&(d<255) ) { - wxChar ch=xitle[s]&0xff; - if (ch==0x5c) { - wxChar ch1=xitle[s+1]&0xff; - wxChar ch2=xitle[s+2]&0xff; - wxChar ch3=xitle[s+3]&0xff; - s+=4; // next character - if ((ch1==0x27)&&(ch2==0x66)&&(ch3==0x36)) { title[d++]='ö'; } - if ((ch1==0x27)&&(ch2==0x65)&&(ch3==0x34)) { title[d++]='ä'; } - if ((ch1==0x27)&&(ch2==0x66)&&(ch3==0x63)) { title[d++]='ü'; } - if ((ch1==0x27)&&(ch2==0x64)&&(ch3==0x36)) { title[d++]='Ö'; } - if ((ch1==0x27)&&(ch2==0x63)&&(ch3==0x34)) { title[d++]='Ä'; } - if ((ch1==0x27)&&(ch2==0x64)&&(ch3==0x63)) { title[d++]='Ü'; } - } else { - title[d++]=ch; - s++; - } + wxChar ch=wxChar(xitle[s]&0xff); + if (ch==0x5c) { + wxChar ch1=wxChar(xitle[s+1]&0xff); + wxChar ch2=wxChar(xitle[s+2]&0xff); + wxChar ch3=wxChar(xitle[s+3]&0xff); + s+=4; // next character + if ((ch1==0x27)&&(ch2==0x66)&&(ch3==0x36)) { title[d++]=wxChar('ö'); } + if ((ch1==0x27)&&(ch2==0x65)&&(ch3==0x34)) { title[d++]=wxChar('ä'); } + if ((ch1==0x27)&&(ch2==0x66)&&(ch3==0x63)) { title[d++]=wxChar('ü'); } + if ((ch1==0x27)&&(ch2==0x64)&&(ch3==0x36)) { title[d++]=wxChar('Ö'); } + if ((ch1==0x27)&&(ch2==0x63)&&(ch3==0x34)) { title[d++]=wxChar('Ä'); } + if ((ch1==0x27)&&(ch2==0x64)&&(ch3==0x63)) { title[d++]=wxChar('Ü'); } + } else { + title[d++]=ch; + s++; + } } title[d]=0; @@ -266,12 +262,9 @@ void WriteWinHelpContentsFileLine(wxChar *topicName, wxChar *xitle, int level) if (level == 0) // Means we had a Chapter in an article, oops. return; - + ResetContentsLevels(level); - - if (!title) - return; - + if (winHelp && winHelpContents && WinHelpContentsFile) { TexTopic *texTopic = (TexTopic *)TopicTable.Get(topicName); @@ -292,7 +285,7 @@ void WriteWinHelpContentsFileLine(wxChar *topicName, wxChar *xitle, int level) // Remember that at this level, we had a book and *must* for the // remainder of sections at this level. - ContentsLevels[level-1] = TRUE; + ContentsLevels[level-1] = true; } else { @@ -306,7 +299,7 @@ void WriteWinHelpContentsFileLine(wxChar *topicName, wxChar *xitle, int level) // Always have a book at level 1 wxFprintf(WinHelpContentsFile, _T("%d %s\n"), level, title); wxFprintf(WinHelpContentsFile, _T("%d %s=%s\n"), level+1, title, topicName); - ContentsLevels[level-1] = TRUE; + ContentsLevels[level-1] = true; } else // Probably doesn't have children if it hasn't been added to the topic table @@ -351,7 +344,7 @@ void GenerateKeywordsForTopic(wxChar *topic) // Must separate out main entry form subentry (only 1 subentry allowed) wxChar buf1[100]; wxChar buf2[100]; SplitIndexEntry(s, buf1, buf2); - + // Check for ':' which messes up index unsigned int i; for (i = 0; i < wxStrlen(buf1) ; i++) @@ -381,7 +374,7 @@ void GenerateKeywordsForTopic(wxChar *topic) * Output index entry in linear RTF * */ - + void GenerateIndexEntry(wxChar *entry) { if (useWord) @@ -404,7 +397,7 @@ void GenerateIndexEntry(wxChar *entry) * Write a suitable RTF header. * */ - + void WriteColourTable(FILE *fd) { wxFprintf(fd, _T("{\\colortbl")); @@ -429,22 +422,22 @@ void WriteHeadingStyle(FILE *fd, int heading) { case 1: { - wxFprintf(fd, _T("\\b\\fs%d"), chapterFont*2); + wxFprintf(fd, _T("\\sb300\\sa260\\f2\\b\\fs%d"), chapterFont*2); break; } case 2: { - wxFprintf(fd, _T("\\b\\fs%d"), sectionFont*2); + wxFprintf(fd, _T("\\sb200\\sa240\\f2\\b\\fs%d"), sectionFont*2); break; } case 3: { - wxFprintf(fd, _T("\\b\\fs%d"), subsectionFont*2); + wxFprintf(fd, _T("\\sb120\\sa240\\f2\\b\\fs%d"), subsectionFont*2); break; } case 4: { - wxFprintf(fd, _T("\\b\\fs%d"), subsectionFont*2); + wxFprintf(fd, _T("\\sb120\\sa240\\f2\\b\\fs%d"), subsectionFont*2); break; } default: @@ -456,19 +449,24 @@ void WriteRTFHeader(FILE *fd) { wxFprintf(fd, _T("{\\rtf1\\%s \\deff0\n"), RTFCharset); wxFprintf(fd, _T("{\\fonttbl{\\f0\\froman Times New Roman;}{\\f1\\ftech Symbol;}{\\f2\\fswiss Arial;}\n")); - wxFprintf(fd, _T("{\\f3\\fmodern Courier;}{\\f4\\ftech Wingdings;}{\\f5\\ftech Monotype Sorts;}\n}")); + wxFprintf(fd, _T("{\\f3\\fmodern Courier New;}{\\f4\\ftech Wingdings;}{\\f5\\ftech Monotype Sorts;}\n}")); /* * Style sheet */ - wxFprintf(fd, _T("{\\stylesheet{\\f2\\fs20 \\snext0 Normal;}\n")); + wxFprintf(fd, _T("{\\stylesheet{\\f2\\fs22\\sa200 \\snext0 Normal;}\n")); // Headings wxFprintf(fd, _T("{\\s1 ")); WriteHeadingStyle(fd, 1); wxFprintf(fd, _T("\\sbasedon0\\snext0 heading 1;}\n")); wxFprintf(fd, _T("{\\s2 ")); WriteHeadingStyle(fd, 2); wxFprintf(fd, _T("\\sbasedon0\\snext0 heading 2;}\n")); wxFprintf(fd, _T("{\\s3 ")); WriteHeadingStyle(fd, 3); wxFprintf(fd, _T("\\sbasedon0\\snext0 heading 3;}\n")); wxFprintf(fd, _T("{\\s4 ")); WriteHeadingStyle(fd, 4); wxFprintf(fd, _T("\\sbasedon0\\snext0 heading 4;}\n")); + + // Code style + wxFprintf(fd, _T("{\\s10\\ql \\li720\\ri0\\nowidctlpar\\faauto\\rin0\\lin720\\itap0 \\cbpat17\ +\\f2\\fs20 \\sbasedon0 \\snext24 Code;}\n")); + // Table of contents styles wxFprintf(fd, _T("{\\s20\\sb300\\tqr\\tldot\\tx8640 \\b\\f2 \\sbasedon0\\snext0 toc 1;}\n")); - + wxFprintf(fd, _T("{\\s21\\sb90\\tqr\\tldot\\li400\\tqr\\tx8640 \\f2\\fs20\\sbasedon0\\snext0 toc 2;}\n")); wxFprintf(fd, _T("{\\s22\\sb90\\tqr\\tldot\\li800\\tx8640 \\f2\\fs20 \\sbasedon0\\snext0 toc 3;}\n")); wxFprintf(fd, _T("{\\s23\\sb90\\tqr\\tldot\\li1200\\tx8640 \\f2\\fs20 \\sbasedon0\\snext0 toc 4;}\n")); @@ -516,66 +514,66 @@ void OutputNumberStyle(wxChar *numberStyle) /* * Write a Windows help project file */ - -bool WriteHPJ(wxChar *filename) -{ - wxChar hpjFilename[256]; - wxChar helpFile[50]; - wxChar rtfFile[50]; - wxStrcpy(hpjFilename, filename); - StripExtension(hpjFilename); - wxStrcat(hpjFilename, _T(".hpj")); - - wxStrcpy(helpFile, wxFileNameFromPath(filename)); - StripExtension(helpFile); - wxStrcpy(rtfFile, helpFile); - wxStrcat(helpFile, _T(".hlp")); - wxStrcat(rtfFile, _T(".rtf")); - - FILE *fd = wxFopen(hpjFilename, _T("w")); - if (!fd) - return FALSE; - - wxChar *helpTitle = winHelpTitle; - if (!helpTitle) - helpTitle = _T("Untitled"); - - wxString thePath = wxPathOnly(InputFile); - if (thePath.IsEmpty()) - thePath = _T("."); - wxFprintf(fd, _T("[OPTIONS]\n")); - wxFprintf(fd, _T("BMROOT=%s ; Assume that bitmaps are where the source is\n"), thePath.c_str()); - wxFprintf(fd, _T("TITLE=%s\n"), helpTitle); - wxFprintf(fd, _T("CONTENTS=Contents\n")); - - if (winHelpVersion > 3) - { - wxFprintf(fd, _T("; COMPRESS=12 Hall Zeck ; Max compression, but needs lots of memory\n")); - wxFprintf(fd, _T("COMPRESS=8 Zeck\n")); - wxFprintf(fd, _T("LCID=0x809 0x0 0x0 ;English (British)\n")); - wxFprintf(fd, _T("HLP=.\\%s.hlp\n"), wxFileNameFromPath(FileRoot)); - } - else - { - wxFprintf(fd, _T("COMPRESS=HIGH\n")); - } - wxFprintf(fd, _T("\n")); - if (winHelpVersion > 3) - { - wxFprintf(fd, _T("[WINDOWS]\n")); - wxFprintf(fd, _T("Main=\"\",(553,102,400,600),20736,(r14876671),(r12632256),f3\n")); +bool WriteHPJ(const wxString& filename) +{ + wxChar hpjFilename[256]; + wxChar helpFile[50]; + wxChar rtfFile[50]; + wxStrcpy(hpjFilename, filename); + StripExtension(hpjFilename); + wxStrcat(hpjFilename, _T(".hpj")); + + wxStrcpy(helpFile, wxFileNameFromPath(filename)); + StripExtension(helpFile); + wxStrcpy(rtfFile, helpFile); + wxStrcat(helpFile, _T(".hlp")); + wxStrcat(rtfFile, _T(".rtf")); + + FILE *fd = wxFopen(hpjFilename, _T("w")); + if (!fd) + return false; + + wxChar *helpTitle = winHelpTitle; + if (!helpTitle) + helpTitle = _T("Untitled"); + + wxString thePath = wxPathOnly(InputFile); + if (thePath.empty()) + thePath = _T("."); + wxFprintf(fd, _T("[OPTIONS]\n")); + wxFprintf(fd, _T("BMROOT=%s ; Assume that bitmaps are where the source is\n"), thePath.c_str()); + wxFprintf(fd, _T("TITLE=%s\n"), helpTitle); + wxFprintf(fd, _T("CONTENTS=Contents\n")); + + if (winHelpVersion > 3) + { + wxFprintf(fd, _T("; COMPRESS=12 Hall Zeck ; Max compression, but needs lots of memory\n")); + wxFprintf(fd, _T("COMPRESS=8 Zeck\n")); + wxFprintf(fd, _T("LCID=0x809 0x0 0x0 ;English (British)\n")); + wxFprintf(fd, _T("HLP=.\\%s.hlp\n"), wxFileNameFromPath(FileRoot)); + } + else + { + wxFprintf(fd, _T("COMPRESS=HIGH\n")); + } wxFprintf(fd, _T("\n")); - } - wxFprintf(fd, _T("[FILES]\n%s\n\n"), rtfFile); - wxFprintf(fd, _T("[CONFIG]\n")); - if (useUpButton) - wxFprintf(fd, _T("CreateButton(\"Up\", \"&Up\", \"JumpId(`%s', `Contents')\")\n"), helpFile); - wxFprintf(fd, _T("BrowseButtons()\n\n")); - wxFprintf(fd, _T("[MAP]\n\n[BITMAPS]\n\n")); - fclose(fd); - return TRUE; + if (winHelpVersion > 3) + { + wxFprintf(fd, _T("[WINDOWS]\n")); + wxFprintf(fd, _T("Main=\"\",(553,102,400,600),20736,(r14876671),(r12632256),f3\n")); + wxFprintf(fd, _T("\n")); + } + + wxFprintf(fd, _T("[FILES]\n%s\n\n"), rtfFile); + wxFprintf(fd, _T("[CONFIG]\n")); + if (useUpButton) + wxFprintf(fd, _T("CreateButton(\"Up\", \"&Up\", \"JumpId(`%s', `Contents')\")\n"), helpFile); + wxFprintf(fd, _T("BrowseButtons()\n\n")); + wxFprintf(fd, _T("[MAP]\n\n[BITMAPS]\n\n")); + fclose(fd); + return true; } @@ -589,7 +587,7 @@ bool WriteHPJ(wxChar *filename) void ProcessText2RTF(TexChunk *chunk) { - bool changed = FALSE; + bool changed = false; int ptr = 0; int i = 0; wxChar ch = 1; @@ -603,8 +601,9 @@ void ProcessText2RTF(TexChunk *chunk) if (inVerbatim) { BigBuffer[ptr] = 0; wxStrcat(BigBuffer, _T("\\par\n")); ptr += 5; +// BigBuffer[ptr] = 0; wxStrcat(BigBuffer, _T("\\par{\\v this was verbatim}\n")); ptr += 5; i ++; - changed = TRUE; + changed = true; } else { @@ -620,7 +619,7 @@ void ProcessText2RTF(TexChunk *chunk) ((len > i+1 && chunk->value[i+1] == 13) && (len > i+2 && isascii(chunk->value[i+2]) && !isspace(chunk->value[i+2])))) -// if (TRUE) +// if (true) { // DOS files have a 13 after the 10 BigBuffer[ptr] = 10; @@ -638,7 +637,7 @@ void ProcessText2RTF(TexChunk *chunk) // Note that the actual ASCII character seen is dealt with in the next // iteration - changed = TRUE; + changed = true; } else { @@ -651,27 +650,27 @@ void ProcessText2RTF(TexChunk *chunk) { BigBuffer[ptr] = '"'; ptr ++; i += 2; - changed = TRUE; + changed = true; } else if (!inVerbatim && ch == '`') // Change ` to ' { BigBuffer[ptr] = 39; ptr ++; i += 1; - changed = TRUE; + changed = true; } else if (inVerbatim && ch == '\\') // Change backslash to two backslashes { BigBuffer[ptr] = '\\'; ptr ++; BigBuffer[ptr] = '\\'; ptr ++; i += 1; - changed = TRUE; + changed = true; } - else if (inVerbatim && (ch == '{' || ch == '}')) // Escape the curley bracket + else if (inVerbatim && (ch == '{' || ch == '}')) // Escape the curly bracket { BigBuffer[ptr] = '\\'; ptr ++; BigBuffer[ptr] = ch; ptr ++; i += 1; - changed = TRUE; + changed = true; } else { @@ -696,7 +695,7 @@ void ProcessText2RTF(TexChunk *chunk) * and before TraverseDocument is called. * */ - + void Text2RTF(TexChunk *chunk) { Tex2RTFYield(); @@ -711,7 +710,7 @@ void Text2RTF(TexChunk *chunk) return; if (def && (def->macroId == ltVERBATIM || def->macroId == ltVERB)) - inVerbatim = TRUE; + inVerbatim = true; wxNode *node = chunk->children.GetFirst(); while (node) @@ -722,7 +721,7 @@ void Text2RTF(TexChunk *chunk) } if (def && (def->macroId == ltVERBATIM || def->macroId == ltVERB)) - inVerbatim = FALSE; + inVerbatim = false; break; } @@ -751,14 +750,14 @@ void Text2RTF(TexChunk *chunk) * Not used yet * */ - + wxChar browseBuf[10]; static long browseId = 0; wxChar *GetBrowseString(void) { wxChar buf[10]; browseId ++; - wxSprintf(buf, _T("%ld"), browseId); + wxSnprintf(buf, sizeof(buf), _T("%ld"), browseId); int noZeroes = 5-wxStrlen(buf); wxStrcpy(browseBuf, _T("browse")); for (int i = 0; i < noZeroes; i++) @@ -802,7 +801,7 @@ void WriteEnvironmentStyles(void) if (!inTabular && (ParIndent > 0) && (forbidParindent == 0)) { wxChar buf[15]; - wxSprintf(buf, _T("\\fi%d"), ParIndent*20); // Convert points to TWIPS + wxSnprintf(buf, sizeof(buf), _T("\\fi%d"), ParIndent*20); // Convert points to TWIPS TexOutput(buf); } if (environmentStack.GetCount() > 0 || (ParIndent > 0)) @@ -837,12 +836,12 @@ void OutputRTFHeaderCommands(void) TexOutput(_T("{\\i \\qr ")); if (DocumentStyle == LATEX_ARTICLE) { - wxSprintf(buf, _T("SECTION %d"), sectionNo); + wxSnprintf(buf, sizeof(buf), _T("SECTION %d"), sectionNo); TexOutput(buf); } else { - wxSprintf(buf, _T("CHAPTER %d: "), chapterNo); + wxSnprintf(buf, sizeof(buf), _T("CHAPTER %d: "), chapterNo); TexOutput(buf); } TexOutput(_T("{\\field{\\*\\fldinst PAGE \\\\* MERGEFORMAT }{\\fldrslt 1}}")); @@ -857,12 +856,12 @@ void OutputRTFHeaderCommands(void) TexOutput(_T("{\\i \\qc ")); if (DocumentStyle == LATEX_ARTICLE) { - wxSprintf(buf, _T("SECTION %d"), sectionNo); + wxSnprintf(buf, sizeof(buf), _T("SECTION %d"), sectionNo); TexOutput(buf); } else { - wxSprintf(buf, _T("CHAPTER %d"), chapterNo); + wxSnprintf(buf, sizeof(buf), _T("CHAPTER %d"), chapterNo); TexOutput(buf); } TexOutput(_T("{\\field{\\*\\fldinst PAGE \\\\* MERGEFORMAT }{\\fldrslt 1}}")); @@ -872,7 +871,7 @@ void OutputRTFHeaderCommands(void) { int oldForbidResetPar = forbidResetPar; forbidResetPar = 0; - + if (LeftHeaderEven || CentreHeaderEven || RightHeaderEven) { TexOutput(_T("{\\headerl\\fi0 ")); @@ -1069,7 +1068,7 @@ void RTFOnMacro(int macroId, int no_args, bool start) { /* wxChar tmpBuf[40]; - wxSprintf(tmpBuf, _T("%d (%d)"), macroId, (int)start); + wxSnprintf(tmpBuf, sizeof(tmpBuf), _T("%d (%d)"), macroId, (int)start); OutputDebugString("RTFOnMacro Start "); OutputDebugString(tmpBuf); OutputDebugString("\n"); wxYield(); */ @@ -1140,7 +1139,7 @@ void RTFOnMacro(int macroId, int no_args, bool start) OutputRTFHeaderCommands(); OutputRTFFooterCommands(); } - + // Need to reset the current numbering style, or RTF forgets it. SetCurrentOutput(Chapters); OutputNumberStyle(currentNumberStyle); @@ -1161,28 +1160,31 @@ void RTFOnMacro(int macroId, int no_args, bool start) else SetCurrentOutput(NULL); // No entry in table of contents } } - - startedSections = TRUE; + + startedSections = true; // Output heading to contents page if (!InPopups()) { OutputCurrentSection(); - + if (winHelp) - wxFprintf(Contents, _T("}{\\v %s}\\par\\pard\n"), topicName); + { + wxFprintf(Contents, _T("}{\\v %s}\\pard\\par\n"), topicName); + //WriteEnvironmentStyles(); + } else if ((macroId == ltCHAPTER) || (macroId == ltCHAPTERHEADING)) wxFprintf(Contents, _T("}\\par\\par\\pard\n")); // From here, just output to chapter SetCurrentOutput(Chapters); } - + if (winHelp) { wxFprintf(Chapters, _T("}\n#{\\footnote %s}\n"), topicName); wxFprintf(Chapters, _T("+{\\footnote %s}\n"), GetBrowseString()); - + OutputSectionKeyword(Chapters); GenerateKeywordsForTopic(topicName); @@ -1221,9 +1223,10 @@ void RTFOnMacro(int macroId, int no_args, bool start) } } OutputCurrentSection(); - TexOutput(_T("\\par\\pard}\\par\n")); + TexOutput(_T("\\par\\pard}\n")); } - issuedNewParagraph = 2; + issuedNewParagraph = 1; + WriteEnvironmentStyles(); } break; } @@ -1307,14 +1310,14 @@ void RTFOnMacro(int macroId, int no_args, bool start) } } else SetCurrentOutput(NULL); - } + } if (startedSections) { if (winHelp) wxFprintf(Sections, _T("\\page\n")); } - startedSections = TRUE; + startedSections = true; if (winHelp) wxFprintf(Sections, _T("\n${\\footnote ")); @@ -1326,7 +1329,10 @@ void RTFOnMacro(int macroId, int no_args, bool start) if (winHelp) { if (!InPopups()) - wxFprintf(jumpFrom, _T("}{\\v %s}\\par\\pard\n"), topicName); + { + wxFprintf(jumpFrom, _T("}{\\v %s}\\pard\\par\n"), topicName); + //WriteEnvironmentStyles(); + } } else if ((macroId != ltSECTIONSTAR) && (macroId != ltGLOSS)) { @@ -1335,7 +1341,7 @@ void RTFOnMacro(int macroId, int no_args, bool start) else wxFprintf(Contents, _T("}\\par\\par\\pard\n")); } - + SetCurrentOutput(winHelp ? Sections : Chapters); if (winHelp) @@ -1372,7 +1378,7 @@ void RTFOnMacro(int macroId, int no_args, bool start) wxChar *keep = _T(""); if (winHelp && (macroId != ltGLOSS) && !InPopups()) keep = _T("\\keepn\\sa140\\sb140"); - + wxFprintf(winHelp ? Sections : Chapters, _T("\\pard{%s%s"), keep, styleCommand); @@ -1409,9 +1415,12 @@ void RTFOnMacro(int macroId, int no_args, bool start) } } OutputCurrentSection(); - TexOutput(_T("\\par\\pard}\\par\n")); + TexOutput(_T("\\par\\pard}\n")); +// TexOutput(_T("\\par\\pard}\\par\n")); } - issuedNewParagraph = 2; + issuedNewParagraph = 1; + WriteEnvironmentStyles(); +// issuedNewParagraph = 2; } break; } @@ -1469,10 +1478,13 @@ void RTFOnMacro(int macroId, int no_args, bool start) if (!InPopups()) wxFprintf(Subsections, _T("\\page\n")); } + // Experimental JACS 2004-02-21 +#if 0 else wxFprintf(Chapters, _T("\\par\n")); +#endif } - startedSections = TRUE; + startedSections = true; if (winHelp) wxFprintf(Subsections, _T("\n${\\footnote ")); @@ -1484,7 +1496,10 @@ void RTFOnMacro(int macroId, int no_args, bool start) if (winHelp) { if (!InPopups()) - wxFprintf(Sections, _T("}{\\v %s}\\par\\pard\n"), topicName); + { + wxFprintf(Sections, _T("}{\\v %s}\\pard\\par\n"), topicName); + //WriteEnvironmentStyles(); + } } else if ((macroId != ltSUBSECTIONSTAR) && (macroId != ltMEMBERSECTION) && (macroId != ltFUNCTIONSECTION)) @@ -1562,9 +1577,13 @@ void RTFOnMacro(int macroId, int no_args, bool start) } } OutputCurrentSection(); // Repeat section header - TexOutput(_T("\\par\\pard}\\par\n")); + + // Experimental JACS + TexOutput(_T("\\par\\pard}\n")); + // TexOutput(_T("\\par\\pard}\\par\n")); } - issuedNewParagraph = 2; + issuedNewParagraph = 1; + WriteEnvironmentStyles(); } } break; @@ -1610,20 +1629,23 @@ void RTFOnMacro(int macroId, int no_args, bool start) } else SetCurrentOutput(NULL); // Don't write it into the contents, or anywhere else - } + } else SetCurrentOutput(NULL); // Don't write it into the contents, or anywhere else } - + if (startedSections) { if (winHelp) wxFprintf(Subsubsections, _T("\\page\n")); + // Experimental JACS 2004-02-21 +#if 0 else wxFprintf(Chapters, _T("\\par\n")); +#endif } - startedSections = TRUE; + startedSections = true; if (winHelp) wxFprintf(Subsubsections, _T("\n${\\footnote ")); @@ -1632,10 +1654,13 @@ void RTFOnMacro(int macroId, int no_args, bool start) OutputCurrentSection(); if (winHelp) - wxFprintf(Subsections, _T("}{\\v %s}\\par\\pard\n"), topicName); + { + wxFprintf(Subsections, _T("}{\\v %s}\\pard\\par\n"), topicName); + //WriteEnvironmentStyles(); + } else if ((DocumentStyle == LATEX_ARTICLE) && (macroId != ltSUBSUBSECTIONSTAR)) wxFprintf(Contents, _T("\\par\\pard\n")); - + SetCurrentOutput(winHelp ? Subsubsections : Chapters); if (winHelp) { @@ -1675,7 +1700,7 @@ void RTFOnMacro(int macroId, int no_args, bool start) WriteHeadingStyle((winHelp ? Subsubsections : Chapters), (DocumentStyle == LATEX_ARTICLE ? 3 : 4)); wxFprintf(winHelp ? Subsubsections : Chapters, _T(" ")); - + if (!winHelp) { if ((macroId != ltSUBSUBSECTIONSTAR)) @@ -1705,9 +1730,11 @@ void RTFOnMacro(int macroId, int no_args, bool start) } } OutputCurrentSection(); // Repeat section header - TexOutput(_T("\\par\\pard}\\par\n")); - issuedNewParagraph = 2; -// if (winHelp) TexOutput(_T("\\pard")); + TexOutput(_T("\\par\\pard}\n")); + issuedNewParagraph = 1; + WriteEnvironmentStyles(); +// TexOutput(_T("\\par\\pard}\\par\n")); +// issuedNewParagraph = 2; } } break; @@ -1730,13 +1757,13 @@ void RTFOnMacro(int macroId, int no_args, bool start) if (winHelp || !useWord) { if (DocumentStyle != LATEX_ARTICLE) - wxSprintf(figBuf, _T("%s %d.%d: "), FigureNameString, chapterNo, figureNo); + wxSnprintf(figBuf, sizeof(figBuf), _T("%s %d.%d: "), FigureNameString, chapterNo, figureNo); else - wxSprintf(figBuf, _T("%s %d: "), FigureNameString, figureNo); + wxSnprintf(figBuf, sizeof(figBuf), _T("%s %d: "), FigureNameString, figureNo); } else { - wxSprintf(figBuf, _T("%s {\\field\\flddirty{\\*\\fldinst SEQ Figure \\\\* ARABIC }{\\fldrslt {\\bkmkstart %s}??{\\bkmkend %s}}}: "), + wxSnprintf(figBuf, sizeof(figBuf), _T("%s {\\field\\flddirty{\\*\\fldinst SEQ Figure \\\\* ARABIC }{\\fldrslt {\\bkmkstart %s}??{\\bkmkend %s}}}: "), FigureNameString, topicName, topicName); } } @@ -1747,13 +1774,13 @@ void RTFOnMacro(int macroId, int no_args, bool start) if (winHelp || !useWord) { if (DocumentStyle != LATEX_ARTICLE) - wxSprintf(figBuf, _T("%s %d.%d: "), TableNameString, chapterNo, tableNo); + wxSnprintf(figBuf, sizeof(figBuf), _T("%s %d.%d: "), TableNameString, chapterNo, tableNo); else - wxSprintf(figBuf, _T("%s %d: "), TableNameString, tableNo); + wxSnprintf(figBuf, sizeof(figBuf), _T("%s %d: "), TableNameString, tableNo); } else { - wxSprintf(figBuf, _T("%s {\\field\\flddirty{\\*\\fldinst SEQ Table \\\\* ARABIC }{\\fldrslt {\\bkmkstart %s}??{\\bkmkend %s}}}: "), + wxSnprintf(figBuf, sizeof(figBuf), _T("%s {\\field\\flddirty{\\*\\fldinst SEQ Table \\\\* ARABIC }{\\fldrslt {\\bkmkstart %s}??{\\bkmkend %s}}}: "), TableNameString, topicName, topicName); } } @@ -1790,18 +1817,18 @@ void RTFOnMacro(int macroId, int no_args, bool start) if (winHelp) { TexOutput(_T("K{\\footnote {K} ")); - suppressNameDecoration = TRUE; + suppressNameDecoration = true; TraverseChildrenFromChunk(currentMember); - suppressNameDecoration = FALSE; + suppressNameDecoration = false; TexOutput(_T("}\n")); } if (!winHelp && useWord) { // Insert index entry for this function TexOutput(_T("{\\xe\\v {")); - suppressNameDecoration = TRUE; // Necessary so don't print "(\\bf" etc. + suppressNameDecoration = true; // Necessary so don't print "(\\bf" etc. TraverseChildrenFromChunk(currentMember); - suppressNameDecoration = FALSE; + suppressNameDecoration = false; TexOutput(_T("}}")); } } @@ -1820,18 +1847,18 @@ void RTFOnMacro(int macroId, int no_args, bool start) if (winHelp) { TexOutput(_T("K{\\footnote {K} ")); - suppressNameDecoration = TRUE; // Necessary so don't print "(\\bf" etc. + suppressNameDecoration = true; // Necessary so don't print "(\\bf" etc. TraverseChildrenFromChunk(currentMember); - suppressNameDecoration = FALSE; + suppressNameDecoration = false; TexOutput(_T("}\n")); } if (!winHelp && useWord) { // Insert index entry for this function TexOutput(_T("{\\xe\\v {")); - suppressNameDecoration = TRUE; // Necessary so don't print "(\\bf" etc. + suppressNameDecoration = true; // Necessary so don't print "(\\bf" etc. TraverseChildrenFromChunk(currentMember); - suppressNameDecoration = FALSE; + suppressNameDecoration = false; TexOutput(_T("}}")); } } @@ -1857,9 +1884,9 @@ void RTFOnMacro(int macroId, int no_args, bool start) { // Insert index entry for this function TexOutput(_T("{\\xe\\v {")); - suppressNameDecoration = TRUE; // Necessary so don't print "(\\bf" etc. + suppressNameDecoration = true; // Necessary so don't print "(\\bf" etc. TraverseChildrenFromChunk(currentMember); - suppressNameDecoration = FALSE; + suppressNameDecoration = false; TexOutput(_T("}}")); } } @@ -1881,10 +1908,10 @@ void RTFOnMacro(int macroId, int no_args, bool start) TexOutput(_T("\\par\\pard\\pgnrestart\\sect\\titlepg")); // In linear RTF, same as chapter headings. - wxSprintf(buf, _T("{\\b\\fs%d %s}\\par\\par\\pard\n\n"), chapterFont*2, ContentsNameString); + wxSnprintf(buf, sizeof(buf), _T("{\\b\\fs%d %s}\\par\\par\\pard\n\n"), chapterFont*2, ContentsNameString); TexOutput(buf); - wxSprintf(buf, _T("{\\field{\\*\\fldinst TOC \\\\o \"1-%d\" }{\\fldrslt PRESS F9 TO REFORMAT CONTENTS}}\n"), contentsDepth); + wxSnprintf(buf, sizeof(buf), _T("{\\field{\\*\\fldinst TOC \\\\o \"1-%d\" }{\\fldrslt PRESS F9 TO REFORMAT CONTENTS}}\n"), contentsDepth); TexOutput(buf); // TexOutput(_T("\\sect\\sectd")); } @@ -1896,7 +1923,7 @@ void RTFOnMacro(int macroId, int no_args, bool start) int ch = getc(fd); while (ch != EOF) { - putc(ch, Chapters); + wxPutc(ch, Chapters); ch = getc(fd); } fclose(fd); @@ -1943,10 +1970,11 @@ void RTFOnMacro(int macroId, int no_args, bool start) { if (start) { - if (inVerbatim) + #if 1 // if(inVerbatim) TexOutput(_T("~")); - else + #else TexOutput(_T(" ")); + #endif } break; } @@ -1967,8 +1995,8 @@ void RTFOnMacro(int macroId, int no_args, bool start) if (TableData[i].leftBorder) TexOutput(_T("\\clbrdrl\\brdrs\\brdrw15")); - - wxSprintf(buf, _T("\\cellx%d"), currentWidth); + + wxSnprintf(buf, sizeof(buf), _T("\\cellx%d"), currentWidth); TexOutput(buf); } TexOutput(_T("\\pard\\intbl\n")); @@ -1998,8 +2026,11 @@ void RTFOnMacro(int macroId, int no_args, bool start) { if (indentLevel > 0) { - TexOutput(_T("\\par\\par\n")); - issuedNewParagraph = 2; + // Experimental JACS 2004-02-21 + TexOutput(_T("\\par\n")); + issuedNewParagraph = 1; +// TexOutput(_T("\\par\\par\n")); +// issuedNewParagraph = 2; } else { @@ -2033,8 +2064,8 @@ void RTFOnMacro(int macroId, int no_args, bool start) ItemizeStruc *struc = new ItemizeStruc(listType, indentSize2, indentSize1); itemizeStack.Insert(struc); - - wxSprintf(buf, _T("\\tx%d\\tx%d\\li%d"), indentSize1, indentSize2, indentSize2); + + wxSnprintf(buf, sizeof(buf), _T("\\tx%d\\tx%d\\li%d\\sa200"), indentSize1, indentSize2, indentSize2); PushEnvironmentStyle(buf); } else @@ -2052,8 +2083,8 @@ void RTFOnMacro(int macroId, int no_args, bool start) /* Change 18/7/97 - don't know why we wish to do this if (itemizeStack.Number() == 0) { - OnMacro(ltPAR, 0, TRUE); - OnMacro(ltPAR, 0, FALSE); + OnMacro(ltPAR, 0, true); + OnMacro(ltPAR, 0, false); issuedNewParagraph = 2; } */ @@ -2074,9 +2105,9 @@ void RTFOnMacro(int macroId, int no_args, bool start) ItemizeStruc *struc = new ItemizeStruc(LATEX_TWOCOL, indentSize); itemizeStack.Insert(struc); - -// wxSprintf(buf, _T("\\tx%d\\li%d\\ri%d"), indentSize, indentSize, TwoColWidthA+TwoColWidthB+oldIndent); - wxSprintf(buf, _T("\\tx%d\\li%d"), indentSize, indentSize); + +// wxSnprintf(buf, sizeof(buf), _T("\\tx%d\\li%d\\ri%d"), indentSize, indentSize, TwoColWidthA+TwoColWidthB+oldIndent); + wxSnprintf(buf, sizeof(buf), _T("\\tx%d\\li%d\\sa200"), indentSize, indentSize); PushEnvironmentStyle(buf); } else @@ -2095,12 +2126,16 @@ void RTFOnMacro(int macroId, int no_args, bool start) WriteEnvironmentStyles(); */ /* why do we need this? */ +// Experimental + TexOutput(_T("\\pard\n")); +#if 0 if (itemizeStack.GetCount() == 0) { issuedNewParagraph = 0; - OnMacro(ltPAR, 0, TRUE); - OnMacro(ltPAR, 0, FALSE); + OnMacro(ltPAR, 0, true); + OnMacro(ltPAR, 0, false); } +#endif } break; } @@ -2119,16 +2154,18 @@ void RTFOnMacro(int macroId, int no_args, bool start) int indentSize2 = struc->indentation; TexOutput(_T("\n")); - if (struc->currentItem > 1) + if (struc->currentItem > 1 && issuedNewParagraph == 0) { - if (currentItemSep > 0) - TexOutput(_T("\\par")); + // JACS +// if (currentItemSep > 0) +// TexOutput(_T("\\par")); TexOutput(_T("\\par")); + issuedNewParagraph = 1; // WriteEnvironmentStyles(); } - wxSprintf(buf, _T("\\tx%d\\tx%d\\li%d\\fi-%d\n"), indentSize1, indentSize2, + wxSnprintf(buf, sizeof(buf), _T("\\tx%d\\tx%d\\li%d\\fi-%d\n"), indentSize1, indentSize2, indentSize2, 20*itemIndentTab); TexOutput(buf); @@ -2142,10 +2179,10 @@ void RTFOnMacro(int macroId, int no_args, bool start) TraverseChildrenFromChunk(descriptionItemArg); TexOutput(_T("}\\tab")); descriptionItemArg = NULL; - } - else - { - wxSprintf(indentBuf, _T("\\tab{\\b %d.}\\tab"), struc->currentItem); + } + else + { + wxSnprintf(indentBuf, sizeof(indentBuf), _T("\\tab{\\b %d.}\\tab"), struc->currentItem); TexOutput(indentBuf); } break; @@ -2158,20 +2195,20 @@ void RTFOnMacro(int macroId, int no_args, bool start) TraverseChildrenFromChunk(descriptionItemArg); TexOutput(_T("}\\tab")); descriptionItemArg = NULL; - } - else - { + } + else + { if (bulletFile && winHelp) { if (winHelpVersion > 3) // Transparent bitmap - wxSprintf(indentBuf, _T("\\tab\\{bmct %s\\}\\tab"), bulletFile); + wxSnprintf(indentBuf, sizeof(indentBuf), _T("\\tab\\{bmct %s\\}\\tab"), bulletFile); else - wxSprintf(indentBuf, _T("\\tab\\{bmc %s\\}\\tab"), bulletFile); + wxSnprintf(indentBuf, sizeof(indentBuf), _T("\\tab\\{bmc %s\\}\\tab"), bulletFile); } else if (winHelp) - wxSprintf(indentBuf, _T("\\tab{\\b o}\\tab")); + wxSnprintf(indentBuf, sizeof(indentBuf), _T("\\tab{\\b o}\\tab")); else - wxSprintf(indentBuf, _T("\\tab{\\f1\\'b7}\\tab")); + wxSnprintf(indentBuf, sizeof(indentBuf), _T("\\tab{\\f1\\'b7}\\tab")); TexOutput(indentBuf); } break; @@ -2188,7 +2225,7 @@ void RTFOnMacro(int macroId, int no_args, bool start) } break; } - } + } } } break; @@ -2212,6 +2249,8 @@ void RTFOnMacro(int macroId, int no_args, bool start) oldIndent = ((ItemizeStruc *)node2->GetData())->indentation; TexOutput(_T("\n")); + // JACS +#if 0 if (struc->currentItem > 1) { if (currentItemSep > 0) @@ -2219,14 +2258,15 @@ void RTFOnMacro(int macroId, int no_args, bool start) // WriteEnvironmentStyles(); } +#endif -// wxSprintf(buf, _T("\\tx%d\\li%d\\fi-%d\\ri%d\n"), TwoColWidthA, +// wxSnprintf(buf, sizeof(buf), _T("\\tx%d\\li%d\\fi-%d\\ri%d\n"), TwoColWidthA, // TwoColWidthA, TwoColWidthA, TwoColWidthA+TwoColWidthB+oldIndent); /* - wxSprintf(buf, _T("\\tx%d\\li%d\\fi-%d\n"), TwoColWidthA, + wxSnprintf(buf, sizeof(buf), _T("\\tx%d\\li%d\\fi-%d\n"), TwoColWidthA, TwoColWidthA, TwoColWidthA); */ - wxSprintf(buf, _T("\\tx%d\\li%d\\fi-%d\n"), TwoColWidthA + oldIndent, + wxSnprintf(buf, sizeof(buf), _T("\\tx%d\\li%d\\fi-%d\n"), TwoColWidthA + oldIndent, TwoColWidthA + oldIndent, TwoColWidthA); TexOutput(buf); } @@ -2238,6 +2278,8 @@ void RTFOnMacro(int macroId, int no_args, bool start) { if (start) { + // JACS +#if 0 if (macroId == ltVERBATIM) { if (!issuedNewParagraph) @@ -2248,7 +2290,12 @@ void RTFOnMacro(int macroId, int no_args, bool start) } else issuedNewParagraph = 0; } - wxSprintf(buf, _T("{\\f3\\fs20 ")); +#endif + + if (macroId == ltVERBATIM) + wxSnprintf(buf, sizeof(buf), _T("{\\f3\\s10\\fs20\\li720\\sa0 ")); + else + wxSnprintf(buf, sizeof(buf), _T("{\\f3\\fs20 ")); TexOutput(buf); } else @@ -2257,8 +2304,12 @@ void RTFOnMacro(int macroId, int no_args, bool start) if (macroId == ltVERBATIM) { TexOutput(_T("\\pard\n")); -// issuedNewParagraph = 1; WriteEnvironmentStyles(); + // JACS +#if 0 + TexOutput(_T("\\par\n")); + issuedNewParagraph = 1; +#endif } } break; @@ -2268,9 +2319,9 @@ void RTFOnMacro(int macroId, int no_args, bool start) { if (start) { - TexOutput(_T("\\fi0\\qc ")); + TexOutput(_T("\\qc ")); forbidParindent ++; - PushEnvironmentStyle(_T("\\qc")); + PushEnvironmentStyle(_T("\\qc\\sa200")); } else { @@ -2286,7 +2337,7 @@ void RTFOnMacro(int macroId, int no_args, bool start) { if (start) { - TexOutput(_T("\\fi0\\ql ")); + TexOutput(_T("\\ql\\sa200 ")); forbidParindent ++; PushEnvironmentStyle(_T("\\ql")); } @@ -2304,7 +2355,7 @@ void RTFOnMacro(int macroId, int no_args, bool start) { if (start) { - TexOutput(_T("\\fi0\\qr ")); + TexOutput(_T("\\qr\\sa200 ")); forbidParindent ++; PushEnvironmentStyle(_T("\\qr")); } @@ -2323,7 +2374,7 @@ void RTFOnMacro(int macroId, int no_args, bool start) { if (start) { - wxSprintf(buf, _T("{\\fs%d\n"), smallFont*2); + wxSnprintf(buf, sizeof(buf), _T("{\\fs%d\n"), smallFont*2); TexOutput(buf); } else TexOutput(_T("}\n")); @@ -2334,7 +2385,7 @@ void RTFOnMacro(int macroId, int no_args, bool start) { if (start) { - wxSprintf(buf, _T("{\\fs%d\n"), tinyFont*2); + wxSnprintf(buf, sizeof(buf), _T("{\\fs%d\n"), tinyFont*2); TexOutput(buf); } else TexOutput(_T("}\n")); @@ -2344,7 +2395,7 @@ void RTFOnMacro(int macroId, int no_args, bool start) { if (start) { - wxSprintf(buf, _T("{\\fs%d\n"), normalFont*2); + wxSnprintf(buf, sizeof(buf), _T("{\\fs%d\n"), normalFont*2); TexOutput(buf); } else TexOutput(_T("}\n")); @@ -2354,7 +2405,7 @@ void RTFOnMacro(int macroId, int no_args, bool start) { if (start) { - wxSprintf(buf, _T("{\\fs%d\n"), largeFont1*2); + wxSnprintf(buf, sizeof(buf), _T("{\\fs%d\n"), largeFont1*2); TexOutput(buf); } else TexOutput(_T("}\n")); @@ -2364,7 +2415,7 @@ void RTFOnMacro(int macroId, int no_args, bool start) { if (start) { - wxSprintf(buf, _T("{\\fs%d\n"), LargeFont2*2); + wxSnprintf(buf, sizeof(buf), _T("{\\fs%d\n"), LargeFont2*2); TexOutput(buf); } else TexOutput(_T("}\n")); @@ -2374,7 +2425,7 @@ void RTFOnMacro(int macroId, int no_args, bool start) { if (start) { - wxSprintf(buf, _T("{\\fs%d\n"), LARGEFont3*2); + wxSnprintf(buf, sizeof(buf), _T("{\\fs%d\n"), LARGEFont3*2); TexOutput(buf); } else TexOutput(_T("}\n")); @@ -2384,7 +2435,7 @@ void RTFOnMacro(int macroId, int no_args, bool start) { if (start) { - wxSprintf(buf, _T("{\\fs%d\n"), hugeFont1*2); + wxSnprintf(buf, sizeof(buf), _T("{\\fs%d\n"), hugeFont1*2); TexOutput(buf); } else TexOutput(_T("}\n")); @@ -2394,7 +2445,7 @@ void RTFOnMacro(int macroId, int no_args, bool start) { if (start) { - wxSprintf(buf, _T("{\\fs%d\n"), HugeFont2*2); + wxSnprintf(buf, sizeof(buf), _T("{\\fs%d\n"), HugeFont2*2); TexOutput(buf); } else TexOutput(_T("}\n")); @@ -2404,7 +2455,7 @@ void RTFOnMacro(int macroId, int no_args, bool start) { if (start) { - wxSprintf(buf, _T("{\\fs%d\n"), HUGEFont3*2); + wxSnprintf(buf, sizeof(buf), _T("{\\fs%d\n"), HUGEFont3*2); TexOutput(buf); } else TexOutput(_T("}\n")); @@ -2449,7 +2500,7 @@ void RTFOnMacro(int macroId, int no_args, bool start) case ltRMFAMILY: case ltRM: { -/* +/* if (start) { TexOutput(_T("{\\plain ")); @@ -2522,34 +2573,39 @@ void RTFOnMacro(int macroId, int no_args, bool start) { if (start) { - if ( issuedNewParagraph == 0 ) - { + if ( issuedNewParagraph == 0 ) + { TexOutput(_T("\\par\\pard")); issuedNewParagraph ++; // Extra par if parskip is more than zero (usually looks best.) - if (!inTabular && (ParSkip > 0)) - { + // N.B. JACS 2004-02-21: shouldn't need this for linear RTF if + // we have a suitable set of styles. +#if 0 + if (winHelp && !inTabular && (ParSkip > 0)) + { TexOutput(_T("\\par")); issuedNewParagraph ++; - } + } +#endif WriteEnvironmentStyles(); - } - // 1 is a whole paragraph if ParSkip == 0, - // half a paragraph if ParSkip > 0 - else if ( issuedNewParagraph == 1 ) - { - // Don't need a par at all if we've already had one, - // and ParSkip == 0. - + } + // 1 is a whole paragraph if ParSkip == 0, + // half a paragraph if ParSkip > 0 + else if ( issuedNewParagraph == 1 ) + { + // Don't need a par at all if we've already had one, + // and ParSkip == 0. +#if 0 // Extra par if parskip is more than zero (usually looks best.) - if (!inTabular && (ParSkip > 0)) - { + if (winHelp && !inTabular && (ParSkip > 0)) + { TexOutput(_T("\\par")); issuedNewParagraph ++; - } + } +#endif WriteEnvironmentStyles(); - } + } /* if (!issuedNewParagraph || (issuedNewParagraph > 1)) { @@ -2581,7 +2637,7 @@ void RTFOnMacro(int macroId, int no_args, bool start) TexOutput(_T("\\par\\pard")); if (!winHelp) TexOutput(_T("\\par")); - wxSprintf(buf, _T("\\qc{\\fs%d\\b "), titleFont*2); + wxSnprintf(buf, sizeof(buf), _T("\\qc{\\fs%d\\b "), titleFont*2); TexOutput(buf); TraverseChildrenFromChunk(DocumentTitle); TexOutput(_T("}\\par\\pard\n")); @@ -2590,7 +2646,7 @@ void RTFOnMacro(int macroId, int no_args, bool start) { if (!winHelp) TexOutput(_T("\\par")); - wxSprintf(buf, _T("\\par\\qc{\\fs%d "), authorFont*2); + wxSnprintf(buf, sizeof(buf), _T("\\par\\qc{\\fs%d "), authorFont*2); TexOutput(buf); TraverseChildrenFromChunk(DocumentAuthor); TexOutput(_T("}")); @@ -2599,7 +2655,7 @@ void RTFOnMacro(int macroId, int no_args, bool start) if (DocumentDate) { TexOutput(_T("\\par")); - wxSprintf(buf, _T("\\qc{\\fs%d "), authorFont*2); + wxSnprintf(buf, sizeof(buf), _T("\\qc{\\fs%d "), authorFont*2); TexOutput(buf); TraverseChildrenFromChunk(DocumentDate); TexOutput(_T("}\\par\\pard\n")); @@ -2683,7 +2739,7 @@ void RTFOnMacro(int macroId, int no_args, bool start) if (start) { // TexOutput(_T("{\\field{\\*\\fldinst SECTION \\\\* MERGEFORMAT }{\\fldrslt 1}}")); - wxSprintf(buf, _T("%d"), chapterNo); + wxSnprintf(buf, sizeof(buf), _T("%d"), chapterNo); TexOutput(buf); } break; @@ -2693,7 +2749,7 @@ void RTFOnMacro(int macroId, int no_args, bool start) if (start) { // TexOutput(_T("{\\field{\\*\\fldinst SECTION \\\\* MERGEFORMAT }{\\fldrslt 1}}")); - wxSprintf(buf, _T("%d"), sectionNo); + wxSnprintf(buf, sizeof(buf), _T("%d"), sectionNo); TexOutput(buf); } break; @@ -2719,8 +2775,8 @@ void RTFOnMacro(int macroId, int no_args, bool start) if (start && useWord && !winHelp) { FakeCurrentSection(_T("Index")); - OnMacro(ltPAR, 0, TRUE); - OnMacro(ltPAR, 0, FALSE); + OnMacro(ltPAR, 0, true); + OnMacro(ltPAR, 0, false); TexOutput(_T("\\par{\\field{\\*\\fldinst INDEX \\\\h \"\\emdash A\\emdash \"\\\\c \"2\"}{\\fldrslt PRESS F9 TO REFORMAT INDEX}}\n")); } break; @@ -2729,13 +2785,13 @@ void RTFOnMacro(int macroId, int no_args, bool start) { if (start && useWord && !winHelp) { - FakeCurrentSection(FiguresNameString, FALSE); - OnMacro(ltPAR, 0, TRUE); - OnMacro(ltPAR, 0, FALSE); - OnMacro(ltPAR, 0, TRUE); - OnMacro(ltPAR, 0, FALSE); + FakeCurrentSection(FiguresNameString, false); + OnMacro(ltPAR, 0, true); + OnMacro(ltPAR, 0, false); + OnMacro(ltPAR, 0, true); + OnMacro(ltPAR, 0, false); wxChar buf[200]; - wxSprintf(buf, _T("{\\field\\fldedit{\\*\\fldinst TOC \\\\c \"%s\" }{\\fldrslt PRESS F9 TO REFORMAT LIST OF FIGURES}}\n"), + wxSnprintf(buf, sizeof(buf), _T("{\\field\\fldedit{\\*\\fldinst TOC \\\\c \"%s\" }{\\fldrslt PRESS F9 TO REFORMAT LIST OF FIGURES}}\n"), FigureNameString); TexOutput(buf); } @@ -2745,13 +2801,13 @@ void RTFOnMacro(int macroId, int no_args, bool start) { if (start && useWord && !winHelp) { - FakeCurrentSection(TablesNameString, FALSE); - OnMacro(ltPAR, 0, TRUE); - OnMacro(ltPAR, 0, FALSE); - OnMacro(ltPAR, 0, TRUE); - OnMacro(ltPAR, 0, FALSE); + FakeCurrentSection(TablesNameString, false); + OnMacro(ltPAR, 0, true); + OnMacro(ltPAR, 0, false); + OnMacro(ltPAR, 0, true); + OnMacro(ltPAR, 0, false); wxChar buf[200]; - wxSprintf(buf, _T("{\\field\\fldedit{\\*\\fldinst TOC \\\\c \"%s\" }{\\fldrslt PRESS F9 TO REFORMAT LIST OF TABLES}}\n"), + wxSnprintf(buf, sizeof(buf), _T("{\\field\\fldedit{\\*\\fldinst TOC \\\\c \"%s\" }{\\fldrslt PRESS F9 TO REFORMAT LIST OF TABLES}}\n"), TablesNameString); TexOutput(buf); } @@ -3106,14 +3162,14 @@ void RTFOnMacro(int macroId, int no_args, bool start) break; case ltFIGURE: { - if (start) inFigure = TRUE; - else inFigure = FALSE; + if (start) inFigure = true; + else inFigure = false; break; } case ltTABLE: { - if (start) inTable = TRUE; - else inTable = FALSE; + if (start) inTable = true; + else inTable = false; break; } default: @@ -3148,7 +3204,7 @@ bool RTFOnArgument(int macroId, int arg_no, bool start) { if (!start && (arg_no == 1)) currentSection = GetArgChunk(); - return FALSE; + return false; } case ltFUNC: { @@ -3167,7 +3223,7 @@ bool RTFOnArgument(int macroId, int arg_no, bool start) { if (!suppressNameDecoration) TexOutput(_T("}")); } - + if (start && (arg_no == 3)) TexOutput(_T("(")); if (!start && (arg_no == 3)) @@ -3275,7 +3331,7 @@ bool RTFOnArgument(int macroId, int arg_no, bool start) if (start) { wxChar *sec = NULL; - + wxChar *refName = GetArgData(); if (winHelp || !useWord) { @@ -3297,7 +3353,7 @@ bool RTFOnArgument(int macroId, int arg_no, bool start) wxFprintf(Chapters, _T("{\\field{\\*\\fldinst REF %s \\\\* MERGEFORMAT }{\\fldrslt ??}}"), refName); } - return FALSE; + return false; } break; } @@ -3342,7 +3398,7 @@ bool RTFOnArgument(int macroId, int arg_no, bool start) if (start) helpRefText = GetArgChunk(); - return TRUE; + return true; } else if ((GetNoArgs() - arg_no) == 0) // Arg = 2, or 3 if first is optional { @@ -3381,7 +3437,7 @@ bool RTFOnArgument(int macroId, int arg_no, bool start) { if (!ignoreBadRefs) TexOutput(_T("??")); - wxSprintf(buf, _T("Warning: unresolved reference '%s'"), refName); + wxSnprintf(buf, sizeof(buf), _T("Warning: unresolved reference '%s'"), refName); OnInform(buf); } } @@ -3395,7 +3451,7 @@ bool RTFOnArgument(int macroId, int arg_no, bool start) TexOutput(_T(")")); } } - return FALSE; + return false; } } break; @@ -3404,21 +3460,21 @@ bool RTFOnArgument(int macroId, int arg_no, bool start) { if (arg_no == 1) { - return TRUE; + return true; } else if (arg_no == 2) { if (start) { - inVerbatim = TRUE; + inVerbatim = true; TexOutput(_T(" ({\\f3 ")); } else { TexOutput(_T("})")); - inVerbatim = FALSE; + inVerbatim = false; } - return TRUE; + return true; } break; } @@ -3457,9 +3513,9 @@ bool RTFOnArgument(int macroId, int arg_no, bool start) TexOutput(_T("{\\i ")); else TexOutput(_T("}")); - return TRUE; + return true; } - else return FALSE; + else return false; } break; } @@ -3471,9 +3527,9 @@ bool RTFOnArgument(int macroId, int arg_no, bool start) contentsLineSection = copystring(GetArgData()); else if (arg_no == 3) contentsLineValue = copystring(GetArgData()); - return FALSE; + return false; } - else return FALSE; + else return false; } case ltIMAGE: case ltIMAGEL: @@ -3482,11 +3538,11 @@ bool RTFOnArgument(int macroId, int arg_no, bool start) case ltPSBOXTO: { if (arg_no == 3) - return FALSE; - + return false; + static int imageWidth = 0; static int imageHeight = 0; - + if (start && (arg_no == 1)) { wxChar *imageDimensions = copystring(GetArgData()); @@ -3496,7 +3552,7 @@ bool RTFOnArgument(int macroId, int arg_no, bool start) if(tok.HasMoreTokens()) { wxString token = tok.GetNextToken(); - imageWidth = (int)(20*ParseUnitArgument((wxChar*)token.c_str())); + imageWidth = (int)(20*ParseUnitArgument(token)); } else { @@ -3507,7 +3563,7 @@ bool RTFOnArgument(int macroId, int arg_no, bool start) if(tok.HasMoreTokens()) { wxString token = tok.GetNextToken(); - imageHeight = (int)(20*ParseUnitArgument((wxChar*)token.c_str())); + imageHeight = (int)(20*ParseUnitArgument(token)); } else { @@ -3516,8 +3572,8 @@ bool RTFOnArgument(int macroId, int arg_no, bool start) if (imageDimensions) // glt delete [] imageDimensions; - return FALSE; - } + return false; + } else if (start && (arg_no == 2 )) { wxChar *filename = copystring(GetArgData()); @@ -3587,7 +3643,7 @@ bool RTFOnArgument(int macroId, int arg_no, bool start) TexOutput(_T("[No BMP or WMF for image file ")); TexOutput(filename); TexOutput(_T("]")); - wxSprintf(buf, _T("Warning: could not find a BMP or WMF equivalent for %s."), filename); + wxSnprintf(buf, sizeof(buf), _T("Warning: could not find a BMP or WMF equivalent for %s."), filename); OnInform(buf); } if (filename) // glt @@ -3609,7 +3665,7 @@ bool RTFOnArgument(int macroId, int arg_no, bool start) OutputBitmapData(fd); else { - wxSprintf(buf, _T("Could not read bitmap %s.\nMay be in wrong format (needs RGB-encoded Windows BMP)."), f.c_str()); + wxSnprintf(buf, sizeof(buf), _T("Could not read bitmap %s.\nMay be in wrong format (needs RGB-encoded Windows BMP)."), f.c_str()); OnError(buf); } fclose(fd); @@ -3631,28 +3687,28 @@ bool RTFOnArgument(int macroId, int arg_no, bool start) } else { - wxSprintf(buf, _T("Could not read metafile %s. Perhaps it's not a placeable metafile?"), f.c_str()); + wxSnprintf(buf, sizeof(buf), _T("Could not read metafile %s. Perhaps it's not a placeable metafile?"), f.c_str()); OnError(buf); } fclose(fd); } else { -#endif +#endif TexOutput(_T("[No BMP or WMF for image file ")); TexOutput(filename); TexOutput(_T("]")); - wxSprintf(buf, _T("Warning: could not find a BMP or WMF equivalent for %s."), filename); + wxSnprintf(buf, sizeof(buf), _T("Warning: could not find a BMP or WMF equivalent for %s."), filename); OnInform(buf); #ifdef __WXMSW__ } #endif } } - return FALSE; + return false; } else - return FALSE; + return false; } case ltTABULAR: case ltSUPERTABULAR: @@ -3662,10 +3718,10 @@ bool RTFOnArgument(int macroId, int arg_no, bool start) if (start) { currentRowNumber = 0; - inTabular = TRUE; - startRows = TRUE; - tableVerticalLineLeft = FALSE; - tableVerticalLineRight = FALSE; + inTabular = true; + startRows = true; + tableVerticalLineLeft = false; + tableVerticalLineRight = false; int currentWidth = 0; wxChar *alignString = copystring(GetArgData()); @@ -3681,21 +3737,21 @@ bool RTFOnArgument(int macroId, int arg_no, bool start) for (int i = 0; i < noColumns; i++) { currentWidth += TableData[i].width; - wxSprintf(buf, _T("\\cellx%d"), currentWidth); + wxSnprintf(buf, sizeof(buf), _T("\\cellx%d"), currentWidth); TexOutput(buf); } TexOutput(_T("\\pard\\intbl\n")); } delete[] alignString; - return FALSE; + return false; } } else if (arg_no == 2 && !start) { TexOutput(_T("\\pard\n")); WriteEnvironmentStyles(); - inTabular = FALSE; + inTabular = false; } break; } @@ -3707,14 +3763,14 @@ bool RTFOnArgument(int macroId, int arg_no, bool start) { TexOutput(_T("\\li360\n")); forbidParindent ++; - PushEnvironmentStyle(_T("\\li360")); + PushEnvironmentStyle(_T("\\li360\\sa200")); } else { forbidParindent --; PopEnvironmentStyle(); - OnMacro(ltPAR, 0, TRUE); - OnMacro(ltPAR, 0, FALSE); + OnMacro(ltPAR, 0, true); + OnMacro(ltPAR, 0, false); } break; } @@ -3723,13 +3779,13 @@ bool RTFOnArgument(int macroId, int arg_no, bool start) if (start) { TexOutput(_T("\\li360\n")); - PushEnvironmentStyle(_T("\\li360")); + PushEnvironmentStyle(_T("\\li360\\sa200")); } else { PopEnvironmentStyle(); - OnMacro(ltPAR, 0, TRUE); - OnMacro(ltPAR, 0, FALSE); + OnMacro(ltPAR, 0, true); + OnMacro(ltPAR, 0, false); } break; } @@ -3741,15 +3797,15 @@ bool RTFOnArgument(int macroId, int arg_no, bool start) { if (start) { - wxSprintf(buf, _T("\\box\\trgaph108%s\n"), ((macroId == ltNORMALBOXD) ? _T("\\brdrdb") : _T("\\brdrs"))); + wxSnprintf(buf, sizeof(buf), _T("\\sa200\\box\\trgaph108%s\n"), ((macroId == ltNORMALBOXD) ? _T("\\brdrdb") : _T("\\brdrs"))); TexOutput(buf); PushEnvironmentStyle(buf); } else { PopEnvironmentStyle(); - OnMacro(ltPAR, 0, TRUE); - OnMacro(ltPAR, 0, FALSE); + OnMacro(ltPAR, 0, true); + OnMacro(ltPAR, 0, false); } break; } @@ -3764,10 +3820,10 @@ bool RTFOnArgument(int macroId, int arg_no, bool start) SetFontSizes(11); else if (wxStrcmp(data, _T("12")) == 0) SetFontSizes(12); - wxSprintf(buf, _T("\\fs%d\n"), normalFont*2); + wxSnprintf(buf, sizeof(buf), _T("\\fs%d\n"), normalFont*2); TexOutput(buf); TexOutput(buf); - return FALSE; + return false; } break; } @@ -3783,7 +3839,7 @@ bool RTFOnArgument(int macroId, int arg_no, bool start) else if (wxStrcmp(data, _T("Times")) == 0) TexOutput(_T("\\f0\n")); - return FALSE; + return false; } break; } @@ -3795,10 +3851,10 @@ bool RTFOnArgument(int macroId, int arg_no, bool start) ParIndent = ParseUnitArgument(data); if (ParIndent == 0 || forbidParindent == 0) { - wxSprintf(buf, _T("\\fi%d\n"), ParIndent*20); + wxSnprintf(buf, sizeof(buf), _T("\\fi%d\n"), ParIndent*20); TexOutput(buf); } - return FALSE; + return false; } break; } @@ -3807,7 +3863,7 @@ bool RTFOnArgument(int macroId, int arg_no, bool start) if (start && IsArgOptional()) { descriptionItemArg = GetArgChunk(); - return FALSE; + return false; } break; } @@ -3835,7 +3891,7 @@ bool RTFOnArgument(int macroId, int arg_no, bool start) break; } } - return TRUE; + return true; } /* * Accents @@ -3885,7 +3941,7 @@ bool RTFOnArgument(int macroId, int arg_no, bool start) } } } - return FALSE; + return false; } case ltACCENT_ACUTE: { @@ -3937,7 +3993,7 @@ bool RTFOnArgument(int macroId, int arg_no, bool start) } } } - return FALSE; + return false; } case ltACCENT_CARET: { @@ -3983,7 +4039,7 @@ bool RTFOnArgument(int macroId, int arg_no, bool start) } } } - return FALSE; + return false; } case ltACCENT_TILDE: { @@ -4020,7 +4076,7 @@ bool RTFOnArgument(int macroId, int arg_no, bool start) } } } - return FALSE; + return false; } case ltACCENT_UMLAUT: { @@ -4075,7 +4131,7 @@ bool RTFOnArgument(int macroId, int arg_no, bool start) } } } - return FALSE; + return false; } case ltACCENT_DOT: { @@ -4097,7 +4153,7 @@ bool RTFOnArgument(int macroId, int arg_no, bool start) } } } - return FALSE; + return false; } case ltACCENT_CADILLA: { @@ -4119,7 +4175,7 @@ bool RTFOnArgument(int macroId, int arg_no, bool start) } } } - return FALSE; + return false; } case ltFOOTNOTE: { @@ -4134,7 +4190,7 @@ bool RTFOnArgument(int macroId, int arg_no, bool start) OnInform(_T("Consider using \\footnotepopup instead of \\footnote.")); footnoteCount ++; wxChar footBuf[20]; - wxSprintf(footBuf, _T("(%d)"), footnoteCount); + wxSnprintf(footBuf, sizeof(footBuf), _T("(%d)"), footnoteCount); TexOutput(_T(" {\\ul ")); TexOutput(footBuf); @@ -4157,26 +4213,26 @@ bool RTFOnArgument(int macroId, int arg_no, bool start) wxFprintf(Popups, _T("+{\\footnote %s}\n"), GetBrowseString()); savedOutput = CurrentOutput1; SetCurrentOutput(Popups); - } - else - { + } + else + { SetCurrentOutput(savedOutput); - } - return TRUE; } - return TRUE; + return true; + } + return true; } else { if (start) { - TexOutput(_T(" {\\super \\chftn{\\footnote \\fs20 {\\super \\chftn}"), TRUE); + TexOutput(_T(" {\\super \\chftn{\\footnote \\fs20 {\\super \\chftn}"), true); } else { - TexOutput(_T("}}"), TRUE); + TexOutput(_T("}}"), true); } - return TRUE; + return true; } } case ltFOOTNOTEPOPUP: @@ -4190,9 +4246,12 @@ bool RTFOnArgument(int macroId, int arg_no, bool start) if (start) { TexOutput(_T("{\\ul ")); - } - else TexOutput(_T("}")); - return TRUE; + } + else + { + TexOutput(_T("}")); + } + return true; } else if (arg_no == 2) { @@ -4221,31 +4280,31 @@ bool RTFOnArgument(int macroId, int arg_no, bool start) { SetCurrentOutput(savedOutput); } - return TRUE; + return true; } } else { if (arg_no == 1) - return TRUE; + return true; if (start) { - TexOutput(_T(" {\\super \\chftn{\\footnote \\fs20 {\\super \\chftn}"), TRUE); + TexOutput(_T(" {\\super \\chftn{\\footnote \\fs20 {\\super \\chftn}"), true); } else { - TexOutput(_T("}}"), TRUE); + TexOutput(_T("}}"), true); } - return TRUE; + return true; } break; } case ltFANCYPLAIN: { if (start && (arg_no == 1)) - return FALSE; + return false; else - return TRUE; + return true; } case ltSETHEADER: { @@ -4254,7 +4313,7 @@ bool RTFOnArgument(int macroId, int arg_no, bool start) else forbidResetPar --; - if (winHelp) return FALSE; + if (winHelp) return false; if (start) { switch (arg_no) @@ -4294,7 +4353,7 @@ bool RTFOnArgument(int macroId, int arg_no, bool start) break; } } - return FALSE; + return false; } case ltSETFOOTER: { @@ -4303,7 +4362,7 @@ bool RTFOnArgument(int macroId, int arg_no, bool start) else forbidResetPar --; - if (winHelp) return FALSE; + if (winHelp) return false; if (start) { switch (arg_no) @@ -4343,11 +4402,11 @@ bool RTFOnArgument(int macroId, int arg_no, bool start) break; } } - return FALSE; + return false; } case ltMARKRIGHT: { - if (winHelp) return FALSE; + if (winHelp) return false; // Fake a SetHeader command if (start) { @@ -4362,11 +4421,11 @@ bool RTFOnArgument(int macroId, int arg_no, bool start) RTFOnArgument(ltSETHEADER, 4, start); if (!start) OutputRTFHeaderCommands(); - return FALSE; + return false; } case ltMARKBOTH: { - if (winHelp) return FALSE; + if (winHelp) return false; // Fake a SetHeader command switch (arg_no) { @@ -4389,7 +4448,7 @@ bool RTFOnArgument(int macroId, int arg_no, bool start) RTFOnArgument(ltSETHEADER, 4, start); if (!start) OutputRTFHeaderCommands(); - return FALSE; + return false; } } break; @@ -4401,7 +4460,7 @@ bool RTFOnArgument(int macroId, int arg_no, bool start) else forbidResetPar --; - if (winHelp) return FALSE; + if (winHelp) return false; if (start) { TexOutput(_T("\\pgnrestart")); @@ -4409,16 +4468,16 @@ bool RTFOnArgument(int macroId, int arg_no, bool start) if (currentNumberStyle) delete[] currentNumberStyle; currentNumberStyle = copystring(data); OutputNumberStyle(currentNumberStyle); - + TexOutput(_T("\n")); } - return FALSE; + return false; } case ltTWOCOLUMN: { - if (winHelp) return FALSE; + if (winHelp) return false; if (start) - return TRUE; + return true; break; } case ltITEMSEP: @@ -4427,13 +4486,13 @@ bool RTFOnArgument(int macroId, int arg_no, bool start) { wxChar *val = GetArgData(); currentItemSep = ParseUnitArgument(val); - return FALSE; + return false; } break; } case ltEVENSIDEMARGIN: { - return FALSE; + return false; } case ltODDSIDEMARGIN: { @@ -4444,12 +4503,12 @@ bool RTFOnArgument(int macroId, int arg_no, bool start) // Add an inch since in LaTeX it's specified minus an inch twips += 1440; CurrentLeftMarginOdd = twips; - wxSprintf(buf, _T("\\margl%d\n"), twips); + wxSnprintf(buf, sizeof(buf), _T("\\margl%d\n"), twips); TexOutput(buf); CurrentMarginParX = CurrentLeftMarginOdd + CurrentTextWidth + CurrentMarginParSep; } - return FALSE; + return false; } case ltMARGINPARWIDTH: { @@ -4459,7 +4518,7 @@ bool RTFOnArgument(int macroId, int arg_no, bool start) int twips = (int)(20*ParseUnitArgument(val)); CurrentMarginParWidth = twips; } - return FALSE; + return false; } case ltMARGINPARSEP: { @@ -4470,7 +4529,7 @@ bool RTFOnArgument(int macroId, int arg_no, bool start) CurrentMarginParSep = twips; CurrentMarginParX = CurrentLeftMarginOdd + CurrentTextWidth + CurrentMarginParSep; } - return FALSE; + return false; } case ltTEXTWIDTH: { @@ -4484,10 +4543,10 @@ bool RTFOnArgument(int macroId, int arg_no, bool start) CurrentRightMarginOdd = PageWidth - CurrentTextWidth - CurrentLeftMarginOdd; CurrentRightMarginEven = PageWidth - CurrentTextWidth - CurrentLeftMarginEven; CurrentMarginParX = CurrentLeftMarginOdd + CurrentTextWidth + CurrentMarginParSep; - wxSprintf(buf, _T("\\margr%d\n"), CurrentRightMarginOdd); + wxSnprintf(buf, sizeof(buf), _T("\\margr%d\n"), CurrentRightMarginOdd); TexOutput(buf); } - return FALSE; + return false; } case ltMARGINPAR: case ltMARGINPARODD: @@ -4496,15 +4555,15 @@ bool RTFOnArgument(int macroId, int arg_no, bool start) { if (winHelp) { - TexOutput(_T("\\box\n")); - PushEnvironmentStyle(_T("\\box")); + TexOutput(_T("\\sa200\\box\n")); + PushEnvironmentStyle(_T("\\sa200\\box")); } else { - wxSprintf(buf, _T("\\phpg\\posx%d\\absw%d\n"), CurrentMarginParX, CurrentMarginParWidth); + wxSnprintf(buf, sizeof(buf), _T("\\phpg\\posx%d\\absw%d\n"), CurrentMarginParX, CurrentMarginParWidth); TexOutput(buf); } - return TRUE; + return true; } else { @@ -4518,7 +4577,7 @@ bool RTFOnArgument(int macroId, int arg_no, bool start) TexOutput(_T("\\par\\pard\n")); issuedNewParagraph = 1; } - return FALSE; + return false; } case ltMARGINPAREVEN: { @@ -4526,8 +4585,8 @@ bool RTFOnArgument(int macroId, int arg_no, bool start) { if (winHelp) { - TexOutput(_T("\\box\n")); - PushEnvironmentStyle(_T("\\box")); + TexOutput(_T("\\sa200\\box\n")); + PushEnvironmentStyle(_T("\\sa200\\box")); } else { @@ -4537,16 +4596,16 @@ bool RTFOnArgument(int macroId, int arg_no, bool start) // mirror mode, on an even (left-hand) page. int x = PageWidth - CurrentRightMarginOdd - CurrentMarginParWidth - CurrentMarginParSep - CurrentTextWidth + GutterWidth; - wxSprintf(buf, _T("\\phpg\\posx%d\\absw%d\n"), x, CurrentMarginParWidth); + wxSnprintf(buf, sizeof(buf), _T("\\phpg\\posx%d\\absw%d\n"), x, CurrentMarginParWidth); TexOutput(buf); } else { - wxSprintf(buf, _T("\\phpg\\posx%d\\absw%d\n"), CurrentMarginParX, CurrentMarginParWidth); + wxSnprintf(buf, sizeof(buf), _T("\\phpg\\posx%d\\absw%d\n"), CurrentMarginParX, CurrentMarginParWidth); TexOutput(buf); } } - return TRUE; + return true; } else { @@ -4560,7 +4619,7 @@ bool RTFOnArgument(int macroId, int arg_no, bool start) issuedNewParagraph = 1; TexOutput(_T("\\par\\pard\n")); } - return FALSE; + return false; } case ltTWOCOLWIDTHA: { @@ -4570,7 +4629,7 @@ bool RTFOnArgument(int macroId, int arg_no, bool start) int twips = (int)(20*ParseUnitArgument(val)); TwoColWidthA = twips; } - return FALSE; + return false; } case ltTWOCOLWIDTHB: { @@ -4580,7 +4639,7 @@ bool RTFOnArgument(int macroId, int arg_no, bool start) int twips = (int)(20*ParseUnitArgument(val)); TwoColWidthB = twips; } - return FALSE; + return false; } case ltROW: case ltRULEDROW: @@ -4620,8 +4679,8 @@ bool RTFOnArgument(int macroId, int arg_no, bool start) if (TableData[i].leftBorder) TexOutput(_T("\\clbrdrl\\brdrs\\brdrw15")); - - wxSprintf(buf, _T("\\cellx%d"), currentWidth); + + wxSnprintf(buf, sizeof(buf), _T("\\cellx%d"), currentWidth); TexOutput(buf); } TexOutput(_T("\\pard\\intbl\n")); @@ -4629,7 +4688,7 @@ bool RTFOnArgument(int macroId, int arg_no, bool start) ruleTop = 0; ruleBottom = 0; currentRowNumber ++; - return TRUE; + return true; } else { @@ -4648,15 +4707,15 @@ bool RTFOnArgument(int macroId, int arg_no, bool start) case 1: { noMultiColumns = wxAtoi(GetArgData()); - return FALSE; + return false; } case 2: { - return FALSE; + return false; } case 3: { - return TRUE; + return true; } } } @@ -4686,11 +4745,11 @@ bool RTFOnArgument(int macroId, int arg_no, bool start) ItemizeStruc *struc = new ItemizeStruc(LATEX_INDENT, indentSize); itemizeStack.Insert(struc); - - wxSprintf(buf, _T("\\tx%d\\li%d "), indentSize, indentSize); + + wxSnprintf(buf, sizeof(buf), _T("\\tx%d\\li%d\\sa200 "), indentSize, indentSize); PushEnvironmentStyle(buf); TexOutput(buf); - return FALSE; + return false; } if (!start && (arg_no == 2)) { @@ -4708,7 +4767,7 @@ bool RTFOnArgument(int macroId, int arg_no, bool start) WriteEnvironmentStyles(); } } - return TRUE; + return true; } /* case ltSIZEDBOX: @@ -4729,12 +4788,12 @@ bool RTFOnArgument(int macroId, int arg_no, bool start) ItemizeStruc *struc = new ItemizeStruc(LATEX_INDENT, indentSize); itemizeStack.Insert(struc); - - wxSprintf(buf, _T("\\tx%d\\li%d\\lr%d\\box%s "), indentSize, indentSize, indentSizeRight, + + wxSnprintf(buf, sizeof(buf), _T("\\tx%d\\li%d\\lr%d\\sa200\\box%s "), indentSize, indentSize, indentSizeRight, ((macroId == ltCENTEREDBOX) ? _T("\\brdrs") : _T("\\brdrdb"))); PushEnvironmentStyle(buf); TexOutput(buf); - return FALSE; + return false; } if (!start && (arg_no == 2)) { @@ -4752,7 +4811,7 @@ bool RTFOnArgument(int macroId, int arg_no, bool start) WriteEnvironmentStyles(); } } - return TRUE; + return true; break; } */ @@ -4771,7 +4830,7 @@ bool RTFOnArgument(int macroId, int arg_no, bool start) } TexOutput(_T("\n")); } - return FALSE; + return false; } case ltSETHOTSPOTCOLOUR: case ltSETHOTSPOTCOLOR: @@ -4780,11 +4839,11 @@ bool RTFOnArgument(int macroId, int arg_no, bool start) { wxChar *text = GetArgData(); if (wxStrcmp(text, _T("yes")) == 0 || wxStrcmp(text, _T("on")) == 0 || wxStrcmp(text, _T("ok")) == 0) - hotSpotColour = TRUE; + hotSpotColour = true; else - hotSpotColour = FALSE; + hotSpotColour = false; } - return FALSE; + return false; } case ltSETTRANSPARENCY: { @@ -4792,11 +4851,11 @@ bool RTFOnArgument(int macroId, int arg_no, bool start) { wxChar *text = GetArgData(); if (wxStrcmp(text, _T("yes")) == 0 || wxStrcmp(text, _T("on")) == 0 || wxStrcmp(text, _T("ok")) == 0) - bitmapTransparency = TRUE; + bitmapTransparency = true; else - bitmapTransparency = FALSE; + bitmapTransparency = false; } - return FALSE; + return false; } case ltSETHOTSPOTUNDERLINE: { @@ -4804,11 +4863,11 @@ bool RTFOnArgument(int macroId, int arg_no, bool start) { wxChar *text = GetArgData(); if (wxStrcmp(text, _T("yes")) == 0 || wxStrcmp(text, _T("on")) == 0 || wxStrcmp(text, _T("ok")) == 0) - hotSpotUnderline = TRUE; + hotSpotUnderline = true; else - hotSpotUnderline = FALSE; + hotSpotUnderline = false; } - return FALSE; + return false; } case ltBIBITEM: { @@ -4819,19 +4878,19 @@ bool RTFOnArgument(int macroId, int arg_no, bool start) if (ref) { if (ref->sectionNumber) delete[] ref->sectionNumber; - wxSprintf(buf, _T("[%d]"), citeCount); + wxSnprintf(buf, sizeof(buf), _T("[%d]"), citeCount); ref->sectionNumber = copystring(buf); } TexOutput(_T("\\li260\\fi-260 ")); // Indent from 2nd line - wxSprintf(buf, _T("{\\b [%d]} "), citeCount); + wxSnprintf(buf, sizeof(buf), _T("{\\b [%d]} "), citeCount); TexOutput(buf); citeCount ++; - return FALSE; + return false; } if (arg_no == 2 && !start) TexOutput(_T("\\par\\pard\\par\n\n")); - return TRUE; + return true; } case ltTHEBIBLIOGRAPHY: { @@ -4853,7 +4912,7 @@ bool RTFOnArgument(int macroId, int arg_no, bool start) OutputRTFHeaderCommands(); OutputRTFFooterCommands(); } - + // Need to reset the current numbering style, or RTF forgets it. OutputNumberStyle(currentNumberStyle); SetCurrentOutput(Contents); @@ -4866,7 +4925,7 @@ bool RTFOnArgument(int macroId, int arg_no, bool start) else wxFprintf(Contents, _T("\\par\n\\pard{\\b %s}"), ReferencesNameString); - startedSections = TRUE; + startedSections = true; if (winHelp) wxFprintf(Chapters, _T("\n${\\footnote %s}"), ReferencesNameString); @@ -4874,7 +4933,10 @@ bool RTFOnArgument(int macroId, int arg_no, bool start) wxChar *topicName = _T("bibliography"); if (winHelp) + { wxFprintf(Contents, _T("{\\v %s}\\par\\pard\n"), topicName); + WriteEnvironmentStyles(); + } else wxFprintf(Contents, _T("\\par\\par\\pard\n")); @@ -4890,7 +4952,7 @@ bool RTFOnArgument(int macroId, int arg_no, bool start) wxFileNameFromPath(FileRoot), "Contents"); } } - + SetCurrentOutput(Chapters); wxChar *styleCommand = _T(""); if (!winHelp && useHeadingStyles) @@ -4898,9 +4960,9 @@ bool RTFOnArgument(int macroId, int arg_no, bool start) wxFprintf(Chapters, _T("\\pard{%s"), (winHelp ? _T("\\keepn\\sa140\\sb140") : styleCommand)); WriteHeadingStyle(Chapters, 1); wxFprintf(Chapters, _T(" References\\par\\pard}\n")); - return FALSE; + return false; } - return TRUE; + return true; } case ltINDEX: { @@ -4927,7 +4989,7 @@ bool RTFOnArgument(int macroId, int arg_no, bool start) } else GenerateIndexEntry(buf); } - return FALSE; + return false; } case ltFCOL: case ltBCOL: @@ -4942,19 +5004,19 @@ bool RTFOnArgument(int macroId, int arg_no, bool start) int pos = FindColourPosition(name); if (pos > -1) { - wxSprintf(buf, _T("{%s%d "), ((macroId == ltFCOL) ? _T("\\cf") : _T("\\cb")), pos); + wxSnprintf(buf, sizeof(buf), _T("{%s%d "), ((macroId == ltFCOL) ? _T("\\cf") : _T("\\cb")), pos); TexOutput(buf); } - else - { - wxSprintf(buf, _T("Could not find colour name %s"), name); + else + { + wxSnprintf(buf, sizeof(buf), _T("Could not find colour name %s"), name); OnError(buf); - } + } break; } case 2: { - return TRUE; + return true; } default: break; @@ -4964,7 +5026,7 @@ bool RTFOnArgument(int macroId, int arg_no, bool start) { if (arg_no == 2) TexOutput(_T("}")); } - return FALSE; + return false; } case ltLABEL: { @@ -4984,7 +5046,7 @@ bool RTFOnArgument(int macroId, int arg_no, bool start) wxFprintf(Chapters, _T("{\\bkmkstart %s}{\\bkmkend %s}"), s,s); } } - return FALSE; + return false; } case ltPAGEREF: { @@ -4994,14 +5056,14 @@ bool RTFOnArgument(int macroId, int arg_no, bool start) wxFprintf(Chapters, _T("{\\field{\\*\\fldinst PAGEREF %s \\\\* MERGEFORMAT }{\\fldrslt ??}}"), s); } - return FALSE; + return false; } case ltPOPREFONLY: { if (start) - inPopRefSection = TRUE; + inPopRefSection = true; else - inPopRefSection = FALSE; + inPopRefSection = false; break; } case ltINSERTATLEVEL: @@ -5009,7 +5071,7 @@ bool RTFOnArgument(int macroId, int arg_no, bool start) // This macro allows you to insert text at a different level // from the current level, e.g. into the Sections from within a subsubsection. if (!winHelp & useWord) - return FALSE; + return false; static int currentLevelNo = 1; static FILE* oldLevelFile = Chapters; if (start) @@ -5054,16 +5116,16 @@ bool RTFOnArgument(int macroId, int arg_no, bool start) } if (outputFile) CurrentOutput1 = outputFile; - return FALSE; + return false; } case 2: { - return TRUE; + return true; } default: break; } - return TRUE; + return true; } else { @@ -5071,207 +5133,208 @@ bool RTFOnArgument(int macroId, int arg_no, bool start) { CurrentOutput1 = oldLevelFile; } - return TRUE; + return true; } } default: return DefaultOnArgument(macroId, arg_no, start); } - return TRUE; + return true; } bool RTFGo(void) { - if (stopRunning) - return FALSE; - - // Reset variables - indentLevel = 0; - forbidParindent = 0; - contentsLineSection = NULL; - contentsLineValue = NULL; - descriptionItemArg = NULL; - inTabular = FALSE; - inTable = FALSE; - inFigure = FALSE; - startRows = FALSE; - tableVerticalLineLeft = FALSE; - tableVerticalLineRight = FALSE; - noColumns = 0; - startedSections = FALSE; - inVerbatim = FALSE; - browseId = 0; - - if (InputFile && OutputFile) - { - // Do some RTF-specific transformations on all the strings, - // recursively - Text2RTF(GetTopLevelChunk()); - - Contents = wxFopen(TmpContentsName, _T("w")); - Chapters = wxFopen(_T("chapters.rtf"), _T("w")); - if (winHelp) - { - Sections = wxFopen(_T("sections.rtf"), _T("w")); - Subsections = wxFopen(_T("subsections.rtf"), _T("w")); - Subsubsections = wxFopen(_T("subsubsections.rtf"), _T("w")); - Popups = wxFopen(_T("popups.rtf"), _T("w")); - if (winHelpContents) - { - WinHelpContentsFile = wxFopen(WinHelpContentsFileName, _T("w")); - if (WinHelpContentsFile) - wxFprintf(WinHelpContentsFile, _T(":Base %s.hlp\n"), wxFileNameFromPath(FileRoot)); - } + if (stopRunning) + return false; + + // Reset variables + indentLevel = 0; + forbidParindent = 0; + contentsLineSection = NULL; + contentsLineValue = NULL; + descriptionItemArg = NULL; + inTabular = false; + inTable = false; + inFigure = false; + startRows = false; + tableVerticalLineLeft = false; + tableVerticalLineRight = false; + noColumns = 0; + startedSections = false; + inVerbatim = false; + browseId = 0; + + if (!InputFile.empty() && !OutputFile.empty()) + { + // Do some RTF-specific transformations on all the strings, + // recursively + Text2RTF(GetTopLevelChunk()); + + Contents = wxFopen(TmpContentsName, _T("w")); + Chapters = wxFopen(_T("chapters.rtf"), _T("w")); + if (winHelp) + { + Sections = wxFopen(_T("sections.rtf"), _T("w")); + Subsections = wxFopen(_T("subsections.rtf"), _T("w")); + Subsubsections = wxFopen(_T("subsubsections.rtf"), _T("w")); + Popups = wxFopen(_T("popups.rtf"), _T("w")); + if (winHelpContents) + { + WinHelpContentsFile = wxFopen(WinHelpContentsFileName, _T("w")); + if (WinHelpContentsFile) + wxFprintf(WinHelpContentsFile, _T(":Base %s.hlp\n"), wxFileNameFromPath(FileRoot)); + } - if (!Sections || !Subsections || !Subsubsections || !Popups || (winHelpContents && !WinHelpContentsFile)) - { - OnError(_T("Ouch! Could not open temporary file(s) for writing.")); - return FALSE; - } - } - if (!Contents || !Chapters) - { - OnError(_T("Ouch! Could not open temporary file(s) for writing.")); - return FALSE; - } + if (!Sections || !Subsections || !Subsubsections || !Popups || (winHelpContents && !WinHelpContentsFile)) + { + OnError(_T("Ouch! Could not open temporary file(s) for writing.")); + return false; + } + } + if (!Contents || !Chapters) + { + OnError(_T("Ouch! Could not open temporary file(s) for writing.")); + return false; + } - if (winHelp) - { - wxFprintf(Chapters, _T("\n#{\\footnote Contents}\n")); - wxFprintf(Chapters, _T("${\\footnote Contents}\n")); - wxFprintf(Chapters, _T("+{\\footnote %s}\n"), GetBrowseString()); - wxFprintf(Chapters, _T("K{\\footnote {K} %s}\n"), ContentsNameString); - wxFprintf(Chapters, _T("!{\\footnote DisableButton(\"Up\")}\n")); - } - if (!winHelp) - { - wxFprintf(Chapters, _T("\\titlepg\n")); - wxFprintf(Contents, _T("\\par\\pard\\pgnrestart\\sect\\titlepg")); - } - - // In WinHelp, Contents title takes font of title. - // In linear RTF, same as chapter headings. - wxFprintf(Contents, _T("{\\b\\fs%d %s}\\par\\par\\pard\n\n"), - (winHelp ? titleFont : chapterFont)*2, ContentsNameString); + if (winHelp) + { + wxFprintf(Chapters, _T("\n#{\\footnote Contents}\n")); + wxFprintf(Chapters, _T("${\\footnote Contents}\n")); + wxFprintf(Chapters, _T("+{\\footnote %s}\n"), GetBrowseString()); + wxFprintf(Chapters, _T("K{\\footnote {K} %s}\n"), ContentsNameString); + wxFprintf(Chapters, _T("!{\\footnote DisableButton(\"Up\")}\n")); + } + if (!winHelp) + { + wxFprintf(Chapters, _T("\\titlepg\n")); + wxFprintf(Contents, _T("\\par\\pard\\pgnrestart\\sect\\titlepg")); + } - // By default, Swiss, 10 point. - wxFprintf(Chapters, _T("\\f2\\fs20\n")); + // In WinHelp, Contents title takes font of title. + // In linear RTF, same as chapter headings. + wxFprintf(Contents, _T("{\\b\\fs%d %s}\\par\\par\\pard\n\n"), + (winHelp ? titleFont : chapterFont)*2, ContentsNameString); - SetCurrentOutput(Chapters); + // By default, Swiss, 11 point. + wxFprintf(Chapters, _T("\\f2\\fs22\n")); - if (stopRunning) - return FALSE; + PushEnvironmentStyle(_T("\\f2\\fs22\\sa200")); - OnInform(_T("Converting...")); + SetCurrentOutput(Chapters); - TraverseDocument(); + if (stopRunning) + return false; - FILE *Header = wxFopen(_T("header.rtf"), _T("w")); - if (!Header) - { - OnError(_T("Ouch! Could not open temporary file header.rtf for writing.")); - return FALSE; - } - WriteRTFHeader(Header); - fclose(Header); - - 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")); - } + OnInform(_T("Converting...")); -// 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; - } - } + TraverseDocument(); - 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); + FILE *Header = wxFopen(_T("header.rtf"), _T("w")); + if (!Header) + { + OnError(_T("Ouch! Could not open temporary file header.rtf for writing.")); + return false; + } + WriteRTFHeader(Header); + fclose(Header); - wxChar *cwdStr; - cwdStr = wxGetWorkingDirectory(); + PopEnvironmentStyle(); - wxString outputDirStr; - outputDirStr = wxPathOnly(OutputFile); + 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")); + } - // 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(outputDirStr.c_str(),_T("")) == 0) || // no path specified on output file - (wxStrcmp(cwdStr,outputDirStr.c_str()) == 0)) // paths do not match - { - wxRenameFile(_T("tmp1.rtf"), OutputFile); - } - else - { - wxCopyFile(_T("tmp1.rtf"), OutputFile); - } - delete [] cwdStr; - Tex2RTFYield(TRUE); - wxRemoveFile(_T("tmp1.rtf")); - } - - if (wxFileExists(ContentsName)) wxRemoveFile(ContentsName); +// 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 (!wxRenameFile(TmpContentsName, ContentsName)) - { - wxCopyFile(TmpContentsName, ContentsName); - wxRemoveFile(TmpContentsName); - } + 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); - 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")); + 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; } - if (winHelp && generateHPJ) - WriteHPJ(OutputFile); - return TRUE; - } - return FALSE; + return false; }