vi: code shrink

function                                             old     new   delta
status_line_bold_errno                                 -      32     +32
colon                                               2891    2873     -18
file_insert                                          354     313     -41
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 0/2 up/down: 32/-59)            Total: -27 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
Denys Vlasenko 2013-03-15 02:17:29 +01:00
parent cb5aa725df
commit 9e7c002182

View File

@ -478,6 +478,7 @@ static void flash(int); // flash the terminal screen
static void show_status_line(void); // put a message on the bottom line static void show_status_line(void); // put a message on the bottom line
static void status_line(const char *, ...); // print to status buf static void status_line(const char *, ...); // print to status buf
static void status_line_bold(const char *, ...); static void status_line_bold(const char *, ...);
static void status_line_bold_errno(const char *fn);
static void not_implemented(const char *); // display "Not implemented" message static void not_implemented(const char *); // display "Not implemented" message
static int format_edit_status(void); // format file status on status line static int format_edit_status(void); // format file status on status line
static void redraw(int); // force a full screen refresh static void redraw(int); // force a full screen refresh
@ -1321,7 +1322,7 @@ static void colon(char *buf)
} }
if (l < 0) { if (l < 0) {
if (l == -1) if (l == -1)
status_line_bold("'%s' %s", fn, strerror(errno)); status_line_bold_errno(fn);
} else { } else {
status_line("'%s' %dL, %dC", fn, li, l); status_line("'%s' %dL, %dC", fn, li, l);
if (q == text && r == end - 1 && l == ch) { if (q == text && r == end - 1 && l == ch) {
@ -2503,7 +2504,7 @@ static int file_insert(const char *fn, char *p, int update_ro_status)
/* Validate file */ /* Validate file */
if (stat(fn, &statbuf) < 0) { if (stat(fn, &statbuf) < 0) {
status_line_bold("'%s' %s", fn, strerror(errno)); status_line_bold_errno(fn);
goto fi0; goto fi0;
} }
if (!S_ISREG(statbuf.st_mode)) { if (!S_ISREG(statbuf.st_mode)) {
@ -2519,14 +2520,14 @@ static int file_insert(const char *fn, char *p, int update_ro_status)
// read file to buffer // read file to buffer
fd = open(fn, O_RDONLY); fd = open(fn, O_RDONLY);
if (fd < 0) { if (fd < 0) {
status_line_bold("'%s' %s", fn, strerror(errno)); status_line_bold_errno(fn);
goto fi0; goto fi0;
} }
size = (statbuf.st_size < INT_MAX ? (int)statbuf.st_size : INT_MAX); size = (statbuf.st_size < INT_MAX ? (int)statbuf.st_size : INT_MAX);
p += text_hole_make(p, size); p += text_hole_make(p, size);
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_errno(fn);
p = text_hole_delete(p, p + size - 1); // un-do buffer insert p = text_hole_delete(p, p + size - 1); // un-do buffer insert
} else if (cnt < size) { } else if (cnt < size) {
// There was a partial read, shrink unused space text[] // There was a partial read, shrink unused space text[]
@ -2717,6 +2718,11 @@ static void status_line_bold(const char *format, ...)
have_status_msg = 1 + sizeof(ESC_BOLD_TEXT) + sizeof(ESC_NORM_TEXT) - 2; have_status_msg = 1 + sizeof(ESC_BOLD_TEXT) + sizeof(ESC_NORM_TEXT) - 2;
} }
static void status_line_bold_errno(const char *fn)
{
status_line_bold("'%s' %s", fn, strerror(errno));
}
// format status buffer // format status buffer
static void status_line(const char *format, ...) static void status_line(const char *format, ...)
{ {