merged tag ooo/DEV300_m102
[LibreOffice.git] / sal / osl / os2 / profile.c
blobd9d166d0e091a5025b19f1ac3af2aa7e4bc2b30a
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 #include "system.h"
30 // YD #define min(a,b) (((a) < (b)) ? (a) : (b))
32 #include <osl/security.h>
33 #include <osl/diagnose.h>
34 #include <osl/profile.h>
35 #include <osl/process.h>
36 #include <osl/thread.h>
37 #include <osl/file.h>
39 #define LINES_INI 32
40 #define LINES_ADD 10
41 #define SECTIONS_INI 5
42 #define SECTIONS_ADD 3
43 #define ENTRIES_INI 5
44 #define ENTRIES_ADD 3
47 #define STR_INI_EXTENSION ".ini"
48 #define STR_INI_METAHOME "?~"
49 #define STR_INI_METASYS "?$"
50 #define STR_INI_METACFG "?^"
51 #define STR_INI_METAINS "?#"
53 #define STR_INI_BOOLYES "yes"
54 #define STR_INI_BOOLON "on"
55 #define STR_INI_BOOLONE "1"
56 #define STR_INI_BOOLNO "no"
57 #define STR_INI_BOOLOFF "off"
58 #define STR_INI_BOOLZERO "0"
60 #define FLG_USER 0x00FF
61 #define FLG_AUTOOPEN 0x0100
62 #define FLG_MODIFIED 0x0200
64 #define SVERSION_LOCATION STR_INI_METACFG
65 #define SVERSION_FALLBACK STR_INI_METASYS
66 #define SVERSION_NAME "sversion"
67 #define SVERSION_SECTION "Versions"
68 #define SVERSION_SOFFICE "StarOffice"
69 #define SVERSION_PROFILE "soffice.ini"
70 #define SVERSION_OPTION "userid:"
71 #define SVERSION_DIRS { "bin", "program" }
72 #define SVERSION_USER "user"
74 #define _BUILD_STR_(n) # n
75 #define BUILD_STR(n) _BUILD_STR_(n)
77 /* implemented in file.c */
78 extern oslFileError FileURLToPath( char *, size_t, rtl_uString* );
80 /*****************************************************************************/
81 /* Data Type Definition */
82 /*****************************************************************************/
84 typedef struct _osl_TStamp
86 FDATE m_Date;
87 FTIME m_Time;
88 } osl_TStamp;
90 typedef enum _osl_TLockMode
92 un_lock, read_lock, write_lock
93 } osl_TLockMode;
95 typedef struct _osl_TFile
97 HFILE m_Handle;
99 sal_Char* m_pReadPtr;
100 sal_Char m_ReadBuf[512];
101 sal_Char* m_pWritePtr;
102 sal_Char m_WriteBuf[512];
104 sal_Char* m_pReadPtr;
105 sal_Char m_ReadBuf[512];
106 /* sal_Char* m_pWritePtr; */
107 /* sal_Char m_WriteBuf[512]; */
108 sal_Char* m_pWriteBuf;
109 sal_uInt32 m_nWriteBufLen;
110 sal_uInt32 m_nWriteBufFree;
111 } osl_TFile;
113 typedef struct _osl_TProfileEntry
115 sal_uInt32 m_Line;
116 sal_uInt32 m_Offset;
117 sal_uInt32 m_Len;
118 } osl_TProfileEntry;
120 typedef struct _osl_TProfileSection
122 sal_uInt32 m_Line;
123 sal_uInt32 m_Offset;
124 sal_uInt32 m_Len;
125 sal_uInt32 m_NoEntries;
126 sal_uInt32 m_MaxEntries;
127 osl_TProfileEntry* m_Entries;
128 } osl_TProfileSection;
132 Profile-data structure hidden behind oslProfile:
134 typedef struct _osl_TProfileImpl
136 sal_uInt32 m_Flags;
137 osl_TFile* m_pFile;
138 osl_TStamp m_Stamp;
139 //sal_Char m_Filename[_MAX_PATH + 1];
140 sal_uInt32 m_NoLines;
141 sal_uInt32 m_MaxLines;
142 sal_uInt32 m_NoSections;
143 sal_uInt32 m_MaxSections;
144 sal_Char** m_Lines;
145 rtl_uString *m_strFileName;
146 osl_TProfileSection* m_Sections;
147 HINI m_hIni;
148 } osl_TProfileImpl;
151 /*****************************************************************************/
152 /* Static Module Function Declarations */
153 /*****************************************************************************/
155 //static osl_TFile* openFile(rtl_uString* pszFilename, sal_Bool bWriteable);
156 //static osl_TStamp closeFile(osl_TFile* pFile);
157 static osl_TFile* openFileImpl(rtl_uString * strFileName, oslProfileOption ProfileFlags );
158 static osl_TStamp closeFileImpl(osl_TFile* pFile);
159 static sal_Bool lockFile(const osl_TFile* pFile, osl_TLockMode eMode);
160 static sal_Bool rewindFile(osl_TFile* pFile, sal_Bool bTruncate);
161 static osl_TStamp getFileStamp(osl_TFile* pFile);
163 static sal_Bool getLine(osl_TFile* pFile, const sal_Char *pszLine, int MaxLen);
164 static sal_Bool putLine(osl_TFile* pFile, const sal_Char *pszLine);
165 static const sal_Char* stripBlanks(const sal_Char* String, sal_uInt32* pLen);
166 static const sal_Char* addLine(osl_TProfileImpl* pProfile, const sal_Char* Line);
167 static const sal_Char* insertLine(osl_TProfileImpl* pProfile, const sal_Char* Line, sal_uInt32 LineNo);
168 static void removeLine(osl_TProfileImpl* pProfile, sal_uInt32 LineNo);
169 static void setEntry(osl_TProfileImpl* pProfile, osl_TProfileSection* pSection,
170 sal_uInt32 NoEntry, sal_uInt32 Line,
171 const sal_Char* Entry, sal_uInt32 Len);
172 static sal_Bool addEntry(osl_TProfileImpl* pProfile, osl_TProfileSection *pSection,
173 int Line, const sal_Char* Entry, sal_uInt32 Len);
174 static void removeEntry(osl_TProfileSection *pSection, sal_uInt32 NoEntry);
175 static sal_Bool addSection(osl_TProfileImpl* pProfile, int Line, const sal_Char* Section, sal_uInt32 Len);
176 static void removeSection(osl_TProfileImpl* pProfile, osl_TProfileSection *pSection);
177 static osl_TProfileSection* findEntry(osl_TProfileImpl* pProfile, const sal_Char* Section,
178 const sal_Char* Entry, sal_uInt32 *pNoEntry);
179 static sal_Bool loadProfile(osl_TFile* pFile, osl_TProfileImpl* pProfile);
180 static sal_Bool storeProfile(osl_TFile* pFile, osl_TProfileImpl* pProfile, sal_Bool bCleanup);
181 static osl_TProfileImpl* acquireProfile(oslProfile Profile, sal_Bool bWriteable);
182 static sal_Bool releaseProfile(osl_TProfileImpl* pProfile);
183 static sal_Bool lookupProfile(const sal_Char *pszPath, const sal_Char *pszFile, sal_Char *pPath);
186 static sal_Bool SAL_CALL osl_getProfileName(rtl_uString* strPath, rtl_uString* strName, rtl_uString** strProfileName);
188 sal_Bool SAL_CALL osl_getFullPath(rtl_uString* pszFilename, sal_Char* pszPath, sal_uInt32 MaxLen)
190 return NO_ERROR == DosQueryPathInfo( (PCSZ)pszFilename, FIL_QUERYFULLNAME, pszPath, MaxLen);
195 /*****************************************************************************/
196 /* Exported Module Functions */
197 /*****************************************************************************/
199 oslProfile SAL_CALL osl_openProfile(rtl_uString *strProfileName, sal_uInt32 Flags)
201 osl_TFile* pFile;
202 osl_TProfileImpl* pProfile;
203 rtl_uString *FileName=NULL;
205 #ifdef TRACE_OSL_PROFILE
206 OSL_TRACE("In osl_openProfile\n");
207 #endif
208 OSL_VERIFY(strProfileName);
210 /* if (rtl_uString_getLength(strProfileName) == 0 )
212 OSL_VERIFY(osl_getProfileName(NULL, NULL, &FileName));
214 else
217 rtl_uString_assign(&FileName, strProfileName);
220 osl_getSystemPathFromFileURL(FileName, &FileName);
222 #ifdef DEBUG_OSL_PROFILE
223 Flags=osl_Profile_FLUSHWRITE;
225 // OSL_TRACE("opening '%s'\n",FileName);
226 if ( Flags == osl_Profile_DEFAULT )
228 OSL_TRACE("with osl_Profile_DEFAULT \n");
230 if ( Flags & osl_Profile_SYSTEM )
232 OSL_TRACE("with osl_Profile_SYSTEM \n");
234 if ( Flags & osl_Profile_READLOCK )
236 OSL_TRACE("with osl_Profile_READLOCK \n");
238 if ( Flags & osl_Profile_WRITELOCK )
240 OSL_TRACE("with osl_Profile_WRITELOCK \n");
242 /* if ( Flags & osl_Profile_READWRITE ) */
243 /* { */
244 /* OSL_TRACE("with osl_Profile_READWRITE \n"); */
245 /* } */
246 if ( Flags & osl_Profile_FLUSHWRITE )
248 OSL_TRACE("with osl_Profile_FLUSHWRITE \n");
250 #endif
252 if ((! (Flags & osl_Profile_SYSTEM)) &&
253 ((pFile = openFileImpl(FileName, (Flags & osl_Profile_WRITELOCK) ? sal_True : sal_False)) == NULL))
255 #ifdef TRACE_OSL_PROFILE
256 OSL_TRACE("Out osl_openProfile [not opened]\n");
257 #endif
258 if( FileName)
259 rtl_uString_release( FileName);
261 return (NULL);
264 pProfile = (osl_TProfileImpl*)calloc(1, sizeof(osl_TProfileImpl));
266 pProfile->m_Flags = Flags & FLG_USER;
267 osl_getSystemPathFromFileURL(strProfileName, &pProfile->m_strFileName);
268 // rtl_uString_assign(&pProfile->m_strFileName, strProfileName);
270 if (Flags & (osl_Profile_READLOCK | osl_Profile_WRITELOCK))
271 pProfile->m_pFile = pFile;
273 pProfile->m_Stamp = getFileStamp(pFile);
275 loadProfile(pFile, pProfile);
277 if (pProfile->m_pFile == NULL)
278 closeFileImpl(pFile);
280 #ifdef TRACE_OSL_PROFILE
281 OSL_TRACE("Out osl_openProfile [ok]\n");
282 #endif
283 if( FileName)
284 rtl_uString_release( FileName);
286 return pProfile;
289 sal_Bool SAL_CALL osl_closeProfile(oslProfile Profile)
291 osl_TProfileImpl* pProfile = (osl_TProfileImpl*)Profile;
293 #ifdef TRACE_OSL_PROFILE
294 OSL_TRACE("In osl_closeProfile\n");
295 #endif
297 if ( pProfile == 0 )
299 #ifdef TRACE_OSL_PROFILE
300 OSL_TRACE("Out osl_closeProfile [profile==0]\n");
301 #endif
302 return sal_False;
305 if (! (pProfile->m_Flags & osl_Profile_SYSTEM))
307 pProfile = acquireProfile(Profile,sal_True);
309 if ( pProfile != 0 )
311 if ( !( pProfile->m_Flags & osl_Profile_READLOCK ) && ( pProfile->m_Flags & FLG_MODIFIED ) )
313 /* if (pProfile->m_pFile == NULL) */
314 /* pProfile->m_pFile = openFileImpl(pProfile->m_Filename, sal_True); */
316 storeProfile(pProfile->m_pFile, pProfile, sal_False);
319 else
321 pProfile = acquireProfile(Profile,sal_False);
324 if ( pProfile == 0 )
326 #ifdef TRACE_OSL_PROFILE
327 OSL_TRACE("Out osl_closeProfile [pProfile==0]\n");
328 #endif
329 return sal_False;
332 if (pProfile->m_pFile != NULL)
333 closeFileImpl(pProfile->m_pFile);
336 pProfile->m_pFile = NULL;
337 rtl_uString_release(pProfile->m_strFileName);
338 pProfile->m_strFileName = NULL;
340 /* release whole profile data types memory */
341 if ( pProfile->m_NoLines > 0)
343 unsigned int index=0;
344 if ( pProfile->m_Lines != 0 )
346 for ( index = 0 ; index < pProfile->m_NoLines ; ++index)
348 if ( pProfile->m_Lines[index] != 0 )
350 free(pProfile->m_Lines[index]);
353 free(pProfile->m_Lines);
355 if ( pProfile->m_Sections != 0 )
357 /*osl_TProfileSection* pSections=pProfile->m_Sections;*/
358 for ( index = 0 ; index < pProfile->m_NoSections ; ++index )
360 if ( pProfile->m_Sections[index].m_Entries != 0 )
362 free(pProfile->m_Sections[index].m_Entries);
365 free(pProfile->m_Sections);
369 free(pProfile);
371 #ifdef TRACE_OSL_PROFILE
372 OSL_TRACE("Out osl_closeProfile [ok]\n");
373 #endif
374 return (sal_True);
377 sal_Bool SAL_CALL osl_flushProfile(oslProfile Profile)
379 osl_TProfileImpl* pProfile = (osl_TProfileImpl*) Profile;
380 osl_TFile* pFile;
381 sal_Bool bRet = sal_False;
383 #ifdef TRACE_OSL_PROFILE
384 OSL_TRACE("In osl_flushProfile()\n");
385 #endif
387 if ( pProfile == 0 )
389 #ifdef TRACE_OSL_PROFILE
390 OSL_TRACE("Out osl_flushProfile() [pProfile == 0]\n");
391 #endif
392 return sal_False;
395 pFile = pProfile->m_pFile;
396 if ( !( pFile != 0 && pFile->m_Handle >= 0 ) )
398 #ifdef TRACE_OSL_PROFILE
399 OSL_TRACE("Out osl_flushProfile() [invalid file]\n");
400 #endif
401 return sal_False;
404 if ( pProfile->m_Flags & FLG_MODIFIED )
406 #ifdef DEBUG_OSL_PROFILE
407 OSL_TRACE("swapping to storeprofile\n");
408 #endif
409 bRet = storeProfile(pFile,pProfile,sal_False);
412 #ifdef TRACE_OSL_PROFILE
413 OSL_TRACE("Out osl_flushProfile() [ok]\n");
414 #endif
415 return bRet;
418 sal_Bool SAL_CALL osl_readProfileString(oslProfile Profile,
419 const sal_Char* pszSection, const sal_Char* pszEntry,
420 sal_Char* pszString, sal_uInt32 MaxLen,
421 const sal_Char* pszDefault)
423 sal_uInt32 NoEntry;
424 const sal_Char* pStr = 0;
425 osl_TProfileSection* pSec;
426 osl_TProfileImpl* pProfile = 0;
429 #ifdef TRACE_OSL_PROFILE
430 OSL_TRACE("In osl_readProfileString\n");
431 #endif
433 pProfile = acquireProfile(Profile, sal_False);
435 if (pProfile == NULL)
437 #ifdef TRACE_OSL_PROFILE
438 OSL_TRACE("Out osl_readProfileString [pProfile==0]\n");
439 #endif
442 return (sal_False);
446 if (! (pProfile->m_Flags & osl_Profile_SYSTEM))
448 if (((pSec = findEntry(pProfile, pszSection, pszEntry, &NoEntry)) != NULL) &&
449 (NoEntry < pSec->m_NoEntries) &&
450 ((pStr = strchr(pProfile->m_Lines[pSec->m_Entries[NoEntry].m_Line],
451 '=')) != NULL))
452 pStr++;
453 else
454 pStr = pszDefault;
456 if ( pStr != 0 )
458 pStr = stripBlanks(pStr, NULL);
459 MaxLen = (MaxLen - 1 < strlen(pStr)) ? (MaxLen - 1) : strlen(pStr);
460 pStr = stripBlanks(pStr, &MaxLen);
461 strncpy(pszString, pStr, MaxLen);
462 pszString[MaxLen] = '\0';
465 else
466 PrfQueryProfileString(pProfile->m_hIni, (PCSZ)pszSection,
467 (PCSZ)pszEntry, (PCSZ)pszDefault,
468 pszString, MaxLen);
470 releaseProfile(pProfile);
472 if ( pStr == 0 )
474 #ifdef TRACE_OSL_PROFILE
475 OSL_TRACE("Out osl_readProfileString [pStr==0]\n");
476 #endif
479 return (sal_False);
482 #ifdef TRACE_OSL_PROFILE
483 OSL_TRACE("Out osl_readProfileString [ok]\n");
484 #endif
486 return (sal_True);
490 sal_Bool SAL_CALL osl_readProfileBool(oslProfile Profile,
491 const sal_Char* pszSection, const sal_Char* pszEntry,
492 sal_Bool Default)
494 sal_Char Line[32];
496 #ifdef TRACE_OSL_PROFILE
497 OSL_TRACE("In osl_readProfileBool\n");
498 #endif
500 if (osl_readProfileString(Profile, pszSection, pszEntry, Line, sizeof(Line), ""))
502 if ((stricmp(Line, STR_INI_BOOLYES) == 0) ||
503 (stricmp(Line, STR_INI_BOOLON) == 0) ||
504 (stricmp(Line, STR_INI_BOOLONE) == 0))
505 Default = sal_True;
506 else
507 if ((stricmp(Line, STR_INI_BOOLNO) == 0) ||
508 (stricmp(Line, STR_INI_BOOLOFF) == 0) ||
509 (stricmp(Line, STR_INI_BOOLZERO) == 0))
510 Default = sal_False;
513 #ifdef TRACE_OSL_PROFILE
514 OSL_TRACE("Out osl_readProfileBool [ok]\n");
515 #endif
517 return (Default);
521 sal_uInt32 SAL_CALL osl_readProfileIdent(oslProfile Profile,
522 const sal_Char* pszSection, const sal_Char* pszEntry,
523 sal_uInt32 FirstId, const sal_Char* Strings[],
524 sal_uInt32 Default)
526 sal_uInt32 i;
527 sal_Char Line[256];
529 #ifdef TRACE_OSL_PROFILE
530 OSL_TRACE("In osl_readProfileIdent\n");
531 #endif
533 if (osl_readProfileString(Profile, pszSection, pszEntry, Line, sizeof(Line), ""))
535 i = 0;
536 while (Strings[i] != NULL)
538 if (stricmp(Line, Strings[i]) == 0)
540 Default = i + FirstId;
541 break;
543 i++;
547 #ifdef TRACE_OSL_PROFILE
548 OSL_TRACE("Out osl_readProfileIdent [ok]\n");
549 #endif
550 return (Default);
554 sal_Bool SAL_CALL osl_writeProfileString(oslProfile Profile,
555 const sal_Char* pszSection, const sal_Char* pszEntry,
556 const sal_Char* pszString)
558 sal_uInt32 i;
559 sal_Bool bRet = sal_False;
560 sal_uInt32 NoEntry;
561 const sal_Char* pStr;
562 sal_Char Line[4096];
563 osl_TProfileSection* pSec;
564 osl_TProfileImpl* pProfile = 0;
566 #ifdef TRACE_OSL_PROFILE
567 OSL_TRACE("In osl_writeProfileString\n");
568 #endif
570 pProfile = acquireProfile(Profile, sal_True);
572 if (pProfile == NULL)
574 #ifdef TRACE_OSL_PROFILE
575 OSL_TRACE("Out osl_writeProfileString [pProfile==0]\n");
576 #endif
577 return (sal_False);
581 if (! (pProfile->m_Flags & osl_Profile_SYSTEM))
583 if ((pSec = findEntry(pProfile, pszSection, pszEntry, &NoEntry)) == NULL)
585 Line[0] = '\0';
586 addLine(pProfile, Line);
588 Line[0] = '[';
589 strcpy(&Line[1], pszSection);
590 Line[1 + strlen(pszSection)] = ']';
591 Line[2 + strlen(pszSection)] = '\0';
593 if (((pStr = addLine(pProfile, Line)) == NULL) ||
594 (! addSection(pProfile, pProfile->m_NoLines - 1, &pStr[1], strlen(pszSection))))
596 releaseProfile(pProfile);
597 #ifdef TRACE_OSL_PROFILE
598 OSL_TRACE("Out osl_writeProfileString [not added]\n");
599 #endif
600 return (sal_False);
603 pSec = &pProfile->m_Sections[pProfile->m_NoSections - 1];
604 NoEntry = pSec->m_NoEntries;
607 Line[0] = '\0';
608 strcpy(&Line[0], pszEntry);
609 Line[0 + strlen(pszEntry)] = '=';
610 strcpy(&Line[1 + strlen(pszEntry)], pszString);
612 if (NoEntry >= pSec->m_NoEntries)
614 if (pSec->m_NoEntries > 0)
615 i = pSec->m_Entries[pSec->m_NoEntries - 1].m_Line + 1;
616 else
617 i = pSec->m_Line + 1;
619 if (((pStr = insertLine(pProfile, Line, i)) == NULL) ||
620 (! addEntry(pProfile, pSec, i, pStr, strlen(pszEntry))))
622 releaseProfile(pProfile);
623 #ifdef TRACE_OSL_PROFILE
624 OSL_TRACE("Out osl_writeProfileString [not inserted]\n");
625 #endif
626 return (sal_False);
629 pProfile->m_Flags |= FLG_MODIFIED;
631 else
633 i = pSec->m_Entries[NoEntry].m_Line;
634 free(pProfile->m_Lines[i]);
635 pProfile->m_Lines[i] = strdup(Line);
636 setEntry(pProfile, pSec, NoEntry, i, pProfile->m_Lines[i], strlen(pszEntry));
638 pProfile->m_Flags |= FLG_MODIFIED;
641 else
642 PrfWriteProfileString(pProfile->m_hIni, (PCSZ)pszSection,
643 (PCSZ)pszEntry, (PCSZ)pszString);
645 bRet = releaseProfile(pProfile);
646 #ifdef TRACE_OSL_PROFILE
647 OSL_TRACE("Out osl_writeProfileString [ok]\n");
648 #endif
649 return bRet;
653 sal_Bool SAL_CALL osl_writeProfileBool(oslProfile Profile,
654 const sal_Char* pszSection, const sal_Char* pszEntry,
655 sal_Bool Value)
657 sal_Bool bRet = sal_False;
659 #ifdef TRACE_OSL_PROFILE
660 OSL_TRACE("In osl_writeProfileBool\n");
661 #endif
663 if (Value)
664 bRet=osl_writeProfileString(Profile, pszSection, pszEntry, STR_INI_BOOLONE);
665 else
666 bRet=osl_writeProfileString(Profile, pszSection, pszEntry, STR_INI_BOOLZERO);
668 #ifdef TRACE_OSL_PROFILE
669 OSL_TRACE("Out osl_writeProfileBool [ok]\n");
670 #endif
672 return bRet;
676 sal_Bool SAL_CALL osl_writeProfileIdent(oslProfile Profile,
677 const sal_Char* pszSection, const sal_Char* pszEntry,
678 sal_uInt32 FirstId, const sal_Char* Strings[],
679 sal_uInt32 Value)
681 int i, n;
682 sal_Bool bRet = sal_False;
684 #ifdef TRACE_OSL_PROFILE
685 OSL_TRACE("In osl_writeProfileIdent\n");
686 #endif
688 for (n = 0; Strings[n] != NULL; n++);
690 if ((i = Value - FirstId) >= n)
691 bRet=sal_False;
692 else
693 bRet=osl_writeProfileString(Profile, pszSection, pszEntry, Strings[i]);
695 #ifdef TRACE_OSL_PROFILE
696 OSL_TRACE("Out osl_writeProfileIdent\n");
697 #endif
698 return bRet;
702 sal_Bool SAL_CALL osl_removeProfileEntry(oslProfile Profile,
703 const sal_Char *pszSection, const sal_Char *pszEntry)
705 sal_uInt32 NoEntry;
706 osl_TProfileSection* pSec;
707 osl_TProfileImpl* pProfile = 0;
708 sal_Bool bRet = sal_False;
710 #ifdef TRACE_OSL_PROFILE
711 OSL_TRACE("In osl_removeProfileEntry\n");
712 #endif
714 pProfile = acquireProfile(Profile, sal_True);
716 if (pProfile == NULL)
718 #ifdef TRACE_OSL_PROFILE
719 OSL_TRACE("Out osl_removeProfileEntry [pProfile==0]\n");
720 #endif
723 return (sal_False);
727 if (! (pProfile->m_Flags & osl_Profile_SYSTEM))
729 if (((pSec = findEntry(pProfile, pszSection, pszEntry, &NoEntry)) != NULL) &&
730 (NoEntry < pSec->m_NoEntries))
732 removeLine(pProfile, pSec->m_Entries[NoEntry].m_Line);
733 removeEntry(pSec, NoEntry);
734 if (pSec->m_NoEntries == 0)
736 removeLine(pProfile, pSec->m_Line);
738 /* remove any empty separation line */
739 if ((pSec->m_Line > 0) && (pProfile->m_Lines[pSec->m_Line - 1][0] == '\0'))
740 removeLine(pProfile, pSec->m_Line - 1);
742 removeSection(pProfile, pSec);
745 pProfile->m_Flags |= FLG_MODIFIED;
748 else
749 PrfWriteProfileString(pProfile->m_hIni, (PCSZ)pszSection, (PCSZ)pszEntry, NULL);
751 bRet = releaseProfile(pProfile);
752 #ifdef TRACE_OSL_PROFILE
753 OSL_TRACE("Out osl_removeProfileEntry [ok]\n");
754 #endif
755 return bRet;
759 sal_uInt32 SAL_CALL osl_getProfileSectionEntries(oslProfile Profile, const sal_Char *pszSection,
760 sal_Char* pszBuffer, sal_uInt32 MaxLen)
762 sal_uInt32 i, n = 0;
763 sal_uInt32 NoEntry;
764 osl_TProfileSection* pSec;
765 osl_TProfileImpl* pProfile = 0;
767 #ifdef TRACE_OSL_PROFILE
768 OSL_TRACE("In osl_getProfileSectionEntries\n");
769 #endif
771 pProfile = acquireProfile(Profile, sal_False);
773 if (pProfile == NULL)
775 #ifdef TRACE_OSL_PROFILE
776 OSL_TRACE("Out osl_getProfileSectionEntries [pProfile=0]\n");
777 #endif
780 return (0);
784 if (! (pProfile->m_Flags & osl_Profile_SYSTEM))
786 if ((pSec = findEntry(pProfile, pszSection, "", &NoEntry)) != NULL)
788 if (MaxLen != 0)
790 for (i = 0; i < pSec->m_NoEntries; i++)
792 if ((n + pSec->m_Entries[i].m_Len + 1) < MaxLen)
794 strncpy(&pszBuffer[n], &pProfile->m_Lines[pSec->m_Entries[i].m_Line]
795 [pSec->m_Entries[i].m_Offset], pSec->m_Entries[i].m_Len);
796 n += pSec->m_Entries[i].m_Len;
797 pszBuffer[n++] = '\0';
799 else
800 break;
804 pszBuffer[n++] = '\0';
806 else
808 for (i = 0; i < pSec->m_NoEntries; i++)
809 n += pSec->m_Entries[i].m_Len + 1;
811 n += 1;
814 else
815 n = 0;
817 else
818 n = PrfQueryProfileString(pProfile->m_hIni, (PCSZ)pszSection, NULL, NULL,
819 pszBuffer, MaxLen );
821 releaseProfile(pProfile);
823 #ifdef TRACE_OSL_PROFILE
824 OSL_TRACE("Out osl_getProfileSectionEntries [ok]\n");
825 #endif
827 return (n);
830 sal_uInt32 SAL_CALL osl_getProfileSections(oslProfile Profile, sal_Char* pszBuffer, sal_uInt32 MaxLen)
832 sal_uInt32 i, n = 0;
833 osl_TProfileSection* pSec;
834 osl_TProfileImpl* pProfile = acquireProfile(Profile, sal_False);
836 if (pProfile == NULL)
837 return (0);
839 if (! (pProfile->m_Flags & osl_Profile_SYSTEM))
841 if (MaxLen != 0)
843 for (i = 0; i < pProfile->m_NoSections; i++)
845 pSec = &pProfile->m_Sections[i];
847 if ((n + pSec->m_Len + 1) < MaxLen)
849 strncpy(&pszBuffer[n], &pProfile->m_Lines[pSec->m_Line][pSec->m_Offset],
850 pSec->m_Len);
851 n += pSec->m_Len;
852 pszBuffer[n++] = '\0';
854 else
855 break;
858 pszBuffer[n++] = '\0';
860 else
862 for (i = 0; i < pProfile->m_NoSections; i++)
863 n += pProfile->m_Sections[i].m_Len + 1;
865 n += 1;
868 else
869 n = PrfQueryProfileString(pProfile->m_hIni, NULL, NULL, NULL,
870 pszBuffer, MaxLen );
872 releaseProfile(pProfile);
874 return (n);
877 #if 0 // YD
878 sal_Bool SAL_CALL osl_getProfileName(rtl_uString* strPath, rtl_uString* strName, rtl_uString** strProfileName)
880 sal_Bool bFailed;
881 sal_Char File[_MAX_PATH];
882 sal_Char Path[_MAX_PATH];
883 sal_uInt32 nFileLen;
884 sal_uInt32 nPathLen = 0;
886 rtl_uString * strTmp = NULL;
887 oslFileError nError;
889 /* build file name */
890 if (strName && strName->length)
892 if(strName->length >= _MAX_PATH)
893 return sal_False;
895 strcpy(File, (char*)strName->buffer);
896 nFileLen = strName->length;
898 if (rtl_ustr_indexOfChar( File, L'.' ) == -1)
900 if (nFileLen + strlen(STR_INI_EXTENSION) >= _MAX_PATH)
901 return sal_False;
903 /* add default extension */
904 strcpy(File + nFileLen, STR_INI_EXTENSION);
905 nFileLen += strlen(STR_INI_EXTENSION);
908 else
910 rtl_uString *strProgName = NULL;
911 sal_Unicode *pProgName;
912 sal_Int32 nOffset = 0;
913 sal_Int32 nLen;
914 sal_Int32 nPos;
916 if (osl_getExecutableFile(&strProgName) != osl_Process_E_None)
917 return sal_False;
919 /* remove path and extension from filename */
920 pProgName = strProgName->buffer;
921 nLen = strProgName->length ;
923 if ((nPos = rtl_ustr_lastIndexOfChar( pProgName, L'/' )) != -1)
924 nOffset = nPos + 1;
925 else if ((nPos = rtl_ustr_lastIndexOfChar( pProgName, L':' )) != -1)
926 nOffset = nPos + 1;
928 if ((nPos = rtl_ustr_lastIndexOfChar( pProgName, L'.' )) != -1 )
929 nLen -= 4;
931 if ((nFileLen = nLen - nOffset) >= _MAX_PATH)
932 return sal_False;
934 strncpy(File, pProgName + nOffset, nFileLen);
936 if (nFileLen + strlen(STR_INI_EXTENSION) >= _MAX_PATH)
937 return sal_False;
939 /* add default extension */
940 strcpy(File + nFileLen, STR_INI_EXTENSION);
941 nFileLen += strlen(STR_INI_EXTENSION);
943 rtl_uString_release( strProgName );
946 if (File[0] == 0)
947 return sal_False;
949 /* build directory path */
950 if (strPath && strPath->length)
952 sal_Unicode *pPath = rtl_uString_getStr(strPath);
953 sal_Int32 nLen = rtl_uString_getLength(strPath);
955 if ((rtl_ustr_ascii_compare_WithLength(pPath, RTL_CONSTASCII_LENGTH(STR_INI_METAHOME) , STR_INI_METAHOME) == 0) &&
956 ((nLen == RTL_CONSTASCII_LENGTH(STR_INI_METAHOME)) || (pPath[RTL_CONSTASCII_LENGTH(STR_INI_METAHOME)] == '/')))
958 rtl_uString * strHome = NULL;
959 oslSecurity security = osl_getCurrentSecurity();
961 bFailed = ! osl_getHomeDir(security, &strHome);
962 osl_freeSecurityHandle(security);
964 if (bFailed) return (sal_False);
966 if (strHome->length >= _MAX_PATH)
967 return sal_False;
969 strcpy( Path, strHome->buffer);
970 nPathLen = strHome->length;
972 if (nLen > RTL_CONSTASCII_LENGTH(STR_INI_METAHOME))
974 pPath += RTL_CONSTASCII_LENGTH(STR_INI_METAHOME);
975 nLen -= RTL_CONSTASCII_LENGTH(STR_INI_METAHOME);
977 if (nLen + nPathLen >= _MAX_PATH)
978 return sal_False;
980 strcpy(Path + nPathLen, pPath);
981 nPathLen += nLen;
984 rtl_uString_release(strHome);
987 else if ((rtl_ustr_ascii_compare_WithLength(pPath, RTL_CONSTASCII_LENGTH(STR_INI_METACFG), STR_INI_METACFG) == 0) &&
988 ((nLen == RTL_CONSTASCII_LENGTH(STR_INI_METACFG)) || (pPath[RTL_CONSTASCII_LENGTH(STR_INI_METACFG)] == '/')))
990 rtl_uString * strConfig = NULL;
991 oslSecurity security = osl_getCurrentSecurity();
993 bFailed = ! osl_getConfigDir(security, &strConfig);
994 osl_freeSecurityHandle(security);
996 if (bFailed) return (sal_False);
998 if (strConfig->length >= _MAX_PATH)
999 return sal_False;
1001 strcpy( Path, strConfig->buffer);
1002 nPathLen = strConfig->length;
1004 if (nLen > RTL_CONSTASCII_LENGTH(STR_INI_METACFG))
1006 pPath += RTL_CONSTASCII_LENGTH(STR_INI_METACFG);
1007 nLen -= RTL_CONSTASCII_LENGTH(STR_INI_METACFG);
1009 if (nLen + nPathLen >= _MAX_PATH)
1010 return sal_False;
1012 strcpy(Path + nPathLen, pPath);
1013 nPathLen += nLen;
1016 rtl_uString_release(strConfig);
1019 else if ((rtl_ustr_ascii_compare_WithLength(pPath, RTL_CONSTASCII_LENGTH(STR_INI_METASYS), STR_INI_METASYS) == 0) &&
1020 ((nLen == RTL_CONSTASCII_LENGTH(STR_INI_METASYS)) || (pPath[RTL_CONSTASCII_LENGTH(STR_INI_METASYS)] == '/')))
1022 if (((nPathLen = GetWindowsDirectoryW(Path, _MAX_PATH)) == 0) || (nPathLen >= _MAX_PATH))
1023 return (sal_False);
1025 if (nLen > RTL_CONSTASCII_LENGTH(STR_INI_METASYS))
1027 pPath += RTL_CONSTASCII_LENGTH(STR_INI_METASYS);
1028 nLen -= RTL_CONSTASCII_LENGTH(STR_INI_METASYS);
1030 if (nLen + nPathLen >= MAX_PATH)
1031 return sal_False;
1033 strcpy(Path + nPathLen, pPath);
1034 nPathLen += nLen;
1038 else if ((rtl_ustr_ascii_compare_WithLength(pPath, RTL_CONSTASCII_LENGTH(STR_INI_METAINS), STR_INI_METAINS) == 0) &&
1039 ((nLen == RTL_CONSTASCII_LENGTH(STR_INI_METAINS)) || (pPath[RTL_CONSTASCII_LENGTH(STR_INI_METAINS)] == '/') ||
1040 (pPath[RTL_CONSTASCII_LENGTH(STR_INI_METAINS)] == '"') ) )
1042 if (! lookupProfile(pPath + RTL_CONSTASCII_LENGTH(STR_INI_METAINS), File, Path))
1043 return (sal_False);
1045 nPathLen = strlen(Path);
1048 else if(nLen < MAX_PATH)
1050 strcpy(Path, pPath);
1051 nPathLen = strlen(Path);
1053 else
1054 return sal_False;
1056 else
1058 rtl_uString * strConfigDir = NULL;
1059 oslSecurity security = osl_getCurrentSecurity();
1061 bFailed = ! osl_getConfigDir(security, &strConfigDir);
1062 osl_freeSecurityHandle(security);
1064 if (bFailed) return (sal_False);
1065 if (strConfigDir->length >= MAX_PATH)
1066 return sal_False;
1068 strcpy(Path, strConfigDir->buffer);
1069 nPathLen = strConfigDir->length;
1072 if (nPathLen && (Path[nPathLen - 1] != L'/') && (Path[nPathLen - 1] != L'\\'))
1074 Path[nPathLen++] = L'\\';
1075 Path[nPathLen] = 0;
1078 if (nPathLen + nFileLen >= MAX_PATH)
1079 return sal_False;
1081 /* append file name */
1082 strcpy(Path + nPathLen, File);
1083 nPathLen += nFileLen;
1085 /* copy filename */
1086 rtl_uString_newFromStr_WithLength(&strTmp, Path, nPathLen);
1087 nError = osl_getFileURLFromSystemPath(strTmp, strProfileName);
1088 rtl_uString_release(strTmp);
1090 return nError == osl_File_E_None;
1092 #endif // 0 // YD
1095 /*****************************************************************************/
1096 /* Static Module Functions */
1097 /*****************************************************************************/
1099 static osl_TStamp getFileStamp(osl_TFile* pFile)
1101 osl_TStamp FileTime;
1102 FILESTATUS3 FileStatus;
1103 sal_uInt32 Bytes;
1105 Bytes = sizeof( FILESTATUS3 );
1106 if ( (!pFile->m_Handle) ||
1107 DosQueryFileInfo(pFile->m_Handle, FIL_STANDARD, &FileStatus, Bytes))
1108 memset(&FileTime, 0, sizeof(FileTime));
1109 else
1111 FileTime.m_Date = FileStatus.fdateLastWrite;
1112 FileTime.m_Time = FileStatus.ftimeLastWrite;
1115 return (FileTime);
1118 static sal_Bool lockFile(const osl_TFile* pFile, osl_TLockMode eMode)
1120 sal_uInt32 status = 1;
1121 FILELOCK Lock;
1123 if (!pFile->m_Handle)
1124 return (sal_False);
1126 Lock.lOffset = 0;
1127 Lock.lRange = 0xFFFFFFFF;
1129 switch (eMode)
1131 case un_lock:
1132 status = DosSetFileLocks(pFile->m_Handle, &Lock, NULL, 1000, 0);
1133 break;
1135 case read_lock:
1136 status = DosSetFileLocks(pFile->m_Handle, NULL, &Lock, 1000, 1);
1137 break;
1139 case write_lock:
1140 status = DosSetFileLocks(pFile->m_Handle, NULL, &Lock, 1000, 0);
1141 break;
1144 return (status == 0);
1147 //static osl_TFile* openFile(rtl_uString* pszFilename, sal_Bool bWriteable)
1148 static osl_TFile* openFileImpl(rtl_uString *ustrFileName, oslProfileOption ProfileFlags )
1150 sal_uInt32 action;
1151 APIRET rc;
1152 osl_TFile* pFile = (osl_TFile*)calloc(1, sizeof(osl_TFile));
1154 ULONG attributes;
1155 ULONG flags;
1156 ULONG mode;
1157 sal_Bool bWriteable = sal_False;
1158 rtl_String* strFileName=0;
1159 sal_Char* pszFileName=0;
1161 /* check parameters */
1162 OSL_ASSERT( ustrFileName );
1164 rtl_uString2String( &strFileName,
1165 rtl_uString_getStr(ustrFileName),
1166 rtl_uString_getLength(ustrFileName),
1167 osl_getThreadTextEncoding(),
1168 OUSTRING_TO_OSTRING_CVTFLAGS );
1169 pszFileName = rtl_string_getStr(strFileName);
1171 /* if ( ProfileFlags & ( osl_Profile_WRITELOCK | osl_Profile_FLUSHWRITE | osl_Profile_READWRITE ) )*/
1172 if ( ProfileFlags & ( osl_Profile_WRITELOCK | osl_Profile_FLUSHWRITE ) )
1174 #ifdef DEBUG_OSL_PROFILE
1175 OSL_TRACE("setting bWriteable to TRUE\n");
1176 #endif
1177 bWriteable=sal_True;
1180 if (bWriteable)
1182 flags = FILE_NORMAL | FILE_ARCHIVED;
1183 attributes = OPEN_ACTION_CREATE_IF_NEW | OPEN_ACTION_OPEN_IF_EXISTS;
1184 mode = OPEN_SHARE_DENYNONE | OPEN_ACCESS_READWRITE;
1186 else
1188 flags = FILE_NORMAL;
1189 attributes = OPEN_ACTION_FAIL_IF_NEW | OPEN_ACTION_OPEN_IF_EXISTS;
1190 mode = OPEN_SHARE_DENYNONE | OPEN_ACCESS_READONLY;
1193 if (rc = DosOpen((PCSZ)pszFileName, &pFile->m_Handle, &action, 0, flags, attributes, mode, NULL))
1195 if (rc == ERROR_TOO_MANY_OPEN_FILES)
1197 LONG fhToAdd = 10;
1198 ULONG fhOld = 0;
1199 rc = DosSetRelMaxFH(&fhToAdd, &fhOld);
1200 rc = DosOpen((PCSZ)pszFileName, &pFile->m_Handle, &action, 0, flags, attributes, mode, NULL);
1204 if ( (rc != NO_ERROR) && bWriteable)
1206 free(pFile);
1207 rtl_string_release(strFileName);
1208 return (NULL);
1211 rtl_string_release(strFileName);
1213 pFile->m_pWriteBuf=0;
1214 pFile->m_nWriteBufFree=0;
1215 pFile->m_nWriteBufLen=0;
1217 if ( ProfileFlags & (osl_Profile_WRITELOCK | osl_Profile_READLOCK ) )
1219 #ifdef DEBUG_OSL_PROFILE
1220 OSL_TRACE("locking '%s' file\n",pszFilename);
1221 #endif
1223 lockFile(pFile, bWriteable ? write_lock : read_lock);
1226 /* mfe: new WriteBuf obsolete */
1227 /* pFile->m_pWritePtr = pFile->m_Buf;*/
1228 /* pFile->m_pReadPtr = pFile->m_ReadBuf + sizeof(pFile->m_ReadBuf);*/
1230 return (pFile);
1233 //static osl_TStamp closeFile(osl_TFile* pFile)
1234 static osl_TStamp closeFileImpl(osl_TFile* pFile)
1236 osl_TStamp stamp = {0, 0};
1238 if ( pFile == 0 )
1240 return stamp;
1243 if (pFile->m_Handle)
1245 /* mfe: new WriteBuf obsolete */
1246 /* we just closing the file here, DO NOT write, it has to be handled in higher levels */
1247 //if (pFile->m_pWritePtr > pFile->m_WriteBuf)
1249 // sal_uInt32 Bytes;
1251 // DosWrite(pFile->m_Handle, pFile->m_WriteBuf,
1252 // pFile->m_pWritePtr - pFile->m_WriteBuf,
1253 // &Bytes);
1256 stamp = getFileStamp(pFile);
1258 lockFile(pFile, un_lock);
1260 DosClose(pFile->m_Handle);
1263 if ( pFile->m_pWriteBuf != 0 )
1265 free(pFile->m_pWriteBuf);
1268 free(pFile);
1270 return(stamp);
1273 static sal_Bool rewindFile(osl_TFile* pFile, sal_Bool bTruncate)
1275 if (pFile->m_Handle)
1277 sal_uInt32 Position;
1279 /* mfe: new WriteBuf obsolete */
1280 /* we just closing the file here, DO NOT write, it has to be handled in higher levels */
1281 /* if (pFile->m_pWritePtr > pFile->m_WriteBuf)
1283 sal_uInt32 Bytes;
1285 DosWrite(pFile->m_Handle, pFile->m_WriteBuf,
1286 pFile->m_pWritePtr - pFile->m_WriteBuf,
1287 &Bytes);
1289 pFile->m_pWritePtr = pFile->m_WriteBuf;
1290 } */
1292 pFile->m_pReadPtr = pFile->m_ReadBuf + sizeof(pFile->m_ReadBuf);
1294 DosSetFilePtr(pFile->m_Handle, 0, FILE_BEGIN, &Position);
1296 if (bTruncate)
1297 DosSetFileSize(pFile->m_Handle, 0);
1300 return (sal_True);
1303 static sal_Bool getLine(osl_TFile* pFile, const sal_Char *pszLine, int MaxLen)
1305 int Free, Bytes;
1306 sal_Char* pChr;
1307 sal_Char* pLine = (sal_Char *)pszLine;
1308 sal_uInt32 Max;
1310 if (pFile->m_Handle == 0)
1311 return (sal_False);
1313 MaxLen -= 1;
1317 Bytes = sizeof(pFile->m_ReadBuf) - (pFile->m_pReadPtr - pFile->m_ReadBuf);
1319 if (Bytes <= 1)
1321 /* refill buffer */
1322 memcpy(pFile->m_ReadBuf, pFile->m_pReadPtr, Bytes);
1323 pFile->m_pReadPtr = pFile->m_ReadBuf;
1325 Free = sizeof(pFile->m_ReadBuf) - Bytes;
1327 if (DosRead(pFile->m_Handle, &pFile->m_ReadBuf[Bytes], Free, &Max))
1329 *pLine = '\0';
1330 return (sal_False);
1333 if (Max < Free)
1335 if ((Max == 0) && (pLine == pszLine))
1337 *pLine = '\0';
1338 return (sal_False);
1341 pFile->m_ReadBuf[Bytes + Max] = '\0';
1345 for (pChr = pFile->m_pReadPtr;
1346 (*pChr != '\n') && (*pChr != '\r') && (*pChr != '\0') &&
1347 (pChr < (pFile->m_ReadBuf + sizeof(pFile->m_ReadBuf) - 1));
1348 pChr++);
1350 Max = min(pChr - pFile->m_pReadPtr, MaxLen);
1351 memcpy(pLine, pFile->m_pReadPtr, Max);
1352 MaxLen -= Max;
1353 pLine += Max;
1355 if (pChr < (pFile->m_ReadBuf + sizeof(pFile->m_ReadBuf) - 1))
1357 if (*pChr != '\0')
1359 if ((pChr[0] == '\r') && (pChr[1] == '\n'))
1360 pChr += 2;
1361 else
1362 pChr += 1;
1365 if ((pChr < (pFile->m_ReadBuf + sizeof(pFile->m_ReadBuf))) &&
1366 (*pChr == '\0'))
1367 pChr = pFile->m_ReadBuf + sizeof(pFile->m_ReadBuf);
1369 *pLine = '\0';
1371 /* setting MaxLen to -1 indicates terminating read loop */
1372 MaxLen = -1;
1375 pFile->m_pReadPtr = pChr;
1377 while (MaxLen > 0);
1379 return (sal_True);
1382 static sal_Bool putLine(osl_TFile* pFile, const sal_Char *pszLine)
1384 unsigned int Len = strlen(pszLine);
1386 #ifdef DEBUG_OSL_PROFILE
1387 int strLen=0;
1388 #endif
1390 if ( pFile == 0 || pFile->m_Handle < 0 )
1392 return (sal_False);
1395 if ( pFile->m_pWriteBuf == 0 )
1397 pFile->m_pWriteBuf = (sal_Char*) malloc(Len+3);
1398 pFile->m_nWriteBufLen = Len+3;
1399 pFile->m_nWriteBufFree = Len+3;
1401 else
1403 if ( pFile->m_nWriteBufFree <= Len + 3 )
1405 sal_Char* pTmp;
1407 pTmp=(sal_Char*) realloc(pFile->m_pWriteBuf,( ( pFile->m_nWriteBufLen + Len ) * 2) );
1408 if ( pTmp == 0 )
1410 return sal_False;
1412 pFile->m_pWriteBuf = pTmp;
1413 pFile->m_nWriteBufFree = pFile->m_nWriteBufFree + pFile->m_nWriteBufLen + ( 2 * Len );
1414 pFile->m_nWriteBufLen = ( pFile->m_nWriteBufLen + Len ) * 2;
1415 memset( (pFile->m_pWriteBuf) + ( pFile->m_nWriteBufLen - pFile->m_nWriteBufFree ), 0, pFile->m_nWriteBufFree);
1421 memcpy(pFile->m_pWriteBuf + ( pFile->m_nWriteBufLen - pFile->m_nWriteBufFree ),pszLine,Len+1);
1422 #ifdef DEBUG_OSL_PROFILE
1423 strLen = strlen(pFile->m_pWriteBuf);
1424 #endif
1425 pFile->m_pWriteBuf[pFile->m_nWriteBufLen - pFile->m_nWriteBufFree + Len]='\r';
1426 pFile->m_pWriteBuf[pFile->m_nWriteBufLen - pFile->m_nWriteBufFree + Len + 1]='\n';
1427 pFile->m_pWriteBuf[pFile->m_nWriteBufLen - pFile->m_nWriteBufFree + Len + 2]='\0';
1429 pFile->m_nWriteBufFree-=Len+2;
1431 #ifdef DEBUG_OSL_PROFILE
1432 /* OSL_TRACE("File Buffer in _putLine '%s' '%i'(%i)\n",pFile->m_pWriteBuf,strlen(pFile->m_pWriteBuf),pFile->m_nWriteBufLen - pFile->m_nWriteBufFree);*/
1433 #endif
1435 return (sal_True);
1438 /* platform specific end */
1440 static const sal_Char* stripBlanks(const sal_Char* String, sal_uInt32* pLen)
1442 if ( (pLen != NULL) && ( *pLen != 0 ) )
1444 while ((String[*pLen - 1] == ' ') || (String[*pLen - 1] == '\t'))
1445 (*pLen)--;
1447 while ((*String == ' ') || (*String == '\t'))
1449 String++;
1450 (*pLen)--;
1453 else
1454 while ((*String == ' ') || (*String == '\t'))
1455 String++;
1457 return (String);
1460 static const sal_Char* addLine(osl_TProfileImpl* pProfile, const sal_Char* Line)
1462 if (pProfile->m_NoLines >= pProfile->m_MaxLines)
1464 if (pProfile->m_Lines == NULL)
1466 pProfile->m_MaxLines = LINES_INI;
1467 pProfile->m_Lines = (sal_Char **)malloc(pProfile->m_MaxLines * sizeof(sal_Char *));
1469 else
1471 pProfile->m_MaxLines += LINES_ADD;
1472 pProfile->m_Lines = (sal_Char **)realloc(pProfile->m_Lines,
1473 pProfile->m_MaxLines * sizeof(sal_Char *));
1476 if (pProfile->m_Lines == NULL)
1478 pProfile->m_NoLines = 0;
1479 pProfile->m_MaxLines = 0;
1480 return (NULL);
1485 pProfile->m_Lines[pProfile->m_NoLines++] = strdup(Line);
1487 return (pProfile->m_Lines[pProfile->m_NoLines - 1]);
1490 static const sal_Char* insertLine(osl_TProfileImpl* pProfile, const sal_Char* Line, sal_uInt32 LineNo)
1492 if (pProfile->m_NoLines >= pProfile->m_MaxLines)
1494 if (pProfile->m_Lines == NULL)
1496 pProfile->m_MaxLines = LINES_INI;
1497 pProfile->m_Lines = (sal_Char **)malloc(pProfile->m_MaxLines * sizeof(sal_Char *));
1499 else
1501 pProfile->m_MaxLines += LINES_ADD;
1502 pProfile->m_Lines = (sal_Char **)realloc(pProfile->m_Lines,
1503 pProfile->m_MaxLines * sizeof(sal_Char *));
1506 if (pProfile->m_Lines == NULL)
1508 pProfile->m_NoLines = 0;
1509 pProfile->m_MaxLines = 0;
1510 return (NULL);
1515 LineNo = LineNo > pProfile->m_NoLines ? pProfile->m_NoLines : LineNo;
1517 if (LineNo < pProfile->m_NoLines)
1519 sal_uInt32 i, n;
1520 osl_TProfileSection* pSec;
1522 memmove(&pProfile->m_Lines[LineNo + 1], &pProfile->m_Lines[LineNo],
1523 (pProfile->m_NoLines - LineNo) * sizeof(sal_Char *));
1525 /* adjust line references */
1526 for (i = 0; i < pProfile->m_NoSections; i++)
1528 pSec = &pProfile->m_Sections[i];
1530 if (pSec->m_Line >= LineNo)
1531 pSec->m_Line++;
1533 for (n = 0; n < pSec->m_NoEntries; n++)
1534 if (pSec->m_Entries[n].m_Line >= LineNo)
1535 pSec->m_Entries[n].m_Line++;
1539 pProfile->m_NoLines++;
1541 pProfile->m_Lines[LineNo] = strdup(Line);
1543 return (pProfile->m_Lines[LineNo]);
1546 static void removeLine(osl_TProfileImpl* pProfile, sal_uInt32 LineNo)
1548 if (LineNo < pProfile->m_NoLines)
1550 free(pProfile->m_Lines[LineNo]);
1551 if (pProfile->m_NoLines - LineNo > 1)
1553 sal_uInt32 i, n;
1554 osl_TProfileSection* pSec;
1556 memmove(&pProfile->m_Lines[LineNo], &pProfile->m_Lines[LineNo + 1],
1557 (pProfile->m_NoLines - LineNo - 1) * sizeof(sal_Char *));
1559 /* adjust line references */
1560 for (i = 0; i < pProfile->m_NoSections; i++)
1562 pSec = &pProfile->m_Sections[i];
1564 if (pSec->m_Line > LineNo)
1565 pSec->m_Line--;
1567 for (n = 0; n < pSec->m_NoEntries; n++)
1568 if (pSec->m_Entries[n].m_Line > LineNo)
1569 pSec->m_Entries[n].m_Line--;
1572 else
1574 pProfile->m_Lines[LineNo] = 0;
1577 pProfile->m_NoLines--;
1580 return;
1583 static void setEntry(osl_TProfileImpl* pProfile, osl_TProfileSection* pSection,
1584 sal_uInt32 NoEntry, sal_uInt32 Line,
1585 const sal_Char* Entry, sal_uInt32 Len)
1587 Entry = stripBlanks(Entry, &Len);
1588 pSection->m_Entries[NoEntry].m_Line = Line;
1589 pSection->m_Entries[NoEntry].m_Offset = Entry - pProfile->m_Lines[Line];
1590 pSection->m_Entries[NoEntry].m_Len = Len;
1592 return;
1595 static sal_Bool addEntry(osl_TProfileImpl* pProfile, osl_TProfileSection *pSection,
1596 int Line, const sal_Char* Entry, sal_uInt32 Len)
1598 if (pSection != NULL)
1600 if (pSection->m_NoEntries >= pSection->m_MaxEntries)
1602 if (pSection->m_Entries == NULL)
1604 pSection->m_MaxEntries = ENTRIES_INI;
1605 pSection->m_Entries = (osl_TProfileEntry *)malloc(
1606 pSection->m_MaxEntries * sizeof(osl_TProfileEntry));
1608 else
1610 pSection->m_MaxEntries += ENTRIES_ADD;
1611 pSection->m_Entries = (osl_TProfileEntry *)realloc(pSection->m_Entries,
1612 pSection->m_MaxEntries * sizeof(osl_TProfileEntry));
1615 if (pSection->m_Entries == NULL)
1617 pSection->m_NoEntries = 0;
1618 pSection->m_MaxEntries = 0;
1619 return (sal_False);
1623 pSection->m_NoEntries++;
1625 Entry = stripBlanks(Entry, &Len);
1626 setEntry(pProfile, pSection, pSection->m_NoEntries - 1, Line,
1627 Entry, Len);
1629 return (sal_True);
1632 return (sal_False);
1635 static void removeEntry(osl_TProfileSection *pSection, sal_uInt32 NoEntry)
1637 if (NoEntry < pSection->m_NoEntries)
1639 if (pSection->m_NoEntries - NoEntry > 1)
1640 memmove(&pSection->m_Entries[NoEntry],
1641 &pSection->m_Entries[NoEntry + 1],
1642 (pSection->m_NoEntries - NoEntry - 1) * sizeof(osl_TProfileEntry));
1643 pSection->m_NoEntries--;
1646 return;
1649 static sal_Bool addSection(osl_TProfileImpl* pProfile, int Line, const sal_Char* Section, sal_uInt32 Len)
1651 if (pProfile->m_NoSections >= pProfile->m_MaxSections)
1653 if (pProfile->m_Sections == NULL)
1655 pProfile->m_MaxSections = SECTIONS_INI;
1656 pProfile->m_Sections = (osl_TProfileSection *)malloc(pProfile->m_MaxSections * sizeof(osl_TProfileSection));
1658 else
1660 pProfile->m_MaxSections += SECTIONS_ADD;
1661 pProfile->m_Sections = (osl_TProfileSection *)realloc(pProfile->m_Sections,
1662 pProfile->m_MaxSections * sizeof(osl_TProfileSection));
1665 if (pProfile->m_Sections == NULL)
1667 pProfile->m_NoSections = 0;
1668 pProfile->m_MaxSections = 0;
1669 return (sal_False);
1673 pProfile->m_NoSections++;
1675 pProfile->m_Sections[pProfile->m_NoSections - 1].m_Entries = NULL;
1676 pProfile->m_Sections[pProfile->m_NoSections - 1].m_NoEntries = 0;
1677 pProfile->m_Sections[pProfile->m_NoSections - 1].m_MaxEntries = 0;
1679 Section = (sal_Char *)stripBlanks(Section, &Len);
1680 pProfile->m_Sections[pProfile->m_NoSections - 1].m_Line = Line;
1681 pProfile->m_Sections[pProfile->m_NoSections - 1].m_Offset = Section - pProfile->m_Lines[Line];
1682 pProfile->m_Sections[pProfile->m_NoSections - 1].m_Len = Len;
1684 return (sal_True);
1687 static void removeSection(osl_TProfileImpl* pProfile, osl_TProfileSection *pSection)
1689 sal_uInt32 Section;
1691 if ((Section = pSection - pProfile->m_Sections) < pProfile->m_NoSections)
1693 free (pSection->m_Entries);
1694 if (pProfile->m_NoSections - Section > 1)
1696 memmove(&pProfile->m_Sections[Section], &pProfile->m_Sections[Section + 1],
1697 (pProfile->m_NoSections - Section - 1) * sizeof(osl_TProfileSection));
1699 else
1701 pSection->m_Entries = 0;
1704 pProfile->m_NoSections--;
1707 return;
1710 static osl_TProfileSection* findEntry(osl_TProfileImpl* pProfile, const sal_Char* Section,
1711 const sal_Char* Entry, sal_uInt32 *pNoEntry)
1713 static sal_uInt32 Sect = 0;
1714 sal_uInt32 i, n;
1715 sal_uInt32 Len;
1716 const sal_Char* pStr;
1717 osl_TProfileSection* pSec;
1719 Len = strlen(Section);
1720 Section = (sal_Char *)stripBlanks(Section, &Len);
1722 n = Sect;
1724 for (i = 0; i < pProfile->m_NoSections; i++)
1726 n %= pProfile->m_NoSections;
1727 pSec = &pProfile->m_Sections[n];
1728 if ((Len == pSec->m_Len) &&
1729 (strnicmp(Section, &pProfile->m_Lines[pSec->m_Line][pSec->m_Offset], pSec->m_Len)
1730 == 0))
1731 break;
1732 n++;
1735 Sect = n;
1737 if (i < pProfile->m_NoSections)
1739 Len = strlen(Entry);
1740 Entry = stripBlanks(Entry, &Len);
1742 *pNoEntry = pSec->m_NoEntries;
1744 for (i = 0; i < pSec->m_NoEntries; i++)
1746 pStr = &pProfile->m_Lines[pSec->m_Entries[i].m_Line]
1747 [pSec->m_Entries[i].m_Offset];
1748 if ((Len == pSec->m_Entries[i].m_Len) &&
1749 (strnicmp(Entry, pStr, pSec->m_Entries[i].m_Len)
1750 == 0))
1752 *pNoEntry = i;
1753 break;
1757 else
1758 pSec = NULL;
1760 return (pSec);
1763 static sal_Bool loadProfile(osl_TFile* pFile, osl_TProfileImpl* pProfile)
1765 sal_uInt32 i;
1766 sal_Char* pStr;
1767 sal_Char* pChar;
1768 sal_Char Line[1024];
1770 pProfile->m_NoLines = 0;
1771 pProfile->m_NoSections = 0;
1773 OSL_VERIFY(rewindFile(pFile, sal_False));
1775 while (getLine(pFile, Line, sizeof(Line)))
1777 if (! addLine(pProfile, Line))
1778 return (sal_False);
1781 for (i = 0; i < pProfile->m_NoLines; i++)
1783 pStr = (sal_Char *)stripBlanks(pProfile->m_Lines[i], NULL);
1785 if ((*pStr == '\0') || (*pStr == ';'))
1786 continue;
1788 if ((*pStr != '[') || ((pChar = strrchr(pStr, ']')) == NULL) ||
1789 ((pChar - pStr) <= 2))
1791 /* insert entry */
1793 if (pProfile->m_NoSections < 1)
1794 continue;
1796 if ((pChar = strchr(pStr, '=')) == NULL)
1797 pChar = pStr + strlen(pStr);
1799 if (! addEntry(pProfile, &pProfile->m_Sections[pProfile->m_NoSections - 1],
1800 i, pStr, pChar - pStr))
1801 return (sal_False);
1803 else
1805 /* new section */
1807 if (! addSection(pProfile, i, pStr + 1, pChar - pStr - 1))
1808 return (sal_False);
1812 return (sal_True);
1815 static sal_Bool storeProfile(osl_TFile* pFile, osl_TProfileImpl* pProfile, sal_Bool bCleanup)
1817 if (pProfile->m_Lines != NULL)
1819 if (pProfile->m_Flags & FLG_MODIFIED)
1821 sal_uInt32 i;
1823 OSL_VERIFY(rewindFile(pFile, sal_True));
1825 for (i = 0; i < pProfile->m_NoLines; i++)
1826 OSL_VERIFY(putLine(pFile, pProfile->m_Lines[i]));
1828 pProfile->m_Flags &= ~FLG_MODIFIED;
1831 if (bCleanup)
1833 while (pProfile->m_NoLines > 0)
1834 removeLine(pProfile, pProfile->m_NoLines - 1);
1836 free(pProfile->m_Lines);
1837 pProfile->m_Lines = NULL;
1838 pProfile->m_MaxLines = 0;
1840 while (pProfile->m_NoSections > 0)
1841 removeSection(pProfile, &pProfile->m_Sections[pProfile->m_NoSections - 1]);
1843 free(pProfile->m_Sections);
1844 pProfile->m_Sections = NULL;
1845 pProfile->m_MaxSections = 0;
1849 return (sal_True);
1852 static osl_TProfileImpl* acquireProfile(oslProfile Profile, sal_Bool bWriteable)
1854 osl_TProfileImpl* pProfile = (osl_TProfileImpl*)Profile;
1855 oslProfileOption PFlags=0;
1858 if ( bWriteable )
1860 /* PFlags = osl_Profile_DEFAULT | osl_Profile_READWRITE; */
1861 PFlags = osl_Profile_DEFAULT | osl_Profile_WRITELOCK;
1863 else
1865 PFlags = osl_Profile_DEFAULT;
1869 if (pProfile == NULL)
1871 #ifdef DEBUG_OSL_PROFILE
1872 OSL_TRACE("AUTOOPEN MODE\n");
1873 #endif
1875 if ((pProfile = (osl_TProfileImpl*)osl_openProfile(NULL, PFlags)) != NULL )
1877 pProfile->m_Flags |= FLG_AUTOOPEN;
1880 else
1882 #ifdef DEBUG_OSL_PROFILE
1883 OSL_TRACE("try to acquire\n");
1884 #endif
1888 if (! (pProfile->m_Flags & osl_Profile_SYSTEM))
1890 if (! (pProfile->m_Flags & (osl_Profile_READLOCK |
1891 osl_Profile_WRITELOCK | osl_Profile_FLUSHWRITE)))
1893 osl_TStamp Stamp;
1894 #ifdef DEBUG_OSL_PROFILE
1895 OSL_TRACE("DEFAULT MODE\n");
1896 #endif
1897 if (! (pProfile->m_pFile = openFileImpl(pProfile->m_strFileName, pProfile->m_Flags | PFlags)))
1898 return NULL;
1900 Stamp = getFileStamp(pProfile->m_pFile);
1902 if (memcmp(&Stamp, &(pProfile->m_Stamp), sizeof(osl_TStamp)))
1904 pProfile->m_Stamp = Stamp;
1906 loadProfile(pProfile->m_pFile, pProfile);
1909 else
1911 #ifdef DEBUG_OSL_PROFILE
1912 OSL_TRACE("READ/WRITELOCK MODE\n");
1913 #endif
1916 /* A readlock file could not be written */
1917 if ((pProfile->m_Flags & osl_Profile_READLOCK) && bWriteable)
1919 return (NULL);
1923 else
1925 sal_Bool bWriteable = sal_False;
1926 char pszFilename[PATH_MAX] = "";
1928 if ( pProfile->m_strFileName != 0 && pProfile->m_strFileName->buffer[0] != 0 )
1929 FileURLToPath( pszFilename, PATH_MAX, pProfile->m_strFileName );
1930 /* hack: usualy you have a specific HAB, but NULL works here... */
1931 pProfile->m_hIni = PrfOpenProfile(NULL, (PCSZ)pszFilename);
1932 if (! pProfile->m_hIni)
1933 return (NULL);
1937 return (pProfile);
1940 static sal_Bool releaseProfile(osl_TProfileImpl* pProfile)
1942 #ifdef TRACE_OSL_PROFILE
1943 OSL_TRACE("In releaseProfile\n");
1944 #endif
1946 if ( pProfile == 0 )
1948 #ifdef TRACE_OSL_PROFILE
1949 OSL_TRACE("Out releaseProfile [profile==0]\n");
1950 #endif
1951 return sal_False;
1954 if (! (pProfile->m_Flags & osl_Profile_SYSTEM))
1956 if (pProfile->m_Flags & FLG_AUTOOPEN)
1958 #ifdef TRACE_OSL_PROFILE
1959 OSL_TRACE("Out releaseProfile [AUTOOPEN]\n");
1960 #endif
1961 return (osl_closeProfile((oslProfile)pProfile));
1963 else
1965 #ifdef DEBUG_OSL_PROFILE
1966 OSL_TRACE("DEFAULT MODE\n");
1967 #endif
1968 if (! (pProfile->m_Flags & (osl_Profile_READLOCK |
1969 osl_Profile_WRITELOCK | osl_Profile_FLUSHWRITE)))
1971 if (pProfile->m_Flags & FLG_MODIFIED)
1972 storeProfile(pProfile->m_pFile, pProfile, sal_False);
1974 closeFileImpl(pProfile->m_pFile);
1975 pProfile->m_pFile = NULL;
1979 else
1980 PrfCloseProfile(pProfile->m_hIni);
1982 #ifdef TRACE_OSL_PROFILE
1983 OSL_TRACE("Out releaseProfile [ok]\n");
1984 #endif
1985 return (sal_True);
1988 #if 0 // YD
1990 static sal_Bool lookupProfile(const sal_Char *pszPath, const sal_Char *pszFile, sal_Char *pPath)
1992 sal_Char *pChr, *pStr;
1993 sal_Char Path[_MAX_PATH] = "";
1994 sal_Char Product[132] = "";
1995 sal_Char Buffer[1024];
1997 if (*pszPath == '"')
1999 int i = 0;
2001 pszPath++;
2003 while ((*pszPath != '"') && (*pszPath != '\0'))
2004 Product[i++] = *pszPath++;
2006 Product[i] = '\0';
2008 if (*pszPath == '"')
2009 pszPath++;
2011 if ( (*pszPath == '/') || (*pszPath == '\\') )
2013 pszPath++;
2016 else
2018 /* if we have not product identfication, do a special handling for soffice.ini */
2019 if (stricmp(SVERSION_PROFILE, pszFile) == 0)
2021 sal_Char Profile[_MAX_PATH];
2022 sal_Char Dir[_MAX_PATH];
2023 oslProfile hProfile;
2025 /* open sversion.ini in the system directory, and try to locate the entry
2026 with the highest version for StarOffice */
2027 if ((osl_getProfileName(SVERSION_FALLBACK, SVERSION_NAME, Profile, sizeof(Profile))) &&
2028 (hProfile = osl_openProfile(Profile, osl_Profile_READLOCK)))
2030 osl_getProfileSectionEntries(hProfile, SVERSION_SECTION,
2031 Buffer, sizeof(Buffer));
2033 for (pChr = Buffer; *pChr != '\0'; pChr += strlen(pChr) + 1)
2035 if ((strnicmp(pChr, SVERSION_SOFFICE, sizeof(SVERSION_SOFFICE) - 1) == 0) &&
2036 (stricmp(Product, pChr) < 0))
2038 osl_readProfileString(hProfile, SVERSION_SECTION, pChr,
2039 Dir, sizeof(Dir), "");
2041 /* check for existence of path */
2042 if (access(Dir, 0) >= 0)
2043 strcpy(Product, pChr);
2047 osl_closeProfile(hProfile);
2050 /* open sversion.ini in the users directory, and try to locate the entry
2051 with the highest version for StarOffice */
2052 if ((strcmp(SVERSION_LOCATION, SVERSION_FALLBACK) != 0) &&
2053 (osl_getProfileName(SVERSION_LOCATION, SVERSION_NAME, Profile, sizeof(Profile))) &&
2054 (hProfile = osl_openProfile(Profile, osl_Profile_READLOCK)))
2056 osl_getProfileSectionEntries(hProfile, SVERSION_SECTION,
2057 Buffer, sizeof(Buffer));
2059 for (pChr = Buffer; *pChr != '\0'; pChr += strlen(pChr) + 1)
2061 if ((strnicmp(pChr, SVERSION_SOFFICE, sizeof(SVERSION_SOFFICE) - 1) == 0) &&
2062 (stricmp(Product, pChr) < 0))
2064 osl_readProfileString(hProfile, SVERSION_SECTION, pChr,
2065 Dir, sizeof(Dir), "");
2067 /* check for existence of path */
2068 if (access(Dir, 0) >= 0)
2069 strcpy(Product, pChr);
2073 osl_closeProfile(hProfile);
2076 /* remove any trailing build number */
2077 if ((pChr = strrchr(Product, '/')) != NULL)
2078 *pChr = '\0';
2083 /* if we have an userid option eg. "-userid:rh[/usr/home/rh/staroffice]",
2084 this will supercede all other locations */
2085 if (osl_getCommandArgs(Buffer, sizeof(Buffer)) == osl_Process_E_None)
2087 sal_Char *pStart, *pEnd;
2089 for (pChr = Buffer; *pChr != '\0'; pChr += strlen(pChr) + 1)
2090 if (((*pChr == '-') || (*pChr == '+')) &&
2091 (strnicmp(pChr + 1, SVERSION_OPTION, sizeof(SVERSION_OPTION) - 1) == 0))
2093 if (((pStart = strchr(pChr + sizeof(SVERSION_OPTION), '[')) != NULL) &&
2094 ((pEnd = strchr(pStart + 1, ']')) != NULL))
2096 strncpy(Path, pStart + 1, pEnd - (pStart + 1));
2097 Path[pEnd - (pStart + 1)] = '\0';
2099 /* build full path */
2100 if ((Path[strlen(Path) - 1] != '/') && (Path[strlen(Path) - 1] != '\\'))
2102 strcat(Path, "\\");
2105 pChr =&Path[strlen(Path)];
2106 if ( strlen(pszPath) <= 0 )
2108 strcat(Path,SVERSION_USER);
2110 if ( access(Path, 0) < 0 )
2112 *pChr='\0';
2115 else
2117 strcat(Path, pszPath);
2120 break;
2125 if (strlen(Path) <= 0)
2127 /* try to find the file in the directory of the executbale */
2128 if (osl_getExecutableFile(Path, sizeof(Path)) != osl_Process_E_None)
2129 return (sal_False);
2131 /* seperate path from filename */
2132 if ((pChr = strrchr(Path, '\\')) == NULL)
2133 if ((pChr = strrchr(Path, ':')) == NULL)
2134 return (sal_False);
2135 else
2136 *pChr = '\0';
2137 else
2138 *pChr = '\0';
2140 /* if we have no product identification use the executable file name */
2141 if (strlen(Product) <= 0)
2143 strcpy(Product, pChr + 1);
2145 /* remove extension */
2146 if ((pChr = strrchr(Product, '.')) != NULL)
2147 *pChr = '\0';
2150 /* remember last subdir */
2151 pStr = strrchr(Path, '\\');
2153 strcat(Path, "\\");
2155 if ( strlen(pszPath) <= 0 )
2157 strcat(Path, pszPath);
2159 else
2161 strcat(Path,pszPath);
2164 /* if file not exists, remove any specified subdirectories
2165 like "bin" or "program" */
2166 if (((access(Path, 0) < 0) && (pStr != NULL)) || (strlen(pszPath) <= 0))
2168 static sal_Char *SubDirs[] = SVERSION_DIRS;
2170 int i = 0;
2172 for (i = 0; i < (sizeof(SubDirs) / sizeof(SubDirs[0])); i++)
2173 if (strnicmp(pStr + 1, SubDirs[i], strlen(SubDirs[i])) == 0)
2175 if ( strlen(pszPath) <= 0)
2177 strcpy(pStr + 1,SVERSION_USER);
2178 if ( access(Path, 0) < 0 )
2180 *(pStr+1)='\0';
2183 else
2185 strcpy(pStr + 1, pszPath);
2188 break;
2192 pChr = &Path[strlen(Path)];
2193 if ((Path[strlen(Path) - 1] != '/') && (Path[strlen(Path) - 1] != '\\'))
2194 strcat(Path, "\\");
2195 strcat(Path, pszFile);
2197 if ((access(Path, 0) < 0) && (strlen(Product) > 0))
2199 sal_Char Profile[_MAX_PATH];
2200 oslProfile hProfile;
2202 /* remove appended filename */
2203 *pChr = '\0';
2205 /* open sversion.ini in the system directory, and try to locate the entry
2206 with the highest version for StarOffice */
2207 if ((osl_getProfileName(SVERSION_LOCATION, SVERSION_NAME, Profile, sizeof(Profile))) &&
2208 (hProfile = osl_openProfile(Profile, osl_Profile_READLOCK)))
2210 pChr = &Product[strlen(Product)];
2212 /* append build number */
2213 strcat(Product, "/");
2214 strcat(Product, BUILD_STR(SUPD));
2216 osl_readProfileString(hProfile, SVERSION_SECTION, Product,
2217 Buffer, sizeof(Buffer), "");
2219 /* if not found, try it without build number */
2220 if (strlen(Buffer) <= 0)
2222 *pChr = '\0';
2224 osl_readProfileString(hProfile, SVERSION_SECTION, Product,
2225 Buffer, sizeof(Buffer), "");
2227 osl_closeProfile(hProfile);
2229 /* if not found, try the fallback */
2230 if ((strlen(Buffer) <= 0) && (strcmp(SVERSION_LOCATION, SVERSION_FALLBACK) != 0))
2232 if ((osl_getProfileName(SVERSION_FALLBACK, SVERSION_NAME, Profile, sizeof(Profile))) &&
2233 (hProfile = osl_openProfile(Profile, osl_Profile_READLOCK)))
2235 /* prepare build number */
2236 *pChr = '/';
2238 osl_readProfileString(hProfile, SVERSION_SECTION, Product,
2239 Buffer, sizeof(Buffer), "");
2241 /* if not found, try it without build number */
2242 if (strlen(Buffer) <= 0)
2244 *pChr = '\0';
2246 osl_readProfileString(hProfile, SVERSION_SECTION, Product,
2247 Buffer, sizeof(Buffer), "");
2250 osl_closeProfile(hProfile);
2254 else
2255 osl_closeProfile(hProfile);
2257 if (strlen(Buffer) > 0)
2259 strcpy(Path, Buffer);
2261 /* build full path */
2262 if ((Path[strlen(Path) - 1] != '/') && (Path[strlen(Path) - 1] != '\\'))
2264 if ((*pszPath != '/') && (*pszPath != '\\'))
2265 strcat(Path, "\\");
2268 pChr=&Path[strlen(pszPath)];
2269 if ( strlen(pszPath) > 0 )
2271 strcat(Path, pszPath);
2273 else
2275 strcat(Path,SVERSION_USER);
2276 if ( access(Path, 0) < 0 )
2278 *pChr='\0';
2284 else
2285 /* remove appended filename */
2286 *pChr = '\0';
2289 strcpy(pPath, Path);
2291 return (sal_True);
2294 #endif // 0 // YD