aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2018-11-29 14:39:52 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2018-11-29 14:39:52 +0100
commitb7330460693f12585c7a6246f0dfafd8742af05a (patch)
tree01ccf4acb1fa7e2e7575513b7b9f1c6f1a41ad53
parent836d0a7ee450893e7479b5f93a501454582955a2 (diff)
downloadbusybox-w32-b7330460693f12585c7a6246f0dfafd8742af05a.tar.gz
busybox-w32-b7330460693f12585c7a6246f0dfafd8742af05a.tar.bz2
busybox-w32-b7330460693f12585c7a6246f0dfafd8742af05a.zip
vi: code shrink
function old new delta char_search 241 247 +6 get_one_address 275 272 -3 colon 2878 2875 -3 do_cmd 4726 4720 -6 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 1/3 up/down: 6/-12) Total: -6 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--editors/vi.c30
1 files changed, 17 insertions, 13 deletions
diff --git a/editors/vi.c b/editors/vi.c
index bff47250d..ee3c7feb2 100644
--- a/editors/vi.c
+++ b/editors/vi.c
@@ -561,7 +561,7 @@ static void indicate_error(void); // use flash or beep to indicate error
561static void Hit_Return(void); 561static void Hit_Return(void);
562 562
563#if ENABLE_FEATURE_VI_SEARCH 563#if ENABLE_FEATURE_VI_SEARCH
564static char *char_search(char *, const char *, int, int); // search for pattern starting at p 564static char *char_search(char *, const char *, int); // search for pattern starting at p
565#endif 565#endif
566#if ENABLE_FEATURE_VI_COLON 566#if ENABLE_FEATURE_VI_COLON
567static char *get_one_address(char *, int *); // get colon addr, if present 567static char *get_one_address(char *, int *); // get colon addr, if present
@@ -938,7 +938,7 @@ static char *get_one_address(char *p, int *addr) // get colon addr, if present
938 p = q; 938 p = q;
939 if (*p == '/') 939 if (*p == '/')
940 p++; 940 p++;
941 q = char_search(dot, pat, FORWARD, FULL); 941 q = char_search(dot, pat, (FORWARD << 1) | FULL);
942 if (q != NULL) { 942 if (q != NULL) {
943 *addr = count_lines(text, q); 943 *addr = count_lines(text, q);
944 } 944 }
@@ -1442,7 +1442,7 @@ static void colon(char *buf)
1442 char *ls = q; // orig line start 1442 char *ls = q; // orig line start
1443 char *found; 1443 char *found;
1444 vc4: 1444 vc4:
1445 found = char_search(q, F, FORWARD, LIMITED); // search cur line only for "find" 1445 found = char_search(q, F, (FORWARD << 1) | LIMITED); // search cur line only for "find"
1446 if (found) { 1446 if (found) {
1447 uintptr_t bias; 1447 uintptr_t bias;
1448 // we found the "find" pattern - delete it 1448 // we found the "find" pattern - delete it
@@ -1895,13 +1895,14 @@ static char *new_screen(int ro, int co)
1895# if ENABLE_FEATURE_VI_REGEX_SEARCH 1895# if ENABLE_FEATURE_VI_REGEX_SEARCH
1896 1896
1897// search for pattern starting at p 1897// search for pattern starting at p
1898static char *char_search(char *p, const char *pat, int dir, int range) 1898static char *char_search(char *p, const char *pat, int dir_and_range)
1899{ 1899{
1900 struct re_pattern_buffer preg; 1900 struct re_pattern_buffer preg;
1901 const char *err; 1901 const char *err;
1902 char *q; 1902 char *q;
1903 int i; 1903 int i;
1904 int size; 1904 int size;
1905 int range;
1905 1906
1906 re_syntax_options = RE_SYNTAX_POSIX_EXTENDED; 1907 re_syntax_options = RE_SYNTAX_POSIX_EXTENDED;
1907 if (ignorecase) 1908 if (ignorecase)
@@ -1914,10 +1915,11 @@ static char *char_search(char *p, const char *pat, int dir, int range)
1914 return p; 1915 return p;
1915 } 1916 }
1916 1917
1918 range = (dir_and_range & 1);
1917 q = end - 1; // if FULL 1919 q = end - 1; // if FULL
1918 if (range == LIMITED) 1920 if (range == LIMITED)
1919 q = next_line(p); 1921 q = next_line(p);
1920 if (dir == BACK) { 1922 if (dir_and_range < 0) { // BACK?
1921 q = text; 1923 q = text;
1922 if (range == LIMITED) 1924 if (range == LIMITED)
1923 q = prev_line(p); 1925 q = prev_line(p);
@@ -1945,7 +1947,7 @@ static char *char_search(char *p, const char *pat, int dir, int range)
1945 regfree(&preg); 1947 regfree(&preg);
1946 if (i < 0) 1948 if (i < 0)
1947 return NULL; 1949 return NULL;
1948 if (dir == FORWARD) 1950 if (dir_and_range > 0) // FORWARD?
1949 p = p + i; 1951 p = p + i;
1950 else 1952 else
1951 p = p - i; 1953 p = p - i;
@@ -1966,13 +1968,15 @@ static int mycmp(const char *s1, const char *s2, int len)
1966# define mycmp strncmp 1968# define mycmp strncmp
1967# endif 1969# endif
1968 1970
1969static char *char_search(char *p, const char *pat, int dir, int range) 1971static char *char_search(char *p, const char *pat, int dir_and_range)
1970{ 1972{
1971 char *start, *stop; 1973 char *start, *stop;
1972 int len; 1974 int len;
1975 int range;
1973 1976
1974 len = strlen(pat); 1977 len = strlen(pat);
1975 if (dir == FORWARD) { 1978 range = (dir_and_range & 1);
1979 if (dir_and_range > 0) { //FORWARD?
1976 stop = end - 1; // assume range is p..end-1 1980 stop = end - 1; // assume range is p..end-1
1977 if (range == LIMITED) 1981 if (range == LIMITED)
1978 stop = next_line(p); // range is to next line 1982 stop = next_line(p); // range is to next line
@@ -1981,7 +1985,7 @@ static char *char_search(char *p, const char *pat, int dir, int range)
1981 return start; 1985 return start;
1982 } 1986 }
1983 } 1987 }
1984 } else if (dir == BACK) { 1988 } else { //BACK
1985 stop = text; // assume range is text..p 1989 stop = text; // assume range is text..p
1986 if (range == LIMITED) 1990 if (range == LIMITED)
1987 stop = prev_line(p); // range is to prev line 1991 stop = prev_line(p); // range is to prev line
@@ -3818,7 +3822,7 @@ static void do_cmd(int c)
3818 p = dot - 1; 3822 p = dot - 1;
3819 } 3823 }
3820 dc4: 3824 dc4:
3821 q = char_search(p, last_search_pattern + 1, dir, FULL); 3825 q = char_search(p, last_search_pattern + 1, (dir << 1) | FULL);
3822 if (q != NULL) { 3826 if (q != NULL) {
3823 dot = q; // good search, update "dot" 3827 dot = q; // good search, update "dot"
3824 msg = NULL; 3828 msg = NULL;
@@ -3829,7 +3833,7 @@ static void do_cmd(int c)
3829 if (dir == BACK) { 3833 if (dir == BACK) {
3830 p = end - 1; 3834 p = end - 1;
3831 } 3835 }
3832 q = char_search(p, last_search_pattern + 1, dir, FULL); 3836 q = char_search(p, last_search_pattern + 1, (dir << 1) | FULL);
3833 if (q != NULL) { // found something 3837 if (q != NULL) { // found something
3834 dot = q; // found new pattern- goto it 3838 dot = q; // found new pattern- goto it
3835 msg = "search hit BOTTOM, continuing at TOP"; 3839 msg = "search hit BOTTOM, continuing at TOP";
@@ -3845,13 +3849,13 @@ static void do_cmd(int c)
3845 } while (--cmdcnt > 0); 3849 } while (--cmdcnt > 0);
3846 break; 3850 break;
3847 case '{': // {- move backward paragraph 3851 case '{': // {- move backward paragraph
3848 q = char_search(dot, "\n\n", BACK, FULL); 3852 q = char_search(dot, "\n\n", (BACK << 1) | FULL);
3849 if (q != NULL) { // found blank line 3853 if (q != NULL) { // found blank line
3850 dot = next_line(q); // move to next blank line 3854 dot = next_line(q); // move to next blank line
3851 } 3855 }
3852 break; 3856 break;
3853 case '}': // }- move forward paragraph 3857 case '}': // }- move forward paragraph
3854 q = char_search(dot, "\n\n", FORWARD, FULL); 3858 q = char_search(dot, "\n\n", (FORWARD << 1) | FULL);
3855 if (q != NULL) { // found blank line 3859 if (q != NULL) { // found blank line
3856 dot = next_line(q); // move to next blank line 3860 dot = next_line(q); // move to next blank line
3857 } 3861 }