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