merge the formfield patch from ooo-build
[ooovba.git] / autodoc / source / exes / adc_uni / cmd_run.cxx
blobf6cd42968fb53fb05b1bbc0f1559f334e526e479
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: cmd_run.cxx,v $
10 * $Revision: 1.12 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #include <precomp.h>
32 #include "cmd_run.hxx"
35 // NOT FULLY DEFINED SERVICES
36 #include <cosv/file.hxx>
37 #include <cosv/x.hxx>
38 #include <ary/ary.hxx>
39 #include <ary/cpp/c_gate.hxx>
40 #include <ary/idl/i_ce.hxx>
41 #include <ary/idl/i_gate.hxx>
42 #include <ary/idl/i_module.hxx>
43 #include <ary/idl/ip_ce.hxx>
44 #include <autodoc/filecoli.hxx>
45 #include <autodoc/parsing.hxx>
46 #include <autodoc/prs_code.hxx>
47 #include <autodoc/prs_docu.hxx>
48 #include <parser/unoidl.hxx>
49 #include <adc_cl.hxx>
50 #include "adc_cmd_parse.hxx"
51 #include "adc_cmds.hxx"
53 namespace autodoc
55 namespace command
57 namespace run
60 Parser::Parser( const Parse & i_command )
61 : rCommand(i_command),
62 pCppParser(),
63 pCppDocuInterpreter(),
64 pIdlParser()
68 Parser::~Parser()
72 bool
73 Parser::Perform()
75 Cout() << "Parsing the repository "
76 << rCommand.ReposyName()
77 << " ..."
78 << Endl();
79 try
81 ::ary::Repository &
82 rAry = CommandLine::Get_().TheRepository();
83 rAry.Set_Title(rCommand.ReposyName());
85 Dyn< FileCollector_Ifc >
86 pFiles( ParseToolsFactory().Create_FileCollector(6000) );
88 bool bIDL = false;
89 bool bCpp = false;
91 command::Parse::ProjectIterator
92 itEnd = rCommand.ProjectsEnd();
93 for ( command::Parse::ProjectIterator it = rCommand.ProjectsBegin();
94 it != itEnd;
95 ++it )
97 uintt nCount = GatherFiles( *pFiles, *(*it) );
98 Cout() << nCount
99 << " files found to parse in project "
100 << (*it)->Name()
101 << "."
102 << Endl();
104 switch ( (*it)->Language().eLanguage )
106 case command::S_LanguageInfo::idl:
108 Get_IdlParser().Run(*pFiles);
109 bIDL = true;
110 } break;
111 case command::S_LanguageInfo::cpp:
113 Get_CppParser().Run( *pFiles );
114 bCpp = true;
115 } break;
116 default:
117 Cerr() << "Project in yet unimplemented language skipped."
118 << Endl();
120 } // end for
122 if (bCpp)
124 rAry.Gate_Cpp().Calculate_AllSecondaryInformation();
126 if (bIDL)
128 rAry.Gate_Idl().Calculate_AllSecondaryInformation(
129 rCommand.DevelopersManual_RefFilePath() );
131 // ::ary::idl::SecondariesPilot &
132 // rIdl2sPilot = rAry.Gate_Idl().Secondaries();
134 // rIdl2sPilot.CheckAllInterfaceBases( rAry.Gate_Idl() );
135 // rIdl2sPilot.Connect_Types2Ces();
136 // rIdl2sPilot.Gather_CrossReferences();
138 // if (NOT rCommand.DevelopersManual_RefFilePath().empty())
139 // {
140 // csv::File
141 // aFile(rCommand.DevelopersManual_RefFilePath(), csv::CFM_READ);
142 // if ( aFile.open() )
143 // {
144 // rIdl2sPilot.Read_Links2DevManual(aFile);
145 // aFile.close();
146 // }
147 // }
148 } // endif (bIDL)
150 return true;
152 } // end try
153 catch (csv::Exception & xx)
155 xx.GetInfo(Cerr());
156 Cerr() << " program will exit." << Endl();
158 return false;
162 CodeParser_Ifc &
163 Parser::Get_CppParser()
165 if ( NOT pCppParser )
166 Create_CppParser();
167 return *pCppParser;
170 IdlParser &
171 Parser::Get_IdlParser()
173 if ( NOT pIdlParser )
174 Create_IdlParser();
175 return *pIdlParser;
178 void
179 Parser::Create_CppParser()
181 pCppParser = ParseToolsFactory().Create_Parser_Cplusplus();
182 pCppDocuInterpreter = ParseToolsFactory().Create_DocuParser_AutodocStyle();
184 pCppParser->Setup( CommandLine::Get_().TheRepository(),
185 *pCppDocuInterpreter );
188 void
189 Parser::Create_IdlParser()
191 pIdlParser = new IdlParser(CommandLine::Get_().TheRepository());
194 const ParseToolsFactory_Ifc &
195 Parser::ParseToolsFactory()
197 return ParseToolsFactory_Ifc::GetIt_();
200 uintt
201 Parser::GatherFiles( FileCollector_Ifc & o_rFiles,
202 const S_ProjectData & i_rProject )
204 uintt ret = 0;
205 o_rFiles.EraseAll();
207 typedef StringVector StrVector;
208 typedef StrVector::const_iterator StrIterator;
209 const S_Sources &
210 rSources = i_rProject.Sources();
211 const StrVector &
212 rExtensions = i_rProject.Language().aExtensions;
214 StrIterator it;
215 StrIterator itTreesEnd = rSources.aTrees.end();
216 StrIterator itDirsEnd = rSources.aDirectories.end();
217 StrIterator itFilesEnd = rSources.aFiles.end();
218 StrIterator itExt;
219 StrIterator itExtEnd = rExtensions.end();
221 csv::StreamStr aDir(500);
222 i_rProject.RootDirectory().Get( aDir );
224 uintt nProjectDir_AddPosition =
225 ( strcmp(aDir.c_str(),".\\") == 0 OR strcmp(aDir.c_str(),"./") == 0 )
227 : uintt( aDir.tellp() );
229 for ( it = rSources.aDirectories.begin();
230 it != itDirsEnd;
231 ++it )
233 aDir.seekp( nProjectDir_AddPosition );
234 aDir << *it;
236 for ( itExt = rExtensions.begin();
237 itExt != itExtEnd;
238 ++itExt )
240 ret += o_rFiles.AddFilesFrom( aDir.c_str(),
241 *itExt,
242 FileCollector_Ifc::flat );
243 } // end for itExt
244 } // end for it
245 for ( it = rSources.aTrees.begin();
246 it != itTreesEnd;
247 ++it )
249 aDir.seekp( nProjectDir_AddPosition );
250 aDir << *it;
252 for ( itExt = rExtensions.begin();
253 itExt != itExtEnd;
254 ++itExt )
256 ret += o_rFiles.AddFilesFrom( aDir.c_str(),
257 *itExt,
258 FileCollector_Ifc::recursive );
259 } // end for itExt
260 } // end for it
261 for ( it = rSources.aFiles.begin();
262 it != itFilesEnd;
263 ++it )
265 aDir.seekp( nProjectDir_AddPosition );
266 aDir << *it;
268 o_rFiles.AddFile( aDir.c_str() );
269 } // end for it
270 ret += rSources.aFiles.size();
272 return ret;
276 } // namespace run
277 } // namespace command
280 #if 0
281 inline const ParseToolsFactory_Ifc &
282 CommandRunner::ParseToolsFactory()
283 { return ParseToolsFactory_Ifc::GetIt_(); }
286 inline const command::S_LanguageInfo &
287 CommandRunner::Get_ProjectLanguage( const command::Parse & i_rCommand,
288 const command::S_ProjectData & i_rProject )
290 if ( i_rProject.pLanguage )
291 return *i_rProject.pLanguage;
292 return *i_rCommand.GlobalLanguageInfo();
295 inline bool
296 CommandRunner::HasParsedCpp() const
297 { return pCppParser; }
298 inline bool
299 CommandRunner::HasParsedIdl() const
300 { return pIdlParser; }
306 CommandRunner::CommandRunner()
307 : pCommandLine(0),
308 pReposy(0),
309 pNewReposy(0),
310 nResultCode(0)
312 Cout() << "\nAutodoc version 2.2.1"
313 << "\n-------------------"
314 << "\n" << Endl();
317 CommandRunner::~CommandRunner()
319 ary::Repository::Destroy_();
320 Cout() << "\n" << Endl();
323 void
324 CommandRunner::Run( const CommandLine & i_rCL )
326 ary::Repository::Destroy_();
327 // ary::Repository::Destroy_();
328 pReposy = 0;
329 pNewReposy = 0;
330 nResultCode = 0;
331 pCommandLine = &i_rCL;
333 pCommandLine->Run();
336 void
337 CommandRunner::Parse()
342 csv_assert( pCommandLine->Cmd_Parse() != 0 );
343 const command::Parse &
344 rCmd = *pCommandLine->Cmd_Parse();
346 Cout() << "Parsing the repository "
347 << rCmd.ReposyName()
348 << " ..."
349 << Endl();
351 if ( pReposy == 0 )
352 pReposy = & ary::Repository::Create_( rCmd.ReposyName(), 0 );
353 if ( pNewReposy == 0 )
354 pNewReposy = & ary::Repository::Create_( rCmd.ReposyName() );
356 Dyn< FileCollector_Ifc > pFiles;
357 pFiles = ParseToolsFactory().Create_FileCollector(6000);
359 bool bCpp = false;
360 bool bIDL = false;
362 command::Parse::ProjectIterator itEnd = rCmd.ProjectsEnd();
363 for ( command::Parse::ProjectIterator it = rCmd.ProjectsBegin();
364 it != itEnd;
365 ++it )
368 uintt nCount = GatherFiles( *pFiles, rCmd, *(*it) );
369 Cout() << nCount
370 << " files found to parse in project "
371 << (*it)->Name()
372 << "."
373 << Endl();
376 switch ( Get_ProjectLanguage(rCmd, *(*it)).eLanguage )
378 case command::S_LanguageInfo::cpp:
380 Get_CppParser().Run( (*it)->Name(),
381 (*it)->RootDirectory(),
382 *pFiles );
383 bCpp = true;
384 } break;
385 case command::S_LanguageInfo::idl:
387 Get_IdlParser().Run(*pFiles);
388 bIDL = true;
389 } break;
390 default:
391 Cerr() << "Project in yet unimplemented language skipped."
392 << Endl();
394 } // end for
396 if (bCpp)
397 pReposy->RwGate_Cpp().Connect_AllTypes_2_TheirRelated_CodeEntites();
398 if (bIDL)
400 pNewReposy->Gate_Idl().Secondaries().Connect_Types2Ces();
401 pNewReposy->Gate_Idl().Secondaries().Gather_CrossReferences();
404 } // end try
405 catch (csv::Exception & xx)
407 xx.GetInfo(Cerr());
408 Cerr() << " program will exit." << Endl();
409 nResultCode = 1;
411 catch (...)
413 Cerr() << "Unknown exception - program will exit." << Endl();
414 nResultCode = 1;
418 void
419 CommandRunner::Load()
421 Cout() << "This would load the repository from the directory "
422 << pCommandLine->Cmd_Load()->ReposyDir()
423 << "."
424 << Endl();
428 void
429 CommandRunner::Save()
431 Cout() << "This would save the repository into the directory "
432 << pCommandLine->Cmd_Save()->ReposyDir()
433 << "."
434 << Endl();
438 void
439 CommandRunner::CreateHtml()
441 Cout() << "Creating HTML-output into the directory "
442 << pCommandLine->Cmd_CreateHtml()->OutputDir()
443 << "."
444 << Endl();
446 if ( HasParsedCpp() )
447 CreateHtml_NewStyle();
448 if ( HasParsedIdl() )
449 CreateHtml_OldIdlStyle();
454 void
455 CommandRunner::CreateXml()
457 Cout() << "This would create the XML-output into the directory "
458 << pCommandLine->Cmd_CreateXml()->OutputDir()
459 << "."
460 << Endl();
463 CodeParser_Ifc &
464 CommandRunner::Get_CppParser()
466 if ( NOT pCppParser )
467 Create_CppParser();
468 return *pCppParser;
471 IdlParser &
472 CommandRunner::Get_IdlParser()
474 if ( NOT pIdlParser )
475 Create_IdlParser();
476 return *pIdlParser;
479 void
480 CommandRunner::Create_CppParser()
482 pCppParser = ParseToolsFactory().Create_Parser_Cplusplus();
483 pCppDocuInterpreter = ParseToolsFactory().Create_DocuParser_AutodocStyle();
485 pCppParser->Setup( *pReposy,
486 *pCppDocuInterpreter );
489 void
490 CommandRunner::Create_IdlParser()
492 pIdlParser = new IdlParser(*pNewReposy);
495 uintt
496 CommandRunner::GatherFiles( FileCollector_Ifc & o_rFiles,
497 const command::Parse & i_rCommand,
498 const command::S_ProjectData & i_rProject )
500 uintt ret = 0;
501 o_rFiles.EraseAll();
503 typedef StringVector StrVector;
504 typedef StrVector::const_iterator StrIterator;
505 const command::S_Sources &
506 rSources = i_rProject.aFiles;
507 const StrVector &
508 rExtensions = Get_ProjectLanguage(i_rCommand,i_rProject).aExtensions;
510 StrIterator it;
511 StrIterator itDirsEnd = rSources.aDirectories.end();
512 StrIterator itTreesEnd = i_rProject.aFiles.aTrees.end();
513 StrIterator itFilesEnd = i_rProject.aFiles.aFiles.end();
514 StrIterator itExt;
515 StrIterator itExtEnd = rExtensions.end();
517 csv::StreamStr aDir(500);
518 i_rProject.aRootDirectory.Get( aDir );
520 uintt nProjectDir_AddPosition =
521 ( strcmp(aDir.c_str(),".\\") == 0 OR strcmp(aDir.c_str(),"./") == 0 )
523 : uintt( aDir.tellp() );
525 for ( it = rSources.aDirectories.begin();
526 it != itDirsEnd;
527 ++it )
529 aDir.seekp( nProjectDir_AddPosition );
530 aDir << *it;
532 for ( itExt = rExtensions.begin();
533 itExt != itExtEnd;
534 ++itExt )
536 ret += o_rFiles.AddFilesFrom( aDir.c_str(),
537 *itExt,
538 FileCollector_Ifc::flat );
539 } // end for itExt
540 } // end for it
541 for ( it = rSources.aTrees.begin();
542 it != itTreesEnd;
543 ++it )
545 aDir.seekp( nProjectDir_AddPosition );
546 aDir << *it;
548 for ( itExt = rExtensions.begin();
549 itExt != itExtEnd;
550 ++itExt )
552 ret += o_rFiles.AddFilesFrom( aDir.c_str(),
553 *itExt,
554 FileCollector_Ifc::recursive );
555 } // end for itExt
556 } // end for it
557 for ( it = rSources.aFiles.begin();
558 it != itFilesEnd;
559 ++it )
561 aDir.seekp( nProjectDir_AddPosition );
562 aDir << *it;
564 o_rFiles.AddFile( aDir.c_str() );
565 } // end for it
566 ret += rSources.aFiles.size();
568 return ret;
571 void
572 CommandRunner::CreateHtml_NewStyle()
574 const ary::cpp::DisplayGate &
575 rGate = pReposy->DisplayGate_Cpp();
577 Dyn< autodoc::HtmlDisplay_UdkStd > pHtmlDisplay;
578 pHtmlDisplay = DisplayToolsFactory_Ifc::GetIt_()
579 .Create_HtmlDisplay_UdkStd();
581 pHtmlDisplay->Run( pCommandLine->Cmd_CreateHtml()->OutputDir(),
582 rGate,
583 DisplayToolsFactory_Ifc::GetIt_().Create_StdFrame() );
586 void
587 CommandRunner::CreateHtml_OldIdlStyle()
589 ary::idl::Gate &
590 rAryGate = pNewReposy->Gate_Idl();
592 // Read DevManualLinkFile:
593 // KORR_FUTURE
594 csv::File
595 aFile("devmanref.txt", csv::CFM_READ);
596 if ( aFile.open() )
598 rAryGate.Secondaries().Read_Links2DevManual(aFile);
599 aFile.close();
602 // New Style Output
603 Dyn<autodoc::HtmlDisplay_Idl_Ifc> pNewDisplay;
604 pNewDisplay = DisplayToolsFactory_Ifc::GetIt_()
605 .Create_HtmlDisplay_Idl();
606 pNewDisplay->Run( pCommandLine->Cmd_CreateHtml()->OutputDir(),
607 rAryGate,
608 DisplayToolsFactory_Ifc::GetIt_().Create_StdFrame() );
610 #endif // 0
612 } // namespace autodoc