2 * Win32 5.1 uxtheme ini file processing
4 * Copyright (C) 2004 Kevin Koltzau
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
27 #include "wine/debug.h"
28 #include "wine/heap.h"
30 WINE_DEFAULT_DEBUG_CHANNEL(uxtheme
);
32 /***********************************************************************
33 * Defines and global variables
36 typedef struct _UXINI_FILE
{
40 } UXINI_FILE
, *PUXINI_FILE
;
42 /***********************************************************************/
44 /**********************************************************************
47 * Load a theme INI file out of resources from the specified
51 * tf Theme to load INI file out of resources
52 * lpName Resource name of the INI file
55 * INI file, or NULL if not found
57 PUXINI_FILE
UXINI_LoadINI(HMODULE hTheme
, LPCWSTR lpName
) {
59 LPCWSTR lpThemesIni
= NULL
;
63 TRACE("Loading resource INI %s\n", debugstr_w(lpName
));
65 if((hrsc
= FindResourceW(hTheme
, lpName
, L
"TEXTFILE"))) {
66 if(!(lpThemesIni
= LoadResource(hTheme
, hrsc
))) {
67 TRACE("%s resource not found\n", debugstr_w(lpName
));
72 dwIniSize
= SizeofResource(hTheme
, hrsc
) / sizeof(WCHAR
);
73 uf
= heap_alloc(sizeof(*uf
));
74 uf
->lpIni
= lpThemesIni
;
75 uf
->lpCurLoc
= lpThemesIni
;
76 uf
->lpEnd
= lpThemesIni
+ dwIniSize
;
80 /**********************************************************************
83 * Close an open theme INI file
86 * uf Theme INI file to close
88 void UXINI_CloseINI(PUXINI_FILE uf
)
93 /**********************************************************************
96 * Determines if we are at the end of the INI file
99 * uf Theme INI file to test
101 static inline BOOL
UXINI_eof(PUXINI_FILE uf
)
103 return uf
->lpCurLoc
>= uf
->lpEnd
;
106 /**********************************************************************
109 * Check if a character is a space character
112 * c Character to test
114 static inline BOOL
UXINI_isspace(WCHAR c
)
116 if (isspace(c
)) return TRUE
;
117 if (c
=='\r') return TRUE
;
121 /**********************************************************************
124 * Get the next line in the INI file, non NULL terminated
125 * removes whitespace at beginning and end of line, and removes comments
128 * uf INI file to retrieve next line
129 * dwLen Location to store pointer to line length
132 * The section name, non NULL terminated
134 static LPCWSTR
UXINI_GetNextLine(PUXINI_FILE uf
, DWORD
*dwLen
)
140 if(UXINI_eof(uf
)) return NULL
;
141 /* Skip whitespace and empty lines */
142 while(!UXINI_eof(uf
) && (UXINI_isspace(*uf
->lpCurLoc
) || *uf
->lpCurLoc
== '\n')) uf
->lpCurLoc
++;
143 lpLineStart
= uf
->lpCurLoc
;
144 lpLineEnd
= uf
->lpCurLoc
;
145 while(!UXINI_eof(uf
) && *uf
->lpCurLoc
!= '\n' && *uf
->lpCurLoc
!= ';') lpLineEnd
= ++uf
->lpCurLoc
;
146 /* If comment was found, skip the rest of the line */
147 if(*uf
->lpCurLoc
== ';')
148 while(!UXINI_eof(uf
) && *uf
->lpCurLoc
!= '\n') uf
->lpCurLoc
++;
149 len
= (lpLineEnd
- lpLineStart
);
150 if(*lpLineStart
!= ';' && len
== 0)
152 } while(*lpLineStart
== ';');
153 /* Remove whitespace from end of line */
154 while(UXINI_isspace(lpLineStart
[len
-1])) len
--;
160 static inline void UXINI_UnGetToLine(PUXINI_FILE uf
, LPCWSTR lpLine
)
162 uf
->lpCurLoc
= lpLine
;
165 /**********************************************************************
166 * UXINI_GetNextSection
168 * Locate the next section in the ini file, and return pointer to
169 * section name, non NULL terminated. Use dwLen to determine length
172 * uf INI file to search, search starts at current location
173 * dwLen Location to store pointer to section name length
176 * The section name, non NULL terminated
178 LPCWSTR
UXINI_GetNextSection(PUXINI_FILE uf
, DWORD
*dwLen
)
181 while((lpLine
= UXINI_GetNextLine(uf
, dwLen
))) {
182 /* Assuming a ']' ending to the section name */
183 if(lpLine
[0] == '[') {
192 /**********************************************************************
195 * Locate a section with the specified name, search starts
196 * at current location in ini file
199 * uf INI file to search, search starts at current location
200 * lpName Name of the section to locate
203 * TRUE if section was found, FALSE otherwise
205 BOOL
UXINI_FindSection(PUXINI_FILE uf
, LPCWSTR lpName
)
209 while((lpSection
= UXINI_GetNextSection(uf
, &dwLen
))) {
210 if(CompareStringW(LOCALE_SYSTEM_DEFAULT
, NORM_IGNORECASE
, lpSection
, dwLen
, lpName
, -1) == CSTR_EQUAL
) {
217 /**********************************************************************
220 * Locate the next value in the current section
223 * uf INI file to search, search starts at current location
224 * dwNameLen Location to store pointer to value name length
225 * lpValue Location to store pointer to the value
226 * dwValueLen Location to store pointer to value length
229 * The value name, non NULL terminated
231 LPCWSTR
UXINI_GetNextValue(PUXINI_FILE uf
, DWORD
*dwNameLen
, LPCWSTR
*lpValue
, DWORD
*dwValueLen
)
236 LPCWSTR value
= NULL
;
240 lpLine
= UXINI_GetNextLine(uf
, &dwLen
);
243 if(lpLine
[0] == '[') {
244 UXINI_UnGetToLine(uf
, lpLine
);
247 lpLineEnd
= lpLine
+ dwLen
;
250 while(namelen
< dwLen
&& *lpLine
!= '=') {
254 if(*lpLine
!= '=') return NULL
;
257 /* Remove whitespace from end of name */
258 while(UXINI_isspace(name
[namelen
-1])) namelen
--;
259 /* Remove whitespace from beginning of value */
260 while(UXINI_isspace(*lpLine
) && lpLine
< lpLineEnd
) lpLine
++;
262 vallen
= dwLen
-(value
-name
);
264 *dwNameLen
= namelen
;
265 *dwValueLen
= vallen
;
271 /**********************************************************************
274 * Locate a value by name
277 * uf INI file to search, search starts at current location
278 * lpName Value name to locate
279 * lpValue Location to store pointer to the value
280 * dwValueLen Location to store pointer to value length
283 * The value name, non NULL terminated
285 BOOL
UXINI_FindValue(PUXINI_FILE uf
, LPCWSTR lpName
, LPCWSTR
*lpValue
, DWORD
*dwValueLen
)
290 while((name
= UXINI_GetNextValue(uf
, &namelen
, lpValue
, dwValueLen
))) {
291 if(CompareStringW(LOCALE_SYSTEM_DEFAULT
, NORM_IGNORECASE
, name
, namelen
, lpName
, -1) == CSTR_EQUAL
) {