Fun API Documentation 0.42.1
The programming language that makes you have fun!
Loading...
Searching...
No Matches
ini.c File Reference

iniparser helpers for Fun VM INI-related opcodes (conditional build). More...

#include <iniparser/dictionary.h>
#include <iniparser/iniparser.h>
#include <ctype.h>
#include <stdio.h>
#include <string.h>
#include <stddef.h>
Include dependency graph for ini.c:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  IniSlot
 One slot in the global INI handle registry. More...

Functions

int ini_alloc_handle (dictionary *d)
 Allocate a registry handle for a newly created dictionary.
dictionary * ini_get (int h)
 Look up a dictionary pointer by registry handle.
int ini_free_handle (int h)
 Free a previously allocated handle and close its dictionary.
void ini_make_full_key (char *buf, size_t cap, const char *sec, const char *key)
 Build a fully qualified key of the form "section:key".

Variables

IniSlot g_ini [64]
 Fixed-size registry of iniparser dictionaries.

Detailed Description

iniparser helpers for Fun VM INI-related opcodes (conditional build).

This module centralizes small utilities and a tiny handle registry used by VM opcodes that interact with INI configuration files through the iniparser library. Placing the concrete logic in src/extensions/ keeps the opcode implementations minimal — they focus on VM stack marshalling and delegate the concrete work here, mirroring other extensions (PCRE2, SQLite, XML2).

Build-time feature flag:

  • All code in this file is compiled only when FUN_WITH_INI is enabled. When disabled, INI-related opcodes should provide safe no-op fallbacks in their respective VM files.

Registry and ownership model:

  • A very small fixed-size registry (g_ini) maps small positive integers to iniparser dictionaries. The registry OWNS the dictionary pointer and will call iniparser_freedict() when a handle is freed via ini_free_handle().
  • Handles are in the range [1, 63]; 0 indicates failure/invalid.
  • The registry does not perform I/O; callers are responsible for creating the dictionary (e.g., iniparser_load()) prior to registration.

Thread-safety:

  • Not thread-safe. If used from multiple threads, coordinate access externally.

Key formatting helper:

  • ini_make_full_key() produces a section-qualified key of the form "section:key", which is what iniparser expects for lookups.

Definition in file ini.c.

Function Documentation

◆ ini_alloc_handle()

int ini_alloc_handle ( dictionary * d)

Allocate a registry handle for a newly created dictionary.

Transfers ownership of the dictionary pointer to the registry on success.

Parameters
dPointer to an initialized iniparser dictionary (e.g., from iniparser_load()). Must not be NULL.
Returns
int Positive handle (>0) on success; 0 if no free slot is available or if d is NULL.

Definition at line 92 of file ini.c.

◆ ini_free_handle()

int ini_free_handle ( int h)

Free a previously allocated handle and close its dictionary.

If the slot holds a dictionary, iniparser_freedict() is called. The slot is then marked available for reuse.

Parameters
hHandle id to free.
Returns
int 1 on success; 0 if the handle is invalid or not in use.

Definition at line 128 of file ini.c.

◆ ini_get()

dictionary * ini_get ( int h)

Look up a dictionary pointer by registry handle.

The returned pointer is owned by the registry; callers must not free it directly. Use ini_free_handle() to release the association.

Parameters
hHandle id previously returned by ini_alloc_handle().
Returns
dictionary* Pointer to dictionary if the handle is valid and in use; NULL otherwise.

Definition at line 114 of file ini.c.

◆ ini_make_full_key()

void ini_make_full_key ( char * buf,
size_t cap,
const char * sec,
const char * key )

Build a fully qualified key of the form "section:key".

Writes into a caller-provided buffer a key qualified by section, as expected by iniparser lookups. If sec is NULL, an empty section is used. If key is NULL, an empty key is used. The function is a no-op if buf is NULL or cap is

  1. Output is always NUL-terminated (subject to snprintf semantics).
Parameters
bufDestination buffer.
capCapacity of buf in bytes (including terminator).
secSection name (may be NULL for default/empty section).
keyKey name (may be NULL to produce an empty key).

Definition at line 149 of file ini.c.

Variable Documentation

◆ g_ini

IniSlot g_ini[64]

Fixed-size registry of iniparser dictionaries.

Index 0 is reserved and never used for valid handles. Valid handles are in the range [1, 63]. When an entry's in_use flag is 0, the slot is available.

Definition at line 80 of file ini.c.