xref: /aoo41x/main/soldep/bootstrp/minormk.cxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #include "minormk.hxx"
29 #include "prodmap.hxx"
30 #include <soldep/appdef.hxx>
31 #include <tools/fsys.hxx>
32 #include <tools/geninfo.hxx>
33 
34 //
35 // class MinorMk
36 //
37 
38 /*****************************************************************************/
39 MinorMk::MinorMk(
40 	GenericInformationList *pList,
41 	const ByteString &rVersion,
42 	const ByteString &rWorkStamp,
43 	const ByteString &rEnvironment,
44 	const ByteString &rMinor
45 )
46 /*****************************************************************************/
47 {
48 	String sRoot( ProductMapper::GetVersionRoot( pList, rVersion ));
49 	if ( sRoot.Len()) {
50 		ByteString sPath( sRoot, RTL_TEXTENCODING_ASCII_US );
51 		sPath += "/";
52 		sPath += rEnvironment;
53 		sPath += "/";
54 		sPath += "inc";
55 		if ( rMinor.Len()) {
56 			sPath += ".";
57 			sPath += rMinor;
58 		}
59 #ifdef UNX
60 		sPath.SearchAndReplaceAll( "\\", "/" );
61 		while( sPath.SearchAndReplace( "//", "/" ) != STRING_NOTFOUND ) {};
62 #else
63 		sPath.SearchAndReplaceAll( "/", "\\" );
64 		while( sPath.SearchAndReplace( "\\\\", "\\" ) != STRING_NOTFOUND ) {};
65 #endif
66 		DirEntry aPath( String( sPath, RTL_TEXTENCODING_ASCII_US ));
67 
68 		ByteString sFile( rWorkStamp );
69 		sFile += "minor.mk";
70 
71 		DirEntry aFile( aPath );
72 		aFile += DirEntry( String( sFile, RTL_TEXTENCODING_ASCII_US ));
73 		if ( !aFile.Exists()) {
74 			sFile = sFile.Copy( 3 );
75 			aFile = aPath;
76 			aFile += DirEntry( String( sFile, RTL_TEXTENCODING_ASCII_US ));
77 		}
78 		ReadMinorMk( aFile.GetFull());
79 	}
80 }
81 
82 /*****************************************************************************/
83 MinorMk::MinorMk( GenericInformationList *pList, const ByteString rVersion )
84 /*****************************************************************************/
85 {
86 	String sRoot( ProductMapper::GetVersionRoot( pList, rVersion ));
87 	if ( sRoot.Len()) {
88 		ByteString sPath( sRoot, RTL_TEXTENCODING_ASCII_US );
89 		sPath += "/src/solenv/inc";
90 #ifdef UNX
91 		sPath.SearchAndReplaceAll( "\\", "/" );
92 		while( sPath.SearchAndReplace( "//", "/" ) != STRING_NOTFOUND ) {};
93 #else
94 		sPath.SearchAndReplaceAll( "/", "\\" );
95 		while( sPath.SearchAndReplace( "\\\\", "\\" ) != STRING_NOTFOUND ) {};
96 #endif
97 		DirEntry aPath( String( sPath, RTL_TEXTENCODING_ASCII_US ));
98 
99  		ByteString sFile( "minor.mk" );
100 
101 		DirEntry aFile( aPath );
102 		aFile += DirEntry( String( sFile, RTL_TEXTENCODING_ASCII_US ));
103 
104 		ReadMinorMk( aFile.GetFull());
105 	}
106 }
107 
108 /*****************************************************************************/
109 MinorMk::MinorMk( const ByteString &rMinor,	const ByteString &rEnvironment )
110 /*****************************************************************************/
111 				: bExists( sal_False )
112 {
113 	ByteString sDelimiter( DirEntry::GetAccessDelimiter(), RTL_TEXTENCODING_ASCII_US );
114 
115 
116 	ByteString sSolver( GetEnv( "SOLARVERSION" ));
117 	sal_Bool bNewEnv = sal_True;
118 	if ( !sSolver.Len()) {
119 		sSolver = GetEnv( "SOLARVER" );
120 		bNewEnv = sal_False;
121 	}
122 	ByteString sUPD( GetEnv( "UPD" ));
123 
124 	ByteString sMinorMk( sSolver );
125 	sMinorMk += sDelimiter;
126 	if ( !bNewEnv ) {
127 		sMinorMk += sUPD;
128 		sMinorMk += sDelimiter;
129 	}
130 
131 	if ( rEnvironment.Len()) {
132 		sMinorMk += rEnvironment;
133 		sMinorMk += sDelimiter;
134 		sMinorMk += "inc";
135 		if( rMinor.Len()) {
136 			sMinorMk += ".";
137 			sMinorMk += rMinor;
138 		}
139 		sMinorMk += sDelimiter;
140 	}
141 
142 	sMinorMk += sUPD;
143 	sMinorMk += "minor.mk";
144 
145 	String sFile( sMinorMk, RTL_TEXTENCODING_ASCII_US );
146 
147 	ReadMinorMk( sFile );
148 }
149 
150 /*****************************************************************************/
151 void MinorMk::ReadMinorMk( const String &rFileName )
152 /*****************************************************************************/
153 {
154 	if ( DirEntry( rFileName ).Exists()) {
155 		bExists = sal_True;
156 		SvFileStream aStream( rFileName, STREAM_STD_READ );
157 		while ( !aStream.IsOpen())
158 			aStream.Open( rFileName, STREAM_STD_READ );
159 
160 		ByteString sLine;
161 		while ( !aStream.IsEof()) {
162 			aStream.ReadLine( sLine );
163 
164 			if ( sLine.GetToken( 0, '=' ) == "RSCVERSION" )
165 				sRSCVERSION = sLine.GetToken( 1, '=' );
166 			else if ( sLine.GetToken( 0, '=' ) == "RSCREVISION" )
167 				sRSCREVISION = sLine.GetToken( 1, '=' );
168 			else if ( sLine.GetToken( 0, '=' ) == "BUILD" )
169 				sBUILD = sLine.GetToken( 1, '=' );
170 			else if ( sLine.GetToken( 0, '=' ) == "LAST_MINOR" )
171 				sLAST_MINOR = sLine.GetToken( 1, '=' );
172 		}
173 		aStream.Close();
174 
175 		sRSCVERSION.EraseTrailingChars();
176 		sRSCREVISION.EraseTrailingChars();
177 		sBUILD.EraseTrailingChars();
178 		sLAST_MINOR.EraseTrailingChars();
179 	}
180 }
181 
182 /*****************************************************************************/
183 MinorMk::~MinorMk()
184 /*****************************************************************************/
185 {
186 }
187 
188