1515#include  " MultiPageVisitor.hpp" 
1616#include  " SinglePageVisitor.hpp" 
1717#include  " lib/Support/LegibleNames.hpp" 
18+ #include  " lib/Support/RawOstream.hpp" 
19+ #include  < llvm/Support/FileSystem.h> 
20+ #include  < llvm/Support/Path.h> 
1821#include  < mrdocs/Metadata/DomMetadata.hpp> 
1922#include  < mrdocs/Support/Error.hpp> 
2023#include  < mrdocs/Support/Path.hpp> 
24+ #include  < fstream> 
2125#include  < optional> 
2226#include  < vector> 
2327
@@ -67,9 +71,34 @@ build(
6771    if (! ex)
6872        return  ex.error ();
6973
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);
7199    visitor (corpus.globalNamespace ());
72100    auto  errors = ex->wait ();
101+     tagfileWriter.finalize ();
73102    if (! errors.empty ())
74103        return  Error (errors);
75104    return  Error::success ();
@@ -79,8 +108,12 @@ Error
79108HTMLGenerator::
80109buildOne (
81110    std::ostream& os,
82-     Corpus const & corpus) const 
111+     Corpus const & corpus,
112+     std::string_view outputPath) const 
83113{
114+     namespace  path  =  llvm::sys::path;
115+     using  SmallString = llvm::SmallString<0 >;
116+     
84117    HTMLCorpus domCorpus (corpus);
85118    auto  ex = createExecutors (domCorpus);
86119    if (! ex)
@@ -98,9 +131,36 @@ buildOne(
98131    if (! errors.empty ())
99132        return  Error (errors);
100133
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);
102161    visitor (corpus.globalNamespace ());
103162    errors = ex->wait ();
163+     tagfileWriter.finalize ();
104164    if (! errors.empty ())
105165        return  Error (errors);
106166
0 commit comments