#if defined(__WXPM__)
#define INCL_DOS
#include <os2.h>
- #define LINKAGEMODE _Optlink
-#else
- #define LINKAGEMODE
#endif
#include <stdlib.h>
#include <ctype.h>
+// headers needed for umask()
+#ifdef __UNIX__
+ #include <sys/types.h>
+ #include <sys/stat.h>
+#endif // __UNIX__
+
// ----------------------------------------------------------------------------
// macros
// ----------------------------------------------------------------------------
#elif defined(__WXSTUBS__)
wxASSERT_MSG( FALSE, wxT("TODO") ) ;
#elif defined(__WXMAC__)
- {
- short vRefNum ;
- long dirID ;
-
- if ( FindFolder( (short) kOnSystemDisk, kPreferencesFolderType, kDontCreateFolder, &vRefNum, &dirID) == noErr)
- {
- FSSpec file ;
- if ( FSMakeFSSpec( vRefNum , dirID , "\p" , &file ) == noErr )
- {
- strDir = wxMacFSSpec2UnixFilename( &file ) + "/" ;
- }
- }
- }
+ strDir = wxMacFindFolder( (short) kOnSystemDisk, kPreferencesFolderType, kDontCreateFolder ) ;
#else // Windows
wxChar szWinDir[MAX_PATH];
::GetWindowsDirectory(szWinDir, MAX_PATH);
#ifndef __WXMAC__
wxGetHomeDir(&strDir);
-#ifndef __VMS__
-# ifdef __UNIX__
- if (strDir.Last() != wxT('/')) strDir << wxT('/');
+#ifdef __UNIX__
+#ifdef __VMS
+ if (strDir.Last() != wxT(']'))
+#endif
+ if (strDir.Last() != wxT('/')) strDir << wxT('/');
#else
if (strDir.Last() != wxT('\\')) strDir << wxT('\\');
#endif
-#endif
#else
// no local dir concept on mac
return GetGlobalDir() ;
#ifdef __VMS__ // On VMS I saw the problem that the home directory was appended
// twice for the configuration file. Does that also happen for other
// platforms?
- wxString str = wxT( ' ' );
+ wxString str = wxT( '.' );
#else
wxString str = GetLocalDir();
#endif
- #ifdef __UNIX__
+ #if defined( __UNIX__ ) && !defined( __VMS )
str << wxT('.');
#endif
}
}
+ SetUmask(-1);
+
Init();
}
pEnd = pStart;
while ( *++pEnd != wxT(']') ) {
- if ( *pEnd == wxT('\n') || *pEnd == wxT('\0') )
+ if ( *pEnd == wxT('\\') ) {
+ // the next char is escaped, so skip it even if it is ']'
+ pEnd++;
+ }
+
+ if ( *pEnd == wxT('\n') || *pEnd == wxT('\0') ) {
+ // we reached the end of line, break out of the loop
break;
+ }
}
if ( *pEnd != wxT(']') ) {
break;
default:
- wxLogWarning(_("file '%s', line %d: '%s' "
- "ignored after group header."),
+ wxLogWarning(_("file '%s', line %d: '%s' ignored after group header."),
file.GetName(), n + 1, pEnd);
bCont = FALSE;
}
}
else { // a key
const wxChar *pEnd = pStart;
- while ( *pEnd != wxT('=') && !wxIsspace(*pEnd) ) {
+ while ( *pEnd && *pEnd != wxT('=') && !wxIsspace(*pEnd) ) {
if ( *pEnd == wxT('\\') ) {
// next character may be space or not - still take it because it's
- // quoted
+ // quoted (unless there is nothing)
pEnd++;
+ if ( !*pEnd ) {
+ // the error message will be given below anyhow
+ break;
+ }
}
pEnd++;
wxString strKey(FilterInEntryName(wxString(pStart, pEnd)));
// skip whitespace
- while ( isspace(*pEnd) )
+ while ( wxIsspace(*pEnd) )
pEnd++;
if ( *pEnd++ != wxT('=') ) {
else {
if ( bLocal && pEntry->IsImmutable() ) {
// immutable keys can't be changed by user
- wxLogWarning(_("file '%s', line %d: value for "
- "immutable key '%s' ignored."),
+ wxLogWarning(_("file '%s', line %d: value for immutable key '%s' ignored."),
file.GetName(), n + 1, strKey.c_str());
continue;
}
// (c) key from global file now found in local one
// which is exactly what we want.
else if ( !bLocal || pEntry->IsLocal() ) {
- wxLogWarning(_("file '%s', line %d: key '%s' was first "
- "found at line %d."),
+ wxLogWarning(_("file '%s', line %d: key '%s' was first found at line %d."),
file.GetName(), n + 1, strKey.c_str(), pEntry->Line());
if ( bLocal )
if (pEntry == NULL) {
return FALSE;
}
- else {
- *pStr = ExpandEnvVars(pEntry->Value());
- return TRUE;
- }
+
+ *pStr = ExpandEnvVars(pEntry->Value());
+ return TRUE;
}
bool wxFileConfig::Read(const wxString& key,
wxConfigPathChanger path(this, key);
ConfigEntry *pEntry = m_pCurrentGroup->FindEntry(path.Name());
+ bool ok;
if (pEntry == NULL) {
if( IsRecordingDefaults() )
((wxFileConfig *)this)->Write(key,defVal);
*pStr = ExpandEnvVars(defVal);
- return FALSE;
+ ok = FALSE;
}
else {
*pStr = ExpandEnvVars(pEntry->Value());
- return TRUE;
+ ok = TRUE;
}
+
+ return ok;
}
bool wxFileConfig::Read(const wxString& key, long *pl) const
{
wxString str;
- if ( Read(key, & str) ) {
- *pl = wxAtol(str);
- return TRUE;
- }
- else {
+ if ( !Read(key, & str) )
+ {
return FALSE;
}
+
+ *pl = wxAtol(str);
+ return TRUE;
}
bool wxFileConfig::Write(const wxString& key, const wxString& szValue)
if ( LineListIsEmpty() || !m_pRootGroup->IsDirty() || !m_strLocalFile )
return TRUE;
+#ifdef __UNIX__
+ // set the umask if needed
+ mode_t umaskOld = 0;
+ if ( m_umask != -1 )
+ {
+ umaskOld = umask((mode_t)m_umask);
+ }
+#endif // __UNIX__
+
wxTempFile file(m_strLocalFile);
if ( !file.IsOpened() ) {
}
}
-#ifndef __WXMAC__
- return file.Commit();
-#else
bool ret = file.Commit();
+
+#if defined(__WXMAC__) && !defined(__UNIX__)
if ( ret )
{
FSSpec spec ;
- wxUnixFilename2FSSpec( m_strLocalFile , &spec ) ;
+ wxMacFilename2FSSpec( m_strLocalFile , &spec ) ;
FInfo finfo ;
if ( FSpGetFInfo( &spec , &finfo ) == noErr )
{
FSpSetFInfo( &spec , &finfo ) ;
}
}
- return ret ;
-#endif
+#endif // __WXMAC__ && !__UNIX__
+
+#ifdef __UNIX__
+ // restore the old umask if we changed it
+ if ( m_umask != -1 )
+ {
+ (void)umask(umaskOld);
+ }
+#endif // __UNIX__
+
+ return ret;
}
// ----------------------------------------------------------------------------
{
CleanUp();
- if ( remove(m_strLocalFile.fn_str()) == -1 )
+ if ( wxRemove(m_strLocalFile) == -1 )
wxLogSysError(_("can't delete user configuration file '%s'"), m_strLocalFile.c_str());
m_strLocalFile = m_strGlobalFile = wxT("");