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,8 +1,8 @@
#include <blue/core/stream.h>
#include <blue/core/stringstream.h>
#include <blue/ds/string.h>
#include <blue/io/file.h>
#include <blue/io/path.h>
#include <fx/core/stream.h>
#include <fx/core/stringstream.h>
#include <fx/ds/string.h>
#include <fx/io/file.h>
#include <fx/io/path.h>
#include <stdio.h>
int main(int argc, const char **argv)
@@ -12,21 +12,21 @@ int main(int argc, const char **argv)
}
const char *path_cstr = argv[1];
b_path *path = b_path_create_from_cstr(path_cstr);
fx_path *path = fx_path_create_from_cstr(path_cstr);
b_file *src = NULL;
b_result result = b_file_open(NULL, path, B_FILE_READ_ONLY, &src);
if (b_result_is_error(result)) {
b_throw(result);
fx_file *src = NULL;
fx_result result = fx_file_open(NULL, path, FX_FILE_READ_ONLY, &src);
if (fx_result_is_error(result)) {
fx_throw(result);
return -1;
}
b_stream_buffer *buf = b_stream_buffer_create_dynamic(1024);
fx_stream_buffer *buf = fx_stream_buffer_create_dynamic(1024);
size_t nr_read;
b_stream_read_all_bytes_s(src, b_stdout, buf, &nr_read);
fx_stream_read_all_bytes_s(src, fx_stdout, buf, &nr_read);
b_stream_buffer_unref(buf);
fx_stream_buffer_unref(buf);
return 0;
}

View File

@@ -1,8 +1,8 @@
#include <blue/core/stream.h>
#include <blue/core/stringstream.h>
#include <blue/ds/string.h>
#include <blue/io/file.h>
#include <blue/io/path.h>
#include <fx/core/stream.h>
#include <fx/core/stringstream.h>
#include <fx/ds/string.h>
#include <fx/io/file.h>
#include <fx/io/path.h>
#include <stdio.h>
int main(int argc, const char **argv)
@@ -12,28 +12,28 @@ int main(int argc, const char **argv)
}
const char *path_cstr = argv[1];
b_path *path = b_path_create_from_cstr(path_cstr);
fx_path *path = fx_path_create_from_cstr(path_cstr);
b_file *src = NULL;
b_result result = b_file_open(NULL, path, B_FILE_READ_ONLY, &src);
if (b_result_is_error(result)) {
b_throw(result);
fx_file *src = NULL;
fx_result result = fx_file_open(NULL, path, FX_FILE_READ_ONLY, &src);
if (fx_result_is_error(result)) {
fx_throw(result);
return -1;
}
b_wchar c;
fx_wchar c;
size_t nr_read;
b_status status = b_stream_read_char(src, &c);
if (!B_OK(status)) {
printf("read error: %s\n", b_status_description(status));
b_file_unref(src);
fx_status status = fx_stream_read_char(src, &c);
if (!FX_OK(status)) {
printf("read error: %s\n", fx_status_description(status));
fx_file_unref(src);
return -1;
}
b_stream_write_char(b_stdout, c);
b_stream_write_char(b_stdout, '\n');
fx_stream_write_char(fx_stdout, c);
fx_stream_write_char(fx_stdout, '\n');
b_file_unref(src);
fx_file_unref(src);
return 0;
}

View File

@@ -1,4 +1,4 @@
#include <blue/cmd.h>
#include <fx/cmd.h>
#include <stdio.h>
enum {
@@ -27,149 +27,149 @@ const char *text
"great pleasure.";
static int test_command(
const b_command *self, const b_arglist *opt, const b_array *args)
const fx_command *self, const fx_arglist *opt, const fx_array *args)
{
printf("Hello, world!\n");
b_arglist_iterator it;
b_arglist_iterator_begin(
opt, B_COMMAND_INVALID_ID, B_COMMAND_INVALID_ID, &it);
while (b_arglist_iterator_is_valid(&it)) {
fx_arglist_iterator it;
fx_arglist_iterator_begin(
opt, FX_COMMAND_INVALID_ID, FX_COMMAND_INVALID_ID, &it);
while (fx_arglist_iterator_is_valid(&it)) {
printf("opt:%u,arg:%u,i:%zu,value: %s\n", it.opt_id,
it.value->val_id, it.i, it.value->val_str);
b_arglist_iterator_next(&it);
fx_arglist_iterator_next(&it);
}
return 0;
}
B_COMMAND(CMD_TEST, B_COMMAND_INVALID_ID)
FX_COMMAND(CMD_TEST, FX_COMMAND_INVALID_ID)
{
B_COMMAND_NAME("test");
B_COMMAND_DESC("A test command.");
B_COMMAND_FLAGS(B_COMMAND_SHOW_HELP_BY_DEFAULT);
B_COMMAND_FUNCTION(test_command);
FX_COMMAND_NAME("test");
FX_COMMAND_DESC("A test command.");
FX_COMMAND_FLAGS(FX_COMMAND_SHOW_HELP_BY_DEFAULT);
FX_COMMAND_FUNCTION(test_command);
B_COMMAND_OPTION(OPT_NAME)
FX_COMMAND_OPTION(OPT_NAME)
{
B_OPTION_LONG_NAME("name");
B_OPTION_SHORT_NAME('n');
B_OPTION_DESC("The name of the data.");
B_OPTION_ARG(OPT_NAME_VALUE)
FX_OPTION_LONG_NAME("name");
FX_OPTION_SHORT_NAME('n');
FX_OPTION_DESC("The name of the data.");
FX_OPTION_ARG(OPT_NAME_VALUE)
{
B_ARG_NAME("name");
B_ARG_NR_VALUES(2);
FX_ARG_NAME("name");
FX_ARG_NR_VALUES(2);
}
}
B_COMMAND_OPTION(OPT_OTHER)
FX_COMMAND_OPTION(OPT_OTHER)
{
B_OPTION_LONG_NAME("other");
B_OPTION_DESC(text);
FX_OPTION_LONG_NAME("other");
FX_OPTION_DESC(text);
B_OPTION_ARG(OPT_OTHER_VALUE)
FX_OPTION_ARG(OPT_OTHER_VALUE)
{
B_ARG_NAME("value");
B_ARG_NR_VALUES(B_ARG_1_OR_MORE_VALUES);
FX_ARG_NAME("value");
FX_ARG_NR_VALUES(FX_ARG_1_OR_MORE_VALUES);
}
}
B_COMMAND_OPTION(OPT_VERBOSE)
FX_COMMAND_OPTION(OPT_VERBOSE)
{
B_OPTION_LONG_NAME("verbose");
B_OPTION_SHORT_NAME('v');
B_OPTION_DESC("Show detailed log output.");
FX_OPTION_LONG_NAME("verbose");
FX_OPTION_SHORT_NAME('v');
FX_OPTION_DESC("Show detailed log output.");
}
B_COMMAND_OPTION(OPT_REALLY_VERBOSE)
FX_COMMAND_OPTION(OPT_REALLY_VERBOSE)
{
B_OPTION_LONG_NAME("really-verbose");
B_OPTION_SHORT_NAME('V');
B_OPTION_DESC("Show REALLY detailed log output.");
FX_OPTION_LONG_NAME("really-verbose");
FX_OPTION_SHORT_NAME('V');
FX_OPTION_DESC("Show REALLY detailed log output.");
}
B_COMMAND_OPTION(OPT_MODE)
FX_COMMAND_OPTION(OPT_MODE)
{
B_OPTION_SHORT_NAME('m');
B_OPTION_LONG_NAME("mode");
B_OPTION_DESC("modes to operate in.");
FX_OPTION_SHORT_NAME('m');
FX_OPTION_LONG_NAME("mode");
FX_OPTION_DESC("modes to operate in.");
B_OPTION_ARG(OPT_MODE_VALUE)
FX_OPTION_ARG(OPT_MODE_VALUE)
{
B_ARG_NAME("mode");
B_ARG_NR_VALUES(1);
B_ARG_ALLOWED_VALUES("fast", "slow");
FX_ARG_NAME("mode");
FX_ARG_NR_VALUES(1);
FX_ARG_ALLOWED_VALUES("fast", "slow");
}
B_OPTION_ARG(OPT_MODE_VALUE2)
FX_OPTION_ARG(OPT_MODE_VALUE2)
{
B_ARG_NAME("mode2");
B_ARG_NR_VALUES(1);
B_ARG_ALLOWED_VALUES("very-fast", "very-slow");
FX_ARG_NAME("mode2");
FX_ARG_NR_VALUES(1);
FX_ARG_ALLOWED_VALUES("very-fast", "very-slow");
}
}
B_COMMAND_ARG(ARG_FILE)
FX_COMMAND_ARG(ARG_FILE)
{
B_ARG_NAME("file");
B_ARG_DESC("The file(s) to use");
B_ARG_NR_VALUES(2);
FX_ARG_NAME("file");
FX_ARG_DESC("The file(s) to use");
FX_ARG_NR_VALUES(2);
}
B_COMMAND_ARG(ARG_MORE)
FX_COMMAND_ARG(ARG_MORE)
{
B_ARG_NAME("more");
B_ARG_DESC("More args to use");
B_ARG_ALLOWED_VALUES("how", "wow");
B_ARG_NR_VALUES(2);
FX_ARG_NAME("more");
FX_ARG_DESC("More args to use");
FX_ARG_ALLOWED_VALUES("how", "wow");
FX_ARG_NR_VALUES(2);
}
B_COMMAND_HELP_OPTION();
FX_COMMAND_HELP_OPTION();
B_COMMAND_USAGE()
FX_COMMAND_USAGE()
{
B_COMMAND_USAGE_OPT(OPT_NAME);
B_COMMAND_USAGE_ARG(ARG_FILE);
B_COMMAND_USAGE_ARG(ARG_MORE);
FX_COMMAND_USAGE_OPT(OPT_NAME);
FX_COMMAND_USAGE_ARG(ARG_FILE);
FX_COMMAND_USAGE_ARG(ARG_MORE);
}
}
B_COMMAND(CMD_SUB, CMD_TEST)
FX_COMMAND(CMD_SUB, CMD_TEST)
{
B_COMMAND_NAME("sub");
B_COMMAND_LONG_NAME("sub");
B_COMMAND_SHORT_NAME('S');
B_COMMAND_DESC("A test subcommand");
B_COMMAND_FLAGS(B_COMMAND_SHOW_HELP_BY_DEFAULT);
B_COMMAND_FUNCTION(test_command);
FX_COMMAND_NAME("sub");
FX_COMMAND_LONG_NAME("sub");
FX_COMMAND_SHORT_NAME('S');
FX_COMMAND_DESC("A test subcommand");
FX_COMMAND_FLAGS(FX_COMMAND_SHOW_HELP_BY_DEFAULT);
FX_COMMAND_FUNCTION(test_command);
B_COMMAND_OPTION(OPT_NAME)
FX_COMMAND_OPTION(OPT_NAME)
{
B_OPTION_LONG_NAME("name");
B_OPTION_SHORT_NAME('n');
B_OPTION_DESC("The name of the data");
B_OPTION_ARG(OPT_NAME_VALUE)
FX_OPTION_LONG_NAME("name");
FX_OPTION_SHORT_NAME('n');
FX_OPTION_DESC("The name of the data");
FX_OPTION_ARG(OPT_NAME_VALUE)
{
B_ARG_NAME("name");
FX_ARG_NAME("name");
}
}
B_COMMAND_OPTION(OPT_OTHER)
FX_COMMAND_OPTION(OPT_OTHER)
{
B_OPTION_LONG_NAME("other");
B_OPTION_SHORT_NAME('o');
B_OPTION_DESC("The other argument");
B_OPTION_ARG(OPT_OTHER_VALUE)
FX_OPTION_LONG_NAME("other");
FX_OPTION_SHORT_NAME('o');
FX_OPTION_DESC("The other argument");
FX_OPTION_ARG(OPT_OTHER_VALUE)
{
B_ARG_NAME("value");
FX_ARG_NAME("value");
}
}
B_COMMAND_HELP_OPTION();
FX_COMMAND_HELP_OPTION();
}
int main(int argc, const char **argv)
{
return b_command_dispatch(CMD_TEST, argc, argv);
return fx_command_dispatch(CMD_TEST, argc, argv);
}

View File

@@ -1,9 +1,9 @@
#include <assert.h>
#include <blue/compress/compressor.h>
#include <blue/compress/cstream.h>
#include <blue/compress/zstd.h>
#include <blue/core/ringbuffer.h>
#include <blue/core/stream.h>
#include <fx/compress/compressor.h>
#include <fx/compress/cstream.h>
#include <fx/compress/zstd.h>
#include <fx/core/ringbuffer.h>
#include <fx/core/stream.h>
#include <stdio.h>
#include <string.h>
@@ -26,7 +26,7 @@ int main(int argc, const char **argv)
return -1;
}
b_compressor_mode mode = B_COMPRESSOR_MODE_COMPRESS;
fx_compressor_mode mode = FX_COMPRESSOR_MODE_COMPRESS;
FILE *out_fp = fopen(argv[1], "wb");
if (!out_fp) {
@@ -34,36 +34,36 @@ int main(int argc, const char **argv)
return -1;
}
b_stream *out_stream = b_stream_open_fp(out_fp);
b_cstream *cstream;
b_cstream_open(out_stream, B_TYPE_ZSTD_COMPRESSOR, mode, &cstream);
fx_stream *out_stream = fx_stream_open_fp(out_fp);
fx_cstream *cstream;
fx_cstream_open(out_stream, FX_TYPE_ZSTD_COMPRESSOR, mode, &cstream);
const size_t source_len = strlen(source);
bool compressed = false;
for (int i = 0; i < NR_ITERATIONS; i++) {
if (compressed) {
b_cstream_begin_compressed_section(cstream, NULL);
fx_cstream_begin_compressed_section(cstream, NULL);
}
size_t nr_written = 0;
b_status status = b_cstream_write(
fx_status status = fx_cstream_write(
cstream, source, source_len, &nr_written);
if (!B_OK(status)) {
if (!FX_OK(status)) {
fprintf(stderr, "write error: %s\n",
b_status_description(status));
fx_status_description(status));
break;
}
size_t nr_written_compressed = 0;
if (compressed) {
b_cstream_end_compressed_section(
fx_cstream_end_compressed_section(
cstream, &nr_written_compressed, &nr_written);
}
size_t tx_total = 0;
b_cstream_tx_bytes(cstream, &tx_total);
fx_cstream_tx_bytes(cstream, &tx_total);
printf("iteration %d: wrote %zu (compressed) / %zu "
"(uncompressed) / %zu (total) bytes (%s)\n",
i, nr_written_compressed, nr_written, tx_total,
@@ -74,8 +74,8 @@ int main(int argc, const char **argv)
printf("Done\n");
b_cstream_unref(cstream);
b_stream_unref(out_stream);
fx_cstream_unref(cstream);
fx_stream_unref(out_stream);
fclose(out_fp);
return 0;

View File

@@ -1,9 +1,9 @@
#include <assert.h>
#include <blue/compress/compressor.h>
#include <blue/compress/cstream.h>
#include <blue/compress/zstd.h>
#include <blue/core/ringbuffer.h>
#include <blue/core/stream.h>
#include <fx/compress/compressor.h>
#include <fx/compress/cstream.h>
#include <fx/compress/zstd.h>
#include <fx/core/ringbuffer.h>
#include <fx/core/stream.h>
#include <stdio.h>
#include <string.h>
@@ -14,7 +14,7 @@ int main(int argc, const char **argv)
return -1;
}
b_compressor_mode mode = B_COMPRESSOR_MODE_DECOMPRESS;
fx_compressor_mode mode = FX_COMPRESSOR_MODE_DECOMPRESS;
FILE *in_fp = fopen(argv[1], "rb");
if (!in_fp) {
@@ -22,26 +22,26 @@ int main(int argc, const char **argv)
return -1;
}
b_stream *in_stream = b_stream_open_fp(in_fp);
b_cstream *cstream;
b_cstream_open(in_stream, B_TYPE_ZSTD_COMPRESSOR, mode, &cstream);
fx_stream *in_stream = fx_stream_open_fp(in_fp);
fx_cstream *cstream;
fx_cstream_open(in_stream, FX_TYPE_ZSTD_COMPRESSOR, mode, &cstream);
bool compressed = false;
char buf[513];
for (int i = 0;; i++) {
if (compressed) {
b_cstream_begin_compressed_section(cstream, NULL);
fx_cstream_begin_compressed_section(cstream, NULL);
}
memset(buf, 0x0, sizeof buf);
size_t nr_read = 0;
b_status status
= b_cstream_read(cstream, buf, sizeof buf - 1, &nr_read);
if (!B_OK(status)) {
fx_status status
= fx_cstream_read(cstream, buf, sizeof buf - 1, &nr_read);
if (!FX_OK(status)) {
fprintf(stderr, "write error: %s\n",
b_status_description(status));
fx_status_description(status));
break;
}
@@ -51,12 +51,12 @@ int main(int argc, const char **argv)
size_t nr_read_compressed = 0;
if (compressed) {
b_cstream_end_compressed_section(
fx_cstream_end_compressed_section(
cstream, &nr_read_compressed, &nr_read);
}
size_t tx_total = 0;
b_cstream_tx_bytes(cstream, &tx_total);
fx_cstream_tx_bytes(cstream, &tx_total);
printf(" * iteration %d: read %zu (compressed) / %zu "
"(uncompressed) / %zu (total) bytes (%s)\n",
i, nr_read_compressed, nr_read, tx_total,
@@ -68,8 +68,8 @@ int main(int argc, const char **argv)
printf("Done\n");
b_cstream_unref(cstream);
b_stream_unref(in_stream);
fx_cstream_unref(cstream);
fx_stream_unref(in_stream);
fclose(in_fp);
return 0;

View File

@@ -1,30 +1,30 @@
#include <assert.h>
#include <blue/compress/compressor.h>
#include <blue/compress/zstd.h>
#include <blue/core/ringbuffer.h>
#include <fx/compress/compressor.h>
#include <fx/compress/zstd.h>
#include <fx/core/ringbuffer.h>
#include <stdio.h>
#include <string.h>
#define BUF_SIZE 32
int refill_input_buffer(FILE *fp, b_ringbuffer *dest)
int refill_input_buffer(FILE *fp, fx_ringbuffer *dest)
{
while (1) {
void *buf;
size_t capacity;
b_status status
= b_ringbuffer_open_write_buffer(dest, &buf, &capacity);
if (status == B_ERR_NO_SPACE) {
fx_status status
= fx_ringbuffer_open_write_buffer(dest, &buf, &capacity);
if (status == FX_ERR_NO_SPACE) {
break;
}
if (!B_OK(status)) {
if (!FX_OK(status)) {
return -1;
}
size_t r = fread(buf, 1, capacity, fp);
b_ringbuffer_close_write_buffer(dest, &buf, r);
fx_ringbuffer_close_write_buffer(dest, &buf, r);
if (r == 0) {
return ferror(fp) ? -1 : 0;
@@ -38,24 +38,24 @@ int refill_input_buffer(FILE *fp, b_ringbuffer *dest)
return 0;
}
int flush_output_buffer(FILE *fp, b_ringbuffer *src)
int flush_output_buffer(FILE *fp, fx_ringbuffer *src)
{
while (1) {
const void *buf;
size_t capacity;
b_status status
= b_ringbuffer_open_read_buffer(src, &buf, &capacity);
if (status == B_ERR_NO_DATA) {
fx_status status
= fx_ringbuffer_open_read_buffer(src, &buf, &capacity);
if (status == FX_ERR_NO_DATA) {
break;
}
if (!B_OK(status)) {
if (!FX_OK(status)) {
return -1;
}
size_t w = fwrite(buf, 1, capacity, fp);
b_ringbuffer_close_read_buffer(src, &buf, w);
fx_ringbuffer_close_read_buffer(src, &buf, w);
if (w < capacity) {
return -1;
@@ -72,11 +72,11 @@ int main(int argc, const char **argv)
return -1;
}
b_compressor_mode mode;
fx_compressor_mode mode;
if (!strcmp(argv[1], "C")) {
mode = B_COMPRESSOR_MODE_COMPRESS;
mode = FX_COMPRESSOR_MODE_COMPRESS;
} else if (!strcmp(argv[1], "D")) {
mode = B_COMPRESSOR_MODE_DECOMPRESS;
mode = FX_COMPRESSOR_MODE_DECOMPRESS;
} else {
fprintf(stderr, "invalid mode %s\n", argv[1]);
return -1;
@@ -95,24 +95,24 @@ int main(int argc, const char **argv)
return -1;
}
b_status status = B_SUCCESS;
b_type compressor_type = B_TYPE_ZSTD_COMPRESSOR;
b_compressor *compressor = b_object_create(compressor_type);
fx_status status = FX_SUCCESS;
fx_type compressor_type = FX_TYPE_ZSTD_COMPRESSOR;
fx_compressor *compressor = fx_object_create(compressor_type);
size_t inbuf_size, outbuf_size;
b_compressor_get_buffer_size(
fx_compressor_get_buffer_size(
compressor_type, mode, &inbuf_size, &outbuf_size);
b_ringbuffer *in = b_ringbuffer_create(inbuf_size);
b_ringbuffer *out = b_ringbuffer_create(outbuf_size);
fx_ringbuffer *in = fx_ringbuffer_create(inbuf_size);
fx_ringbuffer *out = fx_ringbuffer_create(outbuf_size);
if (!in || !out) {
fprintf(stderr, "memory allocation failure");
return -1;
}
b_compressor_set_buffer(compressor, in, out);
b_compressor_set_mode(compressor, mode);
fx_compressor_set_buffer(compressor, in, out);
fx_compressor_set_mode(compressor, mode);
int ret = 0;
while (1) {
@@ -122,21 +122,21 @@ int main(int argc, const char **argv)
break;
}
if (!b_ringbuffer_available_data_remaining(in)) {
if (!fx_ringbuffer_available_data_remaining(in)) {
break;
}
status = b_compressor_step(compressor);
status = fx_compressor_step(compressor);
if (status == B_ERR_NO_DATA) {
if (status == FX_ERR_NO_DATA) {
break;
} else if (status == B_ERR_NO_SPACE) {
} else if (status == FX_ERR_NO_SPACE) {
ret = flush_output_buffer(out_fp, out);
if (ret != 0) {
fprintf(stderr, "write error\n");
break;
}
} else if (!B_OK(status)) {
} else if (!FX_OK(status)) {
ret = -1;
break;
}
@@ -148,16 +148,16 @@ int main(int argc, const char **argv)
return -1;
}
if (mode == B_COMPRESSOR_MODE_COMPRESS) {
while (!b_compressor_eof(compressor)) {
status = b_compressor_end(compressor);
if (!B_OK(status)) {
if (mode == FX_COMPRESSOR_MODE_COMPRESS) {
while (!fx_compressor_eof(compressor)) {
status = fx_compressor_end(compressor);
if (!FX_OK(status)) {
fprintf(stderr,
"compression finalisation error\n");
return -1;
}
if (!b_ringbuffer_available_data_remaining(out)) {
if (!fx_ringbuffer_available_data_remaining(out)) {
break;
}
@@ -171,13 +171,13 @@ int main(int argc, const char **argv)
printf("Done\n");
b_compressor_unref(compressor);
fx_compressor_unref(compressor);
fclose(in_fp);
fclose(out_fp);
b_ringbuffer_unref(in);
b_ringbuffer_unref(out);
fx_ringbuffer_unref(in);
fx_ringbuffer_unref(out);
return ret;
}

View File

@@ -1,35 +1,35 @@
#include <assert.h>
#include <blue/compress/compressor.h>
#include <blue/compress/cstream.h>
#include <blue/compress/zstd.h>
#include <blue/core/ringbuffer.h>
#include <blue/core/stream.h>
#include <fx/compress/compressor.h>
#include <fx/compress/cstream.h>
#include <fx/compress/zstd.h>
#include <fx/core/ringbuffer.h>
#include <fx/core/stream.h>
#include <stdio.h>
#include <string.h>
#define BUF_SIZE 32
static int compress(b_type compressor_type, FILE *in, FILE *out)
static int compress(fx_type compressor_type, FILE *in, FILE *out)
{
b_stream *out_stream = b_stream_open_fp(out);
fx_stream *out_stream = fx_stream_open_fp(out);
b_cstream *cstream;
b_status status = b_cstream_open(
out_stream, compressor_type, B_COMPRESSOR_MODE_COMPRESS, &cstream);
fx_cstream *cstream;
fx_status status = fx_cstream_open(
out_stream, compressor_type, FX_COMPRESSOR_MODE_COMPRESS, &cstream);
if (!B_OK(status)) {
if (!FX_OK(status)) {
fprintf(stderr, "cannot initialise compressor\n");
return -1;
}
b_cstream_begin_compressed_section(cstream, NULL);
fx_cstream_begin_compressed_section(cstream, NULL);
char buf[4096];
while (1) {
size_t r = fread(buf, 1, sizeof buf, in);
size_t w = 0;
b_cstream_write(cstream, buf, r, &w);
fx_cstream_write(cstream, buf, r, &w);
if (r != w) {
fprintf(stderr, "write error\n");
@@ -41,35 +41,35 @@ static int compress(b_type compressor_type, FILE *in, FILE *out)
}
}
b_cstream_end_compressed_section(cstream, NULL, NULL);
b_cstream_unref(cstream);
b_stream_unref(out_stream);
fx_cstream_end_compressed_section(cstream, NULL, NULL);
fx_cstream_unref(cstream);
fx_stream_unref(out_stream);
return 0;
}
static int decompress(b_type compressor_type, FILE *in, FILE *out)
static int decompress(fx_type compressor_type, FILE *in, FILE *out)
{
b_stream *in_stream = b_stream_open_fp(in);
fx_stream *in_stream = fx_stream_open_fp(in);
b_cstream *cstream;
b_status status = b_cstream_open(
in_stream, compressor_type, B_COMPRESSOR_MODE_DECOMPRESS, &cstream);
fx_cstream *cstream;
fx_status status = fx_cstream_open(
in_stream, compressor_type, FX_COMPRESSOR_MODE_DECOMPRESS, &cstream);
if (!B_OK(status)) {
if (!FX_OK(status)) {
fprintf(stderr, "cannot initialise compressor\n");
return -1;
}
b_cstream_begin_compressed_section(cstream, NULL);
fx_cstream_begin_compressed_section(cstream, NULL);
char buf[4096];
while (1) {
size_t r = 0;
b_status status = b_cstream_read(cstream, buf, sizeof buf, &r);
if (!B_OK(status)) {
fx_status status = fx_cstream_read(cstream, buf, sizeof buf, &r);
if (!FX_OK(status)) {
fprintf(stderr, "read error: %s\n",
b_status_description(status));
fx_status_description(status));
return -1;
}
@@ -84,9 +84,9 @@ static int decompress(b_type compressor_type, FILE *in, FILE *out)
}
}
b_cstream_end_compressed_section(cstream, NULL, NULL);
b_cstream_unref(cstream);
b_stream_unref(in_stream);
fx_cstream_end_compressed_section(cstream, NULL, NULL);
fx_cstream_unref(cstream);
fx_stream_unref(in_stream);
return 0;
}
@@ -98,11 +98,11 @@ int main(int argc, const char **argv)
return -1;
}
b_compressor_mode mode;
fx_compressor_mode mode;
if (!strcmp(argv[1], "C")) {
mode = B_COMPRESSOR_MODE_COMPRESS;
mode = FX_COMPRESSOR_MODE_COMPRESS;
} else if (!strcmp(argv[1], "D")) {
mode = B_COMPRESSOR_MODE_DECOMPRESS;
mode = FX_COMPRESSOR_MODE_DECOMPRESS;
} else {
fprintf(stderr, "invalid mode %s\n", argv[1]);
return -1;
@@ -123,11 +123,11 @@ int main(int argc, const char **argv)
int ret = 0;
switch (mode) {
case B_COMPRESSOR_MODE_COMPRESS:
ret = compress(B_TYPE_ZSTD_COMPRESSOR, in_fp, out_fp);
case FX_COMPRESSOR_MODE_COMPRESS:
ret = compress(FX_TYPE_ZSTD_COMPRESSOR, in_fp, out_fp);
break;
case B_COMPRESSOR_MODE_DECOMPRESS:
ret = decompress(B_TYPE_ZSTD_COMPRESSOR, in_fp, out_fp);
case FX_COMPRESSOR_MODE_DECOMPRESS:
ret = decompress(FX_TYPE_ZSTD_COMPRESSOR, in_fp, out_fp);
break;
default:
ret = -1;

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;

View File

@@ -1,21 +1,21 @@
#include <blue/ds/array.h>
#include <blue/ds/number.h>
#include <fx/ds/array.h>
#include <fx/ds/number.h>
#include <stdio.h>
int main(void)
{
b_array *array = b_array_create();
b_array_append(array, B_RV_INT(32));
b_array_append(array, B_RV_INT(64));
b_array_append(array, B_RV_INT(128));
fx_array *array = fx_array_create();
fx_array_append(array, FX_RV_INT(32));
fx_array_append(array, FX_RV_INT(64));
fx_array_append(array, FX_RV_INT(128));
b_iterator *it = b_iterator_begin(array);
b_foreach_ptr(b_object, obj, it)
fx_iterator *it = fx_iterator_begin(array);
fx_foreach_ptr(fx_object, obj, it)
{
printf("object %p\n", obj);
}
b_iterator_unref(it);
fx_iterator_unref(it);
b_array_unref(array);
fx_array_unref(array);
return 0;
}

View File

@@ -1,42 +1,42 @@
#include <CuTest.h>
#include <blue/ds/string.h>
#include <fx/ds/string.h>
static void test_string_create(CuTest *tc)
{
b_string *str = b_string_create();
fx_string *str = fx_string_create();
CuAssertPtrNotNull(tc, str);
CuAssertIntEquals(tc, 0, b_string_get_size(str, B_STRLEN_NORMAL));
CuAssertStrEquals(tc, "", b_string_ptr(str));
CuAssertIntEquals(tc, 0, fx_string_get_size(str, FX_STRLEN_NORMAL));
CuAssertStrEquals(tc, "", fx_string_ptr(str));
b_string_unref(str);
fx_string_unref(str);
str = b_string_create_from_c('A', 8);
str = fx_string_create_from_c('A', 8);
CuAssertPtrNotNull(tc, str);
CuAssertIntEquals(tc, 8, b_string_get_size(str, B_STRLEN_NORMAL));
CuAssertStrEquals(tc, "AAAAAAAA", b_string_ptr(str));
CuAssertIntEquals(tc, 8, fx_string_get_size(str, FX_STRLEN_NORMAL));
CuAssertStrEquals(tc, "AAAAAAAA", fx_string_ptr(str));
b_string_unref(str);
fx_string_unref(str);
str = b_string_create_from_cstr("Hello, world!");
str = fx_string_create_from_cstr("Hello, world!");
CuAssertPtrNotNull(tc, str);
CuAssertIntEquals(tc, 13, b_string_get_size(str, B_STRLEN_NORMAL));
CuAssertStrEquals(tc, "Hello, world!", b_string_ptr(str));
CuAssertIntEquals(tc, 13, fx_string_get_size(str, FX_STRLEN_NORMAL));
CuAssertStrEquals(tc, "Hello, world!", fx_string_ptr(str));
b_string_unref(str);
fx_string_unref(str);
}
static void test_string_length(CuTest *tc)
{
const char *cstr = "Hello, \033[91;1mworld!";
b_string *s = b_string_create_from_cstr(cstr);
fx_string *s = fx_string_create_from_cstr(cstr);
CuAssertIntEquals(tc, 13, b_string_get_size(s, B_STRLEN_IGNORE_ESC));
CuAssertIntEquals(tc, 20, b_string_get_size(s, B_STRLEN_NORMAL));
CuAssertIntEquals(tc, 13, fx_string_get_size(s, FX_STRLEN_IGNORE_ESC));
CuAssertIntEquals(tc, 20, fx_string_get_size(s, FX_STRLEN_NORMAL));
b_string_unref(s);
fx_string_unref(s);
}
CuSuite *get_all_tests(void)

View File

@@ -1,11 +1,11 @@
#include <blue/ds/number.h>
#include <fx/ds/number.h>
#include <stdio.h>
int main(void)
{
b_number *number = b_number_create_float(6.8);
fx_number *number = fx_number_create_float(6.8);
printf("number=%zd\n", B_NUMBER_IVAL(number));
b_number_unref(number);
printf("number=%zd\n", FX_NUMBER_IVAL(number));
fx_number_unref(number);
return 0;
}

View File

@@ -1,11 +1,11 @@
#include <blue/ds/string.h>
#include <fx/ds/string.h>
int main(void)
{
b_string *string = B_CSTR("Hello, world!");
fx_string *string = FX_CSTR("Hello, world!");
printf("string object = ");
b_object_to_string(string, b_stdout);
fx_object_to_string(string, fx_stdout);
printf("\n");
b_string_unref(string);
fx_string_unref(string);
return 0;
}

View File

@@ -1,19 +1,19 @@
#include <blue/core/stream.h>
#include <blue/core/stringstream.h>
#include <blue/ds/string.h>
#include <fx/core/stream.h>
#include <fx/core/stringstream.h>
#include <fx/ds/string.h>
#include <stdio.h>
int main(int argc, const char **argv)
{
size_t nr_read = 0;
b_stringstream *dest_stream = b_stringstream_create();
b_stream_buffer *buf = b_stream_buffer_create_dynamic(1024);
b_stream_read_all_bytes_s(b_stdin, dest_stream, buf, &nr_read);
fx_stringstream *dest_stream = fx_stringstream_create();
fx_stream_buffer *buf = fx_stream_buffer_create_dynamic(1024);
fx_stream_read_all_bytes_s(fx_stdin, dest_stream, buf, &nr_read);
printf("done. read %zu bytes total.\n", nr_read);
printf("%s\n", b_stringstream_ptr(dest_stream));
printf("%s\n", fx_stringstream_ptr(dest_stream));
b_stringstream_unref(dest_stream);
b_stream_buffer_unref(buf);
fx_stringstream_unref(dest_stream);
fx_stream_buffer_unref(buf);
return 0;
}

View File

@@ -1,40 +1,40 @@
#include <blue/core/stringstream.h>
#include <blue/ds/string.h>
#include <fx/core/stringstream.h>
#include <fx/ds/string.h>
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
printf("-------------\n");
b_string *str = b_string_create_from_cstr("Hello, world!\n");
printf("%s\n", b_string_ptr(str));
printf("len:%zu, max:%zu\n", b_string_get_size(str, B_STRLEN_NORMAL),
b_string_get_capacity(str));
fx_string *str = fx_string_create_from_cstr("Hello, world!\n");
printf("%s\n", fx_string_ptr(str));
printf("len:%zu, max:%zu\n", fx_string_get_size(str, FX_STRLEN_NORMAL),
fx_string_get_capacity(str));
b_string_insert_cstr(str, "WOW!", 4);
fx_string_insert_cstr(str, "WOW!", 4);
printf("-------------\n");
printf("%s\n", b_string_ptr(str));
printf("len:%zu, max:%zu\n", b_string_get_size(str, B_STRLEN_NORMAL),
b_string_get_capacity(str));
printf("%s\n", fx_string_ptr(str));
printf("len:%zu, max:%zu\n", fx_string_get_size(str, FX_STRLEN_NORMAL),
fx_string_get_capacity(str));
b_string_replace(str, 4, 4, "+");
fx_string_replace(str, 4, 4, "+");
printf("-------------\n");
printf("%s\n", b_string_ptr(str));
printf("len:%zu, max:%zu\n", b_string_get_size(str, B_STRLEN_NORMAL),
b_string_get_capacity(str));
printf("%s\n", fx_string_ptr(str));
printf("len:%zu, max:%zu\n", fx_string_get_size(str, FX_STRLEN_NORMAL),
fx_string_get_capacity(str));
printf("-------------\n");
b_string_unref(str);
fx_string_unref(str);
b_stringstream *strv = b_stringstream_create();
b_stream_write_string(strv, "Hello", NULL);
b_stream_write_string(strv, ", world", NULL);
b_stream_write_string(strv, "!", NULL);
fx_stringstream *strv = fx_stringstream_create();
fx_stream_write_string(strv, "Hello", NULL);
fx_stream_write_string(strv, ", world", NULL);
fx_stream_write_string(strv, "!", NULL);
char *s = b_stringstream_steal(strv);
b_stringstream_unref(strv);
char *s = fx_stringstream_steal(strv);
fx_stringstream_unref(strv);
printf("%s\n", s);
free(s);

View File

@@ -1,68 +1,68 @@
#include <blue/core/btree.h>
#include <blue/core/iterator.h>
#include <blue/ds/dict.h>
#include <blue/ds/number.h>
#include <blue/ds/tree.h>
#include <fx/core/btree.h>
#include <fx/core/iterator.h>
#include <fx/ds/dict.h>
#include <fx/ds/number.h>
#include <fx/ds/tree.h>
#include <stdio.h>
#define NITEMS 16
struct tree_item {
int value;
b_tree_node node;
fx_tree_node node;
};
struct btree_item {
int value;
b_btree_node node;
fx_bst_node node;
};
B_BTREE_DEFINE_SIMPLE_GET(struct btree_item, int, node, value, get_node)
B_BTREE_DEFINE_SIMPLE_INSERT(struct btree_item, node, value, put_node)
FX_BTREE_DEFINE_SIMPLE_GET(struct btree_item, int, node, value, get_node)
FX_BTREE_DEFINE_SIMPLE_INSERT(struct btree_item, node, value, put_node)
int main(void)
{
b_dict *dict = b_dict_create();
b_dict_put(dict, "hello", B_RV_INT(32));
b_dict_put(dict, "world", B_RV_INT(64));
b_dict_put(dict, "more", B_RV_INT(128));
b_dict_put(dict, "other", B_RV_INT(256));
fx_dict *dict = fx_dict_create();
fx_dict_put(dict, "hello", FX_RV_INT(32));
fx_dict_put(dict, "world", FX_RV_INT(64));
fx_dict_put(dict, "more", FX_RV_INT(128));
fx_dict_put(dict, "other", FX_RV_INT(256));
b_iterator *it = b_iterator_begin(dict);
fx_iterator *it = fx_iterator_begin(dict);
size_t i = 0;
b_foreach(b_dict_item *, item, it)
fx_foreach(fx_dict_item *, item, it)
{
printf("item %zu: %s=%d\n", i++, b_string_ptr(item->key),
b_number_get_int(item->value));
printf("item %zu: %s=%d\n", i++, fx_string_ptr(item->key),
fx_number_get_int(item->value));
}
b_iterator_unref(it);
fx_iterator_unref(it);
b_tree *tree = b_tree_create();
fx_tree *tree = fx_tree_create();
struct tree_item items2[NITEMS];
for (int i = 0; i < NITEMS; i++) {
items2[i].value = i;
items2[i].node = B_TREE_NODE_INIT;
items2[i].node = FX_TREE_NODE_INIT;
}
b_tree_set_root(tree, &items2[0].node);
fx_tree_set_root(tree, &items2[0].node);
b_tree_node_add_child(&items2[0].node, &items2[1].node);
b_tree_node_add_child(&items2[0].node, &items2[2].node);
b_tree_node_add_child(&items2[0].node, &items2[3].node);
b_tree_node_add_child(&items2[0].node, &items2[7].node);
b_tree_node_add_child(&items2[1].node, &items2[4].node);
b_tree_node_add_child(&items2[1].node, &items2[5].node);
b_tree_node_add_child(&items2[4].node, &items2[6].node);
fx_tree_node_add_child(&items2[0].node, &items2[1].node);
fx_tree_node_add_child(&items2[0].node, &items2[2].node);
fx_tree_node_add_child(&items2[0].node, &items2[3].node);
fx_tree_node_add_child(&items2[0].node, &items2[7].node);
fx_tree_node_add_child(&items2[1].node, &items2[4].node);
fx_tree_node_add_child(&items2[1].node, &items2[5].node);
fx_tree_node_add_child(&items2[4].node, &items2[6].node);
#if 0
it = b_iterator_begin(tree);
b_tree_iterator it2;
b_tree_foreach(&it2, tree)
it = fx_iterator_begin(tree);
fx_tree_iterator it2;
fx_tree_foreach(&it2, tree)
{
struct tree_item *item = b_unbox(struct tree_item, it2.node, node);
struct tree_item *item = fx_unbox(struct tree_item, it2.node, node);
for (size_t i = 0; i < it2.depth; i++) {
fputs(" ", stdout);
@@ -71,7 +71,7 @@ int main(void)
printf("%u\n", item->value);
}
b_btree btree = {0};
fx_bst btree = {0};
struct btree_item items3[NITEMS] = {0};
for (int i = 0; i < NITEMS; i++) {
items3[i].value = i;
@@ -80,10 +80,10 @@ int main(void)
printf("\n\n");
b_btree_iterator it3;
b_btree_foreach (&it3, &btree) {
fx_bst_iterator it3;
fx_bst_foreach (&it3, &btree) {
struct btree_item *item
= b_unbox(struct btree_item, it3.node, node);
= fx_unbox(struct btree_item, it3.node, node);
for (size_t i = 0; i < it3.depth; i++) {
fputs(" ", stdout);
@@ -92,23 +92,23 @@ int main(void)
printf("%d\n", item->value);
}
b_btree_iterator_begin(&btree, &it3);
while (b_btree_iterator_is_valid(&it3)) {
fx_bst_iterator_begin(&btree, &it3);
while (fx_bst_iterator_is_valid(&it3)) {
struct btree_item *item
= b_unbox(struct btree_item, it3.node, node);
= fx_unbox(struct btree_item, it3.node, node);
if (item->value == 9) {
b_btree_iterator_erase(&it3);
fx_bst_iterator_erase(&it3);
} else {
b_btree_iterator_next(&it3);
fx_bst_iterator_next(&it3);
}
}
printf("\n\n");
b_btree_foreach (&it3, &btree) {
fx_bst_foreach (&it3, &btree) {
struct btree_item *item
= b_unbox(struct btree_item, it3.node, node);
= fx_unbox(struct btree_item, it3.node, node);
for (size_t i = 0; i < it3.depth; i++) {
fputs(" ", stdout);
@@ -117,9 +117,9 @@ int main(void)
printf("%d\n", item->value);
}
b_tree_unref(tree);
fx_tree_unref(tree);
#endif
b_dict_unref(dict);
fx_dict_unref(dict);
return 0;
}

View File

@@ -1,27 +1,27 @@
#include <blue/core/stringstream.h>
#include <blue/ds/string.h>
#include <fx/core/stringstream.h>
#include <fx/ds/string.h>
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
printf("здравс\u26A0твуите\n");
b_string *str = b_string_create_from_cstr("здравствуите");
const char *s = b_string_ptr(str);
fx_string *str = fx_string_create_from_cstr("здравствуите");
const char *s = fx_string_ptr(str);
printf("%s\n", s);
printf("len: %zu\n", b_string_get_size(str, B_STRLEN_NORMAL));
printf("codepoints: %zu\n", b_string_get_size(str, B_STRLEN_CODEPOINTS));
printf("len: %zu\n", fx_string_get_size(str, FX_STRLEN_NORMAL));
printf("codepoints: %zu\n", fx_string_get_size(str, FX_STRLEN_CODEPOINTS));
const char *delims[] = {"в"};
size_t nr_delims = sizeof delims / sizeof delims[0];
b_iterator *it = b_string_tokenise(str, delims, nr_delims, 0);
b_foreach(const char *, tok, it)
fx_iterator *it = fx_string_tokenise(str, delims, nr_delims, 0);
fx_foreach(const char *, tok, it)
{
printf("%s\n", tok);
}
b_iterator_unref(it);
b_string_unref(str);
fx_iterator_unref(it);
fx_string_unref(str);
return 0;
}

View File

@@ -1,14 +1,14 @@
#include <blue/ds/uuid.h>
#include <fx/ds/uuid.h>
#include <stdio.h>
int main(void)
{
b_uuid *uuid = b_uuid_create_from_cstr(
fx_uuid *uuid = fx_uuid_create_from_cstr(
"5b80ad1f-367f-4a1f-88f3-b3a6f8d1f63d");
char str[B_UUID_STRING_MAX];
b_uuid_to_cstr(uuid, str);
char str[FX_UUID_STRING_MAX];
fx_uuid_to_cstr(uuid, str);
printf("%s\n", str);
b_uuid_unref(uuid);
fx_uuid_unref(uuid);
return 0;
}

View File

@@ -1,27 +1,27 @@
#include <CuTest.h>
#include <blue/core/stringstream.h>
#include <blue/io/path.h>
#include <fx/core/stringstream.h>
#include <fx/io/path.h>
#include <stdio.h>
void test_path_1(CuTest *tc)
{
b_path *path = b_path_create_from_cstr("C:\\hello\\world\\");
fx_path *path = fx_path_create_from_cstr("C:\\hello\\world\\");
char buf[512];
b_stringstream *str = b_stringstream_create_with_buffer(buf, sizeof buf);
fx_stringstream *str = fx_stringstream_create_with_buffer(buf, sizeof buf);
b_object_to_string(path, str);
fx_object_to_string(path, str);
printf("%s\n", buf);
b_path *path2 = b_path_create_from_cstr("path1\\path2\\");
b_path *path3 = b_path_create_from_cstr("path3\\path4\\");
fx_path *path2 = fx_path_create_from_cstr("path1\\path2\\");
fx_path *path3 = fx_path_create_from_cstr("path3\\path4\\");
const b_path *paths[] = {path, path2, path3};
const fx_path *paths[] = {path, path2, path3};
b_path *path4 = b_path_join(paths, sizeof paths / sizeof paths[0]);
fx_path *path4 = fx_path_join(paths, sizeof paths / sizeof paths[0]);
b_stringstream_reset_with_buffer(str, buf, sizeof buf);
b_object_to_string(path4, str);
fx_stringstream_reset_with_buffer(str, buf, sizeof buf);
fx_object_to_string(path4, str);
printf("%s\n", buf);
}

View File

@@ -1,5 +1,5 @@
#include <blue/io/directory.h>
#include <blue/io/path.h>
#include <fx/io/directory.h>
#include <fx/io/path.h>
int main(int argc, const char **argv)
{
@@ -9,14 +9,14 @@ int main(int argc, const char **argv)
const char *path = argv[1];
b_directory *dir;
b_result result = b_directory_open(
NULL, B_RV_PATH(path), B_DIRECTORY_OPEN_CREATE_INTERMEDIATE, &dir);
if (b_result_is_error(result)) {
b_throw(result);
fx_directory *dir;
fx_result result = fx_directory_open(
NULL, FX_RV_PATH(path), FX_DIRECTORY_OPEN_CREATE_INTERMEDIATE, &dir);
if (fx_result_is_error(result)) {
fx_throw(result);
return -1;
}
b_directory_unref(dir);
fx_directory_unref(dir);
return 0;
}

View File

@@ -1,4 +1,4 @@
#include <blue/io/directory.h>
#include <fx/io/directory.h>
int main(int argc, const char **argv)
{
@@ -8,16 +8,16 @@ int main(int argc, const char **argv)
const char *path = argv[1];
b_directory *dir;
b_result result = b_directory_open(NULL, B_RV_PATH(path), 0, &dir);
if (b_result_is_error(result)) {
b_throw(result);
fx_directory *dir;
fx_result result = fx_directory_open(NULL, FX_RV_PATH(path), 0, &dir);
if (fx_result_is_error(result)) {
fx_throw(result);
return -1;
}
result = b_directory_delete(dir);
if (b_result_is_error(result)) {
b_throw(result);
result = fx_directory_delete(dir);
if (fx_result_is_error(result)) {
fx_throw(result);
return -1;
}

View File

@@ -1,26 +1,26 @@
#include <blue/core/stream.h>
#include <blue/io/file.h>
#include <blue/io/path.h>
#include <fx/core/stream.h>
#include <fx/io/file.h>
#include <fx/io/path.h>
#include <stdio.h>
int main(int argc, const char **argv)
{
b_file *dest;
b_path *path = b_path_create_from_cstr("data.txt");
b_result result = b_file_open(
NULL, path, B_FILE_WRITE_ONLY | B_FILE_CREATE, &dest);
if (b_result_is_error(result)) {
b_throw(result);
fx_file *dest;
fx_path *path = fx_path_create_from_cstr("data.txt");
fx_result result = fx_file_open(
NULL, path, FX_FILE_WRITE_ONLY | FX_FILE_CREATE, &dest);
if (fx_result_is_error(result)) {
fx_throw(result);
return -1;
}
size_t nr_read = 0;
b_stream_buffer *buf = b_stream_buffer_create_dynamic(1024);
b_stream_read_all_bytes_s(b_stdin, dest, buf, &nr_read);
fx_stream_buffer *buf = fx_stream_buffer_create_dynamic(1024);
fx_stream_read_all_bytes_s(fx_stdin, dest, buf, &nr_read);
printf("done. read %zu bytes total.\n", nr_read);
b_path_unref(path);
b_file_unref(dest);
fx_path_unref(path);
fx_file_unref(dest);
return 0;
}

View File

@@ -1,4 +1,4 @@
#include <blue/io/directory.h>
#include <fx/io/directory.h>
#include <stdio.h>
#define NRAND_NUMBERS 12
@@ -11,22 +11,22 @@ int main(int argc, const char **argv)
return -1;
}
b_directory *dir = NULL;
b_path *path = b_path_create_from_cstr(argv[1]);
b_result result = b_directory_open(B_DIRECTORY_ROOT, path, 0, &dir);
fx_directory *dir = NULL;
fx_path *path = fx_path_create_from_cstr(argv[1]);
fx_result result = fx_directory_open(FX_DIRECTORY_ROOT, path, 0, &dir);
if (b_result_is_error(result)) {
b_throw(result);
if (fx_result_is_error(result)) {
fx_throw(result);
return -1;
}
b_iterator *it = b_directory_begin(dir, B_DIRECTORY_ITERATE_PARENT_FIRST);
b_foreach(b_directory_entry *, entry, it)
fx_iterator *it = fx_directory_begin(dir, FX_DIRECTORY_ITERATE_PARENT_FIRST);
fx_foreach(fx_directory_entry *, entry, it)
{
printf("%s\n", b_path_ptr(entry->filepath));
printf("%s\n", fx_path_ptr(entry->filepath));
}
b_iterator_unref(it);
fx_iterator_unref(it);
return 0;
}

View File

@@ -1,6 +1,6 @@
#include <blue/io/file.h>
#include <blue/io/path.h>
#include <blue/serial.h>
#include <fx/io/file.h>
#include <fx/io/path.h>
#include <fx/serial.h>
#include <stdio.h>
int main(int argc, const char **argv)
@@ -10,31 +10,31 @@ int main(int argc, const char **argv)
}
const char *path_cstr = argv[1];
b_path *path = b_path_create_from_cstr(path_cstr);
fx_path *path = fx_path_create_from_cstr(path_cstr);
b_file *src = NULL;
b_result result = b_file_open(NULL, path, B_FILE_READ_ONLY, &src);
if (b_result_is_error(result)) {
b_throw(result);
fx_file *src = NULL;
fx_result result = fx_file_open(NULL, path, FX_FILE_READ_ONLY, &src);
if (fx_result_is_error(result)) {
fx_throw(result);
return -1;
}
/* TODO re-implement json support */
b_serial_ctx *ctx = NULL;
fx_serial_ctx *ctx = NULL;
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)) {
fprintf(stderr, "cannot read data\n");
return -1;
}
b_object_to_string(data, b_stdout);
b_stream_write_char(b_stdout, '\n');
fx_object_to_string(data, fx_stdout);
fx_stream_write_char(fx_stdout, '\n');
b_object_unref(data);
b_object_unref(src);
b_serial_ctx_unref(ctx);
fx_object_unref(data);
fx_object_unref(src);
fx_serial_ctx_unref(ctx);
return 0;
}

View File

@@ -1,37 +1,37 @@
#include <blue/core/stream.h>
#include <blue/ds/array.h>
#include <blue/ds/dict.h>
#include <blue/ds/number.h>
#include <blue/ds/string.h>
#include <blue/serial.h>
#include <fx/core/stream.h>
#include <fx/ds/array.h>
#include <fx/ds/dict.h>
#include <fx/ds/number.h>
#include <fx/ds/string.h>
#include <fx/serial.h>
#include <stdio.h>
int main(void)
{
b_serial_ctx *ctx = b_toml_serial_ctx_create();
fx_serial_ctx *ctx = fx_toml_serial_ctx_create();
b_dict *dict = b_dict_create();
fx_dict *dict = fx_dict_create();
b_array *array = b_array_create();
b_array_append(array, B_RV_INT(32));
b_array_append(array, B_RV_INT(64));
b_array_append(array, B_RV_INT(128));
fx_array *array = fx_array_create();
fx_array_append(array, FX_RV_INT(32));
fx_array_append(array, FX_RV_INT(64));
fx_array_append(array, FX_RV_INT(128));
b_dict_put(dict, "numbers", B_RV(array));
fx_dict_put(dict, "numbers", FX_RV(array));
array = b_array_create();
b_array_append(array, B_RV_CSTR("hello"));
b_array_append(array, B_RV_CSTR("world"));
array = fx_array_create();
fx_array_append(array, FX_RV_CSTR("hello"));
fx_array_append(array, FX_RV_CSTR("world"));
b_dict_put(dict, "strings", B_RV(array));
fx_dict_put(dict, "strings", FX_RV(array));
b_object_to_string(dict, b_stdout);
b_stream_write_char(b_stdout, '\n');
fx_object_to_string(dict, fx_stdout);
fx_stream_write_char(fx_stdout, '\n');
b_serial_ctx_serialise(ctx, dict, b_stdout, 0);
fx_serial_ctx_serialise(ctx, dict, fx_stdout, 0);
b_dict_unref(dict);
b_serial_ctx_unref(ctx);
fx_dict_unref(dict);
fx_serial_ctx_unref(ctx);
return 0;
}

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;
}

View File

@@ -1,26 +1,26 @@
#include <blue/serial.h>
#include <fx/serial.h>
int main(void)
{
b_stream *src = b_stdin;
b_stream *dest = b_stdout;
fx_stream *src = fx_stdin;
fx_stream *dest = fx_stdout;
#if 0
b_serial_ctx *ctx;
b_serial_ctx_create(&ctx);
fx_serial_ctx *ctx;
fx_serial_ctx_create(&ctx);
b_object *data;
b_status status = b_serial_ctx_deserialise(
ctx, B_SERIAL_FORMAT_JSON, src, &data, 0);
if (!B_OK(status)) {
fx_object *data;
fx_status status = fx_serial_ctx_deserialise(
ctx, FX_SERIAL_FORMAT_JSON, src, &data, 0);
if (!FX_OK(status)) {
return -1;
}
b_to_string(B_OBJECT(data), dest);
b_stream_write_char(b_stdout, '\n');
fx_to_string(FX_OBJECT(data), dest);
fx_stream_write_char(fx_stdout, '\n');
b_release(data);
b_serial_ctx_destroy(ctx);
fx_release(data);
fx_serial_ctx_destroy(ctx);
#endif
return 0;

View File

@@ -1,5 +1,5 @@
#include <blue/core/error.h>
#include <blue/term/print.h>
#include <fx/core/error.h>
#include <fx/term/print.h>
#include <stdio.h>
enum sample_code {
@@ -13,25 +13,25 @@ enum sample_msg {
SAMPLE_MSG_A_TEMPLATED_MSG,
};
static const b_error_definition sample_errors[] = {
B_ERROR_DEFINITION(SAMPLE_OK, "OK", "Success"),
B_ERROR_DEFINITION(SAMPLE_ERR_IO_FAILURE, "IO_FAILURE", "I/O failure"),
B_ERROR_DEFINITION_TEMPLATE(
static const fx_error_definition sample_errors[] = {
FX_ERROR_DEFINITION(SAMPLE_OK, "OK", "Success"),
FX_ERROR_DEFINITION(SAMPLE_ERR_IO_FAILURE, "IO_FAILURE", "I/O failure"),
FX_ERROR_DEFINITION_TEMPLATE(
SAMPLE_ERR_FILE_READ_FAILED, "FILE_READ_FAILED",
"Failed to read file @i[filepath]",
B_ERROR_TEMPLATE_PARAM(
"filepath", B_ERROR_TEMPLATE_PARAM_STRING, "%s")),
FX_ERROR_TEMPLATE_PARAM(
"filepath", FX_ERROR_TEMPLATE_PARAM_STRING, "%s")),
};
static const b_error_msg sample_error_msg[] = {
B_ERROR_MSG_TEMPLATE(
static const fx_error_msg sample_error_msg[] = {
FX_ERROR_MSG_TEMPLATE(
SAMPLE_MSG_A_TEMPLATED_MSG, "A templated message: @e[param1]",
B_ERROR_TEMPLATE_PARAM(
"param1", B_ERROR_TEMPLATE_PARAM_STRING, "%s")),
FX_ERROR_TEMPLATE_PARAM(
"param1", FX_ERROR_TEMPLATE_PARAM_STRING, "%s")),
};
static const char *sample_code_to_string(
const struct b_error_vendor *vendor, b_error_status_code code)
const struct fx_error_vendor *vendor, fx_error_status_code code)
{
switch (code) {
case SAMPLE_OK:
@@ -45,7 +45,7 @@ static const char *sample_code_to_string(
}
}
static b_error_vendor sample_vendor = {
static fx_error_vendor sample_vendor = {
.v_name = "Sample",
.v_error_definitions = sample_errors,
.v_error_definitions_length = sizeof sample_errors,
@@ -53,31 +53,31 @@ static b_error_vendor sample_vendor = {
.v_msg_length = sizeof sample_error_msg,
};
static b_result error_return_3(void)
static fx_result error_return_3(void)
{
b_result err = b_error_with_string(
fx_result err = fx_error_with_string(
&sample_vendor, SAMPLE_ERR_IO_FAILURE,
"I/O failure while reading file");
b_error_add_submsg_string(
err, B_ERROR_SUBMSG_ERROR, "An @e{error} message");
b_error_add_submsg_string(
err, B_ERROR_SUBMSG_WARNING, "A @w{warning} message");
b_error_add_submsg_template(
err, B_ERROR_SUBMSG_WARNING, SAMPLE_MSG_A_TEMPLATED_MSG,
B_ERROR_PARAM("param1", "Hello!"));
fx_error_add_submsg_string(
err, FX_ERROR_SUBMSG_ERROR, "An @e{error} message");
fx_error_add_submsg_string(
err, FX_ERROR_SUBMSG_WARNING, "A @w{warning} message");
fx_error_add_submsg_template(
err, FX_ERROR_SUBMSG_WARNING, SAMPLE_MSG_A_TEMPLATED_MSG,
FX_ERROR_PARAM("param1", "Hello!"));
return err;
}
static b_result error_return_2(void)
static fx_result error_return_2(void)
{
return b_result_propagate(error_return_3());
return fx_result_propagate(error_return_3());
}
static b_result error_return_1(void)
static fx_result error_return_1(void)
{
return b_result_propagate(error_return_2());
return fx_result_propagate(error_return_2());
}
struct param {
@@ -100,39 +100,39 @@ static void __test(struct param params[])
#define test(...) __test((struct param[]) {__VA_ARGS__, {}})
static b_result some_operation(void)
static fx_result some_operation(void)
{
b_result result = error_return_2();
if (b_result_is_error(result)) {
b_result err = b_error_with_template(
fx_result result = error_return_2();
if (fx_result_is_error(result)) {
fx_result err = fx_error_with_template(
&sample_vendor, SAMPLE_ERR_FILE_READ_FAILED,
B_ERROR_PARAM("filepath", "src/Manifest.json"));
b_error_add_submsg_string(
err, B_ERROR_SUBMSG_INFO,
FX_ERROR_PARAM("filepath", "src/Manifest.json"));
fx_error_add_submsg_string(
err, FX_ERROR_SUBMSG_INFO,
"An @i{informational} message");
b_error_caused_by_b_status(result, B_ERR_IO_FAILURE);
b_result err2 = b_error_caused_by(err, result);
fx_error_caused_by_fx_status(result, FX_ERR_IO_FAILURE);
fx_result err2 = fx_error_caused_by(err, result);
return err2;
}
return B_RESULT_SUCCESS;
return FX_RESULT_SUCCESS;
}
int main(void)
{
b_set_error_report_function(b_enhanced_error_reporter, B_ERROR_REPORT_ALL);
fx_set_error_report_function(fx_enhanced_error_reporter, FX_ERROR_REPORT_ALL);
test(PARAM("Hello", 1), PARAM("Goodbye", 2));
b_result err;
if (B_CATCH(err, some_operation())) {
b_throw(err);
fx_result err;
if (FX_CATCH(err, some_operation())) {
fx_throw(err);
}
b_throw_status(B_ERR_INVALID_ARGUMENT);
b_throw_status_string(B_ERR_INVALID_ARGUMENT, "Hello!");
fx_throw_status(FX_ERR_INVALID_ARGUMENT);
fx_throw_status_string(FX_ERR_INVALID_ARGUMENT, "Hello!");
return 0;
}

View File

@@ -1,6 +1,6 @@
#include <blue/term/tty.h>
#include <blue/term/print.h>
#include <blue/ds/string.h>
#include <fx/term/tty.h>
#include <fx/term/print.h>
#include <fx/ds/string.h>
#include <stdio.h>
#define F_GREEN "[green]"
@@ -55,25 +55,25 @@ static const char *text2
int main(void)
{
const char *s = "[magenta,uline]Hello, [bright_magenta]world![reset]";
b_puts(s);
b_putc('\n');
fx_puts(s);
fx_putc('\n');
b_string *str = b_string_create_from_cstr(s);
size_t len = b_string_get_size(str, B_STRLEN_IGNORE_MOD);
fx_string *str = fx_string_create_from_cstr(s);
size_t len = fx_string_get_size(str, FX_STRLEN_IGNORE_MOD);
printf("length = %zu\n", len);
b_paragraph_format format = { 0 };
fx_paragraph_format format = { 0 };
format.p_left_margin = 5;
format.p_right_margin = 5;
format.p_flags = B_PARAGRAPH_DOUBLE_LINE_BREAK;
format.p_flags = FX_PARAGRAPH_DOUBLE_LINE_BREAK;
b_print_paragraph(text, b_stdtty, &format);
fx_print_paragraph(text, fx_stdtty, &format);
b_i("An informational message\n\nWith multiple lines");
b_warn("A warning message\nWith multiple lines");
b_err("An error message\nWith multiple lines");
fx_i("An informational message\n\nWith multiple lines");
fx_warn("A warning message\nWith multiple lines");
fx_err("An error message\nWith multiple lines");
b_printf("[red]formatting ignored: '%s'[reset]\n[dark_grey]dark text[reset]\n", "[blue]wow![reset]");
fx_printf("[red]formatting ignored: '%s'[reset]\n[dark_grey]dark text[reset]\n", "[blue]wow![reset]");
return 0;
}

View File

@@ -1,8 +1,7 @@
#include "blue/serial/toml.h"
#include <blue/io/file.h>
#include <blue/io/path.h>
#include <blue/serial.h>
#include <fx/io/file.h>
#include <fx/io/path.h>
#include <fx/serial.h>
#include <fx/serial/toml.h>
#include <stdio.h>
int main(int argc, const char **argv)
@@ -12,20 +11,20 @@ int main(int argc, const char **argv)
}
const char *path_cstr = argv[1];
b_path *path = b_path_create_from_cstr(path_cstr);
fx_path *path = fx_path_create_from_cstr(path_cstr);
b_file *src = NULL;
b_result result = b_file_open(NULL, path, B_FILE_READ_ONLY, &src);
if (b_result_is_error(result)) {
b_throw(result);
fx_file *src = NULL;
fx_result result = fx_file_open(NULL, path, FX_FILE_READ_ONLY, &src);
if (fx_result_is_error(result)) {
fx_throw(result);
return -1;
}
b_serial_ctx *ctx = b_toml_serial_ctx_create();
fx_serial_ctx *ctx = fx_toml_serial_ctx_create();
b_object *data = NULL;
b_status status = b_serial_ctx_deserialise(ctx, src, &data, 0);
if (!B_OK(status)) {
fx_object *data = NULL;
fx_status status = fx_serial_ctx_deserialise(ctx, src, &data, 0);
if (!FX_OK(status)) {
fprintf(stderr, "cannot read data\n");
return -1;
}
@@ -34,12 +33,12 @@ int main(int argc, const char **argv)
return 0;
}
b_object_to_string(data, b_stdout);
b_stream_write_char(b_stdout, '\n');
fx_object_to_string(data, fx_stdout);
fx_stream_write_char(fx_stdout, '\n');
b_object_unref(data);
b_object_unref(src);
b_serial_ctx_unref(ctx);
fx_object_unref(data);
fx_object_unref(src);
fx_serial_ctx_unref(ctx);
return 0;
}