1
0
Fork 0
forked from fun/fun

Fixed the code style in *.c files to two spaces indentation and add a linter named funstx to Fun. (0.39.0)

This commit is contained in:
Johannes Findeisen 2026-03-18 20:52:00 +01:00
commit 03b2532474
237 changed files with 17550 additions and 13911 deletions

View file

@ -12,11 +12,11 @@
/* OP_INI_FREE: pops handle; pushes 1/0 */
#ifdef FUN_WITH_INI
case OP_INI_FREE: {
Value vh = pop_value(vm);
int h = (vh.type == VAL_INT) ? (int)vh.i : 0;
free_value(vh);
int ok = ini_free_handle(h);
push_value(vm, make_int(ok));
break;
Value vh = pop_value(vm);
int h = (vh.type == VAL_INT) ? (int)vh.i : 0;
free_value(vh);
int ok = ini_free_handle(h);
push_value(vm, make_int(ok));
break;
}
#endif

View file

@ -12,51 +12,67 @@
/* OP_INI_GET_BOOL */
#ifdef FUN_WITH_INI
case OP_INI_GET_BOOL: {
Value vdef = pop_value(vm);
Value vkey = pop_value(vm);
Value vsec = pop_value(vm);
Value vh = pop_value(vm);
int def = (vdef.type==VAL_INT||vdef.type==VAL_BOOL) ? (int)vdef.i : 0;
const char *key = (vkey.type==VAL_STRING) ? vkey.s : NULL;
const char *sec = (vsec.type==VAL_STRING) ? vsec.s : NULL;
int h = (vh.type==VAL_INT) ? (int)vh.i : 0;
dictionary *d = ini_get(h);
int outb = def;
if (d && sec && key) {
char full[1024]; char alt[1024];
ini_make_full_key(full, sizeof(full), sec, key);
memcpy(alt, full, sizeof(alt));
for (size_t i = 0; i < sizeof(alt) && alt[i]; ++i) { if (alt[i] == ':') { alt[i] = '.'; break; } }
const char *s = iniparser_getstring(d, full, NULL);
if (!s) s = iniparser_getstring(d, alt, NULL);
if (s) {
/* normalize and parse boolean */
char buf[256];
size_t n = strlen(s);
if (n >= 2 && ((s[0]=='"' && s[n-1]=='"') || (s[0]=='\'' && s[n-1]=='\''))) {
size_t copy = (n-2) < sizeof(buf)-1 ? (n-2) : sizeof(buf)-1;
memcpy(buf, s+1, copy); buf[copy] = '\0';
s = buf;
}
/* trim spaces */
while (*s && (unsigned char)*s <= ' ') s++;
/* lower copy for textual booleans */
char lb[256]; size_t li=0; for (; s[li] && li < sizeof(lb)-1; ++li) lb[li] = (char)tolower((unsigned char)s[li]); lb[li]='\0';
if (strcmp(lb, "true")==0 || strcmp(lb, "yes")==0 || strcmp(lb, "on")==0) {
outb = 1;
} else if (strcmp(lb, "false")==0 || strcmp(lb, "no")==0 || strcmp(lb, "off")==0) {
outb = 0;
} else {
/* numeric */
char *endp=NULL; long v = strtol(lb, &endp, 10);
outb = (endp && endp!=lb) ? (v!=0) : def;
}
} else {
outb = def;
}
Value vdef = pop_value(vm);
Value vkey = pop_value(vm);
Value vsec = pop_value(vm);
Value vh = pop_value(vm);
int def = (vdef.type == VAL_INT || vdef.type == VAL_BOOL) ? (int)vdef.i : 0;
const char *key = (vkey.type == VAL_STRING) ? vkey.s : NULL;
const char *sec = (vsec.type == VAL_STRING) ? vsec.s : NULL;
int h = (vh.type == VAL_INT) ? (int)vh.i : 0;
dictionary *d = ini_get(h);
int outb = def;
if (d && sec && key) {
char full[1024];
char alt[1024];
ini_make_full_key(full, sizeof(full), sec, key);
memcpy(alt, full, sizeof(alt));
for (size_t i = 0; i < sizeof(alt) && alt[i]; ++i) {
if (alt[i] == ':') {
alt[i] = '.';
break;
}
}
free_value(vdef); free_value(vkey); free_value(vsec); free_value(vh);
push_value(vm, make_int(outb ? 1 : 0));
break;
const char *s = iniparser_getstring(d, full, NULL);
if (!s) s = iniparser_getstring(d, alt, NULL);
if (s) {
/* normalize and parse boolean */
char buf[256];
size_t n = strlen(s);
if (n >= 2 && ((s[0] == '"' && s[n - 1] == '"') || (s[0] == '\'' && s[n - 1] == '\''))) {
size_t copy = (n - 2) < sizeof(buf) - 1 ? (n - 2) : sizeof(buf) - 1;
memcpy(buf, s + 1, copy);
buf[copy] = '\0';
s = buf;
}
/* trim spaces */
while (*s && (unsigned char)*s <= ' ')
s++;
/* lower copy for textual booleans */
char lb[256];
size_t li = 0;
for (; s[li] && li < sizeof(lb) - 1; ++li)
lb[li] = (char)tolower((unsigned char)s[li]);
lb[li] = '\0';
if (strcmp(lb, "true") == 0 || strcmp(lb, "yes") == 0 || strcmp(lb, "on") == 0) {
outb = 1;
} else if (strcmp(lb, "false") == 0 || strcmp(lb, "no") == 0 || strcmp(lb, "off") == 0) {
outb = 0;
} else {
/* numeric */
char *endp = NULL;
long v = strtol(lb, &endp, 10);
outb = (endp && endp != lb) ? (v != 0) : def;
}
} else {
outb = def;
}
}
free_value(vdef);
free_value(vkey);
free_value(vsec);
free_value(vh);
push_value(vm, make_int(outb ? 1 : 0));
break;
}
#endif

View file

@ -12,41 +12,55 @@
/* OP_INI_GET_DOUBLE */
#ifdef FUN_WITH_INI
case OP_INI_GET_DOUBLE: {
Value vdef = pop_value(vm);
Value vkey = pop_value(vm);
Value vsec = pop_value(vm);
Value vh = pop_value(vm);
double def = (vdef.type==VAL_FLOAT) ? vdef.d : (vdef.type==VAL_INT ? (double)vdef.i : 0.0);
const char *key = (vkey.type==VAL_STRING) ? vkey.s : NULL;
const char *sec = (vsec.type==VAL_STRING) ? vsec.s : NULL;
int h = (vh.type==VAL_INT) ? (int)vh.i : 0;
dictionary *d = ini_get(h);
double outd = def;
if (d && sec && key) {
char full[1024]; char alt[1024];
ini_make_full_key(full, sizeof(full), sec, key);
memcpy(alt, full, sizeof(alt));
for (size_t i = 0; i < sizeof(alt) && alt[i]; ++i) { if (alt[i] == ':') { alt[i] = '.'; break; } }
const char *s = iniparser_getstring(d, full, NULL);
if (!s) s = iniparser_getstring(d, alt, NULL);
if (s) {
char buf[256];
size_t n = strlen(s);
if (n >= 2 && ((s[0]=='"' && s[n-1]=='"') || (s[0]=='\'' && s[n-1]=='\''))) {
size_t copy = (n-2) < sizeof(buf)-1 ? (n-2) : sizeof(buf)-1;
memcpy(buf, s+1, copy); buf[copy] = '\0';
s = buf;
}
while (*s && (unsigned char)*s <= ' ') s++;
char *endp = NULL;
double v = strtod(s, &endp);
if (endp && endp != s) outd = v; else outd = def;
} else {
outd = def;
}
Value vdef = pop_value(vm);
Value vkey = pop_value(vm);
Value vsec = pop_value(vm);
Value vh = pop_value(vm);
double def = (vdef.type == VAL_FLOAT) ? vdef.d : (vdef.type == VAL_INT ? (double)vdef.i : 0.0);
const char *key = (vkey.type == VAL_STRING) ? vkey.s : NULL;
const char *sec = (vsec.type == VAL_STRING) ? vsec.s : NULL;
int h = (vh.type == VAL_INT) ? (int)vh.i : 0;
dictionary *d = ini_get(h);
double outd = def;
if (d && sec && key) {
char full[1024];
char alt[1024];
ini_make_full_key(full, sizeof(full), sec, key);
memcpy(alt, full, sizeof(alt));
for (size_t i = 0; i < sizeof(alt) && alt[i]; ++i) {
if (alt[i] == ':') {
alt[i] = '.';
break;
}
}
free_value(vdef); free_value(vkey); free_value(vsec); free_value(vh);
push_value(vm, make_float(outd));
break;
const char *s = iniparser_getstring(d, full, NULL);
if (!s) s = iniparser_getstring(d, alt, NULL);
if (s) {
char buf[256];
size_t n = strlen(s);
if (n >= 2 && ((s[0] == '"' && s[n - 1] == '"') || (s[0] == '\'' && s[n - 1] == '\''))) {
size_t copy = (n - 2) < sizeof(buf) - 1 ? (n - 2) : sizeof(buf) - 1;
memcpy(buf, s + 1, copy);
buf[copy] = '\0';
s = buf;
}
while (*s && (unsigned char)*s <= ' ')
s++;
char *endp = NULL;
double v = strtod(s, &endp);
if (endp && endp != s)
outd = v;
else
outd = def;
} else {
outd = def;
}
}
free_value(vdef);
free_value(vkey);
free_value(vsec);
free_value(vh);
push_value(vm, make_float(outd));
break;
}
#endif

View file

@ -12,43 +12,57 @@
/* OP_INI_GET_INT */
#ifdef FUN_WITH_INI
case OP_INI_GET_INT: {
Value vdef = pop_value(vm);
Value vkey = pop_value(vm);
Value vsec = pop_value(vm);
Value vh = pop_value(vm);
int def = (vdef.type==VAL_INT) ? (int)vdef.i : 0;
const char *key = (vkey.type==VAL_STRING) ? vkey.s : NULL;
const char *sec = (vsec.type==VAL_STRING) ? vsec.s : NULL;
int h = (vh.type==VAL_INT) ? (int)vh.i : 0;
dictionary *d = ini_get(h);
int outi = def;
if (d && sec && key) {
char full[1024]; char alt[1024];
ini_make_full_key(full, sizeof(full), sec, key);
memcpy(alt, full, sizeof(alt));
for (size_t i = 0; i < sizeof(alt) && alt[i]; ++i) { if (alt[i] == ':') { alt[i] = '.'; break; } }
const char *s = iniparser_getstring(d, full, NULL);
if (!s) s = iniparser_getstring(d, alt, NULL);
if (s) {
/* strip optional quotes and parse */
char buf[256];
size_t n = strlen(s);
if (n >= 2 && ((s[0]=='"' && s[n-1]=='"') || (s[0]=='\'' && s[n-1]=='\''))) {
size_t copy = (n-2) < sizeof(buf)-1 ? (n-2) : sizeof(buf)-1;
memcpy(buf, s+1, copy); buf[copy] = '\0';
s = buf;
}
/* skip leading spaces */
while (*s && (unsigned char)*s <= ' ') s++;
char *endp = NULL;
long v = strtol(s, &endp, 10);
if (endp && endp != s) outi = (int)v; else outi = def;
} else {
outi = def;
}
Value vdef = pop_value(vm);
Value vkey = pop_value(vm);
Value vsec = pop_value(vm);
Value vh = pop_value(vm);
int def = (vdef.type == VAL_INT) ? (int)vdef.i : 0;
const char *key = (vkey.type == VAL_STRING) ? vkey.s : NULL;
const char *sec = (vsec.type == VAL_STRING) ? vsec.s : NULL;
int h = (vh.type == VAL_INT) ? (int)vh.i : 0;
dictionary *d = ini_get(h);
int outi = def;
if (d && sec && key) {
char full[1024];
char alt[1024];
ini_make_full_key(full, sizeof(full), sec, key);
memcpy(alt, full, sizeof(alt));
for (size_t i = 0; i < sizeof(alt) && alt[i]; ++i) {
if (alt[i] == ':') {
alt[i] = '.';
break;
}
}
free_value(vdef); free_value(vkey); free_value(vsec); free_value(vh);
push_value(vm, make_int(outi));
break;
const char *s = iniparser_getstring(d, full, NULL);
if (!s) s = iniparser_getstring(d, alt, NULL);
if (s) {
/* strip optional quotes and parse */
char buf[256];
size_t n = strlen(s);
if (n >= 2 && ((s[0] == '"' && s[n - 1] == '"') || (s[0] == '\'' && s[n - 1] == '\''))) {
size_t copy = (n - 2) < sizeof(buf) - 1 ? (n - 2) : sizeof(buf) - 1;
memcpy(buf, s + 1, copy);
buf[copy] = '\0';
s = buf;
}
/* skip leading spaces */
while (*s && (unsigned char)*s <= ' ')
s++;
char *endp = NULL;
long v = strtol(s, &endp, 10);
if (endp && endp != s)
outi = (int)v;
else
outi = def;
} else {
outi = def;
}
}
free_value(vdef);
free_value(vkey);
free_value(vsec);
free_value(vh);
push_value(vm, make_int(outi));
break;
}
#endif

View file

@ -12,34 +12,42 @@
/* OP_INI_GET_STRING */
#ifdef FUN_WITH_INI
case OP_INI_GET_STRING: {
Value vdef = pop_value(vm);
Value vkey = pop_value(vm);
Value vsec = pop_value(vm);
Value vh = pop_value(vm);
const char *def = (vdef.type==VAL_STRING && vdef.s) ? vdef.s : "";
const char *key = (vkey.type==VAL_STRING) ? vkey.s : NULL;
const char *sec = (vsec.type==VAL_STRING) ? vsec.s : NULL;
int h = (vh.type==VAL_INT) ? (int)vh.i : 0;
dictionary *d = ini_get(h);
const char *res = def;
if (d && sec && key) {
char full[1024]; char alt[1024];
ini_make_full_key(full, sizeof(full), sec, key);
/* Build alternate with dot separator for robustness */
ini_make_full_key(alt, sizeof(alt), sec, key);
size_t flen = strlen(full);
if (flen < sizeof(alt) && flen > 0) { /* create dot version in alt */
memcpy(alt, full, flen + 1);
for (size_t i = 0; i < flen; ++i) if (alt[i] == ':') { alt[i] = '.'; break; }
Value vdef = pop_value(vm);
Value vkey = pop_value(vm);
Value vsec = pop_value(vm);
Value vh = pop_value(vm);
const char *def = (vdef.type == VAL_STRING && vdef.s) ? vdef.s : "";
const char *key = (vkey.type == VAL_STRING) ? vkey.s : NULL;
const char *sec = (vsec.type == VAL_STRING) ? vsec.s : NULL;
int h = (vh.type == VAL_INT) ? (int)vh.i : 0;
dictionary *d = ini_get(h);
const char *res = def;
if (d && sec && key) {
char full[1024];
char alt[1024];
ini_make_full_key(full, sizeof(full), sec, key);
/* Build alternate with dot separator for robustness */
ini_make_full_key(alt, sizeof(alt), sec, key);
size_t flen = strlen(full);
if (flen < sizeof(alt) && flen > 0) { /* create dot version in alt */
memcpy(alt, full, flen + 1);
for (size_t i = 0; i < flen; ++i)
if (alt[i] == ':') {
alt[i] = '.';
break;
}
const char *s = iniparser_getstring(d, full, def);
if (s == def) { /* not found, try alternate dot form */
s = iniparser_getstring(d, alt, def);
}
res = s ? s : "";
}
free_value(vdef); free_value(vkey); free_value(vsec); free_value(vh);
push_value(vm, make_string(res));
break;
const char *s = iniparser_getstring(d, full, def);
if (s == def) { /* not found, try alternate dot form */
s = iniparser_getstring(d, alt, def);
}
res = s ? s : "";
}
free_value(vdef);
free_value(vkey);
free_value(vsec);
free_value(vh);
push_value(vm, make_string(res));
break;
}
#endif

View file

@ -9,55 +9,59 @@
#ifdef FUN_WITH_INI
#if defined(__has_include)
# if __has_include(<iniparser/iniparser.h>)
# include <iniparser/iniparser.h>
# include <iniparser/dictionary.h>
# elif __has_include(<iniparser.h>)
# include <iniparser.h>
# include <dictionary.h>
# else
# error "iniparser headers not found"
# endif
#if __has_include(<iniparser/iniparser.h>)
#include <iniparser/dictionary.h>
#include <iniparser/iniparser.h>
#elif __has_include(<iniparser.h>)
#include <dictionary.h>
#include <iniparser.h>
#else
# include <iniparser/iniparser.h>
# include <iniparser/dictionary.h>
#error "iniparser headers not found"
#endif
#else
#include <iniparser/dictionary.h>
#include <iniparser/iniparser.h>
#endif
#include <ctype.h>
#include <string.h>
#include <stdio.h>
#include <string.h>
#include "handles.h"
IniSlot g_ini[64];
int ini_alloc_handle(dictionary *d) {
if (!d) return 0;
for (int i = 1; i < (int)(sizeof(g_ini)/sizeof(g_ini[0])); ++i) {
if (!g_ini[i].in_use) { g_ini[i].in_use = 1; g_ini[i].dict = d; return i; }
if (!d) return 0;
for (int i = 1; i < (int)(sizeof(g_ini) / sizeof(g_ini[0])); ++i) {
if (!g_ini[i].in_use) {
g_ini[i].in_use = 1;
g_ini[i].dict = d;
return i;
}
return 0;
}
return 0;
}
dictionary* ini_get(int h) {
if (h > 0 && h < (int)(sizeof(g_ini)/sizeof(g_ini[0])) && g_ini[h].in_use) return g_ini[h].dict;
return NULL;
dictionary *ini_get(int h) {
if (h > 0 && h < (int)(sizeof(g_ini) / sizeof(g_ini[0])) && g_ini[h].in_use) return g_ini[h].dict;
return NULL;
}
int ini_free_handle(int h) {
if (h <= 0 || h >= (int)(sizeof(g_ini)/sizeof(g_ini[0])) || !g_ini[h].in_use) return 0;
if (g_ini[h].dict) iniparser_freedict(g_ini[h].dict);
g_ini[h].dict = NULL;
g_ini[h].in_use = 0;
return 1;
if (h <= 0 || h >= (int)(sizeof(g_ini) / sizeof(g_ini[0])) || !g_ini[h].in_use) return 0;
if (g_ini[h].dict) iniparser_freedict(g_ini[h].dict);
g_ini[h].dict = NULL;
g_ini[h].in_use = 0;
return 1;
}
void ini_make_full_key(char *buf, size_t cap, const char *sec, const char *key) {
if (!buf || cap == 0) return;
if (!sec) sec = "";
if (!key) key = "";
/* iniparser expects section:key; lookup is case-insensitive internally */
snprintf(buf, cap, "%s:%s", sec, key);
if (!buf || cap == 0) return;
if (!sec) sec = "";
if (!key) key = "";
/* iniparser expects section:key; lookup is case-insensitive internally */
snprintf(buf, cap, "%s:%s", sec, key);
}
#endif /* FUN_WITH_INI */

View file

@ -14,29 +14,32 @@
#ifdef FUN_WITH_INI
#if defined(__has_include)
# if __has_include(<iniparser/iniparser.h>)
# include <iniparser/iniparser.h>
# include <iniparser/dictionary.h>
# elif __has_include(<iniparser.h>)
# include <iniparser.h>
# include <dictionary.h>
# else
# error "iniparser headers not found"
# endif
#if __has_include(<iniparser/iniparser.h>)
#include <iniparser/dictionary.h>
#include <iniparser/iniparser.h>
#elif __has_include(<iniparser.h>)
#include <dictionary.h>
#include <iniparser.h>
#else
# include <iniparser/iniparser.h>
# include <iniparser/dictionary.h>
#error "iniparser headers not found"
#endif
#else
#include <iniparser/dictionary.h>
#include <iniparser/iniparser.h>
#endif
#include <stddef.h>
typedef struct { dictionary *dict; int in_use; } IniSlot;
typedef struct {
dictionary *dict;
int in_use;
} IniSlot;
/* Single global registry (defined in handles.c) */
extern IniSlot g_ini[64];
/* Registry API (implemented in handles.c) */
int ini_alloc_handle(dictionary *d);
dictionary* ini_get(int h);
dictionary *ini_get(int h);
int ini_free_handle(int h);
/* Helper to build section:key string safely into provided buffer (implemented in handles.c) */

View file

@ -12,18 +12,20 @@
/* OP_INI_LOAD: pops path string; pushes handle (>0) or 0 */
#ifdef FUN_WITH_INI
case OP_INI_LOAD: {
Value vpath = pop_value(vm);
const char *path = (vpath.type == VAL_STRING && vpath.s) ? vpath.s : NULL;
int h = 0;
if (path) {
dictionary *d = iniparser_load(path);
if (d) {
h = ini_alloc_handle(d);
if (!h) { iniparser_freedict(d); }
}
Value vpath = pop_value(vm);
const char *path = (vpath.type == VAL_STRING && vpath.s) ? vpath.s : NULL;
int h = 0;
if (path) {
dictionary *d = iniparser_load(path);
if (d) {
h = ini_alloc_handle(d);
if (!h) {
iniparser_freedict(d);
}
}
free_value(vpath);
push_value(vm, make_int(h));
break;
}
free_value(vpath);
push_value(vm, make_int(h));
break;
}
#endif

View file

@ -12,17 +12,22 @@
/* OP_INI_SAVE */
#ifdef FUN_WITH_INI
case OP_INI_SAVE: {
Value vpath = pop_value(vm);
Value vh = pop_value(vm);
const char *path = (vpath.type==VAL_STRING)?vpath.s:NULL;
dictionary *d = ini_get((vh.type==VAL_INT)?(int)vh.i:0);
int ok = 0;
if (d && path) {
FILE *f = fopen(path, "w");
if (f) { iniparser_dump_ini(d, f); fclose(f); ok = 1; }
Value vpath = pop_value(vm);
Value vh = pop_value(vm);
const char *path = (vpath.type == VAL_STRING) ? vpath.s : NULL;
dictionary *d = ini_get((vh.type == VAL_INT) ? (int)vh.i : 0);
int ok = 0;
if (d && path) {
FILE *f = fopen(path, "w");
if (f) {
iniparser_dump_ini(d, f);
fclose(f);
ok = 1;
}
free_value(vpath); free_value(vh);
push_value(vm, make_int(ok));
break;
}
free_value(vpath);
free_value(vh);
push_value(vm, make_int(ok));
break;
}
#endif

View file

@ -12,32 +12,41 @@
/* OP_INI_SET */
#ifdef FUN_WITH_INI
case OP_INI_SET: {
Value vval = pop_value(vm);
Value vkey = pop_value(vm);
Value vsec = pop_value(vm);
Value vh = pop_value(vm);
dictionary *d = ini_get((vh.type==VAL_INT)?(int)vh.i:0);
const char *key = (vkey.type==VAL_STRING)?vkey.s:NULL;
const char *sec = (vsec.type==VAL_STRING)?vsec.s:NULL;
int ok = 0;
if (d && sec && key) {
char *valstr = value_to_string_alloc(&vval);
if (valstr) {
char full[1024]; char alt[1024];
ini_make_full_key(full, sizeof(full), sec, key);
memcpy(alt, full, sizeof(alt));
for (size_t i = 0; i < sizeof(alt) && alt[i]; ++i) { if (alt[i] == ':') { alt[i] = '.'; break; } }
/* iniparser 4.x does not expose iniparser_set; use dictionary_set */
if (dictionary_set(d, full, valstr) == 0) {
ok = 1; /* 0 means success */
} else if (dictionary_set(d, alt, valstr) == 0) {
ok = 1;
}
free(valstr);
Value vval = pop_value(vm);
Value vkey = pop_value(vm);
Value vsec = pop_value(vm);
Value vh = pop_value(vm);
dictionary *d = ini_get((vh.type == VAL_INT) ? (int)vh.i : 0);
const char *key = (vkey.type == VAL_STRING) ? vkey.s : NULL;
const char *sec = (vsec.type == VAL_STRING) ? vsec.s : NULL;
int ok = 0;
if (d && sec && key) {
char *valstr = value_to_string_alloc(&vval);
if (valstr) {
char full[1024];
char alt[1024];
ini_make_full_key(full, sizeof(full), sec, key);
memcpy(alt, full, sizeof(alt));
for (size_t i = 0; i < sizeof(alt) && alt[i]; ++i) {
if (alt[i] == ':') {
alt[i] = '.';
break;
}
}
/* iniparser 4.x does not expose iniparser_set; use dictionary_set */
if (dictionary_set(d, full, valstr) == 0) {
ok = 1; /* 0 means success */
} else if (dictionary_set(d, alt, valstr) == 0) {
ok = 1;
}
free(valstr);
}
free_value(vval); free_value(vkey); free_value(vsec); free_value(vh);
push_value(vm, make_int(ok));
break;
}
free_value(vval);
free_value(vkey);
free_value(vsec);
free_value(vh);
push_value(vm, make_int(ok));
break;
}
#endif

View file

@ -5,100 +5,114 @@
/* OP_INI_LOAD: pops path string; pushes 0 (invalid handle) */
case OP_INI_LOAD: {
Value vpath = pop_value(vm);
(void)vpath; /* unused */
free_value(vpath);
fun_vm_fprintf(stderr, "Runtime error: INI support disabled (rebuild with -DFUN_WITH_INI=ON)\n");
push_value(vm, make_int(0));
break;
Value vpath = pop_value(vm);
(void)vpath; /* unused */
free_value(vpath);
fun_vm_fprintf(stderr, "Runtime error: INI support disabled (rebuild with -DFUN_WITH_INI=ON)\n");
push_value(vm, make_int(0));
break;
}
/* OP_INI_FREE: pops handle; pushes 0 */
case OP_INI_FREE: {
Value vh = pop_value(vm);
free_value(vh);
fun_vm_fprintf(stderr, "Runtime error: INI support disabled (rebuild with -DFUN_WITH_INI=ON)\n");
push_value(vm, make_int(0));
break;
Value vh = pop_value(vm);
free_value(vh);
fun_vm_fprintf(stderr, "Runtime error: INI support disabled (rebuild with -DFUN_WITH_INI=ON)\n");
push_value(vm, make_int(0));
break;
}
/* Getters: pop args; push defaults (string:"", int:0, double:0.0, bool:0) */
case OP_INI_GET_STRING: {
Value vdef = pop_value(vm);
Value vkey = pop_value(vm);
Value vsec = pop_value(vm);
Value vh = pop_value(vm);
free_value(vh); free_value(vsec); free_value(vkey);
/* cannot convert here; return empty string */
push_value(vm, make_string(""));
free_value(vdef);
fun_vm_fprintf(stderr, "Runtime error: INI support disabled (rebuild with -DFUN_WITH_INI=ON)\n");
break;
Value vdef = pop_value(vm);
Value vkey = pop_value(vm);
Value vsec = pop_value(vm);
Value vh = pop_value(vm);
free_value(vh);
free_value(vsec);
free_value(vkey);
/* cannot convert here; return empty string */
push_value(vm, make_string(""));
free_value(vdef);
fun_vm_fprintf(stderr, "Runtime error: INI support disabled (rebuild with -DFUN_WITH_INI=ON)\n");
break;
}
case OP_INI_GET_INT: {
Value vdef = pop_value(vm);
Value vkey = pop_value(vm);
Value vsec = pop_value(vm);
Value vh = pop_value(vm);
free_value(vh); free_value(vsec); free_value(vkey);
(void)vdef; /* unused */
push_value(vm, make_int(0));
fun_vm_fprintf(stderr, "Runtime error: INI support disabled (rebuild with -DFUN_WITH_INI=ON)\n");
break;
Value vdef = pop_value(vm);
Value vkey = pop_value(vm);
Value vsec = pop_value(vm);
Value vh = pop_value(vm);
free_value(vh);
free_value(vsec);
free_value(vkey);
(void)vdef; /* unused */
push_value(vm, make_int(0));
fun_vm_fprintf(stderr, "Runtime error: INI support disabled (rebuild with -DFUN_WITH_INI=ON)\n");
break;
}
case OP_INI_GET_DOUBLE: {
Value vdef = pop_value(vm);
Value vkey = pop_value(vm);
Value vsec = pop_value(vm);
Value vh = pop_value(vm);
free_value(vh); free_value(vsec); free_value(vkey);
(void)vdef; /* unused */
push_value(vm, make_float(0.0));
fun_vm_fprintf(stderr, "Runtime error: INI support disabled (rebuild with -DFUN_WITH_INI=ON)\n");
break;
Value vdef = pop_value(vm);
Value vkey = pop_value(vm);
Value vsec = pop_value(vm);
Value vh = pop_value(vm);
free_value(vh);
free_value(vsec);
free_value(vkey);
(void)vdef; /* unused */
push_value(vm, make_float(0.0));
fun_vm_fprintf(stderr, "Runtime error: INI support disabled (rebuild with -DFUN_WITH_INI=ON)\n");
break;
}
case OP_INI_GET_BOOL: {
Value vdef = pop_value(vm);
Value vkey = pop_value(vm);
Value vsec = pop_value(vm);
Value vh = pop_value(vm);
free_value(vh); free_value(vsec); free_value(vkey);
(void)vdef; /* unused */
push_value(vm, make_int(0));
fun_vm_fprintf(stderr, "Runtime error: INI support disabled (rebuild with -DFUN_WITH_INI=ON)\n");
break;
Value vdef = pop_value(vm);
Value vkey = pop_value(vm);
Value vsec = pop_value(vm);
Value vh = pop_value(vm);
free_value(vh);
free_value(vsec);
free_value(vkey);
(void)vdef; /* unused */
push_value(vm, make_int(0));
fun_vm_fprintf(stderr, "Runtime error: INI support disabled (rebuild with -DFUN_WITH_INI=ON)\n");
break;
}
/* Mutators: return 0 */
case OP_INI_SET: {
Value vval = pop_value(vm);
Value vkey = pop_value(vm);
Value vsec = pop_value(vm);
Value vh = pop_value(vm);
free_value(vh); free_value(vsec); free_value(vkey); free_value(vval);
fun_vm_fprintf(stderr, "Runtime error: INI support disabled (rebuild with -DFUN_WITH_INI=ON)\n");
push_value(vm, make_int(0));
break;
Value vval = pop_value(vm);
Value vkey = pop_value(vm);
Value vsec = pop_value(vm);
Value vh = pop_value(vm);
free_value(vh);
free_value(vsec);
free_value(vkey);
free_value(vval);
fun_vm_fprintf(stderr, "Runtime error: INI support disabled (rebuild with -DFUN_WITH_INI=ON)\n");
push_value(vm, make_int(0));
break;
}
case OP_INI_UNSET: {
Value vkey = pop_value(vm);
Value vsec = pop_value(vm);
Value vh = pop_value(vm);
free_value(vh); free_value(vsec); free_value(vkey);
fun_vm_fprintf(stderr, "Runtime error: INI support disabled (rebuild with -DFUN_WITH_INI=ON)\n");
push_value(vm, make_int(0));
break;
Value vkey = pop_value(vm);
Value vsec = pop_value(vm);
Value vh = pop_value(vm);
free_value(vh);
free_value(vsec);
free_value(vkey);
fun_vm_fprintf(stderr, "Runtime error: INI support disabled (rebuild with -DFUN_WITH_INI=ON)\n");
push_value(vm, make_int(0));
break;
}
case OP_INI_SAVE: {
Value vpath = pop_value(vm);
Value vh = pop_value(vm);
free_value(vh); free_value(vpath);
fun_vm_fprintf(stderr, "Runtime error: INI support disabled (rebuild with -DFUN_WITH_INI=ON)\n");
push_value(vm, make_int(0));
break;
Value vpath = pop_value(vm);
Value vh = pop_value(vm);
free_value(vh);
free_value(vpath);
fun_vm_fprintf(stderr, "Runtime error: INI support disabled (rebuild with -DFUN_WITH_INI=ON)\n");
push_value(vm, make_int(0));
break;
}

View file

@ -12,25 +12,33 @@
/* OP_INI_UNSET */
#ifdef FUN_WITH_INI
case OP_INI_UNSET: {
Value vkey = pop_value(vm);
Value vsec = pop_value(vm);
Value vh = pop_value(vm);
dictionary *d = ini_get((vh.type==VAL_INT)?(int)vh.i:0);
const char *key = (vkey.type==VAL_STRING)?vkey.s:NULL;
const char *sec = (vsec.type==VAL_STRING)?vsec.s:NULL;
int ok = 0;
if (d && sec && key) {
char full[1024]; char alt[1024];
ini_make_full_key(full, sizeof(full), sec, key);
memcpy(alt, full, sizeof(alt));
for (size_t i = 0; i < sizeof(alt) && alt[i]; ++i) { if (alt[i] == ':') { alt[i] = '.'; break; } }
/* iniparser 4.2.6 dictionary_unset returns void; remove both forms */
dictionary_unset(d, full);
dictionary_unset(d, alt);
ok = 1;
Value vkey = pop_value(vm);
Value vsec = pop_value(vm);
Value vh = pop_value(vm);
dictionary *d = ini_get((vh.type == VAL_INT) ? (int)vh.i : 0);
const char *key = (vkey.type == VAL_STRING) ? vkey.s : NULL;
const char *sec = (vsec.type == VAL_STRING) ? vsec.s : NULL;
int ok = 0;
if (d && sec && key) {
char full[1024];
char alt[1024];
ini_make_full_key(full, sizeof(full), sec, key);
memcpy(alt, full, sizeof(alt));
for (size_t i = 0; i < sizeof(alt) && alt[i]; ++i) {
if (alt[i] == ':') {
alt[i] = '.';
break;
}
}
free_value(vkey); free_value(vsec); free_value(vh);
push_value(vm, make_int(ok));
break;
/* iniparser 4.2.6 dictionary_unset returns void; remove both forms */
dictionary_unset(d, full);
dictionary_unset(d, alt);
ok = 1;
}
free_value(vkey);
free_value(vsec);
free_value(vh);
push_value(vm, make_int(ok));
break;
}
#endif