aboutsummaryrefslogtreecommitdiffstats
path: root/libterminput_unmarshal_keypress__.c
blob: f4b4fc6a2d4a8aed01178179dbc36f1502cc56d6 (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
/* See LICENSE file for copyright and license details. */
#include "common.h"


int
libterminput_unmarshal_keypress__(struct libterminput_unmarshaller *how, struct libterminput_keypress *what) /* TODO test */
{
	what->type = LIBTERMINPUT_KEYPRESS;
	if (how->load(how, &what->key, sizeof(what->key)) ||
	    how->load(how, &what->times, sizeof(what->times)) ||
	    how->load(how, &what->mods, sizeof(what->mods)))
		return -1;
	if ((uintmax_t)what->key > (uintmax_t)LIBTERMINPUT_KEYPAD__LAST__) {
		errno = EINVAL;
		return -1;
	}
	if (what->key == LIBTERMINPUT_SYMBOL) {
		return how->load(how, what->symbol, sizeof(what->symbol));
	} else {
		memset(what->symbol, 0, sizeof(what->symbol));
		return 0;
	}
}