Deleted Added
full compact
teken.c (197116) teken.c (197117)
1/*-
2 * Copyright (c) 2008-2009 Ed Schouten <ed@FreeBSD.org>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 9 unchanged lines hidden (view full) ---

18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 *
1/*-
2 * Copyright (c) 2008-2009 Ed Schouten <ed@FreeBSD.org>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 9 unchanged lines hidden (view full) ---

18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 *
26 * $FreeBSD: head/sys/teken/teken.c 197116 2009-09-12 10:41:32Z ed $
26 * $FreeBSD: head/sys/teken/teken.c 197117 2009-09-12 12:44:21Z ed $
27 */
28
29#include <sys/cdefs.h>
30#if defined(__FreeBSD__) && defined(_KERNEL)
31#include <sys/param.h>
32#include <sys/lock.h>
33#include <sys/systm.h>
34#define teken_assert(x) MPASS(x)

--- 10 unchanged lines hidden (view full) ---

45 fprintf(df, x, ## __VA_ARGS__); \
46} while (0)
47/* debug messages */
48static FILE *df;
49#endif /* __FreeBSD__ && _KERNEL */
50
51#include "teken.h"
52#include "teken_wcwidth.h"
27 */
28
29#include <sys/cdefs.h>
30#if defined(__FreeBSD__) && defined(_KERNEL)
31#include <sys/param.h>
32#include <sys/lock.h>
33#include <sys/systm.h>
34#define teken_assert(x) MPASS(x)

--- 10 unchanged lines hidden (view full) ---

45 fprintf(df, x, ## __VA_ARGS__); \
46} while (0)
47/* debug messages */
48static FILE *df;
49#endif /* __FreeBSD__ && _KERNEL */
50
51#include "teken.h"
52#include "teken_wcwidth.h"
53
54#ifdef TEKEN_XTERM
55#include "teken_scs.h"
53#include "teken_scs.h"
56#else /* !TEKEN_XTERM */
57#define teken_scs_process(t, c) (c)
58#define teken_scs_restore(t)
59#define teken_scs_save(t)
60#define teken_scs_set(t, g, ts)
61#define teken_scs_switch(t, g)
62#endif /* TEKEN_XTERM */
63
64/* Private flags for t_stateflags. */
65#define TS_FIRSTDIGIT 0x01 /* First numeric digit in escape sequence. */
66#define TS_INSERT 0x02 /* Insert mode. */
67#define TS_AUTOWRAP 0x04 /* Autowrap. */
68#define TS_ORIGIN 0x08 /* Origin mode. */
54
55/* Private flags for t_stateflags. */
56#define TS_FIRSTDIGIT 0x01 /* First numeric digit in escape sequence. */
57#define TS_INSERT 0x02 /* Insert mode. */
58#define TS_AUTOWRAP 0x04 /* Autowrap. */
59#define TS_ORIGIN 0x08 /* Origin mode. */
69#ifdef TEKEN_XTERM
70#define TS_WRAPPED 0x10 /* Next character should be printed on col 0. */
60#define TS_WRAPPED 0x10 /* Next character should be printed on col 0. */
71#else /* !TEKEN_XTERM */
72#define TS_WRAPPED 0x00 /* Simple line wrapping. */
73#endif /* TEKEN_XTERM */
61#define TS_8BIT 0x20 /* UTF-8 disabled. */
62#define TS_CONS25 0x40 /* cons25 emulation. */
74
75/* Character that blanks a cell. */
76#define BLANK ' '
77
78static teken_state_t teken_state_init;
79
80/*
81 * Wrappers for hooks.

--- 85 unchanged lines hidden (view full) ---

167 if (df != NULL)
168 setvbuf(df, NULL, _IOLBF, BUFSIZ);
169#endif /* !(__FreeBSD__ && _KERNEL) */
170
171 t->t_funcs = tf;
172 t->t_softc = softc;
173
174 t->t_nextstate = teken_state_init;
63
64/* Character that blanks a cell. */
65#define BLANK ' '
66
67static teken_state_t teken_state_init;
68
69/*
70 * Wrappers for hooks.

--- 85 unchanged lines hidden (view full) ---

156 if (df != NULL)
157 setvbuf(df, NULL, _IOLBF, BUFSIZ);
158#endif /* !(__FreeBSD__ && _KERNEL) */
159
160 t->t_funcs = tf;
161 t->t_softc = softc;
162
163 t->t_nextstate = teken_state_init;
164 t->t_stateflags = 0;
165 t->t_utf8_left = 0;
175
176 t->t_defattr.ta_format = 0;
177 t->t_defattr.ta_fgcolor = TC_WHITE;
178 t->t_defattr.ta_bgcolor = TC_BLACK;
179 teken_subr_do_reset(t);
180
166
167 t->t_defattr.ta_format = 0;
168 t->t_defattr.ta_fgcolor = TC_WHITE;
169 t->t_defattr.ta_bgcolor = TC_BLACK;
170 teken_subr_do_reset(t);
171
181 t->t_utf8_left = 0;
182
183 teken_set_winsize(t, &tp);
184}
185
186static void
187teken_input_char(teken_t *t, teken_char_t c)
188{
189
190 switch (c) {

--- 7 unchanged lines hidden (view full) ---

198 break;
199 case '\n':
200 case '\x0B':
201 teken_subr_newline(t);
202 break;
203 case '\x0C':
204 teken_subr_newpage(t);
205 break;
172 teken_set_winsize(t, &tp);
173}
174
175static void
176teken_input_char(teken_t *t, teken_char_t c)
177{
178
179 switch (c) {

--- 7 unchanged lines hidden (view full) ---

187 break;
188 case '\n':
189 case '\x0B':
190 teken_subr_newline(t);
191 break;
192 case '\x0C':
193 teken_subr_newpage(t);
194 break;
206#ifdef TEKEN_XTERM
207 case '\x0E':
195 case '\x0E':
208 teken_scs_switch(t, 1);
196 if (t->t_stateflags & TS_CONS25)
197 t->t_nextstate(t, c);
198 else
199 teken_scs_switch(t, 1);
209 break;
210 case '\x0F':
200 break;
201 case '\x0F':
211 teken_scs_switch(t, 0);
202 if (t->t_stateflags & TS_CONS25)
203 t->t_nextstate(t, c);
204 else
205 teken_scs_switch(t, 0);
212 break;
206 break;
213#endif /* TEKEN_XTERM */
214 case '\r':
215 teken_subr_carriage_return(t);
216 break;
217 case '\t':
218 teken_subr_horizontal_tab(t);
219 break;
220 default:
221 t->t_nextstate(t, c);

--- 18 unchanged lines hidden (view full) ---

240
241static void
242teken_input_byte(teken_t *t, unsigned char c)
243{
244
245 /*
246 * UTF-8 handling.
247 */
207 case '\r':
208 teken_subr_carriage_return(t);
209 break;
210 case '\t':
211 teken_subr_horizontal_tab(t);
212 break;
213 default:
214 t->t_nextstate(t, c);

--- 18 unchanged lines hidden (view full) ---

233
234static void
235teken_input_byte(teken_t *t, unsigned char c)
236{
237
238 /*
239 * UTF-8 handling.
240 */
248 if (t->t_utf8_left == -1) {
249 /* UTF-8 disabled. */
250 teken_input_char(t, c);
251 } else if ((c & 0x80) == 0x00) {
241 if ((c & 0x80) == 0x00 || t->t_stateflags & TS_8BIT) {
252 /* One-byte sequence. */
253 t->t_utf8_left = 0;
254 teken_input_char(t, c);
255 } else if ((c & 0xe0) == 0xc0) {
256 /* Two-byte sequence. */
257 t->t_utf8_left = 1;
258 t->t_utf8_partial = c & 0x1f;
259 } else if ((c & 0xf0) == 0xe0) {

--- 20 unchanged lines hidden (view full) ---

280teken_input(teken_t *t, const void *buf, size_t len)
281{
282 const char *c = buf;
283
284 while (len-- > 0)
285 teken_input_byte(t, *c++);
286}
287
242 /* One-byte sequence. */
243 t->t_utf8_left = 0;
244 teken_input_char(t, c);
245 } else if ((c & 0xe0) == 0xc0) {
246 /* Two-byte sequence. */
247 t->t_utf8_left = 1;
248 t->t_utf8_partial = c & 0x1f;
249 } else if ((c & 0xf0) == 0xe0) {

--- 20 unchanged lines hidden (view full) ---

270teken_input(teken_t *t, const void *buf, size_t len)
271{
272 const char *c = buf;
273
274 while (len-- > 0)
275 teken_input_byte(t, *c++);
276}
277
278const teken_pos_t *
279teken_get_cursor(teken_t *t)
280{
281
282 return (&t->t_cursor);
283}
284
288void
289teken_set_cursor(teken_t *t, const teken_pos_t *p)
290{
291
292 /* XXX: bounds checking with originreg! */
293 teken_assert(p->tp_row < t->t_winsize.tp_row);
294 teken_assert(p->tp_col < t->t_winsize.tp_col);
295

--- 23 unchanged lines hidden (view full) ---

319
320void
321teken_set_defattr(teken_t *t, const teken_attr_t *a)
322{
323
324 t->t_curattr = t->t_saved_curattr = t->t_defattr = *a;
325}
326
285void
286teken_set_cursor(teken_t *t, const teken_pos_t *p)
287{
288
289 /* XXX: bounds checking with originreg! */
290 teken_assert(p->tp_row < t->t_winsize.tp_row);
291 teken_assert(p->tp_col < t->t_winsize.tp_col);
292

--- 23 unchanged lines hidden (view full) ---

316
317void
318teken_set_defattr(teken_t *t, const teken_attr_t *a)
319{
320
321 t->t_curattr = t->t_saved_curattr = t->t_defattr = *a;
322}
323
324const teken_pos_t *
325teken_get_winsize(teken_t *t)
326{
327
328 return (&t->t_winsize);
329}
330
327void
328teken_set_winsize(teken_t *t, const teken_pos_t *p)
329{
330
331 t->t_winsize = *p;
332 teken_subr_do_reset(t);
333}
334
335void
336teken_set_8bit(teken_t *t)
337{
338
331void
332teken_set_winsize(teken_t *t, const teken_pos_t *p)
333{
334
335 t->t_winsize = *p;
336 teken_subr_do_reset(t);
337}
338
339void
340teken_set_8bit(teken_t *t)
341{
342
339 t->t_utf8_left = -1;
343 t->t_stateflags |= TS_8BIT;
340}
341
344}
345
346void
347teken_set_cons25(teken_t *t)
348{
349
350 t->t_stateflags |= TS_CONS25;
351}
352
342/*
343 * State machine.
344 */
345
346static void
347teken_state_switch(teken_t *t, teken_state_t *s)
348{
349

--- 52 unchanged lines hidden ---
353/*
354 * State machine.
355 */
356
357static void
358teken_state_switch(teken_t *t, teken_state_t *s)
359{
360

--- 52 unchanged lines hidden ---