1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: cmd_run.cxx,v $
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 ************************************************************************/
32 #include "cmd_run.hxx"
35 // NOT FULLY DEFINED SERVICES
36 #include <cosv/file.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>
50 #include "adc_cmd_parse.hxx"
51 #include "adc_cmds.hxx"
60 Parser::Parser( const Parse
& i_command
)
61 : rCommand(i_command
),
63 pCppDocuInterpreter(),
75 Cout() << "Parsing the repository "
76 << rCommand
.ReposyName()
82 rAry
= CommandLine::Get_().TheRepository();
83 rAry
.Set_Title(rCommand
.ReposyName());
85 Dyn
< FileCollector_Ifc
>
86 pFiles( ParseToolsFactory().Create_FileCollector(6000) );
91 command::Parse::ProjectIterator
92 itEnd
= rCommand
.ProjectsEnd();
93 for ( command::Parse::ProjectIterator it
= rCommand
.ProjectsBegin();
97 uintt nCount
= GatherFiles( *pFiles
, *(*it
) );
99 << " files found to parse in project "
104 switch ( (*it
)->Language().eLanguage
)
106 case command::S_LanguageInfo::idl
:
108 Get_IdlParser().Run(*pFiles
);
111 case command::S_LanguageInfo::cpp
:
113 Get_CppParser().Run( *pFiles
);
117 Cerr() << "Project in yet unimplemented language skipped."
124 rAry
.Gate_Cpp().Calculate_AllSecondaryInformation();
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())
141 // aFile(rCommand.DevelopersManual_RefFilePath(), csv::CFM_READ);
142 // if ( aFile.open() )
144 // rIdl2sPilot.Read_Links2DevManual(aFile);
153 catch (csv::Exception
& xx
)
156 Cerr() << " program will exit." << Endl();
163 Parser::Get_CppParser()
165 if ( NOT pCppParser
)
171 Parser::Get_IdlParser()
173 if ( NOT pIdlParser
)
179 Parser::Create_CppParser()
181 pCppParser
= ParseToolsFactory().Create_Parser_Cplusplus();
182 pCppDocuInterpreter
= ParseToolsFactory().Create_DocuParser_AutodocStyle();
184 pCppParser
->Setup( CommandLine::Get_().TheRepository(),
185 *pCppDocuInterpreter
);
189 Parser::Create_IdlParser()
191 pIdlParser
= new IdlParser(CommandLine::Get_().TheRepository());
194 const ParseToolsFactory_Ifc
&
195 Parser::ParseToolsFactory()
197 return ParseToolsFactory_Ifc::GetIt_();
201 Parser::GatherFiles( FileCollector_Ifc
& o_rFiles
,
202 const S_ProjectData
& i_rProject
)
207 typedef StringVector StrVector
;
208 typedef StrVector::const_iterator StrIterator
;
210 rSources
= i_rProject
.Sources();
212 rExtensions
= i_rProject
.Language().aExtensions
;
215 StrIterator itTreesEnd
= rSources
.aTrees
.end();
216 StrIterator itDirsEnd
= rSources
.aDirectories
.end();
217 StrIterator itFilesEnd
= rSources
.aFiles
.end();
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();
233 aDir
.seekp( nProjectDir_AddPosition
);
236 for ( itExt
= rExtensions
.begin();
240 ret
+= o_rFiles
.AddFilesFrom( aDir
.c_str(),
242 FileCollector_Ifc::flat
);
245 for ( it
= rSources
.aTrees
.begin();
249 aDir
.seekp( nProjectDir_AddPosition
);
252 for ( itExt
= rExtensions
.begin();
256 ret
+= o_rFiles
.AddFilesFrom( aDir
.c_str(),
258 FileCollector_Ifc::recursive
);
261 for ( it
= rSources
.aFiles
.begin();
265 aDir
.seekp( nProjectDir_AddPosition
);
268 o_rFiles
.AddFile( aDir
.c_str() );
270 ret
+= rSources
.aFiles
.size();
277 } // namespace command
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();
296 CommandRunner::HasParsedCpp() const
297 { return pCppParser
; }
299 CommandRunner::HasParsedIdl() const
300 { return pIdlParser
; }
306 CommandRunner::CommandRunner()
312 Cout() << "\nAutodoc version 2.2.1"
313 << "\n-------------------"
317 CommandRunner::~CommandRunner()
319 ary::Repository::Destroy_();
320 Cout() << "\n" << Endl();
324 CommandRunner::Run( const CommandLine
& i_rCL
)
326 ary::Repository::Destroy_();
327 // ary::Repository::Destroy_();
331 pCommandLine
= &i_rCL
;
337 CommandRunner::Parse()
342 csv_assert( pCommandLine
->Cmd_Parse() != 0 );
343 const command::Parse
&
344 rCmd
= *pCommandLine
->Cmd_Parse();
346 Cout() << "Parsing the repository "
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);
362 command::Parse::ProjectIterator itEnd
= rCmd
.ProjectsEnd();
363 for ( command::Parse::ProjectIterator it
= rCmd
.ProjectsBegin();
368 uintt nCount
= GatherFiles( *pFiles
, rCmd
, *(*it
) );
370 << " files found to parse in project "
376 switch ( Get_ProjectLanguage(rCmd
, *(*it
)).eLanguage
)
378 case command::S_LanguageInfo::cpp
:
380 Get_CppParser().Run( (*it
)->Name(),
381 (*it
)->RootDirectory(),
385 case command::S_LanguageInfo::idl
:
387 Get_IdlParser().Run(*pFiles
);
391 Cerr() << "Project in yet unimplemented language skipped."
397 pReposy
->RwGate_Cpp().Connect_AllTypes_2_TheirRelated_CodeEntites();
400 pNewReposy
->Gate_Idl().Secondaries().Connect_Types2Ces();
401 pNewReposy
->Gate_Idl().Secondaries().Gather_CrossReferences();
405 catch (csv::Exception
& xx
)
408 Cerr() << " program will exit." << Endl();
413 Cerr() << "Unknown exception - program will exit." << Endl();
419 CommandRunner::Load()
421 Cout() << "This would load the repository from the directory "
422 << pCommandLine
->Cmd_Load()->ReposyDir()
429 CommandRunner::Save()
431 Cout() << "This would save the repository into the directory "
432 << pCommandLine
->Cmd_Save()->ReposyDir()
439 CommandRunner::CreateHtml()
441 Cout() << "Creating HTML-output into the directory "
442 << pCommandLine
->Cmd_CreateHtml()->OutputDir()
446 if ( HasParsedCpp() )
447 CreateHtml_NewStyle();
448 if ( HasParsedIdl() )
449 CreateHtml_OldIdlStyle();
455 CommandRunner::CreateXml()
457 Cout() << "This would create the XML-output into the directory "
458 << pCommandLine
->Cmd_CreateXml()->OutputDir()
464 CommandRunner::Get_CppParser()
466 if ( NOT pCppParser
)
472 CommandRunner::Get_IdlParser()
474 if ( NOT pIdlParser
)
480 CommandRunner::Create_CppParser()
482 pCppParser
= ParseToolsFactory().Create_Parser_Cplusplus();
483 pCppDocuInterpreter
= ParseToolsFactory().Create_DocuParser_AutodocStyle();
485 pCppParser
->Setup( *pReposy
,
486 *pCppDocuInterpreter
);
490 CommandRunner::Create_IdlParser()
492 pIdlParser
= new IdlParser(*pNewReposy
);
496 CommandRunner::GatherFiles( FileCollector_Ifc
& o_rFiles
,
497 const command::Parse
& i_rCommand
,
498 const command::S_ProjectData
& i_rProject
)
503 typedef StringVector StrVector
;
504 typedef StrVector::const_iterator StrIterator
;
505 const command::S_Sources
&
506 rSources
= i_rProject
.aFiles
;
508 rExtensions
= Get_ProjectLanguage(i_rCommand
,i_rProject
).aExtensions
;
511 StrIterator itDirsEnd
= rSources
.aDirectories
.end();
512 StrIterator itTreesEnd
= i_rProject
.aFiles
.aTrees
.end();
513 StrIterator itFilesEnd
= i_rProject
.aFiles
.aFiles
.end();
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();
529 aDir
.seekp( nProjectDir_AddPosition
);
532 for ( itExt
= rExtensions
.begin();
536 ret
+= o_rFiles
.AddFilesFrom( aDir
.c_str(),
538 FileCollector_Ifc::flat
);
541 for ( it
= rSources
.aTrees
.begin();
545 aDir
.seekp( nProjectDir_AddPosition
);
548 for ( itExt
= rExtensions
.begin();
552 ret
+= o_rFiles
.AddFilesFrom( aDir
.c_str(),
554 FileCollector_Ifc::recursive
);
557 for ( it
= rSources
.aFiles
.begin();
561 aDir
.seekp( nProjectDir_AddPosition
);
564 o_rFiles
.AddFile( aDir
.c_str() );
566 ret
+= rSources
.aFiles
.size();
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(),
583 DisplayToolsFactory_Ifc::GetIt_().Create_StdFrame() );
587 CommandRunner::CreateHtml_OldIdlStyle()
590 rAryGate
= pNewReposy
->Gate_Idl();
592 // Read DevManualLinkFile:
595 aFile("devmanref.txt", csv::CFM_READ
);
598 rAryGate
.Secondaries().Read_Links2DevManual(aFile
);
603 Dyn
<autodoc::HtmlDisplay_Idl_Ifc
> pNewDisplay
;
604 pNewDisplay
= DisplayToolsFactory_Ifc::GetIt_()
605 .Create_HtmlDisplay_Idl();
606 pNewDisplay
->Run( pCommandLine
->Cmd_CreateHtml()->OutputDir(),
608 DisplayToolsFactory_Ifc::GetIt_().Create_StdFrame() );
612 } // namespace autodoc