xref: /trunk/main/tools/bootstrp/prj.cxx (revision 89b56da7)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_tools.hxx"
26 #include <stdlib.h>
27 #include <stdio.h>
28 //#include "bootstrp/sstring.hxx"
29 #include <vos/mutex.hxx>
30 
31 #include <tools/stream.hxx>
32 #include <tools/geninfo.hxx>
33 #include "bootstrp/prj.hxx"
34 #include "bootstrp/inimgr.hxx"
35 
DECLARE_LIST(UniStringList,UniString *)36 DECLARE_LIST( UniStringList, UniString* )
37 
38 //#define TEST 	1
39 
40 #if defined(WNT) || defined(OS2)
41 #define LIST_DELIMETER ';'
42 #define PATH_DELIMETER '\\'
43 #elif defined UNX
44 #define LIST_DELIMETER ':'
45 #define PATH_DELIMETER '/'
46 #endif
47 
48 //Link Star::aDBNotFoundHdl;
49 
50 //
51 //	class SimpleConfig
52 //
53 
54 /*****************************************************************************/
55 SimpleConfig::SimpleConfig( String aSimpleConfigFileName )
56 /*****************************************************************************/
57 {
58 	nLine = 0;
59 	aFileName = aSimpleConfigFileName;
60 	aFileStream.Open ( aFileName, STREAM_READ );
61 }
62 
63 /*****************************************************************************/
SimpleConfig(DirEntry & rDirEntry)64 SimpleConfig::SimpleConfig( DirEntry& rDirEntry )
65 /*****************************************************************************/
66 {
67 	nLine = 0;
68 	aFileName = rDirEntry.GetFull();
69 	aFileStream.Open ( aFileName, STREAM_READ );
70 }
71 
72 /*****************************************************************************/
~SimpleConfig()73 SimpleConfig::~SimpleConfig()
74 /*****************************************************************************/
75 {
76 	aFileStream.Close ();
77 }
78 
79 /*****************************************************************************/
GetNext()80 ByteString SimpleConfig::GetNext()
81 /*****************************************************************************/
82 {
83 	ByteString aString;
84 
85 	if ( aStringBuffer =="" )
86 	  while ((aStringBuffer = GetNextLine()) == "\t") ; //solange bis != "\t"
87 	if ( aStringBuffer =="" )
88 		return ByteString();
89 
90 	aString = aStringBuffer.GetToken(0,'\t');
91 	aStringBuffer.Erase(0, aString.Len()+1);
92 
93 	aStringBuffer.EraseLeadingChars( '\t' );
94 
95 	return aString;
96 }
97 
98 /*****************************************************************************/
GetNextLine()99 ByteString	SimpleConfig::GetNextLine()
100 /*****************************************************************************/
101 {
102 	ByteString aSecStr;
103 	nLine++;
104 
105 	aFileStream.ReadLine ( aTmpStr );
106 	if ( aTmpStr.Search( "#" ) == 0 )
107 		return "\t";
108 	aTmpStr = aTmpStr.EraseLeadingChars();
109 	aTmpStr = aTmpStr.EraseTrailingChars();
110 	while ( aTmpStr.SearchAndReplace(ByteString(' '),ByteString('\t') ) != STRING_NOTFOUND ) ;
111 	int nLength = aTmpStr.Len();
112 	sal_Bool bFound = sal_False;
113 	ByteString aEraseString;
114 	for ( sal_uInt16 i = 0; i<= nLength; i++)
115 	{
116 		if ( aTmpStr.GetChar( i ) == 0x20  && !bFound )
117 			aTmpStr.SetChar( i, 0x09 );
118 	}
119 	return aTmpStr;
120 }
121 
122 /*****************************************************************************/
GetCleanedNextLine(sal_Bool bReadComments)123 ByteString SimpleConfig::GetCleanedNextLine( sal_Bool bReadComments )
124 /*****************************************************************************/
125 {
126 
127 	aFileStream.ReadLine ( aTmpStr );
128 	if ( aTmpStr.Search( "#" ) == 0 )
129         {
130 		if (bReadComments )
131 			return aTmpStr;
132 		else
133 			while ( aTmpStr.Search( "#" ) == 0 )
134 			{
135 				aFileStream.ReadLine ( aTmpStr );
136 			}
137         }
138 
139 	aTmpStr = aTmpStr.EraseLeadingChars();
140 	aTmpStr = aTmpStr.EraseTrailingChars();
141 //	while ( aTmpStr.SearchAndReplace(String(' '),String('\t') ) != (sal_uInt16)-1 );
142 	int nLength = aTmpStr.Len();
143 	ByteString aEraseString;
144 	sal_Bool bFirstTab = sal_True;
145 	for ( sal_uInt16 i = 0; i<= nLength; i++)
146 	{
147 		if ( aTmpStr.GetChar( i ) == 0x20 )
148 			aTmpStr.SetChar( i, 0x09 );
149 
150 		if ( aTmpStr.GetChar( i ) ==  0x09 )
151 		{
152 			if ( bFirstTab )
153 				bFirstTab = sal_False;
154 			else
155 			{
156 				aTmpStr.SetChar( i, 0x20 );
157 			}
158 		}
159 		else
160 			bFirstTab = sal_True;
161 
162 	}
163 	aTmpStr.EraseAllChars(' ');
164 	return aTmpStr;
165 
166 }
167 
168