2019-06-15 22:22:44 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
2021-05-16 19:38:00 +01:00
|
|
|
#include <limits.h>
|
2019-06-15 22:22:44 +02:00
|
|
|
#include <stdint.h>
|
|
|
|
|
#include <stddef.h>
|
|
|
|
|
|
|
|
|
|
#include "terminal.h"
|
|
|
|
|
|
|
|
|
|
void vt_from_slave(struct terminal *term, const uint8_t *data, size_t len);
|
2019-07-10 16:03:18 +02:00
|
|
|
|
|
|
|
|
static inline int
|
|
|
|
|
vt_param_get(const struct terminal *term, size_t idx, int default_value)
|
|
|
|
|
{
|
2021-05-16 19:38:00 +01:00
|
|
|
/*
|
|
|
|
|
* We zero excess bits in parsed param values. In most cases this will
|
|
|
|
|
* effectively be a no-op; but it prevents negative returns for edge
|
|
|
|
|
* cases involving unusually large values.
|
|
|
|
|
*/
|
|
|
|
|
static_assert(INT_MAX >= 0x7fffffff, "POSIX requires INT_MAX >= 0x7fffffff");
|
|
|
|
|
const unsigned value_mask = 0x7fffffff;
|
|
|
|
|
|
2019-07-10 16:03:18 +02:00
|
|
|
if (term->vt.params.idx > idx) {
|
2021-05-16 19:38:00 +01:00
|
|
|
unsigned value = term->vt.params.v[idx].value & value_mask;
|
|
|
|
|
return value != 0 ? (int)value : default_value;
|
2019-07-10 16:03:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return default_value;
|
|
|
|
|
}
|