xref: /aoo4110/main/xml2cmp/source/xcd/cr_index.cxx (revision b1cdbd2c)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 
25 #include "cr_index.hxx"
26 
27 #include <string.h>
28 #include <fstream>
29 #include "../support/syshelp.hxx"
30 #include "xmltree.hxx"
31 #include "parse.hxx"
32 #include "cr_html.hxx"
33 
34 
35 extern unsigned	C_nSupportedServicesIndex;
36 
37 char C_sLineEnd[] = "\n";
38 
39 char C_sFileBegin[] 	= "<HTML><HEAD></HEAD><BODY bgcolor=\"#ffffff\">\n";
40 char C_sFileEnd[]   	= "</BODY></HTML>\n";
41 char C_sTableBegin[] 	= "<TABLE WIDTH=100% BORDER=1 CELLPADDING=4 CELLSPACING=0><TBODY>\n";
42 char C_sTableEnd[]  	= "</TBODY></TABLE>\n";
43 char C_sService[]	    = "SupportedService";
44 char C_sModule[]	    = "ModuleName";
45 char C_sComponentname[]	= "ComponentName";
46 
47 
48 
49 Simstr sIdlRootPath;
50 
51 
Index(const char * i_sOutputDirectory,const char * i_sIdlRootPath,const List<Simstr> &)52 Index::Index( const char *			i_sOutputDirectory,
53 			  const char *			i_sIdlRootPath,
54 			  const List<Simstr> &	 )
55 	:	aService2Module(20),
56 		aModule2Service(20),
57 		sOutputDirectory(i_sOutputDirectory),
58 		sIdlRootPath(i_sIdlRootPath)
59 		// sCurModule
60 {
61 	::sIdlRootPath = i_sIdlRootPath;
62 }
63 
~Index()64 Index::~Index()
65 {
66 }
67 
68 void
GatherData(const List<Simstr> & i_rInputFileList)69 Index::GatherData(  const List<Simstr> & i_rInputFileList )
70 {
71 	for ( unsigned i = 0; i < i_rInputFileList.size(); ++i )
72 	{
73 		ReadFile( i_rInputFileList[i].str() );
74 	}
75 }
76 
77 void
WriteOutput(const char * i_sOuputFile)78 Index::WriteOutput( const char * i_sOuputFile )
79 {
80 	std::ofstream aOut( i_sOuputFile, std::ios::out );
81 	if (! aOut)
82 	{
83 		std::cerr << "Error: Indexfile \""
84 			 << i_sOuputFile
85 			 << "\" could not be created."
86 			 << std::endl;
87 		return;
88 	}
89 
90 	WriteStr(aOut, C_sFileBegin);
91 
92 	WriteStr(aOut, "<H2>Module Descriptions Index</H2>");
93 	WriteStr(aOut, C_sLineEnd );
94 
95 
96 	WriteTableFromHeap( aOut, aService2Module, C_sService, C_sModule, lt_html );
97 	WriteTableFromHeap( aOut, aModule2Service, C_sModule, C_sService, lt_idl );
98 
99 	WriteStr( aOut, C_sFileEnd );
100 	aOut.close();
101 }
102 
103 void
InsertSupportedService(const Simstr & i_sService)104 Index::InsertSupportedService( const Simstr &		i_sService )
105 {
106 	aService2Module.InsertValue( i_sService, sCurModule );
107 	aModule2Service.InsertValue( sCurModule, i_sService );
108 }
109 
110 void
ReadFile(const char * i_sFilename)111 Index::ReadFile(  const char * i_sFilename )
112 {
113 	static char				sOutputHtml[1020];
114 
115 	ModuleDescription	aModule;
116 	X2CParser			aParser(aModule);
117 
118 	// Parse
119 	bool bResult = aParser.Parse(i_sFilename);
120 	if (! bResult)
121 	{
122 		std::cerr << "Error: File \""
123 			 << i_sFilename
124 			 << "\" could not be parsed."
125 			 << std::endl;
126 		return;
127 	}
128 
129 	// Create Html:
130 	CreateHtmlFileName( sOutputHtml, aModule );
131 	HtmlCreator 	aHtmlCreator( sOutputHtml, aModule, sIdlRootPath );
132 	aHtmlCreator.Run();
133 
134 	// GetResults:
135 	sCurModule = aModule.ModuleName();
136 
137 	List< const MultipleTextElement* > aSupportedServices;
138 	aModule.Get_SupportedServices(aSupportedServices);
139 
140 	for ( unsigned s = 0; s < aSupportedServices.size(); ++s )
141 	{
142 		aSupportedServices[s]->Insert2Index(*this);
143 	}
144 }
145 
146 void
CreateHtmlFileName(char * o_sOutputHtml,const ModuleDescription & i_rModule)147 Index::CreateHtmlFileName(	char *						o_sOutputHtml,
148 							const ModuleDescription	&   i_rModule )
149 {
150     if ( strlen(sOutputDirectory.str()) + strlen(i_rModule.ModuleName()) > 1000 )
151     {
152      	strcpy( o_sOutputHtml, "too-long-filename.html");   // STRCPY SAFE HERE
153         return;
154     }
155 
156 	strcpy( o_sOutputHtml, sOutputDirectory.str() );        // STRCPY SAFE HERE
157 #if defined(WNT) || defined(OS2)
158 	strcat(o_sOutputHtml, "\\");                            // STRCAT SAFE HERE
159 #elif defined(UNX)
160 	strcat(o_sOutputHtml, "/");                             // STRCAT SAFE HERE
161 #else
162 #error	WNT or UNX have to be defined.
163 #endif
164 	strcat( o_sOutputHtml, i_rModule.ModuleName() );        // STRCAT SAFE HERE
165 	strcat( o_sOutputHtml, ".html" );                       // STRCAT SAFE HERE
166 }
167 
168 
169 void
WriteTableFromHeap(std::ostream & o_rOut,Heap & i_rHeap,const char * i_sIndexValue,const char * i_sIndexReference,E_LinkType i_eLinkType)170 Index::WriteTableFromHeap( std::ostream &  	o_rOut,
171 						   Heap & 	    i_rHeap,
172 						   const char *	i_sIndexValue,
173 						   const char *	i_sIndexReference,
174 						   E_LinkType		i_eLinkType )
175 {
176 	WriteStr(o_rOut, "<H3><BR>");
177 	WriteStr(o_rOut, i_sIndexValue );
178 	WriteStr(o_rOut, " -> ");
179 	WriteStr(o_rOut, i_sIndexReference );
180 	WriteStr(o_rOut, "</H3>\n");
181 
182 	WriteStr(o_rOut, C_sTableBegin);
183 	WriteHeap( o_rOut, i_rHeap, i_eLinkType );
184 	WriteStr(o_rOut, C_sTableEnd);
185 }
186 
187 
188 void
WriteHeap(std::ostream & o_rOut,Heap & i_rHeap,E_LinkType i_eLinkType)189 Index::WriteHeap( std::ostream &  	o_rOut,
190 				  Heap &	    i_rHeap,
191 		          E_LinkType 	i_eLinkType )
192 {
193 	static Simstr S_sKey;
194 	static char C_sSpaceInName[] = "&nbsp;&nbsp;&nbsp;";
195 	S_sKey = "";
196 
197 
198 	WriteStr( o_rOut, "<TR><TD width=33% valign=\"top\">" );
199 
200 	for ( HeapItem * pHeapTop = i_rHeap.ReleaseTop();
201 		  pHeapTop != 0;
202 		  pHeapTop = i_rHeap.ReleaseTop() )
203 	{
204 		if ( S_sKey != pHeapTop->Key() )
205 		{
206 			const char * pStart = pHeapTop->Key().str();
207 			const char * pBreak = strstr( pStart, " in ");
208 
209 			if (S_sKey.l()>0)
210 			{
211 				WriteStr( o_rOut, "</TD></TR>\n" );
212 				WriteStr( o_rOut, "<TR><TD width=33% valign=\"top\">" );
213 			}
214 
215 			if ( pBreak == 0 )
216 				WriteStr( o_rOut, pStart );
217 			else
218 			{
219 				o_rOut.write( pStart, pBreak - pStart );
220 				WriteStr( o_rOut, C_sSpaceInName );
221 				WriteStr( o_rOut, pBreak );
222 			}
223 			WriteStr( o_rOut, "</TD><TD width=66%>" );
224 			S_sKey = pHeapTop->Key();
225 		}
226 		else
227 		{
228 			WriteStr( o_rOut, "<BR>" );
229 		}
230 		WriteName( o_rOut, sIdlRootPath, pHeapTop->Value(), i_eLinkType );
231 		delete pHeapTop;
232 	}
233 
234 	WriteStr( o_rOut, "</TD></TR>\n" );
235 }
236 
237 
238 
239 /**	�bersicht der Struktur
240 
241 MODULEDESCRIPTION
242 {
243 	ModuleName,
244 	COMPONENTDESCRIPTION
245 	{
246 		Author,
247 		Name,
248 		Description,
249 		LoaderName,
250 		Language,
251 		Status,
252 		SupportedService+,
253 		ReferenceDocu*
254 		ServiceDependency*
255 		Type*
256 	}
257 	ProjectBuildDependency*
258 	RuntimeModuleDependency*
259 	ReferenceDocu*
260 	ServiceDependency*
261 	Type*
262 }
263 
264 
265 */
266 
267 
268 
269 
270 
271 
272