meta: rename to fx

This commit is contained in:
2026-03-16 10:35:43 +00:00
parent 84df46489a
commit e9d0e323f0
233 changed files with 12875 additions and 12869 deletions

View File

@@ -1,27 +1,26 @@
#include "blue/core/misc.h"
#include <CuTest.h>
#include <blue/core/btree.h>
#include <blue/core/queue.h>
#include <blue/core/stringstream.h>
#include <fx/core/btree.h>
#include <fx/core/misc.h>
#include <fx/core/queue.h>
#include <fx/core/stringstream.h>
#include <stdlib.h>
#include <time.h>
struct test_tree_node {
int value;
b_btree_node node;
fx_bst_node node;
};
struct test_queue_entry {
int value;
b_queue_entry entry;
fx_queue_entry entry;
};
B_BTREE_DEFINE_SIMPLE_INSERT(struct test_tree_node, node, value, test_tree_insert);
FX_BTREE_DEFINE_SIMPLE_INSERT(struct test_tree_node, node, value, test_tree_insert);
void test_btree_insert(CuTest *tc)
{
b_btree tree = {0};
fx_bst tree = {0};
struct test_tree_node nodes[3] = {0};
for (int i = 0; i < sizeof nodes / sizeof *nodes; i++) {
@@ -30,33 +29,33 @@ void test_btree_insert(CuTest *tc)
test_tree_insert(&tree, &nodes[0]);
CuAssertPtrEquals(tc, NULL, nodes[0].node.b_left);
CuAssertPtrEquals(tc, NULL, nodes[0].node.b_right);
CuAssertIntEquals(tc, 1, nodes[0].node.b_height);
CuAssertPtrEquals(tc, NULL, nodes[0].node.n_left);
CuAssertPtrEquals(tc, NULL, nodes[0].node.n_right);
CuAssertIntEquals(tc, 1, nodes[0].node.n_height);
test_tree_insert(&tree, &nodes[1]);
CuAssertPtrEquals(tc, NULL, nodes[0].node.b_left);
CuAssertPtrEquals(tc, &nodes[1].node, nodes[0].node.b_right);
CuAssertIntEquals(tc, 2, nodes[0].node.b_height);
CuAssertPtrEquals(tc, NULL, nodes[0].node.n_left);
CuAssertPtrEquals(tc, &nodes[1].node, nodes[0].node.n_right);
CuAssertIntEquals(tc, 2, nodes[0].node.n_height);
CuAssertPtrEquals(tc, NULL, nodes[1].node.b_left);
CuAssertPtrEquals(tc, NULL, nodes[1].node.b_right);
CuAssertIntEquals(tc, 1, nodes[1].node.b_height);
CuAssertPtrEquals(tc, NULL, nodes[1].node.n_left);
CuAssertPtrEquals(tc, NULL, nodes[1].node.n_right);
CuAssertIntEquals(tc, 1, nodes[1].node.n_height);
test_tree_insert(&tree, &nodes[2]);
CuAssertPtrEquals(tc, &nodes[0].node, nodes[1].node.b_left);
CuAssertPtrEquals(tc, &nodes[2].node, nodes[1].node.b_right);
CuAssertIntEquals(tc, 2, nodes[1].node.b_height);
CuAssertPtrEquals(tc, &nodes[0].node, nodes[1].node.n_left);
CuAssertPtrEquals(tc, &nodes[2].node, nodes[1].node.n_right);
CuAssertIntEquals(tc, 2, nodes[1].node.n_height);
CuAssertPtrEquals(tc, NULL, nodes[0].node.b_left);
CuAssertPtrEquals(tc, NULL, nodes[0].node.b_right);
CuAssertIntEquals(tc, 1, nodes[0].node.b_height);
CuAssertPtrEquals(tc, NULL, nodes[0].node.n_left);
CuAssertPtrEquals(tc, NULL, nodes[0].node.n_right);
CuAssertIntEquals(tc, 1, nodes[0].node.n_height);
CuAssertPtrEquals(tc, NULL, nodes[2].node.b_left);
CuAssertPtrEquals(tc, NULL, nodes[2].node.b_right);
CuAssertIntEquals(tc, 1, nodes[2].node.b_height);
CuAssertPtrEquals(tc, NULL, nodes[2].node.n_left);
CuAssertPtrEquals(tc, NULL, nodes[2].node.n_right);
CuAssertIntEquals(tc, 1, nodes[2].node.n_height);
}
void test_btree_iterate(CuTest *tc)
@@ -64,7 +63,7 @@ void test_btree_iterate(CuTest *tc)
static const size_t nr_nodes = 256;
srand(time(NULL));
b_btree tree = {0};
fx_bst tree = {0};
struct test_tree_node *nodes = calloc(nr_nodes, sizeof *nodes);
CuAssertPtrNotNull(tc, nodes);
@@ -74,21 +73,21 @@ void test_btree_iterate(CuTest *tc)
}
int prev = -1;
b_btree_node *bnode = b_btree_first(&tree);
fx_bst_node *bnode = fx_bst_first(&tree);
while (bnode) {
struct test_tree_node *node
= b_unbox(struct test_tree_node, bnode, node);
= fx_unbox(struct test_tree_node, bnode, node);
CuAssertPtrNotNull(tc, node);
if (prev == -1) {
prev = node->value;
bnode = b_btree_next(bnode);
bnode = fx_bst_next(bnode);
continue;
}
CuAssertTrue(tc, prev <= node->value);
prev = node->value;
bnode = b_btree_next(bnode);
bnode = fx_bst_next(bnode);
}
free(nodes);
@@ -101,13 +100,13 @@ void test_queue_insert(CuTest *tc)
entries[i].value = i;
}
b_queue q = B_QUEUE_INIT;
fx_queue q = FX_QUEUE_INIT;
b_queue_push_back(&q, &entries[0].entry);
b_queue_push_back(&q, &entries[2].entry);
b_queue_push_back(&q, &entries[4].entry);
b_queue_insert_after(&q, &entries[3].entry, &entries[2].entry);
b_queue_insert_before(&q, &entries[1].entry, &entries[2].entry);
fx_queue_push_back(&q, &entries[0].entry);
fx_queue_push_back(&q, &entries[2].entry);
fx_queue_push_back(&q, &entries[4].entry);
fx_queue_insert_after(&q, &entries[3].entry, &entries[2].entry);
fx_queue_insert_before(&q, &entries[1].entry, &entries[2].entry);
CuAssertPtrEquals(tc, NULL, entries[0].entry.qe_prev);
CuAssertPtrEquals(tc, &entries[1].entry, entries[0].entry.qe_next);
@@ -127,19 +126,19 @@ void test_queue_insert(CuTest *tc)
void test_queue_iterate(CuTest *tc)
{
b_queue q = B_QUEUE_INIT;
fx_queue q = FX_QUEUE_INIT;
struct test_queue_entry entries[32] = {0};
for (int i = 0; i < sizeof entries / sizeof *entries; i++) {
entries[i].value = i;
b_queue_push_back(&q, &entries[i].entry);
fx_queue_push_back(&q, &entries[i].entry);
}
int prev = -1;
struct b_queue_entry *entry = b_queue_first(&q);
struct fx_queue_entry *entry = fx_queue_first(&q);
while (entry) {
struct test_queue_entry *e
= b_unbox(struct test_queue_entry, entry, entry);
= fx_unbox(struct test_queue_entry, entry, entry);
CuAssertPtrNotNull(tc, e);
if (prev == -1) {
@@ -150,20 +149,20 @@ void test_queue_iterate(CuTest *tc)
CuAssertTrue(tc, prev < e->value);
prev = e->value;
skip:
entry = b_queue_next(entry);
entry = fx_queue_next(entry);
}
}
void test_stringstream_1(CuTest *tc)
{
char buf[1024];
b_stringstream *s = b_stringstream_create_with_buffer(buf, sizeof buf);
fx_stringstream *s = fx_stringstream_create_with_buffer(buf, sizeof buf);
b_stream_write_string(s, "hello", NULL);
b_stream_write_fmt(s, NULL, "(%d + %.1f)", 32, 2.3);
fx_stream_write_string(s, "hello", NULL);
fx_stream_write_fmt(s, NULL, "(%d + %.1f)", 32, 2.3);
char *end = b_stringstream_steal(s);
b_stringstream_unref(s);
char *end = fx_stringstream_steal(s);
fx_stringstream_unref(s);
CuAssertStrEquals(tc, "hello(32 + 2.3)", end);
}
@@ -171,19 +170,19 @@ void test_stringstream_1(CuTest *tc)
void test_stringstream_2(CuTest *tc)
{
char buf[1024];
b_stringstream *s = b_stringstream_create_with_buffer(buf, sizeof buf);
fx_stringstream *s = fx_stringstream_create_with_buffer(buf, sizeof buf);
b_stream_write_string(s, "{\n", NULL);
b_stream_push_indent(s, 1);
fx_stream_write_string(s, "{\n", NULL);
fx_stream_push_indent(s, 1);
b_stream_write_string(s, "a = 32,\n", NULL);
b_stream_write_string(s, "b = 64\n", NULL);
fx_stream_write_string(s, "a = 32,\n", NULL);
fx_stream_write_string(s, "b = 64\n", NULL);
b_stream_pop_indent(s);
b_stream_write_string(s, "}", NULL);
fx_stream_pop_indent(s);
fx_stream_write_string(s, "}", NULL);
char *str = b_stringstream_steal(s);
b_stringstream_unref(s);
char *str = fx_stringstream_steal(s);
fx_stringstream_unref(s);
CuAssertStrEquals(tc, "{\n a = 32,\n b = 64\n}", str);
}

View File

@@ -1,4 +1,4 @@
#include <blue/core/error.h>
#include <fx/core/error.h>
int main(void)
{

View File

@@ -1,26 +1,26 @@
#include <blue/core/hash.h>
#include <fx/core/hash.h>
#include <stdio.h>
#include <string.h>
static void print_digest(
const char *func_name, b_hash_function func, const char *msg,
const char *func_name, fx_hash_function func, const char *msg,
size_t msg_len, size_t digest_len)
{
unsigned char digest[128];
b_hash_ctx ctx;
if (!B_OK(b_hash_ctx_init(&ctx, func))) {
printf("b_hash_ctx_init failed\n");
fx_hash_ctx ctx;
if (!FX_OK(fx_hash_ctx_init(&ctx, func))) {
printf("fx_hash_ctx_init failed\n");
return;
}
if (!B_OK(b_hash_ctx_update(&ctx, msg, msg_len))) {
printf("b_hash_ctx_update failed\n");
if (!FX_OK(fx_hash_ctx_update(&ctx, msg, msg_len))) {
printf("fx_hash_ctx_update failed\n");
return;
}
if (!B_OK(b_hash_ctx_finish(&ctx, digest, sizeof digest))) {
printf("b_hash_ctx_finish failed\n");
if (!FX_OK(fx_hash_ctx_finish(&ctx, digest, sizeof digest))) {
printf("fx_hash_ctx_finish failed\n");
return;
}
@@ -40,35 +40,35 @@ int main(void)
const char *msg = "Hello, world!";
size_t msg_len = strlen(msg);
print_digest("MD4", B_HASH_MD4, msg, msg_len, B_DIGEST_LENGTH_MD4);
print_digest("MD5", B_HASH_MD5, msg, msg_len, B_DIGEST_LENGTH_MD5);
print_digest("SHA1", B_HASH_SHA1, msg, msg_len, B_DIGEST_LENGTH_SHA1);
print_digest("MD4", FX_HASH_MD4, msg, msg_len, FX_DIGEST_LENGTH_MD4);
print_digest("MD5", FX_HASH_MD5, msg, msg_len, FX_DIGEST_LENGTH_MD5);
print_digest("SHA1", FX_HASH_SHA1, msg, msg_len, FX_DIGEST_LENGTH_SHA1);
print_digest(
"SHA224", B_HASH_SHA2_224, msg, msg_len, B_DIGEST_LENGTH_SHA2_224);
"SHA224", FX_HASH_SHA2_224, msg, msg_len, FX_DIGEST_LENGTH_SHA2_224);
print_digest(
"SHA256", B_HASH_SHA2_256, msg, msg_len, B_DIGEST_LENGTH_SHA2_256);
"SHA256", FX_HASH_SHA2_256, msg, msg_len, FX_DIGEST_LENGTH_SHA2_256);
print_digest(
"SHA384", B_HASH_SHA2_384, msg, msg_len, B_DIGEST_LENGTH_SHA2_384);
"SHA384", FX_HASH_SHA2_384, msg, msg_len, FX_DIGEST_LENGTH_SHA2_384);
print_digest(
"SHA512", B_HASH_SHA2_512, msg, msg_len, B_DIGEST_LENGTH_SHA2_512);
"SHA512", FX_HASH_SHA2_512, msg, msg_len, FX_DIGEST_LENGTH_SHA2_512);
print_digest(
"SHA3-224", B_HASH_SHA3_224, msg, msg_len,
B_DIGEST_LENGTH_SHA3_224);
"SHA3-224", FX_HASH_SHA3_224, msg, msg_len,
FX_DIGEST_LENGTH_SHA3_224);
print_digest(
"SHA3-256", B_HASH_SHA3_256, msg, msg_len,
B_DIGEST_LENGTH_SHA3_256);
"SHA3-256", FX_HASH_SHA3_256, msg, msg_len,
FX_DIGEST_LENGTH_SHA3_256);
print_digest(
"SHA3-384", B_HASH_SHA3_384, msg, msg_len,
B_DIGEST_LENGTH_SHA3_384);
"SHA3-384", FX_HASH_SHA3_384, msg, msg_len,
FX_DIGEST_LENGTH_SHA3_384);
print_digest(
"SHA3-512", B_HASH_SHA3_512, msg, msg_len,
B_DIGEST_LENGTH_SHA3_512);
"SHA3-512", FX_HASH_SHA3_512, msg, msg_len,
FX_DIGEST_LENGTH_SHA3_512);
print_digest(
"SHAKE128", B_HASH_SHAKE128, msg, msg_len,
B_DIGEST_LENGTH_SHAKE128);
"SHAKE128", FX_HASH_SHAKE128, msg, msg_len,
FX_DIGEST_LENGTH_SHAKE128);
print_digest(
"SHAKE256", B_HASH_SHAKE256, msg, msg_len,
B_DIGEST_LENGTH_SHAKE256);
"SHAKE256", FX_HASH_SHAKE256, msg, msg_len,
FX_DIGEST_LENGTH_SHAKE256);
return 0;
}

View File

@@ -1,4 +1,4 @@
#include <blue/core/random.h>
#include <fx/core/random.h>
#include <stdio.h>
#define NRAND_NUMBERS 12
@@ -7,12 +7,12 @@
int main(void)
{
b_random_ctx random;
b_random_init(&random, B_RANDOM_SECURE | B_RANDOM_MT19937);
fx_random_ctx random;
fx_random_init(&random, FX_RANDOM_SECURE | FX_RANDOM_MT19937);
printf("generating %d random numbers:\n", NRAND_NUMBERS);
for (int i = 0; i < NRAND_NUMBERS; i++) {
unsigned long long v = b_random_next_int64(&random);
unsigned long long v = fx_random_next_int64(&random);
printf(" %llu\n", v);
}
@@ -21,7 +21,7 @@ int main(void)
for (int i = 0; i < NRAND_BYTES; i++) {
if (i == 0 || (i % 16) == 0) {
printf("\n ");
b_random_next_bytes(&random, bytes, sizeof bytes);
fx_random_next_bytes(&random, bytes, sizeof bytes);
} else if ((i % 4) == 0) {
printf(" ");
}
@@ -31,7 +31,7 @@ int main(void)
printf("\n\ngenerating %d random doubles:\n", NRAND_DOUBLES);
for (int i = 0; i < NRAND_DOUBLES; i++) {
double v = b_random_next_double(&random);
double v = fx_random_next_double(&random);
printf(" %lf\n", v);
}

View File

@@ -1,5 +1,5 @@
#include <assert.h>
#include <blue/core/ringbuffer.h>
#include <fx/core/ringbuffer.h>
#include <stdio.h>
#include <string.h>
@@ -7,10 +7,10 @@
int main(void)
{
b_ringbuffer *buf = b_ringbuffer_create(BUF_SIZE);
fx_ringbuffer *buf = fx_ringbuffer_create(BUF_SIZE);
size_t read_available = b_ringbuffer_available_data_remaining(buf);
size_t write_available = b_ringbuffer_write_capacity_remaining(buf);
size_t read_available = fx_ringbuffer_available_data_remaining(buf);
size_t write_available = fx_ringbuffer_write_capacity_remaining(buf);
printf("read available: %zu\n", read_available);
printf("write available: %zu\n", write_available);
@@ -21,15 +21,15 @@ int main(void)
const char ch = 'X';
printf("putc(%c)\n", ch);
b_ringbuffer_putc(buf, ch);
read_available = b_ringbuffer_available_data_remaining(buf);
write_available = b_ringbuffer_write_capacity_remaining(buf);
fx_ringbuffer_putc(buf, ch);
read_available = fx_ringbuffer_available_data_remaining(buf);
write_available = fx_ringbuffer_write_capacity_remaining(buf);
printf("read available: %zu\n", read_available);
printf("write available: %zu\n", write_available);
assert(read_available == 1);
assert(write_available == BUF_SIZE - 2);
int c = b_ringbuffer_getc(buf);
int c = fx_ringbuffer_getc(buf);
printf("getc() = %c\n", c);
assert(c == ch);
@@ -40,9 +40,9 @@ int main(void)
size_t nr_written = 0;
printf("write(%s)\n", s);
b_ringbuffer_write(buf, s, s_len, &nr_written);
read_available = b_ringbuffer_available_data_remaining(buf);
write_available = b_ringbuffer_write_capacity_remaining(buf);
fx_ringbuffer_write(buf, s, s_len, &nr_written);
read_available = fx_ringbuffer_available_data_remaining(buf);
write_available = fx_ringbuffer_write_capacity_remaining(buf);
printf("nr written: %zu\n", nr_written);
printf("read available: %zu\n", read_available);
printf("write available: %zu\n", write_available);
@@ -51,17 +51,17 @@ int main(void)
char data[BUF_SIZE + 32] = {0};
size_t nr_read = 0;
b_ringbuffer_read(buf, data, sizeof data, &nr_read);
fx_ringbuffer_read(buf, data, sizeof data, &nr_read);
printf("read(%u) = %zu bytes\n", BUF_SIZE + 32, nr_read);
printf(" = %s\n", data);
read_available = b_ringbuffer_available_data_remaining(buf);
write_available = b_ringbuffer_write_capacity_remaining(buf);
read_available = fx_ringbuffer_available_data_remaining(buf);
write_available = fx_ringbuffer_write_capacity_remaining(buf);
printf("read available: %zu\n", read_available);
printf("write available: %zu\n", write_available);
assert(read_available == 0);
assert(write_available == BUF_SIZE - 1);
b_ringbuffer_unref(buf);
fx_ringbuffer_unref(buf);
return 0;
}

View File

@@ -1,8 +1,8 @@
#include <blue/core/rope.h>
#include <fx/core/rope.h>
#include <inttypes.h>
#include <stdio.h>
static void print_rope(const struct b_rope *rope, int depth)
static void print_rope(const struct fx_rope *rope, int depth)
{
for (int i = 0; i < depth; i++) {
printf(" ");
@@ -10,32 +10,32 @@ static void print_rope(const struct b_rope *rope, int depth)
printf("[%x:", rope->r_flags);
(B_ROPE_TYPE(rope->r_flags) == B_ROPE_F_CHAR) && printf(" CHAR");
(B_ROPE_TYPE(rope->r_flags) == B_ROPE_F_CSTR) && printf(" CSTR");
(B_ROPE_TYPE(rope->r_flags) == B_ROPE_F_CSTR_BORROWED)
(FX_ROPE_TYPE(rope->r_flags) == FX_ROPE_F_CHAR) && printf(" CHAR");
(FX_ROPE_TYPE(rope->r_flags) == FX_ROPE_F_CSTR) && printf(" CSTR");
(FX_ROPE_TYPE(rope->r_flags) == FX_ROPE_F_CSTR_BORROWED)
&& printf(" CSTR_BORROWED");
(B_ROPE_TYPE(rope->r_flags) == B_ROPE_F_CSTR_STATIC)
(FX_ROPE_TYPE(rope->r_flags) == FX_ROPE_F_CSTR_STATIC)
&& printf(" CSTR_STATIC");
(B_ROPE_TYPE(rope->r_flags) == B_ROPE_F_INT) && printf(" INT");
(B_ROPE_TYPE(rope->r_flags) == B_ROPE_F_UINT) && printf(" UINT");
(B_ROPE_TYPE(rope->r_flags) == B_ROPE_F_COMPOSITE)
(FX_ROPE_TYPE(rope->r_flags) == FX_ROPE_F_INT) && printf(" INT");
(FX_ROPE_TYPE(rope->r_flags) == FX_ROPE_F_UINT) && printf(" UINT");
(FX_ROPE_TYPE(rope->r_flags) == FX_ROPE_F_COMPOSITE)
&& printf(" COMPOSITE");
(rope->r_flags & B_ROPE_F_MALLOC) && printf(" MALLOC");
(rope->r_flags & FX_ROPE_F_MALLOC) && printf(" MALLOC");
printf("] ");
switch (B_ROPE_TYPE(rope->r_flags)) {
case B_ROPE_F_CHAR:
switch (FX_ROPE_TYPE(rope->r_flags)) {
case FX_ROPE_F_CHAR:
printf("%c", rope->r_v.v_char);
break;
case B_ROPE_F_CSTR:
case B_ROPE_F_CSTR_BORROWED:
case B_ROPE_F_CSTR_STATIC:
case FX_ROPE_F_CSTR:
case FX_ROPE_F_CSTR_BORROWED:
case FX_ROPE_F_CSTR_STATIC:
printf("%s", rope->r_v.v_cstr.s);
break;
case B_ROPE_F_INT:
case FX_ROPE_F_INT:
printf("%" PRIdPTR, rope->r_v.v_int);
break;
case B_ROPE_F_UINT:
case FX_ROPE_F_UINT:
printf("%" PRIuPTR, rope->r_v.v_uint);
break;
default:
@@ -44,7 +44,7 @@ static void print_rope(const struct b_rope *rope, int depth)
printf("\n");
if (B_ROPE_TYPE(rope->r_flags) == B_ROPE_F_COMPOSITE) {
if (FX_ROPE_TYPE(rope->r_flags) == FX_ROPE_F_COMPOSITE) {
if (rope->r_v.v_composite.r_left) {
print_rope(rope->r_v.v_composite.r_left, depth + 1);
}
@@ -57,27 +57,27 @@ static void print_rope(const struct b_rope *rope, int depth)
int main(void)
{
b_rope a = B_ROPE_CHAR('a');
b_rope b = B_ROPE_CSTR_STATIC("Hello, world!");
b_rope c = B_ROPE_INT(-4096);
b_rope d = B_ROPE_UINT(4096);
fx_rope a = FX_ROPE_CHAR('a');
fx_rope b = FX_ROPE_CSTR_STATIC("Hello, world!");
fx_rope c = FX_ROPE_INT(-4096);
fx_rope d = FX_ROPE_UINT(4096);
b_rope str;
fx_rope str;
const b_rope *ropes[] = {
const fx_rope *ropes[] = {
&a,
&b,
&c,
&d,
};
b_rope_join(&str, ropes, sizeof ropes / sizeof ropes[0]);
fx_rope_join(&str, ropes, sizeof ropes / sizeof ropes[0]);
print_rope(&str, 0);
char cstr[1024];
b_rope_to_cstr(&str, cstr, sizeof cstr);
b_rope_destroy(&str);
fx_rope_to_cstr(&str, cstr, sizeof cstr);
fx_rope_destroy(&str);
printf("%s\n", cstr);
return 0;

View File

@@ -1,20 +1,20 @@
#include <blue/core/bstr.h>
#include <blue/core/stream.h>
#include <fx/core/bstr.h>
#include <fx/core/stream.h>
#include <stdio.h>
int main(void)
{
b_stream_read_line_s(b_stdin, b_stdout);
b_stream_write_char(b_stdout, '\n');
fx_stream_read_line_s(fx_stdin, fx_stdout);
fx_stream_write_char(fx_stdout, '\n');
char s[16];
b_bstr str;
b_bstr_begin(&str, s, sizeof s);
fx_bstr str;
fx_bstr_begin(&str, s, sizeof s);
b_stream_read_line_s(b_stdin, (b_stream *)&str);
b_stream_write_char((b_stream *)&str, '\n');
fx_stream_read_line_s(fx_stdin, (fx_stream *)&str);
fx_stream_write_char((fx_stream *)&str, '\n');
const char *e = b_bstr_end(&str);
const char *e = fx_bstr_end(&str);
fputs(e, stdout);
return 0;