X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/aed0ed3c420d6821e81ca6243482e620c4aeeffd..4b04699b670b4ab4632229fa0264d154acd3bec1:/utils/tex2rtf/src/rtfutils.cpp diff --git a/utils/tex2rtf/src/rtfutils.cpp b/utils/tex2rtf/src/rtfutils.cpp index dfd45ccde9..a33c1628b8 100644 --- a/utils/tex2rtf/src/rtfutils.cpp +++ b/utils/tex2rtf/src/rtfutils.cpp @@ -58,6 +58,9 @@ extern FILE *WinHelpContentsFile; extern char *RTFCharset; // This is defined in the Tex2Any library and isn't in use after parsing extern char *BigBuffer; + +extern wxHashTable TexReferences; + // Are we in verbatim mode? If so, format differently. static bool inVerbatim = FALSE; @@ -90,6 +93,8 @@ static int TwoColWidthB = 3000; const int PageWidth = 12242; // 8.25 inches wide for A4 +// Remember the anchor in a helpref +static TexChunk *helpRefText = NULL; /* * Flag to say we've just issued a \par\pard command, so don't @@ -208,18 +213,18 @@ void ResetContentsLevels(int l) // : for space. void OutputSectionKeyword(FILE *fd) { - OutputCurrentSectionToString(wxBuffer); + OutputCurrentSectionToString(wxTex2RTFBuffer); - int i; - for (i = 0; i < strlen(wxBuffer); i++) - if (wxBuffer[i] == ':') - wxBuffer[i] = ' '; + unsigned int i; + for (i = 0; i < strlen(wxTex2RTFBuffer); i++) + if (wxTex2RTFBuffer[i] == ':') + wxTex2RTFBuffer[i] = ' '; // Don't write to index if there's some RTF in the string - else if ( wxBuffer[i] == '{' ) + else if ( wxTex2RTFBuffer[i] == '{' ) return; fprintf(fd, "K{\\footnote {K} "); - fprintf(fd, "%s", wxBuffer); + fprintf(fd, "%s", wxTex2RTFBuffer); fprintf(fd, "}\n"); } @@ -349,7 +354,7 @@ void GenerateKeywordsForTopic(char *topic) SplitIndexEntry(s, buf1, buf2); // Check for ':' which messes up index - int i; + unsigned int i; for (i = 0; i < strlen(buf1) ; i++) if (buf1[i] == ':') buf1[i] = ' '; @@ -540,7 +545,7 @@ bool WriteHPJ(char *filename) if (thePath.IsEmpty()) thePath = "."; fprintf(fd, "[OPTIONS]\n"); - fprintf(fd, "BMROOT=%s ; Assume that bitmaps are where the source is\n", thePath); + fprintf(fd, "BMROOT=%s ; Assume that bitmaps are where the source is\n", thePath.c_str()); fprintf(fd, "TITLE=%s\n", helpTitle); fprintf(fd, "CONTENTS=Contents\n"); @@ -662,7 +667,7 @@ void ProcessText2RTF(TexChunk *chunk) i += 1; changed = TRUE; } - else if (inVerbatim && (ch == '{' || ch == '}')) // Escape the curly bracket + else if (inVerbatim && (ch == '{' || ch == '}')) // Escape the curley bracket { BigBuffer[ptr] = '\\'; ptr ++; BigBuffer[ptr] = ch; ptr ++; @@ -1108,8 +1113,8 @@ void RTFOnMacro(int macroId, int no_args, bool start) if (winHelpContents && winHelp && !InPopups()) { - OutputCurrentSectionToString(wxBuffer); - WriteWinHelpContentsFileLine(topicName, wxBuffer, 1); + OutputCurrentSectionToString(wxTex2RTFBuffer); + WriteWinHelpContentsFileLine(topicName, wxTex2RTFBuffer, 1); } AddTexRef(topicName, NULL, ChapterNameString, chapterNo); @@ -1250,8 +1255,8 @@ void RTFOnMacro(int macroId, int no_args, bool start) NotifyParentHasChildren(1); if (winHelpContents && winHelp && !InPopups()) { - OutputCurrentSectionToString(wxBuffer); - WriteWinHelpContentsFileLine(topicName, wxBuffer, 2); + OutputCurrentSectionToString(wxTex2RTFBuffer); + WriteWinHelpContentsFileLine(topicName, wxTex2RTFBuffer, 2); } AddTexRef(topicName, NULL, SectionNameString, chapterNo, sectionNo); @@ -1434,8 +1439,8 @@ void RTFOnMacro(int macroId, int no_args, bool start) NotifyParentHasChildren(2); if (winHelpContents && winHelp && !InPopups()) { - OutputCurrentSectionToString(wxBuffer); - WriteWinHelpContentsFileLine(topicName, wxBuffer, 3); + OutputCurrentSectionToString(wxTex2RTFBuffer); + WriteWinHelpContentsFileLine(topicName, wxTex2RTFBuffer, 3); } AddTexRef(topicName, NULL, SectionNameString, chapterNo, sectionNo, subsectionNo); @@ -1584,8 +1589,8 @@ void RTFOnMacro(int macroId, int no_args, bool start) NotifyParentHasChildren(3); if (winHelpContents && winHelp) { - OutputCurrentSectionToString(wxBuffer); - WriteWinHelpContentsFileLine(topicName, wxBuffer, 4); + OutputCurrentSectionToString(wxTex2RTFBuffer); + WriteWinHelpContentsFileLine(topicName, wxTex2RTFBuffer, 4); } AddTexRef(topicName, NULL, SectionNameString, chapterNo, sectionNo, subsectionNo, subsubsectionNo); @@ -3338,46 +3343,61 @@ bool RTFOnArgument(int macroId, int arg_no, bool start) TexOutput("{\\i "); else TexOutput("}"); + + if (start) + helpRefText = GetArgChunk(); + return TRUE; } else if ((GetNoArgs() - arg_no) == 0) // Arg = 2, or 3 if first is optional { if (macroId != ltHELPREFN) { + char *refName = GetArgData(); + TexRef *texRef = NULL; + if (refName) + texRef = FindReference(refName); if (start) { - TexOutput(" ("); - char *refName = GetArgData(); + if (texRef || !ignoreBadRefs) + TexOutput(" ("); if (refName) { - if (useWord) + if (texRef || !ignoreBadRefs) { - char *s = GetArgData(); - TexOutput("p. "); - TexOutput("{\\field{\\*\\fldinst PAGEREF "); - TexOutput(refName); - TexOutput(" \\\\* MERGEFORMAT }{\\fldrslt ??}}"); - } - else - { - // Only print section name if we're not in Word mode, - // so can't do page references - TexRef *texRef = FindReference(refName); - if (texRef) + if (useWord) { - TexOutput(texRef->sectionName) ; TexOutput(" "); TexOutput(texRef->sectionNumber); + char *s = GetArgData(); + TexOutput("p. "); + TexOutput("{\\field{\\*\\fldinst PAGEREF "); + TexOutput(refName); + TexOutput(" \\\\* MERGEFORMAT }{\\fldrslt ??}}"); } else { - TexOutput("??"); - sprintf(buf, "Warning: unresolved reference %s.", refName); - OnInform(buf); + // Only print section name if we're not in Word mode, + // so can't do page references + if (texRef) + { + TexOutput(texRef->sectionName) ; TexOutput(" "); TexOutput(texRef->sectionNumber); + } + else + { + if (!ignoreBadRefs) + TexOutput("??"); + sprintf(buf, "Warning: unresolved reference '%s'", refName); + OnInform(buf); + } } } } else TexOutput("??"); } - else TexOutput(")"); + else + { + if (texRef || !ignoreBadRefs) + TexOutput(")"); + } } return FALSE; } @@ -3482,6 +3502,8 @@ bool RTFOnArgument(int macroId, int arg_no, bool start) // Convert points to TWIPS (1 twip = 1/20th of point) imageWidth = (int)(20*(tok1 ? ParseUnitArgument(tok1) : 0)); imageHeight = (int)(20*(tok2 ? ParseUnitArgument(tok2) : 0)); + if (imageDimensions) // glt + delete [] imageDimensions; return FALSE; } else if (start && (arg_no == 2 )) @@ -3556,6 +3578,8 @@ bool RTFOnArgument(int macroId, int arg_no, bool start) sprintf(buf, "Warning: could not find a BMP or WMF equivalent for %s.", filename); OnInform(buf); } + if (filename) // glt + delete [] filename; } else // linear RTF { @@ -5081,6 +5105,9 @@ bool RTFOnArgument(int macroId, int arg_no, bool start) bool RTFGo(void) { + if (stopRunning) + return FALSE; + // Reset variables indentLevel = 0; forbidParindent = 0; @@ -5155,6 +5182,9 @@ bool RTFGo(void) SetCurrentOutput(Chapters); + if (stopRunning) + return FALSE; + OnInform("Converting..."); TraverseDocument(); @@ -5218,8 +5248,28 @@ bool RTFGo(void) { wxConcatFiles("header.rtf", "chapters.rtf", "tmp1.rtf"); Tex2RTFYield(TRUE); - if (FileExists(OutputFile)) wxRemoveFile(OutputFile); - wxCopyFile("tmp1.rtf", OutputFile); + if (FileExists(OutputFile)) + wxRemoveFile(OutputFile); + + char *cwdStr; + cwdStr = wxGetWorkingDirectory(); + + wxString outputDirStr; + outputDirStr = wxPathOnly(OutputFile); + + // Determine if the temp file and the output file are in the same directory, + // and if they are, then just rename the temp file rather than copying + // it, as this is much faster when working with large (multi-megabyte files) + if ((wxStrcmp(outputDirStr.c_str(),"") == 0) || // no path specified on output file + (wxStrcmp(cwdStr,outputDirStr.c_str()) == 0)) // paths do not match + { + wxRenameFile("tmp1.rtf", OutputFile); + } + else + { + wxCopyFile("tmp1.rtf", OutputFile); + } + delete [] cwdStr; Tex2RTFYield(TRUE); wxRemoveFile("tmp1.rtf"); }