vi: small code shrink
function old new delta file_insert 328 329 +1 colon 3067 3064 -3 string_insert 93 89 -4 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 1/2 up/down: 1/-7) Total: -6 bytes
This commit is contained in:
parent
b175946ba4
commit
3387538bbe
17
editors/vi.c
17
editors/vi.c
@ -1124,7 +1124,7 @@ static void colon(char *buf)
|
|||||||
}
|
}
|
||||||
#endif /* FEATURE_VI_SEARCH */
|
#endif /* FEATURE_VI_SEARCH */
|
||||||
} else if (strncasecmp(cmd, "version", i) == 0) { // show software version
|
} else if (strncasecmp(cmd, "version", i) == 0) { // show software version
|
||||||
status_line("%s", BB_VER " " BB_BT);
|
status_line(BB_VER " " BB_BT);
|
||||||
} else if (strncasecmp(cmd, "write", i) == 0 // write text to file
|
} else if (strncasecmp(cmd, "write", i) == 0 // write text to file
|
||||||
|| strncasecmp(cmd, "wq", i) == 0
|
|| strncasecmp(cmd, "wq", i) == 0
|
||||||
|| strncasecmp(cmd, "wn", i) == 0
|
|| strncasecmp(cmd, "wn", i) == 0
|
||||||
@ -2035,7 +2035,7 @@ static char *string_insert(char * p, char * s) // insert the string at 'p'
|
|||||||
int cnt, i;
|
int cnt, i;
|
||||||
|
|
||||||
i = strlen(s);
|
i = strlen(s);
|
||||||
if (text_hole_make(p, i)) {
|
text_hole_make(p, i);
|
||||||
strncpy(p, s, i);
|
strncpy(p, s, i);
|
||||||
for (cnt = 0; *s != '\0'; s++) {
|
for (cnt = 0; *s != '\0'; s++) {
|
||||||
if (*s == '\n')
|
if (*s == '\n')
|
||||||
@ -2044,7 +2044,6 @@ static char *string_insert(char * p, char * s) // insert the string at 'p'
|
|||||||
#if ENABLE_FEATURE_VI_YANKMARK
|
#if ENABLE_FEATURE_VI_YANKMARK
|
||||||
status_line("Put %d lines (%d chars) from [%c]", cnt, i, what_reg());
|
status_line("Put %d lines (%d chars) from [%c]", cnt, i, what_reg());
|
||||||
#endif
|
#endif
|
||||||
}
|
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -2404,18 +2403,11 @@ static int file_insert(const char * fn, char *p
|
|||||||
status_line_bold("\"%s\" %s", fn, strerror(errno));
|
status_line_bold("\"%s\" %s", fn, strerror(errno));
|
||||||
goto fi0;
|
goto fi0;
|
||||||
}
|
}
|
||||||
if ((statbuf.st_mode & S_IFREG) == 0) {
|
if (!S_ISREG(statbuf.st_mode)) {
|
||||||
// This is not a regular file
|
// This is not a regular file
|
||||||
status_line_bold("\"%s\" Not a regular file", fn);
|
status_line_bold("\"%s\" Not a regular file", fn);
|
||||||
goto fi0;
|
goto fi0;
|
||||||
}
|
}
|
||||||
/* // this check is done by open()
|
|
||||||
if ((statbuf.st_mode & (S_IRUSR | S_IRGRP | S_IROTH)) == 0) {
|
|
||||||
// dont have any read permissions
|
|
||||||
status_line_bold("\"%s\" Not readable", fn);
|
|
||||||
goto fi0;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
if (p < text || p > end) {
|
if (p < text || p > end) {
|
||||||
status_line_bold("Trying to insert file outside of memory");
|
status_line_bold("Trying to insert file outside of memory");
|
||||||
goto fi0;
|
goto fi0;
|
||||||
@ -2429,8 +2421,6 @@ static int file_insert(const char * fn, char *p
|
|||||||
}
|
}
|
||||||
size = statbuf.st_size;
|
size = statbuf.st_size;
|
||||||
p = text_hole_make(p, size);
|
p = text_hole_make(p, size);
|
||||||
if (p == NULL)
|
|
||||||
goto fi0;
|
|
||||||
cnt = safe_read(fd, p, size);
|
cnt = safe_read(fd, p, size);
|
||||||
if (cnt < 0) {
|
if (cnt < 0) {
|
||||||
status_line_bold("\"%s\" %s", fn, strerror(errno));
|
status_line_bold("\"%s\" %s", fn, strerror(errno));
|
||||||
@ -2458,7 +2448,6 @@ static int file_insert(const char * fn, char *p
|
|||||||
return cnt;
|
return cnt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int file_write(char *fn, char *first, char *last)
|
static int file_write(char *fn, char *first, char *last)
|
||||||
{
|
{
|
||||||
int fd, cnt, charcnt;
|
int fd, cnt, charcnt;
|
||||||
|
Loading…
Reference in New Issue
Block a user