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 286798 2015-08-15 08:42:33Z ed $ |
27 */ 28 29#include <sys/cdefs.h> 30#if defined(__FreeBSD__) && defined(_KERNEL) 31#include <sys/param.h> |
32#include <sys/limits.h> |
33#include <sys/lock.h> 34#include <sys/systm.h> 35#define teken_assert(x) MPASS(x) 36#else /* !(__FreeBSD__ && _KERNEL) */ 37#include <sys/types.h> 38#include <assert.h> |
39#include <limits.h> |
40#include <stdint.h> 41#include <stdio.h> 42#include <string.h> 43#define teken_assert(x) assert(x) 44#endif /* __FreeBSD__ && _KERNEL */ 45 46/* debug messages */ 47#define teken_printf(x,...) --- 354 unchanged lines hidden (view full) --- 402 403static int 404teken_state_numbers(teken_t *t, teken_char_t c) 405{ 406 407 teken_assert(t->t_curnum < T_NUMSIZE); 408 409 if (c >= '0' && c <= '9') { |
410 if (t->t_stateflags & TS_FIRSTDIGIT) { |
411 /* First digit. */ |
412 t->t_stateflags &= ~TS_FIRSTDIGIT; |
413 t->t_nums[t->t_curnum] = c - '0'; 414 } else if (t->t_nums[t->t_curnum] < USHRT_MAX) { 415 /* 416 * Screen positions are stored as unsigned 417 * shorts. There is no need to continue parsing 418 * input once the value exceeds USHRT_MAX. It 419 * would only allow for integer overflows when 420 * performing arithmetic on the cursor position. 421 */ 422 t->t_nums[t->t_curnum] = 423 t->t_nums[t->t_curnum] * 10 + c - '0'; |
424 } |
425 return (1); 426 } else if (c == ';') { 427 if (t->t_stateflags & TS_FIRSTDIGIT) 428 t->t_nums[t->t_curnum] = 0; 429 430 /* Only allow a limited set of arguments. */ 431 if (++t->t_curnum == T_NUMSIZE) { 432 teken_state_switch(t, teken_state_init); --- 131 unchanged lines hidden --- |