/*********************************************************/
/* ptycon: a pty-console bridge */
/* Copyright (C) 2016 Z. Gilboa */
/* Released under GPLv2 and GPLv3; see COPYING.PTYCON. */
/*********************************************************/
#include <psxtypes/psxtypes.h>
#include <ptycon/ptycon.h>
#include "ptycon_bridge_impl.h"
/* forward declarations */
static ptyc_term_handler esi_illegal_code;
static ptyc_term_handler esi_left_bracket;
static ptyc_term_handler esi_right_bracket;
static ptyc_term_handler esi_left_parenthesis;
static ptyc_term_handler esi_right_parenthesis;
ptyc_term_handler * const ptyc_esi_handlers[PTYC_ESI_ARRAY_SIZE] = {
esi_illegal_code, /* 0x00 */
esi_illegal_code, /* 0x01 */
esi_illegal_code, /* 0x02 */
esi_illegal_code, /* 0x03 */
esi_illegal_code, /* 0x04 */
esi_illegal_code, /* 0x05 */
esi_illegal_code, /* 0x06 */
esi_illegal_code, /* 0x07 */
esi_illegal_code, /* 0x08 */
esi_illegal_code, /* 0x09 */
esi_illegal_code, /* 0x0a */
esi_illegal_code, /* 0x0b */
esi_illegal_code, /* 0x0c */
esi_illegal_code, /* 0x0d */
esi_illegal_code, /* 0x0e */
esi_illegal_code, /* 0x0f */
esi_illegal_code, /* 0x10 */
esi_illegal_code, /* 0x11 */
esi_illegal_code, /* 0x12 */
esi_illegal_code, /* 0x13 */
esi_illegal_code, /* 0x14 */
esi_illegal_code, /* 0x15 */
esi_illegal_code, /* 0x16 */
esi_illegal_code, /* 0x17 */
esi_illegal_code, /* 0x18 */
esi_illegal_code, /* 0x19 */
esi_illegal_code, /* 0x1a */
esi_illegal_code, /* 0x1b */
esi_illegal_code, /* 0x1c */
esi_illegal_code, /* 0x1d */
esi_illegal_code, /* 0x1e */
esi_illegal_code, /* 0x1f */
esi_illegal_code, /* 0x20 */
esi_illegal_code, /* 0x21 */
esi_illegal_code, /* 0x22 */
esi_illegal_code, /* 0x23 */
esi_illegal_code, /* 0x24 */
esi_illegal_code, /* 0x25 */
esi_illegal_code, /* 0x26 */
esi_illegal_code, /* 0x27 */
esi_left_parenthesis, /* 0x28 */ /* TODO: */
esi_right_parenthesis, /* 0x29 */ /* TODO: */
esi_illegal_code, /* 0x2a */
esi_illegal_code, /* 0x2b */
esi_illegal_code, /* 0x2c */
esi_illegal_code, /* 0x2d */
esi_illegal_code, /* 0x2e */
esi_illegal_code, /* 0x2f */
esi_illegal_code, /* 0x30 */
esi_illegal_code, /* 0x31 */
esi_illegal_code, /* 0x32 */
esi_illegal_code, /* 0x33 */
esi_illegal_code, /* 0x34 */
esi_illegal_code, /* 0x35 */
esi_illegal_code, /* 0x36 */
esi_illegal_code, /* 0x37 */
esi_illegal_code, /* 0x38 */
esi_illegal_code, /* 0x39 */
esi_illegal_code, /* 0x3a */
esi_illegal_code, /* 0x3b */
esi_illegal_code, /* 0x3c */
esi_illegal_code, /* 0x3d */
esi_illegal_code, /* 0x3e */
esi_illegal_code, /* 0x3f */
esi_illegal_code, /* 0x40 */
esi_illegal_code, /* 0x41 */
esi_illegal_code, /* 0x42 */
esi_illegal_code, /* 0x43 */
esi_illegal_code, /* 0x44 */
esi_illegal_code, /* 0x45 */
esi_illegal_code, /* 0x46 */
esi_illegal_code, /* 0x47 */
esi_illegal_code, /* 0x48 */
esi_illegal_code, /* 0x49 */
esi_illegal_code, /* 0x4a */
esi_illegal_code, /* 0x4b */
esi_illegal_code, /* 0x4c */
esi_illegal_code, /* 0x4d */
esi_illegal_code, /* 0x4e */
esi_illegal_code, /* 0x4f */
esi_illegal_code, /* 0x50 */
esi_illegal_code, /* 0x51 */
esi_illegal_code, /* 0x52 */
esi_illegal_code, /* 0x53 */
esi_illegal_code, /* 0x54 */
esi_illegal_code, /* 0x55 */
esi_illegal_code, /* 0x56 */
esi_illegal_code, /* 0x57 */
esi_illegal_code, /* 0x58 */
esi_illegal_code, /* 0x59 */
esi_illegal_code, /* 0x5a */
esi_left_bracket, /* 0x5b */ /* CSI */
esi_illegal_code, /* 0x5c */
esi_right_bracket, /* 0x5d */ /* TODO: */
esi_illegal_code /* 0x5e */
};
static void * __fastcall esi_illegal_code(struct ptyc_term_ctx * tctx)
{
/* defer to the screen handler routine */
return tctx->char_handler;
}
static void * __fastcall esi_select(
struct ptyc_term_ctx * tctx,
ptyc_term_handler * const * handlers,
unsigned int ctrl_cap)
{
/* set state to param handlers */
tctx->ctrl_state = PTYC_CTRL_STATE_PARAM_HANDLERS;
/* select param handler array */
tctx->ctrl_handlers[tctx->ctrl_state] = handlers;
tctx->ctrl_cap = ctrl_cap;
/* prepare to read the first ctrl param */
tctx->ctrl_param = tctx->ctrl_params;
tctx->ctrl_params[0] = 0;
/* advance the stream pointer */
tctx->wch_pty++;
/* retain mode */
return tctx->ctrl_handler;
}
static void * __fastcall esi_left_bracket(struct ptyc_term_ctx * tctx)
{
return esi_select(tctx,ptyc_csi_handlers,PTYC_CSI_ARRAY_SIZE);
}
static void * __fastcall esi_right_bracket(struct ptyc_term_ctx * tctx)
{
/* todo: */
return esi_illegal_code(tctx);
}
static void * __fastcall esi_left_parenthesis(struct ptyc_term_ctx * tctx)
{
/* todo: */
return esi_illegal_code(tctx);
}
static void * __fastcall esi_right_parenthesis(struct ptyc_term_ctx * tctx)
{
/* todo: */
return esi_illegal_code(tctx);
}