/* $Id: input.c,v 1.6 2007-09-28 22:47:21 nicm Exp $ */
/*
* 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>
#include <string.h>
#include <stdlib.h>
#include "tmux.h"
struct {
u_char first;
u_char last;
enum input_class class;
} input_table[] = {
{ 0x00, 0x1f, INPUT_C0CONTROL },
{ 0x20, 0x20, INPUT_SPACE },
{ 0x21, 0x2F, INPUT_INTERMEDIATE }, /* also INPUT_SPACE */
{ 0x30, 0x3F, INPUT_PARAMETER },
{ 0x40, 0x5F, INPUT_UPPERCASE },
{ 0x60, 0x7E, INPUT_LOWERCASE },
{ 0x7F, 0x7F, INPUT_DELETE },
{ 0x80, 0x9F, INPUT_C1CONTROL },
{ 0xA0, 0xA0, INPUT_SPACE },
{ 0xA1, 0xFE, INPUT_G1DISPLAYABLE },
{ 0xFF, 0xFF, INPUT_SPECIAL },
};
#define NINPUTCLASS (sizeof input_table / sizeof input_table[0])
enum input_class input_lookup_class(u_char);
int input_get_argument(struct input_ctx *, u_int, uint16_t *, uint16_t);
void *input_state_first(u_char, enum input_class, struct input_ctx *);
void *input_state_escape(u_char, enum input_class, struct input_ctx *);
void *input_state_intermediate(u_char, enum input_class, struct input_ctx *);
void *input_state_sequence_first(
u_char, enum input_class, struct input_ctx *);
void *input_state_sequence_next(
u_char, enum input_class, struct input_ctx *);
void *input_state_sequence_intermediate(
u_char, enum input_class, struct input_ctx *);
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 *);
enum input_class
input_lookup_class(u_char ch)
{
enum input_class iclass;
u_int i;
iclass = INPUT_SPACE;
for (i = 0; i < NINPUTCLASS; i++) {
if (ch >= input_table[i].first && ch <= input_table[i].last) {
iclass = input_table[i].class;
break;
}
}
if (i == NINPUTCLASS)
fatalx("character without class");
return (iclass);
}
int
input_get_argument(struct input_ctx