Fun 0.41.5
The programming language that makes You have fun
Loading...
Searching...
No Matches
handles.c
Go to the documentation of this file.
1/*
2 * This file is part of the Fun programming language.
3 * https://fun-lang.xyz/
4 *
5 * Copyright 2025 Johannes Findeisen <you@hanez.org>
6 * Licensed under the terms of the Apache-2.0 license.
7 * https://opensource.org/license/apache-2-0
8 */
9
18
19#ifdef FUN_WITH_INI
20#if defined(__has_include)
21#if __has_include(<iniparser/iniparser.h>)
22#include <iniparser/dictionary.h>
23#include <iniparser/iniparser.h>
24#elif __has_include(<iniparser.h>)
25#include <dictionary.h>
26#include <iniparser.h>
27#else
28#error "iniparser headers not found"
29#endif
30#else
31#include <iniparser/dictionary.h>
32#include <iniparser/iniparser.h>
33#endif
34
35#include <ctype.h>
36#include <stdio.h>
37#include <string.h>
38
39#include "handles.h"
40
41IniSlot g_ini[64];
42
43int ini_alloc_handle(dictionary *d) {
44 if (!d) return 0;
45 for (int i = 1; i < (int)(sizeof(g_ini) / sizeof(g_ini[0])); ++i) {
46 if (!g_ini[i].in_use) {
47 g_ini[i].in_use = 1;
48 g_ini[i].dict = d;
49 return i;
50 }
51 }
52 return 0;
53}
54
55dictionary *ini_get(int h) {
56 if (h > 0 && h < (int)(sizeof(g_ini) / sizeof(g_ini[0])) && g_ini[h].in_use) return g_ini[h].dict;
57 return NULL;
58}
59
60int ini_free_handle(int h) {
61 if (h <= 0 || h >= (int)(sizeof(g_ini) / sizeof(g_ini[0])) || !g_ini[h].in_use) return 0;
62 if (g_ini[h].dict) iniparser_freedict(g_ini[h].dict);
63 g_ini[h].dict = NULL;
64 g_ini[h].in_use = 0;
65 return 1;
66}
67
68void ini_make_full_key(char *buf, size_t cap, const char *sec, const char *key) {
69 if (!buf || cap == 0) return;
70 if (!sec) sec = "";
71 if (!key) key = "";
72 /* iniparser expects section:key; lookup is case-insensitive internally */
73 snprintf(buf, cap, "%s:%s", sec, key);
74}
75
76#endif /* FUN_WITH_INI */
INI handle registry for iniparser 4.2.6 used by INI VM opcodes.
size_t cap
Definition input_line.c:101
char * buf
Definition input_line.c:103