#include <emscripten/emscripten.h>

#include "emc/ini/inifile.h"

extern "C" {

EMSCRIPTEN_KEEPALIVE
int lcini_get_string(const char *inipath,
                     const char *section,
                     const char *tag,
                     char *buf,
                     int bufsize) {
    return iniFindString(inipath, tag, section, buf, static_cast<size_t>(bufsize));
}

EMSCRIPTEN_KEEPALIVE
int lcini_get_bool(const char *inipath,
                   const char *section,
                   const char *tag,
                   int *result) {
    bool value = false;
    const int rc = iniFindBool(inipath, tag, section, &value);
    if (rc == 0 && result) {
        *result = value ? 1 : 0;
    }
    return rc;
}

EMSCRIPTEN_KEEPALIVE
int lcini_tilde_expand(const char *path, char *buf, int bufsize) {
    return TildeExpansion(path, buf, static_cast<size_t>(bufsize));
}

}
