meta: replace bluelib with fx

This commit is contained in:
2026-06-22 17:45:54 +01:00
parent 4190a5c54a
commit c6c4b0c1f9
81 changed files with 3933 additions and 1349 deletions
+70 -69
View File
@@ -1,8 +1,8 @@
#include "pkg-expr.h"
#include <blue/core/error.h>
#include <blue/object/string.h>
#include <ctype.h>
#include <fx/error.h>
#include <fx/string.h>
#include <stdlib.h>
#include <string.h>
@@ -22,52 +22,52 @@ enum parse_state {
struct parse_ctx {
const char *ctx_str;
b_string *ctx_temp;
fx_string *ctx_temp;
enum parse_state ctx_state;
size_t ctx_i;
b_queue ctx_stack, ctx_queue;
fx_queue ctx_stack, ctx_queue;
};
static struct ropkg_pkg_expr *parse_ctx_peek_stack(struct parse_ctx *ctx)
{
b_queue_entry *entry = b_queue_last(&ctx->ctx_stack);
fx_queue_entry *entry = fx_queue_last(&ctx->ctx_stack);
if (!entry) {
return NULL;
}
return b_unbox(struct ropkg_pkg_expr, entry, expr_entry);
return fx_unbox(struct ropkg_pkg_expr, entry, expr_entry);
}
static struct ropkg_pkg_expr *parse_ctx_pop(struct parse_ctx *ctx)
{
b_queue_entry *entry = b_queue_pop_back(&ctx->ctx_stack);
fx_queue_entry *entry = fx_queue_pop_back(&ctx->ctx_stack);
if (!entry) {
return NULL;
}
return b_unbox(struct ropkg_pkg_expr, entry, expr_entry);
return fx_unbox(struct ropkg_pkg_expr, entry, expr_entry);
}
static void parse_ctx_push(struct parse_ctx *ctx, struct ropkg_pkg_expr *expr)
{
b_queue_push_back(&ctx->ctx_stack, &expr->expr_entry);
fx_queue_push_back(&ctx->ctx_stack, &expr->expr_entry);
}
static struct ropkg_pkg_expr *parse_ctx_dequeue(struct parse_ctx *ctx)
{
b_queue_entry *entry = b_queue_pop_front(&ctx->ctx_queue);
fx_queue_entry *entry = fx_queue_pop_front(&ctx->ctx_queue);
if (!entry) {
return NULL;
}
return b_unbox(struct ropkg_pkg_expr, entry, expr_entry);
return fx_unbox(struct ropkg_pkg_expr, entry, expr_entry);
}
static void parse_ctx_enqueue(
struct parse_ctx *ctx,
struct ropkg_pkg_expr *expr)
{
b_queue_push_back(&ctx->ctx_queue, &expr->expr_entry);
fx_queue_push_back(&ctx->ctx_queue, &expr->expr_entry);
}
static char parse_ctx_peek(struct parse_ctx *ctx)
@@ -99,7 +99,7 @@ static char parse_ctx_advance(struct parse_ctx *ctx)
static void parse_ctx_cleanup(struct parse_ctx *ctx)
{
if (ctx->ctx_temp) {
b_string_release(ctx->ctx_temp);
fx_string_unref(ctx->ctx_temp);
}
struct ropkg_pkg_expr *expr = parse_ctx_dequeue(ctx);
@@ -122,16 +122,16 @@ enum ropkg_status ropkg_pkg_expr_create(struct ropkg_pkg_expr **out)
void ropkg_pkg_expr_destroy(struct ropkg_pkg_expr *expr)
{
b_queue q = B_QUEUE_INIT;
b_queue_push_back(&q, &expr->expr_entry);
fx_queue q = FX_QUEUE_INIT;
fx_queue_push_back(&q, &expr->expr_entry);
while (1) {
b_queue_entry *entry = b_queue_pop_front(&q);
fx_queue_entry *entry = fx_queue_pop_front(&q);
if (!entry) {
break;
}
expr = b_unbox(struct ropkg_pkg_expr, entry, expr_entry);
expr = fx_unbox(struct ropkg_pkg_expr, entry, expr_entry);
switch (expr->expr_type) {
case ROPKG_PKG_EXPR_NODE_PKG: {
@@ -150,13 +150,13 @@ void ropkg_pkg_expr_destroy(struct ropkg_pkg_expr *expr)
struct ropkg_pkg_expr_and *and_node
= (struct ropkg_pkg_expr_and *)expr;
if (and_node->and_left) {
b_queue_push_back(
fx_queue_push_back(
&q,
&and_node->and_left->expr_entry);
}
if (and_node->and_right) {
b_queue_push_back(
fx_queue_push_back(
&q,
&and_node->and_right->expr_entry);
}
@@ -166,13 +166,13 @@ void ropkg_pkg_expr_destroy(struct ropkg_pkg_expr *expr)
struct ropkg_pkg_expr_or *or_node
= (struct ropkg_pkg_expr_or *)expr;
if (or_node->or_left) {
b_queue_push_back(
fx_queue_push_back(
&q,
&or_node->or_left->expr_entry);
}
if (or_node->or_right) {
b_queue_push_back(
fx_queue_push_back(
&q,
&or_node->or_right->expr_entry);
}
@@ -187,11 +187,11 @@ void ropkg_pkg_expr_destroy(struct ropkg_pkg_expr *expr)
}
}
static b_result parse_pkg_name(
static fx_result parse_pkg_name(
struct parse_ctx *ctx,
struct ropkg_pkg_expr_pkg *pkg)
{
b_string_clear(ctx->ctx_temp);
fx_string_clear(ctx->ctx_temp);
while (1) {
char c = parse_ctx_peek(ctx);
@@ -200,19 +200,19 @@ static b_result parse_pkg_name(
}
char s[] = {c, 0};
b_string_append_cstr(ctx->ctx_temp, s);
fx_string_append_cstr(ctx->ctx_temp, s);
parse_ctx_advance(ctx);
}
pkg->pkg_name = b_string_steal(ctx->ctx_temp);
return B_RESULT_SUCCESS;
pkg->pkg_name = fx_string_steal(ctx->ctx_temp);
return FX_RESULT_SUCCESS;
}
static b_result parse_pkg_version_predicate(
static fx_result parse_pkg_version_predicate(
struct parse_ctx *ctx,
struct ropkg_pkg_expr_pkg *pkg)
{
b_string_clear(ctx->ctx_temp);
fx_string_clear(ctx->ctx_temp);
while (1) {
char c = parse_ctx_peek(ctx);
@@ -221,11 +221,11 @@ static b_result parse_pkg_version_predicate(
}
char s[] = {c, 0};
b_string_append_cstr(ctx->ctx_temp, s);
fx_string_append_cstr(ctx->ctx_temp, s);
parse_ctx_advance(ctx);
}
const char *pred = b_string_ptr(ctx->ctx_temp);
const char *pred = fx_string_get_cstr(ctx->ctx_temp);
if (!strcmp(pred, ">=")) {
pkg->pkg_version_predicate = ROPKG_OP_GREATER_EQUAL;
} else if (!strcmp(pred, ">")) {
@@ -237,19 +237,19 @@ static b_result parse_pkg_version_predicate(
} else if (!strcmp(pred, "==") || !strcmp(pred, "=")) {
pkg->pkg_version_predicate = ROPKG_OP_EQUAL;
} else {
return b_error_with_code(
return fx_error_with_code(
ROPKG_ERROR_VENDOR,
ROPKG_ERR_INVALID_PKG_EXPR);
}
return B_RESULT_SUCCESS;
return FX_RESULT_SUCCESS;
}
static b_result parse_pkg_version_id(
static fx_result parse_pkg_version_id(
struct parse_ctx *ctx,
struct ropkg_pkg_expr_pkg *pkg)
{
b_string_clear(ctx->ctx_temp);
fx_string_clear(ctx->ctx_temp);
while (1) {
char c = parse_ctx_peek(ctx);
if (!isalnum(c) && c != '.' && c != '-' && c != '~') {
@@ -257,40 +257,41 @@ static b_result parse_pkg_version_id(
}
char s[] = {c, 0};
b_string_append_cstr(ctx->ctx_temp, s);
fx_string_append_cstr(ctx->ctx_temp, s);
parse_ctx_advance(ctx);
}
struct ropkg_version *version = NULL;
enum ropkg_status status = ropkg_version_create(&version);
if (status != ROPKG_SUCCESS) {
return b_error_with_code(ROPKG_ERROR_VENDOR, status);
return fx_error_with_code(ROPKG_ERROR_VENDOR, status);
}
b_result result
= ropkg_version_parse(version, b_string_ptr(ctx->ctx_temp));
if (b_result_is_error(result)) {
fx_result result = ropkg_version_parse(
version,
fx_string_get_cstr(ctx->ctx_temp));
if (fx_result_is_error(result)) {
ropkg_version_destroy(version);
version = NULL;
}
pkg->pkg_version = version;
return b_result_propagate(result);
return fx_result_propagate(result);
}
static b_result parse_pkg_version(
static fx_result parse_pkg_version(
struct parse_ctx *ctx,
struct ropkg_pkg_expr_pkg *pkg)
{
parse_ctx_advance(ctx);
b_result result = B_RESULT_SUCCESS;
fx_result result = FX_RESULT_SUCCESS;
char c = parse_ctx_peek(ctx);
if (c == '>' || c == '<' || c == '=') {
result = parse_pkg_version_predicate(ctx, pkg);
}
if (b_result_is_error(result)) {
if (fx_result_is_error(result)) {
return result;
}
@@ -299,7 +300,7 @@ static b_result parse_pkg_version(
if (isalnum(c)) {
result = parse_pkg_version_id(ctx, pkg);
} else {
result = b_error_with_code(
result = fx_error_with_code(
ROPKG_ERROR_VENDOR,
ROPKG_ERR_INVALID_PKG_EXPR);
}
@@ -308,7 +309,7 @@ static b_result parse_pkg_version(
if (c == ')') {
parse_ctx_advance(ctx);
} else {
result = b_error_with_code(
result = fx_error_with_code(
ROPKG_ERROR_VENDOR,
ROPKG_ERR_INVALID_PKG_EXPR);
}
@@ -316,19 +317,19 @@ static b_result parse_pkg_version(
return result;
}
static b_result parse_pkg(struct parse_ctx *ctx)
static fx_result parse_pkg(struct parse_ctx *ctx)
{
struct ropkg_pkg_expr_pkg *pkg = ropkg_pkg_expr_pkg_create();
b_result result = B_RESULT_SUCCESS;
fx_result result = FX_RESULT_SUCCESS;
char c = parse_ctx_peek(ctx);
if (isalpha(c)) {
result = parse_pkg_name(ctx, pkg);
}
if (b_result_is_error(result)) {
if (fx_result_is_error(result)) {
ropkg_pkg_expr_destroy((struct ropkg_pkg_expr *)pkg);
return b_result_propagate(result);
return fx_result_propagate(result);
}
c = parse_ctx_peek(ctx);
@@ -336,9 +337,9 @@ static b_result parse_pkg(struct parse_ctx *ctx)
result = parse_pkg_version(ctx, pkg);
}
if (b_result_is_error(result)) {
if (fx_result_is_error(result)) {
ropkg_pkg_expr_destroy((struct ropkg_pkg_expr *)pkg);
return b_result_propagate(result);
return fx_result_propagate(result);
}
parse_ctx_enqueue(ctx, &pkg->pkg_base);
@@ -346,7 +347,7 @@ static b_result parse_pkg(struct parse_ctx *ctx)
return result;
}
static b_result parse_and(struct parse_ctx *ctx)
static fx_result parse_and(struct parse_ctx *ctx)
{
parse_ctx_advance(ctx);
@@ -371,10 +372,10 @@ static b_result parse_and(struct parse_ctx *ctx)
}
parse_ctx_push(ctx, &and_node->and_base);
return B_RESULT_SUCCESS;
return FX_RESULT_SUCCESS;
}
static b_result parse_or(struct parse_ctx *ctx)
static fx_result parse_or(struct parse_ctx *ctx)
{
parse_ctx_advance(ctx);
@@ -395,16 +396,16 @@ static b_result parse_or(struct parse_ctx *ctx)
}
parse_ctx_push(ctx, &or_node->or_base);
return B_RESULT_SUCCESS;
return FX_RESULT_SUCCESS;
}
static b_result parse_group_start(struct parse_ctx *ctx)
static fx_result parse_group_start(struct parse_ctx *ctx)
{
parse_ctx_advance(ctx);
struct ropkg_pkg_expr *group_node = malloc(sizeof *group_node);
if (!group_node) {
return b_error_with_code(
return fx_error_with_code(
ROPKG_ERROR_VENDOR,
ROPKG_ERR_NO_MEMORY);
}
@@ -414,10 +415,10 @@ static b_result parse_group_start(struct parse_ctx *ctx)
group_node->expr_type = ROPKG_PKG_EXPR_NODE_GROUP;
parse_ctx_push(ctx, group_node);
return B_RESULT_SUCCESS;
return FX_RESULT_SUCCESS;
}
static b_result parse_group_end(struct parse_ctx *ctx)
static fx_result parse_group_end(struct parse_ctx *ctx)
{
parse_ctx_advance(ctx);
@@ -427,7 +428,7 @@ static b_result parse_group_end(struct parse_ctx *ctx)
struct ropkg_pkg_expr *expr = parse_ctx_pop(ctx);
if (!expr) {
return b_error_with_code(
return fx_error_with_code(
ROPKG_ERROR_VENDOR,
ROPKG_ERR_INVALID_PKG_EXPR);
}
@@ -443,10 +444,10 @@ static b_result parse_group_end(struct parse_ctx *ctx)
}
}
return B_RESULT_SUCCESS;
return FX_RESULT_SUCCESS;
}
b_result ropkg_pkg_expr_parse(const char *s, struct ropkg_pkg_expr **out)
fx_result ropkg_pkg_expr_parse(const char *s, struct ropkg_pkg_expr **out)
{
while (isspace(*s)) {
s++;
@@ -454,12 +455,12 @@ b_result ropkg_pkg_expr_parse(const char *s, struct ropkg_pkg_expr **out)
struct parse_ctx ctx = {
.ctx_str = s,
.ctx_temp = b_string_create(),
.ctx_temp = fx_string_create(),
};
b_result result = B_RESULT_SUCCESS;
fx_result result = FX_RESULT_SUCCESS;
while (!b_result_is_error(result)) {
while (!fx_result_is_error(result)) {
char c = parse_ctx_peek(&ctx);
if (c == 0) {
break;
@@ -476,14 +477,14 @@ b_result ropkg_pkg_expr_parse(const char *s, struct ropkg_pkg_expr **out)
} else if (isalpha(c)) {
result = parse_pkg(&ctx);
} else {
result = b_error_with_code(
result = fx_error_with_code(
ROPKG_ERROR_VENDOR,
ROPKG_ERR_INVALID_PKG_EXPR);
break;
}
}
if (b_result_is_error(result)) {
if (fx_result_is_error(result)) {
parse_ctx_cleanup(&ctx);
return result;
}
@@ -507,7 +508,7 @@ b_result ropkg_pkg_expr_parse(const char *s, struct ropkg_pkg_expr **out)
if (expr->expr_type == ROPKG_PKG_EXPR_NODE_GROUP) {
parse_ctx_cleanup(&ctx);
return b_error_with_code(
return fx_error_with_code(
ROPKG_ERROR_VENDOR,
ROPKG_ERR_INVALID_PKG_EXPR);
}
@@ -517,7 +518,7 @@ b_result ropkg_pkg_expr_parse(const char *s, struct ropkg_pkg_expr **out)
left = parse_ctx_pop(&ctx);
if (!left || !right) {
parse_ctx_cleanup(&ctx);
return b_error_with_code(
return fx_error_with_code(
ROPKG_ERROR_VENDOR,
ROPKG_ERR_INVALID_PKG_EXPR);
}