merge the formfield patch from ooo-build
[ooovba.git] / tools / bootstrp / prj.cxx
blobcb99876cbc2bdcc58ec238976d81d7abd5c70c42
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: prj.cxx,v $
10 * $Revision: 1.29.40.1 $
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 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_tools.hxx"
33 #include <stdlib.h>
34 #include <stdio.h>
35 #include "bootstrp/sstring.hxx"
36 #include <vos/mutex.hxx>
38 #include <tools/stream.hxx>
39 #include <tools/geninfo.hxx>
40 #include "bootstrp/prj.hxx"
41 #include "bootstrp/inimgr.hxx"
43 //#define TEST 1
45 #if defined(WNT) || defined(OS2)
46 #define LIST_DELIMETER ';'
47 #define PATH_DELIMETER '\\'
48 #elif defined UNX
49 #define LIST_DELIMETER ':'
50 #define PATH_DELIMETER '/'
51 #endif
53 Link Star::aDBNotFoundHdl;
56 // class SimpleConfig
59 /*****************************************************************************/
60 SimpleConfig::SimpleConfig( String aSimpleConfigFileName )
61 /*****************************************************************************/
63 nLine = 0;
64 aFileName = aSimpleConfigFileName;
65 aFileStream.Open ( aFileName, STREAM_READ );
68 /*****************************************************************************/
69 SimpleConfig::SimpleConfig( DirEntry& rDirEntry )
70 /*****************************************************************************/
72 nLine = 0;
73 aFileName = rDirEntry.GetFull();
74 aFileStream.Open ( aFileName, STREAM_READ );
77 /*****************************************************************************/
78 SimpleConfig::~SimpleConfig()
79 /*****************************************************************************/
81 aFileStream.Close ();
84 /*****************************************************************************/
85 ByteString SimpleConfig::GetNext()
86 /*****************************************************************************/
88 ByteString aString;
90 if ( aStringBuffer =="" )
91 while ((aStringBuffer = GetNextLine()) == "\t") ; //solange bis != "\t"
92 if ( aStringBuffer =="" )
93 return ByteString();
95 aString = aStringBuffer.GetToken(0,'\t');
96 aStringBuffer.Erase(0, aString.Len()+1);
98 aStringBuffer.EraseLeadingChars( '\t' );
100 return aString;
103 /*****************************************************************************/
104 ByteString SimpleConfig::GetNextLine()
105 /*****************************************************************************/
107 ByteString aSecStr;
108 nLine++;
110 aFileStream.ReadLine ( aTmpStr );
111 if ( aTmpStr.Search( "#" ) == 0 )
112 return "\t";
113 aTmpStr = aTmpStr.EraseLeadingChars();
114 aTmpStr = aTmpStr.EraseTrailingChars();
115 while ( aTmpStr.SearchAndReplace(ByteString(' '),ByteString('\t') ) != STRING_NOTFOUND ) ;
116 int nLength = aTmpStr.Len();
117 BOOL bFound = FALSE;
118 ByteString aEraseString;
119 for ( USHORT i = 0; i<= nLength; i++)
121 if ( aTmpStr.GetChar( i ) == 0x20 && !bFound )
122 aTmpStr.SetChar( i, 0x09 );
124 return aTmpStr;
127 /*****************************************************************************/
128 ByteString SimpleConfig::GetCleanedNextLine( BOOL bReadComments )
129 /*****************************************************************************/
132 aFileStream.ReadLine ( aTmpStr );
133 if ( aTmpStr.Search( "#" ) == 0 )
135 if (bReadComments )
136 return aTmpStr;
137 else
138 while ( aTmpStr.Search( "#" ) == 0 )
140 aFileStream.ReadLine ( aTmpStr );
144 aTmpStr = aTmpStr.EraseLeadingChars();
145 aTmpStr = aTmpStr.EraseTrailingChars();
146 // while ( aTmpStr.SearchAndReplace(String(' '),String('\t') ) != (USHORT)-1 );
147 int nLength = aTmpStr.Len();
148 ByteString aEraseString;
149 BOOL bFirstTab = TRUE;
150 for ( USHORT i = 0; i<= nLength; i++)
152 if ( aTmpStr.GetChar( i ) == 0x20 )
153 aTmpStr.SetChar( i, 0x09 );
155 if ( aTmpStr.GetChar( i ) == 0x09 )
157 if ( bFirstTab )
158 bFirstTab = FALSE;
159 else
161 aTmpStr.SetChar( i, 0x20 );
164 else
165 bFirstTab = TRUE;
168 aTmpStr.EraseAllChars(' ');
169 return aTmpStr;
175 // class CommandData
178 /*****************************************************************************/
179 CommandData::CommandData()
180 /*****************************************************************************/
182 nOSType = 0;
183 nCommand = 0;
184 pDepList = 0;
187 /*****************************************************************************/
188 CommandData::~CommandData()
189 /*****************************************************************************/
191 if ( pDepList )
193 ByteString *pString = pDepList->First();
194 while ( pString )
196 delete pString;
197 pString = pDepList->Next();
199 delete pDepList;
201 pDepList = NULL;
205 /*****************************************************************************/
206 ByteString CommandData::GetOSTypeString()
207 /*****************************************************************************/
209 ByteString aRetStr;
211 switch (nOSType)
213 case OS_WIN16 | OS_WIN32 | OS_OS2 | OS_UNX :
214 aRetStr = "all";
215 break;
216 case OS_WIN32 | OS_WIN16 :
217 aRetStr = "w";
218 break;
219 case OS_OS2 :
220 aRetStr = "p";
221 break;
222 case OS_UNX :
223 aRetStr = "u";
224 break;
225 case OS_WIN16 :
226 aRetStr = "d";
227 break;
228 case OS_WIN32 :
229 aRetStr = "n";
230 break;
231 default :
232 aRetStr = "none";
235 return aRetStr;
238 /*****************************************************************************/
239 ByteString CommandData::GetCommandTypeString()
240 /*****************************************************************************/
242 ByteString aRetStr;
244 switch (nCommand)
246 case COMMAND_NMAKE :
247 aRetStr = "nmake";
248 break;
249 case COMMAND_GET :
250 aRetStr = "get";
251 break;
252 default :
253 aRetStr = "usr";
254 aRetStr += ByteString::CreateFromInt64( nCommand + 1 - COMMAND_USER_START );
258 return aRetStr;
261 /*****************************************************************************/
262 CommandData* Prj::GetDirectoryList ( USHORT, USHORT )
263 /*****************************************************************************/
265 return (CommandData *)NULL;
268 /*****************************************************************************/
269 CommandData* Prj::GetDirectoryData( ByteString aLogFileName )
270 /*****************************************************************************/
272 CommandData *pData = NULL;
273 ULONG nObjCount = Count();
274 for ( ULONG i=0; i<nObjCount; i++ )
276 pData = GetObject(i);
277 if ( pData->GetLogFile() == aLogFileName )
278 return pData;
280 return NULL;
284 // class Prj
287 /*****************************************************************************/
288 Prj::Prj() :
289 bVisited( FALSE ),
290 pPrjInitialDepList(0),
291 pPrjDepList(0),
292 bHardDependencies( FALSE ),
293 bSorted( FALSE )
294 /*****************************************************************************/
298 /*****************************************************************************/
299 Prj::Prj( ByteString aName ) :
300 bVisited( FALSE ),
301 aProjectName( aName ),
302 pPrjInitialDepList(0),
303 pPrjDepList(0),
304 bHardDependencies( FALSE ),
305 bSorted( FALSE )
306 /*****************************************************************************/
310 /*****************************************************************************/
311 Prj::~Prj()
312 /*****************************************************************************/
314 if ( pPrjDepList )
316 ByteString *pString = pPrjDepList->First();
317 while ( pString )
319 delete pString;
320 pString = pPrjDepList->Next();
322 delete pPrjDepList;
324 pPrjDepList = NULL;
327 if ( pPrjInitialDepList )
329 ByteString *pString = pPrjInitialDepList->First();
330 while ( pString )
332 delete pString;
333 pString = pPrjInitialDepList->Next();
335 delete pPrjInitialDepList;
337 pPrjInitialDepList = NULL;
341 /*****************************************************************************/
342 void Prj::AddDependencies( ByteString aStr )
343 /*****************************************************************************/
346 // needs dirty flag - not expanded
347 if ( !pPrjDepList )
348 pPrjDepList = new SByteStringList;
350 pPrjDepList->PutString( new ByteString(aStr) );
352 if ( !pPrjInitialDepList )
353 pPrjInitialDepList = new SByteStringList;
355 pPrjInitialDepList->PutString( new ByteString(aStr) );
358 /*****************************************************************************/
359 SByteStringList* Prj::GetDependencies( BOOL bExpanded )
360 /*****************************************************************************/
362 if ( bExpanded )
363 return pPrjDepList;
364 else
365 return pPrjInitialDepList;
370 /*****************************************************************************/
371 BOOL Prj::InsertDirectory ( ByteString aDirName, USHORT aWhat,
372 USHORT aWhatOS, ByteString aLogFileName,
373 const ByteString &rClientRestriction )
374 /*****************************************************************************/
376 CommandData* pData = new CommandData();
378 pData->SetPath( aDirName );
379 pData->SetCommandType( aWhat );
380 pData->SetOSType( aWhatOS );
381 pData->SetLogFile( aLogFileName );
382 pData->SetClientRestriction( rClientRestriction );
384 Insert( pData );
386 return FALSE;
389 /*****************************************************************************/
391 // removes directory and existing dependencies on it
393 CommandData* Prj::RemoveDirectory ( ByteString aLogFileName )
394 /*****************************************************************************/
396 ULONG nCountMember = Count();
397 CommandData* pData;
398 CommandData* pDataFound = NULL;
399 SByteStringList* pDataDeps;
401 for ( USHORT i = 0; i < nCountMember; i++ )
403 pData = GetObject( i );
404 if ( pData->GetLogFile() == aLogFileName )
405 pDataFound = pData;
406 else
408 pDataDeps = pData->GetDependencies();
409 if ( pDataDeps )
411 ByteString* pString;
412 ULONG nDataDepsCount = pDataDeps->Count();
413 for ( ULONG j = nDataDepsCount; j > 0; j-- )
415 pString = pDataDeps->GetObject( j - 1 );
416 if ( pString->GetToken( 0, '.') == aLogFileName )
417 pDataDeps->Remove( pString );
423 Remove( pDataFound );
425 return pDataFound;
429 // class Star
432 /*****************************************************************************/
433 Star::Star()
434 /*****************************************************************************/
436 // this ctor is only used by StarWriter
439 /*****************************************************************************/
440 Star::Star(String aFileName, USHORT nMode )
441 /*****************************************************************************/
442 : nStarMode( nMode )
444 Read( aFileName );
447 /*****************************************************************************/
448 Star::Star( SolarFileList *pSolarFiles )
449 /*****************************************************************************/
450 : nStarMode( STAR_MODE_MULTIPLE_PARSE )
452 // this ctor is used by StarBuilder to get the information for the whole workspace
453 Read( pSolarFiles );
456 /*****************************************************************************/
457 Star::Star( GenericInformationList *pStandLst, ByteString &rVersion,
458 BOOL bLocal, const char *pSourceRoot )
459 /*****************************************************************************/
461 ByteString sPath( rVersion );
462 String sSrcRoot;
463 if ( pSourceRoot )
464 sSrcRoot = String::CreateFromAscii( pSourceRoot );
466 #ifdef UNX
467 sPath += "/settings/UNXSOLARLIST";
468 #else
469 sPath += "/settings/SOLARLIST";
470 #endif
471 GenericInformation *pInfo = pStandLst->GetInfo( sPath, TRUE );
473 if( pInfo && pInfo->GetValue().Len()) {
474 ByteString sFile( pInfo->GetValue());
475 if ( bLocal ) {
476 IniManager aIniManager;
477 aIniManager.ToLocal( sFile );
479 String sFileName( sFile, RTL_TEXTENCODING_ASCII_US );
480 nStarMode = STAR_MODE_SINGLE_PARSE;
481 Read( sFileName );
483 else {
484 SolarFileList *pFileList = new SolarFileList();
486 sPath = rVersion;
487 sPath += "/drives";
489 GenericInformation *pInfo2 = pStandLst->GetInfo( sPath, TRUE );
490 if ( pInfo2 && pInfo2->GetSubList()) {
491 GenericInformationList *pDrives = pInfo2->GetSubList();
492 for ( ULONG i = 0; i < pDrives->Count(); i++ ) {
493 GenericInformation *pDrive = pDrives->GetObject( i );
494 if ( pDrive ) {
495 DirEntry aEntry;
496 BOOL bOk = FALSE;
497 if ( sSrcRoot.Len()) {
498 aEntry = DirEntry( sSrcRoot );
499 bOk = TRUE;
501 else {
502 #ifdef UNX
503 sPath = "UnixVolume";
504 GenericInformation *pUnixVolume = pDrive->GetSubInfo( sPath );
505 if ( pUnixVolume ) {
506 String sRoot( pUnixVolume->GetValue(), RTL_TEXTENCODING_ASCII_US );
507 aEntry = DirEntry( sRoot );
508 bOk = TRUE;
510 #else
511 bOk = TRUE;
512 String sRoot( *pDrive, RTL_TEXTENCODING_ASCII_US );
513 sRoot += String::CreateFromAscii( "\\" );
514 aEntry = DirEntry( sRoot );
515 #endif
517 if ( bOk ) {
518 sPath = "projects";
519 GenericInformation *pProjectsKey = pDrive->GetSubInfo( sPath, TRUE );
520 if ( pProjectsKey ) {
521 if ( !sSrcRoot.Len()) {
522 sPath = rVersion;
523 sPath += "/settings/PATH";
524 GenericInformation *pPath = pStandLst->GetInfo( sPath, TRUE );
525 if( pPath ) {
526 ByteString sAddPath( pPath->GetValue());
527 #ifdef UNX
528 sAddPath.SearchAndReplaceAll( "\\", "/" );
529 #else
530 sAddPath.SearchAndReplaceAll( "/", "\\" );
531 #endif
532 String ssAddPath( sAddPath, RTL_TEXTENCODING_ASCII_US );
533 aEntry += DirEntry( ssAddPath );
536 GenericInformationList *pProjects = pProjectsKey->GetSubList();
537 if ( pProjects ) {
538 String sPrjDir( String::CreateFromAscii( "prj" ));
539 String sSolarFile( String::CreateFromAscii( "build.lst" ));
541 for ( ULONG j = 0; j < pProjects->Count(); j++ ) {
542 ByteString sProject( *pProjects->GetObject( j ));
543 String ssProject( sProject, RTL_TEXTENCODING_ASCII_US );
545 DirEntry aPrjEntry( aEntry );
547 aPrjEntry += DirEntry( ssProject );
548 aPrjEntry += DirEntry( sPrjDir );
549 aPrjEntry += DirEntry( sSolarFile );
551 pFileList->Insert( new String( aPrjEntry.GetFull()), LIST_APPEND );
553 ByteString sFile( aPrjEntry.GetFull(), RTL_TEXTENCODING_ASCII_US );
561 Read( pFileList );
565 /*****************************************************************************/
566 Star::~Star()
567 /*****************************************************************************/
571 /*****************************************************************************/
572 BOOL Star::NeedsUpdate()
573 /*****************************************************************************/
575 aMutex.acquire();
576 for ( ULONG i = 0; i < aLoadedFilesList.Count(); i++ )
577 if ( aLoadedFilesList.GetObject( i )->NeedsUpdate()) {
578 aMutex.release();
579 return TRUE;
582 aMutex.release();
583 return FALSE;
586 /*****************************************************************************/
587 void Star::Read( String &rFileName )
588 /*****************************************************************************/
590 ByteString aString;
591 aFileList.Insert( new String( rFileName ));
593 DirEntry aEntry( rFileName );
594 aEntry.ToAbs();
595 aEntry = aEntry.GetPath().GetPath().GetPath();
596 sSourceRoot = aEntry.GetFull();
598 while( aFileList.Count()) {
599 StarFile *pFile = new StarFile( *aFileList.GetObject(( ULONG ) 0 ));
600 if ( pFile->Exists()) {
601 SimpleConfig aSolarConfig( *aFileList.GetObject(( ULONG ) 0 ));
602 while (( aString = aSolarConfig.GetNext()) != "" )
603 InsertToken (( char * ) aString.GetBuffer());
605 aMutex.acquire();
606 aLoadedFilesList.Insert( pFile, LIST_APPEND );
607 aMutex.release();
608 aFileList.Remove(( ULONG ) 0 );
610 // resolve all dependencies recursive
611 Expand_Impl();
614 /*****************************************************************************/
615 void Star::Read( SolarFileList *pSolarFiles )
616 /*****************************************************************************/
618 while( pSolarFiles->Count()) {
619 ByteString aString;
621 StarFile *pFile = new StarFile( *pSolarFiles->GetObject(( ULONG ) 0 ));
622 if ( pFile->Exists()) {
623 SimpleConfig aSolarConfig( *pSolarFiles->GetObject(( ULONG ) 0 ));
624 while (( aString = aSolarConfig.GetNext()) != "" )
625 InsertToken (( char * ) aString.GetBuffer());
628 aMutex.acquire();
629 aLoadedFilesList.Insert( pFile, LIST_APPEND );
630 aMutex.release();
631 delete pSolarFiles->Remove(( ULONG ) 0 );
633 delete pSolarFiles;
635 Expand_Impl();
638 /*****************************************************************************/
639 String Star::CreateFileName( String sProject )
640 /*****************************************************************************/
642 // this method is used to find solarlist parts of nabours (other projects)
643 String sPrjDir( String::CreateFromAscii( "prj" ));
644 String sSolarFile( String::CreateFromAscii( "build.lst" ));
646 DirEntry aEntry( sSourceRoot );
647 aEntry += DirEntry( sProject );
648 aEntry += DirEntry( sPrjDir );
649 aEntry += DirEntry( sSolarFile );
651 if ( !aEntry.Exists() && aDBNotFoundHdl.IsSet())
652 aDBNotFoundHdl.Call( &sProject );
654 return aEntry.GetFull();
657 /*****************************************************************************/
658 void Star::InsertSolarList( String sProject )
659 /*****************************************************************************/
661 // inserts a new solarlist part of another project
662 String sFileName( CreateFileName( sProject ));
664 for ( ULONG i = 0; i < aFileList.Count(); i++ ) {
665 if (( *aFileList.GetObject( i )) == sFileName )
666 return;
669 ByteString ssProject( sProject, RTL_TEXTENCODING_ASCII_US );
670 if ( HasProject( ssProject ))
671 return;
673 aFileList.Insert( new String( sFileName ), LIST_APPEND );
676 /*****************************************************************************/
677 void Star::ExpandPrj_Impl( Prj *pPrj, Prj *pDepPrj )
678 /*****************************************************************************/
680 if ( pDepPrj->bVisited )
681 return;
683 pDepPrj->bVisited = TRUE;
685 SByteStringList* pPrjLst = pPrj->GetDependencies();
686 SByteStringList* pDepLst = NULL;
687 ByteString* pDepend;
688 ByteString* pPutStr;
689 Prj *pNextPrj = NULL;
690 ULONG i, nRetPos;
692 if ( pPrjLst ) {
693 pDepLst = pDepPrj->GetDependencies();
694 if ( pDepLst ) {
695 for ( i = 0; i < pDepLst->Count(); i++ ) {
696 pDepend = pDepLst->GetObject( i );
697 pPutStr = new ByteString( *pDepend );
698 nRetPos = pPrjLst->PutString( pPutStr );
699 if( nRetPos == NOT_THERE )
700 delete pPutStr;
701 pNextPrj = GetPrj( *pDepend );
702 if ( pNextPrj ) {
703 ExpandPrj_Impl( pPrj, pNextPrj );
710 /*****************************************************************************/
711 void Star::Expand_Impl()
712 /*****************************************************************************/
714 for ( ULONG i = 0; i < Count(); i++ ) {
715 for ( ULONG j = 0; j < Count(); j++ )
716 GetObject( j )->bVisited = FALSE;
718 Prj* pPrj = GetObject( i );
719 ExpandPrj_Impl( pPrj, pPrj );
723 /*****************************************************************************/
724 void Star::InsertToken ( char *yytext )
725 /*****************************************************************************/
727 static int i = 0;
728 static ByteString aDirName, aWhat, aWhatOS,
729 sClientRestriction, aLogFileName, aProjectName, aPrefix, aCommandPara;
730 static BOOL bPrjDep = FALSE;
731 static BOOL bHardDep = FALSE;
732 static USHORT nCommandType, nOSType;
733 CommandData* pCmdData;
734 static SByteStringList *pStaticDepList;
735 Prj* pPrj;
737 switch (i)
739 case 0:
740 aPrefix = yytext;
741 pStaticDepList = 0;
742 break;
743 case 1:
744 aDirName = yytext;
745 break;
746 case 2:
747 if ( !strcmp( yytext, ":" ))
749 bPrjDep = TRUE;
750 bHardDep = FALSE;
751 i = 9;
753 else if ( !strcmp( yytext, "::" ))
755 bPrjDep = TRUE;
756 bHardDep = TRUE;
757 i = 9;
759 else
761 bPrjDep = FALSE;
762 bHardDep = FALSE;
764 aWhat = yytext;
765 if ( aWhat == "nmake" )
766 nCommandType = COMMAND_NMAKE;
767 else if ( aWhat == "get" )
768 nCommandType = COMMAND_GET;
769 else {
770 ULONG nOffset = aWhat.Copy( 3 ).ToInt32();
771 nCommandType = sal::static_int_cast< USHORT >(
772 COMMAND_USER_START + nOffset - 1);
775 break;
776 case 3:
777 if ( !bPrjDep )
779 aWhat = yytext;
780 if ( aWhat == "-" )
782 aCommandPara = ByteString();
784 else
785 aCommandPara = aWhat;
787 break;
788 case 4:
789 if ( !bPrjDep )
791 aWhatOS = yytext;
792 if ( aWhatOS.GetTokenCount( ',' ) > 1 ) {
793 sClientRestriction = aWhatOS.Copy( aWhatOS.GetToken( 0, ',' ).Len() + 1 );
794 aWhatOS = aWhatOS.GetToken( 0, ',' );
796 if ( aWhatOS == "all" )
797 nOSType = ( OS_WIN16 | OS_WIN32 | OS_OS2 | OS_UNX );
798 else if ( aWhatOS == "w" )
799 nOSType = ( OS_WIN16 | OS_WIN32 );
800 else if ( aWhatOS == "p" )
801 nOSType = OS_OS2;
802 else if ( aWhatOS == "u" )
803 nOSType = OS_UNX;
804 else if ( aWhatOS == "d" )
805 nOSType = OS_WIN16;
806 else if ( aWhatOS == "n" )
807 nOSType = OS_WIN32;
808 else
809 nOSType = OS_NONE;
811 break;
812 case 5:
813 if ( !bPrjDep )
815 aLogFileName = yytext;
817 break;
818 default:
819 if ( !bPrjDep )
821 ByteString aItem = yytext;
822 if ( aItem == "NULL" )
824 // Liste zu Ende
825 i = -1;
827 else
829 // ggfs. Dependency liste anlegen und ergaenzen
830 if ( !pStaticDepList )
831 pStaticDepList = new SByteStringList;
832 pStaticDepList->PutString( new ByteString( aItem ));
835 else
837 ByteString aItem = yytext;
838 if ( aItem == "NULL" )
840 // Liste zu Ende
841 i = -1;
842 bPrjDep= FALSE;
844 else
846 aProjectName = aDirName.GetToken ( 0, '\\');
847 if ( HasProject( aProjectName ))
849 pPrj = GetPrj( aProjectName );
850 // Projekt exist. schon, neue Eintraege anhaengen
852 else
854 // neues Project anlegen
855 pPrj = new Prj ( aProjectName );
856 pPrj->SetPreFix( aPrefix );
857 Insert(pPrj,LIST_APPEND);
859 pPrj->AddDependencies( aItem );
860 pPrj->HasHardDependencies( bHardDep );
862 if ( nStarMode == STAR_MODE_RECURSIVE_PARSE ) {
863 String sItem( aItem, RTL_TEXTENCODING_ASCII_US );
864 InsertSolarList( sItem );
868 break;
870 /* Wenn dieses Project noch nicht vertreten ist, in die Liste
871 der Solar-Projekte einfuegen */
872 if ( i == -1 )
874 aProjectName = aDirName.GetToken ( 0, '\\');
875 if ( HasProject( aProjectName ))
877 pPrj = GetPrj( aProjectName );
878 // Projekt exist. schon, neue Eintraege anhaengen
880 else
882 // neues Project anlegen
883 pPrj = new Prj ( aProjectName );
884 pPrj->SetPreFix( aPrefix );
885 Insert(pPrj,LIST_APPEND);
888 pCmdData = new CommandData;
889 pCmdData->SetPath( aDirName );
890 pCmdData->SetCommandType( nCommandType );
891 pCmdData->SetCommandPara( aCommandPara );
892 pCmdData->SetOSType( nOSType );
893 pCmdData->SetLogFile( aLogFileName );
894 pCmdData->SetClientRestriction( sClientRestriction );
895 if ( pStaticDepList )
896 pCmdData->SetDependencies( pStaticDepList );
898 pStaticDepList = 0;
899 pPrj->Insert ( pCmdData, LIST_APPEND );
900 aDirName ="";
901 aWhat ="";
902 aWhatOS = "";
903 sClientRestriction = "";
904 aLogFileName = "";
905 nCommandType = 0;
906 nOSType = 0;
908 i++;
910 // und wer raeumt die depLst wieder ab ?
913 /*****************************************************************************/
914 BOOL Star::HasProject ( ByteString aProjectName )
915 /*****************************************************************************/
917 Prj *pPrj;
918 int nCountMember;
920 nCountMember = Count();
922 for ( int i=0; i<nCountMember; i++)
924 pPrj = GetObject(i);
925 if ( pPrj->GetProjectName().EqualsIgnoreCaseAscii(aProjectName) )
926 return TRUE;
928 return FALSE;
931 /*****************************************************************************/
932 Prj* Star::GetPrj ( ByteString aProjectName )
933 /*****************************************************************************/
935 Prj* pPrj;
936 int nCountMember = Count();
937 for ( int i=0;i<nCountMember;i++)
939 pPrj = GetObject(i);
940 if ( pPrj->GetProjectName().EqualsIgnoreCaseAscii(aProjectName) )
941 return pPrj;
943 // return (Prj*)NULL;
944 return 0L ;
947 /*****************************************************************************/
948 ByteString Star::GetPrjName( DirEntry &aPath )
949 /*****************************************************************************/
951 ByteString aRetPrj, aDirName;
952 ByteString aFullPathName = ByteString( aPath.GetFull(), gsl_getSystemTextEncoding());
954 xub_StrLen nToken = aFullPathName.GetTokenCount(PATH_DELIMETER);
955 for ( xub_StrLen i=0; i< nToken; i++ )
957 aDirName = aFullPathName.GetToken( i, PATH_DELIMETER );
958 if ( HasProject( aDirName ))
960 aRetPrj = aDirName;
961 break;
965 return aRetPrj;
970 // class StarWriter
973 /*****************************************************************************/
974 StarWriter::StarWriter( String aFileName, BOOL bReadComments, USHORT nMode )
975 /*****************************************************************************/
977 Read ( aFileName, bReadComments, nMode );
980 /*****************************************************************************/
981 StarWriter::StarWriter( SolarFileList *pSolarFiles, BOOL bReadComments )
982 /*****************************************************************************/
984 Read( pSolarFiles, bReadComments );
987 /*****************************************************************************/
988 StarWriter::StarWriter( GenericInformationList *pStandLst, ByteString &rVersion,
989 BOOL bLocal, const char *pSourceRoot )
990 /*****************************************************************************/
992 ByteString sPath( rVersion );
993 String sSrcRoot;
994 if ( pSourceRoot )
995 sSrcRoot = String::CreateFromAscii( pSourceRoot );
997 #ifdef UNX
998 sPath += "/settings/UNXSOLARLIST";
999 #else
1000 sPath += "/settings/SOLARLIST";
1001 #endif
1002 GenericInformation *pInfo = pStandLst->GetInfo( sPath, TRUE );
1004 if( pInfo && pInfo->GetValue().Len()) {
1005 ByteString sFile( pInfo->GetValue());
1006 if ( bLocal ) {
1007 IniManager aIniManager;
1008 aIniManager.ToLocal( sFile );
1010 String sFileName( sFile, RTL_TEXTENCODING_ASCII_US );
1011 nStarMode = STAR_MODE_SINGLE_PARSE;
1012 Read( sFileName );
1014 else {
1015 SolarFileList *pFileList = new SolarFileList();
1017 sPath = rVersion;
1018 sPath += "/drives";
1020 GenericInformation *pInfo2 = pStandLst->GetInfo( sPath, TRUE );
1021 if ( pInfo2 && pInfo2->GetSubList()) {
1022 GenericInformationList *pDrives = pInfo2->GetSubList();
1023 for ( ULONG i = 0; i < pDrives->Count(); i++ ) {
1024 GenericInformation *pDrive = pDrives->GetObject( i );
1025 if ( pDrive ) {
1026 DirEntry aEntry;
1027 BOOL bOk = FALSE;
1028 if ( sSrcRoot.Len()) {
1029 aEntry = DirEntry( sSrcRoot );
1030 bOk = TRUE;
1032 else {
1033 #ifdef UNX
1034 sPath = "UnixVolume";
1035 GenericInformation *pUnixVolume = pDrive->GetSubInfo( sPath );
1036 if ( pUnixVolume ) {
1037 String sRoot( pUnixVolume->GetValue(), RTL_TEXTENCODING_ASCII_US );
1038 aEntry = DirEntry( sRoot );
1039 bOk = TRUE;
1041 #else
1042 bOk = TRUE;
1043 String sRoot( *pDrive, RTL_TEXTENCODING_ASCII_US );
1044 sRoot += String::CreateFromAscii( "\\" );
1045 aEntry = DirEntry( sRoot );
1046 #endif
1048 if ( bOk ) {
1049 sPath = "projects";
1050 GenericInformation *pProjectsKey = pDrive->GetSubInfo( sPath, TRUE );
1051 if ( pProjectsKey ) {
1052 if ( !sSrcRoot.Len()) {
1053 sPath = rVersion;
1054 sPath += "/settings/PATH";
1055 GenericInformation *pPath = pStandLst->GetInfo( sPath, TRUE );
1056 if( pPath ) {
1057 ByteString sAddPath( pPath->GetValue());
1058 #ifdef UNX
1059 sAddPath.SearchAndReplaceAll( "\\", "/" );
1060 #else
1061 sAddPath.SearchAndReplaceAll( "/", "\\" );
1062 #endif
1063 String ssAddPath( sAddPath, RTL_TEXTENCODING_ASCII_US );
1064 aEntry += DirEntry( ssAddPath );
1067 GenericInformationList *pProjects = pProjectsKey->GetSubList();
1068 if ( pProjects ) {
1069 String sPrjDir( String::CreateFromAscii( "prj" ));
1070 String sSolarFile( String::CreateFromAscii( "build.lst" ));
1072 for ( ULONG j = 0; j < pProjects->Count(); j++ ) {
1073 ByteString sProject( *pProjects->GetObject( j ));
1074 String ssProject( sProject, RTL_TEXTENCODING_ASCII_US );
1076 DirEntry aPrjEntry( aEntry );
1078 aPrjEntry += DirEntry( ssProject );
1079 aPrjEntry += DirEntry( sPrjDir );
1080 aPrjEntry += DirEntry( sSolarFile );
1082 pFileList->Insert( new String( aPrjEntry.GetFull()), LIST_APPEND );
1084 ByteString sFile( aPrjEntry.GetFull(), RTL_TEXTENCODING_ASCII_US );
1085 fprintf( stdout, "%s\n", sFile.GetBuffer());
1093 Read( pFileList );
1097 /*****************************************************************************/
1098 void StarWriter::CleanUp()
1099 /*****************************************************************************/
1101 Expand_Impl();
1104 /*****************************************************************************/
1105 USHORT StarWriter::Read( String aFileName, BOOL bReadComments, USHORT nMode )
1106 /*****************************************************************************/
1108 nStarMode = nMode;
1110 ByteString aString;
1111 aFileList.Insert( new String( aFileName ));
1113 DirEntry aEntry( aFileName );
1114 aEntry.ToAbs();
1115 aEntry = aEntry.GetPath().GetPath().GetPath();
1116 sSourceRoot = aEntry.GetFull();
1118 while( aFileList.Count()) {
1120 StarFile *pFile = new StarFile( *aFileList.GetObject(( ULONG ) 0 ));
1121 if ( pFile->Exists()) {
1122 SimpleConfig aSolarConfig( *aFileList.GetObject(( ULONG ) 0 ));
1123 while (( aString = aSolarConfig.GetCleanedNextLine( bReadComments )) != "" )
1124 InsertTokenLine ( aString );
1127 aMutex.acquire();
1128 aLoadedFilesList.Insert( pFile, LIST_APPEND );
1129 aMutex.release();
1130 delete aFileList.Remove(( ULONG ) 0 );
1132 // resolve all dependencies recursive
1133 Expand_Impl();
1135 // Die gefundenen Abhaengigkeiten rekursiv aufloesen
1136 Expand_Impl();
1137 return 0;
1140 /*****************************************************************************/
1141 USHORT StarWriter::Read( SolarFileList *pSolarFiles, BOOL bReadComments )
1142 /*****************************************************************************/
1144 nStarMode = STAR_MODE_MULTIPLE_PARSE;
1146 // this ctor is used by StarBuilder to get the information for the whole workspace
1147 while( pSolarFiles->Count()) {
1148 ByteString aString;
1150 StarFile *pFile = new StarFile( *pSolarFiles->GetObject(( ULONG ) 0 ));
1151 if ( pFile->Exists()) {
1152 SimpleConfig aSolarConfig( *pSolarFiles->GetObject(( ULONG ) 0 ));
1153 while (( aString = aSolarConfig.GetCleanedNextLine( bReadComments )) != "" )
1154 InsertTokenLine ( aString );
1157 aMutex.acquire();
1158 aLoadedFilesList.Insert( pFile, LIST_APPEND );
1159 aMutex.release();
1160 delete pSolarFiles->Remove(( ULONG ) 0 );
1162 delete pSolarFiles;
1164 Expand_Impl();
1165 return 0;
1168 /*****************************************************************************/
1169 USHORT StarWriter::WritePrj( Prj *pPrj, SvFileStream& rStream )
1170 /*****************************************************************************/
1172 ByteString aDataString;
1173 ByteString aTab('\t');
1174 ByteString aSpace(' ');
1175 ByteString aEmptyString("");
1176 SByteStringList* pCmdDepList;
1178 CommandData* pCmdData = NULL;
1179 if ( pPrj->Count() > 0 )
1181 pCmdData = pPrj->First();
1182 SByteStringList* pPrjDepList = pPrj->GetDependencies( FALSE );
1183 if ( pPrjDepList != 0 )
1185 aDataString = pPrj->GetPreFix();
1186 aDataString += aTab;
1187 aDataString += pPrj->GetProjectName();
1188 aDataString += aTab;
1189 if ( pPrj->HasHardDependencies())
1190 aDataString+= ByteString("::");
1191 else
1192 aDataString+= ByteString(":");
1193 aDataString += aTab;
1194 for ( USHORT i = 0; i< pPrjDepList->Count(); i++ ) {
1195 aDataString += *pPrjDepList->GetObject( i );
1196 aDataString += aSpace;
1198 aDataString+= "NULL";
1200 rStream.WriteLine( aDataString );
1202 pCmdData = pPrj->Next();
1204 if ( pCmdData ) {
1207 if (( aDataString = pCmdData->GetComment()) == aEmptyString )
1209 aDataString = pPrj->GetPreFix();
1210 aDataString += aTab;
1212 aDataString+= pCmdData->GetPath();
1213 aDataString += aTab;
1214 USHORT nPathLen = pCmdData->GetPath().Len();
1215 if ( nPathLen < 40 )
1216 for ( int i = 0; i < 9 - pCmdData->GetPath().Len() / 4 ; i++ )
1217 aDataString += aTab;
1218 else
1219 for ( int i = 0; i < 12 - pCmdData->GetPath().Len() / 4 ; i++ )
1220 aDataString += aTab;
1221 aDataString += pCmdData->GetCommandTypeString();
1222 aDataString += aTab;
1223 if ( pCmdData->GetCommandType() == COMMAND_GET )
1224 aDataString += aTab;
1225 if ( pCmdData->GetCommandPara() == aEmptyString )
1226 aDataString+= ByteString("-");
1227 else
1228 aDataString+= pCmdData->GetCommandPara();
1229 aDataString += aTab;
1230 aDataString+= pCmdData->GetOSTypeString();
1231 if ( pCmdData->GetClientRestriction().Len()) {
1232 aDataString += ByteString( "," );
1233 aDataString += pCmdData->GetClientRestriction();
1235 aDataString += aTab;
1236 aDataString += pCmdData->GetLogFile();
1237 aDataString += aSpace;
1239 pCmdDepList = pCmdData->GetDependencies();
1240 if ( pCmdDepList )
1241 for ( USHORT i = 0; i< pCmdDepList->Count(); i++ ) {
1242 aDataString += *pCmdDepList->GetObject( i );
1243 aDataString += aSpace;
1245 aDataString += "NULL";
1248 rStream.WriteLine( aDataString );
1250 pCmdData = pPrj->Next();
1251 } while ( pCmdData );
1254 return 0;
1257 /*****************************************************************************/
1258 USHORT StarWriter::Write( String aFileName )
1259 /*****************************************************************************/
1261 SvFileStream aFileStream;
1263 aFileStream.Open( aFileName, STREAM_WRITE | STREAM_TRUNC);
1265 if ( Count() > 0 )
1267 Prj* pPrj = First();
1270 WritePrj( pPrj, aFileStream );
1271 pPrj = Next();
1272 } while ( pPrj );
1275 aFileStream.Close();
1277 return 0;
1280 /*****************************************************************************/
1281 USHORT StarWriter::WriteMultiple( String rSourceRoot )
1282 /*****************************************************************************/
1284 if ( Count() > 0 )
1286 String sPrjDir( String::CreateFromAscii( "prj" ));
1287 String sSolarFile( String::CreateFromAscii( "build.lst" ));
1289 Prj* pPrj = First();
1292 String sName( pPrj->GetProjectName(), RTL_TEXTENCODING_ASCII_US );
1294 DirEntry aEntry( rSourceRoot );
1295 aEntry += DirEntry( sName );
1296 aEntry += DirEntry( sPrjDir );
1297 aEntry += DirEntry( sSolarFile );
1299 SvFileStream aFileStream;
1300 aFileStream.Open( aEntry.GetFull(), STREAM_WRITE | STREAM_TRUNC);
1302 WritePrj( pPrj, aFileStream );
1304 aFileStream.Close();
1306 pPrj = Next();
1307 } while ( pPrj );
1310 return 0;
1313 /*****************************************************************************/
1314 void StarWriter::InsertTokenLine ( ByteString& rString )
1315 /*****************************************************************************/
1317 int i = 0;
1318 ByteString aWhat, aWhatOS,
1319 sClientRestriction, aLogFileName, aProjectName, aPrefix, aCommandPara;
1320 static ByteString aDirName;
1321 BOOL bPrjDep = FALSE;
1322 BOOL bHardDep = FALSE;
1323 USHORT nCommandType = 0;
1324 USHORT nOSType = 0;
1325 CommandData* pCmdData;
1326 SByteStringList *pDepList2 = NULL;
1327 Prj* pPrj;
1329 ByteString aEmptyString;
1330 ByteString aToken = rString.GetToken( 0, '\t' );
1331 ByteString aCommentString;
1333 const char* yytext = aToken.GetBuffer();
1335 while ( !( aToken == aEmptyString ) )
1337 switch (i)
1339 case 0:
1340 if ( rString.Search( "#" ) == 0 )
1342 i = -1;
1343 aCommentString = rString;
1344 rString = aEmptyString;
1345 if ( Count() == 0 )
1346 aDirName = "null_entry" ; //comments at begin of file
1347 break;
1349 aPrefix = yytext;
1350 pDepList2 = NULL;
1351 break;
1352 case 1:
1353 aDirName = yytext;
1354 break;
1355 case 2:
1356 if ( !strcmp( yytext, ":" ))
1358 bPrjDep = TRUE;
1359 bHardDep = FALSE;
1360 i = 9;
1362 else if ( !strcmp( yytext, "::" ))
1364 bPrjDep = TRUE;
1365 bHardDep = TRUE;
1366 i = 9;
1368 else
1370 bPrjDep = FALSE;
1371 bHardDep = FALSE;
1373 aWhat = yytext;
1374 if ( aWhat == "nmake" )
1375 nCommandType = COMMAND_NMAKE;
1376 else if ( aWhat == "get" )
1377 nCommandType = COMMAND_GET;
1378 else {
1379 ULONG nOffset = aWhat.Copy( 3 ).ToInt32();
1380 nCommandType = sal::static_int_cast< USHORT >(
1381 COMMAND_USER_START + nOffset - 1);
1384 break;
1385 case 3:
1386 if ( !bPrjDep )
1388 aWhat = yytext;
1389 if ( aWhat == "-" )
1391 aCommandPara = ByteString();
1393 else
1394 aCommandPara = aWhat;
1396 break;
1397 case 4:
1398 if ( !bPrjDep )
1400 aWhatOS = yytext;
1401 if ( aWhatOS.GetTokenCount( ',' ) > 1 ) {
1402 sClientRestriction = aWhatOS.Copy( aWhatOS.GetToken( 0, ',' ).Len() + 1 );
1403 aWhatOS = aWhatOS.GetToken( 0, ',' );
1405 aWhatOS = aWhatOS.GetToken( 0, ',' );
1406 if ( aWhatOS == "all" )
1407 nOSType = ( OS_WIN16 | OS_WIN32 | OS_OS2 | OS_UNX );
1408 else if ( aWhatOS == "w" )
1409 nOSType = ( OS_WIN16 | OS_WIN32 );
1410 else if ( aWhatOS == "p" )
1411 nOSType = OS_OS2;
1412 else if ( aWhatOS == "u" )
1413 nOSType = OS_UNX;
1414 else if ( aWhatOS == "d" )
1415 nOSType = OS_WIN16;
1416 else if ( aWhatOS == "n" )
1417 nOSType = OS_WIN32;
1418 else
1419 nOSType = OS_NONE;
1421 break;
1422 case 5:
1423 if ( !bPrjDep )
1425 aLogFileName = yytext;
1427 break;
1428 default:
1429 if ( !bPrjDep )
1431 ByteString aItem = yytext;
1432 if ( aItem == "NULL" )
1434 // Liste zu Ende
1435 i = -1;
1437 else
1439 // ggfs. Dependency liste anlegen und ergaenzen
1440 if ( !pDepList2 )
1441 pDepList2 = new SByteStringList;
1442 pDepList2->PutString( new ByteString( aItem ));
1445 else
1447 ByteString aItem = yytext;
1448 if ( aItem == "NULL" )
1450 // Liste zu Ende
1451 i = -1;
1452 bPrjDep= FALSE;
1454 else
1456 aProjectName = aDirName.GetToken ( 0, '\\');
1457 if ( HasProject( aProjectName ))
1459 pPrj = GetPrj( aProjectName );
1460 // Projekt exist. schon, neue Eintraege anhaengen
1462 else
1464 // neues Project anlegen
1465 pPrj = new Prj ( aProjectName );
1466 pPrj->SetPreFix( aPrefix );
1467 Insert(pPrj,LIST_APPEND);
1469 pPrj->AddDependencies( aItem );
1470 pPrj->HasHardDependencies( bHardDep );
1472 if ( nStarMode == STAR_MODE_RECURSIVE_PARSE ) {
1473 String sItem( aItem, RTL_TEXTENCODING_ASCII_US );
1474 InsertSolarList( sItem );
1479 break;
1481 /* Wenn dieses Project noch nicht vertreten ist, in die Liste
1482 der Solar-Projekte einfuegen */
1483 if ( i == -1 )
1485 aProjectName = aDirName.GetToken ( 0, '\\');
1486 if ( HasProject( aProjectName ))
1488 pPrj = GetPrj( aProjectName );
1489 // Projekt exist. schon, neue Eintraege anhaengen
1491 else
1493 // neues Project anlegen
1494 pPrj = new Prj ( aProjectName );
1495 pPrj->SetPreFix( aPrefix );
1496 Insert(pPrj,LIST_APPEND);
1499 pCmdData = new CommandData;
1500 pCmdData->SetPath( aDirName );
1501 pCmdData->SetCommandType( nCommandType );
1502 pCmdData->SetCommandPara( aCommandPara );
1503 pCmdData->SetOSType( nOSType );
1504 pCmdData->SetLogFile( aLogFileName );
1505 pCmdData->SetComment( aCommentString );
1506 pCmdData->SetClientRestriction( sClientRestriction );
1507 if ( pDepList2 )
1508 pCmdData->SetDependencies( pDepList2 );
1510 pPrj->Insert ( pCmdData, LIST_APPEND );
1513 i++;
1515 rString.Erase(0, aToken.Len()+1);
1516 aToken = rString.GetToken( 0, '\t' );
1517 yytext = aToken.GetBuffer();
1520 // und wer raeumt die depLst wieder ab ?
1523 /*****************************************************************************/
1524 BOOL StarWriter::InsertProject ( Prj* )
1525 /*****************************************************************************/
1527 return FALSE;
1530 /*****************************************************************************/
1531 Prj* StarWriter::RemoveProject ( ByteString aProjectName )
1532 /*****************************************************************************/
1534 ULONG nCountMember = Count();
1535 Prj* pPrj;
1536 Prj* pPrjFound = NULL;
1537 SByteStringList* pPrjDeps;
1539 for ( USHORT i = 0; i < nCountMember; i++ )
1541 pPrj = GetObject( i );
1542 if ( pPrj->GetProjectName() == aProjectName )
1543 pPrjFound = pPrj;
1544 else
1546 pPrjDeps = pPrj->GetDependencies( FALSE );
1547 if ( pPrjDeps )
1549 ByteString* pString;
1550 ULONG nPrjDepsCount = pPrjDeps->Count();
1551 for ( ULONG j = nPrjDepsCount; j > 0; j-- )
1553 pString = pPrjDeps->GetObject( j - 1 );
1554 if ( pString->GetToken( 0, '.') == aProjectName )
1555 pPrjDeps->Remove( pString );
1561 Remove( pPrjFound );
1563 return pPrjFound;
1567 // class StarFile
1570 /*****************************************************************************/
1571 StarFile::StarFile( const String &rFile )
1572 /*****************************************************************************/
1573 : aFileName( rFile )
1575 DirEntry aEntry( aFileName );
1576 if ( aEntry.Exists()) {
1577 bExists = TRUE;
1578 FileStat aStat( aEntry );
1579 aDate = aStat.DateModified();
1580 aTime = aStat.TimeModified();
1582 else
1583 bExists = FALSE;
1586 /*****************************************************************************/
1587 BOOL StarFile::NeedsUpdate()
1588 /*****************************************************************************/
1590 DirEntry aEntry( aFileName );
1591 if ( aEntry.Exists()) {
1592 if ( !bExists ) {
1593 bExists = TRUE;
1594 return TRUE;
1596 FileStat aStat( aEntry );
1597 if (( aStat.DateModified() > aDate ) ||
1598 (( aStat.DateModified() == aDate ) && ( aStat.TimeModified() > aTime )))
1599 return TRUE;
1601 return FALSE;