From b280f86326979519043ab28c6437e3f5d6f6297d Mon Sep 17 00:00:00 2001 From: Toni Wilen Date: Wed, 17 Apr 2019 19:00:23 +0300 Subject: [PATCH] Add boolean type. --- include/ini.h | 1 + ini.cpp | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/include/ini.h b/include/ini.h index b39a7ae5..06f71d5b 100644 --- a/include/ini.h +++ b/include/ini.h @@ -36,6 +36,7 @@ void ini_addnewval64(struct ini_data *ini, const TCHAR *section, const TCHAR *ke bool ini_getstring(struct ini_data *ini, const TCHAR *section, const TCHAR *key, TCHAR **out); bool ini_getstring_multi(struct ini_data *ini, const TCHAR *section, const TCHAR *key, TCHAR **out, struct ini_context*); +bool ini_getbool(struct ini_data *ini, const TCHAR *section, const TCHAR *key, bool *v); bool ini_getval(struct ini_data *ini, const TCHAR *section, const TCHAR *key, int *v); bool ini_getval_multi(struct ini_data *ini, const TCHAR *section, const TCHAR *key, int *v, struct ini_context*); bool ini_getdata(struct ini_data *ini, const TCHAR *section, const TCHAR *key, uae_u8 **out, int *size); diff --git a/ini.cpp b/ini.cpp index c465512c..f4d49d79 100644 --- a/ini.cpp +++ b/ini.cpp @@ -357,6 +357,24 @@ bool ini_getval(struct ini_data *ini, const TCHAR *section, const TCHAR *key, in return ini_getval_multi(ini, section, key, v, NULL); } +bool ini_getbool(struct ini_data *ini, const TCHAR *section, const TCHAR *key, bool *v) +{ + TCHAR *s = NULL; + if (!ini_getstring(ini, section, key, &s)) + return false; + if (!_tcsicmp(s, _T("true")) || !_tcsicmp(s, _T("1"))) { + xfree(s); + *v = true; + return true; + } + if (!_tcsicmp(s, _T("false")) || !_tcsicmp(s, _T("0"))) { + xfree(s); + *v = false; + return true; + } + return false; +} + bool ini_getdata_multi(struct ini_data *ini, const TCHAR *section, const TCHAR *key, uae_u8 **out, int *size, struct ini_context *ctx) { TCHAR *out2 = NULL; -- 2.47.3