xref: /AOO41X/main/autodoc/source/exes/adc_uni/cmd_run.cxx (revision 1ecadb572e7010ff3b3382ad9bf179dbc6efadbb)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #include <precomp.h>
29 #include "cmd_run.hxx"
30 
31 
32 // NOT FULLY DEFINED SERVICES
33 #include <cosv/file.hxx>
34 #include <cosv/x.hxx>
35 #include <ary/ary.hxx>
36 #include <ary/cpp/c_gate.hxx>
37 #include <ary/idl/i_ce.hxx>
38 #include <ary/idl/i_gate.hxx>
39 #include <ary/idl/i_module.hxx>
40 #include <ary/idl/ip_ce.hxx>
41 #include <autodoc/filecoli.hxx>
42 #include <autodoc/parsing.hxx>
43 #include <autodoc/prs_code.hxx>
44 #include <autodoc/prs_docu.hxx>
45 #include <parser/unoidl.hxx>
46 #include <adc_cl.hxx>
47 #include "adc_cmd_parse.hxx"
48 #include "adc_cmds.hxx"
49 
50 namespace autodoc
51 {
52 namespace command
53 {
54 namespace run
55 {
56 
57 Parser::Parser( const Parse & i_command )
58     :   rCommand(i_command),
59         pCppParser(),
60         pCppDocuInterpreter(),
61         pIdlParser()
62 {
63 }
64 
65 Parser::~Parser()
66 {
67 }
68 
69 bool
70 Parser::Perform()
71 {
72     Cout() << "Parsing the repository "
73               << rCommand.ReposyName()
74               << " ..."
75               << Endl();
76   try
77   {
78     ::ary::Repository &
79         rAry = CommandLine::Get_().TheRepository();
80     rAry.Set_Title(rCommand.ReposyName());
81 
82     Dyn< FileCollector_Ifc >
83         pFiles( ParseToolsFactory().Create_FileCollector(6000) );
84 
85     bool bIDL = false;
86     bool bCpp = false;
87 
88     command::Parse::ProjectIterator
89         itEnd = rCommand.ProjectsEnd();
90     for ( command::Parse::ProjectIterator it = rCommand.ProjectsBegin();
91           it != itEnd;
92           ++it )
93     {
94         uintt nCount = GatherFiles( *pFiles, *(*it) );
95         Cout() << nCount
96              << " files found to parse in project "
97              << (*it)->Name()
98              << "."
99              << Endl();
100 
101         switch ( (*it)->Language().eLanguage )
102         {
103             case command::S_LanguageInfo::idl:
104             {
105                 Get_IdlParser().Run(*pFiles);
106                 bIDL = true;
107             }   break;
108             case command::S_LanguageInfo::cpp:
109             {
110                 Get_CppParser().Run( *pFiles );
111                 bCpp = true;
112             }   break;
113             default:
114                 Cerr() << "Project in yet unimplemented language skipped."
115                        << Endl();
116         }
117     }	// end for
118 
119     if (bCpp)
120     {
121 	    rAry.Gate_Cpp().Calculate_AllSecondaryInformation();
122     }
123     if (bIDL)
124     {
125 	    rAry.Gate_Idl().Calculate_AllSecondaryInformation(
126 	                        rCommand.DevelopersManual_RefFilePath() );
127 
128 //        ::ary::idl::SecondariesPilot &
129 //            rIdl2sPilot = rAry.Gate_Idl().Secondaries();
130 //
131 //        rIdl2sPilot.CheckAllInterfaceBases( rAry.Gate_Idl() );
132 //        rIdl2sPilot.Connect_Types2Ces();
133 //        rIdl2sPilot.Gather_CrossReferences();
134 //
135 //        if (NOT rCommand.DevelopersManual_RefFilePath().empty())
136 //        {
137 //            csv::File
138 //                aFile(rCommand.DevelopersManual_RefFilePath(), csv::CFM_READ);
139 //            if ( aFile.open() )
140 //            {
141 //                rIdl2sPilot.Read_Links2DevManual(aFile);
142 //     	        aFile.close();
143 //            }
144 //        }
145     }   // endif (bIDL)
146 
147     return true;
148 
149   }   // end try
150   catch (csv::Exception & xx)
151   {
152     xx.GetInfo(Cerr());
153     Cerr() << " program will exit." << Endl();
154 
155     return false;
156   }
157 }
158 
159 CodeParser_Ifc &
160 Parser::Get_CppParser()
161 {
162     if ( NOT pCppParser )
163         Create_CppParser();
164     return *pCppParser;
165 }
166 
167 IdlParser &
168 Parser::Get_IdlParser()
169 {
170     if ( NOT pIdlParser )
171         Create_IdlParser();
172     return *pIdlParser;
173 }
174 
175 void
176 Parser::Create_CppParser()
177 {
178     pCppParser          = ParseToolsFactory().Create_Parser_Cplusplus();
179     pCppDocuInterpreter = ParseToolsFactory().Create_DocuParser_AutodocStyle();
180 
181     pCppParser->Setup( CommandLine::Get_().TheRepository(),
182                        *pCppDocuInterpreter );
183 }
184 
185 void
186 Parser::Create_IdlParser()
187 {
188     pIdlParser = new IdlParser(CommandLine::Get_().TheRepository());
189 }
190 
191 const ParseToolsFactory_Ifc &
192 Parser::ParseToolsFactory()
193 {
194     return ParseToolsFactory_Ifc::GetIt_();
195 }
196 
197 uintt
198 Parser::GatherFiles( FileCollector_Ifc &    o_rFiles,
199                      const S_ProjectData &  i_rProject )
200 {
201     uintt ret = 0;
202     o_rFiles.EraseAll();
203 
204     typedef StringVector                StrVector;
205     typedef StrVector::const_iterator   StrIterator;
206     const S_Sources &
207         rSources = i_rProject.Sources();
208     const StrVector &
209         rExtensions = i_rProject.Language().aExtensions;
210 
211     StrIterator     it;
212     StrIterator     itTreesEnd  = rSources.aTrees.end();
213     StrIterator     itDirsEnd   = rSources.aDirectories.end();
214     StrIterator     itFilesEnd  = rSources.aFiles.end();
215     StrIterator     itExt;
216     StrIterator     itExtEnd    = rExtensions.end();
217 
218     csv::StreamStr aDir(500);
219     i_rProject.RootDirectory().Get( aDir );
220 
221     uintt nProjectDir_AddPosition =
222             ( strcmp(aDir.c_str(),".\\") == 0 OR strcmp(aDir.c_str(),"./") == 0 )
223                 ?   0
224                 :   uintt( aDir.tellp() );
225 
226     for ( it = rSources.aDirectories.begin();
227           it != itDirsEnd;
228           ++it )
229     {
230         aDir.seekp( nProjectDir_AddPosition );
231         aDir << *it;
232 
233         for ( itExt = rExtensions.begin();
234               itExt != itExtEnd;
235               ++itExt )
236         {
237             ret += o_rFiles.AddFilesFrom( aDir.c_str(),
238                                           *itExt,
239                                           FileCollector_Ifc::flat );
240         }   // end for itExt
241     }   // end for it
242     for ( it = rSources.aTrees.begin();
243           it != itTreesEnd;
244           ++it )
245     {
246         aDir.seekp( nProjectDir_AddPosition );
247         aDir << *it;
248 
249         for ( itExt = rExtensions.begin();
250               itExt != itExtEnd;
251               ++itExt )
252         {
253             ret += o_rFiles.AddFilesFrom( aDir.c_str(),
254                                           *itExt,
255                                           FileCollector_Ifc::recursive );
256         }   // end for itExt
257     }   // end for it
258     for ( it = rSources.aFiles.begin();
259           it != itFilesEnd;
260           ++it )
261     {
262         aDir.seekp( nProjectDir_AddPosition );
263         aDir << *it;
264 
265         o_rFiles.AddFile( aDir.c_str() );
266     }   // end for it
267     ret += rSources.aFiles.size();
268 
269     return ret;
270 }
271 
272 
273 }   // namespace run
274 }   // namespace command
275 
276 
277 #if 0
278 inline const ParseToolsFactory_Ifc &
279 CommandRunner::ParseToolsFactory()
280     { return ParseToolsFactory_Ifc::GetIt_(); }
281 
282 
283 inline const command::S_LanguageInfo &
284 CommandRunner::Get_ProjectLanguage( const command::Parse &          i_rCommand,
285                                     const command::S_ProjectData &  i_rProject )
286 {
287     if ( i_rProject.pLanguage )
288         return *i_rProject.pLanguage;
289     return *i_rCommand.GlobalLanguageInfo();
290 }
291 
292 inline bool
293 CommandRunner::HasParsedCpp() const
294     { return pCppParser; }
295 inline bool
296 CommandRunner::HasParsedIdl() const
297     { return pIdlParser; }
298 
299 
300 
301 
302 
303 CommandRunner::CommandRunner()
304     :   pCommandLine(0),
305         pReposy(0),
306         pNewReposy(0),
307         nResultCode(0)
308 {
309     Cout() << "\nAutodoc version 2.2.1"
310            << "\n-------------------"
311            << "\n" << Endl();
312 }
313 
314 CommandRunner::~CommandRunner()
315 {
316     ary::Repository::Destroy_();
317     Cout() << "\n" << Endl();
318 }
319 
320 void
321 CommandRunner::Run( const CommandLine & i_rCL )
322 {
323     ary::Repository::Destroy_();
324 //  ary::Repository::Destroy_();
325     pReposy = 0;
326     pNewReposy = 0;
327     nResultCode = 0;
328     pCommandLine = &i_rCL;
329 
330     pCommandLine->Run();
331 }
332 
333 void
334 CommandRunner::Parse()
335 {
336     try
337     {
338 
339     csv_assert( pCommandLine->Cmd_Parse() != 0 );
340     const command::Parse &
341         rCmd = *pCommandLine->Cmd_Parse();
342 
343     Cout() << "Parsing the repository "
344               << rCmd.ReposyName()
345               << " ..."
346               << Endl();
347 
348     if ( pReposy == 0 )
349         pReposy = & ary::Repository::Create_( rCmd.ReposyName(), 0 );
350     if ( pNewReposy == 0 )
351         pNewReposy = & ary::Repository::Create_( rCmd.ReposyName() );
352 
353     Dyn< FileCollector_Ifc > pFiles;
354     pFiles      = ParseToolsFactory().Create_FileCollector(6000);
355 
356     bool bCpp = false;
357     bool bIDL = false;
358 
359     command::Parse::ProjectIterator itEnd = rCmd.ProjectsEnd();
360     for ( command::Parse::ProjectIterator it = rCmd.ProjectsBegin();
361           it != itEnd;
362           ++it )
363     {
364 
365         uintt nCount = GatherFiles( *pFiles, rCmd, *(*it) );
366         Cout() << nCount
367              << " files found to parse in project "
368              << (*it)->Name()
369              << "."
370              << Endl();
371 
372 
373         switch ( Get_ProjectLanguage(rCmd, *(*it)).eLanguage )
374         {
375             case command::S_LanguageInfo::cpp:
376             {
377                 Get_CppParser().Run( (*it)->Name(),
378                                      (*it)->RootDirectory(),
379                                      *pFiles );
380                 bCpp = true;
381             }   break;
382             case command::S_LanguageInfo::idl:
383             {
384                 Get_IdlParser().Run(*pFiles);
385                 bIDL = true;
386             }   break;
387             default:
388                 Cerr() << "Project in yet unimplemented language skipped."
389                        << Endl();
390         }
391     }	// end for
392 
393     if (bCpp)
394 	    pReposy->RwGate_Cpp().Connect_AllTypes_2_TheirRelated_CodeEntites();
395     if (bIDL)
396     {
397         pNewReposy->Gate_Idl().Secondaries().Connect_Types2Ces();
398         pNewReposy->Gate_Idl().Secondaries().Gather_CrossReferences();
399     }
400 
401     }   // end try
402     catch (csv::Exception & xx)
403     {
404         xx.GetInfo(Cerr());
405         Cerr() << " program will exit." << Endl();
406         nResultCode = 1;
407     }
408     catch (...)
409     {
410         Cerr() << "Unknown exception -   program will exit." << Endl();
411         nResultCode = 1;
412     }
413 }
414 
415 void
416 CommandRunner::Load()
417 {
418     Cout() << "This would load the repository from the directory "
419               << pCommandLine->Cmd_Load()->ReposyDir()
420               << "."
421               << Endl();
422 }
423 
424 
425 void
426 CommandRunner::Save()
427 {
428     Cout() << "This would save the repository into the directory "
429               << pCommandLine->Cmd_Save()->ReposyDir()
430               << "."
431               << Endl();
432 }
433 
434 
435 void
436 CommandRunner::CreateHtml()
437 {
438     Cout() << "Creating HTML-output into the directory "
439               << pCommandLine->Cmd_CreateHtml()->OutputDir()
440               << "."
441               << Endl();
442 
443     if ( HasParsedCpp() )
444         CreateHtml_NewStyle();
445     if ( HasParsedIdl() )
446         CreateHtml_OldIdlStyle();
447 }
448 
449 
450 
451 void
452 CommandRunner::CreateXml()
453 {
454     Cout() << "This would create the XML-output into the directory "
455               << pCommandLine->Cmd_CreateXml()->OutputDir()
456               << "."
457               << Endl();
458 }
459 
460 CodeParser_Ifc &
461 CommandRunner::Get_CppParser()
462 {
463     if ( NOT pCppParser )
464         Create_CppParser();
465     return *pCppParser;
466 }
467 
468 IdlParser &
469 CommandRunner::Get_IdlParser()
470 {
471     if ( NOT pIdlParser )
472         Create_IdlParser();
473     return *pIdlParser;
474 }
475 
476 void
477 CommandRunner::Create_CppParser()
478 {
479     pCppParser          = ParseToolsFactory().Create_Parser_Cplusplus();
480     pCppDocuInterpreter = ParseToolsFactory().Create_DocuParser_AutodocStyle();
481 
482     pCppParser->Setup( *pReposy,
483                        *pCppDocuInterpreter );
484 }
485 
486 void
487 CommandRunner::Create_IdlParser()
488 {
489     pIdlParser = new IdlParser(*pNewReposy);
490 }
491 
492 uintt
493 CommandRunner::GatherFiles( FileCollector_Ifc &            o_rFiles,
494                             const command::Parse &         i_rCommand,
495                             const command::S_ProjectData & i_rProject )
496 {
497     uintt ret = 0;
498     o_rFiles.EraseAll();
499 
500     typedef StringVector                StrVector;
501     typedef StrVector::const_iterator   StrIterator;
502     const command::S_Sources &
503         rSources = i_rProject.aFiles;
504     const StrVector &
505         rExtensions = Get_ProjectLanguage(i_rCommand,i_rProject).aExtensions;
506 
507     StrIterator     it;
508     StrIterator     itDirsEnd   = rSources.aDirectories.end();
509     StrIterator     itTreesEnd  = i_rProject.aFiles.aTrees.end();
510     StrIterator     itFilesEnd  = i_rProject.aFiles.aFiles.end();
511     StrIterator     itExt;
512     StrIterator     itExtEnd    = rExtensions.end();
513 
514     csv::StreamStr aDir(500);
515     i_rProject.aRootDirectory.Get( aDir );
516 
517     uintt nProjectDir_AddPosition =
518             ( strcmp(aDir.c_str(),".\\") == 0 OR strcmp(aDir.c_str(),"./") == 0 )
519                 ?   0
520                 :   uintt( aDir.tellp() );
521 
522     for ( it = rSources.aDirectories.begin();
523           it != itDirsEnd;
524           ++it )
525     {
526         aDir.seekp( nProjectDir_AddPosition );
527         aDir << *it;
528 
529         for ( itExt = rExtensions.begin();
530               itExt != itExtEnd;
531               ++itExt )
532         {
533             ret += o_rFiles.AddFilesFrom( aDir.c_str(),
534                                           *itExt,
535                                           FileCollector_Ifc::flat );
536         }   // end for itExt
537     }   // end for it
538     for ( it = rSources.aTrees.begin();
539           it != itTreesEnd;
540           ++it )
541     {
542         aDir.seekp( nProjectDir_AddPosition );
543         aDir << *it;
544 
545         for ( itExt = rExtensions.begin();
546               itExt != itExtEnd;
547               ++itExt )
548         {
549             ret += o_rFiles.AddFilesFrom( aDir.c_str(),
550                                           *itExt,
551                                           FileCollector_Ifc::recursive );
552         }   // end for itExt
553     }   // end for it
554     for ( it = rSources.aFiles.begin();
555           it != itFilesEnd;
556           ++it )
557     {
558         aDir.seekp( nProjectDir_AddPosition );
559         aDir << *it;
560 
561         o_rFiles.AddFile( aDir.c_str() );
562     }   // end for it
563     ret += rSources.aFiles.size();
564 
565     return ret;
566 }
567 
568 void
569 CommandRunner::CreateHtml_NewStyle()
570 {
571     const ary::cpp::DisplayGate &
572             rGate = pReposy->DisplayGate_Cpp();
573 
574     Dyn< autodoc::HtmlDisplay_UdkStd > pHtmlDisplay;
575             pHtmlDisplay = DisplayToolsFactory_Ifc::GetIt_()
576                                 .Create_HtmlDisplay_UdkStd();
577 
578     pHtmlDisplay->Run( pCommandLine->Cmd_CreateHtml()->OutputDir(),
579                        rGate,
580                        DisplayToolsFactory_Ifc::GetIt_().Create_StdFrame() );
581 }
582 
583 void
584 CommandRunner::CreateHtml_OldIdlStyle()
585 {
586     ary::idl::Gate &
587         rAryGate            = pNewReposy->Gate_Idl();
588 
589     // Read DevManualLinkFile:
590     // KORR_FUTURE
591     csv::File
592         aFile("devmanref.txt", csv::CFM_READ);
593     if ( aFile.open() )
594     {
595         rAryGate.Secondaries().Read_Links2DevManual(aFile);
596      	aFile.close();
597     }
598 
599     // New Style Output
600     Dyn<autodoc::HtmlDisplay_Idl_Ifc> pNewDisplay;
601         pNewDisplay         = DisplayToolsFactory_Ifc::GetIt_()
602                                 .Create_HtmlDisplay_Idl();
603     pNewDisplay->Run( pCommandLine->Cmd_CreateHtml()->OutputDir(),
604                       rAryGate,
605                       DisplayToolsFactory_Ifc::GetIt_().Create_StdFrame() );
606 }
607 #endif // 0
608 
609 }   // namespace autodoc
610 
611 
612 
613 
614