xref: /trunk/main/sal/osl/os2/profile.c (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir #include "system.h"
29*cdf0e10cSrcweir 
30*cdf0e10cSrcweir // YD #define min(a,b) (((a) < (b)) ? (a) : (b))
31*cdf0e10cSrcweir 
32*cdf0e10cSrcweir #include <osl/security.h>
33*cdf0e10cSrcweir #include <osl/diagnose.h>
34*cdf0e10cSrcweir #include <osl/profile.h>
35*cdf0e10cSrcweir #include <osl/process.h>
36*cdf0e10cSrcweir #include <osl/thread.h>
37*cdf0e10cSrcweir #include <osl/file.h>
38*cdf0e10cSrcweir 
39*cdf0e10cSrcweir #define LINES_INI       32
40*cdf0e10cSrcweir #define LINES_ADD       10
41*cdf0e10cSrcweir #define SECTIONS_INI    5
42*cdf0e10cSrcweir #define SECTIONS_ADD    3
43*cdf0e10cSrcweir #define ENTRIES_INI     5
44*cdf0e10cSrcweir #define ENTRIES_ADD     3
45*cdf0e10cSrcweir 
46*cdf0e10cSrcweir 
47*cdf0e10cSrcweir #define STR_INI_EXTENSION   ".ini"
48*cdf0e10cSrcweir #define STR_INI_METAHOME    "?~"
49*cdf0e10cSrcweir #define STR_INI_METASYS     "?$"
50*cdf0e10cSrcweir #define STR_INI_METACFG     "?^"
51*cdf0e10cSrcweir #define STR_INI_METAINS     "?#"
52*cdf0e10cSrcweir 
53*cdf0e10cSrcweir #define STR_INI_BOOLYES     "yes"
54*cdf0e10cSrcweir #define STR_INI_BOOLON      "on"
55*cdf0e10cSrcweir #define STR_INI_BOOLONE     "1"
56*cdf0e10cSrcweir #define STR_INI_BOOLNO      "no"
57*cdf0e10cSrcweir #define STR_INI_BOOLOFF     "off"
58*cdf0e10cSrcweir #define STR_INI_BOOLZERO    "0"
59*cdf0e10cSrcweir 
60*cdf0e10cSrcweir #define FLG_USER            0x00FF
61*cdf0e10cSrcweir #define FLG_AUTOOPEN        0x0100
62*cdf0e10cSrcweir #define FLG_MODIFIED        0x0200
63*cdf0e10cSrcweir 
64*cdf0e10cSrcweir #define SVERSION_LOCATION   STR_INI_METACFG
65*cdf0e10cSrcweir #define SVERSION_FALLBACK   STR_INI_METASYS
66*cdf0e10cSrcweir #define SVERSION_NAME       "sversion"
67*cdf0e10cSrcweir #define SVERSION_SECTION    "Versions"
68*cdf0e10cSrcweir #define SVERSION_SOFFICE    "StarOffice"
69*cdf0e10cSrcweir #define SVERSION_PROFILE    "soffice.ini"
70*cdf0e10cSrcweir #define SVERSION_OPTION     "userid:"
71*cdf0e10cSrcweir #define SVERSION_DIRS       { "bin", "program" }
72*cdf0e10cSrcweir #define SVERSION_USER       "user"
73*cdf0e10cSrcweir 
74*cdf0e10cSrcweir #define _BUILD_STR_(n)  # n
75*cdf0e10cSrcweir #define BUILD_STR(n)    _BUILD_STR_(n)
76*cdf0e10cSrcweir 
77*cdf0e10cSrcweir /* implemented in file.c */
78*cdf0e10cSrcweir extern oslFileError FileURLToPath( char *, size_t, rtl_uString* );
79*cdf0e10cSrcweir 
80*cdf0e10cSrcweir /*****************************************************************************/
81*cdf0e10cSrcweir /* Data Type Definition */
82*cdf0e10cSrcweir /*****************************************************************************/
83*cdf0e10cSrcweir 
84*cdf0e10cSrcweir typedef struct _osl_TStamp
85*cdf0e10cSrcweir {
86*cdf0e10cSrcweir     FDATE  m_Date;
87*cdf0e10cSrcweir     FTIME  m_Time;
88*cdf0e10cSrcweir } osl_TStamp;
89*cdf0e10cSrcweir 
90*cdf0e10cSrcweir typedef enum _osl_TLockMode
91*cdf0e10cSrcweir {
92*cdf0e10cSrcweir     un_lock, read_lock, write_lock
93*cdf0e10cSrcweir } osl_TLockMode;
94*cdf0e10cSrcweir 
95*cdf0e10cSrcweir typedef struct _osl_TFile
96*cdf0e10cSrcweir {
97*cdf0e10cSrcweir     HFILE   m_Handle;
98*cdf0e10cSrcweir /*
99*cdf0e10cSrcweir     sal_Char*   m_pReadPtr;
100*cdf0e10cSrcweir     sal_Char    m_ReadBuf[512];
101*cdf0e10cSrcweir     sal_Char*   m_pWritePtr;
102*cdf0e10cSrcweir     sal_Char    m_WriteBuf[512];
103*cdf0e10cSrcweir */
104*cdf0e10cSrcweir     sal_Char*   m_pReadPtr;
105*cdf0e10cSrcweir     sal_Char    m_ReadBuf[512];
106*cdf0e10cSrcweir /*      sal_Char*   m_pWritePtr; */
107*cdf0e10cSrcweir /*      sal_Char    m_WriteBuf[512]; */
108*cdf0e10cSrcweir     sal_Char*   m_pWriteBuf;
109*cdf0e10cSrcweir     sal_uInt32  m_nWriteBufLen;
110*cdf0e10cSrcweir     sal_uInt32  m_nWriteBufFree;
111*cdf0e10cSrcweir } osl_TFile;
112*cdf0e10cSrcweir 
113*cdf0e10cSrcweir typedef struct _osl_TProfileEntry
114*cdf0e10cSrcweir {
115*cdf0e10cSrcweir     sal_uInt32    m_Line;
116*cdf0e10cSrcweir     sal_uInt32    m_Offset;
117*cdf0e10cSrcweir     sal_uInt32    m_Len;
118*cdf0e10cSrcweir } osl_TProfileEntry;
119*cdf0e10cSrcweir 
120*cdf0e10cSrcweir typedef struct _osl_TProfileSection
121*cdf0e10cSrcweir {
122*cdf0e10cSrcweir     sal_uInt32            m_Line;
123*cdf0e10cSrcweir     sal_uInt32            m_Offset;
124*cdf0e10cSrcweir     sal_uInt32            m_Len;
125*cdf0e10cSrcweir     sal_uInt32            m_NoEntries;
126*cdf0e10cSrcweir     sal_uInt32            m_MaxEntries;
127*cdf0e10cSrcweir     osl_TProfileEntry*  m_Entries;
128*cdf0e10cSrcweir } osl_TProfileSection;
129*cdf0e10cSrcweir 
130*cdf0e10cSrcweir 
131*cdf0e10cSrcweir /*
132*cdf0e10cSrcweir     Profile-data structure hidden behind oslProfile:
133*cdf0e10cSrcweir */
134*cdf0e10cSrcweir typedef struct _osl_TProfileImpl
135*cdf0e10cSrcweir {
136*cdf0e10cSrcweir     sal_uInt32  m_Flags;
137*cdf0e10cSrcweir     osl_TFile*  m_pFile;
138*cdf0e10cSrcweir     osl_TStamp  m_Stamp;
139*cdf0e10cSrcweir     //sal_Char    m_Filename[_MAX_PATH + 1];
140*cdf0e10cSrcweir     sal_uInt32  m_NoLines;
141*cdf0e10cSrcweir     sal_uInt32  m_MaxLines;
142*cdf0e10cSrcweir     sal_uInt32  m_NoSections;
143*cdf0e10cSrcweir     sal_uInt32  m_MaxSections;
144*cdf0e10cSrcweir     sal_Char**  m_Lines;
145*cdf0e10cSrcweir     rtl_uString *m_strFileName;
146*cdf0e10cSrcweir     osl_TProfileSection*    m_Sections;
147*cdf0e10cSrcweir     HINI                    m_hIni;
148*cdf0e10cSrcweir } osl_TProfileImpl;
149*cdf0e10cSrcweir 
150*cdf0e10cSrcweir 
151*cdf0e10cSrcweir /*****************************************************************************/
152*cdf0e10cSrcweir /* Static Module Function Declarations */
153*cdf0e10cSrcweir /*****************************************************************************/
154*cdf0e10cSrcweir 
155*cdf0e10cSrcweir //static osl_TFile* openFile(rtl_uString* pszFilename, sal_Bool bWriteable);
156*cdf0e10cSrcweir //static osl_TStamp closeFile(osl_TFile* pFile);
157*cdf0e10cSrcweir static osl_TFile*           openFileImpl(rtl_uString * strFileName, oslProfileOption ProfileFlags  );
158*cdf0e10cSrcweir static osl_TStamp           closeFileImpl(osl_TFile* pFile);
159*cdf0e10cSrcweir static sal_Bool   lockFile(const osl_TFile* pFile, osl_TLockMode eMode);
160*cdf0e10cSrcweir static sal_Bool   rewindFile(osl_TFile* pFile, sal_Bool bTruncate);
161*cdf0e10cSrcweir static osl_TStamp getFileStamp(osl_TFile* pFile);
162*cdf0e10cSrcweir 
163*cdf0e10cSrcweir static sal_Bool getLine(osl_TFile* pFile, const sal_Char *pszLine, int MaxLen);
164*cdf0e10cSrcweir static sal_Bool putLine(osl_TFile* pFile, const sal_Char *pszLine);
165*cdf0e10cSrcweir static const sal_Char* stripBlanks(const sal_Char* String, sal_uInt32* pLen);
166*cdf0e10cSrcweir static const sal_Char* addLine(osl_TProfileImpl* pProfile, const sal_Char* Line);
167*cdf0e10cSrcweir static const sal_Char* insertLine(osl_TProfileImpl* pProfile, const sal_Char* Line, sal_uInt32 LineNo);
168*cdf0e10cSrcweir static void removeLine(osl_TProfileImpl* pProfile, sal_uInt32 LineNo);
169*cdf0e10cSrcweir static void setEntry(osl_TProfileImpl* pProfile, osl_TProfileSection* pSection,
170*cdf0e10cSrcweir                      sal_uInt32 NoEntry, sal_uInt32 Line,
171*cdf0e10cSrcweir                      const sal_Char* Entry, sal_uInt32 Len);
172*cdf0e10cSrcweir static sal_Bool addEntry(osl_TProfileImpl* pProfile, osl_TProfileSection *pSection,
173*cdf0e10cSrcweir                          int Line, const sal_Char* Entry, sal_uInt32 Len);
174*cdf0e10cSrcweir static void removeEntry(osl_TProfileSection *pSection, sal_uInt32 NoEntry);
175*cdf0e10cSrcweir static sal_Bool addSection(osl_TProfileImpl* pProfile, int Line, const sal_Char* Section, sal_uInt32 Len);
176*cdf0e10cSrcweir static void removeSection(osl_TProfileImpl* pProfile, osl_TProfileSection *pSection);
177*cdf0e10cSrcweir static osl_TProfileSection* findEntry(osl_TProfileImpl* pProfile, const sal_Char* Section,
178*cdf0e10cSrcweir                                       const sal_Char* Entry, sal_uInt32 *pNoEntry);
179*cdf0e10cSrcweir static sal_Bool loadProfile(osl_TFile* pFile, osl_TProfileImpl* pProfile);
180*cdf0e10cSrcweir static sal_Bool storeProfile(osl_TFile* pFile, osl_TProfileImpl* pProfile, sal_Bool bCleanup);
181*cdf0e10cSrcweir static osl_TProfileImpl* acquireProfile(oslProfile Profile, sal_Bool bWriteable);
182*cdf0e10cSrcweir static sal_Bool releaseProfile(osl_TProfileImpl* pProfile);
183*cdf0e10cSrcweir static sal_Bool lookupProfile(const sal_Char *pszPath, const sal_Char *pszFile, sal_Char *pPath);
184*cdf0e10cSrcweir 
185*cdf0e10cSrcweir 
186*cdf0e10cSrcweir static sal_Bool SAL_CALL osl_getProfileName(rtl_uString* strPath, rtl_uString* strName, rtl_uString** strProfileName);
187*cdf0e10cSrcweir 
188*cdf0e10cSrcweir sal_Bool SAL_CALL osl_getFullPath(rtl_uString* pszFilename, sal_Char* pszPath, sal_uInt32 MaxLen)
189*cdf0e10cSrcweir {
190*cdf0e10cSrcweir     return NO_ERROR == DosQueryPathInfo( (PCSZ)pszFilename, FIL_QUERYFULLNAME, pszPath, MaxLen);
191*cdf0e10cSrcweir }
192*cdf0e10cSrcweir 
193*cdf0e10cSrcweir 
194*cdf0e10cSrcweir 
195*cdf0e10cSrcweir /*****************************************************************************/
196*cdf0e10cSrcweir /* Exported Module Functions */
197*cdf0e10cSrcweir /*****************************************************************************/
198*cdf0e10cSrcweir 
199*cdf0e10cSrcweir oslProfile SAL_CALL osl_openProfile(rtl_uString *strProfileName, sal_uInt32 Flags)
200*cdf0e10cSrcweir {
201*cdf0e10cSrcweir     osl_TFile*        pFile;
202*cdf0e10cSrcweir     osl_TProfileImpl* pProfile;
203*cdf0e10cSrcweir     rtl_uString       *FileName=NULL;
204*cdf0e10cSrcweir 
205*cdf0e10cSrcweir #ifdef TRACE_OSL_PROFILE
206*cdf0e10cSrcweir     OSL_TRACE("In  osl_openProfile\n");
207*cdf0e10cSrcweir #endif
208*cdf0e10cSrcweir     OSL_VERIFY(strProfileName);
209*cdf0e10cSrcweir 
210*cdf0e10cSrcweir /*  if (rtl_uString_getLength(strProfileName) == 0 )
211*cdf0e10cSrcweir     {
212*cdf0e10cSrcweir         OSL_VERIFY(osl_getProfileName(NULL, NULL, &FileName));
213*cdf0e10cSrcweir     }
214*cdf0e10cSrcweir     else
215*cdf0e10cSrcweir */
216*cdf0e10cSrcweir     {
217*cdf0e10cSrcweir         rtl_uString_assign(&FileName, strProfileName);
218*cdf0e10cSrcweir     }
219*cdf0e10cSrcweir 
220*cdf0e10cSrcweir     osl_getSystemPathFromFileURL(FileName, &FileName);
221*cdf0e10cSrcweir 
222*cdf0e10cSrcweir #ifdef DEBUG_OSL_PROFILE
223*cdf0e10cSrcweir     Flags=osl_Profile_FLUSHWRITE;
224*cdf0e10cSrcweir 
225*cdf0e10cSrcweir     // OSL_TRACE("opening '%s'\n",FileName);
226*cdf0e10cSrcweir     if ( Flags == osl_Profile_DEFAULT )
227*cdf0e10cSrcweir     {
228*cdf0e10cSrcweir         OSL_TRACE("with osl_Profile_DEFAULT \n");
229*cdf0e10cSrcweir     }
230*cdf0e10cSrcweir     if ( Flags & osl_Profile_SYSTEM )
231*cdf0e10cSrcweir     {
232*cdf0e10cSrcweir         OSL_TRACE("with osl_Profile_SYSTEM \n");
233*cdf0e10cSrcweir     }
234*cdf0e10cSrcweir     if ( Flags & osl_Profile_READLOCK )
235*cdf0e10cSrcweir     {
236*cdf0e10cSrcweir         OSL_TRACE("with osl_Profile_READLOCK \n");
237*cdf0e10cSrcweir     }
238*cdf0e10cSrcweir     if ( Flags & osl_Profile_WRITELOCK )
239*cdf0e10cSrcweir     {
240*cdf0e10cSrcweir         OSL_TRACE("with osl_Profile_WRITELOCK \n");
241*cdf0e10cSrcweir     }
242*cdf0e10cSrcweir /*      if ( Flags & osl_Profile_READWRITE ) */
243*cdf0e10cSrcweir /*      { */
244*cdf0e10cSrcweir /*          OSL_TRACE("with osl_Profile_READWRITE \n"); */
245*cdf0e10cSrcweir /*      } */
246*cdf0e10cSrcweir     if ( Flags & osl_Profile_FLUSHWRITE )
247*cdf0e10cSrcweir     {
248*cdf0e10cSrcweir         OSL_TRACE("with osl_Profile_FLUSHWRITE \n");
249*cdf0e10cSrcweir     }
250*cdf0e10cSrcweir #endif
251*cdf0e10cSrcweir 
252*cdf0e10cSrcweir     if ((! (Flags & osl_Profile_SYSTEM)) &&
253*cdf0e10cSrcweir         ((pFile = openFileImpl(FileName, (Flags & osl_Profile_WRITELOCK) ? sal_True : sal_False)) == NULL))
254*cdf0e10cSrcweir     {
255*cdf0e10cSrcweir #ifdef TRACE_OSL_PROFILE
256*cdf0e10cSrcweir         OSL_TRACE("Out osl_openProfile [not opened]\n");
257*cdf0e10cSrcweir #endif
258*cdf0e10cSrcweir         if( FileName)
259*cdf0e10cSrcweir             rtl_uString_release( FileName);
260*cdf0e10cSrcweir 
261*cdf0e10cSrcweir         return (NULL);
262*cdf0e10cSrcweir     }
263*cdf0e10cSrcweir 
264*cdf0e10cSrcweir     pProfile = (osl_TProfileImpl*)calloc(1, sizeof(osl_TProfileImpl));
265*cdf0e10cSrcweir 
266*cdf0e10cSrcweir     pProfile->m_Flags = Flags & FLG_USER;
267*cdf0e10cSrcweir     osl_getSystemPathFromFileURL(strProfileName, &pProfile->m_strFileName);
268*cdf0e10cSrcweir //  rtl_uString_assign(&pProfile->m_strFileName, strProfileName);
269*cdf0e10cSrcweir 
270*cdf0e10cSrcweir     if (Flags & (osl_Profile_READLOCK | osl_Profile_WRITELOCK))
271*cdf0e10cSrcweir         pProfile->m_pFile = pFile;
272*cdf0e10cSrcweir 
273*cdf0e10cSrcweir     pProfile->m_Stamp = getFileStamp(pFile);
274*cdf0e10cSrcweir 
275*cdf0e10cSrcweir     loadProfile(pFile, pProfile);
276*cdf0e10cSrcweir 
277*cdf0e10cSrcweir     if (pProfile->m_pFile == NULL)
278*cdf0e10cSrcweir         closeFileImpl(pFile);
279*cdf0e10cSrcweir 
280*cdf0e10cSrcweir #ifdef TRACE_OSL_PROFILE
281*cdf0e10cSrcweir     OSL_TRACE("Out osl_openProfile [ok]\n");
282*cdf0e10cSrcweir #endif
283*cdf0e10cSrcweir     if( FileName)
284*cdf0e10cSrcweir         rtl_uString_release( FileName);
285*cdf0e10cSrcweir 
286*cdf0e10cSrcweir     return pProfile;
287*cdf0e10cSrcweir }
288*cdf0e10cSrcweir 
289*cdf0e10cSrcweir sal_Bool SAL_CALL osl_closeProfile(oslProfile Profile)
290*cdf0e10cSrcweir {
291*cdf0e10cSrcweir     osl_TProfileImpl* pProfile = (osl_TProfileImpl*)Profile;
292*cdf0e10cSrcweir 
293*cdf0e10cSrcweir #ifdef TRACE_OSL_PROFILE
294*cdf0e10cSrcweir     OSL_TRACE("In  osl_closeProfile\n");
295*cdf0e10cSrcweir #endif
296*cdf0e10cSrcweir 
297*cdf0e10cSrcweir     if ( pProfile == 0 )
298*cdf0e10cSrcweir     {
299*cdf0e10cSrcweir #ifdef TRACE_OSL_PROFILE
300*cdf0e10cSrcweir         OSL_TRACE("Out osl_closeProfile [profile==0]\n");
301*cdf0e10cSrcweir #endif
302*cdf0e10cSrcweir         return sal_False;
303*cdf0e10cSrcweir     }
304*cdf0e10cSrcweir 
305*cdf0e10cSrcweir     if (! (pProfile->m_Flags & osl_Profile_SYSTEM))
306*cdf0e10cSrcweir     {
307*cdf0e10cSrcweir         pProfile = acquireProfile(Profile,sal_True);
308*cdf0e10cSrcweir 
309*cdf0e10cSrcweir         if ( pProfile != 0 )
310*cdf0e10cSrcweir         {
311*cdf0e10cSrcweir             if ( !( pProfile->m_Flags & osl_Profile_READLOCK )  && ( pProfile->m_Flags & FLG_MODIFIED ) )
312*cdf0e10cSrcweir             {
313*cdf0e10cSrcweir /*                  if (pProfile->m_pFile == NULL) */
314*cdf0e10cSrcweir /*                      pProfile->m_pFile = openFileImpl(pProfile->m_Filename, sal_True); */
315*cdf0e10cSrcweir 
316*cdf0e10cSrcweir                 storeProfile(pProfile->m_pFile, pProfile, sal_False);
317*cdf0e10cSrcweir             }
318*cdf0e10cSrcweir         }
319*cdf0e10cSrcweir         else
320*cdf0e10cSrcweir         {
321*cdf0e10cSrcweir             pProfile = acquireProfile(Profile,sal_False);
322*cdf0e10cSrcweir         }
323*cdf0e10cSrcweir 
324*cdf0e10cSrcweir         if ( pProfile == 0 )
325*cdf0e10cSrcweir         {
326*cdf0e10cSrcweir #ifdef TRACE_OSL_PROFILE
327*cdf0e10cSrcweir             OSL_TRACE("Out osl_closeProfile [pProfile==0]\n");
328*cdf0e10cSrcweir #endif
329*cdf0e10cSrcweir             return sal_False;
330*cdf0e10cSrcweir         }
331*cdf0e10cSrcweir 
332*cdf0e10cSrcweir         if (pProfile->m_pFile != NULL)
333*cdf0e10cSrcweir             closeFileImpl(pProfile->m_pFile);
334*cdf0e10cSrcweir     }
335*cdf0e10cSrcweir 
336*cdf0e10cSrcweir     pProfile->m_pFile = NULL;
337*cdf0e10cSrcweir     rtl_uString_release(pProfile->m_strFileName);
338*cdf0e10cSrcweir     pProfile->m_strFileName = NULL;
339*cdf0e10cSrcweir 
340*cdf0e10cSrcweir     /* release whole profile data types memory */
341*cdf0e10cSrcweir     if ( pProfile->m_NoLines > 0)
342*cdf0e10cSrcweir     {
343*cdf0e10cSrcweir         unsigned int index=0;
344*cdf0e10cSrcweir         if ( pProfile->m_Lines != 0 )
345*cdf0e10cSrcweir         {
346*cdf0e10cSrcweir             for ( index = 0 ; index < pProfile->m_NoLines ; ++index)
347*cdf0e10cSrcweir             {
348*cdf0e10cSrcweir                 if ( pProfile->m_Lines[index] != 0 )
349*cdf0e10cSrcweir                 {
350*cdf0e10cSrcweir                     free(pProfile->m_Lines[index]);
351*cdf0e10cSrcweir                 }
352*cdf0e10cSrcweir             }
353*cdf0e10cSrcweir             free(pProfile->m_Lines);
354*cdf0e10cSrcweir         }
355*cdf0e10cSrcweir         if ( pProfile->m_Sections != 0 )
356*cdf0e10cSrcweir         {
357*cdf0e10cSrcweir             /*osl_TProfileSection* pSections=pProfile->m_Sections;*/
358*cdf0e10cSrcweir             for ( index = 0 ; index < pProfile->m_NoSections ; ++index )
359*cdf0e10cSrcweir             {
360*cdf0e10cSrcweir                 if ( pProfile->m_Sections[index].m_Entries != 0 )
361*cdf0e10cSrcweir                 {
362*cdf0e10cSrcweir                     free(pProfile->m_Sections[index].m_Entries);
363*cdf0e10cSrcweir                 }
364*cdf0e10cSrcweir             }
365*cdf0e10cSrcweir             free(pProfile->m_Sections);
366*cdf0e10cSrcweir         }
367*cdf0e10cSrcweir 
368*cdf0e10cSrcweir     }
369*cdf0e10cSrcweir     free(pProfile);
370*cdf0e10cSrcweir 
371*cdf0e10cSrcweir #ifdef TRACE_OSL_PROFILE
372*cdf0e10cSrcweir     OSL_TRACE("Out osl_closeProfile [ok]\n");
373*cdf0e10cSrcweir #endif
374*cdf0e10cSrcweir     return (sal_True);
375*cdf0e10cSrcweir }
376*cdf0e10cSrcweir 
377*cdf0e10cSrcweir sal_Bool SAL_CALL osl_flushProfile(oslProfile Profile)
378*cdf0e10cSrcweir {
379*cdf0e10cSrcweir     osl_TProfileImpl* pProfile = (osl_TProfileImpl*) Profile;
380*cdf0e10cSrcweir     osl_TFile* pFile;
381*cdf0e10cSrcweir     sal_Bool bRet = sal_False;
382*cdf0e10cSrcweir 
383*cdf0e10cSrcweir #ifdef TRACE_OSL_PROFILE
384*cdf0e10cSrcweir     OSL_TRACE("In  osl_flushProfile()\n");
385*cdf0e10cSrcweir #endif
386*cdf0e10cSrcweir 
387*cdf0e10cSrcweir     if ( pProfile == 0 )
388*cdf0e10cSrcweir     {
389*cdf0e10cSrcweir #ifdef TRACE_OSL_PROFILE
390*cdf0e10cSrcweir         OSL_TRACE("Out osl_flushProfile() [pProfile == 0]\n");
391*cdf0e10cSrcweir #endif
392*cdf0e10cSrcweir         return sal_False;
393*cdf0e10cSrcweir     }
394*cdf0e10cSrcweir 
395*cdf0e10cSrcweir     pFile = pProfile->m_pFile;
396*cdf0e10cSrcweir     if ( !( pFile != 0 && pFile->m_Handle >= 0 ) )
397*cdf0e10cSrcweir     {
398*cdf0e10cSrcweir #ifdef TRACE_OSL_PROFILE
399*cdf0e10cSrcweir         OSL_TRACE("Out osl_flushProfile() [invalid file]\n");
400*cdf0e10cSrcweir #endif
401*cdf0e10cSrcweir         return sal_False;
402*cdf0e10cSrcweir     }
403*cdf0e10cSrcweir 
404*cdf0e10cSrcweir     if ( pProfile->m_Flags & FLG_MODIFIED )
405*cdf0e10cSrcweir     {
406*cdf0e10cSrcweir #ifdef DEBUG_OSL_PROFILE
407*cdf0e10cSrcweir         OSL_TRACE("swapping to storeprofile\n");
408*cdf0e10cSrcweir #endif
409*cdf0e10cSrcweir         bRet = storeProfile(pFile,pProfile,sal_False);
410*cdf0e10cSrcweir     }
411*cdf0e10cSrcweir 
412*cdf0e10cSrcweir #ifdef TRACE_OSL_PROFILE
413*cdf0e10cSrcweir     OSL_TRACE("Out osl_flushProfile() [ok]\n");
414*cdf0e10cSrcweir #endif
415*cdf0e10cSrcweir     return bRet;
416*cdf0e10cSrcweir }
417*cdf0e10cSrcweir 
418*cdf0e10cSrcweir sal_Bool SAL_CALL osl_readProfileString(oslProfile Profile,
419*cdf0e10cSrcweir                                         const sal_Char* pszSection, const sal_Char* pszEntry,
420*cdf0e10cSrcweir                                         sal_Char* pszString, sal_uInt32 MaxLen,
421*cdf0e10cSrcweir                                         const sal_Char* pszDefault)
422*cdf0e10cSrcweir {
423*cdf0e10cSrcweir     sal_uInt32    NoEntry;
424*cdf0e10cSrcweir     const sal_Char* pStr = 0;
425*cdf0e10cSrcweir     osl_TProfileSection* pSec;
426*cdf0e10cSrcweir     osl_TProfileImpl*    pProfile = 0;
427*cdf0e10cSrcweir 
428*cdf0e10cSrcweir 
429*cdf0e10cSrcweir #ifdef TRACE_OSL_PROFILE
430*cdf0e10cSrcweir     OSL_TRACE("In  osl_readProfileString\n");
431*cdf0e10cSrcweir #endif
432*cdf0e10cSrcweir 
433*cdf0e10cSrcweir     pProfile = acquireProfile(Profile, sal_False);
434*cdf0e10cSrcweir 
435*cdf0e10cSrcweir     if (pProfile == NULL)
436*cdf0e10cSrcweir     {
437*cdf0e10cSrcweir #ifdef TRACE_OSL_PROFILE
438*cdf0e10cSrcweir         OSL_TRACE("Out osl_readProfileString [pProfile==0]\n");
439*cdf0e10cSrcweir #endif
440*cdf0e10cSrcweir 
441*cdf0e10cSrcweir 
442*cdf0e10cSrcweir         return (sal_False);
443*cdf0e10cSrcweir     }
444*cdf0e10cSrcweir 
445*cdf0e10cSrcweir 
446*cdf0e10cSrcweir     if (! (pProfile->m_Flags & osl_Profile_SYSTEM))
447*cdf0e10cSrcweir     {
448*cdf0e10cSrcweir         if (((pSec = findEntry(pProfile, pszSection, pszEntry, &NoEntry)) != NULL) &&
449*cdf0e10cSrcweir             (NoEntry < pSec->m_NoEntries) &&
450*cdf0e10cSrcweir             ((pStr = strchr(pProfile->m_Lines[pSec->m_Entries[NoEntry].m_Line],
451*cdf0e10cSrcweir                             '=')) != NULL))
452*cdf0e10cSrcweir             pStr++;
453*cdf0e10cSrcweir         else
454*cdf0e10cSrcweir             pStr = pszDefault;
455*cdf0e10cSrcweir 
456*cdf0e10cSrcweir         if ( pStr != 0 )
457*cdf0e10cSrcweir         {
458*cdf0e10cSrcweir             pStr = stripBlanks(pStr, NULL);
459*cdf0e10cSrcweir             MaxLen = (MaxLen - 1 < strlen(pStr)) ? (MaxLen - 1) : strlen(pStr);
460*cdf0e10cSrcweir             pStr = stripBlanks(pStr, &MaxLen);
461*cdf0e10cSrcweir             strncpy(pszString, pStr, MaxLen);
462*cdf0e10cSrcweir             pszString[MaxLen] = '\0';
463*cdf0e10cSrcweir         }
464*cdf0e10cSrcweir     }
465*cdf0e10cSrcweir     else
466*cdf0e10cSrcweir         PrfQueryProfileString(pProfile->m_hIni, (PCSZ)pszSection,
467*cdf0e10cSrcweir                               (PCSZ)pszEntry, (PCSZ)pszDefault,
468*cdf0e10cSrcweir                               pszString, MaxLen);
469*cdf0e10cSrcweir 
470*cdf0e10cSrcweir     releaseProfile(pProfile);
471*cdf0e10cSrcweir 
472*cdf0e10cSrcweir     if ( pStr == 0 )
473*cdf0e10cSrcweir     {
474*cdf0e10cSrcweir #ifdef TRACE_OSL_PROFILE
475*cdf0e10cSrcweir         OSL_TRACE("Out osl_readProfileString [pStr==0]\n");
476*cdf0e10cSrcweir #endif
477*cdf0e10cSrcweir 
478*cdf0e10cSrcweir 
479*cdf0e10cSrcweir         return (sal_False);
480*cdf0e10cSrcweir     }
481*cdf0e10cSrcweir 
482*cdf0e10cSrcweir #ifdef TRACE_OSL_PROFILE
483*cdf0e10cSrcweir     OSL_TRACE("Out osl_readProfileString [ok]\n");
484*cdf0e10cSrcweir #endif
485*cdf0e10cSrcweir 
486*cdf0e10cSrcweir     return (sal_True);
487*cdf0e10cSrcweir }
488*cdf0e10cSrcweir 
489*cdf0e10cSrcweir 
490*cdf0e10cSrcweir sal_Bool SAL_CALL osl_readProfileBool(oslProfile Profile,
491*cdf0e10cSrcweir                             const sal_Char* pszSection, const sal_Char* pszEntry,
492*cdf0e10cSrcweir                             sal_Bool Default)
493*cdf0e10cSrcweir {
494*cdf0e10cSrcweir     sal_Char Line[32];
495*cdf0e10cSrcweir 
496*cdf0e10cSrcweir #ifdef TRACE_OSL_PROFILE
497*cdf0e10cSrcweir     OSL_TRACE("In  osl_readProfileBool\n");
498*cdf0e10cSrcweir #endif
499*cdf0e10cSrcweir 
500*cdf0e10cSrcweir     if (osl_readProfileString(Profile, pszSection, pszEntry, Line, sizeof(Line), ""))
501*cdf0e10cSrcweir     {
502*cdf0e10cSrcweir         if ((stricmp(Line, STR_INI_BOOLYES) == 0) ||
503*cdf0e10cSrcweir             (stricmp(Line, STR_INI_BOOLON)  == 0) ||
504*cdf0e10cSrcweir             (stricmp(Line, STR_INI_BOOLONE) == 0))
505*cdf0e10cSrcweir             Default = sal_True;
506*cdf0e10cSrcweir         else
507*cdf0e10cSrcweir             if ((stricmp(Line, STR_INI_BOOLNO)   == 0) ||
508*cdf0e10cSrcweir                 (stricmp(Line, STR_INI_BOOLOFF)  == 0) ||
509*cdf0e10cSrcweir                 (stricmp(Line, STR_INI_BOOLZERO) == 0))
510*cdf0e10cSrcweir                 Default = sal_False;
511*cdf0e10cSrcweir     }
512*cdf0e10cSrcweir 
513*cdf0e10cSrcweir #ifdef TRACE_OSL_PROFILE
514*cdf0e10cSrcweir     OSL_TRACE("Out osl_readProfileBool [ok]\n");
515*cdf0e10cSrcweir #endif
516*cdf0e10cSrcweir 
517*cdf0e10cSrcweir     return (Default);
518*cdf0e10cSrcweir }
519*cdf0e10cSrcweir 
520*cdf0e10cSrcweir 
521*cdf0e10cSrcweir sal_uInt32 SAL_CALL osl_readProfileIdent(oslProfile Profile,
522*cdf0e10cSrcweir                               const sal_Char* pszSection, const sal_Char* pszEntry,
523*cdf0e10cSrcweir                               sal_uInt32 FirstId, const sal_Char* Strings[],
524*cdf0e10cSrcweir                               sal_uInt32 Default)
525*cdf0e10cSrcweir {
526*cdf0e10cSrcweir     sal_uInt32    i;
527*cdf0e10cSrcweir     sal_Char        Line[256];
528*cdf0e10cSrcweir 
529*cdf0e10cSrcweir #ifdef TRACE_OSL_PROFILE
530*cdf0e10cSrcweir     OSL_TRACE("In  osl_readProfileIdent\n");
531*cdf0e10cSrcweir #endif
532*cdf0e10cSrcweir 
533*cdf0e10cSrcweir     if (osl_readProfileString(Profile, pszSection, pszEntry, Line, sizeof(Line), ""))
534*cdf0e10cSrcweir     {
535*cdf0e10cSrcweir         i = 0;
536*cdf0e10cSrcweir         while (Strings[i] != NULL)
537*cdf0e10cSrcweir         {
538*cdf0e10cSrcweir             if (stricmp(Line, Strings[i]) == 0)
539*cdf0e10cSrcweir             {
540*cdf0e10cSrcweir                 Default = i + FirstId;
541*cdf0e10cSrcweir                 break;
542*cdf0e10cSrcweir             }
543*cdf0e10cSrcweir             i++;
544*cdf0e10cSrcweir         }
545*cdf0e10cSrcweir     }
546*cdf0e10cSrcweir 
547*cdf0e10cSrcweir #ifdef TRACE_OSL_PROFILE
548*cdf0e10cSrcweir     OSL_TRACE("Out osl_readProfileIdent [ok]\n");
549*cdf0e10cSrcweir #endif
550*cdf0e10cSrcweir     return (Default);
551*cdf0e10cSrcweir }
552*cdf0e10cSrcweir 
553*cdf0e10cSrcweir 
554*cdf0e10cSrcweir sal_Bool SAL_CALL osl_writeProfileString(oslProfile Profile,
555*cdf0e10cSrcweir                                const sal_Char* pszSection, const sal_Char* pszEntry,
556*cdf0e10cSrcweir                                const sal_Char* pszString)
557*cdf0e10cSrcweir {
558*cdf0e10cSrcweir     sal_uInt32    i;
559*cdf0e10cSrcweir     sal_Bool bRet = sal_False;
560*cdf0e10cSrcweir     sal_uInt32    NoEntry;
561*cdf0e10cSrcweir     const sal_Char* pStr;
562*cdf0e10cSrcweir     sal_Char        Line[4096];
563*cdf0e10cSrcweir     osl_TProfileSection* pSec;
564*cdf0e10cSrcweir     osl_TProfileImpl*    pProfile = 0;
565*cdf0e10cSrcweir 
566*cdf0e10cSrcweir #ifdef TRACE_OSL_PROFILE
567*cdf0e10cSrcweir     OSL_TRACE("In  osl_writeProfileString\n");
568*cdf0e10cSrcweir #endif
569*cdf0e10cSrcweir 
570*cdf0e10cSrcweir     pProfile = acquireProfile(Profile, sal_True);
571*cdf0e10cSrcweir 
572*cdf0e10cSrcweir     if (pProfile == NULL)
573*cdf0e10cSrcweir     {
574*cdf0e10cSrcweir #ifdef TRACE_OSL_PROFILE
575*cdf0e10cSrcweir         OSL_TRACE("Out osl_writeProfileString [pProfile==0]\n");
576*cdf0e10cSrcweir #endif
577*cdf0e10cSrcweir         return (sal_False);
578*cdf0e10cSrcweir     }
579*cdf0e10cSrcweir 
580*cdf0e10cSrcweir 
581*cdf0e10cSrcweir     if (! (pProfile->m_Flags & osl_Profile_SYSTEM))
582*cdf0e10cSrcweir     {
583*cdf0e10cSrcweir         if ((pSec = findEntry(pProfile, pszSection, pszEntry, &NoEntry)) == NULL)
584*cdf0e10cSrcweir         {
585*cdf0e10cSrcweir             Line[0] = '\0';
586*cdf0e10cSrcweir             addLine(pProfile, Line);
587*cdf0e10cSrcweir 
588*cdf0e10cSrcweir             Line[0] = '[';
589*cdf0e10cSrcweir             strcpy(&Line[1], pszSection);
590*cdf0e10cSrcweir             Line[1 + strlen(pszSection)] = ']';
591*cdf0e10cSrcweir             Line[2 + strlen(pszSection)] = '\0';
592*cdf0e10cSrcweir 
593*cdf0e10cSrcweir             if (((pStr = addLine(pProfile, Line)) == NULL) ||
594*cdf0e10cSrcweir                 (! addSection(pProfile, pProfile->m_NoLines - 1, &pStr[1], strlen(pszSection))))
595*cdf0e10cSrcweir             {
596*cdf0e10cSrcweir                 releaseProfile(pProfile);
597*cdf0e10cSrcweir #ifdef TRACE_OSL_PROFILE
598*cdf0e10cSrcweir                 OSL_TRACE("Out osl_writeProfileString [not added]\n");
599*cdf0e10cSrcweir #endif
600*cdf0e10cSrcweir                 return (sal_False);
601*cdf0e10cSrcweir             }
602*cdf0e10cSrcweir 
603*cdf0e10cSrcweir             pSec = &pProfile->m_Sections[pProfile->m_NoSections - 1];
604*cdf0e10cSrcweir             NoEntry = pSec->m_NoEntries;
605*cdf0e10cSrcweir         }
606*cdf0e10cSrcweir 
607*cdf0e10cSrcweir         Line[0] = '\0';
608*cdf0e10cSrcweir         strcpy(&Line[0], pszEntry);
609*cdf0e10cSrcweir         Line[0 + strlen(pszEntry)] = '=';
610*cdf0e10cSrcweir         strcpy(&Line[1 + strlen(pszEntry)], pszString);
611*cdf0e10cSrcweir 
612*cdf0e10cSrcweir         if (NoEntry >= pSec->m_NoEntries)
613*cdf0e10cSrcweir         {
614*cdf0e10cSrcweir             if (pSec->m_NoEntries > 0)
615*cdf0e10cSrcweir                 i = pSec->m_Entries[pSec->m_NoEntries - 1].m_Line + 1;
616*cdf0e10cSrcweir             else
617*cdf0e10cSrcweir                 i = pSec->m_Line + 1;
618*cdf0e10cSrcweir 
619*cdf0e10cSrcweir             if (((pStr = insertLine(pProfile, Line, i)) == NULL) ||
620*cdf0e10cSrcweir                 (! addEntry(pProfile, pSec, i, pStr, strlen(pszEntry))))
621*cdf0e10cSrcweir             {
622*cdf0e10cSrcweir                 releaseProfile(pProfile);
623*cdf0e10cSrcweir #ifdef TRACE_OSL_PROFILE
624*cdf0e10cSrcweir                 OSL_TRACE("Out osl_writeProfileString [not inserted]\n");
625*cdf0e10cSrcweir #endif
626*cdf0e10cSrcweir                 return (sal_False);
627*cdf0e10cSrcweir             }
628*cdf0e10cSrcweir 
629*cdf0e10cSrcweir             pProfile->m_Flags |= FLG_MODIFIED;
630*cdf0e10cSrcweir         }
631*cdf0e10cSrcweir         else
632*cdf0e10cSrcweir         {
633*cdf0e10cSrcweir             i = pSec->m_Entries[NoEntry].m_Line;
634*cdf0e10cSrcweir             free(pProfile->m_Lines[i]);
635*cdf0e10cSrcweir             pProfile->m_Lines[i] = strdup(Line);
636*cdf0e10cSrcweir             setEntry(pProfile, pSec, NoEntry, i, pProfile->m_Lines[i], strlen(pszEntry));
637*cdf0e10cSrcweir 
638*cdf0e10cSrcweir             pProfile->m_Flags |= FLG_MODIFIED;
639*cdf0e10cSrcweir         }
640*cdf0e10cSrcweir     }
641*cdf0e10cSrcweir     else
642*cdf0e10cSrcweir         PrfWriteProfileString(pProfile->m_hIni, (PCSZ)pszSection,
643*cdf0e10cSrcweir                               (PCSZ)pszEntry, (PCSZ)pszString);
644*cdf0e10cSrcweir 
645*cdf0e10cSrcweir     bRet = releaseProfile(pProfile);
646*cdf0e10cSrcweir #ifdef TRACE_OSL_PROFILE
647*cdf0e10cSrcweir     OSL_TRACE("Out osl_writeProfileString [ok]\n");
648*cdf0e10cSrcweir #endif
649*cdf0e10cSrcweir     return bRet;
650*cdf0e10cSrcweir }
651*cdf0e10cSrcweir 
652*cdf0e10cSrcweir 
653*cdf0e10cSrcweir sal_Bool SAL_CALL osl_writeProfileBool(oslProfile Profile,
654*cdf0e10cSrcweir                              const sal_Char* pszSection, const sal_Char* pszEntry,
655*cdf0e10cSrcweir                              sal_Bool Value)
656*cdf0e10cSrcweir {
657*cdf0e10cSrcweir     sal_Bool bRet = sal_False;
658*cdf0e10cSrcweir 
659*cdf0e10cSrcweir #ifdef TRACE_OSL_PROFILE
660*cdf0e10cSrcweir     OSL_TRACE("In  osl_writeProfileBool\n");
661*cdf0e10cSrcweir #endif
662*cdf0e10cSrcweir 
663*cdf0e10cSrcweir     if (Value)
664*cdf0e10cSrcweir         bRet=osl_writeProfileString(Profile, pszSection, pszEntry, STR_INI_BOOLONE);
665*cdf0e10cSrcweir     else
666*cdf0e10cSrcweir         bRet=osl_writeProfileString(Profile, pszSection, pszEntry, STR_INI_BOOLZERO);
667*cdf0e10cSrcweir 
668*cdf0e10cSrcweir #ifdef TRACE_OSL_PROFILE
669*cdf0e10cSrcweir     OSL_TRACE("Out osl_writeProfileBool [ok]\n");
670*cdf0e10cSrcweir #endif
671*cdf0e10cSrcweir 
672*cdf0e10cSrcweir     return bRet;
673*cdf0e10cSrcweir }
674*cdf0e10cSrcweir 
675*cdf0e10cSrcweir 
676*cdf0e10cSrcweir sal_Bool SAL_CALL osl_writeProfileIdent(oslProfile Profile,
677*cdf0e10cSrcweir                               const sal_Char* pszSection, const sal_Char* pszEntry,
678*cdf0e10cSrcweir                               sal_uInt32 FirstId, const sal_Char* Strings[],
679*cdf0e10cSrcweir                               sal_uInt32 Value)
680*cdf0e10cSrcweir {
681*cdf0e10cSrcweir     int i, n;
682*cdf0e10cSrcweir     sal_Bool bRet = sal_False;
683*cdf0e10cSrcweir 
684*cdf0e10cSrcweir #ifdef TRACE_OSL_PROFILE
685*cdf0e10cSrcweir     OSL_TRACE("In  osl_writeProfileIdent\n");
686*cdf0e10cSrcweir #endif
687*cdf0e10cSrcweir 
688*cdf0e10cSrcweir     for (n = 0; Strings[n] != NULL; n++);
689*cdf0e10cSrcweir 
690*cdf0e10cSrcweir     if ((i = Value - FirstId) >= n)
691*cdf0e10cSrcweir         bRet=sal_False;
692*cdf0e10cSrcweir     else
693*cdf0e10cSrcweir         bRet=osl_writeProfileString(Profile, pszSection, pszEntry, Strings[i]);
694*cdf0e10cSrcweir 
695*cdf0e10cSrcweir #ifdef TRACE_OSL_PROFILE
696*cdf0e10cSrcweir     OSL_TRACE("Out osl_writeProfileIdent\n");
697*cdf0e10cSrcweir #endif
698*cdf0e10cSrcweir     return bRet;
699*cdf0e10cSrcweir }
700*cdf0e10cSrcweir 
701*cdf0e10cSrcweir 
702*cdf0e10cSrcweir sal_Bool SAL_CALL osl_removeProfileEntry(oslProfile Profile,
703*cdf0e10cSrcweir                                const sal_Char *pszSection, const sal_Char *pszEntry)
704*cdf0e10cSrcweir {
705*cdf0e10cSrcweir     sal_uInt32    NoEntry;
706*cdf0e10cSrcweir     osl_TProfileSection* pSec;
707*cdf0e10cSrcweir     osl_TProfileImpl*    pProfile = 0;
708*cdf0e10cSrcweir     sal_Bool bRet = sal_False;
709*cdf0e10cSrcweir 
710*cdf0e10cSrcweir #ifdef TRACE_OSL_PROFILE
711*cdf0e10cSrcweir     OSL_TRACE("In  osl_removeProfileEntry\n");
712*cdf0e10cSrcweir #endif
713*cdf0e10cSrcweir 
714*cdf0e10cSrcweir     pProfile = acquireProfile(Profile, sal_True);
715*cdf0e10cSrcweir 
716*cdf0e10cSrcweir     if (pProfile == NULL)
717*cdf0e10cSrcweir     {
718*cdf0e10cSrcweir #ifdef TRACE_OSL_PROFILE
719*cdf0e10cSrcweir         OSL_TRACE("Out osl_removeProfileEntry [pProfile==0]\n");
720*cdf0e10cSrcweir #endif
721*cdf0e10cSrcweir 
722*cdf0e10cSrcweir 
723*cdf0e10cSrcweir         return (sal_False);
724*cdf0e10cSrcweir     }
725*cdf0e10cSrcweir 
726*cdf0e10cSrcweir 
727*cdf0e10cSrcweir     if (! (pProfile->m_Flags & osl_Profile_SYSTEM))
728*cdf0e10cSrcweir     {
729*cdf0e10cSrcweir         if (((pSec = findEntry(pProfile, pszSection, pszEntry, &NoEntry)) != NULL) &&
730*cdf0e10cSrcweir             (NoEntry < pSec->m_NoEntries))
731*cdf0e10cSrcweir         {
732*cdf0e10cSrcweir             removeLine(pProfile, pSec->m_Entries[NoEntry].m_Line);
733*cdf0e10cSrcweir             removeEntry(pSec, NoEntry);
734*cdf0e10cSrcweir             if (pSec->m_NoEntries == 0)
735*cdf0e10cSrcweir             {
736*cdf0e10cSrcweir                 removeLine(pProfile, pSec->m_Line);
737*cdf0e10cSrcweir 
738*cdf0e10cSrcweir                 /* remove any empty separation line */
739*cdf0e10cSrcweir                 if ((pSec->m_Line > 0) && (pProfile->m_Lines[pSec->m_Line - 1][0] == '\0'))
740*cdf0e10cSrcweir                     removeLine(pProfile, pSec->m_Line - 1);
741*cdf0e10cSrcweir 
742*cdf0e10cSrcweir                 removeSection(pProfile, pSec);
743*cdf0e10cSrcweir             }
744*cdf0e10cSrcweir 
745*cdf0e10cSrcweir             pProfile->m_Flags |= FLG_MODIFIED;
746*cdf0e10cSrcweir         }
747*cdf0e10cSrcweir     }
748*cdf0e10cSrcweir     else
749*cdf0e10cSrcweir         PrfWriteProfileString(pProfile->m_hIni, (PCSZ)pszSection, (PCSZ)pszEntry, NULL);
750*cdf0e10cSrcweir 
751*cdf0e10cSrcweir     bRet = releaseProfile(pProfile);
752*cdf0e10cSrcweir #ifdef TRACE_OSL_PROFILE
753*cdf0e10cSrcweir     OSL_TRACE("Out osl_removeProfileEntry [ok]\n");
754*cdf0e10cSrcweir #endif
755*cdf0e10cSrcweir     return bRet;
756*cdf0e10cSrcweir }
757*cdf0e10cSrcweir 
758*cdf0e10cSrcweir 
759*cdf0e10cSrcweir sal_uInt32 SAL_CALL osl_getProfileSectionEntries(oslProfile Profile, const sal_Char *pszSection,
760*cdf0e10cSrcweir                                       sal_Char* pszBuffer, sal_uInt32 MaxLen)
761*cdf0e10cSrcweir {
762*cdf0e10cSrcweir     sal_uInt32    i, n = 0;
763*cdf0e10cSrcweir     sal_uInt32    NoEntry;
764*cdf0e10cSrcweir     osl_TProfileSection* pSec;
765*cdf0e10cSrcweir     osl_TProfileImpl*    pProfile = 0;
766*cdf0e10cSrcweir 
767*cdf0e10cSrcweir #ifdef TRACE_OSL_PROFILE
768*cdf0e10cSrcweir     OSL_TRACE("In  osl_getProfileSectionEntries\n");
769*cdf0e10cSrcweir #endif
770*cdf0e10cSrcweir 
771*cdf0e10cSrcweir     pProfile = acquireProfile(Profile, sal_False);
772*cdf0e10cSrcweir 
773*cdf0e10cSrcweir     if (pProfile == NULL)
774*cdf0e10cSrcweir     {
775*cdf0e10cSrcweir #ifdef TRACE_OSL_PROFILE
776*cdf0e10cSrcweir         OSL_TRACE("Out osl_getProfileSectionEntries [pProfile=0]\n");
777*cdf0e10cSrcweir #endif
778*cdf0e10cSrcweir 
779*cdf0e10cSrcweir 
780*cdf0e10cSrcweir         return (0);
781*cdf0e10cSrcweir     }
782*cdf0e10cSrcweir 
783*cdf0e10cSrcweir 
784*cdf0e10cSrcweir     if (! (pProfile->m_Flags & osl_Profile_SYSTEM))
785*cdf0e10cSrcweir     {
786*cdf0e10cSrcweir         if ((pSec = findEntry(pProfile, pszSection, "", &NoEntry)) != NULL)
787*cdf0e10cSrcweir         {
788*cdf0e10cSrcweir             if (MaxLen != 0)
789*cdf0e10cSrcweir             {
790*cdf0e10cSrcweir                 for (i = 0; i < pSec->m_NoEntries; i++)
791*cdf0e10cSrcweir                 {
792*cdf0e10cSrcweir                     if ((n + pSec->m_Entries[i].m_Len + 1) < MaxLen)
793*cdf0e10cSrcweir                     {
794*cdf0e10cSrcweir                         strncpy(&pszBuffer[n], &pProfile->m_Lines[pSec->m_Entries[i].m_Line]
795*cdf0e10cSrcweir                                 [pSec->m_Entries[i].m_Offset], pSec->m_Entries[i].m_Len);
796*cdf0e10cSrcweir                         n += pSec->m_Entries[i].m_Len;
797*cdf0e10cSrcweir                         pszBuffer[n++] = '\0';
798*cdf0e10cSrcweir                     }
799*cdf0e10cSrcweir                     else
800*cdf0e10cSrcweir                         break;
801*cdf0e10cSrcweir 
802*cdf0e10cSrcweir                 }
803*cdf0e10cSrcweir 
804*cdf0e10cSrcweir                 pszBuffer[n++] = '\0';
805*cdf0e10cSrcweir             }
806*cdf0e10cSrcweir             else
807*cdf0e10cSrcweir             {
808*cdf0e10cSrcweir                 for (i = 0; i < pSec->m_NoEntries; i++)
809*cdf0e10cSrcweir                     n += pSec->m_Entries[i].m_Len + 1;
810*cdf0e10cSrcweir 
811*cdf0e10cSrcweir                 n += 1;
812*cdf0e10cSrcweir             }
813*cdf0e10cSrcweir         }
814*cdf0e10cSrcweir         else
815*cdf0e10cSrcweir             n = 0;
816*cdf0e10cSrcweir     }
817*cdf0e10cSrcweir     else
818*cdf0e10cSrcweir         n = PrfQueryProfileString(pProfile->m_hIni, (PCSZ)pszSection, NULL, NULL,
819*cdf0e10cSrcweir                                   pszBuffer, MaxLen );
820*cdf0e10cSrcweir 
821*cdf0e10cSrcweir     releaseProfile(pProfile);
822*cdf0e10cSrcweir 
823*cdf0e10cSrcweir #ifdef TRACE_OSL_PROFILE
824*cdf0e10cSrcweir     OSL_TRACE("Out osl_getProfileSectionEntries [ok]\n");
825*cdf0e10cSrcweir #endif
826*cdf0e10cSrcweir 
827*cdf0e10cSrcweir     return (n);
828*cdf0e10cSrcweir }
829*cdf0e10cSrcweir 
830*cdf0e10cSrcweir sal_uInt32 SAL_CALL osl_getProfileSections(oslProfile Profile, sal_Char* pszBuffer, sal_uInt32 MaxLen)
831*cdf0e10cSrcweir {
832*cdf0e10cSrcweir     sal_uInt32    i, n = 0;
833*cdf0e10cSrcweir     osl_TProfileSection* pSec;
834*cdf0e10cSrcweir     osl_TProfileImpl*    pProfile = acquireProfile(Profile, sal_False);
835*cdf0e10cSrcweir 
836*cdf0e10cSrcweir     if (pProfile == NULL)
837*cdf0e10cSrcweir         return (0);
838*cdf0e10cSrcweir 
839*cdf0e10cSrcweir     if (! (pProfile->m_Flags & osl_Profile_SYSTEM))
840*cdf0e10cSrcweir     {
841*cdf0e10cSrcweir         if (MaxLen != 0)
842*cdf0e10cSrcweir         {
843*cdf0e10cSrcweir             for (i = 0; i < pProfile->m_NoSections; i++)
844*cdf0e10cSrcweir             {
845*cdf0e10cSrcweir                 pSec = &pProfile->m_Sections[i];
846*cdf0e10cSrcweir 
847*cdf0e10cSrcweir                 if ((n + pSec->m_Len + 1) < MaxLen)
848*cdf0e10cSrcweir                 {
849*cdf0e10cSrcweir                     strncpy(&pszBuffer[n], &pProfile->m_Lines[pSec->m_Line][pSec->m_Offset],
850*cdf0e10cSrcweir                             pSec->m_Len);
851*cdf0e10cSrcweir                     n += pSec->m_Len;
852*cdf0e10cSrcweir                     pszBuffer[n++] = '\0';
853*cdf0e10cSrcweir                 }
854*cdf0e10cSrcweir                 else
855*cdf0e10cSrcweir                     break;
856*cdf0e10cSrcweir             }
857*cdf0e10cSrcweir 
858*cdf0e10cSrcweir             pszBuffer[n++] = '\0';
859*cdf0e10cSrcweir         }
860*cdf0e10cSrcweir         else
861*cdf0e10cSrcweir         {
862*cdf0e10cSrcweir             for (i = 0; i < pProfile->m_NoSections; i++)
863*cdf0e10cSrcweir                 n += pProfile->m_Sections[i].m_Len + 1;
864*cdf0e10cSrcweir 
865*cdf0e10cSrcweir             n += 1;
866*cdf0e10cSrcweir         }
867*cdf0e10cSrcweir     }
868*cdf0e10cSrcweir     else
869*cdf0e10cSrcweir         n = PrfQueryProfileString(pProfile->m_hIni, NULL, NULL, NULL,
870*cdf0e10cSrcweir                                   pszBuffer, MaxLen );
871*cdf0e10cSrcweir 
872*cdf0e10cSrcweir     releaseProfile(pProfile);
873*cdf0e10cSrcweir 
874*cdf0e10cSrcweir     return (n);
875*cdf0e10cSrcweir }
876*cdf0e10cSrcweir 
877*cdf0e10cSrcweir #if 0 // YD
878*cdf0e10cSrcweir sal_Bool SAL_CALL osl_getProfileName(rtl_uString* strPath, rtl_uString* strName, rtl_uString** strProfileName)
879*cdf0e10cSrcweir {
880*cdf0e10cSrcweir     sal_Bool bFailed;
881*cdf0e10cSrcweir     sal_Char File[_MAX_PATH];
882*cdf0e10cSrcweir     sal_Char Path[_MAX_PATH];
883*cdf0e10cSrcweir     sal_uInt32  nFileLen;
884*cdf0e10cSrcweir     sal_uInt32  nPathLen = 0;
885*cdf0e10cSrcweir 
886*cdf0e10cSrcweir     rtl_uString * strTmp = NULL;
887*cdf0e10cSrcweir     oslFileError nError;
888*cdf0e10cSrcweir 
889*cdf0e10cSrcweir     /* build file name */
890*cdf0e10cSrcweir     if (strName && strName->length)
891*cdf0e10cSrcweir     {
892*cdf0e10cSrcweir         if(strName->length >= _MAX_PATH)
893*cdf0e10cSrcweir             return sal_False;
894*cdf0e10cSrcweir 
895*cdf0e10cSrcweir         strcpy(File, (char*)strName->buffer);
896*cdf0e10cSrcweir         nFileLen = strName->length;
897*cdf0e10cSrcweir 
898*cdf0e10cSrcweir         if (rtl_ustr_indexOfChar( File, L'.' ) == -1)
899*cdf0e10cSrcweir         {
900*cdf0e10cSrcweir             if (nFileLen + strlen(STR_INI_EXTENSION) >= _MAX_PATH)
901*cdf0e10cSrcweir                 return sal_False;
902*cdf0e10cSrcweir 
903*cdf0e10cSrcweir             /* add default extension */
904*cdf0e10cSrcweir             strcpy(File + nFileLen, STR_INI_EXTENSION);
905*cdf0e10cSrcweir             nFileLen += strlen(STR_INI_EXTENSION);
906*cdf0e10cSrcweir         }
907*cdf0e10cSrcweir     }
908*cdf0e10cSrcweir     else
909*cdf0e10cSrcweir     {
910*cdf0e10cSrcweir         rtl_uString *strProgName = NULL;
911*cdf0e10cSrcweir         sal_Unicode *pProgName;
912*cdf0e10cSrcweir         sal_Int32 nOffset = 0;
913*cdf0e10cSrcweir         sal_Int32 nLen;
914*cdf0e10cSrcweir         sal_Int32 nPos;
915*cdf0e10cSrcweir 
916*cdf0e10cSrcweir         if (osl_getExecutableFile(&strProgName) != osl_Process_E_None)
917*cdf0e10cSrcweir             return sal_False;
918*cdf0e10cSrcweir 
919*cdf0e10cSrcweir         /* remove path and extension from filename */
920*cdf0e10cSrcweir         pProgName = strProgName->buffer;
921*cdf0e10cSrcweir         nLen = strProgName->length ;
922*cdf0e10cSrcweir 
923*cdf0e10cSrcweir         if ((nPos = rtl_ustr_lastIndexOfChar( pProgName, L'/' )) != -1)
924*cdf0e10cSrcweir             nOffset = nPos + 1;
925*cdf0e10cSrcweir         else if ((nPos = rtl_ustr_lastIndexOfChar( pProgName, L':' )) != -1)
926*cdf0e10cSrcweir             nOffset = nPos + 1;
927*cdf0e10cSrcweir 
928*cdf0e10cSrcweir         if ((nPos = rtl_ustr_lastIndexOfChar( pProgName, L'.' )) != -1 )
929*cdf0e10cSrcweir             nLen -= 4;
930*cdf0e10cSrcweir 
931*cdf0e10cSrcweir         if ((nFileLen = nLen - nOffset) >= _MAX_PATH)
932*cdf0e10cSrcweir             return sal_False;
933*cdf0e10cSrcweir 
934*cdf0e10cSrcweir         strncpy(File, pProgName + nOffset, nFileLen);
935*cdf0e10cSrcweir 
936*cdf0e10cSrcweir         if (nFileLen + strlen(STR_INI_EXTENSION) >= _MAX_PATH)
937*cdf0e10cSrcweir             return sal_False;
938*cdf0e10cSrcweir 
939*cdf0e10cSrcweir         /* add default extension */
940*cdf0e10cSrcweir         strcpy(File + nFileLen, STR_INI_EXTENSION);
941*cdf0e10cSrcweir         nFileLen += strlen(STR_INI_EXTENSION);
942*cdf0e10cSrcweir 
943*cdf0e10cSrcweir         rtl_uString_release( strProgName );
944*cdf0e10cSrcweir     }
945*cdf0e10cSrcweir 
946*cdf0e10cSrcweir     if (File[0] == 0)
947*cdf0e10cSrcweir         return sal_False;
948*cdf0e10cSrcweir 
949*cdf0e10cSrcweir     /* build directory path */
950*cdf0e10cSrcweir     if (strPath && strPath->length)
951*cdf0e10cSrcweir     {
952*cdf0e10cSrcweir         sal_Unicode *pPath = rtl_uString_getStr(strPath);
953*cdf0e10cSrcweir         sal_Int32 nLen = rtl_uString_getLength(strPath);
954*cdf0e10cSrcweir 
955*cdf0e10cSrcweir         if ((rtl_ustr_ascii_compare_WithLength(pPath, RTL_CONSTASCII_LENGTH(STR_INI_METAHOME) , STR_INI_METAHOME) == 0) &&
956*cdf0e10cSrcweir             ((nLen == RTL_CONSTASCII_LENGTH(STR_INI_METAHOME)) || (pPath[RTL_CONSTASCII_LENGTH(STR_INI_METAHOME)] == '/')))
957*cdf0e10cSrcweir         {
958*cdf0e10cSrcweir             rtl_uString * strHome = NULL;
959*cdf0e10cSrcweir             oslSecurity security = osl_getCurrentSecurity();
960*cdf0e10cSrcweir 
961*cdf0e10cSrcweir             bFailed = ! osl_getHomeDir(security, &strHome);
962*cdf0e10cSrcweir             osl_freeSecurityHandle(security);
963*cdf0e10cSrcweir 
964*cdf0e10cSrcweir             if (bFailed) return (sal_False);
965*cdf0e10cSrcweir 
966*cdf0e10cSrcweir             if (strHome->length >= _MAX_PATH)
967*cdf0e10cSrcweir                 return sal_False;
968*cdf0e10cSrcweir 
969*cdf0e10cSrcweir             strcpy( Path, strHome->buffer);
970*cdf0e10cSrcweir             nPathLen = strHome->length;
971*cdf0e10cSrcweir 
972*cdf0e10cSrcweir             if (nLen > RTL_CONSTASCII_LENGTH(STR_INI_METAHOME))
973*cdf0e10cSrcweir             {
974*cdf0e10cSrcweir                 pPath += RTL_CONSTASCII_LENGTH(STR_INI_METAHOME);
975*cdf0e10cSrcweir                 nLen -= RTL_CONSTASCII_LENGTH(STR_INI_METAHOME);
976*cdf0e10cSrcweir 
977*cdf0e10cSrcweir                 if (nLen + nPathLen >= _MAX_PATH)
978*cdf0e10cSrcweir                     return sal_False;
979*cdf0e10cSrcweir 
980*cdf0e10cSrcweir                 strcpy(Path + nPathLen, pPath);
981*cdf0e10cSrcweir                 nPathLen += nLen;
982*cdf0e10cSrcweir             }
983*cdf0e10cSrcweir 
984*cdf0e10cSrcweir             rtl_uString_release(strHome);
985*cdf0e10cSrcweir         }
986*cdf0e10cSrcweir 
987*cdf0e10cSrcweir         else if ((rtl_ustr_ascii_compare_WithLength(pPath, RTL_CONSTASCII_LENGTH(STR_INI_METACFG), STR_INI_METACFG) == 0) &&
988*cdf0e10cSrcweir             ((nLen == RTL_CONSTASCII_LENGTH(STR_INI_METACFG)) || (pPath[RTL_CONSTASCII_LENGTH(STR_INI_METACFG)] == '/')))
989*cdf0e10cSrcweir         {
990*cdf0e10cSrcweir             rtl_uString * strConfig = NULL;
991*cdf0e10cSrcweir             oslSecurity security = osl_getCurrentSecurity();
992*cdf0e10cSrcweir 
993*cdf0e10cSrcweir             bFailed = ! osl_getConfigDir(security, &strConfig);
994*cdf0e10cSrcweir             osl_freeSecurityHandle(security);
995*cdf0e10cSrcweir 
996*cdf0e10cSrcweir             if (bFailed) return (sal_False);
997*cdf0e10cSrcweir 
998*cdf0e10cSrcweir             if (strConfig->length >= _MAX_PATH)
999*cdf0e10cSrcweir                 return sal_False;
1000*cdf0e10cSrcweir 
1001*cdf0e10cSrcweir             strcpy( Path, strConfig->buffer);
1002*cdf0e10cSrcweir             nPathLen = strConfig->length;
1003*cdf0e10cSrcweir 
1004*cdf0e10cSrcweir             if (nLen > RTL_CONSTASCII_LENGTH(STR_INI_METACFG))
1005*cdf0e10cSrcweir             {
1006*cdf0e10cSrcweir                 pPath += RTL_CONSTASCII_LENGTH(STR_INI_METACFG);
1007*cdf0e10cSrcweir                 nLen -= RTL_CONSTASCII_LENGTH(STR_INI_METACFG);
1008*cdf0e10cSrcweir 
1009*cdf0e10cSrcweir                 if (nLen + nPathLen >= _MAX_PATH)
1010*cdf0e10cSrcweir                     return sal_False;
1011*cdf0e10cSrcweir 
1012*cdf0e10cSrcweir                 strcpy(Path + nPathLen, pPath);
1013*cdf0e10cSrcweir                 nPathLen += nLen;
1014*cdf0e10cSrcweir             }
1015*cdf0e10cSrcweir 
1016*cdf0e10cSrcweir             rtl_uString_release(strConfig);
1017*cdf0e10cSrcweir         }
1018*cdf0e10cSrcweir 
1019*cdf0e10cSrcweir         else if ((rtl_ustr_ascii_compare_WithLength(pPath, RTL_CONSTASCII_LENGTH(STR_INI_METASYS), STR_INI_METASYS) == 0) &&
1020*cdf0e10cSrcweir             ((nLen == RTL_CONSTASCII_LENGTH(STR_INI_METASYS)) || (pPath[RTL_CONSTASCII_LENGTH(STR_INI_METASYS)] == '/')))
1021*cdf0e10cSrcweir         {
1022*cdf0e10cSrcweir             if (((nPathLen = GetWindowsDirectoryW(Path, _MAX_PATH)) == 0) || (nPathLen >= _MAX_PATH))
1023*cdf0e10cSrcweir                 return (sal_False);
1024*cdf0e10cSrcweir 
1025*cdf0e10cSrcweir             if (nLen > RTL_CONSTASCII_LENGTH(STR_INI_METASYS))
1026*cdf0e10cSrcweir             {
1027*cdf0e10cSrcweir                 pPath += RTL_CONSTASCII_LENGTH(STR_INI_METASYS);
1028*cdf0e10cSrcweir                 nLen -= RTL_CONSTASCII_LENGTH(STR_INI_METASYS);
1029*cdf0e10cSrcweir 
1030*cdf0e10cSrcweir                 if (nLen + nPathLen >= MAX_PATH)
1031*cdf0e10cSrcweir                     return sal_False;
1032*cdf0e10cSrcweir 
1033*cdf0e10cSrcweir                 strcpy(Path + nPathLen, pPath);
1034*cdf0e10cSrcweir                 nPathLen += nLen;
1035*cdf0e10cSrcweir             }
1036*cdf0e10cSrcweir         }
1037*cdf0e10cSrcweir 
1038*cdf0e10cSrcweir         else if ((rtl_ustr_ascii_compare_WithLength(pPath, RTL_CONSTASCII_LENGTH(STR_INI_METAINS), STR_INI_METAINS) == 0) &&
1039*cdf0e10cSrcweir             ((nLen == RTL_CONSTASCII_LENGTH(STR_INI_METAINS)) || (pPath[RTL_CONSTASCII_LENGTH(STR_INI_METAINS)] == '/') ||
1040*cdf0e10cSrcweir                 (pPath[RTL_CONSTASCII_LENGTH(STR_INI_METAINS)] == '"') ) )
1041*cdf0e10cSrcweir         {
1042*cdf0e10cSrcweir             if (! lookupProfile(pPath + RTL_CONSTASCII_LENGTH(STR_INI_METAINS), File, Path))
1043*cdf0e10cSrcweir                 return (sal_False);
1044*cdf0e10cSrcweir 
1045*cdf0e10cSrcweir             nPathLen = strlen(Path);
1046*cdf0e10cSrcweir         }
1047*cdf0e10cSrcweir 
1048*cdf0e10cSrcweir         else if(nLen < MAX_PATH)
1049*cdf0e10cSrcweir         {
1050*cdf0e10cSrcweir             strcpy(Path, pPath);
1051*cdf0e10cSrcweir             nPathLen = strlen(Path);
1052*cdf0e10cSrcweir         }
1053*cdf0e10cSrcweir         else
1054*cdf0e10cSrcweir             return sal_False;
1055*cdf0e10cSrcweir     }
1056*cdf0e10cSrcweir     else
1057*cdf0e10cSrcweir     {
1058*cdf0e10cSrcweir         rtl_uString * strConfigDir = NULL;
1059*cdf0e10cSrcweir         oslSecurity security = osl_getCurrentSecurity();
1060*cdf0e10cSrcweir 
1061*cdf0e10cSrcweir         bFailed = ! osl_getConfigDir(security, &strConfigDir);
1062*cdf0e10cSrcweir         osl_freeSecurityHandle(security);
1063*cdf0e10cSrcweir 
1064*cdf0e10cSrcweir         if (bFailed) return (sal_False);
1065*cdf0e10cSrcweir         if (strConfigDir->length >= MAX_PATH)
1066*cdf0e10cSrcweir             return sal_False;
1067*cdf0e10cSrcweir 
1068*cdf0e10cSrcweir         strcpy(Path, strConfigDir->buffer);
1069*cdf0e10cSrcweir         nPathLen = strConfigDir->length;
1070*cdf0e10cSrcweir     }
1071*cdf0e10cSrcweir 
1072*cdf0e10cSrcweir     if (nPathLen && (Path[nPathLen - 1] != L'/') && (Path[nPathLen - 1] != L'\\'))
1073*cdf0e10cSrcweir     {
1074*cdf0e10cSrcweir         Path[nPathLen++] = L'\\';
1075*cdf0e10cSrcweir         Path[nPathLen] = 0;
1076*cdf0e10cSrcweir     }
1077*cdf0e10cSrcweir 
1078*cdf0e10cSrcweir     if (nPathLen + nFileLen >= MAX_PATH)
1079*cdf0e10cSrcweir         return sal_False;
1080*cdf0e10cSrcweir 
1081*cdf0e10cSrcweir     /* append file name */
1082*cdf0e10cSrcweir     strcpy(Path + nPathLen, File);
1083*cdf0e10cSrcweir     nPathLen += nFileLen;
1084*cdf0e10cSrcweir 
1085*cdf0e10cSrcweir     /* copy filename */
1086*cdf0e10cSrcweir     rtl_uString_newFromStr_WithLength(&strTmp, Path, nPathLen);
1087*cdf0e10cSrcweir     nError = osl_getFileURLFromSystemPath(strTmp, strProfileName);
1088*cdf0e10cSrcweir     rtl_uString_release(strTmp);
1089*cdf0e10cSrcweir 
1090*cdf0e10cSrcweir     return nError == osl_File_E_None;
1091*cdf0e10cSrcweir }
1092*cdf0e10cSrcweir #endif // 0 // YD
1093*cdf0e10cSrcweir 
1094*cdf0e10cSrcweir 
1095*cdf0e10cSrcweir /*****************************************************************************/
1096*cdf0e10cSrcweir /* Static Module Functions */
1097*cdf0e10cSrcweir /*****************************************************************************/
1098*cdf0e10cSrcweir 
1099*cdf0e10cSrcweir static osl_TStamp getFileStamp(osl_TFile* pFile)
1100*cdf0e10cSrcweir {
1101*cdf0e10cSrcweir     osl_TStamp  FileTime;
1102*cdf0e10cSrcweir     FILESTATUS3 FileStatus;
1103*cdf0e10cSrcweir     sal_uInt32  Bytes;
1104*cdf0e10cSrcweir 
1105*cdf0e10cSrcweir     Bytes = sizeof( FILESTATUS3 );
1106*cdf0e10cSrcweir     if ( (!pFile->m_Handle) ||
1107*cdf0e10cSrcweir         DosQueryFileInfo(pFile->m_Handle, FIL_STANDARD, &FileStatus, Bytes))
1108*cdf0e10cSrcweir         memset(&FileTime, 0, sizeof(FileTime));
1109*cdf0e10cSrcweir     else
1110*cdf0e10cSrcweir     {
1111*cdf0e10cSrcweir         FileTime.m_Date = FileStatus.fdateLastWrite;
1112*cdf0e10cSrcweir         FileTime.m_Time = FileStatus.ftimeLastWrite;
1113*cdf0e10cSrcweir     }
1114*cdf0e10cSrcweir 
1115*cdf0e10cSrcweir     return (FileTime);
1116*cdf0e10cSrcweir }
1117*cdf0e10cSrcweir 
1118*cdf0e10cSrcweir static sal_Bool lockFile(const osl_TFile* pFile, osl_TLockMode eMode)
1119*cdf0e10cSrcweir {
1120*cdf0e10cSrcweir     sal_uInt32  status = 1;
1121*cdf0e10cSrcweir     FILELOCK    Lock;
1122*cdf0e10cSrcweir 
1123*cdf0e10cSrcweir     if (!pFile->m_Handle)
1124*cdf0e10cSrcweir         return (sal_False);
1125*cdf0e10cSrcweir 
1126*cdf0e10cSrcweir     Lock.lOffset = 0;
1127*cdf0e10cSrcweir     Lock.lRange  = 0xFFFFFFFF;
1128*cdf0e10cSrcweir 
1129*cdf0e10cSrcweir     switch (eMode)
1130*cdf0e10cSrcweir     {
1131*cdf0e10cSrcweir         case un_lock:
1132*cdf0e10cSrcweir             status = DosSetFileLocks(pFile->m_Handle, &Lock, NULL, 1000, 0);
1133*cdf0e10cSrcweir             break;
1134*cdf0e10cSrcweir 
1135*cdf0e10cSrcweir         case read_lock:
1136*cdf0e10cSrcweir             status = DosSetFileLocks(pFile->m_Handle, NULL, &Lock, 1000, 1);
1137*cdf0e10cSrcweir             break;
1138*cdf0e10cSrcweir 
1139*cdf0e10cSrcweir         case write_lock:
1140*cdf0e10cSrcweir             status = DosSetFileLocks(pFile->m_Handle, NULL, &Lock, 1000, 0);
1141*cdf0e10cSrcweir             break;
1142*cdf0e10cSrcweir     }
1143*cdf0e10cSrcweir 
1144*cdf0e10cSrcweir     return (status == 0);
1145*cdf0e10cSrcweir }
1146*cdf0e10cSrcweir 
1147*cdf0e10cSrcweir //static osl_TFile* openFile(rtl_uString* pszFilename, sal_Bool bWriteable)
1148*cdf0e10cSrcweir static osl_TFile* openFileImpl(rtl_uString *ustrFileName, oslProfileOption ProfileFlags )
1149*cdf0e10cSrcweir {
1150*cdf0e10cSrcweir     sal_uInt32  action;
1151*cdf0e10cSrcweir     APIRET      rc;
1152*cdf0e10cSrcweir     osl_TFile*  pFile = (osl_TFile*)calloc(1, sizeof(osl_TFile));
1153*cdf0e10cSrcweir 
1154*cdf0e10cSrcweir         ULONG attributes;
1155*cdf0e10cSrcweir         ULONG flags;
1156*cdf0e10cSrcweir         ULONG mode;
1157*cdf0e10cSrcweir     sal_Bool bWriteable = sal_False;
1158*cdf0e10cSrcweir     rtl_String* strFileName=0;
1159*cdf0e10cSrcweir     sal_Char* pszFileName=0;
1160*cdf0e10cSrcweir 
1161*cdf0e10cSrcweir     /* check parameters */
1162*cdf0e10cSrcweir     OSL_ASSERT( ustrFileName );
1163*cdf0e10cSrcweir 
1164*cdf0e10cSrcweir     rtl_uString2String( &strFileName,
1165*cdf0e10cSrcweir                             rtl_uString_getStr(ustrFileName),
1166*cdf0e10cSrcweir                             rtl_uString_getLength(ustrFileName),
1167*cdf0e10cSrcweir                             osl_getThreadTextEncoding(),
1168*cdf0e10cSrcweir                             OUSTRING_TO_OSTRING_CVTFLAGS );
1169*cdf0e10cSrcweir     pszFileName = rtl_string_getStr(strFileName);
1170*cdf0e10cSrcweir 
1171*cdf0e10cSrcweir /*    if ( ProfileFlags & ( osl_Profile_WRITELOCK | osl_Profile_FLUSHWRITE | osl_Profile_READWRITE ) )*/
1172*cdf0e10cSrcweir     if ( ProfileFlags & ( osl_Profile_WRITELOCK | osl_Profile_FLUSHWRITE ) )
1173*cdf0e10cSrcweir     {
1174*cdf0e10cSrcweir #ifdef DEBUG_OSL_PROFILE
1175*cdf0e10cSrcweir         OSL_TRACE("setting bWriteable to TRUE\n");
1176*cdf0e10cSrcweir #endif
1177*cdf0e10cSrcweir         bWriteable=sal_True;
1178*cdf0e10cSrcweir     }
1179*cdf0e10cSrcweir 
1180*cdf0e10cSrcweir         if (bWriteable)
1181*cdf0e10cSrcweir         {
1182*cdf0e10cSrcweir             flags = FILE_NORMAL | FILE_ARCHIVED;
1183*cdf0e10cSrcweir             attributes = OPEN_ACTION_CREATE_IF_NEW | OPEN_ACTION_OPEN_IF_EXISTS;
1184*cdf0e10cSrcweir             mode = OPEN_SHARE_DENYNONE | OPEN_ACCESS_READWRITE;
1185*cdf0e10cSrcweir         }
1186*cdf0e10cSrcweir         else
1187*cdf0e10cSrcweir         {
1188*cdf0e10cSrcweir             flags = FILE_NORMAL;
1189*cdf0e10cSrcweir             attributes = OPEN_ACTION_FAIL_IF_NEW | OPEN_ACTION_OPEN_IF_EXISTS;
1190*cdf0e10cSrcweir             mode = OPEN_SHARE_DENYNONE | OPEN_ACCESS_READONLY;
1191*cdf0e10cSrcweir         }
1192*cdf0e10cSrcweir 
1193*cdf0e10cSrcweir         if (rc = DosOpen((PCSZ)pszFileName, &pFile->m_Handle, &action, 0, flags, attributes, mode, NULL))
1194*cdf0e10cSrcweir         {
1195*cdf0e10cSrcweir             if (rc == ERROR_TOO_MANY_OPEN_FILES)
1196*cdf0e10cSrcweir             {
1197*cdf0e10cSrcweir                 LONG fhToAdd = 10;
1198*cdf0e10cSrcweir                 ULONG fhOld = 0;
1199*cdf0e10cSrcweir                 rc = DosSetRelMaxFH(&fhToAdd, &fhOld);
1200*cdf0e10cSrcweir                 rc = DosOpen((PCSZ)pszFileName, &pFile->m_Handle, &action, 0, flags, attributes, mode, NULL);
1201*cdf0e10cSrcweir             }
1202*cdf0e10cSrcweir         }
1203*cdf0e10cSrcweir 
1204*cdf0e10cSrcweir         if ( (rc != NO_ERROR) && bWriteable)
1205*cdf0e10cSrcweir         {
1206*cdf0e10cSrcweir             free(pFile);
1207*cdf0e10cSrcweir             rtl_string_release(strFileName);
1208*cdf0e10cSrcweir             return (NULL);
1209*cdf0e10cSrcweir         }
1210*cdf0e10cSrcweir 
1211*cdf0e10cSrcweir     rtl_string_release(strFileName);
1212*cdf0e10cSrcweir 
1213*cdf0e10cSrcweir     pFile->m_pWriteBuf=0;
1214*cdf0e10cSrcweir     pFile->m_nWriteBufFree=0;
1215*cdf0e10cSrcweir     pFile->m_nWriteBufLen=0;
1216*cdf0e10cSrcweir 
1217*cdf0e10cSrcweir     if ( ProfileFlags & (osl_Profile_WRITELOCK | osl_Profile_READLOCK ) )
1218*cdf0e10cSrcweir     {
1219*cdf0e10cSrcweir #ifdef DEBUG_OSL_PROFILE
1220*cdf0e10cSrcweir         OSL_TRACE("locking '%s' file\n",pszFilename);
1221*cdf0e10cSrcweir #endif
1222*cdf0e10cSrcweir 
1223*cdf0e10cSrcweir         lockFile(pFile, bWriteable ? write_lock : read_lock);
1224*cdf0e10cSrcweir     }
1225*cdf0e10cSrcweir 
1226*cdf0e10cSrcweir     /* mfe: new WriteBuf obsolete */
1227*cdf0e10cSrcweir /*  pFile->m_pWritePtr = pFile->m_Buf;*/
1228*cdf0e10cSrcweir /*  pFile->m_pReadPtr  = pFile->m_ReadBuf + sizeof(pFile->m_ReadBuf);*/
1229*cdf0e10cSrcweir 
1230*cdf0e10cSrcweir     return (pFile);
1231*cdf0e10cSrcweir }
1232*cdf0e10cSrcweir 
1233*cdf0e10cSrcweir //static osl_TStamp closeFile(osl_TFile* pFile)
1234*cdf0e10cSrcweir static osl_TStamp closeFileImpl(osl_TFile* pFile)
1235*cdf0e10cSrcweir {
1236*cdf0e10cSrcweir     osl_TStamp stamp = {0, 0};
1237*cdf0e10cSrcweir 
1238*cdf0e10cSrcweir     if ( pFile == 0 )
1239*cdf0e10cSrcweir     {
1240*cdf0e10cSrcweir         return stamp;
1241*cdf0e10cSrcweir     }
1242*cdf0e10cSrcweir 
1243*cdf0e10cSrcweir     if (pFile->m_Handle)
1244*cdf0e10cSrcweir     {
1245*cdf0e10cSrcweir         /* mfe: new WriteBuf obsolete */
1246*cdf0e10cSrcweir         /* we just closing the file here, DO NOT write, it has to be handled in higher levels */
1247*cdf0e10cSrcweir         //if (pFile->m_pWritePtr > pFile->m_WriteBuf)
1248*cdf0e10cSrcweir         //{
1249*cdf0e10cSrcweir         //  sal_uInt32 Bytes;
1250*cdf0e10cSrcweir 
1251*cdf0e10cSrcweir         //  DosWrite(pFile->m_Handle, pFile->m_WriteBuf,
1252*cdf0e10cSrcweir         //           pFile->m_pWritePtr - pFile->m_WriteBuf,
1253*cdf0e10cSrcweir         //           &Bytes);
1254*cdf0e10cSrcweir         //}
1255*cdf0e10cSrcweir 
1256*cdf0e10cSrcweir         stamp = getFileStamp(pFile);
1257*cdf0e10cSrcweir 
1258*cdf0e10cSrcweir         lockFile(pFile, un_lock);
1259*cdf0e10cSrcweir 
1260*cdf0e10cSrcweir         DosClose(pFile->m_Handle);
1261*cdf0e10cSrcweir     }
1262*cdf0e10cSrcweir 
1263*cdf0e10cSrcweir     if ( pFile->m_pWriteBuf != 0 )
1264*cdf0e10cSrcweir     {
1265*cdf0e10cSrcweir         free(pFile->m_pWriteBuf);
1266*cdf0e10cSrcweir     }
1267*cdf0e10cSrcweir 
1268*cdf0e10cSrcweir     free(pFile);
1269*cdf0e10cSrcweir 
1270*cdf0e10cSrcweir     return(stamp);
1271*cdf0e10cSrcweir }
1272*cdf0e10cSrcweir 
1273*cdf0e10cSrcweir static sal_Bool rewindFile(osl_TFile* pFile, sal_Bool bTruncate)
1274*cdf0e10cSrcweir {
1275*cdf0e10cSrcweir     if (pFile->m_Handle)
1276*cdf0e10cSrcweir     {
1277*cdf0e10cSrcweir         sal_uInt32 Position;
1278*cdf0e10cSrcweir 
1279*cdf0e10cSrcweir         /* mfe: new WriteBuf obsolete */
1280*cdf0e10cSrcweir         /* we just closing the file here, DO NOT write, it has to be handled in higher levels */
1281*cdf0e10cSrcweir         /* if (pFile->m_pWritePtr > pFile->m_WriteBuf)
1282*cdf0e10cSrcweir         {
1283*cdf0e10cSrcweir             sal_uInt32 Bytes;
1284*cdf0e10cSrcweir 
1285*cdf0e10cSrcweir             DosWrite(pFile->m_Handle, pFile->m_WriteBuf,
1286*cdf0e10cSrcweir                      pFile->m_pWritePtr - pFile->m_WriteBuf,
1287*cdf0e10cSrcweir                      &Bytes);
1288*cdf0e10cSrcweir 
1289*cdf0e10cSrcweir             pFile->m_pWritePtr = pFile->m_WriteBuf;
1290*cdf0e10cSrcweir         } */
1291*cdf0e10cSrcweir 
1292*cdf0e10cSrcweir         pFile->m_pReadPtr = pFile->m_ReadBuf + sizeof(pFile->m_ReadBuf);
1293*cdf0e10cSrcweir 
1294*cdf0e10cSrcweir         DosSetFilePtr(pFile->m_Handle, 0, FILE_BEGIN, &Position);
1295*cdf0e10cSrcweir 
1296*cdf0e10cSrcweir         if (bTruncate)
1297*cdf0e10cSrcweir             DosSetFileSize(pFile->m_Handle, 0);
1298*cdf0e10cSrcweir     }
1299*cdf0e10cSrcweir 
1300*cdf0e10cSrcweir     return (sal_True);
1301*cdf0e10cSrcweir }
1302*cdf0e10cSrcweir 
1303*cdf0e10cSrcweir static sal_Bool getLine(osl_TFile* pFile, const sal_Char *pszLine, int MaxLen)
1304*cdf0e10cSrcweir {
1305*cdf0e10cSrcweir     int   Free, Bytes;
1306*cdf0e10cSrcweir     sal_Char* pChr;
1307*cdf0e10cSrcweir     sal_Char* pLine = (sal_Char *)pszLine;
1308*cdf0e10cSrcweir     sal_uInt32  Max;
1309*cdf0e10cSrcweir 
1310*cdf0e10cSrcweir     if (pFile->m_Handle == 0)
1311*cdf0e10cSrcweir         return (sal_False);
1312*cdf0e10cSrcweir 
1313*cdf0e10cSrcweir     MaxLen -= 1;
1314*cdf0e10cSrcweir 
1315*cdf0e10cSrcweir     do
1316*cdf0e10cSrcweir     {
1317*cdf0e10cSrcweir         Bytes = sizeof(pFile->m_ReadBuf) - (pFile->m_pReadPtr - pFile->m_ReadBuf);
1318*cdf0e10cSrcweir 
1319*cdf0e10cSrcweir         if (Bytes <= 1)
1320*cdf0e10cSrcweir         {
1321*cdf0e10cSrcweir             /* refill buffer */
1322*cdf0e10cSrcweir             memcpy(pFile->m_ReadBuf, pFile->m_pReadPtr, Bytes);
1323*cdf0e10cSrcweir             pFile->m_pReadPtr = pFile->m_ReadBuf;
1324*cdf0e10cSrcweir 
1325*cdf0e10cSrcweir             Free = sizeof(pFile->m_ReadBuf) - Bytes;
1326*cdf0e10cSrcweir 
1327*cdf0e10cSrcweir             if (DosRead(pFile->m_Handle, &pFile->m_ReadBuf[Bytes], Free, &Max))
1328*cdf0e10cSrcweir             {
1329*cdf0e10cSrcweir                 *pLine = '\0';
1330*cdf0e10cSrcweir                 return (sal_False);
1331*cdf0e10cSrcweir             }
1332*cdf0e10cSrcweir 
1333*cdf0e10cSrcweir             if (Max < Free)
1334*cdf0e10cSrcweir             {
1335*cdf0e10cSrcweir                 if ((Max == 0) && (pLine == pszLine))
1336*cdf0e10cSrcweir                 {
1337*cdf0e10cSrcweir                     *pLine = '\0';
1338*cdf0e10cSrcweir                     return (sal_False);
1339*cdf0e10cSrcweir                 }
1340*cdf0e10cSrcweir 
1341*cdf0e10cSrcweir                 pFile->m_ReadBuf[Bytes + Max] = '\0';
1342*cdf0e10cSrcweir             }
1343*cdf0e10cSrcweir         }
1344*cdf0e10cSrcweir 
1345*cdf0e10cSrcweir         for (pChr = pFile->m_pReadPtr;
1346*cdf0e10cSrcweir              (*pChr != '\n') && (*pChr != '\r') && (*pChr != '\0') &&
1347*cdf0e10cSrcweir              (pChr < (pFile->m_ReadBuf + sizeof(pFile->m_ReadBuf) - 1));
1348*cdf0e10cSrcweir              pChr++);
1349*cdf0e10cSrcweir 
1350*cdf0e10cSrcweir         Max = min(pChr - pFile->m_pReadPtr, MaxLen);
1351*cdf0e10cSrcweir         memcpy(pLine, pFile->m_pReadPtr, Max);
1352*cdf0e10cSrcweir         MaxLen -= Max;
1353*cdf0e10cSrcweir         pLine  += Max;
1354*cdf0e10cSrcweir 
1355*cdf0e10cSrcweir         if (pChr < (pFile->m_ReadBuf + sizeof(pFile->m_ReadBuf) - 1))
1356*cdf0e10cSrcweir         {
1357*cdf0e10cSrcweir             if (*pChr != '\0')
1358*cdf0e10cSrcweir             {
1359*cdf0e10cSrcweir                 if ((pChr[0] == '\r') && (pChr[1] == '\n'))
1360*cdf0e10cSrcweir                     pChr += 2;
1361*cdf0e10cSrcweir                 else
1362*cdf0e10cSrcweir                     pChr += 1;
1363*cdf0e10cSrcweir             }
1364*cdf0e10cSrcweir 
1365*cdf0e10cSrcweir             if ((pChr < (pFile->m_ReadBuf + sizeof(pFile->m_ReadBuf))) &&
1366*cdf0e10cSrcweir                 (*pChr == '\0'))
1367*cdf0e10cSrcweir                 pChr = pFile->m_ReadBuf + sizeof(pFile->m_ReadBuf);
1368*cdf0e10cSrcweir 
1369*cdf0e10cSrcweir             *pLine = '\0';
1370*cdf0e10cSrcweir 
1371*cdf0e10cSrcweir             /* setting MaxLen to -1 indicates terminating read loop */
1372*cdf0e10cSrcweir             MaxLen = -1;
1373*cdf0e10cSrcweir         }
1374*cdf0e10cSrcweir 
1375*cdf0e10cSrcweir         pFile->m_pReadPtr = pChr;
1376*cdf0e10cSrcweir     }
1377*cdf0e10cSrcweir     while (MaxLen > 0);
1378*cdf0e10cSrcweir 
1379*cdf0e10cSrcweir     return (sal_True);
1380*cdf0e10cSrcweir }
1381*cdf0e10cSrcweir 
1382*cdf0e10cSrcweir static sal_Bool putLine(osl_TFile* pFile, const sal_Char *pszLine)
1383*cdf0e10cSrcweir {
1384*cdf0e10cSrcweir     unsigned int Len = strlen(pszLine);
1385*cdf0e10cSrcweir 
1386*cdf0e10cSrcweir #ifdef DEBUG_OSL_PROFILE
1387*cdf0e10cSrcweir     int strLen=0;
1388*cdf0e10cSrcweir #endif
1389*cdf0e10cSrcweir 
1390*cdf0e10cSrcweir     if ( pFile == 0 || pFile->m_Handle < 0 )
1391*cdf0e10cSrcweir     {
1392*cdf0e10cSrcweir         return (sal_False);
1393*cdf0e10cSrcweir     }
1394*cdf0e10cSrcweir 
1395*cdf0e10cSrcweir     if ( pFile->m_pWriteBuf == 0 )
1396*cdf0e10cSrcweir     {
1397*cdf0e10cSrcweir         pFile->m_pWriteBuf = (sal_Char*) malloc(Len+3);
1398*cdf0e10cSrcweir         pFile->m_nWriteBufLen = Len+3;
1399*cdf0e10cSrcweir         pFile->m_nWriteBufFree = Len+3;
1400*cdf0e10cSrcweir     }
1401*cdf0e10cSrcweir     else
1402*cdf0e10cSrcweir     {
1403*cdf0e10cSrcweir         if ( pFile->m_nWriteBufFree <= Len + 3 )
1404*cdf0e10cSrcweir         {
1405*cdf0e10cSrcweir             sal_Char* pTmp;
1406*cdf0e10cSrcweir 
1407*cdf0e10cSrcweir             pTmp=(sal_Char*) realloc(pFile->m_pWriteBuf,( ( pFile->m_nWriteBufLen + Len ) * 2) );
1408*cdf0e10cSrcweir             if ( pTmp == 0 )
1409*cdf0e10cSrcweir             {
1410*cdf0e10cSrcweir                 return sal_False;
1411*cdf0e10cSrcweir             }
1412*cdf0e10cSrcweir             pFile->m_pWriteBuf = pTmp;
1413*cdf0e10cSrcweir             pFile->m_nWriteBufFree = pFile->m_nWriteBufFree + pFile->m_nWriteBufLen + ( 2 * Len );
1414*cdf0e10cSrcweir             pFile->m_nWriteBufLen = ( pFile->m_nWriteBufLen + Len ) * 2;
1415*cdf0e10cSrcweir             memset( (pFile->m_pWriteBuf) + ( pFile->m_nWriteBufLen - pFile->m_nWriteBufFree ), 0, pFile->m_nWriteBufFree);
1416*cdf0e10cSrcweir         }
1417*cdf0e10cSrcweir     }
1418*cdf0e10cSrcweir 
1419*cdf0e10cSrcweir 
1420*cdf0e10cSrcweir 
1421*cdf0e10cSrcweir     memcpy(pFile->m_pWriteBuf + ( pFile->m_nWriteBufLen - pFile->m_nWriteBufFree ),pszLine,Len+1);
1422*cdf0e10cSrcweir #ifdef DEBUG_OSL_PROFILE
1423*cdf0e10cSrcweir     strLen = strlen(pFile->m_pWriteBuf);
1424*cdf0e10cSrcweir #endif
1425*cdf0e10cSrcweir     pFile->m_pWriteBuf[pFile->m_nWriteBufLen - pFile->m_nWriteBufFree + Len]='\r';
1426*cdf0e10cSrcweir     pFile->m_pWriteBuf[pFile->m_nWriteBufLen - pFile->m_nWriteBufFree + Len + 1]='\n';
1427*cdf0e10cSrcweir     pFile->m_pWriteBuf[pFile->m_nWriteBufLen - pFile->m_nWriteBufFree + Len + 2]='\0';
1428*cdf0e10cSrcweir 
1429*cdf0e10cSrcweir     pFile->m_nWriteBufFree-=Len+2;
1430*cdf0e10cSrcweir 
1431*cdf0e10cSrcweir #ifdef DEBUG_OSL_PROFILE
1432*cdf0e10cSrcweir /*    OSL_TRACE("File Buffer in _putLine '%s' '%i'(%i)\n",pFile->m_pWriteBuf,strlen(pFile->m_pWriteBuf),pFile->m_nWriteBufLen - pFile->m_nWriteBufFree);*/
1433*cdf0e10cSrcweir #endif
1434*cdf0e10cSrcweir 
1435*cdf0e10cSrcweir     return (sal_True);
1436*cdf0e10cSrcweir }
1437*cdf0e10cSrcweir 
1438*cdf0e10cSrcweir /* platform specific end */
1439*cdf0e10cSrcweir 
1440*cdf0e10cSrcweir static const sal_Char* stripBlanks(const sal_Char* String, sal_uInt32* pLen)
1441*cdf0e10cSrcweir {
1442*cdf0e10cSrcweir     if  ( (pLen != NULL) && ( *pLen != 0 ) )
1443*cdf0e10cSrcweir     {
1444*cdf0e10cSrcweir         while ((String[*pLen - 1] == ' ') || (String[*pLen - 1] == '\t'))
1445*cdf0e10cSrcweir             (*pLen)--;
1446*cdf0e10cSrcweir 
1447*cdf0e10cSrcweir         while ((*String == ' ') || (*String == '\t'))
1448*cdf0e10cSrcweir         {
1449*cdf0e10cSrcweir             String++;
1450*cdf0e10cSrcweir             (*pLen)--;
1451*cdf0e10cSrcweir         }
1452*cdf0e10cSrcweir     }
1453*cdf0e10cSrcweir     else
1454*cdf0e10cSrcweir         while ((*String == ' ') || (*String == '\t'))
1455*cdf0e10cSrcweir             String++;
1456*cdf0e10cSrcweir 
1457*cdf0e10cSrcweir     return (String);
1458*cdf0e10cSrcweir }
1459*cdf0e10cSrcweir 
1460*cdf0e10cSrcweir static const sal_Char* addLine(osl_TProfileImpl* pProfile, const sal_Char* Line)
1461*cdf0e10cSrcweir {
1462*cdf0e10cSrcweir     if (pProfile->m_NoLines >= pProfile->m_MaxLines)
1463*cdf0e10cSrcweir     {
1464*cdf0e10cSrcweir         if (pProfile->m_Lines == NULL)
1465*cdf0e10cSrcweir         {
1466*cdf0e10cSrcweir             pProfile->m_MaxLines = LINES_INI;
1467*cdf0e10cSrcweir             pProfile->m_Lines = (sal_Char **)malloc(pProfile->m_MaxLines * sizeof(sal_Char *));
1468*cdf0e10cSrcweir         }
1469*cdf0e10cSrcweir         else
1470*cdf0e10cSrcweir         {
1471*cdf0e10cSrcweir             pProfile->m_MaxLines += LINES_ADD;
1472*cdf0e10cSrcweir             pProfile->m_Lines = (sal_Char **)realloc(pProfile->m_Lines,
1473*cdf0e10cSrcweir                                                  pProfile->m_MaxLines * sizeof(sal_Char *));
1474*cdf0e10cSrcweir         }
1475*cdf0e10cSrcweir 
1476*cdf0e10cSrcweir         if (pProfile->m_Lines == NULL)
1477*cdf0e10cSrcweir         {
1478*cdf0e10cSrcweir             pProfile->m_NoLines  = 0;
1479*cdf0e10cSrcweir             pProfile->m_MaxLines = 0;
1480*cdf0e10cSrcweir             return (NULL);
1481*cdf0e10cSrcweir         }
1482*cdf0e10cSrcweir 
1483*cdf0e10cSrcweir     }
1484*cdf0e10cSrcweir 
1485*cdf0e10cSrcweir     pProfile->m_Lines[pProfile->m_NoLines++] = strdup(Line);
1486*cdf0e10cSrcweir 
1487*cdf0e10cSrcweir     return (pProfile->m_Lines[pProfile->m_NoLines - 1]);
1488*cdf0e10cSrcweir }
1489*cdf0e10cSrcweir 
1490*cdf0e10cSrcweir static const sal_Char* insertLine(osl_TProfileImpl* pProfile, const sal_Char* Line, sal_uInt32 LineNo)
1491*cdf0e10cSrcweir {
1492*cdf0e10cSrcweir     if (pProfile->m_NoLines >= pProfile->m_MaxLines)
1493*cdf0e10cSrcweir     {
1494*cdf0e10cSrcweir         if (pProfile->m_Lines == NULL)
1495*cdf0e10cSrcweir         {
1496*cdf0e10cSrcweir             pProfile->m_MaxLines = LINES_INI;
1497*cdf0e10cSrcweir             pProfile->m_Lines = (sal_Char **)malloc(pProfile->m_MaxLines * sizeof(sal_Char *));
1498*cdf0e10cSrcweir         }
1499*cdf0e10cSrcweir         else
1500*cdf0e10cSrcweir         {
1501*cdf0e10cSrcweir             pProfile->m_MaxLines += LINES_ADD;
1502*cdf0e10cSrcweir             pProfile->m_Lines = (sal_Char **)realloc(pProfile->m_Lines,
1503*cdf0e10cSrcweir                                                  pProfile->m_MaxLines * sizeof(sal_Char *));
1504*cdf0e10cSrcweir         }
1505*cdf0e10cSrcweir 
1506*cdf0e10cSrcweir         if (pProfile->m_Lines == NULL)
1507*cdf0e10cSrcweir         {
1508*cdf0e10cSrcweir             pProfile->m_NoLines  = 0;
1509*cdf0e10cSrcweir             pProfile->m_MaxLines = 0;
1510*cdf0e10cSrcweir             return (NULL);
1511*cdf0e10cSrcweir         }
1512*cdf0e10cSrcweir 
1513*cdf0e10cSrcweir     }
1514*cdf0e10cSrcweir 
1515*cdf0e10cSrcweir     LineNo = LineNo > pProfile->m_NoLines ? pProfile->m_NoLines : LineNo;
1516*cdf0e10cSrcweir 
1517*cdf0e10cSrcweir     if (LineNo < pProfile->m_NoLines)
1518*cdf0e10cSrcweir     {
1519*cdf0e10cSrcweir         sal_uInt32 i, n;
1520*cdf0e10cSrcweir         osl_TProfileSection* pSec;
1521*cdf0e10cSrcweir 
1522*cdf0e10cSrcweir         memmove(&pProfile->m_Lines[LineNo + 1], &pProfile->m_Lines[LineNo],
1523*cdf0e10cSrcweir                 (pProfile->m_NoLines - LineNo) * sizeof(sal_Char *));
1524*cdf0e10cSrcweir 
1525*cdf0e10cSrcweir         /* adjust line references */
1526*cdf0e10cSrcweir         for (i = 0; i < pProfile->m_NoSections; i++)
1527*cdf0e10cSrcweir         {
1528*cdf0e10cSrcweir             pSec = &pProfile->m_Sections[i];
1529*cdf0e10cSrcweir 
1530*cdf0e10cSrcweir             if (pSec->m_Line >= LineNo)
1531*cdf0e10cSrcweir                 pSec->m_Line++;
1532*cdf0e10cSrcweir 
1533*cdf0e10cSrcweir             for (n = 0; n < pSec->m_NoEntries; n++)
1534*cdf0e10cSrcweir                 if (pSec->m_Entries[n].m_Line >= LineNo)
1535*cdf0e10cSrcweir                     pSec->m_Entries[n].m_Line++;
1536*cdf0e10cSrcweir         }
1537*cdf0e10cSrcweir     }
1538*cdf0e10cSrcweir 
1539*cdf0e10cSrcweir     pProfile->m_NoLines++;
1540*cdf0e10cSrcweir 
1541*cdf0e10cSrcweir     pProfile->m_Lines[LineNo] = strdup(Line);
1542*cdf0e10cSrcweir 
1543*cdf0e10cSrcweir     return (pProfile->m_Lines[LineNo]);
1544*cdf0e10cSrcweir }
1545*cdf0e10cSrcweir 
1546*cdf0e10cSrcweir static void removeLine(osl_TProfileImpl* pProfile, sal_uInt32 LineNo)
1547*cdf0e10cSrcweir {
1548*cdf0e10cSrcweir     if (LineNo < pProfile->m_NoLines)
1549*cdf0e10cSrcweir     {
1550*cdf0e10cSrcweir         free(pProfile->m_Lines[LineNo]);
1551*cdf0e10cSrcweir         if (pProfile->m_NoLines - LineNo > 1)
1552*cdf0e10cSrcweir         {
1553*cdf0e10cSrcweir             sal_uInt32 i, n;
1554*cdf0e10cSrcweir             osl_TProfileSection* pSec;
1555*cdf0e10cSrcweir 
1556*cdf0e10cSrcweir             memmove(&pProfile->m_Lines[LineNo], &pProfile->m_Lines[LineNo + 1],
1557*cdf0e10cSrcweir                     (pProfile->m_NoLines - LineNo - 1) * sizeof(sal_Char *));
1558*cdf0e10cSrcweir 
1559*cdf0e10cSrcweir             /* adjust line references */
1560*cdf0e10cSrcweir             for (i = 0; i < pProfile->m_NoSections; i++)
1561*cdf0e10cSrcweir             {
1562*cdf0e10cSrcweir                 pSec = &pProfile->m_Sections[i];
1563*cdf0e10cSrcweir 
1564*cdf0e10cSrcweir                 if (pSec->m_Line > LineNo)
1565*cdf0e10cSrcweir                     pSec->m_Line--;
1566*cdf0e10cSrcweir 
1567*cdf0e10cSrcweir                 for (n = 0; n < pSec->m_NoEntries; n++)
1568*cdf0e10cSrcweir                     if (pSec->m_Entries[n].m_Line > LineNo)
1569*cdf0e10cSrcweir                         pSec->m_Entries[n].m_Line--;
1570*cdf0e10cSrcweir             }
1571*cdf0e10cSrcweir         }
1572*cdf0e10cSrcweir         else
1573*cdf0e10cSrcweir         {
1574*cdf0e10cSrcweir             pProfile->m_Lines[LineNo] = 0;
1575*cdf0e10cSrcweir         }
1576*cdf0e10cSrcweir 
1577*cdf0e10cSrcweir         pProfile->m_NoLines--;
1578*cdf0e10cSrcweir     }
1579*cdf0e10cSrcweir 
1580*cdf0e10cSrcweir     return;
1581*cdf0e10cSrcweir }
1582*cdf0e10cSrcweir 
1583*cdf0e10cSrcweir static void setEntry(osl_TProfileImpl* pProfile, osl_TProfileSection* pSection,
1584*cdf0e10cSrcweir                      sal_uInt32 NoEntry, sal_uInt32 Line,
1585*cdf0e10cSrcweir                      const sal_Char* Entry, sal_uInt32 Len)
1586*cdf0e10cSrcweir {
1587*cdf0e10cSrcweir     Entry = stripBlanks(Entry, &Len);
1588*cdf0e10cSrcweir     pSection->m_Entries[NoEntry].m_Line   = Line;
1589*cdf0e10cSrcweir     pSection->m_Entries[NoEntry].m_Offset = Entry - pProfile->m_Lines[Line];
1590*cdf0e10cSrcweir     pSection->m_Entries[NoEntry].m_Len    = Len;
1591*cdf0e10cSrcweir 
1592*cdf0e10cSrcweir     return;
1593*cdf0e10cSrcweir }
1594*cdf0e10cSrcweir 
1595*cdf0e10cSrcweir static sal_Bool addEntry(osl_TProfileImpl* pProfile, osl_TProfileSection *pSection,
1596*cdf0e10cSrcweir                         int Line, const sal_Char* Entry, sal_uInt32 Len)
1597*cdf0e10cSrcweir {
1598*cdf0e10cSrcweir     if (pSection != NULL)
1599*cdf0e10cSrcweir     {
1600*cdf0e10cSrcweir         if (pSection->m_NoEntries >= pSection->m_MaxEntries)
1601*cdf0e10cSrcweir         {
1602*cdf0e10cSrcweir             if (pSection->m_Entries == NULL)
1603*cdf0e10cSrcweir             {
1604*cdf0e10cSrcweir                 pSection->m_MaxEntries = ENTRIES_INI;
1605*cdf0e10cSrcweir                 pSection->m_Entries = (osl_TProfileEntry *)malloc(
1606*cdf0e10cSrcweir                                 pSection->m_MaxEntries * sizeof(osl_TProfileEntry));
1607*cdf0e10cSrcweir             }
1608*cdf0e10cSrcweir             else
1609*cdf0e10cSrcweir             {
1610*cdf0e10cSrcweir                 pSection->m_MaxEntries += ENTRIES_ADD;
1611*cdf0e10cSrcweir                 pSection->m_Entries = (osl_TProfileEntry *)realloc(pSection->m_Entries,
1612*cdf0e10cSrcweir                                 pSection->m_MaxEntries * sizeof(osl_TProfileEntry));
1613*cdf0e10cSrcweir             }
1614*cdf0e10cSrcweir 
1615*cdf0e10cSrcweir             if (pSection->m_Entries == NULL)
1616*cdf0e10cSrcweir             {
1617*cdf0e10cSrcweir                 pSection->m_NoEntries  = 0;
1618*cdf0e10cSrcweir                 pSection->m_MaxEntries = 0;
1619*cdf0e10cSrcweir                 return (sal_False);
1620*cdf0e10cSrcweir             }
1621*cdf0e10cSrcweir         }
1622*cdf0e10cSrcweir 
1623*cdf0e10cSrcweir         pSection->m_NoEntries++;
1624*cdf0e10cSrcweir 
1625*cdf0e10cSrcweir         Entry = stripBlanks(Entry, &Len);
1626*cdf0e10cSrcweir         setEntry(pProfile, pSection, pSection->m_NoEntries - 1, Line,
1627*cdf0e10cSrcweir                  Entry, Len);
1628*cdf0e10cSrcweir 
1629*cdf0e10cSrcweir         return (sal_True);
1630*cdf0e10cSrcweir     }
1631*cdf0e10cSrcweir 
1632*cdf0e10cSrcweir     return (sal_False);
1633*cdf0e10cSrcweir }
1634*cdf0e10cSrcweir 
1635*cdf0e10cSrcweir static void removeEntry(osl_TProfileSection *pSection, sal_uInt32 NoEntry)
1636*cdf0e10cSrcweir {
1637*cdf0e10cSrcweir     if (NoEntry < pSection->m_NoEntries)
1638*cdf0e10cSrcweir     {
1639*cdf0e10cSrcweir         if (pSection->m_NoEntries - NoEntry > 1)
1640*cdf0e10cSrcweir             memmove(&pSection->m_Entries[NoEntry],
1641*cdf0e10cSrcweir                     &pSection->m_Entries[NoEntry + 1],
1642*cdf0e10cSrcweir                     (pSection->m_NoEntries - NoEntry - 1) * sizeof(osl_TProfileEntry));
1643*cdf0e10cSrcweir         pSection->m_NoEntries--;
1644*cdf0e10cSrcweir     }
1645*cdf0e10cSrcweir 
1646*cdf0e10cSrcweir     return;
1647*cdf0e10cSrcweir }
1648*cdf0e10cSrcweir 
1649*cdf0e10cSrcweir static sal_Bool addSection(osl_TProfileImpl* pProfile, int Line, const sal_Char* Section, sal_uInt32 Len)
1650*cdf0e10cSrcweir {
1651*cdf0e10cSrcweir     if (pProfile->m_NoSections >= pProfile->m_MaxSections)
1652*cdf0e10cSrcweir     {
1653*cdf0e10cSrcweir         if (pProfile->m_Sections == NULL)
1654*cdf0e10cSrcweir         {
1655*cdf0e10cSrcweir             pProfile->m_MaxSections = SECTIONS_INI;
1656*cdf0e10cSrcweir             pProfile->m_Sections = (osl_TProfileSection *)malloc(pProfile->m_MaxSections * sizeof(osl_TProfileSection));
1657*cdf0e10cSrcweir         }
1658*cdf0e10cSrcweir         else
1659*cdf0e10cSrcweir         {
1660*cdf0e10cSrcweir             pProfile->m_MaxSections += SECTIONS_ADD;
1661*cdf0e10cSrcweir             pProfile->m_Sections = (osl_TProfileSection *)realloc(pProfile->m_Sections,
1662*cdf0e10cSrcweir                                           pProfile->m_MaxSections * sizeof(osl_TProfileSection));
1663*cdf0e10cSrcweir         }
1664*cdf0e10cSrcweir 
1665*cdf0e10cSrcweir         if (pProfile->m_Sections == NULL)
1666*cdf0e10cSrcweir         {
1667*cdf0e10cSrcweir             pProfile->m_NoSections = 0;
1668*cdf0e10cSrcweir             pProfile->m_MaxSections = 0;
1669*cdf0e10cSrcweir             return (sal_False);
1670*cdf0e10cSrcweir         }
1671*cdf0e10cSrcweir     }
1672*cdf0e10cSrcweir 
1673*cdf0e10cSrcweir     pProfile->m_NoSections++;
1674*cdf0e10cSrcweir 
1675*cdf0e10cSrcweir     pProfile->m_Sections[pProfile->m_NoSections - 1].m_Entries    = NULL;
1676*cdf0e10cSrcweir     pProfile->m_Sections[pProfile->m_NoSections - 1].m_NoEntries  = 0;
1677*cdf0e10cSrcweir     pProfile->m_Sections[pProfile->m_NoSections - 1].m_MaxEntries = 0;
1678*cdf0e10cSrcweir 
1679*cdf0e10cSrcweir     Section = (sal_Char *)stripBlanks(Section, &Len);
1680*cdf0e10cSrcweir     pProfile->m_Sections[pProfile->m_NoSections - 1].m_Line = Line;
1681*cdf0e10cSrcweir     pProfile->m_Sections[pProfile->m_NoSections - 1].m_Offset = Section - pProfile->m_Lines[Line];
1682*cdf0e10cSrcweir     pProfile->m_Sections[pProfile->m_NoSections - 1].m_Len = Len;
1683*cdf0e10cSrcweir 
1684*cdf0e10cSrcweir     return (sal_True);
1685*cdf0e10cSrcweir }
1686*cdf0e10cSrcweir 
1687*cdf0e10cSrcweir static void removeSection(osl_TProfileImpl* pProfile, osl_TProfileSection *pSection)
1688*cdf0e10cSrcweir {
1689*cdf0e10cSrcweir     sal_uInt32 Section;
1690*cdf0e10cSrcweir 
1691*cdf0e10cSrcweir     if ((Section = pSection - pProfile->m_Sections) < pProfile->m_NoSections)
1692*cdf0e10cSrcweir     {
1693*cdf0e10cSrcweir         free (pSection->m_Entries);
1694*cdf0e10cSrcweir         if (pProfile->m_NoSections - Section > 1)
1695*cdf0e10cSrcweir         {
1696*cdf0e10cSrcweir             memmove(&pProfile->m_Sections[Section], &pProfile->m_Sections[Section + 1],
1697*cdf0e10cSrcweir                     (pProfile->m_NoSections - Section - 1) * sizeof(osl_TProfileSection));
1698*cdf0e10cSrcweir         }
1699*cdf0e10cSrcweir         else
1700*cdf0e10cSrcweir         {
1701*cdf0e10cSrcweir             pSection->m_Entries = 0;
1702*cdf0e10cSrcweir         }
1703*cdf0e10cSrcweir 
1704*cdf0e10cSrcweir         pProfile->m_NoSections--;
1705*cdf0e10cSrcweir     }
1706*cdf0e10cSrcweir 
1707*cdf0e10cSrcweir     return;
1708*cdf0e10cSrcweir }
1709*cdf0e10cSrcweir 
1710*cdf0e10cSrcweir static osl_TProfileSection* findEntry(osl_TProfileImpl* pProfile, const sal_Char* Section,
1711*cdf0e10cSrcweir                                       const sal_Char* Entry, sal_uInt32 *pNoEntry)
1712*cdf0e10cSrcweir {
1713*cdf0e10cSrcweir static  sal_uInt32    Sect = 0;
1714*cdf0e10cSrcweir         sal_uInt32    i, n;
1715*cdf0e10cSrcweir         sal_uInt32    Len;
1716*cdf0e10cSrcweir         const sal_Char* pStr;
1717*cdf0e10cSrcweir         osl_TProfileSection* pSec;
1718*cdf0e10cSrcweir 
1719*cdf0e10cSrcweir     Len = strlen(Section);
1720*cdf0e10cSrcweir     Section = (sal_Char *)stripBlanks(Section, &Len);
1721*cdf0e10cSrcweir 
1722*cdf0e10cSrcweir     n = Sect;
1723*cdf0e10cSrcweir 
1724*cdf0e10cSrcweir     for (i = 0; i < pProfile->m_NoSections; i++)
1725*cdf0e10cSrcweir     {
1726*cdf0e10cSrcweir         n %= pProfile->m_NoSections;
1727*cdf0e10cSrcweir         pSec = &pProfile->m_Sections[n];
1728*cdf0e10cSrcweir         if ((Len == pSec->m_Len) &&
1729*cdf0e10cSrcweir             (strnicmp(Section, &pProfile->m_Lines[pSec->m_Line][pSec->m_Offset], pSec->m_Len)
1730*cdf0e10cSrcweir              == 0))
1731*cdf0e10cSrcweir             break;
1732*cdf0e10cSrcweir         n++;
1733*cdf0e10cSrcweir     }
1734*cdf0e10cSrcweir 
1735*cdf0e10cSrcweir     Sect = n;
1736*cdf0e10cSrcweir 
1737*cdf0e10cSrcweir     if (i < pProfile->m_NoSections)
1738*cdf0e10cSrcweir     {
1739*cdf0e10cSrcweir         Len = strlen(Entry);
1740*cdf0e10cSrcweir         Entry = stripBlanks(Entry, &Len);
1741*cdf0e10cSrcweir 
1742*cdf0e10cSrcweir         *pNoEntry = pSec->m_NoEntries;
1743*cdf0e10cSrcweir 
1744*cdf0e10cSrcweir         for (i = 0; i < pSec->m_NoEntries; i++)
1745*cdf0e10cSrcweir         {
1746*cdf0e10cSrcweir             pStr = &pProfile->m_Lines[pSec->m_Entries[i].m_Line]
1747*cdf0e10cSrcweir                                      [pSec->m_Entries[i].m_Offset];
1748*cdf0e10cSrcweir             if ((Len == pSec->m_Entries[i].m_Len) &&
1749*cdf0e10cSrcweir                 (strnicmp(Entry, pStr, pSec->m_Entries[i].m_Len)
1750*cdf0e10cSrcweir                  == 0))
1751*cdf0e10cSrcweir             {
1752*cdf0e10cSrcweir                 *pNoEntry = i;
1753*cdf0e10cSrcweir                 break;
1754*cdf0e10cSrcweir             }
1755*cdf0e10cSrcweir         }
1756*cdf0e10cSrcweir     }
1757*cdf0e10cSrcweir     else
1758*cdf0e10cSrcweir         pSec = NULL;
1759*cdf0e10cSrcweir 
1760*cdf0e10cSrcweir     return (pSec);
1761*cdf0e10cSrcweir }
1762*cdf0e10cSrcweir 
1763*cdf0e10cSrcweir static sal_Bool loadProfile(osl_TFile* pFile, osl_TProfileImpl* pProfile)
1764*cdf0e10cSrcweir {
1765*cdf0e10cSrcweir     sal_uInt32    i;
1766*cdf0e10cSrcweir     sal_Char*       pStr;
1767*cdf0e10cSrcweir     sal_Char*       pChar;
1768*cdf0e10cSrcweir     sal_Char        Line[1024];
1769*cdf0e10cSrcweir 
1770*cdf0e10cSrcweir     pProfile->m_NoLines    = 0;
1771*cdf0e10cSrcweir     pProfile->m_NoSections = 0;
1772*cdf0e10cSrcweir 
1773*cdf0e10cSrcweir     OSL_VERIFY(rewindFile(pFile, sal_False));
1774*cdf0e10cSrcweir 
1775*cdf0e10cSrcweir     while (getLine(pFile, Line, sizeof(Line)))
1776*cdf0e10cSrcweir     {
1777*cdf0e10cSrcweir         if (! addLine(pProfile, Line))
1778*cdf0e10cSrcweir             return (sal_False);
1779*cdf0e10cSrcweir     }
1780*cdf0e10cSrcweir 
1781*cdf0e10cSrcweir     for (i = 0; i < pProfile->m_NoLines; i++)
1782*cdf0e10cSrcweir     {
1783*cdf0e10cSrcweir         pStr = (sal_Char *)stripBlanks(pProfile->m_Lines[i], NULL);
1784*cdf0e10cSrcweir 
1785*cdf0e10cSrcweir         if ((*pStr == '\0') || (*pStr == ';'))
1786*cdf0e10cSrcweir             continue;
1787*cdf0e10cSrcweir 
1788*cdf0e10cSrcweir         if ((*pStr != '[') || ((pChar = strrchr(pStr, ']')) == NULL) ||
1789*cdf0e10cSrcweir             ((pChar - pStr) <= 2))
1790*cdf0e10cSrcweir         {
1791*cdf0e10cSrcweir             /* insert entry */
1792*cdf0e10cSrcweir 
1793*cdf0e10cSrcweir             if (pProfile->m_NoSections < 1)
1794*cdf0e10cSrcweir                 continue;
1795*cdf0e10cSrcweir 
1796*cdf0e10cSrcweir             if ((pChar = strchr(pStr, '=')) == NULL)
1797*cdf0e10cSrcweir                 pChar = pStr + strlen(pStr);
1798*cdf0e10cSrcweir 
1799*cdf0e10cSrcweir             if (! addEntry(pProfile, &pProfile->m_Sections[pProfile->m_NoSections - 1],
1800*cdf0e10cSrcweir                            i, pStr, pChar - pStr))
1801*cdf0e10cSrcweir                 return (sal_False);
1802*cdf0e10cSrcweir         }
1803*cdf0e10cSrcweir         else
1804*cdf0e10cSrcweir         {
1805*cdf0e10cSrcweir             /* new section */
1806*cdf0e10cSrcweir 
1807*cdf0e10cSrcweir             if (! addSection(pProfile, i, pStr + 1, pChar - pStr - 1))
1808*cdf0e10cSrcweir                 return (sal_False);
1809*cdf0e10cSrcweir         }
1810*cdf0e10cSrcweir     }
1811*cdf0e10cSrcweir 
1812*cdf0e10cSrcweir     return (sal_True);
1813*cdf0e10cSrcweir }
1814*cdf0e10cSrcweir 
1815*cdf0e10cSrcweir static sal_Bool storeProfile(osl_TFile* pFile, osl_TProfileImpl* pProfile, sal_Bool bCleanup)
1816*cdf0e10cSrcweir {
1817*cdf0e10cSrcweir     if (pProfile->m_Lines != NULL)
1818*cdf0e10cSrcweir     {
1819*cdf0e10cSrcweir         if (pProfile->m_Flags & FLG_MODIFIED)
1820*cdf0e10cSrcweir         {
1821*cdf0e10cSrcweir             sal_uInt32 i;
1822*cdf0e10cSrcweir 
1823*cdf0e10cSrcweir             OSL_VERIFY(rewindFile(pFile, sal_True));
1824*cdf0e10cSrcweir 
1825*cdf0e10cSrcweir             for (i = 0; i < pProfile->m_NoLines; i++)
1826*cdf0e10cSrcweir                 OSL_VERIFY(putLine(pFile, pProfile->m_Lines[i]));
1827*cdf0e10cSrcweir 
1828*cdf0e10cSrcweir             pProfile->m_Flags &= ~FLG_MODIFIED;
1829*cdf0e10cSrcweir         }
1830*cdf0e10cSrcweir 
1831*cdf0e10cSrcweir         if (bCleanup)
1832*cdf0e10cSrcweir         {
1833*cdf0e10cSrcweir             while (pProfile->m_NoLines > 0)
1834*cdf0e10cSrcweir                 removeLine(pProfile, pProfile->m_NoLines - 1);
1835*cdf0e10cSrcweir 
1836*cdf0e10cSrcweir             free(pProfile->m_Lines);
1837*cdf0e10cSrcweir             pProfile->m_Lines = NULL;
1838*cdf0e10cSrcweir             pProfile->m_MaxLines = 0;
1839*cdf0e10cSrcweir 
1840*cdf0e10cSrcweir             while (pProfile->m_NoSections > 0)
1841*cdf0e10cSrcweir                 removeSection(pProfile, &pProfile->m_Sections[pProfile->m_NoSections - 1]);
1842*cdf0e10cSrcweir 
1843*cdf0e10cSrcweir             free(pProfile->m_Sections);
1844*cdf0e10cSrcweir             pProfile->m_Sections = NULL;
1845*cdf0e10cSrcweir             pProfile->m_MaxSections = 0;
1846*cdf0e10cSrcweir         }
1847*cdf0e10cSrcweir     }
1848*cdf0e10cSrcweir 
1849*cdf0e10cSrcweir     return (sal_True);
1850*cdf0e10cSrcweir }
1851*cdf0e10cSrcweir 
1852*cdf0e10cSrcweir static osl_TProfileImpl* acquireProfile(oslProfile Profile, sal_Bool bWriteable)
1853*cdf0e10cSrcweir {
1854*cdf0e10cSrcweir     osl_TProfileImpl* pProfile = (osl_TProfileImpl*)Profile;
1855*cdf0e10cSrcweir     oslProfileOption PFlags=0;
1856*cdf0e10cSrcweir 
1857*cdf0e10cSrcweir 
1858*cdf0e10cSrcweir     if ( bWriteable )
1859*cdf0e10cSrcweir     {
1860*cdf0e10cSrcweir /*          PFlags = osl_Profile_DEFAULT | osl_Profile_READWRITE; */
1861*cdf0e10cSrcweir         PFlags = osl_Profile_DEFAULT | osl_Profile_WRITELOCK;
1862*cdf0e10cSrcweir     }
1863*cdf0e10cSrcweir     else
1864*cdf0e10cSrcweir     {
1865*cdf0e10cSrcweir         PFlags = osl_Profile_DEFAULT;
1866*cdf0e10cSrcweir     }
1867*cdf0e10cSrcweir 
1868*cdf0e10cSrcweir 
1869*cdf0e10cSrcweir     if (pProfile == NULL)
1870*cdf0e10cSrcweir     {
1871*cdf0e10cSrcweir #ifdef DEBUG_OSL_PROFILE
1872*cdf0e10cSrcweir         OSL_TRACE("AUTOOPEN MODE\n");
1873*cdf0e10cSrcweir #endif
1874*cdf0e10cSrcweir 
1875*cdf0e10cSrcweir         if ((pProfile = (osl_TProfileImpl*)osl_openProfile(NULL, PFlags)) != NULL )
1876*cdf0e10cSrcweir         {
1877*cdf0e10cSrcweir             pProfile->m_Flags |= FLG_AUTOOPEN;
1878*cdf0e10cSrcweir         }
1879*cdf0e10cSrcweir     }
1880*cdf0e10cSrcweir     else
1881*cdf0e10cSrcweir     {
1882*cdf0e10cSrcweir #ifdef DEBUG_OSL_PROFILE
1883*cdf0e10cSrcweir         OSL_TRACE("try to acquire\n");
1884*cdf0e10cSrcweir #endif
1885*cdf0e10cSrcweir 
1886*cdf0e10cSrcweir 
1887*cdf0e10cSrcweir 
1888*cdf0e10cSrcweir         if (! (pProfile->m_Flags & osl_Profile_SYSTEM))
1889*cdf0e10cSrcweir         {
1890*cdf0e10cSrcweir             if (! (pProfile->m_Flags & (osl_Profile_READLOCK |
1891*cdf0e10cSrcweir                                         osl_Profile_WRITELOCK | osl_Profile_FLUSHWRITE)))
1892*cdf0e10cSrcweir             {
1893*cdf0e10cSrcweir                 osl_TStamp Stamp;
1894*cdf0e10cSrcweir #ifdef DEBUG_OSL_PROFILE
1895*cdf0e10cSrcweir                 OSL_TRACE("DEFAULT MODE\n");
1896*cdf0e10cSrcweir #endif
1897*cdf0e10cSrcweir                 if (! (pProfile->m_pFile = openFileImpl(pProfile->m_strFileName, pProfile->m_Flags | PFlags)))
1898*cdf0e10cSrcweir                     return NULL;
1899*cdf0e10cSrcweir 
1900*cdf0e10cSrcweir                 Stamp = getFileStamp(pProfile->m_pFile);
1901*cdf0e10cSrcweir 
1902*cdf0e10cSrcweir                 if (memcmp(&Stamp, &(pProfile->m_Stamp), sizeof(osl_TStamp)))
1903*cdf0e10cSrcweir                 {
1904*cdf0e10cSrcweir                     pProfile->m_Stamp = Stamp;
1905*cdf0e10cSrcweir 
1906*cdf0e10cSrcweir                     loadProfile(pProfile->m_pFile, pProfile);
1907*cdf0e10cSrcweir                 }
1908*cdf0e10cSrcweir             }
1909*cdf0e10cSrcweir             else
1910*cdf0e10cSrcweir             {
1911*cdf0e10cSrcweir #ifdef DEBUG_OSL_PROFILE
1912*cdf0e10cSrcweir                 OSL_TRACE("READ/WRITELOCK MODE\n");
1913*cdf0e10cSrcweir #endif
1914*cdf0e10cSrcweir 
1915*cdf0e10cSrcweir 
1916*cdf0e10cSrcweir                 /* A readlock file could not be written */
1917*cdf0e10cSrcweir                 if ((pProfile->m_Flags & osl_Profile_READLOCK) && bWriteable)
1918*cdf0e10cSrcweir                 {
1919*cdf0e10cSrcweir                     return (NULL);
1920*cdf0e10cSrcweir                 }
1921*cdf0e10cSrcweir             }
1922*cdf0e10cSrcweir         }
1923*cdf0e10cSrcweir         else
1924*cdf0e10cSrcweir         {
1925*cdf0e10cSrcweir             sal_Bool bWriteable = sal_False;
1926*cdf0e10cSrcweir             char pszFilename[PATH_MAX] = "";
1927*cdf0e10cSrcweir 
1928*cdf0e10cSrcweir             if ( pProfile->m_strFileName != 0  && pProfile->m_strFileName->buffer[0] != 0 )
1929*cdf0e10cSrcweir                 FileURLToPath( pszFilename, PATH_MAX, pProfile->m_strFileName );
1930*cdf0e10cSrcweir             /* hack: usualy you have a specific HAB, but NULL works here... */
1931*cdf0e10cSrcweir             pProfile->m_hIni = PrfOpenProfile(NULL, (PCSZ)pszFilename);
1932*cdf0e10cSrcweir             if (! pProfile->m_hIni)
1933*cdf0e10cSrcweir                 return (NULL);
1934*cdf0e10cSrcweir         }
1935*cdf0e10cSrcweir     }
1936*cdf0e10cSrcweir 
1937*cdf0e10cSrcweir     return (pProfile);
1938*cdf0e10cSrcweir }
1939*cdf0e10cSrcweir 
1940*cdf0e10cSrcweir static sal_Bool releaseProfile(osl_TProfileImpl* pProfile)
1941*cdf0e10cSrcweir {
1942*cdf0e10cSrcweir #ifdef TRACE_OSL_PROFILE
1943*cdf0e10cSrcweir     OSL_TRACE("In  releaseProfile\n");
1944*cdf0e10cSrcweir #endif
1945*cdf0e10cSrcweir 
1946*cdf0e10cSrcweir     if ( pProfile == 0 )
1947*cdf0e10cSrcweir     {
1948*cdf0e10cSrcweir #ifdef TRACE_OSL_PROFILE
1949*cdf0e10cSrcweir         OSL_TRACE("Out releaseProfile [profile==0]\n");
1950*cdf0e10cSrcweir #endif
1951*cdf0e10cSrcweir         return sal_False;
1952*cdf0e10cSrcweir     }
1953*cdf0e10cSrcweir 
1954*cdf0e10cSrcweir     if (! (pProfile->m_Flags & osl_Profile_SYSTEM))
1955*cdf0e10cSrcweir     {
1956*cdf0e10cSrcweir         if (pProfile->m_Flags & FLG_AUTOOPEN)
1957*cdf0e10cSrcweir         {
1958*cdf0e10cSrcweir #ifdef TRACE_OSL_PROFILE
1959*cdf0e10cSrcweir         OSL_TRACE("Out releaseProfile [AUTOOPEN]\n");
1960*cdf0e10cSrcweir #endif
1961*cdf0e10cSrcweir             return (osl_closeProfile((oslProfile)pProfile));
1962*cdf0e10cSrcweir         }
1963*cdf0e10cSrcweir         else
1964*cdf0e10cSrcweir         {
1965*cdf0e10cSrcweir #ifdef DEBUG_OSL_PROFILE
1966*cdf0e10cSrcweir         OSL_TRACE("DEFAULT MODE\n");
1967*cdf0e10cSrcweir #endif
1968*cdf0e10cSrcweir         if (! (pProfile->m_Flags & (osl_Profile_READLOCK |
1969*cdf0e10cSrcweir                                     osl_Profile_WRITELOCK | osl_Profile_FLUSHWRITE)))
1970*cdf0e10cSrcweir             {
1971*cdf0e10cSrcweir                 if (pProfile->m_Flags & FLG_MODIFIED)
1972*cdf0e10cSrcweir                     storeProfile(pProfile->m_pFile, pProfile, sal_False);
1973*cdf0e10cSrcweir 
1974*cdf0e10cSrcweir                 closeFileImpl(pProfile->m_pFile);
1975*cdf0e10cSrcweir                 pProfile->m_pFile = NULL;
1976*cdf0e10cSrcweir             }
1977*cdf0e10cSrcweir         }
1978*cdf0e10cSrcweir     }
1979*cdf0e10cSrcweir     else
1980*cdf0e10cSrcweir         PrfCloseProfile(pProfile->m_hIni);
1981*cdf0e10cSrcweir 
1982*cdf0e10cSrcweir #ifdef TRACE_OSL_PROFILE
1983*cdf0e10cSrcweir     OSL_TRACE("Out releaseProfile [ok]\n");
1984*cdf0e10cSrcweir #endif
1985*cdf0e10cSrcweir     return (sal_True);
1986*cdf0e10cSrcweir }
1987*cdf0e10cSrcweir 
1988*cdf0e10cSrcweir #if 0 // YD
1989*cdf0e10cSrcweir 
1990*cdf0e10cSrcweir static sal_Bool lookupProfile(const sal_Char *pszPath, const sal_Char *pszFile, sal_Char *pPath)
1991*cdf0e10cSrcweir {
1992*cdf0e10cSrcweir     sal_Char *pChr, *pStr;
1993*cdf0e10cSrcweir     sal_Char Path[_MAX_PATH] = "";
1994*cdf0e10cSrcweir     sal_Char Product[132] = "";
1995*cdf0e10cSrcweir     sal_Char Buffer[1024];
1996*cdf0e10cSrcweir 
1997*cdf0e10cSrcweir     if (*pszPath == '"')
1998*cdf0e10cSrcweir     {
1999*cdf0e10cSrcweir         int i = 0;
2000*cdf0e10cSrcweir 
2001*cdf0e10cSrcweir         pszPath++;
2002*cdf0e10cSrcweir 
2003*cdf0e10cSrcweir         while ((*pszPath != '"') && (*pszPath != '\0'))
2004*cdf0e10cSrcweir             Product[i++] = *pszPath++;
2005*cdf0e10cSrcweir 
2006*cdf0e10cSrcweir         Product[i] = '\0';
2007*cdf0e10cSrcweir 
2008*cdf0e10cSrcweir         if (*pszPath == '"')
2009*cdf0e10cSrcweir             pszPath++;
2010*cdf0e10cSrcweir 
2011*cdf0e10cSrcweir         if ( (*pszPath == '/') || (*pszPath == '\\') )
2012*cdf0e10cSrcweir         {
2013*cdf0e10cSrcweir             pszPath++;
2014*cdf0e10cSrcweir         }
2015*cdf0e10cSrcweir     }
2016*cdf0e10cSrcweir     else
2017*cdf0e10cSrcweir     {
2018*cdf0e10cSrcweir         /* if we have not product identfication, do a special handling for soffice.ini */
2019*cdf0e10cSrcweir         if (stricmp(SVERSION_PROFILE, pszFile) == 0)
2020*cdf0e10cSrcweir         {
2021*cdf0e10cSrcweir             sal_Char   Profile[_MAX_PATH];
2022*cdf0e10cSrcweir             sal_Char   Dir[_MAX_PATH];
2023*cdf0e10cSrcweir             oslProfile hProfile;
2024*cdf0e10cSrcweir 
2025*cdf0e10cSrcweir             /* open sversion.ini in the system directory, and try to locate the entry
2026*cdf0e10cSrcweir                with the highest version for StarOffice */
2027*cdf0e10cSrcweir             if ((osl_getProfileName(SVERSION_FALLBACK, SVERSION_NAME, Profile, sizeof(Profile))) &&
2028*cdf0e10cSrcweir                 (hProfile = osl_openProfile(Profile, osl_Profile_READLOCK)))
2029*cdf0e10cSrcweir             {
2030*cdf0e10cSrcweir                 osl_getProfileSectionEntries(hProfile, SVERSION_SECTION,
2031*cdf0e10cSrcweir                                              Buffer, sizeof(Buffer));
2032*cdf0e10cSrcweir 
2033*cdf0e10cSrcweir                 for (pChr = Buffer; *pChr != '\0'; pChr += strlen(pChr) + 1)
2034*cdf0e10cSrcweir                 {
2035*cdf0e10cSrcweir                     if ((strnicmp(pChr, SVERSION_SOFFICE, sizeof(SVERSION_SOFFICE) - 1) == 0) &&
2036*cdf0e10cSrcweir                         (stricmp(Product, pChr) < 0))
2037*cdf0e10cSrcweir                     {
2038*cdf0e10cSrcweir                         osl_readProfileString(hProfile, SVERSION_SECTION, pChr,
2039*cdf0e10cSrcweir                                               Dir, sizeof(Dir), "");
2040*cdf0e10cSrcweir 
2041*cdf0e10cSrcweir                         /* check for existence of path */
2042*cdf0e10cSrcweir                         if (access(Dir, 0) >= 0)
2043*cdf0e10cSrcweir                             strcpy(Product, pChr);
2044*cdf0e10cSrcweir                     }
2045*cdf0e10cSrcweir                 }
2046*cdf0e10cSrcweir 
2047*cdf0e10cSrcweir                 osl_closeProfile(hProfile);
2048*cdf0e10cSrcweir             }
2049*cdf0e10cSrcweir 
2050*cdf0e10cSrcweir             /* open sversion.ini in the users directory, and try to locate the entry
2051*cdf0e10cSrcweir                with the highest version for StarOffice */
2052*cdf0e10cSrcweir             if ((strcmp(SVERSION_LOCATION, SVERSION_FALLBACK) != 0) &&
2053*cdf0e10cSrcweir                 (osl_getProfileName(SVERSION_LOCATION, SVERSION_NAME, Profile, sizeof(Profile))) &&
2054*cdf0e10cSrcweir                 (hProfile = osl_openProfile(Profile, osl_Profile_READLOCK)))
2055*cdf0e10cSrcweir             {
2056*cdf0e10cSrcweir                 osl_getProfileSectionEntries(hProfile, SVERSION_SECTION,
2057*cdf0e10cSrcweir                                              Buffer, sizeof(Buffer));
2058*cdf0e10cSrcweir 
2059*cdf0e10cSrcweir                 for (pChr = Buffer; *pChr != '\0'; pChr += strlen(pChr) + 1)
2060*cdf0e10cSrcweir                 {
2061*cdf0e10cSrcweir                     if ((strnicmp(pChr, SVERSION_SOFFICE, sizeof(SVERSION_SOFFICE) - 1) == 0) &&
2062*cdf0e10cSrcweir                         (stricmp(Product, pChr) < 0))
2063*cdf0e10cSrcweir                     {
2064*cdf0e10cSrcweir                         osl_readProfileString(hProfile, SVERSION_SECTION, pChr,
2065*cdf0e10cSrcweir                                               Dir, sizeof(Dir), "");
2066*cdf0e10cSrcweir 
2067*cdf0e10cSrcweir                         /* check for existence of path */
2068*cdf0e10cSrcweir                         if (access(Dir, 0) >= 0)
2069*cdf0e10cSrcweir                             strcpy(Product, pChr);
2070*cdf0e10cSrcweir                     }
2071*cdf0e10cSrcweir                 }
2072*cdf0e10cSrcweir 
2073*cdf0e10cSrcweir                 osl_closeProfile(hProfile);
2074*cdf0e10cSrcweir             }
2075*cdf0e10cSrcweir 
2076*cdf0e10cSrcweir             /* remove any trailing build number */
2077*cdf0e10cSrcweir             if ((pChr = strrchr(Product, '/')) != NULL)
2078*cdf0e10cSrcweir                 *pChr = '\0';
2079*cdf0e10cSrcweir         }
2080*cdf0e10cSrcweir     }
2081*cdf0e10cSrcweir 
2082*cdf0e10cSrcweir 
2083*cdf0e10cSrcweir     /* if we have an userid option eg. "-userid:rh[/usr/home/rh/staroffice]",
2084*cdf0e10cSrcweir        this will supercede all other locations */
2085*cdf0e10cSrcweir     if (osl_getCommandArgs(Buffer, sizeof(Buffer)) == osl_Process_E_None)
2086*cdf0e10cSrcweir     {
2087*cdf0e10cSrcweir         sal_Char *pStart, *pEnd;
2088*cdf0e10cSrcweir 
2089*cdf0e10cSrcweir         for (pChr = Buffer; *pChr != '\0'; pChr += strlen(pChr) + 1)
2090*cdf0e10cSrcweir             if (((*pChr == '-') || (*pChr == '+')) &&
2091*cdf0e10cSrcweir                 (strnicmp(pChr + 1, SVERSION_OPTION, sizeof(SVERSION_OPTION) - 1) == 0))
2092*cdf0e10cSrcweir             {
2093*cdf0e10cSrcweir                 if (((pStart = strchr(pChr + sizeof(SVERSION_OPTION), '[')) != NULL) &&
2094*cdf0e10cSrcweir                     ((pEnd = strchr(pStart + 1, ']')) != NULL))
2095*cdf0e10cSrcweir                 {
2096*cdf0e10cSrcweir                     strncpy(Path, pStart + 1, pEnd - (pStart + 1));
2097*cdf0e10cSrcweir                     Path[pEnd - (pStart + 1)] = '\0';
2098*cdf0e10cSrcweir 
2099*cdf0e10cSrcweir                     /* build full path */
2100*cdf0e10cSrcweir                     if ((Path[strlen(Path) - 1] != '/') && (Path[strlen(Path) - 1] != '\\'))
2101*cdf0e10cSrcweir                     {
2102*cdf0e10cSrcweir                         strcat(Path, "\\");
2103*cdf0e10cSrcweir                     }
2104*cdf0e10cSrcweir 
2105*cdf0e10cSrcweir                     pChr =&Path[strlen(Path)];
2106*cdf0e10cSrcweir                     if ( strlen(pszPath) <= 0 )
2107*cdf0e10cSrcweir                     {
2108*cdf0e10cSrcweir                         strcat(Path,SVERSION_USER);
2109*cdf0e10cSrcweir 
2110*cdf0e10cSrcweir                         if ( access(Path, 0) < 0 )
2111*cdf0e10cSrcweir                         {
2112*cdf0e10cSrcweir                             *pChr='\0';
2113*cdf0e10cSrcweir                         }
2114*cdf0e10cSrcweir                     }
2115*cdf0e10cSrcweir                     else
2116*cdf0e10cSrcweir                     {
2117*cdf0e10cSrcweir                         strcat(Path, pszPath);
2118*cdf0e10cSrcweir                     }
2119*cdf0e10cSrcweir 
2120*cdf0e10cSrcweir                     break;
2121*cdf0e10cSrcweir                 }
2122*cdf0e10cSrcweir             }
2123*cdf0e10cSrcweir     }
2124*cdf0e10cSrcweir 
2125*cdf0e10cSrcweir     if (strlen(Path) <= 0)
2126*cdf0e10cSrcweir     {
2127*cdf0e10cSrcweir         /* try to find the file in the directory of the executbale */
2128*cdf0e10cSrcweir         if (osl_getExecutableFile(Path, sizeof(Path)) != osl_Process_E_None)
2129*cdf0e10cSrcweir             return (sal_False);
2130*cdf0e10cSrcweir 
2131*cdf0e10cSrcweir         /* seperate path from filename */
2132*cdf0e10cSrcweir         if ((pChr = strrchr(Path, '\\')) == NULL)
2133*cdf0e10cSrcweir             if ((pChr = strrchr(Path, ':')) == NULL)
2134*cdf0e10cSrcweir                 return (sal_False);
2135*cdf0e10cSrcweir             else
2136*cdf0e10cSrcweir                 *pChr = '\0';
2137*cdf0e10cSrcweir         else
2138*cdf0e10cSrcweir             *pChr = '\0';
2139*cdf0e10cSrcweir 
2140*cdf0e10cSrcweir         /* if we have no product identification use the executable file name */
2141*cdf0e10cSrcweir         if (strlen(Product) <= 0)
2142*cdf0e10cSrcweir         {
2143*cdf0e10cSrcweir             strcpy(Product, pChr + 1);
2144*cdf0e10cSrcweir 
2145*cdf0e10cSrcweir             /* remove extension */
2146*cdf0e10cSrcweir             if ((pChr = strrchr(Product, '.')) != NULL)
2147*cdf0e10cSrcweir                 *pChr = '\0';
2148*cdf0e10cSrcweir         }
2149*cdf0e10cSrcweir 
2150*cdf0e10cSrcweir         /* remember last subdir */
2151*cdf0e10cSrcweir         pStr = strrchr(Path, '\\');
2152*cdf0e10cSrcweir 
2153*cdf0e10cSrcweir         strcat(Path, "\\");
2154*cdf0e10cSrcweir 
2155*cdf0e10cSrcweir         if ( strlen(pszPath) <= 0 )
2156*cdf0e10cSrcweir         {
2157*cdf0e10cSrcweir             strcat(Path, pszPath);
2158*cdf0e10cSrcweir         }
2159*cdf0e10cSrcweir         else
2160*cdf0e10cSrcweir         {
2161*cdf0e10cSrcweir             strcat(Path,pszPath);
2162*cdf0e10cSrcweir         }
2163*cdf0e10cSrcweir 
2164*cdf0e10cSrcweir         /* if file not exists, remove any specified subdirectories
2165*cdf0e10cSrcweir            like "bin" or "program" */
2166*cdf0e10cSrcweir         if (((access(Path, 0) < 0) && (pStr != NULL)) || (strlen(pszPath) <= 0))
2167*cdf0e10cSrcweir         {
2168*cdf0e10cSrcweir             static sal_Char *SubDirs[] = SVERSION_DIRS;
2169*cdf0e10cSrcweir 
2170*cdf0e10cSrcweir             int i = 0;
2171*cdf0e10cSrcweir 
2172*cdf0e10cSrcweir             for (i = 0; i < (sizeof(SubDirs) / sizeof(SubDirs[0])); i++)
2173*cdf0e10cSrcweir                 if (strnicmp(pStr + 1, SubDirs[i], strlen(SubDirs[i])) == 0)
2174*cdf0e10cSrcweir                 {
2175*cdf0e10cSrcweir                     if ( strlen(pszPath) <= 0)
2176*cdf0e10cSrcweir                     {
2177*cdf0e10cSrcweir                         strcpy(pStr + 1,SVERSION_USER);
2178*cdf0e10cSrcweir                         if ( access(Path, 0) < 0 )
2179*cdf0e10cSrcweir                         {
2180*cdf0e10cSrcweir                             *(pStr+1)='\0';
2181*cdf0e10cSrcweir                         }
2182*cdf0e10cSrcweir                     }
2183*cdf0e10cSrcweir                     else
2184*cdf0e10cSrcweir                     {
2185*cdf0e10cSrcweir                         strcpy(pStr + 1, pszPath);
2186*cdf0e10cSrcweir                     }
2187*cdf0e10cSrcweir 
2188*cdf0e10cSrcweir                     break;
2189*cdf0e10cSrcweir                 }
2190*cdf0e10cSrcweir         }
2191*cdf0e10cSrcweir 
2192*cdf0e10cSrcweir         pChr = &Path[strlen(Path)];
2193*cdf0e10cSrcweir         if ((Path[strlen(Path) - 1] != '/') && (Path[strlen(Path) - 1] != '\\'))
2194*cdf0e10cSrcweir             strcat(Path, "\\");
2195*cdf0e10cSrcweir         strcat(Path, pszFile);
2196*cdf0e10cSrcweir 
2197*cdf0e10cSrcweir         if ((access(Path, 0) < 0) && (strlen(Product) > 0))
2198*cdf0e10cSrcweir         {
2199*cdf0e10cSrcweir             sal_Char   Profile[_MAX_PATH];
2200*cdf0e10cSrcweir             oslProfile hProfile;
2201*cdf0e10cSrcweir 
2202*cdf0e10cSrcweir             /* remove appended filename */
2203*cdf0e10cSrcweir             *pChr = '\0';
2204*cdf0e10cSrcweir 
2205*cdf0e10cSrcweir             /* open sversion.ini in the system directory, and try to locate the entry
2206*cdf0e10cSrcweir                with the highest version for StarOffice */
2207*cdf0e10cSrcweir             if ((osl_getProfileName(SVERSION_LOCATION, SVERSION_NAME, Profile, sizeof(Profile))) &&
2208*cdf0e10cSrcweir                 (hProfile = osl_openProfile(Profile, osl_Profile_READLOCK)))
2209*cdf0e10cSrcweir             {
2210*cdf0e10cSrcweir                 pChr = &Product[strlen(Product)];
2211*cdf0e10cSrcweir 
2212*cdf0e10cSrcweir                 /* append build number */
2213*cdf0e10cSrcweir                 strcat(Product, "/");
2214*cdf0e10cSrcweir                 strcat(Product, BUILD_STR(SUPD));
2215*cdf0e10cSrcweir 
2216*cdf0e10cSrcweir                 osl_readProfileString(hProfile, SVERSION_SECTION, Product,
2217*cdf0e10cSrcweir                                       Buffer, sizeof(Buffer), "");
2218*cdf0e10cSrcweir 
2219*cdf0e10cSrcweir                 /* if not found, try it without build number */
2220*cdf0e10cSrcweir                 if (strlen(Buffer) <= 0)
2221*cdf0e10cSrcweir                 {
2222*cdf0e10cSrcweir                     *pChr = '\0';
2223*cdf0e10cSrcweir 
2224*cdf0e10cSrcweir                     osl_readProfileString(hProfile, SVERSION_SECTION, Product,
2225*cdf0e10cSrcweir                                           Buffer, sizeof(Buffer), "");
2226*cdf0e10cSrcweir 
2227*cdf0e10cSrcweir                     osl_closeProfile(hProfile);
2228*cdf0e10cSrcweir 
2229*cdf0e10cSrcweir                     /* if not found, try the fallback */
2230*cdf0e10cSrcweir                     if ((strlen(Buffer) <= 0) && (strcmp(SVERSION_LOCATION, SVERSION_FALLBACK) != 0))
2231*cdf0e10cSrcweir                     {
2232*cdf0e10cSrcweir                         if ((osl_getProfileName(SVERSION_FALLBACK, SVERSION_NAME, Profile, sizeof(Profile))) &&
2233*cdf0e10cSrcweir                             (hProfile = osl_openProfile(Profile, osl_Profile_READLOCK)))
2234*cdf0e10cSrcweir                         {
2235*cdf0e10cSrcweir                             /* prepare build number */
2236*cdf0e10cSrcweir                             *pChr = '/';
2237*cdf0e10cSrcweir 
2238*cdf0e10cSrcweir                             osl_readProfileString(hProfile, SVERSION_SECTION, Product,
2239*cdf0e10cSrcweir                                                   Buffer, sizeof(Buffer), "");
2240*cdf0e10cSrcweir 
2241*cdf0e10cSrcweir                             /* if not found, try it without build number */
2242*cdf0e10cSrcweir                             if (strlen(Buffer) <= 0)
2243*cdf0e10cSrcweir                             {
2244*cdf0e10cSrcweir                                 *pChr = '\0';
2245*cdf0e10cSrcweir 
2246*cdf0e10cSrcweir                                 osl_readProfileString(hProfile, SVERSION_SECTION, Product,
2247*cdf0e10cSrcweir                                                       Buffer, sizeof(Buffer), "");
2248*cdf0e10cSrcweir                             }
2249*cdf0e10cSrcweir 
2250*cdf0e10cSrcweir                             osl_closeProfile(hProfile);
2251*cdf0e10cSrcweir                         }
2252*cdf0e10cSrcweir                     }
2253*cdf0e10cSrcweir                 }
2254*cdf0e10cSrcweir                 else
2255*cdf0e10cSrcweir                     osl_closeProfile(hProfile);
2256*cdf0e10cSrcweir 
2257*cdf0e10cSrcweir                 if (strlen(Buffer) > 0)
2258*cdf0e10cSrcweir                 {
2259*cdf0e10cSrcweir                     strcpy(Path, Buffer);
2260*cdf0e10cSrcweir 
2261*cdf0e10cSrcweir                     /* build full path */
2262*cdf0e10cSrcweir                     if ((Path[strlen(Path) - 1] != '/') && (Path[strlen(Path) - 1] != '\\'))
2263*cdf0e10cSrcweir                     {
2264*cdf0e10cSrcweir                         if ((*pszPath != '/') && (*pszPath != '\\'))
2265*cdf0e10cSrcweir                             strcat(Path, "\\");
2266*cdf0e10cSrcweir                     }
2267*cdf0e10cSrcweir 
2268*cdf0e10cSrcweir                     pChr=&Path[strlen(pszPath)];
2269*cdf0e10cSrcweir                     if ( strlen(pszPath) > 0 )
2270*cdf0e10cSrcweir                     {
2271*cdf0e10cSrcweir                         strcat(Path, pszPath);
2272*cdf0e10cSrcweir                     }
2273*cdf0e10cSrcweir                     else
2274*cdf0e10cSrcweir                     {
2275*cdf0e10cSrcweir                         strcat(Path,SVERSION_USER);
2276*cdf0e10cSrcweir                         if ( access(Path, 0) < 0 )
2277*cdf0e10cSrcweir                         {
2278*cdf0e10cSrcweir                             *pChr='\0';
2279*cdf0e10cSrcweir                         }
2280*cdf0e10cSrcweir                     }
2281*cdf0e10cSrcweir                 }
2282*cdf0e10cSrcweir             }
2283*cdf0e10cSrcweir         }
2284*cdf0e10cSrcweir         else
2285*cdf0e10cSrcweir             /* remove appended filename */
2286*cdf0e10cSrcweir             *pChr = '\0';
2287*cdf0e10cSrcweir     }
2288*cdf0e10cSrcweir 
2289*cdf0e10cSrcweir     strcpy(pPath, Path);
2290*cdf0e10cSrcweir 
2291*cdf0e10cSrcweir     return (sal_True);
2292*cdf0e10cSrcweir }
2293*cdf0e10cSrcweir 
2294*cdf0e10cSrcweir #endif // 0 // YD
2295*cdf0e10cSrcweir 
2296