aboutsummaryrefslogtreecommitdiffstats
path: root/libterminput_unmarshal_input.c
blob: c8c20a2f9cbbcf4ddebc4cfc489ae0f35697e167 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/* See LICENSE file for copyright and license details. */
#include "common.h"


int
libterminput_unmarshal_input(struct libterminput_unmarshaller *how, union libterminput_input *what)
{
	enum libterminput_type type;
	int r;
	if (how->load(how, &what->type, sizeof(what->type)))
		return -1;
	type = what->type;
	if (what->type == LIBTERMINPUT_NONE) {
		what->keypress.key = LIBTERMINPUT_SYMBOL;
		if (how->load(how, &what->type, sizeof(what->type)))
			return -1;
	}
	switch ((int)what->type) {
	case LIBTERMINPUT_KEYPRESS:
		r = libterminput_unmarshal_keypress__(how, &what->keypress);
		break;
	case LIBTERMINPUT_TEXT:
		r = libterminput_unmarshal_text__(how, &what->text);
		break;
	case LIBTERMINPUT_MOUSEEVENT:
		r = libterminput_unmarshal_mouseevent__(how, &what->mouseevent);
		break;
	case LIBTERMINPUT_CURSOR_POSITION:
		r = libterminput_unmarshal_position__(how, &what->position);
		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;
}