- Implement GetPrivateProfileSectionA/W()

- Handle value-less keys
- Handle comments

svn path=/trunk/; revision=11252
This commit is contained in:
Gé van Geldorp 2004-10-09 18:46:41 +00:00
parent 0a6aa71bb4
commit 7600e9b587

View file

@ -1,4 +1,4 @@
/* $Id: profile.c,v 1.12 2004/06/13 20:04:56 navaraf Exp $ /* $Id: profile.c,v 1.13 2004/10/09 18:46:41 gvg Exp $
* *
* Imported from Wine * Imported from Wine
* Copyright 1993 Miguel de Icaza * Copyright 1993 Miguel de Icaza
@ -186,7 +186,7 @@ PROFILE_Load(HANDLE File)
LARGE_INTEGER FileSize; LARGE_INTEGER FileSize;
HANDLE Mapping; HANDLE Mapping;
PVOID BaseAddress; PVOID BaseAddress;
char *Input, *End; char *Input, *End, *EndLine, *LastNonSpace;
FileSize.u.LowPart = GetFileSize(File, &FileSize.u.HighPart); FileSize.u.LowPart = GetFileSize(File, &FileSize.u.HighPart);
if (INVALID_FILE_SIZE == FileSize.u.LowPart && 0 != GetLastError()) if (INVALID_FILE_SIZE == FileSize.u.LowPart && 0 != GetLastError())
@ -228,7 +228,21 @@ PROFILE_Load(HANDLE File)
End = Input + FileSize.QuadPart; End = Input + FileSize.QuadPart;
while (Input < End) while (Input < End)
{ {
while (Input < End && PROFILE_isspace(*Input)) EndLine = Input;
LastNonSpace = NULL;
while (EndLine < End && '\n' != *EndLine && ';' != *EndLine)
{
if (! PROFILE_isspace(*EndLine))
{
LastNonSpace = EndLine;
}
EndLine++;
}
if (NULL != LastNonSpace)
{
EndLine = LastNonSpace + 1;
}
while (Input < EndLine && PROFILE_isspace(*Input))
{ {
Input++; Input++;
} }
@ -239,11 +253,11 @@ PROFILE_Load(HANDLE File)
if ('[' == *Input) /* section start */ if ('[' == *Input) /* section start */
{ {
p = ++Input; p = ++Input;
while (p < End && ']' != *p && '\n' != *p) while (p < EndLine && ']' != *p)
{ {
p++; p++;
} }
if (p < End && ']' == *p) if (p < EndLine && ']' == *p)
{ {
Len = p - Input; Len = p - Input;
if (NULL == (Section = HeapAlloc(GetProcessHeap(), 0, if (NULL == (Section = HeapAlloc(GetProcessHeap(), 0,
@ -274,7 +288,7 @@ PROFILE_Load(HANDLE File)
p = Input; p = Input;
p2 = p; p2 = p;
while (p < End && '=' != *p && '\n' != *p) while (p < EndLine && '=' != *p)
{ {
if (! PROFILE_isspace(*p)) if (! PROFILE_isspace(*p))
{ {
@ -283,7 +297,7 @@ PROFILE_Load(HANDLE File)
p++; p++;
} }
if (p < End && '=' == *p) if (p2 != Input)
{ {
Len = p2 - Input + 1; Len = p2 - Input + 1;
if (NULL == (Key = HeapAlloc(GetProcessHeap(), 0, if (NULL == (Key = HeapAlloc(GetProcessHeap(), 0,
@ -294,11 +308,11 @@ PROFILE_Load(HANDLE File)
MultiByteToWideChar(CP_ACP, 0, Input, Len, Key->Name, Len); MultiByteToWideChar(CP_ACP, 0, Input, Len, Key->Name, Len);
Key->Name[Len] = L'\0'; Key->Name[Len] = L'\0';
Input = p + 1; Input = p + 1;
while (Input < End && '\n' != *Input && PROFILE_isspace(*Input)) while (Input < EndLine && PROFILE_isspace(*Input))
{ {
Input++; Input++;
} }
if (End <= Input || '\n' == *Input) if (EndLine <= Input)
{ {
Key->Value = NULL; Key->Value = NULL;
} }
@ -306,7 +320,7 @@ PROFILE_Load(HANDLE File)
{ {
p2 = Input; p2 = Input;
p = Input + 1; p = Input + 1;
while (p < End && '\n' != *p) while (p < EndLine)
{ {
if (! PROFILE_isspace(*p)) if (! PROFILE_isspace(*p))
{ {
@ -322,6 +336,7 @@ PROFILE_Load(HANDLE File)
} }
MultiByteToWideChar(CP_ACP, 0, Input, Len, Key->Value, Len); MultiByteToWideChar(CP_ACP, 0, Input, Len, Key->Value, Len);
Key->Value[Len] = L'\0'; Key->Value[Len] = L'\0';
}
Key->Next = NULL; Key->Next = NULL;
*NextKey = Key; *NextKey = Key;
@ -333,7 +348,6 @@ PROFILE_Load(HANDLE File)
Input = p; Input = p;
} }
}
while (Input < End && '\n' != *Input) while (Input < End && '\n' != *Input)
{ {
Input++; Input++;
@ -1058,6 +1072,7 @@ PROFILE_Init()
BOOL STDCALL BOOL STDCALL
CloseProfileUserMapping(VOID) CloseProfileUserMapping(VOID)
{ {
DPRINT1("CloseProfileUserMapping not implemented\n");
SetLastError(ERROR_CALL_NOT_IMPLEMENTED); SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
return FALSE; return FALSE;
} }
@ -1159,34 +1174,96 @@ GetPrivateProfileIntA(
/* /*
* @unimplemented * @implemented
*/ */
DWORD STDCALL DWORD STDCALL
GetPrivateProfileSectionW ( GetPrivateProfileSectionW (
LPCWSTR lpAppName, LPCWSTR Section,
LPWSTR lpReturnedString, LPWSTR Buffer,
DWORD nSize, DWORD Len,
LPCWSTR lpFileName LPCWSTR FileName
) )
{ {
SetLastError(ERROR_CALL_NOT_IMPLEMENTED); int Ret = 0;
return 0;
DPRINT("(%S, %p, %ld, %S)\n", Section, Buffer, Len, FileName);
RtlEnterCriticalSection(&ProfileLock);
if (PROFILE_Open(FileName))
{
Ret = PROFILE_GetSection(CurProfile->Section, Section, Buffer, Len, TRUE);
}
RtlLeaveCriticalSection(&ProfileLock);
return Ret;
} }
/* /*
* @unimplemented * @implemented
*/ */
DWORD STDCALL DWORD STDCALL
GetPrivateProfileSectionA ( GetPrivateProfileSectionA (
LPCSTR lpAppName, LPCSTR Section,
LPSTR lpReturnedString, LPSTR Buffer,
DWORD nSize, DWORD Len,
LPCSTR lpFileName LPCSTR FileName
) )
{ {
SetLastError(ERROR_CALL_NOT_IMPLEMENTED); UNICODE_STRING SectionW, FileNameW;
return 0; LPWSTR BufferW;
INT RetW, Ret = 0;
BufferW = NULL != Buffer ? HeapAlloc(GetProcessHeap(), 0, Len * sizeof(WCHAR)) : NULL;
if (NULL != Section)
{
RtlCreateUnicodeStringFromAsciiz(&SectionW, Section);
}
else
{
SectionW.Buffer = NULL;
}
if (NULL != FileName)
{
RtlCreateUnicodeStringFromAsciiz(&FileNameW, FileName);
}
else
{
FileNameW.Buffer = NULL;
}
RetW = GetPrivateProfileSectionW(SectionW.Buffer, BufferW, Len, FileNameW.Buffer);
if (2 < Len)
{
Ret = WideCharToMultiByte(CP_ACP, 0, BufferW, RetW + 2, Buffer, Len, NULL, NULL);
if (2 < Ret)
{
Ret -= 2;
}
else
{
Ret = 0;
Buffer[Len-2] = '\0';
Buffer[Len-1] = '\0';
}
}
else
{
Buffer[0] = '\0';
Buffer[1] = '\0';
}
RtlFreeUnicodeString(&SectionW);
RtlFreeUnicodeString(&FileNameW);
if (NULL != BufferW)
{
HeapFree(GetProcessHeap(), 0, BufferW);
}
return Ret;
} }
@ -1393,6 +1470,7 @@ GetPrivateProfileStructW (
IN LPCWSTR File IN LPCWSTR File
) )
{ {
DPRINT1("GetPrivateProfileStructW not implemented\n");
SetLastError(ERROR_CALL_NOT_IMPLEMENTED); SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
return 0; return 0;
} }
@ -1410,6 +1488,7 @@ GetPrivateProfileStructA (
IN LPCSTR File IN LPCSTR File
) )
{ {
DPRINT1("GetPrivateProfileStructA not implemented\n");
SetLastError(ERROR_CALL_NOT_IMPLEMENTED); SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
return 0; return 0;
} }
@ -1519,6 +1598,7 @@ GetProfileStringA(LPCSTR lpAppName,
BOOL STDCALL BOOL STDCALL
OpenProfileUserMapping (VOID) OpenProfileUserMapping (VOID)
{ {
DPRINT1("OpenProfileUserMapping not implemented\n");
SetLastError(ERROR_CALL_NOT_IMPLEMENTED); SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
return 0; return 0;
} }
@ -1535,6 +1615,7 @@ QueryWin31IniFilesMappedToRegistry (
DWORD Unknown3 DWORD Unknown3
) )
{ {
DPRINT1("QueryWin31IniFilesMappedToRegistry not implemented\n");
SetLastError(ERROR_CALL_NOT_IMPLEMENTED); SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
return FALSE; return FALSE;
} }
@ -1550,6 +1631,7 @@ WritePrivateProfileSectionA (
LPCSTR lpFileName LPCSTR lpFileName
) )
{ {
DPRINT1("WritePrivateProfileSectionA not implemented\n");
SetLastError(ERROR_CALL_NOT_IMPLEMENTED); SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
return FALSE; return FALSE;
} }
@ -1565,6 +1647,7 @@ WritePrivateProfileSectionW (
LPCWSTR lpFileName LPCWSTR lpFileName
) )
{ {
DPRINT1("WritePrivateProfileSectionW not implemented\n");
SetLastError(ERROR_CALL_NOT_IMPLEMENTED); SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
return FALSE; return FALSE;
} }
@ -1679,6 +1762,7 @@ WritePrivateProfileStructA (
IN LPCSTR File IN LPCSTR File
) )
{ {
DPRINT1("WritePrivateProfileStructA not implemented\n");
SetLastError(ERROR_CALL_NOT_IMPLEMENTED); SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
return FALSE; return FALSE;
} }
@ -1696,6 +1780,7 @@ WritePrivateProfileStructW (
IN LPCWSTR File IN LPCWSTR File
) )
{ {
DPRINT1("WritePrivateProfileStructW not implemented\n");
SetLastError(ERROR_CALL_NOT_IMPLEMENTED); SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
return FALSE; return FALSE;
} }