summaryrefslogtreecommitdiffhomepage
path: root/src/bridge/ptyc_term_esi.c
blob: b3e3bf47659786973e1853b4f0a3513fd5fc8dcf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
/*********************************************************/
/*  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);
}