xref: /aoo41x/main/tools/bootstrp/prj.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 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_tools.hxx"
30 #include <stdlib.h>
31 #include <stdio.h>
32 //#include "bootstrp/sstring.hxx"
33 #include <vos/mutex.hxx>
34 
35 #include <tools/stream.hxx>
36 #include <tools/geninfo.hxx>
37 #include "bootstrp/prj.hxx"
38 #include "bootstrp/inimgr.hxx"
39 
40 DECLARE_LIST( UniStringList, UniString* )
41 
42 //#define TEST 	1
43 
44 #if defined(WNT) || defined(OS2)
45 #define LIST_DELIMETER ';'
46 #define PATH_DELIMETER '\\'
47 #elif defined UNX
48 #define LIST_DELIMETER ':'
49 #define PATH_DELIMETER '/'
50 #endif
51 
52 //Link Star::aDBNotFoundHdl;
53 
54 //
55 //	class SimpleConfig
56 //
57 
58 /*****************************************************************************/
59 SimpleConfig::SimpleConfig( String aSimpleConfigFileName )
60 /*****************************************************************************/
61 {
62 	nLine = 0;
63 	aFileName = aSimpleConfigFileName;
64 	aFileStream.Open ( aFileName, STREAM_READ );
65 }
66 
67 /*****************************************************************************/
68 SimpleConfig::SimpleConfig( DirEntry& rDirEntry )
69 /*****************************************************************************/
70 {
71 	nLine = 0;
72 	aFileName = rDirEntry.GetFull();
73 	aFileStream.Open ( aFileName, STREAM_READ );
74 }
75 
76 /*****************************************************************************/
77 SimpleConfig::~SimpleConfig()
78 /*****************************************************************************/
79 {
80 	aFileStream.Close ();
81 }
82 
83 /*****************************************************************************/
84 ByteString SimpleConfig::GetNext()
85 /*****************************************************************************/
86 {
87 	ByteString aString;
88 
89 	if ( aStringBuffer =="" )
90 	  while ((aStringBuffer = GetNextLine()) == "\t") ; //solange bis != "\t"
91 	if ( aStringBuffer =="" )
92 		return ByteString();
93 
94 	aString = aStringBuffer.GetToken(0,'\t');
95 	aStringBuffer.Erase(0, aString.Len()+1);
96 
97 	aStringBuffer.EraseLeadingChars( '\t' );
98 
99 	return aString;
100 }
101 
102 /*****************************************************************************/
103 ByteString	SimpleConfig::GetNextLine()
104 /*****************************************************************************/
105 {
106 	ByteString aSecStr;
107 	nLine++;
108 
109 	aFileStream.ReadLine ( aTmpStr );
110 	if ( aTmpStr.Search( "#" ) == 0 )
111 		return "\t";
112 	aTmpStr = aTmpStr.EraseLeadingChars();
113 	aTmpStr = aTmpStr.EraseTrailingChars();
114 	while ( aTmpStr.SearchAndReplace(ByteString(' '),ByteString('\t') ) != STRING_NOTFOUND ) ;
115 	int nLength = aTmpStr.Len();
116 	sal_Bool bFound = sal_False;
117 	ByteString aEraseString;
118 	for ( sal_uInt16 i = 0; i<= nLength; i++)
119 	{
120 		if ( aTmpStr.GetChar( i ) == 0x20  && !bFound )
121 			aTmpStr.SetChar( i, 0x09 );
122 	}
123 	return aTmpStr;
124 }
125 
126 /*****************************************************************************/
127 ByteString SimpleConfig::GetCleanedNextLine( sal_Bool bReadComments )
128 /*****************************************************************************/
129 {
130 
131 	aFileStream.ReadLine ( aTmpStr );
132 	if ( aTmpStr.Search( "#" ) == 0 )
133         {
134 		if (bReadComments )
135 			return aTmpStr;
136 		else
137 			while ( aTmpStr.Search( "#" ) == 0 )
138 			{
139 				aFileStream.ReadLine ( aTmpStr );
140 			}
141         }
142 
143 	aTmpStr = aTmpStr.EraseLeadingChars();
144 	aTmpStr = aTmpStr.EraseTrailingChars();
145 //	while ( aTmpStr.SearchAndReplace(String(' '),String('\t') ) != (sal_uInt16)-1 );
146 	int nLength = aTmpStr.Len();
147 	ByteString aEraseString;
148 	sal_Bool bFirstTab = sal_True;
149 	for ( sal_uInt16 i = 0; i<= nLength; i++)
150 	{
151 		if ( aTmpStr.GetChar( i ) == 0x20 )
152 			aTmpStr.SetChar( i, 0x09 );
153 
154 		if ( aTmpStr.GetChar( i ) ==  0x09 )
155 		{
156 			if ( bFirstTab )
157 				bFirstTab = sal_False;
158 			else
159 			{
160 				aTmpStr.SetChar( i, 0x20 );
161 			}
162 		}
163 		else
164 			bFirstTab = sal_True;
165 
166 	}
167 	aTmpStr.EraseAllChars(' ');
168 	return aTmpStr;
169 
170 }
171 
172