aboutsummaryrefslogtreecommitdiffstats
path: root/libterminput_unmarshal_input.c
diff options
context:
space:
mode:
authorMattias Andrée <m@maandree.se>2025-02-20 20:24:28 +0100
committerMattias Andrée <m@maandree.se>2025-02-20 20:24:28 +0100
commit4c745dab4c6925fa17714c2214ed5941e5cbf64d (patch)
tree30129b2838d7a27a7a37fd37f5f95d6b355b7203 /libterminput_unmarshal_input.c
parentAdd state marshalling and unmarshalling functions (diff)
downloadlibterminput-4c745dab4c6925fa17714c2214ed5941e5cbf64d.tar.gz
libterminput-4c745dab4c6925fa17714c2214ed5941e5cbf64d.tar.bz2
libterminput-4c745dab4c6925fa17714c2214ed5941e5cbf64d.tar.xz
Validate unmarshalled state + add man pages for (un)marshal functions
Signed-off-by: Mattias Andrée <m@maandree.se>
Diffstat (limited to '')
-rw-r--r--libterminput_unmarshal_input.c24
1 files changed, 19 insertions, 5 deletions
diff --git a/libterminput_unmarshal_input.c b/libterminput_unmarshal_input.c
index ef8606c..851d0be 100644
--- a/libterminput_unmarshal_input.c
+++ b/libterminput_unmarshal_input.c
@@ -15,16 +15,30 @@ libterminput_unmarshal_input(struct libterminput_unmarshaller *how, union libter
if (how->load(how, &what->type, sizeof(what->type)))
return -1;
}
- if (what->type == LIBTERMINPUT_KEYPRESS)
+ switch ((int)what->type) {
+ case LIBTERMINPUT_KEYPRESS:
r = libterminput_unmarshal_keypress__(how, &what->keypress);
- else if (what->type == LIBTERMINPUT_TEXT)
+ break;
+ case LIBTERMINPUT_TEXT:
r = libterminput_unmarshal_text__(how, &what->text);
- else if (what->type == LIBTERMINPUT_MOUSEEVENT)
+ break;
+ case LIBTERMINPUT_MOUSEEVENT:
r = libterminput_unmarshal_mouseevent__(how, &what->mouseevent);
- else if (what->type == LIBTERMINPUT_CURSOR_POSITION)
+ break;
+ case LIBTERMINPUT_CURSOR_POSITION:
r = libterminput_unmarshal_position__(how, &what->position);
- else
+ break;
+ case LIBTERMINPUT_NONE:
+ case LIBTERMINPUT_BRACKETED_PASTE_START:
+ case LIBTERMINPUT_BRACKETED_PASTE_END:
+ case LIBTERMINPUT_TERMINAL_IS_OK:
+ case LIBTERMINPUT_TERMINAL_IS_NOT_OK:
r = 0;
+ break;
+ default:
+ errno = EINVAL;
+ return -1;
+ }
what->type = type;
return r;
}