Skip to content

Commit

Permalink
Delay removing files in case of RTF till end of process
Browse files Browse the repository at this point in the history
In case we include a file by means of a `\rtfonly` section like:
```
\rtfonly
\par \pard\plain
{\field\fldedit{\*\fldinst INCLUDETEXT "inc_aa.rtf" \\*MERGEFORMAT}{\fldrslt includedstuff}}
\endrtfonly
```
or
```
\rtfonly
\par \pard\plain
{\field\fldedit{\*\fldinst INCLUDETEXT "../inc_aa1.rtf" \\*MERGEFORMAT}{\fldrslt includedstuff}}
\endrtfonly
```

we get errors when a file is included multiple times or for the relative link on the second invocation as the files are removed directly after been included.
This is not desirable.
- remove files just at the end of the merging process
- only remove files in the `RTF_OUTPUT` directory (this will contain only "generated / copied" files)
- create possibility to have "RTF_EXTRA_FILES` analogous to the HTML and LATEX counterparts.
  • Loading branch information
albert-github committed Apr 11, 2024
1 parent aa55cc8 commit fa30e8e
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
11 changes: 11 additions & 0 deletions src/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3328,6 +3328,17 @@ The following block name is set based on whether or not a feature is used in the
Syntax is similar to doxygen's configuration file.
A template extensions file can be generated using
<code>doxygen -e rtf extensionFile</code>.
]]>
</docs>
</option>
<option type='list' id='RTF_EXTRA_FILES' format='file' depends='GENERATE_RTF'>
<docs>
<![CDATA[
The \c RTF_EXTRA_FILES tag can be used to specify one or more extra images
or other source files which should be copied to the \ref cfg_rtf_output "RTF_OUTPUT"
output directory.
Note that the files will be copied as-is; there are no commands or markers
available.
]]>
</docs>
</option>
Expand Down
1 change: 1 addition & 0 deletions src/doxygen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12544,6 +12544,7 @@ void generateOutput()
{
copyLogo(Config_getString(RTF_OUTPUT));
copyIcon(Config_getString(RTF_OUTPUT));
copyExtraFiles(Config_getList(RTF_EXTRA_FILES),"RTF_EXTRA_FILES",Config_getString(RTF_OUTPUT));
}

FormulaManager &fm = FormulaManager::instance();
Expand Down
18 changes: 14 additions & 4 deletions src/rtfgen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@
//#define DBG_RTF(x) x;
#define DBG_RTF(x)

static StringSet removeSet;

static QCString dateToRTFDateString()
{
auto tm = getCurrentDateTime();
Expand Down Expand Up @@ -2204,7 +2206,7 @@ static void encodeForOutput(TextStream &t,const QCString &s)
* VERY brittle routine inline RTF's included by other RTF's.
* it is recursive and ugly.
*/
static bool preProcessFile(Dir &d,const QCString &infName, TextStream &t, bool bIncludeHeader=TRUE)
static bool preProcessFile(Dir &d,const QCString &infName, TextStream &t, bool bIncludeHeader=true, bool removeFile = true)
{
static bool rtfDebug = Debug::isFlagSet(Debug::Rtf);
std::ifstream f = Portable::openInputStream(infName);
Expand Down Expand Up @@ -2267,7 +2269,7 @@ static bool preProcessFile(Dir &d,const QCString &infName, TextStream &t, bool b
}
f.close();
// remove temporary file
if (!rtfDebug) d.remove(infName.str());
if (!rtfDebug && removeFile) removeSet.insert(FileInfo(d.filePath(infName.str())).absFilePath());
return TRUE;
}

Expand Down Expand Up @@ -2419,6 +2421,8 @@ void testRTFOutput(const QCString &name)
bool RTFGenerator::preProcessFileInplace(const QCString &path,const QCString &name)
{
static bool rtfDebug = Debug::isFlagSet(Debug::Rtf);
QCString rtfOutput = Config_getString(RTF_OUTPUT);

Dir d(path.str());
// store the original directory
if (!d.exists())
Expand All @@ -2444,12 +2448,12 @@ bool RTFGenerator::preProcessFileInplace(const QCString &path,const QCString &na
}
TextStream outt(&f);

if (!preProcessFile(thisDir,mainRTFName,outt))
if (!preProcessFile(thisDir,mainRTFName,outt,true,false))
{
// it failed, remove the temp file
outt.flush();
f.close();
if (!rtfDebug) thisDir.remove(combinedName.str());
if (!rtfDebug) removeSet.insert(FileInfo(thisDir.filePath(combinedName.str())).absFilePath());
Dir::setCurrent(oldDir);
return FALSE;
}
Expand All @@ -2469,6 +2473,12 @@ bool RTFGenerator::preProcessFileInplace(const QCString &path,const QCString &na

testRTFOutput(mainRTFName);

for (auto &s : removeSet)
{
QCString s1(s.c_str());
if (s1.startsWith(rtfOutput)) Portable::unlink(s1);
}

Dir::setCurrent(oldDir);
return TRUE;
}
Expand Down

0 comments on commit fa30e8e

Please sign in to comment.