X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/04b9c5bb04bfa5470997667993f849e25fc5e869..f2638c97a5d7c4bf724c5c227e273ab002f0af40:/utils/tex2rtf/src/rtfutils.cpp diff --git a/utils/tex2rtf/src/rtfutils.cpp b/utils/tex2rtf/src/rtfutils.cpp index 49c710c82a..e4e08c30bb 100644 --- a/utils/tex2rtf/src/rtfutils.cpp +++ b/utils/tex2rtf/src/rtfutils.cpp @@ -59,10 +59,8 @@ 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; @@ -95,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 @@ -213,18 +213,18 @@ void ResetContentsLevels(int l) // : for space. void OutputSectionKeyword(FILE *fd) { - OutputCurrentSectionToString(wxBuffer); + OutputCurrentSectionToString(wxTex2RTFBuffer); unsigned int i; - for (i = 0; i < strlen(wxBuffer); i++) - if (wxBuffer[i] == ':') - wxBuffer[i] = ' '; + for (i = 0; i < strlen(wxTex2RTFBuffer); i++) + if (wxTex2RTFBuffer[i] == ':') + wxTex2RTFBuffer[i] = ' '; // Don't write to index if there's some RTF in the string - else if ( wxBuffer[i] == '{' ) + else if ( wxTex2RTFBuffer[i] == '{' ) return; fprintf(fd, "K{\\footnote {K} "); - fprintf(fd, "%s", wxBuffer); + fprintf(fd, "%s", wxTex2RTFBuffer); fprintf(fd, "}\n"); } @@ -527,7 +527,7 @@ bool WriteHPJ(char *filename) StripExtension(hpjFilename); strcat(hpjFilename, ".hpj"); - strcpy(helpFile, FileNameFromPath(filename)); + strcpy(helpFile, wxFileNameFromPath(filename)); StripExtension(helpFile); strcpy(rtfFile, helpFile); strcat(helpFile, ".hlp"); @@ -1113,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); @@ -1195,7 +1195,7 @@ void RTFOnMacro(int macroId, int no_args, bool start) fprintf(Chapters, "!{\\footnote DisableButton(\"Up\")}\n"); else fprintf(Chapters, "!{\\footnote EnableButton(\"Up\");ChangeButtonBinding(\"Up\", \"JumpId(`%s.hlp', `%s')\")}\n", - FileNameFromPath(FileRoot), "Contents"); + wxFileNameFromPath(FileRoot), "Contents"); } } @@ -1255,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); @@ -1350,12 +1350,12 @@ void RTFOnMacro(int macroId, int no_args, bool start) if (DocumentStyle == LATEX_ARTICLE) { fprintf(Sections, "!{\\footnote EnableButton(\"Up\");ChangeButtonBinding(\"Up\", \"JumpId(`%s.hlp', `%s')\")}\n", - FileNameFromPath(FileRoot), "Contents"); + wxFileNameFromPath(FileRoot), "Contents"); } else if (CurrentChapterName) { fprintf(Sections, "!{\\footnote EnableButton(\"Up\");ChangeButtonBinding(\"Up\", \"JumpId(`%s.hlp', `%s')\")}\n", - FileNameFromPath(FileRoot), CurrentChapterName); + wxFileNameFromPath(FileRoot), CurrentChapterName); } } } @@ -1439,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); @@ -1501,7 +1501,7 @@ void RTFOnMacro(int macroId, int no_args, bool start) if (useUpButton && CurrentSectionName) { fprintf(Subsections, "!{\\footnote EnableButton(\"Up\");ChangeButtonBinding(\"Up\", \"JumpId(`%s.hlp', `%s')\")}\n", - FileNameFromPath(FileRoot), CurrentSectionName); + wxFileNameFromPath(FileRoot), CurrentSectionName); } } if (!winHelp && indexSubsections && useWord) @@ -1589,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); @@ -1647,7 +1647,7 @@ void RTFOnMacro(int macroId, int no_args, bool start) if (useUpButton && CurrentSubsectionName) { fprintf(Subsubsections, "!{\\footnote EnableButton(\"Up\");ChangeButtonBinding(\"Up\", \"JumpId(`%s.hlp', `%s')\")}\n", - FileNameFromPath(FileRoot), CurrentSubsectionName); + wxFileNameFromPath(FileRoot), CurrentSubsectionName); } } if (!winHelp && indexSubsections && useWord) @@ -2205,7 +2205,6 @@ void RTFOnMacro(int macroId, int no_args, bool start) { struc->currentItem += 1; - int indentSize = struc->indentation; int oldIndent = 0; wxNode *node2 = NULL; if (itemizeStack.Number() > 1) // TODO: do I actually mean Nth(0) here?? @@ -3343,46 +3342,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; } @@ -4883,7 +4897,7 @@ bool RTFOnArgument(int macroId, int arg_no, bool start) if (useUpButton) { fprintf(Chapters, "!{\\footnote EnableButton(\"Up\");ChangeButtonBinding(\"Up\", \"JumpId(`%s.hlp', `%s')\")}\n", - FileNameFromPath(FileRoot), "Contents"); + wxFileNameFromPath(FileRoot), "Contents"); } } @@ -5233,7 +5247,7 @@ bool RTFGo(void) { wxConcatFiles("header.rtf", "chapters.rtf", "tmp1.rtf"); Tex2RTFYield(TRUE); - if (FileExists(OutputFile)) + if (wxFileExists(OutputFile)) wxRemoveFile(OutputFile); char *cwdStr; @@ -5259,7 +5273,7 @@ bool RTFGo(void) wxRemoveFile("tmp1.rtf"); } - if (FileExists(ContentsName)) wxRemoveFile(ContentsName); + if (wxFileExists(ContentsName)) wxRemoveFile(ContentsName); if (!wxRenameFile(TmpContentsName, ContentsName)) {