diff options
-rw-r--r-- | src/nvim/fileio.c | 95 | ||||
-rw-r--r-- | src/nvim/testdir/test_spell.vim | 30 |
2 files changed, 95 insertions, 30 deletions
diff --git a/src/nvim/fileio.c b/src/nvim/fileio.c index d0e30ddbd3..7e8a7d1a35 100644 --- a/src/nvim/fileio.c +++ b/src/nvim/fileio.c @@ -4531,48 +4531,83 @@ bool vim_fgets(char_u *buf, int size, FILE *fp) FUNC_ATTR_NONNULL_ALL } /// Read 2 bytes from "fd" and turn them into an int, MSB first. +/// Returns -1 when encountering EOF. int get2c(FILE *fd) { - int n; - - n = getc(fd); - n = (n << 8) + getc(fd); - return n; + const int n = getc(fd); + if (n == EOF) { + return -1; + } + const int c = getc(fd); + if (c == EOF) { + return -1; + } + return (n << 8) + c; } /// Read 3 bytes from "fd" and turn them into an int, MSB first. +/// Returns -1 when encountering EOF. int get3c(FILE *fd) { - int n; - - n = getc(fd); - n = (n << 8) + getc(fd); - n = (n << 8) + getc(fd); - return n; + int n = getc(fd); + if (n == EOF) { + return -1; + } + int c = getc(fd); + if (c == EOF) { + return -1; + } + n = (n << 8) + c; + c = getc(fd); + if (c == EOF) { + return -1; + } + return (n << 8) + c; } /// Read 4 bytes from "fd" and turn them into an int, MSB first. +/// Returns -1 when encountering EOF. int get4c(FILE *fd) { // Use unsigned rather than int otherwise result is undefined // when left-shift sets the MSB. unsigned n; - n = (unsigned)getc(fd); - n = (n << 8) + (unsigned)getc(fd); - n = (n << 8) + (unsigned)getc(fd); - n = (n << 8) + (unsigned)getc(fd); + int c = getc(fd); + if (c == EOF) { + return -1; + } + n = (unsigned)c; + c = getc(fd); + if (c == EOF) { + return -1; + } + n = (n << 8) + (unsigned)c; + c = getc(fd); + if (c == EOF) { + return -1; + } + n = (n << 8) + (unsigned)c; + c = getc(fd); + if (c == EOF) { + return -1; + } + n = (n << 8) + (unsigned)c; return (int)n; } /// Read 8 bytes from `fd` and turn them into a time_t, MSB first. +/// Returns -1 when encountering EOF. time_t get8ctime(FILE *fd) { time_t n = 0; - int i; - for (i = 0; i < 8; i++) { - n = (n << 8) + getc(fd); + for (int i = 0; i < 8; i++) { + const int c = getc(fd); + if (c == EOF) { + return -1; + } + n = (n << 8) + c; } return n; } @@ -5932,19 +5967,19 @@ void au_event_restore(char_u *old_ei) * will be automatically executed for <event> * when editing a file matching <pat>, in * the current group. - * :autocmd <event> <pat> Show the auto-commands associated with + * :autocmd <event> <pat> Show the autocommands associated with * <event> and <pat>. - * :autocmd <event> Show the auto-commands associated with + * :autocmd <event> Show the autocommands associated with * <event>. - * :autocmd Show all auto-commands. - * :autocmd! <event> <pat> <cmd> Remove all auto-commands associated with + * :autocmd Show all autocommands. + * :autocmd! <event> <pat> <cmd> Remove all autocommands associated with * <event> and <pat>, and add the command * <cmd>, for the current group. - * :autocmd! <event> <pat> Remove all auto-commands associated with + * :autocmd! <event> <pat> Remove all autocommands associated with * <event> and <pat> for the current group. - * :autocmd! <event> Remove all auto-commands associated with + * :autocmd! <event> Remove all autocommands associated with * <event> for the current group. - * :autocmd! Remove ALL auto-commands for the current + * :autocmd! Remove ALL autocommands for the current * group. * * Multiple events and patterns may be given separated by commas. Here are @@ -6037,8 +6072,8 @@ void do_autocmd(char_u *arg_in, int forceit) * Print header when showing autocommands. */ if (!forceit && *cmd == NUL) { - /* Highlight title */ - MSG_PUTS_TITLE(_("\n--- Auto-Commands ---")); + // Highlight title + MSG_PUTS_TITLE(_("\n--- Autocommands ---")); } /* @@ -6907,8 +6942,8 @@ static bool apply_autocmds_group(event_T event, char_u *fname, char_u *fname_io, autocmd_match = fname; - /* Don't redraw while doing auto commands. */ - ++RedrawingDisabled; + // Don't redraw while doing autocommands. + RedrawingDisabled++; save_sourcing_name = sourcing_name; sourcing_name = NULL; /* don't free this one */ save_sourcing_lnum = sourcing_lnum; @@ -7119,7 +7154,7 @@ auto_next_pat ( apc->tail, ap->allow_dirs) : ap->buflocal_nr == apc->arg_bufnr) { const char *const name = event_nr2name(apc->event); - s = _("%s Auto commands for \"%s\""); + s = _("%s Autocommands for \"%s\""); const size_t sourcing_name_len = (STRLEN(s) + strlen(name) + ap->patlen + 1); sourcing_name = xmalloc(sourcing_name_len); diff --git a/src/nvim/testdir/test_spell.vim b/src/nvim/testdir/test_spell.vim index a2828b21d2..b3438cc649 100644 --- a/src/nvim/testdir/test_spell.vim +++ b/src/nvim/testdir/test_spell.vim @@ -85,6 +85,36 @@ func Test_spellreall() bwipe! endfunc +func Test_spellinfo() + throw 'skipped: Nvim does not support enc=latin1' + new + + set enc=latin1 spell spelllang=en + call assert_match("^\nfile: .*/runtime/spell/en.latin1.spl\n$", execute('spellinfo')) + + set enc=cp1250 spell spelllang=en + call assert_match("^\nfile: .*/runtime/spell/en.ascii.spl\n$", execute('spellinfo')) + + if has('multi_byte') + set enc=utf-8 spell spelllang=en + call assert_match("^\nfile: .*/runtime/spell/en.utf-8.spl\n$", execute('spellinfo')) + endif + + set enc=latin1 spell spelllang=en_us,en_nz + call assert_match("^\n" . + \ "file: .*/runtime/spell/en.latin1.spl\n" . + \ "file: .*/runtime/spell/en.latin1.spl\n$", execute('spellinfo')) + + set spell spelllang= + call assert_fails('spellinfo', 'E756:') + + set nospell spelllang=en + call assert_fails('spellinfo', 'E756:') + + set enc& spell& spelllang& + bwipe +endfunc + func Test_zz_basic() call LoadAffAndDic(g:test_data_aff1, g:test_data_dic1) call RunGoodBad("wrong OK puts. Test the end", |