aboutsummaryrefslogtreecommitdiffstats
path: root/main.c
diff options
context:
space:
mode:
authorLibravatar bigfoot547 <[email protected]>2025-11-16 20:52:57 -0600
committerLibravatar bigfoot547 <[email protected]>2025-11-16 20:52:57 -0600
commitd026e93405655129e46debfca2124ee132e9b134 (patch)
tree8adf037dd69c4226ef9a5d2a3dd8fa63eb783761 /main.c
parent[wip] plugin stuff (diff)
build config + more plugin stuff
Diffstat (limited to 'main.c')
-rw-r--r--main.c140
1 files changed, 0 insertions, 140 deletions
diff --git a/main.c b/main.c
deleted file mode 100644
index 273d797..0000000
--- a/main.c
+++ /dev/null
@@ -1,140 +0,0 @@
-#include <stdio.h>
-#include <stdbool.h>
-#include <stdint.h>
-#include <stdarg.h>
-#include <dlfcn.h>
-
-#include "pipeline.h"
-
-#define UNUSED(_v) ((void)(_v))
-
-PIPELINE_STAGE static int identity_stage_handle(const ptx_pipeline_ctx_t *ctx, const void *data, size_t sz)
-{
- return ptx_pipeline_ctx_next(ctx, data, sz);
-}
-
-PIPELINE_INIT static int debug_stage_init(const char *name, void **ppuser, va_list init_args)
-{
- static const char *const messages[] = { "no continue :(", "continue :)" };
-
- UNUSED(name);
-
- int config = !!va_arg(init_args, int);
- *ppuser = (void *)(uintptr_t)config;
-
- printf("Debug stage %s (init): %s\n", name, messages[config]);
-
- return 0;
-}
-
-PIPELINE_CLEANUP static void debug_stage_cleanup(const char *name, void *puser)
-{
- printf("Debug stage %s (cleanup): %p\n", name, puser);
-}
-
-PIPELINE_STAGE static int debug_stage_handle(const ptx_pipeline_ctx_t *ctx, const void *data, size_t sz)
-{
- bool cont = !!(uintptr_t)(*ptx_pipeline_ctx_get_user(ctx));
- printf("Debug stage %s:\n Data: %p\n Size: %zu\n", ptx_pipeline_ctx_get_name(ctx), data, sz);
- return cont ? ptx_pipeline_ctx_next(ctx, data, sz) : 0;
-}
-
-static const struct ptx_pipeline_stage_funcs identity_stage = {
- .init = NULL,
- .handler = &identity_stage_handle,
- .cleanup = NULL
-};
-
-static const struct ptx_pipeline_stage_funcs debug_stage = {
- .init = &debug_stage_init,
- .handler = &debug_stage_handle,
- .cleanup = &debug_stage_cleanup
-};
-
-/* mockup:
- * Pipeline signature: D -> D*1
- * int simple_1to1_stage(struct pipeline_ctx *ctx, void *data, size_t len) {
- * void *out = ... transform data ...;
- * size_t out_len = ^^^;
- * return ptx_pipeline_next(ctx, out, out_len);
- * }
- *
- * Pipeline signature: D -> D*(0,n)
- * int complex_1tomany_stage(struct pipeline_ctx *ctx, void *data, size_t len) {
- * int err;
- * for (void *out; has_data(data, len); out = next_data(data, &len)) {
- * if (!out) {
- * return -1; ... next_data failed somehow ...
- * }
- *
- * if ((err = ptx_pipeline_next(ctx, out, out_len)) < 0) {
- * return err;
- * }
- * }
- * return 0;
- * }
- *
- * Pipeline signature: D -> D*1
- * int stateful_stage(struct pipeline_ctx *ctx, void *data, size_t len) {
- * my_stage_t *stg = ctx->me;
- * stg->stat_in += len;
- * return ptx_pipeline_next(ctx, data, len);
- * }
- *
- * Pipeline signature: D -> void (i.e., never calls next)
- * int terminal_stage(struct pipeline_ctx *ctx, void *data, size_t len) {
- * my_handler_t *handler = ctx->me;
- * handler->do_handle(data, len);
- * return 0; ... return values should indicate pipeline (i.e., parsing) errors, not application errors ...
- * }
- */
-
-int main(void) {
- ptx_pipeline_t *pl = ptx_pipeline_new(1);
- if (!pl) {
- fputs("Allocation failure: pipeline\n", stderr);
- return 1;
- }
-
- if (ptx_pipeline_add_before(pl, &identity_stage, "identity1", NULL) < 0) {
- fputs("Failed to add identity1 to pipeline\n", stderr);
- return 1;
- }
-
- if (ptx_pipeline_add_after(pl, &debug_stage, "debug1", "identity1", true) < 0) {
- fputs("Failed to add debug1 to pipeline\n", stderr);
- return 1;
- }
-
- if (ptx_pipeline_add_after(pl, &debug_stage, "debug2", "debug1", false) < 0) {
- fputs("Failed to add debug2 to pipeline\n", stderr);
- return 1;
- }
-
- printf("Handle returned: %d\n", ptx_pipeline_handle(pl, "sussy", 10));
-
- if (ptx_pipeline_remove_stage(pl, "debug1") < 1) {
- fputs("Failed to remove debug1 from pipeline\n", stderr);
- return 1;
- }
-
- printf("Handle returned: %d\n", ptx_pipeline_handle(pl, "sussy2", 20));
-
- ptx_pipeline_free(pl);
-
- void *mod;
- if (!(mod = dlopen("plugins/libm_skibidi.so", RTLD_LAZY | RTLD_LOCAL))) {
- printf("dlopen: %s\n", dlerror());
- return 1;
- }
-
- int (*f)(void) = dlsym(mod, "do_something");
- if (!f) {
- printf("dlsym: %s\n", dlerror());
- return 1;
- }
-
- printf("f: %d\n", f());
-
- return 0;
-}