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>
This commit is contained in:
parent
836d0a7ee4
commit
b733046069
30
editors/vi.c
30
editors/vi.c
@ -561,7 +561,7 @@ static void indicate_error(void); // use flash or beep to indicate error
|
|||||||
static void Hit_Return(void);
|
static void Hit_Return(void);
|
||||||
|
|
||||||
#if ENABLE_FEATURE_VI_SEARCH
|
#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
|
#endif
|
||||||
#if ENABLE_FEATURE_VI_COLON
|
#if ENABLE_FEATURE_VI_COLON
|
||||||
static char *get_one_address(char *, int *); // get colon addr, if present
|
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;
|
p = q;
|
||||||
if (*p == '/')
|
if (*p == '/')
|
||||||
p++;
|
p++;
|
||||||
q = char_search(dot, pat, FORWARD, FULL);
|
q = char_search(dot, pat, (FORWARD << 1) | FULL);
|
||||||
if (q != NULL) {
|
if (q != NULL) {
|
||||||
*addr = count_lines(text, q);
|
*addr = count_lines(text, q);
|
||||||
}
|
}
|
||||||
@ -1442,7 +1442,7 @@ static void colon(char *buf)
|
|||||||
char *ls = q; // orig line start
|
char *ls = q; // orig line start
|
||||||
char *found;
|
char *found;
|
||||||
vc4:
|
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) {
|
if (found) {
|
||||||
uintptr_t bias;
|
uintptr_t bias;
|
||||||
// we found the "find" pattern - delete it
|
// 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
|
# if ENABLE_FEATURE_VI_REGEX_SEARCH
|
||||||
|
|
||||||
// search for pattern starting at p
|
// 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;
|
struct re_pattern_buffer preg;
|
||||||
const char *err;
|
const char *err;
|
||||||
char *q;
|
char *q;
|
||||||
int i;
|
int i;
|
||||||
int size;
|
int size;
|
||||||
|
int range;
|
||||||
|
|
||||||
re_syntax_options = RE_SYNTAX_POSIX_EXTENDED;
|
re_syntax_options = RE_SYNTAX_POSIX_EXTENDED;
|
||||||
if (ignorecase)
|
if (ignorecase)
|
||||||
@ -1914,10 +1915,11 @@ static char *char_search(char *p, const char *pat, int dir, int range)
|
|||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
range = (dir_and_range & 1);
|
||||||
q = end - 1; // if FULL
|
q = end - 1; // if FULL
|
||||||
if (range == LIMITED)
|
if (range == LIMITED)
|
||||||
q = next_line(p);
|
q = next_line(p);
|
||||||
if (dir == BACK) {
|
if (dir_and_range < 0) { // BACK?
|
||||||
q = text;
|
q = text;
|
||||||
if (range == LIMITED)
|
if (range == LIMITED)
|
||||||
q = prev_line(p);
|
q = prev_line(p);
|
||||||
@ -1945,7 +1947,7 @@ static char *char_search(char *p, const char *pat, int dir, int range)
|
|||||||
regfree(&preg);
|
regfree(&preg);
|
||||||
if (i < 0)
|
if (i < 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
if (dir == FORWARD)
|
if (dir_and_range > 0) // FORWARD?
|
||||||
p = p + i;
|
p = p + i;
|
||||||
else
|
else
|
||||||
p = p - i;
|
p = p - i;
|
||||||
@ -1966,13 +1968,15 @@ static int mycmp(const char *s1, const char *s2, int len)
|
|||||||
# define mycmp strncmp
|
# define mycmp strncmp
|
||||||
# endif
|
# 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;
|
char *start, *stop;
|
||||||
int len;
|
int len;
|
||||||
|
int range;
|
||||||
|
|
||||||
len = strlen(pat);
|
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
|
stop = end - 1; // assume range is p..end-1
|
||||||
if (range == LIMITED)
|
if (range == LIMITED)
|
||||||
stop = next_line(p); // range is to next line
|
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;
|
return start;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (dir == BACK) {
|
} else { //BACK
|
||||||
stop = text; // assume range is text..p
|
stop = text; // assume range is text..p
|
||||||
if (range == LIMITED)
|
if (range == LIMITED)
|
||||||
stop = prev_line(p); // range is to prev line
|
stop = prev_line(p); // range is to prev line
|
||||||
@ -3818,7 +3822,7 @@ static void do_cmd(int c)
|
|||||||
p = dot - 1;
|
p = dot - 1;
|
||||||
}
|
}
|
||||||
dc4:
|
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) {
|
if (q != NULL) {
|
||||||
dot = q; // good search, update "dot"
|
dot = q; // good search, update "dot"
|
||||||
msg = NULL;
|
msg = NULL;
|
||||||
@ -3829,7 +3833,7 @@ static void do_cmd(int c)
|
|||||||
if (dir == BACK) {
|
if (dir == BACK) {
|
||||||
p = end - 1;
|
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
|
if (q != NULL) { // found something
|
||||||
dot = q; // found new pattern- goto it
|
dot = q; // found new pattern- goto it
|
||||||
msg = "search hit BOTTOM, continuing at TOP";
|
msg = "search hit BOTTOM, continuing at TOP";
|
||||||
@ -3845,13 +3849,13 @@ static void do_cmd(int c)
|
|||||||
} while (--cmdcnt > 0);
|
} while (--cmdcnt > 0);
|
||||||
break;
|
break;
|
||||||
case '{': // {- move backward paragraph
|
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
|
if (q != NULL) { // found blank line
|
||||||
dot = next_line(q); // move to next blank line
|
dot = next_line(q); // move to next blank line
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case '}': // }- move forward paragraph
|
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
|
if (q != NULL) { // found blank line
|
||||||
dot = next_line(q); // move to next blank line
|
dot = next_line(q); // move to next blank line
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user