]>
git.saurik.com Git - wxWidgets.git/blob - src/common/config.cpp
ddb5a9d71658bcb3fe50d5440a2898ad51521cf9
1 ///////////////////////////////////////////////////////////////////////////////
3 // Purpose: implementation of wxConfig class
4 // Author: Vadim Zeitlin
8 // Copyright: (c) 1997 Karsten Ballüder Ballueder@usa.net
9 // Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
10 // Licence: wxWindows license
11 ///////////////////////////////////////////////////////////////////////////////
13 // ============================================================================
15 // ============================================================================
17 #pragma implementation "app.h"
20 #include "wx/wxprec.h"
26 #include <wx/string.h>
30 #include <wx/textfile.h>
31 #include <wx/config.h>
36 // ============================================================================
38 // ============================================================================
40 // ----------------------------------------------------------------------------
42 // ----------------------------------------------------------------------------
47 // ----------------------------------------------------------------------------
48 // static & global functions
49 // ----------------------------------------------------------------------------
51 // understands both Unix and Windows (but only under Windows) environment
52 // variables expansion: i.e. $var, $(var) and ${var} are always understood
53 // and in addition under Windows %var% is also.
54 wxString
ExpandEnvVars(const wxString
& str
)
58 // don't change the values the enum elements: they must be equal
59 // to the matching [closing] delimiter.
66 Bracket_Windows
= '%' // yeah, Windows people are a bit strange ;-)
71 for ( uint n
= 0; n
< str
.Len(); n
++ ) {
81 bracket
= Bracket_Windows
;
84 if ( n
== str
.Len() - 1 ) {
85 bracket
= Bracket_None
;
88 switch ( str
[n
+ 1] ) {
90 bracket
= Bracket_Normal
;
91 n
++; // skip the bracket
95 bracket
= Bracket_Curly
;
96 n
++; // skip the bracket
100 bracket
= Bracket_None
;
106 while ( m
< str
.Len() && (isalnum(str
[m
]) || str
[m
] == '_') )
109 wxString
strVarName(str
.c_str() + n
+ 1, m
- n
- 1);
111 const char *pszValue
= getenv(strVarName
);
112 if ( pszValue
!= NULL
) {
113 strResult
+= pszValue
;
116 // variable doesn't exist => don't change anything
118 if ( bracket
!= Bracket_Windows
)
120 if ( bracket
!= Bracket_None
)
121 strResult
<< str
[n
- 1];
122 strResult
<< str
[n
] << strVarName
;
125 // check the closing bracket
126 if ( bracket
!= Bracket_None
) {
127 if ( m
== str
.Len() || str
[m
] != (char)bracket
) {
128 wxLogWarning("missing '%c' at position %d in '%s'.",
129 (char)bracket
, m
+ 1, str
.c_str());
132 // skip closing bracket
133 if ( pszValue
== NULL
)
134 strResult
<< (char)bracket
;
139 n
= m
- 1; // skip variable name