ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

uxini.c
Go to the documentation of this file.
00001 /*
00002  * Win32 5.1 uxtheme ini file processing
00003  *
00004  * Copyright (C) 2004 Kevin Koltzau
00005  *
00006  * This library is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU Lesser General Public
00008  * License as published by the Free Software Foundation; either
00009  * version 2.1 of the License, or (at your option) any later version.
00010  *
00011  * This library is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * Lesser General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Lesser General Public
00017  * License along with this library; if not, write to the Free Software
00018  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
00019  */
00020 
00021 #include "uxthemep.h"
00022 #include "wine/debug.h"
00023 
00024 WINE_DEFAULT_DEBUG_CHANNEL(uxtheme);
00025 
00026 /***********************************************************************
00027  * Defines and global variables
00028  */
00029 
00030 static const WCHAR szTextFileResource[] = {
00031     'T','E','X','T','F','I','L','E','\0'
00032 };
00033 
00034 typedef struct _UXINI_FILE {
00035     LPCWSTR lpIni;
00036     LPCWSTR lpCurLoc;
00037     LPCWSTR lpEnd;
00038 } UXINI_FILE;
00039 
00040 /***********************************************************************/
00041 
00042 /**********************************************************************
00043  *      UXINI_LoadINI
00044  *
00045  * Load a theme INI file out of resources from the specified
00046  * theme
00047  *
00048  * PARAMS
00049  *     tf                  Theme to load INI file out of resources
00050  *     lpName              Resource name of the INI file
00051  *
00052  * RETURNS
00053  *     INI file, or NULL if not found
00054  */
00055 PUXINI_FILE UXINI_LoadINI(HMODULE hTheme, LPCWSTR lpName) {
00056     HRSRC hrsc;
00057     LPCWSTR lpThemesIni = NULL;
00058     PUXINI_FILE uf;
00059     DWORD dwIniSize;
00060 
00061     TRACE("Loading resource INI %s\n", debugstr_w(lpName));
00062 
00063     if((hrsc = FindResourceW(hTheme, lpName, szTextFileResource))) {
00064         if(!(lpThemesIni = LoadResource(hTheme, hrsc))) {
00065             TRACE("%s resource not found\n", debugstr_w(lpName));
00066             return NULL;
00067         }
00068     }
00069 
00070     dwIniSize = SizeofResource(hTheme, hrsc) / sizeof(WCHAR);
00071     uf = HeapAlloc(GetProcessHeap(), 0, sizeof(UXINI_FILE));
00072     uf->lpIni = lpThemesIni;
00073     uf->lpCurLoc = lpThemesIni;
00074     uf->lpEnd = lpThemesIni + dwIniSize;
00075     return uf;
00076 }
00077 
00078 /**********************************************************************
00079  *      UXINI_CloseINI
00080  *
00081  * Close an open theme INI file
00082  *
00083  * PARAMS
00084  *     uf                  Theme INI file to close
00085  */
00086 void UXINI_CloseINI(PUXINI_FILE uf)
00087 {
00088     HeapFree(GetProcessHeap(), 0, uf);
00089 }
00090 
00091 /**********************************************************************
00092  *      UXINI_eof
00093  *
00094  * Determines if we are at the end of the INI file
00095  *
00096  * PARAMS
00097  *     uf                  Theme INI file to test
00098  */
00099 static inline BOOL UXINI_eof(PUXINI_FILE uf)
00100 {
00101     return uf->lpCurLoc >= uf->lpEnd;
00102 }
00103 
00104 /**********************************************************************
00105  *      UXINI_isspace
00106  *
00107  * Check if a character is a space character
00108  *
00109  * PARAMS
00110  *     c                   Character to test
00111  */
00112 static inline BOOL UXINI_isspace(WCHAR c)
00113 {
00114     if (isspace(c)) return TRUE;
00115     if (c=='\r') return TRUE;
00116     return FALSE;
00117 }
00118 
00119 /**********************************************************************
00120  *      UXINI_GetNextLine
00121  *
00122  * Get the next line in the INI file, non NULL terminated
00123  * removes whitespace at beginning and end of line, and removes comments
00124  *
00125  * PARAMS
00126  *     uf                  INI file to retrieve next line
00127  *     dwLen               Location to store pointer to line length
00128  *
00129  * RETURNS
00130  *     The section name, non NULL terminated
00131  */
00132 static LPCWSTR UXINI_GetNextLine(PUXINI_FILE uf, DWORD *dwLen)
00133 {
00134     LPCWSTR lpLineEnd;
00135     LPCWSTR lpLineStart;
00136     DWORD len;
00137     do {
00138         if(UXINI_eof(uf)) return NULL;
00139         /* Skip whitespace and empty lines */
00140         while(!UXINI_eof(uf) && (UXINI_isspace(*uf->lpCurLoc) || *uf->lpCurLoc == '\n')) uf->lpCurLoc++;
00141         lpLineStart = uf->lpCurLoc;
00142         lpLineEnd = uf->lpCurLoc;
00143         while(!UXINI_eof(uf) && *uf->lpCurLoc != '\n' && *uf->lpCurLoc != ';') lpLineEnd = ++uf->lpCurLoc;
00144         /* If comment was found, skip the rest of the line */
00145         if(*uf->lpCurLoc == ';')
00146             while(!UXINI_eof(uf) && *uf->lpCurLoc != '\n') uf->lpCurLoc++;
00147         len = (lpLineEnd - lpLineStart);
00148         if(*lpLineStart != ';' && len == 0)
00149             return NULL;
00150     } while(*lpLineStart == ';');
00151     /* Remove whitespace from end of line */
00152     while(UXINI_isspace(lpLineStart[len-1])) len--;
00153     *dwLen = len;
00154 
00155     return lpLineStart;
00156 }
00157 
00158 static inline void UXINI_UnGetToLine(PUXINI_FILE uf, LPCWSTR lpLine)
00159 {
00160     uf->lpCurLoc = lpLine;
00161 }
00162 
00163 /**********************************************************************
00164  *      UXINI_GetNextSection
00165  *
00166  * Locate the next section in the ini file, and return pointer to
00167  * section name, non NULL terminated. Use dwLen to determine length
00168  *
00169  * PARAMS
00170  *     uf                  INI file to search, search starts at current location
00171  *     dwLen               Location to store pointer to section name length
00172  *
00173  * RETURNS
00174  *     The section name, non NULL terminated
00175  */
00176 LPCWSTR UXINI_GetNextSection(PUXINI_FILE uf, DWORD *dwLen)
00177 {
00178     LPCWSTR lpLine;
00179     while((lpLine = UXINI_GetNextLine(uf, dwLen))) {
00180         /* Assuming a ']' ending to the section name */
00181         if(lpLine[0] == '[') {
00182             lpLine++;
00183             *dwLen -= 2;
00184             break;
00185         }
00186     }
00187     return lpLine;
00188 }
00189 
00190 /**********************************************************************
00191  *      UXINI_FindSection
00192  *
00193  * Locate a section with the specified name, search starts
00194  * at current location in ini file
00195  *
00196  * PARAMS
00197  *     uf                  INI file to search, search starts at current location
00198  *     lpName              Name of the section to locate
00199  *
00200  * RETURNS
00201  *     TRUE if section was found, FALSE otherwise
00202  */
00203 BOOL UXINI_FindSection(PUXINI_FILE uf, LPCWSTR lpName)
00204 {
00205     LPCWSTR lpSection;
00206     DWORD dwLen;
00207     while((lpSection = UXINI_GetNextSection(uf, &dwLen))) {
00208         if(CompareStringW(LOCALE_SYSTEM_DEFAULT, NORM_IGNORECASE, lpSection, dwLen, lpName, -1) == CSTR_EQUAL) {
00209             return TRUE;
00210         }
00211     }
00212     return FALSE;
00213 }
00214 
00215 /**********************************************************************
00216  *      UXINI_GetNextValue
00217  *
00218  * Locate the next value in the current section
00219  *
00220  * PARAMS
00221  *     uf                  INI file to search, search starts at current location
00222  *     dwNameLen            Location to store pointer to value name length
00223  *     lpValue              Location to store pointer to the value
00224  *     dwValueLen           Location to store pointer to value length
00225  *
00226  * RETURNS
00227  *     The value name, non NULL terminated
00228  */
00229 LPCWSTR UXINI_GetNextValue(PUXINI_FILE uf, DWORD *dwNameLen, LPCWSTR *lpValue, DWORD *dwValueLen)
00230 {
00231     LPCWSTR lpLine;
00232     LPCWSTR lpLineEnd;
00233     LPCWSTR name = NULL;
00234     LPCWSTR value = NULL;
00235     DWORD vallen = 0;
00236     DWORD namelen = 0;
00237     DWORD dwLen;
00238     lpLine = UXINI_GetNextLine(uf, &dwLen);
00239     if(!lpLine)
00240         return NULL;
00241     if(lpLine[0] == '[') {
00242         UXINI_UnGetToLine(uf, lpLine);
00243         return NULL;
00244     }
00245     lpLineEnd = lpLine + dwLen;
00246 
00247     name = lpLine;
00248     while(namelen < dwLen && *lpLine != '=') {
00249         lpLine++;
00250         namelen++;
00251     }
00252     if(*lpLine != '=') return NULL;
00253     lpLine++;
00254 
00255     /* Remove whitespace from end of name */
00256     while(UXINI_isspace(name[namelen-1])) namelen--;
00257     /* Remove whitespace from beginning of value */
00258     while(UXINI_isspace(*lpLine) && lpLine < lpLineEnd) lpLine++;
00259     value = lpLine;
00260     vallen = dwLen-(value-name);
00261 
00262     *dwNameLen = namelen;
00263     *dwValueLen = vallen;
00264     *lpValue = value;
00265 
00266     return name;
00267 }
00268 
00269 /**********************************************************************
00270  *      UXINI_FindValue
00271  *
00272  * Locate a value by name
00273  *
00274  * PARAMS
00275  *     uf                   INI file to search, search starts at current location
00276  *     lpName               Value name to locate
00277  *     lpValue              Location to store pointer to the value
00278  *     dwValueLen           Location to store pointer to value length
00279  *
00280  * RETURNS
00281  *     The value name, non NULL terminated
00282  */
00283 BOOL UXINI_FindValue(PUXINI_FILE uf, LPCWSTR lpName, LPCWSTR *lpValue, DWORD *dwValueLen)
00284 {
00285     LPCWSTR name;
00286     DWORD namelen;
00287 
00288     while((name = UXINI_GetNextValue(uf, &namelen, lpValue, dwValueLen))) {
00289         if(CompareStringW(LOCALE_SYSTEM_DEFAULT, NORM_IGNORECASE, name, namelen, lpName, -1) == CSTR_EQUAL) {
00290             return TRUE;
00291         }
00292     }
00293     return FALSE;
00294 }

Generated on Sun May 27 2012 04:26:47 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.