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,196 +1,196 @@
#include <blue/ds/array.h>
#include <blue/ds/datetime.h>
#include <blue/ds/dict.h>
#include <blue/ds/number.h>
#include <blue/ds/string.h>
#include <blue/serial.h>
#include <fx/ds/array.h>
#include <fx/ds/datetime.h>
#include <fx/ds/dict.h>
#include <fx/ds/number.h>
#include <fx/ds/string.h>
#include <fx/serial.h>
#include <inttypes.h>
void write_tagged_value(b_object *data);
void write_tagged_value(fx_object *data);
void write_raw_string(const b_string *data)
void write_raw_string(const fx_string *data)
{
b_stream_write_string(b_stdout, "\"", NULL);
fx_stream_write_string(fx_stdout, "\"", NULL);
const b_iterator *it = b_iterator_cbegin(data);
b_foreach_c(b_wchar, c, it)
const fx_iterator *it = fx_iterator_cbegin(data);
fx_foreach_c(fx_wchar, c, it)
{
if (c >= 0x10000) {
c -= 0x10000;
long hi = 0xD800 | ((c >> 10) & 0x3FF);
long lo = 0xDC00 | (c & 0x3FF);
b_stream_write_fmt(b_stdout, NULL, "\\u%04x\\u%04x", hi, lo);
fx_stream_write_fmt(fx_stdout, NULL, "\\u%04x\\u%04x", hi, lo);
} else if (c <= 0x1F || c >= 0x7F) {
b_stream_write_fmt(b_stdout, NULL, "\\u%04x", c);
fx_stream_write_fmt(fx_stdout, NULL, "\\u%04x", c);
} else if (c == '\\' || c == '"') {
b_stream_write_fmt(b_stdout, NULL, "\\%c", c);
fx_stream_write_fmt(fx_stdout, NULL, "\\%c", c);
} else {
b_stream_write_char(b_stdout, c);
fx_stream_write_char(fx_stdout, c);
}
}
b_iterator_unref(it);
fx_iterator_unref(it);
b_stream_write_string(b_stdout, "\"", NULL);
fx_stream_write_string(fx_stdout, "\"", NULL);
}
void write_tagged_string(b_string *data)
void write_tagged_string(fx_string *data)
{
b_stream_write_string(b_stdout, "{ \"type\": \"string\", \"value\": ", NULL);
fx_stream_write_string(fx_stdout, "{ \"type\": \"string\", \"value\": ", NULL);
write_raw_string(data);
b_stream_write_string(b_stdout, " }", NULL);
fx_stream_write_string(fx_stdout, " }", NULL);
}
void write_tagged_integer(b_number *data)
void write_tagged_integer(fx_number *data)
{
b_stream_write_string(
b_stdout, "{ \"type\": \"integer\", \"value\": \"", NULL);
fx_stream_write_string(
fx_stdout, "{ \"type\": \"integer\", \"value\": \"", NULL);
if (b_number_is_inf_positive(data)) {
b_stream_write_string(b_stdout, "inf", NULL);
} else if (b_number_is_inf_negative(data)) {
b_stream_write_string(b_stdout, "-inf", NULL);
} else if (b_number_is_nan_positive(data)) {
b_stream_write_string(b_stdout, "nan", NULL);
} else if (b_number_is_nan_negative(data)) {
b_stream_write_string(b_stdout, "-nan", NULL);
if (fx_number_is_inf_positive(data)) {
fx_stream_write_string(fx_stdout, "inf", NULL);
} else if (fx_number_is_inf_negative(data)) {
fx_stream_write_string(fx_stdout, "-inf", NULL);
} else if (fx_number_is_nan_positive(data)) {
fx_stream_write_string(fx_stdout, "nan", NULL);
} else if (fx_number_is_nan_negative(data)) {
fx_stream_write_string(fx_stdout, "-nan", NULL);
} else {
b_stream_write_fmt(
b_stdout, NULL, "%lld", b_number_get_longlong(data), NULL);
fx_stream_write_fmt(
fx_stdout, NULL, "%lld", fx_number_get_longlong(data), NULL);
}
b_stream_write_string(b_stdout, "\" }", NULL);
fx_stream_write_string(fx_stdout, "\" }", NULL);
}
void write_tagged_float(b_number *data)
void write_tagged_float(fx_number *data)
{
b_stream_write_string(
b_stdout, "{ \"type\": \"float\", \"value\": \"", NULL);
fx_stream_write_string(
fx_stdout, "{ \"type\": \"float\", \"value\": \"", NULL);
if (b_number_is_inf_positive(data)) {
b_stream_write_string(b_stdout, "inf", NULL);
} else if (b_number_is_inf_negative(data)) {
b_stream_write_string(b_stdout, "-inf", NULL);
} else if (b_number_is_nan_positive(data)) {
b_stream_write_string(b_stdout, "nan", NULL);
} else if (b_number_is_nan_negative(data)) {
b_stream_write_string(b_stdout, "-nan", NULL);
if (fx_number_is_inf_positive(data)) {
fx_stream_write_string(fx_stdout, "inf", NULL);
} else if (fx_number_is_inf_negative(data)) {
fx_stream_write_string(fx_stdout, "-inf", NULL);
} else if (fx_number_is_nan_positive(data)) {
fx_stream_write_string(fx_stdout, "nan", NULL);
} else if (fx_number_is_nan_negative(data)) {
fx_stream_write_string(fx_stdout, "-nan", NULL);
} else {
double v = b_number_get_double(data);
double v = fx_number_get_double(data);
if ((v <= 0.00000001 && v > 0) || (v >= -0.00000001 && v < 0)
|| (v >= 1000000000) || (v <= -1000000000)) {
b_stream_write_fmt(b_stdout, NULL, "%.15e", v, NULL);
fx_stream_write_fmt(fx_stdout, NULL, "%.15e", v, NULL);
} else {
b_stream_write_fmt(b_stdout, NULL, "%.15f", v, NULL);
fx_stream_write_fmt(fx_stdout, NULL, "%.15f", v, NULL);
}
}
b_stream_write_string(b_stdout, "\" }", NULL);
fx_stream_write_string(fx_stdout, "\" }", NULL);
}
void write_tagged_bool(b_number *data)
void write_tagged_bool(fx_number *data)
{
int v = b_number_get_int8(data);
b_stream_write_fmt(
b_stdout, NULL, "{ \"type\": \"bool\", \"value\": \"%s\" }",
int v = fx_number_get_int8(data);
fx_stream_write_fmt(
fx_stdout, NULL, "{ \"type\": \"bool\", \"value\": \"%s\" }",
(v > 0) ? "true" : "false", NULL);
}
void write_tagged_datetime(b_datetime *data)
void write_tagged_datetime(fx_datetime *data)
{
bool has_date = b_datetime_has_date(data);
bool has_time = b_datetime_has_time(data);
bool localtime = b_datetime_is_localtime(data);
bool has_date = fx_datetime_has_date(data);
bool has_time = fx_datetime_has_time(data);
bool localtime = fx_datetime_is_localtime(data);
b_stream_write_string(b_stdout, "{ \"type\": \"", NULL);
fx_stream_write_string(fx_stdout, "{ \"type\": \"", NULL);
if (has_date && has_time) {
b_stream_write_string(
b_stdout, localtime ? "datetime-local" : "datetime", NULL);
fx_stream_write_string(
fx_stdout, localtime ? "datetime-local" : "datetime", NULL);
} else if (has_date) {
b_stream_write_string(
b_stdout, localtime ? "date-local" : "date", NULL);
fx_stream_write_string(
fx_stdout, localtime ? "date-local" : "date", NULL);
} else if (has_time) {
b_stream_write_string(
b_stdout, localtime ? "time-local" : "time", NULL);
fx_stream_write_string(
fx_stdout, localtime ? "time-local" : "time", NULL);
}
b_stream_write_string(b_stdout, "\", \"value\": \"", NULL);
fx_stream_write_string(fx_stdout, "\", \"value\": \"", NULL);
b_string *new_data = b_string_create();
b_datetime_to_string(data, B_DATETIME_FORMAT_RFC3339, new_data);
b_stream_write_string(b_stdout, b_string_ptr(new_data), NULL);
fx_string *new_data = fx_string_create();
fx_datetime_to_string(data, FX_DATETIME_FORMAT_RFC3339, new_data);
fx_stream_write_string(fx_stdout, fx_string_ptr(new_data), NULL);
b_stream_write_string(b_stdout, "\" }", NULL);
fx_stream_write_string(fx_stdout, "\" }", NULL);
b_string_unref(new_data);
fx_string_unref(new_data);
}
void write_tagged_dict(b_dict *data)
void write_tagged_dict(fx_dict *data)
{
b_stream_write_string(b_stdout, "{ ", NULL);
fx_stream_write_string(fx_stdout, "{ ", NULL);
int i = 0;
b_iterator *it = b_iterator_begin(data);
b_foreach(b_dict_item *, item, it)
fx_iterator *it = fx_iterator_begin(data);
fx_foreach(fx_dict_item *, item, it)
{
if (i++ > 0) {
b_stream_write_string(b_stdout, ", ", NULL);
fx_stream_write_string(fx_stdout, ", ", NULL);
}
write_raw_string(item->key);
b_stream_write_string(b_stdout, ": ", NULL);
fx_stream_write_string(fx_stdout, ": ", NULL);
write_tagged_value(item->value);
}
b_iterator_unref(it);
fx_iterator_unref(it);
b_stream_write_string(b_stdout, " }", NULL);
fx_stream_write_string(fx_stdout, " }", NULL);
}
void write_tagged_array(b_array *data)
void write_tagged_array(fx_array *data)
{
b_stream_write_string(b_stdout, "[ ", NULL);
fx_stream_write_string(fx_stdout, "[ ", NULL);
int i = 0;
b_iterator *it = b_iterator_begin(data);
b_foreach(b_object *, obj, it)
fx_iterator *it = fx_iterator_begin(data);
fx_foreach(fx_object *, obj, it)
{
if (i++ > 0) {
b_stream_write_string(b_stdout, ", ", NULL);
fx_stream_write_string(fx_stdout, ", ", NULL);
}
write_tagged_value(obj);
}
b_iterator_unref(it);
fx_iterator_unref(it);
b_stream_write_string(b_stdout, " ]", NULL);
fx_stream_write_string(fx_stdout, " ]", NULL);
}
void write_tagged_value(b_object *data)
void write_tagged_value(fx_object *data)
{
if (b_object_is_type(data, B_TYPE_DICT)) {
if (fx_object_is_type(data, FX_TYPE_DICT)) {
write_tagged_dict(data);
} else if (b_object_is_type(data, B_TYPE_ARRAY)) {
} else if (fx_object_is_type(data, FX_TYPE_ARRAY)) {
write_tagged_array(data);
} else if (b_object_is_type(data, B_TYPE_STRING)) {
} else if (fx_object_is_type(data, FX_TYPE_STRING)) {
write_tagged_string(data);
} else if (b_object_is_type(data, B_TYPE_DATETIME)) {
} else if (fx_object_is_type(data, FX_TYPE_DATETIME)) {
write_tagged_datetime(data);
} else if (b_object_is_type(data, B_TYPE_NUMBER)) {
switch (b_number_get_number_type(data)) {
case B_NUMBER_LONGLONG:
} else if (fx_object_is_type(data, FX_TYPE_NUMBER)) {
switch (fx_number_get_number_type(data)) {
case FX_NUMBER_LONGLONG:
write_tagged_integer(data);
break;
case B_NUMBER_INT8:
case FX_NUMBER_INT8:
write_tagged_bool(data);
break;
case B_NUMBER_DOUBLE:
case FX_NUMBER_DOUBLE:
write_tagged_float(data);
break;
default:
@@ -201,23 +201,23 @@ void write_tagged_value(b_object *data)
int main(void)
{
b_stream *src = b_stdin;
b_stream *dest = b_stdout;
fx_stream *src = fx_stdin;
fx_stream *dest = fx_stdout;
b_serial_ctx *ctx = b_toml_serial_ctx_create();
fx_serial_ctx *ctx = fx_toml_serial_ctx_create();
b_object *data;
b_status status = b_serial_ctx_deserialise(ctx, src, &data, 0);
if (!B_OK(status)) {
fx_object *data;
fx_status status = fx_serial_ctx_deserialise(ctx, src, &data, 0);
if (!FX_OK(status)) {
return 1;
}
write_tagged_value(data);
b_stream_write_char(b_stdout, '\n');
fx_stream_write_char(fx_stdout, '\n');
b_serial_ctx_unref(ctx);
b_object_unref(data);
fx_serial_ctx_unref(ctx);
fx_object_unref(data);
return 0;
}