mirror of
https://github.com/FunkyFr3sh/cnc-ddraw.git
synced 2025-03-15 06:04:49 +01:00
add new .ini function ini_section_exists
This commit is contained in:
parent
c029c9c1e5
commit
f79b7db8cd
@ -12,6 +12,7 @@ typedef struct
|
|||||||
} INIFILE;
|
} INIFILE;
|
||||||
|
|
||||||
void ini_create(INIFILE* ini, char* filename);
|
void ini_create(INIFILE* ini, char* filename);
|
||||||
|
BOOL ini_section_exists(INIFILE* ini, LPCSTR section);
|
||||||
DWORD ini_get_string(INIFILE* ini, LPCSTR section, LPCSTR key, LPCSTR def, LPSTR buf, DWORD size);
|
DWORD ini_get_string(INIFILE* ini, LPCSTR section, LPCSTR key, LPCSTR def, LPSTR buf, DWORD size);
|
||||||
BOOL ini_get_bool(INIFILE* ini, LPCSTR section, LPCSTR key, BOOL def);
|
BOOL ini_get_bool(INIFILE* ini, LPCSTR section, LPCSTR key, BOOL def);
|
||||||
int ini_get_int(INIFILE* ini, LPCSTR section, LPCSTR key, int def);
|
int ini_get_int(INIFILE* ini, LPCSTR section, LPCSTR key, int def);
|
||||||
|
29
src/ini.c
29
src/ini.c
@ -67,6 +67,33 @@ void ini_create(INIFILE* ini, char* filename)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BOOL ini_section_exists(INIFILE* ini, LPCSTR section)
|
||||||
|
{
|
||||||
|
if (!ini || !ini->sections || !section || strlen(section) == 0)
|
||||||
|
{
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
char s[MAX_PATH];
|
||||||
|
strncpy(s, section, sizeof(s) - 1);
|
||||||
|
s[sizeof(s) - 1] = 0;
|
||||||
|
|
||||||
|
for (char* p = s; *p; ++p)
|
||||||
|
*p = tolower(*p);
|
||||||
|
|
||||||
|
unsigned long hash = Crc32_ComputeBuf(0, s, strlen(s));
|
||||||
|
|
||||||
|
for (int i = 0; ini->sections[i].hash; i++)
|
||||||
|
{
|
||||||
|
if (ini->sections[i].hash == hash)
|
||||||
|
{
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
DWORD ini_get_string(INIFILE* ini, LPCSTR section, LPCSTR key, LPCSTR def, LPSTR buf, DWORD size)
|
DWORD ini_get_string(INIFILE* ini, LPCSTR section, LPCSTR key, LPCSTR def, LPSTR buf, DWORD size)
|
||||||
{
|
{
|
||||||
if (!buf || size == 0)
|
if (!buf || size == 0)
|
||||||
@ -88,7 +115,7 @@ DWORD ini_get_string(INIFILE* ini, LPCSTR section, LPCSTR key, LPCSTR def, LPSTR
|
|||||||
|
|
||||||
char s[MAX_PATH];
|
char s[MAX_PATH];
|
||||||
strncpy(s, section, sizeof(s) - 1);
|
strncpy(s, section, sizeof(s) - 1);
|
||||||
buf[sizeof(s) - 1] = 0;
|
s[sizeof(s) - 1] = 0;
|
||||||
|
|
||||||
for (char* p = s; *p; ++p)
|
for (char* p = s; *p; ++p)
|
||||||
*p = tolower(*p);
|
*p = tolower(*p);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user