teken.c (261551) | teken.c (286798) |
---|---|
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 261551 2014-02-06 13:28:06Z ray $ | 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> | 27 */ 28 29#include <sys/cdefs.h> 30#if defined(__FreeBSD__) && defined(_KERNEL) 31#include <sys/param.h> |
32#include <sys/limits.h> |
|
32#include <sys/lock.h> 33#include <sys/systm.h> 34#define teken_assert(x) MPASS(x) 35#else /* !(__FreeBSD__ && _KERNEL) */ 36#include <sys/types.h> 37#include <assert.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> |
|
38#include <stdint.h> 39#include <stdio.h> 40#include <string.h> 41#define teken_assert(x) assert(x) 42#endif /* __FreeBSD__ && _KERNEL */ 43 44/* debug messages */ 45#define teken_printf(x,...) --- 354 unchanged lines hidden (view full) --- 400 401static int 402teken_state_numbers(teken_t *t, teken_char_t c) 403{ 404 405 teken_assert(t->t_curnum < T_NUMSIZE); 406 407 if (c >= '0' && c <= '9') { | 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') { |
408 /* 409 * Don't do math with the default value of 1 when a 410 * custom number is inserted. 411 */ | |
412 if (t->t_stateflags & TS_FIRSTDIGIT) { | 410 if (t->t_stateflags & TS_FIRSTDIGIT) { |
411 /* First digit. */ |
|
413 t->t_stateflags &= ~TS_FIRSTDIGIT; | 412 t->t_stateflags &= ~TS_FIRSTDIGIT; |
414 t->t_nums[t->t_curnum] = 0; 415 } else { 416 t->t_nums[t->t_curnum] *= 10; | 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'; |
417 } | 424 } |
418 419 t->t_nums[t->t_curnum] += c - '0'; | |
420 return (1); 421 } else if (c == ';') { 422 if (t->t_stateflags & TS_FIRSTDIGIT) 423 t->t_nums[t->t_curnum] = 0; 424 425 /* Only allow a limited set of arguments. */ 426 if (++t->t_curnum == T_NUMSIZE) { 427 teken_state_switch(t, teken_state_init); --- 131 unchanged lines hidden --- | 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 --- |