2007-11-09 18:06:01 +01:00
|
|
|
/* $Id: input.c,v 1.30 2007-11-09 17:06:01 nicm Exp $ */
|
2007-07-09 21:04:12 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, and distribute this software for any
|
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
|
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
* WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
|
|
|
|
* IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
|
|
|
#include <stdint.h>
|
2007-09-29 00:47:22 +02:00
|
|
|
#include <stdlib.h>
|
2007-09-29 00:54:21 +02:00
|
|
|
#include <string.h>
|
2007-07-09 21:04:12 +02:00
|
|
|
|
|
|
|
#include "tmux.h"
|
|
|
|
|
2007-10-10 21:45:20 +02:00
|
|
|
#define INPUT_C0CONTROL(ch) (ch <= 0x1f)
|
|
|
|
#define INPUT_INTERMEDIATE(ch) (ch == 0xa0 || (ch >= 0x20 && ch <= 0x2f))
|
|
|
|
#define INPUT_PARAMETER(ch) (ch >= 0x30 && ch <= 0x3f)
|
|
|
|
#define INPUT_UPPERCASE(ch) (ch >= 0x40 && ch <= 0x5f)
|
|
|
|
#define INPUT_LOWERCASE(ch) (ch >= 0x60 && ch <= 0x7e)
|
|
|
|
#define INPUT_DELETE(ch) (ch == 0x7f)
|
|
|
|
#define INPUT_C1CONTROL(ch) (ch >= 0x80 && ch <= 0x9f)
|
|
|
|
#define INPUT_G1DISPLAYABLE(ch) (ch >= 0xa1 && ch <= 0xfe)
|
|
|
|
#define INPUT_SPECIAL(ch) (ch == 0xff)
|
|
|
|
|
2007-09-29 00:47:22 +02:00
|
|
|
int input_get_argument(struct input_ctx *, u_int, uint16_t *, uint16_t);
|
2007-09-29 16:25:49 +02:00
|
|
|
int input_new_argument(struct input_ctx *);
|
|
|
|
int input_add_argument(struct input_ctx *, u_char ch);
|
2007-09-29 00:47:22 +02:00
|
|
|
|
2007-10-10 21:45:20 +02:00
|
|
|
void *input_state_first(u_char, struct input_ctx *);
|
|
|
|
void *input_state_escape(u_char, struct input_ctx *);
|
|
|
|
void *input_state_intermediate(u_char, struct input_ctx *);
|
|
|
|
void *input_state_title_first(u_char, struct input_ctx *);
|
|
|
|
void *input_state_title_second(u_char, struct input_ctx *);
|
|
|
|
void *input_state_title_next(u_char, struct input_ctx *);
|
|
|
|
void *input_state_sequence_first(u_char, struct input_ctx *);
|
|
|
|
void *input_state_sequence_next(u_char, struct input_ctx *);
|
|
|
|
void *input_state_sequence_intermediate(u_char, struct input_ctx *);
|
2007-09-29 00:47:22 +02:00
|
|
|
|
|
|
|
void input_handle_character(u_char, struct input_ctx *);
|
|
|
|
void input_handle_c0_control(u_char, struct input_ctx *);
|
|
|
|
void input_handle_c1_control(u_char, struct input_ctx *);
|
|
|
|
void input_handle_private_two(u_char, struct input_ctx *);
|
|
|
|
void input_handle_standard_two(u_char, struct input_ctx *);
|
|
|
|
void input_handle_sequence(u_char, struct input_ctx *);
|
|
|
|
|
|
|
|
void input_handle_sequence_cuu(struct input_ctx *);
|
|
|
|
void input_handle_sequence_cud(struct input_ctx *);
|
|
|
|
void input_handle_sequence_cuf(struct input_ctx *);
|
|
|
|
void input_handle_sequence_cub(struct input_ctx *);
|
|
|
|
void input_handle_sequence_dch(struct input_ctx *);
|
|
|
|
void input_handle_sequence_dl(struct input_ctx *);
|
|
|
|
void input_handle_sequence_ich(struct input_ctx *);
|
|
|
|
void input_handle_sequence_il(struct input_ctx *);
|
|
|
|
void input_handle_sequence_vpa(struct input_ctx *);
|
|
|
|
void input_handle_sequence_hpa(struct input_ctx *);
|
|
|
|
void input_handle_sequence_cup(struct input_ctx *);
|
|
|
|
void input_handle_sequence_cup(struct input_ctx *);
|
|
|
|
void input_handle_sequence_ed(struct input_ctx *);
|
|
|
|
void input_handle_sequence_el(struct input_ctx *);
|
|
|
|
void input_handle_sequence_sm(struct input_ctx *);
|
|
|
|
void input_handle_sequence_rm(struct input_ctx *);
|
|
|
|
void input_handle_sequence_decstbm(struct input_ctx *);
|
|
|
|
void input_handle_sequence_sgr(struct input_ctx *);
|
2007-10-24 17:29:29 +02:00
|
|
|
void input_handle_sequence_dsr(struct input_ctx *);
|
2007-09-29 00:47:22 +02:00
|
|
|
|
2007-09-29 16:25:49 +02:00
|
|
|
int
|
|
|
|
input_new_argument(struct input_ctx *ictx)
|
|
|
|
{
|
|
|
|
struct input_arg *arg;
|
|
|
|
|
|
|
|
ARRAY_EXPAND(&ictx->args, 1);
|
|
|
|
|
|
|
|
arg = &ARRAY_LAST(&ictx->args);
|
|
|
|
arg->used = 0;
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
input_add_argument(struct input_ctx *ictx, u_char ch)
|
|
|
|
{
|
|
|
|
struct input_arg *arg;
|
|
|
|
|
|
|
|
if (ARRAY_LENGTH(&ictx->args) == 0)
|
|
|
|
return (0);
|
|
|
|
|
|
|
|
arg = &ARRAY_LAST(&ictx->args);
|
|
|
|
if (arg->used > (sizeof arg->data) - 1)
|
|
|
|
return (-1);
|
|
|
|
arg->data[arg->used++] = ch;
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2007-09-29 00:47:22 +02:00
|
|
|
int
|
|
|
|
input_get_argument(struct input_ctx *ictx, u_int i, uint16_t *n, uint16_t d)
|
|
|
|
{
|
|
|
|
struct input_arg *arg;
|
|
|
|
const char *errstr;
|
2007-07-09 21:04:12 +02:00
|
|
|
|
2007-09-29 00:47:22 +02:00
|
|
|
*n = d;
|
|
|
|
if (i >= ARRAY_LENGTH(&ictx->args))
|
|
|
|
return (0);
|
2007-07-09 21:04:12 +02:00
|
|
|
|
2007-09-29 00:47:22 +02:00
|
|
|
arg = &ARRAY_ITEM(&ictx->args, i);
|
2007-09-29 16:25:49 +02:00
|
|
|
if (*arg->data == '\0')
|
2007-09-29 00:47:22 +02:00
|
|
|
return (0);
|
2007-07-09 21:04:12 +02:00
|
|
|
|
2007-09-29 16:25:49 +02:00
|
|
|
*n = strtonum(arg->data, 0, UINT16_MAX, &errstr);
|
2007-09-29 00:47:22 +02:00
|
|
|
if (errstr != NULL)
|
|
|
|
return (-1);
|
2007-07-09 21:04:12 +02:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2007-10-24 17:29:29 +02:00
|
|
|
input_init(struct window *w)
|
2007-07-09 21:04:12 +02:00
|
|
|
{
|
2007-10-24 17:29:29 +02:00
|
|
|
ARRAY_INIT(&w->ictx.args);
|
2007-07-09 21:04:12 +02:00
|
|
|
|
2007-10-24 17:29:29 +02:00
|
|
|
w->ictx.state = input_state_first;
|
2007-09-29 00:47:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2007-10-24 17:29:29 +02:00
|
|
|
input_free(struct window *w)
|
2007-09-29 00:47:22 +02:00
|
|
|
{
|
2007-10-24 17:29:29 +02:00
|
|
|
ARRAY_FREE(&w->ictx.args);
|
2007-07-09 21:04:12 +02:00
|
|
|
}
|
|
|
|
|
2007-09-29 11:15:49 +02:00
|
|
|
void
|
2007-10-24 17:29:29 +02:00
|
|
|
input_parse(struct window *w, struct buffer *b)
|
2007-07-09 21:04:12 +02:00
|
|
|
{
|
2007-10-24 17:29:29 +02:00
|
|
|
struct input_ctx *ictx = &w->ictx;
|
|
|
|
u_char ch;
|
|
|
|
|
|
|
|
if (BUFFER_USED(w->in) == 0)
|
|
|
|
return;
|
2007-07-09 21:04:12 +02:00
|
|
|
|
2007-10-24 17:29:29 +02:00
|
|
|
ictx->buf = BUFFER_OUT(w->in);
|
|
|
|
ictx->len = BUFFER_USED(w->in);
|
2007-09-29 00:47:22 +02:00
|
|
|
ictx->off = 0;
|
2007-07-09 21:04:12 +02:00
|
|
|
|
2007-10-24 17:29:29 +02:00
|
|
|
ictx->w = w;
|
2007-09-29 00:47:22 +02:00
|
|
|
ictx->b = b;
|
|
|
|
|
|
|
|
log_debug2("entry; buffer=%zu", ictx->len);
|
|
|
|
|
|
|
|
while (ictx->off < ictx->len) {
|
|
|
|
ch = ictx->buf[ictx->off++];
|
2007-10-10 21:45:20 +02:00
|
|
|
ictx->state = ictx->state(ch, ictx);
|
2007-07-09 21:04:12 +02:00
|
|
|
}
|
2007-10-24 17:29:29 +02:00
|
|
|
|
|
|
|
buffer_remove(w->in, ictx->len);
|
2007-09-29 00:47:22 +02:00
|
|
|
}
|
2007-07-09 21:04:12 +02:00
|
|
|
|
2007-09-29 00:47:22 +02:00
|
|
|
void *
|
2007-10-10 21:45:20 +02:00
|
|
|
input_state_first(u_char ch, struct input_ctx *ictx)
|
2007-09-29 00:47:22 +02:00
|
|
|
{
|
2007-10-10 21:45:20 +02:00
|
|
|
if (INPUT_C0CONTROL(ch)) {
|
2007-09-29 00:47:22 +02:00
|
|
|
if (ch == 0x1b)
|
|
|
|
return (input_state_escape);
|
|
|
|
input_handle_c0_control(ch, ictx);
|
2007-10-10 21:45:20 +02:00
|
|
|
return (input_state_first);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (INPUT_C1CONTROL(ch)) {
|
2007-09-29 00:47:22 +02:00
|
|
|
ch -= 0x40;
|
|
|
|
if (ch == '[')
|
|
|
|
return (input_state_sequence_first);
|
2007-10-01 19:37:41 +02:00
|
|
|
if (ch == ']')
|
|
|
|
return (input_state_title_first);
|
2007-09-29 00:47:22 +02:00
|
|
|
input_handle_c1_control(ch, ictx);
|
2007-10-10 21:45:20 +02:00
|
|
|
return (input_state_first);
|
2007-09-29 00:47:22 +02:00
|
|
|
}
|
2007-10-10 21:45:20 +02:00
|
|
|
|
|
|
|
input_handle_character(ch, ictx);
|
2007-09-29 00:47:22 +02:00
|
|
|
return (input_state_first);
|
|
|
|
}
|
2007-10-10 21:45:20 +02:00
|
|
|
|
2007-09-29 00:47:22 +02:00
|
|
|
void *
|
2007-10-10 21:45:20 +02:00
|
|
|
input_state_escape(u_char ch, struct input_ctx *ictx)
|
2007-09-29 00:47:22 +02:00
|
|
|
{
|
2007-10-10 21:45:20 +02:00
|
|
|
/* Treat C1 control and G1 displayable as 7-bit equivalent. */
|
|
|
|
if (INPUT_C1CONTROL(ch) || INPUT_G1DISPLAYABLE(ch))
|
2007-09-29 00:47:22 +02:00
|
|
|
ch &= 0x7f;
|
2007-07-09 21:04:12 +02:00
|
|
|
|
2007-10-10 21:45:20 +02:00
|
|
|
if (INPUT_C0CONTROL(ch)) {
|
2007-09-29 00:47:22 +02:00
|
|
|
input_handle_c0_control(ch, ictx);
|
|
|
|
return (input_state_escape);
|
2007-10-10 21:45:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (INPUT_INTERMEDIATE(ch))
|
2007-09-29 00:47:22 +02:00
|
|
|
return (input_state_intermediate);
|
2007-10-10 21:45:20 +02:00
|
|
|
|
|
|
|
if (INPUT_PARAMETER(ch)) {
|
2007-09-29 00:47:22 +02:00
|
|
|
input_handle_private_two(ch, ictx);
|
2007-10-10 21:45:20 +02:00
|
|
|
return (input_state_first);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (INPUT_UPPERCASE(ch)) {
|
2007-09-29 00:47:22 +02:00
|
|
|
if (ch == '[')
|
|
|
|
return (input_state_sequence_first);
|
2007-10-01 19:37:41 +02:00
|
|
|
if (ch == ']')
|
|
|
|
return (input_state_title_first);
|
2007-09-29 00:47:22 +02:00
|
|
|
input_handle_c1_control(ch, ictx);
|
2007-10-10 21:45:20 +02:00
|
|
|
return (input_state_first);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (INPUT_LOWERCASE(ch)) {
|
2007-09-29 00:47:22 +02:00
|
|
|
input_handle_standard_two(ch, ictx);
|
2007-10-10 21:45:20 +02:00
|
|
|
return (input_state_first);
|
|
|
|
}
|
|
|
|
|
2007-09-29 00:47:22 +02:00
|
|
|
return (input_state_first);
|
|
|
|
}
|
2007-07-09 21:04:12 +02:00
|
|
|
|
2007-10-01 19:37:41 +02:00
|
|
|
void *
|
2007-10-10 21:45:20 +02:00
|
|
|
input_state_title_first(u_char ch, struct input_ctx *ictx)
|
2007-10-01 19:37:41 +02:00
|
|
|
{
|
|
|
|
if (ch >= '0' && ch <= '9') {
|
|
|
|
ictx->title_type = ch - '0';
|
|
|
|
return (input_state_title_second);
|
|
|
|
}
|
2007-10-10 21:45:20 +02:00
|
|
|
|
2007-10-01 19:37:41 +02:00
|
|
|
return (input_state_first);
|
|
|
|
}
|
|
|
|
|
|
|
|
void *
|
2007-10-10 21:45:20 +02:00
|
|
|
input_state_title_second(u_char ch, struct input_ctx *ictx)
|
2007-10-01 19:37:41 +02:00
|
|
|
{
|
|
|
|
if (ch == ';') {
|
|
|
|
ictx->title_len = 0;
|
|
|
|
return (input_state_title_next);
|
|
|
|
}
|
2007-10-10 21:45:20 +02:00
|
|
|
|
2007-10-01 19:37:41 +02:00
|
|
|
return (input_state_first);
|
|
|
|
}
|
|
|
|
|
|
|
|
void *
|
2007-10-10 21:45:20 +02:00
|
|
|
input_state_title_next(u_char ch, struct input_ctx *ictx)
|
2007-10-01 19:37:41 +02:00
|
|
|
{
|
2007-10-24 17:40:59 +02:00
|
|
|
struct screen *s = &ictx->w->screen;
|
|
|
|
|
2007-10-01 19:37:41 +02:00
|
|
|
if (ch == '\007') {
|
2007-10-20 01:25:33 +02:00
|
|
|
ictx->title_buf[ictx->title_len++] = '\0';
|
2007-10-01 19:37:41 +02:00
|
|
|
switch (ictx->title_type) {
|
|
|
|
case 0:
|
2007-10-24 17:40:59 +02:00
|
|
|
strlcpy(s->title, ictx->title_buf, sizeof s->title);
|
2007-10-01 19:37:41 +02:00
|
|
|
input_store_one(ictx->b, CODE_TITLE, ictx->title_len);
|
|
|
|
buffer_write(ictx->b, ictx->title_buf, ictx->title_len);
|
|
|
|
break;
|
|
|
|
}
|
2007-10-10 21:45:20 +02:00
|
|
|
return (input_state_first);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ch >= 0x20) {
|
2007-10-01 19:37:41 +02:00
|
|
|
if (ictx->title_len < (sizeof ictx->title_buf) - 1) {
|
|
|
|
ictx->title_buf[ictx->title_len++] = ch;
|
|
|
|
return (input_state_title_next);
|
|
|
|
}
|
2007-10-10 21:45:20 +02:00
|
|
|
return (input_state_first);
|
2007-10-01 19:37:41 +02:00
|
|
|
}
|
2007-10-10 21:45:20 +02:00
|
|
|
|
2007-10-01 19:37:41 +02:00
|
|
|
return (input_state_first);
|
|
|
|
}
|
|
|
|
|
2007-09-29 00:47:22 +02:00
|
|
|
void *
|
2007-10-10 21:45:20 +02:00
|
|
|
input_state_intermediate(u_char ch, struct input_ctx *ictx)
|
2007-09-29 00:47:22 +02:00
|
|
|
{
|
2007-10-10 21:45:20 +02:00
|
|
|
if (INPUT_INTERMEDIATE(ch))
|
2007-09-29 00:47:22 +02:00
|
|
|
return (input_state_intermediate);
|
2007-10-10 21:45:20 +02:00
|
|
|
|
|
|
|
if (INPUT_PARAMETER(ch)) {
|
2007-09-29 00:47:22 +02:00
|
|
|
input_handle_private_two(ch, ictx);
|
2007-10-10 21:45:20 +02:00
|
|
|
return (input_state_first);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (INPUT_UPPERCASE(ch) || INPUT_LOWERCASE(ch)) {
|
2007-09-29 00:47:22 +02:00
|
|
|
input_handle_standard_two(ch, ictx);
|
2007-10-10 21:45:20 +02:00
|
|
|
return (input_state_first);
|
|
|
|
}
|
|
|
|
|
2007-09-29 00:47:22 +02:00
|
|
|
return (input_state_first);
|
|
|
|
}
|
2007-07-09 21:04:12 +02:00
|
|
|
|
2007-09-29 00:47:22 +02:00
|
|
|
void *
|
2007-10-10 21:45:20 +02:00
|
|
|
input_state_sequence_first(u_char ch, struct input_ctx *ictx)
|
2007-09-29 00:47:22 +02:00
|
|
|
{
|
|
|
|
ictx->private = '\0';
|
2007-09-29 16:25:49 +02:00
|
|
|
ARRAY_CLEAR(&ictx->args);
|
2007-09-29 00:47:22 +02:00
|
|
|
|
2007-10-10 21:45:20 +02:00
|
|
|
if (INPUT_PARAMETER(ch)) {
|
2007-09-29 00:47:22 +02:00
|
|
|
if (ch >= 0x3c && ch <= 0x3f) {
|
|
|
|
/* Private control sequence. */
|
|
|
|
ictx->private = ch;
|
|
|
|
return (input_state_sequence_next);
|
2007-07-09 21:04:12 +02:00
|
|
|
}
|
2007-09-29 16:25:49 +02:00
|
|
|
input_new_argument(ictx);
|
2007-09-29 00:47:22 +02:00
|
|
|
}
|
2007-07-09 21:04:12 +02:00
|
|
|
|
2007-09-29 16:25:49 +02:00
|
|
|
/* Pass character on directly. */
|
2007-10-10 21:45:20 +02:00
|
|
|
return (input_state_sequence_next(ch, ictx));
|
2007-09-29 00:47:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void *
|
2007-10-10 21:45:20 +02:00
|
|
|
input_state_sequence_next(u_char ch, struct input_ctx *ictx)
|
2007-09-29 00:47:22 +02:00
|
|
|
{
|
2007-10-10 21:45:20 +02:00
|
|
|
if (INPUT_INTERMEDIATE(ch)) {
|
2007-09-29 16:25:49 +02:00
|
|
|
if (input_add_argument(ictx, '\0') != 0)
|
2007-10-10 21:45:20 +02:00
|
|
|
return (input_state_first);
|
2007-09-29 00:47:22 +02:00
|
|
|
return (input_state_sequence_intermediate);
|
2007-10-10 21:45:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (INPUT_PARAMETER(ch)) {
|
2007-09-29 00:47:22 +02:00
|
|
|
if (ch == ';') {
|
2007-09-29 16:25:49 +02:00
|
|
|
if (input_add_argument(ictx, '\0') != 0)
|
2007-10-10 21:45:20 +02:00
|
|
|
return (input_state_first);
|
2007-09-29 16:25:49 +02:00
|
|
|
input_new_argument(ictx);
|
2007-09-29 00:47:22 +02:00
|
|
|
return (input_state_sequence_next);
|
2007-07-09 21:04:12 +02:00
|
|
|
}
|
2007-09-29 16:25:49 +02:00
|
|
|
if (input_add_argument(ictx, ch) != 0)
|
2007-10-10 21:45:20 +02:00
|
|
|
return (input_state_first);
|
2007-09-29 00:47:22 +02:00
|
|
|
return (input_state_sequence_next);
|
2007-10-10 21:45:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (INPUT_UPPERCASE(ch) || INPUT_LOWERCASE(ch)) {
|
2007-09-29 16:25:49 +02:00
|
|
|
if (input_add_argument(ictx, '\0') != 0)
|
2007-10-10 21:45:20 +02:00
|
|
|
return (input_state_first);
|
2007-09-29 00:47:22 +02:00
|
|
|
input_handle_sequence(ch, ictx);
|
2007-10-10 21:45:20 +02:00
|
|
|
return (input_state_first);
|
|
|
|
}
|
|
|
|
|
2007-09-29 00:47:22 +02:00
|
|
|
return (input_state_first);
|
|
|
|
}
|
2007-07-09 21:04:12 +02:00
|
|
|
|
2007-09-29 00:47:22 +02:00
|
|
|
void *
|
2007-10-10 21:45:20 +02:00
|
|
|
input_state_sequence_intermediate(u_char ch, struct input_ctx *ictx)
|
2007-09-29 00:47:22 +02:00
|
|
|
{
|
2007-10-10 21:45:20 +02:00
|
|
|
if (INPUT_INTERMEDIATE(ch))
|
2007-09-29 00:47:22 +02:00
|
|
|
return (input_state_sequence_intermediate);
|
2007-10-10 21:45:20 +02:00
|
|
|
|
|
|
|
if (INPUT_UPPERCASE(ch) || INPUT_LOWERCASE(ch)) {
|
2007-09-29 00:47:22 +02:00
|
|
|
input_handle_sequence(ch, ictx);
|
2007-10-10 21:45:20 +02:00
|
|
|
return (input_state_first);
|
|
|
|
}
|
|
|
|
|
2007-09-29 00:47:22 +02:00
|
|
|
return (input_state_first);
|
|
|
|
}
|
2007-07-09 21:04:12 +02:00
|
|
|
|
2007-09-29 00:47:22 +02:00
|
|
|
void
|
|
|
|
input_handle_character(u_char ch, struct input_ctx *ictx)
|
|
|
|
{
|
2007-10-24 17:40:59 +02:00
|
|
|
struct screen *s = &ictx->w->screen;
|
|
|
|
|
2007-09-29 00:47:22 +02:00
|
|
|
log_debug2("-- ch %zu: %hhu (%c)", ictx->off, ch, ch);
|
2007-10-04 21:03:52 +02:00
|
|
|
|
2007-10-24 17:40:59 +02:00
|
|
|
if (s->cx > s->sx || s->cy > s->sy - 1)
|
2007-10-04 21:03:52 +02:00
|
|
|
return;
|
2007-10-05 19:51:56 +02:00
|
|
|
|
2007-10-24 17:40:59 +02:00
|
|
|
if (s->cx == s->sx) {
|
2007-10-12 13:44:30 +02:00
|
|
|
input_store8(ictx->b, '\r');
|
|
|
|
input_store8(ictx->b, '\n');
|
2007-10-05 19:51:56 +02:00
|
|
|
|
2007-10-24 17:40:59 +02:00
|
|
|
s->cx = 0;
|
|
|
|
screen_cursor_down_scroll(s);
|
2007-10-12 13:44:30 +02:00
|
|
|
}
|
2007-10-05 19:51:56 +02:00
|
|
|
|
2007-10-24 17:40:59 +02:00
|
|
|
screen_write_character(s, ch);
|
2007-10-12 13:44:30 +02:00
|
|
|
input_store8(ictx->b, ch);
|
|
|
|
|
2007-10-24 17:40:59 +02:00
|
|
|
s->cx++;
|
2007-07-09 21:04:12 +02:00
|
|
|
}
|
|
|
|
|
2007-09-29 00:47:22 +02:00
|
|
|
void
|
|
|
|
input_handle_c0_control(u_char ch, struct input_ctx *ictx)
|
2007-07-09 21:04:12 +02:00
|
|
|
{
|
2007-10-24 17:40:59 +02:00
|
|
|
struct screen *s = &ictx->w->screen;
|
|
|
|
|
2007-09-29 00:47:22 +02:00
|
|
|
log_debug2("-- c0 %zu: %hhu", ictx->off, ch);
|
|
|
|
|
2007-07-09 21:04:12 +02:00
|
|
|
switch (ch) {
|
|
|
|
case '\0': /* NUL */
|
|
|
|
break;
|
|
|
|
case '\n': /* LF */
|
2007-10-24 17:40:59 +02:00
|
|
|
screen_cursor_down_scroll(s);
|
2007-09-29 00:47:22 +02:00
|
|
|
break;
|
2007-07-09 21:04:12 +02:00
|
|
|
case '\r': /* CR */
|
2007-10-24 17:40:59 +02:00
|
|
|
s->cx = 0;
|
2007-09-29 00:47:22 +02:00
|
|
|
break;
|
2007-09-29 11:15:49 +02:00
|
|
|
case '\007': /* BELL */
|
2007-10-24 17:29:29 +02:00
|
|
|
ictx->w->flags |= WINDOW_BELL;
|
2007-10-19 12:21:36 +02:00
|
|
|
return;
|
2007-07-09 21:04:12 +02:00
|
|
|
case '\010': /* BS */
|
2007-10-24 17:40:59 +02:00
|
|
|
if (s->cx > 0)
|
|
|
|
s->cx--;
|
2007-07-09 21:04:12 +02:00
|
|
|
break;
|
2007-11-09 18:06:01 +01:00
|
|
|
case '\011': /* TAB */
|
|
|
|
s->cx = ((s->cx / 8) * 8) + 8;
|
|
|
|
if (s->cx > s->sx) {
|
|
|
|
s->cx = 0;
|
|
|
|
screen_cursor_down_scroll(s);
|
|
|
|
}
|
|
|
|
input_store_two(
|
|
|
|
ictx->b, CODE_CURSORMOVE, s->cy + 1, s->cx + 1);
|
|
|
|
return;
|
2007-07-09 21:04:12 +02:00
|
|
|
default:
|
2007-09-29 00:47:22 +02:00
|
|
|
log_debug("unknown c0: %hhu", ch);
|
|
|
|
return;
|
2007-07-09 21:04:12 +02:00
|
|
|
}
|
2007-09-29 00:47:22 +02:00
|
|
|
input_store8(ictx->b, ch);
|
|
|
|
}
|
2007-07-09 21:04:12 +02:00
|
|
|
|
2007-09-29 00:47:22 +02:00
|
|
|
void
|
|
|
|
input_handle_c1_control(u_char ch, struct input_ctx *ictx)
|
|
|
|
{
|
2007-10-24 17:40:59 +02:00
|
|
|
struct screen *s = &ictx->w->screen;
|
|
|
|
|
2007-09-29 00:47:22 +02:00
|
|
|
log_debug2("-- c1 %zu: %hhu (%c)", ictx->off, ch, ch);
|
|
|
|
|
|
|
|
switch (ch) {
|
|
|
|
case 'M': /* RI */
|
2007-10-24 17:40:59 +02:00
|
|
|
screen_cursor_up_scroll(s);
|
2007-09-29 00:47:22 +02:00
|
|
|
input_store_zero(ictx->b, CODE_REVERSEINDEX);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
log_debug("unknown c1: %hhu", ch);
|
|
|
|
break;
|
|
|
|
}
|
2007-07-09 21:04:12 +02:00
|
|
|
}
|
|
|
|
|
2007-09-29 00:47:22 +02:00
|
|
|
void
|
|
|
|
input_handle_private_two(u_char ch, struct input_ctx *ictx)
|
2007-07-09 21:04:12 +02:00
|
|
|
{
|
2007-10-24 17:40:59 +02:00
|
|
|
struct screen *s = &ictx->w->screen;
|
|
|
|
|
2007-09-29 16:25:49 +02:00
|
|
|
log_debug2("-- p2 %zu: %hhu (%c)", ictx->off, ch, ch);
|
2007-07-09 21:04:12 +02:00
|
|
|
|
|
|
|
switch (ch) {
|
|
|
|
case '=': /* DECKPAM */
|
2007-09-29 00:47:22 +02:00
|
|
|
input_store_zero(ictx->b, CODE_KKEYPADON);
|
2007-07-09 21:04:12 +02:00
|
|
|
break;
|
|
|
|
case '>': /* DECKPNM*/
|
2007-09-29 00:47:22 +02:00
|
|
|
input_store_zero(ictx->b, CODE_KKEYPADOFF);
|
2007-07-09 21:04:12 +02:00
|
|
|
break;
|
2007-10-24 17:01:25 +02:00
|
|
|
case '7': /* DECSC */
|
2007-10-24 17:40:59 +02:00
|
|
|
s->saved_cx = s->cx;
|
|
|
|
s->saved_cy = s->cy;
|
|
|
|
s->saved_attr = s->attr;
|
|
|
|
s->saved_colr = s->colr;
|
|
|
|
s->mode |= MODE_SAVED;
|
2007-10-24 17:01:25 +02:00
|
|
|
break;
|
|
|
|
case '8': /* DECRC */
|
2007-10-24 17:40:59 +02:00
|
|
|
if (!(s->mode & MODE_SAVED))
|
2007-10-24 17:01:25 +02:00
|
|
|
break;
|
2007-10-24 17:40:59 +02:00
|
|
|
s->cx = s->saved_cx;
|
|
|
|
s->cy = s->saved_cy;
|
|
|
|
s->attr = s->saved_attr;
|
|
|
|
s->colr = s->saved_colr;
|
2007-10-24 17:01:25 +02:00
|
|
|
input_store_two(
|
2007-10-24 17:40:59 +02:00
|
|
|
ictx->b, CODE_ATTRIBUTES, s->attr, s->colr);
|
2007-10-24 17:01:25 +02:00
|
|
|
input_store_two(ictx->b, CODE_SCROLLREGION,
|
2007-10-24 17:40:59 +02:00
|
|
|
s->ry_upper + 1, s->ry_lower + 1);
|
2007-10-24 17:01:25 +02:00
|
|
|
input_store_two(
|
2007-10-24 17:40:59 +02:00
|
|
|
ictx->b, CODE_CURSORMOVE, s->cy + 1, s->cx + 1);
|
2007-10-24 17:01:25 +02:00
|
|
|
break;
|
2007-07-09 21:04:12 +02:00
|
|
|
default:
|
2007-09-29 00:47:22 +02:00
|
|
|
log_debug("unknown p2: %hhu", ch);
|
2007-07-09 21:04:12 +02:00
|
|
|
break;
|
|
|
|
}
|
2007-09-29 00:47:22 +02:00
|
|
|
}
|
2007-07-09 21:04:12 +02:00
|
|
|
|
2007-09-29 00:47:22 +02:00
|
|
|
void
|
|
|
|
input_handle_standard_two(u_char ch, struct input_ctx *ictx)
|
|
|
|
{
|
2007-09-29 16:25:49 +02:00
|
|
|
log_debug2("-- s2 %zu: %hhu (%c)", ictx->off, ch, ch);
|
2007-09-29 00:47:22 +02:00
|
|
|
|
|
|
|
log_debug("unknown s2: %hhu", ch);
|
2007-07-09 21:04:12 +02:00
|
|
|
}
|
|
|
|
|
2007-09-29 00:47:22 +02:00
|
|
|
void
|
|
|
|
input_handle_sequence(u_char ch, struct input_ctx *ictx)
|
2007-07-09 21:04:12 +02:00
|
|
|
{
|
2007-09-29 00:47:22 +02:00
|
|
|
static const struct {
|
|
|
|
u_char ch;
|
|
|
|
void (*fn)(struct input_ctx *);
|
|
|
|
} table[] = {
|
2007-09-30 15:29:28 +02:00
|
|
|
{ '@', input_handle_sequence_ich },
|
2007-09-29 00:47:22 +02:00
|
|
|
{ 'A', input_handle_sequence_cuu },
|
|
|
|
{ 'B', input_handle_sequence_cud },
|
|
|
|
{ 'C', input_handle_sequence_cuf },
|
|
|
|
{ 'D', input_handle_sequence_cub },
|
|
|
|
{ 'G', input_handle_sequence_hpa },
|
|
|
|
{ 'H', input_handle_sequence_cup },
|
|
|
|
{ 'J', input_handle_sequence_ed },
|
|
|
|
{ 'K', input_handle_sequence_el },
|
2007-09-30 15:29:28 +02:00
|
|
|
{ 'L', input_handle_sequence_il },
|
|
|
|
{ 'M', input_handle_sequence_dl },
|
|
|
|
{ 'P', input_handle_sequence_dch },
|
|
|
|
{ 'd', input_handle_sequence_vpa },
|
|
|
|
{ 'f', input_handle_sequence_cup },
|
2007-09-29 00:47:22 +02:00
|
|
|
{ 'h', input_handle_sequence_sm },
|
|
|
|
{ 'l', input_handle_sequence_rm },
|
|
|
|
{ 'm', input_handle_sequence_sgr },
|
2007-10-24 17:29:29 +02:00
|
|
|
{ 'n', input_handle_sequence_dsr },
|
2007-09-30 15:29:28 +02:00
|
|
|
{ 'r', input_handle_sequence_decstbm },
|
2007-09-29 00:47:22 +02:00
|
|
|
};
|
2007-10-24 17:40:59 +02:00
|
|
|
struct screen *s = &ictx->w->screen;
|
|
|
|
u_int i;
|
2007-09-29 00:47:22 +02:00
|
|
|
struct input_arg *iarg;
|
|
|
|
|
2007-09-29 20:48:04 +02:00
|
|
|
log_debug2("-- sq %zu: %hhu (%c): %u [sx=%u, sy=%u, cx=%u, cy=%u]",
|
|
|
|
ictx->off, ch, ch, ARRAY_LENGTH(&ictx->args),
|
2007-10-24 17:40:59 +02:00
|
|
|
s->sx, s->sy, s->cx, s->cy);
|
2007-09-29 00:47:22 +02:00
|
|
|
for (i = 0; i < ARRAY_LENGTH(&ictx->args); i++) {
|
|
|
|
iarg = &ARRAY_ITEM(&ictx->args, i);
|
2007-09-29 16:25:49 +02:00
|
|
|
if (*iarg->data != '\0')
|
|
|
|
log_debug2(" ++ %u: %s", i, iarg->data);
|
2007-09-29 00:47:22 +02:00
|
|
|
}
|
2007-07-09 21:04:12 +02:00
|
|
|
|
2007-09-29 00:47:22 +02:00
|
|
|
/* XXX bsearch? */
|
|
|
|
for (i = 0; i < (sizeof table / sizeof table[0]); i++) {
|
|
|
|
if (table[i].ch == ch) {
|
|
|
|
table[i].fn(ictx);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
log_debug("unknown sq: %c (%hhu %hhu)", ch, ch, ictx->private);
|
2007-07-09 21:04:12 +02:00
|
|
|
}
|
|
|
|
|
2007-09-29 00:47:22 +02:00
|
|
|
void
|
|
|
|
input_handle_sequence_cuu(struct input_ctx *ictx)
|
2007-07-09 21:04:12 +02:00
|
|
|
{
|
2007-10-24 17:40:59 +02:00
|
|
|
struct screen *s = &ictx->w->screen;
|
|
|
|
uint16_t n;
|
2007-07-09 21:04:12 +02:00
|
|
|
|
2007-09-29 00:47:22 +02:00
|
|
|
if (ictx->private != '\0')
|
|
|
|
return;
|
2007-07-09 21:04:12 +02:00
|
|
|
|
2007-09-29 00:47:22 +02:00
|
|
|
if (ARRAY_LENGTH(&ictx->args) > 1)
|
|
|
|
return;
|
|
|
|
if (input_get_argument(ictx, 0, &n, 1) != 0)
|
|
|
|
return;
|
2007-07-09 21:04:12 +02:00
|
|
|
|
2007-10-24 17:40:59 +02:00
|
|
|
if (n == 0 || n > s->cy) {
|
2007-09-29 00:47:22 +02:00
|
|
|
log_debug3("cuu: out of range: %hu", n);
|
|
|
|
return;
|
|
|
|
}
|
2007-07-09 21:04:12 +02:00
|
|
|
|
2007-10-24 17:40:59 +02:00
|
|
|
s->cy -= n;
|
2007-09-29 00:47:22 +02:00
|
|
|
input_store_one(ictx->b, CODE_CURSORUP, n);
|
|
|
|
}
|
2007-07-09 21:04:12 +02:00
|
|
|
|
2007-09-29 00:47:22 +02:00
|
|
|
void
|
|
|
|
input_handle_sequence_cud(struct input_ctx *ictx)
|
|
|
|
{
|
2007-10-24 17:40:59 +02:00
|
|
|
struct screen *s = &ictx->w->screen;
|
|
|
|
uint16_t n;
|
2007-09-29 00:47:22 +02:00
|
|
|
|
|
|
|
if (ictx->private != '\0')
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (ARRAY_LENGTH(&ictx->args) > 1)
|
|
|
|
return;
|
|
|
|
if (input_get_argument(ictx, 0, &n, 1) != 0)
|
|
|
|
return;
|
|
|
|
|
2007-10-24 17:40:59 +02:00
|
|
|
if (n == 0 || n > s->sy - s->cy - 1) {
|
2007-09-29 00:47:22 +02:00
|
|
|
log_debug3("cud: out of range: %hu", n);
|
|
|
|
return;
|
2007-07-09 21:04:12 +02:00
|
|
|
}
|
|
|
|
|
2007-10-24 17:40:59 +02:00
|
|
|
s->cy += n;
|
2007-09-29 00:47:22 +02:00
|
|
|
input_store_one(ictx->b, CODE_CURSORDOWN, n);
|
2007-07-09 21:04:12 +02:00
|
|
|
}
|
|
|
|
|
2007-09-29 00:47:22 +02:00
|
|
|
void
|
|
|
|
input_handle_sequence_cuf(struct input_ctx *ictx)
|
|
|
|
{
|
2007-10-24 17:40:59 +02:00
|
|
|
struct screen *s = &ictx->w->screen;
|
|
|
|
uint16_t n;
|
2007-09-29 00:47:22 +02:00
|
|
|
|
|
|
|
if (ictx->private != '\0')
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (ARRAY_LENGTH(&ictx->args) > 1)
|
|
|
|
return;
|
|
|
|
if (input_get_argument(ictx, 0, &n, 1) != 0)
|
|
|
|
return;
|
|
|
|
|
2007-10-24 17:40:59 +02:00
|
|
|
if (n == 0 || n > s->sx - s->cx - 1) {
|
2007-09-29 00:47:22 +02:00
|
|
|
log_debug3("cuf: out of range: %hu", n);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2007-10-24 17:40:59 +02:00
|
|
|
s->cx += n;
|
2007-09-29 00:47:22 +02:00
|
|
|
input_store_one(ictx->b, CODE_CURSORRIGHT, n);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
input_handle_sequence_cub(struct input_ctx *ictx)
|
2007-07-09 21:04:12 +02:00
|
|
|
{
|
2007-10-24 17:40:59 +02:00
|
|
|
struct screen *s = &ictx->w->screen;
|
|
|
|
uint16_t n;
|
2007-07-09 21:04:12 +02:00
|
|
|
|
2007-09-29 00:47:22 +02:00
|
|
|
if (ictx->private != '\0')
|
|
|
|
return;
|
2007-07-09 21:04:12 +02:00
|
|
|
|
2007-09-29 00:47:22 +02:00
|
|
|
if (ARRAY_LENGTH(&ictx->args) > 1)
|
|
|
|
return;
|
|
|
|
if (input_get_argument(ictx, 0, &n, 1) != 0)
|
|
|
|
return;
|
2007-07-09 21:04:12 +02:00
|
|
|
|
2007-10-24 17:40:59 +02:00
|
|
|
if (n == 0 || n > s->cx) {
|
2007-09-29 00:47:22 +02:00
|
|
|
log_debug3("cub: out of range: %hu", n);
|
|
|
|
return;
|
|
|
|
}
|
2007-07-09 21:04:12 +02:00
|
|
|
|
2007-10-24 17:40:59 +02:00
|
|
|
s->cx -= n;
|
2007-09-29 00:47:22 +02:00
|
|
|
input_store_one(ictx->b, CODE_CURSORLEFT, n);
|
|
|
|
}
|
2007-07-09 21:04:12 +02:00
|
|
|
|
2007-09-29 00:47:22 +02:00
|
|
|
void
|
|
|
|
input_handle_sequence_dch(struct input_ctx *ictx)
|
|
|
|
{
|
2007-10-24 17:40:59 +02:00
|
|
|
struct screen *s = &ictx->w->screen;
|
|
|
|
uint16_t n;
|
2007-09-29 00:47:22 +02:00
|
|
|
|
|
|
|
if (ictx->private != '\0')
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (ARRAY_LENGTH(&ictx->args) > 1)
|
|
|
|
return;
|
|
|
|
if (input_get_argument(ictx, 0, &n, 1) != 0)
|
|
|
|
return;
|
|
|
|
|
2007-10-24 17:40:59 +02:00
|
|
|
if (n == 0 || n > s->sx - s->cx - 1) {
|
2007-09-29 00:47:22 +02:00
|
|
|
log_debug3("dch: out of range: %hu", n);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2007-10-24 17:40:59 +02:00
|
|
|
screen_delete_characters(s, s->cx, s->cy, n);
|
2007-09-29 00:47:22 +02:00
|
|
|
input_store_one(ictx->b, CODE_DELETECHARACTER, n);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
input_handle_sequence_dl(struct input_ctx *ictx)
|
|
|
|
{
|
2007-10-24 17:40:59 +02:00
|
|
|
struct screen *s = &ictx->w->screen;
|
|
|
|
uint16_t n;
|
2007-09-29 00:47:22 +02:00
|
|
|
|
|
|
|
if (ictx->private != '\0')
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (ARRAY_LENGTH(&ictx->args) > 1)
|
|
|
|
return;
|
|
|
|
if (input_get_argument(ictx, 0, &n, 1) != 0)
|
|
|
|
return;
|
|
|
|
|
2007-10-24 17:40:59 +02:00
|
|
|
if (n == 0 || n > s->sy - s->cy - 1) {
|
2007-09-29 00:47:22 +02:00
|
|
|
log_debug3("dl: out of range: %hu", n);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2007-10-24 17:40:59 +02:00
|
|
|
if (n < s->ry_upper || n > s->ry_lower)
|
|
|
|
screen_delete_lines(s, s->cy, n);
|
2007-09-29 20:48:04 +02:00
|
|
|
else
|
2007-10-24 17:40:59 +02:00
|
|
|
screen_delete_lines_region(s, s->cy, n);
|
2007-09-29 00:47:22 +02:00
|
|
|
input_store_one(ictx->b, CODE_DELETELINE, n);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
input_handle_sequence_ich(struct input_ctx *ictx)
|
|
|
|
{
|
2007-10-24 17:40:59 +02:00
|
|
|
struct screen *s = &ictx->w->screen;
|
|
|
|
uint16_t n;
|
2007-09-29 00:47:22 +02:00
|
|
|
|
|
|
|
if (ictx->private != '\0')
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (ARRAY_LENGTH(&ictx->args) > 1)
|
|
|
|
return;
|
|
|
|
if (input_get_argument(ictx, 0, &n, 1) != 0)
|
|
|
|
return;
|
|
|
|
|
2007-10-24 17:40:59 +02:00
|
|
|
if (n == 0 || n > s->sx - s->cx - 1) {
|
2007-09-29 00:47:22 +02:00
|
|
|
log_debug3("ich: out of range: %hu", n);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2007-10-24 17:40:59 +02:00
|
|
|
screen_insert_characters(s, s->cx, s->cy, n);
|
2007-09-29 00:47:22 +02:00
|
|
|
input_store_one(ictx->b, CODE_INSERTCHARACTER, n);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
input_handle_sequence_il(struct input_ctx *ictx)
|
|
|
|
{
|
2007-10-24 17:40:59 +02:00
|
|
|
struct screen *s = &ictx->w->screen;
|
|
|
|
uint16_t n;
|
2007-09-29 00:47:22 +02:00
|
|
|
|
|
|
|
if (ictx->private != '\0')
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (ARRAY_LENGTH(&ictx->args) > 1)
|
|
|
|
return;
|
|
|
|
if (input_get_argument(ictx, 0, &n, 1) != 0)
|
|
|
|
return;
|
|
|
|
|
2007-10-24 17:40:59 +02:00
|
|
|
if (n == 0 || n > s->sy - s->cy - 1) {
|
2007-09-29 00:47:22 +02:00
|
|
|
log_debug3("il: out of range: %hu", n);
|
|
|
|
return;
|
|
|
|
}
|
2007-10-24 17:40:59 +02:00
|
|
|
if (n < s->ry_upper || n > s->ry_lower)
|
|
|
|
screen_insert_lines(s, s->cy, n);
|
2007-09-29 20:48:04 +02:00
|
|
|
else
|
2007-10-24 17:40:59 +02:00
|
|
|
screen_insert_lines_region(s, s->cy, n);
|
2007-09-29 00:47:22 +02:00
|
|
|
input_store_one(ictx->b, CODE_INSERTLINE, n);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
input_handle_sequence_vpa(struct input_ctx *ictx)
|
|
|
|
{
|
2007-10-24 17:40:59 +02:00
|
|
|
struct screen *s = &ictx->w->screen;
|
|
|
|
uint16_t n;
|
2007-09-29 00:47:22 +02:00
|
|
|
|
|
|
|
if (ictx->private != '\0')
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (ARRAY_LENGTH(&ictx->args) > 1)
|
|
|
|
return;
|
|
|
|
if (input_get_argument(ictx, 0, &n, 1) != 0)
|
|
|
|
return;
|
|
|
|
|
2007-10-24 17:40:59 +02:00
|
|
|
if (n == 0 || n > s->sy) {
|
2007-09-29 00:47:22 +02:00
|
|
|
log_debug3("vpa: out of range: %hu", n);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2007-10-24 17:40:59 +02:00
|
|
|
s->cy = n - 1;
|
|
|
|
input_store_two(ictx->b, CODE_CURSORMOVE, n, s->cx + 1);
|
2007-09-29 00:47:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
input_handle_sequence_hpa(struct input_ctx *ictx)
|
|
|
|
{
|
2007-10-24 17:40:59 +02:00
|
|
|
struct screen *s = &ictx->w->screen;
|
|
|
|
uint16_t n;
|
2007-09-29 00:47:22 +02:00
|
|
|
|
|
|
|
if (ictx->private != '\0')
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (ARRAY_LENGTH(&ictx->args) > 1)
|
|
|
|
return;
|
|
|
|
if (input_get_argument(ictx, 0, &n, 1) != 0)
|
|
|
|
return;
|
|
|
|
|
2007-10-24 17:40:59 +02:00
|
|
|
if (n == 0 || n > s->sx) {
|
2007-09-29 00:47:22 +02:00
|
|
|
log_debug3("hpa: out of range: %hu", n);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2007-10-24 17:40:59 +02:00
|
|
|
s->cx = n - 1;
|
|
|
|
input_store_two(ictx->b, CODE_CURSORMOVE, s->cy + 1, n);
|
2007-09-29 00:47:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
input_handle_sequence_cup(struct input_ctx *ictx)
|
|
|
|
{
|
2007-10-24 17:40:59 +02:00
|
|
|
struct screen *s = &ictx->w->screen;
|
|
|
|
uint16_t n, m;
|
2007-09-29 00:47:22 +02:00
|
|
|
|
|
|
|
if (ictx->private != '\0')
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (ARRAY_LENGTH(&ictx->args) > 2)
|
|
|
|
return;
|
|
|
|
if (input_get_argument(ictx, 0, &n, 1) != 0)
|
|
|
|
return;
|
|
|
|
if (input_get_argument(ictx, 1, &m, 1) != 0)
|
|
|
|
return;
|
|
|
|
|
2007-10-24 17:01:25 +02:00
|
|
|
if (n == 0)
|
|
|
|
n = 1;
|
2007-10-24 17:40:59 +02:00
|
|
|
if (n > s->sy)
|
|
|
|
n = s->sy;
|
2007-10-24 17:01:25 +02:00
|
|
|
if (m == 0)
|
|
|
|
m = 1;
|
2007-10-24 17:40:59 +02:00
|
|
|
if (m > s->sx)
|
|
|
|
m = s->sx;
|
2007-09-29 00:47:22 +02:00
|
|
|
|
2007-10-24 17:40:59 +02:00
|
|
|
s->cx = m - 1;
|
|
|
|
s->cy = n - 1;
|
2007-09-29 00:47:22 +02:00
|
|
|
input_store_two(ictx->b, CODE_CURSORMOVE, n, m);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
input_handle_sequence_ed(struct input_ctx *ictx)
|
|
|
|
{
|
2007-10-24 17:40:59 +02:00
|
|
|
struct screen *s = &ictx->w->screen;
|
|
|
|
uint16_t n;
|
|
|
|
u_int i;
|
2007-09-29 00:47:22 +02:00
|
|
|
|
|
|
|
if (ictx->private != '\0')
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (ARRAY_LENGTH(&ictx->args) > 1)
|
|
|
|
return;
|
|
|
|
if (input_get_argument(ictx, 0, &n, 0) != 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (n > 2)
|
|
|
|
return;
|
|
|
|
|
|
|
|
switch (n) {
|
|
|
|
case 0:
|
2007-10-24 17:40:59 +02:00
|
|
|
screen_fill_end_of_screen(
|
|
|
|
s, 0, s->cy, SCREEN_DEFDATA, s->attr, s->colr);
|
2007-09-30 15:29:28 +02:00
|
|
|
input_store_zero(ictx->b, CODE_CLEARLINE);
|
2007-10-24 17:40:59 +02:00
|
|
|
for (i = s->cy + 1; i < s->sy; i++) {
|
2007-09-29 12:57:39 +02:00
|
|
|
input_store_two(ictx->b, CODE_CURSORMOVE, i + 1, 1);
|
2007-09-30 15:29:28 +02:00
|
|
|
input_store_zero(ictx->b, CODE_CLEARLINE);
|
2007-09-29 12:57:39 +02:00
|
|
|
}
|
|
|
|
input_store_two(
|
2007-10-24 17:40:59 +02:00
|
|
|
ictx->b, CODE_CURSORMOVE, s->cy + 1, s->cx + 1);
|
2007-07-09 21:04:12 +02:00
|
|
|
break;
|
2007-09-29 00:47:22 +02:00
|
|
|
case 2:
|
2007-10-24 17:40:59 +02:00
|
|
|
screen_fill_screen(s, SCREEN_DEFDATA, s->attr, s->colr);
|
|
|
|
for (i = 0; i < s->sy; i++) {
|
2007-09-29 12:57:39 +02:00
|
|
|
input_store_two(ictx->b, CODE_CURSORMOVE, i + 1, 1);
|
|
|
|
input_store_zero(ictx->b, CODE_CLEARLINE);
|
|
|
|
}
|
2007-09-30 15:29:28 +02:00
|
|
|
input_store_two(
|
2007-10-24 17:40:59 +02:00
|
|
|
ictx->b, CODE_CURSORMOVE, s->cy + 1, s->cx + 1);
|
2007-07-09 21:04:12 +02:00
|
|
|
break;
|
2007-09-29 00:47:22 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
input_handle_sequence_el(struct input_ctx *ictx)
|
|
|
|
{
|
2007-10-24 17:40:59 +02:00
|
|
|
struct screen *s = &ictx->w->screen;
|
|
|
|
uint16_t n;
|
2007-09-29 00:47:22 +02:00
|
|
|
|
|
|
|
if (ictx->private != '\0')
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (ARRAY_LENGTH(&ictx->args) > 1)
|
|
|
|
return;
|
|
|
|
if (input_get_argument(ictx, 0, &n, 0) != 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (n > 2)
|
|
|
|
return;
|
|
|
|
|
|
|
|
switch (n) {
|
|
|
|
case 0:
|
2007-10-24 17:40:59 +02:00
|
|
|
screen_fill_end_of_line(
|
|
|
|
s, s->cx, s->cy, SCREEN_DEFDATA, s->attr, s->colr);
|
2007-09-29 00:47:22 +02:00
|
|
|
input_store_zero(ictx->b, CODE_CLEARENDOFLINE);
|
2007-07-09 21:04:12 +02:00
|
|
|
break;
|
2007-09-29 00:47:22 +02:00
|
|
|
case 1:
|
2007-10-24 17:40:59 +02:00
|
|
|
screen_fill_start_of_line(
|
|
|
|
s, s->cx, s->cy, SCREEN_DEFDATA, s->attr, s->colr);
|
2007-09-29 00:47:22 +02:00
|
|
|
input_store_zero(ictx->b, CODE_CLEARSTARTOFLINE);
|
2007-07-09 21:04:12 +02:00
|
|
|
break;
|
2007-09-29 00:47:22 +02:00
|
|
|
case 2:
|
2007-10-24 17:40:59 +02:00
|
|
|
screen_fill_line(s, s->cy, SCREEN_DEFDATA, s->attr, s->colr);
|
2007-09-29 00:47:22 +02:00
|
|
|
input_store_zero(ictx->b, CODE_CLEARLINE);
|
2007-07-09 21:04:12 +02:00
|
|
|
break;
|
2007-09-29 00:47:22 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
input_handle_sequence_sm(struct input_ctx *ictx)
|
|
|
|
{
|
2007-10-24 17:40:59 +02:00
|
|
|
struct screen *s = &ictx->w->screen;
|
|
|
|
uint16_t n;
|
2007-09-29 00:47:22 +02:00
|
|
|
|
|
|
|
if (ARRAY_LENGTH(&ictx->args) > 1)
|
|
|
|
return;
|
|
|
|
if (input_get_argument(ictx, 0, &n, 0) != 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (ictx->private == '?') {
|
|
|
|
switch (n) {
|
|
|
|
case 1: /* GATM */
|
2007-10-24 17:40:59 +02:00
|
|
|
s->mode |= MODE_KCURSOR;
|
2007-09-29 00:47:22 +02:00
|
|
|
input_store_zero(ictx->b, CODE_KCURSORON);
|
2007-07-09 21:04:12 +02:00
|
|
|
break;
|
2007-09-29 00:47:22 +02:00
|
|
|
case 25: /* TCEM */
|
2007-10-24 17:40:59 +02:00
|
|
|
s->mode |= MODE_CURSOR;
|
2007-09-29 00:47:22 +02:00
|
|
|
input_store_zero(ictx->b, CODE_CURSORON);
|
2007-07-09 21:04:12 +02:00
|
|
|
break;
|
2007-09-29 00:47:22 +02:00
|
|
|
default:
|
|
|
|
log_debug("unknown SM [%hhu]: %u", ictx->private, n);
|
2007-07-09 21:04:12 +02:00
|
|
|
break;
|
2007-09-29 00:47:22 +02:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
switch (n) {
|
|
|
|
case 4: /* IRM */
|
2007-10-24 17:40:59 +02:00
|
|
|
s->mode |= MODE_INSERT;
|
2007-09-29 00:47:22 +02:00
|
|
|
input_store_zero(ictx->b, CODE_INSERTON);
|
2007-07-09 21:04:12 +02:00
|
|
|
break;
|
2007-09-29 00:47:22 +02:00
|
|
|
case 34:
|
|
|
|
/* Cursor high visibility not supported. */
|
2007-07-09 21:04:12 +02:00
|
|
|
break;
|
2007-09-29 00:47:22 +02:00
|
|
|
default:
|
|
|
|
log_debug("unknown SM [%hhu]: %u", ictx->private, n);
|
2007-07-09 21:04:12 +02:00
|
|
|
break;
|
2007-09-29 00:47:22 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
input_handle_sequence_rm(struct input_ctx *ictx)
|
|
|
|
{
|
2007-10-24 17:40:59 +02:00
|
|
|
struct screen *s = &ictx->w->screen;
|
|
|
|
uint16_t n;
|
2007-09-29 00:47:22 +02:00
|
|
|
|
|
|
|
if (ARRAY_LENGTH(&ictx->args) > 1)
|
|
|
|
return;
|
|
|
|
if (input_get_argument(ictx, 0, &n, 0) != 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (ictx->private == '?') {
|
|
|
|
switch (n) {
|
|
|
|
case 1: /* GATM */
|
2007-10-24 17:40:59 +02:00
|
|
|
s->mode &= ~MODE_KCURSOR;
|
2007-09-29 00:47:22 +02:00
|
|
|
input_store_zero(ictx->b, CODE_KCURSOROFF);
|
2007-07-09 21:04:12 +02:00
|
|
|
break;
|
2007-09-29 00:47:22 +02:00
|
|
|
case 25: /* TCEM */
|
2007-10-24 17:40:59 +02:00
|
|
|
s->mode &= ~MODE_CURSOR;
|
2007-09-29 00:47:22 +02:00
|
|
|
input_store_zero(ictx->b, CODE_CURSOROFF);
|
2007-07-09 21:04:12 +02:00
|
|
|
break;
|
2007-09-29 00:47:22 +02:00
|
|
|
default:
|
|
|
|
log_debug("unknown RM [%hhu]: %u", ictx->private, n);
|
2007-07-09 21:04:12 +02:00
|
|
|
break;
|
|
|
|
}
|
2007-09-29 00:47:22 +02:00
|
|
|
} else if (ictx->private == '\0') {
|
|
|
|
switch (n) {
|
|
|
|
case 4: /* IRM */
|
2007-10-24 17:40:59 +02:00
|
|
|
s->mode &= ~MODE_INSERT;
|
2007-09-29 00:47:22 +02:00
|
|
|
input_store_zero(ictx->b, CODE_INSERTOFF);
|
2007-07-09 21:04:12 +02:00
|
|
|
break;
|
2007-09-29 00:47:22 +02:00
|
|
|
case 34:
|
|
|
|
/* Cursor high visibility not supported. */
|
2007-07-09 21:04:12 +02:00
|
|
|
break;
|
2007-09-29 00:47:22 +02:00
|
|
|
default:
|
|
|
|
log_debug("unknown RM [%hhu]: %u", ictx->private, n);
|
2007-07-09 21:04:12 +02:00
|
|
|
break;
|
|
|
|
}
|
2007-09-29 00:47:22 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-10-24 17:29:29 +02:00
|
|
|
void
|
|
|
|
input_handle_sequence_dsr(struct input_ctx *ictx)
|
|
|
|
{
|
2007-10-24 17:40:59 +02:00
|
|
|
struct screen *s = &ictx->w->screen;
|
|
|
|
uint16_t n;
|
|
|
|
char reply[32];
|
2007-10-24 17:29:29 +02:00
|
|
|
|
|
|
|
if (ARRAY_LENGTH(&ictx->args) > 1)
|
|
|
|
return;
|
|
|
|
if (input_get_argument(ictx, 0, &n, 0) != 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (ictx->private == '\0') {
|
|
|
|
switch (n) {
|
|
|
|
case 6: /* cursor position */
|
|
|
|
xsnprintf(reply, sizeof reply,
|
2007-10-24 17:40:59 +02:00
|
|
|
"\033[%u;%uR", s->cy + 1, s->cx + 1);
|
2007-10-24 17:29:29 +02:00
|
|
|
log_debug("cursor request, reply: %s", reply);
|
|
|
|
buffer_write(ictx->w->out, reply, strlen(reply));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2007-09-29 00:47:22 +02:00
|
|
|
void
|
|
|
|
input_handle_sequence_decstbm(struct input_ctx *ictx)
|
|
|
|
{
|
2007-10-24 17:40:59 +02:00
|
|
|
struct screen *s = &ictx->w->screen;
|
|
|
|
uint16_t n, m;
|
2007-09-29 00:47:22 +02:00
|
|
|
|
|
|
|
if (ictx->private != '\0')
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (ARRAY_LENGTH(&ictx->args) > 2)
|
|
|
|
return;
|
2007-10-24 17:01:25 +02:00
|
|
|
if (input_get_argument(ictx, 0, &n, 0) != 0)
|
2007-09-29 00:47:22 +02:00
|
|
|
return;
|
2007-10-24 17:01:25 +02:00
|
|
|
if (input_get_argument(ictx, 1, &m, 0) != 0)
|
2007-09-29 00:47:22 +02:00
|
|
|
return;
|
|
|
|
|
2007-10-24 17:01:25 +02:00
|
|
|
/* Special case: both zero restores to entire screen. */
|
|
|
|
/* XXX this will catch [0;0r and [;r etc too, is this right? */
|
|
|
|
if (n == 0 && m == 0) {
|
|
|
|
n = 1;
|
2007-10-24 17:40:59 +02:00
|
|
|
m = s->sy;
|
2007-09-29 00:47:22 +02:00
|
|
|
}
|
2007-10-24 17:01:25 +02:00
|
|
|
|
|
|
|
if (n == 0)
|
|
|
|
n = 1;
|
2007-10-24 17:40:59 +02:00
|
|
|
if (n > s->sy)
|
|
|
|
n = s->sy;
|
2007-10-24 17:01:25 +02:00
|
|
|
if (m == 0)
|
|
|
|
m = 1;
|
2007-10-26 19:15:50 +02:00
|
|
|
if (m > s->sy)
|
|
|
|
m = s->sy;
|
2007-10-24 17:01:25 +02:00
|
|
|
|
2007-09-29 19:45:10 +02:00
|
|
|
if (n > m) {
|
|
|
|
log_debug3("decstbm: out of range: %hu,%hu", n, m);
|
2007-09-29 00:47:22 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2007-10-24 17:01:25 +02:00
|
|
|
/* Cursor moves to top-left. */
|
2007-10-24 17:40:59 +02:00
|
|
|
s->cx = 0;
|
|
|
|
s->cy = n - 1;
|
2007-10-24 17:01:25 +02:00
|
|
|
|
2007-10-24 17:40:59 +02:00
|
|
|
s->ry_upper = n - 1;
|
|
|
|
s->ry_lower = m - 1;
|
2007-09-29 00:47:22 +02:00
|
|
|
input_store_two(ictx->b, CODE_SCROLLREGION, n, m);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
input_handle_sequence_sgr(struct input_ctx *ictx)
|
|
|
|
{
|
2007-10-24 17:40:59 +02:00
|
|
|
struct screen *s = &ictx->w->screen;
|
|
|
|
u_int i, n;
|
|
|
|
uint16_t m;
|
2007-09-29 00:47:22 +02:00
|
|
|
|
|
|
|
n = ARRAY_LENGTH(&ictx->args);
|
|
|
|
if (n == 0) {
|
2007-10-24 17:40:59 +02:00
|
|
|
s->attr = 0;
|
|
|
|
s->colr = SCREEN_DEFCOLR;
|
2007-09-29 00:47:22 +02:00
|
|
|
} else {
|
|
|
|
for (i = 0; i < n; i++) {
|
2007-10-01 16:18:42 +02:00
|
|
|
if (input_get_argument(ictx, i, &m, 0) != 0)
|
2007-09-29 00:47:22 +02:00
|
|
|
return;
|
|
|
|
switch (m) {
|
|
|
|
case 0:
|
|
|
|
case 10:
|
2007-10-24 17:40:59 +02:00
|
|
|
s->attr = 0;
|
|
|
|
s->colr = SCREEN_DEFCOLR;
|
2007-07-09 21:04:12 +02:00
|
|
|
break;
|
2007-09-29 00:47:22 +02:00
|
|
|
case 1:
|
2007-10-24 17:40:59 +02:00
|
|
|
s->attr |= ATTR_BRIGHT;
|
2007-07-09 21:04:12 +02:00
|
|
|
break;
|
2007-09-29 00:47:22 +02:00
|
|
|
case 2:
|
2007-10-24 17:40:59 +02:00
|
|
|
s->attr |= ATTR_DIM;
|
2007-07-09 21:04:12 +02:00
|
|
|
break;
|
2007-09-29 00:47:22 +02:00
|
|
|
case 3:
|
2007-10-24 17:40:59 +02:00
|
|
|
s->attr |= ATTR_ITALICS;
|
2007-07-09 21:04:12 +02:00
|
|
|
break;
|
2007-09-29 00:47:22 +02:00
|
|
|
case 4:
|
2007-10-24 17:40:59 +02:00
|
|
|
s->attr |= ATTR_UNDERSCORE;
|
2007-07-09 21:04:12 +02:00
|
|
|
break;
|
2007-09-29 00:47:22 +02:00
|
|
|
case 5:
|
2007-10-24 17:40:59 +02:00
|
|
|
s->attr |= ATTR_BLINK;
|
2007-07-09 21:04:12 +02:00
|
|
|
break;
|
2007-09-29 00:47:22 +02:00
|
|
|
case 7:
|
2007-10-24 17:40:59 +02:00
|
|
|
s->attr |= ATTR_REVERSE;
|
2007-07-09 21:04:12 +02:00
|
|
|
break;
|
2007-09-29 00:47:22 +02:00
|
|
|
case 8:
|
2007-10-24 17:40:59 +02:00
|
|
|
s->attr |= ATTR_HIDDEN;
|
2007-07-09 21:04:12 +02:00
|
|
|
break;
|
2007-09-29 00:47:22 +02:00
|
|
|
case 23:
|
2007-10-24 17:40:59 +02:00
|
|
|
s->attr &= ~ATTR_ITALICS;
|
2007-09-29 00:47:22 +02:00
|
|
|
break;
|
|
|
|
case 24:
|
2007-10-24 17:40:59 +02:00
|
|
|
s->attr &= ~ATTR_UNDERSCORE;
|
2007-09-29 00:47:22 +02:00
|
|
|
break;
|
|
|
|
case 30:
|
|
|
|
case 31:
|
|
|
|
case 32:
|
|
|
|
case 33:
|
2007-07-09 21:04:12 +02:00
|
|
|
case 34:
|
2007-09-29 00:47:22 +02:00
|
|
|
case 35:
|
|
|
|
case 36:
|
|
|
|
case 37:
|
2007-10-24 17:40:59 +02:00
|
|
|
s->colr &= 0x0f;
|
|
|
|
s->colr |= (m - 30) << 4;
|
2007-07-09 21:04:12 +02:00
|
|
|
break;
|
2007-09-29 00:47:22 +02:00
|
|
|
case 39:
|
2007-10-24 17:40:59 +02:00
|
|
|
s->colr &= 0x0f;
|
|
|
|
s->colr |= 0x80;
|
2007-09-29 00:47:22 +02:00
|
|
|
break;
|
|
|
|
case 40:
|
|
|
|
case 41:
|
|
|
|
case 42:
|
|
|
|
case 43:
|
|
|
|
case 44:
|
|
|
|
case 45:
|
|
|
|
case 46:
|
|
|
|
case 47:
|
2007-10-24 17:40:59 +02:00
|
|
|
s->colr &= 0xf0;
|
|
|
|
s->colr |= m - 40;
|
2007-09-29 00:47:22 +02:00
|
|
|
break;
|
|
|
|
case 49:
|
2007-10-24 17:40:59 +02:00
|
|
|
s->colr &= 0xf0;
|
|
|
|
s->colr |= 0x08;
|
2007-07-09 21:04:12 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-10-24 17:40:59 +02:00
|
|
|
input_store_two(ictx->b, CODE_ATTRIBUTES, s->attr, s->colr);
|
2007-07-09 21:04:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
input_store_zero(struct buffer *b, u_char code)
|
|
|
|
{
|
|
|
|
input_store8(b, '\e');
|
|
|
|
input_store8(b, code);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
input_store_one(struct buffer *b, u_char code, uint16_t ua)
|
|
|
|
{
|
|
|
|
input_store8(b, '\e');
|
|
|
|
input_store8(b, code);
|
|
|
|
input_store16(b, ua);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
input_store_two(struct buffer *b, u_char code, uint16_t ua, uint16_t ub)
|
|
|
|
{
|
|
|
|
input_store8(b, '\e');
|
|
|
|
input_store8(b, code);
|
|
|
|
input_store16(b, ua);
|
|
|
|
input_store16(b, ub);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
input_store8(struct buffer *b, uint8_t n)
|
|
|
|
{
|
2007-10-03 02:13:46 +02:00
|
|
|
buffer_ensure(b, 1);
|
|
|
|
BUFFER_IN(b)[0] = n;
|
|
|
|
buffer_add(b, 1);
|
2007-07-09 21:04:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
input_store16(struct buffer *b, uint16_t n)
|
|
|
|
{
|
2007-10-03 02:13:46 +02:00
|
|
|
buffer_ensure(b, 2);
|
|
|
|
BUFFER_IN(b)[0] = n & 0xff;
|
|
|
|
BUFFER_IN(b)[1] = n >> 8;
|
|
|
|
buffer_add(b, 2);
|
2007-07-09 21:04:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
uint8_t
|
|
|
|
input_extract8(struct buffer *b)
|
|
|
|
{
|
|
|
|
uint8_t n;
|
|
|
|
|
2007-10-03 02:13:46 +02:00
|
|
|
n = BUFFER_OUT(b)[0];
|
|
|
|
buffer_remove(b, 1);
|
2007-07-09 21:04:12 +02:00
|
|
|
return (n);
|
|
|
|
}
|
|
|
|
|
|
|
|
uint16_t
|
|
|
|
input_extract16(struct buffer *b)
|
|
|
|
{
|
|
|
|
uint16_t n;
|
|
|
|
|
2007-10-03 02:13:46 +02:00
|
|
|
n = BUFFER_OUT(b)[0] | (BUFFER_OUT(b)[1] << 8);
|
|
|
|
buffer_remove(b, 2);
|
2007-07-09 21:04:12 +02:00
|
|
|
return (n);
|
|
|
|
}
|