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