aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNatanael Copa <ncopa@alpinelinux.org>2016-08-14 23:30:29 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2016-08-14 23:30:29 +0200
commit7e6f9316a8bf3030da6c283e43aa0709d0cef259 (patch)
treeec5f4ba877f846b6fff854e2af8507d734edb98b
parent9e5820a86277818c2f83c11c2aa76d7f0a38283e (diff)
downloadbusybox-w32-7e6f9316a8bf3030da6c283e43aa0709d0cef259.tar.gz
busybox-w32-7e6f9316a8bf3030da6c283e43aa0709d0cef259.tar.bz2
busybox-w32-7e6f9316a8bf3030da6c283e43aa0709d0cef259.zip
lineedit: trivial codeshrink for vi-mode
Introduce and use BB_isalnum_or_underscore(). function old new delta BB_isalnum_or_underscore - 43 +43 vi_word_motion 162 150 -12 vi_end_motion 163 145 -18 vi_back_motion 198 179 -19 BB_isalnum 39 - -39 ------------------------------------------------------------------------------ (add/remove: 1/1 grow/shrink: 0/3 up/down: 43/-88) Total: -45 bytes Signed-off-by: Natanael Copa <ncopa@alpinelinux.org> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--libbb/lineedit.c22
1 files changed, 14 insertions, 8 deletions
diff --git a/libbb/lineedit.c b/libbb/lineedit.c
index 3e62f46b4..3bfff0084 100644
--- a/libbb/lineedit.c
+++ b/libbb/lineedit.c
@@ -81,7 +81,9 @@
81# define CHAR_T wchar_t 81# define CHAR_T wchar_t
82static bool BB_isspace(CHAR_T c) { return ((unsigned)c < 256 && isspace(c)); } 82static bool BB_isspace(CHAR_T c) { return ((unsigned)c < 256 && isspace(c)); }
83# if ENABLE_FEATURE_EDITING_VI 83# if ENABLE_FEATURE_EDITING_VI
84static bool BB_isalnum(CHAR_T c) { return ((unsigned)c < 256 && isalnum(c)); } 84static bool BB_isalnum_or_underscore(CHAR_T c) {
85 return ((unsigned)c < 256 && isalnum(c)) || c == '_';
86}
85# endif 87# endif
86static bool BB_ispunct(CHAR_T c) { return ((unsigned)c < 256 && ispunct(c)); } 88static bool BB_ispunct(CHAR_T c) { return ((unsigned)c < 256 && ispunct(c)); }
87# undef isspace 89# undef isspace
@@ -96,7 +98,11 @@ static bool BB_ispunct(CHAR_T c) { return ((unsigned)c < 256 && ispunct(c)); }
96# define BB_NUL '\0' 98# define BB_NUL '\0'
97# define CHAR_T char 99# define CHAR_T char
98# define BB_isspace(c) isspace(c) 100# define BB_isspace(c) isspace(c)
99# define BB_isalnum(c) isalnum(c) 101# if ENABLE_FEATURE_EDITING_VI
102static bool BB_isalnum_or_underscore(CHAR_T c) {
103 return ((unsigned)c < 256 && isalnum(c)) || c == '_';
104}
105# endif
100# define BB_ispunct(c) ispunct(c) 106# define BB_ispunct(c) ispunct(c)
101#endif 107#endif
102#if ENABLE_UNICODE_PRESERVE_BROKEN 108#if ENABLE_UNICODE_PRESERVE_BROKEN
@@ -1586,9 +1592,9 @@ vi_word_motion(int eat)
1586{ 1592{
1587 CHAR_T *command = command_ps; 1593 CHAR_T *command = command_ps;
1588 1594
1589 if (BB_isalnum(command[cursor]) || command[cursor] == '_') { 1595 if (BB_isalnum_or_underscore(command[cursor])) {
1590 while (cursor < command_len 1596 while (cursor < command_len
1591 && (BB_isalnum(command[cursor+1]) || command[cursor+1] == '_') 1597 && (BB_isalnum_or_underscore(command[cursor+1]))
1592 ) { 1598 ) {
1593 input_forward(); 1599 input_forward();
1594 } 1600 }
@@ -1630,9 +1636,9 @@ vi_end_motion(void)
1630 input_forward(); 1636 input_forward();
1631 if (cursor >= command_len-1) 1637 if (cursor >= command_len-1)
1632 return; 1638 return;
1633 if (BB_isalnum(command[cursor]) || command[cursor] == '_') { 1639 if (BB_isalnum_or_underscore(command[cursor])) {
1634 while (cursor < command_len-1 1640 while (cursor < command_len-1
1635 && (BB_isalnum(command[cursor+1]) || command[cursor+1] == '_') 1641 && (BB_isalnum_or_underscore(command[cursor+1]))
1636 ) { 1642 ) {
1637 input_forward(); 1643 input_forward();
1638 } 1644 }
@@ -1665,9 +1671,9 @@ vi_back_motion(void)
1665 input_backward(1); 1671 input_backward(1);
1666 if (cursor <= 0) 1672 if (cursor <= 0)
1667 return; 1673 return;
1668 if (BB_isalnum(command[cursor]) || command[cursor] == '_') { 1674 if (BB_isalnum_or_underscore(command[cursor])) {
1669 while (cursor > 0 1675 while (cursor > 0
1670 && (BB_isalnum(command[cursor-1]) || command[cursor-1] == '_') 1676 && (BB_isalnum_or_underscore(command[cursor-1]))
1671 ) { 1677 ) {
1672 input_backward(1); 1678 input_backward(1);
1673 } 1679 }