mirror of
https://github.com/kovidgoyal/kitty.git
synced 2026-12-03 00:14:47 +01:00
212 lines
8.3 KiB
C
212 lines
8.3 KiB
C
// This file is generated by apc_parsers.py do not edit!
|
|
|
|
#pragma once
|
|
|
|
#include "base64.h"
|
|
|
|
static inline void
|
|
parse_smooth_scroll_code(PS *self, uint8_t *parser_buf, const size_t parser_buf_pos) {
|
|
unsigned int pos = 0;
|
|
|
|
enum PARSER_STATES { KEY, EQUAL, UINT, INT, FLAG, AFTER_VALUE };
|
|
enum PARSER_STATES state = KEY, value_state = FLAG;
|
|
SmoothScrollCommand g = {0};
|
|
g.position = SMOOTH_SCROLL_NO_POSITION;
|
|
unsigned int i, code;
|
|
uint64_t lcode;
|
|
bool is_negative;
|
|
(void)is_negative;
|
|
size_t sz;
|
|
(void)sz;
|
|
|
|
enum KEYS {
|
|
action = 'a',
|
|
query_action = 'e',
|
|
id = 'i',
|
|
x = 'x',
|
|
y = 'y',
|
|
width = 'w',
|
|
height = 'h',
|
|
orientation = 'o',
|
|
capacity = 'k',
|
|
private_overflow = 'p',
|
|
delta = 'd',
|
|
position = 'P'
|
|
};
|
|
|
|
enum KEYS key = 'a';
|
|
if (parser_buf[pos] == ';') state = AFTER_VALUE;
|
|
|
|
while (pos < parser_buf_pos) {
|
|
switch (state) {
|
|
case KEY:
|
|
key = parser_buf[pos++];
|
|
state = EQUAL;
|
|
switch (key) {
|
|
case action: value_state = FLAG; break;
|
|
case query_action: value_state = FLAG; break;
|
|
case id: value_state = UINT; break;
|
|
case x: value_state = UINT; break;
|
|
case y: value_state = UINT; break;
|
|
case width: value_state = UINT; break;
|
|
case height: value_state = UINT; break;
|
|
case orientation: value_state = FLAG; break;
|
|
case capacity: value_state = UINT; break;
|
|
case private_overflow: value_state = UINT; break;
|
|
case delta: value_state = INT; break;
|
|
case position: value_state = INT; break;
|
|
default: REPORT_ERROR("Malformed SmoothScrollCommand control block, invalid key character: 0x%x", key); return;
|
|
}
|
|
break;
|
|
|
|
case EQUAL:
|
|
if (parser_buf[pos++] != '=') {
|
|
REPORT_ERROR("Malformed SmoothScrollCommand control block, no = after key, found: 0x%x instead", parser_buf[pos - 1]);
|
|
return;
|
|
}
|
|
state = value_state;
|
|
break;
|
|
|
|
case FLAG:
|
|
switch (key) {
|
|
case action: {
|
|
g.action = parser_buf[pos++];
|
|
if (g.action != 'd' && (g.action < 'q' || g.action > 's')) {
|
|
REPORT_ERROR("Malformed SmoothScrollCommand control block, unknown flag value for action: 0x%x", g.action);
|
|
return;
|
|
};
|
|
} break;
|
|
|
|
|
|
case query_action: {
|
|
g.query_action = parser_buf[pos++];
|
|
if ((g.query_action < 'A' || g.query_action > 'Z') && (g.query_action < 'a' || g.query_action > 'z')) {
|
|
REPORT_ERROR("Malformed SmoothScrollCommand control block, unknown flag value for query_action: 0x%x", g.query_action);
|
|
return;
|
|
};
|
|
} break;
|
|
|
|
|
|
case orientation: {
|
|
g.orientation = parser_buf[pos++];
|
|
if (g.orientation != 'h' && g.orientation != 'v') {
|
|
REPORT_ERROR("Malformed SmoothScrollCommand control block, unknown flag value for orientation: 0x%x", g.orientation);
|
|
return;
|
|
};
|
|
} break;
|
|
|
|
default: break;
|
|
}
|
|
state = AFTER_VALUE;
|
|
break;
|
|
|
|
case INT:
|
|
#define READ_UINT \
|
|
for (i = pos, lcode = 0; i < MIN(parser_buf_pos, pos + 10); i++) { \
|
|
uint8_t n = parser_buf[i] - '0'; \
|
|
if (n > 9) break; \
|
|
lcode = lcode * 10 + n; \
|
|
} \
|
|
if (i == pos) { \
|
|
REPORT_ERROR("Malformed SmoothScrollCommand control block, expecting an integer value for key: %c", key & 0xFF); \
|
|
return; \
|
|
} \
|
|
pos = i; \
|
|
if (lcode > UINT32_MAX) { \
|
|
REPORT_ERROR("Malformed SmoothScrollCommand control block, number is too large"); \
|
|
return; \
|
|
} \
|
|
code = lcode;
|
|
|
|
is_negative = false;
|
|
if (parser_buf[pos] == '-') {
|
|
is_negative = true;
|
|
pos++;
|
|
}
|
|
#define I(x) \
|
|
case x: g.x = is_negative ? (int32_t)(-(int64_t)code) : (int32_t)code; break
|
|
READ_UINT;
|
|
if (code > (is_negative ? 2147483648u : 2147483647u)) {
|
|
REPORT_ERROR("Malformed SmoothScrollCommand control block, number is too large");
|
|
return;
|
|
}
|
|
switch (key) {
|
|
I(delta);
|
|
I(position);
|
|
default: break;
|
|
}
|
|
state = AFTER_VALUE;
|
|
break;
|
|
#undef I
|
|
case UINT: READ_UINT;
|
|
#define U(x) \
|
|
case x: g.x = code; break
|
|
switch (key) {
|
|
U(id);
|
|
U(x);
|
|
U(y);
|
|
U(width);
|
|
U(height);
|
|
U(capacity);
|
|
U(private_overflow);
|
|
default: break;
|
|
}
|
|
state = AFTER_VALUE;
|
|
break;
|
|
#undef U
|
|
#undef READ_UINT
|
|
|
|
case AFTER_VALUE:
|
|
switch (parser_buf[pos++]) {
|
|
default:
|
|
REPORT_ERROR(
|
|
"Malformed SmoothScrollCommand control block, expecting a : or semi-colon after a value, found: 0x%x", parser_buf[pos - 1]);
|
|
return;
|
|
case ':': state = KEY; break;
|
|
}
|
|
break;
|
|
|
|
|
|
} // end switch
|
|
} // end while
|
|
|
|
switch (state) {
|
|
case EQUAL: REPORT_ERROR("Malformed SmoothScrollCommand control block, no = after key"); return;
|
|
case INT:
|
|
case UINT: REPORT_ERROR("Malformed SmoothScrollCommand control block, expecting an integer value"); return;
|
|
case FLAG: REPORT_ERROR("Malformed SmoothScrollCommand control block, expecting a flag value"); return;
|
|
default: break;
|
|
}
|
|
|
|
REPORT_VA_COMMAND(
|
|
"K s {sc sc sc sI sI sI sI sI sI sI si si}",
|
|
self->window_id,
|
|
"smooth_scroll_command",
|
|
"action",
|
|
g.action,
|
|
"query_action",
|
|
g.query_action,
|
|
"orientation",
|
|
g.orientation,
|
|
"id",
|
|
(unsigned int)g.id,
|
|
"x",
|
|
(unsigned int)g.x,
|
|
"y",
|
|
(unsigned int)g.y,
|
|
"width",
|
|
(unsigned int)g.width,
|
|
"height",
|
|
(unsigned int)g.height,
|
|
"capacity",
|
|
(unsigned int)g.capacity,
|
|
"private_overflow",
|
|
(unsigned int)g.private_overflow,
|
|
"delta",
|
|
(int)g.delta,
|
|
"position",
|
|
(int)g.position);
|
|
|
|
screen_handle_smooth_scroll_command(self->screen, &g);
|
|
}
|