summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke T. Shumaker <lukeshu@lukeshu.com>2025-04-02 17:28:53 -0600
committerLuke T. Shumaker <lukeshu@lukeshu.com>2025-04-02 20:44:53 -0600
commit46c24939e2e0f41f0719289cd3b491367cf3355e (patch)
treec31676d0abc4a56a16791f5b3bbccbdc48b7bc00
parentf41d9a88c07226d107b56873bdbc801e484b524e (diff)
lib9p: Add lo_box_lib9p_msg_as_fmt_formatter() to tables
-rw-r--r--lib9p/9p.generated.c11
-rw-r--r--lib9p/include/lib9p/9p.h2
-rw-r--r--lib9p/protogen/c.py7
-rw-r--r--lib9p/tables.c8
-rw-r--r--lib9p/tables.h4
5 files changed, 26 insertions, 6 deletions
diff --git a/lib9p/9p.generated.c b/lib9p/9p.generated.c
index d1a632b..b58a485 100644
--- a/lib9p/9p.generated.c
+++ b/lib9p/9p.generated.c
@@ -4870,9 +4870,9 @@ static void lib9p_dm_format(lib9p_dm_t *self, struct fmt_state *state) {
fmt_state_puts(state, "OTHER_X");
empty = false;
}
- if (!empty)
- fmt_state_putchar(state, '|');
- fmt_state_printf(state, "%#04"PRIo32, *self & 0777);
+ if (!empty)
+ fmt_state_putchar(state, '|');
+ fmt_state_printf(state, "%#04"PRIo32, *self & 0777);
fmt_state_putchar(state, ')');
}
@@ -7358,7 +7358,10 @@ const struct _lib9p_ver_tentry _lib9p_table_ver[LIB9P_VER_NUM] = {
#endif /* CONFIG_9P_ENABLE_9P2000_u */
};
-#define _MSG(typ) [LIB9P_TYP_##typ] = {.name=#typ}
+#define _MSG(typ) [LIB9P_TYP_##typ] = { \
+ .name = #typ, \
+ .box_as_fmt_formatter = (_box_as_fmt_formatter_fn_t)lo_box_lib9p_msg_##typ##_as_fmt_formatter, \
+ }
const struct _lib9p_msg_tentry _lib9p_table_msg[LIB9P_VER_NUM][0x100] = {
[LIB9P_VER_unknown] = {
_MSG(Tversion),
diff --git a/lib9p/include/lib9p/9p.h b/lib9p/include/lib9p/9p.h
index 4cdb997..5919260 100644
--- a/lib9p/include/lib9p/9p.h
+++ b/lib9p/include/lib9p/9p.h
@@ -65,6 +65,8 @@ int lib9p_errorf(struct lib9p_ctx *ctx, lib9p_errno_t linux_errno, char const *f
uint32_t lib9p_version_min_msg_size(enum lib9p_version);
+lo_interface fmt_formatter lo_box_lib9p_msg_as_fmt_formatter(struct lib9p_ctx *ctx, enum lib9p_msg_type typ, void *body);
+
/* main T-message functions ***************************************************/
/**
diff --git a/lib9p/protogen/c.py b/lib9p/protogen/c.py
index 722db7f..a6824ce 100644
--- a/lib9p/protogen/c.py
+++ b/lib9p/protogen/c.py
@@ -156,7 +156,12 @@ def gen_c(versions: set[str], typs: list[idl.UserType]) -> str:
return ret
ret += "\n"
- ret += f"#define _MSG(typ) [{c9util.Ident('TYP_')}##typ] = {{.name=#typ}}\n"
+ ret += cutil.macro(
+ f"#define _MSG(typ) [{c9util.Ident('TYP_')}##typ] = {{\n"
+ f"\t\t.name = #typ,\n"
+ f"\t\t.box_as_fmt_formatter = (_box_as_fmt_formatter_fn_t)lo_box_{c9util.ident('msg_')}##typ##_as_fmt_formatter,\n"
+ f"\t}}\n"
+ )
ret += msg_table("_msg_tentry", "_table_msg", "_MSG", (0, 0x100, 1))
ret += "\n"
diff --git a/lib9p/tables.c b/lib9p/tables.c
index 36fe3b3..271b17b 100644
--- a/lib9p/tables.c
+++ b/lib9p/tables.c
@@ -45,6 +45,14 @@ const char *lib9p_msgtype_str(enum lib9p_version ver, enum lib9p_msg_type typ) {
return _lib9p_table_msg[ver][typ].name ?: const_byte_str(typ);
}
+lo_interface fmt_formatter lo_box_lib9p_msg_as_fmt_formatter(struct lib9p_ctx *ctx, enum lib9p_msg_type typ, void *body) {
+ assert(ctx);
+ assert_ver(ctx->version);
+ assert_typ(typ);
+ assert(_lib9p_table_msg[ctx->version][typ].box_as_fmt_formatter);
+ return _lib9p_table_msg[ctx->version][typ].box_as_fmt_formatter(body);
+}
+
/* main message functions *****************************************************/
static
diff --git a/lib9p/tables.h b/lib9p/tables.h
index 0b642eb..edb402a 100644
--- a/lib9p/tables.h
+++ b/lib9p/tables.h
@@ -20,8 +20,10 @@ extern const struct _lib9p_ver_tentry _lib9p_table_ver[LIB9P_VER_NUM];
/* message ********************************************************************/
+typedef lo_interface fmt_formatter (*_box_as_fmt_formatter_fn_t)(void *host_val);
struct _lib9p_msg_tentry {
- const char *name;
+ const char *name;
+ _box_as_fmt_formatter_fn_t box_as_fmt_formatter;
};
typedef ssize_t (*_validate_fn_t)(struct lib9p_ctx *ctx, uint32_t net_size, uint8_t *net_bytes);