xref: /aoo41x/main/soldep/bootstrp/prodmap.cxx (revision d9e04f7d)
1*d9e04f7dSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*d9e04f7dSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*d9e04f7dSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*d9e04f7dSAndrew Rist  * distributed with this work for additional information
6*d9e04f7dSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*d9e04f7dSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*d9e04f7dSAndrew Rist  * "License"); you may not use this file except in compliance
9*d9e04f7dSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*d9e04f7dSAndrew Rist  *
11*d9e04f7dSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*d9e04f7dSAndrew Rist  *
13*d9e04f7dSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*d9e04f7dSAndrew Rist  * software distributed under the License is distributed on an
15*d9e04f7dSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*d9e04f7dSAndrew Rist  * KIND, either express or implied.  See the License for the
17*d9e04f7dSAndrew Rist  * specific language governing permissions and limitations
18*d9e04f7dSAndrew Rist  * under the License.
19*d9e04f7dSAndrew Rist  *
20*d9e04f7dSAndrew Rist  *************************************************************/
21*d9e04f7dSAndrew Rist 
22*d9e04f7dSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #include "prodmap.hxx"
25cdf0e10cSrcweir #include <tools/geninfo.hxx>
26cdf0e10cSrcweir #include <tools/fsys.hxx>
27cdf0e10cSrcweir #include "minormk.hxx"
28cdf0e10cSrcweir 
29cdf0e10cSrcweir #include <stdio.h>
30cdf0e10cSrcweir 
31cdf0e10cSrcweir #define PRODUCT_KEY 	"TARGETDESCRIPTION/PRODUCTS"
32cdf0e10cSrcweir #define DEPENDS_ON_KEY	"TARGETDESCRIPTION/DEPENDSON"
33cdf0e10cSrcweir #define BASED_ON_KEY	"TARGETDESCRIPTION/BASEDON"
34cdf0e10cSrcweir 
35cdf0e10cSrcweir //
36cdf0e10cSrcweir // class ProductMapper
37cdf0e10cSrcweir //
38cdf0e10cSrcweir 
39cdf0e10cSrcweir /*****************************************************************************/
ProductMapper()40cdf0e10cSrcweir ProductMapper::ProductMapper()
41cdf0e10cSrcweir /*****************************************************************************/
42cdf0e10cSrcweir 				: pVersionList( NULL ),
43cdf0e10cSrcweir 				pProductList( NULL )
44cdf0e10cSrcweir {
45cdf0e10cSrcweir }
46cdf0e10cSrcweir 
47cdf0e10cSrcweir /*****************************************************************************/
ProductMapper(GenericInformationList * pVerList)48cdf0e10cSrcweir ProductMapper::ProductMapper( GenericInformationList *pVerList )
49cdf0e10cSrcweir /*****************************************************************************/
50cdf0e10cSrcweir 				: pVersionList( pVerList ),
51cdf0e10cSrcweir 				pProductList( NULL )
52cdf0e10cSrcweir {
53cdf0e10cSrcweir 	if ( pVerList )
54cdf0e10cSrcweir 		CreateProductList( pVerList );
55cdf0e10cSrcweir }
56cdf0e10cSrcweir 
57cdf0e10cSrcweir /*****************************************************************************/
~ProductMapper()58cdf0e10cSrcweir ProductMapper::~ProductMapper()
59cdf0e10cSrcweir /*****************************************************************************/
60cdf0e10cSrcweir {
61cdf0e10cSrcweir 	delete pProductList;
62cdf0e10cSrcweir }
63cdf0e10cSrcweir 
64cdf0e10cSrcweir /*****************************************************************************/
CreateProductList(GenericInformationList * pVerList)65cdf0e10cSrcweir void ProductMapper::CreateProductList( GenericInformationList *pVerList )
66cdf0e10cSrcweir /*****************************************************************************/
67cdf0e10cSrcweir {
68cdf0e10cSrcweir 	/*
69cdf0e10cSrcweir 	creates a list of the following format:
70cdf0e10cSrcweir 
71cdf0e10cSrcweir 	ProductName Workspace                // 6.0 Final SRC641
72cdf0e10cSrcweir 	{                                    // {
73cdf0e10cSrcweir 		DependsOn                        //     DependsOn
74cdf0e10cSrcweir 		{                                //     {
75cdf0e10cSrcweir 			product1                     //
76cdf0e10cSrcweir 			product2                     //
77cdf0e10cSrcweir 			...                          //
78cdf0e10cSrcweir 		}                                //
79cdf0e10cSrcweir 		BasedOn                          //
80cdf0e10cSrcweir 		{                                //
81cdf0e10cSrcweir 			productX                     //
82cdf0e10cSrcweir 			productY                     //
83cdf0e10cSrcweir 			...                          //
84cdf0e10cSrcweir 		}                                //
85cdf0e10cSrcweir 	}                                    //
86cdf0e10cSrcweir 	*/
87cdf0e10cSrcweir 
88cdf0e10cSrcweir 	delete pProductList;
89cdf0e10cSrcweir 	pProductList = NULL;
90cdf0e10cSrcweir 
91cdf0e10cSrcweir 	pVersionList = pVerList;
92cdf0e10cSrcweir 
93cdf0e10cSrcweir 	if ( pVersionList ) {
94cdf0e10cSrcweir 		ByteString sProductKey( PRODUCT_KEY );
95cdf0e10cSrcweir 		ByteString sDependsOnKey( DEPENDS_ON_KEY );
96cdf0e10cSrcweir 		ByteString sBasedOnKey( BASED_ON_KEY );
97cdf0e10cSrcweir 
98cdf0e10cSrcweir 		for ( sal_uIntPtr i = 0; i < pVersionList->Count(); i++ ) {
99cdf0e10cSrcweir 			GenericInformation *pVersion = pVersionList->GetObject( i );
100cdf0e10cSrcweir 
101cdf0e10cSrcweir 			GenericInformation *pProducts = pVersion->GetSubInfo( sProductKey, sal_True );
102cdf0e10cSrcweir 			if ( pProducts ) {
103cdf0e10cSrcweir 				ByteString sProducts = pProducts->GetValue();
104cdf0e10cSrcweir 
105cdf0e10cSrcweir 				ByteString sDependsOn;
106cdf0e10cSrcweir 				GenericInformation *pDependsOn = pVersion->GetSubInfo( sDependsOnKey, sal_True );
107cdf0e10cSrcweir 				if ( pDependsOn )
108cdf0e10cSrcweir 					sDependsOn = pDependsOn->GetValue();
109cdf0e10cSrcweir 
110cdf0e10cSrcweir 				ByteString sBasedOn;
111cdf0e10cSrcweir 				GenericInformation *pBasedOn = pVersion->GetSubInfo( sBasedOnKey, sal_True );
112cdf0e10cSrcweir 				if ( pBasedOn )
113cdf0e10cSrcweir 					sBasedOn = pBasedOn->GetValue();
114cdf0e10cSrcweir 
115cdf0e10cSrcweir 				for ( sal_uInt16 x = 0; x < sProducts.GetTokenCount( ';' ); x++ ) {
116cdf0e10cSrcweir 					ByteString sProduct( sProducts.GetToken( x, ';' ));
117cdf0e10cSrcweir 					if( sProduct.Len()) {
118cdf0e10cSrcweir 						if ( !pProductList )
119cdf0e10cSrcweir 							pProductList = new GenericInformationList();
120cdf0e10cSrcweir 
121cdf0e10cSrcweir 						pProductList->InsertInfo( sProduct, *pVersion, sal_True, sal_True );
122cdf0e10cSrcweir 
123cdf0e10cSrcweir 						for ( sal_uInt16 y = 0; y < sDependsOn.GetTokenCount( ';' ); y++ ) {
124cdf0e10cSrcweir 							ByteString sDependsOnKey_l = sProduct;
125cdf0e10cSrcweir 							sDependsOnKey_l += "/DependsOn/";
126cdf0e10cSrcweir 							sDependsOnKey_l += sDependsOn.GetToken( y, ';' );
127cdf0e10cSrcweir 
128cdf0e10cSrcweir 							pProductList->InsertInfo( sDependsOnKey_l, "", sal_True, sal_True );
129cdf0e10cSrcweir 						}
130cdf0e10cSrcweir 						for ( sal_uInt16 z = 0; z < sBasedOn.GetTokenCount( ';' ); z++ ) {
131cdf0e10cSrcweir 							ByteString sBasedOnKey_l = sProduct;
132cdf0e10cSrcweir 							sBasedOnKey_l += "/BasedOn/";
133cdf0e10cSrcweir 							sBasedOnKey_l += sBasedOn.GetToken( z, ';' );
134cdf0e10cSrcweir 
135cdf0e10cSrcweir 							pProductList->InsertInfo( sBasedOnKey_l, "", sal_True, sal_True );
136cdf0e10cSrcweir 						}
137cdf0e10cSrcweir 					}
138cdf0e10cSrcweir 				}
139cdf0e10cSrcweir 			}
140cdf0e10cSrcweir 		}
141cdf0e10cSrcweir 	}
142cdf0e10cSrcweir }
143cdf0e10cSrcweir 
144cdf0e10cSrcweir /*****************************************************************************/
GetProductInformation(const ByteString & rProduct,GenericInformation * & pProductInfo)145cdf0e10cSrcweir sal_uInt16 ProductMapper::GetProductInformation(
146cdf0e10cSrcweir 	const ByteString &rProduct, GenericInformation *& pProductInfo )
147cdf0e10cSrcweir /*****************************************************************************/
148cdf0e10cSrcweir {
149cdf0e10cSrcweir 	pProductInfo = NULL;
150cdf0e10cSrcweir 
151cdf0e10cSrcweir 	if ( !pVersionList )
152cdf0e10cSrcweir 		return PRODUCT_MAPPER_NO_VERSION_INFORMATION;
153cdf0e10cSrcweir 
154cdf0e10cSrcweir 	if ( !pProductList )
155cdf0e10cSrcweir 		return PRODUCT_MAPPER_NO_PRODUCT;
156cdf0e10cSrcweir 
157cdf0e10cSrcweir 	ByteString sProductKey( rProduct );
158cdf0e10cSrcweir 	pProductInfo = pProductList->GetInfo( sProductKey, sal_True );
159cdf0e10cSrcweir 
160cdf0e10cSrcweir 	if ( !pProductInfo )
161cdf0e10cSrcweir 		return PRODUCT_MAPPER_NO_PRODUCT;
162cdf0e10cSrcweir 
163cdf0e10cSrcweir 	return PRODUCT_MAPPER_OK;
164cdf0e10cSrcweir }
165cdf0e10cSrcweir 
166cdf0e10cSrcweir /*****************************************************************************/
PrintDependentTargets(const ByteString & rProduct,sal_uInt16 nLevel)167cdf0e10cSrcweir sal_uInt16 ProductMapper::PrintDependentTargets(
168cdf0e10cSrcweir 	const ByteString &rProduct, sal_uInt16 nLevel )
169cdf0e10cSrcweir /*****************************************************************************/
170cdf0e10cSrcweir {
171cdf0e10cSrcweir 	GenericInformation *pProductInfo;
172cdf0e10cSrcweir 
173cdf0e10cSrcweir 	sal_uInt16 nReturn = GetProductInformation( rProduct, pProductInfo );
174cdf0e10cSrcweir 
175cdf0e10cSrcweir 	if ( nReturn == PRODUCT_MAPPER_OK ) {
176cdf0e10cSrcweir 		for ( sal_uInt16 i = 0; i < nLevel; i++ )
177cdf0e10cSrcweir 			fprintf( stdout, "    " );
178cdf0e10cSrcweir 		fprintf( stdout, "%s (%s)\n", pProductInfo->GetBuffer(),
179cdf0e10cSrcweir 			pProductInfo->GetValue().GetBuffer());
180cdf0e10cSrcweir 		aPrintedList.PutString( new ByteString( *pProductInfo ));
181cdf0e10cSrcweir 
182cdf0e10cSrcweir 		for ( sal_uIntPtr j = 0; j < pProductList->Count(); j++ ) {
183cdf0e10cSrcweir 			GenericInformation *pCandidate = pProductList->GetObject( j );
184cdf0e10cSrcweir 			ByteString sKey( "DEPENDSON/" );
185cdf0e10cSrcweir 			sKey += rProduct;
186cdf0e10cSrcweir 			GenericInformation *pDependsOn = pCandidate->GetSubInfo( sKey, sal_True );
187cdf0e10cSrcweir 			if ( pDependsOn )
188cdf0e10cSrcweir 				PrintDependentTargets( *pCandidate, nLevel + 1 );
189cdf0e10cSrcweir 		}
190cdf0e10cSrcweir 		if ( !nLevel ) {
191cdf0e10cSrcweir 			ByteString sKey( "BASEDON" );
192cdf0e10cSrcweir 			GenericInformation *pBasedOn = pProductInfo->GetSubInfo( sKey );
193cdf0e10cSrcweir 			if ( pBasedOn ) {
194cdf0e10cSrcweir 				GenericInformationList *pBases = pBasedOn->GetSubList();
195cdf0e10cSrcweir 				if ( pBases ) {
196cdf0e10cSrcweir 					for ( sal_uIntPtr k = 0; k < pBases->Count(); k++ ) {
197cdf0e10cSrcweir 						aBaseList.PutString( new ByteString( *pBases->GetObject( k )));
198cdf0e10cSrcweir 					}
199cdf0e10cSrcweir 				}
200cdf0e10cSrcweir 			}
201cdf0e10cSrcweir 		}
202cdf0e10cSrcweir 	}
203cdf0e10cSrcweir 
204cdf0e10cSrcweir 	return nReturn;
205cdf0e10cSrcweir }
206cdf0e10cSrcweir 
207cdf0e10cSrcweir /*****************************************************************************/
PrintAndDeleteBaseList()208cdf0e10cSrcweir sal_uInt16 ProductMapper::PrintAndDeleteBaseList()
209cdf0e10cSrcweir /*****************************************************************************/
210cdf0e10cSrcweir {
211cdf0e10cSrcweir 	if ( aBaseList.Count()) {
212cdf0e10cSrcweir 		fprintf( stdout, "\nbased on\n" );
213cdf0e10cSrcweir 		while ( aBaseList.Count()) {
214cdf0e10cSrcweir 			ByteString sProduct( *aBaseList.GetObject(( sal_uIntPtr ) 0 ));
215cdf0e10cSrcweir 			if ( aPrintedList.IsString( aBaseList.GetObject(( sal_uIntPtr ) 0 )) == NOT_THERE ) {
216cdf0e10cSrcweir 				aPrintedList.PutString( aBaseList.GetObject(( sal_uIntPtr ) 0 ));
217cdf0e10cSrcweir 				PrintDependentTargets( sProduct );
218cdf0e10cSrcweir 			}
219cdf0e10cSrcweir 			else
220cdf0e10cSrcweir 				delete aBaseList.GetObject(( sal_uIntPtr ) 0 );
221cdf0e10cSrcweir 
222cdf0e10cSrcweir 			aBaseList.Remove(( sal_uIntPtr ) 0 );
223cdf0e10cSrcweir 		}
224cdf0e10cSrcweir 		while ( aPrintedList.Count())
225cdf0e10cSrcweir 			delete aPrintedList.Remove(( sal_uIntPtr ) 0 );
226cdf0e10cSrcweir 
227cdf0e10cSrcweir 		fprintf( stdout, "\n" );
228cdf0e10cSrcweir 	}
229cdf0e10cSrcweir 	return PRODUCT_MAPPER_OK;
230cdf0e10cSrcweir }
231cdf0e10cSrcweir 
232cdf0e10cSrcweir /*****************************************************************************/
PrintDependencies(const ByteString & rProduct)233cdf0e10cSrcweir sal_uInt16 ProductMapper::PrintDependencies( const ByteString &rProduct )
234cdf0e10cSrcweir /*****************************************************************************/
235cdf0e10cSrcweir {
236cdf0e10cSrcweir 	sal_uInt16 nResult = PrintDependentTargets( rProduct );
237cdf0e10cSrcweir 	PrintAndDeleteBaseList();
238cdf0e10cSrcweir 	return nResult;
239cdf0e10cSrcweir }
240cdf0e10cSrcweir 
241cdf0e10cSrcweir /*****************************************************************************/
PrintProductList()242cdf0e10cSrcweir sal_uInt16 ProductMapper::PrintProductList()
243cdf0e10cSrcweir /*****************************************************************************/
244cdf0e10cSrcweir {
245cdf0e10cSrcweir 	if ( !pVersionList )
246cdf0e10cSrcweir 		return PRODUCT_MAPPER_NO_VERSION_INFORMATION;
247cdf0e10cSrcweir 
248cdf0e10cSrcweir 	if ( !pProductList || !pProductList->Count())
249cdf0e10cSrcweir 		return PRODUCT_MAPPER_NO_PRODUCT;
250cdf0e10cSrcweir 
251cdf0e10cSrcweir 	if ( pProductList->Count()) {
252cdf0e10cSrcweir 		for ( sal_uIntPtr i = 0; i < pProductList->Count(); i++ )
253cdf0e10cSrcweir 			fprintf( stdout, "%s (%s)\n",
254cdf0e10cSrcweir 				pProductList->GetObject( i )->GetBuffer(),
255cdf0e10cSrcweir 				pProductList->GetObject( i )->GetValue().GetBuffer());
256cdf0e10cSrcweir 		fprintf( stdout, "\n" );
257cdf0e10cSrcweir 	}
258cdf0e10cSrcweir 
259cdf0e10cSrcweir 	return PRODUCT_MAPPER_OK;
260cdf0e10cSrcweir }
261cdf0e10cSrcweir 
262cdf0e10cSrcweir /*****************************************************************************/
GetMinorList(const ByteString & rVersion,const ByteString & rEnvironment)263cdf0e10cSrcweir SByteStringList *ProductMapper::GetMinorList(
264cdf0e10cSrcweir 	const ByteString &rVersion, const ByteString &rEnvironment )
265cdf0e10cSrcweir /*****************************************************************************/
266cdf0e10cSrcweir {
267cdf0e10cSrcweir 	SByteStringList *pList = NULL;
268cdf0e10cSrcweir 
269cdf0e10cSrcweir 	if ( pVersionList ) {
270cdf0e10cSrcweir 		String sRoot( GetVersionRoot( pVersionList, rVersion ));
271cdf0e10cSrcweir 		if ( sRoot.Len()) {
272cdf0e10cSrcweir 			DirEntry aEntry( sRoot );
273cdf0e10cSrcweir 			aEntry += DirEntry( String( rEnvironment, RTL_TEXTENCODING_ASCII_US ));
274cdf0e10cSrcweir 			String sWildcard( String::CreateFromAscii( "inc.*" ));
275cdf0e10cSrcweir 			aEntry += DirEntry( sWildcard );
276cdf0e10cSrcweir 
277cdf0e10cSrcweir 			Dir aDir( aEntry, FSYS_KIND_DIR );
278cdf0e10cSrcweir 			for ( sal_uInt16 i = 0; i < aDir.Count(); i++ ) {
279cdf0e10cSrcweir 				ByteString sInc( aDir[ i ].GetName(), RTL_TEXTENCODING_ASCII_US );
280cdf0e10cSrcweir 				if ( sInc.GetTokenCount( '.' ) > 1 ) {
281cdf0e10cSrcweir 					if ( !pList )
282cdf0e10cSrcweir 						pList = new SByteStringList();
283cdf0e10cSrcweir 					pList->PutString( new ByteString( sInc.GetToken( 1, '.' )));
284cdf0e10cSrcweir 				}
285cdf0e10cSrcweir 			}
286cdf0e10cSrcweir 		}
287cdf0e10cSrcweir 	}
288cdf0e10cSrcweir 	return pList;
289cdf0e10cSrcweir }
290cdf0e10cSrcweir 
291cdf0e10cSrcweir /*****************************************************************************/
GetVersionRoot(GenericInformationList * pList,const ByteString & rVersion)292cdf0e10cSrcweir String ProductMapper::GetVersionRoot(
293cdf0e10cSrcweir 	GenericInformationList *pList, const ByteString &rVersion )
294cdf0e10cSrcweir /*****************************************************************************/
295cdf0e10cSrcweir {
296cdf0e10cSrcweir 	ByteString sKey( rVersion );
297cdf0e10cSrcweir 	GenericInformation *pVersion = pList->GetInfo( sKey );
298cdf0e10cSrcweir 	if ( pVersion ) {
299cdf0e10cSrcweir #ifdef UNX
300cdf0e10cSrcweir 		sKey = "drives/o:/unixvolume";
301cdf0e10cSrcweir 		GenericInformation *pUnixVolume = pVersion->GetSubInfo( sKey, sal_True );
302cdf0e10cSrcweir 		ByteString sPath;
303cdf0e10cSrcweir 		if ( pUnixVolume )
304cdf0e10cSrcweir 			sPath = pUnixVolume->GetValue();
305cdf0e10cSrcweir 		sPath += "/";
306cdf0e10cSrcweir #else
307cdf0e10cSrcweir 		ByteString sPath( "o:\\" );
308cdf0e10cSrcweir #endif
309cdf0e10cSrcweir 		sKey = "settings/path";
310cdf0e10cSrcweir 		GenericInformation *pPath = pVersion->GetSubInfo( sKey, sal_True );
311cdf0e10cSrcweir 		if ( pPath ) {
312cdf0e10cSrcweir 			sPath += pPath->GetValue().GetToken( 0, '\\' );
313cdf0e10cSrcweir 			sPath += "/";
314cdf0e10cSrcweir 		}
315cdf0e10cSrcweir #ifdef UNX
316cdf0e10cSrcweir 		sPath.SearchAndReplaceAll( "\\", "/" );
317cdf0e10cSrcweir 		while( sPath.SearchAndReplace( "//", "/" ) != STRING_NOTFOUND ) {};
318cdf0e10cSrcweir #else
319cdf0e10cSrcweir 		sPath.SearchAndReplaceAll( "/", "\\" );
320cdf0e10cSrcweir 		while( sPath.SearchAndReplace( "\\\\", "\\" ) != STRING_NOTFOUND ) {};
321cdf0e10cSrcweir #endif
322cdf0e10cSrcweir 
323cdf0e10cSrcweir 		return String( sPath, RTL_TEXTENCODING_ASCII_US );
324cdf0e10cSrcweir 	}
325cdf0e10cSrcweir 	return String();
326cdf0e10cSrcweir }
327cdf0e10cSrcweir 
328cdf0e10cSrcweir /*****************************************************************************/
GetBases(GenericInformation * pProductInfo,sal_uInt16 nLevel,BaseProductList * pBases)329cdf0e10cSrcweir BaseProductList *ProductMapper::GetBases(
330cdf0e10cSrcweir 	GenericInformation *pProductInfo, sal_uInt16 nLevel,
331cdf0e10cSrcweir 	BaseProductList *pBases )
332cdf0e10cSrcweir /*****************************************************************************/
333cdf0e10cSrcweir {
334cdf0e10cSrcweir 	if ( !pBases )
335cdf0e10cSrcweir 		pBases = new BaseProductList();
336cdf0e10cSrcweir 
337cdf0e10cSrcweir 	if ( pProductInfo ) {
338cdf0e10cSrcweir 		ByteString sCandidate( *pProductInfo );
339cdf0e10cSrcweir 		sCandidate += " (";
340cdf0e10cSrcweir 		sCandidate += pProductInfo->GetValue();
341cdf0e10cSrcweir 		sCandidate += ")";
342cdf0e10cSrcweir 
343cdf0e10cSrcweir 		ByteString sKey( "BASEDON" );
344cdf0e10cSrcweir 		GenericInformation *pBasedOn = pProductInfo->GetSubInfo( sKey );
345cdf0e10cSrcweir 		if ( pBasedOn ) {
346cdf0e10cSrcweir 			GenericInformationList *pBasesInfo = pBasedOn->GetSubList();
347cdf0e10cSrcweir 			if ( pBasesInfo ) {
348cdf0e10cSrcweir 				for ( sal_uIntPtr k = 0; k < pBasesInfo->Count(); k++ ) {
349cdf0e10cSrcweir 					GenericInformation *pBaseProduct;
350cdf0e10cSrcweir 					if ( GetProductInformation( *pBasesInfo->GetObject( k ), pBaseProduct ) == PRODUCT_MAPPER_OK )
351cdf0e10cSrcweir 						GetBases( pBaseProduct, ++ nLevel, pBases );
352cdf0e10cSrcweir 				}
353cdf0e10cSrcweir 			}
354cdf0e10cSrcweir 		}
355cdf0e10cSrcweir 		sal_Bool bFound = sal_False;
356cdf0e10cSrcweir 		ByteString sUpperCandidate( sCandidate );
357cdf0e10cSrcweir 		sUpperCandidate.ToUpperAscii();
358cdf0e10cSrcweir 		for ( sal_uInt16 i = 0; i < pBases->Count() && !bFound; i++ ) {
359cdf0e10cSrcweir 			ByteString sTest( *pBases->GetObject( i ));
360cdf0e10cSrcweir 			if ( sTest.ToUpperAscii() == sUpperCandidate )
361cdf0e10cSrcweir 				bFound = sal_True;
362cdf0e10cSrcweir 		}
363cdf0e10cSrcweir 		if ( !bFound )
364cdf0e10cSrcweir 			pBases->Insert( new ByteString( sCandidate ), ( sal_uIntPtr ) 0 );
365cdf0e10cSrcweir 	}
366cdf0e10cSrcweir 	return pBases;
367cdf0e10cSrcweir }
368cdf0e10cSrcweir 
369cdf0e10cSrcweir /*****************************************************************************/
PrintMinorList(const ByteString rProduct,const ByteString rEnvironment)370cdf0e10cSrcweir sal_uInt16 ProductMapper::PrintMinorList(
371cdf0e10cSrcweir 	const ByteString rProduct, const ByteString rEnvironment )
372cdf0e10cSrcweir /*****************************************************************************/
373cdf0e10cSrcweir {
374cdf0e10cSrcweir 	if ( !pVersionList )
375cdf0e10cSrcweir 		return PRODUCT_MAPPER_NO_VERSION_INFORMATION;
376cdf0e10cSrcweir 
377cdf0e10cSrcweir 	if ( !pProductList || !pProductList->Count())
378cdf0e10cSrcweir 		return PRODUCT_MAPPER_NO_PRODUCT;
379cdf0e10cSrcweir 
380cdf0e10cSrcweir 	GenericInformation *pProductInfo;
381cdf0e10cSrcweir 	GetProductInformation( rProduct, pProductInfo );
382cdf0e10cSrcweir 	if ( !pProductInfo )
383cdf0e10cSrcweir 		return PRODUCT_MAPPER_NO_PRODUCT;
384cdf0e10cSrcweir 
385cdf0e10cSrcweir 	BaseProductList *pBases = GetBases( pProductInfo );
386cdf0e10cSrcweir 	if ( pBases->Count()) {
387cdf0e10cSrcweir 		if ( pBases->Count() > 1 )
388cdf0e10cSrcweir 			fprintf( stdout, "Product \"%s\" based on ", pBases->GetObject(( sal_uIntPtr ) 0 )->GetBuffer());
389cdf0e10cSrcweir 		else
390cdf0e10cSrcweir 			fprintf( stdout, "Product \"%s\" based on no other products", pBases->GetObject(( sal_uIntPtr ) 0 )->GetBuffer());
391cdf0e10cSrcweir 
392cdf0e10cSrcweir 		for ( sal_uIntPtr i = 1; i < pBases->Count(); i++ ) {
393cdf0e10cSrcweir 			fprintf( stdout, "\"%s\"", pBases->GetObject( i )->GetBuffer());
394cdf0e10cSrcweir 			if ( i < pBases->Count() - 1 )
395cdf0e10cSrcweir 				fprintf( stdout, ", " );
396cdf0e10cSrcweir 		}
397cdf0e10cSrcweir 		fprintf( stdout, "\n\n" );
398cdf0e10cSrcweir 	}
399cdf0e10cSrcweir 	sal_uInt16 nResult = PRODUCT_MAPPER_OK;
400cdf0e10cSrcweir 
401cdf0e10cSrcweir 	if ( rEnvironment.Len())
402cdf0e10cSrcweir 		nResult = PrintSingleMinorList( pProductInfo, pBases, rEnvironment );
403cdf0e10cSrcweir 	else {
404cdf0e10cSrcweir 		ByteString sEnvKey( pProductInfo->GetValue());
405cdf0e10cSrcweir 		sEnvKey += "/Environments";
406cdf0e10cSrcweir 
407cdf0e10cSrcweir 		GenericInformation *pEnvironmentInfo = pVersionList->GetInfo( sEnvKey, sal_True );
408cdf0e10cSrcweir 		if ( pEnvironmentInfo ) {
409cdf0e10cSrcweir 			GenericInformationList *pEnvironmentList = pEnvironmentInfo->GetSubList();
410cdf0e10cSrcweir 			if ( pEnvironmentList ) {
411cdf0e10cSrcweir 				for ( sal_uIntPtr i = 0; i < pEnvironmentList->Count(); i++ ) {
412cdf0e10cSrcweir 					sal_uInt16 nTmp = PrintSingleMinorList( pProductInfo, pBases, *pEnvironmentList->GetObject( i ));
413cdf0e10cSrcweir 					if ( nTmp != PRODUCT_MAPPER_OK )
414cdf0e10cSrcweir 						nResult = nTmp;
415cdf0e10cSrcweir 				}
416cdf0e10cSrcweir 			}
417cdf0e10cSrcweir 		}
418cdf0e10cSrcweir 	}
419cdf0e10cSrcweir 
420cdf0e10cSrcweir 	for ( sal_uIntPtr m = 0; m < pBases->Count(); m++ )
421cdf0e10cSrcweir 		delete pBases->GetObject( m );
422cdf0e10cSrcweir 	delete pBases;
423cdf0e10cSrcweir 
424cdf0e10cSrcweir 	return nResult;
425cdf0e10cSrcweir }
426cdf0e10cSrcweir 
427cdf0e10cSrcweir /*****************************************************************************/
PrintSingleMinorList(GenericInformation * pProductInfo,BaseProductList * pBases,const ByteString rEnvironment)428cdf0e10cSrcweir sal_uInt16 ProductMapper::PrintSingleMinorList(
429cdf0e10cSrcweir 	GenericInformation *pProductInfo, BaseProductList *pBases,
430cdf0e10cSrcweir 	const ByteString rEnvironment )
431cdf0e10cSrcweir /*****************************************************************************/
432cdf0e10cSrcweir {
433cdf0e10cSrcweir 	DirEntry aRoot( GetVersionRoot( pVersionList, pProductInfo->GetValue()));
434cdf0e10cSrcweir 	aRoot += DirEntry( String( rEnvironment, RTL_TEXTENCODING_ASCII_US ));
435cdf0e10cSrcweir 	if ( !aRoot.Exists())
436cdf0e10cSrcweir 		return PRODUCT_MAPPER_OK;
437cdf0e10cSrcweir 
438cdf0e10cSrcweir 	SByteStringList *pMinors = GetMinorList( pProductInfo->GetValue(), rEnvironment );
439cdf0e10cSrcweir 	if ( !pMinors )
440cdf0e10cSrcweir 		pMinors = new SByteStringList();
441cdf0e10cSrcweir 	pMinors->Insert( new ByteString( "" ), LIST_APPEND );
442cdf0e10cSrcweir 
443cdf0e10cSrcweir 	SByteStringList aOutputList;
444cdf0e10cSrcweir 	sal_Bool bUnknownMinor = sal_False;
445cdf0e10cSrcweir 	for ( sal_uIntPtr i = 0; i < pMinors->Count(); i++ ) {
446cdf0e10cSrcweir 		ByteString sOutput;
447cdf0e10cSrcweir 		ByteString sProductVersion;
448cdf0e10cSrcweir 
449cdf0e10cSrcweir 		for ( sal_uIntPtr j = 0; j < pBases->Count(); j++ ) {
450cdf0e10cSrcweir 			ByteString sCurProduct( *pBases->GetObject( j ));
451cdf0e10cSrcweir 			ByteString sVersion( sCurProduct.GetToken( sCurProduct.GetTokenCount( '(' ) - 1, '(' ).GetToken( 0, ')' ));
452cdf0e10cSrcweir 			if ( !j )
453cdf0e10cSrcweir 				sProductVersion = sVersion;
454cdf0e10cSrcweir 
455cdf0e10cSrcweir 			MinorMk *pMinorMk = new MinorMk(
456cdf0e10cSrcweir 				pVersionList, sProductVersion, sVersion, rEnvironment, *pMinors->GetObject( i ));
457cdf0e10cSrcweir 
458cdf0e10cSrcweir 			ByteString sMinor( pMinorMk->GetLastMinor().GetBuffer());
459cdf0e10cSrcweir 			if ( !sMinor.Len()) {
460cdf0e10cSrcweir 				sMinor = "!";
461cdf0e10cSrcweir 				bUnknownMinor = sal_True;
462cdf0e10cSrcweir 			}
463cdf0e10cSrcweir 			if ( j == 0 ) {
464cdf0e10cSrcweir 				sOutput += pMinorMk->GetBuildNr();
465cdf0e10cSrcweir 				sOutput += " ";
466cdf0e10cSrcweir 
467cdf0e10cSrcweir 				if ( i == pMinors->Count() - 1 )
468cdf0e10cSrcweir 					sOutput += "flat: ";
469cdf0e10cSrcweir 				else
470cdf0e10cSrcweir 					sOutput += "      ";
471cdf0e10cSrcweir 			}
472cdf0e10cSrcweir 			sOutput += sVersion;
473cdf0e10cSrcweir 			sOutput += ".";
474cdf0e10cSrcweir 			sOutput += sMinor;
475cdf0e10cSrcweir 			sOutput += "(";
476cdf0e10cSrcweir 			sOutput += pMinorMk->GetBuildNr();
477cdf0e10cSrcweir 			sOutput += ")  ";
478cdf0e10cSrcweir 		}
479cdf0e10cSrcweir 		aOutputList.PutString( new ByteString( sOutput ));
480cdf0e10cSrcweir 	}
481cdf0e10cSrcweir 	ByteString sOldMinor;
482cdf0e10cSrcweir 
483cdf0e10cSrcweir 	if ( aOutputList.Count())
484cdf0e10cSrcweir 		fprintf( stdout, "Available builds on %s:\n", rEnvironment.GetBuffer());
485cdf0e10cSrcweir 
486cdf0e10cSrcweir 	for ( sal_uIntPtr o = 0; o < aOutputList.Count(); o++ ) {
487cdf0e10cSrcweir 		ByteString sOutput( *aOutputList.GetObject( o ));
488cdf0e10cSrcweir 		sOutput = sOutput.Copy( sOutput.GetToken( 0, ' ' ).Len() + 1 );
489cdf0e10cSrcweir 
490cdf0e10cSrcweir 		ByteString sCurMinor( sOutput.GetToken( 1, '.' ).GetToken( 0, '(' ));
491cdf0e10cSrcweir 		if ( sOldMinor.Len() && sCurMinor < sOldMinor ) {
492cdf0e10cSrcweir 			fprintf( stdout, "      ----------\n" );
493cdf0e10cSrcweir 		}
494cdf0e10cSrcweir 		sOldMinor = sCurMinor;
495cdf0e10cSrcweir 
496cdf0e10cSrcweir 		fprintf( stdout, "%s\n", sOutput.GetBuffer());
497cdf0e10cSrcweir 		delete aOutputList.GetObject( o );
498cdf0e10cSrcweir 	}
499cdf0e10cSrcweir 	if ( bUnknownMinor )
500cdf0e10cSrcweir 		fprintf( stdout, "Symbol ! indcates that at least one minor could not be found\n\n" );
501cdf0e10cSrcweir 	else if ( aOutputList.Count())
502cdf0e10cSrcweir 		fprintf( stdout, "\n" );
503cdf0e10cSrcweir 
504cdf0e10cSrcweir 	for ( sal_uIntPtr l = 0; l < pMinors->Count(); l++ )
505cdf0e10cSrcweir 		delete pMinors->GetObject( l );
506cdf0e10cSrcweir 	delete pMinors;
507cdf0e10cSrcweir 
508cdf0e10cSrcweir 	return PRODUCT_MAPPER_OK;
509cdf0e10cSrcweir }
510cdf0e10cSrcweir 
511cdf0e10cSrcweir 
512cdf0e10cSrcweir 
513cdf0e10cSrcweir 
514