Merge branch 'main' into feature/new-object-system
This commit is contained in:
1
test/test.toml
Normal file
1
test/test.toml
Normal file
@@ -0,0 +1 @@
|
||||
tab = 32
|
||||
48
test/toml-read.c
Normal file
48
test/toml-read.c
Normal file
@@ -0,0 +1,48 @@
|
||||
#include <blue/io/file.h>
|
||||
#include <blue/io/path.h>
|
||||
#include <blue/serial.h>
|
||||
#include <stdio.h>
|
||||
|
||||
int main(int argc, const char **argv)
|
||||
{
|
||||
if (argc < 2) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
const char *path_cstr = argv[1];
|
||||
b_path *path = b_path_create_from_cstr(path_cstr);
|
||||
|
||||
b_file *file = NULL;
|
||||
b_result result = b_file_open(NULL, path, B_FILE_READ_ONLY, &file);
|
||||
if (b_result_is_error(result)) {
|
||||
b_throw(result);
|
||||
return -1;
|
||||
}
|
||||
|
||||
b_stream *src_stream;
|
||||
|
||||
b_file_open_stream(file, &src_stream);
|
||||
|
||||
b_serial_ctx *ctx;
|
||||
b_serial_ctx_create(&ctx);
|
||||
|
||||
b_dsref *data = NULL;
|
||||
b_status status = b_serial_ctx_deserialise(
|
||||
ctx, B_SERIAL_FORMAT_TOML, src_stream, &data, 0);
|
||||
if (!B_OK(status)) {
|
||||
fprintf(stderr, "cannot read data\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!data) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
b_to_string(B_DSREF(data), b_stdout);
|
||||
b_stream_write_char(b_stdout, '\n');
|
||||
|
||||
b_release(data);
|
||||
b_serial_ctx_destroy(ctx);
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user