summaryrefslogtreecommitdiff
path: root/editors
diff options
context:
space:
mode:
authorDenys Vlasenko2018-11-29 14:39:52 +0100
committerDenys Vlasenko2018-11-29 14:39:52 +0100
commitb7330460693f12585c7a6246f0dfafd8742af05a (patch)
tree01ccf4acb1fa7e2e7575513b7b9f1c6f1a41ad53 /editors
parent836d0a7ee450893e7479b5f93a501454582955a2 (diff)
downloadbusybox-b7330460693f12585c7a6246f0dfafd8742af05a.zip
busybox-b7330460693f12585c7a6246f0dfafd8742af05a.tar.gz
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>
Diffstat (limited to 'editors')
-rw-r--r--editors/vi.c30
1 files changed, 17 insertions, 13 deletions
diff --git a/editors/vi.c b/editors/vi.c
index bff4725..ee3c7fe 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
static void Hit_Return(void);
#if ENABLE_FEATURE_VI_SEARCH
-static char *char_search(char *, const char *, int, int); // search for pattern starting at p
+static char *char_search(char *, const char *, int); // search for pattern starting at p
#endif
#if ENABLE_FEATURE_VI_COLON
static 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
p = q;
if (*p == '/')
p++;
- q = char_search(dot, pat, FORWARD, FULL);
+ q = char_search(dot, pat, (FORWARD << 1) | FULL);
if (q != NULL) {
*addr = count_lines(text, q);
}
@@ -1442,7 +1442,7 @@ static void colon(char *buf)
char *ls = q; // orig line start
char *found;
vc4:
- found = char_search(q, F, FORWARD, LIMITED); // search cur line only for "find"
+ found = char_search(q, F, (FORWARD << 1) | LIMITED); // search cur line only for "find"
if (found) {
uintptr_t bias;
// we found the "find" pattern - delete it
@@ -1895,13 +1895,14 @@ static char *new_screen(int ro, int co)
# if ENABLE_FEATURE_VI_REGEX_SEARCH
// search for pattern starting at p
-static char *char_search(char *p, const char *pat, int dir, int range)
+static char *char_search(char *p, const char *pat, int dir_and_range)
{
struct re_pattern_buffer preg;
const char *err;
char *q;
int i;
int size;
+ int range;
re_syntax_options = RE_SYNTAX_POSIX_EXTENDED;
if (ignorecase)
@@ -1914,10 +1915,11 @@ static char *char_search(char *p, const char *pat, int dir, int range)
return p;
}
+ range = (dir_and_range & 1);
q = end - 1; // if FULL
if (range == LIMITED)
q = next_line(p);
- if (dir == BACK) {
+ if (dir_and_range < 0) { // BACK?
q = text;
if (range == LIMITED)
q = prev_line(p);
@@ -1945,7 +1947,7 @@ static char *char_search(char *p, const char *pat, int dir, int range)
regfree(&preg);
if (i < 0)
return NULL;
- if (dir == FORWARD)
+ if (dir_and_range > 0) // FORWARD?
p = p + i;
else
p = p - i;
@@ -1966,13 +1968,15 @@ static int mycmp(const char *s1, const char *s2, int len)
# define mycmp strncmp
# endif
-static char *char_search(char *p, const char *pat, int dir, int range)
+static char *char_search(char *p, const char *pat, int dir_and_range)
{
char *start, *stop;
int len;
+ int range;
len = strlen(pat);
- if (dir == FORWARD) {
+ range = (dir_and_range & 1);
+ if (dir_and_range > 0) { //FORWARD?
stop = end - 1; // assume range is p..end-1
if (range == LIMITED)
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)
return start;
}
}
- } else if (dir == BACK) {
+ } else { //BACK
stop = text; // assume range is text..p
if (range == LIMITED)
stop = prev_line(p); // range is to prev line
@@ -3818,7 +3822,7 @@ static void do_cmd(int c)
p = dot - 1;
}
dc4:
- q = char_search(p, last_search_pattern + 1, dir, FULL);
+ q = char_search(p, last_search_pattern + 1, (dir << 1) | FULL);
if (q != NULL) {
dot = q; // good search, update "dot"
msg = NULL;
@@ -3829,7 +3833,7 @@ static void do_cmd(int c)
if (dir == BACK) {
p = end - 1;
}
- q = char_search(p, last_search_pattern + 1, dir, FULL);
+ q = char_search(p, last_search_pattern + 1, (dir << 1) | FULL);
if (q != NULL) { // found something
dot = q; // found new pattern- goto it
msg = "search hit BOTTOM, continuing at TOP";
@@ -3845,13 +3849,13 @@ static void do_cmd(int c)
} while (--cmdcnt > 0);
break;
case '{': // {- move backward paragraph
- q = char_search(dot, "\n\n", BACK, FULL);
+ q = char_search(dot, "\n\n", (BACK << 1) | FULL);
if (q != NULL) { // found blank line
dot = next_line(q); // move to next blank line
}
break;
case '}': // }- move forward paragraph
- q = char_search(dot, "\n\n", FORWARD, FULL);
+ q = char_search(dot, "\n\n", (FORWARD << 1) | FULL);
if (q != NULL) { // found blank line
dot = next_line(q); // move to next blank line
}