Renamed ./src/external to ./src/extensions. No code logic changes. (0.40.5)
This commit is contained in:
parent
529acb77b1
commit
bb704a3778
25 changed files with 81 additions and 414 deletions
196
src/external/libressl.c
vendored
196
src/external/libressl.c
vendored
|
|
@ -1,196 +0,0 @@
|
|||
/*
|
||||
* This file is part of the Fun programming language.
|
||||
* https://fun-lang.xyz/
|
||||
*
|
||||
* Copyright 2026 Johannes Findeisen <you@hanez.org>
|
||||
* Licensed under the terms of the Apache-2.0 license.
|
||||
* https://opensource.org/license/apache-2-0
|
||||
*
|
||||
* Added: 2026-02-19
|
||||
*/
|
||||
|
||||
/*
|
||||
* LibreSSL integration helpers (MD5, RIPEMD-160, SHA-256, SHA-512)
|
||||
*/
|
||||
|
||||
#ifdef FUN_WITH_LIBRESSL
|
||||
/*
|
||||
* When building with LibreSSL, include the LibreSSL-provided headers explicitly.
|
||||
* Downstream distros often ship them under /usr/include/libressl/openssl/…
|
||||
* and expect the include path to point at /usr/include/libressl so that any
|
||||
* nested `#include <openssl/...>` inside these headers resolves to the
|
||||
* corresponding LibreSSL headers as well (not the system OpenSSL 3.x ones).
|
||||
*/
|
||||
#include <libressl/openssl/evp.h>
|
||||
/* Compatibility: Prefer EVP_MD_get_size universally. If LibreSSL headers
|
||||
* don't declare it, provide a forward declaration so we can link against
|
||||
* OpenSSL's libcrypto symbol when that is what CMake found. */
|
||||
#ifndef EVP_MD_get_size
|
||||
int EVP_MD_get_size(const EVP_MD *md);
|
||||
#endif
|
||||
#endif
|
||||
#include <stdlib.h>
|
||||
|
||||
/* Compute MD5 hex of input buffer; returns malloc'ed C string (lowercase hex). */
|
||||
static char *fun_libressl_md5_hex(const unsigned char *data, size_t len) {
|
||||
static const char hexdig[] = "0123456789abcdef";
|
||||
if (!data && len != 0) return NULL;
|
||||
#ifdef FUN_WITH_LIBRESSL
|
||||
const EVP_MD *md = EVP_md5();
|
||||
if (!md) return NULL;
|
||||
int dlen = EVP_MD_get_size(md);
|
||||
if (dlen <= 0) return NULL;
|
||||
unsigned char *digest = (unsigned char *)malloc((size_t)dlen);
|
||||
if (!digest) return NULL;
|
||||
unsigned int out_len = 0;
|
||||
int ok;
|
||||
if (len == 0) {
|
||||
ok = EVP_Digest(NULL, 0, digest, &out_len, md, NULL);
|
||||
} else {
|
||||
ok = EVP_Digest(data, len, digest, &out_len, md, NULL);
|
||||
}
|
||||
if (ok != 1 || (int)out_len != dlen) {
|
||||
free(digest);
|
||||
return NULL;
|
||||
}
|
||||
char *hex = (char *)malloc((size_t)dlen * 2 + 1);
|
||||
if (!hex) {
|
||||
free(digest);
|
||||
return NULL;
|
||||
}
|
||||
for (int i = 0; i < dlen; ++i) {
|
||||
hex[2 * i] = hexdig[(digest[i] >> 4) & 0xF];
|
||||
hex[2 * i + 1] = hexdig[digest[i] & 0xF];
|
||||
}
|
||||
hex[dlen * 2] = '\0';
|
||||
free(digest);
|
||||
return hex;
|
||||
#else
|
||||
char *hex = (char *)malloc(1);
|
||||
if (hex) hex[0] = '\0';
|
||||
return hex;
|
||||
#endif
|
||||
}
|
||||
|
||||
/* Compute SHA-256 hex of input buffer; returns malloc'ed C string (lowercase hex). */
|
||||
static char *fun_libressl_sha256_hex(const unsigned char *data, size_t len) {
|
||||
static const char hexdig[] = "0123456789abcdef";
|
||||
if (!data && len != 0) return NULL;
|
||||
#ifdef FUN_WITH_LIBRESSL
|
||||
const EVP_MD *md = EVP_sha256();
|
||||
if (!md) return NULL;
|
||||
int dlen = EVP_MD_get_size(md);
|
||||
if (dlen <= 0) return NULL;
|
||||
unsigned char *digest = (unsigned char *)malloc((size_t)dlen);
|
||||
if (!digest) return NULL;
|
||||
unsigned int out_len = 0;
|
||||
int ok;
|
||||
if (len == 0) {
|
||||
ok = EVP_Digest(NULL, 0, digest, &out_len, md, NULL);
|
||||
} else {
|
||||
ok = EVP_Digest(data, len, digest, &out_len, md, NULL);
|
||||
}
|
||||
if (ok != 1 || (int)out_len != dlen) {
|
||||
free(digest);
|
||||
return NULL;
|
||||
}
|
||||
char *hex = (char *)malloc((size_t)dlen * 2 + 1);
|
||||
if (!hex) {
|
||||
free(digest);
|
||||
return NULL;
|
||||
}
|
||||
for (int i = 0; i < dlen; ++i) {
|
||||
hex[2 * i] = hexdig[(digest[i] >> 4) & 0xF];
|
||||
hex[2 * i + 1] = hexdig[digest[i] & 0xF];
|
||||
}
|
||||
hex[dlen * 2] = '\0';
|
||||
free(digest);
|
||||
return hex;
|
||||
#else
|
||||
char *hex = (char *)malloc(1);
|
||||
if (hex) hex[0] = '\0';
|
||||
return hex;
|
||||
#endif
|
||||
}
|
||||
|
||||
/* Compute SHA-512 hex of input buffer; returns malloc'ed C string (lowercase hex). */
|
||||
static char *fun_libressl_sha512_hex(const unsigned char *data, size_t len) {
|
||||
static const char hexdig[] = "0123456789abcdef";
|
||||
if (!data && len != 0) return NULL;
|
||||
#ifdef FUN_WITH_LIBRESSL
|
||||
const EVP_MD *md = EVP_sha512();
|
||||
if (!md) return NULL;
|
||||
int dlen = EVP_MD_get_size(md);
|
||||
if (dlen <= 0) return NULL;
|
||||
unsigned char *digest = (unsigned char *)malloc((size_t)dlen);
|
||||
if (!digest) return NULL;
|
||||
unsigned int out_len = 0;
|
||||
int ok;
|
||||
if (len == 0) {
|
||||
ok = EVP_Digest(NULL, 0, digest, &out_len, md, NULL);
|
||||
} else {
|
||||
ok = EVP_Digest(data, len, digest, &out_len, md, NULL);
|
||||
}
|
||||
if (ok != 1 || (int)out_len != dlen) {
|
||||
free(digest);
|
||||
return NULL;
|
||||
}
|
||||
char *hex = (char *)malloc((size_t)dlen * 2 + 1);
|
||||
if (!hex) {
|
||||
free(digest);
|
||||
return NULL;
|
||||
}
|
||||
for (int i = 0; i < dlen; ++i) {
|
||||
hex[2 * i] = hexdig[(digest[i] >> 4) & 0xF];
|
||||
hex[2 * i + 1] = hexdig[digest[i] & 0xF];
|
||||
}
|
||||
hex[dlen * 2] = '\0';
|
||||
free(digest);
|
||||
return hex;
|
||||
#else
|
||||
char *hex = (char *)malloc(1);
|
||||
if (hex) hex[0] = '\0';
|
||||
return hex;
|
||||
#endif
|
||||
}
|
||||
|
||||
/* Compute RIPEMD-160 hex of input buffer; returns malloc'ed C string (lowercase hex). */
|
||||
static char *fun_libressl_ripemd160_hex(const unsigned char *data, size_t len) {
|
||||
static const char hexdig[] = "0123456789abcdef";
|
||||
if (!data && len != 0) return NULL;
|
||||
#ifdef FUN_WITH_LIBRESSL
|
||||
const EVP_MD *md = EVP_ripemd160();
|
||||
if (!md) return NULL;
|
||||
int dlen = EVP_MD_get_size(md);
|
||||
if (dlen <= 0) return NULL;
|
||||
unsigned char *digest = (unsigned char *)malloc((size_t)dlen);
|
||||
if (!digest) return NULL;
|
||||
unsigned int out_len = 0;
|
||||
int ok;
|
||||
if (len == 0) {
|
||||
ok = EVP_Digest(NULL, 0, digest, &out_len, md, NULL);
|
||||
} else {
|
||||
ok = EVP_Digest(data, len, digest, &out_len, md, NULL);
|
||||
}
|
||||
if (ok != 1 || (int)out_len != dlen) {
|
||||
free(digest);
|
||||
return NULL;
|
||||
}
|
||||
char *hex = (char *)malloc((size_t)dlen * 2 + 1);
|
||||
if (!hex) {
|
||||
free(digest);
|
||||
return NULL;
|
||||
}
|
||||
for (int i = 0; i < dlen; ++i) {
|
||||
hex[2 * i] = hexdig[(digest[i] >> 4) & 0xF];
|
||||
hex[2 * i + 1] = hexdig[digest[i] & 0xF];
|
||||
}
|
||||
hex[dlen * 2] = '\0';
|
||||
free(digest);
|
||||
return hex;
|
||||
#else
|
||||
char *hex = (char *)malloc(1);
|
||||
if (hex) hex[0] = '\0';
|
||||
return hex;
|
||||
#endif
|
||||
}
|
||||
58
src/external/libsql.c
vendored
58
src/external/libsql.c
vendored
|
|
@ -1,58 +0,0 @@
|
|||
/*
|
||||
* This file is part of the Fun programming language.
|
||||
* https://fun-lang.xyz/
|
||||
*
|
||||
* Copyright 2025 Johannes Findeisen <you@hanez.org>
|
||||
* Licensed under the terms of the Apache-2.0 license.
|
||||
* https://opensource.org/license/apache-2-0
|
||||
*
|
||||
* Added: 2025-11-26 (2025-12-11 migrated from src/vm/libsql/common.c)
|
||||
*/
|
||||
|
||||
#ifdef FUN_WITH_LIBSQL
|
||||
#include <sqlite3.h> /* libsql provides a sqlite3-compatible C API */
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
typedef struct LibSqlHandle {
|
||||
int id;
|
||||
sqlite3 *db;
|
||||
struct LibSqlHandle *next;
|
||||
} LibSqlHandle;
|
||||
|
||||
static LibSqlHandle *g_libsql_handles = NULL;
|
||||
static int g_libsql_next_id = 1;
|
||||
|
||||
static LibSqlHandle *libsql_reg_add(sqlite3 *db) {
|
||||
LibSqlHandle *h = (LibSqlHandle *)malloc(sizeof(LibSqlHandle));
|
||||
if (!h) return NULL;
|
||||
h->id = g_libsql_next_id++;
|
||||
h->db = db;
|
||||
h->next = g_libsql_handles;
|
||||
g_libsql_handles = h;
|
||||
return h;
|
||||
}
|
||||
|
||||
static LibSqlHandle *libsql_reg_get(int id) {
|
||||
LibSqlHandle *p = g_libsql_handles;
|
||||
while (p) {
|
||||
if (p->id == id) return p;
|
||||
p = p->next;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void libsql_reg_del(int id) {
|
||||
LibSqlHandle **pp = &g_libsql_handles;
|
||||
while (*pp) {
|
||||
if ((*pp)->id == id) {
|
||||
LibSqlHandle *dead = *pp;
|
||||
*pp = (*pp)->next;
|
||||
free(dead);
|
||||
return;
|
||||
}
|
||||
pp = &((*pp)->next);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
79
src/external/tcltk.c
vendored
79
src/external/tcltk.c
vendored
|
|
@ -1,79 +0,0 @@
|
|||
/*
|
||||
* This file is part of the Fun programming language.
|
||||
* https://fun-lang.xyz/
|
||||
*
|
||||
* Copyright 2025 Johannes Findeisen <you@hanez.org>
|
||||
* Licensed under the terms of the Apache-2.0 license.
|
||||
* https://opensource.org/license/apache-2-0
|
||||
*
|
||||
* Added: 2025-12-11 (2025-12-11 migrated from src/vm.c)
|
||||
*/
|
||||
|
||||
#ifdef FUN_WITH_TCLTK
|
||||
#include <tcl.h>
|
||||
#include <tk.h>
|
||||
static Tcl_Interp *g_fun_tcl_interp = NULL;
|
||||
|
||||
static void fun_tk_init_once(void) {
|
||||
if (g_fun_tcl_interp) return;
|
||||
Tcl_FindExecutable(NULL);
|
||||
g_fun_tcl_interp = Tcl_CreateInterp();
|
||||
if (!g_fun_tcl_interp) return;
|
||||
if (Tcl_Init(g_fun_tcl_interp) != TCL_OK) {
|
||||
fprintf(stderr, "Tcl_Init failed: %s\n", Tcl_GetStringResult(g_fun_tcl_interp));
|
||||
}
|
||||
if (Tk_Init(g_fun_tcl_interp) != TCL_OK) {
|
||||
fprintf(stderr, "Tk_Init failed: %s\n", Tcl_GetStringResult(g_fun_tcl_interp));
|
||||
}
|
||||
/* Ensure the app terminates if the main window is closed via window manager */
|
||||
/* Best-effort: set WM_DELETE_WINDOW handler to exit the process. */
|
||||
Tcl_Eval(g_fun_tcl_interp, "wm protocol . WM_DELETE_WINDOW {exit 0}");
|
||||
}
|
||||
|
||||
static int fun_tk_eval_script(const char *script) {
|
||||
fun_tk_init_once();
|
||||
if (!g_fun_tcl_interp) return -1;
|
||||
int rc = Tcl_Eval(g_fun_tcl_interp, script ? script : "");
|
||||
return rc; /* TCL_OK = 0 */
|
||||
}
|
||||
|
||||
static const char *fun_tk_get_result(void) {
|
||||
fun_tk_init_once();
|
||||
if (!g_fun_tcl_interp) return "";
|
||||
return Tcl_GetStringResult(g_fun_tcl_interp);
|
||||
}
|
||||
|
||||
static void fun_tk_loop(void) {
|
||||
fun_tk_init_once();
|
||||
if (!g_fun_tcl_interp) return;
|
||||
/* Drive Tk event loop until all main windows are closed */
|
||||
while (Tk_GetNumMainWindows() > 0) {
|
||||
while (Tcl_DoOneEvent(0)) {
|
||||
}
|
||||
/* tiny sleep to avoid busy spin */
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
Sleep(1);
|
||||
#else
|
||||
#include <time.h>
|
||||
struct timespec ts = {0, 1000000}; /* 1 ms */
|
||||
nanosleep(&ts, NULL);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
#else
|
||||
/* Stubs when Tcl/Tk is disabled */
|
||||
static void fun_tk_init_once(void) {
|
||||
(void)0;
|
||||
}
|
||||
static int fun_tk_eval_script(const char *script) {
|
||||
(void)script;
|
||||
return -1;
|
||||
}
|
||||
static const char *fun_tk_get_result(void) {
|
||||
return "";
|
||||
}
|
||||
static void fun_tk_loop(void) {
|
||||
(void)0;
|
||||
}
|
||||
#endif
|
||||
16
src/vm.c
16
src/vm.c
|
|
@ -56,20 +56,20 @@
|
|||
/* Notcurses support removed */
|
||||
|
||||
// Optional by extensions commonly used code. #ifdef's are in each single file.
|
||||
#include "external/curl.c"
|
||||
#include "external/ini.c"
|
||||
#include "extensions/curl.c"
|
||||
#include "extensions/ini.c"
|
||||
#ifdef FUN_WITH_INI
|
||||
/* Central INI handle registry and helpers */
|
||||
#include "vm/ini/handles.c"
|
||||
#endif
|
||||
/* Note: INI opcode handlers are included below; changes in vm/ini/ .c files
|
||||
* require vm.c to rebuild. */
|
||||
#include "external/json.c"
|
||||
#include "external/openssl.c"
|
||||
#include "external/pcre2.c"
|
||||
#include "external/pcsc.c"
|
||||
#include "external/sqlite.c"
|
||||
#include "external/xml2.c"
|
||||
#include "extensions/json.c"
|
||||
#include "extensions/openssl.c"
|
||||
#include "extensions/pcre2.c"
|
||||
#include "extensions/pcsc.c"
|
||||
#include "extensions/sqlite.c"
|
||||
#include "extensions/xml2.c"
|
||||
|
||||
/* forward declarations for include mapping used in error reporting */
|
||||
extern char *preprocess_includes(const char *src);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue