X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/7f9975410ff186cd35dc770a5981950f0c861f70..a3c8c017cf6cf74dbc89b6c93f6f872e45c74cad:/utils/tex2rtf/src/rtfutils.cpp diff --git a/utils/tex2rtf/src/rtfutils.cpp b/utils/tex2rtf/src/rtfutils.cpp index 2c4ec17613..6dc426cdba 100644 --- a/utils/tex2rtf/src/rtfutils.cpp +++ b/utils/tex2rtf/src/rtfutils.cpp @@ -10,10 +10,6 @@ // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// -#ifdef __GNUG__ -#pragma implementation -#endif - // For compilers that support precompilation, includes "wx.h". #include "wx/wxprec.h" @@ -208,7 +204,7 @@ void ResetContentsLevels(int l) int i; for (i = l; i < 5; i++) ContentsLevels[i] = false; - + // There are always books on the top level ContentsLevels[0] = true; } @@ -218,7 +214,7 @@ void ResetContentsLevels(int l) void OutputSectionKeyword(FILE *fd) { OutputCurrentSectionToString(wxTex2RTFBuffer); - + unsigned int i; for (i = 0; i < wxStrlen(wxTex2RTFBuffer); i++) if (wxTex2RTFBuffer[i] == ':') @@ -229,7 +225,7 @@ void OutputSectionKeyword(FILE *fd) wxFprintf(fd, _T("K{\\footnote {K} ")); wxFprintf(fd, _T("%s"), wxTex2RTFBuffer); - + wxFprintf(fd, _T("}\n")); } @@ -240,24 +236,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; + wxChar ch=wxChar(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++]=_T('ö'); } - if ((ch1==0x27)&&(ch2==0x65)&&(ch3==0x34)) { title[d++]=_T('ä'); } - if ((ch1==0x27)&&(ch2==0x66)&&(ch3==0x63)) { title[d++]=_T('ü'); } - if ((ch1==0x27)&&(ch2==0x64)&&(ch3==0x36)) { title[d++]=_T('Ö'); } - if ((ch1==0x27)&&(ch2==0x63)&&(ch3==0x34)) { title[d++]=_T('Ä'); } - if ((ch1==0x27)&&(ch2==0x64)&&(ch3==0x63)) { title[d++]=_T('Ü'); } + 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; @@ -267,12 +264,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); @@ -352,7 +346,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++) @@ -382,7 +376,7 @@ void GenerateKeywordsForTopic(wxChar *topic) * Output index entry in linear RTF * */ - + void GenerateIndexEntry(wxChar *entry) { if (useWord) @@ -405,7 +399,7 @@ void GenerateIndexEntry(wxChar *entry) * Write a suitable RTF header. * */ - + void WriteColourTable(FILE *fd) { wxFprintf(fd, _T("{\\colortbl")); @@ -457,7 +451,7 @@ 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 */ @@ -474,7 +468,7 @@ void WriteRTFHeader(FILE *fd) // 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")); @@ -522,66 +516,66 @@ void OutputNumberStyle(wxChar *numberStyle) /* * Write a Windows help project file */ - -bool WriteHPJ(wxChar *filename) + +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 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")); + wxChar *helpTitle = winHelpTitle; + if (!helpTitle) + helpTitle = _T("Untitled"); - if (winHelpVersion > 3) - { - wxFprintf(fd, _T("[WINDOWS]\n")); - wxFprintf(fd, _T("Main=\"\",(553,102,400,600),20736,(r14876671),(r12632256),f3\n")); + 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; } @@ -673,7 +667,7 @@ void ProcessText2RTF(TexChunk *chunk) i += 1; 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 ++; @@ -703,7 +697,7 @@ void ProcessText2RTF(TexChunk *chunk) * and before TraverseDocument is called. * */ - + void Text2RTF(TexChunk *chunk) { Tex2RTFYield(); @@ -758,7 +752,7 @@ void Text2RTF(TexChunk *chunk) * Not used yet * */ - + wxChar browseBuf[10]; static long browseId = 0; wxChar *GetBrowseString(void) @@ -879,7 +873,7 @@ void OutputRTFHeaderCommands(void) { int oldForbidResetPar = forbidResetPar; forbidResetPar = 0; - + if (LeftHeaderEven || CentreHeaderEven || RightHeaderEven) { TexOutput(_T("{\\headerl\\fi0 ")); @@ -1147,7 +1141,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); @@ -1168,14 +1162,14 @@ void RTFOnMacro(int macroId, int no_args, bool start) else SetCurrentOutput(NULL); // No entry in table of contents } } - + startedSections = true; // Output heading to contents page if (!InPopups()) { OutputCurrentSection(); - + if (winHelp) { wxFprintf(Contents, _T("}{\\v %s}\\pard\\par\n"), topicName); @@ -1187,12 +1181,12 @@ void RTFOnMacro(int macroId, int no_args, bool start) // 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); @@ -1318,7 +1312,7 @@ void RTFOnMacro(int macroId, int no_args, bool start) } } else SetCurrentOutput(NULL); - } + } if (startedSections) { @@ -1349,7 +1343,7 @@ void RTFOnMacro(int macroId, int no_args, bool start) else wxFprintf(Contents, _T("}\\par\\par\\pard\n")); } - + SetCurrentOutput(winHelp ? Sections : Chapters); if (winHelp) @@ -1386,7 +1380,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); @@ -1490,7 +1484,7 @@ void RTFOnMacro(int macroId, int no_args, bool start) #if 0 else wxFprintf(Chapters, _T("\\par\n")); -#endif +#endif } startedSections = true; @@ -1585,7 +1579,7 @@ void RTFOnMacro(int macroId, int no_args, bool start) } } OutputCurrentSection(); // Repeat section header - + // Experimental JACS TexOutput(_T("\\par\\pard}\n")); // TexOutput(_T("\\par\\pard}\\par\n")); @@ -1641,7 +1635,7 @@ void RTFOnMacro(int macroId, int no_args, bool start) else SetCurrentOutput(NULL); // Don't write it into the contents, or anywhere else } - + if (startedSections) { if (winHelp) @@ -1650,7 +1644,7 @@ void RTFOnMacro(int macroId, int no_args, bool start) #if 0 else wxFprintf(Chapters, _T("\\par\n")); -#endif +#endif } startedSections = true; @@ -1668,7 +1662,7 @@ void RTFOnMacro(int macroId, int no_args, bool start) } else if ((DocumentStyle == LATEX_ARTICLE) && (macroId != ltSUBSUBSECTIONSTAR)) wxFprintf(Contents, _T("\\par\\pard\n")); - + SetCurrentOutput(winHelp ? Subsubsections : Chapters); if (winHelp) { @@ -1708,7 +1702,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)) @@ -2003,7 +1997,7 @@ void RTFOnMacro(int macroId, int no_args, bool start) if (TableData[i].leftBorder) TexOutput(_T("\\clbrdrl\\brdrs\\brdrw15")); - + wxSnprintf(buf, sizeof(buf), _T("\\cellx%d"), currentWidth); TexOutput(buf); } @@ -2072,7 +2066,7 @@ void RTFOnMacro(int macroId, int no_args, bool start) ItemizeStruc *struc = new ItemizeStruc(listType, indentSize2, indentSize1); itemizeStack.Insert(struc); - + wxSnprintf(buf, sizeof(buf), _T("\\tx%d\\tx%d\\li%d\\sa200"), indentSize1, indentSize2, indentSize2); PushEnvironmentStyle(buf); } @@ -2113,7 +2107,7 @@ void RTFOnMacro(int macroId, int no_args, bool start) ItemizeStruc *struc = new ItemizeStruc(LATEX_TWOCOL, indentSize); itemizeStack.Insert(struc); - + // 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); @@ -2143,7 +2137,7 @@ void RTFOnMacro(int macroId, int no_args, bool start) OnMacro(ltPAR, 0, true); OnMacro(ltPAR, 0, false); } -#endif +#endif } break; } @@ -2266,7 +2260,7 @@ void RTFOnMacro(int macroId, int no_args, bool start) // WriteEnvironmentStyles(); } -#endif +#endif // wxSnprintf(buf, sizeof(buf), _T("\\tx%d\\li%d\\fi-%d\\ri%d\n"), TwoColWidthA, // TwoColWidthA, TwoColWidthA, TwoColWidthA+TwoColWidthB+oldIndent); @@ -2299,7 +2293,7 @@ void RTFOnMacro(int macroId, int no_args, bool start) else issuedNewParagraph = 0; } #endif - + if (macroId == ltVERBATIM) wxSnprintf(buf, sizeof(buf), _T("{\\f3\\s10\\fs20\\li720\\sa0 ")); else @@ -2317,7 +2311,7 @@ void RTFOnMacro(int macroId, int no_args, bool start) #if 0 TexOutput(_T("\\par\n")); issuedNewParagraph = 1; -#endif +#endif } } break; @@ -2508,7 +2502,7 @@ void RTFOnMacro(int macroId, int no_args, bool start) case ltRMFAMILY: case ltRM: { -/* +/* if (start) { TexOutput(_T("{\\plain ")); @@ -2585,7 +2579,7 @@ void RTFOnMacro(int macroId, int no_args, bool start) { TexOutput(_T("\\par\\pard")); issuedNewParagraph ++; - + // Extra par if parskip is more than zero (usually looks best.) // N.B. JACS 2004-02-21: shouldn't need this for linear RTF if // we have a suitable set of styles. @@ -2595,7 +2589,7 @@ void RTFOnMacro(int macroId, int no_args, bool start) TexOutput(_T("\\par")); issuedNewParagraph ++; } -#endif +#endif WriteEnvironmentStyles(); } // 1 is a whole paragraph if ParSkip == 0, @@ -2611,7 +2605,7 @@ void RTFOnMacro(int macroId, int no_args, bool start) TexOutput(_T("\\par")); issuedNewParagraph ++; } -#endif +#endif WriteEnvironmentStyles(); } /* @@ -3231,7 +3225,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)) @@ -3339,7 +3333,7 @@ bool RTFOnArgument(int macroId, int arg_no, bool start) if (start) { wxChar *sec = NULL; - + wxChar *refName = GetArgData(); if (winHelp || !useWord) { @@ -3547,10 +3541,10 @@ bool RTFOnArgument(int macroId, int arg_no, bool start) { if (arg_no == 3) return false; - + static int imageWidth = 0; static int imageHeight = 0; - + if (start && (arg_no == 1)) { wxChar *imageDimensions = copystring(GetArgData()); @@ -3581,7 +3575,7 @@ bool RTFOnArgument(int macroId, int arg_no, bool start) if (imageDimensions) // glt delete [] imageDimensions; return false; - } + } else if (start && (arg_no == 2 )) { wxChar *filename = copystring(GetArgData()); @@ -3702,7 +3696,7 @@ bool RTFOnArgument(int macroId, int arg_no, bool start) } else { -#endif +#endif TexOutput(_T("[No BMP or WMF for image file ")); TexOutput(filename); TexOutput(_T("]")); @@ -4476,7 +4470,7 @@ bool RTFOnArgument(int macroId, int arg_no, bool start) if (currentNumberStyle) delete[] currentNumberStyle; currentNumberStyle = copystring(data); OutputNumberStyle(currentNumberStyle); - + TexOutput(_T("\n")); } return false; @@ -4687,7 +4681,7 @@ bool RTFOnArgument(int macroId, int arg_no, bool start) if (TableData[i].leftBorder) TexOutput(_T("\\clbrdrl\\brdrs\\brdrw15")); - + wxSnprintf(buf, sizeof(buf), _T("\\cellx%d"), currentWidth); TexOutput(buf); } @@ -4753,7 +4747,7 @@ bool RTFOnArgument(int macroId, int arg_no, bool start) ItemizeStruc *struc = new ItemizeStruc(LATEX_INDENT, indentSize); itemizeStack.Insert(struc); - + wxSnprintf(buf, sizeof(buf), _T("\\tx%d\\li%d\\sa200 "), indentSize, indentSize); PushEnvironmentStyle(buf); TexOutput(buf); @@ -4796,7 +4790,7 @@ bool RTFOnArgument(int macroId, int arg_no, bool start) ItemizeStruc *struc = new ItemizeStruc(LATEX_INDENT, indentSize); itemizeStack.Insert(struc); - + 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); @@ -4920,7 +4914,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); @@ -4960,7 +4954,7 @@ bool RTFOnArgument(int macroId, int arg_no, bool start) wxFileNameFromPath(FileRoot), "Contents"); } } - + SetCurrentOutput(Chapters); wxChar *styleCommand = _T(""); if (!winHelp && useHeadingStyles) @@ -5152,200 +5146,197 @@ bool RTFOnArgument(int macroId, int arg_no, bool start) bool RTFGo(void) { - if (stopRunning) - return false; + 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)); - } + // 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, 11 point. - wxFprintf(Chapters, _T("\\f2\\fs22\n")); - - PushEnvironmentStyle(_T("\\f2\\fs22\\sa200")); + // 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); + OnInform(_T("Converting...")); - 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")); - } + TraverseDocument(); -// 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; - } - } + 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); - 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); + PopEnvironmentStyle(); - wxChar *cwdStr; - cwdStr = wxGetWorkingDirectory(); + 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")); + } - wxString outputDirStr; - outputDirStr = wxPathOnly(OutputFile); +// 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; + } + } - // 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); + 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); - if (!wxRenameFile(TmpContentsName, ContentsName)) - { - wxCopyFile(TmpContentsName, ContentsName); - wxRemoveFile(TmpContentsName); - } + wxString cwdStr = wxGetCwd(); - 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 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; }