merge the formfield patch from ooo-build
[ooovba.git] / soldep / bootstrp / prodmap.cxx
blobfa99733ffb7c91052627022c4151b1658343add9
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: prodmap.cxx,v $
10 * $Revision: 1.4 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #include "prodmap.hxx"
32 #include <tools/geninfo.hxx>
33 #include <tools/fsys.hxx>
34 #include "minormk.hxx"
36 #include <stdio.h>
38 #define PRODUCT_KEY "TARGETDESCRIPTION/PRODUCTS"
39 #define DEPENDS_ON_KEY "TARGETDESCRIPTION/DEPENDSON"
40 #define BASED_ON_KEY "TARGETDESCRIPTION/BASEDON"
43 // class ProductMapper
46 /*****************************************************************************/
47 ProductMapper::ProductMapper()
48 /*****************************************************************************/
49 : pVersionList( NULL ),
50 pProductList( NULL )
54 /*****************************************************************************/
55 ProductMapper::ProductMapper( GenericInformationList *pVerList )
56 /*****************************************************************************/
57 : pVersionList( pVerList ),
58 pProductList( NULL )
60 if ( pVerList )
61 CreateProductList( pVerList );
64 /*****************************************************************************/
65 ProductMapper::~ProductMapper()
66 /*****************************************************************************/
68 delete pProductList;
71 /*****************************************************************************/
72 void ProductMapper::CreateProductList( GenericInformationList *pVerList )
73 /*****************************************************************************/
76 creates a list of the following format:
78 ProductName Workspace // 6.0 Final SRC641
79 { // {
80 DependsOn // DependsOn
81 { // {
82 product1 //
83 product2 //
84 ... //
85 } //
86 BasedOn //
87 { //
88 productX //
89 productY //
90 ... //
91 } //
92 } //
95 delete pProductList;
96 pProductList = NULL;
98 pVersionList = pVerList;
100 if ( pVersionList ) {
101 ByteString sProductKey( PRODUCT_KEY );
102 ByteString sDependsOnKey( DEPENDS_ON_KEY );
103 ByteString sBasedOnKey( BASED_ON_KEY );
105 for ( ULONG i = 0; i < pVersionList->Count(); i++ ) {
106 GenericInformation *pVersion = pVersionList->GetObject( i );
108 GenericInformation *pProducts = pVersion->GetSubInfo( sProductKey, TRUE );
109 if ( pProducts ) {
110 ByteString sProducts = pProducts->GetValue();
112 ByteString sDependsOn;
113 GenericInformation *pDependsOn = pVersion->GetSubInfo( sDependsOnKey, TRUE );
114 if ( pDependsOn )
115 sDependsOn = pDependsOn->GetValue();
117 ByteString sBasedOn;
118 GenericInformation *pBasedOn = pVersion->GetSubInfo( sBasedOnKey, TRUE );
119 if ( pBasedOn )
120 sBasedOn = pBasedOn->GetValue();
122 for ( USHORT x = 0; x < sProducts.GetTokenCount( ';' ); x++ ) {
123 ByteString sProduct( sProducts.GetToken( x, ';' ));
124 if( sProduct.Len()) {
125 if ( !pProductList )
126 pProductList = new GenericInformationList();
128 pProductList->InsertInfo( sProduct, *pVersion, TRUE, TRUE );
130 for ( USHORT y = 0; y < sDependsOn.GetTokenCount( ';' ); y++ ) {
131 ByteString sDependsOnKey_l = sProduct;
132 sDependsOnKey_l += "/DependsOn/";
133 sDependsOnKey_l += sDependsOn.GetToken( y, ';' );
135 pProductList->InsertInfo( sDependsOnKey_l, "", TRUE, TRUE );
137 for ( USHORT z = 0; z < sBasedOn.GetTokenCount( ';' ); z++ ) {
138 ByteString sBasedOnKey_l = sProduct;
139 sBasedOnKey_l += "/BasedOn/";
140 sBasedOnKey_l += sBasedOn.GetToken( z, ';' );
142 pProductList->InsertInfo( sBasedOnKey_l, "", TRUE, TRUE );
151 /*****************************************************************************/
152 USHORT ProductMapper::GetProductInformation(
153 const ByteString &rProduct, GenericInformation *& pProductInfo )
154 /*****************************************************************************/
156 pProductInfo = NULL;
158 if ( !pVersionList )
159 return PRODUCT_MAPPER_NO_VERSION_INFORMATION;
161 if ( !pProductList )
162 return PRODUCT_MAPPER_NO_PRODUCT;
164 ByteString sProductKey( rProduct );
165 pProductInfo = pProductList->GetInfo( sProductKey, TRUE );
167 if ( !pProductInfo )
168 return PRODUCT_MAPPER_NO_PRODUCT;
170 return PRODUCT_MAPPER_OK;
173 /*****************************************************************************/
174 USHORT ProductMapper::PrintDependentTargets(
175 const ByteString &rProduct, USHORT nLevel )
176 /*****************************************************************************/
178 GenericInformation *pProductInfo;
180 USHORT nReturn = GetProductInformation( rProduct, pProductInfo );
182 if ( nReturn == PRODUCT_MAPPER_OK ) {
183 for ( USHORT i = 0; i < nLevel; i++ )
184 fprintf( stdout, " " );
185 fprintf( stdout, "%s (%s)\n", pProductInfo->GetBuffer(),
186 pProductInfo->GetValue().GetBuffer());
187 aPrintedList.PutString( new ByteString( *pProductInfo ));
189 for ( ULONG j = 0; j < pProductList->Count(); j++ ) {
190 GenericInformation *pCandidate = pProductList->GetObject( j );
191 ByteString sKey( "DEPENDSON/" );
192 sKey += rProduct;
193 GenericInformation *pDependsOn = pCandidate->GetSubInfo( sKey, TRUE );
194 if ( pDependsOn )
195 PrintDependentTargets( *pCandidate, nLevel + 1 );
197 if ( !nLevel ) {
198 ByteString sKey( "BASEDON" );
199 GenericInformation *pBasedOn = pProductInfo->GetSubInfo( sKey );
200 if ( pBasedOn ) {
201 GenericInformationList *pBases = pBasedOn->GetSubList();
202 if ( pBases ) {
203 for ( ULONG k = 0; k < pBases->Count(); k++ ) {
204 aBaseList.PutString( new ByteString( *pBases->GetObject( k )));
211 return nReturn;
214 /*****************************************************************************/
215 USHORT ProductMapper::PrintAndDeleteBaseList()
216 /*****************************************************************************/
218 if ( aBaseList.Count()) {
219 fprintf( stdout, "\nbased on\n" );
220 while ( aBaseList.Count()) {
221 ByteString sProduct( *aBaseList.GetObject(( ULONG ) 0 ));
222 if ( aPrintedList.IsString( aBaseList.GetObject(( ULONG ) 0 )) == NOT_THERE ) {
223 aPrintedList.PutString( aBaseList.GetObject(( ULONG ) 0 ));
224 PrintDependentTargets( sProduct );
226 else
227 delete aBaseList.GetObject(( ULONG ) 0 );
229 aBaseList.Remove(( ULONG ) 0 );
231 while ( aPrintedList.Count())
232 delete aPrintedList.Remove(( ULONG ) 0 );
234 fprintf( stdout, "\n" );
236 return PRODUCT_MAPPER_OK;
239 /*****************************************************************************/
240 USHORT ProductMapper::PrintDependencies( const ByteString &rProduct )
241 /*****************************************************************************/
243 USHORT nResult = PrintDependentTargets( rProduct );
244 PrintAndDeleteBaseList();
245 return nResult;
248 /*****************************************************************************/
249 USHORT ProductMapper::PrintProductList()
250 /*****************************************************************************/
252 if ( !pVersionList )
253 return PRODUCT_MAPPER_NO_VERSION_INFORMATION;
255 if ( !pProductList || !pProductList->Count())
256 return PRODUCT_MAPPER_NO_PRODUCT;
258 if ( pProductList->Count()) {
259 for ( ULONG i = 0; i < pProductList->Count(); i++ )
260 fprintf( stdout, "%s (%s)\n",
261 pProductList->GetObject( i )->GetBuffer(),
262 pProductList->GetObject( i )->GetValue().GetBuffer());
263 fprintf( stdout, "\n" );
266 return PRODUCT_MAPPER_OK;
269 /*****************************************************************************/
270 SByteStringList *ProductMapper::GetMinorList(
271 const ByteString &rVersion, const ByteString &rEnvironment )
272 /*****************************************************************************/
274 SByteStringList *pList = NULL;
276 if ( pVersionList ) {
277 String sRoot( GetVersionRoot( pVersionList, rVersion ));
278 if ( sRoot.Len()) {
279 DirEntry aEntry( sRoot );
280 aEntry += DirEntry( String( rEnvironment, RTL_TEXTENCODING_ASCII_US ));
281 String sWildcard( String::CreateFromAscii( "inc.*" ));
282 aEntry += DirEntry( sWildcard );
284 Dir aDir( aEntry, FSYS_KIND_DIR );
285 for ( USHORT i = 0; i < aDir.Count(); i++ ) {
286 ByteString sInc( aDir[ i ].GetName(), RTL_TEXTENCODING_ASCII_US );
287 if ( sInc.GetTokenCount( '.' ) > 1 ) {
288 if ( !pList )
289 pList = new SByteStringList();
290 pList->PutString( new ByteString( sInc.GetToken( 1, '.' )));
295 return pList;
298 /*****************************************************************************/
299 String ProductMapper::GetVersionRoot(
300 GenericInformationList *pList, const ByteString &rVersion )
301 /*****************************************************************************/
303 ByteString sKey( rVersion );
304 GenericInformation *pVersion = pList->GetInfo( sKey );
305 if ( pVersion ) {
306 #ifdef UNX
307 sKey = "drives/o:/unixvolume";
308 GenericInformation *pUnixVolume = pVersion->GetSubInfo( sKey, TRUE );
309 ByteString sPath;
310 if ( pUnixVolume )
311 sPath = pUnixVolume->GetValue();
312 sPath += "/";
313 #else
314 ByteString sPath( "o:\\" );
315 #endif
316 sKey = "settings/path";
317 GenericInformation *pPath = pVersion->GetSubInfo( sKey, TRUE );
318 if ( pPath ) {
319 sPath += pPath->GetValue().GetToken( 0, '\\' );
320 sPath += "/";
322 #ifdef UNX
323 sPath.SearchAndReplaceAll( "\\", "/" );
324 while( sPath.SearchAndReplace( "//", "/" ) != STRING_NOTFOUND ) {};
325 #else
326 sPath.SearchAndReplaceAll( "/", "\\" );
327 while( sPath.SearchAndReplace( "\\\\", "\\" ) != STRING_NOTFOUND ) {};
328 #endif
330 return String( sPath, RTL_TEXTENCODING_ASCII_US );
332 return String();
335 /*****************************************************************************/
336 BaseProductList *ProductMapper::GetBases(
337 GenericInformation *pProductInfo, USHORT nLevel,
338 BaseProductList *pBases )
339 /*****************************************************************************/
341 if ( !pBases )
342 pBases = new BaseProductList();
344 if ( pProductInfo ) {
345 ByteString sCandidate( *pProductInfo );
346 sCandidate += " (";
347 sCandidate += pProductInfo->GetValue();
348 sCandidate += ")";
350 ByteString sKey( "BASEDON" );
351 GenericInformation *pBasedOn = pProductInfo->GetSubInfo( sKey );
352 if ( pBasedOn ) {
353 GenericInformationList *pBasesInfo = pBasedOn->GetSubList();
354 if ( pBasesInfo ) {
355 for ( ULONG k = 0; k < pBasesInfo->Count(); k++ ) {
356 GenericInformation *pBaseProduct;
357 if ( GetProductInformation( *pBasesInfo->GetObject( k ), pBaseProduct ) == PRODUCT_MAPPER_OK )
358 GetBases( pBaseProduct, ++ nLevel, pBases );
362 BOOL bFound = FALSE;
363 ByteString sUpperCandidate( sCandidate );
364 sUpperCandidate.ToUpperAscii();
365 for ( USHORT i = 0; i < pBases->Count() && !bFound; i++ ) {
366 ByteString sTest( *pBases->GetObject( i ));
367 if ( sTest.ToUpperAscii() == sUpperCandidate )
368 bFound = TRUE;
370 if ( !bFound )
371 pBases->Insert( new ByteString( sCandidate ), ( ULONG ) 0 );
373 return pBases;
376 /*****************************************************************************/
377 USHORT ProductMapper::PrintMinorList(
378 const ByteString rProduct, const ByteString rEnvironment )
379 /*****************************************************************************/
381 if ( !pVersionList )
382 return PRODUCT_MAPPER_NO_VERSION_INFORMATION;
384 if ( !pProductList || !pProductList->Count())
385 return PRODUCT_MAPPER_NO_PRODUCT;
387 GenericInformation *pProductInfo;
388 GetProductInformation( rProduct, pProductInfo );
389 if ( !pProductInfo )
390 return PRODUCT_MAPPER_NO_PRODUCT;
392 BaseProductList *pBases = GetBases( pProductInfo );
393 if ( pBases->Count()) {
394 if ( pBases->Count() > 1 )
395 fprintf( stdout, "Product \"%s\" based on ", pBases->GetObject(( ULONG ) 0 )->GetBuffer());
396 else
397 fprintf( stdout, "Product \"%s\" based on no other products", pBases->GetObject(( ULONG ) 0 )->GetBuffer());
399 for ( ULONG i = 1; i < pBases->Count(); i++ ) {
400 fprintf( stdout, "\"%s\"", pBases->GetObject( i )->GetBuffer());
401 if ( i < pBases->Count() - 1 )
402 fprintf( stdout, ", " );
404 fprintf( stdout, "\n\n" );
406 USHORT nResult = PRODUCT_MAPPER_OK;
408 if ( rEnvironment.Len())
409 nResult = PrintSingleMinorList( pProductInfo, pBases, rEnvironment );
410 else {
411 ByteString sEnvKey( pProductInfo->GetValue());
412 sEnvKey += "/Environments";
414 GenericInformation *pEnvironmentInfo = pVersionList->GetInfo( sEnvKey, TRUE );
415 if ( pEnvironmentInfo ) {
416 GenericInformationList *pEnvironmentList = pEnvironmentInfo->GetSubList();
417 if ( pEnvironmentList ) {
418 for ( ULONG i = 0; i < pEnvironmentList->Count(); i++ ) {
419 USHORT nTmp = PrintSingleMinorList( pProductInfo, pBases, *pEnvironmentList->GetObject( i ));
420 if ( nTmp != PRODUCT_MAPPER_OK )
421 nResult = nTmp;
427 for ( ULONG m = 0; m < pBases->Count(); m++ )
428 delete pBases->GetObject( m );
429 delete pBases;
431 return nResult;
434 /*****************************************************************************/
435 USHORT ProductMapper::PrintSingleMinorList(
436 GenericInformation *pProductInfo, BaseProductList *pBases,
437 const ByteString rEnvironment )
438 /*****************************************************************************/
440 DirEntry aRoot( GetVersionRoot( pVersionList, pProductInfo->GetValue()));
441 aRoot += DirEntry( String( rEnvironment, RTL_TEXTENCODING_ASCII_US ));
442 if ( !aRoot.Exists())
443 return PRODUCT_MAPPER_OK;
445 SByteStringList *pMinors = GetMinorList( pProductInfo->GetValue(), rEnvironment );
446 if ( !pMinors )
447 pMinors = new SByteStringList();
448 pMinors->Insert( new ByteString( "" ), LIST_APPEND );
450 SByteStringList aOutputList;
451 BOOL bUnknownMinor = FALSE;
452 for ( ULONG i = 0; i < pMinors->Count(); i++ ) {
453 ByteString sOutput;
454 ByteString sProductVersion;
456 for ( ULONG j = 0; j < pBases->Count(); j++ ) {
457 ByteString sCurProduct( *pBases->GetObject( j ));
458 ByteString sVersion( sCurProduct.GetToken( sCurProduct.GetTokenCount( '(' ) - 1, '(' ).GetToken( 0, ')' ));
459 if ( !j )
460 sProductVersion = sVersion;
462 MinorMk *pMinorMk = new MinorMk(
463 pVersionList, sProductVersion, sVersion, rEnvironment, *pMinors->GetObject( i ));
465 ByteString sMinor( pMinorMk->GetLastMinor().GetBuffer());
466 if ( !sMinor.Len()) {
467 sMinor = "!";
468 bUnknownMinor = TRUE;
470 if ( j == 0 ) {
471 sOutput += pMinorMk->GetBuildNr();
472 sOutput += " ";
474 if ( i == pMinors->Count() - 1 )
475 sOutput += "flat: ";
476 else
477 sOutput += " ";
479 sOutput += sVersion;
480 sOutput += ".";
481 sOutput += sMinor;
482 sOutput += "(";
483 sOutput += pMinorMk->GetBuildNr();
484 sOutput += ") ";
486 aOutputList.PutString( new ByteString( sOutput ));
488 ByteString sOldMinor;
490 if ( aOutputList.Count())
491 fprintf( stdout, "Available builds on %s:\n", rEnvironment.GetBuffer());
493 for ( ULONG o = 0; o < aOutputList.Count(); o++ ) {
494 ByteString sOutput( *aOutputList.GetObject( o ));
495 sOutput = sOutput.Copy( sOutput.GetToken( 0, ' ' ).Len() + 1 );
497 ByteString sCurMinor( sOutput.GetToken( 1, '.' ).GetToken( 0, '(' ));
498 if ( sOldMinor.Len() && sCurMinor < sOldMinor ) {
499 fprintf( stdout, " ----------\n" );
501 sOldMinor = sCurMinor;
503 fprintf( stdout, "%s\n", sOutput.GetBuffer());
504 delete aOutputList.GetObject( o );
506 if ( bUnknownMinor )
507 fprintf( stdout, "Symbol ! indcates that at least one minor could not be found\n\n" );
508 else if ( aOutputList.Count())
509 fprintf( stdout, "\n" );
511 for ( ULONG l = 0; l < pMinors->Count(); l++ )
512 delete pMinors->GetObject( l );
513 delete pMinors;
515 return PRODUCT_MAPPER_OK;