|
|
3d2f26 |
/*********************************************************/
|
|
|
3d2f26 |
|
|
|
1f983d |
|
|
|
3d2f26 |
|
|
|
3d2f26 |
/*********************************************************/
|
|
|
3d2f26 |
|
|
|
3d2f26 |
#include <psxtypes/psxtypes.h>
|
|
|
3d2f26 |
|
|
|
3d2f26 |
#include <ptycon/ptycon.h>
|
|
|
3d2f26 |
#include "ptycon_bridge_impl.h"
|
|
|
3d2f26 |
|
|
|
3d2f26 |
|
|
|
3d2f26 |
static ptyc_term_handler csi_illegal_code;
|
|
|
3d2f26 |
static ptyc_term_handler csi_param_decimal_digit;
|
|
|
3d2f26 |
static ptyc_term_handler csi_param_semicolon;
|
|
|
3d2f26 |
|
|
|
3d2f26 |
|
|
|
3d2f26 |
static ptyc_term_handler csi_action_select_sgr;
|
|
|
3d2f26 |
static ptyc_term_handler csi_action_process_params;
|
|
|
3d2f26 |
|
|
|
3d2f26 |
ptyc_term_handler * const ptyc_csi_handlers[PTYC_CSI_ARRAY_SIZE] = {
|
|
|
3d2f26 |
csi_illegal_code,
|
|
|
3d2f26 |
csi_illegal_code,
|
|
|
3d2f26 |
csi_illegal_code,
|
|
|
3d2f26 |
csi_illegal_code,
|
|
|
3d2f26 |
csi_illegal_code,
|
|
|
3d2f26 |
csi_illegal_code,
|
|
|
3d2f26 |
csi_illegal_code,
|
|
|
3d2f26 |
csi_illegal_code,
|
|
|
3d2f26 |
csi_illegal_code,
|
|
|
3d2f26 |
csi_illegal_code,
|
|
|
3d2f26 |
csi_illegal_code,
|
|
|
3d2f26 |
csi_illegal_code,
|
|
|
3d2f26 |
csi_illegal_code,
|
|
|
3d2f26 |
csi_illegal_code,
|
|
|
3d2f26 |
csi_illegal_code,
|
|
|
3d2f26 |
csi_illegal_code,
|
|
|
3d2f26 |
csi_illegal_code,
|
|
|
3d2f26 |
csi_illegal_code,
|
|
|
3d2f26 |
csi_illegal_code,
|
|
|
3d2f26 |
csi_illegal_code,
|
|
|
3d2f26 |
csi_illegal_code,
|
|
|
3d2f26 |
csi_illegal_code,
|
|
|
3d2f26 |
csi_illegal_code,
|
|
|
3d2f26 |
csi_illegal_code,
|
|
|
3d2f26 |
csi_illegal_code,
|
|
|
3d2f26 |
csi_illegal_code,
|
|
|
3d2f26 |
csi_illegal_code,
|
|
|
3d2f26 |
csi_illegal_code,
|
|
|
3d2f26 |
csi_illegal_code,
|
|
|
3d2f26 |
csi_illegal_code,
|
|
|
3d2f26 |
csi_illegal_code,
|
|
|
3d2f26 |
csi_illegal_code,
|
|
|
3d2f26 |
csi_illegal_code,
|
|
|
3d2f26 |
csi_illegal_code,
|
|
|
3d2f26 |
csi_illegal_code,
|
|
|
3d2f26 |
csi_illegal_code,
|
|
|
3d2f26 |
csi_illegal_code,
|
|
|
3d2f26 |
csi_illegal_code,
|
|
|
3d2f26 |
csi_illegal_code,
|
|
|
3d2f26 |
csi_illegal_code,
|
|
|
3d2f26 |
csi_illegal_code,
|
|
|
3d2f26 |
csi_illegal_code,
|
|
|
3d2f26 |
csi_illegal_code,
|
|
|
3d2f26 |
csi_illegal_code,
|
|
|
3d2f26 |
csi_illegal_code,
|
|
|
3d2f26 |
csi_illegal_code,
|
|
|
3d2f26 |
csi_illegal_code,
|
|
|
3d2f26 |
csi_illegal_code,
|
|
|
3d2f26 |
csi_param_decimal_digit,
|
|
|
3d2f26 |
csi_param_decimal_digit,
|
|
|
3d2f26 |
csi_param_decimal_digit,
|
|
|
3d2f26 |
csi_param_decimal_digit,
|
|
|
3d2f26 |
csi_param_decimal_digit,
|
|
|
3d2f26 |
csi_param_decimal_digit,
|
|
|
3d2f26 |
csi_param_decimal_digit,
|
|
|
3d2f26 |
csi_param_decimal_digit,
|
|
|
3d2f26 |
csi_param_decimal_digit,
|
|
|
3d2f26 |
csi_param_decimal_digit,
|
|
|
3d2f26 |
csi_illegal_code,
|
|
|
3d2f26 |
csi_param_semicolon,
|
|
|
3d2f26 |
csi_illegal_code,
|
|
|
3d2f26 |
csi_illegal_code,
|
|
|
3d2f26 |
csi_illegal_code,
|
|
|
3d2f26 |
csi_illegal_code,
|
|
|
3d2f26 |
csi_illegal_code,
|
|
|
3d2f26 |
csi_illegal_code,
|
|
|
3d2f26 |
csi_illegal_code,
|
|
|
3d2f26 |
csi_illegal_code,
|
|
|
3d2f26 |
csi_illegal_code,
|
|
|
3d2f26 |
csi_illegal_code,
|
|
|
3d2f26 |
csi_illegal_code,
|
|
|
3d2f26 |
csi_illegal_code,
|
|
|
3d2f26 |
csi_illegal_code,
|
|
|
3d2f26 |
csi_illegal_code,
|
|
|
3d2f26 |
csi_illegal_code,
|
|
|
3d2f26 |
csi_illegal_code,
|
|
|
3d2f26 |
csi_illegal_code,
|
|
|
3d2f26 |
csi_illegal_code,
|
|
|
3d2f26 |
csi_illegal_code,
|
|
|
3d2f26 |
csi_illegal_code,
|
|
|
3d2f26 |
csi_illegal_code,
|
|
|
3d2f26 |
csi_illegal_code,
|
|
|
3d2f26 |
csi_illegal_code,
|
|
|
3d2f26 |
csi_illegal_code,
|
|
|
3d2f26 |
csi_illegal_code,
|
|
|
3d2f26 |
csi_illegal_code,
|
|
|
3d2f26 |
csi_illegal_code,
|
|
|
3d2f26 |
csi_illegal_code,
|
|
|
3d2f26 |
csi_illegal_code,
|
|
|
3d2f26 |
csi_illegal_code,
|
|
|
3d2f26 |
csi_illegal_code,
|
|
|
3d2f26 |
csi_illegal_code,
|
|
|
3d2f26 |
csi_illegal_code,
|
|
|
3d2f26 |
csi_illegal_code,
|
|
|
3d2f26 |
csi_illegal_code,
|
|
|
3d2f26 |
csi_illegal_code,
|
|
|
3d2f26 |
csi_illegal_code,
|
|
|
3d2f26 |
csi_illegal_code,
|
|
|
3d2f26 |
csi_illegal_code,
|
|
|
3d2f26 |
csi_illegal_code,
|
|
|
3d2f26 |
csi_illegal_code,
|
|
|
3d2f26 |
csi_illegal_code,
|
|
|
3d2f26 |
csi_illegal_code,
|
|
|
3d2f26 |
csi_illegal_code,
|
|
|
3d2f26 |
csi_illegal_code,
|
|
|
3d2f26 |
csi_illegal_code,
|
|
|
3d2f26 |
csi_illegal_code,
|
|
|
3d2f26 |
csi_illegal_code,
|
|
|
3d2f26 |
csi_illegal_code,
|
|
|
3d2f26 |
csi_action_select_sgr,
|
|
|
3d2f26 |
csi_illegal_code
|
|
|
3d2f26 |
};
|
|
|
3d2f26 |
|
|
|
3d2f26 |
|
|
|
3d2f26 |
static void * __fastcall csi_illegal_code(struct ptyc_term_ctx * tctx)
|
|
|
3d2f26 |
{
|
|
|
3d2f26 |
|
|
|
3d2f26 |
return tctx->char_handler;
|
|
|
3d2f26 |
}
|
|
|
3d2f26 |
|
|
|
3d2f26 |
|
|
|
3d2f26 |
static void * __fastcall csi_param_decimal_digit(struct ptyc_term_ctx * tctx)
|
|
|
3d2f26 |
{
|
|
|
3d2f26 |
/* add digit to current control parameter */
|
|
|
3d2f26 |
*tctx->ctrl_param *= 10;
|
|
|
3d2f26 |
*tctx->ctrl_param += *tctx->wch_pty - '0';
|
|
|
3d2f26 |
|
|
|
3d2f26 |
|
|
|
3d2f26 |
tctx->wch_pty++;
|
|
|
3d2f26 |
|
|
|
3d2f26 |
|
|
|
3d2f26 |
return tctx->ctrl_handler;
|
|
|
3d2f26 |
}
|
|
|
3d2f26 |
|
|
|
3d2f26 |
|
|
|
3d2f26 |
static void * __fastcall csi_param_semicolon(struct ptyc_term_ctx * tctx)
|
|
|
3d2f26 |
{
|
|
|
3d2f26 |
|
|
|
3d2f26 |
if (tctx->ctrl_param == &tctx->ctrl_params[PTYC_CTRL_PARAMS-1])
|
|
|
3d2f26 |
return csi_illegal_code(tctx);
|
|
|
3d2f26 |
|
|
|
3d2f26 |
|
|
|
3d2f26 |
tctx->ctrl_param++;
|
|
|
3d2f26 |
*tctx->ctrl_param = 0;
|
|
|
3d2f26 |
|
|
|
3d2f26 |
|
|
|
3d2f26 |
tctx->wch_pty++;
|
|
|
3d2f26 |
|
|
|
3d2f26 |
|
|
|
3d2f26 |
return tctx->ctrl_handler;
|
|
|
3d2f26 |
}
|
|
|
3d2f26 |
|
|
|
3d2f26 |
|
|
|
3d2f26 |
static void * __fastcall csi_action_invoke(
|
|
|
3d2f26 |
struct ptyc_term_ctx * tctx,
|
|
|
3d2f26 |
ptyc_term_handler * const * handlers,
|
|
|
3d2f26 |
unsigned int ctrl_cap)
|
|
|
3d2f26 |
{
|
|
|
3d2f26 |
|
|
|
3d2f26 |
tctx->ctrl_state = PTYC_CTRL_STATE_COMMAND_HANDLERS;
|
|
|
3d2f26 |
tctx->ctrl_handlers[tctx->ctrl_state] = handlers;
|
|
|
3d2f26 |
|
|
|
3d2f26 |
|
|
|
3d2f26 |
tctx->ctrl_cap = ctrl_cap;
|
|
|
3d2f26 |
|
|
|
3d2f26 |
|
|
|
3d2f26 |
tctx->ctrl_command = csi_action_process_params;
|
|
|
3d2f26 |
|
|
|
3d2f26 |
|
|
|
3d2f26 |
tctx->ctrl_command(tctx);
|
|
|
3d2f26 |
|
|
|
3d2f26 |
|
|
|
3d2f26 |
tctx->wch_pty++;
|
|
|
3d2f26 |
|
|
|
3d2f26 |
|
|
|
3d2f26 |
return tctx->char_handler;
|
|
|
3d2f26 |
}
|
|
|
3d2f26 |
|
|
|
3d2f26 |
|
|
|
3d2f26 |
static void * __fastcall csi_action_select_sgr(struct ptyc_term_ctx * tctx)
|
|
|
3d2f26 |
{
|
|
|
e4c2ac |
return csi_action_invoke(tctx,ptyc_sgr_handlers,PTYC_SGR_ARRAY_SIZE);
|
|
|
3d2f26 |
}
|
|
|
3d2f26 |
|
|
|
3d2f26 |
static void * __fastcall csi_action_process_params(struct ptyc_term_ctx * tctx)
|
|
|
3d2f26 |
{
|
|
|
3d2f26 |
ptyc_term_handler * pfn_action;
|
|
|
3d2f26 |
unsigned int action_idx;
|
|
|
3d2f26 |
|
|
|
3d2f26 |
tctx->ctrl_mark = tctx->ctrl_params;
|
|
|
3d2f26 |
|
|
|
3d2f26 |
while (tctx->ctrl_mark <= tctx->ctrl_param) {
|
|
|
3d2f26 |
action_idx = (*tctx->ctrl_mark < tctx->ctrl_cap)
|
|
|
3d2f26 |
? *tctx->ctrl_mark
|
|
|
3d2f26 |
: tctx->ctrl_cap - 1;
|
|
|
3d2f26 |
|
|
|
3d2f26 |
pfn_action = tctx->ctrl_handlers[tctx->ctrl_state][action_idx];
|
|
|
3d2f26 |
pfn_action(tctx);
|
|
|
3d2f26 |
|
|
|
3d2f26 |
tctx->ctrl_mark++;
|
|
|
3d2f26 |
}
|
|
|
3d2f26 |
|
|
|
3d2f26 |
/* return value not used */
|
|
|
3d2f26 |
return tctx->ctrl_mark;
|
|
|
3d2f26 |
}
|