Deleted Added
full compact
teken.c (197114) teken.c (197115)
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 197114 2009-09-12 08:19:24Z ed $
26 * $FreeBSD: head/sys/teken/teken.c 197115 2009-09-12 10:34:34Z 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)

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

44 if (df != NULL) \
45 fprintf(df, x, ## __VA_ARGS__); \
46} while (0)
47/* debug messages */
48static FILE *df;
49#endif /* __FreeBSD__ && _KERNEL */
50
51#include "teken.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)

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

44 if (df != NULL) \
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
53#ifdef TEKEN_UTF8
54#include "teken_wcwidth.h"
52#include "teken_wcwidth.h"
55#else /* !TEKEN_UTF8 */
56#ifdef TEKEN_XTERM
57#define teken_wcwidth(c) ((c <= 0x1B) ? -1 : 1)
58#else /* !TEKEN_XTERM */
59#define teken_wcwidth(c) (1)
60#endif /* TEKEN_XTERM */
61#endif /* TEKEN_UTF8 */
62
53
63#if defined(TEKEN_XTERM) && defined(TEKEN_UTF8)
54#ifdef TEKEN_XTERM
64#include "teken_scs.h"
55#include "teken_scs.h"
65#else /* !(TEKEN_XTERM && TEKEN_UTF8) */
56#else /* !TEKEN_XTERM */
66#define teken_scs_process(t, c) (c)
67#define teken_scs_restore(t)
68#define teken_scs_save(t)
69#define teken_scs_set(t, g, ts)
70#define teken_scs_switch(t, g)
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)
71#endif /* TEKEN_XTERM && TEKEN_UTF8 */
62#endif /* TEKEN_XTERM */
72
73/* Private flags for t_stateflags. */
74#define TS_FIRSTDIGIT 0x01 /* First numeric digit in escape sequence. */
75#define TS_INSERT 0x02 /* Insert mode. */
76#define TS_AUTOWRAP 0x04 /* Autowrap. */
77#define TS_ORIGIN 0x08 /* Origin mode. */
78#ifdef TEKEN_XTERM
79#define TS_WRAPPED 0x10 /* Next character should be printed on col 0. */

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

182
183 t->t_nextstate = teken_state_init;
184
185 t->t_defattr.ta_format = 0;
186 t->t_defattr.ta_fgcolor = TC_WHITE;
187 t->t_defattr.ta_bgcolor = TC_BLACK;
188 teken_subr_do_reset(t);
189
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. */
69#ifdef TEKEN_XTERM
70#define TS_WRAPPED 0x10 /* Next character should be printed on col 0. */

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

173
174 t->t_nextstate = teken_state_init;
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
190#ifdef TEKEN_UTF8
191 t->t_utf8_left = 0;
181 t->t_utf8_left = 0;
192#endif /* TEKEN_UTF8 */
193
194 teken_set_winsize(t, &tp);
195}
196
197static void
198teken_input_char(teken_t *t, teken_char_t c)
199{
200

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

209 break;
210 case '\n':
211 case '\x0B':
212 teken_subr_newline(t);
213 break;
214 case '\x0C':
215 teken_subr_newpage(t);
216 break;
182
183 teken_set_winsize(t, &tp);
184}
185
186static void
187teken_input_char(teken_t *t, teken_char_t c)
188{
189

--- 8 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;
217#if defined(TEKEN_XTERM) && defined(TEKEN_UTF8)
206#ifdef TEKEN_XTERM
218 case '\x0E':
219 teken_scs_switch(t, 1);
220 break;
221 case '\x0F':
222 teken_scs_switch(t, 0);
223 break;
207 case '\x0E':
208 teken_scs_switch(t, 1);
209 break;
210 case '\x0F':
211 teken_scs_switch(t, 0);
212 break;
224#endif /* TEKEN_XTERM && TEKEN_UTF8 */
213#endif /* TEKEN_XTERM */
225 case '\r':
226 teken_subr_carriage_return(t);
227 break;
228 case '\t':
229 teken_subr_horizontal_tab(t);
230 break;
231 default:
232 t->t_nextstate(t, c);

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

248 (t->t_originreg.ts_begin == 0 &&
249 t->t_originreg.ts_end == t->t_winsize.tp_row));
250}
251
252static void
253teken_input_byte(teken_t *t, unsigned char c)
254{
255
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);

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

237 (t->t_originreg.ts_begin == 0 &&
238 t->t_originreg.ts_end == t->t_winsize.tp_row));
239}
240
241static void
242teken_input_byte(teken_t *t, unsigned char c)
243{
244
256#ifdef TEKEN_UTF8
257 /*
258 * UTF-8 handling.
259 */
245 /*
246 * UTF-8 handling.
247 */
260 if ((c & 0x80) == 0x00) {
248 if (t->t_utf8_left == -1) {
249 /* UTF-8 disabled. */
250 teken_input_char(t, c);
251 } else if ((c & 0x80) == 0x00) {
261 /* One-byte sequence. */
262 t->t_utf8_left = 0;
263 teken_input_char(t, c);
264 } else if ((c & 0xe0) == 0xc0) {
265 /* Two-byte sequence. */
266 t->t_utf8_left = 1;
267 t->t_utf8_partial = c & 0x1f;
268 } else if ((c & 0xf0) == 0xe0) {

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

278 return;
279 t->t_utf8_left--;
280 t->t_utf8_partial = (t->t_utf8_partial << 6) | (c & 0x3f);
281 if (t->t_utf8_left == 0) {
282 teken_printf("Got UTF-8 char %x\n", t->t_utf8_partial);
283 teken_input_char(t, t->t_utf8_partial);
284 }
285 }
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) {

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

269 return;
270 t->t_utf8_left--;
271 t->t_utf8_partial = (t->t_utf8_partial << 6) | (c & 0x3f);
272 if (t->t_utf8_left == 0) {
273 teken_printf("Got UTF-8 char %x\n", t->t_utf8_partial);
274 teken_input_char(t, t->t_utf8_partial);
275 }
276 }
286#else /* !TEKEN_UTF8 */
287 teken_input_char(t, c);
288#endif /* TEKEN_UTF8 */
289}
290
291void
292teken_input(teken_t *t, const void *buf, size_t len)
293{
294 const char *c = buf;
295
296 while (len-- > 0)

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

339void
340teken_set_winsize(teken_t *t, const teken_pos_t *p)
341{
342
343 t->t_winsize = *p;
344 teken_subr_do_reset(t);
345}
346
277}
278
279void
280teken_input(teken_t *t, const void *buf, size_t len)
281{
282 const char *c = buf;
283
284 while (len-- > 0)

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

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
339 t->t_utf8_left = -1;
340}
341
347/*
348 * State machine.
349 */
350
351static void
352teken_state_switch(teken_t *t, teken_state_t *s)
353{
354

--- 52 unchanged lines hidden ---
342/*
343 * State machine.
344 */
345
346static void
347teken_state_switch(teken_t *t, teken_state_t *s)
348{
349

--- 52 unchanged lines hidden ---