vi: code shrink colon line addresses
Remove some unnecessary code in get_one_address() and rewrite get_address(). function old new delta colon 3325 3604 +279 get_one_address 342 - -342 ------------------------------------------------------------------------------ (add/remove: 0/1 grow/shrink: 1/0 up/down: 279/-342) Total: -63 bytes Signed-off-by: Ron Yorston <rmy@pobox.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
parent
74d565ff1f
commit
5d1bb58b13
49
editors/vi.c
49
editors/vi.c
@ -2345,14 +2345,15 @@ static char *char_search(char *p, const char *pat, int dir_and_range)
|
|||||||
static char *get_one_address(char *p, int *addr) // get colon addr, if present
|
static char *get_one_address(char *p, int *addr) // get colon addr, if present
|
||||||
{
|
{
|
||||||
int st;
|
int st;
|
||||||
|
# if ENABLE_FEATURE_VI_YANKMARK || ENABLE_FEATURE_VI_SEARCH
|
||||||
char *q;
|
char *q;
|
||||||
|
# endif
|
||||||
IF_FEATURE_VI_YANKMARK(char c;)
|
IF_FEATURE_VI_YANKMARK(char c;)
|
||||||
|
|
||||||
*addr = -1; // assume no addr
|
*addr = -1; // assume no addr
|
||||||
if (*p == '.') { // the current line
|
if (*p == '.') { // the current line
|
||||||
p++;
|
p++;
|
||||||
q = begin_line(dot);
|
*addr = count_lines(text, dot);
|
||||||
*addr = count_lines(text, q);
|
|
||||||
}
|
}
|
||||||
# if ENABLE_FEATURE_VI_YANKMARK
|
# if ENABLE_FEATURE_VI_YANKMARK
|
||||||
else if (*p == '\'') { // is this a mark addr
|
else if (*p == '\'') { // is this a mark addr
|
||||||
@ -2389,43 +2390,43 @@ static char *get_one_address(char *p, int *addr) // get colon addr, if present
|
|||||||
# endif
|
# endif
|
||||||
else if (*p == '$') { // the last line in file
|
else if (*p == '$') { // the last line in file
|
||||||
p++;
|
p++;
|
||||||
q = begin_line(end - 1);
|
*addr = count_lines(text, end - 1);
|
||||||
*addr = count_lines(text, q);
|
|
||||||
} else if (isdigit(*p)) { // specific line number
|
} else if (isdigit(*p)) { // specific line number
|
||||||
sscanf(p, "%d%n", addr, &st);
|
sscanf(p, "%d%n", addr, &st);
|
||||||
p += st;
|
p += st;
|
||||||
} else {
|
|
||||||
// unrecognized address - assume -1
|
|
||||||
*addr = -1;
|
|
||||||
}
|
}
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# define GET_FIRST 0
|
||||||
|
# define GET_SECOND 1
|
||||||
|
# define GOT_FIRST 2
|
||||||
|
# define GOT_SECOND 3
|
||||||
|
# define GOT 2
|
||||||
|
|
||||||
static char *get_address(char *p, int *b, int *e) // get two colon addrs, if present
|
static char *get_address(char *p, int *b, int *e) // get two colon addrs, if present
|
||||||
{
|
{
|
||||||
|
int state = GET_FIRST;
|
||||||
|
|
||||||
//----- get the address' i.e., 1,3 'a,'b -----
|
//----- get the address' i.e., 1,3 'a,'b -----
|
||||||
// get FIRST addr, if present
|
for (;;) {
|
||||||
while (isblank(*p))
|
if (isblank(*p)) {
|
||||||
p++; // skip over leading spaces
|
p++;
|
||||||
if (*p == '%') { // alias for 1,$
|
} else if (*p == '%' && state == GET_FIRST) { // alias for 1,$
|
||||||
p++;
|
p++;
|
||||||
*b = 1;
|
*b = 1;
|
||||||
*e = count_lines(text, end-1);
|
*e = count_lines(text, end-1);
|
||||||
goto ga0;
|
state = GOT_SECOND;
|
||||||
|
} else if (*p == ',' && state == GOT_FIRST) {
|
||||||
|
p++;
|
||||||
|
state = GET_SECOND;
|
||||||
|
} else if (state == GET_FIRST || state == GET_SECOND) {
|
||||||
|
p = get_one_address(p, state == GET_FIRST ? b : e);
|
||||||
|
state |= GOT;
|
||||||
|
} else {
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
p = get_one_address(p, b);
|
|
||||||
while (isblank(*p))
|
|
||||||
p++;
|
|
||||||
if (*p == ',') { // is there a address separator
|
|
||||||
p++;
|
|
||||||
while (isblank(*p))
|
|
||||||
p++;
|
|
||||||
// get SECOND addr, if present
|
|
||||||
p = get_one_address(p, e);
|
|
||||||
}
|
}
|
||||||
ga0:
|
|
||||||
while (isblank(*p))
|
|
||||||
p++; // skip over trailing spaces
|
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user