common: update bluelib api usage

This commit is contained in:
2025-11-06 10:38:23 +00:00
parent faa9200bb1
commit b26c37c349
5 changed files with 47 additions and 42 deletions

View File

@@ -12,4 +12,4 @@ endif ()
target_include_directories(ivy-common PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include/)
target_compile_definitions(ivy-common PRIVATE IVY_EXPORT=1 IVY_STATIC=${IVY_STATIC})
target_link_libraries(ivy-common Bluelib::Core Bluelib::Object)
target_link_libraries(ivy-common Bluelib::Core Bluelib::Ds)

View File

@@ -1,5 +1,5 @@
#include <blue/object/array.h>
#include <blue/object/string.h>
#include <blue/ds/array.h>
#include <blue/ds/string.h>
#include <errno.h>
#include <ivy/file.h>
#include <stdlib.h>
@@ -24,7 +24,7 @@ static enum ivy_status get_row(
return IVY_ERR_EOF;
}
b_string *line = B_STRING(b_array_at(f->f_lines, row - 1));
b_string *line = b_array_at(f->f_lines, row - 1);
const char *line_str = b_string_ptr(line);
size_t line_len = b_string_get_size(line, B_STRLEN_NORMAL);
@@ -54,7 +54,7 @@ static enum ivy_status readline(
b_string *line_str = b_string_create_from_cstr(buf);
b_array_append(f->f_lines, B_OBJECT(line_str));
b_string_release(line_str);
b_string_unref(line_str);
*nr_read = strlen(buf);
return IVY_OK;
@@ -89,7 +89,7 @@ enum ivy_status ivy_file_open(const char *path, struct ivy_file **out)
void ivy_file_close(struct ivy_file *file)
{
b_array_release(file->f_lines);
b_array_unref(file->f_lines);
free(file->f_path);
fclose(file->f_fp);
free(file);

View File

@@ -1,6 +1,6 @@
#include <blue/core/queue.h>
#include <blue/core/stringstream.h>
#include <blue/object/string.h>
#include <blue/ds/string.h>
#include <ivy/ident.h>
#include <stdlib.h>
#include <string.h>
@@ -20,16 +20,17 @@ struct ivy_ident *ivy_ident_create(void)
void ivy_ident_destroy(struct ivy_ident *ident)
{
b_queue_iterator it = {0};
b_queue_iterator_begin(&ident->id_parts, &it);
while (b_queue_iterator_is_valid(&it)) {
b_queue_entry *entry = b_queue_first(&ident->id_parts);
while (entry) {
struct ivy_ident_part *part
= b_unbox(struct ivy_ident_part, it.entry, p_entry);
b_queue_iterator_erase(&it);
= b_unbox(struct ivy_ident_part, entry, p_entry);
b_queue_entry *next = b_queue_next(entry);
b_queue_delete(&ident->id_parts, entry);
free(part->p_str);
free(part);
entry = next;
}
free(ident);
@@ -51,19 +52,18 @@ void ivy_ident_add_part(struct ivy_ident *ident, const char *s)
size_t ivy_ident_to_string(const struct ivy_ident *ident, char *out, size_t max)
{
b_stringstream strv;
b_stringstream_begin(&strv, out, max);
b_stringstream *strv = b_stringstream_create_with_buffer(out, max);
int i = 0;
b_queue_iterator it = {0};
b_queue_foreach (&it, &ident->id_parts) {
b_queue_entry *entry = b_queue_first(&ident->id_parts);
while (entry) {
if (i > 0) {
b_stringstream_add(&strv, ".");
b_stream_write_char(strv, '.');
}
struct ivy_ident_part *part
= b_unbox(struct ivy_ident_part, it.entry, p_entry);
b_stringstream_add(&strv, part->p_str);
= b_unbox(struct ivy_ident_part, entry, p_entry);
b_stream_write_string(strv, part->p_str, NULL);
i++;
}

View File

@@ -1,15 +1,14 @@
#ifndef IVY_COMMON_FILE_H_
#define IVY_COMMON_FILE_H_
#include <blue/ds/array.h>
#include <ivy/line-source.h>
#include <ivy/misc.h>
#include <stdio.h>
struct b_array;
struct ivy_file {
struct ivy_line_source f_base;
struct b_array *f_lines;
b_array *f_lines;
char *f_path;
FILE *f_fp;
};

View File

@@ -1,6 +1,6 @@
#include <blue/core/queue.h>
#include <blue/core/stringstream.h>
#include <blue/object/string.h>
#include <blue/ds/string.h>
#include <ivy/selector.h>
#include <stdlib.h>
#include <string.h>
@@ -25,12 +25,12 @@ void ivy_selector_destroy(struct ivy_selector *sel)
free(sel->sel_name);
}
b_queue_iterator it = {0};
b_queue_iterator_begin(&sel->sel_args, &it);
while (b_queue_iterator_is_valid(&it)) {
b_queue_entry *entry = b_queue_first(&sel->sel_args);
while (entry) {
struct ivy_selector_arg *arg
= b_unbox(struct ivy_selector_arg, it.entry, arg_entry);
b_queue_iterator_erase(&it);
= b_unbox(struct ivy_selector_arg, entry, arg_entry);
b_queue_entry *next = b_queue_next(entry);
b_queue_delete(&sel->sel_args, entry);
if (arg->arg_label) {
free(arg->arg_label);
@@ -41,6 +41,8 @@ void ivy_selector_destroy(struct ivy_selector *sel)
}
free(arg);
entry = next;
}
free(sel);
@@ -93,39 +95,43 @@ enum ivy_status ivy_selector_add_arg(
size_t ivy_selector_to_string(const struct ivy_selector *sel, char *out, size_t max)
{
b_stringstream str;
b_stringstream_begin(&str, out, max);
b_stringstream *str = b_stringstream_create_with_buffer(out, max);
switch (sel->sel_recipient) {
case IVY_SEL_OBJECT:
b_stringstream_add(&str, "-");
b_stream_write_char(str, '-');
break;
case IVY_SEL_CLASS:
b_stringstream_add(&str, "+");
b_stream_write_char(str, '+');
break;
default:
break;
}
if (sel->sel_name) {
b_stringstream_add(&str, sel->sel_name);
b_stream_write_string(str, sel->sel_name, NULL);
}
if (sel->sel_name && !b_queue_empty(&sel->sel_args)) {
b_stringstream_add(&str, "(");
b_stream_write_char(str, '(');
}
b_queue_iterator it;
b_queue_foreach (&it, &sel->sel_args) {
b_queue_entry *entry = b_queue_first(&sel->sel_args);
while (entry) {
struct ivy_selector_arg *arg
= b_unbox(struct ivy_selector_arg, it.entry, arg_entry);
b_stringstream_addf(
&str, "%s:", arg->arg_label ? arg->arg_label : "_");
= b_unbox(struct ivy_selector_arg, entry, arg_entry);
b_stream_write_fmt(
str, NULL, "%s:", arg->arg_label ? arg->arg_label : "_");
entry = b_queue_next(entry);
}
if (sel->sel_name && !b_queue_empty(&sel->sel_args)) {
b_stringstream_add(&str, ")");
b_stream_write_char(str, ')');
}
return b_stringstream_get_length(&str);
size_t len = b_stringstream_get_length(str);
b_stringstream_unref(str);
return len;
}