diff options
92 files changed, 1122 insertions, 1025 deletions
diff --git a/.editorconfig b/.editorconfig index 5a5fba37ac..2aa956b1fc 100644 --- a/.editorconfig +++ b/.editorconfig @@ -6,14 +6,10 @@ indent_size = 2 tab_width = 8 end_of_line = lf insert_final_newline = true -charset = utf-8 [*.{c,h,in,lua}] max_line_length = 100 -[*.{vim,po}] -charset = unset - [{Makefile,**/Makefile,runtime/doc/*.txt}] indent_style = tab indent_size = 8 diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 87c270afbe..804feec68b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -47,7 +47,6 @@ jobs: cmake \ flake8 \ gettext \ - gperf \ libluajit-5.1-dev \ libmsgpack-dev \ libtermkey-dev \ @@ -163,7 +162,7 @@ jobs: if: matrix.os == 'linux' run: | sudo apt-get update - sudo apt-get install -y autoconf automake build-essential ccache cmake cpanminus cscope gcc-multilib gdb gettext gperf language-pack-tr libtool-bin locales ninja-build pkg-config python3 python3-pip python3-setuptools unzip valgrind xclip + sudo apt-get install -y autoconf automake build-essential ccache cmake cpanminus cscope gcc-multilib gdb gettext language-pack-tr libtool-bin locales ninja-build pkg-config python3 python3-pip python3-setuptools unzip valgrind xclip - name: Install minimum required version of cmake if: matrix.cmake == 'minimum_required' diff --git a/.github/workflows/coverity-scan.yml b/.github/workflows/coverity-scan.yml index 7c885f8b88..90fe676649 100644 --- a/.github/workflows/coverity-scan.yml +++ b/.github/workflows/coverity-scan.yml @@ -13,7 +13,7 @@ jobs: - name: Install dependencies run: | sudo apt-get update - sudo apt-get install -y autoconf automake build-essential cmake gettext gperf libtool-bin locales ninja-build pkg-config unzip + sudo apt-get install -y autoconf automake build-essential cmake gettext libtool-bin locales ninja-build pkg-config unzip - name: Download Coverity run: | diff --git a/.github/workflows/env.sh b/.github/workflows/env.sh index ca1194efa9..fe7543510e 100755 --- a/.github/workflows/env.sh +++ b/.github/workflows/env.sh @@ -25,7 +25,7 @@ CCACHE_SLOPPINESS=time_macros,file_macro CCACHE_DIR=$HOME/.ccache EOF -DEPS_CMAKE_FLAGS=-DUSE_BUNDLED_GPERF=OFF +DEPS_CMAKE_FLAGS= FUNCTIONALTEST=functionaltest BUILD_FLAGS="CMAKE_FLAGS=-DCI_BUILD=ON -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX:PATH=$HOME/nvim-install -DBUSTED_OUTPUT_TYPE=nvim -DDEPS_PREFIX=$HOME/nvim-deps/usr -DMIN_LOG_LEVEL=3" diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index be93cd0245..a95b57a657 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -27,7 +27,7 @@ jobs: - name: Install dependencies run: | sudo apt-get update - sudo apt-get install -y autoconf automake build-essential cmake gcc-11 gettext gperf libtool-bin locales ninja-build pkg-config unzip + sudo apt-get install -y autoconf automake build-essential cmake gcc-11 gettext libtool-bin locales ninja-build pkg-config unzip - if: github.event_name == 'push' || (github.event_name == 'workflow_dispatch' && github.event.inputs.tag_name != 'nightly') run: printf 'NVIM_BUILD_TYPE=Release\n' >> $GITHUB_ENV - if: github.event_name == 'schedule' || (github.event_name == 'workflow_dispatch' && github.event.inputs.tag_name == 'nightly') @@ -61,7 +61,7 @@ jobs: - name: Install dependencies run: | sudo apt-get update - sudo apt-get install -y autoconf automake build-essential cmake gcc-11 gettext gperf libtool-bin locales ninja-build pkg-config unzip + sudo apt-get install -y autoconf automake build-essential cmake gcc-11 gettext libtool-bin locales ninja-build pkg-config unzip - if: github.event_name == 'push' || (github.event_name == 'workflow_dispatch' && github.event.inputs.tag_name != 'nightly') run: CC=gcc-11 make appimage-latest - if: github.event_name == 'schedule' || (github.event_name == 'workflow_dispatch' && github.event.inputs.tag_name == 'nightly') diff --git a/.travis.yml b/.travis.yml index ec7e19b2f9..e52b53bf90 100644 --- a/.travis.yml +++ b/.travis.yml @@ -37,7 +37,6 @@ env: -DBUSTED_OUTPUT_TYPE=nvim -DDEPS_PREFIX=$DEPS_BUILD_DIR/usr -DMIN_LOG_LEVEL=3" - - DEPS_CMAKE_FLAGS="-DUSE_BUNDLED_GPERF=OFF" # Environment variables for Clang sanitizers. - ASAN_OPTIONS="detect_leaks=1:check_initialization_order=1:log_path=$LOG_DIR/asan" - TSAN_OPTIONS="log_path=$LOG_DIR/tsan" @@ -75,7 +74,6 @@ addons: - cscope - gcc-multilib - gdb - - gperf - language-pack-tr - libtool-bin - locales diff --git a/CMakeLists.txt b/CMakeLists.txt index 01df172ed4..409face71c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -614,7 +614,6 @@ endif() find_program(LUACHECK_PRG luacheck) find_program(FLAKE8_PRG flake8) -find_program(GPERF_PRG gperf) include(InstallHelpers) diff --git a/runtime/autoload/man.vim b/runtime/autoload/man.vim index 4d6a1f78dc..065ca8432e 100644 --- a/runtime/autoload/man.vim +++ b/runtime/autoload/man.vim @@ -125,9 +125,7 @@ endfunction function! s:set_options(pager) abort setlocal noswapfile buftype=nofile bufhidden=hide setlocal nomodified readonly nomodifiable - if a:pager - nnoremap <silent> <buffer> <nowait> q :lclose<CR>:q<CR> - endif + let b:pager = a:pager setlocal filetype=man endfunction diff --git a/runtime/compiler/scdoc.vim b/runtime/compiler/scdoc.vim index 2f6edc6322..c37969f89c 100644 --- a/runtime/compiler/scdoc.vim +++ b/runtime/compiler/scdoc.vim @@ -1,7 +1,8 @@ " scdoc compiler for Vim " Compiler: scdoc -" Maintainer: Greg Anders <greg@gpanders.com> +" Maintainer: Gregory Anders <contact@gpanders.com> " Last Updated: 2019-10-24 +" Upstream: https://github.com/gpanders/vim-scdoc if exists('current_compiler') finish diff --git a/runtime/doc/eval.txt b/runtime/doc/eval.txt index 63a5b69070..d1686741b4 100644 --- a/runtime/doc/eval.txt +++ b/runtime/doc/eval.txt @@ -3137,10 +3137,13 @@ text... :for {var} in {object} *:for* *E690* *E732* :endfo[r] *:endfo* *:endfor* Repeat the commands between `:for` and `:endfor` for - each item in {object}. {object} can be a |List| or - a |Blob|. Variable {var} is set to the value of each - item. When an error is detected for a command inside - the loop, execution continues after the `endfor`. + each item in {object}. {object} can be a |List|, + a |Blob| or a |String|. + + Variable {var} is set to the value of each item. + + When an error is detected for a command inside the + loop, execution continues after the `endfor`. Changing {object} inside the loop affects what items are used. Make a copy if this is unwanted: > :for item in copy(mylist) diff --git a/runtime/doc/pattern.txt b/runtime/doc/pattern.txt index 35f5b311ff..371a210847 100644 --- a/runtime/doc/pattern.txt +++ b/runtime/doc/pattern.txt @@ -71,12 +71,18 @@ N Repeat the latest "/" or "?" [count] times in Only whole keywords are searched for, like with the command "/\<keyword\>". |exclusive| 'ignorecase' is used, 'smartcase' is not. + *v_star-default* + In Visual mode, search forward for the current selection. + |default-mappings| *#* # Same as "*", but search backward. The pound sign (character 163) also works. If the "#" key works as backspace, try using "stty erase <BS>" before starting Vim (<BS> is CTRL-H or a real backspace). + *v_#-default* + In Visual mode, search backward for the current selection. + |default-mappings| *gstar* g* Like "*", but don't put "\<" and "\>" around the word. diff --git a/runtime/doc/syntax.txt b/runtime/doc/syntax.txt index 2a78d975ee..0aceb30ce0 100644 --- a/runtime/doc/syntax.txt +++ b/runtime/doc/syntax.txt @@ -453,7 +453,7 @@ your own highlight colors for the progress bar. Example: > hi TOhtmlProgress guifg=#c0ffee ctermbg=7 < *g:html_number_lines* -Default: current 'number' setting. +Default: Current 'number' setting. When 0, buffer text is displayed in the generated HTML without line numbering. When 1, a column of line numbers is added to the generated HTML with the same highlighting as the line number column in Vim (|hl-LineNr|). @@ -542,7 +542,7 @@ folded text will open the fold as if |g:html_hover_unfold| were set. :let g:html_no_foldcolumn = 1 < *TOhtml-uncopyable-text* *g:html_prevent_copy* -Default: empty string. +Default: Empty string. This option prevents certain regions of the generated HTML from being copied, when you select all text in document rendered in a browser and copy it. Useful for allowing users to copy-paste only the source text even if a fold column or @@ -568,7 +568,7 @@ uncopyable regions. In some browsers, especially older browsers, after selecting an entire page and copying the selection, the <input> tags are not pasted with the page text. If |g:html_no_invalid| is 0, the <input> tags have invalid type; this works in more browsers, but the page will not validate. -Note: this method does NOT work in recent versions of Chrome and equivalent +Note: This method does NOT work in recent versions of Chrome and equivalent browsers; the <input> tags get pasted with the text. When "fallback" (default value), the same <input> elements are generated for @@ -624,12 +624,12 @@ To append a string "_mystring" to the end of each ID: > :let g:html_id_expr = '"_mystring"' < -Note, when converting a diff view to HTML, the expression will only be +Note: When converting a diff view to HTML, the expression will only be evaluated for the first window in the diff, and the result used for all the windows. *TOhtml-wrap-text* *g:html_pre_wrap* -Default: current 'wrap' setting. +Default: Current 'wrap' setting. When 0, if |g:html_no_pre| is 0 or unset, the text in the generated HTML does not wrap at the edge of the browser window. When 1, if |g:html_use_css| is 1, the CSS 2.0 "white-space:pre-wrap" value is @@ -689,7 +689,7 @@ wide browser support. However, you can override this to support specific encodings that may not be automatically detected by default (see options below). See http://www.iana.org/assignments/character-sets for the IANA names. -Note, by default all Unicode encodings are converted to UTF-8 with no BOM in +Note: By default all Unicode encodings are converted to UTF-8 with no BOM in the generated HTML, as recommended by W3C: http://www.w3.org/International/questions/qa-choosing-encodings @@ -1293,8 +1293,8 @@ the global or buffer-local variable load_doxygen_syntax. This is done by adding the following to your vimrc. > :let g:load_doxygen_syntax=1 -There are a couple of variables that have an effect on syntax highlighting, and -are to do with non-standard highlighting options. +There are a couple of variables that have an effect on syntax highlighting, +and are to do with non-standard highlighting options. Variable Default Effect ~ g:doxygen_enhanced_color @@ -1436,8 +1436,8 @@ To enable highlighting some special atoms, put this in your vimrc: > ELIXIR *elixir.vim* *ft-elixir-syntax* -Elixir is a dynamic, functional language for building scalable and maintainable -applications. +Elixir is a dynamic, functional language for building scalable and +maintainable applications. The following file extensions are auto-detected as Elixir file types: @@ -1453,7 +1453,7 @@ Elixir. FLEXWIKI *flexwiki.vim* *ft-flexwiki-syntax* FlexWiki is an ASP.NET-based wiki package available at http://www.flexwiki.com -NOTE: this site currently doesn't work, on Wikipedia is mentioned that +NOTE: This site currently doesn't work, on Wikipedia is mentioned that development stopped in 2009. Syntax highlighting is available for the most common elements of FlexWiki @@ -1533,8 +1533,8 @@ syntax highlighting will not be correct if the form is incorrectly set. When you create a new fortran file, the syntax script assumes fixed source form. If you always use free source form, then > :let fortran_free_source=1 -in your vimrc prior to the :syntax on command. If you always use fixed source -form, then > +in your vimrc prior to the :syntax on command. If you always use fixed +source form, then > :let fortran_fixed_source=1 in your vimrc prior to the :syntax on command. @@ -1807,8 +1807,8 @@ ends with -->) you can define > JavaScript and Visual Basic embedded inside HTML documents are highlighted as 'Special' with statements, comments, strings and so on colored as in standard -programming languages. Note that only JavaScript and Visual Basic are currently -supported, no other scripting language has been added yet. +programming languages. Note that only JavaScript and Visual Basic are +currently supported, no other scripting language has been added yet. Embedded and inlined cascading style sheets (CSS) are highlighted too. @@ -1912,8 +1912,8 @@ The java.vim syntax highlighting file offers several options: In Java 1.0.2 it was never possible to have braces inside parens, so this was flagged as an error. Since Java 1.1 this is possible (with anonymous -classes), and therefore is no longer marked as an error. If you prefer the old -way, put the following line into your vim startup file: > +classes), and therefore is no longer marked as an error. If you prefer the +old way, put the following line into your vim startup file: > :let java_mark_braces_in_parens_as_errors=1 All identifiers in java.lang.* are always visible in all classes. To @@ -2031,10 +2031,10 @@ LISP *lisp.vim* *ft-lisp-syntax* The lisp syntax highlighting provides two options: > - g:lisp_instring : if it exists, then "(...)" strings are highlighted + g:lisp_instring : If it exists, then "(...)" strings are highlighted as if the contents of the string were lisp. Useful for AutoLisp. - g:lisp_rainbow : if it exists and is nonzero, then differing levels + g:lisp_rainbow : If it exists and is nonzero, then differing levels of parenthesization will receive different highlighting. < @@ -2440,8 +2440,8 @@ If you do not want complex things like '@{${"foo"}}' to be parsed: > (In Vim 6.x it was the other way around: "perl_extended_vars" enabled it.) -The coloring strings can be changed. By default strings and qq friends will be -highlighted like the first line. If you set the variable +The coloring strings can be changed. By default strings and qq friends will +be highlighted like the first line. If you set the variable perl_string_as_statement, it will be highlighted as in the second line. "hello world!"; qq|hello world|; @@ -2453,8 +2453,8 @@ perl_string_as_statement, it will be highlighted as in the second line. The syncing has 3 options. The first two switch off some triggering of synchronization and should only be needed in case it fails to work properly. If while scrolling all of a sudden the whole screen changes color completely -then you should try and switch off one of those. Let me know if you can figure -out the line that causes the mistake. +then you should try and switch off one of those. Let me know if you can +figure out the line that causes the mistake. One triggers on "^\s*sub\s*" and the other on "^[$@%]" more or less. > @@ -2491,7 +2491,7 @@ behavior, set 'perl_nofold_packages': > PHP3 and PHP4 *php.vim* *php3.vim* *ft-php-syntax* *ft-php3-syntax* -[note: previously this was called "php3", but since it now also supports php4 +[Note: Previously this was called "php3", but since it now also supports php4 it has been renamed to "php"] There are the following options for the php syntax highlighting. @@ -2561,15 +2561,15 @@ PPWizard is a preprocessor for HTML and OS/2 INF files This syntax file has the options: -- ppwiz_highlight_defs : determines highlighting mode for PPWizard's +- ppwiz_highlight_defs : Determines highlighting mode for PPWizard's definitions. Possible values are ppwiz_highlight_defs = 1 : PPWizard #define statements retain the - colors of their contents (e.g. PPWizard macros and variables) + colors of their contents (e.g. PPWizard macros and variables). - ppwiz_highlight_defs = 2 : preprocessor #define and #evaluate + ppwiz_highlight_defs = 2 : Preprocessor #define and #evaluate statements are shown in a single color with the exception of line - continuation symbols + continuation symbols. The default setting for ppwiz_highlight_defs is 1. @@ -2608,7 +2608,7 @@ highlighted by defining the postscr_level variable as follows: > If this variable is not defined it defaults to 2 (level 2) since this is the most prevalent version currently. -Note, not all PS interpreters will support all language features for a +Note: Not all PS interpreters will support all language features for a particular language level. In particular the %!PS-Adobe-3.0 at the start of PS files does NOT mean the PostScript present is level 3 PostScript! @@ -2710,7 +2710,7 @@ If you want all possible Python highlighting (the same as setting the preceding last option and unsetting all other ones): > :let python_highlight_all = 1 -Note: only existence of these options matter, not their value. You can replace +Note: Only existence of these options matter, not their value. You can replace 1 above with anything. QUAKE *quake.vim* *ft-quake-syntax* @@ -3150,16 +3150,16 @@ The Speedup syntax file has some options: the DECLARE section; if you defined own types, you have to include them in the syntax file. -- oneline_comments : this value ranges from 1 to 3 and determines the +- oneline_comments : This value ranges from 1 to 3 and determines the highlighting of # style comments. - oneline_comments = 1 : allow normal Speedup code after an even + oneline_comments = 1 : Allow normal Speedup code after an even number of #s. - oneline_comments = 2 : show code starting with the second # as + oneline_comments = 2 : Show code starting with the second # as error. This is the default setting. - oneline_comments = 3 : show the whole line as error if it contains + oneline_comments = 3 : Show the whole line as error if it contains more than one #. Since especially OPERATION sections tend to become very large due to @@ -3198,8 +3198,8 @@ This covers the shell named "tcsh". It is a superset of csh. See |csh.vim| for how the filetype is detected. Tcsh does not allow \" in strings unless the "backslash_quote" shell variable -is set. If you want VIM to assume that no backslash quote constructs exist add -this line to your vimrc: > +is set. If you want VIM to assume that no backslash quote constructs exist +add this line to your vimrc: > :let tcsh_backslash_quote = 0 @@ -3552,7 +3552,7 @@ start and end tags. This can be turned on by > :let g:xml_syntax_folding = 1 :set foldmethod=syntax -Note: syntax folding might slow down syntax highlighting significantly, +Note: Syntax folding might slow down syntax highlighting significantly, especially for large files. @@ -4982,8 +4982,8 @@ ctermbg={color-nr} *highlight-ctermbg* a number instead of a color name. Note that for 16 color ansi style terminals (including xterms), the - numbers in the NR-8 column is used. Here '*' means 'add 8' so that Blue - is 12, DarkGray is 8 etc. + numbers in the NR-8 column is used. Here '*' means 'add 8' so that + Blue is 12, DarkGray is 8 etc. Note that for some color terminals these names may result in the wrong colors! @@ -5096,56 +5096,56 @@ These are the builtin highlighting groups. Note that the highlighting depends on the value of 'background'. You can see the current settings with the ":highlight" command. *hl-ColorColumn* -ColorColumn used for the columns set with 'colorcolumn' +ColorColumn Used for the columns set with 'colorcolumn'. *hl-Conceal* -Conceal placeholder characters substituted for concealed - text (see 'conceallevel') +Conceal Placeholder characters substituted for concealed + text (see 'conceallevel'). *hl-CurSearch* -CurSearch used for highlighting a search pattern under the cursor - (see 'hlsearch') +CurSearch Used for highlighting a search pattern under the cursor + (see 'hlsearch'). *hl-Cursor* -Cursor character under the cursor -lCursor the character under the cursor when |language-mapping| - is used (see 'guicursor') +Cursor Character under the cursor. +lCursor Character under the cursor when |language-mapping| + is used (see 'guicursor'). *hl-CursorIM* -CursorIM like Cursor, but used when in IME mode |CursorIM| +CursorIM Like Cursor, but used when in IME mode. |CursorIM| *hl-CursorColumn* CursorColumn Screen-column at the cursor, when 'cursorcolumn' is set. *hl-CursorLine* CursorLine Screen-line at the cursor, when 'cursorline' is set. Low-priority if foreground (ctermfg OR guifg) is not set. *hl-Directory* -Directory directory names (and other special names in listings) +Directory Directory names (and other special names in listings). *hl-DiffAdd* -DiffAdd diff mode: Added line |diff.txt| +DiffAdd Diff mode: Added line. |diff.txt| *hl-DiffChange* -DiffChange diff mode: Changed line |diff.txt| +DiffChange Diff mode: Changed line. |diff.txt| *hl-DiffDelete* -DiffDelete diff mode: Deleted line |diff.txt| +DiffDelete Diff mode: Deleted line. |diff.txt| *hl-DiffText* -DiffText diff mode: Changed text within a changed line |diff.txt| +DiffText Diff mode: Changed text within a changed line. |diff.txt| *hl-EndOfBuffer* -EndOfBuffer filler lines (~) after the end of the buffer. +EndOfBuffer Filler lines (~) after the end of the buffer. By default, this is highlighted like |hl-NonText|. *hl-TermCursor* -TermCursor cursor in a focused terminal +TermCursor Cursor in a focused terminal. *hl-TermCursorNC* -TermCursorNC cursor in an unfocused terminal +TermCursorNC Cursor in an unfocused terminal. *hl-ErrorMsg* -ErrorMsg error messages on the command line +ErrorMsg Error messages on the command line. *hl-WinSeparator* -WinSeparator separators between window splits +WinSeparator Separators between window splits. *hl-Folded* -Folded line used for closed folds +Folded Line used for closed folds. *hl-FoldColumn* FoldColumn 'foldcolumn' *hl-SignColumn* -SignColumn column where |signs| are displayed +SignColumn Column where |signs| are displayed. *hl-IncSearch* IncSearch 'incsearch' highlighting; also used for the text replaced with - ":s///c" + ":s///c". *hl-Substitute* -Substitute |:substitute| replacement text highlighting +Substitute |:substitute| replacement text highlighting. *hl-LineNr* LineNr Line number for ":number" and ":#" commands, and when 'number' @@ -5164,15 +5164,15 @@ CursorLineSign Like SignColumn when 'cursorline' is set for the cursor line. *hl-CursorLineFold* CursorLineFold Like FoldColumn when 'cursorline' is set for the cursor line. *hl-MatchParen* -MatchParen The character under the cursor or just before it, if it +MatchParen Character under the cursor or just before it, if it is a paired bracket, and its match. |pi_paren.txt| *hl-ModeMsg* -ModeMsg 'showmode' message (e.g., "-- INSERT --") +ModeMsg 'showmode' message (e.g., "-- INSERT --"). *hl-MsgArea* -MsgArea Area for messages and cmdline +MsgArea Area for messages and cmdline. *hl-MsgSeparator* -MsgSeparator Separator for scrolled messages, `msgsep` flag of 'display' +MsgSeparator Separator for scrolled messages, `msgsep` flag of 'display'. *hl-MoreMsg* MoreMsg |more-prompt| *hl-NonText* @@ -5181,21 +5181,21 @@ NonText '@' at the end of the window, characters from 'showbreak' (e.g., ">" displayed when a double-wide character doesn't fit at the end of the line). See also |hl-EndOfBuffer|. *hl-Normal* -Normal normal text +Normal Normal text. *hl-NormalFloat* NormalFloat Normal text in floating windows. *hl-NormalNC* -NormalNC normal text in non-current windows +NormalNC Normal text in non-current windows. *hl-Pmenu* -Pmenu Popup menu: normal item. +Pmenu Popup menu: Normal item. *hl-PmenuSel* -PmenuSel Popup menu: selected item. +PmenuSel Popup menu: Selected item. *hl-PmenuSbar* -PmenuSbar Popup menu: scrollbar. +PmenuSbar Popup menu: Scrollbar. *hl-PmenuThumb* PmenuThumb Popup menu: Thumb of the scrollbar. *hl-Question* -Question |hit-enter| prompt and yes/no questions +Question |hit-enter| prompt and yes/no questions. *hl-QuickFixLine* QuickFixLine Current |quickfix| item in the quickfix window. Combined with |hl-CursorLine| when the cursor is there. @@ -5203,7 +5203,7 @@ QuickFixLine Current |quickfix| item in the quickfix window. Combined with Search Last search pattern highlighting (see 'hlsearch'). Also used for similar items that need to stand out. *hl-SpecialKey* -SpecialKey Unprintable characters: text displayed differently from what +SpecialKey Unprintable characters: Text displayed differently from what it really is. But not 'listchars' whitespace. |hl-Whitespace| *hl-SpellBad* SpellBad Word that is not recognized by the spellchecker. |spell| @@ -5220,30 +5220,30 @@ SpellRare Word that is recognized by the spellchecker as one that is hardly ever used. |spell| Combined with the highlighting used otherwise. *hl-StatusLine* -StatusLine status line of current window +StatusLine Status line of current window. *hl-StatusLineNC* -StatusLineNC status lines of not-current windows - Note: if this is equal to "StatusLine" Vim will use "^^^" in +StatusLineNC Status lines of not-current windows. + Note: If this is equal to "StatusLine", Vim will use "^^^" in the status line of the current window. *hl-TabLine* -TabLine tab pages line, not active tab page label +TabLine Tab pages line, not active tab page label. *hl-TabLineFill* -TabLineFill tab pages line, where there are no labels +TabLineFill Tab pages line, where there are no labels. *hl-TabLineSel* -TabLineSel tab pages line, active tab page label +TabLineSel Tab pages line, active tab page label. *hl-Title* -Title titles for output from ":set all", ":autocmd" etc. +Title Titles for output from ":set all", ":autocmd" etc. *hl-Visual* -Visual Visual mode selection +Visual Visual mode selection. *hl-VisualNOS* VisualNOS Visual mode selection when vim is "Not Owning the Selection". *hl-WarningMsg* -WarningMsg warning messages +WarningMsg Warning messages. *hl-Whitespace* Whitespace "nbsp", "space", "tab", "multispace", "lead" and "trail" - in 'listchars' + in 'listchars'. *hl-WildMenu* -WildMenu current match in 'wildmenu' completion +WildMenu Current match in 'wildmenu' completion. *hl-User1* *hl-User1..9* *hl-User9* The 'statusline' syntax allows the use of 9 different highlights in the diff --git a/runtime/doc/vim_diff.txt b/runtime/doc/vim_diff.txt index 1a3d6022ca..fc98331697 100644 --- a/runtime/doc/vim_diff.txt +++ b/runtime/doc/vim_diff.txt @@ -87,6 +87,8 @@ of these in your config by simply removing the mapping, e.g. ":unmap Y". nnoremap <C-L> <Cmd>nohlsearch<Bar>diffupdate<Bar>normal! <C-L><CR> inoremap <C-U> <C-G>u<C-U> inoremap <C-W> <C-G>u<C-W> + xnoremap * y/\V<C-R>"<CR> + xnoremap # y?\V<C-R>"<CR> < Default Autocommands ~ *default-autocmds* @@ -366,9 +368,8 @@ Macro/|recording| behavior the results of keys from 'keymap'. Mappings: -- Creating a mapping for a simplifiable key (e.g. <C-I>) doesn't replace an + Creating a mapping for a simplifiable key (e.g. <C-I>) doesn't replace an existing mapping for its simplified form (e.g. <Tab>). -- The rhs of a mapping is not simplified when it is defined. Motion: The |jumplist| avoids useless/phantom jumps. diff --git a/runtime/doc/windows.txt b/runtime/doc/windows.txt index cd5425336f..8062b9e28f 100644 --- a/runtime/doc/windows.txt +++ b/runtime/doc/windows.txt @@ -983,7 +983,7 @@ modified, but is forced (with '!') to be removed from a window, and 'autowrite' is off or the buffer can't be written. You can make a hidden buffer not hidden by starting to edit it with any -command. Or by deleting it with the ":bdelete" command. +command, or by deleting it with the ":bdelete" command. The 'hidden' is global, it is used for all buffers. The 'bufhidden' option can be used to make an exception for a specific buffer. It can take these diff --git a/runtime/ftplugin/man.vim b/runtime/ftplugin/man.vim index fce12012b5..d7a08a9941 100644 --- a/runtime/ftplugin/man.vim +++ b/runtime/ftplugin/man.vim @@ -24,7 +24,11 @@ if !exists('g:no_plugin_maps') && !exists('g:no_man_maps') nnoremap <silent> <buffer> k gk nnoremap <silent> <buffer> gO :call man#show_toc()<CR> nnoremap <silent> <buffer> <2-LeftMouse> :Man<CR> - nnoremap <silent> <buffer> <nowait> q :lclose<CR><C-W>c + if get(b:, 'pager') + nnoremap <silent> <buffer> <nowait> q :lclose<CR><C-W>q + else + nnoremap <silent> <buffer> <nowait> q :lclose<CR><C-W>c + endif endif if get(g:, 'ft_man_folding_enable', 0) diff --git a/runtime/ftplugin/scdoc.vim b/runtime/ftplugin/scdoc.vim index 2e98e647f4..552c865baa 100644 --- a/runtime/ftplugin/scdoc.vim +++ b/runtime/ftplugin/scdoc.vim @@ -1,6 +1,7 @@ " scdoc filetype plugin -" Maintainer: Gregory Anders <greg@gpanders.com> -" Last Updated: 2021-08-04 +" Maintainer: Gregory Anders <contact@gpanders.com> +" Last Updated: 2022-05-09 +" Upstream: https://github.com/gpanders/vim-scdoc " Only do this when not done yet for this buffer if exists('b:did_ftplugin') @@ -19,8 +20,3 @@ setlocal softtabstop=0 setlocal textwidth=80 let b:undo_ftplugin = 'setl com< cms< fo< et< sw< sts< tw<' - -if has('conceal') - setlocal conceallevel=2 - let b:undo_ftplugin .= ' cole<' -endif diff --git a/runtime/lua/vim/lsp/buf.lua b/runtime/lua/vim/lsp/buf.lua index 1cfbcd1259..b0bf2c6e5b 100644 --- a/runtime/lua/vim/lsp/buf.lua +++ b/runtime/lua/vim/lsp/buf.lua @@ -691,10 +691,38 @@ end --- `codeAction/resolve` local function on_code_action_results(results, ctx, options) local action_tuples = {} - local filter = options and options.filter + + ---@private + local function action_filter(a) + -- filter by specified action kind + if options and options.context and options.context.only then + if not a.kind then + return false + end + local found = false + for _, o in ipairs(options.context.only) do + -- action kinds are hierachical with . as a separator: when requesting only + -- 'quickfix' this filter allows both 'quickfix' and 'quickfix.foo', for example + if a.kind:find('^' .. o .. '$') or a.kind:find('^' .. o .. '%.') then + found = true + break + end + end + if not found then + return false + end + end + -- filter by user function + if options and options.filter and not options.filter(a) then + return false + end + -- no filter removed this action + return true + end + for client_id, result in pairs(results) do for _, action in pairs(result.result or {}) do - if not filter or filter(action) then + if action_filter(action) then table.insert(action_tuples, { client_id, action }) end end diff --git a/runtime/nvim.desktop b/runtime/nvim.desktop index 052904dd76..224353c6ad 100644 --- a/runtime/nvim.desktop +++ b/runtime/nvim.desktop @@ -1,6 +1,7 @@ [Desktop Entry] Name=Neovim GenericName=Text Editor +GenericName[ckb]=دەستکاریکەری دەق GenericName[de]=Texteditor GenericName[fr]=Éditeur de texte GenericName[ru]=ТекÑтовый редактор @@ -16,6 +17,7 @@ Comment[bg]=Редактиране на текÑтови файлове Comment[bn]=টেকà§à¦¸à§à¦Ÿ ফাইল à¦à¦¡à¦¿à¦Ÿ করà§à¦¨ Comment[bs]=Izmijeni tekstualne datoteke Comment[ca]=Edita fitxers de text +Comment[ckb]=دەستکاریی ÙØ§ÛŒÙ„ÛŒ دەق بکە Comment[cs]=Úprava textových souborů Comment[cy]=Golygu ffeiliau testun Comment[da]=Redigér tekstfiler @@ -79,6 +81,7 @@ Exec=nvim %F Terminal=true Type=Application Keywords=Text;editor; +Keywords[ckb]=دەق;دەستکاریکەر; Keywords[fr]=Texte;éditeur; Keywords[ru]=текÑÑ‚;текÑтовый редактор; Keywords[sr]=ТекÑÑ‚;едитор; diff --git a/runtime/syntax/debchangelog.vim b/runtime/syntax/debchangelog.vim index 8d09af0886..2efd919772 100644 --- a/runtime/syntax/debchangelog.vim +++ b/runtime/syntax/debchangelog.vim @@ -3,7 +3,7 @@ " Maintainer: Debian Vim Maintainers " Former Maintainers: Gerfried Fuchs <alfie@ist.org> " Wichert Akkerman <wakkerma@debian.org> -" Last Change: 2022 Mar 28 +" Last Change: 2022 May 01 " URL: https://salsa.debian.org/vim-team/vim-debian/blob/master/syntax/debchangelog.vim " Standard syntax initialization @@ -24,7 +24,7 @@ let s:supported = [ \ 'jessie', 'stretch', 'buster', 'bullseye', 'bookworm', \ 'trixie', 'sid', 'rc-buggy', \ - \ 'trusty', 'xenial', 'bionic', 'focal', 'impish', 'jammy', + \ 'trusty', 'xenial', 'bionic', 'focal', 'impish', 'jammy', 'kinetic', \ 'devel' \ ] let s:unsupported = [ diff --git a/runtime/syntax/debcontrol.vim b/runtime/syntax/debcontrol.vim index 8b65ece4ca..4c7fb5dd63 100644 --- a/runtime/syntax/debcontrol.vim +++ b/runtime/syntax/debcontrol.vim @@ -3,7 +3,7 @@ " Maintainer: Debian Vim Maintainers " Former Maintainers: Gerfried Fuchs <alfie@ist.org> " Wichert Akkerman <wakkerma@debian.org> -" Last Change: 2021 Nov 26 +" Last Change: 2022 May 11 " URL: https://salsa.debian.org/vim-team/vim-debian/blob/master/syntax/debcontrol.vim " Standard syntax initialization @@ -17,7 +17,7 @@ set cpo&vim " Should match case except for the keys of each field syn case match -syn iskeyword @,48-57,-,/ +syn iskeyword @,48-57,- " Everything that is not explicitly matched by the rules below syn match debcontrolElse "^.*$" diff --git a/runtime/syntax/debsources.vim b/runtime/syntax/debsources.vim index d79ce4b573..e3ec6e6598 100644 --- a/runtime/syntax/debsources.vim +++ b/runtime/syntax/debsources.vim @@ -2,7 +2,7 @@ " Language: Debian sources.list " Maintainer: Debian Vim Maintainers " Former Maintainer: Matthijs Mohlmann <matthijs@cacholong.nl> -" Last Change: 2022 Mar 28 +" Last Change: 2022 May 01 " URL: https://salsa.debian.org/vim-team/vim-debian/blob/master/syntax/debsources.vim " Standard syntax initialization @@ -26,7 +26,7 @@ let s:supported = [ \ 'jessie', 'stretch', 'buster', 'bullseye', 'bookworm', \ 'trixie', 'sid', 'rc-buggy', \ - \ 'trusty', 'xenial', 'bionic', 'focal', 'impish', 'jammy', + \ 'trusty', 'xenial', 'bionic', 'focal', 'impish', 'jammy', 'kinetic', \ 'devel' \ ] let s:unsupported = [ diff --git a/runtime/syntax/scdoc.vim b/runtime/syntax/scdoc.vim index 25c9c5433b..0180f35027 100644 --- a/runtime/syntax/scdoc.vim +++ b/runtime/syntax/scdoc.vim @@ -1,6 +1,7 @@ " Syntax file for scdoc files -" Maintainer: Gregory Anders <greg@gpanders.com> -" Last Updated: 2021-08-04 +" Maintainer: Gregory Anders <contact@gpanders.com> +" Last Updated: 2022-05-09 +" Upstream: https://github.com/gpanders/vim-scdoc if exists('b:current_syntax') finish @@ -20,33 +21,43 @@ syntax match scdocIndentError "^[ ]\+" syntax match scdocLineBreak "++$" -syntax match scdocOrderedListMarker "^\s*\.\%(\s\+\S\)\@=" -syntax match scdocListMarker "^\s*-\%(\s\+\S\)\@=" +syntax region scdocOrderedListItem matchgroup=scdocOrderedListMarker start="^\z(\s*\)\." skip="^\z1 .*$" end="^" contains=scdocBold,scdocUnderline +syntax region scdocListItem matchgroup=scdocListMarker start="^\z(\s*\)-" skip="^\z1 .*$" end="^" contains=scdocBold,scdocUnderline -syntax match scdocTableStartMarker "^[\[|\]][\[\-\]]" -syntax match scdocTableMarker "^[|:][\[\-\] ]" +" Tables cannot start with a column +syntax match scdocTableError "^:" + +syntax region scdocTable matchgroup=scdocTableEntry start="^[\[|\]][\[\-\]<=>]" end="^$" contains=scdocTableEntry,scdocTableError,scdocTableContinuation,scdocBold,scdocUnderline,scdocPre +syntax match scdocTableError "^.*$" contained +syntax match scdocTableContinuation "^ \+\S\+" contained +syntax match scdocTableEntry "^[|:][\[\-\]<=> ]" contained +syntax match scdocTableError "^[|:][\[\-\]<=> ]\S.*$" contained syntax region scdocBold concealends matchgroup=scdocBoldDelimiter start="\\\@<!\*" end="\\\@<!\*" syntax region scdocUnderline concealends matchgroup=scdocUnderlineDelimiter start="\<\\\@<!_" end="\\\@<!_\>" syntax region scdocPre matchgroup=scdocPreDelimiter start="^\t*```" end="^\t*```" -hi link scdocFirstLineValid Comment -hi link scdocComment Comment -hi link scdocHeader Title -hi link scdocOrderedListMarker Statement -hi link scdocListMarker scdocOrderedListMarker -hi link scdocLineBreak Special -hi link scdocTableMarker Statement -hi link scdocTableStartMarker scdocTableMarker - -hi link scdocFirstLineError Error -hi link scdocCommentError Error -hi link scdocHeaderError Error -hi link scdocIndentError Error - -hi link scdocPreDelimiter Delimiter - -hi scdocBold term=bold cterm=bold gui=bold -hi scdocUnderline term=underline cterm=underline gui=underline -hi link scdocBoldDelimiter scdocBold -hi link scdocUnderlineDelimiter scdocUnderline +syntax sync minlines=50 + +hi default link scdocFirstLineValid Comment +hi default link scdocComment Comment +hi default link scdocHeader Title +hi default link scdocOrderedListMarker Statement +hi default link scdocListMarker scdocOrderedListMarker +hi default link scdocLineBreak Special +hi default link scdocTableSpecifier Statement +hi default link scdocTableEntry Statement + +hi default link scdocFirstLineError Error +hi default link scdocCommentError Error +hi default link scdocHeaderError Error +hi default link scdocIndentError Error +hi default link scdocTableError Error +hi default link scdocTableError Error + +hi default link scdocPreDelimiter Delimiter + +hi default scdocBold term=bold cterm=bold gui=bold +hi default scdocUnderline term=underline cterm=underline gui=underline +hi default link scdocBoldDelimiter scdocBold +hi default link scdocUnderlineDelimiter scdocUnderline diff --git a/scripts/lintcommit.lua b/scripts/lintcommit.lua index 6871858a0b..34d1263ff4 100644 --- a/scripts/lintcommit.lua +++ b/scripts/lintcommit.lua @@ -45,8 +45,13 @@ end -- Returns nil if the given commit message is valid, or returns a string -- message explaining why it is invalid. local function validate_commit(commit_message) - local commit_split = vim.split(commit_message, ":") + -- Return nil if the commit message starts with "fixup" as it signifies it's + -- a work in progress and shouldn't be linted yet. + if vim.startswith(commit_message, "fixup") then + return nil + end + local commit_split = vim.split(commit_message, ":") -- Return nil if the type is vim-patch since most of the normal rules don't -- apply. if commit_split[1] == "vim-patch" then @@ -183,6 +188,9 @@ function M._test() ['vim-patch:8.2.3374: Pyret files are not recognized (#15642)'] = true, ['vim-patch:8.1.1195,8.2.{3417,3419}'] = true, ['revert: "ci: use continue-on-error instead of "|| true""'] = true, + ['fixup'] = true, + ['fixup: commit message'] = true, + ['fixup! commit message'] = true, [':no type before colon 1'] = false, [' :no type before colon 2'] = false, [' :no type before colon 3'] = false, diff --git a/src/nvim/CMakeLists.txt b/src/nvim/CMakeLists.txt index e6f70033d0..2a323bdea0 100755 --- a/src/nvim/CMakeLists.txt +++ b/src/nvim/CMakeLists.txt @@ -185,15 +185,8 @@ if(NOT MSVC) set_source_files_properties( ${EXTERNAL_SOURCES} PROPERTIES COMPILE_FLAGS "${COMPILE_FLAGS} -Wno-conversion -Wno-missing-noreturn -Wno-missing-format-attribute -Wno-double-promotion") - # gperf generates ANSI-C with incorrect linkage, ignore it. - check_c_compiler_flag(-Wstatic-in-inline HAS_WSTATIC_IN_INLINE) - if(HAS_WSTATIC_IN_INLINE) - set_source_files_properties( - eval/funcs.c PROPERTIES COMPILE_FLAGS "${COMPILE_FLAGS} -Wno-static-in-inline -Wno-conversion") - else() - set_source_files_properties( - eval/funcs.c PROPERTIES COMPILE_FLAGS "${COMPILE_FLAGS} -Wno-conversion") - endif() + set_source_files_properties( + eval/funcs.c PROPERTIES COMPILE_FLAGS "${COMPILE_FLAGS} -Wno-conversion") endif() if(NOT "${MIN_LOG_LEVEL}" MATCHES "^$") @@ -408,14 +401,9 @@ add_custom_command(OUTPUT ${GENERATED_EX_CMDS_ENUM} ${GENERATED_EX_CMDS_DEFS} DEPENDS ${EX_CMDS_GENERATOR} ${CMAKE_CURRENT_LIST_DIR}/ex_cmds.lua ) -if(NOT GPERF_PRG) - message(FATAL_ERROR "gperf was not found.") -endif() add_custom_command(OUTPUT ${GENERATED_FUNCS} ${FUNCS_DATA} COMMAND ${LUA_PRG} ${FUNCS_GENERATOR} - ${CMAKE_CURRENT_LIST_DIR} ${GENERATED_DIR} ${API_METADATA} ${FUNCS_DATA} - COMMAND ${GPERF_PRG} - ${GENERATED_DIR}/funcs.generated.h.gperf --output-file=${GENERATED_FUNCS} + ${CMAKE_CURRENT_LIST_DIR} ${LUA_SHARED_MODULE_SOURCE} ${GENERATED_DIR} ${API_METADATA} ${FUNCS_DATA} DEPENDS ${FUNCS_GENERATOR} ${CMAKE_CURRENT_LIST_DIR}/eval.lua ${API_METADATA} ) list(APPEND NVIM_GENERATED_FOR_SOURCES diff --git a/src/nvim/autocmd.c b/src/nvim/autocmd.c index c5b576b106..51a0521231 100644 --- a/src/nvim/autocmd.c +++ b/src/nvim/autocmd.c @@ -1521,11 +1521,10 @@ bool apply_autocmds(event_T event, char_u *fname, char_u *fname_io, bool force, /// @param exarg Ex command arguments /// /// @return true if some commands were executed. -bool apply_autocmds_exarg(event_T event, char_u *fname, char_u *fname_io, bool force, buf_T *buf, +bool apply_autocmds_exarg(event_T event, char *fname, char *fname_io, bool force, buf_T *buf, exarg_T *eap) { - return apply_autocmds_group(event, (char *)fname, (char *)fname_io, force, AUGROUP_ALL, buf, - eap); + return apply_autocmds_group(event, fname, fname_io, force, AUGROUP_ALL, buf, eap); } /// Like apply_autocmds(), but handles the caller's retval. If the script @@ -1541,14 +1540,14 @@ bool apply_autocmds_exarg(event_T event, char_u *fname, char_u *fname_io, bool f /// @param[in,out] retval caller's retval /// /// @return true if some autocommands were executed -bool apply_autocmds_retval(event_T event, char_u *fname, char_u *fname_io, bool force, buf_T *buf, +bool apply_autocmds_retval(event_T event, char *fname, char *fname_io, bool force, buf_T *buf, int *retval) { if (should_abort(*retval)) { return false; } - bool did_cmd = apply_autocmds_group(event, (char *)fname, (char *)fname_io, force, + bool did_cmd = apply_autocmds_group(event, fname, fname_io, force, AUGROUP_ALL, buf, NULL); if (did_cmd && aborting()) { *retval = FAIL; @@ -1659,9 +1658,9 @@ bool apply_autocmds_group(event_T event, char *fname, char *fname_io, bool force } // Save the autocmd_* variables and info about the current buffer. - char *save_autocmd_fname = (char *)autocmd_fname; + char *save_autocmd_fname = autocmd_fname; int save_autocmd_bufnr = autocmd_bufnr; - char *save_autocmd_match = (char *)autocmd_match; + char *save_autocmd_match = autocmd_match; int save_autocmd_busy = autocmd_busy; int save_autocmd_nested = autocmd_nested; bool save_changed = curbuf->b_changed; @@ -1675,18 +1674,18 @@ bool apply_autocmds_group(event_T event, char *fname, char *fname_io, bool force || event == EVENT_OPTIONSET || event == EVENT_MODECHANGED) { autocmd_fname = NULL; } else if (fname != NULL && !ends_excmd(*fname)) { - autocmd_fname = (char_u *)fname; + autocmd_fname = fname; } else if (buf != NULL) { - autocmd_fname = buf->b_ffname; + autocmd_fname = (char *)buf->b_ffname; } else { autocmd_fname = NULL; } } else { - autocmd_fname = (char_u *)fname_io; + autocmd_fname = fname_io; } if (autocmd_fname != NULL) { // Allocate MAXPATHL for when eval_vars() resolves the fullpath. - autocmd_fname = vim_strnsave(autocmd_fname, MAXPATHL); + autocmd_fname = xstrnsave(autocmd_fname, MAXPATHL); } // Set the buffer number to be used for <abuf>. @@ -1754,11 +1753,11 @@ bool apply_autocmds_group(event_T event, char *fname, char *fname_io, bool force #endif // Set the name to be used for <amatch>. - autocmd_match = (char_u *)fname; + autocmd_match = fname; // Don't redraw while doing autocommands. RedrawingDisabled++; - char *save_sourcing_name = (char *)sourcing_name; + char *save_sourcing_name = sourcing_name; sourcing_name = NULL; // don't free this one linenr_T save_sourcing_lnum = sourcing_lnum; sourcing_lnum = 0; // no line number here @@ -1793,7 +1792,7 @@ bool apply_autocmds_group(event_T event, char *fname, char *fname_io, bool force did_filetype = true; } - char *tail = (char *)path_tail((char_u *)fname); + char *tail = path_tail(fname); // Find first autocommand that matches AutoPatCmd patcmd; @@ -1860,12 +1859,12 @@ bool apply_autocmds_group(event_T event, char *fname, char *fname_io, bool force filechangeshell_busy = false; autocmd_nested = save_autocmd_nested; xfree(sourcing_name); - sourcing_name = (char_u *)save_sourcing_name; + sourcing_name = save_sourcing_name; sourcing_lnum = save_sourcing_lnum; xfree(autocmd_fname); - autocmd_fname = (char_u *)save_autocmd_fname; + autocmd_fname = save_autocmd_fname; autocmd_bufnr = save_autocmd_bufnr; - autocmd_match = (char_u *)save_autocmd_match; + autocmd_match = save_autocmd_match; current_sctx = save_current_sctx; restore_funccal(); if (do_profiling == PROF_YES) { @@ -1933,7 +1932,7 @@ void block_autocmds(void) { // Remember the value of v:termresponse. if (!is_autocmd_blocked()) { - old_termresponse = (char *)get_vim_var_str(VV_TERMRESPONSE); + old_termresponse = get_vim_var_str(VV_TERMRESPONSE); } autocmd_blocked++; } @@ -1946,7 +1945,7 @@ void unblock_autocmds(void) // the autocommands now. Esp. useful when executing a shell command // during startup (nvim -d). if (!is_autocmd_blocked() - && get_vim_var_str(VV_TERMRESPONSE) != (char_u *)old_termresponse) { + && get_vim_var_str(VV_TERMRESPONSE) != old_termresponse) { apply_autocmds(EVENT_TERMRESPONSE, NULL, NULL, false, curbuf); } } @@ -1979,9 +1978,9 @@ void auto_next_pat(AutoPatCmd *apc, int stop_at_last) if (ap->buflocal_nr == 0 ? match_file_pat(NULL, &ap->reg_prog, - (char_u *)apc->fname, - (char_u *)apc->sfname, - (char_u *)apc->tail, + apc->fname, + apc->sfname, + apc->tail, ap->allow_dirs) : ap->buflocal_nr == apc->arg_bufnr) { const char *const name = event_nr2name(apc->event); @@ -1991,7 +1990,7 @@ void auto_next_pat(AutoPatCmd *apc, int stop_at_last) = (STRLEN(s) + strlen(name) + (size_t)ap->patlen + 1); sourcing_name = xmalloc(sourcing_name_len); - snprintf((char *)sourcing_name, sourcing_name_len, s, name, ap->pat); + snprintf(sourcing_name, sourcing_name_len, s, name, ap->pat); if (p_verbose >= 8) { verbose_enter(); smsg(_("Executing %s"), sourcing_name); @@ -2064,7 +2063,7 @@ static bool call_autocmd_callback(const AutoCmd *ac, const AutoPatCmd *apc) /// Get next autocommand command. /// Called by do_cmdline() to get the next line for ":if". /// @return allocated string, or NULL for end of autocommands. -char_u *getnextac(int c, void *cookie, int indent, bool do_concat) +char *getnextac(int c, void *cookie, int indent, bool do_concat) { // These arguments are required for do_cmdline. (void)c; @@ -2155,7 +2154,7 @@ char_u *getnextac(int c, void *cookie, int indent, bool do_concat) acp->nextcmd = ac->next; } - return (char_u *)retval; + return retval; } /// Return true if there is a matching autocommand for "fname". @@ -2165,12 +2164,13 @@ char_u *getnextac(int c, void *cookie, int indent, bool do_concat) /// @param event event that occurred. /// @param sfname filename the event occurred in. /// @param buf buffer the file is open in -bool has_autocmd(event_T event, char_u *sfname, buf_T *buf) FUNC_ATTR_WARN_UNUSED_RESULT +bool has_autocmd(event_T event, char *sfname, buf_T *buf) + FUNC_ATTR_WARN_UNUSED_RESULT { - char *tail = (char *)path_tail(sfname); + char *tail = path_tail(sfname); bool retval = false; - char *fname = FullName_save((char *)sfname, false); + char *fname = FullName_save(sfname, false); if (fname == NULL) { return false; } @@ -2188,9 +2188,9 @@ bool has_autocmd(event_T event, char_u *sfname, buf_T *buf) FUNC_ATTR_WARN_UNUSE && (ap->buflocal_nr == 0 ? match_file_pat(NULL, &ap->reg_prog, - (char_u *)fname, + fname, sfname, - (char_u *)tail, + tail, ap->allow_dirs) : buf != NULL && ap->buflocal_nr == buf->b_fnum)) { retval = true; @@ -2208,12 +2208,12 @@ bool has_autocmd(event_T event, char_u *sfname, buf_T *buf) FUNC_ATTR_WARN_UNUSE // Function given to ExpandGeneric() to obtain the list of autocommand group // names. -char_u *expand_get_augroup_name(expand_T *xp, int idx) +char *expand_get_augroup_name(expand_T *xp, int idx) { // Required for ExpandGeneric (void)xp; - return (char_u *)augroup_name(idx + 1); + return augroup_name(idx + 1); } /// @param doautocmd true for :doauto*, false for :autocmd @@ -2263,7 +2263,7 @@ char *set_context_in_autocmd(expand_T *xp, char *arg, int doautocmd) } // Function given to ExpandGeneric() to obtain the list of event names. -char_u *expand_get_event_name(expand_T *xp, int idx) +char *expand_get_event_name(expand_T *xp, int idx) { // xp is a required parameter to be used with ExpandGeneric (void)xp; @@ -2273,14 +2273,14 @@ char_u *expand_get_event_name(expand_T *xp, int idx) if (name != NULL) { // skip when not including groups or skip deleted entries if (!autocmd_include_groups || name == get_deleted_augroup()) { - return (char_u *)""; + return ""; } - return (char_u *)name; + return name; } // List event names - return (char_u *)event_names[idx - next_augroup_id].name; + return event_names[idx - next_augroup_id].name; } /// Check whether given autocommand is supported @@ -2373,7 +2373,7 @@ bool au_exists(const char *const arg) FUNC_ATTR_WARN_UNUSED_RESULT && (group == AUGROUP_ALL || ap->group == group) && (pattern == NULL || (buflocal_buf == NULL - ? FNAMECMP(ap->pat, (char_u *)pattern) == 0 + ? FNAMECMP(ap->pat, pattern) == 0 : ap->buflocal_nr == buflocal_buf->b_fnum))) { retval = true; break; @@ -2410,7 +2410,7 @@ int aupat_get_buflocal_nr(char *pat, int patlen) } // "<buffer=123>" - if (skipdigits((char_u *)pat + 8) == (char_u *)pat + patlen - 1) { + if (skipdigits(pat + 8) == pat + patlen - 1) { return atoi(pat + 8); } } @@ -2434,10 +2434,10 @@ void aupat_normalize_buflocal_pat(char *dest, char *pat, int patlen, int bufloca buflocal_nr); } -int autocmd_delete_event(int group, event_T event, char_u *pat) +int autocmd_delete_event(int group, event_T event, char *pat) FUNC_ATTR_NONNULL_ALL { - return do_autocmd_event(event, (char *)pat, false, false, "", true, group); + return do_autocmd_event(event, pat, false, false, "", true, group); } /// Deletes an autocmd by ID. diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c index 2c9f997ac1..18c8a2c250 100644 --- a/src/nvim/buffer.c +++ b/src/nvim/buffer.c @@ -111,8 +111,8 @@ static int read_buffer(int read_stdin, exarg_T *eap, int flags) // the end. This makes it possible to retry when 'fileformat' or // 'fileencoding' was guessed wrong. line_count = curbuf->b_ml.ml_line_count; - retval = readfile(read_stdin ? NULL : curbuf->b_ffname, - read_stdin ? NULL : curbuf->b_fname, + retval = readfile(read_stdin ? NULL : (char *)curbuf->b_ffname, + read_stdin ? NULL : (char *)curbuf->b_fname, line_count, (linenr_T)0, (linenr_T)MAXLNUM, eap, flags | READ_BUFFER, silent); if (retval == OK) { @@ -229,7 +229,7 @@ int open_buffer(int read_stdin, exarg_T *eap, int flags) } #endif - retval = readfile(curbuf->b_ffname, curbuf->b_fname, + retval = readfile((char *)curbuf->b_ffname, (char *)curbuf->b_fname, (linenr_T)0, (linenr_T)0, (linenr_T)MAXLNUM, eap, flags | READ_NEW | (read_fifo ? READ_FIFO : 0), silent); #ifdef UNIX @@ -3175,7 +3175,7 @@ void maketitle(void) SPACE_FOR_FNAME + 1); buf_p += MIN(size, SPACE_FOR_FNAME); } else { - buf_p += transstr_buf((const char *)path_tail(curbuf->b_fname), + buf_p += transstr_buf((const char *)path_tail((char *)curbuf->b_fname), buf_p, SPACE_FOR_FNAME + 1, true); } @@ -3285,7 +3285,7 @@ void maketitle(void) if (buf_spname(curbuf) != NULL) { buf_p = buf_spname(curbuf); } else { // use file name only in icon - buf_p = path_tail(curbuf->b_ffname); + buf_p = (char_u *)path_tail((char *)curbuf->b_ffname); } *icon_str = NUL; // Truncate name at 100 bytes. @@ -3841,7 +3841,7 @@ int build_stl_str_hl(win_T *wp, char *out, size_t outlen, char *fmt, int use_san if (opt != STL_FILENAME) { str = (char *)NameBuff; } else { - str = (char *)path_tail(NameBuff); + str = path_tail((char *)NameBuff); } break; case STL_VIM_EXPR: // '{' @@ -3909,7 +3909,7 @@ int build_stl_str_hl(win_T *wp, char *out, size_t outlen, char *fmt, int use_san // Check if the evaluated result is a number. // If so, convert the number to an int and free the string. if (str != NULL && *str != 0) { - if (*skipdigits((char_u *)str) == NUL) { + if (*skipdigits(str) == NUL) { num = atoi(str); XFREE_CLEAR(str); itemisflag = false; @@ -5201,9 +5201,9 @@ static int chk_modeline(linenr_T lnum, int flags) s = linecopy = vim_strsave(s); // copy the line, it will change save_sourcing_lnum = sourcing_lnum; - save_sourcing_name = sourcing_name; + save_sourcing_name = (char_u *)sourcing_name; sourcing_lnum = lnum; // prepare for emsg() - sourcing_name = (char_u *)"modelines"; + sourcing_name = "modelines"; end = false; while (end == false) { @@ -5259,7 +5259,7 @@ static int chk_modeline(linenr_T lnum, int flags) } sourcing_lnum = save_sourcing_lnum; - sourcing_name = save_sourcing_name; + sourcing_name = (char *)save_sourcing_name; xfree(linecopy); @@ -5594,7 +5594,7 @@ bool buf_contents_changed(buf_T *buf) aucmd_prepbuf(&aco, newbuf); if (ml_open(curbuf) == OK - && readfile(buf->b_ffname, buf->b_fname, + && readfile((char *)buf->b_ffname, (char *)buf->b_fname, (linenr_T)0, (linenr_T)0, (linenr_T)MAXLNUM, &ea, READ_NEW | READ_DUMMY, false) == OK) { // compare the two files line by line diff --git a/src/nvim/change.c b/src/nvim/change.c index 767e6d3837..b15e90e0bc 100644 --- a/src/nvim/change.c +++ b/src/nvim/change.c @@ -557,7 +557,7 @@ void ins_char(int c) if (buf[0] == 0) { buf[0] = '\n'; } - ins_char_bytes(buf, n); + ins_char_bytes((char_u *)buf, n); } void ins_char_bytes(char_u *buf, size_t charlen) diff --git a/src/nvim/charset.c b/src/nvim/charset.c index 5b93973f54..4f6033cbfa 100644 --- a/src/nvim/charset.c +++ b/src/nvim/charset.c @@ -1187,16 +1187,16 @@ intptr_t getwhitecols(const char_u *p) /// @param[in] q String to skip digits in. /// /// @return Pointer to the character after the skipped digits. -char_u *skipdigits(const char_u *q) +char *skipdigits(const char *q) FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ALL FUNC_ATTR_NONNULL_RET { - const char_u *p = q; + const char *p = q; while (ascii_isdigit(*p)) { // skip to next non-digit p++; } - return (char_u *)p; + return (char *)p; } /// skip over binary digits diff --git a/src/nvim/context.c b/src/nvim/context.c index 0e0d8fdfde..db26667009 100644 --- a/src/nvim/context.c +++ b/src/nvim/context.c @@ -129,8 +129,8 @@ bool ctx_restore(Context *ctx, const int flags) free_ctx = true; } - char_u *op_shada; - get_option_value("shada", NULL, (char **)&op_shada, OPT_GLOBAL); + char *op_shada; + get_option_value("shada", NULL, &op_shada, OPT_GLOBAL); set_option_value("shada", 0L, "!,'100,%", OPT_GLOBAL); if (flags & kCtxRegs) { @@ -157,7 +157,7 @@ bool ctx_restore(Context *ctx, const int flags) ctx_free(ctx); } - set_option_value("shada", 0L, (char *)op_shada, OPT_GLOBAL); + set_option_value("shada", 0L, op_shada, OPT_GLOBAL); xfree(op_shada); return true; diff --git a/src/nvim/debugger.c b/src/nvim/debugger.c index 6fab70d4c2..0f76c3e884 100644 --- a/src/nvim/debugger.c +++ b/src/nvim/debugger.c @@ -60,7 +60,7 @@ void do_debug(char_u *cmd) int save_ignore_script = 0; int n; char_u *cmdline = NULL; - char_u *p; + char *p; char *tail = NULL; static int last_cmd = 0; #define CMD_CONT 1 @@ -141,7 +141,7 @@ void do_debug(char_u *cmd) // If this is a debug command, set "last_cmd". // If not, reset "last_cmd". // For a blank line use previous command. - p = (char_u *)skipwhite((char *)cmdline); + p = skipwhite((char *)cmdline); if (*p != NUL) { switch (*p) { case 'c': @@ -200,7 +200,7 @@ void do_debug(char_u *cmd) if (last_cmd != 0) { // Check that the tail matches. p++; - while (*p != NUL && *p == (char_u)(*tail)) { + while (*p != NUL && *p == *tail) { p++; tail++; } @@ -242,8 +242,8 @@ void do_debug(char_u *cmd) if (*p == NUL) { do_showbacktrace(cmd); } else { - p = (char_u *)skipwhite((char *)p); - do_setdebugtracelevel(p); + p = skipwhite(p); + do_setdebugtracelevel((char_u *)p); } continue; case CMD_UP: diff --git a/src/nvim/diff.c b/src/nvim/diff.c index 55992f3fae..dcc9b51431 100644 --- a/src/nvim/diff.c +++ b/src/nvim/diff.c @@ -744,7 +744,7 @@ static int diff_write_buffer(buf_T *buf, diffin_T *din) for (char_u *s = ml_get_buf(buf, lnum, false); *s != NUL;) { if (diff_flags & DIFF_ICASE) { int c; - char_u cbuf[MB_MAXBYTES + 1]; + char cbuf[MB_MAXBYTES + 1]; if (*s == NL) { c = NUL; @@ -794,7 +794,7 @@ static int diff_write(buf_T *buf, diffin_T *din) // Writing the buffer is an implementation detail of performing the diff, // so it shouldn't update the '[ and '] marks. cmdmod.lockmarks = true; - int r = buf_write(buf, din->din_fname, NULL, + int r = buf_write(buf, (char *)din->din_fname, NULL, (linenr_T)1, buf->b_ml.ml_line_count, NULL, false, false, false, true); cmdmod.lockmarks = save_lockmarks; @@ -1178,7 +1178,7 @@ void ex_diffpatch(exarg_T *eap) } // Write the current buffer to "tmp_orig". - if (buf_write(curbuf, tmp_orig, NULL, + if (buf_write(curbuf, (char *)tmp_orig, NULL, (linenr_T)1, curbuf->b_ml.ml_line_count, NULL, false, false, false, true) == FAIL) { goto theend; @@ -1982,8 +1982,8 @@ static int diff_cmp(char_u *s1, char_u *s2) return mb_stricmp((const char *)s1, (const char *)s2); } - char_u *p1 = s1; - char_u *p2 = s2; + char *p1 = (char *)s1; + char *p2 = (char *)s2; // Ignore white space changes and possibly ignore case. while (*p1 != NUL && *p2 != NUL) { @@ -1991,11 +1991,11 @@ static int diff_cmp(char_u *s1, char_u *s2) && ascii_iswhite(*p1) && ascii_iswhite(*p2)) || ((diff_flags & DIFF_IWHITEALL) && (ascii_iswhite(*p1) || ascii_iswhite(*p2)))) { - p1 = (char_u *)skipwhite((char *)p1); - p2 = (char_u *)skipwhite((char *)p2); + p1 = skipwhite(p1); + p2 = skipwhite(p2); } else { int l; - if (!diff_equal_char(p1, p2, &l)) { + if (!diff_equal_char((char_u *)p1, (char_u *)p2, &l)) { break; } p1 += l; @@ -2004,8 +2004,8 @@ static int diff_cmp(char_u *s1, char_u *s2) } // Ignore trailing white space. - p1 = (char_u *)skipwhite((char *)p1); - p2 = (char_u *)skipwhite((char *)p2); + p1 = skipwhite(p1); + p2 = skipwhite(p2); if ((*p1 != NUL) || (*p2 != NUL)) { return 1; diff --git a/src/nvim/digraph.c b/src/nvim/digraph.c index da96379700..43ea32fc09 100644 --- a/src/nvim/digraph.c +++ b/src/nvim/digraph.c @@ -2087,7 +2087,7 @@ void ex_loadkeymap(exarg_T *eap) // Get each line of the sourced file, break at the end. for (;;) { - char_u *line = eap->getline(0, eap->cookie, 0, true); + char *line = eap->getline(0, eap->cookie, 0, true); if (line == NULL) { break; diff --git a/src/nvim/edit.c b/src/nvim/edit.c index 20bbc23ac4..c2e61271c7 100644 --- a/src/nvim/edit.c +++ b/src/nvim/edit.c @@ -1325,14 +1325,14 @@ normalchar: if (!p_paste) { // Trigger InsertCharPre. - char_u *str = do_insert_char_pre(s->c); - char_u *p; + char *str = (char *)do_insert_char_pre(s->c); + char *p; if (str != NULL) { if (*str != NUL && stop_arrow() != FAIL) { // Insert the new value of v:char literally. for (p = str; *p != NUL; MB_PTR_ADV(p)) { - s->c = utf_ptr2char((char *)p); + s->c = utf_ptr2char(p); if (s->c == CAR || s->c == K_KENTER || s->c == NL) { ins_eol(s->c); } else { @@ -3505,11 +3505,11 @@ static void ins_compl_addleader(int c) return; } if ((cc = utf_char2len(c)) > 1) { - char_u buf[MB_MAXBYTES + 1]; + char buf[MB_MAXBYTES + 1]; utf_char2bytes(c, (char *)buf); buf[cc] = NUL; - ins_char_bytes(buf, (size_t)cc); + ins_char_bytes((char_u *)buf, (size_t)cc); } else { ins_char(c); } @@ -5939,11 +5939,11 @@ void insertchar(int c, int flags, int second_indent) int cc; if ((cc = utf_char2len(c)) > 1) { - char_u buf[MB_MAXBYTES + 1]; + char buf[MB_MAXBYTES + 1]; utf_char2bytes(c, (char *)buf); buf[cc] = NUL; - ins_char_bytes(buf, (size_t)cc); + ins_char_bytes((char_u *)buf, (size_t)cc); AppendCharToRedobuff(c); } else { ins_char(c); @@ -6840,7 +6840,7 @@ char_u *add_char2buf(int c, char_u *s) char_u temp[MB_MAXBYTES + 1]; const int len = utf_char2bytes(c, (char *)temp); for (int i = 0; i < len; i++) { - c = temp[i]; + c = (uint8_t)temp[i]; // Need to escape K_SPECIAL like in the typeahead buffer. if (c == K_SPECIAL) { *s++ = K_SPECIAL; @@ -9460,7 +9460,7 @@ static char_u *do_insert_char_pre(int c) // character. Only use it when changed, otherwise continue with the // original character to avoid breaking autoindent. if (STRCMP(buf, get_vim_var_str(VV_CHAR)) != 0) { - res = vim_strsave(get_vim_var_str(VV_CHAR)); + res = vim_strsave((char_u *)get_vim_var_str(VV_CHAR)); } } diff --git a/src/nvim/eval.c b/src/nvim/eval.c index 01f913dd70..ba7e34b541 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -1327,7 +1327,7 @@ static list_T *heredoc_get(exarg_T *eap, char *cmd) int mi = 0; int ti = 0; - char *theline = (char *)eap->getline(NUL, eap->cookie, 0, false); + char *theline = eap->getline(NUL, eap->cookie, 0, false); if (theline == NULL) { semsg(_("E990: Missing end marker '%s'"), marker); break; @@ -3170,7 +3170,7 @@ char *cat_prefix_varname(int prefix, const char *name) /// Function given to ExpandGeneric() to obtain the list of user defined /// (global/buffer/window/built-in) variable names. -char_u *get_user_var_name(expand_T *xp, int idx) +char *get_user_var_name(expand_T *xp, int idx) { static size_t gdone; static size_t bdone; @@ -3195,9 +3195,9 @@ char_u *get_user_var_name(expand_T *xp, int idx) ++hi; } if (STRNCMP("g:", xp->xp_pattern, 2) == 0) { - return (char_u *)cat_prefix_varname('g', (char *)hi->hi_key); + return cat_prefix_varname('g', (char *)hi->hi_key); } - return hi->hi_key; + return (char *)hi->hi_key; } // b: variables @@ -3211,7 +3211,7 @@ char_u *get_user_var_name(expand_T *xp, int idx) while (HASHITEM_EMPTY(hi)) { ++hi; } - return (char_u *)cat_prefix_varname('b', (char *)hi->hi_key); + return cat_prefix_varname('b', (char *)hi->hi_key); } // w: variables @@ -3225,7 +3225,7 @@ char_u *get_user_var_name(expand_T *xp, int idx) while (HASHITEM_EMPTY(hi)) { ++hi; } - return (char_u *)cat_prefix_varname('w', (char *)hi->hi_key); + return cat_prefix_varname('w', (char *)hi->hi_key); } // t: variables @@ -3239,12 +3239,12 @@ char_u *get_user_var_name(expand_T *xp, int idx) while (HASHITEM_EMPTY(hi)) { ++hi; } - return (char_u *)cat_prefix_varname('t', (char *)hi->hi_key); + return cat_prefix_varname('t', (char *)hi->hi_key); } // v: variables if (vidx < ARRAY_SIZE(vimvars)) { - return (char_u *)cat_prefix_varname('v', vimvars[vidx++].vv_name); + return cat_prefix_varname('v', vimvars[vidx++].vv_name); } XFREE_CLEAR(varnamebuf); @@ -4057,7 +4057,7 @@ static int eval7(char **arg, typval_T *rettv, int evaluate, int want_string) case '7': case '8': case '9': { - char *p = (char *)skipdigits((char_u *)(*arg) + 1); + char *p = skipdigits(*arg + 1); int get_float = false; // We accept a float when the format matches @@ -4067,7 +4067,7 @@ static int eval7(char **arg, typval_T *rettv, int evaluate, int want_string) // ":let vers = 1.2.3" doesn't fail. if (!want_string && p[0] == '.' && ascii_isdigit(p[1])) { get_float = true; - p = (char *)skipdigits((char_u *)p + 2); + p = skipdigits(p + 2); if (*p == 'e' || *p == 'E') { ++p; if (*p == '-' || *p == '+') { @@ -4076,7 +4076,7 @@ static int eval7(char **arg, typval_T *rettv, int evaluate, int want_string) if (!ascii_isdigit(*p)) { get_float = false; } else { - p = (char *)skipdigits((char_u *)p + 1); + p = skipdigits(p + 1); } } if (ASCII_ISALPHA(*p) || *p == '.') { @@ -8206,9 +8206,10 @@ varnumber_T get_vim_var_nr(int idx) FUNC_ATTR_PURE /// Get string v: variable value. Uses a static buffer, can only be used once. /// If the String variable has never been set, return an empty string. /// Never returns NULL; -char_u *get_vim_var_str(int idx) FUNC_ATTR_PURE FUNC_ATTR_NONNULL_RET +char *get_vim_var_str(int idx) + FUNC_ATTR_PURE FUNC_ATTR_NONNULL_RET { - return (char_u *)tv_get_string(&vimvars[idx].vv_tv); + return (char *)tv_get_string(&vimvars[idx].vv_tv); } /// Get List v: variable value. Caller must take care of reference count when @@ -10217,7 +10218,7 @@ repeat: } } - tail = (char *)path_tail((char_u *)(*fnamep)); + tail = path_tail(*fnamep); *fnamelen = STRLEN(*fnamep); // ":h" - head, remove "/file_name", can be repeated diff --git a/src/nvim/eval/funcs.c b/src/nvim/eval/funcs.c index 282c7cffc9..ee00736b63 100644 --- a/src/nvim/eval/funcs.c +++ b/src/nvim/eval/funcs.c @@ -80,9 +80,6 @@ typedef enum { kSomeMatchStrPos, ///< Data for matchstrpos(). } SomeMatchType; -KHASH_MAP_INIT_STR(functions, VimLFuncDef) - - #ifdef INCLUDE_GENERATED_DECLARATIONS # include "eval/funcs.c.generated.h" @@ -116,7 +113,7 @@ static va_list dummy_ap; /// Function given to ExpandGeneric() to obtain the list of internal /// or user defined function names. -char_u *get_function_name(expand_T *xp, int idx) +char *get_function_name(expand_T *xp, int idx) { static int intidx = -1; char_u *name; @@ -125,23 +122,20 @@ char_u *get_function_name(expand_T *xp, int idx) intidx = -1; } if (intidx < 0) { - name = get_user_func_name(xp, idx); + name = (char_u *)get_user_func_name(xp, idx); if (name != NULL) { if (*name != NUL && *name != '<' && STRNCMP("g:", xp->xp_pattern, 2) == 0) { - return (char_u *)cat_prefix_varname('g', (char *)name); + return cat_prefix_varname('g', (char *)name); } - return name; + return (char *)name; } } - while ((size_t)++intidx < ARRAY_SIZE(functions) - && functions[intidx].name[0] == '\0') {} - if ((size_t)intidx >= ARRAY_SIZE(functions)) { + const char *const key = functions[++intidx].name; + if (!key) { return NULL; } - - const char *const key = functions[intidx].name; const size_t key_len = strlen(key); memcpy(IObuff, key, key_len); IObuff[key_len] = '('; @@ -151,12 +145,12 @@ char_u *get_function_name(expand_T *xp, int idx) } else { IObuff[key_len + 1] = NUL; } - return IObuff; + return (char *)IObuff; } /// Function given to ExpandGeneric() to obtain the list of internal or /// user defined variable or function names. -char_u *get_expr_name(expand_T *xp, int idx) +char *get_expr_name(expand_T *xp, int idx) { static int intidx = -1; char_u *name; @@ -165,9 +159,9 @@ char_u *get_expr_name(expand_T *xp, int idx) intidx = -1; } if (intidx < 0) { - name = get_function_name(xp, idx); + name = (char_u *)get_function_name(xp, idx); if (name != NULL) { - return name; + return (char *)name; } } return get_user_var_name(xp, ++intidx); @@ -178,18 +172,19 @@ char_u *get_expr_name(expand_T *xp, int idx) /// @param[in] name Name of the function. /// /// @return pointer to the function definition or NULL if not found. -const VimLFuncDef *find_internal_func(const char *const name) +const EvalFuncDef *find_internal_func(const char *const name) FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_PURE FUNC_ATTR_NONNULL_ALL { size_t len = strlen(name); - return find_internal_func_gperf(name, len); + int index = find_internal_func_hash(name, len); + return index >= 0 ? &functions[index] : NULL; } int call_internal_func(const char_u *const fname, const int argcount, typval_T *const argvars, typval_T *const rettv) FUNC_ATTR_NONNULL_ALL { - const VimLFuncDef *const fdef = find_internal_func((const char *)fname); + const EvalFuncDef *const fdef = find_internal_func((const char *)fname); if (fdef == NULL) { return ERROR_UNKNOWN; } else if (argcount < fdef->min_argc) { @@ -207,7 +202,7 @@ int call_internal_method(const char_u *const fname, const int argcount, typval_T typval_T *const rettv, typval_T *const basetv) FUNC_ATTR_NONNULL_ALL { - const VimLFuncDef *const fdef = find_internal_func((const char *)fname); + const EvalFuncDef *const fdef = find_internal_func((const char *)fname); if (fdef == NULL) { return ERROR_UNKNOWN; } else if (fdef->base_arg == BASE_NONE) { @@ -1931,7 +1926,7 @@ typedef struct { const listitem_T *li; } GetListLineCookie; -static char_u *get_list_line(int c, void *cookie, int indent, bool do_concat) +static char *get_list_line(int c, void *cookie, int indent, bool do_concat) { GetListLineCookie *const p = (GetListLineCookie *)cookie; @@ -1942,7 +1937,7 @@ static char_u *get_list_line(int c, void *cookie, int indent, bool do_concat) char buf[NUMBUFLEN]; const char *const s = tv_get_string_buf_chk(TV_LIST_ITEM_TV(item), buf); p->li = TV_LIST_ITEM_NEXT(p->l, item); - return (char_u *)(s == NULL ? NULL : xstrdup(s)); + return s == NULL ? NULL : xstrdup(s); } static void execute_common(typval_T *argvars, typval_T *rettv, FunPtr fptr, int arg_off) @@ -2562,7 +2557,7 @@ static void f_foldtext(typval_T *argvars, typval_T *rettv, FunPtr fptr) foldstart = (linenr_T)get_vim_var_nr(VV_FOLDSTART); foldend = (linenr_T)get_vim_var_nr(VV_FOLDEND); - dashes = get_vim_var_str(VV_FOLDDASHES); + dashes = (char_u *)get_vim_var_str(VV_FOLDDASHES); if (foldstart > 0 && foldend <= curbuf->b_ml.ml_line_count) { // Find first non-empty line in the fold. for (lnum = foldstart; lnum < foldend; lnum++) { @@ -3082,7 +3077,7 @@ static void f_getcharstr(typval_T *argvars, typval_T *rettv, FunPtr fptr) getchar_common(argvars, rettv); if (rettv->v_type == VAR_NUMBER) { - char_u temp[7]; // mbyte-char: 6, NUL: 1 + char temp[7]; // mbyte-char: 6, NUL: 1 const varnumber_T n = rettv->vval.v_number; int i = 0; @@ -3092,7 +3087,7 @@ static void f_getcharstr(typval_T *argvars, typval_T *rettv, FunPtr fptr) assert(i < 7); temp[i++] = NUL; rettv->v_type = VAR_STRING; - rettv->vval.v_string = (char *)vim_strsave(temp); + rettv->vval.v_string = xstrdup(temp); } } @@ -3677,7 +3672,7 @@ static int getreg_get_regname(typval_T *argvars) } } else { // Default to v:register - strregname = get_vim_var_str(VV_REG); + strregname = (char_u *)get_vim_var_str(VV_REG); } return *strregname == 0 ? '"' : *strregname; @@ -5101,7 +5096,7 @@ static dict_T *create_environment(const dictitem_T *job_env, const bool clear_en } // Set $NVIM (in the child process) to v:servername. #3118 - char *nvim_addr = (char *)get_vim_var_str(VV_SEND_SERVER); + char *nvim_addr = get_vim_var_str(VV_SEND_SERVER); if (nvim_addr[0] != '\0') { dictitem_T *dv = tv_dict_find(env, S_LEN("NVIM")); if (dv) { @@ -5646,7 +5641,7 @@ static void f_list2str(typval_T *argvars, typval_T *rettv, FunPtr fptr) } ga_init(&ga, 1, 80); - char_u buf[MB_MAXBYTES + 1]; + char buf[MB_MAXBYTES + 1]; TV_LIST_ITER_CONST(l, li, { buf[utf_char2bytes(tv_get_number(TV_LIST_ITEM_TV(li)), (char *)buf)] = NUL; @@ -5666,7 +5661,7 @@ static void f_localtime(typval_T *argvars, typval_T *rettv, FunPtr fptr) static void get_maparg(typval_T *argvars, typval_T *rettv, int exact) { - char_u *keys_buf = NULL; + char *keys_buf = NULL; char_u *alt_keys_buf = NULL; bool did_simplify = false; char_u *rhs; @@ -5682,7 +5677,7 @@ static void get_maparg(typval_T *argvars, typval_T *rettv, int exact) rettv->v_type = VAR_STRING; rettv->vval.v_string = NULL; - char_u *keys = (char_u *)tv_get_string(&argvars[0]); + char *keys = (char *)tv_get_string(&argvars[0]); if (*keys == NUL) { return; } @@ -5707,14 +5702,14 @@ static void get_maparg(typval_T *argvars, typval_T *rettv, int exact) mode = get_map_mode((char **)&which, 0); char_u *keys_simplified - = (char_u *)replace_termcodes((char *)keys, - STRLEN(keys), (char **)&keys_buf, flags, &did_simplify, + = (char_u *)replace_termcodes(keys, + STRLEN(keys), &keys_buf, flags, &did_simplify, CPO_TO_CPO_FLAGS); rhs = check_map(keys_simplified, mode, exact, false, abbr, &mp, &buffer_local, &rhs_lua); if (did_simplify) { // When the lhs is being simplified the not-simplified keys are // preferred for printing, like in do_map(). - (void)replace_termcodes((char *)keys, + (void)replace_termcodes(keys, STRLEN(keys), (char **)&alt_keys_buf, flags | REPTERM_NO_SIMPLIFY, NULL, CPO_TO_CPO_FLAGS); @@ -6100,7 +6095,7 @@ static void f_mkdir(typval_T *argvars, typval_T *rettv, FunPtr fptr) return; } - if (*path_tail((char_u *)dir) == NUL) { + if (*path_tail(dir) == NUL) { // Remove trailing slashes. *path_tail_with_sep((char_u *)dir) = NUL; } @@ -7402,11 +7397,11 @@ static void f_resolve(typval_T *argvars, typval_T *rettv, FunPtr fptr) q[-1] = NUL; } - q = (char *)path_tail((char_u *)p); + q = path_tail(p); if (q > p && *q == NUL) { // Ignore trailing path separator. q[-1] = NUL; - q = (char *)path_tail((char_u *)p); + q = path_tail(p); } if (q > p && !path_is_absolute((const char_u *)buf)) { // Symlink is relative to directory of argument. Replace the @@ -7414,7 +7409,7 @@ static void f_resolve(typval_T *argvars, typval_T *rettv, FunPtr fptr) const size_t p_len = strlen(p); const size_t buf_len = strlen(buf); p = xrealloc(p, p_len + buf_len + 1); - memcpy(path_tail((char_u *)p), buf, buf_len + 1); + memcpy(path_tail(p), buf, buf_len + 1); } else { xfree(p); p = xstrdup(buf); @@ -7524,15 +7519,15 @@ static void f_reduce(typval_T *argvars, typval_T *rettv, FunPtr fptr) return; } - const char_u *func_name; + const char *func_name; partial_T *partial = NULL; if (argvars[1].v_type == VAR_FUNC) { - func_name = (char_u *)argvars[1].vval.v_string; + func_name = argvars[1].vval.v_string; } else if (argvars[1].v_type == VAR_PARTIAL) { partial = argvars[1].vval.v_partial; - func_name = (char_u *)partial_name(partial); + func_name = partial_name(partial); } else { - func_name = (const char_u *)tv_get_string(&argvars[1]); + func_name = tv_get_string(&argvars[1]); } if (*func_name == NUL) { return; // type error or empty name @@ -7881,7 +7876,7 @@ static void f_rpcrequest(typval_T *argvars, typval_T *rettv, FunPtr fptr) } sctx_T save_current_sctx; - uint8_t *save_sourcing_name, *save_autocmd_fname, *save_autocmd_match; + char *save_sourcing_name, *save_autocmd_fname, *save_autocmd_match; linenr_T save_sourcing_lnum; int save_autocmd_bufnr; funccal_entry_T funccal_entry; @@ -9858,13 +9853,13 @@ static void f_stdpath(typval_T *argvars, typval_T *rettv, FunPtr fptr) /// "str2float()" function static void f_str2float(typval_T *argvars, typval_T *rettv, FunPtr fptr) { - char_u *p = (char_u *)skipwhite(tv_get_string(&argvars[0])); + char *p = skipwhite(tv_get_string(&argvars[0])); bool isneg = (*p == '-'); if (*p == '+' || *p == '-') { - p = (char_u *)skipwhite((char *)p + 1); + p = skipwhite(p + 1); } - (void)string2float((char *)p, &rettv->vval.v_float); + (void)string2float(p, &rettv->vval.v_float); if (isneg) { rettv->vval.v_float *= -1; } diff --git a/src/nvim/eval/funcs.h b/src/nvim/eval/funcs.h index c6a0cb959e..4ab4c8f800 100644 --- a/src/nvim/eval/funcs.h +++ b/src/nvim/eval/funcs.h @@ -9,19 +9,19 @@ typedef void (*FunPtr)(void); /// Prototype of C function that implements VimL function typedef void (*VimLFunc)(typval_T *args, typval_T *rvar, FunPtr data); -/// Special flags for base_arg @see VimLFuncDef +/// Special flags for base_arg @see EvalFuncDef #define BASE_NONE 0 ///< Not a method (no base argument). #define BASE_LAST UINT8_MAX ///< Use the last argument as the method base. /// Structure holding VimL function definition -typedef struct fst { +typedef struct { char *name; ///< Name of the function. uint8_t min_argc; ///< Minimal number of arguments. uint8_t max_argc; ///< Maximal number of arguments. uint8_t base_arg; ///< Method base arg # (1-indexed), BASE_NONE or BASE_LAST. VimLFunc func; ///< Function implementation. FunPtr data; ///< Userdata for function implementation. -} VimLFuncDef; +} EvalFuncDef; #ifdef INCLUDE_GENERATED_DECLARATIONS # include "eval/funcs.h.generated.h" diff --git a/src/nvim/eval/typval_encode.h b/src/nvim/eval/typval_encode.h index d5cf431870..ed70ba87ec 100644 --- a/src/nvim/eval/typval_encode.h +++ b/src/nvim/eval/typval_encode.h @@ -85,9 +85,7 @@ static inline size_t tv_strlen(const typval_T *const tv) static inline size_t tv_strlen(const typval_T *const tv) { assert(tv->v_type == VAR_STRING); - return (tv->vval.v_string == NULL - ? 0 - : strlen((char *)tv->vval.v_string)); + return (tv->vval.v_string == NULL ? 0 : strlen(tv->vval.v_string)); } /// Code for checking whether container references itself diff --git a/src/nvim/eval/userfunc.c b/src/nvim/eval/userfunc.c index d6a63993c6..c6b6a8ead9 100644 --- a/src/nvim/eval/userfunc.c +++ b/src/nvim/eval/userfunc.c @@ -994,7 +994,7 @@ void call_user_func(ufunc_T *fp, int argcount, typval_T *argvars, typval_T *rett // Don't redraw while executing the function. RedrawingDisabled++; - save_sourcing_name = sourcing_name; + save_sourcing_name = (char_u *)sourcing_name; save_sourcing_lnum = sourcing_lnum; sourcing_lnum = 1; @@ -1014,7 +1014,7 @@ void call_user_func(ufunc_T *fp, int argcount, typval_T *argvars, typval_T *rett { if (save_sourcing_name != NULL && STRNCMP(save_sourcing_name, "function ", 9) == 0) { - vim_snprintf((char *)sourcing_name, + vim_snprintf(sourcing_name, len, "%s[%" PRId64 "]..", save_sourcing_name, @@ -1022,7 +1022,7 @@ void call_user_func(ufunc_T *fp, int argcount, typval_T *argvars, typval_T *rett } else { STRCPY(sourcing_name, "function "); } - cat_func_name(sourcing_name + STRLEN(sourcing_name), fp); + cat_func_name((char_u *)sourcing_name + STRLEN(sourcing_name), fp); if (p_verbose >= 12) { ++no_wait_return; @@ -1175,7 +1175,7 @@ void call_user_func(ufunc_T *fp, int argcount, typval_T *argvars, typval_T *rett } xfree(sourcing_name); - sourcing_name = save_sourcing_name; + sourcing_name = (char *)save_sourcing_name; sourcing_lnum = save_sourcing_lnum; current_sctx = save_current_sctx; if (do_profiling_yes) { @@ -2219,7 +2219,7 @@ void ex_function(exarg_T *eap) if (eap->getline == NULL) { theline = getcmdline(':', 0L, indent, do_concat); } else { - theline = eap->getline(':', eap->cookie, indent, do_concat); + theline = (char_u *)eap->getline(':', eap->cookie, indent, do_concat); } line_to_free = theline; } @@ -2644,7 +2644,7 @@ bool function_exists(const char *const name, bool no_deref) /// Function given to ExpandGeneric() to obtain the list of user defined /// function names. -char_u *get_user_func_name(expand_T *xp, int idx) +char *get_user_func_name(expand_T *xp, int idx) { static size_t done; static hashitem_T *hi; @@ -2666,11 +2666,11 @@ char_u *get_user_func_name(expand_T *xp, int idx) if ((fp->uf_flags & FC_DICT) || STRNCMP(fp->uf_name, "<lambda>", 8) == 0) { - return (char_u *)""; // don't show dict and lambda functions + return ""; // don't show dict and lambda functions } if (STRLEN(fp->uf_name) + 4 >= IOSIZE) { - return fp->uf_name; // Prevent overflow. + return (char *)fp->uf_name; // Prevent overflow. } cat_func_name(IObuff, fp); @@ -2680,7 +2680,7 @@ char_u *get_user_func_name(expand_T *xp, int idx) STRCAT(IObuff, ")"); } } - return IObuff; + return (char *)IObuff; } return NULL; } @@ -3137,7 +3137,7 @@ char_u *get_return_cmd(void *rettv) /// Called by do_cmdline() to get the next line. /// /// @return allocated string, or NULL for end of function. -char_u *get_func_line(int c, void *cookie, int indent, bool do_concat) +char *get_func_line(int c, void *cookie, int indent, bool do_concat) { funccall_T *fcp = (funccall_T *)cookie; ufunc_T *fp = fcp->func; @@ -3184,7 +3184,7 @@ char_u *get_func_line(int c, void *cookie, int indent, bool do_concat) fcp->dbg_tick = debug_tick; } - return retval; + return (char *)retval; } /// @return TRUE if the currently active function should be ended, because a diff --git a/src/nvim/event/socket.c b/src/nvim/event/socket.c index 060b432b18..1722f0ee1f 100644 --- a/src/nvim/event/socket.c +++ b/src/nvim/event/socket.c @@ -124,7 +124,7 @@ int socket_watcher_start(SocketWatcher *watcher, int backlog, socket_cb cb) if (result == UV_EACCES) { // Libuv converts ENOENT to EACCES for Windows compatibility, but if // the parent directory does not exist, ENOENT would be more accurate. - *path_tail((char_u *)watcher->addr) = NUL; + *path_tail(watcher->addr) = NUL; if (!os_path_exists((char_u *)watcher->addr)) { result = UV_ENOENT; } diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c index b8ca00a9e8..1dbae13354 100644 --- a/src/nvim/ex_cmds.c +++ b/src/nvim/ex_cmds.c @@ -1341,7 +1341,7 @@ static void do_filter(linenr_T line1, linenr_T line2, exarg_T *eap, char *cmd, b * Vi also doesn't do this and the messages are not very informative. */ no_wait_return++; // don't call wait_return() while busy - if (itmp != NULL && buf_write(curbuf, (char_u *)itmp, NULL, line1, line2, eap, + if (itmp != NULL && buf_write(curbuf, itmp, NULL, line1, line2, eap, false, false, false, true) == FAIL) { msg_putchar('\n'); // Keep message from buf_write(). no_wait_return--; @@ -1386,7 +1386,7 @@ static void do_filter(linenr_T line1, linenr_T line2, exarg_T *eap, char *cmd, b if (do_out) { if (otmp != NULL) { - if (readfile((char_u *)otmp, NULL, line2, (linenr_T)0, (linenr_T)MAXLNUM, eap, + if (readfile(otmp, NULL, line2, (linenr_T)0, (linenr_T)MAXLNUM, eap, READ_FILTER, false) != OK) { if (!aborting()) { msg_putchar('\n'); @@ -1930,7 +1930,7 @@ int do_write(exarg_T *eap) } name_was_missing = curbuf->b_ffname == NULL; - retval = buf_write(curbuf, (char_u *)ffname, (char_u *)fname, eap->line1, eap->line2, + retval = buf_write(curbuf, ffname, fname, eap->line1, eap->line2, eap, eap->append, eap->forceit, true, false); // After ":saveas fname" reset 'readonly'. @@ -5360,7 +5360,7 @@ void fix_help_buffer(void) * In the "help.txt" and "help.abx" file, add the locally added help * files. This uses the very first line in the help file. */ - char *const fname = (char *)path_tail(curbuf->b_fname); + char *const fname = path_tail((char *)curbuf->b_fname); if (FNAMECMP(fname, "help.txt") == 0 || (FNAMENCMP(fname, "help.", 5) == 0 && ASCII_ISALPHA(fname[5]) @@ -5413,8 +5413,8 @@ void fix_help_buffer(void) } const char *const f1 = fnames[i1]; const char *const f2 = fnames[i2]; - const char *const t1 = (char *)path_tail((char_u *)f1); - const char *const t2 = (char *)path_tail((char_u *)f2); + const char *const t1 = path_tail(f1); + const char *const t2 = path_tail(f2); const char *const e1 = (char *)STRRCHR(t1, '.'); const char *const e2 = (char *)STRRCHR(t2, '.'); if (e1 == NULL || e2 == NULL) { diff --git a/src/nvim/ex_cmds2.c b/src/nvim/ex_cmds2.c index d1dcb28dbd..8624f6d676 100644 --- a/src/nvim/ex_cmds2.c +++ b/src/nvim/ex_cmds2.c @@ -200,12 +200,12 @@ static char *pexpand_cmds[] = { /// Function given to ExpandGeneric() to obtain the profile command /// specific expansion. -char_u *get_profile_name(expand_T *xp, int idx) +char *get_profile_name(expand_T *xp, int idx) FUNC_ATTR_PURE { switch (pexpand_what) { case PEXP_SUBCMD: - return (char_u *)pexpand_cmds[idx]; + return pexpand_cmds[idx]; // case PEXP_FUNC: TODO default: return NULL; @@ -792,7 +792,7 @@ int buf_write_all(buf_T *buf, int forceit) int retval; buf_T *old_curbuf = curbuf; - retval = (buf_write(buf, buf->b_ffname, buf->b_fname, + retval = (buf_write(buf, (char *)buf->b_ffname, (char *)buf->b_fname, (linenr_T)1, buf->b_ml.ml_line_count, NULL, false, forceit, true, false)); if (curbuf != old_curbuf) { @@ -1571,12 +1571,12 @@ static void alist_add_list(int count, char **files, int after, bool will_edit) // Function given to ExpandGeneric() to obtain the possible arguments of the // argedit and argdelete commands. -char_u *get_arglist_name(expand_T *xp FUNC_ATTR_UNUSED, int idx) +char *get_arglist_name(expand_T *xp FUNC_ATTR_UNUSED, int idx) { if (idx >= ARGCOUNT) { return NULL; } - return alist_name(&ARGLIST[idx]); + return (char *)alist_name(&ARGLIST[idx]); } /// ":compiler[!] {name}" @@ -1766,7 +1766,7 @@ typedef struct { /// /// @return pointer to allocated line, or NULL for end-of-file or /// some error. -static char_u *get_str_line(int c, void *cookie, int indent, bool do_concat) +static char *get_str_line(int c, void *cookie, int indent, bool do_concat) { GetStrLineCookie *p = cookie; if (STRLEN(p->buf) <= p->offset) { @@ -1818,16 +1818,16 @@ scriptitem_T *new_script_item(char *const name, scid_T *const sid_out) static int source_using_linegetter(void *cookie, LineGetter fgetline, const char *traceback_name) { - char *save_sourcing_name = (char *)sourcing_name; + char *save_sourcing_name = sourcing_name; linenr_T save_sourcing_lnum = sourcing_lnum; char sourcing_name_buf[256]; if (save_sourcing_name == NULL) { - sourcing_name = (char_u *)traceback_name; + sourcing_name = (char *)traceback_name; } else { snprintf((char *)sourcing_name_buf, sizeof(sourcing_name_buf), "%s called at %s:%" PRIdLINENR, traceback_name, save_sourcing_name, save_sourcing_lnum); - sourcing_name = (char_u *)sourcing_name_buf; // -V507 reassigned below, before return. + sourcing_name = sourcing_name_buf; // -V507 reassigned below, before return. } sourcing_lnum = 0; @@ -1842,7 +1842,7 @@ static int source_using_linegetter(void *cookie, LineGetter fgetline, const char int retval = do_cmdline(NULL, fgetline, cookie, DOCMD_VERBOSE | DOCMD_NOWAIT | DOCMD_REPEAT); sourcing_lnum = save_sourcing_lnum; - sourcing_name = (char_u *)save_sourcing_name; + sourcing_name = save_sourcing_name; current_sctx = save_current_sctx; restore_funccal(); return retval; @@ -1935,7 +1935,7 @@ int do_source(char *fname, int check_other, int is_vimrc) } // Apply SourceCmd autocommands, they should get the file and source it. - if (has_autocmd(EVENT_SOURCECMD, (char_u *)fname_exp, NULL) + if (has_autocmd(EVENT_SOURCECMD, fname_exp, NULL) && apply_autocmds(EVENT_SOURCECMD, (char_u *)fname_exp, (char_u *)fname_exp, false, curbuf)) { retval = aborting() ? FAIL : OK; @@ -1953,7 +1953,7 @@ int do_source(char *fname, int check_other, int is_vimrc) if (cookie.fp == NULL && check_other) { // Try again, replacing file name ".vimrc" by "_vimrc" or vice versa, // and ".exrc" by "_exrc" or vice versa. - p = (char *)path_tail((char_u *)fname_exp); + p = path_tail(fname_exp); if ((*p == '.' || *p == '_') && (STRICMP(p + 1, "nvimrc") == 0 || STRICMP(p + 1, "exrc") == 0)) { *p = (*p == '_') ? '.' : '_'; @@ -2014,8 +2014,8 @@ int do_source(char *fname, int check_other, int is_vimrc) cookie.level = ex_nesting_level; // Keep the sourcing name/lnum, for recursive calls. - save_sourcing_name = (char *)sourcing_name; - sourcing_name = (char_u *)fname_exp; + save_sourcing_name = sourcing_name; + sourcing_name = fname_exp; save_sourcing_lnum = sourcing_lnum; sourcing_lnum = 0; @@ -2059,7 +2059,7 @@ int do_source(char *fname, int check_other, int is_vimrc) cookie.conv.vc_type = CONV_NONE; // no conversion // Read the first line so we can check for a UTF-8 BOM. - firstline = getsourceline(0, (void *)&cookie, 0, true); + firstline = (uint8_t *)getsourceline(0, (void *)&cookie, 0, true); if (firstline != NULL && STRLEN(firstline) >= 3 && firstline[0] == 0xef && firstline[1] == 0xbb && firstline[2] == 0xbf) { // Found BOM; setup conversion, skip over BOM and recode the line. @@ -2104,7 +2104,7 @@ int do_source(char *fname, int check_other, int is_vimrc) if (got_int) { emsg(_(e_interr)); } - sourcing_name = (char_u *)save_sourcing_name; + sourcing_name = save_sourcing_name; sourcing_lnum = save_sourcing_lnum; if (p_verbose > 1) { verbose_enter(); @@ -2302,7 +2302,7 @@ linenr_T get_sourced_lnum(LineGetter fgetline, void *cookie) /// /// @return pointer to the line in allocated memory, or NULL for end-of-file or /// some error. -char_u *getsourceline(int c, void *cookie, int indent, bool do_concat) +char *getsourceline(int c, void *cookie, int indent, bool do_concat) { struct source_cookie *sp = (struct source_cookie *)cookie; char *line; @@ -2382,7 +2382,7 @@ char_u *getsourceline(int c, void *cookie, int indent, bool do_concat) sp->dbg_tick = debug_tick; } - return (char_u *)line; + return line; } static char *get_one_sourceline(struct source_cookie *sp) @@ -2942,36 +2942,36 @@ void free_locales(void) /// Function given to ExpandGeneric() to obtain the possible arguments of the /// ":language" command. -char_u *get_lang_arg(expand_T *xp, int idx) +char *get_lang_arg(expand_T *xp, int idx) { if (idx == 0) { - return (char_u *)"messages"; + return "messages"; } if (idx == 1) { - return (char_u *)"ctype"; + return "ctype"; } if (idx == 2) { - return (char_u *)"time"; + return "time"; } if (idx == 3) { - return (char_u *)"collate"; + return "collate"; } init_locales(); if (locales == NULL) { return NULL; } - return (char_u *)locales[idx - 4]; + return locales[idx - 4]; } /// Function given to ExpandGeneric() to obtain the available locales. -char_u *get_locales(expand_T *xp, int idx) +char *get_locales(expand_T *xp, int idx) { init_locales(); if (locales == NULL) { return NULL; } - return (char_u *)locales[idx]; + return locales[idx]; } #endif diff --git a/src/nvim/ex_cmds_defs.h b/src/nvim/ex_cmds_defs.h index 396e6fa19f..d8dd3da9e6 100644 --- a/src/nvim/ex_cmds_defs.h +++ b/src/nvim/ex_cmds_defs.h @@ -121,7 +121,7 @@ struct aucmd_executable_t { #define AUCMD_EXECUTABLE_INIT { .type = CALLABLE_NONE } -typedef char_u *(*LineGetter)(int, void *, int, bool); +typedef char *(*LineGetter)(int, void *, int, bool); /// Structure for command definition. typedef struct cmdname { diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c index 34f306bdfd..2173494be9 100644 --- a/src/nvim/ex_docmd.c +++ b/src/nvim/ex_docmd.c @@ -111,7 +111,7 @@ struct loop_cookie { int current_line; // last read line from growarray int repeating; // TRUE when looping a second time // When "repeating" is FALSE use "getline" and "cookie" to get lines - char_u *(*getline)(int, void *, int, bool); + char *(*getline)(int, void *, int, bool); void *cookie; }; @@ -324,7 +324,7 @@ int do_cmdline(char *cmdline, LineGetter fgetline, void *cookie, int flags) struct msglist *private_msg_list; // "fgetline" and "cookie" passed to do_one_cmd() - char_u *(*cmd_getline)(int, void *, int, bool); + char *(*cmd_getline)(int, void *, int, bool); void *cmd_cookie; struct loop_cookie cmd_loop_cookie; void *real_cookie; @@ -372,7 +372,7 @@ int do_cmdline(char *cmdline, LineGetter fgetline, void *cookie, int flags) breakpoint = func_breakpoint(real_cookie); dbg_tick = func_dbg_tick(real_cookie); } else if (getline_equal(fgetline, cookie, getsourceline)) { - fname = (char *)sourcing_name; + fname = sourcing_name; breakpoint = source_breakpoint(real_cookie); dbg_tick = source_dbg_tick(real_cookie); } @@ -518,10 +518,10 @@ int do_cmdline(char *cmdline, LineGetter fgetline, void *cookie, int flags) msg_didout = true; } if (fgetline == NULL - || (next_cmdline = (char *)fgetline(':', cookie, - cstack.cs_idx < - 0 ? 0 : (cstack.cs_idx + 1) * 2, - true)) == NULL) { + || (next_cmdline = fgetline(':', cookie, + cstack.cs_idx < + 0 ? 0 : (cstack.cs_idx + 1) * 2, + true)) == NULL) { // Don't call wait_return for aborted command line. The NULL // returned for the end of a sourced file or executed function // doesn't do this. @@ -832,9 +832,9 @@ int do_cmdline(char *cmdline, LineGetter fgetline, void *cookie, int flags) break; } - saved_sourcing_name = (char *)sourcing_name; + saved_sourcing_name = sourcing_name; saved_sourcing_lnum = sourcing_lnum; - sourcing_name = (char_u *)current_exception->throw_name; + sourcing_name = current_exception->throw_name; sourcing_lnum = current_exception->throw_lnum; current_exception->throw_name = NULL; @@ -856,7 +856,7 @@ int do_cmdline(char *cmdline, LineGetter fgetline, void *cookie, int flags) xfree(p); } xfree(sourcing_name); - sourcing_name = (char_u *)saved_sourcing_name; + sourcing_name = saved_sourcing_name; sourcing_lnum = saved_sourcing_lnum; } else if (got_int || (did_emsg && force_abort)) { // On an interrupt or an aborting error not converted to an exception, @@ -949,7 +949,7 @@ int do_cmdline(char *cmdline, LineGetter fgetline, void *cookie, int flags) } /// Obtain a line when inside a ":while" or ":for" loop. -static char_u *get_loop_line(int c, void *cookie, int indent, bool do_concat) +static char *get_loop_line(int c, void *cookie, int indent, bool do_concat) { struct loop_cookie *cp = (struct loop_cookie *)cookie; wcmd_T *wp; @@ -963,21 +963,21 @@ static char_u *get_loop_line(int c, void *cookie, int indent, bool do_concat) if (cp->getline == NULL) { line = (char *)getcmdline(c, 0L, indent, do_concat); } else { - line = (char *)cp->getline(c, cp->cookie, indent, do_concat); + line = cp->getline(c, cp->cookie, indent, do_concat); } if (line != NULL) { store_loop_line(cp->lines_gap, line); ++cp->current_line; } - return (char_u *)line; + return line; } KeyTyped = false; cp->current_line++; wp = (wcmd_T *)(cp->lines_gap->ga_data) + cp->current_line; sourcing_lnum = wp->lnum; - return vim_strsave((char_u *)wp->line); + return xstrdup(wp->line); } /// Store a line in "gap" so that a ":while" loop can execute it again. @@ -1387,7 +1387,7 @@ static int parse_count(exarg_T *eap, char **errormsg, bool validate) long n; if ((eap->argt & EX_COUNT) && ascii_isdigit(*eap->arg) - && (!(eap->argt & EX_BUFNAME) || *(p = (char *)skipdigits((char_u *)eap->arg + 1)) == NUL + && (!(eap->argt & EX_BUFNAME) || *(p = skipdigits(eap->arg + 1)) == NUL || ascii_iswhite(*p))) { n = getdigits_long((char_u **)&eap->arg, false, -1); eap->arg = skipwhite(eap->arg); @@ -3189,7 +3189,7 @@ int modifier_len(char *cmd) char *p = cmd; if (ascii_isdigit(*cmd)) { - p = skipwhite((char *)skipdigits((char_u *)cmd + 1)); + p = skipwhite(skipdigits(cmd + 1)); } for (int i = 0; i < (int)ARRAY_SIZE(cmdmods); i++) { int j; @@ -3817,7 +3817,7 @@ const char *set_one_cmd_context(expand_T *xp, const char *buff) case CMD_isplit: case CMD_dsplit: // Skip count. - arg = (const char *)skipwhite((char *)skipdigits((const char_u *)arg)); + arg = (const char *)skipwhite(skipdigits(arg)); if (*arg == '/') { // Match regexp, not just whole words. for (++arg; *arg && *arg != '/'; arg++) { if (*arg == '\\' && arg[1] != NUL) { @@ -5498,12 +5498,12 @@ static int check_more(int message, bool forceit) } /// Function given to ExpandGeneric() to obtain the list of command names. -char_u *get_command_name(expand_T *xp, int idx) +char *get_command_name(expand_T *xp, int idx) { if (idx >= CMD_SIZE) { - return (char_u *)expand_user_command_name(idx); + return expand_user_command_name(idx); } - return (char_u *)cmdnames[idx].cmd_name; + return cmdnames[idx].cmd_name; } /// Check for a valid user command name @@ -6729,28 +6729,28 @@ static void do_ucmd(exarg_T *eap) static char *expand_user_command_name(int idx) { - return (char *)get_user_commands(NULL, idx - CMD_SIZE); + return get_user_commands(NULL, idx - CMD_SIZE); } /// Function given to ExpandGeneric() to obtain the list of user address type names. -char_u *get_user_cmd_addr_type(expand_T *xp, int idx) +char *get_user_cmd_addr_type(expand_T *xp, int idx) { - return (char_u *)addr_type_complete[idx].name; + return addr_type_complete[idx].name; } /// Function given to ExpandGeneric() to obtain the list of user command names. -char_u *get_user_commands(expand_T *xp FUNC_ATTR_UNUSED, int idx) +char *get_user_commands(expand_T *xp FUNC_ATTR_UNUSED, int idx) FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT { // In cmdwin, the alternative buffer should be used. const buf_T *const buf = prevwin_curwin()->w_buffer; if (idx < buf->b_ucmds.ga_len) { - return USER_CMD_GA(&buf->b_ucmds, idx)->uc_name; + return (char *)USER_CMD_GA(&buf->b_ucmds, idx)->uc_name; } idx -= buf->b_ucmds.ga_len; if (idx < ucmds.ga_len) { - return USER_CMD(idx)->uc_name; + return (char *)USER_CMD(idx)->uc_name; } return NULL; } @@ -6777,7 +6777,7 @@ static char *get_user_command_name(int idx, int cmdidx) /// Function given to ExpandGeneric() to obtain the list of user command /// attributes. -char_u *get_user_cmd_flags(expand_T *xp, int idx) +char *get_user_cmd_flags(expand_T *xp, int idx) { static char *user_cmd_flags[] = { "addr", "bang", "bar", "buffer", "complete", "count", @@ -6786,31 +6786,31 @@ char_u *get_user_cmd_flags(expand_T *xp, int idx) if (idx >= (int)ARRAY_SIZE(user_cmd_flags)) { return NULL; } - return (char_u *)user_cmd_flags[idx]; + return user_cmd_flags[idx]; } /// Function given to ExpandGeneric() to obtain the list of values for -nargs. -char_u *get_user_cmd_nargs(expand_T *xp, int idx) +char *get_user_cmd_nargs(expand_T *xp, int idx) { static char *user_cmd_nargs[] = { "0", "1", "*", "?", "+" }; if (idx >= (int)ARRAY_SIZE(user_cmd_nargs)) { return NULL; } - return (char_u *)user_cmd_nargs[idx]; + return user_cmd_nargs[idx]; } /// Function given to ExpandGeneric() to obtain the list of values for -complete. -char_u *get_user_cmd_complete(expand_T *xp, int idx) +char *get_user_cmd_complete(expand_T *xp, int idx) { if (idx >= (int)ARRAY_SIZE(command_complete)) { return NULL; } char *cmd_compl = get_command_complete(idx); if (cmd_compl == NULL) { - return (char_u *)""; + return ""; } else { - return (char_u *)cmd_compl; + return cmd_compl; } } @@ -8098,13 +8098,13 @@ static void ex_read(exarg_T *eap) if (check_fname() == FAIL) { // check for no file name return; } - i = readfile(curbuf->b_ffname, curbuf->b_fname, + i = readfile((char *)curbuf->b_ffname, (char *)curbuf->b_fname, eap->line2, (linenr_T)0, (linenr_T)MAXLNUM, eap, 0, false); } else { if (vim_strchr(p_cpo, CPO_ALTREAD) != NULL) { (void)setaltfname((char_u *)eap->arg, (char_u *)eap->arg, (linenr_T)1); } - i = readfile((char_u *)eap->arg, NULL, + i = readfile(eap->arg, NULL, eap->line2, (linenr_T)0, (linenr_T)MAXLNUM, eap, 0, false); } if (i != OK) { @@ -9551,17 +9551,17 @@ char_u *eval_vars(char_u *src, char_u *srcstart, size_t *usedlen, linenr_T *lnum case SPEC_AFILE: // file name for autocommand if (autocmd_fname != NULL - && !path_is_absolute(autocmd_fname) + && !path_is_absolute((char_u *)autocmd_fname) // For CmdlineEnter and related events, <afile> is not a path! #9348 - && !strequal("/", (char *)autocmd_fname)) { + && !strequal("/", autocmd_fname)) { // Still need to turn the fname into a full path. It was // postponed to avoid a delay when <afile> is not used. - result = FullName_save((char *)autocmd_fname, false); + result = FullName_save(autocmd_fname, false); // Copy into `autocmd_fname`, don't reassign it. #8165 STRLCPY(autocmd_fname, result, MAXPATHL); xfree(result); } - result = (char *)autocmd_fname; + result = autocmd_fname; if (result == NULL) { *errormsg = _("E495: no autocommand file name to substitute for \"<afile>\""); return NULL; @@ -9579,7 +9579,7 @@ char_u *eval_vars(char_u *src, char_u *srcstart, size_t *usedlen, linenr_T *lnum break; case SPEC_AMATCH: // match name for autocommand - result = (char *)autocmd_match; + result = autocmd_match; if (result == NULL) { *errormsg = _("E497: no autocommand match name to substitute for \"<amatch>\""); return NULL; @@ -9587,7 +9587,7 @@ char_u *eval_vars(char_u *src, char_u *srcstart, size_t *usedlen, linenr_T *lnum break; case SPEC_SFILE: // file name for ":so" command - result = (char *)sourcing_name; + result = sourcing_name; if (result == NULL) { *errormsg = _("E498: no :source file name to substitute for \"<sfile>\""); return NULL; @@ -9636,7 +9636,7 @@ char_u *eval_vars(char_u *src, char_u *srcstart, size_t *usedlen, linenr_T *lnum if (src[*usedlen] == '<') { (*usedlen)++; if ((s = (char *)STRRCHR(result, '.')) != NULL - && (char_u *)s >= path_tail((char_u *)result)) { + && s >= path_tail(result)) { resultlen = (size_t)(s - result); } } else if (!skip_mod) { @@ -9820,31 +9820,31 @@ static void ex_behave(exarg_T *eap) /// Function given to ExpandGeneric() to obtain the possible arguments of the /// ":behave {mswin,xterm}" command. -char_u *get_behave_arg(expand_T *xp, int idx) +char *get_behave_arg(expand_T *xp, int idx) { if (idx == 0) { - return (char_u *)"mswin"; + return "mswin"; } if (idx == 1) { - return (char_u *)"xterm"; + return "xterm"; } return NULL; } /// Function given to ExpandGeneric() to obtain the possible arguments of the /// ":messages {clear}" command. -char_u *get_messages_arg(expand_T *xp FUNC_ATTR_UNUSED, int idx) +char *get_messages_arg(expand_T *xp FUNC_ATTR_UNUSED, int idx) { if (idx == 0) { - return (char_u *)"clear"; + return "clear"; } return NULL; } -char_u *get_mapclear_arg(expand_T *xp FUNC_ATTR_UNUSED, int idx) +char *get_mapclear_arg(expand_T *xp FUNC_ATTR_UNUSED, int idx) { if (idx == 0) { - return (char_u *)"<buffer>"; + return "<buffer>"; } return NULL; } diff --git a/src/nvim/ex_eval.c b/src/nvim/ex_eval.c index 976a19300b..46f3a31120 100644 --- a/src/nvim/ex_eval.c +++ b/src/nvim/ex_eval.c @@ -479,7 +479,7 @@ static int throw_exception(void *value, except_type_T type, char *cmdname) } excp->type = type; - excp->throw_name = (char *)vim_strsave(sourcing_name == NULL ? (char_u *)"" : sourcing_name); + excp->throw_name = xstrdup(sourcing_name == NULL ? "" : sourcing_name); excp->throw_lnum = sourcing_lnum; if (p_verbose >= 13 || debug_break_level > 0) { diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index 7943a4dadf..a7e843704f 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -293,7 +293,7 @@ static void init_incsearch_state(incsearch_state_T *s) /// Given to ExpandGeneric() to obtain all available heathcheck names. /// @param[in] idx Index of the healthcheck item. /// @param[in] xp Not used. -static char_u *get_healthcheck_names(expand_T *xp, int idx) +static char *get_healthcheck_names(expand_T *xp, int idx) { // Generate the first time or on new prompt. if (healthchecks.last_gen == 0 || healthchecks.last_gen != last_prompt_id) { @@ -311,8 +311,8 @@ static char_u *get_healthcheck_names(expand_T *xp, int idx) // Tracked to regenerate items on next prompt. healthchecks.last_gen = last_prompt_id; } - return idx < - healthchecks.names.ga_len ? ((char_u **)(healthchecks.names.ga_data))[idx] : NULL; + return idx < healthchecks.names.ga_len + ? ((char **)(healthchecks.names.ga_data))[idx] : NULL; } /// Transform healthcheck file path into it's name. @@ -326,7 +326,7 @@ static void get_healthcheck_cb(char *path, void *cookie) struct healthchecks_cookie *hcookie = (struct healthchecks_cookie *)cookie; char *pattern; char *sub = "\\1"; - char_u *res; + char *res; if (hcookie->is_lua) { // Lua: transform "../lua/vim/lsp/health.lua" into "vim.lsp" @@ -336,16 +336,16 @@ static void get_healthcheck_cb(char *path, void *cookie) pattern = ".*[\\/]\\([^\\/]*\\)\\.vim$"; } - res = (char_u *)do_string_sub(path, pattern, sub, NULL, "g"); + res = do_string_sub(path, pattern, sub, NULL, "g"); if (hcookie->is_lua && res != NULL) { // Replace slashes with dots as represented by the healthcheck plugin. - char_u *ares = (char_u *)do_string_sub((char *)res, "[\\/]", ".", NULL, "g"); + char *ares = do_string_sub(res, "[\\/]", ".", NULL, "g"); xfree(res); res = ares; } if (res != NULL) { - GA_APPEND(char_u *, hcookie->names, res); + GA_APPEND(char *, hcookie->names, res); } } } @@ -356,12 +356,12 @@ static bool do_incsearch_highlighting(int firstc, int *search_delim, incsearch_s int *skiplen, int *patlen) FUNC_ATTR_NONNULL_ALL { - char_u *cmd; + char *cmd; cmdmod_T save_cmdmod = cmdmod; - char_u *p; + char *p; bool delim_optional = false; int delim; - char_u *end; + char *end; char *dummy; exarg_T ea; pos_T save_cursor; @@ -397,14 +397,14 @@ static bool do_incsearch_highlighting(int firstc, int *search_delim, incsearch_s parse_command_modifiers(&ea, &dummy, true); cmdmod = save_cmdmod; - cmd = (char_u *)skip_range(ea.cmd, NULL); + cmd = skip_range(ea.cmd, NULL); if (vim_strchr((char_u *)"sgvl", *cmd) == NULL) { goto theend; } // Skip over "substitute" to find the pattern separator. for (p = cmd; ASCII_ISALPHA(*p); p++) {} - if (*skipwhite((char *)p) == NUL) { + if (*skipwhite(p) == NUL) { goto theend; } @@ -420,9 +420,9 @@ static bool do_incsearch_highlighting(int firstc, int *search_delim, incsearch_s } else if (STRNCMP(cmd, "sort", MAX(p - cmd, 3)) == 0) { // skip over ! and flags if (*p == '!') { - p = (char_u *)skipwhite((char *)p + 1); + p = skipwhite(p + 1); } - while (ASCII_ISALPHA(*(p = (char_u *)skipwhite((char *)p)))) { + while (ASCII_ISALPHA(*(p = skipwhite((char *)p)))) { p++; } if (*p == NUL) { @@ -436,7 +436,7 @@ static bool do_incsearch_highlighting(int firstc, int *search_delim, incsearch_s // skip over "!/". if (*p == '!') { p++; - if (*skipwhite((char *)p) == NUL) { + if (*skipwhite(p) == NUL) { goto theend; } } @@ -447,10 +447,10 @@ static bool do_incsearch_highlighting(int firstc, int *search_delim, incsearch_s goto theend; } - p = (char_u *)skipwhite((char *)p); + p = skipwhite(p); delim = (delim_optional && vim_isIDc(*p)) ? ' ' : *p++; *search_delim = delim; - end = skip_regexp(p, delim, p_magic, NULL); + end = (char *)skip_regexp((char_u *)p, delim, p_magic, NULL); use_last_pat = end == p && *end == delim; if (end == p && !use_last_pat) { @@ -459,11 +459,11 @@ static bool do_incsearch_highlighting(int firstc, int *search_delim, incsearch_s // Don't do 'hlsearch' highlighting if the pattern matches everything. if (!use_last_pat) { - char_u c = *end; + char c = *end; int empty; *end = NUL; - empty = empty_pattern(p); + empty = empty_pattern((char_u *)p); *end = c; if (empty) { goto theend; @@ -471,7 +471,7 @@ static bool do_incsearch_highlighting(int firstc, int *search_delim, incsearch_s } // found a non-empty pattern or // - *skiplen = (int)(p - ccline.cmdbuff); + *skiplen = (int)((char_u *)p - ccline.cmdbuff); *patlen = (int)(end - p); // parse the address range @@ -2602,14 +2602,14 @@ static void correct_screencol(int idx, int cells, int *col) /// /// @param c normally ':', NUL for ":append" /// @param indent indent for inside conditionals -char_u *getexline(int c, void *cookie, int indent, bool do_concat) +char *getexline(int c, void *cookie, int indent, bool do_concat) { // When executing a register, remove ':' that's in front of each line. if (exec_from_reg && vpeekc() == ':') { (void)vgetc(); } - return getcmdline(c, 1L, indent, do_concat); + return (char *)getcmdline(c, 1L, indent, do_concat); } bool cmdline_overstrike(void) @@ -2676,7 +2676,7 @@ static void realloc_cmdbuff(int len) } } -static char_u *arshape_buf = NULL; +static char *arshape_buf = NULL; #if defined(EXITFREE) void free_arshape_buf(void) @@ -3074,11 +3074,11 @@ static void draw_cmdline(int start, int len) u8c = arabic_shape(u8c, NULL, &u8cc[0], pc, pc1, nc); - newlen += utf_char2bytes(u8c, (char *)arshape_buf + newlen); + newlen += utf_char2bytes(u8c, arshape_buf + newlen); if (u8cc[0] != 0) { - newlen += utf_char2bytes(u8cc[0], (char *)arshape_buf + newlen); + newlen += utf_char2bytes(u8cc[0], arshape_buf + newlen); if (u8cc[1] != 0) { - newlen += utf_char2bytes(u8cc[1], (char *)arshape_buf + newlen); + newlen += utf_char2bytes(u8cc[1], arshape_buf + newlen); } } } else { @@ -3088,7 +3088,7 @@ static void draw_cmdline(int start, int len) } } - msg_outtrans_len(arshape_buf, newlen); + msg_outtrans_len((char_u *)arshape_buf, newlen); } else { draw_cmdline_no_arabicshape: if (kv_size(ccline.last_colors.colors)) { @@ -4491,7 +4491,7 @@ static int expand_showtail(expand_T *xp) return FALSE; } - end = path_tail((char_u *)xp->xp_pattern); + end = (char_u *)path_tail(xp->xp_pattern); if (end == (char_u *)xp->xp_pattern) { // there is no path separator return false; } @@ -4618,7 +4618,7 @@ char_u *addstar(char_u *fname, size_t len, int context) * ` could be anywhere in the file name. * When the name ends in '$' don't add a star, remove the '$'. */ - tail = path_tail(retval); + tail = (char_u *)path_tail((char *)retval); ends_in_star = (len > 0 && retval[len - 1] == '*'); #ifndef BACKSLASH_IN_FILENAME for (ssize_t k = (ssize_t)len - 2; k >= 0; k--) { @@ -4834,7 +4834,7 @@ static void cleanup_help_tags(int num_file, char_u **file) } } -typedef char_u *(*ExpandFunc)(expand_T *, int); +typedef char *(*ExpandFunc)(expand_T *, int); /// Do the expansion based on xp->xp_context and "pat". /// @@ -5099,8 +5099,8 @@ static void ExpandGeneric(expand_T *xp, regmatch_T *regmatch, int *num_file, cha char_u *str; // count the number of matching names - for (i = 0;; ++i) { - str = (*func)(xp, i); + for (i = 0;; i++) { + str = (char_u *)(*func)(xp, i); if (str == NULL) { // end of list break; } @@ -5121,7 +5121,7 @@ static void ExpandGeneric(expand_T *xp, regmatch_T *regmatch, int *num_file, cha // copy the matching names into allocated memory count = 0; for (i = 0;; i++) { - str = (*func)(xp, i); + str = (char_u *)(*func)(xp, i); if (str == NULL) { // End of list. break; } @@ -5571,7 +5571,7 @@ static int ExpandPackAddDir(char_u *pat, int *num_file, char_u ***file) for (int i = 0; i < ga.ga_len; i++) { char_u *match = ((char_u **)ga.ga_data)[i]; - s = path_tail(match); + s = (char_u *)path_tail((char *)match); memmove(match, s, STRLEN(s) + 1); } @@ -5678,7 +5678,7 @@ static char *(history_names[]) = * Function given to ExpandGeneric() to obtain the possible first * arguments of the ":history command. */ -static char_u *get_history_arg(expand_T *xp, int idx) +static char *get_history_arg(expand_T *xp, int idx) { static char_u compl[2] = { NUL, NUL }; char *short_names = ":=@>?/"; @@ -5687,13 +5687,13 @@ static char_u *get_history_arg(expand_T *xp, int idx) if (idx < short_names_count) { compl[0] = (char_u)short_names[idx]; - return compl; + return (char *)compl; } if (idx < short_names_count + history_name_count) { - return (char_u *)history_names[idx - short_names_count]; + return history_names[idx - short_names_count]; } if (idx == short_names_count + history_name_count) { - return (char_u *)"all"; + return "all"; } return NULL; } @@ -5960,9 +5960,9 @@ char_u *get_cmdline_completion(void) if (p != NULL && p->xpc != NULL) { set_expand_context(p->xpc); - char_u *cmd_compl = get_user_cmd_complete(p->xpc, p->xpc->xp_context); + char *cmd_compl = get_user_cmd_complete(p->xpc, p->xpc->xp_context); if (cmd_compl != NULL) { - return vim_strsave(cmd_compl); + return vim_strsave((char_u *)cmd_compl); } } @@ -6642,8 +6642,8 @@ char *script_get(exarg_T *const eap, size_t *const lenp) const char *const end_pattern = (cmd[2] != NUL ? (const char *)skipwhite(cmd + 2) : "."); for (;;) { - char *const theline = (char *)eap->getline(eap->cstack->cs_looplevel > 0 ? -1 : - NUL, eap->cookie, 0, true); + char *const theline = (char *)eap->getline(eap->cstack->cs_looplevel > 0 ? -1 : NUL, + eap->cookie, 0, true); if (theline == NULL || strcmp(end_pattern, theline) == 0) { xfree(theline); diff --git a/src/nvim/ex_getln.h b/src/nvim/ex_getln.h index fe2bf958b5..5da9febe71 100644 --- a/src/nvim/ex_getln.h +++ b/src/nvim/ex_getln.h @@ -48,7 +48,7 @@ typedef enum { /// Number of history tables #define HIST_COUNT (HIST_DEBUG + 1) -typedef char_u *(*CompleteListItemGetter)(expand_T *, int); +typedef char *(*CompleteListItemGetter)(expand_T *, int); /// History entry definition typedef struct hist_entry { diff --git a/src/nvim/ex_session.c b/src/nvim/ex_session.c index 0d95d7cf28..4554af5356 100644 --- a/src/nvim/ex_session.c +++ b/src/nvim/ex_session.c @@ -930,7 +930,7 @@ void ex_mkrc(exarg_T *eap) viewFile = fname; using_vdir = true; } else if (*eap->arg != NUL) { - fname = (char *)eap->arg; + fname = eap->arg; } else if (eap->cmdidx == CMD_mkvimrc) { fname = VIMRC_FILE; } else if (eap->cmdidx == CMD_mksession) { diff --git a/src/nvim/file_search.c b/src/nvim/file_search.c index 6a3acef91d..02db5ded75 100644 --- a/src/nvim/file_search.c +++ b/src/nvim/file_search.c @@ -298,7 +298,7 @@ void *vim_findfile_init(char_u *path, char_u *filename, char_u *stopdirs, int le && (vim_ispathsep(path[1]) || path[1] == NUL) && (!tagfile || vim_strchr(p_cpo, CPO_DOTTAG) == NULL) && rel_fname != NULL) { - size_t len = (size_t)(path_tail(rel_fname) - rel_fname); + size_t len = (size_t)((char_u *)path_tail((char *)rel_fname) - rel_fname); if (!vim_isAbsName(rel_fname) && len + 1 < MAXPATHL) { // Make the start dir an absolute path name. @@ -477,7 +477,7 @@ void *vim_findfile_init(char_u *path, char_u *filename, char_u *stopdirs, int le STRCAT(ff_expand_buffer, search_ctx->ffsc_fix_path); add_pathsep((char *)ff_expand_buffer); } else { - char_u *p = path_tail(search_ctx->ffsc_fix_path); + char_u *p = (char_u *)path_tail((char *)search_ctx->ffsc_fix_path); char_u *wc_path = NULL; char_u *temp = NULL; int len = 0; @@ -1481,7 +1481,7 @@ char_u *find_file_in_path_option(char_u *ptr, size_t len, int options, int first && rel_fname != NULL && STRLEN(rel_fname) + l < MAXPATHL) { STRCPY(NameBuff, rel_fname); - STRCPY(path_tail(NameBuff), ff_file_to_find); + STRCPY(path_tail((char *)NameBuff), ff_file_to_find); l = STRLEN(NameBuff); } else { STRCPY(NameBuff, ff_file_to_find); diff --git a/src/nvim/fileio.c b/src/nvim/fileio.c index c802920fa9..c412af0eaa 100644 --- a/src/nvim/fileio.c +++ b/src/nvim/fileio.c @@ -173,7 +173,7 @@ void filemess(buf_T *buf, char_u *name, char_u *s, int attr) /// @param eap can be NULL! /// /// @return FAIL for failure, NOTDONE for directory (failure), or OK -int readfile(char_u *fname, char_u *sfname, linenr_T from, linenr_T lines_to_skip, +int readfile(char *fname, char *sfname, linenr_T from, linenr_T lines_to_skip, linenr_T lines_to_read, exarg_T *eap, int flags, bool silent) { int fd = stdin_fd >= 0 ? stdin_fd : 0; @@ -189,10 +189,10 @@ int readfile(char_u *fname, char_u *sfname, linenr_T from, linenr_T lines_to_ski colnr_T read_buf_col = 0; // next char to read from this line char_u c; linenr_T lnum = from; - char_u *ptr = NULL; // pointer into read buffer - char_u *buffer = NULL; // read buffer - char_u *new_buffer = NULL; // init to shut up gcc - char_u *line_start = NULL; // init to shut up gcc + char *ptr = NULL; // pointer into read buffer + char *buffer = NULL; // read buffer + char *new_buffer = NULL; // init to shut up gcc + char *line_start = NULL; // init to shut up gcc int wasempty; // buffer was empty before reading colnr_T len; long size = 0; @@ -227,11 +227,11 @@ int readfile(char_u *fname, char_u *sfname, linenr_T from, linenr_T lines_to_ski int bad_char_behavior = BAD_REPLACE; // BAD_KEEP, BAD_DROP or character to // replace with - char_u *tmpname = NULL; // name of 'charconvert' output file + char *tmpname = NULL; // name of 'charconvert' output file int fio_flags = 0; - char_u *fenc; // fileencoding to use + char *fenc; // fileencoding to use bool fenc_alloced; // fenc_next is in allocated memory - char_u *fenc_next = NULL; // next item in 'fencs' or NULL + char *fenc_next = NULL; // next item in 'fencs' or NULL bool advance_fenc = false; long real_size = 0; #ifdef HAVE_ICONV @@ -241,12 +241,12 @@ int readfile(char_u *fname, char_u *sfname, linenr_T from, linenr_T lines_to_ski #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]; + char conv_rest[CONV_RESTLEN]; int conv_restlen = 0; // nr of bytes in conv_rest[] pos_T orig_start; buf_T *old_curbuf; - char_u *old_b_ffname; - char_u *old_b_fname; + char *old_b_ffname; + char *old_b_fname; int using_b_ffname; int using_b_fname; static char *msg_is_a_directory = N_("is a directory"); @@ -266,7 +266,7 @@ int readfile(char_u *fname, char_u *sfname, linenr_T from, linenr_T lines_to_ski && fname != NULL && vim_strchr(p_cpo, CPO_FNAMER) != NULL && !(flags & READ_DUMMY)) { - if (set_rw_fname(fname, sfname) == FAIL) { + if (set_rw_fname((char_u *)fname, (char_u *)sfname) == FAIL) { return FAIL; } } @@ -276,11 +276,11 @@ int readfile(char_u *fname, char_u *sfname, linenr_T from, linenr_T lines_to_ski // executing nasty autocommands. Also check if "fname" and "sfname" // point to one of these values. old_curbuf = curbuf; - old_b_ffname = curbuf->b_ffname; - old_b_fname = curbuf->b_fname; - using_b_ffname = (fname == curbuf->b_ffname) - || (sfname == curbuf->b_ffname); - using_b_fname = (fname == curbuf->b_fname) || (sfname == curbuf->b_fname); + old_b_ffname = (char *)curbuf->b_ffname; + old_b_fname = (char *)curbuf->b_fname; + using_b_ffname = ((char_u *)fname == curbuf->b_ffname) + || ((char_u *)sfname == curbuf->b_ffname); + using_b_fname = ((char_u *)fname == curbuf->b_fname) || ((char_u *)sfname == curbuf->b_fname); // After reading a file the cursor line changes but we don't want to // display the line. @@ -347,7 +347,7 @@ int readfile(char_u *fname, char_u *sfname, linenr_T from, linenr_T lines_to_ski // If the name is too long we might crash further on, quit here. if (namelen >= MAXPATHL) { - filemess(curbuf, fname, (char_u *)_("Illegal file name"), 0); + filemess(curbuf, (char_u *)fname, (char_u *)_("Illegal file name"), 0); msg_end(); msg_scroll = msg_save; return FAIL; @@ -356,9 +356,9 @@ int readfile(char_u *fname, char_u *sfname, linenr_T from, linenr_T lines_to_ski // If the name ends in a path separator, we can't open it. Check here, // because reading the file may actually work, but then creating the // swap file may destroy it! Reported on MS-DOS and Win 95. - if (after_pathsep((const char *)fname, (const char *)(fname + namelen))) { + if (after_pathsep(fname, fname + namelen)) { if (!silent) { - filemess(curbuf, fname, (char_u *)_(msg_is_a_directory), 0); + filemess(curbuf, (char_u *)fname, (char_u *)_(msg_is_a_directory), 0); } msg_end(); msg_scroll = msg_save; @@ -367,23 +367,23 @@ int readfile(char_u *fname, char_u *sfname, linenr_T from, linenr_T lines_to_ski } if (!read_buffer && !read_stdin && !read_fifo) { - perm = os_getperm((const char *)fname); + perm = os_getperm(fname); // On Unix it is possible to read a directory, so we have to // check for it before os_open(). if (perm >= 0 && !S_ISREG(perm) // not a regular file ... && !S_ISFIFO(perm) // ... or fifo && !S_ISSOCK(perm) // ... or socket #ifdef OPEN_CHR_FILES - && !(S_ISCHR(perm) && is_dev_fd_file(fname)) + && !(S_ISCHR(perm) && is_dev_fd_file((char_u *)fname)) // ... or a character special file named /dev/fd/<n> #endif ) { if (S_ISDIR(perm)) { if (!silent) { - filemess(curbuf, fname, (char_u *)_(msg_is_a_directory), 0); + filemess(curbuf, (char_u *)fname, (char_u *)_(msg_is_a_directory), 0); } } else { - filemess(curbuf, fname, (char_u *)_("is not a file"), 0); + filemess(curbuf, (char_u *)fname, (char_u *)_("is not a file"), 0); } msg_end(); msg_scroll = msg_save; @@ -407,7 +407,7 @@ int readfile(char_u *fname, char_u *sfname, linenr_T from, linenr_T lines_to_ski if (newfile && !read_stdin && !read_buffer && !read_fifo) { // Remember time of file. - if (os_fileinfo((char *)fname, &file_info)) { + if (os_fileinfo(fname, &file_info)) { buf_store_file_info(curbuf, &file_info); curbuf->b_mtime_read = curbuf->b_mtime; curbuf->b_mtime_read_ns = curbuf->b_mtime_ns; @@ -443,10 +443,10 @@ int readfile(char_u *fname, char_u *sfname, linenr_T from, linenr_T lines_to_ski bool file_readonly = false; if (!read_buffer && !read_stdin) { if (!newfile || readonlymode || !(perm & 0222) - || !os_file_is_writable((char *)fname)) { + || !os_file_is_writable(fname)) { file_readonly = true; } - fd = os_open((char *)fname, O_RDONLY, 0); + fd = os_open(fname, O_RDONLY, 0); } if (fd < 0) { // cannot open at all @@ -467,18 +467,18 @@ int readfile(char_u *fname, char_u *sfname, linenr_T from, linenr_T lines_to_ski // SwapExists autocommand may mess things up if (curbuf != old_curbuf || (using_b_ffname - && (old_b_ffname != curbuf->b_ffname)) + && ((char_u *)old_b_ffname != curbuf->b_ffname)) || (using_b_fname - && (old_b_fname != curbuf->b_fname))) { + && ((char_u *)old_b_fname != curbuf->b_fname))) { emsg(_(e_auchangedbuf)); return FAIL; } } if (!silent) { - if (dir_of_file_exists(fname)) { - filemess(curbuf, sfname, (char_u *)new_file_message(), 0); + if (dir_of_file_exists((char_u *)fname)) { + filemess(curbuf, (char_u *)sfname, (char_u *)new_file_message(), 0); } else { - filemess(curbuf, sfname, (char_u *)_("[New DIRECTORY]"), 0); + filemess(curbuf, (char_u *)sfname, (char_u *)_("[New DIRECTORY]"), 0); } } // Even though this is a new file, it might have been @@ -498,15 +498,16 @@ int readfile(char_u *fname, char_u *sfname, linenr_T from, linenr_T lines_to_ski } return OK; // a new file is not an error } else { - filemess(curbuf, sfname, (char_u *)( - (fd == UV_EFBIG) ? _("[File too big]") : + filemess(curbuf, (char_u *)sfname, (char_u *)((fd == UV_EFBIG) ? _("[File too big]") : #if defined(UNIX) && defined(EOVERFLOW) - // libuv only returns -errno in Unix and in Windows open() does not - // set EOVERFLOW - (fd == -EOVERFLOW) ? _("[File too big]") : + // libuv only returns -errno + // in Unix and in Windows + // open() does not set + // EOVERFLOW + (fd == -EOVERFLOW) ? _("[File too big]") : #endif - _("[Permission Denied]")), 0); - curbuf->b_p_ro = TRUE; // must use "w!" now + _("[Permission Denied]")), 0); + curbuf->b_p_ro = true; // must use "w!" now } return FAIL; @@ -538,8 +539,8 @@ int readfile(char_u *fname, char_u *sfname, linenr_T from, linenr_T lines_to_ski check_need_swap(newfile); if (!read_stdin && (curbuf != old_curbuf - || (using_b_ffname && (old_b_ffname != curbuf->b_ffname)) - || (using_b_fname && (old_b_fname != curbuf->b_fname)))) { + || (using_b_ffname && ((char_u *)old_b_ffname != curbuf->b_ffname)) + || (using_b_fname && ((char_u *)old_b_fname != curbuf->b_fname)))) { emsg(_(e_auchangedbuf)); if (!read_buffer) { close(fd); @@ -644,10 +645,10 @@ int readfile(char_u *fname, char_u *sfname, linenr_T from, linenr_T lines_to_ski * (cd for example) if it invalidates fname or sfname. */ if (!read_stdin && (curbuf != old_curbuf - || (using_b_ffname && (old_b_ffname != curbuf->b_ffname)) - || (using_b_fname && (old_b_fname != curbuf->b_fname)) - || (fd = os_open((char *)fname, O_RDONLY, 0)) < 0)) { - --no_wait_return; + || (using_b_ffname && ((char_u *)old_b_ffname != curbuf->b_ffname)) + || (using_b_fname && ((char_u *)old_b_fname != curbuf->b_fname)) + || (fd = os_open(fname, O_RDONLY, 0)) < 0)) { + no_wait_return--; msg_scroll = msg_save; if (fd < 0) { emsg(_("E200: *ReadPre autocommands made the file unreadable")); @@ -664,7 +665,7 @@ int readfile(char_u *fname, char_u *sfname, linenr_T from, linenr_T lines_to_ski if (!recoverymode && !filtering && !(flags & READ_DUMMY) && !silent) { if (!read_stdin && !read_buffer) { - filemess(curbuf, sfname, (char_u *)"", 0); + filemess(curbuf, (char_u *)sfname, (char_u *)"", 0); } } @@ -690,27 +691,27 @@ int readfile(char_u *fname, char_u *sfname, linenr_T from, linenr_T lines_to_ski * Decide which 'encoding' to use or use first. */ if (eap != NULL && eap->force_enc != 0) { - fenc = enc_canonize((char_u *)eap->cmd + eap->force_enc); + fenc = (char *)enc_canonize((char_u *)eap->cmd + eap->force_enc); fenc_alloced = true; keep_dest_enc = true; } else if (curbuf->b_p_bin) { - fenc = (char_u *)""; // binary: don't convert + fenc = ""; // binary: don't convert fenc_alloced = false; } else if (curbuf->b_help) { // Help files are either utf-8 or latin1. Try utf-8 first, if this // fails it must be latin1. // It is needed when the first line contains non-ASCII characters. // That is only in *.??x files. - fenc_next = (char_u *)"latin1"; - fenc = (char_u *)"utf-8"; + fenc_next = "latin1"; + fenc = "utf-8"; fenc_alloced = false; } else if (*p_fencs == NUL) { - fenc = curbuf->b_p_fenc; // use format from buffer + fenc = (char *)curbuf->b_p_fenc; // use format from buffer fenc_alloced = false; } else { - fenc_next = p_fencs; // try items in 'fileencodings' - fenc = next_fenc(&fenc_next, &fenc_alloced); + fenc_next = (char *)p_fencs; // try items in 'fileencodings' + fenc = (char *)next_fenc((char_u **)&fenc_next, &fenc_alloced); } /* @@ -797,21 +798,21 @@ retry: if (fenc_alloced) { xfree(fenc); } - fenc = (char_u *)""; + fenc = ""; fenc_alloced = false; } else { if (fenc_alloced) { xfree(fenc); } if (fenc_next != NULL) { - fenc = next_fenc(&fenc_next, &fenc_alloced); + fenc = (char *)next_fenc((char_u **)&fenc_next, &fenc_alloced); } else { - fenc = (char_u *)""; + fenc = ""; fenc_alloced = false; } } if (tmpname != NULL) { - os_remove((char *)tmpname); // delete converted file + os_remove(tmpname); // delete converted file XFREE_CLEAR(tmpname); } } @@ -821,7 +822,7 @@ retry: * from 'encoding' or 'encoding' is UTF-16, UCS-2 or UCS-4. */ fio_flags = 0; - converted = need_conversion(fenc); + converted = need_conversion((char_u *)fenc); if (converted) { // "ucs-bom" means we need to check the first bytes of the file // for a BOM. @@ -835,7 +836,7 @@ retry: // appears not to handle this correctly. This works just like // conversion to UTF-8 except how the resulting character is put in // the buffer. - fio_flags = get_fio_flags(fenc); + fio_flags = get_fio_flags((char_u *)fenc); } @@ -843,7 +844,7 @@ retry: // 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); + iconv_fd = (iconv_t)my_iconv_open((char_u *)"utf-8", (char_u *)fenc); } #endif @@ -863,7 +864,7 @@ retry: // Skip conversion when it's already done (retry for wrong // "fileformat"). if (tmpname == NULL) { - tmpname = readfile_charconvert(fname, fenc, &fd); + tmpname = (char *)readfile_charconvert((char_u *)fname, (char_u *)fenc, &fd); if (tmpname == NULL) { // Conversion failed. Try another one. advance_fenc = true; @@ -1128,8 +1129,8 @@ retry: if (size < 2 || curbuf->b_p_bin) { ccname = NULL; } else { - ccname = check_for_bom(ptr, size, &blen, - fio_flags == FIO_UCSBOM ? FIO_ALL : get_fio_flags(fenc)); + ccname = check_for_bom((char_u *)ptr, size, &blen, + fio_flags == FIO_UCSBOM ? FIO_ALL : get_fio_flags((char_u *)fenc)); } if (ccname != NULL) { // Remove BOM from the text @@ -1151,7 +1152,7 @@ retry: if (fenc_alloced) { xfree(fenc); } - fenc = ccname; + fenc = (char *)ccname; fenc_alloced = false; } // retry reading without getting new bytes or rewinding @@ -1182,10 +1183,10 @@ retry: size_t from_size; size_t to_size; - fromp = (char *)ptr; + fromp = ptr; from_size = size; ptr += size; - top = (char *)ptr; + top = ptr; to_size = real_size - size; /* @@ -1201,8 +1202,7 @@ retry: goto rewind_retry; } if (conv_error == 0) { - conv_error = readfile_linenr(linecnt, - ptr, (char_u *)top); + conv_error = readfile_linenr(linecnt, (char_u *)ptr, (char_u *)top); } // Deal with a bad byte and continue with the next. @@ -1227,14 +1227,14 @@ retry: // move the linerest to before the converted characters line_start = ptr - linerest; memmove(line_start, buffer, (size_t)linerest); - size = ((char_u *)top - ptr); + size = (top - ptr); } #endif if (fio_flags != 0) { unsigned int u8c; - char_u *dest; - char_u *tail = NULL; + char *dest; + char *tail = NULL; // Convert Unicode or Latin1 to UTF-8. // Go from end to start through the buffer, because the number @@ -1243,7 +1243,7 @@ retry: // to after the next character to convert. dest = ptr + real_size; if (fio_flags == FIO_LATIN1 || fio_flags == FIO_UTF8) { - p = ptr + size; + p = (uint8_t *)ptr + size; if (fio_flags == FIO_UTF8) { // Check for a trailing incomplete UTF-8 sequence tail = ptr + size - 1; @@ -1253,16 +1253,16 @@ retry: if (tail + utf_byte2len(*tail) <= ptr + size) { tail = NULL; } else { - p = tail; + p = (uint8_t *)tail; } } } else if (fio_flags & (FIO_UCS2 | FIO_UTF16)) { // Check for a trailing byte - p = ptr + (size & ~1); + p = (uint8_t *)ptr + (size & ~1); if (size & 1) { - tail = p; + tail = (char *)p; } - if ((fio_flags & FIO_UTF16) && p > ptr) { + if ((fio_flags & FIO_UTF16) && p > (uint8_t *)ptr) { // Check for a trailing leading word if (fio_flags & FIO_ENDIAN_L) { u8c = (*--p << 8); @@ -1272,16 +1272,16 @@ retry: u8c += (*--p << 8); } if (u8c >= 0xd800 && u8c <= 0xdbff) { - tail = p; + tail = (char *)p; } else { p += 2; } } } else { // FIO_UCS4 // Check for trailing 1, 2 or 3 bytes - p = ptr + (size & ~3); + p = (uint8_t *)ptr + (size & ~3); if (size & 3) { - tail = p; + tail = (char *)p; } } @@ -1294,7 +1294,7 @@ retry: } - while (p > ptr) { + while (p > (uint8_t *)ptr) { if (fio_flags & FIO_LATIN1) { u8c = *--p; } else if (fio_flags & (FIO_UCS2 | FIO_UTF16)) { @@ -1309,14 +1309,13 @@ retry: && u8c >= 0xdc00 && u8c <= 0xdfff) { int u16c; - if (p == ptr) { + if (p == (uint8_t *)ptr) { // Missing leading word. if (can_retry) { goto rewind_retry; } if (conv_error == 0) { - conv_error = readfile_linenr(linecnt, - ptr, p); + conv_error = readfile_linenr(linecnt, (char_u *)ptr, p); } if (bad_char_behavior == BAD_DROP) { continue; @@ -1344,8 +1343,7 @@ retry: goto rewind_retry; } if (conv_error == 0) { - conv_error = readfile_linenr(linecnt, - ptr, p); + conv_error = readfile_linenr(linecnt, (char_u *)ptr, p); } if (bad_char_behavior == BAD_DROP) { continue; @@ -1375,7 +1373,7 @@ retry: if (*--p < 0x80) { u8c = *p; } else { - len = utf_head_off(ptr, p); + len = utf_head_off((char_u *)ptr, p); p -= len; u8c = utf_ptr2char((char *)p); if (len == 0) { @@ -1386,8 +1384,7 @@ retry: goto rewind_retry; } if (conv_error == 0) { - conv_error = readfile_linenr(linecnt, - ptr, p); + conv_error = readfile_linenr(linecnt, (char_u *)ptr, p); } if (bad_char_behavior == BAD_DROP) { continue; @@ -1401,7 +1398,7 @@ retry: assert(u8c <= INT_MAX); // produce UTF-8 dest -= utf_char2len((int)u8c); - (void)utf_char2bytes((int)u8c, (char *)dest); + (void)utf_char2bytes((int)u8c, dest); } // move the linerest to before the converted characters @@ -1413,8 +1410,8 @@ retry: bool incomplete_tail = false; // Reading UTF-8: Check if the bytes are valid UTF-8. - for (p = ptr;; p++) { - int todo = (int)((ptr + size) - p); + for (p = (uint8_t *)ptr;; p++) { + int todo = (int)(((uint8_t *)ptr + size) - p); int l; if (todo <= 0) { @@ -1431,13 +1428,13 @@ retry: // a truncated file is more likely, or attempting // to read the rest of an incomplete sequence when // we have already done so. - if (p > ptr || filesize > 0) { + if (p > (uint8_t *)ptr || filesize > 0) { incomplete_tail = true; } // Incomplete byte sequence, move it to conv_rest[] // and try to read the rest of it, unless we've // already done so. - if (p > ptr) { + if (p > (uint8_t *)ptr) { conv_restlen = todo; memmove(conv_rest, p, conv_restlen); size -= conv_restlen; @@ -1454,12 +1451,12 @@ retry: #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); + conv_error = readfile_linenr(linecnt, (char_u *)ptr, p); } #endif // Remember the first linenr with an illegal byte if (conv_error == 0 && illegal_byte == 0) { - illegal_byte = readfile_linenr(linecnt, ptr, p); + illegal_byte = readfile_linenr(linecnt, (char_u *)ptr, p); } // Drop, keep or replace the bad byte. @@ -1475,7 +1472,7 @@ retry: } } } - if (p < ptr + size && !incomplete_tail) { + if (p < (uint8_t *)ptr + size && !incomplete_tail) { // Detected a UTF-8 error. rewind_retry: // Retry reading with another conversion. @@ -1509,10 +1506,10 @@ rewind_retry: try_mac = 1; } - for (p = ptr; p < ptr + size; ++p) { + for (p = (uint8_t *)ptr; p < (uint8_t *)ptr + size; p++) { if (*p == NL) { if (!try_unix - || (try_dos && p > ptr && p[-1] == CAR)) { + || (try_dos && p > (uint8_t *)ptr && p[-1] == CAR)) { fileformat = EOL_DOS; } else { fileformat = EOL_UNIX; @@ -1528,9 +1525,9 @@ rewind_retry: // Need to reset the counters when retrying fenc. try_mac = 1; try_unix = 1; - for (; p >= ptr && *p != CAR; p--) {} - if (p >= ptr) { - for (p = ptr; p < ptr + size; ++p) { + for (; p >= (uint8_t *)ptr && *p != CAR; p--) {} + if (p >= (uint8_t *)ptr) { + for (p = (uint8_t *)ptr; p < (uint8_t *)ptr + size; p++) { if (*p == NL) { try_unix++; } else if (*p == CAR) { @@ -1584,12 +1581,12 @@ rewind_retry: if (skip_count == 0) { *ptr = NUL; // end of line len = (colnr_T)(ptr - line_start + 1); - if (ml_append(lnum, (char *)line_start, len, newfile) == FAIL) { + if (ml_append(lnum, line_start, len, newfile) == FAIL) { error = true; break; } if (read_undo_file) { - sha256_update(&sha_ctx, line_start, len); + sha256_update(&sha_ctx, (char_u *)line_start, len); } ++lnum; if (--read_count == 0) { @@ -1640,12 +1637,12 @@ rewind_retry: ff_error = EOL_DOS; } } - if (ml_append(lnum, (char *)line_start, len, newfile) == FAIL) { + if (ml_append(lnum, line_start, len, newfile) == FAIL) { error = true; break; } if (read_undo_file) { - sha256_update(&sha_ctx, line_start, len); + sha256_update(&sha_ctx, (char_u *)line_start, len); } ++lnum; if (--read_count == 0) { @@ -1688,11 +1685,11 @@ failed: } *ptr = NUL; len = (colnr_T)(ptr - line_start + 1); - if (ml_append(lnum, (char *)line_start, len, newfile) == FAIL) { + if (ml_append(lnum, line_start, len, newfile) == FAIL) { error = true; } else { if (read_undo_file) { - sha256_update(&sha_ctx, line_start, len); + sha256_update(&sha_ctx, (char_u *)line_start, len); } read_no_eol_lnum = ++lnum; } @@ -1703,7 +1700,7 @@ failed: save_file_ff(curbuf); // If editing a new file: set 'fenc' for the current buffer. // Also for ":read ++edit file". - set_string_option_direct("fenc", -1, fenc, OPT_FREE | OPT_LOCAL, 0); + set_string_option_direct("fenc", -1, (char_u *)fenc, OPT_FREE | OPT_LOCAL, 0); } if (fenc_alloced) { xfree(fenc); @@ -1738,7 +1735,7 @@ failed: } if (tmpname != NULL) { - os_remove((char *)tmpname); // delete converted file + os_remove(tmpname); // delete converted file xfree(tmpname); } --no_wait_return; // may wait for return now @@ -1783,7 +1780,7 @@ failed: if (got_int) { if (!(flags & READ_DUMMY)) { - filemess(curbuf, sfname, (char_u *)_(e_interr), 0); + filemess(curbuf, (char_u *)sfname, (char_u *)_(e_interr), 0); if (newfile) { curbuf->b_p_ro = TRUE; // must use "w!" now } @@ -1932,7 +1929,7 @@ failed: char_u hash[UNDO_HASH_SIZE]; sha256_finish(&sha_ctx, hash); - u_read_undo(NULL, hash, fname); + u_read_undo(NULL, hash, (char_u *)fname); } if (!read_stdin && !read_fifo && (!read_buffer || sfname != NULL)) { @@ -1993,7 +1990,7 @@ bool is_dev_fd_file(char_u *fname) { return STRNCMP(fname, "/dev/fd/", 8) == 0 && ascii_isdigit(fname[8]) - && *skipdigits(fname + 9) == NUL + && *skipdigits((char *)fname + 9) == NUL && (fname[9] != NUL || (fname[8] != '0' && fname[8] != '1' && fname[8] != '2')); } @@ -2188,18 +2185,18 @@ char *new_file_message(void) /// @param append append to the file /// /// @return FAIL for failure, OK otherwise -int buf_write(buf_T *buf, char_u *fname, char_u *sfname, linenr_T start, linenr_T end, exarg_T *eap, +int buf_write(buf_T *buf, char *fname, char *sfname, linenr_T start, linenr_T end, exarg_T *eap, int append, int forceit, int reset_changed, int filtering) { int fd; - char_u *backup = NULL; - int backup_copy = FALSE; // copy the original file? + char *backup = NULL; + int backup_copy = false; // copy the original file? int dobackup; - char_u *ffname; - char_u *wfname = NULL; // name of file to write to - char_u *s; - char_u *ptr; - char_u c; + char *ffname; + char *wfname = NULL; // name of file to write to + char *s; + char *ptr; + char c; int len; linenr_T lnum; long nchars; @@ -2213,9 +2210,9 @@ int buf_write(buf_T *buf, char_u *fname, char_u *sfname, linenr_T start, linenr_ char *errmsg = NULL; int errmsgarg = 0; bool errmsg_allocated = false; - char_u *buffer; - char_u smallbuf[SMBUFSIZE]; - char_u *backup_ext; + char *buffer; + char smallbuf[SMBUFSIZE]; + char *backup_ext; int bufsize; long perm; // file permissions int retval = OK; @@ -2238,10 +2235,10 @@ int buf_write(buf_T *buf, char_u *fname, char_u *sfname, linenr_T start, linenr_ int fileformat; int write_bin; struct bw_info write_info; // info for buf_write_bytes() - int converted = FALSE; - int notconverted = FALSE; - char_u *fenc; // effective 'fileencoding' - char_u *fenc_tofree = NULL; // allocated "fenc" + int converted = false; + int notconverted = false; + char *fenc; // effective 'fileencoding' + char *fenc_tofree = NULL; // allocated "fenc" #ifdef HAS_BW_FLAGS int wb_flags = 0; #endif @@ -2307,7 +2304,7 @@ int buf_write(buf_T *buf, char_u *fname, char_u *sfname, linenr_T start, linenr_ && !filtering && (!append || vim_strchr(p_cpo, CPO_FNAMEAPP) != NULL) && vim_strchr(p_cpo, CPO_FNAMEW) != NULL) { - if (set_rw_fname(fname, sfname) == FAIL) { + if (set_rw_fname((char_u *)fname, (char_u *)sfname) == FAIL) { return FAIL; } buf = curbuf; // just in case autocmds made "buf" invalid @@ -2358,17 +2355,17 @@ int buf_write(buf_T *buf, char_u *fname, char_u *sfname, linenr_T start, linenr_ * Set curbuf to the buffer to be written. * Careful: The autocommands may call buf_write() recursively! */ - if (ffname == buf->b_ffname) { - buf_ffname = TRUE; + if ((char_u *)ffname == buf->b_ffname) { + buf_ffname = true; } - if (sfname == buf->b_sfname) { - buf_sfname = TRUE; + if ((char_u *)sfname == buf->b_sfname) { + buf_sfname = true; } - if (fname == buf->b_ffname) { - buf_fname_f = TRUE; + if ((char_u *)fname == buf->b_ffname) { + buf_fname_f = true; } - if (fname == buf->b_sfname) { - buf_fname_s = TRUE; + if ((char_u *)fname == buf->b_sfname) { + buf_fname_s = true; } // Set curwin/curbuf to buf and save a few things. @@ -2508,16 +2505,16 @@ int buf_write(buf_T *buf, char_u *fname, char_u *sfname, linenr_T start, linenr_ * be kept in fname, ffname and sfname. */ if (buf_ffname) { - ffname = buf->b_ffname; + ffname = (char *)buf->b_ffname; } if (buf_sfname) { - sfname = buf->b_sfname; + sfname = (char *)buf->b_sfname; } if (buf_fname_f) { - fname = buf->b_ffname; + fname = (char *)buf->b_ffname; } if (buf_fname_s) { - fname = buf->b_sfname; + fname = (char *)buf->b_sfname; } } @@ -2535,9 +2532,9 @@ int buf_write(buf_T *buf, char_u *fname, char_u *sfname, linenr_T start, linenr_ if (!filtering) { filemess(buf, #ifndef UNIX - sfname, + (char_u *)sfname, #else - fname, + (char_u *)fname, #endif (char_u *)"", 0); // show that we are busy } @@ -2559,8 +2556,8 @@ int buf_write(buf_T *buf, char_u *fname, char_u *sfname, linenr_T start, linenr_ FileInfo file_info_old; #if defined(UNIX) perm = -1; - if (!os_fileinfo((char *)fname, &file_info_old)) { - newfile = TRUE; + if (!os_fileinfo(fname, &file_info_old)) { + newfile = true; } else { perm = file_info_old.stat.st_mode; if (!S_ISREG(file_info_old.stat.st_mode)) { // not a file @@ -2568,7 +2565,7 @@ int buf_write(buf_T *buf, char_u *fname, char_u *sfname, linenr_T start, linenr_ SET_ERRMSG_NUM("E502", _("is a directory")); goto fail; } - if (os_nodetype((char *)fname) != NODE_WRITABLE) { + if (os_nodetype(fname) != NODE_WRITABLE) { SET_ERRMSG_NUM("E503", _("is not a file or writable device")); goto fail; } @@ -2609,7 +2606,7 @@ int buf_write(buf_T *buf, char_u *fname, char_u *sfname, linenr_T start, linenr_ * Check if the file is really writable (when renaming the file to * make a backup we won't discover it later). */ - file_readonly = !os_file_is_writable((char *)fname); + file_readonly = !os_file_is_writable(fname); if (!forceit && file_readonly) { if (vim_strchr(p_cpo, CPO_FWRITE) != NULL) { @@ -2636,7 +2633,7 @@ int buf_write(buf_T *buf, char_u *fname, char_u *sfname, linenr_T start, linenr_ * For systems that support ACL: get the ACL from the original file. */ if (!newfile) { - acl = mch_get_acl(fname); + acl = mch_get_acl((char_u *)fname); } #endif @@ -2644,8 +2641,8 @@ int buf_write(buf_T *buf, char_u *fname, char_u *sfname, linenr_T start, linenr_ * If 'backupskip' is not empty, don't make a backup for some files. */ dobackup = (p_wb || p_bk || *p_pm != NUL); - if (dobackup && *p_bsk != NUL && match_file_list(p_bsk, sfname, ffname)) { - dobackup = FALSE; + if (dobackup && *p_bsk != NUL && match_file_list(p_bsk, (char_u *)sfname, (char_u *)ffname)) { + dobackup = false; } /* @@ -2683,7 +2680,7 @@ int buf_write(buf_T *buf, char_u *fname, char_u *sfname, linenr_T start, linenr_ * - we don't have write permission in the directory */ if (os_fileinfo_hardlinks(&file_info_old) > 1 - || !os_fileinfo_link((char *)fname, &file_info) + || !os_fileinfo_link(fname, &file_info) || !os_fileinfo_id_equal(&file_info, &file_info_old)) { backup_copy = TRUE; } else { @@ -2695,7 +2692,9 @@ int buf_write(buf_T *buf, char_u *fname, char_u *sfname, linenr_T start, linenr_ */ STRCPY(IObuff, fname); for (i = 4913;; i += 123) { - sprintf((char *)path_tail(IObuff), "%d", i); + char *tail = path_tail((char *)IObuff); + size_t size = (char_u *)tail - IObuff; + snprintf(tail, IOSIZE - size, "%d", i); if (!os_fileinfo_link((char *)IObuff, &file_info)) { break; } @@ -2727,7 +2726,7 @@ int buf_write(buf_T *buf, char_u *fname, char_u *sfname, linenr_T start, linenr_ */ if ((bkc & BKC_BREAKSYMLINK) || (bkc & BKC_BREAKHARDLINK)) { #ifdef UNIX - bool file_info_link_ok = os_fileinfo_link((char *)fname, &file_info); + bool file_info_link_ok = os_fileinfo_link(fname, &file_info); // Symlinks. if ((bkc & BKC_BREAKSYMLINK) @@ -2748,17 +2747,17 @@ int buf_write(buf_T *buf, char_u *fname, char_u *sfname, linenr_T start, linenr_ // make sure we have a valid backup extension to use if (*p_bex == NUL) { - backup_ext = (char_u *)".bak"; + backup_ext = ".bak"; } else { - backup_ext = p_bex; + backup_ext = (char *)p_bex; } if (backup_copy) { - char_u *wp; + char *wp; int some_error = false; - char_u *dirp; - char_u *rootname; - char_u *p; + char *dirp; + char *rootname; + char *p; /* * Try to make the backup in each directory in the 'bdir' option. @@ -2772,14 +2771,14 @@ int buf_write(buf_T *buf, char_u *fname, char_u *sfname, linenr_T start, linenr_ * For these reasons, the existing writable file must be truncated * and reused. Creation of a backup COPY will be attempted. */ - dirp = p_bdir; + dirp = (char *)p_bdir; while (*dirp) { /* * Isolate one directory name, using an entry in 'bdir'. */ - size_t dir_len = copy_option_part(&dirp, IObuff, IOSIZE, ","); - p = IObuff + dir_len; - bool trailing_pathseps = after_pathsep((char *)IObuff, (char *)p) && p[-1] == p[-2]; + size_t dir_len = copy_option_part((char_u **)&dirp, IObuff, IOSIZE, ","); + p = (char *)IObuff + dir_len; + bool trailing_pathseps = after_pathsep((char *)IObuff, p) && p[-1] == p[-2]; if (trailing_pathseps) { IObuff[dir_len - 2] = NUL; } @@ -2794,15 +2793,14 @@ int buf_write(buf_T *buf, char_u *fname, char_u *sfname, linenr_T start, linenr_ } if (trailing_pathseps) { // Ends with '//', Use Full path - if ((p = (char_u *)make_percent_swname((char *)IObuff, (char *)fname)) + if ((p = make_percent_swname((char *)IObuff, fname)) != NULL) { - backup = (char_u *)modname((char *)p, (char *)backup_ext, - no_prepend_dot); + backup = modname(p, backup_ext, no_prepend_dot); xfree(p); } } - rootname = get_file_in_dir(fname, IObuff); + rootname = (char *)get_file_in_dir((char_u *)fname, IObuff); if (rootname == NULL) { some_error = TRUE; // out of memory goto nobackup; @@ -2814,8 +2812,7 @@ int buf_write(buf_T *buf, char_u *fname, char_u *sfname, linenr_T start, linenr_ // Make the backup file name. // if (backup == NULL) { - backup = (char_u *)modname((char *)rootname, (char *)backup_ext, - no_prepend_dot); + backup = modname(rootname, backup_ext, no_prepend_dot); } if (backup == NULL) { @@ -2827,7 +2824,7 @@ int buf_write(buf_T *buf, char_u *fname, char_u *sfname, linenr_T start, linenr_ /* * Check if backup file already exists. */ - if (os_fileinfo((char *)backup, &file_info_new)) { + if (os_fileinfo(backup, &file_info_new)) { if (os_fileinfo_id_equal(&file_info_new, &file_info_old)) { // // Backup file is same as original file. @@ -2846,9 +2843,8 @@ int buf_write(buf_T *buf, char_u *fname, char_u *sfname, linenr_T start, linenr_ wp = backup; } *wp = 'z'; - while (*wp > 'a' - && os_fileinfo((char *)backup, &file_info_new)) { - --*wp; + while (*wp > 'a' && os_fileinfo(backup, &file_info_new)) { + (*wp)--; } // They all exist??? Must be something wrong. if (*wp == 'a') { @@ -2864,7 +2860,7 @@ int buf_write(buf_T *buf, char_u *fname, char_u *sfname, linenr_T start, linenr_ */ if (backup != NULL) { // remove old backup, if present - os_remove((char *)backup); + os_remove(backup); // set file protection same as original file, but // strip s-bit. @@ -2877,26 +2873,26 @@ int buf_write(buf_T *buf, char_u *fname, char_u *sfname, linenr_T start, linenr_ // protection bits for others. // if (file_info_new.stat.st_gid != file_info_old.stat.st_gid - && os_chown((char *)backup, -1, file_info_old.stat.st_gid) != 0) { + && os_chown(backup, -1, file_info_old.stat.st_gid) != 0) { os_setperm((const char *)backup, (perm & 0707) | ((perm & 07) << 3)); } #endif // copy the file - if (os_copy((char *)fname, (char *)backup, UV_FS_COPYFILE_FICLONE) + if (os_copy(fname, backup, UV_FS_COPYFILE_FICLONE) != 0) { SET_ERRMSG(_("E506: Can't write to backup file " "(add ! to override)")); } #ifdef UNIX - os_file_settime((char *)backup, + os_file_settime(backup, file_info_old.stat.st_atim.tv_sec, file_info_old.stat.st_mtim.tv_sec); #endif #ifdef HAVE_ACL - mch_set_acl(backup, acl); + mch_set_acl((char_u *)backup, acl); #endif break; } @@ -2913,9 +2909,9 @@ nobackup: } SET_ERRMSG(NULL); } else { - char_u *dirp; - char_u *p; - char_u *rootname; + char *dirp; + char *p; + char *rootname; /* * Make a backup by renaming the original file. @@ -2936,14 +2932,14 @@ nobackup: * path/fo.o.h.bak Try all directories in 'backupdir', first one * that works is used. */ - dirp = p_bdir; + dirp = (char *)p_bdir; while (*dirp) { /* * Isolate one directory name and make the backup file name. */ - size_t dir_len = copy_option_part(&dirp, IObuff, IOSIZE, ","); - p = IObuff + dir_len; - bool trailing_pathseps = after_pathsep((char *)IObuff, (char *)p) && p[-1] == p[-2]; + size_t dir_len = copy_option_part((char_u **)&dirp, IObuff, IOSIZE, ","); + p = (char *)IObuff + dir_len; + bool trailing_pathseps = after_pathsep((char *)IObuff, p) && p[-1] == p[-2]; if (trailing_pathseps) { IObuff[dir_len - 2] = NUL; } @@ -2958,21 +2954,19 @@ nobackup: } if (trailing_pathseps) { // path ends with '//', use full path - if ((p = (char_u *)make_percent_swname((char *)IObuff, (char *)fname)) + if ((p = make_percent_swname((char *)IObuff, fname)) != NULL) { - backup = (char_u *)modname((char *)p, (char *)backup_ext, - no_prepend_dot); + backup = modname(p, backup_ext, no_prepend_dot); xfree(p); } } if (backup == NULL) { - rootname = get_file_in_dir(fname, IObuff); + rootname = (char *)get_file_in_dir((char_u *)fname, IObuff); if (rootname == NULL) { backup = NULL; } else { - backup = (char_u *)modname((char *)rootname, (char *)backup_ext, - no_prepend_dot); + backup = modname(rootname, backup_ext, no_prepend_dot); xfree(rootname); } } @@ -2983,13 +2977,13 @@ nobackup: * delete an existing one, try to use another name. * Change one character, just before the extension. */ - if (!p_bk && os_path_exists(backup)) { + if (!p_bk && os_path_exists((char_u *)backup)) { p = backup + STRLEN(backup) - 1 - STRLEN(backup_ext); if (p < backup) { // empty file name ??? p = backup; } *p = 'z'; - while (*p > 'a' && os_path_exists(backup)) { + while (*p > 'a' && os_path_exists((char_u *)backup)) { (*p)--; } // They all exist??? Must be something wrong! @@ -3007,7 +3001,7 @@ nobackup: // If the renaming of the original file to the backup file // works, quit here. /// - if (vim_rename(fname, backup) == 0) { + if (vim_rename((char_u *)fname, (char_u *)backup) == 0) { break; } @@ -3068,21 +3062,21 @@ nobackup: // Check for forced 'fileencoding' from "++opt=val" argument. if (eap != NULL && eap->force_enc != 0) { - fenc = (char_u *)eap->cmd + eap->force_enc; - fenc = enc_canonize(fenc); + fenc = eap->cmd + eap->force_enc; + fenc = (char *)enc_canonize((char_u *)fenc); fenc_tofree = fenc; } else { - fenc = buf->b_p_fenc; + fenc = (char *)buf->b_p_fenc; } // Check if the file needs to be converted. - converted = need_conversion(fenc); + converted = need_conversion((char_u *)fenc); // Check if UTF-8 to UCS-2/4 or Latin1 conversion needs to be done. Or // Latin1 to Unicode conversion. This is handled in buf_write_bytes(). // Prepare the flags for it and allocate bw_conv_buf when needed. if (converted) { - wb_flags = get_fio_flags(fenc); + wb_flags = get_fio_flags((char_u *)fenc); if (wb_flags & (FIO_UCS2 | FIO_UCS4 | FIO_UTF16 | FIO_UTF8)) { // Need to allocate a buffer to translate into. if (wb_flags & (FIO_UCS2 | FIO_UTF16 | FIO_UTF8)) { @@ -3102,7 +3096,7 @@ nobackup: #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"); + write_info.bw_iconv_fd = (iconv_t)my_iconv_open((char_u *)fenc, (char_u *)"utf-8"); if (write_info.bw_iconv_fd != (iconv_t)-1) { // We're going to use iconv(), allocate a buffer to convert in. write_info.bw_conv_buflen = bufsize * ICONV_MULT; @@ -3120,7 +3114,7 @@ nobackup: * overwrite the original file. */ if (*p_ccv != NUL) { - wfname = vim_tempname(); + wfname = (char *)vim_tempname(); if (wfname == NULL) { // Can't write without a tempfile! SET_ERRMSG(_("E214: Can't find temp file for writing")); goto restore_backup; @@ -3164,7 +3158,7 @@ nobackup: // quotum for number of files). // Appending will fail if the file does not exist and forceit is // FALSE. - while ((fd = os_open((char *)wfname, + while ((fd = os_open(wfname, O_WRONLY | (append ? (forceit ? (O_APPEND | O_CREAT) : O_APPEND) @@ -3179,7 +3173,7 @@ nobackup: // Don't delete the file when it's a hard or symbolic link. if ((!newfile && os_fileinfo_hardlinks(&file_info_old) > 1) - || (os_fileinfo_link((char *)fname, &file_info) + || (os_fileinfo_link(fname, &file_info) && !os_fileinfo_id_equal(&file_info, &file_info_old))) { SET_ERRMSG(_("E166: Can't open linked file for writing")); } else { @@ -3200,7 +3194,7 @@ nobackup: } #endif if (!append) { // don't remove when appending - os_remove((char *)wfname); + os_remove(wfname); } continue; } @@ -3221,21 +3215,21 @@ restore_backup: // This may not work if the vim_rename() fails. // In that case we leave the copy around. // If file does not exist, put the copy in its place - if (!os_path_exists(fname)) { - vim_rename(backup, fname); + if (!os_path_exists((char_u *)fname)) { + vim_rename((char_u *)backup, (char_u *)fname); } // if original file does exist throw away the copy - if (os_path_exists(fname)) { - os_remove((char *)backup); + if (os_path_exists((char_u *)fname)) { + os_remove(backup); } } else { // try to put the original file back - vim_rename(backup, fname); + vim_rename((char_u *)backup, (char_u *)fname); } } // if original file no longer exists give an extra warning - if (!newfile && !os_path_exists(fname)) { + if (!newfile && !os_path_exists((char_u *)fname)) { end = 0; } } @@ -3249,7 +3243,7 @@ restore_backup: } SET_ERRMSG(NULL); - write_info.bw_buf = buffer; + write_info.bw_buf = (char_u *)buffer; nchars = 0; // use "++bin", "++nobin" or 'binary' @@ -3262,7 +3256,7 @@ restore_backup: // Skip the BOM when appending and the file already existed, the BOM // only makes sense at the start of the file. if (buf->b_p_bomb && !write_bin && (!append || perm < 0)) { - write_info.bw_len = make_bom(buffer, fenc); + write_info.bw_len = make_bom((char_u *)buffer, (char_u *)fenc); if (write_info.bw_len > 0) { // don't convert write_info.bw_flags = FIO_NOCONVERT | wb_flags; @@ -3292,9 +3286,9 @@ restore_backup: for (lnum = start; lnum <= end; lnum++) { // The next while loop is done once for each character written. // Keep it fast! - ptr = ml_get_buf(buf, lnum, false) - 1; + ptr = (char *)ml_get_buf(buf, lnum, false) - 1; if (write_undo_file) { - sha256_update(&sha_ctx, ptr + 1, (uint32_t)(STRLEN(ptr + 1) + 1)); + sha256_update(&sha_ctx, (char_u *)ptr + 1, (uint32_t)(STRLEN(ptr + 1) + 1)); } while ((c = *++ptr) != NUL) { if (c == NL) { @@ -3403,7 +3397,7 @@ restore_backup: // don't change the owner when it's already OK, some systems remove // permission or ACL stuff FileInfo file_info; - if (!os_fileinfo((char *)wfname, &file_info) + if (!os_fileinfo(wfname, &file_info) || file_info.stat.st_uid != file_info_old.stat.st_uid || file_info.stat.st_gid != file_info_old.stat.st_gid) { os_fchown(fd, file_info_old.stat.st_uid, file_info_old.stat.st_gid); @@ -3435,7 +3429,7 @@ restore_backup: // Probably need to set the ACL before changing the user (can't set the // ACL on a file the user doesn't own). if (!backup_copy) { - mch_set_acl(wfname, acl); + mch_set_acl((char_u *)wfname, acl); } #endif @@ -3443,13 +3437,12 @@ restore_backup: // The file was written to a temp file, now it needs to be converted // with 'charconvert' to (overwrite) the output file. if (end != 0) { - if (eval_charconvert("utf-8", (char *)fenc, - (char *)wfname, (char *)fname) == FAIL) { + if (eval_charconvert("utf-8", fenc, wfname, fname) == FAIL) { write_info.bw_conv_error = true; end = 0; } } - os_remove((char *)wfname); + os_remove(wfname); xfree(wfname); } } @@ -3493,12 +3486,12 @@ restore_backup: } // copy the file. - if (os_copy((char *)backup, (char *)fname, UV_FS_COPYFILE_FICLONE) + if (os_copy(backup, fname, UV_FS_COPYFILE_FICLONE) == 0) { end = 1; // success } } else { - if (vim_rename(backup, fname) == 0) { + if (vim_rename((char_u *)backup, (char_u *)fname) == 0) { end = 1; } } @@ -3590,7 +3583,7 @@ restore_backup: * the backup file our 'original' file. */ if (*p_pm && dobackup) { - char *const org = modname((char *)fname, (char *)p_pm, false); + char *const org = modname(fname, (char *)p_pm, false); if (backup != NULL) { /* @@ -3600,7 +3593,7 @@ restore_backup: if (org == NULL) { emsg(_("E205: Patchmode: can't save original file")); } else if (!os_path_exists((char_u *)org)) { - vim_rename(backup, (char_u *)org); + vim_rename((char_u *)backup, (char_u *)org); XFREE_CLEAR(backup); // don't delete the file #ifdef UNIX os_file_settime(org, @@ -3636,7 +3629,7 @@ restore_backup: */ if (!p_bk && backup != NULL && !write_info.bw_conv_error - && os_remove((char *)backup) != 0) { + && os_remove(backup) != 0) { emsg(_("E207: Can't delete backup file")); } @@ -3700,7 +3693,7 @@ nofail: // Update the timestamp to avoid an "overwrite changed file" // prompt when writing again. - if (os_fileinfo((char *)fname, &file_info_old)) { + if (os_fileinfo(fname, &file_info_old)) { buf_store_file_info(buf, &file_info_old); buf->b_mtime_read = buf->b_mtime; buf->b_mtime_read_ns = buf->b_mtime_ns; @@ -3714,10 +3707,10 @@ nofail: * file. */ if (retval == OK && write_undo_file) { - char_u hash[UNDO_HASH_SIZE]; + char hash[UNDO_HASH_SIZE]; - sha256_finish(&sha_ctx, hash); - u_write_undo(NULL, FALSE, buf, hash); + sha256_finish(&sha_ctx, (char_u *)hash); + u_write_undo(NULL, false, buf, (char_u *)hash); } if (!should_abort(retval)) { @@ -4442,7 +4435,7 @@ char *modname(const char *fname, const char *ext, bool prepend_dot) char *e; // Prepend the dot if needed. - if (prepend_dot && *(e = (char *)path_tail((char_u *)retval)) != '.') { + if (prepend_dot && *(e = path_tail(retval)) != '.') { STRMOVE(e + 1, e); *e = '.'; } @@ -4653,7 +4646,7 @@ int vim_rename(const char_u *from, const char_u *to) * the file name differs we need to go through a temp file. */ if (FNAMECMP(from, to) == 0) { - if (p_fic && (STRCMP(path_tail((char_u *)from), path_tail((char_u *)to)) + if (p_fic && (STRCMP(path_tail((char *)from), path_tail((char *)to)) != 0)) { use_tmp_file = true; } else { @@ -4688,7 +4681,7 @@ int vim_rename(const char_u *from, const char_u *to) } STRCPY(tempname, from); for (n = 123; n < 99999; n++) { - char *tail = (char *)path_tail(tempname); + char *tail = path_tail((char *)tempname); snprintf(tail, (MAXPATHL + 1) - (tail - (char *)tempname - 1), "%d", n); if (!os_path_exists(tempname)) { @@ -5000,7 +4993,7 @@ int buf_check_timestamp(buf_T *buf) if (!bufref_valid(&bufref)) { emsg(_("E246: FileChangedShell autocommand deleted buffer")); } - s = get_vim_var_str(VV_FCS_CHOICE); + s = (char_u *)get_vim_var_str(VV_FCS_CHOICE); if (STRCMP(s, "reload") == 0 && *reason != 'd') { reload = RELOAD_NORMAL; } else if (STRCMP(s, "edit") == 0) { @@ -5199,7 +5192,7 @@ void buf_reload(buf_T *buf, int orig_mode, bool reload_options) if (saved == OK) { curbuf->b_flags |= BF_CHECK_RO; // check for RO again keep_filetype = true; // don't detect 'filetype' - if (readfile(buf->b_ffname, buf->b_fname, (linenr_T)0, (linenr_T)0, + if (readfile((char *)buf->b_ffname, (char *)buf->b_fname, (linenr_T)0, (linenr_T)0, (linenr_T)MAXLNUM, &ea, flags, false) != OK) { if (!aborting()) { semsg(_("E321: Could not reload \"%s\""), buf->b_fname); @@ -5443,7 +5436,7 @@ void vim_deltempdir(void) { if (vim_tempdir != NULL) { // remove the trailing path separator - path_tail(vim_tempdir)[-1] = NUL; + path_tail((char *)vim_tempdir)[-1] = NUL; delete_recursive((const char *)vim_tempdir); XFREE_CLEAR(vim_tempdir); } @@ -5519,7 +5512,7 @@ char_u *vim_tempname(void) /// @param allow_dirs Allow matching with dir /// /// @return true if there is a match, false otherwise -bool match_file_pat(char_u *pattern, regprog_T **prog, char_u *fname, char_u *sfname, char_u *tail, +bool match_file_pat(char *pattern, regprog_T **prog, char *fname, char *sfname, char *tail, int allow_dirs) { regmatch_T regmatch; @@ -5530,7 +5523,7 @@ bool match_file_pat(char_u *pattern, regprog_T **prog, char_u *fname, char_u *sf if (prog != NULL) { regmatch.regprog = *prog; } else { - regmatch.regprog = vim_regcomp(pattern, RE_MAGIC); + regmatch.regprog = vim_regcomp((char_u *)pattern, RE_MAGIC); } } @@ -5542,10 +5535,10 @@ bool match_file_pat(char_u *pattern, regprog_T **prog, char_u *fname, char_u *sf */ if (regmatch.regprog != NULL && ((allow_dirs - && (vim_regexec(®match, fname, (colnr_T)0) + && (vim_regexec(®match, (char_u *)fname, (colnr_T)0) || (sfname != NULL - && vim_regexec(®match, sfname, (colnr_T)0)))) - || (!allow_dirs && vim_regexec(®match, tail, (colnr_T)0)))) { + && vim_regexec(®match, (char_u *)sfname, (colnr_T)0)))) + || (!allow_dirs && vim_regexec(®match, (char_u *)tail, (colnr_T)0)))) { result = true; } @@ -5576,7 +5569,7 @@ bool match_file_list(char_u *list, char_u *sfname, char_u *ffname) bool match; char_u *p; - tail = path_tail(sfname); + tail = (char_u *)path_tail((char *)sfname); // try all patterns in 'wildignore' p = list; @@ -5586,7 +5579,8 @@ bool match_file_list(char_u *list, char_u *sfname, char_u *ffname) if (regpat == NULL) { break; } - match = match_file_pat(regpat, NULL, ffname, sfname, tail, (int)allow_dirs); + match = match_file_pat((char *)regpat, NULL, (char *)ffname, (char *)sfname, (char *)tail, + (int)allow_dirs); xfree(regpat); if (match) { return true; diff --git a/src/nvim/generators/gen_eval.lua b/src/nvim/generators/gen_eval.lua index 945fa5099f..f094a04c07 100644 --- a/src/nvim/generators/gen_eval.lua +++ b/src/nvim/generators/gen_eval.lua @@ -1,9 +1,12 @@ local mpack = require('mpack') local nvimsrcdir = arg[1] -local autodir = arg[2] -local metadata_file = arg[3] -local funcs_file = arg[4] +local shared_file = arg[2] +local autodir = arg[3] +local metadata_file = arg[4] +local funcs_file = arg[5] + +_G.vim = loadfile(shared_file)() if nvimsrcdir == '--help' then print([[ @@ -20,7 +23,9 @@ package.path = nvimsrcdir .. '/?.lua;' .. package.path local funcsfname = autodir .. '/funcs.generated.h' -local gperfpipe = io.open(funcsfname .. '.gperf', 'wb') +local hashy = require'generators.hashy' + +local hashpipe = io.open(funcsfname, 'wb') local funcs = require('eval').funcs local metadata = mpack.unpack(io.open(metadata_file, 'rb'):read("*all")) @@ -38,21 +43,15 @@ local funcsdata = io.open(funcs_file, 'w') funcsdata:write(mpack.pack(funcs)) funcsdata:close() -gperfpipe:write([[ -%language=ANSI-C -%global-table -%readonly-tables -%define initializer-suffix ,0,0,BASE_NONE,NULL,NULL -%define word-array-name functions -%define hash-function-name hash_internal_func_gperf -%define lookup-function-name find_internal_func_gperf -%omit-struct-type -%struct-type -VimLFuncDef; -%% -]]) -for name, def in pairs(funcs) do +local names = vim.tbl_keys(funcs) + +local neworder, hashfun = hashy.hashy_hash("find_internal_func", names, function (idx) + return "functions["..idx.."].name" +end) +hashpipe:write("static const EvalFuncDef functions[] = {\n") +for _, name in ipairs(neworder) do + local def = funcs[name] local args = def.args or 0 if type(args) == 'number' then args = {args, args} @@ -62,7 +61,10 @@ for name, def in pairs(funcs) do local base = def.base or "BASE_NONE" local func = def.func or ('f_' .. name) local data = def.data or "NULL" - gperfpipe:write(('%s, %s, %s, %s, &%s, (FunPtr)%s\n') + hashpipe:write((' { "%s", %s, %s, %s, &%s, (FunPtr)%s },\n') :format(name, args[1], args[2], base, func, data)) end -gperfpipe:close() +hashpipe:write(' { NULL, 0, 0, BASE_NONE, NULL, NULL },\n') +hashpipe:write("};\n\n") +hashpipe:write(hashfun) +hashpipe:close() diff --git a/src/nvim/getchar.c b/src/nvim/getchar.c index f05eeb2fb8..e64fda39e9 100644 --- a/src/nvim/getchar.c +++ b/src/nvim/getchar.c @@ -848,6 +848,8 @@ void init_default_mappings(void) MODE_NORMAL, true); add_map((char_u *)"<C-U> <C-G>u<C-U>", MODE_INSERT, true); add_map((char_u *)"<C-W> <C-G>u<C-W>", MODE_INSERT, true); + add_map((char_u *)"* y/\\\\V<C-R>\"<CR>", MODE_VISUAL, true); + add_map((char_u *)"# y?\\\\V<C-R>\"<CR>", MODE_VISUAL, true); } // Insert a string in position 'offset' in the typeahead buffer (for "@r" @@ -2902,8 +2904,8 @@ void set_maparg_lhs_rhs(const char *const orig_lhs, const size_t orig_lhs_len, mapargs->rhs_len = 0; mapargs->rhs_is_noop = true; } else { - replaced = replace_termcodes(orig_rhs, orig_rhs_len, &rhs_buf, - REPTERM_DO_LT | REPTERM_NO_SIMPLIFY, NULL, cpo_flags); + replaced = replace_termcodes(orig_rhs, orig_rhs_len, &rhs_buf, REPTERM_DO_LT, NULL, + cpo_flags); mapargs->rhs_len = STRLEN(replaced); // XXX: even when orig_rhs is non-empty, replace_termcodes may produce an empty string. mapargs->rhs_is_noop = orig_rhs[0] != NUL && mapargs->rhs_len == 0; @@ -3009,7 +3011,7 @@ int str_to_mapargs(const char_u *strargs, bool is_unmap, MapArguments *mapargs) // // With :unmap, literal white space is included in the {lhs}; there is no // separate {rhs}. - const char_u *lhs_end = to_parse; + const char *lhs_end = (char *)to_parse; bool do_backslash = (vim_strchr(p_cpo, CPO_BSLASH) == NULL); while (*lhs_end && (is_unmap || !ascii_iswhite(*lhs_end))) { if ((lhs_end[0] == Ctrl_V || (do_backslash && lhs_end[0] == '\\')) @@ -3025,7 +3027,7 @@ int str_to_mapargs(const char_u *strargs, bool is_unmap, MapArguments *mapargs) // Given {lhs} might be larger than MAXMAPLEN before replace_termcodes // (e.g. "<Space>" is longer than ' '), so first copy into a buffer. - size_t orig_lhs_len = (size_t)(lhs_end - to_parse); + size_t orig_lhs_len = (size_t)((char_u *)lhs_end - to_parse); char_u *lhs_to_replace = xcalloc(orig_lhs_len + 1, sizeof(char_u)); STRLCPY(lhs_to_replace, to_parse, orig_lhs_len + 1); @@ -3820,7 +3822,7 @@ bool map_to_exists(const char *const str, const char *const modechars, const boo MAPMODE(mode, modechars, 'c', MODE_CMDLINE); #undef MAPMODE - retval = map_to_exists_mode((const char *)rhs, mode, abbr); + retval = map_to_exists_mode((char *)rhs, mode, abbr); xfree(buf); return retval; @@ -4828,7 +4830,7 @@ mapblock_T *get_maphash(int index, buf_T *buf) } /// Get command argument for <Cmd> key -char_u *getcmdkeycmd(int promptc, void *cookie, int indent, bool do_concat) +char *getcmdkeycmd(int promptc, void *cookie, int indent, bool do_concat) { garray_T line_ga; int c1 = -1, c2; @@ -4901,7 +4903,7 @@ char_u *getcmdkeycmd(int promptc, void *cookie, int indent, bool do_concat) ga_clear(&line_ga); } - return (char_u *)line_ga.ga_data; + return line_ga.ga_data; } bool map_execute_lua(void) diff --git a/src/nvim/globals.h b/src/nvim/globals.h index 8cf069e3ec..1a1f9bd866 100644 --- a/src/nvim/globals.h +++ b/src/nvim/globals.h @@ -253,7 +253,7 @@ EXTERN int lines_left INIT(= -1); // lines left for listing EXTERN int msg_no_more INIT(= false); // don't use more prompt, truncate // messages -EXTERN char_u *sourcing_name INIT(= NULL); // name of error message source +EXTERN char *sourcing_name INIT(= NULL); // name of error message source EXTERN linenr_T sourcing_lnum INIT(= 0); // line number of the source file EXTERN int ex_nesting_level INIT(= 0); // nesting level @@ -354,7 +354,7 @@ EXTERN bool did_source_packages INIT(= false); // provider function call EXTERN struct caller_scope { sctx_T script_ctx; - uint8_t *sourcing_name, *autocmd_fname, *autocmd_match; + char *sourcing_name, *autocmd_fname, *autocmd_match; linenr_T sourcing_lnum; int autocmd_bufnr; void *funccalp; @@ -755,9 +755,9 @@ EXTERN char last_mode[MODE_MAX_LENGTH] INIT(= "n"); EXTERN char_u *last_cmdline INIT(= NULL); // last command line (for ":) EXTERN char_u *repeat_cmdline INIT(= NULL); // command line for "." EXTERN char_u *new_last_cmdline INIT(= NULL); // new value for last_cmdline -EXTERN char_u *autocmd_fname INIT(= NULL); // fname for <afile> on cmdline +EXTERN char *autocmd_fname INIT(= NULL); // fname for <afile> on cmdline EXTERN int autocmd_bufnr INIT(= 0); // fnum for <abuf> on cmdline -EXTERN char_u *autocmd_match INIT(= NULL); // name for <amatch> on cmdline +EXTERN char *autocmd_match INIT(= NULL); // name for <amatch> on cmdline EXTERN bool did_cursorhold INIT(= false); // set when CursorHold t'gerd EXTERN int postponed_split INIT(= 0); // for CTRL-W CTRL-] command diff --git a/src/nvim/hardcopy.c b/src/nvim/hardcopy.c index f75f304bc1..aec15234b9 100644 --- a/src/nvim/hardcopy.c +++ b/src/nvim/hardcopy.c @@ -1576,7 +1576,7 @@ static void prt_resource_name(char *filename, void *cookie) static int prt_find_resource(char *name, struct prt_ps_resource_S *resource) { - char_u *buffer; + char *buffer; int retval; buffer = xmallocz(MAXPATHL); @@ -1584,7 +1584,7 @@ static int prt_find_resource(char *name, struct prt_ps_resource_S *resource) STRLCPY(resource->name, name, 64); // Look for named resource file in runtimepath STRCPY(buffer, "print"); - add_pathsep((char *)buffer); + add_pathsep(buffer); STRLCAT(buffer, name, MAXPATHL); STRLCAT(buffer, ".ps", MAXPATHL); resource->filename[0] = NUL; diff --git a/src/nvim/if_cscope.c b/src/nvim/if_cscope.c index d9cc643e53..77154e8fce 100644 --- a/src/nvim/if_cscope.c +++ b/src/nvim/if_cscope.c @@ -80,7 +80,7 @@ static enum { * Function given to ExpandGeneric() to obtain the cscope command * expansion. */ -char_u *get_cscope_name(expand_T *xp, int idx) +char *get_cscope_name(expand_T *xp, int idx) { int current_idx; @@ -88,7 +88,7 @@ char_u *get_cscope_name(expand_T *xp, int idx) case EXP_CSCOPE_SUBCMD: // Complete with sub-commands of ":cscope": // add, find, help, kill, reset, show - return (char_u *)cs_cmds[idx].name; + return cs_cmds[idx].name; case EXP_SCSCOPE_SUBCMD: { // Complete with sub-commands of ":scscope": same sub-commands as // ":cscope" but skip commands which don't support split windows @@ -100,7 +100,7 @@ char_u *get_cscope_name(expand_T *xp, int idx) } } } - return (char_u *)cs_cmds[i].name; + return cs_cmds[i].name; } case EXP_CSCOPE_FIND: { const char *query_type[] = @@ -112,7 +112,7 @@ char_u *get_cscope_name(expand_T *xp, int idx) // {query_type} can be letters (c, d, ... a) or numbers (0, 1, // ..., 9) but only complete with letters, since numbers are // redundant. - return (char_u *)query_type[idx]; + return (char *)query_type[idx]; } case EXP_CSCOPE_KILL: { static char connection[5]; @@ -128,10 +128,10 @@ char_u *get_cscope_name(expand_T *xp, int idx) } if (current_idx++ == idx) { vim_snprintf(connection, sizeof(connection), "%zu", i); - return (char_u *)connection; + return connection; } } - return (current_idx == idx && idx > 0) ? (char_u *)"-1" : NULL; + return (current_idx == idx && idx > 0) ? "-1" : NULL; } default: return NULL; @@ -2008,8 +2008,8 @@ static char *cs_resolve_file(size_t i, char *name) // path in path resolution. csdir = xmalloc(MAXPATHL); STRLCPY(csdir, csinfo[i].fname, - path_tail((char_u *)csinfo[i].fname) - - (char_u *)csinfo[i].fname + 1); + path_tail(csinfo[i].fname) + - csinfo[i].fname + 1); len += STRLEN(csdir); } diff --git a/src/nvim/lua/executor.c b/src/nvim/lua/executor.c index 7d08481a7b..9758cee0a5 100644 --- a/src/nvim/lua/executor.c +++ b/src/nvim/lua/executor.c @@ -920,7 +920,7 @@ int nlua_call(lua_State *lstate) { Error err = ERROR_INIT; size_t name_len; - const char_u *name = (const char_u *)luaL_checklstring(lstate, 1, &name_len); + const char *name = luaL_checklstring(lstate, 1, &name_len); if (!nlua_is_deferred_safe()) { return luaL_error(lstate, e_luv_api_disabled, "vimL function"); } @@ -1249,7 +1249,7 @@ int nlua_source_using_linegetter(LineGetter fgetline, void *cookie, char *name) char_u *line = NULL; ga_init(&ga, (int)sizeof(char_u *), 10); - while ((line = fgetline(0, cookie, 0, false)) != NULL) { + while ((line = (char_u *)fgetline(0, cookie, 0, false)) != NULL) { GA_APPEND(char_u *, &ga, line); } char *code = ga_concat_strings_sep(&ga, "\n"); diff --git a/src/nvim/main.c b/src/nvim/main.c index 9beaa0686f..1cf3cdd872 100644 --- a/src/nvim/main.c +++ b/src/nvim/main.c @@ -807,7 +807,7 @@ static void init_locale(void) snprintf(localepath, sizeof(localepath), "%s", get_vim_var_str(VV_PROGPATH)); char *tail = (char *)path_tail_with_sep((char_u *)localepath); *tail = NUL; - tail = (char *)path_tail((char_u *)localepath); + tail = path_tail(localepath); xstrlcpy(tail, "share/locale", sizeof(localepath) - (size_t)(tail - localepath)); bindtextdomain(PROJECT_NAME, localepath); @@ -1364,7 +1364,7 @@ scripterror: if (parmp->diff_mode && os_isdir(p) && GARGCOUNT > 0 && !os_isdir(alist_name(&GARGLIST[0]))) { char_u *r = (char_u *)concat_fnames((char *)p, - (char *)path_tail(alist_name(&GARGLIST[0])), true); + path_tail((char *)alist_name(&GARGLIST[0])), true); xfree(p); p = r; } @@ -1470,7 +1470,7 @@ static void init_path(const char *exename) path_guess_exepath(exename, exepath, sizeof(exepath)); } set_vim_var_string(VV_PROGPATH, exepath, -1); - set_vim_var_string(VV_PROGNAME, (char *)path_tail((char_u *)exename), -1); + set_vim_var_string(VV_PROGNAME, path_tail(exename), -1); #ifdef WIN32 // Append the process start directory to $PATH, so that ":!foo" finds tools @@ -1813,7 +1813,7 @@ static void exe_pre_commands(mparm_T *parmp) if (cnt > 0) { curwin->w_cursor.lnum = 0; // just in case.. - sourcing_name = (char_u *)_("pre-vimrc command line"); + sourcing_name = _("pre-vimrc command line"); current_sctx.sc_sid = SID_CMDARG; for (i = 0; i < cnt; i++) { do_cmdline_cmd(cmds[i]); @@ -1840,7 +1840,7 @@ static void exe_commands(mparm_T *parmp) if (parmp->tagname == NULL && curwin->w_cursor.lnum <= 1) { curwin->w_cursor.lnum = 0; } - sourcing_name = (char_u *)"command line"; + sourcing_name = "command line"; current_sctx.sc_sid = SID_CARG; current_sctx.sc_seq = 0; for (i = 0; i < parmp->n_commands; i++) { @@ -2061,16 +2061,16 @@ static int execute_env(char *env) { const char *initstr = os_getenv(env); if (initstr != NULL) { - char_u *save_sourcing_name = sourcing_name; + char_u *save_sourcing_name = (char_u *)sourcing_name; linenr_T save_sourcing_lnum = sourcing_lnum; - sourcing_name = (char_u *)env; + sourcing_name = env; sourcing_lnum = 0; const sctx_T save_current_sctx = current_sctx; current_sctx.sc_sid = SID_ENV; current_sctx.sc_seq = 0; current_sctx.sc_lnum = 0; do_cmdline_cmd((char *)initstr); - sourcing_name = save_sourcing_name; + sourcing_name = (char *)save_sourcing_name; sourcing_lnum = save_sourcing_lnum; current_sctx = save_current_sctx; return OK; @@ -2104,7 +2104,7 @@ static bool file_owned(const char *fname) static void mainerr(const char *errstr, const char *str) FUNC_ATTR_NORETURN { - char *prgname = (char *)path_tail((char_u *)argv0); + char *prgname = path_tail(argv0); signal_stop(); // kill us with CTRL-C here, if you like diff --git a/src/nvim/mbyte.c b/src/nvim/mbyte.c index 1d65529b75..c7408c6260 100644 --- a/src/nvim/mbyte.c +++ b/src/nvim/mbyte.c @@ -1332,7 +1332,7 @@ bool mb_isalpha(int a) static int utf_strnicmp(const char_u *s1, const char_u *s2, size_t n1, size_t n2) { int c1, c2, cdiff; - char_u buffer[6]; + char buffer[6]; for (;;) { c1 = utf_safe_read_char_adv(&s1, &n1); @@ -1371,10 +1371,10 @@ static int utf_strnicmp(const char_u *s1, const char_u *s2, size_t n1, size_t n2 if (c1 != -1 && c2 == -1) { n1 = utf_char2bytes(utf_fold(c1), (char *)buffer); - s1 = buffer; + s1 = (char_u *)buffer; } else if (c2 != -1 && c1 == -1) { n2 = utf_char2bytes(utf_fold(c2), (char *)buffer); - s2 = buffer; + s2 = (char_u *)buffer; } while (n1 > 0 && n2 > 0 && *s1 != NUL && *s2 != NUL) { @@ -1992,6 +1992,31 @@ theend: convert_setup(&vimconv, NULL, NULL); } +/// @return true if string "s" is a valid utf-8 string. +/// When "end" is NULL stop at the first NUL. +/// When "end" is positive stop there. +bool utf_valid_string(const char_u *s, const char_u *end) +{ + const char_u *p = s; + + while (end == NULL ? *p != NUL : p < end) { + int l = utf8len_tab_zero[*p]; + if (l == 0) { + return false; // invalid lead byte + } + if (end != NULL && p + l > end) { + return false; // incomplete byte sequence + } + p++; + while (--l > 0) { + if ((*p++ & 0xc0) != 0x80) { + return false; // invalid trail byte + } + } + } + return true; +} + /* * If the cursor moves on an trail byte, set the cursor on the lead byte. * Thus it moves left if necessary. diff --git a/src/nvim/memline.c b/src/nvim/memline.c index 081045ab18..5ca33faec3 100644 --- a/src/nvim/memline.c +++ b/src/nvim/memline.c @@ -992,7 +992,7 @@ void ml_recover(bool checkext) * 'fileencoding', etc. Ignore errors. The text itself is not used. */ if (curbuf->b_ffname != NULL) { - orig_file_status = readfile(curbuf->b_ffname, NULL, (linenr_T)0, + orig_file_status = readfile((char *)curbuf->b_ffname, NULL, (linenr_T)0, (linenr_T)0, (linenr_T)MAXLNUM, NULL, READ_NEW, false); } @@ -1066,7 +1066,7 @@ void ml_recover(bool checkext) */ if (!cannot_open) { line_count = pp->pb_pointer[idx].pe_line_count; - if (readfile(curbuf->b_ffname, NULL, lnum, + if (readfile((char *)curbuf->b_ffname, NULL, lnum, pp->pb_pointer[idx].pe_old_lnum - 1, line_count, NULL, 0, false) != OK) { cannot_open = true; @@ -1338,8 +1338,8 @@ int recover_names(char_u *fname, int list, int nr, char_u **fname_out) tail = (char_u *)make_percent_swname((char *)dir_name, (char *)fname_res); } else { - tail = path_tail(fname_res); - tail = (char_u *)concat_fnames((char *)dir_name, (char *)tail, TRUE); + tail = (char_u *)path_tail((char *)fname_res); + tail = (char_u *)concat_fnames((char *)dir_name, (char *)tail, true); } num_names = recov_file_names(names, tail, FALSE); xfree(tail); @@ -1418,7 +1418,7 @@ int recover_names(char_u *fname, int list, int nr, char_u **fname_out) // print the swap file name msg_outnum((long)++file_count); msg_puts(". "); - msg_puts((const char *)path_tail(files[i])); + msg_puts((const char *)path_tail((char *)files[i])); msg_putchar('\n'); (void)swapfile_info(files[i]); } @@ -3204,7 +3204,7 @@ int resolve_symlink(const char_u *fname, char_u *buf) if (path_is_absolute(buf)) { STRCPY(tmp, buf); } else { - char_u *tail = path_tail(tmp); + char_u *tail = (char_u *)path_tail((char *)tmp); if (STRLEN(tail) + STRLEN(buf) >= MAXPATHL) { return FAIL; } @@ -3283,7 +3283,7 @@ char_u *get_file_in_dir(char_u *fname, char_u *dname) char_u *retval; int save_char; - tail = path_tail(fname); + tail = (char_u *)path_tail((char *)fname); if (dname[0] == '.' && dname[1] == NUL) { retval = vim_strsave(fname); @@ -3482,8 +3482,8 @@ static char *findswapname(buf_T *buf, char **dirp, char *old_fname, bool *found_ // buffer don't compare the directory names, they can // have a different mountpoint. if (b0.b0_flags & B0_SAME_DIR) { - if (FNAMECMP(path_tail(buf->b_ffname), - path_tail(b0.b0_fname)) != 0 + if (FNAMECMP(path_tail((char *)buf->b_ffname), + path_tail((char *)b0.b0_fname)) != 0 || !same_directory((char_u *)fname, buf->b_ffname)) { // Symlinks may point to the same file even // when the name differs, need to check the @@ -3528,7 +3528,7 @@ static char *findswapname(buf_T *buf, char **dirp, char *old_fname, bool *found_ // response, trigger it. It may return 0 to ask the user anyway. if (choice == 0 && swap_exists_action != SEA_NONE - && has_autocmd(EVENT_SWAPEXISTS, (char_u *)buf_fname, buf)) { + && has_autocmd(EVENT_SWAPEXISTS, buf_fname, buf)) { choice = do_swapexists(buf, (char_u *)fname); } diff --git a/src/nvim/menu.c b/src/nvim/menu.c index 72c129338c..7b254f1b62 100644 --- a/src/nvim/menu.c +++ b/src/nvim/menu.c @@ -1034,7 +1034,7 @@ char *set_context_in_menu_cmd(expand_T *xp, const char *cmd, char *arg, bool for * Function given to ExpandGeneric() to obtain the list of (sub)menus (not * entries). */ -char_u *get_menu_name(expand_T *xp, int idx) +char *get_menu_name(expand_T *xp, int idx) { static vimmenu_T *menu = NULL; char *str; @@ -1076,14 +1076,14 @@ char_u *get_menu_name(expand_T *xp, int idx) should_advance = !should_advance; - return (char_u *)str; + return str; } /* * Function given to ExpandGeneric() to obtain the list of menus and menu * entries. */ -char_u *get_menu_names(expand_T *xp, int idx) +char *get_menu_names(expand_T *xp, int idx) { static vimmenu_T *menu = NULL; #define TBUFFER_LEN 256 @@ -1143,7 +1143,7 @@ char_u *get_menu_names(expand_T *xp, int idx) should_advance = !should_advance; - return (char_u *)str; + return str; } diff --git a/src/nvim/message.c b/src/nvim/message.c index 12a3580831..52eafe6e26 100644 --- a/src/nvim/message.c +++ b/src/nvim/message.c @@ -586,7 +586,7 @@ void msg_source(int attr) if (sourcing_name == NULL) { last_sourcing_name = NULL; } else { - last_sourcing_name = vim_strsave(sourcing_name); + last_sourcing_name = vim_strsave((char_u *)sourcing_name); } } --no_wait_return; @@ -2418,7 +2418,7 @@ void msg_reset_scroll(void) static void inc_msg_scrolled(void) { if (*get_vim_var_str(VV_SCROLLSTART) == NUL) { - char *p = (char *)sourcing_name; + char *p = sourcing_name; char *tofree = NULL; // v:scrollstart is empty, set it to the script/function name and line diff --git a/src/nvim/ops.c b/src/nvim/ops.c index 54db6f6f6f..7b3895333b 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -884,7 +884,7 @@ yankreg_T *copy_register(int name) if (copy->y_size == 0) { copy->y_array = NULL; } else { - copy->y_array = xcalloc(copy->y_size, sizeof(char_u *)); + copy->y_array = xcalloc(copy->y_size, sizeof(char *)); for (size_t i = 0; i < copy->y_size; i++) { copy->y_array[i] = xstrdup(reg->y_array[i]); } @@ -1161,7 +1161,7 @@ int do_execreg(int regname, int colon, int addcr, int silent) * Insert lines into typeahead buffer, from last one to first one. */ put_reedit_in_typebuf(silent); - char_u *escaped; + char *escaped; for (size_t i = reg->y_size; i-- > 0;) { // from y_size - 1 to 0 included // insert NL between lines and after last line if type is kMTLineWise if (reg->y_type == kMTLineWise || i < reg->y_size - 1 || addcr) { @@ -1180,7 +1180,7 @@ int do_execreg(int regname, int colon, int addcr, int silent) free_str = true; } } - escaped = (char_u *)vim_strsave_escape_ks((char *)str); + escaped = vim_strsave_escape_ks((char *)str); if (free_str) { xfree(str); } @@ -1237,12 +1237,12 @@ static int put_in_typebuf(char_u *s, bool esc, bool colon, int silent) retval = ins_typebuf("\n", REMAP_NONE, 0, true, silent); } if (retval == OK) { - char_u *p; + char *p; if (esc) { - p = (char_u *)vim_strsave_escape_ks((char *)s); + p = vim_strsave_escape_ks((char *)s); } else { - p = s; + p = (char *)s; } if (p == NULL) { retval = FAIL; @@ -2679,7 +2679,7 @@ bool op_yank(oparg_T *oap, bool message) static void op_yank_reg(oparg_T *oap, bool message, yankreg_T *reg, bool append) { yankreg_T newreg; // new yank register when appending - char_u **new_ptr; + char **new_ptr; linenr_T lnum; // current line number size_t j; MotionType yank_type = oap->motion_type; @@ -2713,7 +2713,7 @@ static void op_yank_reg(oparg_T *oap, bool message, yankreg_T *reg, bool append) reg->y_size = yanklines; reg->y_type = yank_type; // set the yank register type reg->y_width = 0; - reg->y_array = xcalloc(yanklines, sizeof(char_u *)); + reg->y_array = xcalloc(yanklines, sizeof(char *)); reg->additional_data = NULL; reg->timestamp = os_time(); @@ -2808,10 +2808,10 @@ static void op_yank_reg(oparg_T *oap, bool message, yankreg_T *reg, bool append) if (curr != reg) { // append the new block to the old block new_ptr = xmalloc(sizeof(char_u *) * (curr->y_size + reg->y_size)); for (j = 0; j < curr->y_size; j++) { - new_ptr[j] = (char_u *)curr->y_array[j]; + new_ptr[j] = curr->y_array[j]; } xfree(curr->y_array); - curr->y_array = (char **)new_ptr; + curr->y_array = new_ptr; if (yank_type == kMTLineWise) { // kMTLineWise overrides kMTCharWise and kMTBlockWise @@ -5777,7 +5777,7 @@ static void str_to_reg(yankreg_T *y_ptr, MotionType yank_type, const char_u *str // When appending, copy the previous line and free it after. size_t extra = append ? STRLEN(pp[--lnum]) : 0; - char_u *s = xmallocz(line_len + extra); + char *s = xmallocz(line_len + extra); if (extra > 0) { memcpy(s, pp[lnum], extra); } @@ -5788,7 +5788,7 @@ static void str_to_reg(yankreg_T *y_ptr, MotionType yank_type, const char_u *str xfree(pp[lnum]); append = false; // only first line is appended } - pp[lnum] = s; + pp[lnum] = (char_u *)s; // Convert NULs to '\n' to prevent truncation. memchrsub(pp[lnum], NUL, '\n', s_len); @@ -7120,7 +7120,7 @@ static bool get_clipboard(int name, yankreg_T **target, bool quiet) reg->y_type = kMTUnknown; } - reg->y_array = xcalloc((size_t)tv_list_len(lines), sizeof(char_u *)); + reg->y_array = xcalloc((size_t)tv_list_len(lines), sizeof(char *)); reg->y_size = (size_t)tv_list_len(lines); reg->additional_data = NULL; reg->timestamp = 0; diff --git a/src/nvim/option.c b/src/nvim/option.c index 940570b134..2a2d2cce80 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -1963,13 +1963,10 @@ static char_u *option_expand(int opt_idx, char_u *val) return NameBuff; } -// After setting various option values: recompute variables that depend on -// option values. -static void didset_options(void) +/// After setting various option values: recompute variables that depend on +/// option values. +static void didset_string_options(void) { - // initialize the table for 'iskeyword' et.al. - (void)init_chartab(); - (void)opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, true); (void)opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, true); (void)opt_strings_flags(p_bo, p_bo_values, &bo_flags, true); @@ -1981,8 +1978,20 @@ static void didset_options(void) (void)opt_strings_flags(p_tc, p_tc_values, &tc_flags, false); (void)opt_strings_flags(p_tpf, p_tpf_values, &tpf_flags, true); (void)opt_strings_flags(p_ve, p_ve_values, &ve_flags, true); + (void)opt_strings_flags(p_swb, p_swb_values, &swb_flags, true); (void)opt_strings_flags(p_wop, p_wop_values, &wop_flags, true); (void)opt_strings_flags(p_jop, p_jop_values, &jop_flags, true); +} + +/// After setting various option values: recompute variables that depend on +/// option values. +static void didset_options(void) +{ + // initialize the table for 'iskeyword' et.al. + (void)init_chartab(); + + didset_string_options(); + (void)spell_check_msm(); (void)spell_check_sps(); (void)compile_cap_prog(curwin->w_s); @@ -8161,13 +8170,13 @@ size_t copy_option_part(char_u **option, char_u *buf, size_t maxlen, char *sep_c /// Return true when 'shell' has "csh" in the tail. int csh_like_shell(void) { - return strstr((char *)path_tail(p_sh), "csh") != NULL; + return strstr(path_tail((char *)p_sh), "csh") != NULL; } /// Return true when 'shell' has "fish" in the tail. bool fish_like_shell(void) { - return strstr((char *)path_tail(p_sh), "fish") != NULL; + return strstr(path_tail((char *)p_sh), "fish") != NULL; } /// Return the number of requested sign columns, based on current diff --git a/src/nvim/os/env.c b/src/nvim/os/env.c index 4e6a52a78e..d0435cd968 100644 --- a/src/nvim/os/env.c +++ b/src/nvim/os/env.c @@ -888,7 +888,7 @@ void vim_get_prefix_from_exepath(char *exe_name) MAXPATHL * sizeof(*exe_name)); char *path_end = (char *)path_tail_with_sep((char_u *)exe_name); *path_end = '\0'; // remove the trailing "nvim.exe" - path_end = (char *)path_tail((char_u *)exe_name); + path_end = path_tail(exe_name); *path_end = '\0'; // remove the trailing "bin/" } @@ -957,7 +957,7 @@ char *vim_getenv(const char *name) if (vim_path != NULL) { // remove the file name - char *vim_path_end = (char *)path_tail((char_u *)vim_path); + char *vim_path_end = path_tail(vim_path); // remove "doc/" from 'helpfile', if present if (vim_path == (char *)p_hf) { @@ -1048,7 +1048,7 @@ size_t home_replace(const buf_T *const buf, const char_u *src, char_u *const dst } if (buf != NULL && buf->b_help) { - const size_t dlen = STRLCPY(dst, path_tail(src), dstlen); + const size_t dlen = STRLCPY(dst, path_tail((char *)src), dstlen); return MIN(dlen, dstlen - 1); } @@ -1158,7 +1158,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) +char *get_env_name(expand_T *xp, int idx) { #define ENVNAMELEN 100 // this static buffer is needed to avoid a memory leak in ExpandGeneric @@ -1168,7 +1168,7 @@ char_u *get_env_name(expand_T *xp, int idx) if (envname) { STRLCPY(name, envname, ENVNAMELEN); xfree(envname); - return name; + return (char *)name; } return NULL; } @@ -1226,10 +1226,10 @@ bool os_shell_is_cmdexe(const char *sh) } if (striequal(sh, "$COMSPEC")) { const char *comspec = os_getenv("COMSPEC"); - return striequal("cmd.exe", (char *)path_tail((char_u *)comspec)); + return striequal("cmd.exe", path_tail(comspec)); } if (striequal(sh, "cmd.exe") || striequal(sh, "cmd")) { return true; } - return striequal("cmd.exe", (char *)path_tail((char_u *)sh)); + return striequal("cmd.exe", path_tail(sh)); } diff --git a/src/nvim/os/shell.c b/src/nvim/os/shell.c index 79d24e41b0..34d9015071 100644 --- a/src/nvim/os/shell.c +++ b/src/nvim/os/shell.c @@ -188,7 +188,7 @@ int os_expand_wildcards(int num_pat, char_u **pat, int *num_file, char_u ***file } } if (shell_style == STYLE_ECHO - && strstr((char *)path_tail(p_sh), "sh") != NULL) { + && strstr(path_tail((char *)p_sh), "sh") != NULL) { shell_style = STYLE_VIMGLOB; } diff --git a/src/nvim/os/stdpaths.c b/src/nvim/os/stdpaths.c index 5d6ffc1db1..faeb2fe829 100644 --- a/src/nvim/os/stdpaths.c +++ b/src/nvim/os/stdpaths.c @@ -103,7 +103,8 @@ char *get_xdg_home(const XDGVarType idx) if (dir) { #if defined(WIN32) dir = concat_fnames_realloc(dir, - (idx == kXDGDataHome ? "nvim-data" : "nvim"), + ((idx == kXDGDataHome + || idx == kXDGStateHome) ? "nvim-data" : "nvim"), true); #else dir = concat_fnames_realloc(dir, "nvim", true); diff --git a/src/nvim/os/users.c b/src/nvim/os/users.c index e0ce3fec31..4803be20c3 100644 --- a/src/nvim/os/users.c +++ b/src/nvim/os/users.c @@ -187,11 +187,11 @@ static void init_users(void) } /// Given to ExpandGeneric() to obtain an user names. -char_u *get_users(expand_T *xp, int idx) +char *get_users(expand_T *xp, int idx) { init_users(); if (idx < ga_users.ga_len) { - return ((char_u **)ga_users.ga_data)[idx]; + return ((char **)ga_users.ga_data)[idx]; } return NULL; } diff --git a/src/nvim/path.c b/src/nvim/path.c index 0bb364184a..fd6cca63f4 100644 --- a/src/nvim/path.c +++ b/src/nvim/path.c @@ -92,15 +92,15 @@ FileComparison path_full_compare(char_u *const s1, char_u *const s2, const bool /// /// @return pointer just past the last path separator (empty string, if fname /// ends in a slash), or empty string if fname is NULL. -char_u *path_tail(const char_u *fname) +char *path_tail(const char *fname) FUNC_ATTR_NONNULL_RET { if (fname == NULL) { - return (char_u *)""; + return ""; } - const char_u *tail = get_past_head(fname); - const char_u *p = tail; + const char *tail = (char *)get_past_head((char_u *)fname); + const char *p = tail; // Find last part of path. while (*p != NUL) { if (vim_ispathsep_nocolon(*p)) { @@ -108,7 +108,7 @@ char_u *path_tail(const char_u *fname) } MB_PTR_ADV(p); } - return (char_u *)tail; + return (char *)tail; } /// Get pointer to tail of "fname", including path separators. @@ -126,7 +126,7 @@ char_u *path_tail_with_sep(char_u *fname) // Don't remove the '/' from "c:/file". char_u *past_head = get_past_head(fname); - char_u *tail = path_tail(fname); + char_u *tail = (char_u *)path_tail((char *)fname); while (tail > past_head && after_pathsep((char *)fname, (char *)tail)) { tail--; } @@ -275,7 +275,7 @@ int vim_ispathlistsep(int c) /// It's done in-place. void shorten_dir_len(char_u *str, int trim_len) { - char_u *tail = path_tail(str); + char_u *tail = (char_u *)path_tail((char *)str); char_u *d = str; bool skip = false; int dirchunk_len = 0; @@ -849,7 +849,7 @@ static void expand_path_option(char_u *curdir, garray_T *gap) if (curbuf->b_ffname == NULL) { continue; } - char_u *p = path_tail(curbuf->b_ffname); + char_u *p = (char_u *)path_tail((char *)curbuf->b_ffname); size_t len = (size_t)(p - curbuf->b_ffname); if (len + STRLEN(buf) >= MAXPATHL) { continue; @@ -1375,17 +1375,18 @@ static int vim_backtick(char_u *p) /// @param flags EW_* flags static int expand_backtick(garray_T *gap, char_u *pat, int flags) { - char_u *p; - char_u *buffer; + char *p; + char *buffer; int cnt = 0; // Create the command: lop off the backticks. - char_u *cmd = vim_strnsave(pat + 1, STRLEN(pat) - 2); + char *cmd = (char *)vim_strnsave(pat + 1, STRLEN(pat) - 2); if (*cmd == '=') { // `={expr}`: Expand expression - buffer = (char_u *)eval_to_string((char *)cmd + 1, (char **)&p, true); + buffer = eval_to_string(cmd + 1, &p, true); } else { - buffer = get_cmd_output(cmd, NULL, (flags & EW_SILENT) ? kShellOptSilent : 0, NULL); + buffer = (char *)get_cmd_output((char_u *)cmd, NULL, (flags & EW_SILENT) ? kShellOptSilent : 0, + NULL); } xfree(cmd); if (buffer == NULL) { @@ -1394,16 +1395,16 @@ static int expand_backtick(garray_T *gap, char_u *pat, int flags) cmd = buffer; while (*cmd != NUL) { - cmd = (char_u *)skipwhite((char *)cmd); // skip over white space + cmd = skipwhite(cmd); // skip over white space p = cmd; while (*p != NUL && *p != '\r' && *p != '\n') { // skip over entry ++p; } // add an entry if it is not empty if (p > cmd) { - char_u i = *p; + char i = *p; *p = NUL; - addfile(gap, cmd, flags); + addfile(gap, (char_u *)cmd, flags); *p = i; ++cnt; } @@ -2244,7 +2245,7 @@ int match_suffix(char_u *fname) for (char_u *setsuf = p_su; *setsuf;) { setsuflen = copy_option_part(&setsuf, suf_buf, MAXSUFLEN, ".,"); if (setsuflen == 0) { - char_u *tail = path_tail(fname); + char_u *tail = (char_u *)path_tail((char *)fname); // empty entry: match name without a '.' if (vim_strchr(tail, '.') == NULL) { diff --git a/src/nvim/quickfix.c b/src/nvim/quickfix.c index 394f819f13..c9e6f9c210 100644 --- a/src/nvim/quickfix.c +++ b/src/nvim/quickfix.c @@ -3104,7 +3104,7 @@ static void qf_list_entry(qfline_T *qfp, int qf_idx, bool cursel) && (buf = buflist_findnr(qfp->qf_fnum)) != NULL) { fname = (char *)buf->b_fname; if (qfp->qf_type == 1) { // :helpgrep - fname = (char *)path_tail((char_u *)fname); + fname = path_tail(fname); } } if (fname == NULL) { @@ -4038,7 +4038,7 @@ static int qf_buf_add_line(qf_list_T *qfl, buf_T *buf, linenr_T lnum, const qfli && (errbuf = buflist_findnr(qfp->qf_fnum)) != NULL && errbuf->b_fname != NULL) { if (qfp->qf_type == 1) { // :helpgrep - STRLCPY(IObuff, path_tail(errbuf->b_fname), IOSIZE); + STRLCPY(IObuff, path_tail((char *)errbuf->b_fname), IOSIZE); } else { // Shorten the file name if not done already. // For optimization, do this only for the first entry in a @@ -5740,7 +5740,7 @@ static buf_T *load_dummy_buffer(char *fname, char *dirname_start, char *resultin curbuf->b_flags &= ~BF_DUMMY; newbuf_to_wipe.br_buf = NULL; - readfile_result = readfile((char_u *)fname, NULL, (linenr_T)0, (linenr_T)0, + readfile_result = readfile(fname, NULL, (linenr_T)0, (linenr_T)0, (linenr_T)MAXLNUM, NULL, READ_NEW | READ_DUMMY, false); newbuf->b_locked--; @@ -6887,7 +6887,7 @@ static int cbuffer_process_args(exarg_T *eap, buf_T **bufp, linenr_T *line1, lin if (*eap->arg == NUL) { buf = curbuf; - } else if (*skipwhite((char *)skipdigits((char_u *)eap->arg)) == NUL) { + } else if (*skipwhite(skipdigits(eap->arg)) == NUL) { buf = buflist_findnr(atoi(eap->arg)); } diff --git a/src/nvim/screen.c b/src/nvim/screen.c index 36e8f11bbb..003230d110 100644 --- a/src/nvim/screen.c +++ b/src/nvim/screen.c @@ -3006,6 +3006,10 @@ static int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool noc if (area_attr != 0) { char_attr = hl_combine_attr(line_attr, area_attr); + if (!highlight_match) { + // let search highlight show in Visual area if possible + char_attr = hl_combine_attr(search_attr, char_attr); + } } else if (search_attr != 0) { char_attr = hl_combine_attr(line_attr, search_attr); } diff --git a/src/nvim/sign.c b/src/nvim/sign.c index 6a690f9af8..99a00aefa9 100644 --- a/src/nvim/sign.c +++ b/src/nvim/sign.c @@ -1742,33 +1742,33 @@ static char_u *get_nth_sign_group_name(int idx) /// Function given to ExpandGeneric() to obtain the sign command /// expansion. -char_u *get_sign_name(expand_T *xp, int idx) +char *get_sign_name(expand_T *xp, int idx) { switch (expand_what) { case EXP_SUBCMD: - return (char_u *)cmds[idx]; + return cmds[idx]; case EXP_DEFINE: { char *define_arg[] = { "culhl=", "icon=", "linehl=", "numhl=", "text=", "texthl=", NULL }; - return (char_u *)define_arg[idx]; + return define_arg[idx]; } case EXP_PLACE: { char *place_arg[] = { "line=", "name=", "group=", "priority=", "file=", "buffer=", NULL }; - return (char_u *)place_arg[idx]; + return place_arg[idx]; } case EXP_LIST: { char *list_arg[] = { "group=", "file=", "buffer=", NULL }; - return (char_u *)list_arg[idx]; + return list_arg[idx]; } case EXP_UNPLACE: { char *unplace_arg[] = { "group=", "file=", "buffer=", NULL }; - return (char_u *)unplace_arg[idx]; + return unplace_arg[idx]; } case EXP_SIGN_NAMES: - return get_nth_sign_name(idx); + return (char *)get_nth_sign_name(idx); case EXP_SIGN_GROUPS: - return get_nth_sign_group_name(idx); + return (char *)get_nth_sign_group_name(idx); default: return NULL; } diff --git a/src/nvim/spell.c b/src/nvim/spell.c index fc3bcef666..b2969c5332 100644 --- a/src/nvim/spell.c +++ b/src/nvim/spell.c @@ -385,7 +385,7 @@ size_t spell_check(win_T *wp, char_u *ptr, hlf_T *attrp, int *capcol, bool docou } else if (*ptr == '0' && (ptr[1] == 'x' || ptr[1] == 'X')) { mi.mi_end = skiphex(ptr + 2); } else { - mi.mi_end = skipdigits(ptr); + mi.mi_end = (char_u *)skipdigits((char *)ptr); } nrlen = (size_t)(mi.mi_end - ptr); } @@ -1656,7 +1656,7 @@ void spell_cat_line(char_u *buf, char_u *line, int maxlen) // "lang" must be the language without the region: e.g., "en". static void spell_load_lang(char_u *lang) { - char_u fname_enc[85]; + char fname_enc[85]; int r; spelload_T sl; int round; @@ -2105,7 +2105,7 @@ char *did_set_spelllang(win_T *wp) filename = true; // Locate a region and remove it from the file name. - p = vim_strchr(path_tail(lang), '_'); + p = vim_strchr((char_u *)path_tail((char *)lang), '_'); if (p != NULL && ASCII_ISALPHA(p[1]) && ASCII_ISALPHA(p[2]) && !ASCII_ISALPHA(p[3])) { STRLCPY(region_cp, p + 1, 3); @@ -2247,7 +2247,7 @@ char *did_set_spelllang(win_T *wp) if (round == 0) { STRCPY(lang, "internal wordlist"); } else { - STRLCPY(lang, path_tail(spf_name), MAXWLEN + 1); + STRLCPY(lang, path_tail((char *)spf_name), MAXWLEN + 1); p = vim_strchr(lang, '.'); if (p != NULL) { *p = NUL; // truncate at ".encoding.add" @@ -5652,12 +5652,12 @@ static void make_case_word(char_u *fword, char_u *cword, int flags) static bool similar_chars(slang_T *slang, int c1, int c2) { int m1, m2; - char_u buf[MB_MAXBYTES + 1]; + char buf[MB_MAXBYTES + 1]; hashitem_T *hi; if (c1 >= 256) { buf[utf_char2bytes(c1, (char *)buf)] = 0; - hi = hash_find(&slang->sl_map_hash, buf); + hi = hash_find(&slang->sl_map_hash, (char_u *)buf); if (HASHITEM_EMPTY(hi)) { m1 = 0; } else { @@ -5672,7 +5672,7 @@ static bool similar_chars(slang_T *slang, int c1, int c2) if (c2 >= 256) { buf[utf_char2bytes(c2, (char *)buf)] = 0; - hi = hash_find(&slang->sl_map_hash, buf); + hi = hash_find(&slang->sl_map_hash, (char_u *)buf); if (HASHITEM_EMPTY(hi)) { m2 = 0; } else { @@ -6871,20 +6871,20 @@ void ex_spellinfo(exarg_T *eap) // ":spelldump" void ex_spelldump(exarg_T *eap) { - char_u *spl; + char *spl; long dummy; if (no_spell_checking(curwin)) { return; } - get_option_value("spl", &dummy, (char **)&spl, OPT_LOCAL); + get_option_value("spl", &dummy, &spl, OPT_LOCAL); // Create a new empty buffer in a new window. do_cmdline_cmd("new"); // enable spelling locally in the new window set_option_value("spell", true, "", OPT_LOCAL); - set_option_value("spl", dummy, (char *)spl, OPT_LOCAL); + set_option_value("spl", dummy, spl, OPT_LOCAL); xfree(spl); if (!buf_is_empty(curbuf)) { diff --git a/src/nvim/spellfile.c b/src/nvim/spellfile.c index b7ee3e7374..6f0bd04d39 100644 --- a/src/nvim/spellfile.c +++ b/src/nvim/spellfile.c @@ -302,6 +302,7 @@ #define CF_UPPER 0x02 static char *e_spell_trunc = N_("E758: Truncated spell file"); +static char *e_illegal_character_in_word = N_("E1280: Illegal character in word"); static char *e_afftrailing = N_("Trailing text in %s line %d: %s"); static char *e_affname = N_("Affix name too long in %s line %d: %s"); static char *msg_compressing = N_("Compressing word tree..."); @@ -575,7 +576,7 @@ slang_T *spell_load_file(char_u *fname, char_u *lang, slang_T *old_lp, bool sile char_u *p; int n; int len; - char_u *save_sourcing_name = sourcing_name; + char_u *save_sourcing_name = (char_u *)sourcing_name; linenr_T save_sourcing_lnum = sourcing_lnum; slang_T *lp = NULL; int c = 0; @@ -605,13 +606,13 @@ slang_T *spell_load_file(char_u *fname, char_u *lang, slang_T *old_lp, bool sile lp->sl_fname = vim_strsave(fname); // Check for .add.spl. - lp->sl_add = strstr((char *)path_tail(fname), SPL_FNAME_ADD) != NULL; + lp->sl_add = strstr(path_tail((char *)fname), SPL_FNAME_ADD) != NULL; } else { lp = old_lp; } // Set sourcing_name, so that error messages mention the file name. - sourcing_name = fname; + sourcing_name = (char *)fname; sourcing_lnum = 0; // <HEADER>: <fileID> @@ -809,7 +810,7 @@ endOK: if (fd != NULL) { fclose(fd); } - sourcing_name = save_sourcing_name; + sourcing_name = (char *)save_sourcing_name; sourcing_lnum = save_sourcing_lnum; return lp; @@ -2251,7 +2252,7 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char_u *fname) } } 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) { + if (compflags != NULL || *skipdigits((char *)items[1]) != NUL) { // Concatenate this string to previously defined ones, // using a slash to separate them. l = (int)STRLEN(items[1]) + 1; @@ -3927,6 +3928,11 @@ static int store_word(spellinfo_T *spin, char_u *word, int flags, int region, co char_u foldword[MAXWLEN]; int res = OK; + // Avoid adding illegal bytes to the word tree. + if (!utf_valid_string(word, NULL)) { + return FAIL; + } + (void)spell_casefold(curwin, word, len, foldword, MAXWLEN); for (const char_u *p = pfxlist; res == OK; p++) { if (!need_affix || (p != NULL && *p != NUL)) { @@ -4401,7 +4407,7 @@ static int write_vim_spell(spellinfo_T *spin, char_u *fname) // Also skip this for an .add.spl file, the main spell file must contain // the table (avoids that it conflicts). File is shorter too. if (!spin->si_ascii && !spin->si_add) { - char_u folchars[128 * 8]; + char folchars[128 * 8]; int flags; putc(SN_CHARFLAGS, fd); // <sectionID> @@ -5320,19 +5326,19 @@ static void mkspell(int fcount, char_u **fnames, bool ascii, bool over_write, bo } // Check for .ascii.spl. - if (strstr((char *)path_tail(wfname), SPL_FNAME_ASCII) != NULL) { + if (strstr(path_tail((char *)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(path_tail((char *)wfname), SPL_FNAME_ADD) != NULL) { spin.si_add = true; } } if (incount <= 0) { emsg(_(e_invarg)); // need at least output and input names - } else if (vim_strchr(path_tail(wfname), '_') != NULL) { + } else if (vim_strchr((char_u *)path_tail((char *)wfname), '_') != NULL) { emsg(_("E751: Output file name must not have region name")); } else if (incount > MAXREGIONS) { semsg(_("E754: Only up to %d regions supported"), MAXREGIONS); @@ -5357,7 +5363,7 @@ static void mkspell(int fcount, char_u **fnames, bool ascii, bool over_write, bo if (incount > 1) { len = (int)STRLEN(innames[i]); - if (STRLEN(path_tail(innames[i])) < 5 + if (STRLEN(path_tail((char *)innames[i])) < 5 || innames[i][len - 3] != '_') { semsg(_("E755: Invalid region in %s"), innames[i]); goto theend; @@ -5525,6 +5531,11 @@ void spell_add_word(char_u *word, int len, SpellAddType what, int idx, bool undo int i; char_u *spf; + if (!utf_valid_string(word, NULL)) { + emsg(_(e_illegal_character_in_word)); + return; + } + if (idx == 0) { // use internal wordlist if (int_wordlist == NULL) { int_wordlist = vim_tempname(); @@ -5725,7 +5736,7 @@ static void init_spellfile(void) ->lp_slang->sl_fname; vim_snprintf((char *)buf + l, MAXPATHL - l, ".%s.add", ((fname != NULL - && strstr((char *)path_tail(fname), ".ascii.") != NULL) + && strstr(path_tail((char *)fname), ".ascii.") != NULL) ? "ascii" : (const char *)spell_enc())); set_option_value("spellfile", 0L, (const char *)buf, OPT_LOCAL); @@ -5862,7 +5873,7 @@ static void set_map_str(slang_T *lp, char_u *map) if (c >= 256) { int cl = utf_char2len(c); int headcl = utf_char2len(headc); - char_u *b; + char *b; hash_T hash; hashitem_T *hi; @@ -5871,10 +5882,10 @@ static void set_map_str(slang_T *lp, char_u *map) b[cl] = NUL; utf_char2bytes(headc, (char *)b + cl + 1); b[cl + 1 + headcl] = NUL; - hash = hash_hash(b); + hash = hash_hash((char_u *)b); hi = hash_lookup(&lp->sl_map_hash, (const char *)b, STRLEN(b), hash); if (HASHITEM_EMPTY(hi)) { - hash_add_item(&lp->sl_map_hash, hi, b, hash); + hash_add_item(&lp->sl_map_hash, hi, (char_u *)b, hash); } else { // This should have been checked when generating the .spl // file. diff --git a/src/nvim/syntax.c b/src/nvim/syntax.c index d64494fd85..d82e337aa6 100644 --- a/src/nvim/syntax.c +++ b/src/nvim/syntax.c @@ -5303,8 +5303,8 @@ static void syn_cmd_sync(exarg_T *eap, int syncing) /// @return FAIL for some error, OK for success. static int get_id_list(char_u **const arg, const int keylen, int16_t **const list, const bool skip) { - char_u *p = NULL; - char_u *end; + char *p = NULL; + char *end; int total_count = 0; int16_t *retval = NULL; regmatch_T regmatch; @@ -5318,12 +5318,12 @@ static int get_id_list(char_u **const arg, const int keylen, int16_t **const lis // grow when a regexp is used. In that case round 1 is done once again. for (int round = 1; round <= 2; round++) { // skip "contains" - p = (char_u *)skipwhite((char *)(*arg) + keylen); + p = skipwhite((char *)(*arg) + keylen); if (*p != '=') { semsg(_("E405: Missing equal sign: %s"), *arg); break; } - p = (char_u *)skipwhite((char *)p + 1); + p = skipwhite(p + 1); if (ends_excmd(*p)) { semsg(_("E406: Empty argument: %s"), *arg); break; @@ -5427,11 +5427,11 @@ static int get_id_list(char_u **const arg, const int keylen, int16_t **const lis } ++count; } - p = (char_u *)skipwhite((char *)end); + p = skipwhite(end); if (*p != ',') { break; } - p = (char_u *)skipwhite((char *)p + 1); // skip comma in between arguments + p = skipwhite(p + 1); // skip comma in between arguments } while (!ends_excmd(*p)); if (failed) { break; @@ -5443,7 +5443,7 @@ static int get_id_list(char_u **const arg, const int keylen, int16_t **const lis } } - *arg = p; + *arg = (char_u *)p; if (failed || retval == NULL) { xfree(retval); return FAIL; @@ -5763,26 +5763,26 @@ void set_context_in_syntax_cmd(expand_T *xp, const char *arg) * Function given to ExpandGeneric() to obtain the list syntax names for * expansion. */ -char_u *get_syntax_name(expand_T *xp, int idx) +char *get_syntax_name(expand_T *xp, int idx) { switch (expand_what) { case EXP_SUBCMD: - return (char_u *)subcommands[idx].name; + return subcommands[idx].name; case EXP_CASE: { static char *case_args[] = { "match", "ignore", NULL }; - return (char_u *)case_args[idx]; + return case_args[idx]; } case EXP_SPELL: { static char *spell_args[] = { "toplevel", "notoplevel", "default", NULL }; - return (char_u *)spell_args[idx]; + return spell_args[idx]; } case EXP_SYNC: { static char *sync_args[] = { "ccomment", "clear", "fromstart", "linebreaks=", "linecont", "lines=", "match", "maxlines=", "minlines=", "region", NULL }; - return (char_u *)sync_args[idx]; + return sync_args[idx]; } } return NULL; @@ -5965,17 +5965,17 @@ static void syntime_clear(void) * Function given to ExpandGeneric() to obtain the possible arguments of the * ":syntime {on,off,clear,report}" command. */ -char_u *get_syntime_arg(expand_T *xp, int idx) +char *get_syntime_arg(expand_T *xp, int idx) { switch (idx) { case 0: - return (char_u *)"on"; + return "on"; case 1: - return (char_u *)"off"; + return "off"; case 2: - return (char_u *)"clear"; + return "clear"; case 3: - return (char_u *)"report"; + return "report"; } return NULL; } diff --git a/src/nvim/tag.c b/src/nvim/tag.c index ec4b97963c..1f0d027321 100644 --- a/src/nvim/tag.c +++ b/src/nvim/tag.c @@ -2369,7 +2369,7 @@ int get_tagfname(tagname_T *tnp, int first, char_u *buf) } ++tnp->tn_hf_idx; STRCPY(buf, p_hf); - STRCPY(path_tail(buf), "tags"); + STRCPY(path_tail((char *)buf), "tags"); #ifdef BACKSLASH_IN_FILENAME slash_adjust(buf); #endif @@ -2428,7 +2428,7 @@ int get_tagfname(tagname_T *tnp, int first, char_u *buf) r_ptr = vim_findfile_stopdir(buf); // move the filename one char forward and truncate the // filepath with a NUL - filename = path_tail(buf); + filename = (char_u *)path_tail((char *)buf); STRMOVE(filename + 1, filename); *filename++ = NUL; @@ -2715,7 +2715,7 @@ static int jumpto_tag(const char_u *lbuf_arg, int forceit, int keep_help) * autocommand event (e.g., http://sys/file). */ if (!os_path_exists(fname) - && !has_autocmd(EVENT_BUFREADCMD, fname, + && !has_autocmd(EVENT_BUFREADCMD, (char *)fname, NULL)) { retval = NOTAGFILE; xfree(nofile_fname); @@ -2997,7 +2997,7 @@ static char_u *expand_tag_fname(char_u *fname, char_u *const tag_fname, const bo char_u *retval; if ((p_tr || curbuf->b_help) && !vim_isAbsName(fname) - && (p = path_tail(tag_fname)) != tag_fname) { + && (p = (char_u *)path_tail((char *)tag_fname)) != tag_fname) { retval = xmalloc(MAXPATHL); STRCPY(retval, tag_fname); STRLCPY(retval + (p - tag_fname), fname, @@ -3054,7 +3054,7 @@ static int find_extra(char_u **pp) // Repeat for addresses separated with ';' for (;;) { if (ascii_isdigit(*str)) { - str = skipdigits(str + 1); + str = (char_u *)skipdigits((char *)str + 1); } else if (*str == '/' || *str == '?') { str = skip_regexp(str + 1, *str, false, NULL); if (*str != first_char) { diff --git a/src/nvim/testdir/setup.vim b/src/nvim/testdir/setup.vim index 15e3b31498..f1092af358 100644 --- a/src/nvim/testdir/setup.vim +++ b/src/nvim/testdir/setup.vim @@ -26,11 +26,9 @@ set sessionoptions+=options set viewoptions+=options set switchbuf= -" Unmap Nvim default mappings. -unmap Y -unmap <C-L> -iunmap <C-U> -iunmap <C-W> +" Clear Nvim default mappings. +mapclear +mapclear! " Prevent Nvim log from writing to stderr. let $NVIM_LOG_FILE = exists($NVIM_LOG_FILE) ? $NVIM_LOG_FILE : 'Xnvim.log' diff --git a/src/nvim/testdir/test_options.vim b/src/nvim/testdir/test_options.vim index 8f67b1732e..9e16625cc2 100644 --- a/src/nvim/testdir/test_options.vim +++ b/src/nvim/testdir/test_options.vim @@ -832,4 +832,17 @@ func Test_opt_cdhome() set cdhome& endfunc +func Test_switchbuf_reset() + set switchbuf=useopen + sblast + call assert_equal(1, winnr('$')) + set all& + " Nvim has a different default for 'switchbuf' + " call assert_equal('', &switchbuf) + call assert_equal('uselast', &switchbuf) + sblast + call assert_equal(2, winnr('$')) + only! +endfunc + " vim: shiftwidth=2 sts=2 expandtab diff --git a/src/nvim/testdir/test_search.vim b/src/nvim/testdir/test_search.vim index d359e69f91..454c956996 100644 --- a/src/nvim/testdir/test_search.vim +++ b/src/nvim/testdir/test_search.vim @@ -925,6 +925,26 @@ func Test_hlsearch_block_visual_match() call delete('Xhlsearch_block') endfunc +func Test_hlsearch_and_visual() + CheckOption hlsearch + CheckScreendump + + call writefile([ + \ 'set hlsearch', + \ 'call setline(1, repeat(["xxx yyy zzz"], 3))', + \ 'hi Search cterm=bold', + \ '/yyy', + \ 'call cursor(1, 6)', + \ ], 'Xhlvisual_script') + let buf = RunVimInTerminal('-S Xhlvisual_script', {'rows': 6, 'cols': 40}) + call term_sendkeys(buf, "vjj") + call VerifyScreenDump(buf, 'Test_hlsearch_visual_1', {}) + call term_sendkeys(buf, "\<Esc>") + + call StopVimInTerminal(buf) + call delete('Xhlvisual_script') +endfunc + func Test_incsearch_substitute() CheckFunction test_override CheckOption incsearch diff --git a/src/nvim/testdir/test_spell.vim b/src/nvim/testdir/test_spell.vim index 56ed97cdd9..ce21b8bdc9 100644 --- a/src/nvim/testdir/test_spell.vim +++ b/src/nvim/testdir/test_spell.vim @@ -776,14 +776,6 @@ func Test_spell_screendump() call delete('XtestSpell') endfunc -func Test_spell_single_word() - new - silent! norm 0R00 - spell! ß - silent 0norm 0r$ Dvz= - bwipe! -endfunc - let g:test_data_aff1 = [ \"SET ISO8859-1", \"TRY esianrtolcdugmphbyfvkwjkqxz-\xEB\xE9\xE8\xEA\xEF\xEE\xE4\xE0\xE2\xF6\xFC\xFB'ESIANRTOLCDUGMPHBYFVKWJKQXZ", diff --git a/src/nvim/testdir/test_spell_utf8.vim b/src/nvim/testdir/test_spell_utf8.vim index 3d159f3352..1d323df67e 100644 --- a/src/nvim/testdir/test_spell_utf8.vim +++ b/src/nvim/testdir/test_spell_utf8.vim @@ -768,4 +768,10 @@ func Test_spellfile_value() set spellfile=Xdir/Xtest.utf-8.add,Xtest_other.add endfunc +" Invalid bytes may cause trouble when creating the word list. +func Test_check_for_valid_word() + call assert_fails("spellgood! 0\xac", 'E1280:') +endfunc + + " vim: shiftwidth=2 sts=2 expandtab diff --git a/src/nvim/testdir/test_undo.vim b/src/nvim/testdir/test_undo.vim index 30e00e7ad4..848860649e 100644 --- a/src/nvim/testdir/test_undo.vim +++ b/src/nvim/testdir/test_undo.vim @@ -733,4 +733,21 @@ func Test_undofile_cryptmethod_blowfish2() set undofile& undolevels& cryptmethod& endfunc +func Test_undo_mark() + new + " The undo is applied to the only line. + call setline(1, 'hello') + call feedkeys("ggyiw$p", 'xt') + undo + call assert_equal([0, 1, 1, 0], getpos("'[")) + call assert_equal([0, 1, 1, 0], getpos("']")) + " The undo removes the last line. + call feedkeys("Goaaaa\<Esc>", 'xt') + call feedkeys("obbbb\<Esc>", 'xt') + undo + call assert_equal([0, 2, 1, 0], getpos("'[")) + call assert_equal([0, 2, 1, 0], getpos("']")) + bwipe! +endfunc + " vim: shiftwidth=2 sts=2 expandtab diff --git a/src/nvim/undo.c b/src/nvim/undo.c index 937e86b161..529eef19a3 100644 --- a/src/nvim/undo.c +++ b/src/nvim/undo.c @@ -702,7 +702,7 @@ char *u_get_undo_file_name(const char *const buf_ffname, const bool reading) const size_t ffname_len = strlen(ffname); undo_file_name = xmalloc(ffname_len + 6); memmove(undo_file_name, ffname, ffname_len + 1); - char *const tail = (char *)path_tail((char_u *)undo_file_name); + char *const tail = path_tail(undo_file_name); const size_t tail_len = strlen(tail); memmove(tail + 1, tail, tail_len + 1); *tail = '.'; @@ -2418,10 +2418,11 @@ static void u_undoredo(int undo, bool do_buf_event) changed_lines(top + 1, 0, bot, newsize - oldsize, do_buf_event); - // set '[ and '] mark + // Set the '[ mark. if (top + 1 < curbuf->b_op_start.lnum) { curbuf->b_op_start.lnum = top + 1; } + // Set the '] mark. if (newsize == 0 && top + 1 > curbuf->b_op_end.lnum) { curbuf->b_op_end.lnum = top + 1; } else if (top + newsize > curbuf->b_op_end.lnum) { @@ -2442,6 +2443,14 @@ static void u_undoredo(int undo, bool do_buf_event) newlist = uep; } + // Ensure the '[ and '] marks are within bounds. + if (curbuf->b_op_start.lnum > curbuf->b_ml.ml_line_count) { + curbuf->b_op_start.lnum = curbuf->b_ml.ml_line_count; + } + if (curbuf->b_op_end.lnum > curbuf->b_ml.ml_line_count) { + curbuf->b_op_end.lnum = curbuf->b_ml.ml_line_count; + } + // Adjust Extmarks ExtmarkUndoObject undo_info; if (undo) { diff --git a/src/nvim/window.c b/src/nvim/window.c index 3420e5a10d..9f7e2f8341 100644 --- a/src/nvim/window.c +++ b/src/nvim/window.c @@ -6477,7 +6477,7 @@ char_u *file_name_at_cursor(int options, long count, linenr_T *file_lnum) char_u *file_name_in_line(char_u *line, int col, int options, long count, char_u *rel_fname, linenr_T *file_lnum) { - char_u *ptr; + char *ptr; size_t len; bool in_type = true; bool is_url = false; @@ -6485,7 +6485,7 @@ char_u *file_name_in_line(char_u *line, int col, int options, long count, char_u /* * search forward for what could be the start of a file name */ - ptr = line + col; + ptr = (char *)line + col; while (*ptr != NUL && !vim_isfilec(*ptr)) { MB_PTR_ADV(ptr); } @@ -6500,11 +6500,10 @@ char_u *file_name_in_line(char_u *line, int col, int options, long count, char_u * Search backward for first char of the file name. * Go one char back to ":" before "//" even when ':' is not in 'isfname'. */ - while (ptr > line) { - if ((len = (size_t)(utf_head_off(line, ptr - 1))) > 0) { + while ((char_u *)ptr > line) { + if ((len = (size_t)(utf_head_off(line, (char_u *)ptr - 1))) > 0) { ptr -= len + 1; - } else if (vim_isfilec(ptr[-1]) - || ((options & FNAME_HYP) && path_is_url((char *)ptr - 1))) { + } else if (vim_isfilec(ptr[-1]) || ((options & FNAME_HYP) && path_is_url(ptr - 1))) { ptr--; } else { break; @@ -6517,13 +6516,13 @@ char_u *file_name_in_line(char_u *line, int col, int options, long count, char_u */ len = 0; while (vim_isfilec(ptr[len]) || (ptr[len] == '\\' && ptr[len + 1] == ' ') - || ((options & FNAME_HYP) && path_is_url((char *)ptr + len)) + || ((options & FNAME_HYP) && path_is_url(ptr + len)) || (is_url && vim_strchr((char_u *)":?&=", ptr[len]) != NULL)) { // After type:// we also include :, ?, & and = as valid characters, so that // http://google.com:8080?q=this&that=ok works. if ((ptr[len] >= 'A' && ptr[len] <= 'Z') || (ptr[len] >= 'a' && ptr[len] <= 'z')) { - if (in_type && path_is_url((char *)ptr + len + 1)) { + if (in_type && path_is_url(ptr + len + 1)) { is_url = true; } } else { @@ -6534,7 +6533,7 @@ char_u *file_name_in_line(char_u *line, int col, int options, long count, char_u // Skip over the "\" in "\ ". ++len; } - len += (size_t)(utfc_ptr2len((char *)ptr + len)); + len += (size_t)(utfc_ptr2len(ptr + len)); } /* @@ -6547,7 +6546,7 @@ char_u *file_name_in_line(char_u *line, int col, int options, long count, char_u } if (file_lnum != NULL) { - char_u *p; + char *p; const char *line_english = " line "; const char *line_transl = _(line_msg); @@ -6560,20 +6559,20 @@ char_u *file_name_in_line(char_u *line, int col, int options, long count, char_u } else if (STRNCMP(p, line_transl, STRLEN(line_transl)) == 0) { p += STRLEN(line_transl); } else { - p = (char_u *)skipwhite((char *)p); + p = skipwhite(p); } if (*p != NUL) { if (!isdigit(*p)) { p++; // skip the separator } - p = (char_u *)skipwhite((char *)p); + p = skipwhite(p); if (isdigit(*p)) { - *file_lnum = getdigits_long(&p, false, 0); + *file_lnum = getdigits_long((char_u **)&p, false, 0); } } } - return find_file_name_in_path(ptr, len, options, count, rel_fname); + return find_file_name_in_path((char_u *)ptr, len, options, count, rel_fname); } /// Add or remove a status line from window(s), according to the diff --git a/test/functional/fixtures/fake-lsp-server.lua b/test/functional/fixtures/fake-lsp-server.lua index f589f5955f..86cdf4ef56 100644 --- a/test/functional/fixtures/fake-lsp-server.lua +++ b/test/functional/fixtures/fake-lsp-server.lua @@ -766,8 +766,21 @@ function tests.code_action_filter() isPreferred = true, command = 'preferred_command', } + local quickfix_action = { + title = 'Action 3', + kind = 'quickfix', + command = 'quickfix_command', + } + local quickfix_foo_action = { + title = 'Action 4', + kind = 'quickfix.foo', + command = 'quickfix_foo_command', + } + expect_request('textDocument/codeAction', function() + return nil, { action, preferred_action, quickfix_action, quickfix_foo_action, } + end) expect_request('textDocument/codeAction', function() - return nil, { action, preferred_action, } + return nil, { action, preferred_action, quickfix_action, quickfix_foo_action, } end) notify('shutdown') end; diff --git a/test/functional/helpers.lua b/test/functional/helpers.lua index e9c3d4bd92..3d64625752 100644 --- a/test/functional/helpers.lua +++ b/test/functional/helpers.lua @@ -41,10 +41,8 @@ module.nvim_set = ( module.nvim_argv = { module.nvim_prog, '-u', 'NONE', '-i', 'NONE', '--cmd', module.nvim_set, - '--cmd', 'unmap Y', - '--cmd', 'unmap <C-L>', - '--cmd', 'iunmap <C-U>', - '--cmd', 'iunmap <C-W>', + '--cmd', 'mapclear', + '--cmd', 'mapclear!', '--embed'} -- Directory containing nvim. diff --git a/test/functional/legacy/search_spec.lua b/test/functional/legacy/search_spec.lua index 4ed08881de..67991f5d48 100644 --- a/test/functional/legacy/search_spec.lua +++ b/test/functional/legacy/search_spec.lua @@ -7,6 +7,7 @@ local eval = helpers.eval local feed = helpers.feed local funcs = helpers.funcs local poke_eventloop = helpers.poke_eventloop +local exec = helpers.exec describe('search cmdline', function() local screen @@ -640,3 +641,34 @@ describe('search cmdline', function() feed('<esc>') end) end) + +describe('Search highlight', function() + before_each(clear) + it('Search highlight is combined with Visual highlight vim-patch:8.2.2797', function() + local screen = Screen.new(40, 6) + screen:set_default_attr_ids({ + [1] = {bold = true, foreground = Screen.colors.Blue}, -- NonText + [2] = {bold = true}, -- ModeMsg, Search + [3] = {background = Screen.colors.LightGrey}, -- Visual + [4] = {background = Screen.colors.Yellow, bold = true}, -- Search + [5] = {background = Screen.colors.LightGrey, bold = true}, -- Visual + Search + }) + screen:attach() + exec([[ + set hlsearch noincsearch + call setline(1, repeat(["xxx yyy zzz"], 3)) + hi Search gui=bold + /yyy + call cursor(1, 6) + ]]) + feed('vjj') + screen:expect([[ + xxx {4:y}{5:yy}{3: zzz} | + {3:xxx }{5:yyy}{3: zzz} | + {3:xxx }{5:y}{4:^yy} zzz | + {1:~ }| + {1:~ }| + {2:-- VISUAL --} | + ]]) + end) +end) diff --git a/test/functional/options/defaults_spec.lua b/test/functional/options/defaults_spec.lua index 36a53d8d26..4731df7b95 100644 --- a/test/functional/options/defaults_spec.lua +++ b/test/functional/options/defaults_spec.lua @@ -206,7 +206,7 @@ describe('startup defaults', function() describe('$NVIM_LOG_FILE', function() local xdgdir = 'Xtest-startup-xdg-logpath' - local xdgstatedir = xdgdir..'/nvim' + local xdgstatedir = iswin() and xdgdir..'/nvim-data' or xdgdir..'/nvim' after_each(function() os.remove('Xtest-logpath') rmdir(xdgdir) diff --git a/test/functional/plugin/lsp_spec.lua b/test/functional/plugin/lsp_spec.lua index 33a8976b79..4cb7636825 100644 --- a/test/functional/plugin/lsp_spec.lua +++ b/test/functional/plugin/lsp_spec.lua @@ -2753,12 +2753,33 @@ describe('LSP', function() vim.lsp.commands['executed_preferred'] = function() end end + vim.lsp.commands['quickfix_command'] = function(cmd) + vim.lsp.commands['executed_quickfix'] = function() + end + end local bufnr = vim.api.nvim_get_current_buf() vim.lsp.buf_attach_client(bufnr, TEST_RPC_CLIENT_ID) vim.lsp.buf.code_action({ filter = function(a) return a.isPreferred end, apply = true, }) + vim.lsp.buf.code_action({ + -- expect to be returned actions 'quickfix' and 'quickfix.foo' + context = { only = {'quickfix'}, }, + apply = true, + filter = function(a) + if a.kind == 'quickfix.foo' then + vim.lsp.commands['filtered_quickfix_foo'] = function() end + return false + elseif a.kind == 'quickfix' then + return true + else + assert(nil, 'unreachable') + end + end, + }) ]]) elseif ctx.method == 'shutdown' then eq('function', exec_lua[[return type(vim.lsp.commands['executed_preferred'])]]) + eq('function', exec_lua[[return type(vim.lsp.commands['filtered_quickfix_foo'])]]) + eq('function', exec_lua[[return type(vim.lsp.commands['executed_quickfix'])]]) client.stop() end end diff --git a/test/functional/plugin/man_spec.lua b/test/functional/plugin/man_spec.lua index e5b2e7dc1f..c8da5a711f 100644 --- a/test/functional/plugin/man_spec.lua +++ b/test/functional/plugin/man_spec.lua @@ -2,13 +2,19 @@ local helpers = require('test.functional.helpers')(after_each) local Screen = require('test.functional.ui.screen') local command, eval, rawfeed = helpers.command, helpers.eval, helpers.rawfeed local clear = helpers.clear +local funcs = helpers.funcs +local nvim_prog = helpers.nvim_prog +local matches = helpers.matches describe(':Man', function() + before_each(function() + clear() + end) + describe('man.lua: highlight_line()', function() local screen before_each(function() - clear() command('syntax on') command('set filetype=man') command('syntax off') -- Ignore syntax groups @@ -137,4 +143,10 @@ describe(':Man', function() ]]) end) end) + + it('q quits in "$MANPAGER mode" (:Man!) #18281', function() + -- This will hang if #18281 regresses. + local args = {nvim_prog, '--headless', '+autocmd VimLeave * echo "quit works!!"', '+Man!', '+call nvim_input("q")'} + matches('quit works!!', funcs.system(args, {'manpage contents'})) + end) end) diff --git a/test/functional/ui/input_spec.lua b/test/functional/ui/input_spec.lua index 07582ba602..0f4e97088c 100644 --- a/test/functional/ui/input_spec.lua +++ b/test/functional/ui/input_spec.lua @@ -313,11 +313,6 @@ it('unsimplified mapping works when there was a partial match vim-patch:8.2.4504 expect('xb') end) -it('rhs of a mapping is not simplified', function() - command('nnoremap <Plug>foo <C-J>') - eq('<C-J>', funcs.maparg('<Plug>foo')) -end) - describe('input non-printable chars', function() after_each(function() os.remove('Xtest-overwrite') diff --git a/third-party/CMakeLists.txt b/third-party/CMakeLists.txt index 3d842c9777..21d1f7906a 100644 --- a/third-party/CMakeLists.txt +++ b/third-party/CMakeLists.txt @@ -39,7 +39,6 @@ set(DEPS_DOWNLOAD_DIR "${DEPS_BUILD_DIR}/downloads" CACHE PATH "Dependencies dow option(USE_BUNDLED "Use bundled dependencies." ON) -option(USE_BUNDLED_GPERF "Use the bundled version of gperf." ${USE_BUNDLED}) option(USE_BUNDLED_UNIBILIUM "Use the bundled unibilium." ${USE_BUNDLED}) option(USE_BUNDLED_LIBTERMKEY "Use the bundled libtermkey." ${USE_BUNDLED}) option(USE_BUNDLED_LIBVTERM "Use the bundled libvterm." ${USE_BUNDLED}) @@ -109,10 +108,6 @@ else() set(DEPS_C_COMPILER "${CMAKE_C_COMPILER}") endif() -if(USE_BUNDLED_GPERF) - enable_language(CXX) -endif() - if(CMAKE_CXX_COMPILER) set(DEPS_CXX_COMPILER "${CMAKE_CXX_COMPILER}") endif() @@ -176,9 +171,6 @@ set(LUV_SHA256 cabb7e650f35992686eb95ae167c71614e281cd2979fc804e4e70f8051555728) set(LUA_COMPAT53_URL https://github.com/keplerproject/lua-compat-5.3/archive/v0.9.tar.gz) set(LUA_COMPAT53_SHA256 ad05540d2d96a48725bb79a1def35cf6652a4e2ec26376e2617c8ce2baa6f416) -set(GPERF_URL https://github.com/neovim/deps/raw/ff5b4b18a87397a8564016071ae64f64bcd8c635/opt/gperf-3.1.tar.gz) -set(GPERF_SHA256 588546b945bba4b70b6a3a616e80b4ab466e3f33024a352fc2198112cdbb3ae2) - # cat.exe curl.exe curl-ca-bundle.crt diff.exe tee.exe xxd.exe set(WINTOOLS_URL https://github.com/neovim/deps/raw/d66e306abf5b846484b4f2adffd896bce7e065d2/opt/win32tools.zip) set(WINTOOLS_SHA256 2fb2f8d69070b3f16e029913fb95008e6be33893d77fc358012396c275a0fdb7) @@ -242,10 +234,6 @@ if(USE_BUNDLED_LUV) include(BuildLuv) endif() -if(USE_BUNDLED_GPERF) - include(BuildGperf) -endif() - if(USE_BUNDLED_GETTEXT) include(BuildGettext) endif() diff --git a/third-party/cmake/BuildGperf.cmake b/third-party/cmake/BuildGperf.cmake deleted file mode 100644 index 5401191150..0000000000 --- a/third-party/cmake/BuildGperf.cmake +++ /dev/null @@ -1,68 +0,0 @@ -# Gperf recipe. Gperf is only required when building Neovim, when -# cross compiling we still want to build for the HOST system, whenever -# writing a recipe that is meant for cross-compile, use the HOSTDEPS_* variables -# instead of DEPS_* - check the main CMakeLists.txt for a list. - -# BuildGperf(CONFIGURE_COMMAND ... BUILD_COMMAND ... INSTALL_COMMAND ...) -# Reusable function to build Gperf, wraps ExternalProject_Add. -# Failing to pass a command argument will result in no command being run -function(BuildGperf) - cmake_parse_arguments(_gperf - "" - "" - "CONFIGURE_COMMAND;BUILD_COMMAND;INSTALL_COMMAND" - ${ARGN}) - - if(NOT _gperf_CONFIGURE_COMMAND AND NOT _gperf_BUILD_COMMAND - AND NOT _gperf_INSTALL_COMMAND) - message(FATAL_ERROR "Must pass at least one of CONFIGURE_COMMAND, BUILD_COMMAND, INSTALL_COMMAND") - endif() - - ExternalProject_Add(gperf - PREFIX ${DEPS_BUILD_DIR} - URL ${GPERF_URL} - DOWNLOAD_DIR ${DEPS_DOWNLOAD_DIR}/gperf - DOWNLOAD_COMMAND ${CMAKE_COMMAND} - -DPREFIX=${DEPS_BUILD_DIR} - -DDOWNLOAD_DIR=${DEPS_DOWNLOAD_DIR}/gperf - -DURL=${GPERF_URL} - -DEXPECTED_SHA256=${GPERF_SHA256} - -DTARGET=gperf - -DUSE_EXISTING_SRC_DIR=${USE_EXISTING_SRC_DIR} - -P ${CMAKE_CURRENT_SOURCE_DIR}/cmake/DownloadAndExtractFile.cmake - BUILD_IN_SOURCE 1 - CONFIGURE_COMMAND "${_gperf_CONFIGURE_COMMAND}" - BUILD_COMMAND "${_gperf_BUILD_COMMAND}" - INSTALL_COMMAND "${_gperf_INSTALL_COMMAND}") -endfunction() - -set(GPERF_BUILDARGS CC=${HOSTDEPS_C_COMPILER} CXX=${HOSTDEPS_CXX_COMPILER} - LD=${HOSTDEPS_C_COMPILER}) - -if(UNIX OR (MINGW AND CMAKE_CROSSCOMPILING)) - - BuildGperf( - CONFIGURE_COMMAND ${DEPS_BUILD_DIR}/src/gperf/configure - --prefix=${HOSTDEPS_INSTALL_DIR} - MAKE=${MAKE_PRG} ${GPERF_BUILDARGS} - INSTALL_COMMAND ${MAKE_PRG} install) - -elseif(MSVC OR MINGW) - - BuildGperf( - CONFIGURE_COMMAND ${CMAKE_COMMAND} -E copy - ${CMAKE_CURRENT_SOURCE_DIR}/cmake/GperfCMakeLists.txt - ${DEPS_BUILD_DIR}/src/gperf/CMakeLists.txt - COMMAND ${CMAKE_COMMAND} ${DEPS_BUILD_DIR}/src/gperf/CMakeLists.txt - -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER} - -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER} - -DCMAKE_GENERATOR=${CMAKE_GENERATOR} - -DCMAKE_GENERATOR_PLATFORM=${CMAKE_GENERATOR_PLATFORM} - -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} - -DCMAKE_INSTALL_PREFIX=${DEPS_INSTALL_DIR} - BUILD_COMMAND ${CMAKE_COMMAND} --build . --config ${CMAKE_BUILD_TYPE} - INSTALL_COMMAND ${CMAKE_COMMAND} --build . --target install --config ${CMAKE_BUILD_TYPE}) - -else() - message(FATAL_ERROR "Trying to build gperf in an unsupported system ${CMAKE_SYSTEM_NAME}/${CMAKE_C_COMPILER_ID}") -endif() diff --git a/third-party/cmake/GperfCMakeLists.txt b/third-party/cmake/GperfCMakeLists.txt deleted file mode 100644 index 15ae305ba8..0000000000 --- a/third-party/cmake/GperfCMakeLists.txt +++ /dev/null @@ -1,30 +0,0 @@ -cmake_minimum_required(VERSION 2.8.12) -project(gperf LANGUAGES C CXX) - -add_executable(gperf - lib/getline.cc - lib/hash.cc - lib/getopt.c - lib/getopt1.c - src/version.cc - src/positions.cc - src/options.cc - src/keyword.cc - src/keyword-list.cc - src/input.cc - src/bool-array.cc - src/hash-table.cc - src/search.cc - src/output.cc - src/main.cc) - -include_directories(lib) - -# Copy the config.h template without modifying it -# because none of the definitions are necessary -execute_process(COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_SOURCE_DIR}/src/config.h.in ${CMAKE_BINARY_DIR}/config/config.h) -include_directories(${CMAKE_BINARY_DIR}/config) - -include(GNUInstallDirs) -install(TARGETS gperf - RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) |