diff options
author | dundargoc <33953936+dundargoc@users.noreply.github.com> | 2021-09-29 19:48:50 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-09-29 19:48:50 +0200 |
commit | d90fb1c0bfc1e64c783c385a79e7de87013dadba (patch) | |
tree | 5a27261e9aed7ebdb95122fc888811ea5f903cc8 | |
parent | ec4731d982031e363a59efd4566fc72234bb43c8 (diff) | |
download | rneovim-d90fb1c0bfc1e64c783c385a79e7de87013dadba.tar.gz rneovim-d90fb1c0bfc1e64c783c385a79e7de87013dadba.tar.bz2 rneovim-d90fb1c0bfc1e64c783c385a79e7de87013dadba.zip |
Refactor/uncrustify (#15790)
* refactor: format with uncrustify
* fixup(dundar): fix functions comments
* fixup(dundar): remove space between variable and ++/--
* fixup(dundar): better workaround for macro attributes
This is done to be able to better use uncrustify rules for macros
* fixup(justin): make preprocessors follow neovim style guide
37 files changed, 2366 insertions, 1940 deletions
diff --git a/src/nvim/api/private/dispatch.c b/src/nvim/api/private/dispatch.c index 38ce7ca78c..5e93ccce17 100644 --- a/src/nvim/api/private/dispatch.c +++ b/src/nvim/api/private/dispatch.c @@ -45,5 +45,5 @@ MsgpackRpcRequestHandler msgpack_rpc_get_handler_for(const char *name, size_t na } #ifdef INCLUDE_GENERATED_DECLARATIONS -#include "api/private/dispatch_wrappers.generated.h" +# include "api/private/dispatch_wrappers.generated.h" #endif diff --git a/src/nvim/autocmd.c b/src/nvim/autocmd.c index 67b2b8954d..e7b2ad9000 100644 --- a/src/nvim/autocmd.c +++ b/src/nvim/autocmd.c @@ -24,8 +24,8 @@ #include "nvim/vim.h" #ifdef INCLUDE_GENERATED_DECLARATIONS -#include "auevents_name_map.generated.h" -#include "autocmd.c.generated.h" +# include "auevents_name_map.generated.h" +# include "autocmd.c.generated.h" #endif // diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c index 54b5f8283f..3c86f55260 100644 --- a/src/nvim/buffer.c +++ b/src/nvim/buffer.c @@ -3429,14 +3429,14 @@ void resettitle(void) ui_flush(); } -# if defined(EXITFREE) +#if defined(EXITFREE) void free_titles(void) { xfree(lasttitle); xfree(lasticon); } -# endif +#endif /// Enumeration specifying the valid numeric bases that can /// be used when printing numbers in the status line. diff --git a/src/nvim/decoration.c b/src/nvim/decoration.c index 7e2b6a666e..561be9968a 100644 --- a/src/nvim/decoration.c +++ b/src/nvim/decoration.c @@ -37,7 +37,7 @@ void bufhl_add_hl_pos_offset(buf_T *buf, int src_id, int hl_id, lpos_T pos_start decor->priority = DECOR_PRIORITY_BASE; // TODO(bfredl): if decoration had blocky mode, we could avoid this loop - for (linenr_T lnum = pos_start.lnum; lnum <= pos_end.lnum; lnum ++) { + for (linenr_T lnum = pos_start.lnum; lnum <= pos_end.lnum; lnum++) { int end_off = 0; if (pos_start.lnum < lnum && lnum < pos_end.lnum) { // TODO(bfredl): This is quite ad-hoc, but the space between |num| and diff --git a/src/nvim/edit.c b/src/nvim/edit.c index 085bbc2409..45edbec4a6 100644 --- a/src/nvim/edit.c +++ b/src/nvim/edit.c @@ -5681,7 +5681,7 @@ static void insert_special(int c, int allow_modmask, int ctrlv) * stop and defer processing to the "normal" mechanism. * '0' and '^' are special, because they can be followed by CTRL-D. */ -# define ISSPECIAL(c) ((c) < ' ' || (c) >= DEL || (c) == '0' || (c) == '^') +#define ISSPECIAL(c) ((c) < ' ' || (c) >= DEL || (c) == '0' || (c) == '^') #define WHITECHAR(cc) ( \ ascii_iswhite(cc) \ diff --git a/src/nvim/eval/funcs.c b/src/nvim/eval/funcs.c index 9feecadb6f..6a1afafdac 100644 --- a/src/nvim/eval/funcs.c +++ b/src/nvim/eval/funcs.c @@ -80,16 +80,16 @@ KHASH_MAP_INIT_STR(functions, VimLFuncDef) #ifdef INCLUDE_GENERATED_DECLARATIONS # include "eval/funcs.c.generated.h" -#ifdef _MSC_VER +# ifdef _MSC_VER // This prevents MSVC from replacing the functions with intrinsics, // and causing errors when trying to get their addresses in funcs.generated.h -#pragma function(ceil) -#pragma function(floor) -#endif +# pragma function(ceil) +# pragma function(floor) +# endif PRAGMA_DIAG_PUSH_IGNORE_MISSING_PROTOTYPES PRAGMA_DIAG_PUSH_IGNORE_IMPLICIT_FALLTHROUGH -#include "funcs.generated.h" +# include "funcs.generated.h" PRAGMA_DIAG_POP PRAGMA_DIAG_POP #endif diff --git a/src/nvim/eval/typval.c b/src/nvim/eval/typval.c index 3bc4ec9381..075b50a366 100644 --- a/src/nvim/eval/typval.c +++ b/src/nvim/eval/typval.c @@ -100,7 +100,7 @@ void list_write_log(const char *const fname) } } -#ifdef EXITFREE +# ifdef EXITFREE /// Free list log void list_free_log(void) { @@ -110,7 +110,7 @@ void list_free_log(void) chunk = list_log_first; } } -#endif +# endif #endif //{{{2 List item diff --git a/src/nvim/eval/userfunc.c b/src/nvim/eval/userfunc.c index 0e4ddffa33..657777d7db 100644 --- a/src/nvim/eval/userfunc.c +++ b/src/nvim/eval/userfunc.c @@ -39,7 +39,7 @@ #define FC_CFUNC 0x800 // C function extension #ifdef INCLUDE_GENERATED_DECLARATIONS -#include "eval/userfunc.c.generated.h" +# include "eval/userfunc.c.generated.h" #endif hashtab_T func_hashtab; diff --git a/src/nvim/event/stream.c b/src/nvim/event/stream.c index 8569b92d56..b34fd73d52 100644 --- a/src/nvim/event/stream.c +++ b/src/nvim/event/stream.c @@ -20,7 +20,7 @@ // For compatibility with libuv < 1.19.0 (tested on 1.18.0) #if UV_VERSION_MINOR < 19 -#define uv_stream_get_write_queue_size(stream) stream->write_queue_size +# define uv_stream_get_write_queue_size(stream) stream->write_queue_size #endif /// Sets the stream associated with `fd` to "blocking" mode. diff --git a/src/nvim/ex_cmds2.c b/src/nvim/ex_cmds2.c index 7f3b019d57..46b86fbc84 100644 --- a/src/nvim/ex_cmds2.c +++ b/src/nvim/ex_cmds2.c @@ -109,7 +109,7 @@ struct source_cookie { vimconv_T conv; ///< type of conversion }; -# define PRL_ITEM(si, idx) (((sn_prl_T *)(si)->sn_prl_ga.ga_data)[(idx)]) +#define PRL_ITEM(si, idx) (((sn_prl_T *)(si)->sn_prl_ga.ga_data)[(idx)]) #ifdef INCLUDE_GENERATED_DECLARATIONS # include "ex_cmds2.c.generated.h" @@ -2340,7 +2340,7 @@ void ex_scriptnames(exarg_T *eap) } } -# if defined(BACKSLASH_IN_FILENAME) +#if defined(BACKSLASH_IN_FILENAME) /// Fix slashes in the list of script names for 'shellslash'. void scriptnames_slash_adjust(void) { @@ -2351,7 +2351,7 @@ void scriptnames_slash_adjust(void) } } -# endif +#endif /// Get a pointer to a script name. Used for ":verbose set". /// Message appended to "Last set from " @@ -2388,7 +2388,7 @@ char_u *get_scriptname(LastSet last_set, bool *should_free) } } -# if defined(EXITFREE) +#if defined(EXITFREE) void free_scriptnames(void) { profile_reset(); @@ -2396,7 +2396,7 @@ void free_scriptnames(void) # define FREE_SCRIPTNAME(item) xfree((item)->sn_name) GA_DEEP_CLEAR(&script_items, scriptitem_T, FREE_SCRIPTNAME); } -# endif +#endif linenr_T get_sourced_lnum(LineGetter fgetline, void *cookie) { @@ -2786,17 +2786,17 @@ char *get_mess_lang(void) { char *p; -# ifdef HAVE_GET_LOCALE_VAL -# if defined(LC_MESSAGES) +#ifdef HAVE_GET_LOCALE_VAL +# if defined(LC_MESSAGES) p = get_locale_val(LC_MESSAGES); -# else +# else // This is necessary for Win32, where LC_MESSAGES is not defined and $LANG // may be set to the LCID number. LC_COLLATE is the best guess, LC_TIME // and LC_MONETARY may be set differently for a Japanese working in the // US. p = get_locale_val(LC_COLLATE); -# endif -# else +# endif +#else p = os_getenv("LC_ALL"); if (!is_valid_mess_lang(p)) { p = os_getenv("LC_MESSAGES"); @@ -2804,7 +2804,7 @@ char *get_mess_lang(void) p = os_getenv("LANG"); } } -# endif +#endif return is_valid_mess_lang(p) ? p : NULL; } @@ -2842,37 +2842,37 @@ void set_lang_var(void) { const char *loc; -# ifdef HAVE_GET_LOCALE_VAL +#ifdef HAVE_GET_LOCALE_VAL loc = get_locale_val(LC_CTYPE); -# else +#else // setlocale() not supported: use the default value loc = "C"; -# endif +#endif set_vim_var_string(VV_CTYPE, loc, -1); // When LC_MESSAGES isn't defined use the value from $LC_MESSAGES, fall // back to LC_CTYPE if it's empty. -# ifdef HAVE_WORKING_LIBINTL +#ifdef HAVE_WORKING_LIBINTL loc = (char *)get_mess_env(); -# elif defined(LC_MESSAGES) +#elif defined(LC_MESSAGES) loc = get_locale_val(LC_MESSAGES); -# else +#else // In Windows LC_MESSAGES is not defined fallback to LC_CTYPE loc = get_locale_val(LC_CTYPE); -# endif +#endif set_vim_var_string(VV_LANG, loc, -1); -# ifdef HAVE_GET_LOCALE_VAL +#ifdef HAVE_GET_LOCALE_VAL loc = get_locale_val(LC_TIME); -# endif +#endif set_vim_var_string(VV_LC_TIME, loc, -1); -# ifdef HAVE_GET_LOCALE_VAL +#ifdef HAVE_GET_LOCALE_VAL loc = get_locale_val(LC_COLLATE); -# else +#else // setlocale() not supported: use the default value loc = "C"; -# endif +#endif set_vim_var_string(VV_COLLATE, loc, -1); } @@ -2889,11 +2889,11 @@ void ex_language(exarg_T *eap) char_u *name; int what = LC_ALL; char *whatstr = ""; -#ifdef LC_MESSAGES -# define VIM_LC_MESSAGES LC_MESSAGES -#else -# define VIM_LC_MESSAGES 6789 -#endif +# ifdef LC_MESSAGES +# define VIM_LC_MESSAGES LC_MESSAGES +# else +# define VIM_LC_MESSAGES 6789 +# endif name = eap->arg; @@ -2922,43 +2922,43 @@ void ex_language(exarg_T *eap) } if (*name == NUL) { -#ifdef HAVE_WORKING_LIBINTL +# ifdef HAVE_WORKING_LIBINTL if (what == VIM_LC_MESSAGES) { p = get_mess_env(); } else { -#endif +# endif p = (char_u *)setlocale(what, NULL); -#ifdef HAVE_WORKING_LIBINTL +# ifdef HAVE_WORKING_LIBINTL } -#endif +# endif if (p == NULL || *p == NUL) { p = (char_u *)"Unknown"; } smsg(_("Current %slanguage: \"%s\""), whatstr, p); } else { -#ifndef LC_MESSAGES +# ifndef LC_MESSAGES if (what == VIM_LC_MESSAGES) { loc = ""; } else { -#endif +# endif loc = setlocale(what, (char *)name); -#ifdef LC_NUMERIC +# ifdef LC_NUMERIC // Make sure strtod() uses a decimal point, not a comma. setlocale(LC_NUMERIC, "C"); -#endif -#ifndef LC_MESSAGES +# endif +# ifndef LC_MESSAGES } -#endif +# endif if (loc == NULL) { EMSG2(_("E197: Cannot set language to \"%s\""), name); } else { -#ifdef HAVE_NL_MSG_CAT_CNTR +# ifdef HAVE_NL_MSG_CAT_CNTR // Need to do this for GNU gettext, otherwise cached translations // will be used again. extern int _nl_msg_cat_cntr; _nl_msg_cat_cntr++; -#endif +# endif // Reset $LC_ALL, otherwise it would overrule everything. os_setenv("LC_ALL", "", 1); @@ -2987,7 +2987,7 @@ void ex_language(exarg_T *eap) static char_u **locales = NULL; // Array of all available locales -#ifndef WIN32 +# ifndef WIN32 static bool did_init_locales = false; /// Return an array of strings for all available locales + NULL for the @@ -3022,20 +3022,20 @@ static char_u **find_locales(void) ((char_u **)locales_ga.ga_data)[locales_ga.ga_len] = NULL; return (char_u **)locales_ga.ga_data; } -#endif +# endif /// Lazy initialization of all available locales. static void init_locales(void) { -#ifndef WIN32 +# ifndef WIN32 if (!did_init_locales) { did_init_locales = true; locales = find_locales(); } -#endif +# endif } -# if defined(EXITFREE) +# if defined(EXITFREE) void free_locales(void) { int i; @@ -3047,7 +3047,7 @@ void free_locales(void) } } -# endif +# endif /// Function given to ExpandGeneric() to obtain the possible arguments of the /// ":language" command. diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c index 70057ffd46..dff3b4223b 100644 --- a/src/nvim/ex_docmd.c +++ b/src/nvim/ex_docmd.c @@ -99,7 +99,7 @@ static garray_T ucmds = { 0, 0, sizeof(ucmd_T), 4, NULL }; #define USER_CMD_GA(gap, i) (&((ucmd_T *)((gap)->ga_data))[i]) // Whether a command index indicates a user command. -# define IS_USER_CMDIDX(idx) ((int)(idx) < 0) +#define IS_USER_CMDIDX(idx) ((int)(idx) < 0) // Struct for storing a line inside a while/for loop typedef struct { @@ -6949,7 +6949,7 @@ static void ex_goto(exarg_T *eap) */ void alist_clear(alist_T *al) { -# define FREE_AENTRY_FNAME(arg) xfree(arg->ae_fname) +#define FREE_AENTRY_FNAME(arg) xfree(arg->ae_fname) GA_DEEP_CLEAR(&al->al_ga, aentry_T, FREE_AENTRY_FNAME); } diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index 5f0dca736a..a9990df58f 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -2570,13 +2570,13 @@ static void realloc_cmdbuff(int len) static char_u *arshape_buf = NULL; -# if defined(EXITFREE) +#if defined(EXITFREE) void free_arshape_buf(void) { xfree(arshape_buf); } -# endif +#endif enum { MAX_CB_ERRORS = 1 }; @@ -4111,7 +4111,7 @@ char *vim_strsave_fnameescape(const char *const fname, const bool shell FUNC_ATT FUNC_ATTR_NONNULL_RET FUNC_ATTR_MALLOC FUNC_ATTR_NONNULL_ALL { #ifdef BACKSLASH_IN_FILENAME -#define PATH_ESC_CHARS " \t\n*?[{`%#'\"|!<" +# define PATH_ESC_CHARS " \t\n*?[{`%#'\"|!<" char_u buf[sizeof(PATH_ESC_CHARS)]; int j = 0; @@ -4125,8 +4125,8 @@ char *vim_strsave_fnameescape(const char *const fname, const bool shell FUNC_ATT char *p = (char *)vim_strsave_escaped((const char_u *)fname, (const char_u *)buf); #else -#define PATH_ESC_CHARS ((char_u *)" \t\n*?[{`$\\%#'\"|!<") -#define SHELL_ESC_CHARS ((char_u *)" \t\n*?[{`$\\%#'\"|!<>();&") +# define PATH_ESC_CHARS ((char_u *)" \t\n*?[{`$\\%#'\"|!<") +# define SHELL_ESC_CHARS ((char_u *)" \t\n*?[{`$\\%#'\"|!<>();&") char *p = (char *)vim_strsave_escaped((const char_u *)fname, (shell ? SHELL_ESC_CHARS : PATH_ESC_CHARS)); if (shell && csh_like_shell()) { diff --git a/src/nvim/fileio.c b/src/nvim/fileio.c index 31af47999b..f5a4efc371 100644 --- a/src/nvim/fileio.c +++ b/src/nvim/fileio.c @@ -65,7 +65,7 @@ // For compatibility with libuv < 1.20.0 (tested on 1.18.0) #ifndef UV_FS_COPYFILE_FICLONE -#define UV_FS_COPYFILE_FICLONE 0 +# define UV_FS_COPYFILE_FICLONE 0 #endif #define HAS_BW_FLAGS @@ -105,9 +105,9 @@ struct bw_info { int bw_conv_error; // set for conversion error linenr_T bw_conv_error_lnum; // first line with error or zero linenr_T bw_start_lnum; // line number at start of buffer -# ifdef HAVE_ICONV +#ifdef HAVE_ICONV iconv_t bw_iconv_fd; // descriptor for iconv() or -1 -# endif +#endif }; #ifdef INCLUDE_GENERATED_DECLARATIONS @@ -233,11 +233,11 @@ int readfile(char_u *fname, char_u *sfname, linenr_T from, linenr_T lines_to_ski char_u *fenc_next = NULL; // next item in 'fencs' or NULL bool advance_fenc = false; long real_size = 0; -# ifdef HAVE_ICONV +#ifdef HAVE_ICONV iconv_t iconv_fd = (iconv_t)-1; // descriptor for iconv() or -1 bool did_iconv = false; // true when iconv() failed and trying // 'charconvert' next -# endif +#endif bool converted = false; // true if conversion done bool notconverted = false; // true if conversion wanted but it wasn't possible char_u conv_rest[CONV_RESTLEN]; @@ -373,10 +373,10 @@ int readfile(char_u *fname, char_u *sfname, linenr_T from, linenr_T lines_to_ski if (perm >= 0 && !S_ISREG(perm) // not a regular file ... && !S_ISFIFO(perm) // ... or fifo && !S_ISSOCK(perm) // ... or socket -# ifdef OPEN_CHR_FILES +#ifdef OPEN_CHR_FILES && !(S_ISCHR(perm) && is_dev_fd_file(fname)) // ... or a character special file named /dev/fd/<n> -# endif +#endif ) { if (S_ISDIR(perm)) { filemess(curbuf, fname, (char_u *)_(msg_is_a_directory), 0); @@ -493,11 +493,11 @@ int readfile(char_u *fname, char_u *sfname, linenr_T from, linenr_T lines_to_ski } else { filemess(curbuf, sfname, (char_u *)( (fd == UV_EFBIG) ? _("[File too big]") : -# if defined(UNIX) && defined(EOVERFLOW) +#if defined(UNIX) && defined(EOVERFLOW) // libuv only returns -errno in Unix and in Windows open() does not // set EOVERFLOW (fd == -EOVERFLOW) ? _("[File too big]") : -# endif +#endif _("[Permission Denied]")), 0); curbuf->b_p_ro = TRUE; // must use "w!" now } @@ -768,13 +768,13 @@ retry: } } -# ifdef HAVE_ICONV +#ifdef HAVE_ICONV if (iconv_fd != (iconv_t)-1) { // aborted conversion with iconv(), close the descriptor iconv_close(iconv_fd); iconv_fd = (iconv_t)-1; } -# endif +#endif if (advance_fenc) { /* @@ -833,13 +833,13 @@ retry: -# ifdef HAVE_ICONV +#ifdef HAVE_ICONV // Try using iconv() if we can't convert internally. if (fio_flags == 0 && !did_iconv) { iconv_fd = (iconv_t)my_iconv_open((char_u *)"utf-8", fenc); } -# endif +#endif /* * Use the 'charconvert' expression when conversion is required @@ -847,13 +847,13 @@ retry: */ if (fio_flags == 0 && !read_stdin && !read_buffer && *p_ccv != NUL && !read_fifo -# ifdef HAVE_ICONV +#ifdef HAVE_ICONV && iconv_fd == (iconv_t)-1 -# endif +#endif ) { -# ifdef HAVE_ICONV +#ifdef HAVE_ICONV did_iconv = false; -# endif +#endif /* Skip conversion when it's already done (retry for wrong * "fileformat"). */ if (tmpname == NULL) { @@ -872,9 +872,9 @@ retry: } } else { if (fio_flags == 0 -# ifdef HAVE_ICONV +#ifdef HAVE_ICONV && iconv_fd == (iconv_t)-1 -# endif +#endif ) { /* Conversion wanted but we can't. * Try the next conversion in 'fileencodings' */ @@ -960,11 +960,11 @@ retry: * ucs-4 to utf-8: 4 bytes become up to 6 bytes, size must be * multiple of 4 */ real_size = (int)size; -# ifdef HAVE_ICONV +#ifdef HAVE_ICONV if (iconv_fd != (iconv_t)-1) { size = size / ICONV_MULT; } else { -# endif +#endif if (fio_flags & FIO_LATIN1) { size = size / 2; } else if (fio_flags & (FIO_UCS2 | FIO_UTF16)) { @@ -974,9 +974,9 @@ retry: } else if (fio_flags == FIO_UCSBOM) { size = size / ICONV_MULT; // worst case } -# ifdef HAVE_ICONV +#ifdef HAVE_ICONV } -# endif +#endif if (conv_restlen > 0) { // Insert unconverted bytes from previous line. memmove(ptr, conv_rest, conv_restlen); // -V614 @@ -1055,9 +1055,9 @@ retry: // When we did a conversion report an error. if (fio_flags != 0 -# ifdef HAVE_ICONV +#ifdef HAVE_ICONV || iconv_fd != (iconv_t)-1 -# endif +#endif ) { if (can_retry) { goto rewind_retry; @@ -1081,9 +1081,9 @@ retry: * leave the UTF8 checking code to do it, as it * works slightly differently. */ if (bad_char_behavior != BAD_KEEP && (fio_flags != 0 -# ifdef HAVE_ICONV +#ifdef HAVE_ICONV || iconv_fd != (iconv_t)-1 -# endif +#endif )) { while (conv_restlen > 0) { *(--ptr) = bad_char_behavior; @@ -1091,12 +1091,12 @@ retry: } } fio_flags = 0; // don't convert this -# ifdef HAVE_ICONV +#ifdef HAVE_ICONV if (iconv_fd != (iconv_t)-1) { iconv_close(iconv_fd); iconv_fd = (iconv_t)-1; } -# endif +#endif } } } @@ -1165,7 +1165,7 @@ retry: break; } -# ifdef HAVE_ICONV +#ifdef HAVE_ICONV if (iconv_fd != (iconv_t)-1) { /* * Attempt conversion of the read bytes to 'encoding' using @@ -1223,7 +1223,7 @@ retry: memmove(line_start, buffer, (size_t)linerest); size = ((char_u *)top - ptr); } -# endif +#endif if (fio_flags != 0) { unsigned int u8c; @@ -1441,12 +1441,12 @@ retry: if (can_retry && !incomplete_tail) { break; } -# ifdef HAVE_ICONV +#ifdef HAVE_ICONV // When we did a conversion report an error. if (iconv_fd != (iconv_t)-1 && conv_error == 0) { conv_error = readfile_linenr(linecnt, ptr, p); } -# endif +#endif // Remember the first linenr with an illegal byte if (conv_error == 0 && illegal_byte == 0) { illegal_byte = readfile_linenr(linecnt, ptr, p); @@ -1469,17 +1469,17 @@ retry: // Detected a UTF-8 error. rewind_retry: // Retry reading with another conversion. -# ifdef HAVE_ICONV +#ifdef HAVE_ICONV if (*p_ccv != NUL && iconv_fd != (iconv_t)-1) { // iconv() failed, try 'charconvert' did_iconv = true; } else { -# endif +#endif // use next item from 'fileencodings' advance_fenc = true; -# ifdef HAVE_ICONV +#ifdef HAVE_ICONV } -# endif +#endif file_rewind = true; goto retry; } @@ -1700,11 +1700,11 @@ failed: if (fenc_alloced) { xfree(fenc); } -# ifdef HAVE_ICONV +#ifdef HAVE_ICONV if (iconv_fd != (iconv_t)-1) { iconv_close(iconv_fd); } -# endif +#endif if (!read_buffer && !read_stdin) { close(fd); // errors are ignored @@ -2280,9 +2280,9 @@ int buf_write(buf_T *buf, char_u *fname, char_u *sfname, linenr_T start, linenr_ write_info.bw_conv_error = FALSE; write_info.bw_conv_error_lnum = 0; write_info.bw_restlen = 0; -# ifdef HAVE_ICONV +#ifdef HAVE_ICONV write_info.bw_iconv_fd = (iconv_t)-1; -# endif +#endif /* After writing a file changedtick changes but we don't want to display * the line. */ @@ -2690,7 +2690,7 @@ int buf_write(buf_T *buf, char_u *fname, char_u *sfname, linenr_T start, linenr_ if (fd < 0) { // can't write in directory backup_copy = TRUE; } else { -# ifdef UNIX +#ifdef UNIX os_fchown(fd, file_info_old.stat.st_uid, file_info_old.stat.st_gid); if (!os_fileinfo((char *)IObuff, &file_info) || file_info.stat.st_uid != file_info_old.stat.st_uid @@ -2698,7 +2698,7 @@ int buf_write(buf_T *buf, char_u *fname, char_u *sfname, linenr_T start, linenr_ || (long)file_info.stat.st_mode != perm) { backup_copy = TRUE; } -# endif +#endif /* Close the file before removing it, on MS-Windows we * can't delete an open file. */ close(fd); @@ -2711,7 +2711,7 @@ int buf_write(buf_T *buf, char_u *fname, char_u *sfname, linenr_T start, linenr_ * Break symlinks and/or hardlinks if we've been asked to. */ if ((bkc & BKC_BREAKSYMLINK) || (bkc & BKC_BREAKHARDLINK)) { -# ifdef UNIX +#ifdef UNIX bool file_info_link_ok = os_fileinfo_link((char *)fname, &file_info); // Symlinks. @@ -2728,7 +2728,7 @@ int buf_write(buf_T *buf, char_u *fname, char_u *sfname, linenr_T start, linenr_ || os_fileinfo_id_equal(&file_info, &file_info_old))) { backup_copy = FALSE; } -# endif +#endif } // make sure we have a valid backup extension to use @@ -3085,7 +3085,7 @@ nobackup: if (converted && wb_flags == 0) { -# ifdef HAVE_ICONV +#ifdef HAVE_ICONV // Use iconv() conversion when conversion is needed and it's not done // internally. write_info.bw_iconv_fd = (iconv_t)my_iconv_open(fenc, (char_u *)"utf-8"); @@ -3098,7 +3098,7 @@ nobackup: } write_info.bw_first = TRUE; } else -# endif +#endif /* * When the file needs to be converted with 'charconvert' after @@ -3114,9 +3114,9 @@ nobackup: } } if (converted && wb_flags == 0 -# ifdef HAVE_ICONV +#ifdef HAVE_ICONV && write_info.bw_iconv_fd == (iconv_t)-1 -# endif +#endif && wfname == fname) { if (!forceit) { SET_ERRMSG(_("E213: Cannot convert (add ! to write without conversion)")); @@ -3644,12 +3644,12 @@ nofail: } xfree(fenc_tofree); xfree(write_info.bw_conv_buf); -# ifdef HAVE_ICONV +#ifdef HAVE_ICONV if (write_info.bw_iconv_fd != (iconv_t)-1) { iconv_close(write_info.bw_iconv_fd); write_info.bw_iconv_fd = (iconv_t)-1; } -# endif +#endif #ifdef HAVE_ACL mch_free_acl(acl); #endif @@ -4034,7 +4034,7 @@ static int buf_write_bytes(struct bw_info *ip) } } -# ifdef HAVE_ICONV +#ifdef HAVE_ICONV if (ip->bw_iconv_fd != (iconv_t)-1) { const char *from; size_t fromlen; @@ -4096,7 +4096,7 @@ static int buf_write_bytes(struct bw_info *ip) buf = ip->bw_conv_buf; len = (int)((char_u *)to - ip->bw_conv_buf); } -# endif +#endif } if (ip->bw_fd < 0) { diff --git a/src/nvim/fold.c b/src/nvim/fold.c index f22fa449ea..06b8049176 100644 --- a/src/nvim/fold.c +++ b/src/nvim/fold.c @@ -1414,7 +1414,7 @@ static void deleteFoldEntry(win_T *const wp, garray_T *const gap, const int idx, */ void deleteFoldRecurse(buf_T *bp, garray_T *gap) { -# define DELETE_FOLD_NESTED(fd) deleteFoldRecurse(bp, &((fd)->fd_nested)) +#define DELETE_FOLD_NESTED(fd) deleteFoldRecurse(bp, &((fd)->fd_nested)) GA_DEEP_CLEAR(gap, fold_T, DELETE_FOLD_NESTED); } diff --git a/src/nvim/hardcopy.c b/src/nvim/hardcopy.c index 125108ee78..df2c494ace 100644 --- a/src/nvim/hardcopy.c +++ b/src/nvim/hardcopy.c @@ -140,13 +140,13 @@ static uint32_t curr_bg; static uint32_t curr_fg; static int page_count; -# define OPT_MBFONT_USECOURIER 0 -# define OPT_MBFONT_ASCII 1 -# define OPT_MBFONT_REGULAR 2 -# define OPT_MBFONT_BOLD 3 -# define OPT_MBFONT_OBLIQUE 4 -# define OPT_MBFONT_BOLDOBLIQUE 5 -# define OPT_MBFONT_NUM_OPTIONS 6 +#define OPT_MBFONT_USECOURIER 0 +#define OPT_MBFONT_ASCII 1 +#define OPT_MBFONT_REGULAR 2 +#define OPT_MBFONT_BOLD 3 +#define OPT_MBFONT_OBLIQUE 4 +#define OPT_MBFONT_BOLDOBLIQUE 5 +#define OPT_MBFONT_NUM_OPTIONS 6 static option_table_T mbfont_opts[OPT_MBFONT_NUM_OPTIONS] = { diff --git a/src/nvim/lua/converter.c b/src/nvim/lua/converter.c index 07c53299fa..fac5bab664 100644 --- a/src/nvim/lua/converter.c +++ b/src/nvim/lua/converter.c @@ -755,7 +755,7 @@ void nlua_push_Array(lua_State *lstate, const Array array, bool special) FUNC_ATTR_NONNULL_ALL \ { \ lua_pushnumber(lstate, (lua_Number)(item)); \ -} + } GENERATE_INDEX_FUNCTION(Buffer) GENERATE_INDEX_FUNCTION(Window) @@ -1126,9 +1126,9 @@ Object nlua_pop_Object(lua_State *const lstate, bool ref, Error *const err) size_t len; const char *s = lua_tolstring(lstate, -1, &len); *cur.obj = STRING_OBJ(((String) { - .data = xmemdupz(s, len), - .size = len, - })); + .data = xmemdupz(s, len), + .size = len, + })); break; } case LUA_TNUMBER: { @@ -1147,10 +1147,10 @@ Object nlua_pop_Object(lua_State *const lstate, bool ref, Error *const err) switch (table_props.type) { case kObjectTypeArray: *cur.obj = ARRAY_OBJ(((Array) { - .items = NULL, - .size = 0, - .capacity = 0, - })); + .items = NULL, + .size = 0, + .capacity = 0, + })); if (table_props.maxidx != 0) { cur.obj->data.array.items = xcalloc(table_props.maxidx, @@ -1162,10 +1162,10 @@ Object nlua_pop_Object(lua_State *const lstate, bool ref, Error *const err) break; case kObjectTypeDictionary: *cur.obj = DICTIONARY_OBJ(((Dictionary) { - .items = NULL, - .size = 0, - .capacity = 0, - })); + .items = NULL, + .size = 0, + .capacity = 0, + })); if (table_props.string_keys_num != 0) { cur.obj->data.dictionary.items = xcalloc(table_props.string_keys_num, diff --git a/src/nvim/map.c b/src/nvim/map.c index 1c986a4fa4..20d5570e8c 100644 --- a/src/nvim/map.c +++ b/src/nvim/map.c @@ -36,11 +36,11 @@ #if defined(ARCH_64) -#define ptr_t_hash(key) uint64_t_hash((uint64_t)key) -#define ptr_t_eq(a, b) uint64_t_eq((uint64_t)a, (uint64_t)b) +# define ptr_t_hash(key) uint64_t_hash((uint64_t)key) +# define ptr_t_eq(a, b) uint64_t_eq((uint64_t)a, (uint64_t)b) #elif defined(ARCH_32) -#define ptr_t_hash(key) uint32_t_hash((uint32_t)key) -#define ptr_t_eq(a, b) uint32_t_eq((uint32_t)a, (uint32_t)b) +# define ptr_t_hash(key) uint32_t_hash((uint32_t)key) +# define ptr_t_eq(a, b) uint32_t_eq((uint32_t)a, (uint32_t)b) #endif #define INITIALIZER(T, U) T##_##U##_initializer diff --git a/src/nvim/mbyte.c b/src/nvim/mbyte.c index fe4ec9f96c..253ddfc253 100644 --- a/src/nvim/mbyte.c +++ b/src/nvim/mbyte.c @@ -1395,9 +1395,9 @@ static int utf_strnicmp(const char_u *s1, const char_u *s2, size_t n1, size_t n2 } #ifdef WIN32 -#ifndef CP_UTF8 -# define CP_UTF8 65001 // magic number from winnls.h -#endif +# ifndef CP_UTF8 +# define CP_UTF8 65001 // magic number from winnls.h +# endif /// Converts string from UTF-8 to UTF-16. /// @@ -2208,13 +2208,13 @@ char_u *enc_locale(void) char buf[50]; const char *s; -# ifdef HAVE_NL_LANGINFO_CODESET +#ifdef HAVE_NL_LANGINFO_CODESET if (!(s = nl_langinfo(CODESET)) || *s == NUL) -# endif +#endif { -# if defined(HAVE_LOCALE_H) +#if defined(HAVE_LOCALE_H) if (!(s = setlocale(LC_CTYPE, NULL)) || *s == NUL) -# endif +#endif { if ((s = os_getenv("LC_ALL"))) { if ((s = os_getenv("LC_CTYPE"))) { @@ -2265,7 +2265,7 @@ enc_locale_copy_enc: return enc_canonize((char_u *)buf); } -# if defined(HAVE_ICONV) +#if defined(HAVE_ICONV) /* @@ -2277,7 +2277,7 @@ enc_locale_copy_enc: void *my_iconv_open(char_u *to, char_u *from) { iconv_t fd; -#define ICONV_TESTLEN 400 +# define ICONV_TESTLEN 400 char_u tobuf[ICONV_TESTLEN]; char *p; size_t tolen; @@ -2395,7 +2395,7 @@ static char_u *iconv_string(const vimconv_T *const vcp, char_u *str, size_t slen return result; } -# endif // HAVE_ICONV +#endif // HAVE_ICONV @@ -2425,11 +2425,11 @@ int convert_setup_ext(vimconv_T *vcp, char_u *from, bool from_unicode_is_utf8, c int to_is_utf8; // Reset to no conversion. -# ifdef HAVE_ICONV +#ifdef HAVE_ICONV if (vcp->vc_type == CONV_ICONV && vcp->vc_fd != (iconv_t)-1) { iconv_close(vcp->vc_fd); } -# endif +#endif *vcp = (vimconv_T)MBYTE_NONE_CONV; // No conversion when one of the names is empty or they are equal. @@ -2466,7 +2466,7 @@ int convert_setup_ext(vimconv_T *vcp, char_u *from, bool from_unicode_is_utf8, c // Internal utf-8 -> latin9 conversion. vcp->vc_type = CONV_TO_LATIN9; } -# ifdef HAVE_ICONV +#ifdef HAVE_ICONV else { // NOLINT(readability/braces) // Use iconv() for conversion. vcp->vc_fd = (iconv_t)my_iconv_open(to_is_utf8 ? (char_u *)"utf-8" : to, @@ -2476,7 +2476,7 @@ int convert_setup_ext(vimconv_T *vcp, char_u *from, bool from_unicode_is_utf8, c vcp->vc_factor = 4; // could be longer too... } } -# endif +#endif if (vcp->vc_type == CONV_NONE) { return FAIL; } @@ -2644,11 +2644,11 @@ char_u *string_convert_ext(const vimconv_T *const vcp, char_u *ptr, size_t *lenp } break; -# ifdef HAVE_ICONV +#ifdef HAVE_ICONV case CONV_ICONV: // conversion with vcp->vc_fd retval = iconv_string(vcp, ptr, len, unconvlenp, lenp); break; -# endif +#endif } return retval; diff --git a/src/nvim/memory.c b/src/nvim/memory.c index 0f5f4c1e40..5e6c6a8189 100644 --- a/src/nvim/memory.c +++ b/src/nvim/memory.c @@ -526,35 +526,35 @@ void time_to_bytes(time_t time_, uint8_t buf[8]) #if defined(EXITFREE) -#include "nvim/buffer.h" -#include "nvim/charset.h" -#include "nvim/diff.h" -#include "nvim/edit.h" -#include "nvim/eval/typval.h" -#include "nvim/ex_cmds.h" -#include "nvim/ex_docmd.h" -#include "nvim/ex_getln.h" -#include "nvim/file_search.h" -#include "nvim/fileio.h" -#include "nvim/fold.h" -#include "nvim/getchar.h" -#include "nvim/mark.h" -#include "nvim/mbyte.h" -#include "nvim/memline.h" -#include "nvim/move.h" -#include "nvim/ops.h" -#include "nvim/option.h" -#include "nvim/os/os.h" -#include "nvim/os_unix.h" -#include "nvim/path.h" -#include "nvim/quickfix.h" -#include "nvim/regexp.h" -#include "nvim/screen.h" -#include "nvim/search.h" -#include "nvim/spell.h" -#include "nvim/syntax.h" -#include "nvim/tag.h" -#include "nvim/window.h" +# include "nvim/buffer.h" +# include "nvim/charset.h" +# include "nvim/diff.h" +# include "nvim/edit.h" +# include "nvim/eval/typval.h" +# include "nvim/ex_cmds.h" +# include "nvim/ex_docmd.h" +# include "nvim/ex_getln.h" +# include "nvim/file_search.h" +# include "nvim/fileio.h" +# include "nvim/fold.h" +# include "nvim/getchar.h" +# include "nvim/mark.h" +# include "nvim/mbyte.h" +# include "nvim/memline.h" +# include "nvim/move.h" +# include "nvim/ops.h" +# include "nvim/option.h" +# include "nvim/os/os.h" +# include "nvim/os_unix.h" +# include "nvim/path.h" +# include "nvim/quickfix.h" +# include "nvim/regexp.h" +# include "nvim/screen.h" +# include "nvim/search.h" +# include "nvim/spell.h" +# include "nvim/syntax.h" +# include "nvim/tag.h" +# include "nvim/window.h" /* * Free everything that we allocated. diff --git a/src/nvim/misc1.c b/src/nvim/misc1.c index 2166631767..2dfe5df325 100644 --- a/src/nvim/misc1.c +++ b/src/nvim/misc1.c @@ -874,7 +874,7 @@ void preserve_exit(void) */ #ifndef BREAKCHECK_SKIP -# define BREAKCHECK_SKIP 1000 +# define BREAKCHECK_SKIP 1000 #endif static int breakcheck_count = 0; diff --git a/src/nvim/msgpack_rpc/channel.c b/src/nvim/msgpack_rpc/channel.c index 813f21407c..a1a1f0f8c0 100644 --- a/src/nvim/msgpack_rpc/channel.c +++ b/src/nvim/msgpack_rpc/channel.c @@ -33,8 +33,8 @@ #include "nvim/vim.h" #if MIN_LOG_LEVEL > DEBUG_LOG_LEVEL -#define log_client_msg(...) -#define log_server_msg(...) +# define log_client_msg(...) +# define log_server_msg(...) #endif static PMap(cstr_t) event_strings = MAP_INIT; @@ -699,14 +699,14 @@ const char *rpc_client_name(Channel *chan) } #if MIN_LOG_LEVEL <= DEBUG_LOG_LEVEL -#define REQ "[request] " -#define RES "[response] " -#define NOT "[notify] " -#define ERR "[error] " +# define REQ "[request] " +# define RES "[response] " +# define NOT "[notify] " +# define ERR "[error] " // Cannot define array with negative offsets, so this one is needed to be added // to MSGPACK_UNPACK_\* values. -#define MUR_OFF 2 +# define MUR_OFF 2 static const char *const msgpack_error_messages[] = { [MSGPACK_UNPACK_EXTRA_BYTES + MUR_OFF] = "extra bytes found", diff --git a/src/nvim/msgpack_rpc/helpers.c b/src/nvim/msgpack_rpc/helpers.c index 0bc58fffba..b1b9c77953 100644 --- a/src/nvim/msgpack_rpc/helpers.c +++ b/src/nvim/msgpack_rpc/helpers.c @@ -47,17 +47,15 @@ static msgpack_sbuffer sbuffer; } \ \ static void msgpack_rpc_from_##lt(Integer o, msgpack_packer *res) \ -/* uncrustify:indent-off */ \ FUNC_ATTR_NONNULL_ARG(2) \ -/* uncrustify:indent-on */ \ { \ - msgpack_packer pac; \ - msgpack_packer_init(&pac, &sbuffer, msgpack_sbuffer_write); \ - msgpack_pack_int64(&pac, (handle_T)o); \ - msgpack_pack_ext(res, sbuffer.size, \ - kObjectType##t - EXT_OBJECT_TYPE_SHIFT); \ - msgpack_pack_ext_body(res, sbuffer.data, sbuffer.size); \ - msgpack_sbuffer_clear(&sbuffer); \ + msgpack_packer pac; \ + msgpack_packer_init(&pac, &sbuffer, msgpack_sbuffer_write); \ + msgpack_pack_int64(&pac, (handle_T)o); \ + msgpack_pack_ext(res, sbuffer.size, \ + kObjectType##t - EXT_OBJECT_TYPE_SHIFT); \ + msgpack_pack_ext_body(res, sbuffer.data, sbuffer.size); \ + msgpack_sbuffer_clear(&sbuffer); \ } void msgpack_rpc_helpers_init(void) @@ -90,11 +88,11 @@ bool msgpack_rpc_to_object(const msgpack_object *const obj, Object *const arg) kvec_withinit_t(MPToAPIObjectStackItem, 2) stack = KV_INITIAL_VALUE; kvi_init(stack); kvi_push(stack, ((MPToAPIObjectStackItem) { - .mobj = obj, - .aobj = arg, - .container = false, - .idx = 0, - })); + .mobj = obj, + .aobj = arg, + .container = false, + .idx = 0, + })); while (ret && kv_size(stack)) { MPToAPIObjectStackItem cur = kv_last(stack); if (!cur.container) { @@ -154,19 +152,19 @@ case type: { \ cur.idx++; kv_last(stack) = cur; kvi_push(stack, ((MPToAPIObjectStackItem) { - .mobj = &cur.mobj->via.array.ptr[idx], - .aobj = &cur.aobj->data.array.items[idx], - .container = false, - })); + .mobj = &cur.mobj->via.array.ptr[idx], + .aobj = &cur.aobj->data.array.items[idx], + .container = false, + })); } } else { *cur.aobj = ARRAY_OBJ(((Array) { - .size = size, - .capacity = size, - .items = (size > 0 + .size = size, + .capacity = size, + .items = (size > 0 ? xcalloc(size, sizeof(*cur.aobj->data.array.items)) : NULL), - })); + })); cur.container = true; kv_last(stack) = cur; } @@ -207,20 +205,20 @@ case type: { \ } if (ret) { kvi_push(stack, ((MPToAPIObjectStackItem) { - .mobj = &cur.mobj->via.map.ptr[idx].val, - .aobj = &cur.aobj->data.dictionary.items[idx].value, - .container = false, - })); + .mobj = &cur.mobj->via.map.ptr[idx].val, + .aobj = &cur.aobj->data.dictionary.items[idx].value, + .container = false, + })); } } } else { *cur.aobj = DICTIONARY_OBJ(((Dictionary) { - .size = size, - .capacity = size, - .items = (size > 0 + .size = size, + .capacity = size, + .items = (size > 0 ? xcalloc(size, sizeof(*cur.aobj->data.dictionary.items)) : NULL), - })); + })); cur.container = true; kv_last(stack) = cur; } @@ -412,9 +410,9 @@ void msgpack_rpc_from_object(const Object result, msgpack_packer *const res) cur.idx++; kv_last(stack) = cur; kvi_push(stack, ((APIToMPObjectStackItem) { - .aobj = &cur.aobj->data.array.items[idx], - .container = false, - })); + .aobj = &cur.aobj->data.array.items[idx], + .container = false, + })); } } else { msgpack_pack_array(res, size); @@ -435,9 +433,9 @@ void msgpack_rpc_from_object(const Object result, msgpack_packer *const res) msgpack_rpc_from_string(cur.aobj->data.dictionary.items[idx].key, res); kvi_push(stack, ((APIToMPObjectStackItem) { - .aobj = &cur.aobj->data.dictionary.items[idx].value, - .container = false, - })); + .aobj = &cur.aobj->data.dictionary.items[idx].value, + .container = false, + })); } } else { msgpack_pack_map(res, size); diff --git a/src/nvim/normal.c b/src/nvim/normal.c index 17ec5cd3be..493c704f42 100644 --- a/src/nvim/normal.c +++ b/src/nvim/normal.c @@ -3372,7 +3372,7 @@ static void may_clear_cmdline(void) } // Routines for displaying a partly typed command -# define SHOWCMD_BUFLEN SHOWCMD_COLS + 1 + 30 +#define SHOWCMD_BUFLEN SHOWCMD_COLS + 1 + 30 static char_u showcmd_buf[SHOWCMD_BUFLEN]; static char_u old_showcmd_buf[SHOWCMD_BUFLEN]; // For push_showcmd() static bool showcmd_is_clear = true; diff --git a/src/nvim/option.c b/src/nvim/option.c index 8bdba82b67..5646a62cd4 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -374,11 +374,11 @@ void set_init_1(bool clean_arg) * temp files. */ { -# ifdef UNIX +#ifdef UNIX static char *(names[4]) = { "", "TMPDIR", "TEMP", "TMP" }; -# else +#else static char *(names[3]) = { "TMPDIR", "TEMP", "TMP" }; -# endif +#endif garray_T ga; opt_idx = findoption("backupskip"); @@ -386,16 +386,16 @@ void set_init_1(bool clean_arg) for (size_t n = 0; n < ARRAY_SIZE(names); n++) { bool mustfree = true; char *p; -# ifdef UNIX +#ifdef UNIX if (*names[n] == NUL) { -# ifdef __APPLE__ +# ifdef __APPLE__ p = "/private/tmp"; -# else +# else p = "/tmp"; -# endif +# endif mustfree = false; } else -# endif +#endif { p = vim_getenv(names[n]); } @@ -5831,10 +5831,10 @@ static char_u *get_varp(vimoption_T *p) return (char_u *)&(curbuf->b_p_cms); case PV_CPT: return (char_u *)&(curbuf->b_p_cpt); -# ifdef BACKSLASH_IN_FILENAME +#ifdef BACKSLASH_IN_FILENAME case PV_CSL: return (char_u *)&(curbuf->b_p_csl); -# endif +#endif case PV_CFU: return (char_u *)&(curbuf->b_p_cfu); case PV_OFU: @@ -6179,9 +6179,9 @@ void buf_copy_options(buf_T *buf, int flags) buf->b_p_inf = p_inf; buf->b_p_swf = cmdmod.noswapfile ? false : p_swf; buf->b_p_cpt = vim_strsave(p_cpt); -# ifdef BACKSLASH_IN_FILENAME +#ifdef BACKSLASH_IN_FILENAME buf->b_p_csl = vim_strsave(p_csl); -# endif +#endif buf->b_p_cfu = vim_strsave(p_cfu); buf->b_p_ofu = vim_strsave(p_ofu); buf->b_p_tfu = vim_strsave(p_tfu); diff --git a/src/nvim/os/env.c b/src/nvim/os/env.c index f239c9e1ec..0f363ecfc3 100644 --- a/src/nvim/os/env.c +++ b/src/nvim/os/env.c @@ -22,15 +22,15 @@ #include "nvim/vim.h" #ifdef WIN32 -#include "nvim/mbyte.h" // for utf8_to_utf16, utf16_to_utf8 +# include "nvim/mbyte.h" // for utf8_to_utf16, utf16_to_utf8 #endif #ifdef HAVE__NSGETENVIRON -#include <crt_externs.h> +# include <crt_externs.h> #endif #ifdef HAVE_SYS_UTSNAME_H -#include <sys/utsname.h> +# include <sys/utsname.h> #endif // Because `uv_os_getenv` requires allocating, we must manage a map to maintain @@ -1161,7 +1161,7 @@ char_u *home_replace_save(buf_T *buf, char_u *src) FUNC_ATTR_NONNULL_RET /// Function given to ExpandGeneric() to obtain an environment variable name. char_u *get_env_name(expand_T *xp, int idx) { -# define ENVNAMELEN 100 +#define ENVNAMELEN 100 // this static buffer is needed to avoid a memory leak in ExpandGeneric static char_u name[ENVNAMELEN]; assert(idx >= 0); diff --git a/src/nvim/os/fs.c b/src/nvim/os/fs.c index d50d68c99e..bbf70a4830 100644 --- a/src/nvim/os/fs.c +++ b/src/nvim/os/fs.c @@ -29,7 +29,7 @@ #include "nvim/strings.h" #ifdef WIN32 -#include "nvim/mbyte.h" // for utf8_to_utf16, utf16_to_utf8 +# include "nvim/mbyte.h" // for utf8_to_utf16, utf16_to_utf8 #endif #ifdef INCLUDE_GENERATED_DECLARATIONS @@ -1226,12 +1226,12 @@ char *os_resolve_shortcut(const char *fname) goto shortcut_errorw; } -# if 0 // This makes Vim wait a long time if the target does not exist. +# if 0 // This makes Vim wait a long time if the target does not exist. hr = pslw->lpVtbl->Resolve(pslw, NULL, SLR_NO_UI); if (hr != S_OK) { goto shortcut_errorw; } -# endif +# endif // Get the path to the link target. ZeroMemory(wsz, MAX_PATH * sizeof(wchar_t)); @@ -1262,7 +1262,7 @@ shortcut_end: return rfname; } -#define is_path_sep(c) ((c) == L'\\' || (c) == L'/') +# define is_path_sep(c) ((c) == L'\\' || (c) == L'/') /// Returns true if the path contains a reparse point (junction or symbolic /// link). Otherwise false in returned. bool os_is_reparse_point_include(const char *path) diff --git a/src/nvim/os/pty_process_unix.c b/src/nvim/os/pty_process_unix.c index d94de2e397..24ecf5c24f 100644 --- a/src/nvim/os/pty_process_unix.c +++ b/src/nvim/os/pty_process_unix.c @@ -157,7 +157,7 @@ static void init_child(PtyProcess *ptyproc) FUNC_ATTR_NONNULL_ALL { #if defined(HAVE__NSGETENVIRON) -#define environ (*_NSGetEnviron()) +# define environ (*_NSGetEnviron()) #else extern char **environ; #endif diff --git a/src/nvim/os/users.c b/src/nvim/os/users.c index 2687c66f24..fd7ead68da 100644 --- a/src/nvim/os/users.c +++ b/src/nvim/os/users.c @@ -43,7 +43,7 @@ int os_get_usernames(garray_T *users) } ga_init(users, sizeof(char *), 20); -# if defined(HAVE_GETPWENT) && defined(HAVE_PWD_H) +#if defined(HAVE_GETPWENT) && defined(HAVE_PWD_H) { struct passwd *pw; @@ -53,7 +53,7 @@ int os_get_usernames(garray_T *users) } endpwent(); } -# elif defined(WIN32) +#elif defined(WIN32) { DWORD nusers = 0, ntotal = 0, i; PUSER_INFO_0 uinfo; @@ -73,8 +73,8 @@ int os_get_usernames(garray_T *users) NetApiBufferFree(uinfo); } } -# endif -# if defined(HAVE_GETPWNAM) +#endif +#if defined(HAVE_GETPWNAM) { const char *user_env = os_getenv("USER"); @@ -104,7 +104,7 @@ int os_get_usernames(garray_T *users) } } } -# endif +#endif return OK; } diff --git a/src/nvim/screen.c b/src/nvim/screen.c index 057e800ee2..98d8722ec8 100644 --- a/src/nvim/screen.c +++ b/src/nvim/screen.c @@ -2061,7 +2061,7 @@ static int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool noc bool draw_color_col = false; // highlight colorcolumn int *color_cols = NULL; // pointer to according columns array bool has_spell = false; // this buffer has spell checking -# define SPWORDLEN 150 +#define SPWORDLEN 150 char_u nextline[SPWORDLEN * 2]; // text with start of the next line int nextlinecol = 0; // column where nextline[] starts int nextline_idx = 0; /* index in nextline[] where next line @@ -2124,12 +2124,12 @@ static int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool noc // draw_state: items that are drawn in sequence: #define WL_START 0 // nothing done yet -# define WL_CMDLINE WL_START + 1 // cmdline window column -# define WL_FOLD WL_CMDLINE + 1 // 'foldcolumn' -# define WL_SIGN WL_FOLD + 1 // column for signs +#define WL_CMDLINE WL_START + 1 // cmdline window column +#define WL_FOLD WL_CMDLINE + 1 // 'foldcolumn' +#define WL_SIGN WL_FOLD + 1 // column for signs #define WL_NR WL_SIGN + 1 // line number -# define WL_BRI WL_NR + 1 // 'breakindent' -# define WL_SBR WL_BRI + 1 // 'showbreak' or 'diff' +#define WL_BRI WL_NR + 1 // 'breakindent' +#define WL_SBR WL_BRI + 1 // 'showbreak' or 'diff' #define WL_LINE WL_SBR + 1 // text in the line int draw_state = WL_START; // what to draw next @@ -2144,8 +2144,8 @@ static int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool noc int did_wcol = false; int match_conc = 0; ///< cchar for match functions int old_boguscols = 0; -# define VCOL_HLC (vcol - vcol_off) -# define FIX_FOR_BOGUSCOLS \ +#define VCOL_HLC (vcol - vcol_off) +#define FIX_FOR_BOGUSCOLS \ { \ n_extra += vcol_off; \ vcol -= vcol_off; \ diff --git a/src/nvim/shada.c b/src/nvim/shada.c index 25c9823dc7..bf245bec51 100644 --- a/src/nvim/shada.c +++ b/src/nvim/shada.c @@ -3229,9 +3229,9 @@ static void shada_free_shada_entry(ShadaEntry *const entry) #ifndef HAVE_BE64TOH static inline uint64_t be64toh(uint64_t big_endian_64_bits) { -#ifdef ORDER_BIG_ENDIAN +# ifdef ORDER_BIG_ENDIAN return big_endian_64_bits; -#else +# else // It may appear that when !defined(ORDER_BIG_ENDIAN) actual order is big // endian. This variant is suboptimal, but it works regardless of actual // order. @@ -3241,7 +3241,7 @@ static inline uint64_t be64toh(uint64_t big_endian_64_bits) ret |= ((uint64_t)buf[i - 1]) << ((8 - i) * 8); } return ret; -#endif +# endif } #endif diff --git a/src/nvim/spell.c b/src/nvim/spell.c index 610a359141..3e56ad561b 100644 --- a/src/nvim/spell.c +++ b/src/nvim/spell.c @@ -72,15 +72,14 @@ #include <inttypes.h> #include <limits.h> #include <stdbool.h> -#include <string.h> #include <stdlib.h> +#include <string.h> #include <wctype.h> -/* for offsetof() */ +// for offsetof() #include <stddef.h> #include "nvim/ascii.h" -#include "nvim/spell.h" #include "nvim/buffer.h" #include "nvim/change.h" #include "nvim/charset.h" @@ -92,6 +91,7 @@ #include "nvim/ex_docmd.h" #include "nvim/fileio.h" #include "nvim/func_attr.h" +#include "nvim/garray.h" #include "nvim/getchar.h" #include "nvim/hashtab.h" #include "nvim/mark.h" @@ -100,21 +100,21 @@ #include "nvim/memory.h" #include "nvim/message.h" #include "nvim/misc1.h" -#include "nvim/garray.h" #include "nvim/normal.h" #include "nvim/option.h" +#include "nvim/os/input.h" +#include "nvim/os/os.h" #include "nvim/os_unix.h" #include "nvim/path.h" #include "nvim/regexp.h" #include "nvim/screen.h" #include "nvim/search.h" +#include "nvim/spell.h" #include "nvim/spellfile.h" #include "nvim/strings.h" #include "nvim/syntax.h" -#include "nvim/undo.h" #include "nvim/ui.h" -#include "nvim/os/os.h" -#include "nvim/os/input.h" +#include "nvim/undo.h" // only used for su_badflags #define WF_MIXCAP 0x20 // mix of upper and lower case: macaRONI @@ -151,26 +151,26 @@ typedef struct suginfo_S { int su_maxscore; // maximum score for adding to su_ga int su_sfmaxscore; // idem, for when doing soundfold words garray_T su_sga; // like su_ga, sound-folded scoring - char_u *su_badptr; // start of bad word in line + char_u *su_badptr; // start of bad word in line int su_badlen; // length of detected bad word in line int su_badflags; // caps flags for bad word char_u su_badword[MAXWLEN]; // bad word truncated at su_badlen char_u su_fbadword[MAXWLEN]; // su_badword case-folded char_u su_sal_badword[MAXWLEN]; // su_badword soundfolded hashtab_T su_banned; // table with banned words - slang_T *su_sallang; // default language for sound folding + slang_T *su_sallang; // default language for sound folding } suginfo_T; // One word suggestion. Used in "si_ga". typedef struct { - char_u *st_word; // suggested word, allocated string + char_u *st_word; // suggested word, allocated string int st_wordlen; // STRLEN(st_word) int st_orglen; // length of replaced text int st_score; // lower is better int st_altscore; // used when st_score compares equal bool st_salscore; // st_score is for soundalike bool st_had_bonus; // bonus already included in score - slang_T *st_slang; // language used for sound folding + slang_T *st_slang; // language used for sound folding } suggest_T; #define SUG(ga, i) (((suggest_T *)(ga).ga_data)[i]) @@ -235,14 +235,14 @@ typedef struct { // Structure to store info for word matching. typedef struct matchinf_S { - langp_T *mi_lp; // info for language and region + langp_T *mi_lp; // info for language and region // pointers to original text to be checked - char_u *mi_word; // start of word being checked - char_u *mi_end; // end of matching word so far - char_u *mi_fend; // next char to be added to mi_fword - char_u *mi_cend; // char after what was used for - // mi_capflags + char_u *mi_word; // start of word being checked + char_u *mi_end; // end of matching word so far + char_u *mi_fend; // next char to be added to mi_fword + char_u *mi_cend; // char after what was used for + // mi_capflags // case-folded text char_u mi_fword[MAXWLEN + 1]; // mi_word case-folded @@ -265,11 +265,11 @@ typedef struct matchinf_S { // others int mi_result; // result so far: SP_BAD, SP_OK, etc. int mi_capflags; // WF_ONECAP WF_ALLCAP WF_KEEPCAP - win_T *mi_win; // buffer being checked + win_T *mi_win; // buffer being checked // for NOBREAK int mi_result2; // "mi_resul" without following word - char_u *mi_end2; // "mi_end" without following word + char_u *mi_end2; // "mi_end" without following word } matchinf_T; // Structure used for the cookie argument of do_in_runtimepath(). @@ -334,26 +334,24 @@ char *e_format = N_("E759: Format error in spell file"); static char_u *repl_from = NULL; static char_u *repl_to = NULL; -// Main spell-checking function. -// "ptr" points to a character that could be the start of a word. -// "*attrp" is set to the highlight index for a badly spelled word. For a -// non-word or when it's OK it remains unchanged. -// This must only be called when 'spelllang' is not empty. -// -// "capcol" is used to check for a Capitalised word after the end of a -// sentence. If it's zero then perform the check. Return the column where to -// check next, or -1 when no sentence end was found. If it's NULL then don't -// worry. -// -// Returns the length of the word in bytes, also when it's OK, so that the -// caller can skip over the word. -size_t spell_check( - win_T *wp, // current window - char_u *ptr, - hlf_T *attrp, - int *capcol, // column to check for Capital - bool docount // count good words -) +/// Main spell-checking function. +/// "ptr" points to a character that could be the start of a word. +/// "*attrp" is set to the highlight index for a badly spelled word. For a +/// non-word or when it's OK it remains unchanged. +/// This must only be called when 'spelllang' is not empty. +/// +/// "capcol" is used to check for a Capitalised word after the end of a +/// sentence. If it's zero then perform the check. Return the column where to +/// check next, or -1 when no sentence end was found. If it's NULL then don't +/// worry. +/// +/// @param wp current window +/// @param capcol column to check for Capital +/// @param docount count good words +/// +/// @return the length of the word in bytes, also when it's OK, so that the +/// caller can skip over the word. +size_t spell_check(win_T *wp, char_u *ptr, hlf_T *attrp, int *capcol, bool docount) { matchinf_T mi; // Most things are put in "mi" so that it can // be passed to functions quickly. @@ -383,7 +381,7 @@ size_t spell_check( // julifeest". if (*ptr >= '0' && *ptr <= '9') { if (*ptr == '0' && (ptr[1] == 'b' || ptr[1] == 'B')) { - mi.mi_end = (char_u*) skipbin((char*) ptr + 2); + mi.mi_end = (char_u *)skipbin((char *)ptr + 2); } else if (*ptr == '0' && (ptr[1] == 'x' || ptr[1] == 'X')) { mi.mi_end = skiphex(ptr + 2); } else { @@ -486,7 +484,7 @@ size_t spell_check( // Count the word in the first language where it's found to be OK. if (count_word && mi.mi_result == SP_OK) { count_common_word(mi.mi_lp->lp_slang, ptr, - (int)(mi.mi_end - ptr), 1); + (int)(mi.mi_end - ptr), 1); count_word = false; } } @@ -499,8 +497,8 @@ size_t spell_check( return nrlen; } } else if (!spell_iswordp_nmw(ptr, wp)) { - // When we are at a non-word character there is no error, just - // skip over the character (try looking for a word after it). + // When we are at a non-word character there is no error, just + // skip over the character (try looking for a word after it). if (capcol != NULL && wp->w_s->b_cap_prog != NULL) { regmatch_T regmatch; @@ -521,7 +519,7 @@ size_t spell_check( MB_PTR_ADV(mi.mi_end); } else if (mi.mi_result == SP_BAD && LANGP_ENTRY(wp->w_s->b_langp, 0)->lp_slang->sl_nobreak) { - char_u *p, *fp; + char_u *p, *fp; int save_result = mi.mi_result; // First language in 'spelllang' is NOBREAK. Find first position @@ -576,10 +574,10 @@ static void find_word(matchinf_T *mip, int mode) { int wlen = 0; int flen; - char_u *ptr; - slang_T *slang = mip->mi_lp->lp_slang; - char_u *byts; - idx_T *idxs; + char_u *ptr; + slang_T *slang = mip->mi_lp->lp_slang; + char_u *byts; + idx_T *idxs; if (mode == FIND_KEEPWORD || mode == FIND_KEEPCOMPOUND) { // Check for word with matching case in keep-case tree. @@ -588,9 +586,10 @@ static void find_word(matchinf_T *mip, int mode) byts = slang->sl_kbyts; idxs = slang->sl_kidxs; - if (mode == FIND_KEEPCOMPOUND) + if (mode == FIND_KEEPCOMPOUND) { // Skip over the previously found word(s). wlen += mip->mi_compoff; + } } else { // Check for case-folded in case-folded tree. ptr = mip->mi_fword; @@ -607,12 +606,11 @@ static void find_word(matchinf_T *mip, int mode) wlen = mip->mi_compoff; flen -= mip->mi_compoff; } - } - if (byts == NULL) + if (byts == NULL) { return; // array is empty - + } idx_T arridx = 0; int endlen[MAXWLEN]; // length at possible word endings idx_T endidx[MAXWLEN]; // possible word endings @@ -625,8 +623,9 @@ static void find_word(matchinf_T *mip, int mode) // - we reach the end of the tree, // - or we reach the end of the line. for (;; ) { - if (flen <= 0 && *mip->mi_fend != NUL) + if (flen <= 0 && *mip->mi_fend != NUL) { flen = fold_more(mip); + } len = byts[arridx++]; @@ -648,35 +647,39 @@ static void find_word(matchinf_T *mip, int mode) ++arridx; --len; } - if (len == 0) + if (len == 0) { break; // no children, word must end here + } } // Stop looking at end of the line. - if (ptr[wlen] == NUL) + if (ptr[wlen] == NUL) { break; + } // Perform a binary search in the list of accepted bytes. c = ptr[wlen]; - if (c == TAB) // <Tab> is handled like <Space> + if (c == TAB) { // <Tab> is handled like <Space> c = ' '; + } idx_T lo = arridx; idx_T hi = arridx + len - 1; while (lo < hi) { idx_T m = (lo + hi) / 2; - if (byts[m] > c) + if (byts[m] > c) { hi = m - 1; - else if (byts[m] < c) + } else if (byts[m] < c) { lo = m + 1; - else { + } else { lo = hi = m; break; } } // Stop if there is no matching byte. - if (hi < lo || byts[lo] != c) + if (hi < lo || byts[lo] != c) { break; + } // Continue at the child (if there is one). arridx = idxs[lo]; @@ -687,10 +690,12 @@ static void find_word(matchinf_T *mip, int mode) // checked word. if (c == ' ') { for (;; ) { - if (flen <= 0 && *mip->mi_fend != NUL) + if (flen <= 0 && *mip->mi_fend != NUL) { flen = fold_more(mip); - if (ptr[wlen] != ' ' && ptr[wlen] != TAB) + } + if (ptr[wlen] != ' ' && ptr[wlen] != TAB) { break; + } ++wlen; --flen; } @@ -711,11 +716,13 @@ static void find_word(matchinf_T *mip, int mode) continue; // not at first byte of character } if (spell_iswordp(ptr + wlen, mip->mi_win)) { - if (slang->sl_compprog == NULL && !slang->sl_nobreak) + if (slang->sl_compprog == NULL && !slang->sl_nobreak) { continue; // next char is a word character + } word_ends = false; - } else + } else { word_ends = true; + } // The prefix flag is before compound flags. Once a valid prefix flag // has been found we try compound flags. bool prefix_found = false; @@ -754,23 +761,26 @@ static void find_word(matchinf_T *mip, int mode) } if (mip->mi_capflags == WF_KEEPCAP - || !spell_valid_case(mip->mi_capflags, flags)) + || !spell_valid_case(mip->mi_capflags, flags)) { continue; + } } // When mode is FIND_PREFIX the word must support the prefix: // check the prefix ID and the condition. Do that for the list at // mip->mi_prefarridx that find_prefix() filled. else if (mode == FIND_PREFIX && !prefix_found) { c = valid_word_prefix(mip->mi_prefcnt, mip->mi_prefarridx, - flags, - mip->mi_word + mip->mi_cprefixlen, slang, - false); - if (c == 0) + flags, + mip->mi_word + mip->mi_cprefixlen, slang, + false); + if (c == 0) { continue; + } // Use the WF_RARE flag for a rare prefix. - if (c & WF_RAREPFX) + if (c & WF_RAREPFX) { flags |= WF_RARE; + } prefix_found = true; } @@ -790,8 +800,9 @@ static void find_word(matchinf_T *mip, int mode) // that's too short... Myspell compatibility requires this // anyway. if (((unsigned)flags >> 24) == 0 - || wlen - mip->mi_compoff < slang->sl_compminlen) + || wlen - mip->mi_compoff < slang->sl_compminlen) { continue; + } // For multi-byte chars check character length against // COMPOUNDMIN. if (slang->sl_compminlen > 0 @@ -804,27 +815,32 @@ static void find_word(matchinf_T *mip, int mode) // maximum for syllables is specified. if (!word_ends && mip->mi_complen + mip->mi_compextra + 2 > slang->sl_compmax - && slang->sl_compsylmax == MAXWLEN) + && slang->sl_compsylmax == MAXWLEN) { continue; + } // Don't allow compounding on a side where an affix was added, // unless COMPOUNDPERMITFLAG was used. - if (mip->mi_complen > 0 && (flags & WF_NOCOMPBEF)) + if (mip->mi_complen > 0 && (flags & WF_NOCOMPBEF)) { continue; - if (!word_ends && (flags & WF_NOCOMPAFT)) + } + if (!word_ends && (flags & WF_NOCOMPAFT)) { continue; + } // Quickly check if compounding is possible with this flag. if (!byte_in_str(mip->mi_complen == 0 ? slang->sl_compstartflags : slang->sl_compallflags, - ((unsigned)flags >> 24))) + ((unsigned)flags >> 24))) { continue; + } // If there is a match with a CHECKCOMPOUNDPATTERN rule // discard the compound word. - if (match_checkcompoundpattern(ptr, wlen, &slang->sl_comppat)) + if (match_checkcompoundpattern(ptr, wlen, &slang->sl_comppat)) { continue; + } if (mode == FIND_COMPOUND) { int capflags; @@ -842,8 +858,9 @@ static void find_word(matchinf_T *mip, int mode) } capflags = captype(p, mip->mi_word + wlen); if (capflags == WF_KEEPCAP || (capflags == WF_ALLCAP - && (flags & WF_FIXCAP) != 0)) + && (flags & WF_FIXCAP) != 0)) { continue; + } if (capflags != WF_ALLCAP) { // When the character before the word is a word @@ -876,23 +893,26 @@ static void find_word(matchinf_T *mip, int mode) STRLCPY(fword, ptr, endlen[endidxcnt] + 1); } } - if (!can_compound(slang, fword, mip->mi_compflags)) + if (!can_compound(slang, fword, mip->mi_compflags)) { continue; + } } else if (slang->sl_comprules != NULL - && !match_compoundrule(slang, mip->mi_compflags)) + && !match_compoundrule(slang, mip->mi_compflags)) { // The compound flags collected so far do not match any // COMPOUNDRULE, discard the compounded word. continue; + } } // Check NEEDCOMPOUND: can't use word without compounding. - else if (flags & WF_NEEDCOMP) + else if (flags & WF_NEEDCOMP) { continue; + } int nobreak_result = SP_OK; if (!word_ends) { int save_result = mip->mi_result; - char_u *save_end = mip->mi_end; + char_u *save_end = mip->mi_end; langp_T *save_lp = mip->mi_lp; // Check that a valid word follows. If there is one and we @@ -900,8 +920,9 @@ static void find_word(matchinf_T *mip, int mode) // always finished here. For NOBREAK we only check that a // valid word follows. // Recursive! - if (slang->sl_nobreak) + if (slang->sl_nobreak) { mip->mi_result = SP_BAD; + } // Find following word in case-folded tree. mip->mi_compoff = endlen[endidxcnt]; @@ -922,8 +943,9 @@ static void find_word(matchinf_T *mip, int mode) c = mip->mi_compoff; #endif ++mip->mi_complen; - if (flags & WF_COMPROOT) + if (flags & WF_COMPROOT) { ++mip->mi_compextra; + } // For NOBREAK we need to try all NOBREAK languages, at least // to find the ".add" file(s). @@ -931,8 +953,9 @@ static void find_word(matchinf_T *mip, int mode) if (slang->sl_nobreak) { mip->mi_lp = LANGP_ENTRY(mip->mi_win->w_s->b_langp, lpi); if (mip->mi_lp->lp_slang->sl_fidxs == NULL - || !mip->mi_lp->lp_slang->sl_nobreak) + || !mip->mi_lp->lp_slang->sl_nobreak) { continue; + } } find_word(mip, FIND_COMPOUND); @@ -956,12 +979,14 @@ static void find_word(matchinf_T *mip, int mode) #endif } - if (!slang->sl_nobreak) + if (!slang->sl_nobreak) { break; + } } --mip->mi_complen; - if (flags & WF_COMPROOT) + if (flags & WF_COMPROOT) { --mip->mi_compextra; + } mip->mi_lp = save_lp; if (slang->sl_nobreak) { @@ -969,25 +994,28 @@ static void find_word(matchinf_T *mip, int mode) mip->mi_result = save_result; mip->mi_end = save_end; } else { - if (mip->mi_result == SP_OK) + if (mip->mi_result == SP_OK) { break; + } continue; } } int res = SP_BAD; - if (flags & WF_BANNED) + if (flags & WF_BANNED) { res = SP_BANNED; - else if (flags & WF_REGION) { + } else if (flags & WF_REGION) { // Check region. - if ((mip->mi_lp->lp_region & (flags >> 16)) != 0) + if ((mip->mi_lp->lp_region & (flags >> 16)) != 0) { res = SP_OK; - else + } else { res = SP_LOCAL; - } else if (flags & WF_RARE) + } + } else if (flags & WF_RARE) { res = SP_RARE; - else + } else { res = SP_OK; + } // Always use the longest match and the best result. For NOBREAK // we separately keep the longest match without a following good @@ -997,36 +1025,37 @@ static void find_word(matchinf_T *mip, int mode) mip->mi_result2 = res; mip->mi_end2 = mip->mi_word + wlen; } else if (mip->mi_result2 == res - && mip->mi_end2 < mip->mi_word + wlen) + && mip->mi_end2 < mip->mi_word + wlen) { mip->mi_end2 = mip->mi_word + wlen; + } } else if (mip->mi_result > res) { mip->mi_result = res; mip->mi_end = mip->mi_word + wlen; - } else if (mip->mi_result == res && mip->mi_end < mip->mi_word + wlen) + } else if (mip->mi_result == res && mip->mi_end < mip->mi_word + wlen) { mip->mi_end = mip->mi_word + wlen; + } - if (mip->mi_result == SP_OK) + if (mip->mi_result == SP_OK) { break; + } } - if (mip->mi_result == SP_OK) + if (mip->mi_result == SP_OK) { break; + } } } -// Returns true if there is a match between the word ptr[wlen] and -// CHECKCOMPOUNDPATTERN rules, assuming that we will concatenate with another -// word. -// A match means that the first part of CHECKCOMPOUNDPATTERN matches at the -// end of ptr[wlen] and the second part matches after it. -static bool -match_checkcompoundpattern ( - char_u *ptr, - int wlen, - garray_T *gap // &sl_comppat -) +/// Returns true if there is a match between the word ptr[wlen] and +/// CHECKCOMPOUNDPATTERN rules, assuming that we will concatenate with another +/// word. +/// A match means that the first part of CHECKCOMPOUNDPATTERN matches at the +/// end of ptr[wlen] and the second part matches after it. +/// +/// @param gap &sl_comppat +static bool match_checkcompoundpattern(char_u *ptr, int wlen, garray_T *gap) { - char_u *p; + char_u *p; int len; for (int i = 0; i + 1 < gap->ga_len; i += 2) { @@ -1036,8 +1065,9 @@ match_checkcompoundpattern ( // check if first part matches at end of previous word. p = ((char_u **)gap->ga_data)[i]; len = (int)STRLEN(p); - if (len <= wlen && STRNCMP(ptr + wlen - len, p, len) == 0) + if (len <= wlen && STRNCMP(ptr + wlen - len, p, len) == 0) { return true; + } } } return false; @@ -1045,8 +1075,7 @@ match_checkcompoundpattern ( // Returns true if "flags" is a valid sequence of compound flags and "word" // does not have too many syllables. -static bool can_compound(slang_T *slang, const char_u *word, - const char_u *flags) +static bool can_compound(slang_T *slang, const char_u *word, const char_u *flags) FUNC_ATTR_NONNULL_ALL { char_u uflags[MAXWLEN * 2] = { 0 }; @@ -1069,8 +1098,9 @@ static bool can_compound(slang_T *slang, const char_u *word, // are too many syllables AND the number of compound words is above // COMPOUNDWORDMAX then compounding is not allowed. if (slang->sl_compsylmax < MAXWLEN - && count_syllables(slang, word) > slang->sl_compsylmax) + && count_syllables(slang, word) > slang->sl_compsylmax) { return (int)STRLEN(flags) < slang->sl_compmax; + } return true; } @@ -1082,8 +1112,9 @@ static bool can_be_compound(trystate_T *sp, slang_T *slang, char_u *compflags, i // If the flag doesn't appear in sl_compstartflags or sl_compallflags // then it can't possibly compound. if (!byte_in_str(sp->ts_complen == sp->ts_compsplit - ? slang->sl_compstartflags : slang->sl_compallflags, flag)) + ? slang->sl_compstartflags : slang->sl_compallflags, flag)) { return false; + } // If there are no wildcards, we can check if the flags collected so far // possibly can form a match with COMPOUNDRULE patterns. This only @@ -1105,7 +1136,7 @@ static bool can_be_compound(trystate_T *sp, slang_T *slang, char_u *compflags, i // Caller must check that slang->sl_comprules is not NULL. static bool match_compoundrule(slang_T *slang, char_u *compflags) { - char_u *p; + char_u *p; int i; int c; @@ -1115,30 +1146,37 @@ static bool match_compoundrule(slang_T *slang, char_u *compflags) // them against the current rule entry for (i = 0;; ++i) { c = compflags[i]; - if (c == NUL) + if (c == NUL) { // found a rule that matches for the flags we have so far return true; - if (*p == '/' || *p == NUL) + } + if (*p == '/' || *p == NUL) { break; // end of rule, it's too short + } if (*p == '[') { bool match = false; // compare against all the flags in [] ++p; - while (*p != ']' && *p != NUL) - if (*p++ == c) + while (*p != ']' && *p != NUL) { + if (*p++ == c) { match = true; - if (!match) + } + } + if (!match) { break; // none matches - } else if (*p != c) + } + } else if (*p != c) { break; // flag of word doesn't match flag in pattern + } ++p; } // Skip to the next "/", where the next pattern starts. p = vim_strchr(p, '/'); - if (p == NULL) + if (p == NULL) { break; + } } // Checked all the rules and none of them match the flags, so there @@ -1146,18 +1184,15 @@ static bool match_compoundrule(slang_T *slang, char_u *compflags) return false; } -// Return non-zero if the prefix indicated by "arridx" matches with the prefix -// ID in "flags" for the word "word". -// The WF_RAREPFX flag is included in the return value for a rare prefix. -static int -valid_word_prefix ( - int totprefcnt, // nr of prefix IDs - int arridx, // idx in sl_pidxs[] - int flags, - char_u *word, - slang_T *slang, - bool cond_req // only use prefixes with a condition -) +/// Return non-zero if the prefix indicated by "arridx" matches with the prefix +/// ID in "flags" for the word "word". +/// The WF_RAREPFX flag is included in the return value for a rare prefix. +/// +/// @param totprefcnt nr of prefix IDs +/// @param arridx idx in sl_pidxs[] +/// @param cond_req only use prefixes with a condition +static int valid_word_prefix(int totprefcnt, int arridx, int flags, char_u *word, slang_T *slang, + bool cond_req) { int prefcnt; int pidx; @@ -1168,13 +1203,15 @@ valid_word_prefix ( pidx = slang->sl_pidxs[arridx + prefcnt]; // Check the prefix ID. - if (prefid != (pidx & 0xff)) + if (prefid != (pidx & 0xff)) { continue; + } // Check if the prefix doesn't combine and the word already has a // suffix. - if ((flags & WF_HAS_AFF) && (pidx & WF_PFX_NC)) + if ((flags & WF_HAS_AFF) && (pidx & WF_PFX_NC)) { continue; + } // Check the condition, if there is one. The condition index is // stored in the two bytes above the prefix ID byte. @@ -1183,8 +1220,9 @@ valid_word_prefix ( if (!vim_regexec_prog(rp, false, word, 0)) { continue; } - } else if (cond_req) + } else if (cond_req) { continue; + } // It's a match! Return the WF_ flags. return pidx; @@ -1206,16 +1244,16 @@ static void find_prefix(matchinf_T *mip, int mode) int wlen = 0; int flen; int c; - char_u *ptr; + char_u *ptr; idx_T lo, hi, m; - slang_T *slang = mip->mi_lp->lp_slang; - char_u *byts; - idx_T *idxs; + slang_T *slang = mip->mi_lp->lp_slang; + char_u *byts; + idx_T *idxs; byts = slang->sl_pbyts; - if (byts == NULL) + if (byts == NULL) { return; // array is empty - + } // We use the case-folded word here, since prefixes are always // case-folded. ptr = mip->mi_fword; @@ -1232,8 +1270,9 @@ static void find_prefix(matchinf_T *mip, int mode) // - we reach the end of the tree, // - or we reach the end of the line. for (;; ) { - if (flen == 0 && *mip->mi_fend != NUL) + if (flen == 0 && *mip->mi_fend != NUL) { flen = fold_more(mip); + } len = byts[arridx++]; @@ -1254,9 +1293,10 @@ static void find_prefix(matchinf_T *mip, int mode) // Find the word that comes after the prefix. mip->mi_prefixlen = wlen; - if (mode == FIND_COMPOUND) + if (mode == FIND_COMPOUND) { // Skip over the previously found word(s). mip->mi_prefixlen += mip->mi_compoff; + } // Case-folded length may differ from original length. mip->mi_cprefixlen = nofold_len(mip->mi_fword, mip->mi_prefixlen, @@ -1264,13 +1304,15 @@ static void find_prefix(matchinf_T *mip, int mode) find_word(mip, FIND_PREFIX); - if (len == 0) + if (len == 0) { break; // no children, word must end here + } } // Stop looking at end of the line. - if (ptr[wlen] == NUL) + if (ptr[wlen] == NUL) { break; + } // Perform a binary search in the list of accepted bytes. c = ptr[wlen]; @@ -1278,19 +1320,20 @@ static void find_prefix(matchinf_T *mip, int mode) hi = arridx + len - 1; while (lo < hi) { m = (lo + hi) / 2; - if (byts[m] > c) + if (byts[m] > c) { hi = m - 1; - else if (byts[m] < c) + } else if (byts[m] < c) { lo = m + 1; - else { + } else { lo = hi = m; break; } } // Stop if there is no matching byte. - if (hi < lo || byts[lo] != c) + if (hi < lo || byts[lo] != c) { break; + } // Continue at the child (if there is one). arridx = idxs[lo]; @@ -1305,7 +1348,7 @@ static void find_prefix(matchinf_T *mip, int mode) static int fold_more(matchinf_T *mip) { int flen; - char_u *p; + char_u *p; p = mip->mi_fend; do { @@ -1349,42 +1392,40 @@ static bool no_spell_checking(win_T *wp) return false; } -// Moves to the next spell error. -// "curline" is false for "[s", "]s", "[S" and "]S". -// "curline" is true to find word under/after cursor in the same line. -// For Insert mode completion "dir" is BACKWARD and "curline" is true: move -// to after badly spelled word before the cursor. -// Return 0 if not found, length of the badly spelled word otherwise. -size_t -spell_move_to ( - win_T *wp, - int dir, // FORWARD or BACKWARD - bool allwords, // true for "[s"/"]s", false for "[S"/"]S" - bool curline, - hlf_T *attrp // return: attributes of bad word or NULL - // (only when "dir" is FORWARD) -) +/// Moves to the next spell error. +/// "curline" is false for "[s", "]s", "[S" and "]S". +/// "curline" is true to find word under/after cursor in the same line. +/// For Insert mode completion "dir" is BACKWARD and "curline" is true: move +/// to after badly spelled word before the cursor. +/// +/// @param dir FORWARD or BACKWARD +/// @param allwords true for "[s"/"]s", false for "[S"/"]S" +/// @param attrp return: attributes of bad word or NULL (only when "dir" is FORWARD) +/// +/// @return 0 if not found, length of the badly spelled word otherwise. +size_t spell_move_to(win_T *wp, int dir, bool allwords, bool curline, hlf_T *attrp) { linenr_T lnum; pos_T found_pos; size_t found_len = 0; - char_u *line; - char_u *p; - char_u *endp; + char_u *line; + char_u *p; + char_u *endp; hlf_T attr = HLF_COUNT; size_t len; int has_syntax = syntax_present(wp); int col; bool can_spell; - char_u *buf = NULL; + char_u *buf = NULL; size_t buflen = 0; int skip = 0; int capcol = -1; bool found_one = false; bool wrapped = false; - if (no_spell_checking(wp)) + if (no_spell_checking(wp)) { return 0; + } // Start looking for bad word at the start of the line, because we can't // start halfway through a word, we don't know where it starts or ends. @@ -1410,8 +1451,9 @@ spell_move_to ( assert(buf && buflen >= len + MAXWLEN + 2); // In first line check first word for Capital. - if (lnum == 1) + if (lnum == 1) { capcol = 0; + } // For checking first word with a capital skip white space. if (capcol == 0) { @@ -1431,10 +1473,11 @@ spell_move_to ( // Copy the line into "buf" and append the start of the next line if // possible. STRCPY(buf, line); - if (lnum < wp->w_buffer->b_ml.ml_line_count) + if (lnum < wp->w_buffer->b_ml.ml_line_count) { spell_cat_line(buf + STRLEN(buf), ml_get_buf(wp->w_buffer, lnum + 1, false), MAXWLEN); + } p = buf + skip; endp = buf + len; while (p < endp) { @@ -1443,8 +1486,9 @@ spell_move_to ( if (dir == BACKWARD && lnum == wp->w_cursor.lnum && !wrapped - && (colnr_T)(p - buf) >= wp->w_cursor.col) + && (colnr_T)(p - buf) >= wp->w_cursor.col) { break; + } // start of word attr = HLF_COUNT; @@ -1464,11 +1508,13 @@ spell_move_to ( if (has_syntax) { col = (int)(p - buf); (void)syn_get_id(wp, lnum, (colnr_T)col, - FALSE, &can_spell, FALSE); - if (!can_spell) + FALSE, &can_spell, FALSE); + if (!can_spell) { attr = HLF_COUNT; - } else + } + } else { can_spell = true; + } if (can_spell) { found_one = true; @@ -1479,8 +1525,9 @@ spell_move_to ( // No need to search further. wp->w_cursor = found_pos; xfree(buf); - if (attrp != NULL) + if (attrp != NULL) { *attrp = attr; + } return len; } else if (curline) { // Insert mode completion: put cursor after @@ -1490,8 +1537,9 @@ spell_move_to ( } found_len = len; } - } else + } else { found_one = true; + } } } @@ -1529,22 +1577,24 @@ spell_move_to ( // starting line again and accept the last match. lnum = wp->w_buffer->b_ml.ml_line_count; wrapped = true; - if (!shortmess(SHM_SEARCH)) + if (!shortmess(SHM_SEARCH)) { give_warning((char_u *)_(top_bot_msg), true); + } } capcol = -1; } else { - if (lnum < wp->w_buffer->b_ml.ml_line_count) + if (lnum < wp->w_buffer->b_ml.ml_line_count) { ++lnum; - else if (!p_ws) + } else if (!p_ws) { break; // at first line and 'nowrapscan' - else { + } else { // Wrap around to the start of the buffer. May search the // starting line again and accept the first match. lnum = 1; wrapped = true; - if (!shortmess(SHM_SEARCH)) + if (!shortmess(SHM_SEARCH)) { give_warning((char_u *)_(bot_top_msg), true); + } } // If we are back at the starting line and there is no match then @@ -1555,17 +1605,19 @@ spell_move_to ( // Skip the characters at the start of the next line that were // included in a match crossing line boundaries. - if (attr == HLF_COUNT) + if (attr == HLF_COUNT) { skip = (int)(p - endp); - else + } else { skip = 0; + } // Capcol skips over the inserted space. --capcol; // But after empty line check first word in next line - if (*skipwhite(line) == NUL) + if (*skipwhite(line) == NUL) { capcol = 0; + } } line_breakcheck(); @@ -1581,12 +1633,13 @@ spell_move_to ( // to skip those bytes if the word was OK. void spell_cat_line(char_u *buf, char_u *line, int maxlen) { - char_u *p; + char_u *p; int n; p = skipwhite(line); - while (vim_strchr((char_u *)"*#/\"\t", *p) != NULL) + while (vim_strchr((char_u *)"*#/\"\t", *p) != NULL) { p = skipwhite(p + 1); + } if (*p != NUL) { // Only worth concatenating if there is something else than spaces to @@ -1630,8 +1683,9 @@ static void spell_load_lang(char_u *lang) if (r == FAIL && *sl.sl_lang != NUL && round == 1 && apply_autocmds(EVENT_SPELLFILEMISSING, lang, - curbuf->b_fname, FALSE, curbuf)) + curbuf->b_fname, FALSE, curbuf)) { continue; + } break; } break; @@ -1647,9 +1701,8 @@ static void spell_load_lang(char_u *lang) lang); do_cmdline_cmd(autocmd_buf); } else { - smsg( - _("Warning: Cannot find word list \"%s.%s.spl\" or \"%s.ascii.spl\""), - lang, spell_enc(), lang); + smsg(_("Warning: Cannot find word list \"%s.%s.spl\" or \"%s.ascii.spl\""), + lang, spell_enc(), lang); } } else if (sl.sl_slang != NULL) { // At least one file was loaded, now load ALL the additions. @@ -1662,9 +1715,9 @@ static void spell_load_lang(char_u *lang) // use "latin1" for "latin9". And limit to 60 characters (just in case). char_u *spell_enc(void) { - - if (STRLEN(p_enc) < 60 && STRCMP(p_enc, "iso-8859-15") != 0) + if (STRLEN(p_enc) < 60 && STRCMP(p_enc, "iso-8859-15") != 0) { return p_enc; + } return (char_u *)"latin1"; } @@ -1673,7 +1726,7 @@ char_u *spell_enc(void) static void int_wordlist_spl(char_u *fname) { vim_snprintf((char *)fname, MAXPATHL, SPL_FNAME_TMPL, - int_wordlist, spell_enc()); + int_wordlist, spell_enc()); } // Allocate a new slang_T for language "lang". "lang" can be NULL. @@ -1683,8 +1736,9 @@ slang_T *slang_alloc(char_u *lang) { slang_T *lp = xcalloc(1, sizeof(slang_T)); - if (lang != NULL) + if (lang != NULL) { lp->sl_name = vim_strsave(lang); + } ga_init(&lp->sl_rep, sizeof(fromto_T), 10); ga_init(&lp->sl_repsal, sizeof(fromto_T), 10); lp->sl_compmax = MAXWLEN; @@ -1722,7 +1776,7 @@ static void free_fromto(fromto_T *ftp) { // Clear an slang_T so that the file can be reloaded. void slang_clear(slang_T *lp) { - garray_T *gap; + garray_T *gap; XFREE_CLEAR(lp->sl_fbyts); XFREE_CLEAR(lp->sl_kbyts); @@ -1792,17 +1846,18 @@ void slang_clear_sug(slang_T *lp) // Invoked through do_in_runtimepath(). static void spell_load_cb(char_u *fname, void *cookie) { - spelload_T *slp = (spelload_T *)cookie; - slang_T *slang; + spelload_T *slp = (spelload_T *)cookie; + slang_T *slang; slang = spell_load_file(fname, slp->sl_lang, NULL, false); if (slang != NULL) { // When a previously loaded file has NOBREAK also use it for the // ".add" files. - if (slp->sl_nobreak && slang->sl_add) + if (slp->sl_nobreak && slang->sl_add) { slang->sl_nobreak = true; - else if (slang->sl_nobreak) + } else if (slang->sl_nobreak) { slp->sl_nobreak = true; + } slp->sl_slang = slang; } @@ -1818,10 +1873,10 @@ static void spell_load_cb(char_u *fname, void *cookie) void count_common_word(slang_T *lp, char_u *word, int len, int count) { hash_T hash; - hashitem_T *hi; + hashitem_T *hi; wordcount_T *wc; char_u buf[MAXWLEN]; - char_u *p; + char_u *p; if (len == -1) { p = word; @@ -1842,21 +1897,18 @@ void count_common_word(slang_T *lp, char_u *word, int len, int count) hash_add_item(&lp->sl_wordcount, hi, wc->wc_word, hash); } else { wc = HI2WC(hi); - if ((wc->wc_count += count) < (unsigned)count) // check for overflow + if ((wc->wc_count += count) < (unsigned)count) { // check for overflow wc->wc_count = MAXWORDCOUNT; + } } } -// Adjust the score of common words. -static int -score_wordcount_adj ( - slang_T *slang, - int score, - char_u *word, - bool split // word was split, less bonus -) +/// Adjust the score of common words. +/// +/// @param split word was split, less bonus +static int score_wordcount_adj(slang_T *slang, int score, char_u *word, bool split) { - hashitem_T *hi; + hashitem_T *hi; wordcount_T *wc; int bonus; int newscore; @@ -1864,18 +1916,21 @@ score_wordcount_adj ( hi = hash_find(&slang->sl_wordcount, word); if (!HASHITEM_EMPTY(hi)) { wc = HI2WC(hi); - if (wc->wc_count < SCORE_THRES2) + if (wc->wc_count < SCORE_THRES2) { bonus = SCORE_COMMON1; - else if (wc->wc_count < SCORE_THRES3) + } else if (wc->wc_count < SCORE_THRES3) { bonus = SCORE_COMMON2; - else + } else { bonus = SCORE_COMMON3; - if (split) + } + if (split) { newscore = score - bonus / 2; - else + } else { newscore = score - bonus; - if (newscore < 0) + } + if (newscore < 0) { return 0; + } return newscore; } return score; @@ -1885,11 +1940,13 @@ score_wordcount_adj ( // Like strchr() but independent of locale. bool byte_in_str(char_u *str, int n) { - char_u *p; + char_u *p; - for (p = str; *p != NUL; ++p) - if (*p == n) + for (p = str; *p != NUL; ++p) { + if (*p == n) { return true; + } + } return false; } @@ -1897,24 +1954,27 @@ bool byte_in_str(char_u *str, int n) // in "slang->sl_syl_items". int init_syl_tab(slang_T *slang) { - char_u *p; - char_u *s; + char_u *p; + char_u *s; int l; ga_init(&slang->sl_syl_items, sizeof(syl_item_T), 4); p = vim_strchr(slang->sl_syllable, '/'); while (p != NULL) { *p++ = NUL; - if (*p == NUL) // trailing slash + if (*p == NUL) { // trailing slash break; + } s = p; p = vim_strchr(p, '/'); - if (p == NULL) + if (p == NULL) { l = (int)STRLEN(s); - else + } else { l = (int)(p - s); - if (l >= SY_MAXLEN) + } + if (l >= SY_MAXLEN) { return SP_FORMERROR; + } syl_item_T *syl = GA_APPEND_VIA_PTR(syl_item_T, &slang->sl_syl_items); STRLCPY(syl->sy_chars, s, l + 1); @@ -1932,11 +1992,12 @@ static int count_syllables(slang_T *slang, const char_u *word) int cnt = 0; bool skip = false; int len; - syl_item_T *syl; + syl_item_T *syl; int c; - if (slang->sl_syllable == NULL) + if (slang->sl_syllable == NULL) { return 0; + } for (const char_u *p = word; *p != NUL; p += len) { // When running into a space reset counter. @@ -1951,8 +2012,9 @@ static int count_syllables(slang_T *slang, const char_u *word) for (int i = 0; i < slang->sl_syl_items.ga_len; ++i) { syl = ((syl_item_T *)slang->sl_syl_items.ga_data) + i; if (syl->sy_len > len - && STRNCMP(p, syl->sy_chars, syl->sy_len) == 0) + && STRNCMP(p, syl->sy_chars, syl->sy_len) == 0) { len = syl->sy_len; + } } if (len != 0) { // found a match, count syllable ++cnt; @@ -1961,9 +2023,9 @@ static int count_syllables(slang_T *slang, const char_u *word) // No recognized syllable item, at least a syllable char then? c = utf_ptr2char(p); len = (*mb_ptr2len)(p); - if (vim_strchr(slang->sl_syllable, c) == NULL) + if (vim_strchr(slang->sl_syllable, c) == NULL) { skip = false; // No, search for next syllable - else if (!skip) { + } else if (!skip) { ++cnt; // Yes, count it skip = true; // don't count following syllable chars } @@ -1977,26 +2039,26 @@ static int count_syllables(slang_T *slang, const char_u *word) char_u *did_set_spelllang(win_T *wp) { garray_T ga; - char_u *splp; - char_u *region; + char_u *splp; + char_u *region; char_u region_cp[3]; bool filename; int region_mask; - slang_T *slang; + slang_T *slang; int c; char_u lang[MAXWLEN + 1]; char_u spf_name[MAXPATHL]; int len; - char_u *p; + char_u *p; int round; - char_u *spf; - char_u *use_region = NULL; + char_u *spf; + char_u *use_region = NULL; bool dont_use_region = false; bool nobreak = false; - langp_T *lp, *lp2; + langp_T *lp, *lp2; static bool recursive = false; - char_u *ret_msg = NULL; - char_u *spl_copy; + char_u *ret_msg = NULL; + char_u *spl_copy; bufref_T bufref; set_bufref(&bufref, wp->w_buffer); @@ -2004,8 +2066,9 @@ char_u *did_set_spelllang(win_T *wp) // We don't want to do this recursively. May happen when a language is // not available and the SpellFileMissing autocommand opens a new buffer // in which 'spell' is set. - if (recursive) + if (recursive) { return NULL; + } recursive = true; ga_init(&ga, sizeof(langp_T), 2); @@ -2046,8 +2109,9 @@ char_u *did_set_spelllang(win_T *wp) STRLCPY(region_cp, p + 1, 3); memmove(p, p + 3, len - (p - lang) - 2); region = region_cp; - } else + } else { dont_use_region = true; + } // Check if we loaded this language before. for (slang = first_lang; slang != NULL; slang = slang->sl_next) { @@ -2061,28 +2125,32 @@ char_u *did_set_spelllang(win_T *wp) if (len > 3 && lang[len - 3] == '_') { region = lang + len - 2; lang[len - 3] = NUL; - } else + } else { dont_use_region = true; + } // Check if we loaded this language before. - for (slang = first_lang; slang != NULL; slang = slang->sl_next) - if (STRICMP(lang, slang->sl_name) == 0) + for (slang = first_lang; slang != NULL; slang = slang->sl_next) { + if (STRICMP(lang, slang->sl_name) == 0) { break; + } + } } if (region != NULL) { // If the region differs from what was used before then don't // use it for 'spellfile'. - if (use_region != NULL && STRCMP(region, use_region) != 0) + if (use_region != NULL && STRCMP(region, use_region) != 0) { dont_use_region = true; + } use_region = region; } // If not found try loading the language now. if (slang == NULL) { - if (filename) + if (filename) { (void)spell_load_file(lang, lang, NULL, false); - else { + } else { spell_load_lang(lang); // SpellFileMissing autocommands may do anything, including // destroying the buffer we are using... @@ -2105,16 +2173,19 @@ char_u *did_set_spelllang(win_T *wp) c = find_region(slang->sl_regions, region); if (c == REGION_ALL) { if (slang->sl_add) { - if (*slang->sl_regions != NUL) + if (*slang->sl_regions != NUL) { // This addition file is for other regions. region_mask = 0; - } else + } + } else { // This is probably an error. Give a warning and // accept the words anyway. smsg(_("Warning: region %s not supported"), region); - } else + } + } else { region_mask = 1 << c; + } } if (region_mask != 0) { @@ -2123,8 +2194,9 @@ char_u *did_set_spelllang(win_T *wp) p_->lp_region = region_mask; use_midword(slang, wp); - if (slang->sl_nobreak) + if (slang->sl_nobreak) { nobreak = true; + } } } } @@ -2138,8 +2210,9 @@ char_u *did_set_spelllang(win_T *wp) for (round = 0; round == 0 || *spf != NUL; ++round) { if (round == 0) { // Internal wordlist, if there is one. - if (int_wordlist == NULL) + if (int_wordlist == NULL) { continue; + } int_wordlist_spl(spf_name); } else { // One entry in 'spellfile'. @@ -2154,8 +2227,9 @@ char_u *did_set_spelllang(win_T *wp) break; } } - if (c < ga.ga_len) + if (c < ga.ga_len) { continue; + } } // Check if it was loaded already. @@ -2169,31 +2243,34 @@ char_u *did_set_spelllang(win_T *wp) // Not loaded, try loading it now. The language name includes the // region name, the region is ignored otherwise. for int_wordlist // use an arbitrary name. - if (round == 0) + if (round == 0) { STRCPY(lang, "internal wordlist"); - else { + } else { STRLCPY(lang, path_tail(spf_name), MAXWLEN + 1); p = vim_strchr(lang, '.'); - if (p != NULL) + if (p != NULL) { *p = NUL; // truncate at ".encoding.add" + } } slang = spell_load_file(spf_name, lang, NULL, true); // If one of the languages has NOBREAK we assume the addition // files also have this. - if (slang != NULL && nobreak) + if (slang != NULL && nobreak) { slang->sl_nobreak = true; + } } if (slang != NULL) { region_mask = REGION_ALL; if (use_region != NULL && !dont_use_region) { // find region in sl_regions c = find_region(slang->sl_regions, use_region); - if (c != REGION_ALL) + if (c != REGION_ALL) { region_mask = 1 << c; - else if (*slang->sl_regions != NUL) + } else if (*slang->sl_regions != NUL) { // This spell file is for other regions. region_mask = 0; + } } if (region_mask != 0) { @@ -2219,36 +2296,38 @@ char_u *did_set_spelllang(win_T *wp) lp = LANGP_ENTRY(ga, i); // sound folding - if (!GA_EMPTY(&lp->lp_slang->sl_sal)) + if (!GA_EMPTY(&lp->lp_slang->sl_sal)) { // language does sound folding itself lp->lp_sallang = lp->lp_slang; - else + } else { // find first similar language that does sound folding for (int j = 0; j < ga.ga_len; ++j) { lp2 = LANGP_ENTRY(ga, j); if (!GA_EMPTY(&lp2->lp_slang->sl_sal) && STRNCMP(lp->lp_slang->sl_name, - lp2->lp_slang->sl_name, 2) == 0) { + lp2->lp_slang->sl_name, 2) == 0) { lp->lp_sallang = lp2->lp_slang; break; } } + } // REP items - if (!GA_EMPTY(&lp->lp_slang->sl_rep)) + if (!GA_EMPTY(&lp->lp_slang->sl_rep)) { // language has REP items itself lp->lp_replang = lp->lp_slang; - else + } else { // find first similar language that has REP items for (int j = 0; j < ga.ga_len; ++j) { lp2 = LANGP_ENTRY(ga, j); if (!GA_EMPTY(&lp2->lp_slang->sl_rep) && STRNCMP(lp->lp_slang->sl_name, - lp2->lp_slang->sl_name, 2) == 0) { + lp2->lp_slang->sl_name, 2) == 0) { lp->lp_replang = lp2->lp_slang; break; } } + } } theend: @@ -2302,10 +2381,12 @@ static int find_region(char_u *rp, char_u *region) int i; for (i = 0;; i += 2) { - if (rp[i] == NUL) + if (rp[i] == NUL) { return REGION_ALL; - if (rp[i] == region[0] && rp[i + 1] == region[1]) + } + if (rp[i] == region[0] && rp[i + 1] == region[1]) { break; + } } return i / 2; } @@ -2323,7 +2404,7 @@ static int find_region(char_u *rp, char_u *region) int captype(char_u *word, char_u *end) FUNC_ATTR_NONNULL_ARG(1) { - char_u *p; + char_u *p; int firstcap; bool allcap; bool past_second = false; // past second word char @@ -2356,10 +2437,12 @@ int captype(char_u *word, char_u *end) } } - if (allcap) + if (allcap) { return WF_ALLCAP; - if (firstcap) + } + if (firstcap) { return WF_ONECAP; + } return 0; } @@ -2373,7 +2456,7 @@ static int badword_captype(char_u *word, char_u *end) int c; int l, u; bool first; - char_u *p; + char_u *p; if (flags & WF_KEEPCAP) { // Count the number of UPPER and lower case letters. @@ -2383,23 +2466,27 @@ static int badword_captype(char_u *word, char_u *end) c = PTR2CHAR(p); if (SPELL_ISUPPER(c)) { ++u; - if (p == word) + if (p == word) { first = true; - } else + } + } else { ++l; + } } // If there are more UPPER than lower case letters suggest an // ALLCAP word. Otherwise, if the first letter is UPPER then // suggest ONECAP. Exception: "ALl" most likely should be "All", // require three upper case letters. - if (u > l && u > 2) + if (u > l && u > 2) { flags |= WF_ALLCAP; - else if (first) + } else if (first) { flags |= WF_ONECAP; + } - if (u >= 2 && l >= 2) // maCARONI maCAroni + if (u >= 2 && l >= 2) { // maCARONI maCAroni flags |= WF_MIXCAP; + } } return flags; } @@ -2407,7 +2494,7 @@ static int badword_captype(char_u *word, char_u *end) // Delete the internal wordlist and its .spl file. void spell_delete_wordlist(void) { - char_u fname[MAXPATHL] = {0}; + char_u fname[MAXPATHL] = { 0 }; if (int_wordlist != NULL) { os_remove((char *)int_wordlist); @@ -2420,7 +2507,7 @@ void spell_delete_wordlist(void) // Free all languages. void spell_free_all(void) { - slang_T *slang; + slang_T *slang; // Go through all buffers and handle 'spelllang'. <VN> FOR_ALL_BUFFERS(buf) { @@ -2475,10 +2562,10 @@ static int bytes2offset(char_u **pp) c = *p++; if ((c & 0x80) == 0x00) { // 1 byte nr = c - 1; - } else if ((c & 0xc0) == 0x80) { // 2 bytes + } else if ((c & 0xc0) == 0x80) { // 2 bytes nr = (c & 0x3f) - 1; nr = nr * 255 + (*p++ - 1); - } else if ((c & 0xe0) == 0xc0) { // 3 bytes + } else if ((c & 0xe0) == 0xc0) { // 3 bytes nr = (c & 0x1f) - 1; nr = nr * 255 + (*p++ - 1); nr = nr * 255 + (*p++ - 1); @@ -2537,8 +2624,9 @@ void clear_spell_chartab(spelltab_T *sp) // We include digits. A word shouldn't start with a digit, but handling // that is done separately. - for (i = '0'; i <= '9'; ++i) + for (i = '0'; i <= '9'; ++i) { sp->st_isw[i] = true; + } for (i = 'A'; i <= 'Z'; ++i) { sp->st_isw[i] = true; sp->st_isu[i] = true; @@ -2627,9 +2715,10 @@ bool spell_iswordp_nmw(const char_u *p, win_T *wp) static bool spell_mb_isword_class(int cl, const win_T *wp) FUNC_ATTR_PURE FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT { - if (wp->w_s->b_cjk) + if (wp->w_s->b_cjk) { // East Asian characters are not considered word characters. return cl == 2 || cl == 0x2800; + } return cl >= 2 && cl != 0x2070 && cl != 0x2080 && cl != 3; } @@ -2641,11 +2730,12 @@ static bool spell_iswordp_w(const int *p, const win_T *wp) const int *s; if (*p < 256 ? wp->w_s->b_spell_ismw[*p] - : (wp->w_s->b_spell_ismw_mb != NULL - && vim_strchr(wp->w_s->b_spell_ismw_mb, *p) != NULL)) + : (wp->w_s->b_spell_ismw_mb != NULL + && vim_strchr(wp->w_s->b_spell_ismw_mb, *p) != NULL)) { s = p + 1; - else + } else { s = p; + } if (*s > 255) { return spell_mb_isword_class(utf_class(*s), wp); @@ -2657,8 +2747,7 @@ static bool spell_iswordp_w(const int *p, const win_T *wp) // Uses the character definitions from the .spl file. // When using a multi-byte 'encoding' the length may change! // Returns FAIL when something wrong. -int spell_casefold(const win_T *wp, char_u *str, int len, char_u *buf, - int buflen) +int spell_casefold(const win_T *wp, char_u *str, int len, char_u *buf, int buflen) FUNC_ATTR_NONNULL_ALL { if (len >= buflen) { @@ -2708,8 +2797,8 @@ static int sps_limit = 9999; // max nr of suggestions given // Sets "sps_flags" and "sps_limit". int spell_check_sps(void) { - char_u *p; - char_u *s; + char_u *p; + char_u *s; char_u buf[MAXPATHL]; int f; @@ -2742,12 +2831,14 @@ int spell_check_sps(void) sps_limit = 9999; return FAIL; } - if (f != 0) + if (f != 0) { sps_flags = f; + } } - if (sps_flags == 0) + if (sps_flags == 0) { sps_flags = SPS_BEST; + } return OK; } @@ -2758,13 +2849,13 @@ int spell_check_sps(void) // When "count" is non-zero use that suggestion. void spell_suggest(int count) { - char_u *line; + char_u *line; pos_T prev_cursor = curwin->w_cursor; char_u wcopy[MAXWLEN + 2]; - char_u *p; + char_u *p; int c; suginfo_T sug; - suggest_T *stp; + suggest_T *stp; int mouse_used; int need_cap; int limit; @@ -2833,36 +2924,39 @@ void spell_suggest(int count) // Get the list of suggestions. Limit to 'lines' - 2 or the number in // 'spellsuggest', whatever is smaller. - if (sps_limit > (int)Rows - 2) + if (sps_limit > (int)Rows - 2) { limit = (int)Rows - 2; - else + } else { limit = sps_limit; + } spell_find_suggest(line + curwin->w_cursor.col, badlen, &sug, limit, - true, need_cap, true); + true, need_cap, true); - if (GA_EMPTY(&sug.su_ga)) + if (GA_EMPTY(&sug.su_ga)) { MSG(_("Sorry, no suggestions")); - else if (count > 0) { - if (count > sug.su_ga.ga_len) + } else if (count > 0) { + if (count > sug.su_ga.ga_len) { smsg(_("Sorry, only %" PRId64 " suggestions"), (int64_t)sug.su_ga.ga_len); + } } else { // When 'rightleft' is set the list is drawn right-left. cmdmsg_rl = curwin->w_p_rl; - if (cmdmsg_rl) + if (cmdmsg_rl) { msg_col = Columns - 1; + } // List the suggestions. msg_start(); msg_row = Rows - 1; // for when 'cmdheight' > 1 lines_left = Rows; // avoid more prompt vim_snprintf((char *)IObuff, IOSIZE, _("Change \"%.*s\" to:"), - sug.su_badlen, sug.su_badptr); + sug.su_badlen, sug.su_badptr); if (cmdmsg_rl && STRNCMP(IObuff, "Change", 6) == 0) { // And now the rabbit from the high hat: Avoid showing the // untranslated message rightleft. vim_snprintf((char *)IObuff, IOSIZE, ":ot \"%.*s\" egnahC", - sug.su_badlen, sug.su_badptr); + sug.su_badlen, sug.su_badptr); } msg_puts((const char *)IObuff); msg_clr_eos(); @@ -2875,10 +2969,11 @@ void spell_suggest(int count) // The suggested word may replace only part of the bad word, add // the not replaced part. STRLCPY(wcopy, stp->st_word, MAXWLEN + 1); - if (sug.su_badlen > stp->st_orglen) + if (sug.su_badlen > stp->st_orglen) { STRLCPY(wcopy + stp->st_wordlen, - sug.su_badptr + stp->st_orglen, - sug.su_badlen - stp->st_orglen + 1); + sug.su_badptr + stp->st_orglen, + sug.su_badlen - stp->st_orglen + 1); + } vim_snprintf((char *)IObuff, IOSIZE, "%2d", i + 1); if (cmdmsg_rl) { rl_mirror(IObuff); @@ -2897,16 +2992,18 @@ void spell_suggest(int count) if (p_verbose > 0) { // Add the score. - if (sps_flags & (SPS_DOUBLE | SPS_BEST)) + if (sps_flags & (SPS_DOUBLE | SPS_BEST)) { vim_snprintf((char *)IObuff, IOSIZE, " (%s%d - %d)", - stp->st_salscore ? "s " : "", - stp->st_score, stp->st_altscore); - else + stp->st_salscore ? "s " : "", + stp->st_score, stp->st_altscore); + } else { vim_snprintf((char *)IObuff, IOSIZE, " (%d)", - stp->st_score); - if (cmdmsg_rl) + stp->st_score); + } + if (cmdmsg_rl) { // Mirror the numbers, but keep the leading space. rl_mirror(IObuff + 1); + } msg_advance(30); msg_puts((const char *)IObuff); } @@ -2941,8 +3038,8 @@ void spell_suggest(int count) // repl_to. repl_from = vim_strnsave(sug.su_badptr, sug.su_badlen); vim_snprintf((char *)IObuff, IOSIZE, "%s%.*s", stp->st_word, - sug.su_badlen - stp->st_orglen, - sug.su_badptr + stp->st_orglen); + sug.su_badlen - stp->st_orglen, + sug.su_badptr + stp->st_orglen); repl_to = vim_strsave(IObuff); } else { // Replacing su_badlen or more, use the whole word. @@ -2961,7 +3058,7 @@ void spell_suggest(int count) ResetRedobuff(); AppendToRedobuff("ciw"); AppendToRedobuffLit(p + c, - stp->st_wordlen + sug.su_badlen - stp->st_orglen); + stp->st_wordlen + sug.su_badlen - stp->st_orglen); AppendCharToRedobuff(ESC); // "p" may be freed here @@ -2969,8 +3066,9 @@ void spell_suggest(int count) curwin->w_cursor.col = c; changed_bytes(curwin->w_cursor.lnum, c); - } else + } else { curwin->w_cursor = prev_cursor; + } spell_find_cleanup(&sug); xfree(line); @@ -2982,27 +3080,28 @@ void spell_suggest(int count) static bool check_need_cap(linenr_T lnum, colnr_T col) { bool need_cap = false; - char_u *line; - char_u *line_copy = NULL; - char_u *p; + char_u *line; + char_u *line_copy = NULL; + char_u *p; colnr_T endcol; regmatch_T regmatch; - if (curwin->w_s->b_cap_prog == NULL) + if (curwin->w_s->b_cap_prog == NULL) { return false; + } line = get_cursor_line_ptr(); endcol = 0; if (getwhitecols(line) >= (int)col) { // At start of line, check if previous line is empty or sentence // ends there. - if (lnum == 1) + if (lnum == 1) { need_cap = true; - else { + } else { line = ml_get(lnum - 1); - if (*skipwhite(line) == NUL) + if (*skipwhite(line) == NUL) { need_cap = true; - else { + } else { // Append a space in place of the line break. line_copy = concat_str(line, (char_u *)" "); line = line_copy; @@ -3042,10 +3141,10 @@ static bool check_need_cap(linenr_T lnum, colnr_T col) void ex_spellrepall(exarg_T *eap) { pos_T pos = curwin->w_cursor; - char_u *frompat; + char_u *frompat; int addlen; - char_u *line; - char_u *p; + char_u *line; + char_u *p; bool save_ws = p_ws; linenr_T prev_lnum = 0; @@ -3072,7 +3171,7 @@ void ex_spellrepall(exarg_T *eap) // when changing "etc" to "etc.". line = get_cursor_line_ptr(); if (addlen <= 0 || STRNCMP(line + curwin->w_cursor.col, - repl_to, STRLEN(repl_to)) != 0) { + repl_to, STRLEN(repl_to)) != 0) { p = xmalloc(STRLEN(line) + addlen + 1); memmove(p, line, curwin->w_cursor.col); STRCPY(p + curwin->w_cursor.col, repl_to); @@ -3093,26 +3192,23 @@ void ex_spellrepall(exarg_T *eap) curwin->w_cursor = pos; xfree(frompat); - if (sub_nsubs == 0) + if (sub_nsubs == 0) { EMSG2(_("E753: Not found: %s"), repl_from); - else + } else { do_sub_msg(false); + } } -// Find spell suggestions for "word". Return them in the growarray "*gap" as -// a list of allocated strings. -void -spell_suggest_list ( - garray_T *gap, - char_u *word, - int maxcount, // maximum nr of suggestions - bool need_cap, // 'spellcapcheck' matched - bool interactive -) +/// Find spell suggestions for "word". Return them in the growarray "*gap" as +/// a list of allocated strings. +/// +/// @param maxcount maximum nr of suggestions +/// @param need_cap 'spellcapcheck' matched +void spell_suggest_list(garray_T *gap, char_u *word, int maxcount, bool need_cap, bool interactive) { suginfo_T sug; - suggest_T *stp; - char_u *wcopy; + suggest_T *stp; + char_u *wcopy; spell_find_suggest(word, 0, &sug, maxcount, false, need_cap, interactive); @@ -3134,44 +3230,41 @@ spell_suggest_list ( spell_find_cleanup(&sug); } -// Find spell suggestions for the word at the start of "badptr". -// Return the suggestions in "su->su_ga". -// The maximum number of suggestions is "maxcount". -// Note: does use info for the current window. -// This is based on the mechanisms of Aspell, but completely reimplemented. -static void -spell_find_suggest ( - char_u *badptr, - int badlen, // length of bad word or 0 if unknown - suginfo_T *su, - int maxcount, - bool banbadword, // don't include badword in suggestions - bool need_cap, // word should start with capital - bool interactive -) +/// Find spell suggestions for the word at the start of "badptr". +/// Return the suggestions in "su->su_ga". +/// The maximum number of suggestions is "maxcount". +/// Note: does use info for the current window. +/// This is based on the mechanisms of Aspell, but completely reimplemented. +/// +/// @param badlen length of bad word or 0 if unknown +/// @param banbadword don't include badword in suggestions +/// @param need_cap word should start with capital +static void spell_find_suggest(char_u *badptr, int badlen, suginfo_T *su, int maxcount, + bool banbadword, bool need_cap, bool interactive) { hlf_T attr = HLF_COUNT; char_u buf[MAXPATHL]; - char_u *p; + char_u *p; bool do_combine = false; - char_u *sps_copy; + char_u *sps_copy; static bool expr_busy = false; int c; - langp_T *lp; + langp_T *lp; bool did_intern = false; // Set the info in "*su". memset(su, 0, sizeof(suginfo_T)); ga_init(&su->su_ga, (int)sizeof(suggest_T), 10); ga_init(&su->su_sga, (int)sizeof(suggest_T), 10); - if (*badptr == NUL) + if (*badptr == NUL) { return; + } hash_init(&su->su_banned); su->su_badptr = badptr; - if (badlen != 0) + if (badlen != 0) { su->su_badlen = badlen; - else { + } else { size_t tmplen = spell_check(curwin, su->su_badptr, &attr, NULL, false); assert(tmplen <= INT_MAX); su->su_badlen = (int)tmplen; @@ -3179,8 +3272,9 @@ spell_find_suggest ( su->su_maxcount = maxcount; su->su_maxscore = SCORE_MAXINIT; - if (su->su_badlen >= MAXWLEN) + if (su->su_badlen >= MAXWLEN) { su->su_badlen = MAXWLEN - 1; // just in case + } STRLCPY(su->su_badword, su->su_badptr, su->su_badlen + 1); (void)spell_casefold(curwin, su->su_badptr, su->su_badlen, su->su_fbadword, MAXWLEN); @@ -3192,9 +3286,10 @@ spell_find_suggest ( // get caps flags for bad word su->su_badflags = badword_captype(su->su_badptr, - su->su_badptr + su->su_badlen); - if (need_cap) + su->su_badptr + su->su_badlen); + if (need_cap) { su->su_badflags |= WF_ONECAP; + } // Find the default language for sound folding. We simply use the first // one in 'spelllang' that supports sound folding. That's good for when @@ -3210,9 +3305,10 @@ spell_find_suggest ( // Soundfold the bad word with the default sound folding, so that we don't // have to do this many times. - if (su->su_sallang != NULL) + if (su->su_sallang != NULL) { spell_soundfold(su->su_sallang, su->su_fbadword, true, - su->su_sal_badword); + su->su_sal_badword); + } // If the word is not capitalised and spell_check() doesn't consider the // word to be bad then it might need to be capitalised. Add a suggestion @@ -3221,12 +3317,13 @@ spell_find_suggest ( if (!SPELL_ISUPPER(c) && attr == HLF_COUNT) { make_case_word(su->su_badword, buf, WF_ONECAP); add_suggestion(su, &su->su_ga, buf, su->su_badlen, SCORE_ICASE, - 0, true, su->su_sallang, false); + 0, true, su->su_sallang, false); } // Ban the bad word itself. It may appear in another region. - if (banbadword) + if (banbadword) { add_banned(su, su->su_badword); + } // Make a copy of 'spellsuggest', because the expression may change it. sps_copy = vim_strsave(p_sps); @@ -3258,10 +3355,11 @@ spell_find_suggest ( xfree(sps_copy); - if (do_combine) + if (do_combine) { // Combine the two list of suggestions. This must be done last, // because sorting changes the order again. score_combine(su); + } } // Find suggestions by evaluating expression "expr". @@ -3297,9 +3395,9 @@ static void spell_suggest_expr(suginfo_T *su, char_u *expr) // Find suggestions in file "fname". Used for "file:" in 'spellsuggest'. static void spell_suggest_file(suginfo_T *su, char_u *fname) { - FILE *fd; + FILE *fd; char_u line[MAXWLEN * 2]; - char_u *p; + char_u *p; int len; char_u cword[MAXWLEN]; @@ -3315,13 +3413,15 @@ static void spell_suggest_file(suginfo_T *su, char_u *fname) line_breakcheck(); p = vim_strchr(line, '/'); - if (p == NULL) + if (p == NULL) { continue; // No Tab found, just skip the line. + } *p++ = NUL; if (STRICMP(su->su_badword, line) == 0) { // Match! Isolate the good word, until CR or NL. - for (len = 0; p[len] >= ' '; ++len) + for (len = 0; p[len] >= ' '; ++len) { ; + } p[len] = NUL; // If the suggestion doesn't have specific case duplicate the case @@ -3332,7 +3432,7 @@ static void spell_suggest_file(suginfo_T *su, char_u *fname) } add_suggestion(su, &su->su_ga, p, su->su_badlen, - SCORE_FILE, 0, true, su->su_sallang, false); + SCORE_FILE, 0, true, su->su_sallang, false); } } @@ -3360,15 +3460,17 @@ static void spell_suggest_intern(suginfo_T *su, bool interactive) suggest_try_change(su); // For the resulting top-scorers compute the sound-a-like score. - if (sps_flags & SPS_DOUBLE) + if (sps_flags & SPS_DOUBLE) { score_comp_sal(su); + } // 3. Try finding sound-a-like words. if ((sps_flags & SPS_FAST) == 0) { - if (sps_flags & SPS_BEST) + if (sps_flags & SPS_BEST) { // Adjust the word score for the suggestions found so far for how // they sounds like. rescore_suggestions(su); + } // While going through the soundfold tree "su_maxscore" is the score // for the soundfold word, limits the changes that are being tried, @@ -3407,9 +3509,10 @@ static void spell_suggest_intern(suginfo_T *su, bool interactive) } if ((sps_flags & SPS_DOUBLE) == 0 && su->su_ga.ga_len != 0) { - if (sps_flags & SPS_BEST) + if (sps_flags & SPS_BEST) { // Adjust the word score for how it sounds like. rescore_suggestions(su); + } // Remove bogus suggestions, sort and truncate at "maxcount". check_suggestions(su, &su->su_ga); @@ -3420,7 +3523,7 @@ static void spell_suggest_intern(suginfo_T *su, bool interactive) // Free the info put in "*su" by spell_find_suggest(). static void spell_find_cleanup(suginfo_T *su) { -# define FREE_SUG_WORD(sug) xfree(sug->st_word) +#define FREE_SUG_WORD(sug) xfree(sug->st_word) // Free the suggestions. GA_DEEP_CLEAR(&su->su_ga, suggest_T, FREE_SUG_WORD); GA_DEEP_CLEAR(&su->su_sga, suggest_T, FREE_SUG_WORD); @@ -3459,11 +3562,13 @@ static void allcap_copy(char_u *word, char_u *wcopy) if (c == 0xdf) { c = 'S'; - if (d - wcopy >= MAXWLEN - 1) + if (d - wcopy >= MAXWLEN - 1) { break; + } *d++ = c; - } else + } else { c = SPELL_TOUPPER(c); + } if (d - wcopy >= MAXWLEN - MB_MAXBYTES) { break; @@ -3476,7 +3581,7 @@ static void allcap_copy(char_u *word, char_u *wcopy) // Try finding suggestions by recognizing specific situations. static void suggest_try_special(suginfo_T *su) { - char_u *p; + char_u *p; size_t len; int c; char_u word[MAXWLEN]; @@ -3496,7 +3601,7 @@ static void suggest_try_special(suginfo_T *su) // Give a soundalike score of 0, compute the score as if deleting one // character. add_suggestion(su, &su->su_ga, word, su->su_badlen, - RESCORE(SCORE_REP, 0), 0, true, su->su_sallang, false); + RESCORE(SCORE_REP, 0), 0, true, su->su_sallang, false); } } @@ -3509,8 +3614,7 @@ proftime_T total; proftime_T times[STATE_FINAL + 1]; long counts[STATE_FINAL + 1]; - static void -prof_init(void) +static void prof_init(void) { for (int i = 0; i <= STATE_FINAL; i++) { profile_zero(×[i]); @@ -3521,8 +3625,7 @@ prof_init(void) } // call before changing state - static void -prof_store(state_T state) +static void prof_store(state_T state) { profile_end(¤t); profile_add(×[state], ¤t); @@ -3531,8 +3634,7 @@ prof_store(state_T state) } # define PROF_STORE(state) prof_store(state); - static void -prof_report(char *name) +static void prof_report(char *name) { FILE *fd = fopen("suggestprof", "a"); @@ -3554,8 +3656,8 @@ static void suggest_try_change(suginfo_T *su) { char_u fword[MAXWLEN]; // copy of the bad word, case-folded int n; - char_u *p; - langp_T *lp; + char_u *p; + langp_T *lp; // We make a copy of the case-folded bad word, so that we can modify it // to find matches (esp. REP items). Append some more text, changing @@ -3570,8 +3672,9 @@ static void suggest_try_change(suginfo_T *su) // If reloading a spell file fails it's still in the list but // everything has been cleared. - if (lp->lp_slang->sl_fbyts == NULL) + if (lp->lp_slang->sl_fbyts == NULL) { continue; + } // Try it for this language. Will add possible suggestions. // @@ -3623,28 +3726,28 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so char_u tword[MAXWLEN]; // good word collected so far trystate_T stack[MAXWLEN]; char_u preword[MAXWLEN * 3] = { 0 }; // word found with proper case; - // concatenation of prefix compound - // words and split word. NUL terminated - // when going deeper but not when coming - // back. + // concatenation of prefix compound + // words and split word. NUL terminated + // when going deeper but not when coming + // back. char_u compflags[MAXWLEN]; // compound flags, one for each word - trystate_T *sp; + trystate_T *sp; int newscore; int score; - char_u *byts, *fbyts, *pbyts; - idx_T *idxs, *fidxs, *pidxs; + char_u *byts, *fbyts, *pbyts; + idx_T *idxs, *fidxs, *pidxs; int depth; int c, c2, c3; int n = 0; int flags; - garray_T *gap; + garray_T *gap; idx_T arridx; int len; - char_u *p; - fromto_T *ftp; + char_u *p; + fromto_T *ftp; int fl = 0, tl; int repextra = 0; // extra bytes in fword[] from REP item - slang_T *slang = lp->lp_slang; + slang_T *slang = lp->lp_slang; int fword_ends; bool goodword_ends; #ifdef DEBUG_TRIEWALK @@ -3709,8 +3812,9 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so if (sp->ts_prefixdepth == PFD_PREFIXTREE) { // Skip over the NUL bytes, we use them later. - for (n = 0; n < len && byts[arridx + n] == 0; ++n) + for (n = 0; n < len && byts[arridx + n] == 0; ++n) { ; + } sp->ts_curi += n; // Always past NUL bytes now. @@ -3727,7 +3831,7 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so n = nofold_len(fword, sp->ts_fidx, su->su_badptr); flags = badword_captype(su->su_badptr, su->su_badptr + n); su->su_badflags = badword_captype(su->su_badptr + n, - su->su_badptr + su->su_badlen); + su->su_badptr + su->su_badlen); #ifdef DEBUG_TRIEWALK sprintf(changename[depth], "prefix"); #endif @@ -3743,7 +3847,7 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so // and make find_keepcap_word() works. tword[sp->ts_twordlen] = NUL; make_case_word(tword + sp->ts_splitoff, - preword + sp->ts_prewordlen, flags); + preword + sp->ts_prewordlen, flags); sp->ts_prewordlen = (char_u)STRLEN(preword); sp->ts_splitoff = sp->ts_twordlen; } @@ -3764,8 +3868,9 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so flags = (int)idxs[arridx]; // Skip words with the NOSUGGEST flag. - if (flags & WF_NOSUGGEST) + if (flags & WF_NOSUGGEST) { break; + } fword_ends = (fword[sp->ts_fidx] == NUL || (soundfold @@ -3782,17 +3887,20 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so // none this must be the first try without a prefix. n = stack[sp->ts_prefixdepth].ts_arridx; len = pbyts[n++]; - for (c = 0; c < len && pbyts[n + c] == 0; ++c) + for (c = 0; c < len && pbyts[n + c] == 0; ++c) { ; + } if (c > 0) { c = valid_word_prefix(c, n, flags, - tword + sp->ts_splitoff, slang, false); - if (c == 0) + tword + sp->ts_splitoff, slang, false); + if (c == 0) { break; + } // Use the WF_RARE flag for a rare prefix. - if (c & WF_RAREPFX) + if (c & WF_RAREPFX) { flags |= WF_RARE; + } // Tricky: when checking for both prefix and compounding // we run into the prefix flag first. @@ -3805,10 +3913,11 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so // Check NEEDCOMPOUND: can't use word without compounding. Do try // appending another compound word below. if (sp->ts_complen == sp->ts_compsplit && fword_ends - && (flags & WF_NEEDCOMP)) + && (flags & WF_NEEDCOMP)) { goodword_ends = false; - else + } else { goodword_ends = true; + } p = NULL; compound_ok = true; @@ -3821,18 +3930,19 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so if (sp->ts_fidx - sp->ts_splitfidx == sp->ts_twordlen - sp->ts_splitoff && STRNCMP(fword + sp->ts_splitfidx, - tword + sp->ts_splitoff, - sp->ts_fidx - sp->ts_splitfidx) == 0) { + tword + sp->ts_splitoff, + sp->ts_fidx - sp->ts_splitfidx) == 0) { preword[sp->ts_prewordlen] = NUL; newscore = score_wordcount_adj(slang, sp->ts_score, - preword + sp->ts_prewordlen, - sp->ts_prewordlen > 0); + preword + sp->ts_prewordlen, + sp->ts_prewordlen > 0); // Add the suggestion if the score isn't too bad. - if (newscore <= su->su_maxscore) + if (newscore <= su->su_maxscore) { add_suggestion(su, &su->su_ga, preword, - sp->ts_splitfidx - repextra, - newscore, 0, false, - lp->lp_sallang, false); + sp->ts_splitfidx - repextra, + newscore, 0, false, + lp->lp_sallang, false); + } break; } } else { @@ -3856,23 +3966,26 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so compflags[sp->ts_complen] = ((unsigned)flags >> 24); compflags[sp->ts_complen + 1] = NUL; STRLCPY(preword + sp->ts_prewordlen, - tword + sp->ts_splitoff, - sp->ts_twordlen - sp->ts_splitoff + 1); + tword + sp->ts_splitoff, + sp->ts_twordlen - sp->ts_splitoff + 1); // Verify CHECKCOMPOUNDPATTERN rules. if (match_checkcompoundpattern(preword, sp->ts_prewordlen, - &slang->sl_comppat)) + &slang->sl_comppat)) { compound_ok = false; + } if (compound_ok) { p = preword; - while (*skiptowhite(p) != NUL) + while (*skiptowhite(p) != NUL) { p = skipwhite(skiptowhite(p)); + } if (fword_ends && !can_compound(slang, p, - compflags + sp->ts_compsplit)) + compflags + sp->ts_compsplit)) { // Compound is not allowed. But it may still be // possible if we add another (short) word. compound_ok = false; + } } // Get pointer to last char of previous word. @@ -3884,29 +3997,31 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so // Form the word with proper case in preword. // If there is a word from a previous split, append. // For the soundfold tree don't change the case, simply append. - if (soundfold) + if (soundfold) { STRCPY(preword + sp->ts_prewordlen, tword + sp->ts_splitoff); - else if (flags & WF_KEEPCAP) + } else if (flags & WF_KEEPCAP) { // Must find the word in the keep-case tree. find_keepcap_word(slang, tword + sp->ts_splitoff, - preword + sp->ts_prewordlen); - else { + preword + sp->ts_prewordlen); + } else { // Include badflags: If the badword is onecap or allcap // use that for the goodword too. But if the badword is // allcap and it's only one char long use onecap. c = su->su_badflags; if ((c & WF_ALLCAP) - && su->su_badlen == (*mb_ptr2len)(su->su_badptr) - ) + && su->su_badlen == + (*mb_ptr2len)(su->su_badptr)) { c = WF_ONECAP; + } c |= flags; // When appending a compound word after a word character don't // use Onecap. - if (p != NULL && spell_iswordp_nmw(p, curwin)) + if (p != NULL && spell_iswordp_nmw(p, curwin)) { c &= ~WF_ONECAP; + } make_case_word(tword + sp->ts_splitoff, - preword + sp->ts_prewordlen, c); + preword + sp->ts_prewordlen, c); } if (!soundfold) { @@ -3919,8 +4034,9 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so if ((sp->ts_complen == sp->ts_compsplit && WAS_BANNED(su, preword + sp->ts_prewordlen)) || WAS_BANNED(su, preword)) { - if (slang->sl_compprog == NULL) + if (slang->sl_compprog == NULL) { break; + } // the word so far was banned but we may try compounding goodword_ends = false; } @@ -3929,14 +4045,17 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so newscore = 0; if (!soundfold) { // soundfold words don't have flags if ((flags & WF_REGION) - && (((unsigned)flags >> 16) & lp->lp_region) == 0) + && (((unsigned)flags >> 16) & lp->lp_region) == 0) { newscore += SCORE_REGION; - if (flags & WF_RARE) + } + if (flags & WF_RARE) { newscore += SCORE_RARE; + } if (!spell_valid_case(su->su_badflags, - captype(preword + sp->ts_prewordlen, NULL))) + captype(preword + sp->ts_prewordlen, NULL))) { newscore += SCORE_ICASE; + } } // TODO: how about splitting in the soundfold tree? @@ -3951,15 +4070,16 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so // print the stack of changes that brought us here smsg("------ %s -------", fword); - for (j = 0; j < depth; ++j) + for (j = 0; j < depth; ++j) { smsg("%s", changename[j]); + } } #endif if (soundfold) { // For soundfolded words we need to find the original // words, the edit distance and then add them. add_sound_suggest(su, preword, sp->ts_score, lp); - } else if (sp->ts_fidx > 0) { + } else if (sp->ts_fidx > 0) { // Give a penalty when changing non-word char to word // char, e.g., "thes," -> "these". p = fword + sp->ts_fidx; @@ -3974,15 +4094,15 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so // Give a bonus to words seen before. score = score_wordcount_adj(slang, - sp->ts_score + newscore, - preword + sp->ts_prewordlen, - sp->ts_prewordlen > 0); + sp->ts_score + newscore, + preword + sp->ts_prewordlen, + sp->ts_prewordlen > 0); // Add the suggestion if the score isn't too bad. if (score <= su->su_maxscore) { add_suggestion(su, &su->su_ga, preword, - sp->ts_fidx - repextra, - score, 0, false, lp->lp_sallang, false); + sp->ts_fidx - repextra, + score, 0, false, lp->lp_sallang, false); if (su->su_badflags & WF_MIXCAP) { // We really don't know if the word should be @@ -3990,13 +4110,13 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so c = captype(preword, NULL); if (c == 0 || c == WF_ALLCAP) { make_case_word(tword + sp->ts_splitoff, - preword + sp->ts_prewordlen, - c == 0 ? WF_ALLCAP : 0); + preword + sp->ts_prewordlen, + c == 0 ? WF_ALLCAP : 0); add_suggestion(su, &su->su_ga, preword, - sp->ts_fidx - repextra, - score + SCORE_ICASE, 0, false, - lp->lp_sallang, false); + sp->ts_fidx - repextra, + score + SCORE_ICASE, 0, false, + lp->lp_sallang, false); } } } @@ -4006,8 +4126,7 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so // Try word split and/or compounding. if ((sp->ts_fidx >= sp->ts_fidxtry || fword_ends) // Don't split in the middle of a character - && (sp->ts_tcharlen == 0) - ) { + && (sp->ts_tcharlen == 0)) { bool try_compound; int try_split; @@ -4045,7 +4164,7 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so || sp->ts_complen + 1 - sp->ts_compsplit < slang->sl_compmax) && (can_be_compound(sp, slang, - compflags, ((unsigned)flags >> 24)))) { + compflags, ((unsigned)flags >> 24)))) { try_compound = true; compflags[sp->ts_complen] = ((unsigned)flags >> 24); compflags[sp->ts_complen + 1] = NUL; @@ -4076,35 +4195,40 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so // is only one word it must not have the NEEDCOMPOUND // flag. if (sp->ts_complen == sp->ts_compsplit - && (flags & WF_NEEDCOMP)) + && (flags & WF_NEEDCOMP)) { break; + } p = preword; - while (*skiptowhite(p) != NUL) + while (*skiptowhite(p) != NUL) { p = skipwhite(skiptowhite(p)); + } if (sp->ts_complen > sp->ts_compsplit && !can_compound(slang, p, - compflags + sp->ts_compsplit)) + compflags + sp->ts_compsplit)) { break; + } - if (slang->sl_nosplitsugs) + if (slang->sl_nosplitsugs) { newscore += SCORE_SPLIT_NO; - else + } else { newscore += SCORE_SPLIT; + } // Give a bonus to words seen before. newscore = score_wordcount_adj(slang, newscore, - preword + sp->ts_prewordlen, true); + preword + sp->ts_prewordlen, true); } if (TRY_DEEPER(su, stack, depth, newscore)) { go_deeper(stack, depth, newscore); #ifdef DEBUG_TRIEWALK - if (!try_compound && !fword_ends) + if (!try_compound && !fword_ends) { sprintf(changename[depth], "%.*s-%s: split", - sp->ts_twordlen, tword, fword + sp->ts_fidx); - else + sp->ts_twordlen, tword, fword + sp->ts_fidx); + } else { sprintf(changename[depth], "%.*s-%s: compound", - sp->ts_twordlen, tword, fword + sp->ts_fidx); + sp->ts_twordlen, tword, fword + sp->ts_fidx); + } #endif // Save things to be restored at STATE_SPLITUNDO. sp->ts_save_badflags = su->su_badflags; @@ -4115,8 +4239,9 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so sp = &stack[depth]; // Append a space to preword when splitting. - if (!try_compound && !fword_ends) + if (!try_compound && !fword_ends) { STRCAT(preword, " "); + } sp->ts_prewordlen = (char_u)STRLEN(preword); sp->ts_splitoff = sp->ts_twordlen; sp->ts_splitfidx = sp->ts_fidx; @@ -4127,8 +4252,8 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so // character when the word ends. But only when the // good word can end. if (((!try_compound && !spell_iswordp_nmw(fword - + sp->ts_fidx, - curwin)) + + sp->ts_fidx, + curwin)) || fword_ends) && fword[sp->ts_fidx] != NUL && goodword_ends) { @@ -4138,28 +4263,30 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so if (fword_ends) { // Copy the skipped character to preword. memmove(preword + sp->ts_prewordlen, - fword + sp->ts_fidx, l); + fword + sp->ts_fidx, l); sp->ts_prewordlen += l; preword[sp->ts_prewordlen] = NUL; - } else + } else { sp->ts_score -= SCORE_SPLIT - SCORE_SUBST; + } sp->ts_fidx += l; } // When compounding include compound flag in // compflags[] (already set above). When splitting we // may start compounding over again. - if (try_compound) + if (try_compound) { ++sp->ts_complen; - else + } else { sp->ts_compsplit = sp->ts_complen; + } sp->ts_prefixdepth = PFD_NOPREFIX; // set su->su_badflags to the caps type at this // position n = nofold_len(fword, sp->ts_fidx, su->su_badptr); su->su_badflags = badword_captype(su->su_badptr + n, - su->su_badptr + su->su_badlen); + su->su_badptr + su->su_badlen); // Restart at top of the tree. sp->ts_arridx = 0; @@ -4194,8 +4321,7 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so // Past the NUL bytes in the node. su->su_badflags = sp->ts_save_badflags; if (fword[sp->ts_fidx] == NUL - && sp->ts_tcharlen == 0 - ) { + && sp->ts_tcharlen == 0) { // The badword ends, can't use STATE_PLAIN. PROF_STORE(sp->ts_state) sp->ts_state = STATE_DEL; @@ -4228,11 +4354,12 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so // just deleted this byte, accepting it is always cheaper than // delete + substitute. if (c == fword[sp->ts_fidx] - || (sp->ts_tcharlen > 0 && sp->ts_isdiff != DIFF_NONE) - ) + || (sp->ts_tcharlen > 0 && + sp->ts_isdiff != DIFF_NONE)) { newscore = 0; - else + } else { newscore = SCORE_SUBST; + } if ((newscore == 0 || (sp->ts_fidx >= sp->ts_fidxtry && ((sp->ts_flags & TSF_DIDDEL) == 0 @@ -4240,14 +4367,15 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so && TRY_DEEPER(su, stack, depth, newscore)) { go_deeper(stack, depth, newscore); #ifdef DEBUG_TRIEWALK - if (newscore > 0) + if (newscore > 0) { sprintf(changename[depth], "%.*s-%s: subst %c to %c", - sp->ts_twordlen, tword, fword + sp->ts_fidx, - fword[sp->ts_fidx], c); - else + sp->ts_twordlen, tword, fword + sp->ts_fidx, + fword[sp->ts_fidx], c); + } else { sprintf(changename[depth], "%.*s-%s: accept %c", - sp->ts_twordlen, tword, fword + sp->ts_fidx, - fword[sp->ts_fidx]); + sp->ts_twordlen, tword, fword + sp->ts_fidx, + fword[sp->ts_fidx]); + } #endif ++depth; sp = &stack[depth]; @@ -4289,12 +4417,11 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so + sp->ts_fcharstart))) { sp->ts_score -= SCORE_SUBST - SCORE_SUBCOMP; } else if ( - !soundfold - && slang->sl_has_map - && similar_chars( - slang, - utf_ptr2char(tword + sp->ts_twordlen - sp->ts_tcharlen), - utf_ptr2char(fword + sp->ts_fcharstart))) { + !soundfold + && slang->sl_has_map + && similar_chars(slang, + utf_ptr2char(tword + sp->ts_twordlen - sp->ts_tcharlen), + utf_ptr2char(fword + sp->ts_fcharstart))) { // For a similar character adjust score from // SCORE_SUBST to SCORE_SIMILAR. sp->ts_score -= SCORE_SUBST - SCORE_SIMILAR; @@ -4339,19 +4466,20 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so PROF_STORE(sp->ts_state) sp->ts_state = STATE_INS_PREP; sp->ts_curi = 1; - if (soundfold && sp->ts_fidx == 0 && fword[sp->ts_fidx] == '*') + if (soundfold && sp->ts_fidx == 0 && fword[sp->ts_fidx] == '*') { // Deleting a vowel at the start of a word counts less, see // soundalike_score(). newscore = 2 * SCORE_DEL / 3; - else + } else { newscore = SCORE_DEL; + } if (fword[sp->ts_fidx] != NUL && TRY_DEEPER(su, stack, depth, newscore)) { go_deeper(stack, depth, newscore); #ifdef DEBUG_TRIEWALK sprintf(changename[depth], "%.*s-%s: delete %c", - sp->ts_twordlen, tword, fword + sp->ts_fidx, - fword[sp->ts_fidx]); + sp->ts_twordlen, tword, fword + sp->ts_fidx, + fword[sp->ts_fidx]); #endif ++depth; @@ -4421,19 +4549,20 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so // accepting that byte is always better. n += sp->ts_curi++; c = byts[n]; - if (soundfold && sp->ts_twordlen == 0 && c == '*') + if (soundfold && sp->ts_twordlen == 0 && c == '*') { // Inserting a vowel at the start of a word counts less, // see soundalike_score(). newscore = 2 * SCORE_INS / 3; - else + } else { newscore = SCORE_INS; + } if (c != fword[sp->ts_fidx] && TRY_DEEPER(su, stack, depth, newscore)) { go_deeper(stack, depth, newscore); #ifdef DEBUG_TRIEWALK sprintf(changename[depth], "%.*s-%s: insert %c", - sp->ts_twordlen, tword, fword + sp->ts_fidx, - c); + sp->ts_twordlen, tword, fword + sp->ts_fidx, + c); #endif ++depth; sp = &stack[depth]; @@ -4454,8 +4583,9 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so // soundfold words (illogical but does give a better // score). if (sp->ts_twordlen >= 2 - && tword[sp->ts_twordlen - 2] == c) + && tword[sp->ts_twordlen - 2] == c) { sp->ts_score -= SCORE_INS - SCORE_INSDUP; + } } } break; @@ -4566,8 +4696,8 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so go_deeper(stack, depth, SCORE_SWAP3); #ifdef DEBUG_TRIEWALK sprintf(changename[depth], "%.*s-%s: swap3 %c and %c", - sp->ts_twordlen, tword, fword + sp->ts_fidx, - c, c3); + sp->ts_twordlen, tword, fword + sp->ts_fidx, + c, c3); #endif PROF_STORE(sp->ts_state) sp->ts_state = STATE_UNSWAP3; @@ -4611,8 +4741,8 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so #ifdef DEBUG_TRIEWALK p = fword + sp->ts_fidx; sprintf(changename[depth], "%.*s-%s: rotate left %c%c%c", - sp->ts_twordlen, tword, fword + sp->ts_fidx, - p[0], p[1], p[2]); + sp->ts_twordlen, tword, fword + sp->ts_fidx, + p[0], p[1], p[2]); #endif PROF_STORE(sp->ts_state) sp->ts_state = STATE_UNROT3L; @@ -4648,8 +4778,8 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so #ifdef DEBUG_TRIEWALK p = fword + sp->ts_fidx; sprintf(changename[depth], "%.*s-%s: rotate right %c%c%c", - sp->ts_twordlen, tword, fword + sp->ts_fidx, - p[0], p[1], p[2]); + sp->ts_twordlen, tword, fword + sp->ts_fidx, + p[0], p[1], p[2]); #endif PROF_STORE(sp->ts_state) sp->ts_state = STATE_UNROT3R; @@ -4696,10 +4826,11 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so // Use the first byte to quickly find the first entry that may // match. If the index is -1 there is none. - if (soundfold) + if (soundfold) { sp->ts_curi = slang->sl_repsal_first[fword[sp->ts_fidx]]; - else + } else { sp->ts_curi = lp->lp_replang->sl_rep_first[fword[sp->ts_fidx]]; + } if (sp->ts_curi < 0) { PROF_STORE(sp->ts_state) @@ -4717,10 +4848,11 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so // valid. p = fword + sp->ts_fidx; - if (soundfold) + if (soundfold) { gap = &slang->sl_repsal; - else + } else { gap = &lp->lp_replang->sl_rep; + } while (sp->ts_curi < gap->ga_len) { ftp = (fromto_T *)gap->ga_data + sp->ts_curi++; if (*ftp->ft_from != *p) { @@ -4733,8 +4865,8 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so go_deeper(stack, depth, SCORE_REP); #ifdef DEBUG_TRIEWALK sprintf(changename[depth], "%.*s-%s: replace %s with %s", - sp->ts_twordlen, tword, fword + sp->ts_fidx, - ftp->ft_from, ftp->ft_to); + sp->ts_twordlen, tword, fword + sp->ts_fidx, + ftp->ft_from, ftp->ft_to); #endif // Need to undo this afterwards. PROF_STORE(sp->ts_state) @@ -4755,19 +4887,21 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so } } - if (sp->ts_curi >= gap->ga_len && sp->ts_state == STATE_REP) + if (sp->ts_curi >= gap->ga_len && sp->ts_state == STATE_REP) { // No (more) matches. PROF_STORE(sp->ts_state) sp->ts_state = STATE_FINAL; + } break; case STATE_REP_UNDO: // Undo a REP replacement and continue with the next one. - if (soundfold) + if (soundfold) { gap = &slang->sl_repsal; - else + } else { gap = &lp->lp_replang->sl_rep; + } ftp = (fromto_T *)gap->ga_data + sp->ts_curi - 1; fl = (int)STRLEN(ftp->ft_from); tl = (int)STRLEN(ftp->ft_to); @@ -4815,7 +4949,7 @@ static void go_deeper(trystate_T *stack, int depth, int score_add) // fword[flen] and return the byte length of that many chars in "word". static int nofold_len(char_u *fword, int flen, char_u *word) { - char_u *p; + char_u *p; int i = 0; for (p = fword; p < fword + flen; MB_PTR_ADV(p)) { @@ -4849,9 +4983,9 @@ static void find_keepcap_word(slang_T *slang, char_u *fword, char_u *kword) int len; int c; idx_T lo, hi, m; - char_u *p; - char_u *byts = slang->sl_kbyts; // array with bytes of the words - idx_T *idxs = slang->sl_kidxs; // array with indexes + char_u *p; + char_u *byts = slang->sl_kbyts; // array with bytes of the words + idx_T *idxs = slang->sl_kidxs; // array with indexes if (byts == NULL) { // array is empty: "cannot happen" @@ -4882,7 +5016,7 @@ static void find_keepcap_word(slang_T *slang, char_u *fword, char_u *kword) // kword is getting too long, continue one level up --depth; - } else if (++round[depth] > 2) { + } else if (++round[depth] > 2) { // tried both fold-case and upper-case character, continue one // level up --depth; @@ -4907,19 +5041,20 @@ static void find_keepcap_word(slang_T *slang, char_u *fword, char_u *kword) hi = tryidx + len - 1; while (lo < hi) { m = (lo + hi) / 2; - if (byts[m] > c) + if (byts[m] > c) { hi = m - 1; - else if (byts[m] < c) + } else if (byts[m] < c) { lo = m + 1; - else { + } else { lo = hi = m; break; } } // Stop if there is no matching byte. - if (hi < lo || byts[lo] != c) + if (hi < lo || byts[lo] != c) { break; + } // Continue at the child (if there is one). tryidx = idxs[lo]; @@ -4930,11 +5065,11 @@ static void find_keepcap_word(slang_T *slang, char_u *fword, char_u *kword) // level deeper. if (round[depth] == 1) { STRNCPY(kword + kwordlen[depth], fword + fwordidx[depth], - flen); + flen); kwordlen[depth + 1] = kwordlen[depth] + flen; } else { STRNCPY(kword + kwordlen[depth], uword + uwordidx[depth], - ulen); + ulen); kwordlen[depth + 1] = kwordlen[depth] + ulen; } fwordidx[depth + 1] = fwordidx[depth] + flen; @@ -4955,11 +5090,11 @@ static void find_keepcap_word(slang_T *slang, char_u *fword, char_u *kword) // su->su_sga. static void score_comp_sal(suginfo_T *su) { - langp_T *lp; + langp_T *lp; char_u badsound[MAXWLEN]; int i; - suggest_T *stp; - suggest_T *sstp; + suggest_T *stp; + suggest_T *sstp; int score; ga_grow(&su->su_sga, su->su_ga.ga_len); @@ -4998,13 +5133,13 @@ static void score_comp_sal(suginfo_T *su) static void score_combine(suginfo_T *su) { garray_T ga; - garray_T *gap; - langp_T *lp; - suggest_T *stp; - char_u *p; + garray_T *gap; + langp_T *lp; + suggest_T *stp; + char_u *p; char_u badsound[MAXWLEN]; int round; - slang_T *slang = NULL; + slang_T *slang = NULL; // Add the alternate score to su_ga. for (int lpi = 0; lpi < curwin->w_s->b_langp.ga_len; ++lpi) { @@ -5017,11 +5152,12 @@ static void score_combine(suginfo_T *su) for (int i = 0; i < su->su_ga.ga_len; ++i) { stp = &SUG(su->su_ga, i); stp->st_altscore = stp_sal_score(stp, su, slang, badsound); - if (stp->st_altscore == SCORE_MAXMAX) + if (stp->st_altscore == SCORE_MAXMAX) { stp->st_score = (stp->st_score * 3 + SCORE_BIG) / 4; - else + } else { stp->st_score = (stp->st_score * 3 + stp->st_altscore) / 4; + } stp->st_salscore = false; } break; @@ -5030,7 +5166,7 @@ static void score_combine(suginfo_T *su) if (slang == NULL) { // Using "double" without sound folding. (void)cleanup_suggestions(&su->su_ga, su->su_maxscore, - su->su_maxcount); + su->su_maxcount); return; } @@ -5038,11 +5174,12 @@ static void score_combine(suginfo_T *su) for (int i = 0; i < su->su_sga.ga_len; ++i) { stp = &SUG(su->su_sga, i); stp->st_altscore = spell_edit_score(slang, - su->su_badword, stp->st_word); - if (stp->st_score == SCORE_MAXMAX) + su->su_badword, stp->st_word); + if (stp->st_score == SCORE_MAXMAX) { stp->st_score = (SCORE_BIG * 7 + stp->st_altscore) / 8; - else + } else { stp->st_score = (stp->st_score * 7 + stp->st_altscore) / 8; + } stp->st_salscore = true; } @@ -5066,13 +5203,16 @@ static void score_combine(suginfo_T *su) // Don't add a word if it's already there. p = SUG(*gap, i).st_word; int j; - for (j = 0; j < ga.ga_len; ++j) - if (STRCMP(stp[j].st_word, p) == 0) + for (j = 0; j < ga.ga_len; ++j) { + if (STRCMP(stp[j].st_word, p) == 0) { break; - if (j == ga.ga_len) + } + } + if (j == ga.ga_len) { stp[ga.ga_len++] = SUG(*gap, i); - else + } else { xfree(p); + } } } } @@ -5091,19 +5231,15 @@ static void score_combine(suginfo_T *su) su->su_ga = ga; } -// For the goodword in "stp" compute the soundalike score compared to the -// badword. -static int -stp_sal_score ( - suggest_T *stp, - suginfo_T *su, - slang_T *slang, - char_u *badsound // sound-folded badword -) +/// For the goodword in "stp" compute the soundalike score compared to the +/// badword. +/// +/// @param badsound sound-folded badword +static int stp_sal_score(suggest_T *stp, suginfo_T *su, slang_T *slang, char_u *badsound) { - char_u *p; - char_u *pbad; - char_u *pgood; + char_u *p; + char_u *pbad; + char_u *pgood; char_u badsound2[MAXWLEN]; char_u fword[MAXWLEN]; char_u goodsound[MAXWLEN]; @@ -5111,9 +5247,9 @@ stp_sal_score ( int lendiff; lendiff = su->su_badlen - stp->st_orglen; - if (lendiff >= 0) + if (lendiff >= 0) { pbad = badsound; - else { + } else { // soundfold the bad word with more characters following (void)spell_casefold(curwin, su->su_badptr, stp->st_orglen, fword, MAXWLEN); @@ -5122,9 +5258,11 @@ stp_sal_score ( // removing the space. Don't do it when the good word also contains a // space. if (ascii_iswhite(su->su_badptr[su->su_badlen]) - && *skiptowhite(stp->st_word) == NUL) - for (p = fword; *(p = skiptowhite(p)) != NUL; ) + && *skiptowhite(stp->st_word) == NUL) { + for (p = fword; *(p = skiptowhite(p)) != NUL; ) { STRMOVE(p, p + 1); + } + } spell_soundfold(slang, fword, true, badsound2); pbad = badsound2; @@ -5135,10 +5273,11 @@ stp_sal_score ( // what replaces the bad word. STRCPY(goodword, stp->st_word); STRLCPY(goodword + stp->st_wordlen, - su->su_badptr + su->su_badlen - lendiff, lendiff + 1); + su->su_badptr + su->su_badlen - lendiff, lendiff + 1); pgood = goodword; - } else + } else { pgood = stp->st_word; + } // Sound-fold the word and compute the score for the difference. spell_soundfold(slang, pgood, false, goodsound); @@ -5153,17 +5292,18 @@ static sftword_T dumsft; // Prepare for calling suggest_try_soundalike(). static void suggest_try_soundalike_prep(void) { - langp_T *lp; - slang_T *slang; + langp_T *lp; + slang_T *slang; // Do this for all languages that support sound folding and for which a // .sug file has been loaded. for (int lpi = 0; lpi < curwin->w_s->b_langp.ga_len; ++lpi) { lp = LANGP_ENTRY(curwin->w_s->b_langp, lpi); slang = lp->lp_slang; - if (!GA_EMPTY(&slang->sl_sal) && slang->sl_sbyts != NULL) + if (!GA_EMPTY(&slang->sl_sal) && slang->sl_sbyts != NULL) { // prepare the hashtable used by add_sound_suggest() hash_init(&slang->sl_sounddone); + } } } @@ -5172,8 +5312,8 @@ static void suggest_try_soundalike_prep(void) static void suggest_try_soundalike(suginfo_T *su) { char_u salword[MAXWLEN]; - langp_T *lp; - slang_T *slang; + langp_T *lp; + slang_T *slang; // Do this for all languages that support sound folding and for which a // .sug file has been loaded. @@ -5201,10 +5341,10 @@ static void suggest_try_soundalike(suginfo_T *su) // Finish up after calling suggest_try_soundalike(). static void suggest_try_soundalike_finish(void) { - langp_T *lp; - slang_T *slang; + langp_T *lp; + slang_T *slang; int todo; - hashitem_T *hi; + hashitem_T *hi; // Do this for all languages that support sound folding and for which a // .sug file has been loaded. @@ -5214,11 +5354,12 @@ static void suggest_try_soundalike_finish(void) if (!GA_EMPTY(&slang->sl_sal) && slang->sl_sbyts != NULL) { // Free the info about handled words. todo = (int)slang->sl_sounddone.ht_used; - for (hi = slang->sl_sounddone.ht_array; todo > 0; ++hi) + for (hi = slang->sl_sounddone.ht_array; todo > 0; ++hi) { if (!HASHITEM_EMPTY(hi)) { xfree(HI2SFT(hi)); --todo; } + } // Clear the hashtable, it may also be used by another region. hash_clear(&slang->sl_sounddone); @@ -5227,32 +5368,28 @@ static void suggest_try_soundalike_finish(void) } } -// A match with a soundfolded word is found. Add the good word(s) that -// produce this soundfolded word. -static void -add_sound_suggest ( - suginfo_T *su, - char_u *goodword, - int score, // soundfold score - langp_T *lp -) +/// A match with a soundfolded word is found. Add the good word(s) that +/// produce this soundfolded word. +/// +/// @param score soundfold score +static void add_sound_suggest(suginfo_T *su, char_u *goodword, int score, langp_T *lp) { - slang_T *slang = lp->lp_slang; // language for sound folding + slang_T *slang = lp->lp_slang; // language for sound folding int sfwordnr; - char_u *nrline; + char_u *nrline; int orgnr; char_u theword[MAXWLEN]; int i; int wlen; - char_u *byts; - idx_T *idxs; + char_u *byts; + idx_T *idxs; int n; int wordcount; int wc; int goodscore; hash_T hash; - hashitem_T *hi; - sftword_T *sft; + hashitem_T *hi; + sftword_T *sft; int bc, gc; int limit; @@ -5271,8 +5408,9 @@ add_sound_suggest ( hash_add_item(&slang->sl_sounddone, hi, sft->sft_word, hash); } else { sft = HI2SFT(hi); - if (score >= sft->sft_score) + if (score >= sft->sft_score) { return; + } sft->sft_score = score; } @@ -5299,25 +5437,28 @@ add_sound_suggest ( wordcount = 0; for (wlen = 0; wlen < MAXWLEN - 3; ++wlen) { i = 1; - if (wordcount == orgnr && byts[n + 1] == NUL) + if (wordcount == orgnr && byts[n + 1] == NUL) { break; // found end of word - - if (byts[n + 1] == NUL) + } + if (byts[n + 1] == NUL) { ++wordcount; + } // skip over the NUL bytes - for (; byts[n + i] == NUL; ++i) + for (; byts[n + i] == NUL; ++i) { if (i > byts[n]) { // safety check STRCPY(theword + wlen, "BAD"); wlen += 3; goto badword; } + } // One of the siblings must have the word. for (; i < byts[n]; ++i) { wc = idxs[idxs[n + i]]; // nr of words under this byte - if (wordcount + wc > orgnr) + if (wordcount + wc > orgnr) { break; + } wordcount += wc; } @@ -5330,12 +5471,13 @@ badword: // Go over the possible flags and regions. for (; i <= byts[n] && byts[n + i] == NUL; ++i) { char_u cword[MAXWLEN]; - char_u *p; + char_u *p; int flags = (int)idxs[n + i]; // Skip words with the NOSUGGEST flag - if (flags & WF_NOSUGGEST) + if (flags & WF_NOSUGGEST) { continue; + } if (flags & WF_KEEPCAP) { // Must find the word in the keep-case tree. @@ -5347,23 +5489,26 @@ badword: // Need to fix case according to "flags". make_case_word(theword, cword, flags); p = cword; - } else + } else { p = theword; + } } // Add the suggestion. if (sps_flags & SPS_DOUBLE) { // Add the suggestion if the score isn't too bad. - if (score <= su->su_maxscore) + if (score <= su->su_maxscore) { add_suggestion(su, &su->su_sga, p, su->su_badlen, - score, 0, false, slang, false); + score, 0, false, slang, false); + } } else { // Add a penalty for words in another region. if ((flags & WF_REGION) - && (((unsigned)flags >> 16) & lp->lp_region) == 0) + && (((unsigned)flags >> 16) & lp->lp_region) == 0) { goodscore = SCORE_REGION; - else + } else { goodscore = 0; + } // Add a small penalty for changing the first letter from // lower to upper case. Helps for "tath" -> "Kath", which is @@ -5373,8 +5518,9 @@ badword: if (SPELL_ISUPPER(gc)) { bc = PTR2CHAR(su->su_badword); if (!SPELL_ISUPPER(bc) - && SPELL_TOFOLD(bc) != SPELL_TOFOLD(gc)) + && SPELL_TOFOLD(bc) != SPELL_TOFOLD(gc)) { goodscore += SCORE_ICASE / 2; + } } // Compute the score for the good word. This only does letter @@ -5385,11 +5531,12 @@ badword: // If the limit is very high then the iterative method is // inefficient, using an array is quicker. limit = MAXSCORE(su->su_sfmaxscore - goodscore, score); - if (limit > SCORE_LIMITMAX) + if (limit > SCORE_LIMITMAX) { goodscore += spell_edit_score(slang, su->su_badword, p); - else + } else { goodscore += spell_edit_score_limit(slang, su->su_badword, - p, limit); + p, limit); + } // When going over the limit don't bother to do the rest. if (goodscore < SCORE_MAXMAX) { @@ -5398,9 +5545,10 @@ badword: // Add the suggestion if the score isn't too bad. goodscore = RESCORE(goodscore, score); - if (goodscore <= su->su_sfmaxscore) + if (goodscore <= su->su_sfmaxscore) { add_suggestion(su, &su->su_ga, p, su->su_badlen, - goodscore, score, true, slang, true); + goodscore, score, true, slang, true); + } } } } @@ -5414,9 +5562,9 @@ static int soundfold_find(slang_T *slang, char_u *word) int len; int wlen = 0; int c; - char_u *ptr = word; - char_u *byts; - idx_T *idxs; + char_u *ptr = word; + char_u *byts; + idx_T *idxs; int wordnr = 0; byts = slang->sl_sbyts; @@ -5430,35 +5578,41 @@ static int soundfold_find(slang_T *slang, char_u *word) // If the word ends we found the word. If not skip the NUL bytes. c = ptr[wlen]; if (byts[arridx] == NUL) { - if (c == NUL) + if (c == NUL) { break; + } // Skip over the zeros, there can be several. while (len > 0 && byts[arridx] == NUL) { ++arridx; --len; } - if (len == 0) + if (len == 0) { return -1; // no children, word should have ended here + } ++wordnr; } // If the word ends we didn't find it. - if (c == NUL) + if (c == NUL) { return -1; + } // Perform a binary search in the list of accepted bytes. - if (c == TAB) // <Tab> is handled like <Space> + if (c == TAB) { // <Tab> is handled like <Space> c = ' '; + } while (byts[arridx] < c) { // The word count is in the first idxs[] entry of the child. wordnr += idxs[idxs[arridx]]; ++arridx; - if (--len == 0) // end of the bytes, didn't find it + if (--len == 0) { // end of the bytes, didn't find it return -1; + } } - if (byts[arridx] != c) // didn't find the byte + if (byts[arridx] != c) { // didn't find the byte return -1; + } // Continue at the child (if there is one). arridx = idxs[arridx]; @@ -5466,9 +5620,11 @@ static int soundfold_find(slang_T *slang, char_u *word) // One space in the good word may stand for several spaces in the // checked word. - if (c == ' ') - while (ptr[wlen] == ' ' || ptr[wlen] == TAB) + if (c == ' ') { + while (ptr[wlen] == ' ' || ptr[wlen] == TAB) { ++wlen; + } + } } return wordnr; @@ -5477,15 +5633,16 @@ static int soundfold_find(slang_T *slang, char_u *word) // Copy "fword" to "cword", fixing case according to "flags". static void make_case_word(char_u *fword, char_u *cword, int flags) { - if (flags & WF_ALLCAP) + if (flags & WF_ALLCAP) { // Make it all upper-case allcap_copy(fword, cword); - else if (flags & WF_ONECAP) + } else if (flags & WF_ONECAP) { // Make the first letter upper-case onecap_copy(fword, cword, true); - else + } else { // Use goodword as-is. STRCPY(cword, fword); + } } // Returns true if "c1" and "c2" are similar characters according to the MAP @@ -5494,7 +5651,7 @@ static bool similar_chars(slang_T *slang, int c1, int c2) { int m1, m2; char_u buf[MB_MAXBYTES + 1]; - hashitem_T *hi; + hashitem_T *hi; if (c1 >= 256) { buf[utf_char2bytes(c1, buf)] = 0; @@ -5526,25 +5683,20 @@ static bool similar_chars(slang_T *slang, int c1, int c2) return m1 == m2; } -// Adds a suggestion to the list of suggestions. -// For a suggestion that is already in the list the lowest score is remembered. -static void -add_suggestion ( - suginfo_T *su, - garray_T *gap, // either su_ga or su_sga - const char_u *goodword, - int badlenarg, // len of bad word replaced with "goodword" - int score, - int altscore, - bool had_bonus, // value for st_had_bonus - slang_T *slang, // language for sound folding - bool maxsf // su_maxscore applies to soundfold score, - // su_sfmaxscore to the total score. -) +/// Adds a suggestion to the list of suggestions. +/// For a suggestion that is already in the list the lowest score is remembered. +/// +/// @param gap either su_ga or su_sga +/// @param badlenarg len of bad word replaced with "goodword" +/// @param had_bonus value for st_had_bonus +/// @param slang language for sound folding +/// @param maxsf su_maxscore applies to soundfold score, su_sfmaxscore to the total score. +static void add_suggestion(suginfo_T *su, garray_T *gap, const char_u *goodword, int badlenarg, + int score, int altscore, bool had_bonus, slang_T *slang, bool maxsf) { int goodlen; // len of goodword changed int badlen; // len of bad word changed - suggest_T *stp; + suggest_T *stp; suggest_T new_sug; // Minimize "badlen" for consistency. Avoids that changing "the the" to @@ -5554,8 +5706,9 @@ add_suggestion ( for (;; ) { goodlen = (int)(pgood - goodword); badlen = (int)(pbad - su->su_badptr); - if (goodlen <= 0 || badlen <= 0) + if (goodlen <= 0 || badlen <= 0) { break; + } MB_PTR_BACK(goodword, pgood); MB_PTR_BACK(su->su_badptr, pbad); if (utf_ptr2char(pgood) != utf_ptr2char(pbad)) { @@ -5563,10 +5716,11 @@ add_suggestion ( } } - if (badlen == 0 && goodlen == 0) + if (badlen == 0 && goodlen == 0) { // goodword doesn't change anything; may happen for "the the" changing // the first "the" to itself. return; + } int i; if (GA_EMPTY(gap)) { @@ -5581,8 +5735,9 @@ add_suggestion ( && stp->st_orglen == badlen && STRNCMP(stp->st_word, goodword, goodlen) == 0) { // Found it. Remember the word with the lowest score. - if (stp->st_slang == NULL) + if (stp->st_slang == NULL) { stp->st_slang = slang; + } new_sug.st_score = score; new_sug.st_altscore = altscore; @@ -5595,9 +5750,9 @@ add_suggestion ( // suggest_try_change() doesn't compute the soundalike // word to keep it fast, while some special methods set // the soundalike score to zero. - if (had_bonus) + if (had_bonus) { rescore_one(su, stp); - else { + } else { new_sug.st_word = stp->st_word; new_sug.st_wordlen = stp->st_wordlen; new_sug.st_slang = stp->st_slang; @@ -5630,25 +5785,24 @@ add_suggestion ( // If we have too many suggestions now, sort the list and keep // the best suggestions. if (gap->ga_len > SUG_MAX_COUNT(su)) { - if (maxsf) + if (maxsf) { su->su_sfmaxscore = cleanup_suggestions(gap, - su->su_sfmaxscore, SUG_CLEAN_COUNT(su)); - else + su->su_sfmaxscore, SUG_CLEAN_COUNT(su)); + } else { su->su_maxscore = cleanup_suggestions(gap, - su->su_maxscore, SUG_CLEAN_COUNT(su)); + su->su_maxscore, SUG_CLEAN_COUNT(su)); + } } } } -// Suggestions may in fact be flagged as errors. Esp. for banned words and -// for split words, such as "the the". Remove these from the list here. -static void -check_suggestions ( - suginfo_T *su, - garray_T *gap // either su_ga or su_sga -) +/// Suggestions may in fact be flagged as errors. Esp. for banned words and +/// for split words, such as "the the". Remove these from the list here. +/// +/// @param gap either su_ga or su_sga +static void check_suggestions(suginfo_T *su, garray_T *gap) { - suggest_T *stp; + suggest_T *stp; char_u longword[MAXWLEN + 1]; int len; hlf_T attr; @@ -5662,16 +5816,17 @@ check_suggestions ( STRLCPY(longword, stp[i].st_word, MAXWLEN + 1); len = stp[i].st_wordlen; STRLCPY(longword + len, su->su_badptr + stp[i].st_orglen, - MAXWLEN - len + 1); + MAXWLEN - len + 1); attr = HLF_COUNT; (void)spell_check(curwin, longword, &attr, NULL, false); if (attr != HLF_COUNT) { // Remove this entry. xfree(stp[i].st_word); --gap->ga_len; - if (i < gap->ga_len) + if (i < gap->ga_len) { memmove(stp + i, stp + i + 1, - sizeof(suggest_T) * (gap->ga_len - i)); + sizeof(suggest_T) * (gap->ga_len - i)); + } } } } @@ -5680,9 +5835,9 @@ check_suggestions ( // Add a word to be banned. static void add_banned(suginfo_T *su, char_u *word) { - char_u *s; + char_u *s; hash_T hash; - hashitem_T *hi; + hashitem_T *hi; hash = hash_hash(word); const size_t word_len = STRLEN(word); @@ -5707,23 +5862,24 @@ static void rescore_suggestions(suginfo_T *su) // Recompute the score for one suggestion if sound-folding is possible. static void rescore_one(suginfo_T *su, suggest_T *stp) { - slang_T *slang = stp->st_slang; + slang_T *slang = stp->st_slang; char_u sal_badword[MAXWLEN]; - char_u *p; + char_u *p; // Only rescore suggestions that have no sal score yet and do have a // language. if (slang != NULL && !GA_EMPTY(&slang->sl_sal) && !stp->st_had_bonus) { - if (slang == su->su_sallang) + if (slang == su->su_sallang) { p = su->su_sal_badword; - else { + } else { spell_soundfold(slang, su->su_fbadword, true, sal_badword); p = sal_badword; } stp->st_altscore = stp_sal_score(stp, su, slang, p); - if (stp->st_altscore == SCORE_MAXMAX) + if (stp->st_altscore == SCORE_MAXMAX) { stp->st_altscore = SCORE_BIG; + } stp->st_score = RESCORE(stp->st_score, stp->st_altscore); stp->st_had_bonus = true; } @@ -5734,28 +5890,27 @@ static void rescore_one(suginfo_T *su, suggest_T *stp) // First on "st_score", then "st_altscore" then alphabetically. static int sug_compare(const void *s1, const void *s2) { - suggest_T *p1 = (suggest_T *)s1; - suggest_T *p2 = (suggest_T *)s2; + suggest_T *p1 = (suggest_T *)s1; + suggest_T *p2 = (suggest_T *)s2; int n = p1->st_score - p2->st_score; if (n == 0) { n = p1->st_altscore - p2->st_altscore; - if (n == 0) + if (n == 0) { n = STRICMP(p1->st_word, p2->st_word); + } } return n; } -// Cleanup the suggestions: -// - Sort on score. -// - Remove words that won't be displayed. -// Returns the maximum score in the list or "maxscore" unmodified. -static int -cleanup_suggestions ( - garray_T *gap, - int maxscore, - int keep // nr of suggestions to keep -) +/// Cleanup the suggestions: +/// - Sort on score. +/// - Remove words that won't be displayed. +/// +/// @param keep nr of suggestions to keep +/// +/// @return the maximum score in the list or "maxscore" unmodified. +static int cleanup_suggestions(garray_T *gap, int maxscore, int keep) FUNC_ATTR_NONNULL_ALL { if (gap->ga_len > 0) { @@ -5823,12 +5978,12 @@ char *eval_soundfold(const char *const word) void spell_soundfold(slang_T *slang, char_u *inword, bool folded, char_u *res) { char_u fword[MAXWLEN]; - char_u *word; + char_u *word; - if (slang->sl_sofo) + if (slang->sl_sofo) { // SOFOFROM and SOFOTO used spell_soundfold_sofo(slang, inword, res); - else { + } else { // SAL items used. Requires the word to be case-folded. if (folded) { word = inword; @@ -5892,12 +6047,12 @@ static void spell_soundfold_sofo(slang_T *slang, char_u *inword, char_u *res) // Multi-byte version of spell_soundfold(). static void spell_soundfold_wsal(slang_T *slang, char_u *inword, char_u *res) { - salitem_T *smp = (salitem_T *)slang->sl_sal.ga_data; + salitem_T *smp = (salitem_T *)slang->sl_sal.ga_data; int word[MAXWLEN] = { 0 }; int wres[MAXWLEN] = { 0 }; int l; - int *ws; - int *pf; + int *ws; + int *pf; int i, j, z; int reslen; int n, k = 0; @@ -5954,27 +6109,34 @@ static void spell_soundfold_wsal(slang_T *slang, char_u *inword, char_u *res) && ws[0] != NUL; ++n) { // Quickly skip entries that don't match the word. Most // entries are less then three chars, optimize for that. - if (c != ws[0]) + if (c != ws[0]) { continue; + } k = smp[n].sm_leadlen; if (k > 1) { - if (word[i + 1] != ws[1]) + if (word[i + 1] != ws[1]) { continue; + } if (k > 2) { - for (j = 2; j < k; ++j) - if (word[i + j] != ws[j]) + for (j = 2; j < k; ++j) { + if (word[i + j] != ws[j]) { break; - if (j < k) + } + } + if (j < k) { continue; + } } } if ((pf = smp[n].sm_oneof_w) != NULL) { // Check for match with one of the chars in "sm_oneof". - while (*pf != NUL && *pf != word[i + k]) + while (*pf != NUL && *pf != word[i + k]) { ++pf; - if (*pf == NUL) + } + if (*pf == NUL) { continue; + } ++k; } char_u *s = smp[n].sm_rules; @@ -5986,15 +6148,17 @@ static void spell_soundfold_wsal(slang_T *slang, char_u *inword, char_u *res) k--; s++; } - if (*s == '<') + if (*s == '<') { s++; + } if (ascii_isdigit(*s)) { // determine priority pri = *s - '0'; s++; } - if (*s == '^' && *(s + 1) == '^') + if (*s == '^' && *(s + 1) == '^') { s++; + } if (*s == NUL || (*s == '^' @@ -6017,19 +6181,24 @@ static void spell_soundfold_wsal(slang_T *slang, char_u *inword, char_u *res) for (; ((ws = smp[n0].sm_lead_w)[0] & 0xff) == (c0 & 0xff); ++n0) { // Quickly skip entries that don't match the word. - if (c0 != ws[0]) + if (c0 != ws[0]) { continue; + } k0 = smp[n0].sm_leadlen; if (k0 > 1) { - if (word[i + k] != ws[1]) + if (word[i + k] != ws[1]) { continue; + } if (k0 > 2) { pf = word + i + k + 1; - for (j = 2; j < k0; ++j) - if (*pf++ != ws[j]) + for (j = 2; j < k0; ++j) { + if (*pf++ != ws[j]) { break; - if (j < k0) + } + } + if (j < k0) { continue; + } } } k0 += k - 1; @@ -6037,10 +6206,12 @@ static void spell_soundfold_wsal(slang_T *slang, char_u *inword, char_u *res) if ((pf = smp[n0].sm_oneof_w) != NULL) { // Check for match with one of the chars in // "sm_oneof". - while (*pf != NUL && *pf != word[i + k0]) + while (*pf != NUL && *pf != word[i + k0]) { ++pf; - if (*pf == NUL) + } + if (*pf == NUL) { continue; + } ++k0; } @@ -6051,8 +6222,9 @@ static void spell_soundfold_wsal(slang_T *slang, char_u *inword, char_u *res) // "if (k0 == k)" s++; } - if (*s == '<') + if (*s == '<') { s++; + } if (ascii_isdigit(*s)) { p0 = *s - '0'; s++; @@ -6062,22 +6234,25 @@ static void spell_soundfold_wsal(slang_T *slang, char_u *inword, char_u *res) // *s == '^' cuts || (*s == '$' && !spell_iswordp_w(word + i + k0, - curwin))) { - if (k0 == k) + curwin))) { + if (k0 == k) { // this is just a piece of the string continue; + } - if (p0 < pri) + if (p0 < pri) { // priority too low continue; + } // rule fits; stop search break; } } if (p0 >= pri && (smp[n0].sm_lead_w[0] & 0xff) - == (c0 & 0xff)) + == (c0 & 0xff)) { continue; + } } // replace string @@ -6088,20 +6263,23 @@ static void spell_soundfold_wsal(slang_T *slang, char_u *inword, char_u *res) // rule with '<' is used if (reslen > 0 && ws != NULL && *ws != NUL && (wres[reslen - 1] == c - || wres[reslen - 1] == *ws)) + || wres[reslen - 1] == *ws)) { reslen--; + } z0 = 1; z = 1; k0 = 0; - if (ws != NULL) + if (ws != NULL) { while (*ws != NUL && word[i + k0] != NUL) { word[i + k0] = *ws; k0++; ws++; } - if (k > k0) + } + if (k > k0) { memmove(word + i + k0, word + i + k, - sizeof(int) * (wordlen - (i + k) + 1)); + sizeof(int) * (wordlen - (i + k) + 1)); + } // new "actual letter" c = word[i]; @@ -6109,23 +6287,27 @@ static void spell_soundfold_wsal(slang_T *slang, char_u *inword, char_u *res) // no '<' rule used i += k - 1; z = 0; - if (ws != NULL) + if (ws != NULL) { while (*ws != NUL && ws[1] != NUL && reslen < MAXWLEN) { - if (reslen == 0 || wres[reslen - 1] != *ws) + if (reslen == 0 || wres[reslen - 1] != *ws) { wres[reslen++] = *ws; + } ws++; } + } // new "actual letter" - if (ws == NULL) + if (ws == NULL) { c = NUL; - else + } else { c = *ws; + } if (strstr((char *)s, "^^") != NULL) { - if (c != NUL) + if (c != NUL) { wres[reslen++] = c; + } memmove(word, word + i + 1, - sizeof(int) * (wordlen - (i + 1) + 1)); + sizeof(int) * (wordlen - (i + 1) + 1)); i = 0; z0 = 1; } @@ -6133,7 +6315,7 @@ static void spell_soundfold_wsal(slang_T *slang, char_u *inword, char_u *res) break; } } - } else if (ascii_iswhite(c)) { + } else if (ascii_iswhite(c)) { c = ' '; k = 1; } @@ -6141,9 +6323,10 @@ static void spell_soundfold_wsal(slang_T *slang, char_u *inword, char_u *res) if (z0 == 0) { if (k && !p0 && reslen < MAXWLEN && c != NUL && (!slang->sl_collapse || reslen == 0 - || wres[reslen - 1] != c)) + || wres[reslen - 1] != c)) { // condense only double letters wres[reslen++] = c; + } i++; z = 0; @@ -6162,35 +6345,36 @@ static void spell_soundfold_wsal(slang_T *slang, char_u *inword, char_u *res) res[l] = NUL; } -// Compute a score for two sound-a-like words. -// This permits up to two inserts/deletes/swaps/etc. to keep things fast. -// Instead of a generic loop we write out the code. That keeps it fast by -// avoiding checks that will not be possible. -static int -soundalike_score ( - char_u *goodstart, // sound-folded good word - char_u *badstart // sound-folded bad word -) +/// Compute a score for two sound-a-like words. +/// This permits up to two inserts/deletes/swaps/etc. to keep things fast. +/// Instead of a generic loop we write out the code. That keeps it fast by +/// avoiding checks that will not be possible. +/// +/// @param goodstart sound-folded good word +/// @param badstart sound-folded bad word +static int soundalike_score(char_u *goodstart, char_u *badstart) { - char_u *goodsound = goodstart; - char_u *badsound = badstart; + char_u *goodsound = goodstart; + char_u *badsound = badstart; int goodlen; int badlen; int n; - char_u *pl, *ps; - char_u *pl2, *ps2; + char_u *pl, *ps; + char_u *pl2, *ps2; int score = 0; // Adding/inserting "*" at the start (word starts with vowel) shouldn't be // counted so much, vowels in the middle of the word aren't counted at all. if ((*badsound == '*' || *goodsound == '*') && *badsound != *goodsound) { if ((badsound[0] == NUL && goodsound[1] == NUL) - || (goodsound[0] == NUL && badsound[1] == NUL)) + || (goodsound[0] == NUL && badsound[1] == NUL)) { // changing word with vowel to word without a sound return SCORE_DEL; - if (badsound[0] == NUL || goodsound[0] == NUL) + } + if (badsound[0] == NUL || goodsound[0] == NUL) { // more than two changes return SCORE_MAXMAX; + } if (badsound[1] == goodsound[1] || (badsound[1] != NUL @@ -6199,10 +6383,11 @@ soundalike_score ( // handle like a substitute } else { score = 2 * SCORE_DEL / 3; - if (*badsound == '*') + if (*badsound == '*') { ++badsound; - else + } else { ++goodsound; + } } } @@ -6212,8 +6397,9 @@ soundalike_score ( // Return quickly if the lengths are too different to be fixed by two // changes. n = goodlen - badlen; - if (n < -2 || n > 2) + if (n < -2 || n > 2) { return SCORE_MAXMAX; + } if (n > 0) { pl = goodsound; // goodsound is longest @@ -6239,8 +6425,9 @@ soundalike_score ( ++ps; } // strings must be equal after second delete - if (STRCMP(pl + 1, ps) == 0) + if (STRCMP(pl + 1, ps) == 0) { return score + SCORE_DEL * 2; + } // Failed to compare. break; @@ -6253,20 +6440,23 @@ soundalike_score ( pl2 = pl + 1; ps2 = ps; while (*pl2 == *ps2) { - if (*pl2 == NUL) // reached the end + if (*pl2 == NUL) { // reached the end return score + SCORE_DEL; + } ++pl2; ++ps2; } // 2: delete then swap, then rest must be equal if (pl2[0] == ps2[1] && pl2[1] == ps2[0] - && STRCMP(pl2 + 2, ps2 + 2) == 0) + && STRCMP(pl2 + 2, ps2 + 2) == 0) { return score + SCORE_DEL + SCORE_SWAP; + } // 3: delete then substitute, then the rest must be equal - if (STRCMP(pl2 + 1, ps2 + 1) == 0) + if (STRCMP(pl2 + 1, ps2 + 1) == 0) { return score + SCORE_DEL + SCORE_SUBST; + } // 4: first swap then delete if (pl[0] == ps[1] && pl[1] == ps[0]) { @@ -6277,8 +6467,9 @@ soundalike_score ( ++ps2; } // delete a char and then strings must be equal - if (STRCMP(pl2 + 1, ps2) == 0) + if (STRCMP(pl2 + 1, ps2) == 0) { return score + SCORE_SWAP + SCORE_DEL; + } } // 5: first substitute then delete @@ -6289,8 +6480,9 @@ soundalike_score ( ++ps2; } // delete a char and then strings must be equal - if (STRCMP(pl2 + 1, ps2) == 0) + if (STRCMP(pl2 + 1, ps2) == 0) { return score + SCORE_SUBST + SCORE_DEL; + } // Failed to compare. break; @@ -6299,47 +6491,54 @@ soundalike_score ( // Lengths are equal, thus changes must result in same length: An // insert is only possible in combination with a delete. // 1: check if for identical strings - if (*pl == NUL) + if (*pl == NUL) { return score; + } // 2: swap if (pl[0] == ps[1] && pl[1] == ps[0]) { pl2 = pl + 2; // swap, skip two chars ps2 = ps + 2; while (*pl2 == *ps2) { - if (*pl2 == NUL) // reached the end + if (*pl2 == NUL) { // reached the end return score + SCORE_SWAP; + } ++pl2; ++ps2; } // 3: swap and swap again if (pl2[0] == ps2[1] && pl2[1] == ps2[0] - && STRCMP(pl2 + 2, ps2 + 2) == 0) + && STRCMP(pl2 + 2, ps2 + 2) == 0) { return score + SCORE_SWAP + SCORE_SWAP; + } // 4: swap and substitute - if (STRCMP(pl2 + 1, ps2 + 1) == 0) + if (STRCMP(pl2 + 1, ps2 + 1) == 0) { return score + SCORE_SWAP + SCORE_SUBST; + } } // 5: substitute pl2 = pl + 1; ps2 = ps + 1; while (*pl2 == *ps2) { - if (*pl2 == NUL) // reached the end + if (*pl2 == NUL) { // reached the end return score + SCORE_SUBST; + } ++pl2; ++ps2; } // 6: substitute and swap if (pl2[0] == ps2[1] && pl2[1] == ps2[0] - && STRCMP(pl2 + 2, ps2 + 2) == 0) + && STRCMP(pl2 + 2, ps2 + 2) == 0) { return score + SCORE_SUBST + SCORE_SWAP; + } // 7: substitute and substitute - if (STRCMP(pl2 + 1, ps2 + 1) == 0) + if (STRCMP(pl2 + 1, ps2 + 1) == 0) { return score + SCORE_SUBST + SCORE_SUBST; + } // 8: insert then delete pl2 = pl; @@ -6348,8 +6547,9 @@ soundalike_score ( ++pl2; ++ps2; } - if (STRCMP(pl2 + 1, ps2) == 0) + if (STRCMP(pl2 + 1, ps2) == 0) { return score + SCORE_INS + SCORE_DEL; + } // 9: delete then insert pl2 = pl + 1; @@ -6358,8 +6558,9 @@ soundalike_score ( ++pl2; ++ps2; } - if (STRCMP(pl2, ps2 + 1) == 0) + if (STRCMP(pl2, ps2 + 1) == 0) { return score + SCORE_INS + SCORE_DEL; + } // Failed to compare. break; @@ -6408,8 +6609,9 @@ static int spell_edit_score(slang_T *slang, char_u *badword, char_u *goodword) cnt = xmalloc(sizeof(int) * (badlen + 1) * (goodlen + 1)); CNT(0, 0) = 0; - for (j = 1; j <= goodlen; ++j) + for (j = 1; j <= goodlen; ++j) { CNT(0, j) = CNT(0, j - 1) + SCORE_INS; + } for (i = 1; i <= badlen; ++i) { CNT(i, 0) = CNT(i - 1, 0) + SCORE_DEL; @@ -6420,16 +6622,17 @@ static int spell_edit_score(slang_T *slang, char_u *badword, char_u *goodword) CNT(i, j) = CNT(i - 1, j - 1); } else { // Use a better score when there is only a case difference. - if (SPELL_TOFOLD(bc) == SPELL_TOFOLD(gc)) + if (SPELL_TOFOLD(bc) == SPELL_TOFOLD(gc)) { CNT(i, j) = SCORE_ICASE + CNT(i - 1, j - 1); - else { + } else { // For a similar character use SCORE_SIMILAR. if (slang != NULL && slang->sl_has_map - && similar_chars(slang, gc, bc)) + && similar_chars(slang, gc, bc)) { CNT(i, j) = SCORE_SIMILAR + CNT(i - 1, j - 1); - else + } else { CNT(i, j) = SCORE_SUBST + CNT(i - 1, j - 1); + } } if (i > 1 && j > 1) { @@ -6437,16 +6640,19 @@ static int spell_edit_score(slang_T *slang, char_u *badword, char_u *goodword) pgc = wgoodword[j - 2]; if (bc == pgc && pbc == gc) { t = SCORE_SWAP + CNT(i - 2, j - 2); - if (t < CNT(i, j)) + if (t < CNT(i, j)) { CNT(i, j) = t; + } } } t = SCORE_DEL + CNT(i - 1, j); - if (t < CNT(i, j)) + if (t < CNT(i, j)) { CNT(i, j) = t; + } t = SCORE_INS + CNT(i, j - 1); - if (t < CNT(i, j)) + if (t < CNT(i, j)) { CNT(i, j) = t; + } } } } @@ -6515,11 +6721,13 @@ static int spell_edit_score_limit_w(slang_T *slang, char_u *badword, char_u *goo bc = wbadword[bi]; gc = wgoodword[gi]; - if (bc != gc) // stop at a char that's different + if (bc != gc) { // stop at a char that's different break; + } if (bc == NUL) { // both words end - if (score < minscore) + if (score < minscore) { minscore = score; + } goto pop; // do next alternative } ++bi; @@ -6528,14 +6736,16 @@ static int spell_edit_score_limit_w(slang_T *slang, char_u *badword, char_u *goo if (gc == NUL) { // goodword ends, delete badword chars do { - if ((score += SCORE_DEL) >= minscore) + if ((score += SCORE_DEL) >= minscore) { goto pop; // do next alternative + } } while (wbadword[++bi] != NUL); minscore = score; - } else if (bc == NUL) { // badword ends, insert badword chars + } else if (bc == NUL) { // badword ends, insert badword chars do { - if ((score += SCORE_INS) >= minscore) + if ((score += SCORE_INS) >= minscore) { goto pop; // do next alternative + } } while (wgoodword[++gi] != NUL); minscore = score; } else { // both words continue @@ -6586,16 +6796,17 @@ static int spell_edit_score_limit_w(slang_T *slang, char_u *badword, char_u *goo // Substitute one character for another which is the same // thing as deleting a character from both goodword and badword. // Use a better score when there is only a case difference. - if (SPELL_TOFOLD(bc) == SPELL_TOFOLD(gc)) + if (SPELL_TOFOLD(bc) == SPELL_TOFOLD(gc)) { score += SCORE_ICASE; - else { + } else { // For a similar character use SCORE_SIMILAR. if (slang != NULL && slang->sl_has_map - && similar_chars(slang, gc, bc)) + && similar_chars(slang, gc, bc)) { score += SCORE_SIMILAR; - else + } else { score += SCORE_SUBST; + } } if (score < minscore) { @@ -6607,8 +6818,9 @@ static int spell_edit_score_limit_w(slang_T *slang, char_u *badword, char_u *goo } pop: // Get here to try the next alternative, pop it from the stack. - if (stackidx == 0) // stack is empty, finished + if (stackidx == 0) { // stack is empty, finished break; + } // pop an item from the stack --stackidx; @@ -6620,8 +6832,9 @@ pop: // When the score goes over "limit" it may actually be much higher. // Return a very large number to avoid going below the limit when giving a // bonus. - if (minscore > limit) + if (minscore > limit) { return SCORE_MAXMAX; + } return minscore; } @@ -6656,7 +6869,7 @@ void ex_spellinfo(exarg_T *eap) // ":spelldump" void ex_spelldump(exarg_T *eap) { - char_u *spl; + char_u *spl; long dummy; if (no_spell_checking(curwin)) { @@ -6685,50 +6898,49 @@ void ex_spelldump(exarg_T *eap) redraw_later(curwin, NOT_VALID); } -// Go through all possible words and: -// 1. When "pat" is NULL: dump a list of all words in the current buffer. -// "ic" and "dir" are not used. -// 2. When "pat" is not NULL: add matching words to insert mode completion. -void -spell_dump_compl ( - char_u *pat, // leading part of the word - int ic, // ignore case - Direction *dir, // direction for adding matches - int dumpflags_arg // DUMPFLAG_* -) +/// Go through all possible words and: +/// 1. When "pat" is NULL: dump a list of all words in the current buffer. +/// "ic" and "dir" are not used. +/// 2. When "pat" is not NULL: add matching words to insert mode completion. +/// +/// @param pat leading part of the word +/// @param ic ignore case +/// @param dir direction for adding matches +/// @param dumpflags_arg DUMPFLAG_* +void spell_dump_compl(char_u *pat, int ic, Direction *dir, int dumpflags_arg) { - langp_T *lp; - slang_T *slang; + langp_T *lp; + slang_T *slang; idx_T arridx[MAXWLEN]; int curi[MAXWLEN]; char_u word[MAXWLEN]; int c; - char_u *byts; - idx_T *idxs; + char_u *byts; + idx_T *idxs; linenr_T lnum = 0; int round; int depth; int n; int flags; - char_u *region_names = NULL; // region names being used + char_u *region_names = NULL; // region names being used bool do_region = true; // dump region names and numbers - char_u *p; + char_u *p; int dumpflags = dumpflags_arg; int patlen; // When ignoring case or when the pattern starts with capital pass this on // to dump_word(). if (pat != NULL) { - if (ic) + if (ic) { dumpflags |= DUMPFLAG_ICASE; - else { + } else { n = captype(pat, NULL); - if (n == WF_ONECAP) + if (n == WF_ONECAP) { dumpflags |= DUMPFLAG_ONECAP; - else if (n == WF_ALLCAP - && (int)STRLEN(pat) > mb_ptr2len(pat) - ) + } else if (n == WF_ALLCAP + && (int)STRLEN(pat) > mb_ptr2len(pat)) { dumpflags |= DUMPFLAG_ALLCAP; + } } } @@ -6738,9 +6950,9 @@ spell_dump_compl ( lp = LANGP_ENTRY(curwin->w_s->b_langp, lpi); p = lp->lp_slang->sl_regions; if (p[0] != 0) { - if (region_names == NULL) // first language with regions + if (region_names == NULL) { // first language with regions region_names = p; - else if (STRCMP(region_names, p) != 0) { + } else if (STRCMP(region_names, p) != 0) { do_region = false; // region names are different break; } @@ -6752,15 +6964,17 @@ spell_dump_compl ( vim_snprintf((char *)IObuff, IOSIZE, "/regions=%s", region_names); ml_append(lnum++, IObuff, (colnr_T)0, false); } - } else + } else { do_region = false; + } // Loop over all files loaded for the entries in 'spelllang'. for (int lpi = 0; lpi < curwin->w_s->b_langp.ga_len; ++lpi) { lp = LANGP_ENTRY(curwin->w_s->b_langp, lpi); slang = lp->lp_slang; - if (slang->sl_fbyts == NULL) // reloading failed + if (slang->sl_fbyts == NULL) { // reloading failed continue; + } if (pat == NULL) { vim_snprintf((char *)IObuff, IOSIZE, "# file: %s", slang->sl_fname); @@ -6769,10 +6983,11 @@ spell_dump_compl ( // When matching with a pattern and there are no prefixes only use // parts of the tree that match "pat". - if (pat != NULL && slang->sl_pbyts == NULL) + if (pat != NULL && slang->sl_pbyts == NULL) { patlen = (int)STRLEN(pat); - else + } else { patlen = -1; + } // round 1: case-folded tree // round 2: keep-case tree @@ -6786,9 +7001,9 @@ spell_dump_compl ( byts = slang->sl_kbyts; idxs = slang->sl_kidxs; } - if (byts == NULL) + if (byts == NULL) { continue; // array is empty - + } depth = 0; arridx[0] = 0; curi[0] = 1; @@ -6817,23 +7032,26 @@ spell_dump_compl ( || (((unsigned)flags >> 16) & lp->lp_region) != 0)) { word[depth] = NUL; - if (!do_region) + if (!do_region) { flags &= ~WF_REGION; + } // Dump the basic word if there is no prefix or // when it's the first one. c = (unsigned)flags >> 24; if (c == 0 || curi[depth] == 2) { dump_word(slang, word, pat, dir, - dumpflags, flags, lnum); - if (pat == NULL) + dumpflags, flags, lnum); + if (pat == NULL) { ++lnum; + } } // Apply the prefix, if there is one. - if (c != 0) + if (c != 0) { lnum = dump_prefixes(slang, word, pat, dir, - dumpflags, flags, lnum); + dumpflags, flags, lnum); + } } } else { // Normal char, go one level deeper. @@ -6849,8 +7067,9 @@ spell_dump_compl ( // ignore case... assert(depth >= 0); if (depth <= patlen - && mb_strnicmp(word, pat, (size_t)depth) != 0) + && mb_strnicmp(word, pat, (size_t)depth) != 0) { --depth; + } } } } @@ -6860,22 +7079,23 @@ spell_dump_compl ( // Dumps one word: apply case modifications and append a line to the buffer. // When "lnum" is zero add insert mode completion. -static void dump_word(slang_T *slang, char_u *word, char_u *pat, - Direction *dir, int dumpflags, int wordflags, - linenr_T lnum) +static void dump_word(slang_T *slang, char_u *word, char_u *pat, Direction *dir, int dumpflags, + int wordflags, linenr_T lnum) { bool keepcap = false; - char_u *p; - char_u *tw; + char_u *p; + char_u *tw; char_u cword[MAXWLEN]; char_u badword[MAXWLEN + 10]; int i; int flags = wordflags; - if (dumpflags & DUMPFLAG_ONECAP) + if (dumpflags & DUMPFLAG_ONECAP) { flags |= WF_ONECAP; - if (dumpflags & DUMPFLAG_ALLCAP) + } + if (dumpflags & DUMPFLAG_ALLCAP) { flags |= WF_ALLCAP; + } if ((dumpflags & DUMPFLAG_KEEPCASE) == 0 && (flags & WF_CAPMASK) != 0) { // Need to fix case according to "flags". @@ -6885,8 +7105,9 @@ static void dump_word(slang_T *slang, char_u *word, char_u *pat, p = word; if ((dumpflags & DUMPFLAG_KEEPCASE) && ((captype(word, NULL) & WF_KEEPCAP) == 0 - || (flags & WF_FIXCAP) != 0)) + || (flags & WF_FIXCAP) != 0)) { keepcap = true; + } } tw = p; @@ -6917,13 +7138,13 @@ static void dump_word(slang_T *slang, char_u *word, char_u *pat, } if (dumpflags & DUMPFLAG_COUNT) { - hashitem_T *hi; + hashitem_T *hi; // Include the word count for ":spelldump!". hi = hash_find(&slang->sl_wordcount, tw); if (!HASHITEM_EMPTY(hi)) { vim_snprintf((char *)IObuff, IOSIZE, "%s\t%d", - tw, HI2WC(hi)->wc_count); + tw, HI2WC(hi)->wc_count); p = IObuff; } } @@ -6939,20 +7160,16 @@ static void dump_word(slang_T *slang, char_u *word, char_u *pat, } } -// For ":spelldump": Find matching prefixes for "word". Prepend each to -// "word" and append a line to the buffer. -// When "lnum" is zero add insert mode completion. -// Return the updated line number. -static linenr_T -dump_prefixes ( - slang_T *slang, - char_u *word, // case-folded word - char_u *pat, - Direction *dir, - int dumpflags, - int flags, // flags with prefix ID - linenr_T startlnum -) +/// For ":spelldump": Find matching prefixes for "word". Prepend each to +/// "word" and append a line to the buffer. +/// When "lnum" is zero add insert mode completion. +/// +/// @param word case-folded word +/// @param flags flags with prefix ID +/// +/// @return the updated line number. +static linenr_T dump_prefixes(slang_T *slang, char_u *word, char_u *pat, Direction *dir, + int dumpflags, int flags, linenr_T startlnum) { idx_T arridx[MAXWLEN]; int curi[MAXWLEN]; @@ -6960,8 +7177,8 @@ dump_prefixes ( char_u word_up[MAXWLEN]; bool has_word_up = false; int c; - char_u *byts; - idx_T *idxs; + char_u *byts; + idx_T *idxs; linenr_T lnum = startlnum; int depth; int n; @@ -6998,19 +7215,22 @@ dump_prefixes ( c = byts[n]; if (c == 0) { // End of prefix, find out how many IDs there are. - for (i = 1; i < len; ++i) - if (byts[n + i] != 0) + for (i = 1; i < len; ++i) { + if (byts[n + i] != 0) { break; + } + } curi[depth] += i - 1; c = valid_word_prefix(i, n, flags, word, slang, false); if (c != 0) { STRLCPY(prefix + depth, word, MAXWLEN - depth); dump_word(slang, prefix, pat, dir, dumpflags, - (c & WF_RAREPFX) ? (flags | WF_RARE) - : flags, lnum); - if (lnum != 0) + (c & WF_RAREPFX) ? (flags | WF_RARE) + : flags, lnum); + if (lnum != 0) { ++lnum; + } } // Check for prefix that matches the word when the @@ -7018,14 +7238,15 @@ dump_prefixes ( // a condition. if (has_word_up) { c = valid_word_prefix(i, n, flags, word_up, slang, - true); + true); if (c != 0) { STRLCPY(prefix + depth, word_up, MAXWLEN - depth); dump_word(slang, prefix, pat, dir, dumpflags, - (c & WF_RAREPFX) ? (flags | WF_RARE) - : flags, lnum); - if (lnum != 0) + (c & WF_RAREPFX) ? (flags | WF_RARE) + : flags, lnum); + if (lnum != 0) { ++lnum; + } } } } else { @@ -7045,7 +7266,7 @@ dump_prefixes ( // Uses the spell-checking word characters. char_u *spell_to_word_end(char_u *start, win_T *win) { - char_u *p = start; + char_u *p = start; while (*p != NUL && spell_iswordp(p, win)) { MB_PTR_ADV(p); @@ -7060,8 +7281,8 @@ char_u *spell_to_word_end(char_u *start, win_T *win) // Returns the column number of the word. int spell_word_start(int startcol) { - char_u *line; - char_u *p; + char_u *line; + char_u *p; int col = 0; if (no_spell_checking(curwin)) { diff --git a/src/nvim/spellfile.c b/src/nvim/spellfile.c index 843ecec1b1..772275df84 100644 --- a/src/nvim/spellfile.c +++ b/src/nvim/spellfile.c @@ -226,19 +226,17 @@ // stored as an offset to the previous number in as // few bytes as possible, see offset2bytes()) -#include <stdio.h> #include <stdint.h> +#include <stdio.h> #include <wctype.h> -#include "nvim/vim.h" -#include "nvim/spell_defs.h" #include "nvim/ascii.h" #include "nvim/buffer.h" #include "nvim/charset.h" #include "nvim/ex_cmds2.h" #include "nvim/fileio.h" -#include "nvim/memory.h" #include "nvim/memline.h" +#include "nvim/memory.h" #include "nvim/misc1.h" #include "nvim/option.h" #include "nvim/os/os.h" @@ -246,9 +244,11 @@ #include "nvim/regexp.h" #include "nvim/screen.h" #include "nvim/spell.h" +#include "nvim/spell_defs.h" #include "nvim/spellfile.h" #include "nvim/ui.h" #include "nvim/undo.h" +#include "nvim/vim.h" #ifndef UNIX // it's in os/unix_defs.h for Unix # include <time.h> // for time_t @@ -310,7 +310,7 @@ static char *msg_compressing = N_("Compressing word tree..."); // and .dic file. // Main structure to store the contents of a ".aff" file. typedef struct afffile_S { - char_u *af_enc; // "SET", normalized, alloc'ed string or NULL + char_u *af_enc; // "SET", normalized, alloc'ed string or NULL int af_flagtype; // AFT_CHAR, AFT_LONG, AFT_NUM or AFT_CAPLONG unsigned af_rare; // RARE ID for rare word unsigned af_keepcase; // KEEPCASE ID for keep-case word @@ -338,17 +338,17 @@ typedef struct afffile_S { typedef struct affentry_S affentry_T; // Affix entry from ".aff" file. Used for prefixes and suffixes. struct affentry_S { - affentry_T *ae_next; // next affix with same name/number - char_u *ae_chop; // text to chop off basic word (can be NULL) - char_u *ae_add; // text to add to basic word (can be NULL) - char_u *ae_flags; // flags on the affix (can be NULL) - char_u *ae_cond; // condition (NULL for ".") - regprog_T *ae_prog; // regexp program for ae_cond or NULL + affentry_T *ae_next; // next affix with same name/number + char_u *ae_chop; // text to chop off basic word (can be NULL) + char_u *ae_add; // text to add to basic word (can be NULL) + char_u *ae_flags; // flags on the affix (can be NULL) + char_u *ae_cond; // condition (NULL for ".") + regprog_T *ae_prog; // regexp program for ae_cond or NULL char ae_compforbid; // COMPOUNDFORBIDFLAG found char ae_comppermit; // COMPOUNDPERMITFLAG found }; -# define AH_KEY_LEN 17 // 2 x 8 bytes + NUL +#define AH_KEY_LEN 17 // 2 x 8 bytes + NUL // Affix header from ".aff" file. Used for af_pref and af_suff. typedef struct affheader_S { @@ -357,7 +357,7 @@ typedef struct affheader_S { int ah_newID; // prefix ID after renumbering; 0 if not used int ah_combine; // suffix may combine with prefix int ah_follows; // another affix block should be following - affentry_T *ah_first; // first affix entry + affentry_T *ah_first; // first affix entry } affheader_T; #define HI2AH(hi) ((affheader_T *)(hi)->hi_key) @@ -381,7 +381,7 @@ typedef struct compitem_S { typedef struct sblock_S sblock_T; struct sblock_S { int sb_used; // nr of bytes already in use - sblock_T *sb_next; // next block in list + sblock_T *sb_next; // next block in list char_u sb_data[1]; // data, actually longer }; @@ -397,9 +397,9 @@ struct wordnode_S { wordnode_T *next; // next node with same hash key wordnode_T *wnode; // parent node that will write this node } wn_u2; - wordnode_T *wn_child; // child (next byte in word) - wordnode_T *wn_sibling; // next sibling (alternate byte in word, - // always sorted) + wordnode_T *wn_child; // child (next byte in word) + wordnode_T *wn_sibling; // next sibling (alternate byte in word, + // always sorted) int wn_refs; // Nr. of references to this node. Only // relevant for first node in a list of // siblings, in following siblings it is @@ -425,29 +425,29 @@ struct wordnode_S { // Info used while reading the spell files. typedef struct spellinfo_S { - wordnode_T *si_foldroot; // tree with case-folded words + wordnode_T *si_foldroot; // tree with case-folded words long si_foldwcount; // nr of words in si_foldroot - wordnode_T *si_keeproot; // tree with keep-case words + wordnode_T *si_keeproot; // tree with keep-case words long si_keepwcount; // nr of words in si_keeproot - wordnode_T *si_prefroot; // tree with postponed prefixes + wordnode_T *si_prefroot; // tree with postponed prefixes long si_sugtree; // creating the soundfolding trie - sblock_T *si_blocks; // memory blocks used + sblock_T *si_blocks; // memory blocks used long si_blocks_cnt; // memory blocks allocated int si_did_emsg; // TRUE when ran out of memory long si_compress_cnt; // words to add before lowering // compression limit - wordnode_T *si_first_free; // List of nodes that have been freed during - // compression, linked by "wn_child" field. + wordnode_T *si_first_free; // List of nodes that have been freed during + // compression, linked by "wn_child" field. long si_free_count; // number of nodes in si_first_free #ifdef SPELL_PRINTTREE int si_wordnode_nr; // sequence nr for nodes #endif - buf_T *si_spellbuf; // buffer used to store soundfold word table + buf_T *si_spellbuf; // buffer used to store soundfold word table int si_ascii; // handling only ASCII words int si_add; // addition file @@ -457,18 +457,18 @@ typedef struct spellinfo_S { int si_memtot; // runtime memory used int si_verbose; // verbose messages int si_msg_count; // number of words added since last message - char_u *si_info; // info text chars or NULL + char_u *si_info; // info text chars or NULL int si_region_count; // number of regions supported (1 when there // are no regions) char_u si_region_name[MAXREGIONS * 2 + 1]; - // region names; used only if - // si_region_count > 1) + // region names; used only if + // si_region_count > 1) garray_T si_rep; // list of fromto_T entries from REP lines garray_T si_repsal; // list of fromto_T entries from REPSAL lines garray_T si_sal; // list of fromto_T entries from SAL lines - char_u *si_sofofr; // SOFOFROM text - char_u *si_sofoto; // SOFOTO text + char_u *si_sofofr; // SOFOFROM text + char_u *si_sofoto; // SOFOTO text int si_nosugfile; // NOSUGFILE item found int si_nosplitsugs; // NOSPLITSUGS item found int si_nocompoundsugs; // NOCOMPOUNDSUGS item found @@ -478,16 +478,16 @@ typedef struct spellinfo_S { time_t si_sugtime; // timestamp for .sug file int si_rem_accents; // soundsalike: remove accents garray_T si_map; // MAP info concatenated - char_u *si_midword; // MIDWORD chars or NULL + char_u *si_midword; // MIDWORD chars or NULL int si_compmax; // max nr of words for compounding int si_compminlen; // minimal length for compounding int si_compsylmax; // max nr of syllables for compounding int si_compoptions; // COMP_ flags garray_T si_comppat; // CHECKCOMPOUNDPATTERN items, each stored as // a string - char_u *si_compflags; // flags used for compounding + char_u *si_compflags; // flags used for compounding char_u si_nobreak; // NOBREAK - char_u *si_syllable; // syllable string + char_u *si_syllable; // syllable string garray_T si_prefcond; // table with conditions for postponed // prefixes, each stored as a string int si_newprefID; // current value for ah_newID @@ -508,16 +508,16 @@ typedef struct spellinfo_S { /// @return Allows to proceed if everything is OK, returns SP_TRUNCERROR if /// there are not enough bytes, returns SP_OTHERERROR if reading failed. #define SPELL_READ_BYTES(buf, n, fd, exit_code) \ - do { \ - const size_t n__SPRB = (n); \ - FILE *const fd__SPRB = (fd); \ - char *const buf__SPRB = (buf); \ - const size_t read_bytes__SPRB = fread(buf__SPRB, 1, n__SPRB, fd__SPRB); \ - if (read_bytes__SPRB != n__SPRB) { \ - exit_code; \ - return feof(fd__SPRB) ? SP_TRUNCERROR : SP_OTHERERROR; \ - } \ - } while (0) + do { \ + const size_t n__SPRB = (n); \ + FILE *const fd__SPRB = (fd); \ + char *const buf__SPRB = (buf); \ + const size_t read_bytes__SPRB = fread(buf__SPRB, 1, n__SPRB, fd__SPRB); \ + if (read_bytes__SPRB != n__SPRB) { \ + exit_code; \ + return feof(fd__SPRB) ? SP_TRUNCERROR : SP_OTHERERROR; \ + } \ + } while (0) /// Like #SPELL_READ_BYTES, but also error out if NUL byte was read /// @@ -525,16 +525,16 @@ typedef struct spellinfo_S { /// there are not enough bytes, returns SP_OTHERERROR if reading failed, /// returns SP_FORMERROR if read out a NUL byte. #define SPELL_READ_NONNUL_BYTES(buf, n, fd, exit_code) \ - do { \ - const size_t n__SPRNB = (n); \ - FILE *const fd__SPRNB = (fd); \ - char *const buf__SPRNB = (buf); \ - SPELL_READ_BYTES(buf__SPRNB, n__SPRNB, fd__SPRNB, exit_code); \ - if (memchr(buf__SPRNB, NUL, (size_t)n__SPRNB)) { \ - exit_code; \ - return SP_FORMERROR; \ - } \ - } while (0) + do { \ + const size_t n__SPRNB = (n); \ + FILE *const fd__SPRNB = (fd); \ + char *const buf__SPRNB = (buf); \ + SPELL_READ_BYTES(buf__SPRNB, n__SPRNB, fd__SPRNB, exit_code); \ + if (memchr(buf__SPRNB, NUL, (size_t)n__SPRNB)) { \ + exit_code; \ + return SP_FORMERROR; \ + } \ + } while (0) /// Check that spell file starts with a magic string /// @@ -556,40 +556,36 @@ static inline int spell_check_magic_string(FILE *const fd) return 0; } -// Load one spell file and store the info into a slang_T. -// -// This is invoked in three ways: -// - From spell_load_cb() to load a spell file for the first time. "lang" is -// the language name, "old_lp" is NULL. Will allocate an slang_T. -// - To reload a spell file that was changed. "lang" is NULL and "old_lp" -// points to the existing slang_T. -// - Just after writing a .spl file; it's read back to produce the .sug file. -// "old_lp" is NULL and "lang" is NULL. Will allocate an slang_T. -// -// Returns the slang_T the spell file was loaded into. NULL for error. -slang_T * -spell_load_file ( - char_u *fname, - char_u *lang, - slang_T *old_lp, - bool silent // no error if file doesn't exist -) +/// Load one spell file and store the info into a slang_T. +/// +/// This is invoked in three ways: +/// - From spell_load_cb() to load a spell file for the first time. "lang" is +/// the language name, "old_lp" is NULL. Will allocate an slang_T. +/// - To reload a spell file that was changed. "lang" is NULL and "old_lp" +/// points to the existing slang_T. +/// - Just after writing a .spl file; it's read back to produce the .sug file. +/// "old_lp" is NULL and "lang" is NULL. Will allocate an slang_T. +/// +/// @param silent no error if file doesn't exist +/// +/// @return the slang_T the spell file was loaded into. NULL for error. +slang_T *spell_load_file(char_u *fname, char_u *lang, slang_T *old_lp, bool silent) { - FILE *fd; - char_u *p; + FILE *fd; + char_u *p; int n; int len; - char_u *save_sourcing_name = sourcing_name; + char_u *save_sourcing_name = sourcing_name; linenr_T save_sourcing_lnum = sourcing_lnum; - slang_T *lp = NULL; + slang_T *lp = NULL; int c = 0; int res; fd = os_fopen((char *)fname, "r"); if (fd == NULL) { - if (!silent) + if (!silent) { EMSG2(_(e_notopen), fname); - else if (p_verbose > 2) { + } else if (p_verbose > 2) { verbose_enter(); smsg((char *)e_notopen, fname); verbose_leave(); @@ -610,8 +606,9 @@ spell_load_file ( // Check for .add.spl. lp->sl_add = strstr((char *)path_tail(fname), SPL_FNAME_ADD) != NULL; - } else + } else { lp = old_lp; + } // Set sourcing_name, so that error messages mention the file name. sourcing_name = fname; @@ -620,19 +617,16 @@ spell_load_file ( // <HEADER>: <fileID> const int scms_ret = spell_check_magic_string(fd); switch (scms_ret) { - case SP_FORMERROR: - case SP_TRUNCERROR: { - emsgf("%s", _("E757: This does not look like a spell file")); - goto endFAIL; - } - case SP_OTHERERROR: { - emsgf(_("E5042: Failed to read spell file %s: %s"), - fname, strerror(ferror(fd))); - goto endFAIL; - } - case 0: { - break; - } + case SP_FORMERROR: + case SP_TRUNCERROR: + emsgf("%s", _("E757: This does not look like a spell file")); + goto endFAIL; + case SP_OTHERERROR: + emsgf(_("E5042: Failed to read spell file %s: %s"), + fname, strerror(ferror(fd))); + goto endFAIL; + case 0: + break; } c = getc(fd); // <versionnr> if (c < VIMSPELLVERSION) { @@ -648,19 +642,22 @@ spell_load_file ( // <section>: <sectionID> <sectionflags> <sectionlen> (section contents) for (;; ) { n = getc(fd); // <sectionID> or <sectionend> - if (n == SN_END) + if (n == SN_END) { break; + } c = getc(fd); // <sectionflags> len = get4c(fd); // <sectionlen> - if (len < 0) + if (len < 0) { goto truncerr; + } res = 0; switch (n) { case SN_INFO: lp->sl_info = READ_STRING(fd, len); // <infotext> - if (lp->sl_info == NULL) + if (lp->sl_info == NULL) { goto endFAIL; + } break; case SN_REGION: @@ -673,8 +670,9 @@ spell_load_file ( case SN_MIDWORD: lp->sl_midword = READ_STRING(fd, len); // <midword> - if (lp->sl_midword == NULL) + if (lp->sl_midword == NULL) { goto endFAIL; + } break; case SN_PREFCOND: @@ -699,8 +697,9 @@ spell_load_file ( case SN_MAP: p = READ_STRING(fd, len); // <mapstr> - if (p == NULL) + if (p == NULL) { goto endFAIL; + } set_map_str(lp, p); xfree(p); break; @@ -731,10 +730,12 @@ spell_load_file ( case SN_SYLLABLE: lp->sl_syllable = READ_STRING(fd, len); // <syllable> - if (lp->sl_syllable == NULL) + if (lp->sl_syllable == NULL) { goto endFAIL; - if (init_syl_tab(lp) == FAIL) + } + if (init_syl_tab(lp) == FAIL) { goto endFAIL; + } break; default: @@ -744,9 +745,11 @@ spell_load_file ( EMSG(_("E770: Unsupported section in spell file")); goto endFAIL; } - while (--len >= 0) - if (getc(fd) < 0) + while (--len >= 0) { + if (getc(fd) < 0) { goto truncerr; + } + } break; } someerror: @@ -759,8 +762,9 @@ truncerr: EMSG(_(e_spell_trunc)); goto endFAIL; } - if (res == SP_OTHERERROR) + if (res == SP_OTHERERROR) { goto endFAIL; + } } // <LWORDTREE> @@ -792,16 +796,19 @@ truncerr: goto endOK; endFAIL: - if (lang != NULL) + if (lang != NULL) { // truncating the name signals the error to spell_load_lang() *lang = NUL; - if (lp != NULL && old_lp == NULL) + } + if (lp != NULL && old_lp == NULL) { slang_free(lp); + } lp = NULL; endOK: - if (fd != NULL) + if (fd != NULL) { fclose(fd); + } sourcing_name = save_sourcing_name; sourcing_lnum = save_sourcing_lnum; @@ -827,8 +834,9 @@ static void tree_count_words(char_u *byts, idx_T *idxs) if (curi[depth] > byts[arridx[depth]]) { // Done all bytes at this node, go up one level. idxs[arridx[depth]] = wordcount[depth]; - if (depth > 0) + if (depth > 0) { wordcount[depth - 1] += wordcount[depth]; + } --depth; fast_breakcheck(); @@ -862,10 +870,10 @@ static void tree_count_words(char_u *byts, idx_T *idxs) // Load the .sug files for languages that have one and weren't loaded yet. void suggest_load_files(void) { - langp_T *lp; - slang_T *slang; - char_u *dotp; - FILE *fd; + langp_T *lp; + slang_T *slang; + char_u *dotp; + FILE *fd; char_u buf[MAXWLEN]; int i; time_t timestamp; @@ -895,21 +903,22 @@ void suggest_load_files(void) } // <SUGHEADER>: <fileID> <versionnr> <timestamp> - for (i = 0; i < VIMSUGMAGICL; ++i) + for (i = 0; i < VIMSUGMAGICL; ++i) { buf[i] = getc(fd); // <fileID> + } if (STRNCMP(buf, VIMSUGMAGIC, VIMSUGMAGICL) != 0) { EMSG2(_("E778: This does not look like a .sug file: %s"), - slang->sl_fname); + slang->sl_fname); goto nextone; } c = getc(fd); // <versionnr> if (c < VIMSUGVERSION) { EMSG2(_("E779: Old .sug file, needs to be updated: %s"), - slang->sl_fname); + slang->sl_fname); goto nextone; - } else if (c > VIMSUGVERSION) { + } else if (c > VIMSUGVERSION) { EMSG2(_("E780: .sug file is for newer version of Vim: %s"), - slang->sl_fname); + slang->sl_fname); goto nextone; } @@ -918,7 +927,7 @@ void suggest_load_files(void) timestamp = get8ctime(fd); // <timestamp> if (timestamp != slang->sl_sugtime) { EMSG2(_("E781: .sug file doesn't match .spl file: %s"), - slang->sl_fname); + slang->sl_fname); goto nextone; } @@ -928,7 +937,7 @@ void suggest_load_files(void) false, 0) != 0) { someerror: EMSG2(_("E782: error while reading .sug file: %s"), - slang->sl_fname); + slang->sl_fname); slang_clear_sug(slang); goto nextone; } @@ -942,8 +951,9 @@ someerror: // <sugwcount> wcount = get4c(fd); - if (wcount < 0) + if (wcount < 0) { goto someerror; + } // Read all the wordnr lists into the buffer, one NUL terminated // list per line. @@ -956,8 +966,9 @@ someerror: goto someerror; } GA_APPEND(char_u, &ga, c); - if (c == NUL) + if (c == NUL) { break; + } } if (ml_append_buf(slang->sl_sugbuf, (linenr_T)wordnr, ga.ga_data, ga.ga_len, true) == FAIL) { @@ -972,8 +983,9 @@ someerror: tree_count_words(slang->sl_sbyts, slang->sl_sidxs); nextone: - if (fd != NULL) + if (fd != NULL) { fclose(fd); + } STRCPY(dotp, ".spl"); } } @@ -988,7 +1000,7 @@ nextone: static char_u *read_cnt_string(FILE *fd, int cnt_bytes, int *cntp) { int cnt = 0; - char_u *str; + char_u *str; // read the length bytes, MSB first for (int i = 0; i < cnt_bytes; i++) { @@ -1001,12 +1013,13 @@ static char_u *read_cnt_string(FILE *fd, int cnt_bytes, int *cntp) cnt = (cnt << 8) + (unsigned)c; } *cntp = cnt; - if (cnt == 0) + if (cnt == 0) { return NULL; // nothing to read, return NULL - + } str = READ_STRING(fd, cnt); - if (str == NULL) + if (str == NULL) { *cntp = SP_OTHERERROR; + } return str; } @@ -1027,14 +1040,15 @@ static int read_region_section(FILE *fd, slang_T *lp, int len) // Return SP_*ERROR flags. static int read_charflags_section(FILE *fd) { - char_u *flags; - char_u *fol; + char_u *flags; + char_u *fol; int flagslen, follen; // <charflagslen> <charflags> flags = read_cnt_string(fd, 1, &flagslen); - if (flagslen < 0) + if (flagslen < 0) { return flagslen; + } // <folcharslen> <folchars> fol = read_cnt_string(fd, 2, &follen); @@ -1044,15 +1058,17 @@ static int read_charflags_section(FILE *fd) } // Set the word-char flags and fill SPELL_ISUPPER() table. - if (flags != NULL && fol != NULL) + if (flags != NULL && fol != NULL) { set_spell_charflags(flags, flagslen, fol); + } xfree(flags); xfree(fol); // When <charflagslen> is zero then <fcharlen> must also be zero. - if ((flags == NULL) != (fol == NULL)) + if ((flags == NULL) != (fol == NULL)) { return SP_FORMERROR; + } return 0; } @@ -1094,11 +1110,12 @@ static int read_prefcond_section(FILE *fd, slang_T *lp) static int read_rep_section(FILE *fd, garray_T *gap, int16_t *first) { int cnt; - fromto_T *ftp; + fromto_T *ftp; cnt = get2c(fd); // <repcount> - if (cnt < 0) + if (cnt < 0) { return SP_TRUNCERROR; + } ga_grow(gap, cnt); @@ -1107,15 +1124,18 @@ static int read_rep_section(FILE *fd, garray_T *gap, int16_t *first) int c; ftp = &((fromto_T *)gap->ga_data)[gap->ga_len]; ftp->ft_from = read_cnt_string(fd, 1, &c); - if (c < 0) + if (c < 0) { return c; - if (c == 0) + } + if (c == 0) { return SP_FORMERROR; + } ftp->ft_to = read_cnt_string(fd, 1, &c); if (c <= 0) { xfree(ftp->ft_from); - if (c < 0) + if (c < 0) { return c; + } return SP_FORMERROR; } } @@ -1126,8 +1146,9 @@ static int read_rep_section(FILE *fd, garray_T *gap, int16_t *first) } for (int i = 0; i < gap->ga_len; ++i) { ftp = &((fromto_T *)gap->ga_data)[i]; - if (first[*ftp->ft_from] == -1) + if (first[*ftp->ft_from] == -1) { first[*ftp->ft_from] = i; + } } return 0; } @@ -1137,10 +1158,10 @@ static int read_rep_section(FILE *fd, garray_T *gap, int16_t *first) static int read_sal_section(FILE *fd, slang_T *slang) { int cnt; - garray_T *gap; - salitem_T *smp; + garray_T *gap; + salitem_T *smp; int ccnt; - char_u *p; + char_u *p; slang->sl_sofo = false; @@ -1156,8 +1177,9 @@ static int read_sal_section(FILE *fd, slang_T *slang) } cnt = get2c(fd); // <salcount> - if (cnt < 0) + if (cnt < 0) { return SP_TRUNCERROR; + } gap = &slang->sl_sal; ga_init(gap, sizeof(salitem_T), 10); @@ -1169,8 +1191,9 @@ static int read_sal_section(FILE *fd, slang_T *slang) smp = &((salitem_T *)gap->ga_data)[gap->ga_len]; ccnt = getc(fd); // <salfromlen> - if (ccnt < 0) + if (ccnt < 0) { return SP_TRUNCERROR; + } p = xmalloc(ccnt + 2); smp->sm_lead = p; @@ -1178,8 +1201,9 @@ static int read_sal_section(FILE *fd, slang_T *slang) int i = 0; for (; i < ccnt; ++i) { c = getc(fd); // <salfrom> - if (vim_strchr((char_u *)"0123456789(-<^$", c) != NULL) + if (vim_strchr((char_u *)"0123456789(-<^$", c) != NULL) { break; + } *p++ = c; } smp->sm_leadlen = (int)(p - smp->sm_lead); @@ -1190,15 +1214,18 @@ static int read_sal_section(FILE *fd, slang_T *slang) smp->sm_oneof = p; for (++i; i < ccnt; ++i) { c = getc(fd); // <salfrom> - if (c == ')') + if (c == ')') { break; + } *p++ = c; } *p++ = NUL; - if (++i < ccnt) + if (++i < ccnt) { c = getc(fd); - } else + } + } else { smp->sm_oneof = NULL; + } // Any following chars go in sm_rules. smp->sm_rules = p; @@ -1209,7 +1236,8 @@ static int read_sal_section(FILE *fd, slang_T *slang) i++; if (i < ccnt) { SPELL_READ_NONNUL_BYTES( // <salfrom> - (char *)p, (size_t)(ccnt - i), fd, xfree(smp->sm_lead)); + (char *)p, (size_t)(ccnt - i), fd, + xfree(smp->sm_lead)); p += (ccnt - i); } *p++ = NUL; @@ -1272,13 +1300,16 @@ static int read_words_section(FILE *fd, slang_T *lp, int len) // Read one word at a time. for (i = 0;; ++i) { c = getc(fd); - if (c == EOF) + if (c == EOF) { return SP_TRUNCERROR; + } word[i] = c; - if (word[i] == NUL) + if (word[i] == NUL) { break; - if (i == MAXWLEN - 1) + } + if (i == MAXWLEN - 1) { return SP_FORMERROR; + } } // Init the count to 10. @@ -1293,15 +1324,16 @@ static int read_words_section(FILE *fd, slang_T *lp, int len) static int read_sofo_section(FILE *fd, slang_T *slang) { int cnt; - char_u *from, *to; + char_u *from, *to; int res; slang->sl_sofo = true; // <sofofromlen> <sofofrom> from = read_cnt_string(fd, 2, &cnt); - if (cnt < 0) + if (cnt < 0) { return cnt; + } // <sofotolen> <sofoto> to = read_cnt_string(fd, 2, &cnt); @@ -1311,12 +1343,13 @@ static int read_sofo_section(FILE *fd, slang_T *slang) } // Store the info in slang->sl_sal and/or slang->sl_sal_first. - if (from != NULL && to != NULL) + if (from != NULL && to != NULL) { res = set_sofo(slang, from, to); - else if (from != NULL || to != NULL) + } else if (from != NULL || to != NULL) { res = SP_FORMERROR; // only one of two strings is an error - else + } else { res = 0; + } xfree(from); xfree(to); @@ -1331,39 +1364,42 @@ static int read_compound(FILE *fd, slang_T *slang, int len) int todo = len; int c; int atstart; - char_u *pat; - char_u *pp; - char_u *cp; - char_u *ap; - char_u *crp; + char_u *pat; + char_u *pp; + char_u *cp; + char_u *ap; + char_u *crp; int cnt; - garray_T *gap; + garray_T *gap; - if (todo < 2) + if (todo < 2) { return SP_FORMERROR; // need at least two bytes - + } --todo; c = getc(fd); // <compmax> - if (c < 2) + if (c < 2) { c = MAXWLEN; + } slang->sl_compmax = c; --todo; c = getc(fd); // <compminlen> - if (c < 1) + if (c < 1) { c = 0; + } slang->sl_compminlen = c; --todo; c = getc(fd); // <compsylmax> - if (c < 1) + if (c < 1) { c = MAXWLEN; + } slang->sl_compsylmax = c; c = getc(fd); // <compoptions> - if (c != 0) + if (c != 0) { ungetc(c, fd); // be backwards compatible with Vim 7.0b - else { + } else { --todo; c = getc(fd); // only use the lower byte for now --todo; @@ -1381,13 +1417,15 @@ static int read_compound(FILE *fd, slang_T *slang, int len) ((char_u **)(gap->ga_data))[gap->ga_len++] = read_cnt_string(fd, 1, &cnt); // <comppatlen> <comppattext> - if (cnt < 0) + if (cnt < 0) { return cnt; + } todo -= cnt + 1; } } - if (todo < 0) + if (todo < 0) { return SP_FORMERROR; + } // Turn the COMPOUNDRULE items into a regexp pattern: // "a[bc]/a*b+" -> "^\(a[bc]\|a*b\+\)$". @@ -1436,17 +1474,18 @@ static int read_compound(FILE *fd, slang_T *slang, int len) if (atstart != 0) { // At start of item: copy flags to "sl_compstartflags". For a // [abc] item set "atstart" to 2 and copy up to the ']'. - if (c == '[') + if (c == '[') { atstart = 2; - else if (c == ']') + } else if (c == ']') { atstart = 0; - else { + } else { if (!byte_in_str(slang->sl_compstartflags, c)) { *cp++ = c; *cp = NUL; } - if (atstart == 1) + if (atstart == 1) { atstart = 0; + } } } @@ -1455,8 +1494,9 @@ static int read_compound(FILE *fd, slang_T *slang, int len) if (c == '?' || c == '+' || c == '*') { XFREE_CLEAR(slang->sl_comprules); crp = NULL; - } else + } else { *crp++ = c; + } } if (c == '/') { // slash separates two items @@ -1476,13 +1516,15 @@ static int read_compound(FILE *fd, slang_T *slang, int len) *pp++ = '$'; *pp = NUL; - if (crp != NULL) + if (crp != NULL) { *crp = NUL; + } slang->sl_compprog = vim_regcomp(pat, RE_MAGIC + RE_STRING + RE_STRICT); xfree(pat); - if (slang->sl_compprog == NULL) + if (slang->sl_compprog == NULL) { return SP_FORMERROR; + } return 0; } @@ -1491,8 +1533,8 @@ static int read_compound(FILE *fd, slang_T *slang, int len) // Returns SP_*ERROR flags when there is something wrong. static int set_sofo(slang_T *lp, char_u *from, char_u *to) { - char_u *s; - char_u *p; + char_u *s; + char_u *p; // Use "sl_sal" as an array with 256 pointers to a list of wide // characters. The index is the low byte of the character. @@ -1554,10 +1596,10 @@ static int set_sofo(slang_T *lp, char_u *from, char_u *to) // Fill the first-index table for "lp". static void set_sal_first(slang_T *lp) { - salfirst_T *sfirst; - salitem_T *smp; + salfirst_T *sfirst; + salitem_T *smp; int c; - garray_T *gap = &lp->sl_sal; + garray_T *gap = &lp->sl_sal; sfirst = lp->sl_sal_first; for (int i = 0; i < 256; ++i) { @@ -1613,24 +1655,21 @@ static int *mb_str2wide(char_u *s) return res; } -// Reads a tree from the .spl or .sug file. -// Allocates the memory and stores pointers in "bytsp" and "idxsp". -// This is skipped when the tree has zero length. -// Returns zero when OK, SP_ value for an error. -static int -spell_read_tree ( - FILE *fd, - char_u **bytsp, - long *bytsp_len, - idx_T **idxsp, - bool prefixtree, // true for the prefix tree - int prefixcnt // when "prefixtree" is true: prefix count -) +/// Reads a tree from the .spl or .sug file. +/// Allocates the memory and stores pointers in "bytsp" and "idxsp". +/// This is skipped when the tree has zero length. +/// +/// @param prefixtree true for the prefix tree +/// @param prefixcnt when "prefixtree" is true: prefix count +/// +/// @return zero when OK, SP_ value for an error. +static int spell_read_tree(FILE *fd, char_u **bytsp, long *bytsp_len, idx_T **idxsp, + bool prefixtree, int prefixcnt) FUNC_ATTR_NONNULL_ARG(1, 2, 4) { int idx; - char_u *bp; - idx_T *ip; + char_u *bp; + idx_T *ip; // The tree size was computed when writing the file, so that we can // allocate it as one long block. <nodecount> @@ -1656,30 +1695,28 @@ spell_read_tree ( // Recursively read the tree and store it in the array. idx = read_tree_node(fd, bp, ip, len, 0, prefixtree, prefixcnt); - if (idx < 0) + if (idx < 0) { return idx; + } } return 0; } -// Read one row of siblings from the spell file and store it in the byte array -// "byts" and index array "idxs". Recursively read the children. -// -// NOTE: The code here must match put_node()! -// -// Returns the index (>= 0) following the siblings. -// Returns SP_TRUNCERROR if the file is shorter than expected. -// Returns SP_FORMERROR if there is a format error. -static idx_T -read_tree_node ( - FILE *fd, - char_u *byts, - idx_T *idxs, - int maxidx, // size of arrays - idx_T startidx, // current index in "byts" and "idxs" - bool prefixtree, // true for reading PREFIXTREE - int maxprefcondnr // maximum for <prefcondnr> -) +/// Read one row of siblings from the spell file and store it in the byte array +/// "byts" and index array "idxs". Recursively read the children. +/// +/// NOTE: The code here must match put_node()! +/// +/// Returns the index (>= 0) following the siblings. +/// Returns SP_TRUNCERROR if the file is shorter than expected. +/// Returns SP_FORMERROR if there is a format error. +/// +/// @param maxidx size of arrays +/// @param startidx current index in "byts" and "idxs" +/// @param prefixtree true for reading PREFIXTREE +/// @param maxprefcondnr maximum for <prefcondnr> +static idx_T read_tree_node(FILE *fd, char_u *byts, idx_T *idxs, int maxidx, idx_T startidx, + bool prefixtree, int maxprefcondnr) { int len; int i; @@ -1690,18 +1727,21 @@ read_tree_node ( #define SHARED_MASK 0x8000000 len = getc(fd); // <siblingcount> - if (len <= 0) + if (len <= 0) { return SP_TRUNCERROR; + } - if (startidx + len >= maxidx) + if (startidx + len >= maxidx) { return SP_FORMERROR; + } byts[idx++] = len; // Read the byte values, flag/region bytes and shared indexes. for (i = 1; i <= len; ++i) { c = getc(fd); // <byte> - if (c < 0) + if (c < 0) { return SP_TRUNCERROR; + } if (c <= BY_SPECIAL) { if (c == BY_NOFLAGS && !prefixtree) { // No flags, all regions. @@ -1712,16 +1752,18 @@ read_tree_node ( // condition nr. In idxs[] store the prefix ID in the low // byte, the condition index shifted up 8 bits, the flags // shifted up 24 bits. - if (c == BY_FLAGS) + if (c == BY_FLAGS) { c = getc(fd) << 24; // <pflags> - else + } else { c = 0; + } c |= getc(fd); // <affixID> n = get2c(fd); // <prefcondnr> - if (n >= maxprefcondnr) + if (n >= maxprefcondnr) { return SP_FORMERROR; + } c |= (n << 8); } else { // c must be BY_FLAGS or BY_FLAGS2 // Read flags and optional region and prefix ID. In @@ -1729,21 +1771,25 @@ read_tree_node ( // that and prefix ID above the region. c2 = c; c = getc(fd); // <flags> - if (c2 == BY_FLAGS2) + if (c2 == BY_FLAGS2) { c = (getc(fd) << 8) + c; // <flags2> - if (c & WF_REGION) + } + if (c & WF_REGION) { c = (getc(fd) << 16) + c; // <region> - if (c & WF_AFX) + } + if (c & WF_AFX) { c = (getc(fd) << 24) + c; // <affixID> + } } idxs[idx] = c; c = 0; - } else { // c == BY_INDEX + } else { // c == BY_INDEX // <nodeidx> n = get3c(fd); - if (n < 0 || n >= maxidx) + if (n < 0 || n >= maxidx) { return SP_FORMERROR; + } idxs[idx] = n + SHARED_MASK; c = getc(fd); // <xbyte> } @@ -1754,38 +1800,39 @@ read_tree_node ( // Recursively read the children for non-shared siblings. // Skip the end-of-word ones (zero byte value) and the shared ones (and // remove SHARED_MASK) - for (i = 1; i <= len; ++i) + for (i = 1; i <= len; ++i) { if (byts[startidx + i] != 0) { - if (idxs[startidx + i] & SHARED_MASK) + if (idxs[startidx + i] & SHARED_MASK) { idxs[startidx + i] &= ~SHARED_MASK; - else { + } else { idxs[startidx + i] = idx; idx = read_tree_node(fd, byts, idxs, maxidx, idx, - prefixtree, maxprefcondnr); - if (idx < 0) + prefixtree, maxprefcondnr); + if (idx < 0) { break; + } } } + } return idx; } -// Reload the spell file "fname" if it's loaded. -static void -spell_reload_one ( - char_u *fname, - bool added_word // invoked through "zg" -) +/// Reload the spell file "fname" if it's loaded. +/// +/// @param added_word invoked through "zg" +static void spell_reload_one(char_u *fname, bool added_word) { - slang_T *slang; + slang_T *slang; bool didit = false; for (slang = first_lang; slang != NULL; slang = slang->sl_next) { if (path_full_compare(fname, slang->sl_fname, false, true) == kEqualFiles) { slang_clear(slang); - if (spell_load_file(fname, NULL, slang, false) == NULL) + if (spell_load_file(fname, NULL, slang, false) == NULL) { // reloading failed, clear the language slang_clear(slang); + } redraw_all_later(SOME_VALID); didit = true; } @@ -1793,8 +1840,9 @@ spell_reload_one ( // When "zg" was used and the file wasn't loaded yet, should redo // 'spelllang' to load it now. - if (added_word && !didit) + if (added_word && !didit) { did_set_spelllang(curwin); + } } // Functions for ":mkspell". @@ -1820,13 +1868,14 @@ static long compress_added = 500000; // word count // Sets "sps_flags". int spell_check_msm(void) { - char_u *p = p_msm; + char_u *p = p_msm; long start = 0; long incr = 0; long added = 0; - if (!ascii_isdigit(*p)) + if (!ascii_isdigit(*p)) { return FAIL; + } // block count = (value * 1024) / SBLOCKSIZE (but avoid overflow) start = (getdigits_long(&p, true, 0) * 10) / (SBLOCKSIZE / 102); if (*p != ',') { @@ -1864,11 +1913,12 @@ int spell_check_msm(void) // readable format, so that we can see what happens when adding a word and/or // compressing the tree. // Based on code from Olaf Seibert. -#define PRINTLINESIZE 1000 -#define PRINTWIDTH 6 +# define PRINTLINESIZE 1000 +# define PRINTWIDTH 6 -#define PRINTSOME(l, depth, fmt, a1, a2) vim_snprintf(l + depth * PRINTWIDTH, \ - PRINTLINESIZE - PRINTWIDTH * depth, fmt, a1, a2) +# define PRINTSOME(l, depth, fmt, a1, a2) vim_snprintf(l + depth * PRINTWIDTH, \ + PRINTLINESIZE - PRINTWIDTH * depth, fmt, a1, \ + a2) static char line1[PRINTLINESIZE]; static char line2[PRINTLINESIZE]; @@ -1876,7 +1926,7 @@ static char line3[PRINTLINESIZE]; static void spell_clear_flags(wordnode_T *node) { - wordnode_T *np; + wordnode_T *np; for (np = node; np != NULL; np = np->wn_sibling) { np->wn_u1.index = FALSE; @@ -1898,20 +1948,23 @@ static void spell_print_node(wordnode_T *node, int depth) node->wn_u1.index = TRUE; if (node->wn_byte != NUL) { - if (node->wn_child != NULL) + if (node->wn_child != NULL) { PRINTSOME(line1, depth, " %c -> ", node->wn_byte, 0); - else + } else { // Cannot happen? PRINTSOME(line1, depth, " %c ???", node->wn_byte, 0); - } else + } + } else { PRINTSOME(line1, depth, " $ ", 0, 0); + } PRINTSOME(line2, depth, "%d/%d ", node->wn_nr, node->wn_refs); - if (node->wn_sibling != NULL) + if (node->wn_sibling != NULL) { PRINTSOME(line3, depth, " | ", 0, 0); - else + } else { PRINTSOME(line3, depth, " ", 0, 0); + } if (node->wn_byte == NUL) { msg((char_u *)line1); @@ -1920,8 +1973,9 @@ static void spell_print_node(wordnode_T *node, int depth) } // do the children - if (node->wn_byte != NUL && node->wn_child != NULL) + if (node->wn_byte != NUL && node->wn_child != NULL) { spell_print_node(node->wn_child, depth + 1); + } // do the siblings if (node->wn_sibling != NULL) { @@ -1951,39 +2005,39 @@ static void spell_print_tree(wordnode_T *root) // Returns an afffile_T, NULL for complete failure. static afffile_T *spell_read_aff(spellinfo_T *spin, char_u *fname) { - FILE *fd; + FILE *fd; char_u rline[MAXLINELEN]; - char_u *line; - char_u *pc = NULL; + char_u *line; + char_u *pc = NULL; #define MAXITEMCNT 30 - char_u *(items[MAXITEMCNT]); + char_u *(items[MAXITEMCNT]); int itemcnt; - char_u *p; + char_u *p; int lnum = 0; affheader_T *cur_aff = NULL; bool did_postpone_prefix = false; int aff_todo = 0; - hashtab_T *tp; - char_u *low = NULL; - char_u *fol = NULL; - char_u *upp = NULL; + hashtab_T *tp; + char_u *low = NULL; + char_u *fol = NULL; + char_u *upp = NULL; int do_rep; int do_repsal; int do_sal; int do_mapline; bool found_map = false; - hashitem_T *hi; + hashitem_T *hi; int l; int compminlen = 0; // COMPOUNDMIN value int compsylmax = 0; // COMPOUNDSYLMAX value int compoptions = 0; // COMP_ flags int compmax = 0; // COMPOUNDWORDMAX value - char_u *compflags = NULL; // COMPOUNDFLAG and COMPOUNDRULE - // concatenated - char_u *midword = NULL; // MIDWORD value - char_u *syllable = NULL; // SYLLABLE value - char_u *sofofrom = NULL; // SOFOFROM value - char_u *sofoto = NULL; // SOFOTO value + char_u *compflags = NULL; // COMPOUNDFLAG and COMPOUNDRULE + // concatenated + char_u *midword = NULL; // MIDWORD value + char_u *syllable = NULL; // SYLLABLE value + char_u *sofofrom = NULL; // SOFOFROM value + char_u *sofoto = NULL; // SOFOTO value // Open the file. fd = os_fopen((char *)fname, "r"); @@ -2019,8 +2073,9 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char_u *fname) ++lnum; // Skip comment lines. - if (*rline == '#') + if (*rline == '#') { continue; + } // Convert from "SET" to 'encoding' when needed. xfree(pc); @@ -2041,22 +2096,29 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char_u *fname) // item. itemcnt = 0; for (p = line;; ) { - while (*p != NUL && *p <= ' ') // skip white space and CR/NL + while (*p != NUL && *p <= ' ') { // skip white space and CR/NL ++p; - if (*p == NUL) + } + if (*p == NUL) { break; - if (itemcnt == MAXITEMCNT) // too many items + } + if (itemcnt == MAXITEMCNT) { // too many items break; + } items[itemcnt++] = p; // A few items have arbitrary text argument, don't split them. - if (itemcnt == 2 && spell_info_item(items[0])) - while (*p >= ' ' || *p == TAB) // skip until CR/NL + if (itemcnt == 2 && spell_info_item(items[0])) { + while (*p >= ' ' || *p == TAB) { // skip until CR/NL ++p; - else - while (*p > ' ') // skip until white space or CR/NL + } + } else { + while (*p > ' ') { // skip until white space or CR/NL ++p; - if (*p == NUL) + } + } + if (*p == NUL) { break; + } *p++ = NUL; } @@ -2067,21 +2129,23 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char_u *fname) aff->af_enc = enc_canonize(items[1]); if (!spin->si_ascii && convert_setup(&spin->si_conv, aff->af_enc, - p_enc) == FAIL) + p_enc) == FAIL) { smsg(_("Conversion in %s not supported: from %s to %s"), fname, aff->af_enc, p_enc); + } spin->si_conv.vc_fail = true; } else if (is_aff_rule(items, itemcnt, "FLAG", 2) && aff->af_flagtype == AFT_CHAR) { - if (STRCMP(items[1], "long") == 0) + if (STRCMP(items[1], "long") == 0) { aff->af_flagtype = AFT_LONG; - else if (STRCMP(items[1], "num") == 0) + } else if (STRCMP(items[1], "num") == 0) { aff->af_flagtype = AFT_NUM; - else if (STRCMP(items[1], "caplong") == 0) + } else if (STRCMP(items[1], "caplong") == 0) { aff->af_flagtype = AFT_CAPLONG; - else + } else { smsg(_("Invalid value for FLAG in %s line %d: %s"), fname, lnum, items[1]); + } if (aff->af_rare != 0 || aff->af_keepcase != 0 || aff->af_bad != 0 @@ -2092,10 +2156,11 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char_u *fname) || aff->af_nosuggest != 0 || compflags != NULL || aff->af_suff.ht_used > 0 - || aff->af_pref.ht_used > 0) + || aff->af_pref.ht_used > 0) { smsg(_("FLAG after using flags in %s line %d: %s"), fname, lnum, items[1]); - } else if (spell_info_item(items[0]) && itemcnt > 1) { + } + } else if (spell_info_item(items[0]) && itemcnt > 1) { p = getroom(spin, (spin->si_info == NULL ? 0 : STRLEN(spin->si_info)) + STRLEN(items[0]) @@ -2111,7 +2176,7 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char_u *fname) } else if (is_aff_rule(items, itemcnt, "MIDWORD", 2) && midword == NULL) { midword = getroom_save(spin, items[1]); - } else if (is_aff_rule(items, itemcnt, "TRY", 2)) { + } else if (is_aff_rule(items, itemcnt, "TRY", 2)) { // ignored, we look in the tree for what chars may appear } // TODO: remove "RAR" later @@ -2119,54 +2184,56 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char_u *fname) || is_aff_rule(items, itemcnt, "RARE", 2)) && aff->af_rare == 0) { aff->af_rare = affitem2flag(aff->af_flagtype, items[1], - fname, lnum); + fname, lnum); } // TODO: remove "KEP" later else if ((is_aff_rule(items, itemcnt, "KEP", 2) || is_aff_rule(items, itemcnt, "KEEPCASE", 2)) && aff->af_keepcase == 0) { aff->af_keepcase = affitem2flag(aff->af_flagtype, items[1], - fname, lnum); + fname, lnum); } else if ((is_aff_rule(items, itemcnt, "BAD", 2) || is_aff_rule(items, itemcnt, "FORBIDDENWORD", 2)) && aff->af_bad == 0) { aff->af_bad = affitem2flag(aff->af_flagtype, items[1], - fname, lnum); + fname, lnum); } else if (is_aff_rule(items, itemcnt, "NEEDAFFIX", 2) && aff->af_needaffix == 0) { aff->af_needaffix = affitem2flag(aff->af_flagtype, items[1], - fname, lnum); + fname, lnum); } else if (is_aff_rule(items, itemcnt, "CIRCUMFIX", 2) && aff->af_circumfix == 0) { aff->af_circumfix = affitem2flag(aff->af_flagtype, items[1], - fname, lnum); + fname, lnum); } else if (is_aff_rule(items, itemcnt, "NOSUGGEST", 2) && aff->af_nosuggest == 0) { aff->af_nosuggest = affitem2flag(aff->af_flagtype, items[1], - fname, lnum); + fname, lnum); } else if ((is_aff_rule(items, itemcnt, "NEEDCOMPOUND", 2) || is_aff_rule(items, itemcnt, "ONLYINCOMPOUND", 2)) && aff->af_needcomp == 0) { aff->af_needcomp = affitem2flag(aff->af_flagtype, items[1], - fname, lnum); + fname, lnum); } else if (is_aff_rule(items, itemcnt, "COMPOUNDROOT", 2) && aff->af_comproot == 0) { aff->af_comproot = affitem2flag(aff->af_flagtype, items[1], - fname, lnum); + fname, lnum); } else if (is_aff_rule(items, itemcnt, "COMPOUNDFORBIDFLAG", 2) && aff->af_compforbid == 0) { aff->af_compforbid = affitem2flag(aff->af_flagtype, items[1], - fname, lnum); - if (aff->af_pref.ht_used > 0) + fname, lnum); + if (aff->af_pref.ht_used > 0) { smsg(_("Defining COMPOUNDFORBIDFLAG after PFX item may give wrong results in %s line %d"), fname, lnum); + } } else if (is_aff_rule(items, itemcnt, "COMPOUNDPERMITFLAG", 2) && aff->af_comppermit == 0) { aff->af_comppermit = affitem2flag(aff->af_flagtype, items[1], - fname, lnum); - if (aff->af_pref.ht_used > 0) + fname, lnum); + if (aff->af_pref.ht_used > 0) { smsg(_("Defining COMPOUNDPERMITFLAG after PFX item may give wrong results in %s line %d"), fname, lnum); + } } else if (is_aff_rule(items, itemcnt, "COMPOUNDFLAG", 2) && compflags == NULL) { // Turn flag "c" into COMPOUNDRULE compatible string "c+", @@ -2175,20 +2242,22 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char_u *fname) STRCPY(p, items[1]); STRCAT(p, "+"); compflags = p; - } else if (is_aff_rule(items, itemcnt, "COMPOUNDRULES", 2)) { + } else if (is_aff_rule(items, itemcnt, "COMPOUNDRULES", 2)) { // We don't use the count, but do check that it's a number and // not COMPOUNDRULE mistyped. - if (atoi((char *)items[1]) == 0) + if (atoi((char *)items[1]) == 0) { smsg(_("Wrong COMPOUNDRULES value in %s line %d: %s"), fname, lnum, items[1]); - } else if (is_aff_rule(items, itemcnt, "COMPOUNDRULE", 2)) { + } + } else if (is_aff_rule(items, itemcnt, "COMPOUNDRULE", 2)) { // Don't use the first rule if it is a number. if (compflags != NULL || *skipdigits(items[1]) != NUL) { // Concatenate this string to previously defined ones, // using a slash to separate them. l = (int)STRLEN(items[1]) + 1; - if (compflags != NULL) + if (compflags != NULL) { l += (int)STRLEN(compflags) + 1; + } p = getroom(spin, l, false); if (compflags != NULL) { STRCPY(p, compflags); @@ -2200,43 +2269,49 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char_u *fname) } else if (is_aff_rule(items, itemcnt, "COMPOUNDWORDMAX", 2) && compmax == 0) { compmax = atoi((char *)items[1]); - if (compmax == 0) + if (compmax == 0) { smsg(_("Wrong COMPOUNDWORDMAX value in %s line %d: %s"), fname, lnum, items[1]); + } } else if (is_aff_rule(items, itemcnt, "COMPOUNDMIN", 2) && compminlen == 0) { compminlen = atoi((char *)items[1]); - if (compminlen == 0) + if (compminlen == 0) { smsg(_("Wrong COMPOUNDMIN value in %s line %d: %s"), fname, lnum, items[1]); + } } else if (is_aff_rule(items, itemcnt, "COMPOUNDSYLMAX", 2) && compsylmax == 0) { compsylmax = atoi((char *)items[1]); - if (compsylmax == 0) + if (compsylmax == 0) { smsg(_("Wrong COMPOUNDSYLMAX value in %s line %d: %s"), fname, lnum, items[1]); - } else if (is_aff_rule(items, itemcnt, "CHECKCOMPOUNDDUP", 1)) { + } + } else if (is_aff_rule(items, itemcnt, "CHECKCOMPOUNDDUP", 1)) { compoptions |= COMP_CHECKDUP; - } else if (is_aff_rule(items, itemcnt, "CHECKCOMPOUNDREP", 1)) { + } else if (is_aff_rule(items, itemcnt, "CHECKCOMPOUNDREP", 1)) { compoptions |= COMP_CHECKREP; - } else if (is_aff_rule(items, itemcnt, "CHECKCOMPOUNDCASE", 1)) { + } else if (is_aff_rule(items, itemcnt, "CHECKCOMPOUNDCASE", 1)) { compoptions |= COMP_CHECKCASE; - } else if (is_aff_rule(items, itemcnt, "CHECKCOMPOUNDTRIPLE", 1)) { + } else if (is_aff_rule(items, itemcnt, "CHECKCOMPOUNDTRIPLE", 1)) { compoptions |= COMP_CHECKTRIPLE; - } else if (is_aff_rule(items, itemcnt, "CHECKCOMPOUNDPATTERN", 2)) { - if (atoi((char *)items[1]) == 0) + } else if (is_aff_rule(items, itemcnt, "CHECKCOMPOUNDPATTERN", 2)) { + if (atoi((char *)items[1]) == 0) { smsg(_("Wrong CHECKCOMPOUNDPATTERN value in %s line %d: %s"), fname, lnum, items[1]); - } else if (is_aff_rule(items, itemcnt, "CHECKCOMPOUNDPATTERN", 3)) { - garray_T *gap = &spin->si_comppat; + } + } else if (is_aff_rule(items, itemcnt, "CHECKCOMPOUNDPATTERN", 3)) { + garray_T *gap = &spin->si_comppat; int i; // Only add the couple if it isn't already there. - for (i = 0; i < gap->ga_len - 1; i += 2) + for (i = 0; i < gap->ga_len - 1; i += 2) { if (STRCMP(((char_u **)(gap->ga_data))[i], items[1]) == 0 && STRCMP(((char_u **)(gap->ga_data))[i + 1], - items[2]) == 0) + items[2]) == 0) { break; + } + } if (i >= gap->ga_len) { ga_grow(gap, 2); ((char_u **)(gap->ga_data))[gap->ga_len++] @@ -2247,15 +2322,15 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char_u *fname) } else if (is_aff_rule(items, itemcnt, "SYLLABLE", 2) && syllable == NULL) { syllable = getroom_save(spin, items[1]); - } else if (is_aff_rule(items, itemcnt, "NOBREAK", 1)) { + } else if (is_aff_rule(items, itemcnt, "NOBREAK", 1)) { spin->si_nobreak = true; - } else if (is_aff_rule(items, itemcnt, "NOSPLITSUGS", 1)) { + } else if (is_aff_rule(items, itemcnt, "NOSPLITSUGS", 1)) { spin->si_nosplitsugs = true; } else if (is_aff_rule(items, itemcnt, "NOCOMPOUNDSUGS", 1)) { spin->si_nocompoundsugs = true; - } else if (is_aff_rule(items, itemcnt, "NOSUGFILE", 1)) { + } else if (is_aff_rule(items, itemcnt, "NOSUGFILE", 1)) { spin->si_nosugfile = true; - } else if (is_aff_rule(items, itemcnt, "PFXPOSTPONE", 1)) { + } else if (is_aff_rule(items, itemcnt, "PFXPOSTPONE", 1)) { aff->af_pfxpostpone = true; } else if (is_aff_rule(items, itemcnt, "IGNOREEXTRA", 1)) { aff->af_ignoreextra = true; @@ -2266,10 +2341,11 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char_u *fname) int lasti = 4; char_u key[AH_KEY_LEN]; - if (*items[0] == 'P') + if (*items[0] == 'P') { tp = &aff->af_pref; - else + } else { tp = &aff->af_suff; + } // Myspell allows the same affix name to be used multiple // times. The affix files that do this have an undocumented @@ -2279,12 +2355,14 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char_u *fname) hi = hash_find(tp, key); if (!HASHITEM_EMPTY(hi)) { cur_aff = HI2AH(hi); - if (cur_aff->ah_combine != (*items[2] == 'Y')) + if (cur_aff->ah_combine != (*items[2] == 'Y')) { smsg(_("Different combining flag in continued affix block in %s line %d: %s"), fname, lnum, items[1]); - if (!cur_aff->ah_follows) + } + if (!cur_aff->ah_follows) { smsg(_("Duplicate affix in %s line %d: %s"), fname, lnum, items[1]); + } } else { // New affix letter. cur_aff = getroom(spin, sizeof(*cur_aff), true); @@ -2317,20 +2395,23 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char_u *fname) if (itemcnt > lasti && STRCMP(items[lasti], "S") == 0) { ++lasti; cur_aff->ah_follows = true; - } else + } else { cur_aff->ah_follows = false; + } // Myspell allows extra text after the item, but that might // mean mistakes go unnoticed. Require a comment-starter, // unless IGNOREEXTRA is used. Hunspell uses a "-" item. if (itemcnt > lasti && !aff->af_ignoreextra - && *items[lasti] != '#') + && *items[lasti] != '#') { smsg(_(e_afftrailing), fname, lnum, items[lasti]); + } - if (STRCMP(items[2], "Y") != 0 && STRCMP(items[2], "N") != 0) + if (STRCMP(items[2], "Y") != 0 && STRCMP(items[2], "N") != 0) { smsg(_("Expected Y or N in %s line %d: %s"), - fname, lnum, items[2]); + fname, lnum, items[2]); + } if (*items[0] == 'P' && aff->af_pfxpostpone) { if (cur_aff->ah_newID == 0) { @@ -2343,9 +2424,10 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char_u *fname) // postponed. We know that only after handling all // the items. did_postpone_prefix = false; - } else + } else { // Did use the ID in a previous block. did_postpone_prefix = true; + } } aff_todo = atoi((char *)items[3]); @@ -2354,7 +2436,7 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char_u *fname) && aff_todo > 0 && STRCMP(cur_aff->ah_key, items[1]) == 0 && itemcnt >= 5) { - affentry_T *aff_entry; + affentry_T *aff_entry; bool upper = false; int lasti = 5; @@ -2363,15 +2445,17 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char_u *fname) // Hunspell uses a "-" item. if (itemcnt > lasti && *items[lasti] != '#' && (STRCMP(items[lasti], "-") != 0 - || itemcnt != lasti + 1)) + || itemcnt != lasti + 1)) { smsg(_(e_afftrailing), fname, lnum, items[lasti]); + } // New item for an affix letter. aff_todo--; aff_entry = getroom(spin, sizeof(*aff_entry), true); - if (STRCMP(items[2], "0") != 0) + if (STRCMP(items[2], "0") != 0) { aff_entry->ae_chop = getroom_save(spin, items[2]); + } if (STRCMP(items[3], "0") != 0) { aff_entry->ae_add = getroom_save(spin, items[3]); @@ -2394,15 +2478,17 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char_u *fname) char_u buf[MAXLINELEN]; aff_entry->ae_cond = getroom_save(spin, items[4]); - if (*items[0] == 'P') + if (*items[0] == 'P') { sprintf((char *)buf, "^%s", items[4]); - else + } else { sprintf((char *)buf, "%s$", items[4]); + } aff_entry->ae_prog = vim_regcomp(buf, - RE_MAGIC + RE_STRING + RE_STRICT); - if (aff_entry->ae_prog == NULL) + RE_MAGIC + RE_STRING + RE_STRICT); + if (aff_entry->ae_prog == NULL) { smsg(_("Broken condition in %s line %d: %s"), fname, lnum, items[4]); + } } // For postponed prefixes we need an entry in si_prefcond @@ -2418,9 +2504,8 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char_u *fname) // be empty or start with the same letter. if (aff_entry->ae_chop != NULL && aff_entry->ae_add != NULL - && aff_entry->ae_chop[(*mb_ptr2len)( - aff_entry->ae_chop)] == NUL - ) { + && aff_entry->ae_chop[(*mb_ptr2len)(aff_entry->ae_chop)] == + NUL) { int c, c_up; c = PTR2CHAR(aff_entry->ae_chop); @@ -2445,10 +2530,9 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char_u *fname) aff_entry->ae_cond = getroom_save(spin, buf); if (aff_entry->ae_cond != NULL) { sprintf((char *)buf, "^%s", - aff_entry->ae_cond); + aff_entry->ae_cond); vim_regfree(aff_entry->ae_prog); - aff_entry->ae_prog = vim_regcomp( - buf, RE_MAGIC + RE_STRING); + aff_entry->ae_prog = vim_regcomp(buf, RE_MAGIC + RE_STRING); } } } @@ -2457,43 +2541,49 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char_u *fname) if (aff_entry->ae_chop == NULL) { int idx; - char_u **pp; + char_u **pp; int n; // Find a previously used condition. for (idx = spin->si_prefcond.ga_len - 1; idx >= 0; --idx) { p = ((char_u **)spin->si_prefcond.ga_data)[idx]; - if (str_equal(p, aff_entry->ae_cond)) + if (str_equal(p, aff_entry->ae_cond)) { break; + } } if (idx < 0) { // Not found, add a new condition. idx = spin->si_prefcond.ga_len; pp = GA_APPEND_VIA_PTR(char_u *, &spin->si_prefcond); *pp = (aff_entry->ae_cond == NULL) ? - NULL : getroom_save(spin, aff_entry->ae_cond); + NULL : getroom_save(spin, aff_entry->ae_cond); } // Add the prefix to the prefix tree. - if (aff_entry->ae_add == NULL) + if (aff_entry->ae_add == NULL) { p = (char_u *)""; - else + } else { p = aff_entry->ae_add; + } // PFX_FLAGS is a negative number, so that // tree_add_word() knows this is the prefix tree. n = PFX_FLAGS; - if (!cur_aff->ah_combine) + if (!cur_aff->ah_combine) { n |= WFP_NC; - if (upper) + } + if (upper) { n |= WFP_UP; - if (aff_entry->ae_comppermit) + } + if (aff_entry->ae_comppermit) { n |= WFP_COMPPERMIT; - if (aff_entry->ae_compforbid) + } + if (aff_entry->ae_compforbid) { n |= WFP_COMPFORBID; + } tree_add_word(spin, p, spin->si_prefroot, n, - idx, cur_aff->ah_newID); + idx, cur_aff->ah_newID); did_postpone_prefix = true; } @@ -2504,26 +2594,28 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char_u *fname) } } } - } else if (is_aff_rule(items, itemcnt, "FOL", 2) && fol == NULL) { + } else if (is_aff_rule(items, itemcnt, "FOL", 2) && fol == NULL) { fol = vim_strsave(items[1]); - } else if (is_aff_rule(items, itemcnt, "LOW", 2) && low == NULL) { + } else if (is_aff_rule(items, itemcnt, "LOW", 2) && low == NULL) { low = vim_strsave(items[1]); - } else if (is_aff_rule(items, itemcnt, "UPP", 2) && upp == NULL) { + } else if (is_aff_rule(items, itemcnt, "UPP", 2) && upp == NULL) { upp = vim_strsave(items[1]); } else if (is_aff_rule(items, itemcnt, "REP", 2) || is_aff_rule(items, itemcnt, "REPSAL", 2)) { /* Ignore REP/REPSAL count */; - if (!isdigit(*items[1])) + if (!isdigit(*items[1])) { smsg(_("Expected REP(SAL) count in %s line %d"), fname, lnum); + } } else if ((STRCMP(items[0], "REP") == 0 || STRCMP(items[0], "REPSAL") == 0) && itemcnt >= 3) { // REP/REPSAL item // Myspell ignores extra arguments, we require it starts with // # to detect mistakes. - if (itemcnt > 3 && items[3][0] != '#') + if (itemcnt > 3 && items[3][0] != '#') { smsg(_(e_afftrailing), fname, lnum, items[3]); + } if (items[0][3] == 'S' ? do_repsal : do_rep) { // Replace underscore with space (can't include a space // directly). @@ -2541,15 +2633,16 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char_u *fname) ? &spin->si_repsal : &spin->si_rep, items[1], items[2]); } - } else if (is_aff_rule(items, itemcnt, "MAP", 2)) { + } else if (is_aff_rule(items, itemcnt, "MAP", 2)) { // MAP item or count if (!found_map) { // First line contains the count. found_map = true; - if (!isdigit(*items[1])) + if (!isdigit(*items[1])) { smsg(_("Expected MAP count in %s line %d"), fname, lnum); - } else if (do_mapline) { + } + } else if (do_mapline) { int c; // Check that every character appears only once. @@ -2575,17 +2668,18 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char_u *fname) if (do_sal) { // SAL item (sounds-a-like) // Either one of the known keys or a from-to pair. - if (STRCMP(items[1], "followup") == 0) + if (STRCMP(items[1], "followup") == 0) { spin->si_followup = sal_to_bool(items[2]); - else if (STRCMP(items[1], "collapse_result") == 0) + } else if (STRCMP(items[1], "collapse_result") == 0) { spin->si_collapse = sal_to_bool(items[2]); - else if (STRCMP(items[1], "remove_accents") == 0) + } else if (STRCMP(items[1], "remove_accents") == 0) { spin->si_rem_accents = sal_to_bool(items[2]); - else + } else { // when "to" is "_" it means empty add_fromto(spin, &spin->si_sal, items[1], - STRCMP(items[2], "_") == 0 ? (char_u *)"" - : items[2]); + STRCMP(items[2], "_") == 0 ? (char_u *)"" + : items[2]); + } } } else if (is_aff_rule(items, itemcnt, "SOFOFROM", 2) && sofofrom == NULL) { @@ -2593,19 +2687,20 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char_u *fname) } else if (is_aff_rule(items, itemcnt, "SOFOTO", 2) && sofoto == NULL) { sofoto = getroom_save(spin, items[1]); - } else if (STRCMP(items[0], "COMMON") == 0) { + } else if (STRCMP(items[0], "COMMON") == 0) { int i; for (i = 1; i < itemcnt; ++i) { if (HASHITEM_EMPTY(hash_find(&spin->si_commonwords, - items[i]))) { + items[i]))) { p = vim_strsave(items[i]); hash_add(&spin->si_commonwords, p); } } - } else + } else { smsg(_("Unrecognized or duplicate item in %s line %d: %s"), fname, lnum, items[0]); + } } } @@ -2646,17 +2741,19 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char_u *fname) spin->si_compoptions |= compoptions; } - if (compflags != NULL) + if (compflags != NULL) { process_compflags(spin, aff, compflags); + } // Check that we didn't use too many renumbered flags. if (spin->si_newcompID < spin->si_newprefID) { - if (spin->si_newcompID == 127 || spin->si_newcompID == 255) + if (spin->si_newcompID == 127 || spin->si_newcompID == 255) { MSG(_("Too many postponed prefixes")); - else if (spin->si_newprefID == 0 || spin->si_newprefID == 127) + } else if (spin->si_newprefID == 0 || spin->si_newprefID == 127) { MSG(_("Too many compound flags")); - else + } else { MSG(_("Too many postponed prefixes and/or compound flags")); + } } if (syllable != NULL) { @@ -2665,12 +2762,12 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char_u *fname) } if (sofofrom != NULL || sofoto != NULL) { - if (sofofrom == NULL || sofoto == NULL) + if (sofofrom == NULL || sofoto == NULL) { smsg(_("Missing SOFO%s line in %s"), sofofrom == NULL ? "FROM" : "TO", fname); - else if (!GA_EMPTY(&spin->si_sal)) + } else if (!GA_EMPTY(&spin->si_sal)) { smsg(_("Both SAL and SOFO lines in %s"), fname); - else { + } else { aff_check_string(spin->si_sofofr, sofofrom, "SOFOFROM"); aff_check_string(spin->si_sofoto, sofoto, "SOFOTO"); spin->si_sofofr = sofofrom; @@ -2701,8 +2798,8 @@ static bool is_aff_rule(char_u **items, int itemcnt, char *rulename, int mincoun // ae_flags to ae_comppermit and ae_compforbid. static void aff_process_flags(afffile_T *affile, affentry_T *entry) { - char_u *p; - char_u *prevp; + char_u *p; + char_u *prevp; unsigned flag; if (entry->ae_flags != NULL @@ -2713,16 +2810,19 @@ static void aff_process_flags(afffile_T *affile, affentry_T *entry) if (flag == affile->af_comppermit || flag == affile->af_compforbid) { STRMOVE(prevp, p); p = prevp; - if (flag == affile->af_comppermit) + if (flag == affile->af_comppermit) { entry->ae_comppermit = true; - else + } else { entry->ae_compforbid = true; + } } - if (affile->af_flagtype == AFT_NUM && *p == ',') + if (affile->af_flagtype == AFT_NUM && *p == ',') { ++p; + } } - if (*entry->ae_flags == NUL) + if (*entry->ae_flags == NUL) { entry->ae_flags = NULL; // nothing left + } } } @@ -2742,16 +2842,17 @@ static bool spell_info_item(char_u *s) static unsigned affitem2flag(int flagtype, char_u *item, char_u *fname, int lnum) { unsigned res; - char_u *p = item; + char_u *p = item; res = get_affitem(flagtype, &p); if (res == 0) { - if (flagtype == AFT_NUM) + if (flagtype == AFT_NUM) { smsg(_("Flag is not a number in %s line %d: %s"), fname, lnum, item); - else + } else { smsg(_("Illegal flag in %s line %d: %s"), fname, lnum, item); + } } if (*p != NUL) { smsg(_(e_affname), fname, lnum, item); @@ -2781,8 +2882,9 @@ static unsigned get_affitem(int flagtype, char_u **pp) res = mb_ptr2char_adv((const char_u **)pp); if (flagtype == AFT_LONG || (flagtype == AFT_CAPLONG && res >= 'A' && res <= 'Z')) { - if (**pp == NUL) + if (**pp == NUL) { return 0; + } res = mb_ptr2char_adv((const char_u **)pp) + (res << 16); } } @@ -2795,22 +2897,23 @@ static unsigned get_affitem(int flagtype, char_u **pp) // they fit in one byte. static void process_compflags(spellinfo_T *spin, afffile_T *aff, char_u *compflags) { - char_u *p; - char_u *prevp; + char_u *p; + char_u *prevp; unsigned flag; - compitem_T *ci; + compitem_T *ci; int id; int len; - char_u *tp; + char_u *tp; char_u key[AH_KEY_LEN]; - hashitem_T *hi; + hashitem_T *hi; // Make room for the old and the new compflags, concatenated with a / in // between. Processing it makes it shorter, but we don't know by how // much, thus allocate the maximum. len = (int)STRLEN(compflags) + 1; - if (spin->si_compflags != NULL) + if (spin->si_compflags != NULL) { len += (int)STRLEN(spin->si_compflags) + 1; + } p = getroom(spin, len, false); if (spin->si_compflags != NULL) { STRCPY(p, spin->si_compflags); @@ -2820,10 +2923,10 @@ static void process_compflags(spellinfo_T *spin, afffile_T *aff, char_u *compfla tp = p + STRLEN(p); for (p = compflags; *p != NUL; ) { - if (vim_strchr((char_u *)"/?*+[]", *p) != NULL) + if (vim_strchr((char_u *)"/?*+[]", *p) != NULL) { // Copy non-flag characters directly. *tp++ = *p++; - else { + } else { // First get the flag number, also checks validity. prevp = p; flag = get_affitem(aff->af_flagtype, &p); @@ -2849,8 +2952,9 @@ static void process_compflags(spellinfo_T *spin, afffile_T *aff, char_u *compfla } *tp++ = id; } - if (aff->af_flagtype == AFT_NUM && *p == ',') + if (aff->af_flagtype == AFT_NUM && *p == ',') { ++p; + } } } @@ -2872,7 +2976,7 @@ static void check_renumber(spellinfo_T *spin) // Returns true if flag "flag" appears in affix list "afflist". static bool flag_in_afflist(int flagtype, char_u *afflist, unsigned flag) { - char_u *p; + char_u *p; unsigned n; switch (flagtype) { @@ -2916,25 +3020,28 @@ static bool flag_in_afflist(int flagtype, char_u *afflist, unsigned flag) // Give a warning when "spinval" and "affval" numbers are set and not the same. static void aff_check_number(int spinval, int affval, char *name) { - if (spinval != 0 && spinval != affval) + if (spinval != 0 && spinval != affval) { smsg(_("%s value differs from what is used in another .aff file"), name); + } } // Give a warning when "spinval" and "affval" strings are set and not the same. static void aff_check_string(char_u *spinval, char_u *affval, char *name) { - if (spinval != NULL && STRCMP(spinval, affval) != 0) + if (spinval != NULL && STRCMP(spinval, affval) != 0) { smsg(_("%s value differs from what is used in another .aff file"), name); + } } // Returns true if strings "s1" and "s2" are equal. Also consider both being // NULL as equal. static bool str_equal(char_u *s1, char_u *s2) { - if (s1 == NULL || s2 == NULL) + if (s1 == NULL || s2 == NULL) { return s1 == s2; + } return STRCMP(s1, s2) == 0; } @@ -2960,11 +3067,11 @@ static bool sal_to_bool(char_u *s) // Free the structure filled by spell_read_aff(). static void spell_free_aff(afffile_T *aff) { - hashtab_T *ht; - hashitem_T *hi; + hashtab_T *ht; + hashitem_T *hi; int todo; affheader_T *ah; - affentry_T *ae; + affentry_T *ae; xfree(aff->af_enc); @@ -2975,12 +3082,14 @@ static void spell_free_aff(afffile_T *aff) if (!HASHITEM_EMPTY(hi)) { --todo; ah = HI2AH(hi); - for (ae = ah->ah_first; ae != NULL; ae = ae->ae_next) + for (ae = ah->ah_first; ae != NULL; ae = ae->ae_next) { vim_regfree(ae->ae_prog); + } } } - if (ht == &aff->af_suff) + if (ht == &aff->af_suff) { break; + } } hash_clear(&aff->af_pref); @@ -2994,18 +3103,18 @@ static int spell_read_dic(spellinfo_T *spin, char_u *fname, afffile_T *affile) { hashtab_T ht; char_u line[MAXLINELEN]; - char_u *p; - char_u *afflist; + char_u *p; + char_u *afflist; char_u store_afflist[MAXWLEN]; int pfxlen; bool need_affix; - char_u *dw; - char_u *pc; - char_u *w; + char_u *dw; + char_u *pc; + char_u *w; int l; hash_T hash; - hashitem_T *hi; - FILE *fd; + hashitem_T *hi; + FILE *fd; int lnum = 1; int non_ascii = 0; int retval = OK; @@ -3042,16 +3151,18 @@ static int spell_read_dic(spellinfo_T *spin, char_u *fname, afffile_T *affile) while (!vim_fgets(line, MAXLINELEN, fd) && !got_int) { line_breakcheck(); ++lnum; - if (line[0] == '#' || line[0] == '/') + if (line[0] == '#' || line[0] == '/') { continue; // comment line - + } // Remove CR, LF and white space from the end. White space halfway through // the word is kept to allow multi-word terms like "et al.". l = (int)STRLEN(line); - while (l > 0 && line[l - 1] <= ' ') + while (l > 0 && line[l - 1] <= ' ') { --l; - if (l == 0) + } + if (l == 0) { continue; // empty line + } line[l] = NUL; // Convert from "SET" to 'encoding' when needed. @@ -3117,15 +3228,17 @@ static int spell_read_dic(spellinfo_T *spin, char_u *fname, afffile_T *affile) hash = hash_hash(dw); hi = hash_lookup(&ht, (const char *)dw, STRLEN(dw), hash); if (!HASHITEM_EMPTY(hi)) { - if (p_verbose > 0) + if (p_verbose > 0) { smsg(_("Duplicate word in %s line %d: %s"), fname, lnum, dw); - else if (duplicate == 0) + } else if (duplicate == 0) { smsg(_("First duplicate word in %s line %d: %s"), fname, lnum, dw); + } ++duplicate; - } else + } else { hash_add_item(&ht, hi, dw, hash); + } flags = 0; store_afflist[0] = NUL; @@ -3135,48 +3248,57 @@ static int spell_read_dic(spellinfo_T *spin, char_u *fname, afffile_T *affile) // Extract flags from the affix list. flags |= get_affix_flags(affile, afflist); - if (affile->af_needaffix != 0 && flag_in_afflist( - affile->af_flagtype, afflist, affile->af_needaffix)) + if (affile->af_needaffix != 0 && + flag_in_afflist(affile->af_flagtype, afflist, + affile->af_needaffix)) { need_affix = true; + } - if (affile->af_pfxpostpone) + if (affile->af_pfxpostpone) { // Need to store the list of prefix IDs with the word. pfxlen = get_pfxlist(affile, afflist, store_afflist); + } - if (spin->si_compflags != NULL) + if (spin->si_compflags != NULL) { // Need to store the list of compound flags with the word. // Concatenate them to the list of prefix IDs. get_compflags(affile, afflist, store_afflist + pfxlen); + } } // Add the word to the word tree(s). if (store_word(spin, dw, flags, spin->si_region, - store_afflist, need_affix) == FAIL) + store_afflist, need_affix) == FAIL) { retval = FAIL; + } if (afflist != NULL) { // Find all matching suffixes and add the resulting words. // Additionally do matching prefixes that combine. if (store_aff_word(spin, dw, afflist, affile, - &affile->af_suff, &affile->af_pref, - CONDIT_SUF, flags, store_afflist, pfxlen) == FAIL) + &affile->af_suff, &affile->af_pref, + CONDIT_SUF, flags, store_afflist, pfxlen) == FAIL) { retval = FAIL; + } // Find all matching prefixes and add the resulting words. if (store_aff_word(spin, dw, afflist, affile, - &affile->af_pref, NULL, - CONDIT_SUF, flags, store_afflist, pfxlen) == FAIL) + &affile->af_pref, NULL, + CONDIT_SUF, flags, store_afflist, pfxlen) == FAIL) { retval = FAIL; + } } xfree(pc); } - if (duplicate > 0) + if (duplicate > 0) { smsg(_("%d duplicate word(s) in %s"), duplicate, fname); - if (spin->si_ascii && non_ascii > 0) + } + if (spin->si_ascii && non_ascii > 0) { smsg(_("Ignored %d word(s) with non-ASCII characters in %s"), non_ascii, fname); + } hash_clear(&ht); fclose(fd); @@ -3189,24 +3311,34 @@ static int get_affix_flags(afffile_T *affile, char_u *afflist) { int flags = 0; - if (affile->af_keepcase != 0 && flag_in_afflist( - affile->af_flagtype, afflist, affile->af_keepcase)) + if (affile->af_keepcase != 0 && + flag_in_afflist(affile->af_flagtype, afflist, + affile->af_keepcase)) { flags |= WF_KEEPCAP | WF_FIXCAP; - if (affile->af_rare != 0 && flag_in_afflist( - affile->af_flagtype, afflist, affile->af_rare)) + } + if (affile->af_rare != 0 && + flag_in_afflist(affile->af_flagtype, afflist, affile->af_rare)) { flags |= WF_RARE; - if (affile->af_bad != 0 && flag_in_afflist( - affile->af_flagtype, afflist, affile->af_bad)) + } + if (affile->af_bad != 0 && + flag_in_afflist(affile->af_flagtype, afflist, affile->af_bad)) { flags |= WF_BANNED; - if (affile->af_needcomp != 0 && flag_in_afflist( - affile->af_flagtype, afflist, affile->af_needcomp)) + } + if (affile->af_needcomp != 0 && + flag_in_afflist(affile->af_flagtype, afflist, + affile->af_needcomp)) { flags |= WF_NEEDCOMP; - if (affile->af_comproot != 0 && flag_in_afflist( - affile->af_flagtype, afflist, affile->af_comproot)) + } + if (affile->af_comproot != 0 && + flag_in_afflist(affile->af_flagtype, afflist, + affile->af_comproot)) { flags |= WF_COMPROOT; - if (affile->af_nosuggest != 0 && flag_in_afflist( - affile->af_flagtype, afflist, affile->af_nosuggest)) + } + if (affile->af_nosuggest != 0 && + flag_in_afflist(affile->af_flagtype, afflist, + affile->af_nosuggest)) { flags |= WF_NOSUGGEST; + } return flags; } @@ -3216,12 +3348,12 @@ static int get_affix_flags(afffile_T *affile, char_u *afflist) // and return the number of affixes. static int get_pfxlist(afffile_T *affile, char_u *afflist, char_u *store_afflist) { - char_u *p; - char_u *prevp; + char_u *p; + char_u *prevp; int cnt = 0; int id; char_u key[AH_KEY_LEN]; - hashitem_T *hi; + hashitem_T *hi; for (p = afflist; *p != NUL; ) { prevp = p; @@ -3232,12 +3364,14 @@ static int get_pfxlist(afffile_T *affile, char_u *afflist, char_u *store_afflist hi = hash_find(&affile->af_pref, key); if (!HASHITEM_EMPTY(hi)) { id = HI2AH(hi)->ah_newID; - if (id != 0) + if (id != 0) { store_afflist[cnt++] = id; + } } } - if (affile->af_flagtype == AFT_NUM && *p == ',') + if (affile->af_flagtype == AFT_NUM && *p == ',') { ++p; + } } store_afflist[cnt] = NUL; @@ -3249,11 +3383,11 @@ static int get_pfxlist(afffile_T *affile, char_u *afflist, char_u *store_afflist // Puts the flags in "store_afflist[]". static void get_compflags(afffile_T *affile, char_u *afflist, char_u *store_afflist) { - char_u *p; - char_u *prevp; + char_u *p; + char_u *prevp; int cnt = 0; char_u key[AH_KEY_LEN]; - hashitem_T *hi; + hashitem_T *hi; for (p = afflist; *p != NUL; ) { prevp = p; @@ -3261,48 +3395,47 @@ static void get_compflags(afffile_T *affile, char_u *afflist, char_u *store_affl // A flag is a compound flag if it appears in "af_comp". STRLCPY(key, prevp, p - prevp + 1); hi = hash_find(&affile->af_comp, key); - if (!HASHITEM_EMPTY(hi)) + if (!HASHITEM_EMPTY(hi)) { store_afflist[cnt++] = HI2CI(hi)->ci_newID; + } } - if (affile->af_flagtype == AFT_NUM && *p == ',') + if (affile->af_flagtype == AFT_NUM && *p == ',') { ++p; + } } store_afflist[cnt] = NUL; } -// Apply affixes to a word and store the resulting words. -// "ht" is the hashtable with affentry_T that need to be applied, either -// prefixes or suffixes. -// "xht", when not NULL, is the prefix hashtable, to be used additionally on -// the resulting words for combining affixes. -// -// Returns FAIL when out of memory. -static int -store_aff_word ( - spellinfo_T *spin, // spell info - char_u *word, // basic word start - char_u *afflist, // list of names of supported affixes - afffile_T *affile, - hashtab_T *ht, - hashtab_T *xht, - int condit, // CONDIT_SUF et al. - int flags, // flags for the word - char_u *pfxlist, // list of prefix IDs - int pfxlen // nr of flags in "pfxlist" for prefixes, rest - // is compound flags -) +/// Apply affixes to a word and store the resulting words. +/// "ht" is the hashtable with affentry_T that need to be applied, either +/// prefixes or suffixes. +/// "xht", when not NULL, is the prefix hashtable, to be used additionally on +/// the resulting words for combining affixes. +/// +/// @param spin spell info +/// @param word basic word start +/// @param afflist list of names of supported affixes +/// @param condit CONDIT_SUF et al. +/// @param flags flags for the word +/// @param pfxlist list of prefix IDs +/// @param pfxlen nr of flags in "pfxlist" for prefixes, rest is compound flags +/// +/// @return FAIL when out of memory. +static int store_aff_word(spellinfo_T *spin, char_u *word, char_u *afflist, afffile_T *affile, + hashtab_T *ht, hashtab_T *xht, int condit, int flags, char_u *pfxlist, + int pfxlen) { int todo; - hashitem_T *hi; + hashitem_T *hi; affheader_T *ah; - affentry_T *ae; + affentry_T *ae; char_u newword[MAXWLEN]; int retval = OK; int i, j; - char_u *p; + char_u *p; int use_flags; - char_u *use_pfxlist; + char_u *use_pfxlist; int use_pfxlen; bool need_affix; char_u store_afflist[MAXWLEN]; @@ -3320,7 +3453,7 @@ store_aff_word ( // supports this affix. if (((condit & CONDIT_COMB) == 0 || ah->ah_combine) && flag_in_afflist(affile->af_flagtype, afflist, - ah->ah_flag)) { + ah->ah_flag)) { // Loop over all affix entries with this name. for (ae = ah->ah_first; ae != NULL; ae = ae->ae_next) { // Check the condition. It's not logical to match case @@ -3344,7 +3477,7 @@ store_aff_word ( == ((condit & CONDIT_AFF) == 0 || ae->ae_flags == NULL || !flag_in_afflist(affile->af_flagtype, - ae->ae_flags, affile->af_circumfix)))) { + ae->ae_flags, affile->af_circumfix)))) { // Match. Remove the chop and add the affix. if (xht == NULL) { // prefix: chop/add at the start of the word @@ -3374,8 +3507,9 @@ store_aff_word ( } *p = NUL; } - if (ae->ae_add != NULL) + if (ae->ae_add != NULL) { STRCAT(newword, ae->ae_add); + } } use_flags = flags; @@ -3387,57 +3521,64 @@ store_aff_word ( // Extract flags from the affix list. use_flags |= get_affix_flags(affile, ae->ae_flags); - if (affile->af_needaffix != 0 && flag_in_afflist( - affile->af_flagtype, ae->ae_flags, - affile->af_needaffix)) + if (affile->af_needaffix != 0 && flag_in_afflist(affile->af_flagtype, ae->ae_flags, + affile->af_needaffix)) { need_affix = true; + } // When there is a CIRCUMFIX flag the other affix // must also have it and we don't add the word // with one affix. - if (affile->af_circumfix != 0 && flag_in_afflist( - affile->af_flagtype, ae->ae_flags, - affile->af_circumfix)) { + if (affile->af_circumfix != 0 && flag_in_afflist(affile->af_flagtype, ae->ae_flags, + affile->af_circumfix)) { use_condit |= CONDIT_CFIX; - if ((condit & CONDIT_CFIX) == 0) + if ((condit & CONDIT_CFIX) == 0) { need_affix = true; + } } if (affile->af_pfxpostpone || spin->si_compflags != NULL) { - if (affile->af_pfxpostpone) + if (affile->af_pfxpostpone) { // Get prefix IDS from the affix list. use_pfxlen = get_pfxlist(affile, - ae->ae_flags, store_afflist); - else + ae->ae_flags, store_afflist); + } else { use_pfxlen = 0; + } use_pfxlist = store_afflist; // Combine the prefix IDs. Avoid adding the // same ID twice. for (i = 0; i < pfxlen; ++i) { - for (j = 0; j < use_pfxlen; ++j) - if (pfxlist[i] == use_pfxlist[j]) + for (j = 0; j < use_pfxlen; ++j) { + if (pfxlist[i] == use_pfxlist[j]) { break; - if (j == use_pfxlen) + } + } + if (j == use_pfxlen) { use_pfxlist[use_pfxlen++] = pfxlist[i]; + } } - if (spin->si_compflags != NULL) + if (spin->si_compflags != NULL) { // Get compound IDS from the affix list. get_compflags(affile, ae->ae_flags, - use_pfxlist + use_pfxlen); - else + use_pfxlist + use_pfxlen); + } else { use_pfxlist[use_pfxlen] = NUL; + } // Combine the list of compound flags. // Concatenate them to the prefix IDs list. // Avoid adding the same ID twice. for (i = pfxlen; pfxlist[i] != NUL; ++i) { for (j = use_pfxlen; - use_pfxlist[j] != NUL; ++j) - if (pfxlist[i] == use_pfxlist[j]) + use_pfxlist[j] != NUL; ++j) { + if (pfxlist[i] == use_pfxlist[j]) { break; + } + } if (use_pfxlist[j] == NUL) { use_pfxlist[j++] = pfxlist[i]; use_pfxlist[j] = NUL; @@ -3462,52 +3603,58 @@ store_aff_word ( // ... don't use a prefix list if combining // affixes is not allowed. But do use the // compound flags after them. - if (!ah->ah_combine && use_pfxlist != NULL) + if (!ah->ah_combine && use_pfxlist != NULL) { use_pfxlist += use_pfxlen; + } } // When compounding is supported and there is no // "COMPOUNDPERMITFLAG" then forbid compounding on the // side where the affix is applied. if (spin->si_compflags != NULL && !ae->ae_comppermit) { - if (xht != NULL) + if (xht != NULL) { use_flags |= WF_NOCOMPAFT; - else + } else { use_flags |= WF_NOCOMPBEF; + } } // Store the modified word. if (store_word(spin, newword, use_flags, - spin->si_region, use_pfxlist, - need_affix) == FAIL) + spin->si_region, use_pfxlist, + need_affix) == FAIL) { retval = FAIL; + } // When added a prefix or a first suffix and the affix // has flags may add a(nother) suffix. RECURSIVE! - if ((condit & CONDIT_SUF) && ae->ae_flags != NULL) + if ((condit & CONDIT_SUF) && ae->ae_flags != NULL) { if (store_aff_word(spin, newword, ae->ae_flags, - affile, &affile->af_suff, xht, - use_condit & (xht == NULL + affile, &affile->af_suff, xht, + use_condit & (xht == NULL ? ~0 : ~CONDIT_SUF), - use_flags, use_pfxlist, pfxlen) == FAIL) + use_flags, use_pfxlist, pfxlen) == FAIL) { retval = FAIL; + } + } // When added a suffix and combining is allowed also // try adding a prefix additionally. Both for the // word flags and for the affix flags. RECURSIVE! if (xht != NULL && ah->ah_combine) { if (store_aff_word(spin, newword, - afflist, affile, - xht, NULL, use_condit, - use_flags, use_pfxlist, - pfxlen) == FAIL + afflist, affile, + xht, NULL, use_condit, + use_flags, use_pfxlist, + pfxlen) == FAIL || (ae->ae_flags != NULL && store_aff_word(spin, newword, - ae->ae_flags, affile, - xht, NULL, use_condit, - use_flags, use_pfxlist, - pfxlen) == FAIL)) + ae->ae_flags, affile, + xht, NULL, use_condit, + use_flags, use_pfxlist, + pfxlen) == FAIL)) { retval = FAIL; + } } } } @@ -3521,12 +3668,12 @@ store_aff_word ( // Read a file with a list of words. static int spell_read_wordfile(spellinfo_T *spin, char_u *fname) { - FILE *fd; + FILE *fd; long lnum = 0; char_u rline[MAXLINELEN]; - char_u *line; - char_u *pc = NULL; - char_u *p; + char_u *line; + char_u *pc = NULL; + char_u *p; int l; int retval = OK; bool did_word = false; @@ -3550,15 +3697,18 @@ static int spell_read_wordfile(spellinfo_T *spin, char_u *fname) ++lnum; // Skip comment lines. - if (*rline == '#') + if (*rline == '#') { continue; + } // Remove CR, LF and white space from the end. l = (int)STRLEN(rline); - while (l > 0 && rline[l - 1] <= ' ') + while (l > 0 && rline[l - 1] <= ' ') { --l; - if (l == 0) + } + if (l == 0) { continue; // empty or blank line + } rline[l] = NUL; // Convert from "/encoding={encoding}" to 'encoding' when needed. @@ -3586,16 +3736,17 @@ static int spell_read_wordfile(spellinfo_T *spin, char_u *fname) smsg(_("/encoding= line after word ignored in %s line %ld: %s"), fname, lnum, line - 1); } else { - char_u *enc; + char_u *enc; // Setup for conversion to 'encoding'. line += 9; enc = enc_canonize(line); if (!spin->si_ascii && convert_setup(&spin->si_conv, enc, - p_enc) == FAIL) + p_enc) == FAIL) { smsg(_("Conversion in %s not supported: from %s to %s"), fname, line, p_enc); + } xfree(enc); spin->si_conv.vc_fail = true; } @@ -3635,15 +3786,16 @@ static int spell_read_wordfile(spellinfo_T *spin, char_u *fname) if (p != NULL) { *p++ = NUL; while (*p != NUL) { - if (*p == '=') // keep-case word + if (*p == '=') { // keep-case word flags |= WF_KEEPCAP | WF_FIXCAP; - else if (*p == '!') // Bad, bad, wicked word. + } else if (*p == '!') { // Bad, bad, wicked word. flags |= WF_BANNED; - else if (*p == '?') // Rare word. + } else if (*p == '?') { // Rare word. flags |= WF_RARE; - else if (ascii_isdigit(*p)) { // region number(s) - if ((flags & WF_REGION) == 0) // first one + } else if (ascii_isdigit(*p)) { // region number(s) + if ((flags & WF_REGION) == 0) { // first one regionmask = 0; + } flags |= WF_REGION; l = *p - '0'; @@ -3681,7 +3833,7 @@ static int spell_read_wordfile(spellinfo_T *spin, char_u *fname) if (spin->si_ascii && non_ascii > 0) { vim_snprintf((char *)IObuff, IOSIZE, - _("Ignored %d words with non-ASCII characters"), non_ascii); + _("Ignored %d words with non-ASCII characters"), non_ascii); spell_message(spin, IObuff); } @@ -3699,16 +3851,17 @@ static int spell_read_wordfile(spellinfo_T *spin, char_u *fname) static void *getroom(spellinfo_T *spin, size_t len, bool align) FUNC_ATTR_NONNULL_RET { - char_u *p; - sblock_T *bl = spin->si_blocks; + char_u *p; + sblock_T *bl = spin->si_blocks; assert(len <= SBLOCKSIZE); - - if (align && bl != NULL) + + if (align && bl != NULL) { // Round size up for alignment. On some systems structures need to be // aligned to the size of a pointer (e.g., SPARC). bl->sb_used = (bl->sb_used + sizeof(char *) - 1) & ~(sizeof(char *) - 1); + } if (bl == NULL || bl->sb_used + len > SBLOCKSIZE) { // Allocate a block of memory. It is not freed until much later. @@ -3737,7 +3890,7 @@ static char_u *getroom_save(spellinfo_T *spin, char_u *s) // Free the list of allocated sblock_T. static void free_blocks(sblock_T *bl) { - sblock_T *next; + sblock_T *next; while (bl != NULL) { next = bl->sb_next; @@ -3754,22 +3907,20 @@ static wordnode_T *wordtree_alloc(spellinfo_T *spin) return (wordnode_T *)getroom(spin, sizeof(wordnode_T), true); } -// Store a word in the tree(s). -// Always store it in the case-folded tree. For a keep-case word this is -// useful when the word can also be used with all caps (no WF_FIXCAP flag) and -// used to find suggestions. -// For a keep-case word also store it in the keep-case tree. -// When "pfxlist" is not NULL store the word for each postponed prefix ID and -// compound flag. -static int -store_word ( - spellinfo_T *spin, - char_u *word, - int flags, // extra flags, WF_BANNED - int region, // supported region(s) - const char_u *pfxlist, // list of prefix IDs or NULL - bool need_affix // only store word with affix ID -) +/// Store a word in the tree(s). +/// Always store it in the case-folded tree. For a keep-case word this is +/// useful when the word can also be used with all caps (no WF_FIXCAP flag) and +/// used to find suggestions. +/// For a keep-case word also store it in the keep-case tree. +/// When "pfxlist" is not NULL store the word for each postponed prefix ID and +/// compound flag. +/// +/// @param flags extra flags, wf_banned +/// @param region supported region(s) +/// @param pfxlist list of prefix ids or null +/// @param need_affix only store word with affix id +static int store_word(spellinfo_T *spin, char_u *word, int flags, int region, const char_u *pfxlist, + bool need_affix) { int len = (int)STRLEN(word); int ct = captype(word, word + len); @@ -3807,12 +3958,13 @@ store_word ( // When "flags" < 0 we are adding to the prefix tree where "flags" is used for // "rare" and "region" is the condition nr. // Returns FAIL when out of memory. -static int tree_add_word(spellinfo_T *spin, char_u *word, wordnode_T *root, int flags, int region, int affixID) +static int tree_add_word(spellinfo_T *spin, char_u *word, wordnode_T *root, int flags, int region, + int affixID) { - wordnode_T *node = root; - wordnode_T *np; - wordnode_T *copyp, **copyprev; - wordnode_T **prev = NULL; + wordnode_T *node = root; + wordnode_T *np; + wordnode_T *copyp, **copyprev; + wordnode_T **prev = NULL; int i; // Add each byte of the word to the tree, including the NUL at the end. @@ -3826,11 +3978,13 @@ static int tree_add_word(spellinfo_T *spin, char_u *word, wordnode_T *root, int for (copyp = node; copyp != NULL; copyp = copyp->wn_sibling) { // Allocate a new node and copy the info. np = get_wordnode(spin); - if (np == NULL) + if (np == NULL) { return FAIL; + } np->wn_child = copyp->wn_child; - if (np->wn_child != NULL) + if (np->wn_child != NULL) { ++np->wn_child->wn_refs; // child gets extra ref + } np->wn_byte = copyp->wn_byte; if (np->wn_byte == NUL) { np->wn_flags = copyp->wn_flags; @@ -3840,13 +3994,15 @@ static int tree_add_word(spellinfo_T *spin, char_u *word, wordnode_T *root, int // Link the new node in the list, there will be one ref. np->wn_refs = 1; - if (copyprev != NULL) + if (copyprev != NULL) { *copyprev = np; + } copyprev = &np->wn_sibling; // Let "node" point to the head of the copied list. - if (copyp == node) + if (copyp == node) { node = np; + } } } @@ -3877,22 +4033,24 @@ static int tree_add_word(spellinfo_T *spin, char_u *word, wordnode_T *root, int || node->wn_affixID != affixID))) { // Allocate a new node. np = get_wordnode(spin); - if (np == NULL) + if (np == NULL) { return FAIL; + } np->wn_byte = word[i]; // If "node" is NULL this is a new child or the end of the sibling // list: ref count is one. Otherwise use ref count of sibling and // make ref count of sibling one (matters when inserting in front // of the list of siblings). - if (node == NULL) + if (node == NULL) { np->wn_refs = 1; - else { + } else { np->wn_refs = node->wn_refs; node->wn_refs = 1; } - if (prev != NULL) + if (prev != NULL) { *prev = np; + } np->wn_sibling = node; node = np; } @@ -3934,7 +4092,7 @@ static int tree_add_word(spellinfo_T *spin, char_u *word, wordnode_T *root, int #ifndef SPELL_COMPRESS_ALLWAYS if (spin->si_compress_cnt == 1 // NOLINT(readability/braces) ? spin->si_free_count < MAXWLEN - : spin->si_blocks_cnt >= compress_start) + : spin->si_blocks_cnt >= compress_start) #endif { // Decrement the block counter. The effect is that we compress again @@ -3973,17 +4131,18 @@ static wordnode_T *get_wordnode(spellinfo_T *spin) { wordnode_T *n; - if (spin->si_first_free == NULL) + if (spin->si_first_free == NULL) { n = (wordnode_T *)getroom(spin, sizeof(wordnode_T), true); - else { + } else { n = spin->si_first_free; spin->si_first_free = n->wn_child; memset(n, 0, sizeof(wordnode_T)); --spin->si_free_count; } #ifdef SPELL_PRINTTREE - if (n != NULL) + if (n != NULL) { n->wn_nr = ++spin->si_wordnode_nr; + } #endif return n; } @@ -3995,13 +4154,14 @@ static wordnode_T *get_wordnode(spellinfo_T *spin) static int deref_wordnode(spellinfo_T *spin, wordnode_T *node) FUNC_ATTR_NONNULL_ALL { - wordnode_T *np; + wordnode_T *np; int cnt = 0; if (--node->wn_refs == 0) { for (np = node; np != NULL; np = np->wn_sibling) { - if (np->wn_child != NULL) + if (np->wn_child != NULL) { cnt += deref_wordnode(spin, np->wn_child); + } free_wordnode(spin, np); ++cnt; } @@ -4021,8 +4181,7 @@ static void free_wordnode(spellinfo_T *spin, wordnode_T *n) } // Compress a tree: find tails that are identical and can be shared. -static void wordtree_compress(spellinfo_T *spin, wordnode_T *root, - const char *name) +static void wordtree_compress(spellinfo_T *spin, wordnode_T *root, const char *name) FUNC_ATTR_NONNULL_ALL { hashtab_T ht; @@ -4039,12 +4198,13 @@ static void wordtree_compress(spellinfo_T *spin, wordnode_T *root, if (spin->si_verbose || p_verbose > 2) #endif { - if (tot > 1000000) + if (tot > 1000000) { perc = (tot - n) / (tot / 100); - else if (tot == 0) + } else if (tot == 0) { perc = 0; - else + } else { perc = (tot - n) * 100 / tot; + } vim_snprintf((char *)IObuff, IOSIZE, _("Compressed %s of %ld nodes; %ld (%ld%%) remaining"), name, tot, tot - n, perc); @@ -4057,22 +4217,18 @@ static void wordtree_compress(spellinfo_T *spin, wordnode_T *root, } } -// Compress a node, its siblings and its children, depth first. -// Returns the number of compressed nodes. -static long node_compress( - spellinfo_T *spin, - wordnode_T *node, - hashtab_T *ht, - long *tot // total count of nodes before compressing, - // incremented while going through the tree -) +/// Compress a node, its siblings and its children, depth first. +/// Returns the number of compressed nodes. +/// +/// @param tot total count of nodes before compressing, incremented while going through the tree +static long node_compress(spellinfo_T *spin, wordnode_T *node, hashtab_T *ht, long *tot) FUNC_ATTR_NONNULL_ALL { - wordnode_T *np; - wordnode_T *tp; - wordnode_T *child; + wordnode_T *np; + wordnode_T *tp; + wordnode_T *child; hash_T hash; - hashitem_T *hi; + hashitem_T *hi; long len = 0; unsigned nr, n; long compressed = 0; @@ -4095,7 +4251,7 @@ static long node_compress( // There are children we encountered before with a hash value // identical to the current child. Now check if there is one // that is really identical. - for (tp = HI2WN(hi); tp != NULL; tp = tp->wn_u2.next) + for (tp = HI2WN(hi); tp != NULL; tp = tp->wn_u2.next) { if (node_equal(child, tp)) { // Found one! Now use that child in place of the // current one. This means the current child and all @@ -4105,6 +4261,7 @@ static long node_compress( np->wn_child = tp; break; } + } if (tp == NULL) { // No other child with this hash value equals the child of // the node, add it to the linked list after the first @@ -4113,10 +4270,11 @@ static long node_compress( child->wn_u2.next = tp->wn_u2.next; tp->wn_u2.next = child; } - } else + } else { // No other child has this hash value, add it to the // hashtable. hash_add_item(ht, hi, child->wn_u1.hashkey, hash); + } } } *tot += len + 1; // add one for the node that stores the length @@ -4127,12 +4285,13 @@ static long node_compress( node->wn_u1.hashkey[0] = len; nr = 0; for (np = node; np != NULL; np = np->wn_sibling) { - if (np->wn_byte == NUL) + if (np->wn_byte == NUL) { // end node: use wn_flags, wn_region and wn_affixID n = np->wn_flags + (np->wn_region << 8) + (np->wn_affixID << 16); - else + } else { // byte node: use the byte value and the child pointer n = (unsigned)(np->wn_byte + ((uintptr_t)np->wn_child << 8)); + } nr = nr * 101 + n; } @@ -4156,18 +4315,20 @@ static long node_compress( // Returns true when two nodes have identical siblings and children. static bool node_equal(wordnode_T *n1, wordnode_T *n2) { - wordnode_T *p1; - wordnode_T *p2; + wordnode_T *p1; + wordnode_T *p2; for (p1 = n1, p2 = n2; p1 != NULL && p2 != NULL; - p1 = p1->wn_sibling, p2 = p2->wn_sibling) + p1 = p1->wn_sibling, p2 = p2->wn_sibling) { if (p1->wn_byte != p2->wn_byte || (p1->wn_byte == NUL ? (p1->wn_flags != p2->wn_flags || p1->wn_region != p2->wn_region || p1->wn_affixID != p2->wn_affixID) - : (p1->wn_child != p2->wn_child))) + : (p1->wn_child != p2->wn_child))) { break; + } + } return p1 == NULL && p2 == NULL; } @@ -4176,8 +4337,8 @@ static bool node_equal(wordnode_T *n1, wordnode_T *n2) // Function given to qsort() to sort the REP items on "from" string. static int rep_compare(const void *s1, const void *s2) { - fromto_T *p1 = (fromto_T *)s1; - fromto_T *p2 = (fromto_T *)s2; + fromto_T *p1 = (fromto_T *)s1; + fromto_T *p2 = (fromto_T *)s2; return STRCMP(p1->ft_from, p2->ft_from); } @@ -4198,9 +4359,10 @@ static int write_vim_spell(spellinfo_T *spin, char_u *fname) // <HEADER>: <fileID> <versionnr> // <fileID> size_t fwv = fwrite(VIMSPELLMAGIC, VIMSPELLMAGICL, 1, fd); - if (fwv != (size_t)1) + if (fwv != (size_t)1) { // Catch first write error, don't try writing more. goto theend; + } putc(VIMSPELLVERSION, fd); // <versionnr> @@ -4225,8 +4387,9 @@ static int write_vim_spell(spellinfo_T *spin, char_u *fname) fwv &= fwrite(spin->si_region_name, l, 1, fd); // <regionname> ... regionmask = (1 << spin->si_region_count) - 1; - } else + } else { regionmask = 0; + } // SN_CHARFLAGS: <charflagslen> <charflags> <folcharslen> <folchars> // @@ -4254,10 +4417,12 @@ static int write_vim_spell(spellinfo_T *spin, char_u *fname) fputc(128, fd); // <charflagslen> for (size_t i = 128; i < 256; ++i) { flags = 0; - if (spelltab.st_isw[i]) + if (spelltab.st_isw[i]) { flags |= CF_WORD; - if (spelltab.st_isu[i]) + } + if (spelltab.st_isu[i]) { flags |= CF_UPPER; + } fputc(flags, fd); // <charflags> } @@ -4296,24 +4461,28 @@ static int write_vim_spell(spellinfo_T *spin, char_u *fname) // round 3: SN_REPSAL section for (unsigned int round = 1; round <= 3; ++round) { garray_T *gap; - if (round == 1) + if (round == 1) { gap = &spin->si_rep; - else if (round == 2) { + } else if (round == 2) { // Don't write SN_SAL when using a SN_SOFO section - if (spin->si_sofofr != NULL && spin->si_sofoto != NULL) + if (spin->si_sofofr != NULL && spin->si_sofoto != NULL) { continue; + } gap = &spin->si_sal; - } else + } else { gap = &spin->si_repsal; + } // Don't write the section if there are no items. - if (GA_EMPTY(gap)) + if (GA_EMPTY(gap)) { continue; + } // Sort the REP/REPSAL items. - if (round != 2) + if (round != 2) { qsort(gap->ga_data, (size_t)gap->ga_len, - sizeof(fromto_T), rep_compare); + sizeof(fromto_T), rep_compare); + } int sect_id = round == 1 ? SN_REP : (round == 2 ? SN_SAL : SN_REPSAL); putc(sect_id, fd); // <sectionID> @@ -4329,18 +4498,22 @@ static int write_vim_spell(spellinfo_T *spin, char_u *fname) l += 1 + STRLEN(ftp->ft_from); // count <*fromlen> and <*from> l += 1 + STRLEN(ftp->ft_to); // count <*tolen> and <*to> } - if (round == 2) + if (round == 2) { ++l; // count <salflags> + } put_bytes(fd, l, 4); // <sectionlen> if (round == 2) { int i = 0; - if (spin->si_followup) + if (spin->si_followup) { i |= SAL_F0LLOWUP; - if (spin->si_collapse) + } + if (spin->si_collapse) { i |= SAL_COLLAPSE; - if (spin->si_rem_accents) + } + if (spin->si_rem_accents) { i |= SAL_REM_ACCENTS; + } putc(i, fd); // <salflags> } @@ -4354,11 +4527,11 @@ static int write_vim_spell(spellinfo_T *spin, char_u *fname) l = STRLEN(p); assert(l < INT_MAX); putc((int)l, fd); - if (l > 0) + if (l > 0) { fwv &= fwrite(p, l, 1, fd); + } } } - } // SN_SOFO: <sofofromlen> <sofofrom> <sofotolen> <sofoto> @@ -4389,19 +4562,22 @@ static int write_vim_spell(spellinfo_T *spin, char_u *fname) for (unsigned int round = 1; round <= 2; ++round) { size_t todo; size_t len = 0; - hashitem_T *hi; + hashitem_T *hi; todo = spin->si_commonwords.ht_used; - for (hi = spin->si_commonwords.ht_array; todo > 0; ++hi) + for (hi = spin->si_commonwords.ht_array; todo > 0; ++hi) { if (!HASHITEM_EMPTY(hi)) { size_t l = STRLEN(hi->hi_key) + 1; len += l; - if (round == 2) // <word> + if (round == 2) { // <word> fwv &= fwrite(hi->hi_key, l, 1, fd); + } --todo; } - if (round == 1) + } + if (round == 1) { put_bytes(fd, len, 4); // <sectionlen> + } } } @@ -4509,12 +4685,13 @@ static int write_vim_spell(spellinfo_T *spin, char_u *fname) spin->si_memtot = 0; for (unsigned int round = 1; round <= 3; ++round) { wordnode_T *tree; - if (round == 1) + if (round == 1) { tree = spin->si_foldroot->wn_sibling; - else if (round == 2) + } else if (round == 2) { tree = spin->si_keeproot->wn_sibling; - else + } else { tree = spin->si_prefroot->wn_sibling; + } // Clear the index and wnode fields in the tree. clear_node(tree); @@ -4534,16 +4711,20 @@ static int write_vim_spell(spellinfo_T *spin, char_u *fname) } // Write another byte to check for errors (file system full). - if (putc(0, fd) == EOF) + if (putc(0, fd) == EOF) { retval = FAIL; + } theend: - if (fclose(fd) == EOF) + if (fclose(fd) == EOF) { retval = FAIL; + } - if (fwv != (size_t)1) + if (fwv != (size_t)1) { retval = FAIL; - if (retval == FAIL) + } + if (retval == FAIL) { EMSG(_(e_write)); + } return retval; } @@ -4553,54 +4734,54 @@ theend: // space. static void clear_node(wordnode_T *node) { - wordnode_T *np; + wordnode_T *np; - if (node != NULL) + if (node != NULL) { for (np = node; np != NULL; np = np->wn_sibling) { np->wn_u1.index = 0; np->wn_u2.wnode = NULL; - if (np->wn_byte != NUL) + if (np->wn_byte != NUL) { clear_node(np->wn_child); + } } + } } -// Dump a word tree at node "node". -// -// This first writes the list of possible bytes (siblings). Then for each -// byte recursively write the children. -// -// NOTE: The code here must match the code in read_tree_node(), since -// assumptions are made about the indexes (so that we don't have to write them -// in the file). -// -// Returns the number of nodes used. -static int -put_node ( - FILE *fd, // NULL when only counting - wordnode_T *node, - int idx, - int regionmask, - bool prefixtree // true for PREFIXTREE -) +/// Dump a word tree at node "node". +/// +/// This first writes the list of possible bytes (siblings). Then for each +/// byte recursively write the children. +/// +/// NOTE: The code here must match the code in read_tree_node(), since +/// assumptions are made about the indexes (so that we don't have to write them +/// in the file). +/// +/// @param fd NULL when only counting +/// @param prefixtree true for PREFIXTREE +/// +/// @return the number of nodes used. +static int put_node(FILE *fd, wordnode_T *node, int idx, int regionmask, bool prefixtree) { // If "node" is zero the tree is empty. - if (node == NULL) + if (node == NULL) { return 0; + } // Store the index where this node is written. node->wn_u1.index = idx; // Count the number of siblings. int siblingcount = 0; - for (wordnode_T *np = node; np != NULL; np = np->wn_sibling) + for (wordnode_T *np = node; np != NULL; np = np->wn_sibling) { ++siblingcount; + } // Write the sibling count. - if (fd != NULL) + if (fd != NULL) { putc(siblingcount, fd); // <siblingcount> - + } // Write each sibling byte and optionally extra info. for (wordnode_T *np = node; np != NULL; np = np->wn_sibling) { if (np->wn_byte == 0) { @@ -4611,9 +4792,9 @@ put_node ( // associated condition nr (stored in wn_region). The // byte value is misused to store the "rare" and "not // combining" flags - if (np->wn_flags == (uint16_t)PFX_FLAGS) + if (np->wn_flags == (uint16_t)PFX_FLAGS) { putc(BY_NOFLAGS, fd); // <byte> - else { + } else { putc(BY_FLAGS, fd); // <byte> putc(np->wn_flags, fd); // <pflags> } @@ -4622,10 +4803,12 @@ put_node ( } else { // For word trees we write the flag/region items. int flags = np->wn_flags; - if (regionmask != 0 && np->wn_region != regionmask) + if (regionmask != 0 && np->wn_region != regionmask) { flags |= WF_REGION; - if (np->wn_affixID != 0) + } + if (np->wn_affixID != 0) { flags |= WF_AFX; + } if (flags == 0) { // word without flags or region putc(BY_NOFLAGS, fd); // <byte> @@ -4638,10 +4821,12 @@ put_node ( putc(BY_FLAGS, fd); // <byte> putc(flags, fd); // <flags> } - if (flags & WF_REGION) + if (flags & WF_REGION) { putc(np->wn_region, fd); // <region> - if (flags & WF_AFX) + } + if (flags & WF_AFX) { putc(np->wn_affixID, fd); // <affixID> + } } } } @@ -4653,15 +4838,17 @@ put_node ( putc(BY_INDEX, fd); // <byte> put_bytes(fd, (uintmax_t)np->wn_child->wn_u1.index, 3); // <nodeidx> } - } else if (np->wn_child->wn_u2.wnode == NULL) + } else if (np->wn_child->wn_u2.wnode == NULL) { // We will write the child below and give it an index. np->wn_child->wn_u2.wnode = node; + } - if (fd != NULL) + if (fd != NULL) { if (putc(np->wn_byte, fd) == EOF) { // <byte> or <xbyte> EMSG(_(e_write)); return 0; } + } } } @@ -4670,10 +4857,12 @@ put_node ( int newindex = idx + siblingcount + 1; // Recursively dump the children of each sibling. - for (wordnode_T *np = node; np != NULL; np = np->wn_sibling) - if (np->wn_byte != 0 && np->wn_child->wn_u2.wnode == node) + for (wordnode_T *np = node; np != NULL; np = np->wn_sibling) { + if (np->wn_byte != 0 && np->wn_child->wn_u2.wnode == node) { newindex = put_node(fd, np->wn_child, newindex, regionmask, - prefixtree); + prefixtree); + } + } return newindex; } @@ -4684,8 +4873,8 @@ put_node ( void ex_mkspell(exarg_T *eap) { int fcount; - char_u **fnames; - char_u *arg = eap->arg; + char_u **fnames; + char_u *arg = eap->arg; bool ascii = false; if (STRNCMP(arg, "-ascii", 6) == 0) { @@ -4705,9 +4894,9 @@ void ex_mkspell(exarg_T *eap) // Writes the file with the name "wfname", with ".spl" changed to ".sug". static void spell_make_sugfile(spellinfo_T *spin, char_u *wfname) { - char_u *fname = NULL; + char_u *fname = NULL; int len; - slang_T *slang; + slang_T *slang; bool free_slang = false; // Read back the .spl file that was written. This fills the required @@ -4724,8 +4913,9 @@ static void spell_make_sugfile(spellinfo_T *spin, char_u *wfname) if (slang == NULL) { spell_message(spin, (char_u *)_("Reading back spell file...")); slang = spell_load_file(wfname, NULL, NULL, false); - if (slang == NULL) + if (slang == NULL) { return; + } free_slang = true; } @@ -4740,15 +4930,17 @@ static void spell_make_sugfile(spellinfo_T *spin, char_u *wfname) // Go through the trie of good words, soundfold each word and add it to // the soundfold trie. spell_message(spin, (char_u *)_("Performing soundfolding...")); - if (sug_filltree(spin, slang) == FAIL) + if (sug_filltree(spin, slang) == FAIL) { goto theend; + } // Create the table which links each soundfold word with a list of the // good words it may come from. Creates buffer "spin->si_spellbuf". // This also removes the wordnr from the NUL byte entries to make // compression possible. - if (sug_maketable(spin) == FAIL) + if (sug_maketable(spin) == FAIL) { goto theend; + } smsg(_("Number of words after soundfolding: %" PRId64), (int64_t)spin->si_spellbuf->b_ml.ml_line_count); @@ -4768,8 +4960,9 @@ static void spell_make_sugfile(spellinfo_T *spin, char_u *wfname) theend: xfree(fname); - if (free_slang) + if (free_slang) { slang_free(slang); + } free_blocks(spin->si_blocks); close_spellbuf(spin->si_spellbuf); } @@ -4777,8 +4970,8 @@ theend: // Build the soundfold trie for language "slang". static int sug_filltree(spellinfo_T *spin, slang_T *slang) { - char_u *byts; - idx_T *idxs; + char_u *byts; + idx_T *idxs; int depth; idx_T arridx[MAXWLEN]; int curi[MAXWLEN]; @@ -4809,13 +5002,13 @@ static int sug_filltree(spellinfo_T *spin, slang_T *slang) if (curi[depth] > byts[arridx[depth]]) { // Done all bytes at this node, go up one level. idxs[arridx[depth]] = wordcount[depth]; - if (depth > 0) + if (depth > 0) { wordcount[depth - 1] += wordcount[depth]; + } --depth; line_breakcheck(); } else { - // Do one more byte at this node. n = arridx[depth] + curi[depth]; ++curi[depth]; @@ -4829,9 +5022,10 @@ static int sug_filltree(spellinfo_T *spin, slang_T *slang) // We use the "flags" field for the MSB of the wordnr, // "region" for the LSB of the wordnr. if (tree_add_word(spin, tsalword, spin->si_foldroot, - words_done >> 16, words_done & 0xffff, - 0) == FAIL) + words_done >> 16, words_done & 0xffff, + 0) == FAIL) { return FAIL; + } ++words_done; ++wordcount[depth]; @@ -4880,25 +5074,22 @@ static int sug_maketable(spellinfo_T *spin) ga_init(&ga, 1, 100); // recursively go through the tree - if (sug_filltable(spin, spin->si_foldroot->wn_sibling, 0, &ga) == -1) + if (sug_filltable(spin, spin->si_foldroot->wn_sibling, 0, &ga) == -1) { res = FAIL; + } ga_clear(&ga); return res; } -// Fill the table for one node and its children. -// Returns the wordnr at the start of the node. -// Returns -1 when out of memory. -static int -sug_filltable ( - spellinfo_T *spin, - wordnode_T *node, - int startwordnr, - garray_T *gap // place to store line of numbers -) +/// Fill the table for one node and its children. +/// Returns the wordnr at the start of the node. +/// Returns -1 when out of memory. +/// +/// @param gap place to store line of numbers +static int sug_filltable(spellinfo_T *spin, wordnode_T *node, int startwordnr, garray_T *gap) { - wordnode_T *p, *np; + wordnode_T *p, *np; int wordnr = startwordnr; int nr; int prev_nr; @@ -4918,7 +5109,7 @@ sug_filltable ( nr -= prev_nr; prev_nr += nr; gap->ga_len += offset2bytes(nr, - (char_u *)gap->ga_data + gap->ga_len); + (char_u *)gap->ga_data + gap->ga_len); } // add the NUL byte @@ -4932,8 +5123,9 @@ sug_filltable ( // Remove extra NUL entries, we no longer need them. We don't // bother freeing the nodes, the won't be reused anyway. - while (p->wn_sibling != NULL && p->wn_sibling->wn_byte == NUL) + while (p->wn_sibling != NULL && p->wn_sibling->wn_byte == NUL) { p->wn_sibling = p->wn_sibling->wn_sibling; + } // Clear the flags on the remaining NUL node, so that compression // works a lot better. @@ -4941,8 +5133,9 @@ sug_filltable ( p->wn_region = 0; } else { wordnr = sug_filltable(spin, p->wn_child, wordnr, gap); - if (wordnr == -1) + if (wordnr == -1) { return -1; + } } } return wordnr; @@ -5002,7 +5195,7 @@ static void sug_write(spellinfo_T *spin, char_u *fname) spell_message(spin, IObuff); // <SUGHEADER>: <fileID> <versionnr> <timestamp> - if (fwrite(VIMSUGMAGIC, VIMSUGMAGICL, (size_t)1, fd) != 1) { // <fileID> + if (fwrite(VIMSUGMAGIC, VIMSUGMAGICL, (size_t)1, fd) != 1) { // <fileID> EMSG(_(e_write)); goto theend; } @@ -5049,11 +5242,12 @@ static void sug_write(spellinfo_T *spin, char_u *fname) } // Write another byte to check for errors. - if (putc(0, fd) == EOF) + if (putc(0, fd) == EOF) { EMSG(_(e_write)); + } vim_snprintf((char *)IObuff, IOSIZE, - _("Estimated runtime memory use: %d bytes"), spin->si_memtot); + _("Estimated runtime memory use: %d bytes"), spin->si_memtot); spell_message(spin, IObuff); theend: @@ -5062,23 +5256,20 @@ theend: } -// Create a Vim spell file from one or more word lists. -// "fnames[0]" is the output file name. -// "fnames[fcount - 1]" is the last input file name. -// Exception: when "fnames[0]" ends in ".add" it's used as the input file name -// and ".spl" is appended to make the output file name. -static void -mkspell ( - int fcount, - char_u **fnames, - bool ascii, // -ascii argument given - bool over_write, // overwrite existing output file - bool added_word // invoked through "zg" -) +/// Create a Vim spell file from one or more word lists. +/// "fnames[0]" is the output file name. +/// "fnames[fcount - 1]" is the last input file name. +/// Exception: when "fnames[0]" ends in ".add" it's used as the input file name +/// and ".spl" is appended to make the output file name. +/// +/// @param ascii -ascii argument given +/// @param over_write overwrite existing output file +/// @param added_word invoked through "zg" +static void mkspell(int fcount, char_u **fnames, bool ascii, bool over_write, bool added_word) { - char_u *fname = NULL; - char_u *wfname; - char_u **innames; + char_u *fname = NULL; + char_u *wfname; + char_u **innames; int incount; afffile_T *(afile[MAXREGIONS]); int i; @@ -5114,26 +5305,29 @@ mkspell ( // "path/en.latin1.add.spl". incount = 1; vim_snprintf((char *)wfname, MAXPATHL, "%s.spl", fnames[0]); - } else if (fcount == 1) { + } else if (fcount == 1) { // For ":mkspell path/vim" output file is "path/vim.latin1.spl". incount = 1; vim_snprintf((char *)wfname, MAXPATHL, SPL_FNAME_TMPL, - fnames[0], spin.si_ascii ? (char_u *)"ascii" : spell_enc()); - } else if (len > 4 && STRCMP(fnames[0] + len - 4, ".spl") == 0) { + fnames[0], spin.si_ascii ? (char_u *)"ascii" : spell_enc()); + } else if (len > 4 && STRCMP(fnames[0] + len - 4, ".spl") == 0) { // Name ends in ".spl", use as the file name. STRLCPY(wfname, fnames[0], MAXPATHL); - } else + } else { // Name should be language, make the file name from it. vim_snprintf((char *)wfname, MAXPATHL, SPL_FNAME_TMPL, - fnames[0], spin.si_ascii ? (char_u *)"ascii" : spell_enc()); + fnames[0], spin.si_ascii ? (char_u *)"ascii" : spell_enc()); + } // Check for .ascii.spl. - if (strstr((char *)path_tail(wfname), SPL_FNAME_ASCII) != NULL) + if (strstr((char *)path_tail(wfname), SPL_FNAME_ASCII) != NULL) { spin.si_ascii = true; + } // Check for .add.spl. - if (strstr((char *)path_tail(wfname), SPL_FNAME_ADD) != NULL) + if (strstr((char *)path_tail(wfname), SPL_FNAME_ADD) != NULL) { spin.si_add = true; + } } if (incount <= 0) { @@ -5184,8 +5378,9 @@ mkspell ( // one in the .spl file if the .aff file doesn't define one. That's // better than guessing the contents, the table will match a // previously loaded spell file. - if (!spin.si_add) + if (!spin.si_add) { spin.si_clear_chartab = true; + } // Read all the .aff and .dic files. // Text is converted to 'encoding'. @@ -5199,28 +5394,31 @@ mkspell ( // Read the .aff file. Will init "spin->si_conv" based on the // "SET" line. afile[i] = spell_read_aff(&spin, fname); - if (afile[i] == NULL) + if (afile[i] == NULL) { error = true; - else { + } else { // Read the .dic file and store the words in the trees. vim_snprintf((char *)fname, MAXPATHL, "%s.dic", - innames[i]); - if (spell_read_dic(&spin, fname, afile[i]) == FAIL) + innames[i]); + if (spell_read_dic(&spin, fname, afile[i]) == FAIL) { error = true; + } } } else { // No .aff file, try reading the file as a word list. Store // the words in the trees. - if (spell_read_wordfile(&spin, innames[i]) == FAIL) + if (spell_read_wordfile(&spin, innames[i]) == FAIL) { error = true; + } } // Free any conversion stuff. convert_setup(&spin.si_conv, NULL, NULL); } - if (spin.si_compflags != NULL && spin.si_nobreak) + if (spin.si_compflags != NULL && spin.si_nobreak) { MSG(_("Warning: both compounding and NOBREAK specified")); + } if (!error && !got_int) { // Combine tails in the tree. @@ -5240,12 +5438,13 @@ mkspell ( spell_message(&spin, (char_u *)_("Done!")); vim_snprintf((char *)IObuff, IOSIZE, - _("Estimated runtime memory use: %d bytes"), spin.si_memtot); + _("Estimated runtime memory use: %d bytes"), spin.si_memtot); spell_message(&spin, IObuff); // If the file is loaded need to reload it. - if (!error) + if (!error) { spell_reload_one(wfname, added_word); + } } // Free the allocated memory. @@ -5258,18 +5457,20 @@ mkspell ( hash_clear_all(&spin.si_commonwords, 0); // Free the .aff file structures. - for (i = 0; i < incount; ++i) - if (afile[i] != NULL) + for (i = 0; i < incount; ++i) { + if (afile[i] != NULL) { spell_free_aff(afile[i]); + } + } // Free all the bits and pieces at once. free_blocks(spin.si_blocks); // If there is soundfolding info and no NOSUGFILE item create the // .sug file with the soundfolded word trie. - if (spin.si_sugtime != 0 && !error && !got_int) + if (spin.si_sugtime != 0 && !error && !got_int) { spell_make_sugfile(&spin, wfname); - + } } theend: @@ -5283,12 +5484,14 @@ static void spell_message(const spellinfo_T *spin, char_u *str) FUNC_ATTR_NONNULL_ALL { if (spin->si_verbose || p_verbose > 2) { - if (!spin->si_verbose) + if (!spin->si_verbose) { verbose_enter(); + } MSG(str); ui_flush(); - if (!spin->si_verbose) + if (!spin->si_verbose) { verbose_leave(); + } } } @@ -5305,32 +5508,29 @@ void ex_spell(exarg_T *eap) eap->cmdidx == CMD_spellundo); } -// Add "word[len]" to 'spellfile' as a good or bad word. -void -spell_add_word ( - char_u *word, - int len, - SpellAddType what, // SPELL_ADD_ values - int idx, // "zG" and "zW": zero, otherwise index in - // 'spellfile' - bool undo // true for "zug", "zuG", "zuw" and "zuW" -) +/// Add "word[len]" to 'spellfile' as a good or bad word. +/// +/// @param what SPELL_ADD_ values +/// @param idx "zG" and "zW": zero, otherwise index in 'spellfile' +/// @param bool // true for "zug", "zuG", "zuw" and "zuW" +void spell_add_word(char_u *word, int len, SpellAddType what, int idx, bool undo) { - FILE *fd = NULL; - buf_T *buf = NULL; + FILE *fd = NULL; + buf_T *buf = NULL; bool new_spf = false; - char_u *fname; - char_u *fnamebuf = NULL; + char_u *fname; + char_u *fnamebuf = NULL; char_u line[MAXWLEN * 2]; long fpos, fpos_next = 0; int i; - char_u *spf; + char_u *spf; if (idx == 0) { // use internal wordlist if (int_wordlist == NULL) { int_wordlist = vim_tempname(); - if (int_wordlist == NULL) + if (int_wordlist == NULL) { return; + } } fname = int_wordlist; } else { @@ -5348,8 +5548,9 @@ spell_add_word ( for (spf = curwin->w_s->b_p_spf, i = 1; *spf != NUL; ++i) { copy_option_part(&spf, fnamebuf, MAXPATHL, ","); - if (i == idx) + if (i == idx) { break; + } if (*spf == NUL) { EMSGN(_("E765: 'spellfile' does not have %" PRId64 " entries"), idx); xfree(fnamebuf); @@ -5359,8 +5560,9 @@ spell_add_word ( // Check that the user isn't editing the .add file somewhere. buf = buflist_findname_exp(fnamebuf); - if (buf != NULL && buf->b_ml.ml_mfp == NULL) + if (buf != NULL && buf->b_ml.ml_mfp == NULL) { buf = NULL; + } if (buf != NULL && bufIsChanged(buf)) { EMSG(_(e_bufloaded)); xfree(fnamebuf); @@ -5402,8 +5604,9 @@ spell_add_word ( } } } - if (fd != NULL) + if (fd != NULL) { fclose(fd); + } } } @@ -5450,8 +5653,9 @@ spell_add_word ( mkspell(1, &fname, false, true, true); // If the .add file is edited somewhere, reload it. - if (buf != NULL) + if (buf != NULL) { buf_reload(buf, buf->b_orig_mode); + } redraw_all_later(SOME_VALID); } @@ -5461,13 +5665,13 @@ spell_add_word ( // Initialize 'spellfile' for the current buffer. static void init_spellfile(void) { - char_u *buf; + char_u *buf; int l; - char_u *fname; - char_u *rtp; - char_u *lend; + char_u *fname; + char_u *rtp; + char_u *lend; bool aspath = false; - char_u *lstart = curbuf->b_s.b_p_spl; + char_u *lstart = curbuf->b_s.b_p_spl; if (*curwin->w_s->b_p_spl != NUL && !GA_EMPTY(&curwin->w_s->b_langp)) { buf = xmalloc(MAXPATHL); @@ -5475,31 +5679,33 @@ static void init_spellfile(void) // Find the end of the language name. Exclude the region. If there // is a path separator remember the start of the tail. for (lend = curwin->w_s->b_p_spl; *lend != NUL - && vim_strchr((char_u *)",._", *lend) == NULL; ++lend) + && vim_strchr((char_u *)",._", *lend) == NULL; ++lend) { if (vim_ispathsep(*lend)) { aspath = true; lstart = lend + 1; } + } // Loop over all entries in 'runtimepath'. Use the first one where we // are allowed to write. rtp = p_rtp; while (*rtp != NUL) { - if (aspath) + if (aspath) { // Use directory of an entry with path, e.g., for // "/dir/lg.utf-8.spl" use "/dir". STRLCPY(buf, curbuf->b_s.b_p_spl, - lstart - curbuf->b_s.b_p_spl); - else + lstart - curbuf->b_s.b_p_spl); + } else { // Copy the path from 'runtimepath' to buf[]. copy_option_part(&rtp, buf, MAXPATHL, ","); + } if (os_file_is_writable((char *)buf) == 2) { // Use the first language name from 'spelllang' and the // encoding used in the first loaded .spl file. - if (aspath) + if (aspath) { STRLCPY(buf, curbuf->b_s.b_p_spl, - lend - curbuf->b_s.b_p_spl + 1); - else { + lend - curbuf->b_s.b_p_spl + 1); + } else { // Create the "spell" directory if it doesn't exist yet. l = (int)STRLEN(buf); vim_snprintf((char *)buf + l, MAXPATHL - l, "/spell"); @@ -5509,7 +5715,7 @@ static void init_spellfile(void) l = (int)STRLEN(buf); vim_snprintf((char *)buf + l, MAXPATHL - l, - "/%.*s", (int)(lend - lstart), lstart); + "/%.*s", (int)(lend - lstart), lstart); } l = (int)STRLEN(buf); fname = LANGP_ENTRY(curwin->w_s->b_langp, 0) @@ -5529,19 +5735,16 @@ static void init_spellfile(void) } } -// Set the spell character tables from strings in the .spl file. -static void -set_spell_charflags ( - char_u *flags, - int cnt, // length of "flags" - char_u *fol -) +/// Set the spell character tables from strings in the .spl file. +/// +/// @param cnt length of "flags" +static void set_spell_charflags(char_u *flags, int cnt, char_u *fol) { // We build the new tables here first, so that we can compare with the // previous one. spelltab_T new_st; int i; - char_u *p = fol; + char_u *p = fol; int c; clear_spell_chartab(&new_st); @@ -5555,8 +5758,9 @@ set_spell_charflags ( if (*p != NUL) { c = mb_ptr2char_adv((const char_u **)&p); new_st.st_fold[i + 128] = c; - if (i + 128 != c && new_st.st_isu[i + 128] && c < 256) + if (i + 128 != c && new_st.st_isu[i + 128] && c < 256) { new_st.st_upper[c] = i + 128; + } } } @@ -5593,9 +5797,9 @@ static int write_spell_prefcond(FILE *fd, garray_T *gap) { assert(gap->ga_len >= 0); - if (fd != NULL) + if (fd != NULL) { put_bytes(fd, (uintmax_t)gap->ga_len, 2); // <prefcondcnt> - + } size_t totlen = 2 + (size_t)gap->ga_len; // <prefcondcnt> and <condlen> bytes size_t x = 1; // collect return value of fwrite() for (int i = 0; i < gap->ga_len; ++i) { @@ -5609,8 +5813,9 @@ static int write_spell_prefcond(FILE *fd, garray_T *gap) x &= fwrite(p, len, 1, fd); } totlen += len; - } else if (fd != NULL) + } else if (fd != NULL) { fputc(0, fd); + } } assert(totlen <= INT_MAX); @@ -5620,7 +5825,7 @@ static int write_spell_prefcond(FILE *fd, garray_T *gap) // Use map string "map" for languages "lp". static void set_map_str(slang_T *lp, char_u *map) { - char_u *p; + char_u *p; int headc = 0; int c; int i; @@ -5632,8 +5837,9 @@ static void set_map_str(slang_T *lp, char_u *map) lp->sl_has_map = true; // Init the array and hash tables empty. - for (i = 0; i < 256; ++i) + for (i = 0; i < 256; ++i) { lp->sl_map_array[i] = 0; + } hash_init(&lp->sl_map_hash); // The similar characters are stored separated with slashes: @@ -5654,9 +5860,9 @@ static void set_map_str(slang_T *lp, char_u *map) if (c >= 256) { int cl = mb_char2len(c); int headcl = mb_char2len(headc); - char_u *b; + char_u *b; hash_T hash; - hashitem_T *hi; + hashitem_T *hi; b = xmalloc(cl + headcl + 2); utf_char2bytes(c, b); @@ -5673,8 +5879,9 @@ static void set_map_str(slang_T *lp, char_u *map) EMSG(_("E783: duplicate char in MAP entry")); xfree(b); } - } else + } else { lp->sl_map_array[c] = headc; + } } } } diff --git a/src/nvim/syntax.c b/src/nvim/syntax.c index 760c7c0ecc..d2c94d9fe8 100644 --- a/src/nvim/syntax.c +++ b/src/nvim/syntax.c @@ -383,7 +383,7 @@ static int current_line_id = 0; // unique number for current line #define CUR_STATE(idx) ((stateitem_T *)(current_state.ga_data))[idx] static bool syn_time_on = false; -# define IF_SYN_TIME(p) (p) +#define IF_SYN_TIME(p) (p) // Set the timeout used for syntax highlighting. // Use NULL to reset, no timeout. @@ -578,7 +578,7 @@ void syntax_start(win_T *wp, linenr_T lnum) static void clear_syn_state(synstate_T *p) { if (p->sst_stacksize > SST_FIX_STATES) { -# define UNREF_BUFSTATE_EXTMATCH(bs) unref_extmatch((bs)->bs_extmatch) +#define UNREF_BUFSTATE_EXTMATCH(bs) unref_extmatch((bs)->bs_extmatch) GA_DEEP_CLEAR(&(p->sst_union.sst_ga), bufstate_T, UNREF_BUFSTATE_EXTMATCH); } else { for (int i = 0; i < p->sst_stacksize; i++) { @@ -592,7 +592,7 @@ static void clear_syn_state(synstate_T *p) */ static void clear_current_state(void) { -# define UNREF_STATEITEM_EXTMATCH(si) unref_extmatch((si)->si_extmatch) +#define UNREF_STATEITEM_EXTMATCH(si) unref_extmatch((si)->si_extmatch) GA_DEEP_CLEAR(¤t_state, stateitem_T, UNREF_STATEITEM_EXTMATCH); } diff --git a/src/nvim/tui/tui.c b/src/nvim/tui/tui.c index fb5e12c20e..803ff23cea 100644 --- a/src/nvim/tui/tui.c +++ b/src/nvim/tui/tui.c @@ -59,12 +59,12 @@ #define LINUXSET1C "\x1b[?1c" #ifdef NVIM_UNIBI_HAS_VAR_FROM -#define UNIBI_SET_NUM_VAR(var, num) \ +# define UNIBI_SET_NUM_VAR(var, num) \ do { \ (var) = unibi_var_from_num((num)); \ } while (0) #else -#define UNIBI_SET_NUM_VAR(var, num) (var).i = (num); +# define UNIBI_SET_NUM_VAR(var, num) (var).i = (num); #endif typedef struct { @@ -1483,7 +1483,7 @@ static void tui_guess_size(UI *ui) height = unibi_get_num(data->ut, unibi_lines); width = unibi_get_num(data->ut, unibi_columns); -end: + end: if (width <= 0 || height <= 0) { // use the defaults width = DFLT_COLS; @@ -2111,14 +2111,14 @@ static void flush_buf(UI *ui) static const char *tui_get_stty_erase(void) { static char stty_erase[2] = { 0 }; -#if defined(HAVE_TERMIOS_H) +# if defined(HAVE_TERMIOS_H) struct termios t; if (tcgetattr(input_global_fd(), &t) != -1) { stty_erase[0] = (char)t.c_cc[VERASE]; stty_erase[1] = '\0'; DLOG("stty/termios:erase=%s", stty_erase); } -#endif +# endif return stty_erase; } diff --git a/src/nvim/viml/parser/expressions.c b/src/nvim/viml/parser/expressions.c index c2aa923c49..39687a8e8d 100644 --- a/src/nvim/viml/parser/expressions.c +++ b/src/nvim/viml/parser/expressions.c @@ -936,7 +936,7 @@ static const char *intchar2str(const int ch) } #ifdef UNIT_TESTING -#include <stdio.h> +# include <stdio.h> REAL_FATTR_UNUSED static inline void viml_pexpr_debug_print_ast_node(const ExprASTNode *const *const eastnode_p, @@ -971,14 +971,14 @@ static inline void viml_pexpr_debug_print_token(const ParserState *const pstate, { fprintf(stderr, "\ntkn: %s\n", viml_pexpr_repr_token(pstate, token, NULL)); } -#define PSTACK(msg) \ +# define PSTACK(msg) \ viml_pexpr_debug_print_ast_stack(&ast_stack, #msg) -#define PSTACK_P(msg) \ +# define PSTACK_P(msg) \ viml_pexpr_debug_print_ast_stack(ast_stack, #msg) -#define PNODE_P(eastnode_p, msg) \ +# define PNODE_P(eastnode_p, msg) \ viml_pexpr_debug_print_ast_node((const ExprASTNode *const *)eastnode_p, \ (#msg)) -#define PTOKEN(tkn) \ +# define PTOKEN(tkn) \ viml_pexpr_debug_print_token(pstate, tkn) #endif diff --git a/src/nvim/window.c b/src/nvim/window.c index 400962f993..c0f537aab3 100644 --- a/src/nvim/window.c +++ b/src/nvim/window.c @@ -62,7 +62,7 @@ #define NOWIN (win_T *)-1 // non-existing window -# define ROWS_AVAIL (Rows - p_ch - tabline_height()) +#define ROWS_AVAIL (Rows - p_ch - tabline_height()) /// flags for win_enter_ext() typedef enum { @@ -90,7 +90,7 @@ void do_window(int nchar, long Prenum, int xchar) Prenum1 = Prenum == 0 ? 1 : Prenum; -# define CHECK_CMDWIN \ +#define CHECK_CMDWIN \ do { \ if (cmdwin_type != 0) { \ EMSG(_(e_cmdwin)); \ diff --git a/src/uncrustify.cfg b/src/uncrustify.cfg index 821fbca3fc..5d73e70ed0 100644 --- a/src/uncrustify.cfg +++ b/src/uncrustify.cfg @@ -1,4 +1,4 @@ -# Uncrustify-0.73.0-181-847f1e99 +# Uncrustify-0.73.0-186-03faf73c # # General options @@ -787,7 +787,7 @@ sp_sign = ignore # ignore/add/remove/force/not_defined # applied, as in '(--x)' or 'y++;'. # # Default: remove -sp_incdec = ignore # ignore/add/remove/force/not_defined +sp_incdec = remove # ignore/add/remove/force/not_defined # Add or remove space before a backslash-newline at the end of a line. # @@ -3041,7 +3041,7 @@ mod_sort_oc_property_nullability_weight = 0 # number # Add or remove indentation of preprocessor directives inside #if blocks # at brace level 0 (file-level). -pp_indent = ignore # ignore/add/remove/force/not_defined +pp_indent = remove # ignore/add/remove/force/not_defined # Whether to indent #if/#else/#endif at the brace level. If false, these are # indented from column 1. @@ -3056,7 +3056,7 @@ pp_indent_at_level = false # true/false pp_indent_count = 1 # unsigned number # Add or remove space after # based on pp_level of #if blocks. -pp_space = ignore # ignore/add/remove/force/not_defined +pp_space = force # ignore/add/remove/force/not_defined # Sets the number of spaces per level added with pp_space. pp_space_count = 0 # unsigned number @@ -3267,29 +3267,29 @@ debug_truncate = 0 # unsigned number # `macro-close END_MESSAGE_MAP` # # -set PREPROC FUNC_API_CHECK_TEXTLOCK -set PREPROC FUNC_API_DEPRECATED_SINCE -set PREPROC FUNC_API_FAST -set PREPROC FUNC_API_LUA_ONLY -set PREPROC FUNC_API_NOEXPORT -set PREPROC FUNC_API_REMOTE_ONLY -set PREPROC FUNC_API_SINCE -set PREPROC FUNC_ATTR_ALWAYS_INLINE -set PREPROC FUNC_ATTR_CONST -set PREPROC FUNC_ATTR_MALLOC -set PREPROC FUNC_ATTR_NONNULL_ALL -set PREPROC FUNC_ATTR_NONNULL_ARG -set PREPROC FUNC_ATTR_NONNULL_RET -set PREPROC FUNC_ATTR_NORETURN -set PREPROC FUNC_ATTR_NO_SANITIZE_UNDEFINED -set PREPROC FUNC_ATTR_PRINTF -set PREPROC FUNC_ATTR_PURE -set PREPROC FUNC_ATTR_UNUSED -set PREPROC FUNC_ATTR_WARN_UNUSED_RESULT -set PREPROC REAL_FATTR_ALWAYS_INLINE -set PREPROC REAL_FATTR_CONST -set PREPROC REAL_FATTR_NONNULL_ALL -set PREPROC REAL_FATTR_PURE -set PREPROC REAL_FATTR_WARN_UNUSED_RESULT -# option(s) with 'not default' value: 61 +set QUESTION FUNC_API_CHECK_TEXTLOCK +set QUESTION FUNC_API_DEPRECATED_SINCE +set QUESTION FUNC_API_FAST +set QUESTION FUNC_API_LUA_ONLY +set QUESTION FUNC_API_NOEXPORT +set QUESTION FUNC_API_REMOTE_ONLY +set QUESTION FUNC_API_SINCE +set QUESTION FUNC_ATTR_ALWAYS_INLINE +set QUESTION FUNC_ATTR_CONST +set QUESTION FUNC_ATTR_MALLOC +set QUESTION FUNC_ATTR_NONNULL_ALL +set QUESTION FUNC_ATTR_NONNULL_ARG +set QUESTION FUNC_ATTR_NONNULL_RET +set QUESTION FUNC_ATTR_NORETURN +set QUESTION FUNC_ATTR_NO_SANITIZE_UNDEFINED +set QUESTION FUNC_ATTR_PRINTF +set QUESTION FUNC_ATTR_PURE +set QUESTION FUNC_ATTR_UNUSED +set QUESTION FUNC_ATTR_WARN_UNUSED_RESULT +set QUESTION REAL_FATTR_ALWAYS_INLINE +set QUESTION REAL_FATTR_CONST +set QUESTION REAL_FATTR_NONNULL_ALL +set QUESTION REAL_FATTR_PURE +set QUESTION REAL_FATTR_WARN_UNUSED_RESULT +# option(s) with 'not default' value: 62 # |