15
15
#include " MultiPageVisitor.hpp"
16
16
#include " SinglePageVisitor.hpp"
17
17
#include " lib/Support/LegibleNames.hpp"
18
+ #include " lib/Support/RawOstream.hpp"
19
+ #include < llvm/Support/FileSystem.h>
20
+ #include < llvm/Support/Path.h>
18
21
#include < mrdocs/Metadata/DomMetadata.hpp>
19
22
#include < mrdocs/Support/Error.hpp>
20
23
#include < mrdocs/Support/Path.hpp>
24
+ #include < fstream>
21
25
#include < optional>
22
26
#include < vector>
23
27
@@ -67,9 +71,34 @@ build(
67
71
if (! ex)
68
72
return ex.error ();
69
73
70
- MultiPageVisitor visitor (*ex, outputPath, corpus);
74
+ std::string path = files::appendPath (outputPath, " reference.tag.xml" );
75
+ if (auto err = files::createDirectory (outputPath))
76
+ {
77
+ return err;
78
+ }
79
+
80
+ std::ofstream os;
81
+ try
82
+ {
83
+ os.open (path,
84
+ std::ios_base::binary |
85
+ std::ios_base::out |
86
+ std::ios_base::trunc // | std::ios_base::noreplace
87
+ );
88
+ }
89
+ catch (std::exception const & ex)
90
+ {
91
+ return formatError (" std::ofstream(\" {}\" ) threw \" {}\" " , path, ex.what ());
92
+ }
93
+
94
+ RawOstream raw_os (os);
95
+ auto tagfileWriter = TagfileWriter (raw_os, corpus);
96
+ tagfileWriter.initialize ();
97
+
98
+ MultiPageVisitor visitor (*ex, outputPath, corpus, tagfileWriter);
71
99
visitor (corpus.globalNamespace ());
72
100
auto errors = ex->wait ();
101
+ tagfileWriter.finalize ();
73
102
if (! errors.empty ())
74
103
return Error (errors);
75
104
return Error::success ();
@@ -79,8 +108,12 @@ Error
79
108
HTMLGenerator::
80
109
buildOne (
81
110
std::ostream& os,
82
- Corpus const & corpus) const
111
+ Corpus const & corpus,
112
+ std::string_view outputPath) const
83
113
{
114
+ namespace path = llvm::sys::path;
115
+ using SmallString = llvm::SmallString<0 >;
116
+
84
117
HTMLCorpus domCorpus (corpus);
85
118
auto ex = createExecutors (domCorpus);
86
119
if (! ex)
@@ -98,9 +131,36 @@ buildOne(
98
131
if (! errors.empty ())
99
132
return Error (errors);
100
133
101
- SinglePageVisitor visitor (*ex, corpus, os);
134
+ SmallString fileName (outputPath);
135
+ path::replace_extension (fileName, " tag.xml" );
136
+ auto parentDir = files::getParentDir (fileName.str ());
137
+ if (auto err = files::createDirectory (parentDir))
138
+ {
139
+ return err;
140
+ }
141
+
142
+ std::ofstream osTagfile;
143
+ try
144
+ {
145
+ osTagfile.open (fileName.str ().str (),
146
+ std::ios_base::binary |
147
+ std::ios_base::out |
148
+ std::ios_base::trunc // | std::ios_base::noreplace
149
+ );
150
+ }
151
+ catch (std::exception const & ex)
152
+ {
153
+ return formatError (" std::ofstream(\" {}\" ) threw \" {}\" " , fileName.str ().str (), ex.what ());
154
+ }
155
+
156
+ RawOstream raw_os (osTagfile);
157
+ auto tagfileWriter = TagfileWriter (raw_os, corpus);
158
+ tagfileWriter.initialize ();
159
+
160
+ SinglePageVisitor visitor (*ex, corpus, os, outputPath, tagfileWriter);
102
161
visitor (corpus.globalNamespace ());
103
162
errors = ex->wait ();
163
+ tagfileWriter.finalize ();
104
164
if (! errors.empty ())
105
165
return Error (errors);
106
166
0 commit comments