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 <parser/unoidl.hxx>
30 
31 
32 // NOT FULLY DECLARED SERVICES
33 #include <stdlib.h>
34 #include <cosv/file.hxx>
35 #include <ary/ary.hxx>
36 #include <ary/idl/i_gate.hxx>
37 #include <ary/doc/d_oldidldocu.hxx>
38 #include <../parser/inc/x_docu.hxx>
39 #include <parser/parserinfo.hxx>
40 #include <tools/filecoll.hxx>
41 #include <tools/tkpchars.hxx>
42 #include <s2_luidl/tkp_uidl.hxx>
43 #include <s2_luidl/distrib.hxx>
44 #include <s2_luidl/pe_file2.hxx>
45 #include <s2_dsapi/cx_dsapi.hxx>
46 #include <adc_msg.hxx>
47 #include <x_parse2.hxx>
48 
49 
50 
51 namespace autodoc
52 {
53 
54 
55 class FileParsePerformers
56 {
57   public:
58 						FileParsePerformers(
59 						    ary::Repository &
60 						                        io_rRepository,
61 						    ParserInfo &        io_rParserInfo );
62 
63 	void				ParseFile(
64 							const char *		i_sFullPath );
65 
66     void                ConnectLinks();
67 
68   private:
69 	CharacterSource		aFileLoader;
70 	Dyn<csi::uidl::TokenParser_Uidl>
71 						pTokens;
72 	csi::uidl::TokenDistributor
73                         aDistributor;
74 	Dyn<csi::uidl::PE_File>
75                         pFileParseEnvironment;
76 	ary::Repository &
77                         rRepository;
78     ParserInfo &        rParserInfo;
79 };
80 
81 
82 IdlParser::IdlParser( ary::Repository & io_rRepository )
83 	:	pRepository(&io_rRepository)
84 {
85 }
86 
87 void
88 IdlParser::Run( const autodoc::FileCollector_Ifc & i_rFiles )
89 {
90 	Dyn<FileParsePerformers>
91 		pFileParsePerformers(
92 		    new FileParsePerformers(*pRepository,
93 									static_cast< ParserInfo& >(*this)) );
94 
95 	FileCollector::const_iterator iEnd = i_rFiles.End();
96 	for ( FileCollector::const_iterator iter = i_rFiles.Begin();
97 		  iter != iEnd;
98 		  ++iter )
99 	{
100 		Cout() << (*iter) << " ..."<< Endl();
101 
102         try
103         {
104     		pFileParsePerformers->ParseFile(*iter);
105         }
106         catch (X_AutodocParser &)
107         {
108             /// Ignore and goon
109             TheMessages().Out_ParseError(CurFile(), CurLine());
110     		pFileParsePerformers
111     		    = new FileParsePerformers(*pRepository,
112                                           static_cast< ParserInfo& >(*this));
113         }
114         catch (X_Docu & xd)
115         {
116             // Currently thic catches only wrong since tags, while since tags are
117             // transformed. In this case the program shall be terminated.
118             Cerr() << xd << Endl();
119             exit(1);
120         }
121         catch (...)
122         {
123             Cout() << "Unknown error." << Endl();
124             exit(0);
125 //    		pFileParsePerformers = new FileParsePerformers( *pRepository );
126         }
127 	}
128 
129     pFileParsePerformers->ConnectLinks();
130 }
131 
132 FileParsePerformers::FileParsePerformers( ary::Repository & io_rRepository,
133 										  ParserInfo &			 io_rParserInfo )
134 	:   pTokens(0),
135 	    aDistributor(io_rRepository, io_rParserInfo),
136 		rRepository( io_rRepository ),
137 		rParserInfo(io_rParserInfo)
138 {
139 	DYN csi::dsapi::Context_Docu *
140 	    dpDocuContext
141 			= new csi::dsapi::Context_Docu( aDistributor.DocuTokens_Receiver() );
142 	pTokens = new csi::uidl::TokenParser_Uidl( aDistributor.CodeTokens_Receiver(), *dpDocuContext );
143 	pFileParseEnvironment
144 			= new csi::uidl::PE_File(aDistributor,rParserInfo);
145 
146 	aDistributor.SetTokenProvider(*pTokens);
147 	aDistributor.SetTopParseEnvironment(*pFileParseEnvironment);
148 }
149 
150 void
151 FileParsePerformers::ParseFile( const char * i_sFullPath )
152 {
153 	csv::File aFile(i_sFullPath);
154 
155 	aFile.open( csv::CFM_READ );
156 	csv_assert( aFile.is_open() );
157 	aFileLoader.LoadText(aFile);
158 	aFile.close();
159 
160     rParserInfo.Set_CurFile(i_sFullPath, true); // true = count lines
161 	pTokens->Start(aFileLoader);
162     aDistributor.Reset();
163 
164 	do {
165 		aDistributor.TradeToken();
166 	} while ( NOT aFileLoader.IsFinished() );
167 }
168 
169 void
170 FileParsePerformers::ConnectLinks()
171 {
172     // KORR_FUTURE ?
173 //  rRepository.RwGate_Idl().ConnectAdditionalLinks();
174 }
175 
176 }   // namespace autodoc
177