reactos/lib/kernel32/misc
diff -u -r1.15 -r1.16
--- profile.c 29 Nov 2004 00:08:59 -0000 1.15
+++ profile.c 13 Dec 2004 21:16:26 -0000 1.16
@@ -19,25 +19,11 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-
-/*
- * Whole file ripped from Wine's dlls\kernel\profile.c, rev 1.13 and is
- * unchanged (to make merging easier) except that includes are different
- * and some prototypes were changed to comply with w32api.
- *
- * -Gunnar
- */
-
-#define WINVER 0x0500
-
#include <k32.h>
-#include "wine/config.h"
-//#include "wine/port.h"
-#include "wine/debug.h"
-#include "wine/unicode.h"
+#define NDEBUG
+#include "debug.h"
-WINE_DEFAULT_DEBUG_CHANNEL(profile);
static const char bom_utf8[] = {0xEF,0xBB,0xBF};
@@ -85,7 +71,6 @@
#define IS_ENTRY_COMMENT(str) ((str)[0] == ';')
static const WCHAR emptystringW[] = {0};
-static const WCHAR wininiW[] = { 'w','i','n','.','i','n','i',0 };
static CRITICAL_SECTION PROFILE_CritSect;
static CRITICAL_SECTION_DEBUG critsect_debug =
@@ -98,6 +83,25 @@
static const char hex[16] = "0123456789ABCDEF";
+
+static inline WCHAR *memchrW( const WCHAR *ptr, WCHAR ch, size_t n )
+{
+ const WCHAR *end;
+ for (end = ptr + n; ptr < end; ptr++)
+ if (*ptr == ch)
+ return (WCHAR *)ptr;
+ return NULL;
+}
+
+static inline WCHAR *memrchrW( const WCHAR *ptr, WCHAR ch, size_t n )
+{
+ const WCHAR *end, *ret = NULL;
+ for (end = ptr + n; ptr < end; ptr++)
+ if (*ptr == ch)
+ ret = ptr;
+ return (WCHAR *)ret;
+}
+
/***********************************************************************
* PROFILE_CopyEntry
*
@@ -109,17 +113,21 @@
{
WCHAR quote = '\0';
- if(!buffer) return;
+ if (!buffer)
+ return;
if (strip_quote && ((*value == '\'') || (*value == '\"')))
{
- if (value[1] && (value[strlenW(value)-1] == *value)) quote = *value++;
+ if (value[1] && (value[wcslen(value)-1] == *value))
+ quote = *value++;
}
- lstrcpynW( buffer, value, len );
- if (quote && (len >= strlenW(value))) buffer[strlenW(buffer)-1] = '\0';
+ wcsncpy( buffer, value, len );
+ if (quote && (len >= wcslen(value)))
+ buffer[wcslen(buffer) - 1] = '\0';
}
+
/* byte-swaps shorts in-place in a buffer. len is in WCHARs */
static inline void PROFILE_ByteSwapShortBuffer(WCHAR * buffer, int len)
{
@@ -129,6 +137,7 @@
shortbuffer[i] = RtlUshortByteSwap(shortbuffer[i]);
}
+
/* writes any necessary encoding marker to the file */
static inline void PROFILE_WriteMarker(HANDLE hFile, ENCODING encoding)
{
@@ -152,13 +161,14 @@
}
}
+
static void PROFILE_WriteLine( HANDLE hFile, WCHAR * szLine, int len, ENCODING encoding)
{
char * write_buffer;
int write_buffer_len;
DWORD dwBytesWritten;
- TRACE("writing: %s\n", debugstr_wn(szLine, len));
+ DPRINT("writing: %.*S\n", len, szLine);
switch (encoding)
{
@@ -186,10 +196,11 @@
WriteFile(hFile, szLine, len * sizeof(WCHAR), &dwBytesWritten, NULL);
break;
default:
- FIXME("encoding type %d not implemented\n", encoding);
+ DPRINT1("encoding type %d not implemented\n", encoding);
}
}
+
/***********************************************************************
* PROFILE_Save
*
@@ -206,16 +217,19 @@
{
int len = 0;
- if (section->name[0]) len += strlenW(section->name) + 6;
+ if (section->name[0])
+ len += wcslen(section->name) + 6;
for (key = section->key; key; key = key->next)
{
- len += strlenW(key->name) + 2;
- if (key->value) len += strlenW(key->value) + 1;
+ len += wcslen(key->name) + 2;
+ if (key->value)
+ len += wcslen(key->value) + 1;
}
buffer = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
- if (!buffer) return;
+ if (!buffer)
+ return;
p = buffer;
if (section->name[0])
@@ -223,21 +237,21 @@
*p++ = '\r';
*p++ = '\n';
*p++ = '[';
- strcpyW( p, section->name );
- p += strlenW(p);
+ wcscpy( p, section->name );
+ p += wcslen(p);
*p++ = ']';
*p++ = '\r';
*p++ = '\n';
}
for (key = section->key; key; key = key->next)
{
- strcpyW( p, key->name );
- p += strlenW(p);
+ wcscpy( p, key->name );
+ p += wcslen(p);
if (key->value)
{
*p++ = '=';
- strcpyW( p, key->value );
- p += strlenW(p);
+ wcscpy( p, key->value );
+ p += wcslen(p);
}
*p++ = '\r';
*p++ = '\n';
@@ -263,7 +277,8 @@
for (key = section->key; key; key = next_key)
{
next_key = key->next;
- if (key->value) HeapFree( GetProcessHeap(), 0, key->value );
+ if (key->value)
+ HeapFree( GetProcessHeap(), 0, key->value );
HeapFree( GetProcessHeap(), 0, key );
}
next_section = section->next;
@@ -271,15 +286,19 @@
}
}
+
/* returns 1 if a character white space else 0 */
static inline int PROFILE_isspaceW(WCHAR c)
{
- if (isspaceW(c)) return 1;
- if (c=='\r' || c==0x1a) return 1;
+ if (iswspace(c))
+ return 1;
+ if (c=='\r' || c==0x1a)
+ return 1;
/* CR and ^Z (DOS EOF) are spaces too (found on CD-ROMs) */
return 0;
}
+
static inline ENCODING PROFILE_DetectTextEncoding(const void * buffer, int * len)
{
DWORD flags = IS_TEXT_UNICODE_SIGNATURE |
@@ -326,22 +345,24 @@
PROFILESECTION **next_section;
PROFILEKEY *key, *prev_key, **next_key;
DWORD dwFileSize;
-
- TRACE("%p\n", hFile);
-
+
+ DPRINT("%p\n", hFile);
+
dwFileSize = GetFileSize(hFile, NULL);
if (dwFileSize == INVALID_FILE_SIZE)
return NULL;
pBuffer = HeapAlloc(GetProcessHeap(), 0 , dwFileSize);
- if (!pBuffer) return NULL;
-
+ if (!pBuffer)
+ return NULL;
+
if (!ReadFile(hFile, pBuffer, dwFileSize, &dwFileSize, NULL))
{
HeapFree(GetProcessHeap(), 0, pBuffer);
- WARN("Error %ld reading file\n", GetLastError());
+ DPRINT("Error %ld reading file\n", GetLastError());
return NULL;
}
+
len = dwFileSize;
*pEncoding = PROFILE_DetectTextEncoding(pBuffer, &len);
/* len is set to the number of bytes in the character marker.
@@ -351,7 +372,7 @@
switch (*pEncoding)
{
case ENCODING_ANSI:
- TRACE("ANSI encoding\n");
+ DPRINT("ANSI encoding\n");
len = MultiByteToWideChar(CP_ACP, 0, (char *)pBuffer, dwFileSize, NULL, 0);
szFile = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
@@ -363,9 +384,10 @@
MultiByteToWideChar(CP_ACP, 0, (char *)pBuffer, dwFileSize, szFile, len);
szEnd = szFile + len;
break;
+
case ENCODING_UTF8:
- TRACE("UTF8 encoding\n");
-
+ DPRINT("UTF8 encoding\n");
+
len = MultiByteToWideChar(CP_UTF8, 0, (char *)pBuffer, dwFileSize, NULL, 0);
szFile = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
if (!szFile)
@@ -376,25 +398,28 @@
MultiByteToWideChar(CP_UTF8, 0, (char *)pBuffer, dwFileSize, szFile, len);
szEnd = szFile + len;
break;
+
case ENCODING_UTF16LE:
- TRACE("UTF16 Little Endian encoding\n");
+ DPRINT("UTF16 Little Endian encoding\n");
szFile = (WCHAR *)pBuffer + 1;
szEnd = (WCHAR *)((char *)pBuffer + dwFileSize);
break;
+
case ENCODING_UTF16BE:
- TRACE("UTF16 Big Endian encoding\n");
+ DPRINT("UTF16 Big Endian encoding\n");
szFile = (WCHAR *)pBuffer + 1;
szEnd = (WCHAR *)((char *)pBuffer + dwFileSize);
PROFILE_ByteSwapShortBuffer(szFile, dwFileSize / sizeof(WCHAR));
break;
+
default:
- FIXME("encoding type %d not implemented\n", *pEncoding);
+ DPRINT("encoding type %d not implemented\n", *pEncoding);
HeapFree(GetProcessHeap(), 0, pBuffer);
return NULL;
}
first_section = HeapAlloc( GetProcessHeap(), 0, sizeof(*section) );
- if(first_section == NULL)
+ if (first_section == NULL)
{
if (szFile != pBuffer)
HeapFree(GetProcessHeap(), 0, szFile);
@@ -418,18 +443,20 @@
if (!szLineEnd)
szLineEnd = szEnd;
line++;
-
- while (szLineStart < szLineEnd && PROFILE_isspaceW(*szLineStart)) szLineStart++;
-
- if (szLineStart >= szLineEnd) continue;
+
+ while (szLineStart < szLineEnd && PROFILE_isspaceW(*szLineStart))
+ szLineStart++;
+
+ if (szLineStart >= szLineEnd)
+ continue;
if (*szLineStart == '[') /* section start */
{
const WCHAR * szSectionEnd;
if (!(szSectionEnd = memrchrW( szLineStart, ']', szLineEnd - szLineStart )))
{
- WARN("Invalid section header at line %d: %s\n",
- line, debugstr_wn(szLineStart, (int)(szLineEnd - szLineStart)) );
+ DPRINT("Invalid section header at line %d: %.*S\n",
+ line, (int)(szLineEnd - szLineStart), szLineStart);
}
else
{
@@ -448,14 +475,15 @@
next_key = §ion->key;
prev_key = NULL;
- TRACE("New section: %s\n", debugstr_w(section->name));
+ DPRINT("New section: %S\n", section->name);
continue;
}
}
/* get rid of white space at the end of the line */
- while ((szLineEnd > szLineStart) && ((*szLineEnd == '\n') || PROFILE_isspaceW(*szLineEnd))) szLineEnd--;
+ while ((szLineEnd > szLineStart) && ((*szLineEnd == '\n') || PROFILE_isspaceW(*szLineEnd)))
+ szLineEnd--;
/* line end should be pointing to character *after* the last wanted character */
szLineEnd++;
@@ -465,9 +493,11 @@
if ((szNameEnd = szValueStart = memchrW( szLineStart, '=', szLineEnd - szLineStart )) != NULL)
{
szNameEnd = szValueStart - 1;
- while ((szNameEnd > szLineStart) && PROFILE_isspaceW(*szNameEnd)) szNameEnd--;
+ while ((szNameEnd > szLineStart) && PROFILE_isspaceW(*szNameEnd))
+ szNameEnd--;
szValueStart++;
- while (szValueStart < szLineEnd && PROFILE_isspaceW(*szValueStart)) szValueStart++;
+ while (szValueStart < szLineEnd && PROFILE_isspaceW(*szValueStart))
+ szValueStart++;
}
if (!szNameEnd)
szNameEnd = szLineEnd - 1;
@@ -497,8 +527,8 @@
next_key = &key->next;
prev_key = key;
- TRACE("New key: name=%s, value=%s\n",
- debugstr_w(key->name), key->value ? debugstr_w(key->value) : "(none)");
+ DPRINT("New key: name=%S, value=%S\n",
+ key->name, key->value ?key->value : L"(none)");
}
}
if (szFile != pBuffer)
@@ -517,7 +547,7 @@
{
while (*section)
{
- if ((*section)->name[0] && !strcmpiW( (*section)->name, name ))
+ if ((*section)->name[0] && !_wcsicmp( (*section)->name, name ))
{
PROFILESECTION *to_del = *section;
*section = to_del->next;
@@ -541,16 +571,17 @@
{
while (*section)
{
- if ((*section)->name[0] && !strcmpiW( (*section)->name, section_name ))
+ if ((*section)->name[0] && !_wcsicmp( (*section)->name, section_name ))
{
PROFILEKEY **key = &(*section)->key;
while (*key)
{
- if (!strcmpiW( (*key)->name, key_name ))
+ if (!_wcsicmp( (*key)->name, key_name ))
{
PROFILEKEY *to_del = *key;
*key = to_del->next;
- if (to_del->value) HeapFree( GetProcessHeap(), 0, to_del->value);
+ if (to_del->value)
+ HeapFree( GetProcessHeap(), 0, to_del->value);
HeapFree( GetProcessHeap(), 0, to_del );
return TRUE;
}
@@ -573,16 +604,17 @@
PROFILESECTION **section= &CurProfile->section;
while (*section)
{
- if ((*section)->name[0] && !strcmpiW( (*section)->name, section_name ))
+ if ((*section)->name[0] && !_wcsicmp( (*section)->name, section_name ))
{
PROFILEKEY **key = &(*section)->key;
while (*key)
{
PROFILEKEY *to_del = *key;
- *key = to_del->next;
- if (to_del->value) HeapFree( GetProcessHeap(), 0, to_del->value);
- HeapFree( GetProcessHeap(), 0, to_del );
- CurProfile->changed =TRUE;
+ *key = to_del->next;
+ if (to_del->value)
+ HeapFree( GetProcessHeap(), 0, to_del->value);
+ HeapFree( GetProcessHeap(), 0, to_del );
+ CurProfile->changed =TRUE;
}
}
section = &(*section)->next;
@@ -602,19 +634,19 @@
int seclen, keylen;
while (PROFILE_isspaceW(*section_name)) section_name++;
- p = section_name + strlenW(section_name) - 1;
+ p = section_name + wcslen(section_name) - 1;
while ((p > section_name) && PROFILE_isspaceW(*p)) p--;
seclen = p - section_name + 1;
while (PROFILE_isspaceW(*key_name)) key_name++;
- p = key_name + strlenW(key_name) - 1;
+ p = key_name + wcslen(key_name) - 1;
while ((p > key_name) && PROFILE_isspaceW(*p)) p--;
keylen = p - key_name + 1;
while (*section)
{
if ( ((*section)->name[0])
- && (!(strncmpiW( (*section)->name, section_name, seclen )))
+ && (!(_wcsnicmp( (*section)->name, section_name, seclen )))
&& (((*section)->name)[seclen] == '\0') )
{
PROFILEKEY **key = &(*section)->key;
@@ -628,16 +660,17 @@
*/
if(!create_always)
{
- if ( (!(strncmpiW( (*key)->name, key_name, keylen )))
+ if ( (!(_wcsnicmp( (*key)->name, key_name, keylen )))
&& (((*key)->name)[keylen] == '\0') )
return *key;
}
key = &(*key)->next;
}
- if (!create) return NULL;
- if (!(*key = HeapAlloc( GetProcessHeap(), 0, sizeof(PROFILEKEY) + strlenW(key_name) * sizeof(WCHAR) )))
+ if (!create)
+ return NULL;
+ if (!(*key = HeapAlloc( GetProcessHeap(), 0, sizeof(PROFILEKEY) + wcslen(key_name) * sizeof(WCHAR) )))
return NULL;
- strcpyW( (*key)->name, key_name );
+ wcscpy( (*key)->name, key_name );
(*key)->value = NULL;
(*key)->next = NULL;
return *key;
@@ -645,17 +678,17 @@
section = &(*section)->next;
}
if (!create) return NULL;
- *section = HeapAlloc( GetProcessHeap(), 0, sizeof(PROFILESECTION) + strlenW(section_name) * sizeof(WCHAR) );
+ *section = HeapAlloc( GetProcessHeap(), 0, sizeof(PROFILESECTION) + wcslen(section_name) * sizeof(WCHAR) );
if(*section == NULL) return NULL;
- strcpyW( (*section)->name, section_name );
+ wcscpy( (*section)->name, section_name );
(*section)->next = NULL;
if (!((*section)->key = HeapAlloc( GetProcessHeap(), 0,
- sizeof(PROFILEKEY) + strlenW(key_name) * sizeof(WCHAR) )))
+ sizeof(PROFILEKEY) + wcslen(key_name) * sizeof(WCHAR) )))
{
HeapFree(GetProcessHeap(), 0, *section);
return NULL;
}
- strcpyW( (*section)->key->name, key_name );
+ wcscpy( (*section)->key->name, key_name );
(*section)->key->value = NULL;
(*section)->key->next = NULL;
return (*section)->key;
@@ -674,7 +707,7 @@
if(!CurProfile)
{
- WARN("No current profile!\n");
+ DPRINT("No current profile!\n");
return FALSE;
}
@@ -684,11 +717,11 @@
if (hFile == INVALID_HANDLE_VALUE)
{
- WARN("could not save profile file %s (error was %ld)\n", debugstr_w(CurProfile->filename), GetLastError());
+ DPRINT("could not save profile file %S (error was %ld)\n", CurProfile->filename, GetLastError());
return FALSE;
}
- TRACE("Saving %s\n", debugstr_w(CurProfile->filename));
+ DPRINT("Saving %S\n", CurProfile->filename);
PROFILE_Save( hFile, CurProfile->section, CurProfile->encoding );
if(GetFileTime(hFile, NULL, NULL, &LastWriteTime))
CurProfile->LastWriteTime=LastWriteTime;
@@ -707,7 +740,8 @@
{
PROFILE_FlushFile();
PROFILE_Free( CurProfile->section );
- if (CurProfile->filename) HeapFree( GetProcessHeap(), 0, CurProfile->filename );
+ if (CurProfile->filename)
+ HeapFree( GetProcessHeap(), 0, CurProfile->filename );
CurProfile->changed = FALSE;
CurProfile->section = NULL;
CurProfile->filename = NULL;
@@ -729,7 +763,7 @@
FILETIME LastWriteTime;
int i,j;
PROFILE *tempProfile;
-
+
ZeroMemory(&LastWriteTime, sizeof(LastWriteTime));
/* First time around */
@@ -749,49 +783,53 @@
GetWindowsDirectoryW( windirW, MAX_PATH );
if ((RtlDetermineDosPathNameType_U(filename) == RELATIVE_PATH) &&
- !strchrW(filename, '\\') && !strchrW(filename, '/'))
+ !wcschr(filename, '\\') && !wcschr(filename, '/'))
{
static const WCHAR wszSeparator[] = {'\\', 0};
- strcpyW(buffer, windirW);
- strcatW(buffer, wszSeparator);
- strcatW(buffer, filename);
+ wcscpy(buffer, windirW);
+ wcscat(buffer, wszSeparator);
+ wcscat(buffer, filename);
}
else
{
LPWSTR dummy;
GetFullPathNameW(filename, sizeof(buffer)/sizeof(buffer[0]), buffer, &dummy);
}
-
- TRACE("path: %s\n", debugstr_w(buffer));
-
+
+ DPRINT("path: %S\n", buffer);
+
hFile = CreateFileW(buffer, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
-
+
if ((hFile == INVALID_HANDLE_VALUE) && (GetLastError() != ERROR_FILE_NOT_FOUND))
{
- WARN("Error %ld opening file %s\n", GetLastError(), debugstr_w(buffer));
+ DPRINT("Error %ld opening file %S\n", GetLastError(), buffer);
return FALSE;
}
- for(i=0;i<N_CACHED_PROFILES;i++)
+ for(i = 0; i < N_CACHED_PROFILES; i++)
{
- if ((MRUProfile[i]->filename && !strcmpW( buffer, MRUProfile[i]->filename )))
+ if ((MRUProfile[i]->filename && !wcscmp( buffer, MRUProfile[i]->filename )))
{
- TRACE("MRU Filename: %s, new filename: %s\n", debugstr_w(MRUProfile[i]->filename), debugstr_w(buffer));
+ DPRINT("MRU Filename: %S, new filename: %S\n", MRUProfile[i]->filename, buffer);
if(i)
{
PROFILE_FlushFile();
tempProfile=MRUProfile[i];
- for(j=i;j>0;j--)
- MRUProfile[j]=MRUProfile[j-1];
+ for (j = i; j > 0; j--)
+ MRUProfile[j] = MRUProfile[j-1];
CurProfile=tempProfile;
}
GetFileTime(hFile, NULL, NULL, &LastWriteTime);
- if(memcmp(&CurProfile->LastWriteTime, &LastWriteTime, sizeof(FILETIME)))
- TRACE("(%s): already opened (mru=%d)\n",
- debugstr_w(buffer), i );
+ if (memcmp(&CurProfile->LastWriteTime, &LastWriteTime, sizeof(FILETIME)))
+ {
+ DPRINT("(%S): already opened (mru = %d)\n",
+ buffer, i );
+ }
else
- TRACE("(%s): already opened, needs refreshing (mru=%d)\n",
- debugstr_w(buffer), i );
+ {
+ DPRINT("(%S): already opened, needs refreshing (mru = %d)\n",
+ buffer, i );
+ }
CloseHandle(hFile);
return TRUE;
}
@@ -801,18 +839,20 @@
PROFILE_FlushFile();
/* Make the oldest profile the current one only in order to get rid of it */
- if(i==N_CACHED_PROFILES)
+ if(i == N_CACHED_PROFILES)
{
- tempProfile=MRUProfile[N_CACHED_PROFILES-1];
- for(i=N_CACHED_PROFILES-1;i>0;i--)
- MRUProfile[i]=MRUProfile[i-1];
+ tempProfile = MRUProfile[N_CACHED_PROFILES-1];
+ for (i = N_CACHED_PROFILES - 1; i > 0; i--)
+ MRUProfile[i] = MRUProfile[i-1];
CurProfile=tempProfile;
}
- if(CurProfile->filename) PROFILE_ReleaseFile();
+
+ if (CurProfile->filename)
+ PROFILE_ReleaseFile();
/* OK, now that CurProfile is definitely free we assign it our new file */
- CurProfile->filename = HeapAlloc( GetProcessHeap(), 0, (strlenW(buffer)+1) * sizeof(WCHAR) );
- strcpyW( CurProfile->filename, buffer );
+ CurProfile->filename = HeapAlloc( GetProcessHeap(), 0, (wcslen(buffer)+1) * sizeof(WCHAR) );
+ wcscpy( CurProfile->filename, buffer );
if (hFile != INVALID_HANDLE_VALUE)
{
@@ -823,7 +863,7 @@
else
{
/* Does not exist yet, we will create it in PROFILE_FlushFile */
- WARN("profile file %s not found\n", debugstr_w(buffer) );
+ DPRINT("profile file %S not found\n", buffer);
}
return TRUE;
}
@@ -840,41 +880,46 @@
{
PROFILEKEY *key;
- if(!buffer) return 0;
+ if (!buffer)
+ return 0;
- TRACE("%s,%p,%u\n", debugstr_w(section_name), buffer, len);
+ DPRINT("%S,%p,%u\n", section_name, buffer, len);
while (section)
{
- if (section->name[0] && !strcmpiW( section->name, section_name ))
+ if (section->name[0] && !_wcsicmp( section->name, section_name ))
{
UINT oldlen = len;
for (key = section->key; key; key = key->next)
{
- if (len <= 2) break;
- if (!*key->name) continue; /* Skip empty lines */
- if (IS_ENTRY_COMMENT(key->name)) continue; /* Skip comments */
+ if (len <= 2)
+ break;
+ if (!*key->name)
+ continue; /* Skip empty lines */
+ if (IS_ENTRY_COMMENT(key->name))
+ continue; /* Skip comments */
PROFILE_CopyEntry( buffer, key->name, len - 1, 0 );
- len -= strlenW(buffer) + 1;
- buffer += strlenW(buffer) + 1;
- if (len < 2)
- break;
- if (return_values && key->value) {
- buffer[-1] = '=';
- PROFILE_CopyEntry ( buffer, key->value, len - 1, 0 );
- len -= strlenW(buffer) + 1;
- buffer += strlenW(buffer) + 1;
+ len -= wcslen(buffer) + 1;
+ buffer += wcslen(buffer) + 1;
+ if (len < 2)
+ break;
+ if (return_values && key->value)
+ {
+ buffer[-1] = '=';
+ PROFILE_CopyEntry ( buffer, key->value, len - 1, 0 );
+ len -= wcslen(buffer) + 1;
+ buffer += wcslen(buffer) + 1;
}
}
*buffer = '\0';
if (len <= 1)
+ {
/*If either lpszSection or lpszKey is NULL and the supplied
destination buffer is too small to hold all the strings,
the last string is truncated and followed by two null characters.
In this case, the return value is equal to cchReturnBuffer
minus two. */
- {
- buffer[-1] = '\0';
+ buffer[-1] = '\0';
return oldlen - 2;
}
return oldlen - len;
@@ -892,38 +937,43 @@
UINT f,l;
PROFILESECTION *section;
- TRACE("(%p, %d)\n", buffer, len);
+ DPRINT("(%p, %d)\n", buffer, len);
if (!buffer || !len)
return 0;
- if (len==1) {
- *buffer='\0';
+ if (len == 1)
+ {
+ *buffer = '\0';
return 0;
}
- f=len-1;
- buf=buffer;
+ f = len - 1;
+ buf = buffer;
section = CurProfile->section;
- while ((section!=NULL)) {
- if (section->name[0]) {
- l = strlenW(section->name)+1;
- if (l > f) {
- if (f>0) {
- strncpyW(buf, section->name, f-1);
- buf += f-1;
- *buf++='\0';
+ while ((section!=NULL))
+ {
+ if (section->name[0])
+ {
+ l = wcslen(section->name)+1;
+ if (l > f)
+ {
+ if (f > 0)
+ {
+ wcsncpy(buf, section->name, f - 1);
+ buf += f - 1;
+ *buf++ = '\0';
}
*buf='\0';
- return len-2;
+ return len - 2;
}
- strcpyW(buf, section->name);
+ wcscpy(buf, section->name);
buf += l;
f -= l;
}
section = section->next;
}
- *buf='\0';
- return buf-buffer;
+ *buf = '\0';
+ return buf - buffer;
}
@@ -955,12 +1005,15 @@
PROFILEKEY *key = NULL;
static const WCHAR empty_strW[] = { 0 };
- if(!buffer) return 0;
+ if (!buffer)
+ return 0;
+
+ if (!def_val)
+ def_val = empty_strW;
- if (!def_val) def_val = empty_strW;
if (key_name)
{
- if (!key_name[0])
+ if (!key_name[0])
{
/* Win95 returns 0 on keyname "". Tested with Likse32 bon 000227 */
return 0;
@@ -968,11 +1021,12 @@
key = PROFILE_Find( &CurProfile->section, section, key_name, FALSE, FALSE);
PROFILE_CopyEntry( buffer, (key && key->value) ? key->value : def_val,
len, TRUE );
- TRACE("(%s,%s,%s): returning %s\n",
- debugstr_w(section), debugstr_w(key_name),
- debugstr_w(def_val), debugstr_w(buffer) );
- return strlenW( buffer );
+ DPRINT("(%S, %S, %S): returning %S\n",
+ section, key_name,
+ def_val, buffer);
+ return wcslen(buffer);
}
+
/* no "else" here ! */
if (section && section[0])
{
@@ -980,7 +1034,7 @@
if (!buffer[0]) /* no luck -> def_val */
{
PROFILE_CopyEntry(buffer, def_val, len, TRUE);
- ret = strlenW(buffer);
+ ret = wcslen(buffer);
}
return ret;
}
@@ -999,7 +1053,7 @@
{
if (!key_name) /* Delete a whole section */
{
- TRACE("(%s)\n", debugstr_w(section_name));
+ DPRINT("(%S)\n", section_name);
CurProfile->changed |= PROFILE_DeleteSection( &CurProfile->section,
section_name );
return TRUE; /* Even if PROFILE_DeleteSection() has failed,
@@ -1007,7 +1061,7 @@
}
else if (!value) /* Delete a key */
{
- TRACE("(%s,%s)\n", debugstr_w(section_name), debugstr_w(key_name) );
+ DPRINT("(%S, %S)\n", section_name, key_name);
CurProfile->changed |= PROFILE_DeleteKey( &CurProfile->section,
section_name, key_name );
return TRUE; /* same error handling as above */
@@ -1016,27 +1070,32 @@
{
PROFILEKEY *key = PROFILE_Find(&CurProfile->section, section_name,
key_name, TRUE, create_always );
- TRACE("(%s,%s,%s):\n",
- debugstr_w(section_name), debugstr_w(key_name), debugstr_w(value) );
- if (!key) return FALSE;
+ DPRINT("(%S, %S, %S):\n",
+ section_name, key_name, value);
+ if (!key)
+ return FALSE;
/* strip the leading spaces. We can safely strip \n\r and
* friends too, they should not happen here anyway. */
- while (PROFILE_isspaceW(*value)) value++;
+ while (PROFILE_isspaceW(*value))
+ value++;
if (key->value)
{
- if (!strcmpW( key->value, value ))
+ if (!wcscmp( key->value, value ))
{
- TRACE(" no change needed\n" );
+ DPRINT(" no change needed\n" );
return TRUE; /* No change needed */
}
- TRACE(" replacing %s\n", debugstr_w(key->value) );
+ DPRINT(" replacing %S\n", key->value);
HeapFree( GetProcessHeap(), 0, key->value );
}
- else TRACE(" creating key\n" );
- key->value = HeapAlloc( GetProcessHeap(), 0, (strlenW(value)+1) * sizeof(WCHAR) );
- strcpyW( key->value, value );
+ else
+ {
+ DPRINT(" creating key\n");
+ }
+ key->value = HeapAlloc( GetProcessHeap(), 0, (wcslen(value) + 1) * sizeof(WCHAR) );
+ wcscpy( key->value, value );
CurProfile->changed = TRUE;
}
return TRUE;
@@ -1059,7 +1118,7 @@
*/
UINT WINAPI GetProfileIntW( LPCWSTR section, LPCWSTR entry, INT def_val )
{
- return GetPrivateProfileIntW( section, entry, def_val, wininiW );
+ return GetPrivateProfileIntW( section, entry, def_val, L"win.ini" );
}
/*
@@ -1077,102 +1136,65 @@
LPCWSTR pDefVal = NULL;
if (!filename)
- filename = wininiW;
+ filename = L"win.ini";
- TRACE("%s,%s,%s,%p,%u,%s\n", debugstr_w(section), debugstr_w(entry),
- debugstr_w(def_val), buffer, len, debugstr_w(filename));
+ DPRINT("%S, %S, %S, %p, %u, %S\n",
+ section, entry,
+ def_val, buffer, len, filename);
/* strip any trailing ' ' of def_val. */
if (def_val)
{
- LPCWSTR p = &def_val[strlenW(def_val)]; /* even "" works ! */
+ LPCWSTR p = &def_val[wcslen(def_val)]; /* even "" works ! */
- while (p > def_val)
- {
- p--;
- if ((*p) != ' ')
- break;
- }
- if (*p == ' ') /* ouch, contained trailing ' ' */
- {
- int len = (int)(p - def_val);
- LPWSTR p;
-
- p = HeapAlloc(GetProcessHeap(), 0, (len + 1) * sizeof(WCHAR));
- strncpyW(p, def_val, len);
- p[len] = '\0';
- pDefVal = p;
- }
+ while (p > def_val)
+ {
+ p--;
+ if ((*p) != ' ')
+ break;
+ }
+
+ if (*p == ' ') /* ouch, contained trailing ' ' */
+ {
+ int len = (int)(p - def_val);
+ LPWSTR p;
+
+ p = HeapAlloc(GetProcessHeap(), 0, (len + 1) * sizeof(WCHAR));
+ wcsncpy(p, def_val, len);
+ p[len] = '\0';
+ pDefVal = p;
+ }
}
+
if (!pDefVal)
- pDefVal = (LPCWSTR)def_val;
+ pDefVal = (LPCWSTR)def_val;
RtlEnterCriticalSection( &PROFILE_CritSect );
- if (PROFILE_Open( filename )) {
- if ((allow_section_name_copy) && (section == NULL))
+ if (PROFILE_Open( filename ))
+ {
+ if ((allow_section_name_copy) && (section == NULL))
ret = PROFILE_GetSectionNames(buffer, len);
- else
- /* PROFILE_GetString already handles the 'entry == NULL' case */
+ else
+ /* PROFILE_GetString already handles the 'entry == NULL' case */
ret = PROFILE_GetString( section, entry, pDefVal, buffer, len );
- } else {
- lstrcpynW( buffer, pDefVal, len );
- ret = strlenW( buffer );
+ }
+ else
+ {
+ wcsncpy( buffer, pDefVal, len );
+ ret = wcslen( buffer );
}
RtlLeaveCriticalSection( &PROFILE_CritSect );
if (pDefVal != def_val) /* allocated */
- HeapFree(GetProcessHeap(), 0, (void*)pDefVal);
+ HeapFree(GetProcessHeap(), 0, (void*)pDefVal);
- TRACE("returning %s, %d\n", debugstr_w(buffer), ret);
+ DPRINT("returning %S, %d\n", buffer, ret);
return ret;
}
-/***********************************************************************
- * GetPrivateProfileString (KERNEL.128)
- */
-INT16 WINAPI GetPrivateProfileString16( LPCSTR section, LPCSTR entry,
- LPCSTR def_val, LPSTR buffer,
- UINT16 len, LPCSTR filename )
-{
- UNICODE_STRING sectionW, entryW, def_valW, filenameW;
- LPWSTR bufferW;
- INT16 retW, ret = 0;
-
- bufferW = buffer ? HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR)) : NULL;
- if (section) RtlCreateUnicodeStringFromAsciiz(§ionW, section);
- else sectionW.Buffer = NULL;
- if (entry) RtlCreateUnicodeStringFromAsciiz(&entryW, entry);
- else entryW.Buffer = NULL;
- if (def_val) RtlCreateUnicodeStringFromAsciiz(&def_valW, def_val);
- else def_valW.Buffer = NULL;
- if (filename) RtlCreateUnicodeStringFromAsciiz(&filenameW, filename);
- else filenameW.Buffer = NULL;
-
- retW = PROFILE_GetPrivateProfileString( sectionW.Buffer, entryW.Buffer,
- def_valW.Buffer, bufferW, len,
- filenameW.Buffer, FALSE );
- if (len)
- {
- ret = WideCharToMultiByte(CP_ACP, 0, bufferW, retW + 1, buffer, len, NULL, NULL);
[truncated at 1000 lines; 434 more skipped]