Fun 0.41.5
The programming language that makes you have fun!
Loading...
Searching...
No Matches
handles.h
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
10/**
11 * @file handles.h
12 * @brief INI handle registry for iniparser 4.2.6 used by INI VM opcodes.
13 */
14
15#pragma once
16
17#ifdef FUN_WITH_INI
18#if defined(__has_include)
19#if __has_include(<iniparser/iniparser.h>)
20#include <iniparser/dictionary.h>
21#include <iniparser/iniparser.h>
22#elif __has_include(<iniparser.h>)
23#include <dictionary.h>
24#include <iniparser.h>
25#else
26#error "iniparser headers not found"
27#endif
28#else
29#include <iniparser/dictionary.h>
30#include <iniparser/iniparser.h>
31#endif
32#include <stddef.h>
33
34/**
35 * @brief One slot in the global INI handle registry.
36 * @details Associates an iniparser dictionary pointer with an in-use flag.
37 */
38typedef struct {
39 dictionary *dict;
40 int in_use;
41} IniSlot;
42
43/** Single global registry (defined in handles.c). */
44extern IniSlot g_ini[64];
45
46/**
47 * @brief Allocate a registry handle for a newly created dictionary.
48 * @param d Pointer to an iniparser dictionary.
49 * @return Handle id (>0) on success or 0 on failure.
50 */
51int ini_alloc_handle(dictionary *d);
52/**
53 * @brief Look up a dictionary pointer by registry handle.
54 * @param h Handle id previously returned by ini_alloc_handle().
55 * @return Pointer to dictionary or NULL if not found.
56 */
57dictionary *ini_get(int h);
58/**
59 * @brief Free a previously allocated handle and close its dictionary.
60 * @param h Handle id to free.
61 * @return 1 on success, 0 on error (invalid handle or not in use).
62 */
63int ini_free_handle(int h);
64
65/**
66 * @brief Build a fully qualified key "section:key" into a caller-provided buffer.
67 * @param buf Destination buffer.
68 * @param cap Capacity of buf in bytes (including terminator).
69 * @param sec Section name (may be NULL for default section).
70 * @param key Key name (must not be NULL).
71 */
72void ini_make_full_key(char *buf, size_t cap, const char *sec, const char *key);
73#endif /* FUN_WITH_INI */
CURL * h
Definition download.c:59
FunCurlBuf buf
Definition get.c:48
const char * sec
Definition get_bool.c:41
const char * key
Definition get_bool.c:40
dictionary * d
Definition get_bool.c:43
IniSlot g_ini[64]
Definition handles.c:41
dictionary * ini_get(int h)
Look up a dictionary pointer by registry handle.
Definition handles.c:55
int ini_free_handle(int h)
Free a previously allocated handle and close its dictionary.
Definition handles.c:60
int ini_alloc_handle(dictionary *d)
Allocate a registry handle for a newly created dictionary.
Definition handles.c:43
void ini_make_full_key(char *buf, size_t cap, const char *sec, const char *key)
Build a fully qualified key "section:key" into a caller-provided buffer.
Definition handles.c:68
size_t cap
Definition input_line.c:101
One slot in the global INI handle registry.
Definition handles.h:38
dictionary * dict
Definition handles.h:39
int in_use
Definition handles.h:40