#pragma implementation "fileconf.h"
#endif
-// ============================================================================
-// declarations
-// ============================================================================
-
// ----------------------------------------------------------------------------
// headers
// ----------------------------------------------------------------------------
+
#include "wx/wxprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif //__BORLANDC__
+#if wxUSE_CONFIG
+
#ifndef WX_PRECOMP
#include "wx/string.h"
#include "wx/intl.h"
static wxString FilterInEntryName(const wxString& str);
static wxString FilterOutEntryName(const wxString& str);
+// get the name to use in wxFileConfig ctor
+static wxString GetAppName(const wxString& appname);
+
// ============================================================================
// implementation
// ============================================================================
wxFileConfig::wxFileConfig(const wxString& appName, const wxString& vendorName,
const wxString& strLocal, const wxString& strGlobal,
long style)
- : wxConfigBase(!appName && wxTheApp ? wxTheApp->GetAppName()
- : appName,
- vendorName, strLocal, strGlobal, style),
+ : wxConfigBase(::GetAppName(appName), vendorName,
+ strLocal, strGlobal,
+ style),
m_strLocalFile(strLocal), m_strGlobalFile(strGlobal)
{
// Make up names for files if empty
SetStyle(GetStyle() | wxCONFIG_USE_GLOBAL_FILE);
// if the path is not absolute, prepend the standard directory to it
- if ( !m_strLocalFile.IsEmpty() && !wxIsAbsolutePath(m_strLocalFile) )
- {
- wxString strLocal = m_strLocalFile;
- m_strLocalFile = GetLocalDir();
- m_strLocalFile << strLocal;
- }
-
- if ( !m_strGlobalFile.IsEmpty() && !wxIsAbsolutePath(m_strGlobalFile) )
- {
- wxString strGlobal = m_strGlobalFile;
- m_strGlobalFile = GetGlobalDir();
- m_strGlobalFile << strGlobal;
+ // UNLESS wxCONFIG_USE_RELATIVE_PATH style is set
+ if ( !(style & wxCONFIG_USE_RELATIVE_PATH) ){
+ if ( !m_strLocalFile.IsEmpty() && !wxIsAbsolutePath(m_strLocalFile) )
+ {
+ wxString strLocal = m_strLocalFile;
+ m_strLocalFile = GetLocalDir();
+ m_strLocalFile << strLocal;
+ }
+
+ if ( !m_strGlobalFile.IsEmpty() && !wxIsAbsolutePath(m_strGlobalFile) )
+ {
+ wxString strGlobal = m_strGlobalFile;
+ m_strGlobalFile = GetGlobalDir();
+ m_strGlobalFile << strGlobal;
+ }
}
Init();
}
else { // a key
const wxChar *pEnd = pStart;
- while ( !wxIsspace(*pEnd) ) {
+ while ( *pEnd != _T('=') && !wxIsspace(*pEnd) ) {
if ( *pEnd == _T('\\') ) {
// next character may be space or not - still take it because it's
// quoted
return FALSE;
}
- strName = FilterOutEntryName(strName);
-
ConfigEntry *pEntry = m_pCurrentGroup->FindEntry(strName);
if ( pEntry == NULL )
pEntry = m_pCurrentGroup->AddEntry(strName);
// this group wasn't present in local config file, add it now
if ( pParent != NULL ) {
wxString strFullName;
- strFullName << _T("[") << (GetFullName().c_str() + 1) << _T("]"); // +1: no '/'
+ strFullName << _T("[")
+ // +1: no '/'
+ << FilterOutEntryName(GetFullName().c_str() + 1)
+ << _T("]");
m_pLine = m_pConfig->LineListInsert(strFullName,
pParent->GetLastGroupLine());
pParent->SetLastGroup(this); // we're surely after all the others
if ( bUser ) {
wxString strVal = FilterOutValue(strValue);
wxString strLine;
- strLine << m_strName << _T(" = ") << strVal;
+ strLine << FilterOutEntryName(m_strName) << _T('=') << strVal;
if ( m_pLine != NULL ) {
// entry was read from the local config file, just modify the line
return strResult;
}
+// we can't put ?: in the ctor initializer list because it confuses some
+// broken compilers (Borland C++)
+static wxString GetAppName(const wxString& appName)
+{
+ if ( !appName && wxTheApp )
+ return wxTheApp->GetAppName();
+ else
+ return appName;
+}
+
+#endif // wxUSE_CONFIG
+